2 * Default window procedure
4 * Copyright 1993, 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"
35 #include "wine/unicode.h"
36 #include "wine/winuser16.h"
37 #include "wine/server.h"
38 #include "wine/exception.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(win
);
43 /* bits in the dwKeyData */
44 #define KEYDATA_ALT 0x2000
45 #define KEYDATA_PREVSTATE 0x4000
47 static short iF10Key
= 0;
48 static short iMenuSysKey
= 0;
49 static const WCHAR imm32W
[] = { 'i','m','m','3','2','\0' };
51 /***********************************************************************
52 * DEFWND_HandleWindowPosChanged
54 * Handle the WM_WINDOWPOSCHANGED message.
56 static void DEFWND_HandleWindowPosChanged( HWND hwnd
, const WINDOWPOS
*winpos
)
59 WND
*wndPtr
= WIN_GetPtr( hwnd
);
61 rect
= wndPtr
->rectClient
;
62 WIN_ReleasePtr( wndPtr
);
64 if (!(winpos
->flags
& SWP_NOCLIENTMOVE
))
65 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG(rect
.left
, rect
.top
));
67 if (!(winpos
->flags
& SWP_NOCLIENTSIZE
) || (winpos
->flags
& SWP_STATECHANGED
))
69 WPARAM wp
= SIZE_RESTORED
;
70 if (IsZoomed(hwnd
)) wp
= SIZE_MAXIMIZED
;
71 else if (IsIconic(hwnd
)) wp
= SIZE_MINIMIZED
;
73 SendMessageW( hwnd
, WM_SIZE
, wp
, MAKELONG(rect
.right
-rect
.left
, rect
.bottom
-rect
.top
) );
78 /***********************************************************************
81 * Set the window text.
83 static void DEFWND_SetTextA( HWND hwnd
, LPCSTR text
)
90 count
= MultiByteToWideChar( CP_ACP
, 0, text
, -1, NULL
, 0 );
92 if (!(wndPtr
= WIN_GetPtr( hwnd
))) return;
93 if ((textW
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(WCHAR
))))
95 HeapFree(GetProcessHeap(), 0, wndPtr
->text
);
97 MultiByteToWideChar( CP_ACP
, 0, text
, -1, textW
, count
);
98 SERVER_START_REQ( set_window_text
)
100 req
->handle
= wine_server_user_handle( hwnd
);
101 wine_server_add_data( req
, textW
, (count
-1) * sizeof(WCHAR
) );
102 wine_server_call( req
);
107 ERR("Not enough memory for window text\n");
108 WIN_ReleasePtr( wndPtr
);
110 USER_Driver
->pSetWindowText( hwnd
, textW
);
113 /***********************************************************************
116 * Set the window text.
118 static void DEFWND_SetTextW( HWND hwnd
, LPCWSTR text
)
120 static const WCHAR empty_string
[] = {0};
124 if (!text
) text
= empty_string
;
125 count
= strlenW(text
) + 1;
127 if (!(wndPtr
= WIN_GetPtr( hwnd
))) return;
128 HeapFree(GetProcessHeap(), 0, wndPtr
->text
);
129 if ((wndPtr
->text
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(WCHAR
))))
131 strcpyW( wndPtr
->text
, text
);
132 SERVER_START_REQ( set_window_text
)
134 req
->handle
= wine_server_user_handle( hwnd
);
135 wine_server_add_data( req
, wndPtr
->text
, (count
-1) * sizeof(WCHAR
) );
136 wine_server_call( req
);
141 ERR("Not enough memory for window text\n");
143 WIN_ReleasePtr( wndPtr
);
145 USER_Driver
->pSetWindowText( hwnd
, text
);
148 /***********************************************************************
149 * DEFWND_ControlColor
151 * Default colors for control painting.
153 HBRUSH
DEFWND_ControlColor( HDC hDC
, UINT ctlType
)
155 if( ctlType
== CTLCOLOR_SCROLLBAR
)
157 HBRUSH hb
= GetSysColorBrush(COLOR_SCROLLBAR
);
158 COLORREF bk
= GetSysColor(COLOR_3DHILIGHT
);
159 SetTextColor( hDC
, GetSysColor(COLOR_3DFACE
));
160 SetBkColor( hDC
, bk
);
162 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
163 * we better use 0x55aa bitmap brush to make scrollbar's background
164 * look different from the window background.
166 if (bk
== GetSysColor(COLOR_WINDOW
))
167 return SYSCOLOR_55AABrush
;
169 UnrealizeObject( hb
);
173 SetTextColor( hDC
, GetSysColor(COLOR_WINDOWTEXT
));
175 if ((ctlType
== CTLCOLOR_EDIT
) || (ctlType
== CTLCOLOR_LISTBOX
))
176 SetBkColor( hDC
, GetSysColor(COLOR_WINDOW
) );
178 SetBkColor( hDC
, GetSysColor(COLOR_3DFACE
) );
179 return GetSysColorBrush(COLOR_3DFACE
);
181 return GetSysColorBrush(COLOR_WINDOW
);
185 /***********************************************************************
188 * This method handles the default behavior for the WM_PRINT message.
190 static void DEFWND_Print( HWND hwnd
, HDC hdc
, ULONG uFlags
)
195 if ( (uFlags
& PRF_CHECKVISIBLE
) &&
196 !IsWindowVisible(hwnd
) )
200 * Unimplemented flags.
202 if ( (uFlags
& PRF_CHILDREN
) ||
203 (uFlags
& PRF_OWNED
) ||
204 (uFlags
& PRF_NONCLIENT
) )
206 WARN("WM_PRINT message with unsupported flags\n");
212 if ( uFlags
& PRF_ERASEBKGND
)
213 SendMessageW(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
218 if ( uFlags
& PRF_CLIENT
)
219 SendMessageW(hwnd
, WM_PRINTCLIENT
, (WPARAM
)hdc
, PRF_CLIENT
);
224 * helpers for calling IMM32
226 * WM_IME_* messages are generated only by IMM32,
227 * so I assume imm32 is already LoadLibrary-ed.
229 static HWND
DEFWND_ImmGetDefaultIMEWnd( HWND hwnd
)
231 HINSTANCE hInstIMM
= GetModuleHandleW( imm32W
);
232 HWND (WINAPI
*pFunc
)(HWND
);
237 ERR( "cannot get IMM32 handle\n" );
241 pFunc
= (void*)GetProcAddress(hInstIMM
,"ImmGetDefaultIMEWnd");
243 hwndRet
= (*pFunc
)( hwnd
);
248 static BOOL
DEFWND_ImmIsUIMessageA( HWND hwndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
250 HINSTANCE hInstIMM
= GetModuleHandleW( imm32W
);
251 BOOL (WINAPI
*pFunc
)(HWND
,UINT
,WPARAM
,LPARAM
);
256 ERR( "cannot get IMM32 handle\n" );
260 pFunc
= (void*)GetProcAddress(hInstIMM
,"ImmIsUIMessageA");
262 fRet
= (*pFunc
)( hwndIME
, msg
, wParam
, lParam
);
267 static BOOL
DEFWND_ImmIsUIMessageW( HWND hwndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
269 HINSTANCE hInstIMM
= GetModuleHandleW( imm32W
);
270 BOOL (WINAPI
*pFunc
)(HWND
,UINT
,WPARAM
,LPARAM
);
275 ERR( "cannot get IMM32 handle\n" );
279 pFunc
= (void*)GetProcAddress(hInstIMM
,"ImmIsUIMessageW");
281 fRet
= (*pFunc
)( hwndIME
, msg
, wParam
, lParam
);
288 /***********************************************************************
291 * Default window procedure for messages that are the same in Ansi and Unicode.
293 static LRESULT
DEFWND_DefWinProc( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
298 return NC_HandleNCPaint( hwnd
, (HRGN
)wParam
);
303 pt
.x
= (short)LOWORD(lParam
);
304 pt
.y
= (short)HIWORD(lParam
);
305 return NC_HandleNCHitTest( hwnd
, pt
);
309 return NC_HandleNCCalcSize( hwnd
, (RECT
*)lParam
);
311 case WM_WINDOWPOSCHANGING
:
312 return WINPOS_HandleWindowPosChanging( hwnd
, (WINDOWPOS
*)lParam
);
314 case WM_WINDOWPOSCHANGED
:
315 DEFWND_HandleWindowPosChanged( hwnd
, (const WINDOWPOS
*)lParam
);
321 iF10Key
= iMenuSysKey
= 0;
324 case WM_NCLBUTTONDOWN
:
325 return NC_HandleNCLButtonDown( hwnd
, wParam
, lParam
);
327 case WM_LBUTTONDBLCLK
:
328 return NC_HandleNCLButtonDblClk( hwnd
, HTCLIENT
, lParam
);
330 case WM_NCLBUTTONDBLCLK
:
331 return NC_HandleNCLButtonDblClk( hwnd
, wParam
, lParam
);
333 case WM_NCRBUTTONDOWN
:
334 /* in Windows, capture is taken when right-clicking on the caption bar */
335 if (wParam
==HTCAPTION
)
345 if (hwnd
== GetCapture())
346 /* release capture if we took it on WM_NCRBUTTONDOWN */
349 pt
.x
= (short)LOWORD(lParam
);
350 pt
.y
= (short)HIWORD(lParam
);
351 ClientToScreen(hwnd
, &pt
);
352 SendMessageW( hwnd
, WM_CONTEXTMENU
, (WPARAM
)hwnd
, MAKELPARAM(pt
.x
, pt
.y
) );
358 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
359 * in Windows), but what _should_ we do? According to MSDN :
360 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
361 * message to the window". When is it appropriate?
366 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)
367 SendMessageW( GetParent(hwnd
), msg
, wParam
, lParam
);
372 WND
*wndPtr
= WIN_GetPtr( hwnd
);
373 HMENU hMenu
= wndPtr
->hSysMenu
;
374 WIN_ReleasePtr( wndPtr
);
375 if (!hMenu
) return 0;
376 pt
.x
= (short)LOWORD(lParam
);
377 pt
.y
= (short)HIWORD(lParam
);
378 hitcode
= NC_HandleNCHitTest(hwnd
, pt
);
380 /* Track system popup if click was in the caption area. */
381 if (hitcode
==HTCAPTION
|| hitcode
==HTSYSMENU
)
382 TrackPopupMenu(GetSystemMenu(hwnd
, FALSE
),
383 TPM_LEFTBUTTON
| TPM_RIGHTBUTTON
,
384 pt
.x
, pt
.y
, 0, hwnd
, NULL
);
388 case WM_POPUPSYSTEMMENU
:
390 /* This is an undocumented message used by the windows taskbar to
391 display the system menu of windows that belong to other processes. */
392 HMENU menu
= GetSystemMenu(hwnd
, FALSE
);
395 TrackPopupMenu(menu
, TPM_LEFTBUTTON
|TPM_RIGHTBUTTON
,
396 LOWORD(lParam
), HIWORD(lParam
), 0, hwnd
, NULL
);
401 return NC_HandleNCActivate( hwnd
, wParam
, lParam
);
405 WND
*wndPtr
= WIN_GetPtr( hwnd
);
406 if (!wndPtr
) return 0;
407 HeapFree( GetProcessHeap(), 0, wndPtr
->text
);
409 HeapFree( GetProcessHeap(), 0, wndPtr
->pScroll
);
410 wndPtr
->pScroll
= NULL
;
411 WIN_ReleasePtr( wndPtr
);
416 DEFWND_Print(hwnd
, (HDC
)wParam
, lParam
);
423 HDC hdc
= BeginPaint( hwnd
, &ps
);
427 if (IsIconic(hwnd
) && ((hIcon
= (HICON
)GetClassLongPtrW( hwnd
, GCLP_HICON
))) )
432 GetClientRect( hwnd
, &rc
);
433 x
= (rc
.right
- rc
.left
- GetSystemMetrics(SM_CXICON
))/2;
434 y
= (rc
.bottom
- rc
.top
- GetSystemMetrics(SM_CYICON
))/2;
435 TRACE("Painting class icon: vis rect=(%s)\n",
436 wine_dbgstr_rect(&ps
.rcPaint
));
437 DrawIcon( hdc
, x
, y
, hIcon
);
439 EndPaint( hwnd
, &ps
);
445 RedrawWindow ( hwnd
, NULL
, 0, RDW_ERASENOW
| RDW_ERASE
| RDW_ALLCHILDREN
);
449 if (wParam
) WIN_SetStyle( hwnd
, WS_VISIBLE
, 0 );
452 RedrawWindow( hwnd
, NULL
, 0, RDW_ALLCHILDREN
| RDW_VALIDATE
);
453 WIN_SetStyle( hwnd
, 0, WS_VISIBLE
);
458 DestroyWindow( hwnd
);
461 case WM_MOUSEACTIVATE
:
462 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)
464 LONG ret
= SendMessageW( GetParent(hwnd
), WM_MOUSEACTIVATE
, wParam
, lParam
);
468 /* Caption clicks are handled by NC_HandleNCLButtonDown() */
472 /* The default action in Windows is to set the keyboard focus to
473 * the window, if it's being activated and not minimized */
474 if (LOWORD(wParam
) != WA_INACTIVE
) {
475 if (!IsIconic(hwnd
)) SetFocus(hwnd
);
480 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)
481 return SendMessageW( GetParent(hwnd
), WM_MOUSEWHEEL
, wParam
, lParam
);
485 case WM_ICONERASEBKGND
:
488 HDC hdc
= (HDC
)wParam
;
489 HBRUSH hbr
= (HBRUSH
)GetClassLongPtrW( hwnd
, GCLP_HBRBACKGROUND
);
492 if (GetClassLongW( hwnd
, GCL_STYLE
) & CS_PARENTDC
)
494 /* can't use GetClipBox with a parent DC or we fill the whole parent */
495 GetClientRect( hwnd
, &rect
);
496 DPtoLP( hdc
, (LPPOINT
)&rect
, 2 );
498 else GetClipBox( hdc
, &rect
);
499 FillRect( hdc
, &rect
, hbr
);
506 case WM_CTLCOLORMSGBOX
:
507 case WM_CTLCOLOREDIT
:
508 case WM_CTLCOLORLISTBOX
:
511 case WM_CTLCOLORSTATIC
:
512 case WM_CTLCOLORSCROLLBAR
:
513 return (LRESULT
)DEFWND_ControlColor( (HDC
)wParam
, msg
- WM_CTLCOLORMSGBOX
);
516 return (LRESULT
)DEFWND_ControlColor( (HDC
)wParam
, HIWORD(lParam
) );
519 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)
521 /* with the exception of the border around a resizable wnd,
522 * give the parent first chance to set the cursor */
523 if ((LOWORD(lParam
) < HTSIZEFIRST
) || (LOWORD(lParam
) > HTSIZELAST
))
525 if (SendMessageW(GetParent(hwnd
), WM_SETCURSOR
, wParam
, lParam
)) return TRUE
;
528 NC_HandleSetCursor( hwnd
, wParam
, lParam
);
532 return NC_HandleSysCommand( hwnd
, wParam
, lParam
);
535 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
539 if( HIWORD(lParam
) & KEYDATA_ALT
)
541 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
542 if ( (wParam
== VK_MENU
|| wParam
== VK_LMENU
543 || wParam
== VK_RMENU
) && !iMenuSysKey
)
550 if( wParam
== VK_F4
) /* try to close the window */
552 HWND top
= GetAncestor( hwnd
, GA_ROOT
);
553 if (!(GetClassLongW( top
, GCL_STYLE
) & CS_NOCLOSE
))
554 PostMessageW( top
, WM_SYSCOMMAND
, SC_CLOSE
, 0 );
557 else if( wParam
== VK_F10
)
559 else if( wParam
== VK_ESCAPE
&& (GetKeyState(VK_SHIFT
) & 0x8000))
560 SendMessageW( hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, ' ' );
565 /* Press and release F10 or ALT */
566 if (((wParam
== VK_MENU
|| wParam
== VK_LMENU
|| wParam
== VK_RMENU
)
567 && iMenuSysKey
) || ((wParam
== VK_F10
) && iF10Key
))
568 SendMessageW( GetAncestor( hwnd
, GA_ROOT
), WM_SYSCOMMAND
, SC_KEYMENU
, 0L );
569 iMenuSysKey
= iF10Key
= 0;
575 if (wParam
== '\r' && IsIconic(hwnd
))
577 PostMessageW( hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0L );
580 if ((HIWORD(lParam
) & KEYDATA_ALT
) && wParam
)
582 if (wParam
== '\t' || wParam
== '\x1b') break;
583 if (wParam
== ' ' && (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
))
584 SendMessageW( GetParent(hwnd
), msg
, wParam
, lParam
);
586 SendMessageW( hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, wParam
);
588 else /* check for Ctrl-Esc */
589 if (wParam
!= '\x1b') MessageBeep(0);
595 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
597 if (!lParam
) return 0; /* sent from ShowWindow */
598 if ((style
& WS_VISIBLE
) && wParam
) return 0;
599 if (!(style
& WS_VISIBLE
) && !wParam
) return 0;
600 if (!GetWindow( hwnd
, GW_OWNER
)) return 0;
601 if (!(pWnd
= WIN_GetPtr( hwnd
))) return 0;
602 if (pWnd
== WND_OTHER_PROCESS
) return 0;
605 if (!(pWnd
->flags
& WIN_NEEDS_SHOW_OWNEDPOPUP
))
607 WIN_ReleasePtr( pWnd
);
610 pWnd
->flags
&= ~WIN_NEEDS_SHOW_OWNEDPOPUP
;
612 else pWnd
->flags
|= WIN_NEEDS_SHOW_OWNEDPOPUP
;
613 WIN_ReleasePtr( pWnd
);
614 ShowWindow( hwnd
, wParam
? SW_SHOWNOACTIVATE
: SW_HIDE
);
620 MENU_EndMenu( hwnd
);
621 if (GetCapture() == hwnd
) ReleaseCapture();
631 case WM_QUERYDROPOBJECT
:
632 return (GetWindowLongA( hwnd
, GWL_EXSTYLE
) & WS_EX_ACCEPTFILES
) != 0;
634 case WM_QUERYDRAGICON
:
638 HICON hIcon
= (HICON
)GetClassLongPtrW( hwnd
, GCLP_HICON
);
639 HINSTANCE instance
= (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
);
640 if (hIcon
) return (LRESULT
)hIcon
;
641 for(len
=1; len
<64; len
++)
642 if((hIcon
= LoadIconW(instance
, MAKEINTRESOURCEW(len
))))
643 return (LRESULT
)hIcon
;
644 return (LRESULT
)LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
648 case WM_ISACTIVEICON
:
650 WND
*wndPtr
= WIN_GetPtr( hwnd
);
651 BOOL ret
= (wndPtr
->flags
& WIN_NCACTIVATED
) != 0;
652 WIN_ReleasePtr( wndPtr
);
656 case WM_NOTIFYFORMAT
:
657 if (IsWindowUnicode(hwnd
)) return NFR_UNICODE
;
658 else return NFR_ANSI
;
661 case WM_QUERYENDSESSION
:
667 WND
*wndPtr
= WIN_GetPtr( hwnd
);
672 ret
= wndPtr
->hIconSmall
;
673 wndPtr
->hIconSmall
= (HICON
)lParam
;
677 wndPtr
->hIcon
= (HICON
)lParam
;
683 WIN_ReleasePtr( wndPtr
);
685 USER_Driver
->pSetWindowIcon( hwnd
, wParam
, (HICON
)lParam
);
687 if( (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
688 NC_HandleNCPaint( hwnd
, (HRGN
)1 ); /* Repaint caption */
696 WND
*wndPtr
= WIN_GetPtr( hwnd
);
701 ret
= wndPtr
->hIconSmall
;
707 ret
= wndPtr
->hIconSmall
;
708 if (!ret
) ret
= (HICON
)GetClassLongPtrW( hwnd
, GCLP_HICONSM
);
709 /* FIXME: should have a default here if class icon is null */
715 WIN_ReleasePtr( wndPtr
);
720 SendMessageW( GetParent(hwnd
), msg
, wParam
, lParam
);
725 HWND parent
= GetParent(hwnd
);
727 HOOK_CallHooks(WH_SHELL
, HSHELL_APPCOMMAND
, wParam
, lParam
, TRUE
);
729 SendMessageW( parent
, msg
, wParam
, lParam
);
736 hi
.cbSize
= sizeof(HELPINFO
);
737 GetCursorPos( &hi
.MousePos
);
738 if (MENU_IsMenuActive())
740 hi
.iContextType
= HELPINFO_MENUITEM
;
741 hi
.hItemHandle
= MENU_IsMenuActive();
742 hi
.iCtrlId
= MenuItemFromPoint( hwnd
, hi
.hItemHandle
, hi
.MousePos
);
743 hi
.dwContextId
= GetMenuContextHelpId( hi
.hItemHandle
);
747 hi
.iContextType
= HELPINFO_WINDOW
;
748 hi
.hItemHandle
= hwnd
;
749 hi
.iCtrlId
= GetWindowLongPtrA( hwnd
, GWLP_ID
);
750 hi
.dwContextId
= GetWindowContextHelpId( hwnd
);
752 SendMessageW( hwnd
, WM_HELP
, 0, (LPARAM
)&hi
);
756 case WM_INPUTLANGCHANGEREQUEST
:
757 ActivateKeyboardLayout( (HKL
)lParam
, 0 );
760 case WM_INPUTLANGCHANGE
:
763 HWND
*win_array
= WIN_ListChildren( hwnd
);
767 while (win_array
[count
])
768 SendMessageW( win_array
[count
++], WM_INPUTLANGCHANGE
, wParam
, lParam
);
769 HeapFree(GetProcessHeap(),0,win_array
);
778 static LPARAM
DEFWND_GetTextA( WND
*wndPtr
, LPSTR dest
, WPARAM wParam
)
786 if (!WideCharToMultiByte( CP_ACP
, 0, wndPtr
->text
, -1,
787 dest
, wParam
, NULL
, NULL
)) dest
[wParam
-1] = 0;
788 result
= strlen( dest
);
800 /***********************************************************************
801 * DefWindowProcA (USER32.@)
803 * See DefWindowProcW.
805 LRESULT WINAPI
DefWindowProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
810 if (!(full_handle
= WIN_IsCurrentProcess( hwnd
)))
812 if (!IsWindow( hwnd
)) return 0;
813 ERR( "called for other process window %p\n", hwnd
);
818 SPY_EnterMessage( SPY_DEFWNDPROC
, hwnd
, msg
, wParam
, lParam
);
825 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
826 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
827 * may have child window IDs instead of window name */
828 if (HIWORD(cs
->lpszName
))
829 DEFWND_SetTextA( hwnd
, cs
->lpszName
);
834 case WM_GETTEXTLENGTH
:
836 WND
*wndPtr
= WIN_GetPtr( hwnd
);
837 if (wndPtr
&& wndPtr
->text
)
838 result
= WideCharToMultiByte( CP_ACP
, 0, wndPtr
->text
, strlenW(wndPtr
->text
),
839 NULL
, 0, NULL
, NULL
);
840 WIN_ReleasePtr( wndPtr
);
847 LPSTR dest
= (LPSTR
)lParam
;
848 WND
*wndPtr
= WIN_GetPtr( hwnd
);
851 result
= DEFWND_GetTextA( wndPtr
, dest
, wParam
);
853 WIN_ReleasePtr( wndPtr
);
858 DEFWND_SetTextA( hwnd
, (LPCSTR
)lParam
);
859 if( (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
860 NC_HandleNCPaint( hwnd
, (HRGN
)1 ); /* Repaint caption */
861 result
= 1; /* success. FIXME: check text length */
865 if (HIBYTE(wParam
)) PostMessageA( hwnd
, WM_CHAR
, HIBYTE(wParam
), lParam
);
866 PostMessageA( hwnd
, WM_CHAR
, LOBYTE(wParam
), lParam
);
870 result
= PostMessageA( hwnd
, WM_KEYDOWN
, wParam
, lParam
);
874 result
= PostMessageA( hwnd
, WM_KEYUP
, wParam
, lParam
);
877 case WM_IME_STARTCOMPOSITION
:
878 case WM_IME_COMPOSITION
:
879 case WM_IME_ENDCOMPOSITION
:
885 hwndIME
= DEFWND_ImmGetDefaultIMEWnd( hwnd
);
887 result
= SendMessageA( hwndIME
, msg
, wParam
, lParam
);
890 case WM_IME_SETCONTEXT
:
894 hwndIME
= DEFWND_ImmGetDefaultIMEWnd( hwnd
);
896 result
= DEFWND_ImmIsUIMessageA( hwndIME
, msg
, wParam
, lParam
);
902 CHAR ch
= LOWORD(wParam
);
904 MultiByteToWideChar(CP_ACP
, 0, &ch
, 1, &wch
, 1);
905 wParam
= MAKEWPARAM( wch
, HIWORD(wParam
) );
909 result
= DEFWND_DefWinProc( hwnd
, msg
, wParam
, lParam
);
913 SPY_ExitMessage( SPY_RESULT_DEFWND
, hwnd
, msg
, result
, wParam
, lParam
);
918 static LPARAM
DEFWND_GetTextW( WND
*wndPtr
, LPWSTR dest
, WPARAM wParam
)
926 lstrcpynW( dest
, wndPtr
->text
, wParam
);
927 result
= strlenW( dest
);
940 /***********************************************************************
941 * DefWindowProcW (USER32.@) Calls default window message handler
943 * Calls default window procedure for messages not processed
947 * Return value is dependent upon the message.
949 LRESULT WINAPI
DefWindowProcW(
950 HWND hwnd
, /* [in] window procedure receiving message */
951 UINT msg
, /* [in] message identifier */
952 WPARAM wParam
, /* [in] first message parameter */
953 LPARAM lParam
) /* [in] second message parameter */
958 if (!(full_handle
= WIN_IsCurrentProcess( hwnd
)))
960 if (!IsWindow( hwnd
)) return 0;
961 ERR( "called for other process window %p\n", hwnd
);
965 SPY_EnterMessage( SPY_DEFWNDPROC
, hwnd
, msg
, wParam
, lParam
);
972 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lParam
;
973 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
974 * may have child window IDs instead of window name */
975 if (HIWORD(cs
->lpszName
))
976 DEFWND_SetTextW( hwnd
, cs
->lpszName
);
981 case WM_GETTEXTLENGTH
:
983 WND
*wndPtr
= WIN_GetPtr( hwnd
);
984 if (wndPtr
&& wndPtr
->text
) result
= (LRESULT
)strlenW(wndPtr
->text
);
985 WIN_ReleasePtr( wndPtr
);
992 LPWSTR dest
= (LPWSTR
)lParam
;
993 WND
*wndPtr
= WIN_GetPtr( hwnd
);
996 result
= DEFWND_GetTextW( wndPtr
, dest
, wParam
);
997 WIN_ReleasePtr( wndPtr
);
1002 DEFWND_SetTextW( hwnd
, (LPCWSTR
)lParam
);
1003 if( (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1004 NC_HandleNCPaint( hwnd
, (HRGN
)1 ); /* Repaint caption */
1005 result
= 1; /* success. FIXME: check text length */
1009 PostMessageW( hwnd
, WM_CHAR
, wParam
, lParam
);
1012 case WM_IME_KEYDOWN
:
1013 result
= PostMessageW( hwnd
, WM_KEYDOWN
, wParam
, lParam
);
1017 result
= PostMessageW( hwnd
, WM_KEYUP
, wParam
, lParam
);
1020 case WM_IME_SETCONTEXT
:
1024 hwndIME
= DEFWND_ImmGetDefaultIMEWnd( hwnd
);
1026 result
= DEFWND_ImmIsUIMessageW( hwndIME
, msg
, wParam
, lParam
);
1030 case WM_IME_STARTCOMPOSITION
:
1031 case WM_IME_COMPOSITION
:
1032 case WM_IME_ENDCOMPOSITION
:
1038 hwndIME
= DEFWND_ImmGetDefaultIMEWnd( hwnd
);
1040 result
= SendMessageW( hwndIME
, msg
, wParam
, lParam
);
1045 result
= DEFWND_DefWinProc( hwnd
, msg
, wParam
, lParam
);
1048 SPY_ExitMessage( SPY_RESULT_DEFWND
, hwnd
, msg
, result
, wParam
, lParam
);