Various registry-related PostScript driver enhancements.
[wine.git] / windows / winproc.c
blobe82c350f359d478219c9171661d7b7807ec30971
1 /*
2 * Window procedure callbacks
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1996 Alexandre Julliard
6 */
8 #include <string.h>
10 #include "config.h"
11 #include "windef.h"
12 #include "winbase.h"
13 #include "wingdi.h"
14 #include "wine/winbase16.h"
15 #include "wine/winuser16.h"
16 #include "stackframe.h"
17 #include "builtin16.h"
18 #include "controls.h"
19 #include "heap.h"
20 #include "struct32.h"
21 #include "win.h"
22 #include "winproc.h"
23 #include "debugtools.h"
24 #include "spy.h"
25 #include "task.h"
26 #include "thread.h"
28 DECLARE_DEBUG_CHANNEL(msg);
29 DECLARE_DEBUG_CHANNEL(relay);
30 DECLARE_DEBUG_CHANNEL(win);
32 /* Window procedure 16-to-32-bit thunk,
33 * see BuildSpec16File() in tools/build.c */
35 #include "pshpack1.h"
36 typedef struct
38 WORD pushw_bp; /* pushw %bp */
39 BYTE pushl_func; /* pushl $proc */
40 WNDPROC proc;
41 WORD pushw_ax; /* pushw %ax */
42 BYTE pushl_relay; /* pushl $relay */
43 void (*relay)(); /* WINPROC_Thunk16To32A/W() */
44 BYTE lcall; /* lcall cs:glue */
45 void (*glue)(); /* __wine_call_from_16_long */
46 WORD cs; /* __FLATCS */
47 WORD lret; /* lret $10 */
48 WORD nArgs;
49 } WINPROC_THUNK_FROM16;
50 #include "poppack.h"
52 /* Window procedure 32-to-16-bit thunk,
53 * see BuildSpec32File() in tools/build.c */
55 typedef struct
57 BYTE popl_eax; /* popl %eax (return address) */
58 BYTE pushl_func; /* pushl $proc */
59 WNDPROC16 proc WINE_PACKED;
60 BYTE pushl_eax; /* pushl %eax */
61 BYTE jmp; /* jmp relay (relative jump)*/
62 void (*relay)() WINE_PACKED; /* WINPROC_CallProc32ATo16() */
63 } WINPROC_THUNK_FROM32;
65 /* Simple jmp to call 32-bit procedure directly */
66 typedef struct
68 BYTE jmp; /* jmp proc (relative jump) */
69 WNDPROC proc WINE_PACKED;
70 } WINPROC_JUMP;
72 typedef union
74 WINPROC_THUNK_FROM16 t_from16;
75 WINPROC_THUNK_FROM32 t_from32;
76 } WINPROC_THUNK;
78 typedef struct tagWINDOWPROC
80 WINPROC_THUNK thunk; /* Thunk */
81 WINPROC_JUMP jmp; /* Jump */
82 struct tagWINDOWPROC *next; /* Next window proc */
83 UINT magic; /* Magic number */
84 WINDOWPROCTYPE type; /* Function type */
85 WINDOWPROCUSER user; /* Function user */
86 } WINDOWPROC;
88 #define WINPROC_MAGIC ('W' | ('P' << 8) | ('R' << 16) | ('C' << 24))
90 #define WINPROC_THUNKPROC(pproc) \
91 (((pproc)->type == WIN_PROC_16) ? \
92 (WNDPROC16)((pproc)->thunk.t_from32.proc) : \
93 (WNDPROC16)((pproc)->thunk.t_from16.proc))
95 static LRESULT WINAPI WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd,
96 UINT msg, WPARAM wParam,
97 LPARAM lParam );
98 static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
99 UINT msg, WPARAM wParam,
100 LPARAM lParam );
101 static LRESULT WINAPI WINPROC_Thunk16To32A( WNDPROC func, LPBYTE args );
102 static LRESULT WINAPI WINPROC_Thunk16To32W( WNDPROC func, LPBYTE args );
104 static HANDLE WinProcHeap;
107 /**********************************************************************
108 * WINPROC_Init
110 BOOL WINPROC_Init(void)
112 WinProcHeap = HeapCreate( HEAP_WINE_SEGPTR | HEAP_WINE_CODESEG, 0, 0 );
113 if (!WinProcHeap)
115 WARN_(relay)("Unable to create winproc heap\n" );
116 return FALSE;
118 return TRUE;
122 #ifdef __i386__
123 /* Some window procedures modify register they shouldn't, or are not
124 * properly declared stdcall; so we need a small assembly wrapper to
125 * call them. */
126 extern LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
127 WPARAM wParam, LPARAM lParam );
128 __ASM_GLOBAL_FUNC( WINPROC_wrapper,
129 "pushl %ebp\n\t"
130 "movl %esp,%ebp\n\t"
131 "pushl %edi\n\t"
132 "pushl %esi\n\t"
133 "pushl %ebx\n\t"
134 "pushl 24(%ebp)\n\t"
135 "pushl 20(%ebp)\n\t"
136 "pushl 16(%ebp)\n\t"
137 "pushl 12(%ebp)\n\t"
138 "movl 8(%ebp),%eax\n\t"
139 "call *%eax\n\t"
140 "leal -12(%ebp),%esp\n\t"
141 "popl %ebx\n\t"
142 "popl %esi\n\t"
143 "popl %edi\n\t"
144 "leave\n\t"
145 "ret" );
146 #else
147 static inline LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
148 WPARAM wParam, LPARAM lParam )
150 return proc( hwnd, msg, wParam, lParam );
152 #endif /* __i386__ */
154 /**********************************************************************
155 * WINPROC_CallWndProc32
157 * Call a 32-bit WndProc.
159 static LRESULT WINPROC_CallWndProc( WNDPROC proc, HWND hwnd, UINT msg,
160 WPARAM wParam, LPARAM lParam )
162 LRESULT retvalue;
163 int iWndsLocks;
165 TRACE_(relay)("(wndproc=%p,hwnd=%08x,msg=%s,wp=%08x,lp=%08lx)\n",
166 proc, hwnd, SPY_GetMsgName(msg), wParam, lParam );
167 /* To avoid any deadlocks, all the locks on the windows structures
168 must be suspended before the control is passed to the application */
169 iWndsLocks = WIN_SuspendWndsLock();
170 retvalue = WINPROC_wrapper( proc, hwnd, msg, wParam, lParam );
171 WIN_RestoreWndsLock(iWndsLocks);
172 TRACE_(relay)("(wndproc=%p,hwnd=%08x,msg=%s,wp=%08x,lp=%08lx) retval=%08lx\n",
173 proc, hwnd, SPY_GetMsgName(msg), wParam, lParam, retvalue );
174 return retvalue;
177 /***********************************************************************
178 * WINPROC_CallWndProc16
180 * Call a 16-bit window procedure
182 static LRESULT WINAPI WINPROC_CallWndProc16( WNDPROC16 proc, HWND16 hwnd,
183 UINT16 msg, WPARAM16 wParam,
184 LPARAM lParam )
186 CONTEXT86 context;
187 LRESULT ret;
188 WORD *args;
189 WND *wndPtr = WIN_FindWndPtr( hwnd );
190 DWORD offset = 0;
191 TEB *teb = NtCurrentTeb();
192 int iWndsLocks;
194 /* Window procedures want ax = hInstance, ds = es = ss */
196 memset(&context, '\0', sizeof(context));
197 context.SegDs = context.SegEs = SELECTOROF(teb->cur_stack);
198 context.Eax = wndPtr ? wndPtr->hInstance : context.SegDs;
199 context.SegCs = SELECTOROF(proc);
200 context.Eip = OFFSETOF(proc);
201 context.Ebp = OFFSETOF(teb->cur_stack)
202 + (WORD)&((STACK16FRAME*)0)->bp;
204 WIN_ReleaseWndPtr(wndPtr);
206 if (lParam)
208 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
209 work if structures passed in lParam are placed in the stack/data
210 segment. Programmers easily make the mistake of converting lParam
211 to a near rather than a far pointer, since Windows apparently
212 allows this. We copy the structures to the 16 bit stack; this is
213 ugly but makes these programs work. */
214 switch (msg)
216 case WM_CREATE:
217 case WM_NCCREATE:
218 offset = sizeof(CREATESTRUCT16); break;
219 case WM_DRAWITEM:
220 offset = sizeof(DRAWITEMSTRUCT16); break;
221 case WM_COMPAREITEM:
222 offset = sizeof(COMPAREITEMSTRUCT16); break;
224 if (offset)
226 void *s = MapSL(lParam);
227 lParam = stack16_push( offset );
228 memcpy( MapSL(lParam), s, offset );
232 iWndsLocks = WIN_SuspendWndsLock();
234 args = (WORD *)THREAD_STACK16(teb) - 5;
235 args[0] = LOWORD(lParam);
236 args[1] = HIWORD(lParam);
237 args[2] = wParam;
238 args[3] = msg;
239 args[4] = hwnd;
241 wine_call_to_16_regs_short( &context, 5 * sizeof(WORD) );
242 ret = MAKELONG( LOWORD(context.Eax), LOWORD(context.Edx) );
243 if (offset) stack16_pop( offset );
245 WIN_RestoreWndsLock(iWndsLocks);
247 return ret;
251 /**********************************************************************
252 * WINPROC_GetPtr
254 * Return a pointer to the win proc.
256 static WINDOWPROC *WINPROC_GetPtr( WNDPROC16 handle )
258 BYTE *ptr;
259 WINDOWPROC *proc;
261 /* ptr cannot be < 64K */
262 if (!HIWORD(handle)) return NULL;
264 /* Check for a linear pointer */
266 ptr = (BYTE *)handle;
267 /* First check if it is the jmp address */
268 proc = (WINDOWPROC *)(ptr - (int)&((WINDOWPROC *)0)->jmp);
269 if (HeapValidate( WinProcHeap, 0, proc ) && (proc->magic == WINPROC_MAGIC))
270 return proc;
271 /* Now it must be the thunk address */
272 proc = (WINDOWPROC *)(ptr - (int)&((WINDOWPROC *)0)->thunk);
273 if (HeapValidate( WinProcHeap, 0, proc ) && (proc->magic == WINPROC_MAGIC))
274 return proc;
276 /* Check for a segmented pointer */
278 if (!IsBadReadPtr16( (SEGPTR)handle, sizeof(proc->thunk) ))
280 ptr = MapSL( (SEGPTR)handle );
281 /* It must be the thunk address */
282 proc = (WINDOWPROC *)(ptr - (int)&((WINDOWPROC *)0)->thunk);
283 if (HeapValidate( WinProcHeap, 0, proc ) && (proc->magic == WINPROC_MAGIC))
284 return proc;
287 return NULL;
291 /**********************************************************************
292 * WINPROC_AllocWinProc
294 * Allocate a new window procedure.
296 static WINDOWPROC *WINPROC_AllocWinProc( WNDPROC16 func, WINDOWPROCTYPE type,
297 WINDOWPROCUSER user )
299 WINDOWPROC *proc, *oldproc;
301 /* Allocate a window procedure */
303 if (!(proc = HeapAlloc( WinProcHeap, 0, sizeof(WINDOWPROC) ))) return 0;
305 /* Check if the function is already a win proc */
307 if ((oldproc = WINPROC_GetPtr( func )))
309 *proc = *oldproc;
311 else
313 switch(type)
315 case WIN_PROC_16:
316 proc->thunk.t_from32.popl_eax = 0x58; /* popl %eax */
317 proc->thunk.t_from32.pushl_func = 0x68; /* pushl $proc */
318 proc->thunk.t_from32.proc = func;
319 proc->thunk.t_from32.pushl_eax = 0x50; /* pushl %eax */
320 proc->thunk.t_from32.jmp = 0xe9; /* jmp relay*/
321 proc->thunk.t_from32.relay = /* relative jump */
322 (void(*)())((DWORD)WINPROC_CallProc32ATo16 -
323 (DWORD)(&proc->thunk.t_from32.relay + 1));
324 break;
325 case WIN_PROC_32A:
326 case WIN_PROC_32W:
327 proc->thunk.t_from16.pushw_bp = 0x5566; /* pushw %bp */
328 proc->thunk.t_from16.pushl_func = 0x68; /* pushl $proc */
329 proc->thunk.t_from16.proc = (WNDPROC)func;
330 proc->thunk.t_from16.pushw_ax = 0x5066; /* pushw %ax */
331 proc->thunk.t_from16.pushl_relay = 0x68; /* pushl $relay */
332 proc->thunk.t_from16.relay = (type == WIN_PROC_32A) ?
333 (void(*)())WINPROC_Thunk16To32A :
334 (void(*)())WINPROC_Thunk16To32W;
335 proc->thunk.t_from16.lcall = 0x9a; /* lcall cs:glue */
336 proc->thunk.t_from16.glue = (void*)__wine_call_from_16_long;
337 proc->thunk.t_from16.cs = __get_cs();
338 proc->thunk.t_from16.lret = 0xca66;
339 proc->thunk.t_from16.nArgs = 10;
340 proc->jmp.jmp = 0xe9;
341 /* Fixup relative jump */
342 proc->jmp.proc = (WNDPROC)((DWORD)func -
343 (DWORD)(&proc->jmp.proc + 1));
344 break;
345 default:
346 /* Should not happen */
347 break;
349 proc->magic = WINPROC_MAGIC;
350 proc->type = type;
351 proc->user = user;
353 proc->next = NULL;
354 TRACE_(win)("(%08x,%d): returning %08x\n",
355 (UINT)func, type, (UINT)proc );
356 return proc;
360 /**********************************************************************
361 * WINPROC_GetProc
363 * Get a window procedure pointer that can be passed to the Windows program.
365 WNDPROC16 WINPROC_GetProc( HWINDOWPROC proc, WINDOWPROCTYPE type )
367 if (!proc) return NULL;
368 if (type == WIN_PROC_16) /* We want a 16:16 address */
370 if (((WINDOWPROC *)proc)->type == WIN_PROC_16)
371 return ((WINDOWPROC *)proc)->thunk.t_from32.proc;
372 else
373 return (WNDPROC16)HEAP_GetSegptr( WinProcHeap, 0,
374 &((WINDOWPROC *)proc)->thunk );
376 else /* We want a 32-bit address */
378 if (((WINDOWPROC *)proc)->type == WIN_PROC_16)
379 return (WNDPROC16)&((WINDOWPROC *)proc)->thunk;
380 else if (type != ((WINDOWPROC *)proc)->type)
381 /* Have to return the jmp address if types don't match */
382 return (WNDPROC16)&((WINDOWPROC *)proc)->jmp;
383 else
384 /* Some Win16 programs want to get back the proc they set */
385 return (WNDPROC16)((WINDOWPROC *)proc)->thunk.t_from16.proc;
390 /**********************************************************************
391 * WINPROC_SetProc
393 * Set the window procedure for a window or class. There are
394 * three tree classes of winproc callbacks:
396 * 1) class -> wp - not subclassed
397 * class -> wp -> wp -> wp -> wp - SetClassLong()
398 * / /
399 * 2) window -' / - not subclassed
400 * window -> wp -> wp ' - SetWindowLong()
402 * 3) timer -> wp - SetTimer()
404 * Initially, winproc of the window points to the current winproc
405 * thunk of its class. Subclassing prepends a new thunk to the
406 * window winproc chain at the head of the list. Thus, window thunk
407 * list includes class thunks and the latter are preserved when the
408 * window is destroyed.
411 BOOL WINPROC_SetProc( HWINDOWPROC *pFirst, WNDPROC16 func,
412 WINDOWPROCTYPE type, WINDOWPROCUSER user )
414 BOOL bRecycle = FALSE;
415 WINDOWPROC *proc, **ppPrev;
417 /* Check if function is already in the list */
419 ppPrev = (WINDOWPROC **)pFirst;
420 proc = WINPROC_GetPtr( func );
421 while (*ppPrev)
423 if (proc)
425 if (*ppPrev == proc)
427 if ((*ppPrev)->user != user)
429 /* terminal thunk is being restored */
431 WINPROC_FreeProc( *pFirst, (*ppPrev)->user );
432 *(WINDOWPROC **)pFirst = *ppPrev;
433 return TRUE;
435 bRecycle = TRUE;
436 break;
439 else
441 if (((*ppPrev)->type == type) &&
442 (func == WINPROC_THUNKPROC(*ppPrev)))
444 bRecycle = TRUE;
445 break;
449 /* WPF_CLASS thunk terminates window thunk list */
450 if ((*ppPrev)->user != user) break;
451 ppPrev = &(*ppPrev)->next;
454 if (bRecycle)
456 /* Extract this thunk from the list */
457 proc = *ppPrev;
458 *ppPrev = proc->next;
460 else /* Allocate a new one */
462 if (proc) /* Was already a win proc */
464 type = proc->type;
465 func = WINPROC_THUNKPROC(proc);
467 proc = WINPROC_AllocWinProc( func, type, user );
468 if (!proc) return FALSE;
471 /* Add the win proc at the head of the list */
473 TRACE_(win)("(%08x,%08x,%d): res=%08x\n",
474 (UINT)*pFirst, (UINT)func, type, (UINT)proc );
475 proc->next = *(WINDOWPROC **)pFirst;
476 *(WINDOWPROC **)pFirst = proc;
477 return TRUE;
481 /**********************************************************************
482 * WINPROC_FreeProc
484 * Free a list of win procs.
486 void WINPROC_FreeProc( HWINDOWPROC proc, WINDOWPROCUSER user )
488 while (proc)
490 WINDOWPROC *next = ((WINDOWPROC *)proc)->next;
491 if (((WINDOWPROC *)proc)->user != user) break;
492 TRACE_(win)("freeing %08x\n", (UINT)proc);
493 HeapFree( WinProcHeap, 0, proc );
494 proc = next;
499 /**********************************************************************
500 * WINPROC_GetProcType
502 * Return the window procedure type.
504 WINDOWPROCTYPE WINPROC_GetProcType( HWINDOWPROC proc )
506 if (!proc ||
507 (((WINDOWPROC *)proc)->magic != WINPROC_MAGIC))
508 return WIN_PROC_INVALID;
509 return ((WINDOWPROC *)proc)->type;
511 /**********************************************************************
512 * WINPROC_TestCBForStr
514 * Return TRUE if the lparam is a string
516 static BOOL WINPROC_TestCBForStr ( HWND hwnd )
518 BOOL retvalue;
519 WND * wnd = WIN_FindWndPtr(hwnd);
520 retvalue = ( !(LOWORD(wnd->dwStyle) & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) ||
521 (LOWORD(wnd->dwStyle) & CBS_HASSTRINGS) );
522 WIN_ReleaseWndPtr(wnd);
523 return retvalue;
525 /**********************************************************************
526 * WINPROC_TestLBForStr
528 * Return TRUE if the lparam is a string
530 static BOOL WINPROC_TestLBForStr ( HWND hwnd )
532 BOOL retvalue;
533 WND * wnd = WIN_FindWndPtr(hwnd);
534 retvalue = ( !(LOWORD(wnd->dwStyle) & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) ||
535 (LOWORD(wnd->dwStyle) & LBS_HASSTRINGS) );
536 WIN_ReleaseWndPtr(wnd);
537 return retvalue;
540 /**********************************************************************
541 * WINPROC_MapMsg32ATo32W
543 * Map a message from Ansi to Unicode.
544 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
546 * FIXME:
547 * WM_CHARTOITEM, WM_MENUCHAR
549 * FIXME:
550 * WM_GETTEXT/WM_SETTEXT and static control with SS_ICON style:
551 * the first four bytes are the handle of the icon
552 * when the WM_SETTEXT message has been used to set the icon
554 INT WINPROC_MapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam )
556 switch(msg)
558 case WM_GETTEXT:
560 LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
561 *pwparam * sizeof(WCHAR) + sizeof(LPARAM) );
562 if (!ptr) return -1;
563 *ptr++ = *plparam; /* Store previous lParam */
564 *plparam = (LPARAM)ptr;
566 return 1;
567 /* lparam is string (0-terminated) */
568 case WM_SETTEXT:
569 case WM_WININICHANGE:
570 case CB_DIR:
571 case CB_FINDSTRING:
572 case CB_FINDSTRINGEXACT:
573 case CB_SELECTSTRING:
574 case LB_DIR:
575 case LB_ADDFILE:
576 case LB_FINDSTRING:
577 case LB_FINDSTRINGEXACT:
578 case LB_SELECTSTRING:
579 case EM_REPLACESEL:
580 if(!*plparam) return 0;
581 *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
582 return (*plparam ? 1 : -1);
584 case WM_NCCREATE:
585 case WM_CREATE:
587 struct s
588 { CREATESTRUCTW cs; /* new structure */
589 LPCWSTR lpszName; /* allocated Name */
590 LPCWSTR lpszClass; /* allocated Class */
593 struct s *xs = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct s));
594 if (!xs) return -1;
595 xs->cs = *(CREATESTRUCTW *)*plparam;
596 if (HIWORD(xs->cs.lpszName))
597 xs->lpszName = xs->cs.lpszName = HEAP_strdupAtoW( GetProcessHeap(), 0,
598 (LPCSTR)xs->cs.lpszName );
599 if (HIWORD(xs->cs.lpszClass))
600 xs->lpszClass = xs->cs.lpszClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
601 (LPCSTR)xs->cs.lpszClass );
602 *plparam = (LPARAM)xs;
604 return 1;
605 case WM_MDICREATE:
607 MDICREATESTRUCTW *cs =
608 (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
609 if (!cs) return -1;
610 *cs = *(MDICREATESTRUCTW *)*plparam;
611 if (HIWORD(cs->szClass))
612 cs->szClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
613 (LPCSTR)cs->szClass );
614 if (HIWORD(cs->szTitle))
615 cs->szTitle = HEAP_strdupAtoW( GetProcessHeap(), 0,
616 (LPCSTR)cs->szTitle );
617 *plparam = (LPARAM)cs;
619 return 1;
621 /* Listbox */
622 case LB_ADDSTRING:
623 case LB_INSERTSTRING:
624 if(!*plparam) return 0;
625 if ( WINPROC_TestLBForStr( hwnd ))
626 *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
627 return (*plparam ? 1 : -1);
629 case LB_GETTEXT: /* fixme: fixed sized buffer */
630 { if ( WINPROC_TestLBForStr( hwnd ))
631 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
632 if (!ptr) return -1;
633 *ptr++ = *plparam; /* Store previous lParam */
634 *plparam = (LPARAM)ptr;
637 return 1;
639 /* Combobox */
640 case CB_ADDSTRING:
641 case CB_INSERTSTRING:
642 if(!*plparam) return 0;
643 if ( WINPROC_TestCBForStr( hwnd ))
644 *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
645 return (*plparam ? 1 : -1);
647 case CB_GETLBTEXT: /* fixme: fixed sized buffer */
648 { if ( WINPROC_TestCBForStr( hwnd ))
649 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
650 if (!ptr) return -1;
651 *ptr++ = *plparam; /* Store previous lParam */
652 *plparam = (LPARAM)ptr;
655 return 1;
657 /* Multiline edit */
658 case EM_GETLINE:
659 { WORD len = (WORD)*plparam;
660 LPARAM *ptr = (LPARAM *) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(WCHAR) );
661 if (!ptr) return -1;
662 *ptr++ = *plparam; /* Store previous lParam */
663 *((WORD *) ptr) = len; /* Store the length */
664 *plparam = (LPARAM)ptr;
666 return 1;
668 case WM_CHAR:
669 case WM_DEADCHAR:
670 case WM_SYSCHAR:
671 case WM_SYSDEADCHAR:
672 case EM_SETPASSWORDCHAR:
674 char ch = *pwparam;
675 WCHAR wch;
676 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
677 *pwparam = wch;
679 return 0;
681 case WM_ASKCBFORMATNAME:
682 case WM_DEVMODECHANGE:
683 case WM_PAINTCLIPBOARD:
684 case WM_SIZECLIPBOARD:
685 FIXME_(msg)("message %s (0x%x) needs translation, please report\n", SPY_GetMsgName(msg), msg );
686 return -1;
687 default: /* No translation needed */
688 return 0;
693 /**********************************************************************
694 * WINPROC_UnmapMsg32ATo32W
696 * Unmap a message that was mapped from Ansi to Unicode.
698 void WINPROC_UnmapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
700 switch(msg)
702 case WM_GETTEXT:
704 LPARAM *ptr = (LPARAM *)lParam - 1;
705 if (wParam > 0 && !WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
706 (LPSTR)*ptr, wParam, NULL, NULL ))
707 ((LPSTR)*ptr)[wParam-1] = 0;
708 HeapFree( GetProcessHeap(), 0, ptr );
710 break;
712 case WM_NCCREATE:
713 case WM_CREATE:
715 struct s
716 { CREATESTRUCTW cs; /* new structure */
717 LPWSTR lpszName; /* allocated Name */
718 LPWSTR lpszClass; /* allocated Class */
720 struct s *xs = (struct s *)lParam;
721 if (xs->lpszName) HeapFree( GetProcessHeap(), 0, xs->lpszName );
722 if (xs->lpszClass) HeapFree( GetProcessHeap(), 0, xs->lpszClass );
723 HeapFree( GetProcessHeap(), 0, xs );
725 break;
727 case WM_MDICREATE:
729 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
730 if (HIWORD(cs->szTitle))
731 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
732 if (HIWORD(cs->szClass))
733 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
734 HeapFree( GetProcessHeap(), 0, cs );
736 break;
738 case WM_SETTEXT:
739 case WM_WININICHANGE:
740 case CB_DIR:
741 case CB_FINDSTRING:
742 case CB_FINDSTRINGEXACT:
743 case CB_SELECTSTRING:
744 case LB_DIR:
745 case LB_ADDFILE:
746 case LB_FINDSTRING:
747 case LB_FINDSTRINGEXACT:
748 case LB_SELECTSTRING:
749 case EM_REPLACESEL:
750 HeapFree( GetProcessHeap(), 0, (void *)lParam );
751 break;
753 /* Listbox */
754 case LB_ADDSTRING:
755 case LB_INSERTSTRING:
756 if ( WINPROC_TestLBForStr( hwnd ))
757 HeapFree( GetProcessHeap(), 0, (void *)lParam );
758 break;
760 case LB_GETTEXT:
761 { if ( WINPROC_TestLBForStr( hwnd ))
762 { LPARAM *ptr = (LPARAM *)lParam - 1;
763 WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1, (LPSTR)*ptr, 0x7fffffff, NULL, NULL );
764 HeapFree( GetProcessHeap(), 0, ptr );
767 break;
769 /* Combobox */
770 case CB_ADDSTRING:
771 case CB_INSERTSTRING:
772 if ( WINPROC_TestCBForStr( hwnd ))
773 HeapFree( GetProcessHeap(), 0, (void *)lParam );
774 break;
776 case CB_GETLBTEXT:
777 { if ( WINPROC_TestCBForStr( hwnd ))
778 { LPARAM *ptr = (LPARAM *)lParam - 1;
779 WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1, (LPSTR)*ptr, 0x7fffffff, NULL, NULL );
780 HeapFree( GetProcessHeap(), 0, ptr );
783 break;
785 /* Multiline edit */
786 case EM_GETLINE:
787 { LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lParam */
788 WORD len = *(WORD *) lParam;
789 if (len > 0 && !WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
790 (LPSTR)*ptr, len, NULL, NULL ))
791 ((LPSTR)*ptr)[len-1] = 0;
792 HeapFree( GetProcessHeap(), 0, ptr );
794 break;
799 /**********************************************************************
800 * WINPROC_MapMsg32WTo32A
802 * Map a message from Unicode to Ansi.
803 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
805 INT WINPROC_MapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam )
807 switch(msg)
809 case WM_GETTEXT:
811 LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
812 *pwparam + sizeof(LPARAM) );
813 if (!ptr) return -1;
814 *ptr++ = *plparam; /* Store previous lParam */
815 *plparam = (LPARAM)ptr;
817 return 1;
819 case WM_SETTEXT:
820 case WM_WININICHANGE:
821 case CB_DIR:
822 case CB_FINDSTRING:
823 case CB_FINDSTRINGEXACT:
824 case CB_SELECTSTRING:
825 case LB_DIR:
826 case LB_ADDFILE:
827 case LB_FINDSTRING:
828 case LB_FINDSTRINGEXACT:
829 case LB_SELECTSTRING:
830 case EM_REPLACESEL:
831 if(!*plparam) return 0;
832 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
833 return (*plparam ? 1 : -1);
835 case WM_NCCREATE:
836 case WM_CREATE:
838 CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
839 sizeof(*cs) );
840 if (!cs) return -1;
841 *cs = *(CREATESTRUCTA *)*plparam;
842 if (HIWORD(cs->lpszName))
843 cs->lpszName = HEAP_strdupWtoA( GetProcessHeap(), 0,
844 (LPCWSTR)cs->lpszName );
845 if (HIWORD(cs->lpszClass))
846 cs->lpszClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
847 (LPCWSTR)cs->lpszClass);
848 *plparam = (LPARAM)cs;
850 return 1;
851 case WM_MDICREATE:
853 MDICREATESTRUCTA *cs =
854 (MDICREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
855 if (!cs) return -1;
856 *cs = *(MDICREATESTRUCTA *)*plparam;
857 if (HIWORD(cs->szTitle))
858 cs->szTitle = HEAP_strdupWtoA( GetProcessHeap(), 0,
859 (LPCWSTR)cs->szTitle );
860 if (HIWORD(cs->szClass))
861 cs->szClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
862 (LPCWSTR)cs->szClass );
863 *plparam = (LPARAM)cs;
865 return 1;
867 /* Listbox */
868 case LB_ADDSTRING:
869 case LB_INSERTSTRING:
870 if(!*plparam) return 0;
871 if ( WINPROC_TestLBForStr( hwnd ))
872 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
873 return (*plparam ? 1 : -1);
875 case LB_GETTEXT: /* fixme: fixed sized buffer */
876 { if ( WINPROC_TestLBForStr( hwnd ))
877 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
878 if (!ptr) return -1;
879 *ptr++ = *plparam; /* Store previous lParam */
880 *plparam = (LPARAM)ptr;
883 return 1;
885 /* Combobox */
886 case CB_ADDSTRING:
887 case CB_INSERTSTRING:
888 if(!*plparam) return 0;
889 if ( WINPROC_TestCBForStr( hwnd ))
890 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
891 return (*plparam ? 1 : -1);
893 case CB_GETLBTEXT: /* fixme: fixed sized buffer */
894 { if ( WINPROC_TestCBForStr( hwnd ))
895 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
896 if (!ptr) return -1;
897 *ptr++ = *plparam; /* Store previous lParam */
898 *plparam = (LPARAM)ptr;
901 return 1;
903 /* Multiline edit */
904 case EM_GETLINE:
905 { WORD len = (WORD)*plparam;
906 LPARAM *ptr = (LPARAM *) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(CHAR) );
907 if (!ptr) return -1;
908 *ptr++ = *plparam; /* Store previous lParam */
909 *((WORD *) ptr) = len; /* Store the length */
910 *plparam = (LPARAM)ptr;
912 return 1;
914 case WM_CHAR:
915 case WM_DEADCHAR:
916 case WM_SYSCHAR:
917 case WM_SYSDEADCHAR:
918 case EM_SETPASSWORDCHAR:
920 WCHAR wch = *pwparam;
921 char ch;
922 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL );
923 *pwparam = ch;
925 return 0;
927 case WM_ASKCBFORMATNAME:
928 case WM_DEVMODECHANGE:
929 case WM_PAINTCLIPBOARD:
930 case WM_SIZECLIPBOARD:
931 FIXME_(msg)("message %s (%04x) needs translation, please report\n",SPY_GetMsgName(msg),msg );
932 return -1;
933 default: /* No translation needed */
934 return 0;
939 /**********************************************************************
940 * WINPROC_UnmapMsg32WTo32A
942 * Unmap a message that was mapped from Unicode to Ansi.
944 void WINPROC_UnmapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
946 switch(msg)
948 case WM_GETTEXT:
950 LPARAM *ptr = (LPARAM *)lParam - 1;
951 if (wParam)
953 if (!MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, wParam ))
954 ((LPWSTR)*ptr)[wParam-1] = 0;
956 HeapFree( GetProcessHeap(), 0, ptr );
958 break;
960 case WM_SETTEXT:
961 case WM_WININICHANGE:
962 case CB_DIR:
963 case CB_FINDSTRING:
964 case CB_FINDSTRINGEXACT:
965 case CB_SELECTSTRING:
966 case LB_DIR:
967 case LB_ADDFILE:
968 case LB_FINDSTRING:
969 case LB_FINDSTRINGEXACT:
970 case LB_SELECTSTRING:
971 case EM_REPLACESEL:
972 HeapFree( GetProcessHeap(), 0, (void *)lParam );
973 break;
975 case WM_NCCREATE:
976 case WM_CREATE:
978 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
979 if (HIWORD(cs->lpszName))
980 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszName );
981 if (HIWORD(cs->lpszClass))
982 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszClass );
983 HeapFree( GetProcessHeap(), 0, cs );
985 break;
987 case WM_MDICREATE:
989 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
990 if (HIWORD(cs->szTitle))
991 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
992 if (HIWORD(cs->szClass))
993 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
994 HeapFree( GetProcessHeap(), 0, cs );
996 break;
998 /* Listbox */
999 case LB_ADDSTRING:
1000 case LB_INSERTSTRING:
1001 if ( WINPROC_TestLBForStr( hwnd ))
1002 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1003 break;
1005 case LB_GETTEXT:
1006 if ( WINPROC_TestLBForStr( hwnd ))
1008 LPARAM *ptr = (LPARAM *)lParam - 1;
1009 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, 0x7fffffff );
1010 HeapFree( GetProcessHeap(), 0, ptr );
1012 break;
1014 /* Combobox */
1015 case CB_ADDSTRING:
1016 case CB_INSERTSTRING:
1017 if ( WINPROC_TestCBForStr( hwnd ))
1018 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1019 break;
1021 case CB_GETLBTEXT:
1022 if ( WINPROC_TestCBForStr( hwnd ))
1024 LPARAM *ptr = (LPARAM *)lParam - 1;
1025 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, 0x7fffffff );
1026 HeapFree( GetProcessHeap(), 0, ptr );
1028 break;
1030 /* Multiline edit */
1031 case EM_GETLINE:
1032 { LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lparam */
1033 WORD len = *(WORD *)ptr;
1034 if (len)
1036 if (!MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, len ))
1037 ((LPWSTR)*ptr)[len-1] = 0;
1039 HeapFree( GetProcessHeap(), 0, ptr );
1041 break;
1046 /**********************************************************************
1047 * WINPROC_MapMsg16To32A
1049 * Map a message from 16- to 32-bit Ansi.
1050 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1052 INT WINPROC_MapMsg16To32A( UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
1053 WPARAM *pwparam32, LPARAM *plparam )
1055 *pmsg32 = (UINT)msg16;
1056 *pwparam32 = (WPARAM)wParam16;
1057 switch(msg16)
1059 case WM_ACTIVATE:
1060 case WM_CHARTOITEM:
1061 case WM_COMMAND:
1062 case WM_VKEYTOITEM:
1063 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
1064 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1065 return 0;
1066 case WM_HSCROLL:
1067 case WM_VSCROLL:
1068 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1069 *plparam = (LPARAM)(HWND)HIWORD(*plparam);
1070 return 0;
1071 case WM_CTLCOLOR:
1072 if ( HIWORD(*plparam) > CTLCOLOR_STATIC ) return -1;
1073 *pmsg32 = WM_CTLCOLORMSGBOX + HIWORD(*plparam);
1074 *pwparam32 = (WPARAM)(HDC)wParam16;
1075 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1076 return 0;
1077 case WM_COMPAREITEM:
1079 COMPAREITEMSTRUCT16* cis16 = MapSL(*plparam);
1080 COMPAREITEMSTRUCT *cis = (COMPAREITEMSTRUCT *)
1081 HeapAlloc(GetProcessHeap(), 0, sizeof(*cis));
1082 if (!cis) return -1;
1083 cis->CtlType = cis16->CtlType;
1084 cis->CtlID = cis16->CtlID;
1085 cis->hwndItem = cis16->hwndItem;
1086 cis->itemID1 = cis16->itemID1;
1087 cis->itemData1 = cis16->itemData1;
1088 cis->itemID2 = cis16->itemID2;
1089 cis->itemData2 = cis16->itemData2;
1090 cis->dwLocaleId = 0; /* FIXME */
1091 *plparam = (LPARAM)cis;
1093 return 1;
1094 case WM_DELETEITEM:
1096 DELETEITEMSTRUCT16* dis16 = MapSL(*plparam);
1097 DELETEITEMSTRUCT *dis = (DELETEITEMSTRUCT *)
1098 HeapAlloc(GetProcessHeap(), 0, sizeof(*dis));
1099 if (!dis) return -1;
1100 dis->CtlType = dis16->CtlType;
1101 dis->CtlID = dis16->CtlID;
1102 dis->hwndItem = dis16->hwndItem;
1103 dis->itemData = dis16->itemData;
1104 *plparam = (LPARAM)dis;
1106 return 1;
1107 case WM_MEASUREITEM:
1109 MEASUREITEMSTRUCT16* mis16 = MapSL(*plparam);
1110 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)
1111 HeapAlloc(GetProcessHeap(), 0,
1112 sizeof(*mis) + sizeof(LPARAM));
1113 if (!mis) return -1;
1114 mis->CtlType = mis16->CtlType;
1115 mis->CtlID = mis16->CtlID;
1116 mis->itemID = mis16->itemID;
1117 mis->itemWidth = mis16->itemWidth;
1118 mis->itemHeight = mis16->itemHeight;
1119 mis->itemData = mis16->itemData;
1120 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
1121 *plparam = (LPARAM)mis;
1123 return 1;
1124 case WM_DRAWITEM:
1126 DRAWITEMSTRUCT16* dis16 = MapSL(*plparam);
1127 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT*)HeapAlloc(GetProcessHeap(), 0,
1128 sizeof(*dis));
1129 if (!dis) return -1;
1130 dis->CtlType = dis16->CtlType;
1131 dis->CtlID = dis16->CtlID;
1132 dis->itemID = dis16->itemID;
1133 dis->itemAction = dis16->itemAction;
1134 dis->itemState = dis16->itemState;
1135 dis->hwndItem = dis16->hwndItem;
1136 dis->hDC = dis16->hDC;
1137 dis->itemData = dis16->itemData;
1138 CONV_RECT16TO32( &dis16->rcItem, &dis->rcItem );
1139 *plparam = (LPARAM)dis;
1141 return 1;
1142 case WM_GETMINMAXINFO:
1144 MINMAXINFO *mmi = (MINMAXINFO *)HeapAlloc( GetProcessHeap(), 0,
1145 sizeof(*mmi) + sizeof(LPARAM));
1146 if (!mmi) return -1;
1147 STRUCT32_MINMAXINFO16to32( MapSL(*plparam), mmi );
1148 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
1149 *plparam = (LPARAM)mmi;
1151 return 1;
1152 case WM_GETTEXT:
1153 case WM_SETTEXT:
1154 *plparam = (LPARAM)MapSL(*plparam);
1155 return 0;
1156 case WM_MDICREATE:
1158 MDICREATESTRUCT16 *cs16 = MapSL(*plparam);
1159 MDICREATESTRUCTA *cs = HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) + sizeof(LPARAM) );
1160 if (!cs) return -1;
1161 STRUCT32_MDICREATESTRUCT16to32A( cs16, cs );
1162 cs->szTitle = MapSL(cs16->szTitle);
1163 cs->szClass = MapSL(cs16->szClass);
1164 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1165 *plparam = (LPARAM)cs;
1167 return 1;
1168 case WM_MDIGETACTIVE:
1169 *plparam = (LPARAM)HeapAlloc( GetProcessHeap(), 0, sizeof(BOOL) );
1170 *(BOOL*)(*plparam) = 0;
1171 return 1;
1172 case WM_MDISETMENU:
1173 if(wParam16==TRUE)
1174 *pmsg32=WM_MDIREFRESHMENU;
1175 *pwparam32 = (WPARAM)(HMENU)LOWORD(*plparam);
1176 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1177 return 0;
1178 case WM_MENUCHAR:
1179 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1180 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1181 return 0;
1182 case WM_MENUSELECT:
1183 if((LOWORD(*plparam) & MF_POPUP) && (LOWORD(*plparam) != 0xFFFF))
1185 HMENU hmenu=(HMENU)HIWORD(*plparam);
1186 UINT Pos=MENU_FindSubMenu( &hmenu, wParam16);
1187 if(Pos==0xFFFF) Pos=0; /* NO_SELECTED_ITEM */
1188 *pwparam32 = MAKEWPARAM( Pos, LOWORD(*plparam) );
1190 else *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1191 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1192 return 0;
1193 case WM_MDIACTIVATE:
1194 if( *plparam )
1196 *pwparam32 = (WPARAM)(HWND)HIWORD(*plparam);
1197 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1199 else /* message sent to MDI client */
1200 *pwparam32 = wParam16;
1201 return 0;
1202 case WM_NCCALCSIZE:
1204 NCCALCSIZE_PARAMS16 *nc16;
1205 NCCALCSIZE_PARAMS *nc;
1207 nc = (NCCALCSIZE_PARAMS *)HeapAlloc( GetProcessHeap(), 0,
1208 sizeof(*nc) + sizeof(LPARAM) );
1209 if (!nc) return -1;
1210 nc16 = MapSL(*plparam);
1211 CONV_RECT16TO32( &nc16->rgrc[0], &nc->rgrc[0] );
1212 if (wParam16)
1214 nc->lppos = (WINDOWPOS *)HeapAlloc( GetProcessHeap(), 0,
1215 sizeof(*nc->lppos) );
1216 CONV_RECT16TO32( &nc16->rgrc[1], &nc->rgrc[1] );
1217 CONV_RECT16TO32( &nc16->rgrc[2], &nc->rgrc[2] );
1218 if (nc->lppos) STRUCT32_WINDOWPOS16to32( MapSL(nc16->lppos), nc->lppos );
1220 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
1221 *plparam = (LPARAM)nc;
1223 return 1;
1224 case WM_NCCREATE:
1225 case WM_CREATE:
1227 CREATESTRUCT16 *cs16 = MapSL(*plparam);
1228 CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
1229 sizeof(*cs) + sizeof(LPARAM) );
1230 if (!cs) return -1;
1231 STRUCT32_CREATESTRUCT16to32A( cs16, cs );
1232 cs->lpszName = MapSL(cs16->lpszName);
1233 cs->lpszClass = MapSL(cs16->lpszClass);
1234 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1235 *plparam = (LPARAM)cs;
1237 return 1;
1238 case WM_PARENTNOTIFY:
1239 if ((wParam16 == WM_CREATE) || (wParam16 == WM_DESTROY))
1241 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
1242 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1244 return 0;
1245 case WM_WINDOWPOSCHANGING:
1246 case WM_WINDOWPOSCHANGED:
1248 WINDOWPOS *wp = (WINDOWPOS *)HeapAlloc( GetProcessHeap(), 0,
1249 sizeof(*wp) + sizeof(LPARAM) );
1250 if (!wp) return -1;
1251 STRUCT32_WINDOWPOS16to32( MapSL(*plparam), wp );
1252 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
1253 *plparam = (LPARAM)wp;
1255 return 1;
1256 case WM_GETDLGCODE:
1257 if (*plparam)
1259 LPMSG16 msg16 = MapSL(*plparam);
1260 LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1262 if (!msg32) return -1;
1263 msg32->hwnd = msg16->hwnd;
1264 msg32->lParam = msg16->lParam;
1265 msg32->time = msg16->time;
1266 CONV_POINT16TO32(&msg16->pt,&msg32->pt);
1267 /* this is right, right? */
1268 if (WINPROC_MapMsg16To32A(msg16->message,msg16->wParam,
1269 &msg32->message,&msg32->wParam,
1270 &msg32->lParam)<0) {
1271 HeapFree( GetProcessHeap(), 0, msg32 );
1272 return -1;
1274 *plparam = (LPARAM)msg32;
1275 return 1;
1277 else return 0;
1278 case WM_NOTIFY:
1279 *plparam = (LPARAM)MapSL(*plparam);
1280 return 1;
1281 case WM_ACTIVATEAPP:
1282 if (*plparam)
1283 { /* We need this when SetActiveWindow sends a Sendmessage16() to
1284 a 32bit window. Might be superflous with 32bit interprocess
1285 message queues.
1287 HTASK16 htask = (HTASK16) *plparam;
1288 DWORD idThread = (DWORD)((TDB*)GlobalLock16(htask))->teb->tid;
1289 *plparam = (LPARAM) idThread;
1291 return 1;
1292 case WM_ASKCBFORMATNAME:
1293 case WM_DEVMODECHANGE:
1294 case WM_PAINTCLIPBOARD:
1295 case WM_SIZECLIPBOARD:
1296 case WM_WININICHANGE:
1297 FIXME_(msg)("message %04x needs translation\n",msg16 );
1298 return -1;
1300 default: /* No translation needed */
1301 return 0;
1306 /**********************************************************************
1307 * WINPROC_UnmapMsg16To32A
1309 * Unmap a message that was mapped from 16- to 32-bit Ansi.
1311 LRESULT WINPROC_UnmapMsg16To32A( HWND16 hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1312 LRESULT result )
1314 switch(msg)
1316 case WM_COMPAREITEM:
1317 case WM_DELETEITEM:
1318 case WM_DRAWITEM:
1319 HeapFree( GetProcessHeap(), 0, (LPVOID)lParam );
1320 break;
1321 case WM_MEASUREITEM:
1323 MEASUREITEMSTRUCT16 *mis16;
1324 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lParam;
1325 lParam = *(LPARAM *)(mis + 1);
1326 mis16 = MapSL(lParam);
1327 mis16->itemWidth = (UINT16)mis->itemWidth;
1328 mis16->itemHeight = (UINT16)mis->itemHeight;
1329 HeapFree( GetProcessHeap(), 0, mis );
1331 break;
1332 case WM_GETMINMAXINFO:
1334 MINMAXINFO *mmi = (MINMAXINFO *)lParam;
1335 lParam = *(LPARAM *)(mmi + 1);
1336 STRUCT32_MINMAXINFO32to16( mmi, MapSL(lParam));
1337 HeapFree( GetProcessHeap(), 0, mmi );
1339 break;
1340 case WM_MDICREATE:
1342 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
1343 lParam = *(LPARAM *)(cs + 1);
1344 STRUCT32_MDICREATESTRUCT32Ato16( cs, MapSL(lParam) );
1345 HeapFree( GetProcessHeap(), 0, cs );
1347 break;
1348 case WM_MDIGETACTIVE:
1349 result = MAKELONG( LOWORD(result), (BOOL16)(*(BOOL *)lParam) );
1350 HeapFree( GetProcessHeap(), 0, (BOOL *)lParam );
1351 break;
1352 case WM_NCCALCSIZE:
1354 NCCALCSIZE_PARAMS16 *nc16;
1355 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lParam;
1356 lParam = *(LPARAM *)(nc + 1);
1357 nc16 = MapSL(lParam);
1358 CONV_RECT32TO16( &nc->rgrc[0], &nc16->rgrc[0] );
1359 if (wParam)
1361 CONV_RECT32TO16( &nc->rgrc[1], &nc16->rgrc[1] );
1362 CONV_RECT32TO16( &nc->rgrc[2], &nc16->rgrc[2] );
1363 if (nc->lppos)
1365 STRUCT32_WINDOWPOS32to16( nc->lppos, MapSL(nc16->lppos));
1366 HeapFree( GetProcessHeap(), 0, nc->lppos );
1369 HeapFree( GetProcessHeap(), 0, nc );
1371 break;
1372 case WM_NCCREATE:
1373 case WM_CREATE:
1375 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
1376 lParam = *(LPARAM *)(cs + 1);
1377 STRUCT32_CREATESTRUCT32Ato16( cs, MapSL(lParam) );
1378 HeapFree( GetProcessHeap(), 0, cs );
1380 break;
1381 case WM_WINDOWPOSCHANGING:
1382 case WM_WINDOWPOSCHANGED:
1384 WINDOWPOS *wp = (WINDOWPOS *)lParam;
1385 lParam = *(LPARAM *)(wp + 1);
1386 STRUCT32_WINDOWPOS32to16(wp, MapSL(lParam));
1387 HeapFree( GetProcessHeap(), 0, wp );
1389 break;
1390 case WM_GETDLGCODE:
1391 if (lParam)
1393 LPMSG msg32 = (LPMSG)lParam;
1395 WINPROC_UnmapMsg16To32A( hwnd, msg32->message, msg32->wParam, msg32->lParam,
1396 result);
1397 HeapFree( GetProcessHeap(), 0, msg32 );
1399 break;
1401 return result;
1405 /**********************************************************************
1406 * WINPROC_MapMsg16To32W
1408 * Map a message from 16- to 32-bit Unicode.
1409 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1411 INT WINPROC_MapMsg16To32W( HWND16 hwnd, UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
1412 WPARAM *pwparam32, LPARAM *plparam )
1414 *pmsg32=(UINT)msg16;
1415 *pwparam32 = (WPARAM)wParam16;
1416 switch(msg16)
1418 case EM_GETLINE16:
1420 WORD len = (WORD)*plparam;
1421 LPARAM *ptr = (LPARAM *)HeapAlloc(GetProcessHeap(), 0, sizeof(LPARAM) + sizeof(WORD) + len * sizeof(WCHAR));
1422 if(!ptr) return -1;
1423 *ptr++ = *plparam; /* Store previous lParam */
1424 *((WORD *)ptr) = len; /* Store the length */
1425 *plparam = (LPARAM)ptr;
1427 return 1;
1429 case EM_REPLACESEL16:
1431 WCHAR *str;
1432 INT len;
1433 *plparam = (LPARAM)MapSL(*plparam);
1434 len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)*plparam, -1, NULL, 0);
1435 str = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
1436 if(!str) return -1;
1437 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)*plparam, -1, str, len);
1438 *plparam = (LPARAM)str;
1440 return 1;
1442 case WM_GETTEXT:
1443 case WM_SETTEXT:
1444 *plparam = (LPARAM)MapSL(*plparam);
1445 return WINPROC_MapMsg32ATo32W( hwnd, *pmsg32, pwparam32, plparam );
1446 case WM_NCCREATE:
1447 case WM_CREATE:
1449 CREATESTRUCT16 *cs16 = MapSL(*plparam);
1450 CREATESTRUCTW *cs = (CREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
1451 sizeof(*cs) + sizeof(LPARAM) );
1452 if (!cs) return -1;
1453 STRUCT32_CREATESTRUCT16to32A( cs16, (CREATESTRUCTA *)cs );
1454 cs->lpszName = MapSL(cs16->lpszName);
1455 cs->lpszClass = MapSL(cs16->lpszClass);
1456 if (HIWORD(cs->lpszName))
1457 cs->lpszName = HEAP_strdupAtoW( GetProcessHeap(), 0,
1458 (LPCSTR)cs->lpszName );
1459 if (HIWORD(cs->lpszClass))
1460 cs->lpszClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
1461 (LPCSTR)cs->lpszClass );
1462 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1463 *plparam = (LPARAM)cs;
1465 return 1;
1466 case WM_MDICREATE:
1468 MDICREATESTRUCT16 *cs16 = MapSL(*plparam);
1469 MDICREATESTRUCTW *cs =
1470 (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
1471 sizeof(*cs) + sizeof(LPARAM) );
1472 if (!cs) return -1;
1473 STRUCT32_MDICREATESTRUCT16to32A( cs16, (MDICREATESTRUCTA *)cs );
1474 cs->szTitle = MapSL(cs16->szTitle);
1475 cs->szClass = MapSL(cs16->szClass);
1476 if (HIWORD(cs->szTitle))
1477 cs->szTitle = HEAP_strdupAtoW( GetProcessHeap(), 0,
1478 (LPCSTR)cs->szTitle );
1479 if (HIWORD(cs->szClass))
1480 cs->szClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
1481 (LPCSTR)cs->szClass );
1482 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1483 *plparam = (LPARAM)cs;
1485 return 1;
1486 case WM_GETDLGCODE:
1487 if (*plparam)
1489 LPMSG16 msg16 = MapSL(*plparam);
1490 LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1492 if (!msg32) return -1;
1493 msg32->hwnd = msg16->hwnd;
1494 msg32->lParam = msg16->lParam;
1495 msg32->time = msg16->time;
1496 CONV_POINT16TO32(&msg16->pt,&msg32->pt);
1497 /* this is right, right? */
1498 if (WINPROC_MapMsg16To32W(hwnd, msg16->message,msg16->wParam,
1499 &msg32->message,&msg32->wParam,
1500 &msg32->lParam)<0) {
1501 HeapFree( GetProcessHeap(), 0, msg32 );
1502 return -1;
1504 *plparam = (LPARAM)msg32;
1505 return 1;
1507 else return 0;
1509 case WM_CHAR:
1510 case WM_DEADCHAR:
1511 case WM_SYSCHAR:
1512 case WM_SYSDEADCHAR:
1513 case EM_SETPASSWORDCHAR16:
1515 char ch = wParam16;
1516 WCHAR wch;
1517 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1518 *pwparam32 = wch;
1520 return 0;
1522 default: /* No Unicode translation needed */
1523 return WINPROC_MapMsg16To32A( msg16, wParam16, pmsg32,
1524 pwparam32, plparam );
1529 /**********************************************************************
1530 * WINPROC_UnmapMsg16To32W
1532 * Unmap a message that was mapped from 16- to 32-bit Unicode.
1534 LRESULT WINPROC_UnmapMsg16To32W( HWND16 hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1535 LRESULT result )
1537 switch(msg)
1539 case EM_GETLINE16:
1541 LPARAM *ptr = (LPARAM *)lParam - 1; /* get the old lParam */
1542 WORD len = *(WORD *)lParam;
1543 *ptr = (LPARAM)MapSL(*ptr);
1544 if(len > 0 && !WideCharToMultiByte(CP_ACP, 0, (LPWSTR)lParam, -1,
1545 (LPSTR)*ptr, len, NULL, NULL))
1546 ((LPSTR)*ptr)[len-1] = 0;
1547 HeapFree(GetProcessHeap(), 0, ptr);
1549 break;
1551 case EM_REPLACESEL16:
1552 HeapFree(GetProcessHeap(), 0, (void *)lParam);
1553 break;
1555 case WM_GETTEXT:
1556 case WM_SETTEXT:
1557 WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam );
1558 break;
1559 case WM_NCCREATE:
1560 case WM_CREATE:
1562 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
1563 lParam = *(LPARAM *)(cs + 1);
1564 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs, MapSL(lParam) );
1565 if (HIWORD(cs->lpszName))
1566 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszName );
1567 if (HIWORD(cs->lpszClass))
1568 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszClass );
1569 HeapFree( GetProcessHeap(), 0, cs );
1571 break;
1572 case WM_MDICREATE:
1574 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
1575 lParam = *(LPARAM *)(cs + 1);
1576 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs, MapSL(lParam) );
1577 if (HIWORD(cs->szTitle))
1578 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
1579 if (HIWORD(cs->szClass))
1580 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
1581 HeapFree( GetProcessHeap(), 0, cs );
1583 break;
1584 case WM_GETDLGCODE:
1585 if (lParam)
1587 LPMSG msg32 = (LPMSG)lParam;
1589 WINPROC_UnmapMsg16To32W( hwnd, msg32->message, msg32->wParam, msg32->lParam,
1590 result);
1591 HeapFree( GetProcessHeap(), 0, msg32 );
1593 break;
1594 default:
1595 return WINPROC_UnmapMsg16To32A( hwnd, msg, wParam, lParam, result );
1597 return result;
1601 /**********************************************************************
1602 * WINPROC_MapMsg32ATo16
1604 * Map a message from 32-bit Ansi to 16-bit.
1605 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1607 INT WINPROC_MapMsg32ATo16( HWND hwnd, UINT msg32, WPARAM wParam32,
1608 UINT16 *pmsg16, WPARAM16 *pwparam16,
1609 LPARAM *plparam )
1611 *pmsg16 = (UINT16)msg32;
1612 *pwparam16 = (WPARAM16)LOWORD(wParam32);
1613 switch(msg32)
1615 case BM_GETCHECK:
1616 case BM_SETCHECK:
1617 case BM_GETSTATE:
1618 case BM_SETSTATE:
1619 case BM_SETSTYLE:
1620 *pmsg16 = (UINT16)msg32 + (BM_GETCHECK16 - BM_GETCHECK);
1621 return 0;
1623 case EM_GETSEL:
1624 case EM_GETRECT:
1625 case EM_SETRECT:
1626 case EM_SETRECTNP:
1627 case EM_SCROLL:
1628 case EM_LINESCROLL:
1629 case EM_SCROLLCARET:
1630 case EM_GETMODIFY:
1631 case EM_SETMODIFY:
1632 case EM_GETLINECOUNT:
1633 case EM_LINEINDEX:
1634 case EM_SETHANDLE:
1635 case EM_GETHANDLE:
1636 case EM_GETTHUMB:
1637 case EM_LINELENGTH:
1638 case EM_REPLACESEL:
1639 case EM_GETLINE:
1640 case EM_LIMITTEXT:
1641 case EM_CANUNDO:
1642 case EM_UNDO:
1643 case EM_FMTLINES:
1644 case EM_LINEFROMCHAR:
1645 case EM_SETTABSTOPS:
1646 case EM_SETPASSWORDCHAR:
1647 case EM_EMPTYUNDOBUFFER:
1648 case EM_GETFIRSTVISIBLELINE:
1649 case EM_SETREADONLY:
1650 case EM_SETWORDBREAKPROC:
1651 case EM_GETWORDBREAKPROC:
1652 case EM_GETPASSWORDCHAR:
1653 *pmsg16 = (UINT16)msg32 + (EM_GETSEL16 - EM_GETSEL);
1654 return 0;
1656 case LB_CARETOFF:
1657 case LB_CARETON:
1658 case LB_DELETESTRING:
1659 case LB_GETANCHORINDEX:
1660 case LB_GETCARETINDEX:
1661 case LB_GETCOUNT:
1662 case LB_GETCURSEL:
1663 case LB_GETHORIZONTALEXTENT:
1664 case LB_GETITEMDATA:
1665 case LB_GETITEMHEIGHT:
1666 case LB_GETSEL:
1667 case LB_GETSELCOUNT:
1668 case LB_GETTEXTLEN:
1669 case LB_GETTOPINDEX:
1670 case LB_RESETCONTENT:
1671 case LB_SELITEMRANGE:
1672 case LB_SELITEMRANGEEX:
1673 case LB_SETANCHORINDEX:
1674 case LB_SETCARETINDEX:
1675 case LB_SETCOLUMNWIDTH:
1676 case LB_SETCURSEL:
1677 case LB_SETHORIZONTALEXTENT:
1678 case LB_SETITEMDATA:
1679 case LB_SETITEMHEIGHT:
1680 case LB_SETSEL:
1681 case LB_SETTOPINDEX:
1682 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
1683 return 0;
1684 case CB_DELETESTRING:
1685 case CB_GETCOUNT:
1686 case CB_GETLBTEXTLEN:
1687 case CB_LIMITTEXT:
1688 case CB_RESETCONTENT:
1689 case CB_SETEDITSEL:
1690 case CB_GETCURSEL:
1691 case CB_SETCURSEL:
1692 case CB_SHOWDROPDOWN:
1693 case CB_SETITEMDATA:
1694 case CB_SETITEMHEIGHT:
1695 case CB_GETITEMHEIGHT:
1696 case CB_SETEXTENDEDUI:
1697 case CB_GETEXTENDEDUI:
1698 case CB_GETDROPPEDSTATE:
1699 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
1700 return 0;
1701 case CB_GETEDITSEL:
1702 *pmsg16 = CB_GETEDITSEL16;
1703 return 1;
1705 case LB_ADDSTRING:
1706 case LB_FINDSTRING:
1707 case LB_FINDSTRINGEXACT:
1708 case LB_INSERTSTRING:
1709 case LB_SELECTSTRING:
1710 case LB_DIR:
1711 case LB_ADDFILE:
1713 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
1714 if (!str) return -1;
1715 *plparam = (LPARAM)SEGPTR_GET(str);
1717 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
1718 return 1;
1720 case CB_ADDSTRING:
1721 case CB_FINDSTRING:
1722 case CB_FINDSTRINGEXACT:
1723 case CB_INSERTSTRING:
1724 case CB_SELECTSTRING:
1725 case CB_DIR:
1727 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
1728 if (!str) return -1;
1729 *plparam = (LPARAM)SEGPTR_GET(str);
1731 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
1732 return 1;
1734 case LB_GETITEMRECT:
1736 RECT16 *rect;
1737 rect = (RECT16 *)SEGPTR_ALLOC( sizeof(RECT16) + sizeof(LPARAM) );
1738 if (!rect) return -1;
1739 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
1740 *plparam = (LPARAM)SEGPTR_GET(rect);
1742 *pmsg16 = LB_GETITEMRECT16;
1743 return 1;
1744 case LB_GETSELITEMS:
1746 LPINT16 items;
1747 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
1748 if (!(items = SEGPTR_ALLOC( *pwparam16 * sizeof(INT16)
1749 + sizeof(LPARAM)))) return -1;
1750 *((LPARAM *)items)++ = *plparam; /* Store the previous lParam */
1751 *plparam = (LPARAM)SEGPTR_GET(items);
1753 *pmsg16 = LB_GETSELITEMS16;
1754 return 1;
1755 case LB_SETTABSTOPS:
1756 if (wParam32)
1758 INT i;
1759 LPINT16 stops;
1760 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
1761 if (!(stops = SEGPTR_ALLOC( *pwparam16 * sizeof(INT16)
1762 + sizeof(LPARAM)))) return -1;
1763 for (i = 0; i < *pwparam16; i++) stops[i] = *((LPINT)*plparam+i);
1764 *plparam = (LPARAM)SEGPTR_GET(stops);
1765 return 1;
1767 *pmsg16 = LB_SETTABSTOPS16;
1768 return 0;
1770 case CB_GETDROPPEDCONTROLRECT:
1772 RECT16 *rect;
1773 rect = (RECT16 *)SEGPTR_ALLOC( sizeof(RECT16) + sizeof(LPARAM) );
1774 if (!rect) return -1;
1775 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
1776 *plparam = (LPARAM)SEGPTR_GET(rect);
1778 *pmsg16 = CB_GETDROPPEDCONTROLRECT16;
1779 return 1;
1781 case LB_GETTEXT:
1782 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
1783 *pmsg16 = LB_GETTEXT16;
1784 return 1;
1786 case CB_GETLBTEXT:
1787 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
1788 *pmsg16 = CB_GETLBTEXT16;
1789 return 1;
1791 case EM_SETSEL:
1792 *pwparam16 = 0;
1793 *plparam = MAKELONG( (INT16)(INT)wParam32, (INT16)*plparam );
1794 *pmsg16 = EM_SETSEL16;
1795 return 0;
1797 case WM_ACTIVATE:
1798 case WM_CHARTOITEM:
1799 case WM_COMMAND:
1800 case WM_VKEYTOITEM:
1801 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
1802 return 0;
1803 case WM_HSCROLL:
1804 case WM_VSCROLL:
1805 *plparam = MAKELPARAM( HIWORD(wParam32), (HWND16)*plparam );
1806 return 0;
1807 case WM_CTLCOLORMSGBOX:
1808 case WM_CTLCOLOREDIT:
1809 case WM_CTLCOLORLISTBOX:
1810 case WM_CTLCOLORBTN:
1811 case WM_CTLCOLORDLG:
1812 case WM_CTLCOLORSCROLLBAR:
1813 case WM_CTLCOLORSTATIC:
1814 *pmsg16 = WM_CTLCOLOR;
1815 *plparam = MAKELPARAM( (HWND16)*plparam,
1816 (WORD)msg32 - WM_CTLCOLORMSGBOX );
1817 return 0;
1818 case WM_COMPAREITEM:
1820 COMPAREITEMSTRUCT *cis32 = (COMPAREITEMSTRUCT *)*plparam;
1821 COMPAREITEMSTRUCT16 *cis = SEGPTR_NEW(COMPAREITEMSTRUCT16);
1822 if (!cis) return -1;
1823 cis->CtlType = (UINT16)cis32->CtlType;
1824 cis->CtlID = (UINT16)cis32->CtlID;
1825 cis->hwndItem = (HWND16)cis32->hwndItem;
1826 cis->itemID1 = (UINT16)cis32->itemID1;
1827 cis->itemData1 = cis32->itemData1;
1828 cis->itemID2 = (UINT16)cis32->itemID2;
1829 cis->itemData2 = cis32->itemData2;
1830 *plparam = (LPARAM)SEGPTR_GET(cis);
1832 return 1;
1833 case WM_DELETEITEM:
1835 DELETEITEMSTRUCT *dis32 = (DELETEITEMSTRUCT *)*plparam;
1836 DELETEITEMSTRUCT16 *dis = SEGPTR_NEW(DELETEITEMSTRUCT16);
1837 if (!dis) return -1;
1838 dis->CtlType = (UINT16)dis32->CtlType;
1839 dis->CtlID = (UINT16)dis32->CtlID;
1840 dis->itemID = (UINT16)dis32->itemID;
1841 dis->hwndItem = (HWND16)dis32->hwndItem;
1842 dis->itemData = dis32->itemData;
1843 *plparam = (LPARAM)SEGPTR_GET(dis);
1845 return 1;
1846 case WM_DRAWITEM:
1848 DRAWITEMSTRUCT *dis32 = (DRAWITEMSTRUCT *)*plparam;
1849 DRAWITEMSTRUCT16 *dis = SEGPTR_NEW(DRAWITEMSTRUCT16);
1850 if (!dis) return -1;
1851 dis->CtlType = (UINT16)dis32->CtlType;
1852 dis->CtlID = (UINT16)dis32->CtlID;
1853 dis->itemID = (UINT16)dis32->itemID;
1854 dis->itemAction = (UINT16)dis32->itemAction;
1855 dis->itemState = (UINT16)dis32->itemState;
1856 dis->hwndItem = (HWND16)dis32->hwndItem;
1857 dis->hDC = (HDC16)dis32->hDC;
1858 dis->itemData = dis32->itemData;
1859 CONV_RECT32TO16( &dis32->rcItem, &dis->rcItem );
1860 *plparam = (LPARAM)SEGPTR_GET(dis);
1862 return 1;
1863 case WM_MEASUREITEM:
1865 MEASUREITEMSTRUCT *mis32 = (MEASUREITEMSTRUCT *)*plparam;
1866 MEASUREITEMSTRUCT16 *mis = (MEASUREITEMSTRUCT16 *)
1867 SEGPTR_ALLOC(sizeof(*mis)+sizeof(LPARAM));
1868 if (!mis) return -1;
1869 mis->CtlType = (UINT16)mis32->CtlType;
1870 mis->CtlID = (UINT16)mis32->CtlID;
1871 mis->itemID = (UINT16)mis32->itemID;
1872 mis->itemWidth = (UINT16)mis32->itemWidth;
1873 mis->itemHeight = (UINT16)mis32->itemHeight;
1874 mis->itemData = mis32->itemData;
1875 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
1876 *plparam = (LPARAM)SEGPTR_GET(mis);
1878 return 1;
1879 case WM_GETMINMAXINFO:
1881 MINMAXINFO16 *mmi = (MINMAXINFO16 *)SEGPTR_ALLOC( sizeof(*mmi) +
1882 sizeof(LPARAM) );
1883 if (!mmi) return -1;
1884 STRUCT32_MINMAXINFO32to16( (MINMAXINFO *)*plparam, mmi );
1885 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
1886 *plparam = (LPARAM)SEGPTR_GET(mmi);
1888 return 1;
1889 case WM_GETTEXT:
1891 LPSTR str;
1892 *pwparam16 = (WPARAM16)min( wParam32, 0xff80 ); /* Must be < 64K */
1893 if (!(str = SEGPTR_ALLOC(*pwparam16 + sizeof(LPARAM)))) return -1;
1894 *((LPARAM *)str)++ = *plparam; /* Store the previous lParam */
1895 *plparam = (LPARAM)SEGPTR_GET(str);
1897 return 1;
1898 case WM_MDICREATE:
1900 MDICREATESTRUCT16 *cs;
1901 MDICREATESTRUCTA *cs32 = (MDICREATESTRUCTA *)*plparam;
1902 LPSTR name, cls;
1904 if (!(cs = SEGPTR_NEW(MDICREATESTRUCT16))) return -1;
1905 STRUCT32_MDICREATESTRUCT32Ato16( cs32, cs );
1906 name = SEGPTR_STRDUP( cs32->szTitle );
1907 cls = SEGPTR_STRDUP( cs32->szClass );
1908 cs->szTitle = SEGPTR_GET(name);
1909 cs->szClass = SEGPTR_GET(cls);
1910 *plparam = (LPARAM)SEGPTR_GET(cs);
1912 return 1;
1913 case WM_MDIGETACTIVE:
1914 return 1;
1915 case WM_MDISETMENU:
1916 *plparam = MAKELPARAM( (HMENU16)LOWORD(wParam32),
1917 (HMENU16)LOWORD(*plparam) );
1918 *pwparam16 = (*plparam == 0);
1919 return 0;
1920 case WM_MENUSELECT:
1921 if(HIWORD(wParam32) & MF_POPUP)
1923 UINT16 hmenu;
1924 if (((UINT)HIWORD(wParam32) != 0xFFFF) || (*plparam))
1926 if((hmenu = GetSubMenu((HMENU16)*plparam, *pwparam16)))
1927 *pwparam16=hmenu;
1930 /* fall through */
1931 case WM_MENUCHAR:
1932 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
1933 return 0;
1934 case WM_MDIACTIVATE:
1935 if (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_MDICHILD)
1937 *pwparam16 = ((HWND)*plparam == hwnd);
1938 *plparam = MAKELPARAM( (HWND16)LOWORD(*plparam),
1939 (HWND16)LOWORD(wParam32) );
1941 else
1943 *pwparam16 = (HWND)wParam32;
1944 *plparam = 0;
1946 return 0;
1947 case WM_NCCALCSIZE:
1949 NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)*plparam;
1950 NCCALCSIZE_PARAMS16 *nc = (NCCALCSIZE_PARAMS16 *)SEGPTR_ALLOC( sizeof(*nc) + sizeof(LPARAM) );
1951 if (!nc) return -1;
1953 CONV_RECT32TO16( &nc32->rgrc[0], &nc->rgrc[0] );
1954 if (wParam32)
1956 WINDOWPOS16 *wp;
1957 CONV_RECT32TO16( &nc32->rgrc[1], &nc->rgrc[1] );
1958 CONV_RECT32TO16( &nc32->rgrc[2], &nc->rgrc[2] );
1959 if (!(wp = SEGPTR_NEW(WINDOWPOS16)))
1961 SEGPTR_FREE(nc);
1962 return -1;
1964 STRUCT32_WINDOWPOS32to16( nc32->lppos, wp );
1965 nc->lppos = SEGPTR_GET(wp);
1967 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
1968 *plparam = (LPARAM)SEGPTR_GET(nc);
1970 return 1;
1971 case WM_NCCREATE:
1972 case WM_CREATE:
1974 CREATESTRUCT16 *cs;
1975 CREATESTRUCTA *cs32 = (CREATESTRUCTA *)*plparam;
1976 LPSTR name, cls;
1978 if (!(cs = SEGPTR_NEW(CREATESTRUCT16))) return -1;
1979 STRUCT32_CREATESTRUCT32Ato16( cs32, cs );
1980 name = SEGPTR_STRDUP( cs32->lpszName );
1981 cls = SEGPTR_STRDUP( cs32->lpszClass );
1982 cs->lpszName = SEGPTR_GET(name);
1983 cs->lpszClass = SEGPTR_GET(cls);
1984 *plparam = (LPARAM)SEGPTR_GET(cs);
1986 return 1;
1987 case WM_PARENTNOTIFY:
1988 if ((LOWORD(wParam32)==WM_CREATE) || (LOWORD(wParam32)==WM_DESTROY))
1989 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32));
1990 /* else nothing to do */
1991 return 0;
1992 case WM_NOTIFY:
1993 *plparam = MapLS( (NMHDR *)*plparam ); /* NMHDR is already 32-bit */
1994 return 1;
1995 case WM_SETTEXT:
1997 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
1998 if (!str) return -1;
1999 *plparam = (LPARAM)SEGPTR_GET(str);
2001 return 1;
2002 case WM_WINDOWPOSCHANGING:
2003 case WM_WINDOWPOSCHANGED:
2005 WINDOWPOS16 *wp = (WINDOWPOS16 *)SEGPTR_ALLOC( sizeof(*wp) +
2006 sizeof(LPARAM) );
2007 if (!wp) return -1;
2008 STRUCT32_WINDOWPOS32to16( (WINDOWPOS *)*plparam, wp );
2009 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
2010 *plparam = (LPARAM)SEGPTR_GET(wp);
2012 return 1;
2013 case WM_GETDLGCODE:
2014 if (*plparam) {
2015 LPMSG msg32 = (LPMSG) *plparam;
2016 LPMSG16 msg16 = (LPMSG16) SEGPTR_NEW( MSG16 );
2018 if (!msg16) return -1;
2019 msg16->hwnd = msg32->hwnd;
2020 msg16->lParam = msg32->lParam;
2021 msg16->time = msg32->time;
2022 CONV_POINT32TO16(&msg32->pt,&msg16->pt);
2023 /* this is right, right? */
2024 if (WINPROC_MapMsg32ATo16(msg32->hwnd,msg32->message,msg32->wParam,
2025 &msg16->message,&msg16->wParam, &msg16->lParam)<0) {
2026 SEGPTR_FREE( msg16 );
2027 return -1;
2029 *plparam = (LPARAM)SEGPTR_GET(msg16);
2030 return 1;
2032 return 0;
2034 case WM_ACTIVATEAPP:
2035 if (*plparam) {
2036 *plparam = (LPARAM)THREAD_IdToTEB((DWORD) *plparam)->htask16;
2038 return 1;
2039 case WM_ASKCBFORMATNAME:
2040 case WM_DEVMODECHANGE:
2041 case WM_PAINTCLIPBOARD:
2042 case WM_SIZECLIPBOARD:
2043 case WM_WININICHANGE:
2044 FIXME_(msg)("message %04x needs translation\n", msg32 );
2045 return -1;
2046 case WM_SIZING: /* should not be send to 16-bit apps */
2047 return -1;
2048 default: /* No translation needed */
2049 return 0;
2054 /**********************************************************************
2055 * WINPROC_UnmapMsg32ATo16
2057 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
2059 void WINPROC_UnmapMsg32ATo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2060 MSGPARAM16* p16 )
2062 switch(msg)
2064 case LB_ADDFILE:
2065 case LB_ADDSTRING:
2066 case LB_DIR:
2067 case LB_FINDSTRING:
2068 case LB_FINDSTRINGEXACT:
2069 case LB_INSERTSTRING:
2070 case LB_SELECTSTRING:
2071 case LB_SETTABSTOPS:
2072 case CB_ADDSTRING:
2073 case CB_FINDSTRING:
2074 case CB_FINDSTRINGEXACT:
2075 case CB_INSERTSTRING:
2076 case CB_SELECTSTRING:
2077 case CB_DIR:
2078 case WM_COMPAREITEM:
2079 case WM_DELETEITEM:
2080 case WM_DRAWITEM:
2081 case WM_SETTEXT:
2082 SEGPTR_FREE( MapSL(p16->lParam) );
2083 break;
2085 case CB_GETDROPPEDCONTROLRECT:
2086 case LB_GETITEMRECT:
2088 RECT16 *rect = MapSL(p16->lParam);
2089 p16->lParam = *(LPARAM *)(rect + 1);
2090 CONV_RECT16TO32( rect, (RECT *)(p16->lParam));
2091 SEGPTR_FREE( rect );
2093 break;
2094 case LB_GETSELITEMS:
2096 INT i;
2097 LPINT16 items = MapSL(lParam);
2098 p16->lParam = *((LPARAM *)items - 1);
2099 for (i = 0; i < p16->wParam; i++) *((LPINT)(p16->lParam) + i) = items[i];
2100 SEGPTR_FREE( (LPARAM *)items - 1 );
2102 break;
2104 case CB_GETEDITSEL:
2105 if( wParam )
2106 *((LPUINT)(wParam)) = LOWORD(p16->lResult);
2107 if( lParam )
2108 *((LPUINT)(lParam)) = HIWORD(p16->lResult); /* FIXME: substract 1? */
2109 break;
2111 case LB_GETTEXT:
2112 case CB_GETLBTEXT:
2113 UnMapLS( (SEGPTR)(p16->lParam) );
2114 break;
2116 case WM_MEASUREITEM:
2118 MEASUREITEMSTRUCT16 *mis = MapSL(p16->lParam);
2119 MEASUREITEMSTRUCT *mis32 = *(MEASUREITEMSTRUCT **)(mis + 1);
2120 mis32->itemWidth = mis->itemWidth;
2121 mis32->itemHeight = mis->itemHeight;
2122 SEGPTR_FREE(mis);
2124 break;
2125 case WM_GETMINMAXINFO:
2127 MINMAXINFO16 *mmi = MapSL(p16->lParam);
2128 p16->lParam = *(LPARAM *)(mmi + 1);
2129 STRUCT32_MINMAXINFO16to32( mmi, (MINMAXINFO *)(p16->lParam) );
2130 SEGPTR_FREE(mmi);
2132 break;
2133 case WM_GETTEXT:
2135 LPSTR str = MapSL(p16->lParam);
2136 p16->lParam = *((LPARAM *)str - 1);
2137 lstrcpynA( (LPSTR)(p16->lParam), str, p16->wParam );
2138 SEGPTR_FREE( (LPARAM *)str - 1 );
2140 break;
2141 case WM_MDICREATE:
2143 MDICREATESTRUCT16 *cs = MapSL(p16->lParam);
2144 SEGPTR_FREE( MapSL(cs->szTitle) );
2145 SEGPTR_FREE( MapSL(cs->szClass) );
2146 SEGPTR_FREE( cs );
2148 break;
2149 case WM_MDIGETACTIVE:
2150 if (lParam) *(BOOL *)lParam = (BOOL16)HIWORD(p16->lResult);
2151 p16->lResult = (HWND)LOWORD(p16->lResult);
2152 break;
2153 case WM_NCCALCSIZE:
2155 NCCALCSIZE_PARAMS *nc32;
2156 NCCALCSIZE_PARAMS16 *nc = MapSL(p16->lParam);
2157 p16->lParam = *(LPARAM *)(nc + 1);
2158 nc32 = (NCCALCSIZE_PARAMS *)(p16->lParam);
2159 CONV_RECT16TO32( &nc->rgrc[0], &nc32->rgrc[0] );
2160 if (p16->wParam)
2162 CONV_RECT16TO32( &nc->rgrc[1], &nc32->rgrc[1] );
2163 CONV_RECT16TO32( &nc->rgrc[2], &nc32->rgrc[2] );
2164 STRUCT32_WINDOWPOS16to32( MapSL(nc->lppos), nc32->lppos );
2165 SEGPTR_FREE( MapSL(nc->lppos) );
2167 SEGPTR_FREE(nc);
2169 break;
2170 case WM_NCCREATE:
2171 case WM_CREATE:
2173 CREATESTRUCT16 *cs = MapSL(p16->lParam);
2174 SEGPTR_FREE( MapSL(cs->lpszName) );
2175 SEGPTR_FREE( MapSL(cs->lpszClass) );
2176 SEGPTR_FREE( cs );
2178 break;
2179 case WM_WINDOWPOSCHANGING:
2180 case WM_WINDOWPOSCHANGED:
2182 WINDOWPOS16 *wp = MapSL(p16->lParam);
2183 p16->lParam = *(LPARAM *)(wp + 1);
2184 STRUCT32_WINDOWPOS16to32( wp, (WINDOWPOS *)p16->lParam );
2185 SEGPTR_FREE(wp);
2187 break;
2188 case WM_NOTIFY:
2189 UnMapLS(p16->lParam);
2190 break;
2191 case WM_GETDLGCODE:
2192 if (p16->lParam)
2194 LPMSG16 msg16 = MapSL(p16->lParam);
2195 MSGPARAM16 msgp16;
2196 msgp16.wParam=msg16->wParam;
2197 msgp16.lParam=msg16->lParam;
2198 WINPROC_UnmapMsg32ATo16(((LPMSG)lParam)->hwnd, ((LPMSG)lParam)->message,
2199 ((LPMSG)lParam)->wParam, ((LPMSG)lParam)->lParam,
2200 &msgp16 );
2201 SEGPTR_FREE(msg16);
2203 break;
2208 /**********************************************************************
2209 * WINPROC_MapMsg32WTo16
2211 * Map a message from 32-bit Unicode to 16-bit.
2212 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
2214 INT WINPROC_MapMsg32WTo16( HWND hwnd, UINT msg32, WPARAM wParam32,
2215 UINT16 *pmsg16, WPARAM16 *pwparam16,
2216 LPARAM *plparam )
2218 *pmsg16 = LOWORD(msg32);
2219 *pwparam16 = LOWORD(wParam32);
2220 switch(msg32)
2222 case LB_ADDSTRING:
2223 case LB_FINDSTRING:
2224 case LB_FINDSTRINGEXACT:
2225 case LB_INSERTSTRING:
2226 case LB_SELECTSTRING:
2227 case LB_DIR:
2228 case LB_ADDFILE:
2230 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
2231 if (!str) return -1;
2232 *plparam = (LPARAM)SEGPTR_GET(str);
2234 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
2235 return 1;
2237 case CB_ADDSTRING:
2238 case CB_FINDSTRING:
2239 case CB_FINDSTRINGEXACT:
2240 case CB_INSERTSTRING:
2241 case CB_SELECTSTRING:
2242 case CB_DIR:
2244 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
2245 if (!str) return -1;
2246 *plparam = (LPARAM)SEGPTR_GET(str);
2248 *pmsg16 = (UINT16)msg32 + (CB_ADDSTRING16 - CB_ADDSTRING);
2249 return 1;
2251 case WM_NCCREATE:
2252 case WM_CREATE:
2254 CREATESTRUCT16 *cs;
2255 CREATESTRUCTW *cs32 = (CREATESTRUCTW *)*plparam;
2256 LPSTR name, cls;
2258 if (!(cs = SEGPTR_NEW(CREATESTRUCT16))) return -1;
2259 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs32, cs );
2260 name = SEGPTR_STRDUP_WtoA( cs32->lpszName );
2261 cls = SEGPTR_STRDUP_WtoA( cs32->lpszClass );
2262 cs->lpszName = SEGPTR_GET(name);
2263 cs->lpszClass = SEGPTR_GET(cls);
2264 *plparam = (LPARAM)SEGPTR_GET(cs);
2266 return 1;
2267 case WM_MDICREATE:
2269 MDICREATESTRUCT16 *cs;
2270 MDICREATESTRUCTW *cs32 = (MDICREATESTRUCTW *)*plparam;
2271 LPSTR name, cls;
2273 if (!(cs = SEGPTR_NEW(MDICREATESTRUCT16))) return -1;
2274 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs32, cs );
2275 name = SEGPTR_STRDUP_WtoA( cs32->szTitle );
2276 cls = SEGPTR_STRDUP_WtoA( cs32->szClass );
2277 cs->szTitle = SEGPTR_GET(name);
2278 cs->szClass = SEGPTR_GET(cls);
2279 *plparam = (LPARAM)SEGPTR_GET(cs);
2281 return 1;
2282 case WM_SETTEXT:
2284 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
2285 if (!str) return -1;
2286 *plparam = (LPARAM)SEGPTR_GET(str);
2288 return 1;
2289 case LB_GETTEXT:
2290 case CB_GETLBTEXT:
2291 if ( WINPROC_TestLBForStr( hwnd ))
2293 LPSTR str = (LPSTR) SEGPTR_ALLOC( 256 ); /* fixme: fixed sized buffer */
2294 if (!str) return -1;
2295 *pmsg16 = (msg32 == LB_GETTEXT)? LB_GETTEXT16 : CB_GETLBTEXT16;
2296 *plparam = (LPARAM)SEGPTR_GET(str);
2298 return 1;
2300 case WM_CHAR:
2301 case WM_DEADCHAR:
2302 case WM_SYSCHAR:
2303 case WM_SYSDEADCHAR:
2305 WCHAR wch = wParam32;
2306 char ch;
2307 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
2308 *pwparam16 = ch;
2310 return 0;
2312 default: /* No Unicode translation needed (?) */
2313 return WINPROC_MapMsg32ATo16( hwnd, msg32, wParam32, pmsg16,
2314 pwparam16, plparam );
2319 /**********************************************************************
2320 * WINPROC_UnmapMsg32WTo16
2322 * Unmap a message that was mapped from 32-bit Unicode to 16-bit.
2324 void WINPROC_UnmapMsg32WTo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2325 MSGPARAM16* p16 )
2327 switch(msg)
2329 case WM_GETTEXT:
2331 LPSTR str = MapSL(p16->lParam);
2332 p16->lParam = *((LPARAM *)str - 1);
2333 MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)p16->lParam, 0x7fffffff );
2334 SEGPTR_FREE( (LPARAM *)str - 1 );
2336 break;
2337 case LB_GETTEXT:
2338 case CB_GETLBTEXT:
2339 if ( WINPROC_TestLBForStr( hwnd ))
2341 LPSTR str = MapSL(p16->lParam);
2342 MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)lParam, 0x7fffffff );
2343 SEGPTR_FREE( (LPARAM *) str );
2345 break;
2346 default:
2347 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, p16 );
2348 break;
2353 /**********************************************************************
2354 * WINPROC_CallProc32ATo32W
2356 * Call a window procedure, translating args from Ansi to Unicode.
2358 static LRESULT WINPROC_CallProc32ATo32W( WNDPROC func, HWND hwnd,
2359 UINT msg, WPARAM wParam,
2360 LPARAM lParam )
2362 LRESULT result;
2363 int unmap;
2365 if( (unmap = WINPROC_MapMsg32ATo32W( hwnd, msg, &wParam, &lParam )) == -1) {
2366 ERR_(msg)("Message translation failed. (msg=%s,wp=%08x,lp=%08lx)\n",
2367 SPY_GetMsgName(msg), wParam, lParam );
2368 return 0;
2370 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2371 if( unmap ) WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam );
2372 return result;
2376 /**********************************************************************
2377 * WINPROC_CallProc32WTo32A
2379 * Call a window procedure, translating args from Unicode to Ansi.
2381 static LRESULT WINPROC_CallProc32WTo32A( WNDPROC func, HWND hwnd,
2382 UINT msg, WPARAM wParam,
2383 LPARAM lParam )
2385 LRESULT result;
2386 int unmap;
2388 if ((unmap = WINPROC_MapMsg32WTo32A( hwnd, msg, &wParam, &lParam )) == -1) {
2389 ERR_(msg)("Message translation failed. (msg=%s,wp=%08x,lp=%08lx)\n",
2390 SPY_GetMsgName(msg), wParam, lParam );
2391 return 0;
2393 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2394 if( unmap ) WINPROC_UnmapMsg32WTo32A( hwnd, msg, wParam, lParam );
2395 return result;
2399 /**********************************************************************
2400 * WINPROC_CallProc16To32A
2402 * Call a 32-bit window procedure, translating the 16-bit args.
2404 static LRESULT WINPROC_CallProc16To32A( WNDPROC func, HWND16 hwnd,
2405 UINT16 msg, WPARAM16 wParam,
2406 LPARAM lParam )
2408 LRESULT result;
2409 UINT msg32;
2410 WPARAM wParam32;
2412 if (WINPROC_MapMsg16To32A( msg, wParam, &msg32, &wParam32, &lParam ) == -1)
2413 return 0;
2414 result = WINPROC_CallWndProc( func, hwnd, msg32, wParam32, lParam );
2415 return WINPROC_UnmapMsg16To32A( hwnd, msg32, wParam32, lParam, result );
2418 /**********************************************************************
2419 * WINPROC_Thunk16To32A
2421 static LRESULT WINAPI WINPROC_Thunk16To32A( WNDPROC func, LPBYTE args )
2423 HWND16 hwnd = *(HWND16 *)( args+8 );
2424 UINT16 msg = *(HWND16 *)( args+6 );
2425 WPARAM16 wParam = *(HWND16 *)( args+4 );
2426 LPARAM lParam = *(LPARAM *)( args+0 );
2428 return WINPROC_CallProc16To32A( func, hwnd, msg, wParam, lParam );
2432 /**********************************************************************
2433 * WINPROC_CallProc16To32W
2435 * Call a 32-bit window procedure, translating the 16-bit args.
2437 static LRESULT WINPROC_CallProc16To32W( WNDPROC func, HWND16 hwnd,
2438 UINT16 msg, WPARAM16 wParam,
2439 LPARAM lParam )
2441 LRESULT result;
2442 UINT msg32;
2443 WPARAM wParam32;
2445 if (WINPROC_MapMsg16To32W( hwnd, msg, wParam, &msg32, &wParam32, &lParam ) == -1)
2446 return 0;
2448 result = WINPROC_CallWndProc( func, hwnd, msg32, wParam32, lParam );
2450 return WINPROC_UnmapMsg16To32W( hwnd, msg32, wParam32, lParam, result );
2453 /**********************************************************************
2454 * WINPROC_Thunk16To32W
2456 static LRESULT WINAPI WINPROC_Thunk16To32W( WNDPROC func, LPBYTE args )
2458 HWND16 hwnd = *(HWND16 *)( args+8 );
2459 UINT16 msg = *(HWND16 *)( args+6 );
2460 WPARAM16 wParam = *(HWND16 *)( args+4 );
2461 LPARAM lParam = *(LPARAM *)( args+0 );
2463 return WINPROC_CallProc16To32W( func, hwnd, msg, wParam, lParam );
2466 /**********************************************************************
2467 * WINPROC_CallProc32ATo16
2469 * Call a 16-bit window procedure, translating the 32-bit args.
2471 static LRESULT WINAPI WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd,
2472 UINT msg, WPARAM wParam,
2473 LPARAM lParam )
2475 UINT16 msg16;
2476 MSGPARAM16 mp16;
2478 mp16.lParam = lParam;
2479 if (WINPROC_MapMsg32ATo16( hwnd, msg, wParam,
2480 &msg16, &mp16.wParam, &mp16.lParam ) == -1)
2481 return 0;
2482 mp16.lResult = WINPROC_CallWndProc16( func, hwnd, msg16,
2483 mp16.wParam, mp16.lParam );
2484 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, &mp16 );
2485 return mp16.lResult;
2489 /**********************************************************************
2490 * WINPROC_CallProc32WTo16
2492 * Call a 16-bit window procedure, translating the 32-bit args.
2494 static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
2495 UINT msg, WPARAM wParam,
2496 LPARAM lParam )
2498 UINT16 msg16;
2499 MSGPARAM16 mp16;
2501 mp16.lParam = lParam;
2502 if (WINPROC_MapMsg32WTo16( hwnd, msg, wParam, &msg16, &mp16.wParam,
2503 &mp16.lParam ) == -1)
2504 return 0;
2505 mp16.lResult = WINPROC_CallWndProc16( func, hwnd, msg16,
2506 mp16.wParam, mp16.lParam );
2507 WINPROC_UnmapMsg32WTo16( hwnd, msg, wParam, lParam, &mp16 );
2508 return mp16.lResult;
2512 /**********************************************************************
2513 * CallWindowProc (USER.122)
2514 * CallWindowProc16 (USER32.@)
2516 LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
2517 WPARAM16 wParam, LPARAM lParam )
2519 WINDOWPROC *proc = WINPROC_GetPtr( func );
2521 if (!proc)
2522 return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
2524 #if testing
2525 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_16 );
2526 return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
2527 #endif
2529 switch(proc->type)
2531 case WIN_PROC_16:
2532 if (!proc->thunk.t_from32.proc) return 0;
2533 return WINPROC_CallWndProc16( proc->thunk.t_from32.proc,
2534 hwnd, msg, wParam, lParam );
2535 case WIN_PROC_32A:
2536 if (!proc->thunk.t_from16.proc) return 0;
2537 return WINPROC_CallProc16To32A( proc->thunk.t_from16.proc,
2538 hwnd, msg, wParam, lParam );
2539 case WIN_PROC_32W:
2540 if (!proc->thunk.t_from16.proc) return 0;
2541 return WINPROC_CallProc16To32W( proc->thunk.t_from16.proc,
2542 hwnd, msg, wParam, lParam );
2543 default:
2544 WARN_(relay)("Invalid proc %p\n", proc );
2545 return 0;
2550 /**********************************************************************
2551 * CallWindowProcA (USER32.@)
2553 * The CallWindowProc() function invokes the windows procedure _func_,
2554 * with _hwnd_ as the target window, the message specified by _msg_, and
2555 * the message parameters _wParam_ and _lParam_.
2557 * Some kinds of argument conversion may be done, I'm not sure what.
2559 * CallWindowProc() may be used for windows subclassing. Use
2560 * SetWindowLong() to set a new windows procedure for windows of the
2561 * subclass, and handle subclassed messages in the new windows
2562 * procedure. The new windows procedure may then use CallWindowProc()
2563 * with _func_ set to the parent class's windows procedure to dispatch
2564 * the message to the superclass.
2566 * RETURNS
2568 * The return value is message dependent.
2570 * CONFORMANCE
2572 * ECMA-234, Win32
2574 LRESULT WINAPI CallWindowProcA(
2575 WNDPROC func, /* [in] window procedure */
2576 HWND hwnd, /* [in] target window */
2577 UINT msg, /* [in] message */
2578 WPARAM wParam, /* [in] message dependent parameter */
2579 LPARAM lParam /* [in] message dependent parameter */
2581 WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
2583 if (!proc) return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2585 #if testing
2586 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_32A );
2587 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2588 #endif
2590 switch(proc->type)
2592 case WIN_PROC_16:
2593 if (!proc->thunk.t_from32.proc) return 0;
2594 return WINPROC_CallProc32ATo16( proc->thunk.t_from32.proc,
2595 hwnd, msg, wParam, lParam );
2596 case WIN_PROC_32A:
2597 if (!proc->thunk.t_from16.proc) return 0;
2598 return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
2599 hwnd, msg, wParam, lParam );
2600 case WIN_PROC_32W:
2601 if (!proc->thunk.t_from16.proc) return 0;
2602 return WINPROC_CallProc32ATo32W( proc->thunk.t_from16.proc,
2603 hwnd, msg, wParam, lParam );
2604 default:
2605 WARN_(relay)("Invalid proc %p\n", proc );
2606 return 0;
2611 /**********************************************************************
2612 * CallWindowProcW (USER32.@)
2614 LRESULT WINAPI CallWindowProcW( WNDPROC func, HWND hwnd, UINT msg,
2615 WPARAM wParam, LPARAM lParam )
2617 WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
2619 if (!proc) return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2621 #if testing
2622 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_32W );
2623 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2624 #endif
2626 switch(proc->type)
2628 case WIN_PROC_16:
2629 if (!proc->thunk.t_from32.proc) return 0;
2630 return WINPROC_CallProc32WTo16( proc->thunk.t_from32.proc,
2631 hwnd, msg, wParam, lParam );
2632 case WIN_PROC_32A:
2633 if (!proc->thunk.t_from16.proc) return 0;
2634 return WINPROC_CallProc32WTo32A( proc->thunk.t_from16.proc,
2635 hwnd, msg, wParam, lParam );
2636 case WIN_PROC_32W:
2637 if (!proc->thunk.t_from16.proc) return 0;
2638 return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
2639 hwnd, msg, wParam, lParam );
2640 default:
2641 WARN_(relay)("Invalid proc %p\n", proc );
2642 return 0;