GtkToolbar stock icons



According to bug 50489 we want GtkToolbar stock icons.

Here is a patch, is this what we want? I'm not particulary pleased with
having the icon_size argument in gtk_toolbar_append_stock(), but since
there are two stock toolbar sizes I see no other way.

The placement of the icon size defines in gtkiconfactory.h is also
somewhat non-obvious.

/ Alex

Index: gtktoolbar.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktoolbar.c,v
retrieving revision 1.45
diff -u -p -r1.45 gtktoolbar.c
--- gtktoolbar.c	2000/12/13 01:34:40	1.45
+++ gtktoolbar.c	2001/02/22 15:58:03
@@ -32,6 +32,9 @@
 #include "gtkvbox.h"
 #include "gtkhbox.h"
 #include "gtktoolbar.h"
+#include "gtkstock.h"
+#include "gtkiconfactory.h"
+#include "gtkimage.h"
 
 
 #define DEFAULT_SPACE_SIZE  5
@@ -752,6 +755,81 @@ gtk_toolbar_insert_item (GtkToolbar    *
 				     icon, callback, user_data,
 				     position);
 }
+
+
+GtkWidget*
+gtk_toolbar_append_stock    (GtkToolbar      *toolbar,
+			     const gchar     *stock_id,
+			     const gchar     *icon_size,
+			     const char      *tooltip_text,
+			     const char      *tooltip_private_text,
+			     GtkSignalFunc    callback,
+			     gpointer         user_data)
+{
+  return gtk_toolbar_insert_stock (toolbar,
+				   stock_id,
+				   icon_size,
+				   tooltip_text, tooltip_private_text,
+				   callback, user_data,
+				   toolbar->num_children);
+}
+
+GtkWidget*
+gtk_toolbar_prepend_stock   (GtkToolbar      *toolbar,
+			     const gchar     *stock_id,
+			     const gchar     *icon_size,
+			     const char      *tooltip_text,
+			     const char      *tooltip_private_text,
+			     GtkSignalFunc    callback,
+			     gpointer         user_data)
+{
+  return gtk_toolbar_insert_stock (toolbar,
+				   stock_id,
+				   icon_size,
+				   tooltip_text, tooltip_private_text,
+				   callback, user_data,
+				   0);
+}
+
+
+GtkWidget*
+gtk_toolbar_insert_stock    (GtkToolbar      *toolbar,
+			     const gchar     *stock_id,
+			     const gchar     *icon_size,
+			     const char      *tooltip_text,
+			     const char      *tooltip_private_text,
+			     GtkSignalFunc    callback,
+			     gpointer         user_data,
+			     gint             position)
+{
+  GtkStockItem item;
+  GtkWidget *image;
+
+  if (gtk_stock_lookup (stock_id, &item))
+    {
+      image = gtk_image_new_from_stock (stock_id, icon_size);
+
+      return gtk_toolbar_insert_item (toolbar,
+				      item.label,
+				      tooltip_text,
+				      tooltip_private_text,
+				      image,
+				      callback,
+				      user_data,
+				      position);
+    }
+  else
+    return gtk_toolbar_insert_item (toolbar,
+				    stock_id,
+				    tooltip_text,
+				    tooltip_private_text,
+				    NULL,
+				    callback,
+				    user_data,
+				    position);
+}
+
+
 
 void
 gtk_toolbar_append_space (GtkToolbar *toolbar)
Index: gtktoolbar.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktoolbar.h,v
retrieving revision 1.22
diff -u -p -r1.22 gtktoolbar.h
--- gtktoolbar.h	2000/08/30 00:33:38	1.22
+++ gtktoolbar.h	2001/02/22 15:58:03
@@ -134,6 +134,32 @@ GtkWidget* gtk_toolbar_insert_item     (
 					gpointer         user_data,
 					gint             position);
 
+/* Stock Items */
+GtkWidget* gtk_toolbar_append_stock    (GtkToolbar      *toolbar,
+					const gchar     *stock_id,
+					const gchar     *icon_size,
+					const char      *tooltip_text,
+					const char      *tooltip_private_text,
+					GtkSignalFunc    callback,
+					gpointer         user_data);
+GtkWidget* gtk_toolbar_prepend_stock   (GtkToolbar      *toolbar,
+					const gchar     *stock_id,
+					const gchar     *icon_size,
+					const char      *tooltip_text,
+					const char      *tooltip_private_text,
+					GtkSignalFunc    callback,
+					gpointer         user_data);
+GtkWidget* gtk_toolbar_insert_stock    (GtkToolbar      *toolbar,
+					const gchar     *stock_id,
+					const gchar     *icon_size,
+					const char      *tooltip_text,
+					const char      *tooltip_private_text,
+					GtkSignalFunc    callback,
+					gpointer         user_data,
+					gint             position);
+
+
+
 /* Space Items */
 void       gtk_toolbar_append_space    (GtkToolbar      *toolbar);
 void       gtk_toolbar_prepend_space   (GtkToolbar      *toolbar);
Index: testgtk.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/testgtk.c,v
retrieving revision 1.220
diff -u -p -r1.220 testgtk.c
--- testgtk.c	2001/02/21 19:59:22	1.220
+++ testgtk.c	2001/02/22 15:58:13
@@ -751,6 +751,12 @@ create_toolbar (void)
       toolbar = gtk_toolbar_new (GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_BOTH);
       gtk_toolbar_set_button_relief (GTK_TOOLBAR (toolbar), GTK_RELIEF_NONE);
 
+      gtk_toolbar_append_stock (GTK_TOOLBAR (toolbar),
+				GTK_STOCK_NEW,
+				GTK_ICON_SIZE_LARGE_TOOLBAR,
+				"Stock icon: New", "Toolbar/New",
+				(GtkSignalFunc) set_toolbar_horizontal, toolbar);
+      
       gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
 			       "Horizontal", "Horizontal toolbar layout", "Toolbar/Horizontal",
 			       new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),





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