Resending stock icon patches.



Didn't get an ok on these patches yet.

Add stock icons to GtkImageMenuItem:

Index: gtkimagemenuitem.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkimagemenuitem.c,v
retrieving revision 1.2
diff -u -p -r1.2 gtkimagemenuitem.c
--- gtkimagemenuitem.c	2001/02/15 03:40:48	1.2
+++ gtkimagemenuitem.c	2001/03/07 13:47:50
@@ -28,6 +28,9 @@
 #include "gtkaccellabel.h"
 #include "gtksignal.h"
 #include "gtkintl.h"
+#include "gtkstock.h"
+#include "gtkiconfactory.h"
+#include "gtkimage.h"

 static void gtk_image_menu_item_class_init           (GtkImageMenuItemClass *klass);
 static void gtk_image_menu_item_init                 (GtkImageMenuItem      *image_menu_item);
@@ -35,8 +38,6 @@ static void gtk_image_menu_item_size_req
                                                       GtkRequisition   *requisition);
 static void gtk_image_menu_item_size_allocate        (GtkWidget        *widget,
                                                       GtkAllocation    *allocation);
-static gint gtk_image_menu_item_expose               (GtkWidget             *widget,
-						      GdkEventExpose        *event);
 static void gtk_image_menu_item_remove               (GtkContainer          *container,
                                                       GtkWidget             *child);
 static void gtk_image_menu_item_toggle_size_request  (GtkMenuItem           *menu_item,
@@ -110,7 +111,6 @@ gtk_image_menu_item_class_init (GtkImage

   parent_class = gtk_type_class (GTK_TYPE_MENU_ITEM);

-  widget_class->expose_event = gtk_image_menu_item_expose;
   widget_class->size_request = gtk_image_menu_item_size_request;
   widget_class->size_allocate = gtk_image_menu_item_size_allocate;
   widget_class->map = gtk_image_menu_item_map;
@@ -283,31 +283,6 @@ gtk_image_menu_item_size_allocate (GtkWi
     }
 }

-static gint
-gtk_image_menu_item_expose (GtkWidget      *widget,
-			    GdkEventExpose *event)
-{
-  GdkEventExpose child_event;
-  GtkImageMenuItem *image_menu_item;
-
-  g_return_val_if_fail (widget != NULL, FALSE);
-  g_return_val_if_fail (GTK_IS_IMAGE_MENU_ITEM (widget), FALSE);
-  g_return_val_if_fail (event != NULL, FALSE);
-
-  image_menu_item = GTK_IMAGE_MENU_ITEM (widget);
-
-  if (GTK_WIDGET_CLASS (parent_class)->expose_event)
-    (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event);
-
-  child_event = *event;
-  if (image_menu_item->image && GTK_WIDGET_DRAWABLE (image_menu_item->image) &&
-      GTK_WIDGET_NO_WINDOW (image_menu_item->image) &&
-      gtk_widget_intersect (image_menu_item->image, &event->area, &child_event.area))
-    gtk_widget_event (image_menu_item->image, (GdkEvent*) &child_event);
-
-  return FALSE;
-}
-
 static void
 gtk_image_menu_item_map (GtkWidget *widget)
 {
@@ -389,6 +364,35 @@ gtk_image_menu_item_new (GtkWidget   *wi
     gtk_image_menu_item_add_image (image_menu_item, widget);

   return GTK_WIDGET(image_menu_item);
+}
+
+GtkWidget*
+gtk_image_menu_item_new_stock (const gchar      *stock_id,
+			       GtkAccelGroup    *accel_group)
+{
+  GtkWidget *image;
+  GtkStockItem stock_item;
+  GtkWidget *item;
+
+  image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU);
+
+  if (gtk_stock_lookup (stock_id, &stock_item))
+    {
+      item = gtk_image_menu_item_new (image, stock_item.label);
+
+      if (stock_item.keyval && accel_group)
+	gtk_widget_add_accelerator (item,
+				    "activate",
+				    accel_group,
+				    stock_item.keyval,
+				    stock_item.modifier,
+				    GTK_ACCEL_VISIBLE);
+    }
+  else
+    item = gtk_image_menu_item_new (image, stock_id);
+
+  gtk_widget_show (image);
+  return item;
 }

 void
Index: gtkimagemenuitem.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkimagemenuitem.h,v
retrieving revision 1.1
diff -u -p -r1.1 gtkimagemenuitem.h
--- gtkimagemenuitem.h	2001/02/13 05:44:47	1.1
+++ gtkimagemenuitem.h	2001/03/07 13:47:50
@@ -64,9 +64,11 @@ struct _GtkImageMenuItemClass

 GtkType	   gtk_image_menu_item_get_type  (void) G_GNUC_CONST;
 GtkWidget* gtk_image_menu_item_new       (GtkWidget        *widget,
-                                          const gchar      *label);
+					  const gchar      *label);
+GtkWidget* gtk_image_menu_item_new_stock (const gchar      *stock_id,
+					  GtkAccelGroup    *accel_group);
 void       gtk_image_menu_item_add_image (GtkImageMenuItem *image_menu_item,
-                                          GtkWidget        *child);
+					  GtkWidget        *child);
 GtkWidget* gtk_image_menu_item_get_image (GtkImageMenuItem *image_menu_item);

 #ifdef __cplusplus



