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/.
28 #include "gtkinvisible.h"
37 static void gtk_invisible_class_init (GtkInvisibleClass *klass);
38 static void gtk_invisible_init (GtkInvisible *invisible);
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 static GObjectClass *parent_class;
62 gtk_invisible_get_type (void)
64 static GType invisible_type = 0;
68 static const GTypeInfo invisible_info =
70 sizeof (GtkInvisibleClass),
72 NULL, /* base_finalize */
73 (GClassInitFunc) gtk_invisible_class_init,
74 NULL, /* class_finalize */
75 NULL, /* class_data */
76 sizeof (GtkInvisible),
78 (GInstanceInitFunc) gtk_invisible_init,
81 invisible_type = g_type_register_static (GTK_TYPE_WIDGET, "GtkInvisible",
85 return invisible_type;
89 gtk_invisible_class_init (GtkInvisibleClass *class)
91 GObjectClass *gobject_class;
92 GtkObjectClass *object_class;
93 GtkWidgetClass *widget_class;
95 widget_class = (GtkWidgetClass*) class;
96 object_class = (GtkObjectClass*) class;
97 gobject_class = (GObjectClass*) class;
99 parent_class = g_type_class_peek_parent (class);
101 widget_class->realize = gtk_invisible_realize;
102 widget_class->style_set = gtk_invisible_style_set;
103 widget_class->show = gtk_invisible_show;
104 widget_class->size_allocate = gtk_invisible_size_allocate;
106 object_class->destroy = gtk_invisible_destroy;
107 gobject_class->set_property = gtk_invisible_set_property;
108 gobject_class->get_property = gtk_invisible_get_property;
109 gobject_class->constructor = gtk_invisible_constructor;
111 g_object_class_install_property (gobject_class,
113 g_param_spec_object ("screen",
115 _("The screen where this window will be displayed"),
121 gtk_invisible_init (GtkInvisible *invisible)
123 GdkColormap *colormap;
125 GTK_WIDGET_UNSET_FLAGS (invisible, GTK_NO_WINDOW);
126 GTK_WIDGET_SET_FLAGS (invisible, GTK_TOPLEVEL);
128 g_object_ref (invisible);
129 gtk_object_sink (GTK_OBJECT (invisible));
131 invisible->has_user_ref_count = TRUE;
132 invisible->screen = gdk_screen_get_default ();
134 colormap = _gtk_widget_peek_colormap ();
136 gtk_widget_set_colormap (GTK_WIDGET (invisible), colormap);
140 gtk_invisible_destroy (GtkObject *object)
142 GtkInvisible *invisible = GTK_INVISIBLE (object);
144 if (invisible->has_user_ref_count)
146 invisible->has_user_ref_count = FALSE;
147 g_object_unref (invisible);
152 * gtk_invisible_new_for_screen:
153 * @screen: a #GdkScreen which identifies on which
154 * the new #GtkInvisible will be created.
156 * Creates a new #GtkInvisible object for a specified screen
158 * Return value: a newly created #GtkInvisible object
163 gtk_invisible_new_for_screen (GdkScreen *screen)
165 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
167 return g_object_new (GTK_TYPE_INVISIBLE, "screen", screen, NULL);
173 * Creates a new #GtkInvisible.
175 * Return value: a new #GtkInvisible.
178 gtk_invisible_new (void)
180 return g_object_new (GTK_TYPE_INVISIBLE, NULL);
184 * gtk_invisible_set_screen:
185 * @invisible: a #GtkInvisible.
186 * @screen: a #GdkScreen.
188 * Sets the #GdkScreen where the #GtkInvisible object will be displayed.
193 gtk_invisible_set_screen (GtkInvisible *invisible,
197 GdkScreen *previous_screen;
198 gboolean was_realized;
200 g_return_if_fail (GTK_IS_INVISIBLE (invisible));
201 g_return_if_fail (GDK_IS_SCREEN (screen));
203 if (screen == invisible->screen)
206 widget = GTK_WIDGET (invisible);
208 previous_screen = invisible->screen;
209 was_realized = GTK_WIDGET_REALIZED (invisible);
212 gtk_widget_unrealize (widget);
214 invisible->screen = screen;
215 if (screen != previous_screen)
216 _gtk_widget_propagate_screen_changed (widget, previous_screen);
217 g_object_notify (G_OBJECT (invisible), "screen");
220 gtk_widget_realize (widget);
224 * gtk_invisible_get_screen:
225 * @invisible: a #GtkInvisible.
227 * Returns the #GdkScreen object associated with @invisible
229 * Return value: the associated #GdkScreen.
234 gtk_invisible_get_screen (GtkInvisible *invisible)
236 g_return_val_if_fail (GTK_IS_INVISIBLE (invisible), NULL);
238 return invisible->screen;
242 gtk_invisible_realize (GtkWidget *widget)
244 GdkWindowAttr attributes;
245 gint attributes_mask;
247 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
251 attributes.width = 10;
252 attributes.height = 10;
253 attributes.window_type = GDK_WINDOW_TEMP;
254 attributes.wclass = GDK_INPUT_ONLY;
255 attributes.override_redirect = TRUE;
256 attributes.event_mask = gtk_widget_get_events (widget);
258 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
260 widget->window = gdk_window_new (gtk_widget_get_root_window (widget),
261 &attributes, attributes_mask);
263 gdk_window_set_user_data (widget->window, widget);
265 widget->style = gtk_style_attach (widget->style, widget->window);
269 gtk_invisible_style_set (GtkWidget *widget,
270 GtkStyle *previous_style)
272 /* Don't chain up to parent implementation */
276 gtk_invisible_show (GtkWidget *widget)
278 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
279 gtk_widget_map (widget);
283 gtk_invisible_size_allocate (GtkWidget *widget,
284 GtkAllocation *allocation)
286 widget->allocation = *allocation;
291 gtk_invisible_set_property (GObject *object,
296 GtkInvisible *invisible = GTK_INVISIBLE (object);
301 gtk_invisible_set_screen (invisible, g_value_get_object (value));
304 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
310 gtk_invisible_get_property (GObject *object,
315 GtkInvisible *invisible = GTK_INVISIBLE (object);
320 g_value_set_object (value, invisible->screen);
323 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
328 /* We use a constructor here so that we can realize the invisible on
329 * the correct screen after the "screen" property has been set
332 gtk_invisible_constructor (GType type,
333 guint n_construct_properties,
334 GObjectConstructParam *construct_params)
338 object = (* G_OBJECT_CLASS (parent_class)->constructor) (type,
339 n_construct_properties,
342 gtk_widget_realize (GTK_WIDGET (object));