Fixed some issues found by winapi_check.
[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 "user.h"
19 #include "sysmetrics.h"
20
21 static int sysMetrics[SM_WINE_CMETRICS+1];
22
23 static int SYSMETRICS_GetProfileInt(const char *section, const char *key,
24                                     int default_value)
25 {
26     int ret = default_value;
27     char buffer[1024];
28     HKEY hkey;
29
30     strcpy(buffer, "Software\\Wine\\Wine\\Config\\");
31     strncat(buffer, section, sizeof(buffer) - strlen(buffer));
32
33     if(!RegOpenKeyA(HKEY_LOCAL_MACHINE, buffer, &hkey))
34     {
35         DWORD type, count = sizeof(buffer);
36         if(!RegQueryValueExA(hkey, key, 0, &type, buffer, &count))
37             ret = atoi(buffer);
38         RegCloseKey(hkey);
39     }
40     return ret;
41 }
42
43 /***********************************************************************
44  *           SYSMETRICS_Init
45  *
46  * Initialisation of the system metrics array.
47  *
48  * Differences in return values between 3.1 and 95 apps under Win95 (FIXME ?):
49  * SM_CXVSCROLL        x+1      x       Fixed May 24, 1999 - Ronald B. Cemer
50  * SM_CYHSCROLL        x+1      x       Fixed May 24, 1999 - Ronald B. Cemer
51  * SM_CXDLGFRAME       x-1      x       Already fixed
52  * SM_CYDLGFRAME       x-1      x       Already fixed
53  * SM_CYCAPTION        x+1      x       Fixed May 24, 1999 - Ronald B. Cemer
54  * SM_CYMENU           x-1      x       Already fixed
55  * SM_CYFULLSCREEN     x-1      x
56  * 
57  * (collides with TWEAK_WineLook sometimes,
58  * so changing anything might be difficult) 
59  */
60 void SYSMETRICS_Init(void)
61 {
62     HDC hdc = CreateDCA( "DISPLAY", NULL, NULL, NULL );
63     assert(hdc);
64
65     sysMetrics[SM_CXCURSOR] = 32;
66     sysMetrics[SM_CYCURSOR] = 32;
67     sysMetrics[SM_CXSCREEN] = GetDeviceCaps( hdc, HORZRES );
68     sysMetrics[SM_CYSCREEN] = GetDeviceCaps( hdc, VERTRES );
69     sysMetrics[SM_WINE_BPP] = GetDeviceCaps( hdc, BITSPIXEL );
70     if (TWEAK_WineLook > WIN31_LOOK)
71         sysMetrics[SM_CXVSCROLL] =
72             SYSMETRICS_GetProfileInt("Tweak.Layout", "ScrollBarWidth", 16);
73     else
74         sysMetrics[SM_CXVSCROLL] =
75             SYSMETRICS_GetProfileInt("Tweak.Layout", "ScrollBarWidth", 17);
76     sysMetrics[SM_CYHSCROLL] = sysMetrics[SM_CXVSCROLL];
77     if (TWEAK_WineLook > WIN31_LOOK)
78         sysMetrics[SM_CYCAPTION] =
79             SYSMETRICS_GetProfileInt("Tweak.Layout", "CaptionHeight", 19);
80     else
81         sysMetrics[SM_CYCAPTION] =
82             SYSMETRICS_GetProfileInt("Tweak.Layout", "CaptionHeight", 20);
83     sysMetrics[SM_CXBORDER] = 1;
84     sysMetrics[SM_CYBORDER] = sysMetrics[SM_CXBORDER];
85     sysMetrics[SM_CXDLGFRAME] =
86         SYSMETRICS_GetProfileInt("Tweak.Layout", "DialogFrameWidth",
87                               (TWEAK_WineLook > WIN31_LOOK) ? 3 : 4);
88     sysMetrics[SM_CYDLGFRAME] = sysMetrics[SM_CXDLGFRAME];
89     sysMetrics[SM_CYVTHUMB] = sysMetrics[SM_CXVSCROLL] - 1;
90     sysMetrics[SM_CXHTHUMB] = sysMetrics[SM_CYVTHUMB];
91     sysMetrics[SM_CXICON] = 32;
92     sysMetrics[SM_CYICON] = 32;
93     if (TWEAK_WineLook > WIN31_LOOK)
94         sysMetrics[SM_CYMENU] =
95             SYSMETRICS_GetProfileInt("Tweak.Layout", "MenuHeight", 19);
96     else
97         sysMetrics[SM_CYMENU] =
98             SYSMETRICS_GetProfileInt("Tweak.Layout", "MenuHeight", 18);
99     sysMetrics[SM_CXFULLSCREEN] = sysMetrics[SM_CXSCREEN];
100     sysMetrics[SM_CYFULLSCREEN] =
101         sysMetrics[SM_CYSCREEN] - sysMetrics[SM_CYCAPTION];
102     sysMetrics[SM_CYKANJIWINDOW] = 0;
103     sysMetrics[SM_MOUSEPRESENT] = 1;
104     sysMetrics[SM_CYVSCROLL] = sysMetrics[SM_CYVTHUMB];
105     sysMetrics[SM_CXHSCROLL] = sysMetrics[SM_CXHTHUMB];
106     sysMetrics[SM_DEBUG] = 0;
107
108     /* FIXME: The following should look for the registry key to see if the
109        buttons should be swapped. */
110     sysMetrics[SM_SWAPBUTTON] = 0;
111
112     sysMetrics[SM_RESERVED1] = 0;
113     sysMetrics[SM_RESERVED2] = 0;
114     sysMetrics[SM_RESERVED3] = 0;
115     sysMetrics[SM_RESERVED4] = 0;
116
117     /* FIXME: The following two are calculated, but how? */
118     sysMetrics[SM_CXMIN] = (TWEAK_WineLook > WIN31_LOOK) ? 112 : 100;
119     sysMetrics[SM_CYMIN] = (TWEAK_WineLook > WIN31_LOOK) ? 27 : 28;
120
121     sysMetrics[SM_CXSIZE] = sysMetrics[SM_CYCAPTION] - 2;
122     sysMetrics[SM_CYSIZE] = sysMetrics[SM_CXSIZE];
123     sysMetrics[SM_CXFRAME] = GetProfileIntA("Windows", "BorderWidth", 4) + 1;
124     sysMetrics[SM_CYFRAME] = sysMetrics[SM_CXFRAME];
125     sysMetrics[SM_CXMINTRACK] = sysMetrics[SM_CXMIN];
126     sysMetrics[SM_CYMINTRACK] = sysMetrics[SM_CYMIN];
127     sysMetrics[SM_CXDOUBLECLK] =
128         (GetProfileIntA("Windows", "DoubleClickWidth", 4) + 1) & ~1;
129     sysMetrics[SM_CYDOUBLECLK] =
130         (GetProfileIntA("Windows","DoubleClickHeight", 4) + 1) & ~1;
131     sysMetrics[SM_CXICONSPACING] =
132         GetProfileIntA("Desktop","IconSpacing", 75);
133     sysMetrics[SM_CYICONSPACING] =
134         GetProfileIntA("Desktop", "IconVerticalSpacing", 75);
135     sysMetrics[SM_MENUDROPALIGNMENT] =
136         GetProfileIntA("Windows", "MenuDropAlignment", 0);
137     sysMetrics[SM_PENWINDOWS] = 0;
138     sysMetrics[SM_DBCSENABLED] = 0;
139
140     /* FIXME: Need to query X for the following */
141     sysMetrics[SM_CMOUSEBUTTONS] = 3;
142
143     sysMetrics[SM_SECURE] = 0;
144     sysMetrics[SM_CXEDGE] = sysMetrics[SM_CXBORDER] + 1;
145     sysMetrics[SM_CYEDGE] = sysMetrics[SM_CXEDGE];
146     sysMetrics[SM_CXMINSPACING] = 160;
147     sysMetrics[SM_CYMINSPACING] = 24;
148     sysMetrics[SM_CXSMICON] = sysMetrics[SM_CYSIZE] - (sysMetrics[SM_CYSIZE] % 2);
149     sysMetrics[SM_CYSMICON] = sysMetrics[SM_CXSMICON];
150     sysMetrics[SM_CYSMCAPTION] = 16;
151     sysMetrics[SM_CXSMSIZE] = 15;
152     sysMetrics[SM_CYSMSIZE] = sysMetrics[SM_CXSMSIZE];
153     sysMetrics[SM_CXMENUSIZE] = sysMetrics[SM_CYMENU];
154     sysMetrics[SM_CYMENUSIZE] = sysMetrics[SM_CXMENUSIZE];
155
156     /* FIXME: What do these mean? */
157     sysMetrics[SM_ARRANGE] = ARW_HIDE;
158     sysMetrics[SM_CXMINIMIZED] = 160;
159     sysMetrics[SM_CYMINIMIZED] = 24;
160
161     /* FIXME: How do I calculate these? */
162     sysMetrics[SM_CXMAXTRACK] = 
163         sysMetrics[SM_CXSCREEN] + 4 + 2 * sysMetrics[SM_CXFRAME];
164     sysMetrics[SM_CYMAXTRACK] =
165         sysMetrics[SM_CYSCREEN] + 4 + 2 * sysMetrics[SM_CYFRAME];
166     sysMetrics[SM_CXMAXIMIZED] =
167         sysMetrics[SM_CXSCREEN] + 2 * sysMetrics[SM_CXFRAME];
168     sysMetrics[SM_CYMAXIMIZED] =
169         sysMetrics[SM_CYSCREEN] - 45;
170     sysMetrics[SM_NETWORK] = 3;
171
172     /* For the following: 0 = ok, 1 = failsafe, 2 = failsafe + network */
173     sysMetrics[SM_CLEANBOOT] = 0;
174
175     sysMetrics[SM_CXDRAG] = 2;
176     sysMetrics[SM_CYDRAG] = 2;
177     sysMetrics[SM_SHOWSOUNDS] = 0;
178     sysMetrics[SM_CXMENUCHECK] = 14;
179     sysMetrics[SM_CYMENUCHECK] = 14;
180
181     /* FIXME: Should check the type of processor for the following */
182     sysMetrics[SM_SLOWMACHINE] = 0;
183
184     /* FIXME: Should perform a check */
185     sysMetrics[SM_MIDEASTENABLED] = 0;
186
187     sysMetrics[SM_MOUSEWHEELPRESENT] = 0;
188     
189     sysMetrics[SM_CXVIRTUALSCREEN] = sysMetrics[SM_CXSCREEN];
190     sysMetrics[SM_CYVIRTUALSCREEN] = sysMetrics[SM_CYSCREEN];
191     sysMetrics[SM_XVIRTUALSCREEN] = 0;
192     sysMetrics[SM_YVIRTUALSCREEN] = 0;
193     sysMetrics[SM_CMONITORS] = 1;
194     sysMetrics[SM_SAMEDISPLAYFORMAT] = 1;
195     sysMetrics[SM_CMETRICS] = SM_CMETRICS;
196
197     DeleteDC( hdc );
198 }
199
200
201 /***********************************************************************
202  *              GetSystemMetrics (USER.179)
203  */
204 INT16 WINAPI GetSystemMetrics16( INT16 index )
205 {
206     return (INT16)GetSystemMetrics(index);
207 }
208
209
210 /***********************************************************************
211  *              GetSystemMetrics (USER32.@)
212  */
213 INT WINAPI GetSystemMetrics( INT index )
214 {
215     if ((index < 0) || (index > SM_WINE_CMETRICS)) return 0;
216     else return sysMetrics[index];    
217 }