e51db8eb9a4ab31a96151ef0ac7af40e180e0c5a
[reactos.git] / subsystems / win32 / win32k / 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 * REVISION HISTORY:
7 * 16 July 2005 Created (hardon)
8 */
9
10 /* INCLUDES ******************************************************************/
11
12 #include <w32k.h>
13
14 #define NDEBUG
15 #include <debug.h>
16
17 BOOL InitSysParams();
18
19 /* GLOBALS *******************************************************************/
20
21 ERESOURCE UserLock;
22 ATOM AtomMessage; // Window Message atom.
23 ATOM AtomWndObj; // Window Object atom.
24 BOOL gbInitialized;
25 HINSTANCE hModClient = NULL;
26 BOOL ClientPfnInit = FALSE;
27
28 /* PRIVATE FUNCTIONS *********************************************************/
29
30 static
31 NTSTATUS FASTCALL
32 InitUserAtoms(VOID)
33 {
34
35 gpsi->atomSysClass[ICLS_MENU] = 32768;
36 gpsi->atomSysClass[ICLS_DESKTOP] = 32769;
37 gpsi->atomSysClass[ICLS_DIALOG] = 32770;
38 gpsi->atomSysClass[ICLS_SWITCH] = 32771;
39 gpsi->atomSysClass[ICLS_ICONTITLE] = 32772;
40 gpsi->atomSysClass[ICLS_TOOLTIPS] = 32774;
41
42 /* System Message Atom */
43 AtomMessage = IntAddGlobalAtom(L"Message", TRUE);
44 gpsi->atomSysClass[ICLS_HWNDMESSAGE] = AtomMessage;
45
46 /* System Context Help Id Atom */
47 gpsi->atomContextHelpIdProp = IntAddGlobalAtom(L"SysCH", TRUE);
48
49 AtomWndObj = IntAddGlobalAtom(L"SysWNDO", TRUE);
50
51 return STATUS_SUCCESS;
52 }
53
54 /* FUNCTIONS *****************************************************************/
55
56
57 NTSTATUS FASTCALL InitUserImpl(VOID)
58 {
59 NTSTATUS Status;
60
61 ExInitializeResourceLite(&UserLock);
62
63 if (!UserCreateHandleTable())
64 {
65 DPRINT1("Failed creating handle table\n");
66 return STATUS_INSUFFICIENT_RESOURCES;
67 }
68
69 Status = InitSessionImpl();
70 if (!NT_SUCCESS(Status))
71 {
72 DPRINT1("Error init session impl.\n");
73 return Status;
74 }
75
76 if (!gpsi)
77 {
78 gpsi = UserHeapAlloc(sizeof(SERVERINFO));
79 if (gpsi)
80 {
81 RtlZeroMemory(gpsi, sizeof(SERVERINFO));
82 DPRINT("Global Server Data -> %x\n", gpsi);
83 }
84 }
85
86 InitUserAtoms();
87
88 InitSysParams();
89
90 return STATUS_SUCCESS;
91 }
92
93
94 NTSTATUS
95 NTAPI
96 UserInitialize(
97 HANDLE hPowerRequestEvent,
98 HANDLE hMediaRequestEvent)
99 {
100 NTSTATUS Status;
101
102 // Set W32PF_Flags |= (W32PF_READSCREENACCESSGRANTED | W32PF_IOWINSTA)
103 // Create Object Directory,,, Looks like create workstation. "\\Windows\\WindowStations"
104 // Create Event for Diconnect Desktop.
105 // Initialize Video.
106 // {
107 // DrvInitConsole.
108 // DrvChangeDisplaySettings.
109 // Update Shared Device Caps.
110 // Initialize User Screen.
111 // }
112 // Create ThreadInfo for this Thread!
113 // {
114
115 GetW32ThreadInfo();
116
117 // Callback to User32 Client Thread Setup
118
119 Status = co_IntClientThreadSetup();
120
121 // }
122 // Set Global SERVERINFO Error flags.
123 // Load Resources.
124
125 NtUserUpdatePerUserSystemParameters(0, TRUE);
126
127 return STATUS_SUCCESS;
128 }
129
130 /*
131 Called from win32csr.
132 */
133 NTSTATUS
134 APIENTRY
135 NtUserInitialize(
136 DWORD dwWinVersion,
137 HANDLE hPowerRequestEvent,
138 HANDLE hMediaRequestEvent)
139 {
140 NTSTATUS Status;
141
142 DPRINT("Enter NtUserInitialize(%lx, %p, %p)\n",
143 dwWinVersion, hPowerRequestEvent, hMediaRequestEvent);
144
145 /* Check the Windows version */
146 if (dwWinVersion != 0)
147 {
148 return STATUS_UNSUCCESSFUL;
149 }
150
151 /* Acquire exclusive lock */
152 UserEnterExclusive();
153
154 /* Check if we are already initialized */
155 if (gbInitialized)
156 {
157 UserLeave();
158 return STATUS_UNSUCCESSFUL;
159 }
160
161 // Initialize Power Request List.
162 // Initialize Media Change.
163 // InitializeGreCSRSS();
164 // {
165 // Startup DxGraphics.
166 // calls ** IntGdiGetLanguageID() and sets it **.
167 // Enables Fonts drivers, Initialize Font table & Stock Fonts.
168 // }
169
170 /* Initialize USER */
171 Status = UserInitialize(hPowerRequestEvent, hMediaRequestEvent);
172
173 /* Set us as initialized */
174 gbInitialized = TRUE;
175
176 /* Return */
177 UserLeave();
178 return Status;
179 }
180
181
182 /*
183 RETURN
184 True if current thread owns the lock (possibly shared)
185 */
186 BOOL FASTCALL UserIsEntered(VOID)
187 {
188 return ExIsResourceAcquiredExclusiveLite(&UserLock)
189 || ExIsResourceAcquiredSharedLite(&UserLock);
190 }
191
192 BOOL FASTCALL UserIsEnteredExclusive(VOID)
193 {
194 return ExIsResourceAcquiredExclusiveLite(&UserLock);
195 }
196
197 VOID FASTCALL CleanupUserImpl(VOID)
198 {
199 ExDeleteResourceLite(&UserLock);
200 }
201
202 VOID FASTCALL UserEnterShared(VOID)
203 {
204 KeEnterCriticalRegion();
205 ExAcquireResourceSharedLite(&UserLock, TRUE);
206 }
207
208 VOID FASTCALL UserEnterExclusive(VOID)
209 {
210 KeEnterCriticalRegion();
211 ExAcquireResourceExclusiveLite(&UserLock, TRUE);
212 }
213
214 VOID FASTCALL UserLeave(VOID)
215 {
216 ExReleaseResourceLite(&UserLock);
217 KeLeaveCriticalRegion();
218 }