2 * Window procedure callbacks
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1996 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
33 #include "user_private.h"
34 #include "wine/unicode.h"
35 #include "wine/debug.h"
37 WINE_DECLARE_DEBUG_CHANNEL(msg
);
38 WINE_DECLARE_DEBUG_CHANNEL(relay
);
39 WINE_DEFAULT_DEBUG_CHANNEL(win
);
41 typedef struct tagWINDOWPROC
43 WNDPROC procA
; /* ASCII window proc */
44 WNDPROC procW
; /* Unicode window proc */
47 #define MAX_WINPROCS 4096
48 #define MAX_WINPROC_RECURSION 64
49 #define WINPROC_PROC16 ((WINDOWPROC *)1) /* placeholder for 16-bit window procs */
51 static LRESULT WINAPI
ButtonWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
52 static LRESULT WINAPI
ButtonWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
53 static LRESULT WINAPI
ComboWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
54 static LRESULT WINAPI
ComboWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
55 LRESULT WINAPI
EditWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
56 static LRESULT WINAPI
EditWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
57 static LRESULT WINAPI
ListBoxWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
58 static LRESULT WINAPI
ListBoxWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
59 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
60 static LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
61 static LRESULT WINAPI
ScrollBarWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
62 static LRESULT WINAPI
ScrollBarWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
63 static LRESULT WINAPI
StaticWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
64 static LRESULT WINAPI
StaticWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
66 static WINDOWPROC winproc_array
[MAX_WINPROCS
] =
68 { ButtonWndProcA
, ButtonWndProcW
}, /* WINPROC_BUTTON */
69 { ComboWndProcA
, ComboWndProcW
}, /* WINPROC_COMBO */
70 { DefWindowProcA
, DefWindowProcW
}, /* WINPROC_DEFWND */
71 { DefDlgProcA
, DefDlgProcW
}, /* WINPROC_DIALOG */
72 { EditWndProcA
, EditWndProcW
}, /* WINPROC_EDIT */
73 { ListBoxWndProcA
, ListBoxWndProcW
}, /* WINPROC_LISTBOX */
74 { MDIClientWndProcA
, MDIClientWndProcW
}, /* WINPROC_MDICLIENT */
75 { ScrollBarWndProcA
, ScrollBarWndProcW
}, /* WINPROC_SCROLLBAR */
76 { StaticWndProcA
, StaticWndProcW
}, /* WINPROC_STATIC */
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 FIXME( "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")
197 "movl 8(%ebp),%eax\n\t"
199 "leal -12(%ebp),%esp\n\t"
201 __ASM_CFI(".cfi_same_value %ebx\n\t")
203 __ASM_CFI(".cfi_same_value %esi\n\t")
205 __ASM_CFI(".cfi_same_value %edi\n\t")
207 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
208 __ASM_CFI(".cfi_same_value %ebp\n\t")
211 static inline LRESULT
WINPROC_wrapper( WNDPROC proc
, HWND hwnd
, UINT msg
,
212 WPARAM wParam
, LPARAM lParam
)
214 return proc( hwnd
, msg
, wParam
, lParam
);
216 #endif /* __i386__ */
218 static WPARAM
map_wparam_char_WtoA( WPARAM wParam
, DWORD len
)
223 RtlUnicodeToMultiByteN( (LPSTR
)ch
, len
, &len
, &wch
, sizeof(wch
) );
225 return MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(wParam
) );
227 return MAKEWPARAM( ch
[0], HIWORD(wParam
) );
230 /* call a 32-bit window procedure */
231 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
, LRESULT
*result
, void *arg
)
237 hwnd
= WIN_GetFullHandle( hwnd
);
239 DPRINTF( "%04x:Call window proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
240 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
);
242 *result
= WINPROC_wrapper( proc
, hwnd
, msg
, wp
, lp
);
245 DPRINTF( "%04x:Ret window proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx) retval=%08lx\n",
246 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
, *result
);
250 /* call a 32-bit dialog procedure */
251 static LRESULT
call_dialog_proc( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
, LRESULT
*result
, void *arg
)
258 hwnd
= WIN_GetFullHandle( hwnd
);
260 DPRINTF( "%04x:Call dialog proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
261 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
);
263 ret
= WINPROC_wrapper( proc
, hwnd
, msg
, wp
, lp
);
264 *result
= GetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
);
267 DPRINTF( "%04x:Ret dialog proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx) retval=%08lx result=%08lx\n",
268 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
, ret
, *result
);
273 /**********************************************************************
276 * Get a window procedure pointer that can be passed to the Windows program.
278 WNDPROC
WINPROC_GetProc( WNDPROC proc
, BOOL unicode
)
280 WINDOWPROC
*ptr
= handle_to_proc( proc
);
282 if (!ptr
|| ptr
== WINPROC_PROC16
) return proc
;
285 if (ptr
->procW
) return ptr
->procW
;
290 if (ptr
->procA
) return ptr
->procA
;
296 /**********************************************************************
299 * Allocate a window procedure for a window or class.
301 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
302 * lot of windows, it will usually only have a limited number of window procedures, so the
303 * array won't grow too large, and this way we avoid the need to track allocations per window.
305 WNDPROC
WINPROC_AllocProc( WNDPROC func
, BOOL unicode
)
309 if (!(proc
= alloc_winproc( func
, unicode
))) return NULL
;
310 if (proc
== WINPROC_PROC16
) return func
;
311 return proc_to_handle( proc
);
315 /**********************************************************************
318 * Return the window procedure type, or the default value if not a winproc handle.
320 BOOL
WINPROC_IsUnicode( WNDPROC proc
, BOOL def_val
)
322 WINDOWPROC
*ptr
= handle_to_proc( proc
);
324 if (!ptr
) return def_val
;
325 if (ptr
== WINPROC_PROC16
) return FALSE
; /* 16-bit is always A */
326 if (ptr
->procA
&& ptr
->procW
) return def_val
; /* can be both */
327 return (ptr
->procW
!= NULL
);
331 /**********************************************************************
332 * WINPROC_TestLBForStr
334 * Return TRUE if the lparam is a string
336 static inline BOOL
WINPROC_TestLBForStr( HWND hwnd
, UINT msg
)
338 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
339 if (msg
<= CB_MSGMAX
)
340 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
342 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
347 /**********************************************************************
348 * WINPROC_CallProcAtoW
350 * Call a window procedure, translating args from Ansi to Unicode.
352 LRESULT
WINPROC_CallProcAtoW( winproc_callback_t callback
, HWND hwnd
, UINT msg
, WPARAM wParam
,
353 LPARAM lParam
, LRESULT
*result
, void *arg
, enum wm_char_mapping mapping
)
357 TRACE_(msg
)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
358 hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
365 WCHAR
*ptr
, buffer
[512];
366 CREATESTRUCTA
*csA
= (CREATESTRUCTA
*)lParam
;
367 CREATESTRUCTW csW
= *(CREATESTRUCTW
*)csA
;
368 MDICREATESTRUCTW mdi_cs
;
369 DWORD name_lenA
= 0, name_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
371 if (!IS_INTRESOURCE(csA
->lpszClass
))
373 class_lenA
= strlen(csA
->lpszClass
) + 1;
374 RtlMultiByteToUnicodeSize( &class_lenW
, csA
->lpszClass
, class_lenA
);
376 if (!IS_INTRESOURCE(csA
->lpszName
))
378 name_lenA
= strlen(csA
->lpszName
) + 1;
379 RtlMultiByteToUnicodeSize( &name_lenW
, csA
->lpszName
, name_lenA
);
382 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), class_lenW
+ name_lenW
))) break;
387 RtlMultiByteToUnicodeN( ptr
, class_lenW
, NULL
, csA
->lpszClass
, class_lenA
);
391 csW
.lpszName
= ptr
+ class_lenW
/sizeof(WCHAR
);
392 RtlMultiByteToUnicodeN( ptr
+ class_lenW
/sizeof(WCHAR
), name_lenW
, NULL
,
393 csA
->lpszName
, name_lenA
);
396 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
398 mdi_cs
= *(MDICREATESTRUCTW
*)csA
->lpCreateParams
;
399 mdi_cs
.szTitle
= csW
.lpszName
;
400 mdi_cs
.szClass
= csW
.lpszClass
;
401 csW
.lpCreateParams
= &mdi_cs
;
404 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csW
, result
, arg
);
405 free_buffer( buffer
, ptr
);
411 WCHAR
*ptr
, buffer
[512];
412 DWORD title_lenA
= 0, title_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
413 MDICREATESTRUCTA
*csA
= (MDICREATESTRUCTA
*)lParam
;
414 MDICREATESTRUCTW csW
;
416 memcpy( &csW
, csA
, sizeof(csW
) );
418 if (!IS_INTRESOURCE(csA
->szTitle
))
420 title_lenA
= strlen(csA
->szTitle
) + 1;
421 RtlMultiByteToUnicodeSize( &title_lenW
, csA
->szTitle
, title_lenA
);
423 if (!IS_INTRESOURCE(csA
->szClass
))
425 class_lenA
= strlen(csA
->szClass
) + 1;
426 RtlMultiByteToUnicodeSize( &class_lenW
, csA
->szClass
, class_lenA
);
429 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), title_lenW
+ class_lenW
))) break;
434 RtlMultiByteToUnicodeN( ptr
, title_lenW
, NULL
, csA
->szTitle
, title_lenA
);
438 csW
.szClass
= ptr
+ title_lenW
/sizeof(WCHAR
);
439 RtlMultiByteToUnicodeN( ptr
+ title_lenW
/sizeof(WCHAR
), class_lenW
, NULL
,
440 csA
->szClass
, class_lenA
);
442 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csW
, result
, arg
);
443 free_buffer( buffer
, ptr
);
448 case WM_ASKCBFORMATNAME
:
450 WCHAR
*ptr
, buffer
[512];
451 LPSTR str
= (LPSTR
)lParam
;
452 DWORD len
= wParam
* sizeof(WCHAR
);
454 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
))) break;
455 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
460 RtlUnicodeToMultiByteN( str
, wParam
- 1, &len
, ptr
, strlenW(ptr
) * sizeof(WCHAR
) );
464 free_buffer( buffer
, ptr
);
469 case LB_INSERTSTRING
:
471 case LB_FINDSTRINGEXACT
:
472 case LB_SELECTSTRING
:
474 case CB_INSERTSTRING
:
476 case CB_FINDSTRINGEXACT
:
477 case CB_SELECTSTRING
:
478 if (!lParam
|| !WINPROC_TestLBForStr( hwnd
, msg
))
480 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
485 case WM_WININICHANGE
:
486 case WM_DEVMODECHANGE
:
491 if (!lParam
) ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
494 WCHAR
*ptr
, buffer
[512];
495 LPCSTR strA
= (LPCSTR
)lParam
;
496 DWORD lenW
, lenA
= strlen(strA
) + 1;
498 RtlMultiByteToUnicodeSize( &lenW
, strA
, lenA
);
499 if ((ptr
= get_buffer( buffer
, sizeof(buffer
), lenW
)))
501 RtlMultiByteToUnicodeN( ptr
, lenW
, NULL
, strA
, lenA
);
502 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
503 free_buffer( buffer
, ptr
);
510 if (lParam
&& WINPROC_TestLBForStr( hwnd
, msg
))
512 WCHAR buffer
[512]; /* FIXME: fixed sized buffer */
514 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)buffer
, result
, arg
);
518 RtlUnicodeToMultiByteN( (LPSTR
)lParam
, ~0u, &len
,
519 buffer
, (strlenW(buffer
) + 1) * sizeof(WCHAR
) );
523 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
528 WCHAR
*ptr
, buffer
[512];
529 WORD len
= *(WORD
*)lParam
;
531 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* sizeof(WCHAR
) ))) break;
532 *((WORD
*)ptr
) = len
; /* store the length */
533 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
537 RtlUnicodeToMultiByteN( (LPSTR
)lParam
, len
, &reslen
, ptr
, *result
* sizeof(WCHAR
) );
538 if (reslen
< len
) ((LPSTR
)lParam
)[reslen
] = 0;
541 free_buffer( buffer
, ptr
);
548 MSG newmsg
= *(MSG
*)lParam
;
549 if (map_wparam_AtoW( newmsg
.message
, &newmsg
.wParam
, WMCHAR_MAP_NOMAPPING
))
550 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&newmsg
, result
, arg
);
552 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
561 case EM_SETPASSWORDCHAR
:
563 if (map_wparam_AtoW( msg
, &wParam
, mapping
))
564 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
567 case WM_GETTEXTLENGTH
:
568 case CB_GETLBTEXTLEN
:
570 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
573 WCHAR
*ptr
, buffer
[512];
575 DWORD len
= *result
+ 1;
576 /* Determine respective GETTEXT message */
577 UINT msgGetText
= (msg
== WM_GETTEXTLENGTH
) ? WM_GETTEXT
:
578 ((msg
== CB_GETLBTEXTLEN
) ? CB_GETLBTEXT
: LB_GETTEXT
);
579 /* wParam differs between the messages */
580 WPARAM wp
= (msg
== WM_GETTEXTLENGTH
) ? len
: wParam
;
582 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* sizeof(WCHAR
) ))) break;
584 if (callback
== call_window_proc
) /* FIXME: hack */
585 callback( hwnd
, msgGetText
, wp
, (LPARAM
)ptr
, &tmp
, arg
);
587 tmp
= SendMessageW( hwnd
, msgGetText
, wp
, (LPARAM
)ptr
);
588 RtlUnicodeToMultiByteSize( &len
, ptr
, tmp
* sizeof(WCHAR
) );
590 free_buffer( buffer
, ptr
);
594 case WM_PAINTCLIPBOARD
:
595 case WM_SIZECLIPBOARD
:
596 FIXME_(msg
)( "message %s (0x%x) needs translation, please report\n",
597 SPY_GetMsgName(msg
, hwnd
), msg
);
601 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
608 /**********************************************************************
609 * WINPROC_CallProcWtoA
611 * Call a window procedure, translating args from Unicode to Ansi.
613 static LRESULT
WINPROC_CallProcWtoA( winproc_callback_t callback
, HWND hwnd
, UINT msg
, WPARAM wParam
,
614 LPARAM lParam
, LRESULT
*result
, void *arg
)
618 TRACE_(msg
)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
619 hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
626 char buffer
[1024], *cls
;
627 CREATESTRUCTW
*csW
= (CREATESTRUCTW
*)lParam
;
628 CREATESTRUCTA csA
= *(CREATESTRUCTA
*)csW
;
629 MDICREATESTRUCTA mdi_cs
;
630 DWORD name_lenA
= 0, name_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
632 if (!IS_INTRESOURCE(csW
->lpszClass
))
634 class_lenW
= (strlenW(csW
->lpszClass
) + 1) * sizeof(WCHAR
);
635 RtlUnicodeToMultiByteSize(&class_lenA
, csW
->lpszClass
, class_lenW
);
637 if (!IS_INTRESOURCE(csW
->lpszName
))
639 name_lenW
= (strlenW(csW
->lpszName
) + 1) * sizeof(WCHAR
);
640 RtlUnicodeToMultiByteSize(&name_lenA
, csW
->lpszName
, name_lenW
);
643 if (!(cls
= get_buffer( buffer
, sizeof(buffer
), class_lenA
+ name_lenA
))) break;
647 RtlUnicodeToMultiByteN(cls
, class_lenA
, NULL
, csW
->lpszClass
, class_lenW
);
652 char *name
= cls
+ class_lenA
;
653 RtlUnicodeToMultiByteN(name
, name_lenA
, NULL
, csW
->lpszName
, name_lenW
);
657 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
659 mdi_cs
= *(MDICREATESTRUCTA
*)csW
->lpCreateParams
;
660 mdi_cs
.szTitle
= csA
.lpszName
;
661 mdi_cs
.szClass
= csA
.lpszClass
;
662 csA
.lpCreateParams
= &mdi_cs
;
665 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csA
, result
, arg
);
666 free_buffer( buffer
, cls
);
671 case WM_ASKCBFORMATNAME
:
673 char *ptr
, buffer
[512];
674 DWORD len
= wParam
* 2;
676 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
))) break;
677 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
682 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, wParam
*sizeof(WCHAR
), &len
, ptr
, strlen(ptr
)+1 );
683 *result
= len
/sizeof(WCHAR
) - 1; /* do not count terminating null */
685 ((LPWSTR
)lParam
)[*result
] = 0;
687 free_buffer( buffer
, ptr
);
692 case LB_INSERTSTRING
:
694 case LB_FINDSTRINGEXACT
:
695 case LB_SELECTSTRING
:
697 case CB_INSERTSTRING
:
699 case CB_FINDSTRINGEXACT
:
700 case CB_SELECTSTRING
:
701 if (!lParam
|| !WINPROC_TestLBForStr( hwnd
, msg
))
703 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
708 case WM_WININICHANGE
:
709 case WM_DEVMODECHANGE
:
714 if (!lParam
) ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
717 char *ptr
, buffer
[512];
718 LPCWSTR strW
= (LPCWSTR
)lParam
;
719 DWORD lenA
, lenW
= (strlenW(strW
) + 1) * sizeof(WCHAR
);
721 RtlUnicodeToMultiByteSize( &lenA
, strW
, lenW
);
722 if ((ptr
= get_buffer( buffer
, sizeof(buffer
), lenA
)))
724 RtlUnicodeToMultiByteN( ptr
, lenA
, NULL
, strW
, lenW
);
725 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
726 free_buffer( buffer
, ptr
);
733 char *ptr
, buffer
[1024];
734 DWORD title_lenA
= 0, title_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
735 MDICREATESTRUCTW
*csW
= (MDICREATESTRUCTW
*)lParam
;
736 MDICREATESTRUCTA csA
;
738 memcpy( &csA
, csW
, sizeof(csA
) );
740 if (!IS_INTRESOURCE(csW
->szTitle
))
742 title_lenW
= (strlenW(csW
->szTitle
) + 1) * sizeof(WCHAR
);
743 RtlUnicodeToMultiByteSize( &title_lenA
, csW
->szTitle
, title_lenW
);
745 if (!IS_INTRESOURCE(csW
->szClass
))
747 class_lenW
= (strlenW(csW
->szClass
) + 1) * sizeof(WCHAR
);
748 RtlUnicodeToMultiByteSize( &class_lenA
, csW
->szClass
, class_lenW
);
751 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), title_lenA
+ class_lenA
))) break;
755 RtlUnicodeToMultiByteN( ptr
, title_lenA
, NULL
, csW
->szTitle
, title_lenW
);
760 RtlUnicodeToMultiByteN( ptr
+ title_lenA
, class_lenA
, NULL
, csW
->szClass
, class_lenW
);
761 csA
.szClass
= ptr
+ title_lenA
;
763 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csA
, result
, arg
);
764 free_buffer( buffer
, ptr
);
770 if (lParam
&& WINPROC_TestLBForStr( hwnd
, msg
))
772 char buffer
[512]; /* FIXME: fixed sized buffer */
774 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)buffer
, result
, arg
);
778 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, ~0u, &len
, buffer
, strlen(buffer
) + 1 );
779 *result
= len
/ sizeof(WCHAR
) - 1;
782 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
787 char *ptr
, buffer
[512];
788 WORD len
= *(WORD
*)lParam
;
790 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* 2 ))) break;
791 *((WORD
*)ptr
) = len
* 2; /* store the length */
792 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
796 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, len
*sizeof(WCHAR
), &reslen
, ptr
, *result
);
797 *result
= reslen
/ sizeof(WCHAR
);
798 if (*result
< len
) ((LPWSTR
)lParam
)[*result
] = 0;
800 free_buffer( buffer
, ptr
);
807 MSG newmsg
= *(MSG
*)lParam
;
808 switch(newmsg
.message
)
814 newmsg
.wParam
= map_wparam_char_WtoA( newmsg
.wParam
, 1 );
817 newmsg
.wParam
= map_wparam_char_WtoA( newmsg
.wParam
, 2 );
820 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&newmsg
, result
, arg
);
822 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
831 RtlUnicodeToMultiByteN( ch
, 2, &len
, &wch
, sizeof(wch
) );
832 ret
= callback( hwnd
, msg
, (BYTE
)ch
[0], lParam
, result
, arg
);
833 if (len
== 2) ret
= callback( hwnd
, msg
, (BYTE
)ch
[1], lParam
, result
, arg
);
842 case EM_SETPASSWORDCHAR
:
843 ret
= callback( hwnd
, msg
, map_wparam_char_WtoA(wParam
,1), lParam
, result
, arg
);
847 ret
= callback( hwnd
, msg
, map_wparam_char_WtoA(wParam
,2), lParam
, result
, arg
);
850 case WM_PAINTCLIPBOARD
:
851 case WM_SIZECLIPBOARD
:
852 FIXME_(msg
)( "message %s (%04x) needs translation, please report\n",
853 SPY_GetMsgName(msg
, hwnd
), msg
);
857 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
865 /**********************************************************************
866 * WINPROC_call_window
868 * Call the window procedure of the specified window.
870 BOOL
WINPROC_call_window( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
871 LRESULT
*result
, BOOL unicode
, enum wm_char_mapping mapping
)
873 struct user_thread_info
*thread_info
= get_user_thread_info();
878 if (!(wndPtr
= WIN_GetPtr( hwnd
))) return FALSE
;
879 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
880 if (wndPtr
->tid
!= GetCurrentThreadId())
882 WIN_ReleasePtr( wndPtr
);
885 func
= wndPtr
->winproc
;
886 proc
= handle_to_proc( wndPtr
->winproc
);
887 WIN_ReleasePtr( wndPtr
);
889 if (!proc
) return TRUE
;
891 if (thread_info
->recursion_count
> MAX_WINPROC_RECURSION
) return FALSE
;
892 thread_info
->recursion_count
++;
896 if (proc
== WINPROC_PROC16
)
897 WINPROC_CallProcWtoA( wow_handlers
.call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, func
);
898 else if (proc
->procW
)
899 call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, proc
->procW
);
901 WINPROC_CallProcWtoA( call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, proc
->procA
);
905 if (proc
== WINPROC_PROC16
)
906 wow_handlers
.call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, func
);
907 else if (proc
->procA
)
908 call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, proc
->procA
);
910 WINPROC_CallProcAtoW( call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, proc
->procW
, mapping
);
912 thread_info
->recursion_count
--;
917 /**********************************************************************
918 * CallWindowProcA (USER32.@)
920 * The CallWindowProc() function invokes the windows procedure _func_,
921 * with _hwnd_ as the target window, the message specified by _msg_, and
922 * the message parameters _wParam_ and _lParam_.
924 * Some kinds of argument conversion may be done, I'm not sure what.
926 * CallWindowProc() may be used for windows subclassing. Use
927 * SetWindowLong() to set a new windows procedure for windows of the
928 * subclass, and handle subclassed messages in the new windows
929 * procedure. The new windows procedure may then use CallWindowProc()
930 * with _func_ set to the parent class's windows procedure to dispatch
931 * the message to the superclass.
935 * The return value is message dependent.
941 LRESULT WINAPI
CallWindowProcA(
942 WNDPROC func
, /* [in] window procedure */
943 HWND hwnd
, /* [in] target window */
944 UINT msg
, /* [in] message */
945 WPARAM wParam
, /* [in] message dependent parameter */
946 LPARAM lParam
/* [in] message dependent parameter */
953 if (!(proc
= handle_to_proc( func
)))
954 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
955 else if (proc
== WINPROC_PROC16
)
956 wow_handlers
.call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
957 else if (proc
->procA
)
958 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
960 WINPROC_CallProcAtoW( call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
,
961 proc
->procW
, WMCHAR_MAP_CALLWINDOWPROC
);
966 /**********************************************************************
967 * CallWindowProcW (USER32.@)
969 * See CallWindowProcA.
971 LRESULT WINAPI
CallWindowProcW( WNDPROC func
, HWND hwnd
, UINT msg
,
972 WPARAM wParam
, LPARAM lParam
)
979 if (!(proc
= handle_to_proc( func
)))
980 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
981 else if (proc
== WINPROC_PROC16
)
982 WINPROC_CallProcWtoA( wow_handlers
.call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
, func
);
983 else if (proc
->procW
)
984 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
986 WINPROC_CallProcWtoA( call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
991 /**********************************************************************
992 * WINPROC_CallDlgProcA
994 INT_PTR
WINPROC_CallDlgProcA( DLGPROC func
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1000 if (!func
) return 0;
1002 if (!(proc
= handle_to_proc( func
)))
1003 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
1004 else if (proc
== WINPROC_PROC16
)
1006 ret
= wow_handlers
.call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
1007 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
1009 else if (proc
->procW
)
1011 ret
= WINPROC_CallProcAtoW( call_dialog_proc
, hwnd
, msg
, wParam
, lParam
, &result
,
1012 proc
->procW
, WMCHAR_MAP_CALLWINDOWPROC
);
1013 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
1016 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
1021 /**********************************************************************
1022 * WINPROC_CallDlgProcW
1024 INT_PTR
WINPROC_CallDlgProcW( DLGPROC func
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1030 if (!func
) return 0;
1032 if (!(proc
= handle_to_proc( func
)))
1033 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
1034 else if (proc
== WINPROC_PROC16
)
1036 ret
= WINPROC_CallProcWtoA( wow_handlers
.call_dialog_proc
, hwnd
, msg
, wParam
, lParam
, &result
, func
);
1037 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
1039 else if (proc
->procA
)
1041 ret
= WINPROC_CallProcWtoA( call_dialog_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
1042 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
1045 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
1050 /***********************************************************************
1051 * Window procedures for builtin classes
1054 static LRESULT WINAPI
ButtonWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1056 return wow_handlers
.button_proc( hwnd
, msg
, wParam
, lParam
, FALSE
);
1059 static LRESULT WINAPI
ButtonWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1061 return wow_handlers
.button_proc( hwnd
, msg
, wParam
, lParam
, TRUE
);
1064 static LRESULT WINAPI
ComboWndProcA( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1066 return wow_handlers
.combo_proc( hwnd
, message
, wParam
, lParam
, FALSE
);
1069 static LRESULT WINAPI
ComboWndProcW( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1071 return wow_handlers
.combo_proc( hwnd
, message
, wParam
, lParam
, TRUE
);
1074 LRESULT WINAPI
EditWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1076 return wow_handlers
.edit_proc( hwnd
, msg
, wParam
, lParam
, FALSE
);
1079 static LRESULT WINAPI
EditWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1081 return wow_handlers
.edit_proc( hwnd
, msg
, wParam
, lParam
, TRUE
);
1084 static LRESULT WINAPI
ListBoxWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1086 return wow_handlers
.listbox_proc( hwnd
, msg
, wParam
, lParam
, FALSE
);
1089 static LRESULT WINAPI
ListBoxWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1091 return wow_handlers
.listbox_proc( hwnd
, msg
, wParam
, lParam
, TRUE
);
1094 static LRESULT WINAPI
MDIClientWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1096 return wow_handlers
.mdiclient_proc( hwnd
, msg
, wParam
, lParam
, FALSE
);
1099 static LRESULT WINAPI
MDIClientWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1101 return wow_handlers
.mdiclient_proc( hwnd
, msg
, wParam
, lParam
, TRUE
);
1104 static LRESULT WINAPI
ScrollBarWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1106 return wow_handlers
.scrollbar_proc( hwnd
, msg
, wParam
, lParam
, FALSE
);
1109 static LRESULT WINAPI
ScrollBarWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1111 return wow_handlers
.scrollbar_proc( hwnd
, msg
, wParam
, lParam
, TRUE
);
1114 static LRESULT WINAPI
StaticWndProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1116 return wow_handlers
.static_proc( hwnd
, msg
, wParam
, lParam
, FALSE
);
1119 static LRESULT WINAPI
StaticWndProcW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1121 return wow_handlers
.static_proc( hwnd
, msg
, wParam
, lParam
, TRUE
);
1124 static DWORD
wait_message( DWORD count
, CONST HANDLE
*handles
, DWORD timeout
, DWORD mask
, DWORD flags
)
1126 DWORD ret
= USER_Driver
->pMsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
, flags
);
1127 if (ret
== WAIT_TIMEOUT
&& !count
&& !timeout
) NtYieldExecution();
1131 static HICON
alloc_icon_handle( unsigned int size
)
1133 struct user_object
*obj
= HeapAlloc( GetProcessHeap(), 0, sizeof(*obj
) + size
);
1135 return alloc_user_handle( obj
, USER_ICON
);
1138 static struct tagCURSORICONINFO
*get_icon_ptr( HICON handle
)
1140 struct user_object
*obj
= get_user_handle_ptr( handle
, USER_ICON
);
1141 if (obj
== OBJ_OTHER_PROCESS
)
1143 WARN( "cursor handle %p from other process\n", handle
);
1146 return obj
? (struct tagCURSORICONINFO
*)(obj
+ 1) : NULL
;
1149 static void release_icon_ptr( HICON handle
, struct tagCURSORICONINFO
*ptr
)
1151 release_user_handle_ptr( (struct user_object
*)ptr
- 1 );
1154 static int free_icon_handle( HICON handle
)
1156 struct user_object
*obj
= free_user_handle( handle
, USER_ICON
);
1157 HeapFree( GetProcessHeap(), 0, obj
);
1162 /**********************************************************************
1163 * UserRegisterWowHandlers (USER32.@)
1165 * NOTE: no attempt has been made to be compatible here,
1166 * the Windows function is most likely completely different.
1168 void WINAPI
UserRegisterWowHandlers( const struct wow_handlers16
*new, struct wow_handlers32
*orig
)
1170 orig
->button_proc
= ButtonWndProc_common
;
1171 orig
->combo_proc
= ComboWndProc_common
;
1172 orig
->edit_proc
= EditWndProc_common
;
1173 orig
->listbox_proc
= ListBoxWndProc_common
;
1174 orig
->mdiclient_proc
= MDIClientWndProc_common
;
1175 orig
->scrollbar_proc
= ScrollBarWndProc_common
;
1176 orig
->static_proc
= StaticWndProc_common
;
1177 orig
->wait_message
= wait_message
;
1178 orig
->create_window
= WIN_CreateWindowEx
;
1179 orig
->get_win_handle
= WIN_GetFullHandle
;
1180 orig
->alloc_winproc
= WINPROC_AllocProc
;
1181 orig
->get_dialog_info
= DIALOG_get_info
;
1182 orig
->dialog_box_loop
= DIALOG_DoDialogBox
;
1184 wow_handlers
= *new;
1187 struct wow_handlers16 wow_handlers
=
1189 ButtonWndProc_common
,
1190 ComboWndProc_common
,
1192 ListBoxWndProc_common
,
1193 MDIClientWndProc_common
,
1194 ScrollBarWndProc_common
,
1195 StaticWndProc_common
,
1198 NULL
, /* call_window_proc */
1199 NULL
, /* call_dialog_proc */