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