From 48d1f0b6902b4833460c6562603d6a8c9555aad5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 3 Feb 2010 17:31:17 -0800 Subject: Creating a handle event function and a wrapper for it. --- libdbusmenu-glib/menuitem.c | 23 +++++++++++++++++++---- libdbusmenu-glib/menuitem.h | 7 +++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 06d6200..bc2e748 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -1116,21 +1116,36 @@ dbusmenu_menuitem_foreach (DbusmenuMenuitem * mi, void (*func) (DbusmenuMenuitem } /** - dbusmenu_menuitem_activate: + dbusmenu_menuitem_handle_event: @mi: The #DbusmenuMenuitem to send the signal on. + @name: The name of the signal + @value: A value that could be set for the event @timestamp: The timestamp of when the event happened + This function is called to create an event. It is likely + to be overrided by subclasses. The default menu item + will respond to the activate signal and do: + Emits the #DbusmenuMenuitem::item-activate signal on this menu item. Called by server objects when they get the appropriate DBus signals from the client. + + If you subclass this function you should really think + about calling the parent function unless you have a good + reason not to. */ void -dbusmenu_menuitem_activate (DbusmenuMenuitem * mi, guint timestamp) +dbusmenu_menuitem_handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, guint timestamp) { g_return_if_fail(DBUSMENU_IS_MENUITEM(mi)); #ifdef MASSIVEDEBUGGING - g_debug("Menuitem %d (%s) activated", ID(mi), LABEL(mi)); + g_debug("Menuitem %d (%s) is getting event '%s'", ID(mi), LABEL(mi), name); #endif - g_signal_emit(G_OBJECT(mi), signals[ITEM_ACTIVATED], 0, timestamp, TRUE); + DbusmenuMenuitemClass * class = DBUSMENU_MENUITEM_GET_CLASS(mi); + + if (class->handle_event != NULL) { + return class->handle_event(mi, name, value, timestamp); + } + //g_signal_emit(G_OBJECT(mi), signals[ITEM_ACTIVATED], 0, timestamp, TRUE); return; } diff --git a/libdbusmenu-glib/menuitem.h b/libdbusmenu-glib/menuitem.h index af6f54d..b7ebc4d 100644 --- a/libdbusmenu-glib/menuitem.h +++ b/libdbusmenu-glib/menuitem.h @@ -92,6 +92,9 @@ struct _DbusmenuMenuitem @realized: Slot for #DbusmenuMenuitem::realized. @buildxml: Virtual function that appends the strings required to represent this menu item in the menu XML file. + @handle_event: This function is to override how events are handled + by subclasses. Look at #dbusmenu_menuitem_handle_event for + lots of good information. @reserved1: Reserved for future use. @reserved2: Reserved for future use. @reserved3: Reserved for future use. @@ -112,7 +115,7 @@ struct _DbusmenuMenuitemClass /* Virtual functions */ void (*buildxml) (GPtrArray * stringarray); - void (*handle_event) (gchar * name, GValue * value, guint timestamp); + void (*handle_event) (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, guint timestamp); void (*reserved1) (void); void (*reserved2) (void); @@ -154,7 +157,7 @@ void dbusmenu_menuitem_set_root (DbusmenuMenuitem * mi, gboolean root); gboolean dbusmenu_menuitem_get_root (DbusmenuMenuitem * mi); void dbusmenu_menuitem_foreach (DbusmenuMenuitem * mi, void (*func) (DbusmenuMenuitem * mi, gpointer data), gpointer data); -void dbusmenu_menuitem_handle_event (DbusmenuMenuitem * mi, gchar * name, GValue * value, guint timestamp); +void dbusmenu_menuitem_handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, guint timestamp); /** SECTION:menuitem -- cgit v1.2.3