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 { ImeWndProcA
, ImeWndProcW
}, /* WINPROC_IME */
79 { NULL
, DesktopWndProc
}, /* WINPROC_DESKTOP */
80 { NULL
, IconTitleWndProc
}, /* WINPROC_ICONTITLE */
81 { NULL
, PopupMenuWndProc
}, /* WINPROC_MENU */
82 { NULL
, MessageWndProc
}, /* WINPROC_MESSAGE */
85 static UINT winproc_used
= NB_BUILTIN_WINPROCS
;
87 static CRITICAL_SECTION winproc_cs
;
88 static CRITICAL_SECTION_DEBUG critsect_debug
=
91 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
92 0, 0, { (DWORD_PTR
)(__FILE__
": winproc_cs") }
94 static CRITICAL_SECTION winproc_cs
= { &critsect_debug
, -1, 0, 0, 0, 0 };
96 static inline void *get_buffer( void *static_buffer
, size_t size
, size_t need
)
98 if (size
>= need
) return static_buffer
;
99 return HeapAlloc( GetProcessHeap(), 0, need
);
102 static inline void free_buffer( void *static_buffer
, void *buffer
)
104 if (buffer
!= static_buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
107 /* find an existing winproc for a given function and type */
108 /* FIXME: probably should do something more clever than a linear search */
109 static inline WINDOWPROC
*find_winproc( WNDPROC func
, BOOL unicode
)
113 for (i
= 0; i
< NB_BUILTIN_AW_WINPROCS
; i
++)
115 /* match either proc, some apps confuse A and W */
116 if (winproc_array
[i
].procA
!= func
&& winproc_array
[i
].procW
!= func
) continue;
117 return &winproc_array
[i
];
119 for (i
= NB_BUILTIN_AW_WINPROCS
; i
< winproc_used
; i
++)
121 if (!unicode
&& winproc_array
[i
].procA
!= func
) continue;
122 if (unicode
&& winproc_array
[i
].procW
!= func
) continue;
123 return &winproc_array
[i
];
128 /* return the window proc for a given handle, or NULL for an invalid handle,
129 * or WINPROC_PROC16 for a handle to a 16-bit proc. */
130 static inline WINDOWPROC
*handle_to_proc( WNDPROC handle
)
132 UINT index
= LOWORD(handle
);
133 if ((ULONG_PTR
)handle
>> 16 != WINPROC_HANDLE
) return NULL
;
134 if (index
>= MAX_WINPROCS
) return WINPROC_PROC16
;
135 if (index
>= winproc_used
) return NULL
;
136 return &winproc_array
[index
];
139 /* create a handle for a given window proc */
140 static inline WNDPROC
proc_to_handle( WINDOWPROC
*proc
)
142 return (WNDPROC
)(ULONG_PTR
)((proc
- winproc_array
) | (WINPROC_HANDLE
<< 16));
145 /* allocate and initialize a new winproc */
146 static inline WINDOWPROC
*alloc_winproc( WNDPROC func
, BOOL unicode
)
150 /* check if the function is already a win proc */
151 if (!func
) return NULL
;
152 if ((proc
= handle_to_proc( func
))) return proc
;
154 EnterCriticalSection( &winproc_cs
);
156 /* check if we already have a winproc for that function */
157 if (!(proc
= find_winproc( func
, unicode
)))
159 if (winproc_used
< MAX_WINPROCS
)
161 proc
= &winproc_array
[winproc_used
++];
162 if (unicode
) proc
->procW
= func
;
163 else proc
->procA
= func
;
164 TRACE( "allocated %p for %c %p (%d/%d used)\n",
165 proc_to_handle(proc
), unicode
? 'W' : 'A', func
,
166 winproc_used
, MAX_WINPROCS
);
168 else WARN( "too many winprocs, cannot allocate one for %p\n", func
);
170 else TRACE( "reusing %p for %p\n", proc_to_handle(proc
), func
);
172 LeaveCriticalSection( &winproc_cs
);
177 /* Some window procedures modify register they shouldn't, or are not
178 * properly declared stdcall; so we need a small assembly wrapper to
180 extern LRESULT
WINPROC_wrapper( WNDPROC proc
, HWND hwnd
, UINT msg
,
181 WPARAM wParam
, LPARAM lParam
);
182 __ASM_GLOBAL_FUNC( WINPROC_wrapper
,
184 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
185 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
187 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
189 __ASM_CFI(".cfi_rel_offset %edi,-4\n\t")
191 __ASM_CFI(".cfi_rel_offset %esi,-8\n\t")
193 __ASM_CFI(".cfi_rel_offset %ebx,-12\n\t")
199 "movl 8(%ebp),%eax\n\t"
201 "leal -12(%ebp),%esp\n\t"
203 __ASM_CFI(".cfi_same_value %ebx\n\t")
205 __ASM_CFI(".cfi_same_value %esi\n\t")
207 __ASM_CFI(".cfi_same_value %edi\n\t")
209 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
210 __ASM_CFI(".cfi_same_value %ebp\n\t")
213 static inline LRESULT
WINPROC_wrapper( WNDPROC proc
, HWND hwnd
, UINT msg
,
214 WPARAM wParam
, LPARAM lParam
)
216 return proc( hwnd
, msg
, wParam
, lParam
);
218 #endif /* __i386__ */
220 static WPARAM
map_wparam_char_WtoA( WPARAM wParam
, DWORD len
)
224 DWORD cp
= get_input_codepage();
226 len
= WideCharToMultiByte( cp
, 0, &wch
, 1, (LPSTR
)ch
, len
, NULL
, NULL
);
228 return MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(wParam
) );
230 return MAKEWPARAM( ch
[0], HIWORD(wParam
) );
233 /* call a 32-bit window procedure */
234 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
, LRESULT
*result
, void *arg
)
240 hwnd
= WIN_GetFullHandle( hwnd
);
241 TRACE_(relay
)( "\1Call window proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
242 proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
);
244 *result
= WINPROC_wrapper( proc
, hwnd
, msg
, wp
, lp
);
246 TRACE_(relay
)( "\1Ret window proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx) retval=%08lx\n",
247 proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
, *result
);
251 /* call a 32-bit dialog procedure */
252 static LRESULT
call_dialog_proc( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
, LRESULT
*result
, void *arg
)
259 hwnd
= WIN_GetFullHandle( hwnd
);
260 TRACE_(relay
)( "\1Call dialog proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
261 proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
);
263 ret
= WINPROC_wrapper( proc
, hwnd
, msg
, wp
, lp
);
264 *result
= GetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
);
266 TRACE_(relay
)( "\1Ret dialog proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx) retval=%08lx result=%08lx\n",
267 proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
, ret
, *result
);
272 /**********************************************************************
275 * Get a window procedure pointer that can be passed to the Windows program.
277 WNDPROC
WINPROC_GetProc( WNDPROC proc
, BOOL unicode
)
279 WINDOWPROC
*ptr
= handle_to_proc( proc
);
281 if (!ptr
|| ptr
== WINPROC_PROC16
) return proc
;
284 if (ptr
->procW
) return ptr
->procW
;
289 if (ptr
->procA
) return ptr
->procA
;
295 /**********************************************************************
298 * Allocate a window procedure for a window or class.
300 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
301 * lot of windows, it will usually only have a limited number of window procedures, so the
302 * array won't grow too large, and this way we avoid the need to track allocations per window.
304 WNDPROC
WINPROC_AllocProc( WNDPROC func
, BOOL unicode
)
308 if (!(proc
= alloc_winproc( func
, unicode
))) return func
;
309 if (proc
== WINPROC_PROC16
) return func
;
310 return proc_to_handle( proc
);
314 /**********************************************************************
317 * Return the window procedure type, or the default value if not a winproc handle.
319 BOOL
WINPROC_IsUnicode( WNDPROC proc
, BOOL def_val
)
321 WINDOWPROC
*ptr
= handle_to_proc( proc
);
323 if (!ptr
) return def_val
;
324 if (ptr
== WINPROC_PROC16
) return FALSE
; /* 16-bit is always A */
325 if (ptr
->procA
&& ptr
->procW
) return def_val
; /* can be both */
326 return (ptr
->procW
!= NULL
);
330 /**********************************************************************
331 * WINPROC_TestLBForStr
333 * Return TRUE if the lparam is a string
335 static inline BOOL
WINPROC_TestLBForStr( HWND hwnd
, UINT msg
)
337 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
338 if (msg
<= CB_MSGMAX
)
339 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
341 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
346 /**********************************************************************
347 * WINPROC_CallProcAtoW
349 * Call a window procedure, translating args from Ansi to Unicode.
351 LRESULT
WINPROC_CallProcAtoW( winproc_callback_t callback
, HWND hwnd
, UINT msg
, WPARAM wParam
,
352 LPARAM lParam
, LRESULT
*result
, void *arg
, enum wm_char_mapping mapping
)
356 TRACE_(msg
)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
357 hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
364 WCHAR
*ptr
, buffer
[512];
365 CREATESTRUCTA
*csA
= (CREATESTRUCTA
*)lParam
;
366 CREATESTRUCTW csW
= *(CREATESTRUCTW
*)csA
;
367 MDICREATESTRUCTW mdi_cs
;
368 DWORD name_lenA
= 0, name_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
370 if (!IS_INTRESOURCE(csA
->lpszClass
))
372 class_lenA
= strlen(csA
->lpszClass
) + 1;
373 RtlMultiByteToUnicodeSize( &class_lenW
, csA
->lpszClass
, class_lenA
);
375 if (!IS_INTRESOURCE(csA
->lpszName
))
377 name_lenA
= strlen(csA
->lpszName
) + 1;
378 RtlMultiByteToUnicodeSize( &name_lenW
, csA
->lpszName
, name_lenA
);
381 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), class_lenW
+ name_lenW
))) break;
386 RtlMultiByteToUnicodeN( ptr
, class_lenW
, NULL
, csA
->lpszClass
, class_lenA
);
390 csW
.lpszName
= ptr
+ class_lenW
/sizeof(WCHAR
);
391 RtlMultiByteToUnicodeN( ptr
+ class_lenW
/sizeof(WCHAR
), name_lenW
, NULL
,
392 csA
->lpszName
, name_lenA
);
395 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
397 mdi_cs
= *(MDICREATESTRUCTW
*)csA
->lpCreateParams
;
398 mdi_cs
.szTitle
= csW
.lpszName
;
399 mdi_cs
.szClass
= csW
.lpszClass
;
400 csW
.lpCreateParams
= &mdi_cs
;
403 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csW
, result
, arg
);
404 free_buffer( buffer
, ptr
);
410 WCHAR
*ptr
, buffer
[512];
411 DWORD title_lenA
= 0, title_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
412 MDICREATESTRUCTA
*csA
= (MDICREATESTRUCTA
*)lParam
;
413 MDICREATESTRUCTW csW
;
415 memcpy( &csW
, csA
, sizeof(csW
) );
417 if (!IS_INTRESOURCE(csA
->szTitle
))
419 title_lenA
= strlen(csA
->szTitle
) + 1;
420 RtlMultiByteToUnicodeSize( &title_lenW
, csA
->szTitle
, title_lenA
);
422 if (!IS_INTRESOURCE(csA
->szClass
))
424 class_lenA
= strlen(csA
->szClass
) + 1;
425 RtlMultiByteToUnicodeSize( &class_lenW
, csA
->szClass
, class_lenA
);
428 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), title_lenW
+ class_lenW
))) break;
433 RtlMultiByteToUnicodeN( ptr
, title_lenW
, NULL
, csA
->szTitle
, title_lenA
);
437 csW
.szClass
= ptr
+ title_lenW
/sizeof(WCHAR
);
438 RtlMultiByteToUnicodeN( ptr
+ title_lenW
/sizeof(WCHAR
), class_lenW
, NULL
,
439 csA
->szClass
, class_lenA
);
441 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csW
, result
, arg
);
442 free_buffer( buffer
, ptr
);
447 case WM_ASKCBFORMATNAME
:
449 WCHAR
*ptr
, buffer
[512];
450 LPSTR str
= (LPSTR
)lParam
;
451 DWORD len
= wParam
* sizeof(WCHAR
);
453 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
))) break;
454 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
459 RtlUnicodeToMultiByteN( str
, wParam
- 1, &len
, ptr
, ret
* sizeof(WCHAR
) );
463 free_buffer( buffer
, ptr
);
468 case LB_INSERTSTRING
:
470 case LB_FINDSTRINGEXACT
:
471 case LB_SELECTSTRING
:
473 case CB_INSERTSTRING
:
475 case CB_FINDSTRINGEXACT
:
476 case CB_SELECTSTRING
:
477 if (!lParam
|| !WINPROC_TestLBForStr( hwnd
, msg
))
479 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
484 case WM_WININICHANGE
:
485 case WM_DEVMODECHANGE
:
490 if (!lParam
) ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
493 WCHAR
*ptr
, buffer
[512];
494 LPCSTR strA
= (LPCSTR
)lParam
;
495 DWORD lenW
, lenA
= strlen(strA
) + 1;
497 RtlMultiByteToUnicodeSize( &lenW
, strA
, lenA
);
498 if ((ptr
= get_buffer( buffer
, sizeof(buffer
), lenW
)))
500 RtlMultiByteToUnicodeN( ptr
, lenW
, NULL
, strA
, lenA
);
501 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
502 free_buffer( buffer
, ptr
);
509 if (lParam
&& WINPROC_TestLBForStr( hwnd
, msg
))
511 WCHAR buffer
[512]; /* FIXME: fixed sized buffer */
513 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)buffer
, result
, arg
);
517 RtlUnicodeToMultiByteN( (LPSTR
)lParam
, ~0u, &len
,
518 buffer
, (strlenW(buffer
) + 1) * sizeof(WCHAR
) );
522 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
527 WCHAR
*ptr
, buffer
[512];
528 WORD len
= *(WORD
*)lParam
;
530 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* sizeof(WCHAR
) ))) break;
531 *((WORD
*)ptr
) = len
; /* store the length */
532 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
536 RtlUnicodeToMultiByteN( (LPSTR
)lParam
, len
, &reslen
, ptr
, *result
* sizeof(WCHAR
) );
537 if (reslen
< len
) ((LPSTR
)lParam
)[reslen
] = 0;
540 free_buffer( buffer
, ptr
);
547 MSG newmsg
= *(MSG
*)lParam
;
548 if (map_wparam_AtoW( newmsg
.message
, &newmsg
.wParam
, WMCHAR_MAP_NOMAPPING
))
549 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&newmsg
, result
, arg
);
551 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
560 case EM_SETPASSWORDCHAR
:
562 if (map_wparam_AtoW( msg
, &wParam
, mapping
))
563 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
566 case WM_GETTEXTLENGTH
:
567 case CB_GETLBTEXTLEN
:
569 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
572 WCHAR
*ptr
, buffer
[512];
574 DWORD len
= *result
+ 1;
575 /* Determine respective GETTEXT message */
576 UINT msgGetText
= (msg
== WM_GETTEXTLENGTH
) ? WM_GETTEXT
:
577 ((msg
== CB_GETLBTEXTLEN
) ? CB_GETLBTEXT
: LB_GETTEXT
);
578 /* wParam differs between the messages */
579 WPARAM wp
= (msg
== WM_GETTEXTLENGTH
) ? len
: wParam
;
581 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* sizeof(WCHAR
) ))) break;
583 if (callback
== call_window_proc
) /* FIXME: hack */
584 callback( hwnd
, msgGetText
, wp
, (LPARAM
)ptr
, &tmp
, arg
);
586 tmp
= SendMessageW( hwnd
, msgGetText
, wp
, (LPARAM
)ptr
);
587 RtlUnicodeToMultiByteSize( &len
, ptr
, tmp
* sizeof(WCHAR
) );
589 free_buffer( buffer
, ptr
);
593 case WM_PAINTCLIPBOARD
:
594 case WM_SIZECLIPBOARD
:
595 FIXME_(msg
)( "message %s (0x%x) needs translation, please report\n",
596 SPY_GetMsgName(msg
, hwnd
), msg
);
600 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
607 /**********************************************************************
608 * WINPROC_CallProcWtoA
610 * Call a window procedure, translating args from Unicode to Ansi.
612 static LRESULT
WINPROC_CallProcWtoA( winproc_callback_t callback
, HWND hwnd
, UINT msg
, WPARAM wParam
,
613 LPARAM lParam
, LRESULT
*result
, void *arg
)
617 TRACE_(msg
)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
618 hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
625 char buffer
[1024], *cls
;
626 CREATESTRUCTW
*csW
= (CREATESTRUCTW
*)lParam
;
627 CREATESTRUCTA csA
= *(CREATESTRUCTA
*)csW
;
628 MDICREATESTRUCTA mdi_cs
;
629 DWORD name_lenA
= 0, name_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
631 if (!IS_INTRESOURCE(csW
->lpszClass
))
633 class_lenW
= (strlenW(csW
->lpszClass
) + 1) * sizeof(WCHAR
);
634 RtlUnicodeToMultiByteSize(&class_lenA
, csW
->lpszClass
, class_lenW
);
636 if (!IS_INTRESOURCE(csW
->lpszName
))
638 name_lenW
= (strlenW(csW
->lpszName
) + 1) * sizeof(WCHAR
);
639 RtlUnicodeToMultiByteSize(&name_lenA
, csW
->lpszName
, name_lenW
);
642 if (!(cls
= get_buffer( buffer
, sizeof(buffer
), class_lenA
+ name_lenA
))) break;
646 RtlUnicodeToMultiByteN(cls
, class_lenA
, NULL
, csW
->lpszClass
, class_lenW
);
651 char *name
= cls
+ class_lenA
;
652 RtlUnicodeToMultiByteN(name
, name_lenA
, NULL
, csW
->lpszName
, name_lenW
);
656 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
658 mdi_cs
= *(MDICREATESTRUCTA
*)csW
->lpCreateParams
;
659 mdi_cs
.szTitle
= csA
.lpszName
;
660 mdi_cs
.szClass
= csA
.lpszClass
;
661 csA
.lpCreateParams
= &mdi_cs
;
664 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csA
, result
, arg
);
665 free_buffer( buffer
, cls
);
670 case WM_ASKCBFORMATNAME
:
672 char *ptr
, buffer
[512];
673 DWORD len
= wParam
* 2;
675 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
))) break;
676 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
681 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, wParam
*sizeof(WCHAR
), &len
, ptr
, ret
+ 1 );
682 *result
= len
/sizeof(WCHAR
) - 1; /* do not count terminating null */
684 ((LPWSTR
)lParam
)[*result
] = 0;
686 free_buffer( buffer
, ptr
);
691 case LB_INSERTSTRING
:
693 case LB_FINDSTRINGEXACT
:
694 case LB_SELECTSTRING
:
696 case CB_INSERTSTRING
:
698 case CB_FINDSTRINGEXACT
:
699 case CB_SELECTSTRING
:
700 if (!lParam
|| !WINPROC_TestLBForStr( hwnd
, msg
))
702 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
707 case WM_WININICHANGE
:
708 case WM_DEVMODECHANGE
:
713 if (!lParam
) ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
716 char *ptr
, buffer
[512];
717 LPCWSTR strW
= (LPCWSTR
)lParam
;
718 DWORD lenA
, lenW
= (strlenW(strW
) + 1) * sizeof(WCHAR
);
720 RtlUnicodeToMultiByteSize( &lenA
, strW
, lenW
);
721 if ((ptr
= get_buffer( buffer
, sizeof(buffer
), lenA
)))
723 RtlUnicodeToMultiByteN( ptr
, lenA
, NULL
, strW
, lenW
);
724 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
725 free_buffer( buffer
, ptr
);
732 char *ptr
, buffer
[1024];
733 DWORD title_lenA
= 0, title_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
734 MDICREATESTRUCTW
*csW
= (MDICREATESTRUCTW
*)lParam
;
735 MDICREATESTRUCTA csA
;
737 memcpy( &csA
, csW
, sizeof(csA
) );
739 if (!IS_INTRESOURCE(csW
->szTitle
))
741 title_lenW
= (strlenW(csW
->szTitle
) + 1) * sizeof(WCHAR
);
742 RtlUnicodeToMultiByteSize( &title_lenA
, csW
->szTitle
, title_lenW
);
744 if (!IS_INTRESOURCE(csW
->szClass
))
746 class_lenW
= (strlenW(csW
->szClass
) + 1) * sizeof(WCHAR
);
747 RtlUnicodeToMultiByteSize( &class_lenA
, csW
->szClass
, class_lenW
);
750 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), title_lenA
+ class_lenA
))) break;
754 RtlUnicodeToMultiByteN( ptr
, title_lenA
, NULL
, csW
->szTitle
, title_lenW
);
759 RtlUnicodeToMultiByteN( ptr
+ title_lenA
, class_lenA
, NULL
, csW
->szClass
, class_lenW
);
760 csA
.szClass
= ptr
+ title_lenA
;
762 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csA
, result
, arg
);
763 free_buffer( buffer
, ptr
);
769 if (lParam
&& WINPROC_TestLBForStr( hwnd
, msg
))
771 char buffer
[512]; /* FIXME: fixed sized buffer */
773 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)buffer
, result
, arg
);
777 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, ~0u, &len
, buffer
, strlen(buffer
) + 1 );
778 *result
= len
/ sizeof(WCHAR
) - 1;
781 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
786 char *ptr
, buffer
[512];
787 WORD len
= *(WORD
*)lParam
;
789 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* 2 ))) break;
790 *((WORD
*)ptr
) = len
* 2; /* store the length */
791 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
795 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, len
*sizeof(WCHAR
), &reslen
, ptr
, *result
);
796 *result
= reslen
/ sizeof(WCHAR
);
797 if (*result
< len
) ((LPWSTR
)lParam
)[*result
] = 0;
799 free_buffer( buffer
, ptr
);
806 MSG newmsg
= *(MSG
*)lParam
;
807 switch(newmsg
.message
)
813 newmsg
.wParam
= map_wparam_char_WtoA( newmsg
.wParam
, 1 );
816 newmsg
.wParam
= map_wparam_char_WtoA( newmsg
.wParam
, 2 );
819 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&newmsg
, result
, arg
);
821 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
828 DWORD cp
= get_input_codepage();
829 DWORD len
= WideCharToMultiByte( cp
, 0, &wch
, 1, ch
, 2, NULL
, NULL
);
830 ret
= callback( hwnd
, msg
, (BYTE
)ch
[0], lParam
, result
, arg
);
831 if (len
== 2) ret
= callback( hwnd
, msg
, (BYTE
)ch
[1], lParam
, result
, arg
);
840 case EM_SETPASSWORDCHAR
:
841 ret
= callback( hwnd
, msg
, map_wparam_char_WtoA(wParam
,1), lParam
, result
, arg
);
845 ret
= callback( hwnd
, msg
, map_wparam_char_WtoA(wParam
,2), lParam
, result
, arg
);
848 case WM_PAINTCLIPBOARD
:
849 case WM_SIZECLIPBOARD
:
850 FIXME_(msg
)( "message %s (%04x) needs translation, please report\n",
851 SPY_GetMsgName(msg
, hwnd
), msg
);
855 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
863 /**********************************************************************
864 * WINPROC_call_window
866 * Call the window procedure of the specified window.
868 BOOL
WINPROC_call_window( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
869 LRESULT
*result
, BOOL unicode
, enum wm_char_mapping mapping
)
871 struct user_thread_info
*thread_info
= get_user_thread_info();
872 BOOL unicode_win
, is_dialog
;
877 if (!(wndPtr
= WIN_GetPtr( hwnd
))) return FALSE
;
878 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
879 if (wndPtr
->tid
!= GetCurrentThreadId())
881 WIN_ReleasePtr( wndPtr
);
884 func
= wndPtr
->winproc
;
885 proc
= handle_to_proc( wndPtr
->winproc
);
886 unicode_win
= wndPtr
->flags
& WIN_ISUNICODE
;
887 is_dialog
= wndPtr
->dlgInfo
!= NULL
;
888 WIN_ReleasePtr( wndPtr
);
890 if (thread_info
->recursion_count
> MAX_WINPROC_RECURSION
) return FALSE
;
891 thread_info
->recursion_count
++;
895 if (proc
== WINPROC_PROC16
)
896 WINPROC_CallProcWtoA( wow_handlers
.call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, func
);
901 if (proc
&& proc
->procW
)
902 call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, proc
->procW
);
904 call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, func
);
908 if (proc
&& proc
->procA
)
909 WINPROC_CallProcWtoA( call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, proc
->procA
);
911 WINPROC_CallProcWtoA( call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, func
);
914 else if (proc
&& proc
->procW
)
915 call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, proc
->procW
);
917 WINPROC_CallProcWtoA( call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, proc
->procA
);
918 else if (unicode_win
)
919 call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, func
);
921 WINPROC_CallProcWtoA( call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, func
);
925 if (proc
== WINPROC_PROC16
)
926 wow_handlers
.call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, func
);
931 if (proc
&& proc
->procW
)
932 WINPROC_CallProcAtoW( call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, proc
->procW
, mapping
);
934 WINPROC_CallProcAtoW( call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, func
, mapping
);
938 if (proc
&& proc
->procA
)
939 call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, proc
->procA
);
941 call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, func
);
944 else if (proc
&& proc
->procA
)
945 call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, proc
->procA
);
947 WINPROC_CallProcAtoW( call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, proc
->procW
, mapping
);
948 else if (unicode_win
)
949 WINPROC_CallProcAtoW( call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, func
, mapping
);
951 call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, func
);
953 thread_info
->recursion_count
--;
958 /**********************************************************************
959 * CallWindowProcA (USER32.@)
961 * The CallWindowProc() function invokes the windows procedure _func_,
962 * with _hwnd_ as the target window, the message specified by _msg_, and
963 * the message parameters _wParam_ and _lParam_.
965 * Some kinds of argument conversion may be done, I'm not sure what.
967 * CallWindowProc() may be used for windows subclassing. Use
968 * SetWindowLong() to set a new windows procedure for windows of the
969 * subclass, and handle subclassed messages in the new windows
970 * procedure. The new windows procedure may then use CallWindowProc()
971 * with _func_ set to the parent class's windows procedure to dispatch
972 * the message to the superclass.
976 * The return value is message dependent.
982 LRESULT WINAPI
CallWindowProcA(
983 WNDPROC func
, /* [in] window procedure */
984 HWND hwnd
, /* [in] target window */
985 UINT msg
, /* [in] message */
986 WPARAM wParam
, /* [in] message dependent parameter */
987 LPARAM lParam
/* [in] message dependent parameter */
994 if (!(proc
= handle_to_proc( func
)))
995 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
996 else if (proc
== WINPROC_PROC16
)
997 wow_handlers
.call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
998 else if (proc
->procA
)
999 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
1001 WINPROC_CallProcAtoW( call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
,
1002 proc
->procW
, WMCHAR_MAP_CALLWINDOWPROC
);
1007 /**********************************************************************
1008 * CallWindowProcW (USER32.@)
1010 * See CallWindowProcA.
1012 LRESULT WINAPI
CallWindowProcW( WNDPROC func
, HWND hwnd
, UINT msg
,
1013 WPARAM wParam
, LPARAM lParam
)
1018 if (!func
) return 0;
1020 if (!(proc
= handle_to_proc( func
)))
1021 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
1022 else if (proc
== WINPROC_PROC16
)
1023 WINPROC_CallProcWtoA( wow_handlers
.call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
, func
);
1024 else if (proc
->procW
)
1025 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
1027 WINPROC_CallProcWtoA( call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
1032 /**********************************************************************
1033 * WINPROC_CallDlgProcA
1035 INT_PTR
WINPROC_CallDlgProcA( DLGPROC func
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1041 if (!func
) return 0;
1043 if (!(proc
= handle_to_proc( func
)))
1044 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
1045 else if (proc
== WINPROC_PROC16
)
1047 ret
= wow_handlers
.call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
1048 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
1051 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
? proc
->procW
: proc
->procA
);
1057 /**********************************************************************
1058 * WINPROC_CallDlgProcW
1060 INT_PTR
WINPROC_CallDlgProcW( DLGPROC func
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1066 if (!func
) return 0;
1068 if (!(proc
= handle_to_proc( func
)))
1069 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
1070 else if (proc
== WINPROC_PROC16
)
1072 ret
= WINPROC_CallProcWtoA( wow_handlers
.call_dialog_proc
, hwnd
, msg
, wParam
, lParam
, &result
, func
);
1073 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
1076 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
? proc
->procW
: proc
->procA
);
1082 /***********************************************************************
1083 * Window procedures for builtin classes
1086 static LRESULT WINAPI
ButtonWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1088 return wow_handlers
.button_proc( hwnd
, msg
, wParam
, lParam
, FALSE
);
1091 static LRESULT WINAPI
ButtonWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1093 return wow_handlers
.button_proc( hwnd
, msg
, wParam
, lParam
, TRUE
);
1096 static LRESULT WINAPI
ComboWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1098 return wow_handlers
.combo_proc( hwnd
, message
, wParam
, lParam
, FALSE
);
1101 static LRESULT WINAPI
ComboWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1103 return wow_handlers
.combo_proc( hwnd
, message
, wParam
, lParam
, TRUE
);
1106 LRESULT WINAPI
EditWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1108 return wow_handlers
.edit_proc( hwnd
, msg
, wParam
, lParam
, FALSE
);
1111 static LRESULT WINAPI
EditWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1113 return wow_handlers
.edit_proc( hwnd
, msg
, wParam
, lParam
, TRUE
);
1116 static LRESULT WINAPI
ListBoxWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1118 return wow_handlers
.listbox_proc( hwnd
, msg
, wParam
, lParam
, FALSE
);
1121 static LRESULT WINAPI
ListBoxWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1123 return wow_handlers
.listbox_proc( hwnd
, msg
, wParam
, lParam
, TRUE
);
1126 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1128 return wow_handlers
.mdiclient_proc( hwnd
, msg
, wParam
, lParam
, FALSE
);
1131 static LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1133 return wow_handlers
.mdiclient_proc( hwnd
, msg
, wParam
, lParam
, TRUE
);
1136 static LRESULT WINAPI
ScrollBarWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1138 return wow_handlers
.scrollbar_proc( hwnd
, msg
, wParam
, lParam
, FALSE
);
1141 static LRESULT WINAPI
ScrollBarWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1143 return wow_handlers
.scrollbar_proc( hwnd
, msg
, wParam
, lParam
, TRUE
);
1146 static LRESULT WINAPI
StaticWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1148 return wow_handlers
.static_proc( hwnd
, msg
, wParam
, lParam
, FALSE
);
1151 static LRESULT WINAPI
StaticWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1153 return wow_handlers
.static_proc( hwnd
, msg
, wParam
, lParam
, TRUE
);
1156 static DWORD
wait_message( DWORD count
, const HANDLE
*handles
, DWORD timeout
, DWORD mask
, DWORD flags
)
1158 DWORD ret
= USER_Driver
->pMsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
, flags
);
1159 if (ret
== WAIT_TIMEOUT
&& !count
&& !timeout
) NtYieldExecution();
1160 if ((mask
& QS_INPUT
) == QS_INPUT
) get_user_thread_info()->message_count
= 0;
1164 /**********************************************************************
1165 * UserRegisterWowHandlers (USER32.@)
1167 * NOTE: no attempt has been made to be compatible here,
1168 * the Windows function is most likely completely different.
1170 void WINAPI
UserRegisterWowHandlers( const struct wow_handlers16
*new, struct wow_handlers32
*orig
)
1172 orig
->button_proc
= ButtonWndProc_common
;
1173 orig
->combo_proc
= ComboWndProc_common
;
1174 orig
->edit_proc
= EditWndProc_common
;
1175 orig
->listbox_proc
= ListBoxWndProc_common
;
1176 orig
->mdiclient_proc
= MDIClientWndProc_common
;
1177 orig
->scrollbar_proc
= ScrollBarWndProc_common
;
1178 orig
->static_proc
= StaticWndProc_common
;
1179 orig
->wait_message
= wait_message
;
1180 orig
->create_window
= WIN_CreateWindowEx
;
1181 orig
->get_win_handle
= WIN_GetFullHandle
;
1182 orig
->alloc_winproc
= WINPROC_AllocProc
;
1183 orig
->get_dialog_info
= DIALOG_get_info
;
1184 orig
->dialog_box_loop
= DIALOG_DoDialogBox
;
1185 orig
->get_icon_param
= get_icon_param
;
1186 orig
->set_icon_param
= set_icon_param
;
1188 wow_handlers
= *new;
1191 struct wow_handlers16 wow_handlers
=
1193 ButtonWndProc_common
,
1194 ComboWndProc_common
,
1196 ListBoxWndProc_common
,
1197 MDIClientWndProc_common
,
1198 ScrollBarWndProc_common
,
1199 StaticWndProc_common
,
1202 NULL
, /* call_window_proc */
1203 NULL
, /* call_dialog_proc */
1204 NULL
, /* free_icon_param */