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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29 #include "gtkinvisible.h"
30 #include "gtkwidgetprivate.h"
31 #include "gtkprivate.h"
36 * SECTION:gtkinvisible
37 * @Short_description: A widget which is not displayed
38 * @Title: GtkInvisible
40 * The #GtkInvisible widget is used internally in GTK+, and is probably not
41 * very useful for application developers.
43 * It is used for reliable pointer grabs and selection handling in the code
48 struct _GtkInvisiblePrivate
51 gboolean has_user_ref_count;
60 static void gtk_invisible_destroy (GtkWidget *widget);
61 static void gtk_invisible_realize (GtkWidget *widget);
62 static void gtk_invisible_style_updated (GtkWidget *widget);
63 static void gtk_invisible_show (GtkWidget *widget);
64 static void gtk_invisible_size_allocate (GtkWidget *widget,
65 GtkAllocation *allocation);
66 static void gtk_invisible_set_property (GObject *object,
70 static void gtk_invisible_get_property (GObject *object,
75 static GObject *gtk_invisible_constructor (GType type,
76 guint n_construct_properties,
77 GObjectConstructParam *construct_params);
79 G_DEFINE_TYPE (GtkInvisible, gtk_invisible, GTK_TYPE_WIDGET)
82 gtk_invisible_class_init (GtkInvisibleClass *class)
84 GObjectClass *gobject_class;
85 GtkWidgetClass *widget_class;
87 widget_class = (GtkWidgetClass*) class;
88 gobject_class = (GObjectClass*) class;
90 widget_class->realize = gtk_invisible_realize;
91 widget_class->style_updated = gtk_invisible_style_updated;
92 widget_class->show = gtk_invisible_show;
93 widget_class->size_allocate = gtk_invisible_size_allocate;
94 widget_class->destroy = gtk_invisible_destroy;
96 gobject_class->set_property = gtk_invisible_set_property;
97 gobject_class->get_property = gtk_invisible_get_property;
98 gobject_class->constructor = gtk_invisible_constructor;
100 g_object_class_install_property (gobject_class,
102 g_param_spec_object ("screen",
104 P_("The screen where this window will be displayed"),
106 GTK_PARAM_READWRITE));
108 g_type_class_add_private (class, sizeof (GtkInvisiblePrivate));
112 gtk_invisible_init (GtkInvisible *invisible)
114 GtkInvisiblePrivate *priv;
116 invisible->priv = G_TYPE_INSTANCE_GET_PRIVATE (invisible,
118 GtkInvisiblePrivate);
119 priv = invisible->priv;
121 gtk_widget_set_has_window (GTK_WIDGET (invisible), TRUE);
122 _gtk_widget_set_is_toplevel (GTK_WIDGET (invisible), TRUE);
124 g_object_ref_sink (invisible);
126 priv->has_user_ref_count = TRUE;
127 priv->screen = gdk_screen_get_default ();
131 gtk_invisible_destroy (GtkWidget *widget)
133 GtkInvisible *invisible = GTK_INVISIBLE (widget);
134 GtkInvisiblePrivate *priv = invisible->priv;
136 if (priv->has_user_ref_count)
138 priv->has_user_ref_count = FALSE;
139 g_object_unref (invisible);
142 GTK_WIDGET_CLASS (gtk_invisible_parent_class)->destroy (widget);
146 * gtk_invisible_new_for_screen:
147 * @screen: a #GdkScreen which identifies on which
148 * the new #GtkInvisible will be created.
150 * Creates a new #GtkInvisible object for a specified screen
152 * Return value: a newly created #GtkInvisible object
157 gtk_invisible_new_for_screen (GdkScreen *screen)
159 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
161 return g_object_new (GTK_TYPE_INVISIBLE, "screen", screen, NULL);
167 * Creates a new #GtkInvisible.
169 * Return value: a new #GtkInvisible.
172 gtk_invisible_new (void)
174 return g_object_new (GTK_TYPE_INVISIBLE, NULL);
178 * gtk_invisible_set_screen:
179 * @invisible: a #GtkInvisible.
180 * @screen: a #GdkScreen.
182 * Sets the #GdkScreen where the #GtkInvisible object will be displayed.
187 gtk_invisible_set_screen (GtkInvisible *invisible,
190 GtkInvisiblePrivate *priv;
192 GdkScreen *previous_screen;
193 gboolean was_realized;
195 g_return_if_fail (GTK_IS_INVISIBLE (invisible));
196 g_return_if_fail (GDK_IS_SCREEN (screen));
198 priv = invisible->priv;
200 if (screen == priv->screen)
203 widget = GTK_WIDGET (invisible);
205 previous_screen = priv->screen;
206 was_realized = gtk_widget_get_realized (widget);
209 gtk_widget_unrealize (widget);
211 priv->screen = screen;
212 if (screen != previous_screen)
213 _gtk_widget_propagate_screen_changed (widget, previous_screen);
214 g_object_notify (G_OBJECT (invisible), "screen");
217 gtk_widget_realize (widget);
221 * gtk_invisible_get_screen:
222 * @invisible: a #GtkInvisible.
224 * Returns the #GdkScreen object associated with @invisible
226 * Return value: (transfer none): the associated #GdkScreen.
231 gtk_invisible_get_screen (GtkInvisible *invisible)
233 g_return_val_if_fail (GTK_IS_INVISIBLE (invisible), NULL);
235 return invisible->priv->screen;
239 gtk_invisible_realize (GtkWidget *widget)
243 GdkWindowAttr attributes;
244 gint attributes_mask;
246 gtk_widget_set_realized (widget, TRUE);
248 parent = gtk_widget_get_parent_window (widget);
250 parent = gtk_widget_get_root_window (widget);
254 attributes.width = 10;
255 attributes.height = 10;
256 attributes.window_type = GDK_WINDOW_TEMP;
257 attributes.wclass = GDK_INPUT_ONLY;
258 attributes.override_redirect = TRUE;
259 attributes.event_mask = gtk_widget_get_events (widget);
261 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
263 window = gdk_window_new (parent, &attributes, attributes_mask);
264 gtk_widget_set_window (widget, window);
265 gdk_window_set_user_data (window, widget);
269 gtk_invisible_style_updated (GtkWidget *widget)
271 /* Don't chain up to parent implementation */
275 gtk_invisible_show (GtkWidget *widget)
277 _gtk_widget_set_visible_flag (widget, TRUE);
278 gtk_widget_map (widget);
282 gtk_invisible_size_allocate (GtkWidget *widget,
283 GtkAllocation *allocation)
285 gtk_widget_set_allocation (widget, allocation);
290 gtk_invisible_set_property (GObject *object,
295 GtkInvisible *invisible = GTK_INVISIBLE (object);
300 gtk_invisible_set_screen (invisible, g_value_get_object (value));
303 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
309 gtk_invisible_get_property (GObject *object,
314 GtkInvisible *invisible = GTK_INVISIBLE (object);
315 GtkInvisiblePrivate *priv = invisible->priv;
320 g_value_set_object (value, priv->screen);
323 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
328 /* We use a constructor here so that we can realize the invisible on
329 * the correct screen after the "screen" property has been set
332 gtk_invisible_constructor (GType type,
333 guint n_construct_properties,
334 GObjectConstructParam *construct_params)
338 object = G_OBJECT_CLASS (gtk_invisible_parent_class)->constructor (type,
339 n_construct_properties,
342 gtk_widget_realize (GTK_WIDGET (object));