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/.
30 #include "gtkinvisible.h"
39 static void gtk_invisible_class_init (GtkInvisibleClass *klass);
40 static void gtk_invisible_init (GtkInvisible *invisible);
41 static void gtk_invisible_destroy (GtkObject *object);
42 static void gtk_invisible_realize (GtkWidget *widget);
43 static void gtk_invisible_style_set (GtkWidget *widget,
44 GtkStyle *previous_style);
45 static void gtk_invisible_show (GtkWidget *widget);
46 static void gtk_invisible_size_allocate (GtkWidget *widget,
47 GtkAllocation *allocation);
48 static void gtk_invisible_set_property (GObject *object,
52 static void gtk_invisible_get_property (GObject *object,
57 static GObject *gtk_invisible_constructor (GType type,
58 guint n_construct_properties,
59 GObjectConstructParam *construct_params);
61 static GObjectClass *parent_class;
64 gtk_invisible_get_type (void)
66 static GType invisible_type = 0;
70 static const GTypeInfo invisible_info =
72 sizeof (GtkInvisibleClass),
74 NULL, /* base_finalize */
75 (GClassInitFunc) gtk_invisible_class_init,
76 NULL, /* class_finalize */
77 NULL, /* class_data */
78 sizeof (GtkInvisible),
80 (GInstanceInitFunc) gtk_invisible_init,
83 invisible_type = g_type_register_static (GTK_TYPE_WIDGET, "GtkInvisible",
87 return invisible_type;
91 gtk_invisible_class_init (GtkInvisibleClass *class)
93 GObjectClass *gobject_class;
94 GtkObjectClass *object_class;
95 GtkWidgetClass *widget_class;
97 widget_class = (GtkWidgetClass*) class;
98 object_class = (GtkObjectClass*) class;
99 gobject_class = (GObjectClass*) class;
101 parent_class = g_type_class_peek_parent (class);
103 widget_class->realize = gtk_invisible_realize;
104 widget_class->style_set = gtk_invisible_style_set;
105 widget_class->show = gtk_invisible_show;
106 widget_class->size_allocate = gtk_invisible_size_allocate;
108 object_class->destroy = gtk_invisible_destroy;
109 gobject_class->set_property = gtk_invisible_set_property;
110 gobject_class->get_property = gtk_invisible_get_property;
111 gobject_class->constructor = gtk_invisible_constructor;
113 g_object_class_install_property (gobject_class,
115 g_param_spec_object ("screen",
117 P_("The screen where this window will be displayed"),
123 gtk_invisible_init (GtkInvisible *invisible)
125 GdkColormap *colormap;
127 GTK_WIDGET_UNSET_FLAGS (invisible, GTK_NO_WINDOW);
128 GTK_WIDGET_SET_FLAGS (invisible, GTK_TOPLEVEL);
130 g_object_ref (invisible);
131 gtk_object_sink (GTK_OBJECT (invisible));
133 invisible->has_user_ref_count = TRUE;
134 invisible->screen = gdk_screen_get_default ();
136 colormap = _gtk_widget_peek_colormap ();
138 gtk_widget_set_colormap (GTK_WIDGET (invisible), colormap);
142 gtk_invisible_destroy (GtkObject *object)
144 GtkInvisible *invisible = GTK_INVISIBLE (object);
146 if (invisible->has_user_ref_count)
148 invisible->has_user_ref_count = FALSE;
149 g_object_unref (invisible);
152 GTK_OBJECT_CLASS (parent_class)->destroy (object);
156 * gtk_invisible_new_for_screen:
157 * @screen: a #GdkScreen which identifies on which
158 * the new #GtkInvisible will be created.
160 * Creates a new #GtkInvisible object for a specified screen
162 * Return value: a newly created #GtkInvisible object
167 gtk_invisible_new_for_screen (GdkScreen *screen)
169 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
171 return g_object_new (GTK_TYPE_INVISIBLE, "screen", screen, NULL);
177 * Creates a new #GtkInvisible.
179 * Return value: a new #GtkInvisible.
182 gtk_invisible_new (void)
184 return g_object_new (GTK_TYPE_INVISIBLE, NULL);
188 * gtk_invisible_set_screen:
189 * @invisible: a #GtkInvisible.
190 * @screen: a #GdkScreen.
192 * Sets the #GdkScreen where the #GtkInvisible object will be displayed.
197 gtk_invisible_set_screen (GtkInvisible *invisible,
201 GdkScreen *previous_screen;
202 gboolean was_realized;
204 g_return_if_fail (GTK_IS_INVISIBLE (invisible));
205 g_return_if_fail (GDK_IS_SCREEN (screen));
207 if (screen == invisible->screen)
210 widget = GTK_WIDGET (invisible);
212 previous_screen = invisible->screen;
213 was_realized = GTK_WIDGET_REALIZED (invisible);
216 gtk_widget_unrealize (widget);
218 invisible->screen = screen;
219 if (screen != previous_screen)
220 _gtk_widget_propagate_screen_changed (widget, previous_screen);
221 g_object_notify (G_OBJECT (invisible), "screen");
224 gtk_widget_realize (widget);
228 * gtk_invisible_get_screen:
229 * @invisible: a #GtkInvisible.
231 * Returns the #GdkScreen object associated with @invisible
233 * Return value: the associated #GdkScreen.
238 gtk_invisible_get_screen (GtkInvisible *invisible)
240 g_return_val_if_fail (GTK_IS_INVISIBLE (invisible), NULL);
242 return invisible->screen;
246 gtk_invisible_realize (GtkWidget *widget)
248 GdkWindowAttr attributes;
249 gint attributes_mask;
251 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
255 attributes.width = 10;
256 attributes.height = 10;
257 attributes.window_type = GDK_WINDOW_TEMP;
258 attributes.wclass = GDK_INPUT_ONLY;
259 attributes.override_redirect = TRUE;
260 attributes.event_mask = gtk_widget_get_events (widget);
262 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
264 widget->window = gdk_window_new (gtk_widget_get_root_window (widget),
265 &attributes, attributes_mask);
267 gdk_window_set_user_data (widget->window, widget);
269 widget->style = gtk_style_attach (widget->style, widget->window);
273 gtk_invisible_style_set (GtkWidget *widget,
274 GtkStyle *previous_style)
276 /* Don't chain up to parent implementation */
280 gtk_invisible_show (GtkWidget *widget)
282 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
283 gtk_widget_map (widget);
287 gtk_invisible_size_allocate (GtkWidget *widget,
288 GtkAllocation *allocation)
290 widget->allocation = *allocation;
295 gtk_invisible_set_property (GObject *object,
300 GtkInvisible *invisible = GTK_INVISIBLE (object);
305 gtk_invisible_set_screen (invisible, g_value_get_object (value));
308 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
314 gtk_invisible_get_property (GObject *object,
319 GtkInvisible *invisible = GTK_INVISIBLE (object);
324 g_value_set_object (value, invisible->screen);
327 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
332 /* We use a constructor here so that we can realize the invisible on
333 * the correct screen after the "screen" property has been set
336 gtk_invisible_constructor (GType type,
337 guint n_construct_properties,
338 GObjectConstructParam *construct_params)
342 object = (* G_OBJECT_CLASS (parent_class)->constructor) (type,
343 n_construct_properties,
346 gtk_widget_realize (GTK_WIDGET (object));