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