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