Re: #59885: patch



On 19 Sep 2001, Owen Taylor wrote:

> >
> > Ok to commit?
> >
> > regards,
>
> Looks fine, with various stylistic nits noted below.
>
> Regards,
>                                              Owen

New patch appended. ChangeLog:

Thu Sep 20 18:00:56 2001  Kristian Rietveld  <kristian planet nl>

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

        (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): changed OptionMenuItem arrays into
        gchar * arrays. Removed "Extended" item where used.

        Fixes bug #59885


Ok to commit?

regards,


	Kris



Index: testgtk.c
===================================================================
RCS file: /cvs/gnome/gtk+/tests/testgtk.c,v
retrieving revision 1.276
diff -u -r1.276 testgtk.c
--- testgtk.c	2001/09/18 20:06:48	1.276
+++ testgtk.c	2001/09/20 15:57:45
@@ -52,12 +52,6 @@
 #include "circles.xbm"
 #include "test.xpm"

-typedef struct _OptionMenuItem
-{
-  gchar        *name;
-  GtkSignalFunc func;
-} OptionMenuItem;
-
 gboolean
 file_exists (const char *filename)
 {
@@ -75,10 +69,11 @@
 		   gint      window_type);

 static GtkWidget *
-build_option_menu (OptionMenuItem items[],
-		   gint           num_items,
-		   gint           history,
-		   gpointer       data);
+build_option_menu (gchar           *items[],
+		   gint             num_items,
+		   gint             history,
+		   void           (*func)(GtkWidget *widget, gpointer data),
+		   gpointer         data);

 /* macro, structure and variables used by tree window demos */
 #define DEFAULT_NUMBER_OF_ITEM  3
@@ -105,10 +100,11 @@
 /* end of tree section */

 static GtkWidget *
-build_option_menu (OptionMenuItem items[],
-		   gint           num_items,
-		   gint           history,
-		   gpointer       data)
+build_option_menu (gchar           *items[],
+		   gint             num_items,
+		   gint             history,
+		   void           (*func)(GtkWidget *widget, gpointer data),
+		   gpointer         data)
 {
   GtkWidget *omenu;
   GtkWidget *menu;
@@ -117,15 +113,15 @@
   gint i;

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

   menu = gtk_menu_new ();
   group = NULL;

   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);
+      menu_item = gtk_radio_menu_item_new_with_label (group, items[i]);
       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 +4452,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 +4462,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
@@ -4487,12 +4472,11 @@
 {
   static GtkWidget *window = NULL;

-  static OptionMenuItem items[] =
+  static gchar *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"
   };

   if (!window)
@@ -4590,7 +4574,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, 3, 3,
+				      list_toggle_sel_mode,
+				      list);
       gtk_box_pack_start (GTK_BOX (hbox), list_omenu, FALSE, TRUE, 0);

       separator = gtk_hseparator_new ();
@@ -4940,10 +4926,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
@@ -4977,12 +4962,11 @@
     "Title 8",  "Title 9",  "Title 10", "Title 11"
   };

-  static OptionMenuItem items[] =
+  static gchar *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",
   };

   char text[TESTGTK_CLIST_COLUMNS][50];
@@ -5096,7 +5080,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, 3, 3,
+				       clist_toggle_sel_mode,
+				       clist);
       gtk_box_pack_start (GTK_BOX (hbox), clist_omenu, FALSE, TRUE, 0);

       /*
@@ -5550,16 +5536,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 +5553,10 @@

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

-  gtk_ctree_set_expander_style (ctree, (GtkCTreeExpanderStyle) (3 - i));
+  gtk_ctree_set_expander_style (ctree, (GtkCTreeExpanderStyle) i);
 }

 void ctree_toggle_justify (GtkWidget *widget, GtkCTree *ctree)
@@ -5582,11 +5566,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 +5579,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);
 }

@@ -5764,34 +5746,33 @@
   char *title[] = { "Tree" , "Info" };
   char buf[80];

-  static OptionMenuItem items1[] =
+  static gchar *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[] =
+  static gchar *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[] =
+  static gchar *items3[] =
   {
-    { "Left",  GTK_SIGNAL_FUNC (ctree_toggle_justify) },
-    { "Right", GTK_SIGNAL_FUNC (ctree_toggle_justify) }
+    "Left",
+    "Right"
   };
-
-  static OptionMenuItem items4[] =
+
+  static gchar *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",
   };

   if (!window)
@@ -5985,21 +5966,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,
+				  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,
+				  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,
+				  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, 3, 3,
+				  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 +7235,59 @@
 }

 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);
-}
+  enum {
+    STANDARD,
+    NOTABS,
+    BORDERLESS,
+    SCROLLABLE
+  };

-static void
-notabs_notebook (GtkButton   *button,
-                 GtkNotebook *notebook)
-{
-  gint i;
+  c = gtk_option_menu_get_history (GTK_OPTION_MENU (optionmenu));

-  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);
-}
+  switch (c)
+    {
+    case STANDARD:
+      /* standard notebook */
+      gtk_notebook_set_show_tabs (notebook, TRUE);
+      gtk_notebook_set_show_border (notebook, TRUE);
+      gtk_notebook_set_scrollable (notebook, FALSE);
+      break;

-static void
-borderless_notebook (GtkButton   *button,
-		     GtkNotebook *notebook)
-{
-  gint i;
+    case NOTABS:
+      /* notabs notebook */
+      gtk_notebook_set_show_tabs (notebook, FALSE);
+      gtk_notebook_set_show_border (notebook, TRUE);
+      break;
+
+    case BORDERLESS:
+      /* 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 SCROLLABLE:
+      /* 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)
 {
@@ -7327,12 +7316,12 @@
   GdkColor *transparent = NULL;
   GtkWidget *label;

-  static OptionMenuItem items[] =
+  static gchar *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,
+				 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);
 }
@@ -8990,18 +8977,18 @@
   GtkAdjustment *adj;
   static ProgressData *pdata = NULL;

-  static OptionMenuItem items1[] =
+  static gchar *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[] =
+  static gchar *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,
+					 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,
+					 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]