blob: a6e1e7904f139ed775b49108ecd1d134ea3c191f [file] [log] [blame]
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001/*
2 * Window procedure callbacks
3 *
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1996 Alexandre Julliard
6 */
7
Marcus Meissner61afa331999-02-22 10:16:00 +00008#include "wine/winbase16.h"
9#include "winuser.h"
Alexandre Julliard491502b1997-11-01 19:08:16 +000010#include "callback.h"
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +000011#include "heap.h"
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000012#include "selectors.h"
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +000013#include "struct32.h"
14#include "win.h"
Alexandre Julliard2d93d001996-05-21 15:01:41 +000015#include "winproc.h"
Alexandre Julliard06c275a1999-05-02 14:32:27 +000016#include "debugtools.h"
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000017#include "spy.h"
Juergen Schmied4a84dc21998-10-23 12:04:25 +000018#include "commctrl.h"
Alexandre Julliard638f1691999-01-17 16:32:32 +000019#include "task.h"
20#include "thread.h"
Alexandre Julliard2d93d001996-05-21 15:01:41 +000021
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000022DECLARE_DEBUG_CHANNEL(msg)
23DECLARE_DEBUG_CHANNEL(relay)
24DECLARE_DEBUG_CHANNEL(win)
25
Alexandre Julliard889f7421997-04-15 17:19:52 +000026/* Window procedure 16-to-32-bit thunk,
Alexandre Julliarddf2673b1997-03-29 17:20:20 +000027 * see BuildSpec16Files() in tools/build.c */
28
Alexandre Julliard2d93d001996-05-21 15:01:41 +000029typedef struct
30{
Alexandre Julliard3051b641996-07-05 17:14:13 +000031 BYTE popl_eax; /* popl %eax (return address) */
32 BYTE pushl_func; /* pushl $proc */
Alexandre Julliarda3960291999-02-26 11:11:13 +000033 WNDPROC proc WINE_PACKED;
Alexandre Julliard3051b641996-07-05 17:14:13 +000034 BYTE pushl_eax; /* pushl %eax */
35 WORD pushw_bp WINE_PACKED; /* pushw %bp */
36 BYTE pushl_thunk; /* pushl $thunkfrom16 */
37 void (*thunk32)() WINE_PACKED;
38 BYTE lcall; /* lcall cs:relay */
Alexandre Julliarddf2673b1997-03-29 17:20:20 +000039 void (*relay)() WINE_PACKED; /* WINPROC_CallProc16To32A/W() */
Alexandre Julliard3051b641996-07-05 17:14:13 +000040 WORD cs WINE_PACKED;
41} WINPROC_THUNK_FROM16;
42
Alexandre Julliarddf2673b1997-03-29 17:20:20 +000043/* Window procedure 32-to-16-bit thunk,
44 * see BuildSpec32Files() in tools/build.c */
45
Alexandre Julliard3051b641996-07-05 17:14:13 +000046typedef struct
47{
48 BYTE popl_eax; /* popl %eax (return address) */
Alexandre Julliardca22b331996-07-12 19:02:39 +000049 BYTE pushl_func; /* pushl $proc */
Alexandre Julliard3051b641996-07-05 17:14:13 +000050 WNDPROC16 proc WINE_PACKED;
51 BYTE pushl_eax; /* pushl %eax */
Alexandre Julliardca22b331996-07-12 19:02:39 +000052 BYTE jmp; /* jmp relay (relative jump)*/
Alexandre Julliarddf2673b1997-03-29 17:20:20 +000053 void (*relay)() WINE_PACKED; /* WINPROC_CallProc32ATo16() */
Alexandre Julliard3051b641996-07-05 17:14:13 +000054} WINPROC_THUNK_FROM32;
55
Alexandre Julliardca22b331996-07-12 19:02:39 +000056/* Simple jmp to call 32-bit procedure directly */
57typedef struct
58{
59 BYTE jmp; /* jmp proc (relative jump) */
Alexandre Julliarda3960291999-02-26 11:11:13 +000060 WNDPROC proc WINE_PACKED;
Alexandre Julliardca22b331996-07-12 19:02:39 +000061} WINPROC_JUMP;
62
Alexandre Julliard3051b641996-07-05 17:14:13 +000063typedef union
64{
65 WINPROC_THUNK_FROM16 t_from16;
66 WINPROC_THUNK_FROM32 t_from32;
67} WINPROC_THUNK;
68
69typedef struct tagWINDOWPROC
70{
71 WINPROC_THUNK thunk; /* Thunk */
Alexandre Julliardca22b331996-07-12 19:02:39 +000072 WINPROC_JUMP jmp; /* Jump */
Alexandre Julliard3051b641996-07-05 17:14:13 +000073 struct tagWINDOWPROC *next; /* Next window proc */
Alexandre Julliarda3960291999-02-26 11:11:13 +000074 UINT magic; /* Magic number */
Alexandre Julliard3051b641996-07-05 17:14:13 +000075 WINDOWPROCTYPE type; /* Function type */
Alexandre Julliarddf2673b1997-03-29 17:20:20 +000076 WINDOWPROCUSER user; /* Function user */
Alexandre Julliard2d93d001996-05-21 15:01:41 +000077} WINDOWPROC;
78
Alexandre Julliard1e9ac791996-06-06 18:38:27 +000079#define WINPROC_MAGIC ('W' | ('P' << 8) | ('R' << 16) | ('C' << 24))
Alexandre Julliard2d93d001996-05-21 15:01:41 +000080
Alexandre Julliard3051b641996-07-05 17:14:13 +000081#define WINPROC_THUNKPROC(pproc) \
82 (((pproc)->type == WIN_PROC_16) ? \
83 (WNDPROC16)((pproc)->thunk.t_from32.proc) : \
84 (WNDPROC16)((pproc)->thunk.t_from16.proc))
Alexandre Julliard2d93d001996-05-21 15:01:41 +000085
Alexandre Julliarda3960291999-02-26 11:11:13 +000086static LRESULT WINAPI WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd,
87 UINT msg, WPARAM wParam,
Alexandre Julliard77b99181997-09-14 17:17:23 +000088 LPARAM lParam );
Alexandre Julliarda3960291999-02-26 11:11:13 +000089static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
90 UINT msg, WPARAM wParam,
Alexandre Julliard77b99181997-09-14 17:17:23 +000091 LPARAM lParam );
Alexandre Julliard44ed71f1997-12-21 19:17:50 +000092static LRESULT WINPROC_CallProc16To32A( HWND16 hwnd, UINT16 msg,
93 WPARAM16 wParam, LPARAM lParam,
Alexandre Julliarda3960291999-02-26 11:11:13 +000094 WNDPROC func );
Alexandre Julliard44ed71f1997-12-21 19:17:50 +000095static LRESULT WINPROC_CallProc16To32W( HWND16 hwnd, UINT16 msg,
96 WPARAM16 wParam, LPARAM lParam,
Alexandre Julliarda3960291999-02-26 11:11:13 +000097 WNDPROC func );
Alexandre Julliard3051b641996-07-05 17:14:13 +000098
Alexandre Julliarda3960291999-02-26 11:11:13 +000099static HANDLE WinProcHeap;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000100
Alexandre Julliard84c70f51997-05-09 08:40:27 +0000101
Alexandre Julliard3051b641996-07-05 17:14:13 +0000102/**********************************************************************
103 * WINPROC_Init
104 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000105BOOL WINPROC_Init(void)
Alexandre Julliard3051b641996-07-05 17:14:13 +0000106{
107 WinProcHeap = HeapCreate( HEAP_WINE_SEGPTR | HEAP_WINE_CODESEG, 0, 0 );
108 if (!WinProcHeap)
109 {
Alexandre Julliard06c275a1999-05-02 14:32:27 +0000110 WARN_(relay)("Unable to create winproc heap\n" );
Alexandre Julliard3051b641996-07-05 17:14:13 +0000111 return FALSE;
112 }
113 return TRUE;
114}
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000115
116
117/**********************************************************************
Alexandre Julliard84c70f51997-05-09 08:40:27 +0000118 * WINPROC_CallWndProc32
119 *
120 * Call a 32-bit WndProc.
121 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000122static LRESULT WINPROC_CallWndProc( WNDPROC proc, HWND hwnd, UINT msg,
123 WPARAM wParam, LPARAM lParam )
Alexandre Julliard84c70f51997-05-09 08:40:27 +0000124{
Francois Boisvertd96bc151999-04-02 10:34:43 +0000125 LRESULT retvalue;
126 int iWndsLocks;
127
Alexandre Julliard06c275a1999-05-02 14:32:27 +0000128 TRACE_(relay)("(wndproc=%p,hwnd=%08x,msg=%s,wp=%08x,lp=%08lx)\n",
Alexandre Julliardd30dfd21998-09-27 18:28:36 +0000129 proc, hwnd, SPY_GetMsgName(msg), wParam, lParam );
Francois Boisvertd96bc151999-04-02 10:34:43 +0000130 /* To avoid any deadlocks, all the locks on the windows structures
131 must be suspended before the control is passed to the application */
132 iWndsLocks = WIN_SuspendWndsLock();
133 retvalue = proc( hwnd, msg, wParam, lParam );
134 WIN_RestoreWndsLock(iWndsLocks);
135 return retvalue;
Alexandre Julliard84c70f51997-05-09 08:40:27 +0000136}
137
138
139/**********************************************************************
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000140 * WINPROC_GetPtr
141 *
142 * Return a pointer to the win proc.
143 */
Alexandre Julliard3051b641996-07-05 17:14:13 +0000144static WINDOWPROC *WINPROC_GetPtr( WNDPROC16 handle )
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000145{
Alexandre Julliardca22b331996-07-12 19:02:39 +0000146 BYTE *ptr;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000147 WINDOWPROC *proc;
148
149 /* Check for a linear pointer */
150
151 if (HEAP_IsInsideHeap( WinProcHeap, 0, (LPVOID)handle ))
152 {
Alexandre Julliardca22b331996-07-12 19:02:39 +0000153 ptr = (BYTE *)handle;
154 /* First check if it is the jmp address */
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000155 if (*ptr == 0xe9 /* jmp */) ptr -= (int)&((WINDOWPROC *)0)->jmp -
156 (int)&((WINDOWPROC *)0)->thunk;
Alexandre Julliardca22b331996-07-12 19:02:39 +0000157 /* Now it must be the thunk address */
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000158 if (*ptr == 0x58 /* popl eax */) ptr -= (int)&((WINDOWPROC *)0)->thunk;
Alexandre Julliardca22b331996-07-12 19:02:39 +0000159 /* Now we have a pointer to the WINDOWPROC struct */
160 if (((WINDOWPROC *)ptr)->magic == WINPROC_MAGIC)
161 return (WINDOWPROC *)ptr;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000162 }
163
164 /* Check for a segmented pointer */
165
Alexandre Julliard8bbf8181996-09-13 16:50:47 +0000166 if (!IsBadReadPtr16((SEGPTR)handle,sizeof(WINDOWPROC)-sizeof(proc->thunk)))
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000167 {
Alexandre Julliardca22b331996-07-12 19:02:39 +0000168 ptr = (BYTE *)PTR_SEG_TO_LIN(handle);
Alexandre Julliard8cc3a5e1996-08-11 15:49:51 +0000169 if (!HEAP_IsInsideHeap( WinProcHeap, 0, ptr )) return NULL;
Alexandre Julliardca22b331996-07-12 19:02:39 +0000170 /* It must be the thunk address */
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000171 if (*ptr == 0x58 /* popl eax */) ptr -= (int)&((WINDOWPROC *)0)->thunk;
Alexandre Julliardca22b331996-07-12 19:02:39 +0000172 /* Now we have a pointer to the WINDOWPROC struct */
173 if (((WINDOWPROC *)ptr)->magic == WINPROC_MAGIC)
174 return (WINDOWPROC *)ptr;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000175 }
176
177 return NULL;
178}
179
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000180
181/**********************************************************************
182 * WINPROC_AllocWinProc
183 *
184 * Allocate a new window procedure.
185 */
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000186static WINDOWPROC *WINPROC_AllocWinProc( WNDPROC16 func, WINDOWPROCTYPE type,
187 WINDOWPROCUSER user )
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000188{
Alexandre Julliard3051b641996-07-05 17:14:13 +0000189 WINDOWPROC *proc, *oldproc;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000190
Alexandre Julliard3051b641996-07-05 17:14:13 +0000191 /* Allocate a window procedure */
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000192
193 if (!(proc = HeapAlloc( WinProcHeap, 0, sizeof(WINDOWPROC) ))) return 0;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000194
195 /* Check if the function is already a win proc */
196
197 if ((oldproc = WINPROC_GetPtr( func )))
198 {
199 *proc = *oldproc;
200 }
201 else
202 {
203 switch(type)
204 {
205 case WIN_PROC_16:
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000206 proc->thunk.t_from32.popl_eax = 0x58; /* popl %eax */
207 proc->thunk.t_from32.pushl_func = 0x68; /* pushl $proc */
208 proc->thunk.t_from32.proc = func;
209 proc->thunk.t_from32.pushl_eax = 0x50; /* pushl %eax */
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000210 proc->thunk.t_from32.jmp = 0xe9; /* jmp relay*/
211 proc->thunk.t_from32.relay = /* relative jump */
Alexandre Julliard77b99181997-09-14 17:17:23 +0000212 (void(*)())((DWORD)WINPROC_CallProc32ATo16 -
Alexandre Julliard3051b641996-07-05 17:14:13 +0000213 (DWORD)(&proc->thunk.t_from32.relay + 1));
214 break;
215 case WIN_PROC_32A:
Alexandre Julliard3051b641996-07-05 17:14:13 +0000216 case WIN_PROC_32W:
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000217 proc->thunk.t_from16.popl_eax = 0x58; /* popl %eax */
218 proc->thunk.t_from16.pushl_func = 0x68; /* pushl $proc */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000219 proc->thunk.t_from16.proc = (FARPROC)func;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000220 proc->thunk.t_from16.pushl_eax = 0x50; /* pushl %eax */
221 proc->thunk.t_from16.pushw_bp = 0x5566; /* pushw %bp */
222 proc->thunk.t_from16.pushl_thunk = 0x68; /* pushl $thunkfrom16 */
223 proc->thunk.t_from16.thunk32 = (type == WIN_PROC_32A) ?
224 (void(*)())WINPROC_CallProc16To32A :
225 (void(*)())WINPROC_CallProc16To32W;
226 proc->thunk.t_from16.lcall = 0x9a; /* lcall cs:relay */
Marcus Meissner03479f81999-01-28 10:06:38 +0000227 proc->thunk.t_from16.relay = (void*)Callbacks->CallFrom16WndProc;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000228 GET_CS(proc->thunk.t_from16.cs);
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000229 proc->jmp.jmp = 0xe9;
Alexandre Julliardca22b331996-07-12 19:02:39 +0000230 /* Fixup relative jump */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000231 proc->jmp.proc = (WNDPROC)((DWORD)func -
Alexandre Julliardca22b331996-07-12 19:02:39 +0000232 (DWORD)(&proc->jmp.proc + 1));
Alexandre Julliard3051b641996-07-05 17:14:13 +0000233 break;
234 default:
235 /* Should not happen */
236 break;
237 }
238 proc->magic = WINPROC_MAGIC;
239 proc->type = type;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000240 proc->user = user;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000241 }
242 proc->next = NULL;
Alexandre Julliard06c275a1999-05-02 14:32:27 +0000243 TRACE_(win)("(%08x,%d): returning %08x\n",
Alexandre Julliarda3960291999-02-26 11:11:13 +0000244 (UINT)func, type, (UINT)proc );
Alexandre Julliard3051b641996-07-05 17:14:13 +0000245 return proc;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000246}
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000247
248
249/**********************************************************************
Alexandre Julliard3051b641996-07-05 17:14:13 +0000250 * WINPROC_GetProc
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000251 *
Alexandre Julliard3051b641996-07-05 17:14:13 +0000252 * Get a window procedure pointer that can be passed to the Windows program.
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000253 */
Alexandre Julliard3051b641996-07-05 17:14:13 +0000254WNDPROC16 WINPROC_GetProc( HWINDOWPROC proc, WINDOWPROCTYPE type )
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000255{
Alexandre Julliard21979011997-03-05 08:22:35 +0000256 if (!proc) return NULL;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000257 if (type == WIN_PROC_16) /* We want a 16:16 address */
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000258 {
Alexandre Julliard3051b641996-07-05 17:14:13 +0000259 if (((WINDOWPROC *)proc)->type == WIN_PROC_16)
260 return ((WINDOWPROC *)proc)->thunk.t_from32.proc;
261 else
Alexandre Julliardca22b331996-07-12 19:02:39 +0000262 return (WNDPROC16)HEAP_GetSegptr( WinProcHeap, 0,
263 &((WINDOWPROC *)proc)->thunk );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000264 }
Alexandre Julliard3051b641996-07-05 17:14:13 +0000265 else /* We want a 32-bit address */
266 {
267 if (((WINDOWPROC *)proc)->type == WIN_PROC_16)
Alexandre Julliardca22b331996-07-12 19:02:39 +0000268 return (WNDPROC16)&((WINDOWPROC *)proc)->thunk;
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000269 else if (type != ((WINDOWPROC *)proc)->type)
270 /* Have to return the jmp address if types don't match */
271 return (WNDPROC16)&((WINDOWPROC *)proc)->jmp;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000272 else
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000273 /* Some Win16 programs want to get back the proc they set */
274 return (WNDPROC16)((WINDOWPROC *)proc)->thunk.t_from16.proc;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000275 }
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000276}
277
278
279/**********************************************************************
Alexandre Julliard3051b641996-07-05 17:14:13 +0000280 * WINPROC_SetProc
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000281 *
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000282 * Set the window procedure for a window or class. There are
283 * three tree classes of winproc callbacks:
284 *
285 * 1) class -> wp - not subclassed
286 * class -> wp -> wp -> wp -> wp - SetClassLong()
287 * / /
288 * 2) window -' / - not subclassed
289 * window -> wp -> wp ' - SetWindowLong()
290 *
291 * 3) timer -> wp - SetTimer()
292 *
293 * Initially, winproc of the window points to the current winproc
294 * thunk of its class. Subclassing prepends a new thunk to the
295 * window winproc chain at the head of the list. Thus, window thunk
296 * list includes class thunks and the latter are preserved when the
297 * window is destroyed.
298 *
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000299 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000300BOOL WINPROC_SetProc( HWINDOWPROC *pFirst, WNDPROC16 func,
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000301 WINDOWPROCTYPE type, WINDOWPROCUSER user )
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000302{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000303 BOOL bRecycle = FALSE;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000304 WINDOWPROC *proc, **ppPrev;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000305
Alexandre Julliard3051b641996-07-05 17:14:13 +0000306 /* Check if function is already in the list */
307
308 ppPrev = (WINDOWPROC **)pFirst;
309 proc = WINPROC_GetPtr( func );
310 while (*ppPrev)
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000311 {
Alexandre Julliard3051b641996-07-05 17:14:13 +0000312 if (proc)
313 {
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000314 if (*ppPrev == proc)
315 {
316 if ((*ppPrev)->user != user)
317 {
318 /* terminal thunk is being restored */
319
320 WINPROC_FreeProc( *pFirst, (*ppPrev)->user );
321 *(WINDOWPROC **)pFirst = *ppPrev;
322 return TRUE;
323 }
324 bRecycle = TRUE;
325 break;
326 }
Alexandre Julliard3051b641996-07-05 17:14:13 +0000327 }
328 else
329 {
330 if (((*ppPrev)->type == type) &&
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000331 (func == WINPROC_THUNKPROC(*ppPrev)))
332 {
333 bRecycle = TRUE;
334 break;
335 }
Alexandre Julliard3051b641996-07-05 17:14:13 +0000336 }
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000337
338 /* WPF_CLASS thunk terminates window thunk list */
339 if ((*ppPrev)->user != user) break;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000340 ppPrev = &(*ppPrev)->next;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000341 }
Alexandre Julliard3051b641996-07-05 17:14:13 +0000342
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000343 if (bRecycle)
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000344 {
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000345 /* Extract this thunk from the list */
Alexandre Julliard3051b641996-07-05 17:14:13 +0000346 proc = *ppPrev;
347 *ppPrev = proc->next;
348 }
349 else /* Allocate a new one */
350 {
351 if (proc) /* Was already a win proc */
352 {
353 type = proc->type;
354 func = WINPROC_THUNKPROC(proc);
355 }
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000356 proc = WINPROC_AllocWinProc( func, type, user );
Alexandre Julliard3051b641996-07-05 17:14:13 +0000357 if (!proc) return FALSE;
358 }
359
360 /* Add the win proc at the head of the list */
361
Alexandre Julliard06c275a1999-05-02 14:32:27 +0000362 TRACE_(win)("(%08x,%08x,%d): res=%08x\n",
Alexandre Julliarda3960291999-02-26 11:11:13 +0000363 (UINT)*pFirst, (UINT)func, type, (UINT)proc );
Alexandre Julliard3051b641996-07-05 17:14:13 +0000364 proc->next = *(WINDOWPROC **)pFirst;
365 *(WINDOWPROC **)pFirst = proc;
366 return TRUE;
367}
368
369
370/**********************************************************************
371 * WINPROC_FreeProc
372 *
373 * Free a list of win procs.
374 */
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000375void WINPROC_FreeProc( HWINDOWPROC proc, WINDOWPROCUSER user )
Alexandre Julliard3051b641996-07-05 17:14:13 +0000376{
377 while (proc)
378 {
379 WINDOWPROC *next = ((WINDOWPROC *)proc)->next;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000380 if (((WINDOWPROC *)proc)->user != user) break;
Alexandre Julliard06c275a1999-05-02 14:32:27 +0000381 TRACE_(win)("freeing %08x\n", (UINT)proc);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000382 HeapFree( WinProcHeap, 0, proc );
Alexandre Julliard3051b641996-07-05 17:14:13 +0000383 proc = next;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000384 }
385}
386
387
388/**********************************************************************
Alexandre Julliard3051b641996-07-05 17:14:13 +0000389 * WINPROC_GetProcType
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000390 *
391 * Return the window procedure type.
392 */
Alexandre Julliard3051b641996-07-05 17:14:13 +0000393WINDOWPROCTYPE WINPROC_GetProcType( HWINDOWPROC proc )
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000394{
Alexandre Julliard3051b641996-07-05 17:14:13 +0000395 if (!proc ||
396 (((WINDOWPROC *)proc)->magic != WINPROC_MAGIC))
397 return WIN_PROC_INVALID;
398 return ((WINDOWPROC *)proc)->type;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000399}
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000400/**********************************************************************
401 * WINPROC_TestCBForStr
402 *
403 * Return TRUE if the lparam is a string
404 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000405BOOL WINPROC_TestCBForStr ( HWND hwnd )
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000406{
407 BOOL retvalue;
408 WND * wnd = WIN_FindWndPtr(hwnd);
409 retvalue = ( !(LOWORD(wnd->dwStyle) & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) ||
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000410 (LOWORD(wnd->dwStyle) & CBS_HASSTRINGS) );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000411 WIN_ReleaseWndPtr(wnd);
412 return retvalue;
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000413}
414/**********************************************************************
415 * WINPROC_TestLBForStr
416 *
417 * Return TRUE if the lparam is a string
418 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000419BOOL WINPROC_TestLBForStr ( HWND hwnd )
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000420{
421 BOOL retvalue;
422 WND * wnd = WIN_FindWndPtr(hwnd);
423 retvalue = ( !(LOWORD(wnd->dwStyle) & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) ||
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000424 (LOWORD(wnd->dwStyle) & LBS_HASSTRINGS) );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000425 WIN_ReleaseWndPtr(wnd);
426 return retvalue;
427
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000428}
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000429/**********************************************************************
Alexandre Julliard3051b641996-07-05 17:14:13 +0000430 * WINPROC_MapMsg32ATo32W
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000431 *
Alexandre Julliard3051b641996-07-05 17:14:13 +0000432 * Map a message from Ansi to Unicode.
433 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
Juergen Schmied36636ed1998-11-15 16:53:34 +0000434 *
435 * FIXME:
436 * WM_CHAR, WM_CHARTOITEM, WM_DEADCHAR, WM_MENUCHAR, WM_SYSCHAR, WM_SYSDEADCHAR
437 *
438 * FIXME:
439 * WM_GETTEXT/WM_SETTEXT and static control with SS_ICON style:
440 * the first four bytes are the handle of the icon
441 * when the WM_SETTEXT message has been used to set the icon
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000442 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000443INT WINPROC_MapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM wParam, LPARAM *plparam )
Juergen Schmied36636ed1998-11-15 16:53:34 +0000444{
445 switch(msg)
Alexandre Julliard3051b641996-07-05 17:14:13 +0000446 {
447 case WM_GETTEXT:
448 {
449 LPARAM *ptr = (LPARAM *)HeapAlloc( SystemHeap, 0,
450 wParam * sizeof(WCHAR) + sizeof(LPARAM) );
451 if (!ptr) return -1;
452 *ptr++ = *plparam; /* Store previous lParam */
453 *plparam = (LPARAM)ptr;
454 }
455 return 1;
Juergen Schmiedd3258fc1999-03-12 17:13:54 +0000456 /* lparam is string (0-terminated) */
Alexandre Julliard3051b641996-07-05 17:14:13 +0000457 case WM_SETTEXT:
Juergen Schmiedd3258fc1999-03-12 17:13:54 +0000458 case WM_WININICHANGE:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000459 case CB_DIR:
460 case CB_FINDSTRING:
461 case CB_FINDSTRINGEXACT:
462 case CB_SELECTSTRING:
463 case LB_DIR:
464 case LB_ADDFILE:
465 case LB_FINDSTRING:
466 case LB_SELECTSTRING:
467 case EM_REPLACESEL:
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000468 *plparam = (LPARAM)HEAP_strdupAtoW( SystemHeap, 0, (LPCSTR)*plparam );
Alexandre Julliard3051b641996-07-05 17:14:13 +0000469 return (*plparam ? 1 : -1);
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000470
Alexandre Julliard3051b641996-07-05 17:14:13 +0000471 case WM_NCCREATE:
472 case WM_CREATE:
473 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000474 CREATESTRUCTW *cs = (CREATESTRUCTW *)HeapAlloc( SystemHeap, 0,
Alexandre Julliard3051b641996-07-05 17:14:13 +0000475 sizeof(*cs) );
476 if (!cs) return -1;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000477 *cs = *(CREATESTRUCTW *)*plparam;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000478 if (HIWORD(cs->lpszName))
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000479 cs->lpszName = HEAP_strdupAtoW( SystemHeap, 0,
480 (LPCSTR)cs->lpszName );
Alexandre Julliard3051b641996-07-05 17:14:13 +0000481 if (HIWORD(cs->lpszClass))
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000482 cs->lpszClass = HEAP_strdupAtoW( SystemHeap, 0,
483 (LPCSTR)cs->lpszClass );
Alexandre Julliard3051b641996-07-05 17:14:13 +0000484 *plparam = (LPARAM)cs;
485 }
486 return 1;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000487 case WM_MDICREATE:
488 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000489 MDICREATESTRUCTW *cs =
490 (MDICREATESTRUCTW *)HeapAlloc( SystemHeap, 0, sizeof(*cs) );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000491 if (!cs) return -1;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000492 *cs = *(MDICREATESTRUCTW *)*plparam;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000493 if (HIWORD(cs->szClass))
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000494 cs->szClass = HEAP_strdupAtoW( SystemHeap, 0,
495 (LPCSTR)cs->szClass );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000496 if (HIWORD(cs->szTitle))
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000497 cs->szTitle = HEAP_strdupAtoW( SystemHeap, 0,
498 (LPCSTR)cs->szTitle );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000499 *plparam = (LPARAM)cs;
500 }
501 return 1;
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000502
503/* Listbox */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000504 case LB_ADDSTRING:
505 case LB_INSERTSTRING:
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000506 if ( WINPROC_TestLBForStr( hwnd ))
507 *plparam = (LPARAM)HEAP_strdupAtoW( SystemHeap, 0, (LPCSTR)*plparam );
508 return (*plparam ? 1 : -1);
509
Alexandre Julliarda3960291999-02-26 11:11:13 +0000510 case LB_GETTEXT: /* fixme: fixed sized buffer */
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000511 { if ( WINPROC_TestLBForStr( hwnd ))
512 { LPARAM *ptr = (LPARAM *)HeapAlloc( SystemHeap, 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
513 if (!ptr) return -1;
514 *ptr++ = *plparam; /* Store previous lParam */
515 *plparam = (LPARAM)ptr;
516 }
517 }
518 return 1;
519
520/* Combobox */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000521 case CB_ADDSTRING:
522 case CB_INSERTSTRING:
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000523 if ( WINPROC_TestCBForStr( hwnd ))
524 *plparam = (LPARAM)HEAP_strdupAtoW( SystemHeap, 0, (LPCSTR)*plparam );
525 return (*plparam ? 1 : -1);
526
Alexandre Julliarda3960291999-02-26 11:11:13 +0000527 case CB_GETLBTEXT: /* fixme: fixed sized buffer */
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000528 { if ( WINPROC_TestCBForStr( hwnd ))
529 { LPARAM *ptr = (LPARAM *)HeapAlloc( SystemHeap, 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
530 if (!ptr) return -1;
531 *ptr++ = *plparam; /* Store previous lParam */
532 *plparam = (LPARAM)ptr;
533 }
534 }
535 return 1;
536
537/* Multiline edit */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000538 case EM_GETLINE:
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000539 { WORD len = (WORD)*plparam;
540 LPARAM *ptr = (LPARAM *) HEAP_xalloc( SystemHeap, 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(WCHAR) );
541 if (!ptr) return -1;
542 *ptr++ = *plparam; /* Store previous lParam */
Patrik Stridvalla9a671d1999-04-25 19:01:52 +0000543 *((WORD *) ptr) = len; /* Store the length */
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000544 *plparam = (LPARAM)ptr;
545 }
546 return 1;
547
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000548 case WM_ASKCBFORMATNAME:
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000549 case WM_DEVMODECHANGE:
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000550 case WM_PAINTCLIPBOARD:
551 case WM_SIZECLIPBOARD:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000552 case EM_SETPASSWORDCHAR:
Alexandre Julliard06c275a1999-05-02 14:32:27 +0000553 FIXME_(msg)("message %s (0x%x) needs translation, please report\n", SPY_GetMsgName(msg), msg );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000554 return -1;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000555 default: /* No translation needed */
556 return 0;
557 }
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000558}
559
560
561/**********************************************************************
Alexandre Julliard3051b641996-07-05 17:14:13 +0000562 * WINPROC_UnmapMsg32ATo32W
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000563 *
Alexandre Julliard3051b641996-07-05 17:14:13 +0000564 * Unmap a message that was mapped from Ansi to Unicode.
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000565 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000566void WINPROC_UnmapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
Juergen Schmied36636ed1998-11-15 16:53:34 +0000567{
568 switch(msg)
Alexandre Julliard3051b641996-07-05 17:14:13 +0000569 {
570 case WM_GETTEXT:
571 {
572 LPARAM *ptr = (LPARAM *)lParam - 1;
Juergen Schmied36636ed1998-11-15 16:53:34 +0000573 lstrcpynWtoA( (LPSTR)*ptr, (LPWSTR)lParam, wParam );
Juergen Schmied4a84dc21998-10-23 12:04:25 +0000574 HeapFree( SystemHeap, 0, ptr );
575 }
576 break;
577
Alexandre Julliard3051b641996-07-05 17:14:13 +0000578 case WM_NCCREATE:
579 case WM_CREATE:
580 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000581 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000582 if (HIWORD(cs->lpszName))
583 HeapFree( SystemHeap, 0, (LPVOID)cs->lpszName );
584 if (HIWORD(cs->lpszClass))
585 HeapFree( SystemHeap, 0, (LPVOID)cs->lpszClass );
Alexandre Julliard3051b641996-07-05 17:14:13 +0000586 HeapFree( SystemHeap, 0, cs );
587 }
588 break;
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000589
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000590 case WM_MDICREATE:
591 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000592 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000593 if (HIWORD(cs->szTitle))
594 HeapFree( SystemHeap, 0, (LPVOID)cs->szTitle );
595 if (HIWORD(cs->szClass))
596 HeapFree( SystemHeap, 0, (LPVOID)cs->szClass );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000597 HeapFree( SystemHeap, 0, cs );
598 }
599 break;
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000600
601 case WM_SETTEXT:
Juergen Schmiedd3258fc1999-03-12 17:13:54 +0000602 case WM_WININICHANGE:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000603 case CB_DIR:
604 case CB_FINDSTRING:
605 case CB_FINDSTRINGEXACT:
606 case CB_SELECTSTRING:
607 case LB_DIR:
608 case LB_ADDFILE:
609 case LB_FINDSTRING:
610 case LB_SELECTSTRING:
611 case EM_REPLACESEL:
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000612 HeapFree( SystemHeap, 0, (void *)lParam );
613 break;
614
615/* Listbox */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000616 case LB_ADDSTRING:
617 case LB_INSERTSTRING:
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000618 if ( WINPROC_TestLBForStr( hwnd ))
619 HeapFree( SystemHeap, 0, (void *)lParam );
620 break;
621
Alexandre Julliarda3960291999-02-26 11:11:13 +0000622 case LB_GETTEXT:
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000623 { if ( WINPROC_TestLBForStr( hwnd ))
624 { LPARAM *ptr = (LPARAM *)lParam - 1;
625 lstrcpyWtoA( (LPSTR)*ptr, (LPWSTR)(lParam) );
626 HeapFree( SystemHeap, 0, ptr );
627 }
628 }
629 break;
630
631/* Combobox */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000632 case CB_ADDSTRING:
633 case CB_INSERTSTRING:
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000634 if ( WINPROC_TestCBForStr( hwnd ))
635 HeapFree( SystemHeap, 0, (void *)lParam );
636 break;
637
Alexandre Julliarda3960291999-02-26 11:11:13 +0000638 case CB_GETLBTEXT:
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000639 { if ( WINPROC_TestCBForStr( hwnd ))
640 { LPARAM *ptr = (LPARAM *)lParam - 1;
641 lstrcpyWtoA( (LPSTR)*ptr, (LPWSTR)(lParam) );
642 HeapFree( SystemHeap, 0, ptr );
643 }
644 }
645 break;
646
647/* Multiline edit */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000648 case EM_GETLINE:
Juergen Schmiedafd55801999-01-31 09:18:58 +0000649 { LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lParam */
650 WORD len = *(WORD *) lParam;
651 lstrcpynWtoA( (LPSTR)*ptr , (LPWSTR)lParam, len );
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000652 HeapFree( SystemHeap, 0, ptr );
653 }
654 break;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000655 }
656}
657
658
659/**********************************************************************
660 * WINPROC_MapMsg32WTo32A
661 *
662 * Map a message from Unicode to Ansi.
663 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
664 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000665INT WINPROC_MapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM wParam, LPARAM *plparam )
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000666{ switch(msg)
Alexandre Julliard3051b641996-07-05 17:14:13 +0000667 {
668 case WM_GETTEXT:
669 {
670 LPARAM *ptr = (LPARAM *)HeapAlloc( SystemHeap, 0,
671 wParam + sizeof(LPARAM) );
672 if (!ptr) return -1;
673 *ptr++ = *plparam; /* Store previous lParam */
674 *plparam = (LPARAM)ptr;
675 }
676 return 1;
Juergen Schmied4a84dc21998-10-23 12:04:25 +0000677
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000678 case WM_SETTEXT:
Juergen Schmiedd3258fc1999-03-12 17:13:54 +0000679 case WM_WININICHANGE:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000680 case CB_DIR:
681 case CB_FINDSTRING:
682 case CB_FINDSTRINGEXACT:
683 case CB_SELECTSTRING:
684 case LB_DIR:
685 case LB_ADDFILE:
686 case LB_FINDSTRING:
687 case LB_SELECTSTRING:
688 case EM_REPLACESEL:
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000689 *plparam = (LPARAM)HEAP_strdupWtoA( SystemHeap, 0, (LPCWSTR)*plparam );
Alexandre Julliard3051b641996-07-05 17:14:13 +0000690 return (*plparam ? 1 : -1);
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000691
Alexandre Julliard3051b641996-07-05 17:14:13 +0000692 case WM_NCCREATE:
693 case WM_CREATE:
694 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000695 CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( SystemHeap, 0,
Alexandre Julliard3051b641996-07-05 17:14:13 +0000696 sizeof(*cs) );
697 if (!cs) return -1;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000698 *cs = *(CREATESTRUCTA *)*plparam;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000699 if (HIWORD(cs->lpszName))
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000700 cs->lpszName = HEAP_strdupWtoA( SystemHeap, 0,
701 (LPCWSTR)cs->lpszName );
Alexandre Julliard3051b641996-07-05 17:14:13 +0000702 if (HIWORD(cs->lpszClass))
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000703 cs->lpszClass = HEAP_strdupWtoA( SystemHeap, 0,
704 (LPCWSTR)cs->lpszClass);
Alexandre Julliard3051b641996-07-05 17:14:13 +0000705 *plparam = (LPARAM)cs;
706 }
707 return 1;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000708 case WM_MDICREATE:
709 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000710 MDICREATESTRUCTA *cs =
711 (MDICREATESTRUCTA *)HeapAlloc( SystemHeap, 0, sizeof(*cs) );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000712 if (!cs) return -1;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000713 *cs = *(MDICREATESTRUCTA *)*plparam;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000714 if (HIWORD(cs->szTitle))
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000715 cs->szTitle = HEAP_strdupWtoA( SystemHeap, 0,
716 (LPCWSTR)cs->szTitle );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000717 if (HIWORD(cs->szClass))
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000718 cs->szClass = HEAP_strdupWtoA( SystemHeap, 0,
719 (LPCWSTR)cs->szClass );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000720 *plparam = (LPARAM)cs;
721 }
722 return 1;
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000723
724/* Listbox */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000725 case LB_ADDSTRING:
726 case LB_INSERTSTRING:
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000727 if ( WINPROC_TestLBForStr( hwnd ))
728 *plparam = (LPARAM)HEAP_strdupWtoA( SystemHeap, 0, (LPCWSTR)*plparam );
729 return (*plparam ? 1 : -1);
730
Alexandre Julliarda3960291999-02-26 11:11:13 +0000731 case LB_GETTEXT: /* fixme: fixed sized buffer */
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000732 { if ( WINPROC_TestLBForStr( hwnd ))
733 { LPARAM *ptr = (LPARAM *)HeapAlloc( SystemHeap, 0, 256 + sizeof(LPARAM) );
734 if (!ptr) return -1;
735 *ptr++ = *plparam; /* Store previous lParam */
736 *plparam = (LPARAM)ptr;
737 }
738 }
739 return 1;
740
741/* Combobox */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000742 case CB_ADDSTRING:
743 case CB_INSERTSTRING:
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000744 if ( WINPROC_TestCBForStr( hwnd ))
745 *plparam = (LPARAM)HEAP_strdupWtoA( SystemHeap, 0, (LPCWSTR)*plparam );
746 return (*plparam ? 1 : -1);
747
Alexandre Julliarda3960291999-02-26 11:11:13 +0000748 case CB_GETLBTEXT: /* fixme: fixed sized buffer */
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000749 { if ( WINPROC_TestCBForStr( hwnd ))
750 { LPARAM *ptr = (LPARAM *)HeapAlloc( SystemHeap, 0, 256 + sizeof(LPARAM) );
751 if (!ptr) return -1;
752 *ptr++ = *plparam; /* Store previous lParam */
753 *plparam = (LPARAM)ptr;
754 }
755 }
756 return 1;
757
758/* Multiline edit */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000759 case EM_GETLINE:
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000760 { WORD len = (WORD)*plparam;
761 LPARAM *ptr = (LPARAM *) HEAP_xalloc( SystemHeap, 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(CHAR) );
762 if (!ptr) return -1;
763 *ptr++ = *plparam; /* Store previous lParam */
Patrik Stridvalla9a671d1999-04-25 19:01:52 +0000764 *((WORD *) ptr) = len; /* Store the length */
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000765 *plparam = (LPARAM)ptr;
766 }
767 return 1;
768
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000769 case WM_ASKCBFORMATNAME:
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000770 case WM_DEVMODECHANGE:
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000771 case WM_PAINTCLIPBOARD:
772 case WM_SIZECLIPBOARD:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000773 case EM_SETPASSWORDCHAR:
Alexandre Julliard06c275a1999-05-02 14:32:27 +0000774 FIXME_(msg)("message %s (%04x) needs translation, please report\n",SPY_GetMsgName(msg),msg );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000775 return -1;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000776 default: /* No translation needed */
777 return 0;
778 }
779}
780
781
782/**********************************************************************
783 * WINPROC_UnmapMsg32WTo32A
784 *
785 * Unmap a message that was mapped from Unicode to Ansi.
786 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000787void WINPROC_UnmapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
Juergen Schmied36636ed1998-11-15 16:53:34 +0000788{
789 switch(msg)
Alexandre Julliard3051b641996-07-05 17:14:13 +0000790 {
791 case WM_GETTEXT:
792 {
793 LPARAM *ptr = (LPARAM *)lParam - 1;
Juergen Schmied36636ed1998-11-15 16:53:34 +0000794 lstrcpynAtoW( (LPWSTR)*ptr, (LPSTR)lParam, wParam );
Alexandre Julliard3051b641996-07-05 17:14:13 +0000795 HeapFree( SystemHeap, 0, ptr );
796 }
797 break;
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000798
799 case WM_SETTEXT:
Juergen Schmiedd3258fc1999-03-12 17:13:54 +0000800 case WM_WININICHANGE:
Alexandre Julliarda3960291999-02-26 11:11:13 +0000801 case CB_DIR:
802 case CB_FINDSTRING:
803 case CB_FINDSTRINGEXACT:
804 case CB_SELECTSTRING:
805 case LB_DIR:
806 case LB_ADDFILE:
807 case LB_FINDSTRING:
808 case LB_SELECTSTRING:
809 case EM_REPLACESEL:
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000810 HeapFree( SystemHeap, 0, (void *)lParam );
Alexandre Julliard3051b641996-07-05 17:14:13 +0000811 break;
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000812
Alexandre Julliard3051b641996-07-05 17:14:13 +0000813 case WM_NCCREATE:
814 case WM_CREATE:
815 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000816 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000817 if (HIWORD(cs->lpszName))
818 HeapFree( SystemHeap, 0, (LPVOID)cs->lpszName );
819 if (HIWORD(cs->lpszClass))
820 HeapFree( SystemHeap, 0, (LPVOID)cs->lpszClass );
Alexandre Julliard3051b641996-07-05 17:14:13 +0000821 HeapFree( SystemHeap, 0, cs );
822 }
823 break;
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000824
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000825 case WM_MDICREATE:
826 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000827 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000828 if (HIWORD(cs->szTitle))
829 HeapFree( SystemHeap, 0, (LPVOID)cs->szTitle );
830 if (HIWORD(cs->szClass))
831 HeapFree( SystemHeap, 0, (LPVOID)cs->szClass );
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000832 HeapFree( SystemHeap, 0, cs );
833 }
834 break;
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000835
836/* Listbox */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000837 case LB_ADDSTRING:
838 case LB_INSERTSTRING:
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000839 if ( WINPROC_TestLBForStr( hwnd ))
840 HeapFree( SystemHeap, 0, (void *)lParam );
841 break;
842
Alexandre Julliarda3960291999-02-26 11:11:13 +0000843 case LB_GETTEXT:
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000844 { if ( WINPROC_TestLBForStr( hwnd ))
845 { LPARAM *ptr = (LPARAM *)lParam - 1;
846 lstrcpyAtoW( (LPWSTR)*ptr, (LPSTR)(lParam) );
847 HeapFree( SystemHeap, 0, ptr );
848 }
849 }
850 break;
851
852/* Combobox */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000853 case CB_ADDSTRING:
854 case CB_INSERTSTRING:
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000855 if ( WINPROC_TestCBForStr( hwnd ))
856 HeapFree( SystemHeap, 0, (void *)lParam );
857 break;
858
Alexandre Julliarda3960291999-02-26 11:11:13 +0000859 case CB_GETLBTEXT:
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000860 { if ( WINPROC_TestCBForStr( hwnd ))
861 { LPARAM *ptr = (LPARAM *)lParam - 1;
862 lstrcpyAtoW( (LPWSTR)*ptr, (LPSTR)(lParam) );
863 HeapFree( SystemHeap, 0, ptr );
864 }
865 }
866 break;
867
868/* Multiline edit */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000869 case EM_GETLINE:
Juergen Schmiedafd55801999-01-31 09:18:58 +0000870 { LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lparam */
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000871 WORD len = *(WORD *)ptr;
Juergen Schmiedafd55801999-01-31 09:18:58 +0000872 lstrcpynAtoW( (LPWSTR) *ptr, (LPSTR)lParam, len );
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000873 HeapFree( SystemHeap, 0, ptr );
874 }
875 break;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000876 }
877}
878
879
880/**********************************************************************
881 * WINPROC_MapMsg16To32A
882 *
883 * Map a message from 16- to 32-bit Ansi.
884 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
885 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000886INT WINPROC_MapMsg16To32A( UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
887 WPARAM *pwparam32, LPARAM *plparam )
Alexandre Julliard3051b641996-07-05 17:14:13 +0000888{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000889 *pmsg32 = (UINT)msg16;
890 *pwparam32 = (WPARAM)wParam16;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000891 switch(msg16)
892 {
893 case WM_ACTIVATE:
894 case WM_CHARTOITEM:
895 case WM_COMMAND:
Alexandre Julliard3051b641996-07-05 17:14:13 +0000896 case WM_VKEYTOITEM:
Alexandre Julliard3051b641996-07-05 17:14:13 +0000897 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000898 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
Alexandre Julliard3051b641996-07-05 17:14:13 +0000899 return 0;
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +0000900 case WM_HSCROLL:
901 case WM_VSCROLL:
902 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000903 *plparam = (LPARAM)(HWND)HIWORD(*plparam);
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +0000904 return 0;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000905 case WM_CTLCOLOR:
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +0000906 if ( HIWORD(*plparam) > CTLCOLOR_STATIC ) return -1;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000907 *pmsg32 = WM_CTLCOLORMSGBOX + HIWORD(*plparam);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000908 *pwparam32 = (WPARAM)(HDC)wParam16;
909 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
Alexandre Julliard3051b641996-07-05 17:14:13 +0000910 return 0;
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +0000911 case WM_COMPAREITEM:
912 {
913 COMPAREITEMSTRUCT16* cis16 = (COMPAREITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000914 COMPAREITEMSTRUCT *cis = (COMPAREITEMSTRUCT *)
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +0000915 HeapAlloc(SystemHeap, 0, sizeof(*cis));
916 if (!cis) return -1;
917 cis->CtlType = cis16->CtlType;
918 cis->CtlID = cis16->CtlID;
919 cis->hwndItem = cis16->hwndItem;
920 cis->itemID1 = cis16->itemID1;
921 cis->itemData1 = cis16->itemData1;
922 cis->itemID2 = cis16->itemID2;
923 cis->itemData2 = cis16->itemData2;
924 cis->dwLocaleId = 0; /* FIXME */
925 *plparam = (LPARAM)cis;
926 }
927 return 1;
928 case WM_DELETEITEM:
929 {
930 DELETEITEMSTRUCT16* dis16 = (DELETEITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000931 DELETEITEMSTRUCT *dis = (DELETEITEMSTRUCT *)
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +0000932 HeapAlloc(SystemHeap, 0, sizeof(*dis));
933 if (!dis) return -1;
934 dis->CtlType = dis16->CtlType;
935 dis->CtlID = dis16->CtlID;
936 dis->hwndItem = dis16->hwndItem;
937 dis->itemData = dis16->itemData;
938 *plparam = (LPARAM)dis;
939 }
940 return 1;
941 case WM_MEASUREITEM:
942 {
943 MEASUREITEMSTRUCT16* mis16 = (MEASUREITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000944 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +0000945 HeapAlloc(SystemHeap, 0,
946 sizeof(*mis) + sizeof(LPARAM));
947 if (!mis) return -1;
948 mis->CtlType = mis16->CtlType;
949 mis->CtlID = mis16->CtlID;
950 mis->itemID = mis16->itemID;
951 mis->itemWidth = mis16->itemWidth;
952 mis->itemHeight = mis16->itemHeight;
953 mis->itemData = mis16->itemData;
954 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
955 *plparam = (LPARAM)mis;
956 }
957 return 1;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000958 case WM_DRAWITEM:
959 {
960 DRAWITEMSTRUCT16* dis16 = (DRAWITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000961 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT*)HeapAlloc(SystemHeap, 0,
Alexandre Julliard3051b641996-07-05 17:14:13 +0000962 sizeof(*dis));
963 if (!dis) return -1;
964 dis->CtlType = dis16->CtlType;
965 dis->CtlID = dis16->CtlID;
966 dis->itemID = dis16->itemID;
967 dis->itemAction = dis16->itemAction;
968 dis->itemState = dis16->itemState;
969 dis->hwndItem = dis16->hwndItem;
970 dis->hDC = dis16->hDC;
971 dis->itemData = dis16->itemData;
972 CONV_RECT16TO32( &dis16->rcItem, &dis->rcItem );
973 *plparam = (LPARAM)dis;
974 }
975 return 1;
976 case WM_GETMINMAXINFO:
977 {
Alexandre Julliarda3960291999-02-26 11:11:13 +0000978 MINMAXINFO *mmi = (MINMAXINFO *)HeapAlloc( SystemHeap, 0,
Alexandre Julliard3051b641996-07-05 17:14:13 +0000979 sizeof(*mmi) + sizeof(LPARAM));
980 if (!mmi) return -1;
981 STRUCT32_MINMAXINFO16to32( (MINMAXINFO16*)PTR_SEG_TO_LIN(*plparam),
982 mmi );
983 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
984 *plparam = (LPARAM)mmi;
985 }
986 return 1;
987 case WM_GETTEXT:
Ove Kaaven748acbb1998-11-01 15:27:12 +0000988 case WM_SETTEXT:
Alexandre Julliard3051b641996-07-05 17:14:13 +0000989 *plparam = (LPARAM)PTR_SEG_TO_LIN(*plparam);
990 return 0;
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000991 case WM_MDICREATE:
992 {
993 MDICREATESTRUCT16 *cs16 =
994 (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000995 MDICREATESTRUCTA *cs =
996 (MDICREATESTRUCTA *)HeapAlloc( SystemHeap, 0,
Alexandre Julliard18f92e71996-07-17 20:02:21 +0000997 sizeof(*cs) + sizeof(LPARAM) );
998 if (!cs) return -1;
999 STRUCT32_MDICREATESTRUCT16to32A( cs16, cs );
1000 cs->szTitle = (LPCSTR)PTR_SEG_TO_LIN(cs16->szTitle);
1001 cs->szClass = (LPCSTR)PTR_SEG_TO_LIN(cs16->szClass);
1002 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1003 *plparam = (LPARAM)cs;
1004 }
1005 return 1;
Alexandre Julliard491502b1997-11-01 19:08:16 +00001006 case WM_MDIGETACTIVE:
Alexandre Julliarda3960291999-02-26 11:11:13 +00001007 *plparam = (LPARAM)HeapAlloc( SystemHeap, 0, sizeof(BOOL) );
1008 *(BOOL*)(*plparam) = 0;
Alexandre Julliard491502b1997-11-01 19:08:16 +00001009 return 1;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001010 case WM_MDISETMENU:
Alexandre Julliard85ed45e1998-08-22 19:03:56 +00001011 if(wParam16==TRUE)
1012 *pmsg32=WM_MDIREFRESHMENU;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001013 *pwparam32 = (WPARAM)(HMENU)LOWORD(*plparam);
1014 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
Alexandre Julliard3051b641996-07-05 17:14:13 +00001015 return 0;
1016 case WM_MENUCHAR:
1017 case WM_MENUSELECT:
1018 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
Alexandre Julliarda3960291999-02-26 11:11:13 +00001019 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
Alexandre Julliard3051b641996-07-05 17:14:13 +00001020 return 0;
Alexandre Julliard491502b1997-11-01 19:08:16 +00001021 case WM_MDIACTIVATE:
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00001022 if( *plparam )
1023 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001024 *pwparam32 = (WPARAM)(HWND)HIWORD(*plparam);
1025 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00001026 }
1027 else /* message sent to MDI client */
1028 *pwparam32 = wParam16;
Alexandre Julliard491502b1997-11-01 19:08:16 +00001029 return 0;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001030 case WM_NCCALCSIZE:
1031 {
1032 NCCALCSIZE_PARAMS16 *nc16;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001033 NCCALCSIZE_PARAMS *nc;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001034
Alexandre Julliarda3960291999-02-26 11:11:13 +00001035 nc = (NCCALCSIZE_PARAMS *)HeapAlloc( SystemHeap, 0,
Alexandre Julliard3051b641996-07-05 17:14:13 +00001036 sizeof(*nc) + sizeof(LPARAM) );
1037 if (!nc) return -1;
1038 nc16 = (NCCALCSIZE_PARAMS16 *)PTR_SEG_TO_LIN(*plparam);
1039 CONV_RECT16TO32( &nc16->rgrc[0], &nc->rgrc[0] );
1040 if (wParam16)
1041 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001042 nc->lppos = (WINDOWPOS *)HeapAlloc( SystemHeap, 0,
Alexandre Julliard3051b641996-07-05 17:14:13 +00001043 sizeof(*nc->lppos) );
1044 CONV_RECT16TO32( &nc16->rgrc[1], &nc->rgrc[1] );
1045 CONV_RECT16TO32( &nc16->rgrc[2], &nc->rgrc[2] );
1046 if (nc->lppos) STRUCT32_WINDOWPOS16to32( (WINDOWPOS16 *)PTR_SEG_TO_LIN(nc16->lppos), nc->lppos );
1047 }
1048 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
1049 *plparam = (LPARAM)nc;
1050 }
1051 return 1;
1052 case WM_NCCREATE:
1053 case WM_CREATE:
1054 {
1055 CREATESTRUCT16 *cs16 = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001056 CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( SystemHeap, 0,
Alexandre Julliard3051b641996-07-05 17:14:13 +00001057 sizeof(*cs) + sizeof(LPARAM) );
1058 if (!cs) return -1;
1059 STRUCT32_CREATESTRUCT16to32A( cs16, cs );
1060 cs->lpszName = (LPCSTR)PTR_SEG_TO_LIN(cs16->lpszName);
1061 cs->lpszClass = (LPCSTR)PTR_SEG_TO_LIN(cs16->lpszClass);
1062 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1063 *plparam = (LPARAM)cs;
1064 }
1065 return 1;
1066 case WM_PARENTNOTIFY:
1067 if ((wParam16 == WM_CREATE) || (wParam16 == WM_DESTROY))
1068 {
1069 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
Alexandre Julliarda3960291999-02-26 11:11:13 +00001070 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
Alexandre Julliard3051b641996-07-05 17:14:13 +00001071 }
Alexandre Julliard3051b641996-07-05 17:14:13 +00001072 return 0;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001073 case WM_WINDOWPOSCHANGING:
1074 case WM_WINDOWPOSCHANGED:
1075 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001076 WINDOWPOS *wp = (WINDOWPOS *)HeapAlloc( SystemHeap, 0,
Alexandre Julliard3051b641996-07-05 17:14:13 +00001077 sizeof(*wp) + sizeof(LPARAM) );
1078 if (!wp) return -1;
1079 STRUCT32_WINDOWPOS16to32( (WINDOWPOS16 *)PTR_SEG_TO_LIN(*plparam),
1080 wp );
1081 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
1082 *plparam = (LPARAM)wp;
1083 }
1084 return 1;
Ove Kaaven748acbb1998-11-01 15:27:12 +00001085 case WM_GETDLGCODE:
Alexandre Julliard463b7131998-11-01 16:23:54 +00001086 if (*plparam)
Ove Kaaven748acbb1998-11-01 15:27:12 +00001087 {
1088 LPMSG16 msg16 = (LPMSG16)PTR_SEG_TO_LIN(*plparam);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001089 LPMSG msg32 = (LPMSG)HeapAlloc( SystemHeap, 0, sizeof(MSG) );
Ove Kaaven748acbb1998-11-01 15:27:12 +00001090
1091 if (!msg32) return -1;
1092 msg32->hwnd = msg16->hwnd;
1093 msg32->lParam = msg16->lParam;
1094 msg32->time = msg16->time;
1095 CONV_POINT16TO32(&msg16->pt,&msg32->pt);
1096 /* this is right, right? */
1097 if (WINPROC_MapMsg16To32A(msg16->message,msg16->wParam,
1098 &msg32->message,&msg32->wParam,
1099 &msg32->lParam)<0) {
1100 HeapFree( SystemHeap, 0, msg32 );
1101 return -1;
1102 }
1103 *plparam = (LPARAM)msg32;
Alexandre Julliard463b7131998-11-01 16:23:54 +00001104 return 1;
Ove Kaaven748acbb1998-11-01 15:27:12 +00001105 }
Alexandre Julliard463b7131998-11-01 16:23:54 +00001106 else return 0;
Alexandre Julliard767e6f61998-08-09 12:47:43 +00001107 case WM_NOTIFY:
1108 *plparam = (LPARAM)PTR_SEG_TO_LIN(*plparam);
1109 return 1;
Alexandre Julliard638f1691999-01-17 16:32:32 +00001110 case WM_ACTIVATEAPP:
1111 if (*plparam)
1112 { /* We need this when SetActiveWindow sends a Sendmessage16() to
1113 a 32bit window. Might be superflous with 32bit interprocess
1114 message queues.
1115 */
1116 HTASK16 htask = (HTASK16) *plparam;
Alexandre Julliard0a860a01999-06-22 11:43:42 +00001117 DWORD idThread = (DWORD)((TDB*)GlobalLock16(htask))->teb->tid;
Alexandre Julliard638f1691999-01-17 16:32:32 +00001118 *plparam = (LPARAM) idThread;
1119 }
1120 return 1;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001121 case WM_ASKCBFORMATNAME:
Alexandre Julliard3051b641996-07-05 17:14:13 +00001122 case WM_DEVMODECHANGE:
Alexandre Julliard3051b641996-07-05 17:14:13 +00001123 case WM_PAINTCLIPBOARD:
1124 case WM_SIZECLIPBOARD:
1125 case WM_WININICHANGE:
Alexandre Julliard06c275a1999-05-02 14:32:27 +00001126 FIXME_(msg)("message %04x needs translation\n",msg16 );
Alexandre Julliard3051b641996-07-05 17:14:13 +00001127 return -1;
1128
1129 default: /* No translation needed */
1130 return 0;
1131 }
1132}
1133
1134
1135/**********************************************************************
1136 * WINPROC_UnmapMsg16To32A
1137 *
1138 * Unmap a message that was mapped from 16- to 32-bit Ansi.
1139 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001140LRESULT WINPROC_UnmapMsg16To32A( HWND16 hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
Alexandre Julliard491502b1997-11-01 19:08:16 +00001141 LRESULT result )
Alexandre Julliard3051b641996-07-05 17:14:13 +00001142{
1143 switch(msg)
1144 {
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +00001145 case WM_COMPAREITEM:
1146 case WM_DELETEITEM:
Alexandre Julliard3051b641996-07-05 17:14:13 +00001147 case WM_DRAWITEM:
1148 HeapFree( SystemHeap, 0, (LPVOID)lParam );
1149 break;
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +00001150 case WM_MEASUREITEM:
1151 {
1152 MEASUREITEMSTRUCT16 *mis16;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001153 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lParam;
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +00001154 lParam = *(LPARAM *)(mis + 1);
1155 mis16 = (MEASUREITEMSTRUCT16 *)PTR_SEG_TO_LIN(lParam);
1156 mis16->itemWidth = (UINT16)mis->itemWidth;
1157 mis16->itemHeight = (UINT16)mis->itemHeight;
1158 HeapFree( SystemHeap, 0, mis );
1159 }
1160 break;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001161 case WM_GETMINMAXINFO:
1162 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001163 MINMAXINFO *mmi = (MINMAXINFO *)lParam;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001164 lParam = *(LPARAM *)(mmi + 1);
1165 STRUCT32_MINMAXINFO32to16( mmi,
1166 (MINMAXINFO16 *)PTR_SEG_TO_LIN(lParam));
1167 HeapFree( SystemHeap, 0, mmi );
1168 }
1169 break;
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001170 case WM_MDICREATE:
1171 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001172 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001173 lParam = *(LPARAM *)(cs + 1);
1174 STRUCT32_MDICREATESTRUCT32Ato16( cs,
1175 (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
1176 HeapFree( SystemHeap, 0, cs );
1177 }
1178 break;
Alexandre Julliard491502b1997-11-01 19:08:16 +00001179 case WM_MDIGETACTIVE:
Alexandre Julliarda3960291999-02-26 11:11:13 +00001180 result = MAKELONG( LOWORD(result), (BOOL16)(*(BOOL *)lParam) );
1181 HeapFree( SystemHeap, 0, (BOOL *)lParam );
Alexandre Julliard491502b1997-11-01 19:08:16 +00001182 break;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001183 case WM_NCCALCSIZE:
1184 {
1185 NCCALCSIZE_PARAMS16 *nc16;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001186 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lParam;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001187 lParam = *(LPARAM *)(nc + 1);
1188 nc16 = (NCCALCSIZE_PARAMS16 *)PTR_SEG_TO_LIN(lParam);
1189 CONV_RECT32TO16( &nc->rgrc[0], &nc16->rgrc[0] );
1190 if (wParam)
1191 {
1192 CONV_RECT32TO16( &nc->rgrc[1], &nc16->rgrc[1] );
1193 CONV_RECT32TO16( &nc->rgrc[2], &nc16->rgrc[2] );
1194 if (nc->lppos)
1195 {
1196 STRUCT32_WINDOWPOS32to16( nc->lppos,
1197 (WINDOWPOS16 *)PTR_SEG_TO_LIN(nc16->lppos));
1198 HeapFree( SystemHeap, 0, nc->lppos );
1199 }
1200 }
1201 HeapFree( SystemHeap, 0, nc );
1202 }
1203 break;
1204 case WM_NCCREATE:
1205 case WM_CREATE:
1206 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001207 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001208 lParam = *(LPARAM *)(cs + 1);
1209 STRUCT32_CREATESTRUCT32Ato16( cs,
1210 (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
1211 HeapFree( SystemHeap, 0, cs );
1212 }
1213 break;
1214 case WM_WINDOWPOSCHANGING:
1215 case WM_WINDOWPOSCHANGED:
1216 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001217 WINDOWPOS *wp = (WINDOWPOS *)lParam;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001218 lParam = *(LPARAM *)(wp + 1);
1219 STRUCT32_WINDOWPOS32to16(wp,(WINDOWPOS16 *)PTR_SEG_TO_LIN(lParam));
1220 HeapFree( SystemHeap, 0, wp );
1221 }
1222 break;
Ove Kaaven748acbb1998-11-01 15:27:12 +00001223 case WM_GETDLGCODE:
Alexandre Julliard463b7131998-11-01 16:23:54 +00001224 if (lParam)
Ove Kaaven748acbb1998-11-01 15:27:12 +00001225 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001226 LPMSG msg32 = (LPMSG)lParam;
Ove Kaaven748acbb1998-11-01 15:27:12 +00001227
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +00001228 WINPROC_UnmapMsg16To32A( hwnd, msg32->message, msg32->wParam, msg32->lParam,
Ove Kaaven748acbb1998-11-01 15:27:12 +00001229 result);
1230 HeapFree( SystemHeap, 0, msg32 );
1231 }
1232 break;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001233 }
Alexandre Julliard491502b1997-11-01 19:08:16 +00001234 return result;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001235}
1236
1237
1238/**********************************************************************
1239 * WINPROC_MapMsg16To32W
1240 *
1241 * Map a message from 16- to 32-bit Unicode.
1242 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1243 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001244INT WINPROC_MapMsg16To32W( HWND16 hwnd, UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
1245 WPARAM *pwparam32, LPARAM *plparam )
Alexandre Julliard3051b641996-07-05 17:14:13 +00001246{
1247 switch(msg16)
1248 {
1249 case WM_GETTEXT:
1250 case WM_SETTEXT:
1251 *plparam = (LPARAM)PTR_SEG_TO_LIN(*plparam);
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +00001252 return WINPROC_MapMsg32ATo32W( hwnd, *pmsg32, *pwparam32, plparam );
Alexandre Julliard3051b641996-07-05 17:14:13 +00001253 case WM_NCCREATE:
1254 case WM_CREATE:
1255 {
1256 CREATESTRUCT16 *cs16 = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001257 CREATESTRUCTW *cs = (CREATESTRUCTW *)HeapAlloc( SystemHeap, 0,
Alexandre Julliard3051b641996-07-05 17:14:13 +00001258 sizeof(*cs) + sizeof(LPARAM) );
1259 if (!cs) return -1;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001260 STRUCT32_CREATESTRUCT16to32A( cs16, (CREATESTRUCTA *)cs );
Alexandre Julliard3051b641996-07-05 17:14:13 +00001261 cs->lpszName = (LPCWSTR)PTR_SEG_TO_LIN(cs16->lpszName);
1262 cs->lpszClass = (LPCWSTR)PTR_SEG_TO_LIN(cs16->lpszClass);
1263 if (HIWORD(cs->lpszName))
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00001264 cs->lpszName = HEAP_strdupAtoW( SystemHeap, 0,
1265 (LPCSTR)cs->lpszName );
Alexandre Julliard3051b641996-07-05 17:14:13 +00001266 if (HIWORD(cs->lpszClass))
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00001267 cs->lpszClass = HEAP_strdupAtoW( SystemHeap, 0,
1268 (LPCSTR)cs->lpszClass );
Alexandre Julliard3051b641996-07-05 17:14:13 +00001269 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1270 *plparam = (LPARAM)cs;
1271 }
1272 return 1;
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001273 case WM_MDICREATE:
1274 {
1275 MDICREATESTRUCT16 *cs16 =
1276 (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001277 MDICREATESTRUCTW *cs =
1278 (MDICREATESTRUCTW *)HeapAlloc( SystemHeap, 0,
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001279 sizeof(*cs) + sizeof(LPARAM) );
1280 if (!cs) return -1;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001281 STRUCT32_MDICREATESTRUCT16to32A( cs16, (MDICREATESTRUCTA *)cs );
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001282 cs->szTitle = (LPCWSTR)PTR_SEG_TO_LIN(cs16->szTitle);
1283 cs->szClass = (LPCWSTR)PTR_SEG_TO_LIN(cs16->szClass);
1284 if (HIWORD(cs->szTitle))
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00001285 cs->szTitle = HEAP_strdupAtoW( SystemHeap, 0,
1286 (LPCSTR)cs->szTitle );
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001287 if (HIWORD(cs->szClass))
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00001288 cs->szClass = HEAP_strdupAtoW( SystemHeap, 0,
1289 (LPCSTR)cs->szClass );
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001290 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1291 *plparam = (LPARAM)cs;
1292 }
1293 return 1;
Ove Kaaven748acbb1998-11-01 15:27:12 +00001294 case WM_GETDLGCODE:
Alexandre Julliard463b7131998-11-01 16:23:54 +00001295 if (*plparam)
Ove Kaaven748acbb1998-11-01 15:27:12 +00001296 {
1297 LPMSG16 msg16 = (LPMSG16)PTR_SEG_TO_LIN(*plparam);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001298 LPMSG msg32 = (LPMSG)HeapAlloc( SystemHeap, 0, sizeof(MSG) );
Ove Kaaven748acbb1998-11-01 15:27:12 +00001299
1300 if (!msg32) return -1;
1301 msg32->hwnd = msg16->hwnd;
1302 msg32->lParam = msg16->lParam;
1303 msg32->time = msg16->time;
1304 CONV_POINT16TO32(&msg16->pt,&msg32->pt);
1305 /* this is right, right? */
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +00001306 if (WINPROC_MapMsg16To32W(hwnd, msg16->message,msg16->wParam,
Ove Kaaven748acbb1998-11-01 15:27:12 +00001307 &msg32->message,&msg32->wParam,
1308 &msg32->lParam)<0) {
1309 HeapFree( SystemHeap, 0, msg32 );
1310 return -1;
1311 }
1312 *plparam = (LPARAM)msg32;
Alexandre Julliard463b7131998-11-01 16:23:54 +00001313 return 1;
Ove Kaaven748acbb1998-11-01 15:27:12 +00001314 }
Alexandre Julliard463b7131998-11-01 16:23:54 +00001315 else return 0;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001316 default: /* No Unicode translation needed */
1317 return WINPROC_MapMsg16To32A( msg16, wParam16, pmsg32,
1318 pwparam32, plparam );
1319 }
1320}
1321
1322
1323/**********************************************************************
1324 * WINPROC_UnmapMsg16To32W
1325 *
1326 * Unmap a message that was mapped from 16- to 32-bit Unicode.
1327 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001328LRESULT WINPROC_UnmapMsg16To32W( HWND16 hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
Alexandre Julliard491502b1997-11-01 19:08:16 +00001329 LRESULT result )
Alexandre Julliard3051b641996-07-05 17:14:13 +00001330{
1331 switch(msg)
1332 {
1333 case WM_GETTEXT:
1334 case WM_SETTEXT:
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +00001335 WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam );
Alexandre Julliard3051b641996-07-05 17:14:13 +00001336 break;
1337 case WM_NCCREATE:
1338 case WM_CREATE:
1339 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001340 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001341 lParam = *(LPARAM *)(cs + 1);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001342 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs,
Alexandre Julliard3051b641996-07-05 17:14:13 +00001343 (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00001344 if (HIWORD(cs->lpszName))
1345 HeapFree( SystemHeap, 0, (LPVOID)cs->lpszName );
1346 if (HIWORD(cs->lpszClass))
1347 HeapFree( SystemHeap, 0, (LPVOID)cs->lpszClass );
Alexandre Julliard3051b641996-07-05 17:14:13 +00001348 HeapFree( SystemHeap, 0, cs );
1349 }
1350 break;
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001351 case WM_MDICREATE:
1352 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001353 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001354 lParam = *(LPARAM *)(cs + 1);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001355 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs,
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001356 (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00001357 if (HIWORD(cs->szTitle))
1358 HeapFree( SystemHeap, 0, (LPVOID)cs->szTitle );
1359 if (HIWORD(cs->szClass))
1360 HeapFree( SystemHeap, 0, (LPVOID)cs->szClass );
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001361 HeapFree( SystemHeap, 0, cs );
1362 }
1363 break;
Ove Kaaven748acbb1998-11-01 15:27:12 +00001364 case WM_GETDLGCODE:
Alexandre Julliard463b7131998-11-01 16:23:54 +00001365 if (lParam)
Ove Kaaven748acbb1998-11-01 15:27:12 +00001366 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001367 LPMSG msg32 = (LPMSG)lParam;
Ove Kaaven748acbb1998-11-01 15:27:12 +00001368
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +00001369 WINPROC_UnmapMsg16To32W( hwnd, msg32->message, msg32->wParam, msg32->lParam,
Ove Kaaven748acbb1998-11-01 15:27:12 +00001370 result);
1371 HeapFree( SystemHeap, 0, msg32 );
1372 }
1373 break;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001374 default:
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +00001375 return WINPROC_UnmapMsg16To32A( hwnd, msg, wParam, lParam, result );
Alexandre Julliard3051b641996-07-05 17:14:13 +00001376 }
Alexandre Julliard491502b1997-11-01 19:08:16 +00001377 return result;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001378}
1379
1380
1381/**********************************************************************
1382 * WINPROC_MapMsg32ATo16
1383 *
1384 * Map a message from 32-bit Ansi to 16-bit.
1385 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1386 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001387INT WINPROC_MapMsg32ATo16( HWND hwnd, UINT msg32, WPARAM wParam32,
Alexandre Julliard491502b1997-11-01 19:08:16 +00001388 UINT16 *pmsg16, WPARAM16 *pwparam16,
1389 LPARAM *plparam )
Alexandre Julliard3051b641996-07-05 17:14:13 +00001390{
1391 *pmsg16 = (UINT16)msg32;
1392 *pwparam16 = (WPARAM16)LOWORD(wParam32);
1393 switch(msg32)
1394 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001395 case BM_GETCHECK:
1396 case BM_SETCHECK:
1397 case BM_GETSTATE:
1398 case BM_SETSTATE:
1399 case BM_SETSTYLE:
1400 *pmsg16 = (UINT16)msg32 + (BM_GETCHECK16 - BM_GETCHECK);
Alexandre Julliard8cc3a5e1996-08-11 15:49:51 +00001401 return 0;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001402
Alexandre Julliarda3960291999-02-26 11:11:13 +00001403 case EM_GETSEL:
1404 case EM_GETRECT:
1405 case EM_SETRECT:
1406 case EM_SETRECTNP:
1407 case EM_SCROLL:
1408 case EM_LINESCROLL:
1409 case EM_SCROLLCARET:
1410 case EM_GETMODIFY:
1411 case EM_SETMODIFY:
1412 case EM_GETLINECOUNT:
1413 case EM_LINEINDEX:
1414 case EM_SETHANDLE:
1415 case EM_GETHANDLE:
1416 case EM_GETTHUMB:
1417 case EM_LINELENGTH:
1418 case EM_REPLACESEL:
1419 case EM_GETLINE:
1420 case EM_LIMITTEXT:
1421 case EM_CANUNDO:
1422 case EM_UNDO:
1423 case EM_FMTLINES:
1424 case EM_LINEFROMCHAR:
1425 case EM_SETTABSTOPS:
1426 case EM_SETPASSWORDCHAR:
1427 case EM_EMPTYUNDOBUFFER:
1428 case EM_GETFIRSTVISIBLELINE:
1429 case EM_SETREADONLY:
1430 case EM_SETWORDBREAKPROC:
1431 case EM_GETWORDBREAKPROC:
1432 case EM_GETPASSWORDCHAR:
1433 *pmsg16 = (UINT16)msg32 + (EM_GETSEL16 - EM_GETSEL);
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001434 return 0;
1435
Alexandre Julliarda3960291999-02-26 11:11:13 +00001436 case LB_CARETOFF:
1437 case LB_CARETON:
1438 case LB_DELETESTRING:
1439 case LB_GETANCHORINDEX:
1440 case LB_GETCARETINDEX:
1441 case LB_GETCOUNT:
1442 case LB_GETCURSEL:
1443 case LB_GETHORIZONTALEXTENT:
1444 case LB_GETITEMDATA:
1445 case LB_GETITEMHEIGHT:
1446 case LB_GETSEL:
1447 case LB_GETSELCOUNT:
1448 case LB_GETTEXTLEN:
1449 case LB_GETTOPINDEX:
1450 case LB_RESETCONTENT:
1451 case LB_SELITEMRANGE:
1452 case LB_SELITEMRANGEEX:
1453 case LB_SETANCHORINDEX:
1454 case LB_SETCARETINDEX:
1455 case LB_SETCOLUMNWIDTH:
1456 case LB_SETCURSEL:
1457 case LB_SETHORIZONTALEXTENT:
1458 case LB_SETITEMDATA:
1459 case LB_SETITEMHEIGHT:
1460 case LB_SETSEL:
1461 case LB_SETTOPINDEX:
1462 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001463 return 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001464 case CB_DELETESTRING:
1465 case CB_GETCOUNT:
1466 case CB_GETLBTEXTLEN:
1467 case CB_LIMITTEXT:
1468 case CB_RESETCONTENT:
1469 case CB_SETEDITSEL:
1470 case CB_GETCURSEL:
1471 case CB_SETCURSEL:
1472 case CB_SHOWDROPDOWN:
1473 case CB_SETITEMDATA:
1474 case CB_SETITEMHEIGHT:
1475 case CB_GETITEMHEIGHT:
1476 case CB_SETEXTENDEDUI:
1477 case CB_GETEXTENDEDUI:
1478 case CB_GETDROPPEDSTATE:
1479 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001480 return 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001481 case CB_GETEDITSEL:
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001482 *pmsg16 = CB_GETEDITSEL16;
1483 return 1;
1484
Alexandre Julliarda3960291999-02-26 11:11:13 +00001485 case LB_ADDSTRING:
1486 case LB_FINDSTRING:
1487 case LB_FINDSTRINGEXACT:
1488 case LB_INSERTSTRING:
1489 case LB_SELECTSTRING:
1490 case LB_DIR:
1491 case LB_ADDFILE:
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001492 {
1493 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
1494 if (!str) return -1;
1495 *plparam = (LPARAM)SEGPTR_GET(str);
1496 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00001497 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001498 return 1;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001499
Alexandre Julliarda3960291999-02-26 11:11:13 +00001500 case CB_ADDSTRING:
1501 case CB_FINDSTRING:
1502 case CB_FINDSTRINGEXACT:
1503 case CB_INSERTSTRING:
1504 case CB_SELECTSTRING:
1505 case CB_DIR:
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001506 {
1507 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
1508 if (!str) return -1;
1509 *plparam = (LPARAM)SEGPTR_GET(str);
1510 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00001511 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001512 return 1;
1513
Alexandre Julliarda3960291999-02-26 11:11:13 +00001514 case LB_GETITEMRECT:
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001515 {
1516 RECT16 *rect;
1517 rect = (RECT16 *)SEGPTR_ALLOC( sizeof(RECT16) + sizeof(LPARAM) );
1518 if (!rect) return -1;
1519 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
1520 *plparam = (LPARAM)SEGPTR_GET(rect);
1521 }
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001522 *pmsg16 = LB_GETITEMRECT16;
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001523 return 1;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001524 case LB_GETSELITEMS:
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001525 {
1526 LPINT16 items;
1527 *pwparam16 = (WPARAM16)MIN( wParam32, 0x7f80 ); /* Must be < 64K */
1528 if (!(items = SEGPTR_ALLOC( *pwparam16 * sizeof(INT16)
1529 + sizeof(LPARAM)))) return -1;
1530 *((LPARAM *)items)++ = *plparam; /* Store the previous lParam */
1531 *plparam = (LPARAM)SEGPTR_GET(items);
1532 }
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001533 *pmsg16 = LB_GETSELITEMS16;
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001534 return 1;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001535 case LB_SETTABSTOPS:
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001536 if (wParam32)
1537 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001538 INT i;
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001539 LPINT16 stops;
1540 *pwparam16 = (WPARAM16)MIN( wParam32, 0x7f80 ); /* Must be < 64K */
1541 if (!(stops = SEGPTR_ALLOC( *pwparam16 * sizeof(INT16)
1542 + sizeof(LPARAM)))) return -1;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001543 for (i = 0; i < *pwparam16; i++) stops[i] = *((LPINT)*plparam+i);
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001544 *plparam = (LPARAM)SEGPTR_GET(stops);
1545 return 1;
1546 }
1547 *pmsg16 = LB_SETTABSTOPS16;
1548 return 0;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001549
Alexandre Julliarda3960291999-02-26 11:11:13 +00001550 case CB_GETDROPPEDCONTROLRECT:
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001551 {
1552 RECT16 *rect;
1553 rect = (RECT16 *)SEGPTR_ALLOC( sizeof(RECT16) + sizeof(LPARAM) );
1554 if (!rect) return -1;
1555 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
1556 *plparam = (LPARAM)SEGPTR_GET(rect);
1557 }
1558 *pmsg16 = CB_GETDROPPEDCONTROLRECT16;
1559 return 1;
1560
Alexandre Julliarda3960291999-02-26 11:11:13 +00001561 case LB_GETTEXT:
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001562 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
1563 *pmsg16 = LB_GETTEXT16;
1564 return 1;
1565
Alexandre Julliarda3960291999-02-26 11:11:13 +00001566 case CB_GETLBTEXT:
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001567 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
1568 *pmsg16 = CB_GETLBTEXT16;
1569 return 1;
1570
Alexandre Julliarda3960291999-02-26 11:11:13 +00001571 case EM_SETSEL:
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001572 *pwparam16 = 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001573 *plparam = MAKELONG( (INT16)(INT)wParam32, (INT16)*plparam );
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001574 *pmsg16 = EM_SETSEL16;
1575 return 0;
1576
Alexandre Julliard3051b641996-07-05 17:14:13 +00001577 case WM_ACTIVATE:
1578 case WM_CHARTOITEM:
1579 case WM_COMMAND:
Alexandre Julliard3051b641996-07-05 17:14:13 +00001580 case WM_VKEYTOITEM:
Alexandre Julliard3051b641996-07-05 17:14:13 +00001581 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
1582 return 0;
Alexandre Julliardca22b331996-07-12 19:02:39 +00001583 case WM_HSCROLL:
1584 case WM_VSCROLL:
1585 *plparam = MAKELPARAM( HIWORD(wParam32), (HWND16)*plparam );
1586 return 0;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001587 case WM_CTLCOLORMSGBOX:
1588 case WM_CTLCOLOREDIT:
1589 case WM_CTLCOLORLISTBOX:
1590 case WM_CTLCOLORBTN:
1591 case WM_CTLCOLORDLG:
1592 case WM_CTLCOLORSCROLLBAR:
1593 case WM_CTLCOLORSTATIC:
1594 *pmsg16 = WM_CTLCOLOR;
1595 *plparam = MAKELPARAM( (HWND16)*plparam,
1596 (WORD)msg32 - WM_CTLCOLORMSGBOX );
1597 return 0;
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +00001598 case WM_COMPAREITEM:
1599 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001600 COMPAREITEMSTRUCT *cis32 = (COMPAREITEMSTRUCT *)*plparam;
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +00001601 COMPAREITEMSTRUCT16 *cis = SEGPTR_NEW(COMPAREITEMSTRUCT16);
1602 if (!cis) return -1;
1603 cis->CtlType = (UINT16)cis32->CtlType;
1604 cis->CtlID = (UINT16)cis32->CtlID;
1605 cis->hwndItem = (HWND16)cis32->hwndItem;
1606 cis->itemID1 = (UINT16)cis32->itemID1;
1607 cis->itemData1 = cis32->itemData1;
1608 cis->itemID2 = (UINT16)cis32->itemID2;
1609 cis->itemData2 = cis32->itemData2;
1610 *plparam = (LPARAM)SEGPTR_GET(cis);
1611 }
1612 return 1;
1613 case WM_DELETEITEM:
1614 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001615 DELETEITEMSTRUCT *dis32 = (DELETEITEMSTRUCT *)*plparam;
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +00001616 DELETEITEMSTRUCT16 *dis = SEGPTR_NEW(DELETEITEMSTRUCT16);
1617 if (!dis) return -1;
1618 dis->CtlType = (UINT16)dis32->CtlType;
1619 dis->CtlID = (UINT16)dis32->CtlID;
1620 dis->itemID = (UINT16)dis32->itemID;
1621 dis->hwndItem = (HWND16)dis32->hwndItem;
1622 dis->itemData = dis32->itemData;
1623 *plparam = (LPARAM)SEGPTR_GET(dis);
1624 }
1625 return 1;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001626 case WM_DRAWITEM:
1627 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001628 DRAWITEMSTRUCT *dis32 = (DRAWITEMSTRUCT *)*plparam;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001629 DRAWITEMSTRUCT16 *dis = SEGPTR_NEW(DRAWITEMSTRUCT16);
1630 if (!dis) return -1;
1631 dis->CtlType = (UINT16)dis32->CtlType;
1632 dis->CtlID = (UINT16)dis32->CtlID;
1633 dis->itemID = (UINT16)dis32->itemID;
1634 dis->itemAction = (UINT16)dis32->itemAction;
1635 dis->itemState = (UINT16)dis32->itemState;
1636 dis->hwndItem = (HWND16)dis32->hwndItem;
1637 dis->hDC = (HDC16)dis32->hDC;
1638 dis->itemData = dis32->itemData;
1639 CONV_RECT32TO16( &dis32->rcItem, &dis->rcItem );
1640 *plparam = (LPARAM)SEGPTR_GET(dis);
1641 }
1642 return 1;
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +00001643 case WM_MEASUREITEM:
1644 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001645 MEASUREITEMSTRUCT *mis32 = (MEASUREITEMSTRUCT *)*plparam;
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +00001646 MEASUREITEMSTRUCT16 *mis = (MEASUREITEMSTRUCT16 *)
1647 SEGPTR_ALLOC(sizeof(*mis)+sizeof(LPARAM));
1648 if (!mis) return -1;
1649 mis->CtlType = (UINT16)mis32->CtlType;
1650 mis->CtlID = (UINT16)mis32->CtlID;
1651 mis->itemID = (UINT16)mis32->itemID;
1652 mis->itemWidth = (UINT16)mis32->itemWidth;
1653 mis->itemHeight = (UINT16)mis32->itemHeight;
1654 mis->itemData = mis32->itemData;
1655 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
1656 *plparam = (LPARAM)SEGPTR_GET(mis);
1657 }
1658 return 1;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001659 case WM_GETMINMAXINFO:
1660 {
1661 MINMAXINFO16 *mmi = (MINMAXINFO16 *)SEGPTR_ALLOC( sizeof(*mmi) +
1662 sizeof(LPARAM) );
1663 if (!mmi) return -1;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001664 STRUCT32_MINMAXINFO32to16( (MINMAXINFO *)*plparam, mmi );
Alexandre Julliard3051b641996-07-05 17:14:13 +00001665 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
1666 *plparam = (LPARAM)SEGPTR_GET(mmi);
1667 }
1668 return 1;
1669 case WM_GETTEXT:
1670 {
1671 LPSTR str;
1672 *pwparam16 = (WPARAM16)MIN( wParam32, 0xff80 ); /* Must be < 64K */
1673 if (!(str = SEGPTR_ALLOC(*pwparam16 + sizeof(LPARAM)))) return -1;
1674 *((LPARAM *)str)++ = *plparam; /* Store the previous lParam */
1675 *plparam = (LPARAM)SEGPTR_GET(str);
1676 }
1677 return 1;
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001678 case WM_MDICREATE:
1679 {
1680 MDICREATESTRUCT16 *cs;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001681 MDICREATESTRUCTA *cs32 = (MDICREATESTRUCTA *)*plparam;
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001682 LPSTR name, cls;
1683
1684 if (!(cs = SEGPTR_NEW(MDICREATESTRUCT16))) return -1;
1685 STRUCT32_MDICREATESTRUCT32Ato16( cs32, cs );
1686 name = SEGPTR_STRDUP( cs32->szTitle );
1687 cls = SEGPTR_STRDUP( cs32->szClass );
1688 cs->szTitle = SEGPTR_GET(name);
1689 cs->szClass = SEGPTR_GET(cls);
1690 *plparam = (LPARAM)SEGPTR_GET(cs);
1691 }
1692 return 1;
Alexandre Julliard491502b1997-11-01 19:08:16 +00001693 case WM_MDIGETACTIVE:
1694 return 1;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001695 case WM_MDISETMENU:
Alexandre Julliard3051b641996-07-05 17:14:13 +00001696 *plparam = MAKELPARAM( (HMENU16)LOWORD(wParam32),
1697 (HMENU16)LOWORD(*plparam) );
Alexandre Julliard491502b1997-11-01 19:08:16 +00001698 *pwparam16 = (*plparam == 0);
Alexandre Julliard3051b641996-07-05 17:14:13 +00001699 return 0;
1700 case WM_MENUCHAR:
1701 case WM_MENUSELECT:
1702 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
1703 return 0;
Alexandre Julliard491502b1997-11-01 19:08:16 +00001704 case WM_MDIACTIVATE:
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00001705 {
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001706 WND *tempWnd = WIN_FindWndPtr(hwnd);
1707 if( WIDGETS_IsControl(tempWnd, BIC32_MDICLIENT) )
1708 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001709 *pwparam16 = (HWND)wParam32;
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00001710 *plparam = 0;
1711 }
1712 else
1713 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001714 *pwparam16 = ((HWND)*plparam == hwnd);
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00001715 *plparam = MAKELPARAM( (HWND16)LOWORD(*plparam),
1716 (HWND16)LOWORD(wParam32) );
1717 }
Francois Boisvert6b1b41c1999-03-14 17:25:32 +00001718 WIN_ReleaseWndPtr(tempWnd);
1719 }
Alexandre Julliard491502b1997-11-01 19:08:16 +00001720 return 0;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001721 case WM_NCCALCSIZE:
1722 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001723 NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)*plparam;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001724 NCCALCSIZE_PARAMS16 *nc = (NCCALCSIZE_PARAMS16 *)SEGPTR_ALLOC( sizeof(*nc) + sizeof(LPARAM) );
1725 if (!nc) return -1;
1726
1727 CONV_RECT32TO16( &nc32->rgrc[0], &nc->rgrc[0] );
1728 if (wParam32)
1729 {
1730 WINDOWPOS16 *wp;
1731 CONV_RECT32TO16( &nc32->rgrc[1], &nc->rgrc[1] );
1732 CONV_RECT32TO16( &nc32->rgrc[2], &nc->rgrc[2] );
1733 if (!(wp = SEGPTR_NEW(WINDOWPOS16)))
1734 {
1735 SEGPTR_FREE(nc);
1736 return -1;
1737 }
1738 STRUCT32_WINDOWPOS32to16( nc32->lppos, wp );
1739 nc->lppos = SEGPTR_GET(wp);
1740 }
1741 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
1742 *plparam = (LPARAM)SEGPTR_GET(nc);
1743 }
1744 return 1;
1745 case WM_NCCREATE:
1746 case WM_CREATE:
1747 {
1748 CREATESTRUCT16 *cs;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001749 CREATESTRUCTA *cs32 = (CREATESTRUCTA *)*plparam;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001750 LPSTR name, cls;
1751
1752 if (!(cs = SEGPTR_NEW(CREATESTRUCT16))) return -1;
1753 STRUCT32_CREATESTRUCT32Ato16( cs32, cs );
1754 name = SEGPTR_STRDUP( cs32->lpszName );
1755 cls = SEGPTR_STRDUP( cs32->lpszClass );
1756 cs->lpszName = SEGPTR_GET(name);
1757 cs->lpszClass = SEGPTR_GET(cls);
1758 *plparam = (LPARAM)SEGPTR_GET(cs);
1759 }
1760 return 1;
1761 case WM_PARENTNOTIFY:
1762 if ((LOWORD(wParam32)==WM_CREATE) || (LOWORD(wParam32)==WM_DESTROY))
1763 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32));
1764 /* else nothing to do */
1765 return 0;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001766 case WM_NOTIFY:
1767 *plparam = MapLS( (NMHDR *)*plparam ); /* NMHDR is already 32-bit */
1768 return 1;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001769 case WM_SETTEXT:
1770 {
1771 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
1772 if (!str) return -1;
1773 *plparam = (LPARAM)SEGPTR_GET(str);
1774 }
1775 return 1;
1776 case WM_WINDOWPOSCHANGING:
1777 case WM_WINDOWPOSCHANGED:
1778 {
1779 WINDOWPOS16 *wp = (WINDOWPOS16 *)SEGPTR_ALLOC( sizeof(*wp) +
1780 sizeof(LPARAM) );
1781 if (!wp) return -1;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001782 STRUCT32_WINDOWPOS32to16( (WINDOWPOS *)*plparam, wp );
Alexandre Julliard3051b641996-07-05 17:14:13 +00001783 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
1784 *plparam = (LPARAM)SEGPTR_GET(wp);
1785 }
1786 return 1;
Rein Klazescb505621998-11-07 12:24:21 +00001787 case WM_GETDLGCODE:
1788 if (*plparam) {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001789 LPMSG msg32 = (LPMSG) *plparam;
Rein Klazescb505621998-11-07 12:24:21 +00001790 LPMSG16 msg16 = (LPMSG16) SEGPTR_NEW( MSG16 );
1791
1792 if (!msg16) return -1;
1793 msg16->hwnd = msg32->hwnd;
1794 msg16->lParam = msg32->lParam;
1795 msg16->time = msg32->time;
1796 CONV_POINT32TO16(&msg32->pt,&msg16->pt);
1797 /* this is right, right? */
1798 if (WINPROC_MapMsg32ATo16(msg32->hwnd,msg32->message,msg32->wParam,
1799 &msg16->message,&msg16->wParam, &msg16->lParam)<0) {
1800 SEGPTR_FREE( msg16 );
1801 return -1;
1802 }
1803 *plparam = (LPARAM)SEGPTR_GET(msg16);
1804 return 1;
1805 }
1806 return 0;
1807
Alexandre Julliard638f1691999-01-17 16:32:32 +00001808 case WM_ACTIVATEAPP:
Alexandre Julliard8da12c41999-01-17 16:55:11 +00001809 if (*plparam) {
Alexandre Julliard0a860a01999-06-22 11:43:42 +00001810 *plparam = (LPARAM)THREAD_IdToTEB((DWORD) *plparam)->htask16;
Alexandre Julliard8da12c41999-01-17 16:55:11 +00001811 }
1812 return 1;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001813 case WM_ASKCBFORMATNAME:
Alexandre Julliard3051b641996-07-05 17:14:13 +00001814 case WM_DEVMODECHANGE:
Alexandre Julliard3051b641996-07-05 17:14:13 +00001815 case WM_PAINTCLIPBOARD:
1816 case WM_SIZECLIPBOARD:
1817 case WM_WININICHANGE:
Alexandre Julliard06c275a1999-05-02 14:32:27 +00001818 FIXME_(msg)("message %04x needs translation\n", msg32 );
Alexandre Julliard3051b641996-07-05 17:14:13 +00001819 return -1;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001820 default: /* No translation needed */
1821 return 0;
1822 }
1823}
1824
1825
1826/**********************************************************************
1827 * WINPROC_UnmapMsg32ATo16
1828 *
1829 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
1830 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001831void WINPROC_UnmapMsg32ATo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
Alexandre Julliard491502b1997-11-01 19:08:16 +00001832 MSGPARAM16* p16 )
Alexandre Julliard3051b641996-07-05 17:14:13 +00001833{
1834 switch(msg)
1835 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001836 case LB_ADDFILE:
1837 case LB_ADDSTRING:
1838 case LB_DIR:
1839 case LB_FINDSTRING:
1840 case LB_FINDSTRINGEXACT:
1841 case LB_INSERTSTRING:
1842 case LB_SELECTSTRING:
1843 case LB_SETTABSTOPS:
1844 case CB_ADDSTRING:
1845 case CB_FINDSTRING:
1846 case CB_FINDSTRINGEXACT:
1847 case CB_INSERTSTRING:
1848 case CB_SELECTSTRING:
1849 case CB_DIR:
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +00001850 case WM_COMPAREITEM:
1851 case WM_DELETEITEM:
Alexandre Julliard3051b641996-07-05 17:14:13 +00001852 case WM_DRAWITEM:
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001853 case WM_SETTEXT:
Alexandre Julliard889f7421997-04-15 17:19:52 +00001854 SEGPTR_FREE( PTR_SEG_TO_LIN(p16->lParam) );
Alexandre Julliard3051b641996-07-05 17:14:13 +00001855 break;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001856
Alexandre Julliarda3960291999-02-26 11:11:13 +00001857 case CB_GETDROPPEDCONTROLRECT:
1858 case LB_GETITEMRECT:
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001859 {
Alexandre Julliard889f7421997-04-15 17:19:52 +00001860 RECT16 *rect = (RECT16 *)PTR_SEG_TO_LIN(p16->lParam);
1861 p16->lParam = *(LPARAM *)(rect + 1);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001862 CONV_RECT16TO32( rect, (RECT *)(p16->lParam));
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001863 SEGPTR_FREE( rect );
1864 }
1865 break;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001866 case LB_GETSELITEMS:
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001867 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001868 INT i;
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001869 LPINT16 items = (LPINT16)PTR_SEG_TO_LIN(lParam);
Alexandre Julliard889f7421997-04-15 17:19:52 +00001870 p16->lParam = *((LPARAM *)items - 1);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001871 for (i = 0; i < p16->wParam; i++) *((LPINT)(p16->lParam) + i) = items[i];
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00001872 SEGPTR_FREE( (LPARAM *)items - 1 );
1873 }
1874 break;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001875
Alexandre Julliarda3960291999-02-26 11:11:13 +00001876 case CB_GETEDITSEL:
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001877 if( wParam )
Alexandre Julliarda3960291999-02-26 11:11:13 +00001878 *((LPUINT)(wParam)) = LOWORD(p16->lResult);
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001879 if( lParam )
Alexandre Julliarda3960291999-02-26 11:11:13 +00001880 *((LPUINT)(lParam)) = HIWORD(p16->lResult); /* FIXME: substract 1? */
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001881 break;
1882
Alexandre Julliarda3960291999-02-26 11:11:13 +00001883 case LB_GETTEXT:
1884 case CB_GETLBTEXT:
Alexandre Julliard889f7421997-04-15 17:19:52 +00001885 UnMapLS( (SEGPTR)(p16->lParam) );
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001886 break;
1887
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +00001888 case WM_MEASUREITEM:
1889 {
Alexandre Julliard889f7421997-04-15 17:19:52 +00001890 MEASUREITEMSTRUCT16 *mis = (MEASUREITEMSTRUCT16 *)PTR_SEG_TO_LIN(p16->lParam);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001891 MEASUREITEMSTRUCT *mis32 = *(MEASUREITEMSTRUCT **)(mis + 1);
Alexandre Julliardd1ce8b21996-09-02 16:46:30 +00001892 mis32->itemWidth = mis->itemWidth;
1893 mis32->itemHeight = mis->itemHeight;
1894 SEGPTR_FREE(mis);
1895 }
1896 break;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001897 case WM_GETMINMAXINFO:
1898 {
Alexandre Julliard889f7421997-04-15 17:19:52 +00001899 MINMAXINFO16 *mmi = (MINMAXINFO16 *)PTR_SEG_TO_LIN(p16->lParam);
1900 p16->lParam = *(LPARAM *)(mmi + 1);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001901 STRUCT32_MINMAXINFO16to32( mmi, (MINMAXINFO *)(p16->lParam) );
Alexandre Julliard3051b641996-07-05 17:14:13 +00001902 SEGPTR_FREE(mmi);
1903 }
1904 break;
1905 case WM_GETTEXT:
1906 {
Alexandre Julliard889f7421997-04-15 17:19:52 +00001907 LPSTR str = (LPSTR)PTR_SEG_TO_LIN(p16->lParam);
1908 p16->lParam = *((LPARAM *)str - 1);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001909 lstrcpynA( (LPSTR)(p16->lParam), str, p16->wParam );
Alexandre Julliard3051b641996-07-05 17:14:13 +00001910 SEGPTR_FREE( (LPARAM *)str - 1 );
1911 }
1912 break;
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001913 case WM_MDICREATE:
1914 {
Alexandre Julliard889f7421997-04-15 17:19:52 +00001915 MDICREATESTRUCT16 *cs = (MDICREATESTRUCT16*)PTR_SEG_TO_LIN(p16->lParam);
Alexandre Julliard18f92e71996-07-17 20:02:21 +00001916 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->szTitle) );
1917 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->szClass) );
1918 SEGPTR_FREE( cs );
1919 }
1920 break;
Alexandre Julliard491502b1997-11-01 19:08:16 +00001921 case WM_MDIGETACTIVE:
Alexandre Julliarda3960291999-02-26 11:11:13 +00001922 if (lParam) *(BOOL *)lParam = (BOOL16)HIWORD(p16->lResult);
1923 p16->lResult = (HWND)LOWORD(p16->lResult);
Alexandre Julliard491502b1997-11-01 19:08:16 +00001924 break;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001925 case WM_NCCALCSIZE:
1926 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001927 NCCALCSIZE_PARAMS *nc32;
Alexandre Julliard889f7421997-04-15 17:19:52 +00001928 NCCALCSIZE_PARAMS16 *nc = (NCCALCSIZE_PARAMS16 *)PTR_SEG_TO_LIN(p16->lParam);
1929 p16->lParam = *(LPARAM *)(nc + 1);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001930 nc32 = (NCCALCSIZE_PARAMS *)(p16->lParam);
Alexandre Julliard3051b641996-07-05 17:14:13 +00001931 CONV_RECT16TO32( &nc->rgrc[0], &nc32->rgrc[0] );
Alexandre Julliard889f7421997-04-15 17:19:52 +00001932 if (p16->wParam)
Alexandre Julliard3051b641996-07-05 17:14:13 +00001933 {
1934 CONV_RECT16TO32( &nc->rgrc[1], &nc32->rgrc[1] );
1935 CONV_RECT16TO32( &nc->rgrc[2], &nc32->rgrc[2] );
1936 STRUCT32_WINDOWPOS16to32( (WINDOWPOS16 *)PTR_SEG_TO_LIN(nc->lppos),
1937 nc32->lppos );
1938 SEGPTR_FREE( PTR_SEG_TO_LIN(nc->lppos) );
1939 }
1940 SEGPTR_FREE(nc);
1941 }
1942 break;
1943 case WM_NCCREATE:
1944 case WM_CREATE:
1945 {
Alexandre Julliard889f7421997-04-15 17:19:52 +00001946 CREATESTRUCT16 *cs = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(p16->lParam);
Alexandre Julliard3051b641996-07-05 17:14:13 +00001947 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->lpszName) );
1948 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->lpszClass) );
1949 SEGPTR_FREE( cs );
1950 }
1951 break;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001952 case WM_WINDOWPOSCHANGING:
1953 case WM_WINDOWPOSCHANGED:
1954 {
Alexandre Julliard889f7421997-04-15 17:19:52 +00001955 WINDOWPOS16 *wp = (WINDOWPOS16 *)PTR_SEG_TO_LIN(p16->lParam);
1956 p16->lParam = *(LPARAM *)(wp + 1);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001957 STRUCT32_WINDOWPOS16to32( wp, (WINDOWPOS *)p16->lParam );
Alexandre Julliard3051b641996-07-05 17:14:13 +00001958 SEGPTR_FREE(wp);
1959 }
1960 break;
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001961 case WM_NOTIFY:
1962 UnMapLS(p16->lParam);
1963 break;
Rein Klazescb505621998-11-07 12:24:21 +00001964 case WM_GETDLGCODE:
1965 if (p16->lParam)
1966 {
1967 LPMSG16 msg16 = (LPMSG16)PTR_SEG_TO_LIN(p16->lParam);
1968 MSGPARAM16 msgp16;
1969 msgp16.wParam=msg16->wParam;
1970 msgp16.lParam=msg16->lParam;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001971 WINPROC_UnmapMsg32ATo16(((LPMSG)lParam)->hwnd, ((LPMSG)lParam)->message,
1972 ((LPMSG)lParam)->wParam, ((LPMSG)lParam)->lParam,
Rein Klazescb505621998-11-07 12:24:21 +00001973 &msgp16 );
1974 SEGPTR_FREE(msg16);
1975 }
1976 break;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001977 }
1978}
1979
1980
1981/**********************************************************************
1982 * WINPROC_MapMsg32WTo16
1983 *
1984 * Map a message from 32-bit Unicode to 16-bit.
1985 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1986 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001987INT WINPROC_MapMsg32WTo16( HWND hwnd, UINT msg32, WPARAM wParam32,
Alexandre Julliard491502b1997-11-01 19:08:16 +00001988 UINT16 *pmsg16, WPARAM16 *pwparam16,
1989 LPARAM *plparam )
Alexandre Julliard3051b641996-07-05 17:14:13 +00001990{
1991 switch(msg32)
1992 {
Alexandre Julliarda3960291999-02-26 11:11:13 +00001993 case LB_ADDSTRING:
1994 case LB_FINDSTRING:
1995 case LB_FINDSTRINGEXACT:
1996 case LB_INSERTSTRING:
1997 case LB_SELECTSTRING:
1998 case LB_DIR:
1999 case LB_ADDFILE:
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002000 {
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00002001 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002002 if (!str) return -1;
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002003 *pwparam16 = (WPARAM16)LOWORD(wParam32);
2004 *plparam = (LPARAM)SEGPTR_GET(str);
2005 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00002006 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
Alexandre Julliardda0cfb31996-12-01 17:17:47 +00002007 return 1;
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002008
Alexandre Julliarda3960291999-02-26 11:11:13 +00002009 case CB_ADDSTRING:
2010 case CB_FINDSTRING:
2011 case CB_FINDSTRINGEXACT:
2012 case CB_INSERTSTRING:
2013 case CB_SELECTSTRING:
2014 case CB_DIR:
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002015 {
2016 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
2017 if (!str) return -1;
2018 *pwparam16 = (WPARAM16)LOWORD(wParam32);
2019 *plparam = (LPARAM)SEGPTR_GET(str);
2020 }
Alexandre Julliarda3960291999-02-26 11:11:13 +00002021 *pmsg16 = (UINT16)msg32 + (CB_ADDSTRING16 - CB_ADDSTRING);
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00002022 return 1;
2023
Alexandre Julliard3051b641996-07-05 17:14:13 +00002024 case WM_NCCREATE:
2025 case WM_CREATE:
2026 {
2027 CREATESTRUCT16 *cs;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002028 CREATESTRUCTW *cs32 = (CREATESTRUCTW *)*plparam;
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00002029 LPSTR name, cls;
Alexandre Julliard3051b641996-07-05 17:14:13 +00002030
2031 if (!(cs = SEGPTR_NEW(CREATESTRUCT16))) return -1;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002032 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs32, cs );
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00002033 name = SEGPTR_STRDUP_WtoA( cs32->lpszName );
2034 cls = SEGPTR_STRDUP_WtoA( cs32->lpszClass );
2035 cs->lpszName = SEGPTR_GET(name);
2036 cs->lpszClass = SEGPTR_GET(cls);
Alexandre Julliard3051b641996-07-05 17:14:13 +00002037 *pmsg16 = (UINT16)msg32;
2038 *pwparam16 = (WPARAM16)LOWORD(wParam32);
2039 *plparam = (LPARAM)SEGPTR_GET(cs);
2040 }
2041 return 1;
Alexandre Julliard18f92e71996-07-17 20:02:21 +00002042 case WM_MDICREATE:
2043 {
2044 MDICREATESTRUCT16 *cs;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002045 MDICREATESTRUCTW *cs32 = (MDICREATESTRUCTW *)*plparam;
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00002046 LPSTR name, cls;
Alexandre Julliard18f92e71996-07-17 20:02:21 +00002047
2048 if (!(cs = SEGPTR_NEW(MDICREATESTRUCT16))) return -1;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002049 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs32, cs );
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00002050 name = SEGPTR_STRDUP_WtoA( cs32->szTitle );
2051 cls = SEGPTR_STRDUP_WtoA( cs32->szClass );
2052 cs->szTitle = SEGPTR_GET(name);
2053 cs->szClass = SEGPTR_GET(cls);
Alexandre Julliard18f92e71996-07-17 20:02:21 +00002054 *pmsg16 = (UINT16)msg32;
2055 *pwparam16 = (WPARAM16)LOWORD(wParam32);
2056 *plparam = (LPARAM)SEGPTR_GET(cs);
2057 }
2058 return 1;
Alexandre Julliard3051b641996-07-05 17:14:13 +00002059 case WM_SETTEXT:
2060 {
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00002061 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
Alexandre Julliard3051b641996-07-05 17:14:13 +00002062 if (!str) return -1;
Alexandre Julliard3051b641996-07-05 17:14:13 +00002063 *pmsg16 = (UINT16)msg32;
2064 *pwparam16 = (WPARAM16)LOWORD(wParam32);
2065 *plparam = (LPARAM)SEGPTR_GET(str);
2066 }
2067 return 1;
2068 default: /* No Unicode translation needed */
Alexandre Julliard491502b1997-11-01 19:08:16 +00002069 return WINPROC_MapMsg32ATo16( hwnd, msg32, wParam32, pmsg16,
Alexandre Julliard3051b641996-07-05 17:14:13 +00002070 pwparam16, plparam );
2071 }
2072}
2073
2074
2075/**********************************************************************
2076 * WINPROC_UnmapMsg32WTo16
2077 *
2078 * Unmap a message that was mapped from 32-bit Unicode to 16-bit.
2079 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002080void WINPROC_UnmapMsg32WTo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
Alexandre Julliard491502b1997-11-01 19:08:16 +00002081 MSGPARAM16* p16 )
Alexandre Julliard3051b641996-07-05 17:14:13 +00002082{
2083 switch(msg)
2084 {
2085 case WM_GETTEXT:
2086 {
Alexandre Julliard889f7421997-04-15 17:19:52 +00002087 LPSTR str = (LPSTR)PTR_SEG_TO_LIN(p16->lParam);
2088 p16->lParam = *((LPARAM *)str - 1);
2089 lstrcpyAtoW( (LPWSTR)(p16->lParam), str );
Alexandre Julliard3051b641996-07-05 17:14:13 +00002090 SEGPTR_FREE( (LPARAM *)str - 1 );
2091 }
2092 break;
2093 default:
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +00002094 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, p16 );
Alexandre Julliard3051b641996-07-05 17:14:13 +00002095 break;
2096 }
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00002097}
2098
2099
2100/**********************************************************************
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002101 * WINPROC_CallProc32ATo32W
2102 *
2103 * Call a window procedure, translating args from Ansi to Unicode.
2104 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002105static LRESULT WINPROC_CallProc32ATo32W( WNDPROC func, HWND hwnd,
2106 UINT msg, WPARAM wParam,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002107 LPARAM lParam )
2108{
2109 LRESULT result;
2110
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +00002111 if (WINPROC_MapMsg32ATo32W( hwnd, msg, wParam, &lParam ) == -1) return 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002112 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +00002113 WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam );
Alexandre Julliard3051b641996-07-05 17:14:13 +00002114 return result;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002115}
2116
2117
2118/**********************************************************************
2119 * WINPROC_CallProc32WTo32A
2120 *
2121 * Call a window procedure, translating args from Unicode to Ansi.
2122 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002123static LRESULT WINPROC_CallProc32WTo32A( WNDPROC func, HWND hwnd,
2124 UINT msg, WPARAM wParam,
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002125 LPARAM lParam )
2126{
2127 LRESULT result;
2128
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +00002129 if (WINPROC_MapMsg32WTo32A( hwnd, msg, wParam, &lParam ) == -1) return 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002130 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +00002131 WINPROC_UnmapMsg32WTo32A( hwnd, msg, wParam, lParam );
Alexandre Julliard3051b641996-07-05 17:14:13 +00002132 return result;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002133}
2134
2135
2136/**********************************************************************
2137 * WINPROC_CallProc16To32A
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002138 *
2139 * Call a 32-bit window procedure, translating the 16-bit args.
2140 */
Alexandre Julliard3051b641996-07-05 17:14:13 +00002141LRESULT WINPROC_CallProc16To32A( HWND16 hwnd, UINT16 msg,
2142 WPARAM16 wParam, LPARAM lParam,
Alexandre Julliarda3960291999-02-26 11:11:13 +00002143 WNDPROC func )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002144{
2145 LRESULT result;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002146 UINT msg32;
2147 WPARAM wParam32;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002148
Alexandre Julliard3051b641996-07-05 17:14:13 +00002149 if (WINPROC_MapMsg16To32A( msg, wParam, &msg32, &wParam32, &lParam ) == -1)
2150 return 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002151 result = WINPROC_CallWndProc( func, hwnd, msg32, wParam32, lParam );
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +00002152 return WINPROC_UnmapMsg16To32A( hwnd, msg32, wParam32, lParam, result );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002153}
2154
2155
2156/**********************************************************************
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002157 * WINPROC_CallProc16To32W
2158 *
2159 * Call a 32-bit window procedure, translating the 16-bit args.
2160 */
Alexandre Julliard3051b641996-07-05 17:14:13 +00002161LRESULT WINPROC_CallProc16To32W( HWND16 hwnd, UINT16 msg,
2162 WPARAM16 wParam, LPARAM lParam,
Alexandre Julliarda3960291999-02-26 11:11:13 +00002163 WNDPROC func )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002164{
Alexandre Julliard3051b641996-07-05 17:14:13 +00002165 LRESULT result;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002166 UINT msg32;
2167 WPARAM wParam32;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002168
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +00002169 if (WINPROC_MapMsg16To32W( hwnd, msg, wParam, &msg32, &wParam32, &lParam ) == -1)
Alexandre Julliard3051b641996-07-05 17:14:13 +00002170 return 0;
Francois Boisvertd96bc151999-04-02 10:34:43 +00002171
Alexandre Julliarda3960291999-02-26 11:11:13 +00002172 result = WINPROC_CallWndProc( func, hwnd, msg32, wParam32, lParam );
Francois Boisvertd96bc151999-04-02 10:34:43 +00002173
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +00002174 return WINPROC_UnmapMsg16To32W( hwnd, msg32, wParam32, lParam, result );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002175}
2176
2177
2178/**********************************************************************
2179 * WINPROC_CallProc32ATo16
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002180 *
2181 * Call a 16-bit window procedure, translating the 32-bit args.
2182 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002183static LRESULT WINAPI WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd,
2184 UINT msg, WPARAM wParam,
Alexandre Julliard77b99181997-09-14 17:17:23 +00002185 LPARAM lParam )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002186{
Alexandre Julliard3051b641996-07-05 17:14:13 +00002187 UINT16 msg16;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002188 MSGPARAM16 mp16;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002189
Alexandre Julliard889f7421997-04-15 17:19:52 +00002190 mp16.lParam = lParam;
Alexandre Julliard491502b1997-11-01 19:08:16 +00002191 if (WINPROC_MapMsg32ATo16( hwnd, msg, wParam,
2192 &msg16, &mp16.wParam, &mp16.lParam ) == -1)
Alexandre Julliard3051b641996-07-05 17:14:13 +00002193 return 0;
Alexandre Julliard491502b1997-11-01 19:08:16 +00002194 mp16.lResult = Callbacks->CallWndProc( func, hwnd, msg16,
2195 mp16.wParam, mp16.lParam );
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +00002196 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, &mp16 );
Alexandre Julliard889f7421997-04-15 17:19:52 +00002197 return mp16.lResult;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002198}
2199
2200
2201/**********************************************************************
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002202 * WINPROC_CallProc32WTo16
2203 *
2204 * Call a 16-bit window procedure, translating the 32-bit args.
2205 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002206static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
2207 UINT msg, WPARAM wParam,
Alexandre Julliard77b99181997-09-14 17:17:23 +00002208 LPARAM lParam )
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002209{
Alexandre Julliard3051b641996-07-05 17:14:13 +00002210 UINT16 msg16;
Alexandre Julliard889f7421997-04-15 17:19:52 +00002211 MSGPARAM16 mp16;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002212
Alexandre Julliard889f7421997-04-15 17:19:52 +00002213 mp16.lParam = lParam;
Alexandre Julliard491502b1997-11-01 19:08:16 +00002214 if (WINPROC_MapMsg32WTo16( hwnd, msg, wParam, &msg16, &mp16.wParam,
2215 &mp16.lParam ) == -1)
Alexandre Julliard3051b641996-07-05 17:14:13 +00002216 return 0;
Alexandre Julliard491502b1997-11-01 19:08:16 +00002217 mp16.lResult = Callbacks->CallWndProc( func, hwnd, msg16,
2218 mp16.wParam, mp16.lParam );
Juergen Schmiedfdf6aa41998-11-08 16:28:49 +00002219 WINPROC_UnmapMsg32WTo16( hwnd, msg, wParam, lParam, &mp16 );
Alexandre Julliard889f7421997-04-15 17:19:52 +00002220 return mp16.lResult;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002221}
2222
2223
2224/**********************************************************************
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002225 * CallWindowProc16 (USER.122)
2226 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +00002227LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
2228 WPARAM16 wParam, LPARAM lParam )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002229{
Alexandre Julliard3051b641996-07-05 17:14:13 +00002230 WINDOWPROC *proc = WINPROC_GetPtr( func );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002231
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00002232 if (!proc)
Alexandre Julliard491502b1997-11-01 19:08:16 +00002233 return Callbacks->CallWndProc( func, hwnd, msg, wParam, lParam );
Alexandre Julliard3db94ef1997-09-28 17:43:24 +00002234
Alexandre Julliard3051b641996-07-05 17:14:13 +00002235#if testing
Alexandre Julliard3db94ef1997-09-28 17:43:24 +00002236 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_16 );
Alexandre Julliard491502b1997-11-01 19:08:16 +00002237 return Callbacks->CallWndProc( func, hwnd, msg, wParam, lParam );
Alexandre Julliard3051b641996-07-05 17:14:13 +00002238#endif
2239
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00002240 switch(proc->type)
2241 {
2242 case WIN_PROC_16:
Alexandre Julliard3051b641996-07-05 17:14:13 +00002243 if (!proc->thunk.t_from32.proc) return 0;
Alexandre Julliard491502b1997-11-01 19:08:16 +00002244 return Callbacks->CallWndProc( proc->thunk.t_from32.proc,
2245 hwnd, msg, wParam, lParam );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002246 case WIN_PROC_32A:
Alexandre Julliard3051b641996-07-05 17:14:13 +00002247 if (!proc->thunk.t_from16.proc) return 0;
2248 return WINPROC_CallProc16To32A( hwnd, msg, wParam, lParam,
2249 proc->thunk.t_from16.proc );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002250 case WIN_PROC_32W:
Alexandre Julliard3051b641996-07-05 17:14:13 +00002251 if (!proc->thunk.t_from16.proc) return 0;
2252 return WINPROC_CallProc16To32W( hwnd, msg, wParam, lParam,
2253 proc->thunk.t_from16.proc );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002254 default:
Alexandre Julliard06c275a1999-05-02 14:32:27 +00002255 WARN_(relay)("Invalid proc %p\n", proc );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002256 return 0;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002257 }
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002258}
2259
2260
2261/**********************************************************************
Alexandre Julliard767e6f61998-08-09 12:47:43 +00002262 * CallWindowProc32A (USER32.18)
2263 *
2264 * The CallWindowProc() function invokes the windows procedure _func_,
2265 * with _hwnd_ as the target window, the message specified by _msg_, and
2266 * the message parameters _wParam_ and _lParam_.
2267 *
2268 * Some kinds of argument conversion may be done, I'm not sure what.
2269 *
2270 * CallWindowProc() may be used for windows subclassing. Use
2271 * SetWindowLong() to set a new windows procedure for windows of the
2272 * subclass, and handle subclassed messages in the new windows
2273 * procedure. The new windows procedure may then use CallWindowProc()
2274 * with _func_ set to the parent class's windows procedure to dispatch
2275 * the message to the superclass.
2276 *
2277 * RETURNS
2278 *
2279 * The return value is message dependent.
2280 *
2281 * CONFORMANCE
2282 *
2283 * ECMA-234, Win32
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002284 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002285LRESULT WINAPI CallWindowProcA(
2286 WNDPROC func, /* window procedure */
2287 HWND hwnd, /* target window */
2288 UINT msg, /* message */
2289 WPARAM wParam, /* message dependent parameter */
Alexandre Julliard767e6f61998-08-09 12:47:43 +00002290 LPARAM lParam /* message dependent parameter */
2291) {
Alexandre Julliard3051b641996-07-05 17:14:13 +00002292 WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002293
Alexandre Julliarda3960291999-02-26 11:11:13 +00002294 if (!proc) return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00002295
Alexandre Julliard3051b641996-07-05 17:14:13 +00002296#if testing
2297 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_32A );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002298 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
Alexandre Julliard3051b641996-07-05 17:14:13 +00002299#endif
2300
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00002301 switch(proc->type)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002302 {
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002303 case WIN_PROC_16:
Alexandre Julliard3051b641996-07-05 17:14:13 +00002304 if (!proc->thunk.t_from32.proc) return 0;
2305 return WINPROC_CallProc32ATo16( proc->thunk.t_from32.proc,
2306 hwnd, msg, wParam, lParam );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002307 case WIN_PROC_32A:
Alexandre Julliard3051b641996-07-05 17:14:13 +00002308 if (!proc->thunk.t_from16.proc) return 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002309 return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
Alexandre Julliard77b99181997-09-14 17:17:23 +00002310 hwnd, msg, wParam, lParam );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002311 case WIN_PROC_32W:
Alexandre Julliard3051b641996-07-05 17:14:13 +00002312 if (!proc->thunk.t_from16.proc) return 0;
2313 return WINPROC_CallProc32ATo32W( proc->thunk.t_from16.proc,
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00002314 hwnd, msg, wParam, lParam );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002315 default:
Alexandre Julliard06c275a1999-05-02 14:32:27 +00002316 WARN_(relay)("Invalid proc %p\n", proc );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002317 return 0;
2318 }
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002319}
2320
2321
2322/**********************************************************************
Alexandre Julliardc7c217b1998-04-13 12:21:30 +00002323 * CallWindowProc32W (USER32.19)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002324 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00002325LRESULT WINAPI CallWindowProcW( WNDPROC func, HWND hwnd, UINT msg,
2326 WPARAM wParam, LPARAM lParam )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002327{
Alexandre Julliard3051b641996-07-05 17:14:13 +00002328 WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002329
Alexandre Julliarda3960291999-02-26 11:11:13 +00002330 if (!proc) return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00002331
Alexandre Julliard3051b641996-07-05 17:14:13 +00002332#if testing
2333 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_32W );
Alexandre Julliarda3960291999-02-26 11:11:13 +00002334 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
Alexandre Julliard3051b641996-07-05 17:14:13 +00002335#endif
2336
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00002337 switch(proc->type)
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002338 {
2339 case WIN_PROC_16:
Alexandre Julliard3051b641996-07-05 17:14:13 +00002340 if (!proc->thunk.t_from32.proc) return 0;
2341 return WINPROC_CallProc32WTo16( proc->thunk.t_from32.proc,
2342 hwnd, msg, wParam, lParam );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002343 case WIN_PROC_32A:
Alexandre Julliard3051b641996-07-05 17:14:13 +00002344 if (!proc->thunk.t_from16.proc) return 0;
2345 return WINPROC_CallProc32WTo32A( proc->thunk.t_from16.proc,
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00002346 hwnd, msg, wParam, lParam );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002347 case WIN_PROC_32W:
Alexandre Julliard3051b641996-07-05 17:14:13 +00002348 if (!proc->thunk.t_from16.proc) return 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +00002349 return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
Alexandre Julliard77b99181997-09-14 17:17:23 +00002350 hwnd, msg, wParam, lParam );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002351 default:
Alexandre Julliard06c275a1999-05-02 14:32:27 +00002352 WARN_(relay)("Invalid proc %p\n", proc );
Alexandre Julliard2d93d001996-05-21 15:01:41 +00002353 return 0;
2354 }
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00002355}