[gtk+/gtk-3-22] Move style change for popover creation.



commit 8cf774d668da5983fa66c9b40b57e235e7e30208
Author: Olof-Joachim Frahm <olof macrolet net>
Date:   Sun Feb 26 16:02:49 2017 +0100

    Move style change for popover creation.
    
    Creating with `gtk_popover_new_from_model` should be exactly the same as
    if via `gtk_popover_new` plus `gtk_popover_bind_model`.
    
    Also remove the style if the model is unbound at any point.

 gtk/gtkpopover.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkpopover.c b/gtk/gtkpopover.c
index 5f0f443..e89ae37 100644
--- a/gtk/gtkpopover.c
+++ b/gtk/gtkpopover.c
@@ -2469,6 +2469,7 @@ gtk_popover_bind_model (GtkPopover  *popover,
 {
   GtkWidget *child;
   GtkWidget *stack;
+  GtkStyleContext *style_context;
 
   g_return_if_fail (GTK_IS_POPOVER (popover));
   g_return_if_fail (model == NULL || G_IS_MENU_MODEL (model));
@@ -2477,6 +2478,8 @@ gtk_popover_bind_model (GtkPopover  *popover,
   if (child)
     gtk_widget_destroy (child);
 
+  style_context = gtk_widget_get_style_context (GTK_WIDGET (popover));
+
   if (model)
     {
       stack = gtk_stack_new ();
@@ -2494,6 +2497,12 @@ gtk_popover_bind_model (GtkPopover  *popover,
 
       g_signal_connect (popover, "unmap", G_CALLBACK (back_to_main), NULL);
       g_signal_connect (popover, "map", G_CALLBACK (back_to_main), NULL);
+
+      gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_MENU);
+    }
+  else
+    {
+      gtk_style_context_remove_class (style_context, GTK_STYLE_CLASS_MENU);
     }
 }
 
@@ -2522,7 +2531,6 @@ gtk_popover_new_from_model (GtkWidget  *relative_to,
                             GMenuModel *model)
 {
   GtkWidget *popover;
-  GtkStyleContext *style_context;
 
   g_return_val_if_fail (relative_to == NULL || GTK_IS_WIDGET (relative_to), NULL);
   g_return_val_if_fail (G_IS_MENU_MODEL (model), NULL);
@@ -2530,9 +2538,6 @@ gtk_popover_new_from_model (GtkWidget  *relative_to,
   popover = gtk_popover_new (relative_to);
   gtk_popover_bind_model (GTK_POPOVER (popover), model, NULL);
 
-  style_context = gtk_widget_get_style_context (GTK_WIDGET (popover));
-  gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_MENU);
-
   return popover;
 }
 


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