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"
34 #include "user_private.h"
35 #include "wine/unicode.h"
36 #include "wine/debug.h"
38 WINE_DECLARE_DEBUG_CHANNEL(msg
);
39 WINE_DECLARE_DEBUG_CHANNEL(relay
);
40 WINE_DEFAULT_DEBUG_CHANNEL(win
);
42 typedef struct tagWINDOWPROC
44 WNDPROC procA
; /* ASCII window proc */
45 WNDPROC procW
; /* Unicode window proc */
48 #define MAX_WINPROCS 4096
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 { DefWindowProcA
, DefWindowProcW
}, /* WINPROC_DEFWND */
72 { DefDlgProcA
, DefDlgProcW
}, /* WINPROC_DIALOG */
73 { EditWndProcA
, EditWndProcW
}, /* WINPROC_EDIT */
74 { ListBoxWndProcA
, ListBoxWndProcW
}, /* WINPROC_LISTBOX */
75 { MDIClientWndProcA
, MDIClientWndProcW
}, /* WINPROC_MDICLIENT */
76 { ScrollBarWndProcA
, ScrollBarWndProcW
}, /* WINPROC_SCROLLBAR */
77 { StaticWndProcA
, StaticWndProcW
}, /* WINPROC_STATIC */
78 { NULL
, DesktopWndProc
}, /* WINPROC_DESKTOP */
79 { NULL
, IconTitleWndProc
}, /* WINPROC_ICONTITLE */
80 { NULL
, PopupMenuWndProc
}, /* WINPROC_MENU */
81 { NULL
, MessageWndProc
}, /* WINPROC_MESSAGE */
84 static UINT winproc_used
= NB_BUILTIN_WINPROCS
;
86 static CRITICAL_SECTION winproc_cs
;
87 static CRITICAL_SECTION_DEBUG critsect_debug
=
90 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
91 0, 0, { (DWORD_PTR
)(__FILE__
": winproc_cs") }
93 static CRITICAL_SECTION winproc_cs
= { &critsect_debug
, -1, 0, 0, 0, 0 };
95 static inline void *get_buffer( void *static_buffer
, size_t size
, size_t need
)
97 if (size
>= need
) return static_buffer
;
98 return HeapAlloc( GetProcessHeap(), 0, need
);
101 static inline void free_buffer( void *static_buffer
, void *buffer
)
103 if (buffer
!= static_buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
106 /* find an existing winproc for a given function and type */
107 /* FIXME: probably should do something more clever than a linear search */
108 static inline WINDOWPROC
*find_winproc( WNDPROC func
, BOOL unicode
)
112 for (i
= 0; i
< NB_BUILTIN_AW_WINPROCS
; i
++)
114 /* match either proc, some apps confuse A and W */
115 if (winproc_array
[i
].procA
!= func
&& winproc_array
[i
].procW
!= func
) continue;
116 return &winproc_array
[i
];
118 for (i
= NB_BUILTIN_AW_WINPROCS
; i
< winproc_used
; i
++)
120 if (!unicode
&& winproc_array
[i
].procA
!= func
) continue;
121 if (unicode
&& winproc_array
[i
].procW
!= func
) continue;
122 return &winproc_array
[i
];
127 /* return the window proc for a given handle, or NULL for an invalid handle,
128 * or WINPROC_PROC16 for a handle to a 16-bit proc. */
129 static inline WINDOWPROC
*handle_to_proc( WNDPROC handle
)
131 UINT index
= LOWORD(handle
);
132 if ((ULONG_PTR
)handle
>> 16 != WINPROC_HANDLE
) return NULL
;
133 if (index
>= MAX_WINPROCS
) return WINPROC_PROC16
;
134 if (index
>= winproc_used
) return NULL
;
135 return &winproc_array
[index
];
138 /* create a handle for a given window proc */
139 static inline WNDPROC
proc_to_handle( WINDOWPROC
*proc
)
141 return (WNDPROC
)(ULONG_PTR
)((proc
- winproc_array
) | (WINPROC_HANDLE
<< 16));
144 /* allocate and initialize a new winproc */
145 static inline WINDOWPROC
*alloc_winproc( WNDPROC func
, BOOL unicode
)
149 /* check if the function is already a win proc */
150 if (!func
) return NULL
;
151 if ((proc
= handle_to_proc( func
))) return proc
;
153 EnterCriticalSection( &winproc_cs
);
155 /* check if we already have a winproc for that function */
156 if (!(proc
= find_winproc( func
, unicode
)))
158 if (winproc_used
< MAX_WINPROCS
)
160 proc
= &winproc_array
[winproc_used
++];
161 if (unicode
) proc
->procW
= func
;
162 else proc
->procA
= func
;
163 TRACE( "allocated %p for %c %p (%d/%d used)\n",
164 proc_to_handle(proc
), unicode
? 'W' : 'A', func
,
165 winproc_used
, MAX_WINPROCS
);
167 else FIXME( "too many winprocs, cannot allocate one for %p\n", func
);
169 else TRACE( "reusing %p for %p\n", proc_to_handle(proc
), func
);
171 LeaveCriticalSection( &winproc_cs
);
176 /* Some window procedures modify register they shouldn't, or are not
177 * properly declared stdcall; so we need a small assembly wrapper to
179 extern LRESULT
WINPROC_wrapper( WNDPROC proc
, HWND hwnd
, UINT msg
,
180 WPARAM wParam
, LPARAM lParam
);
181 __ASM_GLOBAL_FUNC( WINPROC_wrapper
,
183 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
184 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
186 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
188 __ASM_CFI(".cfi_rel_offset %edi,-4\n\t")
190 __ASM_CFI(".cfi_rel_offset %esi,-8\n\t")
192 __ASM_CFI(".cfi_rel_offset %ebx,-12\n\t")
198 "movl 8(%ebp),%eax\n\t"
200 "leal -12(%ebp),%esp\n\t"
202 __ASM_CFI(".cfi_same_value %ebx\n\t")
204 __ASM_CFI(".cfi_same_value %esi\n\t")
206 __ASM_CFI(".cfi_same_value %edi\n\t")
208 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
209 __ASM_CFI(".cfi_same_value %ebp\n\t")
212 static inline LRESULT
WINPROC_wrapper( WNDPROC proc
, HWND hwnd
, UINT msg
,
213 WPARAM wParam
, LPARAM lParam
)
215 return proc( hwnd
, msg
, wParam
, lParam
);
217 #endif /* __i386__ */
219 static WPARAM
map_wparam_char_WtoA( WPARAM wParam
, DWORD len
)
223 DWORD cp
= get_input_codepage();
225 len
= WideCharToMultiByte( cp
, 0, &wch
, 1, (LPSTR
)ch
, len
, NULL
, NULL
);
227 return MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(wParam
) );
229 return MAKEWPARAM( ch
[0], HIWORD(wParam
) );
232 /* call a 32-bit window procedure */
233 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
, LRESULT
*result
, void *arg
)
239 hwnd
= WIN_GetFullHandle( hwnd
);
241 DPRINTF( "%04x:Call window proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
242 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
);
244 *result
= WINPROC_wrapper( proc
, hwnd
, msg
, wp
, lp
);
247 DPRINTF( "%04x:Ret window proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx) retval=%08lx\n",
248 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
, *result
);
252 /* call a 32-bit dialog procedure */
253 static LRESULT
call_dialog_proc( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
, LRESULT
*result
, void *arg
)
260 hwnd
= WIN_GetFullHandle( hwnd
);
262 DPRINTF( "%04x:Call dialog proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
263 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
);
265 ret
= WINPROC_wrapper( proc
, hwnd
, msg
, wp
, lp
);
266 *result
= GetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
);
269 DPRINTF( "%04x:Ret dialog proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx) retval=%08lx result=%08lx\n",
270 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
, ret
, *result
);
275 /**********************************************************************
278 * Get a window procedure pointer that can be passed to the Windows program.
280 WNDPROC
WINPROC_GetProc( WNDPROC proc
, BOOL unicode
)
282 WINDOWPROC
*ptr
= handle_to_proc( proc
);
284 if (!ptr
|| ptr
== WINPROC_PROC16
) return proc
;
287 if (ptr
->procW
) return ptr
->procW
;
292 if (ptr
->procA
) return ptr
->procA
;
298 /**********************************************************************
301 * Allocate a window procedure for a window or class.
303 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
304 * lot of windows, it will usually only have a limited number of window procedures, so the
305 * array won't grow too large, and this way we avoid the need to track allocations per window.
307 WNDPROC
WINPROC_AllocProc( WNDPROC func
, BOOL unicode
)
311 if (!(proc
= alloc_winproc( func
, unicode
))) return NULL
;
312 if (proc
== WINPROC_PROC16
) return func
;
313 return proc_to_handle( proc
);
317 /**********************************************************************
320 * Return the window procedure type, or the default value if not a winproc handle.
322 BOOL
WINPROC_IsUnicode( WNDPROC proc
, BOOL def_val
)
324 WINDOWPROC
*ptr
= handle_to_proc( proc
);
326 if (!ptr
) return def_val
;
327 if (ptr
== WINPROC_PROC16
) return FALSE
; /* 16-bit is always A */
328 if (ptr
->procA
&& ptr
->procW
) return def_val
; /* can be both */
329 return (ptr
->procW
!= NULL
);
333 /**********************************************************************
334 * WINPROC_TestLBForStr
336 * Return TRUE if the lparam is a string
338 static inline BOOL
WINPROC_TestLBForStr( HWND hwnd
, UINT msg
)
340 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
341 if (msg
<= CB_MSGMAX
)
342 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
344 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
349 /**********************************************************************
350 * WINPROC_CallProcAtoW
352 * Call a window procedure, translating args from Ansi to Unicode.
354 LRESULT
WINPROC_CallProcAtoW( winproc_callback_t callback
, HWND hwnd
, UINT msg
, WPARAM wParam
,
355 LPARAM lParam
, LRESULT
*result
, void *arg
, enum wm_char_mapping mapping
)
359 TRACE_(msg
)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
360 hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
367 WCHAR
*ptr
, buffer
[512];
368 CREATESTRUCTA
*csA
= (CREATESTRUCTA
*)lParam
;
369 CREATESTRUCTW csW
= *(CREATESTRUCTW
*)csA
;
370 MDICREATESTRUCTW mdi_cs
;
371 DWORD name_lenA
= 0, name_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
373 if (!IS_INTRESOURCE(csA
->lpszClass
))
375 class_lenA
= strlen(csA
->lpszClass
) + 1;
376 RtlMultiByteToUnicodeSize( &class_lenW
, csA
->lpszClass
, class_lenA
);
378 if (!IS_INTRESOURCE(csA
->lpszName
))
380 name_lenA
= strlen(csA
->lpszName
) + 1;
381 RtlMultiByteToUnicodeSize( &name_lenW
, csA
->lpszName
, name_lenA
);
384 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), class_lenW
+ name_lenW
))) break;
389 RtlMultiByteToUnicodeN( ptr
, class_lenW
, NULL
, csA
->lpszClass
, class_lenA
);
393 csW
.lpszName
= ptr
+ class_lenW
/sizeof(WCHAR
);
394 RtlMultiByteToUnicodeN( ptr
+ class_lenW
/sizeof(WCHAR
), name_lenW
, NULL
,
395 csA
->lpszName
, name_lenA
);
398 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
400 mdi_cs
= *(MDICREATESTRUCTW
*)csA
->lpCreateParams
;
401 mdi_cs
.szTitle
= csW
.lpszName
;
402 mdi_cs
.szClass
= csW
.lpszClass
;
403 csW
.lpCreateParams
= &mdi_cs
;
406 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csW
, result
, arg
);
407 free_buffer( buffer
, ptr
);
413 WCHAR
*ptr
, buffer
[512];
414 DWORD title_lenA
= 0, title_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
415 MDICREATESTRUCTA
*csA
= (MDICREATESTRUCTA
*)lParam
;
416 MDICREATESTRUCTW csW
;
418 memcpy( &csW
, csA
, sizeof(csW
) );
420 if (!IS_INTRESOURCE(csA
->szTitle
))
422 title_lenA
= strlen(csA
->szTitle
) + 1;
423 RtlMultiByteToUnicodeSize( &title_lenW
, csA
->szTitle
, title_lenA
);
425 if (!IS_INTRESOURCE(csA
->szClass
))
427 class_lenA
= strlen(csA
->szClass
) + 1;
428 RtlMultiByteToUnicodeSize( &class_lenW
, csA
->szClass
, class_lenA
);
431 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), title_lenW
+ class_lenW
))) break;
436 RtlMultiByteToUnicodeN( ptr
, title_lenW
, NULL
, csA
->szTitle
, title_lenA
);
440 csW
.szClass
= ptr
+ title_lenW
/sizeof(WCHAR
);
441 RtlMultiByteToUnicodeN( ptr
+ title_lenW
/sizeof(WCHAR
), class_lenW
, NULL
,
442 csA
->szClass
, class_lenA
);
444 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csW
, result
, arg
);
445 free_buffer( buffer
, ptr
);
450 case WM_ASKCBFORMATNAME
:
452 WCHAR
*ptr
, buffer
[512];
453 LPSTR str
= (LPSTR
)lParam
;
454 DWORD len
= wParam
* sizeof(WCHAR
);
456 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
))) break;
457 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
462 RtlUnicodeToMultiByteN( str
, wParam
- 1, &len
, ptr
, strlenW(ptr
) * sizeof(WCHAR
) );
466 free_buffer( buffer
, ptr
);
471 case LB_INSERTSTRING
:
473 case LB_FINDSTRINGEXACT
:
474 case LB_SELECTSTRING
:
476 case CB_INSERTSTRING
:
478 case CB_FINDSTRINGEXACT
:
479 case CB_SELECTSTRING
:
480 if (!lParam
|| !WINPROC_TestLBForStr( hwnd
, msg
))
482 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
487 case WM_WININICHANGE
:
488 case WM_DEVMODECHANGE
:
493 if (!lParam
) ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
496 WCHAR
*ptr
, buffer
[512];
497 LPCSTR strA
= (LPCSTR
)lParam
;
498 DWORD lenW
, lenA
= strlen(strA
) + 1;
500 RtlMultiByteToUnicodeSize( &lenW
, strA
, lenA
);
501 if ((ptr
= get_buffer( buffer
, sizeof(buffer
), lenW
)))
503 RtlMultiByteToUnicodeN( ptr
, lenW
, NULL
, strA
, lenA
);
504 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
505 free_buffer( buffer
, ptr
);
512 if (lParam
&& WINPROC_TestLBForStr( hwnd
, msg
))
514 WCHAR buffer
[512]; /* FIXME: fixed sized buffer */
516 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)buffer
, result
, arg
);
520 RtlUnicodeToMultiByteN( (LPSTR
)lParam
, ~0u, &len
,
521 buffer
, (strlenW(buffer
) + 1) * sizeof(WCHAR
) );
525 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
530 WCHAR
*ptr
, buffer
[512];
531 WORD len
= *(WORD
*)lParam
;
533 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* sizeof(WCHAR
) ))) break;
534 *((WORD
*)ptr
) = len
; /* store the length */
535 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
539 RtlUnicodeToMultiByteN( (LPSTR
)lParam
, len
, &reslen
, ptr
, *result
* sizeof(WCHAR
) );
540 if (reslen
< len
) ((LPSTR
)lParam
)[reslen
] = 0;
543 free_buffer( buffer
, ptr
);
550 MSG newmsg
= *(MSG
*)lParam
;
551 if (map_wparam_AtoW( newmsg
.message
, &newmsg
.wParam
, WMCHAR_MAP_NOMAPPING
))
552 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&newmsg
, result
, arg
);
554 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
563 case EM_SETPASSWORDCHAR
:
565 if (map_wparam_AtoW( msg
, &wParam
, mapping
))
566 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
569 case WM_GETTEXTLENGTH
:
570 case CB_GETLBTEXTLEN
:
572 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
575 WCHAR
*ptr
, buffer
[512];
577 DWORD len
= *result
+ 1;
578 /* Determine respective GETTEXT message */
579 UINT msgGetText
= (msg
== WM_GETTEXTLENGTH
) ? WM_GETTEXT
:
580 ((msg
== CB_GETLBTEXTLEN
) ? CB_GETLBTEXT
: LB_GETTEXT
);
581 /* wParam differs between the messages */
582 WPARAM wp
= (msg
== WM_GETTEXTLENGTH
) ? len
: wParam
;
584 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* sizeof(WCHAR
) ))) break;
586 if (callback
== call_window_proc
) /* FIXME: hack */
587 callback( hwnd
, msgGetText
, wp
, (LPARAM
)ptr
, &tmp
, arg
);
589 tmp
= SendMessageW( hwnd
, msgGetText
, wp
, (LPARAM
)ptr
);
590 RtlUnicodeToMultiByteSize( &len
, ptr
, tmp
* sizeof(WCHAR
) );
592 free_buffer( buffer
, ptr
);
596 case WM_PAINTCLIPBOARD
:
597 case WM_SIZECLIPBOARD
:
598 FIXME_(msg
)( "message %s (0x%x) needs translation, please report\n",
599 SPY_GetMsgName(msg
, hwnd
), msg
);
603 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
610 /**********************************************************************
611 * WINPROC_CallProcWtoA
613 * Call a window procedure, translating args from Unicode to Ansi.
615 static LRESULT
WINPROC_CallProcWtoA( winproc_callback_t callback
, HWND hwnd
, UINT msg
, WPARAM wParam
,
616 LPARAM lParam
, LRESULT
*result
, void *arg
)
620 TRACE_(msg
)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
621 hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
628 char buffer
[1024], *cls
;
629 CREATESTRUCTW
*csW
= (CREATESTRUCTW
*)lParam
;
630 CREATESTRUCTA csA
= *(CREATESTRUCTA
*)csW
;
631 MDICREATESTRUCTA mdi_cs
;
632 DWORD name_lenA
= 0, name_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
634 if (!IS_INTRESOURCE(csW
->lpszClass
))
636 class_lenW
= (strlenW(csW
->lpszClass
) + 1) * sizeof(WCHAR
);
637 RtlUnicodeToMultiByteSize(&class_lenA
, csW
->lpszClass
, class_lenW
);
639 if (!IS_INTRESOURCE(csW
->lpszName
))
641 name_lenW
= (strlenW(csW
->lpszName
) + 1) * sizeof(WCHAR
);
642 RtlUnicodeToMultiByteSize(&name_lenA
, csW
->lpszName
, name_lenW
);
645 if (!(cls
= get_buffer( buffer
, sizeof(buffer
), class_lenA
+ name_lenA
))) break;
649 RtlUnicodeToMultiByteN(cls
, class_lenA
, NULL
, csW
->lpszClass
, class_lenW
);
654 char *name
= cls
+ class_lenA
;
655 RtlUnicodeToMultiByteN(name
, name_lenA
, NULL
, csW
->lpszName
, name_lenW
);
659 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
661 mdi_cs
= *(MDICREATESTRUCTA
*)csW
->lpCreateParams
;
662 mdi_cs
.szTitle
= csA
.lpszName
;
663 mdi_cs
.szClass
= csA
.lpszClass
;
664 csA
.lpCreateParams
= &mdi_cs
;
667 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csA
, result
, arg
);
668 free_buffer( buffer
, cls
);
673 case WM_ASKCBFORMATNAME
:
675 char *ptr
, buffer
[512];
676 DWORD len
= wParam
* 2;
678 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
))) break;
679 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
684 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, wParam
*sizeof(WCHAR
), &len
, ptr
, strlen(ptr
)+1 );
685 *result
= len
/sizeof(WCHAR
) - 1; /* do not count terminating null */
687 ((LPWSTR
)lParam
)[*result
] = 0;
689 free_buffer( buffer
, ptr
);
694 case LB_INSERTSTRING
:
696 case LB_FINDSTRINGEXACT
:
697 case LB_SELECTSTRING
:
699 case CB_INSERTSTRING
:
701 case CB_FINDSTRINGEXACT
:
702 case CB_SELECTSTRING
:
703 if (!lParam
|| !WINPROC_TestLBForStr( hwnd
, msg
))
705 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
710 case WM_WININICHANGE
:
711 case WM_DEVMODECHANGE
:
716 if (!lParam
) ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
719 char *ptr
, buffer
[512];
720 LPCWSTR strW
= (LPCWSTR
)lParam
;
721 DWORD lenA
, lenW
= (strlenW(strW
) + 1) * sizeof(WCHAR
);
723 RtlUnicodeToMultiByteSize( &lenA
, strW
, lenW
);
724 if ((ptr
= get_buffer( buffer
, sizeof(buffer
), lenA
)))
726 RtlUnicodeToMultiByteN( ptr
, lenA
, NULL
, strW
, lenW
);
727 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
728 free_buffer( buffer
, ptr
);
735 char *ptr
, buffer
[1024];
736 DWORD title_lenA
= 0, title_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
737 MDICREATESTRUCTW
*csW
= (MDICREATESTRUCTW
*)lParam
;
738 MDICREATESTRUCTA csA
;
740 memcpy( &csA
, csW
, sizeof(csA
) );
742 if (!IS_INTRESOURCE(csW
->szTitle
))
744 title_lenW
= (strlenW(csW
->szTitle
) + 1) * sizeof(WCHAR
);
745 RtlUnicodeToMultiByteSize( &title_lenA
, csW
->szTitle
, title_lenW
);
747 if (!IS_INTRESOURCE(csW
->szClass
))
749 class_lenW
= (strlenW(csW
->szClass
) + 1) * sizeof(WCHAR
);
750 RtlUnicodeToMultiByteSize( &class_lenA
, csW
->szClass
, class_lenW
);
753 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), title_lenA
+ class_lenA
))) break;
757 RtlUnicodeToMultiByteN( ptr
, title_lenA
, NULL
, csW
->szTitle
, title_lenW
);
762 RtlUnicodeToMultiByteN( ptr
+ title_lenA
, class_lenA
, NULL
, csW
->szClass
, class_lenW
);
763 csA
.szClass
= ptr
+ title_lenA
;
765 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csA
, result
, arg
);
766 free_buffer( buffer
, ptr
);
772 if (lParam
&& WINPROC_TestLBForStr( hwnd
, msg
))
774 char buffer
[512]; /* FIXME: fixed sized buffer */
776 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)buffer
, result
, arg
);
780 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, ~0u, &len
, buffer
, strlen(buffer
) + 1 );
781 *result
= len
/ sizeof(WCHAR
) - 1;
784 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
789 char *ptr
, buffer
[512];
790 WORD len
= *(WORD
*)lParam
;
792 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* 2 ))) break;
793 *((WORD
*)ptr
) = len
* 2; /* store the length */
794 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
798 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, len
*sizeof(WCHAR
), &reslen
, ptr
, *result
);
799 *result
= reslen
/ sizeof(WCHAR
);
800 if (*result
< len
) ((LPWSTR
)lParam
)[*result
] = 0;
802 free_buffer( buffer
, ptr
);
809 MSG newmsg
= *(MSG
*)lParam
;
810 switch(newmsg
.message
)
816 newmsg
.wParam
= map_wparam_char_WtoA( newmsg
.wParam
, 1 );
819 newmsg
.wParam
= map_wparam_char_WtoA( newmsg
.wParam
, 2 );
822 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&newmsg
, result
, arg
);
824 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
831 DWORD cp
= get_input_codepage();
832 DWORD len
= WideCharToMultiByte( cp
, 0, &wch
, 1, ch
, 2, NULL
, NULL
);
833 ret
= callback( hwnd
, msg
, (BYTE
)ch
[0], lParam
, result
, arg
);
834 if (len
== 2) ret
= callback( hwnd
, msg
, (BYTE
)ch
[1], lParam
, result
, arg
);
843 case EM_SETPASSWORDCHAR
:
844 ret
= callback( hwnd
, msg
, map_wparam_char_WtoA(wParam
,1), lParam
, result
, arg
);
848 ret
= callback( hwnd
, msg
, map_wparam_char_WtoA(wParam
,2), lParam
, result
, arg
);
851 case WM_PAINTCLIPBOARD
:
852 case WM_SIZECLIPBOARD
:
853 FIXME_(msg
)( "message %s (%04x) needs translation, please report\n",
854 SPY_GetMsgName(msg
, hwnd
), msg
);
858 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
866 /**********************************************************************
867 * WINPROC_call_window
869 * Call the window procedure of the specified window.
871 BOOL
WINPROC_call_window( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
872 LRESULT
*result
, BOOL unicode
, enum wm_char_mapping mapping
)
874 struct user_thread_info
*thread_info
= get_user_thread_info();
879 if (!(wndPtr
= WIN_GetPtr( hwnd
))) return FALSE
;
880 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
881 if (wndPtr
->tid
!= GetCurrentThreadId())
883 WIN_ReleasePtr( wndPtr
);
886 func
= wndPtr
->winproc
;
887 proc
= handle_to_proc( wndPtr
->winproc
);
888 WIN_ReleasePtr( wndPtr
);
890 if (!proc
) return TRUE
;
892 if (thread_info
->recursion_count
> MAX_WINPROC_RECURSION
) return FALSE
;
893 thread_info
->recursion_count
++;
897 if (proc
== WINPROC_PROC16
)
898 WINPROC_CallProcWtoA( wow_handlers
.call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, func
);
899 else if (proc
->procW
)
900 call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, proc
->procW
);
902 WINPROC_CallProcWtoA( call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, proc
->procA
);
906 if (proc
== WINPROC_PROC16
)
907 wow_handlers
.call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, func
);
908 else if (proc
->procA
)
909 call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, proc
->procA
);
911 WINPROC_CallProcAtoW( call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, proc
->procW
, mapping
);
913 thread_info
->recursion_count
--;
918 /**********************************************************************
919 * CallWindowProcA (USER32.@)
921 * The CallWindowProc() function invokes the windows procedure _func_,
922 * with _hwnd_ as the target window, the message specified by _msg_, and
923 * the message parameters _wParam_ and _lParam_.
925 * Some kinds of argument conversion may be done, I'm not sure what.
927 * CallWindowProc() may be used for windows subclassing. Use
928 * SetWindowLong() to set a new windows procedure for windows of the
929 * subclass, and handle subclassed messages in the new windows
930 * procedure. The new windows procedure may then use CallWindowProc()
931 * with _func_ set to the parent class's windows procedure to dispatch
932 * the message to the superclass.
936 * The return value is message dependent.
942 LRESULT WINAPI
CallWindowProcA(
943 WNDPROC func
, /* [in] window procedure */
944 HWND hwnd
, /* [in] target window */
945 UINT msg
, /* [in] message */
946 WPARAM wParam
, /* [in] message dependent parameter */
947 LPARAM lParam
/* [in] message dependent parameter */
954 if (!(proc
= handle_to_proc( func
)))
955 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
956 else if (proc
== WINPROC_PROC16
)
957 wow_handlers
.call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
958 else if (proc
->procA
)
959 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
961 WINPROC_CallProcAtoW( call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
,
962 proc
->procW
, WMCHAR_MAP_CALLWINDOWPROC
);
967 /**********************************************************************
968 * CallWindowProcW (USER32.@)
970 * See CallWindowProcA.
972 LRESULT WINAPI
CallWindowProcW( WNDPROC func
, HWND hwnd
, UINT msg
,
973 WPARAM wParam
, LPARAM lParam
)
980 if (!(proc
= handle_to_proc( func
)))
981 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
982 else if (proc
== WINPROC_PROC16
)
983 WINPROC_CallProcWtoA( wow_handlers
.call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
, func
);
984 else if (proc
->procW
)
985 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
987 WINPROC_CallProcWtoA( call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
992 /**********************************************************************
993 * WINPROC_CallDlgProcA
995 INT_PTR
WINPROC_CallDlgProcA( DLGPROC func
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1001 if (!func
) return 0;
1003 if (!(proc
= handle_to_proc( func
)))
1004 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
1005 else if (proc
== WINPROC_PROC16
)
1007 ret
= wow_handlers
.call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
1008 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
1010 else if (proc
->procW
)
1012 ret
= WINPROC_CallProcAtoW( call_dialog_proc
, hwnd
, msg
, wParam
, lParam
, &result
,
1013 proc
->procW
, WMCHAR_MAP_CALLWINDOWPROC
);
1014 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
1017 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
1022 /**********************************************************************
1023 * WINPROC_CallDlgProcW
1025 INT_PTR
WINPROC_CallDlgProcW( DLGPROC func
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1031 if (!func
) return 0;
1033 if (!(proc
= handle_to_proc( func
)))
1034 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
1035 else if (proc
== WINPROC_PROC16
)
1037 ret
= WINPROC_CallProcWtoA( wow_handlers
.call_dialog_proc
, hwnd
, msg
, wParam
, lParam
, &result
, func
);
1038 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
1040 else if (proc
->procA
)
1042 ret
= WINPROC_CallProcWtoA( call_dialog_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
1043 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
1046 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
1051 /***********************************************************************
1052 * Window procedures for builtin classes
1055 static LRESULT WINAPI
ButtonWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1057 return wow_handlers
.button_proc( hwnd
, msg
, wParam
, lParam
, FALSE
);
1060 static LRESULT WINAPI
ButtonWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1062 return wow_handlers
.button_proc( hwnd
, msg
, wParam
, lParam
, TRUE
);
1065 static LRESULT WINAPI
ComboWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1067 return wow_handlers
.combo_proc( hwnd
, message
, wParam
, lParam
, FALSE
);
1070 static LRESULT WINAPI
ComboWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1072 return wow_handlers
.combo_proc( hwnd
, message
, wParam
, lParam
, TRUE
);
1075 LRESULT WINAPI
EditWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1077 return wow_handlers
.edit_proc( hwnd
, msg
, wParam
, lParam
, FALSE
);
1080 static LRESULT WINAPI
EditWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1082 return wow_handlers
.edit_proc( hwnd
, msg
, wParam
, lParam
, TRUE
);
1085 static LRESULT WINAPI
ListBoxWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1087 return wow_handlers
.listbox_proc( hwnd
, msg
, wParam
, lParam
, FALSE
);
1090 static LRESULT WINAPI
ListBoxWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1092 return wow_handlers
.listbox_proc( hwnd
, msg
, wParam
, lParam
, TRUE
);
1095 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1097 return wow_handlers
.mdiclient_proc( hwnd
, msg
, wParam
, lParam
, FALSE
);
1100 static LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1102 return wow_handlers
.mdiclient_proc( hwnd
, msg
, wParam
, lParam
, TRUE
);
1105 static LRESULT WINAPI
ScrollBarWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1107 return wow_handlers
.scrollbar_proc( hwnd
, msg
, wParam
, lParam
, FALSE
);
1110 static LRESULT WINAPI
ScrollBarWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1112 return wow_handlers
.scrollbar_proc( hwnd
, msg
, wParam
, lParam
, TRUE
);
1115 static LRESULT WINAPI
StaticWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1117 return wow_handlers
.static_proc( hwnd
, msg
, wParam
, lParam
, FALSE
);
1120 static LRESULT WINAPI
StaticWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1122 return wow_handlers
.static_proc( hwnd
, msg
, wParam
, lParam
, TRUE
);
1125 static DWORD
wait_message( DWORD count
, CONST HANDLE
*handles
, DWORD timeout
, DWORD mask
, DWORD flags
)
1127 DWORD ret
= USER_Driver
->pMsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
, flags
);
1128 if (ret
== WAIT_TIMEOUT
&& !count
&& !timeout
) NtYieldExecution();
1129 if ((mask
& QS_INPUT
) == QS_INPUT
) get_user_thread_info()->message_count
= 0;
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
->wait_message
= wait_message
;
1149 orig
->create_window
= WIN_CreateWindowEx
;
1150 orig
->get_win_handle
= WIN_GetFullHandle
;
1151 orig
->alloc_winproc
= WINPROC_AllocProc
;
1152 orig
->get_dialog_info
= DIALOG_get_info
;
1153 orig
->dialog_box_loop
= DIALOG_DoDialogBox
;
1154 orig
->get_icon_param
= get_icon_param
;
1155 orig
->set_icon_param
= set_icon_param
;
1157 wow_handlers
= *new;
1160 struct wow_handlers16 wow_handlers
=
1162 ButtonWndProc_common
,
1163 ComboWndProc_common
,
1165 ListBoxWndProc_common
,
1166 MDIClientWndProc_common
,
1167 ScrollBarWndProc_common
,
1168 StaticWndProc_common
,
1171 NULL
, /* call_window_proc */
1172 NULL
, /* call_dialog_proc */
1173 NULL
, /* free_icon_param */