stock and image items in GtkItemFactory (bug 50489)
- From: Alexander Larsson <alla lysator liu se>
- To: gtk-devel-list gnome org
- Subject: stock and image items in GtkItemFactory (bug 50489)
- Date: Fri, 23 Feb 2001 14:58:22 +0100 (CET)
This implements stock menu items and image menu items (using inline
pixbufs) in GtkItemFactory.
Comments?
/ Alex
Index: gtk/gtkitemfactory.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkitemfactory.c,v
retrieving revision 1.32
diff -u -p -r1.32 gtkitemfactory.c
--- gtk/gtkitemfactory.c 2001/02/02 17:53:29 1.32
+++ gtk/gtkitemfactory.c 2001/02/23 13:37:32
@@ -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: gtk/gtkitemfactory.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkitemfactory.h,v
retrieving revision 1.18
diff -u -p -r1.18 gtkitemfactory.h
--- gtk/gtkitemfactory.h 2000/08/30 00:33:37 1.18
+++ gtk/gtkitemfactory.h 2001/02/23 13:37:32
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]