#59885: patch



Hi all,

Appended patch fixes bug #59885 (gtk-criticals in testgtk, (severity:
major)). ChangeLog is seperate from the diff at the moment:

2001-09-19  Kristian Rietveld  <kristian planet nl>

	* tests/testgtk.c (struct OptionMenuItem): get rid of func,

	(build_option_menu): add func argument, connect ::changed
	signal to option menu instead of connecting the ::activate
	signal to the menu items,

	(toplevel): get rid of RADIOMENUTOGGLED macro,

	(list_toggle_sel_mode), (clist_toggle_sel_mode),
	(ctree_toggle_line_style), (ctree_toggle_expander_style),
	(ctree_toggle_justify), (ctree_toggle_sel_mode),
	(progressbar_toggle_orientation), (progressbar_toggle_bar_style):
	use gtk_option_menu_get_history() instead of RADIOMENUTOGGLED,

	(notebook_type_changed): merged standard_notebook(),
	notabs_notebook(), scrollable_notebook() and borderless_notebook()
	into notebook_type_changed()

	(create_list), (create_ctree), (create_notebook),
	(create_progress_bar): changes to the OptionMenuItem arrays
	to reflect change in OptionMenuItem structure.

	All these changes fixes bug #59885


Ok to commit?

regards,


	Kris



Index: testgtk.c
===================================================================
RCS file: /cvs/gnome/gtk+/tests/testgtk.c,v
retrieving revision 1.275
diff -u -r1.275 testgtk.c
--- testgtk.c	2001/09/10 18:54:20	1.275
+++ testgtk.c	2001/09/19 18:04:27
@@ -55,7 +55,6 @@
 typedef struct _OptionMenuItem
 {
   gchar        *name;
-  GtkSignalFunc func;
 } OptionMenuItem;

 gboolean
@@ -78,6 +77,7 @@
 build_option_menu (OptionMenuItem items[],
 		   gint           num_items,
 		   gint           history,
+		   GtkSignalFunc  func,
 		   gpointer       data);

 /* macro, structure and variables used by tree window demos */
@@ -108,6 +108,7 @@
 build_option_menu (OptionMenuItem items[],
 		   gint           num_items,
 		   gint           history,
+		   GtkSignalFunc  func,
 		   gpointer       data)
 {
   GtkWidget *omenu;
@@ -117,6 +118,8 @@
   gint i;

   omenu = gtk_option_menu_new ();
+  gtk_signal_connect (GTK_OBJECT (omenu), "changed",
+		      (GtkSignalFunc) func, data);

   menu = gtk_menu_new ();
   group = NULL;
@@ -124,8 +127,6 @@
   for (i = 0; i < num_items; i++)
     {
       menu_item = gtk_radio_menu_item_new_with_label (group, items[i].name);
-      gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
-			  (GtkSignalFunc) items[i].func, data);
       group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menu_item));
       gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
       if (i == history)
@@ -4456,16 +4457,6 @@
   gtk_list_clear_items (GTK_LIST (list), 0, -1);
 }

-#define RADIOMENUTOGGLED(_rmi_, __i) { \
-  GSList * __g; \
-  __i = 0; \
-  __g = gtk_radio_menu_item_group(_rmi_); \
-  while( __g  && !((GtkCheckMenuItem *)(__g->data))->active) { \
-    __g = __g->next; \
-    __i++; \
-  }\
-}
-
 static GtkWidget *list_omenu;

 static void
@@ -4476,10 +4467,9 @@
   if (!GTK_WIDGET_MAPPED (widget))
     return;

-  RADIOMENUTOGGLED ((GtkRadioMenuItem *)
-		    (((GtkOptionMenu *)list_omenu)->menu_item), i);
+  i = gtk_option_menu_get_history (GTK_OPTION_MENU (widget));

-  gtk_list_set_selection_mode (list, (GtkSelectionMode) (3-i));
+  gtk_list_set_selection_mode (list, (GtkSelectionMode) (i));
 }

 static void
@@ -4489,10 +4479,10 @@

   static OptionMenuItem items[] =
   {
-    { "Single",   GTK_SIGNAL_FUNC (list_toggle_sel_mode) },
-    { "Browse",   GTK_SIGNAL_FUNC (list_toggle_sel_mode) },
-    { "Multiple", GTK_SIGNAL_FUNC (list_toggle_sel_mode) },
-    { "Extended", GTK_SIGNAL_FUNC (list_toggle_sel_mode) }
+    { "Single"    },
+    { "Browse"    },
+    { "Multiple"  },
+    { "Extended"  }
   };

   if (!window)
