Re: [Nautilus-list] two keynav/a11y patches



On Sat, 2002-04-20 at 15:05, Alex Larsson wrote:
> Please use <libgnome/gnome-i18n.h> instead of <bonobo/bonobo-i18n.h>, as 
> that is what the rest of nautilus uses.

Done.

> 
> We should probably make up a better name instead of:
>  N_("Show the contents at optimal size")
> What about "Try to fit in window". Hmm. That sounds dorky too. Ideas?

I didn't have any ideas, so I put in "Try to fit in window".  I can file
a bug against that if you want.

> 
> +	if ((accessible = eel_accessibility_get_atk_object (widget))) {
> +		return accessible;
> +	}
> Don't assign in the comparison.

Fixed.

> 
> +	gtk_binding_entry_add_signal (binding_set, 
> +				      GDK_equal, 0, 
> +				      "change_value",
> +				      1, GTK_TYPE_SCROLL_TYPE,
> +				      GTK_SCROLL_STEP_UP);
> This should be GDK_plus, not GDK_equal. And you're missing the right 
> binding for GDK_equal.

Fixed.

> In nautilus_zoom_control_accessible_do_action, 
> nautilus_zoom_control_accessible_action_get_description and 
> nautilus_zoom_control_accessible_action_get_name. Check for valid range 
> for i before using it (we want at least some warning spew if it's wrong).

Fixed.
 
> What happens if you use 
> nautilus_zoom_control_accessible_set_current_value() to set the zoom to an 
> irregular zoom level (one not normally in the zoom widget)? Does it work?

It zoomed to whatever level was passed in.  The attached patch snaps to
the closest preferred zoom level. 

The attached patch also changes the zoom code to use floats rather than
doubles throughout nautilus, to match the bonobo-zoomable interface.

-dave
? nautilus-zoom-fixes.patch
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/nautilus/ChangeLog,v
retrieving revision 1.5241
diff -u -r1.5241 ChangeLog
--- ChangeLog	24 Apr 2002 14:40:35 -0000	1.5241
+++ ChangeLog	24 Apr 2002 20:33:05 -0000
@@ -1,3 +1,41 @@
+2002-04-24  Dave Camp  <dave ximian com>
+
+	* src/nautilus-view-frame.c: (nautilus_view_frame_set_zoom_level):
+	* src/nautilus-view-frame.h:
+	* src/nautilus-window-manage-views.c:
+	(zoom_parameters_changed_callback):
+	* src/nautilus-window-private.h:
+	* src/nautilus-window.c: (nautilus_window_zoom_to_level): Replace
+	doubles in the zoom interfaces with floats to match the bonobo
+	zoomable interface.
+
+	* src/nautilus-zoom-control.c: (nautilus_zoom_control_expose):
+	Draw the focus rectangle if the zoom control is focused.
+	(nautilus_zoom_control_button_press_event): Grab focus.
+	(zoom_menu_callback), (create_zoom_menu_item),
+	(nautilus_zoom_control_change_value),
+	(nautilus_zoom_control_set_zoom_level),
+	(nautilus_zoom_control_set_parameters): Replace double with float.
+	(nautilus_zoom_control_class_init): Initialize keybindings.
+	(nautilus_zoom_control_get_accessible),
+	(nautilus_zoom_control_accessible_do_action),
+	(nautilus_zoom_control_accessible_get_n_actions),
+	(nautilus_zoom_control_accessible_action_get_description),
+	(nautilus_zoom_control_accessible_action_get_name),
+	(nautilus_zoom_control_accessible_action_interface_init),
+	(nautilus_zoom_control_accessible_get_current_value),
+	(nautilus_zoom_control_accessible_get_maximum_value),
+	(nautilus_zoom_control_accessible_get_minimum_value),
+	(nearest_preferred),
+	(nautilus_zoom_control_accessible_set_current_value),
+	(nautilus_zoom_control_accessible_value_interface_init),
+	(nautilus_zoom_control_accessible_get_name),
+	(nautilus_zoom_control_accessible_get_description),
+	(nautilus_zoom_control_accessible_class_init),
+	(nautilus_zoom_control_accessible_get_type): Implement the zoom
+	accessible.
+	* src/nautilus-zoom-control.h: Added the change_value signal.
+
 2002-04-24  Jody Goldberg <jody gnome org>
 
 	* src/file-manager/fm-list-model.c
Index: src/nautilus-view-frame.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-view-frame.c,v
retrieving revision 1.158
diff -u -r1.158 nautilus-view-frame.c
--- src/nautilus-view-frame.c	18 Mar 2002 17:21:42 -0000	1.158
+++ src/nautilus-view-frame.c	24 Apr 2002 20:33:23 -0000
@@ -921,7 +921,7 @@
 	return view->details->zoomable_frame != NULL;
 }
 
