? test-toolbar.ssp.c
? tooldiff
Index: eggtoolbar.c
===================================================================
RCS file: /cvs/gnome/libegg/libegg/toolbar/eggtoolbar.c,v
retrieving revision 1.21
diff -u -p -u -r1.21 eggtoolbar.c
--- eggtoolbar.c	6 Mar 2003 00:56:01 -0000	1.21
+++ eggtoolbar.c	21 Mar 2003 20:36:54 -0000
@@ -32,6 +32,9 @@
 #include <gtk/gtkmenu.h>
 #include <gtk/gtkradiobutton.h>
 #include <gtk/gtktoolbar.h>
+#include <gtk/gtkbindings.h>
+#include <gdk/gdkkeysyms.h>
+#include "../util/eggmarshalers.h"
 
 #define DEFAULT_IPADDING 0
 #define DEFAULT_SPACE_SIZE  5
@@ -64,6 +67,7 @@ enum {
   ORIENTATION_CHANGED,
   STYLE_CHANGED,
   POPUP_CONTEXT_MENU,
+  MOVE_FOCUS,
   LAST_SIGNAL
 };
 
@@ -90,7 +94,6 @@ static void     egg_toolbar_style_set   
 					    GtkStyle         *prev_style);
 static void     egg_toolbar_direction_changed (GtkWidget        *widget,
                                                GtkTextDirection  previous_direction);
-
 static gboolean egg_toolbar_focus          (GtkWidget        *widget,
 					    GtkDirectionType  dir);
 static void     egg_toolbar_screen_changed (GtkWidget        *widget,
@@ -106,12 +109,14 @@ static void  egg_toolbar_forall     (Gtk
 				     gpointer      callback_data);
 static GType egg_toolbar_child_type (GtkContainer *container);
 
-
 static void egg_toolbar_real_orientation_changed (EggToolbar      *toolbar,
 						  GtkOrientation   orientation);
 static void egg_toolbar_real_style_changed       (EggToolbar      *toolbar,
 						  GtkToolbarStyle  style);
 
+static gboolean egg_toolbar_move_focus (EggToolbar       *toolbar,
+					GtkDirectionType  dir);
+
 static gboolean             egg_toolbar_button_press         (GtkWidget      *button,
 							      GdkEventButton *event,
 							      EggToolbar     *toolbar);
@@ -186,11 +191,27 @@ egg_toolbar_get_type (void)
 }
 
 static void
