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"
34 struct _GtkInvisiblePrivate
37 gboolean has_user_ref_count;
46 static void gtk_invisible_destroy (GtkWidget *widget);
47 static void gtk_invisible_realize (GtkWidget *widget);
48 static void gtk_invisible_style_set (GtkWidget *widget,
49 GtkStyle *previous_style);
50 static void gtk_invisible_show (GtkWidget *widget);
51 static void gtk_invisible_size_allocate (GtkWidget *widget,
52 GtkAllocation *allocation);
53 static void gtk_invisible_set_property (GObject *object,
57 static void gtk_invisible_get_property (GObject *object,
62 static GObject *gtk_invisible_constructor (GType type,
63 guint n_construct_properties,
64 GObjectConstructParam *construct_params);
66 G_DEFINE_TYPE (GtkInvisible, gtk_invisible, GTK_TYPE_WIDGET)
69 gtk_invisible_class_init (GtkInvisibleClass *class)
71 GObjectClass *gobject_class;
72 GtkWidgetClass *widget_class;
74 widget_class = (GtkWidgetClass*) class;
75 gobject_class = (GObjectClass*) class;
77 widget_class->realize = gtk_invisible_realize;
78 widget_class->style_set = gtk_invisible_style_set;
79 widget_class->show = gtk_invisible_show;
80 widget_class->size_allocate = gtk_invisible_size_allocate;
81 widget_class->destroy = gtk_invisible_destroy;
83 gobject_class->set_property = gtk_invisible_set_property;
84 gobject_class->get_property = gtk_invisible_get_property;
85 gobject_class->constructor = gtk_invisible_constructor;
87 g_object_class_install_property (gobject_class,
89 g_param_spec_object ("screen",
91 P_("The screen where this window will be displayed"),
93 GTK_PARAM_READWRITE));
95 g_type_class_add_private (class, sizeof (GtkInvisiblePrivate));
99 gtk_invisible_init (GtkInvisible *invisible)
101 GtkInvisiblePrivate *priv;
103 invisible->priv = G_TYPE_INSTANCE_GET_PRIVATE (invisible,
105 GtkInvisiblePrivate);
106 priv = invisible->priv;
108 gtk_widget_set_has_window (GTK_WIDGET (invisible), TRUE);
109 _gtk_widget_set_is_toplevel (GTK_WIDGET (invisible), TRUE);
111 g_object_ref_sink (invisible);
113 priv->has_user_ref_count = TRUE;
114 priv->screen = gdk_screen_get_default ();
118 gtk_invisible_destroy (GtkWidget *widget)
120 GtkInvisible *invisible = GTK_INVISIBLE (widget);
121 GtkInvisiblePrivate *priv = invisible->priv;
123 if (priv->has_user_ref_count)
125 priv->has_user_ref_count = FALSE;
126 g_object_unref (invisible);
129 GTK_WIDGET_CLASS (gtk_invisible_parent_class)->destroy (widget);
133 * gtk_invisible_new_for_screen:
134 * @screen: a #GdkScreen which identifies on which
135 * the new #GtkInvisible will be created.
137 * Creates a new #GtkInvisible object for a specified screen
139 * Return value: a newly created #GtkInvisible object
144 gtk_invisible_new_for_screen (GdkScreen *screen)
146 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
148 return g_object_new (GTK_TYPE_INVISIBLE, "screen", screen, NULL);
154 * Creates a new #GtkInvisible.
156 * Return value: a new #GtkInvisible.
159 gtk_invisible_new (void)
161 return g_object_new (GTK_TYPE_INVISIBLE, NULL);
165 * gtk_invisible_set_screen:
166 * @invisible: a #GtkInvisible.
167 * @screen: a #GdkScreen.
169 * Sets the #GdkScreen where the #GtkInvisible object will be displayed.
174 gtk_invisible_set_screen (GtkInvisible *invisible,
177 GtkInvisiblePrivate *priv;
179 GdkScreen *previous_screen;
180 gboolean was_realized;
182 g_return_if_fail (GTK_IS_INVISIBLE (invisible));
183 g_return_if_fail (GDK_IS_SCREEN (screen));
185 priv = invisible->priv;
187 if (screen == priv->screen)
190 widget = GTK_WIDGET (invisible);
192 previous_screen = priv->screen;
193 was_realized = gtk_widget_get_realized (widget);
196 gtk_widget_unrealize (widget);
198 priv->screen = screen;
199 if (screen != previous_screen)
200 _gtk_widget_propagate_screen_changed (widget, previous_screen);
201 g_object_notify (G_OBJECT (invisible), "screen");
204 gtk_widget_realize (widget);
208 * gtk_invisible_get_screen:
209 * @invisible: a #GtkInvisible.
211 * Returns the #GdkScreen object associated with @invisible
213 * Return value: (transfer none): the associated #GdkScreen.
218 gtk_invisible_get_screen (GtkInvisible *invisible)
220 g_return_val_if_fail (GTK_IS_INVISIBLE (invisible), NULL);
222 return invisible->priv->screen;
226 gtk_invisible_realize (GtkWidget *widget)
230 GdkWindowAttr attributes;
231 gint attributes_mask;
233 gtk_widget_set_realized (widget, TRUE);
235 parent = gtk_widget_get_parent_window (widget);
237 parent = gtk_widget_get_root_window (widget);
241 attributes.width = 10;
242 attributes.height = 10;
243 attributes.window_type = GDK_WINDOW_TEMP;
244 attributes.wclass = GDK_INPUT_ONLY;
245 attributes.override_redirect = TRUE;
246 attributes.event_mask = gtk_widget_get_events (widget);
248 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
250 window = gdk_window_new (parent, &attributes, attributes_mask);
251 gtk_widget_set_window (widget, window);
252 gdk_window_set_user_data (window, widget);
254 gtk_widget_style_attach (widget);
258 gtk_invisible_style_set (GtkWidget *widget,
259 GtkStyle *previous_style)
261 /* Don't chain up to parent implementation */
265 gtk_invisible_show (GtkWidget *widget)
267 _gtk_widget_set_visible_flag (widget, TRUE);
268 gtk_widget_map (widget);
272 gtk_invisible_size_allocate (GtkWidget *widget,
273 GtkAllocation *allocation)
275 gtk_widget_set_allocation (widget, allocation);
280 gtk_invisible_set_property (GObject *object,
285 GtkInvisible *invisible = GTK_INVISIBLE (object);
290 gtk_invisible_set_screen (invisible, g_value_get_object (value));
293 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
299 gtk_invisible_get_property (GObject *object,
304 GtkInvisible *invisible = GTK_INVISIBLE (object);
305 GtkInvisiblePrivate *priv = invisible->priv;
310 g_value_set_object (value, priv->screen);
313 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
318 /* We use a constructor here so that we can realize the invisible on
319 * the correct screen after the "screen" property has been set
322 gtk_invisible_constructor (GType type,
323 guint n_construct_properties,
324 GObjectConstructParam *construct_params)
328 object = G_OBJECT_CLASS (gtk_invisible_parent_class)->constructor (type,
329 n_construct_properties,
332 gtk_widget_realize (GTK_WIDGET (object));