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