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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
29 #include "nonclient.h"
37 #include "wine/unicode.h"
38 #include "wine/winuser16.h"
39 #include "wine/server.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(win);
44 /* bits in the dwKeyData */
45 #define KEYDATA_ALT 0x2000
46 #define KEYDATA_PREVSTATE 0x4000
48 static short iF10Key = 0;
49 static short iMenuSysKey = 0;
51 /***********************************************************************
52 * DEFWND_HandleWindowPosChanged
54 * Handle the WM_WINDOWPOSCHANGED message.
56 static void DEFWND_HandleWindowPosChanged( HWND hwnd, UINT flags )
59 WND *wndPtr = WIN_GetPtr( hwnd );
61 rect = wndPtr->rectClient;
62 WIN_ReleasePtr( wndPtr );
64 if (!(flags & SWP_NOCLIENTMOVE))
65 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG(rect.left, rect.top));
67 if (!(flags & SWP_NOCLIENTSIZE))
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 if (wndPtr->text) 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 if (USER_Driver.pSetWindowText) 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 if (wndPtr->text) 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 if (USER_Driver.pSetWindowText) 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 CACHE_GetPattern55AABrush();
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 static void DEFWND_SetRedraw( HWND hwnd, WPARAM wParam )
190 WND *wndPtr = WIN_FindWndPtr( hwnd );
191 BOOL bVisible = wndPtr->dwStyle & WS_VISIBLE;
193 TRACE("%p %i\n", hwnd, (wParam!=0) );
199 WIN_SetStyle( hwnd, wndPtr->dwStyle | WS_VISIBLE );
200 DCE_InvalidateDCE( hwnd, &wndPtr->rectWindow );
205 if( wndPtr->dwStyle & WS_MINIMIZE ) wParam = RDW_VALIDATE;
206 else wParam = RDW_ALLCHILDREN | RDW_VALIDATE;
208 RedrawWindow( hwnd, NULL, 0, wParam );
209 DCE_InvalidateDCE( hwnd, &wndPtr->rectWindow );
210 WIN_SetStyle( hwnd, wndPtr->dwStyle & ~WS_VISIBLE );
212 WIN_ReleaseWndPtr( wndPtr );
215 /***********************************************************************
218 * This method handles the default behavior for the WM_PRINT message.
220 static void DEFWND_Print( HWND hwnd, HDC hdc, ULONG uFlags)
225 if ( (uFlags & PRF_CHECKVISIBLE) &&
226 !IsWindowVisible(hwnd) )
230 * Unimplemented flags.
232 if ( (uFlags & PRF_CHILDREN) ||
233 (uFlags & PRF_OWNED) ||
234 (uFlags & PRF_NONCLIENT) )
236 WARN("WM_PRINT message with unsupported flags\n");
242 if ( uFlags & PRF_ERASEBKGND)
243 SendMessageW(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
248 if ( uFlags & PRF_CLIENT)
249 SendMessageW(hwnd, WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
254 * helpers for calling IMM32
256 * WM_IME_* messages are generated only by IMM32,
257 * so I assume imm32 is already LoadLibrary-ed.
259 static HWND DEFWND_ImmGetDefaultIMEWnd( HWND hwnd )
261 HINSTANCE hInstIMM = GetModuleHandleA( "imm32" );
262 HWND (WINAPI *pFunc)(HWND);
267 ERR( "cannot get IMM32 handle\n" );
271 pFunc = (void*)GetProcAddress(hInstIMM,"ImmGetDefaultIMEWnd");
273 hwndRet = (*pFunc)( hwnd );
278 static BOOL DEFWND_ImmIsUIMessageA( HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam )
280 HINSTANCE hInstIMM = GetModuleHandleA( "imm32" );
281 BOOL (WINAPI *pFunc)(HWND,UINT,WPARAM,LPARAM);
286 ERR( "cannot get IMM32 handle\n" );
290 pFunc = (void*)GetProcAddress(hInstIMM,"ImmIsUIMessageA");
292 fRet = (*pFunc)( hwndIME, msg, wParam, lParam );
297 static BOOL DEFWND_ImmIsUIMessageW( HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam )
299 HINSTANCE hInstIMM = GetModuleHandleA( "imm32" );
300 BOOL (WINAPI *pFunc)(HWND,UINT,WPARAM,LPARAM);
305 ERR( "cannot get IMM32 handle\n" );
309 pFunc = (void*)GetProcAddress(hInstIMM,"ImmIsUIMessageW");
311 fRet = (*pFunc)( hwndIME, msg, wParam, lParam );
318 /***********************************************************************
321 * Default window procedure for messages that are the same in Win16 and Win32.
323 static LRESULT DEFWND_DefWinProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
328 return NC_HandleNCPaint( hwnd, (HRGN)wParam );
333 pt.x = (short)LOWORD(lParam);
334 pt.y = (short)HIWORD(lParam);
335 return NC_HandleNCHitTest( hwnd, pt );
338 case WM_NCLBUTTONDOWN:
339 return NC_HandleNCLButtonDown( hwnd, wParam, lParam );
341 case WM_LBUTTONDBLCLK:
342 case WM_NCLBUTTONDBLCLK:
343 return NC_HandleNCLButtonDblClk( hwnd, wParam, lParam );
345 case WM_NCRBUTTONDOWN:
346 /* in Windows, capture is taken when right-clicking on the caption bar */
347 if (wParam==HTCAPTION)
357 if (hwnd == GetCapture())
358 /* release capture if we took it on WM_NCRBUTTONDOWN */
361 pt.x = (short)LOWORD(lParam);
362 pt.y = (short)HIWORD(lParam);
363 ClientToScreen(hwnd, &pt);
364 SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM)hwnd, MAKELPARAM(pt.x, pt.y) );
370 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
371 * in Windows), but what _should_ we do? According to MSDN :
372 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
373 * message to the window". When is it appropriate?
378 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
379 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
384 WND *wndPtr = WIN_GetPtr( hwnd );
385 HMENU hMenu = wndPtr->hSysMenu;
386 WIN_ReleasePtr( wndPtr );
387 if (!hMenu) return 0;
388 pt.x = (short)LOWORD(lParam);
389 pt.y = (short)HIWORD(lParam);
390 hitcode = NC_HandleNCHitTest(hwnd, pt);
392 /* Track system popup if click was in the caption area. */
393 if (hitcode==HTCAPTION || hitcode==HTSYSMENU)
394 TrackPopupMenu(GetSystemMenu(hwnd, FALSE),
395 TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
396 pt.x, pt.y, 0, hwnd, NULL);
401 return NC_HandleNCActivate( hwnd, wParam );
405 WND *wndPtr = WIN_GetPtr( hwnd );
406 if (!wndPtr) return 0;
407 if (wndPtr->text) HeapFree( GetProcessHeap(), 0, wndPtr->text );
409 if (wndPtr->pVScroll) HeapFree( GetProcessHeap(), 0, wndPtr->pVScroll );
410 if (wndPtr->pHScroll) HeapFree( GetProcessHeap(), 0, wndPtr->pHScroll );
411 wndPtr->pVScroll = wndPtr->pHScroll = NULL;
412 WIN_ReleasePtr( wndPtr );
417 DEFWND_Print(hwnd, (HDC)wParam, lParam);
424 HDC hdc = BeginPaint( hwnd, &ps );
428 if (IsIconic(hwnd) && ((hIcon = (HICON)GetClassLongW( hwnd, GCL_HICON))) )
433 GetClientRect( hwnd, &rc );
434 x = (rc.right - rc.left - GetSystemMetrics(SM_CXICON))/2;
435 y = (rc.bottom - rc.top - GetSystemMetrics(SM_CYICON))/2;
436 TRACE("Painting class icon: vis rect=(%ld,%ld - %ld,%ld)\n",
437 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom );
438 DrawIcon( hdc, x, y, hIcon );
440 EndPaint( hwnd, &ps );
446 RedrawWindow ( hwnd, NULL, 0, RDW_ERASENOW | RDW_ERASE | RDW_ALLCHILDREN );
450 DEFWND_SetRedraw( hwnd, wParam );
454 DestroyWindow( hwnd );
457 case WM_MOUSEACTIVATE:
458 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
460 LONG ret = SendMessageW( GetParent(hwnd), WM_MOUSEACTIVATE, wParam, lParam );
464 /* Caption clicks are handled by the NC_HandleNCLButtonDown() */
465 return (LOWORD(lParam) >= HTCLIENT) ? MA_ACTIVATE : MA_NOACTIVATE;
468 /* The default action in Windows is to set the keyboard focus to
469 * the window, if it's being activated and not minimized */
470 if (LOWORD(wParam) != WA_INACTIVE) {
471 if (!IsIconic(hwnd)) SetFocus(hwnd);
476 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
477 return SendMessageW( GetParent(hwnd), WM_MOUSEWHEEL, wParam, lParam );
481 case WM_ICONERASEBKGND:
484 HDC hdc = (HDC)wParam;
485 HBRUSH hbr = (HBRUSH)GetClassLongW( hwnd, GCL_HBRBACKGROUND );
488 if (GetClassLongW( hwnd, GCL_STYLE ) & CS_PARENTDC)
490 /* can't use GetClipBox with a parent DC or we fill the whole parent */
491 GetClientRect( hwnd, &rect );
492 DPtoLP( hdc, (LPPOINT)&rect, 2 );
494 else GetClipBox( hdc, &rect );
495 FillRect( hdc, &rect, hbr );
502 case WM_CTLCOLORMSGBOX:
503 case WM_CTLCOLOREDIT:
504 case WM_CTLCOLORLISTBOX:
507 case WM_CTLCOLORSTATIC:
508 case WM_CTLCOLORSCROLLBAR:
509 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, msg - WM_CTLCOLORMSGBOX );
512 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, HIWORD(lParam) );
515 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
517 /* with the exception of the border around a resizable wnd,
518 * give the parent first chance to set the cursor */
519 if ((LOWORD(lParam) < HTSIZEFIRST) || (LOWORD(lParam) > HTSIZELAST))
521 if (SendMessageW(GetParent(hwnd), WM_SETCURSOR, wParam, lParam)) return TRUE;
524 NC_HandleSetCursor( hwnd, wParam, lParam );
528 return NC_HandleSysCommand( hwnd, wParam, lParam );
531 if(wParam == VK_F10) iF10Key = VK_F10;
535 if( HIWORD(lParam) & KEYDATA_ALT )
537 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
538 if( wParam == VK_MENU && !iMenuSysKey )
545 if( wParam == VK_F4 ) /* try to close the window */
547 HWND top = GetAncestor( hwnd, GA_ROOT );
548 if (!(GetClassLongW( top, GCL_STYLE ) & CS_NOCLOSE))
549 PostMessageW( top, WM_SYSCOMMAND, SC_CLOSE, 0 );
552 else if( wParam == VK_F10 )
555 if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
556 SendMessageW( hwnd, WM_SYSCOMMAND, SC_KEYMENU, ' ' );
561 /* Press and release F10 or ALT */
562 if (((wParam == VK_MENU) && iMenuSysKey) ||
563 ((wParam == VK_F10) && iF10Key))
564 SendMessageW( GetAncestor( hwnd, GA_ROOT ), WM_SYSCOMMAND, SC_KEYMENU, 0L );
565 iMenuSysKey = iF10Key = 0;
571 if (wParam == '\r' && IsIconic(hwnd))
573 PostMessageW( hwnd, WM_SYSCOMMAND, SC_RESTORE, 0L );
576 if ((HIWORD(lParam) & KEYDATA_ALT) && wParam)
578 if (wParam == '\t' || wParam == '\x1b') break;
579 if (wParam == ' ' && (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD))
580 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
582 SendMessageW( hwnd, WM_SYSCOMMAND, SC_KEYMENU, wParam );
584 else /* check for Ctrl-Esc */
585 if (wParam != '\x1b') MessageBeep(0);
591 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
592 if (!lParam) return 0; /* sent from ShowWindow */
593 if (!(style & WS_POPUP)) return 0;
594 if ((style & WS_VISIBLE) && wParam) return 0;
595 if (!(style & WS_VISIBLE) && !wParam) return 0;
596 if (!GetWindow( hwnd, GW_OWNER )) return 0;
597 ShowWindow( hwnd, wParam ? SW_SHOWNOACTIVATE : SW_HIDE );
602 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) EndMenu();
603 if (GetCapture() == hwnd) ReleaseCapture();
613 case WM_QUERYDROPOBJECT:
614 return (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_ACCEPTFILES) != 0;
616 case WM_QUERYDRAGICON:
620 HICON hIcon = (HICON)GetClassLongW( hwnd, GCL_HICON );
621 HINSTANCE instance = (HINSTANCE)GetWindowLongW( hwnd, GWL_HINSTANCE );
622 if (hIcon) return (LRESULT)hIcon;
623 for(len=1; len<64; len++)
624 if((hIcon = LoadIconW(instance, MAKEINTRESOURCEW(len))))
625 return (LRESULT)hIcon;
626 return (LRESULT)LoadIconW(0, (LPWSTR)IDI_APPLICATION);
630 case WM_ISACTIVEICON:
632 WND *wndPtr = WIN_GetPtr( hwnd );
633 BOOL ret = (wndPtr->flags & WIN_NCACTIVATED) != 0;
634 WIN_ReleasePtr( wndPtr );
638 case WM_NOTIFYFORMAT:
639 if (IsWindowUnicode(hwnd)) return NFR_UNICODE;
640 else return NFR_ANSI;
643 case WM_QUERYENDSESSION:
649 WND *wndPtr = WIN_GetPtr( hwnd );
654 ret = wndPtr->hIconSmall;
655 wndPtr->hIconSmall = (HICON)lParam;
659 wndPtr->hIcon = (HICON)lParam;
665 WIN_ReleasePtr( wndPtr );
667 if (USER_Driver.pSetWindowIcon)
668 USER_Driver.pSetWindowIcon( hwnd, wParam, (HICON)lParam );
670 SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE |
671 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
679 WND *wndPtr = WIN_GetPtr( hwnd );
684 ret = wndPtr->hIconSmall;
690 ret = wndPtr->hIconSmall;
691 if (!ret) ret = (HICON)GetClassLongA( hwnd, GCL_HICONSM );
692 /* FIXME: should have a default here if class icon is null */
698 WIN_ReleasePtr( wndPtr );
703 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
712 /***********************************************************************
713 * DefWindowProc (USER.107)
715 LRESULT WINAPI DefWindowProc16( HWND16 hwnd16, UINT16 msg, WPARAM16 wParam,
719 HWND hwnd = WIN_Handle32( hwnd16 );
721 if (!WIN_IsCurrentProcess( hwnd ))
723 if (!IsWindow( hwnd )) return 0;
724 ERR( "called for other process window %p\n", hwnd );
727 SPY_EnterMessage( SPY_DEFWNDPROC16, hwnd, msg, wParam, lParam );
733 CREATESTRUCT16 *cs = MapSL(lParam);
734 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
735 * may have child window IDs instead of window name */
736 if (HIWORD(cs->lpszName))
737 DEFWND_SetTextA( hwnd, MapSL(cs->lpszName) );
745 CONV_RECT16TO32( MapSL(lParam), &rect32 );
746 result = NC_HandleNCCalcSize( hwnd, &rect32 );
747 CONV_RECT32TO16( &rect32, MapSL(lParam) );
751 case WM_WINDOWPOSCHANGING:
752 result = WINPOS_HandleWindowPosChanging16( hwnd, MapSL(lParam) );
755 case WM_WINDOWPOSCHANGED:
757 WINDOWPOS16 * winPos = MapSL(lParam);
758 DEFWND_HandleWindowPosChanged( hwnd, winPos->flags );
764 result = DefWindowProcA( hwnd, msg, wParam, (LPARAM)MapSL(lParam) );
768 result = DefWindowProcA( hwnd, msg, wParam, lParam );
772 SPY_ExitMessage( SPY_RESULT_DEFWND16, hwnd, msg, result, wParam, lParam );
777 /***********************************************************************
778 * DefWindowProcA (USER32.@)
781 LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
786 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
788 if (!IsWindow( hwnd )) return 0;
789 ERR( "called for other process window %p\n", hwnd );
794 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
800 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
801 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
802 * may have child window IDs instead of window name */
803 if (HIWORD(cs->lpszName))
804 DEFWND_SetTextA( hwnd, cs->lpszName );
810 result = NC_HandleNCCalcSize( hwnd, (RECT *)lParam );
813 case WM_WINDOWPOSCHANGING:
814 result = WINPOS_HandleWindowPosChanging( hwnd, (WINDOWPOS *)lParam );
817 case WM_WINDOWPOSCHANGED:
819 WINDOWPOS * winPos = (WINDOWPOS *)lParam;
820 DEFWND_HandleWindowPosChanged( hwnd, winPos->flags );
824 case WM_GETTEXTLENGTH:
826 WND *wndPtr = WIN_GetPtr( hwnd );
827 if (wndPtr && wndPtr->text)
828 result = WideCharToMultiByte( CP_ACP, 0, wndPtr->text, strlenW(wndPtr->text),
829 NULL, 0, NULL, NULL );
830 WIN_ReleasePtr( wndPtr );
837 LPSTR dest = (LPSTR)lParam;
838 WND *wndPtr = WIN_GetPtr( hwnd );
843 if (!WideCharToMultiByte( CP_ACP, 0, wndPtr->text, -1,
844 dest, wParam, NULL, NULL )) dest[wParam-1] = 0;
845 result = strlen( dest );
848 WIN_ReleasePtr( wndPtr );
853 DEFWND_SetTextA( hwnd, (LPCSTR)lParam );
854 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
855 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
856 result = 1; /* success. FIXME: check text length */
859 /* for far east users (IMM32) - <hidenori@a2.ctktv.ne.jp> */
862 CHAR chChar1 = (CHAR)( (wParam>>8) & 0xff );
863 CHAR chChar2 = (CHAR)( wParam & 0xff );
866 SendMessageA( hwnd, WM_CHAR, (WPARAM)chChar1, lParam );
867 SendMessageA( hwnd, WM_CHAR, (WPARAM)chChar2, lParam );
871 result = SendMessageA( hwnd, WM_KEYDOWN, wParam, lParam );
874 result = SendMessageA( hwnd, WM_KEYUP, wParam, lParam );
877 case WM_IME_STARTCOMPOSITION:
878 case WM_IME_COMPOSITION:
879 case WM_IME_ENDCOMPOSITION:
884 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
886 result = SendMessageA( hwndIME, msg, wParam, lParam );
889 case WM_IME_SETCONTEXT:
893 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
895 result = DEFWND_ImmIsUIMessageA( hwndIME, msg, wParam, lParam );
899 case WM_INPUTLANGCHANGEREQUEST:
900 /* notify about the switch only if it's really our current layout */
901 if ((HKL)lParam == GetKeyboardLayout(0))
902 result = SendMessageA( hwnd, WM_INPUTLANGCHANGE, wParam, lParam );
909 BYTE ch = LOWORD(wParam);
911 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
912 wParam = MAKEWPARAM( wch, HIWORD(wParam) );
916 result = DEFWND_DefWinProc( hwnd, msg, wParam, lParam );
920 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
925 /***********************************************************************
926 * DefWindowProcW (USER32.@) Calls default window message handler
928 * Calls default window procedure for messages not processed
932 * Return value is dependent upon the message.
934 LRESULT WINAPI DefWindowProcW(
935 HWND hwnd, /* [in] window procedure receiving message */
936 UINT msg, /* [in] message identifier */
937 WPARAM wParam, /* [in] first message parameter */
938 LPARAM lParam ) /* [in] second message parameter */
943 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
945 if (!IsWindow( hwnd )) return 0;
946 ERR( "called for other process window %p\n", hwnd );
950 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
956 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
957 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
958 * may have child window IDs instead of window name */
959 if (HIWORD(cs->lpszName))
960 DEFWND_SetTextW( hwnd, cs->lpszName );
966 result = NC_HandleNCCalcSize( hwnd, (RECT *)lParam );
969 case WM_WINDOWPOSCHANGING:
970 result = WINPOS_HandleWindowPosChanging( hwnd, (WINDOWPOS *)lParam );
973 case WM_WINDOWPOSCHANGED:
975 WINDOWPOS * winPos = (WINDOWPOS *)lParam;
976 DEFWND_HandleWindowPosChanged( hwnd, winPos->flags );
980 case WM_GETTEXTLENGTH:
982 WND *wndPtr = WIN_GetPtr( hwnd );
983 if (wndPtr && wndPtr->text) result = (LRESULT)strlenW(wndPtr->text);
984 WIN_ReleasePtr( wndPtr );
991 LPWSTR dest = (LPWSTR)lParam;
992 WND *wndPtr = WIN_GetPtr( hwnd );
997 lstrcpynW( dest, wndPtr->text, wParam );
998 result = strlenW( dest );
1000 else dest[0] = '\0';
1001 WIN_ReleasePtr( wndPtr );
1006 DEFWND_SetTextW( hwnd, (LPCWSTR)lParam );
1007 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
1008 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
1009 result = 1; /* success. FIXME: check text length */
1012 /* for far east users (IMM32) - <hidenori@a2.ctktv.ne.jp> */
1014 SendMessageW( hwnd, WM_CHAR, wParam, lParam );
1016 case WM_IME_SETCONTEXT:
1020 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
1022 result = DEFWND_ImmIsUIMessageW( hwndIME, msg, wParam, lParam );
1026 case WM_INPUTLANGCHANGEREQUEST:
1027 /* notify about the switch only if it's really our current layout */
1028 if ((HKL)lParam == GetKeyboardLayout(0))
1029 result = SendMessageW( hwnd, WM_INPUTLANGCHANGE, wParam, lParam );
1035 result = DEFWND_DefWinProc( hwnd, msg, wParam, lParam );
1038 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );