2 * GDI OEM bitmap objects
4 * Copyright 1994, 1995 Alexandre Julliard
8 #define NO_TRANSITION_TYPES /* This file is Win32-clean */
12 #include <X11/Xutil.h>
18 #include "cursoricon.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"
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"
67 #include "bitmaps/obm_zoomd_95"
68 #include "bitmaps/obm_reduced_95"
69 #include "bitmaps/obm_zoom_95"
70 #include "bitmaps/obm_reduce_95"
71 #include "bitmaps/obm_close_95"
72 #include "bitmaps/obm_closed_95"
73 #endif /* WIN_95_LOOK */
75 #define OBM_FIRST OBM_TRTYPE /* First OEM bitmap */
76 #define OBM_LAST OBM_OLD_CLOSE /* Last OEM bitmap */
80 char** data
; /* Pointer to bitmap data */
81 BOOL32 color
; /* Is it a color bitmap? */
82 } OBM_Pixmaps_Data
[OBM_LAST
-OBM_FIRST
+1] = {
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 */
101 { obm_zoomd_95
, TRUE
}, /* OBM_ZOOMD */
102 { obm_reduced_95
, TRUE
}, /* OBM_REDUCED */
104 { obm_zoomd
, TRUE
}, /* OBM_ZOOMD */
105 { obm_reduced
, TRUE
}, /* OBM_REDUCED */
107 { obm_restore
, TRUE
}, /* OBM_RESTORE */
109 { obm_zoom_95
, TRUE
}, /* OBM_ZOOM */
110 { obm_reduce_95
, TRUE
}, /* OBM_REDUCE */
112 { obm_zoom
, TRUE
}, /* OBM_ZOOM */
113 { obm_reduce
, TRUE
}, /* OBM_REDUCE */
115 { obm_lfarrow
, TRUE
}, /* OBM_LFARROW */
116 { obm_rgarrow
, TRUE
}, /* OBM_RGARROW */
117 { obm_dnarrow
, TRUE
}, /* OBM_DNARROW */
118 { obm_uparrow
, TRUE
}, /* OBM_UPARROW */
120 { obm_close_95
, TRUE
}, /* OBM_CLOSE */
122 { obm_close
, TRUE
}, /* OBM_CLOSE */
124 { obm_old_restore
, FALSE
}, /* OBM_OLD_RESTORE */
125 { obm_old_zoom
, FALSE
}, /* OBM_OLD_ZOOM */
126 { obm_old_reduce
, FALSE
}, /* OBM_OLD_REDUCE */
127 { obm_btncorners
, FALSE
}, /* OBM_BTNCORNERS */
128 { obm_checkboxes
, FALSE
}, /* OBM_CHECKBOXES */
129 { obm_check
, FALSE
}, /* OBM_CHECK */
130 { obm_btsize
, FALSE
}, /* OBM_BTSIZE */
131 { obm_old_lfarrow
, FALSE
}, /* OBM_OLD_LFARROW */
132 { obm_old_rgarrow
, FALSE
}, /* OBM_OLD_RGARROW */
133 { obm_old_dnarrow
, FALSE
}, /* OBM_OLD_DNARROW */
134 { obm_old_uparrow
, FALSE
}, /* OBM_OLD_UPARROW */
135 { obm_size
, FALSE
}, /* OBM_SIZE */
136 { obm_old_close
, FALSE
}, /* OBM_OLD_CLOSE */
140 /* Include OEM icons */
141 #include "bitmaps/oic_sample"
142 #include "bitmaps/oic_hand"
143 #include "bitmaps/oic_ques"
144 #include "bitmaps/oic_bang"
145 #include "bitmaps/oic_note"
146 #include "bitmaps/oic_portrait"
147 #include "bitmaps/oic_landscape"
148 #include "bitmaps/oic_wineicon"
150 #define OIC_FIRST OIC_SAMPLE /* First OEM icon */
151 #define OIC_LAST OIC_WINEICON /* Last OEM icon */
153 static char ** const OBM_Icons_Data
[OIC_LAST
-OIC_FIRST
+1] =
155 oic_sample
, /* OIC_SAMPLE */
156 oic_hand
, /* OIC_HAND */
157 oic_ques
, /* OIC_QUES */
158 oic_bang
, /* OIC_BANG */
159 oic_note
, /* OIC_NOTE */
160 oic_portrait
, /* OIC_PORTRAIT */
161 oic_landscape
, /* OIC_LANDSCAPE */
162 oic_wineicon
/* OIC_WINEICON */
166 /* Include OEM cursors */
167 #include "bitmaps/ocr_normal"
168 #include "bitmaps/ocr_ibeam"
169 #include "bitmaps/ocr_wait"
170 #include "bitmaps/ocr_cross"
171 #include "bitmaps/ocr_up"
172 #include "bitmaps/ocr_size"
173 #include "bitmaps/ocr_icon"
174 #include "bitmaps/ocr_sizenwse"
175 #include "bitmaps/ocr_sizenesw"
176 #include "bitmaps/ocr_sizewe"
177 #include "bitmaps/ocr_sizens"
178 #include "bitmaps/ocr_bummer"
179 #include "bitmaps/ocr_dragobject"
180 /*#include "bitmaps/ocr_sizeall"*/
181 /*#include "bitmaps/ocr_icocur"*/
183 /* Cursor are not all contiguous (go figure...) */
184 #define OCR_FIRST0 OCR_BUMMER
185 #define OCR_LAST0 OCR_DRAGOBJECT
188 #define OCR_FIRST1 OCR_NORMAL
189 #define OCR_LAST1 OCR_UP
190 #define OCR_BASE1 (OCR_BASE0 + OCR_LAST0 - OCR_FIRST0 + 1)
192 #define OCR_FIRST2 OCR_SIZE
193 #define OCR_LAST2 OCR_SIZENS
194 #define OCR_BASE2 (OCR_BASE1 + OCR_LAST1 - OCR_FIRST1 + 1)
196 #define NB_CURSORS (OCR_BASE2 + OCR_LAST2 - OCR_FIRST2 + 1)
197 static char **OBM_Cursors_Data
[NB_CURSORS
] =
199 ocr_bummer
, /* OCR_BUMMER */
200 ocr_dragobject
,/* OCR_DRAGOBJECT */
201 ocr_normal
, /* OCR_NORMAL */
202 ocr_ibeam
, /* OCR_IBEAM */
203 ocr_wait
, /* OCR_WAIT */
204 ocr_cross
, /* OCR_CROSS */
206 ocr_size
, /* OCR_SIZE */
207 ocr_icon
, /* OCR_ICON */
208 ocr_sizenwse
, /* OCR_SIZENWSE */
209 ocr_sizenesw
, /* OCR_SIZENESW */
210 ocr_sizewe
, /* OCR_SIZEWE */
211 ocr_sizens
/* OCR_SIZENS */
213 ocr_sizeall
, /* OCR_SIZEALL */
214 ocr_icocur
/* OCR_ICOCUR */
218 static HGLOBAL16 OBM_Cursors
[NB_CURSORS
];
221 /* All the colors used in the xpm files must be included in this */
222 /* list, to make sure that the loaded bitmaps only use colors from */
223 /* the Windows colormap. Note: the PALETTEINDEX() are not really */
224 /* palette indexes, but system colors that will be converted to */
225 /* indexes later on. */
231 } OBM_SymbolicColors
[] =
233 { "black", RGB(0,0,0) },
234 { "white", RGB(255,255,255) },
235 { "red", RGB(255,0,0) },
236 { "green", RGB(0,255,0) },
237 { "blue", RGB(0,0,255) },
238 { "yellow", RGB(255,255,0) },
239 { "cyan", RGB(0,255,255) },
240 { "dkyellow", RGB(128,128,0) },
241 { "purple", RGB(128,0,128) },
242 { "ltgray", RGB(192,192,192) },
243 { "dkgray", RGB(128,128,128) },
244 { "foldercol", RGB(0,191,191) },
245 { "button_face", PALETTEINDEX(COLOR_BTNFACE
) },
246 { "button_shadow", PALETTEINDEX(COLOR_BTNSHADOW
) },
247 { "button_highlight", PALETTEINDEX(COLOR_BTNHIGHLIGHT
) },
248 { "button_edge", PALETTEINDEX(COLOR_BTNHIGHLIGHT
) },
249 { "button_text", PALETTEINDEX(COLOR_BTNTEXT
) },
250 { "window_frame", PALETTEINDEX(COLOR_WINDOWFRAME
) }
253 #define NB_COLOR_SYMBOLS \
254 (sizeof(OBM_SymbolicColors)/sizeof(OBM_SymbolicColors[0]))
256 /* These are the symbolic colors for monochrome bitmaps */
257 /* This is needed to make sure that black is always 0 and */
258 /* white always 1, as required by Windows. */
260 static XpmColorSymbol OBM_BlackAndWhite
[2] =
262 { "black", NULL
, 0 },
263 { "white", NULL
, 0xffffffff }
266 static XpmColorSymbol
*OBM_Colors
= NULL
;
269 /***********************************************************************
270 * OBM_InitColorSymbols
272 static BOOL32
OBM_InitColorSymbols()
276 if (OBM_Colors
) return TRUE
; /* Already initialised */
278 OBM_Colors
= (XpmColorSymbol
*) malloc( sizeof(XpmColorSymbol
) *
280 if (!OBM_Colors
) return FALSE
;
281 for (i
= 0; i
< NB_COLOR_SYMBOLS
; i
++)
283 OBM_Colors
[i
].name
= OBM_SymbolicColors
[i
].name
;
284 OBM_Colors
[i
].value
= NULL
;
285 if (OBM_SymbolicColors
[i
].color
& 0xff000000) /* PALETTEINDEX */
286 OBM_Colors
[i
].pixel
= COLOR_ToPhysical( NULL
,
287 GetSysColor(OBM_SymbolicColors
[i
].color
& 0xff));
289 OBM_Colors
[i
].pixel
= COLOR_ToPhysical( NULL
,
290 OBM_SymbolicColors
[i
].color
);
296 /***********************************************************************
299 * Allocate a GDI bitmap.
301 static HBITMAP16
OBM_MakeBitmap( WORD width
, WORD height
,
302 WORD bpp
, Pixmap pixmap
)
305 BITMAPOBJ
* bmpObjPtr
;
307 if (!pixmap
) return 0;
309 hbitmap
= GDI_AllocObject( sizeof(BITMAPOBJ
), BITMAP_MAGIC
);
310 if (!hbitmap
) return 0;
312 bmpObjPtr
= (BITMAPOBJ
*) GDI_HEAP_LIN_ADDR( hbitmap
);
313 bmpObjPtr
->size
.cx
= 0;
314 bmpObjPtr
->size
.cy
= 0;
315 bmpObjPtr
->pixmap
= pixmap
;
316 bmpObjPtr
->bitmap
.bmType
= 0;
317 bmpObjPtr
->bitmap
.bmWidth
= width
;
318 bmpObjPtr
->bitmap
.bmHeight
= height
;
319 bmpObjPtr
->bitmap
.bmWidthBytes
= BITMAP_WIDTH_BYTES( width
, bpp
);
320 bmpObjPtr
->bitmap
.bmPlanes
= 1;
321 bmpObjPtr
->bitmap
.bmBitsPixel
= bpp
;
322 bmpObjPtr
->bitmap
.bmBits
= NULL
;
327 /***********************************************************************
330 * Create the 2 bitmaps from XPM data.
332 static BOOL32
OBM_CreateBitmaps( char **data
, BOOL32 color
, HBITMAP16
*hBitmap
,
333 HBITMAP16
*hBitmapMask
, POINT32
*hotspot
)
335 Pixmap pixmap
, pixmask
;
336 XpmAttributes
*attrs
;
339 attrs
= (XpmAttributes
*)xmalloc( XpmAttributesSize() );
340 attrs
->valuemask
= XpmColormap
| XpmDepth
| XpmColorSymbols
|XpmHotspot
;
341 attrs
->colormap
= COLOR_GetColormap();
342 attrs
->depth
= color
? screenDepth
: 1;
343 attrs
->colorsymbols
= (attrs
->depth
> 1) ? OBM_Colors
: OBM_BlackAndWhite
;
344 attrs
->numsymbols
= (attrs
->depth
> 1) ? NB_COLOR_SYMBOLS
: 2;
346 err
= XpmCreatePixmapFromData( display
, rootWindow
, data
,
347 &pixmap
, &pixmask
, attrs
);
349 if (err
!= XpmSuccess
)
356 hotspot
->x
= attrs
->x_hotspot
;
357 hotspot
->y
= attrs
->y_hotspot
;
359 *hBitmap
= OBM_MakeBitmap( attrs
->width
, attrs
->height
,
360 attrs
->depth
, pixmap
);
361 if (hBitmapMask
) *hBitmapMask
= OBM_MakeBitmap(attrs
->width
, attrs
->height
,
366 if (pixmap
) XFreePixmap( display
, pixmap
);
367 if (pixmask
) XFreePixmap( display
, pixmask
);
368 if (*hBitmap
) GDI_FreeObject( *hBitmap
);
369 if (hBitmapMask
&& *hBitmapMask
) GDI_FreeObject( *hBitmapMask
);
376 /***********************************************************************
379 HBITMAP16
OBM_LoadBitmap( WORD id
)
383 if ((id
< OBM_FIRST
) || (id
> OBM_LAST
)) return 0;
386 if (!OBM_InitColorSymbols()) return 0;
388 if (!CallTo32_LargeStack( (int(*)())OBM_CreateBitmaps
, 5,
389 OBM_Pixmaps_Data
[id
].data
,
390 OBM_Pixmaps_Data
[id
].color
,
391 &hbitmap
, NULL
, NULL
))
393 fprintf( stderr
, "Error creating OEM bitmap %d\n", OBM_FIRST
+id
);
400 /***********************************************************************
403 HGLOBAL16
OBM_LoadCursorIcon( WORD id
, BOOL32 fCursor
)
406 CURSORICONINFO
*pInfo
;
407 BITMAPOBJ
*bmpXor
, *bmpAnd
;
408 HBITMAP16 hXorBits
, hAndBits
;
410 int sizeXor
, sizeAnd
;
414 if ((id
>= OCR_FIRST1
) && (id
<= OCR_LAST1
))
415 id
= OCR_BASE1
+ id
- OCR_FIRST1
;
416 else if ((id
>= OCR_FIRST2
) && (id
<= OCR_LAST2
))
417 id
= OCR_BASE2
+ id
- OCR_FIRST2
;
418 else if ((id
>= OCR_FIRST0
) && (id
<= OCR_LAST0
))
419 id
= OCR_BASE0
+ id
- OCR_FIRST0
;
421 if (OBM_Cursors
[id
]) return OBM_Cursors
[id
];
425 if ((id
< OIC_FIRST
) || (id
> OIC_LAST
)) return 0;
429 if (!OBM_InitColorSymbols()) return 0;
431 if (!CallTo32_LargeStack( (int(*)())OBM_CreateBitmaps
, 5,
432 fCursor
? OBM_Cursors_Data
[id
] : OBM_Icons_Data
[id
],
433 !fCursor
, &hXorBits
, &hAndBits
, &hotspot
))
435 fprintf( stderr
, "Error creating OEM cursor/icon %d\n", id
);
439 bmpXor
= (BITMAPOBJ
*) GDI_GetObjPtr( hXorBits
, BITMAP_MAGIC
);
440 bmpAnd
= (BITMAPOBJ
*) GDI_GetObjPtr( hAndBits
, BITMAP_MAGIC
);
441 sizeXor
= bmpXor
->bitmap
.bmHeight
* bmpXor
->bitmap
.bmWidthBytes
;
442 sizeAnd
= bmpXor
->bitmap
.bmHeight
* BITMAP_WIDTH_BYTES( bmpXor
->bitmap
.bmWidth
, 1 );
444 if (!(handle
= GlobalAlloc16( GMEM_MOVEABLE
,
445 sizeof(CURSORICONINFO
) + sizeXor
+ sizeAnd
)))
447 DeleteObject32( hXorBits
);
448 DeleteObject32( hAndBits
);
452 pInfo
= (CURSORICONINFO
*)GlobalLock16( handle
);
453 pInfo
->ptHotSpot
.x
= hotspot
.x
;
454 pInfo
->ptHotSpot
.y
= hotspot
.y
;
455 pInfo
->nWidth
= bmpXor
->bitmap
.bmWidth
;
456 pInfo
->nHeight
= bmpXor
->bitmap
.bmHeight
;
457 pInfo
->nWidthBytes
= bmpXor
->bitmap
.bmWidthBytes
;
458 pInfo
->bPlanes
= bmpXor
->bitmap
.bmPlanes
;
459 pInfo
->bBitsPerPixel
= bmpXor
->bitmap
.bmBitsPixel
;
463 /* Invert the mask */
465 XSetFunction( display
, BITMAP_monoGC
, GXinvert
);
466 XFillRectangle( display
, bmpAnd
->pixmap
, BITMAP_monoGC
, 0, 0,
467 bmpAnd
->bitmap
.bmWidth
, bmpAnd
->bitmap
.bmHeight
);
468 XSetFunction( display
, BITMAP_monoGC
, GXcopy
);
470 /* Set the masked pixels to black */
472 if (bmpXor
->bitmap
.bmBitsPixel
!= 1)
474 XSetForeground( display
, BITMAP_colorGC
,
475 COLOR_ToPhysical( NULL
, RGB(0,0,0) ));
476 XSetBackground( display
, BITMAP_colorGC
, 0 );
477 XSetFunction( display
, BITMAP_colorGC
, GXor
);
478 XCopyPlane(display
, bmpAnd
->pixmap
, bmpXor
->pixmap
, BITMAP_colorGC
,
479 0, 0, bmpXor
->bitmap
.bmWidth
, bmpXor
->bitmap
.bmHeight
,
481 XSetFunction( display
, BITMAP_colorGC
, GXcopy
);
485 if (hAndBits
) GetBitmapBits( hAndBits
, sizeAnd
, (char *)(pInfo
+ 1) );
486 else memset( (char *)(pInfo
+ 1), 0xff, sizeAnd
);
487 GetBitmapBits( hXorBits
, sizeXor
, (char *)(pInfo
+ 1) + sizeAnd
);
489 DeleteObject32( hXorBits
);
490 DeleteObject32( hAndBits
);
492 if (fCursor
) OBM_Cursors
[id
] = handle
;