2 * GDI OEM bitmap objects
4 * Copyright 1994, 1995 Alexandre Julliard
11 #include <X11/Xutil.h>
17 #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"
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"
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"
73 #define OBM_FIRST OBM_TRTYPE /* First OEM bitmap */
74 #define OBM_LAST OBM_OLD_CLOSE /* Last OEM bitmap */
78 char** data
; /* Pointer to bitmap data */
79 BOOL32 color
; /* Is it a color bitmap? */
80 } OBM_Pixmaps_Data
[OBM_LAST
-OBM_FIRST
+1] = {
81 { obm_trtype
, TRUE
}, /* OBM_TRTYPE */
82 { obm_cdrom
, TRUE
}, /* OBM_CDROM */
83 { obm_harddisk
, TRUE
}, /* OBM_HARDDISK */
84 { obm_drive
, TRUE
}, /* OBM_DRIVE */
85 { obm_folder2
, TRUE
}, /* OBM_FOLDER2 */
86 { obm_folder
, TRUE
}, /* OBM_FOLDER */
87 { obm_lfarrowi
, TRUE
}, /* OBM_LFARROWI */
88 { obm_rgarrowi
, TRUE
}, /* OBM_RGARROWI */
89 { obm_dnarrowi
, TRUE
}, /* OBM_DNARROWI */
90 { obm_uparrowi
, TRUE
}, /* OBM_UPARROWI */
91 { obm_combo
, FALSE
}, /* OBM_COMBO */
92 { obm_mnarrow
, FALSE
}, /* OBM_MNARROW */
93 { obm_lfarrowd
, TRUE
}, /* OBM_LFARROWD */
94 { obm_rgarrowd
, TRUE
}, /* OBM_RGARROWD */
95 { obm_dnarrowd
, TRUE
}, /* OBM_DNARROWD */
96 { obm_uparrowd
, TRUE
}, /* OBM_UPARROWD */
97 { obm_restored
, TRUE
}, /* OBM_RESTORED */
98 { obm_zoomd
, TRUE
}, /* OBM_ZOOMD */
99 { obm_reduced
, TRUE
}, /* OBM_REDUCED */
100 { obm_restore
, TRUE
}, /* OBM_RESTORE */
101 { obm_zoom
, TRUE
}, /* OBM_ZOOM */
102 { obm_reduce
, TRUE
}, /* OBM_REDUCE */
103 { obm_lfarrow
, TRUE
}, /* OBM_LFARROW */
104 { obm_rgarrow
, TRUE
}, /* OBM_RGARROW */
105 { obm_dnarrow
, TRUE
}, /* OBM_DNARROW */
106 { obm_uparrow
, TRUE
}, /* OBM_UPARROW */
107 { obm_close
, TRUE
}, /* OBM_CLOSE */
108 { obm_old_restore
, FALSE
}, /* OBM_OLD_RESTORE */
109 { obm_old_zoom
, FALSE
}, /* OBM_OLD_ZOOM */
110 { obm_old_reduce
, FALSE
}, /* OBM_OLD_REDUCE */
111 { obm_btncorners
, FALSE
}, /* OBM_BTNCORNERS */
112 { obm_checkboxes
, FALSE
}, /* OBM_CHECKBOXES */
113 { obm_check
, FALSE
}, /* OBM_CHECK */
114 { obm_btsize
, FALSE
}, /* OBM_BTSIZE */
115 { obm_old_lfarrow
, FALSE
}, /* OBM_OLD_LFARROW */
116 { obm_old_rgarrow
, FALSE
}, /* OBM_OLD_RGARROW */
117 { obm_old_dnarrow
, FALSE
}, /* OBM_OLD_DNARROW */
118 { obm_old_uparrow
, FALSE
}, /* OBM_OLD_UPARROW */
119 { obm_size
, FALSE
}, /* OBM_SIZE */
120 { obm_old_close
, FALSE
}, /* OBM_OLD_CLOSE */
124 /* Include OEM icons */
125 #include "bitmaps/oic_sample"
126 #include "bitmaps/oic_hand"
127 #include "bitmaps/oic_ques"
128 #include "bitmaps/oic_bang"
129 #include "bitmaps/oic_note"
130 #include "bitmaps/oic_portrait"
131 #include "bitmaps/oic_landscape"
132 #include "bitmaps/oic_wineicon"
134 #define OIC_FIRST OIC_SAMPLE /* First OEM icon */
135 #define OIC_LAST OIC_WINEICON /* Last OEM icon */
137 static char ** const OBM_Icons_Data
[OIC_LAST
-OIC_FIRST
+1] =
139 oic_sample
, /* OIC_SAMPLE */
140 oic_hand
, /* OIC_HAND */
141 oic_ques
, /* OIC_QUES */
142 oic_bang
, /* OIC_BANG */
143 oic_note
, /* OIC_NOTE */
144 oic_portrait
, /* OIC_PORTRAIT */
145 oic_landscape
, /* OIC_LANDSCAPE */
146 oic_wineicon
/* OIC_WINEICON */
150 /* Include OEM cursors */
151 #include "bitmaps/ocr_normal"
152 #include "bitmaps/ocr_ibeam"
153 #include "bitmaps/ocr_wait"
154 #include "bitmaps/ocr_cross"
155 #include "bitmaps/ocr_up"
156 #include "bitmaps/ocr_size"
157 #include "bitmaps/ocr_icon"
158 #include "bitmaps/ocr_sizenwse"
159 #include "bitmaps/ocr_sizenesw"
160 #include "bitmaps/ocr_sizewe"
161 #include "bitmaps/ocr_sizens"
162 #include "bitmaps/ocr_bummer"
163 #include "bitmaps/ocr_dragobject"
164 /*#include "bitmaps/ocr_sizeall"*/
165 /*#include "bitmaps/ocr_icocur"*/
167 /* Cursor are not all contiguous (go figure...) */
168 #define OCR_FIRST0 OCR_BUMMER
169 #define OCR_LAST0 OCR_DRAGOBJECT
172 #define OCR_FIRST1 OCR_NORMAL
173 #define OCR_LAST1 OCR_UP
174 #define OCR_BASE1 (OCR_BASE0 + OCR_LAST0 - OCR_FIRST0 + 1)
176 #define OCR_FIRST2 OCR_SIZE
177 #define OCR_LAST2 OCR_SIZENS
178 #define OCR_BASE2 (OCR_BASE1 + OCR_LAST1 - OCR_FIRST1 + 1)
180 #define NB_CURSORS (OCR_BASE2 + OCR_LAST2 - OCR_FIRST2 + 1)
181 static char **OBM_Cursors_Data
[NB_CURSORS
] =
183 ocr_bummer
, /* OCR_BUMMER */
184 ocr_dragobject
,/* OCR_DRAGOBJECT */
185 ocr_normal
, /* OCR_NORMAL */
186 ocr_ibeam
, /* OCR_IBEAM */
187 ocr_wait
, /* OCR_WAIT */
188 ocr_cross
, /* OCR_CROSS */
190 ocr_size
, /* OCR_SIZE */
191 ocr_icon
, /* OCR_ICON */
192 ocr_sizenwse
, /* OCR_SIZENWSE */
193 ocr_sizenesw
, /* OCR_SIZENESW */
194 ocr_sizewe
, /* OCR_SIZEWE */
195 ocr_sizens
/* OCR_SIZENS */
197 ocr_sizeall
, /* OCR_SIZEALL */
198 ocr_icocur
/* OCR_ICOCUR */
202 static HGLOBAL16 OBM_Cursors
[NB_CURSORS
];
205 /* All the colors used in the xpm files must be included in this */
206 /* list, to make sure that the loaded bitmaps only use colors from */
207 /* the Windows colormap. Note: the PALETTEINDEX() are not really */
208 /* palette indexes, but system colors that will be converted to */
209 /* indexes later on. */
215 } OBM_SymbolicColors
[] =
217 { "black", RGB(0,0,0) },
218 { "white", RGB(255,255,255) },
219 { "red", RGB(255,0,0) },
220 { "green", RGB(0,255,0) },
221 { "blue", RGB(0,0,255) },
222 { "yellow", RGB(255,255,0) },
223 { "cyan", RGB(0,255,255) },
224 { "dkyellow", RGB(128,128,0) },
225 { "purple", RGB(128,0,128) },
226 { "ltgray", RGB(192,192,192) },
227 { "dkgray", RGB(128,128,128) },
228 { "foldercol", RGB(0,191,191) },
229 { "button_face", PALETTEINDEX(COLOR_BTNFACE
) },
230 { "button_shadow", PALETTEINDEX(COLOR_BTNSHADOW
) },
231 { "button_highlight", PALETTEINDEX(COLOR_BTNHIGHLIGHT
) },
232 { "button_edge", PALETTEINDEX(COLOR_BTNHIGHLIGHT
) },
233 { "button_text", PALETTEINDEX(COLOR_BTNTEXT
) },
234 { "window_frame", PALETTEINDEX(COLOR_WINDOWFRAME
) }
237 #define NB_COLOR_SYMBOLS \
238 (sizeof(OBM_SymbolicColors)/sizeof(OBM_SymbolicColors[0]))
240 /* These are the symbolic colors for monochrome bitmaps */
241 /* This is needed to make sure that black is always 0 and */
242 /* white always 1, as required by Windows. */
244 static XpmColorSymbol OBM_BlackAndWhite
[2] =
246 { "black", NULL
, 0 },
247 { "white", NULL
, 0xffffffff }
250 static XpmColorSymbol
*OBM_Colors
= NULL
;
253 /***********************************************************************
254 * OBM_InitColorSymbols
256 static BOOL32
OBM_InitColorSymbols()
260 if (OBM_Colors
) return TRUE
; /* Already initialised */
262 OBM_Colors
= (XpmColorSymbol
*) malloc( sizeof(XpmColorSymbol
) *
264 if (!OBM_Colors
) return FALSE
;
265 for (i
= 0; i
< NB_COLOR_SYMBOLS
; i
++)
267 OBM_Colors
[i
].name
= OBM_SymbolicColors
[i
].name
;
268 OBM_Colors
[i
].value
= NULL
;
269 if (OBM_SymbolicColors
[i
].color
& 0xff000000) /* PALETTEINDEX */
270 OBM_Colors
[i
].pixel
= COLOR_ToPhysical( NULL
,
271 GetSysColor32(OBM_SymbolicColors
[i
].color
& 0xff));
273 OBM_Colors
[i
].pixel
= COLOR_ToPhysical( NULL
,
274 OBM_SymbolicColors
[i
].color
);
280 /***********************************************************************
283 * Allocate a GDI bitmap.
285 static HBITMAP16
OBM_MakeBitmap( WORD width
, WORD height
,
286 WORD bpp
, Pixmap pixmap
)
289 BITMAPOBJ
* bmpObjPtr
;
291 if (!pixmap
) return 0;
293 hbitmap
= GDI_AllocObject( sizeof(BITMAPOBJ
), BITMAP_MAGIC
);
294 if (!hbitmap
) return 0;
296 bmpObjPtr
= (BITMAPOBJ
*) GDI_HEAP_LIN_ADDR( hbitmap
);
297 bmpObjPtr
->size
.cx
= width
;
298 bmpObjPtr
->size
.cy
= height
;
299 bmpObjPtr
->pixmap
= pixmap
;
300 bmpObjPtr
->bitmap
.bmType
= 0;
301 bmpObjPtr
->bitmap
.bmWidth
= width
;
302 bmpObjPtr
->bitmap
.bmHeight
= height
;
303 bmpObjPtr
->bitmap
.bmWidthBytes
= BITMAP_WIDTH_BYTES( width
, bpp
);
304 bmpObjPtr
->bitmap
.bmPlanes
= 1;
305 bmpObjPtr
->bitmap
.bmBitsPixel
= bpp
;
306 bmpObjPtr
->bitmap
.bmBits
= NULL
;
311 /***********************************************************************
314 * Create the 2 bitmaps from XPM data.
316 static BOOL32
OBM_CreateBitmaps( char **data
, BOOL32 color
, HBITMAP16
*hBitmap
,
317 HBITMAP16
*hBitmapMask
, POINT32
*hotspot
)
319 Pixmap pixmap
, pixmask
;
320 XpmAttributes
*attrs
;
323 attrs
= (XpmAttributes
*)xmalloc( XpmAttributesSize() );
324 attrs
->valuemask
= XpmColormap
| XpmDepth
| XpmColorSymbols
|XpmHotspot
;
325 attrs
->colormap
= COLOR_GetColormap();
326 attrs
->depth
= color
? screenDepth
: 1;
327 attrs
->colorsymbols
= (attrs
->depth
> 1) ? OBM_Colors
: OBM_BlackAndWhite
;
328 attrs
->numsymbols
= (attrs
->depth
> 1) ? NB_COLOR_SYMBOLS
: 2;
330 err
= XpmCreatePixmapFromData( display
, rootWindow
, data
,
331 &pixmap
, &pixmask
, attrs
);
333 if (err
!= XpmSuccess
)
340 hotspot
->x
= attrs
->x_hotspot
;
341 hotspot
->y
= attrs
->y_hotspot
;
343 *hBitmap
= OBM_MakeBitmap( attrs
->width
, attrs
->height
,
344 attrs
->depth
, pixmap
);
345 if (hBitmapMask
) *hBitmapMask
= OBM_MakeBitmap(attrs
->width
, attrs
->height
,
350 if (pixmap
) XFreePixmap( display
, pixmap
);
351 if (pixmask
) XFreePixmap( display
, pixmask
);
352 if (*hBitmap
) GDI_FreeObject( *hBitmap
);
353 if (hBitmapMask
&& *hBitmapMask
) GDI_FreeObject( *hBitmapMask
);
360 /***********************************************************************
363 HBITMAP16
OBM_LoadBitmap( WORD id
)
367 if ((id
< OBM_FIRST
) || (id
> OBM_LAST
)) return 0;
370 if (!OBM_InitColorSymbols()) return 0;
372 if (!CallTo32_LargeStack( (int(*)())OBM_CreateBitmaps
, 5,
373 OBM_Pixmaps_Data
[id
].data
,
374 OBM_Pixmaps_Data
[id
].color
,
375 &hbitmap
, NULL
, NULL
))
377 fprintf( stderr
, "Error creating OEM bitmap %d\n", OBM_FIRST
+id
);
384 /***********************************************************************
387 HGLOBAL16
OBM_LoadCursorIcon( WORD id
, BOOL32 fCursor
)
390 CURSORICONINFO
*pInfo
;
391 BITMAPOBJ
*bmpXor
, *bmpAnd
;
392 HBITMAP16 hXorBits
, hAndBits
;
394 int sizeXor
, sizeAnd
;
398 if ((id
>= OCR_FIRST1
) && (id
<= OCR_LAST1
))
399 id
= OCR_BASE1
+ id
- OCR_FIRST1
;
400 else if ((id
>= OCR_FIRST2
) && (id
<= OCR_LAST2
))
401 id
= OCR_BASE2
+ id
- OCR_FIRST2
;
402 else if ((id
>= OCR_FIRST0
) && (id
<= OCR_LAST0
))
403 id
= OCR_BASE0
+ id
- OCR_FIRST0
;
405 if (OBM_Cursors
[id
]) return OBM_Cursors
[id
];
409 if ((id
< OIC_FIRST
) || (id
> OIC_LAST
)) return 0;
413 if (!OBM_InitColorSymbols()) return 0;
415 if (!CallTo32_LargeStack( (int(*)())OBM_CreateBitmaps
, 5,
416 fCursor
? OBM_Cursors_Data
[id
] : OBM_Icons_Data
[id
],
417 !fCursor
, &hXorBits
, &hAndBits
, &hotspot
))
419 fprintf( stderr
, "Error creating OEM cursor/icon %d\n", id
);
423 bmpXor
= (BITMAPOBJ
*) GDI_GetObjPtr( hXorBits
, BITMAP_MAGIC
);
424 bmpAnd
= (BITMAPOBJ
*) GDI_GetObjPtr( hAndBits
, BITMAP_MAGIC
);
425 sizeXor
= bmpXor
->bitmap
.bmHeight
* bmpXor
->bitmap
.bmWidthBytes
;
426 sizeAnd
= bmpXor
->bitmap
.bmHeight
* BITMAP_WIDTH_BYTES( bmpXor
->bitmap
.bmWidth
, 1 );
428 if (!(handle
= GlobalAlloc16( GMEM_MOVEABLE
,
429 sizeof(CURSORICONINFO
) + sizeXor
+ sizeAnd
)))
431 DeleteObject32( hXorBits
);
432 DeleteObject32( hAndBits
);
436 pInfo
= (CURSORICONINFO
*)GlobalLock16( handle
);
437 pInfo
->ptHotSpot
.x
= hotspot
.x
;
438 pInfo
->ptHotSpot
.y
= hotspot
.y
;
439 pInfo
->nWidth
= bmpXor
->bitmap
.bmWidth
;
440 pInfo
->nHeight
= bmpXor
->bitmap
.bmHeight
;
441 pInfo
->nWidthBytes
= bmpXor
->bitmap
.bmWidthBytes
;
442 pInfo
->bPlanes
= bmpXor
->bitmap
.bmPlanes
;
443 pInfo
->bBitsPerPixel
= bmpXor
->bitmap
.bmBitsPixel
;
447 /* Invert the mask */
449 XSetFunction( display
, BITMAP_monoGC
, GXinvert
);
450 XFillRectangle( display
, bmpAnd
->pixmap
, BITMAP_monoGC
, 0, 0,
451 bmpAnd
->bitmap
.bmWidth
, bmpAnd
->bitmap
.bmHeight
);
452 XSetFunction( display
, BITMAP_monoGC
, GXcopy
);
454 /* Set the masked pixels to black */
456 if (bmpXor
->bitmap
.bmBitsPixel
!= 1)
458 XSetForeground( display
, BITMAP_colorGC
,
459 COLOR_ToPhysical( NULL
, RGB(0,0,0) ));
460 XSetBackground( display
, BITMAP_colorGC
, 0 );
461 XSetFunction( display
, BITMAP_colorGC
, GXor
);
462 XCopyPlane(display
, bmpAnd
->pixmap
, bmpXor
->pixmap
, BITMAP_colorGC
,
463 0, 0, bmpXor
->bitmap
.bmWidth
, bmpXor
->bitmap
.bmHeight
,
465 XSetFunction( display
, BITMAP_colorGC
, GXcopy
);
469 if (hAndBits
) GetBitmapBits32( hAndBits
, sizeAnd
, (char *)(pInfo
+ 1) );
470 else memset( (char *)(pInfo
+ 1), 0xff, sizeAnd
);
471 GetBitmapBits32( hXorBits
, sizeXor
, (char *)(pInfo
+ 1) + sizeAnd
);
473 DeleteObject32( hXorBits
);
474 DeleteObject32( hAndBits
);
476 if (fCursor
) OBM_Cursors
[id
] = handle
;
481 /***********************************************************************
484 * Initializes the OBM_Pixmaps_Data struct
488 if(TWEAK_Win95Look
) {
489 OBM_Pixmaps_Data
[OBM_ZOOMD
- OBM_FIRST
].data
= obm_zoomd_95
;
490 OBM_Pixmaps_Data
[OBM_REDUCED
- OBM_FIRST
].data
= obm_reduced_95
;
491 OBM_Pixmaps_Data
[OBM_ZOOM
- OBM_FIRST
].data
= obm_zoom_95
;
492 OBM_Pixmaps_Data
[OBM_REDUCE
- OBM_FIRST
].data
= obm_reduce_95
;
493 OBM_Pixmaps_Data
[OBM_CLOSE
- OBM_FIRST
].data
= obm_close_95
;
496 OBM_Pixmaps_Data
[OBM_ZOOMD
- OBM_FIRST
].data
= obm_zoomd
;
497 OBM_Pixmaps_Data
[OBM_REDUCED
- OBM_FIRST
].data
= obm_reduced
;
498 OBM_Pixmaps_Data
[OBM_ZOOM
- OBM_FIRST
].data
= obm_zoom
;
499 OBM_Pixmaps_Data
[OBM_REDUCE
- OBM_FIRST
].data
= obm_reduce
;
500 OBM_Pixmaps_Data
[OBM_CLOSE
- OBM_FIRST
].data
= obm_close
;