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