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