1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
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.
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/.
29 #include "gdkvisual.h"
30 #include "gdkprivate-win32.h"
31 //#include "gdkinternals.h"
35 static void gdk_visual_decompose_mask (gulong mask,
39 static GdkVisualPrivate *system_visual = NULL;
41 static gint available_depths[1];
43 static GdkVisualType available_types[1];
46 gdk_visual_finalize (GObject *object)
48 g_error ("A GdkVisual object was finalized. This should not happen");
52 gdk_visual_class_init (GObjectClass *class)
54 class->finalize = gdk_visual_finalize;
59 gdk_visual_get_type (void)
61 static GType object_type = 0;
65 static const GTypeInfo object_info =
67 sizeof (GdkVisualClass),
69 (GBaseFinalizeFunc) NULL,
70 (GClassInitFunc) gdk_visual_class_init,
71 NULL, /* class_finalize */
72 NULL, /* class_data */
75 (GInstanceInitFunc) NULL,
78 object_type = g_type_register_static (G_TYPE_OBJECT,
87 gdk_visual_init (void)
100 int rastercaps, numcolors, sizepalette, bitspixel;
102 system_visual = g_new (GdkVisualPrivate, 1);
104 bitspixel = GetDeviceCaps (gdk_display_hdc, BITSPIXEL);
105 rastercaps = GetDeviceCaps (gdk_display_hdc, RASTERCAPS);
106 system_visual->xvisual = g_new (Visual, 1);
107 system_visual->xvisual->visualid = 0;
108 system_visual->xvisual->bitspixel = bitspixel;
110 if (rastercaps & RC_PALETTE)
112 if (!getenv ("GDK_WIN32_ENABLE_BROKEN_PSEUDOCOLOR_VISUAL"))
113 g_error ("Palettized display (%d-colour) mode not supported on Windows.",
114 GetDeviceCaps (gdk_display_hdc, SIZEPALETTE));
115 system_visual->visual.type = GDK_VISUAL_PSEUDO_COLOR;
116 numcolors = GetDeviceCaps (gdk_display_hdc, NUMCOLORS);
117 sizepalette = GetDeviceCaps (gdk_display_hdc, SIZEPALETTE);
118 system_visual->xvisual->map_entries = sizepalette;
120 else if (bitspixel == 1)
122 system_visual->visual.type = GDK_VISUAL_STATIC_GRAY;
123 system_visual->xvisual->map_entries = 2;
125 else if (bitspixel == 4)
127 system_visual->visual.type = GDK_VISUAL_STATIC_COLOR;
128 system_visual->xvisual->map_entries = 16;
130 else if (bitspixel == 8)
132 system_visual->visual.type = GDK_VISUAL_STATIC_COLOR;
133 system_visual->xvisual->map_entries = 256;
135 else if (bitspixel == 16)
137 system_visual->visual.type = GDK_VISUAL_TRUE_COLOR;
139 /* This code by Mike Enright,
140 * see http://www.users.cts.com/sd/m/menright/display.html
142 memset (&bmi, 0, sizeof (bmi));
143 bmi.bi.biSize = sizeof (bmi.bi);
145 hbm = CreateCompatibleBitmap (gdk_display_hdc, 1, 1);
146 GetDIBits (gdk_display_hdc, hbm, 0, 1, NULL,
147 (BITMAPINFO *) &bmi, DIB_RGB_COLORS);
148 GetDIBits (gdk_display_hdc, hbm, 0, 1, NULL,
149 (BITMAPINFO *) &bmi, DIB_RGB_COLORS);
152 if (bmi.bi.biCompression != BI_BITFIELDS)
154 /* Either BI_RGB or BI_RLE_something
155 * .... or perhaps (!!) something else.
156 * Theoretically biCompression might be
157 * mmioFourCC('c','v','i','d') but I doubt it.
159 if (bmi.bi.biCompression == BI_RGB)
163 system_visual->visual.red_mask = 0x00007C00;
164 system_visual->visual.green_mask = 0x000003E0;
165 system_visual->visual.blue_mask = 0x0000001F;
169 g_assert_not_reached ();
175 bmi.u.fields[0] | bmi.u.fields[1] | bmi.u.fields[2];
184 system_visual->visual.red_mask = bmi.u.fields[0];
185 system_visual->visual.green_mask = bmi.u.fields[1];
186 system_visual->visual.blue_mask = bmi.u.fields[2];
189 /* Old, incorrect (but still working) code. */
191 system_visual->visual.red_mask = 0x0000F800;
192 system_visual->visual.green_mask = 0x000007E0;
193 system_visual->visual.blue_mask = 0x0000001F;
195 system_visual->visual.red_mask = 0x00007C00;
196 system_visual->visual.green_mask = 0x000003E0;
197 system_visual->visual.blue_mask = 0x0000001F;
201 else if (bitspixel == 24 || bitspixel == 32)
204 system_visual->visual.type = GDK_VISUAL_TRUE_COLOR;
205 system_visual->visual.red_mask = 0x00FF0000;
206 system_visual->visual.green_mask = 0x0000FF00;
207 system_visual->visual.blue_mask = 0x000000FF;
210 g_error ("gdk_visual_init: unsupported BITSPIXEL: %d\n", bitspixel);
212 system_visual->visual.depth = bitspixel;
213 system_visual->visual.byte_order = GDK_LSB_FIRST;
214 system_visual->visual.bits_per_rgb = 42; /* Not used? */
216 if ((system_visual->visual.type == GDK_VISUAL_TRUE_COLOR) ||
217 (system_visual->visual.type == GDK_VISUAL_DIRECT_COLOR))
219 gdk_visual_decompose_mask (system_visual->visual.red_mask,
220 &system_visual->visual.red_shift,
221 &system_visual->visual.red_prec);
223 gdk_visual_decompose_mask (system_visual->visual.green_mask,
224 &system_visual->visual.green_shift,
225 &system_visual->visual.green_prec);
227 gdk_visual_decompose_mask (system_visual->visual.blue_mask,
228 &system_visual->visual.blue_shift,
229 &system_visual->visual.blue_prec);
230 system_visual->xvisual->map_entries =
231 1 << (MAX (system_visual->visual.red_prec,
232 MAX (system_visual->visual.green_prec,
233 system_visual->visual.blue_prec)));
237 system_visual->visual.red_mask = 0;
238 system_visual->visual.red_shift = 0;
239 system_visual->visual.red_prec = 0;
241 system_visual->visual.green_mask = 0;
242 system_visual->visual.green_shift = 0;
243 system_visual->visual.green_prec = 0;
245 system_visual->visual.blue_mask = 0;
246 system_visual->visual.blue_shift = 0;
247 system_visual->visual.blue_prec = 0;
249 system_visual->visual.colormap_size = system_visual->xvisual->map_entries;
251 available_depths[0] = system_visual->visual.depth;
252 available_types[0] = system_visual->visual.type;
256 gdk_visual_get_best_depth (void)
258 return available_depths[0];
262 gdk_visual_get_best_type (void)
264 return available_types[0];
268 gdk_visual_get_system (void)
270 return ((GdkVisual*) system_visual);
274 gdk_visual_get_best (void)
276 return ((GdkVisual*) system_visual);
280 gdk_visual_get_best_with_depth (gint depth)
282 if (depth == system_visual->visual.depth)
283 return (GdkVisual*) system_visual;
289 gdk_visual_get_best_with_type (GdkVisualType visual_type)
291 if (visual_type == system_visual->visual.type)
292 return (GdkVisual*) system_visual;
298 gdk_visual_get_best_with_both (gint depth,
299 GdkVisualType visual_type)
301 if ((depth == system_visual->visual.depth) &&
302 (visual_type == system_visual->visual.type))
303 return (GdkVisual*) system_visual;
309 gdk_query_depths (gint **depths,
313 *depths = available_depths;
317 gdk_query_visual_types (GdkVisualType **visual_types,
321 *visual_types = available_types;
325 gdk_list_visuals (void)
327 return g_list_append (NULL, (gpointer) system_visual);
331 gdk_visual_lookup (Visual *xvisual)
333 if (system_visual->xvisual == xvisual)
334 return (GdkVisual *) system_visual;
340 gdk_visual_decompose_mask (gulong mask,
347 while (!(mask & 0x1))