Documentation ordinal fixes.
[wine/multimedia.git] / graphics / x11drv / oembitmap.c
blob3daf0d1202043f7350a2d853d99ca74bf25732e5
1 /*
2 * X11DRV OEM bitmap objects
4 * Copyright 1994, 1995 Alexandre Julliard
6 */
8 #include "config.h"
10 #include "ts_xlib.h"
11 #include "ts_xutil.h"
13 #ifdef HAVE_LIBXXPM
14 #include "ts_xpm.h"
15 #else /* defined(HAVE_LIBXXPM) */
16 typedef unsigned long Pixel;
17 #endif /* defined(HAVE_LIBXXPM) */
19 #include <stdlib.h>
20 #include <string.h>
22 #include "winbase.h"
23 #include "wingdi.h"
24 #include "winuser.h"
25 #include "wine/winuser16.h"
27 #include "bitmap.h"
28 #include "color.h"
29 #include "cursoricon.h"
30 #include "debugtools.h"
31 #include "gdi.h"
32 #include "heap.h"
33 #include "user.h" /* for TWEAK_WineLook (FIXME) */
34 #include "x11drv.h"
36 /* Include OEM pixmaps */
37 #include "bitmaps/obm_lfarrowi"
38 #include "bitmaps/obm_rgarrowi"
39 #include "bitmaps/obm_dnarrowi"
40 #include "bitmaps/obm_uparrowi"
41 #include "bitmaps/obm_combo"
42 #include "bitmaps/obm_mnarrow"
43 #include "bitmaps/obm_lfarrowd"
44 #include "bitmaps/obm_rgarrowd"
45 #include "bitmaps/obm_dnarrowd"
46 #include "bitmaps/obm_uparrowd"
47 #include "bitmaps/obm_restored"
48 #include "bitmaps/obm_restore"
49 #include "bitmaps/obm_lfarrow"
50 #include "bitmaps/obm_rgarrow"
51 #include "bitmaps/obm_dnarrow"
52 #include "bitmaps/obm_uparrow"
53 #include "bitmaps/obm_old_restore"
54 #include "bitmaps/obm_old_zoom"
55 #include "bitmaps/obm_old_reduce"
56 #include "bitmaps/obm_btncorners"
57 #include "bitmaps/obm_checkboxes"
58 #include "bitmaps/obm_check"
59 #include "bitmaps/obm_btsize"
60 #include "bitmaps/obm_old_lfarrow"
61 #include "bitmaps/obm_old_rgarrow"
62 #include "bitmaps/obm_old_dnarrow"
63 #include "bitmaps/obm_old_uparrow"
64 #include "bitmaps/obm_size"
65 #include "bitmaps/obm_old_close"
66 #include "bitmaps/obm_trtype"
68 #include "bitmaps/obm_zoomd"
69 #include "bitmaps/obm_reduced"
70 #include "bitmaps/obm_zoom"
71 #include "bitmaps/obm_reduce"
72 #include "bitmaps/obm_close"
73 #include "bitmaps/obm_zoomd_95"
74 #include "bitmaps/obm_reduced_95"
75 #include "bitmaps/obm_zoom_95"
76 #include "bitmaps/obm_reduce_95"
77 #include "bitmaps/obm_close_95"
78 #include "bitmaps/obm_closed_95"
79 #include "bitmaps/obm_restore_95"
80 #include "bitmaps/obm_restored_95"
82 DECLARE_DEBUG_CHANNEL(bitmap);
83 DECLARE_DEBUG_CHANNEL(cursor);
84 DECLARE_DEBUG_CHANNEL(x11drv);
87 #define OBM_FIRST OBM_CLOSED /* First OEM bitmap */
88 #define OBM_LAST OBM_OLD_CLOSE /* Last OEM bitmap */
90 static struct
92 char** data; /* Pointer to bitmap data */
93 BOOL color; /* Is it a color bitmap? */
94 } OBM_Pixmaps_Data[OBM_LAST-OBM_FIRST+1] = {
95 { obm_closed_95,TRUE}, /* OBM_CLOSED */
96 { obm_trtype, TRUE }, /* OBM_TRTYPE */
97 { NULL, FALSE }, /* unused */
98 { obm_lfarrowi, TRUE }, /* OBM_LFARROWI */
99 { obm_rgarrowi, TRUE }, /* OBM_RGARROWI */
100 { obm_dnarrowi, TRUE }, /* OBM_DNARROWI */
101 { obm_uparrowi, TRUE }, /* OBM_UPARROWI */
102 { obm_combo, FALSE }, /* OBM_COMBO */
103 { obm_mnarrow, FALSE }, /* OBM_MNARROW */
104 { obm_lfarrowd, TRUE }, /* OBM_LFARROWD */
105 { obm_rgarrowd, TRUE }, /* OBM_RGARROWD */
106 { obm_dnarrowd, TRUE }, /* OBM_DNARROWD */
107 { obm_uparrowd, TRUE }, /* OBM_UPARROWD */
108 { obm_restored, TRUE }, /* OBM_RESTORED */
109 { obm_zoomd, TRUE }, /* OBM_ZOOMD */
110 { obm_reduced, TRUE }, /* OBM_REDUCED */
111 { obm_restore, TRUE }, /* OBM_RESTORE */
112 { obm_zoom, TRUE }, /* OBM_ZOOM */
113 { obm_reduce, TRUE }, /* OBM_REDUCE */
114 { obm_lfarrow, TRUE }, /* OBM_LFARROW */
115 { obm_rgarrow, TRUE }, /* OBM_RGARROW */
116 { obm_dnarrow, TRUE }, /* OBM_DNARROW */
117 { obm_uparrow, TRUE }, /* OBM_UPARROW */
118 { obm_close, TRUE }, /* OBM_CLOSE */
119 { obm_old_restore, FALSE }, /* OBM_OLD_RESTORE */
120 { obm_old_zoom, FALSE }, /* OBM_OLD_ZOOM */
121 { obm_old_reduce, FALSE }, /* OBM_OLD_REDUCE */
122 { obm_btncorners, FALSE }, /* OBM_BTNCORNERS */
123 { obm_checkboxes, FALSE }, /* OBM_CHECKBOXES */
124 { obm_check, FALSE }, /* OBM_CHECK */
125 { obm_btsize, FALSE }, /* OBM_BTSIZE */
126 { obm_old_lfarrow, FALSE }, /* OBM_OLD_LFARROW */
127 { obm_old_rgarrow, FALSE }, /* OBM_OLD_RGARROW */
128 { obm_old_dnarrow, FALSE }, /* OBM_OLD_DNARROW */
129 { obm_old_uparrow, FALSE }, /* OBM_OLD_UPARROW */
130 { obm_size, FALSE }, /* OBM_SIZE */
131 { obm_old_close, FALSE }, /* OBM_OLD_CLOSE */
135 /* All the colors used in the xpm files must be included in this */
136 /* list, to make sure that the loaded bitmaps only use colors from */
137 /* the Windows colormap. Note: the PALETTEINDEX() are not really */
138 /* palette indexes, but system colors that will be converted to */
139 /* indexes later on. */
141 #ifdef HAVE_LIBXXPM
142 static XpmColorSymbol
143 #else /* defined(HAVE_LIBXXPM) */
144 static struct
146 char *name;
147 char *value;
148 Pixel pixel;
150 #endif /* defined(HAVE_LIBXXPM) */
151 OBM_Colors[] =
153 { "black", NULL, (Pixel)RGB(0,0,0) },
154 { "white", NULL, (Pixel)RGB(255,255,255) },
155 { "red", NULL, (Pixel)RGB(255,0,0) },
156 { "green", NULL, (Pixel)RGB(0,255,0) },
157 { "blue", NULL, (Pixel)RGB(0,0,255) },
158 { "yellow", NULL, (Pixel)RGB(255,255,0) },
159 { "cyan", NULL, (Pixel)RGB(0,255,255) },
160 { "dkyellow", NULL, (Pixel)RGB(128,128,0) },
161 { "purple", NULL, (Pixel)RGB(128,0,128) },
162 { "ltgray", NULL, (Pixel)RGB(192,192,192) },
163 { "dkgray", NULL, (Pixel)RGB(128,128,128) },
164 { "button_face", NULL, (Pixel)PALETTEINDEX(COLOR_BTNFACE) },
165 { "button_shadow", NULL, (Pixel)PALETTEINDEX(COLOR_BTNSHADOW) },
166 { "button_highlight", NULL, (Pixel)PALETTEINDEX(COLOR_BTNHIGHLIGHT) },
167 { "button_edge", NULL, (Pixel)PALETTEINDEX(COLOR_BTNHIGHLIGHT) },
168 { "button_text", NULL, (Pixel)PALETTEINDEX(COLOR_BTNTEXT) },
169 { "window_frame", NULL, (Pixel)PALETTEINDEX(COLOR_WINDOWFRAME) }
172 #define NB_COLOR_SYMBOLS (sizeof(OBM_Colors)/sizeof(OBM_Colors[0]))
174 /* These are the symbolic colors for monochrome bitmaps */
175 /* This is needed to make sure that black is always 0 and */
176 /* white always 1, as required by Windows. */
178 #ifdef HAVE_LIBXXPM
179 static XpmColorSymbol OBM_BlackAndWhite[2] =
181 { "black", NULL, 0 },
182 { "white", NULL, 0xffffffff }
184 #endif /* defined(HAVE_LIBXXPM) */
188 /***********************************************************************
189 * OBM_InitColorSymbols
191 static BOOL OBM_InitColorSymbols()
193 static BOOL initialized = FALSE;
194 int i;
196 if (initialized) return TRUE; /* Already initialised */
197 initialized = TRUE;
199 for (i = 0; i < NB_COLOR_SYMBOLS; i++)
201 if (OBM_Colors[i].pixel & 0xff000000) /* PALETTEINDEX */
202 OBM_Colors[i].pixel = X11DRV_PALETTE_ToPhysical( NULL,
203 GetSysColor(OBM_Colors[i].pixel & 0xff));
204 else /* RGB*/
205 OBM_Colors[i].pixel = X11DRV_PALETTE_ToPhysical( NULL, OBM_Colors[i].pixel);
207 return TRUE;
211 /***********************************************************************
212 * OBM_MakeBitmap
214 * Allocate a GDI bitmap.
216 #ifdef HAVE_LIBXXPM
217 static HBITMAP16 OBM_MakeBitmap( WORD width, WORD height,
218 WORD bpp, Pixmap pixmap )
220 HBITMAP hbitmap;
221 BITMAPOBJ * bmpObjPtr;
223 if (!pixmap) return 0;
225 if (!(bmpObjPtr = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC, &hbitmap ))) return 0;
226 bmpObjPtr->size.cx = width;
227 bmpObjPtr->size.cy = height;
228 bmpObjPtr->bitmap.bmType = 0;
229 bmpObjPtr->bitmap.bmWidth = width;
230 bmpObjPtr->bitmap.bmHeight = height;
231 bmpObjPtr->bitmap.bmWidthBytes = BITMAP_GetWidthBytes( width, bpp );
232 bmpObjPtr->bitmap.bmPlanes = 1;
233 bmpObjPtr->bitmap.bmBitsPixel = bpp;
234 bmpObjPtr->bitmap.bmBits = NULL;
235 bmpObjPtr->dib = NULL;
237 bmpObjPtr->funcs = &X11DRV_DC_Funcs;
238 bmpObjPtr->physBitmap = (void *)pixmap;
240 GDI_ReleaseObj( hbitmap );
241 return hbitmap;
243 #endif /* defined(HAVE_LIBXXPM) */
246 /***********************************************************************
247 * OBM_CreateBitmaps
249 * Create the 2 bitmaps from XPM data.
251 static BOOL OBM_CreateBitmaps( char **data, BOOL color,
252 HBITMAP16 *bitmap, HBITMAP16 *mask, POINT *hotspot )
254 #ifdef HAVE_LIBXXPM
255 XpmAttributes *attrs;
256 Pixmap pixmap, pixmask;
257 int err;
259 attrs = (XpmAttributes *)HeapAlloc( GetProcessHeap(), 0, XpmAttributesSize() );
260 if (attrs == NULL) return FALSE;
261 attrs->valuemask = XpmColormap | XpmDepth | XpmColorSymbols | XpmHotspot;
262 attrs->colormap = X11DRV_PALETTE_PaletteXColormap;
263 attrs->depth = color ? X11DRV_GetDepth() : 1;
264 attrs->colorsymbols = (attrs->depth > 1) ? OBM_Colors : OBM_BlackAndWhite;
265 attrs->numsymbols = (attrs->depth > 1) ? NB_COLOR_SYMBOLS : 2;
267 err = TSXpmCreatePixmapFromData( display, X11DRV_GetXRootWindow(), data,
268 &pixmap, &pixmask, attrs );
269 if (err != XpmSuccess)
271 HeapFree( GetProcessHeap(), 0, attrs );
272 return FALSE;
275 if (hotspot)
277 hotspot->x = attrs->x_hotspot;
278 hotspot->y = attrs->y_hotspot;
281 if (bitmap)
282 *bitmap = OBM_MakeBitmap( attrs->width, attrs->height,
283 attrs->depth, pixmap );
285 if (mask)
286 *mask = OBM_MakeBitmap( attrs->width, attrs->height,
287 1, pixmask );
289 HeapFree( GetProcessHeap(), 0, attrs );
291 if (pixmap && (!bitmap || !*bitmap)) TSXFreePixmap( display, pixmap );
292 if (pixmask && (!mask || !*mask)) TSXFreePixmap( display, pixmask );
294 if (bitmap && !*bitmap)
296 if (mask && *mask) DeleteObject( *mask );
297 return FALSE;
299 return TRUE;
300 #else /* defined(HAVE_LIBXXPM) */
301 FIXME_(x11drv)(
302 "Xpm support not in the binary, "
303 "please install the Xpm and Xpm-devel packages and recompile\n"
305 return FALSE;
306 #endif /* defined(HAVE_LIBXXPM) */
310 /***********************************************************************
311 * OBM_LoadBitmap
313 static HBITMAP16 OBM_LoadBitmap( WORD id )
315 HBITMAP16 bitmap;
317 if ((id < OBM_FIRST) || (id > OBM_LAST)) return 0;
318 id -= OBM_FIRST;
319 if (!OBM_Pixmaps_Data[id].data) return 0;
321 if (!OBM_InitColorSymbols()) return 0;
323 if (!OBM_CreateBitmaps( OBM_Pixmaps_Data[id].data, OBM_Pixmaps_Data[id].color,
324 &bitmap, NULL, NULL ))
326 WARN_(bitmap)("Error creating OEM bitmap %d\n", OBM_FIRST+id );
327 return 0;
329 return bitmap;
333 /***********************************************************************
334 * X11DRV_LoadOEMResource (X11DRV.@)
337 HANDLE X11DRV_LoadOEMResource(WORD resid, WORD type)
339 switch(type) {
340 case OEM_BITMAP:
341 return OBM_LoadBitmap(resid);
343 default:
344 ERR_(x11drv)("Unknown type\n");
346 return 0;
350 /***********************************************************************
351 * X11DRV_OBM_Init
353 * Initializes the OBM_Pixmaps_Data and OBM_Icons_Data struct
355 BOOL X11DRV_OBM_Init(void)
357 if (TWEAK_WineLook == WIN31_LOOK) {
358 OBM_Pixmaps_Data[OBM_ZOOMD - OBM_FIRST].data = obm_zoomd;
359 OBM_Pixmaps_Data[OBM_REDUCED - OBM_FIRST].data = obm_reduced;
360 OBM_Pixmaps_Data[OBM_ZOOM - OBM_FIRST].data = obm_zoom;
361 OBM_Pixmaps_Data[OBM_REDUCE - OBM_FIRST].data = obm_reduce;
362 OBM_Pixmaps_Data[OBM_CLOSE - OBM_FIRST].data = obm_close;
363 OBM_Pixmaps_Data[OBM_RESTORE - OBM_FIRST].data = obm_restore;
364 OBM_Pixmaps_Data[OBM_RESTORED - OBM_FIRST].data = obm_restored;
366 else {
367 OBM_Pixmaps_Data[OBM_ZOOMD - OBM_FIRST].data = obm_zoomd_95;
368 OBM_Pixmaps_Data[OBM_REDUCED - OBM_FIRST].data = obm_reduced_95;
369 OBM_Pixmaps_Data[OBM_ZOOM - OBM_FIRST].data = obm_zoom_95;
370 OBM_Pixmaps_Data[OBM_REDUCE - OBM_FIRST].data = obm_reduce_95;
371 OBM_Pixmaps_Data[OBM_CLOSE - OBM_FIRST].data = obm_close_95;
372 OBM_Pixmaps_Data[OBM_RESTORE - OBM_FIRST].data = obm_restore_95;
373 OBM_Pixmaps_Data[OBM_RESTORED - OBM_FIRST].data = obm_restored_95;
376 return 1;