initial implementation of carets
[reactos.git] / reactos / subsys / win32k / main / dllmain.c
1 /*
2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id: dllmain.c,v 1.46 2003/10/16 22:07:37 weiden Exp $
20 *
21 * Entry Point for win32k.sys
22 */
23
24 #undef WIN32_LEAN_AND_MEAN
25 #define WIN32_NO_STATUS
26 #include <windows.h>
27 #define NTOS_MODE_KERNEL
28 #include <ntos.h>
29 #include <ddk/winddi.h>
30
31 #include <win32k/win32k.h>
32
33 #include <include/winsta.h>
34 #include <include/class.h>
35 #include <include/window.h>
36 #include <include/menu.h>
37 #include <include/object.h>
38 #include <include/input.h>
39 #include <include/timer.h>
40 #include <include/text.h>
41 #include <include/caret.h>
42
43 #define NDEBUG
44 #include <win32k/debug1.h>
45
46 extern SSDT Win32kSSDT[];
47 extern SSPT Win32kSSPT[];
48 extern ULONG Win32kNumberOfSysCalls;
49
50 PEPROCESS Win32kDeviceProcess;
51
52
53 NTSTATUS STDCALL
54 Win32kProcessCallback (struct _EPROCESS *Process,
55 BOOLEAN Create)
56 {
57 PW32PROCESS Win32Process;
58 NTSTATUS Status;
59
60 #if 0
61 DbgPrint ("Win32kProcessCallback() called\n");
62 #endif
63
64 Win32Process = Process->Win32Process;
65 if (Create)
66 {
67 #if 0
68 DbgPrint (" Create process\n");
69 #endif
70
71 InitializeListHead(&Win32Process->ClassListHead);
72 ExInitializeFastMutex(&Win32Process->ClassListLock);
73
74 InitializeListHead(&Win32Process->MenuListHead);
75 ExInitializeFastMutex(&Win32Process->MenuListLock);
76
77 Win32Process->KeyboardLayout = W32kGetDefaultKeyLayout();
78 Win32Process->WindowStation = NULL;
79 if (Process->Win32WindowStation != NULL)
80 {
81 Status =
82 ValidateWindowStationHandle(Process->Win32WindowStation,
83 UserMode,
84 GENERIC_ALL,
85 &Win32Process->WindowStation);
86 if (!NT_SUCCESS(Status))
87 {
88 DbgPrint("Win32K: Failed to reference a window station for "
89 "process.\n");
90 }
91 }
92 }
93 else
94 {
95 #if 0
96 DbgPrint (" Destroy process\n");
97 DbgPrint (" IRQ level: %lu\n", KeGetCurrentIrql ());
98 #endif
99
100 IntCleanupMenus(Process, Win32Process);
101
102 CleanupForProcess(Process, Process->UniqueProcessId);
103 }
104
105 return STATUS_SUCCESS;
106 }
107
108
109 NTSTATUS STDCALL
110 Win32kThreadCallback (struct _ETHREAD *Thread,
111 BOOLEAN Create)
112 {
113 struct _EPROCESS *Process;
114 PW32THREAD Win32Thread;
115 NTSTATUS Status;
116
117 #if 0
118 DbgPrint ("Win32kThreadCallback() called\n");
119 #endif
120
121 Process = Thread->ThreadsProcess;
122 Win32Thread = Thread->Win32Thread;
123 if (Create)
124 {
125 #if 0
126 DbgPrint (" Create thread\n");
127 #endif
128
129 IntDestroyCaret(Win32Thread);
130 Win32Thread->MessageQueue = MsqCreateMessageQueue();
131 Win32Thread->KeyboardLayout = W32kGetDefaultKeyLayout();
132 InitializeListHead(&Win32Thread->WindowListHead);
133 ExInitializeFastMutex(&Win32Thread->WindowListLock);
134
135 /* By default threads get assigned their process's desktop. */
136 Win32Thread->Desktop = NULL;
137 if (Process->Win32Desktop != NULL)
138 {
139 Status = ObReferenceObjectByHandle(Process->Win32Desktop,
140 GENERIC_ALL,
141 ExDesktopObjectType,
142 UserMode,
143 (PVOID*)&Win32Thread->Desktop,
144 NULL);
145 if (!NT_SUCCESS(Status))
146 {
147 DbgPrint("Win32K: Failed to reference a desktop for thread.\n");
148 }
149 }
150 }
151 else
152 {
153 #if 0
154 DbgPrint (" Destroy thread\n");
155 #endif
156
157 RemoveTimersThread(Thread->Cid.UniqueThread);
158 DestroyThreadWindows(Thread);
159 }
160
161 return STATUS_SUCCESS;
162 }
163
164
165 /*
166 * This definition doesn't work
167 */
168 // WINBOOL STDCALL DllMain(VOID)
169 NTSTATUS
170 STDCALL
171 DllMain (
172 IN PDRIVER_OBJECT DriverObject,
173 IN PUNICODE_STRING RegistryPath)
174 {
175 NTSTATUS Status;
176 BOOLEAN Result;
177
178 IntInitializeWinLock();
179
180 /*
181 * Register user mode call interface
182 * (system service table index = 1)
183 */
184 Result = KeAddSystemServiceTable (Win32kSSDT,
185 NULL,
186 Win32kNumberOfSysCalls,
187 Win32kSSPT,
188 1);
189 if (Result == FALSE)
190 {
191 DbgPrint("Adding system services failed!\n");
192 return STATUS_UNSUCCESSFUL;
193 }
194
195 /*
196 * Register our per-process and per-thread structures.
197 */
198 PsEstablishWin32Callouts (Win32kProcessCallback,
199 Win32kThreadCallback,
200 0,
201 0,
202 sizeof(W32THREAD) + sizeof(THRDCARETINFO),
203 sizeof(W32PROCESS));
204
205 WinPosSetupInternalPos();
206
207 Status = InitWindowStationImpl();
208 if (!NT_SUCCESS(Status))
209 {
210 DbgPrint("Failed to initialize window station implementation!\n");
211 return STATUS_UNSUCCESSFUL;
212 }
213
214 Status = InitClassImpl();
215 if (!NT_SUCCESS(Status))
216 {
217 DbgPrint("Failed to initialize window class implementation!\n");
218 return STATUS_UNSUCCESSFUL;
219 }
220
221 Status = InitWindowImpl();
222 if (!NT_SUCCESS(Status))
223 {
224 DbgPrint("Failed to initialize window implementation!\n");
225 return STATUS_UNSUCCESSFUL;
226 }
227
228 Status = InitMenuImpl();
229 if (!NT_SUCCESS(Status))
230 {
231 DbgPrint("Failed to initialize menu implementation!\n");
232 return STATUS_UNSUCCESSFUL;
233 }
234
235 Status = InitInputImpl();
236 if (!NT_SUCCESS(Status))
237 {
238 DbgPrint("Failed to initialize input implementation.\n");
239 return(Status);
240 }
241
242 Status = MsqInitializeImpl();
243 if (!NT_SUCCESS(Status))
244 {
245 DbgPrint("Failed to initialize message queue implementation.\n");
246 return(Status);
247 }
248
249 Status = InitTimerImpl();
250 if (!NT_SUCCESS(Status))
251 {
252 DbgPrint("Failed to initialize timer implementation.\n");
253 return(Status);
254 }
255
256 return STATUS_SUCCESS;
257 }
258
259
260 BOOLEAN
261 STDCALL
262 Win32kInitialize (VOID)
263 {
264 DPRINT("in Win32kInitialize\n");
265
266 Win32kDeviceProcess = PsGetCurrentProcess();
267
268 InitGdiObjectHandleTable ();
269
270 // Initialize FreeType library
271 if(!InitFontSupport()) return FALSE;
272
273 // Create stock objects, ie. precreated objects commonly used by win32 applications
274 CreateStockObjects();
275
276 return TRUE;
277 }
278
279 /* EOF */