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