Re: another patch for gtkoptionmenu



Ok, here's a corrected version of the patch, actually it merges the two
previous patches into one.  It should address all of your concerns.

George
Index: gtkoptionmenu.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkoptionmenu.c,v
retrieving revision 1.27
diff -u -r1.27 gtkoptionmenu.c
--- gtkoptionmenu.c	1999/12/03 20:15:32	1.27
+++ gtkoptionmenu.c	2000/01/26 04:28:18
@@ -39,6 +39,11 @@
 #define OPTION_INDICATOR_HEIGHT   8
 #define OPTION_INDICATOR_SPACING  2
 
+/* Signals */
+enum {
+  HISTORY_CHANGED,
+  LAST_SIGNAL
+};
 
 static void gtk_option_menu_class_init      (GtkOptionMenuClass *klass);
 static void gtk_option_menu_init            (GtkOptionMenu      *option_menu);
@@ -73,6 +78,7 @@
 				       
 
 static GtkButtonClass *parent_class = NULL;
+static guint option_menu_signals[LAST_SIGNAL] = {0};
 
 
 GtkType
@@ -117,6 +123,15 @@
 
   object_class->destroy = gtk_option_menu_destroy;
 
+  option_menu_signals[HISTORY_CHANGED] =
+    gtk_signal_new ("history_changed",
+		    GTK_RUN_LAST,
+		    object_class->type,
+		    GTK_SIGNAL_OFFSET (GtkOptionMenuClass, history_changed),
+		    gtk_marshal_NONE__NONE,
+		    GTK_TYPE_NONE, 0);
+  gtk_object_class_add_signals (object_class, option_menu_signals, LAST_SIGNAL);
+
   widget_class->draw = gtk_option_menu_draw;
   widget_class->size_request = gtk_option_menu_size_request;
   widget_class->size_allocate = gtk_option_menu_size_allocate;
@@ -126,6 +141,8 @@
   widget_class->show_all = gtk_option_menu_show_all;
   widget_class->hide_all = gtk_option_menu_hide_all;
 
+  class->history_changed = NULL;
+
   container_class->child_type = gtk_option_menu_child_type;
 }
 
@@ -247,15 +264,13 @@
 gint
 gtk_option_menu_get_history (GtkOptionMenu *option_menu)
 {
-  GtkWidget *active_widget;
-  
+  g_return_val_if_fail (option_menu != NULL, -1);
   g_return_val_if_fail (GTK_IS_OPTION_MENU (option_menu), -1);
-  
-  active_widget = gtk_menu_get_active (GTK_MENU (option_menu->menu));
 
-  if (active_widget)
+  if (option_menu->menu != NULL &&
+      option_menu->menu_item != NULL)
     return g_list_index (GTK_MENU_SHELL (option_menu->menu)->children,
-			 active_widget);
+			 option_menu->menu_item);
   else
     return -1;
 }
@@ -540,6 +555,7 @@
 gtk_option_menu_update_contents (GtkOptionMenu *option_menu)
 {
   GtkWidget *child;
+  GtkWidget *active_item;
   GtkRequisition child_requisition;
 
   g_return_if_fail (option_menu != NULL);
@@ -548,8 +564,19 @@
   if (option_menu->menu)
     {
       gtk_option_menu_remove_contents (option_menu);
+
+      active_item = gtk_menu_get_active (GTK_MENU (option_menu->menu));
+
+      /* if a new item was selected emit 'history_changed' */
+      if (option_menu->menu_item != active_item)
+        {
+          option_menu->menu_item = active_item;
+          gtk_signal_emit (GTK_OBJECT (option_menu),
+			   option_menu_signals[HISTORY_CHANGED]);
+	}
+      else
+        option_menu->menu_item = active_item;
 
-      option_menu->menu_item = gtk_menu_get_active (GTK_MENU (option_menu->menu));
       if (option_menu->menu_item)
 	{
 	  gtk_widget_ref (option_menu->menu_item);
Index: gtkoptionmenu.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkoptionmenu.h,v
retrieving revision 1.7
diff -u -r1.7 gtkoptionmenu.h
--- gtkoptionmenu.h	1999/12/03 20:15:32	1.7
+++ gtkoptionmenu.h	2000/01/26 04:28:19
@@ -60,7 +60,9 @@
 
 struct _GtkOptionMenuClass
 {
-  GtkButtonClass parent_class;
+  GtkButtonClass        parent_class;
+
+  void (* history_changed) (GtkOptionMenu *option_menu);
 };
 
 


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