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