From 46ed450a2995c98c44305077d3edcd10d6fd2bc3 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Thu, 21 Nov 2013 16:24:27 +0100 Subject: [PATCH] treemenu: Implement height-for-width properly --- gtk/gtktreemenu.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/gtk/gtktreemenu.c b/gtk/gtktreemenu.c index 5bdf729159..cc025070a5 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 * ****************************************************************/