user: Added helper functions for A<->W conversion of single characters.
[wine/multimedia.git] / dlls / user / winproc.c
blob7746135808a7f1731aed514f4b2249bbf4de9d99
1 /*
2 * Window procedure callbacks
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1996 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <assert.h>
26 #include <stdarg.h>
27 #include <string.h>
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "wownt32.h"
33 #include "wine/winbase16.h"
34 #include "wine/winuser16.h"
35 #include "controls.h"
36 #include "win.h"
37 #include "winproc.h"
38 #include "user_private.h"
39 #include "dde.h"
40 #include "winternl.h"
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
44 WINE_DECLARE_DEBUG_CHANNEL(msg);
45 WINE_DECLARE_DEBUG_CHANNEL(relay);
46 WINE_DEFAULT_DEBUG_CHANNEL(win);
48 typedef struct tagWINDOWPROC
50 WNDPROC16 proc16; /* 16-bit window proc */
51 WNDPROC procA; /* ASCII window proc */
52 WNDPROC procW; /* Unicode window proc */
53 } WINDOWPROC;
55 #define WINPROC_HANDLE (~0UL >> 16)
56 #define MAX_WINPROCS 8192
58 static WINDOWPROC winproc_array[MAX_WINPROCS];
59 static UINT winproc_used;
61 static CRITICAL_SECTION winproc_cs;
62 static CRITICAL_SECTION_DEBUG critsect_debug =
64 0, 0, &winproc_cs,
65 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
66 0, 0, { (DWORD_PTR)(__FILE__ ": winproc_cs") }
68 static CRITICAL_SECTION winproc_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
70 /* find an existing winproc for a given 16-bit function and type */
71 /* FIXME: probably should do something more clever than a linear search */
72 static inline WINDOWPROC *find_winproc16( WNDPROC16 func )
74 unsigned int i;
76 for (i = 0; i < winproc_used; i++)
78 if (winproc_array[i].proc16 == func) return &winproc_array[i];
80 return NULL;
83 /* find an existing winproc for a given function and type */
84 /* FIXME: probably should do something more clever than a linear search */
85 static inline WINDOWPROC *find_winproc( WNDPROC funcA, WNDPROC funcW )
87 unsigned int i;
89 for (i = 0; i < winproc_used; i++)
91 if (funcA && winproc_array[i].procA != funcA) continue;
92 if (funcW && winproc_array[i].procW != funcW) continue;
93 return &winproc_array[i];
95 return NULL;
98 /* return the window proc for a given handle, or NULL for an invalid handle */
99 static inline WINDOWPROC *handle_to_proc( WNDPROC handle )
101 UINT index = LOWORD(handle);
102 if ((ULONG_PTR)handle >> 16 != WINPROC_HANDLE) return NULL;
103 if (index >= winproc_used) return NULL;
104 return &winproc_array[index];
107 /* create a handle for a given window proc */
108 static inline WNDPROC proc_to_handle( WINDOWPROC *proc )
110 return (WNDPROC)(ULONG_PTR)((proc - winproc_array) | (WINPROC_HANDLE << 16));
113 /* allocate and initialize a new winproc */
114 static inline WINDOWPROC *alloc_winproc( WNDPROC funcA, WNDPROC funcW )
116 WINDOWPROC *proc;
118 /* check if the function is already a win proc */
119 if (funcA && (proc = handle_to_proc( funcA ))) return proc;
120 if (funcW && (proc = handle_to_proc( funcW ))) return proc;
121 if (!funcA && !funcW) return NULL;
123 EnterCriticalSection( &winproc_cs );
125 /* check if we already have a winproc for that function */
126 if (!(proc = find_winproc( funcA, funcW )))
128 if (winproc_used < MAX_WINPROCS)
130 proc = &winproc_array[winproc_used++];
131 proc->procA = funcA;
132 proc->procW = funcW;
133 TRACE( "allocated %p for %p/%p (%d/%d used)\n",
134 proc_to_handle(proc), funcA, funcW, winproc_used, MAX_WINPROCS );
136 else FIXME( "too many winprocs, cannot allocate one for %p/%p\n", funcA, funcW );
138 else TRACE( "reusing %p for %p/%p\n", proc_to_handle(proc), funcA, funcW );
140 LeaveCriticalSection( &winproc_cs );
141 return proc;
145 #ifdef __i386__
147 #include "pshpack1.h"
149 /* Window procedure 16-to-32-bit thunk */
150 typedef struct
152 BYTE popl_eax; /* popl %eax (return address) */
153 BYTE pushl_func; /* pushl $proc */
154 WINDOWPROC *proc;
155 BYTE pushl_eax; /* pushl %eax */
156 BYTE ljmp; /* ljmp relay*/
157 DWORD relay_offset; /* __wine_call_wndproc */
158 WORD relay_sel;
159 } WINPROC_THUNK;
161 #include "poppack.h"
163 #define MAX_THUNKS (0x10000 / sizeof(WINPROC_THUNK))
165 static WINPROC_THUNK *thunk_array;
166 static UINT thunk_selector;
167 static UINT thunk_used;
169 /* return the window proc for a given handle, or NULL for an invalid handle */
170 static inline WINDOWPROC *handle16_to_proc( WNDPROC16 handle )
172 if (HIWORD(handle) == thunk_selector)
174 UINT index = LOWORD(handle) / sizeof(WINPROC_THUNK);
175 /* check alignment */
176 if (index * sizeof(WINPROC_THUNK) != LOWORD(handle)) return NULL;
177 /* check array limits */
178 if (index >= thunk_used) return NULL;
179 return thunk_array[index].proc;
181 return handle_to_proc( (WNDPROC)handle );
184 /* allocate a 16-bit thunk for an existing window proc */
185 static WNDPROC16 alloc_win16_thunk( WINDOWPROC *proc )
187 static FARPROC16 relay;
188 UINT i;
190 if (proc->proc16) return proc->proc16;
192 EnterCriticalSection( &winproc_cs );
194 if (!thunk_array) /* allocate the array and its selector */
196 LDT_ENTRY entry;
198 if (!(thunk_selector = wine_ldt_alloc_entries(1))) goto done;
199 if (!(thunk_array = VirtualAlloc( NULL, MAX_THUNKS * sizeof(WINPROC_THUNK), MEM_COMMIT,
200 PAGE_EXECUTE_READWRITE ))) goto done;
201 wine_ldt_set_base( &entry, thunk_array );
202 wine_ldt_set_limit( &entry, MAX_THUNKS * sizeof(WINPROC_THUNK) - 1 );
203 wine_ldt_set_flags( &entry, WINE_LDT_FLAGS_CODE | WINE_LDT_FLAGS_32BIT );
204 wine_ldt_set_entry( thunk_selector, &entry );
205 relay = GetProcAddress16( GetModuleHandle16("user"), "__wine_call_wndproc" );
208 /* check if it already exists */
209 for (i = 0; i < thunk_used; i++) if (thunk_array[i].proc == proc) break;
211 if (i == thunk_used) /* create a new one */
213 WINPROC_THUNK *thunk;
215 if (thunk_used >= MAX_THUNKS) goto done;
216 thunk = &thunk_array[thunk_used++];
217 thunk->popl_eax = 0x58; /* popl %eax */
218 thunk->pushl_func = 0x68; /* pushl $proc */
219 thunk->proc = proc;
220 thunk->pushl_eax = 0x50; /* pushl %eax */
221 thunk->ljmp = 0xea; /* ljmp relay*/
222 thunk->relay_offset = OFFSETOF(relay);
223 thunk->relay_sel = SELECTOROF(relay);
225 proc->proc16 = (WNDPROC16)MAKESEGPTR( thunk_selector, i * sizeof(WINPROC_THUNK) );
226 done:
227 LeaveCriticalSection( &winproc_cs );
228 return proc->proc16;
231 #else /* __i386__ */
233 static inline WINDOWPROC *handle16_to_proc( WNDPROC16 handle )
235 return handle_to_proc( (WNDPROC)handle );
238 static inline WNDPROC16 alloc_win16_thunk( WINDOWPROC *proc )
240 return 0;
243 #endif /* __i386__ */
246 #ifdef __i386__
247 /* Some window procedures modify register they shouldn't, or are not
248 * properly declared stdcall; so we need a small assembly wrapper to
249 * call them. */
250 extern LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
251 WPARAM wParam, LPARAM lParam );
252 __ASM_GLOBAL_FUNC( WINPROC_wrapper,
253 "pushl %ebp\n\t"
254 "movl %esp,%ebp\n\t"
255 "pushl %edi\n\t"
256 "pushl %esi\n\t"
257 "pushl %ebx\n\t"
258 "subl $12,%esp\n\t"
259 "pushl 24(%ebp)\n\t"
260 "pushl 20(%ebp)\n\t"
261 "pushl 16(%ebp)\n\t"
262 "pushl 12(%ebp)\n\t"
263 "movl 8(%ebp),%eax\n\t"
264 "call *%eax\n\t"
265 "leal -12(%ebp),%esp\n\t"
266 "popl %ebx\n\t"
267 "popl %esi\n\t"
268 "popl %edi\n\t"
269 "leave\n\t"
270 "ret" );
271 #else
272 static inline LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
273 WPARAM wParam, LPARAM lParam )
275 return proc( hwnd, msg, wParam, lParam );
277 #endif /* __i386__ */
280 static void MINMAXINFO32to16( const MINMAXINFO *from, MINMAXINFO16 *to )
282 to->ptReserved.x = from->ptReserved.x;
283 to->ptReserved.y = from->ptReserved.y;
284 to->ptMaxSize.x = from->ptMaxSize.x;
285 to->ptMaxSize.y = from->ptMaxSize.y;
286 to->ptMaxPosition.x = from->ptMaxPosition.x;
287 to->ptMaxPosition.y = from->ptMaxPosition.y;
288 to->ptMinTrackSize.x = from->ptMinTrackSize.x;
289 to->ptMinTrackSize.y = from->ptMinTrackSize.y;
290 to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
291 to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
294 static void MINMAXINFO16to32( const MINMAXINFO16 *from, MINMAXINFO *to )
296 to->ptReserved.x = from->ptReserved.x;
297 to->ptReserved.y = from->ptReserved.y;
298 to->ptMaxSize.x = from->ptMaxSize.x;
299 to->ptMaxSize.y = from->ptMaxSize.y;
300 to->ptMaxPosition.x = from->ptMaxPosition.x;
301 to->ptMaxPosition.y = from->ptMaxPosition.y;
302 to->ptMinTrackSize.x = from->ptMinTrackSize.x;
303 to->ptMinTrackSize.y = from->ptMinTrackSize.y;
304 to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
305 to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
308 static void WINDOWPOS32to16( const WINDOWPOS* from, WINDOWPOS16* to )
310 to->hwnd = HWND_16(from->hwnd);
311 to->hwndInsertAfter = HWND_16(from->hwndInsertAfter);
312 to->x = from->x;
313 to->y = from->y;
314 to->cx = from->cx;
315 to->cy = from->cy;
316 to->flags = from->flags;
319 static void WINDOWPOS16to32( const WINDOWPOS16* from, WINDOWPOS* to )
321 to->hwnd = WIN_Handle32(from->hwnd);
322 to->hwndInsertAfter = (from->hwndInsertAfter == (HWND16)-1) ?
323 HWND_TOPMOST : WIN_Handle32(from->hwndInsertAfter);
324 to->x = from->x;
325 to->y = from->y;
326 to->cx = from->cx;
327 to->cy = from->cy;
328 to->flags = from->flags;
331 /* The strings are not copied */
332 static void CREATESTRUCT32Ato16( const CREATESTRUCTA* from, CREATESTRUCT16* to )
334 to->lpCreateParams = (SEGPTR)from->lpCreateParams;
335 to->hInstance = HINSTANCE_16(from->hInstance);
336 to->hMenu = HMENU_16(from->hMenu);
337 to->hwndParent = HWND_16(from->hwndParent);
338 to->cy = from->cy;
339 to->cx = from->cx;
340 to->y = from->y;
341 to->x = from->x;
342 to->style = from->style;
343 to->dwExStyle = from->dwExStyle;
346 static void CREATESTRUCT16to32A( const CREATESTRUCT16* from, CREATESTRUCTA *to )
349 to->lpCreateParams = (LPVOID)from->lpCreateParams;
350 to->hInstance = HINSTANCE_32(from->hInstance);
351 to->hMenu = HMENU_32(from->hMenu);
352 to->hwndParent = WIN_Handle32(from->hwndParent);
353 to->cy = from->cy;
354 to->cx = from->cx;
355 to->y = from->y;
356 to->x = from->x;
357 to->style = from->style;
358 to->dwExStyle = from->dwExStyle;
361 /* The strings are not copied */
362 static void MDICREATESTRUCT32Ato16( const MDICREATESTRUCTA* from, MDICREATESTRUCT16* to )
364 to->hOwner = HINSTANCE_16(from->hOwner);
365 to->x = from->x;
366 to->y = from->y;
367 to->cx = from->cx;
368 to->cy = from->cy;
369 to->style = from->style;
370 to->lParam = from->lParam;
373 static void MDICREATESTRUCT16to32A( const MDICREATESTRUCT16* from, MDICREATESTRUCTA *to )
375 to->hOwner = HINSTANCE_32(from->hOwner);
376 to->x = from->x;
377 to->y = from->y;
378 to->cx = from->cx;
379 to->cy = from->cy;
380 to->style = from->style;
381 to->lParam = from->lParam;
384 static WPARAM map_wparam_char_AtoW( WPARAM wParam, DWORD len )
386 CHAR ch[2];
387 WCHAR wch;
389 ch[0] = (wParam >> 8);
390 ch[1] = wParam & 0xff;
391 if (len > 1 && ch[0])
392 RtlMultiByteToUnicodeN( &wch, sizeof(wch), NULL, ch, 2 );
393 else
394 RtlMultiByteToUnicodeN( &wch, sizeof(wch), NULL, ch + 1, 1 );
395 return MAKEWPARAM( wch, HIWORD(wParam) );
398 static WPARAM map_wparam_char_WtoA( WPARAM wParam, DWORD len )
400 WCHAR wch = wParam;
401 BYTE ch[2];
403 RtlUnicodeToMultiByteN( (LPSTR)ch, len, &len, &wch, sizeof(wch) );
404 if (len == 2)
405 return MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(wParam) );
406 else
407 return MAKEWPARAM( ch[0], HIWORD(wParam) );
410 /**********************************************************************
411 * WINPROC_CallWndProc32
413 * Call a 32-bit WndProc.
415 static LRESULT WINPROC_CallWndProc( WNDPROC proc, HWND hwnd, UINT msg,
416 WPARAM wParam, LPARAM lParam )
418 LRESULT retvalue;
420 USER_CheckNotLock();
422 hwnd = WIN_GetFullHandle( hwnd );
423 if (TRACE_ON(relay))
424 DPRINTF( "%04lx:Call window proc %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
425 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam );
427 retvalue = WINPROC_wrapper( proc, hwnd, msg, wParam, lParam );
429 if (TRACE_ON(relay))
430 DPRINTF( "%04lx:Ret window proc %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx) retval=%08lx\n",
431 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam, retvalue );
432 return retvalue;
435 /***********************************************************************
436 * WINPROC_CallWndProc16
438 * Call a 16-bit window procedure
440 static LRESULT WINAPI WINPROC_CallWndProc16( WNDPROC16 proc, HWND16 hwnd,
441 UINT16 msg, WPARAM16 wParam,
442 LPARAM lParam )
444 CONTEXT86 context;
445 size_t size = 0;
446 struct
448 WORD params[5];
449 union
451 CREATESTRUCT16 cs16;
452 DRAWITEMSTRUCT16 dis16;
453 COMPAREITEMSTRUCT16 cis16;
454 } u;
455 } args;
457 USER_CheckNotLock();
459 /* Window procedures want ax = hInstance, ds = es = ss */
461 memset(&context, 0, sizeof(context));
462 context.SegDs = context.SegEs = SELECTOROF(NtCurrentTeb()->WOW32Reserved);
463 context.SegFs = wine_get_fs();
464 context.SegGs = wine_get_gs();
465 if (!(context.Eax = GetWindowWord( HWND_32(hwnd), GWLP_HINSTANCE ))) context.Eax = context.SegDs;
466 context.SegCs = SELECTOROF(proc);
467 context.Eip = OFFSETOF(proc);
468 context.Ebp = OFFSETOF(NtCurrentTeb()->WOW32Reserved) + (WORD)&((STACK16FRAME*)0)->bp;
470 if (lParam)
472 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
473 work if structures passed in lParam are placed in the stack/data
474 segment. Programmers easily make the mistake of converting lParam
475 to a near rather than a far pointer, since Windows apparently
476 allows this. We copy the structures to the 16 bit stack; this is
477 ugly but makes these programs work. */
478 switch (msg)
480 case WM_CREATE:
481 case WM_NCCREATE:
482 size = sizeof(CREATESTRUCT16); break;
483 case WM_DRAWITEM:
484 size = sizeof(DRAWITEMSTRUCT16); break;
485 case WM_COMPAREITEM:
486 size = sizeof(COMPAREITEMSTRUCT16); break;
488 if (size)
490 memcpy( &args.u, MapSL(lParam), size );
491 lParam = (SEGPTR)NtCurrentTeb()->WOW32Reserved - size;
495 args.params[4] = hwnd;
496 args.params[3] = msg;
497 args.params[2] = wParam;
498 args.params[1] = HIWORD(lParam);
499 args.params[0] = LOWORD(lParam);
500 WOWCallback16Ex( 0, WCB16_REGS, sizeof(args.params) + size, &args, (DWORD *)&context );
501 return MAKELONG( LOWORD(context.Eax), LOWORD(context.Edx) );
505 /**********************************************************************
506 * WINPROC_GetProc16
508 * Get a window procedure pointer that can be passed to the Windows program.
510 WNDPROC16 WINPROC_GetProc16( WNDPROC proc, BOOL unicode )
512 WINDOWPROC *ptr;
514 if (unicode) ptr = alloc_winproc( NULL, proc );
515 else ptr = alloc_winproc( proc, NULL );
517 if (!ptr) return 0;
518 return alloc_win16_thunk( ptr );
522 /**********************************************************************
523 * WINPROC_GetProc
525 * Get a window procedure pointer that can be passed to the Windows program.
527 WNDPROC WINPROC_GetProc( WNDPROC proc, BOOL unicode )
529 WINDOWPROC *ptr = handle_to_proc( proc );
531 if (!ptr) return proc;
532 if (unicode)
534 if (ptr->procW) return ptr->procW;
535 return proc;
537 else
539 if (ptr->procA) return ptr->procA;
540 return proc;
545 /**********************************************************************
546 * WINPROC_AllocProc16
548 * Allocate a window procedure for a window or class.
550 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
551 * lot of windows, it will usually only have a limited number of window procedures, so the
552 * array won't grow too large, and this way we avoid the need to track allocations per window.
554 WNDPROC WINPROC_AllocProc16( WNDPROC16 func )
556 WINDOWPROC *proc;
558 if (!func) return NULL;
560 /* check if the function is already a win proc */
561 if (!(proc = handle16_to_proc( func )))
563 EnterCriticalSection( &winproc_cs );
565 /* then check if we already have a winproc for that function */
566 if (!(proc = find_winproc16( func )))
568 if (winproc_used < MAX_WINPROCS)
570 proc = &winproc_array[winproc_used++];
571 proc->proc16 = func;
572 TRACE( "allocated %p for %p/16-bit (%d/%d used)\n",
573 proc_to_handle(proc), func, winproc_used, MAX_WINPROCS );
575 else FIXME( "too many winprocs, cannot allocate one for 16-bit %p\n", func );
577 else TRACE( "reusing %p for %p/16-bit\n", proc_to_handle(proc), func );
579 LeaveCriticalSection( &winproc_cs );
581 return proc_to_handle( proc );
585 /**********************************************************************
586 * WINPROC_AllocProc
588 * Allocate a window procedure for a window or class.
590 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
591 * lot of windows, it will usually only have a limited number of window procedures, so the
592 * array won't grow too large, and this way we avoid the need to track allocations per window.
594 WNDPROC WINPROC_AllocProc( WNDPROC funcA, WNDPROC funcW )
596 WINDOWPROC *proc;
598 if (!(proc = alloc_winproc( funcA, funcW ))) return NULL;
599 return proc_to_handle( proc );
603 /**********************************************************************
604 * WINPROC_IsUnicode
606 * Return the window procedure type, or the default value if not a winproc handle.
608 BOOL WINPROC_IsUnicode( WNDPROC proc, BOOL def_val )
610 WINDOWPROC *ptr = handle_to_proc( proc );
612 if (!ptr) return def_val;
613 if (ptr->procA && ptr->procW) return def_val; /* can be both */
614 return (ptr->procW != NULL);
618 /**********************************************************************
619 * WINPROC_TestLBForStr
621 * Return TRUE if the lparam is a string
623 inline static BOOL WINPROC_TestLBForStr( HWND hwnd, UINT msg )
625 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
626 if (msg <= CB_MSGMAX)
627 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
628 else
629 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
632 /**********************************************************************
633 * WINPROC_MapMsg32ATo32W
635 * Map a message from Ansi to Unicode.
636 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
638 * FIXME:
639 * WM_GETTEXT/WM_SETTEXT and static control with SS_ICON style:
640 * the first four bytes are the handle of the icon
641 * when the WM_SETTEXT message has been used to set the icon
643 INT WINPROC_MapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam )
645 switch(msg)
647 case WM_GETTEXT:
648 case WM_ASKCBFORMATNAME:
650 LPARAM *ptr = HeapAlloc( GetProcessHeap(), 0,
651 *pwparam * sizeof(WCHAR) + sizeof(LPARAM) );
652 if (!ptr) return -1;
653 *ptr++ = *plparam; /* Store previous lParam */
654 *plparam = (LPARAM)ptr;
656 return 1;
657 /* lparam is string (0-terminated) */
658 case WM_SETTEXT:
659 case WM_WININICHANGE:
660 case WM_DEVMODECHANGE:
661 case CB_DIR:
662 case LB_DIR:
663 case LB_ADDFILE:
664 case EM_REPLACESEL:
665 if (!*plparam) return 0;
666 else
668 DWORD len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)*plparam, -1, NULL, 0);
669 WCHAR *buf = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
670 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)*plparam, -1, buf, len);
671 *plparam = (LPARAM)buf;
672 return (*plparam ? 1 : -1);
674 case WM_GETTEXTLENGTH:
675 case CB_GETLBTEXTLEN:
676 case LB_GETTEXTLEN:
677 return 1; /* need to map result */
678 case WM_NCCREATE:
679 case WM_CREATE:
681 UNICODE_STRING usBuffer;
682 struct s
683 { CREATESTRUCTW cs; /* new structure */
684 LPCWSTR lpszName; /* allocated Name */
685 LPCWSTR lpszClass; /* allocated Class */
688 struct s *xs = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct s));
689 if (!xs) return -1;
690 xs->cs = *(CREATESTRUCTW *)*plparam;
691 if (HIWORD(xs->cs.lpszName))
693 RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)xs->cs.lpszName);
694 xs->lpszName = xs->cs.lpszName = usBuffer.Buffer;
696 if (HIWORD(xs->cs.lpszClass))
698 RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)xs->cs.lpszClass);
699 xs->lpszClass = xs->cs.lpszClass = usBuffer.Buffer;
702 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
704 MDICREATESTRUCTW *mdi_cs = HeapAlloc(GetProcessHeap(), 0, sizeof(*mdi_cs));
705 *mdi_cs = *(MDICREATESTRUCTW *)xs->cs.lpCreateParams;
706 if (HIWORD(mdi_cs->szTitle))
708 RtlCreateUnicodeStringFromAsciiz(&usBuffer, (LPCSTR)mdi_cs->szTitle);
709 mdi_cs->szTitle = usBuffer.Buffer;
711 if (HIWORD(mdi_cs->szClass))
713 RtlCreateUnicodeStringFromAsciiz(&usBuffer, (LPCSTR)mdi_cs->szClass);
714 mdi_cs->szClass = usBuffer.Buffer;
716 xs->cs.lpCreateParams = mdi_cs;
719 *plparam = (LPARAM)xs;
721 return 1;
722 case WM_MDICREATE:
724 MDICREATESTRUCTW *cs = HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
725 if (!cs) return -1;
726 *cs = *(MDICREATESTRUCTW *)*plparam;
727 if (HIWORD(cs->szClass))
729 UNICODE_STRING usBuffer;
730 RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)cs->szClass);
731 cs->szClass = usBuffer.Buffer;
733 if (HIWORD(cs->szTitle))
735 UNICODE_STRING usBuffer;
736 RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)cs->szTitle);
737 cs->szTitle = usBuffer.Buffer;
739 *plparam = (LPARAM)cs;
741 return 1;
743 /* Listbox / Combobox */
744 case LB_ADDSTRING:
745 case LB_INSERTSTRING:
746 case LB_FINDSTRING:
747 case LB_FINDSTRINGEXACT:
748 case LB_SELECTSTRING:
749 case CB_ADDSTRING:
750 case CB_INSERTSTRING:
751 case CB_FINDSTRINGEXACT:
752 case CB_FINDSTRING:
753 case CB_SELECTSTRING:
754 if(!*plparam) return 0;
755 if ( WINPROC_TestLBForStr( hwnd, msg ))
757 UNICODE_STRING usBuffer;
758 RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)*plparam);
759 *plparam = (LPARAM)usBuffer.Buffer;
761 return (*plparam ? 1 : -1);
763 case LB_GETTEXT: /* FIXME: fixed sized buffer */
764 case CB_GETLBTEXT:
765 if ( WINPROC_TestLBForStr( hwnd, msg ))
767 LPARAM *ptr = HeapAlloc( GetProcessHeap(), 0, 512 * sizeof(WCHAR) + sizeof(LPARAM) );
768 if (!ptr) return -1;
769 *ptr++ = *plparam; /* Store previous lParam */
770 *plparam = (LPARAM)ptr;
772 return 1;
774 /* Multiline edit */
775 case EM_GETLINE:
776 { WORD len = (WORD)*plparam;
777 LPARAM *ptr = HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(WCHAR) );
778 if (!ptr) return -1;
779 *ptr++ = *plparam; /* Store previous lParam */
780 *((WORD *) ptr) = len; /* Store the length */
781 *plparam = (LPARAM)ptr;
783 return 1;
785 case WM_CHARTOITEM:
786 case WM_MENUCHAR:
787 case WM_CHAR:
788 case WM_DEADCHAR:
789 case WM_SYSCHAR:
790 case WM_SYSDEADCHAR:
791 case EM_SETPASSWORDCHAR:
792 *pwparam = map_wparam_char_AtoW( *pwparam, 1 );
793 return 0;
795 case WM_IME_CHAR:
796 *pwparam = map_wparam_char_AtoW( *pwparam, 2 );
797 return 0;
799 case WM_PAINTCLIPBOARD:
800 case WM_SIZECLIPBOARD:
801 FIXME_(msg)("message %s (0x%x) needs translation, please report\n", SPY_GetMsgName(msg, hwnd), msg );
802 return -1;
803 default: /* No translation needed */
804 return 0;
809 /**********************************************************************
810 * WINPROC_UnmapMsg32ATo32W
812 * Unmap a message that was mapped from Ansi to Unicode.
814 LRESULT WINPROC_UnmapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
815 LRESULT result, WNDPROC dispatch )
817 switch(msg)
819 case WM_GETTEXT:
820 case WM_ASKCBFORMATNAME:
822 LPARAM *ptr = (LPARAM *)lParam - 1;
823 if (!wParam) result = 0;
824 else if (!(result = WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
825 (LPSTR)*ptr, wParam, NULL, NULL )))
827 ((LPSTR)*ptr)[wParam-1] = 0;
828 result = wParam - 1;
830 else result--; /* do not count terminating null */
831 HeapFree( GetProcessHeap(), 0, ptr );
833 break;
834 case WM_GETTEXTLENGTH:
835 case CB_GETLBTEXTLEN:
836 case LB_GETTEXTLEN:
837 if (result >= 0)
839 /* Determine respective GETTEXT message */
840 UINT msgGetText =
841 (msg == WM_GETTEXTLENGTH) ? WM_GETTEXT :
842 ((msg == CB_GETLBTEXTLEN) ? CB_GETLBTEXT : LB_GETTEXT);
843 /* wParam differs between the messages */
844 WPARAM wp = (msg == WM_GETTEXTLENGTH) ? (WPARAM)(result + 1) : wParam;
846 WCHAR* p = HeapAlloc (GetProcessHeap(), 0, (result + 1) * sizeof(WCHAR));
848 if (p)
850 LRESULT n;
852 if (dispatch)
853 n = WINPROC_CallWndProc(dispatch, hwnd, msgGetText, wp, (LPARAM)p);
854 else
855 n = SendMessageW (hwnd, msgGetText, wp, (LPARAM)p);
857 result = WideCharToMultiByte( CP_ACP, 0, p, n, NULL, 0, 0, NULL );
858 HeapFree (GetProcessHeap(), 0, p);
861 break;
862 case WM_NCCREATE:
863 case WM_CREATE:
865 struct s
866 { CREATESTRUCTW cs; /* new structure */
867 LPWSTR lpszName; /* allocated Name */
868 LPWSTR lpszClass; /* allocated Class */
870 struct s *xs = (struct s *)lParam;
871 HeapFree( GetProcessHeap(), 0, xs->lpszName );
872 HeapFree( GetProcessHeap(), 0, xs->lpszClass );
874 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
876 MDICREATESTRUCTW *mdi_cs = (MDICREATESTRUCTW *)xs->cs.lpCreateParams;
877 if (HIWORD(mdi_cs->szTitle))
878 HeapFree(GetProcessHeap(), 0, (LPVOID)mdi_cs->szTitle);
879 if (HIWORD(mdi_cs->szClass))
880 HeapFree(GetProcessHeap(), 0, (LPVOID)mdi_cs->szClass);
881 HeapFree(GetProcessHeap(), 0, mdi_cs);
883 HeapFree( GetProcessHeap(), 0, xs );
885 break;
887 case WM_MDICREATE:
889 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
890 if (HIWORD(cs->szTitle))
891 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
892 if (HIWORD(cs->szClass))
893 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
894 HeapFree( GetProcessHeap(), 0, cs );
896 break;
898 case WM_SETTEXT:
899 case WM_WININICHANGE:
900 case WM_DEVMODECHANGE:
901 case CB_DIR:
902 case LB_DIR:
903 case LB_ADDFILE:
904 case EM_REPLACESEL:
905 HeapFree( GetProcessHeap(), 0, (void *)lParam );
906 break;
908 /* Listbox / Combobox */
909 case LB_ADDSTRING:
910 case LB_INSERTSTRING:
911 case LB_FINDSTRING:
912 case LB_FINDSTRINGEXACT:
913 case LB_SELECTSTRING:
914 case CB_ADDSTRING:
915 case CB_INSERTSTRING:
916 case CB_FINDSTRING:
917 case CB_FINDSTRINGEXACT:
918 case CB_SELECTSTRING:
919 if ( WINPROC_TestLBForStr( hwnd, msg ))
920 HeapFree( GetProcessHeap(), 0, (void *)lParam );
921 break;
923 case LB_GETTEXT:
924 case CB_GETLBTEXT:
925 if ( WINPROC_TestLBForStr( hwnd, msg ))
927 LPARAM *ptr = (LPARAM *)lParam - 1;
928 if (result >= 0)
929 result = WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
930 (LPSTR)*ptr, 0x7fffffff, NULL, NULL ) - 1;
931 HeapFree( GetProcessHeap(), 0, ptr );
933 break;
935 /* Multiline edit */
936 case EM_GETLINE:
938 LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lParam */
939 WORD len = *(WORD *) lParam;
940 result = WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, result,
941 (LPSTR)*ptr, len, NULL, NULL );
942 if (result < len) ((LPSTR)*ptr)[result] = 0;
943 HeapFree( GetProcessHeap(), 0, ptr );
945 break;
947 return result;
951 static UINT convert_handle_16_to_32(HANDLE16 src, unsigned int flags)
953 HANDLE dst;
954 UINT sz = GlobalSize16(src);
955 LPSTR ptr16, ptr32;
957 if (!(dst = GlobalAlloc(flags, sz)))
958 return 0;
959 ptr16 = GlobalLock16(src);
960 ptr32 = GlobalLock(dst);
961 if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr32, ptr16, sz);
962 GlobalUnlock16(src);
963 GlobalUnlock(dst);
965 return (UINT)dst;
968 /**********************************************************************
969 * WINPROC_MapMsg16To32A
971 * Map a message from 16- to 32-bit Ansi.
972 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
974 INT WINPROC_MapMsg16To32A( HWND hwnd, UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
975 WPARAM *pwparam32, LPARAM *plparam )
977 *pmsg32 = (UINT)msg16;
978 *pwparam32 = (WPARAM)wParam16;
979 switch(msg16)
981 case WM_ACTIVATE:
982 case WM_CHARTOITEM:
983 case WM_COMMAND:
984 case WM_VKEYTOITEM:
985 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
986 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
987 return 0;
988 case WM_HSCROLL:
989 case WM_VSCROLL:
990 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
991 *plparam = (LPARAM)WIN_Handle32( HIWORD(*plparam) );
992 return 0;
993 case WM_CTLCOLOR:
994 if ( HIWORD(*plparam) > CTLCOLOR_STATIC ) return -1;
995 *pmsg32 = WM_CTLCOLORMSGBOX + HIWORD(*plparam);
996 *pwparam32 = (WPARAM)HDC_32(wParam16);
997 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
998 return 0;
999 case WM_COMPAREITEM:
1001 COMPAREITEMSTRUCT16* cis16 = MapSL(*plparam);
1002 COMPAREITEMSTRUCT *cis = HeapAlloc(GetProcessHeap(), 0, sizeof(*cis));
1003 if (!cis) return -1;
1004 cis->CtlType = cis16->CtlType;
1005 cis->CtlID = cis16->CtlID;
1006 cis->hwndItem = WIN_Handle32( cis16->hwndItem );
1007 cis->itemID1 = cis16->itemID1;
1008 cis->itemData1 = cis16->itemData1;
1009 cis->itemID2 = cis16->itemID2;
1010 cis->itemData2 = cis16->itemData2;
1011 cis->dwLocaleId = 0; /* FIXME */
1012 *plparam = (LPARAM)cis;
1014 return 1;
1015 case WM_COPYDATA:
1017 PCOPYDATASTRUCT16 pcds16 = MapSL(*plparam);
1018 PCOPYDATASTRUCT pcds = HeapAlloc ( GetProcessHeap(), 0, sizeof(*pcds));
1019 pcds->dwData = pcds16->dwData;
1020 pcds->cbData = pcds16->cbData;
1021 pcds->lpData = MapSL( pcds16->lpData);
1022 *plparam = (LPARAM)pcds;
1024 return 1;
1025 case WM_DELETEITEM:
1027 DELETEITEMSTRUCT16* dis16 = MapSL(*plparam);
1028 DELETEITEMSTRUCT *dis = HeapAlloc(GetProcessHeap(), 0, sizeof(*dis));
1029 if (!dis) return -1;
1030 dis->CtlType = dis16->CtlType;
1031 dis->CtlID = dis16->CtlID;
1032 dis->hwndItem = WIN_Handle32( dis16->hwndItem );
1033 dis->itemData = dis16->itemData;
1034 *plparam = (LPARAM)dis;
1036 return 1;
1037 case WM_MEASUREITEM:
1039 MEASUREITEMSTRUCT16* mis16 = MapSL(*plparam);
1040 MEASUREITEMSTRUCT *mis = HeapAlloc(GetProcessHeap(), 0,
1041 sizeof(*mis) + sizeof(LPARAM));
1042 if (!mis) return -1;
1043 mis->CtlType = mis16->CtlType;
1044 mis->CtlID = mis16->CtlID;
1045 mis->itemID = mis16->itemID;
1046 mis->itemWidth = mis16->itemWidth;
1047 mis->itemHeight = mis16->itemHeight;
1048 mis->itemData = mis16->itemData;
1049 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
1050 *plparam = (LPARAM)mis;
1052 return 1;
1053 case WM_DRAWITEM:
1055 DRAWITEMSTRUCT16* dis16 = MapSL(*plparam);
1056 DRAWITEMSTRUCT *dis = HeapAlloc(GetProcessHeap(), 0, sizeof(*dis));
1057 if (!dis) return -1;
1058 dis->CtlType = dis16->CtlType;
1059 dis->CtlID = dis16->CtlID;
1060 dis->itemID = dis16->itemID;
1061 dis->itemAction = dis16->itemAction;
1062 dis->itemState = dis16->itemState;
1063 dis->hwndItem = (dis->CtlType == ODT_MENU) ? (HWND)HMENU_32(dis16->hwndItem)
1064 : WIN_Handle32( dis16->hwndItem );
1065 dis->hDC = HDC_32(dis16->hDC);
1066 dis->itemData = dis16->itemData;
1067 dis->rcItem.left = dis16->rcItem.left;
1068 dis->rcItem.top = dis16->rcItem.top;
1069 dis->rcItem.right = dis16->rcItem.right;
1070 dis->rcItem.bottom = dis16->rcItem.bottom;
1071 *plparam = (LPARAM)dis;
1073 return 1;
1074 case WM_GETMINMAXINFO:
1076 MINMAXINFO *mmi = HeapAlloc( GetProcessHeap(), 0, sizeof(*mmi) + sizeof(LPARAM));
1077 if (!mmi) return -1;
1078 MINMAXINFO16to32( MapSL(*plparam), mmi );
1079 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
1080 *plparam = (LPARAM)mmi;
1082 return 1;
1083 case WM_GETTEXT:
1084 case WM_SETTEXT:
1085 case WM_WININICHANGE:
1086 case WM_DEVMODECHANGE:
1087 case WM_ASKCBFORMATNAME:
1088 *plparam = (LPARAM)MapSL(*plparam);
1089 return 0;
1090 case WM_MDICREATE:
1092 MDICREATESTRUCT16 *cs16 = MapSL(*plparam);
1093 MDICREATESTRUCTA *cs = HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) + sizeof(LPARAM) );
1094 if (!cs) return -1;
1095 MDICREATESTRUCT16to32A( cs16, cs );
1096 cs->szTitle = MapSL(cs16->szTitle);
1097 cs->szClass = MapSL(cs16->szClass);
1098 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1099 *plparam = (LPARAM)cs;
1101 return 1;
1102 case WM_MDIGETACTIVE:
1103 *plparam = (LPARAM)HeapAlloc( GetProcessHeap(), 0, sizeof(BOOL) );
1104 *(BOOL*)(*plparam) = 0;
1105 return 1;
1106 case WM_MDISETMENU:
1107 if(wParam16) *pmsg32=WM_MDIREFRESHMENU;
1108 *pwparam32 = (WPARAM)HMENU_32(LOWORD(*plparam));
1109 *plparam = (LPARAM)HMENU_32(HIWORD(*plparam));
1110 return 0;
1111 case WM_MENUCHAR:
1112 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1113 *plparam = (LPARAM)HMENU_32(HIWORD(*plparam));
1114 return 0;
1115 case WM_MENUSELECT:
1116 if((LOWORD(*plparam) & MF_POPUP) && (LOWORD(*plparam) != 0xFFFF))
1118 HMENU hmenu=HMENU_32(HIWORD(*plparam));
1119 UINT Pos=MENU_FindSubMenu( &hmenu, HMENU_32(wParam16));
1120 if(Pos==0xFFFF) Pos=0; /* NO_SELECTED_ITEM */
1121 *pwparam32 = MAKEWPARAM( Pos, LOWORD(*plparam) );
1123 else *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1124 *plparam = (LPARAM)HMENU_32(HIWORD(*plparam));
1125 return 0;
1126 case WM_MDIACTIVATE:
1127 if( *plparam )
1129 *pwparam32 = (WPARAM)WIN_Handle32( HIWORD(*plparam) );
1130 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1132 else /* message sent to MDI client */
1133 *pwparam32 = wParam16;
1134 return 0;
1135 case WM_NCCALCSIZE:
1137 NCCALCSIZE_PARAMS16 *nc16;
1138 NCCALCSIZE_PARAMS *nc;
1140 nc = HeapAlloc( GetProcessHeap(), 0, sizeof(*nc) + sizeof(LPARAM) );
1141 if (!nc) return -1;
1142 nc16 = MapSL(*plparam);
1143 nc->rgrc[0].left = nc16->rgrc[0].left;
1144 nc->rgrc[0].top = nc16->rgrc[0].top;
1145 nc->rgrc[0].right = nc16->rgrc[0].right;
1146 nc->rgrc[0].bottom = nc16->rgrc[0].bottom;
1147 if (wParam16)
1149 nc->lppos = HeapAlloc( GetProcessHeap(), 0, sizeof(*nc->lppos) );
1150 nc->rgrc[1].left = nc16->rgrc[1].left;
1151 nc->rgrc[1].top = nc16->rgrc[1].top;
1152 nc->rgrc[1].right = nc16->rgrc[1].right;
1153 nc->rgrc[1].bottom = nc16->rgrc[1].bottom;
1154 nc->rgrc[2].left = nc16->rgrc[2].left;
1155 nc->rgrc[2].top = nc16->rgrc[2].top;
1156 nc->rgrc[2].right = nc16->rgrc[2].right;
1157 nc->rgrc[2].bottom = nc16->rgrc[2].bottom;
1158 if (nc->lppos) WINDOWPOS16to32( MapSL(nc16->lppos), nc->lppos );
1160 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
1161 *plparam = (LPARAM)nc;
1163 return 1;
1164 case WM_NCCREATE:
1165 case WM_CREATE:
1167 CREATESTRUCT16 *cs16 = MapSL(*plparam);
1168 CREATESTRUCTA *cs = HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) + sizeof(LPARAM) );
1169 if (!cs) return -1;
1170 CREATESTRUCT16to32A( cs16, cs );
1171 cs->lpszName = MapSL(cs16->lpszName);
1172 cs->lpszClass = MapSL(cs16->lpszClass);
1174 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1176 MDICREATESTRUCT16 *mdi_cs16;
1177 MDICREATESTRUCTA *mdi_cs = HeapAlloc(GetProcessHeap(), 0, sizeof(*mdi_cs));
1178 if (!mdi_cs)
1180 HeapFree(GetProcessHeap(), 0, cs);
1181 return -1;
1183 mdi_cs16 = (MDICREATESTRUCT16 *)MapSL(cs16->lpCreateParams);
1184 MDICREATESTRUCT16to32A(mdi_cs16, mdi_cs);
1185 mdi_cs->szTitle = MapSL(mdi_cs16->szTitle);
1186 mdi_cs->szClass = MapSL(mdi_cs16->szClass);
1188 cs->lpCreateParams = mdi_cs;
1190 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1191 *plparam = (LPARAM)cs;
1193 return 1;
1194 case WM_PARENTNOTIFY:
1195 if ((wParam16 == WM_CREATE) || (wParam16 == WM_DESTROY))
1197 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
1198 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1200 return 0;
1201 case WM_WINDOWPOSCHANGING:
1202 case WM_WINDOWPOSCHANGED:
1204 WINDOWPOS *wp = HeapAlloc( GetProcessHeap(), 0, sizeof(*wp) + sizeof(LPARAM) );
1205 if (!wp) return -1;
1206 WINDOWPOS16to32( MapSL(*plparam), wp );
1207 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
1208 *plparam = (LPARAM)wp;
1210 return 1;
1211 case WM_GETDLGCODE:
1212 if (*plparam)
1214 LPMSG16 msg16 = MapSL(*plparam);
1215 LPMSG msg32 = HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1217 if (!msg32) return -1;
1218 msg32->hwnd = WIN_Handle32( msg16->hwnd );
1219 msg32->message = msg16->message;
1220 msg32->wParam = msg16->wParam;
1221 msg32->lParam = msg16->lParam;
1222 msg32->time = msg16->time;
1223 msg32->pt.x = msg16->pt.x;
1224 msg32->pt.y = msg16->pt.y;
1225 *plparam = (LPARAM)msg32;
1226 return 1;
1228 else return 0;
1229 case WM_NOTIFY:
1230 *plparam = (LPARAM)MapSL(*plparam);
1231 return 0;
1232 case WM_ACTIVATEAPP:
1233 /* We need this when SetActiveWindow sends a Sendmessage16() to
1234 * a 32bit window. Might be superflous with 32bit interprocess
1235 * message queues. */
1236 if (*plparam) *plparam = HTASK_32( *plparam );
1237 return 0;
1238 case WM_NEXTMENU:
1240 MDINEXTMENU *next = HeapAlloc( GetProcessHeap(), 0, sizeof(*next) );
1241 if (!next) return -1;
1242 next->hmenuIn = (HMENU)*plparam;
1243 next->hmenuNext = 0;
1244 next->hwndNext = 0;
1245 *plparam = (LPARAM)next;
1246 return 1;
1248 case WM_PAINTCLIPBOARD:
1249 case WM_SIZECLIPBOARD:
1250 FIXME_(msg)("message %04x needs translation\n",msg16 );
1251 return -1;
1252 case WM_DDE_INITIATE:
1253 case WM_DDE_TERMINATE:
1254 case WM_DDE_UNADVISE:
1255 case WM_DDE_REQUEST:
1256 *pwparam32 = (WPARAM)WIN_Handle32(wParam16);
1257 return 0;
1258 case WM_DDE_ADVISE:
1259 case WM_DDE_DATA:
1260 case WM_DDE_POKE:
1262 HANDLE16 lo16;
1263 ATOM hi;
1264 UINT lo32 = 0;
1266 *pwparam32 = (WPARAM)WIN_Handle32(wParam16);
1267 lo16 = LOWORD(*plparam);
1268 hi = HIWORD(*plparam);
1269 if (lo16 && !(lo32 = convert_handle_16_to_32(lo16, GMEM_DDESHARE)))
1270 return -1;
1271 *plparam = PackDDElParam(msg16, lo32, hi);
1273 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
1274 case WM_DDE_ACK:
1276 UINT lo, hi;
1277 int flag = 0;
1278 char buf[2];
1280 *pwparam32 = (WPARAM)WIN_Handle32(wParam16);
1282 lo = LOWORD(*plparam);
1283 hi = HIWORD(*plparam);
1285 if (GlobalGetAtomNameA(hi, buf, 2) > 0) flag |= 1;
1286 if (GlobalSize16(hi) != 0) flag |= 2;
1287 switch (flag)
1289 case 0:
1290 if (hi)
1292 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
1293 hi = 0;
1295 break;
1296 case 1:
1297 break; /* atom, nothing to do */
1298 case 3:
1299 MESSAGE("DDE_ACK: %x both atom and handle... choosing handle\n", hi);
1300 /* fall thru */
1301 case 2:
1302 hi = convert_handle_16_to_32(hi, GMEM_DDESHARE);
1303 break;
1305 *plparam = PackDDElParam(WM_DDE_ACK, lo, hi);
1307 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
1308 case WM_DDE_EXECUTE:
1309 *plparam = convert_handle_16_to_32(*plparam, GMEM_DDESHARE);
1310 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
1311 default: /* No translation needed */
1312 return 0;
1317 /**********************************************************************
1318 * WINPROC_UnmapMsg16To32A
1320 * Unmap a message that was mapped from 16- to 32-bit Ansi.
1322 LRESULT WINPROC_UnmapMsg16To32A( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1323 LRESULT result )
1325 switch(msg)
1327 case WM_COMPAREITEM:
1328 case WM_DELETEITEM:
1329 case WM_DRAWITEM:
1330 case WM_COPYDATA:
1331 HeapFree( GetProcessHeap(), 0, (LPVOID)lParam );
1332 break;
1333 case WM_MEASUREITEM:
1335 MEASUREITEMSTRUCT16 *mis16;
1336 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lParam;
1337 lParam = *(LPARAM *)(mis + 1);
1338 mis16 = MapSL(lParam);
1339 mis16->itemWidth = (UINT16)mis->itemWidth;
1340 mis16->itemHeight = (UINT16)mis->itemHeight;
1341 HeapFree( GetProcessHeap(), 0, mis );
1343 break;
1344 case WM_GETMINMAXINFO:
1346 MINMAXINFO *mmi = (MINMAXINFO *)lParam;
1347 lParam = *(LPARAM *)(mmi + 1);
1348 MINMAXINFO32to16( mmi, MapSL(lParam));
1349 HeapFree( GetProcessHeap(), 0, mmi );
1351 break;
1352 case WM_MDICREATE:
1354 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
1355 lParam = *(LPARAM *)(cs + 1);
1356 MDICREATESTRUCT32Ato16( cs, MapSL(lParam) );
1357 HeapFree( GetProcessHeap(), 0, cs );
1359 break;
1360 case WM_MDIGETACTIVE:
1361 result = MAKELONG( LOWORD(result), (BOOL16)(*(BOOL *)lParam) );
1362 HeapFree( GetProcessHeap(), 0, (BOOL *)lParam );
1363 break;
1364 case WM_NCCALCSIZE:
1366 NCCALCSIZE_PARAMS16 *nc16;
1367 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lParam;
1368 lParam = *(LPARAM *)(nc + 1);
1369 nc16 = MapSL(lParam);
1370 nc16->rgrc[0].left = nc->rgrc[0].left;
1371 nc16->rgrc[0].top = nc->rgrc[0].top;
1372 nc16->rgrc[0].right = nc->rgrc[0].right;
1373 nc16->rgrc[0].bottom = nc->rgrc[0].bottom;
1374 if (wParam)
1376 nc16->rgrc[1].left = nc->rgrc[1].left;
1377 nc16->rgrc[1].top = nc->rgrc[1].top;
1378 nc16->rgrc[1].right = nc->rgrc[1].right;
1379 nc16->rgrc[1].bottom = nc->rgrc[1].bottom;
1380 nc16->rgrc[2].left = nc->rgrc[2].left;
1381 nc16->rgrc[2].top = nc->rgrc[2].top;
1382 nc16->rgrc[2].right = nc->rgrc[2].right;
1383 nc16->rgrc[2].bottom = nc->rgrc[2].bottom;
1384 if (nc->lppos)
1386 WINDOWPOS32to16( nc->lppos, MapSL(nc16->lppos));
1387 HeapFree( GetProcessHeap(), 0, nc->lppos );
1390 HeapFree( GetProcessHeap(), 0, nc );
1392 break;
1393 case WM_NCCREATE:
1394 case WM_CREATE:
1396 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
1397 lParam = *(LPARAM *)(cs + 1);
1398 CREATESTRUCT32Ato16( cs, MapSL(lParam) );
1400 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1401 HeapFree(GetProcessHeap(), 0, cs->lpCreateParams);
1403 HeapFree( GetProcessHeap(), 0, cs );
1405 break;
1406 case WM_WINDOWPOSCHANGING:
1407 case WM_WINDOWPOSCHANGED:
1409 WINDOWPOS *wp = (WINDOWPOS *)lParam;
1410 lParam = *(LPARAM *)(wp + 1);
1411 WINDOWPOS32to16(wp, MapSL(lParam));
1412 HeapFree( GetProcessHeap(), 0, wp );
1414 break;
1415 case WM_GETDLGCODE:
1416 if (lParam)
1418 LPMSG msg32 = (LPMSG)lParam;
1419 HeapFree( GetProcessHeap(), 0, msg32 );
1421 break;
1422 case WM_NEXTMENU:
1424 MDINEXTMENU *next = (MDINEXTMENU *)lParam;
1425 result = MAKELONG( HMENU_16(next->hmenuNext), HWND_16(next->hwndNext) );
1426 HeapFree( GetProcessHeap(), 0, next );
1428 break;
1430 return result;
1434 /**********************************************************************
1435 * WINPROC_MapMsg16To32W
1437 * Map a message from 16- to 32-bit Unicode.
1438 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1440 INT WINPROC_MapMsg16To32W( HWND hwnd, UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
1441 WPARAM *pwparam32, LPARAM *plparam )
1443 *pmsg32=(UINT)msg16;
1444 *pwparam32 = (WPARAM)wParam16;
1445 switch(msg16)
1447 case WM_GETTEXT:
1448 case WM_SETTEXT:
1449 case WM_WININICHANGE:
1450 case WM_DEVMODECHANGE:
1451 case WM_ASKCBFORMATNAME:
1452 *plparam = (LPARAM)MapSL(*plparam);
1453 return WINPROC_MapMsg32ATo32W( hwnd, *pmsg32, pwparam32, plparam );
1454 case WM_GETTEXTLENGTH:
1455 case CB_GETLBTEXTLEN:
1456 case LB_GETTEXTLEN:
1457 return 1; /* need to map result */
1458 case WM_NCCREATE:
1459 case WM_CREATE:
1461 CREATESTRUCT16 *cs16 = MapSL(*plparam);
1462 CREATESTRUCTW *cs = HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) + sizeof(LPARAM) );
1463 if (!cs) return -1;
1464 CREATESTRUCT16to32A( cs16, (CREATESTRUCTA *)cs );
1465 cs->lpszName = map_str_16_to_32W(cs16->lpszName);
1466 cs->lpszClass = map_str_16_to_32W(cs16->lpszClass);
1468 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1470 MDICREATESTRUCT16 *mdi_cs16;
1471 MDICREATESTRUCTW *mdi_cs = HeapAlloc(GetProcessHeap(), 0, sizeof(*mdi_cs));
1472 if (!mdi_cs)
1474 HeapFree(GetProcessHeap(), 0, cs);
1475 return -1;
1477 mdi_cs16 = (MDICREATESTRUCT16 *)MapSL(cs16->lpCreateParams);
1478 MDICREATESTRUCT16to32A(mdi_cs16, (MDICREATESTRUCTA *)mdi_cs);
1479 mdi_cs->szTitle = map_str_16_to_32W(mdi_cs16->szTitle);
1480 mdi_cs->szClass = map_str_16_to_32W(mdi_cs16->szClass);
1482 cs->lpCreateParams = mdi_cs;
1484 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1485 *plparam = (LPARAM)cs;
1487 return 1;
1488 case WM_MDICREATE:
1490 MDICREATESTRUCT16 *cs16 = MapSL(*plparam);
1491 MDICREATESTRUCTW *cs = HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) + sizeof(LPARAM) );
1492 if (!cs) return -1;
1493 MDICREATESTRUCT16to32A( cs16, (MDICREATESTRUCTA *)cs );
1494 cs->szTitle = map_str_16_to_32W(cs16->szTitle);
1495 cs->szClass = map_str_16_to_32W(cs16->szClass);
1496 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1497 *plparam = (LPARAM)cs;
1499 return 1;
1500 case WM_GETDLGCODE:
1501 if (*plparam)
1503 LPMSG16 msg16 = MapSL(*plparam);
1504 LPMSG msg32 = HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1506 if (!msg32) return -1;
1507 msg32->hwnd = WIN_Handle32( msg16->hwnd );
1508 msg32->message = msg16->message;
1509 msg32->wParam = msg16->wParam;
1510 msg32->lParam = msg16->lParam;
1511 msg32->time = msg16->time;
1512 msg32->pt.x = msg16->pt.x;
1513 msg32->pt.y = msg16->pt.y;
1514 switch(msg32->message)
1516 case WM_CHAR:
1517 case WM_DEADCHAR:
1518 case WM_SYSCHAR:
1519 case WM_SYSDEADCHAR:
1520 msg32->wParam = map_wparam_char_AtoW( msg16->wParam, 1 );
1521 break;
1523 *plparam = (LPARAM)msg32;
1524 return 1;
1526 else return 0;
1528 case WM_CHARTOITEM:
1529 *pwparam32 = MAKEWPARAM( map_wparam_char_AtoW( wParam16, 1 ), HIWORD(*plparam) );
1530 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1531 return 0;
1532 case WM_MENUCHAR:
1533 *pwparam32 = MAKEWPARAM( map_wparam_char_AtoW( wParam16, 1 ), LOWORD(*plparam) );
1534 *plparam = (LPARAM)HMENU_32(HIWORD(*plparam));
1535 return 0;
1536 case WM_CHAR:
1537 case WM_DEADCHAR:
1538 case WM_SYSCHAR:
1539 case WM_SYSDEADCHAR:
1540 *pwparam32 = map_wparam_char_AtoW( wParam16, 1 );
1541 return 0;
1542 case WM_IME_CHAR:
1543 *pwparam32 = map_wparam_char_AtoW( wParam16, 2 );
1544 return 0;
1546 default: /* No Unicode translation needed */
1547 return WINPROC_MapMsg16To32A( hwnd, msg16, wParam16, pmsg32,
1548 pwparam32, plparam );
1553 /**********************************************************************
1554 * WINPROC_UnmapMsg16To32W
1556 * Unmap a message that was mapped from 16- to 32-bit Unicode.
1558 LRESULT WINPROC_UnmapMsg16To32W( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1559 LRESULT result, WNDPROC dispatch )
1561 switch(msg)
1563 case WM_GETTEXT:
1564 case WM_SETTEXT:
1565 case WM_GETTEXTLENGTH:
1566 case CB_GETLBTEXTLEN:
1567 case LB_GETTEXTLEN:
1568 case WM_ASKCBFORMATNAME:
1569 return WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam, result, dispatch );
1570 case WM_NCCREATE:
1571 case WM_CREATE:
1573 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
1574 lParam = *(LPARAM *)(cs + 1);
1575 CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs, MapSL(lParam) );
1576 unmap_str_16_to_32W( cs->lpszName );
1577 unmap_str_16_to_32W( cs->lpszClass );
1579 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1581 MDICREATESTRUCTW *mdi_cs = (MDICREATESTRUCTW *)cs->lpCreateParams;
1582 unmap_str_16_to_32W( mdi_cs->szTitle );
1583 unmap_str_16_to_32W( mdi_cs->szClass );
1584 HeapFree(GetProcessHeap(), 0, cs->lpCreateParams);
1586 HeapFree( GetProcessHeap(), 0, cs );
1588 break;
1589 case WM_MDICREATE:
1591 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
1592 lParam = *(LPARAM *)(cs + 1);
1593 MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs, MapSL(lParam) );
1594 unmap_str_16_to_32W( cs->szTitle );
1595 unmap_str_16_to_32W( cs->szClass );
1596 HeapFree( GetProcessHeap(), 0, cs );
1598 break;
1599 case WM_GETDLGCODE:
1600 if (lParam)
1602 LPMSG msg32 = (LPMSG)lParam;
1603 HeapFree( GetProcessHeap(), 0, msg32 );
1605 break;
1606 default:
1607 return WINPROC_UnmapMsg16To32A( hwnd, msg, wParam, lParam, result );
1609 return result;
1612 static HANDLE16 convert_handle_32_to_16(UINT src, unsigned int flags)
1614 HANDLE16 dst;
1615 UINT sz = GlobalSize((HANDLE)src);
1616 LPSTR ptr16, ptr32;
1618 if (!(dst = GlobalAlloc16(flags, sz)))
1619 return 0;
1620 ptr32 = GlobalLock((HANDLE)src);
1621 ptr16 = GlobalLock16(dst);
1622 if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr16, ptr32, sz);
1623 GlobalUnlock((HANDLE)src);
1624 GlobalUnlock16(dst);
1626 return dst;
1630 /**********************************************************************
1631 * WINPROC_MapMsg32ATo16
1633 * Map a message from 32-bit Ansi to 16-bit.
1634 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1636 INT WINPROC_MapMsg32ATo16( HWND hwnd, UINT msg32, WPARAM wParam32,
1637 UINT16 *pmsg16, WPARAM16 *pwparam16,
1638 LPARAM *plparam )
1640 *pmsg16 = (UINT16)msg32;
1641 *pwparam16 = (WPARAM16)LOWORD(wParam32);
1642 switch(msg32)
1644 case SBM_SETRANGE:
1645 *pmsg16 = SBM_SETRANGE16;
1646 *plparam = MAKELPARAM(wParam32, *plparam);
1647 *pwparam16 = 0;
1648 return 0;
1650 case SBM_GETRANGE:
1651 *pmsg16 = SBM_GETRANGE16;
1652 return 1;
1654 case BM_GETCHECK:
1655 case BM_SETCHECK:
1656 case BM_GETSTATE:
1657 case BM_SETSTATE:
1658 case BM_SETSTYLE:
1659 *pmsg16 = (UINT16)msg32 + (BM_GETCHECK16 - BM_GETCHECK);
1660 return 0;
1662 case EM_GETSEL:
1663 case EM_GETRECT:
1664 case EM_SETRECT:
1665 case EM_SETRECTNP:
1666 case EM_SCROLL:
1667 case EM_LINESCROLL:
1668 case EM_SCROLLCARET:
1669 case EM_GETMODIFY:
1670 case EM_SETMODIFY:
1671 case EM_GETLINECOUNT:
1672 case EM_LINEINDEX:
1673 case EM_SETHANDLE:
1674 case EM_GETHANDLE:
1675 case EM_GETTHUMB:
1676 case EM_LINELENGTH:
1677 case EM_REPLACESEL:
1678 case EM_GETLINE:
1679 case EM_LIMITTEXT:
1680 case EM_CANUNDO:
1681 case EM_UNDO:
1682 case EM_FMTLINES:
1683 case EM_LINEFROMCHAR:
1684 case EM_SETTABSTOPS:
1685 case EM_SETPASSWORDCHAR:
1686 case EM_EMPTYUNDOBUFFER:
1687 case EM_GETFIRSTVISIBLELINE:
1688 case EM_SETREADONLY:
1689 case EM_SETWORDBREAKPROC:
1690 case EM_GETWORDBREAKPROC:
1691 case EM_GETPASSWORDCHAR:
1692 *pmsg16 = (UINT16)msg32 + (EM_GETSEL16 - EM_GETSEL);
1693 return 0;
1695 case LB_CARETOFF:
1696 case LB_CARETON:
1697 case LB_DELETESTRING:
1698 case LB_GETANCHORINDEX:
1699 case LB_GETCARETINDEX:
1700 case LB_GETCOUNT:
1701 case LB_GETCURSEL:
1702 case LB_GETHORIZONTALEXTENT:
1703 case LB_GETITEMDATA:
1704 case LB_GETITEMHEIGHT:
1705 case LB_GETSEL:
1706 case LB_GETSELCOUNT:
1707 case LB_GETTEXTLEN:
1708 case LB_GETTOPINDEX:
1709 case LB_RESETCONTENT:
1710 case LB_SELITEMRANGE:
1711 case LB_SELITEMRANGEEX:
1712 case LB_SETANCHORINDEX:
1713 case LB_SETCARETINDEX:
1714 case LB_SETCOLUMNWIDTH:
1715 case LB_SETCURSEL:
1716 case LB_SETHORIZONTALEXTENT:
1717 case LB_SETITEMDATA:
1718 case LB_SETITEMHEIGHT:
1719 case LB_SETSEL:
1720 case LB_SETTOPINDEX:
1721 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
1722 return 0;
1723 case CB_DELETESTRING:
1724 case CB_GETCOUNT:
1725 case CB_GETLBTEXTLEN:
1726 case CB_LIMITTEXT:
1727 case CB_RESETCONTENT:
1728 case CB_SETEDITSEL:
1729 case CB_GETCURSEL:
1730 case CB_SETCURSEL:
1731 case CB_SHOWDROPDOWN:
1732 case CB_SETITEMDATA:
1733 case CB_SETITEMHEIGHT:
1734 case CB_GETITEMHEIGHT:
1735 case CB_SETEXTENDEDUI:
1736 case CB_GETEXTENDEDUI:
1737 case CB_GETDROPPEDSTATE:
1738 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
1739 return 0;
1740 case CB_GETEDITSEL:
1741 *pmsg16 = CB_GETEDITSEL16;
1742 return 1;
1744 case LB_ADDSTRING:
1745 case LB_FINDSTRING:
1746 case LB_FINDSTRINGEXACT:
1747 case LB_INSERTSTRING:
1748 case LB_SELECTSTRING:
1749 case LB_DIR:
1750 case LB_ADDFILE:
1751 *plparam = (LPARAM)MapLS( (LPSTR)*plparam );
1752 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
1753 return 1;
1755 case CB_ADDSTRING:
1756 case CB_FINDSTRING:
1757 case CB_FINDSTRINGEXACT:
1758 case CB_INSERTSTRING:
1759 case CB_SELECTSTRING:
1760 case CB_DIR:
1761 *plparam = (LPARAM)MapLS( (LPSTR)*plparam );
1762 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
1763 return 1;
1765 case LB_GETITEMRECT:
1767 RECT16 *rect = HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16) + sizeof(LPARAM) );
1768 if (!rect) return -1;
1769 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
1770 *plparam = MapLS( rect );
1772 *pmsg16 = LB_GETITEMRECT16;
1773 return 1;
1774 case LB_GETSELITEMS:
1776 LPARAM *items; /* old LPARAM first, then *pwparam16 x INT16 entries */
1778 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
1779 if (!(items = HeapAlloc( GetProcessHeap(), 0,
1780 *pwparam16 * sizeof(INT16) + sizeof(LPARAM)))) return -1;
1781 *items++ = *plparam; /* Store the previous lParam */
1782 *plparam = MapLS( items );
1784 *pmsg16 = LB_GETSELITEMS16;
1785 return 1;
1786 case LB_SETTABSTOPS:
1787 if (wParam32)
1789 INT i;
1790 LPINT16 stops;
1791 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
1792 if (!(stops = HeapAlloc( GetProcessHeap(), 0,
1793 *pwparam16 * sizeof(INT16) + sizeof(LPARAM)))) return -1;
1794 for (i = 0; i < *pwparam16; i++) stops[i] = *((LPINT)*plparam+i);
1795 *plparam = MapLS( stops );
1796 return 1;
1798 *pmsg16 = LB_SETTABSTOPS16;
1799 return 0;
1801 case CB_GETDROPPEDCONTROLRECT:
1803 RECT16 *rect = HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16) + sizeof(LPARAM) );
1804 if (!rect) return -1;
1805 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
1806 *plparam = (LPARAM)MapLS(rect);
1808 *pmsg16 = CB_GETDROPPEDCONTROLRECT16;
1809 return 1;
1811 case LB_GETTEXT:
1812 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
1813 *pmsg16 = LB_GETTEXT16;
1814 return 1;
1816 case CB_GETLBTEXT:
1817 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
1818 *pmsg16 = CB_GETLBTEXT16;
1819 return 1;
1821 case EM_SETSEL:
1822 *pwparam16 = 0;
1823 *plparam = MAKELONG( (INT16)(INT)wParam32, (INT16)*plparam );
1824 *pmsg16 = EM_SETSEL16;
1825 return 0;
1827 case WM_ACTIVATE:
1828 case WM_CHARTOITEM:
1829 case WM_COMMAND:
1830 case WM_VKEYTOITEM:
1831 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
1832 return 0;
1833 case WM_HSCROLL:
1834 case WM_VSCROLL:
1835 *plparam = MAKELPARAM( HIWORD(wParam32), (HWND16)*plparam );
1836 return 0;
1837 case WM_COPYDATA:
1839 PCOPYDATASTRUCT pcds32 = (PCOPYDATASTRUCT) *plparam;
1840 PCOPYDATASTRUCT16 pcds = HeapAlloc( GetProcessHeap(), 0, sizeof( *pcds));
1841 pcds->dwData = pcds32->dwData;
1842 pcds->cbData = pcds32->cbData;
1843 pcds->lpData = MapLS( pcds32->lpData);
1844 *plparam = MapLS( pcds );
1846 return 1;
1847 case WM_CTLCOLORMSGBOX:
1848 case WM_CTLCOLOREDIT:
1849 case WM_CTLCOLORLISTBOX:
1850 case WM_CTLCOLORBTN:
1851 case WM_CTLCOLORDLG:
1852 case WM_CTLCOLORSCROLLBAR:
1853 case WM_CTLCOLORSTATIC:
1854 *pmsg16 = WM_CTLCOLOR;
1855 *plparam = MAKELPARAM( (HWND16)*plparam,
1856 (WORD)msg32 - WM_CTLCOLORMSGBOX );
1857 return 0;
1858 case WM_COMPAREITEM:
1860 COMPAREITEMSTRUCT *cis32 = (COMPAREITEMSTRUCT *)*plparam;
1861 COMPAREITEMSTRUCT16 *cis = HeapAlloc( GetProcessHeap(), 0, sizeof(COMPAREITEMSTRUCT16));
1862 if (!cis) return -1;
1863 cis->CtlType = (UINT16)cis32->CtlType;
1864 cis->CtlID = (UINT16)cis32->CtlID;
1865 cis->hwndItem = HWND_16( cis32->hwndItem );
1866 cis->itemID1 = (UINT16)cis32->itemID1;
1867 cis->itemData1 = cis32->itemData1;
1868 cis->itemID2 = (UINT16)cis32->itemID2;
1869 cis->itemData2 = cis32->itemData2;
1870 *plparam = MapLS( cis );
1872 return 1;
1873 case WM_DELETEITEM:
1875 DELETEITEMSTRUCT *dis32 = (DELETEITEMSTRUCT *)*plparam;
1876 DELETEITEMSTRUCT16 *dis = HeapAlloc( GetProcessHeap(), 0, sizeof(DELETEITEMSTRUCT16) );
1877 if (!dis) return -1;
1878 dis->CtlType = (UINT16)dis32->CtlType;
1879 dis->CtlID = (UINT16)dis32->CtlID;
1880 dis->itemID = (UINT16)dis32->itemID;
1881 dis->hwndItem = (dis->CtlType == ODT_MENU) ? (HWND16)LOWORD(dis32->hwndItem)
1882 : HWND_16( dis32->hwndItem );
1883 dis->itemData = dis32->itemData;
1884 *plparam = MapLS( dis );
1886 return 1;
1887 case WM_DRAWITEM:
1889 DRAWITEMSTRUCT *dis32 = (DRAWITEMSTRUCT *)*plparam;
1890 DRAWITEMSTRUCT16 *dis = HeapAlloc( GetProcessHeap(), 0, sizeof(DRAWITEMSTRUCT16) );
1891 if (!dis) return -1;
1892 dis->CtlType = (UINT16)dis32->CtlType;
1893 dis->CtlID = (UINT16)dis32->CtlID;
1894 dis->itemID = (UINT16)dis32->itemID;
1895 dis->itemAction = (UINT16)dis32->itemAction;
1896 dis->itemState = (UINT16)dis32->itemState;
1897 dis->hwndItem = HWND_16( dis32->hwndItem );
1898 dis->hDC = HDC_16(dis32->hDC);
1899 dis->itemData = dis32->itemData;
1900 dis->rcItem.left = dis32->rcItem.left;
1901 dis->rcItem.top = dis32->rcItem.top;
1902 dis->rcItem.right = dis32->rcItem.right;
1903 dis->rcItem.bottom = dis32->rcItem.bottom;
1904 *plparam = MapLS( dis );
1906 return 1;
1907 case WM_MEASUREITEM:
1909 MEASUREITEMSTRUCT *mis32 = (MEASUREITEMSTRUCT *)*plparam;
1910 MEASUREITEMSTRUCT16 *mis = HeapAlloc( GetProcessHeap(), 0, sizeof(*mis)+sizeof(LPARAM));
1911 if (!mis) return -1;
1912 mis->CtlType = (UINT16)mis32->CtlType;
1913 mis->CtlID = (UINT16)mis32->CtlID;
1914 mis->itemID = (UINT16)mis32->itemID;
1915 mis->itemWidth = (UINT16)mis32->itemWidth;
1916 mis->itemHeight = (UINT16)mis32->itemHeight;
1917 mis->itemData = mis32->itemData;
1918 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
1919 *plparam = MapLS( mis );
1921 return 1;
1922 case WM_GETMINMAXINFO:
1924 MINMAXINFO16 *mmi = HeapAlloc( GetProcessHeap(), 0, sizeof(*mmi) + sizeof(LPARAM) );
1925 if (!mmi) return -1;
1926 MINMAXINFO32to16( (MINMAXINFO *)*plparam, mmi );
1927 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
1928 *plparam = MapLS( mmi );
1930 return 1;
1931 case WM_GETTEXT:
1932 case WM_ASKCBFORMATNAME:
1934 LPARAM *str; /* store LPARAM, then *pwparam16 char space */
1935 *pwparam16 = (WPARAM16)min( wParam32, 0xff80 ); /* Must be < 64K */
1936 if (!(str = HeapAlloc( GetProcessHeap(), 0, *pwparam16 + sizeof(LPARAM)))) return -1;
1937 *str++ = *plparam; /* Store the previous lParam */
1938 *plparam = MapLS( str );
1940 return 1;
1941 case WM_MDICREATE:
1943 MDICREATESTRUCT16 *cs;
1944 MDICREATESTRUCTA *cs32 = (MDICREATESTRUCTA *)*plparam;
1946 if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(MDICREATESTRUCT16) ))) return -1;
1947 MDICREATESTRUCT32Ato16( cs32, cs );
1948 cs->szTitle = MapLS( cs32->szTitle );
1949 cs->szClass = MapLS( cs32->szClass );
1950 *plparam = MapLS( cs );
1952 return 1;
1953 case WM_MDIGETACTIVE:
1954 return 1;
1955 case WM_MDISETMENU:
1956 *plparam = MAKELPARAM( (HMENU16)LOWORD(wParam32),
1957 (HMENU16)LOWORD(*plparam) );
1958 *pwparam16 = (*plparam == 0);
1959 return 0;
1960 case WM_MENUSELECT:
1961 if(HIWORD(wParam32) & MF_POPUP)
1963 HMENU hmenu;
1964 if (((UINT)HIWORD(wParam32) != 0xFFFF) || (*plparam))
1966 if((hmenu = GetSubMenu((HMENU)*plparam, *pwparam16)))
1967 *pwparam16=HMENU_16(hmenu);
1970 /* fall through */
1971 case WM_MENUCHAR:
1972 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
1973 return 0;
1974 case WM_MDIACTIVATE:
1975 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_MDICHILD)
1977 *pwparam16 = ((HWND)*plparam == hwnd);
1978 *plparam = MAKELPARAM( (HWND16)LOWORD(*plparam),
1979 (HWND16)LOWORD(wParam32) );
1981 else
1983 *pwparam16 = HWND_16( (HWND)wParam32 );
1984 *plparam = 0;
1986 return 0;
1987 case WM_NCCALCSIZE:
1989 NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)*plparam;
1990 NCCALCSIZE_PARAMS16 *nc = HeapAlloc( GetProcessHeap(), 0, sizeof(*nc) + sizeof(LPARAM));
1991 if (!nc) return -1;
1993 nc->rgrc[0].left = nc32->rgrc[0].left;
1994 nc->rgrc[0].top = nc32->rgrc[0].top;
1995 nc->rgrc[0].right = nc32->rgrc[0].right;
1996 nc->rgrc[0].bottom = nc32->rgrc[0].bottom;
1997 if (wParam32)
1999 WINDOWPOS16 *wp;
2000 nc->rgrc[1].left = nc32->rgrc[1].left;
2001 nc->rgrc[1].top = nc32->rgrc[1].top;
2002 nc->rgrc[1].right = nc32->rgrc[1].right;
2003 nc->rgrc[1].bottom = nc32->rgrc[1].bottom;
2004 nc->rgrc[2].left = nc32->rgrc[2].left;
2005 nc->rgrc[2].top = nc32->rgrc[2].top;
2006 nc->rgrc[2].right = nc32->rgrc[2].right;
2007 nc->rgrc[2].bottom = nc32->rgrc[2].bottom;
2008 if (!(wp = HeapAlloc( GetProcessHeap(), 0, sizeof(WINDOWPOS16) )))
2010 HeapFree( GetProcessHeap(), 0, nc );
2011 return -1;
2013 WINDOWPOS32to16( nc32->lppos, wp );
2014 nc->lppos = MapLS( wp );
2016 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
2017 *plparam = MapLS( nc );
2019 return 1;
2020 case WM_NCCREATE:
2021 case WM_CREATE:
2023 CREATESTRUCT16 *cs;
2024 CREATESTRUCTA *cs32 = (CREATESTRUCTA *)*plparam;
2026 if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(CREATESTRUCT16) ))) return -1;
2027 CREATESTRUCT32Ato16( cs32, cs );
2028 cs->lpszName = MapLS( cs32->lpszName );
2029 cs->lpszClass = MapLS( cs32->lpszClass );
2031 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
2033 MDICREATESTRUCT16 *mdi_cs16;
2034 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs32->lpCreateParams;
2035 mdi_cs16 = HeapAlloc(GetProcessHeap(), 0, sizeof(*mdi_cs16));
2036 if (!mdi_cs16)
2038 HeapFree(GetProcessHeap(), 0, cs);
2039 return -1;
2041 MDICREATESTRUCT32Ato16(mdi_cs, mdi_cs16);
2042 mdi_cs16->szTitle = MapLS( mdi_cs->szTitle );
2043 mdi_cs16->szClass = MapLS( mdi_cs->szClass );
2044 cs->lpCreateParams = MapLS( mdi_cs16 );
2046 *plparam = MapLS( cs );
2048 return 1;
2049 case WM_PARENTNOTIFY:
2050 if ((LOWORD(wParam32)==WM_CREATE) || (LOWORD(wParam32)==WM_DESTROY))
2051 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32));
2052 /* else nothing to do */
2053 return 0;
2054 case WM_NOTIFY:
2055 *plparam = MapLS( (NMHDR *)*plparam ); /* NMHDR is already 32-bit */
2056 return 1;
2057 case WM_SETTEXT:
2058 case WM_WININICHANGE:
2059 case WM_DEVMODECHANGE:
2060 *plparam = MapLS( (LPSTR)*plparam );
2061 return 1;
2062 case WM_WINDOWPOSCHANGING:
2063 case WM_WINDOWPOSCHANGED:
2065 WINDOWPOS16 *wp = HeapAlloc( GetProcessHeap(), 0, sizeof(*wp) + sizeof(LPARAM) );
2066 if (!wp) return -1;
2067 WINDOWPOS32to16( (WINDOWPOS *)*plparam, wp );
2068 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
2069 *plparam = MapLS( wp );
2071 return 1;
2072 case WM_GETDLGCODE:
2073 if (*plparam) {
2074 LPMSG msg32 = (LPMSG) *plparam;
2075 LPMSG16 msg16 = HeapAlloc( GetProcessHeap(), 0, sizeof(MSG16) );
2077 if (!msg16) return -1;
2078 msg16->hwnd = HWND_16( msg32->hwnd );
2079 msg16->message = msg32->message;
2080 msg16->wParam = msg32->wParam;
2081 msg16->lParam = msg32->lParam;
2082 msg16->time = msg32->time;
2083 msg16->pt.x = msg32->pt.x;
2084 msg16->pt.y = msg32->pt.y;
2085 *plparam = MapLS( msg16 );
2086 return 1;
2088 return 0;
2090 case WM_ACTIVATEAPP:
2091 if (*plparam) *plparam = HTASK_16( (HANDLE)*plparam );
2092 return 0;
2093 case WM_NEXTMENU:
2095 MDINEXTMENU *next = (MDINEXTMENU *)*plparam;
2096 *plparam = (LPARAM)next->hmenuIn;
2097 return 1;
2099 case WM_PAINT:
2100 if (IsIconic( hwnd ) && GetClassLongPtrW( hwnd, GCLP_HICON ))
2102 *pmsg16 = WM_PAINTICON;
2103 *pwparam16 = 1;
2105 return 0;
2106 case WM_ERASEBKGND:
2107 if (IsIconic( hwnd ) && GetClassLongPtrW( hwnd, GCLP_HICON ))
2108 *pmsg16 = WM_ICONERASEBKGND;
2109 return 0;
2110 case WM_PAINTCLIPBOARD:
2111 case WM_SIZECLIPBOARD:
2112 FIXME_(msg)("message %04x needs translation\n", msg32 );
2113 return -1;
2114 /* following messages should not be sent to 16-bit apps */
2115 case WM_SIZING:
2116 case WM_MOVING:
2117 case WM_CAPTURECHANGED:
2118 case WM_STYLECHANGING:
2119 case WM_STYLECHANGED:
2120 return -1;
2121 case WM_DDE_INITIATE:
2122 case WM_DDE_TERMINATE:
2123 case WM_DDE_UNADVISE:
2124 case WM_DDE_REQUEST:
2125 *pwparam16 = HWND_16((HWND)wParam32);
2126 return 0;
2127 case WM_DDE_ADVISE:
2128 case WM_DDE_DATA:
2129 case WM_DDE_POKE:
2131 UINT_PTR lo32, hi;
2132 HANDLE16 lo16 = 0;
2134 *pwparam16 = HWND_16((HWND)wParam32);
2135 UnpackDDElParam(msg32, *plparam, &lo32, &hi);
2136 if (lo32 && !(lo16 = convert_handle_32_to_16(lo32, GMEM_DDESHARE)))
2137 return -1;
2138 *plparam = MAKELPARAM(lo16, hi);
2140 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
2141 case WM_DDE_ACK:
2143 UINT_PTR lo, hi;
2144 int flag = 0;
2145 char buf[2];
2147 *pwparam16 = HWND_16((HWND)wParam32);
2149 UnpackDDElParam(msg32, *plparam, &lo, &hi);
2151 if (GlobalGetAtomNameA((ATOM)hi, buf, sizeof(buf)) > 0) flag |= 1;
2152 if (GlobalSize((HANDLE)hi) != 0) flag |= 2;
2153 switch (flag)
2155 case 0:
2156 if (hi)
2158 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
2159 hi = 0;
2161 break;
2162 case 1:
2163 break; /* atom, nothing to do */
2164 case 3:
2165 MESSAGE("DDE_ACK: %x both atom and handle... choosing handle\n", hi);
2166 /* fall thru */
2167 case 2:
2168 hi = convert_handle_32_to_16(hi, GMEM_DDESHARE);
2169 break;
2171 *plparam = MAKELPARAM(lo, hi);
2173 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
2174 case WM_DDE_EXECUTE:
2175 *plparam = convert_handle_32_to_16(*plparam, GMEM_DDESHARE);
2176 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
2177 default: /* No translation needed */
2178 return 0;
2183 /**********************************************************************
2184 * WINPROC_UnmapMsg32ATo16
2186 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
2188 void WINPROC_UnmapMsg32ATo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2189 MSGPARAM16* p16 )
2191 switch(msg)
2193 case SBM_GETRANGE:
2194 *(LPINT)wParam = LOWORD(p16->lResult);
2195 *(LPINT)lParam = HIWORD(p16->lResult);
2196 break;
2198 case LB_ADDFILE:
2199 case LB_ADDSTRING:
2200 case LB_DIR:
2201 case LB_FINDSTRING:
2202 case LB_FINDSTRINGEXACT:
2203 case LB_INSERTSTRING:
2204 case LB_SELECTSTRING:
2205 case LB_GETTEXT:
2206 case CB_ADDSTRING:
2207 case CB_FINDSTRING:
2208 case CB_FINDSTRINGEXACT:
2209 case CB_INSERTSTRING:
2210 case CB_SELECTSTRING:
2211 case CB_DIR:
2212 case CB_GETLBTEXT:
2213 case WM_SETTEXT:
2214 case WM_WININICHANGE:
2215 case WM_DEVMODECHANGE:
2216 UnMapLS( (SEGPTR)p16->lParam );
2217 break;
2218 case LB_SETTABSTOPS:
2219 case WM_COMPAREITEM:
2220 case WM_DELETEITEM:
2221 case WM_DRAWITEM:
2223 void *ptr = MapSL( p16->lParam );
2224 UnMapLS( p16->lParam );
2225 HeapFree( GetProcessHeap(), 0, ptr );
2227 break;
2228 case WM_COPYDATA:
2230 PCOPYDATASTRUCT16 pcds = MapSL( p16->lParam );
2231 UnMapLS( p16->lParam );
2232 UnMapLS( pcds->lpData );
2233 HeapFree( GetProcessHeap(), 0, pcds );
2235 break;
2236 case CB_GETDROPPEDCONTROLRECT:
2237 case LB_GETITEMRECT:
2239 RECT *r32;
2240 RECT16 *rect = MapSL(p16->lParam);
2241 UnMapLS( p16->lParam );
2242 p16->lParam = *(LPARAM *)(rect + 1);
2243 r32 = (RECT *)p16->lParam;
2244 r32->left = rect->left;
2245 r32->top = rect->top;
2246 r32->right = rect->right;
2247 r32->bottom = rect->bottom;
2248 HeapFree( GetProcessHeap(), 0, rect );
2250 break;
2251 case LB_GETSELITEMS:
2253 INT i;
2254 LPINT16 items = MapSL(p16->lParam);
2255 UnMapLS( p16->lParam );
2256 p16->lParam = *((LPARAM *)items - 1);
2257 for (i = 0; i < p16->wParam; i++) *((LPINT)(p16->lParam) + i) = items[i];
2258 HeapFree( GetProcessHeap(), 0, (LPARAM *)items - 1 );
2260 break;
2262 case CB_GETEDITSEL:
2263 if( wParam )
2264 *((PUINT)(wParam)) = LOWORD(p16->lResult);
2265 if( lParam )
2266 *((PUINT)(lParam)) = HIWORD(p16->lResult); /* FIXME: substract 1? */
2267 break;
2269 case WM_MEASUREITEM:
2271 MEASUREITEMSTRUCT16 *mis = MapSL(p16->lParam);
2272 MEASUREITEMSTRUCT *mis32 = *(MEASUREITEMSTRUCT **)(mis + 1);
2273 mis32->itemWidth = mis->itemWidth;
2274 mis32->itemHeight = mis->itemHeight;
2275 UnMapLS( p16->lParam );
2276 HeapFree( GetProcessHeap(), 0, mis );
2278 break;
2279 case WM_GETMINMAXINFO:
2281 MINMAXINFO16 *mmi = MapSL(p16->lParam);
2282 UnMapLS( p16->lParam );
2283 p16->lParam = *(LPARAM *)(mmi + 1);
2284 MINMAXINFO16to32( mmi, (MINMAXINFO *)(p16->lParam) );
2285 HeapFree( GetProcessHeap(), 0, mmi );
2287 break;
2288 case WM_GETTEXT:
2289 case WM_ASKCBFORMATNAME:
2291 LPSTR str = MapSL(p16->lParam);
2292 UnMapLS( p16->lParam );
2293 p16->lParam = *((LPARAM *)str - 1);
2294 lstrcpynA( (LPSTR)(p16->lParam), str, p16->wParam );
2295 HeapFree( GetProcessHeap(), 0, (LPARAM *)str - 1 );
2297 break;
2298 case WM_MDICREATE:
2300 MDICREATESTRUCT16 *cs = MapSL(p16->lParam);
2301 UnMapLS( cs->szTitle );
2302 UnMapLS( cs->szClass );
2303 UnMapLS( p16->lParam );
2304 HeapFree( GetProcessHeap(), 0, cs );
2306 break;
2307 case WM_MDIGETACTIVE:
2308 if (lParam) *(BOOL *)lParam = (BOOL16)HIWORD(p16->lResult);
2309 p16->lResult = (LRESULT)WIN_Handle32( LOWORD(p16->lResult) );
2310 break;
2311 case WM_NCCALCSIZE:
2313 NCCALCSIZE_PARAMS *nc32;
2314 NCCALCSIZE_PARAMS16 *nc = MapSL(p16->lParam);
2315 UnMapLS( p16->lParam );
2316 p16->lParam = *(LPARAM *)(nc + 1);
2317 nc32 = (NCCALCSIZE_PARAMS *)(p16->lParam);
2318 nc32->rgrc[0].left = nc->rgrc[0].left;
2319 nc32->rgrc[0].top = nc->rgrc[0].top;
2320 nc32->rgrc[0].right = nc->rgrc[0].right;
2321 nc32->rgrc[0].bottom = nc->rgrc[0].bottom;
2322 if (p16->wParam)
2324 WINDOWPOS16 *pos = MapSL(nc->lppos);
2325 UnMapLS( nc->lppos );
2326 nc32->rgrc[1].left = nc->rgrc[1].left;
2327 nc32->rgrc[1].top = nc->rgrc[1].top;
2328 nc32->rgrc[1].right = nc->rgrc[1].right;
2329 nc32->rgrc[1].bottom = nc->rgrc[1].bottom;
2330 nc32->rgrc[2].left = nc->rgrc[2].left;
2331 nc32->rgrc[2].top = nc->rgrc[2].top;
2332 nc32->rgrc[2].right = nc->rgrc[2].right;
2333 nc32->rgrc[2].bottom = nc->rgrc[2].bottom;
2334 WINDOWPOS16to32( pos, nc32->lppos );
2335 HeapFree( GetProcessHeap(), 0, pos );
2337 HeapFree( GetProcessHeap(), 0, nc );
2339 break;
2340 case WM_NCCREATE:
2341 case WM_CREATE:
2343 CREATESTRUCT16 *cs = MapSL(p16->lParam);
2344 UnMapLS( p16->lParam );
2345 UnMapLS( cs->lpszName );
2346 UnMapLS( cs->lpszClass );
2347 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
2349 MDICREATESTRUCT16 *mdi_cs16 = (MDICREATESTRUCT16 *)MapSL(cs->lpCreateParams);
2350 UnMapLS( cs->lpCreateParams );
2351 UnMapLS( mdi_cs16->szTitle );
2352 UnMapLS( mdi_cs16->szClass );
2353 HeapFree(GetProcessHeap(), 0, mdi_cs16);
2355 HeapFree( GetProcessHeap(), 0, cs );
2357 break;
2358 case WM_WINDOWPOSCHANGING:
2359 case WM_WINDOWPOSCHANGED:
2361 WINDOWPOS16 *wp = MapSL(p16->lParam);
2362 UnMapLS( p16->lParam );
2363 p16->lParam = *(LPARAM *)(wp + 1);
2364 WINDOWPOS16to32( wp, (WINDOWPOS *)p16->lParam );
2365 HeapFree( GetProcessHeap(), 0, wp );
2367 break;
2368 case WM_NOTIFY:
2369 UnMapLS(p16->lParam);
2370 break;
2371 case WM_GETDLGCODE:
2372 if (p16->lParam)
2374 LPMSG16 msg16 = MapSL(p16->lParam);
2375 UnMapLS( p16->lParam );
2376 HeapFree( GetProcessHeap(), 0, msg16 );
2378 break;
2379 case WM_NEXTMENU:
2381 MDINEXTMENU *next = (MDINEXTMENU *)lParam;
2382 next->hmenuNext = HMENU_32( LOWORD(p16->lResult) );
2383 next->hwndNext = WIN_Handle32( HIWORD(p16->lResult) );
2384 p16->lResult = 0;
2386 break;
2391 /**********************************************************************
2392 * WINPROC_MapMsg32WTo16
2394 * Map a message from 32-bit Unicode to 16-bit.
2395 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
2397 INT WINPROC_MapMsg32WTo16( HWND hwnd, UINT msg32, WPARAM wParam32,
2398 UINT16 *pmsg16, WPARAM16 *pwparam16,
2399 LPARAM *plparam )
2401 *pmsg16 = LOWORD(msg32);
2402 *pwparam16 = LOWORD(wParam32);
2403 switch(msg32)
2405 case LB_ADDSTRING:
2406 case LB_FINDSTRING:
2407 case LB_FINDSTRINGEXACT:
2408 case LB_INSERTSTRING:
2409 case LB_SELECTSTRING:
2410 case LB_DIR:
2411 case LB_ADDFILE:
2412 *plparam = map_str_32W_to_16( (LPWSTR)*plparam );
2413 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
2414 return 1;
2416 case CB_ADDSTRING:
2417 case CB_FINDSTRING:
2418 case CB_FINDSTRINGEXACT:
2419 case CB_INSERTSTRING:
2420 case CB_SELECTSTRING:
2421 case CB_DIR:
2422 *plparam = map_str_32W_to_16( (LPWSTR)*plparam );
2423 *pmsg16 = (UINT16)msg32 + (CB_ADDSTRING16 - CB_ADDSTRING);
2424 return 1;
2426 case WM_NCCREATE:
2427 case WM_CREATE:
2429 CREATESTRUCT16 *cs;
2430 CREATESTRUCTW *cs32 = (CREATESTRUCTW *)*plparam;
2432 if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(CREATESTRUCT16) ))) return -1;
2433 CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs32, cs );
2434 cs->lpszName = map_str_32W_to_16( cs32->lpszName );
2435 cs->lpszClass = map_str_32W_to_16( cs32->lpszClass );
2437 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
2439 MDICREATESTRUCT16 *mdi_cs16;
2440 MDICREATESTRUCTW *mdi_cs = (MDICREATESTRUCTW *)cs32->lpCreateParams;
2441 mdi_cs16 = HeapAlloc(GetProcessHeap(), 0, sizeof(*mdi_cs16));
2442 if (!mdi_cs16)
2444 HeapFree(GetProcessHeap(), 0, cs);
2445 return -1;
2447 MDICREATESTRUCT32Ato16((MDICREATESTRUCTA *)mdi_cs, mdi_cs16);
2448 mdi_cs16->szTitle = map_str_32W_to_16(mdi_cs->szTitle);
2449 mdi_cs16->szClass = map_str_32W_to_16(mdi_cs->szClass);
2450 cs->lpCreateParams = MapLS(mdi_cs16);
2452 *plparam = MapLS(cs);
2454 return 1;
2455 case WM_MDICREATE:
2457 MDICREATESTRUCT16 *cs;
2458 MDICREATESTRUCTW *cs32 = (MDICREATESTRUCTW *)*plparam;
2460 if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(MDICREATESTRUCT16) ))) return -1;
2461 MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs32, cs );
2462 cs->szTitle = map_str_32W_to_16( cs32->szTitle );
2463 cs->szClass = map_str_32W_to_16( cs32->szClass );
2464 *plparam = MapLS(cs);
2466 return 1;
2467 case WM_SETTEXT:
2468 case WM_WININICHANGE:
2469 case WM_DEVMODECHANGE:
2470 *plparam = map_str_32W_to_16( (LPWSTR)*plparam );
2471 return 1;
2472 case LB_GETTEXT:
2473 case CB_GETLBTEXT:
2474 if ( WINPROC_TestLBForStr( hwnd, msg32 ))
2476 LPSTR str = HeapAlloc( GetProcessHeap(), 0, 512 ); /* FIXME: fixed sized buffer */
2477 if (!str) return -1;
2478 *pmsg16 = (msg32 == LB_GETTEXT) ? LB_GETTEXT16 : CB_GETLBTEXT16;
2479 *plparam = (LPARAM)MapLS(str);
2481 return 1;
2483 case WM_CHARTOITEM:
2484 *pwparam16 = map_wparam_char_WtoA( wParam32, 1 );
2485 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
2486 return 0;
2487 case WM_MENUCHAR:
2488 *pwparam16 = map_wparam_char_WtoA( wParam32, 1 );
2489 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
2490 return 0;
2491 case WM_CHAR:
2492 case WM_DEADCHAR:
2493 case WM_SYSCHAR:
2494 case WM_SYSDEADCHAR:
2495 *pwparam16 = map_wparam_char_WtoA( wParam32, 1 );
2496 return 0;
2497 case WM_IME_CHAR:
2498 *pwparam16 = map_wparam_char_WtoA( wParam32, 2 );
2499 return 0;
2501 default: /* No Unicode translation needed (?) */
2502 return WINPROC_MapMsg32ATo16( hwnd, msg32, wParam32, pmsg16,
2503 pwparam16, plparam );
2508 /**********************************************************************
2509 * WINPROC_UnmapMsg32WTo16
2511 * Unmap a message that was mapped from 32-bit Unicode to 16-bit.
2513 void WINPROC_UnmapMsg32WTo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2514 MSGPARAM16* p16 )
2516 switch(msg)
2518 case LB_ADDSTRING:
2519 case LB_FINDSTRING:
2520 case LB_FINDSTRINGEXACT:
2521 case LB_INSERTSTRING:
2522 case LB_SELECTSTRING:
2523 case LB_DIR:
2524 case LB_ADDFILE:
2525 case CB_ADDSTRING:
2526 case CB_FINDSTRING:
2527 case CB_FINDSTRINGEXACT:
2528 case CB_INSERTSTRING:
2529 case CB_SELECTSTRING:
2530 case CB_DIR:
2531 case WM_SETTEXT:
2532 case WM_WININICHANGE:
2533 case WM_DEVMODECHANGE:
2534 unmap_str_32W_to_16( p16->lParam );
2535 break;
2536 case WM_NCCREATE:
2537 case WM_CREATE:
2539 CREATESTRUCT16 *cs = MapSL(p16->lParam);
2540 UnMapLS( p16->lParam );
2541 unmap_str_32W_to_16( cs->lpszName );
2542 unmap_str_32W_to_16( cs->lpszClass );
2544 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
2546 MDICREATESTRUCT16 *mdi_cs16 = (MDICREATESTRUCT16 *)MapSL(cs->lpCreateParams);
2547 UnMapLS( cs->lpCreateParams );
2548 unmap_str_32W_to_16(mdi_cs16->szTitle);
2549 unmap_str_32W_to_16(mdi_cs16->szClass);
2550 HeapFree(GetProcessHeap(), 0, mdi_cs16);
2552 HeapFree( GetProcessHeap(), 0, cs );
2554 break;
2555 case WM_MDICREATE:
2557 MDICREATESTRUCT16 *cs = MapSL(p16->lParam);
2558 UnMapLS( p16->lParam );
2559 unmap_str_32W_to_16( cs->szTitle );
2560 unmap_str_32W_to_16( cs->szClass );
2561 HeapFree( GetProcessHeap(), 0, cs );
2563 break;
2564 case WM_GETTEXT:
2565 case WM_ASKCBFORMATNAME:
2567 LPSTR str = MapSL(p16->lParam);
2568 UnMapLS( p16->lParam );
2569 p16->lParam = *((LPARAM *)str - 1);
2570 MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)p16->lParam, 0x7fffffff );
2571 p16->lResult = strlenW( (LPWSTR)p16->lParam );
2572 HeapFree( GetProcessHeap(), 0, (LPARAM *)str - 1 );
2574 break;
2575 case LB_GETTEXT:
2576 case CB_GETLBTEXT:
2577 if ( WINPROC_TestLBForStr( hwnd, msg ))
2579 LPSTR str = MapSL(p16->lParam);
2580 UnMapLS( p16->lParam );
2581 p16->lResult = MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)lParam, 0x7fffffff ) - 1;
2582 HeapFree( GetProcessHeap(), 0, (LPARAM *)str );
2584 break;
2585 default:
2586 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, p16 );
2587 break;
2592 /**********************************************************************
2593 * WINPROC_CallProc32ATo32W
2595 * Call a window procedure, translating args from Ansi to Unicode.
2597 static LRESULT WINPROC_CallProc32ATo32W( WNDPROC func, HWND hwnd, UINT msg, WPARAM wParam,
2598 LPARAM lParam, BOOL dialog )
2600 LRESULT ret;
2601 int unmap;
2603 TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
2604 func, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
2606 if( (unmap = WINPROC_MapMsg32ATo32W( hwnd, msg, &wParam, &lParam )) == -1) {
2607 ERR_(msg)("Message translation failed. (msg=%s,wp=%08x,lp=%08lx)\n",
2608 SPY_GetMsgName(msg, hwnd), wParam, lParam );
2609 return 0;
2611 ret = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2612 if (unmap)
2614 if (dialog)
2616 LRESULT result = GetWindowLongPtrW( hwnd, DWLP_MSGRESULT );
2617 result = WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam, result, NULL );
2618 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
2620 else ret = WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam, ret, func );
2622 return ret;
2626 static inline void *get_buffer( void *static_buffer, size_t size, size_t need )
2628 if (size >= need) return static_buffer;
2629 return HeapAlloc( GetProcessHeap(), 0, need );
2632 static inline void free_buffer( void *static_buffer, void *buffer )
2634 if (buffer != static_buffer) HeapFree( GetProcessHeap(), 0, buffer );
2637 /**********************************************************************
2638 * WINPROC_CallProc32WTo32A
2640 * Call a window procedure, translating args from Unicode to Ansi.
2642 static LRESULT WINPROC_CallProc32WTo32A( WNDPROC func, HWND hwnd, UINT msg, WPARAM wParam,
2643 LPARAM lParam, BOOL dialog )
2645 LRESULT ret = 0;
2647 TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
2648 func, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
2650 switch(msg)
2652 case WM_NCCREATE:
2653 case WM_CREATE:
2654 { /* csW->lpszName and csW->lpszClass are NOT supposed to be atoms
2655 * at this point.
2657 char buffer[1024], *cls, *name;
2658 CREATESTRUCTW *csW = (CREATESTRUCTW *)lParam;
2659 CREATESTRUCTA csA = *(CREATESTRUCTA *)csW;
2660 MDICREATESTRUCTA mdi_cs;
2661 DWORD name_lenA, name_lenW, class_lenA, class_lenW;
2663 class_lenW = strlenW(csW->lpszClass) * sizeof(WCHAR);
2664 RtlUnicodeToMultiByteSize(&class_lenA, csW->lpszClass, class_lenW);
2666 if (csW->lpszName)
2668 name_lenW = strlenW(csW->lpszName) * sizeof(WCHAR);
2669 RtlUnicodeToMultiByteSize(&name_lenA, csW->lpszName, name_lenW);
2671 else
2672 name_lenW = name_lenA = 0;
2674 if (!(cls = get_buffer( buffer, sizeof(buffer), class_lenA + name_lenA + 2 ))) break;
2676 RtlUnicodeToMultiByteN(cls, class_lenA, NULL, csW->lpszClass, class_lenW);
2677 cls[class_lenA] = 0;
2678 csA.lpszClass = cls;
2680 if (csW->lpszName)
2682 name = cls + class_lenA + 1;
2683 RtlUnicodeToMultiByteN(name, name_lenA, NULL, csW->lpszName, name_lenW);
2684 name[name_lenA] = 0;
2685 csA.lpszName = name;
2688 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
2690 mdi_cs = *(MDICREATESTRUCTA *)csW->lpCreateParams;
2691 mdi_cs.szTitle = csA.lpszName;
2692 mdi_cs.szClass = csA.lpszClass;
2693 csA.lpCreateParams = &mdi_cs;
2696 ret = WINPROC_CallWndProc(func, hwnd, msg, wParam, (LPARAM)&csA);
2697 free_buffer( buffer, cls );
2699 break;
2701 case WM_GETTEXT:
2702 case WM_ASKCBFORMATNAME:
2704 char *ptr, buffer[512];
2705 DWORD len = wParam * 2;
2707 if (!(ptr = get_buffer( buffer, sizeof(buffer), len ))) break;
2708 ret = WINPROC_CallWndProc( func, hwnd, msg, len, (LPARAM)ptr );
2709 if (ret && len)
2711 RtlMultiByteToUnicodeN( (LPWSTR)lParam, wParam*sizeof(WCHAR), &len, ptr, strlen(ptr)+1 );
2712 ret = len/sizeof(WCHAR) - 1; /* do not count terminating null */
2713 ((LPWSTR)lParam)[ret] = 0;
2714 if (dialog)
2716 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, ret );
2717 ret = TRUE;
2720 free_buffer( buffer, ptr );
2722 break;
2724 case LB_ADDSTRING:
2725 case LB_INSERTSTRING:
2726 case LB_FINDSTRING:
2727 case LB_FINDSTRINGEXACT:
2728 case LB_SELECTSTRING:
2729 case CB_ADDSTRING:
2730 case CB_INSERTSTRING:
2731 case CB_FINDSTRING:
2732 case CB_FINDSTRINGEXACT:
2733 case CB_SELECTSTRING:
2734 if (!lParam || !WINPROC_TestLBForStr( hwnd, msg ))
2736 ret = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2737 break;
2739 /* fall through */
2740 case WM_SETTEXT:
2741 case WM_WININICHANGE:
2742 case WM_DEVMODECHANGE:
2743 case CB_DIR:
2744 case LB_DIR:
2745 case LB_ADDFILE:
2746 case EM_REPLACESEL:
2747 if (!lParam) ret = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2748 else
2750 char *ptr, buffer[512];
2751 LPCWSTR strW = (LPCWSTR)lParam;
2752 DWORD lenA, lenW = (strlenW(strW) + 1) * sizeof(WCHAR);
2754 RtlUnicodeToMultiByteSize( &lenA, strW, lenW );
2755 if ((ptr = get_buffer( buffer, sizeof(buffer), lenA )))
2757 RtlUnicodeToMultiByteN( ptr, lenA, NULL, strW, lenW );
2758 ret = WINPROC_CallWndProc( func, hwnd, msg, wParam, (LPARAM)ptr );
2759 free_buffer( buffer, ptr );
2762 break;
2764 case WM_MDICREATE:
2766 char *ptr, buffer[1024];
2767 DWORD title_lenA = 0, title_lenW = 0, class_lenA = 0, class_lenW = 0;
2768 MDICREATESTRUCTW *csW = (MDICREATESTRUCTW *)lParam;
2769 MDICREATESTRUCTA csA;
2771 memcpy( &csA, csW, sizeof(csA) );
2773 if (HIWORD(csW->szTitle))
2775 title_lenW = (strlenW(csW->szTitle) + 1) * sizeof(WCHAR);
2776 RtlUnicodeToMultiByteSize( &title_lenA, csW->szTitle, title_lenW );
2778 if (HIWORD(csW->szClass))
2780 class_lenW = (strlenW(csW->szClass) + 1) * sizeof(WCHAR);
2781 RtlUnicodeToMultiByteSize( &class_lenA, csW->szClass, class_lenW );
2784 if (!(ptr = get_buffer( buffer, sizeof(buffer), title_lenA + class_lenA ))) break;
2786 if (title_lenA)
2788 RtlUnicodeToMultiByteN( ptr, title_lenA, NULL, csW->szTitle, title_lenW );
2789 csA.szTitle = ptr;
2791 if (class_lenA)
2793 RtlUnicodeToMultiByteN( ptr + title_lenA, class_lenA, NULL, csW->szClass, class_lenW );
2794 csA.szClass = ptr + title_lenA;
2796 ret = WINPROC_CallWndProc( func, hwnd, msg, wParam, (LPARAM)&csA );
2797 free_buffer( buffer, ptr );
2799 break;
2801 case LB_GETTEXT:
2802 case CB_GETLBTEXT:
2803 if (lParam && WINPROC_TestLBForStr( hwnd, msg ))
2805 char buffer[512]; /* FIXME: fixed sized buffer */
2806 LRESULT result;
2808 ret = WINPROC_CallWndProc( func, hwnd, msg, wParam, (LPARAM)buffer );
2809 result = dialog ? GetWindowLongPtrW( hwnd, DWLP_MSGRESULT ) : ret;
2810 if (result >= 0)
2812 DWORD len;
2813 RtlMultiByteToUnicodeN( (LPWSTR)lParam, ~0u, &len, buffer, strlen(buffer) + 1 );
2814 result = len / sizeof(WCHAR) - 1;
2815 if (dialog) SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
2816 else ret = result;
2819 else ret = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2820 break;
2822 case EM_GETLINE:
2824 char *ptr, buffer[512];
2825 WORD len = *(WORD *)lParam;
2826 DWORD result;
2828 if (!(ptr = get_buffer( buffer, sizeof(buffer), len * 2 ))) break;
2829 *((WORD *)ptr) = len * 2; /* store the length */
2830 ret = WINPROC_CallWndProc( func, hwnd, msg, wParam, (LPARAM)ptr );
2831 result = dialog ? GetWindowLongPtrW( hwnd, DWLP_MSGRESULT ) : ret;
2832 if (result)
2834 RtlMultiByteToUnicodeN( (LPWSTR)lParam, len*sizeof(WCHAR), &result, buffer, result );
2835 result /= sizeof(WCHAR);
2836 if (result < len) ((LPWSTR)lParam)[result] = 0;
2837 if (dialog) SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
2838 else ret = result;
2840 free_buffer( buffer, ptr );
2842 break;
2844 case WM_CHARTOITEM:
2845 case WM_MENUCHAR:
2846 case WM_CHAR:
2847 case WM_DEADCHAR:
2848 case WM_SYSCHAR:
2849 case WM_SYSDEADCHAR:
2850 case EM_SETPASSWORDCHAR:
2851 ret = WINPROC_CallWndProc( func, hwnd, msg, map_wparam_char_WtoA(wParam,1), lParam );
2852 break;
2854 case WM_IME_CHAR:
2855 ret = WINPROC_CallWndProc( func, hwnd, msg, map_wparam_char_WtoA(wParam,2), lParam );
2856 break;
2858 case WM_PAINTCLIPBOARD:
2859 case WM_SIZECLIPBOARD:
2860 FIXME_(msg)( "message %s (%04x) needs translation, please report\n",
2861 SPY_GetMsgName(msg, hwnd), msg );
2862 break;
2864 default:
2865 ret = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2866 break;
2869 return ret;
2873 /**********************************************************************
2874 * WINPROC_CallProc16To32A
2876 static LRESULT WINPROC_CallProc16To32A( WNDPROC func, HWND16 hwnd, UINT16 msg,
2877 WPARAM16 wParam, LPARAM lParam, BOOL dialog )
2879 LRESULT ret;
2880 UINT msg32;
2881 WPARAM wParam32;
2882 HWND hwnd32 = WIN_Handle32( hwnd );
2884 TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
2885 func, hwnd32, SPY_GetMsgName(msg, hwnd32), wParam, lParam);
2887 if (WINPROC_MapMsg16To32A( hwnd32, msg, wParam, &msg32, &wParam32, &lParam ) == -1)
2888 return 0;
2889 ret = WINPROC_CallWndProc( func, hwnd32, msg32, wParam32, lParam );
2890 if (dialog)
2892 LRESULT result = GetWindowLongPtrW( hwnd32, DWLP_MSGRESULT );
2893 result = WINPROC_UnmapMsg16To32A( hwnd32, msg32, wParam32, lParam, result );
2894 SetWindowLongPtrW( hwnd32, DWLP_MSGRESULT, result );
2896 else ret = WINPROC_UnmapMsg16To32A( hwnd32, msg32, wParam32, lParam, ret );
2898 return ret;
2902 /**********************************************************************
2903 * WINPROC_CallProc16To32W
2905 static LRESULT WINPROC_CallProc16To32W( WNDPROC func, HWND16 hwnd, UINT16 msg,
2906 WPARAM16 wParam, LPARAM lParam, BOOL dialog )
2908 LRESULT ret;
2909 UINT msg32;
2910 WPARAM wParam32;
2911 HWND hwnd32 = WIN_Handle32( hwnd );
2913 TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
2914 func, hwnd32, SPY_GetMsgName(msg, hwnd32), wParam, lParam);
2916 if (WINPROC_MapMsg16To32W( hwnd32, msg, wParam, &msg32, &wParam32, &lParam ) == -1)
2917 return 0;
2919 ret = WINPROC_CallWndProc( func, hwnd32, msg32, wParam32, lParam );
2920 if (dialog)
2922 LRESULT result = GetWindowLongPtrW( hwnd32, DWLP_MSGRESULT );
2923 result = WINPROC_UnmapMsg16To32W( hwnd32, msg32, wParam32, lParam, result, NULL );
2924 SetWindowLongPtrW( hwnd32, DWLP_MSGRESULT, result );
2926 else ret = WINPROC_UnmapMsg16To32W( hwnd32, msg32, wParam32, lParam, ret, func );
2928 return ret;
2932 /**********************************************************************
2933 * __wine_call_wndproc (USER.1010)
2935 LRESULT WINAPI __wine_call_wndproc( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
2936 WINDOWPROC *proc )
2938 if (proc->procA) return WINPROC_CallProc16To32A( proc->procA, hwnd, msg, wParam, lParam, FALSE );
2939 else return WINPROC_CallProc16To32W( proc->procW, hwnd, msg, wParam, lParam, FALSE );
2943 /**********************************************************************
2944 * WINPROC_CallProc32ATo16
2946 * Call a 16-bit window procedure, translating the 32-bit args.
2948 static LRESULT WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd, UINT msg,
2949 WPARAM wParam, LPARAM lParam, BOOL dialog )
2951 LRESULT ret;
2952 UINT16 msg16;
2953 MSGPARAM16 mp16;
2955 TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
2956 func, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
2958 mp16.lParam = lParam;
2959 if (WINPROC_MapMsg32ATo16( hwnd, msg, wParam, &msg16, &mp16.wParam, &mp16.lParam ) == -1)
2960 return 0;
2961 ret = WINPROC_CallWndProc16( func, HWND_16(hwnd), msg16, mp16.wParam, mp16.lParam );
2962 if (dialog)
2964 mp16.lResult = GetWindowLongPtrW( hwnd, DWLP_MSGRESULT );
2965 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, &mp16 );
2966 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, mp16.lResult );
2967 ret = LOWORD(ret);
2969 else
2971 mp16.lResult = ret;
2972 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, &mp16 );
2973 ret = mp16.lResult;
2975 return ret;
2979 /**********************************************************************
2980 * WINPROC_CallProc32WTo16
2982 * Call a 16-bit window procedure, translating the 32-bit args.
2984 static LRESULT WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd, UINT msg,
2985 WPARAM wParam, LPARAM lParam, BOOL dialog )
2987 LRESULT ret;
2988 UINT16 msg16;
2989 MSGPARAM16 mp16;
2991 TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
2992 func, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
2994 mp16.lParam = lParam;
2995 if (WINPROC_MapMsg32WTo16( hwnd, msg, wParam, &msg16, &mp16.wParam, &mp16.lParam ) == -1)
2996 return 0;
2997 ret = WINPROC_CallWndProc16( func, HWND_16(hwnd), msg16, mp16.wParam, mp16.lParam );
2998 if (dialog)
3000 mp16.lResult = GetWindowLongPtrW( hwnd, DWLP_MSGRESULT );
3001 WINPROC_UnmapMsg32WTo16( hwnd, msg, wParam, lParam, &mp16 );
3002 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, mp16.lResult );
3003 ret = LOWORD(ret);
3005 else
3007 mp16.lResult = ret;
3008 WINPROC_UnmapMsg32WTo16( hwnd, msg, wParam, lParam, &mp16 );
3009 ret = mp16.lResult;
3011 return ret;
3015 /**********************************************************************
3016 * CallWindowProc (USER.122)
3018 LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
3019 WPARAM16 wParam, LPARAM lParam )
3021 WINDOWPROC *proc;
3023 if (!func) return 0;
3025 if (!(proc = handle16_to_proc( func )))
3026 return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
3028 if (proc->procA) return WINPROC_CallProc16To32A( proc->procA, hwnd, msg, wParam, lParam, FALSE );
3029 if (proc->procW) return WINPROC_CallProc16To32W( proc->procW, hwnd, msg, wParam, lParam, FALSE );
3030 return WINPROC_CallWndProc16( proc->proc16, hwnd, msg, wParam, lParam );
3034 /**********************************************************************
3035 * CallWindowProcA (USER32.@)
3037 * The CallWindowProc() function invokes the windows procedure _func_,
3038 * with _hwnd_ as the target window, the message specified by _msg_, and
3039 * the message parameters _wParam_ and _lParam_.
3041 * Some kinds of argument conversion may be done, I'm not sure what.
3043 * CallWindowProc() may be used for windows subclassing. Use
3044 * SetWindowLong() to set a new windows procedure for windows of the
3045 * subclass, and handle subclassed messages in the new windows
3046 * procedure. The new windows procedure may then use CallWindowProc()
3047 * with _func_ set to the parent class's windows procedure to dispatch
3048 * the message to the superclass.
3050 * RETURNS
3052 * The return value is message dependent.
3054 * CONFORMANCE
3056 * ECMA-234, Win32
3058 LRESULT WINAPI CallWindowProcA(
3059 WNDPROC func, /* [in] window procedure */
3060 HWND hwnd, /* [in] target window */
3061 UINT msg, /* [in] message */
3062 WPARAM wParam, /* [in] message dependent parameter */
3063 LPARAM lParam /* [in] message dependent parameter */
3065 WINDOWPROC *proc;
3067 if (!func) return 0;
3069 if (!(proc = handle_to_proc( func )))
3070 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
3072 if (proc->procA) return WINPROC_CallWndProc( proc->procA, hwnd, msg, wParam, lParam );
3073 if (proc->procW) return WINPROC_CallProc32ATo32W( proc->procW, hwnd, msg, wParam, lParam, FALSE );
3074 return WINPROC_CallProc32ATo16( proc->proc16, hwnd, msg, wParam, lParam, FALSE );
3078 /**********************************************************************
3079 * CallWindowProcW (USER32.@)
3081 * See CallWindowProcA.
3083 LRESULT WINAPI CallWindowProcW( WNDPROC func, HWND hwnd, UINT msg,
3084 WPARAM wParam, LPARAM lParam )
3086 WINDOWPROC *proc;
3088 if (!func) return 0;
3090 if (!(proc = handle_to_proc( func )))
3091 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
3093 if (proc->procW) return WINPROC_CallWndProc( proc->procW, hwnd, msg, wParam, lParam );
3094 if (proc->procA) return WINPROC_CallProc32WTo32A( proc->procA, hwnd, msg, wParam, lParam, FALSE );
3095 return WINPROC_CallProc32WTo16( proc->proc16, hwnd, msg, wParam, lParam, FALSE );
3099 /**********************************************************************
3100 * WINPROC_CallDlgProc16
3102 INT_PTR WINPROC_CallDlgProc16( DLGPROC16 func, HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam )
3104 WINDOWPROC *proc;
3106 if (!func) return 0;
3108 if (!(proc = handle16_to_proc( (WNDPROC16)func )))
3109 return LOWORD( WINPROC_CallWndProc16( (WNDPROC16)func, hwnd, msg, wParam, lParam ) );
3111 if (proc->procA) return WINPROC_CallProc16To32A( proc->procA, hwnd, msg, wParam, lParam, TRUE );
3112 if (proc->procW) return WINPROC_CallProc16To32W( proc->procW, hwnd, msg, wParam, lParam, TRUE );
3113 return LOWORD( WINPROC_CallWndProc16( proc->proc16, hwnd, msg, wParam, lParam ) );
3117 /**********************************************************************
3118 * WINPROC_CallDlgProcA
3120 INT_PTR WINPROC_CallDlgProcA( DLGPROC func, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
3122 WINDOWPROC *proc;
3124 if (!func) return 0;
3126 if (!(proc = handle_to_proc( (WNDPROC)func )))
3127 return WINPROC_CallWndProc( (WNDPROC)func, hwnd, msg, wParam, lParam );
3129 if (proc->procA) return WINPROC_CallWndProc( proc->procA, hwnd, msg, wParam, lParam );
3130 if (proc->procW) return WINPROC_CallProc32ATo32W( proc->procW, hwnd, msg, wParam, lParam, TRUE );
3131 return WINPROC_CallProc32ATo16( proc->proc16, hwnd, msg, wParam, lParam, TRUE );
3135 /**********************************************************************
3136 * WINPROC_CallDlgProcW
3138 INT_PTR WINPROC_CallDlgProcW( DLGPROC func, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
3140 WINDOWPROC *proc;
3142 if (!func) return 0;
3144 if (!(proc = handle_to_proc( (WNDPROC)func )))
3145 return WINPROC_CallWndProc( (WNDPROC)func, hwnd, msg, wParam, lParam );
3147 if (proc->procW) return WINPROC_CallWndProc( proc->procW, hwnd, msg, wParam, lParam );
3148 if (proc->procA) return WINPROC_CallProc32WTo32A( proc->procA, hwnd, msg, wParam, lParam, TRUE );
3149 return WINPROC_CallProc32WTo16( proc->proc16, hwnd, msg, wParam, lParam, TRUE );