From e319b07fba9a47a15aae9ef7c85da464b75874ff Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 16:02:48 -0600 Subject: Steal the serializable menuitem from IDO --- libdbusmenu-gtk/serializablemenuitem.c | 99 ++++++++++++++++++++++++++++++++++ libdbusmenu-gtk/serializablemenuitem.h | 58 ++++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 libdbusmenu-gtk/serializablemenuitem.c create mode 100644 libdbusmenu-gtk/serializablemenuitem.h (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c new file mode 100644 index 0000000..2c166d8 --- /dev/null +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -0,0 +1,99 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "idoserializablemenuitem.h" + +struct _IdoSerializableMenuItemPrivate { + int dummy; +}; + +#define IDO_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(o) \ +(G_TYPE_INSTANCE_GET_PRIVATE ((o), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItemPrivate)) + +static void ido_serializable_menu_item_class_init (IdoSerializableMenuItemClass *klass); +static void ido_serializable_menu_item_init (IdoSerializableMenuItem *self); +static void ido_serializable_menu_item_dispose (GObject *object); +static void ido_serializable_menu_item_finalize (GObject *object); + +G_DEFINE_TYPE (IdoSerializableMenuItem, ido_serializable_menu_item, GTK_TYPE_MENU_ITEM); + +static void +ido_serializable_menu_item_class_init (IdoSerializableMenuItemClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (IdoSerializableMenuItemPrivate)); + + object_class->dispose = ido_serializable_menu_item_dispose; + object_class->finalize = ido_serializable_menu_item_finalize; + + return; +} + +static void +ido_serializable_menu_item_init (IdoSerializableMenuItem *self) +{ + self->priv = IDO_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(self); + + self->priv->dummy = 5; + + return; +} + +static void +ido_serializable_menu_item_dispose (GObject *object) +{ + + + G_OBJECT_CLASS (ido_serializable_menu_item_parent_class)->dispose (object); + return; +} + +static void +ido_serializable_menu_item_finalize (GObject *object) +{ + + + + G_OBJECT_CLASS (ido_serializable_menu_item_parent_class)->finalize (object); + return; +} + +DbusmenuMenuitem * +ido_serializable_menu_item_get_dbusmenu_menuitem (IdoSerializableMenuItem * smi) +{ + g_return_val_if_fail(IDO_IS_SERIALIZABLE_MENU_ITEM(smi), NULL); + + IdoSerializableMenuItemClass * klass = IDO_SERIALIZABLE_MENU_ITEM_GET_CLASS(smi); + if (klass->get_dbusmenu_menuitem != NULL) { + return klass->get_dbusmenu_menuitem(smi); + } + + return NULL; +} + +void +ido_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) +{ + g_return_if_fail(g_type_is_a(item_type, IDO_TYPE_SERIALIZABLE_MENU_ITEM)); + + gpointer type_class = g_type_class_ref(item_type); + g_return_if_fail(type_class != NULL); + + IdoSerializableMenuItemClass * class = IDO_SERIALIZABLE_MENU_ITEM_CLASS(type_class); + + if (class->get_type_string == NULL) { + g_type_class_unref(type_class); + g_error("No 'get_type_string' in subclass of IdoSerializableMenuItem"); + return; + } + + /* Register type */ + + + /* Register defaults */ + + + return; +} diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h new file mode 100644 index 0000000..48fdb49 --- /dev/null +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -0,0 +1,58 @@ +#ifndef __IDO_SERIALIZABLE_MENU_ITEM_H__ +#define __IDO_SERIALIZABLE_MENU_ITEM_H__ + +#include +#include +#include +#include +#include + +G_BEGIN_DECLS + +#define IDO_TYPE_SERIALIZABLE_MENU_ITEM (ido_serializable_menu_item_get_type ()) +#define IDO_SERIALIZABLE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItem)) +#define IDO_SERIALIZABLE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItemClass)) +#define IDO_IS_SERIALIZABLE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDO_TYPE_SERIALIZABLE_MENU_ITEM)) +#define IDO_IS_SERIALIZABLE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IDO_TYPE_SERIALIZABLE_MENU_ITEM)) +#define IDO_SERIALIZABLE_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItemClass)) + +typedef struct _IdoSerializableMenuItem IdoSerializableMenuItem; +typedef struct _IdoSerializableMenuItemClass IdoSerializableMenuItemClass; +typedef struct _IdoSerializableMenuItemPrivate IdoSerializableMenuItemPrivate; + +struct _IdoSerializableMenuItemClass { + GtkMenuItemClass parent_class; + + /* Subclassable functions */ + const gchar * (*get_type_string) (void); + GHashTable * (*get_default_properties) (void); + + DbusmenuMenuitem * (*get_dbusmenu_menuitem) (IdoSerializableMenuItem * smi); + + /* Signals */ + + + + /* Empty Space */ + void (*_ido_serializable_menu_item_reserved1) (void); + void (*_ido_serializable_menu_item_reserved2) (void); + void (*_ido_serializable_menu_item_reserved3) (void); + void (*_ido_serializable_menu_item_reserved4) (void); + void (*_ido_serializable_menu_item_reserved5) (void); + void (*_ido_serializable_menu_item_reserved6) (void); +}; + +struct _IdoSerializableMenuItem { + GtkMenuItem parent; + + IdoSerializableMenuItemPrivate * priv; +}; + +GType ido_serializable_menu_item_get_type (void); + +DbusmenuMenuitem * ido_serializable_menu_item_get_dbusmenu_menuitem (IdoSerializableMenuItem * smi); +void ido_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type); + +G_END_DECLS + +#endif -- cgit v1.2.3 From d43d544702665d2653f7dbb9c73493733ff2fae6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 16:27:12 -0600 Subject: Adding the files to the build --- libdbusmenu-gtk/Makefile.am | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index 0b939c0..a424d4a 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -22,7 +22,8 @@ libdbusmenu_gtkincludedir=$(includedir)/libdbusmenu-0.4/libdbusmenu-gtk$(VER)/ libdbusmenu_gtkinclude_HEADERS = \ client.h \ menu.h \ - menuitem.h + menuitem.h \ + serializablemenuitem.h libdbusmenu_gtk_la_SOURCES = \ client.h \ @@ -32,7 +33,9 @@ libdbusmenu_gtk_la_SOURCES = \ menu.h \ menu.c \ menuitem.h \ - menuitem.c + menuitem.c \ + serializablemenuitem.h \ + serializablemenuitem.c libdbusmenu_gtk_la_LDFLAGS = \ -version-info $(LIBDBUSMENU_CURRENT):$(LIBDBUSMENU_REVISION):$(LIBDBUSMENU_AGE) \ -- cgit v1.2.3 From 8122074a5e67cf69f147a8b10b31c1fefaf64486 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 16:32:02 -0600 Subject: Changing namespace from IDO to DBusMenu GTK --- libdbusmenu-gtk/serializablemenuitem.c | 52 +++++++++++++++++----------------- libdbusmenu-gtk/serializablemenuitem.h | 48 +++++++++++++++---------------- 2 files changed, 50 insertions(+), 50 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 2c166d8..c9eb416 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -2,39 +2,39 @@ #include "config.h" #endif -#include "idoserializablemenuitem.h" +#include "serializablemenuitem.h" -struct _IdoSerializableMenuItemPrivate { +struct _DbusmenuGtkSerializableMenuItemPrivate { int dummy; }; -#define IDO_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(o) \ -(G_TYPE_INSTANCE_GET_PRIVATE ((o), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItemPrivate)) +#define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(o) \ +(G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM, DbusmenuGtkSerializableMenuItemPrivate)) -static void ido_serializable_menu_item_class_init (IdoSerializableMenuItemClass *klass); -static void ido_serializable_menu_item_init (IdoSerializableMenuItem *self); -static void ido_serializable_menu_item_dispose (GObject *object); -static void ido_serializable_menu_item_finalize (GObject *object); +static void dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemClass *klass); +static void dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self); +static void dbusmenu_gtk_serializable_menu_item_dispose (GObject *object); +static void dbusmenu_gtk_serializable_menu_item_finalize (GObject *object); -G_DEFINE_TYPE (IdoSerializableMenuItem, ido_serializable_menu_item, GTK_TYPE_MENU_ITEM); +G_DEFINE_TYPE (DbusmenuGtkSerializableMenuItem, dbusmenu_gtk_serializable_menu_item, GTK_TYPE_MENU_ITEM); static void -ido_serializable_menu_item_class_init (IdoSerializableMenuItemClass *klass) +dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - g_type_class_add_private (klass, sizeof (IdoSerializableMenuItemPrivate)); + g_type_class_add_private (klass, sizeof (DbusmenuGtkSerializableMenuItemPrivate)); - object_class->dispose = ido_serializable_menu_item_dispose; - object_class->finalize = ido_serializable_menu_item_finalize; + object_class->dispose = dbusmenu_gtk_serializable_menu_item_dispose; + object_class->finalize = dbusmenu_gtk_serializable_menu_item_finalize; return; } static void -ido_serializable_menu_item_init (IdoSerializableMenuItem *self) +dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self) { - self->priv = IDO_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(self); + self->priv = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(self); self->priv->dummy = 5; @@ -42,30 +42,30 @@ ido_serializable_menu_item_init (IdoSerializableMenuItem *self) } static void -ido_serializable_menu_item_dispose (GObject *object) +dbusmenu_gtk_serializable_menu_item_dispose (GObject *object) { - G_OBJECT_CLASS (ido_serializable_menu_item_parent_class)->dispose (object); + G_OBJECT_CLASS (dbusmenu_gtk_serializable_menu_item_parent_class)->dispose (object); return; } static void -ido_serializable_menu_item_finalize (GObject *object) +dbusmenu_gtk_serializable_menu_item_finalize (GObject *object) { - G_OBJECT_CLASS (ido_serializable_menu_item_parent_class)->finalize (object); + G_OBJECT_CLASS (dbusmenu_gtk_serializable_menu_item_parent_class)->finalize (object); return; } DbusmenuMenuitem * -ido_serializable_menu_item_get_dbusmenu_menuitem (IdoSerializableMenuItem * smi) +dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi) { - g_return_val_if_fail(IDO_IS_SERIALIZABLE_MENU_ITEM(smi), NULL); + g_return_val_if_fail(DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(smi), NULL); - IdoSerializableMenuItemClass * klass = IDO_SERIALIZABLE_MENU_ITEM_GET_CLASS(smi); + DbusmenuGtkSerializableMenuItemClass * klass = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_CLASS(smi); if (klass->get_dbusmenu_menuitem != NULL) { return klass->get_dbusmenu_menuitem(smi); } @@ -74,18 +74,18 @@ ido_serializable_menu_item_get_dbusmenu_menuitem (IdoSerializableMenuItem * smi) } void -ido_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) +dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) { - g_return_if_fail(g_type_is_a(item_type, IDO_TYPE_SERIALIZABLE_MENU_ITEM)); + g_return_if_fail(g_type_is_a(item_type, DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM)); gpointer type_class = g_type_class_ref(item_type); g_return_if_fail(type_class != NULL); - IdoSerializableMenuItemClass * class = IDO_SERIALIZABLE_MENU_ITEM_CLASS(type_class); + DbusmenuGtkSerializableMenuItemClass * class = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_CLASS(type_class); if (class->get_type_string == NULL) { g_type_class_unref(type_class); - g_error("No 'get_type_string' in subclass of IdoSerializableMenuItem"); + g_error("No 'get_type_string' in subclass of DbusmenuGtkSerializableMenuItem"); return; } diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index 48fdb49..e99d329 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -1,5 +1,5 @@ -#ifndef __IDO_SERIALIZABLE_MENU_ITEM_H__ -#define __IDO_SERIALIZABLE_MENU_ITEM_H__ +#ifndef __DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ +#define __DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ #include #include @@ -9,49 +9,49 @@ G_BEGIN_DECLS -#define IDO_TYPE_SERIALIZABLE_MENU_ITEM (ido_serializable_menu_item_get_type ()) -#define IDO_SERIALIZABLE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItem)) -#define IDO_SERIALIZABLE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItemClass)) -#define IDO_IS_SERIALIZABLE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDO_TYPE_SERIALIZABLE_MENU_ITEM)) -#define IDO_IS_SERIALIZABLE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IDO_TYPE_SERIALIZABLE_MENU_ITEM)) -#define IDO_SERIALIZABLE_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItemClass)) +#define DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM (dbusmenu_gtk_serializable_menu_item_get_type ()) +#define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM, DbusmenuGtkSerializableMenuItem)) +#define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM, DbusmenuGtkSerializableMenuItemClass)) +#define DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM)) +#define DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM)) +#define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM, DbusmenuGtkSerializableMenuItemClass)) -typedef struct _IdoSerializableMenuItem IdoSerializableMenuItem; -typedef struct _IdoSerializableMenuItemClass IdoSerializableMenuItemClass; -typedef struct _IdoSerializableMenuItemPrivate IdoSerializableMenuItemPrivate; +typedef struct _DbusmenuGtkSerializableMenuItem DbusmenuGtkSerializableMenuItem; +typedef struct _DbusmenuGtkSerializableMenuItemClass DbusmenuGtkSerializableMenuItemClass; +typedef struct _DbusmenuGtkSerializableMenuItemPrivate DbusmenuGtkSerializableMenuItemPrivate; -struct _IdoSerializableMenuItemClass { +struct _DbusmenuGtkSerializableMenuItemClass { GtkMenuItemClass parent_class; /* Subclassable functions */ const gchar * (*get_type_string) (void); GHashTable * (*get_default_properties) (void); - DbusmenuMenuitem * (*get_dbusmenu_menuitem) (IdoSerializableMenuItem * smi); + DbusmenuMenuitem * (*get_dbusmenu_menuitem) (DbusmenuGtkSerializableMenuItem * smi); /* Signals */ /* Empty Space */ - void (*_ido_serializable_menu_item_reserved1) (void); - void (*_ido_serializable_menu_item_reserved2) (void); - void (*_ido_serializable_menu_item_reserved3) (void); - void (*_ido_serializable_menu_item_reserved4) (void); - void (*_ido_serializable_menu_item_reserved5) (void); - void (*_ido_serializable_menu_item_reserved6) (void); + void (*_dbusmenu_gtk_serializable_menu_item_reserved1) (void); + void (*_dbusmenu_gtk_serializable_menu_item_reserved2) (void); + void (*_dbusmenu_gtk_serializable_menu_item_reserved3) (void); + void (*_dbusmenu_gtk_serializable_menu_item_reserved4) (void); + void (*_dbusmenu_gtk_serializable_menu_item_reserved5) (void); + void (*_dbusmenu_gtk_serializable_menu_item_reserved6) (void); }; -struct _IdoSerializableMenuItem { +struct _DbusmenuGtkSerializableMenuItem { GtkMenuItem parent; - IdoSerializableMenuItemPrivate * priv; + DbusmenuGtkSerializableMenuItemPrivate * priv; }; -GType ido_serializable_menu_item_get_type (void); +GType dbusmenu_gtk_serializable_menu_item_get_type (void); -DbusmenuMenuitem * ido_serializable_menu_item_get_dbusmenu_menuitem (IdoSerializableMenuItem * smi); -void ido_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type); +DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi); +void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type); G_END_DECLS -- cgit v1.2.3 From 6ec53854067f149492c18d35d680c2dad01d0a41 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 16:45:44 -0600 Subject: Setting up the type handler, need more API --- libdbusmenu-gtk/serializablemenuitem.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index c9eb416..4d23635 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -73,6 +73,14 @@ dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializab return NULL; } +/* Handle the type with this item. */ +static gboolean +type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +{ + + return TRUE; +} + void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) { @@ -90,10 +98,10 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, } /* Register type */ - + dbusmenu_client_add_type_handler(client, class->get_type_string(), type_handler); /* need type */ /* Register defaults */ - + /* TODO: Need API on another branch */ return; } -- cgit v1.2.3 From 3d8ec9ae0b07cbe287aaeda633621ac8c81b5925 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 16:59:57 -0600 Subject: Fixing callback prototypes --- libdbusmenu-gtk/client.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index b01156f..af7768a 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -54,8 +54,8 @@ static void delete_child (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, Dbusm static void move_child (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, guint new, guint old, DbusmenuGtkClient * gtkclient); static void item_activate (DbusmenuClient * client, DbusmenuMenuitem * mi, guint timestamp, gpointer userdata); -static gboolean new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); -static gboolean new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); +static gboolean new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data); +static gboolean new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data); static void process_visible (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * value); static void process_sensitive (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * value); @@ -684,7 +684,7 @@ dbusmenu_gtkclient_menuitem_get_submenu (DbusmenuGtkClient * client, DbusmenuMen /* The base type handler that builds a plain ol' GtkMenuItem to represent, well, the GtkMenuItem */ static gboolean -new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data) { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); @@ -719,7 +719,7 @@ new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusmenu /* Type handler for the seperators where it builds a GtkSeparator to act as the GtkMenuItem */ static gboolean -new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data) { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); -- cgit v1.2.3 From 61fd5050b6319de6b948cdb0cd36e1b985d7b2a8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 17:02:00 -0600 Subject: Setup to the use the full type handler --- libdbusmenu-gtk/serializablemenuitem.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 4d23635..42d79b2 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -75,12 +75,20 @@ dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializab /* Handle the type with this item. */ static gboolean -type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data) { return TRUE; } +/* Destruction is inevitable */ +static void +type_destroy_handler (DbusmenuClient * client, const gchar * type, gpointer user_data) +{ + + return; +} + void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) { @@ -98,7 +106,7 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, } /* Register type */ - dbusmenu_client_add_type_handler(client, class->get_type_string(), type_handler); /* need type */ + dbusmenu_client_add_type_handler_full(client, class->get_type_string(), type_handler, NULL, type_destroy_handler); /* need type */ /* Register defaults */ /* TODO: Need API on another branch */ -- cgit v1.2.3 From 5d6f408aad06b27f8d29b52df9bd8d76155eabe4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 17:05:31 -0600 Subject: Build a type handler structure to handle the class struct --- libdbusmenu-gtk/serializablemenuitem.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 42d79b2..16b3910 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -73,6 +73,12 @@ dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializab return NULL; } +typedef struct _type_handler_t type_handler_t; +struct _type_handler_t { + DbusmenuGtkSerializableMenuItemClass * class; + GType type; +}; + /* Handle the type with this item. */ static gboolean type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data) @@ -85,7 +91,10 @@ type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuCli static void type_destroy_handler (DbusmenuClient * client, const gchar * type, gpointer user_data) { - + g_return_if_fail(user_data != NULL); + type_handler_t * th = (type_handler_t *)user_data; + g_type_class_unref(th->class); + g_free(user_data); return; } @@ -106,7 +115,10 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, } /* Register type */ - dbusmenu_client_add_type_handler_full(client, class->get_type_string(), type_handler, NULL, type_destroy_handler); /* need type */ + type_handler_t * th = g_new0(type_handler_t, 1); + th->class = class; + th->type = item_type; + dbusmenu_client_add_type_handler_full(client, class->get_type_string(), type_handler, th, type_destroy_handler); /* need type */ /* Register defaults */ /* TODO: Need API on another branch */ -- cgit v1.2.3 From 43b377b84c868f652e8ea0db989b985cf20a3304 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 17:06:28 -0600 Subject: Clean up on failure --- libdbusmenu-gtk/serializablemenuitem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 16b3910..1d4703f 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -118,7 +118,9 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, type_handler_t * th = g_new0(type_handler_t, 1); th->class = class; th->type = item_type; - dbusmenu_client_add_type_handler_full(client, class->get_type_string(), type_handler, th, type_destroy_handler); /* need type */ + if (!dbusmenu_client_add_type_handler_full(client, class->get_type_string(), type_handler, th, type_destroy_handler)) { + type_destroy_handler(client, class->get_type_string(), th); + } /* Register defaults */ /* TODO: Need API on another branch */ -- cgit v1.2.3 From 4d6b2a232814fc61e7652199a142d5af39c4f78f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Jan 2011 10:52:33 -0600 Subject: License headers --- libdbusmenu-gtk/serializablemenuitem.c | 28 ++++++++++++++++++++++++++++ libdbusmenu-gtk/serializablemenuitem.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 1d4703f..e8ad22b 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -1,3 +1,31 @@ +/* +An object to act as a base class for easy GTK widgets that can be +transfered over dbusmenu. + +Copyright 2011 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see + +*/ + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index e99d329..bb67192 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -1,3 +1,31 @@ +/* +An object to act as a base class for easy GTK widgets that can be +transfered over dbusmenu. + +Copyright 2011 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see + +*/ + #ifndef __DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ #define __DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ -- cgit v1.2.3 From c0990d9fa4889042ae255ed1358c0686d5dec241 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Jan 2011 16:50:34 -0600 Subject: Filling out the type handler --- libdbusmenu-gtk/serializablemenuitem.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index e8ad22b..de7bb04 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -30,6 +30,7 @@ License version 3 and version 2.1 along with this program. If not, see #include "config.h" #endif +#include "client.h" #include "serializablemenuitem.h" struct _DbusmenuGtkSerializableMenuItemPrivate { @@ -111,6 +112,13 @@ struct _type_handler_t { static gboolean type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data) { + type_handler_t * th = (type_handler_t *)user_data; + + DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(g_object_new(th->type, NULL)); + g_return_val_if_fail(smi != NULL, FALSE); + + dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem(smi, newitem); + dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(smi), parent); return TRUE; } -- cgit v1.2.3 From 5dc7f70d50ba5cf9cdc86693e7b759f567fb862c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Jan 2011 17:00:50 -0600 Subject: Adding a function to tell the menu item about where it's properties are coming from. --- libdbusmenu-gtk/serializablemenuitem.c | 7 +++++++ libdbusmenu-gtk/serializablemenuitem.h | 1 + 2 files changed, 8 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index de7bb04..74e0bec 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -163,3 +163,10 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, return; } + +void +dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi) +{ + + return; +} diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index bb67192..487b08b 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -80,6 +80,7 @@ GType dbusmenu_gtk_serializable_menu_item_get_type (void); DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi); void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type); +void dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi); G_END_DECLS -- cgit v1.2.3 From abe1a8b281bf08217367666fbac41eb812708d33 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Jan 2011 19:56:14 -0600 Subject: Switching the name to build so that we realize what's going on there. --- libdbusmenu-gtk/serializablemenuitem.c | 6 +++--- libdbusmenu-gtk/serializablemenuitem.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 74e0bec..32be773 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -90,13 +90,13 @@ dbusmenu_gtk_serializable_menu_item_finalize (GObject *object) } DbusmenuMenuitem * -dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi) +dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi) { g_return_val_if_fail(DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(smi), NULL); DbusmenuGtkSerializableMenuItemClass * klass = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_CLASS(smi); - if (klass->get_dbusmenu_menuitem != NULL) { - return klass->get_dbusmenu_menuitem(smi); + if (klass->build_dbusmenu_menuitem != NULL) { + return klass->build_dbusmenu_menuitem(smi); } return NULL; diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index 487b08b..30e1157 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -55,7 +55,7 @@ struct _DbusmenuGtkSerializableMenuItemClass { const gchar * (*get_type_string) (void); GHashTable * (*get_default_properties) (void); - DbusmenuMenuitem * (*get_dbusmenu_menuitem) (DbusmenuGtkSerializableMenuItem * smi); + DbusmenuMenuitem * (*build_dbusmenu_menuitem) (DbusmenuGtkSerializableMenuItem * smi); /* Signals */ @@ -78,7 +78,7 @@ struct _DbusmenuGtkSerializableMenuItem { GType dbusmenu_gtk_serializable_menu_item_get_type (void); -DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi); +DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi); void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type); void dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi); -- cgit v1.2.3 From aea42d14c645517cc32611ab0e8580223948aad3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Jan 2011 20:09:39 -0600 Subject: Installing a property for the menuitem in the super-class --- libdbusmenu-gtk/serializablemenuitem.c | 23 +++++++++++++++++++++-- libdbusmenu-gtk/serializablemenuitem.h | 2 ++ 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 32be773..5089af0 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -34,7 +34,13 @@ License version 3 and version 2.1 along with this program. If not, see #include "serializablemenuitem.h" struct _DbusmenuGtkSerializableMenuItemPrivate { - int dummy; + DbusmenuMenuitem * mi; +}; + +/* Properties */ +enum { + PROP_0, + PROP_MENUITEM }; #define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(o) \ @@ -57,6 +63,12 @@ dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemC object_class->dispose = dbusmenu_gtk_serializable_menu_item_dispose; object_class->finalize = dbusmenu_gtk_serializable_menu_item_finalize; + g_object_class_install_property (object_class, PROP_MENUITEM, + g_param_spec_object(DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_PROP_MENUITEM, "DBusmenu Menuitem attached to item", + "A menuitem who's properties are being watched and where changes should be watched for updates. It is the responsibility of subclasses to set up the signal handlers for those property changes.", + DBUSMENU_TYPE_MENUITEM, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + return; } @@ -65,7 +77,7 @@ dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self) { self->priv = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(self); - self->priv->dummy = 5; + self->priv->mi = NULL; return; } @@ -73,6 +85,13 @@ dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self) static void dbusmenu_gtk_serializable_menu_item_dispose (GObject *object) { + DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(object); + g_return_if_fail(smi != NULL); + + if (smi->priv->mi != NULL) { + g_object_unref(G_OBJECT(smi->priv->mi)); + smi->priv->mi = NULL; + } G_OBJECT_CLASS (dbusmenu_gtk_serializable_menu_item_parent_class)->dispose (object); diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index 30e1157..0dc92e0 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -44,6 +44,8 @@ G_BEGIN_DECLS #define DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM)) #define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM, DbusmenuGtkSerializableMenuItemClass)) +#define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_PROP_MENUITEM "dbusmenu-menuitem" + typedef struct _DbusmenuGtkSerializableMenuItem DbusmenuGtkSerializableMenuItem; typedef struct _DbusmenuGtkSerializableMenuItemClass DbusmenuGtkSerializableMenuItemClass; typedef struct _DbusmenuGtkSerializableMenuItemPrivate DbusmenuGtkSerializableMenuItemPrivate; -- cgit v1.2.3 From 1a4efa01c312cf8c54d7d158385b5208f1cdb841 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 10:35:55 -0600 Subject: Add a single include for dbusmenu-gtk --- libdbusmenu-gtk/Makefile.am | 1 + libdbusmenu-gtk/dbusmenu-gtk.h | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 libdbusmenu-gtk/dbusmenu-gtk.h (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index b8e1170..e5df6b1 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -20,6 +20,7 @@ EXTRA_DIST = \ libdbusmenu_gtkincludedir=$(includedir)/libdbusmenu-0.4/libdbusmenu-gtk$(VER)/ libdbusmenu_gtkinclude_HEADERS = \ + dbusmenu-gtk.h \ client.h \ menu.h \ menuitem.h diff --git a/libdbusmenu-gtk/dbusmenu-gtk.h b/libdbusmenu-gtk/dbusmenu-gtk.h new file mode 100644 index 0000000..de63c61 --- /dev/null +++ b/libdbusmenu-gtk/dbusmenu-gtk.h @@ -0,0 +1,40 @@ +/* +A library to communicate a menu object set accross DBus and +track updates and maintain consistency. + +Copyright 2011 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see + +*/ + +#ifndef __DBUSMENU_GTK_H__ +#define __DBUSMENU_GTK_H__ + +/* Start with the glib stuff */ +#include + +/* Now get the GTK stuff */ +#include +#include +#include + +#endif /* __DBUSMENU_GLIB_H__ */ -- cgit v1.2.3 From 0ea5e726b97d9080b4300d007f002da247dbf0b2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 11:59:06 -0600 Subject: Add serializable menuitem to the single include --- libdbusmenu-gtk/dbusmenu-gtk.h | 1 + 1 file changed, 1 insertion(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/dbusmenu-gtk.h b/libdbusmenu-gtk/dbusmenu-gtk.h index de63c61..f2fe5be 100644 --- a/libdbusmenu-gtk/dbusmenu-gtk.h +++ b/libdbusmenu-gtk/dbusmenu-gtk.h @@ -36,5 +36,6 @@ License version 3 and version 2.1 along with this program. If not, see #include #include #include +#include #endif /* __DBUSMENU_GLIB_H__ */ -- cgit v1.2.3 From ffce14168e30c5b34d24ee7ee5199a61bb4a30f3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 12:02:57 -0600 Subject: Add some documentation of the class and object structures. --- libdbusmenu-gtk/serializablemenuitem.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index 0dc92e0..aae2f96 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -50,6 +50,19 @@ typedef struct _DbusmenuGtkSerializableMenuItem DbusmenuGtkSerializableMe typedef struct _DbusmenuGtkSerializableMenuItemClass DbusmenuGtkSerializableMenuItemClass; typedef struct _DbusmenuGtkSerializableMenuItemPrivate DbusmenuGtkSerializableMenuItemPrivate; +/** + DbusmenuGtkSerializableMenuItemClass: + @parent_class: Inherit from GtkMenuItem + @get_type_string: Static function to get a string describing this type + @get_default_properties: Return a hashtable of defaults for the menu item type + @build_dbusmenu_menuitem: Build a menuitem that can be sent over dbus + @_dbusmenu_gtk_serializable_menu_item_reserved1: Reserved for future use. + @_dbusmenu_gtk_serializable_menu_item_reserved2: Reserved for future use. + @_dbusmenu_gtk_serializable_menu_item_reserved3: Reserved for future use. + @_dbusmenu_gtk_serializable_menu_item_reserved4: Reserved for future use. + @_dbusmenu_gtk_serializable_menu_item_reserved5: Reserved for future use. + @_dbusmenu_gtk_serializable_menu_item_reserved6: Reserved for future use. +*/ struct _DbusmenuGtkSerializableMenuItemClass { GtkMenuItemClass parent_class; @@ -64,6 +77,7 @@ struct _DbusmenuGtkSerializableMenuItemClass { /* Empty Space */ + /*< Private >*/ void (*_dbusmenu_gtk_serializable_menu_item_reserved1) (void); void (*_dbusmenu_gtk_serializable_menu_item_reserved2) (void); void (*_dbusmenu_gtk_serializable_menu_item_reserved3) (void); @@ -72,6 +86,11 @@ struct _DbusmenuGtkSerializableMenuItemClass { void (*_dbusmenu_gtk_serializable_menu_item_reserved6) (void); }; +/** + DbusmenuGtkSerializableMenuItem: + @parent: Inherit from GtkMenuItem + @priv: Blind structure of private variables +*/ struct _DbusmenuGtkSerializableMenuItem { GtkMenuItem parent; -- cgit v1.2.3 From efd5c63d09eed1230bb0bb822f3040f55d30638d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 16:01:20 -0600 Subject: More documentation --- libdbusmenu-gtk/serializablemenuitem.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 5089af0..01b20b2 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -33,6 +33,10 @@ License version 3 and version 2.1 along with this program. If not, see #include "client.h" #include "serializablemenuitem.h" +/** + DbusmenuGtkSerializableMenuItemPrivate: + @mi: Menuitem to watch the property changes from +*/ struct _DbusmenuGtkSerializableMenuItemPrivate { DbusmenuMenuitem * mi; }; @@ -43,16 +47,20 @@ enum { PROP_MENUITEM }; +/* Private macro, only used in object init */ #define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM, DbusmenuGtkSerializableMenuItemPrivate)) +/* Function prototypes */ static void dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemClass *klass); static void dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self); static void dbusmenu_gtk_serializable_menu_item_dispose (GObject *object); static void dbusmenu_gtk_serializable_menu_item_finalize (GObject *object); +/* GObject boiler plate */ G_DEFINE_TYPE (DbusmenuGtkSerializableMenuItem, dbusmenu_gtk_serializable_menu_item, GTK_TYPE_MENU_ITEM); +/* Initialize the stuff in the class structure */ static void dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemClass *klass) { @@ -72,6 +80,7 @@ dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemC return; } +/* Initialize the object structures and private structure */ static void dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self) { @@ -82,6 +91,7 @@ dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self) return; } +/* Free all references to objects */ static void dbusmenu_gtk_serializable_menu_item_dispose (GObject *object) { @@ -98,6 +108,7 @@ dbusmenu_gtk_serializable_menu_item_dispose (GObject *object) return; } +/* Free memory */ static void dbusmenu_gtk_serializable_menu_item_finalize (GObject *object) { @@ -121,6 +132,7 @@ dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializ return NULL; } +/* Callback to the generic type handler */ typedef struct _type_handler_t type_handler_t; struct _type_handler_t { DbusmenuGtkSerializableMenuItemClass * class; -- cgit v1.2.3 From 91544bb4a5ae2bc6eea3e930da6c7ebbb32216d0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 16:37:44 -0600 Subject: gtk-doc documentation for public API functions --- libdbusmenu-gtk/serializablemenuitem.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 01b20b2..06dfa59 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -119,6 +119,19 @@ dbusmenu_gtk_serializable_menu_item_finalize (GObject *object) return; } +/** + dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem: + @smi: #DbusmenuGtkSerializableMenuItem to build a #DbusmenuMenuitem mirroring + + This function is for menu items that are instanciated from + GTK and have their properites set using GTK functions. This + builds a #DbusmenuMenuitem that then has the properties that + should be sent over the bus to create a new item of this + type on the other side. + + Return value: A #DbusmenuMenuitem who's values will be set by + this object. +*/ DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi) { @@ -165,6 +178,16 @@ type_destroy_handler (DbusmenuClient * client, const gchar * type, gpointer user return; } +/** + dbusmenu_gtk_serializable_menu_item_register_to_client: + @client: #DbusmenuClient that we should register a type at. + @item_type: The #GType of a class that is a subclass of #DbusmenuGtkSerializableMenuItem + + Registers a generic handler for dealing with all subclasses of + #DbusmenuGtkSerializableMenuItem. This handler responds to the callback, + creates a new object and attaches it to the appropriate #DbusmenuMenuitem + object. +*/ void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) { @@ -195,6 +218,17 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, return; } +/** + dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem: + @smi: #DbusmenuGtkSerializableMenuItem to set the @DbusmenuGtkSerializableMenuItem::dbusmenu-menuitem of + @mi: Menuitem to get the properties from + + This function is used on the server side to signal to the object + that it should get its' property change events from @mi instead + of expecting calls to its' API. A call to this function sets the + property and subclasses should listen to the notify signal to + pick up this property being set. +*/ void dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi) { -- cgit v1.2.3 From 97083dc0b396d91c68fe9f439024cc048333e87b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 16:43:44 -0600 Subject: Adding in set and get property functions. --- libdbusmenu-gtk/serializablemenuitem.c | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 06dfa59..99bc585 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -56,6 +56,14 @@ static void dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializa static void dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self); static void dbusmenu_gtk_serializable_menu_item_dispose (GObject *object); static void dbusmenu_gtk_serializable_menu_item_finalize (GObject *object); +static void set_property (GObject * obj, + guint id, + const GValue * value, + GParamSpec * pspec); +static void get_property (GObject * obj, + guint id, + GValue * value, + GParamSpec * pspec); /* GObject boiler plate */ G_DEFINE_TYPE (DbusmenuGtkSerializableMenuItem, dbusmenu_gtk_serializable_menu_item, GTK_TYPE_MENU_ITEM); @@ -70,6 +78,8 @@ dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemC object_class->dispose = dbusmenu_gtk_serializable_menu_item_dispose; object_class->finalize = dbusmenu_gtk_serializable_menu_item_finalize; + object_class->set_property = set_property; + object_class->get_property = get_property; g_object_class_install_property (object_class, PROP_MENUITEM, g_param_spec_object(DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_PROP_MENUITEM, "DBusmenu Menuitem attached to item", @@ -119,6 +129,42 @@ dbusmenu_gtk_serializable_menu_item_finalize (GObject *object) return; } +/* Set an object property */ +static void +set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec) +{ + DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(obj); + + switch (id) { + case PROP_MENUITEM: + smi->priv->mi = g_value_get_object(value); + break; + default: + g_return_if_reached(); + break; + } + + return; +} + +/* Get an object property */ +static void +get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) +{ + DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(obj); + + switch (id) { + case PROP_MENUITEM: + g_value_set_object(value, smi->priv->mi); + break; + default: + g_return_if_reached(); + break; + } + + return; +} + /** dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem: @smi: #DbusmenuGtkSerializableMenuItem to build a #DbusmenuMenuitem mirroring -- cgit v1.2.3 From 555f085168fac50cf55c910c746363f8ce268823 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 16:46:27 -0600 Subject: Fleshing out setting the property --- libdbusmenu-gtk/serializablemenuitem.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 99bc585..6bc3695 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -278,6 +278,11 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, void dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi) { + g_return_if_fail(DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(smi)); + g_return_if_fail(mi != NULL); + + smi->priv->mi = mi; + g_object_notify(G_OBJECT(smi), DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_PROP_MENUITEM); return; } -- cgit v1.2.3 From 539290124d737754b20dd69e6d3033175ca37e12 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 16:48:41 -0600 Subject: Ensuring our double include protectors make g-ir-scanner happy. --- libdbusmenu-gtk/menuitem.h | 4 ++-- libdbusmenu-gtk/serializablemenuitem.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.h b/libdbusmenu-gtk/menuitem.h index a2b6652..4fc42f9 100644 --- a/libdbusmenu-gtk/menuitem.h +++ b/libdbusmenu-gtk/menuitem.h @@ -26,8 +26,8 @@ License version 3 and version 2.1 along with this program. If not, see */ -#ifndef __DBUSMENU_GTKMENUITEM_H__ -#define __DBUSMENU_GTKMENUITEM_H__ 1 +#ifndef DBUSMENU_GTK_MENUITEM_H__ +#define DBUSMENU_GTK_MENUITEM_H__ 1 #include #include diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index aae2f96..1ca3ef8 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -26,8 +26,8 @@ License version 3 and version 2.1 along with this program. If not, see */ -#ifndef __DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ -#define __DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ +#ifndef DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ +#define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ 1 #include #include -- cgit v1.2.3 From edef8613dd3e78e5d11a2754e6175dd8e55ff87e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 16:59:35 -0600 Subject: Adding a transfer annotation --- libdbusmenu-gtk/serializablemenuitem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 6bc3695..f67434e 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -175,8 +175,8 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) should be sent over the bus to create a new item of this type on the other side. - Return value: A #DbusmenuMenuitem who's values will be set by - this object. + Return value: (transfer full) A #DbusmenuMenuitem who's values will be + set by this object. */ DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi) -- cgit v1.2.3 From c644e10c9da09e443a00422df00a6ba9df7a7e83 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 23 Jan 2011 12:45:05 -0600 Subject: Adding the base files for the parser --- libdbusmenu-gtk/Makefile.am | 7 +++++-- libdbusmenu-gtk/parser.c | 9 +++++++++ libdbusmenu-gtk/parser.h | 6 ++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 libdbusmenu-gtk/parser.c create mode 100644 libdbusmenu-gtk/parser.h (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index e5df6b1..201a631 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -23,7 +23,8 @@ libdbusmenu_gtkinclude_HEADERS = \ dbusmenu-gtk.h \ client.h \ menu.h \ - menuitem.h + menuitem.h \ + parser.h libdbusmenu_gtk_la_SOURCES = \ client.h \ @@ -33,7 +34,9 @@ libdbusmenu_gtk_la_SOURCES = \ menu.h \ menu.c \ menuitem.h \ - menuitem.c + menuitem.c \ + parser.h \ + parser.c libdbusmenu_gtk_la_LDFLAGS = \ -version-info $(LIBDBUSMENU_CURRENT):$(LIBDBUSMENU_REVISION):$(LIBDBUSMENU_AGE) \ diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c new file mode 100644 index 0000000..98b3f7d --- /dev/null +++ b/libdbusmenu-gtk/parser.c @@ -0,0 +1,9 @@ + +#include "parser.h" + +DbusmenuMenuitem * +dbusmenu_gtk_parse_menu_structure (GtkMenuItem * mi) +{ + + return NULL; +} diff --git a/libdbusmenu-gtk/parser.h b/libdbusmenu-gtk/parser.h new file mode 100644 index 0000000..222d9f4 --- /dev/null +++ b/libdbusmenu-gtk/parser.h @@ -0,0 +1,6 @@ + +#include +#include + +DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkMenuItem * mi); + -- cgit v1.2.3 From b39a625defde44aa345253237d4f186abedf7196 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Sun, 23 Jan 2011 13:05:28 -0600 Subject: Taking the menu parsing code from appmenu-gtk --- libdbusmenu-gtk/parser.c | 426 ++++++++++++++++++++++++++++++++++++++++++++++- libdbusmenu-gtk/parser.h | 2 +- 2 files changed, 426 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 98b3f7d..8fd0d12 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -1,9 +1,433 @@ #include "parser.h" +#include "menuitem.h" + +static void accel_changed (GtkWidget *widget, gpointer data); +static gboolean update_stock_item (DbusmenuMenuitem *menuitem, GtkWidget *widget); +static void checkbox_toggled (GtkWidget *widget, DbusmenuMenuitem *mi); +static void update_icon_name (DbusmenuMenuitem *menuitem, GtkWidget *widget); +static GtkWidget * find_menu_label (GtkWidget *widget); +static void label_notify_cb (GtkWidget *widget, GParamSpec *pspec, gpointer data); +static void action_notify_cb (GtkAction *action, GParamSpec *pspec, gpointer data); +static void item_activated (DbusmenuMenuitem *item, guint timestamp, gpointer user_data); +static gboolean item_about_to_show (DbusmenuMenuitem *item, gpointer user_data); +static void widget_notify_cb (GtkWidget *widget, GParamSpec *pspec, gpointer data); +static gboolean should_show_image (GtkImage *image); DbusmenuMenuitem * -dbusmenu_gtk_parse_menu_structure (GtkMenuItem * mi) +dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) { + DbusmenuMenuitem *mi = dbusmenu_menuitem_new (); + + if (GTK_IS_MENU_ITEM (widget)) + { + gboolean visible = FALSE; + gboolean sensitive = FALSE; + if (GTK_IS_SEPARATOR_MENU_ITEM (widget)) + { + dbusmenu_menuitem_property_set (mi, + "type", + "separator"); + + visible = gtk_widget_get_visible (widget); + sensitive = gtk_widget_get_sensitive (widget); + } + else + { + gboolean label_set = FALSE; + + g_signal_connect (widget, + "accel-closures-changed", + G_CALLBACK (accel_changed), + mi); + + if (GTK_IS_CHECK_MENU_ITEM (widget)) + { + dbusmenu_menuitem_property_set (mi, + DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, + gtk_check_menu_item_get_draw_as_radio (GTK_CHECK_MENU_ITEM (widget)) ? DBUSMENU_MENUITEM_TOGGLE_RADIO : DBUSMENU_MENUITEM_TOGGLE_CHECK); + + dbusmenu_menuitem_property_set_int (mi, + DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, + gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget)) ? DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED : DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED); + + g_signal_connect (widget, + "activate", + G_CALLBACK (checkbox_toggled), + mi); + } + + if (GTK_IS_IMAGE_MENU_ITEM (widget)) + { + GtkWidget *image; + GtkImageType image_type; + + image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (widget)); + + if (GTK_IS_IMAGE (image)) + { + image_type = gtk_image_get_storage_type (GTK_IMAGE (image)); + + if (image_type == GTK_IMAGE_STOCK) + { + label_set = update_stock_item (mi, image); + } + else if (image_type == GTK_IMAGE_ICON_NAME) + { + update_icon_name (mi, image); + } + else if (image_type == GTK_IMAGE_PIXBUF) + { + dbusmenu_menuitem_property_set_image (mi, + DBUSMENU_MENUITEM_PROP_ICON_DATA, + gtk_image_get_pixbuf (GTK_IMAGE (image))); + } + } + } + + GtkWidget *label = find_menu_label (widget); + + dbusmenu_menuitem_property_set (mi, + "label", + label ? gtk_label_get_text (GTK_LABEL (label)) : NULL); + + if (label) + { + // Sometimes, an app will directly find and modify the label + // (like empathy), so watch the label especially for that. + g_signal_connect (G_OBJECT (label), + "notify", + G_CALLBACK (label_notify_cb), + mi); + } + + if (GTK_IS_ACTIVATABLE (widget)) + { + GtkActivatable *activatable = GTK_ACTIVATABLE (widget); + + if (gtk_activatable_get_use_action_appearance (activatable)) + { + GtkAction *action = gtk_activatable_get_related_action (activatable); + + if (action) + { + visible = gtk_action_is_visible (action); + sensitive = gtk_action_is_sensitive (action); + + g_signal_connect_object (action, "notify", + G_CALLBACK (action_notify_cb), + mi, + G_CONNECT_AFTER); + } + } + } + + if (!g_object_get_data (G_OBJECT (widget), "gtk-empty-menu-item") && !GTK_IS_TEAROFF_MENU_ITEM (widget)) + { + visible = gtk_widget_get_visible (widget); + sensitive = gtk_widget_get_sensitive (widget); + } + + dbusmenu_menuitem_property_set_shortcut_menuitem (mi, GTK_MENU_ITEM (widget)); + + g_signal_connect (G_OBJECT (mi), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK (item_activated), + widget); + + g_signal_connect (G_OBJECT (mi), + DBUSMENU_MENUITEM_SIGNAL_ABOUT_TO_SHOW, + G_CALLBACK (item_about_to_show), + widget); + } + + dbusmenu_menuitem_property_set_bool (mi, + DBUSMENU_MENUITEM_PROP_VISIBLE, + visible); + + dbusmenu_menuitem_property_set_bool (mi, + DBUSMENU_MENUITEM_PROP_ENABLED, + sensitive); + + g_signal_connect (widget, + "notify", + G_CALLBACK (widget_notify_cb), + mi); + } + + return mi; return NULL; } + +static void +accel_changed (GtkWidget *widget, + gpointer data) +{ + DbusmenuMenuitem *mi = (DbusmenuMenuitem *)data; + dbusmenu_menuitem_property_set_shortcut_menuitem (mi, GTK_MENU_ITEM (widget)); +} + +static gboolean +update_stock_item (DbusmenuMenuitem *menuitem, + GtkWidget *widget) +{ + GtkStockItem stock; + GtkImage *image; + + g_return_val_if_fail (GTK_IS_IMAGE (widget), FALSE); + + image = GTK_IMAGE (widget); + + if (gtk_image_get_storage_type (image) != GTK_IMAGE_STOCK) + return FALSE; + + gtk_stock_lookup (image->data.stock.stock_id, &stock); + + if (should_show_image (image)) + dbusmenu_menuitem_property_set (menuitem, + DBUSMENU_MENUITEM_PROP_ICON_NAME, + image->data.stock.stock_id); + else + dbusmenu_menuitem_property_remove (menuitem, + DBUSMENU_MENUITEM_PROP_ICON_NAME); + + const gchar *label = dbusmenu_menuitem_property_get (menuitem, + DBUSMENU_MENUITEM_PROP_LABEL); + + if (stock.label != NULL && label != NULL) + { + dbusmenu_menuitem_property_set (menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + stock.label); + + return TRUE; + } + + return FALSE; +} + +static void +checkbox_toggled (GtkWidget *widget, DbusmenuMenuitem *mi) +{ + dbusmenu_menuitem_property_set_int (mi, + DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, + gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget)) ? DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED : DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED); +} + +static void +update_icon_name (DbusmenuMenuitem *menuitem, + GtkWidget *widget) +{ + GtkImage *image; + + g_return_if_fail (GTK_IS_IMAGE (widget)); + + image = GTK_IMAGE (widget); + + if (gtk_image_get_storage_type (image) != GTK_IMAGE_ICON_NAME) + return; + + if (should_show_image (image)) + dbusmenu_menuitem_property_set (menuitem, + DBUSMENU_MENUITEM_PROP_ICON_NAME, + image->data.name.icon_name); + else + dbusmenu_menuitem_property_remove (menuitem, + DBUSMENU_MENUITEM_PROP_ICON_NAME); +} + +static GtkWidget * +find_menu_label (GtkWidget *widget) +{ + GtkWidget *label = NULL; + + if (GTK_IS_LABEL (widget)) + return widget; + + if (GTK_IS_CONTAINER (widget)) + { + GList *children; + GList *l; + + children = gtk_container_get_children (GTK_CONTAINER (widget)); + + for (l = children; l; l = l->next) + { + label = find_menu_label (l->data); + + if (label) + break; + } + + g_list_free (children); + } + + return label; +} + +static void +label_notify_cb (GtkWidget *widget, + GParamSpec *pspec, + gpointer data) +{ + DbusmenuMenuitem *child = (DbusmenuMenuitem *)data; + + if (pspec->name == g_intern_static_string ("label")) + { + dbusmenu_menuitem_property_set (child, + DBUSMENU_MENUITEM_PROP_LABEL, + gtk_label_get_text (GTK_LABEL (widget))); + } +} + +static void +action_notify_cb (GtkAction *action, + GParamSpec *pspec, + gpointer data) +{ + DbusmenuMenuitem *mi = (DbusmenuMenuitem *)data; + + if (pspec->name == g_intern_static_string ("sensitive")) + { + dbusmenu_menuitem_property_set_bool (mi, + DBUSMENU_MENUITEM_PROP_ENABLED, + gtk_action_is_sensitive (action)); + } + else if (pspec->name == g_intern_static_string ("visible")) + { + dbusmenu_menuitem_property_set_bool (mi, + DBUSMENU_MENUITEM_PROP_VISIBLE, + gtk_action_is_visible (action)); + } + else if (pspec->name == g_intern_static_string ("active")) + { + dbusmenu_menuitem_property_set_bool (mi, + DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, + gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))); + } + else if (pspec->name == g_intern_static_string ("label")) + { + dbusmenu_menuitem_property_set (mi, + DBUSMENU_MENUITEM_PROP_LABEL, + gtk_action_get_label (action)); + } +} + +static void +item_activated (DbusmenuMenuitem *item, guint timestamp, gpointer user_data) +{ + GtkWidget *child; + + if (user_data != NULL) + { + child = (GtkWidget *)user_data; + + if (GTK_IS_MENU_ITEM (child)) + { + gtk_menu_item_activate (GTK_MENU_ITEM (child)); + } + } +} + +static gboolean +item_about_to_show (DbusmenuMenuitem *item, gpointer user_data) +{ + GtkWidget *child; + + if (user_data != NULL) + { + child = (GtkWidget *)user_data; + + if (GTK_IS_MENU_ITEM (child)) + { + // Only called for items with submens. So we activate it here in + // case the program dynamically creates menus (like empathy does) + gtk_menu_item_activate (GTK_MENU_ITEM (child)); + } + } + + return TRUE; +} + +static void +widget_notify_cb (GtkWidget *widget, + GParamSpec *pspec, + gpointer data) +{ + DbusmenuMenuitem *child = (DbusmenuMenuitem *)data; + + if (pspec->name == g_intern_static_string ("sensitive")) + { + dbusmenu_menuitem_property_set_bool (child, + DBUSMENU_MENUITEM_PROP_ENABLED, + gtk_widget_get_sensitive (widget)); + } + else if (pspec->name == g_intern_static_string ("label")) + { + dbusmenu_menuitem_property_set (child, + DBUSMENU_MENUITEM_PROP_LABEL, + gtk_menu_item_get_label (GTK_MENU_ITEM (widget))); + } + else if (pspec->name == g_intern_static_string ("visible")) + { + dbusmenu_menuitem_property_set_bool (child, + DBUSMENU_MENUITEM_PROP_VISIBLE, + gtk_widget_get_visible (widget)); + } + else if (pspec->name == g_intern_static_string ("stock")) + { + update_stock_item (child, widget); + } + else if (pspec->name == g_intern_static_string ("icon-name")) + { + update_icon_name (child, widget); + } + else if (pspec->name == g_intern_static_string ("parent")) + { + /* + * We probably should have added a 'remove' method to the + * UbuntuMenuProxy early on, but it's late in the cycle now. + */ + if (gtk_widget_get_parent (widget) == NULL) + { + g_signal_handlers_disconnect_by_func (widget, + G_CALLBACK (widget_notify_cb), + child); + + DbusmenuMenuitem *parent = g_object_get_data (G_OBJECT (child), "dbusmenu-parent"); + + if (DBUSMENU_IS_MENUITEM (parent) && DBUSMENU_IS_MENUITEM (child)) + { + dbusmenu_menuitem_child_delete (parent, child); + } + } + } +} + +static gboolean +should_show_image (GtkImage *image) +{ + GtkWidget *item; + + item = gtk_widget_get_ancestor (GTK_WIDGET (image), + GTK_TYPE_IMAGE_MENU_ITEM); + + if (item) + { + GtkSettings *settings; + gboolean gtk_menu_images; + + settings = gtk_widget_get_settings (item); + + g_object_get (settings, "gtk-menu-images", >k_menu_images, NULL); + + if (gtk_menu_images) + return TRUE; + + return gtk_image_menu_item_get_always_show_image (GTK_IMAGE_MENU_ITEM (item)); + } + + return FALSE; +} + diff --git a/libdbusmenu-gtk/parser.h b/libdbusmenu-gtk/parser.h index 222d9f4..3cffb9c 100644 --- a/libdbusmenu-gtk/parser.h +++ b/libdbusmenu-gtk/parser.h @@ -2,5 +2,5 @@ #include #include -DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkMenuItem * mi); +DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget); -- cgit v1.2.3 From 708ccab44c2c88b43ad35048dc0aee81023e61f9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 23 Jan 2011 13:11:46 -0600 Subject: Reformating prototypes because it makes the code run faster. --- libdbusmenu-gtk/parser.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 8fd0d12..f0c22be 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -2,17 +2,30 @@ #include "parser.h" #include "menuitem.h" -static void accel_changed (GtkWidget *widget, gpointer data); -static gboolean update_stock_item (DbusmenuMenuitem *menuitem, GtkWidget *widget); -static void checkbox_toggled (GtkWidget *widget, DbusmenuMenuitem *mi); -static void update_icon_name (DbusmenuMenuitem *menuitem, GtkWidget *widget); -static GtkWidget * find_menu_label (GtkWidget *widget); -static void label_notify_cb (GtkWidget *widget, GParamSpec *pspec, gpointer data); -static void action_notify_cb (GtkAction *action, GParamSpec *pspec, gpointer data); -static void item_activated (DbusmenuMenuitem *item, guint timestamp, gpointer user_data); -static gboolean item_about_to_show (DbusmenuMenuitem *item, gpointer user_data); -static void widget_notify_cb (GtkWidget *widget, GParamSpec *pspec, gpointer data); -static gboolean should_show_image (GtkImage *image); +static void accel_changed (GtkWidget * widget, + gpointer data); +static gboolean update_stock_item (DbusmenuMenuitem * menuitem, + GtkWidget * widget); +static void checkbox_toggled (GtkWidget * widget, + DbusmenuMenuitem * mi); +static void update_icon_name (DbusmenuMenuitem * menuitem, + GtkWidget * widget); +static GtkWidget * find_menu_label (GtkWidget * widget); +static void label_notify_cb (GtkWidget * widget, + GParamSpec * pspec, + gpointer data); +static void action_notify_cb (GtkAction * action, + GParamSpec * pspec, + gpointer data); +static void item_activated (DbusmenuMenuitem * item, + guint timestamp, + gpointer user_data); +static gboolean item_about_to_show (DbusmenuMenuitem * item, + gpointer user_data); +static void widget_notify_cb (GtkWidget * widget, + GParamSpec * pspec, + gpointer data); +static gboolean should_show_image (GtkImage * image); DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) -- cgit v1.2.3 From 401bc7c326c518ad01c1edd38155d89d9e35fd49 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 23 Jan 2011 13:16:20 -0600 Subject: Adding copyright headers --- libdbusmenu-gtk/parser.c | 27 +++++++++++++++++++++++++++ libdbusmenu-gtk/parser.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index f0c22be..cba6b42 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -1,3 +1,30 @@ +/* +Parse to take a set of GTK Menus and turn them into something that can +be sent over the wire. + +Copyright 2011 Canonical Ltd. + +Authors: + Numerous (check Bazaar) + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see + +*/ #include "parser.h" #include "menuitem.h" diff --git a/libdbusmenu-gtk/parser.h b/libdbusmenu-gtk/parser.h index 3cffb9c..a40d709 100644 --- a/libdbusmenu-gtk/parser.h +++ b/libdbusmenu-gtk/parser.h @@ -1,6 +1,37 @@ +/* +Parse to take a set of GTK Menus and turn them into something that can +be sent over the wire. + +Copyright 2011 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see + +*/ + +#ifndef DBUSMENU_GTK_PARSER_H__ +#define DBUSMENU_GTK_PARSER_H__ #include #include DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget); +#endif /* DBUSMENU_GTK_PARSER_H__ */ -- cgit v1.2.3 From 32a7eb938893bcc1bc5644aa95c63041e9d4db01 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 23 Jan 2011 15:09:51 -0600 Subject: Needed to go up a level to get recursion code. --- libdbusmenu-gtk/parser.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index cba6b42..08613ac 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -29,6 +29,14 @@ License version 3 and version 2.1 along with this program. If not, see #include "parser.h" #include "menuitem.h" +typedef struct _RecurseContext +{ + gint count; + DbusmenuMenuitem *stack[30]; +} RecurseContext; + +static void parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse); +static DbusmenuMenuitem * construct_dbusmenu_for_widget (GtkWidget * widget); static void accel_changed (GtkWidget * widget, gpointer data); static gboolean update_stock_item (DbusmenuMenuitem * menuitem, @@ -56,6 +64,156 @@ static gboolean should_show_image (GtkImage * image); DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) +{ + RecurseContext recurse = {0}; + recurse.count = -1; + + parse_menu_structure_helper(widget, &recurse); + + if (recurse.stack[0] != NULL && DBUSMENU_IS_MENUITEM(recurse.stack[0])) { + return recurse.stack[0]; + } + + return NULL; +} + +static void +parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) +{ + if (GTK_IS_CONTAINER (widget)) + { + gboolean increment = GTK_IS_MENU_BAR (widget) || GTK_IS_MENU_ITEM (widget); + + if (increment) + recurse->count++; + + /* Okay, this is a little janky and all.. but some applications update some + * menuitem properties such as sensitivity on the activate callback. This + * seems a little weird, but it's not our place to judge when all this code + * is so crazy. So we're going to get ever crazier and activate all the + * menus that are directly below the menubar and force the applications to + * update their sensitivity. The menus won't actually popup in the app + * window due to our gtk+ patches. + * + * Note that this will not force menuitems in submenus to be updated as well. + */ + if (recurse->count == 0 && GTK_IS_MENU_BAR (widget)) + { + GList *children = gtk_container_get_children (GTK_CONTAINER (widget)); + + for (; children != NULL; children = children->next) + { + gtk_menu_shell_activate_item (GTK_MENU_SHELL (widget), + children->data, + TRUE); + } + + g_list_free (children); + } + + if (recurse->count > -1 && increment) + { + DbusmenuMenuitem *dmi = NULL; //g_hash_table_lookup (recurse->context->lookup, widget); + if (dmi != NULL) + { + if (increment) + recurse->count--; + + return; + } + else + { + recurse->stack[recurse->count] = construct_dbusmenu_for_widget (widget); + //g_hash_table_insert (recurse->context->lookup, widget, recurse->stack[recurse->count]); + } + + if (!gtk_widget_get_visible (widget)) + { + /*g_signal_connect (G_OBJECT (widget), + "notify", + G_CALLBACK (menuitem_notify_cb), + recurse->context); */ + } + + if (GTK_IS_TEAROFF_MENU_ITEM (widget)) + { + dbusmenu_menuitem_property_set_bool (recurse->stack[recurse->count], + DBUSMENU_MENUITEM_PROP_VISIBLE, + FALSE); + } + + if (recurse->count > 0) + { + GList *children = NULL; + GList *peek = NULL; + + if (recurse->stack[recurse->count - 1]) + { + children = dbusmenu_menuitem_get_children (recurse->stack[recurse->count - 1]); + + if (children) + { + peek = g_list_find (children, recurse->stack[recurse->count]); + } + + if (!peek) + { + /* Should we set a weak ref on the parent? */ + g_object_set_data (G_OBJECT (recurse->stack[recurse->count]), + "dbusmenu-parent", + recurse->stack[recurse->count - 1]); + dbusmenu_menuitem_child_append (recurse->stack[recurse->count - 1], + recurse->stack[recurse->count]); + } + } + else + { + DbusmenuMenuitem *item = NULL; /* g_hash_table_lookup (recurse->context->lookup, + gtk_widget_get_parent (widget)); */ + + if (item) + { + children = dbusmenu_menuitem_get_children (item); + + if (children) + { + peek = g_list_find (children, recurse->stack[recurse->count]); + } + + if (!peek) + { + g_object_set_data (G_OBJECT (recurse->stack[recurse->count]), + "dbusmenu-parent", + recurse->stack[recurse->count - 1]); + + dbusmenu_menuitem_child_append (item, recurse->stack[recurse->count]); + } + } + } + } + } + + gtk_container_foreach (GTK_CONTAINER (widget), + (GtkCallback)parse_menu_structure_helper, + recurse); + + if (GTK_IS_MENU_ITEM (widget)) + { + GtkWidget *menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget)); + + if (menu != NULL) + { + parse_menu_structure_helper (menu, recurse); + } + } + + if (increment) + recurse->count--; + } +} + +static DbusmenuMenuitem * +construct_dbusmenu_for_widget (GtkWidget * widget) { DbusmenuMenuitem *mi = dbusmenu_menuitem_new (); -- cgit v1.2.3 From 65b9cda89a5bef2c541f5ed2624e6e199f136435 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 23 Jan 2011 15:40:26 -0600 Subject: Trying to put back in the visibility notifier to force the rebuild, but I'm not quite sure how to do that yet. --- libdbusmenu-gtk/parser.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 08613ac..9d0f9b4 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -31,6 +31,7 @@ License version 3 and version 2.1 along with this program. If not, see typedef struct _RecurseContext { + GtkWidget * toplevel; gint count; DbusmenuMenuitem *stack[30]; } RecurseContext; @@ -61,12 +62,17 @@ static void widget_notify_cb (GtkWidget * widget, GParamSpec * pspec, gpointer data); static gboolean should_show_image (GtkImage * image); +static void menuitem_notify_cb (GtkWidget * widget, + GParamSpec * pspec, + gpointer data); DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) { RecurseContext recurse = {0}; + recurse.count = -1; + recurse.toplevel = gtk_widget_get_toplevel(widget); parse_menu_structure_helper(widget, &recurse); @@ -129,10 +135,10 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) if (!gtk_widget_get_visible (widget)) { - /*g_signal_connect (G_OBJECT (widget), - "notify", + g_signal_connect (G_OBJECT (widget), + "notify::visible", G_CALLBACK (menuitem_notify_cb), - recurse->context); */ + recurse->toplevel); } if (GTK_IS_TEAROFF_MENU_ITEM (widget)) @@ -358,6 +364,27 @@ construct_dbusmenu_for_widget (GtkWidget * widget) return NULL; } +static void +menuitem_notify_cb (GtkWidget *widget, + GParamSpec *pspec, + gpointer data) +{ + if (pspec->name == g_intern_static_string ("visible")) + { + GtkWidget * new_toplevel = gtk_widget_get_toplevel (widget); + GtkWidget * old_toplevel = GTK_WIDGET(data); + + if (new_toplevel == old_toplevel) { + /* TODO: Figure this out -> rebuild (context->bridge, window); */ + } + + /* We only care about this once, so let's disconnect now. */ + g_signal_handlers_disconnect_by_func (widget, + G_CALLBACK (menuitem_notify_cb), + data); + } +} + static void accel_changed (GtkWidget *widget, gpointer data) -- cgit v1.2.3 From a439aeb8fd08d9858055bbb2ae1326a1335600d1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 23 Jan 2011 15:53:27 -0600 Subject: Reimplementing the cache based on object data with signals to cleanup --- libdbusmenu-gtk/parser.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 9d0f9b4..f1c46ba 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -29,6 +29,8 @@ License version 3 and version 2.1 along with this program. If not, see #include "parser.h" #include "menuitem.h" +#define CACHED_MENUITEM "dbusmenu-gtk-parser-cached-item" + typedef struct _RecurseContext { GtkWidget * toplevel; @@ -83,6 +85,20 @@ dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) return NULL; } +static void +dbusmenu_cache_freed (gpointer data, GObject * obj) +{ + g_object_set_data(G_OBJECT(data), CACHED_MENUITEM, NULL); + return; +} + +static void +object_cache_freed (gpointer data) +{ + g_object_weak_unref(G_OBJECT(data), dbusmenu_cache_freed, data); + return; +} + static void parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) { @@ -119,7 +135,10 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) if (recurse->count > -1 && increment) { - DbusmenuMenuitem *dmi = NULL; //g_hash_table_lookup (recurse->context->lookup, widget); + gpointer pmi = g_object_get_data(G_OBJECT(widget), CACHED_MENUITEM); + DbusmenuMenuitem *dmi = NULL; + if (pmi != NULL) dmi = DBUSMENU_MENUITEM(pmi); + if (dmi != NULL) { if (increment) @@ -130,7 +149,8 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) else { recurse->stack[recurse->count] = construct_dbusmenu_for_widget (widget); - //g_hash_table_insert (recurse->context->lookup, widget, recurse->stack[recurse->count]); + g_object_set_data_full(G_OBJECT(widget), CACHED_MENUITEM, recurse->stack[recurse->count], object_cache_freed); + g_object_weak_ref(G_OBJECT(recurse->stack[recurse->count]), dbusmenu_cache_freed, widget); } if (!gtk_widget_get_visible (widget)) -- cgit v1.2.3 From fc096ca12b152461dfddbfdf74720b98691448ce Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 23 Jan 2011 16:08:39 -0600 Subject: Stop using the data field in gtk image for GTK3 --- libdbusmenu-gtk/parser.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index f1c46ba..cfce42a 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -427,12 +427,15 @@ update_stock_item (DbusmenuMenuitem *menuitem, if (gtk_image_get_storage_type (image) != GTK_IMAGE_STOCK) return FALSE; - gtk_stock_lookup (image->data.stock.stock_id, &stock); + gchar * stock_id = NULL; + gtk_image_get_stock(image, &stock_id, NULL); + + gtk_stock_lookup (stock_id, &stock); if (should_show_image (image)) dbusmenu_menuitem_property_set (menuitem, DBUSMENU_MENUITEM_PROP_ICON_NAME, - image->data.stock.stock_id); + stock_id); else dbusmenu_menuitem_property_remove (menuitem, DBUSMENU_MENUITEM_PROP_ICON_NAME); @@ -473,13 +476,16 @@ update_icon_name (DbusmenuMenuitem *menuitem, if (gtk_image_get_storage_type (image) != GTK_IMAGE_ICON_NAME) return; - if (should_show_image (image)) + if (should_show_image (image)) { + const gchar * icon_name = NULL; + gtk_image_get_icon_name(image, &icon_name, NULL); dbusmenu_menuitem_property_set (menuitem, DBUSMENU_MENUITEM_PROP_ICON_NAME, - image->data.name.icon_name); - else + icon_name); + } else { dbusmenu_menuitem_property_remove (menuitem, DBUSMENU_MENUITEM_PROP_ICON_NAME); + } } static GtkWidget * -- cgit v1.2.3 From 25ab785826d59d8ca7860b0d0bc39d6187a3a1ed Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 24 Jan 2011 14:56:07 -0600 Subject: Fixing referencing warnings on destruction. --- libdbusmenu-gtk/parser.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index cfce42a..52bd8a8 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -88,7 +88,9 @@ dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) static void dbusmenu_cache_freed (gpointer data, GObject * obj) { - g_object_set_data(G_OBJECT(data), CACHED_MENUITEM, NULL); + /* If the dbusmenu item is killed we don't need to remove + the weak ref as well. */ + g_object_steal_data(G_OBJECT(data), CACHED_MENUITEM); return; } -- cgit v1.2.3 From 32def89e3191d994a43d222c1e81c746922b688d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 25 Jan 2011 11:50:46 -0600 Subject: Moving one up the stack so GtkMenu works as well --- libdbusmenu-gtk/parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 52bd8a8..d26f8fb 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -106,7 +106,7 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) { if (GTK_IS_CONTAINER (widget)) { - gboolean increment = GTK_IS_MENU_BAR (widget) || GTK_IS_MENU_ITEM (widget); + gboolean increment = GTK_IS_MENU_SHELL (widget) || GTK_IS_MENU_ITEM (widget); if (increment) recurse->count++; -- cgit v1.2.3 From 275bd0eec2e28b708ff6cda14531f63a8aa16e8e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 25 Jan 2011 16:51:31 -0600 Subject: Looking for the serializable menu item and using it's build function if it is one. --- libdbusmenu-gtk/parser.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index d26f8fb..6d95f10 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -28,6 +28,7 @@ License version 3 and version 2.1 along with this program. If not, see #include "parser.h" #include "menuitem.h" +#include "serializablemenuitem.h" #define CACHED_MENUITEM "dbusmenu-gtk-parser-cached-item" @@ -240,13 +241,23 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) } } +/* Turn a widget into a dbusmenu item depending on the type of GTK + object that it is. */ static DbusmenuMenuitem * construct_dbusmenu_for_widget (GtkWidget * widget) { - DbusmenuMenuitem *mi = dbusmenu_menuitem_new (); - + /* If it's a subclass of our serializable menu item then we can + use its own build function */ + if (DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(widget)) { + DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(widget); + return dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem(smi); + } + + /* If it's a standard GTK Menu Item we need to do some of our own work */ if (GTK_IS_MENU_ITEM (widget)) { + DbusmenuMenuitem *mi = dbusmenu_menuitem_new (); + gboolean visible = FALSE; gboolean sensitive = FALSE; if (GTK_IS_SEPARATOR_MENU_ITEM (widget)) @@ -379,11 +390,12 @@ construct_dbusmenu_for_widget (GtkWidget * widget) "notify", G_CALLBACK (widget_notify_cb), mi); + return mi; } - return mi; - - return NULL; + /* If it's none of those we're going to just create a + generic menuitem as a place holder for it. */ + return dbusmenu_menuitem_new(); } static void -- cgit v1.2.3 From d5a160e04dfd351cefb70ac5f6955cb2913e2ad5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 25 Jan 2011 17:04:23 -0600 Subject: Adding a little helper to reduce the number of warnings if the property is missing. --- libdbusmenu-gtk/client.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 18a2cdd..ff2b3a7 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -42,6 +42,7 @@ struct _DbusmenuGtkClientPrivate { }; #define DBUSMENU_GTKCLIENT_GET_PRIVATE(o) (DBUSMENU_GTKCLIENT(o)->priv) +#define USE_FALLBACK_PROP "use-fallback" /* Prototypes */ static void dbusmenu_gtkclient_class_init (DbusmenuGtkClientClass *klass); @@ -737,6 +738,28 @@ new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm return TRUE; } +/* A little helper so we don't generate a bunch of warnings + about being able to set use-fallback */ +static void +set_use_fallback (GtkWidget * widget) +{ + static gboolean checked = FALSE; + static gboolean available = FALSE; + + if (!checked) { + available = (g_object_class_find_property(G_OBJECT_CLASS(GTK_IMAGE_GET_CLASS(widget)), USE_FALLBACK_PROP) != NULL); + if (!available) { + g_warning("The '" USE_FALLBACK_PROP "' is not available on GtkImage so icons may not show correctly."); + } + } + + if (available) { + g_object_set(G_OBJECT(widget), USE_FALLBACK_PROP, TRUE, NULL); + } + + return; +} + /* This handler looks at property changes for items that are image menu items. */ static void @@ -789,7 +812,7 @@ image_property_handle (DbusmenuMenuitem * item, const gchar * property, GVariant gtkimage = NULL; } else if (g_strcmp0(iconname, DBUSMENU_MENUITEM_ICON_NAME_BLANK) == 0) { gtkimage = gtk_image_new(); - g_object_set(G_OBJECT(gtkimage), "use-fallback", TRUE, NULL); + set_use_fallback(gtkimage); } else { /* Look to see if we want to have an icon with the 'ltr' or 'rtl' depending on what we're doing. */ @@ -808,7 +831,7 @@ image_property_handle (DbusmenuMenuitem * item, const gchar * property, GVariant can just convert it to this name. */ if (gtkimage == NULL) { gtkimage = gtk_image_new_from_icon_name(finaliconname, GTK_ICON_SIZE_MENU); - g_object_set(G_OBJECT(gtkimage), "use-fallback", TRUE, NULL); + set_use_fallback(gtkimage); } else { gtk_image_set_from_icon_name(GTK_IMAGE(gtkimage), finaliconname, GTK_ICON_SIZE_MENU); } -- cgit v1.2.3 From 1039a4dd88243938e8871c307c20841c375b78d2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Jan 2011 15:11:16 -0600 Subject: Adding comments and a check to ensure the item is valid. --- libdbusmenu-gtk/parser.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index d26f8fb..1936d2d 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -85,6 +85,8 @@ dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) return NULL; } +/* Called when the dbusmenu item that we're keeping around + is finalized */ static void dbusmenu_cache_freed (gpointer data, GObject * obj) { @@ -94,9 +96,12 @@ dbusmenu_cache_freed (gpointer data, GObject * obj) return; } +/* Called if we replace the cache on the object with a new + dbusmenu menuitem */ static void object_cache_freed (gpointer data) { + if (!G_IS_OBJECT(data)) return; g_object_weak_unref(G_OBJECT(data), dbusmenu_cache_freed, data); return; } -- cgit v1.2.3 From 81032fae461250e5e73aaa49896fd92dd58ad674 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Jan 2011 16:09:41 -0600 Subject: Factoring out the stack and just tracking the parent as that's all we were using it for really. --- libdbusmenu-gtk/parser.c | 236 ++++++++++++++++++++--------------------------- 1 file changed, 99 insertions(+), 137 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 1936d2d..5f0ef48 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -34,8 +34,7 @@ License version 3 and version 2.1 along with this program. If not, see typedef struct _RecurseContext { GtkWidget * toplevel; - gint count; - DbusmenuMenuitem *stack[30]; + DbusmenuMenuitem * parent; } RecurseContext; static void parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse); @@ -68,21 +67,17 @@ static void menuitem_notify_cb (GtkWidget * widget, GParamSpec * pspec, gpointer data); + DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) { RecurseContext recurse = {0}; - recurse.count = -1; recurse.toplevel = gtk_widget_get_toplevel(widget); parse_menu_structure_helper(widget, &recurse); - if (recurse.stack[0] != NULL && DBUSMENU_IS_MENUITEM(recurse.stack[0])) { - return recurse.stack[0]; - } - - return NULL; + return recurse.parent; } /* Called when the dbusmenu item that we're keeping around @@ -93,6 +88,7 @@ dbusmenu_cache_freed (gpointer data, GObject * obj) /* If the dbusmenu item is killed we don't need to remove the weak ref as well. */ g_object_steal_data(G_OBJECT(data), CACHED_MENUITEM); + g_signal_handlers_disconnect_by_func(data, G_CALLBACK(widget_notify_cb), obj); return; } @@ -109,140 +105,106 @@ object_cache_freed (gpointer data) static void parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) { - if (GTK_IS_CONTAINER (widget)) - { - gboolean increment = GTK_IS_MENU_SHELL (widget) || GTK_IS_MENU_ITEM (widget); - - if (increment) - recurse->count++; - - /* Okay, this is a little janky and all.. but some applications update some - * menuitem properties such as sensitivity on the activate callback. This - * seems a little weird, but it's not our place to judge when all this code - * is so crazy. So we're going to get ever crazier and activate all the - * menus that are directly below the menubar and force the applications to - * update their sensitivity. The menus won't actually popup in the app - * window due to our gtk+ patches. - * - * Note that this will not force menuitems in submenus to be updated as well. - */ - if (recurse->count == 0 && GTK_IS_MENU_BAR (widget)) - { - GList *children = gtk_container_get_children (GTK_CONTAINER (widget)); - - for (; children != NULL; children = children->next) - { - gtk_menu_shell_activate_item (GTK_MENU_SHELL (widget), - children->data, - TRUE); - } - - g_list_free (children); - } - - if (recurse->count > -1 && increment) - { - gpointer pmi = g_object_get_data(G_OBJECT(widget), CACHED_MENUITEM); - DbusmenuMenuitem *dmi = NULL; - if (pmi != NULL) dmi = DBUSMENU_MENUITEM(pmi); - if (dmi != NULL) - { - if (increment) - recurse->count--; - - return; - } - else - { - recurse->stack[recurse->count] = construct_dbusmenu_for_widget (widget); - g_object_set_data_full(G_OBJECT(widget), CACHED_MENUITEM, recurse->stack[recurse->count], object_cache_freed); - g_object_weak_ref(G_OBJECT(recurse->stack[recurse->count]), dbusmenu_cache_freed, widget); + /* If this is a shell, then let's handle the items in it. */ + if (GTK_IS_MENU_SHELL (widget)) { + /* Okay, this is a little janky and all.. but some applications update some + * menuitem properties such as sensitivity on the activate callback. This + * seems a little weird, but it's not our place to judge when all this code + * is so crazy. So we're going to get ever crazier and activate all the + * menus that are directly below the menubar and force the applications to + * update their sensitivity. The menus won't actually popup in the app + * window due to our gtk+ patches. + * + * Note that this will not force menuitems in submenus to be updated as well. + */ + GList *children = gtk_container_get_children (GTK_CONTAINER (widget)); + + for (; children != NULL; children = children->next) { + gtk_menu_shell_activate_item (GTK_MENU_SHELL (widget), + children->data, + TRUE); + } + + g_list_free (children); + + if (recurse->parent == NULL) { + recurse->parent = dbusmenu_menuitem_new(); + } + + gtk_container_foreach (GTK_CONTAINER (widget), + (GtkCallback)parse_menu_structure_helper, + recurse); + return; + } + + if (GTK_IS_MENU_ITEM(widget)) { + DbusmenuMenuitem * thisitem = NULL; + + /* Check to see if we're cached already */ + gpointer pmi = g_object_get_data(G_OBJECT(widget), CACHED_MENUITEM); + if (pmi != NULL) { + thisitem = DBUSMENU_MENUITEM(pmi); + g_object_ref(G_OBJECT(thisitem)); + } + + /* We don't have one, so we'll need to build it */ + if (thisitem == NULL) { + thisitem = construct_dbusmenu_for_widget (widget); + g_object_set_data_full(G_OBJECT(widget), CACHED_MENUITEM, thisitem, object_cache_freed); + g_object_weak_ref(G_OBJECT(thisitem), dbusmenu_cache_freed, widget); + + if (!gtk_widget_get_visible (widget)) { + g_signal_connect (G_OBJECT (widget), + "notify::visible", + G_CALLBACK (menuitem_notify_cb), + recurse->toplevel); } - if (!gtk_widget_get_visible (widget)) - { - g_signal_connect (G_OBJECT (widget), - "notify::visible", - G_CALLBACK (menuitem_notify_cb), - recurse->toplevel); + if (GTK_IS_TEAROFF_MENU_ITEM (widget)) { + dbusmenu_menuitem_property_set_bool (thisitem, + DBUSMENU_MENUITEM_PROP_VISIBLE, + FALSE); } + } + + /* Check to see if we're in our parents list of children, if we have + a parent. */ + if (recurse->parent != NULL) { + GList * children = dbusmenu_menuitem_get_children (recurse->parent); + GList * peek = NULL; + + if (children != NULL) { + peek = g_list_find (children, thisitem); + } + + /* Oops, let's tell our parents about us */ + if (peek == NULL) { + /* TODO: Should we set a weak ref on the parent? */ + g_object_set_data (G_OBJECT (thisitem), + "dbusmenu-parent", + recurse->parent); + dbusmenu_menuitem_child_append (recurse->parent, + thisitem); + } + } + + GtkWidget *menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget)); + if (menu != NULL) { + DbusmenuMenuitem * parent_save = recurse->parent; + recurse->parent = thisitem; + parse_menu_structure_helper (menu, recurse); + recurse->parent = parent_save; + } + + if (recurse->parent == NULL) { + recurse->parent = thisitem; + } else { + g_object_unref(thisitem); + } + } - if (GTK_IS_TEAROFF_MENU_ITEM (widget)) - { - dbusmenu_menuitem_property_set_bool (recurse->stack[recurse->count], - DBUSMENU_MENUITEM_PROP_VISIBLE, - FALSE); - } - - if (recurse->count > 0) - { - GList *children = NULL; - GList *peek = NULL; - - if (recurse->stack[recurse->count - 1]) - { - children = dbusmenu_menuitem_get_children (recurse->stack[recurse->count - 1]); - - if (children) - { - peek = g_list_find (children, recurse->stack[recurse->count]); - } - - if (!peek) - { - /* Should we set a weak ref on the parent? */ - g_object_set_data (G_OBJECT (recurse->stack[recurse->count]), - "dbusmenu-parent", - recurse->stack[recurse->count - 1]); - dbusmenu_menuitem_child_append (recurse->stack[recurse->count - 1], - recurse->stack[recurse->count]); - } - } - else - { - DbusmenuMenuitem *item = NULL; /* g_hash_table_lookup (recurse->context->lookup, - gtk_widget_get_parent (widget)); */ - - if (item) - { - children = dbusmenu_menuitem_get_children (item); - - if (children) - { - peek = g_list_find (children, recurse->stack[recurse->count]); - } - - if (!peek) - { - g_object_set_data (G_OBJECT (recurse->stack[recurse->count]), - "dbusmenu-parent", - recurse->stack[recurse->count - 1]); - - dbusmenu_menuitem_child_append (item, recurse->stack[recurse->count]); - } - } - } - } - } - - gtk_container_foreach (GTK_CONTAINER (widget), - (GtkCallback)parse_menu_structure_helper, - recurse); - - if (GTK_IS_MENU_ITEM (widget)) - { - GtkWidget *menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget)); - - if (menu != NULL) - { - parse_menu_structure_helper (menu, recurse); - } - } - - if (increment) - recurse->count--; - } + return; } static DbusmenuMenuitem * -- cgit v1.2.3 From fe464dc002ed3e2e713f64145e689f66ad51f275 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 26 Jan 2011 16:13:56 -0600 Subject: Fix to the type of toggle-state to int --- libdbusmenu-gtk/parser.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 5f0ef48..b1e7e01 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -522,9 +522,9 @@ action_notify_cb (GtkAction *action, } else if (pspec->name == g_intern_static_string ("active")) { - dbusmenu_menuitem_property_set_bool (mi, - DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, - gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))); + dbusmenu_menuitem_property_set_int (mi, + DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, + gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) ? DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED : DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED); } else if (pspec->name == g_intern_static_string ("label")) { -- cgit v1.2.3 From e5078ed1027e8c466d081183eeee6888b10ef510 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Jan 2011 16:27:50 -0600 Subject: No really, read the comment and make sure that only happens on the highest level --- libdbusmenu-gtk/parser.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index b1e7e01..27ac926 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -118,15 +118,17 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) * * Note that this will not force menuitems in submenus to be updated as well. */ - GList *children = gtk_container_get_children (GTK_CONTAINER (widget)); + if (recurse->parent == NULL) { + GList *children = gtk_container_get_children (GTK_CONTAINER (widget)); - for (; children != NULL; children = children->next) { - gtk_menu_shell_activate_item (GTK_MENU_SHELL (widget), - children->data, - TRUE); - } + for (; children != NULL; children = children->next) { + gtk_menu_shell_activate_item (GTK_MENU_SHELL (widget), + children->data, + TRUE); + } - g_list_free (children); + g_list_free (children); + } if (recurse->parent == NULL) { recurse->parent = dbusmenu_menuitem_new(); -- cgit v1.2.3 From c6da3667cae61d1606eb66e6b7be01c2cbf9cbff Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Jan 2011 16:53:54 -0600 Subject: Only activating on menu bars. --- libdbusmenu-gtk/parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 27ac926..5dea9de 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -118,7 +118,7 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) * * Note that this will not force menuitems in submenus to be updated as well. */ - if (recurse->parent == NULL) { + if (recurse->parent == NULL && GTK_IS_MENU_BAR(widget)) { GList *children = gtk_container_get_children (GTK_CONTAINER (widget)); for (; children != NULL; children = children->next) { -- cgit v1.2.3 From 1555d242f4e0214dd39dbd56e5cc6ddcf426e19b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Jan 2011 22:42:30 -0600 Subject: Actually setting the 'checked' value --- libdbusmenu-gtk/client.c | 1 + 1 file changed, 1 insertion(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index ff2b3a7..00b2b90 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -751,6 +751,7 @@ set_use_fallback (GtkWidget * widget) if (!available) { g_warning("The '" USE_FALLBACK_PROP "' is not available on GtkImage so icons may not show correctly."); } + checked = TRUE; } if (available) { -- cgit v1.2.3 From 7e55758aa584a9e4080411cbd663d1fa30725a57 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 27 Jan 2011 08:48:37 -0600 Subject: Adding documentation of the public API. --- libdbusmenu-gtk/parser.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 5dea9de..8537a07 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -67,7 +67,17 @@ static void menuitem_notify_cb (GtkWidget * widget, GParamSpec * pspec, gpointer data); +/** + dbusmenu_gtk_parse_menu_structure: + @widget: A #GtkMenuItem or #GtkMenuShell to turn into a #DbusmenuMenuitem + Goes through the GTK structures and turns them into the appropraite + Dbusmenu structures along with setting up all the relationships + between the objects. It also stores the dbusmenu items as a cache + on the GTK items so that they'll be reused if necissary. + + Return value: A dbusmenu item representing the menu structure +*/ DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) { -- cgit v1.2.3 From 321935e1678923454a97bcb41f9ddc6714e4ac88 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 27 Jan 2011 08:50:24 -0600 Subject: Adding an early check on the type of widget coming into the function. --- libdbusmenu-gtk/parser.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 8537a07..ead653a 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -81,6 +81,8 @@ static void menuitem_notify_cb (GtkWidget * widget, DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) { + g_return_val_if_fail(GTK_IS_MENU_ITEM(widget) || GTK_IS_MENU_SHELL(widget), NULL); + RecurseContext recurse = {0}; recurse.toplevel = gtk_widget_get_toplevel(widget); -- cgit v1.2.3 From 49ecfc8c84d543491031aecbe64037e3fd76d366 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 27 Jan 2011 09:28:44 -0600 Subject: Shortening function names to be more reasonable. --- libdbusmenu-gtk/serializablemenuitem.c | 10 +++++----- libdbusmenu-gtk/serializablemenuitem.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index f67434e..cfd864d 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -166,7 +166,7 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) } /** - dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem: + dbusmenu_gtk_serializable_menu_item_build_menuitem: @smi: #DbusmenuGtkSerializableMenuItem to build a #DbusmenuMenuitem mirroring This function is for menu items that are instanciated from @@ -179,7 +179,7 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) set by this object. */ DbusmenuMenuitem * -dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi) +dbusmenu_gtk_serializable_menu_item_build_menuitem (DbusmenuGtkSerializableMenuItem * smi) { g_return_val_if_fail(DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(smi), NULL); @@ -207,7 +207,7 @@ type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuCli DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(g_object_new(th->type, NULL)); g_return_val_if_fail(smi != NULL, FALSE); - dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem(smi, newitem); + dbusmenu_gtk_serializable_menu_item_set_menuitem(smi, newitem); dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(smi), parent); return TRUE; @@ -265,7 +265,7 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, } /** - dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem: + dbusmenu_gtk_serializable_menu_item_set_menuitem: @smi: #DbusmenuGtkSerializableMenuItem to set the @DbusmenuGtkSerializableMenuItem::dbusmenu-menuitem of @mi: Menuitem to get the properties from @@ -276,7 +276,7 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, pick up this property being set. */ void -dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi) +dbusmenu_gtk_serializable_menu_item_set_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi) { g_return_if_fail(DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(smi)); g_return_if_fail(mi != NULL); diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index 1ca3ef8..1d12dd4 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -99,9 +99,9 @@ struct _DbusmenuGtkSerializableMenuItem { GType dbusmenu_gtk_serializable_menu_item_get_type (void); -DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi); +DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_build_menuitem (DbusmenuGtkSerializableMenuItem * smi); void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type); -void dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi); +void dbusmenu_gtk_serializable_menu_item_set_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi); G_END_DECLS -- cgit v1.2.3 From 717e9a319cd430428c297d0777b45c64e4d7f5fd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 27 Jan 2011 09:40:30 -0600 Subject: Adding some naritive text describing the purpose --- libdbusmenu-gtk/serializablemenuitem.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index 1d12dd4..db28a24 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -90,6 +90,13 @@ struct _DbusmenuGtkSerializableMenuItemClass { DbusmenuGtkSerializableMenuItem: @parent: Inherit from GtkMenuItem @priv: Blind structure of private variables + + The Serializable Menuitem provides a way for menu items to be created + that can easily be picked up by the Dbusmenu GTK Parser. This way + you can create custom items, and transport them across dbusmenu to + your menus or the appmenu on the other side of the bus. By providing + these function the parser has enough information to both serialize, and + deserialize on the other side, the menuitem you've so carefully created. */ struct _DbusmenuGtkSerializableMenuItem { GtkMenuItem parent; -- cgit v1.2.3 From 07666d7543bfce7fe925c15d3350519fd711a8f0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 27 Jan 2011 09:44:11 -0600 Subject: Fix changing prototypes. --- libdbusmenu-gtk/parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 6d95f10..cdbc001 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -250,7 +250,7 @@ construct_dbusmenu_for_widget (GtkWidget * widget) use its own build function */ if (DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(widget)) { DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(widget); - return dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem(smi); + return dbusmenu_gtk_serializable_menu_item_build_menuitem(smi); } /* If it's a standard GTK Menu Item we need to do some of our own work */ -- cgit v1.2.3