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 "gtksignal.h"
29 #include "gtkinvisible.h"
38 static void gtk_invisible_class_init (GtkInvisibleClass *klass);
39 static void gtk_invisible_init (GtkInvisible *invisible);
40 static void gtk_invisible_destroy (GtkObject *object);
41 static void gtk_invisible_realize (GtkWidget *widget);
42 static void gtk_invisible_style_set (GtkWidget *widget,
43 GtkStyle *previous_style);
44 static void gtk_invisible_show (GtkWidget *widget);
45 static void gtk_invisible_size_allocate (GtkWidget *widget,
46 GtkAllocation *allocation);
47 static void gtk_invisible_set_property (GObject *object,
51 static void gtk_invisible_get_property (GObject *object,
56 static GObject *gtk_invisible_constructor (GType type,
57 guint n_construct_properties,
58 GObjectConstructParam *construct_params);
60 GObjectClass *parent_class;
63 gtk_invisible_get_type (void)
65 static GtkType invisible_type = 0;
69 static const GtkTypeInfo invisible_info =
72 sizeof (GtkInvisible),
73 sizeof (GtkInvisibleClass),
74 (GtkClassInitFunc) gtk_invisible_class_init,
75 (GtkObjectInitFunc) gtk_invisible_init,
76 /* reserved_1 */ NULL,
77 /* reserved_2 */ NULL,
78 (GtkClassInitFunc) NULL,
81 invisible_type = gtk_type_unique (GTK_TYPE_WIDGET, &invisible_info);
84 return invisible_type;
88 gtk_invisible_class_init (GtkInvisibleClass *class)
90 GObjectClass *gobject_class;
91 GtkObjectClass *object_class;
92 GtkWidgetClass *widget_class;
94 widget_class = (GtkWidgetClass*) class;
95 object_class = (GtkObjectClass*) class;
96 gobject_class = (GObjectClass*) class;
98 parent_class = g_type_class_peek_parent (class);
100 widget_class->realize = gtk_invisible_realize;
101 widget_class->style_set = gtk_invisible_style_set;
102 widget_class->show = gtk_invisible_show;
103 widget_class->size_allocate = gtk_invisible_size_allocate;
105 object_class->destroy = gtk_invisible_destroy;
106 gobject_class->set_property = gtk_invisible_set_property;
107 gobject_class->get_property = gtk_invisible_get_property;
108 gobject_class->constructor = gtk_invisible_constructor;
110 g_object_class_install_property (gobject_class,
112 g_param_spec_object ("screen",
114 _("The screen where this window will be displayed"),
120 gtk_invisible_init (GtkInvisible *invisible)
122 GdkColormap *colormap;
124 GTK_WIDGET_UNSET_FLAGS (invisible, GTK_NO_WINDOW);
125 GTK_WIDGET_SET_FLAGS (invisible, GTK_TOPLEVEL);
127 gtk_widget_ref (GTK_WIDGET (invisible));
128 gtk_object_sink (GTK_OBJECT (invisible));
130 invisible->has_user_ref_count = TRUE;
131 invisible->screen = gdk_screen_get_default ();
133 colormap = _gtk_widget_peek_colormap ();
135 gtk_widget_set_colormap (GTK_WIDGET (invisible), colormap);
139 gtk_invisible_destroy (GtkObject *object)
141 GtkInvisible *invisible = GTK_INVISIBLE (object);
143 if (invisible->has_user_ref_count)
145 invisible->has_user_ref_count = FALSE;
146 gtk_widget_unref (GTK_WIDGET (invisible));
151 * gtk_invisible_new_for_screen:
152 * @screen: a #GdkScreen which identifies on which
153 * the new #GtkInvisible will be created.
155 * Creates a new #GtkInvisible object for a specified screen
157 * Return value: a newly created #GtkInvisible object
160 gtk_invisible_new_for_screen (GdkScreen *screen)
162 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
164 return g_object_new (GTK_TYPE_INVISIBLE, "screen", screen, NULL);
170 * Creates a new #GtkInvisible.
172 * Return value: a new #GtkInvisible.
175 gtk_invisible_new (void)
177 return g_object_new (GTK_TYPE_INVISIBLE, NULL);
181 * gtk_invisible_set_screen:
182 * @invisible: a #GtkInvisible.
183 * @screen: a #GdkScreen.
185 * Sets the #GdkScreen where the #GtkInvisible object will be displayed.
188 gtk_invisible_set_screen (GtkInvisible *invisible,
191 gboolean was_realized;
193 g_return_if_fail (GTK_IS_INVISIBLE (invisible));
194 g_return_if_fail (GDK_IS_SCREEN (screen));
196 if (screen == invisible->screen)
199 was_realized = GTK_WIDGET_REALIZED (invisible);
202 gtk_widget_unrealize (GTK_WIDGET (invisible));
204 invisible->screen = screen;
205 g_object_notify (G_OBJECT (invisible), "screen");
208 gtk_widget_realize (GTK_WIDGET (invisible));
212 * gtk_invisible_get_screen:
213 * @invisible: a #GtkInvisible.
215 * Returns the #GdkScreen object associated with @invisible
217 * Return value : the associated #GdkScreen.
220 gtk_invisible_get_screen (GtkInvisible *invisible)
222 g_return_val_if_fail (GTK_IS_INVISIBLE (invisible), NULL);
224 return invisible->screen;
228 gtk_invisible_realize (GtkWidget *widget)
230 GdkWindowAttr attributes;
231 gint attributes_mask;
233 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
237 attributes.width = 10;
238 attributes.height = 10;
239 attributes.window_type = GDK_WINDOW_TEMP;
240 attributes.wclass = GDK_INPUT_ONLY;
241 attributes.override_redirect = TRUE;
242 attributes.event_mask = gtk_widget_get_events (widget);
244 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
246 widget->window = gdk_window_new (gtk_widget_get_root_window (widget),
247 &attributes, attributes_mask);
249 gdk_window_set_user_data (widget->window, widget);
251 widget->style = gtk_style_attach (widget->style, widget->window);
255 gtk_invisible_style_set (GtkWidget *widget,
256 GtkStyle *previous_style)
258 /* Don't chain up to parent implementation */
262 gtk_invisible_show (GtkWidget *widget)
264 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
265 gtk_widget_map (widget);
269 gtk_invisible_size_allocate (GtkWidget *widget,
270 GtkAllocation *allocation)
272 widget->allocation = *allocation;
277 gtk_invisible_set_property (GObject *object,
282 GtkInvisible *invisible = GTK_INVISIBLE (object);
287 gtk_invisible_set_screen (invisible, g_value_get_object (value));
290 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
296 gtk_invisible_get_property (GObject *object,
301 GtkInvisible *invisible = GTK_INVISIBLE (object);
306 g_value_set_object (value, invisible->screen);
309 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
314 /* We use a constructor here so that we can realize the invisible on
315 * the correct screen after the "screen" property has been set
318 gtk_invisible_constructor (GType type,
319 guint n_construct_properties,
320 GObjectConstructParam *construct_params)
324 object = (* G_OBJECT_CLASS (parent_class)->constructor) (type,
325 n_construct_properties,
328 gtk_widget_realize (GTK_WIDGET (object));