[gtk+/overlay] overlay: handle window stacking



commit 233eec4c1986a4e3c0aeb740dc90973c77dcc819
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Jun 11 21:54:05 2011 -0400

    overlay: handle window stacking
    
    When window-widgets change their visibility, the raise their
    windows, so we have to make sure the overlays stay on top.
    
    This commit also changes the name of gtk_overlay_add to
    gtk_overlay_add_overlay to avoid clashes with gtk_container_add
    in oo bindings.

 gtk/gtkoverlay.c    |   16 ++++++++++---
 gtk/gtkoverlay.h    |    8 +++---
 tests/testoverlay.c |   62 ++++++++++++++++++++++++++++++++++++++++++++++----
 3 files changed, 73 insertions(+), 13 deletions(-)
---
diff --git a/gtk/gtkoverlay.c b/gtk/gtkoverlay.c
index b815ff5..5d89da4 100644
--- a/gtk/gtkoverlay.c
+++ b/gtk/gtkoverlay.c
@@ -239,6 +239,14 @@ gtk_overlay_size_allocate (GtkWidget     *widget,
 
       child = children->data;
 
+      if (gtk_widget_get_mapped (GTK_WIDGET (overlay)))
+        {
+          if (gtk_widget_get_visible (child->widget))
+            gdk_window_show (child->window);
+          else if (gdk_window_is_visible (child->window))
+            gdk_window_hide (child->window);
+        }
+
       if (!gtk_widget_get_visible (child->widget))
         continue;
 
@@ -495,7 +503,7 @@ gtk_overlay_buildable_add_child (GtkBuildable *buildable,
                                  const gchar  *type)
 {
   if (type && strcmp (type, "overlay") == 0)
-    gtk_overlay_add (GTK_OVERLAY (buildable), GTK_WIDGET (child));
+    gtk_overlay_add_overlay (GTK_OVERLAY (buildable), GTK_WIDGET (child));
   else if (!type)
     gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child));
   else
@@ -524,7 +532,7 @@ gtk_overlay_new (void)
 }
 
 /**
- * gtk_overlay_add:
+ * gtk_overlay_add_overlay:
  * @overlay: a #GtkOverlay
  * @widget: a #GtkWidget to be added to the container
  *
@@ -538,8 +546,8 @@ gtk_overlay_new (void)
  * Since: 3.2
  */
 void
-gtk_overlay_add (GtkOverlay *overlay,
-                 GtkWidget  *widget)
+gtk_overlay_add_overlay (GtkOverlay *overlay,
+                         GtkWidget  *widget)
 {
   GtkOverlayPrivate *priv = overlay->priv;
   GtkOverlayChild *child;
diff --git a/gtk/gtkoverlay.h b/gtk/gtkoverlay.h
index 593eefb..0a9740d 100644
--- a/gtk/gtkoverlay.h
+++ b/gtk/gtkoverlay.h
@@ -64,11 +64,11 @@ struct _GtkOverlayClass
   void (*_gtk_reserved8) (void);
 };
 
-GType      gtk_overlay_get_type (void) G_GNUC_CONST;
+GType      gtk_overlay_get_type    (void) G_GNUC_CONST;
 
-GtkWidget *gtk_overlay_new      (void);
-void       gtk_overlay_add      (GtkOverlay *overlay,
-                                 GtkWidget  *widget);
+GtkWidget *gtk_overlay_new         (void);
+void       gtk_overlay_add_overlay (GtkOverlay *overlay,
+                                    GtkWidget  *widget);
 
 G_END_DECLS
 
diff --git a/tests/testoverlay.c b/tests/testoverlay.c
index 154fc4a..7a64f33 100644
--- a/tests/testoverlay.c
+++ b/tests/testoverlay.c
@@ -40,12 +40,12 @@ test_nonzerox (void)
   gtk_widget_set_halign (child, GTK_ALIGN_START);
   gtk_widget_set_valign (child, GTK_ALIGN_START);
   g_object_set (child, "margin", 3, NULL);
-  gtk_overlay_add (GTK_OVERLAY (overlay), child);
+  gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child);
 
   child = gtk_label_new ("No, I'm the overlay");
   gtk_widget_set_halign (child, GTK_ALIGN_END);
   gtk_widget_set_valign (child, GTK_ALIGN_END);
