Build the tests with winegcc.
[wine/multimedia.git] / windows / sysmetrics.c
blob2527dfc78f9381eeeba24986825329d38904c6c1
1 /*
2 * System metrics functions
4 * Copyright 1994 Alexandre Julliard
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.
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.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <assert.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "wingdi.h"
30 #include "wine/winuser16.h"
31 #include "winuser.h"
32 #include "winerror.h"
33 #include "user.h"
35 static int sysMetrics[SM_CMETRICS+1];
36 static HDC display_dc;
39 /***********************************************************************
40 * RegistryTwips2Pixels
42 * Convert a a dimension value that was obtained from the registry. These are
43 * quoted as being "twips" values if negative and pixels if positive.
44 * See for example
45 * MSDN Library - April 2001 -> Resource Kits ->
46 * Windows 2000 Resource Kit Reference ->
47 * Technical Reference to the Windows 2000 Registry ->
48 * HKEY_CURRENT_USER -> Control Panel -> Desktop -> WindowMetrics
50 * This is written as a function to prevent repeated evaluation of the
51 * argument.
53 inline static int RegistryTwips2Pixels(int x)
55 if (x < 0)
56 x = (-x+7)/15;
57 return x;
61 /***********************************************************************
62 * SYSMETRICS_GetRegistryMetric
64 * Get a registry entry from the already open key. This allows us to open the
65 * section once and read several values.
67 * Of course this function belongs somewhere more usable but here will do
68 * for now.
70 static int SYSMETRICS_GetRegistryMetric (
71 HKEY hkey, /* handle to the registry section */
72 const char *key, /* value name in the section */
73 int default_value) /* default to return */
75 int value = default_value;
76 if (hkey)
78 BYTE buffer[128];
79 DWORD type, count = sizeof(buffer);
80 if(!RegQueryValueExA (hkey, key, 0, &type, buffer, &count))
82 if (type != REG_SZ)
84 /* Are there any utilities for converting registry entries
85 * between formats?
87 /* FIXME_(reg)("We need reg format converter\n"); */
89 else
90 value = atoi(buffer);
93 return RegistryTwips2Pixels(value);
97 /***********************************************************************
98 * SYSMETRICS_Init
100 * Initialisation of the system metrics array.
102 * Differences in return values between 3.1 and 95 apps under Win95 (FIXME ?):
103 * SM_CXVSCROLL x+1 x Fixed May 24, 1999 - Ronald B. Cemer
104 * SM_CYHSCROLL x+1 x Fixed May 24, 1999 - Ronald B. Cemer
105 * SM_CXDLGFRAME x-1 x Already fixed
106 * SM_CYDLGFRAME x-1 x Already fixed
107 * SM_CYCAPTION x+1 x Fixed May 24, 1999 - Ronald B. Cemer
108 * SM_CYMENU x-1 x Already fixed
109 * SM_CYFULLSCREEN x-1 x
110 * SM_CXFRAME Fixed July 6, 2001 - Bill Medland
112 * (collides with TWEAK_WineLook sometimes,
113 * so changing anything might be difficult)
115 * Starting at Win95 there are now a large number or Registry entries in the
116 * [WindowMetrics] section that are probably relevant here.
118 void SYSMETRICS_Init(void)
120 HKEY hkey; /* key to the window metrics area of the registry */
121 INT dummy;
123 display_dc = CreateICA( "DISPLAY", NULL, NULL, NULL );
124 assert( display_dc );
126 if (RegOpenKeyExA (HKEY_CURRENT_USER, "Control Panel\\desktop\\WindowMetrics",
127 0, KEY_QUERY_VALUE, &hkey) != ERROR_SUCCESS) hkey = 0;
129 if (TWEAK_WineLook > WIN31_LOOK)
131 sysMetrics[SM_CXVSCROLL] = SYSMETRICS_GetRegistryMetric( hkey, "ScrollWidth", 16 );
132 sysMetrics[SM_CYHSCROLL] = sysMetrics[SM_CXVSCROLL];
134 /* The Win 2000 resource kit SAYS that this is governed by the ScrollHeight
135 * but on my computer that controls the CYV/CXH values. */
136 sysMetrics[SM_CYCAPTION] = SYSMETRICS_GetRegistryMetric(hkey, "CaptionHeight", 18)
137 + 1; /* for the separator? */
139 sysMetrics[SM_CYMENU] = SYSMETRICS_GetRegistryMetric (hkey, "MenuHeight", 18) + 1;
142 sysMetrics[SM_CXDLGFRAME] = 3;
143 sysMetrics[SM_CYDLGFRAME] = sysMetrics[SM_CXDLGFRAME];
145 /* force setting of SM_CXFRAME/SM_CYFRAME */
146 SystemParametersInfoA( SPI_GETBORDER, 0, &dummy, 0 );
148 else
150 sysMetrics[SM_CXVSCROLL] = 17;
151 sysMetrics[SM_CYHSCROLL] = sysMetrics[SM_CXVSCROLL];
152 sysMetrics[SM_CYCAPTION] = 20;
153 sysMetrics[SM_CYMENU] = 18;
154 sysMetrics[SM_CXDLGFRAME] = 4;
155 sysMetrics[SM_CYDLGFRAME] = sysMetrics[SM_CXDLGFRAME];
156 sysMetrics[SM_CXFRAME] = GetProfileIntA("Windows", "BorderWidth", 4) + 1;
157 sysMetrics[SM_CYFRAME] = sysMetrics[SM_CXFRAME];
160 sysMetrics[SM_CXCURSOR] = 32;
161 sysMetrics[SM_CYCURSOR] = 32;
162 sysMetrics[SM_CXBORDER] = 1;
163 sysMetrics[SM_CYBORDER] = sysMetrics[SM_CXBORDER];
164 sysMetrics[SM_CYVTHUMB] = sysMetrics[SM_CXVSCROLL];
165 sysMetrics[SM_CXHTHUMB] = sysMetrics[SM_CYVTHUMB];
166 sysMetrics[SM_CXICON] = 32;
167 sysMetrics[SM_CYICON] = 32;
168 sysMetrics[SM_CYKANJIWINDOW] = 0;
169 sysMetrics[SM_MOUSEPRESENT] = 1;
170 sysMetrics[SM_CYVSCROLL] = SYSMETRICS_GetRegistryMetric (hkey, "ScrollHeight", sysMetrics[SM_CXVSCROLL]);
171 sysMetrics[SM_CXHSCROLL] = SYSMETRICS_GetRegistryMetric (hkey, "ScrollHeight", sysMetrics[SM_CYHSCROLL]);
172 sysMetrics[SM_DEBUG] = 0;
174 sysMetrics[SM_SWAPBUTTON] = 0;
175 sysMetrics[SM_SWAPBUTTON] = SYSPARAMS_GetMouseButtonSwap();
177 sysMetrics[SM_RESERVED1] = 0;
178 sysMetrics[SM_RESERVED2] = 0;
179 sysMetrics[SM_RESERVED3] = 0;
180 sysMetrics[SM_RESERVED4] = 0;
182 /* FIXME: The following two are calculated, but how? */
183 sysMetrics[SM_CXMIN] = (TWEAK_WineLook > WIN31_LOOK) ? 112 : 100;
184 sysMetrics[SM_CYMIN] = (TWEAK_WineLook > WIN31_LOOK) ? 27 : 28;
186 sysMetrics[SM_CXSIZE] = sysMetrics[SM_CYCAPTION] - 1;
187 sysMetrics[SM_CYSIZE] = sysMetrics[SM_CXSIZE];
188 sysMetrics[SM_CXMINTRACK] = sysMetrics[SM_CXMIN];
189 sysMetrics[SM_CYMINTRACK] = sysMetrics[SM_CYMIN];
191 sysMetrics[SM_CXDOUBLECLK] = 4;
192 sysMetrics[SM_CYDOUBLECLK] = 4;
193 SYSPARAMS_GetDoubleClickSize( &sysMetrics[SM_CXDOUBLECLK], &sysMetrics[SM_CYDOUBLECLK] );
195 sysMetrics[SM_CXICONSPACING] = 75;
196 SystemParametersInfoA( SPI_ICONHORIZONTALSPACING, 0,
197 &sysMetrics[SM_CXICONSPACING], 0 );
198 sysMetrics[SM_CYICONSPACING] = 75;
199 SystemParametersInfoA( SPI_ICONVERTICALSPACING, 0,
200 &sysMetrics[SM_CYICONSPACING], 0 );
202 SystemParametersInfoA( SPI_GETMENUDROPALIGNMENT, 0,
203 &sysMetrics[SM_MENUDROPALIGNMENT], 0 );
204 sysMetrics[SM_PENWINDOWS] = 0;
205 sysMetrics[SM_DBCSENABLED] = 0;
207 /* FIXME: Need to query X for the following */
208 sysMetrics[SM_CMOUSEBUTTONS] = 3;
210 sysMetrics[SM_SECURE] = 0;
211 sysMetrics[SM_CXEDGE] = sysMetrics[SM_CXBORDER] + 1;
212 sysMetrics[SM_CYEDGE] = sysMetrics[SM_CXEDGE];
213 sysMetrics[SM_CXMINSPACING] = 160;
214 sysMetrics[SM_CYMINSPACING] = 24;
215 sysMetrics[SM_CXSMICON] = sysMetrics[SM_CYSIZE] - (sysMetrics[SM_CYSIZE] % 2);
216 sysMetrics[SM_CYSMICON] = sysMetrics[SM_CXSMICON];
217 sysMetrics[SM_CYSMCAPTION] = 16;
218 sysMetrics[SM_CXSMSIZE] = 13;
219 sysMetrics[SM_CYSMSIZE] = 15;
220 sysMetrics[SM_CXMENUSIZE] = sysMetrics[SM_CYMENU] - 1;
221 sysMetrics[SM_CYMENUSIZE] = sysMetrics[SM_CXMENUSIZE];
223 /* FIXME: What do these mean? */
224 sysMetrics[SM_ARRANGE] = ARW_HIDE;
225 sysMetrics[SM_CXMINIMIZED] = 160;
226 sysMetrics[SM_CYMINIMIZED] = 24;
228 /* FIXME: How do I calculate these? */
229 sysMetrics[SM_NETWORK] = 3;
231 /* For the following: 0 = ok, 1 = failsafe, 2 = failsafe + network */
232 sysMetrics[SM_CLEANBOOT] = 0;
234 sysMetrics[SM_CXDRAG] = 2;
235 sysMetrics[SM_CYDRAG] = 2;
236 sysMetrics[SM_CXMENUCHECK] = 13;
237 sysMetrics[SM_CYMENUCHECK] = 13;
239 /* FIXME: Should check the type of processor for the following */
240 sysMetrics[SM_SLOWMACHINE] = 0;
242 /* FIXME: Should perform a check */
243 sysMetrics[SM_MIDEASTENABLED] = 0;
245 sysMetrics[SM_MOUSEWHEELPRESENT] = 1;
247 sysMetrics[SM_XVIRTUALSCREEN] = 0;
248 sysMetrics[SM_YVIRTUALSCREEN] = 0;
249 sysMetrics[SM_CMONITORS] = 1;
250 sysMetrics[SM_SAMEDISPLAYFORMAT] = 1;
251 sysMetrics[SM_CMETRICS] = SM_CMETRICS;
253 SystemParametersInfoA( SPI_GETSHOWSOUNDS, 0, &sysMetrics[SM_SHOWSOUNDS], 0 );
255 if (hkey) RegCloseKey (hkey);
259 /***********************************************************************
260 * SYSMETRICS_Set
262 * Sets system metrics.
264 INT SYSMETRICS_Set( INT index, INT value )
266 if ((index < 0) || (index > SM_CMETRICS)) return 0;
267 else
269 INT prev = sysMetrics[index];
270 sysMetrics[index] = value;
271 return prev;
276 /***********************************************************************
277 * GetSystemMetrics (USER.179)
279 INT16 WINAPI GetSystemMetrics16( INT16 index )
281 return (INT16)GetSystemMetrics(index);
285 /***********************************************************************
286 * GetSystemMetrics (USER32.@)
288 INT WINAPI GetSystemMetrics( INT index )
290 /* some metrics are dynamic */
291 switch (index)
293 case SM_CXSCREEN:
294 case SM_CXFULLSCREEN:
295 case SM_CXVIRTUALSCREEN:
296 return GetDeviceCaps( display_dc, HORZRES );
297 case SM_CYSCREEN:
298 case SM_CYVIRTUALSCREEN:
299 return GetDeviceCaps( display_dc, VERTRES );
300 case SM_CYFULLSCREEN:
301 return GetDeviceCaps( display_dc, VERTRES ) - sysMetrics[SM_CYCAPTION];
303 /* FIXME: How do I calculate these? */
304 case SM_CXMAXTRACK:
305 return GetDeviceCaps( display_dc, HORZRES ) + 4 + 2 * sysMetrics[SM_CXFRAME];
306 case SM_CYMAXTRACK:
307 return GetDeviceCaps( display_dc, VERTRES ) + 4 + 2 * sysMetrics[SM_CYFRAME];
308 case SM_CXMAXIMIZED:
309 return GetDeviceCaps( display_dc, HORZRES ) + 2 * sysMetrics[SM_CXFRAME];
310 case SM_CYMAXIMIZED:
311 return GetDeviceCaps( display_dc, VERTRES ) + 2 * sysMetrics[SM_CYFRAME];
313 default:
314 if ((index < 0) || (index > SM_CMETRICS)) return 0;
315 return sysMetrics[index];