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"
59 #include "bitmaps/obm_radiocheck"
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"
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"
74 #define OBM_FIRST OBM_RADIOCHECK /* First OEM bitmap */
75 #define OBM_LAST OBM_OLD_CLOSE /* Last OEM bitmap */
79 char** data
; /* Pointer to bitmap data */
80 BOOL32 color
; /* Is it a color bitmap? */
81 } OBM_Pixmaps_Data
[OBM_LAST
-OBM_FIRST
+1] = {
82 { obm_radiocheck
, FALSE
}, /* OBM_RADIOCHECK */
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 */
100 { obm_zoomd
, TRUE
}, /* OBM_ZOOMD */
101 { obm_reduced
, TRUE
}, /* OBM_REDUCED */
102 { obm_restore
, TRUE
}, /* OBM_RESTORE */
103 { obm_zoom
, TRUE
}, /* OBM_ZOOM */
104 { obm_reduce
, TRUE
}, /* OBM_REDUCE */
105 { obm_lfarrow
, TRUE
}, /* OBM_LFARROW */
106 { obm_rgarrow
, TRUE
}, /* OBM_RGARROW */
107 { obm_dnarrow
, TRUE
}, /* OBM_DNARROW */
108 { obm_uparrow
, TRUE
}, /* OBM_UPARROW */
109 { obm_close
, TRUE
}, /* OBM_CLOSE */
110 { obm_old_restore
, FALSE
}, /* OBM_OLD_RESTORE */
111 { obm_old_zoom
, FALSE
}, /* OBM_OLD_ZOOM */
112 { obm_old_reduce
, FALSE
}, /* OBM_OLD_REDUCE */
113 { obm_btncorners
, FALSE
}, /* OBM_BTNCORNERS */
114 { obm_checkboxes
, FALSE
}, /* OBM_CHECKBOXES */
115 { obm_check
, FALSE
}, /* OBM_CHECK */
116 { obm_btsize
, FALSE
}, /* OBM_BTSIZE */
117 { obm_old_lfarrow
, FALSE
}, /* OBM_OLD_LFARROW */
118 { obm_old_rgarrow
, FALSE
}, /* OBM_OLD_RGARROW */
119 { obm_old_dnarrow
, FALSE
}, /* OBM_OLD_DNARROW */
120 { obm_old_uparrow
, FALSE
}, /* OBM_OLD_UPARROW */
121 { obm_size
, FALSE
}, /* OBM_SIZE */
122 { obm_old_close
, FALSE
}, /* OBM_OLD_CLOSE */
126 /* Include OEM icons */
127 #include "bitmaps/oic_sample"
128 #include "bitmaps/oic_hand"
129 #include "bitmaps/oic_ques"
130 #include "bitmaps/oic_bang"
131 #include "bitmaps/oic_note"
132 #include "bitmaps/oic_portrait"
133 #include "bitmaps/oic_landscape"
134 #include "bitmaps/oic_wineicon"
136 #define OIC_FIRST OIC_SAMPLE /* First OEM icon */
137 #define OIC_LAST OIC_WINEICON /* Last OEM icon */
139 static char ** const OBM_Icons_Data
[OIC_LAST
-OIC_FIRST
+1] =
141 oic_sample
, /* OIC_SAMPLE */
142 oic_hand
, /* OIC_HAND */
143 oic_ques
, /* OIC_QUES */
144 oic_bang
, /* OIC_BANG */
145 oic_note
, /* OIC_NOTE */
146 oic_portrait
, /* OIC_PORTRAIT */
147 oic_landscape
, /* OIC_LANDSCAPE */
148 oic_wineicon
/* OIC_WINEICON */
152 /* Include OEM cursors */
153 #include "bitmaps/ocr_normal"
154 #include "bitmaps/ocr_ibeam"
155 #include "bitmaps/ocr_wait"
156 #include "bitmaps/ocr_cross"
157 #include "bitmaps/ocr_up"
158 #include "bitmaps/ocr_size"
159 #include "bitmaps/ocr_icon"
160 #include "bitmaps/ocr_sizenwse"
161 #include "bitmaps/ocr_sizenesw"
162 #include "bitmaps/ocr_sizewe"
163 #include "bitmaps/ocr_sizens"
164 #include "bitmaps/ocr_bummer"
165 #include "bitmaps/ocr_dragobject"
166 /*#include "bitmaps/ocr_sizeall"*/
167 /*#include "bitmaps/ocr_icocur"*/
169 /* Cursor are not all contiguous (go figure...) */
170 #define OCR_FIRST0 OCR_BUMMER
171 #define OCR_LAST0 OCR_DRAGOBJECT
174 #define OCR_FIRST1 OCR_NORMAL
175 #define OCR_LAST1 OCR_UP
176 #define OCR_BASE1 (OCR_BASE0 + OCR_LAST0 - OCR_FIRST0 + 1)
178 #define OCR_FIRST2 OCR_SIZE
179 #define OCR_LAST2 OCR_SIZENS
180 #define OCR_BASE2 (OCR_BASE1 + OCR_LAST1 - OCR_FIRST1 + 1)
182 #define NB_CURSORS (OCR_BASE2 + OCR_LAST2 - OCR_FIRST2 + 1)
183 static char **OBM_Cursors_Data
[NB_CURSORS
] =
185 ocr_bummer
, /* OCR_BUMMER */
186 ocr_dragobject
,/* OCR_DRAGOBJECT */
187 ocr_normal
, /* OCR_NORMAL */
188 ocr_ibeam
, /* OCR_IBEAM */
189 ocr_wait
, /* OCR_WAIT */
190 ocr_cross
, /* OCR_CROSS */
192 ocr_size
, /* OCR_SIZE */
193 ocr_icon
, /* OCR_ICON */
194 ocr_sizenwse
, /* OCR_SIZENWSE */
195 ocr_sizenesw
, /* OCR_SIZENESW */
196 ocr_sizewe
, /* OCR_SIZEWE */
197 ocr_sizens
/* OCR_SIZENS */
199 ocr_sizeall
, /* OCR_SIZEALL */
200 ocr_icocur
/* OCR_ICOCUR */
204 static HGLOBAL16 OBM_Cursors
[NB_CURSORS
];
207 /* All the colors used in the xpm files must be included in this */
208 /* list, to make sure that the loaded bitmaps only use colors from */
209 /* the Windows colormap. Note: the PALETTEINDEX() are not really */
210 /* palette indexes, but system colors that will be converted to */
211 /* indexes later on. */
218 } OBM_SymbolicColors
[] =
220 static XpmColorSymbol OBM_Colors
[] =
222 { "black", NULL
, (Pixel
)RGB(0,0,0) },
223 { "white", NULL
, (Pixel
)RGB(255,255,255) },
224 { "red", NULL
, (Pixel
)RGB(255,0,0) },
225 { "green", NULL
, (Pixel
)RGB(0,255,0) },
226 { "blue", NULL
, (Pixel
)RGB(0,0,255) },
227 { "yellow", NULL
, (Pixel
)RGB(255,255,0) },
228 { "cyan", NULL
, (Pixel
)RGB(0,255,255) },
229 { "dkyellow", NULL
, (Pixel
)RGB(128,128,0) },
230 { "purple", NULL
, (Pixel
)RGB(128,0,128) },
231 { "ltgray", NULL
, (Pixel
)RGB(192,192,192) },
232 { "dkgray", NULL
, (Pixel
)RGB(128,128,128) },
233 { "foldercol", NULL
, (Pixel
)RGB(0,191,191) },
234 { "button_face", NULL
, (Pixel
)PALETTEINDEX(COLOR_BTNFACE
) },
235 { "button_shadow", NULL
, (Pixel
)PALETTEINDEX(COLOR_BTNSHADOW
) },
236 { "button_highlight", NULL
, (Pixel
)PALETTEINDEX(COLOR_BTNHIGHLIGHT
) },
237 { "button_edge", NULL
, (Pixel
)PALETTEINDEX(COLOR_BTNHIGHLIGHT
) },
238 { "button_text", NULL
, (Pixel
)PALETTEINDEX(COLOR_BTNTEXT
) },
239 { "window_frame", NULL
, (Pixel
)PALETTEINDEX(COLOR_WINDOWFRAME
) }
242 #define NB_COLOR_SYMBOLS (sizeof(OBM_Colors)/sizeof(OBM_Colors[0]))
244 /* These are the symbolic colors for monochrome bitmaps */
245 /* This is needed to make sure that black is always 0 and */
246 /* white always 1, as required by Windows. */
248 static XpmColorSymbol OBM_BlackAndWhite
[2] =
250 { "black", NULL
, 0 },
251 { "white", NULL
, 0xffffffff }
254 /* This structure holds the arguments for OBM_CreateBitmaps() */
257 char **data
; /* In: bitmap data */
258 BOOL32 color
; /* In: color or monochrome */
259 BOOL32 need_mask
; /* In: do we need a mask? */
260 HBITMAP16 bitmap
; /* Out: resulting bitmap */
261 HBITMAP16 mask
; /* Out: resulting mask (if needed) */
262 POINT32 hotspot
; /* Out: bitmap hotspot */
266 /***********************************************************************
267 * OBM_InitColorSymbols
269 static BOOL32
OBM_InitColorSymbols()
271 static BOOL32 initialized
= FALSE
;
274 if (initialized
) return TRUE
; /* Already initialised */
277 for (i
= 0; i
< NB_COLOR_SYMBOLS
; i
++)
279 if (OBM_Colors
[i
].pixel
& 0xff000000) /* PALETTEINDEX */
280 OBM_Colors
[i
].pixel
= COLOR_ToPhysical( NULL
,
281 GetSysColor32(OBM_Colors
[i
].pixel
& 0xff));
283 OBM_Colors
[i
].pixel
= COLOR_ToPhysical( NULL
, OBM_Colors
[i
].pixel
);
289 /***********************************************************************
292 * Allocate a GDI bitmap.
294 static HBITMAP16
OBM_MakeBitmap( WORD width
, WORD height
,
295 WORD bpp
, Pixmap pixmap
)
298 BITMAPOBJ
* bmpObjPtr
;
300 if (!pixmap
) return 0;
302 hbitmap
= GDI_AllocObject( sizeof(BITMAPOBJ
), BITMAP_MAGIC
);
303 if (!hbitmap
) return 0;
305 bmpObjPtr
= (BITMAPOBJ
*) GDI_HEAP_LOCK( hbitmap
);
306 bmpObjPtr
->size
.cx
= width
;
307 bmpObjPtr
->size
.cy
= height
;
308 bmpObjPtr
->pixmap
= pixmap
;
309 bmpObjPtr
->bitmap
.bmType
= 0;
310 bmpObjPtr
->bitmap
.bmWidth
= width
;
311 bmpObjPtr
->bitmap
.bmHeight
= height
;
312 bmpObjPtr
->bitmap
.bmWidthBytes
= BITMAP_WIDTH_BYTES( width
, bpp
);
313 bmpObjPtr
->bitmap
.bmPlanes
= 1;
314 bmpObjPtr
->bitmap
.bmBitsPixel
= bpp
;
315 bmpObjPtr
->bitmap
.bmBits
= NULL
;
316 GDI_HEAP_UNLOCK( hbitmap
);
321 /***********************************************************************
324 * Create the 2 bitmaps from XPM data.
326 static BOOL32
OBM_CreateBitmaps( OBM_BITMAP_DESCR
*descr
)
328 Pixmap pixmap
, pixmask
;
329 XpmAttributes
*attrs
;
332 attrs
= (XpmAttributes
*)HEAP_xalloc( GetProcessHeap(), 0,
333 XpmAttributesSize() );
334 attrs
->valuemask
= XpmColormap
| XpmDepth
| XpmColorSymbols
|XpmHotspot
;
335 attrs
->colormap
= COLOR_GetColormap();
336 attrs
->depth
= descr
->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
, descr
->data
,
341 &pixmap
, &pixmask
, attrs
);
343 if (err
!= XpmSuccess
)
345 HeapFree( GetProcessHeap(), 0, attrs
);
348 descr
->hotspot
.x
= attrs
->x_hotspot
;
349 descr
->hotspot
.y
= attrs
->y_hotspot
;
350 descr
->bitmap
= OBM_MakeBitmap( attrs
->width
, attrs
->height
,
351 attrs
->depth
, pixmap
);
352 if (descr
->need_mask
)
353 descr
->mask
= OBM_MakeBitmap( attrs
->width
, attrs
->height
,
355 HeapFree( GetProcessHeap(), 0, attrs
);
358 if (pixmap
) XFreePixmap( display
, pixmap
);
359 if (pixmask
) XFreePixmap( display
, pixmask
);
360 if (descr
->bitmap
) GDI_FreeObject( descr
->bitmap
);
361 if (descr
->need_mask
&& descr
->mask
) GDI_FreeObject( descr
->mask
);
368 /***********************************************************************
371 HBITMAP16
OBM_LoadBitmap( WORD id
)
373 OBM_BITMAP_DESCR descr
;
375 if ((id
< OBM_FIRST
) || (id
> OBM_LAST
)) return 0;
378 if (!OBM_InitColorSymbols()) return 0;
380 descr
.data
= OBM_Pixmaps_Data
[id
].data
;
381 descr
.color
= OBM_Pixmaps_Data
[id
].color
;
382 descr
.need_mask
= FALSE
;
384 if (!CALL_LARGE_STACK( OBM_CreateBitmaps
, &descr
))
386 fprintf( stderr
, "Error creating OEM bitmap %d\n", OBM_FIRST
+id
);
393 /***********************************************************************
396 HGLOBAL16
OBM_LoadCursorIcon( WORD id
, BOOL32 fCursor
)
398 OBM_BITMAP_DESCR descr
;
400 CURSORICONINFO
*pInfo
;
401 BITMAPOBJ
*bmpXor
, *bmpAnd
;
402 int sizeXor
, sizeAnd
;
406 if ((id
>= OCR_FIRST1
) && (id
<= OCR_LAST1
))
407 id
= OCR_BASE1
+ id
- OCR_FIRST1
;
408 else if ((id
>= OCR_FIRST2
) && (id
<= OCR_LAST2
))
409 id
= OCR_BASE2
+ id
- OCR_FIRST2
;
410 else if ((id
>= OCR_FIRST0
) && (id
<= OCR_LAST0
))
411 id
= OCR_BASE0
+ id
- OCR_FIRST0
;
413 if (OBM_Cursors
[id
]) return OBM_Cursors
[id
];
417 if ((id
< OIC_FIRST
) || (id
> OIC_LAST
)) return 0;
421 if (!OBM_InitColorSymbols()) return 0;
423 descr
.data
= fCursor
? OBM_Cursors_Data
[id
] : OBM_Icons_Data
[id
];
424 descr
.color
= !fCursor
;
425 descr
.need_mask
= TRUE
;
427 if (!CALL_LARGE_STACK( OBM_CreateBitmaps
, &descr
))
429 fprintf( stderr
, "Error creating OEM cursor/icon %d\n", id
);
433 bmpXor
= (BITMAPOBJ
*) GDI_GetObjPtr( descr
.bitmap
, BITMAP_MAGIC
);
434 bmpAnd
= (BITMAPOBJ
*) GDI_GetObjPtr( descr
.mask
, BITMAP_MAGIC
);
435 sizeXor
= bmpXor
->bitmap
.bmHeight
* bmpXor
->bitmap
.bmWidthBytes
;
436 sizeAnd
= bmpXor
->bitmap
.bmHeight
* BITMAP_WIDTH_BYTES( bmpXor
->bitmap
.bmWidth
, 1 );
438 if (!(handle
= GlobalAlloc16( GMEM_MOVEABLE
,
439 sizeof(CURSORICONINFO
) + sizeXor
+ sizeAnd
)))
441 DeleteObject32( descr
.bitmap
);
442 DeleteObject32( descr
.mask
);
446 pInfo
= (CURSORICONINFO
*)GlobalLock16( handle
);
447 pInfo
->ptHotSpot
.x
= descr
.hotspot
.x
;
448 pInfo
->ptHotSpot
.y
= descr
.hotspot
.y
;
449 pInfo
->nWidth
= bmpXor
->bitmap
.bmWidth
;
450 pInfo
->nHeight
= bmpXor
->bitmap
.bmHeight
;
451 pInfo
->nWidthBytes
= bmpXor
->bitmap
.bmWidthBytes
;
452 pInfo
->bPlanes
= bmpXor
->bitmap
.bmPlanes
;
453 pInfo
->bBitsPerPixel
= bmpXor
->bitmap
.bmBitsPixel
;
457 /* Invert the mask */
459 XSetFunction( display
, BITMAP_monoGC
, GXinvert
);
460 XFillRectangle( display
, bmpAnd
->pixmap
, BITMAP_monoGC
, 0, 0,
461 bmpAnd
->bitmap
.bmWidth
, bmpAnd
->bitmap
.bmHeight
);
462 XSetFunction( display
, BITMAP_monoGC
, GXcopy
);
464 /* Set the masked pixels to black */
466 if (bmpXor
->bitmap
.bmBitsPixel
!= 1)
468 XSetForeground( display
, BITMAP_colorGC
,
469 COLOR_ToPhysical( NULL
, RGB(0,0,0) ));
470 XSetBackground( display
, BITMAP_colorGC
, 0 );
471 XSetFunction( display
, BITMAP_colorGC
, GXor
);
472 XCopyPlane(display
, bmpAnd
->pixmap
, bmpXor
->pixmap
, BITMAP_colorGC
,
473 0, 0, bmpXor
->bitmap
.bmWidth
, bmpXor
->bitmap
.bmHeight
,
475 XSetFunction( display
, BITMAP_colorGC
, GXcopy
);
479 if (descr
.mask
) GetBitmapBits32( descr
.mask
, sizeAnd
, (char *)(pInfo
+ 1));
480 else memset( (char *)(pInfo
+ 1), 0xff, sizeAnd
);
481 GetBitmapBits32( descr
.bitmap
, sizeXor
, (char *)(pInfo
+ 1) + sizeAnd
);
483 DeleteObject32( descr
.bitmap
);
484 DeleteObject32( descr
.mask
);
486 if (fCursor
) OBM_Cursors
[id
] = handle
;
491 /***********************************************************************
494 * Initializes the OBM_Pixmaps_Data struct
498 if(TWEAK_Win95Look
) {
499 OBM_Pixmaps_Data
[OBM_ZOOMD
- OBM_FIRST
].data
= obm_zoomd_95
;
500 OBM_Pixmaps_Data
[OBM_REDUCED
- OBM_FIRST
].data
= obm_reduced_95
;
501 OBM_Pixmaps_Data
[OBM_ZOOM
- OBM_FIRST
].data
= obm_zoom_95
;
502 OBM_Pixmaps_Data
[OBM_REDUCE
- OBM_FIRST
].data
= obm_reduce_95
;
503 OBM_Pixmaps_Data
[OBM_CLOSE
- OBM_FIRST
].data
= obm_close_95
;
506 OBM_Pixmaps_Data
[OBM_ZOOMD
- OBM_FIRST
].data
= obm_zoomd
;
507 OBM_Pixmaps_Data
[OBM_REDUCED
- OBM_FIRST
].data
= obm_reduced
;
508 OBM_Pixmaps_Data
[OBM_ZOOM
- OBM_FIRST
].data
= obm_zoom
;
509 OBM_Pixmaps_Data
[OBM_REDUCE
- OBM_FIRST
].data
= obm_reduce
;
510 OBM_Pixmaps_Data
[OBM_CLOSE
- OBM_FIRST
].data
= obm_close
;