[gtk/bin-removal: 54/59] gtk-demo: Port blur demo from GtkBin



commit cba31dd5bbb3c89254efcd340c2f9f5313ec853b
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun May 3 16:32:33 2020 -0400

    gtk-demo: Port blur demo from GtkBin

 demos/gtk-demo/bluroverlay.c | 70 ++++++++++++++++----------------------------
 demos/gtk-demo/bluroverlay.h |  7 +++--
 demos/gtk-demo/transparent.c |  2 +-
 3 files changed, 32 insertions(+), 47 deletions(-)
---
diff --git a/demos/gtk-demo/bluroverlay.c b/demos/gtk-demo/bluroverlay.c
index b48747f78b..6436b3cad4 100644
--- a/demos/gtk-demo/bluroverlay.c
+++ b/demos/gtk-demo/bluroverlay.c
@@ -39,7 +39,7 @@ enum {
 static guint signals[LAST_SIGNAL] = { 0 };
 static GQuark child_data_quark = 0;
 
-G_DEFINE_TYPE (BlurOverlay, blur_overlay, GTK_TYPE_BIN)
+G_DEFINE_TYPE (BlurOverlay, blur_overlay, GTK_TYPE_WIDGET)
 
 static void
 blur_overlay_set_overlay_child (GtkWidget       *widget,
@@ -204,7 +204,7 @@ blur_overlay_size_allocate (GtkWidget *widget,
   GtkWidget *child;
   GtkWidget *main_widget;
 
-  main_widget = gtk_overlay_get_child (GTK_OVERLAY (overlay));
+  main_widget = overlay->main_widget;
   if (main_widget && gtk_widget_get_visible (main_widget))
     gtk_widget_size_allocate (main_widget,
                               &(GtkAllocation) {
@@ -290,43 +290,6 @@ blur_overlay_get_child_position (BlurOverlay    *overlay,
   return TRUE;
 }
 
-static void
-blur_overlay_add (GtkContainer *container,
-                  GtkWidget    *widget)
-{
-  BlurOverlay *overlay = BLUR_OVERLAY (container);
-  gtk_widget_insert_after (widget, GTK_WIDGET (container), NULL);
-  overlay->main_widget = widget;  
-}
-
-static void
-blur_overlay_remove (GtkContainer *container,
-                     GtkWidget    *widget)
-{
-  BlurOverlay *overlay = BLUR_OVERLAY (container);
-  gtk_widget_unparent (widget);
-  if (overlay->main_widget == widget)
-    overlay->main_widget = NULL;
-}
-
-static void
-blur_overlay_forall (GtkContainer *overlay,
-                    GtkCallback   callback,
-                    gpointer      callback_data)
-{
-  GtkWidget *child;
-
-  child = gtk_widget_get_first_child (GTK_WIDGET (overlay));
-  while (child != NULL)
-    {
-      GtkWidget *next = gtk_widget_get_next_sibling (child);
-
-      (* callback) (child, callback_data);
-
-      child = next;
-    }
-}
-
 static void
 blur_overlay_snapshot (GtkWidget   *widget,
                       GtkSnapshot *snapshot)
@@ -420,21 +383,32 @@ blur_overlay_snapshot (GtkWidget   *widget,
   gsk_render_node_unref (main_widget_node);
 }
 
+static void
+blur_overlay_dispose (GObject *object)
+{
+  BlurOverlay *overlay = BLUR_OVERLAY (object);
+  GtkWidget *child;
+
+  g_clear_pointer (&overlay->main_widget, gtk_widget_unparent);
+
+  while ((child = gtk_widget_get_first_child (GTK_WIDGET (overlay))))
+    gtk_widget_unparent (child);
+
+  G_OBJECT_CLASS (blur_overlay_parent_class)->dispose (object);
+}
+
 static void
 blur_overlay_class_init (BlurOverlayClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
-  GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
+
+  object_class->dispose = blur_overlay_dispose;
 
   widget_class->measure = blur_overlay_measure;
   widget_class->size_allocate = blur_overlay_size_allocate;
   widget_class->snapshot = blur_overlay_snapshot;
 
-  container_class->add = blur_overlay_add;
-  container_class->remove = blur_overlay_remove;
-  container_class->forall = blur_overlay_forall;
-
   klass->get_child_position = blur_overlay_get_child_position;
 
   signals[GET_CHILD_POSITION] =
@@ -477,3 +451,11 @@ blur_overlay_add_overlay (BlurOverlay *overlay,
 
   blur_overlay_set_overlay_child (widget, child);
 }
+
+void
+blur_overlay_set_child (BlurOverlay *overlay,
+                        GtkWidget   *widget)
+{
+  gtk_widget_insert_after (widget, GTK_WIDGET (overlay), NULL);
+  overlay->main_widget = widget;
+}
diff --git a/demos/gtk-demo/bluroverlay.h b/demos/gtk-demo/bluroverlay.h
index e3fc27c7a8..57aa1fb757 100644
--- a/demos/gtk-demo/bluroverlay.h
+++ b/demos/gtk-demo/bluroverlay.h
@@ -37,14 +37,14 @@ typedef struct _BlurOverlayClass    BlurOverlayClass;
 
 struct _BlurOverlay
 {
-  GtkBin parent_instance;
+  GtkWidget parent_instance;
 
   GtkWidget *main_widget;
 };
 
 struct _BlurOverlayClass
 {
-  GtkBinClass parent_class;
+  GtkWidgetClass parent_class;
 
   gboolean (*get_child_position) (BlurOverlay   *overlay,
                                   GtkWidget     *widget,
@@ -59,6 +59,9 @@ GDK_AVAILABLE_IN_ALL
 void       blur_overlay_add_overlay (BlurOverlay *overlay,
                                      GtkWidget   *widget,
                                      double       blur);
+GDK_AVAILABLE_IN_ALL
+void       blur_overlay_set_child   (BlurOverlay *overlay,
+                                     GtkWidget   *widget);
 
 G_END_DECLS
 
diff --git a/demos/gtk-demo/transparent.c b/demos/gtk-demo/transparent.c
index f53dabed24..6d2c010c10 100644
--- a/demos/gtk-demo/transparent.c
+++ b/demos/gtk-demo/transparent.c
@@ -58,7 +58,7 @@ do_transparent (GtkWidget *do_widget)
       blur_overlay_add_overlay (BLUR_OVERLAY (overlay), button, 5.0);
 
       picture = gtk_picture_new_for_resource ("/transparent/portland-rose.jpg");
-      gtk_overlay_set_child (GTK_OVERLAY (overlay), picture);
+      blur_overlay_set_child (BLUR_OVERLAY (overlay), picture);
     }
 
   if (!gtk_widget_get_visible (window))


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