@@ -4590,7 +4580,9 @@
       label = gtk_label_new ("Selection Mode :");
       gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);

-      list_omenu = build_option_menu (items, 4, 3, list);
+      list_omenu = build_option_menu (items, 4, 3,
+				      (GtkSignalFunc)list_toggle_sel_mode,
+				      list);
       gtk_box_pack_start (GTK_BOX (hbox), list_omenu, FALSE, TRUE, 0);

       separator = gtk_hseparator_new ();
@@ -4940,10 +4932,9 @@
   if (!GTK_WIDGET_MAPPED (widget))
     return;

-  RADIOMENUTOGGLED ((GtkRadioMenuItem *)
-		    (((GtkOptionMenu *)clist_omenu)->menu_item), i);
+  i = gtk_option_menu_get_history (GTK_OPTION_MENU (widget));

-  gtk_clist_set_selection_mode (clist, (GtkSelectionMode) (3-i));
+  gtk_clist_set_selection_mode (clist, (GtkSelectionMode) (i));
 }

 static void
@@ -4979,10 +4970,10 @@

   static OptionMenuItem items[] =
   {
-    { "Single",   GTK_SIGNAL_FUNC (clist_toggle_sel_mode) },
-    { "Browse",   GTK_SIGNAL_FUNC (clist_toggle_sel_mode) },
-    { "Multiple", GTK_SIGNAL_FUNC (clist_toggle_sel_mode) },
-    { "Extended", GTK_SIGNAL_FUNC (clist_toggle_sel_mode) }
+    { "Single"    },
+    { "Browse"    },
+    { "Multiple"  },
+    { "Extended"  }
   };

   char text[TESTGTK_CLIST_COLUMNS][50];
@@ -5096,7 +5087,9 @@
       label = gtk_label_new ("Selection Mode :");
       gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);

