1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #include "gtkinvisible.h"
28 #include "gtkwidgetprivate.h"
29 #include "gtkprivate.h"
34 * SECTION:gtkinvisible
35 * @Short_description: A widget which is not displayed
36 * @Title: GtkInvisible
38 * The #GtkInvisible widget is used internally in GTK+, and is probably not
39 * very useful for application developers.
41 * It is used for reliable pointer grabs and selection handling in the code
46 struct _GtkInvisiblePrivate
49 gboolean has_user_ref_count;
58 static void gtk_invisible_destroy (GtkWidget *widget);
59 static void gtk_invisible_realize (GtkWidget *widget);
60 static void gtk_invisible_style_updated (GtkWidget *widget);
61 static void gtk_invisible_show (GtkWidget *widget);
62 static void gtk_invisible_size_allocate (GtkWidget *widget,
63 GtkAllocation *allocation);
64 static void gtk_invisible_set_property (GObject *object,
68 static void gtk_invisible_get_property (GObject *object,
73 static GObject *gtk_invisible_constructor (GType type,
74 guint n_construct_properties,
75 GObjectConstructParam *construct_params);
77 G_DEFINE_TYPE (GtkInvisible, gtk_invisible, GTK_TYPE_WIDGET)
80 gtk_invisible_class_init (GtkInvisibleClass *class)
82 GObjectClass *gobject_class;
83 GtkWidgetClass *widget_class;
85 widget_class = (GtkWidgetClass*) class;
86 gobject_class = (GObjectClass*) class;
88 widget_class->realize = gtk_invisible_realize;
89 widget_class->style_updated = gtk_invisible_style_updated;
90 widget_class->show = gtk_invisible_show;
91 widget_class->size_allocate = gtk_invisible_size_allocate;
92 widget_class->destroy = gtk_invisible_destroy;
94 gobject_class->set_property = gtk_invisible_set_property;
95 gobject_class->get_property = gtk_invisible_get_property;
96 gobject_class->constructor = gtk_invisible_constructor;
98 g_object_class_install_property (gobject_class,
100 g_param_spec_object ("screen",
102 P_("The screen where this window will be displayed"),
104 GTK_PARAM_READWRITE));
106 g_type_class_add_private (class, sizeof (GtkInvisiblePrivate));
110 gtk_invisible_init (GtkInvisible *invisible)
112 GtkInvisiblePrivate *priv;
114 invisible->priv = G_TYPE_INSTANCE_GET_PRIVATE (invisible,
116 GtkInvisiblePrivate);
117 priv = invisible->priv;
119 gtk_widget_set_has_window (GTK_WIDGET (invisible), TRUE);
120 _gtk_widget_set_is_toplevel (GTK_WIDGET (invisible), TRUE);
122 g_object_ref_sink (invisible);
124 priv->has_user_ref_count = TRUE;
125 priv->screen = gdk_screen_get_default ();
129 gtk_invisible_destroy (GtkWidget *widget)
131 GtkInvisible *invisible = GTK_INVISIBLE (widget);
132 GtkInvisiblePrivate *priv = invisible->priv;
134 if (priv->has_user_ref_count)
136 priv->has_user_ref_count = FALSE;
137 g_object_unref (invisible);
140 GTK_WIDGET_CLASS (gtk_invisible_parent_class)->destroy (widget);
144 * gtk_invisible_new_for_screen:
145 * @screen: a #GdkScreen which identifies on which
146 * the new #GtkInvisible will be created.
148 * Creates a new #GtkInvisible object for a specified screen
150 * Return value: a newly created #GtkInvisible object
155 gtk_invisible_new_for_screen (GdkScreen *screen)
157 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
159 return g_object_new (GTK_TYPE_INVISIBLE, "screen", screen, NULL);
165 * Creates a new #GtkInvisible.
167 * Return value: a new #GtkInvisible.
170 gtk_invisible_new (void)
172 return g_object_new (GTK_TYPE_INVISIBLE, NULL);
176 * gtk_invisible_set_screen:
177 * @invisible: a #GtkInvisible.
178 * @screen: a #GdkScreen.
180 * Sets the #GdkScreen where the #GtkInvisible object will be displayed.
185 gtk_invisible_set_screen (GtkInvisible *invisible,
188 GtkInvisiblePrivate *priv;
190 GdkScreen *previous_screen;
191 gboolean was_realized;
193 g_return_if_fail (GTK_IS_INVISIBLE (invisible));
194 g_return_if_fail (GDK_IS_SCREEN (screen));
196 priv = invisible->priv;
198 if (screen == priv->screen)
201 widget = GTK_WIDGET (invisible);
203 previous_screen = priv->screen;
204 was_realized = gtk_widget_get_realized (widget);
207 gtk_widget_unrealize (widget);
209 priv->screen = screen;
210 if (screen != previous_screen)
211 _gtk_widget_propagate_screen_changed (widget, previous_screen);
212 g_object_notify (G_OBJECT (invisible), "screen");
215 gtk_widget_realize (widget);
219 * gtk_invisible_get_screen:
220 * @invisible: a #GtkInvisible.
222 * Returns the #GdkScreen object associated with @invisible
224 * Return value: (transfer none): the associated #GdkScreen.
229 gtk_invisible_get_screen (GtkInvisible *invisible)
231 g_return_val_if_fail (GTK_IS_INVISIBLE (invisible), NULL);
233 return invisible->priv->screen;
237 gtk_invisible_realize (GtkWidget *widget)
241 GdkWindowAttr attributes;
242 gint attributes_mask;
244 gtk_widget_set_realized (widget, TRUE);
246 parent = gtk_widget_get_parent_window (widget);
248 parent = gtk_widget_get_root_window (widget);
252 attributes.width = 10;
253 attributes.height = 10;
254 attributes.window_type = GDK_WINDOW_TEMP;
255 attributes.wclass = GDK_INPUT_ONLY;
256 attributes.override_redirect = TRUE;
257 attributes.event_mask = gtk_widget_get_events (widget);
259 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
261 window = gdk_window_new (parent, &attributes, attributes_mask);
262 gtk_widget_set_window (widget, window);
263 gdk_window_set_user_data (window, widget);
267 gtk_invisible_style_updated (GtkWidget *widget)
269 /* Don't chain up to parent implementation */
273 gtk_invisible_show (GtkWidget *widget)
275 _gtk_widget_set_visible_flag (widget, TRUE);
276 gtk_widget_map (widget);
280 gtk_invisible_size_allocate (GtkWidget *widget,
281 GtkAllocation *allocation)
283 gtk_widget_set_allocation (widget, allocation);
288 gtk_invisible_set_property (GObject *object,
293 GtkInvisible *invisible = GTK_INVISIBLE (object);
298 gtk_invisible_set_screen (invisible, g_value_get_object (value));
301 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
307 gtk_invisible_get_property (GObject *object,
312 GtkInvisible *invisible = GTK_INVISIBLE (object);
313 GtkInvisiblePrivate *priv = invisible->priv;
318 g_value_set_object (value, priv->screen);
321 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
326 /* We use a constructor here so that we can realize the invisible on
327 * the correct screen after the "screen" property has been set
330 gtk_invisible_constructor (GType type,
331 guint n_construct_properties,
332 GObjectConstructParam *construct_params)
336 object = G_OBJECT_CLASS (gtk_invisible_parent_class)->constructor (type,
337 n_construct_properties,
340 gtk_widget_realize (GTK_WIDGET (object));