2 * X11DRV OEM bitmap objects
4 * Copyright 1994, 1995 Alexandre Julliard
15 #else /* defined(HAVE_LIBXXPM) */
16 typedef unsigned long Pixel;
17 #endif /* defined(HAVE_LIBXXPM) */
25 #include "wine/winuser16.h"
28 #include "cursoricon.h"
29 #include "debugtools.h"
31 #include "user.h" /* for TWEAK_WineLook (FIXME) */
34 /* Include OEM pixmaps */
35 #include "bitmaps/obm_lfarrowi"
36 #include "bitmaps/obm_rgarrowi"
37 #include "bitmaps/obm_dnarrowi"
38 #include "bitmaps/obm_uparrowi"
39 #include "bitmaps/obm_combo"
40 #include "bitmaps/obm_mnarrow"
41 #include "bitmaps/obm_lfarrowd"
42 #include "bitmaps/obm_rgarrowd"
43 #include "bitmaps/obm_dnarrowd"
44 #include "bitmaps/obm_uparrowd"
45 #include "bitmaps/obm_restored"
46 #include "bitmaps/obm_restore"
47 #include "bitmaps/obm_lfarrow"
48 #include "bitmaps/obm_rgarrow"
49 #include "bitmaps/obm_dnarrow"
50 #include "bitmaps/obm_uparrow"
51 #include "bitmaps/obm_old_restore"
52 #include "bitmaps/obm_old_zoom"
53 #include "bitmaps/obm_old_reduce"
54 #include "bitmaps/obm_btncorners"
55 #include "bitmaps/obm_checkboxes"
56 #include "bitmaps/obm_check"
57 #include "bitmaps/obm_btsize"
58 #include "bitmaps/obm_old_lfarrow"
59 #include "bitmaps/obm_old_rgarrow"
60 #include "bitmaps/obm_old_dnarrow"
61 #include "bitmaps/obm_old_uparrow"
62 #include "bitmaps/obm_size"
63 #include "bitmaps/obm_old_close"
64 #include "bitmaps/obm_trtype"
66 #include "bitmaps/obm_zoomd"
67 #include "bitmaps/obm_reduced"
68 #include "bitmaps/obm_zoom"
69 #include "bitmaps/obm_reduce"
70 #include "bitmaps/obm_close"
71 #include "bitmaps/obm_zoomd_95"
72 #include "bitmaps/obm_reduced_95"
73 #include "bitmaps/obm_zoom_95"
74 #include "bitmaps/obm_reduce_95"
75 #include "bitmaps/obm_close_95"
76 #include "bitmaps/obm_closed_95"
77 #include "bitmaps/obm_restore_95"
78 #include "bitmaps/obm_restored_95"
80 DECLARE_DEBUG_CHANNEL(bitmap);
81 DECLARE_DEBUG_CHANNEL(cursor);
82 DECLARE_DEBUG_CHANNEL(x11drv);
85 #define OBM_FIRST OBM_CLOSED /* First OEM bitmap */
86 #define OBM_LAST OBM_OLD_CLOSE /* Last OEM bitmap */
90 char** data; /* Pointer to bitmap data */
91 BOOL color; /* Is it a color bitmap? */
92 } OBM_Pixmaps_Data[OBM_LAST-OBM_FIRST+1] = {
93 { obm_closed_95,TRUE}, /* OBM_CLOSED */
94 { obm_trtype, TRUE }, /* OBM_TRTYPE */
95 { NULL, FALSE }, /* unused */
96 { obm_lfarrowi, TRUE }, /* OBM_LFARROWI */
97 { obm_rgarrowi, TRUE }, /* OBM_RGARROWI */
98 { obm_dnarrowi, TRUE }, /* OBM_DNARROWI */
99 { obm_uparrowi, TRUE }, /* OBM_UPARROWI */
100 { obm_combo, FALSE }, /* OBM_COMBO */
101 { obm_mnarrow, FALSE }, /* OBM_MNARROW */
102 { obm_lfarrowd, TRUE }, /* OBM_LFARROWD */
103 { obm_rgarrowd, TRUE }, /* OBM_RGARROWD */
104 { obm_dnarrowd, TRUE }, /* OBM_DNARROWD */
105 { obm_uparrowd, TRUE }, /* OBM_UPARROWD */
106 { obm_restored, TRUE }, /* OBM_RESTORED */
107 { obm_zoomd, TRUE }, /* OBM_ZOOMD */
108 { obm_reduced, TRUE }, /* OBM_REDUCED */
109 { obm_restore, TRUE }, /* OBM_RESTORE */
110 { obm_zoom, TRUE }, /* OBM_ZOOM */
111 { obm_reduce, TRUE }, /* OBM_REDUCE */
112 { obm_lfarrow, TRUE }, /* OBM_LFARROW */
113 { obm_rgarrow, TRUE }, /* OBM_RGARROW */
114 { obm_dnarrow, TRUE }, /* OBM_DNARROW */
115 { obm_uparrow, TRUE }, /* OBM_UPARROW */
116 { obm_close, TRUE }, /* OBM_CLOSE */
117 { obm_old_restore, FALSE }, /* OBM_OLD_RESTORE */
118 { obm_old_zoom, FALSE }, /* OBM_OLD_ZOOM */
119 { obm_old_reduce, FALSE }, /* OBM_OLD_REDUCE */
120 { obm_btncorners, FALSE }, /* OBM_BTNCORNERS */
121 { obm_checkboxes, FALSE }, /* OBM_CHECKBOXES */
122 { obm_check, FALSE }, /* OBM_CHECK */
123 { obm_btsize, FALSE }, /* OBM_BTSIZE */
124 { obm_old_lfarrow, FALSE }, /* OBM_OLD_LFARROW */
125 { obm_old_rgarrow, FALSE }, /* OBM_OLD_RGARROW */
126 { obm_old_dnarrow, FALSE }, /* OBM_OLD_DNARROW */
127 { obm_old_uparrow, FALSE }, /* OBM_OLD_UPARROW */
128 { obm_size, FALSE }, /* OBM_SIZE */
129 { obm_old_close, FALSE }, /* OBM_OLD_CLOSE */
133 /* All the colors used in the xpm files must be included in this */
134 /* list, to make sure that the loaded bitmaps only use colors from */
135 /* the Windows colormap. Note: the PALETTEINDEX() are not really */
136 /* palette indexes, but system colors that will be converted to */
137 /* indexes later on. */
145 #endif /* !defined(HAVE_LIBXXPM) */
147 static XpmColorSymbol OBM_Colors[] =
149 { "black", NULL, (Pixel)RGB(0,0,0) },
150 { "white", NULL, (Pixel)RGB(255,255,255) },
151 { "red", NULL, (Pixel)RGB(255,0,0) },
152 { "green", NULL, (Pixel)RGB(0,255,0) },
153 { "blue", NULL, (Pixel)RGB(0,0,255) },
154 { "yellow", NULL, (Pixel)RGB(255,255,0) },
155 { "cyan", NULL, (Pixel)RGB(0,255,255) },
156 { "dkyellow", NULL, (Pixel)RGB(128,128,0) },
157 { "purple", NULL, (Pixel)RGB(128,0,128) },
158 { "ltgray", NULL, (Pixel)RGB(192,192,192) },
159 { "dkgray", NULL, (Pixel)RGB(128,128,128) },
160 { "button_face", NULL, (Pixel)PALETTEINDEX(COLOR_BTNFACE) },
161 { "button_shadow", NULL, (Pixel)PALETTEINDEX(COLOR_BTNSHADOW) },
162 { "button_highlight", NULL, (Pixel)PALETTEINDEX(COLOR_BTNHIGHLIGHT) },
163 { "button_edge", NULL, (Pixel)PALETTEINDEX(COLOR_BTNHIGHLIGHT) },
164 { "button_text", NULL, (Pixel)PALETTEINDEX(COLOR_BTNTEXT) },
165 { "window_frame", NULL, (Pixel)PALETTEINDEX(COLOR_WINDOWFRAME) }
168 #define NB_COLOR_SYMBOLS (sizeof(OBM_Colors)/sizeof(OBM_Colors[0]))
170 /* These are the symbolic colors for monochrome bitmaps */
171 /* This is needed to make sure that black is always 0 and */
172 /* white always 1, as required by Windows. */
175 static XpmColorSymbol OBM_BlackAndWhite[2] =
177 { "black", NULL, 0 },
178 { "white", NULL, 0xffffffff }
180 #endif /* defined(HAVE_LIBXXPM) */
182 extern const DC_FUNCTIONS *X11DRV_DC_Funcs; /* hack */
185 /***********************************************************************
186 * OBM_InitColorSymbols
188 static BOOL OBM_InitColorSymbols()
190 static BOOL initialized = FALSE;
193 if (initialized) return TRUE; /* Already initialised */
196 for (i = 0; i < NB_COLOR_SYMBOLS; i++)
198 if (OBM_Colors[i].pixel & 0xff000000) /* PALETTEINDEX */
199 OBM_Colors[i].pixel = X11DRV_PALETTE_ToPhysical( NULL,
200 GetSysColor(OBM_Colors[i].pixel & 0xff));
202 OBM_Colors[i].pixel = X11DRV_PALETTE_ToPhysical( NULL, OBM_Colors[i].pixel);
208 /***********************************************************************
211 * Allocate a GDI bitmap.
214 static HBITMAP16 OBM_MakeBitmap( WORD width, WORD height,
215 WORD bpp, Pixmap pixmap )
218 BITMAPOBJ * bmpObjPtr;
220 if (!pixmap) return 0;
222 if (!(bmpObjPtr = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC, &hbitmap ))) return 0;
223 bmpObjPtr->size.cx = width;
224 bmpObjPtr->size.cy = height;
225 bmpObjPtr->bitmap.bmType = 0;
226 bmpObjPtr->bitmap.bmWidth = width;
227 bmpObjPtr->bitmap.bmHeight = height;
228 bmpObjPtr->bitmap.bmWidthBytes = BITMAP_GetWidthBytes( width, bpp );
229 bmpObjPtr->bitmap.bmPlanes = 1;
230 bmpObjPtr->bitmap.bmBitsPixel = bpp;
231 bmpObjPtr->bitmap.bmBits = NULL;
232 bmpObjPtr->dib = NULL;
234 bmpObjPtr->funcs = X11DRV_DC_Funcs;
235 bmpObjPtr->physBitmap = (void *)pixmap;
237 GDI_ReleaseObj( hbitmap );
240 #endif /* defined(HAVE_LIBXXPM) */
243 /***********************************************************************
246 * Create the 2 bitmaps from XPM data.
248 static BOOL OBM_CreateBitmaps( char **data, BOOL color,
249 HBITMAP16 *bitmap, HBITMAP16 *mask, POINT *hotspot )
252 XpmAttributes *attrs;
253 Pixmap pixmap, pixmask;
256 attrs = (XpmAttributes *)HeapAlloc( GetProcessHeap(), 0, XpmAttributesSize() );
257 if (attrs == NULL) return FALSE;
258 attrs->valuemask = XpmColormap | XpmDepth | XpmColorSymbols | XpmHotspot;
259 attrs->colormap = X11DRV_PALETTE_PaletteXColormap;
260 attrs->depth = color ? screen_depth : 1;
261 attrs->colorsymbols = (attrs->depth > 1) ? OBM_Colors : OBM_BlackAndWhite;
262 attrs->numsymbols = (attrs->depth > 1) ? NB_COLOR_SYMBOLS : 2;
264 err = TSXpmCreatePixmapFromData( gdi_display, root_window, data, &pixmap, &pixmask, attrs );
265 if (err != XpmSuccess)
267 HeapFree( GetProcessHeap(), 0, attrs );
273 hotspot->x = attrs->x_hotspot;
274 hotspot->y = attrs->y_hotspot;
278 *bitmap = OBM_MakeBitmap( attrs->width, attrs->height,
279 attrs->depth, pixmap );
282 *mask = OBM_MakeBitmap( attrs->width, attrs->height,
285 HeapFree( GetProcessHeap(), 0, attrs );
287 if (pixmap && (!bitmap || !*bitmap)) TSXFreePixmap( gdi_display, pixmap );
288 if (pixmask && (!mask || !*mask)) TSXFreePixmap( gdi_display, pixmask );
290 if (bitmap && !*bitmap)
292 if (mask && *mask) DeleteObject( *mask );
296 #else /* defined(HAVE_LIBXXPM) */
298 "Xpm support not in the binary, "
299 "please install the Xpm and Xpm-devel packages and recompile wine\n"
302 #endif /* defined(HAVE_LIBXXPM) */
306 /***********************************************************************
309 static HBITMAP16 OBM_LoadBitmap( WORD id )
313 if ((id < OBM_FIRST) || (id > OBM_LAST)) return 0;
315 if (!OBM_Pixmaps_Data[id].data) return 0;
317 if (!OBM_InitColorSymbols()) return 0;
319 if (!OBM_CreateBitmaps( OBM_Pixmaps_Data[id].data, OBM_Pixmaps_Data[id].color,
320 &bitmap, NULL, NULL ))
322 WARN_(bitmap)("Error creating OEM bitmap %d\n", OBM_FIRST+id );
329 /***********************************************************************
330 * LoadOEMResource (X11DRV.@)
333 HANDLE X11DRV_LoadOEMResource(WORD resid, WORD type)
337 return OBM_LoadBitmap(resid);
340 ERR_(x11drv)("Unknown type\n");
346 /***********************************************************************
349 * Initializes the OBM_Pixmaps_Data and OBM_Icons_Data struct
351 BOOL X11DRV_OBM_Init(void)
353 if (TWEAK_WineLook == WIN31_LOOK) {
354 OBM_Pixmaps_Data[OBM_ZOOMD - OBM_FIRST].data = obm_zoomd;
355 OBM_Pixmaps_Data[OBM_REDUCED - OBM_FIRST].data = obm_reduced;
356 OBM_Pixmaps_Data[OBM_ZOOM - OBM_FIRST].data = obm_zoom;
357 OBM_Pixmaps_Data[OBM_REDUCE - OBM_FIRST].data = obm_reduce;
358 OBM_Pixmaps_Data[OBM_CLOSE - OBM_FIRST].data = obm_close;
359 OBM_Pixmaps_Data[OBM_RESTORE - OBM_FIRST].data = obm_restore;
360 OBM_Pixmaps_Data[OBM_RESTORED - OBM_FIRST].data = obm_restored;
363 OBM_Pixmaps_Data[OBM_ZOOMD - OBM_FIRST].data = obm_zoomd_95;
364 OBM_Pixmaps_Data[OBM_REDUCED - OBM_FIRST].data = obm_reduced_95;
365 OBM_Pixmaps_Data[OBM_ZOOM - OBM_FIRST].data = obm_zoom_95;
366 OBM_Pixmaps_Data[OBM_REDUCE - OBM_FIRST].data = obm_reduce_95;
367 OBM_Pixmaps_Data[OBM_CLOSE - OBM_FIRST].data = obm_close_95;
368 OBM_Pixmaps_Data[OBM_RESTORE - OBM_FIRST].data = obm_restore_95;
369 OBM_Pixmaps_Data[OBM_RESTORED - OBM_FIRST].data = obm_restored_95;