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