2 * GDI OEM bitmap objects
4 * Copyright 1994, 1995 Alexandre Julliard
11 #include <X11/Xutil.h>
17 #include "cursoricon.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"
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"
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 */
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 */
101 { obm_zoom_95
, TRUE
}, /* OBM_ZOOM */
102 { obm_reduce_95
, TRUE
}, /* OBM_REDUCE */
104 { obm_zoom
, TRUE
}, /* OBM_ZOOM */
105 { obm_reduce
, TRUE
}, /* OBM_REDUCE */
107 { obm_lfarrow
, TRUE
}, /* OBM_LFARROW */
108 { obm_rgarrow
, TRUE
}, /* OBM_RGARROW */
109 { obm_dnarrow
, TRUE
}, /* OBM_DNARROW */
110 { obm_uparrow
, TRUE
}, /* OBM_UPARROW */
112 { obm_close_95
, TRUE
}, /* OBM_CLOSE */
114 { obm_close
, TRUE
}, /* OBM_CLOSE */
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"
173 #include "bitmaps/ocr_sizeall"
174 #include "bitmaps/ocr_icocur"
177 /* Cursor are not all contiguous (go figure...) */
178 #define OCR_FIRST0 OCR_BUMMER
179 #define OCR_LAST0 OCR_DRAGOBJECT
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 */
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 */
207 ocr_sizeall
, /* OCR_SIZEALL */
208 ocr_icocur
/* OCR_ICOCUR */
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. */
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()
270 if (OBM_Colors
) return TRUE
; /* Already initialised */
272 OBM_Colors
= (XpmColorSymbol
*) malloc( sizeof(XpmColorSymbol
) *
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));
283 OBM_Colors
[i
].pixel
= COLOR_ToPhysical( NULL
,
284 OBM_SymbolicColors
[i
].color
);
290 /***********************************************************************
293 * Allocate a GDI bitmap.
295 static HBITMAP
OBM_MakeBitmap( WORD width
, WORD height
,
296 WORD bpp
, Pixmap pixmap
)
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
;
321 /***********************************************************************
324 * Create the 2 bitmaps from XPM data.
326 static BOOL
OBM_CreateBitmaps( char **data
, BOOL color
, HBITMAP
*hBitmap
,
327 HBITMAP
*hBitmapMask
, POINT
*hotspot
)
329 Pixmap pixmap
, pixmask
;
333 attrs
.valuemask
= XpmColormap
| XpmDepth
| XpmColorSymbols
| XpmHotspot
;
334 attrs
.colormap
= COLOR_WinColormap
;
335 attrs
.depth
= color
? screenDepth
: 1;
336 attrs
.colorsymbols
= (attrs
.depth
> 1) ? OBM_Colors
: OBM_BlackAndWhite
;
337 attrs
.numsymbols
= (attrs
.depth
> 1) ? NB_COLOR_SYMBOLS
: 2;
339 err
= XpmCreatePixmapFromData( display
, rootWindow
, data
,
340 &pixmap
, &pixmask
, &attrs
);
342 if (err
!= XpmSuccess
) return FALSE
;
345 hotspot
->x
= attrs
.x_hotspot
;
346 hotspot
->y
= attrs
.y_hotspot
;
348 *hBitmap
= OBM_MakeBitmap( attrs
.width
, attrs
.height
,
349 attrs
.depth
, pixmap
);
350 if (hBitmapMask
) *hBitmapMask
= OBM_MakeBitmap( attrs
.width
, attrs
.height
,
354 if (pixmap
) XFreePixmap( display
, pixmap
);
355 if (pixmask
) XFreePixmap( display
, pixmask
);
356 if (*hBitmap
) GDI_FreeObject( *hBitmap
);
357 if (hBitmapMask
&& *hBitmapMask
) GDI_FreeObject( *hBitmapMask
);
364 /***********************************************************************
367 HBITMAP
OBM_LoadBitmap( WORD id
)
371 if ((id
< OBM_FIRST
) || (id
> OBM_LAST
)) return 0;
374 if (!OBM_InitColorSymbols()) return 0;
376 if (!CallTo32_LargeStack( (int(*)())OBM_CreateBitmaps
, 5,
377 OBM_Pixmaps_Data
[id
].data
,
378 OBM_Pixmaps_Data
[id
].color
,
379 &hbitmap
, NULL
, NULL
))
381 fprintf( stderr
, "Error creating OEM bitmap %d\n", OBM_FIRST
+id
);
388 /***********************************************************************
391 HANDLE
OBM_LoadCursorIcon( WORD id
, BOOL fCursor
)
394 CURSORICONINFO
*pInfo
;
395 BITMAPOBJ
*bmpXor
, *bmpAnd
;
396 HBITMAP hXorBits
, hAndBits
;
398 int sizeXor
, sizeAnd
;
402 if ((id
>= OCR_FIRST1
) && (id
<= OCR_LAST1
))
403 id
= OCR_BASE1
+ id
- OCR_FIRST1
;
404 else if ((id
>= OCR_FIRST2
) && (id
<= OCR_LAST2
))
405 id
= OCR_BASE2
+ id
- OCR_FIRST2
;
406 else if ((id
>= OCR_FIRST0
) && (id
<= OCR_LAST0
))
407 id
= OCR_BASE0
+ id
- OCR_FIRST0
;
409 if (OBM_Cursors
[id
]) return OBM_Cursors
[id
];
413 if ((id
< OIC_FIRST
) || (id
> OIC_LAST
)) return 0;
417 if (!OBM_InitColorSymbols()) return 0;
419 if (!CallTo32_LargeStack( (int(*)())OBM_CreateBitmaps
, 5,
420 fCursor
? OBM_Cursors_Data
[id
] : OBM_Icons_Data
[id
],
421 !fCursor
, &hXorBits
, &hAndBits
, &hotspot
))
423 fprintf( stderr
, "Error creating OEM cursor/icon %d\n", id
);
427 bmpXor
= (BITMAPOBJ
*) GDI_GetObjPtr( hXorBits
, BITMAP_MAGIC
);
428 bmpAnd
= (BITMAPOBJ
*) GDI_GetObjPtr( hAndBits
, BITMAP_MAGIC
);
429 sizeXor
= bmpXor
->bitmap
.bmHeight
* bmpXor
->bitmap
.bmWidthBytes
;
430 sizeAnd
= bmpXor
->bitmap
.bmHeight
* ((bmpXor
->bitmap
.bmWidth
+15) / 16 * 2);
432 if (!(handle
= GlobalAlloc( GMEM_MOVEABLE
,
433 sizeof(CURSORICONINFO
) + sizeXor
+ sizeAnd
)))
435 DeleteObject( hXorBits
);
436 DeleteObject( hAndBits
);
440 pInfo
= (CURSORICONINFO
*)GlobalLock( handle
);
441 pInfo
->ptHotSpot
.x
= hotspot
.x
;
442 pInfo
->ptHotSpot
.y
= hotspot
.y
;
443 pInfo
->nWidth
= bmpXor
->bitmap
.bmWidth
;
444 pInfo
->nHeight
= bmpXor
->bitmap
.bmHeight
;
445 pInfo
->nWidthBytes
= bmpXor
->bitmap
.bmWidthBytes
;
446 pInfo
->bPlanes
= bmpXor
->bitmap
.bmPlanes
;
447 pInfo
->bBitsPerPixel
= bmpXor
->bitmap
.bmBitsPixel
;
451 /* Invert the mask */
453 XSetFunction( display
, BITMAP_monoGC
, GXinvert
);
454 XFillRectangle( display
, bmpAnd
->pixmap
, BITMAP_monoGC
, 0, 0,
455 bmpAnd
->bitmap
.bmWidth
, bmpAnd
->bitmap
.bmHeight
);
456 XSetFunction( display
, BITMAP_monoGC
, GXcopy
);
458 /* Set the masked pixels to black */
460 if (bmpXor
->bitmap
.bmBitsPixel
!= 1)
462 XSetForeground( display
, BITMAP_colorGC
,
463 COLOR_ToPhysical( NULL
, RGB(0,0,0) ));
464 XSetBackground( display
, BITMAP_colorGC
, 0 );
465 XSetFunction( display
, BITMAP_colorGC
, GXor
);
466 XCopyPlane(display
, bmpAnd
->pixmap
, bmpXor
->pixmap
, BITMAP_colorGC
,
467 0, 0, bmpXor
->bitmap
.bmWidth
, bmpXor
->bitmap
.bmHeight
,
469 XSetFunction( display
, BITMAP_colorGC
, GXcopy
);
473 if (hAndBits
) GetBitmapBits( hAndBits
, sizeAnd
, (char *)(pInfo
+ 1) );
474 else memset( (char *)(pInfo
+ 1), 0xff, sizeAnd
);
475 GetBitmapBits( hXorBits
, sizeXor
, (char *)(pInfo
+ 1) + sizeAnd
);
477 DeleteObject( hXorBits
);
478 DeleteObject( hAndBits
);
480 if (fCursor
) OBM_Cursors
[id
] = handle
;