[gtk/global-coords: 19/24] menu: Use a scrolled window
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/global-coords: 19/24] menu: Use a scrolled window
- Date: Fri, 31 May 2019 23:38:09 +0000 (UTC)
commit 13e010deb6777601009950720a9e032039df6036
Author: Matthias Clasen <mclasen redhat com>
Date: Thu May 30 23:07:24 2019 +0000
menu: Use a scrolled window
This brings back some support for scrolling.
We still need to reinstate some of the
scroll-to-selected and keynav functionality.
gtk/gtkmenu.c | 22 +++++++++++++++-------
gtk/gtkmenuprivate.h | 1 +
2 files changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c
index 7b78615c77..6592a909c2 100644
--- a/gtk/gtkmenu.c
+++ b/gtk/gtkmenu.c
@@ -90,6 +90,7 @@
#include "gtkadjustment.h"
#include "gtkbindings.h"
#include "gtkbox.h"
+#include "gtkscrolledwindow.h"
#include "gtkcheckmenuitemprivate.h"
#include "gtkcssnodeprivate.h"
#include "gtkcssstylepropertyprivate.h"
@@ -702,8 +703,18 @@ gtk_menu_init (GtkMenu *menu)
g_object_force_floating (G_OBJECT (menu));
priv->needs_destruction_ref = TRUE;
+ priv->swin = gtk_scrolled_window_new (NULL, NULL);
+ 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_scrolled_window_set_propagate_natural_width (GTK_SCROLLED_WINDOW (priv->swin),
+ TRUE);
+ gtk_scrolled_window_set_propagate_natural_height (GTK_SCROLLED_WINDOW (priv->swin),
+ TRUE);
+
priv->box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- gtk_widget_set_parent (priv->box, GTK_WIDGET (menu));
+ gtk_container_add (GTK_CONTAINER (priv->swin), priv->box);
priv->monitor_num = -1;
@@ -781,7 +792,7 @@ gtk_menu_finalize (GObject *object)
GtkMenu *menu = GTK_MENU (object);
GtkMenuPrivate *priv = menu->priv;
- g_clear_pointer (&priv->box, gtk_widget_unparent);
+ g_clear_pointer (&priv->swin, gtk_widget_unparent);
G_OBJECT_CLASS (gtk_menu_parent_class)->finalize (object);
}
@@ -1944,7 +1955,6 @@ gtk_menu_size_allocate (GtkWidget *widget,
{
GtkMenu *menu = GTK_MENU (widget);
GtkMenuPrivate *priv = menu->priv;
- GtkMenuShell *menu_shell = GTK_MENU_SHELL (widget);
GList *children, *l;
children = gtk_container_get_children (GTK_CONTAINER (priv->box));
@@ -1957,7 +1967,7 @@ gtk_menu_size_allocate (GtkWidget *widget,
}
g_list_free (children);
- gtk_widget_size_allocate (priv->box,
+ gtk_widget_size_allocate (priv->swin,
&(GtkAllocation) { 0, 0, width, height },
baseline);
}
@@ -1983,10 +1993,8 @@ gtk_menu_measure (GtkWidget *widget,
{
GtkMenu *menu = GTK_MENU (widget);
GtkMenuPrivate *priv = gtk_menu_get_instance_private (menu);
- GtkMenuShell *menu_shell = GTK_MENU_SHELL (widget);
-
- gtk_widget_measure (priv->box,
+ gtk_widget_measure (priv->swin,
orientation,
for_size,
minimum, natural,
diff --git a/gtk/gtkmenuprivate.h b/gtk/gtkmenuprivate.h
index 62e8da8cba..3e6e41b566 100644
--- a/gtk/gtkmenuprivate.h
+++ b/gtk/gtkmenuprivate.h
@@ -75,6 +75,7 @@ struct _GtkMenuPrivate
* before operating on these widgets
*/
GtkWidget *toplevel;
+ GtkWidget *swin;
GtkWidget *box;
guint needs_destruction_ref : 1;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]