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
31 #include "user_private.h"
33 #include "wine/server.h"
34 #include "wine/exception.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(win
);
39 /* bits in the dwKeyData */
40 #define KEYDATA_ALT 0x2000
41 #define KEYDATA_PREVSTATE 0x4000
43 #define DRAG_FILE 0x454C4946
45 static short iF10Key
= 0;
46 static short iMenuSysKey
= 0;
48 /***********************************************************************
49 * DEFWND_HandleWindowPosChanged
51 * Handle the WM_WINDOWPOSCHANGED message.
53 static void DEFWND_HandleWindowPosChanged( HWND hwnd
, const WINDOWPOS
*winpos
)
57 WIN_GetRectangles( hwnd
, COORDS_PARENT
, NULL
, &rect
);
58 if (!(winpos
->flags
& SWP_NOCLIENTMOVE
))
59 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG(rect
.left
, rect
.top
));
61 if (!(winpos
->flags
& SWP_NOCLIENTSIZE
) || (winpos
->flags
& SWP_STATECHANGED
))
65 SendMessageW( hwnd
, WM_SIZE
, SIZE_MINIMIZED
, 0 );
69 WPARAM wp
= IsZoomed( hwnd
) ? SIZE_MAXIMIZED
: SIZE_RESTORED
;
71 SendMessageW( hwnd
, WM_SIZE
, wp
, MAKELONG(rect
.right
-rect
.left
, rect
.bottom
-rect
.top
) );
77 /***********************************************************************
80 * Set the window text.
82 static LRESULT
DEFWND_SetTextA( HWND hwnd
, LPCSTR text
)
88 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
89 * may have child window IDs instead of window name */
90 if (text
&& IS_INTRESOURCE(text
))
94 count
= MultiByteToWideChar( CP_ACP
, 0, text
, -1, NULL
, 0 );
96 if (!(wndPtr
= WIN_GetPtr( hwnd
))) return 0;
97 if ((textW
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(WCHAR
))))
99 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
)
104 req
->handle
= wine_server_user_handle( hwnd
);
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 USER_Driver
->pSetWindowText( hwnd
, textW
);
119 /***********************************************************************
122 * Set the window text.
124 static LRESULT
DEFWND_SetTextW( HWND hwnd
, LPCWSTR text
)
129 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
130 * may have child window IDs instead of window name */
131 if (text
&& IS_INTRESOURCE(text
))
134 if (!text
) text
= L
"";
135 count
= lstrlenW(text
) + 1;
137 if (!(wndPtr
= WIN_GetPtr( hwnd
))) return 0;
138 HeapFree(GetProcessHeap(), 0, wndPtr
->text
);
139 if ((wndPtr
->text
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(WCHAR
))))
141 lstrcpyW( wndPtr
->text
, text
);
142 SERVER_START_REQ( set_window_text
)
144 req
->handle
= wine_server_user_handle( hwnd
);
145 wine_server_add_data( req
, wndPtr
->text
, (count
-1) * sizeof(WCHAR
) );
146 wine_server_call( req
);
151 ERR("Not enough memory for window text\n");
153 WIN_ReleasePtr( wndPtr
);
155 USER_Driver
->pSetWindowText( hwnd
, text
);
160 /***********************************************************************
161 * DEFWND_ControlColor
163 * Default colors for control painting.
165 HBRUSH
DEFWND_ControlColor( HDC hDC
, UINT ctlType
)
167 if( ctlType
== CTLCOLOR_SCROLLBAR
)
169 HBRUSH hb
= GetSysColorBrush(COLOR_SCROLLBAR
);
170 COLORREF bk
= GetSysColor(COLOR_3DHILIGHT
);
171 SetTextColor( hDC
, GetSysColor(COLOR_3DFACE
));
172 SetBkColor( hDC
, bk
);
174 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
175 * we better use 0x55aa bitmap brush to make scrollbar's background
176 * look different from the window background.
178 if (bk
== GetSysColor(COLOR_WINDOW
))
179 return SYSCOLOR_Get55AABrush();
181 UnrealizeObject( hb
);
185 SetTextColor( hDC
, GetSysColor(COLOR_WINDOWTEXT
));
187 if ((ctlType
== CTLCOLOR_EDIT
) || (ctlType
== CTLCOLOR_LISTBOX
))
188 SetBkColor( hDC
, GetSysColor(COLOR_WINDOW
) );
190 SetBkColor( hDC
, GetSysColor(COLOR_3DFACE
) );
191 return GetSysColorBrush(COLOR_3DFACE
);
193 return GetSysColorBrush(COLOR_WINDOW
);
197 /***********************************************************************
200 * This method handles the default behavior for the WM_PRINT message.
202 static void DEFWND_Print( HWND hwnd
, HDC hdc
, ULONG uFlags
)
207 if ( (uFlags
& PRF_CHECKVISIBLE
) &&
208 !IsWindowVisible(hwnd
) )
212 * Unimplemented flags.
214 if ( (uFlags
& PRF_CHILDREN
) ||
215 (uFlags
& PRF_OWNED
) ||
216 (uFlags
& PRF_NONCLIENT
) )
218 WARN("WM_PRINT message with unsupported flags\n");
224 if ( uFlags
& PRF_ERASEBKGND
)
225 SendMessageW(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
230 if ( uFlags
& PRF_CLIENT
)
231 SendMessageW(hwnd
, WM_PRINTCLIENT
, (WPARAM
)hdc
, uFlags
);
236 /***********************************************************************
239 * Default window procedure for messages that are the same in Ansi and Unicode.
241 static LRESULT
DEFWND_DefWinProc( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
246 return NC_HandleNCPaint( hwnd
, (HRGN
)wParam
);
249 return NC_HandleNCMouseMove( hwnd
, wParam
, lParam
);
251 case WM_NCMOUSELEAVE
:
252 return NC_HandleNCMouseLeave( hwnd
);
257 pt
.x
= (short)LOWORD(lParam
);
258 pt
.y
= (short)HIWORD(lParam
);
259 return NC_HandleNCHitTest( hwnd
, pt
);
263 return NC_HandleNCCalcSize( hwnd
, wParam
, (RECT
*)lParam
);
265 case WM_WINDOWPOSCHANGING
:
266 return WINPOS_HandleWindowPosChanging( hwnd
, (WINDOWPOS
*)lParam
);
268 case WM_WINDOWPOSCHANGED
:
269 DEFWND_HandleWindowPosChanged( hwnd
, (const WINDOWPOS
*)lParam
);
275 iF10Key
= iMenuSysKey
= 0;
278 case WM_NCLBUTTONDOWN
:
279 return NC_HandleNCLButtonDown( hwnd
, wParam
, lParam
);
281 case WM_LBUTTONDBLCLK
:
282 return NC_HandleNCLButtonDblClk( hwnd
, HTCLIENT
, lParam
);
284 case WM_NCLBUTTONDBLCLK
:
285 return NC_HandleNCLButtonDblClk( hwnd
, wParam
, lParam
);
287 case WM_NCRBUTTONDOWN
:
288 return NC_HandleNCRButtonDown( hwnd
, wParam
, lParam
);
293 pt
.x
= (short)LOWORD(lParam
);
294 pt
.y
= (short)HIWORD(lParam
);
295 ClientToScreen(hwnd
, &pt
);
296 SendMessageW( hwnd
, WM_CONTEXTMENU
, (WPARAM
)hwnd
, MAKELPARAM(pt
.x
, pt
.y
) );
302 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
303 * in Windows), but what _should_ we do? According to MSDN :
304 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
305 * message to the window". When is it appropriate?
311 if (HIWORD(wParam
) == XBUTTON1
|| HIWORD(wParam
) == XBUTTON2
)
313 SendMessageW(hwnd
, WM_APPCOMMAND
, (WPARAM
)hwnd
,
314 MAKELPARAM(LOWORD(wParam
), FAPPCOMMAND_MOUSE
| HIWORD(wParam
)));
319 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)
320 SendMessageW( GetParent(hwnd
), msg
, (WPARAM
)hwnd
, lParam
);
325 pt
.x
= (short)LOWORD(lParam
);
326 pt
.y
= (short)HIWORD(lParam
);
327 hitcode
= NC_HandleNCHitTest(hwnd
, pt
);
329 /* Track system popup if click was in the caption area. */
330 if (hitcode
==HTCAPTION
|| hitcode
==HTSYSMENU
)
331 TrackPopupMenu(GetSystemMenu(hwnd
, FALSE
),
332 TPM_LEFTBUTTON
| TPM_RIGHTBUTTON
,
333 pt
.x
, pt
.y
, 0, hwnd
, NULL
);
337 case WM_POPUPSYSTEMMENU
:
338 /* This is an undocumented message used by the windows taskbar to
339 display the system menu of windows that belong to other processes. */
340 TrackPopupMenu( GetSystemMenu(hwnd
, FALSE
), TPM_LEFTBUTTON
|TPM_RIGHTBUTTON
,
341 (short)LOWORD(lParam
), (short)HIWORD(lParam
), 0, hwnd
, NULL
);
345 return NC_HandleNCActivate( hwnd
, wParam
, lParam
);
349 WND
*wndPtr
= WIN_GetPtr( hwnd
);
350 if (!wndPtr
) return 0;
351 HeapFree( GetProcessHeap(), 0, wndPtr
->text
);
353 HeapFree( GetProcessHeap(), 0, wndPtr
->pScroll
);
354 wndPtr
->pScroll
= NULL
;
355 WIN_ReleasePtr( wndPtr
);
360 DEFWND_Print(hwnd
, (HDC
)wParam
, lParam
);
367 HDC hdc
= BeginPaint( hwnd
, &ps
);
371 if (IsIconic(hwnd
) && ((hIcon
= (HICON
)GetClassLongPtrW( hwnd
, GCLP_HICON
))) )
376 GetClientRect( hwnd
, &rc
);
377 x
= (rc
.right
- rc
.left
- GetSystemMetrics(SM_CXICON
))/2;
378 y
= (rc
.bottom
- rc
.top
- GetSystemMetrics(SM_CYICON
))/2;
379 TRACE("Painting class icon: vis rect=(%s)\n",
380 wine_dbgstr_rect(&ps
.rcPaint
));
381 DrawIcon( hdc
, x
, y
, hIcon
);
383 EndPaint( hwnd
, &ps
);
389 RedrawWindow ( hwnd
, NULL
, 0, RDW_ERASENOW
| RDW_ERASE
| RDW_ALLCHILDREN
);
393 if (wParam
) WIN_SetStyle( hwnd
, WS_VISIBLE
, 0 );
396 RedrawWindow( hwnd
, NULL
, 0, RDW_ALLCHILDREN
| RDW_VALIDATE
);
397 WIN_SetStyle( hwnd
, 0, WS_VISIBLE
);
402 DestroyWindow( hwnd
);
405 case WM_MOUSEACTIVATE
:
406 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)
408 LONG ret
= SendMessageW( GetParent(hwnd
), WM_MOUSEACTIVATE
, wParam
, lParam
);
412 /* Caption clicks are handled by NC_HandleNCLButtonDown() */
413 return ( HIWORD(lParam
) == WM_LBUTTONDOWN
&& LOWORD(lParam
) == HTCAPTION
? MA_NOACTIVATE
: MA_ACTIVATE
);
416 /* The default action in Windows is to set the keyboard focus to
417 * the window, if it's being activated and not minimized */
418 if (LOWORD(wParam
) != WA_INACTIVE
) {
419 if (!IsIconic(hwnd
)) SetFocus(hwnd
);
424 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)
425 return SendMessageW( GetParent(hwnd
), WM_MOUSEWHEEL
, wParam
, lParam
);
429 case WM_ICONERASEBKGND
:
432 HDC hdc
= (HDC
)wParam
;
433 HBRUSH hbr
= (HBRUSH
)GetClassLongPtrW( hwnd
, GCLP_HBRBACKGROUND
);
436 if (GetClassLongW( hwnd
, GCL_STYLE
) & CS_PARENTDC
)
438 /* can't use GetClipBox with a parent DC or we fill the whole parent */
439 GetClientRect( hwnd
, &rect
);
440 DPtoLP( hdc
, (LPPOINT
)&rect
, 2 );
442 else GetClipBox( hdc
, &rect
);
443 FillRect( hdc
, &rect
, hbr
);
450 case WM_CTLCOLORMSGBOX
:
451 case WM_CTLCOLOREDIT
:
452 case WM_CTLCOLORLISTBOX
:
455 case WM_CTLCOLORSTATIC
:
456 case WM_CTLCOLORSCROLLBAR
:
457 return (LRESULT
)DEFWND_ControlColor( (HDC
)wParam
, msg
- WM_CTLCOLORMSGBOX
);
460 return (LRESULT
)DEFWND_ControlColor( (HDC
)wParam
, HIWORD(lParam
) );
463 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)
465 /* with the exception of the border around a resizable wnd,
466 * give the parent first chance to set the cursor */
467 if ((LOWORD(lParam
) < HTSIZEFIRST
) || (LOWORD(lParam
) > HTSIZELAST
))
469 HWND parent
= GetParent( hwnd
);
470 if (parent
!= GetDesktopWindow() &&
471 SendMessageW( parent
, WM_SETCURSOR
, wParam
, lParam
)) return TRUE
;
474 NC_HandleSetCursor( hwnd
, wParam
, lParam
);
478 return NC_HandleSysCommand( hwnd
, wParam
, lParam
);
481 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
485 if( HIWORD(lParam
) & KEYDATA_ALT
)
487 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
488 if ( (wParam
== VK_MENU
|| wParam
== VK_LMENU
489 || wParam
== VK_RMENU
) && !iMenuSysKey
)
496 if( wParam
== VK_F4
) /* try to close the window */
498 HWND top
= GetAncestor( hwnd
, GA_ROOT
);
499 if (!(GetClassLongW( top
, GCL_STYLE
) & CS_NOCLOSE
))
500 PostMessageW( top
, WM_SYSCOMMAND
, SC_CLOSE
, 0 );
503 else if( wParam
== VK_F10
)
505 if (NtUserGetKeyState(VK_SHIFT
) & 0x8000)
506 SendMessageW( hwnd
, WM_CONTEXTMENU
, (WPARAM
)hwnd
, -1 );
509 else if (wParam
== VK_ESCAPE
&& (NtUserGetKeyState(VK_SHIFT
) & 0x8000))
510 SendMessageW( hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, ' ' );
515 /* Press and release F10 or ALT */
516 if (((wParam
== VK_MENU
|| wParam
== VK_LMENU
|| wParam
== VK_RMENU
)
517 && iMenuSysKey
) || ((wParam
== VK_F10
) && iF10Key
))
518 SendMessageW( GetAncestor( hwnd
, GA_ROOT
), WM_SYSCOMMAND
, SC_KEYMENU
, 0L );
519 iMenuSysKey
= iF10Key
= 0;
525 if (wParam
== '\r' && IsIconic(hwnd
))
527 PostMessageW( hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0L );
530 if ((HIWORD(lParam
) & KEYDATA_ALT
) && wParam
)
532 if (wParam
== '\t' || wParam
== '\x1b') break;
533 if (wParam
== ' ' && (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
))
534 SendMessageW( GetParent(hwnd
), msg
, wParam
, lParam
);
536 SendMessageW( hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, wParam
);
538 else /* check for Ctrl-Esc */
539 if (wParam
!= '\x1b') MessageBeep(0);
545 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
547 if (!lParam
) return 0; /* sent from ShowWindow */
548 if ((style
& WS_VISIBLE
) && wParam
) return 0;
549 if (!(style
& WS_VISIBLE
) && !wParam
) return 0;
550 if (!GetWindow( hwnd
, GW_OWNER
)) return 0;
551 if (!(pWnd
= WIN_GetPtr( hwnd
))) return 0;
552 if (pWnd
== WND_OTHER_PROCESS
) return 0;
555 if (!(pWnd
->flags
& WIN_NEEDS_SHOW_OWNEDPOPUP
))
557 WIN_ReleasePtr( pWnd
);
560 pWnd
->flags
&= ~WIN_NEEDS_SHOW_OWNEDPOPUP
;
562 else pWnd
->flags
|= WIN_NEEDS_SHOW_OWNEDPOPUP
;
563 WIN_ReleasePtr( pWnd
);
564 ShowWindow( hwnd
, wParam
? SW_SHOWNOACTIVATE
: SW_HIDE
);
570 MENU_EndMenu( hwnd
);
571 if (GetCapture() == hwnd
) ReleaseCapture();
581 case WM_QUERYDROPOBJECT
:
582 return (GetWindowLongA( hwnd
, GWL_EXSTYLE
) & WS_EX_ACCEPTFILES
) != 0;
584 case WM_QUERYDRAGICON
:
588 HICON hIcon
= (HICON
)GetClassLongPtrW( hwnd
, GCLP_HICON
);
589 HINSTANCE instance
= (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
);
590 if (hIcon
) return (LRESULT
)hIcon
;
591 for(len
=1; len
<64; len
++)
592 if((hIcon
= LoadIconW(instance
, MAKEINTRESOURCEW(len
))))
593 return (LRESULT
)hIcon
;
594 return (LRESULT
)LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
598 case WM_ISACTIVEICON
:
599 return (win_get_flags( hwnd
) & WIN_NCACTIVATED
) != 0;
601 case WM_NOTIFYFORMAT
:
602 if (IsWindowUnicode(hwnd
)) return NFR_UNICODE
;
603 else return NFR_ANSI
;
606 case WM_QUERYENDSESSION
:
612 WND
*wndPtr
= WIN_GetPtr( hwnd
);
617 ret
= wndPtr
->hIconSmall
;
618 if (ret
&& !lParam
&& wndPtr
->hIcon
)
620 wndPtr
->hIconSmall2
= CopyImage( wndPtr
->hIcon
, IMAGE_ICON
,
621 GetSystemMetrics( SM_CXSMICON
),
622 GetSystemMetrics( SM_CYSMICON
), 0 );
624 else if (lParam
&& wndPtr
->hIconSmall2
)
626 DestroyIcon( wndPtr
->hIconSmall2
);
627 wndPtr
->hIconSmall2
= NULL
;
629 wndPtr
->hIconSmall
= (HICON
)lParam
;
633 if (wndPtr
->hIconSmall2
)
635 DestroyIcon( wndPtr
->hIconSmall2
);
636 wndPtr
->hIconSmall2
= NULL
;
638 if (lParam
&& !wndPtr
->hIconSmall
)
640 wndPtr
->hIconSmall2
= CopyImage( (HICON
)lParam
, IMAGE_ICON
,
641 GetSystemMetrics( SM_CXSMICON
),
642 GetSystemMetrics( SM_CYSMICON
), 0 );
644 wndPtr
->hIcon
= (HICON
)lParam
;
650 WIN_ReleasePtr( wndPtr
);
652 USER_Driver
->pSetWindowIcon( hwnd
, wParam
, (HICON
)lParam
);
654 if( (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
655 NC_HandleNCPaint( hwnd
, (HRGN
)1 ); /* Repaint caption */
663 WND
*wndPtr
= WIN_GetPtr( hwnd
);
668 ret
= wndPtr
->hIconSmall
;
674 ret
= wndPtr
->hIconSmall
? wndPtr
->hIconSmall
: wndPtr
->hIconSmall2
;
680 WIN_ReleasePtr( wndPtr
);
685 SendMessageW( GetParent(hwnd
), msg
, wParam
, lParam
);
688 case WM_STYLECHANGED
:
689 if (wParam
== GWL_STYLE
&& (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_LAYERED
))
691 STYLESTRUCT
*style
= (STYLESTRUCT
*)lParam
;
692 if ((style
->styleOld
^ style
->styleNew
) & (WS_CAPTION
|WS_THICKFRAME
|WS_VSCROLL
|WS_HSCROLL
))
693 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
| SWP_NOZORDER
|
694 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOCLIENTSIZE
| SWP_NOCLIENTMOVE
);
700 HWND parent
= GetParent(hwnd
);
702 HOOK_CallHooks(WH_SHELL
, HSHELL_APPCOMMAND
, wParam
, lParam
, TRUE
);
704 SendMessageW( parent
, msg
, wParam
, lParam
);
711 hi
.cbSize
= sizeof(HELPINFO
);
712 GetCursorPos( &hi
.MousePos
);
713 if (MENU_IsMenuActive())
715 hi
.iContextType
= HELPINFO_MENUITEM
;
716 hi
.hItemHandle
= MENU_IsMenuActive();
717 hi
.iCtrlId
= MenuItemFromPoint( hwnd
, hi
.hItemHandle
, hi
.MousePos
);
718 hi
.dwContextId
= GetMenuContextHelpId( hi
.hItemHandle
);
722 hi
.iContextType
= HELPINFO_WINDOW
;
723 hi
.hItemHandle
= hwnd
;
724 hi
.iCtrlId
= GetWindowLongPtrA( hwnd
, GWLP_ID
);
725 hi
.dwContextId
= GetWindowContextHelpId( hwnd
);
727 SendMessageW( hwnd
, WM_HELP
, 0, (LPARAM
)&hi
);
731 case WM_INPUTLANGCHANGEREQUEST
:
732 NtUserActivateKeyboardLayout( (HKL
)lParam
, 0 );
735 case WM_INPUTLANGCHANGE
:
737 struct user_thread_info
*info
= get_user_thread_info();
739 HWND
*win_array
= WIN_ListChildren( hwnd
);
740 info
->kbd_layout
= (HKL
)lParam
;
744 while (win_array
[count
])
745 SendMessageW( win_array
[count
++], WM_INPUTLANGCHANGE
, wParam
, lParam
);
746 HeapFree(GetProcessHeap(),0,win_array
);
755 static LPARAM
DEFWND_GetTextA( WND
*wndPtr
, LPSTR dest
, WPARAM wParam
)
763 if (!WideCharToMultiByte( CP_ACP
, 0, wndPtr
->text
, -1,
764 dest
, wParam
, NULL
, NULL
)) dest
[wParam
-1] = 0;
765 result
= strlen( dest
);
777 /***********************************************************************
778 * DefWindowProcA (USER32.@)
780 * See DefWindowProcW.
782 LRESULT WINAPI
DefWindowProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
787 if (!(full_handle
= WIN_IsCurrentProcess( hwnd
)))
789 if (!IsWindow( hwnd
)) return 0;
790 ERR( "called for other process window %p\n", hwnd
);
795 SPY_EnterMessage( SPY_DEFWNDPROC
, hwnd
, msg
, wParam
, lParam
);
802 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
804 DEFWND_SetTextA( hwnd
, cs
->lpszName
);
807 if(cs
->style
& (WS_HSCROLL
| WS_VSCROLL
))
809 SCROLLINFO si
= {sizeof si
, SIF_ALL
, 0, 100, 0, 0, 0};
810 SetScrollInfo( hwnd
, SB_HORZ
, &si
, FALSE
);
811 SetScrollInfo( hwnd
, SB_VERT
, &si
, FALSE
);
816 case WM_GETTEXTLENGTH
:
818 WND
*wndPtr
= WIN_GetPtr( hwnd
);
819 if (wndPtr
&& wndPtr
->text
)
820 result
= WideCharToMultiByte( CP_ACP
, 0, wndPtr
->text
, lstrlenW(wndPtr
->text
),
821 NULL
, 0, NULL
, NULL
);
822 WIN_ReleasePtr( wndPtr
);
829 LPSTR dest
= (LPSTR
)lParam
;
830 WND
*wndPtr
= WIN_GetPtr( hwnd
);
833 result
= DEFWND_GetTextA( wndPtr
, dest
, wParam
);
835 WIN_ReleasePtr( wndPtr
);
840 if (!DEFWND_SetTextA( hwnd
, (LPCSTR
)lParam
))
842 if( (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
843 NC_HandleNCPaint( hwnd
, (HRGN
)1 ); /* Repaint caption */
844 result
= 1; /* success. FIXME: check text length */
848 if (HIBYTE(wParam
)) PostMessageA( hwnd
, WM_CHAR
, HIBYTE(wParam
), lParam
);
849 PostMessageA( hwnd
, WM_CHAR
, LOBYTE(wParam
), lParam
);
853 result
= PostMessageA( hwnd
, WM_KEYDOWN
, wParam
, lParam
);
857 result
= PostMessageA( hwnd
, WM_KEYUP
, wParam
, lParam
);
860 case WM_IME_COMPOSITION
:
861 if (lParam
& GCS_RESULTSTR
)
864 unsigned char lead
= 0;
866 HIMC himc
= ImmGetContext( hwnd
);
870 if ((size
= ImmGetCompositionStringA( himc
, GCS_RESULTSTR
, NULL
, 0 )))
872 if (!(buf
= HeapAlloc( GetProcessHeap(), 0, size
))) size
= 0;
873 else size
= ImmGetCompositionStringA( himc
, GCS_RESULTSTR
, buf
, size
);
875 ImmReleaseContext( hwnd
, himc
);
877 for (i
= 0; i
< size
; i
++)
879 unsigned char c
= buf
[i
];
882 if (IsDBCSLeadByte( c
))
885 SendMessageA( hwnd
, WM_IME_CHAR
, c
, 1 );
889 SendMessageA( hwnd
, WM_IME_CHAR
, MAKEWORD(c
, lead
), 1 );
893 HeapFree( GetProcessHeap(), 0, buf
);
897 case WM_IME_STARTCOMPOSITION
:
898 case WM_IME_ENDCOMPOSITION
:
903 HWND hwndIME
= ImmGetDefaultIMEWnd( hwnd
);
905 result
= SendMessageA( hwndIME
, msg
, wParam
, lParam
);
908 case WM_IME_SETCONTEXT
:
910 HWND hwndIME
= ImmGetDefaultIMEWnd( hwnd
);
911 if (hwndIME
) result
= ImmIsUIMessageA( hwndIME
, msg
, wParam
, lParam
);
917 CHAR ch
= LOWORD(wParam
);
919 MultiByteToWideChar(CP_ACP
, 0, &ch
, 1, &wch
, 1);
920 wParam
= MAKEWPARAM( wch
, HIWORD(wParam
) );
924 result
= DEFWND_DefWinProc( hwnd
, msg
, wParam
, lParam
);
928 SPY_ExitMessage( SPY_RESULT_DEFWND
, hwnd
, msg
, result
, wParam
, lParam
);
933 static LPARAM
DEFWND_GetTextW( WND
*wndPtr
, LPWSTR dest
, WPARAM wParam
)
941 lstrcpynW( dest
, wndPtr
->text
, wParam
);
942 result
= lstrlenW( dest
);
955 /***********************************************************************
956 * DefWindowProcW (USER32.@) Calls default window message handler
958 * Calls default window procedure for messages not processed
962 * Return value is dependent upon the message.
964 LRESULT WINAPI
DefWindowProcW(
965 HWND hwnd
, /* [in] window procedure receiving message */
966 UINT msg
, /* [in] message identifier */
967 WPARAM wParam
, /* [in] first message parameter */
968 LPARAM lParam
) /* [in] second message parameter */
973 if (!(full_handle
= WIN_IsCurrentProcess( hwnd
)))
975 if (!IsWindow( hwnd
)) return 0;
976 ERR( "called for other process window %p\n", hwnd
);
980 SPY_EnterMessage( SPY_DEFWNDPROC
, hwnd
, msg
, wParam
, lParam
);
987 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lParam
;
989 DEFWND_SetTextW( hwnd
, cs
->lpszName
);
992 if(cs
->style
& (WS_HSCROLL
| WS_VSCROLL
))
994 SCROLLINFO si
= {sizeof si
, SIF_ALL
, 0, 100, 0, 0, 0};
995 SetScrollInfo( hwnd
, SB_HORZ
, &si
, FALSE
);
996 SetScrollInfo( hwnd
, SB_VERT
, &si
, FALSE
);
1001 case WM_GETTEXTLENGTH
:
1003 WND
*wndPtr
= WIN_GetPtr( hwnd
);
1004 if (wndPtr
&& wndPtr
->text
) result
= (LRESULT
)lstrlenW(wndPtr
->text
);
1005 WIN_ReleasePtr( wndPtr
);
1012 LPWSTR dest
= (LPWSTR
)lParam
;
1013 WND
*wndPtr
= WIN_GetPtr( hwnd
);
1016 result
= DEFWND_GetTextW( wndPtr
, dest
, wParam
);
1017 WIN_ReleasePtr( wndPtr
);
1022 if (!DEFWND_SetTextW( hwnd
, (LPCWSTR
)lParam
))
1024 if( (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1025 NC_HandleNCPaint( hwnd
, (HRGN
)1 ); /* Repaint caption */
1026 result
= 1; /* success. FIXME: check text length */
1030 PostMessageW( hwnd
, WM_CHAR
, wParam
, lParam
);
1033 case WM_IME_KEYDOWN
:
1034 result
= PostMessageW( hwnd
, WM_KEYDOWN
, wParam
, lParam
);
1038 result
= PostMessageW( hwnd
, WM_KEYUP
, wParam
, lParam
);
1041 case WM_IME_SETCONTEXT
:
1043 HWND hwndIME
= ImmGetDefaultIMEWnd( hwnd
);
1044 if (hwndIME
) result
= ImmIsUIMessageW( hwndIME
, msg
, wParam
, lParam
);
1048 case WM_IME_COMPOSITION
:
1049 if (lParam
& GCS_RESULTSTR
)
1053 HIMC himc
= ImmGetContext( hwnd
);
1057 if ((size
= ImmGetCompositionStringW( himc
, GCS_RESULTSTR
, NULL
, 0 )))
1059 if (!(buf
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(WCHAR
) ))) size
= 0;
1060 else size
= ImmGetCompositionStringW( himc
, GCS_RESULTSTR
, buf
, size
* sizeof(WCHAR
) );
1062 ImmReleaseContext( hwnd
, himc
);
1064 for (i
= 0; i
< size
/ sizeof(WCHAR
); i
++)
1065 SendMessageW( hwnd
, WM_IME_CHAR
, buf
[i
], 1 );
1066 HeapFree( GetProcessHeap(), 0, buf
);
1070 case WM_IME_STARTCOMPOSITION
:
1071 case WM_IME_ENDCOMPOSITION
:
1074 case WM_IME_CONTROL
:
1076 HWND hwndIME
= ImmGetDefaultIMEWnd( hwnd
);
1078 result
= SendMessageW( hwndIME
, msg
, wParam
, lParam
);
1083 result
= DEFWND_DefWinProc( hwnd
, msg
, wParam
, lParam
);
1086 SPY_ExitMessage( SPY_RESULT_DEFWND
, hwnd
, msg
, result
, wParam
, lParam
);