Implement SPI_GETICONMETRICS.
[wine] / misc / main.c
1 /*
2  * Main function.
3  *
4  * Copyright 1994 Alexandre Julliard
5  */
6
7 #include "config.h"
8
9 #ifndef X_DISPLAY_MISSING
10 #include "x11drv.h"
11 #else /* !defined(X_DISPLAY_MISSING) */
12 #include "ttydrv.h"
13 #endif /* !defined(X_DISPLAY_MISSING) */
14
15 #include <locale.h>
16 #include <ctype.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <unistd.h>
20 #ifdef MALLOC_DEBUGGING
21 # include <malloc.h>
22 #endif
23
24 #include "winbase.h"
25 #include "winsock.h"
26 #include "heap.h"
27 #include "message.h"
28 #include "msdos.h"
29 #include "color.h"
30 #include "options.h"
31 #include "desktop.h"
32 #include "builtin32.h"
33 #include "debugtools.h"
34 #include "debugdefs.h"
35 #include "xmalloc.h"
36 #include "module.h"
37 #include "version.h"
38 #include "winnls.h"
39 #include "console.h"
40 #include "monitor.h"
41 #include "keyboard.h"
42 #include "gdi.h"
43 #include "user.h"
44 #include "windef.h"
45 #include "wingdi.h"
46 #include "wine/winuser16.h"
47 #include "tweak.h"
48 #include "winerror.h"
49
50 /**********************************************************************/
51
52 USER_DRIVER *USER_Driver = NULL;
53
54 /* when adding new languages look at ole/ole2nls.c 
55  * for proper iso name and Windows code (add 0x0400 
56  * to the code listed there)
57  */
58 const WINE_LANGUAGE_DEF Languages[] =
59 {
60     {"En",0x0409},      /* LANG_En */
61     {"Es",0x040A},      /* LANG_Es */
62     {"De",0x0407},      /* LANG_De */
63     {"No",0x0414},      /* LANG_No */
64     {"Fr",0x040C},      /* LANG_Fr */
65     {"Fi",0x040B},      /* LANG_Fi */
66     {"Da",0x0406},      /* LANG_Da */
67     {"Cs",0x0405},      /* LANG_Cs */
68     {"Eo",0x048f},      /* LANG_Eo */
69     {"It",0x0410},      /* LANG_It */
70     {"Ko",0x0412},      /* LANG_Ko */
71     {"Hu",0x040e},      /* LANG_Hu */
72     {"Pl",0x0415},      /* LANG_Pl */
73     {"Pt",0x0416},      /* LANG_Pt */
74     {"Sv",0x041d},      /* LANG_Sv */
75     {"Ca",0x0403},      /* LANG_Ca */
76     {"Nl",0x0413},      /* LANG_Nl */
77     {"Ru",0x0419},      /* LANG_Ru */
78     {"Wa",0x0490},      /* LANG_Wa */
79     {"Ga",0x043c},      /* LANG_Ga */
80     {"Gd",0x083c},      /* LANG_Gd */
81     {"Gv",0x0c3c},      /* LANG_Gv */
82     {"Kw",0x0491},      /* LANG_Kw */
83     {"Cy",0x0492},      /* LANG_Cy */
84     {"Br",0x0493},      /* LANG_Br  */
85     {NULL,0}
86 };
87
88 WORD WINE_LanguageId = 0x409;   /* english as default */
89
90 struct options Options =
91 {  /* default options */
92     0,              /* argc */
93     NULL,           /* argv */
94     NULL,           /* desktopGeometry */
95     NULL,           /* programName */
96     NULL,           /* dllFlags */
97     FALSE,          /* usePrivateMap */
98     FALSE,          /* synchronous */
99     FALSE,
100     FALSE,          /* failReadOnly */
101 #ifdef DEFAULT_LANG
102     DEFAULT_LANG,   /* Default language */
103 #else
104     LANG_En,
105 #endif
106     FALSE,          /* Managed windows */
107     FALSE,          /* Perfect graphics */
108     FALSE,          /* No DGA */
109     FALSE,          /* No XSHM */
110     FALSE,          /* DXGrab */
111     NULL,           /* Alternate config file name */
112     0               /* screenDepth */
113 };
114
115 const char *argv0;
116
117 static const char szUsage[] =
118   "Options:\n"
119   "    -config name    Specify config file to use\n"
120   "    -debug          Enter debugger before starting application\n"
121   "    -debugmsg name  Turn debugging-messages on or off\n"
122   "    -depth n        Change the depth to use for multiple-depth screens\n"
123   "    -desktop geom   Use a desktop window of the given geometry\n"
124   "    -display name   Use the specified display\n"
125   "    -dll name       Enable or disable built-in DLLs\n"
126   "    -failreadonly   Read only files may not be opened in write mode\n"
127   "    -help           Show this help message\n"
128   "    -language xx    Set the language (one of Br,Ca,Cs,Cy,Da,De,En,Eo,Es,Fi,Fr,Ga,Gd,Gv\n"
129   "                    Hu,It,Ko,Kw,Nl,No,Pl,Pt,Sv,Ru,Wa)\n"
130   "    -managed        Allow the window manager to manage created windows\n"
131   "    -name name      Set the application name\n"
132   "    -nodga          Disable XFree86 DGA extensions\n"
133   "    -noxshm         Disable XSHM extension\n"
134   "    -dxgrab         Enable DirectX mouse grab\n"
135   "    -perfect        Favor correctness over speed for graphical operations\n"
136   "    -privatemap     Use a private color map\n"
137   "    -synchronous    Turn on synchronous display mode\n"
138   "    -version        Display the Wine version\n"
139   "    -winver         Version to imitate (one of win31,win95,nt351,nt40)\n"
140   "    -dosver         DOS version to imitate (x.xx, e.g. 6.22). Only valid with -winver win31\n"
141   ;
142
143 /***********************************************************************
144  *           MAIN_Usage
145  */
146 void MAIN_Usage( char *name )
147 {
148     MESSAGE( WINE_RELEASE_INFO "\nUsage:  %s [options] \"program_name [arguments]\"\n\n", name );
149     write( 2, szUsage, sizeof(szUsage)-1 );  /* too large for MESSAGE() */
150     ExitProcess(1);
151 }
152
153 /***********************************************************************
154  *           MAIN_GetProgramName
155  *
156  * Get the program name. The name is specified by (in order of precedence):
157  * - the option '-name'.
158  * - the environment variable 'WINE_NAME'.
159  * - the last component of argv[0].
160  */
161 static char *MAIN_GetProgramName( int argc, char *argv[] )
162 {
163     int i;
164     char *p;
165
166     for (i = 1; i < argc-1; i++)
167         if (!strcmp( argv[i], "-name" )) return argv[i+1];
168     if ((p = getenv( "WINE_NAME" )) != NULL) return p;
169     if ((p = strrchr( argv[0], '/' )) != NULL) return p+1;
170     return argv[0];
171 }
172
173 /***********************************************************************
174  *          MAIN_ParseDebugOptions
175  *
176  *  Turns specific debug messages on or off, according to "options".
177  *  
178  *  RETURNS
179  *    TRUE if parsing was successful
180  */
181 BOOL MAIN_ParseDebugOptions(char *options)
182 {
183   /* defined in relay32/relay386.c */
184   extern char **debug_relay_includelist;
185   extern char **debug_relay_excludelist;
186   /* defined in relay32/snoop.c */
187   extern char **debug_snoop_includelist;
188   extern char **debug_snoop_excludelist;
189
190   int i;
191   int l, cls, dotracerelay = TRACE_ON(relay);
192
193   l = strlen(options);
194   if (l<2)
195     return FALSE;
196   if (options[l-1]=='\n') options[l-1]='\0';
197   do
198   {
199     if ((*options!='+')&&(*options!='-')){
200       int j;
201
202       for(j=0; j<DEBUG_CLASS_COUNT; j++)
203         if(!lstrncmpiA(options, debug_cl_name[j], strlen(debug_cl_name[j])))
204           break;
205       if(j==DEBUG_CLASS_COUNT)
206         goto error;
207       options += strlen(debug_cl_name[j]);
208       if ((*options!='+')&&(*options!='-'))
209         goto error;
210       cls = j;
211     }
212     else
213       cls = -1; /* all classes */
214
215     if (strchr(options,','))
216       l=strchr(options,',')-options;
217     else
218       l=strlen(options);
219
220     if (!lstrncmpiA(options+1,"all",l-1))
221       {
222         int i, j;
223         for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
224           for(j=0; j<DEBUG_CLASS_COUNT; j++)
225             if(cls == -1 || cls == j)
226                 __SET_DEBUGGING( j, debug_channels[i], (*options=='+') );
227       }
228     else if (!lstrncmpiA(options+1, "relay=", 6) ||
229              !lstrncmpiA(options+1, "snoop=", 6))
230       {
231         int i, j;
232         char *s, *s2, ***output, c;
233
234         for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
235           if (!strncasecmp( debug_channels[i] + 1, options + 1, 5))
236           {
237             for(j=0; j<DEBUG_CLASS_COUNT; j++)
238               if(cls == -1 || cls == j)
239                   __SET_DEBUGGING( j, debug_channels[i], 1 );
240             break;
241           }
242         /* should never happen, maybe assert(i!=DEBUG_CHANNEL_COUNT)? */
243         if (i==DEBUG_CHANNEL_COUNT)
244           goto error;
245         output = (*options == '+') ?
246                         ((*(options+1) == 'r') ?
247                                 &debug_relay_includelist :
248                                 &debug_snoop_includelist) :
249                         ((*(options+1) == 'r') ?
250                                 &debug_relay_excludelist :
251                                 &debug_snoop_excludelist);
252         s = options + 7;
253         /* if there are n ':', there are n+1 modules, and we need n+2 slots
254          * last one being for the sentinel (NULL) */
255         i = 2;  
256         while((s = strchr(s, ':'))) i++, s++;
257         *output = malloc(sizeof(char **) * i);
258         i = 0;
259         s = options + 7;
260         while((s2 = strchr(s, ':'))) {
261           c = *s2;
262           *s2 = '\0';
263           *((*output)+i) = CharUpperA(strdup(s));
264           *s2 = c;
265           s = s2 + 1;
266           i++;
267         }
268         c = *(options + l);
269         *(options + l) = '\0';
270         *((*output)+i) = CharUpperA(strdup(s));
271         *(options + l) = c;
272         *((*output)+i+1) = NULL;
273       }
274     else
275       {
276         int i, j;
277         for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
278           if (!strncasecmp( debug_channels[i] + 1, options + 1, l - 1) && !debug_channels[i][l])
279           {
280             for(j=0; j<DEBUG_CLASS_COUNT; j++)
281               if(cls == -1 || cls == j)
282                   __SET_DEBUGGING( j, debug_channels[i], (*options=='+') );
283             break;
284           }
285         if (i==DEBUG_CHANNEL_COUNT)
286           goto error;
287       }
288     options+=l;
289   }
290   while((*options==',')&&(*(++options)));
291
292   /* special handling for relay debugging */
293   if (dotracerelay != TRACE_ON(relay))
294         BUILTIN32_SwitchRelayDebug( TRACE_ON(relay) );
295
296   if (!*options)
297     return TRUE;
298
299  error:  
300   MESSAGE("%s: Syntax: -debugmsg [class]+xxx,...  or "
301       "-debugmsg [class]-xxx,...\n",Options.argv[0]);
302   MESSAGE("Example: -debugmsg +all,warn-heap\n"
303       "  turn on all messages except warning heap messages\n");
304   MESSAGE("Special case: -debugmsg +relay=DLL:DLL.###:FuncName\n"
305       "  turn on -debugmsg +relay only as specified\n"
306       "Special case: -debugmsg -relay=DLL:DLL.###:FuncName\n"
307       "  turn on -debugmsg +relay except as specified\n"
308       "Also permitted, +snoop=..., -snoop=... as with relay.\n\n");
309   
310   MESSAGE("Available message classes:\n");
311   for(i=0;i<DEBUG_CLASS_COUNT;i++)
312     MESSAGE( "%-9s", debug_cl_name[i]);
313   MESSAGE("\n\n");
314   
315   MESSAGE("Available message types:\n");
316   MESSAGE("%-9s ","all");
317   for(i=0;i<DEBUG_CHANNEL_COUNT;i++)
318       MESSAGE("%-9s%c",debug_channels[i] + 1,
319           (((i+2)%8==0)?'\n':' '));
320   MESSAGE("\n\n");
321   ExitProcess(1);
322   return FALSE;
323 }
324
325 /***********************************************************************
326  *           MAIN_GetLanguageID
327  *
328  * INPUT:
329  *      Lang: a string whose two first chars are the iso name of a language.
330  *      Country: a string whose two first chars are the iso name of country
331  *      Charset: a string defining the chossen charset encoding
332  *      Dialect: a string defining a variation of the locale
333  *
334  *      all those values are from the standardized format of locale
335  *      name in unix which is: Lang[_Country][.Charset][@Dialect]
336  *
337  * RETURNS:
338  *      the numeric code of the language used by Windows (or 0x00)
339  */
340 int MAIN_GetLanguageID(LPCSTR Lang,LPCSTR Country,LPCSTR Charset,LPCSTR Dialect)
341 {
342     char lang[3]="??", country[3]={0,0,0};
343     char *charset=NULL, *dialect=NULL;
344     int i,j,ret=0;
345
346     if (Lang==NULL) return 0x00;
347     if (Lang[0]) lang[0]=tolower(Lang[0]);
348     if (Lang[1]) lang[1]=tolower(Lang[1]);
349
350     if (Country!=NULL) {
351         if (Country[0]) country[0]=toupper(Country[0]);
352         if (Country[1]) country[1]=toupper(Country[1]);
353     }
354
355     if (Charset!=NULL) {
356         j=strlen(Charset);
357         charset=(char*)malloc(j+1);
358         for (i=0;i<j;i++)
359             charset[i]=toupper(Charset[i]);
360         charset[i]='\0';
361     }
362
363     if (Dialect!=NULL) {
364         j=strlen(Dialect);
365         dialect=(char*)malloc(j+1);
366         for (i=0;i<j;i++)
367             dialect[i]=tolower(Dialect[i]);
368         dialect[i]='\0';
369     } else {
370         dialect = malloc(1);
371         dialect[0] = '\0';
372     }
373
374 #define LANG_ENTRY_BEGIN(x,y)   if(!strcmp(lang, x )) { \
375                                     if (!country[0]) { \
376                                         ret=LANG_##y ; \
377                                         goto end_MAIN_GetLanguageID; \
378                                     }
379 #define LANG_SUB_ENTRY(x,y,z)       if (!strcmp(country, x )) \
380                                         ret = MAKELANGID( LANG_##y , SUBLANG_##z ); \
381                                         goto end_MAIN_GetLanguageID;
382 #define LANG_DIALECT_ENTRY(x,y)     { ret = MAKELANGID(LANG_##x , SUBLANG_##y ); \
383                                     goto end_MAIN_GetLanguageID; }
384 #define LANG_ENTRY_END(x)           ret = MAKELANGID(LANG_##x , SUBLANG_DEFAULT); \
385                                     goto end_MAIN_GetLanguageID; \
386                                 }
387
388 /*x01*/ LANG_ENTRY_BEGIN( "ar", ARABIC )
389         LANG_SUB_ENTRY( "SA", ARABIC, ARABIC)
390         LANG_SUB_ENTRY( "IQ", ARABIC, ARABIC_IRAQ )
391         LANG_SUB_ENTRY( "EG", ARABIC, ARABIC_EGYPT )
392         LANG_SUB_ENTRY( "LY", ARABIC, ARABIC_LIBYA )
393         LANG_SUB_ENTRY( "DZ", ARABIC, ARABIC_ALGERIA )
394         LANG_SUB_ENTRY( "MA", ARABIC, ARABIC_MOROCCO )
395         LANG_SUB_ENTRY( "TN", ARABIC, ARABIC_TUNISIA )
396         LANG_SUB_ENTRY( "OM", ARABIC, ARABIC_OMAN )
397         LANG_SUB_ENTRY( "YE", ARABIC, ARABIC_YEMEN )
398         LANG_SUB_ENTRY( "SY", ARABIC, ARABIC_SYRIA )
399         LANG_SUB_ENTRY( "JO", ARABIC, ARABIC_JORDAN )
400         LANG_SUB_ENTRY( "LB", ARABIC, ARABIC_LEBANON )
401         LANG_SUB_ENTRY( "KW", ARABIC, ARABIC_KUWAIT )
402         LANG_SUB_ENTRY( "AE", ARABIC, ARABIC_UAE )
403         LANG_SUB_ENTRY( "BH", ARABIC, ARABIC_BAHRAIN )
404         LANG_SUB_ENTRY( "QA", ARABIC, ARABIC_QATAR )
405         LANG_ENTRY_END( ARABIC )
406 /*x02*/ LANG_ENTRY_BEGIN( "bu", BULGARIAN )
407         LANG_ENTRY_END( BULGARIAN )
408 /*x03*/ LANG_ENTRY_BEGIN( "ca", CATALAN )
409         LANG_ENTRY_END( CATALAN )
410 /*x04*/ LANG_ENTRY_BEGIN( "zh", CHINESE )
411         LANG_SUB_ENTRY( "TW", CHINESE, CHINESE_TRADITIONAL )
412         LANG_SUB_ENTRY( "CN", CHINESE, CHINESE_SIMPLIFIED )
413         LANG_SUB_ENTRY( "HK", CHINESE, CHINESE_HONGKONG )
414         LANG_SUB_ENTRY( "SG", CHINESE, CHINESE_SINGAPORE )
415         LANG_SUB_ENTRY( "MO", CHINESE, CHINESE_MACAU )
416         LANG_ENTRY_END( CHINESE )
417 /*x05*/ LANG_ENTRY_BEGIN( "cs", CZECH )
418         LANG_ENTRY_END( CZECH )
419 /*x06*/ LANG_ENTRY_BEGIN( "da", DANISH )
420         LANG_ENTRY_END( DANISH )
421 /*x07*/ LANG_ENTRY_BEGIN( "de", GERMAN )
422         LANG_SUB_ENTRY( "DE", GERMAN, GERMAN )
423         LANG_SUB_ENTRY( "CH", GERMAN, GERMAN_SWISS )
424         LANG_SUB_ENTRY( "AT", GERMAN, GERMAN_AUSTRIAN )
425         LANG_SUB_ENTRY( "LU", GERMAN, GERMAN_LUXEMBOURG )
426         LANG_SUB_ENTRY( "LI", GERMAN, GERMAN_LIECHTENSTEIN )
427         LANG_ENTRY_END( GERMAN )
428 /*x08*/ LANG_ENTRY_BEGIN( "el", GREEK )
429         LANG_ENTRY_END( GREEK )
430 /*x09*/ LANG_ENTRY_BEGIN( "en", ENGLISH )
431         LANG_SUB_ENTRY( "US", ENGLISH, ENGLISH_US )
432         LANG_SUB_ENTRY( "UK", ENGLISH, ENGLISH_UK )
433         LANG_SUB_ENTRY( "AU", ENGLISH, ENGLISH_AUS )
434         LANG_SUB_ENTRY( "CA", ENGLISH, ENGLISH_CAN )
435         LANG_SUB_ENTRY( "NZ", ENGLISH, ENGLISH_NZ )
436         LANG_SUB_ENTRY( "EI", ENGLISH, ENGLISH_EIRE )
437         LANG_SUB_ENTRY( "ZA", ENGLISH, ENGLISH_SAFRICA )
438         LANG_SUB_ENTRY( "JM", ENGLISH, ENGLISH_JAMAICA )
439      /* LANG_SUB_ENTRY( "AG", ENGLISH, ENGLISH_CARIBBEAN ) */
440         LANG_SUB_ENTRY( "BZ", ENGLISH, ENGLISH_BELIZE )
441         LANG_SUB_ENTRY( "TT", ENGLISH, ENGLISH_TRINIDAD )
442         LANG_SUB_ENTRY( "ZW", ENGLISH, ENGLISH_ZIMBABWE )
443         LANG_SUB_ENTRY( "PH", ENGLISH, ENGLISH_PHILIPPINES )
444         LANG_ENTRY_END( ENGLISH )
445 /*x0a*/ LANG_ENTRY_BEGIN( "es", SPANISH )
446         /* traditional sorting */
447         if (!strcmp(dialect,"tradicional"))
448                 LANG_DIALECT_ENTRY( SPANISH, SPANISH )
449         LANG_SUB_ENTRY( "MX", SPANISH, SPANISH_MEXICAN )
450         LANG_SUB_ENTRY( "ES", SPANISH, SPANISH_MODERN )
451         LANG_SUB_ENTRY( "GT", SPANISH, SPANISH_GUATEMALA )
452         LANG_SUB_ENTRY( "CR", SPANISH, SPANISH_COSTARICA )
453         LANG_SUB_ENTRY( "PA", SPANISH, SPANISH_PANAMA )
454         LANG_SUB_ENTRY( "DO", SPANISH, SPANISH_DOMINICAN )
455         LANG_SUB_ENTRY( "VE", SPANISH, SPANISH_VENEZUELA )
456         LANG_SUB_ENTRY( "CO", SPANISH, SPANISH_COLOMBIA )
457         LANG_SUB_ENTRY( "PE", SPANISH, SPANISH_PERU )
458         LANG_SUB_ENTRY( "AR", SPANISH, SPANISH_ARGENTINA )
459         LANG_SUB_ENTRY( "EC", SPANISH, SPANISH_ECUADOR )
460         LANG_SUB_ENTRY( "CL", SPANISH, SPANISH_CHILE )
461         LANG_SUB_ENTRY( "UY", SPANISH, SPANISH_URUGUAY )
462         LANG_SUB_ENTRY( "PY", SPANISH, SPANISH_PARAGUAY )
463         LANG_SUB_ENTRY( "BO", SPANISH, SPANISH_BOLIVIA )
464         LANG_SUB_ENTRY( "HN", SPANISH, SPANISH_HONDURAS )
465         LANG_SUB_ENTRY( "NI", SPANISH, SPANISH_NICARAGUA )
466         LANG_SUB_ENTRY( "PR", SPANISH, SPANISH_PUERTO_RICO )
467         LANG_ENTRY_END( SPANISH )
468 /*x0b*/ LANG_ENTRY_BEGIN( "fi", FINNISH )
469         LANG_ENTRY_END( FINNISH )
470 /*x0c*/ LANG_ENTRY_BEGIN( "fr", FRENCH )
471         LANG_SUB_ENTRY( "FR", FRENCH, FRENCH )
472         LANG_SUB_ENTRY( "BE", FRENCH, FRENCH_BELGIAN )
473         LANG_SUB_ENTRY( "CA", FRENCH, FRENCH_CANADIAN )
474         LANG_SUB_ENTRY( "CH", FRENCH, FRENCH_SWISS )
475         LANG_SUB_ENTRY( "LU", FRENCH, FRENCH_LUXEMBOURG )
476         LANG_SUB_ENTRY( "MC", FRENCH, FRENCH_MONACO )
477         LANG_ENTRY_END( FRENCH )
478 /*x0d*/ LANG_ENTRY_BEGIN( "iw", HEBREW )
479         LANG_ENTRY_END( HEBREW )
480 /*x0e*/ LANG_ENTRY_BEGIN( "hu", HUNGARIAN )
481         LANG_ENTRY_END( HUNGARIAN )
482 /*x0f*/ LANG_ENTRY_BEGIN( "ic", ICELANDIC )
483         LANG_ENTRY_END( ICELANDIC )
484 /*x10*/ LANG_ENTRY_BEGIN( "it", ITALIAN )
485         LANG_SUB_ENTRY( "IT", ITALIAN, ITALIAN )
486         LANG_SUB_ENTRY( "CH", ITALIAN, ITALIAN_SWISS )
487         LANG_ENTRY_END( ITALIAN )
488 /*x11*/ LANG_ENTRY_BEGIN( "ja", JAPANESE )
489         LANG_ENTRY_END( JAPANESE )
490 /*x12*/ LANG_ENTRY_BEGIN( "ko", KOREAN )
491         /* JOHAB encoding */
492         if (!strcmp(charset,"JOHAB"))
493                 LANG_DIALECT_ENTRY( KOREAN, KOREAN_JOHAB )
494         else
495                 LANG_DIALECT_ENTRY( KOREAN, KOREAN )
496         LANG_ENTRY_END( KOREAN )
497 /*x13*/ LANG_ENTRY_BEGIN( "nl", DUTCH )
498         LANG_SUB_ENTRY( "NL", DUTCH, DUTCH )
499         LANG_SUB_ENTRY( "BE", DUTCH, DUTCH_BELGIAN )
500         LANG_SUB_ENTRY( "SR", DUTCH, DUTCH_SURINAM )
501         LANG_ENTRY_END( DUTCH )
502 /*x14*/ LANG_ENTRY_BEGIN( "no", NORWEGIAN )
503         /* nynorsk */
504         if (!strcmp(dialect,"nynorsk"))
505                 LANG_DIALECT_ENTRY( NORWEGIAN, NORWEGIAN_NYNORSK )
506         else
507                 LANG_DIALECT_ENTRY( NORWEGIAN, NORWEGIAN_BOKMAL )
508         LANG_ENTRY_END( NORWEGIAN )
509 /*x15*/ LANG_ENTRY_BEGIN( "pl", POLISH )
510         LANG_ENTRY_END( POLISH )
511 /*x16*/ LANG_ENTRY_BEGIN( "pt", PORTUGUESE )
512         LANG_SUB_ENTRY( "BR", PORTUGUESE, PORTUGUESE_BRAZILIAN )
513         LANG_SUB_ENTRY( "PT", PORTUGUESE, PORTUGUESE )
514         LANG_ENTRY_END( PORTUGUESE )
515 /*x17*/ LANG_ENTRY_BEGIN( "rm", RHAETO_ROMANCE )
516         LANG_ENTRY_END( RHAETO_ROMANCE )
517 /*x18*/ LANG_ENTRY_BEGIN( "ro", ROMANIAN )
518         LANG_SUB_ENTRY( "RO", ROMANIAN, ROMANIAN )
519         LANG_SUB_ENTRY( "MD", ROMANIAN, ROMANIAN_MOLDAVIA )
520         LANG_ENTRY_END( ROMANIAN )
521 /*x19*/ LANG_ENTRY_BEGIN( "ru", RUSSIAN )
522         LANG_SUB_ENTRY( "RU", RUSSIAN, RUSSIAN )
523         LANG_SUB_ENTRY( "MD", RUSSIAN, RUSSIAN_MOLDAVIA )
524         LANG_ENTRY_END( RUSSIAN )
525 /*x1a*/ if (!strcmp(lang,"sh") || !strcmp(lang,"hr") || !strcmp(lang,"sr")) {
526             if (!country[0]) 
527                 LANG_DIALECT_ENTRY( SERBO_CROATIAN, NEUTRAL)
528             if (!strcmp(charset,"ISO-8859-5"))
529                 LANG_DIALECT_ENTRY( SERBO_CROATIAN, SERBIAN )
530             LANG_SUB_ENTRY( "HR", SERBO_CROATIAN, CROATIAN )
531             if (!strcmp(country,"YU") && !strcmp(charset,"ISO-8859-2"))
532                 LANG_DIALECT_ENTRY( SERBO_CROATIAN, SERBIAN_LATIN )
533             LANG_SUB_ENTRY( "YU", SERBO_CROATIAN, SERBIAN )
534             LANG_DIALECT_ENTRY( SERBO_CROATIAN, SERBIAN_LATIN )
535         }
536 /*x1b*/ LANG_ENTRY_BEGIN( "sk", SLOVAK )
537         LANG_ENTRY_END( SLOVAK )
538 /*x1c*/ LANG_ENTRY_BEGIN( "sq", ALBANIAN )
539         LANG_ENTRY_END( ALBANIAN )
540 /*x1d*/ LANG_ENTRY_BEGIN( "sv", SWEDISH )
541         LANG_SUB_ENTRY( "SE", SWEDISH, SWEDISH )
542         LANG_SUB_ENTRY( "FI", SWEDISH, SWEDISH_FINLAND )
543         LANG_ENTRY_END( SWEDISH )
544 /*x1e*/ LANG_ENTRY_BEGIN( "th", THAI )
545         LANG_ENTRY_END( THAI )
546 /*x1f*/ LANG_ENTRY_BEGIN( "tr", TURKISH )
547         LANG_ENTRY_END( TURKISH )
548 /*x20*/ LANG_ENTRY_BEGIN( "ur", URDU )
549         LANG_ENTRY_END( URDU )
550 /*x21*/ LANG_ENTRY_BEGIN( "in", INDONESIAN )
551         LANG_ENTRY_END( INDONESIAN )
552 /*x22*/ LANG_ENTRY_BEGIN( "uk", UKRAINIAN )
553         LANG_ENTRY_END( UKRAINIAN )
554 /*x23*/ LANG_ENTRY_BEGIN( "be", BYELORUSSIAN )
555         LANG_ENTRY_END( BYELORUSSIAN )
556 /*x24*/ LANG_ENTRY_BEGIN( "sl", SLOVENIAN )
557         LANG_ENTRY_END( SLOVENIAN )
558 /*x25*/ LANG_ENTRY_BEGIN( "et", ESTONIAN )
559         LANG_ENTRY_END( ESTONIAN )
560 /*x26*/ LANG_ENTRY_BEGIN( "lv", LATVIAN )
561         LANG_ENTRY_END( LATVIAN )
562 /*x27*/ LANG_ENTRY_BEGIN( "lt", LITHUANIAN )
563         /* traditional sorting ? */
564         if (!strcmp(dialect,"classic") || !strcmp(dialect,"traditional"))
565                 LANG_DIALECT_ENTRY( LITHUANIAN, LITHUANIAN_CLASSIC )
566         else
567                 LANG_DIALECT_ENTRY( LITHUANIAN, LITHUANIAN )
568         LANG_ENTRY_END( LITHUANIAN )
569 /*x28*/ LANG_ENTRY_BEGIN( "mi", MAORI )
570         LANG_ENTRY_END( MAORI )
571 /*x29*/ LANG_ENTRY_BEGIN( "fa", FARSI )
572         LANG_ENTRY_END( FARSI )
573 /*x2a*/ LANG_ENTRY_BEGIN( "vi", VIETNAMESE )
574         LANG_ENTRY_END( VIETNAMESE )
575 /*x2b*/ LANG_ENTRY_BEGIN( "hy", ARMENIAN )
576         LANG_ENTRY_END( ARMENIAN )
577 /*x2c*/ LANG_ENTRY_BEGIN( "az", AZERI )
578         /* Cyrillic */
579         if (strstr(charset,"KOI8") || !strcmp(charset,"ISO-8859-5"))
580                 LANG_DIALECT_ENTRY( AZERI, AZERI_CYRILLIC )
581         else
582                 LANG_DIALECT_ENTRY( AZERI, AZERI )
583         LANG_ENTRY_END( AZERI )
584 /*x2d*/ LANG_ENTRY_BEGIN( "eu", BASQUE )
585         LANG_ENTRY_END( BASQUE )
586 /*x2e*/ /*LANG_ENTRY_BEGIN( "??", SORBIAN )
587         LANG_ENTRY_END( SORBIAN ) */
588 /*x2f*/ LANG_ENTRY_BEGIN( "mk", MACEDONIAN )
589         LANG_ENTRY_END( MACEDONIAN )
590 /*x30*/ /*LANG_ENTRY_BEGIN( "??", SUTU )
591         LANG_ENTRY_END( SUTU ) */
592 /*x31*/ LANG_ENTRY_BEGIN( "ts", TSONGA )
593         LANG_ENTRY_END( TSONGA )
594 /*x32*/ /*LANG_ENTRY_BEGIN( "??", TSWANA )
595         LANG_ENTRY_END( TSWANA ) */
596 /*x33*/ /*LANG_ENTRY_BEGIN( "??", VENDA )
597         LANG_ENTRY_END( VENDA ) */
598 /*x34*/ LANG_ENTRY_BEGIN( "xh", XHOSA )
599         LANG_ENTRY_END( XHOSA )
600 /*x35*/ LANG_ENTRY_BEGIN( "zu", ZULU )
601         LANG_ENTRY_END( ZULU )
602 /*x36*/ LANG_ENTRY_BEGIN( "af", AFRIKAANS )
603         LANG_ENTRY_END( AFRIKAANS )
604 /*x37*/ LANG_ENTRY_BEGIN( "ka", GEORGIAN )
605         LANG_ENTRY_END( GEORGIAN )
606 /*x38*/ LANG_ENTRY_BEGIN( "fo", FAEROESE )
607         LANG_ENTRY_END( FAEROESE )
608 /*x39*/ LANG_ENTRY_BEGIN( "hi", HINDI )
609         LANG_ENTRY_END( HINDI )
610 /*x3a*/ LANG_ENTRY_BEGIN( "mt", MALTESE )
611         LANG_ENTRY_END( MALTESE )
612 /*x3b*/ /*LANG_ENTRY_BEGIN( "??", SAAMI )
613         LANG_ENTRY_END( SAAMI ) */
614 /*x3c*/ LANG_ENTRY_BEGIN( "ga", GAELIC )
615         LANG_DIALECT_ENTRY( GAELIC, GAELIC )
616         LANG_ENTRY_END( GAELIC )
617 /*x3c*/ LANG_ENTRY_BEGIN( "gd", GAELIC )
618         LANG_DIALECT_ENTRY( GAELIC, GAELIC_SCOTTISH )
619         LANG_ENTRY_END( GAELIC )
620 /* 0x3d */
621 /*x3e*/ LANG_ENTRY_BEGIN( "ms", MALAY )
622         LANG_SUB_ENTRY( "MY", MALAY, MALAY )
623         LANG_SUB_ENTRY( "BN", MALAY, MALAY_BRUNEI_DARUSSALAM )
624         LANG_ENTRY_END( MALAY )
625 /*x3f*/ LANG_ENTRY_BEGIN( "kk", KAZAKH )
626         LANG_ENTRY_END( KAZAKH )
627 /* 0x40 */
628 /*x41*/ LANG_ENTRY_BEGIN( "sw", SWAHILI )
629         LANG_ENTRY_END( SWAHILI )
630 /* 0x42 */
631 /*x43*/ LANG_ENTRY_BEGIN( "uz", UZBEK )
632         /* Cyrillic */
633         if (strstr(charset,"KOI8") || !strcmp(charset,"ISO-8859-5"))
634                 LANG_DIALECT_ENTRY( UZBEK, UZBEK_CYRILLIC )
635         else
636                 LANG_DIALECT_ENTRY( UZBEK, UZBEK )
637         LANG_ENTRY_END( UZBEK )
638 /*x44*/ LANG_ENTRY_BEGIN( "tt", TATAR )
639         LANG_ENTRY_END( TATAR )
640 /*x45*/ LANG_ENTRY_BEGIN( "bn", BENGALI )
641         LANG_ENTRY_END( BENGALI )
642 /*x46*/ LANG_ENTRY_BEGIN( "pa", PUNJABI )
643         LANG_ENTRY_END( PUNJABI )
644 /*x47*/ LANG_ENTRY_BEGIN( "gu", GUJARATI )
645         LANG_ENTRY_END( GUJARATI )
646 /*x48*/ LANG_ENTRY_BEGIN( "or", ORIYA )
647         LANG_ENTRY_END( ORIYA )
648 /*x49*/ LANG_ENTRY_BEGIN( "ta", TAMIL )
649         LANG_ENTRY_END( TAMIL )
650 /*x4a*/ LANG_ENTRY_BEGIN( "te", TELUGU )
651         LANG_ENTRY_END( TELUGU )
652 /*x4b*/ LANG_ENTRY_BEGIN( "kn", KANNADA )
653         LANG_ENTRY_END( KANNADA )
654 /*x4c*/ LANG_ENTRY_BEGIN( "ml", MALAYALAM )
655         LANG_ENTRY_END( MALAYALAM )
656 /*x4d*/ LANG_ENTRY_BEGIN( "as", ASSAMESE )
657         LANG_ENTRY_END( ASSAMESE )
658 /*x4e*/ LANG_ENTRY_BEGIN( "mr", MARATHI )
659         LANG_ENTRY_END( MARATHI )
660 /*x4f*/ LANG_ENTRY_BEGIN( "sa", SANSKRIT )
661         LANG_ENTRY_END( SANSKRIT )
662 /* 0x50 -> 0x56 */
663 /*x57*/ /*LANG_ENTRY_BEGIN( "??", KONKANI )
664         LANG_ENTRY_END( KONKANI ) */
665 /* 0x58 -> ... */
666         LANG_ENTRY_BEGIN( "eo", ESPERANTO ) /* not official */
667         LANG_ENTRY_END( ESPERANTO )
668         LANG_ENTRY_BEGIN( "wa", WALON ) /* not official */ 
669         LANG_ENTRY_END( WALON )
670
671         ret = LANG_ENGLISH;
672
673 end_MAIN_GetLanguageID:
674         if (Charset) free(charset);
675         free(dialect);
676
677         return ret;
678 }
679
680 /***********************************************************************
681  *           MAIN_ParseLanguageOption
682  *
683  * Parse -language option.
684  */
685 void MAIN_ParseLanguageOption( char *arg )
686 {
687     const WINE_LANGUAGE_DEF *p = Languages;
688
689 /* for compatibility whith non-iso names previously used */
690     if (!strcmp("Sw",arg)) { strcpy(arg,"Sv"); FIXME_(system)("use 'Sv' instead of 'Sw'\n");}
691     if (!strcmp("Cz",arg)) { strcpy(arg,"Cs"); FIXME_(system)("use 'Cs' instead of 'Cz'\n");}
692     if (!strcmp("Po",arg)) { strcpy(arg,"Pt"); FIXME_(system)("use 'Pt' instead of 'Po'\n");}
693
694     Options.language = LANG_Xx;  /* First (dummy) language */
695     for (;p->name;p++)
696     {
697         if (!lstrcmpiA( p->name, arg ))
698         {
699             WINE_LanguageId = p->langid;
700             return;
701         }
702         Options.language++;
703     }
704     MESSAGE( "Invalid language specified '%s'. Supported languages are: ", arg );
705     for (p = Languages; p->name; p++) MESSAGE( "%s ", p->name );
706     MESSAGE( "\n" );
707     ExitProcess(1);
708 }
709
710
711 /***********************************************************************
712  *           MAIN_ParseOptions
713  *
714  * Parse command line options and open display.
715  */
716 static void MAIN_ParseOptions( int *argc, char *argv[] )
717 {
718     int i;
719     char *pcDot;
720
721     Options.argc = argc;
722     Options.argv = argv;
723     Options.programName = MAIN_GetProgramName( *argc, argv );
724
725     /* initialise Options.language to 0 to tell "no language choosen yet" */
726     Options.language = 0;
727   
728     /* make sure there is no "." in Options.programName to confuse the X
729        resource database lookups */
730     if ((pcDot = strchr(Options.programName, '.'))) *pcDot = '\0';
731
732     for (i = 1; i < *argc; i++)
733     {
734         if (!strcmp( argv[i], "-v" ) || !strcmp( argv[i], "-version" ))
735         {
736             MESSAGE( "%s\n", WINE_RELEASE_INFO );
737             ExitProcess(0);
738         }
739         if (!strcmp( argv[i], "-h" ) || !strcmp( argv[i], "-help" ))
740         {
741             MAIN_Usage(argv[0]);
742             ExitProcess(0);
743         }
744     }
745 }
746
747 /***********************************************************************
748  *           called_at_exit
749  */
750 static void called_at_exit(void)
751 {
752     if (GDI_Driver)
753         GDI_Driver->pFinalize();
754     if (USER_Driver)
755         USER_Driver->pFinalize();
756
757     CONSOLE_Close();
758 }
759
760 /***********************************************************************
761  *           MAIN_WineInit
762  *
763  * Wine initialisation and command-line parsing
764  */
765 BOOL MAIN_WineInit( int *argc, char *argv[] )
766 {    
767     struct timeval tv;
768
769 #ifdef MALLOC_DEBUGGING
770     char *trace;
771
772     mcheck(NULL);
773     if (!(trace = getenv("MALLOC_TRACE")))
774     {       
775         MESSAGE( "MALLOC_TRACE not set. No trace generated\n" );
776     }
777     else
778     {
779         MESSAGE( "malloc trace goes to %s\n", trace );
780         mtrace();
781     }
782 #endif
783
784     setbuf(stdout,NULL);
785     setbuf(stderr,NULL);
786
787     setlocale(LC_CTYPE,"");
788     gettimeofday( &tv, NULL);
789     MSG_WineStartTicks = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
790     
791     MAIN_ParseOptions(argc, argv);
792
793 #ifndef X_DISPLAY_MISSING
794     USER_Driver = &X11DRV_USER_Driver;
795 #else /* !defined(X_DISPLAY_MISSING) */
796     USER_Driver = &TTYDRV_USER_Driver;
797 #endif /* !defined(X_DISPLAY_MISSING) */
798
799     USER_Driver->pInitialize();
800
801     MONITOR_Initialize(&MONITOR_PrimaryMonitor);
802
803     atexit(called_at_exit);
804     return TRUE;
805 }
806
807 /***********************************************************************
808  *           MessageBeep16   (USER.104)
809  */
810 void WINAPI MessageBeep16( UINT16 i )
811 {
812     MessageBeep( i );
813 }
814
815
816 /***********************************************************************
817  *           MessageBeep32   (USER32.390)
818  */
819 BOOL WINAPI MessageBeep( UINT i )
820 {
821     KEYBOARD_Beep();
822     return TRUE;
823 }
824
825
826 /***********************************************************************
827  *           Beep   (KERNEL32.11)
828  */
829 BOOL WINAPI Beep( DWORD dwFreq, DWORD dwDur )
830 {
831     /* dwFreq and dwDur are ignored by Win95 */
832     KEYBOARD_Beep();
833     return TRUE;
834 }
835
836
837 /***********************************************************************
838  *      GetTimerResolution (USER.14)
839  */
840 LONG WINAPI GetTimerResolution16(void)
841 {
842         return (1000);
843 }
844
845 /***********************************************************************
846  *      SystemParametersInfo32A   (USER32.540)
847  */
848 BOOL WINAPI SystemParametersInfoA( UINT uAction, UINT uParam,
849                                        LPVOID lpvParam, UINT fuWinIni )
850 {
851         int timeout;
852
853         switch (uAction) {
854         case SPI_GETBEEP:
855                 *(BOOL *) lpvParam = KEYBOARD_GetBeepActive();
856                 break;
857         case SPI_SETBEEP:
858                KEYBOARD_SetBeepActive(uParam);
859                break;
860
861         case SPI_GETBORDER:
862                 *(INT *)lpvParam = GetSystemMetrics( SM_CXFRAME );
863                 break;
864
865         case SPI_GETDRAGFULLWINDOWS:
866                 *(BOOL *) lpvParam = FALSE;
867                 break;
868
869         case SPI_SETDRAGFULLWINDOWS:
870                 break;
871
872         case SPI_GETFASTTASKSWITCH:
873                 if ( GetProfileIntA( "windows", "CoolSwitch", 1 ) == 1 )
874                         *(BOOL *) lpvParam = TRUE;
875                 else
876                         *(BOOL *) lpvParam = FALSE;
877                 break;
878                 
879         case SPI_GETGRIDGRANULARITY:
880                 *(INT*)lpvParam=GetProfileIntA("desktop","GridGranularity",1);
881                 break;
882
883         case SPI_GETICONTITLEWRAP:
884                 *(BOOL*)lpvParam=GetProfileIntA("desktop","IconTitleWrap",TRUE);
885                 break;
886
887         case SPI_GETKEYBOARDDELAY:
888                 *(INT*)lpvParam=GetProfileIntA("keyboard","KeyboardDelay",1);
889                 break;
890
891         case SPI_GETKEYBOARDSPEED:
892                 *(DWORD*)lpvParam=GetProfileIntA("keyboard","KeyboardSpeed",30);
893                 break;
894
895         case SPI_GETMENUDROPALIGNMENT:
896                 *(BOOL*)lpvParam=GetSystemMetrics(SM_MENUDROPALIGNMENT); /* XXX check this */
897                 break;
898
899         case SPI_GETSCREENSAVEACTIVE:           
900                if(MONITOR_GetScreenSaveActive(&MONITOR_PrimaryMonitor) || 
901                   GetProfileIntA( "windows", "ScreenSaveActive", 1 ) == 1)
902                         *(BOOL*)lpvParam = TRUE;
903                 else
904                         *(BOOL*)lpvParam = FALSE;
905                 break;
906
907         case SPI_GETSCREENSAVETIMEOUT:
908                 timeout = MONITOR_GetScreenSaveTimeout(&MONITOR_PrimaryMonitor);
909                 if(!timeout)
910                         timeout = GetProfileIntA( "windows", "ScreenSaveTimeout", 300 );
911                 *(INT *) lpvParam = timeout * 1000;
912                 break;
913
914         case SPI_ICONHORIZONTALSPACING:
915                 /* FIXME Get/SetProfileInt */
916                 if (lpvParam == NULL)
917                         /*SetSystemMetrics( SM_CXICONSPACING, uParam )*/ ;
918                 else
919                         *(INT*)lpvParam=GetSystemMetrics(SM_CXICONSPACING);
920                 break;
921
922         case SPI_ICONVERTICALSPACING:
923                 /* FIXME Get/SetProfileInt */
924                 if (lpvParam == NULL)
925                         /*SetSystemMetrics( SM_CYICONSPACING, uParam )*/ ;
926                 else
927                         *(INT*)lpvParam=GetSystemMetrics(SM_CYICONSPACING);
928                 break;
929
930         case SPI_GETICONTITLELOGFONT: {
931                 LPLOGFONTA lpLogFont = (LPLOGFONTA)lpvParam;
932
933                 /* from now on we always have an alias for MS Sans Serif */
934
935                 GetProfileStringA("Desktop", "IconTitleFaceName", "MS Sans Serif", 
936                         lpLogFont->lfFaceName, LF_FACESIZE );
937                 lpLogFont->lfHeight = -GetProfileIntA("Desktop","IconTitleSize", 13);
938                 lpLogFont->lfWidth = 0;
939                 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
940                 lpLogFont->lfWeight = FW_NORMAL;
941                 lpLogFont->lfItalic = FALSE;
942                 lpLogFont->lfStrikeOut = FALSE;
943                 lpLogFont->lfUnderline = FALSE;
944                 lpLogFont->lfCharSet = ANSI_CHARSET;
945                 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
946                 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
947                 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
948                 break;
949         }
950
951         case SPI_GETICONMETRICS: {
952             LPICONMETRICSA lpIcon = lpvParam;
953             if(!lpIcon || lpIcon->cbSize != sizeof(*lpIcon))
954                 return FALSE;
955             SystemParametersInfoA( SPI_ICONHORIZONTALSPACING, 0,
956                                    &lpIcon->iHorzSpacing, FALSE );
957             SystemParametersInfoA( SPI_ICONVERTICALSPACING, 0,
958                                    &lpIcon->iVertSpacing, FALSE );
959             SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0,
960                                    &lpIcon->iTitleWrap, FALSE );
961             SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0,
962                                    &lpIcon->lfFont, FALSE );
963             break;
964         }
965         case SPI_GETWORKAREA:
966                 SetRect( (RECT *)lpvParam, 0, 0,
967                         GetSystemMetrics( SM_CXSCREEN ),
968                         GetSystemMetrics( SM_CYSCREEN )
969                 );
970                 break;
971         case SPI_GETNONCLIENTMETRICS: 
972
973 #define lpnm ((LPNONCLIENTMETRICSA)lpvParam)
974                 
975                 if( lpnm->cbSize == sizeof(NONCLIENTMETRICSA) )
976                 {
977                     LPLOGFONTA lpLogFont = &(lpnm->lfMenuFont);
978                 
979                     /* clear the struct, so we have 'sane' members */
980                     memset(
981                         (char*)lpvParam+sizeof(lpnm->cbSize),
982                         0,
983                         lpnm->cbSize-sizeof(lpnm->cbSize)
984                     );
985
986                     /* FIXME: initialize geometry entries */
987                     /* FIXME: As these values are presumably in device units,
988                      *  we should calculate the defaults based on the screen dpi
989                      */
990                     /* caption */
991                     lpnm->iCaptionWidth = ((TWEAK_WineLook > WIN31_LOOK)  ? 32 : 20);
992                     lpnm->iCaptionHeight = lpnm->iCaptionWidth;
993                     lpnm->lfCaptionFont.lfWeight = FW_BOLD;
994                     SystemParametersInfoA(SPI_GETICONTITLELOGFONT, 0, (LPVOID)&(lpnm->lfCaptionFont),0);
995
996                     /* small caption */
997                     lpnm->iSmCaptionWidth = ((TWEAK_WineLook > WIN31_LOOK)  ? 32 : 17);
998                     lpnm->iSmCaptionHeight = lpnm->iSmCaptionWidth;
999                     SystemParametersInfoA(SPI_GETICONTITLELOGFONT, 0, (LPVOID)&(lpnm->lfSmCaptionFont),0);
1000
1001                     /* menus, FIXME: names of wine.conf entrys are bogus */
1002
1003                     lpnm->iMenuWidth = GetProfileIntA("Desktop","MenuWidth", 13);       /* size of the menu buttons*/
1004                     lpnm->iMenuHeight = GetProfileIntA("Desktop","MenuHeight", 
1005                                                 (TWEAK_WineLook > WIN31_LOOK) ? 13 : 27);
1006
1007                     GetProfileStringA("Desktop", "MenuFont", 
1008                         (TWEAK_WineLook > WIN31_LOOK) ? "MS Sans Serif": "System", 
1009                         lpLogFont->lfFaceName, LF_FACESIZE );
1010
1011                     lpLogFont->lfHeight = -GetProfileIntA("Desktop","MenuFontSize", 13);
1012                     lpLogFont->lfWidth = 0;
1013                     lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1014                     lpLogFont->lfWeight = (TWEAK_WineLook > WIN31_LOOK) ? FW_NORMAL : FW_BOLD;
1015                     lpLogFont->lfItalic = FALSE;
1016                     lpLogFont->lfStrikeOut = FALSE;
1017                     lpLogFont->lfUnderline = FALSE;
1018                     lpLogFont->lfCharSet = ANSI_CHARSET;
1019                     lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1020                     lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1021                     lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1022
1023                     SystemParametersInfoA(SPI_GETICONTITLELOGFONT, 0,
1024                                                         (LPVOID)&(lpnm->lfStatusFont),0);
1025                     SystemParametersInfoA(SPI_GETICONTITLELOGFONT, 0,
1026                                                         (LPVOID)&(lpnm->lfMessageFont),0);
1027                 }
1028 #undef lpnm
1029                 break;
1030
1031         case SPI_GETANIMATION: {
1032                 LPANIMATIONINFO lpAnimInfo = (LPANIMATIONINFO)lpvParam;
1033  
1034                 /* Tell it "disabled" */
1035                 lpAnimInfo->cbSize = sizeof(ANIMATIONINFO);
1036                 uParam = sizeof(ANIMATIONINFO);
1037                 lpAnimInfo->iMinAnimate = 0; /* Minimise and restore animation is disabled (nonzero == enabled) */
1038                 break;
1039         }
1040  
1041         case SPI_SETANIMATION: {
1042                 LPANIMATIONINFO lpAnimInfo = (LPANIMATIONINFO)lpvParam;
1043  
1044                 /* Do nothing */
1045                 WARN_(system)("SPI_SETANIMATION ignored.\n");
1046                 lpAnimInfo->cbSize = sizeof(ANIMATIONINFO);
1047                 uParam = sizeof(ANIMATIONINFO);
1048                 break;
1049         }
1050
1051         case SPI_GETHIGHCONTRAST:
1052         {
1053                 LPHIGHCONTRASTA lpHighContrastA = (LPHIGHCONTRASTA)lpvParam;
1054
1055                 FIXME_(system)("SPI_GETHIGHCONTRAST not fully implemented\n");
1056
1057                 if ( lpHighContrastA->cbSize == sizeof( HIGHCONTRASTA ) )
1058                 {
1059                         /* Indicate that there is no high contrast available */
1060                         lpHighContrastA->dwFlags = 0;
1061                         lpHighContrastA->lpszDefaultScheme = NULL;
1062                 }
1063                 else
1064                 {
1065                         return FALSE;
1066                 }
1067
1068                 break;
1069         }
1070
1071         default:
1072                 return SystemParametersInfo16(uAction,uParam,lpvParam,fuWinIni);
1073         }
1074         return TRUE;
1075 }
1076
1077
1078 /***********************************************************************
1079  *      SystemParametersInfo16   (USER.483)
1080  */
1081 BOOL16 WINAPI SystemParametersInfo16( UINT16 uAction, UINT16 uParam,
1082                                       LPVOID lpvParam, UINT16 fuWinIni )
1083 {
1084         int timeout; 
1085         char buffer[256];
1086
1087         switch (uAction)
1088         {
1089                 case SPI_GETBEEP:
1090                         *(BOOL *) lpvParam = KEYBOARD_GetBeepActive();
1091                         break;
1092                 
1093                 case SPI_GETBORDER:
1094                         *(INT16 *)lpvParam = GetSystemMetrics16( SM_CXFRAME );
1095                         break;
1096
1097                 case SPI_GETFASTTASKSWITCH:
1098                     if ( GetProfileIntA( "windows", "CoolSwitch", 1 ) == 1 )
1099                           *(BOOL16 *) lpvParam = TRUE;
1100                         else
1101                           *(BOOL16 *) lpvParam = FALSE;
1102                         break;
1103
1104                 case SPI_GETGRIDGRANULARITY:
1105                     *(INT16 *) lpvParam = GetProfileIntA( "desktop", 
1106                                                           "GridGranularity",
1107                                                           1 );
1108                     break;
1109
1110                 case SPI_GETICONTITLEWRAP:
1111                     *(BOOL16 *) lpvParam = GetProfileIntA( "desktop",
1112                                                            "IconTitleWrap",
1113                                                            TRUE );
1114                     break;
1115
1116                 case SPI_GETKEYBOARDDELAY:
1117                     *(INT16 *) lpvParam = GetProfileIntA( "keyboard",
1118                                                           "KeyboardDelay", 1 );
1119                     break;
1120
1121                 case SPI_GETKEYBOARDSPEED:
1122                     *(WORD *) lpvParam = GetProfileIntA( "keyboard",
1123                                                            "KeyboardSpeed",
1124                                                            30 );
1125                     break;
1126
1127                 case SPI_GETMENUDROPALIGNMENT:
1128                         *(BOOL16 *) lpvParam = GetSystemMetrics16( SM_MENUDROPALIGNMENT ); /* XXX check this */
1129                         break;
1130
1131                 case SPI_GETSCREENSAVEACTIVE:
1132                   if(MONITOR_GetScreenSaveActive(&MONITOR_PrimaryMonitor) ||
1133                      GetProfileIntA( "windows", "ScreenSaveActive", 1 ) == 1)
1134                         *(BOOL16 *) lpvParam = TRUE;
1135                     else
1136                         *(BOOL16 *) lpvParam = FALSE;
1137                     break;
1138
1139                 case SPI_GETSCREENSAVETIMEOUT:
1140                         timeout = MONITOR_GetScreenSaveTimeout(&MONITOR_PrimaryMonitor);
1141                         if(!timeout)
1142                             timeout = GetProfileIntA( "windows", "ScreenSaveTimeout", 300 );
1143                         *(INT16 *) lpvParam = timeout;
1144                         break;
1145
1146                 case SPI_ICONHORIZONTALSPACING:
1147                     /* FIXME Get/SetProfileInt */
1148                         if (lpvParam == NULL)
1149                             /*SetSystemMetrics( SM_CXICONSPACING, uParam )*/ ;
1150                         else
1151                             *(INT16 *)lpvParam = GetSystemMetrics16( SM_CXICONSPACING );
1152                         break;
1153
1154                 case SPI_ICONVERTICALSPACING:
1155                     /* FIXME Get/SetProfileInt */
1156                     if (lpvParam == NULL)
1157                         /*SetSystemMetrics( SM_CYICONSPACING, uParam )*/ ;
1158                     else
1159                         *(INT16 *)lpvParam = GetSystemMetrics16(SM_CYICONSPACING);
1160                     break;
1161
1162                 case SPI_SETBEEP:
1163                         KEYBOARD_SetBeepActive(uParam);
1164                         break;
1165
1166                 case SPI_SETSCREENSAVEACTIVE:
1167                         MONITOR_SetScreenSaveActive(&MONITOR_PrimaryMonitor, uParam);
1168                         break;
1169
1170                 case SPI_SETSCREENSAVETIMEOUT:
1171                         MONITOR_SetScreenSaveTimeout(&MONITOR_PrimaryMonitor, uParam);
1172                         break;
1173
1174                 case SPI_SETDESKWALLPAPER:
1175                         return (SetDeskWallPaper((LPSTR) lpvParam));
1176                         break;
1177
1178                 case SPI_SETDESKPATTERN:
1179                         if ((INT16)uParam == -1) {
1180                                 GetProfileStringA("Desktop", "Pattern", 
1181                                                 "170 85 170 85 170 85 170 85", 
1182                                                 buffer, sizeof(buffer) );
1183                                 return (DESKTOP_SetPattern((LPSTR) buffer));
1184                         } else
1185                                 return (DESKTOP_SetPattern((LPSTR) lpvParam));
1186                         break;
1187
1188                 case SPI_GETICONTITLELOGFONT: 
1189                 {
1190                     LPLOGFONT16 lpLogFont = (LPLOGFONT16)lpvParam;
1191                     GetProfileStringA("Desktop", "IconTitleFaceName", "MS Sans Serif", 
1192                                         lpLogFont->lfFaceName, LF_FACESIZE );
1193                     lpLogFont->lfHeight = -GetProfileIntA("Desktop","IconTitleSize", 13);
1194                     lpLogFont->lfWidth = 0;
1195                     lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1196                     lpLogFont->lfWeight = FW_NORMAL;
1197                     lpLogFont->lfItalic = FALSE;
1198                     lpLogFont->lfStrikeOut = FALSE;
1199                     lpLogFont->lfUnderline = FALSE;
1200                     lpLogFont->lfCharSet = ANSI_CHARSET;
1201                     lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1202                     lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1203                     lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1204                     break;
1205                 }
1206                 case SPI_GETNONCLIENTMETRICS:
1207
1208 #define lpnm ((LPNONCLIENTMETRICS16)lpvParam)
1209                     if( lpnm->cbSize == sizeof(NONCLIENTMETRICS16) )
1210                     {
1211                         /* clear the struct, so we have 'sane' members */
1212                         memset(
1213                             (char*)lpvParam+sizeof(lpnm->cbSize),
1214                             0,
1215                             lpnm->cbSize-sizeof(lpnm->cbSize)
1216                         );
1217                         /* FIXME: initialize geometry entries */
1218                         SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0, 
1219                                                         (LPVOID)&(lpnm->lfCaptionFont),0);
1220                         lpnm->lfCaptionFont.lfWeight = FW_BOLD;
1221                         SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1222                                                         (LPVOID)&(lpnm->lfSmCaptionFont),0);
1223                         SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1224                                                         (LPVOID)&(lpnm->lfMenuFont),0);
1225                         SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1226                                                         (LPVOID)&(lpnm->lfStatusFont),0);
1227                         SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
1228                                                         (LPVOID)&(lpnm->lfMessageFont),0);
1229                     }
1230                     else /* winfile 95 sets sbSize to 340 */
1231                         SystemParametersInfoA( uAction, uParam, lpvParam, fuWinIni );
1232 #undef lpnm
1233                     break;
1234
1235                 case SPI_LANGDRIVER:
1236                 case SPI_SETBORDER:
1237                 case SPI_SETDOUBLECLKHEIGHT:
1238                 case SPI_SETDOUBLECLICKTIME:
1239                 case SPI_SETDOUBLECLKWIDTH:
1240                 case SPI_SETFASTTASKSWITCH:
1241                 case SPI_SETKEYBOARDDELAY:
1242                 case SPI_SETKEYBOARDSPEED:
1243                         WARN_(system)("Option %d ignored.\n", uAction);
1244                         break;
1245
1246                 case SPI_GETWORKAREA:
1247                     SetRect16( (RECT16 *)lpvParam, 0, 0,
1248                                GetSystemMetrics16( SM_CXSCREEN ),
1249                                GetSystemMetrics16( SM_CYSCREEN ) );
1250                     break;
1251
1252                 default:
1253                         FIXME_(system)("Unknown option %d.\n", uAction);
1254                         SetLastError(ERROR_INVALID_SPI_VALUE);
1255                         return 0;
1256         }
1257         return 1;
1258 }
1259
1260 /***********************************************************************
1261  *      SystemParametersInfo32W   (USER32.541)
1262  */
1263 BOOL WINAPI SystemParametersInfoW( UINT uAction, UINT uParam,
1264                                        LPVOID lpvParam, UINT fuWinIni )
1265 {
1266     char buffer[256];
1267
1268     switch (uAction)
1269     {
1270     case SPI_SETDESKWALLPAPER:
1271         if (lpvParam)
1272         {
1273             lstrcpynWtoA(buffer,(LPWSTR)lpvParam,sizeof(buffer));
1274             return SetDeskWallPaper(buffer);
1275         }
1276         return SetDeskWallPaper(NULL);
1277
1278     case SPI_SETDESKPATTERN:
1279         if ((INT) uParam == -1)
1280         {
1281             GetProfileStringA("Desktop", "Pattern", 
1282                                 "170 85 170 85 170 85 170 85", 
1283                                 buffer, sizeof(buffer) );
1284             return (DESKTOP_SetPattern((LPSTR) buffer));
1285         }
1286         if (lpvParam)
1287         {
1288             lstrcpynWtoA(buffer,(LPWSTR)lpvParam,sizeof(buffer));
1289             return DESKTOP_SetPattern(buffer);
1290         }
1291         return DESKTOP_SetPattern(NULL);
1292
1293     case SPI_GETICONTITLELOGFONT:
1294         {
1295             LPLOGFONTW lpLogFont = (LPLOGFONTW)lpvParam;
1296
1297             GetProfileStringA("Desktop", "IconTitleFaceName", "MS Sans Serif", 
1298                          buffer, sizeof(buffer) );
1299             lstrcpynAtoW(lpLogFont->lfFaceName, buffer, LF_FACESIZE);
1300             lpLogFont->lfHeight = 17;
1301             lpLogFont->lfWidth = 0;
1302             lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1303             lpLogFont->lfWeight = FW_NORMAL;
1304             lpLogFont->lfItalic = lpLogFont->lfStrikeOut = lpLogFont->lfUnderline = FALSE;
1305             lpLogFont->lfCharSet = ANSI_CHARSET;
1306             lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1307             lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1308             lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1309         }
1310         break;
1311         case SPI_GETICONMETRICS: {
1312             LPICONMETRICSW lpIcon = lpvParam;
1313             if(!lpIcon || lpIcon->cbSize != sizeof(*lpIcon))
1314                 return FALSE;
1315             SystemParametersInfoW( SPI_ICONHORIZONTALSPACING, 0,
1316                                    &lpIcon->iHorzSpacing, FALSE );
1317             SystemParametersInfoW( SPI_ICONVERTICALSPACING, 0,
1318                                    &lpIcon->iVertSpacing, FALSE );
1319             SystemParametersInfoW( SPI_GETICONTITLEWRAP, 0,
1320                                    &lpIcon->iTitleWrap, FALSE );
1321             SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0,
1322                                    &lpIcon->lfFont, FALSE );
1323             break;
1324         }
1325     case SPI_GETNONCLIENTMETRICS: {
1326         /* FIXME: implement correctly */
1327         LPNONCLIENTMETRICSW     lpnm=(LPNONCLIENTMETRICSW)lpvParam;
1328
1329         /* clear the struct, so we have 'sane' members */
1330         memset((char*)lpvParam+sizeof(lpnm->cbSize),
1331                 0,
1332                 lpnm->cbSize-sizeof(lpnm->cbSize)
1333         );
1334         SystemParametersInfoW(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfCaptionFont),0);
1335         lpnm->lfCaptionFont.lfWeight = FW_BOLD;
1336         SystemParametersInfoW(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfSmCaptionFont),0);
1337         SystemParametersInfoW(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfMenuFont),0);
1338         SystemParametersInfoW(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfStatusFont),0);
1339         SystemParametersInfoW(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfMessageFont),0);
1340         break;
1341     }
1342
1343     case SPI_GETHIGHCONTRAST:
1344     {
1345        LPHIGHCONTRASTW lpHighContrastW = (LPHIGHCONTRASTW)lpvParam;
1346
1347        FIXME_(system)("SPI_GETHIGHCONTRAST not fully implemented\n");
1348
1349        if ( lpHighContrastW->cbSize == sizeof( HIGHCONTRASTW ) )
1350        {
1351           /* Indicate that there is no high contrast available */
1352           lpHighContrastW->dwFlags = 0;
1353           lpHighContrastW->lpszDefaultScheme = NULL;
1354        }
1355        else
1356        {
1357           return FALSE;
1358        }
1359
1360        break;
1361     }
1362
1363     default:
1364         return SystemParametersInfoA(uAction,uParam,lpvParam,fuWinIni);
1365         
1366     }
1367     return TRUE;
1368 }
1369
1370
1371 /***********************************************************************
1372 *       FileCDR (KERNEL.130)
1373 */
1374 FARPROC16 WINAPI FileCDR16(FARPROC16 x)
1375 {
1376         FIXME_(file)("(0x%8x): stub\n", (int) x);
1377         return (FARPROC16)TRUE;
1378 }