Menufactory patch




Here's a short patch to add support for radio menu items to the
menufactory code. The approach is dead simple: any consecutive items that
start with "<radio>" will belong to the same group.

I don't have CVS access (and don't have the time to make use of it) so if
this patch seems reasonable, somebody please feel to apply it.


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. 

Ideally, I'd like some way of switching the menufactory around so that I
can put together an entry like this:

 GtkMenuEntry e = 
    { "A/B", NULL/*Accel*/, NULL/*callback*/, NULL/*callbackdata*/,
       1/*userdata*/ }

And say:

   gtk_menu_factory_add_entries_with_callback_data(factory, &e, 1, this);

This would put 'this' into the callback data paramter for all the
callbacks and put '1' into the user_data slot of the menu item. 

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. 



--- gtkmenufactory.c.save	Fri Jan 16 22:43:15 1998
+++ gtkmenufactory.c	Fri Jan 16 23:07:38 1998
@@ -21,6 +21,7 @@
 #include "gtkmenubar.h"
 #include "gtkmenufactory.h"
 #include "gtkmenuitem.h"
+#include "gtkradiomenuitem.h"
 #include "gtksignal.h"
 
 
@@ -28,7 +29,8 @@
 {
   CREATE  = 1 << 0,
   DESTROY = 1 << 1,
-  CHECK   = 1 << 2
+  CHECK   = 1 << 2,
+  RADIO   = 1 << 3
 };
 
 
@@ -225,7 +227,9 @@
 	}
       else
 	{
-	  if (strncmp (path, "<check>", 7) == 0)
+	  if (strncmp (path, "<radio>", 7) == 0)
+	    menu_path = gtk_menu_factory_get (parent, path + 7, CREATE | RADIO);
+	  else if (strncmp (path, "<check>", 7) == 0)
 	    menu_path = gtk_menu_factory_get (parent, path + 7, CREATE | CHECK);
 	  else
 	    menu_path = gtk_menu_factory_get (parent, path, CREATE);
@@ -419,7 +423,16 @@
       menu_path = g_new (GtkMenuPath, 1);
       menu_path->path = g_strdup (path);
 
-      if (flags & CHECK)
+      if (flags & RADIO) {
+        GSList * group;
+        GList * children = g_list_last(gtk_container_children(GTK_CONTAINER(parent)));
+       	if (children && GTK_IS_RADIO_MENU_ITEM(children->data))
+       		group = gtk_radio_menu_item_group(GTK_RADIO_MENU_ITEM(children->data));
+       	else
+       		group = 0;
+	menu_path->widget = gtk_radio_menu_item_new_with_label (group, path);
+      }
+      else if (flags & CHECK)
 	menu_path->widget = gtk_check_menu_item_new_with_label (path);
       else
 	menu_path->widget = gtk_menu_item_new_with_label (path);


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




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