summaryrefslogtreecommitdiff
path: root/gtk/gtkmenusectionbox.c
diff options
context:
space:
mode:
authorTimm Bäder <mail@baedert.org>2015-03-17 19:34:43 +0100
committerTimm Bäder <mail@baedert.org>2015-05-29 17:37:04 +0200
commitd3a18de97e1033e7be7f5695a6abcdb48f48469f (patch)
treea47365dfccf9cf23b193f538a946d0f0514d93c1 /gtk/gtkmenusectionbox.c
parent36c65c1acabfd8fb1b5b85d7b128bfd4361b6fc3 (diff)
downloadgtk+-d3a18de97e1033e7be7f5695a6abcdb48f48469f.tar.gz
gtkpopover: Update the menu's alignment
... when the popover position changes.
Diffstat (limited to 'gtk/gtkmenusectionbox.c')
-rw-r--r--gtk/gtkmenusectionbox.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/gtk/gtkmenusectionbox.c b/gtk/gtkmenusectionbox.c
index 359d6341d5..1f38e1b81f 100644
--- a/gtk/gtkmenusectionbox.c
+++ b/gtk/gtkmenusectionbox.c
@@ -277,7 +277,7 @@ gtk_menu_section_box_insert_func (GtkMenuTrackerItem *item,
gchar *name;
widget = g_object_new (GTK_TYPE_MODEL_BUTTON,
- "menu-name", gtk_menu_tracker_item_get_label (item),
+ "menu-name", gtk_menu_tracker_item_get_label (item),
NULL);
g_object_bind_property (item, "label", widget, "text", G_BINDING_SYNC_CREATE);
g_object_bind_property (item, "icon", widget, "icon", G_BINDING_SYNC_CREATE);
@@ -369,10 +369,39 @@ gtk_menu_section_box_class_init (GtkMenuSectionBoxClass *class)
G_OBJECT_CLASS (class)->dispose = gtk_menu_section_box_dispose;
}
+static void
+update_popover_position_cb (GObject *source,
+ GParamSpec *spec,
+ gpointer *user_data)
+{
+ GtkPopover *popover = GTK_POPOVER (source);
+ GtkMenuSectionBox *box = GTK_MENU_SECTION_BOX (user_data);
+
+ GtkPositionType new_pos = gtk_popover_get_position (popover);
+
+ GList *children = gtk_container_get_children (GTK_CONTAINER (gtk_widget_get_parent (GTK_WIDGET (box))));
+ GList *l;
+
+ for (l = children;
+ l != NULL;
+ l = l->next)
+ {
+ GtkWidget *w = l->data;
+
+ if (new_pos == GTK_POS_BOTTOM)
+ gtk_widget_set_valign (w, GTK_ALIGN_START);
+ else if (new_pos == GTK_POS_TOP)
+ gtk_widget_set_valign (w, GTK_ALIGN_END);
+ else
+ gtk_widget_set_valign (w, GTK_ALIGN_CENTER);
+ }
+}
+
void
gtk_menu_section_box_new_toplevel (GtkStack *stack,
GMenuModel *model,
- const gchar *action_namespace)
+ const gchar *action_namespace,
+ GtkPopover *popover)
{
GtkMenuSectionBox *box;
@@ -384,6 +413,9 @@ gtk_menu_section_box_new_toplevel (GtkStack *stack,
gtk_menu_section_box_insert_func,
gtk_menu_section_box_remove_func, box);
+ g_signal_connect (G_OBJECT (popover), "notify::position", G_CALLBACK (update_popover_position_cb), box);
+
+
gtk_widget_show (GTK_WIDGET (box));
}