Fix the Winelib case.
[wine.git] / windows / winproc.c
blob00224a3801727e1e1b66f61cc854a79918e0e538
1 /*
2 * Window procedure callbacks
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1996 Alexandre Julliard
6 */
8 #include <string.h>
10 #include "config.h"
11 #include "windef.h"
12 #include "winnls.h"
13 #include "wingdi.h"
14 #include "wine/winbase16.h"
15 #include "wine/winuser16.h"
16 #include "stackframe.h"
17 #include "builtin16.h"
18 #include "heap.h"
19 #include "selectors.h"
20 #include "struct32.h"
21 #include "win.h"
22 #include "winproc.h"
23 #include "debugtools.h"
24 #include "spy.h"
25 #include "commctrl.h"
26 #include "task.h"
27 #include "thread.h"
28 #include "menu.h"
30 DECLARE_DEBUG_CHANNEL(msg);
31 DECLARE_DEBUG_CHANNEL(relay);
32 DECLARE_DEBUG_CHANNEL(win);
34 /* Window procedure 16-to-32-bit thunk,
35 * see BuildSpec16File() in tools/build.c */
37 #include "pshpack1.h"
38 typedef struct
40 WORD pushw_bp; /* pushw %bp */
41 BYTE pushl_func; /* pushl $proc */
42 WNDPROC proc;
43 WORD pushw_ax; /* pushw %ax */
44 BYTE pushl_relay; /* pushl $relay */
45 void (*relay)(); /* WINPROC_Thunk16To32A/W() */
46 BYTE lcall; /* lcall cs:glue */
47 void (*glue)(); /* __wine_call_from_16_long */
48 WORD cs; /* __FLATCS */
49 WORD lret; /* lret $10 */
50 WORD nArgs;
51 } WINPROC_THUNK_FROM16;
52 #include "poppack.h"
54 /* Window procedure 32-to-16-bit thunk,
55 * see BuildSpec32File() in tools/build.c */
57 typedef struct
59 BYTE popl_eax; /* popl %eax (return address) */
60 BYTE pushl_func; /* pushl $proc */
61 WNDPROC16 proc WINE_PACKED;
62 BYTE pushl_eax; /* pushl %eax */
63 BYTE jmp; /* jmp relay (relative jump)*/
64 void (*relay)() WINE_PACKED; /* WINPROC_CallProc32ATo16() */
65 } WINPROC_THUNK_FROM32;
67 /* Simple jmp to call 32-bit procedure directly */
68 typedef struct
70 BYTE jmp; /* jmp proc (relative jump) */
71 WNDPROC proc WINE_PACKED;
72 } WINPROC_JUMP;
74 typedef union
76 WINPROC_THUNK_FROM16 t_from16;
77 WINPROC_THUNK_FROM32 t_from32;
78 } WINPROC_THUNK;
80 typedef struct tagWINDOWPROC
82 WINPROC_THUNK thunk; /* Thunk */
83 WINPROC_JUMP jmp; /* Jump */
84 struct tagWINDOWPROC *next; /* Next window proc */
85 UINT magic; /* Magic number */
86 WINDOWPROCTYPE type; /* Function type */
87 WINDOWPROCUSER user; /* Function user */
88 } WINDOWPROC;
90 #define WINPROC_MAGIC ('W' | ('P' << 8) | ('R' << 16) | ('C' << 24))
92 #define WINPROC_THUNKPROC(pproc) \
93 (((pproc)->type == WIN_PROC_16) ? \
94 (WNDPROC16)((pproc)->thunk.t_from32.proc) : \
95 (WNDPROC16)((pproc)->thunk.t_from16.proc))
97 static LRESULT WINAPI WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd,
98 UINT msg, WPARAM wParam,
99 LPARAM lParam );
100 static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
101 UINT msg, WPARAM wParam,
102 LPARAM lParam );
103 static LRESULT WINAPI WINPROC_Thunk16To32A( WNDPROC func, LPBYTE args );
104 static LRESULT WINAPI WINPROC_Thunk16To32W( WNDPROC func, LPBYTE args );
106 static HANDLE WinProcHeap;
109 /**********************************************************************
110 * WINPROC_Init
112 BOOL WINPROC_Init(void)
114 WinProcHeap = HeapCreate( HEAP_WINE_SEGPTR | HEAP_WINE_CODESEG, 0, 0 );
115 if (!WinProcHeap)
117 WARN_(relay)("Unable to create winproc heap\n" );
118 return FALSE;
120 return TRUE;
124 #ifdef __i386__
125 /* Some window procedures modify register they shouldn't, or are not
126 * properly declared stdcall; so we need a small assembly wrapper to
127 * call them. */
128 extern LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
129 WPARAM wParam, LPARAM lParam );
130 __ASM_GLOBAL_FUNC( WINPROC_wrapper,
131 "pushl %ebp\n\t"
132 "movl %esp,%ebp\n\t"
133 "pushl %edi\n\t"
134 "pushl %esi\n\t"
135 "pushl %ebx\n\t"
136 "pushl 24(%ebp)\n\t"
137 "pushl 20(%ebp)\n\t"
138 "pushl 16(%ebp)\n\t"
139 "pushl 12(%ebp)\n\t"
140 "movl 8(%ebp),%eax\n\t"
141 "call *%eax\n\t"
142 "leal -12(%ebp),%esp\n\t"
143 "popl %ebx\n\t"
144 "popl %esi\n\t"
145 "popl %edi\n\t"
146 "leave\n\t"
147 "ret" );
148 #else
149 static inline LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
150 WPARAM wParam, LPARAM lParam )
152 return proc( hwnd, msg, wParam, lParam );
154 #endif /* __i386__ */
156 /**********************************************************************
157 * WINPROC_CallWndProc32
159 * Call a 32-bit WndProc.
161 static LRESULT WINPROC_CallWndProc( WNDPROC proc, HWND hwnd, UINT msg,
162 WPARAM wParam, LPARAM lParam )
164 LRESULT retvalue;
165 int iWndsLocks;
167 TRACE_(relay)("(wndproc=%p,hwnd=%08x,msg=%s,wp=%08x,lp=%08lx)\n",
168 proc, hwnd, SPY_GetMsgName(msg), wParam, lParam );
169 /* To avoid any deadlocks, all the locks on the windows structures
170 must be suspended before the control is passed to the application */
171 iWndsLocks = WIN_SuspendWndsLock();
172 retvalue = WINPROC_wrapper( proc, hwnd, msg, wParam, lParam );
173 WIN_RestoreWndsLock(iWndsLocks);
174 TRACE_(relay)("(wndproc=%p,hwnd=%08x,msg=%s,wp=%08x,lp=%08lx) ret=%08lx\n",
175 proc, hwnd, SPY_GetMsgName(msg), wParam, lParam, retvalue );
176 return retvalue;
179 /***********************************************************************
180 * WINPROC_CallWndProc16
182 * Call a 16-bit window procedure
184 static LRESULT WINAPI WINPROC_CallWndProc16( WNDPROC16 proc, HWND16 hwnd,
185 UINT16 msg, WPARAM16 wParam,
186 LPARAM lParam )
188 CONTEXT86 context;
189 LRESULT ret;
190 WORD *args;
191 WND *wndPtr = WIN_FindWndPtr( hwnd );
192 DWORD offset = 0;
193 TEB *teb = NtCurrentTeb();
194 int iWndsLocks;
196 /* Window procedures want ax = hInstance, ds = es = ss */
198 memset(&context, '\0', sizeof(context));
199 context.SegDs = context.SegEs = SELECTOROF(teb->cur_stack);
200 context.Eax = wndPtr ? wndPtr->hInstance : context.SegDs;
201 context.SegCs = SELECTOROF(proc);
202 context.Eip = OFFSETOF(proc);
203 context.Ebp = OFFSETOF(teb->cur_stack)
204 + (WORD)&((STACK16FRAME*)0)->bp;
206 WIN_ReleaseWndPtr(wndPtr);
208 if (lParam)
210 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
211 work if structures passed in lParam are placed in the stack/data
212 segment. Programmers easily make the mistake of converting lParam
213 to a near rather than a far pointer, since Windows apparently
214 allows this. We copy the structures to the 16 bit stack; this is
215 ugly but makes these programs work. */
216 switch (msg)
218 case WM_CREATE:
219 case WM_NCCREATE:
220 offset = sizeof(CREATESTRUCT16); break;
221 case WM_DRAWITEM:
222 offset = sizeof(DRAWITEMSTRUCT16); break;
223 case WM_COMPAREITEM:
224 offset = sizeof(COMPAREITEMSTRUCT16); break;
226 if (offset)
228 void *s = PTR_SEG_TO_LIN(lParam);
229 lParam = stack16_push( offset );
230 memcpy( PTR_SEG_TO_LIN(lParam), s, offset );
234 iWndsLocks = WIN_SuspendWndsLock();
236 args = (WORD *)THREAD_STACK16(teb) - 5;
237 args[0] = LOWORD(lParam);
238 args[1] = HIWORD(lParam);
239 args[2] = wParam;
240 args[3] = msg;
241 args[4] = hwnd;
243 wine_call_to_16_regs_short( &context, 5 * sizeof(WORD) );
244 ret = MAKELONG( LOWORD(context.Eax), LOWORD(context.Edx) );
245 if (offset) stack16_pop( offset );
247 WIN_RestoreWndsLock(iWndsLocks);
249 return ret;
253 /**********************************************************************
254 * WINPROC_GetPtr
256 * Return a pointer to the win proc.
258 static WINDOWPROC *WINPROC_GetPtr( WNDPROC16 handle )
260 BYTE *ptr;
261 WINDOWPROC *proc;
263 /* Check for a linear pointer */
265 if (handle && HeapValidate( WinProcHeap, 0, (LPVOID)handle ))
267 ptr = (BYTE *)handle;
268 /* First check if it is the jmp address */
269 if (*ptr == 0xe9 /* jmp */) ptr -= (int)&((WINDOWPROC *)0)->jmp -
270 (int)&((WINDOWPROC *)0)->thunk;
271 /* Now it must be the thunk address */
272 if (*ptr == 0x58 /* popl eax */) ptr -= (int)&((WINDOWPROC *)0)->thunk;
273 /* Now we have a pointer to the WINDOWPROC struct */
274 if (((WINDOWPROC *)ptr)->magic == WINPROC_MAGIC)
275 return (WINDOWPROC *)ptr;
278 /* Check for a segmented pointer */
280 if (!IsBadReadPtr16((SEGPTR)handle,sizeof(WINDOWPROC)-sizeof(proc->thunk)))
282 ptr = (BYTE *)PTR_SEG_TO_LIN(handle);
283 if (!HeapValidate( WinProcHeap, 0, ptr )) return NULL;
284 /* It must be the thunk address */
285 if (*ptr == 0x58 /* popl eax */) ptr -= (int)&((WINDOWPROC *)0)->thunk;
286 /* Now we have a pointer to the WINDOWPROC struct */
287 if (((WINDOWPROC *)ptr)->magic == WINPROC_MAGIC)
288 return (WINDOWPROC *)ptr;
291 return NULL;
295 /**********************************************************************
296 * WINPROC_AllocWinProc
298 * Allocate a new window procedure.
300 static WINDOWPROC *WINPROC_AllocWinProc( WNDPROC16 func, WINDOWPROCTYPE type,
301 WINDOWPROCUSER user )
303 WINDOWPROC *proc, *oldproc;
305 /* Allocate a window procedure */
307 if (!(proc = HeapAlloc( WinProcHeap, 0, sizeof(WINDOWPROC) ))) return 0;
309 /* Check if the function is already a win proc */
311 if ((oldproc = WINPROC_GetPtr( func )))
313 *proc = *oldproc;
315 else
317 switch(type)
319 case WIN_PROC_16:
320 proc->thunk.t_from32.popl_eax = 0x58; /* popl %eax */
321 proc->thunk.t_from32.pushl_func = 0x68; /* pushl $proc */
322 proc->thunk.t_from32.proc = func;
323 proc->thunk.t_from32.pushl_eax = 0x50; /* pushl %eax */
324 proc->thunk.t_from32.jmp = 0xe9; /* jmp relay*/
325 proc->thunk.t_from32.relay = /* relative jump */
326 (void(*)())((DWORD)WINPROC_CallProc32ATo16 -
327 (DWORD)(&proc->thunk.t_from32.relay + 1));
328 break;
329 case WIN_PROC_32A:
330 case WIN_PROC_32W:
331 proc->thunk.t_from16.pushw_bp = 0x5566; /* pushw %bp */
332 proc->thunk.t_from16.pushl_func = 0x68; /* pushl $proc */
333 proc->thunk.t_from16.proc = (FARPROC)func;
334 proc->thunk.t_from16.pushw_ax = 0x5066; /* pushw %ax */
335 proc->thunk.t_from16.pushl_relay = 0x68; /* pushl $relay */
336 proc->thunk.t_from16.relay = (type == WIN_PROC_32A) ?
337 (void(*)())WINPROC_Thunk16To32A :
338 (void(*)())WINPROC_Thunk16To32W;
339 proc->thunk.t_from16.lcall = 0x9a; /* lcall cs:glue */
340 proc->thunk.t_from16.glue = (void*)__wine_call_from_16_long;
341 proc->thunk.t_from16.cs = __get_cs();
342 proc->thunk.t_from16.lret = 0xca66;
343 proc->thunk.t_from16.nArgs = 10;
344 proc->jmp.jmp = 0xe9;
345 /* Fixup relative jump */
346 proc->jmp.proc = (WNDPROC)((DWORD)func -
347 (DWORD)(&proc->jmp.proc + 1));
348 break;
349 default:
350 /* Should not happen */
351 break;
353 proc->magic = WINPROC_MAGIC;
354 proc->type = type;
355 proc->user = user;
357 proc->next = NULL;
358 TRACE_(win)("(%08x,%d): returning %08x\n",
359 (UINT)func, type, (UINT)proc );
360 return proc;
364 /**********************************************************************
365 * WINPROC_GetProc
367 * Get a window procedure pointer that can be passed to the Windows program.
369 WNDPROC16 WINPROC_GetProc( HWINDOWPROC proc, WINDOWPROCTYPE type )
371 if (!proc) return NULL;
372 if (type == WIN_PROC_16) /* We want a 16:16 address */
374 if (((WINDOWPROC *)proc)->type == WIN_PROC_16)
375 return ((WINDOWPROC *)proc)->thunk.t_from32.proc;
376 else
377 return (WNDPROC16)HEAP_GetSegptr( WinProcHeap, 0,
378 &((WINDOWPROC *)proc)->thunk );
380 else /* We want a 32-bit address */
382 if (((WINDOWPROC *)proc)->type == WIN_PROC_16)
383 return (WNDPROC16)&((WINDOWPROC *)proc)->thunk;
384 else if (type != ((WINDOWPROC *)proc)->type)
385 /* Have to return the jmp address if types don't match */
386 return (WNDPROC16)&((WINDOWPROC *)proc)->jmp;
387 else
388 /* Some Win16 programs want to get back the proc they set */
389 return (WNDPROC16)((WINDOWPROC *)proc)->thunk.t_from16.proc;
394 /**********************************************************************
395 * WINPROC_SetProc
397 * Set the window procedure for a window or class. There are
398 * three tree classes of winproc callbacks:
400 * 1) class -> wp - not subclassed
401 * class -> wp -> wp -> wp -> wp - SetClassLong()
402 * / /
403 * 2) window -' / - not subclassed
404 * window -> wp -> wp ' - SetWindowLong()
406 * 3) timer -> wp - SetTimer()
408 * Initially, winproc of the window points to the current winproc
409 * thunk of its class. Subclassing prepends a new thunk to the
410 * window winproc chain at the head of the list. Thus, window thunk
411 * list includes class thunks and the latter are preserved when the
412 * window is destroyed.
415 BOOL WINPROC_SetProc( HWINDOWPROC *pFirst, WNDPROC16 func,
416 WINDOWPROCTYPE type, WINDOWPROCUSER user )
418 BOOL bRecycle = FALSE;
419 WINDOWPROC *proc, **ppPrev;
421 /* Check if function is already in the list */
423 ppPrev = (WINDOWPROC **)pFirst;
424 proc = WINPROC_GetPtr( func );
425 while (*ppPrev)
427 if (proc)
429 if (*ppPrev == proc)
431 if ((*ppPrev)->user != user)
433 /* terminal thunk is being restored */
435 WINPROC_FreeProc( *pFirst, (*ppPrev)->user );
436 *(WINDOWPROC **)pFirst = *ppPrev;
437 return TRUE;
439 bRecycle = TRUE;
440 break;
443 else
445 if (((*ppPrev)->type == type) &&
446 (func == WINPROC_THUNKPROC(*ppPrev)))
448 bRecycle = TRUE;
449 break;
453 /* WPF_CLASS thunk terminates window thunk list */
454 if ((*ppPrev)->user != user) break;
455 ppPrev = &(*ppPrev)->next;
458 if (bRecycle)
460 /* Extract this thunk from the list */
461 proc = *ppPrev;
462 *ppPrev = proc->next;
464 else /* Allocate a new one */
466 if (proc) /* Was already a win proc */
468 type = proc->type;
469 func = WINPROC_THUNKPROC(proc);
471 proc = WINPROC_AllocWinProc( func, type, user );
472 if (!proc) return FALSE;
475 /* Add the win proc at the head of the list */
477 TRACE_(win)("(%08x,%08x,%d): res=%08x\n",
478 (UINT)*pFirst, (UINT)func, type, (UINT)proc );
479 proc->next = *(WINDOWPROC **)pFirst;
480 *(WINDOWPROC **)pFirst = proc;
481 return TRUE;
485 /**********************************************************************
486 * WINPROC_FreeProc
488 * Free a list of win procs.
490 void WINPROC_FreeProc( HWINDOWPROC proc, WINDOWPROCUSER user )
492 while (proc)
494 WINDOWPROC *next = ((WINDOWPROC *)proc)->next;
495 if (((WINDOWPROC *)proc)->user != user) break;
496 TRACE_(win)("freeing %08x\n", (UINT)proc);
497 HeapFree( WinProcHeap, 0, proc );
498 proc = next;
503 /**********************************************************************
504 * WINPROC_GetProcType
506 * Return the window procedure type.
508 WINDOWPROCTYPE WINPROC_GetProcType( HWINDOWPROC proc )
510 if (!proc ||
511 (((WINDOWPROC *)proc)->magic != WINPROC_MAGIC))
512 return WIN_PROC_INVALID;
513 return ((WINDOWPROC *)proc)->type;
515 /**********************************************************************
516 * WINPROC_TestCBForStr
518 * Return TRUE if the lparam is a string
520 static BOOL WINPROC_TestCBForStr ( HWND hwnd )
522 BOOL retvalue;
523 WND * wnd = WIN_FindWndPtr(hwnd);
524 retvalue = ( !(LOWORD(wnd->dwStyle) & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) ||
525 (LOWORD(wnd->dwStyle) & CBS_HASSTRINGS) );
526 WIN_ReleaseWndPtr(wnd);
527 return retvalue;
529 /**********************************************************************
530 * WINPROC_TestLBForStr
532 * Return TRUE if the lparam is a string
534 static BOOL WINPROC_TestLBForStr ( HWND hwnd )
536 BOOL retvalue;
537 WND * wnd = WIN_FindWndPtr(hwnd);
538 retvalue = ( !(LOWORD(wnd->dwStyle) & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) ||
539 (LOWORD(wnd->dwStyle) & LBS_HASSTRINGS) );
540 WIN_ReleaseWndPtr(wnd);
541 return retvalue;
544 /**********************************************************************
545 * WINPROC_MapMsg32ATo32W
547 * Map a message from Ansi to Unicode.
548 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
550 * FIXME:
551 * WM_CHARTOITEM, WM_MENUCHAR
553 * FIXME:
554 * WM_GETTEXT/WM_SETTEXT and static control with SS_ICON style:
555 * the first four bytes are the handle of the icon
556 * when the WM_SETTEXT message has been used to set the icon
558 INT WINPROC_MapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam )
560 switch(msg)
562 case WM_GETTEXT:
564 LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
565 *pwparam * sizeof(WCHAR) + sizeof(LPARAM) );
566 if (!ptr) return -1;
567 *ptr++ = *plparam; /* Store previous lParam */
568 *plparam = (LPARAM)ptr;
570 return 1;
571 /* lparam is string (0-terminated) */
572 case WM_SETTEXT:
573 case WM_WININICHANGE:
574 case CB_DIR:
575 case CB_FINDSTRING:
576 case CB_FINDSTRINGEXACT:
577 case CB_SELECTSTRING:
578 case LB_DIR:
579 case LB_ADDFILE:
580 case LB_FINDSTRING:
581 case LB_SELECTSTRING:
582 case EM_REPLACESEL:
583 *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
584 return (*plparam ? 1 : -1);
586 case WM_NCCREATE:
587 case WM_CREATE:
589 struct s
590 { CREATESTRUCTW cs; /* new structure */
591 LPCWSTR lpszName; /* allocated Name */
592 LPCWSTR lpszClass; /* allocated Class */
595 struct s *xs = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct s));
596 if (!xs) return -1;
597 xs->cs = *(CREATESTRUCTW *)*plparam;
598 if (HIWORD(xs->cs.lpszName))
599 xs->lpszName = xs->cs.lpszName = HEAP_strdupAtoW( GetProcessHeap(), 0,
600 (LPCSTR)xs->cs.lpszName );
601 if (HIWORD(xs->cs.lpszClass))
602 xs->lpszClass = xs->cs.lpszClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
603 (LPCSTR)xs->cs.lpszClass );
604 *plparam = (LPARAM)xs;
606 return 1;
607 case WM_MDICREATE:
609 MDICREATESTRUCTW *cs =
610 (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
611 if (!cs) return -1;
612 *cs = *(MDICREATESTRUCTW *)*plparam;
613 if (HIWORD(cs->szClass))
614 cs->szClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
615 (LPCSTR)cs->szClass );
616 if (HIWORD(cs->szTitle))
617 cs->szTitle = HEAP_strdupAtoW( GetProcessHeap(), 0,
618 (LPCSTR)cs->szTitle );
619 *plparam = (LPARAM)cs;
621 return 1;
623 /* Listbox */
624 case LB_ADDSTRING:
625 case LB_INSERTSTRING:
626 if ( WINPROC_TestLBForStr( hwnd ))
627 *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
628 return (*plparam ? 1 : -1);
630 case LB_GETTEXT: /* fixme: fixed sized buffer */
631 { if ( WINPROC_TestLBForStr( hwnd ))
632 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
633 if (!ptr) return -1;
634 *ptr++ = *plparam; /* Store previous lParam */
635 *plparam = (LPARAM)ptr;
638 return 1;
640 /* Combobox */
641 case CB_ADDSTRING:
642 case CB_INSERTSTRING:
643 if ( WINPROC_TestCBForStr( hwnd ))
644 *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
645 return (*plparam ? 1 : -1);
647 case CB_GETLBTEXT: /* fixme: fixed sized buffer */
648 { if ( WINPROC_TestCBForStr( hwnd ))
649 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
650 if (!ptr) return -1;
651 *ptr++ = *plparam; /* Store previous lParam */
652 *plparam = (LPARAM)ptr;
655 return 1;
657 /* Multiline edit */
658 case EM_GETLINE:
659 { WORD len = (WORD)*plparam;
660 LPARAM *ptr = (LPARAM *) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(WCHAR) );
661 if (!ptr) return -1;
662 *ptr++ = *plparam; /* Store previous lParam */
663 *((WORD *) ptr) = len; /* Store the length */
664 *plparam = (LPARAM)ptr;
666 return 1;
668 case WM_CHAR:
669 case WM_DEADCHAR:
670 case WM_SYSCHAR:
671 case WM_SYSDEADCHAR:
673 char ch = *pwparam;
674 WCHAR wch;
675 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
676 *pwparam = wch;
678 return 0;
680 case WM_ASKCBFORMATNAME:
681 case WM_DEVMODECHANGE:
682 case WM_PAINTCLIPBOARD:
683 case WM_SIZECLIPBOARD:
684 case EM_SETPASSWORDCHAR:
685 FIXME_(msg)("message %s (0x%x) needs translation, please report\n", SPY_GetMsgName(msg), msg );
686 return -1;
687 default: /* No translation needed */
688 return 0;
693 /**********************************************************************
694 * WINPROC_UnmapMsg32ATo32W
696 * Unmap a message that was mapped from Ansi to Unicode.
698 void WINPROC_UnmapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
700 switch(msg)
702 case WM_GETTEXT:
704 LPARAM *ptr = (LPARAM *)lParam - 1;
705 if (wParam > 0 && !WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
706 (LPSTR)*ptr, wParam, NULL, NULL ))
707 ((LPSTR)*ptr)[wParam-1] = 0;
708 HeapFree( GetProcessHeap(), 0, ptr );
710 break;
712 case WM_NCCREATE:
713 case WM_CREATE:
715 struct s
716 { CREATESTRUCTW cs; /* new structure */
717 LPWSTR lpszName; /* allocated Name */
718 LPWSTR lpszClass; /* allocated Class */
720 struct s *xs = (struct s *)lParam;
721 if (xs->lpszName) HeapFree( GetProcessHeap(), 0, xs->lpszName );
722 if (xs->lpszClass) HeapFree( GetProcessHeap(), 0, xs->lpszClass );
723 HeapFree( GetProcessHeap(), 0, xs );
725 break;
727 case WM_MDICREATE:
729 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
730 if (HIWORD(cs->szTitle))
731 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
732 if (HIWORD(cs->szClass))
733 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
734 HeapFree( GetProcessHeap(), 0, cs );
736 break;
738 case WM_SETTEXT:
739 case WM_WININICHANGE:
740 case CB_DIR:
741 case CB_FINDSTRING:
742 case CB_FINDSTRINGEXACT:
743 case CB_SELECTSTRING:
744 case LB_DIR:
745 case LB_ADDFILE:
746 case LB_FINDSTRING:
747 case LB_SELECTSTRING:
748 case EM_REPLACESEL:
749 HeapFree( GetProcessHeap(), 0, (void *)lParam );
750 break;
752 /* Listbox */
753 case LB_ADDSTRING:
754 case LB_INSERTSTRING:
755 if ( WINPROC_TestLBForStr( hwnd ))
756 HeapFree( GetProcessHeap(), 0, (void *)lParam );
757 break;
759 case LB_GETTEXT:
760 { if ( WINPROC_TestLBForStr( hwnd ))
761 { LPARAM *ptr = (LPARAM *)lParam - 1;
762 WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1, (LPSTR)*ptr, 0x7fffffff, NULL, NULL );
763 HeapFree( GetProcessHeap(), 0, ptr );
766 break;
768 /* Combobox */
769 case CB_ADDSTRING:
770 case CB_INSERTSTRING:
771 if ( WINPROC_TestCBForStr( hwnd ))
772 HeapFree( GetProcessHeap(), 0, (void *)lParam );
773 break;
775 case CB_GETLBTEXT:
776 { if ( WINPROC_TestCBForStr( hwnd ))
777 { LPARAM *ptr = (LPARAM *)lParam - 1;
778 WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1, (LPSTR)*ptr, 0x7fffffff, NULL, NULL );
779 HeapFree( GetProcessHeap(), 0, ptr );
782 break;
784 /* Multiline edit */
785 case EM_GETLINE:
786 { LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lParam */
787 WORD len = *(WORD *) lParam;
788 if (len > 0 && !WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
789 (LPSTR)*ptr, len, NULL, NULL ))
790 ((LPSTR)*ptr)[len-1] = 0;
791 HeapFree( GetProcessHeap(), 0, ptr );
793 break;
798 /**********************************************************************
799 * WINPROC_MapMsg32WTo32A
801 * Map a message from Unicode to Ansi.
802 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
804 INT WINPROC_MapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam )
806 switch(msg)
808 case WM_GETTEXT:
810 LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
811 *pwparam + sizeof(LPARAM) );
812 if (!ptr) return -1;
813 *ptr++ = *plparam; /* Store previous lParam */
814 *plparam = (LPARAM)ptr;
816 return 1;
818 case WM_SETTEXT:
819 case WM_WININICHANGE:
820 case CB_DIR:
821 case CB_FINDSTRING:
822 case CB_FINDSTRINGEXACT:
823 case CB_SELECTSTRING:
824 case LB_DIR:
825 case LB_ADDFILE:
826 case LB_FINDSTRING:
827 case LB_SELECTSTRING:
828 case EM_REPLACESEL:
829 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
830 return (*plparam ? 1 : -1);
832 case WM_NCCREATE:
833 case WM_CREATE:
835 CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
836 sizeof(*cs) );
837 if (!cs) return -1;
838 *cs = *(CREATESTRUCTA *)*plparam;
839 if (HIWORD(cs->lpszName))
840 cs->lpszName = HEAP_strdupWtoA( GetProcessHeap(), 0,
841 (LPCWSTR)cs->lpszName );
842 if (HIWORD(cs->lpszClass))
843 cs->lpszClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
844 (LPCWSTR)cs->lpszClass);
845 *plparam = (LPARAM)cs;
847 return 1;
848 case WM_MDICREATE:
850 MDICREATESTRUCTA *cs =
851 (MDICREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
852 if (!cs) return -1;
853 *cs = *(MDICREATESTRUCTA *)*plparam;
854 if (HIWORD(cs->szTitle))
855 cs->szTitle = HEAP_strdupWtoA( GetProcessHeap(), 0,
856 (LPCWSTR)cs->szTitle );
857 if (HIWORD(cs->szClass))
858 cs->szClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
859 (LPCWSTR)cs->szClass );
860 *plparam = (LPARAM)cs;
862 return 1;
864 /* Listbox */
865 case LB_ADDSTRING:
866 case LB_INSERTSTRING:
867 if ( WINPROC_TestLBForStr( hwnd ))
868 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
869 return (*plparam ? 1 : -1);
871 case LB_GETTEXT: /* fixme: fixed sized buffer */
872 { if ( WINPROC_TestLBForStr( hwnd ))
873 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
874 if (!ptr) return -1;
875 *ptr++ = *plparam; /* Store previous lParam */
876 *plparam = (LPARAM)ptr;
879 return 1;
881 /* Combobox */
882 case CB_ADDSTRING:
883 case CB_INSERTSTRING:
884 if ( WINPROC_TestCBForStr( hwnd ))
885 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
886 return (*plparam ? 1 : -1);
888 case CB_GETLBTEXT: /* fixme: fixed sized buffer */
889 { if ( WINPROC_TestCBForStr( hwnd ))
890 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
891 if (!ptr) return -1;
892 *ptr++ = *plparam; /* Store previous lParam */
893 *plparam = (LPARAM)ptr;
896 return 1;
898 /* Multiline edit */
899 case EM_GETLINE:
900 { WORD len = (WORD)*plparam;
901 LPARAM *ptr = (LPARAM *) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(CHAR) );
902 if (!ptr) return -1;
903 *ptr++ = *plparam; /* Store previous lParam */
904 *((WORD *) ptr) = len; /* Store the length */
905 *plparam = (LPARAM)ptr;
907 return 1;
909 case WM_CHAR:
910 case WM_DEADCHAR:
911 case WM_SYSCHAR:
912 case WM_SYSDEADCHAR:
914 WCHAR wch = *pwparam;
915 char ch;
916 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL );
917 *pwparam = ch;
919 return 0;
921 case WM_ASKCBFORMATNAME:
922 case WM_DEVMODECHANGE:
923 case WM_PAINTCLIPBOARD:
924 case WM_SIZECLIPBOARD:
925 case EM_SETPASSWORDCHAR:
926 FIXME_(msg)("message %s (%04x) needs translation, please report\n",SPY_GetMsgName(msg),msg );
927 return -1;
928 default: /* No translation needed */
929 return 0;
934 /**********************************************************************
935 * WINPROC_UnmapMsg32WTo32A
937 * Unmap a message that was mapped from Unicode to Ansi.
939 void WINPROC_UnmapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
941 switch(msg)
943 case WM_GETTEXT:
945 LPARAM *ptr = (LPARAM *)lParam - 1;
946 if (wParam)
948 if (!MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, wParam ))
949 ((LPWSTR)*ptr)[wParam-1] = 0;
951 HeapFree( GetProcessHeap(), 0, ptr );
953 break;
955 case WM_SETTEXT:
956 case WM_WININICHANGE:
957 case CB_DIR:
958 case CB_FINDSTRING:
959 case CB_FINDSTRINGEXACT:
960 case CB_SELECTSTRING:
961 case LB_DIR:
962 case LB_ADDFILE:
963 case LB_FINDSTRING:
964 case LB_SELECTSTRING:
965 case EM_REPLACESEL:
966 HeapFree( GetProcessHeap(), 0, (void *)lParam );
967 break;
969 case WM_NCCREATE:
970 case WM_CREATE:
972 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
973 if (HIWORD(cs->lpszName))
974 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszName );
975 if (HIWORD(cs->lpszClass))
976 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszClass );
977 HeapFree( GetProcessHeap(), 0, cs );
979 break;
981 case WM_MDICREATE:
983 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
984 if (HIWORD(cs->szTitle))
985 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
986 if (HIWORD(cs->szClass))
987 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
988 HeapFree( GetProcessHeap(), 0, cs );
990 break;
992 /* Listbox */
993 case LB_ADDSTRING:
994 case LB_INSERTSTRING:
995 if ( WINPROC_TestLBForStr( hwnd ))
996 HeapFree( GetProcessHeap(), 0, (void *)lParam );
997 break;
999 case LB_GETTEXT:
1000 if ( WINPROC_TestLBForStr( hwnd ))
1002 LPARAM *ptr = (LPARAM *)lParam - 1;
1003 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, 0x7fffffff );
1004 HeapFree( GetProcessHeap(), 0, ptr );
1006 break;
1008 /* Combobox */
1009 case CB_ADDSTRING:
1010 case CB_INSERTSTRING:
1011 if ( WINPROC_TestCBForStr( hwnd ))
1012 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1013 break;
1015 case CB_GETLBTEXT:
1016 if ( WINPROC_TestCBForStr( hwnd ))
1018 LPARAM *ptr = (LPARAM *)lParam - 1;
1019 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, 0x7fffffff );
1020 HeapFree( GetProcessHeap(), 0, ptr );
1022 break;
1024 /* Multiline edit */
1025 case EM_GETLINE:
1026 { LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lparam */
1027 WORD len = *(WORD *)ptr;
1028 if (len)
1030 if (!MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, len ))
1031 ((LPWSTR)*ptr)[len-1] = 0;
1033 HeapFree( GetProcessHeap(), 0, ptr );
1035 break;
1040 /**********************************************************************
1041 * WINPROC_MapMsg16To32A
1043 * Map a message from 16- to 32-bit Ansi.
1044 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1046 INT WINPROC_MapMsg16To32A( UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
1047 WPARAM *pwparam32, LPARAM *plparam )
1049 *pmsg32 = (UINT)msg16;
1050 *pwparam32 = (WPARAM)wParam16;
1051 switch(msg16)
1053 case WM_ACTIVATE:
1054 case WM_CHARTOITEM:
1055 case WM_COMMAND:
1056 case WM_VKEYTOITEM:
1057 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
1058 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1059 return 0;
1060 case WM_HSCROLL:
1061 case WM_VSCROLL:
1062 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1063 *plparam = (LPARAM)(HWND)HIWORD(*plparam);
1064 return 0;
1065 case WM_CTLCOLOR:
1066 if ( HIWORD(*plparam) > CTLCOLOR_STATIC ) return -1;
1067 *pmsg32 = WM_CTLCOLORMSGBOX + HIWORD(*plparam);
1068 *pwparam32 = (WPARAM)(HDC)wParam16;
1069 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1070 return 0;
1071 case WM_COMPAREITEM:
1073 COMPAREITEMSTRUCT16* cis16 = (COMPAREITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1074 COMPAREITEMSTRUCT *cis = (COMPAREITEMSTRUCT *)
1075 HeapAlloc(GetProcessHeap(), 0, sizeof(*cis));
1076 if (!cis) return -1;
1077 cis->CtlType = cis16->CtlType;
1078 cis->CtlID = cis16->CtlID;
1079 cis->hwndItem = cis16->hwndItem;
1080 cis->itemID1 = cis16->itemID1;
1081 cis->itemData1 = cis16->itemData1;
1082 cis->itemID2 = cis16->itemID2;
1083 cis->itemData2 = cis16->itemData2;
1084 cis->dwLocaleId = 0; /* FIXME */
1085 *plparam = (LPARAM)cis;
1087 return 1;
1088 case WM_DELETEITEM:
1090 DELETEITEMSTRUCT16* dis16 = (DELETEITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1091 DELETEITEMSTRUCT *dis = (DELETEITEMSTRUCT *)
1092 HeapAlloc(GetProcessHeap(), 0, sizeof(*dis));
1093 if (!dis) return -1;
1094 dis->CtlType = dis16->CtlType;
1095 dis->CtlID = dis16->CtlID;
1096 dis->hwndItem = dis16->hwndItem;
1097 dis->itemData = dis16->itemData;
1098 *plparam = (LPARAM)dis;
1100 return 1;
1101 case WM_MEASUREITEM:
1103 MEASUREITEMSTRUCT16* mis16 = (MEASUREITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1104 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)
1105 HeapAlloc(GetProcessHeap(), 0,
1106 sizeof(*mis) + sizeof(LPARAM));
1107 if (!mis) return -1;
1108 mis->CtlType = mis16->CtlType;
1109 mis->CtlID = mis16->CtlID;
1110 mis->itemID = mis16->itemID;
1111 mis->itemWidth = mis16->itemWidth;
1112 mis->itemHeight = mis16->itemHeight;
1113 mis->itemData = mis16->itemData;
1114 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
1115 *plparam = (LPARAM)mis;
1117 return 1;
1118 case WM_DRAWITEM:
1120 DRAWITEMSTRUCT16* dis16 = (DRAWITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1121 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT*)HeapAlloc(GetProcessHeap(), 0,
1122 sizeof(*dis));
1123 if (!dis) return -1;
1124 dis->CtlType = dis16->CtlType;
1125 dis->CtlID = dis16->CtlID;
1126 dis->itemID = dis16->itemID;
1127 dis->itemAction = dis16->itemAction;
1128 dis->itemState = dis16->itemState;
1129 dis->hwndItem = dis16->hwndItem;
1130 dis->hDC = dis16->hDC;
1131 dis->itemData = dis16->itemData;
1132 CONV_RECT16TO32( &dis16->rcItem, &dis->rcItem );
1133 *plparam = (LPARAM)dis;
1135 return 1;
1136 case WM_GETMINMAXINFO:
1138 MINMAXINFO *mmi = (MINMAXINFO *)HeapAlloc( GetProcessHeap(), 0,
1139 sizeof(*mmi) + sizeof(LPARAM));
1140 if (!mmi) return -1;
1141 STRUCT32_MINMAXINFO16to32( (MINMAXINFO16*)PTR_SEG_TO_LIN(*plparam),
1142 mmi );
1143 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
1144 *plparam = (LPARAM)mmi;
1146 return 1;
1147 case WM_GETTEXT:
1148 case WM_SETTEXT:
1149 *plparam = (LPARAM)PTR_SEG_TO_LIN(*plparam);
1150 return 0;
1151 case WM_MDICREATE:
1153 MDICREATESTRUCT16 *cs16 =
1154 (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1155 MDICREATESTRUCTA *cs =
1156 (MDICREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
1157 sizeof(*cs) + sizeof(LPARAM) );
1158 if (!cs) return -1;
1159 STRUCT32_MDICREATESTRUCT16to32A( cs16, cs );
1160 cs->szTitle = (LPCSTR)PTR_SEG_TO_LIN(cs16->szTitle);
1161 cs->szClass = (LPCSTR)PTR_SEG_TO_LIN(cs16->szClass);
1162 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1163 *plparam = (LPARAM)cs;
1165 return 1;
1166 case WM_MDIGETACTIVE:
1167 *plparam = (LPARAM)HeapAlloc( GetProcessHeap(), 0, sizeof(BOOL) );
1168 *(BOOL*)(*plparam) = 0;
1169 return 1;
1170 case WM_MDISETMENU:
1171 if(wParam16==TRUE)
1172 *pmsg32=WM_MDIREFRESHMENU;
1173 *pwparam32 = (WPARAM)(HMENU)LOWORD(*plparam);
1174 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1175 return 0;
1176 case WM_MENUCHAR:
1177 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1178 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1179 return 0;
1180 case WM_MENUSELECT:
1181 if((LOWORD(*plparam) & MF_POPUP) && (LOWORD(*plparam) != 0xFFFF))
1183 HMENU hmenu=(HMENU)HIWORD(*plparam);
1184 UINT Pos=MENU_FindSubMenu( &hmenu, wParam16);
1185 if(Pos==0xFFFF) Pos=0; /* NO_SELECTED_ITEM */
1186 *pwparam32 = MAKEWPARAM( Pos, LOWORD(*plparam) );
1188 else *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1189 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1190 return 0;
1191 case WM_MDIACTIVATE:
1192 if( *plparam )
1194 *pwparam32 = (WPARAM)(HWND)HIWORD(*plparam);
1195 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1197 else /* message sent to MDI client */
1198 *pwparam32 = wParam16;
1199 return 0;
1200 case WM_NCCALCSIZE:
1202 NCCALCSIZE_PARAMS16 *nc16;
1203 NCCALCSIZE_PARAMS *nc;
1205 nc = (NCCALCSIZE_PARAMS *)HeapAlloc( GetProcessHeap(), 0,
1206 sizeof(*nc) + sizeof(LPARAM) );
1207 if (!nc) return -1;
1208 nc16 = (NCCALCSIZE_PARAMS16 *)PTR_SEG_TO_LIN(*plparam);
1209 CONV_RECT16TO32( &nc16->rgrc[0], &nc->rgrc[0] );
1210 if (wParam16)
1212 nc->lppos = (WINDOWPOS *)HeapAlloc( GetProcessHeap(), 0,
1213 sizeof(*nc->lppos) );
1214 CONV_RECT16TO32( &nc16->rgrc[1], &nc->rgrc[1] );
1215 CONV_RECT16TO32( &nc16->rgrc[2], &nc->rgrc[2] );
1216 if (nc->lppos) STRUCT32_WINDOWPOS16to32( (WINDOWPOS16 *)PTR_SEG_TO_LIN(nc16->lppos), nc->lppos );
1218 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
1219 *plparam = (LPARAM)nc;
1221 return 1;
1222 case WM_NCCREATE:
1223 case WM_CREATE:
1225 CREATESTRUCT16 *cs16 = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1226 CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
1227 sizeof(*cs) + sizeof(LPARAM) );
1228 if (!cs) return -1;
1229 STRUCT32_CREATESTRUCT16to32A( cs16, cs );
1230 cs->lpszName = (LPCSTR)PTR_SEG_TO_LIN(cs16->lpszName);
1231 cs->lpszClass = (LPCSTR)PTR_SEG_TO_LIN(cs16->lpszClass);
1232 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1233 *plparam = (LPARAM)cs;
1235 return 1;
1236 case WM_PARENTNOTIFY:
1237 if ((wParam16 == WM_CREATE) || (wParam16 == WM_DESTROY))
1239 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
1240 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1242 return 0;
1243 case WM_WINDOWPOSCHANGING:
1244 case WM_WINDOWPOSCHANGED:
1246 WINDOWPOS *wp = (WINDOWPOS *)HeapAlloc( GetProcessHeap(), 0,
1247 sizeof(*wp) + sizeof(LPARAM) );
1248 if (!wp) return -1;
1249 STRUCT32_WINDOWPOS16to32( (WINDOWPOS16 *)PTR_SEG_TO_LIN(*plparam),
1250 wp );
1251 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
1252 *plparam = (LPARAM)wp;
1254 return 1;
1255 case WM_GETDLGCODE:
1256 if (*plparam)
1258 LPMSG16 msg16 = (LPMSG16)PTR_SEG_TO_LIN(*plparam);
1259 LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1261 if (!msg32) return -1;
1262 msg32->hwnd = msg16->hwnd;
1263 msg32->lParam = msg16->lParam;
1264 msg32->time = msg16->time;
1265 CONV_POINT16TO32(&msg16->pt,&msg32->pt);
1266 /* this is right, right? */
1267 if (WINPROC_MapMsg16To32A(msg16->message,msg16->wParam,
1268 &msg32->message,&msg32->wParam,
1269 &msg32->lParam)<0) {
1270 HeapFree( GetProcessHeap(), 0, msg32 );
1271 return -1;
1273 *plparam = (LPARAM)msg32;
1274 return 1;
1276 else return 0;
1277 case WM_NOTIFY:
1278 *plparam = (LPARAM)PTR_SEG_TO_LIN(*plparam);
1279 return 1;
1280 case WM_ACTIVATEAPP:
1281 if (*plparam)
1282 { /* We need this when SetActiveWindow sends a Sendmessage16() to
1283 a 32bit window. Might be superflous with 32bit interprocess
1284 message queues.
1286 HTASK16 htask = (HTASK16) *plparam;
1287 DWORD idThread = (DWORD)((TDB*)GlobalLock16(htask))->teb->tid;
1288 *plparam = (LPARAM) idThread;
1290 return 1;
1291 case WM_ASKCBFORMATNAME:
1292 case WM_DEVMODECHANGE:
1293 case WM_PAINTCLIPBOARD:
1294 case WM_SIZECLIPBOARD:
1295 case WM_WININICHANGE:
1296 FIXME_(msg)("message %04x needs translation\n",msg16 );
1297 return -1;
1299 default: /* No translation needed */
1300 return 0;
1305 /**********************************************************************
1306 * WINPROC_UnmapMsg16To32A
1308 * Unmap a message that was mapped from 16- to 32-bit Ansi.
1310 LRESULT WINPROC_UnmapMsg16To32A( HWND16 hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1311 LRESULT result )
1313 switch(msg)
1315 case WM_COMPAREITEM:
1316 case WM_DELETEITEM:
1317 case WM_DRAWITEM:
1318 HeapFree( GetProcessHeap(), 0, (LPVOID)lParam );
1319 break;
1320 case WM_MEASUREITEM:
1322 MEASUREITEMSTRUCT16 *mis16;
1323 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lParam;
1324 lParam = *(LPARAM *)(mis + 1);
1325 mis16 = (MEASUREITEMSTRUCT16 *)PTR_SEG_TO_LIN(lParam);
1326 mis16->itemWidth = (UINT16)mis->itemWidth;
1327 mis16->itemHeight = (UINT16)mis->itemHeight;
1328 HeapFree( GetProcessHeap(), 0, mis );
1330 break;
1331 case WM_GETMINMAXINFO:
1333 MINMAXINFO *mmi = (MINMAXINFO *)lParam;
1334 lParam = *(LPARAM *)(mmi + 1);
1335 STRUCT32_MINMAXINFO32to16( mmi,
1336 (MINMAXINFO16 *)PTR_SEG_TO_LIN(lParam));
1337 HeapFree( GetProcessHeap(), 0, mmi );
1339 break;
1340 case WM_MDICREATE:
1342 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
1343 lParam = *(LPARAM *)(cs + 1);
1344 STRUCT32_MDICREATESTRUCT32Ato16( cs,
1345 (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
1346 HeapFree( GetProcessHeap(), 0, cs );
1348 break;
1349 case WM_MDIGETACTIVE:
1350 result = MAKELONG( LOWORD(result), (BOOL16)(*(BOOL *)lParam) );
1351 HeapFree( GetProcessHeap(), 0, (BOOL *)lParam );
1352 break;
1353 case WM_NCCALCSIZE:
1355 NCCALCSIZE_PARAMS16 *nc16;
1356 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lParam;
1357 lParam = *(LPARAM *)(nc + 1);
1358 nc16 = (NCCALCSIZE_PARAMS16 *)PTR_SEG_TO_LIN(lParam);
1359 CONV_RECT32TO16( &nc->rgrc[0], &nc16->rgrc[0] );
1360 if (wParam)
1362 CONV_RECT32TO16( &nc->rgrc[1], &nc16->rgrc[1] );
1363 CONV_RECT32TO16( &nc->rgrc[2], &nc16->rgrc[2] );
1364 if (nc->lppos)
1366 STRUCT32_WINDOWPOS32to16( nc->lppos,
1367 (WINDOWPOS16 *)PTR_SEG_TO_LIN(nc16->lppos));
1368 HeapFree( GetProcessHeap(), 0, nc->lppos );
1371 HeapFree( GetProcessHeap(), 0, nc );
1373 break;
1374 case WM_NCCREATE:
1375 case WM_CREATE:
1377 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
1378 lParam = *(LPARAM *)(cs + 1);
1379 STRUCT32_CREATESTRUCT32Ato16( cs,
1380 (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
1381 HeapFree( GetProcessHeap(), 0, cs );
1383 break;
1384 case WM_WINDOWPOSCHANGING:
1385 case WM_WINDOWPOSCHANGED:
1387 WINDOWPOS *wp = (WINDOWPOS *)lParam;
1388 lParam = *(LPARAM *)(wp + 1);
1389 STRUCT32_WINDOWPOS32to16(wp,(WINDOWPOS16 *)PTR_SEG_TO_LIN(lParam));
1390 HeapFree( GetProcessHeap(), 0, wp );
1392 break;
1393 case WM_GETDLGCODE:
1394 if (lParam)
1396 LPMSG msg32 = (LPMSG)lParam;
1398 WINPROC_UnmapMsg16To32A( hwnd, msg32->message, msg32->wParam, msg32->lParam,
1399 result);
1400 HeapFree( GetProcessHeap(), 0, msg32 );
1402 break;
1404 return result;
1408 /**********************************************************************
1409 * WINPROC_MapMsg16To32W
1411 * Map a message from 16- to 32-bit Unicode.
1412 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1414 INT WINPROC_MapMsg16To32W( HWND16 hwnd, UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
1415 WPARAM *pwparam32, LPARAM *plparam )
1417 switch(msg16)
1419 case WM_GETTEXT:
1420 case WM_SETTEXT:
1421 *plparam = (LPARAM)PTR_SEG_TO_LIN(*plparam);
1422 return WINPROC_MapMsg32ATo32W( hwnd, *pmsg32, pwparam32, plparam );
1423 case WM_NCCREATE:
1424 case WM_CREATE:
1426 CREATESTRUCT16 *cs16 = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1427 CREATESTRUCTW *cs = (CREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
1428 sizeof(*cs) + sizeof(LPARAM) );
1429 if (!cs) return -1;
1430 STRUCT32_CREATESTRUCT16to32A( cs16, (CREATESTRUCTA *)cs );
1431 cs->lpszName = (LPCWSTR)PTR_SEG_TO_LIN(cs16->lpszName);
1432 cs->lpszClass = (LPCWSTR)PTR_SEG_TO_LIN(cs16->lpszClass);
1433 if (HIWORD(cs->lpszName))
1434 cs->lpszName = HEAP_strdupAtoW( GetProcessHeap(), 0,
1435 (LPCSTR)cs->lpszName );
1436 if (HIWORD(cs->lpszClass))
1437 cs->lpszClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
1438 (LPCSTR)cs->lpszClass );
1439 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1440 *plparam = (LPARAM)cs;
1442 return 1;
1443 case WM_MDICREATE:
1445 MDICREATESTRUCT16 *cs16 =
1446 (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1447 MDICREATESTRUCTW *cs =
1448 (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
1449 sizeof(*cs) + sizeof(LPARAM) );
1450 if (!cs) return -1;
1451 STRUCT32_MDICREATESTRUCT16to32A( cs16, (MDICREATESTRUCTA *)cs );
1452 cs->szTitle = (LPCWSTR)PTR_SEG_TO_LIN(cs16->szTitle);
1453 cs->szClass = (LPCWSTR)PTR_SEG_TO_LIN(cs16->szClass);
1454 if (HIWORD(cs->szTitle))
1455 cs->szTitle = HEAP_strdupAtoW( GetProcessHeap(), 0,
1456 (LPCSTR)cs->szTitle );
1457 if (HIWORD(cs->szClass))
1458 cs->szClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
1459 (LPCSTR)cs->szClass );
1460 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1461 *plparam = (LPARAM)cs;
1463 return 1;
1464 case WM_GETDLGCODE:
1465 if (*plparam)
1467 LPMSG16 msg16 = (LPMSG16)PTR_SEG_TO_LIN(*plparam);
1468 LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1470 if (!msg32) return -1;
1471 msg32->hwnd = msg16->hwnd;
1472 msg32->lParam = msg16->lParam;
1473 msg32->time = msg16->time;
1474 CONV_POINT16TO32(&msg16->pt,&msg32->pt);
1475 /* this is right, right? */
1476 if (WINPROC_MapMsg16To32W(hwnd, msg16->message,msg16->wParam,
1477 &msg32->message,&msg32->wParam,
1478 &msg32->lParam)<0) {
1479 HeapFree( GetProcessHeap(), 0, msg32 );
1480 return -1;
1482 *plparam = (LPARAM)msg32;
1483 return 1;
1485 else return 0;
1487 case WM_CHAR:
1488 case WM_DEADCHAR:
1489 case WM_SYSCHAR:
1490 case WM_SYSDEADCHAR:
1492 char ch = wParam16;
1493 WCHAR wch;
1494 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1495 *pwparam32 = wch;
1497 return 0;
1499 default: /* No Unicode translation needed */
1500 return WINPROC_MapMsg16To32A( msg16, wParam16, pmsg32,
1501 pwparam32, plparam );
1506 /**********************************************************************
1507 * WINPROC_UnmapMsg16To32W
1509 * Unmap a message that was mapped from 16- to 32-bit Unicode.
1511 LRESULT WINPROC_UnmapMsg16To32W( HWND16 hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1512 LRESULT result )
1514 switch(msg)
1516 case WM_GETTEXT:
1517 case WM_SETTEXT:
1518 WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam );
1519 break;
1520 case WM_NCCREATE:
1521 case WM_CREATE:
1523 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
1524 lParam = *(LPARAM *)(cs + 1);
1525 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs,
1526 (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
1527 if (HIWORD(cs->lpszName))
1528 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszName );
1529 if (HIWORD(cs->lpszClass))
1530 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszClass );
1531 HeapFree( GetProcessHeap(), 0, cs );
1533 break;
1534 case WM_MDICREATE:
1536 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
1537 lParam = *(LPARAM *)(cs + 1);
1538 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs,
1539 (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
1540 if (HIWORD(cs->szTitle))
1541 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
1542 if (HIWORD(cs->szClass))
1543 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
1544 HeapFree( GetProcessHeap(), 0, cs );
1546 break;
1547 case WM_GETDLGCODE:
1548 if (lParam)
1550 LPMSG msg32 = (LPMSG)lParam;
1552 WINPROC_UnmapMsg16To32W( hwnd, msg32->message, msg32->wParam, msg32->lParam,
1553 result);
1554 HeapFree( GetProcessHeap(), 0, msg32 );
1556 break;
1557 default:
1558 return WINPROC_UnmapMsg16To32A( hwnd, msg, wParam, lParam, result );
1560 return result;
1564 /**********************************************************************
1565 * WINPROC_MapMsg32ATo16
1567 * Map a message from 32-bit Ansi to 16-bit.
1568 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1570 INT WINPROC_MapMsg32ATo16( HWND hwnd, UINT msg32, WPARAM wParam32,
1571 UINT16 *pmsg16, WPARAM16 *pwparam16,
1572 LPARAM *plparam )
1574 *pmsg16 = (UINT16)msg32;
1575 *pwparam16 = (WPARAM16)LOWORD(wParam32);
1576 switch(msg32)
1578 case BM_GETCHECK:
1579 case BM_SETCHECK:
1580 case BM_GETSTATE:
1581 case BM_SETSTATE:
1582 case BM_SETSTYLE:
1583 *pmsg16 = (UINT16)msg32 + (BM_GETCHECK16 - BM_GETCHECK);
1584 return 0;
1586 case EM_GETSEL:
1587 case EM_GETRECT:
1588 case EM_SETRECT:
1589 case EM_SETRECTNP:
1590 case EM_SCROLL:
1591 case EM_LINESCROLL:
1592 case EM_SCROLLCARET:
1593 case EM_GETMODIFY:
1594 case EM_SETMODIFY:
1595 case EM_GETLINECOUNT:
1596 case EM_LINEINDEX:
1597 case EM_SETHANDLE:
1598 case EM_GETHANDLE:
1599 case EM_GETTHUMB:
1600 case EM_LINELENGTH:
1601 case EM_REPLACESEL:
1602 case EM_GETLINE:
1603 case EM_LIMITTEXT:
1604 case EM_CANUNDO:
1605 case EM_UNDO:
1606 case EM_FMTLINES:
1607 case EM_LINEFROMCHAR:
1608 case EM_SETTABSTOPS:
1609 case EM_SETPASSWORDCHAR:
1610 case EM_EMPTYUNDOBUFFER:
1611 case EM_GETFIRSTVISIBLELINE:
1612 case EM_SETREADONLY:
1613 case EM_SETWORDBREAKPROC:
1614 case EM_GETWORDBREAKPROC:
1615 case EM_GETPASSWORDCHAR:
1616 *pmsg16 = (UINT16)msg32 + (EM_GETSEL16 - EM_GETSEL);
1617 return 0;
1619 case LB_CARETOFF:
1620 case LB_CARETON:
1621 case LB_DELETESTRING:
1622 case LB_GETANCHORINDEX:
1623 case LB_GETCARETINDEX:
1624 case LB_GETCOUNT:
1625 case LB_GETCURSEL:
1626 case LB_GETHORIZONTALEXTENT:
1627 case LB_GETITEMDATA:
1628 case LB_GETITEMHEIGHT:
1629 case LB_GETSEL:
1630 case LB_GETSELCOUNT:
1631 case LB_GETTEXTLEN:
1632 case LB_GETTOPINDEX:
1633 case LB_RESETCONTENT:
1634 case LB_SELITEMRANGE:
1635 case LB_SELITEMRANGEEX:
1636 case LB_SETANCHORINDEX:
1637 case LB_SETCARETINDEX:
1638 case LB_SETCOLUMNWIDTH:
1639 case LB_SETCURSEL:
1640 case LB_SETHORIZONTALEXTENT:
1641 case LB_SETITEMDATA:
1642 case LB_SETITEMHEIGHT:
1643 case LB_SETSEL:
1644 case LB_SETTOPINDEX:
1645 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
1646 return 0;
1647 case CB_DELETESTRING:
1648 case CB_GETCOUNT:
1649 case CB_GETLBTEXTLEN:
1650 case CB_LIMITTEXT:
1651 case CB_RESETCONTENT:
1652 case CB_SETEDITSEL:
1653 case CB_GETCURSEL:
1654 case CB_SETCURSEL:
1655 case CB_SHOWDROPDOWN:
1656 case CB_SETITEMDATA:
1657 case CB_SETITEMHEIGHT:
1658 case CB_GETITEMHEIGHT:
1659 case CB_SETEXTENDEDUI:
1660 case CB_GETEXTENDEDUI:
1661 case CB_GETDROPPEDSTATE:
1662 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
1663 return 0;
1664 case CB_GETEDITSEL:
1665 *pmsg16 = CB_GETEDITSEL16;
1666 return 1;
1668 case LB_ADDSTRING:
1669 case LB_FINDSTRING:
1670 case LB_FINDSTRINGEXACT:
1671 case LB_INSERTSTRING:
1672 case LB_SELECTSTRING:
1673 case LB_DIR:
1674 case LB_ADDFILE:
1676 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
1677 if (!str) return -1;
1678 *plparam = (LPARAM)SEGPTR_GET(str);
1680 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
1681 return 1;
1683 case CB_ADDSTRING:
1684 case CB_FINDSTRING:
1685 case CB_FINDSTRINGEXACT:
1686 case CB_INSERTSTRING:
1687 case CB_SELECTSTRING:
1688 case CB_DIR:
1690 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
1691 if (!str) return -1;
1692 *plparam = (LPARAM)SEGPTR_GET(str);
1694 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
1695 return 1;
1697 case LB_GETITEMRECT:
1699 RECT16 *rect;
1700 rect = (RECT16 *)SEGPTR_ALLOC( sizeof(RECT16) + sizeof(LPARAM) );
1701 if (!rect) return -1;
1702 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
1703 *plparam = (LPARAM)SEGPTR_GET(rect);
1705 *pmsg16 = LB_GETITEMRECT16;
1706 return 1;
1707 case LB_GETSELITEMS:
1709 LPINT16 items;
1710 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
1711 if (!(items = SEGPTR_ALLOC( *pwparam16 * sizeof(INT16)
1712 + sizeof(LPARAM)))) return -1;
1713 *((LPARAM *)items)++ = *plparam; /* Store the previous lParam */
1714 *plparam = (LPARAM)SEGPTR_GET(items);
1716 *pmsg16 = LB_GETSELITEMS16;
1717 return 1;
1718 case LB_SETTABSTOPS:
1719 if (wParam32)
1721 INT i;
1722 LPINT16 stops;
1723 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
1724 if (!(stops = SEGPTR_ALLOC( *pwparam16 * sizeof(INT16)
1725 + sizeof(LPARAM)))) return -1;
1726 for (i = 0; i < *pwparam16; i++) stops[i] = *((LPINT)*plparam+i);
1727 *plparam = (LPARAM)SEGPTR_GET(stops);
1728 return 1;
1730 *pmsg16 = LB_SETTABSTOPS16;
1731 return 0;
1733 case CB_GETDROPPEDCONTROLRECT:
1735 RECT16 *rect;
1736 rect = (RECT16 *)SEGPTR_ALLOC( sizeof(RECT16) + sizeof(LPARAM) );
1737 if (!rect) return -1;
1738 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
1739 *plparam = (LPARAM)SEGPTR_GET(rect);
1741 *pmsg16 = CB_GETDROPPEDCONTROLRECT16;
1742 return 1;
1744 case LB_GETTEXT:
1745 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
1746 *pmsg16 = LB_GETTEXT16;
1747 return 1;
1749 case CB_GETLBTEXT:
1750 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
1751 *pmsg16 = CB_GETLBTEXT16;
1752 return 1;
1754 case EM_SETSEL:
1755 *pwparam16 = 0;
1756 *plparam = MAKELONG( (INT16)(INT)wParam32, (INT16)*plparam );
1757 *pmsg16 = EM_SETSEL16;
1758 return 0;
1760 case WM_ACTIVATE:
1761 case WM_CHARTOITEM:
1762 case WM_COMMAND:
1763 case WM_VKEYTOITEM:
1764 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
1765 return 0;
1766 case WM_HSCROLL:
1767 case WM_VSCROLL:
1768 *plparam = MAKELPARAM( HIWORD(wParam32), (HWND16)*plparam );
1769 return 0;
1770 case WM_CTLCOLORMSGBOX:
1771 case WM_CTLCOLOREDIT:
1772 case WM_CTLCOLORLISTBOX:
1773 case WM_CTLCOLORBTN:
1774 case WM_CTLCOLORDLG:
1775 case WM_CTLCOLORSCROLLBAR:
1776 case WM_CTLCOLORSTATIC:
1777 *pmsg16 = WM_CTLCOLOR;
1778 *plparam = MAKELPARAM( (HWND16)*plparam,
1779 (WORD)msg32 - WM_CTLCOLORMSGBOX );
1780 return 0;
1781 case WM_COMPAREITEM:
1783 COMPAREITEMSTRUCT *cis32 = (COMPAREITEMSTRUCT *)*plparam;
1784 COMPAREITEMSTRUCT16 *cis = SEGPTR_NEW(COMPAREITEMSTRUCT16);
1785 if (!cis) return -1;
1786 cis->CtlType = (UINT16)cis32->CtlType;
1787 cis->CtlID = (UINT16)cis32->CtlID;
1788 cis->hwndItem = (HWND16)cis32->hwndItem;
1789 cis->itemID1 = (UINT16)cis32->itemID1;
1790 cis->itemData1 = cis32->itemData1;
1791 cis->itemID2 = (UINT16)cis32->itemID2;
1792 cis->itemData2 = cis32->itemData2;
1793 *plparam = (LPARAM)SEGPTR_GET(cis);
1795 return 1;
1796 case WM_DELETEITEM:
1798 DELETEITEMSTRUCT *dis32 = (DELETEITEMSTRUCT *)*plparam;
1799 DELETEITEMSTRUCT16 *dis = SEGPTR_NEW(DELETEITEMSTRUCT16);
1800 if (!dis) return -1;
1801 dis->CtlType = (UINT16)dis32->CtlType;
1802 dis->CtlID = (UINT16)dis32->CtlID;
1803 dis->itemID = (UINT16)dis32->itemID;
1804 dis->hwndItem = (HWND16)dis32->hwndItem;
1805 dis->itemData = dis32->itemData;
1806 *plparam = (LPARAM)SEGPTR_GET(dis);
1808 return 1;
1809 case WM_DRAWITEM:
1811 DRAWITEMSTRUCT *dis32 = (DRAWITEMSTRUCT *)*plparam;
1812 DRAWITEMSTRUCT16 *dis = SEGPTR_NEW(DRAWITEMSTRUCT16);
1813 if (!dis) return -1;
1814 dis->CtlType = (UINT16)dis32->CtlType;
1815 dis->CtlID = (UINT16)dis32->CtlID;
1816 dis->itemID = (UINT16)dis32->itemID;
1817 dis->itemAction = (UINT16)dis32->itemAction;
1818 dis->itemState = (UINT16)dis32->itemState;
1819 dis->hwndItem = (HWND16)dis32->hwndItem;
1820 dis->hDC = (HDC16)dis32->hDC;
1821 dis->itemData = dis32->itemData;
1822 CONV_RECT32TO16( &dis32->rcItem, &dis->rcItem );
1823 *plparam = (LPARAM)SEGPTR_GET(dis);
1825 return 1;
1826 case WM_MEASUREITEM:
1828 MEASUREITEMSTRUCT *mis32 = (MEASUREITEMSTRUCT *)*plparam;
1829 MEASUREITEMSTRUCT16 *mis = (MEASUREITEMSTRUCT16 *)
1830 SEGPTR_ALLOC(sizeof(*mis)+sizeof(LPARAM));
1831 if (!mis) return -1;
1832 mis->CtlType = (UINT16)mis32->CtlType;
1833 mis->CtlID = (UINT16)mis32->CtlID;
1834 mis->itemID = (UINT16)mis32->itemID;
1835 mis->itemWidth = (UINT16)mis32->itemWidth;
1836 mis->itemHeight = (UINT16)mis32->itemHeight;
1837 mis->itemData = mis32->itemData;
1838 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
1839 *plparam = (LPARAM)SEGPTR_GET(mis);
1841 return 1;
1842 case WM_GETMINMAXINFO:
1844 MINMAXINFO16 *mmi = (MINMAXINFO16 *)SEGPTR_ALLOC( sizeof(*mmi) +
1845 sizeof(LPARAM) );
1846 if (!mmi) return -1;
1847 STRUCT32_MINMAXINFO32to16( (MINMAXINFO *)*plparam, mmi );
1848 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
1849 *plparam = (LPARAM)SEGPTR_GET(mmi);
1851 return 1;
1852 case WM_GETTEXT:
1854 LPSTR str;
1855 *pwparam16 = (WPARAM16)min( wParam32, 0xff80 ); /* Must be < 64K */
1856 if (!(str = SEGPTR_ALLOC(*pwparam16 + sizeof(LPARAM)))) return -1;
1857 *((LPARAM *)str)++ = *plparam; /* Store the previous lParam */
1858 *plparam = (LPARAM)SEGPTR_GET(str);
1860 return 1;
1861 case WM_MDICREATE:
1863 MDICREATESTRUCT16 *cs;
1864 MDICREATESTRUCTA *cs32 = (MDICREATESTRUCTA *)*plparam;
1865 LPSTR name, cls;
1867 if (!(cs = SEGPTR_NEW(MDICREATESTRUCT16))) return -1;
1868 STRUCT32_MDICREATESTRUCT32Ato16( cs32, cs );
1869 name = SEGPTR_STRDUP( cs32->szTitle );
1870 cls = SEGPTR_STRDUP( cs32->szClass );
1871 cs->szTitle = SEGPTR_GET(name);
1872 cs->szClass = SEGPTR_GET(cls);
1873 *plparam = (LPARAM)SEGPTR_GET(cs);
1875 return 1;
1876 case WM_MDIGETACTIVE:
1877 return 1;
1878 case WM_MDISETMENU:
1879 *plparam = MAKELPARAM( (HMENU16)LOWORD(wParam32),
1880 (HMENU16)LOWORD(*plparam) );
1881 *pwparam16 = (*plparam == 0);
1882 return 0;
1883 case WM_MENUSELECT:
1884 if(HIWORD(wParam32) & MF_POPUP)
1886 UINT16 hmenu;
1887 if (((UINT)HIWORD(wParam32) != 0xFFFF) || (*plparam))
1889 if((hmenu = GetSubMenu((HMENU16)*plparam, *pwparam16)))
1890 *pwparam16=hmenu;
1893 /* fall through */
1894 case WM_MENUCHAR:
1895 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
1896 return 0;
1897 case WM_MDIACTIVATE:
1899 WND *tempWnd = WIN_FindWndPtr(hwnd);
1900 if( WIDGETS_IsControl(tempWnd, BIC32_MDICLIENT) )
1902 *pwparam16 = (HWND)wParam32;
1903 *plparam = 0;
1905 else
1907 *pwparam16 = ((HWND)*plparam == hwnd);
1908 *plparam = MAKELPARAM( (HWND16)LOWORD(*plparam),
1909 (HWND16)LOWORD(wParam32) );
1911 WIN_ReleaseWndPtr(tempWnd);
1913 return 0;
1914 case WM_NCCALCSIZE:
1916 NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)*plparam;
1917 NCCALCSIZE_PARAMS16 *nc = (NCCALCSIZE_PARAMS16 *)SEGPTR_ALLOC( sizeof(*nc) + sizeof(LPARAM) );
1918 if (!nc) return -1;
1920 CONV_RECT32TO16( &nc32->rgrc[0], &nc->rgrc[0] );
1921 if (wParam32)
1923 WINDOWPOS16 *wp;
1924 CONV_RECT32TO16( &nc32->rgrc[1], &nc->rgrc[1] );
1925 CONV_RECT32TO16( &nc32->rgrc[2], &nc->rgrc[2] );
1926 if (!(wp = SEGPTR_NEW(WINDOWPOS16)))
1928 SEGPTR_FREE(nc);
1929 return -1;
1931 STRUCT32_WINDOWPOS32to16( nc32->lppos, wp );
1932 nc->lppos = SEGPTR_GET(wp);
1934 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
1935 *plparam = (LPARAM)SEGPTR_GET(nc);
1937 return 1;
1938 case WM_NCCREATE:
1939 case WM_CREATE:
1941 CREATESTRUCT16 *cs;
1942 CREATESTRUCTA *cs32 = (CREATESTRUCTA *)*plparam;
1943 LPSTR name, cls;
1945 if (!(cs = SEGPTR_NEW(CREATESTRUCT16))) return -1;
1946 STRUCT32_CREATESTRUCT32Ato16( cs32, cs );
1947 name = SEGPTR_STRDUP( cs32->lpszName );
1948 cls = SEGPTR_STRDUP( cs32->lpszClass );
1949 cs->lpszName = SEGPTR_GET(name);
1950 cs->lpszClass = SEGPTR_GET(cls);
1951 *plparam = (LPARAM)SEGPTR_GET(cs);
1953 return 1;
1954 case WM_PARENTNOTIFY:
1955 if ((LOWORD(wParam32)==WM_CREATE) || (LOWORD(wParam32)==WM_DESTROY))
1956 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32));
1957 /* else nothing to do */
1958 return 0;
1959 case WM_NOTIFY:
1960 *plparam = MapLS( (NMHDR *)*plparam ); /* NMHDR is already 32-bit */
1961 return 1;
1962 case WM_SETTEXT:
1964 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
1965 if (!str) return -1;
1966 *plparam = (LPARAM)SEGPTR_GET(str);
1968 return 1;
1969 case WM_WINDOWPOSCHANGING:
1970 case WM_WINDOWPOSCHANGED:
1972 WINDOWPOS16 *wp = (WINDOWPOS16 *)SEGPTR_ALLOC( sizeof(*wp) +
1973 sizeof(LPARAM) );
1974 if (!wp) return -1;
1975 STRUCT32_WINDOWPOS32to16( (WINDOWPOS *)*plparam, wp );
1976 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
1977 *plparam = (LPARAM)SEGPTR_GET(wp);
1979 return 1;
1980 case WM_GETDLGCODE:
1981 if (*plparam) {
1982 LPMSG msg32 = (LPMSG) *plparam;
1983 LPMSG16 msg16 = (LPMSG16) SEGPTR_NEW( MSG16 );
1985 if (!msg16) return -1;
1986 msg16->hwnd = msg32->hwnd;
1987 msg16->lParam = msg32->lParam;
1988 msg16->time = msg32->time;
1989 CONV_POINT32TO16(&msg32->pt,&msg16->pt);
1990 /* this is right, right? */
1991 if (WINPROC_MapMsg32ATo16(msg32->hwnd,msg32->message,msg32->wParam,
1992 &msg16->message,&msg16->wParam, &msg16->lParam)<0) {
1993 SEGPTR_FREE( msg16 );
1994 return -1;
1996 *plparam = (LPARAM)SEGPTR_GET(msg16);
1997 return 1;
1999 return 0;
2001 case WM_ACTIVATEAPP:
2002 if (*plparam) {
2003 *plparam = (LPARAM)THREAD_IdToTEB((DWORD) *plparam)->htask16;
2005 return 1;
2006 case WM_ASKCBFORMATNAME:
2007 case WM_DEVMODECHANGE:
2008 case WM_PAINTCLIPBOARD:
2009 case WM_SIZECLIPBOARD:
2010 case WM_WININICHANGE:
2011 FIXME_(msg)("message %04x needs translation\n", msg32 );
2012 return -1;
2013 case WM_SIZING: /* should not be send to 16-bit apps */
2014 return -1;
2015 default: /* No translation needed */
2016 return 0;
2021 /**********************************************************************
2022 * WINPROC_UnmapMsg32ATo16
2024 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
2026 void WINPROC_UnmapMsg32ATo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2027 MSGPARAM16* p16 )
2029 switch(msg)
2031 case LB_ADDFILE:
2032 case LB_ADDSTRING:
2033 case LB_DIR:
2034 case LB_FINDSTRING:
2035 case LB_FINDSTRINGEXACT:
2036 case LB_INSERTSTRING:
2037 case LB_SELECTSTRING:
2038 case LB_SETTABSTOPS:
2039 case CB_ADDSTRING:
2040 case CB_FINDSTRING:
2041 case CB_FINDSTRINGEXACT:
2042 case CB_INSERTSTRING:
2043 case CB_SELECTSTRING:
2044 case CB_DIR:
2045 case WM_COMPAREITEM:
2046 case WM_DELETEITEM:
2047 case WM_DRAWITEM:
2048 case WM_SETTEXT:
2049 SEGPTR_FREE( PTR_SEG_TO_LIN(p16->lParam) );
2050 break;
2052 case CB_GETDROPPEDCONTROLRECT:
2053 case LB_GETITEMRECT:
2055 RECT16 *rect = (RECT16 *)PTR_SEG_TO_LIN(p16->lParam);
2056 p16->lParam = *(LPARAM *)(rect + 1);
2057 CONV_RECT16TO32( rect, (RECT *)(p16->lParam));
2058 SEGPTR_FREE( rect );
2060 break;
2061 case LB_GETSELITEMS:
2063 INT i;
2064 LPINT16 items = (LPINT16)PTR_SEG_TO_LIN(lParam);
2065 p16->lParam = *((LPARAM *)items - 1);
2066 for (i = 0; i < p16->wParam; i++) *((LPINT)(p16->lParam) + i) = items[i];
2067 SEGPTR_FREE( (LPARAM *)items - 1 );
2069 break;
2071 case CB_GETEDITSEL:
2072 if( wParam )
2073 *((LPUINT)(wParam)) = LOWORD(p16->lResult);
2074 if( lParam )
2075 *((LPUINT)(lParam)) = HIWORD(p16->lResult); /* FIXME: substract 1? */
2076 break;
2078 case LB_GETTEXT:
2079 case CB_GETLBTEXT:
2080 UnMapLS( (SEGPTR)(p16->lParam) );
2081 break;
2083 case WM_MEASUREITEM:
2085 MEASUREITEMSTRUCT16 *mis = (MEASUREITEMSTRUCT16 *)PTR_SEG_TO_LIN(p16->lParam);
2086 MEASUREITEMSTRUCT *mis32 = *(MEASUREITEMSTRUCT **)(mis + 1);
2087 mis32->itemWidth = mis->itemWidth;
2088 mis32->itemHeight = mis->itemHeight;
2089 SEGPTR_FREE(mis);
2091 break;
2092 case WM_GETMINMAXINFO:
2094 MINMAXINFO16 *mmi = (MINMAXINFO16 *)PTR_SEG_TO_LIN(p16->lParam);
2095 p16->lParam = *(LPARAM *)(mmi + 1);
2096 STRUCT32_MINMAXINFO16to32( mmi, (MINMAXINFO *)(p16->lParam) );
2097 SEGPTR_FREE(mmi);
2099 break;
2100 case WM_GETTEXT:
2102 LPSTR str = (LPSTR)PTR_SEG_TO_LIN(p16->lParam);
2103 p16->lParam = *((LPARAM *)str - 1);
2104 lstrcpynA( (LPSTR)(p16->lParam), str, p16->wParam );
2105 SEGPTR_FREE( (LPARAM *)str - 1 );
2107 break;
2108 case WM_MDICREATE:
2110 MDICREATESTRUCT16 *cs = (MDICREATESTRUCT16*)PTR_SEG_TO_LIN(p16->lParam);
2111 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->szTitle) );
2112 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->szClass) );
2113 SEGPTR_FREE( cs );
2115 break;
2116 case WM_MDIGETACTIVE:
2117 if (lParam) *(BOOL *)lParam = (BOOL16)HIWORD(p16->lResult);
2118 p16->lResult = (HWND)LOWORD(p16->lResult);
2119 break;
2120 case WM_NCCALCSIZE:
2122 NCCALCSIZE_PARAMS *nc32;
2123 NCCALCSIZE_PARAMS16 *nc = (NCCALCSIZE_PARAMS16 *)PTR_SEG_TO_LIN(p16->lParam);
2124 p16->lParam = *(LPARAM *)(nc + 1);
2125 nc32 = (NCCALCSIZE_PARAMS *)(p16->lParam);
2126 CONV_RECT16TO32( &nc->rgrc[0], &nc32->rgrc[0] );
2127 if (p16->wParam)
2129 CONV_RECT16TO32( &nc->rgrc[1], &nc32->rgrc[1] );
2130 CONV_RECT16TO32( &nc->rgrc[2], &nc32->rgrc[2] );
2131 STRUCT32_WINDOWPOS16to32( (WINDOWPOS16 *)PTR_SEG_TO_LIN(nc->lppos),
2132 nc32->lppos );
2133 SEGPTR_FREE( PTR_SEG_TO_LIN(nc->lppos) );
2135 SEGPTR_FREE(nc);
2137 break;
2138 case WM_NCCREATE:
2139 case WM_CREATE:
2141 CREATESTRUCT16 *cs = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(p16->lParam);
2142 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->lpszName) );
2143 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->lpszClass) );
2144 SEGPTR_FREE( cs );
2146 break;
2147 case WM_WINDOWPOSCHANGING:
2148 case WM_WINDOWPOSCHANGED:
2150 WINDOWPOS16 *wp = (WINDOWPOS16 *)PTR_SEG_TO_LIN(p16->lParam);
2151 p16->lParam = *(LPARAM *)(wp + 1);
2152 STRUCT32_WINDOWPOS16to32( wp, (WINDOWPOS *)p16->lParam );
2153 SEGPTR_FREE(wp);
2155 break;
2156 case WM_NOTIFY:
2157 UnMapLS(p16->lParam);
2158 break;
2159 case WM_GETDLGCODE:
2160 if (p16->lParam)
2162 LPMSG16 msg16 = (LPMSG16)PTR_SEG_TO_LIN(p16->lParam);
2163 MSGPARAM16 msgp16;
2164 msgp16.wParam=msg16->wParam;
2165 msgp16.lParam=msg16->lParam;
2166 WINPROC_UnmapMsg32ATo16(((LPMSG)lParam)->hwnd, ((LPMSG)lParam)->message,
2167 ((LPMSG)lParam)->wParam, ((LPMSG)lParam)->lParam,
2168 &msgp16 );
2169 SEGPTR_FREE(msg16);
2171 break;
2176 /**********************************************************************
2177 * WINPROC_MapMsg32WTo16
2179 * Map a message from 32-bit Unicode to 16-bit.
2180 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
2182 INT WINPROC_MapMsg32WTo16( HWND hwnd, UINT msg32, WPARAM wParam32,
2183 UINT16 *pmsg16, WPARAM16 *pwparam16,
2184 LPARAM *plparam )
2186 *pmsg16 = LOWORD(msg32);
2187 *pwparam16 = LOWORD(wParam32);
2188 switch(msg32)
2190 case LB_ADDSTRING:
2191 case LB_FINDSTRING:
2192 case LB_FINDSTRINGEXACT:
2193 case LB_INSERTSTRING:
2194 case LB_SELECTSTRING:
2195 case LB_DIR:
2196 case LB_ADDFILE:
2198 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
2199 if (!str) return -1;
2200 *plparam = (LPARAM)SEGPTR_GET(str);
2202 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
2203 return 1;
2205 case CB_ADDSTRING:
2206 case CB_FINDSTRING:
2207 case CB_FINDSTRINGEXACT:
2208 case CB_INSERTSTRING:
2209 case CB_SELECTSTRING:
2210 case CB_DIR:
2212 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
2213 if (!str) return -1;
2214 *plparam = (LPARAM)SEGPTR_GET(str);
2216 *pmsg16 = (UINT16)msg32 + (CB_ADDSTRING16 - CB_ADDSTRING);
2217 return 1;
2219 case WM_NCCREATE:
2220 case WM_CREATE:
2222 CREATESTRUCT16 *cs;
2223 CREATESTRUCTW *cs32 = (CREATESTRUCTW *)*plparam;
2224 LPSTR name, cls;
2226 if (!(cs = SEGPTR_NEW(CREATESTRUCT16))) return -1;
2227 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs32, cs );
2228 name = SEGPTR_STRDUP_WtoA( cs32->lpszName );
2229 cls = SEGPTR_STRDUP_WtoA( cs32->lpszClass );
2230 cs->lpszName = SEGPTR_GET(name);
2231 cs->lpszClass = SEGPTR_GET(cls);
2232 *plparam = (LPARAM)SEGPTR_GET(cs);
2234 return 1;
2235 case WM_MDICREATE:
2237 MDICREATESTRUCT16 *cs;
2238 MDICREATESTRUCTW *cs32 = (MDICREATESTRUCTW *)*plparam;
2239 LPSTR name, cls;
2241 if (!(cs = SEGPTR_NEW(MDICREATESTRUCT16))) return -1;
2242 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs32, cs );
2243 name = SEGPTR_STRDUP_WtoA( cs32->szTitle );
2244 cls = SEGPTR_STRDUP_WtoA( cs32->szClass );
2245 cs->szTitle = SEGPTR_GET(name);
2246 cs->szClass = SEGPTR_GET(cls);
2247 *plparam = (LPARAM)SEGPTR_GET(cs);
2249 return 1;
2250 case WM_SETTEXT:
2252 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
2253 if (!str) return -1;
2254 *plparam = (LPARAM)SEGPTR_GET(str);
2256 return 1;
2257 case LB_GETTEXT:
2258 case CB_GETLBTEXT:
2259 if ( WINPROC_TestLBForStr( hwnd ))
2261 LPSTR str = (LPSTR) SEGPTR_ALLOC( 256 ); /* fixme: fixed sized buffer */
2262 if (!str) return -1;
2263 *pmsg16 = (msg32 == LB_GETTEXT)? LB_GETTEXT16 : CB_GETLBTEXT16;
2264 *plparam = (LPARAM)SEGPTR_GET(str);
2266 return 1;
2268 case WM_CHAR:
2269 case WM_DEADCHAR:
2270 case WM_SYSCHAR:
2271 case WM_SYSDEADCHAR:
2273 WCHAR wch = wParam32;
2274 char ch;
2275 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
2276 *pwparam16 = ch;
2278 return 0;
2280 default: /* No Unicode translation needed (?) */
2281 return WINPROC_MapMsg32ATo16( hwnd, msg32, wParam32, pmsg16,
2282 pwparam16, plparam );
2287 /**********************************************************************
2288 * WINPROC_UnmapMsg32WTo16
2290 * Unmap a message that was mapped from 32-bit Unicode to 16-bit.
2292 void WINPROC_UnmapMsg32WTo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2293 MSGPARAM16* p16 )
2295 switch(msg)
2297 case WM_GETTEXT:
2299 LPSTR str = (LPSTR)PTR_SEG_TO_LIN(p16->lParam);
2300 p16->lParam = *((LPARAM *)str - 1);
2301 MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)p16->lParam, 0x7fffffff );
2302 SEGPTR_FREE( (LPARAM *)str - 1 );
2304 break;
2305 case LB_GETTEXT:
2306 case CB_GETLBTEXT:
2307 if ( WINPROC_TestLBForStr( hwnd ))
2309 LPSTR str = (LPSTR)PTR_SEG_TO_LIN(p16->lParam);
2310 MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)lParam, 0x7fffffff );
2311 SEGPTR_FREE( (LPARAM *) str );
2313 break;
2314 default:
2315 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, p16 );
2316 break;
2321 /**********************************************************************
2322 * WINPROC_CallProc32ATo32W
2324 * Call a window procedure, translating args from Ansi to Unicode.
2326 static LRESULT WINPROC_CallProc32ATo32W( WNDPROC func, HWND hwnd,
2327 UINT msg, WPARAM wParam,
2328 LPARAM lParam )
2330 LRESULT result;
2332 if (WINPROC_MapMsg32ATo32W( hwnd, msg, &wParam, &lParam ) == -1) return 0;
2333 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2334 WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam );
2335 return result;
2339 /**********************************************************************
2340 * WINPROC_CallProc32WTo32A
2342 * Call a window procedure, translating args from Unicode to Ansi.
2344 static LRESULT WINPROC_CallProc32WTo32A( WNDPROC func, HWND hwnd,
2345 UINT msg, WPARAM wParam,
2346 LPARAM lParam )
2348 LRESULT result;
2350 if (WINPROC_MapMsg32WTo32A( hwnd, msg, &wParam, &lParam ) == -1) return 0;
2351 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2352 WINPROC_UnmapMsg32WTo32A( hwnd, msg, wParam, lParam );
2353 return result;
2357 /**********************************************************************
2358 * WINPROC_CallProc16To32A
2360 * Call a 32-bit window procedure, translating the 16-bit args.
2362 static LRESULT WINPROC_CallProc16To32A( WNDPROC func, HWND16 hwnd,
2363 UINT16 msg, WPARAM16 wParam,
2364 LPARAM lParam )
2366 LRESULT result;
2367 UINT msg32;
2368 WPARAM wParam32;
2370 if (WINPROC_MapMsg16To32A( msg, wParam, &msg32, &wParam32, &lParam ) == -1)
2371 return 0;
2372 result = WINPROC_CallWndProc( func, hwnd, msg32, wParam32, lParam );
2373 return WINPROC_UnmapMsg16To32A( hwnd, msg32, wParam32, lParam, result );
2376 /**********************************************************************
2377 * WINPROC_Thunk16To32A
2379 static LRESULT WINAPI WINPROC_Thunk16To32A( WNDPROC func, LPBYTE args )
2381 HWND16 hwnd = *(HWND16 *)( args+8 );
2382 UINT16 msg = *(HWND16 *)( args+6 );
2383 WPARAM16 wParam = *(HWND16 *)( args+4 );
2384 LPARAM lParam = *(LPARAM *)( args+0 );
2386 return WINPROC_CallProc16To32A( func, hwnd, msg, wParam, lParam );
2390 /**********************************************************************
2391 * WINPROC_CallProc16To32W
2393 * Call a 32-bit window procedure, translating the 16-bit args.
2395 static LRESULT WINPROC_CallProc16To32W( WNDPROC func, HWND16 hwnd,
2396 UINT16 msg, WPARAM16 wParam,
2397 LPARAM lParam )
2399 LRESULT result;
2400 UINT msg32;
2401 WPARAM wParam32;
2403 if (WINPROC_MapMsg16To32W( hwnd, msg, wParam, &msg32, &wParam32, &lParam ) == -1)
2404 return 0;
2406 result = WINPROC_CallWndProc( func, hwnd, msg32, wParam32, lParam );
2408 return WINPROC_UnmapMsg16To32W( hwnd, msg32, wParam32, lParam, result );
2411 /**********************************************************************
2412 * WINPROC_Thunk16To32W
2414 static LRESULT WINAPI WINPROC_Thunk16To32W( WNDPROC func, LPBYTE args )
2416 HWND16 hwnd = *(HWND16 *)( args+8 );
2417 UINT16 msg = *(HWND16 *)( args+6 );
2418 WPARAM16 wParam = *(HWND16 *)( args+4 );
2419 LPARAM lParam = *(LPARAM *)( args+0 );
2421 return WINPROC_CallProc16To32W( func, hwnd, msg, wParam, lParam );
2424 /**********************************************************************
2425 * WINPROC_CallProc32ATo16
2427 * Call a 16-bit window procedure, translating the 32-bit args.
2429 static LRESULT WINAPI WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd,
2430 UINT msg, WPARAM wParam,
2431 LPARAM lParam )
2433 UINT16 msg16;
2434 MSGPARAM16 mp16;
2436 mp16.lParam = lParam;
2437 if (WINPROC_MapMsg32ATo16( hwnd, msg, wParam,
2438 &msg16, &mp16.wParam, &mp16.lParam ) == -1)
2439 return 0;
2440 mp16.lResult = WINPROC_CallWndProc16( func, hwnd, msg16,
2441 mp16.wParam, mp16.lParam );
2442 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, &mp16 );
2443 return mp16.lResult;
2447 /**********************************************************************
2448 * WINPROC_CallProc32WTo16
2450 * Call a 16-bit window procedure, translating the 32-bit args.
2452 static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
2453 UINT msg, WPARAM wParam,
2454 LPARAM lParam )
2456 UINT16 msg16;
2457 MSGPARAM16 mp16;
2459 mp16.lParam = lParam;
2460 if (WINPROC_MapMsg32WTo16( hwnd, msg, wParam, &msg16, &mp16.wParam,
2461 &mp16.lParam ) == -1)
2462 return 0;
2463 mp16.lResult = WINPROC_CallWndProc16( func, hwnd, msg16,
2464 mp16.wParam, mp16.lParam );
2465 WINPROC_UnmapMsg32WTo16( hwnd, msg, wParam, lParam, &mp16 );
2466 return mp16.lResult;
2470 /**********************************************************************
2471 * CallWindowProc16 (USER.122)
2473 LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
2474 WPARAM16 wParam, LPARAM lParam )
2476 WINDOWPROC *proc = WINPROC_GetPtr( func );
2478 if (!proc)
2479 return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
2481 #if testing
2482 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_16 );
2483 return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
2484 #endif
2486 switch(proc->type)
2488 case WIN_PROC_16:
2489 if (!proc->thunk.t_from32.proc) return 0;
2490 return WINPROC_CallWndProc16( proc->thunk.t_from32.proc,
2491 hwnd, msg, wParam, lParam );
2492 case WIN_PROC_32A:
2493 if (!proc->thunk.t_from16.proc) return 0;
2494 return WINPROC_CallProc16To32A( proc->thunk.t_from16.proc,
2495 hwnd, msg, wParam, lParam );
2496 case WIN_PROC_32W:
2497 if (!proc->thunk.t_from16.proc) return 0;
2498 return WINPROC_CallProc16To32W( proc->thunk.t_from16.proc,
2499 hwnd, msg, wParam, lParam );
2500 default:
2501 WARN_(relay)("Invalid proc %p\n", proc );
2502 return 0;
2507 /**********************************************************************
2508 * CallWindowProcA (USER32.18)
2510 * The CallWindowProc() function invokes the windows procedure _func_,
2511 * with _hwnd_ as the target window, the message specified by _msg_, and
2512 * the message parameters _wParam_ and _lParam_.
2514 * Some kinds of argument conversion may be done, I'm not sure what.
2516 * CallWindowProc() may be used for windows subclassing. Use
2517 * SetWindowLong() to set a new windows procedure for windows of the
2518 * subclass, and handle subclassed messages in the new windows
2519 * procedure. The new windows procedure may then use CallWindowProc()
2520 * with _func_ set to the parent class's windows procedure to dispatch
2521 * the message to the superclass.
2523 * RETURNS
2525 * The return value is message dependent.
2527 * CONFORMANCE
2529 * ECMA-234, Win32
2531 LRESULT WINAPI CallWindowProcA(
2532 WNDPROC func, /* [in] window procedure */
2533 HWND hwnd, /* [in] target window */
2534 UINT msg, /* [in] message */
2535 WPARAM wParam, /* [in] message dependent parameter */
2536 LPARAM lParam /* [in] message dependent parameter */
2538 WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
2540 if (!proc) return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2542 #if testing
2543 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_32A );
2544 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2545 #endif
2547 switch(proc->type)
2549 case WIN_PROC_16:
2550 if (!proc->thunk.t_from32.proc) return 0;
2551 return WINPROC_CallProc32ATo16( proc->thunk.t_from32.proc,
2552 hwnd, msg, wParam, lParam );
2553 case WIN_PROC_32A:
2554 if (!proc->thunk.t_from16.proc) return 0;
2555 return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
2556 hwnd, msg, wParam, lParam );
2557 case WIN_PROC_32W:
2558 if (!proc->thunk.t_from16.proc) return 0;
2559 return WINPROC_CallProc32ATo32W( proc->thunk.t_from16.proc,
2560 hwnd, msg, wParam, lParam );
2561 default:
2562 WARN_(relay)("Invalid proc %p\n", proc );
2563 return 0;
2568 /**********************************************************************
2569 * CallWindowProcW (USER32.19)
2571 LRESULT WINAPI CallWindowProcW( WNDPROC func, HWND hwnd, UINT msg,
2572 WPARAM wParam, LPARAM lParam )
2574 WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
2576 if (!proc) return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2578 #if testing
2579 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_32W );
2580 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2581 #endif
2583 switch(proc->type)
2585 case WIN_PROC_16:
2586 if (!proc->thunk.t_from32.proc) return 0;
2587 return WINPROC_CallProc32WTo16( proc->thunk.t_from32.proc,
2588 hwnd, msg, wParam, lParam );
2589 case WIN_PROC_32A:
2590 if (!proc->thunk.t_from16.proc) return 0;
2591 return WINPROC_CallProc32WTo32A( proc->thunk.t_from16.proc,
2592 hwnd, msg, wParam, lParam );
2593 case WIN_PROC_32W:
2594 if (!proc->thunk.t_from16.proc) return 0;
2595 return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
2596 hwnd, msg, wParam, lParam );
2597 default:
2598 WARN_(relay)("Invalid proc %p\n", proc );
2599 return 0;