2011-05-19 16:53:05 +00:00
|
|
|
|
/*
|
|
|
|
|
* gtkoverlay.c
|
|
|
|
|
* This file is part of gtk
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2011 - Ignacio Casal Quinteiro, Mike Krüger
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2011-05-19 16:53:05 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include "gtkoverlay.h"
|
2019-03-16 03:48:26 +00:00
|
|
|
|
|
2020-05-25 18:22:10 +00:00
|
|
|
|
#include "gtkoverlaylayout.h"
|
2011-05-19 16:53:05 +00:00
|
|
|
|
#include "gtkbuildable.h"
|
2019-03-16 03:48:26 +00:00
|
|
|
|
#include "gtkintl.h"
|
2011-05-19 16:53:05 +00:00
|
|
|
|
#include "gtkmarshalers.h"
|
|
|
|
|
#include "gtkprivate.h"
|
2019-03-16 03:48:26 +00:00
|
|
|
|
#include "gtkscrolledwindow.h"
|
|
|
|
|
#include "gtksnapshot.h"
|
|
|
|
|
#include "gtkwidgetprivate.h"
|
2011-05-19 16:53:05 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2021-02-27 23:18:30 +00:00
|
|
|
|
* GtkOverlay
|
2011-05-19 16:53:05 +00:00
|
|
|
|
*
|
2021-02-27 23:18:30 +00:00
|
|
|
|
* `GtkOverlay` is a container which contains a single main child, on top
|
|
|
|
|
* of which it can place “overlay” widgets.
|
|
|
|
|
*
|
|
|
|
|
* ![An example GtkOverlay](overlay.png)
|
|
|
|
|
*
|
|
|
|
|
* The position of each overlay widget is determined by its
|
|
|
|
|
* [property@Gtk.Widget:halign] and [property@Gtk.Widget:valign]
|
2015-08-21 22:19:26 +00:00
|
|
|
|
* properties. E.g. a widget with both alignments set to %GTK_ALIGN_START
|
2021-02-27 23:18:30 +00:00
|
|
|
|
* will be placed at the top left corner of the `GtkOverlay` container,
|
2015-08-21 22:19:26 +00:00
|
|
|
|
* whereas an overlay with halign set to %GTK_ALIGN_CENTER and valign set
|
2021-02-27 23:18:30 +00:00
|
|
|
|
* to %GTK_ALIGN_END will be placed a the bottom edge of the `GtkOverlay`,
|
2015-08-21 22:19:26 +00:00
|
|
|
|
* horizontally centered. The position can be adjusted by setting the margin
|
|
|
|
|
* properties of the child to non-zero values.
|
2011-05-19 16:53:05 +00:00
|
|
|
|
*
|
|
|
|
|
* More complicated placement of overlays is possible by connecting
|
2021-02-27 23:18:30 +00:00
|
|
|
|
* to the [signal@Gtk.Overlay::get-child-position] signal.
|
2011-05-19 16:53:05 +00:00
|
|
|
|
*
|
2021-02-27 23:18:30 +00:00
|
|
|
|
* An overlay’s minimum and natural sizes are those of its main child.
|
|
|
|
|
* The sizes of overlay children are not considered when measuring these
|
|
|
|
|
* preferred sizes.
|
2019-06-13 17:22:33 +00:00
|
|
|
|
*
|
2014-02-05 02:00:58 +00:00
|
|
|
|
* # GtkOverlay as GtkBuildable
|
2014-02-02 05:29:00 +00:00
|
|
|
|
*
|
2021-02-27 23:18:30 +00:00
|
|
|
|
* The `GtkOverlay` implementation of the `GtkBuildable` interface
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* supports placing a child as an overlay by specifying “overlay” as
|
2014-02-09 22:24:06 +00:00
|
|
|
|
* the “type” attribute of a `<child>` element.
|
2017-09-20 16:34:43 +00:00
|
|
|
|
*
|
|
|
|
|
* # CSS nodes
|
|
|
|
|
*
|
2021-02-27 23:18:30 +00:00
|
|
|
|
* `GtkOverlay` has a single CSS node with the name “overlay”. Overlay children
|
2017-09-20 16:34:43 +00:00
|
|
|
|
* whose alignments cause them to be positioned at an edge get the style classes
|
|
|
|
|
* “.left”, “.right”, “.top”, and/or “.bottom” according to their position.
|
2011-05-19 16:53:05 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
GET_CHILD_POSITION,
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
2020-05-03 14:31:09 +00:00
|
|
|
|
enum {
|
|
|
|
|
PROP_CHILD = 1
|
|
|
|
|
};
|
|
|
|
|
|
2011-05-19 16:53:05 +00:00
|
|
|
|
static void gtk_overlay_buildable_init (GtkBuildableIface *iface);
|
|
|
|
|
|
2020-04-26 19:37:47 +00:00
|
|
|
|
typedef struct _GtkOverlayClass GtkOverlayClass;
|
2019-05-27 21:35:24 +00:00
|
|
|
|
|
|
|
|
|
struct _GtkOverlay
|
|
|
|
|
{
|
2020-05-03 14:50:56 +00:00
|
|
|
|
GtkWidget parent_instance;
|
|
|
|
|
|
|
|
|
|
GtkWidget *child;
|
2019-05-27 21:35:24 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct _GtkOverlayClass
|
|
|
|
|
{
|
2020-05-03 14:50:56 +00:00
|
|
|
|
GtkWidgetClass parent_class;
|
2019-05-27 21:35:24 +00:00
|
|
|
|
|
|
|
|
|
gboolean (*get_child_position) (GtkOverlay *overlay,
|
|
|
|
|
GtkWidget *widget,
|
|
|
|
|
GtkAllocation *allocation);
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-03 14:50:56 +00:00
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkOverlay, gtk_overlay, GTK_TYPE_WIDGET,
|
2011-05-19 16:53:05 +00:00
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
|
|
|
|
|
gtk_overlay_buildable_init))
|
|
|
|
|
|
2012-02-03 20:33:30 +00:00
|
|
|
|
static GtkAlign
|
|
|
|
|
effective_align (GtkAlign align,
|
|
|
|
|
GtkTextDirection direction)
|
|
|
|
|
{
|
|
|
|
|
switch (align)
|
|
|
|
|
{
|
|
|
|
|
case GTK_ALIGN_START:
|
|
|
|
|
return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_END : GTK_ALIGN_START;
|
|
|
|
|
case GTK_ALIGN_END:
|
|
|
|
|
return direction == GTK_TEXT_DIR_RTL ? GTK_ALIGN_START : GTK_ALIGN_END;
|
2017-10-06 19:19:42 +00:00
|
|
|
|
case GTK_ALIGN_FILL:
|
|
|
|
|
case GTK_ALIGN_CENTER:
|
|
|
|
|
case GTK_ALIGN_BASELINE:
|
2012-02-03 20:33:30 +00:00
|
|
|
|
default:
|
|
|
|
|
return align;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-19 16:53:05 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
gtk_overlay_get_child_position (GtkOverlay *overlay,
|
|
|
|
|
GtkWidget *widget,
|
|
|
|
|
GtkAllocation *alloc)
|
|
|
|
|
{
|
2013-03-28 12:24:04 +00:00
|
|
|
|
GtkRequisition min, req;
|
2011-05-19 16:53:05 +00:00
|
|
|
|
GtkAlign halign;
|
|
|
|
|
GtkTextDirection direction;
|
2019-02-09 03:01:45 +00:00
|
|
|
|
int width, height;
|
2011-05-19 16:53:05 +00:00
|
|
|
|
|
2013-03-28 12:24:04 +00:00
|
|
|
|
gtk_widget_get_preferred_size (widget, &min, &req);
|
2019-02-09 03:01:45 +00:00
|
|
|
|
width = gtk_widget_get_width (GTK_WIDGET (overlay));
|
|
|
|
|
height = gtk_widget_get_height (GTK_WIDGET (overlay));
|
2011-05-19 16:53:05 +00:00
|
|
|
|
|
2019-02-09 03:01:45 +00:00
|
|
|
|
alloc->x = 0;
|
|
|
|
|
alloc->width = MAX (min.width, MIN (width, req.width));
|
2011-05-19 16:53:05 +00:00
|
|
|
|
|
2017-01-11 14:27:51 +00:00
|
|
|
|
direction = _gtk_widget_get_direction (widget);
|
2011-05-19 16:53:05 +00:00
|
|
|
|
|
|
|
|
|
halign = gtk_widget_get_halign (widget);
|
|
|
|
|
switch (effective_align (halign, direction))
|
|
|
|
|
{
|
|
|
|
|
case GTK_ALIGN_START:
|
|
|
|
|
/* nothing to do */
|
|
|
|
|
break;
|
|
|
|
|
case GTK_ALIGN_FILL:
|
2019-02-09 03:01:45 +00:00
|
|
|
|
alloc->width = MAX (alloc->width, width);
|
2011-05-19 16:53:05 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_ALIGN_CENTER:
|
2019-02-09 03:01:45 +00:00
|
|
|
|
alloc->x += width / 2 - alloc->width / 2;
|
2011-05-19 16:53:05 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_ALIGN_END:
|
2019-02-09 03:01:45 +00:00
|
|
|
|
alloc->x += width - alloc->width;
|
2011-05-19 16:53:05 +00:00
|
|
|
|
break;
|
2013-04-23 18:13:33 +00:00
|
|
|
|
case GTK_ALIGN_BASELINE:
|
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
break;
|
2011-05-19 16:53:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-09 03:01:45 +00:00
|
|
|
|
alloc->y = 0;
|
|
|
|
|
alloc->height = MAX (min.height, MIN (height, req.height));
|
2011-05-19 16:53:05 +00:00
|
|
|
|
|
|
|
|
|
switch (gtk_widget_get_valign (widget))
|
|
|
|
|
{
|
|
|
|
|
case GTK_ALIGN_START:
|
|
|
|
|
/* nothing to do */
|
|
|
|
|
break;
|
|
|
|
|
case GTK_ALIGN_FILL:
|
2019-02-09 03:01:45 +00:00
|
|
|
|
alloc->height = MAX (alloc->height, height);
|
2011-05-19 16:53:05 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_ALIGN_CENTER:
|
2019-02-09 03:01:45 +00:00
|
|
|
|
alloc->y += height / 2 - alloc->height / 2;
|
2011-05-19 16:53:05 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_ALIGN_END:
|
2019-02-09 03:01:45 +00:00
|
|
|
|
alloc->y += height - alloc->height;
|
2011-05-19 16:53:05 +00:00
|
|
|
|
break;
|
2013-04-23 18:13:33 +00:00
|
|
|
|
case GTK_ALIGN_BASELINE:
|
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
break;
|
2011-05-19 16:53:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-11 10:36:22 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_overlay_snapshot_child (GtkWidget *overlay,
|
|
|
|
|
GtkWidget *child,
|
|
|
|
|
GtkSnapshot *snapshot)
|
|
|
|
|
{
|
|
|
|
|
graphene_rect_t bounds;
|
|
|
|
|
gboolean clip_set;
|
|
|
|
|
|
|
|
|
|
clip_set = gtk_overlay_get_clip_overlay (GTK_OVERLAY (overlay), child);
|
|
|
|
|
|
|
|
|
|
if (!clip_set)
|
|
|
|
|
{
|
|
|
|
|
gtk_widget_snapshot_child (overlay, child, snapshot);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
graphene_rect_init (&bounds, 0, 0,
|
|
|
|
|
gtk_widget_get_width (overlay),
|
|
|
|
|
gtk_widget_get_height (overlay));
|
|
|
|
|
|
|
|
|
|
gtk_snapshot_push_clip (snapshot, &bounds);
|
|
|
|
|
gtk_widget_snapshot_child (overlay, child, snapshot);
|
|
|
|
|
gtk_snapshot_pop (snapshot);
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-03 00:42:47 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_overlay_snapshot (GtkWidget *widget,
|
|
|
|
|
GtkSnapshot *snapshot)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *child;
|
|
|
|
|
|
|
|
|
|
for (child = _gtk_widget_get_first_child (widget);
|
|
|
|
|
child != NULL;
|
|
|
|
|
child = _gtk_widget_get_next_sibling (child))
|
|
|
|
|
{
|
2019-02-22 00:39:42 +00:00
|
|
|
|
gtk_overlay_snapshot_child (widget, child, snapshot);
|
2017-09-03 00:42:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-15 15:20:18 +00:00
|
|
|
|
|
2020-05-03 14:31:09 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_overlay_get_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GtkOverlay *overlay = GTK_OVERLAY (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_CHILD:
|
|
|
|
|
g_value_set_object (value, gtk_overlay_get_child (overlay));
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_CHILD:
|
|
|
|
|
gtk_overlay_set_child (overlay, g_value_get_object (value));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-03 14:50:56 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_overlay_dispose (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
GtkOverlay *overlay = GTK_OVERLAY (object);
|
|
|
|
|
GtkWidget *child;
|
|
|
|
|
|
|
|
|
|
g_clear_pointer (&overlay->child, gtk_widget_unparent);
|
|
|
|
|
|
|
|
|
|
while ((child = gtk_widget_get_first_child (GTK_WIDGET (overlay))))
|
|
|
|
|
gtk_widget_unparent (child);
|
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_overlay_parent_class)->dispose (object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_overlay_compute_expand (GtkWidget *widget,
|
|
|
|
|
gboolean *hexpand,
|
|
|
|
|
gboolean *vexpand)
|
|
|
|
|
{
|
|
|
|
|
GtkOverlay *overlay = GTK_OVERLAY (widget);
|
|
|
|
|
|
|
|
|
|
if (overlay->child)
|
|
|
|
|
{
|
|
|
|
|
*hexpand = gtk_widget_compute_expand (overlay->child, GTK_ORIENTATION_HORIZONTAL);
|
|
|
|
|
*vexpand = gtk_widget_compute_expand (overlay->child, GTK_ORIENTATION_VERTICAL);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*hexpand = FALSE;
|
|
|
|
|
*vexpand = FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-19 16:53:05 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_overlay_class_init (GtkOverlayClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2020-05-03 14:50:56 +00:00
|
|
|
|
|
|
|
|
|
object_class->dispose = gtk_overlay_dispose;
|
2011-05-19 16:53:05 +00:00
|
|
|
|
|
2020-05-03 14:31:09 +00:00
|
|
|
|
object_class->get_property = gtk_overlay_get_property;
|
|
|
|
|
object_class->set_property = gtk_overlay_set_property;
|
|
|
|
|
|
2017-09-03 00:42:47 +00:00
|
|
|
|
widget_class->snapshot = gtk_overlay_snapshot;
|
2020-05-03 14:50:56 +00:00
|
|
|
|
widget_class->compute_expand = gtk_overlay_compute_expand;
|
2011-05-19 16:53:05 +00:00
|
|
|
|
|
|
|
|
|
klass->get_child_position = gtk_overlay_get_child_position;
|
|
|
|
|
|
2020-05-03 14:31:09 +00:00
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_CHILD,
|
2022-05-11 12:19:39 +00:00
|
|
|
|
g_param_spec_object ("child", NULL, NULL,
|
2020-05-03 14:31:09 +00:00
|
|
|
|
GTK_TYPE_WIDGET,
|
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
|
|
|
|
|
|
2011-05-19 16:53:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkOverlay::get-child-position:
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* @overlay: the `GtkOverlay`
|
2011-05-19 16:53:05 +00:00
|
|
|
|
* @widget: the child widget to position
|
2014-05-26 16:41:21 +00:00
|
|
|
|
* @allocation: (type Gdk.Rectangle) (out caller-allocates): return
|
|
|
|
|
* location for the allocation
|
2011-05-19 16:53:05 +00:00
|
|
|
|
*
|
2021-02-27 23:18:30 +00:00
|
|
|
|
* Emitted to determine the position and size of any overlay
|
|
|
|
|
* child widgets.
|
|
|
|
|
*
|
|
|
|
|
* A handler for this signal should fill @allocation with
|
2011-05-19 16:53:05 +00:00
|
|
|
|
* the desired position and size for @widget, relative to
|
|
|
|
|
* the 'main' child of @overlay.
|
|
|
|
|
*
|
|
|
|
|
* The default handler for this signal uses the @widget's
|
|
|
|
|
* halign and valign properties to determine the position
|
|
|
|
|
* and gives the widget its natural size (except that an
|
|
|
|
|
* alignment of %GTK_ALIGN_FILL will cause the overlay to
|
|
|
|
|
* be full-width/height). If the main child is a
|
2021-02-27 23:18:30 +00:00
|
|
|
|
* `GtkScrolledWindow`, the overlays are placed relative
|
2011-05-19 16:53:05 +00:00
|
|
|
|
* to its contents.
|
|
|
|
|
*
|
2014-07-10 15:52:44 +00:00
|
|
|
|
* Returns: %TRUE if the @allocation has been filled
|
2011-05-19 16:53:05 +00:00
|
|
|
|
*/
|
|
|
|
|
signals[GET_CHILD_POSITION] =
|
|
|
|
|
g_signal_new (I_("get-child-position"),
|
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkOverlayClass, get_child_position),
|
|
|
|
|
_gtk_boolean_handled_accumulator, NULL,
|
|
|
|
|
_gtk_marshal_BOOLEAN__OBJECT_BOXED,
|
|
|
|
|
G_TYPE_BOOLEAN, 2,
|
|
|
|
|
GTK_TYPE_WIDGET,
|
|
|
|
|
GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE);
|
2019-06-06 22:27:54 +00:00
|
|
|
|
g_signal_set_va_marshaller (signals[GET_CHILD_POSITION],
|
|
|
|
|
G_TYPE_FROM_CLASS (object_class),
|
|
|
|
|
_gtk_marshal_BOOLEAN__OBJECT_BOXEDv);
|
2016-02-10 13:03:56 +00:00
|
|
|
|
|
2017-11-18 03:49:57 +00:00
|
|
|
|
gtk_widget_class_set_css_name (widget_class, I_("overlay"));
|
2019-05-06 11:06:27 +00:00
|
|
|
|
|
|
|
|
|
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_OVERLAY_LAYOUT);
|
2011-05-19 16:53:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_overlay_init (GtkOverlay *overlay)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-08 02:13:57 +00:00
|
|
|
|
static GtkBuildableIface *parent_buildable_iface;
|
|
|
|
|
|
2011-05-19 16:53:05 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_overlay_buildable_add_child (GtkBuildable *buildable,
|
|
|
|
|
GtkBuilder *builder,
|
|
|
|
|
GObject *child,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *type)
|
2011-05-19 16:53:05 +00:00
|
|
|
|
{
|
2018-03-08 02:13:57 +00:00
|
|
|
|
if (GTK_IS_WIDGET (child))
|
2017-04-23 06:39:15 +00:00
|
|
|
|
{
|
2018-03-08 02:13:57 +00:00
|
|
|
|
if (type && strcmp (type, "overlay") == 0)
|
|
|
|
|
gtk_overlay_add_overlay (GTK_OVERLAY (buildable), GTK_WIDGET (child));
|
|
|
|
|
else if (!type)
|
2020-05-03 14:50:56 +00:00
|
|
|
|
gtk_overlay_set_child (GTK_OVERLAY (buildable), GTK_WIDGET (child));
|
2018-03-08 02:13:57 +00:00
|
|
|
|
else
|
|
|
|
|
GTK_BUILDER_WARN_INVALID_CHILD_TYPE (buildable, type);
|
2017-04-23 06:39:15 +00:00
|
|
|
|
}
|
2011-05-19 16:53:05 +00:00
|
|
|
|
else
|
2018-03-08 02:13:57 +00:00
|
|
|
|
{
|
|
|
|
|
parent_buildable_iface->add_child (buildable, builder, child, type);
|
|
|
|
|
}
|
2011-05-19 16:53:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_overlay_buildable_init (GtkBuildableIface *iface)
|
|
|
|
|
{
|
2018-03-08 02:13:57 +00:00
|
|
|
|
parent_buildable_iface = g_type_interface_peek_parent (iface);
|
|
|
|
|
|
2011-05-19 16:53:05 +00:00
|
|
|
|
iface->add_child = gtk_overlay_buildable_add_child;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_overlay_new:
|
|
|
|
|
*
|
2021-02-27 23:18:30 +00:00
|
|
|
|
* Creates a new `GtkOverlay`.
|
2011-05-19 16:53:05 +00:00
|
|
|
|
*
|
2021-02-27 23:18:30 +00:00
|
|
|
|
* Returns: a new `GtkOverlay` object.
|
2011-05-19 16:53:05 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkWidget *
|
|
|
|
|
gtk_overlay_new (void)
|
|
|
|
|
{
|
|
|
|
|
return g_object_new (GTK_TYPE_OVERLAY, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_overlay_add_overlay:
|
2021-02-27 23:18:30 +00:00
|
|
|
|
* @overlay: a `GtkOverlay`
|
|
|
|
|
* @widget: a `GtkWidget` to be added to the container
|
2011-05-19 16:53:05 +00:00
|
|
|
|
*
|
|
|
|
|
* Adds @widget to @overlay.
|
|
|
|
|
*
|
|
|
|
|
* The widget will be stacked on top of the main widget
|
2021-02-27 23:18:30 +00:00
|
|
|
|
* added with [method@Gtk.Overlay.set_child].
|
2011-05-19 16:53:05 +00:00
|
|
|
|
*
|
|
|
|
|
* The position at which @widget is placed is determined
|
2021-02-27 23:18:30 +00:00
|
|
|
|
* from its [property@Gtk.Widget:halign] and
|
|
|
|
|
* [property@Gtk.Widget:valign] properties.
|
2011-05-19 16:53:05 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_overlay_add_overlay (GtkOverlay *overlay,
|
|
|
|
|
GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_OVERLAY (overlay));
|
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
2020-05-03 14:51:49 +00:00
|
|
|
|
g_return_if_fail (widget != overlay->child);
|
2011-05-19 16:53:05 +00:00
|
|
|
|
|
2017-04-23 06:39:15 +00:00
|
|
|
|
gtk_widget_insert_before (widget, GTK_WIDGET (overlay), NULL);
|
2011-05-19 16:53:05 +00:00
|
|
|
|
}
|
2015-06-09 08:26:31 +00:00
|
|
|
|
|
2020-05-03 14:51:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_overlay_remove_overlay:
|
2021-02-27 23:18:30 +00:00
|
|
|
|
* @overlay: a `GtkOverlay`
|
|
|
|
|
* @widget: a `GtkWidget` to be removed
|
2020-05-03 14:51:49 +00:00
|
|
|
|
*
|
|
|
|
|
* Removes an overlay that was added with gtk_overlay_add_overlay().
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_overlay_remove_overlay (GtkOverlay *overlay,
|
|
|
|
|
GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_OVERLAY (overlay));
|
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
|
|
|
|
g_return_if_fail (gtk_widget_get_parent (widget) == GTK_WIDGET (overlay));
|
|
|
|
|
g_return_if_fail (widget != overlay->child);
|
|
|
|
|
|
|
|
|
|
gtk_widget_unparent (widget);
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-07 15:04:04 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_overlay_set_measure_overlay:
|
2021-02-27 23:18:30 +00:00
|
|
|
|
* @overlay: a `GtkOverlay`
|
|
|
|
|
* @widget: an overlay child of `GtkOverlay`
|
2018-03-07 15:04:04 +00:00
|
|
|
|
* @measure: whether the child should be measured
|
|
|
|
|
*
|
|
|
|
|
* Sets whether @widget is included in the measured size of @overlay.
|
|
|
|
|
*
|
|
|
|
|
* The overlay will request the size of the largest child that has
|
|
|
|
|
* this property set to %TRUE. Children who are not included may
|
|
|
|
|
* be drawn outside of @overlay's allocation if they are too large.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_overlay_set_measure_overlay (GtkOverlay *overlay,
|
|
|
|
|
GtkWidget *widget,
|
|
|
|
|
gboolean measure)
|
|
|
|
|
{
|
2020-04-26 19:37:47 +00:00
|
|
|
|
GtkLayoutManager *layout;
|
2019-03-28 03:47:32 +00:00
|
|
|
|
GtkOverlayLayoutChild *child;
|
|
|
|
|
|
2018-03-07 15:04:04 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_OVERLAY (overlay));
|
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
|
|
|
|
|
2020-04-26 19:37:47 +00:00
|
|
|
|
layout = gtk_widget_get_layout_manager (GTK_WIDGET (overlay));
|
|
|
|
|
child = GTK_OVERLAY_LAYOUT_CHILD (gtk_layout_manager_get_layout_child (layout, widget));
|
2019-03-28 03:47:32 +00:00
|
|
|
|
gtk_overlay_layout_child_set_measure (child, measure);
|
2018-03-07 15:04:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_overlay_get_measure_overlay:
|
2021-02-27 23:18:30 +00:00
|
|
|
|
* @overlay: a `GtkOverlay`
|
|
|
|
|
* @widget: an overlay child of `GtkOverlay`
|
2018-03-07 15:04:04 +00:00
|
|
|
|
*
|
|
|
|
|
* Gets whether @widget's size is included in the measurement of
|
|
|
|
|
* @overlay.
|
|
|
|
|
*
|
|
|
|
|
* Returns: whether the widget is measured
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_overlay_get_measure_overlay (GtkOverlay *overlay,
|
|
|
|
|
GtkWidget *widget)
|
|
|
|
|
{
|
2020-04-26 19:37:47 +00:00
|
|
|
|
GtkLayoutManager *layout;
|
2019-03-28 03:47:32 +00:00
|
|
|
|
GtkOverlayLayoutChild *child;
|
2018-03-07 15:04:04 +00:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_OVERLAY (overlay), FALSE);
|
|
|
|
|
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
|
|
|
|
|
|
2020-04-26 19:37:47 +00:00
|
|
|
|
layout = gtk_widget_get_layout_manager (GTK_WIDGET (overlay));
|
|
|
|
|
child = GTK_OVERLAY_LAYOUT_CHILD (gtk_layout_manager_get_layout_child (layout, widget));
|
2019-03-28 03:47:32 +00:00
|
|
|
|
return gtk_overlay_layout_child_get_measure (child);
|
2018-03-07 15:04:04 +00:00
|
|
|
|
}
|
2018-06-11 10:36:22 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_overlay_set_clip_overlay:
|
2021-02-27 23:18:30 +00:00
|
|
|
|
* @overlay: a `GtkOverlay`
|
|
|
|
|
* @widget: an overlay child of `GtkOverlay`
|
2018-06-11 10:36:22 +00:00
|
|
|
|
* @clip_overlay: whether the child should be clipped
|
|
|
|
|
*
|
2020-05-11 16:47:20 +00:00
|
|
|
|
* Sets whether @widget should be clipped within the parent.
|
2018-06-11 10:36:22 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_overlay_set_clip_overlay (GtkOverlay *overlay,
|
|
|
|
|
GtkWidget *widget,
|
|
|
|
|
gboolean clip_overlay)
|
|
|
|
|
{
|
2020-04-26 19:37:47 +00:00
|
|
|
|
GtkLayoutManager *layout;
|
2019-03-28 03:47:32 +00:00
|
|
|
|
GtkOverlayLayoutChild *child;
|
|
|
|
|
|
2018-06-11 10:36:22 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_OVERLAY (overlay));
|
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
|
|
|
|
|
2020-04-26 19:37:47 +00:00
|
|
|
|
layout = gtk_widget_get_layout_manager (GTK_WIDGET (overlay));
|
|
|
|
|
child = GTK_OVERLAY_LAYOUT_CHILD (gtk_layout_manager_get_layout_child (layout, widget));
|
2019-03-28 03:47:32 +00:00
|
|
|
|
gtk_overlay_layout_child_set_clip_overlay (child, clip_overlay);
|
2018-06-11 10:36:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-02-24 20:29:08 +00:00
|
|
|
|
* gtk_overlay_get_clip_overlay:
|
2021-02-27 23:18:30 +00:00
|
|
|
|
* @overlay: a `GtkOverlay`
|
|
|
|
|
* @widget: an overlay child of `GtkOverlay`
|
2018-06-11 10:36:22 +00:00
|
|
|
|
*
|
2020-05-11 16:47:20 +00:00
|
|
|
|
* Gets whether @widget should be clipped within the parent.
|
2018-06-11 10:36:22 +00:00
|
|
|
|
*
|
|
|
|
|
* Returns: whether the widget is clipped within the parent.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_overlay_get_clip_overlay (GtkOverlay *overlay,
|
|
|
|
|
GtkWidget *widget)
|
|
|
|
|
{
|
2020-04-26 19:37:47 +00:00
|
|
|
|
GtkLayoutManager *layout;
|
2019-03-28 03:47:32 +00:00
|
|
|
|
GtkOverlayLayoutChild *child;
|
2018-06-11 10:36:22 +00:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_OVERLAY (overlay), FALSE);
|
|
|
|
|
g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
|
|
|
|
|
|
2020-04-26 19:37:47 +00:00
|
|
|
|
layout = gtk_widget_get_layout_manager (GTK_WIDGET (overlay));
|
|
|
|
|
child = GTK_OVERLAY_LAYOUT_CHILD (gtk_layout_manager_get_layout_child (layout, widget));
|
2018-06-11 10:36:22 +00:00
|
|
|
|
|
2019-03-28 03:47:32 +00:00
|
|
|
|
return gtk_overlay_layout_child_get_clip_overlay (child);
|
2018-06-11 10:36:22 +00:00
|
|
|
|
}
|
2020-05-03 14:31:09 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_overlay_set_child:
|
2021-02-27 23:18:30 +00:00
|
|
|
|
* @overlay: a `GtkOverlay`
|
2021-05-19 11:24:34 +00:00
|
|
|
|
* @child: (nullable): the child widget
|
2020-05-03 14:31:09 +00:00
|
|
|
|
*
|
|
|
|
|
* Sets the child widget of @overlay.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_overlay_set_child (GtkOverlay *overlay,
|
|
|
|
|
GtkWidget *child)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_OVERLAY (overlay));
|
|
|
|
|
g_return_if_fail (child == NULL || GTK_IS_WIDGET (child));
|
|
|
|
|
|
2020-05-03 14:50:56 +00:00
|
|
|
|
g_clear_pointer (&overlay->child, gtk_widget_unparent);
|
|
|
|
|
|
|
|
|
|
overlay->child = child;
|
|
|
|
|
|
|
|
|
|
if (child)
|
|
|
|
|
{
|
|
|
|
|
/* Make sure the main-child node is the first one */
|
|
|
|
|
gtk_widget_insert_after (child, GTK_WIDGET (overlay), NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-03 14:31:09 +00:00
|
|
|
|
g_object_notify (G_OBJECT (overlay), "child");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_overlay_get_child:
|
2021-02-27 23:18:30 +00:00
|
|
|
|
* @overlay: a `GtkOverlay`
|
2020-05-03 14:31:09 +00:00
|
|
|
|
*
|
|
|
|
|
* Gets the child widget of @overlay.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (nullable) (transfer none): the child widget of @overlay
|
|
|
|
|
*/
|
|
|
|
|
GtkWidget *
|
|
|
|
|
gtk_overlay_get_child (GtkOverlay *overlay)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_OVERLAY (overlay), NULL);
|
|
|
|
|
|
2020-05-03 14:50:56 +00:00
|
|
|
|
return overlay->child;
|
2020-05-03 14:31:09 +00:00
|
|
|
|
}
|