The [windows] section is in win.ini not in ~/.wine/config.
[wine.git] / windows / winproc.c
blob02191355f9d4dbb3465f3f2604c40bfc22d4abcd
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 "controls.h"
19 #include "heap.h"
20 #include "struct32.h"
21 #include "win.h"
22 #include "winproc.h"
23 #include "debugtools.h"
24 #include "spy.h"
25 #include "task.h"
26 #include "thread.h"
28 DECLARE_DEBUG_CHANNEL(msg);
29 DECLARE_DEBUG_CHANNEL(relay);
30 DECLARE_DEBUG_CHANNEL(win);
32 /* Window procedure 16-to-32-bit thunk,
33 * see BuildSpec16File() in tools/build.c */
35 #include "pshpack1.h"
36 typedef struct
38 WORD pushw_bp; /* pushw %bp */
39 BYTE pushl_func; /* pushl $proc */
40 WNDPROC proc;
41 WORD pushw_ax; /* pushw %ax */
42 BYTE pushl_relay; /* pushl $relay */
43 void (*relay)(); /* WINPROC_Thunk16To32A/W() */
44 BYTE lcall; /* lcall cs:glue */
45 void (*glue)(); /* __wine_call_from_16_long */
46 WORD cs; /* __FLATCS */
47 WORD lret; /* lret $10 */
48 WORD nArgs;
49 } WINPROC_THUNK_FROM16;
50 #include "poppack.h"
52 /* Window procedure 32-to-16-bit thunk,
53 * see BuildSpec32File() in tools/build.c */
55 typedef struct
57 BYTE popl_eax; /* popl %eax (return address) */
58 BYTE pushl_func; /* pushl $proc */
59 WNDPROC16 proc WINE_PACKED;
60 BYTE pushl_eax; /* pushl %eax */
61 BYTE jmp; /* jmp relay (relative jump)*/
62 void (*relay)() WINE_PACKED; /* WINPROC_CallProc32ATo16() */
63 } WINPROC_THUNK_FROM32;
65 /* Simple jmp to call 32-bit procedure directly */
66 typedef struct
68 BYTE jmp; /* jmp proc (relative jump) */
69 WNDPROC proc WINE_PACKED;
70 } WINPROC_JUMP;
72 typedef union
74 WINPROC_THUNK_FROM16 t_from16;
75 WINPROC_THUNK_FROM32 t_from32;
76 } WINPROC_THUNK;
78 typedef struct tagWINDOWPROC
80 WINPROC_THUNK thunk; /* Thunk */
81 WINPROC_JUMP jmp; /* Jump */
82 struct tagWINDOWPROC *next; /* Next window proc */
83 UINT magic; /* Magic number */
84 WINDOWPROCTYPE type; /* Function type */
85 WINDOWPROCUSER user; /* Function user */
86 } WINDOWPROC;
88 #define WINPROC_MAGIC ('W' | ('P' << 8) | ('R' << 16) | ('C' << 24))
90 #define WINPROC_THUNKPROC(pproc) \
91 (((pproc)->type == WIN_PROC_16) ? \
92 (WNDPROC16)((pproc)->thunk.t_from32.proc) : \
93 (WNDPROC16)((pproc)->thunk.t_from16.proc))
95 static LRESULT WINAPI WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd,
96 UINT msg, WPARAM wParam,
97 LPARAM lParam );
98 static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
99 UINT msg, WPARAM wParam,
100 LPARAM lParam );
101 static LRESULT WINAPI WINPROC_Thunk16To32A( WNDPROC func, LPBYTE args );
102 static LRESULT WINAPI WINPROC_Thunk16To32W( WNDPROC func, LPBYTE args );
104 static HANDLE WinProcHeap;
107 /**********************************************************************
108 * WINPROC_Init
110 BOOL WINPROC_Init(void)
112 WinProcHeap = HeapCreate( HEAP_WINE_SEGPTR | HEAP_WINE_CODESEG, 0, 0 );
113 if (!WinProcHeap)
115 WARN_(relay)("Unable to create winproc heap\n" );
116 return FALSE;
118 return TRUE;
122 #ifdef __i386__
123 /* Some window procedures modify register they shouldn't, or are not
124 * properly declared stdcall; so we need a small assembly wrapper to
125 * call them. */
126 extern LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
127 WPARAM wParam, LPARAM lParam );
128 __ASM_GLOBAL_FUNC( WINPROC_wrapper,
129 "pushl %ebp\n\t"
130 "movl %esp,%ebp\n\t"
131 "pushl %edi\n\t"
132 "pushl %esi\n\t"
133 "pushl %ebx\n\t"
134 "pushl 24(%ebp)\n\t"
135 "pushl 20(%ebp)\n\t"
136 "pushl 16(%ebp)\n\t"
137 "pushl 12(%ebp)\n\t"
138 "movl 8(%ebp),%eax\n\t"
139 "call *%eax\n\t"
140 "leal -12(%ebp),%esp\n\t"
141 "popl %ebx\n\t"
142 "popl %esi\n\t"
143 "popl %edi\n\t"
144 "leave\n\t"
145 "ret" );
146 #else
147 static inline LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
148 WPARAM wParam, LPARAM lParam )
150 return proc( hwnd, msg, wParam, lParam );
152 #endif /* __i386__ */
154 /**********************************************************************
155 * WINPROC_CallWndProc32
157 * Call a 32-bit WndProc.
159 static LRESULT WINPROC_CallWndProc( WNDPROC proc, HWND hwnd, UINT msg,
160 WPARAM wParam, LPARAM lParam )
162 LRESULT retvalue;
163 int iWndsLocks;
165 hwnd = WIN_GetFullHandle( hwnd );
166 if (TRACE_ON(relay))
167 DPRINTF( "%08lx:Call window proc %p (hwnd=%08x,msg=%s,wp=%08x,lp=%08lx)\n",
168 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), 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);
175 if (TRACE_ON(relay))
176 DPRINTF( "%08lx:Ret window proc %p (hwnd=%08x,msg=%s,wp=%08x,lp=%08lx) retval=%08lx\n",
177 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam, retvalue );
178 return retvalue;
181 /***********************************************************************
182 * WINPROC_CallWndProc16
184 * Call a 16-bit window procedure
186 static LRESULT WINAPI WINPROC_CallWndProc16( WNDPROC16 proc, HWND16 hwnd,
187 UINT16 msg, WPARAM16 wParam,
188 LPARAM lParam )
190 CONTEXT86 context;
191 LRESULT ret;
192 WORD *args;
193 WND *wndPtr = WIN_FindWndPtr( hwnd );
194 DWORD offset = 0;
195 TEB *teb = NtCurrentTeb();
196 int iWndsLocks;
198 /* Window procedures want ax = hInstance, ds = es = ss */
200 memset(&context, '\0', sizeof(context));
201 context.SegDs = context.SegEs = SELECTOROF(teb->cur_stack);
202 context.Eax = wndPtr ? wndPtr->hInstance : context.SegDs;
203 context.SegCs = SELECTOROF(proc);
204 context.Eip = OFFSETOF(proc);
205 context.Ebp = OFFSETOF(teb->cur_stack)
206 + (WORD)&((STACK16FRAME*)0)->bp;
208 WIN_ReleaseWndPtr(wndPtr);
210 if (lParam)
212 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
213 work if structures passed in lParam are placed in the stack/data
214 segment. Programmers easily make the mistake of converting lParam
215 to a near rather than a far pointer, since Windows apparently
216 allows this. We copy the structures to the 16 bit stack; this is
217 ugly but makes these programs work. */
218 switch (msg)
220 case WM_CREATE:
221 case WM_NCCREATE:
222 offset = sizeof(CREATESTRUCT16); break;
223 case WM_DRAWITEM:
224 offset = sizeof(DRAWITEMSTRUCT16); break;
225 case WM_COMPAREITEM:
226 offset = sizeof(COMPAREITEMSTRUCT16); break;
228 if (offset)
230 void *s = MapSL(lParam);
231 lParam = stack16_push( offset );
232 memcpy( MapSL(lParam), s, offset );
236 iWndsLocks = WIN_SuspendWndsLock();
238 args = (WORD *)THREAD_STACK16(teb) - 5;
239 args[0] = LOWORD(lParam);
240 args[1] = HIWORD(lParam);
241 args[2] = wParam;
242 args[3] = msg;
243 args[4] = hwnd;
245 wine_call_to_16_regs_short( &context, 5 * sizeof(WORD) );
246 ret = MAKELONG( LOWORD(context.Eax), LOWORD(context.Edx) );
247 if (offset) stack16_pop( offset );
249 WIN_RestoreWndsLock(iWndsLocks);
251 return ret;
255 /**********************************************************************
256 * WINPROC_GetPtr
258 * Return a pointer to the win proc.
260 static WINDOWPROC *WINPROC_GetPtr( WNDPROC16 handle )
262 BYTE *ptr;
263 WINDOWPROC *proc;
265 /* ptr cannot be < 64K */
266 if (!HIWORD(handle)) return NULL;
268 /* Check for a linear pointer */
270 ptr = (BYTE *)handle;
271 /* First check if it is the jmp address */
272 proc = (WINDOWPROC *)(ptr - (int)&((WINDOWPROC *)0)->jmp);
273 if (HeapValidate( WinProcHeap, 0, proc ) && (proc->magic == WINPROC_MAGIC))
274 return proc;
275 /* Now it must be the thunk address */
276 proc = (WINDOWPROC *)(ptr - (int)&((WINDOWPROC *)0)->thunk);
277 if (HeapValidate( WinProcHeap, 0, proc ) && (proc->magic == WINPROC_MAGIC))
278 return proc;
280 /* Check for a segmented pointer */
282 if (!IsBadReadPtr16( (SEGPTR)handle, sizeof(proc->thunk) ))
284 ptr = MapSL( (SEGPTR)handle );
285 /* It must be the thunk address */
286 proc = (WINDOWPROC *)(ptr - (int)&((WINDOWPROC *)0)->thunk);
287 if (HeapValidate( WinProcHeap, 0, proc ) && (proc->magic == WINPROC_MAGIC))
288 return proc;
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 = (WNDPROC)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 inline static BOOL WINPROC_TestCBForStr( HWND hwnd )
522 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
523 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
525 /**********************************************************************
526 * WINPROC_TestLBForStr
528 * Return TRUE if the lparam is a string
530 inline static BOOL WINPROC_TestLBForStr( HWND hwnd )
532 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
533 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
536 /**********************************************************************
537 * WINPROC_MapMsg32ATo32W
539 * Map a message from Ansi to Unicode.
540 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
542 * FIXME:
543 * WM_GETTEXT/WM_SETTEXT and static control with SS_ICON style:
544 * the first four bytes are the handle of the icon
545 * when the WM_SETTEXT message has been used to set the icon
547 INT WINPROC_MapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam )
549 switch(msg)
551 case WM_GETTEXT:
552 case WM_ASKCBFORMATNAME:
554 LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
555 *pwparam * sizeof(WCHAR) + sizeof(LPARAM) );
556 if (!ptr) return -1;
557 *ptr++ = *plparam; /* Store previous lParam */
558 *plparam = (LPARAM)ptr;
560 return 1;
561 /* lparam is string (0-terminated) */
562 case WM_SETTEXT:
563 case WM_WININICHANGE:
564 case WM_DEVMODECHANGE:
565 case CB_DIR:
566 case CB_FINDSTRING:
567 case CB_FINDSTRINGEXACT:
568 case CB_SELECTSTRING:
569 case LB_DIR:
570 case LB_ADDFILE:
571 case LB_FINDSTRING:
572 case LB_FINDSTRINGEXACT:
573 case LB_SELECTSTRING:
574 case EM_REPLACESEL:
575 if(!*plparam) return 0;
576 *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
577 return (*plparam ? 1 : -1);
578 case WM_GETTEXTLENGTH:
579 case CB_GETLBTEXTLEN:
580 case LB_GETTEXTLEN:
581 return 1; /* need to map result */
582 case WM_NCCREATE:
583 case WM_CREATE:
585 struct s
586 { CREATESTRUCTW cs; /* new structure */
587 LPCWSTR lpszName; /* allocated Name */
588 LPCWSTR lpszClass; /* allocated Class */
591 struct s *xs = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct s));
592 if (!xs) return -1;
593 xs->cs = *(CREATESTRUCTW *)*plparam;
594 if (HIWORD(xs->cs.lpszName))
595 xs->lpszName = xs->cs.lpszName = HEAP_strdupAtoW( GetProcessHeap(), 0,
596 (LPCSTR)xs->cs.lpszName );
597 if (HIWORD(xs->cs.lpszClass))
598 xs->lpszClass = xs->cs.lpszClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
599 (LPCSTR)xs->cs.lpszClass );
600 *plparam = (LPARAM)xs;
602 return 1;
603 case WM_MDICREATE:
605 MDICREATESTRUCTW *cs =
606 (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
607 if (!cs) return -1;
608 *cs = *(MDICREATESTRUCTW *)*plparam;
609 if (HIWORD(cs->szClass))
610 cs->szClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
611 (LPCSTR)cs->szClass );
612 if (HIWORD(cs->szTitle))
613 cs->szTitle = HEAP_strdupAtoW( GetProcessHeap(), 0,
614 (LPCSTR)cs->szTitle );
615 *plparam = (LPARAM)cs;
617 return 1;
619 /* Listbox */
620 case LB_ADDSTRING:
621 case LB_INSERTSTRING:
622 if(!*plparam) return 0;
623 if ( WINPROC_TestLBForStr( hwnd ))
624 *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
625 return (*plparam ? 1 : -1);
627 case LB_GETTEXT: /* fixme: fixed sized buffer */
628 { if ( WINPROC_TestLBForStr( hwnd ))
629 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
630 if (!ptr) return -1;
631 *ptr++ = *plparam; /* Store previous lParam */
632 *plparam = (LPARAM)ptr;
635 return 1;
637 /* Combobox */
638 case CB_ADDSTRING:
639 case CB_INSERTSTRING:
640 if(!*plparam) return 0;
641 if ( WINPROC_TestCBForStr( hwnd ))
642 *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
643 return (*plparam ? 1 : -1);
645 case CB_GETLBTEXT: /* fixme: fixed sized buffer */
646 { if ( WINPROC_TestCBForStr( hwnd ))
647 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
648 if (!ptr) return -1;
649 *ptr++ = *plparam; /* Store previous lParam */
650 *plparam = (LPARAM)ptr;
653 return 1;
655 /* Multiline edit */
656 case EM_GETLINE:
657 { WORD len = (WORD)*plparam;
658 LPARAM *ptr = (LPARAM *) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(WCHAR) );
659 if (!ptr) return -1;
660 *ptr++ = *plparam; /* Store previous lParam */
661 *((WORD *) ptr) = len; /* Store the length */
662 *plparam = (LPARAM)ptr;
664 return 1;
666 case WM_CHARTOITEM:
667 case WM_MENUCHAR:
668 case WM_CHAR:
669 case WM_DEADCHAR:
670 case WM_SYSCHAR:
671 case WM_SYSDEADCHAR:
672 case EM_SETPASSWORDCHAR:
674 char ch = LOWORD(*pwparam);
675 WCHAR wch;
676 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
677 *pwparam = MAKEWPARAM( wch, HIWORD(*pwparam) );
679 return 0;
681 case WM_PAINTCLIPBOARD:
682 case WM_SIZECLIPBOARD:
683 FIXME_(msg)("message %s (0x%x) needs translation, please report\n", SPY_GetMsgName(msg, hwnd), msg );
684 return -1;
685 default: /* No translation needed */
686 return 0;
691 /**********************************************************************
692 * WINPROC_UnmapMsg32ATo32W
694 * Unmap a message that was mapped from Ansi to Unicode.
696 LRESULT WINPROC_UnmapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
697 LRESULT result )
699 switch(msg)
701 case WM_GETTEXT:
702 case WM_ASKCBFORMATNAME:
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;
711 case WM_GETTEXTLENGTH:
712 case CB_GETLBTEXTLEN:
713 case LB_GETTEXTLEN:
714 /* there may be one DBCS char for each Unicode char */
715 return result * 2;
716 case WM_NCCREATE:
717 case WM_CREATE:
719 struct s
720 { CREATESTRUCTW cs; /* new structure */
721 LPWSTR lpszName; /* allocated Name */
722 LPWSTR lpszClass; /* allocated Class */
724 struct s *xs = (struct s *)lParam;
725 if (xs->lpszName) HeapFree( GetProcessHeap(), 0, xs->lpszName );
726 if (xs->lpszClass) HeapFree( GetProcessHeap(), 0, xs->lpszClass );
727 HeapFree( GetProcessHeap(), 0, xs );
729 break;
731 case WM_MDICREATE:
733 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
734 if (HIWORD(cs->szTitle))
735 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
736 if (HIWORD(cs->szClass))
737 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
738 HeapFree( GetProcessHeap(), 0, cs );
740 break;
742 case WM_SETTEXT:
743 case WM_WININICHANGE:
744 case WM_DEVMODECHANGE:
745 case CB_DIR:
746 case CB_FINDSTRING:
747 case CB_FINDSTRINGEXACT:
748 case CB_SELECTSTRING:
749 case LB_DIR:
750 case LB_ADDFILE:
751 case LB_FINDSTRING:
752 case LB_FINDSTRINGEXACT:
753 case LB_SELECTSTRING:
754 case EM_REPLACESEL:
755 HeapFree( GetProcessHeap(), 0, (void *)lParam );
756 break;
758 /* Listbox */
759 case LB_ADDSTRING:
760 case LB_INSERTSTRING:
761 if ( WINPROC_TestLBForStr( hwnd ))
762 HeapFree( GetProcessHeap(), 0, (void *)lParam );
763 break;
765 case LB_GETTEXT:
766 { if ( WINPROC_TestLBForStr( hwnd ))
767 { LPARAM *ptr = (LPARAM *)lParam - 1;
768 WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1, (LPSTR)*ptr, 0x7fffffff, NULL, NULL );
769 HeapFree( GetProcessHeap(), 0, ptr );
772 break;
774 /* Combobox */
775 case CB_ADDSTRING:
776 case CB_INSERTSTRING:
777 if ( WINPROC_TestCBForStr( hwnd ))
778 HeapFree( GetProcessHeap(), 0, (void *)lParam );
779 break;
781 case CB_GETLBTEXT:
782 { if ( WINPROC_TestCBForStr( hwnd ))
783 { LPARAM *ptr = (LPARAM *)lParam - 1;
784 WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1, (LPSTR)*ptr, 0x7fffffff, NULL, NULL );
785 HeapFree( GetProcessHeap(), 0, ptr );
788 break;
790 /* Multiline edit */
791 case EM_GETLINE:
792 { LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lParam */
793 WORD len = *(WORD *) lParam;
794 if (len > 0 && !WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
795 (LPSTR)*ptr, len, NULL, NULL ))
796 ((LPSTR)*ptr)[len-1] = 0;
797 HeapFree( GetProcessHeap(), 0, ptr );
799 break;
801 return result;
805 /**********************************************************************
806 * WINPROC_MapMsg32WTo32A
808 * Map a message from Unicode to Ansi.
809 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
811 INT WINPROC_MapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam )
813 switch(msg)
815 case WM_GETTEXT:
816 case WM_ASKCBFORMATNAME:
818 LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
819 *pwparam + sizeof(LPARAM) );
820 if (!ptr) return -1;
821 *ptr++ = *plparam; /* Store previous lParam */
822 *plparam = (LPARAM)ptr;
824 return 1;
826 case WM_SETTEXT:
827 case WM_WININICHANGE:
828 case WM_DEVMODECHANGE:
829 case CB_DIR:
830 case CB_FINDSTRING:
831 case CB_FINDSTRINGEXACT:
832 case CB_SELECTSTRING:
833 case LB_DIR:
834 case LB_ADDFILE:
835 case LB_FINDSTRING:
836 case LB_FINDSTRINGEXACT:
837 case LB_SELECTSTRING:
838 case EM_REPLACESEL:
839 if(!*plparam) return 0;
840 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
841 return (*plparam ? 1 : -1);
843 case WM_NCCREATE:
844 case WM_CREATE:
846 CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
847 sizeof(*cs) );
848 if (!cs) return -1;
849 *cs = *(CREATESTRUCTA *)*plparam;
850 if (HIWORD(cs->lpszName))
851 cs->lpszName = HEAP_strdupWtoA( GetProcessHeap(), 0,
852 (LPCWSTR)cs->lpszName );
853 if (HIWORD(cs->lpszClass))
854 cs->lpszClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
855 (LPCWSTR)cs->lpszClass);
856 *plparam = (LPARAM)cs;
858 return 1;
859 case WM_MDICREATE:
861 MDICREATESTRUCTA *cs =
862 (MDICREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
863 if (!cs) return -1;
864 *cs = *(MDICREATESTRUCTA *)*plparam;
865 if (HIWORD(cs->szTitle))
866 cs->szTitle = HEAP_strdupWtoA( GetProcessHeap(), 0,
867 (LPCWSTR)cs->szTitle );
868 if (HIWORD(cs->szClass))
869 cs->szClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
870 (LPCWSTR)cs->szClass );
871 *plparam = (LPARAM)cs;
873 return 1;
875 /* Listbox */
876 case LB_ADDSTRING:
877 case LB_INSERTSTRING:
878 if(!*plparam) return 0;
879 if ( WINPROC_TestLBForStr( hwnd ))
880 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
881 return (*plparam ? 1 : -1);
883 case LB_GETTEXT: /* fixme: fixed sized buffer */
884 { if ( WINPROC_TestLBForStr( hwnd ))
885 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
886 if (!ptr) return -1;
887 *ptr++ = *plparam; /* Store previous lParam */
888 *plparam = (LPARAM)ptr;
891 return 1;
893 /* Combobox */
894 case CB_ADDSTRING:
895 case CB_INSERTSTRING:
896 if(!*plparam) return 0;
897 if ( WINPROC_TestCBForStr( hwnd ))
898 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
899 return (*plparam ? 1 : -1);
901 case CB_GETLBTEXT: /* fixme: fixed sized buffer */
902 { if ( WINPROC_TestCBForStr( hwnd ))
903 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
904 if (!ptr) return -1;
905 *ptr++ = *plparam; /* Store previous lParam */
906 *plparam = (LPARAM)ptr;
909 return 1;
911 /* Multiline edit */
912 case EM_GETLINE:
913 { WORD len = (WORD)*plparam;
914 LPARAM *ptr = (LPARAM *) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(CHAR) );
915 if (!ptr) return -1;
916 *ptr++ = *plparam; /* Store previous lParam */
917 *((WORD *) ptr) = len; /* Store the length */
918 *plparam = (LPARAM)ptr;
920 return 1;
922 case WM_CHARTOITEM:
923 case WM_MENUCHAR:
924 case WM_CHAR:
925 case WM_DEADCHAR:
926 case WM_SYSCHAR:
927 case WM_SYSDEADCHAR:
928 case EM_SETPASSWORDCHAR:
930 WCHAR wch = LOWORD(*pwparam);
931 char ch;
932 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL );
933 *pwparam = MAKEWPARAM( ch, HIWORD(*pwparam) );
935 return 0;
937 case WM_PAINTCLIPBOARD:
938 case WM_SIZECLIPBOARD:
939 FIXME_(msg)("message %s (%04x) needs translation, please report\n",SPY_GetMsgName(msg, hwnd),msg );
940 return -1;
941 default: /* No translation needed */
942 return 0;
947 /**********************************************************************
948 * WINPROC_UnmapMsg32WTo32A
950 * Unmap a message that was mapped from Unicode to Ansi.
952 void WINPROC_UnmapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
954 switch(msg)
956 case WM_GETTEXT:
957 case WM_ASKCBFORMATNAME:
959 LPARAM *ptr = (LPARAM *)lParam - 1;
960 if (wParam)
962 if (!MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, wParam ))
963 ((LPWSTR)*ptr)[wParam-1] = 0;
965 HeapFree( GetProcessHeap(), 0, ptr );
967 break;
969 case WM_SETTEXT:
970 case WM_WININICHANGE:
971 case WM_DEVMODECHANGE:
972 case CB_DIR:
973 case CB_FINDSTRING:
974 case CB_FINDSTRINGEXACT:
975 case CB_SELECTSTRING:
976 case LB_DIR:
977 case LB_ADDFILE:
978 case LB_FINDSTRING:
979 case LB_FINDSTRINGEXACT:
980 case LB_SELECTSTRING:
981 case EM_REPLACESEL:
982 HeapFree( GetProcessHeap(), 0, (void *)lParam );
983 break;
985 case WM_NCCREATE:
986 case WM_CREATE:
988 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
989 if (HIWORD(cs->lpszName))
990 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszName );
991 if (HIWORD(cs->lpszClass))
992 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszClass );
993 HeapFree( GetProcessHeap(), 0, cs );
995 break;
997 case WM_MDICREATE:
999 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
1000 if (HIWORD(cs->szTitle))
1001 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
1002 if (HIWORD(cs->szClass))
1003 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
1004 HeapFree( GetProcessHeap(), 0, cs );
1006 break;
1008 /* Listbox */
1009 case LB_ADDSTRING:
1010 case LB_INSERTSTRING:
1011 if ( WINPROC_TestLBForStr( hwnd ))
1012 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1013 break;
1015 case LB_GETTEXT:
1016 if ( WINPROC_TestLBForStr( 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 /* Combobox */
1025 case CB_ADDSTRING:
1026 case CB_INSERTSTRING:
1027 if ( WINPROC_TestCBForStr( hwnd ))
1028 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1029 break;
1031 case CB_GETLBTEXT:
1032 if ( WINPROC_TestCBForStr( hwnd ))
1034 LPARAM *ptr = (LPARAM *)lParam - 1;
1035 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, 0x7fffffff );
1036 HeapFree( GetProcessHeap(), 0, ptr );
1038 break;
1040 /* Multiline edit */
1041 case EM_GETLINE:
1042 { LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lparam */
1043 WORD len = *(WORD *)ptr;
1044 if (len)
1046 if (!MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, len ))
1047 ((LPWSTR)*ptr)[len-1] = 0;
1049 HeapFree( GetProcessHeap(), 0, ptr );
1051 break;
1056 /**********************************************************************
1057 * WINPROC_MapMsg16To32A
1059 * Map a message from 16- to 32-bit Ansi.
1060 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1062 INT WINPROC_MapMsg16To32A( UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
1063 WPARAM *pwparam32, LPARAM *plparam )
1065 *pmsg32 = (UINT)msg16;
1066 *pwparam32 = (WPARAM)wParam16;
1067 switch(msg16)
1069 case WM_ACTIVATE:
1070 case WM_CHARTOITEM:
1071 case WM_COMMAND:
1072 case WM_VKEYTOITEM:
1073 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
1074 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1075 return 0;
1076 case WM_HSCROLL:
1077 case WM_VSCROLL:
1078 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1079 *plparam = (LPARAM)(HWND)HIWORD(*plparam);
1080 return 0;
1081 case WM_CTLCOLOR:
1082 if ( HIWORD(*plparam) > CTLCOLOR_STATIC ) return -1;
1083 *pmsg32 = WM_CTLCOLORMSGBOX + HIWORD(*plparam);
1084 *pwparam32 = (WPARAM)(HDC)wParam16;
1085 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1086 return 0;
1087 case WM_COMPAREITEM:
1089 COMPAREITEMSTRUCT16* cis16 = MapSL(*plparam);
1090 COMPAREITEMSTRUCT *cis = (COMPAREITEMSTRUCT *)
1091 HeapAlloc(GetProcessHeap(), 0, sizeof(*cis));
1092 if (!cis) return -1;
1093 cis->CtlType = cis16->CtlType;
1094 cis->CtlID = cis16->CtlID;
1095 cis->hwndItem = cis16->hwndItem;
1096 cis->itemID1 = cis16->itemID1;
1097 cis->itemData1 = cis16->itemData1;
1098 cis->itemID2 = cis16->itemID2;
1099 cis->itemData2 = cis16->itemData2;
1100 cis->dwLocaleId = 0; /* FIXME */
1101 *plparam = (LPARAM)cis;
1103 return 1;
1104 case WM_DELETEITEM:
1106 DELETEITEMSTRUCT16* dis16 = MapSL(*plparam);
1107 DELETEITEMSTRUCT *dis = (DELETEITEMSTRUCT *)
1108 HeapAlloc(GetProcessHeap(), 0, sizeof(*dis));
1109 if (!dis) return -1;
1110 dis->CtlType = dis16->CtlType;
1111 dis->CtlID = dis16->CtlID;
1112 dis->hwndItem = dis16->hwndItem;
1113 dis->itemData = dis16->itemData;
1114 *plparam = (LPARAM)dis;
1116 return 1;
1117 case WM_MEASUREITEM:
1119 MEASUREITEMSTRUCT16* mis16 = MapSL(*plparam);
1120 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)
1121 HeapAlloc(GetProcessHeap(), 0,
1122 sizeof(*mis) + sizeof(LPARAM));
1123 if (!mis) return -1;
1124 mis->CtlType = mis16->CtlType;
1125 mis->CtlID = mis16->CtlID;
1126 mis->itemID = mis16->itemID;
1127 mis->itemWidth = mis16->itemWidth;
1128 mis->itemHeight = mis16->itemHeight;
1129 mis->itemData = mis16->itemData;
1130 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
1131 *plparam = (LPARAM)mis;
1133 return 1;
1134 case WM_DRAWITEM:
1136 DRAWITEMSTRUCT16* dis16 = MapSL(*plparam);
1137 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT*)HeapAlloc(GetProcessHeap(), 0,
1138 sizeof(*dis));
1139 if (!dis) return -1;
1140 dis->CtlType = dis16->CtlType;
1141 dis->CtlID = dis16->CtlID;
1142 dis->itemID = dis16->itemID;
1143 dis->itemAction = dis16->itemAction;
1144 dis->itemState = dis16->itemState;
1145 dis->hwndItem = dis16->hwndItem;
1146 dis->hDC = dis16->hDC;
1147 dis->itemData = dis16->itemData;
1148 CONV_RECT16TO32( &dis16->rcItem, &dis->rcItem );
1149 *plparam = (LPARAM)dis;
1151 return 1;
1152 case WM_GETMINMAXINFO:
1154 MINMAXINFO *mmi = (MINMAXINFO *)HeapAlloc( GetProcessHeap(), 0,
1155 sizeof(*mmi) + sizeof(LPARAM));
1156 if (!mmi) return -1;
1157 STRUCT32_MINMAXINFO16to32( MapSL(*plparam), mmi );
1158 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
1159 *plparam = (LPARAM)mmi;
1161 return 1;
1162 case WM_GETTEXT:
1163 case WM_SETTEXT:
1164 case WM_WININICHANGE:
1165 case WM_DEVMODECHANGE:
1166 case WM_ASKCBFORMATNAME:
1167 *plparam = (LPARAM)MapSL(*plparam);
1168 return 0;
1169 case WM_MDICREATE:
1171 MDICREATESTRUCT16 *cs16 = MapSL(*plparam);
1172 MDICREATESTRUCTA *cs = HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) + sizeof(LPARAM) );
1173 if (!cs) return -1;
1174 STRUCT32_MDICREATESTRUCT16to32A( cs16, cs );
1175 cs->szTitle = MapSL(cs16->szTitle);
1176 cs->szClass = MapSL(cs16->szClass);
1177 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1178 *plparam = (LPARAM)cs;
1180 return 1;
1181 case WM_MDIGETACTIVE:
1182 *plparam = (LPARAM)HeapAlloc( GetProcessHeap(), 0, sizeof(BOOL) );
1183 *(BOOL*)(*plparam) = 0;
1184 return 1;
1185 case WM_MDISETMENU:
1186 if(wParam16==TRUE)
1187 *pmsg32=WM_MDIREFRESHMENU;
1188 *pwparam32 = (WPARAM)(HMENU)LOWORD(*plparam);
1189 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1190 return 0;
1191 case WM_MENUCHAR:
1192 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1193 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1194 return 0;
1195 case WM_MENUSELECT:
1196 if((LOWORD(*plparam) & MF_POPUP) && (LOWORD(*plparam) != 0xFFFF))
1198 HMENU hmenu=(HMENU)HIWORD(*plparam);
1199 UINT Pos=MENU_FindSubMenu( &hmenu, wParam16);
1200 if(Pos==0xFFFF) Pos=0; /* NO_SELECTED_ITEM */
1201 *pwparam32 = MAKEWPARAM( Pos, LOWORD(*plparam) );
1203 else *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1204 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1205 return 0;
1206 case WM_MDIACTIVATE:
1207 if( *plparam )
1209 *pwparam32 = (WPARAM)(HWND)HIWORD(*plparam);
1210 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1212 else /* message sent to MDI client */
1213 *pwparam32 = wParam16;
1214 return 0;
1215 case WM_NCCALCSIZE:
1217 NCCALCSIZE_PARAMS16 *nc16;
1218 NCCALCSIZE_PARAMS *nc;
1220 nc = (NCCALCSIZE_PARAMS *)HeapAlloc( GetProcessHeap(), 0,
1221 sizeof(*nc) + sizeof(LPARAM) );
1222 if (!nc) return -1;
1223 nc16 = MapSL(*plparam);
1224 CONV_RECT16TO32( &nc16->rgrc[0], &nc->rgrc[0] );
1225 if (wParam16)
1227 nc->lppos = (WINDOWPOS *)HeapAlloc( GetProcessHeap(), 0,
1228 sizeof(*nc->lppos) );
1229 CONV_RECT16TO32( &nc16->rgrc[1], &nc->rgrc[1] );
1230 CONV_RECT16TO32( &nc16->rgrc[2], &nc->rgrc[2] );
1231 if (nc->lppos) STRUCT32_WINDOWPOS16to32( MapSL(nc16->lppos), nc->lppos );
1233 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
1234 *plparam = (LPARAM)nc;
1236 return 1;
1237 case WM_NCCREATE:
1238 case WM_CREATE:
1240 CREATESTRUCT16 *cs16 = MapSL(*plparam);
1241 CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
1242 sizeof(*cs) + sizeof(LPARAM) );
1243 if (!cs) return -1;
1244 STRUCT32_CREATESTRUCT16to32A( cs16, cs );
1245 cs->lpszName = MapSL(cs16->lpszName);
1246 cs->lpszClass = MapSL(cs16->lpszClass);
1247 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1248 *plparam = (LPARAM)cs;
1250 return 1;
1251 case WM_PARENTNOTIFY:
1252 if ((wParam16 == WM_CREATE) || (wParam16 == WM_DESTROY))
1254 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
1255 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1257 return 0;
1258 case WM_WINDOWPOSCHANGING:
1259 case WM_WINDOWPOSCHANGED:
1261 WINDOWPOS *wp = (WINDOWPOS *)HeapAlloc( GetProcessHeap(), 0,
1262 sizeof(*wp) + sizeof(LPARAM) );
1263 if (!wp) return -1;
1264 STRUCT32_WINDOWPOS16to32( MapSL(*plparam), wp );
1265 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
1266 *plparam = (LPARAM)wp;
1268 return 1;
1269 case WM_GETDLGCODE:
1270 if (*plparam)
1272 LPMSG16 msg16 = MapSL(*plparam);
1273 LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1275 if (!msg32) return -1;
1276 msg32->hwnd = msg16->hwnd;
1277 msg32->lParam = msg16->lParam;
1278 msg32->time = msg16->time;
1279 CONV_POINT16TO32(&msg16->pt,&msg32->pt);
1280 /* this is right, right? */
1281 if (WINPROC_MapMsg16To32A(msg16->message,msg16->wParam,
1282 &msg32->message,&msg32->wParam,
1283 &msg32->lParam)<0) {
1284 HeapFree( GetProcessHeap(), 0, msg32 );
1285 return -1;
1287 *plparam = (LPARAM)msg32;
1288 return 1;
1290 else return 0;
1291 case WM_NOTIFY:
1292 *plparam = (LPARAM)MapSL(*plparam);
1293 return 0;
1294 case WM_ACTIVATEAPP:
1295 if (*plparam)
1296 { /* We need this when SetActiveWindow sends a Sendmessage16() to
1297 a 32bit window. Might be superflous with 32bit interprocess
1298 message queues.
1300 HTASK16 htask = (HTASK16) *plparam;
1301 DWORD idThread = (DWORD)TASK_GetPtr(htask)->teb->tid;
1302 *plparam = (LPARAM) idThread;
1304 return 0;
1305 case WM_NEXTMENU:
1307 MDINEXTMENU *next = HeapAlloc( GetProcessHeap(), 0, sizeof(*next) );
1308 if (!next) return -1;
1309 next->hmenuIn = *plparam;
1310 next->hmenuNext = 0;
1311 next->hwndNext = 0;
1312 *plparam = (LPARAM)next;
1313 return 1;
1315 case WM_PAINTCLIPBOARD:
1316 case WM_SIZECLIPBOARD:
1317 FIXME_(msg)("message %04x needs translation\n",msg16 );
1318 return -1;
1320 default: /* No translation needed */
1321 return 0;
1326 /**********************************************************************
1327 * WINPROC_UnmapMsg16To32A
1329 * Unmap a message that was mapped from 16- to 32-bit Ansi.
1331 LRESULT WINPROC_UnmapMsg16To32A( HWND16 hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1332 LRESULT result )
1334 switch(msg)
1336 case WM_COMPAREITEM:
1337 case WM_DELETEITEM:
1338 case WM_DRAWITEM:
1339 HeapFree( GetProcessHeap(), 0, (LPVOID)lParam );
1340 break;
1341 case WM_MEASUREITEM:
1343 MEASUREITEMSTRUCT16 *mis16;
1344 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lParam;
1345 lParam = *(LPARAM *)(mis + 1);
1346 mis16 = MapSL(lParam);
1347 mis16->itemWidth = (UINT16)mis->itemWidth;
1348 mis16->itemHeight = (UINT16)mis->itemHeight;
1349 HeapFree( GetProcessHeap(), 0, mis );
1351 break;
1352 case WM_GETMINMAXINFO:
1354 MINMAXINFO *mmi = (MINMAXINFO *)lParam;
1355 lParam = *(LPARAM *)(mmi + 1);
1356 STRUCT32_MINMAXINFO32to16( mmi, MapSL(lParam));
1357 HeapFree( GetProcessHeap(), 0, mmi );
1359 break;
1360 case WM_MDICREATE:
1362 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
1363 lParam = *(LPARAM *)(cs + 1);
1364 STRUCT32_MDICREATESTRUCT32Ato16( cs, MapSL(lParam) );
1365 HeapFree( GetProcessHeap(), 0, cs );
1367 break;
1368 case WM_MDIGETACTIVE:
1369 result = MAKELONG( LOWORD(result), (BOOL16)(*(BOOL *)lParam) );
1370 HeapFree( GetProcessHeap(), 0, (BOOL *)lParam );
1371 break;
1372 case WM_NCCALCSIZE:
1374 NCCALCSIZE_PARAMS16 *nc16;
1375 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lParam;
1376 lParam = *(LPARAM *)(nc + 1);
1377 nc16 = MapSL(lParam);
1378 CONV_RECT32TO16( &nc->rgrc[0], &nc16->rgrc[0] );
1379 if (wParam)
1381 CONV_RECT32TO16( &nc->rgrc[1], &nc16->rgrc[1] );
1382 CONV_RECT32TO16( &nc->rgrc[2], &nc16->rgrc[2] );
1383 if (nc->lppos)
1385 STRUCT32_WINDOWPOS32to16( nc->lppos, MapSL(nc16->lppos));
1386 HeapFree( GetProcessHeap(), 0, nc->lppos );
1389 HeapFree( GetProcessHeap(), 0, nc );
1391 break;
1392 case WM_NCCREATE:
1393 case WM_CREATE:
1395 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
1396 lParam = *(LPARAM *)(cs + 1);
1397 STRUCT32_CREATESTRUCT32Ato16( cs, MapSL(lParam) );
1398 HeapFree( GetProcessHeap(), 0, cs );
1400 break;
1401 case WM_WINDOWPOSCHANGING:
1402 case WM_WINDOWPOSCHANGED:
1404 WINDOWPOS *wp = (WINDOWPOS *)lParam;
1405 lParam = *(LPARAM *)(wp + 1);
1406 STRUCT32_WINDOWPOS32to16(wp, MapSL(lParam));
1407 HeapFree( GetProcessHeap(), 0, wp );
1409 break;
1410 case WM_GETDLGCODE:
1411 if (lParam)
1413 LPMSG msg32 = (LPMSG)lParam;
1415 WINPROC_UnmapMsg16To32A( hwnd, msg32->message, msg32->wParam, msg32->lParam,
1416 result);
1417 HeapFree( GetProcessHeap(), 0, msg32 );
1419 break;
1420 case WM_NEXTMENU:
1422 MDINEXTMENU *next = (MDINEXTMENU *)lParam;
1423 result = MAKELONG( next->hmenuNext, next->hwndNext );
1424 HeapFree( GetProcessHeap(), 0, next );
1426 break;
1428 return result;
1432 /**********************************************************************
1433 * WINPROC_MapMsg16To32W
1435 * Map a message from 16- to 32-bit Unicode.
1436 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1438 INT WINPROC_MapMsg16To32W( HWND16 hwnd, UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
1439 WPARAM *pwparam32, LPARAM *plparam )
1441 char ch;
1442 WCHAR wch;
1444 *pmsg32=(UINT)msg16;
1445 *pwparam32 = (WPARAM)wParam16;
1446 switch(msg16)
1448 case WM_GETTEXT:
1449 case WM_SETTEXT:
1450 case WM_WININICHANGE:
1451 case WM_DEVMODECHANGE:
1452 case WM_ASKCBFORMATNAME:
1453 *plparam = (LPARAM)MapSL(*plparam);
1454 return WINPROC_MapMsg32ATo32W( hwnd, *pmsg32, pwparam32, plparam );
1455 case WM_GETTEXTLENGTH:
1456 case CB_GETLBTEXTLEN:
1457 case LB_GETTEXTLEN:
1458 return 1; /* need to map result */
1459 case WM_NCCREATE:
1460 case WM_CREATE:
1462 CREATESTRUCT16 *cs16 = MapSL(*plparam);
1463 CREATESTRUCTW *cs = (CREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
1464 sizeof(*cs) + sizeof(LPARAM) );
1465 if (!cs) return -1;
1466 STRUCT32_CREATESTRUCT16to32A( cs16, (CREATESTRUCTA *)cs );
1467 cs->lpszName = MapSL(cs16->lpszName);
1468 cs->lpszClass = MapSL(cs16->lpszClass);
1469 if (HIWORD(cs->lpszName))
1470 cs->lpszName = HEAP_strdupAtoW( GetProcessHeap(), 0,
1471 (LPCSTR)cs->lpszName );
1472 if (HIWORD(cs->lpszClass))
1473 cs->lpszClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
1474 (LPCSTR)cs->lpszClass );
1475 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1476 *plparam = (LPARAM)cs;
1478 return 1;
1479 case WM_MDICREATE:
1481 MDICREATESTRUCT16 *cs16 = MapSL(*plparam);
1482 MDICREATESTRUCTW *cs =
1483 (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
1484 sizeof(*cs) + sizeof(LPARAM) );
1485 if (!cs) return -1;
1486 STRUCT32_MDICREATESTRUCT16to32A( cs16, (MDICREATESTRUCTA *)cs );
1487 cs->szTitle = MapSL(cs16->szTitle);
1488 cs->szClass = MapSL(cs16->szClass);
1489 if (HIWORD(cs->szTitle))
1490 cs->szTitle = HEAP_strdupAtoW( GetProcessHeap(), 0,
1491 (LPCSTR)cs->szTitle );
1492 if (HIWORD(cs->szClass))
1493 cs->szClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
1494 (LPCSTR)cs->szClass );
1495 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1496 *plparam = (LPARAM)cs;
1498 return 1;
1499 case WM_GETDLGCODE:
1500 if (*plparam)
1502 LPMSG16 msg16 = MapSL(*plparam);
1503 LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1505 if (!msg32) return -1;
1506 msg32->hwnd = msg16->hwnd;
1507 msg32->lParam = msg16->lParam;
1508 msg32->time = msg16->time;
1509 CONV_POINT16TO32(&msg16->pt,&msg32->pt);
1510 /* this is right, right? */
1511 if (WINPROC_MapMsg16To32W(hwnd, msg16->message,msg16->wParam,
1512 &msg32->message,&msg32->wParam,
1513 &msg32->lParam)<0) {
1514 HeapFree( GetProcessHeap(), 0, msg32 );
1515 return -1;
1517 *plparam = (LPARAM)msg32;
1518 return 1;
1520 else return 0;
1522 case WM_CHARTOITEM:
1523 ch = wParam16;
1524 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1525 *pwparam32 = MAKEWPARAM( wch, HIWORD(*plparam) );
1526 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1527 return 0;
1528 case WM_MENUCHAR:
1529 ch = wParam16;
1530 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1531 *pwparam32 = MAKEWPARAM( wch, LOWORD(*plparam) );
1532 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1533 return 0;
1534 case WM_CHAR:
1535 case WM_DEADCHAR:
1536 case WM_SYSCHAR:
1537 case WM_SYSDEADCHAR:
1538 ch = wParam16;
1539 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1540 *pwparam32 = wch;
1541 return 0;
1543 default: /* No Unicode translation needed */
1544 return WINPROC_MapMsg16To32A( msg16, wParam16, pmsg32,
1545 pwparam32, plparam );
1550 /**********************************************************************
1551 * WINPROC_UnmapMsg16To32W
1553 * Unmap a message that was mapped from 16- to 32-bit Unicode.
1555 LRESULT WINPROC_UnmapMsg16To32W( HWND16 hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1556 LRESULT result )
1558 switch(msg)
1560 case WM_GETTEXT:
1561 case WM_SETTEXT:
1562 case WM_GETTEXTLENGTH:
1563 case CB_GETLBTEXTLEN:
1564 case LB_GETTEXTLEN:
1565 case WM_ASKCBFORMATNAME:
1566 return WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam, result );
1567 case WM_NCCREATE:
1568 case WM_CREATE:
1570 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
1571 lParam = *(LPARAM *)(cs + 1);
1572 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs, MapSL(lParam) );
1573 if (HIWORD(cs->lpszName))
1574 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszName );
1575 if (HIWORD(cs->lpszClass))
1576 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszClass );
1577 HeapFree( GetProcessHeap(), 0, cs );
1579 break;
1580 case WM_MDICREATE:
1582 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
1583 lParam = *(LPARAM *)(cs + 1);
1584 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs, MapSL(lParam) );
1585 if (HIWORD(cs->szTitle))
1586 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
1587 if (HIWORD(cs->szClass))
1588 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
1589 HeapFree( GetProcessHeap(), 0, cs );
1591 break;
1592 case WM_GETDLGCODE:
1593 if (lParam)
1595 LPMSG msg32 = (LPMSG)lParam;
1597 WINPROC_UnmapMsg16To32W( hwnd, msg32->message, msg32->wParam, msg32->lParam,
1598 result);
1599 HeapFree( GetProcessHeap(), 0, msg32 );
1601 break;
1602 default:
1603 return WINPROC_UnmapMsg16To32A( hwnd, msg, wParam, lParam, result );
1605 return result;
1609 /**********************************************************************
1610 * WINPROC_MapMsg32ATo16
1612 * Map a message from 32-bit Ansi to 16-bit.
1613 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1615 INT WINPROC_MapMsg32ATo16( HWND hwnd, UINT msg32, WPARAM wParam32,
1616 UINT16 *pmsg16, WPARAM16 *pwparam16,
1617 LPARAM *plparam )
1619 *pmsg16 = (UINT16)msg32;
1620 *pwparam16 = (WPARAM16)LOWORD(wParam32);
1621 switch(msg32)
1623 case BM_GETCHECK:
1624 case BM_SETCHECK:
1625 case BM_GETSTATE:
1626 case BM_SETSTATE:
1627 case BM_SETSTYLE:
1628 *pmsg16 = (UINT16)msg32 + (BM_GETCHECK16 - BM_GETCHECK);
1629 return 0;
1631 case EM_GETSEL:
1632 case EM_GETRECT:
1633 case EM_SETRECT:
1634 case EM_SETRECTNP:
1635 case EM_SCROLL:
1636 case EM_LINESCROLL:
1637 case EM_SCROLLCARET:
1638 case EM_GETMODIFY:
1639 case EM_SETMODIFY:
1640 case EM_GETLINECOUNT:
1641 case EM_LINEINDEX:
1642 case EM_SETHANDLE:
1643 case EM_GETHANDLE:
1644 case EM_GETTHUMB:
1645 case EM_LINELENGTH:
1646 case EM_REPLACESEL:
1647 case EM_GETLINE:
1648 case EM_LIMITTEXT:
1649 case EM_CANUNDO:
1650 case EM_UNDO:
1651 case EM_FMTLINES:
1652 case EM_LINEFROMCHAR:
1653 case EM_SETTABSTOPS:
1654 case EM_SETPASSWORDCHAR:
1655 case EM_EMPTYUNDOBUFFER:
1656 case EM_GETFIRSTVISIBLELINE:
1657 case EM_SETREADONLY:
1658 case EM_SETWORDBREAKPROC:
1659 case EM_GETWORDBREAKPROC:
1660 case EM_GETPASSWORDCHAR:
1661 *pmsg16 = (UINT16)msg32 + (EM_GETSEL16 - EM_GETSEL);
1662 return 0;
1664 case LB_CARETOFF:
1665 case LB_CARETON:
1666 case LB_DELETESTRING:
1667 case LB_GETANCHORINDEX:
1668 case LB_GETCARETINDEX:
1669 case LB_GETCOUNT:
1670 case LB_GETCURSEL:
1671 case LB_GETHORIZONTALEXTENT:
1672 case LB_GETITEMDATA:
1673 case LB_GETITEMHEIGHT:
1674 case LB_GETSEL:
1675 case LB_GETSELCOUNT:
1676 case LB_GETTEXTLEN:
1677 case LB_GETTOPINDEX:
1678 case LB_RESETCONTENT:
1679 case LB_SELITEMRANGE:
1680 case LB_SELITEMRANGEEX:
1681 case LB_SETANCHORINDEX:
1682 case LB_SETCARETINDEX:
1683 case LB_SETCOLUMNWIDTH:
1684 case LB_SETCURSEL:
1685 case LB_SETHORIZONTALEXTENT:
1686 case LB_SETITEMDATA:
1687 case LB_SETITEMHEIGHT:
1688 case LB_SETSEL:
1689 case LB_SETTOPINDEX:
1690 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
1691 return 0;
1692 case CB_DELETESTRING:
1693 case CB_GETCOUNT:
1694 case CB_GETLBTEXTLEN:
1695 case CB_LIMITTEXT:
1696 case CB_RESETCONTENT:
1697 case CB_SETEDITSEL:
1698 case CB_GETCURSEL:
1699 case CB_SETCURSEL:
1700 case CB_SHOWDROPDOWN:
1701 case CB_SETITEMDATA:
1702 case CB_SETITEMHEIGHT:
1703 case CB_GETITEMHEIGHT:
1704 case CB_SETEXTENDEDUI:
1705 case CB_GETEXTENDEDUI:
1706 case CB_GETDROPPEDSTATE:
1707 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
1708 return 0;
1709 case CB_GETEDITSEL:
1710 *pmsg16 = CB_GETEDITSEL16;
1711 return 1;
1713 case LB_ADDSTRING:
1714 case LB_FINDSTRING:
1715 case LB_FINDSTRINGEXACT:
1716 case LB_INSERTSTRING:
1717 case LB_SELECTSTRING:
1718 case LB_DIR:
1719 case LB_ADDFILE:
1721 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
1722 if (!str) return -1;
1723 *plparam = (LPARAM)SEGPTR_GET(str);
1725 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
1726 return 1;
1728 case CB_ADDSTRING:
1729 case CB_FINDSTRING:
1730 case CB_FINDSTRINGEXACT:
1731 case CB_INSERTSTRING:
1732 case CB_SELECTSTRING:
1733 case CB_DIR:
1735 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
1736 if (!str) return -1;
1737 *plparam = (LPARAM)SEGPTR_GET(str);
1739 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
1740 return 1;
1742 case LB_GETITEMRECT:
1744 RECT16 *rect;
1745 rect = (RECT16 *)SEGPTR_ALLOC( sizeof(RECT16) + sizeof(LPARAM) );
1746 if (!rect) return -1;
1747 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
1748 *plparam = (LPARAM)SEGPTR_GET(rect);
1750 *pmsg16 = LB_GETITEMRECT16;
1751 return 1;
1752 case LB_GETSELITEMS:
1754 LPINT16 items;
1755 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
1756 if (!(items = SEGPTR_ALLOC( *pwparam16 * sizeof(INT16)
1757 + sizeof(LPARAM)))) return -1;
1758 *((LPARAM *)items)++ = *plparam; /* Store the previous lParam */
1759 *plparam = (LPARAM)SEGPTR_GET(items);
1761 *pmsg16 = LB_GETSELITEMS16;
1762 return 1;
1763 case LB_SETTABSTOPS:
1764 if (wParam32)
1766 INT i;
1767 LPINT16 stops;
1768 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
1769 if (!(stops = SEGPTR_ALLOC( *pwparam16 * sizeof(INT16)
1770 + sizeof(LPARAM)))) return -1;
1771 for (i = 0; i < *pwparam16; i++) stops[i] = *((LPINT)*plparam+i);
1772 *plparam = (LPARAM)SEGPTR_GET(stops);
1773 return 1;
1775 *pmsg16 = LB_SETTABSTOPS16;
1776 return 0;
1778 case CB_GETDROPPEDCONTROLRECT:
1780 RECT16 *rect;
1781 rect = (RECT16 *)SEGPTR_ALLOC( sizeof(RECT16) + sizeof(LPARAM) );
1782 if (!rect) return -1;
1783 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
1784 *plparam = (LPARAM)SEGPTR_GET(rect);
1786 *pmsg16 = CB_GETDROPPEDCONTROLRECT16;
1787 return 1;
1789 case LB_GETTEXT:
1790 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
1791 *pmsg16 = LB_GETTEXT16;
1792 return 1;
1794 case CB_GETLBTEXT:
1795 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
1796 *pmsg16 = CB_GETLBTEXT16;
1797 return 1;
1799 case EM_SETSEL:
1800 *pwparam16 = 0;
1801 *plparam = MAKELONG( (INT16)(INT)wParam32, (INT16)*plparam );
1802 *pmsg16 = EM_SETSEL16;
1803 return 0;
1805 case WM_ACTIVATE:
1806 case WM_CHARTOITEM:
1807 case WM_COMMAND:
1808 case WM_VKEYTOITEM:
1809 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
1810 return 0;
1811 case WM_HSCROLL:
1812 case WM_VSCROLL:
1813 *plparam = MAKELPARAM( HIWORD(wParam32), (HWND16)*plparam );
1814 return 0;
1815 case WM_CTLCOLORMSGBOX:
1816 case WM_CTLCOLOREDIT:
1817 case WM_CTLCOLORLISTBOX:
1818 case WM_CTLCOLORBTN:
1819 case WM_CTLCOLORDLG:
1820 case WM_CTLCOLORSCROLLBAR:
1821 case WM_CTLCOLORSTATIC:
1822 *pmsg16 = WM_CTLCOLOR;
1823 *plparam = MAKELPARAM( (HWND16)*plparam,
1824 (WORD)msg32 - WM_CTLCOLORMSGBOX );
1825 return 0;
1826 case WM_COMPAREITEM:
1828 COMPAREITEMSTRUCT *cis32 = (COMPAREITEMSTRUCT *)*plparam;
1829 COMPAREITEMSTRUCT16 *cis = SEGPTR_NEW(COMPAREITEMSTRUCT16);
1830 if (!cis) return -1;
1831 cis->CtlType = (UINT16)cis32->CtlType;
1832 cis->CtlID = (UINT16)cis32->CtlID;
1833 cis->hwndItem = (HWND16)cis32->hwndItem;
1834 cis->itemID1 = (UINT16)cis32->itemID1;
1835 cis->itemData1 = cis32->itemData1;
1836 cis->itemID2 = (UINT16)cis32->itemID2;
1837 cis->itemData2 = cis32->itemData2;
1838 *plparam = (LPARAM)SEGPTR_GET(cis);
1840 return 1;
1841 case WM_DELETEITEM:
1843 DELETEITEMSTRUCT *dis32 = (DELETEITEMSTRUCT *)*plparam;
1844 DELETEITEMSTRUCT16 *dis = SEGPTR_NEW(DELETEITEMSTRUCT16);
1845 if (!dis) return -1;
1846 dis->CtlType = (UINT16)dis32->CtlType;
1847 dis->CtlID = (UINT16)dis32->CtlID;
1848 dis->itemID = (UINT16)dis32->itemID;
1849 dis->hwndItem = (HWND16)dis32->hwndItem;
1850 dis->itemData = dis32->itemData;
1851 *plparam = (LPARAM)SEGPTR_GET(dis);
1853 return 1;
1854 case WM_DRAWITEM:
1856 DRAWITEMSTRUCT *dis32 = (DRAWITEMSTRUCT *)*plparam;
1857 DRAWITEMSTRUCT16 *dis = SEGPTR_NEW(DRAWITEMSTRUCT16);
1858 if (!dis) return -1;
1859 dis->CtlType = (UINT16)dis32->CtlType;
1860 dis->CtlID = (UINT16)dis32->CtlID;
1861 dis->itemID = (UINT16)dis32->itemID;
1862 dis->itemAction = (UINT16)dis32->itemAction;
1863 dis->itemState = (UINT16)dis32->itemState;
1864 dis->hwndItem = (HWND16)dis32->hwndItem;
1865 dis->hDC = (HDC16)dis32->hDC;
1866 dis->itemData = dis32->itemData;
1867 CONV_RECT32TO16( &dis32->rcItem, &dis->rcItem );
1868 *plparam = (LPARAM)SEGPTR_GET(dis);
1870 return 1;
1871 case WM_MEASUREITEM:
1873 MEASUREITEMSTRUCT *mis32 = (MEASUREITEMSTRUCT *)*plparam;
1874 MEASUREITEMSTRUCT16 *mis = (MEASUREITEMSTRUCT16 *)
1875 SEGPTR_ALLOC(sizeof(*mis)+sizeof(LPARAM));
1876 if (!mis) return -1;
1877 mis->CtlType = (UINT16)mis32->CtlType;
1878 mis->CtlID = (UINT16)mis32->CtlID;
1879 mis->itemID = (UINT16)mis32->itemID;
1880 mis->itemWidth = (UINT16)mis32->itemWidth;
1881 mis->itemHeight = (UINT16)mis32->itemHeight;
1882 mis->itemData = mis32->itemData;
1883 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
1884 *plparam = (LPARAM)SEGPTR_GET(mis);
1886 return 1;
1887 case WM_GETMINMAXINFO:
1889 MINMAXINFO16 *mmi = (MINMAXINFO16 *)SEGPTR_ALLOC( sizeof(*mmi) +
1890 sizeof(LPARAM) );
1891 if (!mmi) return -1;
1892 STRUCT32_MINMAXINFO32to16( (MINMAXINFO *)*plparam, mmi );
1893 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
1894 *plparam = (LPARAM)SEGPTR_GET(mmi);
1896 return 1;
1897 case WM_GETTEXT:
1898 case WM_ASKCBFORMATNAME:
1900 LPSTR str;
1901 *pwparam16 = (WPARAM16)min( wParam32, 0xff80 ); /* Must be < 64K */
1902 if (!(str = SEGPTR_ALLOC(*pwparam16 + sizeof(LPARAM)))) return -1;
1903 *((LPARAM *)str)++ = *plparam; /* Store the previous lParam */
1904 *plparam = (LPARAM)SEGPTR_GET(str);
1906 return 1;
1907 case WM_MDICREATE:
1909 MDICREATESTRUCT16 *cs;
1910 MDICREATESTRUCTA *cs32 = (MDICREATESTRUCTA *)*plparam;
1911 LPSTR name, cls;
1913 if (!(cs = SEGPTR_NEW(MDICREATESTRUCT16))) return -1;
1914 STRUCT32_MDICREATESTRUCT32Ato16( cs32, cs );
1915 name = SEGPTR_STRDUP( cs32->szTitle );
1916 cls = SEGPTR_STRDUP( cs32->szClass );
1917 cs->szTitle = SEGPTR_GET(name);
1918 cs->szClass = SEGPTR_GET(cls);
1919 *plparam = (LPARAM)SEGPTR_GET(cs);
1921 return 1;
1922 case WM_MDIGETACTIVE:
1923 return 1;
1924 case WM_MDISETMENU:
1925 *plparam = MAKELPARAM( (HMENU16)LOWORD(wParam32),
1926 (HMENU16)LOWORD(*plparam) );
1927 *pwparam16 = (*plparam == 0);
1928 return 0;
1929 case WM_MENUSELECT:
1930 if(HIWORD(wParam32) & MF_POPUP)
1932 UINT16 hmenu;
1933 if (((UINT)HIWORD(wParam32) != 0xFFFF) || (*plparam))
1935 if((hmenu = GetSubMenu((HMENU16)*plparam, *pwparam16)))
1936 *pwparam16=hmenu;
1939 /* fall through */
1940 case WM_MENUCHAR:
1941 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
1942 return 0;
1943 case WM_MDIACTIVATE:
1944 if (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_MDICHILD)
1946 *pwparam16 = ((HWND)*plparam == hwnd);
1947 *plparam = MAKELPARAM( (HWND16)LOWORD(*plparam),
1948 (HWND16)LOWORD(wParam32) );
1950 else
1952 *pwparam16 = (HWND)wParam32;
1953 *plparam = 0;
1955 return 0;
1956 case WM_NCCALCSIZE:
1958 NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)*plparam;
1959 NCCALCSIZE_PARAMS16 *nc = (NCCALCSIZE_PARAMS16 *)SEGPTR_ALLOC( sizeof(*nc) + sizeof(LPARAM) );
1960 if (!nc) return -1;
1962 CONV_RECT32TO16( &nc32->rgrc[0], &nc->rgrc[0] );
1963 if (wParam32)
1965 WINDOWPOS16 *wp;
1966 CONV_RECT32TO16( &nc32->rgrc[1], &nc->rgrc[1] );
1967 CONV_RECT32TO16( &nc32->rgrc[2], &nc->rgrc[2] );
1968 if (!(wp = SEGPTR_NEW(WINDOWPOS16)))
1970 SEGPTR_FREE(nc);
1971 return -1;
1973 STRUCT32_WINDOWPOS32to16( nc32->lppos, wp );
1974 nc->lppos = SEGPTR_GET(wp);
1976 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
1977 *plparam = (LPARAM)SEGPTR_GET(nc);
1979 return 1;
1980 case WM_NCCREATE:
1981 case WM_CREATE:
1983 CREATESTRUCT16 *cs;
1984 CREATESTRUCTA *cs32 = (CREATESTRUCTA *)*plparam;
1985 LPSTR name, cls;
1987 if (!(cs = SEGPTR_NEW(CREATESTRUCT16))) return -1;
1988 STRUCT32_CREATESTRUCT32Ato16( cs32, cs );
1989 name = SEGPTR_STRDUP( cs32->lpszName );
1990 cls = SEGPTR_STRDUP( cs32->lpszClass );
1991 cs->lpszName = SEGPTR_GET(name);
1992 cs->lpszClass = SEGPTR_GET(cls);
1993 *plparam = (LPARAM)SEGPTR_GET(cs);
1995 return 1;
1996 case WM_PARENTNOTIFY:
1997 if ((LOWORD(wParam32)==WM_CREATE) || (LOWORD(wParam32)==WM_DESTROY))
1998 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32));
1999 /* else nothing to do */
2000 return 0;
2001 case WM_NOTIFY:
2002 *plparam = MapLS( (NMHDR *)*plparam ); /* NMHDR is already 32-bit */
2003 return 1;
2004 case WM_SETTEXT:
2005 case WM_WININICHANGE:
2006 case WM_DEVMODECHANGE:
2008 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
2009 if (!str) return -1;
2010 *plparam = (LPARAM)SEGPTR_GET(str);
2012 return 1;
2013 case WM_WINDOWPOSCHANGING:
2014 case WM_WINDOWPOSCHANGED:
2016 WINDOWPOS16 *wp = (WINDOWPOS16 *)SEGPTR_ALLOC( sizeof(*wp) +
2017 sizeof(LPARAM) );
2018 if (!wp) return -1;
2019 STRUCT32_WINDOWPOS32to16( (WINDOWPOS *)*plparam, wp );
2020 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
2021 *plparam = (LPARAM)SEGPTR_GET(wp);
2023 return 1;
2024 case WM_GETDLGCODE:
2025 if (*plparam) {
2026 LPMSG msg32 = (LPMSG) *plparam;
2027 LPMSG16 msg16 = (LPMSG16) SEGPTR_NEW( MSG16 );
2029 if (!msg16) return -1;
2030 msg16->hwnd = msg32->hwnd;
2031 msg16->lParam = msg32->lParam;
2032 msg16->time = msg32->time;
2033 CONV_POINT32TO16(&msg32->pt,&msg16->pt);
2034 /* this is right, right? */
2035 if (WINPROC_MapMsg32ATo16(msg32->hwnd,msg32->message,msg32->wParam,
2036 &msg16->message,&msg16->wParam, &msg16->lParam)<0) {
2037 SEGPTR_FREE( msg16 );
2038 return -1;
2040 *plparam = (LPARAM)SEGPTR_GET(msg16);
2041 return 1;
2043 return 0;
2045 case WM_ACTIVATEAPP:
2046 if (*plparam) *plparam = (LPARAM)THREAD_IdToTEB((DWORD) *plparam)->htask16;
2047 return 0;
2048 case WM_NEXTMENU:
2050 MDINEXTMENU *next = (MDINEXTMENU *)*plparam;
2051 *plparam = next->hmenuIn;
2052 return 1;
2054 case WM_PAINTCLIPBOARD:
2055 case WM_SIZECLIPBOARD:
2056 FIXME_(msg)("message %04x needs translation\n", msg32 );
2057 return -1;
2058 /* following messages should not be sent to 16-bit apps */
2059 case WM_SIZING:
2060 case WM_MOVING:
2061 case WM_CAPTURECHANGED:
2062 case WM_STYLECHANGING:
2063 case WM_STYLECHANGED:
2064 return -1;
2065 default: /* No translation needed */
2066 return 0;
2071 /**********************************************************************
2072 * WINPROC_UnmapMsg32ATo16
2074 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
2076 void WINPROC_UnmapMsg32ATo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2077 MSGPARAM16* p16 )
2079 switch(msg)
2081 case LB_ADDFILE:
2082 case LB_ADDSTRING:
2083 case LB_DIR:
2084 case LB_FINDSTRING:
2085 case LB_FINDSTRINGEXACT:
2086 case LB_INSERTSTRING:
2087 case LB_SELECTSTRING:
2088 case LB_SETTABSTOPS:
2089 case CB_ADDSTRING:
2090 case CB_FINDSTRING:
2091 case CB_FINDSTRINGEXACT:
2092 case CB_INSERTSTRING:
2093 case CB_SELECTSTRING:
2094 case CB_DIR:
2095 case WM_COMPAREITEM:
2096 case WM_DELETEITEM:
2097 case WM_DRAWITEM:
2098 case WM_SETTEXT:
2099 case WM_WININICHANGE:
2100 case WM_DEVMODECHANGE:
2101 SEGPTR_FREE( MapSL(p16->lParam) );
2102 break;
2104 case CB_GETDROPPEDCONTROLRECT:
2105 case LB_GETITEMRECT:
2107 RECT16 *rect = MapSL(p16->lParam);
2108 p16->lParam = *(LPARAM *)(rect + 1);
2109 CONV_RECT16TO32( rect, (RECT *)(p16->lParam));
2110 SEGPTR_FREE( rect );
2112 break;
2113 case LB_GETSELITEMS:
2115 INT i;
2116 LPINT16 items = MapSL(lParam);
2117 p16->lParam = *((LPARAM *)items - 1);
2118 for (i = 0; i < p16->wParam; i++) *((LPINT)(p16->lParam) + i) = items[i];
2119 SEGPTR_FREE( (LPARAM *)items - 1 );
2121 break;
2123 case CB_GETEDITSEL:
2124 if( wParam )
2125 *((LPUINT)(wParam)) = LOWORD(p16->lResult);
2126 if( lParam )
2127 *((LPUINT)(lParam)) = HIWORD(p16->lResult); /* FIXME: substract 1? */
2128 break;
2130 case LB_GETTEXT:
2131 case CB_GETLBTEXT:
2132 UnMapLS( (SEGPTR)(p16->lParam) );
2133 break;
2135 case WM_MEASUREITEM:
2137 MEASUREITEMSTRUCT16 *mis = MapSL(p16->lParam);
2138 MEASUREITEMSTRUCT *mis32 = *(MEASUREITEMSTRUCT **)(mis + 1);
2139 mis32->itemWidth = mis->itemWidth;
2140 mis32->itemHeight = mis->itemHeight;
2141 SEGPTR_FREE(mis);
2143 break;
2144 case WM_GETMINMAXINFO:
2146 MINMAXINFO16 *mmi = MapSL(p16->lParam);
2147 p16->lParam = *(LPARAM *)(mmi + 1);
2148 STRUCT32_MINMAXINFO16to32( mmi, (MINMAXINFO *)(p16->lParam) );
2149 SEGPTR_FREE(mmi);
2151 break;
2152 case WM_GETTEXT:
2153 case WM_ASKCBFORMATNAME:
2155 LPSTR str = MapSL(p16->lParam);
2156 p16->lParam = *((LPARAM *)str - 1);
2157 lstrcpynA( (LPSTR)(p16->lParam), str, p16->wParam );
2158 SEGPTR_FREE( (LPARAM *)str - 1 );
2160 break;
2161 case WM_MDICREATE:
2163 MDICREATESTRUCT16 *cs = MapSL(p16->lParam);
2164 SEGPTR_FREE( MapSL(cs->szTitle) );
2165 SEGPTR_FREE( MapSL(cs->szClass) );
2166 SEGPTR_FREE( cs );
2168 break;
2169 case WM_MDIGETACTIVE:
2170 if (lParam) *(BOOL *)lParam = (BOOL16)HIWORD(p16->lResult);
2171 p16->lResult = (HWND)LOWORD(p16->lResult);
2172 break;
2173 case WM_NCCALCSIZE:
2175 NCCALCSIZE_PARAMS *nc32;
2176 NCCALCSIZE_PARAMS16 *nc = MapSL(p16->lParam);
2177 p16->lParam = *(LPARAM *)(nc + 1);
2178 nc32 = (NCCALCSIZE_PARAMS *)(p16->lParam);
2179 CONV_RECT16TO32( &nc->rgrc[0], &nc32->rgrc[0] );
2180 if (p16->wParam)
2182 CONV_RECT16TO32( &nc->rgrc[1], &nc32->rgrc[1] );
2183 CONV_RECT16TO32( &nc->rgrc[2], &nc32->rgrc[2] );
2184 STRUCT32_WINDOWPOS16to32( MapSL(nc->lppos), nc32->lppos );
2185 SEGPTR_FREE( MapSL(nc->lppos) );
2187 SEGPTR_FREE(nc);
2189 break;
2190 case WM_NCCREATE:
2191 case WM_CREATE:
2193 CREATESTRUCT16 *cs = MapSL(p16->lParam);
2194 SEGPTR_FREE( MapSL(cs->lpszName) );
2195 SEGPTR_FREE( MapSL(cs->lpszClass) );
2196 SEGPTR_FREE( cs );
2198 break;
2199 case WM_WINDOWPOSCHANGING:
2200 case WM_WINDOWPOSCHANGED:
2202 WINDOWPOS16 *wp = MapSL(p16->lParam);
2203 p16->lParam = *(LPARAM *)(wp + 1);
2204 STRUCT32_WINDOWPOS16to32( wp, (WINDOWPOS *)p16->lParam );
2205 SEGPTR_FREE(wp);
2207 break;
2208 case WM_NOTIFY:
2209 UnMapLS(p16->lParam);
2210 break;
2211 case WM_GETDLGCODE:
2212 if (p16->lParam)
2214 LPMSG16 msg16 = MapSL(p16->lParam);
2215 MSGPARAM16 msgp16;
2216 msgp16.wParam=msg16->wParam;
2217 msgp16.lParam=msg16->lParam;
2218 WINPROC_UnmapMsg32ATo16(((LPMSG)lParam)->hwnd, ((LPMSG)lParam)->message,
2219 ((LPMSG)lParam)->wParam, ((LPMSG)lParam)->lParam,
2220 &msgp16 );
2221 SEGPTR_FREE(msg16);
2223 break;
2224 case WM_NEXTMENU:
2226 MDINEXTMENU *next = (MDINEXTMENU *)lParam;
2227 next->hmenuNext = LOWORD(p16->lResult);
2228 next->hwndNext = HIWORD(p16->lResult);
2229 p16->lResult = 0;
2231 break;
2236 /**********************************************************************
2237 * WINPROC_MapMsg32WTo16
2239 * Map a message from 32-bit Unicode to 16-bit.
2240 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
2242 INT WINPROC_MapMsg32WTo16( HWND hwnd, UINT msg32, WPARAM wParam32,
2243 UINT16 *pmsg16, WPARAM16 *pwparam16,
2244 LPARAM *plparam )
2246 char ch;
2247 WCHAR wch;
2249 *pmsg16 = LOWORD(msg32);
2250 *pwparam16 = LOWORD(wParam32);
2251 switch(msg32)
2253 case LB_ADDSTRING:
2254 case LB_FINDSTRING:
2255 case LB_FINDSTRINGEXACT:
2256 case LB_INSERTSTRING:
2257 case LB_SELECTSTRING:
2258 case LB_DIR:
2259 case LB_ADDFILE:
2261 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
2262 if (!str) return -1;
2263 *plparam = (LPARAM)SEGPTR_GET(str);
2265 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
2266 return 1;
2268 case CB_ADDSTRING:
2269 case CB_FINDSTRING:
2270 case CB_FINDSTRINGEXACT:
2271 case CB_INSERTSTRING:
2272 case CB_SELECTSTRING:
2273 case CB_DIR:
2275 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
2276 if (!str) return -1;
2277 *plparam = (LPARAM)SEGPTR_GET(str);
2279 *pmsg16 = (UINT16)msg32 + (CB_ADDSTRING16 - CB_ADDSTRING);
2280 return 1;
2282 case WM_NCCREATE:
2283 case WM_CREATE:
2285 CREATESTRUCT16 *cs;
2286 CREATESTRUCTW *cs32 = (CREATESTRUCTW *)*plparam;
2287 LPSTR name, cls;
2289 if (!(cs = SEGPTR_NEW(CREATESTRUCT16))) return -1;
2290 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs32, cs );
2291 name = SEGPTR_STRDUP_WtoA( cs32->lpszName );
2292 cls = SEGPTR_STRDUP_WtoA( cs32->lpszClass );
2293 cs->lpszName = SEGPTR_GET(name);
2294 cs->lpszClass = SEGPTR_GET(cls);
2295 *plparam = (LPARAM)SEGPTR_GET(cs);
2297 return 1;
2298 case WM_MDICREATE:
2300 MDICREATESTRUCT16 *cs;
2301 MDICREATESTRUCTW *cs32 = (MDICREATESTRUCTW *)*plparam;
2302 LPSTR name, cls;
2304 if (!(cs = SEGPTR_NEW(MDICREATESTRUCT16))) return -1;
2305 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs32, cs );
2306 name = SEGPTR_STRDUP_WtoA( cs32->szTitle );
2307 cls = SEGPTR_STRDUP_WtoA( cs32->szClass );
2308 cs->szTitle = SEGPTR_GET(name);
2309 cs->szClass = SEGPTR_GET(cls);
2310 *plparam = (LPARAM)SEGPTR_GET(cs);
2312 return 1;
2313 case WM_SETTEXT:
2315 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
2316 if (!str) return -1;
2317 *plparam = (LPARAM)SEGPTR_GET(str);
2319 return 1;
2320 case LB_GETTEXT:
2321 case CB_GETLBTEXT:
2322 if ( WINPROC_TestLBForStr( hwnd ))
2324 LPSTR str = (LPSTR) SEGPTR_ALLOC( 256 ); /* fixme: fixed sized buffer */
2325 if (!str) return -1;
2326 *pmsg16 = (msg32 == LB_GETTEXT)? LB_GETTEXT16 : CB_GETLBTEXT16;
2327 *plparam = (LPARAM)SEGPTR_GET(str);
2329 return 1;
2331 case WM_CHARTOITEM:
2332 wch = LOWORD(wParam32);
2333 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
2334 *pwparam16 = ch;
2335 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
2336 return 0;
2337 case WM_MENUCHAR:
2338 wch = LOWORD(wParam32);
2339 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
2340 *pwparam16 = ch;
2341 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
2342 return 0;
2343 case WM_CHAR:
2344 case WM_DEADCHAR:
2345 case WM_SYSCHAR:
2346 case WM_SYSDEADCHAR:
2347 wch = wParam32;
2348 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
2349 *pwparam16 = ch;
2350 return 0;
2352 default: /* No Unicode translation needed (?) */
2353 return WINPROC_MapMsg32ATo16( hwnd, msg32, wParam32, pmsg16,
2354 pwparam16, plparam );
2359 /**********************************************************************
2360 * WINPROC_UnmapMsg32WTo16
2362 * Unmap a message that was mapped from 32-bit Unicode to 16-bit.
2364 void WINPROC_UnmapMsg32WTo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2365 MSGPARAM16* p16 )
2367 switch(msg)
2369 case WM_GETTEXT:
2370 case WM_ASKCBFORMATNAME:
2372 LPSTR str = MapSL(p16->lParam);
2373 p16->lParam = *((LPARAM *)str - 1);
2374 MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)p16->lParam, 0x7fffffff );
2375 SEGPTR_FREE( (LPARAM *)str - 1 );
2377 break;
2378 case LB_GETTEXT:
2379 case CB_GETLBTEXT:
2380 if ( WINPROC_TestLBForStr( hwnd ))
2382 LPSTR str = MapSL(p16->lParam);
2383 MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)lParam, 0x7fffffff );
2384 SEGPTR_FREE( (LPARAM *) str );
2386 break;
2387 default:
2388 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, p16 );
2389 break;
2394 /**********************************************************************
2395 * WINPROC_CallProc32ATo32W
2397 * Call a window procedure, translating args from Ansi to Unicode.
2399 static LRESULT WINPROC_CallProc32ATo32W( WNDPROC func, HWND hwnd,
2400 UINT msg, WPARAM wParam,
2401 LPARAM lParam )
2403 LRESULT result;
2404 int unmap;
2406 if( (unmap = WINPROC_MapMsg32ATo32W( hwnd, msg, &wParam, &lParam )) == -1) {
2407 ERR_(msg)("Message translation failed. (msg=%s,wp=%08x,lp=%08lx)\n",
2408 SPY_GetMsgName(msg, hwnd), wParam, lParam );
2409 return 0;
2411 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2412 if (unmap) result = WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam, result );
2413 return result;
2417 /**********************************************************************
2418 * WINPROC_CallProc32WTo32A
2420 * Call a window procedure, translating args from Unicode to Ansi.
2422 static LRESULT WINPROC_CallProc32WTo32A( WNDPROC func, HWND hwnd,
2423 UINT msg, WPARAM wParam,
2424 LPARAM lParam )
2426 LRESULT result;
2427 int unmap;
2429 if ((unmap = WINPROC_MapMsg32WTo32A( hwnd, msg, &wParam, &lParam )) == -1) {
2430 ERR_(msg)("Message translation failed. (msg=%s,wp=%08x,lp=%08lx)\n",
2431 SPY_GetMsgName(msg, hwnd), wParam, lParam );
2432 return 0;
2434 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2435 if( unmap ) WINPROC_UnmapMsg32WTo32A( hwnd, msg, wParam, lParam );
2436 return result;
2440 /**********************************************************************
2441 * WINPROC_CallProc16To32A
2443 * Call a 32-bit window procedure, translating the 16-bit args.
2445 static LRESULT WINPROC_CallProc16To32A( WNDPROC func, HWND16 hwnd,
2446 UINT16 msg, WPARAM16 wParam,
2447 LPARAM lParam )
2449 LRESULT result;
2450 UINT msg32;
2451 WPARAM wParam32;
2453 if (WINPROC_MapMsg16To32A( msg, wParam, &msg32, &wParam32, &lParam ) == -1)
2454 return 0;
2455 result = WINPROC_CallWndProc( func, hwnd, msg32, wParam32, lParam );
2456 return WINPROC_UnmapMsg16To32A( hwnd, msg32, wParam32, lParam, result );
2459 /**********************************************************************
2460 * WINPROC_Thunk16To32A
2462 static LRESULT WINAPI WINPROC_Thunk16To32A( WNDPROC func, LPBYTE args )
2464 HWND16 hwnd = *(HWND16 *)( args+8 );
2465 UINT16 msg = *(HWND16 *)( args+6 );
2466 WPARAM16 wParam = *(HWND16 *)( args+4 );
2467 LPARAM lParam = *(LPARAM *)( args+0 );
2469 return WINPROC_CallProc16To32A( func, hwnd, msg, wParam, lParam );
2473 /**********************************************************************
2474 * WINPROC_CallProc16To32W
2476 * Call a 32-bit window procedure, translating the 16-bit args.
2478 static LRESULT WINPROC_CallProc16To32W( WNDPROC func, HWND16 hwnd,
2479 UINT16 msg, WPARAM16 wParam,
2480 LPARAM lParam )
2482 LRESULT result;
2483 UINT msg32;
2484 WPARAM wParam32;
2486 if (WINPROC_MapMsg16To32W( hwnd, msg, wParam, &msg32, &wParam32, &lParam ) == -1)
2487 return 0;
2489 result = WINPROC_CallWndProc( func, hwnd, msg32, wParam32, lParam );
2491 return WINPROC_UnmapMsg16To32W( hwnd, msg32, wParam32, lParam, result );
2494 /**********************************************************************
2495 * WINPROC_Thunk16To32W
2497 static LRESULT WINAPI WINPROC_Thunk16To32W( WNDPROC func, LPBYTE args )
2499 HWND16 hwnd = *(HWND16 *)( args+8 );
2500 UINT16 msg = *(HWND16 *)( args+6 );
2501 WPARAM16 wParam = *(HWND16 *)( args+4 );
2502 LPARAM lParam = *(LPARAM *)( args+0 );
2504 return WINPROC_CallProc16To32W( func, hwnd, msg, wParam, lParam );
2507 /**********************************************************************
2508 * WINPROC_CallProc32ATo16
2510 * Call a 16-bit window procedure, translating the 32-bit args.
2512 static LRESULT WINAPI WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd,
2513 UINT msg, WPARAM wParam,
2514 LPARAM lParam )
2516 UINT16 msg16;
2517 MSGPARAM16 mp16;
2519 mp16.lParam = lParam;
2520 if (WINPROC_MapMsg32ATo16( hwnd, msg, wParam,
2521 &msg16, &mp16.wParam, &mp16.lParam ) == -1)
2522 return 0;
2523 mp16.lResult = WINPROC_CallWndProc16( func, hwnd, msg16,
2524 mp16.wParam, mp16.lParam );
2525 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, &mp16 );
2526 return mp16.lResult;
2530 /**********************************************************************
2531 * WINPROC_CallProc32WTo16
2533 * Call a 16-bit window procedure, translating the 32-bit args.
2535 static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
2536 UINT msg, WPARAM wParam,
2537 LPARAM lParam )
2539 UINT16 msg16;
2540 MSGPARAM16 mp16;
2542 mp16.lParam = lParam;
2543 if (WINPROC_MapMsg32WTo16( hwnd, msg, wParam, &msg16, &mp16.wParam,
2544 &mp16.lParam ) == -1)
2545 return 0;
2546 mp16.lResult = WINPROC_CallWndProc16( func, hwnd, msg16,
2547 mp16.wParam, mp16.lParam );
2548 WINPROC_UnmapMsg32WTo16( hwnd, msg, wParam, lParam, &mp16 );
2549 return mp16.lResult;
2553 /**********************************************************************
2554 * CallWindowProc (USER.122)
2555 * CallWindowProc16 (USER32.@)
2557 LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
2558 WPARAM16 wParam, LPARAM lParam )
2560 WINDOWPROC *proc = WINPROC_GetPtr( func );
2562 if (!proc)
2563 return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
2565 #if testing
2566 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_16 );
2567 return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
2568 #endif
2570 switch(proc->type)
2572 case WIN_PROC_16:
2573 if (!proc->thunk.t_from32.proc) return 0;
2574 return WINPROC_CallWndProc16( proc->thunk.t_from32.proc,
2575 hwnd, msg, wParam, lParam );
2576 case WIN_PROC_32A:
2577 if (!proc->thunk.t_from16.proc) return 0;
2578 return WINPROC_CallProc16To32A( proc->thunk.t_from16.proc,
2579 hwnd, msg, wParam, lParam );
2580 case WIN_PROC_32W:
2581 if (!proc->thunk.t_from16.proc) return 0;
2582 return WINPROC_CallProc16To32W( proc->thunk.t_from16.proc,
2583 hwnd, msg, wParam, lParam );
2584 default:
2585 WARN_(relay)("Invalid proc %p\n", proc );
2586 return 0;
2591 /**********************************************************************
2592 * CallWindowProcA (USER32.@)
2594 * The CallWindowProc() function invokes the windows procedure _func_,
2595 * with _hwnd_ as the target window, the message specified by _msg_, and
2596 * the message parameters _wParam_ and _lParam_.
2598 * Some kinds of argument conversion may be done, I'm not sure what.
2600 * CallWindowProc() may be used for windows subclassing. Use
2601 * SetWindowLong() to set a new windows procedure for windows of the
2602 * subclass, and handle subclassed messages in the new windows
2603 * procedure. The new windows procedure may then use CallWindowProc()
2604 * with _func_ set to the parent class's windows procedure to dispatch
2605 * the message to the superclass.
2607 * RETURNS
2609 * The return value is message dependent.
2611 * CONFORMANCE
2613 * ECMA-234, Win32
2615 LRESULT WINAPI CallWindowProcA(
2616 WNDPROC func, /* [in] window procedure */
2617 HWND hwnd, /* [in] target window */
2618 UINT msg, /* [in] message */
2619 WPARAM wParam, /* [in] message dependent parameter */
2620 LPARAM lParam /* [in] message dependent parameter */
2622 WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
2624 if (!proc) return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2626 #if testing
2627 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_32A );
2628 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2629 #endif
2631 switch(proc->type)
2633 case WIN_PROC_16:
2634 if (!proc->thunk.t_from32.proc) return 0;
2635 return WINPROC_CallProc32ATo16( proc->thunk.t_from32.proc,
2636 hwnd, msg, wParam, lParam );
2637 case WIN_PROC_32A:
2638 if (!proc->thunk.t_from16.proc) return 0;
2639 return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
2640 hwnd, msg, wParam, lParam );
2641 case WIN_PROC_32W:
2642 if (!proc->thunk.t_from16.proc) return 0;
2643 return WINPROC_CallProc32ATo32W( proc->thunk.t_from16.proc,
2644 hwnd, msg, wParam, lParam );
2645 default:
2646 WARN_(relay)("Invalid proc %p\n", proc );
2647 return 0;
2652 /**********************************************************************
2653 * CallWindowProcW (USER32.@)
2655 LRESULT WINAPI CallWindowProcW( WNDPROC func, HWND hwnd, UINT msg,
2656 WPARAM wParam, LPARAM lParam )
2658 WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
2660 if (!proc) return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2662 #if testing
2663 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_32W );
2664 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2665 #endif
2667 switch(proc->type)
2669 case WIN_PROC_16:
2670 if (!proc->thunk.t_from32.proc) return 0;
2671 return WINPROC_CallProc32WTo16( proc->thunk.t_from32.proc,
2672 hwnd, msg, wParam, lParam );
2673 case WIN_PROC_32A:
2674 if (!proc->thunk.t_from16.proc) return 0;
2675 return WINPROC_CallProc32WTo32A( proc->thunk.t_from16.proc,
2676 hwnd, msg, wParam, lParam );
2677 case WIN_PROC_32W:
2678 if (!proc->thunk.t_from16.proc) return 0;
2679 return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
2680 hwnd, msg, wParam, lParam );
2681 default:
2682 WARN_(relay)("Invalid proc %p\n", proc );
2683 return 0;