-      clist_omenu = build_option_menu (items, 4, 3, clist);
+      clist_omenu = build_option_menu (items, 4, 3,
+				       (GtkSignalFunc)clist_toggle_sel_mode,
+				       clist);
       gtk_box_pack_start (GTK_BOX (hbox), clist_omenu, FALSE, TRUE, 0);

       /*
@@ -5550,16 +5543,15 @@
   if (!GTK_WIDGET_MAPPED (widget))
     return;

-  RADIOMENUTOGGLED ((GtkRadioMenuItem *)
-		    (((GtkOptionMenu *)omenu1)->menu_item), i);
-
+  i = gtk_option_menu_get_history (GTK_OPTION_MENU (widget));
+
   if ((ctree->line_style == GTK_CTREE_LINES_TABBED &&
-       ((GtkCTreeLineStyle) (3 - i)) != GTK_CTREE_LINES_TABBED) ||
+       ((GtkCTreeLineStyle) (i)) != GTK_CTREE_LINES_TABBED) ||
       (ctree->line_style != GTK_CTREE_LINES_TABBED &&
-       ((GtkCTreeLineStyle) (3 - i)) == GTK_CTREE_LINES_TABBED))
+       ((GtkCTreeLineStyle) (i)) == GTK_CTREE_LINES_TABBED))
     gtk_ctree_pre_recursive (ctree, NULL, set_background, NULL);
-  gtk_ctree_set_line_style (ctree, 3 - i);
-  line_style = 3 - i;
+  gtk_ctree_set_line_style (ctree, i);
+  line_style = i;
 }

 void ctree_toggle_expander_style (GtkWidget *widget, GtkCTree *ctree)
@@ -5568,11 +5560,10 @@

   if (!GTK_WIDGET_MAPPED (widget))
     return;
-
-  RADIOMENUTOGGLED ((GtkRadioMenuItem *)
-		    (((GtkOptionMenu *)omenu2)->menu_item), i);

-  gtk_ctree_set_expander_style (ctree, (GtkCTreeExpanderStyle) (3 - i));
+  i = gtk_option_menu_get_history (GTK_OPTION_MENU (widget));
+
+  gtk_ctree_set_expander_style (ctree, (GtkCTreeExpanderStyle) (i));
 }

 void ctree_toggle_justify (GtkWidget *widget, GtkCTree *ctree)
@@ -5582,11 +5573,10 @@
   if (!GTK_WIDGET_MAPPED (widget))
     return;

-  RADIOMENUTOGGLED ((GtkRadioMenuItem *)
-		    (((GtkOptionMenu *)omenu3)->menu_item), i);
+  i = gtk_option_menu_get_history (GTK_OPTION_MENU (widget));

   gtk_clist_set_column_justification (GTK_CLIST (ctree), ctree->tree_column,
-				      (GtkJustification) (1 - i));
+				      (GtkJustification) (i));
 }

 void ctree_toggle_sel_mode (GtkWidget *widget, GtkCTree *ctree)
@@ -5596,10 +5586,9 @@
   if (!GTK_WIDGET_MAPPED (widget))
     return;

-  RADIOMENUTOGGLED ((GtkRadioMenuItem *)
-		    (((GtkOptionMenu *)omenu4)->menu_item), i);
+  i = gtk_option_menu_get_history (GTK_OPTION_MENU (widget));

-  gtk_clist_set_selection_mode (GTK_CLIST (ctree), (GtkSelectionMode) (3 - i));
+  gtk_clist_set_selection_mode (GTK_CLIST (ctree), (GtkSelectionMode) (i));
   after_press (ctree, NULL);
 }

@@ -5766,32 +5755,32 @@

   static OptionMenuItem items1[] =
   {
-    { "No lines", GTK_SIGNAL_FUNC (ctree_toggle_line_style) },
-    { "Solid",    GTK_SIGNAL_FUNC (ctree_toggle_line_style) },
-    { "Dotted",   GTK_SIGNAL_FUNC (ctree_toggle_line_style) },
-    { "Tabbed",   GTK_SIGNAL_FUNC (ctree_toggle_line_style) }
+    { "No lines" },
+    { "Solid"    },
+    { "Dotted"   },
+    { "Tabbed"   }
   };

   static OptionMenuItem items2[] =
   {
-    { "None",     GTK_SIGNAL_FUNC (ctree_toggle_expander_style) },
-    { "Square",   GTK_SIGNAL_FUNC (ctree_toggle_expander_style) },
-    { "Triangle", GTK_SIGNAL_FUNC (ctree_toggle_expander_style) },
-    { "Circular", GTK_SIGNAL_FUNC (ctree_toggle_expander_style) }
+    { "None"     },
+    { "Square"   },
+    { "Triangle" },
+    { "Circular" }
   };

   static OptionMenuItem items3[] =
   {
-    { "Left",  GTK_SIGNAL_FUNC (ctree_toggle_justify) },
-    { "Right", GTK_SIGNAL_FUNC (ctree_toggle_justify) }
+    { "Left"  },
+    { "Right" }
   };

   static OptionMenuItem items4[] =
   {
-    { "Single",   GTK_SIGNAL_FUNC (ctree_toggle_sel_mode) },
-    { "Browse",   GTK_SIGNAL_FUNC (ctree_toggle_sel_mode) },
-    { "Multiple", GTK_SIGNAL_FUNC (ctree_toggle_sel_mode) },
-    { "Extended", GTK_SIGNAL_FUNC (ctree_toggle_sel_mode) }
+    { "Single"   },
+    { "Browse"   },
+    { "Multiple" },
+    { "Extended" }
   };

   if (!window)
@@ -5985,21 +5974,27 @@
       hbox = gtk_hbox_new (TRUE, 5);
       gtk_box_pack_start (GTK_BOX (mbox), hbox, FALSE, FALSE, 0);

-      omenu1 = build_option_menu (items1, 4, 2, ctree);
+      omenu1 = build_option_menu (items1, 4, 2,
+				  (GtkSignalFunc)ctree_toggle_line_style,
+				  ctree);
       gtk_box_pack_start (GTK_BOX (hbox), omenu1, FALSE, TRUE, 0);
       gtk_tooltips_set_tip (tooltips, omenu1, "The tree's line style.", NULL);

-      omenu2 = build_option_menu (items2, 4, 1, ctree);
+      omenu2 = build_option_menu (items2, 4, 1,
+				  (GtkSignalFunc)ctree_toggle_expander_style,
+				  ctree);
       gtk_box_pack_start (GTK_BOX (hbox), omenu2, FALSE, TRUE, 0);
       gtk_tooltips_set_tip (tooltips, omenu2, "The tree's expander style.",
 			    NULL);

-      omenu3 = build_option_menu (items3, 2, 0, ctree);
+      omenu3 = build_option_menu (items3, 2, 0,
+				  (GtkSignalFunc)ctree_toggle_justify, ctree);
       gtk_box_pack_start (GTK_BOX (hbox), omenu3, FALSE, TRUE, 0);
       gtk_tooltips_set_tip (tooltips, omenu3, "The tree's justification.",
 			    NULL);

-      omenu4 = build_option_menu (items4, 4, 3, ctree);
+      omenu4 = build_option_menu (items4, 4, 3,
+				  (GtkSignalFunc)ctree_toggle_sel_mode, ctree);
       gtk_box_pack_start (GTK_BOX (hbox), omenu4, FALSE, TRUE, 0);
       gtk_tooltips_set_tip (tooltips, omenu4, "The list's selection mode.",
 			    NULL);
@@ -7248,57 +7243,51 @@
 }

 static void
-standard_notebook (GtkButton   *button,
-                   GtkNotebook *notebook)
+notebook_type_changed (GtkWidget *optionmenu, GtkNotebook *notebook)
 {
-  gint i;
+  gint i, c;

-  gtk_notebook_set_show_tabs (notebook, TRUE);
-  gtk_notebook_set_show_border (notebook, TRUE);
-  gtk_notebook_set_scrollable (notebook, FALSE);
-  if (g_list_length (notebook->children) == 15)
-    for (i = 0; i < 10; i++)
-      gtk_notebook_remove_page (notebook, 5);
-}
+  c = gtk_option_menu_get_history (GTK_OPTION_MENU (optionmenu));

-static void
-notabs_notebook (GtkButton   *button,
-                 GtkNotebook *notebook)
-{
-  gint i;
+  switch (c)
+    {
+    case 0:
+      /* standard notebook */
+      gtk_notebook_set_show_tabs (notebook, TRUE);
+      gtk_notebook_set_show_border (notebook, TRUE);
+      gtk_notebook_set_scrollable (notebook, FALSE);
+      break;

