4 * Copyright 1993 Alexandre Julliard
7 static char Copyright
[] = "Copyright Alexandre Julliard, 1993";
14 extern Display
* XT_display
;
15 extern Screen
* XT_screen
;
19 * We try to use a private color map if possible, because Windows programs
20 * assume that palette(0) == Black and palette(max-1) == White.
22 #define USE_PRIVATE_MAP
24 Colormap COLOR_WinColormap
= 0;
29 static const char * SysColors
[] =
31 /* Low pixel values (0..7) */
33 "black", "red4", "green4", "yellow4",
34 "blue4", "magenta4", "cyan4", "gray50",
36 /* High pixel values (max-7..max) */
38 "gray75", "red", "green", "yellow",
39 "blue", "magenta", "cyan", "white"
42 #define NB_SYS_COLORS (sizeof(SysColors) / sizeof(SysColors[0]))
45 /***********************************************************************
46 * COLOR_FillDefaultMap
48 * Try to allocate colors from default screen map (used when we
49 * don't want to or can't use a private map).
51 static int COLOR_FillDefaultMap()
56 for (i
= 0; i
< NB_SYS_COLORS
; i
++)
58 if (XParseColor( XT_display
, DefaultColormapOfScreen( XT_screen
),
59 SysColors
[i
], &color
))
61 if (XAllocColor( XT_display
, DefaultColormapOfScreen( XT_screen
),
70 /***********************************************************************
73 * Fill the private colormap.
75 #ifdef USE_PRIVATE_MAP
77 static BOOL
COLOR_BuildMap( Colormap map
, int depth
, int size
)
82 /* Fill the whole map with a range of colors */
84 if ((1 << depth
) > NB_SYS_COLORS
)
86 int red_incr
, green_incr
, blue_incr
;
89 blue_incr
= 0x10000 >> (depth
/ 3);
90 red_incr
= 0x10000 >> ((depth
+ 1) / 3);
91 green_incr
= 0x10000 >> ((depth
+ 2) / 3);
93 for (i
= 0, r
= red_incr
- 1; r
< 0x10000; r
+= red_incr
)
94 for (g
= green_incr
- 1; g
< 0x10000; g
+= green_incr
)
95 for (b
= blue_incr
- 1; b
< 0x10000; b
+= blue_incr
)
102 XStoreColor( XT_display
, map
, &color
);
106 /* Store the system palette colors */
108 for (i
= 0; i
< NB_SYS_COLORS
; i
++)
110 if (!XParseColor( XT_display
, map
, SysColors
[i
], &color
))
111 color
.red
= color
.green
= color
.blue
= color
.flags
= 0;
112 if (i
< NB_SYS_COLORS
/2) color
.pixel
= i
;
113 else color
.pixel
= (1 << depth
) - NB_SYS_COLORS
+ i
;
114 if (color
.pixel
< size
) XStoreColor( XT_display
, map
, &color
);
118 #endif /* USE_PRIVATE_MAP */
120 /***********************************************************************
125 Visual
* visual
= DefaultVisual( XT_display
, DefaultScreen(XT_display
) );
127 switch(visual
->class)
133 #ifdef USE_PRIVATE_MAP
134 COLOR_WinColormap
= XCreateColormap( XT_display
,
135 DefaultRootWindow(XT_display
),
137 if (COLOR_WinColormap
)
138 COLOR_BuildMap(COLOR_WinColormap
,
139 DefaultDepth(XT_display
, DefaultScreen(XT_display
)),
140 visual
->map_entries
);
141 else COLOR_FillDefaultMap();
143 #endif /* USE_PRIVATE_MAP */
148 COLOR_FillDefaultMap();
149 COLOR_WinColormap
= DefaultColormapOfScreen( XT_screen
);