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"
36 #include "nonclient.h"
40 #include "wine/unicode.h"
41 #include "wine/winuser16.h"
42 #include "wine/server.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(win
);
47 /* bits in the dwKeyData */
48 #define KEYDATA_ALT 0x2000
49 #define KEYDATA_PREVSTATE 0x4000
51 static short iF10Key
= 0;
52 static short iMenuSysKey
= 0;
53 static const WCHAR imm32W
[] = { 'i','m','m','3','2','\0' };
55 /***********************************************************************
56 * DEFWND_HandleWindowPosChanged
58 * Handle the WM_WINDOWPOSCHANGED message.
60 static void DEFWND_HandleWindowPosChanged( HWND hwnd
, UINT flags
)
63 WND
*wndPtr
= WIN_GetPtr( hwnd
);
65 rect
= wndPtr
->rectClient
;
66 WIN_ReleasePtr( wndPtr
);
68 if (!(flags
& SWP_NOCLIENTMOVE
))
69 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG(rect
.left
, rect
.top
));
71 if (!(flags
& SWP_NOCLIENTSIZE
))
73 WPARAM wp
= SIZE_RESTORED
;
74 if (IsZoomed(hwnd
)) wp
= SIZE_MAXIMIZED
;
75 else if (IsIconic(hwnd
)) wp
= SIZE_MINIMIZED
;
77 SendMessageW( hwnd
, WM_SIZE
, wp
, MAKELONG(rect
.right
-rect
.left
, rect
.bottom
-rect
.top
) );
82 /***********************************************************************
85 * Set the window text.
87 static void DEFWND_SetTextA( HWND hwnd
, LPCSTR text
)
94 count
= MultiByteToWideChar( CP_ACP
, 0, text
, -1, NULL
, 0 );
96 if (!(wndPtr
= WIN_GetPtr( hwnd
))) return;
97 if ((textW
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(WCHAR
))))
99 if (wndPtr
->text
) HeapFree(GetProcessHeap(), 0, wndPtr
->text
);
100 wndPtr
->text
= textW
;
101 MultiByteToWideChar( CP_ACP
, 0, text
, -1, textW
, count
);
102 SERVER_START_REQ( set_window_text
)
105 wine_server_add_data( req
, textW
, (count
-1) * sizeof(WCHAR
) );
106 wine_server_call( req
);
111 ERR("Not enough memory for window text\n");
112 WIN_ReleasePtr( wndPtr
);
114 if (USER_Driver
.pSetWindowText
) USER_Driver
.pSetWindowText( hwnd
, textW
);
117 /***********************************************************************
120 * Set the window text.
122 static void DEFWND_SetTextW( HWND hwnd
, LPCWSTR text
)
124 static const WCHAR empty_string
[] = {0};
128 if (!text
) text
= empty_string
;
129 count
= strlenW(text
) + 1;
131 if (!(wndPtr
= WIN_GetPtr( hwnd
))) return;
132 if (wndPtr
->text
) HeapFree(GetProcessHeap(), 0, wndPtr
->text
);
133 if ((wndPtr
->text
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(WCHAR
))))
135 strcpyW( wndPtr
->text
, text
);
136 SERVER_START_REQ( set_window_text
)
139 wine_server_add_data( req
, wndPtr
->text
, (count
-1) * sizeof(WCHAR
) );
140 wine_server_call( req
);
145 ERR("Not enough memory for window text\n");
147 WIN_ReleasePtr( wndPtr
);
149 if (USER_Driver
.pSetWindowText
) USER_Driver
.pSetWindowText( hwnd
, text
);
152 /***********************************************************************
153 * DEFWND_ControlColor
155 * Default colors for control painting.
157 HBRUSH
DEFWND_ControlColor( HDC hDC
, UINT ctlType
)
159 if( ctlType
== CTLCOLOR_SCROLLBAR
)
161 HBRUSH hb
= GetSysColorBrush(COLOR_SCROLLBAR
);
162 COLORREF bk
= GetSysColor(COLOR_3DHILIGHT
);
163 SetTextColor( hDC
, GetSysColor(COLOR_3DFACE
));
164 SetBkColor( hDC
, bk
);
166 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
167 * we better use 0x55aa bitmap brush to make scrollbar's background
168 * look different from the window background.
170 if (bk
== GetSysColor(COLOR_WINDOW
))
171 return UITOOLS_GetPattern55AABrush();
173 UnrealizeObject( hb
);
177 SetTextColor( hDC
, GetSysColor(COLOR_WINDOWTEXT
));
179 if ((ctlType
== CTLCOLOR_EDIT
) || (ctlType
== CTLCOLOR_LISTBOX
))
180 SetBkColor( hDC
, GetSysColor(COLOR_WINDOW
) );
182 SetBkColor( hDC
, GetSysColor(COLOR_3DFACE
) );
183 return GetSysColorBrush(COLOR_3DFACE
);
185 return GetSysColorBrush(COLOR_WINDOW
);
189 /***********************************************************************
192 static void DEFWND_SetRedraw( HWND hwnd
, WPARAM wParam
)
194 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
195 BOOL bVisible
= wndPtr
->dwStyle
& WS_VISIBLE
;
197 TRACE("%p %i\n", hwnd
, (wParam
!=0) );
203 WIN_SetStyle( hwnd
, wndPtr
->dwStyle
| WS_VISIBLE
);
204 DCE_InvalidateDCE( hwnd
, &wndPtr
->rectWindow
);
209 if( wndPtr
->dwStyle
& WS_MINIMIZE
) wParam
= RDW_VALIDATE
;
210 else wParam
= RDW_ALLCHILDREN
| RDW_VALIDATE
;
212 RedrawWindow( hwnd
, NULL
, 0, wParam
);
213 DCE_InvalidateDCE( hwnd
, &wndPtr
->rectWindow
);
214 WIN_SetStyle( hwnd
, wndPtr
->dwStyle
& ~WS_VISIBLE
);
216 WIN_ReleaseWndPtr( wndPtr
);
219 /***********************************************************************
222 * This method handles the default behavior for the WM_PRINT message.
224 static void DEFWND_Print( HWND hwnd
, HDC hdc
, ULONG uFlags
)
229 if ( (uFlags
& PRF_CHECKVISIBLE
) &&
230 !IsWindowVisible(hwnd
) )
234 * Unimplemented flags.
236 if ( (uFlags
& PRF_CHILDREN
) ||
237 (uFlags
& PRF_OWNED
) ||
238 (uFlags
& PRF_NONCLIENT
) )
240 WARN("WM_PRINT message with unsupported flags\n");
246 if ( uFlags
& PRF_ERASEBKGND
)
247 SendMessageW(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
252 if ( uFlags
& PRF_CLIENT
)
253 SendMessageW(hwnd
, WM_PRINTCLIENT
, (WPARAM
)hdc
, PRF_CLIENT
);
258 * helpers for calling IMM32
260 * WM_IME_* messages are generated only by IMM32,
261 * so I assume imm32 is already LoadLibrary-ed.
263 static HWND
DEFWND_ImmGetDefaultIMEWnd( HWND hwnd
)
265 HINSTANCE hInstIMM
= GetModuleHandleW( imm32W
);
266 HWND (WINAPI
*pFunc
)(HWND
);
271 ERR( "cannot get IMM32 handle\n" );
275 pFunc
= (void*)GetProcAddress(hInstIMM
,"ImmGetDefaultIMEWnd");
277 hwndRet
= (*pFunc
)( hwnd
);
282 static BOOL
DEFWND_ImmIsUIMessageA( HWND hwndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
284 HINSTANCE hInstIMM
= GetModuleHandleW( imm32W
);
285 BOOL (WINAPI
*pFunc
)(HWND
,UINT
,WPARAM
,LPARAM
);
290 ERR( "cannot get IMM32 handle\n" );
294 pFunc
= (void*)GetProcAddress(hInstIMM
,"ImmIsUIMessageA");
296 fRet
= (*pFunc
)( hwndIME
, msg
, wParam
, lParam
);
301 static BOOL
DEFWND_ImmIsUIMessageW( HWND hwndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
303 HINSTANCE hInstIMM
= GetModuleHandleW( imm32W
);
304 BOOL (WINAPI
*pFunc
)(HWND
,UINT
,WPARAM
,LPARAM
);
309 ERR( "cannot get IMM32 handle\n" );
313 pFunc
= (void*)GetProcAddress(hInstIMM
,"ImmIsUIMessageW");
315 fRet
= (*pFunc
)( hwndIME
, msg
, wParam
, lParam
);
322 /***********************************************************************
325 * Default window procedure for messages that are the same in Win16 and Win32.
327 static LRESULT
DEFWND_DefWinProc( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
332 return NC_HandleNCPaint( hwnd
, (HRGN
)wParam
);
337 pt
.x
= (short)LOWORD(lParam
);
338 pt
.y
= (short)HIWORD(lParam
);
339 return NC_HandleNCHitTest( hwnd
, pt
);
342 case WM_NCLBUTTONDOWN
:
343 return NC_HandleNCLButtonDown( hwnd
, wParam
, lParam
);
345 case WM_LBUTTONDBLCLK
:
346 case WM_NCLBUTTONDBLCLK
:
347 return NC_HandleNCLButtonDblClk( hwnd
, wParam
, lParam
);
349 case WM_NCRBUTTONDOWN
:
350 /* in Windows, capture is taken when right-clicking on the caption bar */
351 if (wParam
==HTCAPTION
)
361 if (hwnd
== GetCapture())
362 /* release capture if we took it on WM_NCRBUTTONDOWN */
365 pt
.x
= (short)LOWORD(lParam
);
366 pt
.y
= (short)HIWORD(lParam
);
367 ClientToScreen(hwnd
, &pt
);
368 SendMessageW( hwnd
, WM_CONTEXTMENU
, (WPARAM
)hwnd
, MAKELPARAM(pt
.x
, pt
.y
) );
374 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
375 * in Windows), but what _should_ we do? According to MSDN :
376 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
377 * message to the window". When is it appropriate?
382 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)
383 SendMessageW( GetParent(hwnd
), msg
, wParam
, lParam
);
388 WND
*wndPtr
= WIN_GetPtr( hwnd
);
389 HMENU hMenu
= wndPtr
->hSysMenu
;
390 WIN_ReleasePtr( wndPtr
);
391 if (!hMenu
) return 0;
392 pt
.x
= (short)LOWORD(lParam
);
393 pt
.y
= (short)HIWORD(lParam
);
394 hitcode
= NC_HandleNCHitTest(hwnd
, pt
);
396 /* Track system popup if click was in the caption area. */
397 if (hitcode
==HTCAPTION
|| hitcode
==HTSYSMENU
)
398 TrackPopupMenu(GetSystemMenu(hwnd
, FALSE
),
399 TPM_LEFTBUTTON
| TPM_RIGHTBUTTON
,
400 pt
.x
, pt
.y
, 0, hwnd
, NULL
);
405 return NC_HandleNCActivate( hwnd
, wParam
);
409 WND
*wndPtr
= WIN_GetPtr( hwnd
);
410 if (!wndPtr
) return 0;
411 if (wndPtr
->text
) HeapFree( GetProcessHeap(), 0, wndPtr
->text
);
413 if (wndPtr
->pVScroll
) HeapFree( GetProcessHeap(), 0, wndPtr
->pVScroll
);
414 if (wndPtr
->pHScroll
) HeapFree( GetProcessHeap(), 0, wndPtr
->pHScroll
);
415 wndPtr
->pVScroll
= wndPtr
->pHScroll
= NULL
;
416 WIN_ReleasePtr( wndPtr
);
421 DEFWND_Print(hwnd
, (HDC
)wParam
, lParam
);
428 HDC hdc
= BeginPaint( hwnd
, &ps
);
432 if (IsIconic(hwnd
) && ((hIcon
= (HICON
)GetClassLongW( hwnd
, GCL_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=(%ld,%ld - %ld,%ld)\n",
441 ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
442 DrawIcon( hdc
, x
, y
, hIcon
);
444 EndPaint( hwnd
, &ps
);
450 RedrawWindow ( hwnd
, NULL
, 0, RDW_ERASENOW
| RDW_ERASE
| RDW_ALLCHILDREN
);
454 DEFWND_SetRedraw( hwnd
, wParam
);
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 the NC_HandleNCLButtonDown() */
469 return (LOWORD(lParam
) >= HTCLIENT
) ? MA_ACTIVATE
: MA_NOACTIVATE
;
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
)GetClassLongW( hwnd
, GCL_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
&& !iMenuSysKey
)
549 if( wParam
== VK_F4
) /* try to close the window */
551 HWND top
= GetAncestor( hwnd
, GA_ROOT
);
552 if (!(GetClassLongW( top
, GCL_STYLE
) & CS_NOCLOSE
))
553 PostMessageW( top
, WM_SYSCOMMAND
, SC_CLOSE
, 0 );
556 else if( wParam
== VK_F10
)
558 else if( wParam
== VK_ESCAPE
&& (GetKeyState(VK_SHIFT
) & 0x8000))
559 SendMessageW( hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, ' ' );
564 /* Press and release F10 or ALT */
565 if (((wParam
== VK_MENU
) && iMenuSysKey
) ||
566 ((wParam
== VK_F10
) && iF10Key
))
567 SendMessageW( GetAncestor( hwnd
, GA_ROOT
), WM_SYSCOMMAND
, SC_KEYMENU
, 0L );
568 iMenuSysKey
= iF10Key
= 0;
574 if (wParam
== '\r' && IsIconic(hwnd
))
576 PostMessageW( hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0L );
579 if ((HIWORD(lParam
) & KEYDATA_ALT
) && wParam
)
581 if (wParam
== '\t' || wParam
== '\x1b') break;
582 if (wParam
== ' ' && (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
))
583 SendMessageW( GetParent(hwnd
), msg
, wParam
, lParam
);
585 SendMessageW( hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, wParam
);
587 else /* check for Ctrl-Esc */
588 if (wParam
!= '\x1b') MessageBeep(0);
594 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
595 if (!lParam
) return 0; /* sent from ShowWindow */
596 if (!(style
& WS_POPUP
)) return 0;
597 if ((style
& WS_VISIBLE
) && wParam
) return 0;
598 if (!(style
& WS_VISIBLE
) && !wParam
) return 0;
599 if (!GetWindow( hwnd
, GW_OWNER
)) return 0;
600 ShowWindow( hwnd
, wParam
? SW_SHOWNOACTIVATE
: SW_HIDE
);
605 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)) EndMenu();
606 if (GetCapture() == hwnd
) ReleaseCapture();
616 case WM_QUERYDROPOBJECT
:
617 return (GetWindowLongA( hwnd
, GWL_EXSTYLE
) & WS_EX_ACCEPTFILES
) != 0;
619 case WM_QUERYDRAGICON
:
623 HICON hIcon
= (HICON
)GetClassLongW( hwnd
, GCL_HICON
);
624 HINSTANCE instance
= (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
);
625 if (hIcon
) return (LRESULT
)hIcon
;
626 for(len
=1; len
<64; len
++)
627 if((hIcon
= LoadIconW(instance
, MAKEINTRESOURCEW(len
))))
628 return (LRESULT
)hIcon
;
629 return (LRESULT
)LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
633 case WM_ISACTIVEICON
:
635 WND
*wndPtr
= WIN_GetPtr( hwnd
);
636 BOOL ret
= (wndPtr
->flags
& WIN_NCACTIVATED
) != 0;
637 WIN_ReleasePtr( wndPtr
);
641 case WM_NOTIFYFORMAT
:
642 if (IsWindowUnicode(hwnd
)) return NFR_UNICODE
;
643 else return NFR_ANSI
;
646 case WM_QUERYENDSESSION
:
652 WND
*wndPtr
= WIN_GetPtr( hwnd
);
657 ret
= wndPtr
->hIconSmall
;
658 wndPtr
->hIconSmall
= (HICON
)lParam
;
662 wndPtr
->hIcon
= (HICON
)lParam
;
668 WIN_ReleasePtr( wndPtr
);
670 if (USER_Driver
.pSetWindowIcon
)
671 USER_Driver
.pSetWindowIcon( hwnd
, wParam
, (HICON
)lParam
);
673 SetWindowPos(hwnd
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOSIZE
|
674 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
682 WND
*wndPtr
= WIN_GetPtr( hwnd
);
687 ret
= wndPtr
->hIconSmall
;
693 ret
= wndPtr
->hIconSmall
;
694 if (!ret
) ret
= (HICON
)GetClassLongA( hwnd
, GCL_HICONSM
);
695 /* FIXME: should have a default here if class icon is null */
701 WIN_ReleasePtr( wndPtr
);
706 SendMessageW( GetParent(hwnd
), msg
, wParam
, lParam
);
715 /***********************************************************************
716 * DefWindowProc (USER.107)
718 LRESULT WINAPI
DefWindowProc16( HWND16 hwnd16
, UINT16 msg
, WPARAM16 wParam
,
722 HWND hwnd
= WIN_Handle32( hwnd16
);
724 if (!WIN_IsCurrentProcess( hwnd
))
726 if (!IsWindow( hwnd
)) return 0;
727 ERR( "called for other process window %p\n", hwnd
);
730 SPY_EnterMessage( SPY_DEFWNDPROC16
, hwnd
, msg
, wParam
, lParam
);
736 CREATESTRUCT16
*cs
= MapSL(lParam
);
737 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
738 * may have child window IDs instead of window name */
739 if (HIWORD(cs
->lpszName
))
740 DEFWND_SetTextA( hwnd
, MapSL(cs
->lpszName
) );
748 RECT16
*rect16
= MapSL(lParam
);
750 rect32
.left
= rect16
->left
;
751 rect32
.top
= rect16
->top
;
752 rect32
.right
= rect16
->right
;
753 rect32
.bottom
= rect16
->bottom
;
754 result
= NC_HandleNCCalcSize( hwnd
, &rect32
);
755 rect16
->left
= rect32
.left
;
756 rect16
->top
= rect32
.top
;
757 rect16
->right
= rect32
.right
;
758 rect16
->bottom
= rect32
.bottom
;
762 case WM_WINDOWPOSCHANGING
:
763 result
= WINPOS_HandleWindowPosChanging16( hwnd
, MapSL(lParam
) );
766 case WM_WINDOWPOSCHANGED
:
768 WINDOWPOS16
* winPos
= MapSL(lParam
);
769 DEFWND_HandleWindowPosChanged( hwnd
, winPos
->flags
);
775 result
= DefWindowProcA( hwnd
, msg
, wParam
, (LPARAM
)MapSL(lParam
) );
779 result
= DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
783 SPY_ExitMessage( SPY_RESULT_DEFWND16
, hwnd
, msg
, result
, wParam
, lParam
);
788 /***********************************************************************
789 * DefWindowProcA (USER32.@)
792 LRESULT WINAPI
DefWindowProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
797 if (!(full_handle
= WIN_IsCurrentProcess( hwnd
)))
799 if (!IsWindow( hwnd
)) return 0;
800 ERR( "called for other process window %p\n", hwnd
);
805 SPY_EnterMessage( SPY_DEFWNDPROC
, hwnd
, msg
, wParam
, lParam
);
811 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
812 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
813 * may have child window IDs instead of window name */
814 if (HIWORD(cs
->lpszName
))
815 DEFWND_SetTextA( hwnd
, cs
->lpszName
);
821 result
= NC_HandleNCCalcSize( hwnd
, (RECT
*)lParam
);
824 case WM_WINDOWPOSCHANGING
:
825 result
= WINPOS_HandleWindowPosChanging( hwnd
, (WINDOWPOS
*)lParam
);
828 case WM_WINDOWPOSCHANGED
:
830 WINDOWPOS
* winPos
= (WINDOWPOS
*)lParam
;
831 DEFWND_HandleWindowPosChanged( hwnd
, winPos
->flags
);
835 case WM_GETTEXTLENGTH
:
837 WND
*wndPtr
= WIN_GetPtr( hwnd
);
838 if (wndPtr
&& wndPtr
->text
)
839 result
= WideCharToMultiByte( CP_ACP
, 0, wndPtr
->text
, strlenW(wndPtr
->text
),
840 NULL
, 0, NULL
, NULL
);
841 WIN_ReleasePtr( wndPtr
);
848 LPSTR dest
= (LPSTR
)lParam
;
849 WND
*wndPtr
= WIN_GetPtr( hwnd
);
854 if (!WideCharToMultiByte( CP_ACP
, 0, wndPtr
->text
, -1,
855 dest
, wParam
, NULL
, NULL
)) dest
[wParam
-1] = 0;
856 result
= strlen( dest
);
859 WIN_ReleasePtr( wndPtr
);
864 DEFWND_SetTextA( hwnd
, (LPCSTR
)lParam
);
865 if( (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
866 NC_HandleNCPaint( hwnd
, (HRGN
)1 ); /* Repaint caption */
867 result
= 1; /* success. FIXME: check text length */
870 /* for far east users (IMM32) - <hidenori@a2.ctktv.ne.jp> */
873 CHAR chChar1
= (CHAR
)( (wParam
>>8) & 0xff );
874 CHAR chChar2
= (CHAR
)( wParam
& 0xff );
877 SendMessageA( hwnd
, WM_CHAR
, (WPARAM
)chChar1
, lParam
);
878 SendMessageA( hwnd
, WM_CHAR
, (WPARAM
)chChar2
, lParam
);
882 result
= SendMessageA( hwnd
, WM_KEYDOWN
, wParam
, lParam
);
885 result
= SendMessageA( hwnd
, WM_KEYUP
, wParam
, lParam
);
888 case WM_IME_STARTCOMPOSITION
:
889 case WM_IME_COMPOSITION
:
890 case WM_IME_ENDCOMPOSITION
:
895 hwndIME
= DEFWND_ImmGetDefaultIMEWnd( hwnd
);
897 result
= SendMessageA( hwndIME
, msg
, wParam
, lParam
);
900 case WM_IME_SETCONTEXT
:
904 hwndIME
= DEFWND_ImmGetDefaultIMEWnd( hwnd
);
906 result
= DEFWND_ImmIsUIMessageA( hwndIME
, msg
, wParam
, lParam
);
910 case WM_INPUTLANGCHANGEREQUEST
:
911 /* notify about the switch only if it's really our current layout */
912 if ((HKL
)lParam
== GetKeyboardLayout(0))
913 result
= SendMessageA( hwnd
, WM_INPUTLANGCHANGE
, wParam
, lParam
);
920 BYTE ch
= LOWORD(wParam
);
922 MultiByteToWideChar(CP_ACP
, 0, &ch
, 1, &wch
, 1);
923 wParam
= MAKEWPARAM( wch
, HIWORD(wParam
) );
927 result
= DEFWND_DefWinProc( hwnd
, msg
, wParam
, lParam
);
931 SPY_ExitMessage( SPY_RESULT_DEFWND
, hwnd
, msg
, result
, wParam
, lParam
);
936 /***********************************************************************
937 * DefWindowProcW (USER32.@) Calls default window message handler
939 * Calls default window procedure for messages not processed
943 * Return value is dependent upon the message.
945 LRESULT WINAPI
DefWindowProcW(
946 HWND hwnd
, /* [in] window procedure receiving message */
947 UINT msg
, /* [in] message identifier */
948 WPARAM wParam
, /* [in] first message parameter */
949 LPARAM lParam
) /* [in] second message parameter */
954 if (!(full_handle
= WIN_IsCurrentProcess( hwnd
)))
956 if (!IsWindow( hwnd
)) return 0;
957 ERR( "called for other process window %p\n", hwnd
);
961 SPY_EnterMessage( SPY_DEFWNDPROC
, hwnd
, msg
, wParam
, lParam
);
967 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lParam
;
968 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
969 * may have child window IDs instead of window name */
970 if (HIWORD(cs
->lpszName
))
971 DEFWND_SetTextW( hwnd
, cs
->lpszName
);
977 result
= NC_HandleNCCalcSize( hwnd
, (RECT
*)lParam
);
980 case WM_WINDOWPOSCHANGING
:
981 result
= WINPOS_HandleWindowPosChanging( hwnd
, (WINDOWPOS
*)lParam
);
984 case WM_WINDOWPOSCHANGED
:
986 WINDOWPOS
* winPos
= (WINDOWPOS
*)lParam
;
987 DEFWND_HandleWindowPosChanged( hwnd
, winPos
->flags
);
991 case WM_GETTEXTLENGTH
:
993 WND
*wndPtr
= WIN_GetPtr( hwnd
);
994 if (wndPtr
&& wndPtr
->text
) result
= (LRESULT
)strlenW(wndPtr
->text
);
995 WIN_ReleasePtr( wndPtr
);
1002 LPWSTR dest
= (LPWSTR
)lParam
;
1003 WND
*wndPtr
= WIN_GetPtr( hwnd
);
1008 lstrcpynW( dest
, wndPtr
->text
, wParam
);
1009 result
= strlenW( dest
);
1011 else dest
[0] = '\0';
1012 WIN_ReleasePtr( wndPtr
);
1017 DEFWND_SetTextW( hwnd
, (LPCWSTR
)lParam
);
1018 if( (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1019 NC_HandleNCPaint( hwnd
, (HRGN
)1 ); /* Repaint caption */
1020 result
= 1; /* success. FIXME: check text length */
1023 /* for far east users (IMM32) - <hidenori@a2.ctktv.ne.jp> */
1025 SendMessageW( hwnd
, WM_CHAR
, wParam
, lParam
);
1027 case WM_IME_SETCONTEXT
:
1031 hwndIME
= DEFWND_ImmGetDefaultIMEWnd( hwnd
);
1033 result
= DEFWND_ImmIsUIMessageW( hwndIME
, msg
, wParam
, lParam
);
1037 case WM_INPUTLANGCHANGEREQUEST
:
1038 /* notify about the switch only if it's really our current layout */
1039 if ((HKL
)lParam
== GetKeyboardLayout(0))
1040 result
= SendMessageW( hwnd
, WM_INPUTLANGCHANGE
, wParam
, lParam
);
1046 result
= DEFWND_DefWinProc( hwnd
, msg
, wParam
, lParam
);
1049 SPY_ExitMessage( SPY_RESULT_DEFWND
, hwnd
, msg
, result
, wParam
, lParam
);