Removed some direct accesses to GDI internal pen/brush/font
[wine/dcerpc.git] / windows / sysmetrics.c
blob6c274a169b051fd6ecf67dc6db945404ce7d0fdd
1 /*
2 * System metrics functions
4 * Copyright 1994 Alexandre Julliard
6 */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <assert.h>
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"
22 static int sysMetrics[SM_WINE_CMETRICS+1];
25 /***********************************************************************
26 * RegistryTwips2Pixels
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
36 * This is written as a function to prevent repeated evaluation of the
37 * argument.
39 inline static int RegistryTwips2Pixels(int x)
41 if (x < 0)
42 x = (-x+7)/15;
43 return x;
47 /***********************************************************************
48 * SYSMETRICS_GetRegistryMetric
50 * Get a registry entry from the already open key. This allows us to open the
51 * section once and read several values.
53 * Of course this function belongs somewhere more usable but here will do
54 * for now.
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 */
61 int value = default_value;
62 if (hkey)
64 BYTE buffer[128];
65 DWORD type, count = sizeof(buffer);
66 if(!RegQueryValueExA (hkey, key, 0, &type, buffer, &count))
68 if (type != REG_SZ)
70 /* Are there any utilities for converting registry entries
71 * between formats?
73 /* FIXME_(reg)("We need reg format converter\n"); */
75 else
76 value = atoi(buffer);
79 return RegistryTwips2Pixels(value);
83 /***********************************************************************
84 * SYSMETRICS_Init
86 * Initialisation of the system metrics array.
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
98 * (collides with TWEAK_WineLook sometimes,
99 * so changing anything might be difficult)
101 * Starting at Win95 there are now a large number or Registry entries in the
102 * [WindowMetrics] section that are probably relevant here.
104 void SYSMETRICS_Init(void)
106 HDC hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
107 HKEY hkey; /* key to the window metrics area of the registry */
108 assert(hdc);
110 if (RegOpenKeyExA (HKEY_CURRENT_USER, "Control Panel\\desktop\\WindowMetrics",
111 0, KEY_QUERY_VALUE, &hkey) != ERROR_SUCCESS) hkey = 0;
113 if (TWEAK_WineLook > WIN31_LOOK)
115 sysMetrics[SM_CXVSCROLL] = SYSMETRICS_GetRegistryMetric( hkey, "ScrollWidth", 16 );
116 sysMetrics[SM_CYHSCROLL] = sysMetrics[SM_CXVSCROLL];
118 /* The Win 2000 resource kit SAYS that this is governed by the ScrollHeight
119 * but on my computer that controls the CYV/CXH values. */
120 sysMetrics[SM_CYCAPTION] = SYSMETRICS_GetRegistryMetric(hkey, "CaptionHeight", 18)
121 + 1; /* for the separator? */
123 sysMetrics[SM_CYMENU] = SYSMETRICS_GetRegistryMetric (hkey, "MenuHeight", 18) + 1;
126 sysMetrics[SM_CXDLGFRAME] = 3;
127 sysMetrics[SM_CYDLGFRAME] = sysMetrics[SM_CXDLGFRAME];
129 sysMetrics[SM_CXFRAME] = SYSMETRICS_GetRegistryMetric(hkey, "BorderWidth", 1)
130 + sysMetrics[SM_CXDLGFRAME];
131 sysMetrics[SM_CYFRAME] = sysMetrics[SM_CXFRAME];
132 /* Since I am unable to get SM_CXDLGFRAME to be anything other than 3 on
133 * my Win95 computer I cannot proved the above assumption that the frame
134 * size is dependent on it. However the above relationship is assumed in
135 * the painting of the Windows 95 frames (currently in nonclient.c)
138 else
140 sysMetrics[SM_CXVSCROLL] = 17;
141 sysMetrics[SM_CYHSCROLL] = sysMetrics[SM_CXVSCROLL];
142 sysMetrics[SM_CYCAPTION] = 20;
143 sysMetrics[SM_CYMENU] = 18;
144 sysMetrics[SM_CXDLGFRAME] = 4;
145 sysMetrics[SM_CYDLGFRAME] = sysMetrics[SM_CXDLGFRAME];
146 sysMetrics[SM_CXFRAME] = GetProfileIntA("Windows", "BorderWidth", 4) + 1;
147 sysMetrics[SM_CYFRAME] = sysMetrics[SM_CXFRAME];
150 sysMetrics[SM_CXCURSOR] = 32;
151 sysMetrics[SM_CYCURSOR] = 32;
152 sysMetrics[SM_CXSCREEN] = GetDeviceCaps( hdc, HORZRES );
153 sysMetrics[SM_CYSCREEN] = GetDeviceCaps( hdc, VERTRES );
154 sysMetrics[SM_WINE_BPP] = GetDeviceCaps( hdc, BITSPIXEL );
155 sysMetrics[SM_CXBORDER] = 1;
156 sysMetrics[SM_CYBORDER] = sysMetrics[SM_CXBORDER];
157 sysMetrics[SM_CYVTHUMB] = sysMetrics[SM_CXVSCROLL] - 1;
158 sysMetrics[SM_CXHTHUMB] = sysMetrics[SM_CYVTHUMB];
159 sysMetrics[SM_CXICON] = 32;
160 sysMetrics[SM_CYICON] = 32;
161 sysMetrics[SM_CXFULLSCREEN] = sysMetrics[SM_CXSCREEN];
162 sysMetrics[SM_CYFULLSCREEN] =
163 sysMetrics[SM_CYSCREEN] - sysMetrics[SM_CYCAPTION];
164 sysMetrics[SM_CYKANJIWINDOW] = 0;
165 sysMetrics[SM_MOUSEPRESENT] = 1;
166 sysMetrics[SM_CYVSCROLL] = SYSMETRICS_GetRegistryMetric (hkey, "ScrollHeight", sysMetrics[SM_CXVSCROLL]);
167 sysMetrics[SM_CXHSCROLL] = SYSMETRICS_GetRegistryMetric (hkey, "ScrollHeight", sysMetrics[SM_CYHSCROLL]);
168 sysMetrics[SM_DEBUG] = 0;
170 /* FIXME: The following should look for the registry key to see if the
171 buttons should be swapped. */
172 sysMetrics[SM_SWAPBUTTON] = 0;
174 sysMetrics[SM_RESERVED1] = 0;
175 sysMetrics[SM_RESERVED2] = 0;
176 sysMetrics[SM_RESERVED3] = 0;
177 sysMetrics[SM_RESERVED4] = 0;
179 /* FIXME: The following two are calculated, but how? */
180 sysMetrics[SM_CXMIN] = (TWEAK_WineLook > WIN31_LOOK) ? 112 : 100;
181 sysMetrics[SM_CYMIN] = (TWEAK_WineLook > WIN31_LOOK) ? 27 : 28;
183 sysMetrics[SM_CXSIZE] = sysMetrics[SM_CYCAPTION] - 2;
184 sysMetrics[SM_CYSIZE] = sysMetrics[SM_CXSIZE];
185 sysMetrics[SM_CXMINTRACK] = sysMetrics[SM_CXMIN];
186 sysMetrics[SM_CYMINTRACK] = sysMetrics[SM_CYMIN];
187 sysMetrics[SM_CXDOUBLECLK] =
188 (GetProfileIntA("Windows", "DoubleClickWidth", 4) + 1) & ~1;
189 sysMetrics[SM_CYDOUBLECLK] =
190 (GetProfileIntA("Windows","DoubleClickHeight", 4) + 1) & ~1;
191 sysMetrics[SM_CXICONSPACING] =
192 GetProfileIntA("Desktop","IconSpacing", 75);
193 sysMetrics[SM_CYICONSPACING] =
194 GetProfileIntA("Desktop", "IconVerticalSpacing", 75);
195 sysMetrics[SM_MENUDROPALIGNMENT] =
196 GetProfileIntA("Windows", "MenuDropAlignment", 0);
197 sysMetrics[SM_PENWINDOWS] = 0;
198 sysMetrics[SM_DBCSENABLED] = 0;
200 /* FIXME: Need to query X for the following */
201 sysMetrics[SM_CMOUSEBUTTONS] = 3;
203 sysMetrics[SM_SECURE] = 0;
204 sysMetrics[SM_CXEDGE] = sysMetrics[SM_CXBORDER] + 1;
205 sysMetrics[SM_CYEDGE] = sysMetrics[SM_CXEDGE];
206 sysMetrics[SM_CXMINSPACING] = 160;
207 sysMetrics[SM_CYMINSPACING] = 24;
208 sysMetrics[SM_CXSMICON] = sysMetrics[SM_CYSIZE] - (sysMetrics[SM_CYSIZE] % 2);
209 sysMetrics[SM_CYSMICON] = sysMetrics[SM_CXSMICON];
210 sysMetrics[SM_CYSMCAPTION] = 16;
211 sysMetrics[SM_CXSMSIZE] = 15;
212 sysMetrics[SM_CYSMSIZE] = sysMetrics[SM_CXSMSIZE];
213 sysMetrics[SM_CXMENUSIZE] = sysMetrics[SM_CYMENU];
214 sysMetrics[SM_CYMENUSIZE] = sysMetrics[SM_CXMENUSIZE];
216 /* FIXME: What do these mean? */
217 sysMetrics[SM_ARRANGE] = ARW_HIDE;
218 sysMetrics[SM_CXMINIMIZED] = 160;
219 sysMetrics[SM_CYMINIMIZED] = 24;
221 /* FIXME: How do I calculate these? */
222 sysMetrics[SM_CXMAXTRACK] =
223 sysMetrics[SM_CXSCREEN] + 4 + 2 * sysMetrics[SM_CXFRAME];
224 sysMetrics[SM_CYMAXTRACK] =
225 sysMetrics[SM_CYSCREEN] + 4 + 2 * sysMetrics[SM_CYFRAME];
226 sysMetrics[SM_CXMAXIMIZED] =
227 sysMetrics[SM_CXSCREEN] + 2 * sysMetrics[SM_CXFRAME];
228 sysMetrics[SM_CYMAXIMIZED] =
229 sysMetrics[SM_CYSCREEN] - 45;
230 sysMetrics[SM_NETWORK] = 3;
232 /* For the following: 0 = ok, 1 = failsafe, 2 = failsafe + network */
233 sysMetrics[SM_CLEANBOOT] = 0;
235 sysMetrics[SM_CXDRAG] = 2;
236 sysMetrics[SM_CYDRAG] = 2;
237 sysMetrics[SM_SHOWSOUNDS] = 0;
238 sysMetrics[SM_CXMENUCHECK] = 14;
239 sysMetrics[SM_CYMENUCHECK] = 14;
241 /* FIXME: Should check the type of processor for the following */
242 sysMetrics[SM_SLOWMACHINE] = 0;
244 /* FIXME: Should perform a check */
245 sysMetrics[SM_MIDEASTENABLED] = 0;
247 sysMetrics[SM_MOUSEWHEELPRESENT] = 0;
249 sysMetrics[SM_CXVIRTUALSCREEN] = sysMetrics[SM_CXSCREEN];
250 sysMetrics[SM_CYVIRTUALSCREEN] = sysMetrics[SM_CYSCREEN];
251 sysMetrics[SM_XVIRTUALSCREEN] = 0;
252 sysMetrics[SM_YVIRTUALSCREEN] = 0;
253 sysMetrics[SM_CMONITORS] = 1;
254 sysMetrics[SM_SAMEDISPLAYFORMAT] = 1;
255 sysMetrics[SM_CMETRICS] = SM_CMETRICS;
257 if (hkey) RegCloseKey (hkey);
258 DeleteDC( hdc );
262 /***********************************************************************
263 * GetSystemMetrics (USER.179)
265 INT16 WINAPI GetSystemMetrics16( INT16 index )
267 return (INT16)GetSystemMetrics(index);
271 /***********************************************************************
272 * GetSystemMetrics (USER32.@)
274 INT WINAPI GetSystemMetrics( INT index )
276 if ((index < 0) || (index > SM_WINE_CMETRICS)) return 0;
277 else return sysMetrics[index];