Adds stock items and imagemenuitems to GtkItemFactory.

Index: gtkitemfactory.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkitemfactory.c,v
retrieving revision 1.32
diff -u -p -r1.32 gtkitemfactory.c
--- gtkitemfactory.c	2001/02/02 17:53:29	1.32
+++ gtkitemfactory.c	2001/03/07 13:52:07
@@ -37,9 +37,13 @@
 #include	"gtk/gtkmenuitem.h"
 #include	"gtk/gtkradiomenuitem.h"
 #include	"gtk/gtkcheckmenuitem.h"
+#include	"gtk/gtkimagemenuitem.h"
 #include	"gtk/gtktearoffmenuitem.h"
 #include	"gtk/gtkaccellabel.h"
 #include        "gdk/gdkkeysyms.h"
+#include	"gtk/gtkimage.h"
+#include	"gtk/gtkstock.h"
+#include	"gtk/gtkiconfactory.h"
 #include	<string.h>
 #include	<sys/stat.h>
 #include	<fcntl.h>
@@ -105,6 +109,8 @@ static GQuark		 quark_type_title = 0;
 static GQuark		 quark_type_radio_item = 0;
 static GQuark		 quark_type_check_item = 0;
 static GQuark		 quark_type_toggle_item = 0;
+static GQuark		 quark_type_image_item = 0;
+static GQuark		 quark_type_stock_item = 0;
 static GQuark		 quark_type_tearoff_item = 0;
 static GQuark		 quark_type_separator_item = 0;
 static GQuark		 quark_type_branch = 0;
