2 * Window procedure callbacks
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1996 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
33 #include "user_private.h"
34 #include "wine/unicode.h"
35 #include "wine/debug.h"
37 WINE_DECLARE_DEBUG_CHANNEL(msg);
38 WINE_DECLARE_DEBUG_CHANNEL(relay);
39 WINE_DEFAULT_DEBUG_CHANNEL(win);
41 typedef struct tagWINDOWPROC
43 WNDPROC procA; /* ASCII window proc */
44 WNDPROC procW; /* Unicode window proc */
47 #define MAX_WINPROCS 4096
48 #define BUILTIN_WINPROCS 9 /* first BUILTIN_WINPROCS entries are reserved for builtin procs */
49 #define MAX_WINPROC_RECURSION 64
50 #define WINPROC_PROC16 ((WINDOWPROC *)1) /* placeholder for 16-bit window procs */
52 static LRESULT WINAPI ButtonWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
53 static LRESULT WINAPI ButtonWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
54 static LRESULT WINAPI ComboWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
55 static LRESULT WINAPI ComboWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
56 LRESULT WINAPI EditWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
57 static LRESULT WINAPI EditWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
58 static LRESULT WINAPI ListBoxWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
59 static LRESULT WINAPI ListBoxWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
60 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
61 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
62 static LRESULT WINAPI ScrollBarWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
63 static LRESULT WINAPI ScrollBarWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
64 static LRESULT WINAPI StaticWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
65 static LRESULT WINAPI StaticWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
67 static WINDOWPROC winproc_array[MAX_WINPROCS] =
69 { ButtonWndProcA, ButtonWndProcW }, /* WINPROC_BUTTON */
70 { ComboWndProcA, ComboWndProcW }, /* WINPROC_COMBO */
71 { DefDlgProcA, DefDlgProcW }, /* WINPROC_DIALOG */
72 { EditWndProcA, EditWndProcW }, /* WINPROC_EDIT */
73 { ListBoxWndProcA, ListBoxWndProcW }, /* WINPROC_LISTBOX */
74 { MDIClientWndProcA, MDIClientWndProcW }, /* WINPROC_MDICLIENT */
75 { ScrollBarWndProcA, ScrollBarWndProcW }, /* WINPROC_SCROLLBAR */
76 { StaticWndProcA, StaticWndProcW }, /* WINPROC_STATIC */
79 static UINT builtin_used = NB_BUILTIN_WINPROCS;
80 static UINT winproc_used = BUILTIN_WINPROCS;
82 static CRITICAL_SECTION winproc_cs;
83 static CRITICAL_SECTION_DEBUG critsect_debug =
86 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
87 0, 0, { (DWORD_PTR)(__FILE__ ": winproc_cs") }
89 static CRITICAL_SECTION winproc_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
91 static inline void *get_buffer( void *static_buffer, size_t size, size_t need )
93 if (size >= need) return static_buffer;
94 return HeapAlloc( GetProcessHeap(), 0, need );
97 static inline void free_buffer( void *static_buffer, void *buffer )
99 if (buffer != static_buffer) HeapFree( GetProcessHeap(), 0, buffer );
102 /* find an existing winproc for a given function and type */
103 /* FIXME: probably should do something more clever than a linear search */
104 static inline WINDOWPROC *find_winproc( WNDPROC funcA, WNDPROC funcW )
108 for (i = 0; i < builtin_used; i++)
110 /* match either proc, some apps confuse A and W */
111 if (funcA && winproc_array[i].procA != funcA && winproc_array[i].procW != funcA) continue;
112 if (funcW && winproc_array[i].procA != funcW && winproc_array[i].procW != funcW) continue;
113 return &winproc_array[i];
115 for (i = BUILTIN_WINPROCS; i < winproc_used; i++)
117 if (funcA && winproc_array[i].procA != funcA) continue;
118 if (funcW && winproc_array[i].procW != funcW) continue;
119 return &winproc_array[i];
124 /* return the window proc for a given handle, or NULL for an invalid handle,
125 * or WINPROC_PROC16 for a handle to a 16-bit proc. */
126 static inline WINDOWPROC *handle_to_proc( WNDPROC handle )
128 UINT index = LOWORD(handle);
129 if ((ULONG_PTR)handle >> 16 != WINPROC_HANDLE) return NULL;
130 if (index >= MAX_WINPROCS) return WINPROC_PROC16;
131 if (index >= winproc_used) return NULL;
132 return &winproc_array[index];
135 /* create a handle for a given window proc */
136 static inline WNDPROC proc_to_handle( WINDOWPROC *proc )
138 return (WNDPROC)(ULONG_PTR)((proc - winproc_array) | (WINPROC_HANDLE << 16));
141 /* allocate and initialize a new winproc */
142 static inline WINDOWPROC *alloc_winproc( WNDPROC funcA, WNDPROC funcW )
146 /* check if the function is already a win proc */
147 if (funcA && (proc = handle_to_proc( funcA ))) return proc;
148 if (funcW && (proc = handle_to_proc( funcW ))) return proc;
149 if (!funcA && !funcW) return NULL;
151 EnterCriticalSection( &winproc_cs );
153 /* check if we already have a winproc for that function */
154 if (!(proc = find_winproc( funcA, funcW )))
158 assert( builtin_used < BUILTIN_WINPROCS );
159 proc = &winproc_array[builtin_used++];
162 TRACE( "allocated %p for builtin %p/%p (%d/%d used)\n",
163 proc_to_handle(proc), funcA, funcW, builtin_used, BUILTIN_WINPROCS );
165 else if (winproc_used < MAX_WINPROCS)
167 proc = &winproc_array[winproc_used++];
170 TRACE( "allocated %p for %c %p (%d/%d used)\n",
171 proc_to_handle(proc), funcA ? 'A' : 'W', funcA ? funcA : funcW,
172 winproc_used, MAX_WINPROCS );
174 else FIXME( "too many winprocs, cannot allocate one for %p/%p\n", funcA, funcW );
176 else TRACE( "reusing %p for %p/%p\n", proc_to_handle(proc), funcA, funcW );
178 LeaveCriticalSection( &winproc_cs );
183 /* Some window procedures modify register they shouldn't, or are not
184 * properly declared stdcall; so we need a small assembly wrapper to
186 extern LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
187 WPARAM wParam, LPARAM lParam );
188 __ASM_GLOBAL_FUNC( WINPROC_wrapper,
190 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
191 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
193 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
195 __ASM_CFI(".cfi_rel_offset %edi,-4\n\t")
197 __ASM_CFI(".cfi_rel_offset %esi,-8\n\t")
199 __ASM_CFI(".cfi_rel_offset %ebx,-12\n\t")
205 "movl 8(%ebp),%eax\n\t"
207 "leal -12(%ebp),%esp\n\t"
209 __ASM_CFI(".cfi_same_value %ebx\n\t")
211 __ASM_CFI(".cfi_same_value %esi\n\t")
213 __ASM_CFI(".cfi_same_value %edi\n\t")
215 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
216 __ASM_CFI(".cfi_same_value %ebp\n\t")
219 static inline LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
220 WPARAM wParam, LPARAM lParam )
222 return proc( hwnd, msg, wParam, lParam );
224 #endif /* __i386__ */
226 static WPARAM map_wparam_char_WtoA( WPARAM wParam, DWORD len )
231 RtlUnicodeToMultiByteN( (LPSTR)ch, len, &len, &wch, sizeof(wch) );
233 return MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(wParam) );
235 return MAKEWPARAM( ch[0], HIWORD(wParam) );
238 /* call a 32-bit window procedure */
239 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp, LRESULT *result, void *arg )
245 hwnd = WIN_GetFullHandle( hwnd );
247 DPRINTF( "%04x:Call window proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
248 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wp, lp );
250 *result = WINPROC_wrapper( proc, hwnd, msg, wp, lp );
253 DPRINTF( "%04x:Ret window proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx) retval=%08lx\n",
254 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wp, lp, *result );
258 /* call a 32-bit dialog procedure */
259 static LRESULT call_dialog_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp, LRESULT *result, void *arg )
266 hwnd = WIN_GetFullHandle( hwnd );
268 DPRINTF( "%04x:Call dialog proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
269 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wp, lp );
271 ret = WINPROC_wrapper( proc, hwnd, msg, wp, lp );
272 *result = GetWindowLongPtrW( hwnd, DWLP_MSGRESULT );
275 DPRINTF( "%04x:Ret dialog proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx) retval=%08lx result=%08lx\n",
276 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wp, lp, ret, *result );
281 /**********************************************************************
284 * Get a window procedure pointer that can be passed to the Windows program.
286 WNDPROC WINPROC_GetProc( WNDPROC proc, BOOL unicode )
288 WINDOWPROC *ptr = handle_to_proc( proc );
290 if (!ptr || ptr == WINPROC_PROC16) return proc;
293 if (ptr->procW) return ptr->procW;
298 if (ptr->procA) return ptr->procA;
304 /**********************************************************************
307 * Allocate a window procedure for a window or class.
309 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
310 * lot of windows, it will usually only have a limited number of window procedures, so the
311 * array won't grow too large, and this way we avoid the need to track allocations per window.
313 WNDPROC WINPROC_AllocProc( WNDPROC funcA, WNDPROC funcW )
317 if (!(proc = alloc_winproc( funcA, funcW ))) return NULL;
318 if (proc == WINPROC_PROC16) return funcA ? funcA : funcW;
319 return proc_to_handle( proc );
323 /**********************************************************************
326 * Return the window procedure type, or the default value if not a winproc handle.
328 BOOL WINPROC_IsUnicode( WNDPROC proc, BOOL def_val )
330 WINDOWPROC *ptr = handle_to_proc( proc );
332 if (!ptr) return def_val;
333 if (ptr == WINPROC_PROC16) return FALSE; /* 16-bit is always A */
334 if (ptr->procA && ptr->procW) return def_val; /* can be both */
335 return (ptr->procW != NULL);
339 /**********************************************************************
340 * WINPROC_TestLBForStr
342 * Return TRUE if the lparam is a string
344 static inline BOOL WINPROC_TestLBForStr( HWND hwnd, UINT msg )
346 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
347 if (msg <= CB_MSGMAX)
348 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
350 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
355 /**********************************************************************
356 * WINPROC_CallProcAtoW
358 * Call a window procedure, translating args from Ansi to Unicode.
360 LRESULT WINPROC_CallProcAtoW( winproc_callback_t callback, HWND hwnd, UINT msg, WPARAM wParam,
361 LPARAM lParam, LRESULT *result, void *arg, enum wm_char_mapping mapping )
365 TRACE_(msg)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
366 hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
373 WCHAR *ptr, buffer[512];
374 CREATESTRUCTA *csA = (CREATESTRUCTA *)lParam;
375 CREATESTRUCTW csW = *(CREATESTRUCTW *)csA;
376 MDICREATESTRUCTW mdi_cs;
377 DWORD name_lenA = 0, name_lenW = 0, class_lenA = 0, class_lenW = 0;
379 if (!IS_INTRESOURCE(csA->lpszClass))
381 class_lenA = strlen(csA->lpszClass) + 1;
382 RtlMultiByteToUnicodeSize( &class_lenW, csA->lpszClass, class_lenA );
384 if (!IS_INTRESOURCE(csA->lpszName))
386 name_lenA = strlen(csA->lpszName) + 1;
387 RtlMultiByteToUnicodeSize( &name_lenW, csA->lpszName, name_lenA );
390 if (!(ptr = get_buffer( buffer, sizeof(buffer), class_lenW + name_lenW ))) break;
395 RtlMultiByteToUnicodeN( ptr, class_lenW, NULL, csA->lpszClass, class_lenA );
399 csW.lpszName = ptr + class_lenW/sizeof(WCHAR);
400 RtlMultiByteToUnicodeN( ptr + class_lenW/sizeof(WCHAR), name_lenW, NULL,
401 csA->lpszName, name_lenA );
404 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
406 mdi_cs = *(MDICREATESTRUCTW *)csA->lpCreateParams;
407 mdi_cs.szTitle = csW.lpszName;
408 mdi_cs.szClass = csW.lpszClass;
409 csW.lpCreateParams = &mdi_cs;
412 ret = callback( hwnd, msg, wParam, (LPARAM)&csW, result, arg );
413 free_buffer( buffer, ptr );
419 WCHAR *ptr, buffer[512];
420 DWORD title_lenA = 0, title_lenW = 0, class_lenA = 0, class_lenW = 0;
421 MDICREATESTRUCTA *csA = (MDICREATESTRUCTA *)lParam;
422 MDICREATESTRUCTW csW;
424 memcpy( &csW, csA, sizeof(csW) );
426 if (!IS_INTRESOURCE(csA->szTitle))
428 title_lenA = strlen(csA->szTitle) + 1;
429 RtlMultiByteToUnicodeSize( &title_lenW, csA->szTitle, title_lenA );
431 if (!IS_INTRESOURCE(csA->szClass))
433 class_lenA = strlen(csA->szClass) + 1;
434 RtlMultiByteToUnicodeSize( &class_lenW, csA->szClass, class_lenA );
437 if (!(ptr = get_buffer( buffer, sizeof(buffer), title_lenW + class_lenW ))) break;
442 RtlMultiByteToUnicodeN( ptr, title_lenW, NULL, csA->szTitle, title_lenA );
446 csW.szClass = ptr + title_lenW/sizeof(WCHAR);
447 RtlMultiByteToUnicodeN( ptr + title_lenW/sizeof(WCHAR), class_lenW, NULL,
448 csA->szClass, class_lenA );
450 ret = callback( hwnd, msg, wParam, (LPARAM)&csW, result, arg );
451 free_buffer( buffer, ptr );
456 case WM_ASKCBFORMATNAME:
458 WCHAR *ptr, buffer[512];
459 LPSTR str = (LPSTR)lParam;
460 DWORD len = wParam * sizeof(WCHAR);
462 if (!(ptr = get_buffer( buffer, sizeof(buffer), len ))) break;
463 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
468 RtlUnicodeToMultiByteN( str, wParam - 1, &len, ptr, strlenW(ptr) * sizeof(WCHAR) );
472 free_buffer( buffer, ptr );
477 case LB_INSERTSTRING:
479 case LB_FINDSTRINGEXACT:
480 case LB_SELECTSTRING:
482 case CB_INSERTSTRING:
484 case CB_FINDSTRINGEXACT:
485 case CB_SELECTSTRING:
486 if (!lParam || !WINPROC_TestLBForStr( hwnd, msg ))
488 ret = callback( hwnd, msg, wParam, lParam, result, arg );
493 case WM_WININICHANGE:
494 case WM_DEVMODECHANGE:
499 if (!lParam) ret = callback( hwnd, msg, wParam, lParam, result, arg );
502 WCHAR *ptr, buffer[512];
503 LPCSTR strA = (LPCSTR)lParam;
504 DWORD lenW, lenA = strlen(strA) + 1;
506 RtlMultiByteToUnicodeSize( &lenW, strA, lenA );
507 if ((ptr = get_buffer( buffer, sizeof(buffer), lenW )))
509 RtlMultiByteToUnicodeN( ptr, lenW, NULL, strA, lenA );
510 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
511 free_buffer( buffer, ptr );
518 if (lParam && WINPROC_TestLBForStr( hwnd, msg ))
520 WCHAR buffer[512]; /* FIXME: fixed sized buffer */
522 ret = callback( hwnd, msg, wParam, (LPARAM)buffer, result, arg );
526 RtlUnicodeToMultiByteN( (LPSTR)lParam, ~0u, &len,
527 buffer, (strlenW(buffer) + 1) * sizeof(WCHAR) );
531 else ret = callback( hwnd, msg, wParam, lParam, result, arg );
536 WCHAR *ptr, buffer[512];
537 WORD len = *(WORD *)lParam;
539 if (!(ptr = get_buffer( buffer, sizeof(buffer), len * sizeof(WCHAR) ))) break;
540 *((WORD *)ptr) = len; /* store the length */
541 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
545 RtlUnicodeToMultiByteN( (LPSTR)lParam, len, &reslen, ptr, *result * sizeof(WCHAR) );
546 if (reslen < len) ((LPSTR)lParam)[reslen] = 0;
549 free_buffer( buffer, ptr );
556 MSG newmsg = *(MSG *)lParam;
557 if (map_wparam_AtoW( newmsg.message, &newmsg.wParam, WMCHAR_MAP_NOMAPPING ))
558 ret = callback( hwnd, msg, wParam, (LPARAM)&newmsg, result, arg );
560 else ret = callback( hwnd, msg, wParam, lParam, result, arg );
569 case EM_SETPASSWORDCHAR:
571 if (map_wparam_AtoW( msg, &wParam, mapping ))
572 ret = callback( hwnd, msg, wParam, lParam, result, arg );
575 case WM_GETTEXTLENGTH:
576 case CB_GETLBTEXTLEN:
578 ret = callback( hwnd, msg, wParam, lParam, result, arg );
581 WCHAR *ptr, buffer[512];
583 DWORD len = *result + 1;
584 /* Determine respective GETTEXT message */
585 UINT msgGetText = (msg == WM_GETTEXTLENGTH) ? WM_GETTEXT :
586 ((msg == CB_GETLBTEXTLEN) ? CB_GETLBTEXT : LB_GETTEXT);
587 /* wParam differs between the messages */
588 WPARAM wp = (msg == WM_GETTEXTLENGTH) ? len : wParam;
590 if (!(ptr = get_buffer( buffer, sizeof(buffer), len * sizeof(WCHAR) ))) break;
592 if (callback == call_window_proc) /* FIXME: hack */
593 callback( hwnd, msgGetText, wp, (LPARAM)ptr, &tmp, arg );
595 tmp = SendMessageW( hwnd, msgGetText, wp, (LPARAM)ptr );
596 RtlUnicodeToMultiByteSize( &len, ptr, tmp * sizeof(WCHAR) );
598 free_buffer( buffer, ptr );
602 case WM_PAINTCLIPBOARD:
603 case WM_SIZECLIPBOARD:
604 FIXME_(msg)( "message %s (0x%x) needs translation, please report\n",
605 SPY_GetMsgName(msg, hwnd), msg );
609 ret = callback( hwnd, msg, wParam, lParam, result, arg );
616 /**********************************************************************
617 * WINPROC_CallProcWtoA
619 * Call a window procedure, translating args from Unicode to Ansi.
621 static LRESULT WINPROC_CallProcWtoA( winproc_callback_t callback, HWND hwnd, UINT msg, WPARAM wParam,
622 LPARAM lParam, LRESULT *result, void *arg )
626 TRACE_(msg)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
627 hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
634 char buffer[1024], *cls;
635 CREATESTRUCTW *csW = (CREATESTRUCTW *)lParam;
636 CREATESTRUCTA csA = *(CREATESTRUCTA *)csW;
637 MDICREATESTRUCTA mdi_cs;
638 DWORD name_lenA = 0, name_lenW = 0, class_lenA = 0, class_lenW = 0;
640 if (!IS_INTRESOURCE(csW->lpszClass))
642 class_lenW = (strlenW(csW->lpszClass) + 1) * sizeof(WCHAR);
643 RtlUnicodeToMultiByteSize(&class_lenA, csW->lpszClass, class_lenW);
645 if (!IS_INTRESOURCE(csW->lpszName))
647 name_lenW = (strlenW(csW->lpszName) + 1) * sizeof(WCHAR);
648 RtlUnicodeToMultiByteSize(&name_lenA, csW->lpszName, name_lenW);
651 if (!(cls = get_buffer( buffer, sizeof(buffer), class_lenA + name_lenA ))) break;
655 RtlUnicodeToMultiByteN(cls, class_lenA, NULL, csW->lpszClass, class_lenW);
660 char *name = cls + class_lenA;
661 RtlUnicodeToMultiByteN(name, name_lenA, NULL, csW->lpszName, name_lenW);
665 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
667 mdi_cs = *(MDICREATESTRUCTA *)csW->lpCreateParams;
668 mdi_cs.szTitle = csA.lpszName;
669 mdi_cs.szClass = csA.lpszClass;
670 csA.lpCreateParams = &mdi_cs;
673 ret = callback( hwnd, msg, wParam, (LPARAM)&csA, result, arg );
674 free_buffer( buffer, cls );
679 case WM_ASKCBFORMATNAME:
681 char *ptr, buffer[512];
682 DWORD len = wParam * 2;
684 if (!(ptr = get_buffer( buffer, sizeof(buffer), len ))) break;
685 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
690 RtlMultiByteToUnicodeN( (LPWSTR)lParam, wParam*sizeof(WCHAR), &len, ptr, strlen(ptr)+1 );
691 *result = len/sizeof(WCHAR) - 1; /* do not count terminating null */
693 ((LPWSTR)lParam)[*result] = 0;
695 free_buffer( buffer, ptr );
700 case LB_INSERTSTRING:
702 case LB_FINDSTRINGEXACT:
703 case LB_SELECTSTRING:
705 case CB_INSERTSTRING:
707 case CB_FINDSTRINGEXACT:
708 case CB_SELECTSTRING:
709 if (!lParam || !WINPROC_TestLBForStr( hwnd, msg ))
711 ret = callback( hwnd, msg, wParam, lParam, result, arg );
716 case WM_WININICHANGE:
717 case WM_DEVMODECHANGE:
722 if (!lParam) ret = callback( hwnd, msg, wParam, lParam, result, arg );
725 char *ptr, buffer[512];
726 LPCWSTR strW = (LPCWSTR)lParam;
727 DWORD lenA, lenW = (strlenW(strW) + 1) * sizeof(WCHAR);
729 RtlUnicodeToMultiByteSize( &lenA, strW, lenW );
730 if ((ptr = get_buffer( buffer, sizeof(buffer), lenA )))
732 RtlUnicodeToMultiByteN( ptr, lenA, NULL, strW, lenW );
733 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
734 free_buffer( buffer, ptr );
741 char *ptr, buffer[1024];
742 DWORD title_lenA = 0, title_lenW = 0, class_lenA = 0, class_lenW = 0;
743 MDICREATESTRUCTW *csW = (MDICREATESTRUCTW *)lParam;
744 MDICREATESTRUCTA csA;
746 memcpy( &csA, csW, sizeof(csA) );
748 if (!IS_INTRESOURCE(csW->szTitle))
750 title_lenW = (strlenW(csW->szTitle) + 1) * sizeof(WCHAR);
751 RtlUnicodeToMultiByteSize( &title_lenA, csW->szTitle, title_lenW );
753 if (!IS_INTRESOURCE(csW->szClass))
755 class_lenW = (strlenW(csW->szClass) + 1) * sizeof(WCHAR);
756 RtlUnicodeToMultiByteSize( &class_lenA, csW->szClass, class_lenW );
759 if (!(ptr = get_buffer( buffer, sizeof(buffer), title_lenA + class_lenA ))) break;
763 RtlUnicodeToMultiByteN( ptr, title_lenA, NULL, csW->szTitle, title_lenW );
768 RtlUnicodeToMultiByteN( ptr + title_lenA, class_lenA, NULL, csW->szClass, class_lenW );
769 csA.szClass = ptr + title_lenA;
771 ret = callback( hwnd, msg, wParam, (LPARAM)&csA, result, arg );
772 free_buffer( buffer, ptr );
778 if (lParam && WINPROC_TestLBForStr( hwnd, msg ))
780 char buffer[512]; /* FIXME: fixed sized buffer */
782 ret = callback( hwnd, msg, wParam, (LPARAM)buffer, result, arg );
786 RtlMultiByteToUnicodeN( (LPWSTR)lParam, ~0u, &len, buffer, strlen(buffer) + 1 );
787 *result = len / sizeof(WCHAR) - 1;
790 else ret = callback( hwnd, msg, wParam, lParam, result, arg );
795 char *ptr, buffer[512];
796 WORD len = *(WORD *)lParam;
798 if (!(ptr = get_buffer( buffer, sizeof(buffer), len * 2 ))) break;
799 *((WORD *)ptr) = len * 2; /* store the length */
800 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
804 RtlMultiByteToUnicodeN( (LPWSTR)lParam, len*sizeof(WCHAR), &reslen, ptr, *result );
805 *result = reslen / sizeof(WCHAR);
806 if (*result < len) ((LPWSTR)lParam)[*result] = 0;
808 free_buffer( buffer, ptr );
815 MSG newmsg = *(MSG *)lParam;
816 switch(newmsg.message)
822 newmsg.wParam = map_wparam_char_WtoA( newmsg.wParam, 1 );
825 newmsg.wParam = map_wparam_char_WtoA( newmsg.wParam, 2 );
828 ret = callback( hwnd, msg, wParam, (LPARAM)&newmsg, result, arg );
830 else ret = callback( hwnd, msg, wParam, lParam, result, arg );
839 RtlUnicodeToMultiByteN( ch, 2, &len, &wch, sizeof(wch) );
840 ret = callback( hwnd, msg, (BYTE)ch[0], lParam, result, arg );
841 if (len == 2) ret = callback( hwnd, msg, (BYTE)ch[1], lParam, result, arg );
850 case EM_SETPASSWORDCHAR:
851 ret = callback( hwnd, msg, map_wparam_char_WtoA(wParam,1), lParam, result, arg );
855 ret = callback( hwnd, msg, map_wparam_char_WtoA(wParam,2), lParam, result, arg );
858 case WM_PAINTCLIPBOARD:
859 case WM_SIZECLIPBOARD:
860 FIXME_(msg)( "message %s (%04x) needs translation, please report\n",
861 SPY_GetMsgName(msg, hwnd), msg );
865 ret = callback( hwnd, msg, wParam, lParam, result, arg );
873 /**********************************************************************
874 * WINPROC_call_window
876 * Call the window procedure of the specified window.
878 BOOL WINPROC_call_window( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
879 LRESULT *result, BOOL unicode, enum wm_char_mapping mapping )
881 struct user_thread_info *thread_info = get_user_thread_info();
886 if (!(wndPtr = WIN_GetPtr( hwnd ))) return FALSE;
887 if (wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
888 if (wndPtr->tid != GetCurrentThreadId())
890 WIN_ReleasePtr( wndPtr );
893 func = wndPtr->winproc;
894 proc = handle_to_proc( wndPtr->winproc );
895 WIN_ReleasePtr( wndPtr );
897 if (!proc) return TRUE;
899 if (thread_info->recursion_count > MAX_WINPROC_RECURSION) return FALSE;
900 thread_info->recursion_count++;
904 if (proc == WINPROC_PROC16)
905 WINPROC_CallProcWtoA( wow_handlers.call_window_proc, hwnd, msg, wParam, lParam, result, func );
906 else if (proc->procW)
907 call_window_proc( hwnd, msg, wParam, lParam, result, proc->procW );
909 WINPROC_CallProcWtoA( call_window_proc, hwnd, msg, wParam, lParam, result, proc->procA );
913 if (proc == WINPROC_PROC16)
914 wow_handlers.call_window_proc( hwnd, msg, wParam, lParam, result, func );
915 else if (proc->procA)
916 call_window_proc( hwnd, msg, wParam, lParam, result, proc->procA );
918 WINPROC_CallProcAtoW( call_window_proc, hwnd, msg, wParam, lParam, result, proc->procW, mapping );
920 thread_info->recursion_count--;
925 /**********************************************************************
926 * CallWindowProcA (USER32.@)
928 * The CallWindowProc() function invokes the windows procedure _func_,
929 * with _hwnd_ as the target window, the message specified by _msg_, and
930 * the message parameters _wParam_ and _lParam_.
932 * Some kinds of argument conversion may be done, I'm not sure what.
934 * CallWindowProc() may be used for windows subclassing. Use
935 * SetWindowLong() to set a new windows procedure for windows of the
936 * subclass, and handle subclassed messages in the new windows
937 * procedure. The new windows procedure may then use CallWindowProc()
938 * with _func_ set to the parent class's windows procedure to dispatch
939 * the message to the superclass.
943 * The return value is message dependent.
949 LRESULT WINAPI CallWindowProcA(
950 WNDPROC func, /* [in] window procedure */
951 HWND hwnd, /* [in] target window */
952 UINT msg, /* [in] message */
953 WPARAM wParam, /* [in] message dependent parameter */
954 LPARAM lParam /* [in] message dependent parameter */
961 if (!(proc = handle_to_proc( func )))
962 call_window_proc( hwnd, msg, wParam, lParam, &result, func );
963 else if (proc == WINPROC_PROC16)
964 wow_handlers.call_window_proc( hwnd, msg, wParam, lParam, &result, func );
965 else if (proc->procA)
966 call_window_proc( hwnd, msg, wParam, lParam, &result, proc->procA );
968 WINPROC_CallProcAtoW( call_window_proc, hwnd, msg, wParam, lParam, &result,
969 proc->procW, WMCHAR_MAP_CALLWINDOWPROC );
974 /**********************************************************************
975 * CallWindowProcW (USER32.@)
977 * See CallWindowProcA.
979 LRESULT WINAPI CallWindowProcW( WNDPROC func, HWND hwnd, UINT msg,
980 WPARAM wParam, LPARAM lParam )
987 if (!(proc = handle_to_proc( func )))
988 call_window_proc( hwnd, msg, wParam, lParam, &result, func );
989 else if (proc == WINPROC_PROC16)
990 WINPROC_CallProcWtoA( wow_handlers.call_window_proc, hwnd, msg, wParam, lParam, &result, func );
991 else if (proc->procW)
992 call_window_proc( hwnd, msg, wParam, lParam, &result, proc->procW );
994 WINPROC_CallProcWtoA( call_window_proc, hwnd, msg, wParam, lParam, &result, proc->procA );
999 /**********************************************************************
1000 * WINPROC_CallDlgProcA
1002 INT_PTR WINPROC_CallDlgProcA( DLGPROC func, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
1008 if (!func) return 0;
1010 if (!(proc = handle_to_proc( func )))
1011 ret = call_dialog_proc( hwnd, msg, wParam, lParam, &result, func );
1012 else if (proc == WINPROC_PROC16)
1014 ret = wow_handlers.call_dialog_proc( hwnd, msg, wParam, lParam, &result, func );
1015 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
1017 else if (proc->procW)
1019 ret = WINPROC_CallProcAtoW( call_dialog_proc, hwnd, msg, wParam, lParam, &result,
1020 proc->procW, WMCHAR_MAP_CALLWINDOWPROC );
1021 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
1024 ret = call_dialog_proc( hwnd, msg, wParam, lParam, &result, proc->procA );
1029 /**********************************************************************
1030 * WINPROC_CallDlgProcW
1032 INT_PTR WINPROC_CallDlgProcW( DLGPROC func, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
1038 if (!func) return 0;
1040 if (!(proc = handle_to_proc( func )))
1041 ret = call_dialog_proc( hwnd, msg, wParam, lParam, &result, func );
1042 else if (proc == WINPROC_PROC16)
1044 ret = WINPROC_CallProcWtoA( wow_handlers.call_dialog_proc, hwnd, msg, wParam, lParam, &result, func );
1045 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
1047 else if (proc->procA)
1049 ret = WINPROC_CallProcWtoA( call_dialog_proc, hwnd, msg, wParam, lParam, &result, proc->procA );
1050 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
1053 ret = call_dialog_proc( hwnd, msg, wParam, lParam, &result, proc->procW );
1058 /***********************************************************************
1059 * Window procedures for builtin classes
1062 static LRESULT WINAPI ButtonWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
1064 return wow_handlers.button_proc( hwnd, msg, wParam, lParam, FALSE );
1067 static LRESULT WINAPI ButtonWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
1069 return wow_handlers.button_proc( hwnd, msg, wParam, lParam, TRUE );
1072 static LRESULT WINAPI ComboWndProcA( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1074 return wow_handlers.combo_proc( hwnd, message, wParam, lParam, FALSE );
1077 static LRESULT WINAPI ComboWndProcW( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
1079 return wow_handlers.combo_proc( hwnd, message, wParam, lParam, TRUE );
1082 LRESULT WINAPI EditWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
1084 return wow_handlers.edit_proc( hwnd, msg, wParam, lParam, FALSE );
1087 static LRESULT WINAPI EditWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
1089 return wow_handlers.edit_proc( hwnd, msg, wParam, lParam, TRUE );
1092 static LRESULT WINAPI ListBoxWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
1094 return wow_handlers.listbox_proc( hwnd, msg, wParam, lParam, FALSE );
1097 static LRESULT WINAPI ListBoxWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
1099 return wow_handlers.listbox_proc( hwnd, msg, wParam, lParam, TRUE );
1102 static LRESULT WINAPI MDIClientWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
1104 return wow_handlers.mdiclient_proc( hwnd, msg, wParam, lParam, FALSE );
1107 static LRESULT WINAPI MDIClientWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
1109 return wow_handlers.mdiclient_proc( hwnd, msg, wParam, lParam, TRUE );
1112 static LRESULT WINAPI ScrollBarWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
1114 return wow_handlers.scrollbar_proc( hwnd, msg, wParam, lParam, FALSE );
1117 static LRESULT WINAPI ScrollBarWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
1119 return wow_handlers.scrollbar_proc( hwnd, msg, wParam, lParam, TRUE );
1122 static LRESULT WINAPI StaticWndProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
1124 return wow_handlers.static_proc( hwnd, msg, wParam, lParam, FALSE );
1127 static LRESULT WINAPI StaticWndProcW( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
1129 return wow_handlers.static_proc( hwnd, msg, wParam, lParam, TRUE );
1133 /**********************************************************************
1134 * UserRegisterWowHandlers (USER32.@)
1136 * NOTE: no attempt has been made to be compatible here,
1137 * the Windows function is most likely completely different.
1139 void WINAPI UserRegisterWowHandlers( const struct wow_handlers16 *new, struct wow_handlers32 *orig )
1141 orig->button_proc = ButtonWndProc_common;
1142 orig->combo_proc = ComboWndProc_common;
1143 orig->edit_proc = EditWndProc_common;
1144 orig->listbox_proc = ListBoxWndProc_common;
1145 orig->mdiclient_proc = MDIClientWndProc_common;
1146 orig->scrollbar_proc = ScrollBarWndProc_common;
1147 orig->static_proc = StaticWndProc_common;
1148 orig->alloc_winproc = WINPROC_AllocProc;
1150 wow_handlers = *new;
1153 struct wow_handlers16 wow_handlers =
1155 ButtonWndProc_common,
1156 ComboWndProc_common,
1158 ListBoxWndProc_common,
1159 MDIClientWndProc_common,
1160 ScrollBarWndProc_common,
1161 StaticWndProc_common,
1162 NULL, /* call_window_proc */
1163 NULL /* call_dialog_proc */