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"
33 struct _GtkInvisiblePrivate
36 gboolean has_user_ref_count;
45 static void gtk_invisible_destroy (GtkObject *object);
46 static void gtk_invisible_realize (GtkWidget *widget);
47 static void gtk_invisible_style_set (GtkWidget *widget,
48 GtkStyle *previous_style);
49 static void gtk_invisible_show (GtkWidget *widget);
50 static void gtk_invisible_size_allocate (GtkWidget *widget,
51 GtkAllocation *allocation);
52 static void gtk_invisible_set_property (GObject *object,
56 static void gtk_invisible_get_property (GObject *object,
61 static GObject *gtk_invisible_constructor (GType type,
62 guint n_construct_properties,
63 GObjectConstructParam *construct_params);
65 G_DEFINE_TYPE (GtkInvisible, gtk_invisible, GTK_TYPE_WIDGET)
68 gtk_invisible_class_init (GtkInvisibleClass *class)
70 GObjectClass *gobject_class;
71 GtkObjectClass *object_class;
72 GtkWidgetClass *widget_class;
74 widget_class = (GtkWidgetClass*) class;
75 object_class = (GtkObjectClass*) class;
76 gobject_class = (GObjectClass*) class;
78 widget_class->realize = gtk_invisible_realize;
79 widget_class->style_set = gtk_invisible_style_set;
80 widget_class->show = gtk_invisible_show;
81 widget_class->size_allocate = gtk_invisible_size_allocate;
83 object_class->destroy = gtk_invisible_destroy;
84 gobject_class->set_property = gtk_invisible_set_property;
85 gobject_class->get_property = gtk_invisible_get_property;
86 gobject_class->constructor = gtk_invisible_constructor;
88 g_object_class_install_property (gobject_class,
90 g_param_spec_object ("screen",
92 P_("The screen where this window will be displayed"),
94 GTK_PARAM_READWRITE));
96 g_type_class_add_private (class, sizeof (GtkInvisiblePrivate));
100 gtk_invisible_init (GtkInvisible *invisible)
102 GtkInvisiblePrivate *priv;
104 invisible->priv = G_TYPE_INSTANCE_GET_PRIVATE (invisible,
106 GtkInvisiblePrivate);
107 priv = invisible->priv;
109 gtk_widget_set_has_window (GTK_WIDGET (invisible), TRUE);
110 _gtk_widget_set_is_toplevel (GTK_WIDGET (invisible), TRUE);
112 g_object_ref_sink (invisible);
114 priv->has_user_ref_count = TRUE;
115 priv->screen = gdk_screen_get_default ();
119 gtk_invisible_destroy (GtkObject *object)
121 GtkInvisible *invisible = GTK_INVISIBLE (object);
122 GtkInvisiblePrivate *priv = invisible->priv;
124 if (priv->has_user_ref_count)
126 priv->has_user_ref_count = FALSE;
127 g_object_unref (invisible);
130 GTK_OBJECT_CLASS (gtk_invisible_parent_class)->destroy (object);
134 * gtk_invisible_new_for_screen:
135 * @screen: a #GdkScreen which identifies on which
136 * the new #GtkInvisible will be created.
138 * Creates a new #GtkInvisible object for a specified screen
140 * Return value: a newly created #GtkInvisible object
145 gtk_invisible_new_for_screen (GdkScreen *screen)
147 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
149 return g_object_new (GTK_TYPE_INVISIBLE, "screen", screen, NULL);
155 * Creates a new #GtkInvisible.
157 * Return value: a new #GtkInvisible.
160 gtk_invisible_new (void)
162 return g_object_new (GTK_TYPE_INVISIBLE, NULL);
166 * gtk_invisible_set_screen:
167 * @invisible: a #GtkInvisible.
168 * @screen: a #GdkScreen.
170 * Sets the #GdkScreen where the #GtkInvisible object will be displayed.
175 gtk_invisible_set_screen (GtkInvisible *invisible,
178 GtkInvisiblePrivate *priv;
180 GdkScreen *previous_screen;
181 gboolean was_realized;
183 g_return_if_fail (GTK_IS_INVISIBLE (invisible));
184 g_return_if_fail (GDK_IS_SCREEN (screen));
186 priv = invisible->priv;
188 if (screen == priv->screen)
191 widget = GTK_WIDGET (invisible);
193 previous_screen = priv->screen;
194 was_realized = gtk_widget_get_realized (widget);
197 gtk_widget_unrealize (widget);
199 priv->screen = screen;
200 if (screen != previous_screen)
201 _gtk_widget_propagate_screen_changed (widget, previous_screen);
202 g_object_notify (G_OBJECT (invisible), "screen");
205 gtk_widget_realize (widget);
209 * gtk_invisible_get_screen:
210 * @invisible: a #GtkInvisible.
212 * Returns the #GdkScreen object associated with @invisible
214 * Return value: (transfer none): the associated #GdkScreen.
219 gtk_invisible_get_screen (GtkInvisible *invisible)
221 g_return_val_if_fail (GTK_IS_INVISIBLE (invisible), NULL);
223 return invisible->priv->screen;
227 gtk_invisible_realize (GtkWidget *widget)
231 GdkWindowAttr attributes;
232 gint attributes_mask;
234 gtk_widget_set_realized (widget, TRUE);
236 parent = gtk_widget_get_parent_window (widget);
238 parent = gtk_widget_get_root_window (widget);
242 attributes.width = 10;
243 attributes.height = 10;
244 attributes.window_type = GDK_WINDOW_TEMP;
245 attributes.wclass = GDK_INPUT_ONLY;
246 attributes.override_redirect = TRUE;
247 attributes.event_mask = gtk_widget_get_events (widget);
249 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
251 window = gdk_window_new (parent, &attributes, attributes_mask);
252 gtk_widget_set_window (widget, window);
253 gdk_window_set_user_data (window, widget);
255 gtk_widget_style_attach (widget);
259 gtk_invisible_style_set (GtkWidget *widget,
260 GtkStyle *previous_style)
262 /* Don't chain up to parent implementation */
266 gtk_invisible_show (GtkWidget *widget)
268 GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
269 gtk_widget_map (widget);
273 gtk_invisible_size_allocate (GtkWidget *widget,
274 GtkAllocation *allocation)
276 gtk_widget_set_allocation (widget, allocation);
281 gtk_invisible_set_property (GObject *object,
286 GtkInvisible *invisible = GTK_INVISIBLE (object);
291 gtk_invisible_set_screen (invisible, g_value_get_object (value));
294 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
300 gtk_invisible_get_property (GObject *object,
305 GtkInvisible *invisible = GTK_INVISIBLE (object);
306 GtkInvisiblePrivate *priv = invisible->priv;
311 g_value_set_object (value, priv->screen);
314 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
319 /* We use a constructor here so that we can realize the invisible on
320 * the correct screen after the "screen" property has been set
323 gtk_invisible_constructor (GType type,
324 guint n_construct_properties,
325 GObjectConstructParam *construct_params)
329 object = G_OBJECT_CLASS (gtk_invisible_parent_class)->constructor (type,
330 n_construct_properties,
333 gtk_widget_realize (GTK_WIDGET (object));