Stock icons in GtkToolbar (bug 50489)



New patch.

It doesn't support changing the size of the toolbar icons after they've
been inserted. Is this something we need?

/ Alex

Index: gtk/gtktoolbar.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktoolbar.c,v
retrieving revision 1.45
diff -u -p -r1.45 gtktoolbar.c
--- gtk/gtktoolbar.c	2000/12/13 01:34:40	1.45
+++ gtk/gtktoolbar.c	2001/02/23 13:37:34
@@ -32,11 +32,16 @@
 #include "gtkvbox.h"
 #include "gtkhbox.h"
 #include "gtktoolbar.h"
+#include "gtkstock.h"
+#include "gtkiconfactory.h"
+#include "gtkimage.h"
 
 
 #define DEFAULT_SPACE_SIZE  5
 #define DEFAULT_SPACE_STYLE GTK_TOOLBAR_SPACE_EMPTY
 
+#define DEFAULT_ICON_SIZE GTK_TOOLBAR_ICON_SIZE_LARGE
+
 #define SPACE_LINE_DIVISION 10
 #define SPACE_LINE_START    3
 #define SPACE_LINE_END      7
@@ -198,6 +203,7 @@ gtk_toolbar_init (GtkToolbar *toolbar)
   toolbar->relief       = GTK_RELIEF_NORMAL;
   toolbar->space_size   = DEFAULT_SPACE_SIZE;
   toolbar->space_style  = DEFAULT_SPACE_STYLE;
+  toolbar->icon_size    = DEFAULT_ICON_SIZE;
   toolbar->tooltips     = gtk_tooltips_new ();
   toolbar->button_maxw  = 0;
   toolbar->button_maxh  = 0;
@@ -752,6 +758,89 @@ gtk_toolbar_insert_item (GtkToolbar    *
 				     icon, callback, user_data,
 				     position);
 }
+
+
+void
+gtk_toolbar_set_stock_size  (GtkToolbar      *toolbar,
+			     GtkToolbarIconSize stock_size)
+{
+  toolbar->icon_size = stock_size;
+}
+
+GtkWidget*
+gtk_toolbar_append_stock    (GtkToolbar      *toolbar,
+			     const gchar     *stock_id,
+			     const char      *tooltip_text,
+			     const char      *tooltip_private_text,
+			     GtkSignalFunc    callback,
+			     gpointer         user_data)
+{
+  return gtk_toolbar_insert_stock (toolbar,
+				   stock_id,
+				   tooltip_text, tooltip_private_text,
+				   callback, user_data,
+				   toolbar->num_children);
+}
+
+GtkWidget*
+gtk_toolbar_prepend_stock   (GtkToolbar      *toolbar,
+			     const gchar     *stock_id,
+			     const char      *tooltip_text,
+			     const char      *tooltip_private_text,
+			     GtkSignalFunc    callback,
+			     gpointer         user_data)
+{
+  return gtk_toolbar_insert_stock (toolbar,
+				   stock_id,
+				   tooltip_text, tooltip_private_text,
+				   callback, user_data,
+				   0);
+}
+
+
+GtkWidget*
+gtk_toolbar_insert_stock    (GtkToolbar      *toolbar,
+			     const gchar     *stock_id,
+			     const char      *tooltip_text,
+			     const char      *tooltip_private_text,
+			     GtkSignalFunc    callback,
+			     gpointer         user_data,
+			     gint             position)
+{
+  GtkStockItem item;
+  GtkWidget *image;
+  gchar *icon_size;
+
+  if (gtk_stock_lookup (stock_id, &item))
+    {
+      if (toolbar->icon_size == GTK_TOOLBAR_ICON_SIZE_SMALL)
+	icon_size = GTK_ICON_SIZE_SMALL_TOOLBAR;
+      else
+	icon_size = GTK_ICON_SIZE_LARGE_TOOLBAR;
+
+      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: gtk/gtktoolbar.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktoolbar.h,v
retrieving revision 1.22
diff -u -p -r1.22 gtktoolbar.h
--- gtk/gtktoolbar.h	2000/08/30 00:33:38	1.22
+++ gtk/gtktoolbar.h	2001/02/23 13:37:34
@@ -65,6 +65,13 @@ typedef enum
   GTK_TOOLBAR_SPACE_LINE
 } GtkToolbarSpaceStyle;
 
+typedef enum
+{
+  GTK_TOOLBAR_ICON_SIZE_SMALL,
+  GTK_TOOLBAR_ICON_SIZE_LARGE
+} GtkToolbarIconSize;
+
+
 typedef struct _GtkToolbarChild      GtkToolbarChild;
 typedef struct _GtkToolbar           GtkToolbar;
 typedef struct _GtkToolbarClass      GtkToolbarClass;
@@ -87,6 +94,7 @@ struct _GtkToolbar
   GtkToolbarStyle  style;
   gint             space_size; /* big optional space between buttons */
   GtkToolbarSpaceStyle space_style;
+  GtkToolbarIconSize   icon_size;
 
   GtkTooltips     *tooltips;
 
@@ -133,6 +141,31 @@ GtkWidget* gtk_toolbar_insert_item     (
 					GtkSignalFunc    callback,
 					gpointer         user_data,
 					gint             position);
+
+/* Stock Items */
+void       gtk_toolbar_set_stock_size  (GtkToolbar      *toolbar,
+					GtkToolbarIconSize stock_size);
+GtkWidget* gtk_toolbar_append_stock    (GtkToolbar      *toolbar,
+					const gchar     *stock_id,
+					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 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 char      *tooltip_text,
+					const char      *tooltip_private_text,
+					GtkSignalFunc    callback,
+					gpointer         user_data,
+					gint             position);
+
+
 
 /* Space Items */
 void       gtk_toolbar_append_space    (GtkToolbar      *toolbar);





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