update for HEAD-2003091401
[reactos.git] / subsys / win32k / ntuser / callback.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$
20  *
21  * COPYRIGHT:        See COPYING in the top level directory
22  * PROJECT:          ReactOS kernel
23  * PURPOSE:          Window classes
24  * FILE:             subsys/win32k/ntuser/wndproc.c
25  * PROGRAMER:        Casper S. Hornstrup (chorns@users.sourceforge.net)
26  * REVISION HISTORY:
27  *       06-06-2001  CSH  Created
28  */
29
30 /* INCLUDES ******************************************************************/
31
32 #include <ddk/ntddk.h>
33 #include <win32k/win32k.h>
34 #include <win32k/userobj.h>
35 #include <include/class.h>
36 #include <include/error.h>
37 #include <include/winsta.h>
38 #include <include/window.h>
39 #include <include/msgqueue.h>
40 #include <user32/callback.h>
41 #include <include/callback.h>
42
43 #define NDEBUG
44 #include <debug.h>
45
46 /* FUNCTIONS *****************************************************************/
47
48 VOID STDCALL
49 IntCallSentMessageCallback(SENDASYNCPROC CompletionCallback,
50                             HWND hWnd,
51                             UINT Msg,
52                             ULONG_PTR CompletionCallbackContext,
53                             LRESULT Result)
54 {
55   SENDASYNCPROC_CALLBACK_ARGUMENTS Arguments;
56   NTSTATUS Status;
57
58   Arguments.Callback = CompletionCallback;
59   Arguments.Wnd = hWnd;
60   Arguments.Msg = Msg;
61   Arguments.Context = CompletionCallbackContext;
62   Arguments.Result = Result;
63   Status = NtW32Call(USER32_CALLBACK_SENDASYNCPROC,
64                      &Arguments,
65                      sizeof(SENDASYNCPROC_CALLBACK_ARGUMENTS),
66                      NULL,
67                      NULL);
68   if (!NT_SUCCESS(Status))
69     {
70       return;
71     }
72   return;  
73 }
74
75 LRESULT STDCALL
76 IntSendNCCALCSIZEMessage(HWND Wnd, BOOL Validate, PRECT Rect,
77                           NCCALCSIZE_PARAMS* Params)
78 {
79   SENDNCCALCSIZEMESSAGE_CALLBACK_ARGUMENTS Arguments;
80   SENDNCCALCSIZEMESSAGE_CALLBACK_RESULT Result;
81   NTSTATUS Status;
82   PVOID ResultPointer;
83   ULONG ResultLength;
84
85   Arguments.Wnd = Wnd;
86   Arguments.Validate = Validate;
87   if (!Validate)
88     {
89       Arguments.Rect = *Rect;
90     }
91   else
92     {
93       Arguments.Params = *Params;
94     }
95   ResultPointer = &Result;
96   ResultLength = sizeof(SENDNCCALCSIZEMESSAGE_CALLBACK_RESULT);
97   Status = NtW32Call(USER32_CALLBACK_SENDNCCALCSIZE,
98                      &Arguments,
99                      sizeof(SENDNCCALCSIZEMESSAGE_CALLBACK_ARGUMENTS),
100                      &ResultPointer,
101                      &ResultLength);
102   if (!NT_SUCCESS(Status))
103     {
104       return(0);
105     }
106   if (!Validate)
107     {
108       *Rect = Result.Rect;
109     }
110   else
111     {
112       *Params = Result.Params;
113     }
114   return(Result.Result);
115 }
116
117 LRESULT STDCALL
118 IntSendCREATEMessage(HWND Wnd, CREATESTRUCTW* CreateStruct)
119 {
120   SENDCREATEMESSAGE_CALLBACK_ARGUMENTS Arguments;
121   LRESULT Result;
122   NTSTATUS Status;
123   PVOID ResultPointer;
124   ULONG ResultLength;
125
126   Arguments.Wnd = Wnd;
127   Arguments.CreateStruct = *CreateStruct;
128   ResultPointer = &Result;
129   ResultLength = sizeof(LRESULT);
130   Status = NtW32Call(USER32_CALLBACK_SENDCREATE,
131                      &Arguments,
132                      sizeof(SENDCREATEMESSAGE_CALLBACK_ARGUMENTS),
133                      &ResultPointer,
134                      &ResultLength);
135   if (!NT_SUCCESS(Status))
136     {
137       return(0);
138     }
139   return(Result);
140 }
141
142 LRESULT STDCALL
143 IntSendNCCREATEMessage(HWND Wnd, CREATESTRUCTW* CreateStruct)
144 {
145   SENDNCCREATEMESSAGE_CALLBACK_ARGUMENTS Arguments;
146   LRESULT Result;
147   NTSTATUS Status;
148   PVOID ResultPointer;
149   ULONG ResultLength;
150
151   Arguments.Wnd = Wnd;
152   Arguments.CreateStruct = *CreateStruct;
153   ResultPointer = &Result;
154   ResultLength = sizeof(LRESULT);
155   Status = NtW32Call(USER32_CALLBACK_SENDNCCREATE,
156                      &Arguments,
157                      sizeof(SENDNCCREATEMESSAGE_CALLBACK_ARGUMENTS),
158                      &ResultPointer,
159                      &ResultLength);
160   if (!NT_SUCCESS(Status))
161     {
162       return(0);
163     }
164   return(Result);
165 }
166
167 LRESULT STDCALL
168 IntCallWindowProc(WNDPROC Proc,
169                    HWND Wnd,
170                    UINT Message,
171                    WPARAM wParam,
172                    LPARAM lParam)
173 {
174   WINDOWPROC_CALLBACK_ARGUMENTS Arguments;
175   LRESULT Result;
176   NTSTATUS Status;
177   PVOID ResultPointer;
178   ULONG ResultLength;
179   PWINDOW_OBJECT WindowObject = IntGetWindowObject(Wnd);
180
181   if (IntIsDesktopWindow(WindowObject))
182     {
183       IntReleaseWindowObject(WindowObject);
184       return(IntDesktopWindowProc(Wnd, Message, wParam, lParam));
185     }
186   IntReleaseWindowObject(WindowObject);
187
188   Arguments.Proc = Proc;
189   Arguments.Wnd = Wnd;
190   Arguments.Msg = Message;
191   Arguments.wParam = wParam;
192   Arguments.lParam = lParam;
193   ResultPointer = &Result;
194   ResultLength = sizeof(LRESULT);
195   Status = NtW32Call(USER32_CALLBACK_WINDOWPROC,
196                      &Arguments,
197                      sizeof(WINDOWPROC_CALLBACK_ARGUMENTS),
198                      &ResultPointer,
199                      &ResultLength);
200   if (!NT_SUCCESS(Status))
201     {
202       return(0xFFFFFFFF);
203     }
204   return(Result);
205 }
206
207 LRESULT STDCALL
208 IntSendGETMINMAXINFOMessage(HWND Wnd, MINMAXINFO* MinMaxInfo)
209 {
210   SENDGETMINMAXINFO_CALLBACK_ARGUMENTS Arguments;
211   SENDGETMINMAXINFO_CALLBACK_RESULT Result;
212   NTSTATUS Status;
213   PVOID ResultPointer;
214   ULONG ResultLength;
215
216   Arguments.Wnd = Wnd;
217   Arguments.MinMaxInfo = *MinMaxInfo;
218   ResultPointer = &Result;
219   ResultLength = sizeof(Result);
220   Status = NtW32Call(USER32_CALLBACK_SENDGETMINMAXINFO,
221                      &Arguments,
222                      sizeof(SENDGETMINMAXINFO_CALLBACK_ARGUMENTS),
223                      &ResultPointer,
224                      &ResultLength);
225   if (!NT_SUCCESS(Status))
226     {
227       return(0);
228     }
229   return(Result.Result);  
230 }
231
232 LRESULT STDCALL
233 IntSendWINDOWPOSCHANGINGMessage(HWND Wnd, WINDOWPOS* WindowPos)
234 {
235   SENDWINDOWPOSCHANGING_CALLBACK_ARGUMENTS Arguments;
236   LRESULT Result;
237   NTSTATUS Status;
238   PVOID ResultPointer;
239   ULONG ResultLength;
240
241   Arguments.Wnd = Wnd;
242   Arguments.WindowPos = *WindowPos;
243   ResultPointer = &Result;
244   ResultLength = sizeof(LRESULT);
245   Status = NtW32Call(USER32_CALLBACK_SENDWINDOWPOSCHANGING,
246                      &Arguments,
247                      sizeof(SENDWINDOWPOSCHANGING_CALLBACK_ARGUMENTS),
248                      &ResultPointer,
249                      &ResultLength);
250   if (!NT_SUCCESS(Status))
251     {
252       return(0);
253     }
254   return(Result);
255 }
256
257 LRESULT STDCALL
258 IntSendWINDOWPOSCHANGEDMessage(HWND Wnd, WINDOWPOS* WindowPos)
259 {
260   SENDWINDOWPOSCHANGED_CALLBACK_ARGUMENTS Arguments;
261   LRESULT Result;
262   NTSTATUS Status;
263   PVOID ResultPointer;
264   ULONG ResultLength;
265
266   Arguments.Wnd = Wnd;
267   Arguments.WindowPos = *WindowPos;
268   ResultPointer = &Result;
269   ResultLength = sizeof(LRESULT);
270   Status = NtW32Call(USER32_CALLBACK_SENDWINDOWPOSCHANGED,
271                      &Arguments,
272                      sizeof(SENDWINDOWPOSCHANGED_CALLBACK_ARGUMENTS),
273                      &ResultPointer,
274                      &ResultLength);
275   if (!NT_SUCCESS(Status))
276     {
277       return(0);
278     }
279   return(Result);
280 }
281
282 LRESULT STDCALL
283 IntSendSTYLECHANGINGMessage(HWND Wnd, DWORD WhichStyle, STYLESTRUCT* Style)
284 {
285   SENDSTYLECHANGING_CALLBACK_ARGUMENTS Arguments;
286   LRESULT Result;
287   NTSTATUS Status;
288   PVOID ResultPointer;
289   ULONG ResultLength;
290
291   Arguments.Wnd = Wnd;
292   Arguments.Style = *Style;
293   Arguments.WhichStyle = WhichStyle;
294   ResultPointer = &Result;
295   ResultLength = sizeof(LRESULT);
296   Status = NtW32Call(USER32_CALLBACK_SENDSTYLECHANGING,
297                      &Arguments,
298                      sizeof(SENDSTYLECHANGING_CALLBACK_ARGUMENTS),
299                      &ResultPointer,
300                      &ResultLength);
301   if (!NT_SUCCESS(Status))
302     {
303       return(0);
304     }
305   *Style = Arguments.Style;  
306   return(Result);
307 }
308
309 LRESULT STDCALL
310 IntSendSTYLECHANGEDMessage(HWND Wnd, DWORD WhichStyle, STYLESTRUCT* Style)
311 {
312   SENDSTYLECHANGED_CALLBACK_ARGUMENTS Arguments;
313   LRESULT Result;
314   NTSTATUS Status;
315   PVOID ResultPointer;
316   ULONG ResultLength;
317
318   Arguments.Wnd = Wnd;
319   Arguments.Style = *Style;
320   Arguments.WhichStyle = WhichStyle;
321   ResultPointer = &Result;
322   ResultLength = sizeof(LRESULT);
323   Status = NtW32Call(USER32_CALLBACK_SENDSTYLECHANGED,
324                      &Arguments,
325                      sizeof(SENDSTYLECHANGED_CALLBACK_ARGUMENTS),
326                      &ResultPointer,
327                      &ResultLength);
328   if (!NT_SUCCESS(Status))
329     {
330       return(0);
331     }
332   return(Result);
333 }
334
335 LRESULT STDCALL
336 IntCallTrampolineWindowProc(WNDPROC Proc,
337                              HWND Wnd,
338                              UINT Message,
339                              WPARAM wParam,
340                              LPARAM lParam)
341 {
342   switch (Message)
343     {
344     case WM_NCCREATE:
345       return IntSendNCCREATEMessage(Wnd, (CREATESTRUCTW*)lParam);
346      
347     case WM_CREATE:
348       return IntSendCREATEMessage(Wnd, (CREATESTRUCTW*)lParam);
349
350     case WM_GETMINMAXINFO:
351       return IntSendGETMINMAXINFOMessage(Wnd, (MINMAXINFO*)lParam);
352
353     case WM_NCCALCSIZE:
354       {
355         if (wParam)
356           {
357             return IntSendNCCALCSIZEMessage(Wnd, TRUE, NULL, 
358                                              (NCCALCSIZE_PARAMS*)lParam);
359           }
360         else
361           {
362             return IntSendNCCALCSIZEMessage(Wnd, FALSE, (RECT*)lParam, NULL);
363           }
364       }
365
366     case WM_WINDOWPOSCHANGING:
367       return IntSendWINDOWPOSCHANGINGMessage(Wnd, (WINDOWPOS*) lParam);
368
369     case WM_WINDOWPOSCHANGED:
370       return IntSendWINDOWPOSCHANGEDMessage(Wnd, (WINDOWPOS*) lParam);
371
372     case WM_STYLECHANGING:
373       return IntSendSTYLECHANGINGMessage(Wnd, wParam, (STYLESTRUCT*) lParam);
374
375     case WM_STYLECHANGED:
376           return IntSendSTYLECHANGEDMessage(Wnd, wParam, (STYLESTRUCT*) lParam);
377
378     default:
379       return(IntCallWindowProc(Proc, Wnd, Message, wParam, lParam));
380     }
381 }
382
383 HMENU STDCALL
384 IntLoadSysMenuTemplate()
385 {
386   LRESULT Result;
387   NTSTATUS Status;
388   PVOID ResultPointer;
389   ULONG ResultLength;
390
391   ResultPointer = &Result;
392   ResultLength = sizeof(LRESULT);
393   Status = NtW32Call(USER32_CALLBACK_LOADSYSMENUTEMPLATE,
394                      NULL,
395                      0,
396                      &ResultPointer,
397                      &ResultLength);
398   if (!NT_SUCCESS(Status))
399     {
400       return(0);
401     }
402   return (HMENU)Result;
403 }
404
405 BOOL STDCALL
406 IntLoadDefaultCursors()
407 {
408   LRESULT Result;
409   NTSTATUS Status;
410   PVOID ResultPointer;
411   ULONG ResultLength;
412
413   ResultPointer = &Result;
414   ResultLength = sizeof(LRESULT);
415   Status = NtW32Call(USER32_CALLBACK_LOADDEFAULTCURSORS,
416                      NULL,
417                      0,
418                      &ResultPointer,
419                      &ResultLength);
420   if (!NT_SUCCESS(Status))
421     {
422       return(0);
423     }
424   return (BOOL)Result;
425 }
426
427 /* EOF */