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_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 G_DEFINE_TYPE (GtkInvisible, gtk_invisible, GTK_TYPE_WIDGET);
63 gtk_invisible_class_init (GtkInvisibleClass *class)
65 GObjectClass *gobject_class;
66 GtkObjectClass *object_class;
67 GtkWidgetClass *widget_class;
69 widget_class = (GtkWidgetClass*) class;
70 object_class = (GtkObjectClass*) class;
71 gobject_class = (GObjectClass*) class;
73 widget_class->realize = gtk_invisible_realize;
74 widget_class->style_set = gtk_invisible_style_set;
75 widget_class->show = gtk_invisible_show;
76 widget_class->size_allocate = gtk_invisible_size_allocate;
78 object_class->destroy = gtk_invisible_destroy;
79 gobject_class->set_property = gtk_invisible_set_property;
80 gobject_class->get_property = gtk_invisible_get_property;
81 gobject_class->constructor = gtk_invisible_constructor;
83 g_object_class_install_property (gobject_class,
85 g_param_spec_object ("screen",
87 P_("The screen where this window will be displayed"),
89 GTK_PARAM_READWRITE));
93 gtk_invisible_init (GtkInvisible *invisible)
95 GdkColormap *colormap;
97 GTK_WIDGET_UNSET_FLAGS (invisible, GTK_NO_WINDOW);
98 GTK_WIDGET_SET_FLAGS (invisible, GTK_TOPLEVEL);
100 g_object_ref_sink (invisible);
102 invisible->has_user_ref_count = TRUE;
103 invisible->screen = gdk_screen_get_default ();
105 colormap = _gtk_widget_peek_colormap ();
107 gtk_widget_set_colormap (GTK_WIDGET (invisible), colormap);
111 gtk_invisible_destroy (GtkObject *object)
113 GtkInvisible *invisible = GTK_INVISIBLE (object);
115 if (invisible->has_user_ref_count)
117 invisible->has_user_ref_count = FALSE;
118 g_object_unref (invisible);
121 GTK_OBJECT_CLASS (gtk_invisible_parent_class)->destroy (object);
125 * gtk_invisible_new_for_screen:
126 * @screen: a #GdkScreen which identifies on which
127 * the new #GtkInvisible will be created.
129 * Creates a new #GtkInvisible object for a specified screen
131 * Return value: a newly created #GtkInvisible object
136 gtk_invisible_new_for_screen (GdkScreen *screen)
138 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
140 return g_object_new (GTK_TYPE_INVISIBLE, "screen", screen, NULL);
146 * Creates a new #GtkInvisible.
148 * Return value: a new #GtkInvisible.
151 gtk_invisible_new (void)
153 return g_object_new (GTK_TYPE_INVISIBLE, NULL);
157 * gtk_invisible_set_screen:
158 * @invisible: a #GtkInvisible.
159 * @screen: a #GdkScreen.
161 * Sets the #GdkScreen where the #GtkInvisible object will be displayed.
166 gtk_invisible_set_screen (GtkInvisible *invisible,
170 GdkScreen *previous_screen;
171 gboolean was_realized;
173 g_return_if_fail (GTK_IS_INVISIBLE (invisible));
174 g_return_if_fail (GDK_IS_SCREEN (screen));
176 if (screen == invisible->screen)
179 widget = GTK_WIDGET (invisible);
181 previous_screen = invisible->screen;
182 was_realized = GTK_WIDGET_REALIZED (invisible);
185 gtk_widget_unrealize (widget);
187 invisible->screen = screen;
188 if (screen != previous_screen)
189 _gtk_widget_propagate_screen_changed (widget, previous_screen);
190 g_object_notify (G_OBJECT (invisible), "screen");
193 gtk_widget_realize (widget);
197 * gtk_invisible_get_screen:
198 * @invisible: a #GtkInvisible.
200 * Returns the #GdkScreen object associated with @invisible
202 * Return value: the associated #GdkScreen.
207 gtk_invisible_get_screen (GtkInvisible *invisible)
209 g_return_val_if_fail (GTK_IS_INVISIBLE (invisible), NULL);
211 return invisible->screen;
215 gtk_invisible_realize (GtkWidget *widget)
217 GdkWindowAttr attributes;
218 gint attributes_mask;
220 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
224 attributes.width = 10;
225 attributes.height = 10;
226 attributes.window_type = GDK_WINDOW_TEMP;
227 attributes.wclass = GDK_INPUT_ONLY;
228 attributes.override_redirect = TRUE;
229 attributes.event_mask = gtk_widget_get_events (widget);
231 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
233 widget->window = gdk_window_new (gtk_widget_get_root_window (widget),
234 &attributes, attributes_mask);
236 gdk_window_set_user_data (widget->window, widget);
238 widget->style = gtk_style_attach (widget->style, widget->window);
242 gtk_invisible_style_set (GtkWidget *widget,
243 GtkStyle *previous_style)
245 /* Don't chain up to parent implementation */
249 gtk_invisible_show (GtkWidget *widget)
251 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
252 gtk_widget_map (widget);
256 gtk_invisible_size_allocate (GtkWidget *widget,
257 GtkAllocation *allocation)
259 widget->allocation = *allocation;
264 gtk_invisible_set_property (GObject *object,
269 GtkInvisible *invisible = GTK_INVISIBLE (object);
274 gtk_invisible_set_screen (invisible, g_value_get_object (value));
277 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
283 gtk_invisible_get_property (GObject *object,
288 GtkInvisible *invisible = GTK_INVISIBLE (object);
293 g_value_set_object (value, invisible->screen);
296 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
301 /* We use a constructor here so that we can realize the invisible on
302 * the correct screen after the "screen" property has been set
305 gtk_invisible_constructor (GType type,
306 guint n_construct_properties,
307 GObjectConstructParam *construct_params)
311 object = (* G_OBJECT_CLASS (gtk_invisible_parent_class)->constructor) (type,
312 n_construct_properties,
315 gtk_widget_realize (GTK_WIDGET (object));
320 #define __GTK_INVISIBLE_C__
321 #include "gtkaliasdef.c"