xref: /reactos/win32ss/user/ntuser/metric.c (revision dad056e0)
1 /*
2  * COPYRIGHT:        See COPYING in the top level directory
3  * PROJECT:          ReactOS Win32k subsystem
4  * PURPOSE:          Window classes
5  * FILE:             win32ss/user/ntuser/metric.c
6  * PROGRAMER:        Casper S. Hornstrup (chorns@users.sourceforge.net)
7  *                   Timo Kreuzer (timo.kreuzer@reactos.org)
8  */
9 
10 #include <win32k.h>
11 DBG_DEFAULT_CHANNEL(UserSysparams);
12 
13 static BOOL Setup = FALSE;
14 
15 /* FUNCTIONS *****************************************************************/
16 
17 BOOL FASTCALL UserIsDBCSEnabled(VOID)
18 {
19     return NLS_MB_CODE_PAGE_TAG;
20 }
21 
22 BOOL FASTCALL UserIsIMMEnabled(VOID)
23 {
24     if (NLS_MB_CODE_PAGE_TAG)
25         return TRUE;
26 
27     return !!RegGetSectionDWORD(L"IMM", L"LoadIMM", FALSE);
28 }
29 
30 BOOL FASTCALL UserIsCiceroEnabled(VOID)
31 {
32 #if 1
33     return FALSE; /* FIXME: Cicero is not supported yet */
34 #else
35     if (RegGetSectionDWORD(L"IMM", L"DontLoadCTFIME", FALSE))
36         return FALSE;
37 
38     return UserIsIMMEnabled();
39 #endif
40 }
41 
42 BOOL
43 NTAPI
44 InitMetrics(VOID)
45 {
46     INT *piSysMet = gpsi->aiSysMet;
47     ULONG Width, Height;
48 
49     /* Note: used for the SM_CLEANBOOT metric */
50     DWORD dwValue = 0;
51     HKEY hKey = 0;
52 
53     /* Clean boot */
54     piSysMet[SM_CLEANBOOT] = 0; // Fallback value of 0 (normal mode)
55     if(NT_SUCCESS(RegOpenKey(L"\\REGISTRY\\MACHINE\\SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Option", &hKey)))
56     {
57         if(RegReadDWORD(hKey, L"OptionValue", &dwValue)) piSysMet[SM_CLEANBOOT] = (INT)dwValue;
58         ZwClose(hKey);
59     }
60 
61     /* FIXME: HACK, due to missing MDEV on first init */
62     if (!gpmdev)
63     {
64         Width = 640;
65         Height = 480;
66     }
67     else
68     {
69         Width = gpmdev->ppdevGlobal->gdiinfo.ulHorzRes;
70         Height = gpmdev->ppdevGlobal->gdiinfo.ulVertRes;
71     }
72 
73     /* Screen sizes */
74     piSysMet[SM_CXSCREEN] = Width;
75     piSysMet[SM_CYSCREEN] = Height;
76     piSysMet[SM_XVIRTUALSCREEN] = 0;
77     piSysMet[SM_YVIRTUALSCREEN] = 0;
78     piSysMet[SM_CXVIRTUALSCREEN] = Width;
79     piSysMet[SM_CYVIRTUALSCREEN] = Height;
80 
81     /* NC area sizes */
82     piSysMet[SM_CYCAPTION] = gspv.ncm.iCaptionHeight + 1;       // 19
83     piSysMet[SM_CYSMCAPTION] = gspv.ncm.iSmCaptionHeight + 1;   // 15;
84     piSysMet[SM_CXSIZE] = gspv.ncm.iCaptionHeight;              // 18;
85     piSysMet[SM_CYSIZE] = gspv.ncm.iCaptionHeight;              // 18;
86     piSysMet[SM_CXSMSIZE] = gspv.ncm.iSmCaptionWidth;   // 12; XP: piSysMet(SM_CYSMCAPTION) - 1
87     piSysMet[SM_CYSMSIZE] = gspv.ncm.iSmCaptionHeight;  // 14;
88     piSysMet[SM_CXBORDER] = 1; // Seems to be hardcoded
89     piSysMet[SM_CYBORDER] = 1; // Seems to be hardcoded
90     piSysMet[SM_CXFOCUSBORDER] = 1;
91     piSysMet[SM_CYFOCUSBORDER] = 1;
92     piSysMet[SM_CXDLGFRAME] = 3;
93     piSysMet[SM_CYDLGFRAME] = 3;
94     piSysMet[SM_CXEDGE] = 2;
95     piSysMet[SM_CYEDGE] = 2;
96     piSysMet[SM_CXFRAME] = piSysMet[SM_CXDLGFRAME] + gspv.ncm.iBorderWidth; // 4
97     piSysMet[SM_CYFRAME] = piSysMet[SM_CYDLGFRAME] + gspv.ncm.iBorderWidth; // 4
98 #if (_WIN32_WINNT >= 0x0600)
99     piSysMet[SM_CXPADDEDBORDER] = 0;
100 #endif
101 
102     /* Window sizes */
103     TRACE("ncm.iCaptionWidth=%d,GetSystemMetrics(SM_CYSIZE)=%d,GetSystemMetrics(SM_CXFRAME)=%d,avcwCaption=%d \n",
104            gspv.ncm.iCaptionWidth, piSysMet[SM_CYSIZE],piSysMet[SM_CXFRAME], gspv.tmCaptionFont.tmAveCharWidth);
105 
106     piSysMet[SM_CXMIN] = 3 * max(gspv.ncm.iCaptionWidth, 8) // 112
107                          + piSysMet[SM_CYSIZE] + 4
108                          + 4 * gspv.tmCaptionFont.tmAveCharWidth
109                          + 2 * piSysMet[SM_CXFRAME];
110     piSysMet[SM_CYMIN] = piSysMet[SM_CYCAPTION] + 2 * piSysMet[SM_CYFRAME]; // 27
111     piSysMet[SM_CXMAXIMIZED] = piSysMet[SM_CXSCREEN] + 2 * piSysMet[SM_CXFRAME];
112     piSysMet[SM_CYMAXIMIZED] = piSysMet[SM_CYSCREEN] - 20;
113     piSysMet[SM_CXFULLSCREEN] = piSysMet[SM_CXSCREEN];
114     piSysMet[SM_CYFULLSCREEN] = piSysMet[SM_CYMAXIMIZED] - piSysMet[SM_CYMIN];
115     piSysMet[SM_CYKANJIWINDOW] = 0;
116     piSysMet[SM_CXMINIMIZED] = gspv.mm.iWidth + 6;
117     piSysMet[SM_CYMINIMIZED] = piSysMet[SM_CYCAPTION] + 5;
118     piSysMet[SM_CXMINSPACING] = piSysMet[SM_CXMINIMIZED] + gspv.mm.iHorzGap;
119     piSysMet[SM_CYMINSPACING] = piSysMet[SM_CYMINIMIZED] + gspv.mm.iVertGap;
120     piSysMet[SM_CXMAXTRACK] = piSysMet[SM_CXVIRTUALSCREEN] + 4
121                               + 2 * piSysMet[SM_CXFRAME];
122     piSysMet[SM_CYMAXTRACK] = piSysMet[SM_CYVIRTUALSCREEN] + 4
123                               + 2 * piSysMet[SM_CYFRAME];
124 
125     /* Icon */
126     piSysMet[SM_CXVSCROLL] = gspv.ncm.iScrollWidth;     // 16;
127     piSysMet[SM_CYVTHUMB] = gspv.ncm.iScrollHeight;     // 16;
128     piSysMet[SM_CYHSCROLL] = gspv.ncm.iScrollWidth;     // 16;
129     piSysMet[SM_CXHTHUMB] = gspv.ncm.iScrollHeight;     // 16;
130     piSysMet[SM_CYVSCROLL] = gspv.ncm.iScrollHeight;    // 16
131     piSysMet[SM_CXHSCROLL] = gspv.ncm.iScrollHeight;    // 16;
132     piSysMet[SM_CXICON] = 32;
133     piSysMet[SM_CYICON] = 32;
134     piSysMet[SM_CXSMICON] = 16;
135     piSysMet[SM_CYSMICON] = 16;
136     piSysMet[SM_CXICONSPACING] = gspv.im.iHorzSpacing;  // 64;
137     piSysMet[SM_CYICONSPACING] = gspv.im.iVertSpacing;  // 64;
138     piSysMet[SM_CXCURSOR] = 32;
139     piSysMet[SM_CYCURSOR] = 32;
140     piSysMet[SM_CXMINTRACK] = piSysMet[SM_CXMIN];       // 117
141     piSysMet[SM_CYMINTRACK] = piSysMet[SM_CYMIN];       // 27
142     piSysMet[SM_CXDRAG] = 4;
143     piSysMet[SM_CYDRAG] = 4;
144     piSysMet[SM_ARRANGE] = gspv.mm.iArrange;            // 8;
145 
146     /* Menu */
147     piSysMet[SM_CYMENU] = gspv.ncm.iMenuHeight + 1;     // 19;
148     piSysMet[SM_MENUDROPALIGNMENT] = gspv.bMenuDropAlign;
149     piSysMet[SM_CXMENUCHECK] = ((1 + gspv.tmMenuFont.tmHeight +
150                                  gspv.tmMenuFont.tmExternalLeading) & ~1) - 1; // 13;
151     piSysMet[SM_CYMENUCHECK] = piSysMet[SM_CXMENUCHECK];
152     piSysMet[SM_CXMENUSIZE] = gspv.ncm.iMenuWidth;      // 18;
153     piSysMet[SM_CYMENUSIZE] = gspv.ncm.iMenuHeight;     // 18;
154 
155     /* Mouse */
156     piSysMet[SM_MOUSEPRESENT] = 1;
157     piSysMet[SM_MOUSEWHEELPRESENT] = 1;
158     piSysMet[SM_CMOUSEBUTTONS] = 2;
159     piSysMet[SM_SWAPBUTTON] = gspv.bMouseBtnSwap ? 1 : 0;
160     piSysMet[SM_CXDOUBLECLK] = gspv.iDblClickWidth;
161     piSysMet[SM_CYDOUBLECLK] = gspv.iDblClickHeight;
162 #if (_WIN32_WINNT >= 0x0600)
163     piSysMet[SM_MOUSEHORIZONTALWHEELPRESENT] = 0;
164 #endif
165 
166     /* Version info */
167     piSysMet[SM_TABLETPC] = 0;
168     piSysMet[SM_MEDIACENTER] = 0;
169     piSysMet[SM_STARTER] = 0;
170     piSysMet[SM_SERVERR2] = 0;
171     piSysMet[SM_PENWINDOWS] = 0;
172 
173     /* Other */
174     piSysMet[SM_DEBUG] = 0;
175     piSysMet[SM_NETWORK] = 3;
176     piSysMet[SM_SLOWMACHINE] = 0;
177     piSysMet[SM_SECURE] = 0;
178     piSysMet[SM_DBCSENABLED] = NLS_MB_CODE_PAGE_TAG;
179     piSysMet[SM_SHOWSOUNDS] = gspv.bShowSounds;
180     piSysMet[SM_MIDEASTENABLED] = 0;
181     piSysMet[SM_CMONITORS] = 1;
182     piSysMet[SM_SAMEDISPLAYFORMAT] = 1;
183     piSysMet[SM_IMMENABLED] = NLS_MB_CODE_PAGE_TAG;
184 
185     /* Reserved */
186     piSysMet[SM_RESERVED1] = 0;
187     piSysMet[SM_RESERVED2] = 0;
188     piSysMet[SM_RESERVED3] = 0;
189     piSysMet[SM_RESERVED4] = 0;
190     piSysMet[64] = 0;
191     piSysMet[65] = 0;
192     piSysMet[66] = 0;
193 #if (_WIN32_WINNT >= 0x0600)
194     piSysMet[90] = 0;
195 #endif
196 
197     if (UserIsDBCSEnabled())
198         gpsi->dwSRVIFlags |= SRVINFO_DBCSENABLED; /* DBCS Support */
199 
200     if (UserIsIMMEnabled())
201         gpsi->dwSRVIFlags |= SRVINFO_IMM32; /* IME Support */
202 
203     if (UserIsCiceroEnabled())
204         gpsi->dwSRVIFlags |= SRVINFO_CICERO_ENABLED; /* Cicero support */
205 
206     Setup = TRUE;
207 
208     return TRUE;
209 }
210 
211 LONG
212 NTAPI
213 UserGetSystemMetrics(ULONG Index)
214 {
215     ASSERT(gpsi);
216     ASSERT(Setup);
217     TRACE("UserGetSystemMetrics(%lu)\n", Index);
218 
219     if (Index == SM_DBCSENABLED)
220         return !!(gpsi->dwSRVIFlags & SRVINFO_DBCSENABLED);
221 
222     if (Index == SM_IMMENABLED)
223         return !!(gpsi->dwSRVIFlags & SRVINFO_IMM32);
224 
225     /* Get metrics from array */
226     if (Index < SM_CMETRICS)
227     {
228         return gpsi->aiSysMet[Index];
229     }
230 
231     /* Handle special values */
232     switch (Index)
233     {
234         case SM_REMOTESESSION:
235             return 0; // FIXME
236 
237         case SM_SHUTTINGDOWN:
238             return 0; // FIXME
239 
240         case SM_REMOTECONTROL:
241             return 0; // FIXME
242     }
243 
244     ERR("UserGetSystemMetrics() called with invalid index %lu\n", Index);
245     return 0;
246 }
247 
248 /* EOF */
249