4 * Copyright 1994 Alexandre Julliard
12 /* #include <locale.h> */
13 #ifdef MALLOC_DEBUGGING
17 #include <X11/Xresource.h>
18 #include <X11/Xutil.h>
19 #include <X11/Xlocale.h>
20 #include <X11/cursorfont.h>
32 #define DEBUG_DEFINE_VARIABLES
37 const char people
[] = "Wine is available thanks to the work of "
38 "Bob Amstadt, Dag Asheim, Martin Ayotte, Peter Bajusz, Ross Biro, "
39 "Uwe Bonnes, Erik Bos, Fons Botman, John Brezak, Andrew Bulhak, "
40 "John Burton, Niels de Carpentier, Jimen Ching, Huw D. M. Davies, "
41 "Roman Dolejsi, Frans van Dorsselaer, Paul Falstad, David Faure, "
42 "Olaf Flebbe, Peter Galbavy, Ramon Garcia, Matthew Ghio, "
43 "Hans de Graaff, Charles M. Hannum, John Harvey, Cameron Heide, "
44 "Jochen Hoenicke, Onno Hovers, Jeffrey Hsu, Miguel de Icaza, "
45 "Jukka Iivonen, Lee Jaekil, Alexandre Julliard, Bang Jun-Young, "
46 "Pavel Kankovsky, Jochen Karrer, Andreas Kirschbaum, Albrecht Kleine, "
47 "Jon Konrath, Alex Korobka, Greg Kreider, Anand Kumria, Scott A. Laird, "
48 "Andrew Lewycky, Martin von Loewis, Kenneth MacDonald, Peter MacDonald, "
49 "William Magro, Juergen Marquardt, Ricardo Massaro, Marcus Meissner, "
50 "Graham Menhennitt, David Metcalfe, Bruce Milner, Steffen Moeller, "
51 "Andreas Mohr, Philippe De Muyter, Itai Nahshon, Michael Patra, "
52 "Jim Peterson, Robert Pouliot, Keith Reynolds, Slaven Rezic, "
53 "John Richardson, Johannes Ruscheinski, Thomas Sandford, "
54 "Constantine Sapuntzakis, Pablo Saratxaga, Daniel Schepler, "
55 "Ulrich Schmid, Bernd Schmidt, Yngvi Sigurjonsson, Stephen Simmons, "
56 "Rick Sladkey, William Smith, Dominik Strasser, Vadim Strizhevsky, "
57 "Erik Svendsen, Tristan Tarrant, Andrew Taylor, Duncan C Thomson, "
58 "Goran Thyni, Jimmy Tirtawangsa, Jon Tombs, Linus Torvalds, "
59 "Gregory Trubetskoy, Petri Tuomola, Michael Veksler, Sven Verdoolaege, "
60 "Ronan Waide, Eric Warnke, Manfred Weichel, Morten Welinder, "
61 "Jan Willamowius, Carl Williams, Karl Guenter Wuensch, Eric Youngdale, "
62 "James Youngman, Mikolaj Zalewski, and John Zero.";
64 const WINE_LANGUAGE_DEF Languages
[] =
66 {"En",0x0409}, /* LANG_En */
67 {"Es",0x040A}, /* LANG_Es */
68 {"De",0x0407}, /* LANG_De */
69 {"No",0x0414}, /* LANG_No */
70 {"Fr",0x0400}, /* LANG_Fr */
71 {"Fi",0x040B}, /* LANG_Fi */
72 {"Da",0x0406}, /* LANG_Da */
73 {"Cz",0x0405}, /* LANG_Cz */
74 {"Eo", 0}, /* LANG_Eo */ /* FIXME languageid */
75 {"It",0x0410}, /* LANG_It */
76 {"Ko",0x0412}, /* LANG_Ko */
77 {"Hu",0x0436}, /* LANG_Hu */
78 {"Pl",0x0415}, /* LANG_Pl */
79 {"Po",0x0416}, /* LANG_Po */
83 WORD WINE_LanguageId
= 0;
85 #define WINE_CLASS "Wine" /* Class name for resources */
87 #define WINE_APP_DEFAULTS "/usr/lib/X11/app-defaults/Wine"
89 typedef struct tagENVENTRY
{
93 struct tagENVENTRY
*Prev
;
94 struct tagENVENTRY
*Next
;
95 } ENVENTRY
, *LPENVENTRY
;
97 LPENVENTRY lpEnvList
= NULL
;
102 int screenWidth
= 0, screenHeight
= 0; /* Desktop window dimensions */
103 int screenDepth
= 0; /* Screen depth to use */
104 int desktopX
= 0, desktopY
= 0; /* Desktop window position (if any) */
105 int getVersion16
= 0;
106 int getVersion32
= 0;
107 OSVERSIONINFO32A getVersionEx
;
109 struct options Options
=
110 { /* default options */
111 NULL
, /* desktopGeometry */
112 NULL
, /* programName */
113 FALSE
, /* usePrivateMap */
114 FALSE
, /* useFixedMap */
115 FALSE
, /* synchronous */
116 FALSE
, /* backing store */
117 SW_SHOWNORMAL
, /* cmdShow */
119 FALSE
, /* failReadOnly */
120 MODE_ENHANCED
, /* Enhanced mode */
121 FALSE
, /* IPC enabled */
123 DEFAULT_LANG
, /* Default language */
127 FALSE
, /* Managed windows */
128 FALSE
/* Perfect graphics */
132 static XrmOptionDescRec optionsTable
[] =
134 { "-backingstore", ".backingstore", XrmoptionNoArg
, (caddr_t
)"on" },
135 { "-desktop", ".desktop", XrmoptionSepArg
, (caddr_t
)NULL
},
136 { "-depth", ".depth", XrmoptionSepArg
, (caddr_t
)NULL
},
137 { "-display", ".display", XrmoptionSepArg
, (caddr_t
)NULL
},
138 { "-iconic", ".iconic", XrmoptionNoArg
, (caddr_t
)"on" },
139 { "-ipc", ".ipc", XrmoptionNoArg
, (caddr_t
)"off"},
140 { "-language", ".language", XrmoptionSepArg
, (caddr_t
)"En" },
141 { "-name", ".name", XrmoptionSepArg
, (caddr_t
)NULL
},
142 { "-perfect", ".perfect", XrmoptionNoArg
, (caddr_t
)"on" },
143 { "-privatemap", ".privatemap", XrmoptionNoArg
, (caddr_t
)"on" },
144 { "-fixedmap", ".fixedmap", XrmoptionNoArg
, (caddr_t
)"on" },
145 { "-synchronous", ".synchronous", XrmoptionNoArg
, (caddr_t
)"on" },
146 { "-debug", ".debug", XrmoptionNoArg
, (caddr_t
)"on" },
147 { "-debugmsg", ".debugmsg", XrmoptionSepArg
, (caddr_t
)NULL
},
148 { "-dll", ".dll", XrmoptionSepArg
, (caddr_t
)NULL
},
149 { "-failreadonly", ".failreadonly", XrmoptionNoArg
, (caddr_t
)"on" },
150 { "-mode", ".mode", XrmoptionSepArg
, (caddr_t
)NULL
},
151 { "-managed", ".managed", XrmoptionNoArg
, (caddr_t
)"off"},
152 { "-winver", ".winver", XrmoptionSepArg
, (caddr_t
)NULL
}
155 #define NB_OPTIONS (sizeof(optionsTable) / sizeof(optionsTable[0]))
158 "Usage: %s [options] program_name [arguments]\n" \
161 " -backingstore Turn on backing store\n" \
162 " -debug Enter debugger before starting application\n" \
163 " -debugmsg name Turn debugging-messages on or off\n" \
164 " -depth n Change the depth to use for multiple-depth screens\n" \
165 " -desktop geom Use a desktop window of the given geometry\n" \
166 " -display name Use the specified display\n" \
167 " -dll name Enable or disable built-in DLLs\n" \
168 " -failreadonly Read only files may not be opened in write mode\n" \
169 " -fixedmap Use a \"standard\" color map\n" \
170 " -iconic Start as an icon\n" \
171 " -ipc Enable IPC facilities\n" \
172 " -language xx Set the language (one of En,Es,De,No,Fr,Fi,Da,Cz,Eo,It,Ko,\n Hu,Pl,Po)\n" \
173 " -managed Allow the window manager to manage created windows\n" \
174 " -mode mode Start Wine in a particular mode (standard or enhanced)\n" \
175 " -name name Set the application name\n" \
176 " -perfect Favor correctness over speed for graphical operations\n" \
177 " -privatemap Use a private color map\n" \
178 " -synchronous Turn on synchronous display mode\n" \
179 " -winver Version to imitate (one of win31,win95,nt351)\n"
183 /***********************************************************************
187 void MAIN_Usage( char *name
)
189 fprintf( stderr
, USAGE
, name
);
195 /***********************************************************************
196 * MAIN_GetProgramName
198 * Get the program name. The name is specified by (in order of precedence):
199 * - the option '-name'.
200 * - the environment variable 'WINE_NAME'.
201 * - the last component of argv[0].
203 static char *MAIN_GetProgramName( int argc
, char *argv
[] )
208 for (i
= 1; i
< argc
-1; i
++)
209 if (!strcmp( argv
[i
], "-name" )) return argv
[i
+1];
210 if ((p
= getenv( "WINE_NAME" )) != NULL
) return p
;
211 if ((p
= strrchr( argv
[0], '/' )) != NULL
) return p
+1;
216 /***********************************************************************
219 * Fetch the value of resource 'name' using the correct instance name.
220 * 'name' must begin with '.' or '*'
222 static int MAIN_GetResource( XrmDatabase db
, char *name
, XrmValue
*value
)
224 char *buff_instance
, *buff_class
;
228 buff_instance
= (char *)xmalloc(strlen(Options
.programName
)+strlen(name
)+1);
229 buff_class
= (char *)xmalloc( strlen(WINE_CLASS
) + strlen(name
) + 1 );
231 strcpy( buff_instance
, Options
.programName
);
232 strcat( buff_instance
, name
);
233 strcpy( buff_class
, WINE_CLASS
);
234 strcat( buff_class
, name
);
235 retval
= XrmGetResource( db
, buff_instance
, buff_class
, &dummy
, value
);
236 free( buff_instance
);
242 /***********************************************************************
245 * Turns specific debug messages on or off, according to "options".
246 * Returns TRUE if parsing was successful
250 BOOL32
ParseDebugOptions(char *options
)
253 if (strlen(options
)<3)
257 if ((*options
!='+')&&(*options
!='-'))
259 if (strchr(options
,','))
260 l
=strchr(options
,',')-options
;
263 if (!lstrncmpi32A(options
+1,"all",l
-1))
266 for (i
=0;i
<sizeof(debug_msg_enabled
)/sizeof(short);i
++)
267 debug_msg_enabled
[i
]=(*options
=='+');
272 for (i
=0;i
<sizeof(debug_msg_enabled
)/sizeof(short);i
++)
273 if (debug_msg_name
&& (!lstrncmpi32A(options
+1,debug_msg_name
[i
],l
-1)))
275 debug_msg_enabled
[i
]=(*options
=='+');
278 if (i
==sizeof(debug_msg_enabled
)/sizeof(short))
283 while((*options
==',')&&(*(++options
)));
293 /***********************************************************************
294 * MAIN_ParseLanguageOption
296 * Parse -language option.
298 static void MAIN_ParseLanguageOption( char *arg
)
300 const WINE_LANGUAGE_DEF
*p
= Languages
;
302 Options
.language
= LANG_En
; /* First language */
305 if (!lstrcmpi32A( p
->name
, arg
))
307 WINE_LanguageId
= p
->langid
;
312 fprintf( stderr
, "Invalid language specified '%s'. Supported languages are: ", arg
);
313 for (p
= Languages
; p
->name
; p
++) fprintf( stderr
, "%s ", p
->name
);
314 fprintf( stderr
, "\n" );
319 /***********************************************************************
320 * MAIN_ParseModeOption
322 * Parse -mode option.
324 static void MAIN_ParseModeOption( char *arg
)
326 if (!lstrcmpi32A("enhanced", arg
)) Options
.mode
= MODE_ENHANCED
;
327 else if (!lstrcmpi32A("standard", arg
)) Options
.mode
= MODE_STANDARD
;
330 fprintf(stderr
, "Invalid mode '%s' specified.\n", arg
);
331 fprintf(stderr
, "Valid modes are: 'standard', 'enhanced' (default).\n");
336 /**********************************************************************
339 static void MAIN_ParseVersion( char *arg
)
341 /* If you add any other options,
342 verify the values you return on the real thing */
343 if(strcmp(arg
,"win31")==0)
345 getVersion16
= 0x06160A03;
346 /* FIXME: My Win32s installation failed to execute the
347 MSVC 4 test program. So check these values */
348 getVersion32
= 0x80000A03;
349 getVersionEx
.dwMajorVersion
=3;
350 getVersionEx
.dwMinorVersion
=10;
351 getVersionEx
.dwBuildNumber
=0;
352 getVersionEx
.dwPlatformId
=VER_PLATFORM_WIN32s
;
353 strcpy(getVersionEx
.szCSDVersion
,"Win32s 1.3");
355 else if(strcmp(arg
, "win95")==0)
357 getVersion16
= 0x07005F03;
358 getVersion32
= 0xC0000004;
359 getVersionEx
.dwMajorVersion
=4;
360 getVersionEx
.dwMinorVersion
=0;
361 getVersionEx
.dwBuildNumber
=0x40003B6;
362 getVersionEx
.dwPlatformId
=VER_PLATFORM_WIN32_WINDOWS
;
363 strcpy(getVersionEx
.szCSDVersion
,"");
365 else if(strcmp(arg
, "nt351")==0)
367 getVersion16
= 0x05000A03;
368 getVersion32
= 0x04213303;
369 getVersionEx
.dwMajorVersion
=3;
370 getVersionEx
.dwMinorVersion
=51;
371 getVersionEx
.dwBuildNumber
=0x421;
372 getVersionEx
.dwPlatformId
=VER_PLATFORM_WIN32_NT
;
373 strcpy(getVersionEx
.szCSDVersion
,"Service Pack 2");
375 else fprintf(stderr
, "Unknown winver system code - ignored\n");
378 /***********************************************************************
381 * Parse command line options and open display.
383 static void MAIN_ParseOptions( int *argc
, char *argv
[] )
385 char *display_name
= NULL
;
387 XrmDatabase db
= XrmGetFileDatabase(WINE_APP_DEFAULTS
);
391 Options
.programName
= MAIN_GetProgramName( *argc
, argv
);
393 /* Get display name from command line */
394 for (i
= 1; i
< *argc
- 1; i
++)
395 if (!strcmp( argv
[i
], "-display" ))
397 display_name
= argv
[i
+1];
402 /* Need to assemble command line and pass it to WinMain */
404 if (*argc
< 2 || lstrcmpi32A(argv
[1], "-h") == 0)
405 MAIN_Usage( argv
[0] );
410 if (display_name
== NULL
&&
411 MAIN_GetResource( db
, ".display", &value
)) display_name
= value
.addr
;
413 if (!(display
= XOpenDisplay( display_name
)))
415 fprintf( stderr
, "%s: Can't open display: %s\n",
416 argv
[0], display_name
? display_name
: "(none specified)" );
420 /* Merge file and screen databases */
421 if ((xrm_string
= XResourceManagerString( display
)) != NULL
)
423 XrmDatabase display_db
= XrmGetStringDatabase( xrm_string
);
424 XrmMergeDatabases( display_db
, &db
);
427 /* Parse command line */
428 XrmParseCommand( &db
, optionsTable
, NB_OPTIONS
,
429 Options
.programName
, argc
, argv
);
431 /* Get all options */
432 if (MAIN_GetResource( db
, ".iconic", &value
))
433 Options
.cmdShow
= SW_SHOWMINIMIZED
;
434 if (MAIN_GetResource( db
, ".privatemap", &value
))
435 Options
.usePrivateMap
= TRUE
;
436 if (MAIN_GetResource( db
, ".fixedmap", &value
))
437 Options
.useFixedMap
= TRUE
;
438 if (MAIN_GetResource( db
, ".synchronous", &value
))
439 Options
.synchronous
= TRUE
;
440 if (MAIN_GetResource( db
, ".backingstore", &value
))
441 Options
.backingstore
= TRUE
;
442 if (MAIN_GetResource( db
, ".debug", &value
))
443 Options
.debug
= TRUE
;
444 if (MAIN_GetResource( db
, ".failreadonly", &value
))
445 Options
.failReadOnly
= TRUE
;
446 if (MAIN_GetResource( db
, ".ipc", &value
))
448 if (MAIN_GetResource( db
, ".perfect", &value
))
449 Options
.perfectGraphics
= TRUE
;
450 if (MAIN_GetResource( db
, ".depth", &value
))
451 screenDepth
= atoi( value
.addr
);
452 if (MAIN_GetResource( db
, ".desktop", &value
))
453 Options
.desktopGeometry
= value
.addr
;
454 if (MAIN_GetResource( db
, ".language", &value
))
455 MAIN_ParseLanguageOption( (char *)value
.addr
);
456 if (MAIN_GetResource( db
, ".managed", &value
))
457 Options
.managed
= TRUE
;
458 if (MAIN_GetResource( db
, ".mode", &value
))
459 MAIN_ParseModeOption( (char *)value
.addr
);
462 if (MAIN_GetResource( db
, ".debugoptions", &value
))
463 ParseDebugOptions((char*)value
.addr
);
465 if (MAIN_GetResource( db
, ".debugmsg", &value
))
467 #ifndef DEBUG_RUNTIME
468 fprintf(stderr
,"%s: Option \"-debugmsg\" not implemented.\n" \
469 " Recompile with DEBUG_RUNTIME in include/stddebug.h defined.\n",
473 if (ParseDebugOptions((char*)value
.addr
)==FALSE
)
476 fprintf(stderr
,"%s: Syntax: -debugmsg +xxx,... or -debugmsg -xxx,...\n",argv
[0]);
477 fprintf(stderr
,"Example: -debugmsg +all,-heap turn on all messages except heap messages\n");
478 fprintf(stderr
,"Available message types:\n");
479 fprintf(stderr
,"%-9s ","all");
480 for(i
=0;i
<sizeof(debug_msg_enabled
)/sizeof(short);i
++)
481 if(debug_msg_name
[i
])
482 fprintf(stderr
,"%-9s%c",debug_msg_name
[i
],
483 (((i
+2)%8==0)?'\n':' '));
484 fprintf(stderr
,"\n\n");
490 if(MAIN_GetResource( db
, ".dll", &value
))
493 if (!BUILTIN_ParseDLLOptions( (char*)value
.addr
))
495 fprintf(stderr
,"%s: Syntax: -dll +xxx,... or -dll -xxx,...\n",argv
[0]);
496 fprintf(stderr
,"Example: -dll -ole2 Do not use emulated OLE2.DLL\n");
497 fprintf(stderr
,"Available DLLs:\n");
502 fprintf(stderr
,"-dll not supported in libwine\n");
506 if(MAIN_GetResource( db
, ".winver", &value
))
507 MAIN_ParseVersion( (char*)value
.addr
);
511 /***********************************************************************
514 static void MAIN_CreateDesktop( int argc
, char *argv
[] )
517 unsigned int width
= 640, height
= 480; /* Default size = 640x480 */
518 char *name
= "Wine desktop";
519 XSizeHints
*size_hints
;
521 XClassHint
*class_hints
;
522 XSetWindowAttributes win_attr
;
523 XTextProperty window_name
;
524 Atom XA_WM_DELETE_WINDOW
;
526 flags
= XParseGeometry( Options
.desktopGeometry
,
527 &desktopX
, &desktopY
, &width
, &height
);
529 screenHeight
= height
;
533 win_attr
.event_mask
= ExposureMask
| KeyPressMask
| KeyReleaseMask
|
534 PointerMotionMask
| ButtonPressMask
|
535 ButtonReleaseMask
| EnterWindowMask
|
537 win_attr
.cursor
= XCreateFontCursor( display
, XC_top_left_arrow
);
539 rootWindow
= XCreateWindow( display
, DefaultRootWindow(display
),
540 desktopX
, desktopY
, width
, height
, 0,
541 CopyFromParent
, InputOutput
, CopyFromParent
,
542 CWEventMask
| CWCursor
, &win_attr
);
544 /* Set window manager properties */
546 size_hints
= XAllocSizeHints();
547 wm_hints
= XAllocWMHints();
548 class_hints
= XAllocClassHint();
549 if (!size_hints
|| !wm_hints
|| !class_hints
)
551 fprintf( stderr
, "Not enough memory for window manager hints.\n" );
554 size_hints
->min_width
= size_hints
->max_width
= width
;
555 size_hints
->min_height
= size_hints
->max_height
= height
;
556 size_hints
->flags
= PMinSize
| PMaxSize
;
557 if (flags
& (XValue
| YValue
)) size_hints
->flags
|= USPosition
;
558 if (flags
& (WidthValue
| HeightValue
)) size_hints
->flags
|= USSize
;
559 else size_hints
->flags
|= PSize
;
561 wm_hints
->flags
= InputHint
| StateHint
;
562 wm_hints
->input
= True
;
563 wm_hints
->initial_state
= NormalState
;
564 class_hints
->res_name
= argv
[0];
565 class_hints
->res_class
= "Wine";
567 XStringListToTextProperty( &name
, 1, &window_name
);
568 XSetWMProperties( display
, rootWindow
, &window_name
, &window_name
,
569 argv
, argc
, size_hints
, wm_hints
, class_hints
);
570 XA_WM_DELETE_WINDOW
= XInternAtom( display
, "WM_DELETE_WINDOW", False
);
571 XSetWMProtocols( display
, rootWindow
, &XA_WM_DELETE_WINDOW
, 1 );
574 XFree( class_hints
);
578 XMapWindow( display
, rootWindow
);
582 XKeyboardState keyboard_state
;
584 /***********************************************************************
587 static void MAIN_SaveSetup(void)
589 XGetKeyboardControl(display
, &keyboard_state
);
592 /***********************************************************************
595 static void MAIN_RestoreSetup(void)
597 XKeyboardControl keyboard_value
;
599 keyboard_value
.key_click_percent
= keyboard_state
.key_click_percent
;
600 keyboard_value
.bell_percent
= keyboard_state
.bell_percent
;
601 keyboard_value
.bell_pitch
= keyboard_state
.bell_pitch
;
602 keyboard_value
.bell_duration
= keyboard_state
.bell_duration
;
603 keyboard_value
.auto_repeat_mode
= keyboard_state
.global_auto_repeat
;
605 XChangeKeyboardControl(display
, KBKeyClickPercent
| KBBellPercent
|
606 KBBellPitch
| KBBellDuration
| KBAutoRepeatMode
, &keyboard_value
);
610 static void called_at_exit(void)
617 /***********************************************************************
620 * Wine initialisation and command-line parsing
622 BOOL32
MAIN_WineInit( int *argc
, char *argv
[] )
628 extern int _WinMain(int argc
, char **argv
);
630 #ifdef MALLOC_DEBUGGING
634 if (!(trace
= getenv("MALLOC_TRACE")))
636 fprintf( stderr
, "MALLOC_TRACE not set. No trace generated\n" );
640 fprintf( stderr
, "malloc trace goes to %s\n", trace
);
648 setlocale(LC_CTYPE
,"");
649 gettimeofday( &tv
, NULL
);
650 MSG_WineStartTicks
= (tv
.tv_sec
* 1000) + (tv
.tv_usec
/ 1000);
654 putenv("XKB_DISABLE="); /* Disable XKB extension if present. */
656 MAIN_ParseOptions( argc
, argv
);
658 if (Options
.desktopGeometry
&& Options
.managed
)
660 fprintf( stderr
, "%s: -managed and -desktop options cannot be used together\n",
661 Options
.programName
);
665 screen
= DefaultScreenOfDisplay( display
);
666 screenWidth
= WidthOfScreen( screen
);
667 screenHeight
= HeightOfScreen( screen
);
668 if (screenDepth
) /* -depth option specified */
670 depth_list
= XListDepths(display
,DefaultScreen(display
),&depth_count
);
671 for (i
= 0; i
< depth_count
; i
++)
672 if (depth_list
[i
] == screenDepth
) break;
674 if (i
>= depth_count
)
676 fprintf( stderr
, "%s: Depth %d not supported on this screen.\n",
677 Options
.programName
, screenDepth
);
681 else screenDepth
= DefaultDepthOfScreen( screen
);
682 if (Options
.synchronous
) XSynchronize( display
, True
);
683 if (Options
.desktopGeometry
) MAIN_CreateDesktop( *argc
, argv
);
684 else rootWindow
= DefaultRootWindow( display
);
687 atexit(called_at_exit
);
692 /***********************************************************************
693 * MessageBeep16 (USER.104)
695 void MessageBeep16( UINT16 i
)
701 /***********************************************************************
702 * MessageBeep32 (USER32.389)
704 BOOL32
MessageBeep32( UINT32 i
)
706 XBell( display
, 100 );
711 /***********************************************************************
714 BOOL32
Beep( DWORD dwFreq
, DWORD dwDur
)
716 /* dwFreq and dwDur are ignored by Win95 */
722 /***********************************************************************
723 * GetVersion16 (KERNEL.3)
725 LONG
GetVersion16(void)
727 if (getVersion16
) return getVersion16
;
728 return MAKELONG( WINVERSION
, WINDOSVER
);
732 /***********************************************************************
735 LONG
GetVersion32(void)
737 if (getVersion32
) return getVersion32
;
738 return MAKELONG( 4, DOSVERSION
);
742 /***********************************************************************
745 BOOL32
GetVersionEx32A(OSVERSIONINFO32A
*v
)
747 if(v
->dwOSVersionInfoSize
!=sizeof(OSVERSIONINFO32A
))
749 fprintf(stddeb
,"wrong OSVERSIONINFO size from app");
754 /* Return something like NT 3.5 */
755 v
->dwMajorVersion
= 3;
756 v
->dwMinorVersion
= 5;
757 v
->dwBuildNumber
= 42;
758 v
->dwPlatformId
= VER_PLATFORM_WIN32_NT
;
759 strcpy(v
->szCSDVersion
, "Wine is not an emulator");
762 v
->dwMajorVersion
= getVersionEx
.dwMajorVersion
;
763 v
->dwMinorVersion
= getVersionEx
.dwMinorVersion
;
764 v
->dwBuildNumber
= getVersionEx
.dwBuildNumber
;
765 v
->dwPlatformId
= getVersionEx
.dwPlatformId
;
766 strcpy(v
->szCSDVersion
, getVersionEx
.szCSDVersion
);
771 /***********************************************************************
774 BOOL32
GetVersionEx32W(OSVERSIONINFO32W
*v
)
777 if(v
->dwOSVersionInfoSize
!=sizeof(OSVERSIONINFO32W
))
779 fprintf(stddeb
,"wrong OSVERSIONINFO size from app");
782 v1
.dwOSVersionInfoSize
=sizeof(v1
);
783 GetVersionEx32A(&v1
);
784 v
->dwMajorVersion
= v1
.dwMajorVersion
;
785 v
->dwMinorVersion
= v1
.dwMinorVersion
;
786 v
->dwBuildNumber
= v1
.dwBuildNumber
;
787 v
->dwPlatformId
= v1
.dwPlatformId
;
788 lstrcpyAtoW( v
->szCSDVersion
, v1
.szCSDVersion
);
792 /***********************************************************************
793 * GetWinFlags (KERNEL.132)
795 DWORD
GetWinFlags(void)
797 static const long cpuflags
[5] =
798 { WF_CPU086
, WF_CPU186
, WF_CPU286
, WF_CPU386
, WF_CPU486
};
800 long result
= 0,cpuflag
;
804 /* There doesn't seem to be any Pentium flag. */
805 cpuflag
= cpuflags
[MIN (si
.wProcessorLevel
, 4)];
807 switch(Options
.mode
) {
809 result
= (WF_STANDARD
| cpuflag
| WF_PMODE
| WF_80x87
);
813 result
= (WF_ENHANCED
| cpuflag
| WF_PMODE
| WF_80x87
| WF_PAGING
);
817 fprintf(stderr
, "Unknown mode set? This shouldn't happen. Check GetWinFlags()!\n");
820 if (si
.wProcessorLevel
>=4)
821 result
|= WF_HASCPUID
;
822 if( getVersionEx
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
823 result
|= WF_WIN32WOW
; /* undocumented WF_WINNT */
827 /***********************************************************************
828 * SetEnvironment (GDI.132)
830 INT16
SetEnvironment( LPCSTR lpPortName
, LPCSTR lpEnviron
, UINT16 nCount
)
833 LPENVENTRY lpEnv
= lpEnvList
;
834 dprintf_env(stddeb
, "SetEnvironment('%s', '%s', %d) !\n",
835 lpPortName
, lpEnviron
, nCount
);
836 if (lpPortName
== NULL
) return -1;
837 while (lpEnv
!= NULL
) {
838 if (lpEnv
->Name
!= NULL
&& strcmp(lpEnv
->Name
, lpPortName
) == 0) {
839 if (nCount
== 0 || lpEnviron
== NULL
) {
840 if (lpEnv
->Prev
!= NULL
) lpEnv
->Prev
->Next
= lpEnv
->Next
;
841 if (lpEnv
->Next
!= NULL
) lpEnv
->Next
->Prev
= lpEnv
->Prev
;
845 dprintf_env(stddeb
, "SetEnvironment() // entry deleted !\n");
849 lpEnv
->Value
= malloc(nCount
);
850 if (lpEnv
->Value
== NULL
) {
851 dprintf_env(stddeb
, "SetEnvironment() // Error allocating entry value !\n");
854 memcpy(lpEnv
->Value
, lpEnviron
, nCount
);
855 lpEnv
->wSize
= nCount
;
856 dprintf_env(stddeb
, "SetEnvironment() // entry modified !\n");
859 if (lpEnv
->Next
== NULL
) break;
862 if (nCount
== 0 || lpEnviron
== NULL
) return -1;
863 dprintf_env(stddeb
, "SetEnvironment() // new entry !\n");
864 lpNewEnv
= malloc(sizeof(ENVENTRY
));
865 if (lpNewEnv
== NULL
) {
866 dprintf_env(stddeb
, "SetEnvironment() // Error allocating new entry !\n");
869 if (lpEnvList
== NULL
) {
870 lpEnvList
= lpNewEnv
;
871 lpNewEnv
->Prev
= NULL
;
875 lpEnv
->Next
= lpNewEnv
;
876 lpNewEnv
->Prev
= lpEnv
;
878 lpNewEnv
->Next
= NULL
;
879 lpNewEnv
->Name
= malloc(strlen(lpPortName
) + 1);
880 if (lpNewEnv
->Name
== NULL
) {
881 dprintf_env(stddeb
, "SetEnvironment() // Error allocating entry name !\n");
884 strcpy(lpNewEnv
->Name
, lpPortName
);
885 lpNewEnv
->Value
= malloc(nCount
);
886 if (lpNewEnv
->Value
== NULL
) {
887 dprintf_env(stddeb
, "SetEnvironment() // Error allocating entry value !\n");
890 memcpy(lpNewEnv
->Value
, lpEnviron
, nCount
);
891 lpNewEnv
->wSize
= nCount
;
896 /***********************************************************************
897 * GetEnvironment (GDI.134)
899 INT16
GetEnvironment( LPCSTR lpPortName
, LPSTR lpEnviron
, UINT16 nMaxSiz
)
902 LPENVENTRY lpEnv
= lpEnvList
;
904 dprintf_env(stddeb
, "GetEnvironment('%s', '%s', %d) !\n",
905 lpPortName
, lpEnviron
, nMaxSiz
);
906 while (lpEnv
!= NULL
) {
907 if (lpEnv
->Name
!= NULL
&& strcmp(lpEnv
->Name
, lpPortName
) == 0) {
908 if( lpEnviron
== NULL
) return lpEnv
->wSize
;
909 nCount
= MIN(nMaxSiz
, lpEnv
->wSize
);
910 memcpy(lpEnviron
, lpEnv
->Value
, nCount
);
911 dprintf_env(stddeb
, "GetEnvironment() // found '%s' !\n", lpEnv
->Value
);
916 dprintf_env(stddeb
, "GetEnvironment() // not found !\n");
921 /***********************************************************************
922 * GetTimerResolution (USER.14)
924 LONG
GetTimerResolution(void)
929 /***********************************************************************
930 * SystemParametersInfo32A (USER32.539)
932 BOOL32
SystemParametersInfo32A( UINT32 uAction
, UINT32 uParam
,
933 LPVOID lpvParam
, UINT32 fuWinIni
)
936 XKeyboardState keyboard_state
;
940 XGetKeyboardControl(display
, &keyboard_state
);
941 if (keyboard_state
.bell_percent
== 0)
942 *(BOOL32
*) lpvParam
= FALSE
;
944 *(BOOL32
*) lpvParam
= TRUE
;
948 *(INT32
*)lpvParam
= GetSystemMetrics32( SM_CXFRAME
);
951 case SPI_GETFASTTASKSWITCH
:
952 if ( GetProfileInt32A( "windows", "CoolSwitch", 1 ) == 1 )
953 *(BOOL32
*) lpvParam
= TRUE
;
955 *(BOOL32
*) lpvParam
= FALSE
;
958 case SPI_GETGRIDGRANULARITY
:
959 *(INT32
*)lpvParam
=GetProfileInt32A("desktop","GridGranularity",1);
962 case SPI_GETICONTITLEWRAP
:
963 *(BOOL32
*)lpvParam
=GetProfileInt32A("desktop","IconTitleWrap",TRUE
);
966 case SPI_GETKEYBOARDDELAY
:
967 *(INT32
*)lpvParam
=GetProfileInt32A("keyboard","KeyboardDelay",1);
970 case SPI_GETKEYBOARDSPEED
:
971 *(DWORD
*)lpvParam
=GetProfileInt32A("keyboard","KeyboardSpeed",30);
974 case SPI_GETMENUDROPALIGNMENT
:
975 *(BOOL32
*)lpvParam
=GetSystemMetrics32(SM_MENUDROPALIGNMENT
); /* XXX check this */
978 case SPI_GETSCREENSAVEACTIVE
:
979 if ( GetProfileInt32A( "windows", "ScreenSaveActive", 1 ) == 1 )
980 *(BOOL32
*)lpvParam
= TRUE
;
982 *(BOOL32
*)lpvParam
= FALSE
;
985 case SPI_GETSCREENSAVETIMEOUT
:
986 /* FIXME GetProfileInt( "windows", "ScreenSaveTimeout", 300 ); */
987 XGetScreenSaver(display
, &timeout
, &temp
,&temp
,&temp
);
988 *(INT32
*) lpvParam
= timeout
* 1000;
991 case SPI_ICONHORIZONTALSPACING
:
992 /* FIXME Get/SetProfileInt */
993 if (lpvParam
== NULL
)
994 /*SetSystemMetrics( SM_CXICONSPACING, uParam )*/ ;
996 *(INT32
*)lpvParam
=GetSystemMetrics32(SM_CXICONSPACING
);
999 case SPI_ICONVERTICALSPACING
:
1000 /* FIXME Get/SetProfileInt */
1001 if (lpvParam
== NULL
)
1002 /*SetSystemMetrics( SM_CYICONSPACING, uParam )*/ ;
1004 *(INT32
*)lpvParam
=GetSystemMetrics32(SM_CYICONSPACING
);
1007 case SPI_GETICONTITLELOGFONT
: {
1008 LPLOGFONT32A lpLogFont
= (LPLOGFONT32A
)lpvParam
;
1010 GetProfileString32A("Desktop", "IconTitleFaceName", "Helvetica",
1011 lpLogFont
->lfFaceName
, LF_FACESIZE
);
1012 lpLogFont
->lfHeight
= -GetProfileInt32A("Desktop","IconTitleSize", 8);
1014 lpLogFont
->lfWidth
= 0;
1015 lpLogFont
->lfEscapement
= lpLogFont
->lfOrientation
= 0;
1016 lpLogFont
->lfWeight
= FW_NORMAL
;
1017 lpLogFont
->lfItalic
= FALSE
;
1018 lpLogFont
->lfStrikeOut
= FALSE
;
1019 lpLogFont
->lfUnderline
= FALSE
;
1020 lpLogFont
->lfCharSet
= ANSI_CHARSET
;
1021 lpLogFont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
1022 lpLogFont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
1023 lpLogFont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_SWISS
;
1026 case SPI_GETWORKAREA
:
1027 SetRect32( (RECT32
*)lpvParam
, 0, 0,
1028 GetSystemMetrics32( SM_CXSCREEN
),
1029 GetSystemMetrics32( SM_CYSCREEN
)
1032 case SPI_GETNONCLIENTMETRICS
: {
1033 /* FIXME: implement correctly */
1034 LPNONCLIENTMETRICS32A lpnm
=(LPNONCLIENTMETRICS32A
)lpvParam
;
1036 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT
,0,(LPVOID
)&(lpnm
->lfCaptionFont
),0);
1037 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT
,0,(LPVOID
)&(lpnm
->lfMenuFont
),0);
1038 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT
,0,(LPVOID
)&(lpnm
->lfStatusFont
),0);
1039 SystemParametersInfo32A(SPI_GETICONTITLELOGFONT
,0,(LPVOID
)&(lpnm
->lfMessageFont
),0);
1043 return SystemParametersInfo16(uAction
,uParam
,lpvParam
,fuWinIni
);
1049 /***********************************************************************
1050 * SystemParametersInfo16 (USER.483)
1052 BOOL16
SystemParametersInfo16( UINT16 uAction
, UINT16 uParam
,
1053 LPVOID lpvParam
, UINT16 fuWinIni
)
1057 XKeyboardState keyboard_state
;
1058 XKeyboardControl keyboard_value
;
1064 XGetKeyboardControl(display
, &keyboard_state
);
1065 if (keyboard_state
.bell_percent
== 0)
1066 *(BOOL16
*) lpvParam
= FALSE
;
1068 *(BOOL16
*) lpvParam
= TRUE
;
1072 *(INT16
*)lpvParam
= GetSystemMetrics16( SM_CXFRAME
);
1075 case SPI_GETFASTTASKSWITCH
:
1076 if ( GetProfileInt32A( "windows", "CoolSwitch", 1 ) == 1 )
1077 *(BOOL16
*) lpvParam
= TRUE
;
1079 *(BOOL16
*) lpvParam
= FALSE
;
1082 case SPI_GETGRIDGRANULARITY
:
1083 *(INT16
*) lpvParam
= GetProfileInt32A( "desktop",
1088 case SPI_GETICONTITLEWRAP
:
1089 *(BOOL16
*) lpvParam
= GetProfileInt32A( "desktop",
1094 case SPI_GETKEYBOARDDELAY
:
1095 *(INT16
*) lpvParam
= GetProfileInt32A( "keyboard",
1096 "KeyboardDelay", 1 );
1099 case SPI_GETKEYBOARDSPEED
:
1100 *(WORD
*) lpvParam
= GetProfileInt32A( "keyboard",
1105 case SPI_GETMENUDROPALIGNMENT
:
1106 *(BOOL16
*) lpvParam
= GetSystemMetrics16( SM_MENUDROPALIGNMENT
); /* XXX check this */
1109 case SPI_GETSCREENSAVEACTIVE
:
1110 if ( GetProfileInt32A( "windows", "ScreenSaveActive", 1 ) == 1 )
1111 *(BOOL16
*) lpvParam
= TRUE
;
1113 *(BOOL16
*) lpvParam
= FALSE
;
1116 case SPI_GETSCREENSAVETIMEOUT
:
1117 /* FIXME GetProfileInt( "windows", "ScreenSaveTimeout", 300 ); */
1118 XGetScreenSaver(display
, &timeout
, &temp
,&temp
,&temp
);
1119 *(INT16
*) lpvParam
= timeout
* 1000;
1122 case SPI_ICONHORIZONTALSPACING
:
1123 /* FIXME Get/SetProfileInt */
1124 if (lpvParam
== NULL
)
1125 /*SetSystemMetrics( SM_CXICONSPACING, uParam )*/ ;
1127 *(INT16
*)lpvParam
= GetSystemMetrics16( SM_CXICONSPACING
);
1130 case SPI_ICONVERTICALSPACING
:
1131 /* FIXME Get/SetProfileInt */
1132 if (lpvParam
== NULL
)
1133 /*SetSystemMetrics( SM_CYICONSPACING, uParam )*/ ;
1135 *(INT16
*)lpvParam
= GetSystemMetrics16(SM_CYICONSPACING
);
1140 keyboard_value
.bell_percent
= -1;
1142 keyboard_value
.bell_percent
= 0;
1143 XChangeKeyboardControl(display
, KBBellPercent
,
1147 case SPI_SETSCREENSAVEACTIVE
:
1149 XActivateScreenSaver(display
);
1151 XResetScreenSaver(display
);
1154 case SPI_SETSCREENSAVETIMEOUT
:
1155 XSetScreenSaver(display
, uParam
, 60, DefaultBlanking
,
1159 case SPI_SETDESKWALLPAPER
:
1160 return (SetDeskWallPaper32((LPSTR
) lpvParam
));
1163 case SPI_SETDESKPATTERN
:
1164 if ((INT16
)uParam
== -1) {
1165 GetProfileString32A("Desktop", "Pattern",
1166 "170 85 170 85 170 85 170 85",
1167 buffer
, sizeof(buffer
) );
1168 return (DESKTOP_SetPattern((LPSTR
) buffer
));
1170 return (DESKTOP_SetPattern((LPSTR
) lpvParam
));
1173 case SPI_GETICONTITLELOGFONT
:
1175 LPLOGFONT16 lpLogFont
= (LPLOGFONT16
)lpvParam
;
1177 GetProfileString32A("Desktop", "IconTitleFaceName", "Helvetica",
1178 lpLogFont
->lfFaceName
, LF_FACESIZE
);
1179 lpLogFont
->lfHeight
= -GetProfileInt32A("Desktop","IconTitleSize", 8);
1181 lpLogFont
->lfWidth
= 0;
1182 lpLogFont
->lfEscapement
= lpLogFont
->lfOrientation
= 0;
1183 lpLogFont
->lfWeight
= FW_NORMAL
;
1184 lpLogFont
->lfItalic
= FALSE
;
1185 lpLogFont
->lfStrikeOut
= FALSE
;
1186 lpLogFont
->lfUnderline
= FALSE
;
1187 lpLogFont
->lfCharSet
= ANSI_CHARSET
;
1188 lpLogFont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
1189 lpLogFont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
1190 lpLogFont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_SWISS
;
1193 case SPI_GETNONCLIENTMETRICS
: {
1194 /* FIXME: implement correctly */
1195 LPNONCLIENTMETRICS16 lpnm
=(LPNONCLIENTMETRICS16
)lpvParam
;
1197 SystemParametersInfo16(SPI_GETICONTITLELOGFONT
,0,(LPVOID
)&(lpnm
->lfCaptionFont
),0);
1198 SystemParametersInfo16(SPI_GETICONTITLELOGFONT
,0,(LPVOID
)&(lpnm
->lfMenuFont
),0);
1199 SystemParametersInfo16(SPI_GETICONTITLELOGFONT
,0,(LPVOID
)&(lpnm
->lfStatusFont
),0);
1200 SystemParametersInfo16(SPI_GETICONTITLELOGFONT
,0,(LPVOID
)&(lpnm
->lfMessageFont
),0);
1204 case SPI_LANGDRIVER
:
1206 case SPI_SETDOUBLECLKHEIGHT
:
1207 case SPI_SETDOUBLECLICKTIME
:
1208 case SPI_SETDOUBLECLKWIDTH
:
1209 case SPI_SETFASTTASKSWITCH
:
1210 case SPI_SETKEYBOARDDELAY
:
1211 case SPI_SETKEYBOARDSPEED
:
1212 fprintf(stderr
, "SystemParametersInfo: option %d ignored.\n", uAction
);
1215 case SPI_GETWORKAREA
:
1216 SetRect16( (RECT16
*)lpvParam
, 0, 0,
1217 GetSystemMetrics16( SM_CXSCREEN
),
1218 GetSystemMetrics16( SM_CYSCREEN
) );
1222 fprintf(stderr
, "SystemParametersInfo: unknown option %d.\n", uAction
);
1228 /***********************************************************************
1229 * SystemParametersInfo32W (USER32.540)
1231 BOOL32
SystemParametersInfo32W( UINT32 uAction
, UINT32 uParam
,
1232 LPVOID lpvParam
, UINT32 fuWinIni
)
1238 case SPI_SETDESKWALLPAPER
:
1241 lstrcpynWtoA(buffer
,(LPWSTR
)lpvParam
,sizeof(buffer
));
1242 return SetDeskWallPaper32(buffer
);
1244 return SetDeskWallPaper32(NULL
);
1246 case SPI_SETDESKPATTERN
:
1247 if ((INT32
) uParam
== -1)
1249 GetProfileString32A("Desktop", "Pattern",
1250 "170 85 170 85 170 85 170 85",
1251 buffer
, sizeof(buffer
) );
1252 return (DESKTOP_SetPattern((LPSTR
) buffer
));
1256 lstrcpynWtoA(buffer
,(LPWSTR
)lpvParam
,sizeof(buffer
));
1257 return DESKTOP_SetPattern(buffer
);
1259 return DESKTOP_SetPattern(NULL
);
1261 case SPI_GETICONTITLELOGFONT
:
1263 /* FIXME GetProfileString32A( "?", "?", "?" ) */
1264 LPLOGFONT32W lpLogFont
= (LPLOGFONT32W
)lpvParam
;
1265 lpLogFont
->lfHeight
= 10;
1266 lpLogFont
->lfWidth
= 0;
1267 lpLogFont
->lfEscapement
= lpLogFont
->lfOrientation
= 0;
1268 lpLogFont
->lfWeight
= FW_NORMAL
;
1269 lpLogFont
->lfItalic
= lpLogFont
->lfStrikeOut
= lpLogFont
->lfUnderline
= FALSE
;
1270 lpLogFont
->lfCharSet
= ANSI_CHARSET
;
1271 lpLogFont
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
1272 lpLogFont
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
1273 lpLogFont
->lfPitchAndFamily
= DEFAULT_PITCH
| FF_SWISS
;
1276 case SPI_GETNONCLIENTMETRICS
: {
1277 /* FIXME: implement correctly */
1278 LPNONCLIENTMETRICS32W lpnm
=(LPNONCLIENTMETRICS32W
)lpvParam
;
1280 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT
,0,(LPVOID
)&(lpnm
->lfCaptionFont
),0);
1281 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT
,0,(LPVOID
)&(lpnm
->lfMenuFont
),0);
1282 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT
,0,(LPVOID
)&(lpnm
->lfStatusFont
),0);
1283 SystemParametersInfo32W(SPI_GETICONTITLELOGFONT
,0,(LPVOID
)&(lpnm
->lfMessageFont
),0);
1288 return SystemParametersInfo32A(uAction
,uParam
,lpvParam
,fuWinIni
);
1295 /***********************************************************************
1296 * FileCDR (KERNEL.130)
1298 void FileCDR(FARPROC16 x
)
1300 printf("FileCDR(%8x)\n", (int) x
);
1303 /***********************************************************************
1304 * GetWinDebugInfo (KERNEL.355)
1306 BOOL16
GetWinDebugInfo(WINDEBUGINFO
*lpwdi
, UINT16 flags
)
1308 printf("GetWinDebugInfo(%8lx,%d) stub returning 0\n", (unsigned long)lpwdi
, flags
);
1309 /* 0 means not in debugging mode/version */
1310 /* Can this type of debugging be used in wine ? */
1311 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
1315 /***********************************************************************
1316 * GetWinDebugInfo (KERNEL.355)
1318 BOOL16
SetWinDebugInfo(WINDEBUGINFO
*lpwdi
)
1320 printf("SetWinDebugInfo(%8lx) stub returning 0\n", (unsigned long)lpwdi
);
1321 /* 0 means not in debugging mode/version */
1322 /* Can this type of debugging be used in wine ? */
1323 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */