Fix SHRegOpenUSKey{A|W} and SHRegQueryUSValue{A|W} to actually use
[wine] / windows / sysmetrics.c
1 /*
2  * System metrics functions
3  *
4  * Copyright 1994 Alexandre Julliard
5  *
6  */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <assert.h>
11
12 #include "windef.h"
13 #include "wingdi.h"
14 #include "wine/winuser16.h"
15 #include "winbase.h"
16 #include "winreg.h"
17 #include "winuser.h"
18 #include "winerror.h"
19 #include "user.h"
20 #include "sysmetrics.h"
21
22 static int sysMetrics[SM_WINE_CMETRICS+1];
23
24
25 /***********************************************************************
26  * RegistryTwips2Pixels
27  *
28  * Convert a a dimension value that was obtained from the registry.  These are
29  * quoted as being "twips" values if negative and pixels if positive.
30  * See for example 
31  *   MSDN Library - April 2001 -> Resource Kits ->
32  *       Windows 2000 Resource Kit Reference ->
33  *       Technical Reference to the Windows 2000 Registry ->
34  *       HKEY_CURRENT_USE -> Control Panel -> Desktop -> WindowMetrics
35  *
36  * This is written as a function to prevent repeated evaluation of the 
37  * argument.
38  */
39 inline static int RegistryTwips2Pixels(int x)
40 {
41     if (x < 0)
42         x = (-x+7)/15;
43     return x;
44 }
45
46
47 /***********************************************************************
48  * SYSMETRICS_GetRegistryMetric
49  *
50  * Get a registry entry from the already open key.  This allows us to open the
51  * section once and read several values.
52  *
53  * Of course this function belongs somewhere more usable but here will do
54  * for now.
55  */
56 static int SYSMETRICS_GetRegistryMetric (
57         HKEY       hkey,            /* handle to the registry section */
58         const char *key,            /* value name in the section */
59         int        default_value)   /* default to return */
60 {
61     int value = default_value;
62     if (hkey)
63     {
64         BYTE buffer[128];
65         DWORD type, count = sizeof(buffer);
66         if(!RegQueryValueExA (hkey, key, 0, &type, buffer, &count))
67         {
68             if (type != REG_SZ)
69             {
70                 /* Are there any utilities for converting registry entries
71                  * between formats?
72                  */
73                 /* FIXME_(reg)("We need reg format converter\n"); */
74             }
75             else
76                 value = atoi(buffer);
77         }
78     }
79     return RegistryTwips2Pixels(value);
80 }
81
82
83 /***********************************************************************
84  *           SYSMETRICS_Init
85  *
86  * Initialisation of the system metrics array.
87  *
88  * Differences in return values between 3.1 and 95 apps under Win95 (FIXME ?):
89  * SM_CXVSCROLL        x+1      x       Fixed May 24, 1999 - Ronald B. Cemer
90  * SM_CYHSCROLL        x+1      x       Fixed May 24, 1999 - Ronald B. Cemer
91  * SM_CXDLGFRAME       x-1      x       Already fixed
92  * SM_CYDLGFRAME       x-1      x       Already fixed
93  * SM_CYCAPTION        x+1      x       Fixed May 24, 1999 - Ronald B. Cemer
94  * SM_CYMENU           x-1      x       Already fixed
95  * SM_CYFULLSCREEN     x-1      x
96  * SM_CXFRAME                           Fixed July 6, 2001 - Bill Medland
97  * 
98  * (collides with TWEAK_WineLook sometimes,
99  * so changing anything might be difficult) 
100  *
101  * Starting at Win95 there are now a large number or Registry entries in the
102  * [WindowMetrics] section that are probably relevant here.
103  */
104 void SYSMETRICS_Init(void)
105 {
106     HDC hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
107     HKEY hkey; /* key to the window metrics area of the registry */
108     INT dummy;
109
110     assert(hdc);
111
112     if (RegOpenKeyExA (HKEY_CURRENT_USER, "Control Panel\\desktop\\WindowMetrics",
113                        0, KEY_QUERY_VALUE, &hkey) != ERROR_SUCCESS) hkey = 0;
114
115     if (TWEAK_WineLook > WIN31_LOOK)
116     {
117         sysMetrics[SM_CXVSCROLL] = SYSMETRICS_GetRegistryMetric( hkey, "ScrollWidth", 16 );
118         sysMetrics[SM_CYHSCROLL] = sysMetrics[SM_CXVSCROLL];
119
120         /* The Win 2000 resource kit SAYS that this is governed by the ScrollHeight
121          * but on my computer that controls the CYV/CXH values. */
122         sysMetrics[SM_CYCAPTION] = SYSMETRICS_GetRegistryMetric(hkey, "CaptionHeight", 18)
123                                      + 1; /* for the separator? */
124
125         sysMetrics[SM_CYMENU] = SYSMETRICS_GetRegistryMetric (hkey, "MenuHeight", 18) + 1;
126
127
128         sysMetrics[SM_CXDLGFRAME] = 3;
129         sysMetrics[SM_CYDLGFRAME] = sysMetrics[SM_CXDLGFRAME];
130
131         /* force setting of SM_CXFRAME/SM_CYFRAME */
132         SystemParametersInfoA( SPI_GETBORDER, 0, &dummy, 0 );
133     }
134     else
135     {
136         sysMetrics[SM_CXVSCROLL]  = 17;
137         sysMetrics[SM_CYHSCROLL]  = sysMetrics[SM_CXVSCROLL];
138         sysMetrics[SM_CYCAPTION]  = 20;
139         sysMetrics[SM_CYMENU]     = 18;
140         sysMetrics[SM_CXDLGFRAME] = 4;
141         sysMetrics[SM_CYDLGFRAME] = sysMetrics[SM_CXDLGFRAME];
142         sysMetrics[SM_CXFRAME]    = GetProfileIntA("Windows", "BorderWidth", 4) + 1;
143         sysMetrics[SM_CYFRAME]    = sysMetrics[SM_CXFRAME];
144     }
145
146     sysMetrics[SM_CXCURSOR] = 32;
147     sysMetrics[SM_CYCURSOR] = 32;
148     sysMetrics[SM_CXSCREEN] = GetDeviceCaps( hdc, HORZRES );
149     sysMetrics[SM_CYSCREEN] = GetDeviceCaps( hdc, VERTRES );
150     sysMetrics[SM_WINE_BPP] = GetDeviceCaps( hdc, BITSPIXEL );
151     sysMetrics[SM_CXBORDER] = 1;
152     sysMetrics[SM_CYBORDER] = sysMetrics[SM_CXBORDER];
153     sysMetrics[SM_CYVTHUMB] = sysMetrics[SM_CXVSCROLL] - 1;
154     sysMetrics[SM_CXHTHUMB] = sysMetrics[SM_CYVTHUMB];
155     sysMetrics[SM_CXICON] = 32;
156     sysMetrics[SM_CYICON] = 32;
157     sysMetrics[SM_CXFULLSCREEN] = sysMetrics[SM_CXSCREEN];
158     sysMetrics[SM_CYFULLSCREEN] =
159         sysMetrics[SM_CYSCREEN] - sysMetrics[SM_CYCAPTION];
160     sysMetrics[SM_CYKANJIWINDOW] = 0;
161     sysMetrics[SM_MOUSEPRESENT] = 1;
162     sysMetrics[SM_CYVSCROLL] = SYSMETRICS_GetRegistryMetric (hkey, "ScrollHeight", sysMetrics[SM_CXVSCROLL]);
163     sysMetrics[SM_CXHSCROLL] = SYSMETRICS_GetRegistryMetric (hkey, "ScrollHeight", sysMetrics[SM_CYHSCROLL]);
164     sysMetrics[SM_DEBUG] = 0;
165
166     sysMetrics[SM_SWAPBUTTON] = 0;
167     sysMetrics[SM_SWAPBUTTON] = SYSPARAMS_GetMouseButtonSwap();
168
169     sysMetrics[SM_RESERVED1] = 0;
170     sysMetrics[SM_RESERVED2] = 0;
171     sysMetrics[SM_RESERVED3] = 0;
172     sysMetrics[SM_RESERVED4] = 0;
173
174     /* FIXME: The following two are calculated, but how? */
175     sysMetrics[SM_CXMIN] = (TWEAK_WineLook > WIN31_LOOK) ? 112 : 100;
176     sysMetrics[SM_CYMIN] = (TWEAK_WineLook > WIN31_LOOK) ? 27 : 28;
177
178     sysMetrics[SM_CXSIZE] = sysMetrics[SM_CYCAPTION] - 2;
179     sysMetrics[SM_CYSIZE] = sysMetrics[SM_CXSIZE];
180     sysMetrics[SM_CXMINTRACK] = sysMetrics[SM_CXMIN];
181     sysMetrics[SM_CYMINTRACK] = sysMetrics[SM_CYMIN];
182
183     sysMetrics[SM_CXDOUBLECLK] = 4;
184     sysMetrics[SM_CYDOUBLECLK] = 4;
185     SYSPARAMS_GetDoubleClickSize( &sysMetrics[SM_CXDOUBLECLK], &sysMetrics[SM_CYDOUBLECLK] );
186
187     sysMetrics[SM_CXICONSPACING] = 75;
188     SystemParametersInfoA( SPI_ICONHORIZONTALSPACING, 0,
189                            &sysMetrics[SM_CXICONSPACING], 0 );
190     sysMetrics[SM_CYICONSPACING] = 75;
191     SystemParametersInfoA( SPI_ICONVERTICALSPACING, 0,
192                            &sysMetrics[SM_CYICONSPACING], 0 );
193
194     SystemParametersInfoA( SPI_GETMENUDROPALIGNMENT, 0,
195                            &sysMetrics[SM_MENUDROPALIGNMENT], 0 );
196     sysMetrics[SM_PENWINDOWS] = 0;
197     sysMetrics[SM_DBCSENABLED] = 0;
198
199     /* FIXME: Need to query X for the following */
200     sysMetrics[SM_CMOUSEBUTTONS] = 3;
201
202     sysMetrics[SM_SECURE] = 0;
203     sysMetrics[SM_CXEDGE] = sysMetrics[SM_CXBORDER] + 1;
204     sysMetrics[SM_CYEDGE] = sysMetrics[SM_CXEDGE];
205     sysMetrics[SM_CXMINSPACING] = 160;
206     sysMetrics[SM_CYMINSPACING] = 24;
207     sysMetrics[SM_CXSMICON] = sysMetrics[SM_CYSIZE] - (sysMetrics[SM_CYSIZE] % 2);
208     sysMetrics[SM_CYSMICON] = sysMetrics[SM_CXSMICON];
209     sysMetrics[SM_CYSMCAPTION] = 16;
210     sysMetrics[SM_CXSMSIZE] = 15;
211     sysMetrics[SM_CYSMSIZE] = sysMetrics[SM_CXSMSIZE];
212     sysMetrics[SM_CXMENUSIZE] = sysMetrics[SM_CYMENU];
213     sysMetrics[SM_CYMENUSIZE] = sysMetrics[SM_CXMENUSIZE];
214
215     /* FIXME: What do these mean? */
216     sysMetrics[SM_ARRANGE] = ARW_HIDE;
217     sysMetrics[SM_CXMINIMIZED] = 160;
218     sysMetrics[SM_CYMINIMIZED] = 24;
219
220     /* FIXME: How do I calculate these? */
221     sysMetrics[SM_CXMAXTRACK] = 
222         sysMetrics[SM_CXSCREEN] + 4 + 2 * sysMetrics[SM_CXFRAME];
223     sysMetrics[SM_CYMAXTRACK] =
224         sysMetrics[SM_CYSCREEN] + 4 + 2 * sysMetrics[SM_CYFRAME];
225     sysMetrics[SM_CXMAXIMIZED] =
226         sysMetrics[SM_CXSCREEN] + 2 * sysMetrics[SM_CXFRAME];
227     sysMetrics[SM_CYMAXIMIZED] =
228         sysMetrics[SM_CYSCREEN] - 45;
229     sysMetrics[SM_NETWORK] = 3;
230
231     /* For the following: 0 = ok, 1 = failsafe, 2 = failsafe + network */
232     sysMetrics[SM_CLEANBOOT] = 0;
233
234     sysMetrics[SM_CXDRAG] = 2;
235     sysMetrics[SM_CYDRAG] = 2;
236     sysMetrics[SM_CXMENUCHECK] = 14;
237     sysMetrics[SM_CYMENUCHECK] = 14;
238
239     /* FIXME: Should check the type of processor for the following */
240     sysMetrics[SM_SLOWMACHINE] = 0;
241
242     /* FIXME: Should perform a check */
243     sysMetrics[SM_MIDEASTENABLED] = 0;
244
245     sysMetrics[SM_MOUSEWHEELPRESENT] = 0;
246
247     sysMetrics[SM_CXVIRTUALSCREEN] = sysMetrics[SM_CXSCREEN];
248     sysMetrics[SM_CYVIRTUALSCREEN] = sysMetrics[SM_CYSCREEN];
249     sysMetrics[SM_XVIRTUALSCREEN] = 0;
250     sysMetrics[SM_YVIRTUALSCREEN] = 0;
251     sysMetrics[SM_CMONITORS] = 1;
252     sysMetrics[SM_SAMEDISPLAYFORMAT] = 1;
253     sysMetrics[SM_CMETRICS] = SM_CMETRICS;
254
255     SystemParametersInfoA( SPI_GETSHOWSOUNDS, 0, &sysMetrics[SM_SHOWSOUNDS], 0 );
256
257     if (hkey) RegCloseKey (hkey);
258     DeleteDC( hdc );
259 }
260
261
262 /***********************************************************************
263  *              SYSMETRICS_Set
264  *
265  *  Sets system metrics.
266  */
267 INT SYSMETRICS_Set( INT index, INT value )
268 {
269     if ((index < 0) || (index > SM_WINE_CMETRICS)) return 0;
270     else
271     {
272         INT prev = sysMetrics[index];
273         sysMetrics[index] = value;
274         return prev;
275     }
276 }
277
278
279 /***********************************************************************
280  *              GetSystemMetrics (USER.179)
281  */
282 INT16 WINAPI GetSystemMetrics16( INT16 index )
283 {
284     return (INT16)GetSystemMetrics(index);
285 }
286
287
288 /***********************************************************************
289  *              GetSystemMetrics (USER32.@)
290  */
291 INT WINAPI GetSystemMetrics( INT index )
292 {
293     if ((index < 0) || (index > SM_WINE_CMETRICS)) return 0;
294     return sysMetrics[index];
295 }