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))
71 SendMessageW( hwnd, WM_SIZE, SIZE_MINIMIZED, 0 );
75 WPARAM wp = IsZoomed( hwnd ) ? SIZE_MAXIMIZED : SIZE_RESTORED;
77 SendMessageW( hwnd, WM_SIZE, wp, MAKELONG(rect.right-rect.left, rect.bottom-rect.top) );
83 /***********************************************************************
86 * Set the window text.
88 static void DEFWND_SetTextA( HWND hwnd, LPCSTR text )
95 count = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
97 if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
98 if ((textW = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
100 HeapFree(GetProcessHeap(), 0, wndPtr->text);
101 wndPtr->text = textW;
102 MultiByteToWideChar( CP_ACP, 0, text, -1, textW, count );
103 SERVER_START_REQ( set_window_text )
105 req->handle = wine_server_user_handle( hwnd );
106 wine_server_add_data( req, textW, (count-1) * sizeof(WCHAR) );
107 wine_server_call( req );
112 ERR("Not enough memory for window text\n");
113 WIN_ReleasePtr( wndPtr );
115 USER_Driver->pSetWindowText( hwnd, textW );
118 /***********************************************************************
121 * Set the window text.
123 static void DEFWND_SetTextW( HWND hwnd, LPCWSTR text )
125 static const WCHAR empty_string[] = {0};
129 if (!text) text = empty_string;
130 count = strlenW(text) + 1;
132 if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
133 HeapFree(GetProcessHeap(), 0, wndPtr->text);
134 if ((wndPtr->text = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
136 strcpyW( wndPtr->text, text );
137 SERVER_START_REQ( set_window_text )
139 req->handle = wine_server_user_handle( hwnd );
140 wine_server_add_data( req, wndPtr->text, (count-1) * sizeof(WCHAR) );
141 wine_server_call( req );
146 ERR("Not enough memory for window text\n");
148 WIN_ReleasePtr( wndPtr );
150 USER_Driver->pSetWindowText( hwnd, text );
153 /***********************************************************************
154 * DEFWND_ControlColor
156 * Default colors for control painting.
158 HBRUSH DEFWND_ControlColor( HDC hDC, UINT ctlType )
160 if( ctlType == CTLCOLOR_SCROLLBAR)
162 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
163 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
164 SetTextColor( hDC, GetSysColor(COLOR_3DFACE));
165 SetBkColor( hDC, bk);
167 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
168 * we better use 0x55aa bitmap brush to make scrollbar's background
169 * look different from the window background.
171 if (bk == GetSysColor(COLOR_WINDOW))
172 return SYSCOLOR_55AABrush;
174 UnrealizeObject( hb );
178 SetTextColor( hDC, GetSysColor(COLOR_WINDOWTEXT));
180 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
181 SetBkColor( hDC, GetSysColor(COLOR_WINDOW) );
183 SetBkColor( hDC, GetSysColor(COLOR_3DFACE) );
184 return GetSysColorBrush(COLOR_3DFACE);
186 return GetSysColorBrush(COLOR_WINDOW);
190 /***********************************************************************
193 * This method handles the default behavior for the WM_PRINT message.
195 static void DEFWND_Print( HWND hwnd, HDC hdc, ULONG uFlags)
200 if ( (uFlags & PRF_CHECKVISIBLE) &&
201 !IsWindowVisible(hwnd) )
205 * Unimplemented flags.
207 if ( (uFlags & PRF_CHILDREN) ||
208 (uFlags & PRF_OWNED) ||
209 (uFlags & PRF_NONCLIENT) )
211 WARN("WM_PRINT message with unsupported flags\n");
217 if ( uFlags & PRF_ERASEBKGND)
218 SendMessageW(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
223 if ( uFlags & PRF_CLIENT)
224 SendMessageW(hwnd, WM_PRINTCLIENT, (WPARAM)hdc, uFlags);
229 * helpers for calling IMM32
231 * WM_IME_* messages are generated only by IMM32,
232 * so I assume imm32 is already LoadLibrary-ed.
234 static HWND DEFWND_ImmGetDefaultIMEWnd( HWND hwnd )
236 HINSTANCE hInstIMM = GetModuleHandleW( imm32W );
237 HWND (WINAPI *pFunc)(HWND);
242 ERR( "cannot get IMM32 handle\n" );
246 pFunc = (void*)GetProcAddress(hInstIMM,"ImmGetDefaultIMEWnd");
248 hwndRet = (*pFunc)( hwnd );
253 static BOOL DEFWND_ImmIsUIMessageA( HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam )
255 HINSTANCE hInstIMM = GetModuleHandleW( imm32W );
256 BOOL (WINAPI *pFunc)(HWND,UINT,WPARAM,LPARAM);
261 ERR( "cannot get IMM32 handle\n" );
265 pFunc = (void*)GetProcAddress(hInstIMM,"ImmIsUIMessageA");
267 fRet = (*pFunc)( hwndIME, msg, wParam, lParam );
272 static BOOL DEFWND_ImmIsUIMessageW( HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam )
274 HINSTANCE hInstIMM = GetModuleHandleW( imm32W );
275 BOOL (WINAPI *pFunc)(HWND,UINT,WPARAM,LPARAM);
280 ERR( "cannot get IMM32 handle\n" );
284 pFunc = (void*)GetProcAddress(hInstIMM,"ImmIsUIMessageW");
286 fRet = (*pFunc)( hwndIME, msg, wParam, lParam );
293 /***********************************************************************
296 * Default window procedure for messages that are the same in Ansi and Unicode.
298 static LRESULT DEFWND_DefWinProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
303 return NC_HandleNCPaint( hwnd, (HRGN)wParam );
308 pt.x = (short)LOWORD(lParam);
309 pt.y = (short)HIWORD(lParam);
310 return NC_HandleNCHitTest( hwnd, pt );
314 return NC_HandleNCCalcSize( hwnd, (RECT *)lParam );
316 case WM_WINDOWPOSCHANGING:
317 return WINPOS_HandleWindowPosChanging( hwnd, (WINDOWPOS *)lParam );
319 case WM_WINDOWPOSCHANGED:
320 DEFWND_HandleWindowPosChanged( hwnd, (const WINDOWPOS *)lParam );
326 iF10Key = iMenuSysKey = 0;
329 case WM_NCLBUTTONDOWN:
330 return NC_HandleNCLButtonDown( hwnd, wParam, lParam );
332 case WM_LBUTTONDBLCLK:
333 return NC_HandleNCLButtonDblClk( hwnd, HTCLIENT, lParam );
335 case WM_NCLBUTTONDBLCLK:
336 return NC_HandleNCLButtonDblClk( hwnd, wParam, lParam );
338 case WM_NCRBUTTONDOWN:
339 /* in Windows, capture is taken when right-clicking on the caption bar */
340 if (wParam==HTCAPTION)
350 if (hwnd == GetCapture())
351 /* release capture if we took it on WM_NCRBUTTONDOWN */
354 pt.x = (short)LOWORD(lParam);
355 pt.y = (short)HIWORD(lParam);
356 ClientToScreen(hwnd, &pt);
357 SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM)hwnd, MAKELPARAM(pt.x, pt.y) );
363 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
364 * in Windows), but what _should_ we do? According to MSDN :
365 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
366 * message to the window". When is it appropriate?
371 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
372 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
377 WND *wndPtr = WIN_GetPtr( hwnd );
378 HMENU hMenu = wndPtr->hSysMenu;
379 WIN_ReleasePtr( wndPtr );
380 if (!hMenu) return 0;
381 pt.x = (short)LOWORD(lParam);
382 pt.y = (short)HIWORD(lParam);
383 hitcode = NC_HandleNCHitTest(hwnd, pt);
385 /* Track system popup if click was in the caption area. */
386 if (hitcode==HTCAPTION || hitcode==HTSYSMENU)
387 TrackPopupMenu(GetSystemMenu(hwnd, FALSE),
388 TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
389 pt.x, pt.y, 0, hwnd, NULL);
393 case WM_POPUPSYSTEMMENU:
395 /* This is an undocumented message used by the windows taskbar to
396 display the system menu of windows that belong to other processes. */
397 HMENU menu = GetSystemMenu(hwnd, FALSE);
400 TrackPopupMenu(menu, TPM_LEFTBUTTON|TPM_RIGHTBUTTON,
401 LOWORD(lParam), HIWORD(lParam), 0, hwnd, NULL);
406 return NC_HandleNCActivate( hwnd, wParam, lParam );
410 WND *wndPtr = WIN_GetPtr( hwnd );
411 if (!wndPtr) return 0;
412 HeapFree( GetProcessHeap(), 0, wndPtr->text );
414 HeapFree( GetProcessHeap(), 0, wndPtr->pScroll );
415 wndPtr->pScroll = NULL;
416 WIN_ReleasePtr( wndPtr );
421 DEFWND_Print(hwnd, (HDC)wParam, lParam);
428 HDC hdc = BeginPaint( hwnd, &ps );
432 if (IsIconic(hwnd) && ((hIcon = (HICON)GetClassLongPtrW( hwnd, GCLP_HICON))) )
437 GetClientRect( hwnd, &rc );
438 x = (rc.right - rc.left - GetSystemMetrics(SM_CXICON))/2;
439 y = (rc.bottom - rc.top - GetSystemMetrics(SM_CYICON))/2;
440 TRACE("Painting class icon: vis rect=(%s)\n",
441 wine_dbgstr_rect(&ps.rcPaint));
442 DrawIcon( hdc, x, y, hIcon );
444 EndPaint( hwnd, &ps );
450 RedrawWindow ( hwnd, NULL, 0, RDW_ERASENOW | RDW_ERASE | RDW_ALLCHILDREN );
454 if (wParam) WIN_SetStyle( hwnd, WS_VISIBLE, 0 );
457 RedrawWindow( hwnd, NULL, 0, RDW_ALLCHILDREN | RDW_VALIDATE );
458 WIN_SetStyle( hwnd, 0, WS_VISIBLE );
463 DestroyWindow( hwnd );
466 case WM_MOUSEACTIVATE:
467 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
469 LONG ret = SendMessageW( GetParent(hwnd), WM_MOUSEACTIVATE, wParam, lParam );
473 /* Caption clicks are handled by NC_HandleNCLButtonDown() */
477 /* The default action in Windows is to set the keyboard focus to
478 * the window, if it's being activated and not minimized */
479 if (LOWORD(wParam) != WA_INACTIVE) {
480 if (!IsIconic(hwnd)) SetFocus(hwnd);
485 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
486 return SendMessageW( GetParent(hwnd), WM_MOUSEWHEEL, wParam, lParam );
490 case WM_ICONERASEBKGND:
493 HDC hdc = (HDC)wParam;
494 HBRUSH hbr = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND );
497 if (GetClassLongW( hwnd, GCL_STYLE ) & CS_PARENTDC)
499 /* can't use GetClipBox with a parent DC or we fill the whole parent */
500 GetClientRect( hwnd, &rect );
501 DPtoLP( hdc, (LPPOINT)&rect, 2 );
503 else GetClipBox( hdc, &rect );
504 FillRect( hdc, &rect, hbr );
511 case WM_CTLCOLORMSGBOX:
512 case WM_CTLCOLOREDIT:
513 case WM_CTLCOLORLISTBOX:
516 case WM_CTLCOLORSTATIC:
517 case WM_CTLCOLORSCROLLBAR:
518 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, msg - WM_CTLCOLORMSGBOX );
521 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, HIWORD(lParam) );
524 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
526 /* with the exception of the border around a resizable wnd,
527 * give the parent first chance to set the cursor */
528 if ((LOWORD(lParam) < HTSIZEFIRST) || (LOWORD(lParam) > HTSIZELAST))
530 if (SendMessageW(GetParent(hwnd), WM_SETCURSOR, wParam, lParam)) return TRUE;
533 NC_HandleSetCursor( hwnd, wParam, lParam );
537 return NC_HandleSysCommand( hwnd, wParam, lParam );
540 if(wParam == VK_F10) iF10Key = VK_F10;
544 if( HIWORD(lParam) & KEYDATA_ALT )
546 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
547 if ( (wParam == VK_MENU || wParam == VK_LMENU
548 || wParam == VK_RMENU) && !iMenuSysKey )
555 if( wParam == VK_F4 ) /* try to close the window */
557 HWND top = GetAncestor( hwnd, GA_ROOT );
558 if (!(GetClassLongW( top, GCL_STYLE ) & CS_NOCLOSE))
559 PostMessageW( top, WM_SYSCOMMAND, SC_CLOSE, 0 );
562 else if( wParam == VK_F10 )
564 else if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
565 SendMessageW( hwnd, WM_SYSCOMMAND, SC_KEYMENU, ' ' );
570 /* Press and release F10 or ALT */
571 if (((wParam == VK_MENU || wParam == VK_LMENU || wParam == VK_RMENU)
572 && iMenuSysKey) || ((wParam == VK_F10) && iF10Key))
573 SendMessageW( GetAncestor( hwnd, GA_ROOT ), WM_SYSCOMMAND, SC_KEYMENU, 0L );
574 iMenuSysKey = iF10Key = 0;
580 if (wParam == '\r' && IsIconic(hwnd))
582 PostMessageW( hwnd, WM_SYSCOMMAND, SC_RESTORE, 0L );
585 if ((HIWORD(lParam) & KEYDATA_ALT) && wParam)
587 if (wParam == '\t' || wParam == '\x1b') break;
588 if (wParam == ' ' && (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD))
589 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
591 SendMessageW( hwnd, WM_SYSCOMMAND, SC_KEYMENU, wParam );
593 else /* check for Ctrl-Esc */
594 if (wParam != '\x1b') MessageBeep(0);
600 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
602 if (!lParam) return 0; /* sent from ShowWindow */
603 if ((style & WS_VISIBLE) && wParam) return 0;
604 if (!(style & WS_VISIBLE) && !wParam) return 0;
605 if (!GetWindow( hwnd, GW_OWNER )) return 0;
606 if (!(pWnd = WIN_GetPtr( hwnd ))) return 0;
607 if (pWnd == WND_OTHER_PROCESS) return 0;
610 if (!(pWnd->flags & WIN_NEEDS_SHOW_OWNEDPOPUP))
612 WIN_ReleasePtr( pWnd );
615 pWnd->flags &= ~WIN_NEEDS_SHOW_OWNEDPOPUP;
617 else pWnd->flags |= WIN_NEEDS_SHOW_OWNEDPOPUP;
618 WIN_ReleasePtr( pWnd );
619 ShowWindow( hwnd, wParam ? SW_SHOWNOACTIVATE : SW_HIDE );
625 MENU_EndMenu( hwnd );
626 if (GetCapture() == hwnd) ReleaseCapture();
636 case WM_QUERYDROPOBJECT:
637 return (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_ACCEPTFILES) != 0;
639 case WM_QUERYDRAGICON:
643 HICON hIcon = (HICON)GetClassLongPtrW( hwnd, GCLP_HICON );
644 HINSTANCE instance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
645 if (hIcon) return (LRESULT)hIcon;
646 for(len=1; len<64; len++)
647 if((hIcon = LoadIconW(instance, MAKEINTRESOURCEW(len))))
648 return (LRESULT)hIcon;
649 return (LRESULT)LoadIconW(0, (LPWSTR)IDI_APPLICATION);
653 case WM_ISACTIVEICON:
655 WND *wndPtr = WIN_GetPtr( hwnd );
656 BOOL ret = (wndPtr->flags & WIN_NCACTIVATED) != 0;
657 WIN_ReleasePtr( wndPtr );
661 case WM_NOTIFYFORMAT:
662 if (IsWindowUnicode(hwnd)) return NFR_UNICODE;
663 else return NFR_ANSI;
666 case WM_QUERYENDSESSION:
672 WND *wndPtr = WIN_GetPtr( hwnd );
677 ret = wndPtr->hIconSmall;
678 wndPtr->hIconSmall = (HICON)lParam;
682 wndPtr->hIcon = (HICON)lParam;
688 WIN_ReleasePtr( wndPtr );
690 USER_Driver->pSetWindowIcon( hwnd, wParam, (HICON)lParam );
692 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
693 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
701 WND *wndPtr = WIN_GetPtr( hwnd );
706 ret = wndPtr->hIconSmall;
712 ret = wndPtr->hIconSmall;
713 if (!ret) ret = (HICON)GetClassLongPtrW( hwnd, GCLP_HICONSM );
714 /* FIXME: should have a default here if class icon is null */
720 WIN_ReleasePtr( wndPtr );
725 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
730 HWND parent = GetParent(hwnd);
732 HOOK_CallHooks(WH_SHELL, HSHELL_APPCOMMAND, wParam, lParam, TRUE);
734 SendMessageW( parent, msg, wParam, lParam );
741 hi.cbSize = sizeof(HELPINFO);
742 GetCursorPos( &hi.MousePos );
743 if (MENU_IsMenuActive())
745 hi.iContextType = HELPINFO_MENUITEM;
746 hi.hItemHandle = MENU_IsMenuActive();
747 hi.iCtrlId = MenuItemFromPoint( hwnd, hi.hItemHandle, hi.MousePos );
748 hi.dwContextId = GetMenuContextHelpId( hi.hItemHandle );
752 hi.iContextType = HELPINFO_WINDOW;
753 hi.hItemHandle = hwnd;
754 hi.iCtrlId = GetWindowLongPtrA( hwnd, GWLP_ID );
755 hi.dwContextId = GetWindowContextHelpId( hwnd );
757 SendMessageW( hwnd, WM_HELP, 0, (LPARAM)&hi );
761 case WM_INPUTLANGCHANGEREQUEST:
762 ActivateKeyboardLayout( (HKL)lParam, 0 );
765 case WM_INPUTLANGCHANGE:
768 HWND *win_array = WIN_ListChildren( hwnd );
772 while (win_array[count])
773 SendMessageW( win_array[count++], WM_INPUTLANGCHANGE, wParam, lParam);
774 HeapFree(GetProcessHeap(),0,win_array);
783 static LPARAM DEFWND_GetTextA( WND *wndPtr, LPSTR dest, WPARAM wParam )
791 if (!WideCharToMultiByte( CP_ACP, 0, wndPtr->text, -1,
792 dest, wParam, NULL, NULL )) dest[wParam-1] = 0;
793 result = strlen( dest );
805 /***********************************************************************
806 * DefWindowProcA (USER32.@)
808 * See DefWindowProcW.
810 LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
815 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
817 if (!IsWindow( hwnd )) return 0;
818 ERR( "called for other process window %p\n", hwnd );
823 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
830 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
831 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
832 * may have child window IDs instead of window name */
833 if (HIWORD(cs->lpszName))
834 DEFWND_SetTextA( hwnd, cs->lpszName );
839 case WM_GETTEXTLENGTH:
841 WND *wndPtr = WIN_GetPtr( hwnd );
842 if (wndPtr && wndPtr->text)
843 result = WideCharToMultiByte( CP_ACP, 0, wndPtr->text, strlenW(wndPtr->text),
844 NULL, 0, NULL, NULL );
845 WIN_ReleasePtr( wndPtr );
852 LPSTR dest = (LPSTR)lParam;
853 WND *wndPtr = WIN_GetPtr( hwnd );
856 result = DEFWND_GetTextA( wndPtr, dest, wParam );
858 WIN_ReleasePtr( wndPtr );
863 DEFWND_SetTextA( hwnd, (LPCSTR)lParam );
864 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
865 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
866 result = 1; /* success. FIXME: check text length */
870 if (HIBYTE(wParam)) PostMessageA( hwnd, WM_CHAR, HIBYTE(wParam), lParam );
871 PostMessageA( hwnd, WM_CHAR, LOBYTE(wParam), lParam );
875 result = PostMessageA( hwnd, WM_KEYDOWN, wParam, lParam );
879 result = PostMessageA( hwnd, WM_KEYUP, wParam, lParam );
882 case WM_IME_STARTCOMPOSITION:
883 case WM_IME_COMPOSITION:
884 case WM_IME_ENDCOMPOSITION:
890 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
892 result = SendMessageA( hwndIME, msg, wParam, lParam );
895 case WM_IME_SETCONTEXT:
899 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
901 result = DEFWND_ImmIsUIMessageA( hwndIME, msg, wParam, lParam );
907 CHAR ch = LOWORD(wParam);
909 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
910 wParam = MAKEWPARAM( wch, HIWORD(wParam) );
914 result = DEFWND_DefWinProc( hwnd, msg, wParam, lParam );
918 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
923 static LPARAM DEFWND_GetTextW( WND *wndPtr, LPWSTR dest, WPARAM wParam )
931 lstrcpynW( dest, wndPtr->text, wParam );
932 result = strlenW( dest );
945 /***********************************************************************
946 * DefWindowProcW (USER32.@) Calls default window message handler
948 * Calls default window procedure for messages not processed
952 * Return value is dependent upon the message.
954 LRESULT WINAPI DefWindowProcW(
955 HWND hwnd, /* [in] window procedure receiving message */
956 UINT msg, /* [in] message identifier */
957 WPARAM wParam, /* [in] first message parameter */
958 LPARAM lParam ) /* [in] second message parameter */
963 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
965 if (!IsWindow( hwnd )) return 0;
966 ERR( "called for other process window %p\n", hwnd );
970 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
977 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
978 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
979 * may have child window IDs instead of window name */
980 if (HIWORD(cs->lpszName))
981 DEFWND_SetTextW( hwnd, cs->lpszName );
986 case WM_GETTEXTLENGTH:
988 WND *wndPtr = WIN_GetPtr( hwnd );
989 if (wndPtr && wndPtr->text) result = (LRESULT)strlenW(wndPtr->text);
990 WIN_ReleasePtr( wndPtr );
997 LPWSTR dest = (LPWSTR)lParam;
998 WND *wndPtr = WIN_GetPtr( hwnd );
1001 result = DEFWND_GetTextW( wndPtr, dest, wParam );
1002 WIN_ReleasePtr( wndPtr );
1007 DEFWND_SetTextW( hwnd, (LPCWSTR)lParam );
1008 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
1009 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
1010 result = 1; /* success. FIXME: check text length */
1014 PostMessageW( hwnd, WM_CHAR, wParam, lParam );
1017 case WM_IME_KEYDOWN:
1018 result = PostMessageW( hwnd, WM_KEYDOWN, wParam, lParam );
1022 result = PostMessageW( hwnd, WM_KEYUP, wParam, lParam );
1025 case WM_IME_SETCONTEXT:
1029 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
1031 result = DEFWND_ImmIsUIMessageW( hwndIME, msg, wParam, lParam );
1035 case WM_IME_STARTCOMPOSITION:
1036 case WM_IME_COMPOSITION:
1037 case WM_IME_ENDCOMPOSITION:
1043 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
1045 result = SendMessageW( hwndIME, msg, wParam, lParam );
1050 result = DEFWND_DefWinProc( hwnd, msg, wParam, lParam );
1053 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );