]> Pileus Git - ~andy/gtk/blob - gdk/quartz/gdkvisual-quartz.c
Do not use static GTypeInfo and GInterfaceInfo
[~andy/gtk] / gdk / quartz / gdkvisual-quartz.c
1 /* gdkvisual-quartz.c
2  *
3  * Copyright (C) 2005 Imendio AB
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #include "config.h"
22
23 #include "gdkvisual.h"
24 #include "gdkprivate-quartz.h"
25
26 /* FIXME: We might want to include the rgba visual in the query functions */
27
28 static GdkVisual *system_visual;
29 static GdkVisual *rgba_visual;
30
31 static void
32 gdk_visual_finalize (GObject *object)
33 {
34   g_error ("A GdkVisual object was finalized. This should not happen");
35 }
36
37 static void
38 gdk_visual_class_init (GObjectClass *class)
39 {
40   class->finalize = gdk_visual_finalize;
41 }
42
43 GType
44 gdk_visual_get_type (void)
45 {
46   static GType object_type = 0;
47
48   if (!object_type)
49     {
50       const GTypeInfo object_info =
51       {
52         sizeof (GdkVisualClass),
53         (GBaseInitFunc) NULL,
54         (GBaseFinalizeFunc) NULL,
55         (GClassInitFunc) gdk_visual_class_init,
56         NULL,           /* class_finalize */
57         NULL,           /* class_data */
58         sizeof (GdkVisual),
59         0,              /* n_preallocs */
60         (GInstanceInitFunc) NULL,
61       };
62       
63       object_type = g_type_register_static (G_TYPE_OBJECT,
64                                             "GdkVisual",
65                                             &object_info, 0);
66     }
67   
68   return object_type;
69 }
70
71 static void
72 gdk_visual_decompose_mask (gulong  mask,
73                            gint   *shift,
74                            gint   *prec)
75 {
76   *shift = 0;
77   *prec = 0;
78
79   while (!(mask & 0x1))
80     {
81       (*shift)++;
82       mask >>= 1;
83     }
84
85   while (mask & 0x1)
86     {
87       (*prec)++;
88       mask >>= 1;
89     }
90 }
91
92 static GdkVisual *
93 create_standard_visual (gint depth)
94 {
95   GdkVisual *visual = g_object_new (GDK_TYPE_VISUAL, NULL);
96
97   visual->depth = depth;
98   visual->byte_order = GDK_MSB_FIRST; /* FIXME: Should this be different on intel macs? */
99   visual->colormap_size = 0;
100   
101   visual->type = GDK_VISUAL_TRUE_COLOR;
102
103   visual->red_mask = 0xff0000;
104   visual->green_mask = 0xff00;
105   visual->blue_mask = 0xff;
106   
107   gdk_visual_decompose_mask (visual->red_mask,
108                              &visual->red_shift,
109                              &visual->red_prec);
110   gdk_visual_decompose_mask (visual->green_mask,
111                              &visual->green_shift,
112                              &visual->green_prec);
113   gdk_visual_decompose_mask (visual->blue_mask,
114                              &visual->blue_shift,
115                              &visual->blue_prec);
116
117   return visual;
118 }
119
120 void
121 _gdk_visual_init (void)
122 {
123   system_visual = create_standard_visual (24);
124   rgba_visual = create_standard_visual (32);
125 }
126
127 gint
128 gdk_visual_get_best_depth (void)
129 {
130   return system_visual->depth;
131 }
132
133 GdkVisualType
134 gdk_visual_get_best_type (void)
135 {
136   return system_visual->type;
137 }
138
139 GdkVisual *
140 gdk_screen_get_rgba_visual (GdkScreen *screen)
141 {
142   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
143
144   return rgba_visual;
145 }
146
147 GdkVisual*
148 gdk_screen_get_system_visual (GdkScreen *screen)
149 {
150   return system_visual;
151 }
152
153 GdkVisual*
154 gdk_visual_get_best (void)
155 {
156   return system_visual;
157 }
158
159 GdkVisual*
160 gdk_visual_get_best_with_depth (gint depth)
161 {
162   if (system_visual->depth != depth)
163     return NULL;
164
165   return system_visual;
166 }
167
168 GdkVisual*
169 gdk_visual_get_best_with_type (GdkVisualType visual_type)
170 {
171   if (system_visual->type != visual_type)
172     return NULL;
173
174   return system_visual;
175 }
176
177 GdkVisual*
178 gdk_visual_get_best_with_both (gint          depth,
179                                GdkVisualType visual_type)
180 {
181   if (system_visual->depth != depth)
182     return NULL;
183
184   if (system_visual->type != visual_type)
185     return NULL;
186
187   return system_visual;
188 }
189
190 void
191 gdk_query_depths  (gint **depths,
192                    gint  *count)
193 {
194   *count = 1;
195   *depths = &system_visual->depth;
196 }
197
198 void
199 gdk_query_visual_types (GdkVisualType **visual_types,
200                         gint           *count)
201 {
202   *count = 1;
203   *visual_types = &system_visual->type;
204 }
205
206 GList*
207 gdk_screen_list_visuals (GdkScreen *screen)
208 {
209   return g_list_append (NULL, gdk_visual_get_system ());
210 }
211
212 GdkScreen *
213 gdk_visual_get_screen (GdkVisual *visual)
214 {
215   g_return_val_if_fail (GDK_IS_VISUAL (visual), NULL);
216
217   return gdk_screen_get_default ();
218 }
219