[WIN32K:NTUSER]
[reactos.git] / reactos / win32ss / user / ntuser / ntuser.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: ntuser init. and main funcs.
5 * FILE: win32ss/user/ntuser/ntuser.c
6 */
7
8 #include <win32k.h>
9 DBG_DEFAULT_CHANNEL(UserMisc);
10
11 BOOL FASTCALL RegisterControlAtoms(VOID);
12
13 /* GLOBALS ********************************************************************/
14
15 PTHREADINFO gptiCurrent = NULL;
16 PPROCESSINFO gppiInputProvider = NULL;
17 BOOL g_AlwaysDisplayVersion = FALSE;
18 ERESOURCE UserLock;
19 ATOM AtomMessage; // Window Message atom.
20 ATOM AtomWndObj; // Window Object atom.
21 ATOM AtomLayer; // Window Layer atom.
22 ATOM AtomFlashWndState; // Window Flash State atom.
23 ATOM AtomDDETrack; // Window DDE Tracking atom.
24 ATOM AtomQOS; // Window DDE Quality of Service atom.
25 HINSTANCE hModClient = NULL;
26 BOOL ClientPfnInit = FALSE;
27 ATOM gaGuiConsoleWndClass;
28
29 /* PRIVATE FUNCTIONS **********************************************************/
30
31 static
32 NTSTATUS FASTCALL
33 InitUserAtoms(VOID)
34 {
35 RegisterControlAtoms();
36
37 gpsi->atomSysClass[ICLS_MENU] = 32768;
38 gpsi->atomSysClass[ICLS_DESKTOP] = 32769;
39 gpsi->atomSysClass[ICLS_DIALOG] = 32770;
40 gpsi->atomSysClass[ICLS_SWITCH] = 32771;
41 gpsi->atomSysClass[ICLS_ICONTITLE] = 32772;
42 gpsi->atomSysClass[ICLS_TOOLTIPS] = 32774;
43
44 /* System Message Atom */
45 AtomMessage = IntAddGlobalAtom(L"Message", TRUE);
46 gpsi->atomSysClass[ICLS_HWNDMESSAGE] = AtomMessage;
47
48 /* System Context Help Id Atom */
49 gpsi->atomContextHelpIdProp = IntAddGlobalAtom(L"SysCH", TRUE);
50
51 gpsi->atomIconSmProp = IntAddGlobalAtom(L"SysICS", TRUE);
52 gpsi->atomIconProp = IntAddGlobalAtom(L"SysIC", TRUE);
53
54 gpsi->atomFrostedWindowProp = IntAddGlobalAtom(L"SysFrostedWindow", TRUE);
55
56 AtomDDETrack = IntAddGlobalAtom(L"SysDT", TRUE);
57 AtomQOS = IntAddGlobalAtom(L"SysQOS", TRUE);
58
59 /*
60 * FIXME: AddPropW uses the global kernel atom table, thus leading to conflicts if we use
61 * the win32k atom table for this one. What is the right thing to do ?
62 */
63 // AtomWndObj = IntAddGlobalAtom(L"SysWNDO", TRUE);
64 NtAddAtom(L"SysWNDO", 14, &AtomWndObj);
65
66 AtomLayer = IntAddGlobalAtom(L"SysLayer", TRUE);
67 AtomFlashWndState = IntAddGlobalAtom(L"FlashWState", TRUE);
68
69 return STATUS_SUCCESS;
70 }
71
72 /* FUNCTIONS ******************************************************************/
73
74 INIT_FUNCTION
75 NTSTATUS
76 NTAPI
77 InitUserImpl(VOID)
78 {
79 NTSTATUS Status;
80 HKEY hKey;
81
82 ExInitializeResourceLite(&UserLock);
83
84 if (!UserCreateHandleTable())
85 {
86 ERR("Failed creating handle table\n");
87 return STATUS_INSUFFICIENT_RESOURCES;
88 }
89
90 Status = InitSessionImpl();
91 if (!NT_SUCCESS(Status))
92 {
93 ERR("Error init session impl.\n");
94 return Status;
95 }
96
97 InitUserAtoms();
98
99 Status = RegOpenKey(L"\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows",
100 &hKey);
101 if (NT_SUCCESS(Status))
102 {
103 DWORD dwValue = 0;
104 RegReadDWORD(hKey, L"DisplayVersion", &dwValue);
105 g_AlwaysDisplayVersion = !!dwValue;
106 ZwClose(hKey);
107 }
108
109 InitSysParams();
110
111 return STATUS_SUCCESS;
112 }
113
114 NTSTATUS
115 NTAPI
116 InitVideo();
117
118 NTSTATUS
119 NTAPI
120 UserInitialize(VOID)
121 {
122 static const DWORD wPattern55AA[] = /* 32 bit aligned */
123 { 0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
124 0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa };
125 HBITMAP hPattern55AABitmap = NULL;
126 NTSTATUS Status;
127
128 NT_ASSERT(PsGetCurrentThreadWin32Thread() != NULL);
129
130 // Create Event for Disconnect Desktop.
131
132 Status = UserCreateWinstaDirectory();
133 if (!NT_SUCCESS(Status)) return Status;
134
135 /* Initialize Video */
136 Status = InitVideo();
137 if (!NT_SUCCESS(Status)) return Status;
138
139 // {
140 // DrvInitConsole.
141 // DrvChangeDisplaySettings.
142 // Update Shared Device Caps.
143 // Initialize User Screen.
144 // }
145
146 // Set Global SERVERINFO Error flags.
147 // Load Resources.
148
149 NtUserUpdatePerUserSystemParameters(0, TRUE);
150
151 if (gpsi->hbrGray == NULL)
152 {
153 hPattern55AABitmap = GreCreateBitmap(8, 8, 1, 1, (LPBYTE)wPattern55AA);
154 if (hPattern55AABitmap == NULL)
155 return STATUS_INSUFFICIENT_RESOURCES;
156
157 //NT_VERIFY(GreSetBitmapOwner(hPattern55AABitmap, GDI_OBJ_HMGR_PUBLIC));
158 gpsi->hbrGray = IntGdiCreatePatternBrush(hPattern55AABitmap);
159 GreDeleteObject(hPattern55AABitmap);
160 if (gpsi->hbrGray == NULL)
161 return STATUS_INSUFFICIENT_RESOURCES;
162 }
163
164 return STATUS_SUCCESS;
165 }
166
167 /*
168 * Called from usersrv.
169 */
170 NTSTATUS
171 APIENTRY
172 NtUserInitialize(
173 DWORD dwWinVersion,
174 HANDLE hPowerRequestEvent,
175 HANDLE hMediaRequestEvent)
176 {
177 NTSTATUS Status;
178
179 TRACE("Enter NtUserInitialize(%lx, %p, %p)\n",
180 dwWinVersion, hPowerRequestEvent, hMediaRequestEvent);
181
182 /* Check if we are already initialized */
183 if (gpepCSRSS)
184 return STATUS_UNSUCCESSFUL;
185
186 /* Check Windows USER subsystem version */
187 if (dwWinVersion != USER_VERSION)
188 {
189 // FIXME: Should bugcheck!
190 return STATUS_UNSUCCESSFUL;
191 }
192
193 /* Acquire exclusive lock */
194 UserEnterExclusive();
195
196 /* Save the EPROCESS of CSRSS */
197 InitCsrProcess(/*PsGetCurrentProcess()*/);
198
199 // Initialize Power Request List (use hPowerRequestEvent).
200 // Initialize Media Change (use hMediaRequestEvent).
201
202 // InitializeGreCSRSS();
203 // {
204 // Startup DxGraphics.
205 // calls ** UserGetLanguageID() and sets it **.
206 // Enables Fonts drivers, Initialize Font table & Stock Fonts.
207 // }
208
209 /* Initialize USER */
210 Status = UserInitialize();
211
212 /* Return */
213 UserLeave();
214 return Status;
215 }
216
217
218 /*
219 RETURN
220 True if current thread owns the lock (possibly shared)
221 */
222 BOOL FASTCALL UserIsEntered(VOID)
223 {
224 return ExIsResourceAcquiredExclusiveLite(&UserLock) ||
225 ExIsResourceAcquiredSharedLite(&UserLock);
226 }
227
228 BOOL FASTCALL UserIsEnteredExclusive(VOID)
229 {
230 return ExIsResourceAcquiredExclusiveLite(&UserLock);
231 }
232
233 VOID FASTCALL CleanupUserImpl(VOID)
234 {
235 ExDeleteResourceLite(&UserLock);
236 }
237
238 VOID FASTCALL UserEnterShared(VOID)
239 {
240 KeEnterCriticalRegion();
241 ExAcquireResourceSharedLite(&UserLock, TRUE);
242 }
243
244 VOID FASTCALL UserEnterExclusive(VOID)
245 {
246 ASSERT_NOGDILOCKS();
247 KeEnterCriticalRegion();
248 ExAcquireResourceExclusiveLite(&UserLock, TRUE);
249 gptiCurrent = PsGetCurrentThreadWin32Thread();
250 }
251
252 VOID FASTCALL UserLeave(VOID)
253 {
254 ASSERT_NOGDILOCKS();
255 ASSERT(UserIsEntered());
256 ExReleaseResourceLite(&UserLock);
257 KeLeaveCriticalRegion();
258 }
259
260 /* EOF */