Bonobo patch for radio menu item bug fix



Here's a patch that fixes the bug where removing a radio menu item leaves a
dangling pointer. Also some changes to fix warnings.

Index: bonobo/bonobo-uih-menu.c
===================================================================
RCS file: /cvs/gnome/bonobo/bonobo/bonobo-uih-menu.c,v
retrieving revision 1.6
diff -u -p -r1.6 bonobo-uih-menu.c
--- bonobo/bonobo-uih-menu.c    2000/04/29 22:04:09    1.6
+++ bonobo/bonobo-uih-menu.c    2000/05/01 16:51:43
@@ -1424,6 +1424,38 @@ impl_Bonobo_UIHandler_menu_overridden (P
 }
 
 static void
+menu_toplevel_remove_radio_menu_item (BonoboUIHandler *uih,
+                      const char      *path,
+                      GtkWidget       *widget)
+{
+  char *parent_path;
+  MenuItemInternal *radio_group;
+  
+  /*
+   * Handle the unusual case where we are destroying the first
+   * widget of a radio group. If we don't update the parent's
+   * radio_items pointer here, it will end up pointing to the
+   * destroyed widget.
+   */
+  parent_path = bonobo_ui_handler_path_get_parent (path);
+  if (parent_path != NULL)
+    {
+      radio_group = menu_toplevel_get_item (uih, parent_path);
+      if (radio_group != NULL
+      && radio_group->radio_items != NULL
+      && radio_group->radio_items->data == widget)
+    {
+      /* The widget's destroy function will remove itself from
+       * this list, but we won't be notified about the change.
+       * So we just move down to the next item.
+       */
+      radio_group->radio_items = radio_group->radio_items->next;
+    }
+      g_free (parent_path);
+    }
+}
+
+static void
 menu_toplevel_remove_widgets (BonoboUIHandler *uih, const char *path)
 {
     GtkWidget *menu_widget;
@@ -1436,6 +1468,14 @@ menu_toplevel_remove_widgets (BonoboUIHa
     menu_widget = menu_toplevel_get_widget (uih, path);
     g_return_if_fail (menu_widget != NULL);
 
+    /*
+     * We could do the "remove from radio items list" work all the
+     * time, but it's only really needed for GtkRadioMenuItem
+     * widgets.
+     */
+    if (GTK_IS_RADIO_MENU_ITEM (menu_widget))
+      menu_toplevel_remove_radio_menu_item (uih, path, menu_widget);
+
     gtk_widget_destroy (menu_widget);
 
     /* Free the path string that was stored in the hash table. */
@@ -1869,13 +1909,6 @@ menu_toplevel_remove_data (BonoboUIHandl
         g_free ((char *) curr->data);
     g_list_free (internal->children);
 
-    /*
-     * FIXME
-     *
-     * This g_slist_free() (or maybe the other one in this file)
-     * seems to corrupt the SList allocator's free list
-     */
-/*    g_slist_free (internal->radio_items); */
     g_free (internal);
     g_free (path);
 }
Index: bonobo/bonobo-uih-private.h
===================================================================
RCS file: /cvs/gnome/bonobo/bonobo/bonobo-uih-private.h,v
retrieving revision 1.2
diff -u -p -r1.2 bonobo-uih-private.h
--- bonobo/bonobo-uih-private.h    2000/02/28 20:46:51    1.2
+++ bonobo/bonobo-uih-private.h    2000/05/01 16:51:43
@@ -116,7 +116,7 @@ typedef struct _MenuItemInternal {
 
     /*
      * If this item is a radio group, then this list points to the
-     * MenuItemInternal structures for the members of the group.
+     * GtkRadioMenuItem widgets for the members of the group.
      */
     GSList *radio_items;
 
@@ -176,12 +176,6 @@ struct _ToolbarItemInternal {
      * this particular menu item.
      */
     Bonobo_UIHandler uih_corba;
-
-    /*
-     * If this item is a radio group, then this list points to the
-     * ToolbarItemInternal structures for the members of the group.
-     */
-    GSList *radio_items;
 
     /*
      * In the world of toolbars, only radio groups can have
Index: bonobo/bonobo-uih-toolbar.c
===================================================================
RCS file: /cvs/gnome/bonobo/bonobo/bonobo-uih-toolbar.c,v
retrieving revision 1.11
diff -u -p -r1.11 bonobo-uih-toolbar.c
--- bonobo/bonobo-uih-toolbar.c    2000/04/29 22:04:10    1.11
+++ bonobo/bonobo-uih-toolbar.c    2000/05/01 16:51:53
@@ -1205,7 +1205,6 @@ toolbar_toplevel_item_create_widgets (Bo
         return;
         
     default:
-
         g_warning ("toolbar_toplevel_item_create_widgets: Unkonwn toolbar
item type [%d]!",
                (gint) internal->item->type);
         return;
@@ -1884,13 +1883,6 @@ toolbar_toplevel_item_remove_data (Bonob
 
     toolbar_free (internal->item);
 
-    /*
-     * FIXME
-     *
-     * This g_slist_free() (or maybe the other one in this file)
-     * seems to corrupt the SList allocator's free list
-     */
-/*    g_slist_free (internal->radio_items); */
     g_free (internal);
     g_free (path);
 }
Index: gshell/gshell.c
===================================================================
RCS file: /cvs/gnome/bonobo/gshell/gshell.c,v
retrieving revision 1.23
diff -u -p -r1.23 gshell.c
--- gshell/gshell.c    2000/04/29 22:04:10    1.23
+++ gshell/gshell.c    2000/05/01 16:51:53
@@ -56,7 +56,6 @@ void
 edit_menu_preferences_cb (BonoboUIHandler *uih, void *data, char *path)
 {
     Frame *frame;
-    GList *v;
 
     if (!(frame = get_active_frame (GTK_WIDGET (bonobo_ui_handler_get_app
(uih))))) return;
 
Index: tools/bonobrowser/register-new-object.c
===================================================================
RCS file: /cvs/gnome/bonobo/tools/bonobrowser/register-new-object.c,v
retrieving revision 1.3
diff -u -p -r1.3 register-new-object.c
--- tools/bonobrowser/register-new-object.c    2000/04/29 22:04:11    1.3
+++ tools/bonobrowser/register-new-object.c    2000/05/01 16:51:58
@@ -179,7 +179,7 @@ register_object (gchar *server_id, gchar
             fprintf (f, "[%s]\ntype=%s\nrepo_id=",
                  server_id, creation_type);
 
-            for (;*interfaces; *interfaces++) {
+            for (;*interfaces; interfaces++) {
                 fprintf (f, "%s ", *interfaces);
             }
 
@@ -382,12 +382,14 @@ delete_clist_item (GtkWidget *widget,
     gint row;
 
     if (event->keyval != GDK_Delete)
-        return;
+        return FALSE;
     
     if (clist->selection) {
         row = (gint)g_list_nth (clist->selection, 0)->data;
         gtk_clist_remove (clist, row);
     }
+
+    return FALSE;
 } /* delete_clist_item */
 
 
Index: tools/bonobrowser/utils.c
===================================================================
RCS file: /cvs/gnome/bonobo/tools/bonobrowser/utils.c,v
retrieving revision 1.3
diff -u -p -r1.3 utils.c
--- tools/bonobrowser/utils.c    2000/04/29 22:04:11    1.3
+++ tools/bonobrowser/utils.c    2000/05/01 16:51:58
@@ -21,6 +21,8 @@
 
 #include <config.h>
 #include <gnome.h>
+#include "utils.h"
+#include <ctype.h>
 
 /**
  * message_box:
@@ -152,7 +154,8 @@ remove_leading_and_trailing_whitespace (
  *
  * Returns true if any character in a string is a whitespace.
  */
-gboolean contains_whitespace (gchar *str)
+gboolean
+contains_whitespace (gchar *str)
 {
     int i;
     g_assert (str);
===================================================================

    -- Darin





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