changeset 21256:e8b0f224483f

Add gnt_menuitem_activate, and 'activate' signal for GntMenuItem.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 20 Oct 2007 05:52:52 +0000
parents 430fd445a053
children 512da37d0b4f
files ChangeLog.API finch/libgnt/gntmenu.c finch/libgnt/gntmenuitem.c finch/libgnt/gntmenuitem.h
diffstat 4 files changed, 51 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog.API	Sat Oct 20 05:50:48 2007 +0000
+++ b/ChangeLog.API	Sat Oct 20 05:52:52 2007 +0000
@@ -104,6 +104,8 @@
 		  bound to a keystroke.
 		* Added gnt_menu_get_item to activate and return a menuitem of the
 		  given id from a menu.
+		* Added gnt_menuitem_activate, which triggers the 'activate' signal on
+		  the menuitem and calls the callback function, if available.
 
 version 2.2.2 (??/??/????):
 	libpurple:
--- a/finch/libgnt/gntmenu.c	Sat Oct 20 05:50:48 2007 +0000
+++ b/finch/libgnt/gntmenu.c	Sat Oct 20 05:52:52 2007 +0000
@@ -181,7 +181,15 @@
 static void
 menuitem_activate(GntMenu *menu, GntMenuItem *item)
 {
-	if (item) {
+	if (!item)
+		return;
+
+	if (gnt_menuitem_activate(item)) {
+		while (menu) {
+			gnt_widget_hide(GNT_WIDGET(menu));
+			menu = menu->parentmenu;
+		}
+	} else {
 		if (item->submenu) {
 			GntMenu *sub = GNT_MENU(item->submenu);
 			menu->submenu = sub;
@@ -195,12 +203,6 @@
 			gnt_widget_set_position(GNT_WIDGET(sub), item->priv.x, item->priv.y);
 			GNT_WIDGET_UNSET_FLAGS(GNT_WIDGET(sub), GNT_WIDGET_INVISIBLE);
 			gnt_widget_draw(GNT_WIDGET(sub));
-		} else if (item->callback) {
-			item->callback(item, item->callbackdata);
-			while (menu) {
-				gnt_widget_hide(GNT_WIDGET(menu));
-				menu = menu->parentmenu;
-			}
 		}
 	}
 }
@@ -326,8 +328,7 @@
 	GntMenu *menu = GNT_MENU(tree);
 	gboolean check = gnt_menuitem_check_get_checked(GNT_MENU_ITEM_CHECK(item));
 	gnt_menuitem_check_set_checked(GNT_MENU_ITEM_CHECK(item), !check);
-	if (item->callback)
-		item->callback(item, item->callbackdata);
+	gnt_menuitem_activate(item);
 	while (menu) {
 		gnt_widget_hide(GNT_WIDGET(menu));
 		menu = menu->parentmenu;
--- a/finch/libgnt/gntmenuitem.c	Sat Oct 20 05:50:48 2007 +0000
+++ b/finch/libgnt/gntmenuitem.c	Sat Oct 20 05:52:52 2007 +0000
@@ -23,6 +23,13 @@
 #include "gntmenu.h"
 #include "gntmenuitem.h"
 
+enum
+{
+	SIG_ACTIVATE,
+	SIGS
+};
+static guint signals[SIGS] = { 0 };
+
 static GObjectClass *parent_class = NULL;
 
 static void
@@ -44,10 +51,18 @@
 	parent_class = g_type_class_peek_parent(klass);
 
 	obj_class->dispose = gnt_menuitem_destroy;
+
+	signals[SIG_ACTIVATE] =
+		g_signal_new("activate",
+					 G_TYPE_FROM_CLASS(klass),
+					 G_SIGNAL_RUN_LAST,
+					 0, NULL, NULL,
+					 g_cclosure_marshal_VOID__VOID,
+					 G_TYPE_NONE, 0);
 }
 
 static void
-gnt_menuitem_init(GTypeInstance *instance, gpointer class)
+gnt_menuitem_init(GTypeInstance *instance, gpointer klass)
 {
 }
 
@@ -131,3 +146,13 @@
 	return item->priv.id;
 }
 
+gboolean gnt_menuitem_activate(GntMenuItem *item)
+{
+	g_signal_emit(item, signals[SIG_ACTIVATE], 0);
+	if (item->callback) {
+		item->callback(item, item->callbackdata);
+		return TRUE;
+	}
+	return FALSE;
+}
+
--- a/finch/libgnt/gntmenuitem.h	Sat Oct 20 05:50:48 2007 +0000
+++ b/finch/libgnt/gntmenuitem.h	Sat Oct 20 05:52:52 2007 +0000
@@ -168,6 +168,19 @@
  */
 const char * gnt_menuitem_get_id(GntMenuItem *item);
 
+/**
+ * Activate a menuitem.
+ * Activating the menuitem will first trigger the 'activate' signal for the
+ * menuitem. Then the callback for the menuitem is triggered, if there is one.
+ *
+ * @param item   The menuitem.
+ *
+ * @return  Whether the callback for the menuitem was called.
+ *
+ * @since 2.3.0
+ */
+gboolean gnt_menuitem_activate(GntMenuItem *item);
+
 G_END_DECLS
 
 #endif /* GNT_MENUITEM_H */