f496e420a155f2cbc39ff1cf61fd1a5bd8a6241f
[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 AtomWndObj = IntAddGlobalAtom(L"SysWNDO", TRUE);
53 AtomLayer = IntAddGlobalAtom(L"SysLayer", TRUE);
54 AtomFlashWndState = IntAddGlobalAtom(L"FlashWState", TRUE);
55
56 return STATUS_SUCCESS;
57 }
58
59 /* FUNCTIONS *****************************************************************/
60
61 INIT_FUNCTION
62 NTSTATUS
63 NTAPI
64 InitUserImpl(VOID)
65 {
66 NTSTATUS Status;
67
68 ExInitializeResourceLite(&UserLock);
69
70 if (!UserCreateHandleTable())
71 {
72 ERR("Failed creating handle table\n");
73 return STATUS_INSUFFICIENT_RESOURCES;
74 }
75
76 Status = InitSessionImpl();
77 if (!NT_SUCCESS(Status))
78 {
79 ERR("Error init session impl.\n");
80 return Status;
81 }
82
83 InitUserAtoms();
84
85 InitSysParams();
86
87 return STATUS_SUCCESS;
88 }
89
90 NTSTATUS
91 NTAPI
92 InitVideo();
93
94 NTSTATUS
95 NTAPI
96 UserInitialize(
97 HANDLE hPowerRequestEvent,
98 HANDLE hMediaRequestEvent)
99 {
100 static const DWORD wPattern55AA[] = /* 32 bit aligned */
101 { 0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa,
102 0x55555555, 0xaaaaaaaa, 0x55555555, 0xaaaaaaaa };
103 HBITMAP hPattern55AABitmap = NULL;
104 NTSTATUS Status;
105
106 // Set W32PF_Flags |= (W32PF_READSCREENACCESSGRANTED | W32PF_IOWINSTA)
107 // Create Event for Diconnect Desktop.
108
109 Status = UserCreateWinstaDirectory();
110 if (!NT_SUCCESS(Status)) return Status;
111
112 /* Initialize Video. */
113 Status = InitVideo();
114 if (!NT_SUCCESS(Status)) return Status;
115
116 // {
117 // DrvInitConsole.
118 // DrvChangeDisplaySettings.
119 // Update Shared Device Caps.
120 // Initialize User Screen.
121 // }
122 // Create ThreadInfo for this Thread!
123 // {
124
125 /* Initialize the current thread. */
126 Status = UserCreateThreadInfo(PsGetCurrentThread());
127 if (!NT_SUCCESS(Status)) return Status;
128
129 // Callback to User32 Client Thread Setup
130
131 co_IntClientThreadSetup();
132
133 // }
134 // Set Global SERVERINFO Error flags.
135 // Load Resources.
136
137 NtUserUpdatePerUserSystemParameters(0, TRUE);
138
139 if (gpsi->hbrGray == NULL)
140 {
141 hPattern55AABitmap = GreCreateBitmap(8, 8, 1, 1, (LPBYTE)wPattern55AA);
142 gpsi->hbrGray = IntGdiCreatePatternBrush(hPattern55AABitmap);
143 GreDeleteObject(hPattern55AABitmap);
144 GreSetBrushOwner(gpsi->hbrGray, GDI_OBJ_HMGR_PUBLIC);
145 }
146
147 return STATUS_SUCCESS;
148 }
149
150 /*
151 Called from win32csr.
152 */
153 NTSTATUS
154 APIENTRY
155 NtUserInitialize(
156 DWORD dwWinVersion,
157 HANDLE hPowerRequestEvent,
158 HANDLE hMediaRequestEvent)
159 {
160 NTSTATUS Status;
161
162 ERR("Enter NtUserInitialize(%lx, %p, %p)\n",
163 dwWinVersion, hPowerRequestEvent, hMediaRequestEvent);
164
165 /* Check the Windows version */
166 if (dwWinVersion != 0)
167 {
168 return STATUS_UNSUCCESSFUL;
169 }
170
171 /* Acquire exclusive lock */
172 UserEnterExclusive();
173
174 /* Check if we are already initialized */
175 if (gbInitialized)
176 {
177 UserLeave();
178 return STATUS_UNSUCCESSFUL;
179 }
180
181 /* Save EPROCESS of CSRSS */
182 gpepCSRSS = PsGetCurrentProcess();
183
184 // Initialize Power Request List.
185 // Initialize Media Change.
186 // InitializeGreCSRSS();
187 // {
188 // Startup DxGraphics.
189 // calls ** UserGetLanguageID() and sets it **.
190 // Enables Fonts drivers, Initialize Font table & Stock Fonts.
191 // }
192
193 /* Initialize USER */
194 Status = UserInitialize(hPowerRequestEvent, hMediaRequestEvent);
195
196 /* Set us as initialized */
197 gbInitialized = TRUE;
198
199 /* Return */
200 UserLeave();
201 return Status;
202 }
203
204
205 /*
206 RETURN
207 True if current thread owns the lock (possibly shared)
208 */
209 BOOL FASTCALL UserIsEntered(VOID)
210 {
211 return ExIsResourceAcquiredExclusiveLite(&UserLock)
212 || ExIsResourceAcquiredSharedLite(&UserLock);
213 }
214
215 BOOL FASTCALL UserIsEnteredExclusive(VOID)
216 {
217 return ExIsResourceAcquiredExclusiveLite(&UserLock);
218 }
219
220 VOID FASTCALL CleanupUserImpl(VOID)
221 {
222 ExDeleteResourceLite(&UserLock);
223 }
224
225 VOID FASTCALL UserEnterShared(VOID)
226 {
227 KeEnterCriticalRegion();
228 ExAcquireResourceSharedLite(&UserLock, TRUE);
229 }
230
231 VOID FASTCALL UserEnterExclusive(VOID)
232 {
233 ASSERT_NOGDILOCKS();
234 KeEnterCriticalRegion();
235 ExAcquireResourceExclusiveLite(&UserLock, TRUE);
236 gptiCurrent = PsGetCurrentThreadWin32Thread();
237 }
238
239 VOID FASTCALL UserLeave(VOID)
240 {
241 ASSERT_NOGDILOCKS();
242 ExReleaseResourceLite(&UserLock);
243 KeLeaveCriticalRegion();
244 }