-  gtk_notebook_set_show_tabs (notebook, FALSE);
-  gtk_notebook_set_show_border (notebook, TRUE);
-  if (g_list_length (notebook->children) == 15)
-    for (i = 0; i < 10; i++)
-      gtk_notebook_remove_page (notebook, 5);
-}
+    case 1:
+      /* notabs notebook */
+      gtk_notebook_set_show_tabs (notebook, FALSE);
+      gtk_notebook_set_show_border (notebook, TRUE);
+      break;

-static void
-borderless_notebook (GtkButton   *button,
-		     GtkNotebook *notebook)
-{
-  gint i;
+    case 2:
+      /* borderless */
+      gtk_notebook_set_show_tabs (notebook, FALSE);
+      gtk_notebook_set_show_border (notebook, FALSE);
+      break;

-  gtk_notebook_set_show_tabs (notebook, FALSE);
-  gtk_notebook_set_show_border (notebook, FALSE);
+    case 3:
+      /* scrollable */
+      gtk_notebook_set_show_tabs (notebook, TRUE);
+      gtk_notebook_set_show_border (notebook, TRUE);
+      gtk_notebook_set_scrollable (notebook, TRUE);
+      if (g_list_length (notebook->children) == 5)
+	create_pages (notebook, 6, 15);
+
+      return;
+      break;
+    }
+
   if (g_list_length (notebook->children) == 15)
     for (i = 0; i < 10; i++)
       gtk_notebook_remove_page (notebook, 5);
 }

 static void
