2008-07-01 22:57:50 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
1997-11-24 22:37:52 +00:00
|
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2000-07-26 11:33:08 +00:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1997-11-24 22:37:52 +00:00
|
|
|
* 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
|
2000-07-26 11:33:08 +00:00
|
|
|
* Lesser General Public License for more details.
|
1997-11-24 22:37:52 +00:00
|
|
|
*
|
2000-07-26 11:33:08 +00:00
|
|
|
* 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/>.
|
1997-11-24 22:37:52 +00:00
|
|
|
*/
|
1999-02-24 07:37:18 +00:00
|
|
|
|
|
|
|
/*
|
2000-07-26 11:33:08 +00:00
|
|
|
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
|
1999-02-24 07:37:18 +00:00
|
|
|
* file for a list of people on the GTK+ Team. See the ChangeLog
|
|
|
|
* files for a list of changes. These files are distributed with
|
2008-09-24 10:35:53 +00:00
|
|
|
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
1999-02-24 07:37:18 +00:00
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2010-09-14 01:33:06 +00:00
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
#include "gtkeventbox.h"
|
2010-09-14 01:33:06 +00:00
|
|
|
|
|
|
|
#include "gtksizerequest.h"
|
|
|
|
|
2005-03-22 02:14:55 +00:00
|
|
|
#include "gtkprivate.h"
|
2003-09-08 20:04:49 +00:00
|
|
|
#include "gtkintl.h"
|
2010-07-09 17:22:23 +00:00
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
|
2011-01-04 15:31:19 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gtkeventbox
|
|
|
|
* @Short_description: A widget used to catch events for widgets which
|
|
|
|
* do not have their own window
|
|
|
|
* @Title: GtkEventBox
|
|
|
|
*
|
|
|
|
* The #GtkEventBox widget is a subclass of #GtkBin which also has its
|
|
|
|
* own window. It is useful since it allows you to catch events for widgets
|
|
|
|
* which do not have their own window.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct _GtkEventBoxPrivate
|
2003-09-08 20:04:49 +00:00
|
|
|
{
|
|
|
|
gboolean above_child;
|
|
|
|
GdkWindow *event_window;
|
2011-01-04 15:31:19 +00:00
|
|
|
};
|
2003-09-08 20:04:49 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_VISIBLE_WINDOW,
|
|
|
|
PROP_ABOVE_CHILD
|
|
|
|
};
|
|
|
|
|
2008-09-24 10:35:53 +00:00
|
|
|
static void gtk_event_box_realize (GtkWidget *widget);
|
|
|
|
static void gtk_event_box_unrealize (GtkWidget *widget);
|
|
|
|
static void gtk_event_box_map (GtkWidget *widget);
|
|
|
|
static void gtk_event_box_unmap (GtkWidget *widget);
|
2010-10-15 03:03:39 +00:00
|
|
|
static void gtk_event_box_get_preferred_width (GtkWidget *widget,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural);
|
|
|
|
static void gtk_event_box_get_preferred_height (GtkWidget *widget,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural);
|
2013-03-26 10:08:33 +00:00
|
|
|
static void gtk_event_box_get_preferred_height_and_baseline_for_width (GtkWidget *widget,
|
|
|
|
gint width,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural,
|
|
|
|
gint *minimum_baseline,
|
|
|
|
gint *natural_baseline);
|
2008-09-24 10:35:53 +00:00
|
|
|
static void gtk_event_box_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation);
|
2010-09-07 18:13:50 +00:00
|
|
|
static gboolean gtk_event_box_draw (GtkWidget *widget,
|
|
|
|
cairo_t *cr);
|
2008-09-24 10:35:53 +00:00
|
|
|
static void gtk_event_box_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gtk_event_box_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
1997-11-24 22:37:52 +00:00
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkEventBox, gtk_event_box, GTK_TYPE_BIN)
|
1997-11-24 22:37:52 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_event_box_class_init (GtkEventBoxClass *class)
|
|
|
|
{
|
2003-09-08 20:04:49 +00:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
2010-10-15 02:34:39 +00:00
|
|
|
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
|
1997-11-24 22:37:52 +00:00
|
|
|
|
2003-09-08 20:04:49 +00:00
|
|
|
gobject_class->set_property = gtk_event_box_set_property;
|
|
|
|
gobject_class->get_property = gtk_event_box_get_property;
|
2010-10-15 02:34:39 +00:00
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
widget_class->realize = gtk_event_box_realize;
|
2003-09-08 20:04:49 +00:00
|
|
|
widget_class->unrealize = gtk_event_box_unrealize;
|
|
|
|
widget_class->map = gtk_event_box_map;
|
|
|
|
widget_class->unmap = gtk_event_box_unmap;
|
2010-10-15 03:03:39 +00:00
|
|
|
widget_class->get_preferred_width = gtk_event_box_get_preferred_width;
|
|
|
|
widget_class->get_preferred_height = gtk_event_box_get_preferred_height;
|
2013-03-26 10:08:33 +00:00
|
|
|
widget_class->get_preferred_height_and_baseline_for_width = gtk_event_box_get_preferred_height_and_baseline_for_width;
|
1997-11-24 22:37:52 +00:00
|
|
|
widget_class->size_allocate = gtk_event_box_size_allocate;
|
2010-09-07 18:13:50 +00:00
|
|
|
widget_class->draw = gtk_event_box_draw;
|
2003-09-08 20:04:49 +00:00
|
|
|
|
2010-10-15 02:34:39 +00:00
|
|
|
gtk_container_class_handle_border_width (container_class);
|
|
|
|
|
2003-09-08 20:04:49 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_VISIBLE_WINDOW,
|
|
|
|
g_param_spec_boolean ("visible-window",
|
2004-01-16 23:10:05 +00:00
|
|
|
P_("Visible Window"),
|
|
|
|
P_("Whether the event box is visible, as opposed to invisible and only used to trap events."),
|
2003-11-08 21:01:14 +00:00
|
|
|
TRUE,
|
2005-03-22 02:14:55 +00:00
|
|
|
GTK_PARAM_READWRITE));
|
2003-09-08 20:04:49 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_ABOVE_CHILD,
|
|
|
|
g_param_spec_boolean ("above-child",
|
2004-01-16 23:10:05 +00:00
|
|
|
P_("Above child"),
|
|
|
|
P_("Whether the event-trapping window of the eventbox is above the window of the child widget as opposed to below it."),
|
2003-09-08 20:04:49 +00:00
|
|
|
FALSE,
|
2005-03-22 02:14:55 +00:00
|
|
|
GTK_PARAM_READWRITE));
|
1997-11-24 22:37:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_event_box_init (GtkEventBox *event_box)
|
|
|
|
{
|
2010-01-04 07:41:07 +00:00
|
|
|
gtk_widget_set_has_window (GTK_WIDGET (event_box), TRUE);
|
2011-01-04 15:31:19 +00:00
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
event_box->priv = gtk_event_box_get_instance_private (event_box);
|
|
|
|
event_box->priv->above_child = FALSE;
|
1997-11-24 22:37:52 +00:00
|
|
|
}
|
|
|
|
|
2011-01-04 15:31:19 +00:00
|
|
|
/**
|
|
|
|
* gtk_event_box_new:
|
|
|
|
*
|
|
|
|
* Creates a new #GtkEventBox.
|
|
|
|
*
|
|
|
|
* Returns: a new #GtkEventBox
|
|
|
|
*/
|
1997-11-24 22:37:52 +00:00
|
|
|
GtkWidget*
|
1998-05-03 22:41:32 +00:00
|
|
|
gtk_event_box_new (void)
|
1997-11-24 22:37:52 +00:00
|
|
|
{
|
2002-10-10 22:00:09 +00:00
|
|
|
return g_object_new (GTK_TYPE_EVENT_BOX, NULL);
|
1997-11-24 22:37:52 +00:00
|
|
|
}
|
|
|
|
|
2011-01-04 15:31:19 +00:00
|
|
|
static void
|
2003-09-08 20:04:49 +00:00
|
|
|
gtk_event_box_set_property (GObject *object,
|
2011-01-04 15:31:19 +00:00
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2003-09-08 20:04:49 +00:00
|
|
|
{
|
|
|
|
GtkEventBox *event_box;
|
2011-01-04 15:31:19 +00:00
|
|
|
|
2003-09-08 20:04:49 +00:00
|
|
|
event_box = GTK_EVENT_BOX (object);
|
2011-01-04 15:31:19 +00:00
|
|
|
|
2003-09-08 20:04:49 +00:00
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_VISIBLE_WINDOW:
|
|
|
|
gtk_event_box_set_visible_window (event_box, g_value_get_boolean (value));
|
2011-01-04 15:31:19 +00:00
|
|
|
break;
|
|
|
|
|
2003-09-08 20:04:49 +00:00
|
|
|
case PROP_ABOVE_CHILD:
|
|
|
|
gtk_event_box_set_above_child (event_box, g_value_get_boolean (value));
|
2011-01-04 15:31:19 +00:00
|
|
|
break;
|
|
|
|
|
2003-09-08 20:04:49 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-04 15:31:19 +00:00
|
|
|
static void
|
2003-09-08 20:04:49 +00:00
|
|
|
gtk_event_box_get_property (GObject *object,
|
2011-01-04 15:31:19 +00:00
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2003-09-08 20:04:49 +00:00
|
|
|
{
|
|
|
|
GtkEventBox *event_box;
|
2011-01-04 15:31:19 +00:00
|
|
|
|
2003-09-08 20:04:49 +00:00
|
|
|
event_box = GTK_EVENT_BOX (object);
|
2011-01-04 15:31:19 +00:00
|
|
|
|
2003-09-08 20:04:49 +00:00
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_VISIBLE_WINDOW:
|
|
|
|
g_value_set_boolean (value, gtk_event_box_get_visible_window (event_box));
|
|
|
|
break;
|
2011-01-04 15:31:19 +00:00
|
|
|
|
2003-09-08 20:04:49 +00:00
|
|
|
case PROP_ABOVE_CHILD:
|
|
|
|
g_value_set_boolean (value, gtk_event_box_get_above_child (event_box));
|
|
|
|
break;
|
2011-01-04 15:31:19 +00:00
|
|
|
|
2003-09-08 20:04:49 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_event_box_get_visible_window:
|
|
|
|
* @event_box: a #GtkEventBox
|
|
|
|
*
|
|
|
|
* Returns whether the event box has a visible window.
|
|
|
|
* See gtk_event_box_set_visible_window() for details.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if the event box window is visible
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
2011-01-04 15:31:19 +00:00
|
|
|
*/
|
2003-09-08 20:04:49 +00:00
|
|
|
gboolean
|
|
|
|
gtk_event_box_get_visible_window (GtkEventBox *event_box)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_EVENT_BOX (event_box), FALSE);
|
|
|
|
|
2010-01-04 07:41:07 +00:00
|
|
|
return gtk_widget_get_has_window (GTK_WIDGET (event_box));
|
2003-09-08 20:04:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_event_box_set_visible_window:
|
|
|
|
* @event_box: a #GtkEventBox
|
2011-01-04 15:31:19 +00:00
|
|
|
* @visible_window: %TRUE to make the event box have a visible window
|
2003-09-08 20:04:49 +00:00
|
|
|
*
|
|
|
|
* Set whether the event box uses a visible or invisible child
|
|
|
|
* window. The default is to use visible windows.
|
|
|
|
*
|
2006-09-25 14:48:31 +00:00
|
|
|
* In an invisible window event box, the window that the
|
2011-01-04 15:31:19 +00:00
|
|
|
* event box creates is a %GDK_INPUT_ONLY window, which
|
2003-09-08 20:04:49 +00:00
|
|
|
* means that it is invisible and only serves to receive
|
|
|
|
* events.
|
2011-01-04 15:31:19 +00:00
|
|
|
*
|
2003-09-08 20:04:49 +00:00
|
|
|
* A visible window event box creates a visible (%GDK_INPUT_OUTPUT)
|
2011-01-04 15:31:19 +00:00
|
|
|
* window that acts as the parent window for all the widgets
|
2003-09-08 20:04:49 +00:00
|
|
|
* contained in the event box.
|
2011-01-04 15:31:19 +00:00
|
|
|
*
|
2003-09-08 20:04:49 +00:00
|
|
|
* You should generally make your event box invisible if
|
|
|
|
* you just want to trap events. Creating a visible window
|
|
|
|
* may cause artifacts that are visible to the user, especially
|
|
|
|
* if the user is using a theme with gradients or pixmaps.
|
2011-01-04 15:31:19 +00:00
|
|
|
*
|
2003-09-08 20:04:49 +00:00
|
|
|
* The main reason to create a non input-only event box is if
|
|
|
|
* you want to set the background to a different color or
|
|
|
|
* draw on it.
|
|
|
|
*
|
2003-10-05 20:39:17 +00:00
|
|
|
* <note><para>
|
2003-09-08 20:04:49 +00:00
|
|
|
* There is one unexpected issue for an invisible event box that has its
|
|
|
|
* window below the child. (See gtk_event_box_set_above_child().)
|
|
|
|
* Since the input-only window is not an ancestor window of any windows
|
2011-01-04 15:31:19 +00:00
|
|
|
* that descendent widgets of the event box create, events on these
|
2003-09-08 20:04:49 +00:00
|
|
|
* windows aren't propagated up by the windowing system, but only by GTK+.
|
|
|
|
* The practical effect of this is if an event isn't in the event
|
2011-01-04 15:31:19 +00:00
|
|
|
* mask for the descendant window (see gtk_widget_add_events()),
|
|
|
|
* it won't be received by the event box.
|
2003-10-05 20:39:17 +00:00
|
|
|
* </para><para>
|
2003-09-08 20:04:49 +00:00
|
|
|
* This problem doesn't occur for visible event boxes, because in
|
|
|
|
* that case, the event box window is actually the ancestor of the
|
|
|
|
* descendant windows, not just at the same place on the screen.
|
2003-10-05 20:39:17 +00:00
|
|
|
* </para></note>
|
2011-01-04 15:31:19 +00:00
|
|
|
*
|
2003-09-08 20:04:49 +00:00
|
|
|
* Since: 2.4
|
2011-01-04 15:31:19 +00:00
|
|
|
*/
|
2003-09-08 20:04:49 +00:00
|
|
|
void
|
|
|
|
gtk_event_box_set_visible_window (GtkEventBox *event_box,
|
2011-01-04 15:31:19 +00:00
|
|
|
gboolean visible_window)
|
2003-09-08 20:04:49 +00:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_EVENT_BOX (event_box));
|
|
|
|
|
|
|
|
widget = GTK_WIDGET (event_box);
|
|
|
|
|
|
|
|
visible_window = visible_window != FALSE;
|
|
|
|
|
2010-01-04 07:41:07 +00:00
|
|
|
if (visible_window != gtk_widget_get_has_window (widget))
|
2003-09-08 20:04:49 +00:00
|
|
|
{
|
2010-03-02 06:16:02 +00:00
|
|
|
if (gtk_widget_get_realized (widget))
|
2011-01-04 15:31:19 +00:00
|
|
|
{
|
|
|
|
gboolean visible = gtk_widget_get_visible (widget);
|
2003-09-08 20:04:49 +00:00
|
|
|
|
2011-01-04 15:31:19 +00:00
|
|
|
if (visible)
|
|
|
|
gtk_widget_hide (widget);
|
2003-09-08 20:04:49 +00:00
|
|
|
|
2011-01-04 15:31:19 +00:00
|
|
|
gtk_widget_unrealize (widget);
|
2003-09-08 20:04:49 +00:00
|
|
|
|
2010-01-04 07:41:07 +00:00
|
|
|
gtk_widget_set_has_window (widget, visible_window);
|
|
|
|
|
2011-01-04 15:31:19 +00:00
|
|
|
gtk_widget_realize (widget);
|
2003-09-08 20:04:49 +00:00
|
|
|
|
2011-01-04 15:31:19 +00:00
|
|
|
if (visible)
|
|
|
|
gtk_widget_show (widget);
|
|
|
|
}
|
2003-09-08 20:04:49 +00:00
|
|
|
else
|
2011-01-04 15:31:19 +00:00
|
|
|
{
|
2010-01-04 07:41:07 +00:00
|
|
|
gtk_widget_set_has_window (widget, visible_window);
|
2011-01-04 15:31:19 +00:00
|
|
|
}
|
2003-09-08 20:04:49 +00:00
|
|
|
|
2010-03-01 06:47:38 +00:00
|
|
|
if (gtk_widget_get_visible (widget))
|
2011-01-04 15:31:19 +00:00
|
|
|
gtk_widget_queue_resize (widget);
|
|
|
|
|
2003-09-08 20:04:49 +00:00
|
|
|
g_object_notify (G_OBJECT (event_box), "visible-window");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_event_box_get_above_child:
|
|
|
|
* @event_box: a #GtkEventBox
|
|
|
|
*
|
|
|
|
* Returns whether the event box window is above or below the
|
2011-01-04 15:31:19 +00:00
|
|
|
* windows of its child. See gtk_event_box_set_above_child()
|
|
|
|
* for details.
|
2003-09-08 20:04:49 +00:00
|
|
|
*
|
2011-01-04 15:31:19 +00:00
|
|
|
* Return value: %TRUE if the event box window is above the
|
|
|
|
* window of its child
|
2003-09-08 20:04:49 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2011-01-04 15:31:19 +00:00
|
|
|
*/
|
2003-09-08 20:04:49 +00:00
|
|
|
gboolean
|
|
|
|
gtk_event_box_get_above_child (GtkEventBox *event_box)
|
|
|
|
{
|
2011-01-04 15:31:19 +00:00
|
|
|
GtkEventBoxPrivate *priv = event_box->priv;
|
2003-09-08 20:04:49 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_EVENT_BOX (event_box), FALSE);
|
|
|
|
|
|
|
|
return priv->above_child;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_event_box_set_above_child:
|
|
|
|
* @event_box: a #GtkEventBox
|
2011-01-04 15:31:19 +00:00
|
|
|
* @above_child: %TRUE if the event box window is above its child
|
2003-09-08 20:04:49 +00:00
|
|
|
*
|
2011-01-04 15:31:19 +00:00
|
|
|
* Set whether the event box window is positioned above the windows
|
|
|
|
* of its child, as opposed to below it. If the window is above, all
|
|
|
|
* events inside the event box will go to the event box. If the window
|
|
|
|
* is below, events in windows of child widgets will first got to that
|
|
|
|
* widget, and then to its parents.
|
2003-09-08 20:04:49 +00:00
|
|
|
*
|
|
|
|
* The default is to keep the window below the child.
|
2011-01-04 15:31:19 +00:00
|
|
|
*
|
2003-09-08 20:04:49 +00:00
|
|
|
* Since: 2.4
|
2011-01-04 15:31:19 +00:00
|
|
|
*/
|
2003-09-08 20:04:49 +00:00
|
|
|
void
|
|
|
|
gtk_event_box_set_above_child (GtkEventBox *event_box,
|
2011-01-04 15:31:19 +00:00
|
|
|
gboolean above_child)
|
2003-09-08 20:04:49 +00:00
|
|
|
{
|
2011-01-04 15:31:19 +00:00
|
|
|
GtkEventBoxPrivate *priv = event_box->priv;
|
2003-09-08 20:04:49 +00:00
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_EVENT_BOX (event_box));
|
|
|
|
|
|
|
|
widget = GTK_WIDGET (event_box);
|
|
|
|
|
|
|
|
above_child = above_child != FALSE;
|
|
|
|
|
|
|
|
if (priv->above_child != above_child)
|
|
|
|
{
|
2003-11-09 23:41:15 +00:00
|
|
|
priv->above_child = above_child;
|
|
|
|
|
2010-03-02 06:16:02 +00:00
|
|
|
if (gtk_widget_get_realized (widget))
|
2011-01-04 15:31:19 +00:00
|
|
|
{
|
|
|
|
if (!gtk_widget_get_has_window (widget))
|
|
|
|
{
|
|
|
|
if (above_child)
|
|
|
|
gdk_window_raise (priv->event_window);
|
|
|
|
else
|
|
|
|
gdk_window_lower (priv->event_window);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gboolean visible = gtk_widget_get_visible (widget);
|
|
|
|
|
|
|
|
if (visible)
|
|
|
|
gtk_widget_hide (widget);
|
|
|
|
|
|
|
|
gtk_widget_unrealize (widget);
|
|
|
|
gtk_widget_realize (widget);
|
|
|
|
|
|
|
|
if (visible)
|
|
|
|
gtk_widget_show (widget);
|
|
|
|
}
|
|
|
|
}
|
2003-09-08 20:04:49 +00:00
|
|
|
|
2010-03-01 06:47:38 +00:00
|
|
|
if (gtk_widget_get_visible (widget))
|
2011-01-04 15:31:19 +00:00
|
|
|
gtk_widget_queue_resize (widget);
|
|
|
|
|
2003-09-08 20:04:49 +00:00
|
|
|
g_object_notify (G_OBJECT (event_box), "above-child");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
static void
|
|
|
|
gtk_event_box_realize (GtkWidget *widget)
|
|
|
|
{
|
2011-01-04 15:31:19 +00:00
|
|
|
GtkEventBoxPrivate *priv;
|
2010-08-11 21:13:11 +00:00
|
|
|
GtkAllocation allocation;
|
|
|
|
GdkWindow *window;
|
1997-11-24 22:37:52 +00:00
|
|
|
GdkWindowAttr attributes;
|
|
|
|
gint attributes_mask;
|
2003-09-08 20:04:49 +00:00
|
|
|
gboolean visible_window;
|
1997-11-24 22:37:52 +00:00
|
|
|
|
2010-08-11 21:13:11 +00:00
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
|
2010-03-06 10:51:33 +00:00
|
|
|
gtk_widget_set_realized (widget, TRUE);
|
1997-11-24 22:37:52 +00:00
|
|
|
|
2010-10-15 02:34:39 +00:00
|
|
|
attributes.x = allocation.x;
|
|
|
|
attributes.y = allocation.y;
|
|
|
|
attributes.width = allocation.width;
|
|
|
|
attributes.height = allocation.height;
|
1997-11-24 22:37:52 +00:00
|
|
|
attributes.window_type = GDK_WINDOW_CHILD;
|
|
|
|
attributes.event_mask = gtk_widget_get_events (widget)
|
2011-01-04 15:31:19 +00:00
|
|
|
| GDK_BUTTON_MOTION_MASK
|
|
|
|
| GDK_BUTTON_PRESS_MASK
|
|
|
|
| GDK_BUTTON_RELEASE_MASK
|
|
|
|
| GDK_EXPOSURE_MASK
|
|
|
|
| GDK_ENTER_NOTIFY_MASK
|
|
|
|
| GDK_LEAVE_NOTIFY_MASK;
|
1997-11-24 22:37:52 +00:00
|
|
|
|
2011-01-04 15:31:19 +00:00
|
|
|
priv = GTK_EVENT_BOX (widget)->priv;
|
2003-09-08 20:04:49 +00:00
|
|
|
|
2010-01-04 07:41:07 +00:00
|
|
|
visible_window = gtk_widget_get_has_window (widget);
|
2003-09-08 20:04:49 +00:00
|
|
|
if (visible_window)
|
|
|
|
{
|
|
|
|
attributes.visual = gtk_widget_get_visual (widget);
|
|
|
|
attributes.wclass = GDK_INPUT_OUTPUT;
|
2010-10-15 02:34:39 +00:00
|
|
|
|
2010-08-28 16:04:08 +00:00
|
|
|
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
|
2010-08-11 21:13:11 +00:00
|
|
|
|
|
|
|
window = gdk_window_new (gtk_widget_get_parent_window (widget),
|
|
|
|
&attributes, attributes_mask);
|
|
|
|
gtk_widget_set_window (widget, window);
|
2013-02-05 08:36:49 +00:00
|
|
|
gtk_widget_register_window (widget, window);
|
2003-09-08 20:04:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-11 21:13:11 +00:00
|
|
|
window = gtk_widget_get_parent_window (widget);
|
|
|
|
gtk_widget_set_window (widget, window);
|
|
|
|
g_object_ref (window);
|
2003-09-08 20:04:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!visible_window || priv->above_child)
|
|
|
|
{
|
|
|
|
attributes.wclass = GDK_INPUT_ONLY;
|
2007-04-28 21:45:39 +00:00
|
|
|
if (!visible_window)
|
|
|
|
attributes_mask = GDK_WA_X | GDK_WA_Y;
|
|
|
|
else
|
|
|
|
attributes_mask = 0;
|
2003-09-08 20:04:49 +00:00
|
|
|
|
2010-08-11 21:13:11 +00:00
|
|
|
priv->event_window = gdk_window_new (window,
|
2011-01-04 15:31:19 +00:00
|
|
|
&attributes, attributes_mask);
|
2013-02-05 08:36:49 +00:00
|
|
|
gtk_widget_register_window (widget, priv->event_window);
|
2003-09-08 20:04:49 +00:00
|
|
|
}
|
1997-11-24 22:37:52 +00:00
|
|
|
|
2003-09-08 20:04:49 +00:00
|
|
|
if (visible_window)
|
2010-12-28 16:39:08 +00:00
|
|
|
gtk_style_context_set_background (gtk_widget_get_style_context (widget), window);
|
2003-09-08 20:04:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_event_box_unrealize (GtkWidget *widget)
|
|
|
|
{
|
2011-01-04 15:31:19 +00:00
|
|
|
GtkEventBoxPrivate *priv = GTK_EVENT_BOX (widget)->priv;
|
|
|
|
|
2003-09-08 20:04:49 +00:00
|
|
|
if (priv->event_window != NULL)
|
|
|
|
{
|
2013-02-05 08:36:49 +00:00
|
|
|
gtk_widget_unregister_window (widget, priv->event_window);
|
2003-09-08 20:04:49 +00:00
|
|
|
gdk_window_destroy (priv->event_window);
|
|
|
|
priv->event_window = NULL;
|
|
|
|
}
|
|
|
|
|
2008-08-12 09:44:32 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_event_box_parent_class)->unrealize (widget);
|
1997-11-24 22:37:52 +00:00
|
|
|
}
|
|
|
|
|
2003-09-08 20:04:49 +00:00
|
|
|
static void
|
|
|
|
gtk_event_box_map (GtkWidget *widget)
|
|
|
|
{
|
2011-01-04 15:31:19 +00:00
|
|
|
GtkEventBoxPrivate *priv = GTK_EVENT_BOX (widget)->priv;
|
2003-09-08 20:04:49 +00:00
|
|
|
|
|
|
|
if (priv->event_window != NULL && !priv->above_child)
|
|
|
|
gdk_window_show (priv->event_window);
|
2008-08-12 09:06:34 +00:00
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_event_box_parent_class)->map (widget);
|
2003-09-08 20:04:49 +00:00
|
|
|
|
|
|
|
if (priv->event_window != NULL && priv->above_child)
|
|
|
|
gdk_window_show (priv->event_window);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_event_box_unmap (GtkWidget *widget)
|
|
|
|
{
|
2011-01-04 15:31:19 +00:00
|
|
|
GtkEventBoxPrivate *priv = GTK_EVENT_BOX (widget)->priv;
|
2003-09-08 20:04:49 +00:00
|
|
|
|
|
|
|
if (priv->event_window != NULL)
|
|
|
|
gdk_window_hide (priv->event_window);
|
2008-08-12 09:06:34 +00:00
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_event_box_parent_class)->unmap (widget);
|
2003-09-08 20:04:49 +00:00
|
|
|
}
|
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
static void
|
2010-10-15 03:03:39 +00:00
|
|
|
gtk_event_box_get_preferred_width (GtkWidget *widget,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural)
|
1997-11-24 22:37:52 +00:00
|
|
|
{
|
2002-01-30 22:29:03 +00:00
|
|
|
GtkBin *bin = GTK_BIN (widget);
|
2010-05-24 20:31:36 +00:00
|
|
|
GtkWidget *child;
|
1997-11-24 22:37:52 +00:00
|
|
|
|
2010-10-15 03:03:39 +00:00
|
|
|
if (minimum)
|
|
|
|
*minimum = 0;
|
|
|
|
|
|
|
|
if (natural)
|
|
|
|
*natural = 0;
|
1997-11-24 22:37:52 +00:00
|
|
|
|
2010-05-24 20:31:36 +00:00
|
|
|
child = gtk_bin_get_child (bin);
|
|
|
|
if (child && gtk_widget_get_visible (child))
|
2010-10-15 03:03:39 +00:00
|
|
|
gtk_widget_get_preferred_width (child, minimum, natural);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-03-26 10:08:33 +00:00
|
|
|
gtk_event_box_get_preferred_height_and_baseline_for_width (GtkWidget *widget,
|
|
|
|
gint width,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural,
|
|
|
|
gint *minimum_baseline,
|
|
|
|
gint *natural_baseline)
|
2010-10-15 03:03:39 +00:00
|
|
|
{
|
|
|
|
GtkBin *bin = GTK_BIN (widget);
|
|
|
|
GtkWidget *child;
|
2010-09-14 01:33:06 +00:00
|
|
|
|
2010-10-15 03:03:39 +00:00
|
|
|
if (minimum)
|
|
|
|
*minimum = 0;
|
1997-11-24 22:37:52 +00:00
|
|
|
|
2010-10-15 03:03:39 +00:00
|
|
|
if (natural)
|
|
|
|
*natural = 0;
|
|
|
|
|
2013-03-26 10:08:33 +00:00
|
|
|
if (minimum_baseline)
|
|
|
|
*minimum_baseline = -1;
|
|
|
|
|
|
|
|
if (natural_baseline)
|
|
|
|
*natural_baseline = -1;
|
|
|
|
|
2010-10-15 03:03:39 +00:00
|
|
|
child = gtk_bin_get_child (bin);
|
|
|
|
if (child && gtk_widget_get_visible (child))
|
2013-03-26 10:08:33 +00:00
|
|
|
gtk_widget_get_preferred_height_and_baseline_for_width (child,
|
2013-05-06 15:48:46 +00:00
|
|
|
width,
|
2013-03-26 10:08:33 +00:00
|
|
|
minimum,
|
|
|
|
natural,
|
|
|
|
minimum_baseline,
|
|
|
|
natural_baseline);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_event_box_get_preferred_height (GtkWidget *widget,
|
|
|
|
gint *minimum,
|
|
|
|
gint *natural)
|
|
|
|
{
|
|
|
|
gtk_event_box_get_preferred_height_and_baseline_for_width (widget, -1,
|
|
|
|
minimum, natural,
|
|
|
|
NULL, NULL);
|
1997-11-24 22:37:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_event_box_size_allocate (GtkWidget *widget,
|
2010-10-15 03:03:39 +00:00
|
|
|
GtkAllocation *allocation)
|
1997-11-24 22:37:52 +00:00
|
|
|
{
|
|
|
|
GtkBin *bin;
|
|
|
|
GtkAllocation child_allocation;
|
2013-03-26 10:08:33 +00:00
|
|
|
gint baseline;
|
2003-09-08 20:04:49 +00:00
|
|
|
GtkEventBoxPrivate *priv;
|
2010-05-24 20:31:36 +00:00
|
|
|
GtkWidget *child;
|
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
bin = GTK_BIN (widget);
|
2010-08-11 21:13:11 +00:00
|
|
|
|
|
|
|
gtk_widget_set_allocation (widget, allocation);
|
|
|
|
|
2010-01-04 07:41:07 +00:00
|
|
|
if (!gtk_widget_get_has_window (widget))
|
2003-09-08 20:04:49 +00:00
|
|
|
{
|
2010-10-15 02:34:39 +00:00
|
|
|
child_allocation.x = allocation->x;
|
|
|
|
child_allocation.y = allocation->y;
|
2003-09-08 20:04:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
child_allocation.x = 0;
|
|
|
|
child_allocation.y = 0;
|
|
|
|
}
|
2010-10-15 02:34:39 +00:00
|
|
|
child_allocation.width = allocation->width;
|
|
|
|
child_allocation.height = allocation->height;
|
1997-11-24 22:37:52 +00:00
|
|
|
|
2010-03-02 06:16:02 +00:00
|
|
|
if (gtk_widget_get_realized (widget))
|
1997-11-24 22:37:52 +00:00
|
|
|
{
|
2011-01-04 15:31:19 +00:00
|
|
|
priv = GTK_EVENT_BOX (widget)->priv;
|
2003-09-08 20:04:49 +00:00
|
|
|
|
|
|
|
if (priv->event_window != NULL)
|
2011-01-04 15:31:19 +00:00
|
|
|
gdk_window_move_resize (priv->event_window,
|
|
|
|
child_allocation.x,
|
|
|
|
child_allocation.y,
|
|
|
|
child_allocation.width,
|
|
|
|
child_allocation.height);
|
|
|
|
|
2010-01-04 07:41:07 +00:00
|
|
|
if (gtk_widget_get_has_window (widget))
|
2011-01-04 15:31:19 +00:00
|
|
|
gdk_window_move_resize (gtk_widget_get_window (widget),
|
|
|
|
allocation->x,
|
|
|
|
allocation->y,
|
|
|
|
child_allocation.width,
|
|
|
|
child_allocation.height);
|
1997-11-24 22:37:52 +00:00
|
|
|
}
|
2010-05-24 20:31:36 +00:00
|
|
|
|
2013-03-26 10:08:33 +00:00
|
|
|
baseline = gtk_widget_get_allocated_baseline (widget);
|
2010-05-24 20:31:36 +00:00
|
|
|
child = gtk_bin_get_child (bin);
|
|
|
|
if (child)
|
2013-03-26 10:08:33 +00:00
|
|
|
gtk_widget_size_allocate_with_baseline (child, &child_allocation, baseline);
|
1997-11-24 22:37:52 +00:00
|
|
|
}
|
|
|
|
|
2010-09-07 17:29:03 +00:00
|
|
|
static gboolean
|
2011-01-04 15:31:19 +00:00
|
|
|
gtk_event_box_draw (GtkWidget *widget,
|
|
|
|
cairo_t *cr)
|
1999-01-15 16:00:39 +00:00
|
|
|
{
|
2010-09-07 17:29:03 +00:00
|
|
|
if (gtk_widget_get_has_window (widget) &&
|
|
|
|
!gtk_widget_get_app_paintable (widget))
|
2010-12-28 16:39:08 +00:00
|
|
|
{
|
|
|
|
GtkStyleContext *context;
|
|
|
|
|
|
|
|
context = gtk_widget_get_style_context (widget);
|
2011-01-14 15:55:46 +00:00
|
|
|
|
2010-12-28 16:39:08 +00:00
|
|
|
gtk_render_background (context, cr, 0, 0,
|
|
|
|
gtk_widget_get_allocated_width (widget),
|
|
|
|
gtk_widget_get_allocated_height (widget));
|
2013-11-02 11:18:25 +00:00
|
|
|
gtk_render_frame (context, cr, 0, 0,
|
|
|
|
gtk_widget_get_allocated_width (widget),
|
|
|
|
gtk_widget_get_allocated_height (widget));
|
2010-12-28 16:39:08 +00:00
|
|
|
}
|
2011-01-04 15:31:19 +00:00
|
|
|
|
2010-09-07 18:13:50 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_event_box_parent_class)->draw (widget, cr);
|
1997-11-24 22:37:52 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|