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