Re: EggToolbar



Soeren Sandmann <sandmann daimi au dk> writes:

> Michael Meeks <michael ximian com> writes:
> 
> > 	If you had time; it'd be really great if you could have a
> > quick hack at switching libbonoboui/bonobo/bonobo-ui-toolbar.c to
> > the new toolbar - ultimately, the API requirements there are really
> > rather trivial I think, so - I'm hoping it'll be easy enough - but
> > it might reveal something interesting that we need in GtkToolbar.
> 
> I will have a look at this, but it won't be until after GUADEC at the
> earliest.

I did this today, but the patch is probably not too useful. Actually
doing a port of this API to the new toolbar will take someone with
more knowledge about bonobo and its API guarantees than I have.

These notes should be more useful:

	- the HIG recommends that the toolbar style be overridable on
	  a per-application basis, but the new gtk+ toolbar doesn't
	  really support this in any convenient way.

	  Maybe gtk_toolbar_[un]set_style() should be undeprecated?

        - GtkToolButtons can't do priority_text, because the usability
          people think it's a bad idea:

		http://mail.gnome.org/archives/gtk-devel-list/2002-September/msg00144.html

		http://mail.gnome.org/archives/gtk-devel-list/2002-September/msg00140.html

		http://mail.gnome.org/archives/usability/2002-August/msg00085.html

	- GtkToolItems do not have a minimum width, though you can
          gtk_set_size_request()

        - The GtkToolBar does not allow you to set its style based on
          its orientation (ie., set_hv_styles). Actually GtkToolBar
          doesn't allow you to set the style at all (see above).

	- I didn't have the energy to actually try to create a
	  ToolItem class for BonoboControls, so there may be problems
	  with that

	- BonoboToolbarItems have some signals that GtkToolItems don't: 

		"state_changed"

		"activated" 

	I mapped BonoboToolItem::activated to GtkToolButton::clicked,
	and "state_changed" to GtkToggleToolButton::toggled.

	In both cases a less general widget was used, so there is a
	potential compatibility problem.


Søren

Index: bonobo-ui-sync-toolbar.c
===================================================================
RCS file: /cvs/gnome/libbonoboui/bonobo/bonobo-ui-sync-toolbar.c,v
retrieving revision 1.44
diff -u -p -u -r1.44 bonobo-ui-sync-toolbar.c
--- bonobo-ui-sync-toolbar.c	26 Feb 2003 03:18:02 -0000	1.44
+++ bonobo-ui-sync-toolbar.c	19 Jul 2003 19:36:05 -0000
@@ -25,13 +25,6 @@
 #include <bonobo/bonobo-ui-preferences.h>
 #include <bonobo/bonobo-ui-private.h>
 
-#include <bonobo/bonobo-ui-toolbar.h>
-#include <bonobo/bonobo-ui-toolbar-button-item.h>
-#include <bonobo/bonobo-ui-toolbar-toggle-button-item.h>
-#include <bonobo/bonobo-ui-toolbar-separator-item.h>
-#include <bonobo/bonobo-ui-toolbar-popup-item.h>
-#include <bonobo/bonobo-ui-toolbar-control-item.h>
-
 static GObjectClass *parent_class = NULL;
 
 static GQuark dockitem_id = 0;
