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