summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2019-06-03 14:47:48 +0000
committerMatthias Clasen <mclasen@redhat.com>2019-06-03 14:49:13 +0000
commitc7ccaa5ef24d25f8ba6d197b4e6b4ac59a7737f5 (patch)
tree58a78ed477c11c1606439e7dd7fd4eb56caad89d
parent3ae15aad164fb06fc4411ec95c652a23ecc6c62f (diff)
downloadgtk+-c7ccaa5ef24d25f8ba6d197b4e6b4ac59a7737f5.tar.gz
menu: Update scrollbar policy
We want to avoid sizing problems for small menus due to the vertical scrollbar imposing a min-height on its slider. Closes: https://gitlab.gnome.org/GNOME/gtk/issues/1930
-rw-r--r--gtk/gtkmenu.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c
index 1cb05a58ed..fef9f53050 100644
--- a/gtk/gtkmenu.c
+++ b/gtk/gtkmenu.c
@@ -242,6 +242,31 @@ static guint menu_signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE_WITH_PRIVATE (GtkMenu, gtk_menu, GTK_TYPE_MENU_SHELL)
static void
+update_scrollbars (GtkMenu *menu)
+{
+ GtkMenuPrivate *priv = menu->priv;
+ GtkWidget *child;
+ int n = 0;
+ GtkPolicyType policy = GTK_POLICY_NEVER;
+
+ for (child = gtk_widget_get_first_child (priv->box);
+ child;
+ child = gtk_widget_get_next_sibling (child))
+ {
+ n++;
+ if (n == 10)
+ {
+ policy = GTK_POLICY_AUTOMATIC;
+ break;
+ }
+ }
+
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->swin),
+ GTK_POLICY_NEVER,
+ policy);
+}
+
+static void
menu_queue_resize (GtkMenu *menu)
{
GtkMenuPrivate *priv = menu->priv;
@@ -802,7 +827,7 @@ gtk_menu_init (GtkMenu *menu)
gtk_widget_set_parent (priv->swin, GTK_WIDGET (menu));
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->swin),
GTK_POLICY_NEVER,
- GTK_POLICY_AUTOMATIC);
+ GTK_POLICY_NEVER);
gtk_scrolled_window_set_propagate_natural_width (GTK_SCROLLED_WINDOW (priv->swin),
TRUE);
gtk_scrolled_window_set_propagate_natural_height (GTK_SCROLLED_WINDOW (priv->swin),
@@ -1089,6 +1114,7 @@ gtk_menu_add (GtkContainer *container,
gtk_container_add (GTK_CONTAINER (priv->box), widget);
+ update_scrollbars (menu);
menu_queue_resize (menu);
}
@@ -1107,6 +1133,7 @@ gtk_menu_remove (GtkContainer *container,
GTK_CONTAINER_CLASS (gtk_menu_parent_class)->remove (container, widget);
+ update_scrollbars (menu);
menu_queue_resize (menu);
}
@@ -1134,6 +1161,7 @@ gtk_menu_real_insert (GtkMenuShell *menu_shell,
gtk_container_add (GTK_CONTAINER (priv->box), child);
gtk_menu_reorder_child (menu, child, position);
+ update_scrollbars (menu);
menu_queue_resize (menu);
}