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



commit 8a178cd7c3872ba097aad0d858bf55ec5921354d
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 |   44 +++++++++++++++++++++++++++++++++++++++-----
 gtk/gtkmenuitem.h |    4 ++++
 2 files changed, 43 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkmenuitem.c b/gtk/gtkmenuitem.c
index 2084444..943ca98 100644
--- a/gtk/gtkmenuitem.c
+++ b/gtk/gtkmenuitem.c
@@ -42,7 +42,8 @@
 
 typedef struct {
   GtkAction *action;
-  gboolean   use_action_appearance;
+  guint32    use_action_appearance : 1;
+  guint32    reserve_indicator : 1;
 } GtkMenuItemPrivate;
 
 enum {
@@ -704,11 +705,12 @@ gtk_menu_item_get_preferred_width (GtkWidget *request,
 
   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;
@@ -800,6 +802,7 @@ gtk_menu_item_get_preferred_height (GtkWidget *request,
 
   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);
@@ -807,7 +810,7 @@ gtk_menu_item_get_preferred_height (GtkWidget *request,
       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;
 
@@ -909,10 +912,11 @@ gtk_menu_item_get_preferred_height_for_width (GtkWidget *request,
 
   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;
@@ -1343,6 +1347,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;
@@ -1385,7 +1390,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;
@@ -2504,3 +2509,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 ef62c77..4aa85c2 100644
--- a/gtk/gtkmenuitem.h
+++ b/gtk/gtkmenuitem.h
@@ -128,6 +128,10 @@ 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,



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