Added Traditional Chinese Support
[wine] / graphics / x11drv / oembitmap.c
1 /*
2  * X11DRV OEM bitmap objects
3  *
4  * Copyright 1994, 1995 Alexandre Julliard
5  *
6  */
7
8 #include "config.h"
9
10 #include "ts_xlib.h"
11 #include "ts_xutil.h"
12
13 #ifdef HAVE_LIBXXPM
14 #include "ts_xpm.h"
15 #else /* defined(HAVE_LIBXXPM) */
16 typedef unsigned long Pixel;
17 #endif /* defined(HAVE_LIBXXPM) */
18
19 #include <stdlib.h>
20 #include <string.h>
21
22 #include "winbase.h"
23 #include "wingdi.h"
24 #include "winuser.h"
25 #include "wine/winuser16.h"
26
27 #include "bitmap.h"
28 #include "color.h"
29 #include "cursoricon.h"
30 #include "debugtools.h"
31 #include "gdi.h"
32 #include "heap.h"
33 #include "user.h" /* for TWEAK_WineLook (FIXME) */
34 #include "x11drv.h"
35
36   /* Include OEM pixmaps */
37 #include "bitmaps/obm_lfarrowi"
38 #include "bitmaps/obm_rgarrowi"
39 #include "bitmaps/obm_dnarrowi"
40 #include "bitmaps/obm_uparrowi"
41 #include "bitmaps/obm_combo"
42 #include "bitmaps/obm_mnarrow"
43 #include "bitmaps/obm_lfarrowd"
44 #include "bitmaps/obm_rgarrowd"
45 #include "bitmaps/obm_dnarrowd"
46 #include "bitmaps/obm_uparrowd"
47 #include "bitmaps/obm_restored"
48 #include "bitmaps/obm_restore"
49 #include "bitmaps/obm_lfarrow"
50 #include "bitmaps/obm_rgarrow"
51 #include "bitmaps/obm_dnarrow"
52 #include "bitmaps/obm_uparrow"
53 #include "bitmaps/obm_old_restore"
54 #include "bitmaps/obm_old_zoom"
55 #include "bitmaps/obm_old_reduce"
56 #include "bitmaps/obm_btncorners"
57 #include "bitmaps/obm_checkboxes"
58 #include "bitmaps/obm_check"
59 #include "bitmaps/obm_btsize"
60 #include "bitmaps/obm_old_lfarrow"
61 #include "bitmaps/obm_old_rgarrow"
62 #include "bitmaps/obm_old_dnarrow"
63 #include "bitmaps/obm_old_uparrow"
64 #include "bitmaps/obm_size"
65 #include "bitmaps/obm_old_close"
66 #include "bitmaps/obm_trtype"
67
68 #include "bitmaps/obm_zoomd"
69 #include "bitmaps/obm_reduced"
70 #include "bitmaps/obm_zoom"
71 #include "bitmaps/obm_reduce"
72 #include "bitmaps/obm_close"
73 #include "bitmaps/obm_zoomd_95"
74 #include "bitmaps/obm_reduced_95"
75 #include "bitmaps/obm_zoom_95"
76 #include "bitmaps/obm_reduce_95"
77 #include "bitmaps/obm_close_95"
78 #include "bitmaps/obm_closed_95"
79 #include "bitmaps/obm_restore_95"
80 #include "bitmaps/obm_restored_95"
81
82 DECLARE_DEBUG_CHANNEL(bitmap);
83 DECLARE_DEBUG_CHANNEL(cursor);
84 DECLARE_DEBUG_CHANNEL(x11drv);
85
86
87 #define OBM_FIRST  OBM_CLOSED  /* First OEM bitmap */
88 #define OBM_LAST   OBM_OLD_CLOSE   /* Last OEM bitmap */
89
90 static struct
91 {
92     char** data;   /* Pointer to bitmap data */
93     BOOL color;  /* Is it a color bitmap?  */
94 } OBM_Pixmaps_Data[OBM_LAST-OBM_FIRST+1] = {
95     { obm_closed_95,TRUE},      /* OBM_CLOSED */
96     { obm_trtype, TRUE },       /* OBM_TRTYPE */
97     { NULL, FALSE },            /* unused */
98     { obm_lfarrowi, TRUE },     /* OBM_LFARROWI */
99     { obm_rgarrowi, TRUE },     /* OBM_RGARROWI */
100     { obm_dnarrowi, TRUE },     /* OBM_DNARROWI */
101     { obm_uparrowi, TRUE },     /* OBM_UPARROWI */
102     { obm_combo, FALSE },       /* OBM_COMBO */
103     { obm_mnarrow, FALSE },     /* OBM_MNARROW */
104     { obm_lfarrowd, TRUE },     /* OBM_LFARROWD */
105     { obm_rgarrowd, TRUE },     /* OBM_RGARROWD */
106     { obm_dnarrowd, TRUE },     /* OBM_DNARROWD */
107     { obm_uparrowd, TRUE },     /* OBM_UPARROWD */
108     { obm_restored, TRUE },     /* OBM_RESTORED */
109     { obm_zoomd, TRUE },        /* OBM_ZOOMD */
110     { obm_reduced, TRUE },      /* OBM_REDUCED */
111     { obm_restore, TRUE },      /* OBM_RESTORE */
112     { obm_zoom, TRUE },         /* OBM_ZOOM */
113     { 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 */
118     { obm_close, TRUE },        /* OBM_CLOSE */
119     { obm_old_restore, FALSE }, /* OBM_OLD_RESTORE */
120     { obm_old_zoom, FALSE },    /* OBM_OLD_ZOOM */
121     { obm_old_reduce, FALSE },  /* OBM_OLD_REDUCE */
122     { obm_btncorners, FALSE },  /* OBM_BTNCORNERS */
123     { obm_checkboxes, FALSE },  /* OBM_CHECKBOXES */
124     { obm_check, FALSE },       /* OBM_CHECK */
125     { obm_btsize, FALSE },      /* OBM_BTSIZE */
126     { obm_old_lfarrow, FALSE }, /* OBM_OLD_LFARROW */
127     { obm_old_rgarrow, FALSE }, /* OBM_OLD_RGARROW */
128     { obm_old_dnarrow, FALSE }, /* OBM_OLD_DNARROW */
129     { obm_old_uparrow, FALSE }, /* OBM_OLD_UPARROW */
130     { obm_size, FALSE },        /* OBM_SIZE */
131     { obm_old_close, FALSE },   /* OBM_OLD_CLOSE */
132 };
133
134
135   /* All the colors used in the xpm files must be included in this   */
136   /* list, to make sure that the loaded bitmaps only use colors from */
137   /* the Windows colormap. Note: the PALETTEINDEX() are not really   */
138   /* palette indexes, but system colors that will be converted to    */
139   /* indexes later on.                                               */
140
141 #ifdef HAVE_LIBXXPM
142 static XpmColorSymbol
143 #else /* defined(HAVE_LIBXXPM) */
144 static struct
145 {
146     char  *name;
147     char  *value;
148     Pixel  pixel;
149
150 #endif /* defined(HAVE_LIBXXPM) */
151 OBM_Colors[] =
152 {
153     { "black",            NULL, (Pixel)RGB(0,0,0) },
154     { "white",            NULL, (Pixel)RGB(255,255,255) },
155     { "red",              NULL, (Pixel)RGB(255,0,0) },
156     { "green",            NULL, (Pixel)RGB(0,255,0) },
157     { "blue",             NULL, (Pixel)RGB(0,0,255) },
158     { "yellow",           NULL, (Pixel)RGB(255,255,0) },
159     { "cyan",             NULL, (Pixel)RGB(0,255,255) },    
160     { "dkyellow",         NULL, (Pixel)RGB(128,128,0) },
161     { "purple",           NULL, (Pixel)RGB(128,0,128) },
162     { "ltgray",           NULL, (Pixel)RGB(192,192,192) },
163     { "dkgray",           NULL, (Pixel)RGB(128,128,128) },
164     { "button_face",      NULL, (Pixel)PALETTEINDEX(COLOR_BTNFACE) },
165     { "button_shadow",    NULL, (Pixel)PALETTEINDEX(COLOR_BTNSHADOW) },
166     { "button_highlight", NULL, (Pixel)PALETTEINDEX(COLOR_BTNHIGHLIGHT) },
167     { "button_edge",      NULL, (Pixel)PALETTEINDEX(COLOR_BTNHIGHLIGHT) },
168     { "button_text",      NULL, (Pixel)PALETTEINDEX(COLOR_BTNTEXT) },
169     { "window_frame",     NULL, (Pixel)PALETTEINDEX(COLOR_WINDOWFRAME) }
170 };
171
172 #define NB_COLOR_SYMBOLS (sizeof(OBM_Colors)/sizeof(OBM_Colors[0]))
173
174   /* These are the symbolic colors for monochrome bitmaps   */
175   /* This is needed to make sure that black is always 0 and */
176   /* white always 1, as required by Windows.                */
177
178 #ifdef HAVE_LIBXXPM
179 static XpmColorSymbol OBM_BlackAndWhite[2] =
180 {
181     { "black", NULL, 0 },
182     { "white", NULL, 0xffffffff }
183 };
184 #endif /* defined(HAVE_LIBXXPM) */
185
186
187
188 /***********************************************************************
189  *           OBM_InitColorSymbols
190  */
191 static BOOL OBM_InitColorSymbols()
192 {
193     static BOOL initialized = FALSE;
194     int i;
195
196     if (initialized) return TRUE;  /* Already initialised */
197     initialized = TRUE;
198
199     for (i = 0; i < NB_COLOR_SYMBOLS; i++)
200     {
201         if (OBM_Colors[i].pixel & 0xff000000)  /* PALETTEINDEX */
202             OBM_Colors[i].pixel = X11DRV_PALETTE_ToPhysical( NULL,
203                                     GetSysColor(OBM_Colors[i].pixel & 0xff));
204         else  /* RGB*/
205             OBM_Colors[i].pixel = X11DRV_PALETTE_ToPhysical( NULL, OBM_Colors[i].pixel);
206     }
207     return TRUE;
208 }
209
210
211 /***********************************************************************
212  *           OBM_MakeBitmap
213  *
214  * Allocate a GDI bitmap.
215  */
216 #ifdef HAVE_LIBXXPM
217 static HBITMAP16 OBM_MakeBitmap( WORD width, WORD height,
218                                  WORD bpp, Pixmap pixmap )
219 {
220     HBITMAP hbitmap;
221     BITMAPOBJ * bmpObjPtr;
222
223     if (!pixmap) return 0;
224
225     if (!(bmpObjPtr = GDI_AllocObject( sizeof(BITMAPOBJ), BITMAP_MAGIC, &hbitmap ))) return 0;
226     bmpObjPtr->size.cx = width;
227     bmpObjPtr->size.cy = height;
228     bmpObjPtr->bitmap.bmType       = 0;
229     bmpObjPtr->bitmap.bmWidth      = width;
230     bmpObjPtr->bitmap.bmHeight     = height;
231     bmpObjPtr->bitmap.bmWidthBytes = BITMAP_GetWidthBytes( width, bpp );
232     bmpObjPtr->bitmap.bmPlanes     = 1;
233     bmpObjPtr->bitmap.bmBitsPixel  = bpp;
234     bmpObjPtr->bitmap.bmBits       = NULL;
235     bmpObjPtr->dib                 = NULL;
236
237     bmpObjPtr->funcs = &X11DRV_DC_Funcs;
238     bmpObjPtr->physBitmap = (void *)pixmap;
239
240     GDI_ReleaseObj( hbitmap );
241     return hbitmap;
242 }
243 #endif /* defined(HAVE_LIBXXPM) */
244
245
246 /***********************************************************************
247  *           OBM_CreateBitmaps
248  *
249  * Create the 2 bitmaps from XPM data.
250  */
251 static BOOL OBM_CreateBitmaps( char **data, BOOL color,
252                                HBITMAP16 *bitmap, HBITMAP16 *mask, POINT *hotspot )
253 {
254 #ifdef HAVE_LIBXXPM
255     XpmAttributes *attrs;
256     Pixmap pixmap, pixmask;
257     int err;
258
259     attrs = (XpmAttributes *)HeapAlloc( GetProcessHeap(), 0, XpmAttributesSize() );
260     if (attrs == NULL) return FALSE;
261     attrs->valuemask    = XpmColormap | XpmDepth | XpmColorSymbols | XpmHotspot;
262     attrs->colormap     = X11DRV_PALETTE_PaletteXColormap;
263     attrs->depth        = color ? screen_depth : 1;
264     attrs->colorsymbols = (attrs->depth > 1) ? OBM_Colors : OBM_BlackAndWhite;
265     attrs->numsymbols   = (attrs->depth > 1) ? NB_COLOR_SYMBOLS : 2;
266
267     err = TSXpmCreatePixmapFromData( gdi_display, root_window, data, &pixmap, &pixmask, attrs );
268     if (err != XpmSuccess)
269     {
270         HeapFree( GetProcessHeap(), 0, attrs );
271         return FALSE;
272     }
273
274     if (hotspot)
275     {
276         hotspot->x = attrs->x_hotspot;
277         hotspot->y = attrs->y_hotspot;
278     }
279
280     if (bitmap)
281         *bitmap = OBM_MakeBitmap( attrs->width, attrs->height,
282                                   attrs->depth, pixmap );
283         
284     if (mask)
285         *mask = OBM_MakeBitmap( attrs->width, attrs->height,
286                                 1, pixmask );
287
288     HeapFree( GetProcessHeap(), 0, attrs );
289
290     if (pixmap && (!bitmap || !*bitmap)) TSXFreePixmap( gdi_display, pixmap );
291     if (pixmask && (!mask || !*mask)) TSXFreePixmap( gdi_display, pixmask );
292
293     if (bitmap && !*bitmap)
294     {
295         if (mask && *mask) DeleteObject( *mask );
296         return FALSE;
297     }
298     return TRUE;
299 #else /* defined(HAVE_LIBXXPM) */
300     FIXME_(x11drv)(
301         "Xpm support not in the binary, "
302         "please install the Xpm and Xpm-devel packages and recompile\n"
303     );
304     return FALSE;
305 #endif /* defined(HAVE_LIBXXPM) */
306 }
307
308
309 /***********************************************************************
310  *           OBM_LoadBitmap
311  */
312 static HBITMAP16 OBM_LoadBitmap( WORD id )
313 {
314     HBITMAP16 bitmap;
315
316     if ((id < OBM_FIRST) || (id > OBM_LAST)) return 0;
317     id -= OBM_FIRST;
318     if (!OBM_Pixmaps_Data[id].data) return 0;
319
320     if (!OBM_InitColorSymbols()) return 0;
321
322     if (!OBM_CreateBitmaps( OBM_Pixmaps_Data[id].data, OBM_Pixmaps_Data[id].color,
323                             &bitmap, NULL, NULL ))
324     {
325         WARN_(bitmap)("Error creating OEM bitmap %d\n", OBM_FIRST+id );
326         return 0;
327     }
328     return bitmap;
329 }
330
331
332 /***********************************************************************
333  *           X11DRV_LoadOEMResource (X11DRV.@)
334  *
335  */
336 HANDLE X11DRV_LoadOEMResource(WORD resid, WORD type)
337 {
338     switch(type) {
339     case OEM_BITMAP:
340         return OBM_LoadBitmap(resid);
341
342     default:
343         ERR_(x11drv)("Unknown type\n");
344     }
345     return 0;
346 }
347
348
349 /***********************************************************************
350  *           X11DRV_OBM_Init
351  *
352  * Initializes the OBM_Pixmaps_Data and OBM_Icons_Data struct
353  */
354 BOOL X11DRV_OBM_Init(void)
355 {
356     if (TWEAK_WineLook == WIN31_LOOK) {
357         OBM_Pixmaps_Data[OBM_ZOOMD - OBM_FIRST].data = obm_zoomd;
358         OBM_Pixmaps_Data[OBM_REDUCED - OBM_FIRST].data = obm_reduced;
359         OBM_Pixmaps_Data[OBM_ZOOM - OBM_FIRST].data = obm_zoom;
360         OBM_Pixmaps_Data[OBM_REDUCE - OBM_FIRST].data = obm_reduce;
361         OBM_Pixmaps_Data[OBM_CLOSE - OBM_FIRST].data = obm_close;
362         OBM_Pixmaps_Data[OBM_RESTORE - OBM_FIRST].data = obm_restore;
363         OBM_Pixmaps_Data[OBM_RESTORED - OBM_FIRST].data = obm_restored;
364     }
365     else {
366         OBM_Pixmaps_Data[OBM_ZOOMD - OBM_FIRST].data = obm_zoomd_95;
367         OBM_Pixmaps_Data[OBM_REDUCED - OBM_FIRST].data = obm_reduced_95;
368         OBM_Pixmaps_Data[OBM_ZOOM - OBM_FIRST].data = obm_zoom_95;
369         OBM_Pixmaps_Data[OBM_REDUCE - OBM_FIRST].data = obm_reduce_95;
370         OBM_Pixmaps_Data[OBM_CLOSE - OBM_FIRST].data = obm_close_95;
371         OBM_Pixmaps_Data[OBM_RESTORE - OBM_FIRST].data = obm_restore_95;
372         OBM_Pixmaps_Data[OBM_RESTORED - OBM_FIRST].data = obm_restored_95;
373     }
374
375     return 1;
376 }
377