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
32 #include "user_private.h"
34 #include "wine/debug.h"
36 WINE_DECLARE_DEBUG_CHANNEL(msg
);
37 WINE_DECLARE_DEBUG_CHANNEL(relay
);
38 WINE_DEFAULT_DEBUG_CHANNEL(win
);
40 typedef struct tagWINDOWPROC
42 WNDPROC procA
; /* ASCII window proc */
43 WNDPROC procW
; /* Unicode window proc */
46 #define MAX_WINPROCS 4096
47 #define MAX_WINPROC_RECURSION 64
48 #define WINPROC_PROC16 ((WINDOWPROC *)1) /* placeholder for 16-bit window procs */
50 static LRESULT WINAPI
ButtonWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
51 static LRESULT WINAPI
ButtonWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
52 static LRESULT WINAPI
ComboWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
53 static LRESULT WINAPI
ComboWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
54 LRESULT WINAPI
EditWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
55 static LRESULT WINAPI
EditWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
56 static LRESULT WINAPI
ListBoxWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
57 static LRESULT WINAPI
ListBoxWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
58 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
59 static LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
60 static LRESULT WINAPI
ScrollBarWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
61 static LRESULT WINAPI
ScrollBarWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
62 static LRESULT WINAPI
StaticWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
63 static LRESULT WINAPI
StaticWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
65 static WINDOWPROC winproc_array
[MAX_WINPROCS
] =
67 { ButtonWndProcA
, ButtonWndProcW
}, /* WINPROC_BUTTON */
68 { ComboWndProcA
, ComboWndProcW
}, /* WINPROC_COMBO */
69 { DefWindowProcA
, DefWindowProcW
}, /* WINPROC_DEFWND */
70 { DefDlgProcA
, DefDlgProcW
}, /* WINPROC_DIALOG */
71 { EditWndProcA
, EditWndProcW
}, /* WINPROC_EDIT */
72 { ListBoxWndProcA
, ListBoxWndProcW
}, /* WINPROC_LISTBOX */
73 { MDIClientWndProcA
, MDIClientWndProcW
}, /* WINPROC_MDICLIENT */
74 { ScrollBarWndProcA
, ScrollBarWndProcW
}, /* WINPROC_SCROLLBAR */
75 { StaticWndProcA
, StaticWndProcW
}, /* WINPROC_STATIC */
76 { ImeWndProcA
, ImeWndProcW
}, /* WINPROC_IME */
77 { NULL
, DesktopWndProc
}, /* WINPROC_DESKTOP */
78 { NULL
, IconTitleWndProc
}, /* WINPROC_ICONTITLE */
79 { NULL
, PopupMenuWndProc
}, /* WINPROC_MENU */
80 { NULL
, MessageWndProc
}, /* WINPROC_MESSAGE */
83 static UINT winproc_used
= NB_BUILTIN_WINPROCS
;
85 static CRITICAL_SECTION winproc_cs
;
86 static CRITICAL_SECTION_DEBUG critsect_debug
=
89 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
90 0, 0, { (DWORD_PTR
)(__FILE__
": winproc_cs") }
92 static CRITICAL_SECTION winproc_cs
= { &critsect_debug
, -1, 0, 0, 0, 0 };
94 static inline void *get_buffer( void *static_buffer
, size_t size
, size_t need
)
96 if (size
>= need
) return static_buffer
;
97 return HeapAlloc( GetProcessHeap(), 0, need
);
100 static inline void free_buffer( void *static_buffer
, void *buffer
)
102 if (buffer
!= static_buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
105 /* find an existing winproc for a given function and type */
106 /* FIXME: probably should do something more clever than a linear search */
107 static inline WINDOWPROC
*find_winproc( WNDPROC func
, BOOL unicode
)
111 for (i
= 0; i
< NB_BUILTIN_AW_WINPROCS
; i
++)
113 /* match either proc, some apps confuse A and W */
114 if (winproc_array
[i
].procA
!= func
&& winproc_array
[i
].procW
!= func
) continue;
115 return &winproc_array
[i
];
117 for (i
= NB_BUILTIN_AW_WINPROCS
; i
< winproc_used
; i
++)
119 if (!unicode
&& winproc_array
[i
].procA
!= func
) continue;
120 if (unicode
&& winproc_array
[i
].procW
!= func
) continue;
121 return &winproc_array
[i
];
126 /* return the window proc for a given handle, or NULL for an invalid handle,
127 * or WINPROC_PROC16 for a handle to a 16-bit proc. */
128 static inline WINDOWPROC
*handle_to_proc( WNDPROC handle
)
130 UINT index
= LOWORD(handle
);
131 if ((ULONG_PTR
)handle
>> 16 != WINPROC_HANDLE
) return NULL
;
132 if (index
>= MAX_WINPROCS
) return WINPROC_PROC16
;
133 if (index
>= winproc_used
) return NULL
;
134 return &winproc_array
[index
];
137 /* create a handle for a given window proc */
138 static inline WNDPROC
proc_to_handle( WINDOWPROC
*proc
)
140 return (WNDPROC
)(ULONG_PTR
)((proc
- winproc_array
) | (WINPROC_HANDLE
<< 16));
143 /* allocate and initialize a new winproc */
144 static inline WINDOWPROC
*alloc_winproc( WNDPROC func
, BOOL unicode
)
148 /* check if the function is already a win proc */
149 if (!func
) return NULL
;
150 if ((proc
= handle_to_proc( func
))) return proc
;
152 EnterCriticalSection( &winproc_cs
);
154 /* check if we already have a winproc for that function */
155 if (!(proc
= find_winproc( func
, unicode
)))
157 if (winproc_used
< MAX_WINPROCS
)
159 proc
= &winproc_array
[winproc_used
++];
160 if (unicode
) proc
->procW
= func
;
161 else proc
->procA
= func
;
162 TRACE( "allocated %p for %c %p (%d/%d used)\n",
163 proc_to_handle(proc
), unicode
? 'W' : 'A', func
,
164 winproc_used
, MAX_WINPROCS
);
166 else WARN( "too many winprocs, cannot allocate one for %p\n", func
);
168 else TRACE( "reusing %p for %p\n", proc_to_handle(proc
), func
);
170 LeaveCriticalSection( &winproc_cs
);
175 /* Some window procedures modify register they shouldn't, or are not
176 * properly declared stdcall; so we need a small assembly wrapper to
178 extern LRESULT
WINPROC_wrapper( WNDPROC proc
, HWND hwnd
, UINT msg
,
179 WPARAM wParam
, LPARAM lParam
);
180 __ASM_GLOBAL_FUNC( WINPROC_wrapper
,
182 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
183 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
185 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
187 __ASM_CFI(".cfi_rel_offset %edi,-4\n\t")
189 __ASM_CFI(".cfi_rel_offset %esi,-8\n\t")
191 __ASM_CFI(".cfi_rel_offset %ebx,-12\n\t")
192 /* TreePad X Enterprise assumes that edi is < 0x80000000 in WM_TIMER messages */
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
)
236 DPI_AWARENESS_CONTEXT context
;
241 hwnd
= WIN_GetFullHandle( hwnd
);
242 TRACE_(relay
)( "\1Call window proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
243 proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
);
245 context
= SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( hwnd
));
246 *result
= WINPROC_wrapper( proc
, hwnd
, msg
, wp
, lp
);
247 SetThreadDpiAwarenessContext( context
);
249 TRACE_(relay
)( "\1Ret window proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx) retval=%08lx\n",
250 proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
, *result
);
254 /* call a 32-bit dialog procedure */
255 static LRESULT
call_dialog_proc( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
, LRESULT
*result
, void *arg
)
257 DPI_AWARENESS_CONTEXT context
;
263 hwnd
= WIN_GetFullHandle( hwnd
);
264 TRACE_(relay
)( "\1Call dialog proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
265 proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
);
267 context
= SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( hwnd
));
268 ret
= WINPROC_wrapper( proc
, hwnd
, msg
, wp
, lp
);
269 *result
= GetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
);
270 SetThreadDpiAwarenessContext( context
);
272 TRACE_(relay
)( "\1Ret dialog proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx) retval=%08lx result=%08lx\n",
273 proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
, ret
, *result
);
278 /**********************************************************************
281 * Get a window procedure pointer that can be passed to the Windows program.
283 WNDPROC
WINPROC_GetProc( WNDPROC proc
, BOOL unicode
)
285 WINDOWPROC
*ptr
= handle_to_proc( proc
);
287 if (!ptr
|| ptr
== WINPROC_PROC16
) return proc
;
290 if (ptr
->procW
) return ptr
->procW
;
295 if (ptr
->procA
) return ptr
->procA
;
301 /**********************************************************************
304 * Allocate a window procedure for a window or class.
306 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
307 * lot of windows, it will usually only have a limited number of window procedures, so the
308 * array won't grow too large, and this way we avoid the need to track allocations per window.
310 WNDPROC
WINPROC_AllocProc( WNDPROC func
, BOOL unicode
)
314 if (!(proc
= alloc_winproc( func
, unicode
))) return func
;
315 if (proc
== WINPROC_PROC16
) return func
;
316 return proc_to_handle( proc
);
320 /**********************************************************************
323 * Return the window procedure type, or the default value if not a winproc handle.
325 BOOL
WINPROC_IsUnicode( WNDPROC proc
, BOOL def_val
)
327 WINDOWPROC
*ptr
= handle_to_proc( proc
);
329 if (!ptr
) return def_val
;
330 if (ptr
== WINPROC_PROC16
) return FALSE
; /* 16-bit is always A */
331 if (ptr
->procA
&& ptr
->procW
) return def_val
; /* can be both */
332 return (ptr
->procW
!= NULL
);
336 /**********************************************************************
337 * WINPROC_TestLBForStr
339 * Return TRUE if the lparam is a string
341 static inline BOOL
WINPROC_TestLBForStr( HWND hwnd
, UINT msg
)
343 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
344 if (msg
<= CB_MSGMAX
)
345 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
347 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
352 /**********************************************************************
353 * WINPROC_CallProcAtoW
355 * Call a window procedure, translating args from Ansi to Unicode.
357 LRESULT
WINPROC_CallProcAtoW( winproc_callback_t callback
, HWND hwnd
, UINT msg
, WPARAM wParam
,
358 LPARAM lParam
, LRESULT
*result
, void *arg
, enum wm_char_mapping mapping
)
362 TRACE_(msg
)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
363 hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
370 WCHAR
*ptr
, buffer
[512];
371 CREATESTRUCTA
*csA
= (CREATESTRUCTA
*)lParam
;
372 CREATESTRUCTW csW
= *(CREATESTRUCTW
*)csA
;
373 MDICREATESTRUCTW mdi_cs
;
374 DWORD name_lenA
= 0, name_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
376 if (!IS_INTRESOURCE(csA
->lpszClass
))
378 class_lenA
= strlen(csA
->lpszClass
) + 1;
379 RtlMultiByteToUnicodeSize( &class_lenW
, csA
->lpszClass
, class_lenA
);
381 if (!IS_INTRESOURCE(csA
->lpszName
))
383 name_lenA
= strlen(csA
->lpszName
) + 1;
384 RtlMultiByteToUnicodeSize( &name_lenW
, csA
->lpszName
, name_lenA
);
387 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), class_lenW
+ name_lenW
))) break;
392 RtlMultiByteToUnicodeN( ptr
, class_lenW
, NULL
, csA
->lpszClass
, class_lenA
);
396 csW
.lpszName
= ptr
+ class_lenW
/sizeof(WCHAR
);
397 RtlMultiByteToUnicodeN( ptr
+ class_lenW
/sizeof(WCHAR
), name_lenW
, NULL
,
398 csA
->lpszName
, name_lenA
);
401 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
403 mdi_cs
= *(MDICREATESTRUCTW
*)csA
->lpCreateParams
;
404 mdi_cs
.szTitle
= csW
.lpszName
;
405 mdi_cs
.szClass
= csW
.lpszClass
;
406 csW
.lpCreateParams
= &mdi_cs
;
409 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csW
, result
, arg
);
410 free_buffer( buffer
, ptr
);
416 WCHAR
*ptr
, buffer
[512];
417 DWORD title_lenA
= 0, title_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
418 MDICREATESTRUCTA
*csA
= (MDICREATESTRUCTA
*)lParam
;
419 MDICREATESTRUCTW csW
;
421 memcpy( &csW
, csA
, sizeof(csW
) );
423 if (!IS_INTRESOURCE(csA
->szTitle
))
425 title_lenA
= strlen(csA
->szTitle
) + 1;
426 RtlMultiByteToUnicodeSize( &title_lenW
, csA
->szTitle
, title_lenA
);
428 if (!IS_INTRESOURCE(csA
->szClass
))
430 class_lenA
= strlen(csA
->szClass
) + 1;
431 RtlMultiByteToUnicodeSize( &class_lenW
, csA
->szClass
, class_lenA
);
434 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), title_lenW
+ class_lenW
))) break;
439 RtlMultiByteToUnicodeN( ptr
, title_lenW
, NULL
, csA
->szTitle
, title_lenA
);
443 csW
.szClass
= ptr
+ title_lenW
/sizeof(WCHAR
);
444 RtlMultiByteToUnicodeN( ptr
+ title_lenW
/sizeof(WCHAR
), class_lenW
, NULL
,
445 csA
->szClass
, class_lenA
);
447 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csW
, result
, arg
);
448 free_buffer( buffer
, ptr
);
453 case WM_ASKCBFORMATNAME
:
455 WCHAR
*ptr
, buffer
[512];
456 LPSTR str
= (LPSTR
)lParam
;
457 DWORD len
= wParam
* sizeof(WCHAR
);
459 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
))) break;
460 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
465 RtlUnicodeToMultiByteN( str
, wParam
- 1, &len
, ptr
, ret
* sizeof(WCHAR
) );
469 free_buffer( buffer
, ptr
);
474 case LB_INSERTSTRING
:
476 case LB_FINDSTRINGEXACT
:
477 case LB_SELECTSTRING
:
479 case CB_INSERTSTRING
:
481 case CB_FINDSTRINGEXACT
:
482 case CB_SELECTSTRING
:
483 if (!lParam
|| !WINPROC_TestLBForStr( hwnd
, msg
))
485 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
490 case WM_WININICHANGE
:
491 case WM_DEVMODECHANGE
:
496 if (!lParam
) ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
499 WCHAR
*ptr
, buffer
[512];
500 LPCSTR strA
= (LPCSTR
)lParam
;
501 DWORD lenW
, lenA
= strlen(strA
) + 1;
503 RtlMultiByteToUnicodeSize( &lenW
, strA
, lenA
);
504 if ((ptr
= get_buffer( buffer
, sizeof(buffer
), lenW
)))
506 RtlMultiByteToUnicodeN( ptr
, lenW
, NULL
, strA
, lenA
);
507 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
508 free_buffer( buffer
, ptr
);
515 if (lParam
&& WINPROC_TestLBForStr( hwnd
, msg
))
517 WCHAR buffer
[512]; /* FIXME: fixed sized buffer */
519 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)buffer
, result
, arg
);
523 RtlUnicodeToMultiByteN( (LPSTR
)lParam
, ~0u, &len
,
524 buffer
, (lstrlenW(buffer
) + 1) * sizeof(WCHAR
) );
528 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
533 WCHAR
*ptr
, buffer
[512];
534 WORD len
= *(WORD
*)lParam
;
536 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* sizeof(WCHAR
) ))) break;
537 *((WORD
*)ptr
) = len
; /* store the length */
538 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
542 RtlUnicodeToMultiByteN( (LPSTR
)lParam
, len
, &reslen
, ptr
, *result
* sizeof(WCHAR
) );
543 if (reslen
< len
) ((LPSTR
)lParam
)[reslen
] = 0;
546 free_buffer( buffer
, ptr
);
553 MSG newmsg
= *(MSG
*)lParam
;
554 if (map_wparam_AtoW( newmsg
.message
, &newmsg
.wParam
, WMCHAR_MAP_NOMAPPING
))
555 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&newmsg
, result
, arg
);
557 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
566 case EM_SETPASSWORDCHAR
:
568 if (map_wparam_AtoW( msg
, &wParam
, mapping
))
569 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
572 case WM_GETTEXTLENGTH
:
573 case CB_GETLBTEXTLEN
:
575 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
578 WCHAR
*ptr
, buffer
[512];
580 DWORD len
= *result
+ 1;
581 /* Determine respective GETTEXT message */
582 UINT msgGetText
= (msg
== WM_GETTEXTLENGTH
) ? WM_GETTEXT
:
583 ((msg
== CB_GETLBTEXTLEN
) ? CB_GETLBTEXT
: LB_GETTEXT
);
584 /* wParam differs between the messages */
585 WPARAM wp
= (msg
== WM_GETTEXTLENGTH
) ? len
: wParam
;
587 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* sizeof(WCHAR
) ))) break;
589 if (callback
== call_window_proc
) /* FIXME: hack */
590 callback( hwnd
, msgGetText
, wp
, (LPARAM
)ptr
, &tmp
, arg
);
592 tmp
= SendMessageW( hwnd
, msgGetText
, wp
, (LPARAM
)ptr
);
593 RtlUnicodeToMultiByteSize( &len
, ptr
, tmp
* sizeof(WCHAR
) );
595 free_buffer( buffer
, ptr
);
599 case WM_PAINTCLIPBOARD
:
600 case WM_SIZECLIPBOARD
:
601 FIXME_(msg
)( "message %s (0x%x) needs translation, please report\n",
602 SPY_GetMsgName(msg
, hwnd
), msg
);
606 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
613 /**********************************************************************
614 * WINPROC_CallProcWtoA
616 * Call a window procedure, translating args from Unicode to Ansi.
618 static LRESULT
WINPROC_CallProcWtoA( winproc_callback_t callback
, HWND hwnd
, UINT msg
, WPARAM wParam
,
619 LPARAM lParam
, LRESULT
*result
, void *arg
)
623 TRACE_(msg
)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
624 hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
631 char buffer
[1024], *cls
;
632 CREATESTRUCTW
*csW
= (CREATESTRUCTW
*)lParam
;
633 CREATESTRUCTA csA
= *(CREATESTRUCTA
*)csW
;
634 MDICREATESTRUCTA mdi_cs
;
635 DWORD name_lenA
= 0, name_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
637 if (!IS_INTRESOURCE(csW
->lpszClass
))
639 class_lenW
= (lstrlenW(csW
->lpszClass
) + 1) * sizeof(WCHAR
);
640 RtlUnicodeToMultiByteSize(&class_lenA
, csW
->lpszClass
, class_lenW
);
642 if (!IS_INTRESOURCE(csW
->lpszName
))
644 name_lenW
= (lstrlenW(csW
->lpszName
) + 1) * sizeof(WCHAR
);
645 RtlUnicodeToMultiByteSize(&name_lenA
, csW
->lpszName
, name_lenW
);
648 if (!(cls
= get_buffer( buffer
, sizeof(buffer
), class_lenA
+ name_lenA
))) break;
652 RtlUnicodeToMultiByteN(cls
, class_lenA
, NULL
, csW
->lpszClass
, class_lenW
);
657 char *name
= cls
+ class_lenA
;
658 RtlUnicodeToMultiByteN(name
, name_lenA
, NULL
, csW
->lpszName
, name_lenW
);
662 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
664 mdi_cs
= *(MDICREATESTRUCTA
*)csW
->lpCreateParams
;
665 mdi_cs
.szTitle
= csA
.lpszName
;
666 mdi_cs
.szClass
= csA
.lpszClass
;
667 csA
.lpCreateParams
= &mdi_cs
;
670 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csA
, result
, arg
);
671 free_buffer( buffer
, cls
);
676 case WM_ASKCBFORMATNAME
:
678 char *ptr
, buffer
[512];
679 DWORD len
= wParam
* 2;
681 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
))) break;
682 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
687 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, wParam
*sizeof(WCHAR
), &len
, ptr
, ret
+ 1 );
688 *result
= len
/sizeof(WCHAR
) - 1; /* do not count terminating null */
690 ((LPWSTR
)lParam
)[*result
] = 0;
692 free_buffer( buffer
, ptr
);
697 case LB_INSERTSTRING
:
699 case LB_FINDSTRINGEXACT
:
700 case LB_SELECTSTRING
:
702 case CB_INSERTSTRING
:
704 case CB_FINDSTRINGEXACT
:
705 case CB_SELECTSTRING
:
706 if (!lParam
|| !WINPROC_TestLBForStr( hwnd
, msg
))
708 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
713 case WM_WININICHANGE
:
714 case WM_DEVMODECHANGE
:
719 if (!lParam
) ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
722 char *ptr
, buffer
[512];
723 LPCWSTR strW
= (LPCWSTR
)lParam
;
724 DWORD lenA
, lenW
= (lstrlenW(strW
) + 1) * sizeof(WCHAR
);
726 RtlUnicodeToMultiByteSize( &lenA
, strW
, lenW
);
727 if ((ptr
= get_buffer( buffer
, sizeof(buffer
), lenA
)))
729 RtlUnicodeToMultiByteN( ptr
, lenA
, NULL
, strW
, lenW
);
730 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
731 free_buffer( buffer
, ptr
);
738 char *ptr
, buffer
[1024];
739 DWORD title_lenA
= 0, title_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
740 MDICREATESTRUCTW
*csW
= (MDICREATESTRUCTW
*)lParam
;
741 MDICREATESTRUCTA csA
;
743 memcpy( &csA
, csW
, sizeof(csA
) );
745 if (!IS_INTRESOURCE(csW
->szTitle
))
747 title_lenW
= (lstrlenW(csW
->szTitle
) + 1) * sizeof(WCHAR
);
748 RtlUnicodeToMultiByteSize( &title_lenA
, csW
->szTitle
, title_lenW
);
750 if (!IS_INTRESOURCE(csW
->szClass
))
752 class_lenW
= (lstrlenW(csW
->szClass
) + 1) * sizeof(WCHAR
);
753 RtlUnicodeToMultiByteSize( &class_lenA
, csW
->szClass
, class_lenW
);
756 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), title_lenA
+ class_lenA
))) break;
760 RtlUnicodeToMultiByteN( ptr
, title_lenA
, NULL
, csW
->szTitle
, title_lenW
);
765 RtlUnicodeToMultiByteN( ptr
+ title_lenA
, class_lenA
, NULL
, csW
->szClass
, class_lenW
);
766 csA
.szClass
= ptr
+ title_lenA
;
768 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csA
, result
, arg
);
769 free_buffer( buffer
, ptr
);
775 if (lParam
&& WINPROC_TestLBForStr( hwnd
, msg
))
777 char buffer
[512]; /* FIXME: fixed sized buffer */
779 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)buffer
, result
, arg
);
783 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, ~0u, &len
, buffer
, strlen(buffer
) + 1 );
784 *result
= len
/ sizeof(WCHAR
) - 1;
787 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
792 char *ptr
, buffer
[512];
793 WORD len
= *(WORD
*)lParam
;
795 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* 2 ))) break;
796 *((WORD
*)ptr
) = len
* 2; /* store the length */
797 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
801 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, len
*sizeof(WCHAR
), &reslen
, ptr
, *result
);
802 *result
= reslen
/ sizeof(WCHAR
);
803 if (*result
< len
) ((LPWSTR
)lParam
)[*result
] = 0;
805 free_buffer( buffer
, ptr
);
812 MSG newmsg
= *(MSG
*)lParam
;
813 switch(newmsg
.message
)
819 newmsg
.wParam
= map_wparam_char_WtoA( newmsg
.wParam
, 1 );
822 newmsg
.wParam
= map_wparam_char_WtoA( newmsg
.wParam
, 2 );
825 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&newmsg
, result
, arg
);
827 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
834 DWORD cp
= get_input_codepage();
835 DWORD len
= WideCharToMultiByte( cp
, 0, &wch
, 1, ch
, 2, NULL
, NULL
);
836 ret
= callback( hwnd
, msg
, (BYTE
)ch
[0], lParam
, result
, arg
);
837 if (len
== 2) ret
= callback( hwnd
, msg
, (BYTE
)ch
[1], lParam
, result
, arg
);
846 case EM_SETPASSWORDCHAR
:
847 ret
= callback( hwnd
, msg
, map_wparam_char_WtoA(wParam
,1), lParam
, result
, arg
);
851 ret
= callback( hwnd
, msg
, map_wparam_char_WtoA(wParam
,2), lParam
, result
, arg
);
854 case WM_PAINTCLIPBOARD
:
855 case WM_SIZECLIPBOARD
:
856 FIXME_(msg
)( "message %s (%04x) needs translation, please report\n",
857 SPY_GetMsgName(msg
, hwnd
), msg
);
861 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
869 /**********************************************************************
870 * WINPROC_call_window
872 * Call the window procedure of the specified window.
874 BOOL
WINPROC_call_window( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
875 LRESULT
*result
, BOOL unicode
, enum wm_char_mapping mapping
)
877 struct user_thread_info
*thread_info
= get_user_thread_info();
878 BOOL unicode_win
, is_dialog
;
883 if (!(wndPtr
= WIN_GetPtr( hwnd
))) return FALSE
;
884 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
885 if (wndPtr
->tid
!= GetCurrentThreadId())
887 WIN_ReleasePtr( wndPtr
);
890 func
= wndPtr
->winproc
;
891 proc
= handle_to_proc( wndPtr
->winproc
);
892 unicode_win
= wndPtr
->flags
& WIN_ISUNICODE
;
893 is_dialog
= wndPtr
->dlgInfo
!= NULL
;
894 WIN_ReleasePtr( wndPtr
);
896 if (thread_info
->recursion_count
> MAX_WINPROC_RECURSION
) return FALSE
;
897 thread_info
->recursion_count
++;
901 if (proc
== WINPROC_PROC16
)
902 WINPROC_CallProcWtoA( wow_handlers
.call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, func
);
907 if (proc
&& proc
->procW
)
908 call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, proc
->procW
);
910 call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, func
);
914 if (proc
&& proc
->procA
)
915 WINPROC_CallProcWtoA( call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, proc
->procA
);
917 WINPROC_CallProcWtoA( call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, func
);
920 else if (proc
&& proc
->procW
)
921 call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, proc
->procW
);
923 WINPROC_CallProcWtoA( call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, proc
->procA
);
924 else if (unicode_win
)
925 call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, func
);
927 WINPROC_CallProcWtoA( call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, func
);
931 if (proc
== WINPROC_PROC16
)
932 wow_handlers
.call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, func
);
937 if (proc
&& proc
->procW
)
938 WINPROC_CallProcAtoW( call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, proc
->procW
, mapping
);
940 WINPROC_CallProcAtoW( call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, func
, mapping
);
944 if (proc
&& proc
->procA
)
945 call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, proc
->procA
);
947 call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, func
);
950 else if (proc
&& proc
->procA
)
951 call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, proc
->procA
);
953 WINPROC_CallProcAtoW( call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, proc
->procW
, mapping
);
954 else if (unicode_win
)
955 WINPROC_CallProcAtoW( call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, func
, mapping
);
957 call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, func
);
959 thread_info
->recursion_count
--;
964 /**********************************************************************
965 * CallWindowProcA (USER32.@)
967 * The CallWindowProc() function invokes the windows procedure _func_,
968 * with _hwnd_ as the target window, the message specified by _msg_, and
969 * the message parameters _wParam_ and _lParam_.
971 * Some kinds of argument conversion may be done, I'm not sure what.
973 * CallWindowProc() may be used for windows subclassing. Use
974 * SetWindowLong() to set a new windows procedure for windows of the
975 * subclass, and handle subclassed messages in the new windows
976 * procedure. The new windows procedure may then use CallWindowProc()
977 * with _func_ set to the parent class's windows procedure to dispatch
978 * the message to the superclass.
982 * The return value is message dependent.
988 LRESULT WINAPI
CallWindowProcA(
989 WNDPROC func
, /* [in] window procedure */
990 HWND hwnd
, /* [in] target window */
991 UINT msg
, /* [in] message */
992 WPARAM wParam
, /* [in] message dependent parameter */
993 LPARAM lParam
/* [in] message dependent parameter */
1000 if (!(proc
= handle_to_proc( func
)))
1001 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
1002 else if (proc
== WINPROC_PROC16
)
1003 wow_handlers
.call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
1004 else if (proc
->procA
)
1005 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
1007 WINPROC_CallProcAtoW( call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
,
1008 proc
->procW
, WMCHAR_MAP_CALLWINDOWPROC
);
1013 /**********************************************************************
1014 * CallWindowProcW (USER32.@)
1016 * See CallWindowProcA.
1018 LRESULT WINAPI
CallWindowProcW( WNDPROC func
, HWND hwnd
, UINT msg
,
1019 WPARAM wParam
, LPARAM lParam
)
1024 if (!func
) return 0;
1026 if (!(proc
= handle_to_proc( func
)))
1027 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
1028 else if (proc
== WINPROC_PROC16
)
1029 WINPROC_CallProcWtoA( wow_handlers
.call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
, func
);
1030 else if (proc
->procW
)
1031 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
1033 WINPROC_CallProcWtoA( call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
1038 /**********************************************************************
1039 * WINPROC_CallDlgProcA
1041 INT_PTR
WINPROC_CallDlgProcA( DLGPROC func
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1047 if (!func
) return 0;
1049 if (!(proc
= handle_to_proc( func
)))
1050 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
1051 else if (proc
== WINPROC_PROC16
)
1053 ret
= wow_handlers
.call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
1054 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
1057 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
? proc
->procW
: proc
->procA
);
1063 /**********************************************************************
1064 * WINPROC_CallDlgProcW
1066 INT_PTR
WINPROC_CallDlgProcW( DLGPROC func
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1072 if (!func
) return 0;
1074 if (!(proc
= handle_to_proc( func
)))
1075 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
1076 else if (proc
== WINPROC_PROC16
)
1078 ret
= WINPROC_CallProcWtoA( wow_handlers
.call_dialog_proc
, hwnd
, msg
, wParam
, lParam
, &result
, func
);
1079 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
1082 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
? proc
->procW
: proc
->procA
);
1088 /***********************************************************************
1089 * Window procedures for builtin classes
1092 static LRESULT WINAPI
ButtonWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1094 return wow_handlers
.button_proc( hwnd
, msg
, wParam
, lParam
, FALSE
);
1097 static LRESULT WINAPI
ButtonWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1099 return wow_handlers
.button_proc( hwnd
, msg
, wParam
, lParam
, TRUE
);
1102 static LRESULT WINAPI
ComboWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1104 return wow_handlers
.combo_proc( hwnd
, message
, wParam
, lParam
, FALSE
);
1107 static LRESULT WINAPI
ComboWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1109 return wow_handlers
.combo_proc( hwnd
, message
, wParam
, lParam
, TRUE
);
1112 LRESULT WINAPI
EditWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1114 return wow_handlers
.edit_proc( hwnd
, msg
, wParam
, lParam
, FALSE
);
1117 static LRESULT WINAPI
EditWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1119 return wow_handlers
.edit_proc( hwnd
, msg
, wParam
, lParam
, TRUE
);
1122 static LRESULT WINAPI
ListBoxWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1124 return wow_handlers
.listbox_proc( hwnd
, msg
, wParam
, lParam
, FALSE
);
1127 static LRESULT WINAPI
ListBoxWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1129 return wow_handlers
.listbox_proc( hwnd
, msg
, wParam
, lParam
, TRUE
);
1132 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1134 return wow_handlers
.mdiclient_proc( hwnd
, msg
, wParam
, lParam
, FALSE
);
1137 static LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1139 return wow_handlers
.mdiclient_proc( hwnd
, msg
, wParam
, lParam
, TRUE
);
1142 static LRESULT WINAPI
ScrollBarWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1144 return wow_handlers
.scrollbar_proc( hwnd
, msg
, wParam
, lParam
, FALSE
);
1147 static LRESULT WINAPI
ScrollBarWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1149 return wow_handlers
.scrollbar_proc( hwnd
, msg
, wParam
, lParam
, TRUE
);
1152 static LRESULT WINAPI
StaticWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1154 return wow_handlers
.static_proc( hwnd
, msg
, wParam
, lParam
, FALSE
);
1157 static LRESULT WINAPI
StaticWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1159 return wow_handlers
.static_proc( hwnd
, msg
, wParam
, lParam
, TRUE
);
1162 static DWORD
wait_message( DWORD count
, const HANDLE
*handles
, DWORD timeout
, DWORD mask
, DWORD flags
)
1164 DWORD ret
= USER_Driver
->pMsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
, flags
);
1165 if (ret
== WAIT_TIMEOUT
&& !count
&& !timeout
) NtYieldExecution();
1166 if ((mask
& QS_INPUT
) == QS_INPUT
) get_user_thread_info()->message_count
= 0;
1170 /**********************************************************************
1171 * UserRegisterWowHandlers (USER32.@)
1173 * NOTE: no attempt has been made to be compatible here,
1174 * the Windows function is most likely completely different.
1176 void WINAPI
UserRegisterWowHandlers( const struct wow_handlers16
*new, struct wow_handlers32
*orig
)
1178 orig
->button_proc
= ButtonWndProc_common
;
1179 orig
->combo_proc
= ComboWndProc_common
;
1180 orig
->edit_proc
= EditWndProc_common
;
1181 orig
->listbox_proc
= ListBoxWndProc_common
;
1182 orig
->mdiclient_proc
= MDIClientWndProc_common
;
1183 orig
->scrollbar_proc
= ScrollBarWndProc_common
;
1184 orig
->static_proc
= StaticWndProc_common
;
1185 orig
->wait_message
= wait_message
;
1186 orig
->create_window
= WIN_CreateWindowEx
;
1187 orig
->get_win_handle
= WIN_GetFullHandle
;
1188 orig
->alloc_winproc
= WINPROC_AllocProc
;
1189 orig
->get_dialog_info
= DIALOG_get_info
;
1190 orig
->dialog_box_loop
= DIALOG_DoDialogBox
;
1191 orig
->get_icon_param
= get_icon_param
;
1192 orig
->set_icon_param
= set_icon_param
;
1194 wow_handlers
= *new;
1197 struct wow_handlers16 wow_handlers
=
1199 ButtonWndProc_common
,
1200 ComboWndProc_common
,
1202 ListBoxWndProc_common
,
1203 MDIClientWndProc_common
,
1204 ScrollBarWndProc_common
,
1205 StaticWndProc_common
,
1208 NULL
, /* call_window_proc */
1209 NULL
, /* call_dialog_proc */
1210 NULL
, /* free_icon_param */