:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / subsys / win32k / ntuser / callback.c
1 /* $Id$
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 W32kCallTrampolineWindowProc(WNDPROC Proc,
212                              HWND Wnd,
213                              UINT Message,
214                              WPARAM wParam,
215                              LPARAM lParam)
216 {
217   switch (Message)
218     {
219     case WM_NCCREATE:
220       return(W32kSendNCCREATEMessage(Wnd, (CREATESTRUCTW*)lParam));
221      
222     case WM_CREATE:
223       return(W32kSendCREATEMessage(Wnd, (CREATESTRUCTW*)lParam));
224
225     case WM_GETMINMAXINFO:
226       return(W32kSendGETMINMAXINFOMessage(Wnd, (MINMAXINFO*)lParam));
227
228     case WM_NCCALCSIZE:
229       {
230         if (wParam)
231           {
232             return(W32kSendNCCALCSIZEMessage(Wnd, TRUE, NULL, 
233                                              (NCCALCSIZE_PARAMS*)lParam));
234           }
235         else
236           {
237             return(W32kSendNCCALCSIZEMessage(Wnd, FALSE, (RECT*)lParam, NULL));
238           }
239       }
240
241     default:
242       return(W32kCallWindowProc(Proc, Wnd, Message, wParam, lParam));
243     }
244 }
245
246 /* EOF */