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