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"
|
|
|
|
#include "gtkbuildable.h"
|
|
|
|
#include "gtkscrolledwindow.h"
|
|
|
|
#include "gtkmarshalers.h"
|
|
|
|
|
|
|
|
#include "gtkprivate.h"
|
|
|
|
#include "gtkintl.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gtkoverlay
|
|
|
|
* @short_description: A container which overlays widgets on top of each other
|
|
|
|
* @title: GtkOverlay
|
|
|
|
*
|
|
|
|
* GtkOverlay is a container which contains a single main child, on top
|
|
|
|
* of which it can place <firstterm>overlay</firstterm> widgets. The
|
2012-02-15 10:43:33 +00:00
|
|
|
* position of each overlay widget is determined by its #GtkWidget:halign
|
|
|
|
* and #GtkWidget:valign properties. E.g. a widget with both alignments
|
2011-05-19 16:53:05 +00:00
|
|
|
* set to %GTK_ALIGN_START will be placed at the top left corner of the
|
|
|
|
* 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 margin properties of the child to non-zero values.
|
|
|
|
*
|
|
|
|
* More complicated placement of overlays is possible by connecting
|
|
|
|
* to the #GtkOverlay::get-child-position signal.
|
|
|
|
*
|
|
|
|
* <refsect2 id="GtkOverlay-BUILDER-UI">
|
|
|
|
* <title>GtkOverlay as GtkBuildable</title>
|
|
|
|
* <para>
|
|
|
|
* The GtkOverlay implementation of the GtkBuildable interface
|
|
|
|
* supports placing a child as an overlay by specifying "overlay" as
|
|
|
|
* the "type" attribute of a <tag class="starttag">child</tag> element.
|
|
|
|
* </para>
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct _GtkOverlayPrivate
|
|
|
|
{
|
|
|
|
GSList *children;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _GtkOverlayChild GtkOverlayChild;
|
|
|
|
|
|
|
|
struct _GtkOverlayChild
|
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
GdkWindow *window;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
GET_CHILD_POSITION,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
static void gtk_overlay_buildable_init (GtkBuildableIface *iface);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkOverlay, gtk_overlay, GTK_TYPE_BIN,
|
2013-06-27 19:02:52 +00:00
|
|
|
G_ADD_PRIVATE (GtkOverlay)
|
2011-05-19 16:53:05 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
|
|
|
|
gtk_overlay_buildable_init))
|
|
|
|
|
2013-03-28 11:10:09 +00:00
|
|
|
static void
|
|
|
|
gtk_overlay_compute_child_allocation (GtkOverlay *overlay,
|
|
|
|
GtkOverlayChild *child,
|
|
|
|
GtkAllocation *window_allocation,
|
|
|
|
GtkAllocation *widget_allocation)
|
|
|
|
{
|
|
|
|
gint left, right, top, bottom;
|
|
|
|
GtkAllocation allocation, overlay_allocation;
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
g_signal_emit (overlay, signals[GET_CHILD_POSITION],
|
|
|
|
0, child->widget, &allocation, &result);
|
|
|
|
|
|
|
|
gtk_widget_get_allocation (GTK_WIDGET (overlay), &overlay_allocation);
|
|
|
|
|
|
|
|
allocation.x += overlay_allocation.x;
|
|
|
|
allocation.y += overlay_allocation.y;
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
|
|
|
if (widget_allocation)
|
|
|
|
{
|
|
|
|
widget_allocation->x = - left;
|
|
|
|
widget_allocation->y = - top;
|
|
|
|
widget_allocation->width = allocation.width;
|
|
|
|
widget_allocation->height = allocation.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window_allocation)
|
|
|
|
{
|
|
|
|
window_allocation->x = allocation.x + left;
|
|
|
|
window_allocation->y = allocation.y + top;
|
|
|
|
window_allocation->width = allocation.width - (left + right);
|
|
|
|
window_allocation->height = allocation.height - (top + bottom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-19 16:53:05 +00:00
|
|
|
static GdkWindow *
|
|
|
|
gtk_overlay_create_child_window (GtkOverlay *overlay,
|
2013-03-28 11:10:09 +00:00
|
|
|
GtkOverlayChild *child)
|
2011-05-19 16:53:05 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget = GTK_WIDGET (overlay);
|
|
|
|
GtkAllocation allocation;
|
|
|
|
GdkWindow *window;
|
|
|
|
GdkWindowAttr attributes;
|
|
|
|
gint attributes_mask;
|
|
|
|
|
2013-03-28 11:10:09 +00:00
|
|
|
gtk_overlay_compute_child_allocation (overlay, child, &allocation, NULL);
|
2011-05-19 16:53:05 +00:00
|
|
|
|
|
|
|
attributes.window_type = GDK_WINDOW_CHILD;
|
|
|
|
attributes.wclass = GDK_INPUT_OUTPUT;
|
|
|
|
attributes.width = allocation.width;
|
|
|
|
attributes.height = allocation.height;
|
|
|
|
attributes.x = allocation.x;
|
|
|
|
attributes.y = allocation.y;
|
2013-05-08 13:51:00 +00:00
|
|
|
attributes.visual = gtk_widget_get_visual (widget);
|
|
|
|
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
|
2011-05-19 16:53:05 +00:00
|
|
|
attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
|
|
|
|
|
|
|
|
window = gdk_window_new (gtk_widget_get_window (widget),
|
|
|
|
&attributes, attributes_mask);
|
2013-02-05 08:36:49 +00:00
|
|
|
gtk_widget_register_window (widget, window);
|
2011-05-19 16:53:05 +00:00
|
|
|
gtk_style_context_set_background (gtk_widget_get_style_context (widget), window);
|
|
|
|
|
2013-03-28 11:10:09 +00:00
|
|
|
gtk_widget_set_parent_window (child->widget, window);
|
|
|
|
|
2011-05-19 16:53:05 +00:00
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
default:
|
|
|
|
return align;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-29 17:20:25 +00:00
|
|
|
static void
|
|
|
|
gtk_overlay_get_main_widget_allocation (GtkOverlay *overlay,
|
|
|
|
GtkAllocation *main_alloc_out)
|
|
|
|
{
|
|
|
|
GtkWidget *main_widget;
|
|
|
|
GtkAllocation main_alloc;
|
|
|
|
|
|
|
|
main_widget = gtk_bin_get_child (GTK_BIN (overlay));
|
|
|
|
|
|
|
|
/* special-case scrolled windows */
|
|
|
|
if (GTK_IS_SCROLLED_WINDOW (main_widget))
|
|
|
|
{
|
|
|
|
GtkWidget *grandchild;
|
|
|
|
gint x, y;
|
2012-02-29 17:21:59 +00:00
|
|
|
gboolean res;
|
2012-02-29 17:20:25 +00:00
|
|
|
|
|
|
|
grandchild = gtk_bin_get_child (GTK_BIN (main_widget));
|
|
|
|
res = gtk_widget_translate_coordinates (grandchild, main_widget, 0, 0, &x, &y);
|
|
|
|
|
2012-02-29 17:21:59 +00:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
main_alloc.x = x;
|
|
|
|
main_alloc.y = y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
main_alloc.x = 0;
|
|
|
|
main_alloc.y = 0;
|
|
|
|
}
|
|
|
|
|
2012-02-29 17:20:25 +00:00
|
|
|
main_alloc.width = gtk_widget_get_allocated_width (grandchild);
|
|
|
|
main_alloc.height = gtk_widget_get_allocated_height (grandchild);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
main_alloc.x = 0;
|
|
|
|
main_alloc.y = 0;
|
|
|
|
main_alloc.width = gtk_widget_get_allocated_width (main_widget);
|
|
|
|
main_alloc.height = gtk_widget_get_allocated_height (main_widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (main_alloc_out)
|
|
|
|
*main_alloc_out = main_alloc;
|
|
|
|
}
|
|
|
|
|
2012-02-03 20:33:30 +00:00
|
|
|
static void
|
|
|
|
gtk_overlay_child_update_style_classes (GtkOverlay *overlay,
|
|
|
|
GtkWidget *child,
|
|
|
|
GtkAllocation *child_allocation)
|
|
|
|
{
|
|
|
|
GtkAllocation overlay_allocation, main_allocation;
|
|
|
|
GtkAlign valign, halign;
|
|
|
|
gboolean is_left, is_right, is_top, is_bottom;
|
|
|
|
gboolean has_left, has_right, has_top, has_bottom;
|
|
|
|
GtkStyleContext *context;
|
|
|
|
|
|
|
|
context = gtk_widget_get_style_context (child);
|
|
|
|
has_left = gtk_style_context_has_class (context, GTK_STYLE_CLASS_LEFT);
|
|
|
|
has_right = gtk_style_context_has_class (context, GTK_STYLE_CLASS_RIGHT);
|
|
|
|
has_top = gtk_style_context_has_class (context, GTK_STYLE_CLASS_TOP);
|
|
|
|
has_bottom = gtk_style_context_has_class (context, GTK_STYLE_CLASS_BOTTOM);
|
|
|
|
|
|
|
|
is_left = is_right = is_top = is_bottom = FALSE;
|
|
|
|
|
|
|
|
gtk_overlay_get_main_widget_allocation (overlay, &main_allocation);
|
|
|
|
gtk_widget_get_allocation (GTK_WIDGET (overlay), &overlay_allocation);
|
|
|
|
|
|
|
|
main_allocation.x += overlay_allocation.x;
|
|
|
|
main_allocation.y += overlay_allocation.y;
|
|
|
|
|
|
|
|
halign = effective_align (gtk_widget_get_halign (child),
|
|
|
|
gtk_widget_get_direction (child));
|
|
|
|
|
|
|
|
if (halign == GTK_ALIGN_START)
|
|
|
|
is_left = (child_allocation->x == main_allocation.x);
|
|
|
|
else if (halign == GTK_ALIGN_END)
|
|
|
|
is_right = (child_allocation->x + child_allocation->width ==
|
|
|
|
main_allocation.x + main_allocation.width);
|
|
|
|
|
|
|
|
valign = gtk_widget_get_valign (child);
|
|
|
|
|
|
|
|
if (valign == GTK_ALIGN_START)
|
|
|
|
is_top = (child_allocation->y == main_allocation.y);
|
|
|
|
else if (valign == GTK_ALIGN_END)
|
|
|
|
is_bottom = (child_allocation->y + child_allocation->height ==
|
|
|
|
main_allocation.y + main_allocation.height);
|
|
|
|
|
|
|
|
if (has_left && !is_left)
|
|
|
|
gtk_style_context_remove_class (context, GTK_STYLE_CLASS_LEFT);
|
|
|
|
else if (!has_left && is_left)
|
|
|
|
gtk_style_context_add_class (context, GTK_STYLE_CLASS_LEFT);
|
|
|
|
|
|
|
|
if (has_right && !is_right)
|
|
|
|
gtk_style_context_remove_class (context, GTK_STYLE_CLASS_RIGHT);
|
|
|
|
else if (!has_right && is_right)
|
|
|
|
gtk_style_context_add_class (context, GTK_STYLE_CLASS_RIGHT);
|
|
|
|
|
|
|
|
if (has_top && !is_top)
|
|
|
|
gtk_style_context_remove_class (context, GTK_STYLE_CLASS_TOP);
|
|
|
|
else if (!has_top && is_top)
|
|
|
|
gtk_style_context_add_class (context, GTK_STYLE_CLASS_TOP);
|
|
|
|
|
|
|
|
if (has_bottom && !is_bottom)
|
|
|
|
gtk_style_context_remove_class (context, GTK_STYLE_CLASS_BOTTOM);
|
|
|
|
else if (!has_bottom && is_bottom)
|
|
|
|
gtk_style_context_add_class (context, GTK_STYLE_CLASS_BOTTOM);
|
|
|
|
}
|
|
|
|
|
2011-05-19 16:53:05 +00:00
|
|
|
static void
|
2011-12-07 22:51:19 +00:00
|
|
|
gtk_overlay_child_allocate (GtkOverlay *overlay,
|
|
|
|
GtkOverlayChild *child)
|
2011-05-19 16:53:05 +00:00
|
|
|
{
|
2013-03-28 11:10:09 +00:00
|
|
|
GtkAllocation window_allocation, child_allocation;
|
2011-12-07 22:51:19 +00:00
|
|
|
|
|
|
|
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))
|
|
|
|
return;
|
|
|
|
|
2013-03-28 11:10:09 +00:00
|
|
|
gtk_overlay_compute_child_allocation (overlay, child, &window_allocation, &child_allocation);
|
2011-05-19 16:53:05 +00:00
|
|
|
|
|
|
|
if (child->window)
|
|
|
|
gdk_window_move_resize (child->window,
|
2013-03-28 11:10:09 +00:00
|
|
|
window_allocation.x, window_allocation.y,
|
|
|
|
window_allocation.width, window_allocation.height);
|
2011-05-19 16:53:05 +00:00
|
|
|
|
2013-03-28 11:10:09 +00:00
|
|
|
gtk_overlay_child_update_style_classes (overlay, child->widget, &window_allocation);
|
2011-05-19 16:53:05 +00:00
|
|
|
gtk_widget_size_allocate (child->widget, &child_allocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_overlay_get_preferred_width (GtkWidget *widget,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural)
|
|
|
|
{
|
|
|
|
GtkBin *bin = GTK_BIN (widget);
|
|
|
|
GtkWidget *child;
|
|
|
|
|
|
|
|
if (minimum)
|
|
|
|
*minimum = 0;
|
|
|
|
|
|
|
|
if (natural)
|
|
|
|
*natural = 0;
|
|
|
|
|
|
|
|
child = gtk_bin_get_child (bin);
|
|
|
|
if (child && gtk_widget_get_visible (child))
|
|
|
|
gtk_widget_get_preferred_width (child, minimum, natural);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_overlay_get_preferred_height (GtkWidget *widget,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural)
|
|
|
|
{
|
|
|
|
GtkBin *bin = GTK_BIN (widget);
|
|
|
|
GtkWidget *child;
|
|
|
|
|
|
|
|
if (minimum)
|
|
|
|
*minimum = 0;
|
|
|
|
|
|
|
|
if (natural)
|
|
|
|
*natural = 0;
|
|
|
|
|
|
|
|
child = gtk_bin_get_child (bin);
|
|
|
|
if (child && gtk_widget_get_visible (child))
|
|
|
|
gtk_widget_get_preferred_height (child, minimum, natural);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_overlay_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation)
|
|
|
|
{
|
|
|
|
GtkOverlay *overlay = GTK_OVERLAY (widget);
|
|
|
|
GtkOverlayPrivate *priv = overlay->priv;
|
|
|
|
GSList *children;
|
|
|
|
GtkWidget *main_widget;
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_overlay_parent_class)->size_allocate (widget, allocation);
|
|
|
|
|
|
|
|
main_widget = gtk_bin_get_child (GTK_BIN (overlay));
|
|
|
|
if (!main_widget || !gtk_widget_get_visible (main_widget))
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_widget_size_allocate (main_widget, allocation);
|
|
|
|
|
|
|
|
for (children = priv->children; children; children = children->next)
|
2013-03-28 11:10:09 +00:00
|
|
|
gtk_overlay_child_allocate (overlay, children->data);
|
2011-05-19 16:53:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_overlay_get_child_position (GtkOverlay *overlay,
|
|
|
|
GtkWidget *widget,
|
|
|
|
GtkAllocation *alloc)
|
|
|
|
{
|
|
|
|
GtkAllocation main_alloc;
|
2013-03-28 12:24:04 +00:00
|
|
|
GtkRequisition min, req;
|
2011-05-19 16:53:05 +00:00
|
|
|
GtkAlign halign;
|
|
|
|
GtkTextDirection direction;
|
|
|
|
|
2012-02-29 17:20:25 +00:00
|
|
|
gtk_overlay_get_main_widget_allocation (overlay, &main_alloc);
|
2013-03-28 12:24:04 +00:00
|
|
|
gtk_widget_get_preferred_size (widget, &min, &req);
|
2011-05-19 16:53:05 +00:00
|
|
|
|
|
|
|
alloc->x = main_alloc.x;
|
2013-03-28 12:24:04 +00:00
|
|
|
alloc->width = MAX (min.width, MIN (main_alloc.width, req.width));
|
2011-05-19 16:53:05 +00:00
|
|
|
|
|
|
|
direction = gtk_widget_get_direction (widget);
|
|
|
|
|
|
|
|
halign = gtk_widget_get_halign (widget);
|
|
|
|
switch (effective_align (halign, direction))
|
|
|
|
{
|
|
|
|
case GTK_ALIGN_START:
|
|
|
|
/* nothing to do */
|
|
|
|
break;
|
|
|
|
case GTK_ALIGN_FILL:
|
2013-03-28 12:24:04 +00:00
|
|
|
alloc->width = MAX (alloc->width, main_alloc.width);
|
2011-05-19 16:53:05 +00:00
|
|
|
break;
|
|
|
|
case GTK_ALIGN_CENTER:
|
|
|
|
alloc->x += main_alloc.width / 2 - req.width / 2;
|
|
|
|
break;
|
|
|
|
case GTK_ALIGN_END:
|
|
|
|
alloc->x += main_alloc.width - req.width;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
alloc->y = main_alloc.y;
|
2013-03-28 12:24:04 +00:00
|
|
|
alloc->height = MAX (min.height, MIN (main_alloc.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:
|
2013-03-28 12:24:04 +00:00
|
|
|
alloc->height = MAX (alloc->height, main_alloc.height);
|
2011-05-19 16:53:05 +00:00
|
|
|
break;
|
|
|
|
case GTK_ALIGN_CENTER:
|
|
|
|
alloc->y += main_alloc.height / 2 - req.height / 2;
|
|
|
|
break;
|
|
|
|
case GTK_ALIGN_END:
|
|
|
|
alloc->y += main_alloc.height - req.height;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_overlay_realize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkOverlay *overlay = GTK_OVERLAY (widget);
|
|
|
|
GtkOverlayPrivate *priv = overlay->priv;
|
|
|
|
GtkOverlayChild *child;
|
|
|
|
GSList *children;
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_overlay_parent_class)->realize (widget);
|
|
|
|
|
|
|
|
for (children = priv->children; children; children = children->next)
|
|
|
|
{
|
|
|
|
child = children->data;
|
|
|
|
|
|
|
|
if (child->window == NULL)
|
2013-03-28 11:10:09 +00:00
|
|
|
child->window = gtk_overlay_create_child_window (overlay, child);
|
2011-05-19 16:53:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_overlay_unrealize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkOverlay *overlay = GTK_OVERLAY (widget);
|
|
|
|
GtkOverlayPrivate *priv = overlay->priv;
|
|
|
|
GtkOverlayChild *child;
|
|
|
|
GSList *children;
|
|
|
|
|
|
|
|
for (children = priv->children; children; children = children->next)
|
|
|
|
{
|
|
|
|
child = children->data;
|
|
|
|
|
|
|
|
gtk_widget_set_parent_window (child->widget, NULL);
|
2013-02-05 08:36:49 +00:00
|
|
|
gtk_widget_unregister_window (widget, child->window);
|
2011-05-19 16:53:05 +00:00
|
|
|
gdk_window_destroy (child->window);
|
|
|
|
child->window = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_overlay_parent_class)->unrealize (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_overlay_map (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkOverlay *overlay = GTK_OVERLAY (widget);
|
|
|
|
GtkOverlayPrivate *priv = overlay->priv;
|
|
|
|
GtkOverlayChild *child;
|
|
|
|
GSList *children;
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_overlay_parent_class)->map (widget);
|
|
|
|
|
|
|
|
for (children = priv->children; children; children = children->next)
|
|
|
|
{
|
|
|
|
child = children->data;
|
|
|
|
|
|
|
|
if (child->window != NULL &&
|
|
|
|
gtk_widget_get_visible (child->widget) &&
|
|
|
|
gtk_widget_get_child_visible (child->widget))
|
|
|
|
gdk_window_show (child->window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_overlay_unmap (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkOverlay *overlay = GTK_OVERLAY (widget);
|
|
|
|
GtkOverlayPrivate *priv = overlay->priv;
|
|
|
|
GtkOverlayChild *child;
|
|
|
|
GSList *children;
|
|
|
|
|
|
|
|
for (children = priv->children; children; children = children->next)
|
|
|
|
{
|
|
|
|
child = children->data;
|
|
|
|
|
|
|
|
if (child->window != NULL &&
|
|
|
|
gdk_window_is_visible (child->window))
|
|
|
|
gdk_window_hide (child->window);
|
|
|
|
}
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_overlay_parent_class)->unmap (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_overlay_draw (GtkWidget *widget,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
GtkOverlay *overlay = GTK_OVERLAY (widget);
|
|
|
|
GtkOverlayPrivate *priv = overlay->priv;
|
|
|
|
GtkOverlayChild *child;
|
|
|
|
GSList *children;
|
|
|
|
|
|
|
|
for (children = priv->children; children; children = children->next)
|
|
|
|
{
|
|
|
|
child = children->data;
|
|
|
|
|
|
|
|
if (gtk_cairo_should_draw_window (cr, child->window))
|
|
|
|
{
|
|
|
|
cairo_save (cr);
|
|
|
|
gtk_cairo_transform_to_window (cr, widget, child->window);
|
|
|
|
gtk_render_background (gtk_widget_get_style_context (widget),
|
|
|
|
cr,
|
|
|
|
0, 0,
|
|
|
|
gdk_window_get_width (child->window),
|
|
|
|
gdk_window_get_height (child->window));
|
|
|
|
cairo_restore (cr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_overlay_parent_class)->draw (widget, cr);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_overlay_remove (GtkContainer *container,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkOverlayPrivate *priv = GTK_OVERLAY (container)->priv;
|
|
|
|
GtkOverlayChild *child;
|
|
|
|
GSList *children;
|
|
|
|
|
|
|
|
for (children = priv->children; children; children = children->next)
|
|
|
|
{
|
|
|
|
child = children->data;
|
|
|
|
|
|
|
|
if (child->widget == widget)
|
|
|
|
{
|
|
|
|
if (child->window != NULL)
|
|
|
|
{
|
2013-02-05 08:36:49 +00:00
|
|
|
gtk_widget_unregister_window (GTK_WIDGET (container), child->window);
|
2011-05-19 16:53:05 +00:00
|
|
|
gdk_window_destroy (child->window);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_widget_unparent (widget);
|
|
|
|
|
|
|
|
priv->children = g_slist_delete_link (priv->children, children);
|
|
|
|
g_slice_free (GtkOverlayChild, child);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GTK_CONTAINER_CLASS (gtk_overlay_parent_class)->remove (container, widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_overlay_forall (GtkContainer *overlay,
|
|
|
|
gboolean include_internals,
|
|
|
|
GtkCallback callback,
|
|
|
|
gpointer callback_data)
|
|
|
|
{
|
|
|
|
GtkOverlayPrivate *priv = GTK_OVERLAY (overlay)->priv;
|
|
|
|
GtkOverlayChild *child;
|
|
|
|
GSList *children;
|
|
|
|
GtkWidget *main_widget;
|
|
|
|
|
|
|
|
main_widget = gtk_bin_get_child (GTK_BIN (overlay));
|
|
|
|
if (main_widget)
|
|
|
|
(* callback) (main_widget, callback_data);
|
|
|
|
|
|
|
|
children = priv->children;
|
|
|
|
while (children)
|
|
|
|
{
|
|
|
|
child = children->data;
|
|
|
|
children = children->next;
|
|
|
|
|
|
|
|
(* callback) (child->widget, callback_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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;
|
|
|
|
widget_class->realize = gtk_overlay_realize;
|
|
|
|
widget_class->unrealize = gtk_overlay_unrealize;
|
|
|
|
widget_class->map = gtk_overlay_map;
|
|
|
|
widget_class->unmap = gtk_overlay_unmap;
|
|
|
|
widget_class->draw = gtk_overlay_draw;
|
|
|
|
|
|
|
|
container_class->remove = gtk_overlay_remove;
|
|
|
|
container_class->forall = gtk_overlay_forall;
|
|
|
|
|
|
|
|
klass->get_child_position = gtk_overlay_get_child_position;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkOverlay::get-child-position:
|
|
|
|
* @overlay: the #GtkOverlay
|
|
|
|
* @widget: the child widget to position
|
2012-09-16 17:02:20 +00:00
|
|
|
* @allocation: (out caller-allocates): return location for the allocation
|
2011-05-19 16:53:05 +00:00
|
|
|
*
|
|
|
|
* The ::get-child-position signal is emitted to determine
|
|
|
|
* the position and size of any overlay child widgets. A
|
|
|
|
* handler for this signal should fill @allocation with
|
|
|
|
* 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
|
|
|
|
* #GtkScrolledWindow, the overlays are placed relative
|
|
|
|
* to its contents.
|
|
|
|
*
|
|
|
|
* Return: %TRUE if the @allocation has been filled
|
|
|
|
*/
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_overlay_init (GtkOverlay *overlay)
|
|
|
|
{
|
2013-06-27 19:02:52 +00:00
|
|
|
overlay->priv = gtk_overlay_get_instance_private (overlay);
|
2011-05-19 16:53:05 +00:00
|
|
|
|
|
|
|
gtk_widget_set_has_window (GTK_WIDGET (overlay), FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_overlay_buildable_add_child (GtkBuildable *buildable,
|
|
|
|
GtkBuilder *builder,
|
|
|
|
GObject *child,
|
|
|
|
const gchar *type)
|
|
|
|
{
|
|
|
|
if (type && strcmp (type, "overlay") == 0)
|
|
|
|
gtk_overlay_add_overlay (GTK_OVERLAY (buildable), GTK_WIDGET (child));
|
|
|
|
else if (!type)
|
|
|
|
gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child));
|
|
|
|
else
|
|
|
|
GTK_BUILDER_WARN_INVALID_CHILD_TYPE (buildable, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_overlay_buildable_init (GtkBuildableIface *iface)
|
|
|
|
{
|
|
|
|
iface->add_child = gtk_overlay_buildable_add_child;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_overlay_new:
|
|
|
|
*
|
|
|
|
* Creates a new #GtkOverlay.
|
|
|
|
*
|
|
|
|
* Returns: a new #GtkOverlay object.
|
|
|
|
*
|
|
|
|
* Since: 3.2
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_overlay_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_OVERLAY, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_overlay_add_overlay:
|
|
|
|
* @overlay: a #GtkOverlay
|
|
|
|
* @widget: a #GtkWidget to be added to the container
|
|
|
|
*
|
|
|
|
* Adds @widget to @overlay.
|
|
|
|
*
|
|
|
|
* The widget will be stacked on top of the main widget
|
|
|
|
* added with gtk_container_add().
|
|
|
|
*
|
|
|
|
* The position at which @widget is placed is determined
|
2012-02-15 10:43:33 +00:00
|
|
|
* from its #GtkWidget:halign and #GtkWidget:valign properties.
|
2011-05-19 16:53:05 +00:00
|
|
|
*
|
|
|
|
* Since: 3.2
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_overlay_add_overlay (GtkOverlay *overlay,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkOverlayPrivate *priv = overlay->priv;
|
|
|
|
GtkOverlayChild *child;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_OVERLAY (overlay));
|
|
|
|
g_return_if_fail (GTK_IS_WIDGET (widget));
|
|
|
|
|
|
|
|
child = g_slice_new0 (GtkOverlayChild);
|
|
|
|
child->widget = widget;
|
|
|
|
|
|
|
|
priv->children = g_slist_append (priv->children, child);
|
|
|
|
|
|
|
|
if (gtk_widget_get_realized (GTK_WIDGET (overlay)))
|
2011-12-07 23:20:06 +00:00
|
|
|
{
|
2013-03-28 11:10:09 +00:00
|
|
|
child->window = gtk_overlay_create_child_window (overlay, child);
|
2011-12-07 23:20:06 +00:00
|
|
|
gtk_widget_set_parent (widget, GTK_WIDGET (overlay));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gtk_widget_set_parent (widget, GTK_WIDGET (overlay));
|
|
|
|
|
2011-05-19 16:53:05 +00:00
|
|
|
}
|