Commit d1404606 authored by John Sullivan's avatar John Sullivan

Added can_zoom_in and can_zoom_out, and made item context menu disable

Zoom In and Zoom Out correctly.
parent dd8153b2
2000-01-31 John Sullivan <sullivan@eazel.com>
Improved zooming API and made zoom items on item context
menu disable properly. (There's still a bug with disabling
the background menu if an item menu ever appears; Darin will
fix this in his next checkin.)
* src/file-manager/fm-directory-view.c:
* src/file-manager/fm-directory-view.h:
(can_zoom_in), (can_zoom_out): New function pointers for subclasses
to replace.
(fm_directory_view_can_zoom_in), (fm_directory_view_can_zoom_out):
New functions that call through to the new function pointers.
(bump_zoom_level), (fm_directory_view_bump_zoom_level):
Removed return value in favor of new functions.
(update_zoom_menu_items): Helper function to update sensitivity of
background context menu Zoom In and Zoom Out items. Darin will eliminate
this with his next checkin.
(zoom_in_cb), (zoom_out_cb): Now use update_zoom_menu_items to share code.
(append_background_items): Set sensitivity of Zoom In and Zoom Out items
at creation time.
* src/file-manager/fm-directory-view-list.c:
(fm_directory_view_list_bump_zoom_level): Removed return value.
(fm_directory_view_list_can_zoom_in), (fm_directory_view_list_can_zoom_out):
New functions, compare current zoom level against limits.
(fm_directory_view_list_get_zoom_level),
(fm_directory_view_list_set_zoom_level): New convenience functions,
deployed throughout this file.
(fm_directory_view_list_initialize_class): Replace can_zoom_in and
can_zoom_out function pointers.
* src/file-manager/fm-directory-view-icons.c:
(fm_directory_view_icons_bump_zoom_level): Removed return value.
(fm_directory_view_icons_can_zoom_in), (fm_directory_view_icons_can_zoom_out):
New functions, compare current zoom level against limits.
(fm_directory_view_icons_get_zoom_level): New convenience function,
deployed throughout this file.
(fm_directory_view_icons_initialize_class): Replace can_zoom_in and
can_zoom_out function pointers.
2000-01-30 Andy Hertzfeld <andy@eazel.com>
made fonts scale according to the zoom level:
......
......@@ -61,16 +61,23 @@ 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 gboolean fm_directory_view_icons_bump_zoom_level
static void fm_directory_view_icons_bump_zoom_level
(FMDirectoryView *view, gint zoom_increment);
static gboolean fm_directory_view_icons_can_zoom_in (FMDirectoryView *view);
static gboolean fm_directory_view_icons_can_zoom_out (FMDirectoryView *view);
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
(FMDirectoryView *view);
static NautilusFileList * fm_directory_view_icons_get_selection
(FMDirectoryView *view);
static NautilusZoomLevel fm_directory_view_icons_get_zoom_level
(FMDirectoryViewIcons *view);
static void fm_directory_view_icons_initialize (FMDirectoryViewIcons *icon_view);
static void fm_directory_view_icons_initialize_class (FMDirectoryViewIconsClass *klass);
static void fm_directory_view_icons_set_zoom_level
(FMDirectoryViewIcons *view,
NautilusZoomLevel new_level);
static GnomeIconContainer *get_icon_container (FMDirectoryViewIcons *icon_view);
static void icon_container_activate_cb (GnomeIconContainer *container,
NautilusFile *icon_data,
......@@ -118,6 +125,10 @@ fm_directory_view_icons_initialize_class (FMDirectoryViewIconsClass *klass)
= fm_directory_view_icons_get_selection;
fm_directory_view_class->bump_zoom_level
= fm_directory_view_icons_bump_zoom_level;
fm_directory_view_class->can_zoom_in
= fm_directory_view_icons_can_zoom_in;
fm_directory_view_class->can_zoom_out
= fm_directory_view_icons_can_zoom_out;
}
......@@ -295,19 +306,68 @@ fm_directory_view_icons_begin_loading (FMDirectoryView *view)
{
}
static gboolean
static NautilusZoomLevel
fm_directory_view_icons_get_zoom_level (FMDirectoryViewIcons *view)
{
GnomeIconContainer *icon_container;
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW_ICONS (view),
NAUTILUS_ZOOM_LEVEL_STANDARD);
icon_container = get_icon_container (view);
return (gnome_icon_container_get_zoom_level (icon_container));
}
static void
fm_directory_view_icons_set_zoom_level (FMDirectoryViewIcons *view,
NautilusZoomLevel new_level)
{
GnomeIconContainer *icon_container;
g_return_if_fail (FM_IS_DIRECTORY_VIEW_ICONS (view));
g_return_if_fail (new_level >= NAUTILUS_ZOOM_LEVEL_SMALLEST &&
new_level <= NAUTILUS_ZOOM_LEVEL_LARGEST);
icon_container = get_icon_container (view);
if (gnome_icon_container_get_zoom_level (icon_container) == new_level)
return;
gnome_icon_container_set_zoom_level (icon_container, new_level);
}
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);
gint new_zoom_level = current_zoom_level + zoom_increment;
gnome_icon_container_set_zoom_level(icon_container, new_zoom_level);
if (zoom_increment > 0)
return new_zoom_level < NAUTILUS_ZOOM_LEVEL_LARGEST;
else
return new_zoom_level > NAUTILUS_ZOOM_LEVEL_SMALLEST;
FMDirectoryViewIcons *icon_view;
NautilusZoomLevel new_level;
g_return_if_fail (FM_IS_DIRECTORY_VIEW_ICONS (view));
icon_view = FM_DIRECTORY_VIEW_ICONS (view);
new_level = fm_directory_view_icons_get_zoom_level (icon_view) + zoom_increment;
fm_directory_view_icons_set_zoom_level(icon_view, new_level);
}
static gboolean
fm_directory_view_icons_can_zoom_in (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW_ICONS (view), FALSE);
return fm_directory_view_icons_get_zoom_level (FM_DIRECTORY_VIEW_ICONS (view))
< NAUTILUS_ZOOM_LEVEL_LARGEST;
}
static gboolean
fm_directory_view_icons_can_zoom_out (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW_ICONS (view), FALSE);
return fm_directory_view_icons_get_zoom_level (FM_DIRECTORY_VIEW_ICONS (view))
> NAUTILUS_ZOOM_LEVEL_SMALLEST;
}
static GList *
fm_directory_view_icons_get_selection (FMDirectoryView *view)
{
......
......@@ -91,11 +91,15 @@ static void fm_directory_view_list_background_changed_cb
FMDirectoryViewList *list_view);
static void fm_directory_view_list_begin_adding_entries
(FMDirectoryView *view);
static gboolean fm_directory_view_list_bump_zoom_level (FMDirectoryView *view,
static void fm_directory_view_list_bump_zoom_level (FMDirectoryView *view,
gint zoom_increment);
static gboolean fm_directory_view_list_can_zoom_in (FMDirectoryView *view);
static gboolean fm_directory_view_list_can_zoom_out (FMDirectoryView *view);
static void fm_directory_view_list_clear (FMDirectoryView *view);
static guint fm_directory_view_list_get_icon_size (FMDirectoryViewList *list_view);
static GList *fm_directory_view_list_get_selection (FMDirectoryView *view);
static NautilusZoomLevel fm_directory_view_list_get_zoom_level
(FMDirectoryViewList *list_view);
static void fm_directory_view_list_initialize (gpointer object, gpointer klass);
static void fm_directory_view_list_initialize_class (gpointer klass);
static void fm_directory_view_list_destroy (GtkObject *object);
......@@ -162,6 +166,8 @@ fm_directory_view_list_initialize_class (gpointer klass)
fm_directory_view_class->done_adding_entries = fm_directory_view_list_done_adding_entries;
fm_directory_view_class->get_selection = fm_directory_view_list_get_selection;
fm_directory_view_class->bump_zoom_level = fm_directory_view_list_bump_zoom_level;
fm_directory_view_class->can_zoom_in = fm_directory_view_list_can_zoom_in;
fm_directory_view_class->can_zoom_out = fm_directory_view_list_can_zoom_out;
}
static void
......@@ -490,35 +496,50 @@ get_flist (FMDirectoryViewList *list_view)
return GTK_FLIST (GTK_BIN (list_view)->child);
}
static gboolean
static void
fm_directory_view_list_bump_zoom_level (FMDirectoryView *view, gint zoom_increment)
{
FMDirectoryViewList *list_view;
NautilusZoomLevel old_level;
NautilusZoomLevel new_level;
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), FALSE);
g_return_if_fail (FM_IS_DIRECTORY_VIEW_LIST (view));
list_view = FM_DIRECTORY_VIEW_LIST (view);
old_level = fm_directory_view_list_get_zoom_level (list_view);
if (zoom_increment < 0 && 0 - zoom_increment > list_view->details->zoom_level)
if (zoom_increment < 0 && 0 - zoom_increment > old_level)
{
new_level = NAUTILUS_ZOOM_LEVEL_SMALLEST;
}
else
{
new_level = MIN (list_view->details->zoom_level + zoom_increment,
new_level = MIN (old_level + zoom_increment,
NAUTILUS_ZOOM_LEVEL_LARGEST);
}
fm_directory_view_list_set_zoom_level (list_view, new_level);
if (zoom_increment > 0)
return new_level < NAUTILUS_ZOOM_LEVEL_LARGEST;
else
return new_level > NAUTILUS_ZOOM_LEVEL_SMALLEST;
}
static gboolean
fm_directory_view_list_can_zoom_in (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW_LIST (view), FALSE);
return fm_directory_view_list_get_zoom_level (FM_DIRECTORY_VIEW_LIST (view))
< NAUTILUS_ZOOM_LEVEL_LARGEST;
}
static gboolean
fm_directory_view_list_can_zoom_out (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW_LIST (view), FALSE);
return fm_directory_view_list_get_zoom_level (FM_DIRECTORY_VIEW_LIST (view))
> NAUTILUS_ZOOM_LEVEL_SMALLEST;
}
static void
fm_directory_view_list_clear (FMDirectoryView *view)
{
......@@ -570,7 +591,8 @@ fm_directory_view_list_get_icon_size (FMDirectoryViewList *list_view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW_LIST (list_view), NAUTILUS_ICON_SIZE_STANDARD);
return nautilus_icon_size_for_zoom_level (list_view->details->zoom_level);
return nautilus_icon_size_for_zoom_level (
fm_directory_view_list_get_zoom_level (list_view));
}
static GList *
......@@ -581,6 +603,15 @@ fm_directory_view_list_get_selection (FMDirectoryView *view)
return gtk_flist_get_selection (get_flist (FM_DIRECTORY_VIEW_LIST (view)));
}
static NautilusZoomLevel
fm_directory_view_list_get_zoom_level (FMDirectoryViewList *list_view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW_LIST (list_view),
NAUTILUS_ZOOM_LEVEL_STANDARD);
return list_view->details->zoom_level;
}
static void
fm_directory_view_list_set_zoom_level (FMDirectoryViewList *list_view,
NautilusZoomLevel new_level)
......@@ -592,7 +623,7 @@ fm_directory_view_list_set_zoom_level (FMDirectoryViewList *list_view,
g_return_if_fail (new_level >= NAUTILUS_ZOOM_LEVEL_SMALLEST &&
new_level <= NAUTILUS_ZOOM_LEVEL_LARGEST);
if (new_level == list_view->details->zoom_level)
if (new_level == fm_directory_view_list_get_zoom_level (list_view))
return;
list_view->details->zoom_level = new_level;
......
......@@ -104,6 +104,8 @@ 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)
NAUTILUS_IMPLEMENT_MUST_OVERRIDE_SIGNAL (fm_directory_view, can_zoom_in)
NAUTILUS_IMPLEMENT_MUST_OVERRIDE_SIGNAL (fm_directory_view, can_zoom_out)
static void
fm_directory_view_initialize_class (FMDirectoryViewClass *klass)
......@@ -150,10 +152,14 @@ fm_directory_view_initialize_class (FMDirectoryViewClass *klass)
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
/* Function pointers that subclasses must override */
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);
NAUTILUS_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, fm_directory_view, can_zoom_in);
NAUTILUS_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, fm_directory_view, can_zoom_out);
}
static void
......@@ -369,22 +375,34 @@ stop_load (FMDirectoryView *view, gboolean error)
/* handle the zoom in/out menu items */
static void
update_zoom_menu_items (FMDirectoryView *directory_view)
{
/* Note that this updates only the unchanging background menu;
* we also have to make sure we set the sensitivity of these
* items on the item-specific menu when it's created. This function
* can go away entirely when the background menu is created on
* the fly, a change Darin is in the process of making.
*/
gtk_widget_set_sensitive(directory_view->details->zoom_in_item,
fm_directory_view_can_zoom_in (directory_view));
gtk_widget_set_sensitive(directory_view->details->zoom_out_item,
fm_directory_view_can_zoom_out (directory_view));
}
static void
zoom_in_cb(GtkMenuItem *item, FMDirectoryView *directory_view)
{
gboolean can_zoom_in = fm_directory_view_bump_zoom_level (directory_view, 1);
gtk_widget_set_sensitive(directory_view->details->zoom_in_item, can_zoom_in);
gtk_widget_set_sensitive(directory_view->details->zoom_out_item, TRUE);
fm_directory_view_bump_zoom_level (directory_view, 1);
update_zoom_menu_items (directory_view);
}
static void
zoom_out_cb(GtkMenuItem *item, FMDirectoryView *directory_view)
{
gboolean can_zoom_out = fm_directory_view_bump_zoom_level (directory_view, -1);
gtk_widget_set_sensitive(directory_view->details->zoom_out_item, can_zoom_out);
gtk_widget_set_sensitive(directory_view->details->zoom_in_item, TRUE);
fm_directory_view_bump_zoom_level (directory_view, -1);
update_zoom_menu_items (directory_view);
}
static void
......@@ -578,12 +596,46 @@ fm_directory_view_begin_loading (FMDirectoryView *view)
* bump the current zoom level by invoking the relevant subclass through the slot
*
**/
gboolean
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_can_zoom_in:
*
* Determine whether the view can be zoomed any closer.
* @view: The zoomable FMDirectoryView.
*
* Return value: TRUE if @view can be zoomed any closer, FALSE otherwise.
*
**/
gboolean
fm_directory_view_can_zoom_in (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), FALSE);
return (* FM_DIRECTORY_VIEW_CLASS (GTK_OBJECT (view)->klass)->bump_zoom_level) (view, zoom_increment);
return (* FM_DIRECTORY_VIEW_CLASS (GTK_OBJECT (view)->klass)->can_zoom_in) (view);
}
/**
* fm_directory_view_can_zoom_out:
*
* Determine whether the view can be zoomed any further away.
* @view: The zoomable FMDirectoryView.
*
* Return value: TRUE if @view can be zoomed any further away, FALSE otherwise.
*
**/
gboolean
fm_directory_view_can_zoom_out (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), FALSE);
return (* FM_DIRECTORY_VIEW_CLASS (GTK_OBJECT (view)->klass)->can_zoom_out) (view);
}
/**
......@@ -676,6 +728,14 @@ append_background_items (FMDirectoryView *view, GtkMenu *menu)
gtk_widget_show (menu_item);
gtk_menu_append (menu, menu_item);
gtk_widget_set_sensitive (menu_item, fm_directory_view_can_zoom_in (view));
/* FIXME: This code assumes that the function won't be called again after
* the background menu is set up, but that's not true if the user clicks
* on an item. This code and the corresponding details field can go away
* entirely when the background menu is always created dynamically (a change
* Darin is in the process of making).
*/
view->details->zoom_in_item = menu_item;
......@@ -686,6 +746,14 @@ append_background_items (FMDirectoryView *view, GtkMenu *menu)
gtk_widget_show (menu_item);
gtk_menu_append (menu, menu_item);
gtk_widget_set_sensitive (menu_item, fm_directory_view_can_zoom_out (view));
/* FIXME: This code assumes that the function won't be called again after
* the background menu is set up, but that's not true if the user clicks
* on an item. This code and the corresponding details field can go away
* entirely when the background menu is always created dynamically (a change
* Darin is in the process of making).
*/
view->details->zoom_out_item = menu_item;
}
......@@ -924,4 +992,4 @@ fm_directory_view_stop (FMDirectoryView *view)
display_pending_entries (view);
stop_load (view, FALSE);
}
\ No newline at end of file
}
......@@ -80,6 +80,8 @@ struct _FMDirectoryViewClass {
*/
void (* begin_loading) (FMDirectoryView *view);
/* Function pointers that don't have corresponding signals */
/* get_selection is not a signal; it is just a function pointer for
* subclasses to replace (override). Subclasses must replace it
* with a function that returns a newly-allocated GList of
......@@ -88,10 +90,17 @@ 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. It returns FALSE if it's now zoomed as
far as it can go */
gboolean (* bump_zoom_level) (FMDirectoryView *view, gint zoom_increment);
/* bump_zoom_level is a function pointer that subclasses must override
* to change the zoom level of an object. */
void (* bump_zoom_level) (FMDirectoryView *view, gint zoom_increment);
/* can_zoom_in is a function pointer that subclasses must override to
* return whether the view is at maximum size (furthest-in zoom level) */
gboolean (* can_zoom_in) (FMDirectoryView *view);
/* can_zoom_out is a function pointer that subclasses must override to
* return whether the view is at minimum size (furthest-out zoom level) */
gboolean (* can_zoom_out) (FMDirectoryView *view);
};
......@@ -109,6 +118,10 @@ void fm_directory_view_load_uri (FMDirector
/* Functions callable from the user interface and elsewhere. */
GList * fm_directory_view_get_selection (FMDirectoryView *view);
void fm_directory_view_stop (FMDirectoryView *view);
gboolean fm_directory_view_can_zoom_in (FMDirectoryView *view);
gboolean fm_directory_view_can_zoom_out (FMDirectoryView *view);
void fm_directory_view_bump_zoom_level (FMDirectoryView *view,
gint zoom_increment);
/* Wrappers for signal emitters. These are normally called
* only by FMDirectoryView itself. They have corresponding signals
......@@ -120,12 +133,12 @@ void fm_directory_view_add_entry (FMDirector
NautilusFile *file);
void fm_directory_view_done_adding_entries (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);
gboolean fm_directory_view_bump_zoom_level (FMDirectoryView *view, gint zoom_increment);
void fm_directory_view_notify_selection_changed (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