Release 980215
[wine/multimedia.git] / objects / oembitmap.c
blob700e9fece544058b7287eb4518512ab572a09792
1 /*
2 * GDI OEM bitmap objects
4 * Copyright 1994, 1995 Alexandre Julliard
6 */
8 #include <stdlib.h>
9 #include <string.h>
10 #include "ts_xlib.h"
11 #include "ts_xutil.h"
12 #include "ts_xpm.h"
13 #include "gdi.h"
14 #include "bitmap.h"
15 #include "callback.h"
16 #include "color.h"
17 #include "cursoricon.h"
18 #include "heap.h"
19 #include "stddebug.h"
20 #include "tweak.h"
21 #include "debug.h"
23 /* Include OEM pixmaps */
24 #include "bitmaps/obm_cdrom"
25 #include "bitmaps/obm_harddisk"
26 #include "bitmaps/obm_drive"
27 #include "bitmaps/obm_folder2"
28 #include "bitmaps/obm_folder"
29 #include "bitmaps/obm_lfarrowi"
30 #include "bitmaps/obm_rgarrowi"
31 #include "bitmaps/obm_dnarrowi"
32 #include "bitmaps/obm_uparrowi"
33 #include "bitmaps/obm_combo"
34 #include "bitmaps/obm_mnarrow"
35 #include "bitmaps/obm_lfarrowd"
36 #include "bitmaps/obm_rgarrowd"
37 #include "bitmaps/obm_dnarrowd"
38 #include "bitmaps/obm_uparrowd"
39 #include "bitmaps/obm_restored"
40 #include "bitmaps/obm_restore"
41 #include "bitmaps/obm_lfarrow"
42 #include "bitmaps/obm_rgarrow"
43 #include "bitmaps/obm_dnarrow"
44 #include "bitmaps/obm_uparrow"
45 #include "bitmaps/obm_old_restore"
46 #include "bitmaps/obm_old_zoom"
47 #include "bitmaps/obm_old_reduce"
48 #include "bitmaps/obm_btncorners"
49 #include "bitmaps/obm_checkboxes"
50 #include "bitmaps/obm_check"
51 #include "bitmaps/obm_btsize"
52 #include "bitmaps/obm_old_lfarrow"
53 #include "bitmaps/obm_old_rgarrow"
54 #include "bitmaps/obm_old_dnarrow"
55 #include "bitmaps/obm_old_uparrow"
56 #include "bitmaps/obm_size"
57 #include "bitmaps/obm_old_close"
58 #include "bitmaps/obm_trtype"
59 #include "bitmaps/obm_radiocheck"
61 #include "bitmaps/obm_zoomd"
62 #include "bitmaps/obm_reduced"
63 #include "bitmaps/obm_zoom"
64 #include "bitmaps/obm_reduce"
65 #include "bitmaps/obm_close"
66 #include "bitmaps/obm_zoomd_95"
67 #include "bitmaps/obm_reduced_95"
68 #include "bitmaps/obm_zoom_95"
69 #include "bitmaps/obm_reduce_95"
70 #include "bitmaps/obm_close_95"
71 #include "bitmaps/obm_closed_95"
74 #define OBM_FIRST OBM_RADIOCHECK /* First OEM bitmap */
75 #define OBM_LAST OBM_OLD_CLOSE /* Last OEM bitmap */
77 static struct
79 char** data; /* Pointer to bitmap data */
80 BOOL32 color; /* Is it a color bitmap? */
81 } OBM_Pixmaps_Data[OBM_LAST-OBM_FIRST+1] = {
82 { obm_radiocheck, FALSE }, /* OBM_RADIOCHECK */
83 { obm_trtype, TRUE }, /* OBM_TRTYPE */
84 { obm_cdrom, TRUE }, /* OBM_CDROM */
85 { obm_harddisk, TRUE }, /* OBM_HARDDISK */
86 { obm_drive, TRUE }, /* OBM_DRIVE */
87 { obm_folder2, TRUE }, /* OBM_FOLDER2 */
88 { obm_folder, TRUE }, /* OBM_FOLDER */
89 { obm_lfarrowi, TRUE }, /* OBM_LFARROWI */
90 { obm_rgarrowi, TRUE }, /* OBM_RGARROWI */
91 { obm_dnarrowi, TRUE }, /* OBM_DNARROWI */
92 { obm_uparrowi, TRUE }, /* OBM_UPARROWI */
93 { obm_combo, FALSE }, /* OBM_COMBO */
94 { obm_mnarrow, FALSE }, /* OBM_MNARROW */
95 { obm_lfarrowd, TRUE }, /* OBM_LFARROWD */
96 { obm_rgarrowd, TRUE }, /* OBM_RGARROWD */
97 { obm_dnarrowd, TRUE }, /* OBM_DNARROWD */
98 { obm_uparrowd, TRUE }, /* OBM_UPARROWD */
99 { obm_restored, TRUE }, /* OBM_RESTORED */
100 { obm_zoomd, TRUE }, /* OBM_ZOOMD */
101 { obm_reduced, TRUE }, /* OBM_REDUCED */
102 { obm_restore, TRUE }, /* OBM_RESTORE */
103 { obm_zoom, TRUE }, /* OBM_ZOOM */
104 { obm_reduce, TRUE }, /* OBM_REDUCE */
105 { obm_lfarrow, TRUE }, /* OBM_LFARROW */
106 { obm_rgarrow, TRUE }, /* OBM_RGARROW */
107 { obm_dnarrow, TRUE }, /* OBM_DNARROW */
108 { obm_uparrow, TRUE }, /* OBM_UPARROW */
109 { obm_close, TRUE }, /* OBM_CLOSE */
110 { obm_old_restore, FALSE }, /* OBM_OLD_RESTORE */
111 { obm_old_zoom, FALSE }, /* OBM_OLD_ZOOM */
112 { obm_old_reduce, FALSE }, /* OBM_OLD_REDUCE */
113 { obm_btncorners, FALSE }, /* OBM_BTNCORNERS */
114 { obm_checkboxes, FALSE }, /* OBM_CHECKBOXES */
115 { obm_check, FALSE }, /* OBM_CHECK */
116 { obm_btsize, FALSE }, /* OBM_BTSIZE */
117 { obm_old_lfarrow, FALSE }, /* OBM_OLD_LFARROW */
118 { obm_old_rgarrow, FALSE }, /* OBM_OLD_RGARROW */
119 { obm_old_dnarrow, FALSE }, /* OBM_OLD_DNARROW */
120 { obm_old_uparrow, FALSE }, /* OBM_OLD_UPARROW */
121 { obm_size, FALSE }, /* OBM_SIZE */
122 { obm_old_close, FALSE }, /* OBM_OLD_CLOSE */
126 /* Include OEM icons */
127 #include "bitmaps/oic_sample"
128 #include "bitmaps/oic_hand"
129 #include "bitmaps/oic_ques"
130 #include "bitmaps/oic_bang"
131 #include "bitmaps/oic_note"
132 #include "bitmaps/oic_portrait"
133 #include "bitmaps/oic_landscape"
134 #include "bitmaps/oic_wineicon"
136 #define OIC_FIRST OIC_SAMPLE /* First OEM icon */
137 #define OIC_LAST OIC_WINEICON /* Last OEM icon */
139 static char ** const OBM_Icons_Data[OIC_LAST-OIC_FIRST+1] =
141 oic_sample, /* OIC_SAMPLE */
142 oic_hand, /* OIC_HAND */
143 oic_ques, /* OIC_QUES */
144 oic_bang, /* OIC_BANG */
145 oic_note, /* OIC_NOTE */
146 oic_portrait, /* OIC_PORTRAIT */
147 oic_landscape, /* OIC_LANDSCAPE */
148 oic_wineicon /* OIC_WINEICON */
152 /* Include OEM cursors */
153 #include "bitmaps/ocr_normal"
154 #include "bitmaps/ocr_ibeam"
155 #include "bitmaps/ocr_wait"
156 #include "bitmaps/ocr_cross"
157 #include "bitmaps/ocr_up"
158 #include "bitmaps/ocr_size"
159 #include "bitmaps/ocr_icon"
160 #include "bitmaps/ocr_sizenwse"
161 #include "bitmaps/ocr_sizenesw"
162 #include "bitmaps/ocr_sizewe"
163 #include "bitmaps/ocr_sizens"
164 #include "bitmaps/ocr_bummer"
165 #include "bitmaps/ocr_dragobject"
166 /*#include "bitmaps/ocr_sizeall"*/
167 /*#include "bitmaps/ocr_icocur"*/
169 /* Cursor are not all contiguous (go figure...) */
170 #define OCR_FIRST0 OCR_BUMMER
171 #define OCR_LAST0 OCR_DRAGOBJECT
172 #define OCR_BASE0 0
174 #define OCR_FIRST1 OCR_NORMAL
175 #define OCR_LAST1 OCR_UP
176 #define OCR_BASE1 (OCR_BASE0 + OCR_LAST0 - OCR_FIRST0 + 1)
178 #define OCR_FIRST2 OCR_SIZE
179 #define OCR_LAST2 OCR_SIZENS
180 #define OCR_BASE2 (OCR_BASE1 + OCR_LAST1 - OCR_FIRST1 + 1)
182 #define NB_CURSORS (OCR_BASE2 + OCR_LAST2 - OCR_FIRST2 + 1)
183 static char **OBM_Cursors_Data[NB_CURSORS] =
185 ocr_bummer, /* OCR_BUMMER */
186 ocr_dragobject,/* OCR_DRAGOBJECT */
187 ocr_normal, /* OCR_NORMAL */
188 ocr_ibeam, /* OCR_IBEAM */
189 ocr_wait, /* OCR_WAIT */
190 ocr_cross, /* OCR_CROSS */
191 ocr_up, /* OCR_UP */
192 ocr_size, /* OCR_SIZE */
193 ocr_icon, /* OCR_ICON */
194 ocr_sizenwse, /* OCR_SIZENWSE */
195 ocr_sizenesw, /* OCR_SIZENESW */
196 ocr_sizewe, /* OCR_SIZEWE */
197 ocr_sizens /* OCR_SIZENS */
198 #if 0
199 ocr_sizeall, /* OCR_SIZEALL */
200 ocr_icocur /* OCR_ICOCUR */
201 #endif
204 static HGLOBAL16 OBM_Cursors[NB_CURSORS];
207 /* All the colors used in the xpm files must be included in this */
208 /* list, to make sure that the loaded bitmaps only use colors from */
209 /* the Windows colormap. Note: the PALETTEINDEX() are not really */
210 /* palette indexes, but system colors that will be converted to */
211 /* indexes later on. */
213 #if 0
214 static const struct
216 char * name;
217 COLORREF color;
218 } OBM_SymbolicColors[] =
219 #endif
220 static XpmColorSymbol OBM_Colors[] =
222 { "black", NULL, (Pixel)RGB(0,0,0) },
223 { "white", NULL, (Pixel)RGB(255,255,255) },
224 { "red", NULL, (Pixel)RGB(255,0,0) },
225 { "green", NULL, (Pixel)RGB(0,255,0) },
226 { "blue", NULL, (Pixel)RGB(0,0,255) },
227 { "yellow", NULL, (Pixel)RGB(255,255,0) },
228 { "cyan", NULL, (Pixel)RGB(0,255,255) },
229 { "dkyellow", NULL, (Pixel)RGB(128,128,0) },
230 { "purple", NULL, (Pixel)RGB(128,0,128) },
231 { "ltgray", NULL, (Pixel)RGB(192,192,192) },
232 { "dkgray", NULL, (Pixel)RGB(128,128,128) },
233 { "foldercol", NULL, (Pixel)RGB(0,191,191) },
234 { "button_face", NULL, (Pixel)PALETTEINDEX(COLOR_BTNFACE) },
235 { "button_shadow", NULL, (Pixel)PALETTEINDEX(COLOR_BTNSHADOW) },
236 { "button_highlight", NULL, (Pixel)PALETTEINDEX(COLOR_BTNHIGHLIGHT) },
237 { "button_edge", NULL, (Pixel)PALETTEINDEX(COLOR_BTNHIGHLIGHT) },
238 { "button_text", NULL, (Pixel)PALETTEINDEX(COLOR_BTNTEXT) },
239 { "window_frame", NULL, (Pixel)PALETTEINDEX(COLOR_WINDOWFRAME) }
242 #define NB_COLOR_SYMBOLS (sizeof(OBM_Colors)/sizeof(OBM_Colors[0]))
244 /* These are the symbolic colors for monochrome bitmaps */
245 /* This is needed to make sure that black is always 0 and */
246 /* white always 1, as required by Windows. */
248 static XpmColorSymbol OBM_BlackAndWhite[2] =
250 { "black", NULL, 0 },
251 { "white", NULL, 0xffffffff }
254 /* This structure holds the arguments for OBM_CreateBitmaps() */
255 typedef struct
257 char **data; /* In: bitmap data */
258 BOOL32 color; /* In: color or monochrome */
259 BOOL32 need_mask; /* In: do we need a mask? */
260 HBITMAP16 bitmap; /* Out: resulting bitmap */
261 HBITMAP16 mask; /* Out: resulting mask (if needed) */
262 POINT32 hotspot; /* Out: bitmap hotspot */
263 } OBM_BITMAP_DESCR;
266 /***********************************************************************
267 * OBM_InitColorSymbols
269 static BOOL32 OBM_InitColorSymbols()
271 static BOOL32 initialized = FALSE;
272 int i;
274 if (initialized) return TRUE; /* Already initialised */
275 initialized = TRUE;
277 for (i = 0; i < NB_COLOR_SYMBOLS; i++)
279 if (OBM_Colors[i].pixel & 0xff000000) /* PALETTEINDEX */
280 OBM_Colors[i].pixel = COLOR_ToPhysical( NULL,
281 GetSysColor32(OBM_Colors[i].pixel & 0xff));
282 else /* RGB*/
283 OBM_Colors[i].pixel = COLOR_ToPhysical( NULL, OBM_Colors[i].pixel);
285 return TRUE;
289 /***********************************************************************
290 * OBM_MakeBitmap
292 * Allocate a GDI bitmap.
294 static HBITMAP16 OBM_MakeBitmap( WORD width, WORD height,
295 WORD bpp, Pixmap pixmap )
297 HBITMAP16 hbitmap;
298 BITMAPOBJ * bmpObjPtr;
300 if (!pixmap) return 0;
302 hbitmap = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC );
303 if (!hbitmap) return 0;
305 bmpObjPtr = (BITMAPOBJ *) GDI_HEAP_LOCK( hbitmap );
306 bmpObjPtr->size.cx = width;
307 bmpObjPtr->size.cy = height;
308 bmpObjPtr->pixmap = pixmap;
309 bmpObjPtr->bitmap.bmType = 0;
310 bmpObjPtr->bitmap.bmWidth = width;
311 bmpObjPtr->bitmap.bmHeight = height;
312 bmpObjPtr->bitmap.bmWidthBytes = BITMAP_WIDTH_BYTES( width, bpp );
313 bmpObjPtr->bitmap.bmPlanes = 1;
314 bmpObjPtr->bitmap.bmBitsPixel = bpp;
315 bmpObjPtr->bitmap.bmBits = NULL;
316 GDI_HEAP_UNLOCK( hbitmap );
317 return hbitmap;
321 /***********************************************************************
322 * OBM_CreateBitmaps
324 * Create the 2 bitmaps from XPM data.
326 * The Xlib critical section must be entered before calling this function.
328 static BOOL32 OBM_CreateBitmaps( OBM_BITMAP_DESCR *descr )
330 Pixmap pixmap, pixmask;
331 XpmAttributes *attrs;
332 int err;
334 attrs = (XpmAttributes *)HEAP_xalloc( GetProcessHeap(), 0,
335 XpmAttributesSize() );
336 attrs->valuemask = XpmColormap | XpmDepth | XpmColorSymbols |XpmHotspot;
337 attrs->colormap = COLOR_GetColormap();
338 attrs->depth = descr->color ? screenDepth : 1;
339 attrs->colorsymbols = (attrs->depth > 1) ? OBM_Colors : OBM_BlackAndWhite;
340 attrs->numsymbols = (attrs->depth > 1) ? NB_COLOR_SYMBOLS : 2;
342 err = XpmCreatePixmapFromData( display, rootWindow, descr->data,
343 &pixmap, &pixmask, attrs );
345 if (err != XpmSuccess)
347 HeapFree( GetProcessHeap(), 0, attrs );
348 return FALSE;
350 descr->hotspot.x = attrs->x_hotspot;
351 descr->hotspot.y = attrs->y_hotspot;
352 descr->bitmap = OBM_MakeBitmap( attrs->width, attrs->height,
353 attrs->depth, pixmap );
354 if (descr->need_mask)
355 descr->mask = OBM_MakeBitmap( attrs->width, attrs->height,
356 1, pixmask );
357 HeapFree( GetProcessHeap(), 0, attrs );
358 if (!descr->bitmap)
360 if (pixmap) XFreePixmap( display, pixmap );
361 if (pixmask) XFreePixmap( display, pixmask );
362 if (descr->bitmap) GDI_FreeObject( descr->bitmap );
363 if (descr->need_mask && descr->mask) GDI_FreeObject( descr->mask );
364 return FALSE;
366 else return TRUE;
370 /***********************************************************************
371 * OBM_LoadBitmap
373 HBITMAP16 OBM_LoadBitmap( WORD id )
375 OBM_BITMAP_DESCR descr;
377 if ((id < OBM_FIRST) || (id > OBM_LAST)) return 0;
378 id -= OBM_FIRST;
380 if (!OBM_InitColorSymbols()) return 0;
382 descr.data = OBM_Pixmaps_Data[id].data;
383 descr.color = OBM_Pixmaps_Data[id].color;
384 descr.need_mask = FALSE;
386 EnterCriticalSection( &X11DRV_CritSection );
387 if (!CALL_LARGE_STACK( OBM_CreateBitmaps, &descr ))
389 LeaveCriticalSection( &X11DRV_CritSection );
390 fprintf( stderr, "Error creating OEM bitmap %d\n", OBM_FIRST+id );
391 return 0;
393 LeaveCriticalSection( &X11DRV_CritSection );
394 return descr.bitmap;
398 /***********************************************************************
399 * OBM_LoadCursorIcon
401 HGLOBAL16 OBM_LoadCursorIcon( WORD id, BOOL32 fCursor )
403 OBM_BITMAP_DESCR descr;
404 HGLOBAL16 handle;
405 CURSORICONINFO *pInfo;
406 BITMAPOBJ *bmpXor, *bmpAnd;
407 int sizeXor, sizeAnd;
409 if (fCursor)
411 if ((id >= OCR_FIRST1) && (id <= OCR_LAST1))
412 id = OCR_BASE1 + id - OCR_FIRST1;
413 else if ((id >= OCR_FIRST2) && (id <= OCR_LAST2))
414 id = OCR_BASE2 + id - OCR_FIRST2;
415 else if ((id >= OCR_FIRST0) && (id <= OCR_LAST0))
416 id = OCR_BASE0 + id - OCR_FIRST0;
417 else return 0;
418 if (OBM_Cursors[id]) return OBM_Cursors[id];
420 else
422 if ((id < OIC_FIRST) || (id > OIC_LAST)) return 0;
423 id -= OIC_FIRST;
426 if (!OBM_InitColorSymbols()) return 0;
428 descr.data = fCursor ? OBM_Cursors_Data[id] : OBM_Icons_Data[id];
429 descr.color = !fCursor;
430 descr.need_mask = TRUE;
432 EnterCriticalSection( &X11DRV_CritSection );
433 if (!CALL_LARGE_STACK( OBM_CreateBitmaps, &descr ))
435 LeaveCriticalSection( &X11DRV_CritSection );
436 fprintf( stderr, "Error creating OEM cursor/icon %d\n", id );
437 return 0;
439 LeaveCriticalSection( &X11DRV_CritSection );
441 bmpXor = (BITMAPOBJ *) GDI_GetObjPtr( descr.bitmap, BITMAP_MAGIC );
442 bmpAnd = (BITMAPOBJ *) GDI_GetObjPtr( descr.mask, BITMAP_MAGIC );
443 sizeXor = bmpXor->bitmap.bmHeight * bmpXor->bitmap.bmWidthBytes;
444 sizeAnd = bmpXor->bitmap.bmHeight * BITMAP_WIDTH_BYTES( bmpXor->bitmap.bmWidth, 1 );
446 if (!(handle = GlobalAlloc16( GMEM_MOVEABLE,
447 sizeof(CURSORICONINFO) + sizeXor + sizeAnd)))
449 DeleteObject32( descr.bitmap );
450 DeleteObject32( descr.mask );
451 return 0;
454 pInfo = (CURSORICONINFO *)GlobalLock16( handle );
455 pInfo->ptHotSpot.x = descr.hotspot.x;
456 pInfo->ptHotSpot.y = descr.hotspot.y;
457 pInfo->nWidth = bmpXor->bitmap.bmWidth;
458 pInfo->nHeight = bmpXor->bitmap.bmHeight;
459 pInfo->nWidthBytes = bmpXor->bitmap.bmWidthBytes;
460 pInfo->bPlanes = bmpXor->bitmap.bmPlanes;
461 pInfo->bBitsPerPixel = bmpXor->bitmap.bmBitsPixel;
463 if (descr.mask)
465 /* Invert the mask */
467 TSXSetFunction( display, BITMAP_monoGC, GXinvert );
468 TSXFillRectangle( display, bmpAnd->pixmap, BITMAP_monoGC, 0, 0,
469 bmpAnd->bitmap.bmWidth, bmpAnd->bitmap.bmHeight );
470 TSXSetFunction( display, BITMAP_monoGC, GXcopy );
472 /* Set the masked pixels to black */
474 if (bmpXor->bitmap.bmBitsPixel != 1)
476 TSXSetForeground( display, BITMAP_colorGC,
477 COLOR_ToPhysical( NULL, RGB(0,0,0) ));
478 TSXSetBackground( display, BITMAP_colorGC, 0 );
479 TSXSetFunction( display, BITMAP_colorGC, GXor );
480 TSXCopyPlane(display, bmpAnd->pixmap, bmpXor->pixmap, BITMAP_colorGC,
481 0, 0, bmpXor->bitmap.bmWidth, bmpXor->bitmap.bmHeight,
482 0, 0, 1 );
483 TSXSetFunction( display, BITMAP_colorGC, GXcopy );
487 if (descr.mask) GetBitmapBits32( descr.mask, sizeAnd, (char *)(pInfo + 1));
488 else memset( (char *)(pInfo + 1), 0xff, sizeAnd );
489 GetBitmapBits32( descr.bitmap, sizeXor, (char *)(pInfo + 1) + sizeAnd );
491 DeleteObject32( descr.bitmap );
492 DeleteObject32( descr.mask );
494 if (fCursor) OBM_Cursors[id] = handle;
495 return handle;
499 /***********************************************************************
500 * OBM_Init
502 * Initializes the OBM_Pixmaps_Data struct
504 BOOL32 OBM_Init()
506 if(TWEAK_Win95Look) {
507 OBM_Pixmaps_Data[OBM_ZOOMD - OBM_FIRST].data = obm_zoomd_95;
508 OBM_Pixmaps_Data[OBM_REDUCED - OBM_FIRST].data = obm_reduced_95;
509 OBM_Pixmaps_Data[OBM_ZOOM - OBM_FIRST].data = obm_zoom_95;
510 OBM_Pixmaps_Data[OBM_REDUCE - OBM_FIRST].data = obm_reduce_95;
511 OBM_Pixmaps_Data[OBM_CLOSE - OBM_FIRST].data = obm_close_95;
513 else {
514 OBM_Pixmaps_Data[OBM_ZOOMD - OBM_FIRST].data = obm_zoomd;
515 OBM_Pixmaps_Data[OBM_REDUCED - OBM_FIRST].data = obm_reduced;
516 OBM_Pixmaps_Data[OBM_ZOOM - OBM_FIRST].data = obm_zoom;
517 OBM_Pixmaps_Data[OBM_REDUCE - OBM_FIRST].data = obm_reduce;
518 OBM_Pixmaps_Data[OBM_CLOSE - OBM_FIRST].data = obm_close;
521 return 1;