Release 960712
[wine/multimedia.git] / windows / winproc.c
blob501acfea5f12e31663c841d2e0b53cd19c5e3921
1 /*
2 * Window procedure callbacks
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1996 Alexandre Julliard
6 */
8 #include <stdio.h>
9 #include "windows.h"
10 #include "callback.h"
11 #include "heap.h"
12 #include "ldt.h"
13 #include "registers.h"
14 #include "stackframe.h"
15 #include "string32.h"
16 #include "struct32.h"
17 #include "win.h"
18 #include "winproc.h"
19 #include "stddebug.h"
20 #include "debug.h"
22 /* Window procedure 16-bit thunk; see BuildSpec16Files() in tools/build.c */
23 typedef struct
25 BYTE popl_eax; /* popl %eax (return address) */
26 BYTE pushl_func; /* pushl $proc */
27 WNDPROC32 proc WINE_PACKED;
28 BYTE pushl_eax; /* pushl %eax */
29 WORD pushw_bp WINE_PACKED; /* pushw %bp */
30 BYTE pushl_thunk; /* pushl $thunkfrom16 */
31 void (*thunk32)() WINE_PACKED;
32 BYTE lcall; /* lcall cs:relay */
33 void (*relay)() WINE_PACKED;
34 WORD cs WINE_PACKED;
35 } WINPROC_THUNK_FROM16;
37 /* Window procedure 32-bit thunk; see BuildSpec32Files() in tools/build.c */
38 typedef struct
40 BYTE popl_eax; /* popl %eax (return address) */
41 BYTE pushl_func; /* pushl $proc */
42 WNDPROC16 proc WINE_PACKED;
43 BYTE pushl_eax; /* pushl %eax */
44 BYTE pushl_ebp; /* pushl %ebp */
45 BYTE pushl_name; /* pushl $name */
46 LPCSTR name WINE_PACKED;
47 BYTE pushl_thunk; /* pushl $thunkfrom32 */
48 void (*thunk32)() WINE_PACKED;
49 BYTE jmp; /* jmp relay (relative jump)*/
50 void (*relay)() WINE_PACKED;
51 } WINPROC_THUNK_FROM32;
53 /* Simple jmp to call 32-bit procedure directly */
54 typedef struct
56 BYTE jmp; /* jmp proc (relative jump) */
57 WNDPROC32 proc WINE_PACKED;
58 } WINPROC_JUMP;
60 typedef union
62 WINPROC_THUNK_FROM16 t_from16;
63 WINPROC_THUNK_FROM32 t_from32;
64 } WINPROC_THUNK;
66 typedef struct tagWINDOWPROC
68 WINPROC_THUNK thunk; /* Thunk */
69 WINPROC_JUMP jmp; /* Jump */
70 struct tagWINDOWPROC *next; /* Next window proc */
71 UINT32 magic; /* Magic number */
72 WINDOWPROCTYPE type; /* Function type */
73 } WINDOWPROC;
75 #define WINPROC_MAGIC ('W' | ('P' << 8) | ('R' << 16) | ('C' << 24))
77 #define WINPROC_THUNKPROC(pproc) \
78 (((pproc)->type == WIN_PROC_16) ? \
79 (WNDPROC16)((pproc)->thunk.t_from32.proc) : \
80 (WNDPROC16)((pproc)->thunk.t_from16.proc))
82 LRESULT WINPROC_CallProc16To32A( HWND16 hwnd, UINT16 msg,
83 WPARAM16 wParam, LPARAM lParam,
84 WNDPROC32 func );
85 LRESULT WINPROC_CallProc16To32W( HWND16 hwnd, UINT16 msg,
86 WPARAM16 wParam, LPARAM lParam,
87 WNDPROC32 func );
88 static LRESULT WINPROC_CallProc32ATo16( WNDPROC16 func, HWND32 hwnd,
89 UINT32 msg, WPARAM32 wParam,
90 LPARAM lParam );
91 static LRESULT WINPROC_CallProc32WTo16( WNDPROC16 func, HWND32 hwnd,
92 UINT32 msg, WPARAM32 wParam,
93 LPARAM lParam );
95 #ifndef WINELIB
96 extern void CallFrom16_long_wwwll(void);
97 extern void CallFrom32_stdcall_5(void);
98 #else
99 static void CallFrom16_long_wwwll(void) {}
100 static void CallFrom32_stdcall_5(void) {}
101 #endif /* WINELIB */
103 /* Reference 16->32A thunk */
104 static const WINPROC_THUNK_FROM16 WINPROC_ThunkRef16To32A =
106 0x58, /* popl %eax */
107 0x68, 0x00000000, /* pushl $proc32 */
108 0x50, /* pushl %eax */
109 0x5566, /* pushw %bp */
110 0x68, (void (*)())WINPROC_CallProc16To32A, /* pushl $thunk32 */
111 0x9a, CallFrom16_long_wwwll, /* lcall cs:relay */
112 WINE_CODE_SELECTOR
115 /* Reference 16->32W thunk */
116 static const WINPROC_THUNK_FROM16 WINPROC_ThunkRef16To32W =
118 0x58, /* popl %eax */
119 0x68, 0x00000000, /* pushl $proc32 */
120 0x50, /* pushl %eax */
121 0x5566, /* pushw %bp */
122 0x68, (void (*)())WINPROC_CallProc16To32W, /* pushl $thunk32 */
123 0x9a, CallFrom16_long_wwwll, /* lcall cs:relay */
124 WINE_CODE_SELECTOR
127 /* Reference 32->16 thunk */
128 static const WINPROC_THUNK_FROM32 WINPROC_ThunkRef32To16 =
130 0x58, /* popl %eax */
131 0x68, 0x00000000, /* pushl $proc16 */
132 0x50, /* pushl %eax */
133 0x55, /* pushl %ebp */
134 0x68, "WINPROC_CallProc32ATo16", /* pushl $name */
135 0x68, (void (*)())WINPROC_CallProc32ATo16, /* pushl $thunk32 */
136 0xe9, CallFrom32_stdcall_5 /* jmp relay */
139 /* Reference 32->32 jump */
140 static const WINPROC_JUMP WINPROC_JumpRef =
142 0xe9, 0x00000000 /* jmp proc (relative) */
145 static HANDLE32 WinProcHeap;
147 /**********************************************************************
148 * WINPROC_Init
150 BOOL32 WINPROC_Init(void)
152 WinProcHeap = HeapCreate( HEAP_WINE_SEGPTR | HEAP_WINE_CODESEG, 0, 0 );
153 if (!WinProcHeap)
155 fprintf( stderr, "Unable to create winproc heap\n" );
156 return FALSE;
158 return TRUE;
162 /**********************************************************************
163 * WINPROC_GetPtr
165 * Return a pointer to the win proc.
167 static WINDOWPROC *WINPROC_GetPtr( WNDPROC16 handle )
169 BYTE *ptr;
170 WINDOWPROC *proc;
172 /* Check for a linear pointer */
174 if (HEAP_IsInsideHeap( WinProcHeap, 0, (LPVOID)handle ))
176 ptr = (BYTE *)handle;
177 /* First check if it is the jmp address */
178 if (*ptr == WINPROC_JumpRef.jmp)
179 ptr -= (int)&((WINDOWPROC *)0)->jmp -
180 (int)&((WINDOWPROC *)0)->thunk;
181 /* Now it must be the thunk address */
182 if (*ptr == WINPROC_ThunkRef16To32A.popl_eax)
183 ptr -= (int)&((WINDOWPROC *)0)->thunk;
184 /* Now we have a pointer to the WINDOWPROC struct */
185 if (((WINDOWPROC *)ptr)->magic == WINPROC_MAGIC)
186 return (WINDOWPROC *)ptr;
189 /* Check for a segmented pointer */
191 if (!IsBadReadPtr( (SEGPTR)handle, sizeof(WINDOWPROC)-sizeof(proc->thunk)))
193 ptr = (BYTE *)PTR_SEG_TO_LIN(handle);
194 /* It must be the thunk address */
195 if (*ptr == WINPROC_ThunkRef32To16.popl_eax)
196 ptr -= (int)&((WINDOWPROC *)0)->thunk;
197 /* Now we have a pointer to the WINDOWPROC struct */
198 if (((WINDOWPROC *)ptr)->magic == WINPROC_MAGIC)
199 return (WINDOWPROC *)ptr;
202 return NULL;
206 /**********************************************************************
207 * WINPROC_AllocWinProc
209 * Allocate a new window procedure.
211 static WINDOWPROC *WINPROC_AllocWinProc( WNDPROC16 func, WINDOWPROCTYPE type )
213 WINDOWPROC *proc, *oldproc;
215 /* Allocate a window procedure */
217 if (!(proc = HeapAlloc( WinProcHeap, 0, sizeof(WINDOWPROC) ))) return 0;
219 /* Check if the function is already a win proc */
221 if ((oldproc = WINPROC_GetPtr( func )))
223 *proc = *oldproc;
225 else
227 switch(type)
229 case WIN_PROC_16:
230 proc->thunk.t_from32 = WINPROC_ThunkRef32To16;
231 proc->thunk.t_from32.proc = func;
232 /* We need to fix the relative jump target */
233 proc->thunk.t_from32.relay = (void (*)())((DWORD)proc->thunk.t_from32.relay -
234 (DWORD)(&proc->thunk.t_from32.relay + 1));
235 break;
236 case WIN_PROC_32A:
237 proc->thunk.t_from16 = WINPROC_ThunkRef16To32A;
238 proc->thunk.t_from16.proc = (FARPROC32)func;
239 proc->jmp = WINPROC_JumpRef;
240 /* Fixup relative jump */
241 proc->jmp.proc = (WNDPROC32)((DWORD)func -
242 (DWORD)(&proc->jmp.proc + 1));
243 break;
244 case WIN_PROC_32W:
245 proc->thunk.t_from16 = WINPROC_ThunkRef16To32W;
246 proc->thunk.t_from16.proc = (WNDPROC32)func;
247 proc->jmp = WINPROC_JumpRef;
248 /* Fixup relative jump */
249 proc->jmp.proc = (WNDPROC32)((DWORD)func -
250 (DWORD)(&proc->jmp.proc + 1));
251 break;
252 default:
253 /* Should not happen */
254 break;
256 proc->magic = WINPROC_MAGIC;
257 proc->type = type;
259 proc->next = NULL;
260 dprintf_win( stddeb, "WINPROC_AllocWinProc(%08x,%d): returning %08x\n",
261 (UINT32)func, type, (UINT32)proc );
262 return proc;
266 /**********************************************************************
267 * WINPROC_GetProc
269 * Get a window procedure pointer that can be passed to the Windows program.
271 WNDPROC16 WINPROC_GetProc( HWINDOWPROC proc, WINDOWPROCTYPE type )
273 if (type == WIN_PROC_16) /* We want a 16:16 address */
275 if (((WINDOWPROC *)proc)->type == WIN_PROC_16)
276 return ((WINDOWPROC *)proc)->thunk.t_from32.proc;
277 else
278 return (WNDPROC16)HEAP_GetSegptr( WinProcHeap, 0,
279 &((WINDOWPROC *)proc)->thunk );
281 else /* We want a 32-bit address */
283 if (((WINDOWPROC *)proc)->type == WIN_PROC_16)
284 return (WNDPROC16)&((WINDOWPROC *)proc)->thunk;
285 else
286 return (WNDPROC16)&((WINDOWPROC *)proc)->jmp;
291 /**********************************************************************
292 * WINPROC_SetProc
294 * Set the window procedure for a window or class.
296 BOOL32 WINPROC_SetProc( HWINDOWPROC *pFirst, WNDPROC16 func,
297 WINDOWPROCTYPE type )
299 WINDOWPROC *proc, **ppPrev;
301 /* Check if function is already in the list */
303 ppPrev = (WINDOWPROC **)pFirst;
304 proc = WINPROC_GetPtr( func );
305 while (*ppPrev)
307 if (proc)
309 if (*ppPrev == proc) break;
311 else
313 if (((*ppPrev)->type == type) &&
314 (func == WINPROC_THUNKPROC(*ppPrev))) break;
316 ppPrev = &(*ppPrev)->next;
319 if (*ppPrev) /* Remove it from the list */
321 proc = *ppPrev;
322 *ppPrev = proc->next;
324 else /* Allocate a new one */
326 if (proc) /* Was already a win proc */
328 type = proc->type;
329 func = WINPROC_THUNKPROC(proc);
331 proc = WINPROC_AllocWinProc( func, type );
332 if (!proc) return FALSE;
335 /* Add the win proc at the head of the list */
337 dprintf_win( stddeb, "WINPROC_SetProc(%08x,%08x,%d): res=%08x\n",
338 (UINT32)*pFirst, (UINT32)func, type, (UINT32)proc );
339 proc->next = *(WINDOWPROC **)pFirst;
340 *(WINDOWPROC **)pFirst = proc;
341 return TRUE;
345 /**********************************************************************
346 * WINPROC_FreeProc
348 * Free a list of win procs.
350 void WINPROC_FreeProc( HWINDOWPROC proc )
352 while (proc)
354 WINDOWPROC *next = ((WINDOWPROC *)proc)->next;
355 dprintf_win( stddeb, "WINPROC_FreeProc: freeing %08x\n", (UINT32)proc);
356 HeapFree( WinProcHeap, 0, proc );
357 proc = next;
362 /**********************************************************************
363 * WINPROC_GetProcType
365 * Return the window procedure type.
367 WINDOWPROCTYPE WINPROC_GetProcType( HWINDOWPROC proc )
369 if (!proc ||
370 (((WINDOWPROC *)proc)->magic != WINPROC_MAGIC))
371 return WIN_PROC_INVALID;
372 return ((WINDOWPROC *)proc)->type;
376 /**********************************************************************
377 * WINPROC_MapMsg32ATo32W
379 * Map a message from Ansi to Unicode.
380 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
382 INT32 WINPROC_MapMsg32ATo32W( UINT32 msg, WPARAM32 wParam, LPARAM *plparam )
384 switch(msg)
386 case WM_GETTEXT:
388 LPARAM *ptr = (LPARAM *)HeapAlloc( SystemHeap, 0,
389 wParam * sizeof(WCHAR) + sizeof(LPARAM) );
390 if (!ptr) return -1;
391 *ptr++ = *plparam; /* Store previous lParam */
392 *plparam = (LPARAM)ptr;
394 return 1;
395 case WM_SETTEXT:
396 *plparam = (LPARAM)STRING32_DupAnsiToUni( (LPCSTR)*plparam );
397 return (*plparam ? 1 : -1);
398 case WM_NCCREATE:
399 case WM_CREATE:
401 CREATESTRUCT32W *cs = (CREATESTRUCT32W *)HeapAlloc( SystemHeap, 0,
402 sizeof(*cs) );
403 if (!cs) return -1;
404 *cs = *(CREATESTRUCT32W *)*plparam;
405 if (HIWORD(cs->lpszName))
406 cs->lpszName = STRING32_DupAnsiToUni( (LPCSTR)cs->lpszName );
407 if (HIWORD(cs->lpszClass))
408 cs->lpszClass = STRING32_DupAnsiToUni( (LPCSTR)cs->lpszClass );
409 *plparam = (LPARAM)cs;
411 return 1;
412 default: /* No translation needed */
413 return 0;
418 /**********************************************************************
419 * WINPROC_UnmapMsg32ATo32W
421 * Unmap a message that was mapped from Ansi to Unicode.
423 void WINPROC_UnmapMsg32ATo32W( UINT32 msg, WPARAM32 wParam, LPARAM lParam )
425 switch(msg)
427 case WM_GETTEXT:
429 LPARAM *ptr = (LPARAM *)lParam - 1;
430 lstrcpynWtoA( (LPSTR)*ptr, (LPWSTR)(ptr + 1), wParam );
431 HeapFree( SystemHeap, 0, ptr );
433 break;
434 case WM_SETTEXT:
435 free( (void *)lParam );
436 break;
437 case WM_NCCREATE:
438 case WM_CREATE:
440 CREATESTRUCT32W *cs = (CREATESTRUCT32W *)lParam;
441 if (HIWORD(cs->lpszName)) free( (LPVOID)cs->lpszName );
442 if (HIWORD(cs->lpszClass)) free( (LPVOID)cs->lpszClass );
443 HeapFree( SystemHeap, 0, cs );
445 break;
450 /**********************************************************************
451 * WINPROC_MapMsg32WTo32A
453 * Map a message from Unicode to Ansi.
454 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
456 INT32 WINPROC_MapMsg32WTo32A( UINT32 msg, WPARAM32 wParam, LPARAM *plparam )
458 switch(msg)
460 case WM_GETTEXT:
462 LPARAM *ptr = (LPARAM *)HeapAlloc( SystemHeap, 0,
463 wParam + sizeof(LPARAM) );
464 if (!ptr) return -1;
465 *ptr++ = *plparam; /* Store previous lParam */
466 *plparam = (LPARAM)ptr;
468 return 1;
469 case WM_SETTEXT:
470 *plparam = (LPARAM)STRING32_DupUniToAnsi( (LPCWSTR)*plparam );
471 return (*plparam ? 1 : -1);
472 case WM_NCCREATE:
473 case WM_CREATE:
475 CREATESTRUCT32A *cs = (CREATESTRUCT32A *)HeapAlloc( SystemHeap, 0,
476 sizeof(*cs) );
477 if (!cs) return -1;
478 *cs = *(CREATESTRUCT32A *)*plparam;
479 if (HIWORD(cs->lpszName))
480 cs->lpszName = STRING32_DupUniToAnsi( (LPCWSTR)cs->lpszName );
481 if (HIWORD(cs->lpszClass))
482 cs->lpszClass = STRING32_DupUniToAnsi( (LPCWSTR)cs->lpszClass);
483 *plparam = (LPARAM)cs;
485 return 1;
486 default: /* No translation needed */
487 return 0;
492 /**********************************************************************
493 * WINPROC_UnmapMsg32WTo32A
495 * Unmap a message that was mapped from Unicode to Ansi.
497 void WINPROC_UnmapMsg32WTo32A( UINT32 msg, WPARAM32 wParam, LPARAM lParam )
499 switch(msg)
501 case WM_GETTEXT:
503 LPARAM *ptr = (LPARAM *)lParam - 1;
504 lstrcpynAtoW( (LPWSTR)*ptr, (LPSTR)(ptr + 1), wParam );
505 HeapFree( SystemHeap, 0, ptr );
507 break;
508 case WM_SETTEXT:
509 free( (void *)lParam );
510 break;
511 case WM_NCCREATE:
512 case WM_CREATE:
514 CREATESTRUCT32A *cs = (CREATESTRUCT32A *)lParam;
515 if (HIWORD(cs->lpszName)) free( (LPVOID)cs->lpszName );
516 if (HIWORD(cs->lpszClass)) free( (LPVOID)cs->lpszClass );
517 HeapFree( SystemHeap, 0, cs );
519 break;
524 /**********************************************************************
525 * WINPROC_MapMsg16To32A
527 * Map a message from 16- to 32-bit Ansi.
528 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
530 INT32 WINPROC_MapMsg16To32A( UINT16 msg16, WPARAM16 wParam16, UINT32 *pmsg32,
531 WPARAM32 *pwparam32, LPARAM *plparam )
533 *pmsg32 = (UINT32)msg16;
534 *pwparam32 = (WPARAM32)wParam16;
535 switch(msg16)
537 case WM_ACTIVATE:
538 case WM_CHARTOITEM:
539 case WM_COMMAND:
540 case WM_HSCROLL:
541 case WM_VKEYTOITEM:
542 case WM_VSCROLL:
543 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
544 *plparam = (LPARAM)(HWND32)LOWORD(*plparam);
545 return 0;
546 case WM_CTLCOLOR:
547 *pmsg32 = WM_CTLCOLORMSGBOX + HIWORD(*plparam);
548 *pwparam32 = (WPARAM32)(HDC32)wParam16;
549 *plparam = (LPARAM)(HWND32)LOWORD(*plparam);
550 return 0;
551 case WM_DRAWITEM:
553 DRAWITEMSTRUCT16* dis16 = (DRAWITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
554 DRAWITEMSTRUCT32 *dis = (DRAWITEMSTRUCT32*)HeapAlloc(SystemHeap, 0,
555 sizeof(*dis));
556 if (!dis) return -1;
557 dis->CtlType = dis16->CtlType;
558 dis->CtlID = dis16->CtlID;
559 dis->itemID = dis16->itemID;
560 dis->itemAction = dis16->itemAction;
561 dis->itemState = dis16->itemState;
562 dis->hwndItem = dis16->hwndItem;
563 dis->hDC = dis16->hDC;
564 dis->itemData = dis16->itemData;
565 CONV_RECT16TO32( &dis16->rcItem, &dis->rcItem );
566 *plparam = (LPARAM)dis;
568 return 1;
569 case WM_GETMINMAXINFO:
571 MINMAXINFO32 *mmi = (MINMAXINFO32 *)HeapAlloc( SystemHeap, 0,
572 sizeof(*mmi) + sizeof(LPARAM));
573 if (!mmi) return -1;
574 STRUCT32_MINMAXINFO16to32( (MINMAXINFO16*)PTR_SEG_TO_LIN(*plparam),
575 mmi );
576 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
577 *plparam = (LPARAM)mmi;
579 return 1;
580 case WM_GETTEXT:
581 *plparam = (LPARAM)PTR_SEG_TO_LIN(*plparam);
582 return 0;
583 case WM_MDISETMENU:
584 *pwparam32 = (WPARAM32)(HMENU32)LOWORD(*plparam);
585 *plparam = (LPARAM)(HMENU32)HIWORD(*plparam);
586 return 0;
587 case WM_MENUCHAR:
588 case WM_MENUSELECT:
589 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
590 *plparam = (LPARAM)(HMENU32)HIWORD(*plparam);
591 return 0;
592 case WM_NCCALCSIZE:
594 NCCALCSIZE_PARAMS16 *nc16;
595 NCCALCSIZE_PARAMS32 *nc;
597 nc = (NCCALCSIZE_PARAMS32 *)HeapAlloc( SystemHeap, 0,
598 sizeof(*nc) + sizeof(LPARAM) );
599 if (!nc) return -1;
600 nc16 = (NCCALCSIZE_PARAMS16 *)PTR_SEG_TO_LIN(*plparam);
601 CONV_RECT16TO32( &nc16->rgrc[0], &nc->rgrc[0] );
602 if (wParam16)
604 nc->lppos = (WINDOWPOS32 *)HeapAlloc( SystemHeap, 0,
605 sizeof(*nc->lppos) );
606 CONV_RECT16TO32( &nc16->rgrc[1], &nc->rgrc[1] );
607 CONV_RECT16TO32( &nc16->rgrc[2], &nc->rgrc[2] );
608 if (nc->lppos) STRUCT32_WINDOWPOS16to32( (WINDOWPOS16 *)PTR_SEG_TO_LIN(nc16->lppos), nc->lppos );
610 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
611 *plparam = (LPARAM)nc;
613 return 1;
614 case WM_NCCREATE:
615 case WM_CREATE:
617 CREATESTRUCT16 *cs16 = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
618 CREATESTRUCT32A *cs = (CREATESTRUCT32A *)HeapAlloc( SystemHeap, 0,
619 sizeof(*cs) + sizeof(LPARAM) );
620 if (!cs) return -1;
621 STRUCT32_CREATESTRUCT16to32A( cs16, cs );
622 cs->lpszName = (LPCSTR)PTR_SEG_TO_LIN(cs16->lpszName);
623 cs->lpszClass = (LPCSTR)PTR_SEG_TO_LIN(cs16->lpszClass);
624 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
625 *plparam = (LPARAM)cs;
627 return 1;
628 case WM_PARENTNOTIFY:
629 if ((wParam16 == WM_CREATE) || (wParam16 == WM_DESTROY))
631 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
632 *plparam = (LPARAM)(HWND32)LOWORD(*plparam);
634 else
636 *pwparam32 = MAKEWPARAM( wParam16, 0 /* FIXME? */ );
638 return 0;
639 case WM_SETTEXT:
640 *plparam = (LPARAM)PTR_SEG_TO_LIN(*plparam);
641 return 0;
642 case WM_WINDOWPOSCHANGING:
643 case WM_WINDOWPOSCHANGED:
645 WINDOWPOS32 *wp = (WINDOWPOS32 *)HeapAlloc( SystemHeap, 0,
646 sizeof(*wp) + sizeof(LPARAM) );
647 if (!wp) return -1;
648 STRUCT32_WINDOWPOS16to32( (WINDOWPOS16 *)PTR_SEG_TO_LIN(*plparam),
649 wp );
650 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
651 *plparam = (LPARAM)wp;
653 return 1;
654 case WM_ASKCBFORMATNAME:
655 case WM_COMPAREITEM:
656 case WM_DELETEITEM:
657 case WM_DEVMODECHANGE:
658 case WM_MDIACTIVATE:
659 case WM_MDICREATE:
660 case WM_MEASUREITEM:
661 case WM_PAINTCLIPBOARD:
662 case WM_SIZECLIPBOARD:
663 case WM_WININICHANGE:
664 fprintf( stderr, "MapMsg16To32A: message %04x needs translation\n",
665 msg16 );
666 return -1;
668 default: /* No translation needed */
669 return 0;
674 /**********************************************************************
675 * WINPROC_UnmapMsg16To32A
677 * Unmap a message that was mapped from 16- to 32-bit Ansi.
679 void WINPROC_UnmapMsg16To32A( UINT32 msg, WPARAM32 wParam, LPARAM lParam )
681 switch(msg)
683 case WM_DRAWITEM:
684 HeapFree( SystemHeap, 0, (LPVOID)lParam );
685 break;
686 case WM_GETMINMAXINFO:
688 MINMAXINFO32 *mmi = (MINMAXINFO32 *)lParam;
689 lParam = *(LPARAM *)(mmi + 1);
690 STRUCT32_MINMAXINFO32to16( mmi,
691 (MINMAXINFO16 *)PTR_SEG_TO_LIN(lParam));
692 HeapFree( SystemHeap, 0, mmi );
694 break;
695 case WM_NCCALCSIZE:
697 NCCALCSIZE_PARAMS16 *nc16;
698 NCCALCSIZE_PARAMS32 *nc = (NCCALCSIZE_PARAMS32 *)lParam;
699 lParam = *(LPARAM *)(nc + 1);
700 nc16 = (NCCALCSIZE_PARAMS16 *)PTR_SEG_TO_LIN(lParam);
701 CONV_RECT32TO16( &nc->rgrc[0], &nc16->rgrc[0] );
702 if (wParam)
704 CONV_RECT32TO16( &nc->rgrc[1], &nc16->rgrc[1] );
705 CONV_RECT32TO16( &nc->rgrc[2], &nc16->rgrc[2] );
706 if (nc->lppos)
708 STRUCT32_WINDOWPOS32to16( nc->lppos,
709 (WINDOWPOS16 *)PTR_SEG_TO_LIN(nc16->lppos));
710 HeapFree( SystemHeap, 0, nc->lppos );
713 HeapFree( SystemHeap, 0, nc );
715 break;
716 case WM_NCCREATE:
717 case WM_CREATE:
719 CREATESTRUCT32A *cs = (CREATESTRUCT32A *)lParam;
720 lParam = *(LPARAM *)(cs + 1);
721 STRUCT32_CREATESTRUCT32Ato16( cs,
722 (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
723 HeapFree( SystemHeap, 0, cs );
725 break;
726 case WM_WINDOWPOSCHANGING:
727 case WM_WINDOWPOSCHANGED:
729 WINDOWPOS32 *wp = (WINDOWPOS32 *)lParam;
730 lParam = *(LPARAM *)(wp + 1);
731 STRUCT32_WINDOWPOS32to16(wp,(WINDOWPOS16 *)PTR_SEG_TO_LIN(lParam));
732 HeapFree( SystemHeap, 0, wp );
734 break;
739 /**********************************************************************
740 * WINPROC_MapMsg16To32W
742 * Map a message from 16- to 32-bit Unicode.
743 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
745 INT32 WINPROC_MapMsg16To32W( UINT16 msg16, WPARAM16 wParam16, UINT32 *pmsg32,
746 WPARAM32 *pwparam32, LPARAM *plparam )
748 switch(msg16)
750 case WM_GETTEXT:
751 case WM_SETTEXT:
752 *plparam = (LPARAM)PTR_SEG_TO_LIN(*plparam);
753 return WINPROC_MapMsg32ATo32W( *pmsg32, *pwparam32, plparam );
754 case WM_NCCREATE:
755 case WM_CREATE:
757 CREATESTRUCT16 *cs16 = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
758 CREATESTRUCT32W *cs = (CREATESTRUCT32W *)HeapAlloc( SystemHeap, 0,
759 sizeof(*cs) + sizeof(LPARAM) );
760 if (!cs) return -1;
761 STRUCT32_CREATESTRUCT16to32A( cs16, (CREATESTRUCT32A *)cs );
762 cs->lpszName = (LPCWSTR)PTR_SEG_TO_LIN(cs16->lpszName);
763 cs->lpszClass = (LPCWSTR)PTR_SEG_TO_LIN(cs16->lpszClass);
764 if (HIWORD(cs->lpszName))
765 cs->lpszName = STRING32_DupAnsiToUni( (LPCSTR)cs->lpszName );
766 if (HIWORD(cs->lpszClass))
767 cs->lpszClass = STRING32_DupAnsiToUni( (LPCSTR)cs->lpszClass );
768 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
769 *plparam = (LPARAM)cs;
771 return 1;
772 default: /* No Unicode translation needed */
773 return WINPROC_MapMsg16To32A( msg16, wParam16, pmsg32,
774 pwparam32, plparam );
779 /**********************************************************************
780 * WINPROC_UnmapMsg16To32W
782 * Unmap a message that was mapped from 16- to 32-bit Unicode.
784 void WINPROC_UnmapMsg16To32W( UINT32 msg, WPARAM32 wParam, LPARAM lParam )
786 switch(msg)
788 case WM_GETTEXT:
789 case WM_SETTEXT:
790 WINPROC_UnmapMsg32ATo32W( msg, wParam, lParam );
791 break;
792 case WM_NCCREATE:
793 case WM_CREATE:
795 CREATESTRUCT32W *cs = (CREATESTRUCT32W *)lParam;
796 lParam = *(LPARAM *)(cs + 1);
797 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCT32A *)cs,
798 (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
799 if (HIWORD(cs->lpszName)) free( (LPVOID)cs->lpszName );
800 if (HIWORD(cs->lpszClass)) free( (LPVOID)cs->lpszClass );
801 HeapFree( SystemHeap, 0, cs );
803 break;
804 default:
805 WINPROC_UnmapMsg16To32A( msg, wParam, lParam );
806 break;
811 /**********************************************************************
812 * WINPROC_MapMsg32ATo16
814 * Map a message from 32-bit Ansi to 16-bit.
815 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
817 INT32 WINPROC_MapMsg32ATo16( UINT32 msg32, WPARAM32 wParam32, UINT16 *pmsg16,
818 WPARAM16 *pwparam16, LPARAM *plparam )
820 *pmsg16 = (UINT16)msg32;
821 *pwparam16 = (WPARAM16)LOWORD(wParam32);
822 switch(msg32)
824 case WM_ACTIVATE:
825 case WM_CHARTOITEM:
826 case WM_COMMAND:
827 case WM_VKEYTOITEM:
828 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
829 return 0;
830 case WM_HSCROLL:
831 case WM_VSCROLL:
832 *plparam = MAKELPARAM( HIWORD(wParam32), (HWND16)*plparam );
833 return 0;
834 case WM_CTLCOLORMSGBOX:
835 case WM_CTLCOLOREDIT:
836 case WM_CTLCOLORLISTBOX:
837 case WM_CTLCOLORBTN:
838 case WM_CTLCOLORDLG:
839 case WM_CTLCOLORSCROLLBAR:
840 case WM_CTLCOLORSTATIC:
841 *pmsg16 = WM_CTLCOLOR;
842 *plparam = MAKELPARAM( (HWND16)*plparam,
843 (WORD)msg32 - WM_CTLCOLORMSGBOX );
844 return 0;
845 case WM_DRAWITEM:
847 DRAWITEMSTRUCT32 *dis32 = (DRAWITEMSTRUCT32 *)*plparam;
848 DRAWITEMSTRUCT16 *dis = SEGPTR_NEW(DRAWITEMSTRUCT16);
849 if (!dis) return -1;
850 dis->CtlType = (UINT16)dis32->CtlType;
851 dis->CtlID = (UINT16)dis32->CtlID;
852 dis->itemID = (UINT16)dis32->itemID;
853 dis->itemAction = (UINT16)dis32->itemAction;
854 dis->itemState = (UINT16)dis32->itemState;
855 dis->hwndItem = (HWND16)dis32->hwndItem;
856 dis->hDC = (HDC16)dis32->hDC;
857 dis->itemData = dis32->itemData;
858 CONV_RECT32TO16( &dis32->rcItem, &dis->rcItem );
859 *plparam = (LPARAM)SEGPTR_GET(dis);
861 return 1;
862 case WM_GETMINMAXINFO:
864 MINMAXINFO16 *mmi = (MINMAXINFO16 *)SEGPTR_ALLOC( sizeof(*mmi) +
865 sizeof(LPARAM) );
866 if (!mmi) return -1;
867 STRUCT32_MINMAXINFO32to16( (MINMAXINFO32 *)*plparam, mmi );
868 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
869 *plparam = (LPARAM)SEGPTR_GET(mmi);
871 return 1;
872 case WM_GETTEXT:
874 LPSTR str;
875 *pwparam16 = (WPARAM16)MIN( wParam32, 0xff80 ); /* Must be < 64K */
876 if (!(str = SEGPTR_ALLOC(*pwparam16 + sizeof(LPARAM)))) return -1;
877 *((LPARAM *)str)++ = *plparam; /* Store the previous lParam */
878 *plparam = (LPARAM)SEGPTR_GET(str);
880 return 1;
881 case WM_MDISETMENU:
882 *pwparam16 = TRUE; /* FIXME? */
883 *plparam = MAKELPARAM( (HMENU16)LOWORD(wParam32),
884 (HMENU16)LOWORD(*plparam) );
885 return 0;
886 case WM_MENUCHAR:
887 case WM_MENUSELECT:
888 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
889 return 0;
890 case WM_NCCALCSIZE:
892 NCCALCSIZE_PARAMS32 *nc32 = (NCCALCSIZE_PARAMS32 *)*plparam;
893 NCCALCSIZE_PARAMS16 *nc = (NCCALCSIZE_PARAMS16 *)SEGPTR_ALLOC( sizeof(*nc) + sizeof(LPARAM) );
894 if (!nc) return -1;
896 CONV_RECT32TO16( &nc32->rgrc[0], &nc->rgrc[0] );
897 if (wParam32)
899 WINDOWPOS16 *wp;
900 CONV_RECT32TO16( &nc32->rgrc[1], &nc->rgrc[1] );
901 CONV_RECT32TO16( &nc32->rgrc[2], &nc->rgrc[2] );
902 if (!(wp = SEGPTR_NEW(WINDOWPOS16)))
904 SEGPTR_FREE(nc);
905 return -1;
907 STRUCT32_WINDOWPOS32to16( nc32->lppos, wp );
908 nc->lppos = SEGPTR_GET(wp);
910 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
911 *plparam = (LPARAM)SEGPTR_GET(nc);
913 return 1;
914 case WM_NCCREATE:
915 case WM_CREATE:
917 CREATESTRUCT16 *cs;
918 CREATESTRUCT32A *cs32 = (CREATESTRUCT32A *)*plparam;
919 LPSTR name, cls;
921 if (!(cs = SEGPTR_NEW(CREATESTRUCT16))) return -1;
922 STRUCT32_CREATESTRUCT32Ato16( cs32, cs );
923 name = SEGPTR_STRDUP( cs32->lpszName );
924 cls = SEGPTR_STRDUP( cs32->lpszClass );
925 cs->lpszName = SEGPTR_GET(name);
926 cs->lpszClass = SEGPTR_GET(cls);
927 *plparam = (LPARAM)SEGPTR_GET(cs);
929 return 1;
930 case WM_PARENTNOTIFY:
931 if ((LOWORD(wParam32)==WM_CREATE) || (LOWORD(wParam32)==WM_DESTROY))
932 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32));
933 /* else nothing to do */
934 return 0;
935 case WM_SETTEXT:
937 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
938 if (!str) return -1;
939 *plparam = (LPARAM)SEGPTR_GET(str);
941 return 1;
942 case WM_WINDOWPOSCHANGING:
943 case WM_WINDOWPOSCHANGED:
945 WINDOWPOS16 *wp = (WINDOWPOS16 *)SEGPTR_ALLOC( sizeof(*wp) +
946 sizeof(LPARAM) );
947 if (!wp) return -1;
948 STRUCT32_WINDOWPOS32to16( (WINDOWPOS32 *)*plparam, wp );
949 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
950 *plparam = (LPARAM)SEGPTR_GET(wp);
952 return 1;
953 case WM_ASKCBFORMATNAME:
954 case WM_COMPAREITEM:
955 case WM_DELETEITEM:
956 case WM_DEVMODECHANGE:
957 case WM_MDIACTIVATE:
958 case WM_MDICREATE:
959 case WM_MEASUREITEM:
960 case WM_PAINTCLIPBOARD:
961 case WM_SIZECLIPBOARD:
962 case WM_WININICHANGE:
963 fprintf( stderr, "MapMsg32ATo16: message %04x needs translation\n",
964 msg32 );
965 return -1;
967 default: /* No translation needed */
968 return 0;
973 /**********************************************************************
974 * WINPROC_UnmapMsg32ATo16
976 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
978 void WINPROC_UnmapMsg32ATo16( UINT16 msg, WPARAM16 wParam, LPARAM lParam )
980 switch(msg)
982 case WM_DRAWITEM:
983 SEGPTR_FREE( PTR_SEG_TO_LIN(lParam) );
984 break;
985 case WM_GETMINMAXINFO:
987 MINMAXINFO16 *mmi = (MINMAXINFO16 *)PTR_SEG_TO_LIN(lParam);
988 lParam = *(LPARAM *)(mmi + 1);
989 STRUCT32_MINMAXINFO16to32( mmi, (MINMAXINFO32 *)lParam );
990 SEGPTR_FREE(mmi);
992 break;
993 case WM_GETTEXT:
995 LPSTR str = (LPSTR)PTR_SEG_TO_LIN(lParam);
996 lParam = *((LPARAM *)str - 1);
997 strcpy( (LPSTR)lParam, str );
998 SEGPTR_FREE( (LPARAM *)str - 1 );
1000 break;
1001 case WM_NCCALCSIZE:
1003 NCCALCSIZE_PARAMS32 *nc32;
1004 NCCALCSIZE_PARAMS16 *nc = (NCCALCSIZE_PARAMS16 *)PTR_SEG_TO_LIN(lParam);
1005 lParam = *(LPARAM *)(nc + 1);
1006 nc32 = (NCCALCSIZE_PARAMS32 *)lParam;
1007 CONV_RECT16TO32( &nc->rgrc[0], &nc32->rgrc[0] );
1008 if (wParam)
1010 CONV_RECT16TO32( &nc->rgrc[1], &nc32->rgrc[1] );
1011 CONV_RECT16TO32( &nc->rgrc[2], &nc32->rgrc[2] );
1012 STRUCT32_WINDOWPOS16to32( (WINDOWPOS16 *)PTR_SEG_TO_LIN(nc->lppos),
1013 nc32->lppos );
1014 SEGPTR_FREE( PTR_SEG_TO_LIN(nc->lppos) );
1016 SEGPTR_FREE(nc);
1018 break;
1019 case WM_NCCREATE:
1020 case WM_CREATE:
1022 CREATESTRUCT16 *cs = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam);
1023 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->lpszName) );
1024 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->lpszClass) );
1025 SEGPTR_FREE( cs );
1027 break;
1028 case WM_SETTEXT:
1029 SEGPTR_FREE( PTR_SEG_TO_LIN(lParam) );
1030 break;
1031 case WM_WINDOWPOSCHANGING:
1032 case WM_WINDOWPOSCHANGED:
1034 WINDOWPOS16 *wp = (WINDOWPOS16 *)PTR_SEG_TO_LIN(lParam);
1035 lParam = *(LPARAM *)(wp + 1);
1036 STRUCT32_WINDOWPOS16to32( wp, (WINDOWPOS32 *)lParam );
1037 SEGPTR_FREE(wp);
1039 break;
1044 /**********************************************************************
1045 * WINPROC_MapMsg32WTo16
1047 * Map a message from 32-bit Unicode to 16-bit.
1048 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1050 INT32 WINPROC_MapMsg32WTo16( UINT32 msg32, WPARAM32 wParam32, UINT16 *pmsg16,
1051 WPARAM16 *pwparam16, LPARAM *plparam )
1053 switch(msg32)
1055 case WM_NCCREATE:
1056 case WM_CREATE:
1058 CREATESTRUCT16 *cs;
1059 CREATESTRUCT32W *cs32 = (CREATESTRUCT32W *)*plparam;
1061 if (!(cs = SEGPTR_NEW(CREATESTRUCT16))) return -1;
1062 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCT32A *)cs32, cs );
1063 if (HIWORD(cs32->lpszName))
1065 LPSTR name = SEGPTR_ALLOC( lstrlen32W(cs32->lpszName) + 1 );
1066 STRING32_UniToAnsi( name, cs32->lpszName );
1067 cs->lpszName = SEGPTR_GET(name);
1069 else cs->lpszName = (SEGPTR)cs32->lpszName;
1070 if (HIWORD(cs32->lpszClass))
1072 LPSTR name = SEGPTR_ALLOC( lstrlen32W(cs32->lpszClass) + 1 );
1073 STRING32_UniToAnsi( name, cs32->lpszClass );
1074 cs->lpszClass = SEGPTR_GET(name);
1076 else cs->lpszClass = (SEGPTR)cs32->lpszClass;
1077 *pmsg16 = (UINT16)msg32;
1078 *pwparam16 = (WPARAM16)LOWORD(wParam32);
1079 *plparam = (LPARAM)SEGPTR_GET(cs);
1081 return 1;
1082 case WM_SETTEXT:
1084 LPSTR str = SEGPTR_ALLOC( lstrlen32W((LPWSTR)*plparam) + 1 );
1085 if (!str) return -1;
1086 STRING32_UniToAnsi( str, (LPWSTR)*plparam );
1087 *pmsg16 = (UINT16)msg32;
1088 *pwparam16 = (WPARAM16)LOWORD(wParam32);
1089 *plparam = (LPARAM)SEGPTR_GET(str);
1091 return 1;
1092 default: /* No Unicode translation needed */
1093 return WINPROC_MapMsg32ATo16( msg32, wParam32, pmsg16,
1094 pwparam16, plparam );
1099 /**********************************************************************
1100 * WINPROC_UnmapMsg32WTo16
1102 * Unmap a message that was mapped from 32-bit Unicode to 16-bit.
1104 void WINPROC_UnmapMsg32WTo16( UINT16 msg, WPARAM16 wParam, LPARAM lParam )
1106 switch(msg)
1108 case WM_GETTEXT:
1110 LPSTR str = (LPSTR)PTR_SEG_TO_LIN(lParam);
1111 lParam = *((LPARAM *)str - 1);
1112 STRING32_AnsiToUni( (LPWSTR)lParam, str );
1113 SEGPTR_FREE( (LPARAM *)str - 1 );
1115 break;
1116 default:
1117 WINPROC_UnmapMsg32ATo16( msg, wParam, lParam );
1118 break;
1123 /**********************************************************************
1124 * WINPROC_CallProc32ATo32W
1126 * Call a window procedure, translating args from Ansi to Unicode.
1128 static LRESULT WINPROC_CallProc32ATo32W( WNDPROC32 func, HWND32 hwnd,
1129 UINT32 msg, WPARAM32 wParam,
1130 LPARAM lParam )
1132 LRESULT result;
1134 if (WINPROC_MapMsg32ATo32W( msg, wParam, &lParam ) == -1) return 0;
1135 result = CallWndProc32( func, hwnd, msg, wParam, lParam );
1136 WINPROC_UnmapMsg32ATo32W( msg, wParam, lParam );
1137 return result;
1141 /**********************************************************************
1142 * WINPROC_CallProc32WTo32A
1144 * Call a window procedure, translating args from Unicode to Ansi.
1146 static LRESULT WINPROC_CallProc32WTo32A( WNDPROC32 func, HWND32 hwnd,
1147 UINT32 msg, WPARAM32 wParam,
1148 LPARAM lParam )
1150 LRESULT result;
1152 if (WINPROC_MapMsg32WTo32A( msg, wParam, &lParam ) == -1) return 0;
1153 result = CallWndProc32( func, hwnd, msg, wParam, lParam );
1154 WINPROC_UnmapMsg32WTo32A( msg, wParam, lParam );
1155 return result;
1159 /**********************************************************************
1160 * WINPROC_CallProc16To32A
1162 * Call a 32-bit window procedure, translating the 16-bit args.
1164 LRESULT WINPROC_CallProc16To32A( HWND16 hwnd, UINT16 msg,
1165 WPARAM16 wParam, LPARAM lParam,
1166 WNDPROC32 func )
1168 LRESULT result;
1169 UINT32 msg32;
1170 WPARAM32 wParam32;
1172 if (WINPROC_MapMsg16To32A( msg, wParam, &msg32, &wParam32, &lParam ) == -1)
1173 return 0;
1174 result = CallWndProc32( func, hwnd, msg32, wParam32, lParam );
1175 WINPROC_UnmapMsg16To32A( msg32, wParam32, lParam );
1176 return result;
1180 /**********************************************************************
1181 * WINPROC_CallProc16To32W
1183 * Call a 32-bit window procedure, translating the 16-bit args.
1185 LRESULT WINPROC_CallProc16To32W( HWND16 hwnd, UINT16 msg,
1186 WPARAM16 wParam, LPARAM lParam,
1187 WNDPROC32 func )
1189 LRESULT result;
1190 UINT32 msg32;
1191 WPARAM32 wParam32;
1193 if (WINPROC_MapMsg16To32W( msg, wParam, &msg32, &wParam32, &lParam ) == -1)
1194 return 0;
1195 result = CallWndProc32( func, hwnd, msg32, wParam32, lParam );
1196 WINPROC_UnmapMsg16To32W( msg32, wParam32, lParam );
1197 return result;
1201 /**********************************************************************
1202 * WINPROC_CallProc32ATo16
1204 * Call a 16-bit window procedure, translating the 32-bit args.
1206 static LRESULT WINPROC_CallProc32ATo16( WNDPROC16 func, HWND32 hwnd,
1207 UINT32 msg, WPARAM32 wParam,
1208 LPARAM lParam )
1210 LRESULT result;
1211 UINT16 msg16;
1212 WPARAM16 wParam16;
1213 WND *wndPtr = WIN_FindWndPtr( hwnd );
1214 WORD ds = wndPtr ? wndPtr->hInstance : CURRENT_DS;
1216 if (WINPROC_MapMsg32ATo16( msg, wParam, &msg16, &wParam16, &lParam ) == -1)
1217 return 0;
1218 result = CallWndProc16( func, ds, hwnd, msg16, wParam16, lParam );
1219 WINPROC_UnmapMsg32ATo16( msg16, wParam16, lParam );
1220 return result;
1224 /**********************************************************************
1225 * WINPROC_CallProc32WTo16
1227 * Call a 16-bit window procedure, translating the 32-bit args.
1229 static LRESULT WINPROC_CallProc32WTo16( WNDPROC16 func, HWND32 hwnd,
1230 UINT32 msg, WPARAM32 wParam,
1231 LPARAM lParam )
1233 LRESULT result;
1234 UINT16 msg16;
1235 WPARAM16 wParam16;
1236 WND *wndPtr = WIN_FindWndPtr( hwnd );
1238 if (WINPROC_MapMsg32WTo16( msg, wParam, &msg16, &wParam16, &lParam ) == -1)
1239 return 0;
1240 result = CallWndProc16( func, wndPtr ? wndPtr->hInstance : CURRENT_DS,
1241 hwnd, msg16, wParam16, lParam );
1242 WINPROC_UnmapMsg32WTo16( msg16, wParam16, lParam );
1243 return result;
1247 /**********************************************************************
1248 * CallWindowProc16 (USER.122)
1250 LRESULT CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
1251 WPARAM16 wParam, LPARAM lParam )
1253 WND *wndPtr;
1254 WINDOWPROC *proc = WINPROC_GetPtr( func );
1256 if (!proc)
1258 wndPtr = WIN_FindWndPtr( hwnd );
1259 return CallWndProc16( (FARPROC16)func,
1260 wndPtr ? wndPtr->hInstance : CURRENT_DS,
1261 hwnd, msg, wParam, lParam );
1263 #if testing
1264 wndPtr = WIN_FindWndPtr( hwnd );
1265 return CallWndProc16( WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_16),
1266 wndPtr ? wndPtr->hInstance : CURRENT_DS,
1267 hwnd, msg, wParam, lParam );
1268 #endif
1270 switch(proc->type)
1272 case WIN_PROC_16:
1273 if (!proc->thunk.t_from32.proc) return 0;
1274 wndPtr = WIN_FindWndPtr( hwnd );
1275 #ifndef WINELIB
1276 if ((msg == WM_CREATE) || (msg == WM_NCCREATE))
1278 CREATESTRUCT16 *cs = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam);
1279 /* Build the CREATESTRUCT on the 16-bit stack. */
1280 /* This is really ugly, but some programs (notably the */
1281 /* "Undocumented Windows" examples) want it that way. */
1282 return CallWndProcNCCREATE16( proc->thunk.t_from32.proc,
1283 wndPtr ? wndPtr->hInstance : CURRENT_DS, cs->dwExStyle,
1284 cs->lpszClass, cs->lpszName, cs->style, cs->x, cs->y,
1285 cs->cx, cs->cy, cs->hwndParent, cs->hMenu, cs->hInstance,
1286 (LONG)cs->lpCreateParams, hwnd, msg, wParam,
1287 MAKELONG( IF1632_Saved16_sp-sizeof(CREATESTRUCT16),
1288 IF1632_Saved16_ss ) );
1290 #endif
1291 return CallWndProc16( proc->thunk.t_from32.proc,
1292 wndPtr ? wndPtr->hInstance : CURRENT_DS,
1293 hwnd, msg, wParam, lParam );
1294 case WIN_PROC_32A:
1295 if (!proc->thunk.t_from16.proc) return 0;
1296 return WINPROC_CallProc16To32A( hwnd, msg, wParam, lParam,
1297 proc->thunk.t_from16.proc );
1298 case WIN_PROC_32W:
1299 if (!proc->thunk.t_from16.proc) return 0;
1300 return WINPROC_CallProc16To32W( hwnd, msg, wParam, lParam,
1301 proc->thunk.t_from16.proc );
1302 default:
1303 fprintf( stderr, "CallWindowProc16: invalid proc %p\n", proc );
1304 return 0;
1309 /**********************************************************************
1310 * CallWindowProc32A (USER32.17)
1312 LRESULT CallWindowProc32A( WNDPROC32 func, HWND32 hwnd, UINT32 msg,
1313 WPARAM32 wParam, LPARAM lParam )
1315 WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
1317 if (!proc) return CallWndProc32( func, hwnd, msg, wParam, lParam );
1319 #if testing
1320 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_32A );
1321 return CallWndProc32( func, hwnd, msg, wParam, lParam );
1322 #endif
1324 switch(proc->type)
1326 case WIN_PROC_16:
1327 if (!proc->thunk.t_from32.proc) return 0;
1328 return WINPROC_CallProc32ATo16( proc->thunk.t_from32.proc,
1329 hwnd, msg, wParam, lParam );
1330 case WIN_PROC_32A:
1331 if (!proc->thunk.t_from16.proc) return 0;
1332 return CallWndProc32( proc->thunk.t_from16.proc,
1333 hwnd, msg, wParam, lParam );
1334 case WIN_PROC_32W:
1335 if (!proc->thunk.t_from16.proc) return 0;
1336 return WINPROC_CallProc32ATo32W( proc->thunk.t_from16.proc,
1337 hwnd, msg, wParam, lParam );
1338 default:
1339 fprintf( stderr, "CallWindowProc32A: invalid proc %p\n", proc );
1340 return 0;
1345 /**********************************************************************
1346 * CallWindowProc32W (USER32.18)
1348 LRESULT CallWindowProc32W( WNDPROC32 func, HWND32 hwnd, UINT32 msg,
1349 WPARAM32 wParam, LPARAM lParam )
1351 WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
1353 if (!proc) return CallWndProc32( func, hwnd, msg, wParam, lParam );
1355 #if testing
1356 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_32W );
1357 return CallWndProc32( func, hwnd, msg, wParam, lParam );
1358 #endif
1360 switch(proc->type)
1362 case WIN_PROC_16:
1363 if (!proc->thunk.t_from32.proc) return 0;
1364 return WINPROC_CallProc32WTo16( proc->thunk.t_from32.proc,
1365 hwnd, msg, wParam, lParam );
1366 case WIN_PROC_32A:
1367 if (!proc->thunk.t_from16.proc) return 0;
1368 return WINPROC_CallProc32WTo32A( proc->thunk.t_from16.proc,
1369 hwnd, msg, wParam, lParam );
1370 case WIN_PROC_32W:
1371 if (!proc->thunk.t_from16.proc) return 0;
1372 return CallWndProc32( proc->thunk.t_from16.proc,
1373 hwnd, msg, wParam, lParam );
1374 default:
1375 fprintf( stderr, "CallWindowProc32W: invalid proc %p\n", proc );
1376 return 0;