[gtk+/gtk-3-10] treemenu: Implement height-for-width properly



commit 99129d15c7679cbb0f37adbe5b12f012cd49a37e
Author: Benjamin Otte <otte redhat com>
Date:   Thu Nov 21 16:24:27 2013 +0100

    treemenu: Implement height-for-width properly

 gtk/gtktreemenu.c |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtktreemenu.c b/gtk/gtktreemenu.c
index 5bdf729..cc02507 100644
--- a/gtk/gtktreemenu.c
+++ b/gtk/gtktreemenu.c
@@ -73,6 +73,14 @@ static void      gtk_tree_menu_get_preferred_width            (GtkWidget
 static void      gtk_tree_menu_get_preferred_height           (GtkWidget           *widget,
                                                                gint                *minimum_size,
                                                                gint                *natural_size);
+static void      gtk_tree_menu_get_preferred_width_for_height (GtkWidget           *widget,
+                                                               gint                 for_height,
+                                                               gint                *minimum_size,
+                                                               gint                *natural_size);
+static void      gtk_tree_menu_get_preferred_height_for_width (GtkWidget           *widget,
+                                                               gint                 for_width,
+                                                               gint                *minimum_size,
+                                                               gint                *natural_size);
 
 /* GtkCellLayoutIface */
 static void      gtk_tree_menu_cell_layout_init               (GtkCellLayoutIface  *iface);
@@ -227,6 +235,8 @@ _gtk_tree_menu_class_init (GtkTreeMenuClass *class)
 
   widget_class->get_preferred_width  = gtk_tree_menu_get_preferred_width;
   widget_class->get_preferred_height = gtk_tree_menu_get_preferred_height;
+  widget_class->get_preferred_width_for_height  = gtk_tree_menu_get_preferred_width_for_height;
+  widget_class->get_preferred_height_for_width = gtk_tree_menu_get_preferred_height_for_width;
 
   /*
    * GtkTreeMenu::menu-activate:
@@ -617,6 +627,49 @@ gtk_tree_menu_get_preferred_height (GtkWidget           *widget,
   g_signal_handler_unblock (priv->context, priv->size_changed_id);
 }
 
+static void
+gtk_tree_menu_get_preferred_width_for_height (GtkWidget           *widget,
+                                              gint                 for_height,
+                                              gint                *minimum_size,
+                                              gint                *natural_size)
+{
+  GtkTreeMenu        *menu = GTK_TREE_MENU (widget);
+  GtkTreeMenuPrivate *priv = menu->priv;
+
+  /* We leave the requesting work up to the cellviews which operate in the same
+   * context, reserving space for the submenu indicator if any of the items have
+   * submenus ensures that every cellview will receive the same allocated width.
+   *
+   * Since GtkMenu does hieght-for-width correctly, we know that the width of
+   * every cell will be requested before the height-for-widths are requested.
+   */
+  g_signal_handler_block (priv->context, priv->size_changed_id);
+
+  sync_reserve_submenu_size (menu);
+
+  GTK_WIDGET_CLASS (_gtk_tree_menu_parent_class)->get_preferred_width_for_height (widget, for_height, 
minimum_size, natural_size);
+
+  g_signal_handler_unblock (priv->context, priv->size_changed_id);
+}
+
+static void
+gtk_tree_menu_get_preferred_height_for_width (GtkWidget           *widget,
+                                              gint                 for_width,
+                                              gint                *minimum_size,
+                                              gint                *natural_size)
+{
+  GtkTreeMenu        *menu = GTK_TREE_MENU (widget);
+  GtkTreeMenuPrivate *priv = menu->priv;
+
+  g_signal_handler_block (priv->context, priv->size_changed_id);
+
+  sync_reserve_submenu_size (menu);
+
+  GTK_WIDGET_CLASS (_gtk_tree_menu_parent_class)->get_preferred_height_for_width (widget, for_width, 
minimum_size, natural_size);
+
+  g_signal_handler_unblock (priv->context, priv->size_changed_id);
+}
+
 /****************************************************************
  *                      GtkCellLayoutIface                      *
  ****************************************************************/


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