37a4da77e806b67d3040f894990f68e9ac335c38
[reactos.git] / reactos / subsys / win32k / ntuser / callback.c
1 /* $Id: callback.c,v 1.8 2003/05/17 14:30:28 gvg Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * PURPOSE: Window classes
6 * FILE: subsys/win32k/ntuser/wndproc.c
7 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * REVISION HISTORY:
9 * 06-06-2001 CSH Created
10 */
11
12 /* INCLUDES ******************************************************************/
13
14 #include <ddk/ntddk.h>
15 #include <win32k/win32k.h>
16 #include <win32k/userobj.h>
17 #include <include/class.h>
18 #include <include/error.h>
19 #include <include/winsta.h>
20 #include <include/msgqueue.h>
21 #include <user32/callback.h>
22 #include <include/callback.h>
23
24 #define NDEBUG
25 #include <debug.h>
26
27 /* FUNCTIONS *****************************************************************/
28
29 VOID STDCALL
30 W32kCallSentMessageCallback(SENDASYNCPROC CompletionCallback,
31 HWND hWnd,
32 UINT Msg,
33 ULONG_PTR CompletionCallbackContext,
34 LRESULT Result)
35 {
36 SENDASYNCPROC_CALLBACK_ARGUMENTS Arguments;
37 NTSTATUS Status;
38
39 Arguments.Callback = CompletionCallback;
40 Arguments.Wnd = hWnd;
41 Arguments.Msg = Msg;
42 Arguments.Context = CompletionCallbackContext;
43 Arguments.Result = Result;
44 Status = NtW32Call(USER32_CALLBACK_SENDASYNCPROC,
45 &Arguments,
46 sizeof(SENDASYNCPROC_CALLBACK_ARGUMENTS),
47 NULL,
48 NULL);
49 if (!NT_SUCCESS(Status))
50 {
51 return;
52 }
53 return;
54 }
55
56 LRESULT STDCALL
57 W32kSendNCCALCSIZEMessage(HWND Wnd, BOOL Validate, PRECT Rect,
58 NCCALCSIZE_PARAMS* Params)
59 {
60 SENDNCCALCSIZEMESSAGE_CALLBACK_ARGUMENTS Arguments;
61 SENDNCCALCSIZEMESSAGE_CALLBACK_RESULT Result;
62 NTSTATUS Status;
63 PVOID ResultPointer;
64 ULONG ResultLength;
65
66 Arguments.Wnd = Wnd;
67 Arguments.Validate = Validate;
68 if (!Validate)
69 {
70 Arguments.Rect = *Rect;
71 }
72 else
73 {
74 Arguments.Params = *Params;
75 }
76 ResultPointer = &Result;
77 ResultLength = sizeof(SENDNCCALCSIZEMESSAGE_CALLBACK_RESULT);
78 Status = NtW32Call(USER32_CALLBACK_SENDNCCALCSIZE,
79 &Arguments,
80 sizeof(SENDNCCALCSIZEMESSAGE_CALLBACK_ARGUMENTS),
81 &ResultPointer,
82 &ResultLength);
83 if (!NT_SUCCESS(Status))
84 {
85 return(0);
86 }
87 if (!Validate)
88 {
89 *Rect = Result.Rect;
90 }
91 else
92 {
93 *Params = Result.Params;
94 }
95 return(Result.Result);
96 }
97
98 LRESULT STDCALL
99 W32kSendCREATEMessage(HWND Wnd, CREATESTRUCTW* CreateStruct)
100 {
101 SENDCREATEMESSAGE_CALLBACK_ARGUMENTS Arguments;
102 LRESULT Result;
103 NTSTATUS Status;
104 PVOID ResultPointer;
105 ULONG ResultLength;
106
107 Arguments.Wnd = Wnd;
108 Arguments.CreateStruct = *CreateStruct;
109 ResultPointer = &Result;
110 ResultLength = sizeof(LRESULT);
111 Status = NtW32Call(USER32_CALLBACK_SENDCREATE,
112 &Arguments,
113 sizeof(SENDCREATEMESSAGE_CALLBACK_ARGUMENTS),
114 &ResultPointer,
115 &ResultLength);
116 if (!NT_SUCCESS(Status))
117 {
118 return(0);
119 }
120 return(Result);
121 }
122
123 LRESULT STDCALL
124 W32kSendNCCREATEMessage(HWND Wnd, CREATESTRUCTW* CreateStruct)
125 {
126 SENDNCCREATEMESSAGE_CALLBACK_ARGUMENTS Arguments;
127 LRESULT Result;
128 NTSTATUS Status;
129 PVOID ResultPointer;
130 ULONG ResultLength;
131
132 Arguments.Wnd = Wnd;
133 Arguments.CreateStruct = *CreateStruct;
134 ResultPointer = &Result;
135 ResultLength = sizeof(LRESULT);
136 Status = NtW32Call(USER32_CALLBACK_SENDNCCREATE,
137 &Arguments,
138 sizeof(SENDNCCREATEMESSAGE_CALLBACK_ARGUMENTS),
139 &ResultPointer,
140 &ResultLength);
141 if (!NT_SUCCESS(Status))
142 {
143 return(0);
144 }
145 return(Result);
146 }
147
148 LRESULT STDCALL
149 W32kCallWindowProc(WNDPROC Proc,
150 HWND Wnd,
151 UINT Message,
152 WPARAM wParam,
153 LPARAM lParam)
154 {
155 WINDOWPROC_CALLBACK_ARGUMENTS Arguments;
156 LRESULT Result;
157 NTSTATUS Status;
158 PVOID ResultPointer;
159 ULONG ResultLength;
160
161 if (W32kIsDesktopWindow(Wnd))
162 {
163 return(W32kDesktopWindowProc(Wnd, Message, wParam, lParam));
164 }
165
166 Arguments.Proc = Proc;
167 Arguments.Wnd = Wnd;
168 Arguments.Msg = Message;
169 Arguments.wParam = wParam;
170 Arguments.lParam = lParam;
171 ResultPointer = &Result;
172 ResultLength = sizeof(LRESULT);
173 Status = NtW32Call(USER32_CALLBACK_WINDOWPROC,
174 &Arguments,
175 sizeof(WINDOWPROC_CALLBACK_ARGUMENTS),
176 &ResultPointer,
177 &ResultLength);
178 if (!NT_SUCCESS(Status))
179 {
180 return(0xFFFFFFFF);
181 }
182 return(Result);
183 }
184
185 LRESULT STDCALL
186 W32kSendGETMINMAXINFOMessage(HWND Wnd, MINMAXINFO* MinMaxInfo)
187 {
188 SENDGETMINMAXINFO_CALLBACK_ARGUMENTS Arguments;
189 SENDGETMINMAXINFO_CALLBACK_RESULT Result;
190 NTSTATUS Status;
191 PVOID ResultPointer;
192 ULONG ResultLength;
193
194 Arguments.Wnd = Wnd;
195 Arguments.MinMaxInfo = *MinMaxInfo;
196 ResultPointer = &Result;
197 ResultLength = sizeof(Result);
198 Status = NtW32Call(USER32_CALLBACK_SENDGETMINMAXINFO,
199 &Arguments,
200 sizeof(SENDGETMINMAXINFO_CALLBACK_ARGUMENTS),
201 &ResultPointer,
202 &ResultLength);
203 if (!NT_SUCCESS(Status))
204 {
205 return(0);
206 }
207 return(Result.Result);
208 }
209
210 LRESULT STDCALL
211 W32kSendWINDOWPOSCHANGINGMessage(HWND Wnd, WINDOWPOS* WindowPos)
212 {
213 SENDWINDOWPOSCHANGING_CALLBACK_ARGUMENTS Arguments;
214 LRESULT Result;
215 NTSTATUS Status;
216 PVOID ResultPointer;
217 ULONG ResultLength;
218
219 Arguments.Wnd = Wnd;
220 Arguments.WindowPos = *WindowPos;
221 ResultPointer = &Result;
222 ResultLength = sizeof(LRESULT);
223 Status = NtW32Call(USER32_CALLBACK_SENDWINDOWPOSCHANGING,
224 &Arguments,
225 sizeof(SENDWINDOWPOSCHANGING_CALLBACK_ARGUMENTS),
226 &ResultPointer,
227 &ResultLength);
228 if (!NT_SUCCESS(Status))
229 {
230 return(0);
231 }
232 return(Result);
233 }
234
235 LRESULT STDCALL
236 W32kSendWINDOWPOSCHANGEDMessage(HWND Wnd, WINDOWPOS* WindowPos)
237 {
238 SENDWINDOWPOSCHANGED_CALLBACK_ARGUMENTS Arguments;
239 LRESULT Result;
240 NTSTATUS Status;
241 PVOID ResultPointer;
242 ULONG ResultLength;
243
244 Arguments.Wnd = Wnd;
245 Arguments.WindowPos = *WindowPos;
246 ResultPointer = &Result;
247 ResultLength = sizeof(LRESULT);
248 Status = NtW32Call(USER32_CALLBACK_SENDWINDOWPOSCHANGED,
249 &Arguments,
250 sizeof(SENDWINDOWPOSCHANGED_CALLBACK_ARGUMENTS),
251 &ResultPointer,
252 &ResultLength);
253 if (!NT_SUCCESS(Status))
254 {
255 return(0);
256 }
257 return(Result);
258 }
259
260 LRESULT STDCALL
261 W32kCallTrampolineWindowProc(WNDPROC Proc,
262 HWND Wnd,
263 UINT Message,
264 WPARAM wParam,
265 LPARAM lParam)
266 {
267 switch (Message)
268 {
269 case WM_NCCREATE:
270 return W32kSendNCCREATEMessage(Wnd, (CREATESTRUCTW*)lParam);
271
272 case WM_CREATE:
273 return W32kSendCREATEMessage(Wnd, (CREATESTRUCTW*)lParam);
274
275 case WM_GETMINMAXINFO:
276 return W32kSendGETMINMAXINFOMessage(Wnd, (MINMAXINFO*)lParam);
277
278 case WM_NCCALCSIZE:
279 {
280 if (wParam)
281 {
282 return W32kSendNCCALCSIZEMessage(Wnd, TRUE, NULL,
283 (NCCALCSIZE_PARAMS*)lParam);
284 }
285 else
286 {
287 return W32kSendNCCALCSIZEMessage(Wnd, FALSE, (RECT*)lParam, NULL);
288 }
289 }
290
291 case WM_WINDOWPOSCHANGING:
292 return W32kSendWINDOWPOSCHANGINGMessage(Wnd, (WINDOWPOS*) lParam);
293
294 case WM_WINDOWPOSCHANGED:
295 return W32kSendWINDOWPOSCHANGEDMessage(Wnd, (WINDOWPOS*) lParam);
296
297 default:
298 return(W32kCallWindowProc(Proc, Wnd, Message, wParam, lParam));
299 }
300 }
301
302 /* EOF */