]> Pileus Git - ~andy/gtk/blob - gtk/gtkinvisible.c
Document 2.2 API additions.
[~andy/gtk] / gtk / gtkinvisible.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 /*
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/. 
25  */
26
27 #include <gdk/gdk.h>
28 #include "gtkinvisible.h"
29 #include "gtkintl.h"
30
31 enum {
32   PROP_0,
33   PROP_SCREEN,
34   LAST_ARG
35 };
36
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,
47                                          guint              prop_id,
48                                          const GValue      *value,
49                                          GParamSpec        *pspec);
50 static void gtk_invisible_get_property  (GObject           *object,
51                                          guint              prop_id,
52                                          GValue            *value,
53                                          GParamSpec        *pspec);
54
55 static GObject *gtk_invisible_constructor (GType                  type,
56                                            guint                  n_construct_properties,
57                                            GObjectConstructParam *construct_params);
58
59 static GObjectClass *parent_class;
60
61 GType
62 gtk_invisible_get_type (void)
63 {
64   static GType invisible_type = 0;
65
66   if (!invisible_type)
67     {
68       static const GTypeInfo invisible_info =
69       {
70         sizeof (GtkInvisibleClass),
71         NULL,           /* base_init */
72         NULL,           /* base_finalize */
73         (GClassInitFunc) gtk_invisible_class_init,
74         NULL,           /* class_finalize */
75         NULL,           /* class_data */
76         sizeof (GtkInvisible),
77         0,              /* n_preallocs */
78         (GInstanceInitFunc) gtk_invisible_init,
79       };
80
81       invisible_type = g_type_register_static (GTK_TYPE_WIDGET, "GtkInvisible",
82                                                &invisible_info, 0);
83     }
84
85   return invisible_type;
86 }
87
88 static void
89 gtk_invisible_class_init (GtkInvisibleClass *class)
90 {
91   GObjectClass   *gobject_class;
92   GtkObjectClass *object_class;
93   GtkWidgetClass *widget_class;
94
95   widget_class = (GtkWidgetClass*) class;
96   object_class = (GtkObjectClass*) class;
97   gobject_class = (GObjectClass*) class;
98
99   parent_class = g_type_class_peek_parent (class);
100
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;
105
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;
110
111   g_object_class_install_property (gobject_class,
112                                    PROP_SCREEN,
113                                    g_param_spec_object ("screen",
114                                                         _("Screen"),
115                                                         _("The screen where this window will be displayed"),
116                                                         GDK_TYPE_SCREEN,
117                                                         G_PARAM_READWRITE));
118 }
119
120 static void
121 gtk_invisible_init (GtkInvisible *invisible)
122 {
123   GdkColormap *colormap;
124   
125   GTK_WIDGET_UNSET_FLAGS (invisible, GTK_NO_WINDOW);
126   GTK_WIDGET_SET_FLAGS (invisible, GTK_TOPLEVEL);
127
128   g_object_ref (invisible);
129   gtk_object_sink (GTK_OBJECT (invisible));
130
131   invisible->has_user_ref_count = TRUE;
132   invisible->screen = gdk_screen_get_default ();
133   
134   colormap = _gtk_widget_peek_colormap ();
135   if (colormap)
136     gtk_widget_set_colormap (GTK_WIDGET (invisible), colormap);
137 }
138
139 static void
140 gtk_invisible_destroy (GtkObject *object)
141 {
142   GtkInvisible *invisible = GTK_INVISIBLE (object);
143   
144   if (invisible->has_user_ref_count)
145     {
146       invisible->has_user_ref_count = FALSE;
147       g_object_unref (invisible);
148     }
149 }
150
151 /**
152  * gtk_invisible_new_for_screen:
153  * @screen: a #GdkScreen which identifies on which
154  *          the new #GtkInvisible will be created.
155  *
156  * Creates a new #GtkInvisible object for a specified screen
157  *
158  * Return value: a newly created #GtkInvisible object
159  *
160  * Since: 2.2
161  **/
162 GtkWidget* 
163 gtk_invisible_new_for_screen (GdkScreen *screen)
164 {
165   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
166   
167   return g_object_new (GTK_TYPE_INVISIBLE, "screen", screen, NULL);
168 }
169
170 /**
171  * gtk_invisible_new:
172  * 
173  * Creates a new #GtkInvisible.
174  * 
175  * Return value: a new #GtkInvisible.
176  **/
177 GtkWidget*
178 gtk_invisible_new (void)
179 {
180   return g_object_new (GTK_TYPE_INVISIBLE, NULL);
181 }
182
183 /**
184  * gtk_invisible_set_screen:
185  * @invisible: a #GtkInvisible.
186  * @screen: a #GdkScreen.
187  *
188  * Sets the #GdkScreen where the #GtkInvisible object will be displayed.
189  *
190  * Since: 2.2
191  **/ 
192 void
193 gtk_invisible_set_screen (GtkInvisible *invisible,
194                           GdkScreen    *screen)
195 {
196   GtkWidget *widget;
197   GdkScreen *previous_screen;
198   gboolean was_realized;
199   
200   g_return_if_fail (GTK_IS_INVISIBLE (invisible));
201   g_return_if_fail (GDK_IS_SCREEN (screen));
202
203   if (screen == invisible->screen)
204     return;
205
206   widget = GTK_WIDGET (invisible);
207
208   previous_screen = invisible->screen;
209   was_realized = GTK_WIDGET_REALIZED (invisible);
210
211   if (was_realized)
212     gtk_widget_unrealize (widget);
213   
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");
218   
219   if (was_realized)
220     gtk_widget_realize (widget);
221 }
222
223 /**
224  * gtk_invisible_get_screen:
225  * @invisible: a #GtkInvisible.
226  *
227  * Returns the #GdkScreen object associated with @invisible
228  *
229  * Return value: the associated #GdkScreen.
230  *
231  * Since: 2.2
232  **/
233 GdkScreen *
234 gtk_invisible_get_screen (GtkInvisible *invisible)
235 {
236   g_return_val_if_fail (GTK_IS_INVISIBLE (invisible), NULL);
237   
238   return invisible->screen;
239 }
240
241 static void
242 gtk_invisible_realize (GtkWidget *widget)
243 {
244   GdkWindowAttr attributes;
245   gint attributes_mask;
246
247   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
248
249   attributes.x = -100;
250   attributes.y = -100;
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);
257
258   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
259
260   widget->window = gdk_window_new (gtk_widget_get_root_window (widget),
261                                    &attributes, attributes_mask);
262                                               
263   gdk_window_set_user_data (widget->window, widget);
264   
265   widget->style = gtk_style_attach (widget->style, widget->window);
266 }
267
268 static void
269 gtk_invisible_style_set (GtkWidget *widget,
270                          GtkStyle  *previous_style)
271 {
272   /* Don't chain up to parent implementation */
273 }
274
275 static void
276 gtk_invisible_show (GtkWidget *widget)
277 {
278   GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
279   gtk_widget_map (widget);
280 }
281
282 static void
283 gtk_invisible_size_allocate (GtkWidget     *widget,
284                             GtkAllocation *allocation)
285 {
286   widget->allocation = *allocation;
287
288
289
290 static void 
291 gtk_invisible_set_property  (GObject      *object,
292                              guint         prop_id,
293                              const GValue *value,
294                              GParamSpec   *pspec)
295 {
296   GtkInvisible *invisible = GTK_INVISIBLE (object);
297   
298   switch (prop_id)
299     {
300     case PROP_SCREEN:
301       gtk_invisible_set_screen (invisible, g_value_get_object (value));
302       break;
303     default:
304       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
305       break;
306     }
307 }
308
309 static void 
310 gtk_invisible_get_property  (GObject      *object,
311                              guint         prop_id,
312                              GValue       *value,
313                              GParamSpec   *pspec)
314 {
315   GtkInvisible *invisible = GTK_INVISIBLE (object);
316
317   switch (prop_id)
318     {
319     case PROP_SCREEN:
320       g_value_set_object (value, invisible->screen);
321       break;
322     default:
323       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
324       break;
325     }
326 }
327
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
330  */
331 static GObject*
332 gtk_invisible_constructor (GType                  type,
333                            guint                  n_construct_properties,
334                            GObjectConstructParam *construct_params)
335 {
336   GObject *object;
337
338   object = (* G_OBJECT_CLASS (parent_class)->constructor) (type,
339                                                            n_construct_properties,
340                                                            construct_params);
341
342   gtk_widget_realize (GTK_WIDGET (object));
343
344   return object;
345 }
346