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 "gtkprivate.h"
33 struct _GtkInvisiblePrivate
36 gboolean has_user_ref_count;
45 static void gtk_invisible_destroy (GtkObject *object);
46 static void gtk_invisible_realize (GtkWidget *widget);
47 static void gtk_invisible_style_set (GtkWidget *widget,
48 GtkStyle *previous_style);
49 static void gtk_invisible_show (GtkWidget *widget);
50 static void gtk_invisible_size_allocate (GtkWidget *widget,
51 GtkAllocation *allocation);
52 static void gtk_invisible_set_property (GObject *object,
56 static void gtk_invisible_get_property (GObject *object,
61 static GObject *gtk_invisible_constructor (GType type,
62 guint n_construct_properties,
63 GObjectConstructParam *construct_params);
65 G_DEFINE_TYPE (GtkInvisible, gtk_invisible, GTK_TYPE_WIDGET)
68 gtk_invisible_class_init (GtkInvisibleClass *class)
70 GObjectClass *gobject_class;
71 GtkObjectClass *object_class;
72 GtkWidgetClass *widget_class;
74 widget_class = (GtkWidgetClass*) class;
75 object_class = (GtkObjectClass*) class;
76 gobject_class = (GObjectClass*) class;
78 widget_class->realize = gtk_invisible_realize;
79 widget_class->style_set = gtk_invisible_style_set;
80 widget_class->show = gtk_invisible_show;
81 widget_class->size_allocate = gtk_invisible_size_allocate;
83 object_class->destroy = gtk_invisible_destroy;
84 gobject_class->set_property = gtk_invisible_set_property;
85 gobject_class->get_property = gtk_invisible_get_property;
86 gobject_class->constructor = gtk_invisible_constructor;
88 g_object_class_install_property (gobject_class,
90 g_param_spec_object ("screen",
92 P_("The screen where this window will be displayed"),
94 GTK_PARAM_READWRITE));
96 g_type_class_add_private (class, sizeof (GtkInvisiblePrivate));
100 gtk_invisible_init (GtkInvisible *invisible)
102 GtkInvisiblePrivate *priv;
103 GdkColormap *colormap;
105 invisible->priv = G_TYPE_INSTANCE_GET_PRIVATE (invisible,
107 GtkInvisiblePrivate);
108 priv = invisible->priv;
110 gtk_widget_set_has_window (GTK_WIDGET (invisible), TRUE);
111 _gtk_widget_set_is_toplevel (GTK_WIDGET (invisible), TRUE);
113 g_object_ref_sink (invisible);
115 priv->has_user_ref_count = TRUE;
116 priv->screen = gdk_screen_get_default ();
118 colormap = _gtk_widget_peek_colormap ();
120 gtk_widget_set_colormap (GTK_WIDGET (invisible), colormap);
124 gtk_invisible_destroy (GtkObject *object)
126 GtkInvisible *invisible = GTK_INVISIBLE (object);
127 GtkInvisiblePrivate *priv = invisible->priv;
129 if (priv->has_user_ref_count)
131 priv->has_user_ref_count = FALSE;
132 g_object_unref (invisible);
135 GTK_OBJECT_CLASS (gtk_invisible_parent_class)->destroy (object);
139 * gtk_invisible_new_for_screen:
140 * @screen: a #GdkScreen which identifies on which
141 * the new #GtkInvisible will be created.
143 * Creates a new #GtkInvisible object for a specified screen
145 * Return value: a newly created #GtkInvisible object
150 gtk_invisible_new_for_screen (GdkScreen *screen)
152 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
154 return g_object_new (GTK_TYPE_INVISIBLE, "screen", screen, NULL);
160 * Creates a new #GtkInvisible.
162 * Return value: a new #GtkInvisible.
165 gtk_invisible_new (void)
167 return g_object_new (GTK_TYPE_INVISIBLE, NULL);
171 * gtk_invisible_set_screen:
172 * @invisible: a #GtkInvisible.
173 * @screen: a #GdkScreen.
175 * Sets the #GdkScreen where the #GtkInvisible object will be displayed.
180 gtk_invisible_set_screen (GtkInvisible *invisible,
183 GtkInvisiblePrivate *priv;
185 GdkScreen *previous_screen;
186 gboolean was_realized;
188 g_return_if_fail (GTK_IS_INVISIBLE (invisible));
189 g_return_if_fail (GDK_IS_SCREEN (screen));
191 priv = invisible->priv;
193 if (screen == priv->screen)
196 widget = GTK_WIDGET (invisible);
198 previous_screen = priv->screen;
199 was_realized = gtk_widget_get_realized (widget);
202 gtk_widget_unrealize (widget);
204 priv->screen = screen;
205 if (screen != previous_screen)
206 _gtk_widget_propagate_screen_changed (widget, previous_screen);
207 g_object_notify (G_OBJECT (invisible), "screen");
210 gtk_widget_realize (widget);
214 * gtk_invisible_get_screen:
215 * @invisible: a #GtkInvisible.
217 * Returns the #GdkScreen object associated with @invisible
219 * Return value: the associated #GdkScreen.
224 gtk_invisible_get_screen (GtkInvisible *invisible)
226 g_return_val_if_fail (GTK_IS_INVISIBLE (invisible), NULL);
228 return invisible->priv->screen;
232 gtk_invisible_realize (GtkWidget *widget)
236 GdkWindowAttr attributes;
237 gint attributes_mask;
239 gtk_widget_set_realized (widget, TRUE);
241 parent = gtk_widget_get_parent_window (widget);
243 parent = gtk_widget_get_root_window (widget);
247 attributes.width = 10;
248 attributes.height = 10;
249 attributes.window_type = GDK_WINDOW_TEMP;
250 attributes.wclass = GDK_INPUT_ONLY;
251 attributes.override_redirect = TRUE;
252 attributes.event_mask = gtk_widget_get_events (widget);
254 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
256 window = gdk_window_new (parent, &attributes, attributes_mask);
257 gtk_widget_set_window (widget, window);
258 gdk_window_set_user_data (window, widget);
260 gtk_widget_style_attach (widget);
264 gtk_invisible_style_set (GtkWidget *widget,
265 GtkStyle *previous_style)
267 /* Don't chain up to parent implementation */
271 gtk_invisible_show (GtkWidget *widget)
273 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
274 gtk_widget_map (widget);
278 gtk_invisible_size_allocate (GtkWidget *widget,
279 GtkAllocation *allocation)
281 gtk_widget_set_allocation (widget, allocation);
286 gtk_invisible_set_property (GObject *object,
291 GtkInvisible *invisible = GTK_INVISIBLE (object);
296 gtk_invisible_set_screen (invisible, g_value_get_object (value));
299 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
305 gtk_invisible_get_property (GObject *object,
310 GtkInvisible *invisible = GTK_INVISIBLE (object);
311 GtkInvisiblePrivate *priv = invisible->priv;
316 g_value_set_object (value, priv->screen);
319 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
324 /* We use a constructor here so that we can realize the invisible on
325 * the correct screen after the "screen" property has been set
328 gtk_invisible_constructor (GType type,
329 guint n_construct_properties,
330 GObjectConstructParam *construct_params)
334 object = G_OBJECT_CLASS (gtk_invisible_parent_class)->constructor (type,
335 n_construct_properties,
338 gtk_widget_realize (GTK_WIDGET (object));