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"
39 static void gtk_invisible_destroy (GtkObject *object);
40 static void gtk_invisible_realize (GtkWidget *widget);
41 static void gtk_invisible_style_set (GtkWidget *widget,
42 GtkStyle *previous_style);
43 static void gtk_invisible_show (GtkWidget *widget);
44 static void gtk_invisible_size_allocate (GtkWidget *widget,
45 GtkAllocation *allocation);
46 static void gtk_invisible_set_property (GObject *object,
50 static void gtk_invisible_get_property (GObject *object,
55 static GObject *gtk_invisible_constructor (GType type,
56 guint n_construct_properties,
57 GObjectConstructParam *construct_params);
59 G_DEFINE_TYPE (GtkInvisible, gtk_invisible, GTK_TYPE_WIDGET)
62 gtk_invisible_class_init (GtkInvisibleClass *class)
64 GObjectClass *gobject_class;
65 GtkObjectClass *object_class;
66 GtkWidgetClass *widget_class;
68 widget_class = (GtkWidgetClass*) class;
69 object_class = (GtkObjectClass*) class;
70 gobject_class = (GObjectClass*) class;
72 widget_class->realize = gtk_invisible_realize;
73 widget_class->style_set = gtk_invisible_style_set;
74 widget_class->show = gtk_invisible_show;
75 widget_class->size_allocate = gtk_invisible_size_allocate;
77 object_class->destroy = gtk_invisible_destroy;
78 gobject_class->set_property = gtk_invisible_set_property;
79 gobject_class->get_property = gtk_invisible_get_property;
80 gobject_class->constructor = gtk_invisible_constructor;
82 g_object_class_install_property (gobject_class,
84 g_param_spec_object ("screen",
86 P_("The screen where this window will be displayed"),
88 GTK_PARAM_READWRITE));
92 gtk_invisible_init (GtkInvisible *invisible)
94 GdkColormap *colormap;
96 gtk_widget_set_has_window (GTK_WIDGET (invisible), TRUE);
97 _gtk_widget_set_is_toplevel (GTK_WIDGET (invisible), TRUE);
99 g_object_ref_sink (invisible);
101 invisible->has_user_ref_count = TRUE;
102 invisible->screen = gdk_screen_get_default ();
104 colormap = _gtk_widget_peek_colormap ();
106 gtk_widget_set_colormap (GTK_WIDGET (invisible), colormap);
110 gtk_invisible_destroy (GtkObject *object)
112 GtkInvisible *invisible = GTK_INVISIBLE (object);
114 if (invisible->has_user_ref_count)
116 invisible->has_user_ref_count = FALSE;
117 g_object_unref (invisible);
120 GTK_OBJECT_CLASS (gtk_invisible_parent_class)->destroy (object);
124 * gtk_invisible_new_for_screen:
125 * @screen: a #GdkScreen which identifies on which
126 * the new #GtkInvisible will be created.
128 * Creates a new #GtkInvisible object for a specified screen
130 * Return value: a newly created #GtkInvisible object
135 gtk_invisible_new_for_screen (GdkScreen *screen)
137 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
139 return g_object_new (GTK_TYPE_INVISIBLE, "screen", screen, NULL);
145 * Creates a new #GtkInvisible.
147 * Return value: a new #GtkInvisible.
150 gtk_invisible_new (void)
152 return g_object_new (GTK_TYPE_INVISIBLE, NULL);
156 * gtk_invisible_set_screen:
157 * @invisible: a #GtkInvisible.
158 * @screen: a #GdkScreen.
160 * Sets the #GdkScreen where the #GtkInvisible object will be displayed.
165 gtk_invisible_set_screen (GtkInvisible *invisible,
169 GdkScreen *previous_screen;
170 gboolean was_realized;
172 g_return_if_fail (GTK_IS_INVISIBLE (invisible));
173 g_return_if_fail (GDK_IS_SCREEN (screen));
175 if (screen == invisible->screen)
178 widget = GTK_WIDGET (invisible);
180 previous_screen = invisible->screen;
181 was_realized = gtk_widget_get_realized (widget);
184 gtk_widget_unrealize (widget);
186 invisible->screen = screen;
187 if (screen != previous_screen)
188 _gtk_widget_propagate_screen_changed (widget, previous_screen);
189 g_object_notify (G_OBJECT (invisible), "screen");
192 gtk_widget_realize (widget);
196 * gtk_invisible_get_screen:
197 * @invisible: a #GtkInvisible.
199 * Returns the #GdkScreen object associated with @invisible
201 * Return value: the associated #GdkScreen.
206 gtk_invisible_get_screen (GtkInvisible *invisible)
208 g_return_val_if_fail (GTK_IS_INVISIBLE (invisible), NULL);
210 return invisible->screen;
214 gtk_invisible_realize (GtkWidget *widget)
217 GdkWindowAttr attributes;
218 gint attributes_mask;
220 gtk_widget_set_realized (widget, TRUE);
222 parent = gtk_widget_get_parent_window (widget);
224 parent = gtk_widget_get_root_window (widget);
228 attributes.width = 10;
229 attributes.height = 10;
230 attributes.window_type = GDK_WINDOW_TEMP;
231 attributes.wclass = GDK_INPUT_ONLY;
232 attributes.override_redirect = TRUE;
233 attributes.event_mask = gtk_widget_get_events (widget);
235 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
237 widget->window = gdk_window_new (parent, &attributes, attributes_mask);
239 gdk_window_set_user_data (widget->window, widget);
241 widget->style = gtk_style_attach (widget->style, widget->window);
245 gtk_invisible_style_set (GtkWidget *widget,
246 GtkStyle *previous_style)
248 /* Don't chain up to parent implementation */
252 gtk_invisible_show (GtkWidget *widget)
254 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
255 gtk_widget_map (widget);
259 gtk_invisible_size_allocate (GtkWidget *widget,
260 GtkAllocation *allocation)
262 widget->allocation = *allocation;
267 gtk_invisible_set_property (GObject *object,
272 GtkInvisible *invisible = GTK_INVISIBLE (object);
277 gtk_invisible_set_screen (invisible, g_value_get_object (value));
280 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
286 gtk_invisible_get_property (GObject *object,
291 GtkInvisible *invisible = GTK_INVISIBLE (object);
296 g_value_set_object (value, invisible->screen);
299 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
304 /* We use a constructor here so that we can realize the invisible on
305 * the correct screen after the "screen" property has been set
308 gtk_invisible_constructor (GType type,
309 guint n_construct_properties,
310 GObjectConstructParam *construct_params)
314 object = G_OBJECT_CLASS (gtk_invisible_parent_class)->constructor (type,
315 n_construct_properties,
318 gtk_widget_realize (GTK_WIDGET (object));