-double
+float
 nautilus_view_frame_get_zoom_level (NautilusViewFrame *view)
 {
 	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), 0.0);
@@ -935,7 +935,7 @@
 
 void
 nautilus_view_frame_set_zoom_level (NautilusViewFrame *view,
-				    double zoom_level)
+				    float zoom_level)
 {
 	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
 
@@ -943,10 +943,10 @@
 		return;
 	}
 
-	bonobo_zoomable_frame_set_zoom_level (view->details->zoomable_frame, (float) zoom_level);
+	bonobo_zoomable_frame_set_zoom_level (view->details->zoomable_frame, zoom_level);
 }
 
-double
+float
 nautilus_view_frame_get_min_zoom_level (NautilusViewFrame *view)
 {
 	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), 0.0);
@@ -958,7 +958,7 @@
 	return bonobo_zoomable_frame_get_min_zoom_level (view->details->zoomable_frame);
 }
 
-double
+float
 nautilus_view_frame_get_max_zoom_level (NautilusViewFrame *view)
 {
 	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), 0.0);
Index: src/nautilus-view-frame.h
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-view-frame.h,v
retrieving revision 1.68
diff -u -r1.68 nautilus-view-frame.h
--- src/nautilus-view-frame.h	8 Jan 2002 17:35:50 -0000	1.68
+++ src/nautilus-view-frame.h	24 Apr 2002 20:33:24 -0000
@@ -115,11 +115,11 @@
                                                                   const char          *title);
 
 /* calls to Bonobo:Zoomable functions */
-double             nautilus_view_frame_get_zoom_level            (NautilusViewFrame   *view);
+float              nautilus_view_frame_get_zoom_level            (NautilusViewFrame   *view);
 void               nautilus_view_frame_set_zoom_level            (NautilusViewFrame   *view,
-                                                                  double               zoom_level);
-double             nautilus_view_frame_get_min_zoom_level        (NautilusViewFrame   *view);
-double             nautilus_view_frame_get_max_zoom_level        (NautilusViewFrame   *view);
+                                                                  float                zoom_level);
+float              nautilus_view_frame_get_min_zoom_level        (NautilusViewFrame   *view);
+float              nautilus_view_frame_get_max_zoom_level        (NautilusViewFrame   *view);
 gboolean           nautilus_view_frame_get_has_min_zoom_level    (NautilusViewFrame   *view);
 gboolean           nautilus_view_frame_get_has_max_zoom_level    (NautilusViewFrame   *view);
 gboolean           nautilus_view_frame_get_is_continuous         (NautilusViewFrame   *view);
