Large-scale renaming of all Win32 functions and types to use the
[wine] / misc / callback.c
1 /*
2  * Function callbacks for the library
3  *
4  * Copyright 1997 Alexandre Julliard
5  */
6
7 #include <assert.h>
8 #include "winuser.h"
9 #include "callback.h"
10 #include "task.h"
11 #include "syslevel.h"
12 #include "queue.h"
13 #include "debug.h"
14
15
16 /**********************************************************************
17  *           CALLBACK_CallWndProc
18  */
19 static LRESULT WINAPI CALLBACK_CallWndProc( WNDPROC16 proc, HWND16 hwnd,
20                                             UINT16 msg, WPARAM16 wParam,
21                                             LPARAM lParam )
22 {
23     return proc( hwnd, msg, wParam, lParam );
24 }
25
26
27 /**********************************************************************
28  *           CALLBACK_CallRegisterProc
29  */
30 static LONG WINAPI CALLBACK_CallRegisterProc( CONTEXT *context, INT offset)
31 {
32     ERR(relay, "Cannot call a register proc in Winelib\n" );
33     assert( FALSE );
34     return 0;
35 }
36
37
38 /**********************************************************************
39  *           CALLBACK_CallDriverProc
40  */
41 static LRESULT WINAPI CALLBACK_CallDriverProc( DRIVERPROC16 proc, DWORD dwId,
42                                                HDRVR16 hdrvr, UINT16 msg,
43                                                LPARAM lp1, LPARAM lp2 )
44 {
45     return proc( dwId, hdrvr, msg, lp1, lp2 );
46 }
47
48
49 /**********************************************************************
50  *           CALLBACK_CallDriverCallback
51  */
52 static LRESULT WINAPI CALLBACK_CallDriverCallback( FARPROC16 proc,
53                                                    HANDLE16 hDev, UINT16 msg,
54                                                    DWORD dwUser, LPARAM lp1,
55                                                    LPARAM lp2 )
56 {
57     return proc( hDev, msg, dwUser, lp1, lp2 );
58 }
59
60
61 /**********************************************************************
62  *           CALLBACK_CallTimeFuncProc
63  */
64 static LRESULT WINAPI CALLBACK_CallTimeFuncProc( FARPROC16 proc, WORD id,
65                                                  UINT16 msg, DWORD dwUser,
66                                                  LPARAM lp1, LPARAM lp2 )
67 {
68     return proc( id, msg, dwUser, lp1, lp2 );
69 }
70
71
72 /**********************************************************************
73  *           CALLBACK_CallWindowsExitProc
74  */
75 static INT16 WINAPI CALLBACK_CallWindowsExitProc( FARPROC16 proc, INT16 type)
76 {
77     return proc( type );
78 }
79
80
81 /**********************************************************************
82  *           CALLBACK_CallWordBreakProc
83  */
84 static INT16 WINAPI CALLBACK_CallWordBreakProc( EDITWORDBREAKPROC16 proc,
85                                                 SEGPTR text, INT16 word,
86                                                 INT16 len, INT16 action )
87 {
88     return proc( (LPSTR)text, word, len, action );
89 }
90
91
92 /**********************************************************************
93  *           CALLBACK_CallBootAppProc
94  */
95 static void WINAPI CALLBACK_CallBootAppProc( FARPROC16 proc, HANDLE16 module,
96                                              HFILE16 file )
97 {
98     proc( module, file );
99 }
100
101
102 /**********************************************************************
103  *           CALLBACK_CallLoadAppSegProc
104  */
105 static WORD WINAPI CALLBACK_CallLoadAppSegProc( FARPROC16 proc,
106                                                 HANDLE16 module, HFILE16 file,
107                                                 WORD seg )
108 {
109     return proc( module, file, seg );
110 }
111
112
113 /**********************************************************************
114  *           CALLBACK_CallLocalNotifyFunc
115  */
116 static WORD WINAPI CALLBACK_CallLocalNotifyFunc( FARPROC16 proc,
117                                                  WORD wMsg, HLOCAL16 hMem,
118                                                  WORD wArg )
119 {
120     return proc( wMsg, hMem, wArg );
121 }
122
123
124 /**********************************************************************
125  *           CALLBACK_CallResourceHandlerProc
126  */
127 static HGLOBAL16 WINAPI CALLBACK_CallResourceHandlerProc( FARPROC16 proc,
128                                                           HGLOBAL16 hMemObj, 
129                                                           HMODULE16 hModule,
130                                                           HRSRC16 hRsrc )
131 {
132     return proc( hMemObj, hModule, hRsrc );
133 }
134
135
136 /**********************************************************************
137  *           CALLBACK_CallASPIPostProc
138  */
139 static LRESULT WINAPI CALLBACK_CallASPIPostProc( FARPROC16 proc, SEGPTR ptr )
140 {
141     return proc( ptr );
142 }
143
144
145 /**********************************************************************
146  *           CALLBACK_CallWOWCallbackProc
147  */
148 static DWORD WINAPI CALLBACK_CallWOWCallbackProc( FARPROC16 proc, DWORD dw )
149 {
150     return proc( dw );
151 }
152
153 /**********************************************************************
154  *           CALLBACK_CallWOWCallback16Ex
155  *
156  * WCB16_MAX_CBARGS (16) is the maximum number of args.
157  *
158  * Can call functions using CDECL or PASCAL calling conventions. The CDECL
159  * ones are reversed (not 100% sure about that).
160  */
161 static BOOL WINAPI CALLBACK_CallWOWCallback16Ex( 
162         FARPROC16 proc, DWORD dwFlags, DWORD cbArgs, LPVOID xargs,LPDWORD pdwret
163 ) {
164     LPDWORD     args = (LPDWORD)xargs;
165     DWORD       ret,i;
166
167     if (dwFlags == WCB16_CDECL) {
168         /* swap the arguments */
169         args = HeapAlloc(GetProcessHeap(),0,cbArgs*sizeof(DWORD));
170         for (i=0;i<cbArgs;i++)
171                 args[i] = ((DWORD*)xargs)[cbArgs-i-1];
172     }
173     switch (cbArgs) {
174     case 0: ret = proc();break;
175     case 1: ret = proc(args[0]);break;
176     case 2: ret = proc(args[0],args[1]);break;
177     case 3: ret = proc(args[0],args[1],args[2]);break;
178     case 4: ret = proc(args[0],args[1],args[2],args[3]);break;
179     case 5: ret = proc(args[0],args[1],args[2],args[3],args[4]);break;
180     case 6: ret = proc(args[0],args[1],args[2],args[3],args[4],args[5]);
181             break;
182     case 7: ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
183                     args[6]
184             );
185             break;
186     case 8: ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
187                     args[6],args[7]
188             );
189             break;
190     case 9: ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
191                     args[6],args[7],args[8]
192             );
193             break;
194     case 10:ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
195                     args[6],args[7],args[8],args[9]
196             );
197             break;
198     case 11:ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
199                     args[6],args[7],args[8],args[9],args[10]
200             );
201             break;
202     case 12:ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
203                     args[6],args[7],args[8],args[9],args[10],args[11]
204             );
205             break;
206     case 13:ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
207                     args[6],args[7],args[8],args[9],args[10],args[11],
208                     args[12]
209             );
210             break;
211     case 14:ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
212                     args[6],args[7],args[8],args[9],args[10],args[11],
213                     args[12],args[13]
214             );
215             break;
216     case 15:ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
217                     args[6],args[7],args[8],args[9],args[10],args[11],
218                     args[12],args[13],args[14]
219             );
220             break;
221     case 16:ret = proc(args[0],args[1],args[2],args[3],args[4],args[5],
222                     args[6],args[7],args[8],args[9],args[10],args[11],
223                     args[12],args[13],args[14],args[15]
224             );
225             break;
226     default:
227             WARN(relay,"(%ld) arguments not supported.\n",cbArgs);
228             if (dwFlags == WCB16_CDECL)
229                 HeapFree(GetProcessHeap(),0,args);
230             return FALSE;
231     }
232     if (dwFlags == WCB16_CDECL)
233         HeapFree(GetProcessHeap(),0,args);
234     if (pdwret) 
235         *pdwret = ret;
236     return TRUE;
237 }
238
239 /**********************************************************************
240  *           CALLBACK_CallTaskRescheduleProc
241  */
242 static BOOL WINAPI CALLBACK_CallTaskRescheduleProc( void )
243 {
244     BOOL pending;
245
246     SYSLEVEL_EnterWin16Lock();
247     pending = TASK_Reschedule();
248     SYSLEVEL_LeaveWin16Lock();
249
250     return pending;
251 }
252
253
254 /**********************************************************************
255  *           CALLBACK_WinelibTable
256  *
257  * The callbacks function table for Winelib
258  */
259 static const CALLBACKS_TABLE CALLBACK_WinelibTable =
260 {
261     CALLBACK_CallRegisterProc,        /* CallRegisterShortProc */
262     CALLBACK_CallRegisterProc,        /* CallRegisterLongProc */
263     CALLBACK_CallTaskRescheduleProc,  /* CallTaskRescheduleProc */
264     NULL,                             /* CallFrom16WndProc */
265     CALLBACK_CallWndProc,             /* CallWndProc */
266     CALLBACK_CallDriverProc,          /* CallDriverProc */
267     CALLBACK_CallDriverCallback,      /* CallDriverCallback */
268     CALLBACK_CallTimeFuncProc,        /* CallTimeFuncProc */
269     CALLBACK_CallWindowsExitProc,     /* CallWindowsExitProc */
270     CALLBACK_CallWordBreakProc,       /* CallWordBreakProc */
271     CALLBACK_CallBootAppProc,         /* CallBootAppProc */
272     CALLBACK_CallLoadAppSegProc,      /* CallLoadAppSegProc */
273     CALLBACK_CallLocalNotifyFunc,     /* CallLocalNotifyFunc */
274     CALLBACK_CallResourceHandlerProc, /* CallResourceHandlerProc */
275     CALLBACK_CallWOWCallbackProc,     /* CallWOWCallbackProc */
276     CALLBACK_CallWOWCallback16Ex,     /* CallWOWCallback16Ex */
277     CALLBACK_CallASPIPostProc,        /* CallASPIPostProc */
278     /* The graphics driver callbacks are never used in Winelib */
279     NULL,                             /* CallDrvControlProc */
280     NULL,                             /* CallDrvEnableProc */
281     NULL,                             /* CallDrvEnumDFontsProc */
282     NULL,                             /* CallDrvEnumObjProc */
283     NULL,                             /* CallDrvOutputProc */
284     NULL,                             /* CallDrvRealizeProc */
285     NULL,                             /* CallDrvStretchBltProc */
286     NULL,                             /* CallDrvExtTextOutProc */
287     NULL,                             /* CallDrvGetCharWidth */
288     NULL                              /* CallDrvAbortProc */
289 };
290
291 const CALLBACKS_TABLE *Callbacks = &CALLBACK_WinelibTable;
292
293
294 /**********************************************************************
295  *           CALLOUT_Table
296  *
297  * The callout function table for Winelib
298  */
299
300 CALLOUT_TABLE Callout = 
301 {
302     PeekMessage16, PeekMessageA, PeekMessageW,
303     GetMessage16, GetMessageA, GetMessageW,
304     SendMessage16, SendMessageA, SendMessageW,
305     PostMessage16, PostMessageA, PostMessageW,
306     PostAppMessage16, PostThreadMessageA, PostThreadMessageW,
307     TranslateMessage16, TranslateMessage,
308     DispatchMessage16, DispatchMessageA, DispatchMessageW,
309     RedrawWindow16, RedrawWindow,
310     InitThreadInput16,
311     UserYield16
312 };
313