changeset 14834:52022b0a9405

[gaim-migrate @ 17601] Add another action "context-menu" for all widgets. This will allow to popup the context-menu for adding buddies. etc. in the buddylist with some custom binding for keyboards that don't have the menu-key (like the one at my work). committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 28 Oct 2006 15:22:30 +0000
parents 2b369cd04576
children 061157db8017
files console/gntblist.c console/libgnt/gntmarshal.c console/libgnt/gntmarshal.h console/libgnt/gntwidget.c
diffstat 4 files changed, 70 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/console/gntblist.c	Sat Oct 28 14:24:10 2006 +0000
+++ b/console/gntblist.c	Sat Oct 28 15:22:30 2006 +0000
@@ -1258,6 +1258,13 @@
 }
 
 static gboolean
+context_menu(GntWidget *widget, GGBlist *ggblist)
+{
+	draw_context_menu(ggblist);
+	return TRUE;
+}
+
+static gboolean
 key_pressed(GntWidget *widget, const char *text, GGBlist *ggblist)
 {
 	gboolean stop = FALSE, ret = FALSE;
@@ -1275,16 +1282,7 @@
 		stop = TRUE;
 	}
 
-	if (text[0] == 27)
-	{
-		if (strcmp(text + 1, GNT_KEY_POPUP) == 0)
-		{
-			draw_context_menu(ggblist);
-			stop = TRUE;
-			ret = TRUE;
-		}
-	}
-	else if (strcmp(text, GNT_KEY_CTRL_O) == 0)
+	if (strcmp(text, GNT_KEY_CTRL_O) == 0)
 	{
 		gaim_prefs_set_bool(PREF_ROOT "/showoffline",
 				!gaim_prefs_get_bool(PREF_ROOT "/showoffline"));
@@ -1933,6 +1931,7 @@
 
 	g_signal_connect(G_OBJECT(ggblist->tree), "selection_changed", G_CALLBACK(selection_changed), ggblist);
 	g_signal_connect(G_OBJECT(ggblist->tree), "key_pressed", G_CALLBACK(key_pressed), ggblist);
+	g_signal_connect(G_OBJECT(ggblist->tree), "context-menu", G_CALLBACK(context_menu), ggblist);
 	g_signal_connect_after(G_OBJECT(ggblist->tree), "clicked", G_CALLBACK(blist_clicked), ggblist);
 	g_signal_connect(G_OBJECT(ggblist->tree), "activate", G_CALLBACK(selection_activate), ggblist);
 	g_signal_connect_data(G_OBJECT(ggblist->tree), "gained-focus", G_CALLBACK(draw_tooltip),
--- a/console/libgnt/gntmarshal.c	Sat Oct 28 14:24:10 2006 +0000
+++ b/console/libgnt/gntmarshal.c	Sat Oct 28 15:22:30 2006 +0000
@@ -1,5 +1,37 @@
 #include "gntmarshal.h"
 
+void gnt_closure_marshal_BOOLEAN__VOID(GClosure *closure,
+										GValue *ret_value,
+										guint n_param_values,
+										const GValue *param_values,
+										gpointer invocation_hint,
+										gpointer marshal_data)
+{
+	typedef gboolean (*func) (gpointer data1, gpointer data2);
+	register func callback;
+	register GCClosure *cc = (GCClosure*)closure;
+	register gpointer data1, data2;
+	gboolean ret;
+
+	g_return_if_fail(ret_value != NULL);
+	g_return_if_fail(n_param_values == 1);
+
+	if (G_CCLOSURE_SWAP_DATA(closure))
+	{
+		data1 = closure->data;
+		data2 = g_value_peek_pointer(param_values + 0);
+	}
+	else
+	{
+		data1 = g_value_peek_pointer(param_values + 0);
+		data2 = closure->data;
+	}
+
+	callback = (func) (marshal_data ? marshal_data : cc->callback);
+	ret = callback(data1, data2);
+	g_value_set_boolean(ret_value, ret);
+}
+
 void gnt_closure_marshal_BOOLEAN__STRING(GClosure *closure,
 										GValue *ret_value,
 										guint n_param_values,
--- a/console/libgnt/gntmarshal.h	Sat Oct 28 14:24:10 2006 +0000
+++ b/console/libgnt/gntmarshal.h	Sat Oct 28 15:22:30 2006 +0000
@@ -1,5 +1,12 @@
 #include "gntwidget.h"
 
+void gnt_closure_marshal_BOOLEAN__VOID(GClosure *closure,
+										GValue *ret_value,
+										guint n_param_values,
+										const GValue *param_values,
+										gpointer invocation_hint,
+										gpointer marshal_data);
+
 void gnt_closure_marshal_BOOLEAN__STRING(GClosure *closure,
 										GValue *ret_value,
 										guint n_param_values,
--- a/console/libgnt/gntwidget.c	Sat Oct 28 14:24:10 2006 +0000
+++ b/console/libgnt/gntwidget.c	Sat Oct 28 15:22:30 2006 +0000
@@ -21,6 +21,7 @@
 	SIG_SIZE_CHANGED,
 	SIG_POSITION,
 	SIG_CLICKED,
+	SIG_CONTEXT_MENU,
 	SIGS
 };
 
@@ -83,6 +84,14 @@
 }
 
 static gboolean
+context_menu(GntWidget *widget, GList *null)
+{
+	gboolean ret = FALSE;
+	g_signal_emit(widget, signals[SIG_CONTEXT_MENU], 0, &ret);
+	return ret;
+}
+
+static gboolean
 gnt_boolean_handled_accumulator(GSignalInvocationHint *ihint,
 				  GValue                *return_accu,
 				  const GValue          *handler_return,
@@ -234,11 +243,24 @@
 					 gnt_closure_marshal_BOOLEAN__INT_INT_INT,
 					 G_TYPE_BOOLEAN, 3, G_TYPE_INT, G_TYPE_INT, G_TYPE_INT);
 
+	signals[SIG_CONTEXT_MENU] = 
+		g_signal_new("context-menu",
+					 G_TYPE_FROM_CLASS(klass),
+					 G_SIGNAL_RUN_LAST,
+					 0,
+					 gnt_boolean_handled_accumulator, NULL,
+					 gnt_closure_marshal_BOOLEAN__VOID,
+					 G_TYPE_BOOLEAN, 0);
+
 	klass->actions = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
 				(GDestroyNotify)gnt_widget_action_free);
 	klass->bindings = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
 				(GDestroyNotify)gnt_widget_action_param_free);
 
+	/* This is relevant for all widgets */
+	gnt_widget_class_register_action(klass, "context-menu", context_menu,
+				"\033" GNT_KEY_POPUP, NULL);
+
 	gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), klass);
 
 	GNTDEBUG;