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