1ca06aba1ccca956b5af3767e8c1c8fae5a71b78
[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 <win32k.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 InitUserAtoms();
77
78 InitSysParams();
79
80 return STATUS_SUCCESS;
81 }
82
83 BOOL
84 InitVideo(ULONG);
85
86 NTSTATUS
87 NTAPI
88 UserInitialize(
89 HANDLE hPowerRequestEvent,
90 HANDLE hMediaRequestEvent)
91 {
92 // Set W32PF_Flags |= (W32PF_READSCREENACCESSGRANTED | W32PF_IOWINSTA)
93 // Create Object Directory,,, Looks like create workstation. "\\Windows\\WindowStations"
94 // Create Event for Diconnect Desktop.
95 InitVideo(0);
96 // Initialize Video.
97 // {
98 // DrvInitConsole.
99 // DrvChangeDisplaySettings.
100 // Update Shared Device Caps.
101 // Initialize User Screen.
102 // }
103 // Create ThreadInfo for this Thread!
104 // {
105
106 GetW32ThreadInfo();
107
108 // Callback to User32 Client Thread Setup
109
110 co_IntClientThreadSetup();
111
112 // }
113 // Set Global SERVERINFO Error flags.
114 // Load Resources.
115
116 NtUserUpdatePerUserSystemParameters(0, TRUE);
117
118 CsrInit();
119
120 return STATUS_SUCCESS;
121 }
122
123 /*
124 Called from win32csr.
125 */
126 NTSTATUS
127 APIENTRY
128 NtUserInitialize(
129 DWORD dwWinVersion,
130 HANDLE hPowerRequestEvent,
131 HANDLE hMediaRequestEvent)
132 {
133 NTSTATUS Status;
134
135 DPRINT1("Enter NtUserInitialize(%lx, %p, %p)\n",
136 dwWinVersion, hPowerRequestEvent, hMediaRequestEvent);
137
138 /* Check the Windows version */
139 if (dwWinVersion != 0)
140 {
141 return STATUS_UNSUCCESSFUL;
142 }
143
144 /* Acquire exclusive lock */
145 UserEnterExclusive();
146
147 /* Check if we are already initialized */
148 if (gbInitialized)
149 {
150 UserLeave();
151 return STATUS_UNSUCCESSFUL;
152 }
153
154 // Initialize Power Request List.
155 // Initialize Media Change.
156 // InitializeGreCSRSS();
157 // {
158 // Startup DxGraphics.
159 // calls ** IntGdiGetLanguageID() and sets it **.
160 // Enables Fonts drivers, Initialize Font table & Stock Fonts.
161 // }
162
163 /* Initialize USER */
164 Status = UserInitialize(hPowerRequestEvent, hMediaRequestEvent);
165
166 /* Set us as initialized */
167 gbInitialized = TRUE;
168
169 /* Return */
170 UserLeave();
171 return Status;
172 }
173
174
175 /*
176 RETURN
177 True if current thread owns the lock (possibly shared)
178 */
179 BOOL FASTCALL UserIsEntered(VOID)
180 {
181 return ExIsResourceAcquiredExclusiveLite(&UserLock)
182 || ExIsResourceAcquiredSharedLite(&UserLock);
183 }
184
185 BOOL FASTCALL UserIsEnteredExclusive(VOID)
186 {
187 return ExIsResourceAcquiredExclusiveLite(&UserLock);
188 }
189
190 VOID FASTCALL CleanupUserImpl(VOID)
191 {
192 ExDeleteResourceLite(&UserLock);
193 }
194
195 VOID FASTCALL UserEnterShared(VOID)
196 {
197 KeEnterCriticalRegion();
198 ExAcquireResourceSharedLite(&UserLock, TRUE);
199 }
200
201 VOID FASTCALL UserEnterExclusive(VOID)
202 {
203 KeEnterCriticalRegion();
204 ExAcquireResourceExclusiveLite(&UserLock, TRUE);
205 }
206
207 VOID FASTCALL UserLeave(VOID)
208 {
209 ExReleaseResourceLite(&UserLock);
210 KeLeaveCriticalRegion();
211 }