Added several additional to/from unicode message mappings.
[wine/multimedia.git] / windows / winproc.c
blob88cb6f0e0e85c21002a19a36d5b9c33314ba1fc0
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 "winbase.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:
672 case EM_SETPASSWORDCHAR:
674 char ch = *pwparam;
675 WCHAR wch;
676 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
677 *pwparam = wch;
679 return 0;
681 case WM_ASKCBFORMATNAME:
682 case WM_DEVMODECHANGE:
683 case WM_PAINTCLIPBOARD:
684 case WM_SIZECLIPBOARD:
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:
913 case EM_SETPASSWORDCHAR:
915 WCHAR wch = *pwparam;
916 char ch;
917 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL );
918 *pwparam = ch;
920 return 0;
922 case WM_ASKCBFORMATNAME:
923 case WM_DEVMODECHANGE:
924 case WM_PAINTCLIPBOARD:
925 case WM_SIZECLIPBOARD:
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 EM_GETLINE16:
1421 WORD len = (WORD)*plparam;
1422 LPARAM *ptr = (LPARAM *)HeapAlloc(GetProcessHeap(), 0, sizeof(LPARAM) + sizeof(WORD) + len * sizeof(WCHAR));
1423 if(!ptr) return -1;
1424 *ptr++ = *plparam; /* Store previous lParam */
1425 *((WORD *)ptr) = len; /* Store the length */
1426 *plparam = (LPARAM)ptr;
1428 return 1;
1430 case EM_REPLACESEL16:
1432 WCHAR *str;
1433 INT len;
1434 *plparam = (LPARAM)PTR_SEG_TO_LIN(*plparam);
1435 len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)*plparam, -1, NULL, 0);
1436 str = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1437 if(!str) return -1;
1438 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)*plparam, -1, str, len);
1439 *plparam = (LPARAM)str;
1441 return 1;
1443 case EM_SETPASSWORDCHAR16:
1445 char ch = wParam16;
1446 WCHAR wch;
1447 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
1448 *pwparam32 = wch;
1450 return 0;
1452 case WM_GETTEXT:
1453 case WM_SETTEXT:
1454 *plparam = (LPARAM)PTR_SEG_TO_LIN(*plparam);
1455 return WINPROC_MapMsg32ATo32W( hwnd, *pmsg32, pwparam32, plparam );
1456 case WM_NCCREATE:
1457 case WM_CREATE:
1459 CREATESTRUCT16 *cs16 = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1460 CREATESTRUCTW *cs = (CREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
1461 sizeof(*cs) + sizeof(LPARAM) );
1462 if (!cs) return -1;
1463 STRUCT32_CREATESTRUCT16to32A( cs16, (CREATESTRUCTA *)cs );
1464 cs->lpszName = (LPCWSTR)PTR_SEG_TO_LIN(cs16->lpszName);
1465 cs->lpszClass = (LPCWSTR)PTR_SEG_TO_LIN(cs16->lpszClass);
1466 if (HIWORD(cs->lpszName))
1467 cs->lpszName = HEAP_strdupAtoW( GetProcessHeap(), 0,
1468 (LPCSTR)cs->lpszName );
1469 if (HIWORD(cs->lpszClass))
1470 cs->lpszClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
1471 (LPCSTR)cs->lpszClass );
1472 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1473 *plparam = (LPARAM)cs;
1475 return 1;
1476 case WM_MDICREATE:
1478 MDICREATESTRUCT16 *cs16 =
1479 (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1480 MDICREATESTRUCTW *cs =
1481 (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
1482 sizeof(*cs) + sizeof(LPARAM) );
1483 if (!cs) return -1;
1484 STRUCT32_MDICREATESTRUCT16to32A( cs16, (MDICREATESTRUCTA *)cs );
1485 cs->szTitle = (LPCWSTR)PTR_SEG_TO_LIN(cs16->szTitle);
1486 cs->szClass = (LPCWSTR)PTR_SEG_TO_LIN(cs16->szClass);
1487 if (HIWORD(cs->szTitle))
1488 cs->szTitle = HEAP_strdupAtoW( GetProcessHeap(), 0,
1489 (LPCSTR)cs->szTitle );
1490 if (HIWORD(cs->szClass))
1491 cs->szClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
1492 (LPCSTR)cs->szClass );
1493 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1494 *plparam = (LPARAM)cs;
1496 return 1;
1497 case WM_GETDLGCODE:
1498 if (*plparam)
1500 LPMSG16 msg16 = (LPMSG16)PTR_SEG_TO_LIN(*plparam);
1501 LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1503 if (!msg32) return -1;
1504 msg32->hwnd = msg16->hwnd;
1505 msg32->lParam = msg16->lParam;
1506 msg32->time = msg16->time;
1507 CONV_POINT16TO32(&msg16->pt,&msg32->pt);
1508 /* this is right, right? */
1509 if (WINPROC_MapMsg16To32W(hwnd, msg16->message,msg16->wParam,
1510 &msg32->message,&msg32->wParam,
1511 &msg32->lParam)<0) {
1512 HeapFree( GetProcessHeap(), 0, msg32 );
1513 return -1;
1515 *plparam = (LPARAM)msg32;
1516 return 1;
1518 else return 0;
1520 case WM_CHAR:
1521 case WM_DEADCHAR:
1522 case WM_SYSCHAR:
1523 case WM_SYSDEADCHAR:
1525 char ch = wParam16;
1526 WCHAR wch;
1527 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1528 *pwparam32 = wch;
1530 return 0;
1532 default: /* No Unicode translation needed */
1533 return WINPROC_MapMsg16To32A( msg16, wParam16, pmsg32,
1534 pwparam32, plparam );
1539 /**********************************************************************
1540 * WINPROC_UnmapMsg16To32W
1542 * Unmap a message that was mapped from 16- to 32-bit Unicode.
1544 LRESULT WINPROC_UnmapMsg16To32W( HWND16 hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1545 LRESULT result )
1547 switch(msg)
1549 case EM_GETLINE16:
1551 LPARAM *ptr = (LPARAM *)lParam - 1; /* get the old lParam */
1552 WORD len = *(WORD *)lParam;
1553 *ptr = (LPARAM)PTR_SEG_TO_LIN(*ptr);
1554 if(len > 0 && !WideCharToMultiByte(CP_ACP, 0, (LPWSTR)lParam, -1,
1555 (LPSTR)*ptr, len, NULL, NULL))
1556 ((LPSTR)*ptr)[len-1] = 0;
1557 HeapFree(GetProcessHeap(), 0, ptr);
1559 break;
1561 case EM_REPLACESEL16:
1562 HeapFree(GetProcessHeap(), 0, (void *)lParam);
1563 break;
1565 case WM_GETTEXT:
1566 case WM_SETTEXT:
1567 WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam );
1568 break;
1569 case WM_NCCREATE:
1570 case WM_CREATE:
1572 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
1573 lParam = *(LPARAM *)(cs + 1);
1574 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs,
1575 (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
1576 if (HIWORD(cs->lpszName))
1577 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszName );
1578 if (HIWORD(cs->lpszClass))
1579 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszClass );
1580 HeapFree( GetProcessHeap(), 0, cs );
1582 break;
1583 case WM_MDICREATE:
1585 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
1586 lParam = *(LPARAM *)(cs + 1);
1587 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs,
1588 (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
1589 if (HIWORD(cs->szTitle))
1590 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
1591 if (HIWORD(cs->szClass))
1592 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
1593 HeapFree( GetProcessHeap(), 0, cs );
1595 break;
1596 case WM_GETDLGCODE:
1597 if (lParam)
1599 LPMSG msg32 = (LPMSG)lParam;
1601 WINPROC_UnmapMsg16To32W( hwnd, msg32->message, msg32->wParam, msg32->lParam,
1602 result);
1603 HeapFree( GetProcessHeap(), 0, msg32 );
1605 break;
1606 default:
1607 return WINPROC_UnmapMsg16To32A( hwnd, msg, wParam, lParam, result );
1609 return result;
1613 /**********************************************************************
1614 * WINPROC_MapMsg32ATo16
1616 * Map a message from 32-bit Ansi to 16-bit.
1617 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1619 INT WINPROC_MapMsg32ATo16( HWND hwnd, UINT msg32, WPARAM wParam32,
1620 UINT16 *pmsg16, WPARAM16 *pwparam16,
1621 LPARAM *plparam )
1623 *pmsg16 = (UINT16)msg32;
1624 *pwparam16 = (WPARAM16)LOWORD(wParam32);
1625 switch(msg32)
1627 case BM_GETCHECK:
1628 case BM_SETCHECK:
1629 case BM_GETSTATE:
1630 case BM_SETSTATE:
1631 case BM_SETSTYLE:
1632 *pmsg16 = (UINT16)msg32 + (BM_GETCHECK16 - BM_GETCHECK);
1633 return 0;
1635 case EM_GETSEL:
1636 case EM_GETRECT:
1637 case EM_SETRECT:
1638 case EM_SETRECTNP:
1639 case EM_SCROLL:
1640 case EM_LINESCROLL:
1641 case EM_SCROLLCARET:
1642 case EM_GETMODIFY:
1643 case EM_SETMODIFY:
1644 case EM_GETLINECOUNT:
1645 case EM_LINEINDEX:
1646 case EM_SETHANDLE:
1647 case EM_GETHANDLE:
1648 case EM_GETTHUMB:
1649 case EM_LINELENGTH:
1650 case EM_REPLACESEL:
1651 case EM_GETLINE:
1652 case EM_LIMITTEXT:
1653 case EM_CANUNDO:
1654 case EM_UNDO:
1655 case EM_FMTLINES:
1656 case EM_LINEFROMCHAR:
1657 case EM_SETTABSTOPS:
1658 case EM_SETPASSWORDCHAR:
1659 case EM_EMPTYUNDOBUFFER:
1660 case EM_GETFIRSTVISIBLELINE:
1661 case EM_SETREADONLY:
1662 case EM_SETWORDBREAKPROC:
1663 case EM_GETWORDBREAKPROC:
1664 case EM_GETPASSWORDCHAR:
1665 *pmsg16 = (UINT16)msg32 + (EM_GETSEL16 - EM_GETSEL);
1666 return 0;
1668 case LB_CARETOFF:
1669 case LB_CARETON:
1670 case LB_DELETESTRING:
1671 case LB_GETANCHORINDEX:
1672 case LB_GETCARETINDEX:
1673 case LB_GETCOUNT:
1674 case LB_GETCURSEL:
1675 case LB_GETHORIZONTALEXTENT:
1676 case LB_GETITEMDATA:
1677 case LB_GETITEMHEIGHT:
1678 case LB_GETSEL:
1679 case LB_GETSELCOUNT:
1680 case LB_GETTEXTLEN:
1681 case LB_GETTOPINDEX:
1682 case LB_RESETCONTENT:
1683 case LB_SELITEMRANGE:
1684 case LB_SELITEMRANGEEX:
1685 case LB_SETANCHORINDEX:
1686 case LB_SETCARETINDEX:
1687 case LB_SETCOLUMNWIDTH:
1688 case LB_SETCURSEL:
1689 case LB_SETHORIZONTALEXTENT:
1690 case LB_SETITEMDATA:
1691 case LB_SETITEMHEIGHT:
1692 case LB_SETSEL:
1693 case LB_SETTOPINDEX:
1694 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
1695 return 0;
1696 case CB_DELETESTRING:
1697 case CB_GETCOUNT:
1698 case CB_GETLBTEXTLEN:
1699 case CB_LIMITTEXT:
1700 case CB_RESETCONTENT:
1701 case CB_SETEDITSEL:
1702 case CB_GETCURSEL:
1703 case CB_SETCURSEL:
1704 case CB_SHOWDROPDOWN:
1705 case CB_SETITEMDATA:
1706 case CB_SETITEMHEIGHT:
1707 case CB_GETITEMHEIGHT:
1708 case CB_SETEXTENDEDUI:
1709 case CB_GETEXTENDEDUI:
1710 case CB_GETDROPPEDSTATE:
1711 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
1712 return 0;
1713 case CB_GETEDITSEL:
1714 *pmsg16 = CB_GETEDITSEL16;
1715 return 1;
1717 case LB_ADDSTRING:
1718 case LB_FINDSTRING:
1719 case LB_FINDSTRINGEXACT:
1720 case LB_INSERTSTRING:
1721 case LB_SELECTSTRING:
1722 case LB_DIR:
1723 case LB_ADDFILE:
1725 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
1726 if (!str) return -1;
1727 *plparam = (LPARAM)SEGPTR_GET(str);
1729 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
1730 return 1;
1732 case CB_ADDSTRING:
1733 case CB_FINDSTRING:
1734 case CB_FINDSTRINGEXACT:
1735 case CB_INSERTSTRING:
1736 case CB_SELECTSTRING:
1737 case CB_DIR:
1739 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
1740 if (!str) return -1;
1741 *plparam = (LPARAM)SEGPTR_GET(str);
1743 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
1744 return 1;
1746 case LB_GETITEMRECT:
1748 RECT16 *rect;
1749 rect = (RECT16 *)SEGPTR_ALLOC( sizeof(RECT16) + sizeof(LPARAM) );
1750 if (!rect) return -1;
1751 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
1752 *plparam = (LPARAM)SEGPTR_GET(rect);
1754 *pmsg16 = LB_GETITEMRECT16;
1755 return 1;
1756 case LB_GETSELITEMS:
1758 LPINT16 items;
1759 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
1760 if (!(items = SEGPTR_ALLOC( *pwparam16 * sizeof(INT16)
1761 + sizeof(LPARAM)))) return -1;
1762 *((LPARAM *)items)++ = *plparam; /* Store the previous lParam */
1763 *plparam = (LPARAM)SEGPTR_GET(items);
1765 *pmsg16 = LB_GETSELITEMS16;
1766 return 1;
1767 case LB_SETTABSTOPS:
1768 if (wParam32)
1770 INT i;
1771 LPINT16 stops;
1772 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
1773 if (!(stops = SEGPTR_ALLOC( *pwparam16 * sizeof(INT16)
1774 + sizeof(LPARAM)))) return -1;
1775 for (i = 0; i < *pwparam16; i++) stops[i] = *((LPINT)*plparam+i);
1776 *plparam = (LPARAM)SEGPTR_GET(stops);
1777 return 1;
1779 *pmsg16 = LB_SETTABSTOPS16;
1780 return 0;
1782 case CB_GETDROPPEDCONTROLRECT:
1784 RECT16 *rect;
1785 rect = (RECT16 *)SEGPTR_ALLOC( sizeof(RECT16) + sizeof(LPARAM) );
1786 if (!rect) return -1;
1787 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
1788 *plparam = (LPARAM)SEGPTR_GET(rect);
1790 *pmsg16 = CB_GETDROPPEDCONTROLRECT16;
1791 return 1;
1793 case LB_GETTEXT:
1794 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
1795 *pmsg16 = LB_GETTEXT16;
1796 return 1;
1798 case CB_GETLBTEXT:
1799 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
1800 *pmsg16 = CB_GETLBTEXT16;
1801 return 1;
1803 case EM_SETSEL:
1804 *pwparam16 = 0;
1805 *plparam = MAKELONG( (INT16)(INT)wParam32, (INT16)*plparam );
1806 *pmsg16 = EM_SETSEL16;
1807 return 0;
1809 case WM_ACTIVATE:
1810 case WM_CHARTOITEM:
1811 case WM_COMMAND:
1812 case WM_VKEYTOITEM:
1813 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
1814 return 0;
1815 case WM_HSCROLL:
1816 case WM_VSCROLL:
1817 *plparam = MAKELPARAM( HIWORD(wParam32), (HWND16)*plparam );
1818 return 0;
1819 case WM_CTLCOLORMSGBOX:
1820 case WM_CTLCOLOREDIT:
1821 case WM_CTLCOLORLISTBOX:
1822 case WM_CTLCOLORBTN:
1823 case WM_CTLCOLORDLG:
1824 case WM_CTLCOLORSCROLLBAR:
1825 case WM_CTLCOLORSTATIC:
1826 *pmsg16 = WM_CTLCOLOR;
1827 *plparam = MAKELPARAM( (HWND16)*plparam,
1828 (WORD)msg32 - WM_CTLCOLORMSGBOX );
1829 return 0;
1830 case WM_COMPAREITEM:
1832 COMPAREITEMSTRUCT *cis32 = (COMPAREITEMSTRUCT *)*plparam;
1833 COMPAREITEMSTRUCT16 *cis = SEGPTR_NEW(COMPAREITEMSTRUCT16);
1834 if (!cis) return -1;
1835 cis->CtlType = (UINT16)cis32->CtlType;
1836 cis->CtlID = (UINT16)cis32->CtlID;
1837 cis->hwndItem = (HWND16)cis32->hwndItem;
1838 cis->itemID1 = (UINT16)cis32->itemID1;
1839 cis->itemData1 = cis32->itemData1;
1840 cis->itemID2 = (UINT16)cis32->itemID2;
1841 cis->itemData2 = cis32->itemData2;
1842 *plparam = (LPARAM)SEGPTR_GET(cis);
1844 return 1;
1845 case WM_DELETEITEM:
1847 DELETEITEMSTRUCT *dis32 = (DELETEITEMSTRUCT *)*plparam;
1848 DELETEITEMSTRUCT16 *dis = SEGPTR_NEW(DELETEITEMSTRUCT16);
1849 if (!dis) return -1;
1850 dis->CtlType = (UINT16)dis32->CtlType;
1851 dis->CtlID = (UINT16)dis32->CtlID;
1852 dis->itemID = (UINT16)dis32->itemID;
1853 dis->hwndItem = (HWND16)dis32->hwndItem;
1854 dis->itemData = dis32->itemData;
1855 *plparam = (LPARAM)SEGPTR_GET(dis);
1857 return 1;
1858 case WM_DRAWITEM:
1860 DRAWITEMSTRUCT *dis32 = (DRAWITEMSTRUCT *)*plparam;
1861 DRAWITEMSTRUCT16 *dis = SEGPTR_NEW(DRAWITEMSTRUCT16);
1862 if (!dis) return -1;
1863 dis->CtlType = (UINT16)dis32->CtlType;
1864 dis->CtlID = (UINT16)dis32->CtlID;
1865 dis->itemID = (UINT16)dis32->itemID;
1866 dis->itemAction = (UINT16)dis32->itemAction;
1867 dis->itemState = (UINT16)dis32->itemState;
1868 dis->hwndItem = (HWND16)dis32->hwndItem;
1869 dis->hDC = (HDC16)dis32->hDC;
1870 dis->itemData = dis32->itemData;
1871 CONV_RECT32TO16( &dis32->rcItem, &dis->rcItem );
1872 *plparam = (LPARAM)SEGPTR_GET(dis);
1874 return 1;
1875 case WM_MEASUREITEM:
1877 MEASUREITEMSTRUCT *mis32 = (MEASUREITEMSTRUCT *)*plparam;
1878 MEASUREITEMSTRUCT16 *mis = (MEASUREITEMSTRUCT16 *)
1879 SEGPTR_ALLOC(sizeof(*mis)+sizeof(LPARAM));
1880 if (!mis) return -1;
1881 mis->CtlType = (UINT16)mis32->CtlType;
1882 mis->CtlID = (UINT16)mis32->CtlID;
1883 mis->itemID = (UINT16)mis32->itemID;
1884 mis->itemWidth = (UINT16)mis32->itemWidth;
1885 mis->itemHeight = (UINT16)mis32->itemHeight;
1886 mis->itemData = mis32->itemData;
1887 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
1888 *plparam = (LPARAM)SEGPTR_GET(mis);
1890 return 1;
1891 case WM_GETMINMAXINFO:
1893 MINMAXINFO16 *mmi = (MINMAXINFO16 *)SEGPTR_ALLOC( sizeof(*mmi) +
1894 sizeof(LPARAM) );
1895 if (!mmi) return -1;
1896 STRUCT32_MINMAXINFO32to16( (MINMAXINFO *)*plparam, mmi );
1897 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
1898 *plparam = (LPARAM)SEGPTR_GET(mmi);
1900 return 1;
1901 case WM_GETTEXT:
1903 LPSTR str;
1904 *pwparam16 = (WPARAM16)min( wParam32, 0xff80 ); /* Must be < 64K */
1905 if (!(str = SEGPTR_ALLOC(*pwparam16 + sizeof(LPARAM)))) return -1;
1906 *((LPARAM *)str)++ = *plparam; /* Store the previous lParam */
1907 *plparam = (LPARAM)SEGPTR_GET(str);
1909 return 1;
1910 case WM_MDICREATE:
1912 MDICREATESTRUCT16 *cs;
1913 MDICREATESTRUCTA *cs32 = (MDICREATESTRUCTA *)*plparam;
1914 LPSTR name, cls;
1916 if (!(cs = SEGPTR_NEW(MDICREATESTRUCT16))) return -1;
1917 STRUCT32_MDICREATESTRUCT32Ato16( cs32, cs );
1918 name = SEGPTR_STRDUP( cs32->szTitle );
1919 cls = SEGPTR_STRDUP( cs32->szClass );
1920 cs->szTitle = SEGPTR_GET(name);
1921 cs->szClass = SEGPTR_GET(cls);
1922 *plparam = (LPARAM)SEGPTR_GET(cs);
1924 return 1;
1925 case WM_MDIGETACTIVE:
1926 return 1;
1927 case WM_MDISETMENU:
1928 *plparam = MAKELPARAM( (HMENU16)LOWORD(wParam32),
1929 (HMENU16)LOWORD(*plparam) );
1930 *pwparam16 = (*plparam == 0);
1931 return 0;
1932 case WM_MENUSELECT:
1933 if(HIWORD(wParam32) & MF_POPUP)
1935 UINT16 hmenu;
1936 if (((UINT)HIWORD(wParam32) != 0xFFFF) || (*plparam))
1938 if((hmenu = GetSubMenu((HMENU16)*plparam, *pwparam16)))
1939 *pwparam16=hmenu;
1942 /* fall through */
1943 case WM_MENUCHAR:
1944 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
1945 return 0;
1946 case WM_MDIACTIVATE:
1948 WND *tempWnd = WIN_FindWndPtr(hwnd);
1949 if( WIDGETS_IsControl(tempWnd, BIC32_MDICLIENT) )
1951 *pwparam16 = (HWND)wParam32;
1952 *plparam = 0;
1954 else
1956 *pwparam16 = ((HWND)*plparam == hwnd);
1957 *plparam = MAKELPARAM( (HWND16)LOWORD(*plparam),
1958 (HWND16)LOWORD(wParam32) );
1960 WIN_ReleaseWndPtr(tempWnd);
1962 return 0;
1963 case WM_NCCALCSIZE:
1965 NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)*plparam;
1966 NCCALCSIZE_PARAMS16 *nc = (NCCALCSIZE_PARAMS16 *)SEGPTR_ALLOC( sizeof(*nc) + sizeof(LPARAM) );
1967 if (!nc) return -1;
1969 CONV_RECT32TO16( &nc32->rgrc[0], &nc->rgrc[0] );
1970 if (wParam32)
1972 WINDOWPOS16 *wp;
1973 CONV_RECT32TO16( &nc32->rgrc[1], &nc->rgrc[1] );
1974 CONV_RECT32TO16( &nc32->rgrc[2], &nc->rgrc[2] );
1975 if (!(wp = SEGPTR_NEW(WINDOWPOS16)))
1977 SEGPTR_FREE(nc);
1978 return -1;
1980 STRUCT32_WINDOWPOS32to16( nc32->lppos, wp );
1981 nc->lppos = SEGPTR_GET(wp);
1983 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
1984 *plparam = (LPARAM)SEGPTR_GET(nc);
1986 return 1;
1987 case WM_NCCREATE:
1988 case WM_CREATE:
1990 CREATESTRUCT16 *cs;
1991 CREATESTRUCTA *cs32 = (CREATESTRUCTA *)*plparam;
1992 LPSTR name, cls;
1994 if (!(cs = SEGPTR_NEW(CREATESTRUCT16))) return -1;
1995 STRUCT32_CREATESTRUCT32Ato16( cs32, cs );
1996 name = SEGPTR_STRDUP( cs32->lpszName );
1997 cls = SEGPTR_STRDUP( cs32->lpszClass );
1998 cs->lpszName = SEGPTR_GET(name);
1999 cs->lpszClass = SEGPTR_GET(cls);
2000 *plparam = (LPARAM)SEGPTR_GET(cs);
2002 return 1;
2003 case WM_PARENTNOTIFY:
2004 if ((LOWORD(wParam32)==WM_CREATE) || (LOWORD(wParam32)==WM_DESTROY))
2005 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32));
2006 /* else nothing to do */
2007 return 0;
2008 case WM_NOTIFY:
2009 *plparam = MapLS( (NMHDR *)*plparam ); /* NMHDR is already 32-bit */
2010 return 1;
2011 case WM_SETTEXT:
2013 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
2014 if (!str) return -1;
2015 *plparam = (LPARAM)SEGPTR_GET(str);
2017 return 1;
2018 case WM_WINDOWPOSCHANGING:
2019 case WM_WINDOWPOSCHANGED:
2021 WINDOWPOS16 *wp = (WINDOWPOS16 *)SEGPTR_ALLOC( sizeof(*wp) +
2022 sizeof(LPARAM) );
2023 if (!wp) return -1;
2024 STRUCT32_WINDOWPOS32to16( (WINDOWPOS *)*plparam, wp );
2025 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
2026 *plparam = (LPARAM)SEGPTR_GET(wp);
2028 return 1;
2029 case WM_GETDLGCODE:
2030 if (*plparam) {
2031 LPMSG msg32 = (LPMSG) *plparam;
2032 LPMSG16 msg16 = (LPMSG16) SEGPTR_NEW( MSG16 );
2034 if (!msg16) return -1;
2035 msg16->hwnd = msg32->hwnd;
2036 msg16->lParam = msg32->lParam;
2037 msg16->time = msg32->time;
2038 CONV_POINT32TO16(&msg32->pt,&msg16->pt);
2039 /* this is right, right? */
2040 if (WINPROC_MapMsg32ATo16(msg32->hwnd,msg32->message,msg32->wParam,
2041 &msg16->message,&msg16->wParam, &msg16->lParam)<0) {
2042 SEGPTR_FREE( msg16 );
2043 return -1;
2045 *plparam = (LPARAM)SEGPTR_GET(msg16);
2046 return 1;
2048 return 0;
2050 case WM_ACTIVATEAPP:
2051 if (*plparam) {
2052 *plparam = (LPARAM)THREAD_IdToTEB((DWORD) *plparam)->htask16;
2054 return 1;
2055 case WM_ASKCBFORMATNAME:
2056 case WM_DEVMODECHANGE:
2057 case WM_PAINTCLIPBOARD:
2058 case WM_SIZECLIPBOARD:
2059 case WM_WININICHANGE:
2060 FIXME_(msg)("message %04x needs translation\n", msg32 );
2061 return -1;
2062 case WM_SIZING: /* should not be send to 16-bit apps */
2063 return -1;
2064 default: /* No translation needed */
2065 return 0;
2070 /**********************************************************************
2071 * WINPROC_UnmapMsg32ATo16
2073 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
2075 void WINPROC_UnmapMsg32ATo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2076 MSGPARAM16* p16 )
2078 switch(msg)
2080 case LB_ADDFILE:
2081 case LB_ADDSTRING:
2082 case LB_DIR:
2083 case LB_FINDSTRING:
2084 case LB_FINDSTRINGEXACT:
2085 case LB_INSERTSTRING:
2086 case LB_SELECTSTRING:
2087 case LB_SETTABSTOPS:
2088 case CB_ADDSTRING:
2089 case CB_FINDSTRING:
2090 case CB_FINDSTRINGEXACT:
2091 case CB_INSERTSTRING:
2092 case CB_SELECTSTRING:
2093 case CB_DIR:
2094 case WM_COMPAREITEM:
2095 case WM_DELETEITEM:
2096 case WM_DRAWITEM:
2097 case WM_SETTEXT:
2098 SEGPTR_FREE( PTR_SEG_TO_LIN(p16->lParam) );
2099 break;
2101 case CB_GETDROPPEDCONTROLRECT:
2102 case LB_GETITEMRECT:
2104 RECT16 *rect = (RECT16 *)PTR_SEG_TO_LIN(p16->lParam);
2105 p16->lParam = *(LPARAM *)(rect + 1);
2106 CONV_RECT16TO32( rect, (RECT *)(p16->lParam));
2107 SEGPTR_FREE( rect );
2109 break;
2110 case LB_GETSELITEMS:
2112 INT i;
2113 LPINT16 items = (LPINT16)PTR_SEG_TO_LIN(lParam);
2114 p16->lParam = *((LPARAM *)items - 1);
2115 for (i = 0; i < p16->wParam; i++) *((LPINT)(p16->lParam) + i) = items[i];
2116 SEGPTR_FREE( (LPARAM *)items - 1 );
2118 break;
2120 case CB_GETEDITSEL:
2121 if( wParam )
2122 *((LPUINT)(wParam)) = LOWORD(p16->lResult);
2123 if( lParam )
2124 *((LPUINT)(lParam)) = HIWORD(p16->lResult); /* FIXME: substract 1? */
2125 break;
2127 case LB_GETTEXT:
2128 case CB_GETLBTEXT:
2129 UnMapLS( (SEGPTR)(p16->lParam) );
2130 break;
2132 case WM_MEASUREITEM:
2134 MEASUREITEMSTRUCT16 *mis = (MEASUREITEMSTRUCT16 *)PTR_SEG_TO_LIN(p16->lParam);
2135 MEASUREITEMSTRUCT *mis32 = *(MEASUREITEMSTRUCT **)(mis + 1);
2136 mis32->itemWidth = mis->itemWidth;
2137 mis32->itemHeight = mis->itemHeight;
2138 SEGPTR_FREE(mis);
2140 break;
2141 case WM_GETMINMAXINFO:
2143 MINMAXINFO16 *mmi = (MINMAXINFO16 *)PTR_SEG_TO_LIN(p16->lParam);
2144 p16->lParam = *(LPARAM *)(mmi + 1);
2145 STRUCT32_MINMAXINFO16to32( mmi, (MINMAXINFO *)(p16->lParam) );
2146 SEGPTR_FREE(mmi);
2148 break;
2149 case WM_GETTEXT:
2151 LPSTR str = (LPSTR)PTR_SEG_TO_LIN(p16->lParam);
2152 p16->lParam = *((LPARAM *)str - 1);
2153 lstrcpynA( (LPSTR)(p16->lParam), str, p16->wParam );
2154 SEGPTR_FREE( (LPARAM *)str - 1 );
2156 break;
2157 case WM_MDICREATE:
2159 MDICREATESTRUCT16 *cs = (MDICREATESTRUCT16*)PTR_SEG_TO_LIN(p16->lParam);
2160 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->szTitle) );
2161 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->szClass) );
2162 SEGPTR_FREE( cs );
2164 break;
2165 case WM_MDIGETACTIVE:
2166 if (lParam) *(BOOL *)lParam = (BOOL16)HIWORD(p16->lResult);
2167 p16->lResult = (HWND)LOWORD(p16->lResult);
2168 break;
2169 case WM_NCCALCSIZE:
2171 NCCALCSIZE_PARAMS *nc32;
2172 NCCALCSIZE_PARAMS16 *nc = (NCCALCSIZE_PARAMS16 *)PTR_SEG_TO_LIN(p16->lParam);
2173 p16->lParam = *(LPARAM *)(nc + 1);
2174 nc32 = (NCCALCSIZE_PARAMS *)(p16->lParam);
2175 CONV_RECT16TO32( &nc->rgrc[0], &nc32->rgrc[0] );
2176 if (p16->wParam)
2178 CONV_RECT16TO32( &nc->rgrc[1], &nc32->rgrc[1] );
2179 CONV_RECT16TO32( &nc->rgrc[2], &nc32->rgrc[2] );
2180 STRUCT32_WINDOWPOS16to32( (WINDOWPOS16 *)PTR_SEG_TO_LIN(nc->lppos),
2181 nc32->lppos );
2182 SEGPTR_FREE( PTR_SEG_TO_LIN(nc->lppos) );
2184 SEGPTR_FREE(nc);
2186 break;
2187 case WM_NCCREATE:
2188 case WM_CREATE:
2190 CREATESTRUCT16 *cs = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(p16->lParam);
2191 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->lpszName) );
2192 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->lpszClass) );
2193 SEGPTR_FREE( cs );
2195 break;
2196 case WM_WINDOWPOSCHANGING:
2197 case WM_WINDOWPOSCHANGED:
2199 WINDOWPOS16 *wp = (WINDOWPOS16 *)PTR_SEG_TO_LIN(p16->lParam);
2200 p16->lParam = *(LPARAM *)(wp + 1);
2201 STRUCT32_WINDOWPOS16to32( wp, (WINDOWPOS *)p16->lParam );
2202 SEGPTR_FREE(wp);
2204 break;
2205 case WM_NOTIFY:
2206 UnMapLS(p16->lParam);
2207 break;
2208 case WM_GETDLGCODE:
2209 if (p16->lParam)
2211 LPMSG16 msg16 = (LPMSG16)PTR_SEG_TO_LIN(p16->lParam);
2212 MSGPARAM16 msgp16;
2213 msgp16.wParam=msg16->wParam;
2214 msgp16.lParam=msg16->lParam;
2215 WINPROC_UnmapMsg32ATo16(((LPMSG)lParam)->hwnd, ((LPMSG)lParam)->message,
2216 ((LPMSG)lParam)->wParam, ((LPMSG)lParam)->lParam,
2217 &msgp16 );
2218 SEGPTR_FREE(msg16);
2220 break;
2225 /**********************************************************************
2226 * WINPROC_MapMsg32WTo16
2228 * Map a message from 32-bit Unicode to 16-bit.
2229 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
2231 INT WINPROC_MapMsg32WTo16( HWND hwnd, UINT msg32, WPARAM wParam32,
2232 UINT16 *pmsg16, WPARAM16 *pwparam16,
2233 LPARAM *plparam )
2235 *pmsg16 = LOWORD(msg32);
2236 *pwparam16 = LOWORD(wParam32);
2237 switch(msg32)
2239 case LB_ADDSTRING:
2240 case LB_FINDSTRING:
2241 case LB_FINDSTRINGEXACT:
2242 case LB_INSERTSTRING:
2243 case LB_SELECTSTRING:
2244 case LB_DIR:
2245 case LB_ADDFILE:
2247 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
2248 if (!str) return -1;
2249 *plparam = (LPARAM)SEGPTR_GET(str);
2251 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
2252 return 1;
2254 case CB_ADDSTRING:
2255 case CB_FINDSTRING:
2256 case CB_FINDSTRINGEXACT:
2257 case CB_INSERTSTRING:
2258 case CB_SELECTSTRING:
2259 case CB_DIR:
2261 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
2262 if (!str) return -1;
2263 *plparam = (LPARAM)SEGPTR_GET(str);
2265 *pmsg16 = (UINT16)msg32 + (CB_ADDSTRING16 - CB_ADDSTRING);
2266 return 1;
2268 case WM_NCCREATE:
2269 case WM_CREATE:
2271 CREATESTRUCT16 *cs;
2272 CREATESTRUCTW *cs32 = (CREATESTRUCTW *)*plparam;
2273 LPSTR name, cls;
2275 if (!(cs = SEGPTR_NEW(CREATESTRUCT16))) return -1;
2276 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs32, cs );
2277 name = SEGPTR_STRDUP_WtoA( cs32->lpszName );
2278 cls = SEGPTR_STRDUP_WtoA( cs32->lpszClass );
2279 cs->lpszName = SEGPTR_GET(name);
2280 cs->lpszClass = SEGPTR_GET(cls);
2281 *plparam = (LPARAM)SEGPTR_GET(cs);
2283 return 1;
2284 case WM_MDICREATE:
2286 MDICREATESTRUCT16 *cs;
2287 MDICREATESTRUCTW *cs32 = (MDICREATESTRUCTW *)*plparam;
2288 LPSTR name, cls;
2290 if (!(cs = SEGPTR_NEW(MDICREATESTRUCT16))) return -1;
2291 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs32, cs );
2292 name = SEGPTR_STRDUP_WtoA( cs32->szTitle );
2293 cls = SEGPTR_STRDUP_WtoA( cs32->szClass );
2294 cs->szTitle = SEGPTR_GET(name);
2295 cs->szClass = SEGPTR_GET(cls);
2296 *plparam = (LPARAM)SEGPTR_GET(cs);
2298 return 1;
2299 case WM_SETTEXT:
2301 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
2302 if (!str) return -1;
2303 *plparam = (LPARAM)SEGPTR_GET(str);
2305 return 1;
2306 case LB_GETTEXT:
2307 case CB_GETLBTEXT:
2308 if ( WINPROC_TestLBForStr( hwnd ))
2310 LPSTR str = (LPSTR) SEGPTR_ALLOC( 256 ); /* fixme: fixed sized buffer */
2311 if (!str) return -1;
2312 *pmsg16 = (msg32 == LB_GETTEXT)? LB_GETTEXT16 : CB_GETLBTEXT16;
2313 *plparam = (LPARAM)SEGPTR_GET(str);
2315 return 1;
2317 case WM_CHAR:
2318 case WM_DEADCHAR:
2319 case WM_SYSCHAR:
2320 case WM_SYSDEADCHAR:
2322 WCHAR wch = wParam32;
2323 char ch;
2324 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
2325 *pwparam16 = ch;
2327 return 0;
2329 default: /* No Unicode translation needed (?) */
2330 return WINPROC_MapMsg32ATo16( hwnd, msg32, wParam32, pmsg16,
2331 pwparam16, plparam );
2336 /**********************************************************************
2337 * WINPROC_UnmapMsg32WTo16
2339 * Unmap a message that was mapped from 32-bit Unicode to 16-bit.
2341 void WINPROC_UnmapMsg32WTo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2342 MSGPARAM16* p16 )
2344 switch(msg)
2346 case WM_GETTEXT:
2348 LPSTR str = (LPSTR)PTR_SEG_TO_LIN(p16->lParam);
2349 p16->lParam = *((LPARAM *)str - 1);
2350 MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)p16->lParam, 0x7fffffff );
2351 SEGPTR_FREE( (LPARAM *)str - 1 );
2353 break;
2354 case LB_GETTEXT:
2355 case CB_GETLBTEXT:
2356 if ( WINPROC_TestLBForStr( hwnd ))
2358 LPSTR str = (LPSTR)PTR_SEG_TO_LIN(p16->lParam);
2359 MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)lParam, 0x7fffffff );
2360 SEGPTR_FREE( (LPARAM *) str );
2362 break;
2363 default:
2364 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, p16 );
2365 break;
2370 /**********************************************************************
2371 * WINPROC_CallProc32ATo32W
2373 * Call a window procedure, translating args from Ansi to Unicode.
2375 static LRESULT WINPROC_CallProc32ATo32W( WNDPROC func, HWND hwnd,
2376 UINT msg, WPARAM wParam,
2377 LPARAM lParam )
2379 LRESULT result;
2381 if (WINPROC_MapMsg32ATo32W( hwnd, msg, &wParam, &lParam ) == -1) return 0;
2382 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2383 WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam );
2384 return result;
2388 /**********************************************************************
2389 * WINPROC_CallProc32WTo32A
2391 * Call a window procedure, translating args from Unicode to Ansi.
2393 static LRESULT WINPROC_CallProc32WTo32A( WNDPROC func, HWND hwnd,
2394 UINT msg, WPARAM wParam,
2395 LPARAM lParam )
2397 LRESULT result;
2399 if (WINPROC_MapMsg32WTo32A( hwnd, msg, &wParam, &lParam ) == -1) return 0;
2400 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2401 WINPROC_UnmapMsg32WTo32A( hwnd, msg, wParam, lParam );
2402 return result;
2406 /**********************************************************************
2407 * WINPROC_CallProc16To32A
2409 * Call a 32-bit window procedure, translating the 16-bit args.
2411 static LRESULT WINPROC_CallProc16To32A( WNDPROC func, HWND16 hwnd,
2412 UINT16 msg, WPARAM16 wParam,
2413 LPARAM lParam )
2415 LRESULT result;
2416 UINT msg32;
2417 WPARAM wParam32;
2419 if (WINPROC_MapMsg16To32A( msg, wParam, &msg32, &wParam32, &lParam ) == -1)
2420 return 0;
2421 result = WINPROC_CallWndProc( func, hwnd, msg32, wParam32, lParam );
2422 return WINPROC_UnmapMsg16To32A( hwnd, msg32, wParam32, lParam, result );
2425 /**********************************************************************
2426 * WINPROC_Thunk16To32A
2428 static LRESULT WINAPI WINPROC_Thunk16To32A( WNDPROC func, LPBYTE args )
2430 HWND16 hwnd = *(HWND16 *)( args+8 );
2431 UINT16 msg = *(HWND16 *)( args+6 );
2432 WPARAM16 wParam = *(HWND16 *)( args+4 );
2433 LPARAM lParam = *(LPARAM *)( args+0 );
2435 return WINPROC_CallProc16To32A( func, hwnd, msg, wParam, lParam );
2439 /**********************************************************************
2440 * WINPROC_CallProc16To32W
2442 * Call a 32-bit window procedure, translating the 16-bit args.
2444 static LRESULT WINPROC_CallProc16To32W( WNDPROC func, HWND16 hwnd,
2445 UINT16 msg, WPARAM16 wParam,
2446 LPARAM lParam )
2448 LRESULT result;
2449 UINT msg32;
2450 WPARAM wParam32;
2452 if (WINPROC_MapMsg16To32W( hwnd, msg, wParam, &msg32, &wParam32, &lParam ) == -1)
2453 return 0;
2455 result = WINPROC_CallWndProc( func, hwnd, msg32, wParam32, lParam );
2457 return WINPROC_UnmapMsg16To32W( hwnd, msg32, wParam32, lParam, result );
2460 /**********************************************************************
2461 * WINPROC_Thunk16To32W
2463 static LRESULT WINAPI WINPROC_Thunk16To32W( WNDPROC func, LPBYTE args )
2465 HWND16 hwnd = *(HWND16 *)( args+8 );
2466 UINT16 msg = *(HWND16 *)( args+6 );
2467 WPARAM16 wParam = *(HWND16 *)( args+4 );
2468 LPARAM lParam = *(LPARAM *)( args+0 );
2470 return WINPROC_CallProc16To32W( func, hwnd, msg, wParam, lParam );
2473 /**********************************************************************
2474 * WINPROC_CallProc32ATo16
2476 * Call a 16-bit window procedure, translating the 32-bit args.
2478 static LRESULT WINAPI WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd,
2479 UINT msg, WPARAM wParam,
2480 LPARAM lParam )
2482 UINT16 msg16;
2483 MSGPARAM16 mp16;
2485 mp16.lParam = lParam;
2486 if (WINPROC_MapMsg32ATo16( hwnd, msg, wParam,
2487 &msg16, &mp16.wParam, &mp16.lParam ) == -1)
2488 return 0;
2489 mp16.lResult = WINPROC_CallWndProc16( func, hwnd, msg16,
2490 mp16.wParam, mp16.lParam );
2491 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, &mp16 );
2492 return mp16.lResult;
2496 /**********************************************************************
2497 * WINPROC_CallProc32WTo16
2499 * Call a 16-bit window procedure, translating the 32-bit args.
2501 static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
2502 UINT msg, WPARAM wParam,
2503 LPARAM lParam )
2505 UINT16 msg16;
2506 MSGPARAM16 mp16;
2508 mp16.lParam = lParam;
2509 if (WINPROC_MapMsg32WTo16( hwnd, msg, wParam, &msg16, &mp16.wParam,
2510 &mp16.lParam ) == -1)
2511 return 0;
2512 mp16.lResult = WINPROC_CallWndProc16( func, hwnd, msg16,
2513 mp16.wParam, mp16.lParam );
2514 WINPROC_UnmapMsg32WTo16( hwnd, msg, wParam, lParam, &mp16 );
2515 return mp16.lResult;
2519 /**********************************************************************
2520 * CallWindowProc16 (USER.122)
2522 LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
2523 WPARAM16 wParam, LPARAM lParam )
2525 WINDOWPROC *proc = WINPROC_GetPtr( func );
2527 if (!proc)
2528 return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
2530 #if testing
2531 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_16 );
2532 return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
2533 #endif
2535 switch(proc->type)
2537 case WIN_PROC_16:
2538 if (!proc->thunk.t_from32.proc) return 0;
2539 return WINPROC_CallWndProc16( proc->thunk.t_from32.proc,
2540 hwnd, msg, wParam, lParam );
2541 case WIN_PROC_32A:
2542 if (!proc->thunk.t_from16.proc) return 0;
2543 return WINPROC_CallProc16To32A( proc->thunk.t_from16.proc,
2544 hwnd, msg, wParam, lParam );
2545 case WIN_PROC_32W:
2546 if (!proc->thunk.t_from16.proc) return 0;
2547 return WINPROC_CallProc16To32W( proc->thunk.t_from16.proc,
2548 hwnd, msg, wParam, lParam );
2549 default:
2550 WARN_(relay)("Invalid proc %p\n", proc );
2551 return 0;
2556 /**********************************************************************
2557 * CallWindowProcA (USER32.18)
2559 * The CallWindowProc() function invokes the windows procedure _func_,
2560 * with _hwnd_ as the target window, the message specified by _msg_, and
2561 * the message parameters _wParam_ and _lParam_.
2563 * Some kinds of argument conversion may be done, I'm not sure what.
2565 * CallWindowProc() may be used for windows subclassing. Use
2566 * SetWindowLong() to set a new windows procedure for windows of the
2567 * subclass, and handle subclassed messages in the new windows
2568 * procedure. The new windows procedure may then use CallWindowProc()
2569 * with _func_ set to the parent class's windows procedure to dispatch
2570 * the message to the superclass.
2572 * RETURNS
2574 * The return value is message dependent.
2576 * CONFORMANCE
2578 * ECMA-234, Win32
2580 LRESULT WINAPI CallWindowProcA(
2581 WNDPROC func, /* [in] window procedure */
2582 HWND hwnd, /* [in] target window */
2583 UINT msg, /* [in] message */
2584 WPARAM wParam, /* [in] message dependent parameter */
2585 LPARAM lParam /* [in] message dependent parameter */
2587 WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
2589 if (!proc) return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2591 #if testing
2592 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_32A );
2593 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2594 #endif
2596 switch(proc->type)
2598 case WIN_PROC_16:
2599 if (!proc->thunk.t_from32.proc) return 0;
2600 return WINPROC_CallProc32ATo16( proc->thunk.t_from32.proc,
2601 hwnd, msg, wParam, lParam );
2602 case WIN_PROC_32A:
2603 if (!proc->thunk.t_from16.proc) return 0;
2604 return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
2605 hwnd, msg, wParam, lParam );
2606 case WIN_PROC_32W:
2607 if (!proc->thunk.t_from16.proc) return 0;
2608 return WINPROC_CallProc32ATo32W( proc->thunk.t_from16.proc,
2609 hwnd, msg, wParam, lParam );
2610 default:
2611 WARN_(relay)("Invalid proc %p\n", proc );
2612 return 0;
2617 /**********************************************************************
2618 * CallWindowProcW (USER32.19)
2620 LRESULT WINAPI CallWindowProcW( WNDPROC func, HWND hwnd, UINT msg,
2621 WPARAM wParam, LPARAM lParam )
2623 WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
2625 if (!proc) return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2627 #if testing
2628 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_32W );
2629 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2630 #endif
2632 switch(proc->type)
2634 case WIN_PROC_16:
2635 if (!proc->thunk.t_from32.proc) return 0;
2636 return WINPROC_CallProc32WTo16( proc->thunk.t_from32.proc,
2637 hwnd, msg, wParam, lParam );
2638 case WIN_PROC_32A:
2639 if (!proc->thunk.t_from16.proc) return 0;
2640 return WINPROC_CallProc32WTo32A( proc->thunk.t_from16.proc,
2641 hwnd, msg, wParam, lParam );
2642 case WIN_PROC_32W:
2643 if (!proc->thunk.t_from16.proc) return 0;
2644 return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
2645 hwnd, msg, wParam, lParam );
2646 default:
2647 WARN_(relay)("Invalid proc %p\n", proc );
2648 return 0;