]> Pileus Git - ~andy/gtk/blob - gdk/quartz/gdkcolor-quartz.c
Add escape to the list of special keys, to get the escape key working.
[~andy/gtk] / gdk / quartz / gdkcolor-quartz.c
1 /* gdkcolor-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 "gdkcolor.h"
24 #include "gdkprivate-quartz.h"
25
26 GType
27 gdk_colormap_get_type (void)
28 {
29   static GType object_type = 0;
30
31   if (!object_type)
32     {
33       static const GTypeInfo object_info =
34       {
35         sizeof (GdkColormapClass),
36         (GBaseInitFunc) NULL,
37         (GBaseFinalizeFunc) NULL,
38         (GClassInitFunc) NULL,
39         NULL,           /* class_finalize */
40         NULL,           /* class_data */
41         sizeof (GdkColormap),
42         0,              /* n_preallocs */
43         (GInstanceInitFunc) NULL,
44       };
45       
46       object_type = g_type_register_static (G_TYPE_OBJECT,
47                                             "GdkColormap",
48                                             &object_info,
49                                             0);
50     }
51   
52   return object_type;
53 }
54
55 GdkColormap *
56 gdk_colormap_new (GdkVisual *visual,
57                   gint       private_cmap)
58 {
59   g_return_val_if_fail (visual != NULL, NULL);
60
61   /* FIXME: Implement */
62   return NULL;
63 }
64
65 GdkColormap *
66 gdk_screen_get_system_colormap (GdkScreen *screen)
67 {
68   static GdkColormap *colormap = NULL;
69
70   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
71
72   if (!colormap)
73     {
74       colormap = g_object_new (GDK_TYPE_COLORMAP, NULL);
75
76       colormap->visual = gdk_visual_get_system ();
77       colormap->size = colormap->visual->colormap_size;
78     }
79
80   return colormap;
81 }
82
83
84 GdkColormap *
85 gdk_screen_get_rgba_colormap (GdkScreen *screen)
86 {
87   static GdkColormap *colormap = NULL;
88
89   g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
90
91   if (!colormap)
92     {
93       colormap = g_object_new (GDK_TYPE_COLORMAP, NULL);
94
95       colormap->visual = gdk_screen_get_rgba_visual (screen);
96       colormap->size = colormap->visual->colormap_size;
97     }
98
99   return colormap;
100 }
101
102 gint
103 gdk_colormap_get_system_size (void)
104 {
105   /* FIXME: Implement */
106   return 0;
107 }
108
109 void
110 gdk_colormap_change (GdkColormap *colormap,
111                      gint         ncolors)
112 {
113   /* FIXME: Implement */
114 }
115
116 void
117 gdk_colormap_free_colors (GdkColormap *colormap,
118                           GdkColor    *colors,
119                           gint         ncolors)
120 {
121   /* This function shouldn't do anything since
122    * colors are neve allocated.
123    */
124 }
125
126 gint
127 gdk_colormap_alloc_colors (GdkColormap *colormap,
128                            GdkColor    *colors,
129                            gint         ncolors,
130                            gboolean     writeable,
131                            gboolean     best_match,
132                            gboolean    *success)
133 {
134   int i;
135
136   for (i = 0; i < ncolors; i++)
137     {
138       colors[i].pixel = ((colors[i].red >> 8) & 0xff) << 16 |
139                         ((colors[i].green >> 8) & 0xff) << 8 |
140                         ((colors[i].blue >> 8) & 0xff);
141     }
142
143   return ncolors;
144 }
145
146 void
147 gdk_colormap_query_color (GdkColormap *colormap,
148                           gulong       pixel,
149                           GdkColor    *result)
150 {
151   result->red = pixel >> 16 & 0xff;
152   result->red += result->red << 8;
153
154   result->green = pixel >> 8 & 0xff;
155   result->green += result->green << 8;
156
157   result->blue = pixel & 0xff;
158   result->blue += result->blue << 8;
159 }
160
161 GdkScreen*
162 gdk_colormap_get_screen (GdkColormap *cmap)
163 {
164   g_return_val_if_fail (cmap != NULL, NULL);
165
166   return gdk_screen_get_default ();
167 }
168
169 void
170 _gdk_quartz_set_context_fill_color_from_pixel (CGContextRef context, GdkColormap *colormap, guint32 pixel)
171 {
172   float red, green, blue, alpha;
173
174   red = (pixel >> 16 & 0xff) / 255.0;
175   green = (pixel >> 8 & 0xff) / 255.0;
176   blue = (pixel & 0xff) / 255.0;
177
178   if (colormap && gdk_colormap_get_visual (colormap)->depth == 32)
179     alpha = (pixel >> 24 & 0xff) / 255.0;
180   else
181     alpha = 1.0;
182
183   CGContextSetRGBFillColor (context, red, green, blue, alpha);
184 }
185
186 void
187 _gdk_quartz_set_context_stroke_color_from_pixel (CGContextRef context, GdkColormap *colormap, guint32 pixel)
188 {
189   float red, green, blue, alpha;
190
191   red = (pixel >> 16 & 0xff) / 255.0;
192   green = (pixel >> 8 & 0xff) / 255.0;
193   blue = (pixel & 0xff) / 255.0;
194
195   if (colormap && gdk_colormap_get_visual (colormap)->depth == 32)
196     alpha = (pixel >> 24 & 0xff) / 255.0;
197   else
198     alpha = 1.0;
199
200   CGContextSetRGBStrokeColor (context, red, green, blue, 1.0);  
201 }
202
203 gboolean
204 gdk_color_change (GdkColormap *colormap,
205                   GdkColor    *color)
206 {
207   /* FIXME: Implement */
208   return FALSE;
209 }
210