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