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