[POSSIBLE PATCH] Menu factory patch #2




This patch adds a new function to the menu factory,
_set_callback_data(GtkMenuFactory *factory, gpointer data), which I
actually find more difficult to explain than use.

The idea is to allow me to easily set the user_data of each menu, as well
as the data of the "activate" signal. The purpose is for using MenuFactory
from C++, where I need two data values for each menu signal (one is the
usual data value, the other is the object that the menu pertains to.)

I'm rather of the opinion that this patch should _not_ be applied, and
some better (or at least more easily explained) approach found. 

--- gtkmenufactory.h.save	Fri Jan 16 23:27:07 1998
+++ gtkmenufactory.h	Fri Jan 16 23:28:20 1998
@@ -56,11 +56,14 @@
   GtkAcceleratorTable *table;
   GtkWidget *widget;
   GList *subfactories;
+  gpointer callback_data;
 };
 
 
 GtkMenuFactory* gtk_menu_factory_new               (GtkMenuFactoryType  type);
 void            gtk_menu_factory_destroy           (GtkMenuFactory     *factory);
+void            gtk_menu_factory_set_callback_data (GtkMenuFactory     *factory,
+						    gpointer            data);
 void            gtk_menu_factory_add_entries       (GtkMenuFactory     *factory,
 						    GtkMenuEntry       *entries,
 						    int                 nentries);
--- gtkmenufactory.c.save2	Fri Jan 16 23:27:20 1998
+++ gtkmenufactory.c	Fri Jan 16 23:36:23 1998
@@ -64,6 +64,7 @@
   factory->table = NULL;
   factory->widget = NULL;
   factory->subfactories = NULL;
+  factory->callback_data = NULL;
 
   return factory;
 }
@@ -253,10 +254,15 @@
 					      accelerator_mods);
 	    }
 
+
 	  if (entry->callback)
-	    gtk_signal_connect (GTK_OBJECT (menu_path->widget), "activate",
-				(GtkSignalFunc) entry->callback,
-				entry->callback_data);
+	    {
+	      gtk_signal_connect (GTK_OBJECT (menu_path->widget), "activate",
+				  (GtkSignalFunc) entry->callback,
+				  factory->callback_data ? factory->callback_data : entry->callback_data);
+	      if (factory->callback_data)
+	        gtk_object_set_user_data( GTK_OBJECT(menu_path->widget), entry->callback_data);
+	    }				
 	}
     }
   else
@@ -356,6 +362,15 @@
 	}
     }
 }
+
+void
+gtk_menu_factory_set_callback_data (GtkMenuFactory *factory,  
+                                    gpointer        data)
+{
+  g_return_if_fail (factory != NULL);
+  factory->callback_data = data;
+}
+
 
 static GtkWidget*
 gtk_menu_factory_make_widget (GtkMenuFactory *factory)


-- 
Kenneth Albanowski (kjahds@kjahds.com, CIS: 70705,126)





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]