Release 980517
[wine/multimedia.git] / misc / main.c
blob6d7f47d544d6be9fea2f7856d9edae6d3eefb27a
1 /*
2 * Main function.
4 * Copyright 1994 Alexandre Julliard
5 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <unistd.h>
11 #include <ctype.h>
12 /* #include <locale.h> */
13 #ifdef MALLOC_DEBUGGING
14 #include <malloc.h>
15 #endif
16 #include "ts_xlib.h"
17 #include "ts_xresource.h"
18 #include "ts_xutil.h"
19 #include <X11/Xlocale.h>
20 #include <X11/cursorfont.h>
21 #include "winsock.h"
22 #include "heap.h"
23 #include "message.h"
24 #include "msdos.h"
25 #include "windows.h"
26 #include "color.h"
27 #include "options.h"
28 #include "desktop.h"
29 #include "process.h"
30 #include "shell.h"
31 #include "winbase.h"
32 #include "debug.h"
33 #include "debugdefs.h"
34 #include "xmalloc.h"
35 #include "version.h"
37 const WINE_LANGUAGE_DEF Languages[] =
39 {"En",0x0409}, /* LANG_En */
40 {"Es",0x040A}, /* LANG_Es */
41 {"De",0x0407}, /* LANG_De */
42 {"No",0x0414}, /* LANG_No */
43 {"Fr",0x0400}, /* LANG_Fr */
44 {"Fi",0x040B}, /* LANG_Fi */
45 {"Da",0x0406}, /* LANG_Da */
46 {"Cz",0x0405}, /* LANG_Cz */
47 {"Eo",0x0425}, /* LANG_Eo */
48 {"It",0x0410}, /* LANG_It */
49 {"Ko",0x0412}, /* LANG_Ko */
50 {"Hu",0x0436}, /* LANG_Hu */
51 {"Pl",0x0415}, /* LANG_Pl */
52 {"Po",0x0416}, /* LANG_Po */
53 {"Sw",0x0417}, /* LANG_Sw */
54 {"Ca",0x0426}, /* LANG_Ca */
55 {NULL,0}
58 WORD WINE_LanguageId = 0;
60 #define WINE_CLASS "Wine" /* Class name for resources */
62 #define WINE_APP_DEFAULTS "/usr/lib/X11/app-defaults/Wine"
64 Display *display;
65 Screen *screen;
66 Window rootWindow;
67 int screenWidth = 0, screenHeight = 0; /* Desktop window dimensions */
68 int screenDepth = 0; /* Screen depth to use */
70 struct options Options =
71 { /* default options */
72 NULL, /* desktopGeometry */
73 NULL, /* programName */
74 NULL, /* argv0 */
75 NULL, /* dllFlags */
76 FALSE, /* usePrivateMap */
77 FALSE, /* useFixedMap */
78 FALSE, /* synchronous */
79 FALSE, /* backing store */
80 SW_SHOWNORMAL, /* cmdShow */
81 FALSE,
82 FALSE, /* failReadOnly */
83 MODE_ENHANCED, /* Enhanced mode */
84 #ifdef DEFAULT_LANG
85 DEFAULT_LANG, /* Default language */
86 #else
87 LANG_En,
88 #endif
89 FALSE, /* Managed windows */
90 FALSE /* Perfect graphics */
94 static XrmOptionDescRec optionsTable[] =
96 { "-backingstore", ".backingstore", XrmoptionNoArg, (caddr_t)"on" },
97 { "-desktop", ".desktop", XrmoptionSepArg, (caddr_t)NULL },
98 { "-depth", ".depth", XrmoptionSepArg, (caddr_t)NULL },
99 { "-display", ".display", XrmoptionSepArg, (caddr_t)NULL },
100 { "-iconic", ".iconic", XrmoptionNoArg, (caddr_t)"on" },
101 { "-language", ".language", XrmoptionSepArg, (caddr_t)"En" },
102 { "-name", ".name", XrmoptionSepArg, (caddr_t)NULL },
103 { "-perfect", ".perfect", XrmoptionNoArg, (caddr_t)"on" },
104 { "-privatemap", ".privatemap", XrmoptionNoArg, (caddr_t)"on" },
105 { "-fixedmap", ".fixedmap", XrmoptionNoArg, (caddr_t)"on" },
106 { "-synchronous", ".synchronous", XrmoptionNoArg, (caddr_t)"on" },
107 { "-debug", ".debug", XrmoptionNoArg, (caddr_t)"on" },
108 { "-debugmsg", ".debugmsg", XrmoptionSepArg, (caddr_t)NULL },
109 { "-dll", ".dll", XrmoptionSepArg, (caddr_t)NULL },
110 { "-failreadonly", ".failreadonly", XrmoptionNoArg, (caddr_t)"on" },
111 { "-mode", ".mode", XrmoptionSepArg, (caddr_t)NULL },
112 { "-managed", ".managed", XrmoptionNoArg, (caddr_t)"off"},
113 { "-winver", ".winver", XrmoptionSepArg, (caddr_t)NULL }
116 #define NB_OPTIONS (sizeof(optionsTable) / sizeof(optionsTable[0]))
118 #define USAGE \
119 "%s\n" \
120 "Usage: %s [options] \"program_name [arguments]\"\n" \
121 "\n" \
122 "Options:\n" \
123 " -backingstore Turn on backing store\n" \
124 " -debug Enter debugger before starting application\n" \
125 " -debugmsg name Turn debugging-messages on or off\n" \
126 " -depth n Change the depth to use for multiple-depth screens\n" \
127 " -desktop geom Use a desktop window of the given geometry\n" \
128 " -display name Use the specified display\n" \
129 " -dll name Enable or disable built-in DLLs\n" \
130 " -failreadonly Read only files may not be opened in write mode\n" \
131 " -fixedmap Use a \"standard\" color map\n" \
132 " -help Show this help message\n" \
133 " -iconic Start as an icon\n" \
134 " -language xx Set the language (one of En,Es,De,No,Fr,Fi,Da,Cz,Eo,It,Ko,\n Hu,Pl,Po,Sw,Ca)\n" \
135 " -managed Allow the window manager to manage created windows\n" \
136 " -mode mode Start Wine in a particular mode (standard or enhanced)\n" \
137 " -name name Set the application name\n" \
138 " -perfect Favor correctness over speed for graphical operations\n" \
139 " -privatemap Use a private color map\n" \
140 " -synchronous Turn on synchronous display mode\n" \
141 " -version Display the Wine version\n" \
142 " -winver Version to imitate (one of win31,win95,nt351,nt40)\n"
146 /***********************************************************************
147 * MAIN_Usage
149 void MAIN_Usage( char *name )
151 MSG( USAGE, WINE_RELEASE_INFO, name );
152 exit(1);
156 /***********************************************************************
157 * MAIN_GetProgramName
159 * Get the program name. The name is specified by (in order of precedence):
160 * - the option '-name'.
161 * - the environment variable 'WINE_NAME'.
162 * - the last component of argv[0].
164 static char *MAIN_GetProgramName( int argc, char *argv[] )
166 int i;
167 char *p;
169 for (i = 1; i < argc-1; i++)
170 if (!strcmp( argv[i], "-name" )) return argv[i+1];
171 if ((p = getenv( "WINE_NAME" )) != NULL) return p;
172 if ((p = strrchr( argv[0], '/' )) != NULL) return p+1;
173 return argv[0];
177 /***********************************************************************
178 * MAIN_GetResource
180 * Fetch the value of resource 'name' using the correct instance name.
181 * 'name' must begin with '.' or '*'
183 static int MAIN_GetResource( XrmDatabase db, char *name, XrmValue *value )
185 char *buff_instance, *buff_class;
186 char *dummy;
187 int retval;
189 buff_instance = (char *)xmalloc(strlen(Options.programName)+strlen(name)+1);
190 buff_class = (char *)xmalloc( strlen(WINE_CLASS) + strlen(name) + 1 );
192 strcpy( buff_instance, Options.programName );
193 strcat( buff_instance, name );
194 strcpy( buff_class, WINE_CLASS );
195 strcat( buff_class, name );
196 retval = TSXrmGetResource( db, buff_instance, buff_class, &dummy, value );
197 free( buff_instance );
198 free( buff_class );
199 return retval;
203 /***********************************************************************
204 * MAIN_ParseDebugOptions
206 * Turns specific debug messages on or off, according to "options".
208 * RETURNS
209 * TRUE if parsing was successful
211 static BOOL32 MAIN_ParseDebugOptions(char *options)
213 int l, cls;
214 if (strlen(options)<3)
215 return FALSE;
218 if ((*options!='+')&&(*options!='-')){
219 int j;
221 for(j=0; j<DEBUG_CLASS_COUNT; j++)
222 if(!lstrncmpi32A(options, debug_cl_name[j], strlen(debug_cl_name[j])))
223 break;
224 if(j==DEBUG_CLASS_COUNT)
225 return FALSE;
226 options += strlen(debug_cl_name[j]);
227 if ((*options!='+')&&(*options!='-'))
228 return FALSE;
229 cls = j;
231 else
232 cls = -1; /* all classes */
234 if (strchr(options,','))
235 l=strchr(options,',')-options;
236 else
237 l=strlen(options);
239 if (!lstrncmpi32A(options+1,"all",l-1))
241 int i, j;
242 for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
243 for(j=0; j<DEBUG_CLASS_COUNT; j++)
244 if(cls == -1 || cls == j)
245 debug_msg_enabled[i][j]=(*options=='+');
247 else
249 int i, j;
250 for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
251 if (debug_ch_name && (!lstrncmpi32A(options+1,debug_ch_name[i],l-1))){
252 for(j=0; j<DEBUG_CLASS_COUNT; j++)
253 if(cls == -1 || cls == j)
254 debug_msg_enabled[i][j]=(*options=='+');
255 break;
257 if (i==DEBUG_CHANNEL_COUNT)
258 return FALSE;
260 options+=l;
262 while((*options==',')&&(*(++options)));
263 if (*options)
264 return FALSE;
265 else
266 return TRUE;
269 /***********************************************************************
270 * MAIN_ParseLanguageOption
272 * Parse -language option.
274 static void MAIN_ParseLanguageOption( char *arg )
276 const WINE_LANGUAGE_DEF *p = Languages;
278 Options.language = LANG_En; /* First language */
279 for (;p->name;p++)
281 if (!lstrcmpi32A( p->name, arg ))
283 WINE_LanguageId = p->langid;
284 return;
286 Options.language++;
288 MSG( "Invalid language specified '%s'. Supported languages are: ", arg );
289 for (p = Languages; p->name; p++) MSG( "%s ", p->name );
290 MSG( "\n" );
291 exit(1);
295 /***********************************************************************
296 * MAIN_ParseModeOption
298 * Parse -mode option.
300 static void MAIN_ParseModeOption( char *arg )
302 if (!lstrcmpi32A("enhanced", arg)) Options.mode = MODE_ENHANCED;
303 else if (!lstrcmpi32A("standard", arg)) Options.mode = MODE_STANDARD;
304 else
306 MSG( "Invalid mode '%s' specified.\n", arg);
307 MSG( "Valid modes are: 'standard', 'enhanced' (default).\n");
308 exit(1);
312 /***********************************************************************
313 * MAIN_ParseOptions
315 * Parse command line options and open display.
317 static void MAIN_ParseOptions( int *argc, char *argv[] )
319 char *display_name = NULL;
320 XrmValue value;
321 XrmDatabase db = TSXrmGetFileDatabase(WINE_APP_DEFAULTS);
322 int i;
323 char *xrm_string;
325 Options.programName = MAIN_GetProgramName( *argc, argv );
326 Options.argv0 = argv[0];
328 /* Get display name from command line */
329 for (i = 1; i < *argc; i++)
331 if (!strcmp( argv[i], "-display" )) display_name = argv[i+1];
332 if (!strcmp( argv[i], "-v" ) || !strcmp( argv[i], "-version" ))
334 MSG( "%s\n", WINE_RELEASE_INFO );
335 exit(0);
337 if (!strcmp( argv[i], "-h" ) || !strcmp( argv[i], "-help" ))
339 MAIN_Usage(argv[0]);
340 exit(0);
344 /* Open display */
346 if (display_name == NULL &&
347 MAIN_GetResource( db, ".display", &value )) display_name = value.addr;
349 if (!(display = TSXOpenDisplay( display_name )))
351 MSG( "%s: Can't open display: %s\n",
352 argv[0], display_name ? display_name : "(none specified)" );
353 exit(1);
356 /* Merge file and screen databases */
357 if ((xrm_string = TSXResourceManagerString( display )) != NULL)
359 XrmDatabase display_db = TSXrmGetStringDatabase( xrm_string );
360 TSXrmMergeDatabases( display_db, &db );
363 /* Parse command line */
364 TSXrmParseCommand( &db, optionsTable, NB_OPTIONS,
365 Options.programName, argc, argv );
367 /* Get all options */
368 if (MAIN_GetResource( db, ".iconic", &value ))
369 Options.cmdShow = SW_SHOWMINIMIZED;
370 if (MAIN_GetResource( db, ".privatemap", &value ))
371 Options.usePrivateMap = TRUE;
372 if (MAIN_GetResource( db, ".fixedmap", &value ))
373 Options.useFixedMap = TRUE;
374 if (MAIN_GetResource( db, ".synchronous", &value ))
375 Options.synchronous = TRUE;
376 if (MAIN_GetResource( db, ".backingstore", &value ))
377 Options.backingstore = TRUE;
378 if (MAIN_GetResource( db, ".debug", &value ))
379 Options.debug = TRUE;
380 if (MAIN_GetResource( db, ".failreadonly", &value ))
381 Options.failReadOnly = TRUE;
382 if (MAIN_GetResource( db, ".perfect", &value ))
383 Options.perfectGraphics = TRUE;
384 if (MAIN_GetResource( db, ".depth", &value))
385 screenDepth = atoi( value.addr );
386 if (MAIN_GetResource( db, ".desktop", &value))
387 Options.desktopGeometry = value.addr;
388 if (MAIN_GetResource( db, ".language", &value))
389 MAIN_ParseLanguageOption( (char *)value.addr );
390 if (MAIN_GetResource( db, ".managed", &value))
391 Options.managed = TRUE;
392 if (MAIN_GetResource( db, ".mode", &value))
393 MAIN_ParseModeOption( (char *)value.addr );
394 if (MAIN_GetResource( db, ".debugoptions", &value))
395 MAIN_ParseDebugOptions((char*)value.addr);
396 if (MAIN_GetResource( db, ".debugmsg", &value))
398 #ifndef DEBUG_RUNTIME
399 MSG("%s: Option \"-debugmsg\" not implemented.\n" \
400 " Recompile with DEBUG_RUNTIME in include/debugtools.h defined.\n",
401 argv[0]);
402 exit(1);
403 #else
404 if (MAIN_ParseDebugOptions((char*)value.addr)==FALSE)
406 int i;
407 MSG("%s: Syntax: -debugmsg [class]+xxx,... or "
408 "-debugmsg [class]-xxx,...\n",argv[0]);
409 MSG("Example: -debugmsg +all,warn-heap"
410 "turn on all messages except warning heap messages\n");
412 MSG("Available message classes:\n");
413 for(i=0;i<DEBUG_CLASS_COUNT;i++)
414 MSG( "%-9s", debug_cl_name[i]);
415 MSG("\n\n");
417 MSG("Available message types:\n");
418 MSG("%-9s ","all");
419 for(i=0;i<DEBUG_CHANNEL_COUNT;i++)
420 if(debug_ch_name[i])
421 MSG("%-9s%c",debug_ch_name[i],
422 (((i+2)%8==0)?'\n':' '));
423 MSG("\n\n");
424 exit(1);
426 #endif
429 if (MAIN_GetResource( db, ".dll", &value))
431 /* Hack: store option value in Options to be retrieved */
432 /* later on inside the emulator code. */
433 if (!__winelib) Options.dllFlags = xstrdup((char *)value.addr);
434 else
436 MSG("-dll not supported in Winelib\n" );
437 exit(1);
441 if (MAIN_GetResource( db, ".winver", &value))
442 VERSION_ParseVersion( (char*)value.addr );
446 /***********************************************************************
447 * MAIN_CreateDesktop
449 static void MAIN_CreateDesktop( int argc, char *argv[] )
451 int x, y, flags;
452 unsigned int width = 640, height = 480; /* Default size = 640x480 */
453 char *name = "Wine desktop";
454 XSizeHints *size_hints;
455 XWMHints *wm_hints;
456 XClassHint *class_hints;
457 XSetWindowAttributes win_attr;
458 XTextProperty window_name;
459 Atom XA_WM_DELETE_WINDOW;
461 flags = TSXParseGeometry( Options.desktopGeometry, &x, &y, &width, &height );
462 screenWidth = width;
463 screenHeight = height;
465 /* Create window */
467 win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
468 PointerMotionMask | ButtonPressMask |
469 ButtonReleaseMask | EnterWindowMask;
470 win_attr.cursor = TSXCreateFontCursor( display, XC_top_left_arrow );
472 rootWindow = TSXCreateWindow( display, DefaultRootWindow(display),
473 x, y, width, height, 0,
474 CopyFromParent, InputOutput, CopyFromParent,
475 CWEventMask | CWCursor, &win_attr );
477 /* Set window manager properties */
479 size_hints = TSXAllocSizeHints();
480 wm_hints = TSXAllocWMHints();
481 class_hints = TSXAllocClassHint();
482 if (!size_hints || !wm_hints || !class_hints)
484 MSG("Not enough memory for window manager hints.\n" );
485 exit(1);
487 size_hints->min_width = size_hints->max_width = width;
488 size_hints->min_height = size_hints->max_height = height;
489 size_hints->flags = PMinSize | PMaxSize;
490 if (flags & (XValue | YValue)) size_hints->flags |= USPosition;
491 if (flags & (WidthValue | HeightValue)) size_hints->flags |= USSize;
492 else size_hints->flags |= PSize;
494 wm_hints->flags = InputHint | StateHint;
495 wm_hints->input = True;
496 wm_hints->initial_state = NormalState;
497 class_hints->res_name = argv[0];
498 class_hints->res_class = "Wine";
500 TSXStringListToTextProperty( &name, 1, &window_name );
501 TSXSetWMProperties( display, rootWindow, &window_name, &window_name,
502 argv, argc, size_hints, wm_hints, class_hints );
503 XA_WM_DELETE_WINDOW = TSXInternAtom( display, "WM_DELETE_WINDOW", False );
504 TSXSetWMProtocols( display, rootWindow, &XA_WM_DELETE_WINDOW, 1 );
505 TSXFree( size_hints );
506 TSXFree( wm_hints );
507 TSXFree( class_hints );
509 /* Map window */
511 TSXMapWindow( display, rootWindow );
515 XKeyboardState keyboard_state;
517 /***********************************************************************
518 * MAIN_SaveSetup
520 static void MAIN_SaveSetup(void)
522 TSXGetKeyboardControl(display, &keyboard_state);
525 /***********************************************************************
526 * MAIN_RestoreSetup
528 static void MAIN_RestoreSetup(void)
530 XKeyboardControl keyboard_value;
532 keyboard_value.key_click_percent = keyboard_state.key_click_percent;
533 keyboard_value.bell_percent = keyboard_state.bell_percent;
534 keyboard_value.bell_pitch = keyboard_state.bell_pitch;
535 keyboard_value.bell_duration = keyboard_state.bell_duration;
536 keyboard_value.auto_repeat_mode = keyboard_state.global_auto_repeat;
538 XChangeKeyboardControl(display, KBKeyClickPercent | KBBellPercent |
539 KBBellPitch | KBBellDuration | KBAutoRepeatMode, &keyboard_value);
543 /***********************************************************************
544 * called_at_exit
546 static void called_at_exit(void)
548 MAIN_RestoreSetup();
549 COLOR_Cleanup();
550 WINSOCK_Shutdown();
551 /* FIXME: should check for other processes or threads */
552 DeleteCriticalSection( HEAP_SystemLock );
555 /***********************************************************************
556 * MAIN_WineInit
558 * Wine initialisation and command-line parsing
560 BOOL32 MAIN_WineInit( int *argc, char *argv[] )
562 int depth_count, i;
563 int *depth_list;
564 struct timeval tv;
566 #ifdef MALLOC_DEBUGGING
567 char *trace;
569 mcheck(NULL);
570 if (!(trace = getenv("MALLOC_TRACE")))
572 MSG( "MALLOC_TRACE not set. No trace generated\n" );
574 else
576 MSG( "malloc trace goes to %s\n", trace );
577 mtrace();
579 #endif
581 setbuf(stdout,NULL);
582 setbuf(stderr,NULL);
584 setlocale(LC_CTYPE,"");
585 gettimeofday( &tv, NULL);
586 MSG_WineStartTicks = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
588 /* We need this before calling any Xlib function */
589 InitializeCriticalSection( &X11DRV_CritSection );
591 TSXrmInitialize();
593 putenv("XKB_DISABLE="); /* Disable XKB extension if present. */
595 MAIN_ParseOptions( argc, argv );
597 if (Options.desktopGeometry && Options.managed)
599 MSG( "%s: -managed and -desktop options cannot be used together\n",
600 Options.programName );
601 exit(1);
604 screen = DefaultScreenOfDisplay( display );
605 screenWidth = WidthOfScreen( screen );
606 screenHeight = HeightOfScreen( screen );
607 if (screenDepth) /* -depth option specified */
609 depth_list = TSXListDepths(display,DefaultScreen(display),&depth_count);
610 for (i = 0; i < depth_count; i++)
611 if (depth_list[i] == screenDepth) break;
612 TSXFree( depth_list );
613 if (i >= depth_count)
615 MSG( "%s: Depth %d not supported on this screen.\n",
616 Options.programName, screenDepth );
617 exit(1);
620 else screenDepth = DefaultDepthOfScreen( screen );
621 if (Options.synchronous) TSXSynchronize( display, True );
622 if (Options.desktopGeometry) MAIN_CreateDesktop( *argc, argv );
623 else rootWindow = DefaultRootWindow( display );
625 MAIN_SaveSetup();
626 atexit(called_at_exit);
627 return TRUE;
631 /***********************************************************************
632 * MessageBeep16 (USER.104)
634 void WINAPI MessageBeep16( UINT16 i )
636 MessageBeep32( i );
640 /***********************************************************************
641 * MessageBeep32 (USER32.390)
643 BOOL32 WINAPI MessageBeep32( UINT32 i )
645 TSXBell( display, 0 );
646 return TRUE;
650 /***********************************************************************
651 * Beep (KERNEL32.11)
653 BOOL32 WINAPI Beep( DWORD dwFreq, DWORD dwDur )
655 /* dwFreq and dwDur are ignored by Win95 */
656 TSXBell(display, 0);
657 return TRUE;
661 /***********************************************************************
662 * GetTimerResolution (USER.14)
664 LONG WINAPI GetTimerResolution(void)
666 return (1000);
669 /***********************************************************************
670 * SystemParametersInfo32A (USER32.540)
672 BOOL32 WINAPI SystemParametersInfo32A( UINT32 uAction, UINT32 uParam,
673 LPVOID lpvParam, UINT32 fuWinIni )
675 int timeout, temp;
676 XKeyboardState keyboard_state;
678 switch (uAction) {
679 case SPI_GETBEEP:
680 TSXGetKeyboardControl(display, &keyboard_state);
681 if (keyboard_state.bell_percent == 0)
682 *(BOOL32 *) lpvParam = FALSE;
683 else
684 *(BOOL32 *) lpvParam = TRUE;
685 break;
687 case SPI_GETBORDER:
688 *(INT32 *)lpvParam = GetSystemMetrics32( SM_CXFRAME );
689 break;
691 case SPI_GETFASTTASKSWITCH:
692 if ( GetProfileInt32A( "windows", "CoolSwitch", 1 ) == 1 )
693 *(BOOL32 *) lpvParam = TRUE;
694 else
695 *(BOOL32 *) lpvParam = FALSE;
696 break;
698 case SPI_GETDRAGFULLWINDOWS:
699 *(BOOL32 *) lpvParam = FALSE;
701 case SPI_GETGRIDGRANULARITY:
702 *(INT32*)lpvParam=GetProfileInt32A("desktop","GridGranularity",1);
703 break;
705 case SPI_GETICONTITLEWRAP:
706 *(BOOL32*)lpvParam=GetProfileInt32A("desktop","IconTitleWrap",TRUE);
707 break;
709 case SPI_GETKEYBOARDDELAY:
710 *(INT32*)lpvParam=GetProfileInt32A("keyboard","KeyboardDelay",1);
711 break;
713 case SPI_GETKEYBOARDSPEED:
714 *(DWORD*)lpvParam=GetProfileInt32A("keyboard","KeyboardSpeed",30);
715 break;
717 case SPI_GETMENUDROPALIGNMENT:
718 *(BOOL32*)lpvParam=GetSystemMetrics32(SM_MENUDROPALIGNMENT); /* XXX check this */
719 break;
721 case SPI_GETSCREENSAVEACTIVE:
722 if ( GetProfileInt32A( "windows", "ScreenSaveActive", 1 ) == 1 )
723 *(BOOL32*)lpvParam = TRUE;
724 else
725 *(BOOL32*)lpvParam = FALSE;
726 break;
728 case SPI_GETSCREENSAVETIMEOUT:
729 /* FIXME GetProfileInt( "windows", "ScreenSaveTimeout", 300 ); */
730 TSXGetScreenSaver(display, &timeout, &temp,&temp,&temp);
731 *(INT32 *) lpvParam = timeout * 1000;
732 break;
734 case SPI_ICONHORIZONTALSPACING:
735 /* FIXME Get/SetProfileInt */
736 if (lpvParam == NULL)
737 /*SetSystemMetrics( SM_CXICONSPACING, uParam )*/ ;
738 else
739 *(INT32*)lpvParam=GetSystemMetrics32(SM_CXICONSPACING);
740 break;
742 case SPI_ICONVERTICALSPACING:
743 /* FIXME Get/SetProfileInt */
744 if (lpvParam == NULL)
745 /*SetSystemMetrics( SM_CYICONSPACING, uParam )*/ ;
746 else
747 *(INT32*)lpvParam=GetSystemMetrics32(SM_CYICONSPACING);
748 break;
750 case SPI_GETICONTITLELOGFONT: {
751 LPLOGFONT32A lpLogFont = (LPLOGFONT32A)lpvParam;
753 /* from now on we always have an alias for MS Sans Serif */
755 GetProfileString32A("Desktop", "IconTitleFaceName", "MS Sans Serif",
756 lpLogFont->lfFaceName, LF_FACESIZE );
757 lpLogFont->lfHeight = -GetProfileInt32A("Desktop","IconTitleSize", 8);
759 lpLogFont->lfWidth = 0;
760 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
761 lpLogFont->lfWeight = FW_NORMAL;
762 lpLogFont->lfItalic = FALSE;
763 lpLogFont->lfStrikeOut = FALSE;
764 lpLogFont->lfUnderline = FALSE;
765 lpLogFont->lfCharSet = ANSI_CHARSET;
766 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
767 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
768 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
769 break;
771 case SPI_GETWORKAREA:
772 SetRect32( (RECT32 *)lpvParam, 0, 0,
773 GetSystemMetrics32( SM_CXSCREEN ),
774 GetSystemMetrics32( SM_CYSCREEN )
776 break;
777 case SPI_GETNONCLIENTMETRICS:
779 #define lpnm ((LPNONCLIENTMETRICS32A)lpvParam)
781 if( lpnm->cbSize == sizeof(NONCLIENTMETRICS32A) )
783 /* FIXME: initialize geometry entries */
785 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
786 (LPVOID)&(lpnm->lfCaptionFont),0);
787 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
788 (LPVOID)&(lpnm->lfMenuFont),0);
789 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
790 (LPVOID)&(lpnm->lfStatusFont),0);
791 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT, 0,
792 (LPVOID)&(lpnm->lfMessageFont),0);
794 #undef lpnm
795 break;
797 case SPI_GETANIMATION: {
798 LPANIMATIONINFO lpAnimInfo = (LPANIMATIONINFO)lpvParam;
800 /* Tell it "disabled" */
801 lpAnimInfo->cbSize = sizeof(ANIMATIONINFO);
802 uParam = sizeof(ANIMATIONINFO);
803 lpAnimInfo->iMinAnimate = 0; /* Minimise and restore animation is disabled (nonzero == enabled) */
804 break;
807 case SPI_SETANIMATION: {
808 LPANIMATIONINFO lpAnimInfo = (LPANIMATIONINFO)lpvParam;
810 /* Do nothing */
811 WARN(system, "SPI_SETANIMATION ignored.\n");
812 lpAnimInfo->cbSize = sizeof(ANIMATIONINFO);
813 uParam = sizeof(ANIMATIONINFO);
814 break;
817 default:
818 return SystemParametersInfo16(uAction,uParam,lpvParam,fuWinIni);
820 return TRUE;
824 /***********************************************************************
825 * SystemParametersInfo16 (USER.483)
827 BOOL16 WINAPI SystemParametersInfo16( UINT16 uAction, UINT16 uParam,
828 LPVOID lpvParam, UINT16 fuWinIni )
830 int timeout, temp;
831 char buffer[256];
832 XKeyboardState keyboard_state;
833 XKeyboardControl keyboard_value;
836 switch (uAction)
838 case SPI_GETBEEP:
839 TSXGetKeyboardControl(display, &keyboard_state);
840 if (keyboard_state.bell_percent == 0)
841 *(BOOL16 *) lpvParam = FALSE;
842 else
843 *(BOOL16 *) lpvParam = TRUE;
844 break;
846 case SPI_GETBORDER:
847 *(INT16 *)lpvParam = GetSystemMetrics16( SM_CXFRAME );
848 break;
850 case SPI_GETFASTTASKSWITCH:
851 if ( GetProfileInt32A( "windows", "CoolSwitch", 1 ) == 1 )
852 *(BOOL16 *) lpvParam = TRUE;
853 else
854 *(BOOL16 *) lpvParam = FALSE;
855 break;
857 case SPI_GETGRIDGRANULARITY:
858 *(INT16 *) lpvParam = GetProfileInt32A( "desktop",
859 "GridGranularity",
860 1 );
861 break;
863 case SPI_GETICONTITLEWRAP:
864 *(BOOL16 *) lpvParam = GetProfileInt32A( "desktop",
865 "IconTitleWrap",
866 TRUE );
867 break;
869 case SPI_GETKEYBOARDDELAY:
870 *(INT16 *) lpvParam = GetProfileInt32A( "keyboard",
871 "KeyboardDelay", 1 );
872 break;
874 case SPI_GETKEYBOARDSPEED:
875 *(WORD *) lpvParam = GetProfileInt32A( "keyboard",
876 "KeyboardSpeed",
877 30 );
878 break;
880 case SPI_GETMENUDROPALIGNMENT:
881 *(BOOL16 *) lpvParam = GetSystemMetrics16( SM_MENUDROPALIGNMENT ); /* XXX check this */
882 break;
884 case SPI_GETSCREENSAVEACTIVE:
885 if ( GetProfileInt32A( "windows", "ScreenSaveActive", 1 ) == 1 )
886 *(BOOL16 *) lpvParam = TRUE;
887 else
888 *(BOOL16 *) lpvParam = FALSE;
889 break;
891 case SPI_GETSCREENSAVETIMEOUT:
892 /* FIXME GetProfileInt( "windows", "ScreenSaveTimeout", 300 ); */
893 TSXGetScreenSaver(display, &timeout, &temp,&temp,&temp);
894 *(INT16 *) lpvParam = timeout * 1000;
895 break;
897 case SPI_ICONHORIZONTALSPACING:
898 /* FIXME Get/SetProfileInt */
899 if (lpvParam == NULL)
900 /*SetSystemMetrics( SM_CXICONSPACING, uParam )*/ ;
901 else
902 *(INT16 *)lpvParam = GetSystemMetrics16( SM_CXICONSPACING );
903 break;
905 case SPI_ICONVERTICALSPACING:
906 /* FIXME Get/SetProfileInt */
907 if (lpvParam == NULL)
908 /*SetSystemMetrics( SM_CYICONSPACING, uParam )*/ ;
909 else
910 *(INT16 *)lpvParam = GetSystemMetrics16(SM_CYICONSPACING);
911 break;
913 case SPI_SETBEEP:
914 if (uParam == TRUE)
915 keyboard_value.bell_percent = -1;
916 else
917 keyboard_value.bell_percent = 0;
918 TSXChangeKeyboardControl(display, KBBellPercent,
919 &keyboard_value);
920 break;
922 case SPI_SETSCREENSAVEACTIVE:
923 if (uParam == TRUE)
924 TSXActivateScreenSaver(display);
925 else
926 TSXResetScreenSaver(display);
927 break;
929 case SPI_SETSCREENSAVETIMEOUT:
930 TSXSetScreenSaver(display, uParam, 60, DefaultBlanking,
931 DefaultExposures);
932 break;
934 case SPI_SETDESKWALLPAPER:
935 return (SetDeskWallPaper32((LPSTR) lpvParam));
936 break;
938 case SPI_SETDESKPATTERN:
939 if ((INT16)uParam == -1) {
940 GetProfileString32A("Desktop", "Pattern",
941 "170 85 170 85 170 85 170 85",
942 buffer, sizeof(buffer) );
943 return (DESKTOP_SetPattern((LPSTR) buffer));
944 } else
945 return (DESKTOP_SetPattern((LPSTR) lpvParam));
946 break;
948 case SPI_GETICONTITLELOGFONT:
950 LPLOGFONT16 lpLogFont = (LPLOGFONT16)lpvParam;
952 GetProfileString32A("Desktop", "IconTitleFaceName", "MS Sans Serif",
953 lpLogFont->lfFaceName, LF_FACESIZE );
954 lpLogFont->lfHeight = -GetProfileInt32A("Desktop","IconTitleSize", 8);
956 lpLogFont->lfWidth = 0;
957 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
958 lpLogFont->lfWeight = FW_NORMAL;
959 lpLogFont->lfItalic = FALSE;
960 lpLogFont->lfStrikeOut = FALSE;
961 lpLogFont->lfUnderline = FALSE;
962 lpLogFont->lfCharSet = ANSI_CHARSET;
963 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
964 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
965 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
966 break;
968 case SPI_GETNONCLIENTMETRICS:
970 #define lpnm ((LPNONCLIENTMETRICS16)lpvParam)
971 if( lpnm->cbSize == sizeof(NONCLIENTMETRICS16) )
973 /* FIXME: initialize geometry entries */
974 SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
975 (LPVOID)&(lpnm->lfCaptionFont),0);
976 SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
977 (LPVOID)&(lpnm->lfMenuFont),0);
978 SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
979 (LPVOID)&(lpnm->lfStatusFont),0);
980 SystemParametersInfo16( SPI_GETICONTITLELOGFONT, 0,
981 (LPVOID)&(lpnm->lfMessageFont),0);
983 else /* winfile 95 sets sbSize to 340 */
984 SystemParametersInfo32A( uAction, uParam, lpvParam, fuWinIni );
985 #undef lpnm
986 break;
988 case SPI_LANGDRIVER:
989 case SPI_SETBORDER:
990 case SPI_SETDOUBLECLKHEIGHT:
991 case SPI_SETDOUBLECLICKTIME:
992 case SPI_SETDOUBLECLKWIDTH:
993 case SPI_SETFASTTASKSWITCH:
994 case SPI_SETKEYBOARDDELAY:
995 case SPI_SETKEYBOARDSPEED:
996 case SPI_GETHIGHCONTRAST:
997 WARN(system, "Option %d ignored.\n", uAction);
998 break;
1000 case SPI_GETWORKAREA:
1001 SetRect16( (RECT16 *)lpvParam, 0, 0,
1002 GetSystemMetrics16( SM_CXSCREEN ),
1003 GetSystemMetrics16( SM_CYSCREEN ) );
1004 break;
1006 default:
1007 WARN(system, "Unknown option %d.\n", uAction);
1008 break;
1010 return 1;
1013 /***********************************************************************
1014 * SystemParametersInfo32W (USER32.541)
1016 BOOL32 WINAPI SystemParametersInfo32W( UINT32 uAction, UINT32 uParam,
1017 LPVOID lpvParam, UINT32 fuWinIni )
1019 char buffer[256];
1021 switch (uAction)
1023 case SPI_SETDESKWALLPAPER:
1024 if (lpvParam)
1026 lstrcpynWtoA(buffer,(LPWSTR)lpvParam,sizeof(buffer));
1027 return SetDeskWallPaper32(buffer);
1029 return SetDeskWallPaper32(NULL);
1031 case SPI_SETDESKPATTERN:
1032 if ((INT32) uParam == -1)
1034 GetProfileString32A("Desktop", "Pattern",
1035 "170 85 170 85 170 85 170 85",
1036 buffer, sizeof(buffer) );
1037 return (DESKTOP_SetPattern((LPSTR) buffer));
1039 if (lpvParam)
1041 lstrcpynWtoA(buffer,(LPWSTR)lpvParam,sizeof(buffer));
1042 return DESKTOP_SetPattern(buffer);
1044 return DESKTOP_SetPattern(NULL);
1046 case SPI_GETICONTITLELOGFONT:
1048 /* FIXME GetProfileString32A( "?", "?", "?" ) */
1049 LPLOGFONT32W lpLogFont = (LPLOGFONT32W)lpvParam;
1050 lpLogFont->lfHeight = 10;
1051 lpLogFont->lfWidth = 0;
1052 lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1053 lpLogFont->lfWeight = FW_NORMAL;
1054 lpLogFont->lfItalic = lpLogFont->lfStrikeOut = lpLogFont->lfUnderline = FALSE;
1055 lpLogFont->lfCharSet = ANSI_CHARSET;
1056 lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1057 lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1058 lpLogFont->lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
1060 break;
1061 case SPI_GETNONCLIENTMETRICS: {
1062 /* FIXME: implement correctly */
1063 LPNONCLIENTMETRICS32W lpnm=(LPNONCLIENTMETRICS32W)lpvParam;
1065 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfCaptionFont),0);
1066 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfMenuFont),0);
1067 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfStatusFont),0);
1068 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT,0,(LPVOID)&(lpnm->lfMessageFont),0);
1069 break;
1072 default:
1073 return SystemParametersInfo32A(uAction,uParam,lpvParam,fuWinIni);
1076 return TRUE;
1080 /***********************************************************************
1081 * FileCDR (KERNEL.130)
1083 void WINAPI FileCDR(FARPROC16 x)
1085 FIXME(file,"(%8x): stub\n", (int) x);