]> Pileus Git - ~andy/gtk/blob - gtk/gtkinvisible.c
Make the default default colormap the GdkRGB colormap, not the system
[~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_style_set     (GtkWidget         *widget,
36                                          GtkStyle          *previous_style);
37 static void gtk_invisible_show          (GtkWidget         *widget);
38 static void gtk_invisible_size_allocate (GtkWidget         *widget,
39                                          GtkAllocation     *allocation);
40
41 GtkType
42 gtk_invisible_get_type (void)
43 {
44   static GtkType invisible_type = 0;
45
46   if (!invisible_type)
47     {
48       static const GtkTypeInfo invisible_info =
49       {
50         "GtkInvisible",
51         sizeof (GtkInvisible),
52         sizeof (GtkInvisibleClass),
53         (GtkClassInitFunc) gtk_invisible_class_init,
54         (GtkObjectInitFunc) gtk_invisible_init,
55         /* reserved_1 */ NULL,
56         /* reserved_2 */ NULL,
57         (GtkClassInitFunc) NULL,
58       };
59
60       invisible_type = gtk_type_unique (GTK_TYPE_WIDGET, &invisible_info);
61     }
62
63   return invisible_type;
64 }
65
66 static void
67 gtk_invisible_class_init (GtkInvisibleClass *class)
68 {
69   GtkObjectClass *object_class;
70   GtkWidgetClass *widget_class;
71
72   widget_class = (GtkWidgetClass*) class;
73   object_class = (GtkObjectClass*) class;
74
75   widget_class->realize = gtk_invisible_realize;
76   widget_class->style_set = gtk_invisible_style_set;
77   widget_class->show = gtk_invisible_show;
78   widget_class->size_allocate = gtk_invisible_size_allocate;
79
80   object_class->destroy = gtk_invisible_destroy;
81 }
82
83 static void
84 gtk_invisible_init (GtkInvisible *invisible)
85 {
86   GdkColormap *colormap;
87   
88   GTK_WIDGET_UNSET_FLAGS (invisible, GTK_NO_WINDOW);
89   GTK_WIDGET_SET_FLAGS (invisible, GTK_TOPLEVEL);
90
91   gtk_widget_ref (GTK_WIDGET (invisible));
92   gtk_object_sink (GTK_OBJECT (invisible));
93
94   invisible->has_user_ref_count = TRUE;
95   
96   colormap = _gtk_widget_peek_colormap ();
97   if (colormap)
98     gtk_widget_set_colormap (GTK_WIDGET (invisible), colormap);
99 }
100
101 static void
102 gtk_invisible_destroy (GtkObject *object)
103 {
104   GtkInvisible *invisible = GTK_INVISIBLE (object);
105   
106   if (invisible->has_user_ref_count)
107     {
108       invisible->has_user_ref_count = FALSE;
109       gtk_widget_unref (GTK_WIDGET (invisible));
110     }
111 }
112
113 GtkWidget*
114 gtk_invisible_new (void)
115 {
116   GtkWidget *result = GTK_WIDGET (gtk_type_new (GTK_TYPE_INVISIBLE));
117   gtk_widget_realize (result);
118
119   return result;
120 }
121
122 static void
123 gtk_invisible_realize (GtkWidget *widget)
124 {
125   GdkWindowAttr attributes;
126   gint attributes_mask;
127
128   g_return_if_fail (GTK_IS_INVISIBLE (widget));
129
130   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
131
132   attributes.x = -100;
133   attributes.y = -100;
134   attributes.width = 10;
135   attributes.height = 10;
136   attributes.window_type = GDK_WINDOW_TEMP;
137   attributes.wclass = GDK_INPUT_ONLY;
138   attributes.override_redirect = TRUE;
139   attributes.event_mask = gtk_widget_get_events (widget);
140
141   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
142
143   widget->window = gdk_window_new (NULL, &attributes, attributes_mask);
144   gdk_window_set_user_data (widget->window, widget);
145   
146   widget->style = gtk_style_attach (widget->style, widget->window);
147 }
148
149 static void
150 gtk_invisible_style_set (GtkWidget *widget,
151                          GtkStyle  *previous_style)
152 {
153   /* Don't chain up to parent implementation */
154 }
155
156 static void
157 gtk_invisible_show (GtkWidget *widget)
158 {
159   g_return_if_fail (widget != NULL);
160
161   GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
162   gtk_widget_map (widget);
163 }
164
165 static void
166 gtk_invisible_size_allocate (GtkWidget     *widget,
167                             GtkAllocation *allocation)
168 {
169   widget->allocation = *allocation;
170 }