Implemented a default behavior for SPI_GETGRADIENTCAPTIONS flag in
[wine] / windows / sysparams.c
1 /*
2  * System parameters functions
3  *
4  * Copyright 1994 Alexandre Julliard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winnls.h"
29 #include "wingdi.h"
30 #include "winreg.h"
31 #include "wine/winuser16.h"
32 #include "winerror.h"
33
34 #include "controls.h"
35 #include "user.h"
36 #include "wine/debug.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(system);
39
40 /* System parameter indexes */
41 #define SPI_SETBEEP_IDX                         0
42 #define SPI_SETMOUSE_IDX                        1
43 #define SPI_SETBORDER_IDX                       2
44 #define SPI_SETKEYBOARDSPEED_IDX                3
45 #define SPI_ICONHORIZONTALSPACING_IDX           4
46 #define SPI_SETSCREENSAVETIMEOUT_IDX            5
47 #define SPI_SETGRIDGRANULARITY_IDX              6
48 #define SPI_SETKEYBOARDDELAY_IDX                7
49 #define SPI_ICONVERTICALSPACING_IDX             8
50 #define SPI_SETICONTITLEWRAP_IDX                9
51 #define SPI_SETMENUDROPALIGNMENT_IDX            10
52 #define SPI_SETDOUBLECLKWIDTH_IDX               11
53 #define SPI_SETDOUBLECLKHEIGHT_IDX              12
54 #define SPI_SETDOUBLECLICKTIME_IDX              13
55 #define SPI_SETMOUSEBUTTONSWAP_IDX              14
56 #define SPI_SETDRAGFULLWINDOWS_IDX              15
57 #define SPI_SETWORKAREA_IDX                     16
58 #define SPI_SETSHOWSOUNDS_IDX                   17
59 #define SPI_SETKEYBOARDPREF_IDX                 18
60 #define SPI_SETSCREENREADER_IDX                 19
61 #define SPI_SETSCREENSAVERRUNNING_IDX           20
62 #define SPI_WINE_IDX                            SPI_SETSCREENSAVERRUNNING_IDX
63
64 /**
65  * Names of the registry subkeys of HKEY_CURRENT_USER key and value names
66  * for the system parameters.
67  * Names of the keys are created by adding string "_REGKEY" to
68  * "SET" action names, value names are created by adding "_REG_NAME"
69  * to the "SET" action name.
70  */
71 #define SPI_SETBEEP_REGKEY              "Control Panel\\Sound"
72 #define SPI_SETBEEP_VALNAME             "Beep"
73 #define SPI_SETMOUSE_REGKEY             "Control Panel\\Mouse"
74 #define SPI_SETMOUSE_VALNAME1           "MouseThreshold1"
75 #define SPI_SETMOUSE_VALNAME2           "MouseThreshold2"
76 #define SPI_SETMOUSE_VALNAME3           "MouseSpeed"
77 #define SPI_SETBORDER_REGKEY            "Control Panel\\Desktop"
78 #define SPI_SETBORDER_VALNAME           "BorderWidth"
79 #define SPI_SETKEYBOARDSPEED_REGKEY             "Control Panel\\Keyboard"
80 #define SPI_SETKEYBOARDSPEED_VALNAME            "KeyboardSpeed"
81 #define SPI_ICONHORIZONTALSPACING_REGKEY        "Control Panel\\Desktop\\WindowMetrics"
82 #define SPI_ICONHORIZONTALSPACING_VALNAME       "IconSpacing"
83 #define SPI_SETSCREENSAVETIMEOUT_REGKEY         "Control Panel\\Desktop"
84 #define SPI_SETSCREENSAVETIMEOUT_VALNAME        "ScreenSaveTimeOut"
85 #define SPI_SETSCREENSAVEACTIVE_REGKEY          "Control Panel\\Desktop"
86 #define SPI_SETSCREENSAVEACTIVE_VALNAME         "ScreenSaveActive"
87 #define SPI_SETGRIDGRANULARITY_REGKEY           "Control Panel\\Desktop"
88 #define SPI_SETGRIDGRANULARITY_VALNAME          "GridGranularity"
89 #define SPI_SETKEYBOARDDELAY_REGKEY             "Control Panel\\Keyboard"
90 #define SPI_SETKEYBOARDDELAY_VALNAME            "KeyboardDelay"
91 #define SPI_ICONVERTICALSPACING_REGKEY          "Control Panel\\Desktop\\WindowMetrics"
92 #define SPI_ICONVERTICALSPACING_VALNAME         "IconVerticalSpacing"
93 #define SPI_SETICONTITLEWRAP_REGKEY1            "Control Panel\\Desktop\\WindowMetrics"
94 #define SPI_SETICONTITLEWRAP_REGKEY2            "Control Panel\\Desktop"
95 #define SPI_SETICONTITLEWRAP_VALNAME            "IconTitleWrap"
96 #define SPI_SETMENUDROPALIGNMENT_REGKEY1        "Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows"
97 #define SPI_SETMENUDROPALIGNMENT_REGKEY2        "Control Panel\\Desktop"
98 #define SPI_SETMENUDROPALIGNMENT_VALNAME        "MenuDropAlignment"
99 #define SPI_SETDOUBLECLKWIDTH_REGKEY1           "Control Panel\\Mouse"
100 #define SPI_SETDOUBLECLKWIDTH_REGKEY2           "Control Panel\\Desktop"
101 #define SPI_SETDOUBLECLKWIDTH_VALNAME           "DoubleClickWidth"
102 #define SPI_SETDOUBLECLKHEIGHT_REGKEY1          "Control Panel\\Mouse"
103 #define SPI_SETDOUBLECLKHEIGHT_REGKEY2          "Control Panel\\Desktop"
104 #define SPI_SETDOUBLECLKHEIGHT_VALNAME          "DoubleClickHeight"
105 #define SPI_SETDOUBLECLICKTIME_REGKEY           "Control Panel\\Mouse"
106 #define SPI_SETDOUBLECLICKTIME_VALNAME          "DoubleClickSpeed"
107 #define SPI_SETMOUSEBUTTONSWAP_REGKEY           "Control Panel\\Mouse"
108 #define SPI_SETMOUSEBUTTONSWAP_VALNAME          "SwapMouseButtons"
109 #define SPI_SETDRAGFULLWINDOWS_REGKEY           "Control Panel\\Desktop"
110 #define SPI_SETDRAGFULLWINDOWS_VALNAME          "DragFullWindows"
111 #define SPI_SETWORKAREA_REGKEY                  "Control Panel\\Desktop"
112 #define SPI_SETWORKAREA_VALNAME                 "WINE_WorkArea"
113 #define SPI_SETSHOWSOUNDS_REGKEY        "Control Panel\\Accessibility\\ShowSounds"
114 #define SPI_SETSHOWSOUNDS_VALNAME       "On"
115 #define SPI_SETDESKWALLPAPER_REGKEY     "Control Panel\\Desktop"
116 #define SPI_SETDESKWALLPAPER_VALNAME    "Wallpaper"
117 /* FIXME - real values */
118 #define SPI_SETKEYBOARDPREF_REGKEY      "Control Panel\\Desktop"
119 #define SPI_SETKEYBOARDPREF_VALNAME     "WINE_KeyboardPref"
120 #define SPI_SETSCREENREADER_REGKEY      "Control Panel\\Desktop"
121 #define SPI_SETSCREENREADER_VALNAME     "WINE_ScreenReader"
122 #define SPI_SETSCREENSAVERRUNNING_REGKEY        "Control Panel\\Desktop"
123 #define SPI_SETSCREENSAVERRUNNING_VALNAME       "WINE_ScreenSaverRunning"
124
125 /* volatile registry branch under CURRENT_USER_REGKEY for temporary values storage */
126 #define WINE_CURRENT_USER_REGKEY     "Wine"
127
128 /* Indicators whether system parameter value is loaded */
129 static char spi_loaded[SPI_WINE_IDX + 1];
130
131 static BOOL notify_change = TRUE;
132
133 /* System parameters storage */
134 static BOOL beep_active = TRUE;
135 static int mouse_threshold1 = 6;
136 static int mouse_threshold2 = 10;
137 static int mouse_speed = 1;
138 static int border = 1;
139 static int keyboard_speed = 31;
140 static int screensave_timeout = 300;
141 static int grid_granularity = 0;
142 static int keyboard_delay = 1;
143 static BOOL icon_title_wrap = TRUE;
144 static int double_click_time = 500;
145 static BOOL drag_full_windows = FALSE;
146 static RECT work_area;
147 static BOOL keyboard_pref = TRUE;
148 static BOOL screen_reader = FALSE;
149 static BOOL screensaver_running = FALSE;
150
151 /***********************************************************************
152  *              GetTimerResolution (USER.14)
153  */
154 LONG WINAPI GetTimerResolution16(void)
155 {
156         return (1000);
157 }
158
159 /***********************************************************************
160  *              ControlPanelInfo (USER.273)
161  */
162 void WINAPI ControlPanelInfo16( INT16 nInfoType, WORD wData, LPSTR lpBuffer )
163 {
164         FIXME("(%d, %04x, %p): stub.\n", nInfoType, wData, lpBuffer);
165 }
166
167 /* This function is a copy of the one in objects/font.c */
168 static void SYSPARAMS_LogFont32ATo16( const LOGFONTA* font32, LPLOGFONT16 font16 )
169 {
170     font16->lfHeight = font32->lfHeight;
171     font16->lfWidth = font32->lfWidth;
172     font16->lfEscapement = font32->lfEscapement;
173     font16->lfOrientation = font32->lfOrientation;
174     font16->lfWeight = font32->lfWeight;
175     font16->lfItalic = font32->lfItalic;
176     font16->lfUnderline = font32->lfUnderline;
177     font16->lfStrikeOut = font32->lfStrikeOut;
178     font16->lfCharSet = font32->lfCharSet;
179     font16->lfOutPrecision = font32->lfOutPrecision;
180     font16->lfClipPrecision = font32->lfClipPrecision;
181     font16->lfQuality = font32->lfQuality;
182     font16->lfPitchAndFamily = font32->lfPitchAndFamily;
183     lstrcpynA( font16->lfFaceName, font32->lfFaceName, LF_FACESIZE );
184 }
185
186 static void SYSPARAMS_LogFont32ATo32W( const LOGFONTA* font32A, LPLOGFONTW font32W )
187 {
188     font32W->lfHeight = font32A->lfHeight;
189     font32W->lfWidth = font32A->lfWidth;
190     font32W->lfEscapement = font32A->lfEscapement;
191     font32W->lfOrientation = font32A->lfOrientation;
192     font32W->lfWeight = font32A->lfWeight;
193     font32W->lfItalic = font32A->lfItalic;
194     font32W->lfUnderline = font32A->lfUnderline;
195     font32W->lfStrikeOut = font32A->lfStrikeOut;
196     font32W->lfCharSet = font32A->lfCharSet;
197     font32W->lfOutPrecision = font32A->lfOutPrecision;
198     font32W->lfClipPrecision = font32A->lfClipPrecision;
199     font32W->lfQuality = font32A->lfQuality;
200     font32W->lfPitchAndFamily = font32A->lfPitchAndFamily;
201     MultiByteToWideChar( CP_ACP, 0, font32A->lfFaceName, -1, font32W->lfFaceName, LF_FACESIZE );
202     font32W->lfFaceName[LF_FACESIZE-1] = 0;
203 }
204
205 static void SYSPARAMS_NonClientMetrics32ATo16( const NONCLIENTMETRICSA* lpnm32, LPNONCLIENTMETRICS16 lpnm16 )
206 {
207     lpnm16->iBorderWidth        = lpnm32->iBorderWidth;
208     lpnm16->iScrollWidth        = lpnm32->iScrollWidth;
209     lpnm16->iScrollHeight       = lpnm32->iScrollHeight;
210     lpnm16->iCaptionWidth       = lpnm32->iCaptionWidth;
211     lpnm16->iCaptionHeight      = lpnm32->iCaptionHeight;
212     SYSPARAMS_LogFont32ATo16( &lpnm32->lfCaptionFont,   &lpnm16->lfCaptionFont );
213     lpnm16->iSmCaptionWidth     = lpnm32->iSmCaptionWidth;
214     lpnm16->iSmCaptionHeight    = lpnm32->iSmCaptionHeight;
215     SYSPARAMS_LogFont32ATo16( &lpnm32->lfSmCaptionFont, &lpnm16->lfSmCaptionFont );
216     lpnm16->iMenuWidth          = lpnm32->iMenuWidth;
217     lpnm16->iMenuHeight         = lpnm32->iMenuHeight;
218     SYSPARAMS_LogFont32ATo16( &lpnm32->lfMenuFont,      &lpnm16->lfMenuFont );
219     SYSPARAMS_LogFont32ATo16( &lpnm32->lfStatusFont,    &lpnm16->lfStatusFont );
220     SYSPARAMS_LogFont32ATo16( &lpnm32->lfMessageFont,   &lpnm16->lfMessageFont );
221 }
222
223 static void SYSPARAMS_NonClientMetrics32ATo32W( const NONCLIENTMETRICSA* lpnm32A, LPNONCLIENTMETRICSW lpnm32W )
224 {
225     lpnm32W->iBorderWidth       = lpnm32A->iBorderWidth;
226     lpnm32W->iScrollWidth       = lpnm32A->iScrollWidth;
227     lpnm32W->iScrollHeight      = lpnm32A->iScrollHeight;
228     lpnm32W->iCaptionWidth      = lpnm32A->iCaptionWidth;
229     lpnm32W->iCaptionHeight     = lpnm32A->iCaptionHeight;
230     SYSPARAMS_LogFont32ATo32W( &lpnm32A->lfCaptionFont,         &lpnm32W->lfCaptionFont );
231     lpnm32W->iSmCaptionWidth    = lpnm32A->iSmCaptionWidth;
232     lpnm32W->iSmCaptionHeight   = lpnm32A->iSmCaptionHeight;
233     SYSPARAMS_LogFont32ATo32W( &lpnm32A->lfSmCaptionFont,       &lpnm32W->lfSmCaptionFont );
234     lpnm32W->iMenuWidth         = lpnm32A->iMenuWidth;
235     lpnm32W->iMenuHeight        = lpnm32A->iMenuHeight;
236     SYSPARAMS_LogFont32ATo32W( &lpnm32A->lfMenuFont,            &lpnm32W->lfMenuFont );
237     SYSPARAMS_LogFont32ATo32W( &lpnm32A->lfStatusFont,          &lpnm32W->lfStatusFont );
238     SYSPARAMS_LogFont32ATo32W( &lpnm32A->lfMessageFont,         &lpnm32W->lfMessageFont );
239 }
240
241 /***********************************************************************
242  *           SYSPARAMS_Reset
243  *
244  * Sets the system parameter which should be always loaded to
245  * current value stored in registry.
246  * Invalidates lazy loaded parameter, so it will be loaded the next time
247  * it is requested.
248  *
249  * Parameters:
250  * uiAction - system parameter to reload value for.
251  *      Note, only "SET" values can be used for this parameter.
252  *      If uiAction is 0 all system parameters are reset.
253  */
254 void SYSPARAMS_Reset( UINT uiAction )
255 {
256 #define WINE_RELOAD_SPI(x) \
257     case x: \
258         spi_loaded[x##_IDX] = FALSE; \
259         SystemParametersInfoA( x, 0, dummy_buf, 0 );\
260         if (uiAction) \
261             break
262
263 #define WINE_IGNORE_SPI(x) \
264     case x: \
265         if (uiAction) \
266             break
267
268 #define WINE_INVALIDATE_SPI(x) \
269     case x: \
270         spi_loaded[x##_IDX] = FALSE; \
271         break
272
273     BOOL not_all_processed = TRUE;
274     char dummy_buf[10];
275
276     /* Execution falls through all the branches for uiAction == 0 */
277     switch (uiAction)
278     {
279     case 0:
280         memset( spi_loaded, 0, sizeof(spi_loaded) );
281
282     WINE_RELOAD_SPI(SPI_SETBORDER);
283     WINE_RELOAD_SPI(SPI_ICONHORIZONTALSPACING);
284     WINE_RELOAD_SPI(SPI_ICONVERTICALSPACING);
285     WINE_IGNORE_SPI(SPI_SETSCREENSAVEACTIVE);
286     WINE_RELOAD_SPI(SPI_SETDOUBLECLKWIDTH);
287     WINE_RELOAD_SPI(SPI_SETDOUBLECLKHEIGHT);
288     WINE_RELOAD_SPI(SPI_SETMOUSEBUTTONSWAP);
289     WINE_RELOAD_SPI(SPI_SETSHOWSOUNDS);
290     WINE_RELOAD_SPI(SPI_SETMENUDROPALIGNMENT);
291
292     default:
293         if (uiAction)
294         {
295             /* lazy loaded parameters */
296             switch (uiAction)
297             {
298             WINE_INVALIDATE_SPI(SPI_SETBEEP);
299             WINE_INVALIDATE_SPI(SPI_SETMOUSE);
300             WINE_INVALIDATE_SPI(SPI_SETKEYBOARDSPEED);
301             WINE_INVALIDATE_SPI(SPI_SETSCREENSAVETIMEOUT);
302             WINE_INVALIDATE_SPI(SPI_SETGRIDGRANULARITY);
303             WINE_INVALIDATE_SPI(SPI_SETKEYBOARDDELAY);
304             WINE_INVALIDATE_SPI(SPI_SETICONTITLEWRAP);
305             WINE_INVALIDATE_SPI(SPI_SETDOUBLECLICKTIME);
306             WINE_INVALIDATE_SPI(SPI_SETDRAGFULLWINDOWS);
307             WINE_INVALIDATE_SPI(SPI_SETWORKAREA);
308             WINE_INVALIDATE_SPI(SPI_SETKEYBOARDPREF);
309             WINE_INVALIDATE_SPI(SPI_SETSCREENREADER);
310             WINE_INVALIDATE_SPI(SPI_SETSCREENSAVERRUNNING);
311             default:
312                 FIXME( "Unknown action reset: %u\n", uiAction );
313                 break;
314             }
315         }
316         else
317             not_all_processed = FALSE;
318         break;
319     }
320
321     if (!uiAction && not_all_processed)
322         ERR( "Incorrect implementation of SYSPARAMS_Reset. "
323              "Not all params are reloaded.\n" );
324 #undef WINE_INVALIDATE_SPI
325 #undef WINE_IGNORE_SPI
326 #undef WINE_RELOAD_SPI
327 }
328
329 /***********************************************************************
330  *           get_volatile_regkey
331  *
332  * Return a handle to the volatile registry key used to store
333  * non-permanently modified parameters.
334  */
335 static HKEY get_volatile_regkey(void)
336 {
337     static HKEY volatile_key;
338
339     if (!volatile_key)
340     {
341         if (RegCreateKeyExA( HKEY_CURRENT_USER, WINE_CURRENT_USER_REGKEY,
342                              0, 0, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, 0,
343                              &volatile_key, 0 ) != ERROR_SUCCESS)
344             ERR("Can't create wine configuration registry branch\n");
345     }
346     return volatile_key;
347 }
348
349 /***********************************************************************
350  *           SYSPARAMS_NotifyChange
351  *
352  * Sends notification about system parameter update.
353  */
354 void SYSPARAMS_NotifyChange( UINT uiAction, UINT fWinIni )
355 {
356     if (notify_change)
357     {
358         if (fWinIni & SPIF_UPDATEINIFILE)
359         {
360             if (fWinIni & (SPIF_SENDWININICHANGE | SPIF_SENDCHANGE))
361                 SendMessageA(HWND_BROADCAST, WM_SETTINGCHANGE,
362                              uiAction, (LPARAM) "");
363         }
364         else
365         {
366             /* FIXME notify other wine processes with internal message */
367         }
368     }
369 }
370
371
372 /***********************************************************************
373  * Loads system parameter from user profile.
374  */
375 BOOL SYSPARAMS_Load( LPSTR lpRegKey, LPSTR lpValName, LPSTR lpBuf )
376 {
377     BOOL ret = FALSE;
378     DWORD type;
379     HKEY hKey;
380     DWORD count;
381
382     if ((RegOpenKeyA( get_volatile_regkey(), lpRegKey,
383                      &hKey ) == ERROR_SUCCESS) ||
384         (RegOpenKeyA( HKEY_CURRENT_USER, lpRegKey,
385                       &hKey ) == ERROR_SUCCESS))
386     {
387         ret = !RegQueryValueExA( hKey, lpValName, NULL, &type, lpBuf, &count );
388         RegCloseKey( hKey );
389     }
390     return ret;
391 }
392
393 /***********************************************************************
394  * Saves system parameter to user profile.
395  */
396 BOOL SYSPARAMS_Save( LPSTR lpRegKey, LPSTR lpValName, LPSTR lpValue,
397                      UINT fWinIni )
398 {
399     HKEY hKey;
400     HKEY hBaseKey;
401     DWORD dwOptions;
402     BOOL ret = FALSE;
403
404     if (fWinIni & SPIF_UPDATEINIFILE)
405     {
406         hBaseKey = HKEY_CURRENT_USER;
407         dwOptions = 0;
408     }
409     else
410     {
411         hBaseKey = get_volatile_regkey();
412         dwOptions = REG_OPTION_VOLATILE;
413     }
414
415     if (RegCreateKeyExA( hBaseKey, lpRegKey,
416                          0, 0, dwOptions, KEY_ALL_ACCESS,
417                          0, &hKey, 0 ) == ERROR_SUCCESS)
418     {
419         if (RegSetValueExA( hKey, lpValName, 0, REG_SZ,
420                             lpValue, strlen(lpValue) + 1 ) == ERROR_SUCCESS)
421         {
422             ret = TRUE;
423             if (hBaseKey == HKEY_CURRENT_USER)
424                 RegDeleteKeyA( get_volatile_regkey(), lpRegKey );
425         }
426         RegCloseKey( hKey );
427     }
428     return ret;
429 }
430
431
432 /***********************************************************************
433  *           SYSPARAMS_GetDoubleClickSize
434  *
435  * There is no SPI_GETDOUBLECLK* so we export this function instead.
436  */
437 void SYSPARAMS_GetDoubleClickSize( INT *width, INT *height )
438 {
439     char buf[10];
440
441     if (!spi_loaded[SPI_SETDOUBLECLKWIDTH_IDX])
442     {
443         char buf[10];
444
445         if (SYSPARAMS_Load( SPI_SETDOUBLECLKWIDTH_REGKEY1,
446                             SPI_SETDOUBLECLKWIDTH_VALNAME, buf ))
447         {
448             SYSMETRICS_Set( SM_CXDOUBLECLK, atoi( buf ) );
449         }
450         spi_loaded[SPI_SETDOUBLECLKWIDTH_IDX] = TRUE;
451     }
452     if (!spi_loaded[SPI_SETDOUBLECLKHEIGHT_IDX])
453     {
454         if (SYSPARAMS_Load( SPI_SETDOUBLECLKHEIGHT_REGKEY1,
455                             SPI_SETDOUBLECLKHEIGHT_VALNAME, buf ))
456         {
457             SYSMETRICS_Set( SM_CYDOUBLECLK, atoi( buf ) );
458         }
459         spi_loaded[SPI_SETDOUBLECLKHEIGHT_IDX] = TRUE;
460     }
461     *width  = GetSystemMetrics( SM_CXDOUBLECLK );
462     *height = GetSystemMetrics( SM_CYDOUBLECLK );
463 }
464
465
466 /***********************************************************************
467  *           SYSPARAMS_GetMouseButtonSwap
468  *
469  * There is no SPI_GETMOUSEBUTTONSWAP so we export this function instead.
470  */
471 INT SYSPARAMS_GetMouseButtonSwap( void )
472 {
473         int spi_idx = SPI_SETMOUSEBUTTONSWAP_IDX;
474
475         if (!spi_loaded[spi_idx])
476         {
477             char buf[5];
478
479             if (SYSPARAMS_Load( SPI_SETMOUSEBUTTONSWAP_REGKEY,
480                                 SPI_SETMOUSEBUTTONSWAP_VALNAME, buf ))
481             {
482                 SYSMETRICS_Set( SM_SWAPBUTTON, atoi( buf ) );
483             }
484             spi_loaded[spi_idx] = TRUE;
485         }
486
487         return GetSystemMetrics( SM_SWAPBUTTON );
488 }
489
490 /***********************************************************************
491  *
492  *      SYSPARAMS_GetGUIFont
493  *
494  *  fills LOGFONT with 'default GUI font'.
495  */
496
497 static void SYSPARAMS_GetGUIFont( LOGFONTA* plf )
498 {
499         HFONT   hf;
500
501         memset( plf, 0, sizeof(LOGFONTA) );
502         hf = (HFONT)GetStockObject( DEFAULT_GUI_FONT );
503         if ( GetObjectA( hf, sizeof(LOGFONTA), plf ) != sizeof(LOGFONTA) )
504         {
505                 /*
506                  * GetObjectA() would be succeeded always
507                  * since this is a stock object
508                  */
509                 ERR("GetObjectA() failed\n");
510         }
511 }
512
513 /* copied from GetSystemMetrics()'s RegistryTwips2Pixels() */
514 inline static int SYSPARAMS_Twips2Pixels(int x)
515 {
516     if (x < 0)
517         x = (-x+7)/15;
518     return x;
519 }
520
521 /***********************************************************************
522  *              SystemParametersInfoA (USER32.@)
523  *
524  *     Each system parameter has flag which shows whether the parameter
525  * is loaded or not. Parameters, stored directly in SysParametersInfo are
526  * loaded from registry only when they are requested and the flag is
527  * "false", after the loading the flag is set to "true". On interprocess
528  * notification of the parameter change the corresponding parameter flag is
529  * set to "false". The parameter value will be reloaded when it is requested
530  * the next time.
531  *     Parameters, backed by or depend on GetSystemMetrics are processed
532  * differently. These parameters are always loaded. They are reloaded right
533  * away on interprocess change notification. We can't do lazy loading because
534  * we don't want to complicate GetSystemMetrics.
535  *     Parameters, backed by X settings are read from corresponding setting.
536  * On the parameter change request the setting is changed. Interprocess change
537  * notifications are ignored.
538  *     When parameter value is updated the changed value is stored in permanent
539  * registry branch if saving is requested. Otherwise it is stored
540  * in temporary branch
541  *
542  * Some SPI values can also be stored as Twips values in the registry,
543  * don't forget the conversion!
544  */
545 BOOL WINAPI SystemParametersInfoA( UINT uiAction, UINT uiParam,
546                                    PVOID pvParam, UINT fWinIni )
547 {
548 #define WINE_SPI_FIXME(x) \
549     case x: \
550         FIXME( "Unimplemented action: %u (%s)\n", x, #x ); \
551         SetLastError( ERROR_INVALID_SPI_VALUE ); \
552         ret = FALSE; \
553         break
554 #define WINE_SPI_WARN(x) \
555     case x: \
556         WARN( "Ignored action: %u (%s)\n", x, #x ); \
557         break
558
559     BOOL ret = TRUE;
560     unsigned spi_idx = 0;
561
562     TRACE("(%u, %u, %p, %u)\n", uiAction, uiParam, pvParam, fWinIni);
563
564     switch (uiAction)
565     {
566     case SPI_GETBEEP:                           /*      1 */
567         spi_idx = SPI_SETBEEP_IDX;
568         if (!spi_loaded[spi_idx])
569         {
570             char buf[5];
571
572             if (SYSPARAMS_Load( SPI_SETBEEP_REGKEY, SPI_SETBEEP_VALNAME, buf ))
573                 beep_active  = !strcasecmp( "Yes", buf );
574             spi_loaded[spi_idx] = TRUE;
575         }
576
577         *(BOOL *)pvParam = beep_active;
578         break;
579
580     case SPI_SETBEEP:                           /*      2 */
581         spi_idx = SPI_SETBEEP_IDX;
582         if (SYSPARAMS_Save( SPI_SETBEEP_REGKEY, SPI_SETBEEP_VALNAME,
583                             (uiParam ? "Yes" : "No"), fWinIni ))
584         {
585             beep_active = uiParam;
586             spi_loaded[spi_idx] = TRUE;
587         }
588         else
589             ret = FALSE;
590         break;
591
592     case SPI_GETMOUSE:                          /*      3 */
593         spi_idx = SPI_SETMOUSE_IDX;
594         if (!spi_loaded[spi_idx])
595         {
596             char buf[10];
597
598             if (SYSPARAMS_Load( SPI_SETMOUSE_REGKEY, SPI_SETMOUSE_VALNAME1,
599                                 buf ))
600                 mouse_threshold1 = atoi( buf );
601             if (SYSPARAMS_Load( SPI_SETMOUSE_REGKEY, SPI_SETMOUSE_VALNAME2,
602                                 buf ))
603                 mouse_threshold2 = atoi( buf );
604             if (SYSPARAMS_Load( SPI_SETMOUSE_REGKEY, SPI_SETMOUSE_VALNAME3,
605                                 buf ))
606                 mouse_speed = atoi( buf );
607             spi_loaded[spi_idx] = TRUE;
608         }
609         ((INT *)pvParam)[0] = mouse_threshold1;
610         ((INT *)pvParam)[1] = mouse_threshold2;
611         ((INT *)pvParam)[2] = mouse_speed;
612         break;
613
614     case SPI_SETMOUSE:                          /*      4 */
615     {
616         char buf[10];
617
618         spi_idx = SPI_SETMOUSE_IDX;
619         sprintf(buf, "%d", ((INT *)pvParam)[0]);
620
621         if (SYSPARAMS_Save( SPI_SETMOUSE_REGKEY, SPI_SETMOUSE_VALNAME1,
622                             buf, fWinIni ))
623         {
624             mouse_threshold1 = ((INT *)pvParam)[0];
625             spi_loaded[spi_idx] = TRUE;
626
627             sprintf(buf, "%d", ((INT *)pvParam)[1]);
628             SYSPARAMS_Save( SPI_SETMOUSE_REGKEY, SPI_SETMOUSE_VALNAME2,
629                             buf, fWinIni );
630             mouse_threshold2 = ((INT *)pvParam)[1];
631
632             sprintf(buf, "%d", ((INT *)pvParam)[2]);
633             SYSPARAMS_Save( SPI_SETMOUSE_REGKEY, SPI_SETMOUSE_VALNAME3,
634                             buf, fWinIni );
635             mouse_speed = ((INT *)pvParam)[2];
636         }
637         else
638             ret = FALSE;
639         break;
640     }
641
642     case SPI_GETBORDER:                         /*      5 */
643         spi_idx = SPI_SETBORDER_IDX;
644         if (!spi_loaded[spi_idx])
645         {
646             char buf[10];
647
648             if (SYSPARAMS_Load( SPI_SETBORDER_REGKEY, SPI_SETBORDER_VALNAME, buf ))
649                 border = SYSPARAMS_Twips2Pixels( atoi(buf) );
650
651             spi_loaded[spi_idx] = TRUE;
652             if (TWEAK_WineLook > WIN31_LOOK)
653             {
654                 SYSMETRICS_Set( SM_CXFRAME, border + GetSystemMetrics( SM_CXDLGFRAME ) );
655                 SYSMETRICS_Set( SM_CYFRAME, border + GetSystemMetrics( SM_CXDLGFRAME ) );
656             }
657         }
658         *(INT *)pvParam = border;
659         break;
660
661     case SPI_SETBORDER:                         /*      6 */
662     {
663         char buf[10];
664
665         spi_idx = SPI_SETBORDER_IDX;
666         sprintf(buf, "%u", uiParam);
667
668         if (SYSPARAMS_Save( SPI_SETBORDER_REGKEY, SPI_SETBORDER_VALNAME,
669                             buf, fWinIni ))
670         {
671             if (uiParam > 0)
672             {
673                 border = uiParam;
674                 spi_loaded[spi_idx] = TRUE;
675                 if (TWEAK_WineLook > WIN31_LOOK)
676                 {
677                     SYSMETRICS_Set( SM_CXFRAME, uiParam + GetSystemMetrics( SM_CXDLGFRAME ) );
678                     SYSMETRICS_Set( SM_CYFRAME, uiParam + GetSystemMetrics( SM_CXDLGFRAME ) );
679                 }
680             }
681         }
682         else
683             ret = FALSE;
684         break;
685     }
686
687     case SPI_GETKEYBOARDSPEED:                  /*     10 */
688         spi_idx = SPI_SETKEYBOARDSPEED_IDX;
689         if (!spi_loaded[spi_idx])
690         {
691             char buf[10];
692
693             if (SYSPARAMS_Load( SPI_SETKEYBOARDSPEED_REGKEY,
694                                 SPI_SETKEYBOARDSPEED_VALNAME,
695                                 buf ))
696                 keyboard_speed = atoi( buf );
697             spi_loaded[spi_idx] = TRUE;
698         }
699         *(INT *)pvParam = keyboard_speed;
700         break;
701
702     case SPI_SETKEYBOARDSPEED:                  /*     11 */
703     {
704         char buf[10];
705
706         spi_idx = SPI_SETKEYBOARDSPEED_IDX;
707         if (uiParam > 31)
708             uiParam = 31;
709         sprintf(buf, "%u", uiParam);
710
711         if (SYSPARAMS_Save( SPI_SETKEYBOARDSPEED_REGKEY,
712                             SPI_SETKEYBOARDSPEED_VALNAME,
713                             buf, fWinIni ))
714         {
715             keyboard_speed = uiParam;
716             spi_loaded[spi_idx] = TRUE;
717         }
718         else
719             ret = FALSE;
720         break;
721     }
722
723     /* not implemented in Windows */
724     WINE_SPI_WARN(SPI_LANGDRIVER);              /*     12 */
725
726     case SPI_ICONHORIZONTALSPACING:             /*     13 */
727         spi_idx = SPI_ICONHORIZONTALSPACING_IDX;
728         if (pvParam != NULL)
729         {
730             if (!spi_loaded[spi_idx])
731             {
732                 char buf[10];
733                 int val;
734
735                 if (SYSPARAMS_Load( SPI_ICONHORIZONTALSPACING_REGKEY,
736                                     SPI_ICONHORIZONTALSPACING_VALNAME, buf ))
737                 {
738                     val = SYSPARAMS_Twips2Pixels( atoi(buf) );
739                     SYSMETRICS_Set( SM_CXICONSPACING, val );
740                 }
741                 spi_loaded[spi_idx] = TRUE;
742             }
743
744             *(INT *)pvParam = GetSystemMetrics( SM_CXICONSPACING );
745         }
746         else
747         {
748             char buf[10];
749
750             if (uiParam < 32) uiParam = 32;
751
752             sprintf(buf, "%u", uiParam);
753             if (SYSPARAMS_Save( SPI_ICONHORIZONTALSPACING_REGKEY,
754                                 SPI_ICONHORIZONTALSPACING_VALNAME,
755                                 buf, fWinIni ))
756             {
757                 SYSMETRICS_Set( SM_CXICONSPACING, uiParam );
758                 spi_loaded[spi_idx] = TRUE;
759             }
760             else
761                 ret = FALSE;
762         }
763         break;
764
765     case SPI_GETSCREENSAVETIMEOUT:              /*     14 */
766         spi_idx = SPI_SETSCREENSAVETIMEOUT_IDX;
767         if (!spi_loaded[spi_idx])
768         {
769             char buf[10];
770
771             if (SYSPARAMS_Load( SPI_SETSCREENSAVETIMEOUT_REGKEY,
772                                 SPI_SETSCREENSAVETIMEOUT_VALNAME,
773                                 buf ))
774                 screensave_timeout = atoi( buf );
775
776             spi_loaded[spi_idx] = TRUE;
777         }
778         *(INT *)pvParam = screensave_timeout;
779         break;
780
781     case SPI_SETSCREENSAVETIMEOUT:              /*     15 */
782     {
783         char buf[10];
784
785         spi_idx = SPI_SETSCREENSAVETIMEOUT_IDX;
786         sprintf(buf, "%u", uiParam);
787
788         if (SYSPARAMS_Save( SPI_SETSCREENSAVETIMEOUT_REGKEY,
789                             SPI_SETSCREENSAVETIMEOUT_VALNAME,
790                             buf, fWinIni ))
791         {
792             screensave_timeout = uiParam;
793             spi_loaded[spi_idx] = TRUE;
794         }
795         else
796             ret = FALSE;
797         break;
798     }
799
800     case SPI_GETSCREENSAVEACTIVE:               /*     16 */
801         *(BOOL *)pvParam = USER_Driver.pGetScreenSaveActive();
802         break;
803
804     case SPI_SETSCREENSAVEACTIVE:               /*     17 */
805     {
806         char buf[5];
807
808         sprintf(buf, "%u", uiParam);
809         USER_Driver.pSetScreenSaveActive( uiParam );
810         /* saved value does not affect Wine */
811         SYSPARAMS_Save( SPI_SETSCREENSAVEACTIVE_REGKEY,
812                         SPI_SETSCREENSAVEACTIVE_VALNAME,
813                         buf, fWinIni );
814         break;
815     }
816
817     case SPI_GETGRIDGRANULARITY:                /*     18 */
818         spi_idx = SPI_SETGRIDGRANULARITY_IDX;
819         if (!spi_loaded[spi_idx])
820         {
821             char buf[10];
822
823             if (SYSPARAMS_Load( SPI_SETGRIDGRANULARITY_REGKEY,
824                                 SPI_SETGRIDGRANULARITY_VALNAME,
825                                 buf ))
826                 grid_granularity = atoi( buf );
827
828             spi_loaded[spi_idx] = TRUE;
829         }
830         *(INT *)pvParam = grid_granularity;
831         break;
832
833     case SPI_SETGRIDGRANULARITY:                /*     19 */
834     {
835         char buf[10];
836
837         spi_idx = SPI_SETGRIDGRANULARITY_IDX;
838         sprintf(buf, "%u", uiParam);
839
840         if (SYSPARAMS_Save( SPI_SETGRIDGRANULARITY_REGKEY,
841                             SPI_SETGRIDGRANULARITY_VALNAME,
842                             buf, fWinIni ))
843         {
844             grid_granularity = uiParam;
845             spi_loaded[spi_idx] = TRUE;
846         }
847         else
848             ret = FALSE;
849         break;
850     }
851
852     case SPI_SETDESKWALLPAPER:                  /*     20 */
853         SYSPARAMS_Save(SPI_SETDESKWALLPAPER_REGKEY, SPI_SETDESKWALLPAPER_VALNAME, pvParam, fWinIni);
854         ret = SetDeskWallPaper( (LPSTR)pvParam );
855         break;
856     case SPI_SETDESKPATTERN:                    /*     21 */
857         /* FIXME: the ability to specify a pattern in pvParam
858            doesn't seem to be documented for Win32 */
859         if ((INT16)uiParam == -1)
860         {
861             char buffer[256];
862             GetProfileStringA( "Desktop", "Pattern",
863                                "170 85 170 85 170 85 170 85",
864                                buffer, sizeof(buffer) );
865             ret = DESKTOP_SetPattern( (LPSTR)buffer );
866         } else
867             ret = DESKTOP_SetPattern( (LPSTR)pvParam );
868         break;
869
870     case SPI_GETKEYBOARDDELAY:                  /*     22 */
871         spi_idx = SPI_SETKEYBOARDDELAY_IDX;
872         if (!spi_loaded[spi_idx])
873         {
874             char buf[10];
875
876             if (SYSPARAMS_Load( SPI_SETKEYBOARDDELAY_REGKEY,
877                                 SPI_SETKEYBOARDDELAY_VALNAME,
878                                 buf ))
879             {
880                 int i = atoi( buf );
881                 if ( (i >= 0) && (i <= 3)) keyboard_delay = i;
882             }
883
884             spi_loaded[spi_idx] = TRUE;
885         }
886         *(INT *)pvParam = keyboard_delay;
887         break;
888
889     case SPI_SETKEYBOARDDELAY:                  /*     23 */
890     {
891         char buf[10];
892
893         spi_idx = SPI_SETKEYBOARDDELAY_IDX;
894         sprintf(buf, "%u", uiParam);
895
896         if (SYSPARAMS_Save( SPI_SETKEYBOARDDELAY_REGKEY,
897                             SPI_SETKEYBOARDDELAY_VALNAME,
898                             buf, fWinIni ))
899         {
900             if (uiParam <= 3)
901                 keyboard_delay = uiParam;
902             spi_loaded[spi_idx] = TRUE;
903         }
904         else
905             ret = FALSE;
906         break;
907     }
908
909     case SPI_ICONVERTICALSPACING:               /*     24 */
910         spi_idx = SPI_ICONVERTICALSPACING_IDX;
911         if (pvParam != NULL)
912         {
913             if (!spi_loaded[spi_idx])
914             {
915                 char buf[10];
916                 int val;
917
918                 if (SYSPARAMS_Load( SPI_ICONVERTICALSPACING_REGKEY,
919                                     SPI_ICONVERTICALSPACING_VALNAME, buf ))
920                 {
921                     val = SYSPARAMS_Twips2Pixels( atoi(buf) );
922                     SYSMETRICS_Set( SM_CYICONSPACING, val );
923                 }
924                 spi_loaded[spi_idx] = TRUE;
925             }
926
927             *(INT *)pvParam = GetSystemMetrics( SM_CYICONSPACING );
928         }
929         else
930         {
931             char buf[10];
932
933             if (uiParam < 32) uiParam = 32;
934
935             sprintf(buf, "%u", uiParam);
936             if (SYSPARAMS_Save( SPI_ICONVERTICALSPACING_REGKEY,
937                                 SPI_ICONVERTICALSPACING_VALNAME,
938                                 buf, fWinIni ))
939             {
940                 SYSMETRICS_Set( SM_CYICONSPACING, uiParam );
941                 spi_loaded[spi_idx] = TRUE;
942             }
943             else
944                 ret = FALSE;
945         }
946
947         break;
948
949     case SPI_GETICONTITLEWRAP:                  /*     25 */
950         spi_idx = SPI_SETICONTITLEWRAP_IDX;
951         if (!spi_loaded[spi_idx])
952         {
953             char buf[5];
954
955             if (SYSPARAMS_Load( SPI_SETICONTITLEWRAP_REGKEY1,
956                                 SPI_SETICONTITLEWRAP_VALNAME, buf ))
957                 icon_title_wrap  = atoi(buf);
958             spi_loaded[spi_idx] = TRUE;
959         }
960
961         *(BOOL *)pvParam = icon_title_wrap;
962         break;
963
964     case SPI_SETICONTITLEWRAP:                  /*     26 */
965     {
966         char buf[5];
967
968         spi_idx = SPI_SETICONTITLEWRAP_IDX;
969         sprintf(buf, "%u", uiParam);
970         if (SYSPARAMS_Save( SPI_SETICONTITLEWRAP_REGKEY1,
971                             SPI_SETICONTITLEWRAP_VALNAME,
972                             buf, fWinIni ))
973         {
974             SYSPARAMS_Save( SPI_SETICONTITLEWRAP_REGKEY2,
975                             SPI_SETICONTITLEWRAP_VALNAME,
976                             buf, fWinIni );
977             icon_title_wrap = uiParam;
978             spi_loaded[spi_idx] = TRUE;
979         }
980         else
981             ret = FALSE;
982         break;
983     }
984
985     case SPI_GETMENUDROPALIGNMENT:              /*     27 */
986         spi_idx = SPI_SETMENUDROPALIGNMENT_IDX;
987
988         if (!spi_loaded[spi_idx])
989         {
990             char buf[5];
991
992             if (SYSPARAMS_Load( SPI_SETMENUDROPALIGNMENT_REGKEY1,
993                                 SPI_SETMENUDROPALIGNMENT_VALNAME, buf ))
994             {
995                 SYSMETRICS_Set( SM_MENUDROPALIGNMENT, atoi( buf ) );
996             }
997             spi_loaded[spi_idx] = TRUE;
998         }
999
1000
1001         *(BOOL *)pvParam = GetSystemMetrics( SM_MENUDROPALIGNMENT );
1002         break;
1003
1004     case SPI_SETMENUDROPALIGNMENT:              /*     28 */
1005     {
1006         char buf[5];
1007         spi_idx = SPI_SETMENUDROPALIGNMENT_IDX;
1008
1009         sprintf(buf, "%u", uiParam);
1010         if (SYSPARAMS_Save( SPI_SETMENUDROPALIGNMENT_REGKEY1,
1011                             SPI_SETMENUDROPALIGNMENT_VALNAME,
1012                             buf, fWinIni ))
1013         {
1014             SYSPARAMS_Save( SPI_SETMENUDROPALIGNMENT_REGKEY2,
1015                             SPI_SETMENUDROPALIGNMENT_VALNAME,
1016                             buf, fWinIni );
1017             SYSMETRICS_Set( SM_MENUDROPALIGNMENT, uiParam );
1018             spi_loaded[spi_idx] = TRUE;
1019         }
1020         else
1021             ret = FALSE;
1022         break;
1023     }
1024
1025     case SPI_SETDOUBLECLKWIDTH:                 /*     29 */
1026     {
1027         char buf[10];
1028         spi_idx = SPI_SETDOUBLECLKWIDTH_IDX;
1029
1030         sprintf(buf, "%u", uiParam);
1031         if (SYSPARAMS_Save( SPI_SETDOUBLECLKWIDTH_REGKEY1,
1032                             SPI_SETDOUBLECLKWIDTH_VALNAME,
1033                             buf, fWinIni ))
1034         {
1035             SYSPARAMS_Save( SPI_SETDOUBLECLKWIDTH_REGKEY2,
1036                             SPI_SETDOUBLECLKWIDTH_VALNAME,
1037                             buf, fWinIni );
1038             SYSMETRICS_Set( SM_CXDOUBLECLK, uiParam );
1039             spi_loaded[spi_idx] = TRUE;
1040         }
1041         else
1042             ret = FALSE;
1043         break;
1044     }
1045
1046     case SPI_SETDOUBLECLKHEIGHT:                /*     30 */
1047     {
1048         char buf[10];
1049         spi_idx = SPI_SETDOUBLECLKHEIGHT_IDX;
1050
1051         sprintf(buf, "%u", uiParam);
1052         if (SYSPARAMS_Save( SPI_SETDOUBLECLKHEIGHT_REGKEY1,
1053                             SPI_SETDOUBLECLKHEIGHT_VALNAME,
1054                             buf, fWinIni ))
1055         {
1056             SYSPARAMS_Save( SPI_SETDOUBLECLKHEIGHT_REGKEY2,
1057                             SPI_SETDOUBLECLKHEIGHT_VALNAME,
1058                             buf, fWinIni );
1059             SYSMETRICS_Set( SM_CYDOUBLECLK, uiParam );
1060             spi_loaded[spi_idx] = TRUE;
1061         }
1062         else
1063             ret = FALSE;
1064         break;
1065     }
1066
1067     case SPI_GETICONTITLELOGFONT:               /*     31 */
1068     {
1069         LPLOGFONTA lpLogFont = (LPLOGFONTA)pvParam;
1070         LOGFONTA        lfDefault;
1071
1072         /*
1073          * The 'default GDI fonts' seems to be returned.
1074          * If a returned font is not a correct font in your environment,
1075          * please try to fix objects/gdiobj.c at first.
1076          */
1077         SYSPARAMS_GetGUIFont( &lfDefault );
1078
1079         GetProfileStringA( "Desktop", "IconTitleFaceName",
1080                            lfDefault.lfFaceName,
1081                            lpLogFont->lfFaceName, LF_FACESIZE );
1082         lpLogFont->lfHeight = -GetProfileIntA( "Desktop", "IconTitleSize", 11 );
1083         lpLogFont->lfWidth = 0;
1084         lpLogFont->lfEscapement = lpLogFont->lfOrientation = 0;
1085         lpLogFont->lfWeight = FW_NORMAL;
1086         lpLogFont->lfItalic = FALSE;
1087         lpLogFont->lfStrikeOut = FALSE;
1088         lpLogFont->lfUnderline = FALSE;
1089         lpLogFont->lfCharSet = lfDefault.lfCharSet; /* at least 'charset' should not be hard-coded */
1090         lpLogFont->lfOutPrecision = OUT_DEFAULT_PRECIS;
1091         lpLogFont->lfClipPrecision = CLIP_DEFAULT_PRECIS;
1092         lpLogFont->lfPitchAndFamily = DEFAULT_PITCH;
1093         break;
1094     }
1095
1096     case SPI_SETDOUBLECLICKTIME:                /*     32 */
1097     {
1098         char buf[10];
1099
1100         spi_idx = SPI_SETDOUBLECLICKTIME_IDX;
1101         sprintf(buf, "%u", uiParam);
1102
1103         if (SYSPARAMS_Save( SPI_SETDOUBLECLICKTIME_REGKEY,
1104                             SPI_SETDOUBLECLICKTIME_VALNAME,
1105                             buf, fWinIni ))
1106         {
1107             if (!uiParam)
1108                 uiParam = 500;
1109             double_click_time = uiParam;
1110             spi_loaded[spi_idx] = TRUE;
1111         }
1112         else
1113             ret = FALSE;
1114         break;
1115     }
1116
1117     case SPI_SETMOUSEBUTTONSWAP:                /*     33 */
1118     {
1119         char buf[5];
1120         spi_idx = SPI_SETMOUSEBUTTONSWAP_IDX;
1121
1122         sprintf(buf, "%u", uiParam);
1123         if (SYSPARAMS_Save( SPI_SETMOUSEBUTTONSWAP_REGKEY,
1124                             SPI_SETMOUSEBUTTONSWAP_VALNAME,
1125                             buf, fWinIni ))
1126         {
1127             SYSMETRICS_Set( SM_SWAPBUTTON, uiParam );
1128             spi_loaded[spi_idx] = TRUE;
1129         }
1130         else
1131             ret = FALSE;
1132         break;
1133     }
1134
1135     WINE_SPI_FIXME(SPI_SETICONTITLELOGFONT);    /*     34 */
1136
1137     case SPI_GETFASTTASKSWITCH:                 /*     35 */
1138         *(BOOL *)pvParam = 1;
1139         break;
1140
1141     case SPI_SETFASTTASKSWITCH:                 /*     36 */
1142         /* the action is disabled */
1143         ret = FALSE;
1144         break;
1145
1146     case SPI_SETDRAGFULLWINDOWS:                /*     37  WINVER >= 0x0400 */
1147     {
1148         char buf[5];
1149
1150         spi_idx = SPI_SETDRAGFULLWINDOWS_IDX;
1151         sprintf(buf, "%u", uiParam);
1152         if (SYSPARAMS_Save( SPI_SETDRAGFULLWINDOWS_REGKEY,
1153                             SPI_SETDRAGFULLWINDOWS_VALNAME,
1154                             buf, fWinIni ))
1155         {
1156             drag_full_windows = uiParam;
1157             spi_loaded[spi_idx] = TRUE;
1158         }
1159         else
1160             ret = FALSE;
1161         break;
1162     }
1163
1164     case SPI_GETDRAGFULLWINDOWS:                /*     38  WINVER >= 0x0400 */
1165         spi_idx = SPI_SETDRAGFULLWINDOWS_IDX;
1166         if (!spi_loaded[spi_idx])
1167         {
1168             char buf[5];
1169
1170             if (SYSPARAMS_Load( SPI_SETDRAGFULLWINDOWS_REGKEY,
1171                                 SPI_SETDRAGFULLWINDOWS_VALNAME, buf ))
1172                 drag_full_windows  = atoi(buf);
1173             spi_loaded[spi_idx] = TRUE;
1174         }
1175
1176         *(BOOL *)pvParam = drag_full_windows;
1177         break;
1178
1179     case SPI_GETNONCLIENTMETRICS:               /*     41  WINVER >= 0x400 */
1180     {
1181         LPNONCLIENTMETRICSA lpnm = (LPNONCLIENTMETRICSA)pvParam;
1182
1183         if (lpnm->cbSize == sizeof(NONCLIENTMETRICSA))
1184         {
1185             /* clear the struct, so we have 'sane' members */
1186             memset(
1187                 (char *)pvParam + sizeof(lpnm->cbSize),
1188                 0,
1189                 lpnm->cbSize - sizeof(lpnm->cbSize)
1190                 );
1191
1192             /* initialize geometry entries */
1193             lpnm->iBorderWidth = 1;
1194             lpnm->iScrollWidth = GetSystemMetrics(SM_CXVSCROLL);
1195             lpnm->iScrollHeight = GetSystemMetrics(SM_CYHSCROLL);
1196
1197             /* size of the normal caption buttons */
1198             lpnm->iCaptionWidth = GetSystemMetrics(SM_CXSIZE);
1199             lpnm->iCaptionHeight = GetSystemMetrics(SM_CYSIZE);
1200
1201             /* caption font metrics */
1202             SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, (LPVOID)&(lpnm->lfCaptionFont), 0 );
1203             lpnm->lfCaptionFont.lfWeight = FW_BOLD;
1204
1205             /* size of the small caption buttons */
1206             lpnm->iSmCaptionWidth = GetSystemMetrics(SM_CXSMSIZE);
1207             lpnm->iSmCaptionHeight = GetSystemMetrics(SM_CYSMSIZE);
1208
1209             /* small caption font metrics */
1210             SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, (LPVOID)&(lpnm->lfSmCaptionFont), 0 );
1211
1212             /* menus, FIXME: names of wine.conf entries are bogus */
1213
1214             /* size of the menu (MDI) buttons */
1215             lpnm->iMenuWidth = GetSystemMetrics(SM_CXMENUSIZE);
1216             lpnm->iMenuHeight = GetSystemMetrics(SM_CYMENUSIZE);
1217
1218             /* menu font metrics */
1219             SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, (LPVOID)&(lpnm->lfMenuFont), 0 );
1220             GetProfileStringA( "Desktop", "MenuFont",
1221                                (TWEAK_WineLook > WIN31_LOOK) ? lpnm->lfCaptionFont.lfFaceName : "System",
1222                                lpnm->lfMenuFont.lfFaceName, LF_FACESIZE );
1223             lpnm->lfMenuFont.lfHeight = -GetProfileIntA( "Desktop", "MenuFontSize", 11 );
1224             lpnm->lfMenuFont.lfWeight = (TWEAK_WineLook > WIN31_LOOK) ? FW_NORMAL : FW_BOLD;
1225
1226             /* status bar font metrics */
1227             SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0,
1228                                    (LPVOID)&(lpnm->lfStatusFont), 0 );
1229             /* message font metrics */
1230             SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0,
1231                                    (LPVOID)&(lpnm->lfMessageFont), 0 );
1232         }
1233         else
1234         {
1235             WARN("size mismatch !! (is %d; should be %d)\n", lpnm->cbSize, sizeof(NONCLIENTMETRICSA));
1236             /* FIXME: SetLastError? */
1237             ret = FALSE;
1238         }
1239         break;
1240     }
1241     WINE_SPI_FIXME(SPI_SETNONCLIENTMETRICS);    /*     42  WINVER >= 0x400 */
1242
1243     case SPI_GETMINIMIZEDMETRICS:               /*     43  WINVER >= 0x400 */
1244     {
1245         MINIMIZEDMETRICS * lpMm = pvParam;
1246         if (lpMm->cbSize == sizeof(*lpMm))
1247         {
1248             /* these taken from Win2k SP3 */
1249             lpMm->iWidth = 154;
1250             lpMm->iHorzGap = 0;
1251             lpMm->iVertGap = 0;
1252             lpMm->iArrange = 8;
1253         }
1254         else
1255             ret = FALSE;
1256         break;
1257     }
1258     WINE_SPI_FIXME(SPI_SETMINIMIZEDMETRICS);    /*     44  WINVER >= 0x400 */
1259
1260     case SPI_GETICONMETRICS:                    /*     45  WINVER >= 0x400 */
1261     {
1262         LPICONMETRICSA lpIcon = pvParam;
1263         if(lpIcon && lpIcon->cbSize == sizeof(*lpIcon))
1264         {
1265             SystemParametersInfoA( SPI_ICONHORIZONTALSPACING, 0,
1266                                    &lpIcon->iHorzSpacing, FALSE );
1267             SystemParametersInfoA( SPI_ICONVERTICALSPACING, 0,
1268                                    &lpIcon->iVertSpacing, FALSE );
1269             SystemParametersInfoA( SPI_GETICONTITLEWRAP, 0,
1270                                    &lpIcon->iTitleWrap, FALSE );
1271             SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0,
1272                                    &lpIcon->lfFont, FALSE );
1273         }
1274         else
1275         {
1276             ret = FALSE;
1277         }
1278         break;
1279     }
1280     WINE_SPI_FIXME(SPI_SETICONMETRICS);         /*     46  WINVER >= 0x400 */
1281
1282     case SPI_SETWORKAREA:                       /*     47  WINVER >= 0x400 */
1283     {
1284         char buf[20];
1285         RECT *pr = (RECT *) pvParam;
1286
1287         spi_idx = SPI_SETWORKAREA_IDX;
1288         sprintf(buf, "%ld %ld %ld %ld",
1289                 pr->left, pr->top,
1290                 pr->right, pr->bottom );
1291
1292         if (SYSPARAMS_Save( SPI_SETWORKAREA_REGKEY,
1293                             SPI_SETWORKAREA_VALNAME,
1294                             buf, fWinIni ))
1295         {
1296             CopyRect( &work_area, (RECT *)pvParam );
1297             spi_loaded[spi_idx] = TRUE;
1298         }
1299         else
1300             ret = FALSE;
1301         break;
1302     }
1303
1304     case SPI_GETWORKAREA:                       /*     48  WINVER >= 0x400 */
1305       spi_idx = SPI_SETWORKAREA_IDX;
1306       if (!spi_loaded[spi_idx])
1307       {
1308           char buf[20];
1309
1310           SetRect( &work_area, 0, 0,
1311                    GetSystemMetrics( SM_CXSCREEN ),
1312                    GetSystemMetrics( SM_CYSCREEN ) );
1313
1314           if (SYSPARAMS_Load( SPI_SETWORKAREA_REGKEY,
1315                               SPI_SETWORKAREA_VALNAME,
1316                               buf ))
1317           {
1318               sscanf( buf, "%ld %ld %ld %ld",
1319                       &work_area.left, &work_area.top,
1320                       &work_area.right, &work_area.bottom );
1321           }
1322           spi_loaded[spi_idx] = TRUE;
1323       }
1324       CopyRect( (RECT *)pvParam, &work_area );
1325
1326       break;
1327
1328     WINE_SPI_FIXME(SPI_SETPENWINDOWS);          /*     49  WINVER >= 0x400 */
1329
1330     case SPI_GETFILTERKEYS:                     /*     50 */
1331     {
1332         LPFILTERKEYS lpFilterKeys = (LPFILTERKEYS)pvParam;
1333         WARN("SPI_GETFILTERKEYS not fully implemented\n");
1334         if (lpFilterKeys->cbSize == sizeof(FILTERKEYS))
1335         {
1336             /* Indicate that no FilterKeys feature available */
1337             lpFilterKeys->dwFlags = 0;
1338             lpFilterKeys->iWaitMSec = 0;
1339             lpFilterKeys->iDelayMSec = 0;
1340             lpFilterKeys->iRepeatMSec = 0;
1341             lpFilterKeys->iBounceMSec = 0;
1342          }
1343         else
1344         {
1345             ret = FALSE;
1346         }
1347         break;
1348     }
1349     WINE_SPI_FIXME(SPI_SETFILTERKEYS);          /*     51 */
1350
1351     case SPI_GETTOGGLEKEYS:                     /*     52 */
1352     {
1353         LPTOGGLEKEYS lpToggleKeys = (LPTOGGLEKEYS)pvParam;
1354         WARN("SPI_GETTOGGLEKEYS not fully implemented\n");
1355         if (lpToggleKeys->cbSize == sizeof(TOGGLEKEYS))
1356         {
1357             /* Indicate that no ToggleKeys feature available */
1358             lpToggleKeys->dwFlags = 0;
1359         }
1360         else
1361         {
1362             ret = FALSE;
1363         }
1364         break;
1365     }
1366     WINE_SPI_FIXME(SPI_SETTOGGLEKEYS);          /*     53 */
1367
1368     case SPI_GETMOUSEKEYS:                      /*     54 */
1369     {
1370         LPMOUSEKEYS lpMouseKeys = (LPMOUSEKEYS)pvParam;
1371         WARN("SPI_GETMOUSEKEYS not fully implemented\n");
1372         if (lpMouseKeys->cbSize == sizeof(MOUSEKEYS))
1373         {
1374             /* Indicate that no MouseKeys feature available */
1375             lpMouseKeys->dwFlags = 0;
1376             lpMouseKeys->iMaxSpeed = 360;
1377             lpMouseKeys->iTimeToMaxSpeed = 1000;
1378             lpMouseKeys->iCtrlSpeed = 0;
1379             lpMouseKeys->dwReserved1 = 0;
1380             lpMouseKeys->dwReserved2 = 0;
1381         }
1382         else
1383         {
1384             ret = FALSE;
1385         }
1386         break;
1387     }
1388     WINE_SPI_FIXME(SPI_SETMOUSEKEYS);           /*     55 */
1389
1390     case SPI_GETSHOWSOUNDS:                     /*     56 */
1391         spi_idx = SPI_SETSHOWSOUNDS_IDX;
1392
1393         if (!spi_loaded[spi_idx])
1394         {
1395             char buf[10];
1396
1397             if (SYSPARAMS_Load( SPI_SETSHOWSOUNDS_REGKEY,
1398                                 SPI_SETSHOWSOUNDS_VALNAME, buf ))
1399             {
1400                 SYSMETRICS_Set( SM_SHOWSOUNDS, atoi( buf ) );
1401             }
1402             spi_loaded[spi_idx] = TRUE;
1403         }
1404
1405
1406         *(INT *)pvParam = GetSystemMetrics( SM_SHOWSOUNDS );
1407         break;
1408
1409     case SPI_SETSHOWSOUNDS:                     /*     57 */
1410     {
1411         char buf[10];
1412         spi_idx = SPI_SETSHOWSOUNDS_IDX;
1413
1414         sprintf(buf, "%u", uiParam);
1415         if (SYSPARAMS_Save( SPI_SETSHOWSOUNDS_REGKEY,
1416                             SPI_SETSHOWSOUNDS_VALNAME,
1417                             buf, fWinIni ))
1418         {
1419             SYSMETRICS_Set( SM_SHOWSOUNDS, uiParam );
1420             spi_loaded[spi_idx] = TRUE;
1421         }
1422         else
1423             ret = FALSE;
1424         break;
1425     }
1426
1427     case SPI_GETSTICKYKEYS:                     /*     58 */
1428     {
1429         LPSTICKYKEYS lpStickyKeys = (LPSTICKYKEYS)pvParam;
1430         WARN("SPI_GETSTICKYKEYS not fully implemented\n");
1431         if (lpStickyKeys->cbSize == sizeof(STICKYKEYS))
1432         {
1433             /* Indicate that no StickyKeys feature available */
1434             lpStickyKeys->dwFlags = 0;
1435         }
1436         else
1437         {
1438             ret = FALSE;
1439         }
1440         break;
1441     }
1442     WINE_SPI_FIXME(SPI_SETSTICKYKEYS);          /*     59 */
1443
1444     case SPI_GETACCESSTIMEOUT:                  /*     60 */
1445     {
1446         LPACCESSTIMEOUT lpAccessTimeout = (LPACCESSTIMEOUT)pvParam;
1447         WARN("SPI_GETACCESSTIMEOUT not fully implemented\n");
1448         if (lpAccessTimeout->cbSize == sizeof(ACCESSTIMEOUT))
1449         {
1450             /* Indicate that no accessibility features timeout is available */
1451             lpAccessTimeout->dwFlags = 0;
1452             lpAccessTimeout->iTimeOutMSec = 0;
1453         }
1454         else
1455         {
1456             ret = FALSE;
1457         }
1458         break;
1459     }
1460     WINE_SPI_FIXME(SPI_SETACCESSTIMEOUT);       /*     61 */
1461
1462     case SPI_GETSERIALKEYS:                     /*     62  WINVER >= 0x400 */
1463     {
1464         LPSERIALKEYSA lpSerialKeysA = (LPSERIALKEYSA)pvParam;
1465         WARN("SPI_GETSERIALKEYS not fully implemented\n");
1466         if (lpSerialKeysA->cbSize == sizeof(SERIALKEYSA))
1467         {
1468             /* Indicate that no SerialKeys feature available */
1469             lpSerialKeysA->dwFlags = 0;
1470             lpSerialKeysA->lpszActivePort = NULL;
1471             lpSerialKeysA->lpszPort = NULL;
1472             lpSerialKeysA->iBaudRate = 0;
1473             lpSerialKeysA->iPortState = 0;
1474         }
1475         else
1476         {
1477             ret = FALSE;
1478         }
1479         break;
1480     }
1481     WINE_SPI_FIXME(SPI_SETSERIALKEYS);          /*     63  WINVER >= 0x400 */
1482
1483     case SPI_GETSOUNDSENTRY:                    /*     64 */
1484     {
1485         LPSOUNDSENTRYA lpSoundSentryA = (LPSOUNDSENTRYA)pvParam;
1486         WARN("SPI_GETSOUNDSENTRY not fully implemented\n");
1487         if (lpSoundSentryA->cbSize == sizeof(SOUNDSENTRYA))
1488         {
1489             /* Indicate that no SoundSentry feature available */
1490             lpSoundSentryA->dwFlags = 0;
1491             lpSoundSentryA->iFSTextEffect = 0;
1492             lpSoundSentryA->iFSTextEffectMSec = 0;
1493             lpSoundSentryA->iFSTextEffectColorBits = 0;
1494             lpSoundSentryA->iFSGrafEffect = 0;
1495             lpSoundSentryA->iFSGrafEffectMSec = 0;
1496             lpSoundSentryA->iFSGrafEffectColor = 0;
1497             lpSoundSentryA->iWindowsEffect = 0;
1498             lpSoundSentryA->iWindowsEffectMSec = 0;
1499             lpSoundSentryA->lpszWindowsEffectDLL = 0;
1500             lpSoundSentryA->iWindowsEffectOrdinal = 0;
1501         }
1502         else
1503         {
1504             ret = FALSE;
1505         }
1506         break;
1507     }
1508     WINE_SPI_FIXME(SPI_SETSOUNDSENTRY);         /*     65 */
1509
1510     case SPI_GETHIGHCONTRAST:                   /*     66  WINVER >= 0x400 */
1511     {
1512         LPHIGHCONTRASTA lpHighContrastA = (LPHIGHCONTRASTA)pvParam;
1513         WARN("SPI_GETHIGHCONTRAST not fully implemented\n");
1514         if (lpHighContrastA->cbSize == sizeof(HIGHCONTRASTA))
1515         {
1516             /* Indicate that no high contrast feature available */
1517             lpHighContrastA->dwFlags = 0;
1518             lpHighContrastA->lpszDefaultScheme = NULL;
1519         }
1520         else
1521         {
1522             ret = FALSE;
1523         }
1524         break;
1525     }
1526     WINE_SPI_FIXME(SPI_SETHIGHCONTRAST);        /*     67  WINVER >= 0x400 */
1527
1528     case SPI_GETKEYBOARDPREF:                   /*     68  WINVER >= 0x400 */
1529         spi_idx = SPI_SETKEYBOARDPREF_IDX;
1530         if (!spi_loaded[spi_idx])
1531         {
1532             char buf[5];
1533
1534             if (SYSPARAMS_Load( SPI_SETKEYBOARDPREF_REGKEY,
1535                                 SPI_SETKEYBOARDPREF_VALNAME, buf ))
1536                 keyboard_pref  = atoi(buf);
1537             spi_loaded[spi_idx] = TRUE;
1538         }
1539
1540         *(BOOL *)pvParam = keyboard_pref;
1541         break;
1542
1543     case SPI_SETKEYBOARDPREF:                   /*     69  WINVER >= 0x400 */
1544     {
1545         char buf[5];
1546
1547         spi_idx = SPI_SETKEYBOARDPREF_IDX;
1548         sprintf(buf, "%u", uiParam);
1549         if (SYSPARAMS_Save( SPI_SETKEYBOARDPREF_REGKEY,
1550                             SPI_SETKEYBOARDPREF_VALNAME,
1551                             buf, fWinIni ))
1552         {
1553             keyboard_pref = uiParam;
1554             spi_loaded[spi_idx] = TRUE;
1555         }
1556         else
1557             ret = FALSE;
1558         break;
1559     }
1560
1561     case SPI_GETSCREENREADER:                   /*     70  WINVER >= 0x400 */
1562         spi_idx = SPI_SETSCREENREADER_IDX;
1563         if (!spi_loaded[spi_idx])
1564         {
1565             char buf[5];
1566
1567             if (SYSPARAMS_Load( SPI_SETSCREENREADER_REGKEY,
1568                                 SPI_SETSCREENREADER_VALNAME, buf ))
1569                 screen_reader  = atoi(buf);
1570             spi_loaded[spi_idx] = TRUE;
1571         }
1572
1573         *(BOOL *)pvParam = screen_reader;
1574         break;
1575
1576     case SPI_SETSCREENREADER:                   /*     71  WINVER >= 0x400 */
1577     {
1578         char buf[5];
1579
1580         spi_idx = SPI_SETSCREENREADER_IDX;
1581         sprintf(buf, "%u", uiParam);
1582         if (SYSPARAMS_Save( SPI_SETSCREENREADER_REGKEY,
1583                             SPI_SETSCREENREADER_VALNAME,
1584                             buf, fWinIni ))
1585         {
1586             screen_reader = uiParam;
1587             spi_loaded[spi_idx] = TRUE;
1588         }
1589         else
1590             ret = FALSE;
1591         break;
1592     }
1593
1594     case SPI_GETANIMATION:                      /*     72  WINVER >= 0x400 */
1595     {
1596         LPANIMATIONINFO lpAnimInfo = (LPANIMATIONINFO)pvParam;
1597
1598         /* Tell it "disabled" */
1599         if (lpAnimInfo->cbSize == sizeof(ANIMATIONINFO))
1600             lpAnimInfo->iMinAnimate = 0; /* Minimise and restore animation is disabled (nonzero == enabled) */
1601         else
1602             ret = FALSE;
1603         break;
1604     }
1605     WINE_SPI_WARN(SPI_SETANIMATION);            /*     73  WINVER >= 0x400 */
1606
1607     WINE_SPI_FIXME(SPI_GETFONTSMOOTHING);       /*     74  WINVER >= 0x400 */
1608     WINE_SPI_FIXME(SPI_SETFONTSMOOTHING);       /*     75  WINVER >= 0x400 */
1609
1610     WINE_SPI_FIXME(SPI_SETDRAGWIDTH);           /*     76  WINVER >= 0x400 */
1611     WINE_SPI_FIXME(SPI_SETDRAGHEIGHT);          /*     77  WINVER >= 0x400 */
1612
1613     WINE_SPI_FIXME(SPI_SETHANDHELD);            /*     78  WINVER >= 0x400 */
1614
1615     WINE_SPI_FIXME(SPI_GETLOWPOWERTIMEOUT);     /*     79  WINVER >= 0x400 */
1616     WINE_SPI_FIXME(SPI_GETPOWEROFFTIMEOUT);     /*     80  WINVER >= 0x400 */
1617     WINE_SPI_FIXME(SPI_SETLOWPOWERTIMEOUT);     /*     81  WINVER >= 0x400 */
1618     WINE_SPI_FIXME(SPI_SETPOWEROFFTIMEOUT);     /*     82  WINVER >= 0x400 */
1619     WINE_SPI_FIXME(SPI_GETLOWPOWERACTIVE);      /*     83  WINVER >= 0x400 */
1620     WINE_SPI_FIXME(SPI_GETPOWEROFFACTIVE);      /*     84  WINVER >= 0x400 */
1621     WINE_SPI_FIXME(SPI_SETLOWPOWERACTIVE);      /*     85  WINVER >= 0x400 */
1622     WINE_SPI_FIXME(SPI_SETPOWEROFFACTIVE);      /*     86  WINVER >= 0x400 */
1623
1624     WINE_SPI_FIXME(SPI_SETCURSORS);             /*     87  WINVER >= 0x400 */
1625     WINE_SPI_FIXME(SPI_SETICONS);               /*     88  WINVER >= 0x400 */
1626
1627     case SPI_GETDEFAULTINPUTLANG:       /*     89  WINVER >= 0x400 */
1628         ret = GetKeyboardLayout(0) ? TRUE : FALSE;
1629         break;
1630
1631     WINE_SPI_FIXME(SPI_SETDEFAULTINPUTLANG);    /*     90  WINVER >= 0x400 */
1632
1633     WINE_SPI_FIXME(SPI_SETLANGTOGGLE);          /*     91  WINVER >= 0x400 */
1634
1635     case SPI_GETWINDOWSEXTENSION:               /*     92  WINVER >= 0x400 */
1636         WARN("pretend no support for Win9x Plus! for now.\n");
1637         ret = FALSE; /* yes, this is the result value */
1638         break;
1639
1640     WINE_SPI_FIXME(SPI_SETMOUSETRAILS);         /*     93  WINVER >= 0x400 */
1641     WINE_SPI_FIXME(SPI_GETMOUSETRAILS);         /*     94  WINVER >= 0x400 */
1642
1643     case SPI_SETSCREENSAVERRUNNING:             /*     97  WINVER >= 0x400 */
1644         {
1645         /* SPI_SCREENSAVERRUNNING is an alias for SPI_SETSCREENSAVERRUNNING */
1646         char buf[5];
1647
1648         spi_idx = SPI_SETSCREENSAVERRUNNING_IDX;
1649         sprintf(buf, "%u", uiParam);
1650
1651         /* save only temporarily */
1652         if (SYSPARAMS_Save( SPI_SETSCREENSAVERRUNNING_REGKEY,
1653                             SPI_SETSCREENSAVERRUNNING_VALNAME,
1654                             buf, 0 ))
1655         {
1656             screensaver_running = uiParam;
1657             spi_loaded[spi_idx] = TRUE;
1658         }
1659         else
1660             ret = FALSE;
1661         break;
1662     }
1663
1664     case SPI_GETMOUSEHOVERWIDTH:                /*     98  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
1665         *(UINT *)pvParam = 4;
1666         break;
1667     WINE_SPI_FIXME(SPI_SETMOUSEHOVERWIDTH);     /*     99  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
1668
1669     case SPI_GETMOUSEHOVERHEIGHT:               /*    100  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
1670         *(UINT *)pvParam = 4;
1671         break;
1672     WINE_SPI_FIXME(SPI_SETMOUSEHOVERHEIGHT);    /*    101  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
1673
1674     case SPI_GETMOUSEHOVERTIME:                 /*    102  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
1675         *(UINT *)pvParam = 400; /* default for menu dropdowns */
1676         break;
1677     WINE_SPI_FIXME(SPI_SETMOUSEHOVERTIME);      /*    103  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
1678
1679     case SPI_GETWHEELSCROLLLINES:               /*    104  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
1680         *(UINT *)pvParam = 3; /* default for num scroll lines */
1681         break;
1682
1683     WINE_SPI_FIXME(SPI_SETWHEELSCROLLLINES);    /*    105  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
1684
1685     case SPI_GETMENUSHOWDELAY:                  /*    106  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
1686         *(UINT *)pvParam = 400; /* Tested against Windows NT 4.0 and Windows 2000 */
1687         break;
1688
1689     WINE_SPI_FIXME(SPI_GETSHOWIMEUI);           /*    110  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
1690     WINE_SPI_FIXME(SPI_SETSHOWIMEUI);           /*    111  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
1691
1692     case SPI_GETSCREENSAVERRUNNING:             /*    114  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1693         spi_idx = SPI_SETSCREENSAVERRUNNING_IDX;
1694         if (!spi_loaded[spi_idx])
1695         {
1696             char buf[5];
1697
1698             if (SYSPARAMS_Load( SPI_SETSCREENSAVERRUNNING_REGKEY,
1699                                 SPI_SETSCREENSAVERRUNNING_VALNAME, buf ))
1700                 screensaver_running  = atoi( buf );
1701             spi_loaded[spi_idx] = TRUE;
1702         }
1703
1704         *(BOOL *)pvParam = screensaver_running;
1705         break;
1706
1707     case SPI_GETDESKWALLPAPER:                  /*    115  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1708     {
1709         char buf[MAX_PATH];
1710
1711         if (uiParam > MAX_PATH)
1712         {
1713             uiParam = MAX_PATH;
1714         }
1715
1716         if (SYSPARAMS_Load(SPI_SETDESKWALLPAPER_REGKEY, SPI_SETDESKWALLPAPER_VALNAME, buf))
1717         {
1718             strncpy((char*)pvParam, buf, uiParam);
1719         }
1720         else
1721         {
1722             /* Return an empty string */
1723             memset((char*)pvParam, 0, uiParam);
1724         }
1725
1726         break;
1727     }
1728
1729     WINE_SPI_FIXME(SPI_GETACTIVEWINDOWTRACKING);/* 0x1000  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1730     WINE_SPI_FIXME(SPI_SETACTIVEWINDOWTRACKING);/* 0x1001  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1731     WINE_SPI_FIXME(SPI_GETMENUANIMATION);       /* 0x1002  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1732     WINE_SPI_FIXME(SPI_SETMENUANIMATION);       /* 0x1003  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1733     WINE_SPI_FIXME(SPI_GETCOMBOBOXANIMATION);   /* 0x1004  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1734     WINE_SPI_FIXME(SPI_SETCOMBOBOXANIMATION);   /* 0x1005  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1735     WINE_SPI_FIXME(SPI_GETLISTBOXSMOOTHSCROLLING);/* 0x1006  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1736     WINE_SPI_FIXME(SPI_SETLISTBOXSMOOTHSCROLLING);/* 0x1007  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1737
1738     case SPI_GETGRADIENTCAPTIONS:    /* 0x1008  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1739         FIXME("case SPI_GETGRADIENTCAPTIONS always return false\n");
1740         *(BOOL *)pvParam = FALSE;
1741         break;
1742
1743     WINE_SPI_FIXME(SPI_SETGRADIENTCAPTIONS);    /* 0x1009  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1744     WINE_SPI_FIXME(SPI_GETKEYBOARDCUES);        /* 0x100A  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1745     WINE_SPI_FIXME(SPI_SETKEYBOARDCUES);        /* 0x100B  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1746     WINE_SPI_FIXME(SPI_GETACTIVEWNDTRKZORDER);  /* 0x100C  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1747     WINE_SPI_FIXME(SPI_SETACTIVEWNDTRKZORDER);  /* 0x100D  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1748     WINE_SPI_FIXME(SPI_GETHOTTRACKING);         /* 0x100E  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1749     WINE_SPI_FIXME(SPI_SETHOTTRACKING);         /* 0x100F  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1750     WINE_SPI_FIXME(SPI_GETSELECTIONFADE);       /* 0x1014  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1751     WINE_SPI_FIXME(SPI_SETSELECTIONFADE);       /* 0x1015  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1752     WINE_SPI_FIXME(SPI_GETDROPSHADOW);          /* 0x1024  _WIN32_WINNT >= 0x510 */
1753     WINE_SPI_FIXME(SPI_SETDROPSHADOW);          /* 0x1025  _WIN32_WINNT >= 0x510 */
1754     WINE_SPI_FIXME(SPI_GETFOREGROUNDLOCKTIMEOUT);/* 0x2000  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1755     WINE_SPI_FIXME(SPI_SETFOREGROUNDLOCKTIMEOUT);/* 0x2001  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1756     WINE_SPI_FIXME(SPI_GETACTIVEWNDTRKTIMEOUT); /* 0x2002  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1757     WINE_SPI_FIXME(SPI_SETACTIVEWNDTRKTIMEOUT); /* 0x2003  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1758     WINE_SPI_FIXME(SPI_GETFOREGROUNDFLASHCOUNT);/* 0x2004  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1759     WINE_SPI_FIXME(SPI_SETFOREGROUNDFLASHCOUNT);/* 0x2005  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
1760
1761     default:
1762         FIXME( "Unknown action: %u\n", uiAction );
1763         SetLastError( ERROR_INVALID_SPI_VALUE );
1764         ret = FALSE;
1765         break;
1766     }
1767
1768     if (ret)
1769         SYSPARAMS_NotifyChange( uiAction, fWinIni );
1770     return ret;
1771
1772 #undef WINE_SPI_FIXME
1773 #undef WINE_SPI_WARN
1774 }
1775
1776
1777 /***********************************************************************
1778  *              SystemParametersInfo (USER.483)
1779  */
1780 BOOL16 WINAPI SystemParametersInfo16( UINT16 uAction, UINT16 uParam,
1781                                       LPVOID lpvParam, UINT16 fuWinIni )
1782 {
1783     BOOL16 ret;
1784
1785     TRACE("(%u, %u, %p, %u)\n", uAction, uParam, lpvParam, fuWinIni);
1786
1787     switch (uAction)
1788     {
1789     case SPI_GETBEEP:                           /*      1 */
1790     case SPI_GETSCREENSAVEACTIVE:               /*     16 */
1791     case SPI_GETICONTITLEWRAP:                  /*     25 */
1792     case SPI_GETMENUDROPALIGNMENT:              /*     27 */
1793     case SPI_GETFASTTASKSWITCH:                 /*     35 */
1794     case SPI_GETDRAGFULLWINDOWS:                /*     38  WINVER >= 0x0400 */
1795     {
1796         BOOL tmp;
1797         ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
1798         if (ret && lpvParam)
1799             *(BOOL16 *)lpvParam = tmp;
1800         break;
1801     }
1802
1803     case SPI_GETBORDER:                         /*      5 */
1804     case SPI_ICONHORIZONTALSPACING:             /*     13 */
1805     case SPI_GETSCREENSAVETIMEOUT:              /*     14 */
1806     case SPI_GETGRIDGRANULARITY:                /*     18 */
1807     case SPI_GETKEYBOARDDELAY:                  /*     22 */
1808     case SPI_ICONVERTICALSPACING:               /*     24 */
1809     {
1810         INT tmp;
1811         ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
1812         if (ret && lpvParam)
1813             *(INT16 *)lpvParam = tmp;
1814         break;
1815     }
1816
1817     case SPI_GETKEYBOARDSPEED:                  /*     10 */
1818     {
1819         DWORD tmp;
1820         ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
1821         if (ret && lpvParam)
1822             *(WORD *)lpvParam = tmp;
1823         break;
1824     }
1825
1826     case SPI_GETICONTITLELOGFONT:               /*     31 */
1827     {
1828         LOGFONTA tmp;
1829         ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
1830         if (ret && lpvParam)
1831             SYSPARAMS_LogFont32ATo16( &tmp, (LPLOGFONT16)lpvParam );
1832         break;
1833     }
1834
1835     case SPI_GETNONCLIENTMETRICS:               /*     41  WINVER >= 0x400 */
1836     {
1837         NONCLIENTMETRICSA tmp;
1838         LPNONCLIENTMETRICS16 lpnm16 = (LPNONCLIENTMETRICS16)lpvParam;
1839         if (lpnm16 && lpnm16->cbSize == sizeof(NONCLIENTMETRICS16))
1840         {
1841             tmp.cbSize = sizeof(NONCLIENTMETRICSA);
1842             ret = SystemParametersInfoA( uAction, uParam, &tmp, fuWinIni );
1843             if (ret)
1844                 SYSPARAMS_NonClientMetrics32ATo16( &tmp, lpnm16 );
1845         }
1846         else /* winfile 95 sets cbSize to 340 */
1847             ret = SystemParametersInfoA( uAction, uParam, lpvParam, fuWinIni );
1848         break;
1849     }
1850
1851     case SPI_GETWORKAREA:                       /*     48  WINVER >= 0x400 */
1852     {
1853         RECT tmp;
1854         ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
1855         if (ret && lpvParam)
1856             CONV_RECT32TO16( &tmp, (RECT16 *)lpvParam );
1857         break;
1858     }
1859
1860     case SPI_GETMOUSEHOVERWIDTH:                /*     98  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
1861     case SPI_GETMOUSEHOVERHEIGHT:               /*    100  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
1862     case SPI_GETMOUSEHOVERTIME:                 /*    102  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
1863     {
1864         UINT tmp;
1865         ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
1866         if (ret && lpvParam)
1867             *(UINT16 *)lpvParam = tmp;
1868         break;
1869     }
1870
1871     default:
1872         ret = SystemParametersInfoA( uAction, uParam, lpvParam, fuWinIni );
1873     }
1874
1875     return ret;
1876 }
1877
1878 /***********************************************************************
1879  *              SystemParametersInfoW (USER32.@)
1880  */
1881 BOOL WINAPI SystemParametersInfoW( UINT uiAction, UINT uiParam,
1882                                    PVOID pvParam, UINT fuWinIni )
1883 {
1884     BOOL ret;
1885
1886     TRACE("(%u, %u, %p, %u)\n", uiAction, uiParam, pvParam, fuWinIni);
1887
1888     switch (uiAction)
1889     {
1890     case SPI_SETDESKWALLPAPER:                  /*     20 */
1891     case SPI_SETDESKPATTERN:                    /*     21 */
1892     {
1893         char buffer[256];
1894         if (pvParam)
1895             if (!WideCharToMultiByte( CP_ACP, 0, (LPWSTR)pvParam, -1,
1896                                       buffer, sizeof(buffer), NULL, NULL ))
1897                 buffer[sizeof(buffer)-1] = 0;
1898         ret = SystemParametersInfoA( uiAction, uiParam, pvParam ? buffer : NULL, fuWinIni );
1899         break;
1900     }
1901
1902     case SPI_GETICONTITLELOGFONT:               /*     31 */
1903     {
1904         LOGFONTA tmp;
1905         ret = SystemParametersInfoA( uiAction, uiParam, pvParam ? &tmp : NULL, fuWinIni );
1906         if (ret && pvParam)
1907             SYSPARAMS_LogFont32ATo32W( &tmp, (LPLOGFONTW)pvParam );
1908         break;
1909     }
1910
1911     case SPI_GETNONCLIENTMETRICS:               /*     41  WINVER >= 0x400 */
1912     {
1913         NONCLIENTMETRICSA tmp;
1914         LPNONCLIENTMETRICSW lpnmW = (LPNONCLIENTMETRICSW)pvParam;
1915         if (lpnmW && lpnmW->cbSize == sizeof(NONCLIENTMETRICSW))
1916         {
1917             tmp.cbSize = sizeof(NONCLIENTMETRICSA);
1918             ret = SystemParametersInfoA( uiAction, uiParam, &tmp, fuWinIni );
1919             if (ret)
1920                 SYSPARAMS_NonClientMetrics32ATo32W( &tmp, lpnmW );
1921         }
1922         else
1923             ret = FALSE;
1924         break;
1925     }
1926
1927     case SPI_GETICONMETRICS:                    /*     45  WINVER >= 0x400 */
1928     {
1929         ICONMETRICSA tmp;
1930         LPICONMETRICSW lpimW = (LPICONMETRICSW)pvParam;
1931         if (lpimW && lpimW->cbSize == sizeof(ICONMETRICSW))
1932         {
1933             tmp.cbSize = sizeof(ICONMETRICSA);
1934             ret = SystemParametersInfoA( uiAction, uiParam, &tmp, fuWinIni );
1935             if (ret)
1936             {
1937                 lpimW->iHorzSpacing = tmp.iHorzSpacing;
1938                 lpimW->iVertSpacing = tmp.iVertSpacing;
1939                 lpimW->iTitleWrap   = tmp.iTitleWrap;
1940                 SYSPARAMS_LogFont32ATo32W( &tmp.lfFont, &lpimW->lfFont );
1941             }
1942         }
1943         else
1944             ret = FALSE;
1945         break;
1946     }
1947
1948     case SPI_GETHIGHCONTRAST:                   /*     66  WINVER >= 0x400 */
1949     {
1950         HIGHCONTRASTA tmp;
1951         LPHIGHCONTRASTW lphcW = (LPHIGHCONTRASTW)pvParam;
1952         if (lphcW && lphcW->cbSize == sizeof(HIGHCONTRASTW))
1953         {
1954             tmp.cbSize = sizeof(HIGHCONTRASTA);
1955             ret = SystemParametersInfoA( uiAction, uiParam, &tmp, fuWinIni );
1956             if (ret)
1957             {
1958                 lphcW->dwFlags = tmp.dwFlags;
1959                 lphcW->lpszDefaultScheme = NULL;  /* FIXME? */
1960             }
1961         }
1962         else
1963             ret = FALSE;
1964         break;
1965     }
1966
1967     default:
1968         ret = SystemParametersInfoA( uiAction, uiParam, pvParam, fuWinIni );
1969         break;
1970     }
1971     return ret;
1972 }
1973
1974
1975 /**********************************************************************
1976  *              SetDoubleClickTime (USER32.@)
1977  */
1978 BOOL WINAPI SetDoubleClickTime( UINT interval )
1979 {
1980     return SystemParametersInfoA(SPI_SETDOUBLECLICKTIME, interval, 0, 0);
1981 }
1982
1983
1984 /**********************************************************************
1985  *              GetDoubleClickTime (USER32.@)
1986  */
1987 UINT WINAPI GetDoubleClickTime(void)
1988 {
1989     char buf[10];
1990
1991     if (!spi_loaded[SPI_SETDOUBLECLICKTIME_IDX])
1992     {
1993         if (SYSPARAMS_Load( SPI_SETDOUBLECLICKTIME_REGKEY,
1994                             SPI_SETDOUBLECLICKTIME_VALNAME,
1995                             buf ))
1996         {
1997             double_click_time = atoi( buf );
1998             if (!double_click_time) double_click_time = 500;
1999         }
2000         spi_loaded[SPI_SETDOUBLECLICKTIME_IDX] = TRUE;
2001     }
2002     return double_click_time;
2003 }