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
)
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
)
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 case WM_NCLBUTTONDBLCLK
:
329 return NC_HandleNCLButtonDblClk( hwnd
, wParam
, lParam
);
331 case WM_NCRBUTTONDOWN
:
332 /* in Windows, capture is taken when right-clicking on the caption bar */
333 if (wParam
==HTCAPTION
)
343 if (hwnd
== GetCapture())
344 /* release capture if we took it on WM_NCRBUTTONDOWN */
347 pt
.x
= (short)LOWORD(lParam
);
348 pt
.y
= (short)HIWORD(lParam
);
349 ClientToScreen(hwnd
, &pt
);
350 SendMessageW( hwnd
, WM_CONTEXTMENU
, (WPARAM
)hwnd
, MAKELPARAM(pt
.x
, pt
.y
) );
356 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
357 * in Windows), but what _should_ we do? According to MSDN :
358 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
359 * message to the window". When is it appropriate?
364 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)
365 SendMessageW( GetParent(hwnd
), msg
, wParam
, lParam
);
370 WND
*wndPtr
= WIN_GetPtr( hwnd
);
371 HMENU hMenu
= wndPtr
->hSysMenu
;
372 WIN_ReleasePtr( wndPtr
);
373 if (!hMenu
) return 0;
374 pt
.x
= (short)LOWORD(lParam
);
375 pt
.y
= (short)HIWORD(lParam
);
376 hitcode
= NC_HandleNCHitTest(hwnd
, pt
);
378 /* Track system popup if click was in the caption area. */
379 if (hitcode
==HTCAPTION
|| hitcode
==HTSYSMENU
)
380 TrackPopupMenu(GetSystemMenu(hwnd
, FALSE
),
381 TPM_LEFTBUTTON
| TPM_RIGHTBUTTON
,
382 pt
.x
, pt
.y
, 0, hwnd
, NULL
);
387 return NC_HandleNCActivate( hwnd
, wParam
);
391 WND
*wndPtr
= WIN_GetPtr( hwnd
);
392 if (!wndPtr
) return 0;
393 HeapFree( GetProcessHeap(), 0, wndPtr
->text
);
395 HeapFree( GetProcessHeap(), 0, wndPtr
->pVScroll
);
396 HeapFree( GetProcessHeap(), 0, wndPtr
->pHScroll
);
397 wndPtr
->pVScroll
= wndPtr
->pHScroll
= NULL
;
398 WIN_ReleasePtr( wndPtr
);
403 DEFWND_Print(hwnd
, (HDC
)wParam
, lParam
);
410 HDC hdc
= BeginPaint( hwnd
, &ps
);
414 if (IsIconic(hwnd
) && ((hIcon
= (HICON
)GetClassLongPtrW( hwnd
, GCLP_HICON
))) )
419 GetClientRect( hwnd
, &rc
);
420 x
= (rc
.right
- rc
.left
- GetSystemMetrics(SM_CXICON
))/2;
421 y
= (rc
.bottom
- rc
.top
- GetSystemMetrics(SM_CYICON
))/2;
422 TRACE("Painting class icon: vis rect=(%d,%d - %d,%d)\n",
423 ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
424 DrawIcon( hdc
, x
, y
, hIcon
);
426 EndPaint( hwnd
, &ps
);
432 RedrawWindow ( hwnd
, NULL
, 0, RDW_ERASENOW
| RDW_ERASE
| RDW_ALLCHILDREN
);
436 if (wParam
) WIN_SetStyle( hwnd
, WS_VISIBLE
, 0 );
439 RedrawWindow( hwnd
, NULL
, 0, RDW_ALLCHILDREN
| RDW_VALIDATE
);
440 WIN_SetStyle( hwnd
, 0, WS_VISIBLE
);
445 DestroyWindow( hwnd
);
448 case WM_MOUSEACTIVATE
:
449 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)
451 LONG ret
= SendMessageW( GetParent(hwnd
), WM_MOUSEACTIVATE
, wParam
, lParam
);
455 /* Caption clicks are handled by NC_HandleNCLButtonDown() */
459 /* The default action in Windows is to set the keyboard focus to
460 * the window, if it's being activated and not minimized */
461 if (LOWORD(wParam
) != WA_INACTIVE
) {
462 if (!IsIconic(hwnd
)) SetFocus(hwnd
);
467 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)
468 return SendMessageW( GetParent(hwnd
), WM_MOUSEWHEEL
, wParam
, lParam
);
472 case WM_ICONERASEBKGND
:
475 HDC hdc
= (HDC
)wParam
;
476 HBRUSH hbr
= (HBRUSH
)GetClassLongPtrW( hwnd
, GCLP_HBRBACKGROUND
);
479 if (GetClassLongW( hwnd
, GCL_STYLE
) & CS_PARENTDC
)
481 /* can't use GetClipBox with a parent DC or we fill the whole parent */
482 GetClientRect( hwnd
, &rect
);
483 DPtoLP( hdc
, (LPPOINT
)&rect
, 2 );
485 else GetClipBox( hdc
, &rect
);
486 FillRect( hdc
, &rect
, hbr
);
493 case WM_CTLCOLORMSGBOX
:
494 case WM_CTLCOLOREDIT
:
495 case WM_CTLCOLORLISTBOX
:
498 case WM_CTLCOLORSTATIC
:
499 case WM_CTLCOLORSCROLLBAR
:
500 return (LRESULT
)DEFWND_ControlColor( (HDC
)wParam
, msg
- WM_CTLCOLORMSGBOX
);
503 return (LRESULT
)DEFWND_ControlColor( (HDC
)wParam
, HIWORD(lParam
) );
506 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)
508 /* with the exception of the border around a resizable wnd,
509 * give the parent first chance to set the cursor */
510 if ((LOWORD(lParam
) < HTSIZEFIRST
) || (LOWORD(lParam
) > HTSIZELAST
))
512 if (SendMessageW(GetParent(hwnd
), WM_SETCURSOR
, wParam
, lParam
)) return TRUE
;
515 NC_HandleSetCursor( hwnd
, wParam
, lParam
);
519 return NC_HandleSysCommand( hwnd
, wParam
, lParam
);
522 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
526 if( HIWORD(lParam
) & KEYDATA_ALT
)
528 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
529 if ( (wParam
== VK_MENU
|| wParam
== VK_LMENU
530 || wParam
== VK_RMENU
) && !iMenuSysKey
)
537 if( wParam
== VK_F4
) /* try to close the window */
539 HWND top
= GetAncestor( hwnd
, GA_ROOT
);
540 if (!(GetClassLongW( top
, GCL_STYLE
) & CS_NOCLOSE
))
541 PostMessageW( top
, WM_SYSCOMMAND
, SC_CLOSE
, 0 );
544 else if( wParam
== VK_F10
)
546 else if( wParam
== VK_ESCAPE
&& (GetKeyState(VK_SHIFT
) & 0x8000))
547 SendMessageW( hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, ' ' );
552 /* Press and release F10 or ALT */
553 if (((wParam
== VK_MENU
|| wParam
== VK_LMENU
|| wParam
== VK_RMENU
)
554 && iMenuSysKey
) || ((wParam
== VK_F10
) && iF10Key
))
555 SendMessageW( GetAncestor( hwnd
, GA_ROOT
), WM_SYSCOMMAND
, SC_KEYMENU
, 0L );
556 iMenuSysKey
= iF10Key
= 0;
562 if (wParam
== '\r' && IsIconic(hwnd
))
564 PostMessageW( hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0L );
567 if ((HIWORD(lParam
) & KEYDATA_ALT
) && wParam
)
569 if (wParam
== '\t' || wParam
== '\x1b') break;
570 if (wParam
== ' ' && (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
))
571 SendMessageW( GetParent(hwnd
), msg
, wParam
, lParam
);
573 SendMessageW( hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, wParam
);
575 else /* check for Ctrl-Esc */
576 if (wParam
!= '\x1b') MessageBeep(0);
582 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
584 if (!lParam
) return 0; /* sent from ShowWindow */
585 if ((style
& WS_VISIBLE
) && wParam
) return 0;
586 if (!(style
& WS_VISIBLE
) && !wParam
) return 0;
587 if (!GetWindow( hwnd
, GW_OWNER
)) return 0;
588 if (!(pWnd
= WIN_GetPtr( hwnd
))) return 0;
589 if (pWnd
== WND_OTHER_PROCESS
) return 0;
592 if (!(pWnd
->flags
& WIN_NEEDS_SHOW_OWNEDPOPUP
))
594 WIN_ReleasePtr( pWnd
);
597 pWnd
->flags
&= ~WIN_NEEDS_SHOW_OWNEDPOPUP
;
599 else pWnd
->flags
|= WIN_NEEDS_SHOW_OWNEDPOPUP
;
600 WIN_ReleasePtr( pWnd
);
601 ShowWindow( hwnd
, wParam
? SW_SHOWNOACTIVATE
: SW_HIDE
);
607 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)) EndMenu();
608 if (GetCapture() == hwnd
) ReleaseCapture();
618 case WM_QUERYDROPOBJECT
:
619 return (GetWindowLongA( hwnd
, GWL_EXSTYLE
) & WS_EX_ACCEPTFILES
) != 0;
621 case WM_QUERYDRAGICON
:
625 HICON hIcon
= (HICON
)GetClassLongPtrW( hwnd
, GCLP_HICON
);
626 HINSTANCE instance
= (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
);
627 if (hIcon
) return (LRESULT
)hIcon
;
628 for(len
=1; len
<64; len
++)
629 if((hIcon
= LoadIconW(instance
, MAKEINTRESOURCEW(len
))))
630 return (LRESULT
)hIcon
;
631 return (LRESULT
)LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
635 case WM_ISACTIVEICON
:
637 WND
*wndPtr
= WIN_GetPtr( hwnd
);
638 BOOL ret
= (wndPtr
->flags
& WIN_NCACTIVATED
) != 0;
639 WIN_ReleasePtr( wndPtr
);
643 case WM_NOTIFYFORMAT
:
644 if (IsWindowUnicode(hwnd
)) return NFR_UNICODE
;
645 else return NFR_ANSI
;
648 case WM_QUERYENDSESSION
:
659 WND
*wndPtr
= WIN_GetPtr( hwnd
);
664 ret
= wndPtr
->hIconSmall
;
665 wndPtr
->hIconSmall
= (HICON
)lParam
;
669 wndPtr
->hIcon
= (HICON
)lParam
;
675 WIN_ReleasePtr( wndPtr
);
677 USER_Driver
->pSetWindowIcon( hwnd
, wParam
, (HICON
)lParam
);
679 if( (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
680 NC_HandleNCPaint( hwnd
, (HRGN
)1 ); /* Repaint caption */
688 WND
*wndPtr
= WIN_GetPtr( hwnd
);
693 ret
= wndPtr
->hIconSmall
;
699 ret
= wndPtr
->hIconSmall
;
700 if (!ret
) ret
= (HICON
)GetClassLongPtrW( hwnd
, GCLP_HICONSM
);
701 /* FIXME: should have a default here if class icon is null */
707 WIN_ReleasePtr( wndPtr
);
712 SendMessageW( GetParent(hwnd
), msg
, wParam
, lParam
);
717 HWND parent
= GetParent(hwnd
);
719 HOOK_CallHooks(WH_SHELL
, HSHELL_APPCOMMAND
, wParam
, lParam
, TRUE
);
721 SendMessageW( parent
, msg
, wParam
, lParam
);
729 static LPARAM
DEFWND_GetTextA( WND
*wndPtr
, LPSTR dest
, WPARAM wParam
)
737 if (!WideCharToMultiByte( CP_ACP
, 0, wndPtr
->text
, -1,
738 dest
, wParam
, NULL
, NULL
)) dest
[wParam
-1] = 0;
739 result
= strlen( dest
);
751 /***********************************************************************
752 * DefWindowProcA (USER32.@)
754 * See DefWindowProcW.
756 LRESULT WINAPI
DefWindowProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
761 if (!(full_handle
= WIN_IsCurrentProcess( hwnd
)))
763 if (!IsWindow( hwnd
)) return 0;
764 ERR( "called for other process window %p\n", hwnd
);
769 SPY_EnterMessage( SPY_DEFWNDPROC
, hwnd
, msg
, wParam
, lParam
);
776 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
777 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
778 * may have child window IDs instead of window name */
779 if (HIWORD(cs
->lpszName
))
780 DEFWND_SetTextA( hwnd
, cs
->lpszName
);
785 case WM_GETTEXTLENGTH
:
787 WND
*wndPtr
= WIN_GetPtr( hwnd
);
788 if (wndPtr
&& wndPtr
->text
)
789 result
= WideCharToMultiByte( CP_ACP
, 0, wndPtr
->text
, strlenW(wndPtr
->text
),
790 NULL
, 0, NULL
, NULL
);
791 WIN_ReleasePtr( wndPtr
);
798 LPSTR dest
= (LPSTR
)lParam
;
799 WND
*wndPtr
= WIN_GetPtr( hwnd
);
802 result
= DEFWND_GetTextA( wndPtr
, dest
, wParam
);
804 WIN_ReleasePtr( wndPtr
);
809 DEFWND_SetTextA( hwnd
, (LPCSTR
)lParam
);
810 if( (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
811 NC_HandleNCPaint( hwnd
, (HRGN
)1 ); /* Repaint caption */
812 result
= 1; /* success. FIXME: check text length */
816 if (HIBYTE(wParam
)) PostMessageA( hwnd
, WM_CHAR
, HIBYTE(wParam
), lParam
);
817 PostMessageA( hwnd
, WM_CHAR
, LOBYTE(wParam
), lParam
);
821 result
= SendMessageA( hwnd
, WM_KEYDOWN
, wParam
, lParam
);
825 result
= SendMessageA( hwnd
, WM_KEYUP
, wParam
, lParam
);
828 case WM_IME_STARTCOMPOSITION
:
829 case WM_IME_COMPOSITION
:
830 case WM_IME_ENDCOMPOSITION
:
835 hwndIME
= DEFWND_ImmGetDefaultIMEWnd( hwnd
);
837 result
= SendMessageA( hwndIME
, msg
, wParam
, lParam
);
840 case WM_IME_SETCONTEXT
:
844 hwndIME
= DEFWND_ImmGetDefaultIMEWnd( hwnd
);
846 result
= DEFWND_ImmIsUIMessageA( hwndIME
, msg
, wParam
, lParam
);
850 case WM_INPUTLANGCHANGEREQUEST
:
851 /* notify about the switch only if it's really our current layout */
852 if ((HKL
)lParam
== GetKeyboardLayout(0))
853 result
= SendMessageA( hwnd
, WM_INPUTLANGCHANGE
, wParam
, lParam
);
860 CHAR ch
= LOWORD(wParam
);
862 MultiByteToWideChar(CP_ACP
, 0, &ch
, 1, &wch
, 1);
863 wParam
= MAKEWPARAM( wch
, HIWORD(wParam
) );
867 result
= DEFWND_DefWinProc( hwnd
, msg
, wParam
, lParam
);
871 SPY_ExitMessage( SPY_RESULT_DEFWND
, hwnd
, msg
, result
, wParam
, lParam
);
876 static LPARAM
DEFWND_GetTextW( WND
*wndPtr
, LPWSTR dest
, WPARAM wParam
)
884 lstrcpynW( dest
, wndPtr
->text
, wParam
);
885 result
= strlenW( dest
);
898 /***********************************************************************
899 * DefWindowProcW (USER32.@) Calls default window message handler
901 * Calls default window procedure for messages not processed
905 * Return value is dependent upon the message.
907 LRESULT WINAPI
DefWindowProcW(
908 HWND hwnd
, /* [in] window procedure receiving message */
909 UINT msg
, /* [in] message identifier */
910 WPARAM wParam
, /* [in] first message parameter */
911 LPARAM lParam
) /* [in] second message parameter */
916 if (!(full_handle
= WIN_IsCurrentProcess( hwnd
)))
918 if (!IsWindow( hwnd
)) return 0;
919 ERR( "called for other process window %p\n", hwnd
);
923 SPY_EnterMessage( SPY_DEFWNDPROC
, hwnd
, msg
, wParam
, lParam
);
930 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lParam
;
931 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
932 * may have child window IDs instead of window name */
933 if (HIWORD(cs
->lpszName
))
934 DEFWND_SetTextW( hwnd
, cs
->lpszName
);
939 case WM_GETTEXTLENGTH
:
941 WND
*wndPtr
= WIN_GetPtr( hwnd
);
942 if (wndPtr
&& wndPtr
->text
) result
= (LRESULT
)strlenW(wndPtr
->text
);
943 WIN_ReleasePtr( wndPtr
);
950 LPWSTR dest
= (LPWSTR
)lParam
;
951 WND
*wndPtr
= WIN_GetPtr( hwnd
);
954 result
= DEFWND_GetTextW( wndPtr
, dest
, wParam
);
955 WIN_ReleasePtr( wndPtr
);
960 DEFWND_SetTextW( hwnd
, (LPCWSTR
)lParam
);
961 if( (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
962 NC_HandleNCPaint( hwnd
, (HRGN
)1 ); /* Repaint caption */
963 result
= 1; /* success. FIXME: check text length */
967 PostMessageW( hwnd
, WM_CHAR
, wParam
, lParam
);
970 case WM_IME_SETCONTEXT
:
974 hwndIME
= DEFWND_ImmGetDefaultIMEWnd( hwnd
);
976 result
= DEFWND_ImmIsUIMessageW( hwndIME
, msg
, wParam
, lParam
);
980 case WM_IME_STARTCOMPOSITION
:
981 case WM_IME_COMPOSITION
:
982 case WM_IME_ENDCOMPOSITION
:
987 hwndIME
= DEFWND_ImmGetDefaultIMEWnd( hwnd
);
989 result
= SendMessageW( hwndIME
, msg
, wParam
, lParam
);
993 case WM_INPUTLANGCHANGEREQUEST
:
994 /* notify about the switch only if it's really our current layout */
995 if ((HKL
)lParam
== GetKeyboardLayout(0))
996 result
= SendMessageW( hwnd
, WM_INPUTLANGCHANGE
, wParam
, lParam
);
1002 result
= DEFWND_DefWinProc( hwnd
, msg
, wParam
, lParam
);
1005 SPY_ExitMessage( SPY_RESULT_DEFWND
, hwnd
, msg
, result
, wParam
, lParam
);