-  gtk_overlay_add (GTK_OVERLAY (overlay), child);
+  gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child);
   g_object_set (child, "margin", 3, NULL);
 
   return win;
@@ -128,7 +128,7 @@ test_fullwidth (void)
   child = gtk_label_new ("Fullwidth top overlay");
   gtk_widget_set_halign (child, GTK_ALIGN_FILL);
   gtk_widget_set_valign (child, GTK_ALIGN_START);
-  gtk_overlay_add (GTK_OVERLAY (overlay), child);
+  gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child);
   g_object_set (child, "margin", 4, NULL);
 
   return win;
@@ -176,7 +176,7 @@ test_scrolling (void)
   child = gtk_label_new ("This should be visible");
   gtk_widget_set_halign (child, GTK_ALIGN_CENTER);
   gtk_widget_set_valign (child, GTK_ALIGN_END);
-  gtk_overlay_add (GTK_OVERLAY (overlay), child);
+  gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child);
   g_object_set (child, "margin", 4, NULL);
 
   return win;
@@ -318,7 +318,7 @@ test_chase (void)
   child = gtk_label_new ("Try to enter");
   gtk_widget_set_halign (child, GTK_ALIGN_START);
   gtk_widget_set_valign (child, GTK_ALIGN_END);
-  gtk_overlay_add (GTK_OVERLAY (overlay), child);
+  gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child);
   g_object_set (child, "margin", 4, NULL);
 
   g_signal_connect (overlay, "enter-notify-event",
@@ -326,6 +326,54 @@ test_chase (void)
   return win;
 }
 
+static GtkWidget *
+test_stacking (void)
+{
+  GtkWidget *win;
+  GtkWidget *overlay;
+  GtkWidget *main_child;
+  GtkWidget *label;
+  GtkWidget *child;
+  GtkWidget *grid;
+  GtkWidget *check1;
+  GtkWidget *check2;
+  GdkRGBA color;
+
+  win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+  gtk_window_set_title (GTK_WINDOW (win), "Stacking");
+
+  grid = gtk_grid_new ();
+  overlay = gtk_overlay_new ();
+  main_child = gtk_event_box_new ();
+  gdk_rgba_parse (&color, "green");
+  gtk_widget_override_background_color (main_child, 0, &color);
+  gtk_widget_set_hexpand (main_child, TRUE);
+  gtk_widget_set_vexpand (main_child, TRUE);
+  label = gtk_label_new ("Main child");
+  child = gtk_label_new ("Overlay");
+  gtk_widget_set_halign (child, GTK_ALIGN_END);
+  gtk_widget_set_valign (child, GTK_ALIGN_END);
+
+  check1 = gtk_check_button_new_with_label ("Show main");
+  g_object_bind_property (main_child, "visible", check1, "active", G_BINDING_BIDIRECTIONAL);
+
+  check2 = gtk_check_button_new_with_label ("Show overlay");
+  g_object_bind_property (child, "visible", check2, "active", G_BINDING_BIDIRECTIONAL);
+  gtk_container_add (GTK_CONTAINER (main_child), label);
+  gtk_container_add (GTK_CONTAINER (overlay), main_child);
+  gtk_overlay_add_overlay (GTK_OVERLAY (overlay), child);
+  gtk_grid_attach (GTK_GRID (grid), overlay, 1, 0, 1, 3);
+  gtk_container_add (GTK_CONTAINER (win), grid);
+
+  gtk_grid_attach (GTK_GRID (grid), check1, 0, 0, 1, 1);
+  gtk_grid_attach (GTK_GRID (grid), check2, 0, 1, 1, 1);
+  child = gtk_label_new ("");
+  gtk_widget_set_vexpand (child, TRUE);
+  gtk_grid_attach (GTK_GRID (grid), child, 0, 2, 1, 1);
+
+  return win;
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -335,6 +383,7 @@ main (int argc, char *argv[])
   GtkWidget *win4;
   GtkWidget *win5;
   GtkWidget *win6;
+  GtkWidget *win7;
 
   gtk_init (&argc, &argv);
 
@@ -361,6 +410,9 @@ main (int argc, char *argv[])
   win6 = test_chase ();
   gtk_widget_show_all (win6);
 
+  win7 = test_stacking ();
+  gtk_widget_show_all (win7);
+
   gtk_main ();
 
   return 0;



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