Commit c9692eff authored by Andy Hertzfeld's avatar Andy Hertzfeld

hooked up zooming to the background context menu


      hooked up zooming to the background context menu
parent a5d6405d
2000-01-27 Andy Hertzfeld <andy@eazel.com>
hooked zooming up to the background context menu; right now the canvas item
doesn't work at different zoom levels properly, which we'll fix soon.
* libnautilus/fm-directory-view.c,h:
enable zoom in and zoom out items and hooked them up to callback
added a bump_zoom_level slot, to be overriden by subclasses, which the zoom callback use
* libnautilus/fm-directory-view-icons.c:
added method for bump_zoom_index that calls the icon container to do the work
* libnautilus/gnome-icon-container-private.h:
added a private instance variable for zoom level
* libnautilus/gnome-icon-container.c,.h:
added methods for get_zoom_level and set_zoom_level
2000-01-27 Darin Adler <darin@eazel.com>
* libnautilus/gnome-icon-container.c:
......
......@@ -161,10 +161,26 @@ struct _GnomeIconContainerDetails {
/* DnD info. */
GnomeIconContainerDndInfo *dnd_info;
/* zoom level */
gint zoom_level;
/* default font used to draw labels */
GdkFont *label_font;
};
/* Names for Nautilus's different zoom levels, from tiniest items to largest items */
/* FIXME: These are also defined in fm-icon-cache.h and shouldn't be in both places */
typedef enum {
NAUTILUS_ZOOM_LEVEL_SMALLEST,
NAUTILUS_ZOOM_LEVEL_SMALLER,
NAUTILUS_ZOOM_LEVEL_SMALL,
NAUTILUS_ZOOM_LEVEL_STANDARD,
NAUTILUS_ZOOM_LEVEL_LARGE,
NAUTILUS_ZOOM_LEVEL_LARGER,
NAUTILUS_ZOOM_LEVEL_LARGEST
} NautilusZoomLevel;
/* Layout and icon size constants.
These will change based on the zoom level eventually, so they
should probably become function calls instead of macros.
......
......@@ -134,6 +134,7 @@ icon_new_pixbuf (GnomeIconContainer *container,
image = nautilus_icons_controller_get_icon_image (details->controller, data);
name = nautilus_icons_controller_get_icon_name (details->controller, data);
new->item = gnome_canvas_item_new
(GNOME_CANVAS_GROUP (canvas->root),
nautilus_icons_view_icon_item_get_type (),
......@@ -142,6 +143,7 @@ icon_new_pixbuf (GnomeIconContainer *container,
"x", (gdouble) 0,
"y", (gdouble) 0,
NULL);
g_free (name);
return new;
......@@ -1642,7 +1644,8 @@ destroy (GtkObject *object)
icon_grid_destroy (container->details->grid);
g_hash_table_destroy (container->details->canvas_item_to_icon);
unschedule_kbd_icon_visibility (container);
if (container->details->idle_id != 0)
if (container->details->idle_id != 0)
gtk_idle_remove (container->details->idle_id);
if (container->details->linger_selection_mode_timer_tag != -1)
gtk_timeout_remove (container->details->linger_selection_mode_timer_tag);
......@@ -2029,6 +2032,7 @@ gnome_icon_container_initialize (GnomeIconContainer *container)
details->kbd_icon_visibility_timer_tag = -1;
details->linger_selection_mode_timer_tag = -1;
details->zoom_level = NAUTILUS_ZOOM_LEVEL_STANDARD;
/* FIXME: soon we'll need fonts at multiple sizes */
details->label_font = gdk_font_load("-bitstream-charter-medium-r-normal-*-12-*-*-*-*-*-*-*");
......@@ -2336,6 +2340,32 @@ gnome_icon_container_add_auto (GnomeIconContainer *container,
add_idle (container);
}
/* zooming */
gint
gnome_icon_container_get_zoom_level(GnomeIconContainer *container)
{
return container->details->zoom_level;
}
void
gnome_icon_container_set_zoom_level(GnomeIconContainer *container, gint new_level)
{
gint pinned_level = new_level;
double zoom_levels[7] = { 0.25, 0.50, 0.75, 1.0, 1.5, 2.0, 4.0 };
if (pinned_level < NAUTILUS_ZOOM_LEVEL_SMALLEST)
pinned_level = NAUTILUS_ZOOM_LEVEL_SMALLEST;
else if (pinned_level > NAUTILUS_ZOOM_LEVEL_LARGEST)
pinned_level = NAUTILUS_ZOOM_LEVEL_LARGEST;
if (pinned_level != container->details->zoom_level)
{
container->details->zoom_level = pinned_level;
gnome_canvas_set_pixels_per_unit(GNOME_CANVAS(container), zoom_levels[pinned_level]);
}
}
/**
* gnome_icon_container_relayout:
......
......@@ -85,6 +85,9 @@ void gnome_icon_container_line_up (GnomeIconContainer
GList * gnome_icon_container_get_selection (GnomeIconContainer *view);
gint gnome_icon_container_get_zoom_level (GnomeIconContainer *view);
void gnome_icon_container_set_zoom_level (GnomeIconContainer *view, gint new_zoom_level);
void gnome_icon_container_unselect_all (GnomeIconContainer *view);
void gnome_icon_container_select_all (GnomeIconContainer *view);
......
......@@ -161,10 +161,26 @@ struct _GnomeIconContainerDetails {
/* DnD info. */
GnomeIconContainerDndInfo *dnd_info;
/* zoom level */
gint zoom_level;
/* default font used to draw labels */
GdkFont *label_font;
};
/* Names for Nautilus's different zoom levels, from tiniest items to largest items */
/* FIXME: These are also defined in fm-icon-cache.h and shouldn't be in both places */
typedef enum {
NAUTILUS_ZOOM_LEVEL_SMALLEST,
NAUTILUS_ZOOM_LEVEL_SMALLER,
NAUTILUS_ZOOM_LEVEL_SMALL,
NAUTILUS_ZOOM_LEVEL_STANDARD,
NAUTILUS_ZOOM_LEVEL_LARGE,
NAUTILUS_ZOOM_LEVEL_LARGER,
NAUTILUS_ZOOM_LEVEL_LARGEST
} NautilusZoomLevel;
/* Layout and icon size constants.
These will change based on the zoom level eventually, so they
should probably become function calls instead of macros.
......
......@@ -134,6 +134,7 @@ icon_new_pixbuf (GnomeIconContainer *container,
image = nautilus_icons_controller_get_icon_image (details->controller, data);
name = nautilus_icons_controller_get_icon_name (details->controller, data);
new->item = gnome_canvas_item_new
(GNOME_CANVAS_GROUP (canvas->root),
nautilus_icons_view_icon_item_get_type (),
......@@ -142,6 +143,7 @@ icon_new_pixbuf (GnomeIconContainer *container,
"x", (gdouble) 0,
"y", (gdouble) 0,
NULL);
g_free (name);
return new;
......@@ -1642,7 +1644,8 @@ destroy (GtkObject *object)
icon_grid_destroy (container->details->grid);
g_hash_table_destroy (container->details->canvas_item_to_icon);
unschedule_kbd_icon_visibility (container);
if (container->details->idle_id != 0)
if (container->details->idle_id != 0)
gtk_idle_remove (container->details->idle_id);
if (container->details->linger_selection_mode_timer_tag != -1)
gtk_timeout_remove (container->details->linger_selection_mode_timer_tag);
......@@ -2029,6 +2032,7 @@ gnome_icon_container_initialize (GnomeIconContainer *container)
details->kbd_icon_visibility_timer_tag = -1;
details->linger_selection_mode_timer_tag = -1;
details->zoom_level = NAUTILUS_ZOOM_LEVEL_STANDARD;
/* FIXME: soon we'll need fonts at multiple sizes */
details->label_font = gdk_font_load("-bitstream-charter-medium-r-normal-*-12-*-*-*-*-*-*-*");
......@@ -2336,6 +2340,32 @@ gnome_icon_container_add_auto (GnomeIconContainer *container,
add_idle (container);
}
/* zooming */
gint
gnome_icon_container_get_zoom_level(GnomeIconContainer *container)
{
return container->details->zoom_level;
}
void
gnome_icon_container_set_zoom_level(GnomeIconContainer *container, gint new_level)
{
gint pinned_level = new_level;
double zoom_levels[7] = { 0.25, 0.50, 0.75, 1.0, 1.5, 2.0, 4.0 };
if (pinned_level < NAUTILUS_ZOOM_LEVEL_SMALLEST)
pinned_level = NAUTILUS_ZOOM_LEVEL_SMALLEST;
else if (pinned_level > NAUTILUS_ZOOM_LEVEL_LARGEST)
pinned_level = NAUTILUS_ZOOM_LEVEL_LARGEST;
if (pinned_level != container->details->zoom_level)
{
container->details->zoom_level = pinned_level;
gnome_canvas_set_pixels_per_unit(GNOME_CANVAS(container), zoom_levels[pinned_level]);
}
}
/**
* gnome_icon_container_relayout:
......
......@@ -85,6 +85,9 @@ void gnome_icon_container_line_up (GnomeIconContainer
GList * gnome_icon_container_get_selection (GnomeIconContainer *view);
gint gnome_icon_container_get_zoom_level (GnomeIconContainer *view);
void gnome_icon_container_set_zoom_level (GnomeIconContainer *view, gint new_zoom_level);
void gnome_icon_container_unselect_all (GnomeIconContainer *view);
void gnome_icon_container_select_all (GnomeIconContainer *view);
......
......@@ -161,10 +161,26 @@ struct _GnomeIconContainerDetails {
/* DnD info. */
GnomeIconContainerDndInfo *dnd_info;
/* zoom level */
gint zoom_level;
/* default font used to draw labels */
GdkFont *label_font;
};
/* Names for Nautilus's different zoom levels, from tiniest items to largest items */
/* FIXME: These are also defined in fm-icon-cache.h and shouldn't be in both places */
typedef enum {
NAUTILUS_ZOOM_LEVEL_SMALLEST,
NAUTILUS_ZOOM_LEVEL_SMALLER,
NAUTILUS_ZOOM_LEVEL_SMALL,
NAUTILUS_ZOOM_LEVEL_STANDARD,
NAUTILUS_ZOOM_LEVEL_LARGE,
NAUTILUS_ZOOM_LEVEL_LARGER,
NAUTILUS_ZOOM_LEVEL_LARGEST
} NautilusZoomLevel;
/* Layout and icon size constants.
These will change based on the zoom level eventually, so they
should probably become function calls instead of macros.
......
......@@ -134,6 +134,7 @@ icon_new_pixbuf (GnomeIconContainer *container,
image = nautilus_icons_controller_get_icon_image (details->controller, data);
name = nautilus_icons_controller_get_icon_name (details->controller, data);
new->item = gnome_canvas_item_new
(GNOME_CANVAS_GROUP (canvas->root),
nautilus_icons_view_icon_item_get_type (),
......@@ -142,6 +143,7 @@ icon_new_pixbuf (GnomeIconContainer *container,
"x", (gdouble) 0,
"y", (gdouble) 0,
NULL);
g_free (name);
return new;
......@@ -1642,7 +1644,8 @@ destroy (GtkObject *object)
icon_grid_destroy (container->details->grid);
g_hash_table_destroy (container->details->canvas_item_to_icon);
unschedule_kbd_icon_visibility (container);
if (container->details->idle_id != 0)
if (container->details->idle_id != 0)
gtk_idle_remove (container->details->idle_id);
if (container->details->linger_selection_mode_timer_tag != -1)
gtk_timeout_remove (container->details->linger_selection_mode_timer_tag);
......@@ -2029,6 +2032,7 @@ gnome_icon_container_initialize (GnomeIconContainer *container)
details->kbd_icon_visibility_timer_tag = -1;
details->linger_selection_mode_timer_tag = -1;
details->zoom_level = NAUTILUS_ZOOM_LEVEL_STANDARD;
/* FIXME: soon we'll need fonts at multiple sizes */
details->label_font = gdk_font_load("-bitstream-charter-medium-r-normal-*-12-*-*-*-*-*-*-*");
......@@ -2336,6 +2340,32 @@ gnome_icon_container_add_auto (GnomeIconContainer *container,
add_idle (container);
}
/* zooming */
gint
gnome_icon_container_get_zoom_level(GnomeIconContainer *container)
{
return container->details->zoom_level;
}
void
gnome_icon_container_set_zoom_level(GnomeIconContainer *container, gint new_level)
{
gint pinned_level = new_level;
double zoom_levels[7] = { 0.25, 0.50, 0.75, 1.0, 1.5, 2.0, 4.0 };
if (pinned_level < NAUTILUS_ZOOM_LEVEL_SMALLEST)
pinned_level = NAUTILUS_ZOOM_LEVEL_SMALLEST;
else if (pinned_level > NAUTILUS_ZOOM_LEVEL_LARGEST)
pinned_level = NAUTILUS_ZOOM_LEVEL_LARGEST;
if (pinned_level != container->details->zoom_level)
{
container->details->zoom_level = pinned_level;
gnome_canvas_set_pixels_per_unit(GNOME_CANVAS(container), zoom_levels[pinned_level]);
}
}
/**
* gnome_icon_container_relayout:
......
......@@ -85,6 +85,9 @@ void gnome_icon_container_line_up (GnomeIconContainer
GList * gnome_icon_container_get_selection (GnomeIconContainer *view);
gint gnome_icon_container_get_zoom_level (GnomeIconContainer *view);
void gnome_icon_container_set_zoom_level (GnomeIconContainer *view, gint new_zoom_level);
void gnome_icon_container_unselect_all (GnomeIconContainer *view);
void gnome_icon_container_select_all (GnomeIconContainer *view);
......
......@@ -61,6 +61,8 @@ static void fm_directory_view_icons_background_changed_cb (NautilusBackground *b
FMDirectoryViewIcons *icon_view);
static void fm_directory_view_icons_begin_loading
(FMDirectoryView *view);
static void fm_directory_view_icons_bump_zoom_level
(FMDirectoryView *view, gint zoom_increment);
static void fm_directory_view_icons_clear (FMDirectoryView *view);
static void fm_directory_view_icons_destroy (GtkObject *view);
static void fm_directory_view_icons_done_adding_entries
......@@ -114,14 +116,17 @@ fm_directory_view_icons_initialize_class (FMDirectoryViewIconsClass *klass)
= fm_directory_view_icons_begin_loading;
fm_directory_view_class->get_selection
= fm_directory_view_icons_get_selection;
fm_directory_view_class->bump_zoom_level
= fm_directory_view_icons_bump_zoom_level;
}
static void
fm_directory_view_icons_initialize (FMDirectoryViewIcons *icon_view)
{
GnomeIconContainer *icon_container;
g_return_if_fail (GTK_BIN (icon_view)->child == NULL);
g_return_if_fail (GTK_BIN (icon_view)->child == NULL);
icon_view->details = g_new0 (FMDirectoryViewIconsDetails, 1);
......@@ -290,6 +295,15 @@ fm_directory_view_icons_begin_loading (FMDirectoryView *view)
{
}
static void
fm_directory_view_icons_bump_zoom_level (FMDirectoryView *view, gint zoom_increment)
{
GnomeIconContainer *icon_container = get_icon_container(FM_DIRECTORY_VIEW_ICONS (view));
gint current_zoom_level = gnome_icon_container_get_zoom_level(icon_container);
gnome_icon_container_set_zoom_level(icon_container, current_zoom_level + zoom_increment);
}
static GList *
fm_directory_view_icons_get_selection (FMDirectoryView *view)
{
......
......@@ -93,11 +93,14 @@ static void notify_location_change_cb (NautilusViewFrame *view_frame,
Nautilus_NavigationInfo *nav_context,
FMDirectoryView *directory_view);
static void fm_directory_view_repopulate (FMDirectoryView *view);
static void zoom_in_cb (GtkMenuItem *item, FMDirectoryView *directory_view);
static void zoom_out_cb (GtkMenuItem *item, FMDirectoryView *directory_view);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (FMDirectoryView, fm_directory_view, GTK_TYPE_SCROLLED_WINDOW)
NAUTILUS_IMPLEMENT_MUST_OVERRIDE_SIGNAL (fm_directory_view, add_entry)
NAUTILUS_IMPLEMENT_MUST_OVERRIDE_SIGNAL (fm_directory_view, clear)
NAUTILUS_IMPLEMENT_MUST_OVERRIDE_SIGNAL (fm_directory_view, get_selection)
NAUTILUS_IMPLEMENT_MUST_OVERRIDE_SIGNAL (fm_directory_view, bump_zoom_level)
static void
fm_directory_view_initialize_class (FMDirectoryViewClass *klass)
......@@ -147,6 +150,7 @@ fm_directory_view_initialize_class (FMDirectoryViewClass *klass)
NAUTILUS_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, fm_directory_view, add_entry);
NAUTILUS_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, fm_directory_view, clear);
NAUTILUS_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, fm_directory_view, get_selection);
NAUTILUS_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, fm_directory_view, bump_zoom_level);
}
static void
......@@ -358,6 +362,19 @@ stop_load (FMDirectoryView *view, gboolean error)
/* handle the zoom in/out menu items */
static void
zoom_in_cb(GtkMenuItem *item, FMDirectoryView *directory_view)
{
fm_directory_view_bump_zoom_level (directory_view, 1);
}
static void
zoom_out_cb(GtkMenuItem *item, FMDirectoryView *directory_view)
{
fm_directory_view_bump_zoom_level (directory_view, -1);
}
/**
* fm_directory_view_repopulate:
......@@ -586,6 +603,20 @@ fm_directory_view_begin_loading (FMDirectoryView *view)
gtk_signal_emit (GTK_OBJECT (view), fm_directory_view_signals[BEGIN_LOADING]);
}
/**
* fm_directory_view_bump_zoom_level:
*
* bump the current zoom level by invoking the relevant subclass through the slot
*
**/
void
fm_directory_view_bump_zoom_level (FMDirectoryView *view, gint zoom_increment)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
(* FM_DIRECTORY_VIEW_CLASS (GTK_OBJECT (view)->klass)->bump_zoom_level) (view, zoom_increment);
}
/**
* fm_directory_view_get_selection:
*
......@@ -700,13 +731,17 @@ create_background_context_menu (FMDirectoryView *view)
gtk_menu_append (menu, menu_item);
menu_item = gtk_menu_item_new_with_label ("Zoom in");
gtk_widget_set_sensitive (menu_item, FALSE);
gtk_signal_connect(GTK_OBJECT (menu_item), "activate",
GTK_SIGNAL_FUNC (zoom_in_cb), view);
gtk_widget_show (menu_item);
gtk_menu_append (menu, menu_item);
menu_item = gtk_menu_item_new_with_label ("Zoom out");
gtk_widget_set_sensitive (menu_item, FALSE);
gtk_widget_show (menu_item);
gtk_signal_connect(GTK_OBJECT (menu_item), "activate",
GTK_SIGNAL_FUNC (zoom_out_cb), view);
gtk_widget_show (menu_item);
gtk_menu_append (menu, menu_item);
gtk_object_ref(GTK_OBJECT(menu));
......
......@@ -99,6 +99,10 @@ struct _FMDirectoryViewClass {
*/
NautilusFileList *
(* get_selection) (FMDirectoryView *view);
/* bump_zoom_level is a function pointer that subclasses override to
* change the zoom level of an object */
void (* bump_zoom_level) (FMDirectoryView *view, gint zoom_increment);
};
......@@ -129,13 +133,13 @@ void fm_directory_view_begin_adding_entries (FMDirector
void fm_directory_view_add_entry (FMDirectoryView *view,
NautilusFile *file);
void fm_directory_view_done_adding_entries (FMDirectoryView *view);
void fm_directory_view_begin_loading (FMDirectoryView *view);
void fm_directory_view_begin_loading (FMDirectoryView *view);
/* Hooks for subclasses to call. These are normally called only by
* FMDirectoryView and its subclasses
*/
void fm_directory_view_activate_entry (FMDirectoryView *view,
NautilusFile *file);
void fm_directory_view_bump_zoom_level (FMDirectoryView *view, gint zoom_increment);
void fm_directory_view_notify_selection_changed (FMDirectoryView *view);
NautilusDirectory * fm_directory_view_get_model (FMDirectoryView *view);
void fm_directory_view_popup_background_context_menu (FMDirectoryView *view);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment