[gtk+/overlay] overlay: reduce and simplify to the core



commit e66099f14940ea67043fcbf90b4fe2202e8d8039
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Jun 11 20:11:05 2011 -0400

    overlay: reduce and simplify to the core
    
    We drop the relative_widget, since it is somewhat problematic, and
    not easy to fully support. Instead, we special-case the one important
    case of the child being a scrolled window. We may bring back custom
    positioning support in the form of a signal later.
    
    Also remove the offset and use the child widgets margins for this
    purpose.

 gtk/gtkoverlay.c    |  422 +++++---------------------------------------------
 gtk/gtkoverlay.h    |   24 +---
 tests/testoverlay.c |   47 ++----
 3 files changed, 64 insertions(+), 429 deletions(-)
---
diff --git a/gtk/gtkoverlay.c b/gtk/gtkoverlay.c
index 064cf9a..b815ff5 100644
--- a/gtk/gtkoverlay.c
+++ b/gtk/gtkoverlay.c
@@ -24,6 +24,7 @@
 
 #include "gtkoverlay.h"
 #include "gtkbuildable.h"
+#include "gtkscrolledwindow.h"
 
 #include "gtkprivate.h"
 #include "gtkintl.h"
@@ -41,8 +42,7 @@
  * main widget, whereas an overlay with halign set to %GTK_ALIGN_CENTER
  * and valign set to %GTK_ALIGN_END will be placed a the bottom edge of
  * the main widget, horizontally centered. The position can be adjusted
- * by setting the #GtkOverlay::x-offset and #GtkOverlay::y-offset child
- * properties to non-zero values.
+ * by setting the margin properties of the child to non-zero values.
  *
  * <refsect2 id="GtkOverlay-BUILDER-UI">
  * <title>GtkOverlay as GtkBuildable</title>
@@ -56,7 +56,6 @@
 
 struct _GtkOverlayPrivate
 {
-  GtkWidget *relative_widget;
   GSList    *children;
 };
 
@@ -66,21 +65,6 @@ struct _GtkOverlayChild
 {
   GtkWidget *widget;
   GdkWindow *window;
-  gint x_offset;
-  gint y_offset;
-};
-
-enum
-{
-  PROP_0,
-  PROP_RELATIVE_WIDGET
-};
-
-enum
-{
-  CHILD_PROP_0,
-  CHILD_PROP_X_OFFSET,
-  CHILD_PROP_Y_OFFSET
 };
 
 static void gtk_overlay_buildable_init (GtkBuildableIface *iface);
@@ -89,25 +73,6 @@ G_DEFINE_TYPE_WITH_CODE (GtkOverlay, gtk_overlay, GTK_TYPE_BIN,
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
                                                 gtk_overlay_buildable_init))
 
-static GtkOverlayChild *
-get_child (GtkOverlay *overlay,
-           GtkWidget  *widget)
-{
-  GtkOverlayPrivate *priv = overlay->priv;
-  GtkOverlayChild *child;
-  GSList *children;
-
-  for (children = priv->children; children; children = children->next)
-    {
-      child = children->data;
-
-      if (child->widget == widget)
-        return child;
-    }
-
-  return NULL;
-}
-
 static GdkWindow *
 gtk_overlay_create_child_window (GtkOverlay *overlay,
                                  GtkWidget  *child)
@@ -140,73 +105,36 @@ gtk_overlay_create_child_window (GtkOverlay *overlay,
 }
 
 static void
-gtk_overlay_get_property (GObject    *object,
-                          guint       prop_id,
-                          GValue     *value,
-                          GParamSpec *pspec)
-{
-  GtkOverlay *overlay = GTK_OVERLAY (object);
-  GtkOverlayPrivate *priv = overlay->priv;
-
-  switch (prop_id)
-    {
-    case PROP_RELATIVE_WIDGET:
-      g_value_set_object (value, priv->relative_widget);
-      break;
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-      break;
-    }
-}
-
-static void
-gtk_overlay_set_property (GObject      *object,
-                          guint         prop_id,
-                          const GValue *value,
-                          GParamSpec   *pspec)
-{
-  GtkOverlay *overlay = GTK_OVERLAY (object);
-  GtkOverlayPrivate *priv = overlay->priv;
-
-  switch (prop_id)
-    {
-    case PROP_RELATIVE_WIDGET:
-      {
-        GtkWidget *relative_widget;
-        GtkWidget *main_widget;
-
-        relative_widget = g_value_get_object (value);
-
-        main_widget = gtk_bin_get_child (GTK_BIN (object));
-        if (main_widget != NULL &&
-            relative_widget != NULL &&
-            !gtk_widget_is_ancestor (relative_widget, main_widget))
-          {
-            g_warning ("relative_widget must be a child of the main widget");
-            break;
-          }
-        priv->relative_widget = relative_widget;
-        gtk_widget_queue_resize (GTK_WIDGET (overlay));
-      }
-      break;
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-      break;
-    }
-}
-
-static void
-gtk_overlay_child_allocate (GtkWidget           *child,
-                            GdkWindow           *child_window, /* can be NULL */
-                            const GtkAllocation *window_allocation,
-                            GtkAllocation       *child_allocation)
+gtk_overlay_child_allocate (GtkOverlayChild *child,
+                            GtkAllocation   *allocation)
 {
-  if (child_window)
-    gdk_window_move_resize (child_window,
-                            window_allocation->x, window_allocation->y,
-                            window_allocation->width, window_allocation->height);
+  gint left, right, top, bottom;
+  GtkAllocation child_allocation;
 
-  gtk_widget_size_allocate (child, child_allocation);
+  /* put the margins outside the window; also arrange things
+   * so that the adjusted child allocation still ends up at 0, 0
+   */
+  left = gtk_widget_get_margin_left (child->widget);
+  right = gtk_widget_get_margin_right (child->widget);
+  top = gtk_widget_get_margin_top (child->widget);
+  bottom = gtk_widget_get_margin_bottom (child->widget);
+
+  child_allocation.x = - left;
+  child_allocation.y = - top;
+  child_allocation.width = allocation->width;
+  child_allocation.height = allocation->height;
+
+  allocation->x += left;
+  allocation->y += top;
+  allocation->width -= left + right;
+  allocation->height -= top + bottom;
+
+  if (child->window)
+    gdk_window_move_resize (child->window,
+                            allocation->x, allocation->y,
+                            allocation->width, allocation->height);
+
+  gtk_widget_size_allocate (child->widget, &child_allocation);
 }
 
 static GtkAlign
@@ -275,22 +203,24 @@ gtk_overlay_size_allocate (GtkWidget     *widget,
 
   GTK_WIDGET_CLASS (gtk_overlay_parent_class)->size_allocate (widget, allocation);
 
-  main_widget = gtk_bin_get_child (GTK_BIN (widget));
+  main_widget = gtk_bin_get_child (GTK_BIN (overlay));
   if (main_widget == NULL)
     return;
 
   gtk_widget_size_allocate (main_widget, allocation);
 
-  /* if a relative widget exists place the floating widgets in relation to it */
-  if (priv->relative_widget)
+  /* special-case scrolled windows */
+  if (GTK_IS_SCROLLED_WINDOW (main_widget))
     {
+      GtkWidget *grandchild;
       gint x, y;
 
-      gtk_widget_translate_coordinates (priv->relative_widget, main_widget, 0, 0, &x, &y);
+      grandchild = gtk_bin_get_child (GTK_BIN (main_widget));
+      gtk_widget_translate_coordinates (grandchild, main_widget, 0, 0, &x, &y);
       main_alloc.x = allocation->x + x;
       main_alloc.y = allocation->y + y;
-      main_alloc.width = gtk_widget_get_allocated_width (priv->relative_widget);
-      main_alloc.height = gtk_widget_get_allocated_height (priv->relative_widget);
+      main_alloc.width = gtk_widget_get_allocated_width (grandchild);
+      main_alloc.height = gtk_widget_get_allocated_height (grandchild);
     }
   else
     {
@@ -300,10 +230,10 @@ gtk_overlay_size_allocate (GtkWidget     *widget,
       main_alloc.height = allocation->height;
     }
 
-  for (children = priv->children; children; children = g_slist_next (children))
+  for (children = priv->children; children; children = children->next)
     {
       GtkRequisition req;
-      GtkAllocation alloc, child_alloc;
+      GtkAllocation alloc;
       GtkAlign halign;
       GtkTextDirection direction;
 
@@ -319,11 +249,6 @@ gtk_overlay_size_allocate (GtkWidget     *widget,
 
       direction = gtk_widget_get_direction (child->widget);
 
-      if (direction == GTK_TEXT_DIR_RTL)
-        alloc.x -= child->x_offset;
-      else
-        alloc.x += child->x_offset;
-
       halign = gtk_widget_get_halign (child->widget);
       switch (effective_align (halign, direction))
         {
@@ -331,7 +256,7 @@ gtk_overlay_size_allocate (GtkWidget     *widget,
           /* nothing to do */
           break;
         case GTK_ALIGN_FILL:
-          alloc.width = main_alloc.width - 2 * child->x_offset;
+          alloc.width = main_alloc.width;
           break;
         case GTK_ALIGN_CENTER:
           alloc.x += main_alloc.width / 2 - req.width / 2;
@@ -344,15 +269,13 @@ gtk_overlay_size_allocate (GtkWidget     *widget,
       alloc.y = main_alloc.y;
       alloc.height = MIN (main_alloc.height, req.height);
 
-      alloc.y += child->y_offset;
-
       switch (gtk_widget_get_valign (child->widget))
         {
         case GTK_ALIGN_START:
           /* nothing to do */
           break;
         case GTK_ALIGN_FILL:
-          alloc.height = main_alloc.height - 2 * child->y_offset;
+          alloc.height = main_alloc.height;
           break;
         case GTK_ALIGN_CENTER:
           alloc.y += main_alloc.height / 2 - req.height / 2;
@@ -362,12 +285,7 @@ gtk_overlay_size_allocate (GtkWidget     *widget,
           break;
         }
 
-      child_alloc.x = 0;
-      child_alloc.y = 0;
-      child_alloc.width = alloc.width;
-      child_alloc.height = alloc.height;
-
-      gtk_overlay_child_allocate (child->widget, child->window, &alloc, &child_alloc);
+      gtk_overlay_child_allocate (child, &alloc);
     }
 }
 
@@ -484,33 +402,6 @@ gtk_overlay_draw (GtkWidget *widget,
 }
 
 static void
-overlay_add (GtkContainer *container,
-             GtkWidget    *widget)
-{
-  GtkOverlay *overlay = GTK_OVERLAY (container);
-  GtkOverlayPrivate *priv = overlay->priv;
-  GtkWidget *main_widget;
-
-  GTK_CONTAINER_CLASS (gtk_overlay_parent_class)->add (container, widget);
-
-  /* if we have a previously added relative widget, we must
-   * check that it is still valid
-   */
-  main_widget = gtk_bin_get_child (GTK_BIN (container));
-  if (main_widget != NULL &&
-      priv->relative_widget != NULL &&
-      !gtk_widget_is_ancestor (priv->relative_widget, main_widget))
-    {
-      g_warning ("The previously relative widget with type %s is not compatible "
-                 "with the new main widget added %s, the relative widget will "
-                 "be unset before continue",
-                 g_type_name (G_OBJECT_TYPE (priv->relative_widget)),
-                 g_type_name (G_OBJECT_TYPE (widget)));
-      gtk_overlay_set_relative_widget (overlay, NULL);
-    }
-}
-
-static void
 gtk_overlay_remove (GtkContainer *container,
                     GtkWidget    *widget)
 {
@@ -568,101 +459,12 @@ gtk_overlay_forall (GtkContainer *overlay,
 }
 
 static void
-gtk_overlay_set_offset_internal (GtkOverlay      *overlay,
-                                 GtkOverlayChild *child,
-                                 gint             x_offset,
-                                 gint             y_offset)
-{
-  g_return_if_fail (gtk_widget_get_parent (child->widget) == GTK_WIDGET (overlay));
-
-  gtk_widget_freeze_child_notify (child->widget);
-
-  if (child->x_offset != x_offset)
-    {
-      child->x_offset = x_offset;
-      gtk_widget_child_notify (child->widget, "x-offset");
-    }
-
-  if (child->y_offset != y_offset)
-    {
-      child->y_offset = y_offset;
-      gtk_widget_child_notify (child->widget, "y-offset");
-    }
-
-  gtk_widget_thaw_child_notify (child->widget);
-
-  if (gtk_widget_get_visible (child->widget) &&
-      gtk_widget_get_visible (GTK_WIDGET (overlay)))
-    gtk_widget_queue_resize (GTK_WIDGET (overlay));
-}
-
-static void
-gtk_overlay_set_child_property (GtkContainer *container,
-                                GtkWidget    *child,
-                                guint         property_id,
-                                const GValue *value,
-                                GParamSpec   *pspec)
-{
-  GtkOverlay *overlay = GTK_OVERLAY (container);
-  GtkOverlayChild *overlay_child;
-
-  overlay_child = get_child (overlay, child);
-
-  switch (property_id)
-    {
-    case CHILD_PROP_X_OFFSET:
-      gtk_overlay_set_offset_internal (overlay,
-                                       overlay_child,
-                                       g_value_get_int (value),
-                                       overlay_child->y_offset);
-      break;
-    case CHILD_PROP_Y_OFFSET:
-      gtk_overlay_set_offset_internal (overlay,
-                                       overlay_child,
-                                       overlay_child->x_offset,
-                                       g_value_get_int (value));
-      break;
-    default:
-      GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
-      break;
-    }
-}
-
-static void
-gtk_overlay_get_child_property (GtkContainer *container,
-                                GtkWidget    *child,
-                                guint         property_id,
-                                GValue       *value,
-                                GParamSpec   *pspec)
-{
-  GtkOverlayChild *overlay_child;
-
-  overlay_child = get_child (GTK_OVERLAY (container), child);
-
-  switch (property_id)
-    {
-    case CHILD_PROP_X_OFFSET:
-      g_value_set_int (value, overlay_child->x_offset);
-      break;
-    case CHILD_PROP_Y_OFFSET:
-      g_value_set_int (value, overlay_child->y_offset);
-      break;
-    default:
-      GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID (container, property_id, pspec);
-      break;
-    }
-}
-
-static void
 gtk_overlay_class_init (GtkOverlayClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
   GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
 
-  object_class->get_property = gtk_overlay_get_property;
-  object_class->set_property = gtk_overlay_set_property;
-
   widget_class->get_preferred_width = gtk_overlay_get_preferred_width;
   widget_class->get_preferred_height = gtk_overlay_get_preferred_height;
   widget_class->size_allocate = gtk_overlay_size_allocate;
@@ -672,43 +474,8 @@ gtk_overlay_class_init (GtkOverlayClass *klass)
   widget_class->unmap = gtk_overlay_unmap;
   widget_class->draw = gtk_overlay_draw;
 
-  container_class->add = overlay_add;
   container_class->remove = gtk_overlay_remove;
   container_class->forall = gtk_overlay_forall;
-  container_class->set_child_property = gtk_overlay_set_child_property;
-  container_class->get_child_property = gtk_overlay_get_child_property;
-
-  /**
-   * GtkOverlay:relative-widget
-   *
-   * Widget where the floating widgets will be placed. This widget must be
-   * a child of the main widget added to #GtkOverlay
-   *
-   * Since: 3.2
-   */
-  g_object_class_install_property (object_class, PROP_RELATIVE_WIDGET,
-                                   g_param_spec_object ("relative-widget",
-                                                        "Relative Widget",
-                                                        "Widget on which the floating widgets are placed",
-                                                        GTK_TYPE_WIDGET,
-                                                        G_PARAM_READWRITE |
-                                                        G_PARAM_STATIC_STRINGS));
-
-  gtk_container_class_install_child_property (container_class,
-                                              CHILD_PROP_X_OFFSET,
-                                              g_param_spec_int ("x-offset",
-                                                                P_("X Offset"),
-                                                                P_("The x offset of child widget"),
-                                                                G_MININT, G_MAXINT, 0,
-                                                                GTK_PARAM_READWRITE));
-
-  gtk_container_class_install_child_property (container_class,
-                                              CHILD_PROP_Y_OFFSET,
-                                              g_param_spec_int ("y-offset",
-                                                                P_("Y Offset"),
-                                                                P_("The y offset of child widget"),
-                                                                G_MININT, G_MAXINT, 0,
-                                                                GTK_PARAM_READWRITE));
 
   g_type_class_add_private (object_class, sizeof (GtkOverlayPrivate));
 }
@@ -757,53 +524,6 @@ gtk_overlay_new (void)
 }
 
 /**
- * gtk_overlay_set_relative_widget:
- * @overlay: a #GtkOverlay
- * @relative_widget: (allow-none): a child of the main widget, or %NULL
- *
- * Sets the relative widget where static widgets will be placed.
- *
- * This widget must be a child of the widget added by
- * gtk_container_add().
- *
- * Since: 3.2
- */
-void
-gtk_overlay_set_relative_widget (GtkOverlay *overlay,
-                                 GtkWidget  *relative_widget)
-{
-  GtkOverlayPrivate *priv;
-
-  g_return_if_fail (GTK_IS_OVERLAY (overlay));
-
-  priv = overlay->priv;
-
-  if (priv->relative_widget != relative_widget)
-    {
-      priv->relative_widget = relative_widget;
-
-      g_object_notify (G_OBJECT (overlay), "relative-widget");
-    }
-}
-
-/**
- * gtk_overlay_get_relative_widget:
- * @overlay: a #GtkOverlay
- *
- * Gets the relative widget to the main widget added
- * by gtk_container_add().
- *
- * Since: 3.2
- */
-GtkWidget *
-gtk_overlay_get_relative_widget (GtkOverlay *overlay)
-{
-  g_return_val_if_fail (GTK_IS_OVERLAY (overlay), NULL);
-
-  return overlay->priv->relative_widget;
-}
-
-/**
  * gtk_overlay_add:
  * @overlay: a #GtkOverlay
  * @widget: a #GtkWidget to be added to the container
@@ -837,59 +557,3 @@ gtk_overlay_add (GtkOverlay *overlay,
   if (gtk_widget_get_realized (GTK_WIDGET (overlay)))
     child->window = gtk_overlay_create_child_window (overlay, widget);
 }
-
-/**
- * gtk_overlay_set_offset:
- * @overlay: a #GtkOverlay
- * @widget: a child of @overlay
- * @x_offset: the new x offset for @widget
- * @y_offset: the new y offset for @widget
- *
- * Sets the offset for @widget.
- *
- * Since: 3.2
- */
-void
-gtk_overlay_set_offset (GtkOverlay *overlay,
-                        GtkWidget  *widget,
-                        gint        x_offset,
-                        gint        y_offset)
-{
-  GtkOverlayChild *child;
-
-  g_return_if_fail (GTK_IS_OVERLAY (overlay));
-
-  child = get_child (overlay, widget);
-
-  gtk_overlay_set_offset_internal (overlay, child, x_offset, y_offset);
-}
-
-/**
- * gtk_overlay_get_offset:
- * @overlay: a #GtkOverlay
- * @widget: a child of @overlay
- * @x_offset: (out) (allow-none): returns the x offset of @widget
- * @y_offset: (out) (allow-none): returns the y offset of @widget
- *
- * Gets the offset for @widget.
- *
- * Since: 3.2
- */
-void
-gtk_overlay_get_offset (GtkOverlay *overlay,
-                        GtkWidget  *widget,
-                        gint       *x_offset,
-                        gint       *y_offset)
-{
-  GtkOverlayChild *child;
-
-  g_return_if_fail (GTK_IS_OVERLAY (overlay));
-
-  child = get_child (overlay, widget);
-
-  if (x_offset != NULL)
-    *x_offset = child->x_offset;
-
-  if (y_offset != NULL)
-    *y_offset = child->y_offset;
-}
diff --git a/gtk/gtkoverlay.h b/gtk/gtkoverlay.h
index 604b844..593eefb 100644
--- a/gtk/gtkoverlay.h
+++ b/gtk/gtkoverlay.h
@@ -64,27 +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_set_relative_widget (GtkOverlay *overlay,
-                                            GtkWidget  *relative_widget);
-
-GtkWidget *gtk_overlay_get_relative_widget (GtkOverlay *overlay);
-
-void       gtk_overlay_add                 (GtkOverlay *overlay,
-                                            GtkWidget  *widget);
-
-void       gtk_overlay_set_offset          (GtkOverlay *overlay,
-                                            GtkWidget  *widget,
-                                            gint        x_offset,
-                                            gint        y_offset);
-
-void       gtk_overlay_get_offset          (GtkOverlay *overlay,
-                                            GtkWidget  *widget,
-                                            gint       *x_offset,
-                                            gint       *y_offset);
+GtkWidget *gtk_overlay_new      (void);
+void       gtk_overlay_add      (GtkOverlay *overlay,
+                                 GtkWidget  *widget);
 
 G_END_DECLS
 
diff --git a/tests/testoverlay.c b/tests/testoverlay.c
index 83acfe6..154fc4a 100644
--- a/tests/testoverlay.c
+++ b/tests/testoverlay.c
@@ -18,10 +18,7 @@ test_nonzerox (void)
   gtk_window_set_title (GTK_WINDOW (win), "Non-zero X");
 
   grid = gtk_grid_new ();
-  gtk_widget_set_margin_top (grid, 5);
-  gtk_widget_set_margin_bottom (grid, 5);
-  gtk_widget_set_margin_left (grid, 5);
-  gtk_widget_set_margin_right (grid, 5);
+  g_object_set (grid, "margin", 5, NULL);
   gtk_container_add (GTK_CONTAINER (win), grid);
   gtk_grid_attach (GTK_GRID (grid), gtk_label_new ("Above"), 1, 0, 1, 1);
   gtk_grid_attach (GTK_GRID (grid), gtk_label_new ("Below"), 1, 2, 1, 1);
@@ -42,18 +39,19 @@ test_nonzerox (void)
   child = gtk_label_new ("I'm the overlay");
   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_set_offset (GTK_OVERLAY (overlay), child, 1, 1);
 
   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_set_offset (GTK_OVERLAY (overlay), child, -1, -1);
+  g_object_set (child, "margin", 3, NULL);
 
   return win;
 }
 
+#if 0
 /* test that margins and non-zero allocation x/y
  * of the relative widget are handled correctly
  */
@@ -84,10 +82,7 @@ test_relative (void)
 
   text = gtk_text_view_new ();
   gtk_widget_set_size_request (text, 200, 200);
-  gtk_widget_set_margin_top (text, 5);
-  gtk_widget_set_margin_bottom (text, 5);
-  gtk_widget_set_margin_left (text, 5);
-  gtk_widget_set_margin_right (text, 5);
+  g_object_set (text, "margin", 5, NULL);
   gtk_widget_set_hexpand (text, TRUE);
   gtk_widget_set_vexpand (text, TRUE);
   gtk_grid_attach (GTK_GRID (grid), text, 1, 1, 1, 1);
@@ -97,16 +92,17 @@ test_relative (void)
   gtk_widget_set_halign (child, GTK_ALIGN_START);
   gtk_widget_set_valign (child, GTK_ALIGN_START);
   gtk_overlay_add (GTK_OVERLAY (overlay), child);
-  gtk_overlay_set_offset (GTK_OVERLAY (overlay), child, 1, 1);
+  g_object_set (child, "margin", 1, NULL);
 
   child = gtk_label_new ("Bottom right 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_set_offset (GTK_OVERLAY (overlay), child, -1, -1);
+  g_object_set (child, "margin", 1, NULL);
 
   return win;
 }
+#endif
 
 /* test GTK_ALIGN_FILL handling */
 static GtkWidget *
@@ -133,7 +129,7 @@ test_fullwidth (void)
   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_set_offset (GTK_OVERLAY (overlay), child, 4, 4);
+  g_object_set (child, "margin", 4, NULL);
 
   return win;
 }
@@ -176,13 +172,12 @@ test_scrolling (void)
   gtk_widget_set_hexpand (text, TRUE);
   gtk_widget_set_vexpand (text, TRUE);
   gtk_container_add (GTK_CONTAINER (sw), text);
-  gtk_overlay_set_relative_widget (GTK_OVERLAY (overlay), text);
 
   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_set_offset (GTK_OVERLAY (overlay), child, 0, -4);
+  g_object_set (child, "margin", 4, NULL);
 
   return win;
 }
@@ -193,17 +188,14 @@ static const gchar *buffer =
 "    <property name='title'>GtkBuilder support</property>"
 "    <child>"
 "      <object class='GtkOverlay' id='overlay'>"
-"        <property name='relative_widget'>text</property>"
+"<!--        <property name='relative_widget'>text</property> -->"
 "        <child type='overlay'>"
 "          <object class='GtkLabel' id='overlay-child'>"
 "            <property name='label'>Witty remark goes here</property>"
 "            <property name='halign'>end</property>"
 "            <property name='valign'>end</property>"
+"            <property name='margin'>4</property>"
 "          </object>"
-"          <packing>"
-"            <property name='x-offset'>-2</property>"
-"            <property name='y-offset'>-2</property>"
-"          </packing>"
 "        </child>"
 "        <child>"
 "          <object class='GtkGrid' id='grid'>"
@@ -277,15 +269,9 @@ on_enter (GtkWidget *overlay, GdkEventCrossing *event, GtkWidget *child)
     return;
 
   if (gtk_widget_get_halign (child) == GTK_ALIGN_START)
-    {
-      gtk_overlay_set_offset (GTK_OVERLAY (overlay), child, -4, -4);
-      gtk_widget_set_halign (child, GTK_ALIGN_END);
-    }
+    gtk_widget_set_halign (child, GTK_ALIGN_END);
   else
-    {
-      gtk_overlay_set_offset (GTK_OVERLAY (overlay), child, 4, -4);
-      gtk_widget_set_halign (child, GTK_ALIGN_START);
-    }
+    gtk_widget_set_halign (child, GTK_ALIGN_START);
 
   gtk_widget_queue_resize (overlay);
 }
@@ -328,13 +314,12 @@ test_chase (void)
   gtk_widget_set_hexpand (text, TRUE);
   gtk_widget_set_vexpand (text, TRUE);
   gtk_container_add (GTK_CONTAINER (sw), text);
-  gtk_overlay_set_relative_widget (GTK_OVERLAY (overlay), text);
 
   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_set_offset (GTK_OVERLAY (overlay), child, 4, -4);
+  g_object_set (child, "margin", 4, NULL);
 
   g_signal_connect (overlay, "enter-notify-event",
                     G_CALLBACK (on_enter), child);
@@ -359,8 +344,10 @@ main (int argc, char *argv[])
   win1 = test_nonzerox ();
   gtk_widget_show_all (win1);
 
+#if 0
   win2 = test_relative ();
   gtk_widget_show_all (win2);
+#endif
 
   win3 = test_fullwidth ();
   gtk_widget_show_all (win3);



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