-scrollable_notebook (GtkButton   *button,
-                     GtkNotebook *notebook)
-{
-  gtk_notebook_set_show_tabs (notebook, TRUE);
-  gtk_notebook_set_show_border (notebook, TRUE);
-  gtk_notebook_set_scrollable (notebook, TRUE);
-  if (g_list_length (notebook->children) == 5)
-    create_pages (notebook, 6, 15);
-}
-
-static void
 notebook_popup (GtkToggleButton *button,
 		GtkNotebook     *notebook)
 {
@@ -7329,10 +7318,10 @@

   static OptionMenuItem items[] =
   {
-    { "Standard",   GTK_SIGNAL_FUNC (standard_notebook) },
-    { "No tabs",    GTK_SIGNAL_FUNC (notabs_notebook) },
-    { "Borderless", GTK_SIGNAL_FUNC (borderless_notebook) },
-    { "Scrollable", GTK_SIGNAL_FUNC (scrollable_notebook) },
+    { "Standard"   },
+    { "No tabs"    },
+    { "Borderless" },
+    { "Scrollable" },
   };

   if (!window)
@@ -7396,7 +7385,9 @@
       label = gtk_label_new ("Notebook Style :");
       gtk_box_pack_start (GTK_BOX (box2), label, FALSE, TRUE, 0);

-      omenu = build_option_menu (items, G_N_ELEMENTS (items), 0, sample_notebook);
+      omenu = build_option_menu (items, G_N_ELEMENTS (items), 0,
+				 (GtkSignalFunc)notebook_type_changed,
+				 sample_notebook);
       gtk_box_pack_start (GTK_BOX (box2), omenu, FALSE, TRUE, 0);

       button = gtk_button_new_with_label ("Show all Pages");
@@ -8870,11 +8861,10 @@
   if (!GTK_WIDGET_MAPPED (widget))
     return;

-  RADIOMENUTOGGLED ((GtkRadioMenuItem *)
-		    (((GtkOptionMenu *)(pdata->omenu1))->menu_item), i);
+  i = gtk_option_menu_get_history (GTK_OPTION_MENU (widget));

   gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (pdata->pbar),
-			    (GtkProgressBarOrientation) (3-i));
+				    (GtkProgressBarOrientation) (i));
 }

 static void
@@ -8896,17 +8886,14 @@

   if (!GTK_WIDGET_MAPPED (widget))
     return;
-
-  RADIOMENUTOGGLED ((GtkRadioMenuItem *)
-		    (((GtkOptionMenu *)(pdata->omenu2))->menu_item), i);

-  i = 1 - i;
+  i = gtk_option_menu_get_history (GTK_OPTION_MENU (widget));

   if (i == 1)
     gtk_widget_set_sensitive (pdata->block_spin, TRUE);
   else
     gtk_widget_set_sensitive (pdata->block_spin, FALSE);
-
+
   gtk_progress_bar_set_bar_style (GTK_PROGRESS_BAR (pdata->pbar),
 				  (GtkProgressBarStyle) i);
 }
@@ -8992,16 +8979,16 @@

   static OptionMenuItem items1[] =
   {
-    { "Left-Right", GTK_SIGNAL_FUNC (progressbar_toggle_orientation) },
-    { "Right-Left", GTK_SIGNAL_FUNC (progressbar_toggle_orientation) },
-    { "Bottom-Top", GTK_SIGNAL_FUNC (progressbar_toggle_orientation) },
-    { "Top-Bottom", GTK_SIGNAL_FUNC (progressbar_toggle_orientation) }
+    { "Left-Right" },
+    { "Right-Left" },
+    { "Bottom-Top" },
+    { "Top-Bottom" }
   };

   static OptionMenuItem items2[] =
   {
-    { "Continuous", GTK_SIGNAL_FUNC (progressbar_toggle_bar_style) },
-    { "Discrete",   GTK_SIGNAL_FUNC (progressbar_toggle_bar_style) }
+    { "Continuous" },
+    { "Discrete"   }
   };

   if (!pdata)
@@ -9071,7 +9058,9 @@
 			5, 5);
       gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);

-      pdata->omenu1 = build_option_menu (items1, 4, 0, pdata);
+      pdata->omenu1 = build_option_menu
+	(items1, 4, 0, (GtkSignalFunc)progressbar_toggle_orientation,
+	 pdata);
       hbox = gtk_hbox_new (FALSE, 0);
       gtk_table_attach (GTK_TABLE (tab), hbox, 1, 2, 0, 1,
 			GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
@@ -9140,7 +9129,9 @@
 			5, 5);
       gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);

-      pdata->omenu2 = build_option_menu (items2, 2, 0, pdata);
+      pdata->omenu2 = build_option_menu
+	(items2, 2, 0, (GtkSignalFunc)progressbar_toggle_bar_style,
+	 pdata);
       hbox = gtk_hbox_new (FALSE, 0);
       gtk_table_attach (GTK_TABLE (tab), hbox, 1, 2, 3, 4,
 			GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,



-- 
Odi et amo. Quare id faciam, fortasse requiris?
	Nescio, sed fieri sentio et excrucior.

-Catullus (Carmen 85)





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