[gtk+] Add a way to turn off toggle spacing in menus



commit 724ab5824455f7ec57f56cbd3d0ba05b21e3d305
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jun 24 01:01:51 2009 -0400

    Add a way to turn off toggle spacing in menus
    
    Reserving toggle space is nice for consistency in main menus
    and context menus, but it gets in the way in special situations,
    such as combo boxes, tabular menus, etc.

 docs/reference/gtk/gtk-sections.txt |    2 +
 gtk/gtk.symbols                     |    2 +
 gtk/gtkcombobox.c                   |    6 +-
 gtk/gtkmenu.c                       |   73 +++++++++++++++++++++++++++++++++--
 gtk/gtkmenu.h                       |    7 +--
 5 files changed, 79 insertions(+), 11 deletions(-)
---
diff --git a/docs/reference/gtk/gtk-sections.txt b/docs/reference/gtk/gtk-sections.txt
index 3d93755..45712f3 100644
--- a/docs/reference/gtk/gtk-sections.txt
+++ b/docs/reference/gtk/gtk-sections.txt
@@ -2420,6 +2420,8 @@ gtk_menu_get_title
 gtk_menu_set_monitor
 gtk_menu_get_monitor
 gtk_menu_get_tearoff_state
+gtk_menu_set_reserve_toggle_size
+get_menu_get_reserve_toggle_size
 <SUBSECTION>
 gtk_menu_popdown
 gtk_menu_reposition
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index 3fdbb67..0449189 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -2443,6 +2443,7 @@ gtk_menu_get_active
 gtk_menu_get_monitor
 gtk_menu_get_attach_widget
 gtk_menu_get_for_attach_widget
+gtk_menu_get_reserve_toggle_size
 gtk_menu_get_tearoff_state
 gtk_menu_get_title
 gtk_menu_get_type G_GNUC_CONST
@@ -2455,6 +2456,7 @@ gtk_menu_set_accel_group
 gtk_menu_set_accel_path
 gtk_menu_set_active
 gtk_menu_set_monitor
+gtk_menu_set_reserve_toggle_size
 gtk_menu_set_screen
 gtk_menu_set_tearoff_state
 gtk_menu_set_title
diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c
index b57618a..4e4349e 100644
--- a/gtk/gtkcombobox.c
+++ b/gtk/gtkcombobox.c
@@ -2840,7 +2840,7 @@ gtk_combo_box_menu_setup (GtkComboBox *combo_box,
   /* create our funky menu */
   menu = gtk_menu_new ();
   gtk_widget_set_name (menu, "gtk-combobox-popup-menu");
-  _gtk_menu_set_reserve_toggle_size (GTK_MENU (menu), FALSE);
+  gtk_menu_set_reserve_toggle_size (GTK_MENU (menu), FALSE);
   
   g_signal_connect (menu, "key-press-event",
 		    G_CALLBACK (gtk_combo_box_menu_key_press), combo_box);
@@ -2953,7 +2953,7 @@ gtk_combo_box_menu_fill_level (GtkComboBox *combo_box,
 	  if (gtk_tree_model_iter_has_child (model, &iter))
 	    {
 	      submenu = gtk_menu_new ();
-              _gtk_menu_set_reserve_toggle_size (GTK_MENU (submenu), FALSE);
+              gtk_menu_set_reserve_toggle_size (GTK_MENU (submenu), FALSE);
 	      gtk_widget_show (submenu);
 	      gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
 	      
@@ -3464,7 +3464,7 @@ gtk_combo_box_menu_row_inserted (GtkTreeModel *model,
       if (!menu)
 	{
 	  menu = gtk_menu_new ();
-          _gtk_menu_set_reserve_toggle_size (GTK_MENU (menu), FALSE);
+          gtk_menu_set_reserve_toggle_size (GTK_MENU (menu), FALSE);
 	  gtk_widget_show (menu);
 	  gtk_menu_item_set_submenu (GTK_MENU_ITEM (parent), menu);
 	  
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c
index 49d2e23..0fd5d3d 100644
--- a/gtk/gtkmenu.c
+++ b/gtk/gtkmenu.c
@@ -125,7 +125,8 @@ enum {
   PROP_ATTACH_WIDGET,
   PROP_TEAROFF_STATE,
   PROP_TEAROFF_TITLE,
-  PROP_MONITOR
+  PROP_MONITOR,
+  PROP_RESERVE_TOGGLE_SIZE
 };
 
 enum {
@@ -596,6 +597,27 @@ gtk_menu_class_init (GtkMenuClass *class)
 							     1,
 							     GTK_PARAM_READABLE));
 
+  /**
+   * GtkMenu:reserve-toggle-size:
+   *
+   * A boolean that indicates whether the menu reserves space for
+   * toggles and icons, regardless of their actual presence.
+   *
+   * This property should only be changed from its default value
+   * for special-purposes such as tabular menus. Regular menus that
+   * are connected to a menu bar or context menus should reserve
+   * toggle space for consistency.
+   *
+   * Since: 2.18
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_RESERVE_TOGGLE_SIZE,
+                                   g_param_spec_boolean ("reserve-toggle-size",
+							 P_("Reserve Toggle Size"),
+							 P_("A boolean that indicates whether the menu reserves space for toggles and icons"),
+							 TRUE,
+							 GTK_PARAM_READWRITE));
+
   gtk_widget_class_install_style_property (widget_class,
                                            g_param_spec_int ("horizontal-padding",
                                                              P_("Horizontal Padding"),
@@ -840,6 +862,9 @@ gtk_menu_set_property (GObject      *object,
     case PROP_MONITOR:
       gtk_menu_set_monitor (menu, g_value_get_int (value));
       break;
+    case PROP_RESERVE_TOGGLE_SIZE:
+      gtk_menu_set_reserve_toggle_size (menu, g_value_get_boolean (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -877,6 +902,9 @@ gtk_menu_get_property (GObject     *object,
     case PROP_MONITOR:
       g_value_set_int (value, gtk_menu_get_monitor (menu));
       break;
+    case PROP_RESERVE_TOGGLE_SIZE:
+      g_value_set_boolean (value, gtk_menu_get_reserve_toggle_size (menu));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -5284,13 +5312,50 @@ gtk_menu_grab_notify (GtkWidget *widget,
     }
 }
 
+/**
+ * gtk_menu_set_reserve_toggle_size:
+ * @menu: a #GtkMenu
+ * @reserve_toggle_size: whether to reserve size for toggles
+ *
+ * Sets whether the menu should reserve space for drawing toggles 
+ * or icons, regardless of their actual presence.
+ *
+ * Since: 2.18
+ */
 void
-_gtk_menu_set_reserve_toggle_size (GtkMenu  *menu,
-                                   gboolean  reserve)
+gtk_menu_set_reserve_toggle_size (GtkMenu  *menu,
+                                  gboolean  reserve_toggle_size)
 {
   GtkMenuPrivate *priv = gtk_menu_get_private (menu);
+  gboolean no_toggle_size;
   
-  priv->no_toggle_size = !reserve;
+  no_toggle_size = !reserve_toggle_size;
+
+  if (priv->no_toggle_size != no_toggle_size)
+    {
+      priv->no_toggle_size = no_toggle_size;
+
+      g_object_notify (G_OBJECT (menu), "reserve-toggle-size");
+    }
+}
+
+/**
+ * gtk_menu_get_reserve_toggle_size:
+ * @menu: a #GtkMenu
+ *
+ * Returns whether the menu reserves space for toggles and
+ * icons, regardless of their actual presence.
+ *
+ * Returns: Whether the menu reserves toggle space
+ *
+ * Since: 2.18
+ */
+gboolean
+gtk_menu_get_reserve_toggle_size (GtkMenu *menu)
+{
+  GtkMenuPrivate *priv = gtk_menu_get_private (menu);
+
+  return !priv->no_toggle_size;
 }
 
 #define __GTK_MENU_C__
diff --git a/gtk/gtkmenu.h b/gtk/gtkmenu.h
index 4cdcad3..694457a 100644
--- a/gtk/gtkmenu.h
+++ b/gtk/gtkmenu.h
@@ -209,10 +209,9 @@ GList*     gtk_menu_get_for_attach_widget (GtkWidget           *widget);
 #define gtk_menu_insert(menu,child,pos)	gtk_menu_shell_insert ((GtkMenuShell *)(menu),(child),(pos))
 #endif /* GTK_DISABLE_DEPRECATED */
 
-/* private */
-
-void      _gtk_menu_set_reserve_toggle_size (GtkMenu  *menu,
-                                             gboolean  reserve);
+void     gtk_menu_set_reserve_toggle_size (GtkMenu  *menu,
+                                          gboolean   reserve_toggle_size);
+gboolean gtk_menu_get_reserve_toggle_size (GtkMenu  *menu);
 
 
 G_END_DECLS



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