@@ -220,6 +226,8 @@ gtk_item_factory_class_init (GtkItemFact
   quark_type_radio_item		= g_quark_from_static_string ("<RadioItem>");
   quark_type_check_item		= g_quark_from_static_string ("<CheckItem>");
   quark_type_toggle_item	= g_quark_from_static_string ("<ToggleItem>");
+  quark_type_image_item         = g_quark_from_static_string ("<ImageItem>");
+  quark_type_stock_item         = g_quark_from_static_string ("<StockItem>");
   quark_type_tearoff_item	= g_quark_from_static_string ("<Tearoff>");
   quark_type_separator_item	= g_quark_from_static_string ("<Separator>");
   quark_type_branch		= g_quark_from_static_string ("<Branch>");
@@ -1001,15 +1009,18 @@ gtk_item_factory_create_item (GtkItemFac
   GtkOptionMenu *option_menu = NULL;
   GtkWidget *parent;
   GtkWidget *widget;
+  GtkWidget *image;
   GSList *radio_group;
   gchar *name;
   gchar *parent_path;
   gchar *path;
+  gchar *accelerator;
   guint accel_key;
   guint type_id;
   GtkType type;
   gchar *item_type_path;
-
+  GtkStockItem stock_item;
+
   g_return_if_fail (ifactory != NULL);
   g_return_if_fail (GTK_IS_ITEM_FACTORY (ifactory));
   g_return_if_fail (entry != NULL);
@@ -1038,6 +1049,10 @@ gtk_item_factory_create_item (GtkItemFac
     type = GTK_TYPE_RADIO_MENU_ITEM;
   else if (type_id == quark_type_check_item)
     type = GTK_TYPE_CHECK_MENU_ITEM;
+  else if (type_id == quark_type_image_item)
+    type = GTK_TYPE_IMAGE_MENU_ITEM;
+  else if (type_id == quark_type_stock_item)
+    type = GTK_TYPE_IMAGE_MENU_ITEM;
   else if (type_id == quark_type_tearoff_item)
     type = GTK_TYPE_TEAROFF_MENU_ITEM;
   else if (type_id == quark_type_toggle_item)
@@ -1105,6 +1120,8 @@ gtk_item_factory_create_item (GtkItemFac

   g_return_if_fail (GTK_IS_CONTAINER (parent));

+  accelerator = entry->accelerator;
+
   widget = gtk_widget_new (type,
 			   "GtkWidget::visible", TRUE,
 			   "GtkWidget::sensitive", (type_id != quark_type_separator_item &&
@@ -1118,7 +1135,40 @@ gtk_item_factory_create_item (GtkItemFac
     gtk_radio_menu_item_set_group (GTK_RADIO_MENU_ITEM (widget), radio_group);
   if (GTK_IS_CHECK_MENU_ITEM (widget))
     gtk_check_menu_item_set_show_toggle (GTK_CHECK_MENU_ITEM (widget), TRUE);
+  if (GTK_IS_IMAGE_MENU_ITEM (widget))
+    {
+      GdkPixbuf *pixbuf = NULL;
+      image = NULL;
+
+      pixbuf = gdk_pixbuf_new_from_inline (entry->extra_data,
+					   FALSE,
+					   entry->extra_data2,
+					   NULL);

+      if (pixbuf)
+	image = gtk_image_new_from_pixbuf (pixbuf);
+
+      if (image)
+	gtk_image_menu_item_add_image (GTK_IMAGE_MENU_ITEM (widget), image);
+
+      if (pixbuf)
+	g_object_unref (G_OBJECT (pixbuf));
+    }
+  if (type_id == quark_type_stock_item)
+    {
+      image = gtk_image_new_from_stock (entry->extra_data, GTK_ICON_SIZE_MENU);
+      if (image)
+	gtk_image_menu_item_add_image (GTK_IMAGE_MENU_ITEM (widget), image);
+
+      if (gtk_stock_lookup (entry->extra_data, &stock_item))
+	{
+	  if (!accelerator)
+	    accelerator = gtk_accelerator_name (stock_item.keyval, stock_item.modifier);
+	}
+    }
+
+
+
   /* install underline accelerators for this item
    */
   if (type_id != quark_type_separator_item &&
@@ -1174,7 +1224,7 @@ gtk_item_factory_create_item (GtkItemFac
     }

   gtk_item_factory_add_item (ifactory,
-			     path, entry->accelerator,
+			     path, accelerator,
 			     (type_id == quark_type_branch ||
 			      type_id == quark_type_last_branch) ?
 			      (GtkItemFactoryCallback) NULL : entry->callback,
@@ -1183,6 +1233,9 @@ gtk_item_factory_create_item (GtkItemFac
 			     item_type_path,
 			     widget);

+  if (accelerator != entry->accelerator)
+    g_free (accelerator);
+
   g_free (path);
 }

Index: gtkitemfactory.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkitemfactory.h,v
retrieving revision 1.18
diff -u -p -r1.18 gtkitemfactory.h
--- gtkitemfactory.h	2000/08/30 00:33:37	1.18
+++ gtkitemfactory.h	2001/03/07 13:52:07
@@ -110,6 +110,13 @@ struct _GtkItemFactoryEntry
    * "<LastBranch>"	-> create a right justified item to hold sub items
    */
   gchar		 *item_type;
+
+  /* Extra data for some item types:
+   *  ImageItem  -> pointer to inline pixbuf + inline pixbuf length
+   *  StockItem  -> name of stock item
+   */
+  gpointer extra_data;
+  guint    extra_data2;
 };

 struct _GtkItemFactoryItem


Stock Toolbar buttons. Owen commented on another patch like this that we
don't want any more append/prepend functions, only insert where pos -1 is
at the end. Maybe i should remove the append/prepend here too?

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/03/07 13:53:44
@@ -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 +756,127 @@ gtk_toolbar_insert_item (GtkToolbar    *
 				     icon, callback, user_data,
 				     position);
 }
+
+
+void
+gtk_toolbar_set_stock_size (GtkToolbar         *toolbar,
+			    GtkToolbarIconSize  stock_size)
+{
+  GList *children;
+  GtkToolbarChild *child;
+  GtkImage *image;
+  gchar *stock_id;
+  gchar *icon_size;
+
+  g_return_if_fail (toolbar != NULL);
+  g_return_if_fail (GTK_IS_TOOLBAR (toolbar));
+
+  if (toolbar->icon_size == stock_size)
+    return;
+
+  toolbar->icon_size = stock_size;
+
+  if (toolbar->icon_size == GTK_TOOLBAR_ICON_SIZE_SMALL)
+    icon_size = GTK_ICON_SIZE_SMALL_TOOLBAR;
+  else
+    icon_size = GTK_ICON_SIZE_LARGE_TOOLBAR;
+
+  for (children = toolbar->children; children; children = children->next)
+    {
+      child = children->data;
+      if (child->type == GTK_TOOLBAR_CHILD_BUTTON &&
+	  GTK_IS_IMAGE (child->icon))
+	{
+	  image = GTK_IMAGE (child->icon);
+	  if (gtk_image_get_storage_type (image) == GTK_IMAGE_STOCK)
+	    {
+	      gtk_image_get_stock (image, &stock_id, NULL);
+	      stock_id = g_strdup (stock_id);
+	      gtk_image_set_from_stock (image,
+					stock_id,
+					icon_size);
+	      g_free (stock_id);
+	    }
+	}
+    }
+
+  gtk_widget_queue_resize (GTK_WIDGET (toolbar));
+}
+
+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: 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/03/07 13:53:44
@@ -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]