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"
57 #include "bitmaps/obm_trtype"
60 #include "bitmaps/obm_zoomd"
61 #include "bitmaps/obm_reduced"
62 #include "bitmaps/obm_zoom"
63 #include "bitmaps/obm_reduce"
64 #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"
72 #endif /* WIN_95_LOOK */
74 #define OBM_FIRST OBM_TRTYPE /* First OEM bitmap */
75 #define OBM_LAST OBM_OLD_CLOSE /* Last OEM bitmap */
79 char** data
; /* Pointer to bitmap data */
80 BOOL color
; /* Is it a color bitmap? */
81 } OBM_Pixmaps_Data
[OBM_LAST
-OBM_FIRST
+1] = {
82 { obm_trtype
, TRUE
}, /* OBM_TRTYPE */
83 { obm_cdrom
, TRUE
}, /* OBM_CDROM */
84 { obm_harddisk
, TRUE
}, /* OBM_HARDDISK */
85 { obm_drive
, TRUE
}, /* OBM_DRIVE */
86 { obm_folder2
, TRUE
}, /* OBM_FOLDER2 */
87 { obm_folder
, TRUE
}, /* OBM_FOLDER */
88 { obm_lfarrowi
, TRUE
}, /* OBM_LFARROWI */
89 { obm_rgarrowi
, TRUE
}, /* OBM_RGARROWI */
90 { obm_dnarrowi
, TRUE
}, /* OBM_DNARROWI */
91 { obm_uparrowi
, TRUE
}, /* OBM_UPARROWI */
92 { obm_combo
, FALSE
}, /* OBM_COMBO */
93 { obm_mnarrow
, FALSE
}, /* OBM_MNARROW */
94 { obm_lfarrowd
, TRUE
}, /* OBM_LFARROWD */
95 { obm_rgarrowd
, TRUE
}, /* OBM_RGARROWD */
96 { obm_dnarrowd
, TRUE
}, /* OBM_DNARROWD */
97 { obm_uparrowd
, TRUE
}, /* OBM_UPARROWD */
98 { obm_restored
, TRUE
}, /* OBM_RESTORED */
100 { obm_zoomd_95
, TRUE
}, /* OBM_ZOOMD */
101 { obm_reduced_95
, TRUE
}, /* OBM_REDUCED */
103 { obm_zoomd
, TRUE
}, /* OBM_ZOOMD */
104 { obm_reduced
, TRUE
}, /* OBM_REDUCED */
106 { obm_restore
, TRUE
}, /* OBM_RESTORE */
108 { obm_zoom_95
, TRUE
}, /* OBM_ZOOM */
109 { obm_reduce_95
, TRUE
}, /* OBM_REDUCE */
111 { obm_zoom
, TRUE
}, /* OBM_ZOOM */
112 { 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 */
119 { obm_close_95
, TRUE
}, /* OBM_CLOSE */
121 { obm_close
, TRUE
}, /* OBM_CLOSE */
123 { obm_old_restore
, FALSE
}, /* OBM_OLD_RESTORE */
124 { obm_old_zoom
, FALSE
}, /* OBM_OLD_ZOOM */
125 { obm_old_reduce
, FALSE
}, /* OBM_OLD_REDUCE */
126 { obm_btncorners
, FALSE
}, /* OBM_BTNCORNERS */
127 { obm_checkboxes
, FALSE
}, /* OBM_CHECKBOXES */
128 { obm_check
, FALSE
}, /* OBM_CHECK */
129 { obm_btsize
, FALSE
}, /* OBM_BTSIZE */
130 { obm_old_lfarrow
, FALSE
}, /* OBM_OLD_LFARROW */
131 { obm_old_rgarrow
, FALSE
}, /* OBM_OLD_RGARROW */
132 { obm_old_dnarrow
, FALSE
}, /* OBM_OLD_DNARROW */
133 { obm_old_uparrow
, FALSE
}, /* OBM_OLD_UPARROW */
134 { obm_size
, FALSE
}, /* OBM_SIZE */
135 { obm_old_close
, FALSE
}, /* OBM_OLD_CLOSE */
139 /* Include OEM icons */
140 #include "bitmaps/oic_sample"
141 #include "bitmaps/oic_hand"
142 #include "bitmaps/oic_ques"
143 #include "bitmaps/oic_bang"
144 #include "bitmaps/oic_note"
145 #include "bitmaps/oic_portrait"
146 #include "bitmaps/oic_landscape"
147 #include "bitmaps/oic_wineicon"
149 #define OIC_FIRST OIC_SAMPLE /* First OEM icon */
150 #define OIC_LAST OIC_WINEICON /* Last OEM icon */
152 static char ** const OBM_Icons_Data
[OIC_LAST
-OIC_FIRST
+1] =
154 oic_sample
, /* OIC_SAMPLE */
155 oic_hand
, /* OIC_HAND */
156 oic_ques
, /* OIC_QUES */
157 oic_bang
, /* OIC_BANG */
158 oic_note
, /* OIC_NOTE */
159 oic_portrait
, /* OIC_PORTRAIT */
160 oic_landscape
, /* OIC_LANDSCAPE */
161 oic_wineicon
/* OIC_WINEICON */
165 /* Include OEM cursors */
166 #include "bitmaps/ocr_normal"
167 #include "bitmaps/ocr_ibeam"
168 #include "bitmaps/ocr_wait"
169 #include "bitmaps/ocr_cross"
170 #include "bitmaps/ocr_up"
171 #include "bitmaps/ocr_size"
172 #include "bitmaps/ocr_icon"
173 #include "bitmaps/ocr_sizenwse"
174 #include "bitmaps/ocr_sizenesw"
175 #include "bitmaps/ocr_sizewe"
176 #include "bitmaps/ocr_sizens"
177 #include "bitmaps/ocr_bummer"
178 #include "bitmaps/ocr_dragobject"
179 /*#include "bitmaps/ocr_sizeall"*/
180 /*#include "bitmaps/ocr_icocur"*/
182 /* Cursor are not all contiguous (go figure...) */
183 #define OCR_FIRST0 OCR_BUMMER
184 #define OCR_LAST0 OCR_DRAGOBJECT
187 #define OCR_FIRST1 OCR_NORMAL
188 #define OCR_LAST1 OCR_UP
189 #define OCR_BASE1 (OCR_BASE0 + OCR_LAST0 - OCR_FIRST0 + 1)
191 #define OCR_FIRST2 OCR_SIZE
192 #define OCR_LAST2 OCR_SIZENS
193 #define OCR_BASE2 (OCR_BASE1 + OCR_LAST1 - OCR_FIRST1 + 1)
195 #define NB_CURSORS (OCR_BASE2 + OCR_LAST2 - OCR_FIRST2 + 1)
196 static char **OBM_Cursors_Data
[NB_CURSORS
] =
198 ocr_bummer
, /* OCR_BUMMER */
199 ocr_dragobject
,/* OCR_DRAGOBJECT */
200 ocr_normal
, /* OCR_NORMAL */
201 ocr_ibeam
, /* OCR_IBEAM */
202 ocr_wait
, /* OCR_WAIT */
203 ocr_cross
, /* OCR_CROSS */
205 ocr_size
, /* OCR_SIZE */
206 ocr_icon
, /* OCR_ICON */
207 ocr_sizenwse
, /* OCR_SIZENWSE */
208 ocr_sizenesw
, /* OCR_SIZENESW */
209 ocr_sizewe
, /* OCR_SIZEWE */
210 ocr_sizens
/* OCR_SIZENS */
212 ocr_sizeall
, /* OCR_SIZEALL */
213 ocr_icocur
/* OCR_ICOCUR */
217 static HGLOBAL16 OBM_Cursors
[NB_CURSORS
];
220 /* All the colors used in the xpm files must be included in this */
221 /* list, to make sure that the loaded bitmaps only use colors from */
222 /* the Windows colormap. Note: the PALETTEINDEX() are not really */
223 /* palette indexes, but system colors that will be converted to */
224 /* indexes later on. */
230 } OBM_SymbolicColors
[] =
232 { "black", RGB(0,0,0) },
233 { "white", RGB(255,255,255) },
234 { "red", RGB(255,0,0) },
235 { "green", RGB(0,255,0) },
236 { "blue", RGB(0,0,255) },
237 { "yellow", RGB(255,255,0) },
238 { "cyan", RGB(0,255,255) },
239 { "dkyellow", RGB(128,128,0) },
240 { "purple", RGB(128,0,128) },
241 { "ltgray", RGB(192,192,192) },
242 { "dkgray", RGB(128,128,128) },
243 { "foldercol", RGB(0,191,191) },
244 { "button_face", PALETTEINDEX(COLOR_BTNFACE
) },
245 { "button_shadow", PALETTEINDEX(COLOR_BTNSHADOW
) },
246 { "button_highlight", PALETTEINDEX(COLOR_BTNHIGHLIGHT
) },
247 { "button_edge", PALETTEINDEX(COLOR_BTNHIGHLIGHT
) },
248 { "button_text", PALETTEINDEX(COLOR_BTNTEXT
) },
249 { "window_frame", PALETTEINDEX(COLOR_WINDOWFRAME
) }
252 #define NB_COLOR_SYMBOLS \
253 (sizeof(OBM_SymbolicColors)/sizeof(OBM_SymbolicColors[0]))
255 /* These are the symbolic colors for monochrome bitmaps */
256 /* This is needed to make sure that black is always 0 and */
257 /* white always 1, as required by Windows. */
259 static XpmColorSymbol OBM_BlackAndWhite
[2] =
261 { "black", NULL
, 0 },
262 { "white", NULL
, 0xffffffff }
265 static XpmColorSymbol
*OBM_Colors
= NULL
;
268 /***********************************************************************
269 * OBM_InitColorSymbols
271 static BOOL
OBM_InitColorSymbols()
275 if (OBM_Colors
) return TRUE
; /* Already initialised */
277 OBM_Colors
= (XpmColorSymbol
*) malloc( sizeof(XpmColorSymbol
) *
279 if (!OBM_Colors
) return FALSE
;
280 for (i
= 0; i
< NB_COLOR_SYMBOLS
; i
++)
282 OBM_Colors
[i
].name
= OBM_SymbolicColors
[i
].name
;
283 OBM_Colors
[i
].value
= NULL
;
284 if (OBM_SymbolicColors
[i
].color
& 0xff000000) /* PALETTEINDEX */
285 OBM_Colors
[i
].pixel
= COLOR_ToPhysical( NULL
,
286 GetSysColor(OBM_SymbolicColors
[i
].color
& 0xff));
288 OBM_Colors
[i
].pixel
= COLOR_ToPhysical( NULL
,
289 OBM_SymbolicColors
[i
].color
);
295 /***********************************************************************
298 * Allocate a GDI bitmap.
300 static HBITMAP16
OBM_MakeBitmap( WORD width
, WORD height
,
301 WORD bpp
, Pixmap pixmap
)
304 BITMAPOBJ
* bmpObjPtr
;
306 if (!pixmap
) return 0;
308 hbitmap
= GDI_AllocObject( sizeof(BITMAPOBJ
), BITMAP_MAGIC
);
309 if (!hbitmap
) return 0;
311 bmpObjPtr
= (BITMAPOBJ
*) GDI_HEAP_LIN_ADDR( hbitmap
);
312 bmpObjPtr
->size
.cx
= 0;
313 bmpObjPtr
->size
.cy
= 0;
314 bmpObjPtr
->pixmap
= pixmap
;
315 bmpObjPtr
->bitmap
.bmType
= 0;
316 bmpObjPtr
->bitmap
.bmWidth
= width
;
317 bmpObjPtr
->bitmap
.bmHeight
= height
;
318 bmpObjPtr
->bitmap
.bmWidthBytes
= BITMAP_WIDTH_BYTES( width
, bpp
);
319 bmpObjPtr
->bitmap
.bmPlanes
= 1;
320 bmpObjPtr
->bitmap
.bmBitsPixel
= bpp
;
321 bmpObjPtr
->bitmap
.bmBits
= NULL
;
326 /***********************************************************************
329 * Create the 2 bitmaps from XPM data.
331 static BOOL
OBM_CreateBitmaps( char **data
, BOOL color
, HBITMAP16
*hBitmap
,
332 HBITMAP16
*hBitmapMask
, POINT16
*hotspot
)
334 Pixmap pixmap
, pixmask
;
335 XpmAttributes
*attrs
;
338 attrs
= (XpmAttributes
*)xmalloc( XpmAttributesSize() );
339 attrs
->valuemask
= XpmColormap
| XpmDepth
| XpmColorSymbols
|XpmHotspot
;
340 attrs
->colormap
= COLOR_GetColormap();
341 attrs
->depth
= color
? screenDepth
: 1;
342 attrs
->colorsymbols
= (attrs
->depth
> 1) ? OBM_Colors
: OBM_BlackAndWhite
;
343 attrs
->numsymbols
= (attrs
->depth
> 1) ? NB_COLOR_SYMBOLS
: 2;
345 err
= XpmCreatePixmapFromData( display
, rootWindow
, data
,
346 &pixmap
, &pixmask
, attrs
);
348 if (err
!= XpmSuccess
)
355 hotspot
->x
= attrs
->x_hotspot
;
356 hotspot
->y
= attrs
->y_hotspot
;
358 *hBitmap
= OBM_MakeBitmap( attrs
->width
, attrs
->height
,
359 attrs
->depth
, pixmap
);
360 if (hBitmapMask
) *hBitmapMask
= OBM_MakeBitmap(attrs
->width
, attrs
->height
,
365 if (pixmap
) XFreePixmap( display
, pixmap
);
366 if (pixmask
) XFreePixmap( display
, pixmask
);
367 if (*hBitmap
) GDI_FreeObject( *hBitmap
);
368 if (hBitmapMask
&& *hBitmapMask
) GDI_FreeObject( *hBitmapMask
);
375 /***********************************************************************
378 HBITMAP16
OBM_LoadBitmap( WORD id
)
382 if ((id
< OBM_FIRST
) || (id
> OBM_LAST
)) return 0;
385 if (!OBM_InitColorSymbols()) return 0;
387 if (!CallTo32_LargeStack( (int(*)())OBM_CreateBitmaps
, 5,
388 OBM_Pixmaps_Data
[id
].data
,
389 OBM_Pixmaps_Data
[id
].color
,
390 &hbitmap
, NULL
, NULL
))
392 fprintf( stderr
, "Error creating OEM bitmap %d\n", OBM_FIRST
+id
);
399 /***********************************************************************
402 HGLOBAL16
OBM_LoadCursorIcon( WORD id
, BOOL32 fCursor
)
405 CURSORICONINFO
*pInfo
;
406 BITMAPOBJ
*bmpXor
, *bmpAnd
;
407 HBITMAP16 hXorBits
, hAndBits
;
409 int sizeXor
, sizeAnd
;
413 if ((id
>= OCR_FIRST1
) && (id
<= OCR_LAST1
))
414 id
= OCR_BASE1
+ id
- OCR_FIRST1
;
415 else if ((id
>= OCR_FIRST2
) && (id
<= OCR_LAST2
))
416 id
= OCR_BASE2
+ id
- OCR_FIRST2
;
417 else if ((id
>= OCR_FIRST0
) && (id
<= OCR_LAST0
))
418 id
= OCR_BASE0
+ id
- OCR_FIRST0
;
420 if (OBM_Cursors
[id
]) return OBM_Cursors
[id
];
424 if ((id
< OIC_FIRST
) || (id
> OIC_LAST
)) return 0;
428 if (!OBM_InitColorSymbols()) return 0;
430 if (!CallTo32_LargeStack( (int(*)())OBM_CreateBitmaps
, 5,
431 fCursor
? OBM_Cursors_Data
[id
] : OBM_Icons_Data
[id
],
432 !fCursor
, &hXorBits
, &hAndBits
, &hotspot
))
434 fprintf( stderr
, "Error creating OEM cursor/icon %d\n", id
);
438 bmpXor
= (BITMAPOBJ
*) GDI_GetObjPtr( hXorBits
, BITMAP_MAGIC
);
439 bmpAnd
= (BITMAPOBJ
*) GDI_GetObjPtr( hAndBits
, BITMAP_MAGIC
);
440 sizeXor
= bmpXor
->bitmap
.bmHeight
* bmpXor
->bitmap
.bmWidthBytes
;
441 sizeAnd
= bmpXor
->bitmap
.bmHeight
* BITMAP_WIDTH_BYTES( bmpXor
->bitmap
.bmWidth
, 1 );
443 if (!(handle
= GlobalAlloc16( GMEM_MOVEABLE
,
444 sizeof(CURSORICONINFO
) + sizeXor
+ sizeAnd
)))
446 DeleteObject( hXorBits
);
447 DeleteObject( hAndBits
);
451 pInfo
= (CURSORICONINFO
*)GlobalLock16( handle
);
452 pInfo
->ptHotSpot
.x
= hotspot
.x
;
453 pInfo
->ptHotSpot
.y
= hotspot
.y
;
454 pInfo
->nWidth
= bmpXor
->bitmap
.bmWidth
;
455 pInfo
->nHeight
= bmpXor
->bitmap
.bmHeight
;
456 pInfo
->nWidthBytes
= bmpXor
->bitmap
.bmWidthBytes
;
457 pInfo
->bPlanes
= bmpXor
->bitmap
.bmPlanes
;
458 pInfo
->bBitsPerPixel
= bmpXor
->bitmap
.bmBitsPixel
;
462 /* Invert the mask */
464 XSetFunction( display
, BITMAP_monoGC
, GXinvert
);
465 XFillRectangle( display
, bmpAnd
->pixmap
, BITMAP_monoGC
, 0, 0,
466 bmpAnd
->bitmap
.bmWidth
, bmpAnd
->bitmap
.bmHeight
);
467 XSetFunction( display
, BITMAP_monoGC
, GXcopy
);
469 /* Set the masked pixels to black */
471 if (bmpXor
->bitmap
.bmBitsPixel
!= 1)
473 XSetForeground( display
, BITMAP_colorGC
,
474 COLOR_ToPhysical( NULL
, RGB(0,0,0) ));
475 XSetBackground( display
, BITMAP_colorGC
, 0 );
476 XSetFunction( display
, BITMAP_colorGC
, GXor
);
477 XCopyPlane(display
, bmpAnd
->pixmap
, bmpXor
->pixmap
, BITMAP_colorGC
,
478 0, 0, bmpXor
->bitmap
.bmWidth
, bmpXor
->bitmap
.bmHeight
,
480 XSetFunction( display
, BITMAP_colorGC
, GXcopy
);
484 if (hAndBits
) GetBitmapBits( hAndBits
, sizeAnd
, (char *)(pInfo
+ 1) );
485 else memset( (char *)(pInfo
+ 1), 0xff, sizeAnd
);
486 GetBitmapBits( hXorBits
, sizeXor
, (char *)(pInfo
+ 1) + sizeAnd
);
488 DeleteObject( hXorBits
);
489 DeleteObject( hAndBits
);
491 if (fCursor
) OBM_Cursors
[id
] = handle
;