+add_arrow_bindings (GtkBindingSet   *binding_set,
+		    guint            keysym,
+		    GtkDirectionType dir)
+{
+  guint keypad_keysym = keysym - GDK_Left + GDK_KP_Left;
+  
+  gtk_binding_entry_add_signal (binding_set, keysym, 0,
+                                "move_focus", 1,
+                                GTK_TYPE_DIRECTION_TYPE, dir);
+  gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
+                                "move_focus", 1,
+                                GTK_TYPE_DIRECTION_TYPE, dir);
+}
+
+static void
 egg_toolbar_class_init (EggToolbarClass *klass)
 {
   GObjectClass *gobject_class;
   GtkWidgetClass *widget_class;
   GtkContainerClass *container_class;
+  GtkBindingSet *binding_set;
 
   parent_class = g_type_class_peek_parent (klass);
   
@@ -217,7 +238,8 @@ egg_toolbar_class_init (EggToolbarClass 
   
   klass->orientation_changed = egg_toolbar_real_orientation_changed;
   klass->style_changed = egg_toolbar_real_style_changed;
-
+  klass->move_focus = egg_toolbar_move_focus;
+  
   toolbar_signals[ORIENTATION_CHANGED] =
     g_signal_new ("orientation_changed",
 		  G_OBJECT_CLASS_TYPE (klass),
@@ -245,6 +267,15 @@ egg_toolbar_class_init (EggToolbarClass 
 		  NULL, NULL,
 		  g_cclosure_marshal_VOID__VOID,
 		  G_TYPE_NONE, 0);
+  toolbar_signals[MOVE_FOCUS] =
+    g_signal_new ("move_focus",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                  G_STRUCT_OFFSET (EggToolbarClass, move_focus),
+                  NULL, NULL,
+                  _egg_marshal_BOOLEAN__ENUM,
+                  G_TYPE_BOOLEAN, 1,
+                  GTK_TYPE_DIRECTION_TYPE);
   
   g_object_class_install_property (gobject_class,
 				   PROP_ORIENTATION,
@@ -325,6 +356,13 @@ egg_toolbar_class_init (EggToolbarClass 
                                                     GTK_TYPE_ICON_SIZE,
                                                     DEFAULT_ICON_SIZE,
                                                     G_PARAM_READWRITE));  
+
+  binding_set = gtk_binding_set_by_class (klass);
+
+  add_arrow_bindings (binding_set, GDK_Left, GTK_DIR_LEFT);
+  add_arrow_bindings (binding_set, GDK_Right, GTK_DIR_RIGHT);
+  add_arrow_bindings (binding_set, GDK_Up, GTK_DIR_UP);
+  add_arrow_bindings (binding_set, GDK_Down, GTK_DIR_DOWN);
 }
 
 static void
@@ -348,7 +386,10 @@ egg_toolbar_init (EggToolbar *toolbar)
 		    G_CALLBACK (egg_toolbar_arrow_button_press), toolbar);
   gtk_button_set_relief (GTK_BUTTON (priv->button),
 			 get_button_relief (toolbar));
+#if 0
+  /* this should be done by some kind of button property, imo */
   GTK_WIDGET_UNSET_FLAGS (priv->button, GTK_CAN_FOCUS);
+#endif
   
   priv->arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
   gtk_widget_show (priv->arrow);
@@ -1046,7 +1087,7 @@ egg_toolbar_style_set (GtkWidget *widget
 		       GtkStyle  *prev_style)
 {
   if (GTK_WIDGET_REALIZED (widget))
-      gtk_style_set_background (widget->style, widget->window, widget->state);
+    gtk_style_set_background (widget->style, widget->window, widget->state);
 
   if (prev_style)
     egg_toolbar_update_button_relief (EGG_TOOLBAR (widget));
@@ -1070,13 +1111,93 @@ egg_toolbar_direction_changed (GtkWidget
   GTK_WIDGET_CLASS (parent_class)->direction_changed (widget, previous_dir);
 }
 
+static GList *
+egg_toolbar_list_items_in_focus_order (EggToolbar       *toolbar,
+				       GtkDirectionType  dir)
+{
+  EggToolbarPrivate *priv = EGG_TOOLBAR_GET_PRIVATE (toolbar);
+  GList *result = NULL;
+  GList *list;
+
+  for (list = priv->items; list != NULL; list = list->next)
+    {
+      EggToolItem *item = list->data;
+      if (!item->pack_end)
+	result = g_list_prepend (result, item);
+    }
+
+  for (list = priv->items; list != NULL; list = list->next)
+    {
+      EggToolItem *item = list->data;
+
+      if (item->pack_end)
+	result = g_list_prepend (result, item);
+    }
+
+  if (dir == GTK_DIR_RIGHT || dir == GTK_DIR_DOWN || dir == GTK_DIR_TAB_FORWARD)
+    result = g_list_reverse (result);
+
+  return result;
+}
+
+static gboolean
+egg_toolbar_move_focus (EggToolbar       *toolbar,
+			GtkDirectionType  dir)
+{
+  GList *list;
+  gboolean retval = FALSE;
+  gboolean try_focus = FALSE;
+  GList *items = egg_toolbar_list_items_in_focus_order (toolbar, dir);
+  
+  for (list = items; list != NULL; list = list->next)
+    {
+      GtkWidget *tool_item = list->data;
+      
+      if (try_focus && tool_item && gtk_widget_child_focus (tool_item, dir))
+	{
+	  retval = TRUE;
+	  break;
+	}
+
+      if (tool_item == GTK_CONTAINER (toolbar)->focus_child)
+	try_focus = TRUE;
+    }
+
+  g_list_free (items);
+  return retval;
+}
+
 static gboolean
 egg_toolbar_focus (GtkWidget        *widget,
 		   GtkDirectionType  dir)
 {
-  /* Focus can't go in toolbars */
+  EggToolbar *toolbar = EGG_TOOLBAR (widget);
+  GList *items;
+  gboolean retval = FALSE;
+
+  if (GTK_CONTAINER (widget)->focus_child)
+    return FALSE;
+
+  items = egg_toolbar_list_items_in_focus_order (toolbar, dir);
+
+  if (items)
+    retval = gtk_widget_child_focus (items->data, dir);
+
+  g_list_free (items);
   
-  return FALSE;
+  return retval;
+}
+
+static gboolean
+egg_toolbar_key_press (GtkWidget        *widget,
+		       GdkEventKey      *event)
+{
+
+  
+  
+  
+  
+  return (* GTK_WIDGET_CLASS (parent_class)->key_press_event) (widget, event);
 }
 
 static void
@@ -1513,7 +1634,9 @@ egg_toolbar_insert_tool_item (EggToolbar
   egg_tool_item_set_relief_style (item, get_button_relief (toolbar));
   
   gtk_widget_set_parent (GTK_WIDGET (item), GTK_WIDGET (toolbar));
+#if 0
   GTK_WIDGET_UNSET_FLAGS (item, GTK_CAN_FOCUS);  
+#endif
 }
 
 void
Index: eggtoolbar.h
===================================================================
RCS file: /cvs/gnome/libegg/libegg/toolbar/eggtoolbar.h,v
retrieving revision 1.10
diff -u -p -u -r1.10 eggtoolbar.h
--- eggtoolbar.h	27 Feb 2003 00:35:43 -0000	1.10
+++ eggtoolbar.h	21 Mar 2003 20:36:59 -0000
@@ -98,17 +98,19 @@ struct _EggToolbarClass
 {
   GtkContainerClass parent_class;
 
-  void (* orientation_changed) (EggToolbar      *toolbar,
-				GtkOrientation   orientation);
-  void (* style_changed)       (EggToolbar      *toolbar,
-				GtkToolbarStyle  style);
-  void (* popup_context_menu)  (EggToolbar      *toolbar);
+  void (* orientation_changed) (EggToolbar       *toolbar,
+				GtkOrientation    orientation);
+  void (* style_changed)       (EggToolbar       *toolbar,
+				GtkToolbarStyle   style);
+  void (* popup_context_menu)  (EggToolbar       *toolbar);
 
+  gboolean (* move_focus)          (EggToolbar       *toolbar,
+				    GtkDirectionType  dir);
+  
   /* Padding for future expansion */
   void (*_gtk_reserved1) (void);
   void (*_gtk_reserved2) (void);
   void (*_gtk_reserved3) (void);
-  void (*_gtk_reserved4) (void);
 };
 
 GType      egg_toolbar_get_type        (void) G_GNUC_CONST;
Index: eggtoolbutton.c
===================================================================
RCS file: /cvs/gnome/libegg/libegg/toolbar/eggtoolbutton.c,v
retrieving revision 1.12
diff -u -p -u -r1.12 eggtoolbutton.c
--- eggtoolbutton.c	25 Jan 2003 17:38:36 -0000	1.12
+++ eggtoolbutton.c	21 Mar 2003 20:37:01 -0000
@@ -180,7 +180,9 @@ egg_tool_button_init (EggToolButton *but
 
   /* create button */
   button->button = g_object_new (klass->button_type, NULL);
+#if 0
   GTK_WIDGET_UNSET_FLAGS (button->button, GTK_CAN_FOCUS);
+#endif
   g_signal_connect_object (button->button, "clicked",
 			   G_CALLBACK (button_clicked), button, 0);
 
Index: test-toolbar.c
===================================================================
RCS file: /cvs/gnome/libegg/libegg/toolbar/test-toolbar.c,v
retrieving revision 1.13
diff -u -p -u -r1.13 test-toolbar.c
--- test-toolbar.c	29 Dec 2002 15:01:25 -0000	1.13
+++ test-toolbar.c	21 Mar 2003 20:37:01 -0000
@@ -327,11 +327,30 @@ icon_size_history_changed (GtkOptionMenu
   egg_toolbar_set_icon_size (toolbar, icon_size);
 }
 
+static GtkWidget *
+create_location_widget (void)
+{
+  GtkWidget *hbox = gtk_hbox_new (FALSE, 0);
+  GtkWidget *label = gtk_label_new_with_mnemonic ("L_ocation: ");
+  GtkWidget *entry = gtk_entry_new ();
+
+  gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
+  
+  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
+  gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
+
+  gtk_widget_show (label);
+  gtk_widget_show (entry);
+  gtk_widget_show (hbox);
+
+  return hbox;
+}
+
 gint
 main (gint argc, gchar **argv)
 {
   GtkWidget *window, *toolbar, *table, *treeview, *scrolled_window;
-  GtkWidget *hbox, *checkbox, *option_menu, *menu;
+  GtkWidget *handle_box, *hbox, *checkbox, *option_menu, *menu;
   gint i;
   static const gchar *toolbar_styles[] = { "icons", "text", "both (vertical)",
 					   "both (horizontal)" };
@@ -339,6 +358,7 @@ main (gint argc, gchar **argv)
   GtkListStore *store;
   GtkWidget *image;
   GtkWidget *menuitem;
+  GtkWidget *location;
   GSList *group;
   
   gtk_init (&argc, &argv);
@@ -351,7 +371,10 @@ main (gint argc, gchar **argv)
   gtk_container_add (GTK_CONTAINER (window), table);
 
   toolbar = egg_toolbar_new ();
-  gtk_table_attach (GTK_TABLE (table), toolbar,
+  handle_box = gtk_handle_box_new ();
+  gtk_container_add (GTK_CONTAINER (handle_box), toolbar);
+  
+  gtk_table_attach (GTK_TABLE (table), handle_box,
 		    0,2, 0,1, GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);
 
   hbox = gtk_hbox_new (FALSE, 5);
@@ -450,6 +473,12 @@ main (gint argc, gchar **argv)
   add_item_to_list (store, item, "(Custom Item)");    
   egg_toolbar_insert_tool_item (EGG_TOOLBAR (toolbar), item, -1);
 
+  location = create_location_widget ();
+  item = egg_tool_item_new ();
+  gtk_widget_show (location);
+  gtk_container_add (GTK_CONTAINER (item), location);
+  add_item_to_list (store, item, "Location");
+  egg_toolbar_insert_tool_item (EGG_TOOLBAR (toolbar), item, -1);
   
   item = egg_tool_button_new_from_stock (GTK_STOCK_GO_BACK);
   add_item_to_list (store, item, "Back");    
