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