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