]> Pileus Git - ~andy/gtk/blob - gtk/gtkinvisible.c
Flag invisible widgets as TOPLEVEL.
[~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 "gtksignal.h"
29 #include "gtkinvisible.h"
30
31 static void gtk_invisible_class_init               (GtkInvisibleClass *klass);
32 static void gtk_invisible_init                     (GtkInvisible      *invisible);
33 static void gtk_invisible_destroy                  (GtkObject        *object);
34 static void gtk_invisible_realize                  (GtkWidget        *widget);
35 static void gtk_invisible_show                     (GtkWidget        *widget);
36 static void gtk_invisible_size_allocate            (GtkWidget        *widget,
37                                                     GtkAllocation    *allocation);
38
39 GtkType
40 gtk_invisible_get_type (void)
41 {
42   static GtkType invisible_type = 0;
43
44   if (!invisible_type)
45     {
46       static const GtkTypeInfo invisible_info =
47       {
48         "GtkInvisible",
49         sizeof (GtkInvisible),
50         sizeof (GtkInvisibleClass),
51         (GtkClassInitFunc) gtk_invisible_class_init,
52         (GtkObjectInitFunc) gtk_invisible_init,
53         /* reserved_1 */ NULL,
54         /* reserved_2 */ NULL,
55         (GtkClassInitFunc) NULL,
56       };
57
58       invisible_type = gtk_type_unique (GTK_TYPE_WIDGET, &invisible_info);
59     }
60
61   return invisible_type;
62 }
63
64 static void
65 gtk_invisible_class_init (GtkInvisibleClass *class)
66 {
67   GtkObjectClass *object_class;
68   GtkWidgetClass *widget_class;
69
70   widget_class = (GtkWidgetClass*) class;
71   object_class = (GtkObjectClass*) class;
72
73   widget_class->realize = gtk_invisible_realize;
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 }
79
80 static void
81 gtk_invisible_init (GtkInvisible *invisible)
82 {
83   GTK_WIDGET_UNSET_FLAGS (invisible, GTK_NO_WINDOW);
84   GTK_WIDGET_SET_FLAGS (invisible, GTK_TOPLEVEL);
85
86   gtk_widget_ref (GTK_WIDGET (invisible));
87   gtk_object_sink (GTK_OBJECT (invisible));
88
89   invisible->has_user_ref_count = TRUE;
90 }
91
92 static void
93 gtk_invisible_destroy (GtkObject *object)
94 {
95   GtkInvisible *invisible = GTK_INVISIBLE (object);
96   
97   if (invisible->has_user_ref_count)
98     {
99       invisible->has_user_ref_count = FALSE;
100       gtk_widget_unref (GTK_WIDGET (invisible));
101     }
102 }
103
104 GtkWidget*
105 gtk_invisible_new (void)
106 {
107   GtkWidget *result = GTK_WIDGET (gtk_type_new (GTK_TYPE_INVISIBLE));
108   gtk_widget_realize (result);
109
110   return result;
111 }
112
113 static void
114 gtk_invisible_realize (GtkWidget *widget)
115 {
116   GdkWindowAttr attributes;
117   gint attributes_mask;
118
119   g_return_if_fail (widget != NULL);
120   g_return_if_fail (GTK_IS_INVISIBLE (widget));
121
122   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
123
124   attributes.x = -100;
125   attributes.y = -100;
126   attributes.width = 10;
127   attributes.height = 10;
128   attributes.window_type = GDK_WINDOW_TEMP;
129   attributes.wclass = GDK_INPUT_ONLY;
130   attributes.override_redirect = TRUE;
131   attributes.event_mask = gtk_widget_get_events (widget);
132
133   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
134
135   widget->window = gdk_window_new (NULL, &attributes, attributes_mask);
136   gdk_window_set_user_data (widget->window, widget);
137 }
138
139 static void
140 gtk_invisible_show (GtkWidget *widget)
141 {
142   g_return_if_fail (widget != NULL);
143
144   GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
145   gtk_widget_map (widget);
146 }
147
148 static void
149 gtk_invisible_size_allocate (GtkWidget     *widget,
150                             GtkAllocation *allocation)
151 {
152   widget->allocation = *allocation;
153 }