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"
40 static void gtk_invisible_class_init (GtkInvisibleClass *klass);
41 static void gtk_invisible_init (GtkInvisible *invisible);
42 static void gtk_invisible_destroy (GtkObject *object);
43 static void gtk_invisible_realize (GtkWidget *widget);
44 static void gtk_invisible_style_set (GtkWidget *widget,
45 GtkStyle *previous_style);
46 static void gtk_invisible_show (GtkWidget *widget);
47 static void gtk_invisible_size_allocate (GtkWidget *widget,
48 GtkAllocation *allocation);
49 static void gtk_invisible_set_property (GObject *object,
53 static void gtk_invisible_get_property (GObject *object,
58 static GObject *gtk_invisible_constructor (GType type,
59 guint n_construct_properties,
60 GObjectConstructParam *construct_params);
62 static GObjectClass *parent_class;
65 gtk_invisible_get_type (void)
67 static GType invisible_type = 0;
71 static const GTypeInfo invisible_info =
73 sizeof (GtkInvisibleClass),
75 NULL, /* base_finalize */
76 (GClassInitFunc) gtk_invisible_class_init,
77 NULL, /* class_finalize */
78 NULL, /* class_data */
79 sizeof (GtkInvisible),
81 (GInstanceInitFunc) gtk_invisible_init,
84 invisible_type = g_type_register_static (GTK_TYPE_WIDGET, I_("GtkInvisible"),
88 return invisible_type;
92 gtk_invisible_class_init (GtkInvisibleClass *class)
94 GObjectClass *gobject_class;
95 GtkObjectClass *object_class;
96 GtkWidgetClass *widget_class;
98 widget_class = (GtkWidgetClass*) class;
99 object_class = (GtkObjectClass*) class;
100 gobject_class = (GObjectClass*) class;
102 parent_class = g_type_class_peek_parent (class);
104 widget_class->realize = gtk_invisible_realize;
105 widget_class->style_set = gtk_invisible_style_set;
106 widget_class->show = gtk_invisible_show;
107 widget_class->size_allocate = gtk_invisible_size_allocate;
109 object_class->destroy = gtk_invisible_destroy;
110 gobject_class->set_property = gtk_invisible_set_property;
111 gobject_class->get_property = gtk_invisible_get_property;
112 gobject_class->constructor = gtk_invisible_constructor;
114 g_object_class_install_property (gobject_class,
116 g_param_spec_object ("screen",
118 P_("The screen where this window will be displayed"),
120 GTK_PARAM_READWRITE));
124 gtk_invisible_init (GtkInvisible *invisible)
126 GdkColormap *colormap;
128 GTK_WIDGET_UNSET_FLAGS (invisible, GTK_NO_WINDOW);
129 GTK_WIDGET_SET_FLAGS (invisible, GTK_TOPLEVEL);
131 g_object_ref (invisible);
132 gtk_object_sink (GTK_OBJECT (invisible));
134 invisible->has_user_ref_count = TRUE;
135 invisible->screen = gdk_screen_get_default ();
137 colormap = _gtk_widget_peek_colormap ();
139 gtk_widget_set_colormap (GTK_WIDGET (invisible), colormap);
143 gtk_invisible_destroy (GtkObject *object)
145 GtkInvisible *invisible = GTK_INVISIBLE (object);
147 if (invisible->has_user_ref_count)
149 invisible->has_user_ref_count = FALSE;
150 g_object_unref (invisible);
153 GTK_OBJECT_CLASS (parent_class)->destroy (object);
157 * gtk_invisible_new_for_screen:
158 * @screen: a #GdkScreen which identifies on which
159 * the new #GtkInvisible will be created.
161 * Creates a new #GtkInvisible object for a specified screen
163 * Return value: a newly created #GtkInvisible object
168 gtk_invisible_new_for_screen (GdkScreen *screen)
170 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
172 return g_object_new (GTK_TYPE_INVISIBLE, "screen", screen, NULL);
178 * Creates a new #GtkInvisible.
180 * Return value: a new #GtkInvisible.
183 gtk_invisible_new (void)
185 return g_object_new (GTK_TYPE_INVISIBLE, NULL);
189 * gtk_invisible_set_screen:
190 * @invisible: a #GtkInvisible.
191 * @screen: a #GdkScreen.
193 * Sets the #GdkScreen where the #GtkInvisible object will be displayed.
198 gtk_invisible_set_screen (GtkInvisible *invisible,
202 GdkScreen *previous_screen;
203 gboolean was_realized;
205 g_return_if_fail (GTK_IS_INVISIBLE (invisible));
206 g_return_if_fail (GDK_IS_SCREEN (screen));
208 if (screen == invisible->screen)
211 widget = GTK_WIDGET (invisible);
213 previous_screen = invisible->screen;
214 was_realized = GTK_WIDGET_REALIZED (invisible);
217 gtk_widget_unrealize (widget);
219 invisible->screen = screen;
220 if (screen != previous_screen)
221 _gtk_widget_propagate_screen_changed (widget, previous_screen);
222 g_object_notify (G_OBJECT (invisible), "screen");
225 gtk_widget_realize (widget);
229 * gtk_invisible_get_screen:
230 * @invisible: a #GtkInvisible.
232 * Returns the #GdkScreen object associated with @invisible
234 * Return value: the associated #GdkScreen.
239 gtk_invisible_get_screen (GtkInvisible *invisible)
241 g_return_val_if_fail (GTK_IS_INVISIBLE (invisible), NULL);
243 return invisible->screen;
247 gtk_invisible_realize (GtkWidget *widget)
249 GdkWindowAttr attributes;
250 gint attributes_mask;
252 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
256 attributes.width = 10;
257 attributes.height = 10;
258 attributes.window_type = GDK_WINDOW_TEMP;
259 attributes.wclass = GDK_INPUT_ONLY;
260 attributes.override_redirect = TRUE;
261 attributes.event_mask = gtk_widget_get_events (widget);
263 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
265 widget->window = gdk_window_new (gtk_widget_get_root_window (widget),
266 &attributes, attributes_mask);
268 gdk_window_set_user_data (widget->window, widget);
270 widget->style = gtk_style_attach (widget->style, widget->window);
274 gtk_invisible_style_set (GtkWidget *widget,
275 GtkStyle *previous_style)
277 /* Don't chain up to parent implementation */
281 gtk_invisible_show (GtkWidget *widget)
283 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
284 gtk_widget_map (widget);
288 gtk_invisible_size_allocate (GtkWidget *widget,
289 GtkAllocation *allocation)
291 widget->allocation = *allocation;
296 gtk_invisible_set_property (GObject *object,
301 GtkInvisible *invisible = GTK_INVISIBLE (object);
306 gtk_invisible_set_screen (invisible, g_value_get_object (value));
309 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
315 gtk_invisible_get_property (GObject *object,
320 GtkInvisible *invisible = GTK_INVISIBLE (object);
325 g_value_set_object (value, invisible->screen);
328 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
333 /* We use a constructor here so that we can realize the invisible on
334 * the correct screen after the "screen" property has been set
337 gtk_invisible_constructor (GType type,
338 guint n_construct_properties,
339 GObjectConstructParam *construct_params)
343 object = (* G_OBJECT_CLASS (parent_class)->constructor) (type,
344 n_construct_properties,
347 gtk_widget_realize (GTK_WIDGET (object));
352 #define __GTK_INVISIBLE_C__
353 #include "gtkaliasdef.c"