Release 960114
[wine.git] / objects / oembitmap.c
blobfacd5b45e007edd89717e2c25fa7917662298d68
1 /*
2 * GDI OEM bitmap objects
4 * Copyright 1994, 1995 Alexandre Julliard
6 */
8 #include <stdlib.h>
9 #include <string.h>
10 #include <X11/Xlib.h>
11 #include <X11/Xutil.h>
12 #include <X11/xpm.h>
13 #include "gdi.h"
14 #include "bitmap.h"
15 #include "callback.h"
16 #include "color.h"
17 #include "cursoricon.h"
18 #include "stddebug.h"
19 #include "debug.h"
22 /* Include OEM pixmaps */
23 #include "bitmaps/obm_cdrom"
24 #include "bitmaps/obm_harddisk"
25 #include "bitmaps/obm_drive"
26 #include "bitmaps/obm_folder2"
27 #include "bitmaps/obm_folder"
28 #include "bitmaps/obm_lfarrowi"
29 #include "bitmaps/obm_rgarrowi"
30 #include "bitmaps/obm_dnarrowi"
31 #include "bitmaps/obm_uparrowi"
32 #include "bitmaps/obm_combo"
33 #include "bitmaps/obm_mnarrow"
34 #include "bitmaps/obm_lfarrowd"
35 #include "bitmaps/obm_rgarrowd"
36 #include "bitmaps/obm_dnarrowd"
37 #include "bitmaps/obm_uparrowd"
38 #include "bitmaps/obm_restored"
39 #include "bitmaps/obm_restore"
40 #include "bitmaps/obm_lfarrow"
41 #include "bitmaps/obm_rgarrow"
42 #include "bitmaps/obm_dnarrow"
43 #include "bitmaps/obm_uparrow"
44 #include "bitmaps/obm_old_restore"
45 #include "bitmaps/obm_old_zoom"
46 #include "bitmaps/obm_old_reduce"
47 #include "bitmaps/obm_btncorners"
48 #include "bitmaps/obm_checkboxes"
49 #include "bitmaps/obm_check"
50 #include "bitmaps/obm_btsize"
51 #include "bitmaps/obm_old_lfarrow"
52 #include "bitmaps/obm_old_rgarrow"
53 #include "bitmaps/obm_old_dnarrow"
54 #include "bitmaps/obm_old_uparrow"
55 #include "bitmaps/obm_size"
56 #include "bitmaps/obm_old_close"
58 #ifndef WIN_95_LOOK
59 #include "bitmaps/obm_zoomd"
60 #include "bitmaps/obm_reduced"
61 #include "bitmaps/obm_zoom"
62 #include "bitmaps/obm_reduce"
63 #include "bitmaps/obm_close"
64 #else
65 #include "bitmaps/obm_zoomd_95"
66 #include "bitmaps/obm_reduced_95"
67 #include "bitmaps/obm_zoom_95"
68 #include "bitmaps/obm_reduce_95"
69 #include "bitmaps/obm_close_95"
70 #include "bitmaps/obm_closed_95"
71 #endif /* WIN_95_LOOK */
73 #define OBM_FIRST OBM_CDROM /* First OEM bitmap */
74 #define OBM_LAST OBM_OLD_CLOSE /* Last OEM bitmap */
76 static const struct
78 char** data; /* Pointer to bitmap data */
79 BOOL color; /* Is it a color bitmap? */
80 } OBM_Pixmaps_Data[OBM_LAST-OBM_FIRST+1] = {
81 { obm_cdrom, TRUE }, /* OBM_CDROM */
82 { obm_harddisk, TRUE }, /* OBM_HARDDISK */
83 { obm_drive, TRUE }, /* OBM_DRIVE */
84 { obm_folder2, TRUE }, /* OBM_FOLDER2 */
85 { obm_folder, TRUE }, /* OBM_FOLDER */
86 { obm_lfarrowi, TRUE }, /* OBM_LFARROWI */
87 { obm_rgarrowi, TRUE }, /* OBM_RGARROWI */
88 { obm_dnarrowi, TRUE }, /* OBM_DNARROWI */
89 { obm_uparrowi, TRUE }, /* OBM_UPARROWI */
90 { obm_combo, FALSE }, /* OBM_COMBO */
91 { obm_mnarrow, FALSE }, /* OBM_MNARROW */
92 { obm_lfarrowd, TRUE }, /* OBM_LFARROWD */
93 { obm_rgarrowd, TRUE }, /* OBM_RGARROWD */
94 { obm_dnarrowd, TRUE }, /* OBM_DNARROWD */
95 { obm_uparrowd, TRUE }, /* OBM_UPARROWD */
96 { obm_restored, TRUE }, /* OBM_RESTORED */
97 { obm_zoomd, TRUE }, /* OBM_ZOOMD */
98 { obm_reduced, TRUE }, /* OBM_REDUCED */
99 { obm_restore, TRUE }, /* OBM_RESTORE */
100 #ifdef WIN_95_LOOK
101 { obm_zoom_95, TRUE }, /* OBM_ZOOM */
102 { obm_reduce_95, TRUE }, /* OBM_REDUCE */
103 #else
104 { obm_zoom, TRUE }, /* OBM_ZOOM */
105 { obm_reduce, TRUE }, /* OBM_REDUCE */
106 #endif
107 { obm_lfarrow, TRUE }, /* OBM_LFARROW */
108 { obm_rgarrow, TRUE }, /* OBM_RGARROW */
109 { obm_dnarrow, TRUE }, /* OBM_DNARROW */
110 { obm_uparrow, TRUE }, /* OBM_UPARROW */
111 #ifdef WIN_95_LOOK
112 { obm_close_95, TRUE }, /* OBM_CLOSE */
113 #else
114 { obm_close, TRUE }, /* OBM_CLOSE */
115 #endif
116 { obm_old_restore, FALSE }, /* OBM_OLD_RESTORE */
117 { obm_old_zoom, FALSE }, /* OBM_OLD_ZOOM */
118 { obm_old_reduce, FALSE }, /* OBM_OLD_REDUCE */
119 { obm_btncorners, FALSE }, /* OBM_BTNCORNERS */
120 { obm_checkboxes, FALSE }, /* OBM_CHECKBOXES */
121 { obm_check, FALSE }, /* OBM_CHECK */
122 { obm_btsize, FALSE }, /* OBM_BTSIZE */
123 { obm_old_lfarrow, FALSE }, /* OBM_OLD_LFARROW */
124 { obm_old_rgarrow, FALSE }, /* OBM_OLD_RGARROW */
125 { obm_old_dnarrow, FALSE }, /* OBM_OLD_DNARROW */
126 { obm_old_uparrow, FALSE }, /* OBM_OLD_UPARROW */
127 { obm_size, FALSE }, /* OBM_SIZE */
128 { obm_old_close, FALSE }, /* OBM_OLD_CLOSE */
132 /* Include OEM icons */
133 #include "bitmaps/oic_sample"
134 #include "bitmaps/oic_hand"
135 #include "bitmaps/oic_ques"
136 #include "bitmaps/oic_bang"
137 #include "bitmaps/oic_note"
138 #include "bitmaps/oic_portrait"
139 #include "bitmaps/oic_landscape"
140 #include "bitmaps/oic_wineicon"
142 #define OIC_FIRST OIC_SAMPLE /* First OEM icon */
143 #define OIC_LAST OIC_WINEICON /* Last OEM icon */
145 static char **OBM_Icons_Data[OIC_LAST-OIC_FIRST+1] =
147 oic_sample, /* OIC_SAMPLE */
148 oic_hand, /* OIC_HAND */
149 oic_ques, /* OIC_QUES */
150 oic_bang, /* OIC_BANG */
151 oic_note, /* OIC_NOTE */
152 oic_portrait, /* OIC_PORTRAIT */
153 oic_landscape, /* OIC_LANDSCAPE */
154 oic_wineicon /* OIC_WINEICON */
158 /* Include OEM cursors */
159 #include "bitmaps/ocr_normal"
160 #include "bitmaps/ocr_ibeam"
161 #include "bitmaps/ocr_wait"
162 #include "bitmaps/ocr_cross"
163 #include "bitmaps/ocr_up"
164 #include "bitmaps/ocr_size"
165 #include "bitmaps/ocr_icon"
166 #include "bitmaps/ocr_sizenwse"
167 #include "bitmaps/ocr_sizenesw"
168 #include "bitmaps/ocr_sizewe"
169 #include "bitmaps/ocr_sizens"
170 #include "bitmaps/ocr_bummer"
171 #include "bitmaps/ocr_dragobject"
172 #if 0
173 #include "bitmaps/ocr_sizeall"
174 #include "bitmaps/ocr_icocur"
175 #endif
177 /* Cursor are not all contiguous (go figure...) */
178 #define OCR_FIRST0 OCR_BUMMER
179 #define OCR_LAST0 OCR_DRAGOBJECT
180 #define OCR_BASE0 0
182 #define OCR_FIRST1 OCR_NORMAL
183 #define OCR_LAST1 OCR_UP
184 #define OCR_BASE1 (OCR_BASE0 + OCR_LAST0 - OCR_FIRST0 + 1)
186 #define OCR_FIRST2 OCR_SIZE
187 #define OCR_LAST2 OCR_SIZENS
188 #define OCR_BASE2 (OCR_BASE1 + OCR_LAST1 - OCR_FIRST1 + 1)
190 #define NB_CURSORS (OCR_BASE2 + OCR_LAST2 - OCR_FIRST2 + 1)
191 static char **OBM_Cursors_Data[NB_CURSORS] =
193 ocr_bummer, /* OCR_BUMMER */
194 ocr_dragobject,/* OCR_DRAGOBJECT */
195 ocr_normal, /* OCR_NORMAL */
196 ocr_ibeam, /* OCR_IBEAM */
197 ocr_wait, /* OCR_WAIT */
198 ocr_cross, /* OCR_CROSS */
199 ocr_up, /* OCR_UP */
200 ocr_size, /* OCR_SIZE */
201 ocr_icon, /* OCR_ICON */
202 ocr_sizenwse, /* OCR_SIZENWSE */
203 ocr_sizenesw, /* OCR_SIZENESW */
204 ocr_sizewe, /* OCR_SIZEWE */
205 ocr_sizens /* OCR_SIZENS */
206 #if 0
207 ocr_sizeall, /* OCR_SIZEALL */
208 ocr_icocur /* OCR_ICOCUR */
209 #endif
212 static HCURSOR OBM_Cursors[NB_CURSORS] = { 0, };
215 /* All the colors used in the xpm files must be included in this */
216 /* list, to make sure that the loaded bitmaps only use colors from */
217 /* the Windows colormap. Note: the PALETTEINDEX() are not really */
218 /* palette indexes, but system colors that will be converted to */
219 /* indexes later on. */
221 static const struct
223 char * name;
224 COLORREF color;
225 } OBM_SymbolicColors[] =
227 { "black", RGB(0,0,0) },
228 { "white", RGB(255,255,255) },
229 { "red", RGB(255,0,0) },
230 { "green", RGB(0,255,0) },
231 { "blue", RGB(0,0,255) },
232 { "yellow", RGB(255,255,0) },
233 { "cyan", RGB(0,255,255) },
234 { "dkyellow", RGB(128,128,0) },
235 { "purple", RGB(128,0,128) },
236 { "ltgray", RGB(192,192,192) },
237 { "dkgray", RGB(128,128,128) },
238 { "foldercol", RGB(0,191,191) },
239 { "button_face", PALETTEINDEX(COLOR_BTNFACE) },
240 { "button_shadow", PALETTEINDEX(COLOR_BTNSHADOW) },
241 { "button_highlight", PALETTEINDEX(COLOR_BTNHIGHLIGHT) },
242 { "button_edge", PALETTEINDEX(COLOR_BTNHIGHLIGHT) },
243 { "button_text", PALETTEINDEX(COLOR_BTNTEXT) },
244 { "window_frame", PALETTEINDEX(COLOR_WINDOWFRAME) }
247 #define NB_COLOR_SYMBOLS \
248 (sizeof(OBM_SymbolicColors)/sizeof(OBM_SymbolicColors[0]))
250 /* These are the symbolic colors for monochrome bitmaps */
251 /* This is needed to make sure that black is always 0 and */
252 /* white always 1, as required by Windows. */
254 static XpmColorSymbol OBM_BlackAndWhite[2] =
256 { "black", NULL, 0 },
257 { "white", NULL, 0xffffffff }
260 static XpmColorSymbol *OBM_Colors = NULL;
263 /***********************************************************************
264 * OBM_InitColorSymbols
266 static BOOL OBM_InitColorSymbols()
268 int i;
270 if (OBM_Colors) return TRUE; /* Already initialised */
272 OBM_Colors = (XpmColorSymbol *) malloc( sizeof(XpmColorSymbol) *
273 NB_COLOR_SYMBOLS );
274 if (!OBM_Colors) return FALSE;
275 for (i = 0; i < NB_COLOR_SYMBOLS; i++)
277 OBM_Colors[i].name = OBM_SymbolicColors[i].name;
278 OBM_Colors[i].value = NULL;
279 if (OBM_SymbolicColors[i].color & 0xff000000) /* PALETTEINDEX */
280 OBM_Colors[i].pixel = COLOR_ToPhysical( NULL,
281 GetSysColor(OBM_SymbolicColors[i].color & 0xff));
282 else /* RGB*/
283 OBM_Colors[i].pixel = COLOR_ToPhysical( NULL,
284 OBM_SymbolicColors[i].color );
286 return TRUE;
290 /***********************************************************************
291 * OBM_MakeBitmap
293 * Allocate a GDI bitmap.
295 static HBITMAP OBM_MakeBitmap( WORD width, WORD height,
296 WORD bpp, Pixmap pixmap )
298 HBITMAP hbitmap;
299 BITMAPOBJ * bmpObjPtr;
301 if (!pixmap) return 0;
303 hbitmap = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC );
304 if (!hbitmap) return 0;
306 bmpObjPtr = (BITMAPOBJ *) GDI_HEAP_LIN_ADDR( hbitmap );
307 bmpObjPtr->size.cx = 0;
308 bmpObjPtr->size.cy = 0;
309 bmpObjPtr->pixmap = pixmap;
310 bmpObjPtr->bitmap.bmType = 0;
311 bmpObjPtr->bitmap.bmWidth = width;
312 bmpObjPtr->bitmap.bmHeight = height;
313 bmpObjPtr->bitmap.bmWidthBytes = (width * bpp + 15) / 16 * 2;
314 bmpObjPtr->bitmap.bmPlanes = 1;
315 bmpObjPtr->bitmap.bmBitsPixel = bpp;
316 bmpObjPtr->bitmap.bmBits = NULL;
317 return hbitmap;
321 /***********************************************************************
322 * OBM_CreateBitmaps
324 * Create the 2 bitmaps from XPM data.
326 static BOOL OBM_CreateBitmaps( char **data, BOOL color, BOOL mask,
327 HBITMAP *hBitmap, HBITMAP *hBitmapMask,
328 POINT *hotspot )
330 Pixmap pixmap, pixmask;
331 XpmAttributes attrs;
332 int err;
334 attrs.valuemask = XpmColormap | XpmDepth | XpmColorSymbols | XpmHotspot;
335 attrs.colormap = COLOR_WinColormap;
336 attrs.depth = color ? screenDepth : 1;
337 attrs.colorsymbols = (attrs.depth > 1) ? OBM_Colors : OBM_BlackAndWhite;
338 attrs.numsymbols = (attrs.depth > 1) ? NB_COLOR_SYMBOLS : 2;
340 err = XpmCreatePixmapFromData( display, rootWindow, data,
341 &pixmap, &pixmask, &attrs );
343 if (err != XpmSuccess) return FALSE;
344 if (hotspot)
346 hotspot->x = attrs.x_hotspot;
347 hotspot->y = attrs.y_hotspot;
349 *hBitmap = OBM_MakeBitmap( attrs.width, attrs.height,
350 attrs.depth, pixmap );
351 if (mask) *hBitmapMask = OBM_MakeBitmap( attrs.width, attrs.height,
352 1, pixmask );
353 if (!*hBitmap)
355 if (pixmap) XFreePixmap( display, pixmap );
356 if (pixmask) XFreePixmap( display, pixmask );
357 if (*hBitmap) GDI_FreeObject( *hBitmap );
358 if (*hBitmapMask) GDI_FreeObject( *hBitmapMask );
359 return FALSE;
361 else return TRUE;
365 /***********************************************************************
366 * OBM_LoadBitmap
368 HBITMAP OBM_LoadBitmap( WORD id )
370 HBITMAP hbitmap, hbitmask;
372 if ((id < OBM_FIRST) || (id > OBM_LAST)) return 0;
373 id -= OBM_FIRST;
375 if (!OBM_InitColorSymbols()) return 0;
377 if (!CallTo32_LargeStack( (int(*)())OBM_CreateBitmaps, 6,
378 OBM_Pixmaps_Data[id].data,
379 OBM_Pixmaps_Data[id].color,
380 FALSE, &hbitmap, &hbitmask, NULL, NULL ))
382 fprintf( stderr, "Error creating OEM bitmap %d\n", OBM_FIRST+id );
383 return 0;
385 return hbitmap;
389 /***********************************************************************
390 * OBM_LoadCursorIcon
392 HANDLE OBM_LoadCursorIcon( WORD id, BOOL fCursor )
394 HANDLE handle;
395 CURSORICONINFO *pInfo;
396 BITMAPOBJ *bmpXor, *bmpAnd;
397 HBITMAP hXorBits, hAndBits;
398 POINT hotspot;
399 int sizeXor, sizeAnd;
401 if (fCursor)
403 if ((id >= OCR_FIRST1) && (id <= OCR_LAST1))
404 id = OCR_BASE1 + id - OCR_FIRST1;
405 else if ((id >= OCR_FIRST2) && (id <= OCR_LAST2))
406 id = OCR_BASE2 + id - OCR_FIRST2;
407 else if ((id >= OCR_FIRST0) && (id <= OCR_LAST0))
408 id = OCR_BASE0 + id - OCR_FIRST0;
409 else return 0;
410 if (OBM_Cursors[id]) return OBM_Cursors[id];
412 else
414 if ((id < OIC_FIRST) || (id > OIC_LAST)) return 0;
415 id -= OIC_FIRST;
418 if (!OBM_InitColorSymbols()) return 0;
420 if (!CallTo32_LargeStack( (int(*)())OBM_CreateBitmaps, 6,
421 fCursor ? OBM_Cursors_Data[id] : OBM_Icons_Data[id],
422 !fCursor, TRUE, &hXorBits, &hAndBits, &hotspot ))
424 fprintf( stderr, "Error creating OEM cursor/icon %d\n", id );
425 return 0;
428 bmpXor = (BITMAPOBJ *) GDI_GetObjPtr( hXorBits, BITMAP_MAGIC );
429 bmpAnd = (BITMAPOBJ *) GDI_GetObjPtr( hAndBits, BITMAP_MAGIC );
430 sizeXor = bmpXor->bitmap.bmHeight * bmpXor->bitmap.bmWidthBytes;
431 sizeAnd = bmpXor->bitmap.bmHeight * ((bmpXor->bitmap.bmWidth+15) / 16 * 2);
433 if (!(handle = GlobalAlloc( GMEM_MOVEABLE,
434 sizeof(CURSORICONINFO) + sizeXor + sizeAnd)))
436 DeleteObject( hXorBits );
437 DeleteObject( hAndBits );
438 return 0;
441 pInfo = (CURSORICONINFO *)GlobalLock( handle );
442 pInfo->ptHotSpot.x = hotspot.x;
443 pInfo->ptHotSpot.y = hotspot.y;
444 pInfo->nWidth = bmpXor->bitmap.bmWidth;
445 pInfo->nHeight = bmpXor->bitmap.bmHeight;
446 pInfo->nWidthBytes = bmpXor->bitmap.bmWidthBytes;
447 pInfo->bPlanes = bmpXor->bitmap.bmPlanes;
448 pInfo->bBitsPerPixel = bmpXor->bitmap.bmBitsPixel;
450 if (hAndBits)
452 /* Invert the mask */
454 XSetFunction( display, BITMAP_monoGC, GXinvert );
455 XFillRectangle( display, bmpAnd->pixmap, BITMAP_monoGC, 0, 0,
456 bmpAnd->bitmap.bmWidth, bmpAnd->bitmap.bmHeight );
457 XSetFunction( display, BITMAP_monoGC, GXcopy );
459 /* Set the masked pixels to black */
461 if (bmpXor->bitmap.bmBitsPixel != 1)
463 XSetForeground( display, BITMAP_colorGC,
464 COLOR_ToPhysical( NULL, RGB(0,0,0) ));
465 XSetBackground( display, BITMAP_colorGC, 0 );
466 XSetFunction( display, BITMAP_colorGC, GXor );
467 XCopyPlane(display, bmpAnd->pixmap, bmpXor->pixmap, BITMAP_colorGC,
468 0, 0, bmpXor->bitmap.bmWidth, bmpXor->bitmap.bmHeight,
469 0, 0, 1 );
470 XSetFunction( display, BITMAP_colorGC, GXcopy );
474 if (hAndBits) GetBitmapBits( hAndBits, sizeAnd, (char *)(pInfo + 1) );
475 else memset( (char *)(pInfo + 1), 0xff, sizeAnd );
476 GetBitmapBits( hXorBits, sizeXor, (char *)(pInfo + 1) + sizeAnd );
478 DeleteObject( hXorBits );
479 DeleteObject( hAndBits );
481 if (fCursor) OBM_Cursors[id] = handle;
482 return handle;