Re: [gtk-list] Menufactory patch



On Fri, 16 Jan 1998, Kenneth Albanowski wrote:

> On another note, I'm not quite happy with the menufactory approach of
> having the callback data value in the MenuEntry list. I'm working with C++
> code that places the object itself (the this value) in the callback data
> slot, and uses object_data slots for any additional data. Menufactory
> doesn't support this very well, unless I want to go back, afterward, and
> patch up all of the handlers. 
[...]
> I don't see any clean way of making this change that doesn't involve
> binary incompatability (due to changing GtkMenuEntry) or lots of
> duplicated code. 

As usually seems to be the case, the moment I post this, I figure out a
simple method.

This patch, on top of my previous one, adds a new function:

  gtk_menu_factory_set_callback_data(factory, gpointer data);

If this function is called, and data is nonzero, then that value will be
placed into the callback_data slot of all the signals, and the
callback_data slot from the entry will be, in turn, placed in the
user_data of the menu item widget.

This is very _useful_ for me, but I'm not sure how comprehensible it is,
or whether it'll be useful to other folks. (Perhaps a better explanation
would help.)

--- 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]