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