Index: src/nautilus-window-manage-views.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-window-manage-views.c,v
retrieving revision 1.292
diff -u -r1.292 nautilus-window-manage-views.c
--- src/nautilus-window-manage-views.c	21 Apr 2002 21:15:41 -0000	1.292
+++ src/nautilus-window-manage-views.c	24 Apr 2002 20:33:26 -0000
@@ -1604,7 +1604,7 @@
 zoom_parameters_changed_callback (NautilusViewFrame *view,
                                   NautilusWindow *window)
 {
-        double zoom_level;
+        float zoom_level;
 
         g_assert (NAUTILUS_IS_WINDOW (window));
 
Index: src/nautilus-window-private.h
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-window-private.h,v
retrieving revision 1.86
diff -u -r1.86 nautilus-window-private.h
--- src/nautilus-window-private.h	5 Apr 2002 11:54:35 -0000	1.86
+++ src/nautilus-window-private.h	24 Apr 2002 20:33:26 -0000
@@ -151,7 +151,7 @@
 void               nautilus_window_zoom_in                               (NautilusWindow    *window);
 void               nautilus_window_zoom_out                              (NautilusWindow    *window);
 void               nautilus_window_zoom_to_level                         (NautilusWindow    *window,
-                                                                          double             level);
+                                                                          float                   level);
 void               nautilus_window_zoom_to_fit                           (NautilusWindow    *window);
 void		   nautilus_window_show_view_as_dialog			 (NautilusWindow    *window);
 void               nautilus_window_set_content_view_widget               (NautilusWindow    *window,
Index: src/nautilus-window.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-window.c,v
retrieving revision 1.384
diff -u -r1.384 nautilus-window.c
--- src/nautilus-window.c	24 Apr 2002 01:32:46 -0000	1.384
+++ src/nautilus-window.c	24 Apr 2002 20:33:28 -0000
@@ -423,7 +423,7 @@
 }
 
 void
-nautilus_window_zoom_to_level (NautilusWindow *window, double level)
+nautilus_window_zoom_to_level (NautilusWindow *window, float level)
 {
 	if (window->content_view != NULL) {
 		nautilus_view_frame_set_zoom_level (window->content_view, level);
Index: src/nautilus-zoom-control.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-zoom-control.c,v
retrieving revision 1.69
diff -u -r1.69 nautilus-zoom-control.c
--- src/nautilus-zoom-control.c	21 Apr 2002 18:14:40 -0000	1.69
+++ src/nautilus-zoom-control.c	24 Apr 2002 20:33:29 -0000
@@ -28,11 +28,17 @@
 #include <config.h>
 #include "nautilus-zoom-control.h"
 
+#include <atk/atkaction.h>
+#include <libgnome/gnome-i18n.h>
+#include <eel/eel-accessibility.h>
 #include <eel/eel-glib-extensions.h>
 #include <eel/eel-graphic-effects.h>
 #include <eel/eel-gtk-extensions.h>
+#include <gtk/gtkaccessible.h>
 #include <gtk/gtkmenu.h>
 #include <gtk/gtkradiomenuitem.h>
+#include <gtk/gtkbindings.h>
+#include <gdk/gdkkeysyms.h>
 #include <libgnome/gnome-macros.h>
 #include <libnautilus-private/nautilus-file-utilities.h>
 #include <libnautilus-private/nautilus-global-preferences.h>
@@ -47,6 +53,7 @@
 	ZOOM_OUT,
 	ZOOM_TO_LEVEL,
 	ZOOM_TO_FIT,
+	CHANGE_VALUE,
 	LAST_SIGNAL
 };
 
@@ -60,9 +67,9 @@
 #define	GAP_WIDTH 2
 
 struct NautilusZoomControlDetails {
-	double zoom_level;
-	double min_zoom_level;	 
-	double max_zoom_level;
+	float zoom_level;
+	float min_zoom_level;	 
+	float max_zoom_level;
 	gboolean has_min_zoom_level;
 	gboolean has_max_zoom_level;
 	GList *preferred_zoom_levels;
@@ -82,13 +89,37 @@
 
 static guint signals[LAST_SIGNAL];
 
+gpointer accessible_parent_class;
+
+static const char *nautilus_zoom_control_accessible_action_names[] = {
+	N_("Zoom In"),
+	N_("Zoom Out"),
+	N_("Zoom to Fit"),
+};
+
+static int nautilus_zoom_control_accessible_action_signals[] = {
+	ZOOM_IN,
+	ZOOM_OUT,
+	ZOOM_TO_FIT,
+};
+
+static const char *nautilus_zoom_control_accessible_action_descriptions[] = {
+	N_("Show the contents in more detail"),
+	N_("Show the contents in less detail"),
+	N_("Try to fit in window"),
+};
+
 static void nautilus_zoom_control_load_images   (NautilusZoomControl      *zoom_control);
 static void nautilus_zoom_control_unload_images (NautilusZoomControl      *zoom_control);
 static void nautilus_zoom_control_theme_changed (gpointer                  user_data);
 
+static GType nautilus_zoom_control_accessible_get_type (void);
+
 /* button assignments */
 #define CONTEXTUAL_MENU_BUTTON 3
 
+#define NUM_ACTIONS ((int)(sizeof (nautilus_zoom_control_accessible_action_names) / sizeof (nautilus_zoom_control_accessible_action_names[0])))
+
 GNOME_CLASS_BOILERPLATE (NautilusZoomControl, nautilus_zoom_control,
 			 GtkEventBox, GTK_TYPE_EVENT_BOX)
 
@@ -346,6 +377,17 @@
 
 	draw_zoom_control_image (widget, &box);	
 	draw_number (widget, &box);
+	
+	if (GTK_WIDGET_HAS_FOCUS (widget)) {
+		gtk_paint_focus (widget->style,
+				 widget->window,
+				 GTK_WIDGET_STATE (widget),
+				 &event->area,
+				 widget,
+				 "nautilus-zoom-control",
+				 box.x, box.y,
+				 box.width, box.height);
+	}		 
 
 	return FALSE;
 }
@@ -459,7 +501,7 @@
 static void
 zoom_menu_callback (GtkMenuItem *item, gpointer callback_data)
 {
-	double zoom_level;
+	float zoom_level;
 	NautilusZoomControl *zoom_control;
 	gboolean can_zoom;
 		
@@ -470,7 +512,12 @@
 		return;
 	}
 
-	zoom_level = * (double *) g_object_get_data (G_OBJECT (item), "zoom_level");
+	/* Don't send the signal if the menuitem was toggled off */
+	if (!gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (item))) {
+		return;
+	}
+
+	zoom_level = * (float *) g_object_get_data (G_OBJECT (item), "zoom_level");
 
 	/* Assume we can zoom and then check whether we're right. */
 	can_zoom = TRUE;
