[gtk+/combo-refactor: 5/59] Added gtk_menu_item_set/get_reserve_indicator.



commit f15a589651889fae1c2436f052b9f960d46b482a
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Thu Nov 18 17:31:31 2010 +0900

    Added gtk_menu_item_set/get_reserve_indicator.
    
    This is needed by GtkTreeMenu to ensure that child menu items
    reserve space for the submenu indicator even if they dont have
    submenus... in this way we ensure the same size of all cell
    areas in the menu items at allocation/request time.

 gtk/gtkmenuitem.c        |   41 +++++++++++++++++++++++++++++++++++++----
 gtk/gtkmenuitem.h        |   13 +++++++++++++
 gtk/gtkmenuitemprivate.h |    1 +
 3 files changed, 51 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkmenuitem.c b/gtk/gtkmenuitem.c
index 125d6df..4f04f6c 100644
--- a/gtk/gtkmenuitem.c
+++ b/gtk/gtkmenuitem.c
@@ -709,11 +709,12 @@ gtk_menu_item_get_preferred_width (GtkWidget *widget,
 
   if (child != NULL && gtk_widget_get_visible (child))
     {
+      GtkMenuItemPrivate *priv = GET_PRIVATE (menu_item);
       gint child_min, child_nat;
 
       gtk_widget_get_preferred_width (child, &child_min, &child_nat);
 
-      if (menu_item->submenu && !GTK_IS_MENU_BAR (parent))
+      if ((menu_item->submenu && !GTK_IS_MENU_BAR (parent)) || priv->reserve_indicator);
 	{
 	  guint arrow_spacing;
 	  gint  arrow_size;
@@ -807,6 +808,7 @@ gtk_menu_item_get_preferred_height (GtkWidget *widget,
 
   if (child != NULL && gtk_widget_get_visible (child))
     {
+      GtkMenuItemPrivate *priv = GET_PRIVATE (menu_item);
       gint child_min, child_nat;
 
       gtk_widget_get_preferred_height (child, &child_min, &child_nat);
@@ -814,7 +816,7 @@ gtk_menu_item_get_preferred_height (GtkWidget *widget,
       min_height += child_min;
       nat_height += child_nat;
 
-      if (menu_item->submenu && !GTK_IS_MENU_BAR (parent))
+      if ((menu_item->submenu && !GTK_IS_MENU_BAR (parent)) || priv->reserve_indicator)
 	{
 	  gint  arrow_size;
 
@@ -916,10 +918,11 @@ gtk_menu_item_get_preferred_height_for_width (GtkWidget *widget,
 
   if (child != NULL && gtk_widget_get_visible (child))
     {
+      GtkMenuItemPrivate *priv = GET_PRIVATE (menu_item);
       gint child_min, child_nat;
       gint arrow_size = 0;
       
-      if (menu_item->submenu && !GTK_IS_MENU_BAR (parent))
+      if ((menu_item->submenu && !GTK_IS_MENU_BAR (parent)) || priv->reserve_indicator)
 	{
           guint arrow_spacing;
 
@@ -1351,6 +1354,7 @@ gtk_menu_item_size_allocate (GtkWidget     *widget,
   child = gtk_bin_get_child (bin);
   if (child)
     {
+      GtkMenuItemPrivate *priv = GET_PRIVATE (menu_item);
       GtkRequisition child_requisition;
       GtkStyle *style;
       guint horizontal_padding;
@@ -1393,7 +1397,7 @@ gtk_menu_item_size_allocate (GtkWidget     *widget,
       child_allocation.y += allocation->y;
 
       gtk_widget_get_preferred_size (child, &child_requisition, NULL);
-      if (menu_item->submenu && !GTK_IS_MENU_BAR (parent)) 
+      if ((menu_item->submenu && !GTK_IS_MENU_BAR (parent)) || priv->reserve_indicator)
 	{
 	  if (direction == GTK_TEXT_DIR_RTL)
 	    child_allocation.x += child_requisition.height;
@@ -2515,3 +2519,32 @@ gtk_menu_item_get_use_underline (GtkMenuItem *menu_item)
 
   return FALSE;
 }
+
+void
+gtk_menu_item_set_reserve_indicator (GtkMenuItem         *menu_item,
+				     gboolean             reserve)
+{
+  GtkMenuItemPrivate *priv;
+
+  g_return_if_fail (GTK_IS_MENU_ITEM (menu_item));
+
+  priv = GET_PRIVATE (menu_item);
+
+  if (priv->reserve_indicator != reserve)
+    {
+      priv->reserve_indicator = reserve;
+      gtk_widget_queue_resize (GTK_WIDGET (menu_item));
+    }
+}
+
+gboolean
+gtk_menu_item_get_reserve_indicator (GtkMenuItem         *menu_item)
+{
+  GtkMenuItemPrivate *priv;
+
+  g_return_val_if_fail (GTK_IS_MENU_ITEM (menu_item), FALSE);
+
+  priv = GET_PRIVATE (menu_item);
+
+  return priv->reserve_indicator;
+}
diff --git a/gtk/gtkmenuitem.h b/gtk/gtkmenuitem.h
index c0a51e4..efa1bf0 100644
--- a/gtk/gtkmenuitem.h
+++ b/gtk/gtkmenuitem.h
@@ -119,6 +119,19 @@ void       gtk_menu_item_set_use_underline    (GtkMenuItem         *menu_item,
                                                gboolean             setting);
 gboolean   gtk_menu_item_get_use_underline    (GtkMenuItem         *menu_item);
 
+void       gtk_menu_item_set_reserve_indicator(GtkMenuItem         *menu_item,
+					       gboolean             reserve);
+gboolean   gtk_menu_item_get_reserve_indicator(GtkMenuItem         *menu_item);
+
+/* private */
+void	  _gtk_menu_item_refresh_accel_path   (GtkMenuItem	   *menu_item,
+					       const gchar	   *prefix,
+					       GtkAccelGroup	   *accel_group,
+					       gboolean		    group_changed);
+gboolean  _gtk_menu_item_is_selectable        (GtkWidget           *menu_item);
+void      _gtk_menu_item_popup_submenu        (GtkWidget           *menu_item,
+                                               gboolean             with_delay);
+void      _gtk_menu_item_popdown_submenu      (GtkWidget           *menu_item);
 
 G_END_DECLS
 
diff --git a/gtk/gtkmenuitemprivate.h b/gtk/gtkmenuitemprivate.h
index 226ff3c..6c3377a 100644
--- a/gtk/gtkmenuitemprivate.h
+++ b/gtk/gtkmenuitemprivate.h
@@ -42,6 +42,7 @@ struct _GtkMenuItemPrivate
   guint timer_from_keypress    : 1;
   guint from_menubar           : 1;
   guint use_action_appearance  : 1;
+  guint reserve_indicator      : 1;
 
   guint timer;
 



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