@@ -89,12 +82,12 @@ impl_bonobo_ui_sync_toolbar_state (Bonob
 		behavior_array = g_strsplit (behavior, ",", -1);
 		bonobo_ui_node_free_string (behavior);
 
-		bonobo_ui_toolbar_item_set_expandable (
-			BONOBO_UI_TOOLBAR_ITEM (widget),
+		gtk_tool_item_set_expand (
+			GTK_TOOL_ITEM (widget),
 			string_array_contains (behavior_array, "expandable"));
 
-		bonobo_ui_toolbar_item_set_pack_end (
-			BONOBO_UI_TOOLBAR_ITEM (widget),
+		gtk_tool_item_set_pack_end (
+			GTK_TOOL_ITEM (widget),
 			string_array_contains (behavior_array, "pack-end"));
 
 		g_strfreev (behavior_array);
@@ -106,26 +99,29 @@ impl_bonobo_ui_sync_toolbar_state (Bonob
 	} else
 		priority = FALSE;
 
+#if 0 	/* GtkToolbar does not have priority text */
 	bonobo_ui_toolbar_item_set_want_label (
 		BONOBO_UI_TOOLBAR_ITEM (widget), priority);
+#endif
 
 	type  = bonobo_ui_engine_get_attr (node, cmd_node, "type");
 	label = bonobo_ui_engine_get_attr (node, cmd_node, "label");
 	
 	if (!type || !strcmp (type, "toggle")) {
 
-		if (BONOBO_IS_UI_TOOLBAR_BUTTON_ITEM (widget) &&
+		if (GTK_IS_TOOL_BUTTON (widget) &&
 		    (bonobo_ui_node_peek_attr (node, "pixtype") ||
 		     bonobo_ui_node_peek_attr (cmd_node, "pixtype"))) {
 			GtkWidget *image;
-			BonoboUIToolbarButtonItem *button_item;
+			GtkToolButton *button_item;
 
-			button_item = (BonoboUIToolbarButtonItem *) widget;
+			button_item = GTK_TOOL_BUTTON (widget);
 
-			image = bonobo_ui_toolbar_button_item_get_image (button_item);
+			image = gtk_tool_button_get_icon_widget (button_item);
 			if (!image) {
 				image = gtk_image_new ();
-				bonobo_ui_toolbar_button_item_set_image (button_item, image);
+				gtk_tool_button_set_icon_widget (
+					button_item, image);
 			}
 
 			bonobo_ui_util_xml_set_image (
@@ -134,9 +130,9 @@ impl_bonobo_ui_sync_toolbar_state (Bonob
 			gtk_widget_show (image);
 		}
 
-		if (label)
-			bonobo_ui_toolbar_button_item_set_label (
-				BONOBO_UI_TOOLBAR_BUTTON_ITEM (widget), label);
+		if (label) {
+			gtk_tool_button_set_label (GTK_TOOL_BUTTON (widget), label);
+		}
 	}
 
 	bonobo_ui_node_free_string (type);
@@ -153,8 +149,10 @@ impl_bonobo_ui_sync_toolbar_state (Bonob
 		txt = bonobo_ui_node_peek_attr (node, "vdisplay");
 		vdisp = decode_control_disp (txt);
 
+#if 0
 		bonobo_ui_toolbar_control_item_set_display (
 			BONOBO_UI_TOOLBAR_CONTROL_ITEM (widget), hdisp, vdisp);
+#endif
 
 		txt = bonobo_ui_node_peek_attr (node, "sensitive");
 		if (txt)
@@ -162,21 +160,19 @@ impl_bonobo_ui_sync_toolbar_state (Bonob
 		else
 			sensitive = TRUE;
 
-		bonobo_ui_toolbar_control_item_set_sensitive (
-			BONOBO_UI_TOOLBAR_CONTROL_ITEM (widget), sensitive);
+		gtk_widget_set_sensitive (widget, sensitive);
 	}
 
 	if ((min_width = bonobo_ui_engine_get_attr (node, cmd_node, "min_width"))) {
-		bonobo_ui_toolbar_item_set_minimum_width (BONOBO_UI_TOOLBAR_ITEM (widget),
-							  atoi (min_width));
+		gtk_widget_set_size_request (widget, atoi (min_width), -1);
 		bonobo_ui_node_free_string (min_width);
 	}
 	
 	if ((txt = bonobo_ui_engine_get_attr (node, cmd_node, "tip"))) {
-		bonobo_ui_toolbar_item_set_tooltip (
-			BONOBO_UI_TOOLBAR_ITEM (widget),
-			bonobo_ui_toolbar_get_tooltips (
-				BONOBO_UI_TOOLBAR (parent)), txt);
+		gtk_tool_item_set_tooltip (
+			GTK_TOOL_ITEM (widget),
+			GTK_TOOLBAR (parent)->tooltips,
+			txt, NULL);
 
 		bonobo_ui_node_free_string (txt);
 	}
@@ -194,17 +190,22 @@ exec_verb_cb (GtkWidget *item, BonoboUIE
 }
 
 static gint
-win_item_emit_ui_event (BonoboUIToolbarItem *item,
-			const char          *state,
-			BonoboUIEngine      *engine)
+win_item_emit_ui_event (GtkToggleToolButton	*item,
+			BonoboUIEngine          *engine)
 {
+	char *state;
 	BonoboUINode     *node = bonobo_ui_engine_widget_get_node (
 		GTK_WIDGET (item));
 
 	g_return_val_if_fail (node != NULL, FALSE);
 
+	state = g_strdup_printf (
+		"%d", gtk_toggle_tool_button_get_active (item));
+	
 	bonobo_ui_engine_emit_event_on (engine, node, state);
 
+	g_free (state);
+
 	return FALSE;
 }
 
@@ -233,11 +234,8 @@ toolbar_build_control (BonoboUISync     
 			sync->engine, node);
 
 		if (control != CORBA_OBJECT_NIL) {
-			item = bonobo_ui_toolbar_control_item_new (control);
-
-			if (!item)
-				return NULL;
-
+			item = GTK_WIDGET (gtk_tool_button_new ("CTRL", NULL));
+			
 			bonobo_ui_engine_stamp_custom (
 				sync->engine, node);
 		} else
@@ -246,9 +244,8 @@ toolbar_build_control (BonoboUISync     
 
 	gtk_widget_show (item);
 
-	bonobo_ui_toolbar_insert (BONOBO_UI_TOOLBAR (parent),
-				  BONOBO_UI_TOOLBAR_ITEM (item),
-				  (*pos)++);
+	gtk_toolbar_insert (
+		GTK_TOOLBAR (parent), GTK_TOOL_ITEM (item), (*pos)++);
 
 	return item;
 }
@@ -261,7 +258,7 @@ toolbar_build_widget (BonoboUISync *sync
 		      GtkWidget    *parent)
 {
 	char         *type, *stock_id;
-	GtkWidget    *item;
+	GtkToolItem  *item;
 
 	g_return_val_if_fail (sync != NULL, NULL);
 	g_return_val_if_fail (node != NULL, NULL);
@@ -303,16 +300,14 @@ toolbar_build_widget (BonoboUISync *sync
 	}
 
 	if (bonobo_ui_node_has_name (node, "separator")) {
-		item = bonobo_ui_toolbar_separator_item_new ();
-		gtk_widget_set_sensitive (item, FALSE);
+		item = gtk_separator_tool_item_new ();
+		gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
 
-	} else if (!type)
-		item = bonobo_ui_toolbar_button_item_new (NULL, NULL);
-	
-	else if (!strcmp (type, "toggle"))
-		item = bonobo_ui_toolbar_toggle_button_item_new (NULL, NULL);
-	
-	else {
+	} else if (!type) {
+		item = gtk_tool_button_new (NULL, NULL);
+	} else if (!strcmp (type, "toggle")) {
+		item = gtk_toggle_tool_button_new ();
+	} else {
 		/* FIXME: Implement radio-toolbars */
 		g_warning ("Invalid type '%s'", type);
 		return NULL;
@@ -320,12 +315,11 @@ toolbar_build_widget (BonoboUISync *sync
 
 	bonobo_ui_node_free_string (type);
 	
-	bonobo_ui_toolbar_insert (BONOBO_UI_TOOLBAR (parent),
-				  BONOBO_UI_TOOLBAR_ITEM (item),
-				  (*pos)++);
-	gtk_widget_show (item);
+	gtk_toolbar_insert (
+		GTK_TOOLBAR (parent), GTK_TOOL_ITEM (item), (*pos)++);
+	gtk_widget_show (GTK_WIDGET (item));
 
-	return item;
+	return GTK_WIDGET (item);
 }
 
 static GtkWidget *
@@ -345,18 +339,20 @@ impl_bonobo_ui_sync_toolbar_build (Bonob
 		widget = toolbar_build_widget (
 			sync, node, cmd_node, pos, parent);
 
-	if (widget) {
+	if (widget && GTK_IS_TOOL_BUTTON (widget)) {
 		/* FIXME: What about "id"s ! ? */
 		if ((verb = bonobo_ui_engine_get_attr (node, NULL, "verb"))) {
-			g_signal_connect (GTK_OBJECT (widget), "activate",
-					    (GtkSignalFunc) exec_verb_cb,
-					    sync->engine);
+			g_signal_connect (G_OBJECT (widget), "clicked",
+					  (GCallback) exec_verb_cb,
+					  sync->engine);
 			bonobo_ui_node_free_string (verb);
 		}
 		
-		g_signal_connect (GTK_OBJECT (widget), "state_altered",
-				    (GtkSignalFunc) win_item_emit_ui_event,
-				    sync->engine);
+		if (GTK_IS_TOGGLE_TOOL_BUTTON (widget)) {
+			g_signal_connect (G_OBJECT (widget), "toggled",
+					  (GCallback) win_item_emit_ui_event,
+					  sync->engine);
+		}
 	}
 
 	return widget;
@@ -369,16 +365,14 @@ impl_bonobo_ui_sync_toolbar_build_placeh
 					       int              *pos,
 					       GtkWidget        *parent)
 {
-	GtkWidget *widget;
+	GtkToolItem *item;
 
-	widget = bonobo_ui_toolbar_separator_item_new ();
-	gtk_widget_set_sensitive (widget, FALSE);
+	item = gtk_separator_tool_item_new ();
+	gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
 	
-	bonobo_ui_toolbar_insert (BONOBO_UI_TOOLBAR (parent),
-				  BONOBO_UI_TOOLBAR_ITEM (widget),
-				  (*pos)++);
+	gtk_toolbar_insert (GTK_TOOLBAR (parent), item, (*pos)++);
 
-	return widget;
+	return GTK_WIDGET (item);
 }
 
 static BonoboDockItem *
@@ -395,12 +389,21 @@ get_dock_item (BonoboUISyncToolbar *sync
 					    &dummy, &dummy);
 }
 
+static void
+prepend_child (GtkWidget *child, gpointer data)
+{
+	GList **children = data;
+	
+	*children = g_list_prepend (*children, child);
+}
+
 static GList *
 impl_bonobo_ui_sync_toolbar_get_widgets (BonoboUISync *sync,
 					 BonoboUINode *node)
 {
 	const char     *dockname;
 	BonoboDockItem *item;
+	GList	       *children;
 
 	dockname = bonobo_ui_node_peek_attr (node, "name");
 	item = get_dock_item (BONOBO_UI_SYNC_TOOLBAR (sync), dockname);
@@ -410,8 +413,12 @@ impl_bonobo_ui_sync_toolbar_get_widgets 
 		return NULL;
 	}
 
-	return bonobo_ui_toolbar_get_children (
-		BONOBO_UI_TOOLBAR (GTK_BIN (item)->child));
+	children = NULL;
+	gtk_container_foreach (GTK_CONTAINER (GTK_BIN (item)->child),
+			       prepend_child, &children);
+	children = g_list_reverse (children);
+
+	return children;
 }
 
 static void
@@ -422,16 +429,17 @@ impl_bonobo_ui_sync_toolbar_state_update
 	g_return_if_fail (widget != NULL);
 
 	if (new_state) {
-		if (BONOBO_IS_UI_TOOLBAR_ITEM (widget))
-			bonobo_ui_toolbar_item_set_state (
-				BONOBO_UI_TOOLBAR_ITEM (widget), new_state);
-		
-		else
+		if (GTK_IS_TOGGLE_TOOL_BUTTON (widget)) {
+			gint is_active = atoi (new_state);
+			gtk_toggle_tool_button_set_active (
+				GTK_TOGGLE_TOOL_BUTTON (widget), is_active);
+		} else {
 			g_warning ("TESTME: strange, setting "
 				   "state '%s' on weird object '%s'",
 				   new_state,
 				   g_type_name_from_instance (
 					   (GTypeInstance *) widget));
+		}
 	}
 }
 
@@ -452,7 +460,7 @@ static gboolean
 impl_bonobo_ui_sync_toolbar_ignore_widget (BonoboUISync *sync,
 					   GtkWidget    *widget)
 {
-	return BONOBO_IS_UI_TOOLBAR_POPUP_ITEM (widget);
+	return FALSE;
 }
 
 static BonoboUIToolbarStyle
@@ -490,8 +498,8 @@ bonobo_ui_sync_toolbar_get_look (BonoboU
 
 		widget = bonobo_ui_engine_node_get_widget (engine, node);
 
-		if (!widget || !BONOBO_IS_UI_TOOLBAR (widget) ||
-		    bonobo_ui_toolbar_get_orientation (BONOBO_UI_TOOLBAR (widget)) ==
+		if (!widget || !GTK_IS_TOOLBAR (widget) ||
+		    gtk_toolbar_get_orientation (GTK_TOOLBAR (widget)) ==
 		    GTK_ORIENTATION_HORIZONTAL) {
 			txt = bonobo_ui_node_peek_attr (node, "hlook");
 			look = parse_look (txt);
@@ -620,7 +628,7 @@ create_dockitem (BonoboUISyncToolbar *sy
 	guint offset = 0;
 	gboolean in_new_band = TRUE;
 	gboolean can_config = TRUE;
-	BonoboUIToolbar *toolbar;
+	GtkToolbar *toolbar;
 
 	if ((prop = bonobo_ui_node_peek_attr (node, "behavior"))) {
 		behavior_array = g_strsplit (prop, ",", -1);
@@ -681,9 +689,8 @@ create_dockitem (BonoboUISyncToolbar *sy
 			      position, offset, in_new_band);
 
 		
-	toolbar = BONOBO_UI_TOOLBAR (bonobo_ui_toolbar_new ());
+	toolbar = GTK_TOOLBAR (gtk_toolbar_new ());
 
-	gtk_container_set_border_width (GTK_CONTAINER (toolbar), 2);
 	gtk_container_add (GTK_CONTAINER (item),
 			   GTK_WIDGET (toolbar));
 	gtk_widget_show (GTK_WIDGET (toolbar));
@@ -728,6 +735,45 @@ impl_bonobo_ui_sync_toolbar_remove_root 
 }
 
 static void
+set_toolbar_style (GtkToolbar           *toolbar,
+		   BonoboUIToolbarStyle  style)
+{
+	GtkToolbarStyle gtk_style;
+	
+	/* Notes:
+	 *
+	 *	- The GtkToolbar doesn't allow you to set styles
+	 *        on a horizontal/vertical basis.
+	 *
+	 *	- The GtkToolbar does not support priority text
+	 */
+	switch (style) {
+
+	case BONOBO_UI_TOOLBAR_STYLE_PRIORITY_TEXT:
+		gtk_style = GTK_TOOLBAR_BOTH_HORIZ;
+		break;
+
+	case BONOBO_UI_TOOLBAR_STYLE_ICONS_AND_TEXT:
+		gtk_style = GTK_TOOLBAR_BOTH;
+		break;
+		
+	case BONOBO_UI_TOOLBAR_STYLE_ICONS_ONLY:
+		gtk_style = GTK_TOOLBAR_ICONS;
+		break;
+		
+	case BONOBO_UI_TOOLBAR_STYLE_TEXT_ONLY:
+		gtk_style = GTK_TOOLBAR_TEXT;
+		break;
+
+	default:
+		gtk_style = GTK_TOOLBAR_BOTH;
+		break;
+	}
+	
+	gtk_toolbar_set_style (toolbar, gtk_style);
+}
+
+static void
 impl_bonobo_ui_sync_toolbar_update_root (BonoboUISync *sync,
 					 BonoboUINode *node)
 {
@@ -736,7 +782,7 @@ impl_bonobo_ui_sync_toolbar_update_root 
 	gboolean    tooltips;
 	gboolean    detachable;
 	BonoboDockItem *item;
-	BonoboUIToolbar *toolbar;
+	GtkToolbar *toolbar;
 	BonoboUIToolbarStyle look;
 
 	dockname = bonobo_ui_node_peek_attr (node, "name");
@@ -756,13 +802,13 @@ impl_bonobo_ui_sync_toolbar_update_root 
 		detachable = bonobo_ui_preferences_get_toolbar_detachable ();
 	bonobo_dock_item_set_locked (item, !detachable);
 
-	toolbar = BONOBO_UI_TOOLBAR (GTK_BIN (item)->child);
+	toolbar = GTK_TOOLBAR (GTK_BIN (item)->child);
 
 	bonobo_ui_engine_stamp_root (sync->engine, node, GTK_WIDGET (toolbar));
 
 	if ((txt = bonobo_ui_node_peek_attr (node, "look"))) {
 		look = parse_look (txt);
-		bonobo_ui_toolbar_set_hv_styles (toolbar, look, look);
+		set_toolbar_style (toolbar, look);
 
 	} else {
 		BonoboUIToolbarStyle vlook, hlook;
@@ -773,7 +819,7 @@ impl_bonobo_ui_sync_toolbar_update_root 
 		txt = bonobo_ui_node_peek_attr (node, "vlook");
 		vlook = parse_look (txt);
 
-		bonobo_ui_toolbar_set_hv_styles (toolbar, hlook, vlook);
+		set_toolbar_style (toolbar, hlook);
 	}		
 
 #if 0
@@ -798,7 +844,7 @@ impl_bonobo_ui_sync_toolbar_update_root 
 	else
 		tooltips = TRUE;
 
-	bonobo_ui_toolbar_show_tooltips (toolbar, tooltips);
+	gtk_toolbar_set_tooltips (toolbar, tooltips);
 
        /*
 	* FIXME: It shouldn't be necessary to explicitly resize the
@@ -823,12 +869,17 @@ impl_bonobo_ui_sync_toolbar_can_handle (
 		node->name_id == toolitem_id);
 }
 
-GtkWidget *
+static GtkWidget *
 impl_bonobo_ui_sync_toolbar_wrap_widget (BonoboUISync *sync,
 					 GtkWidget    *custom_widget)
 {
-	if (!BONOBO_IS_UI_TOOLBAR_ITEM (custom_widget))
-		return bonobo_ui_toolbar_control_item_new_widget (custom_widget);
+	GtkToolItem *item;
+	
+	if (!GTK_IS_TOOL_ITEM (custom_widget)) {
+		item = gtk_tool_item_new ();
+		gtk_container_add (GTK_CONTAINER (item), custom_widget);
+		return GTK_WIDGET (item);
+	}
 	else
 		return custom_widget;
 }


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