@@ -494,7 +541,7 @@
 {
 	GtkWidget *menu_item;
 	char *item_text;
-	double *zoom_level_ptr;
+	float *zoom_level_ptr;
 	GSList *radio_item_group;
 	int percent;
 	
@@ -514,7 +561,7 @@
 		: gtk_radio_menu_item_get_group (previous_radio_item);
 	menu_item = gtk_radio_menu_item_new_with_label (radio_item_group, item_text);
 
-	zoom_level_ptr = g_new (double, 1);
+	zoom_level_ptr = g_new (float, 1);
 	*zoom_level_ptr = zoom_level;
 
 	gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), 
@@ -563,7 +610,9 @@
 	if (event->type != GDK_BUTTON_PRESS) {
 		return FALSE;
 	}
-	
+
+	gtk_widget_grab_focus (widget);
+
 	/* check for the context menu button and handle by creating and showing the menu */  
 	if (event->button == CONTEXTUAL_MENU_BUTTON) {
 		eel_pop_up_context_menu (create_zoom_menu (zoom_control), 
@@ -605,6 +654,23 @@
   	return FALSE;
 }
 
+static AtkObject *
+nautilus_zoom_control_get_accessible (GtkWidget *widget)
+{
+	AtkObject *accessible;
+	
+	accessible = eel_accessibility_get_atk_object (widget);
+
+	if (accessible) {
+		return accessible;
+	}
+	
+	accessible = g_object_new 
+		(nautilus_zoom_control_accessible_get_type (), NULL);
+	
+	return eel_accessibility_set_atk_object_return (widget, accessible);
+}
+
 static gboolean
 nautilus_zoom_control_motion_notify (GtkWidget *widget, GdkEventMotion *event)
 {
@@ -651,8 +717,28 @@
 	nautilus_zoom_control_update_offsets (zoom_control);
 }
 
+static void
+nautilus_zoom_control_change_value (NautilusZoomControl *zoom_control, 
+				    GtkScrollType scroll)
+{
+	switch (scroll) {
+	case GTK_SCROLL_STEP_DOWN :
+		if (nautilus_zoom_control_can_zoom_out (zoom_control)) {
+			g_signal_emit (zoom_control, signals[ZOOM_OUT], 0);
+		}
+		break;
+	case GTK_SCROLL_STEP_UP :
+		if (nautilus_zoom_control_can_zoom_in (zoom_control)) {
+			g_signal_emit (zoom_control, signals[ZOOM_IN], 0);
+		}
+		break;
+	default :
+		g_warning ("Invalid scroll type %d for NautilusZoomControl:change_value", scroll);
+	}
+}
+
 void
-nautilus_zoom_control_set_zoom_level (NautilusZoomControl *zoom_control, double zoom_level)
+nautilus_zoom_control_set_zoom_level (NautilusZoomControl *zoom_control, float zoom_level)
 {
 	zoom_control->details->zoom_level = zoom_level;
 	gtk_widget_queue_draw (GTK_WIDGET (zoom_control));
@@ -660,8 +746,8 @@
 
 void
 nautilus_zoom_control_set_parameters (NautilusZoomControl *zoom_control,
-				      double min_zoom_level,
-				      double max_zoom_level,
+				      float min_zoom_level,
+				      float max_zoom_level,
 				      gboolean has_min_zoom_level,
 				      gboolean has_max_zoom_level,
 				      GList *zoom_levels)
@@ -677,19 +763,19 @@
 	gtk_widget_queue_draw (GTK_WIDGET (zoom_control));
 }
 
-double
+float
 nautilus_zoom_control_get_zoom_level (NautilusZoomControl *zoom_control)
 {
 	return zoom_control->details->zoom_level;
 }
 
-double
+float
 nautilus_zoom_control_get_min_zoom_level (NautilusZoomControl *zoom_control)
 {
 	return zoom_control->details->min_zoom_level;
 }
 
-double
+float
 nautilus_zoom_control_get_max_zoom_level (NautilusZoomControl *zoom_control)
 {
 	return zoom_control->details->max_zoom_level;
@@ -727,6 +813,7 @@
 nautilus_zoom_control_class_init (NautilusZoomControlClass *class)
 {
 	GtkWidgetClass *widget_class;
+	GtkBindingSet *binding_set;
 
 	G_OBJECT_CLASS (class)->finalize = nautilus_zoom_control_finalize;
 
@@ -737,7 +824,10 @@
 	widget_class->motion_notify_event = nautilus_zoom_control_motion_notify;
 	widget_class->size_allocate = nautilus_zoom_control_size_allocate;
   	widget_class->leave_notify_event = nautilus_zoom_control_leave_notify;
+	widget_class->get_accessible = nautilus_zoom_control_get_accessible;
 	
+	class->change_value = nautilus_zoom_control_change_value;
+
 	signals[ZOOM_IN] =
 		g_signal_new ("zoom_in",
 		              G_TYPE_FROM_CLASS (class),
@@ -765,18 +855,275 @@
 		              G_STRUCT_OFFSET (NautilusZoomControlClass,
 					       zoom_to_level),
 		              NULL, NULL,
-		              nautilus_marshal_VOID__DOUBLE,
+		              g_cclosure_marshal_VOID__FLOAT,
 		              G_TYPE_NONE,
 			      1,
-			      G_TYPE_DOUBLE);
+			      G_TYPE_FLOAT);
 
 	signals[ZOOM_TO_FIT] =
 		g_signal_new ("zoom_to_fit",
 		              G_TYPE_FROM_CLASS (class),
-		              G_SIGNAL_RUN_LAST,
+		              G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
 		              G_STRUCT_OFFSET (NautilusZoomControlClass,
 					       zoom_to_fit),
 		              NULL, NULL,
 		              g_cclosure_marshal_VOID__VOID,
 		              G_TYPE_NONE, 0);
+
+	signals[CHANGE_VALUE] =
+		g_signal_new ("change_value",
+		              G_TYPE_FROM_CLASS (class),
+		              G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+		              G_STRUCT_OFFSET (NautilusZoomControlClass,
+					       change_value),
+		              NULL, NULL,
+		              g_cclosure_marshal_VOID__ENUM,
+		              G_TYPE_NONE, 1, GTK_TYPE_SCROLL_TYPE);
+
+	binding_set = gtk_binding_set_by_class (class);	
+
+	gtk_binding_entry_add_signal (binding_set, 
+				      GDK_KP_Subtract, 0, 
+				      "change_value",
+				      1, GTK_TYPE_SCROLL_TYPE, 
+				      GTK_SCROLL_STEP_DOWN);
+	gtk_binding_entry_add_signal (binding_set, 
+				      GDK_minus, 0,
+				      "change_value",
+				      1, GTK_TYPE_SCROLL_TYPE, 
+				      GTK_SCROLL_STEP_DOWN);
+
+	gtk_binding_entry_add_signal (binding_set, 
+				      GDK_KP_Equal, 0, 
+				      "zoom_to_fit",
+				      0);
+	gtk_binding_entry_add_signal (binding_set, 
+				      GDK_KP_Equal, 0, 
+				      "zoom_to_fit",
+				      0);
+
+	gtk_binding_entry_add_signal (binding_set, 
+				      GDK_KP_Add, 0, 
+				      "change_value",
+				      1, GTK_TYPE_SCROLL_TYPE,
+				      GTK_SCROLL_STEP_UP);
+	gtk_binding_entry_add_signal (binding_set, 
+				      GDK_plus, 0, 
+				      "change_value",
+				      1, GTK_TYPE_SCROLL_TYPE,
+				      GTK_SCROLL_STEP_UP);
+}
+
+static gboolean
+nautilus_zoom_control_accessible_do_action (AtkAction *accessible, int i)
+{
+	GtkWidget *widget;
+	
+	g_return_val_if_fail (i >= 0 && i < NUM_ACTIONS, FALSE);
+
+	widget = GTK_ACCESSIBLE (accessible)->widget;
+	if (!widget) {
+		return FALSE;
+	}
+	
+	g_signal_emit (widget, 
+		       signals[nautilus_zoom_control_accessible_action_signals [i]],
+		       0);
+
+	return TRUE;
+}
+
+static int
+nautilus_zoom_control_accessible_get_n_actions (AtkAction *accessible)
+{
+
+	return NUM_ACTIONS;
+}
+
+static G_CONST_RETURN char *
+nautilus_zoom_control_accessible_action_get_description (AtkAction *accessible, 
+							 int i)
+{
+	g_return_val_if_fail (i >= 0 && i < NUM_ACTIONS, NULL);
+
+	return _(nautilus_zoom_control_accessible_action_descriptions[i]);
+}
+
+static G_CONST_RETURN char *
+nautilus_zoom_control_accessible_action_get_name (AtkAction *accessible, 
+						  int i)
+{
+	g_return_val_if_fail (i >= 0 && i < NUM_ACTIONS, NULL);
+
+	return _(nautilus_zoom_control_accessible_action_names[i]);
+}
+
+static void
+nautilus_zoom_control_accessible_action_interface_init (AtkActionIface *iface)
+{
+        iface->do_action = nautilus_zoom_control_accessible_do_action;
+        iface->get_n_actions = nautilus_zoom_control_accessible_get_n_actions;
+	iface->get_description = nautilus_zoom_control_accessible_action_get_description;
+        iface->get_name = nautilus_zoom_control_accessible_action_get_name;
+}
+
+static void
+nautilus_zoom_control_accessible_get_current_value (AtkValue *accessible,
+						    GValue *value)
+{
+	NautilusZoomControl *control;
+
+	g_value_init (value, G_TYPE_FLOAT);
+	
+	control = NAUTILUS_ZOOM_CONTROL (GTK_ACCESSIBLE (accessible)->widget);
+	if (!control) {
+		g_value_set_float (value, 0.0);
+		return;
+	}
+
+	g_value_set_float (value, control->details->zoom_level);
+}
+
+static void
+nautilus_zoom_control_accessible_get_maximum_value (AtkValue *accessible,
+						    GValue *value)
+{
+	NautilusZoomControl *control;
+
+	g_value_init (value, G_TYPE_FLOAT);
+	
+	control = NAUTILUS_ZOOM_CONTROL (GTK_ACCESSIBLE (accessible)->widget);
+	if (!control) {
+		g_value_set_float (value, 0.0);
+		return;
+	}
+
+	g_value_set_float (value, control->details->max_zoom_level);
+}
+
+static void
+nautilus_zoom_control_accessible_get_minimum_value (AtkValue *accessible,
+						    GValue *value)
+{
+	NautilusZoomControl *control;
+	
+	g_value_init (value, G_TYPE_FLOAT);
+
+	control = NAUTILUS_ZOOM_CONTROL (GTK_ACCESSIBLE (accessible)->widget);
+	if (!control) {
+		g_value_set_float (value, 0.0);
+		return;
+	}
+
+	g_value_set_float (value, control->details->min_zoom_level);
+}
+
+static float
+nearest_preferred (NautilusZoomControl *zoom_control, float value)
+{
+	float last_value;
+	float current_value;
+	GList *l;
+
+	if (!zoom_control->details->preferred_zoom_levels) {
+		return value;
+	}
+
+	last_value = * (float *)zoom_control->details->preferred_zoom_levels->data;
+
+	for (l = zoom_control->details->preferred_zoom_levels; l != NULL; l = l->next) {
+		current_value = * (float*)l->data;
+		
+		if (current_value > value) {
+			float center = (last_value + current_value) / 2;
+			
+			return (value < center) ? last_value : current_value;
+				
+		}
+		
+		last_value = current_value;
+	}
+
+	return current_value;
+}
+
+static gboolean
+nautilus_zoom_control_accessible_set_current_value (AtkValue *accessible,
+						    const GValue *value)
+{
+	NautilusZoomControl *control;
+	float zoom;
+
+	control = NAUTILUS_ZOOM_CONTROL (GTK_ACCESSIBLE (accessible)->widget);
+	if (!control) {
+		return FALSE;
+	}
+
+	zoom = nearest_preferred (control, g_value_get_float (value));
+
+	g_signal_emit (control, signals[ZOOM_TO_LEVEL], 0, zoom);
+
+	return TRUE;
+}
+
+static void
+nautilus_zoom_control_accessible_value_interface_init (AtkValueIface *iface)
+{
+	iface->get_current_value = nautilus_zoom_control_accessible_get_current_value;
+	iface->get_maximum_value = nautilus_zoom_control_accessible_get_maximum_value;
+	iface->get_minimum_value = nautilus_zoom_control_accessible_get_minimum_value;
+	iface->set_current_value = nautilus_zoom_control_accessible_set_current_value;
+}
+
+static G_CONST_RETURN char *
+nautilus_zoom_control_accessible_get_name (AtkObject *accessible)
+{
+	return _("Zoom");
+}
+
+static G_CONST_RETURN char *
+nautilus_zoom_control_accessible_get_description (AtkObject *accessible)
+{
+	return _("Set the zoom level of the current view");
+}
+
+static void
+nautilus_zoom_control_accessible_class_init (AtkObjectClass *klass)
+{	
+	accessible_parent_class = g_type_class_peek_parent (klass);
+
+	klass->get_name = nautilus_zoom_control_accessible_get_name;
+	klass->get_description = nautilus_zoom_control_accessible_get_description;
+}
+
+static GType
+nautilus_zoom_control_accessible_get_type (void)
+{
+	static GType type = 0;
+	
+	if (!type) {
+		static GInterfaceInfo atk_action_info = {
+			(GInterfaceInitFunc)nautilus_zoom_control_accessible_action_interface_init,
+			(GInterfaceFinalizeFunc)NULL,
+			NULL
+		};
+		
+		static GInterfaceInfo atk_value_info = {
+			(GInterfaceInitFunc)nautilus_zoom_control_accessible_value_interface_init,
+			(GInterfaceFinalizeFunc)NULL,
+			NULL
+		};
+		
+		type = eel_accessibility_create_derived_type
+			("NautilusZoomControlAccessible",
+			 GTK_TYPE_EVENT_BOX,
+			 nautilus_zoom_control_accessible_class_init);
+		
+ 		g_type_add_interface_static (type, ATK_TYPE_ACTION,
+					     &atk_action_info);
+ 		g_type_add_interface_static (type, ATK_TYPE_VALUE,
+					     &atk_value_info);
+	}
+
+	return type;
 }
Index: src/nautilus-zoom-control.h
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-zoom-control.h,v
retrieving revision 1.15
diff -u -r1.15 nautilus-zoom-control.h
--- src/nautilus-zoom-control.h	8 Mar 2002 09:29:57 -0000	1.15
+++ src/nautilus-zoom-control.h	24 Apr 2002 20:33:29 -0000
@@ -50,25 +50,30 @@
 	
 	void (*zoom_in)		(NautilusZoomControl *control);
 	void (*zoom_out) 	(NautilusZoomControl *control);
-	void (*zoom_to_level) 	(NautilusZoomControl *control);
+	void (*zoom_to_level) 	(NautilusZoomControl *control,
+				 float zoom_level);
 	void (*zoom_to_fit) 	(NautilusZoomControl *control);
+
+	/* Action signal for keybindings, do not connect to this */
+	void (*change_value)    (NautilusZoomControl *control,
+				 GtkScrollType scroll);
 };
 
 GtkType    nautilus_zoom_control_get_type           (void);
 GtkWidget *nautilus_zoom_control_new                (void);
 
 void       nautilus_zoom_control_set_zoom_level     (NautilusZoomControl *zoom_control,
-						     double               zoom_level);
+						     float                zoom_level);
 void       nautilus_zoom_control_set_parameters     (NautilusZoomControl *zoom_control,
-						     double               min_zoom_level,
-						     double               max_zoom_level,
+						     float                min_zoom_level,
+						     float                max_zoom_level,
 						     gboolean             has_min_zoom_level,
 						     gboolean             has_max_zoom_level,
  						     GList               *zoom_levels);
 
-double     nautilus_zoom_control_get_zoom_level     (NautilusZoomControl *zoom_control);
-double     nautilus_zoom_control_get_min_zoom_level (NautilusZoomControl *zoom_control);
-double     nautilus_zoom_control_get_max_zoom_level (NautilusZoomControl *zoom_control);
+float      nautilus_zoom_control_get_zoom_level     (NautilusZoomControl *zoom_control);
+float      nautilus_zoom_control_get_min_zoom_level (NautilusZoomControl *zoom_control);
+float      nautilus_zoom_control_get_max_zoom_level (NautilusZoomControl *zoom_control);
 gboolean   nautilus_zoom_control_has_min_zoom_level (NautilusZoomControl *zoom_control);
 gboolean   nautilus_zoom_control_has_max_zoom_level (NautilusZoomControl *zoom_control);
 gboolean   nautilus_zoom_control_can_zoom_in        (NautilusZoomControl *zoom_control);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]