user: Increase the time during which flush_events() waits for pending events.
[wine] / dlls / user / 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "config.h"
22
23 #include <assert.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnls.h"
31 #include "wingdi.h"
32 #include "winreg.h"
33 #include "wine/winuser16.h"
34 #include "winerror.h"
35
36 #include "controls.h"
37 #include "user_private.h"
38 #include "wine/unicode.h"
39 #include "wine/debug.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(system);
42
43 /* System parameter indexes */
44 enum spi_index
45 {
46     SPI_SETBEEP_IDX,
47     SPI_SETMOUSE_IDX,
48     SPI_SETBORDER_IDX,
49     SPI_SETKEYBOARDSPEED_IDX,
50     SPI_ICONHORIZONTALSPACING_IDX,
51     SPI_SETSCREENSAVETIMEOUT_IDX,
52     SPI_SETGRIDGRANULARITY_IDX,
53     SPI_SETKEYBOARDDELAY_IDX,
54     SPI_ICONVERTICALSPACING_IDX,
55     SPI_SETICONTITLEWRAP_IDX,
56     SPI_SETMENUDROPALIGNMENT_IDX,
57     SPI_SETDOUBLECLKWIDTH_IDX,
58     SPI_SETDOUBLECLKHEIGHT_IDX,
59     SPI_SETDOUBLECLICKTIME_IDX,
60     SPI_SETMOUSEBUTTONSWAP_IDX,
61     SPI_SETDRAGFULLWINDOWS_IDX,
62     SPI_SETWORKAREA_IDX,
63     SPI_SETSHOWSOUNDS_IDX,
64     SPI_SETKEYBOARDPREF_IDX,
65     SPI_SETSCREENREADER_IDX,
66     SPI_SETSCREENSAVERRUNNING_IDX,
67     SPI_SETFONTSMOOTHING_IDX,
68     SPI_SETLISTBOXSMOOTHSCROLLING_IDX,
69     SPI_SETMOUSEHOVERWIDTH_IDX,
70     SPI_SETMOUSEHOVERHEIGHT_IDX,
71     SPI_SETMOUSEHOVERTIME_IDX,
72     SPI_SETMOUSESCROLLLINES_IDX,
73     SPI_SETMENUSHOWDELAY_IDX,
74     SPI_SETICONTITLELOGFONT_IDX,
75     SPI_SETLOWPOWERACTIVE_IDX,
76     SPI_SETPOWEROFFACTIVE_IDX,
77     SPI_USERPREFERENCEMASK_IDX,
78     SPI_NONCLIENTMETRICS_IDX,
79     SPI_MINIMIZEDMETRICS_IDX,
80     SPI_CARETWIDTH_IDX,
81     SPI_INDEX_COUNT
82 };
83
84 static const char * const DefSysColors[] =
85 {
86     "Scrollbar", "192 192 192",              /* COLOR_SCROLLBAR */
87     "Background", "0 128 128",               /* COLOR_BACKGROUND */
88     "ActiveTitle", "0 0 128",                /* COLOR_ACTIVECAPTION */
89     "InactiveTitle", "128 128 128",          /* COLOR_INACTIVECAPTION */
90     "Menu", "192 192 192",                   /* COLOR_MENU */
91     "Window", "255 255 255",                 /* COLOR_WINDOW */
92     "WindowFrame", "0 0 0",                  /* COLOR_WINDOWFRAME */
93     "MenuText", "0 0 0",                     /* COLOR_MENUTEXT */
94     "WindowText", "0 0 0",                   /* COLOR_WINDOWTEXT */
95     "TitleText", "255 255 255",              /* COLOR_CAPTIONTEXT */
96     "ActiveBorder", "192 192 192",           /* COLOR_ACTIVEBORDER */
97     "InactiveBorder", "192 192 192",         /* COLOR_INACTIVEBORDER */
98     "AppWorkSpace", "128 128 128",           /* COLOR_APPWORKSPACE */
99     "Hilight", "0 0 128",                    /* COLOR_HIGHLIGHT */
100     "HilightText", "255 255 255",            /* COLOR_HIGHLIGHTTEXT */
101     "ButtonFace", "192 192 192",             /* COLOR_BTNFACE */
102     "ButtonShadow", "128 128 128",           /* COLOR_BTNSHADOW */
103     "GrayText", "128 128 128",               /* COLOR_GRAYTEXT */
104     "ButtonText", "0 0 0",                   /* COLOR_BTNTEXT */
105     "InactiveTitleText", "192 192 192",      /* COLOR_INACTIVECAPTIONTEXT */
106     "ButtonHilight", "255 255 255",          /* COLOR_BTNHIGHLIGHT */
107     "ButtonDkShadow", "0 0 0",               /* COLOR_3DDKSHADOW */
108     "ButtonLight", "224 224 224",            /* COLOR_3DLIGHT */
109     "InfoText", "0 0 0",                     /* COLOR_INFOTEXT */
110     "InfoWindow", "255 255 225",             /* COLOR_INFOBK */
111     "ButtonAlternateFace", "180 180 180",    /* COLOR_ALTERNATEBTNFACE */
112     "HotTrackingColor", "0 0 255",           /* COLOR_HOTLIGHT */
113     "GradientActiveTitle", "16 132 208",     /* COLOR_GRADIENTACTIVECAPTION */
114     "GradientInactiveTitle", "181 181 181",  /* COLOR_GRADIENTINACTIVECAPTION */
115     "MenuHilight", "0 0 0",                  /* COLOR_MENUHILIGHT */
116     "MenuBar", "192 192 192"                 /* COLOR_MENUBAR */
117 };
118
119 /**
120  * Names of the registry subkeys of HKEY_CURRENT_USER key and value names
121  * for the system parameters.
122  * Names of the keys are created by adding string "_REGKEY" to
123  * "SET" action names, value names are created by adding "_REG_NAME"
124  * to the "SET" action name.
125  */
126 static const WCHAR SPI_SETBEEP_REGKEY[]=                      {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','S','o','u','n','d',0};
127 static const WCHAR SPI_SETBEEP_VALNAME[]=                     {'B','e','e','p',0};
128 static const WCHAR SPI_SETMOUSE_REGKEY[]=                     {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
129 static const WCHAR SPI_SETMOUSE_VALNAME1[]=                   {'M','o','u','s','e','T','h','r','e','s','h','o','l','d','1',0};
130 static const WCHAR SPI_SETMOUSE_VALNAME2[]=                   {'M','o','u','s','e','T','h','r','e','s','h','o','l','d','2',0};
131 static const WCHAR SPI_SETMOUSE_VALNAME3[]=                   {'M','o','u','s','e','S','p','e','e','d',0};
132 static const WCHAR SPI_SETBORDER_REGKEY[]=                    {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p','\\',
133                                                                'W','i','n','d','o','w','M','e','t','r','i','c','s',0};
134 static const WCHAR SPI_SETBORDER_VALNAME[]=                   {'B','o','r','d','e','r','W','i','d','t','h',0};
135 static const WCHAR SPI_SETKEYBOARDSPEED_REGKEY[]=             {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','K','e','y','b','o','a','r','d',0};
136 static const WCHAR SPI_SETKEYBOARDSPEED_VALNAME[]=            {'K','e','y','b','o','a','r','d','S','p','e','e','d',0};
137 static const WCHAR SPI_ICONHORIZONTALSPACING_REGKEY[]=        {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p','\\',
138                                                                'W','i','n','d','o','w','M','e','t','r','i','c','s',0};
139 static const WCHAR SPI_ICONHORIZONTALSPACING_VALNAME[]=       {'I','c','o','n','S','p','a','c','i','n','g',0};
140 static const WCHAR SPI_SETSCREENSAVETIMEOUT_REGKEY[]=         {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
141 static const WCHAR SPI_SETSCREENSAVETIMEOUT_VALNAME[]=        {'S','c','r','e','e','n','S','a','v','e','T','i','m','e','O','u','t',0};
142 static const WCHAR SPI_SETSCREENSAVEACTIVE_REGKEY[]=          {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
143 static const WCHAR SPI_SETSCREENSAVEACTIVE_VALNAME[]=         {'S','c','r','e','e','n','S','a','v','e','A','c','t','i','v','e',0};
144 static const WCHAR SPI_SETGRIDGRANULARITY_REGKEY[]=           {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
145 static const WCHAR SPI_SETGRIDGRANULARITY_VALNAME[]=          {'G','r','i','d','G','r','a','n','u','l','a','r','i','t','y',0};
146 static const WCHAR SPI_SETKEYBOARDDELAY_REGKEY[]=             {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','K','e','y','b','o','a','r','d',0};
147 static const WCHAR SPI_SETKEYBOARDDELAY_VALNAME[]=            {'K','e','y','b','o','a','r','d','D','e','l','a','y',0};
148 static const WCHAR SPI_ICONVERTICALSPACING_REGKEY[]=          {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p','\\',
149                                                                'W','i','n','d','o','w','M','e','t','r','i','c','s',0};
150 static const WCHAR SPI_ICONVERTICALSPACING_VALNAME[]=         {'I','c','o','n','V','e','r','t','i','c','a','l','S','p','a','c','i','n','g',0};
151 static const WCHAR SPI_SETICONTITLEWRAP_REGKEY1[]=            {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p','\\',
152                                                                'W','i','n','d','o','w','M','e','t','r','i','c','s',0};
153 static const WCHAR SPI_SETICONTITLEWRAP_REGKEY2[]=            {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
154 static const WCHAR SPI_SETICONTITLEWRAP_VALNAME[]=            {'I','c','o','n','T','i','t','l','e','W','r','a','p',0};
155 static const WCHAR SPI_SETICONTITLELOGFONT_REGKEY[]=          {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p','\\',
156                                                                'W','i','n','d','o','w','M','e','t','r','i','c','s',0};
157 static const WCHAR SPI_SETICONTITLELOGFONT_VALNAME[]=         {'I','c','o','n','F','o','n','t',0};
158 static const WCHAR SPI_SETMENUDROPALIGNMENT_REGKEY1[]=        {'S','o','f','t','w','a','r','e','\\',
159                                                                'M','i','c','r','o','s','o','f','t','\\',
160                                                                'W','i','n','d','o','w','s',' ','N','T','\\',
161                                                                'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
162                                                                'W','i','n','d','o','w','s',0};
163 static const WCHAR SPI_SETMENUDROPALIGNMENT_REGKEY2[]=        {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
164 static const WCHAR SPI_SETMENUDROPALIGNMENT_VALNAME[]=        {'M','e','n','u','D','r','o','p','A','l','i','g','n','m','e','n','t',0};
165 static const WCHAR SPI_SETDOUBLECLKWIDTH_REGKEY1[]=           {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
166 static const WCHAR SPI_SETDOUBLECLKWIDTH_REGKEY2[]=           {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
167 static const WCHAR SPI_SETDOUBLECLKWIDTH_VALNAME[]=           {'D','o','u','b','l','e','C','l','i','c','k','W','i','d','t','h',0};
168 static const WCHAR SPI_SETDOUBLECLKHEIGHT_REGKEY1[]=          {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
169 static const WCHAR SPI_SETDOUBLECLKHEIGHT_REGKEY2[]=          {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
170 static const WCHAR SPI_SETDOUBLECLKHEIGHT_VALNAME[]=          {'D','o','u','b','l','e','C','l','i','c','k','H','e','i','g','h','t',0};
171 static const WCHAR SPI_SETDOUBLECLICKTIME_REGKEY[]=           {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
172 static const WCHAR SPI_SETDOUBLECLICKTIME_VALNAME[]=          {'D','o','u','b','l','e','C','l','i','c','k','S','p','e','e','d',0};
173 static const WCHAR SPI_SETMOUSEBUTTONSWAP_REGKEY[]=           {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
174 static const WCHAR SPI_SETMOUSEBUTTONSWAP_VALNAME[]=          {'S','w','a','p','M','o','u','s','e','B','u','t','t','o','n','s',0};
175 static const WCHAR SPI_SETDRAGFULLWINDOWS_REGKEY[]=           {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
176 static const WCHAR SPI_SETDRAGFULLWINDOWS_VALNAME[]=          {'D','r','a','g','F','u','l','l','W','i','n','d','o','w','s',0};
177 static const WCHAR SPI_SETSHOWSOUNDS_REGKEY[]=                {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
178                                                                'A','c','c','e','s','s','i','b','i','l','i','t','y','\\',
179                                                                'S','h','o','w','S','o','u','n','d','s',0};
180 static const WCHAR SPI_SETSHOWSOUNDS_VALNAME[]=               {'O','n',0};
181 static const WCHAR SPI_SETKEYBOARDPREF_REGKEY[]=              {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
182                                                                'A','c','c','e','s','s','i','b','i','l','i','t','y','\\',
183                                                                'K','e','y','b','o','a','r','d',' ','P','r','e','f','e','r','e','n','c','e',0};
184 static const WCHAR SPI_SETKEYBOARDPREF_VALNAME[]=             {'O','n',0};
185 static const WCHAR SPI_SETSCREENREADER_REGKEY[]=              {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
186                                                                'A','c','c','e','s','s','i','b','i','l','i','t','y','\\',
187                                                                'B','l','i','n','d',' ','A','c','c','e','s','s',0};
188 static const WCHAR SPI_SETSCREENREADER_VALNAME[]=             {'O','n',0};
189 static const WCHAR SPI_SETDESKWALLPAPER_REGKEY[]=             {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
190 static const WCHAR SPI_SETDESKWALLPAPER_VALNAME[]=            {'W','a','l','l','p','a','p','e','r',0};
191 static const WCHAR SPI_SETFONTSMOOTHING_REGKEY[]=             {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
192 static const WCHAR SPI_SETFONTSMOOTHING_VALNAME[]=            {'F','o','n','t','S','m','o','o','t','h','i','n','g',0};
193 static const WCHAR SPI_SETLOWPOWERACTIVE_REGKEY[]=            {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
194 static const WCHAR SPI_SETLOWPOWERACTIVE_VALNAME[]=           {'L','o','w','P','o','w','e','r','A','c','t','i','v','e',0};
195 static const WCHAR SPI_SETPOWEROFFACTIVE_REGKEY[]=            {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
196 static const WCHAR SPI_SETPOWEROFFACTIVE_VALNAME[]=           {'P','o','w','e','r','O','f','f','A','c','t','i','v','e',0};
197 static const WCHAR SPI_USERPREFERENCEMASK_REGKEY[]=           {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
198 static const WCHAR SPI_USERPREFERENCEMASK_VALNAME[]=          {'U','s','e','r','P','r','e','f','e','r','e','n','c','e','m','a','s','k',0};
199 static const WCHAR SPI_SETLISTBOXSMOOTHSCROLLING_REGKEY[]=    {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
200 static const WCHAR SPI_SETLISTBOXSMOOTHSCROLLING_VALNAME[]=   {'S','m','o','o','t','h','S','c','r','o','l','l',0};
201 static const WCHAR SPI_SETMOUSEHOVERWIDTH_REGKEY[]=           {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
202 static const WCHAR SPI_SETMOUSEHOVERWIDTH_VALNAME[]=          {'M','o','u','s','e','H','o','v','e','r','W','i','d','t','h',0};
203 static const WCHAR SPI_SETMOUSEHOVERHEIGHT_REGKEY[]=          {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
204 static const WCHAR SPI_SETMOUSEHOVERHEIGHT_VALNAME[]=         {'M','o','u','s','e','H','o','v','e','r','H','e','i','g','h','t',0};
205 static const WCHAR SPI_SETMOUSEHOVERTIME_REGKEY[]=            {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','M','o','u','s','e',0};
206 static const WCHAR SPI_SETMOUSEHOVERTIME_VALNAME[]=           {'M','o','u','s','e','H','o','v','e','r','T','i','m','e',0};
207 static const WCHAR SPI_SETMOUSESCROLLLINES_REGKEY[]=          {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
208 static const WCHAR SPI_SETMOUSESCROLLLINES_VALNAME[]=         {'W','h','e','e','l','S','c','r','o','l','l','L','i','n','e','s',0};
209 static const WCHAR SPI_SETMENUSHOWDELAY_REGKEY[]=             {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
210 static const WCHAR SPI_SETMENUSHOWDELAY_VALNAME[]=            {'M','e','n','u','S','h','o','w','D','e','l','a','y',0};
211 static const WCHAR SPI_CARETWIDTH_REGKEY[]=                   {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
212 static const WCHAR SPI_CARETWIDTH_VALNAME[]=                  {'C','a','r','e','t','W','i','d','t','h',0};
213
214 /* FIXME - real values */
215 static const WCHAR SPI_SETSCREENSAVERRUNNING_REGKEY[]=   {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p',0};
216 static const WCHAR SPI_SETSCREENSAVERRUNNING_VALNAME[]=  {'W','I','N','E','_','S','c','r','e','e','n','S','a','v','e','r','R','u','n','n','i','n','g',0};
217
218 static const WCHAR METRICS_REGKEY[]=                  {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p','\\',
219                                                        'W','i','n','d','o','w','M','e','t','r','i','c','s',0};
220 static const WCHAR METRICS_SCROLLWIDTH_VALNAME[]=     {'S','c','r','o','l','l','W','i','d','t','h',0};
221 static const WCHAR METRICS_SCROLLHEIGHT_VALNAME[]=    {'S','c','r','o','l','l','H','e','i','g','h','t',0};
222 static const WCHAR METRICS_CAPTIONWIDTH_VALNAME[]=    {'C','a','p','t','i','o','n','W','i','d','t','h',0};
223 static const WCHAR METRICS_CAPTIONHEIGHT_VALNAME[]=   {'C','a','p','t','i','o','n','H','e','i','g','h','t',0};
224 static const WCHAR METRICS_SMCAPTIONWIDTH_VALNAME[]=  {'S','m','C','a','p','t','i','o','n','W','i','d','t','h',0};
225 static const WCHAR METRICS_SMCAPTIONHEIGHT_VALNAME[]= {'S','m','C','a','p','t','i','o','n','H','e','i','g','h','t',0};
226 static const WCHAR METRICS_MENUWIDTH_VALNAME[]=       {'M','e','n','u','W','i','d','t','h',0};
227 static const WCHAR METRICS_MENUHEIGHT_VALNAME[]=      {'M','e','n','u','H','e','i','g','h','t',0};
228 static const WCHAR METRICS_ICONSIZE_VALNAME[]=        {'S','h','e','l','l',' ','I','c','o','n',' ','S','i','z','e',0};
229 static const WCHAR METRICS_BORDERWIDTH_VALNAME[]=     {'B','o','r','d','e','r','W','i','d','t','h',0};
230 static const WCHAR METRICS_CAPTIONLOGFONT_VALNAME[]=  {'C','a','p','t','i','o','n','F','o','n','t',0};
231 static const WCHAR METRICS_SMCAPTIONLOGFONT_VALNAME[]={'S','m','C','a','p','t','i','o','n','F','o','n','t',0};
232 static const WCHAR METRICS_MENULOGFONT_VALNAME[]=     {'M','e','n','u','F','o','n','t',0};
233 static const WCHAR METRICS_MESSAGELOGFONT_VALNAME[]=  {'M','e','s','s','a','g','e','F','o','n','t',0};
234 static const WCHAR METRICS_STATUSLOGFONT_VALNAME[]=   {'S','t','a','t','u','s','F','o','n','t',0};
235 /* minimized metrics */
236 static const WCHAR METRICS_MINWIDTH_VALNAME[] =   {'M','i','n','W','i','d','t','h','\0'}; 
237 static const WCHAR METRICS_MINHORZGAP_VALNAME[] = {'M','i','n','H','o','r','z','G','a','p','\0'};
238 static const WCHAR METRICS_MINVERTGAP_VALNAME[] = {'M','i','n','V','e','r','t','G','a','p','\0'};
239 static const WCHAR METRICS_MINARRANGE_VALNAME[] = {'M','i','n','A','r','r','a','n','g','e','\0'}; 
240
241 static const WCHAR WINE_CURRENT_USER_REGKEY[] = {'S','o','f','t','w','a','r','e','\\',
242                                                  'W','i','n','e',0};
243
244 /* volatile registry branch under WINE_CURRENT_USER_REGKEY for temporary values storage */
245 static const WCHAR WINE_CURRENT_USER_REGKEY_TEMP_PARAMS[] = {'T','e','m','p','o','r','a','r','y',' ',
246                                                              'S','y','s','t','e','m',' ',
247                                                              'P','a','r','a','m','e','t','e','r','s',0};
248
249 static const WCHAR Yes[]=                                    {'Y','e','s',0};
250 static const WCHAR No[]=                                     {'N','o',0};
251 static const WCHAR Desktop[]=                                {'D','e','s','k','t','o','p',0};
252 static const WCHAR Pattern[]=                                {'P','a','t','t','e','r','n',0};
253 static const WCHAR MenuFont[]=                               {'M','e','n','u','F','o','n','t',0};
254 static const WCHAR MenuFontSize[]=                           {'M','e','n','u','F','o','n','t','S','i','z','e',0};
255 static const WCHAR StatusFont[]=                             {'S','t','a','t','u','s','F','o','n','t',0};
256 static const WCHAR StatusFontSize[]=                         {'S','t','a','t','u','s','F','o','n','t','S','i','z','e',0};
257 static const WCHAR MessageFont[]=                            {'M','e','s','s','a','g','e','F','o','n','t',0};
258 static const WCHAR MessageFontSize[]=                        {'M','e','s','s','a','g','e','F','o','n','t','S','i','z','e',0};
259 static const WCHAR System[]=                                 {'S','y','s','t','e','m',0};
260 static const WCHAR IconTitleSize[]=                          {'I','c','o','n','T','i','t','l','e','S','i','z','e',0};
261 static const WCHAR IconTitleFaceName[]=                      {'I','c','o','n','T','i','t','l','e','F','a','c','e','N','a','m','e',0};
262 static const WCHAR defPattern[]=                             {'1','7','0',' ','8','5',' ','1','7','0',' ','8','5',' ','1','7','0',' ','8','5',
263                                                               ' ','1','7','0',' ','8','5',0};
264 static const WCHAR CSu[]=                                    {'%','u',0};
265 static const WCHAR CSd[]=                                    {'%','d',0};
266
267 /* Indicators whether system parameter value is loaded */
268 static char spi_loaded[SPI_INDEX_COUNT];
269
270 static BOOL notify_change = TRUE;
271
272 /* System parameters storage */
273 static BOOL beep_active = TRUE;
274 static int mouse_threshold1 = 6;
275 static int mouse_threshold2 = 10;
276 static int mouse_speed = 1;
277 static UINT border = 1;
278 static UINT keyboard_speed = 31;
279 static UINT screensave_timeout = 300;
280 static UINT grid_granularity = 0;
281 static UINT keyboard_delay = 1;
282 static UINT double_click_width = 4;
283 static UINT double_click_height = 4;
284 static UINT double_click_time = 500;
285 static BOOL drag_full_windows = FALSE;
286 static RECT work_area;
287 static BOOL keyboard_pref = TRUE;
288 static BOOL screen_reader = FALSE;
289 static UINT mouse_hover_width = 4;
290 static UINT mouse_hover_height = 4;
291 static UINT mouse_hover_time = 400;
292 static UINT mouse_scroll_lines = 3;
293 static UINT menu_show_delay = 400;
294 static UINT menu_drop_alignment = 0;
295 static BOOL screensaver_running = FALSE;
296 static UINT font_smoothing = 0;  /* 0x01 for 95/98/NT, 0x02 for 98/ME/2k/XP */
297 static BOOL lowpoweractive = FALSE;
298 static BOOL poweroffactive = FALSE;
299 static BOOL show_sounds = FALSE;
300 static BOOL swap_buttons = FALSE;
301 static UINT caret_width = 1;
302 static BYTE user_prefs[4];
303
304 static MINIMIZEDMETRICS minimized_metrics =
305 {
306     sizeof(MINIMIZEDMETRICS),
307     154,      /* iWidth */
308     0,        /* iHorzGap */
309     0,        /* iVertGap */
310     ARW_HIDE  /* iArrange */
311 };
312
313 static ICONMETRICSW icon_metrics =
314 {
315     sizeof(ICONMETRICSW),
316     75,   /* iHorzSpacing */
317     75,   /* iVertSpacing */
318     TRUE, /* iTitleWrap */
319     { -11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET,
320       OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH }   /* lfFont */
321 };
322
323 static NONCLIENTMETRICSW nonclient_metrics =
324 {
325     sizeof(NONCLIENTMETRICSW),
326     1,     /* iBorderWidth */
327     16,    /* iScrollWidth */
328     16,    /* iScrollHeight */
329     18,    /* iCaptionWidth */
330     18,    /* iCaptionHeight */
331     { 0 }, /* lfCaptionFont */
332     13,    /* iSmCaptionWidth */
333     15,    /* iSmCaptionHeight */
334     { 0 }, /* lfSmCaptionFont */
335     18,    /* iMenuWidth */
336     18,    /* iMenuHeight */
337     { 0 }, /* lfMenuFont */
338     { 0 }, /* lfStatusFont */
339     { 0 }  /* lfMessageFont */
340 };
341
342 /* some additional non client metric info */
343 static TEXTMETRICW tmMenuFont;
344 static UINT CaptionFontAvCharWidth;
345
346 static SIZE icon_size = { 32, 32 };
347
348 #define NUM_SYS_COLORS     (COLOR_MENUBAR+1)
349
350 static COLORREF SysColors[NUM_SYS_COLORS];
351 static HBRUSH SysColorBrushes[NUM_SYS_COLORS];
352 static HPEN   SysColorPens[NUM_SYS_COLORS];
353
354 static const WORD wPattern55AA[] = { 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa };
355
356 HBRUSH SYSCOLOR_55AABrush = 0;
357
358 extern void __wine_make_gdi_object_system( HGDIOBJ handle, BOOL set );
359
360
361 /* This function is a copy of the one in objects/font.c */
362 static void SYSPARAMS_LogFont32ATo16( const LOGFONTA* font32, LPLOGFONT16 font16 )
363 {
364     font16->lfHeight = font32->lfHeight;
365     font16->lfWidth = font32->lfWidth;
366     font16->lfEscapement = font32->lfEscapement;
367     font16->lfOrientation = font32->lfOrientation;
368     font16->lfWeight = font32->lfWeight;
369     font16->lfItalic = font32->lfItalic;
370     font16->lfUnderline = font32->lfUnderline;
371     font16->lfStrikeOut = font32->lfStrikeOut;
372     font16->lfCharSet = font32->lfCharSet;
373     font16->lfOutPrecision = font32->lfOutPrecision;
374     font16->lfClipPrecision = font32->lfClipPrecision;
375     font16->lfQuality = font32->lfQuality;
376     font16->lfPitchAndFamily = font32->lfPitchAndFamily;
377     lstrcpynA( font16->lfFaceName, font32->lfFaceName, LF_FACESIZE );
378 }
379
380 static void SYSPARAMS_LogFont16To32W( const LOGFONT16 *font16, LPLOGFONTW font32 )
381 {
382     font32->lfHeight = font16->lfHeight;
383     font32->lfWidth = font16->lfWidth;
384     font32->lfEscapement = font16->lfEscapement;
385     font32->lfOrientation = font16->lfOrientation;
386     font32->lfWeight = font16->lfWeight;
387     font32->lfItalic = font16->lfItalic;
388     font32->lfUnderline = font16->lfUnderline;
389     font32->lfStrikeOut = font16->lfStrikeOut;
390     font32->lfCharSet = font16->lfCharSet;
391     font32->lfOutPrecision = font16->lfOutPrecision;
392     font32->lfClipPrecision = font16->lfClipPrecision;
393     font32->lfQuality = font16->lfQuality;
394     font32->lfPitchAndFamily = font16->lfPitchAndFamily;
395     MultiByteToWideChar( CP_ACP, 0, font16->lfFaceName, -1, font32->lfFaceName, LF_FACESIZE );
396     font32->lfFaceName[LF_FACESIZE-1] = 0;
397 }
398
399 static void SYSPARAMS_LogFont32WTo32A( const LOGFONTW* font32W, LPLOGFONTA font32A )
400 {
401     font32A->lfHeight = font32W->lfHeight;
402     font32A->lfWidth = font32W->lfWidth;
403     font32A->lfEscapement = font32W->lfEscapement;
404     font32A->lfOrientation = font32W->lfOrientation;
405     font32A->lfWeight = font32W->lfWeight;
406     font32A->lfItalic = font32W->lfItalic;
407     font32A->lfUnderline = font32W->lfUnderline;
408     font32A->lfStrikeOut = font32W->lfStrikeOut;
409     font32A->lfCharSet = font32W->lfCharSet;
410     font32A->lfOutPrecision = font32W->lfOutPrecision;
411     font32A->lfClipPrecision = font32W->lfClipPrecision;
412     font32A->lfQuality = font32W->lfQuality;
413     font32A->lfPitchAndFamily = font32W->lfPitchAndFamily;
414     WideCharToMultiByte( CP_ACP, 0, font32W->lfFaceName, -1, font32A->lfFaceName, LF_FACESIZE, NULL, NULL );
415     font32A->lfFaceName[LF_FACESIZE-1] = 0;
416 }
417
418 static void SYSPARAMS_LogFont32ATo32W( const LOGFONTA* font32A, LPLOGFONTW font32W )
419 {
420     font32W->lfHeight = font32A->lfHeight;
421     font32W->lfWidth = font32A->lfWidth;
422     font32W->lfEscapement = font32A->lfEscapement;
423     font32W->lfOrientation = font32A->lfOrientation;
424     font32W->lfWeight = font32A->lfWeight;
425     font32W->lfItalic = font32A->lfItalic;
426     font32W->lfUnderline = font32A->lfUnderline;
427     font32W->lfStrikeOut = font32A->lfStrikeOut;
428     font32W->lfCharSet = font32A->lfCharSet;
429     font32W->lfOutPrecision = font32A->lfOutPrecision;
430     font32W->lfClipPrecision = font32A->lfClipPrecision;
431     font32W->lfQuality = font32A->lfQuality;
432     font32W->lfPitchAndFamily = font32A->lfPitchAndFamily;
433     MultiByteToWideChar( CP_ACP, 0, font32A->lfFaceName, -1, font32W->lfFaceName, LF_FACESIZE );
434     font32W->lfFaceName[LF_FACESIZE-1] = 0;
435 }
436
437 static void SYSPARAMS_NonClientMetrics32ATo16( const NONCLIENTMETRICSA* lpnm32, LPNONCLIENTMETRICS16 lpnm16 )
438 {
439     lpnm16->iBorderWidth        = lpnm32->iBorderWidth;
440     lpnm16->iScrollWidth        = lpnm32->iScrollWidth;
441     lpnm16->iScrollHeight       = lpnm32->iScrollHeight;
442     lpnm16->iCaptionWidth       = lpnm32->iCaptionWidth;
443     lpnm16->iCaptionHeight      = lpnm32->iCaptionHeight;
444     SYSPARAMS_LogFont32ATo16( &lpnm32->lfCaptionFont,   &lpnm16->lfCaptionFont );
445     lpnm16->iSmCaptionWidth     = lpnm32->iSmCaptionWidth;
446     lpnm16->iSmCaptionHeight    = lpnm32->iSmCaptionHeight;
447     SYSPARAMS_LogFont32ATo16( &lpnm32->lfSmCaptionFont, &lpnm16->lfSmCaptionFont );
448     lpnm16->iMenuWidth          = lpnm32->iMenuWidth;
449     lpnm16->iMenuHeight         = lpnm32->iMenuHeight;
450     SYSPARAMS_LogFont32ATo16( &lpnm32->lfMenuFont,      &lpnm16->lfMenuFont );
451     SYSPARAMS_LogFont32ATo16( &lpnm32->lfStatusFont,    &lpnm16->lfStatusFont );
452     SYSPARAMS_LogFont32ATo16( &lpnm32->lfMessageFont,   &lpnm16->lfMessageFont );
453 }
454
455 static void SYSPARAMS_NonClientMetrics32WTo32A( const NONCLIENTMETRICSW* lpnm32W, LPNONCLIENTMETRICSA lpnm32A )
456 {
457     lpnm32A->iBorderWidth       = lpnm32W->iBorderWidth;
458     lpnm32A->iScrollWidth       = lpnm32W->iScrollWidth;
459     lpnm32A->iScrollHeight      = lpnm32W->iScrollHeight;
460     lpnm32A->iCaptionWidth      = lpnm32W->iCaptionWidth;
461     lpnm32A->iCaptionHeight     = lpnm32W->iCaptionHeight;
462     SYSPARAMS_LogFont32WTo32A(  &lpnm32W->lfCaptionFont,        &lpnm32A->lfCaptionFont );
463     lpnm32A->iSmCaptionWidth    = lpnm32W->iSmCaptionWidth;
464     lpnm32A->iSmCaptionHeight   = lpnm32W->iSmCaptionHeight;
465     SYSPARAMS_LogFont32WTo32A( &lpnm32W->lfSmCaptionFont,       &lpnm32A->lfSmCaptionFont );
466     lpnm32A->iMenuWidth         = lpnm32W->iMenuWidth;
467     lpnm32A->iMenuHeight        = lpnm32W->iMenuHeight;
468     SYSPARAMS_LogFont32WTo32A( &lpnm32W->lfMenuFont,            &lpnm32A->lfMenuFont );
469     SYSPARAMS_LogFont32WTo32A( &lpnm32W->lfStatusFont,          &lpnm32A->lfStatusFont );
470     SYSPARAMS_LogFont32WTo32A( &lpnm32W->lfMessageFont,         &lpnm32A->lfMessageFont );
471 }
472
473 static void SYSPARAMS_NonClientMetrics32ATo32W( const NONCLIENTMETRICSA* lpnm32A, LPNONCLIENTMETRICSW lpnm32W )
474 {
475     lpnm32W->iBorderWidth       = lpnm32A->iBorderWidth;
476     lpnm32W->iScrollWidth       = lpnm32A->iScrollWidth;
477     lpnm32W->iScrollHeight      = lpnm32A->iScrollHeight;
478     lpnm32W->iCaptionWidth      = lpnm32A->iCaptionWidth;
479     lpnm32W->iCaptionHeight     = lpnm32A->iCaptionHeight;
480     SYSPARAMS_LogFont32ATo32W(  &lpnm32A->lfCaptionFont,        &lpnm32W->lfCaptionFont );
481     lpnm32W->iSmCaptionWidth    = lpnm32A->iSmCaptionWidth;
482     lpnm32W->iSmCaptionHeight   = lpnm32A->iSmCaptionHeight;
483     SYSPARAMS_LogFont32ATo32W( &lpnm32A->lfSmCaptionFont,       &lpnm32W->lfSmCaptionFont );
484     lpnm32W->iMenuWidth         = lpnm32A->iMenuWidth;
485     lpnm32W->iMenuHeight        = lpnm32A->iMenuHeight;
486     SYSPARAMS_LogFont32ATo32W( &lpnm32A->lfMenuFont,            &lpnm32W->lfMenuFont );
487     SYSPARAMS_LogFont32ATo32W( &lpnm32A->lfStatusFont,          &lpnm32W->lfStatusFont );
488     SYSPARAMS_LogFont32ATo32W( &lpnm32A->lfMessageFont,         &lpnm32W->lfMessageFont );
489 }
490
491 /* get text metrics and/or "average" char width of the specified logfont 
492  * for the specified dc */
493 static void get_text_metr_size( HDC hdc, LOGFONTW *plf, TEXTMETRICW * ptm, UINT *psz)
494 {
495     HFONT hfont, hfontsav;
496     TEXTMETRICW tm;
497     if( !ptm) ptm = &tm;
498     hfont = CreateFontIndirectW( plf);
499     if( !hfont || ( hfontsav = SelectObject( hdc, hfont)) == NULL ) {
500         ptm->tmHeight = -1;
501         if( psz) *psz = 10;
502         if( hfont) DeleteObject( hfont);
503         return;
504     }
505     GetTextMetricsW( hdc, ptm);
506     if( psz)
507         if( !(*psz = GdiGetCharDimensions( hdc, ptm, NULL)))
508             *psz = 10;
509     SelectObject( hdc, hfontsav);
510     DeleteObject( hfont);
511 }
512
513 /***********************************************************************
514  *           get_volatile_regkey
515  *
516  * Return a handle to the volatile registry key used to store
517  * non-permanently modified parameters.
518  */
519 static HKEY get_volatile_regkey(void)
520 {
521     static HKEY volatile_key;
522
523     if (!volatile_key)
524     {
525         HKEY key;
526         /* This must be non-volatile! */
527         if (RegCreateKeyExW( HKEY_CURRENT_USER, WINE_CURRENT_USER_REGKEY,
528                              0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0,
529                              &key, 0 ) != ERROR_SUCCESS)
530         {
531             ERR("Can't create wine registry branch\n");
532         }
533         else
534         {
535             /* @@ Wine registry key: HKCU\Software\Wine\Temporary System Parameters */
536             if (RegCreateKeyExW( key, WINE_CURRENT_USER_REGKEY_TEMP_PARAMS,
537                                  0, 0, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, 0,
538                                  &volatile_key, 0 ) != ERROR_SUCCESS)
539                 ERR("Can't create non-permanent wine registry branch\n");
540
541             RegCloseKey(key);
542         }
543     }
544     return volatile_key;
545 }
546
547 /***********************************************************************
548  *           SYSPARAMS_NotifyChange
549  *
550  * Sends notification about system parameter update.
551  */
552 static void SYSPARAMS_NotifyChange( UINT uiAction, UINT fWinIni )
553 {
554     static const WCHAR emptyW[1];
555
556     if (notify_change)
557     {
558         if (fWinIni & SPIF_UPDATEINIFILE)
559         {
560             if (fWinIni & (SPIF_SENDWININICHANGE | SPIF_SENDCHANGE))
561                 SendMessageTimeoutW(HWND_BROADCAST, WM_SETTINGCHANGE,
562                                     uiAction, (LPARAM) emptyW,
563                                     SMTO_ABORTIFHUNG, 2000, NULL );
564         }
565         else
566         {
567             /* FIXME notify other wine processes with internal message */
568         }
569     }
570 }
571
572
573 /***********************************************************************
574  * Loads system parameter from user profile.
575  */
576 static BOOL SYSPARAMS_LoadRaw( LPCWSTR lpRegKey, LPCWSTR lpValName, LPBYTE lpBuf, DWORD count )
577 {
578     BOOL ret = FALSE;
579     DWORD type;
580     HKEY hKey;
581
582     memset( lpBuf, 0, count );
583     if ((RegOpenKeyW( get_volatile_regkey(), lpRegKey, &hKey ) == ERROR_SUCCESS) ||
584         (RegOpenKeyW( HKEY_CURRENT_USER, lpRegKey, &hKey ) == ERROR_SUCCESS))
585     {
586         ret = !RegQueryValueExW( hKey, lpValName, NULL, &type, (LPBYTE)lpBuf, &count);
587         RegCloseKey( hKey );
588     }
589     return ret;
590 }
591
592 static BOOL SYSPARAMS_Load( LPCWSTR lpRegKey, LPCWSTR lpValName, LPWSTR lpBuf, DWORD count )
593 {
594   return SYSPARAMS_LoadRaw( lpRegKey, lpValName, (LPBYTE)lpBuf, count );
595 }
596
597 /***********************************************************************
598  * Saves system parameter to user profile.
599  */
600
601 /* Save data as-is */
602 static BOOL SYSPARAMS_SaveRaw( LPCWSTR lpRegKey, LPCWSTR lpValName, 
603                                const BYTE* lpValue, DWORD valueSize, 
604                                DWORD type, UINT fWinIni )
605 {
606     HKEY hKey;
607     HKEY hBaseKey;
608     DWORD dwOptions;
609     BOOL ret = FALSE;
610
611     if (fWinIni & SPIF_UPDATEINIFILE)
612     {
613         hBaseKey = HKEY_CURRENT_USER;
614         dwOptions = 0;
615     }
616     else
617     {
618         hBaseKey = get_volatile_regkey();
619         dwOptions = REG_OPTION_VOLATILE;
620     }
621
622     if (RegCreateKeyExW( hBaseKey, lpRegKey,
623                          0, 0, dwOptions, KEY_ALL_ACCESS,
624                          0, &hKey, 0 ) == ERROR_SUCCESS)
625     {
626         if (RegSetValueExW( hKey, lpValName, 0, type,
627                             lpValue, valueSize) == ERROR_SUCCESS)
628         {
629             ret = TRUE;
630             if (hBaseKey == HKEY_CURRENT_USER)
631                 RegDeleteKeyW( get_volatile_regkey(), lpRegKey );
632         }
633         RegCloseKey( hKey );
634     }
635     return ret;
636 }
637
638 /* Convenience function to save strings */
639 static BOOL SYSPARAMS_Save( LPCWSTR lpRegKey, LPCWSTR lpValName, LPCWSTR lpValue,
640                             UINT fWinIni )
641 {
642     return SYSPARAMS_SaveRaw( lpRegKey, lpValName, (const BYTE*)lpValue, 
643         (strlenW(lpValue) + 1)*sizeof(WCHAR), REG_SZ, fWinIni );
644 }
645
646 /* Convenience function to save logical fonts */
647 static BOOL SYSPARAMS_SaveLogFont( LPCWSTR lpRegKey, LPCWSTR lpValName,
648                                     LPLOGFONTW plf, UINT fWinIni )
649 {
650     return SYSPARAMS_SaveRaw( lpRegKey, lpValName, (const BYTE*)plf, 
651         sizeof( LOGFONTW), REG_BINARY, fWinIni );
652 }
653
654
655 static inline HDC get_display_dc(void)
656 {
657     static const WCHAR DISPLAY[] = {'D','I','S','P','L','A','Y',0};
658     static HDC display_dc;
659     if (!display_dc) display_dc = CreateICW( DISPLAY, NULL, NULL, NULL );
660     return display_dc;
661 }
662
663 static inline int get_display_dpi(void)
664 {
665     static int display_dpi;
666     if (!display_dpi) display_dpi = GetDeviceCaps( get_display_dc(), LOGPIXELSY );
667     return display_dpi;
668 }
669
670 /***********************************************************************
671  * SYSPARAMS_Twips2Pixels
672  *
673  * Convert a dimension value that was obtained from the registry.  These are
674  * quoted as being "twips" values if negative and pixels if positive.
675  * One inch is 1440 twips. So to convert, divide by 1440 to get inches and
676  * multiply that by the dots-per-inch to get the size in pixels. 
677  * See for example
678  *   MSDN Library - April 2001 -> Resource Kits ->
679  *       Windows 2000 Resource Kit Reference ->
680  *       Technical Reference to the Windows 2000 Registry ->
681  *       HKEY_CURRENT_USER -> Control Panel -> Desktop -> WindowMetrics
682  */
683 inline static int SYSPARAMS_Twips2Pixels(int x)
684 {
685     if (x < 0)
686         x = (-x * get_display_dpi() + 720) / 1440;
687     return x;
688 }
689
690 /***********************************************************************
691  * get_reg_metric
692  *
693  * Get a registry entry from the already open key.  This allows us to open the
694  * section once and read several values.
695  *
696  * Of course this function belongs somewhere more usable but here will do
697  * for now.
698  */
699 static int get_reg_metric( HKEY hkey, LPCWSTR lpValName, int default_value )
700 {
701     int value = default_value;
702     if (hkey)
703     {
704         WCHAR buffer[128];
705         DWORD type, count = sizeof(buffer);
706         if(!RegQueryValueExW( hkey, lpValName, NULL, &type, (LPBYTE)buffer, &count) )
707         {
708             if (type != REG_SZ)
709             {
710                 /* Are there any utilities for converting registry entries
711                  * between formats?
712                  */
713                 /* FIXME_(reg)("We need reg format converter\n"); */
714             }
715             else
716                 value = atoiW(buffer);
717         }
718     }
719     return SYSPARAMS_Twips2Pixels(value);
720 }
721
722
723 /*************************************************************************
724  *             SYSPARAMS_SetSysColor
725  */
726 static void SYSPARAMS_SetSysColor( int index, COLORREF color )
727 {
728     if (index < 0 || index >= NUM_SYS_COLORS) return;
729     SysColors[index] = color;
730     if (SysColorBrushes[index])
731     {
732         __wine_make_gdi_object_system( SysColorBrushes[index], FALSE);
733         DeleteObject( SysColorBrushes[index] );
734     }
735     SysColorBrushes[index] = CreateSolidBrush( color );
736     __wine_make_gdi_object_system( SysColorBrushes[index], TRUE);
737
738     if (SysColorPens[index])
739     {
740         __wine_make_gdi_object_system( SysColorPens[index], FALSE);
741         DeleteObject( SysColorPens[index] );
742     }
743     SysColorPens[index] = CreatePen( PS_SOLID, 1, color );
744     __wine_make_gdi_object_system( SysColorPens[index], TRUE);
745 }
746
747 /* load a uint parameter from the registry */
748 static BOOL get_uint_param( unsigned int idx, LPCWSTR regkey, LPCWSTR value,
749                             UINT *value_ptr, UINT *ret_ptr )
750 {
751     if (!ret_ptr) return FALSE;
752     if (!spi_loaded[idx])
753     {
754         WCHAR buf[12];
755
756         if (SYSPARAMS_Load( regkey, value, buf, sizeof(buf) )) *value_ptr = atoiW( buf );
757         spi_loaded[idx] = TRUE;
758     }
759     *ret_ptr = *value_ptr;
760     return TRUE;
761 }
762
763 /* load a twips parameter from the registry */
764 static BOOL get_twips_param( unsigned int idx, LPCWSTR regkey, LPCWSTR value,
765                              UINT *value_ptr, UINT *ret_ptr )
766 {
767     if (!ret_ptr) return FALSE;
768     if (!spi_loaded[idx])
769     {
770         WCHAR buf[12];
771
772         if (SYSPARAMS_Load( regkey, value, buf, sizeof(buf) ))
773             *value_ptr = SYSPARAMS_Twips2Pixels( atoiW(buf) );
774         spi_loaded[idx] = TRUE;
775     }
776     *ret_ptr = *value_ptr;
777     return TRUE;
778 }
779
780 /* load a boolean parameter from the registry */
781 static inline BOOL get_bool_param( unsigned int idx, LPCWSTR regkey, LPCWSTR value,
782                                    BOOL *value_ptr, BOOL *ret_ptr )
783 {
784     return get_uint_param( idx, regkey, value, (UINT *)value_ptr, (UINT *)ret_ptr );
785 }
786
787 /* set a uint parameter that is mirrored in two different registry locations */
788 static BOOL set_uint_param_mirrored( unsigned int idx, LPCWSTR regkey, LPCWSTR regkey_mirror,
789                                      LPCWSTR value, UINT *value_ptr, UINT new_val, UINT fWinIni )
790 {
791     WCHAR buf[12];
792
793     wsprintfW(buf, CSu, new_val);
794     if (!SYSPARAMS_Save( regkey, value, buf, fWinIni )) return FALSE;
795     if (regkey_mirror) SYSPARAMS_Save( regkey_mirror, value, buf, fWinIni );
796     *value_ptr = new_val;
797     spi_loaded[idx] = TRUE;
798     return TRUE;
799 }
800
801 /* save an int parameter in registry */
802 static BOOL save_int_param( LPCWSTR regkey, LPCWSTR value, INT *value_ptr,
803                             INT new_val, UINT fWinIni )
804 {
805     WCHAR buf[12];
806
807     wsprintfW(buf, CSd, new_val);
808     if (!SYSPARAMS_Save( regkey, value, buf, fWinIni )) return FALSE;
809     if( value_ptr) *value_ptr = new_val;
810     return TRUE;
811 }
812
813 /* set an int parameter in the registry */
814 static inline BOOL set_int_param( unsigned int idx, LPCWSTR regkey, LPCWSTR value,
815                                   INT *value_ptr, INT new_val, UINT fWinIni )
816 {
817     BOOL ret = save_int_param( regkey, value, value_ptr, new_val, fWinIni );
818     if (ret) spi_loaded[idx] = TRUE;
819     return ret;
820 }
821
822 /* set a uint parameter in the registry */
823 static inline BOOL set_uint_param( unsigned int idx, LPCWSTR regkey, LPCWSTR value,
824                                    UINT *value_ptr, UINT new_val, UINT fWinIni )
825 {
826     return set_uint_param_mirrored( idx, regkey, NULL, value, value_ptr, new_val, fWinIni );
827 }
828
829 /* set a boolean parameter that is mirrored in two different registry locations */
830 static inline BOOL set_bool_param_mirrored( unsigned int idx, LPCWSTR regkey, LPCWSTR regkey_mirror,
831                                             LPCWSTR value, BOOL *value_ptr, BOOL new_val, UINT fWinIni )
832 {
833     return set_uint_param_mirrored( idx, regkey, regkey_mirror, value,
834                                     (UINT *)value_ptr, new_val, fWinIni );
835 }
836
837 /* set a boolean parameter in the registry */
838 static inline BOOL set_bool_param( unsigned int idx, LPCWSTR regkey, LPCWSTR value,
839                                    BOOL *value_ptr, BOOL new_val, UINT fWinIni )
840 {
841     return set_uint_param( idx, regkey, value, (UINT *)value_ptr, new_val, fWinIni );
842 }
843
844 /* load a boolean parameter from the user preference key */
845 static BOOL get_user_pref_param( UINT offset, UINT mask, BOOL *ret_ptr )
846 {
847     if (!ret_ptr) return FALSE;
848
849     if (!spi_loaded[SPI_USERPREFERENCEMASK_IDX])
850     {
851         SYSPARAMS_LoadRaw( SPI_USERPREFERENCEMASK_REGKEY,
852                            SPI_USERPREFERENCEMASK_VALNAME,
853                            user_prefs, sizeof(user_prefs) );
854         spi_loaded[SPI_USERPREFERENCEMASK_IDX] = TRUE;
855     }
856     *ret_ptr = (user_prefs[offset] & mask) != 0;
857     return TRUE;
858 }
859
860 /* set a boolean parameter in the user preference key */
861 static BOOL set_user_pref_param( UINT offset, UINT mask, BOOL value, BOOL fWinIni )
862 {
863     SYSPARAMS_LoadRaw( SPI_USERPREFERENCEMASK_REGKEY,
864                        SPI_USERPREFERENCEMASK_VALNAME,
865                        user_prefs, sizeof(user_prefs) );
866     spi_loaded[SPI_USERPREFERENCEMASK_IDX] = TRUE;
867
868     if (value) user_prefs[offset] |= mask;
869     else user_prefs[offset] &= ~mask;
870
871     SYSPARAMS_SaveRaw( SPI_USERPREFERENCEMASK_REGKEY,
872                        SPI_USERPREFERENCEMASK_VALNAME,
873                        user_prefs, sizeof(user_prefs), REG_BINARY, fWinIni );
874     return TRUE;
875 }
876
877 /***********************************************************************
878  *           SYSPARAMS_Init
879  *
880  * Initialisation of the system metrics array.
881  */
882 void SYSPARAMS_Init(void)
883 {
884     HKEY hkey; /* key to the window metrics area of the registry */
885     int i, r, g, b;
886     char buffer[100];
887     HBITMAP h55AABitmap;
888
889     /* initialize system colors */
890
891     if (RegCreateKeyExA(HKEY_CURRENT_USER, "Control Panel\\Colors", 0, 0, 0, KEY_ALL_ACCESS, 0, &hkey, 0))
892         hkey = 0;
893     for (i = 0; i < NUM_SYS_COLORS; i++)
894     {
895         BOOL bOk = FALSE;
896
897         /* first try, registry */
898         if (hkey)
899         {
900             DWORD dwDataSize = sizeof(buffer);
901             if (!(RegQueryValueExA(hkey,DefSysColors[i*2], 0, 0, (LPBYTE) buffer, &dwDataSize)))
902                 if (sscanf( buffer, "%d %d %d", &r, &g, &b ) == 3) bOk = TRUE;
903         }
904
905         /* second try, win.ini */
906         if (!bOk)
907         {
908             GetProfileStringA( "colors", DefSysColors[i*2], DefSysColors[i*2+1], buffer, 100 );
909             if (sscanf( buffer, " %d %d %d", &r, &g, &b ) == 3) bOk = TRUE;
910         }
911
912         /* last chance, take the default */
913         if (!bOk)
914         {
915             int iNumColors = sscanf( DefSysColors[i*2+1], " %d %d %d", &r, &g, &b );
916             assert (iNumColors==3);
917         }
918
919         SYSPARAMS_SetSysColor( i, RGB(r,g,b) );
920     }
921     if (hkey) RegCloseKey( hkey );
922
923     /* create 55AA bitmap */
924
925     h55AABitmap = CreateBitmap( 8, 8, 1, 1, wPattern55AA );
926     SYSCOLOR_55AABrush = CreatePatternBrush( h55AABitmap );
927     __wine_make_gdi_object_system( SYSCOLOR_55AABrush, TRUE );
928 }
929
930
931 /***********************************************************************
932  *              reg_get_logfont
933  *
934  *  Tries to retrieve logfont info from the specified key and value
935  */
936 static BOOL reg_get_logfont(LPCWSTR key, LPCWSTR value, LOGFONTW *lf)
937 {
938     HKEY hkey;
939     LOGFONTW lfbuf;
940     DWORD type, size;
941     BOOL found = FALSE;
942     HKEY base_keys[2];
943     int i;
944
945     base_keys[0] = get_volatile_regkey();
946     base_keys[1] = HKEY_CURRENT_USER;
947
948     for(i = 0; i < 2 && !found; i++)
949     {
950         if(RegOpenKeyW(base_keys[i], key, &hkey) == ERROR_SUCCESS)
951         {
952             size = sizeof(lfbuf);
953             if(RegQueryValueExW(hkey, value, NULL, &type, (LPBYTE)&lfbuf, &size) == ERROR_SUCCESS &&
954                     type == REG_BINARY)
955             {
956                 if( size == sizeof(lfbuf))
957                 {
958                     found = TRUE;
959                     memcpy(lf, &lfbuf, size);
960                 } else if( size == sizeof( LOGFONT16))
961                 {    /* win9x-winME format */
962                     found = TRUE;
963                     SYSPARAMS_LogFont16To32W( (LOGFONT16*) &lfbuf, lf);
964                 } else
965                     WARN("Unknown format in key %s value %s, size is %d\n",
966                             debugstr_w( key), debugstr_w( value), size);
967             }
968             RegCloseKey(hkey);
969         }
970     }
971     if( found && lf->lfHeight > 0) { 
972         /* positive height value means points ( inch/72 ) */
973         lf->lfHeight = -MulDiv( lf->lfHeight, get_display_dpi(), 72);
974     }
975     return found;
976 }
977
978 /* load all the minimized metrics */
979 static void load_minimized_metrics(void)
980 {
981     HKEY hkey;
982     if (RegOpenKeyExW (HKEY_CURRENT_USER, METRICS_REGKEY,
983                        0, KEY_QUERY_VALUE, &hkey) != ERROR_SUCCESS) hkey = 0;
984
985     minimized_metrics.iWidth = max( get_reg_metric(hkey,
986             METRICS_MINWIDTH_VALNAME, minimized_metrics.iWidth), 0);
987     minimized_metrics.iHorzGap = max( get_reg_metric(hkey,
988             METRICS_MINHORZGAP_VALNAME, minimized_metrics.iHorzGap), 0);
989     minimized_metrics.iVertGap = max( get_reg_metric(hkey,
990             METRICS_MINVERTGAP_VALNAME, minimized_metrics.iVertGap), 0);
991     minimized_metrics.iArrange = 0x0f & get_reg_metric(hkey,
992             METRICS_MINARRANGE_VALNAME, minimized_metrics.iArrange);
993
994     if (hkey) RegCloseKey( hkey );
995     spi_loaded[SPI_MINIMIZEDMETRICS_IDX] = TRUE;
996 }
997
998 /* adjust some of the raw values found in the registry */
999 static void normalize_nonclientmetrics( NONCLIENTMETRICSW *pncm)
1000 {
1001     TEXTMETRICW tm;
1002     if( pncm->iBorderWidth < 1) pncm->iBorderWidth = 1;
1003     if( pncm->iCaptionWidth < 8) pncm->iCaptionWidth = 8;
1004     if( pncm->iScrollWidth < 8) pncm->iScrollWidth = 8;
1005     if( pncm->iScrollHeight < 8) pncm->iScrollHeight = 8;
1006
1007     /* get some extra metrics */
1008     get_text_metr_size( get_display_dc(), &pncm->lfMenuFont,
1009             &tmMenuFont, NULL);
1010     get_text_metr_size( get_display_dc(), &pncm->lfCaptionFont,
1011             NULL, &CaptionFontAvCharWidth);
1012
1013     /* adjust some heights to the corresponding font */
1014     pncm->iMenuHeight = max( pncm->iMenuHeight,
1015             2 + tmMenuFont.tmHeight + tmMenuFont.tmExternalLeading);
1016     get_text_metr_size( get_display_dc(), &pncm->lfCaptionFont, &tm, NULL);
1017     pncm->iCaptionHeight = max( pncm->iCaptionHeight, 2 + tm.tmHeight);
1018     get_text_metr_size( get_display_dc(), &pncm->lfSmCaptionFont, &tm, NULL);
1019     pncm->iSmCaptionHeight = max( pncm->iSmCaptionHeight, 2 + tm.tmHeight);
1020 }
1021
1022 /* load all the non-client metrics */
1023 static void load_nonclient_metrics(void)
1024 {
1025     HKEY hkey;
1026     NONCLIENTMETRICSW ncm;
1027     INT r;
1028
1029     ncm.cbSize = sizeof (ncm);
1030     if (RegOpenKeyExW (HKEY_CURRENT_USER, METRICS_REGKEY,
1031                        0, KEY_QUERY_VALUE, &hkey) != ERROR_SUCCESS) hkey = 0;
1032
1033     /* initialize geometry entries */
1034     ncm.iBorderWidth =  get_reg_metric(hkey, METRICS_BORDERWIDTH_VALNAME, 1);
1035     ncm.iScrollWidth = get_reg_metric(hkey, METRICS_SCROLLWIDTH_VALNAME, 16);
1036     ncm.iScrollHeight = get_reg_metric(hkey, METRICS_SCROLLHEIGHT_VALNAME, 16);
1037
1038     /* size of the normal caption buttons */
1039     ncm.iCaptionHeight = get_reg_metric(hkey, METRICS_CAPTIONHEIGHT_VALNAME, 18);
1040     ncm.iCaptionWidth = get_reg_metric(hkey, METRICS_CAPTIONWIDTH_VALNAME, ncm.iCaptionHeight);
1041
1042     /* caption font metrics */
1043     if (!reg_get_logfont(METRICS_REGKEY, METRICS_CAPTIONLOGFONT_VALNAME, &ncm.lfCaptionFont))
1044     {
1045         SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &ncm.lfCaptionFont, 0 );
1046         ncm.lfCaptionFont.lfWeight = FW_BOLD;
1047     }
1048
1049     /* size of the small caption buttons */
1050     ncm.iSmCaptionWidth = get_reg_metric(hkey, METRICS_SMCAPTIONWIDTH_VALNAME, 13);
1051     ncm.iSmCaptionHeight = get_reg_metric(hkey, METRICS_SMCAPTIONHEIGHT_VALNAME, 15);
1052
1053     /* small caption font metrics */
1054     if (!reg_get_logfont(METRICS_REGKEY, METRICS_SMCAPTIONLOGFONT_VALNAME, &ncm.lfSmCaptionFont))
1055         SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &ncm.lfSmCaptionFont, 0 );
1056
1057     /* menus, FIXME: names of wine.conf entries are bogus */
1058
1059     /* size of the menu (MDI) buttons */
1060     ncm.iMenuHeight = get_reg_metric(hkey, METRICS_MENUHEIGHT_VALNAME, 18);
1061     ncm.iMenuWidth = get_reg_metric(hkey, METRICS_MENUWIDTH_VALNAME, ncm.iMenuHeight);
1062
1063     /* menu font metrics */
1064     if (!reg_get_logfont(METRICS_REGKEY, METRICS_MENULOGFONT_VALNAME, &ncm.lfMenuFont))
1065     {
1066         SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &ncm.lfMenuFont, 0 );
1067         GetProfileStringW( Desktop, MenuFont, ncm.lfCaptionFont.lfFaceName,
1068                            ncm.lfMenuFont.lfFaceName, LF_FACESIZE );
1069         r = GetProfileIntW( Desktop, MenuFontSize, 0 );
1070         if (r)
1071             ncm.lfMenuFont.lfHeight = -r;
1072         ncm.lfMenuFont.lfWeight = FW_NORMAL;
1073     }
1074
1075     /* status bar font metrics */
1076     if (!reg_get_logfont(METRICS_REGKEY, METRICS_STATUSLOGFONT_VALNAME, &ncm.lfStatusFont))
1077     {
1078         SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &ncm.lfStatusFont, 0 );
1079         GetProfileStringW( Desktop, StatusFont, ncm.lfCaptionFont.lfFaceName,
1080                            ncm.lfStatusFont.lfFaceName, LF_FACESIZE );
1081         r = GetProfileIntW( Desktop, StatusFontSize, 0 );
1082         if (r)
1083             ncm.lfStatusFont.lfHeight = -r;
1084         ncm.lfStatusFont.lfWeight = FW_NORMAL;
1085     }
1086
1087     /* message font metrics */
1088     if (!reg_get_logfont(METRICS_REGKEY, METRICS_MESSAGELOGFONT_VALNAME, &ncm.lfMessageFont))
1089     {
1090         SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0, &ncm.lfMessageFont, 0 );
1091         GetProfileStringW( Desktop, MessageFont, ncm.lfCaptionFont.lfFaceName,
1092                            ncm.lfMessageFont.lfFaceName, LF_FACESIZE );
1093         r = GetProfileIntW( Desktop, MessageFontSize, 0 );
1094         if (r)
1095             ncm.lfMessageFont.lfHeight = -r;
1096         ncm.lfMessageFont.lfWeight = FW_NORMAL;
1097     }
1098
1099     /* some extra fields not in the nonclient structure */
1100     icon_size.cx = icon_size.cy = get_reg_metric( hkey, METRICS_ICONSIZE_VALNAME, 32 );
1101
1102     if (hkey) RegCloseKey( hkey );
1103     normalize_nonclientmetrics( &ncm);
1104     memcpy( &nonclient_metrics, &ncm, sizeof(nonclient_metrics) );
1105     spi_loaded[SPI_NONCLIENTMETRICS_IDX] = TRUE;
1106 }
1107
1108
1109 /***********************************************************************
1110  *              SystemParametersInfoW (USER32.@)
1111  *
1112  *     Each system parameter has flag which shows whether the parameter
1113  * is loaded or not. Parameters, stored directly in SysParametersInfo are
1114  * loaded from registry only when they are requested and the flag is
1115  * "false", after the loading the flag is set to "true". On interprocess
1116  * notification of the parameter change the corresponding parameter flag is
1117  * set to "false". The parameter value will be reloaded when it is requested
1118  * the next time.
1119  *     Parameters, backed by or depend on GetSystemMetrics are processed
1120  * differently. These parameters are always loaded. They are reloaded right
1121  * away on interprocess change notification. We can't do lazy loading because
1122  * we don't want to complicate GetSystemMetrics.
1123  *     Parameters, backed by X settings are read from corresponding setting.
1124  * On the parameter change request the setting is changed. Interprocess change
1125  * notifications are ignored.
1126  *     When parameter value is updated the changed value is stored in permanent
1127  * registry branch if saving is requested. Otherwise it is stored
1128  * in temporary branch
1129  *
1130  * Some SPI values can also be stored as Twips values in the registry,
1131  * don't forget the conversion!
1132  */
1133 BOOL WINAPI SystemParametersInfoW( UINT uiAction, UINT uiParam,
1134                                    PVOID pvParam, UINT fWinIni )
1135 {
1136 #define WINE_SPI_FIXME(x) \
1137     case x: \
1138         FIXME( "Unimplemented action: %u (%s)\n", x, #x ); \
1139         SetLastError( ERROR_INVALID_SPI_VALUE ); \
1140         ret = FALSE; \
1141         break
1142 #define WINE_SPI_WARN(x) \
1143     case x: \
1144         WARN( "Ignored action: %u (%s)\n", x, #x ); \
1145         break
1146
1147     BOOL ret = TRUE;
1148     unsigned spi_idx = 0;
1149
1150     switch (uiAction)
1151     {
1152     case SPI_GETBEEP:                           /*      1 */
1153         if (!pvParam) return FALSE;
1154
1155         spi_idx = SPI_SETBEEP_IDX;
1156         if (!spi_loaded[spi_idx])
1157         {
1158             WCHAR buf[5];
1159
1160             if (SYSPARAMS_Load( SPI_SETBEEP_REGKEY, SPI_SETBEEP_VALNAME, buf, sizeof(buf) ))
1161                 beep_active  = !lstrcmpiW( Yes, buf );
1162             spi_loaded[spi_idx] = TRUE;
1163         }
1164
1165         *(BOOL *)pvParam = beep_active;
1166         break;
1167
1168     case SPI_SETBEEP:                           /*      2 */
1169         spi_idx = SPI_SETBEEP_IDX;
1170         if (SYSPARAMS_Save( SPI_SETBEEP_REGKEY, SPI_SETBEEP_VALNAME,
1171                             (uiParam ? Yes : No), fWinIni ))
1172         {
1173             beep_active = uiParam;
1174             spi_loaded[spi_idx] = TRUE;
1175         }
1176         else
1177             ret = FALSE;
1178         break;
1179
1180     case SPI_GETMOUSE:                          /*      3 */
1181         if (!pvParam) return FALSE;
1182
1183         spi_idx = SPI_SETMOUSE_IDX;
1184         if (!spi_loaded[spi_idx])
1185         {
1186             WCHAR buf[12];
1187
1188             if (SYSPARAMS_Load( SPI_SETMOUSE_REGKEY, SPI_SETMOUSE_VALNAME1,
1189                                 buf, sizeof(buf) ))
1190                 mouse_threshold1 = atoiW( buf );
1191             if (SYSPARAMS_Load( SPI_SETMOUSE_REGKEY, SPI_SETMOUSE_VALNAME2,
1192                                 buf, sizeof(buf) ))
1193                 mouse_threshold2 = atoiW( buf );
1194             if (SYSPARAMS_Load( SPI_SETMOUSE_REGKEY, SPI_SETMOUSE_VALNAME3,
1195                                 buf, sizeof(buf) ))
1196                 mouse_speed = atoiW( buf );
1197             spi_loaded[spi_idx] = TRUE;
1198         }
1199         ((INT *)pvParam)[0] = mouse_threshold1;
1200         ((INT *)pvParam)[1] = mouse_threshold2;
1201         ((INT *)pvParam)[2] = mouse_speed;
1202         break;
1203
1204     case SPI_SETMOUSE:                          /*      4 */
1205     {
1206         if (!pvParam) return FALSE;
1207         ret = set_int_param( SPI_SETMOUSE_IDX, SPI_SETMOUSE_REGKEY, SPI_SETMOUSE_VALNAME1,
1208                              &mouse_threshold1, ((INT *)pvParam)[0], fWinIni);
1209         if( ret) {
1210             save_int_param( SPI_SETMOUSE_REGKEY, SPI_SETMOUSE_VALNAME2,
1211                             &mouse_threshold2, ((INT *)pvParam)[1], fWinIni);
1212             save_int_param( SPI_SETMOUSE_REGKEY, SPI_SETMOUSE_VALNAME3,
1213                             &mouse_speed, ((INT *)pvParam)[2], fWinIni);
1214         }
1215         break;
1216     }
1217
1218     case SPI_GETBORDER:
1219         ret = get_twips_param( SPI_SETBORDER_IDX,
1220                                SPI_SETBORDER_REGKEY,
1221                                SPI_SETBORDER_VALNAME,
1222                                &border, pvParam );
1223         if( *(INT*)pvParam < 1) *(INT*)pvParam = 1; 
1224         break;
1225
1226     case SPI_SETBORDER:
1227         nonclient_metrics.iBorderWidth = uiParam > 0 ? uiParam : 1;
1228         /* raw value goes to registry */
1229         ret = set_uint_param( SPI_SETBORDER_IDX,
1230                               SPI_SETBORDER_REGKEY,
1231                               SPI_SETBORDER_VALNAME,
1232                               &border, uiParam, fWinIni );
1233         break;
1234
1235     case SPI_GETKEYBOARDSPEED:
1236         ret = get_uint_param( SPI_SETKEYBOARDSPEED_IDX,
1237                               SPI_SETKEYBOARDSPEED_REGKEY,
1238                               SPI_SETKEYBOARDSPEED_VALNAME,
1239                               &keyboard_speed, pvParam );
1240         break;
1241
1242     case SPI_SETKEYBOARDSPEED:
1243         if (uiParam > 31) uiParam = 31;
1244         ret = set_uint_param( SPI_SETKEYBOARDSPEED_IDX,
1245                               SPI_SETKEYBOARDSPEED_REGKEY,
1246                               SPI_SETKEYBOARDSPEED_VALNAME,
1247                               &keyboard_speed, uiParam, fWinIni );
1248         break;
1249
1250     /* not implemented in Windows */
1251     WINE_SPI_WARN(SPI_LANGDRIVER);              /*     12 */
1252
1253     case SPI_ICONHORIZONTALSPACING:
1254         if (pvParam != NULL)
1255         {
1256             ret = get_twips_param( SPI_ICONHORIZONTALSPACING_IDX,
1257                                    SPI_ICONHORIZONTALSPACING_REGKEY,
1258                                    SPI_ICONHORIZONTALSPACING_VALNAME,
1259                                    (UINT*)&icon_metrics.iHorzSpacing, pvParam );
1260         }
1261         else
1262         {
1263             if (uiParam < 32) uiParam = 32;
1264             ret = set_uint_param( SPI_ICONHORIZONTALSPACING_IDX,
1265                                   SPI_ICONHORIZONTALSPACING_REGKEY,
1266                                   SPI_ICONHORIZONTALSPACING_VALNAME,
1267                                   (UINT*)&icon_metrics.iHorzSpacing, uiParam, fWinIni );
1268         }
1269         break;
1270
1271     case SPI_GETSCREENSAVETIMEOUT:
1272         ret = get_uint_param( SPI_SETSCREENSAVETIMEOUT_IDX,
1273                               SPI_SETSCREENSAVETIMEOUT_REGKEY,
1274                               SPI_SETSCREENSAVETIMEOUT_VALNAME,
1275                               &screensave_timeout, pvParam );
1276         break;
1277
1278     case SPI_SETSCREENSAVETIMEOUT:
1279         ret = set_uint_param( SPI_SETSCREENSAVETIMEOUT_IDX,
1280                               SPI_SETSCREENSAVETIMEOUT_REGKEY,
1281                               SPI_SETSCREENSAVETIMEOUT_VALNAME,
1282                               &screensave_timeout, uiParam, fWinIni );
1283         break;
1284
1285     case SPI_GETSCREENSAVEACTIVE:               /*     16 */
1286         if (!pvParam) return FALSE;
1287         *(BOOL *)pvParam = USER_Driver->pGetScreenSaveActive();
1288         break;
1289
1290     case SPI_SETSCREENSAVEACTIVE:               /*     17 */
1291     {
1292         WCHAR buf[12];
1293
1294         wsprintfW(buf, CSu, uiParam);
1295         USER_Driver->pSetScreenSaveActive( uiParam );
1296         /* saved value does not affect Wine */
1297         SYSPARAMS_Save( SPI_SETSCREENSAVEACTIVE_REGKEY,
1298                         SPI_SETSCREENSAVEACTIVE_VALNAME,
1299                         buf, fWinIni );
1300         break;
1301     }
1302
1303     case SPI_GETGRIDGRANULARITY:
1304         ret = get_uint_param( SPI_SETGRIDGRANULARITY_IDX,
1305                               SPI_SETGRIDGRANULARITY_REGKEY,
1306                               SPI_SETGRIDGRANULARITY_VALNAME,
1307                               &grid_granularity, pvParam );
1308         break;
1309
1310     case SPI_SETGRIDGRANULARITY:
1311         ret = set_uint_param( SPI_SETGRIDGRANULARITY_IDX,
1312                               SPI_SETGRIDGRANULARITY_REGKEY,
1313                               SPI_SETGRIDGRANULARITY_VALNAME,
1314                               &grid_granularity, uiParam, fWinIni );
1315         break;
1316
1317     case SPI_SETDESKWALLPAPER:                  /*     20 */
1318         if (!pvParam || !SetDeskWallPaper( (LPSTR)pvParam )) return FALSE;
1319         SYSPARAMS_Save(SPI_SETDESKWALLPAPER_REGKEY, SPI_SETDESKWALLPAPER_VALNAME, pvParam, fWinIni);
1320         break;
1321         
1322     case SPI_SETDESKPATTERN:                    /*     21 */
1323         /* FIXME: the ability to specify a pattern in pvParam
1324            doesn't seem to be documented for Win32 */
1325         if ((INT16)uiParam == -1)
1326         {
1327             WCHAR buf[256];
1328             GetProfileStringW( Desktop, Pattern,
1329                                defPattern,
1330                                buf, sizeof(buf)/sizeof(WCHAR) );
1331             ret = DESKTOP_SetPattern( buf );
1332         } else
1333             ret = DESKTOP_SetPattern( (LPWSTR)pvParam );
1334         break;
1335
1336     case SPI_GETKEYBOARDDELAY:
1337         ret = get_uint_param( SPI_SETKEYBOARDDELAY_IDX,
1338                               SPI_SETKEYBOARDDELAY_REGKEY,
1339                               SPI_SETKEYBOARDDELAY_VALNAME,
1340                               &keyboard_delay, pvParam );
1341         break;
1342
1343     case SPI_SETKEYBOARDDELAY:
1344         ret = set_uint_param( SPI_SETKEYBOARDDELAY_IDX,
1345                               SPI_SETKEYBOARDDELAY_REGKEY,
1346                               SPI_SETKEYBOARDDELAY_VALNAME,
1347                               &keyboard_delay, uiParam, fWinIni );
1348         break;
1349
1350     case SPI_ICONVERTICALSPACING:
1351         if (pvParam != NULL)
1352         {
1353             ret = get_twips_param( SPI_ICONVERTICALSPACING_IDX,
1354                                    SPI_ICONVERTICALSPACING_REGKEY,
1355                                    SPI_ICONVERTICALSPACING_VALNAME,
1356                                    (UINT*)&icon_metrics.iVertSpacing, pvParam );
1357             if( icon_metrics.iVertSpacing < 32) 
1358                 icon_metrics.iVertSpacing = 32;
1359         }
1360         else
1361         {
1362             if (uiParam < 32) uiParam = 32;
1363             ret = set_uint_param( SPI_ICONVERTICALSPACING_IDX,
1364                                   SPI_ICONVERTICALSPACING_REGKEY,
1365                                   SPI_ICONVERTICALSPACING_VALNAME,
1366                                   (UINT*)&icon_metrics.iVertSpacing, uiParam, fWinIni );
1367         }
1368         break;
1369
1370     case SPI_GETICONTITLEWRAP:
1371         ret = get_bool_param( SPI_SETICONTITLEWRAP_IDX,
1372                               SPI_SETICONTITLEWRAP_REGKEY1,
1373                               SPI_SETICONTITLEWRAP_VALNAME,
1374                               &icon_metrics.iTitleWrap, pvParam );
1375         break;
1376
1377     case SPI_SETICONTITLEWRAP:
1378         ret = set_bool_param_mirrored( SPI_SETICONTITLEWRAP_IDX,
1379                                        SPI_SETICONTITLEWRAP_REGKEY1,
1380                                        SPI_SETICONTITLEWRAP_REGKEY2,
1381                                        SPI_SETICONTITLEWRAP_VALNAME,
1382                                        &icon_metrics.iTitleWrap, uiParam, fWinIni );
1383         break;
1384
1385     case SPI_GETMENUDROPALIGNMENT:
1386         ret = get_uint_param( SPI_SETMENUDROPALIGNMENT_IDX,
1387                               SPI_SETMENUDROPALIGNMENT_REGKEY1,
1388                               SPI_SETMENUDROPALIGNMENT_VALNAME,
1389                               &menu_drop_alignment, pvParam );
1390         break;
1391
1392     case SPI_SETMENUDROPALIGNMENT:
1393         ret = set_uint_param_mirrored( SPI_SETMENUDROPALIGNMENT_IDX,
1394                                        SPI_SETMENUDROPALIGNMENT_REGKEY1,
1395                                        SPI_SETMENUDROPALIGNMENT_REGKEY2,
1396                                        SPI_SETMENUDROPALIGNMENT_VALNAME,
1397                                        &menu_drop_alignment, uiParam, fWinIni );
1398         break;
1399
1400     case SPI_SETDOUBLECLKWIDTH:
1401         ret = set_uint_param_mirrored( SPI_SETDOUBLECLKWIDTH_IDX,
1402                                        SPI_SETDOUBLECLKWIDTH_REGKEY1,
1403                                        SPI_SETDOUBLECLKWIDTH_REGKEY2,
1404                                        SPI_SETDOUBLECLKWIDTH_VALNAME,
1405                                        &double_click_width, uiParam, fWinIni );
1406         break;
1407
1408     case SPI_SETDOUBLECLKHEIGHT:
1409         ret = set_uint_param_mirrored( SPI_SETDOUBLECLKHEIGHT_IDX,
1410                                        SPI_SETDOUBLECLKHEIGHT_REGKEY1,
1411                                        SPI_SETDOUBLECLKHEIGHT_REGKEY2,
1412                                        SPI_SETDOUBLECLKHEIGHT_VALNAME,
1413                                        &double_click_height, uiParam, fWinIni );
1414         break;
1415
1416     case SPI_GETICONTITLELOGFONT:
1417     {
1418         LOGFONTW lfDefault;
1419
1420         if (!pvParam) return FALSE;
1421
1422         spi_idx = SPI_SETICONTITLELOGFONT_IDX;
1423         if (!spi_loaded[spi_idx])
1424         {
1425             if (!reg_get_logfont( SPI_SETICONTITLELOGFONT_REGKEY,
1426                                   SPI_SETICONTITLELOGFONT_VALNAME, &icon_metrics.lfFont ))
1427             {
1428                 INT r;
1429
1430                 /*
1431                  * The 'default GDI fonts' seems to be returned.
1432                  * If a returned font is not a correct font in your environment,
1433                  * please try to fix objects/gdiobj.c at first.
1434                  */
1435                 GetObjectW( GetStockObject( DEFAULT_GUI_FONT ), sizeof(LOGFONTW), &lfDefault );
1436
1437                 GetProfileStringW( Desktop, IconTitleFaceName,
1438                                    lfDefault.lfFaceName,
1439                                    icon_metrics.lfFont.lfFaceName,
1440                                    LF_FACESIZE );
1441                 
1442                 r = GetProfileIntW( Desktop, IconTitleSize, 0 );
1443                 if (r)
1444                     icon_metrics.lfFont.lfHeight = -r;
1445                 else
1446                     icon_metrics.lfFont.lfHeight = lfDefault.lfHeight;
1447
1448                 icon_metrics.lfFont.lfWidth = 0;
1449                 icon_metrics.lfFont.lfEscapement = icon_metrics.lfFont.lfOrientation = 0;
1450                 icon_metrics.lfFont.lfWeight = FW_NORMAL;
1451                 icon_metrics.lfFont.lfItalic = FALSE;
1452                 icon_metrics.lfFont.lfStrikeOut = FALSE;
1453                 icon_metrics.lfFont.lfUnderline = FALSE;
1454                 icon_metrics.lfFont.lfCharSet = lfDefault.lfCharSet; /* at least 'charset' should not be hard-coded */
1455                 icon_metrics.lfFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
1456                 icon_metrics.lfFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
1457                 icon_metrics.lfFont.lfQuality = DEFAULT_QUALITY;
1458                 icon_metrics.lfFont.lfPitchAndFamily = DEFAULT_PITCH;
1459                 spi_loaded[spi_idx] = TRUE;
1460             }
1461         }
1462         *(LOGFONTW *)pvParam = icon_metrics.lfFont;
1463         break;
1464     }
1465
1466     case SPI_SETDOUBLECLICKTIME:
1467         ret = set_uint_param( SPI_SETDOUBLECLICKTIME_IDX,
1468                               SPI_SETDOUBLECLICKTIME_REGKEY,
1469                               SPI_SETDOUBLECLICKTIME_VALNAME,
1470                               &double_click_time, uiParam, fWinIni );
1471         break;
1472
1473     case SPI_SETMOUSEBUTTONSWAP:
1474         ret = set_bool_param( SPI_SETMOUSEBUTTONSWAP_IDX,
1475                               SPI_SETMOUSEBUTTONSWAP_REGKEY,
1476                               SPI_SETMOUSEBUTTONSWAP_VALNAME,
1477                               &swap_buttons, uiParam, fWinIni );
1478         break;
1479
1480     case SPI_SETICONTITLELOGFONT:               /*     34 */
1481         if( uiParam == sizeof(LOGFONTW)) {
1482             ret = SYSPARAMS_SaveLogFont( SPI_SETICONTITLELOGFONT_REGKEY,
1483                     SPI_SETICONTITLELOGFONT_VALNAME, (LOGFONTW *)pvParam, fWinIni);
1484             if( ret) {
1485                 icon_metrics.lfFont = *(LOGFONTW *)pvParam;
1486                 spi_loaded[SPI_SETICONTITLELOGFONT_IDX] = TRUE;
1487             }
1488         } else
1489             ret = FALSE;
1490         break;
1491
1492     case SPI_GETFASTTASKSWITCH:                 /*     35 */
1493         if (!pvParam) return FALSE;
1494         *(BOOL *)pvParam = 1;
1495         break;
1496
1497     case SPI_SETFASTTASKSWITCH:                 /*     36 */
1498         /* the action is disabled */
1499         ret = FALSE;
1500         break;
1501
1502     case SPI_SETDRAGFULLWINDOWS:
1503         ret = set_bool_param( SPI_SETDRAGFULLWINDOWS_IDX,
1504                               SPI_SETDRAGFULLWINDOWS_REGKEY,
1505                               SPI_SETDRAGFULLWINDOWS_VALNAME,
1506                               &drag_full_windows, uiParam, fWinIni );
1507         break;
1508
1509     case SPI_GETDRAGFULLWINDOWS:
1510         ret = get_bool_param( SPI_SETDRAGFULLWINDOWS_IDX,
1511                               SPI_SETDRAGFULLWINDOWS_REGKEY,
1512                               SPI_SETDRAGFULLWINDOWS_VALNAME,
1513                               &drag_full_windows, pvParam );
1514         break;
1515
1516     case SPI_GETNONCLIENTMETRICS:
1517     {
1518         LPNONCLIENTMETRICSW lpnm = pvParam;
1519
1520         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
1521
1522         if (lpnm && lpnm->cbSize == sizeof(NONCLIENTMETRICSW))
1523             memcpy( lpnm, &nonclient_metrics, sizeof(*lpnm) );
1524         else
1525             ret = FALSE;
1526         break;
1527     }
1528
1529     case SPI_SETNONCLIENTMETRICS:
1530     {
1531         LPNONCLIENTMETRICSW lpnm = pvParam;
1532
1533         if (lpnm && lpnm->cbSize == sizeof(NONCLIENTMETRICSW))
1534         {
1535             NONCLIENTMETRICSW ncm;
1536             ret = set_uint_param( SPI_SETBORDER_IDX,
1537                     SPI_SETBORDER_REGKEY, SPI_SETBORDER_VALNAME,
1538                     &border, lpnm->iBorderWidth, fWinIni );
1539             if( ret) ret = save_int_param( METRICS_REGKEY,
1540                     METRICS_SCROLLWIDTH_VALNAME, NULL,
1541                     lpnm->iScrollWidth, fWinIni );
1542             if( ret) ret = save_int_param( METRICS_REGKEY,
1543                     METRICS_SCROLLHEIGHT_VALNAME, NULL,
1544                     lpnm->iScrollHeight, fWinIni );
1545             if( ret) ret = save_int_param( METRICS_REGKEY,
1546                     METRICS_CAPTIONWIDTH_VALNAME, NULL,
1547                     lpnm->iCaptionWidth, fWinIni );
1548             if( ret) ret = save_int_param( METRICS_REGKEY,
1549                     METRICS_CAPTIONHEIGHT_VALNAME, NULL,
1550                     lpnm->iCaptionHeight, fWinIni );
1551             if( ret) ret = save_int_param( METRICS_REGKEY,
1552                     METRICS_SMCAPTIONWIDTH_VALNAME, NULL,
1553                     lpnm->iSmCaptionWidth, fWinIni );
1554             if( ret) ret = save_int_param( METRICS_REGKEY,
1555                     METRICS_SMCAPTIONHEIGHT_VALNAME, NULL,
1556                     lpnm->iSmCaptionHeight, fWinIni );
1557             if( ret) ret = save_int_param( METRICS_REGKEY,
1558                     METRICS_MENUWIDTH_VALNAME, NULL,
1559                     lpnm->iMenuWidth, fWinIni );
1560             if( ret) ret = save_int_param( METRICS_REGKEY,
1561                     METRICS_MENUHEIGHT_VALNAME, NULL,
1562                     lpnm->iMenuHeight, fWinIni );
1563             if( ret) ret = SYSPARAMS_SaveLogFont(
1564                     METRICS_REGKEY, METRICS_MENULOGFONT_VALNAME,
1565                     &lpnm->lfMenuFont, fWinIni);
1566             if( ret) ret = SYSPARAMS_SaveLogFont(
1567                     METRICS_REGKEY, METRICS_CAPTIONLOGFONT_VALNAME,
1568                     &lpnm->lfCaptionFont, fWinIni);
1569             if( ret) ret = SYSPARAMS_SaveLogFont(
1570                     METRICS_REGKEY, METRICS_SMCAPTIONLOGFONT_VALNAME,
1571                     &lpnm->lfSmCaptionFont, fWinIni);
1572             if( ret) ret = SYSPARAMS_SaveLogFont(
1573                     METRICS_REGKEY, METRICS_STATUSLOGFONT_VALNAME,
1574                     &lpnm->lfStatusFont, fWinIni);
1575             if( ret) ret = SYSPARAMS_SaveLogFont(
1576                     METRICS_REGKEY, METRICS_MESSAGELOGFONT_VALNAME,
1577                     &lpnm->lfMessageFont, fWinIni);
1578             if( ret) {
1579                 memcpy( &ncm, lpnm, sizeof(nonclient_metrics) );
1580                 normalize_nonclientmetrics( &ncm);
1581                 memcpy( &nonclient_metrics, &ncm, sizeof(nonclient_metrics) );
1582                 spi_loaded[SPI_NONCLIENTMETRICS_IDX] = TRUE;
1583             }
1584         }
1585         break;
1586     }
1587
1588     case SPI_GETMINIMIZEDMETRICS:
1589     {
1590         MINIMIZEDMETRICS * lpMm = pvParam;
1591         if (lpMm && lpMm->cbSize == sizeof(*lpMm)) {
1592             if( spi_loaded[SPI_MINIMIZEDMETRICS_IDX]) load_minimized_metrics();
1593             memcpy( lpMm, &minimized_metrics, sizeof(*lpMm) );
1594         } else
1595             ret = FALSE;
1596         break;
1597     }
1598
1599     case SPI_SETMINIMIZEDMETRICS:
1600     {
1601         MINIMIZEDMETRICS * lpMm = pvParam;
1602         if (lpMm && lpMm->cbSize == sizeof(*lpMm)) {
1603             ret = save_int_param( METRICS_REGKEY, METRICS_MINWIDTH_VALNAME,
1604                                   &minimized_metrics.iWidth, max( lpMm->iWidth, 0), fWinIni);
1605             if( ret) ret = save_int_param( METRICS_REGKEY,
1606                                            METRICS_MINHORZGAP_VALNAME, &minimized_metrics.iHorzGap,
1607                                            max( lpMm->iHorzGap, 0), fWinIni);
1608             if( ret) ret = save_int_param( METRICS_REGKEY,
1609                                            METRICS_MINVERTGAP_VALNAME, &minimized_metrics.iVertGap,
1610                                            max( lpMm->iVertGap, 0), fWinIni);
1611             if( ret) ret = save_int_param( METRICS_REGKEY,
1612                                            METRICS_MINARRANGE_VALNAME, &minimized_metrics.iArrange,
1613                                            0x0f & lpMm->iArrange, fWinIni);
1614             if( ret) spi_loaded[SPI_MINIMIZEDMETRICS_IDX] = TRUE;
1615         } else
1616             ret = FALSE;
1617         break;
1618     }
1619
1620     case SPI_GETICONMETRICS:
1621     {
1622         LPICONMETRICSW lpIcon = pvParam;
1623         if(lpIcon && lpIcon->cbSize == sizeof(*lpIcon))
1624         {
1625             SystemParametersInfoW( SPI_ICONHORIZONTALSPACING, 0,
1626                                    &lpIcon->iHorzSpacing, FALSE );
1627             SystemParametersInfoW( SPI_ICONVERTICALSPACING, 0,
1628                                    &lpIcon->iVertSpacing, FALSE );
1629             SystemParametersInfoW( SPI_GETICONTITLEWRAP, 0,
1630                                    &lpIcon->iTitleWrap, FALSE );
1631             SystemParametersInfoW( SPI_GETICONTITLELOGFONT, 0,
1632                                    &lpIcon->lfFont, FALSE );
1633         }
1634         else
1635         {
1636             ret = FALSE;
1637         }
1638         break;
1639     }
1640
1641     case SPI_SETICONMETRICS:
1642     {
1643         LPICONMETRICSW lpIcon = pvParam;
1644         if (lpIcon && lpIcon->cbSize == sizeof(*lpIcon)) {
1645             ret = set_int_param( SPI_ICONVERTICALSPACING_IDX,
1646                                  SPI_ICONVERTICALSPACING_REGKEY,
1647                                  SPI_ICONVERTICALSPACING_VALNAME,
1648                                  &icon_metrics.iVertSpacing,
1649                                  lpIcon->iVertSpacing, fWinIni);
1650             if( ret) {
1651                 ret = set_int_param( SPI_ICONHORIZONTALSPACING_IDX,
1652                                      SPI_ICONHORIZONTALSPACING_REGKEY,
1653                                      SPI_ICONHORIZONTALSPACING_VALNAME,
1654                                      &icon_metrics.iHorzSpacing,
1655                                      lpIcon->iHorzSpacing, fWinIni );
1656             }
1657             if( ret) {
1658                 ret = set_bool_param_mirrored( SPI_SETICONTITLEWRAP_IDX,
1659                     SPI_SETICONTITLEWRAP_REGKEY1, SPI_SETICONTITLEWRAP_REGKEY2,
1660                     SPI_SETICONTITLEWRAP_VALNAME, &icon_metrics.iTitleWrap,
1661                     lpIcon->iTitleWrap, fWinIni );
1662             }
1663             if( ret) ret = SYSPARAMS_SaveLogFont( SPI_SETICONTITLELOGFONT_REGKEY,
1664                     SPI_SETICONTITLELOGFONT_VALNAME, &lpIcon->lfFont, fWinIni);
1665             if( ret) {
1666                 icon_metrics.lfFont = lpIcon->lfFont;
1667                 spi_loaded[SPI_SETICONTITLELOGFONT_IDX] = TRUE;
1668             }
1669         } else
1670             ret = FALSE;
1671         break;
1672     }
1673
1674     case SPI_SETWORKAREA:                       /*     47  WINVER >= 0x400 */
1675     {
1676         if (!pvParam) return FALSE;
1677
1678         spi_idx = SPI_SETWORKAREA_IDX;
1679         CopyRect( &work_area, (RECT *)pvParam );
1680         spi_loaded[spi_idx] = TRUE;
1681         break;
1682     }
1683
1684     case SPI_GETWORKAREA:                       /*     48  WINVER >= 0x400 */
1685     {
1686         if (!pvParam) return FALSE;
1687
1688         spi_idx = SPI_SETWORKAREA_IDX;
1689         if (!spi_loaded[spi_idx])
1690         {
1691             SetRect( &work_area, 0, 0,
1692                      GetSystemMetrics( SM_CXSCREEN ),
1693                      GetSystemMetrics( SM_CYSCREEN ) );
1694             spi_loaded[spi_idx] = TRUE;
1695         }
1696         CopyRect( (RECT *)pvParam, &work_area );
1697
1698         break;
1699     }
1700
1701     WINE_SPI_FIXME(SPI_SETPENWINDOWS);          /*     49  WINVER >= 0x400 */
1702
1703     case SPI_GETFILTERKEYS:                     /*     50 */
1704     {
1705         LPFILTERKEYS lpFilterKeys = (LPFILTERKEYS)pvParam;
1706         WARN("SPI_GETFILTERKEYS not fully implemented\n");
1707         if (lpFilterKeys && lpFilterKeys->cbSize == sizeof(FILTERKEYS))
1708         {
1709             /* Indicate that no FilterKeys feature available */
1710             lpFilterKeys->dwFlags = 0;
1711             lpFilterKeys->iWaitMSec = 0;
1712             lpFilterKeys->iDelayMSec = 0;
1713             lpFilterKeys->iRepeatMSec = 0;
1714             lpFilterKeys->iBounceMSec = 0;
1715          }
1716         else
1717         {
1718             ret = FALSE;
1719         }
1720         break;
1721     }
1722     WINE_SPI_FIXME(SPI_SETFILTERKEYS);          /*     51 */
1723
1724     case SPI_GETTOGGLEKEYS:                     /*     52 */
1725     {
1726         LPTOGGLEKEYS lpToggleKeys = (LPTOGGLEKEYS)pvParam;
1727         WARN("SPI_GETTOGGLEKEYS not fully implemented\n");
1728         if (lpToggleKeys && lpToggleKeys->cbSize == sizeof(TOGGLEKEYS))
1729         {
1730             /* Indicate that no ToggleKeys feature available */
1731             lpToggleKeys->dwFlags = 0;
1732         }
1733         else
1734         {
1735             ret = FALSE;
1736         }
1737         break;
1738     }
1739     WINE_SPI_FIXME(SPI_SETTOGGLEKEYS);          /*     53 */
1740
1741     case SPI_GETMOUSEKEYS:                      /*     54 */
1742     {
1743         LPMOUSEKEYS lpMouseKeys = (LPMOUSEKEYS)pvParam;
1744         WARN("SPI_GETMOUSEKEYS not fully implemented\n");
1745         if (lpMouseKeys && lpMouseKeys->cbSize == sizeof(MOUSEKEYS))
1746         {
1747             /* Indicate that no MouseKeys feature available */
1748             lpMouseKeys->dwFlags = 0;
1749             lpMouseKeys->iMaxSpeed = 360;
1750             lpMouseKeys->iTimeToMaxSpeed = 1000;
1751             lpMouseKeys->iCtrlSpeed = 0;
1752             lpMouseKeys->dwReserved1 = 0;
1753             lpMouseKeys->dwReserved2 = 0;
1754         }
1755         else
1756         {
1757             ret = FALSE;
1758         }
1759         break;
1760     }
1761     WINE_SPI_FIXME(SPI_SETMOUSEKEYS);           /*     55 */
1762
1763     case SPI_GETSHOWSOUNDS:
1764         ret = get_bool_param( SPI_SETSHOWSOUNDS_IDX,
1765                               SPI_SETSHOWSOUNDS_REGKEY,
1766                               SPI_SETSHOWSOUNDS_VALNAME,
1767                               &show_sounds, pvParam );
1768         break;
1769
1770     case SPI_SETSHOWSOUNDS:
1771         ret = set_bool_param( SPI_SETSHOWSOUNDS_IDX,
1772                               SPI_SETSHOWSOUNDS_REGKEY,
1773                               SPI_SETSHOWSOUNDS_VALNAME,
1774                               &show_sounds, uiParam, fWinIni );
1775         break;
1776
1777     case SPI_GETSTICKYKEYS:                     /*     58 */
1778     {
1779         LPSTICKYKEYS lpStickyKeys = (LPSTICKYKEYS)pvParam;
1780         WARN("SPI_GETSTICKYKEYS not fully implemented\n");
1781         if (lpStickyKeys && lpStickyKeys->cbSize == sizeof(STICKYKEYS))
1782         {
1783             /* Indicate that no StickyKeys feature available */
1784             lpStickyKeys->dwFlags = 0;
1785         }
1786         else
1787         {
1788             ret = FALSE;
1789         }
1790         break;
1791     }
1792     WINE_SPI_FIXME(SPI_SETSTICKYKEYS);          /*     59 */
1793
1794     case SPI_GETACCESSTIMEOUT:                  /*     60 */
1795     {
1796         LPACCESSTIMEOUT lpAccessTimeout = (LPACCESSTIMEOUT)pvParam;
1797         WARN("SPI_GETACCESSTIMEOUT not fully implemented\n");
1798         if (lpAccessTimeout && lpAccessTimeout->cbSize == sizeof(ACCESSTIMEOUT))
1799         {
1800             /* Indicate that no accessibility features timeout is available */
1801             lpAccessTimeout->dwFlags = 0;
1802             lpAccessTimeout->iTimeOutMSec = 0;
1803         }
1804         else
1805         {
1806             ret = FALSE;
1807         }
1808         break;
1809     }
1810     WINE_SPI_FIXME(SPI_SETACCESSTIMEOUT);       /*     61 */
1811
1812     case SPI_GETSERIALKEYS:                     /*     62  WINVER >= 0x400 */
1813     {
1814         LPSERIALKEYSW lpSerialKeysW = (LPSERIALKEYSW)pvParam;
1815         WARN("SPI_GETSERIALKEYS not fully implemented\n");
1816         if (lpSerialKeysW && lpSerialKeysW->cbSize == sizeof(SERIALKEYSW))
1817         {
1818             /* Indicate that no SerialKeys feature available */
1819             lpSerialKeysW->dwFlags = 0;
1820             lpSerialKeysW->lpszActivePort = NULL;
1821             lpSerialKeysW->lpszPort = NULL;
1822             lpSerialKeysW->iBaudRate = 0;
1823             lpSerialKeysW->iPortState = 0;
1824         }
1825         else
1826         {
1827             ret = FALSE;
1828         }
1829         break;
1830     }
1831     WINE_SPI_FIXME(SPI_SETSERIALKEYS);          /*     63  WINVER >= 0x400 */
1832
1833     case SPI_GETSOUNDSENTRY:                    /*     64 */
1834     {
1835         LPSOUNDSENTRYW lpSoundSentryW = (LPSOUNDSENTRYW)pvParam;
1836         WARN("SPI_GETSOUNDSENTRY not fully implemented\n");
1837         if (lpSoundSentryW && lpSoundSentryW->cbSize == sizeof(SOUNDSENTRYW))
1838         {
1839             /* Indicate that no SoundSentry feature available */
1840             lpSoundSentryW->dwFlags = 0;
1841             lpSoundSentryW->iFSTextEffect = 0;
1842             lpSoundSentryW->iFSTextEffectMSec = 0;
1843             lpSoundSentryW->iFSTextEffectColorBits = 0;
1844             lpSoundSentryW->iFSGrafEffect = 0;
1845             lpSoundSentryW->iFSGrafEffectMSec = 0;
1846             lpSoundSentryW->iFSGrafEffectColor = 0;
1847             lpSoundSentryW->iWindowsEffect = 0;
1848             lpSoundSentryW->iWindowsEffectMSec = 0;
1849             lpSoundSentryW->lpszWindowsEffectDLL = 0;
1850             lpSoundSentryW->iWindowsEffectOrdinal = 0;
1851         }
1852         else
1853         {
1854             ret = FALSE;
1855         }
1856         break;
1857     }
1858     WINE_SPI_FIXME(SPI_SETSOUNDSENTRY);         /*     65 */
1859
1860     case SPI_GETHIGHCONTRAST:                   /*     66  WINVER >= 0x400 */
1861     {
1862         LPHIGHCONTRASTW lpHighContrastW = (LPHIGHCONTRASTW)pvParam;
1863         WARN("SPI_GETHIGHCONTRAST not fully implemented\n");
1864         if (lpHighContrastW && lpHighContrastW->cbSize == sizeof(HIGHCONTRASTW))
1865         {
1866             /* Indicate that no high contrast feature available */
1867             lpHighContrastW->dwFlags = 0;
1868             lpHighContrastW->lpszDefaultScheme = NULL;
1869         }
1870         else
1871         {
1872             ret = FALSE;
1873         }
1874         break;
1875     }
1876     WINE_SPI_FIXME(SPI_SETHIGHCONTRAST);        /*     67  WINVER >= 0x400 */
1877
1878     case SPI_GETKEYBOARDPREF:
1879         ret = get_bool_param( SPI_SETKEYBOARDPREF_IDX,
1880                               SPI_SETKEYBOARDPREF_REGKEY,
1881                               SPI_SETKEYBOARDPREF_VALNAME,
1882                               &keyboard_pref, pvParam );
1883         break;
1884
1885     case SPI_SETKEYBOARDPREF:
1886         ret = set_bool_param( SPI_SETKEYBOARDPREF_IDX,
1887                               SPI_SETKEYBOARDPREF_REGKEY,
1888                               SPI_SETKEYBOARDPREF_VALNAME,
1889                               &keyboard_pref, uiParam, fWinIni );
1890         break;
1891
1892     case SPI_GETSCREENREADER:
1893         ret = get_bool_param( SPI_SETSCREENREADER_IDX,
1894                               SPI_SETSCREENREADER_REGKEY,
1895                               SPI_SETSCREENREADER_VALNAME,
1896                               &screen_reader, pvParam );
1897         break;
1898
1899     case SPI_SETSCREENREADER:
1900         ret = set_bool_param( SPI_SETSCREENREADER_IDX,
1901                               SPI_SETSCREENREADER_REGKEY,
1902                               SPI_SETSCREENREADER_VALNAME,
1903                               &screen_reader, uiParam, fWinIni );
1904         break;
1905
1906     case SPI_GETANIMATION:                      /*     72  WINVER >= 0x400 */
1907     {
1908         LPANIMATIONINFO lpAnimInfo = (LPANIMATIONINFO)pvParam;
1909
1910         /* Tell it "disabled" */
1911         if (lpAnimInfo && lpAnimInfo->cbSize == sizeof(ANIMATIONINFO))
1912             lpAnimInfo->iMinAnimate = 0; /* Minimise and restore animation is disabled (nonzero == enabled) */
1913         else
1914             ret = FALSE;
1915         break;
1916     }
1917     WINE_SPI_WARN(SPI_SETANIMATION);            /*     73  WINVER >= 0x400 */
1918
1919     case SPI_GETFONTSMOOTHING:
1920     {
1921         UINT tmpval;
1922         ret = get_uint_param( SPI_SETFONTSMOOTHING_IDX,
1923                               SPI_SETFONTSMOOTHING_REGKEY,
1924                               SPI_SETFONTSMOOTHING_VALNAME,
1925                               &font_smoothing, &tmpval );
1926         *(UINT *) pvParam = ( tmpval != 0);
1927         break;
1928     }
1929     case SPI_SETFONTSMOOTHING:
1930         uiParam = uiParam ? 2 : 0; /* Win NT4/2k/XP behavior */
1931         ret = set_uint_param( SPI_SETFONTSMOOTHING_IDX,
1932                               SPI_SETFONTSMOOTHING_REGKEY,
1933                               SPI_SETFONTSMOOTHING_VALNAME,
1934                               &font_smoothing, uiParam, fWinIni );
1935         break;
1936
1937     WINE_SPI_FIXME(SPI_SETDRAGWIDTH);           /*     76  WINVER >= 0x400 */
1938     WINE_SPI_FIXME(SPI_SETDRAGHEIGHT);          /*     77  WINVER >= 0x400 */
1939
1940     WINE_SPI_FIXME(SPI_SETHANDHELD);            /*     78  WINVER >= 0x400 */
1941
1942     WINE_SPI_FIXME(SPI_GETLOWPOWERTIMEOUT);     /*     79  WINVER >= 0x400 */
1943     WINE_SPI_FIXME(SPI_GETPOWEROFFTIMEOUT);     /*     80  WINVER >= 0x400 */
1944     WINE_SPI_FIXME(SPI_SETLOWPOWERTIMEOUT);     /*     81  WINVER >= 0x400 */
1945     WINE_SPI_FIXME(SPI_SETPOWEROFFTIMEOUT);     /*     82  WINVER >= 0x400 */
1946
1947     case SPI_GETLOWPOWERACTIVE:
1948         ret = get_bool_param( SPI_SETLOWPOWERACTIVE_IDX,
1949                               SPI_SETLOWPOWERACTIVE_REGKEY,
1950                               SPI_SETLOWPOWERACTIVE_VALNAME,
1951                               &lowpoweractive, pvParam );
1952         break;
1953
1954     case SPI_GETPOWEROFFACTIVE:
1955         ret = get_bool_param( SPI_SETPOWEROFFACTIVE_IDX,
1956                               SPI_SETPOWEROFFACTIVE_REGKEY,
1957                               SPI_SETPOWEROFFACTIVE_VALNAME,
1958                               &poweroffactive, pvParam );
1959         break;
1960
1961     case SPI_SETLOWPOWERACTIVE:
1962         ret = set_bool_param( SPI_SETLOWPOWERACTIVE_IDX,
1963                               SPI_SETLOWPOWERACTIVE_REGKEY,
1964                               SPI_SETLOWPOWERACTIVE_VALNAME,
1965                               &lowpoweractive, uiParam, fWinIni );
1966         break;
1967
1968     case SPI_SETPOWEROFFACTIVE:
1969         ret = set_bool_param( SPI_SETPOWEROFFACTIVE_IDX,
1970                               SPI_SETPOWEROFFACTIVE_REGKEY,
1971                               SPI_SETPOWEROFFACTIVE_VALNAME,
1972                               &poweroffactive, uiParam, fWinIni );
1973         break;
1974
1975     WINE_SPI_FIXME(SPI_SETCURSORS);             /*     87  WINVER >= 0x400 */
1976     WINE_SPI_FIXME(SPI_SETICONS);               /*     88  WINVER >= 0x400 */
1977
1978     case SPI_GETDEFAULTINPUTLANG:       /*     89  WINVER >= 0x400 */
1979         ret = GetKeyboardLayout(0) ? TRUE : FALSE;
1980         break;
1981
1982     WINE_SPI_FIXME(SPI_SETDEFAULTINPUTLANG);    /*     90  WINVER >= 0x400 */
1983
1984     WINE_SPI_FIXME(SPI_SETLANGTOGGLE);          /*     91  WINVER >= 0x400 */
1985
1986     case SPI_GETWINDOWSEXTENSION:               /*     92  WINVER >= 0x400 */
1987         WARN("pretend no support for Win9x Plus! for now.\n");
1988         ret = FALSE; /* yes, this is the result value */
1989         break;
1990
1991     WINE_SPI_FIXME(SPI_SETMOUSETRAILS);         /*     93  WINVER >= 0x400 */
1992     WINE_SPI_FIXME(SPI_GETMOUSETRAILS);         /*     94  WINVER >= 0x400 */
1993     WINE_SPI_FIXME(SPI_GETSNAPTODEFBUTTON);     /*     95  WINVER >= 0x400 */
1994     WINE_SPI_FIXME(SPI_SETSNAPTODEFBUTTON);     /*     96  WINVER >= 0x400 */
1995
1996     case SPI_SETSCREENSAVERRUNNING:
1997         ret = set_bool_param( SPI_SETSCREENSAVERRUNNING_IDX,
1998                               SPI_SETSCREENSAVERRUNNING_REGKEY,
1999                               SPI_SETSCREENSAVERRUNNING_VALNAME,
2000                               &screensaver_running, uiParam, fWinIni );
2001         break;
2002
2003     case SPI_GETMOUSEHOVERWIDTH:
2004         ret = get_uint_param( SPI_SETMOUSEHOVERWIDTH_IDX,
2005                               SPI_SETMOUSEHOVERWIDTH_REGKEY,
2006                               SPI_SETMOUSEHOVERWIDTH_VALNAME,
2007                               &mouse_hover_width, pvParam );
2008         break;
2009
2010     case SPI_SETMOUSEHOVERWIDTH:
2011         ret = set_uint_param( SPI_SETMOUSEHOVERWIDTH_IDX,
2012                               SPI_SETMOUSEHOVERWIDTH_REGKEY,
2013                               SPI_SETMOUSEHOVERWIDTH_VALNAME,
2014                               &mouse_hover_width, uiParam, fWinIni );
2015         break;
2016
2017     case SPI_GETMOUSEHOVERHEIGHT:
2018         ret = get_uint_param( SPI_SETMOUSEHOVERHEIGHT_IDX,
2019                               SPI_SETMOUSEHOVERHEIGHT_REGKEY,
2020                               SPI_SETMOUSEHOVERHEIGHT_VALNAME,
2021                               &mouse_hover_height, pvParam );
2022         break;
2023
2024     case SPI_SETMOUSEHOVERHEIGHT:
2025         ret = set_uint_param( SPI_SETMOUSEHOVERHEIGHT_IDX,
2026                               SPI_SETMOUSEHOVERHEIGHT_REGKEY,
2027                               SPI_SETMOUSEHOVERHEIGHT_VALNAME,
2028                               &mouse_hover_height, uiParam, fWinIni );
2029         break;
2030
2031     case SPI_GETMOUSEHOVERTIME:
2032         ret = get_uint_param( SPI_SETMOUSEHOVERTIME_IDX,
2033                               SPI_SETMOUSEHOVERTIME_REGKEY,
2034                               SPI_SETMOUSEHOVERTIME_VALNAME,
2035                               &mouse_hover_time, pvParam );
2036         break;
2037
2038     case SPI_SETMOUSEHOVERTIME:
2039         ret = set_uint_param( SPI_SETMOUSEHOVERTIME_IDX,
2040                               SPI_SETMOUSEHOVERTIME_REGKEY,
2041                               SPI_SETMOUSEHOVERTIME_VALNAME,
2042                               &mouse_hover_time, uiParam, fWinIni );
2043         break;
2044
2045     case SPI_GETWHEELSCROLLLINES:
2046         ret = get_uint_param( SPI_SETMOUSESCROLLLINES_IDX,
2047                               SPI_SETMOUSESCROLLLINES_REGKEY,
2048                               SPI_SETMOUSESCROLLLINES_VALNAME,
2049                               &mouse_scroll_lines, pvParam );
2050         break;
2051
2052     case SPI_SETWHEELSCROLLLINES:
2053         ret = set_uint_param( SPI_SETMOUSESCROLLLINES_IDX,
2054                               SPI_SETMOUSESCROLLLINES_REGKEY,
2055                               SPI_SETMOUSESCROLLLINES_VALNAME,
2056                               &mouse_scroll_lines, uiParam, fWinIni );
2057         break;
2058
2059     case SPI_GETMENUSHOWDELAY:
2060         ret = get_uint_param( SPI_SETMENUSHOWDELAY_IDX,
2061                               SPI_SETMENUSHOWDELAY_REGKEY,
2062                               SPI_SETMENUSHOWDELAY_VALNAME,
2063                               &menu_show_delay, pvParam );
2064         break;
2065
2066     case SPI_SETMENUSHOWDELAY:
2067         ret = set_uint_param( SPI_SETMENUSHOWDELAY_IDX,
2068                               SPI_SETMENUSHOWDELAY_REGKEY,
2069                               SPI_SETMENUSHOWDELAY_VALNAME,
2070                               &menu_show_delay, uiParam, fWinIni );
2071         break;
2072
2073     WINE_SPI_FIXME(SPI_GETSHOWIMEUI);           /*    110  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
2074     WINE_SPI_FIXME(SPI_SETSHOWIMEUI);           /*    111  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
2075     WINE_SPI_FIXME(SPI_GETMOUSESPEED);          /*    112  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2076     WINE_SPI_FIXME(SPI_SETMOUSESPEED);          /*    113  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2077
2078     case SPI_GETSCREENSAVERRUNNING:
2079         ret = get_bool_param( SPI_SETSCREENSAVERRUNNING_IDX,
2080                               SPI_SETSCREENSAVERRUNNING_REGKEY,
2081                               SPI_SETSCREENSAVERRUNNING_VALNAME,
2082                               &screensaver_running, pvParam );
2083         break;
2084
2085     case SPI_GETDESKWALLPAPER:                  /*    115  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2086     {
2087         WCHAR buf[MAX_PATH];
2088
2089         if (!pvParam) return FALSE;
2090
2091         if (uiParam > MAX_PATH)
2092         {
2093             uiParam = MAX_PATH;
2094         }
2095
2096         if (SYSPARAMS_Load(SPI_SETDESKWALLPAPER_REGKEY, SPI_SETDESKWALLPAPER_VALNAME, buf, sizeof(buf)))
2097         {
2098             lstrcpynW((WCHAR*)pvParam, buf, uiParam);
2099         }
2100         else
2101         {
2102             /* Return an empty string */
2103             memset((WCHAR*)pvParam, 0, uiParam);
2104         }
2105
2106         break;
2107     }
2108
2109     WINE_SPI_FIXME(SPI_GETACTIVEWINDOWTRACKING);/* 0x1000  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2110     WINE_SPI_FIXME(SPI_SETACTIVEWINDOWTRACKING);/* 0x1001  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2111     case SPI_GETMENUANIMATION:             /* 0x1002  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2112         ret = get_user_pref_param( 0, 0x02, pvParam );
2113         break;
2114
2115     case SPI_SETMENUANIMATION:             /* 0x1003  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2116         ret = set_user_pref_param( 0, 0x02, (BOOL)pvParam, fWinIni );
2117         break;
2118
2119     case SPI_GETCOMBOBOXANIMATION:         /* 0x1004  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2120         ret = get_user_pref_param( 0, 0x04, pvParam );
2121         break;
2122
2123     case SPI_SETCOMBOBOXANIMATION:         /* 0x1005  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2124         ret = set_user_pref_param( 0, 0x04, (BOOL)pvParam, fWinIni );
2125         break;
2126
2127     case SPI_GETLISTBOXSMOOTHSCROLLING:    /* 0x1006  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2128         ret = get_user_pref_param( 0, 0x08, pvParam );
2129         break;
2130
2131     case SPI_SETLISTBOXSMOOTHSCROLLING:    /* 0x1007  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2132         ret = set_user_pref_param( 0, 0x08, (BOOL)pvParam, fWinIni );
2133         break;
2134
2135     case SPI_GETGRADIENTCAPTIONS:
2136         ret = get_user_pref_param( 0, 0x10, pvParam );
2137         break;
2138
2139     case SPI_SETGRADIENTCAPTIONS:
2140         ret = set_user_pref_param( 0, 0x10, (BOOL)pvParam, fWinIni );
2141         break;
2142
2143     case SPI_GETKEYBOARDCUES:
2144         ret = get_user_pref_param( 0, 0x20, pvParam );
2145         break;
2146
2147     case SPI_SETKEYBOARDCUES:
2148         ret = set_user_pref_param( 0, 0x20, (BOOL)pvParam, fWinIni );
2149         break;
2150
2151     WINE_SPI_FIXME(SPI_GETACTIVEWNDTRKZORDER);  /* 0x100C  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2152     WINE_SPI_FIXME(SPI_SETACTIVEWNDTRKZORDER);  /* 0x100D  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2153     case SPI_GETHOTTRACKING:
2154         ret = get_user_pref_param( 0, 0x80, pvParam );
2155         break;
2156
2157     case SPI_SETHOTTRACKING:
2158         ret = set_user_pref_param( 0, 0x80, (BOOL)pvParam, fWinIni );
2159         break;
2160
2161     WINE_SPI_FIXME(SPI_GETMENUFADE);            /* 0x1012  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2162     WINE_SPI_FIXME(SPI_SETMENUFADE);            /* 0x1013  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2163     case SPI_GETSELECTIONFADE:                  /* 0x1014  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2164         ret = get_user_pref_param( 1, 0x04, pvParam );
2165         break;
2166
2167     case SPI_SETSELECTIONFADE:                  /* 0x1015  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2168         ret = set_user_pref_param( 1, 0x04, (BOOL)pvParam, fWinIni );
2169         break;
2170
2171     case SPI_GETTOOLTIPANIMATION:               /* 0x1016  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2172         ret = get_user_pref_param( 1, 0x08, pvParam );
2173         break;
2174
2175     case SPI_SETTOOLTIPANIMATION:               /* 0x1017  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2176         ret = set_user_pref_param( 1, 0x08, (BOOL)pvParam, fWinIni );
2177         break;
2178
2179     case SPI_GETTOOLTIPFADE:                    /* 0x1018  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2180         ret = get_user_pref_param( 1, 0x10, pvParam );
2181         break;
2182
2183     case SPI_SETTOOLTIPFADE:                    /* 0x1019  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2184         ret = set_user_pref_param( 1, 0x10, (BOOL)pvParam, fWinIni );
2185         break;
2186
2187     case SPI_GETCURSORSHADOW:                   /* 0x101A  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2188         ret = get_user_pref_param( 1, 0x20, pvParam );
2189         break;
2190
2191     case SPI_SETCURSORSHADOW:                   /* 0x101B  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2192         ret = set_user_pref_param( 1, 0x20, (BOOL)pvParam, fWinIni );
2193         break;
2194
2195     WINE_SPI_FIXME(SPI_GETMOUSESONAR);          /* 0x101C  _WIN32_WINNT >= 0x510 || _WIN32_WINDOW >= 0x490*/
2196     WINE_SPI_FIXME(SPI_SETMOUSESONAR);          /* 0x101D  _WIN32_WINNT >= 0x510 || _WIN32_WINDOW >= 0x490*/
2197     WINE_SPI_FIXME(SPI_GETMOUSECLICKLOCK);      /* 0x101E  _WIN32_WINNT >= 0x510 || _WIN32_WINDOW >= 0x490*/
2198     WINE_SPI_FIXME(SPI_SETMOUSECLICKLOCK);      /* 0x101F  _WIN32_WINNT >= 0x510 || _WIN32_WINDOW >= 0x490*/
2199     WINE_SPI_FIXME(SPI_GETMOUSEVANISH);         /* 0x1020  _WIN32_WINNT >= 0x510 || _WIN32_WINDOW >= 0x490*/
2200     WINE_SPI_FIXME(SPI_SETMOUSEVANISH);         /* 0x1021  _WIN32_WINNT >= 0x510 || _WIN32_WINDOW >= 0x490*/
2201     case SPI_GETFLATMENU:
2202         ret = get_user_pref_param( 2, 0x02, pvParam );
2203         break;
2204
2205     case SPI_SETFLATMENU:
2206         ret = set_user_pref_param( 2, 0x02, (BOOL)pvParam, fWinIni );
2207         break;
2208
2209     WINE_SPI_FIXME(SPI_GETDROPSHADOW);          /* 0x1024  _WIN32_WINNT >= 0x510 */
2210     WINE_SPI_FIXME(SPI_SETDROPSHADOW);          /* 0x1025  _WIN32_WINNT >= 0x510 */
2211     WINE_SPI_FIXME(SPI_GETBLOCKSENDINPUTRESETS);
2212     WINE_SPI_FIXME(SPI_SETBLOCKSENDINPUTRESETS);
2213     case SPI_GETUIEFFECTS:
2214         ret = get_user_pref_param( 3, 0x80, pvParam );
2215         break;
2216
2217     case SPI_SETUIEFFECTS:
2218         /* FIXME: this probably should mask other UI effect values when unset */
2219         ret = set_user_pref_param( 3, 0x80, (BOOL)pvParam, fWinIni );
2220         break;
2221
2222     WINE_SPI_FIXME(SPI_GETFOREGROUNDLOCKTIMEOUT);/* 0x2000  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2223     WINE_SPI_FIXME(SPI_SETFOREGROUNDLOCKTIMEOUT);/* 0x2001  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2224     WINE_SPI_FIXME(SPI_GETACTIVEWNDTRKTIMEOUT); /* 0x2002  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2225     WINE_SPI_FIXME(SPI_SETACTIVEWNDTRKTIMEOUT); /* 0x2003  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2226     WINE_SPI_FIXME(SPI_GETFOREGROUNDFLASHCOUNT);/* 0x2004  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2227     WINE_SPI_FIXME(SPI_SETFOREGROUNDFLASHCOUNT);/* 0x2005  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2228     case SPI_GETCARETWIDTH:          /* 0x2006  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2229         ret = get_uint_param( SPI_CARETWIDTH_IDX,
2230                               SPI_CARETWIDTH_REGKEY,
2231                               SPI_CARETWIDTH_VALNAME,
2232                               &caret_width, pvParam );
2233         break;
2234
2235     case SPI_SETCARETWIDTH:          /* 0x2007  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2236         ret = set_uint_param( SPI_CARETWIDTH_IDX,
2237                               SPI_CARETWIDTH_REGKEY,
2238                               SPI_CARETWIDTH_VALNAME,
2239                               &caret_width, uiParam, fWinIni );
2240         break;
2241
2242     WINE_SPI_FIXME(SPI_GETMOUSECLICKLOCKTIME);  /* 0x2008  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2243     WINE_SPI_FIXME(SPI_SETMOUSECLICKLOCKTIME);  /* 0x2009  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2244     WINE_SPI_FIXME(SPI_GETFONTSMOOTHINGTYPE);   /* 0x200A  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2245     WINE_SPI_FIXME(SPI_SETFONTSMOOTHINGTYPE);   /* 0x200B  _WIN32_WINNT >= 0x500 || _WIN32_WINDOW > 0x400 */
2246     WINE_SPI_FIXME(SPI_GETFONTSMOOTHINGCONTRAST);/* 0x200C  _WIN32_WINNT >= 0x510 */
2247     WINE_SPI_FIXME(SPI_SETFONTSMOOTHINGCONTRAST);/* 0x200D  _WIN32_WINNT >= 0x510 */
2248     WINE_SPI_FIXME(SPI_GETFOCUSBORDERWIDTH);    /* 0x200E  _WIN32_WINNT >= 0x510 */
2249     WINE_SPI_FIXME(SPI_SETFOCUSBORDERWIDTH);    /* 0x200F  _WIN32_WINNT >= 0x510 */
2250     WINE_SPI_FIXME(SPI_GETFOCUSBORDERHEIGHT);    /* 0x2010  _WIN32_WINNT >= 0x510 */
2251     WINE_SPI_FIXME(SPI_SETFOCUSBORDERHEIGHT);    /* 0x2011  _WIN32_WINNT >= 0x510 */
2252
2253     default:
2254         FIXME( "Unknown action: %u\n", uiAction );
2255         SetLastError( ERROR_INVALID_SPI_VALUE );
2256         ret = FALSE;
2257         break;
2258     }
2259
2260     if (ret)
2261         SYSPARAMS_NotifyChange( uiAction, fWinIni );
2262     TRACE("(%u, %u, %p, %u) ret %d\n",
2263             uiAction, uiParam, pvParam, fWinIni, ret);
2264     return ret;
2265
2266 #undef WINE_SPI_FIXME
2267 #undef WINE_SPI_WARN
2268 }
2269
2270
2271 /***********************************************************************
2272  *              SystemParametersInfo (USER.483)
2273  */
2274 BOOL16 WINAPI SystemParametersInfo16( UINT16 uAction, UINT16 uParam,
2275                                       LPVOID lpvParam, UINT16 fuWinIni )
2276 {
2277     BOOL16 ret;
2278
2279     TRACE("(%u, %u, %p, %u)\n", uAction, uParam, lpvParam, fuWinIni);
2280
2281     switch (uAction)
2282     {
2283     case SPI_GETBEEP:                           /*      1 */
2284     case SPI_GETSCREENSAVEACTIVE:               /*     16 */
2285     case SPI_GETICONTITLEWRAP:                  /*     25 */
2286     case SPI_GETMENUDROPALIGNMENT:              /*     27 */
2287     case SPI_GETFASTTASKSWITCH:                 /*     35 */
2288     case SPI_GETDRAGFULLWINDOWS:                /*     38  WINVER >= 0x0400 */
2289     {
2290         BOOL tmp;
2291         ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
2292         if (ret && lpvParam)
2293             *(BOOL16 *)lpvParam = tmp;
2294         break;
2295     }
2296
2297     case SPI_GETBORDER:                         /*      5 */
2298     case SPI_ICONHORIZONTALSPACING:             /*     13 */
2299     case SPI_GETSCREENSAVETIMEOUT:              /*     14 */
2300     case SPI_GETGRIDGRANULARITY:                /*     18 */
2301     case SPI_GETKEYBOARDDELAY:                  /*     22 */
2302     case SPI_ICONVERTICALSPACING:               /*     24 */
2303     {
2304         INT tmp;
2305         ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
2306         if (ret && lpvParam)
2307             *(INT16 *)lpvParam = tmp;
2308         break;
2309     }
2310
2311     case SPI_GETKEYBOARDSPEED:                  /*     10 */
2312     {
2313         DWORD tmp;
2314         ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
2315         if (ret && lpvParam)
2316             *(WORD *)lpvParam = tmp;
2317         break;
2318     }
2319
2320     case SPI_GETICONTITLELOGFONT:               /*     31 */
2321     {
2322         LOGFONTA tmp;
2323         ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
2324         if (ret && lpvParam)
2325             SYSPARAMS_LogFont32ATo16( &tmp, (LPLOGFONT16)lpvParam );
2326         break;
2327     }
2328
2329     case SPI_GETNONCLIENTMETRICS:               /*     41  WINVER >= 0x400 */
2330     {
2331         NONCLIENTMETRICSA tmp;
2332         LPNONCLIENTMETRICS16 lpnm16 = (LPNONCLIENTMETRICS16)lpvParam;
2333         if (lpnm16 && lpnm16->cbSize == sizeof(NONCLIENTMETRICS16))
2334         {
2335             tmp.cbSize = sizeof(NONCLIENTMETRICSA);
2336             ret = SystemParametersInfoA( uAction, uParam, &tmp, fuWinIni );
2337             if (ret)
2338                 SYSPARAMS_NonClientMetrics32ATo16( &tmp, lpnm16 );
2339         }
2340         else /* winfile 95 sets cbSize to 340 */
2341             ret = SystemParametersInfoA( uAction, uParam, lpvParam, fuWinIni );
2342         break;
2343     }
2344
2345     case SPI_GETWORKAREA:                       /*     48  WINVER >= 0x400 */
2346     {
2347         RECT tmp;
2348         ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
2349         if (ret && lpvParam)
2350         {
2351             RECT16 *r16 = (RECT16 *)lpvParam;
2352             r16->left   = tmp.left;
2353             r16->top    = tmp.top;
2354             r16->right  = tmp.right;
2355             r16->bottom = tmp.bottom;
2356         }
2357         break;
2358     }
2359
2360     case SPI_GETMOUSEHOVERWIDTH:                /*     98  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
2361     case SPI_GETMOUSEHOVERHEIGHT:               /*    100  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
2362     case SPI_GETMOUSEHOVERTIME:                 /*    102  _WIN32_WINNT >= 0x400 || _WIN32_WINDOW > 0x400 */
2363     {
2364         UINT tmp;
2365         ret = SystemParametersInfoA( uAction, uParam, lpvParam ? &tmp : NULL, fuWinIni );
2366         if (ret && lpvParam)
2367             *(UINT16 *)lpvParam = tmp;
2368         break;
2369     }
2370
2371     default:
2372         ret = SystemParametersInfoA( uAction, uParam, lpvParam, fuWinIni );
2373     }
2374
2375     return ret;
2376 }
2377
2378 /***********************************************************************
2379  *              SystemParametersInfoA (USER32.@)
2380  */
2381 BOOL WINAPI SystemParametersInfoA( UINT uiAction, UINT uiParam,
2382                                    PVOID pvParam, UINT fuWinIni )
2383 {
2384     BOOL ret;
2385
2386     TRACE("(%u, %u, %p, %u)\n", uiAction, uiParam, pvParam, fuWinIni);
2387
2388     switch (uiAction)
2389     {
2390     case SPI_SETDESKWALLPAPER:                  /*     20 */
2391     case SPI_SETDESKPATTERN:                    /*     21 */
2392     {
2393         WCHAR buffer[256];
2394         if (pvParam)
2395             if (!MultiByteToWideChar( CP_ACP, 0, (LPSTR)pvParam, -1,
2396                                       buffer, sizeof(buffer)/sizeof(WCHAR) ))
2397                 buffer[sizeof(buffer)/sizeof(WCHAR)-1] = 0;
2398         ret = SystemParametersInfoW( uiAction, uiParam, pvParam ? buffer : NULL, fuWinIni );
2399         break;
2400     }
2401
2402     case SPI_GETICONTITLELOGFONT:               /*     31 */
2403     {
2404         LOGFONTW tmp;
2405         ret = SystemParametersInfoW( uiAction, uiParam, pvParam ? &tmp : NULL, fuWinIni );
2406         if (ret && pvParam)
2407             SYSPARAMS_LogFont32WTo32A( &tmp, (LPLOGFONTA)pvParam );
2408         break;
2409     }
2410
2411     case SPI_GETNONCLIENTMETRICS:               /*     41  WINVER >= 0x400 */
2412     {
2413         NONCLIENTMETRICSW tmp;
2414         LPNONCLIENTMETRICSA lpnmA = (LPNONCLIENTMETRICSA)pvParam;
2415         if (lpnmA && lpnmA->cbSize == sizeof(NONCLIENTMETRICSA))
2416         {
2417             tmp.cbSize = sizeof(NONCLIENTMETRICSW);
2418             ret = SystemParametersInfoW( uiAction, uiParam, &tmp, fuWinIni );
2419             if (ret)
2420                 SYSPARAMS_NonClientMetrics32WTo32A( &tmp, lpnmA );
2421         }
2422         else
2423             ret = FALSE;
2424         break;
2425     }
2426
2427     case SPI_SETNONCLIENTMETRICS:               /*     42  WINVER >= 0x400 */
2428     {
2429         NONCLIENTMETRICSW tmp;
2430         LPNONCLIENTMETRICSA lpnmA = (LPNONCLIENTMETRICSA)pvParam;
2431         if (lpnmA && lpnmA->cbSize == sizeof(NONCLIENTMETRICSA))
2432         {
2433             tmp.cbSize = sizeof(NONCLIENTMETRICSW);
2434             SYSPARAMS_NonClientMetrics32ATo32W( lpnmA, &tmp );
2435             ret = SystemParametersInfoW( uiAction, uiParam, &tmp, fuWinIni );
2436         }
2437         else
2438             ret = FALSE;
2439         break;
2440     }
2441
2442     case SPI_GETICONMETRICS:                    /*     45  WINVER >= 0x400 */
2443     {
2444         ICONMETRICSW tmp;
2445         LPICONMETRICSA lpimA = (LPICONMETRICSA)pvParam;
2446         if (lpimA && lpimA->cbSize == sizeof(ICONMETRICSA))
2447         {
2448             tmp.cbSize = sizeof(ICONMETRICSW);
2449             ret = SystemParametersInfoW( uiAction, uiParam, &tmp, fuWinIni );
2450             if (ret)
2451             {
2452                 lpimA->iHorzSpacing = tmp.iHorzSpacing;
2453                 lpimA->iVertSpacing = tmp.iVertSpacing;
2454                 lpimA->iTitleWrap   = tmp.iTitleWrap;
2455                 SYSPARAMS_LogFont32WTo32A( &tmp.lfFont, &lpimA->lfFont );
2456             }
2457         }
2458         else
2459             ret = FALSE;
2460         break;
2461     }
2462
2463     case SPI_SETICONMETRICS:                    /*     46  WINVER >= 0x400 */
2464     {
2465         ICONMETRICSW tmp;
2466         LPICONMETRICSA lpimA = (LPICONMETRICSA)pvParam;
2467         if (lpimA && lpimA->cbSize == sizeof(ICONMETRICSA))
2468         {
2469             tmp.cbSize = sizeof(ICONMETRICSW);
2470             tmp.iHorzSpacing = lpimA->iHorzSpacing;
2471             tmp.iVertSpacing = lpimA->iVertSpacing;
2472             tmp.iTitleWrap = lpimA->iTitleWrap;
2473             SYSPARAMS_LogFont32ATo32W(  &lpimA->lfFont, &tmp.lfFont);
2474             ret = SystemParametersInfoW( uiAction, uiParam, &tmp, fuWinIni );
2475         }
2476         else
2477             ret = FALSE;
2478         break;
2479     }
2480
2481     case SPI_GETHIGHCONTRAST:                   /*     66  WINVER >= 0x400 */
2482     {
2483         HIGHCONTRASTW tmp;
2484         LPHIGHCONTRASTA lphcA = (LPHIGHCONTRASTA)pvParam;
2485         if (lphcA && lphcA->cbSize == sizeof(HIGHCONTRASTA))
2486         {
2487             tmp.cbSize = sizeof(HIGHCONTRASTW);
2488             ret = SystemParametersInfoW( uiAction, uiParam, &tmp, fuWinIni );
2489             if (ret)
2490             {
2491                 lphcA->dwFlags = tmp.dwFlags;
2492                 lphcA->lpszDefaultScheme = NULL;  /* FIXME? */
2493             }
2494         }
2495         else
2496             ret = FALSE;
2497         break;
2498     }
2499
2500     case SPI_GETDESKWALLPAPER:                  /*     115 */
2501     {
2502         WCHAR buffer[MAX_PATH];
2503         ret = (SystemParametersInfoW( SPI_GETDESKWALLPAPER, uiParam, buffer, fuWinIni ) &&
2504                WideCharToMultiByte(CP_ACP, 0, buffer, -1, pvParam, uiParam, NULL, NULL));
2505         break;
2506     }
2507
2508     default:
2509         ret = SystemParametersInfoW( uiAction, uiParam, pvParam, fuWinIni );
2510         break;
2511     }
2512     return ret;
2513 }
2514
2515
2516 /***********************************************************************
2517  *              GetSystemMetrics (USER32.@)
2518  */
2519 INT WINAPI GetSystemMetrics( INT index )
2520 {
2521     UINT ret;
2522
2523     /* some metrics are dynamic */
2524     switch (index)
2525     {
2526     case SM_CXSCREEN:
2527         return GetDeviceCaps( get_display_dc(), HORZRES );
2528     case SM_CYSCREEN:
2529         return GetDeviceCaps( get_display_dc(), VERTRES );
2530     case SM_CXVSCROLL:
2531         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2532         return nonclient_metrics.iScrollWidth;
2533     case SM_CYHSCROLL:
2534         return GetSystemMetrics(SM_CXVSCROLL);
2535     case SM_CYCAPTION:
2536         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2537         return nonclient_metrics.iCaptionHeight + 1;
2538     case SM_CXBORDER:
2539     case SM_CYBORDER:
2540         /* SM_C{X,Y}BORDER always returns 1 regardless of 'BorderWidth' value in registry */
2541         return 1;
2542     case SM_CXDLGFRAME:
2543     case SM_CYDLGFRAME:
2544         return 3;
2545     case SM_CYVTHUMB:
2546         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2547         return nonclient_metrics.iScrollHeight;
2548     case SM_CXHTHUMB:
2549         return GetSystemMetrics(SM_CYVTHUMB);
2550     case SM_CXICON:
2551         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2552         return icon_size.cx;
2553     case SM_CYICON:
2554         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2555         return icon_size.cy;
2556     case SM_CXCURSOR:
2557     case SM_CYCURSOR:
2558         return 32;
2559     case SM_CYMENU:
2560         return GetSystemMetrics(SM_CYMENUSIZE) + 1;
2561     case SM_CXFULLSCREEN:
2562         /* see the remark for SM_CXMAXIMIZED, at least this formulation is
2563          * correct */
2564         return GetSystemMetrics( SM_CXMAXIMIZED) - 2 * GetSystemMetrics( SM_CXFRAME);
2565     case SM_CYFULLSCREEN:
2566         /* see the remark for SM_CYMAXIMIZED, at least this formulation is
2567          * correct */
2568         return GetSystemMetrics( SM_CYMAXIMIZED) - GetSystemMetrics( SM_CYMIN);
2569     case SM_CYKANJIWINDOW:
2570         return 0;
2571     case SM_MOUSEPRESENT:
2572         return 1;
2573     case SM_CYVSCROLL:
2574         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2575         return nonclient_metrics.iScrollHeight;
2576     case SM_CXHSCROLL:
2577         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2578         return nonclient_metrics.iScrollHeight;
2579     case SM_DEBUG:
2580         return 0;
2581     case SM_SWAPBUTTON:
2582         get_bool_param( SPI_SETMOUSEBUTTONSWAP_IDX, SPI_SETMOUSEBUTTONSWAP_REGKEY,
2583                         SPI_SETMOUSEBUTTONSWAP_VALNAME, &swap_buttons, (BOOL*)&ret );
2584         return ret;
2585     case SM_RESERVED1:
2586     case SM_RESERVED2:
2587     case SM_RESERVED3:
2588     case SM_RESERVED4:
2589         return 0;
2590     case SM_CXMIN:
2591         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2592         return 3 * nonclient_metrics.iCaptionWidth + GetSystemMetrics( SM_CYSIZE) +
2593             4 * CaptionFontAvCharWidth + 2 * GetSystemMetrics( SM_CXFRAME) + 4;
2594     case SM_CYMIN:
2595         return GetSystemMetrics( SM_CYCAPTION) + 2 * GetSystemMetrics( SM_CYFRAME);
2596     case SM_CXSIZE:
2597         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2598         return nonclient_metrics.iCaptionWidth;
2599     case SM_CYSIZE:
2600         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2601         return nonclient_metrics.iCaptionHeight;
2602     case SM_CXFRAME:
2603         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2604         return GetSystemMetrics(SM_CXDLGFRAME) + nonclient_metrics.iBorderWidth;
2605     case SM_CYFRAME:
2606         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2607         return GetSystemMetrics(SM_CYDLGFRAME) + nonclient_metrics.iBorderWidth;
2608     case SM_CXMINTRACK:
2609         return GetSystemMetrics(SM_CXMIN);
2610     case SM_CYMINTRACK:
2611         return GetSystemMetrics(SM_CYMIN);
2612     case SM_CXDOUBLECLK:
2613         get_uint_param( SPI_SETDOUBLECLKWIDTH_IDX, SPI_SETDOUBLECLKWIDTH_REGKEY1,
2614                         SPI_SETDOUBLECLKWIDTH_VALNAME, &double_click_width, &ret );
2615         return ret;
2616     case SM_CYDOUBLECLK:
2617         get_uint_param( SPI_SETDOUBLECLKHEIGHT_IDX, SPI_SETDOUBLECLKHEIGHT_REGKEY1,
2618                         SPI_SETDOUBLECLKHEIGHT_VALNAME, &double_click_height, &ret );
2619         return ret;
2620     case SM_CXICONSPACING:
2621         SystemParametersInfoW( SPI_ICONHORIZONTALSPACING, 0, &ret, 0 );
2622         return ret;
2623     case SM_CYICONSPACING:
2624         SystemParametersInfoW( SPI_ICONVERTICALSPACING, 0, &ret, 0 );
2625         return ret;
2626     case SM_MENUDROPALIGNMENT:
2627         SystemParametersInfoW( SPI_GETMENUDROPALIGNMENT, 0, &ret, 0 );
2628         return ret;
2629     case SM_PENWINDOWS:
2630         return 0;
2631     case SM_DBCSENABLED:
2632     {
2633         CPINFO cpinfo;
2634         GetCPInfo( CP_ACP, &cpinfo );
2635         return (cpinfo.MaxCharSize > 1);
2636     }
2637     case SM_CMOUSEBUTTONS:
2638         return 3;
2639     case SM_SECURE:
2640         return 0;
2641     case SM_CXEDGE:
2642         return GetSystemMetrics(SM_CXBORDER) + 1;
2643     case SM_CYEDGE:
2644         return GetSystemMetrics(SM_CYBORDER) + 1;
2645     case SM_CXMINSPACING:
2646         if( spi_loaded[SPI_MINIMIZEDMETRICS_IDX]) load_minimized_metrics();
2647         return GetSystemMetrics(SM_CXMINIMIZED) + minimized_metrics.iHorzGap;
2648     case SM_CYMINSPACING:
2649         if( spi_loaded[SPI_MINIMIZEDMETRICS_IDX]) load_minimized_metrics();
2650         return GetSystemMetrics(SM_CYMINIMIZED) + minimized_metrics.iVertGap;
2651     case SM_CXSMICON:
2652     case SM_CYSMICON:
2653         return 16;
2654     case SM_CYSMCAPTION:
2655         return GetSystemMetrics(SM_CYSMSIZE) + 1;
2656     case SM_CXSMSIZE:
2657         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2658         return nonclient_metrics.iSmCaptionWidth;
2659     case SM_CYSMSIZE:
2660         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2661         return nonclient_metrics.iSmCaptionHeight;
2662     case SM_CXMENUSIZE:
2663         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2664         return nonclient_metrics.iMenuWidth;
2665     case SM_CYMENUSIZE:
2666         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2667         return nonclient_metrics.iMenuHeight;
2668     case SM_ARRANGE:
2669         if( spi_loaded[SPI_MINIMIZEDMETRICS_IDX]) load_minimized_metrics();
2670         return minimized_metrics.iArrange;
2671     case SM_CXMINIMIZED:
2672         if( spi_loaded[SPI_MINIMIZEDMETRICS_IDX]) load_minimized_metrics();
2673         return minimized_metrics.iWidth + 6;
2674     case SM_CYMINIMIZED:
2675         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2676         return nonclient_metrics.iCaptionHeight + 6;
2677     case SM_CXMAXTRACK:
2678         return GetSystemMetrics(SM_CXSCREEN) + 4 + 2 * GetSystemMetrics(SM_CXFRAME);
2679     case SM_CYMAXTRACK:
2680         return GetSystemMetrics(SM_CYSCREEN) + 4 + 2 * GetSystemMetrics(SM_CYFRAME);
2681     case SM_CXMAXIMIZED:
2682         /* FIXME: subtract the width of any vertical application toolbars*/
2683         return GetSystemMetrics(SM_CXSCREEN) + 2 * GetSystemMetrics(SM_CXFRAME);
2684     case SM_CYMAXIMIZED:
2685         /* FIXME: subtract the width of any horizontal application toolbars*/
2686         return GetSystemMetrics(SM_CYSCREEN) + 2 * GetSystemMetrics(SM_CYCAPTION);
2687     case SM_NETWORK:
2688         return 3;  /* FIXME */
2689     case SM_CLEANBOOT:
2690         return 0; /* 0 = ok, 1 = failsafe, 2 = failsafe + network */
2691     case SM_CXDRAG:
2692     case SM_CYDRAG:
2693         return 4;
2694     case SM_SHOWSOUNDS:
2695         SystemParametersInfoW( SPI_GETSHOWSOUNDS, 0, &ret, 0 );
2696         return ret;
2697     case SM_CXMENUCHECK:
2698     case SM_CYMENUCHECK:
2699         if (!spi_loaded[SPI_NONCLIENTMETRICS_IDX]) load_nonclient_metrics();
2700         return tmMenuFont.tmHeight <= 0 ? 13 :
2701         ((tmMenuFont.tmHeight + tmMenuFont.tmExternalLeading + 1) / 2) * 2 - 1;
2702     case SM_SLOWMACHINE:
2703         return 0;  /* FIXME: Should check the type of processor */
2704     case SM_MIDEASTENABLED:
2705         return 0;  /* FIXME */
2706     case SM_MOUSEWHEELPRESENT:
2707         return 1;
2708     case SM_XVIRTUALSCREEN:
2709     case SM_YVIRTUALSCREEN:
2710         return 0;
2711     case SM_CXVIRTUALSCREEN:
2712         return GetSystemMetrics(SM_CXSCREEN);
2713     case SM_CYVIRTUALSCREEN:
2714         return GetSystemMetrics(SM_CYSCREEN);
2715     case SM_CMONITORS:
2716         return 1;
2717     case SM_SAMEDISPLAYFORMAT:
2718         return 1;
2719     case SM_IMMENABLED:
2720         return 0;  /* FIXME */
2721     case SM_CXFOCUSBORDER:
2722     case SM_CYFOCUSBORDER:
2723         return 1;
2724     case SM_TABLETPC:
2725     case SM_MEDIACENTER:
2726         return 0;
2727     case SM_CMETRICS:
2728         return SM_CMETRICS;
2729     default:
2730         return 0;
2731     }
2732 }
2733
2734
2735 /***********************************************************************
2736  *              SwapMouseButton (USER32.@)
2737  *  Reverse or restore the meaning of the left and right mouse buttons
2738  *  fSwap  [I ] TRUE - reverse, FALSE - original
2739  * RETURN
2740  *   previous state 
2741  */
2742 BOOL WINAPI SwapMouseButton( BOOL fSwap )
2743 {
2744     BOOL prev = GetSystemMetrics(SM_SWAPBUTTON);
2745     SystemParametersInfoW(SPI_SETMOUSEBUTTONSWAP, fSwap, 0, 0);
2746     return prev;
2747 }
2748
2749
2750 /**********************************************************************
2751  *              SetDoubleClickTime (USER32.@)
2752  */
2753 BOOL WINAPI SetDoubleClickTime( UINT interval )
2754 {
2755     return SystemParametersInfoW(SPI_SETDOUBLECLICKTIME, interval, 0, 0);
2756 }
2757
2758
2759 /**********************************************************************
2760  *              GetDoubleClickTime (USER32.@)
2761  */
2762 UINT WINAPI GetDoubleClickTime(void)
2763 {
2764     UINT time = 0;
2765
2766     get_uint_param( SPI_SETDOUBLECLICKTIME_IDX,
2767                     SPI_SETDOUBLECLICKTIME_REGKEY,
2768                     SPI_SETDOUBLECLICKTIME_VALNAME,
2769                     &double_click_time, &time );
2770     if (!time) time = 500;
2771     return time;
2772 }
2773
2774
2775 /*************************************************************************
2776  *              GetSysColor (USER32.@)
2777  */
2778 COLORREF WINAPI GetSysColor( INT nIndex )
2779 {
2780     if (nIndex >= 0 && nIndex < NUM_SYS_COLORS)
2781         return SysColors[nIndex];
2782     else
2783         return 0;
2784 }
2785
2786
2787 /*************************************************************************
2788  *              SetSysColors (USER32.@)
2789  */
2790 BOOL WINAPI SetSysColors( INT nChanges, const INT *lpSysColor,
2791                               const COLORREF *lpColorValues )
2792 {
2793     int i;
2794
2795     for (i = 0; i < nChanges; i++) SYSPARAMS_SetSysColor( lpSysColor[i], lpColorValues[i] );
2796
2797     /* Send WM_SYSCOLORCHANGE message to all windows */
2798
2799     SendMessageTimeoutW( HWND_BROADCAST, WM_SYSCOLORCHANGE, 0, 0, SMTO_ABORTIFHUNG, 2000, NULL );
2800
2801     /* Repaint affected portions of all visible windows */
2802
2803     RedrawWindow( GetDesktopWindow(), NULL, 0,
2804                 RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN );
2805     return TRUE;
2806 }
2807
2808
2809 /*************************************************************************
2810  *              SetSysColorsTemp (USER32.@)
2811  *
2812  * UNDOCUMENTED !!
2813  *
2814  * Called by W98SE desk.cpl Control Panel Applet:
2815  * handle = SetSysColorsTemp(ptr, ptr, nCount);     ("set" call)
2816  * result = SetSysColorsTemp(NULL, NULL, handle);   ("restore" call)
2817  *
2818  * pPens is an array of COLORREF values, which seems to be used
2819  * to indicate the color values to create new pens with.
2820  *
2821  * pBrushes is an array of solid brush handles (returned by a previous
2822  * CreateSolidBrush), which seems to contain the brush handles to set
2823  * for the system colors.
2824  *
2825  * n seems to be used for
2826  *   a) indicating the number of entries to operate on (length of pPens,
2827  *      pBrushes)
2828  *   b) passing the handle that points to the previously used color settings.
2829  *      I couldn't figure out in hell what kind of handle this is on
2830  *      Windows. I just use a heap handle instead. Shouldn't matter anyway.
2831  *
2832  * RETURNS
2833  *     heap handle of our own copy of the current syscolors in case of
2834  *                 "set" call, i.e. pPens, pBrushes != NULL.
2835  *     TRUE (unconditionally !) in case of "restore" call,
2836  *          i.e. pPens, pBrushes == NULL.
2837  *     FALSE in case of either pPens != NULL and pBrushes == NULL
2838  *          or pPens == NULL and pBrushes != NULL.
2839  *
2840  * I'm not sure whether this implementation is 100% correct. [AM]
2841  */
2842 DWORD WINAPI SetSysColorsTemp( const COLORREF *pPens, const HBRUSH *pBrushes, DWORD n)
2843 {
2844     int i;
2845
2846     if (pPens && pBrushes) /* "set" call */
2847     {
2848         /* allocate our structure to remember old colors */
2849         LPVOID pOldCol = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD)+n*sizeof(HPEN)+n*sizeof(HBRUSH));
2850         LPVOID p = pOldCol;
2851         *(DWORD *)p = n; p = (char*)p + sizeof(DWORD);
2852         memcpy(p, SysColorPens, n*sizeof(HPEN)); p = (char*)p + n*sizeof(HPEN);
2853         memcpy(p, SysColorBrushes, n*sizeof(HBRUSH)); p = (char*)p + n*sizeof(HBRUSH);
2854
2855         for (i=0; i < n; i++)
2856         {
2857             SysColorPens[i] = CreatePen( PS_SOLID, 1, pPens[i] );
2858             SysColorBrushes[i] = pBrushes[i];
2859         }
2860
2861         return (DWORD)pOldCol;
2862     }
2863     if (!pPens && !pBrushes) /* "restore" call */
2864     {
2865         LPVOID pOldCol = (LPVOID)n;
2866         LPVOID p = pOldCol;
2867         DWORD nCount = *(DWORD *)p;
2868         p = (char*)p + sizeof(DWORD);
2869
2870         for (i=0; i < nCount; i++)
2871         {
2872             DeleteObject(SysColorPens[i]);
2873             SysColorPens[i] = *(HPEN *)p; p = (char*)p + sizeof(HPEN);
2874         }
2875         for (i=0; i < nCount; i++)
2876         {
2877             SysColorBrushes[i] = *(HBRUSH *)p; p = (char*)p + sizeof(HBRUSH);
2878         }
2879         /* get rid of storage structure */
2880         HeapFree(GetProcessHeap(), 0, pOldCol);
2881
2882         return TRUE;
2883     }
2884     return FALSE;
2885 }
2886
2887
2888 /***********************************************************************
2889  *              GetSysColorBrush (USER32.@)
2890  */
2891 HBRUSH WINAPI GetSysColorBrush( INT index )
2892 {
2893     if (0 <= index && index < NUM_SYS_COLORS) return SysColorBrushes[index];
2894     WARN("Unknown index(%d)\n", index );
2895     return GetStockObject(LTGRAY_BRUSH);
2896 }
2897
2898
2899 /***********************************************************************
2900  *              SYSCOLOR_GetPen
2901  */
2902 HPEN SYSCOLOR_GetPen( INT index )
2903 {
2904     /* We can assert here, because this function is internal to Wine */
2905     assert (0 <= index && index < NUM_SYS_COLORS);
2906     return SysColorPens[index];
2907 }
2908
2909
2910 /***********************************************************************
2911  *              ChangeDisplaySettingsA (USER32.@)
2912  */
2913 LONG WINAPI ChangeDisplaySettingsA( LPDEVMODEA devmode, DWORD flags )
2914 {
2915     return ChangeDisplaySettingsExA(NULL,devmode,NULL,flags,NULL);
2916 }
2917
2918
2919 /***********************************************************************
2920  *              ChangeDisplaySettingsW (USER32.@)
2921  */
2922 LONG WINAPI ChangeDisplaySettingsW( LPDEVMODEW devmode, DWORD flags )
2923 {
2924     return ChangeDisplaySettingsExW(NULL,devmode,NULL,flags,NULL);
2925 }
2926
2927
2928 /***********************************************************************
2929  *              ChangeDisplaySettingsExA (USER32.@)
2930  */
2931 LONG WINAPI ChangeDisplaySettingsExA( LPCSTR devname, LPDEVMODEA devmode, HWND hwnd,
2932                                       DWORD flags, LPVOID lparam )
2933 {
2934     DEVMODEW devmodeW;
2935     LONG ret;
2936     UNICODE_STRING nameW;
2937
2938     if (devname) RtlCreateUnicodeStringFromAsciiz(&nameW, devname);
2939     else nameW.Buffer = NULL;
2940
2941     if (devmode)
2942     {
2943         devmodeW.dmBitsPerPel       = devmode->dmBitsPerPel;
2944         devmodeW.dmPelsHeight       = devmode->dmPelsHeight;
2945         devmodeW.dmPelsWidth        = devmode->dmPelsWidth;
2946         devmodeW.dmDisplayFlags     = devmode->dmDisplayFlags;
2947         devmodeW.dmDisplayFrequency = devmode->dmDisplayFrequency;
2948         devmodeW.dmFields           = devmode->dmFields;
2949         ret = ChangeDisplaySettingsExW(nameW.Buffer, &devmodeW, hwnd, flags, lparam);
2950     }
2951     else
2952     {
2953         ret = ChangeDisplaySettingsExW(nameW.Buffer, NULL, hwnd, flags, lparam);
2954     }
2955
2956     if (devname) RtlFreeUnicodeString(&nameW);
2957     return ret;
2958 }
2959
2960
2961 /***********************************************************************
2962  *              ChangeDisplaySettingsExW (USER32.@)
2963  */
2964 LONG WINAPI ChangeDisplaySettingsExW( LPCWSTR devname, LPDEVMODEW devmode, HWND hwnd,
2965                                       DWORD flags, LPVOID lparam )
2966 {
2967     /* make sure the desktop window is created before mode changing */
2968     GetDesktopWindow();
2969
2970     return USER_Driver->pChangeDisplaySettingsEx( devname, devmode, hwnd, flags, lparam );
2971 }
2972
2973
2974 /***********************************************************************
2975  *              EnumDisplaySettingsW (USER32.@)
2976  *
2977  * RETURNS
2978  *      TRUE if nth setting exists found (described in the LPDEVMODEW struct)
2979  *      FALSE if we do not have the nth setting
2980  */
2981 BOOL WINAPI EnumDisplaySettingsW( LPCWSTR name, DWORD n, LPDEVMODEW devmode )
2982 {
2983     return EnumDisplaySettingsExW(name, n, devmode, 0);
2984 }
2985
2986
2987 /***********************************************************************
2988  *              EnumDisplaySettingsA (USER32.@)
2989  */
2990 BOOL WINAPI EnumDisplaySettingsA(LPCSTR name,DWORD n,LPDEVMODEA devmode)
2991 {
2992     return EnumDisplaySettingsExA(name, n, devmode, 0);
2993 }
2994
2995
2996 /***********************************************************************
2997  *              EnumDisplaySettingsExA (USER32.@)
2998  */
2999 BOOL WINAPI EnumDisplaySettingsExA(LPCSTR lpszDeviceName, DWORD iModeNum,
3000                                    LPDEVMODEA lpDevMode, DWORD dwFlags)
3001 {
3002     DEVMODEW devmodeW;
3003     BOOL ret;
3004     UNICODE_STRING nameW;
3005
3006     if (lpszDeviceName) RtlCreateUnicodeStringFromAsciiz(&nameW, lpszDeviceName);
3007     else nameW.Buffer = NULL;
3008
3009     ret = EnumDisplaySettingsExW(nameW.Buffer,iModeNum,&devmodeW,dwFlags);
3010     if (ret)
3011     {
3012         lpDevMode->dmBitsPerPel       = devmodeW.dmBitsPerPel;
3013         lpDevMode->dmPelsHeight       = devmodeW.dmPelsHeight;
3014         lpDevMode->dmPelsWidth        = devmodeW.dmPelsWidth;
3015         lpDevMode->dmDisplayFlags     = devmodeW.dmDisplayFlags;
3016         lpDevMode->dmDisplayFrequency = devmodeW.dmDisplayFrequency;
3017         lpDevMode->dmFields           = devmodeW.dmFields;
3018     }
3019     if (lpszDeviceName) RtlFreeUnicodeString(&nameW);
3020     return ret;
3021 }
3022
3023
3024 /***********************************************************************
3025  *              EnumDisplaySettingsExW (USER32.@)
3026  */
3027 BOOL WINAPI EnumDisplaySettingsExW(LPCWSTR lpszDeviceName, DWORD iModeNum,
3028                                    LPDEVMODEW lpDevMode, DWORD dwFlags)
3029 {
3030     return USER_Driver->pEnumDisplaySettingsEx(lpszDeviceName, iModeNum, lpDevMode, dwFlags);
3031 }