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"
34 #include "user_private.h"
36 #include "wine/unicode.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 #define DRAG_FILE 0x454C4946
49 static short iF10Key
= 0;
50 static short iMenuSysKey
= 0;
52 /***********************************************************************
53 * DEFWND_HandleWindowPosChanged
55 * Handle the WM_WINDOWPOSCHANGED message.
57 static void DEFWND_HandleWindowPosChanged( HWND hwnd
, const WINDOWPOS
*winpos
)
61 WIN_GetRectangles( hwnd
, COORDS_PARENT
, NULL
, &rect
);
62 if (!(winpos
->flags
& SWP_NOCLIENTMOVE
))
63 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG(rect
.left
, rect
.top
));
65 if (!(winpos
->flags
& SWP_NOCLIENTSIZE
) || (winpos
->flags
& SWP_STATECHANGED
))
69 SendMessageW( hwnd
, WM_SIZE
, SIZE_MINIMIZED
, 0 );
73 WPARAM wp
= IsZoomed( hwnd
) ? SIZE_MAXIMIZED
: SIZE_RESTORED
;
75 SendMessageW( hwnd
, WM_SIZE
, wp
, MAKELONG(rect
.right
-rect
.left
, rect
.bottom
-rect
.top
) );
81 /***********************************************************************
84 * Set the window text.
86 static LRESULT
DEFWND_SetTextA( HWND hwnd
, LPCSTR text
)
92 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
93 * may have child window IDs instead of window name */
94 if (text
&& IS_INTRESOURCE(text
))
98 count
= MultiByteToWideChar( CP_ACP
, 0, text
, -1, NULL
, 0 );
100 if (!(wndPtr
= WIN_GetPtr( hwnd
))) return 0;
101 if ((textW
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(WCHAR
))))
103 HeapFree(GetProcessHeap(), 0, wndPtr
->text
);
104 wndPtr
->text
= textW
;
105 MultiByteToWideChar( CP_ACP
, 0, text
, -1, textW
, count
);
106 SERVER_START_REQ( set_window_text
)
108 req
->handle
= wine_server_user_handle( hwnd
);
109 wine_server_add_data( req
, textW
, (count
-1) * sizeof(WCHAR
) );
110 wine_server_call( req
);
115 ERR("Not enough memory for window text\n");
116 WIN_ReleasePtr( wndPtr
);
118 USER_Driver
->pSetWindowText( hwnd
, textW
);
123 /***********************************************************************
126 * Set the window text.
128 static LRESULT
DEFWND_SetTextW( HWND hwnd
, LPCWSTR text
)
130 static const WCHAR empty_string
[] = {0};
134 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
135 * may have child window IDs instead of window name */
136 if (text
&& IS_INTRESOURCE(text
))
139 if (!text
) text
= empty_string
;
140 count
= strlenW(text
) + 1;
142 if (!(wndPtr
= WIN_GetPtr( hwnd
))) return 0;
143 HeapFree(GetProcessHeap(), 0, wndPtr
->text
);
144 if ((wndPtr
->text
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(WCHAR
))))
146 strcpyW( wndPtr
->text
, text
);
147 SERVER_START_REQ( set_window_text
)
149 req
->handle
= wine_server_user_handle( hwnd
);
150 wine_server_add_data( req
, wndPtr
->text
, (count
-1) * sizeof(WCHAR
) );
151 wine_server_call( req
);
156 ERR("Not enough memory for window text\n");
158 WIN_ReleasePtr( wndPtr
);
160 USER_Driver
->pSetWindowText( hwnd
, text
);
165 /***********************************************************************
166 * DEFWND_ControlColor
168 * Default colors for control painting.
170 HBRUSH
DEFWND_ControlColor( HDC hDC
, UINT ctlType
)
172 if( ctlType
== CTLCOLOR_SCROLLBAR
)
174 HBRUSH hb
= GetSysColorBrush(COLOR_SCROLLBAR
);
175 COLORREF bk
= GetSysColor(COLOR_3DHILIGHT
);
176 SetTextColor( hDC
, GetSysColor(COLOR_3DFACE
));
177 SetBkColor( hDC
, bk
);
179 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
180 * we better use 0x55aa bitmap brush to make scrollbar's background
181 * look different from the window background.
183 if (bk
== GetSysColor(COLOR_WINDOW
))
184 return SYSCOLOR_Get55AABrush();
186 UnrealizeObject( hb
);
190 SetTextColor( hDC
, GetSysColor(COLOR_WINDOWTEXT
));
192 if ((ctlType
== CTLCOLOR_EDIT
) || (ctlType
== CTLCOLOR_LISTBOX
))
193 SetBkColor( hDC
, GetSysColor(COLOR_WINDOW
) );
195 SetBkColor( hDC
, GetSysColor(COLOR_3DFACE
) );
196 return GetSysColorBrush(COLOR_3DFACE
);
198 return GetSysColorBrush(COLOR_WINDOW
);
202 /***********************************************************************
205 * This method handles the default behavior for the WM_PRINT message.
207 static void DEFWND_Print( HWND hwnd
, HDC hdc
, ULONG uFlags
)
212 if ( (uFlags
& PRF_CHECKVISIBLE
) &&
213 !IsWindowVisible(hwnd
) )
217 * Unimplemented flags.
219 if ( (uFlags
& PRF_CHILDREN
) ||
220 (uFlags
& PRF_OWNED
) ||
221 (uFlags
& PRF_NONCLIENT
) )
223 WARN("WM_PRINT message with unsupported flags\n");
229 if ( uFlags
& PRF_ERASEBKGND
)
230 SendMessageW(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
235 if ( uFlags
& PRF_CLIENT
)
236 SendMessageW(hwnd
, WM_PRINTCLIENT
, (WPARAM
)hdc
, uFlags
);
241 /***********************************************************************
244 * Default window procedure for messages that are the same in Ansi and Unicode.
246 static LRESULT
DEFWND_DefWinProc( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
251 return NC_HandleNCPaint( hwnd
, (HRGN
)wParam
);
256 pt
.x
= (short)LOWORD(lParam
);
257 pt
.y
= (short)HIWORD(lParam
);
258 return NC_HandleNCHitTest( hwnd
, pt
);
262 return NC_HandleNCCalcSize( hwnd
, wParam
, (RECT
*)lParam
);
264 case WM_WINDOWPOSCHANGING
:
265 return WINPOS_HandleWindowPosChanging( hwnd
, (WINDOWPOS
*)lParam
);
267 case WM_WINDOWPOSCHANGED
:
268 DEFWND_HandleWindowPosChanged( hwnd
, (const WINDOWPOS
*)lParam
);
274 iF10Key
= iMenuSysKey
= 0;
277 case WM_NCLBUTTONDOWN
:
278 return NC_HandleNCLButtonDown( hwnd
, wParam
, lParam
);
280 case WM_LBUTTONDBLCLK
:
281 return NC_HandleNCLButtonDblClk( hwnd
, HTCLIENT
, lParam
);
283 case WM_NCLBUTTONDBLCLK
:
284 return NC_HandleNCLButtonDblClk( hwnd
, wParam
, lParam
);
286 case WM_NCRBUTTONDOWN
:
287 return NC_HandleNCRButtonDown( hwnd
, wParam
, lParam
);
292 pt
.x
= (short)LOWORD(lParam
);
293 pt
.y
= (short)HIWORD(lParam
);
294 ClientToScreen(hwnd
, &pt
);
295 SendMessageW( hwnd
, WM_CONTEXTMENU
, (WPARAM
)hwnd
, MAKELPARAM(pt
.x
, pt
.y
) );
301 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
302 * in Windows), but what _should_ we do? According to MSDN :
303 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
304 * message to the window". When is it appropriate?
310 if (HIWORD(wParam
) == XBUTTON1
|| HIWORD(wParam
) == XBUTTON2
)
312 SendMessageW(hwnd
, WM_APPCOMMAND
, (WPARAM
)hwnd
,
313 MAKELPARAM(LOWORD(wParam
), FAPPCOMMAND_MOUSE
| HIWORD(wParam
)));
318 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)
319 SendMessageW( GetParent(hwnd
), msg
, wParam
, lParam
);
324 pt
.x
= (short)LOWORD(lParam
);
325 pt
.y
= (short)HIWORD(lParam
);
326 hitcode
= NC_HandleNCHitTest(hwnd
, pt
);
328 /* Track system popup if click was in the caption area. */
329 if (hitcode
==HTCAPTION
|| hitcode
==HTSYSMENU
)
330 TrackPopupMenu(GetSystemMenu(hwnd
, FALSE
),
331 TPM_LEFTBUTTON
| TPM_RIGHTBUTTON
,
332 pt
.x
, pt
.y
, 0, hwnd
, NULL
);
336 case WM_POPUPSYSTEMMENU
:
337 /* This is an undocumented message used by the windows taskbar to
338 display the system menu of windows that belong to other processes. */
339 TrackPopupMenu( GetSystemMenu(hwnd
, FALSE
), TPM_LEFTBUTTON
|TPM_RIGHTBUTTON
,
340 (short)LOWORD(lParam
), (short)HIWORD(lParam
), 0, hwnd
, NULL
);
344 return NC_HandleNCActivate( hwnd
, wParam
, lParam
);
348 WND
*wndPtr
= WIN_GetPtr( hwnd
);
349 if (!wndPtr
) return 0;
350 HeapFree( GetProcessHeap(), 0, wndPtr
->text
);
352 HeapFree( GetProcessHeap(), 0, wndPtr
->pScroll
);
353 wndPtr
->pScroll
= NULL
;
354 WIN_ReleasePtr( wndPtr
);
359 DEFWND_Print(hwnd
, (HDC
)wParam
, lParam
);
366 HDC hdc
= BeginPaint( hwnd
, &ps
);
370 if (IsIconic(hwnd
) && ((hIcon
= (HICON
)GetClassLongPtrW( hwnd
, GCLP_HICON
))) )
375 GetClientRect( hwnd
, &rc
);
376 x
= (rc
.right
- rc
.left
- GetSystemMetrics(SM_CXICON
))/2;
377 y
= (rc
.bottom
- rc
.top
- GetSystemMetrics(SM_CYICON
))/2;
378 TRACE("Painting class icon: vis rect=(%s)\n",
379 wine_dbgstr_rect(&ps
.rcPaint
));
380 DrawIcon( hdc
, x
, y
, hIcon
);
382 EndPaint( hwnd
, &ps
);
388 RedrawWindow ( hwnd
, NULL
, 0, RDW_ERASENOW
| RDW_ERASE
| RDW_ALLCHILDREN
);
392 if (wParam
) WIN_SetStyle( hwnd
, WS_VISIBLE
, 0 );
395 RedrawWindow( hwnd
, NULL
, 0, RDW_ALLCHILDREN
| RDW_VALIDATE
);
396 WIN_SetStyle( hwnd
, 0, WS_VISIBLE
);
401 DestroyWindow( hwnd
);
404 case WM_MOUSEACTIVATE
:
405 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)
407 LONG ret
= SendMessageW( GetParent(hwnd
), WM_MOUSEACTIVATE
, wParam
, lParam
);
411 /* Caption clicks are handled by NC_HandleNCLButtonDown() */
415 /* The default action in Windows is to set the keyboard focus to
416 * the window, if it's being activated and not minimized */
417 if (LOWORD(wParam
) != WA_INACTIVE
) {
418 if (!IsIconic(hwnd
)) SetFocus(hwnd
);
423 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)
424 return SendMessageW( GetParent(hwnd
), WM_MOUSEWHEEL
, wParam
, lParam
);
428 case WM_ICONERASEBKGND
:
431 HDC hdc
= (HDC
)wParam
;
432 HBRUSH hbr
= (HBRUSH
)GetClassLongPtrW( hwnd
, GCLP_HBRBACKGROUND
);
435 if (GetClassLongW( hwnd
, GCL_STYLE
) & CS_PARENTDC
)
437 /* can't use GetClipBox with a parent DC or we fill the whole parent */
438 GetClientRect( hwnd
, &rect
);
439 DPtoLP( hdc
, (LPPOINT
)&rect
, 2 );
441 else GetClipBox( hdc
, &rect
);
442 FillRect( hdc
, &rect
, hbr
);
449 case WM_CTLCOLORMSGBOX
:
450 case WM_CTLCOLOREDIT
:
451 case WM_CTLCOLORLISTBOX
:
454 case WM_CTLCOLORSTATIC
:
455 case WM_CTLCOLORSCROLLBAR
:
456 return (LRESULT
)DEFWND_ControlColor( (HDC
)wParam
, msg
- WM_CTLCOLORMSGBOX
);
459 return (LRESULT
)DEFWND_ControlColor( (HDC
)wParam
, HIWORD(lParam
) );
462 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)
464 /* with the exception of the border around a resizable wnd,
465 * give the parent first chance to set the cursor */
466 if ((LOWORD(lParam
) < HTSIZEFIRST
) || (LOWORD(lParam
) > HTSIZELAST
))
468 HWND parent
= GetParent( hwnd
);
469 if (parent
!= GetDesktopWindow() &&
470 SendMessageW( parent
, WM_SETCURSOR
, wParam
, lParam
)) return TRUE
;
473 NC_HandleSetCursor( hwnd
, wParam
, lParam
);
477 return NC_HandleSysCommand( hwnd
, wParam
, lParam
);
480 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
484 if( HIWORD(lParam
) & KEYDATA_ALT
)
486 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
487 if ( (wParam
== VK_MENU
|| wParam
== VK_LMENU
488 || wParam
== VK_RMENU
) && !iMenuSysKey
)
495 if( wParam
== VK_F4
) /* try to close the window */
497 HWND top
= GetAncestor( hwnd
, GA_ROOT
);
498 if (!(GetClassLongW( top
, GCL_STYLE
) & CS_NOCLOSE
))
499 PostMessageW( top
, WM_SYSCOMMAND
, SC_CLOSE
, 0 );
502 else if( wParam
== VK_F10
)
504 if (GetKeyState(VK_SHIFT
) & 0x8000)
505 SendMessageW( hwnd
, WM_CONTEXTMENU
, (WPARAM
)hwnd
, -1 );
508 else if( wParam
== VK_ESCAPE
&& (GetKeyState(VK_SHIFT
) & 0x8000))
509 SendMessageW( hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, ' ' );
514 /* Press and release F10 or ALT */
515 if (((wParam
== VK_MENU
|| wParam
== VK_LMENU
|| wParam
== VK_RMENU
)
516 && iMenuSysKey
) || ((wParam
== VK_F10
) && iF10Key
))
517 SendMessageW( GetAncestor( hwnd
, GA_ROOT
), WM_SYSCOMMAND
, SC_KEYMENU
, 0L );
518 iMenuSysKey
= iF10Key
= 0;
524 if (wParam
== '\r' && IsIconic(hwnd
))
526 PostMessageW( hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0L );
529 if ((HIWORD(lParam
) & KEYDATA_ALT
) && wParam
)
531 if (wParam
== '\t' || wParam
== '\x1b') break;
532 if (wParam
== ' ' && (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
))
533 SendMessageW( GetParent(hwnd
), msg
, wParam
, lParam
);
535 SendMessageW( hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, wParam
);
537 else /* check for Ctrl-Esc */
538 if (wParam
!= '\x1b') MessageBeep(0);
544 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
546 if (!lParam
) return 0; /* sent from ShowWindow */
547 if ((style
& WS_VISIBLE
) && wParam
) return 0;
548 if (!(style
& WS_VISIBLE
) && !wParam
) return 0;
549 if (!GetWindow( hwnd
, GW_OWNER
)) return 0;
550 if (!(pWnd
= WIN_GetPtr( hwnd
))) return 0;
551 if (pWnd
== WND_OTHER_PROCESS
) return 0;
554 if (!(pWnd
->flags
& WIN_NEEDS_SHOW_OWNEDPOPUP
))
556 WIN_ReleasePtr( pWnd
);
559 pWnd
->flags
&= ~WIN_NEEDS_SHOW_OWNEDPOPUP
;
561 else pWnd
->flags
|= WIN_NEEDS_SHOW_OWNEDPOPUP
;
562 WIN_ReleasePtr( pWnd
);
563 ShowWindow( hwnd
, wParam
? SW_SHOWNOACTIVATE
: SW_HIDE
);
569 MENU_EndMenu( hwnd
);
570 if (GetCapture() == hwnd
) ReleaseCapture();
580 case WM_QUERYDROPOBJECT
:
581 return (GetWindowLongA( hwnd
, GWL_EXSTYLE
) & WS_EX_ACCEPTFILES
) != 0;
583 case WM_QUERYDRAGICON
:
587 HICON hIcon
= (HICON
)GetClassLongPtrW( hwnd
, GCLP_HICON
);
588 HINSTANCE instance
= (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
);
589 if (hIcon
) return (LRESULT
)hIcon
;
590 for(len
=1; len
<64; len
++)
591 if((hIcon
= LoadIconW(instance
, MAKEINTRESOURCEW(len
))))
592 return (LRESULT
)hIcon
;
593 return (LRESULT
)LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
597 case WM_ISACTIVEICON
:
598 return (win_get_flags( hwnd
) & WIN_NCACTIVATED
) != 0;
600 case WM_NOTIFYFORMAT
:
601 if (IsWindowUnicode(hwnd
)) return NFR_UNICODE
;
602 else return NFR_ANSI
;
605 case WM_QUERYENDSESSION
:
611 WND
*wndPtr
= WIN_GetPtr( hwnd
);
616 ret
= wndPtr
->hIconSmall
;
617 if (ret
&& !lParam
&& wndPtr
->hIcon
)
619 wndPtr
->hIconSmall2
= CopyImage( wndPtr
->hIcon
, IMAGE_ICON
,
620 GetSystemMetrics( SM_CXSMICON
),
621 GetSystemMetrics( SM_CYSMICON
), 0 );
623 else if (lParam
&& wndPtr
->hIconSmall2
)
625 DestroyIcon( wndPtr
->hIconSmall2
);
626 wndPtr
->hIconSmall2
= NULL
;
628 wndPtr
->hIconSmall
= (HICON
)lParam
;
632 if (wndPtr
->hIconSmall2
)
634 DestroyIcon( wndPtr
->hIconSmall2
);
635 wndPtr
->hIconSmall2
= NULL
;
637 if (lParam
&& !wndPtr
->hIconSmall
)
639 wndPtr
->hIconSmall2
= CopyImage( (HICON
)lParam
, IMAGE_ICON
,
640 GetSystemMetrics( SM_CXSMICON
),
641 GetSystemMetrics( SM_CYSMICON
), 0 );
643 wndPtr
->hIcon
= (HICON
)lParam
;
649 WIN_ReleasePtr( wndPtr
);
651 USER_Driver
->pSetWindowIcon( hwnd
, wParam
, (HICON
)lParam
);
653 if( (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
654 NC_HandleNCPaint( hwnd
, (HRGN
)1 ); /* Repaint caption */
662 WND
*wndPtr
= WIN_GetPtr( hwnd
);
667 ret
= wndPtr
->hIconSmall
;
673 ret
= wndPtr
->hIconSmall
? wndPtr
->hIconSmall
: wndPtr
->hIconSmall2
;
679 WIN_ReleasePtr( wndPtr
);
684 SendMessageW( GetParent(hwnd
), msg
, wParam
, lParam
);
687 case WM_STYLECHANGED
:
688 if (wParam
== GWL_STYLE
&& (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_LAYERED
))
690 STYLESTRUCT
*style
= (STYLESTRUCT
*)lParam
;
691 if ((style
->styleOld
^ style
->styleNew
) & (WS_CAPTION
|WS_THICKFRAME
|WS_VSCROLL
|WS_HSCROLL
))
692 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
| SWP_NOZORDER
|
693 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOCLIENTSIZE
| SWP_NOCLIENTMOVE
);
699 HWND parent
= GetParent(hwnd
);
701 HOOK_CallHooks(WH_SHELL
, HSHELL_APPCOMMAND
, wParam
, lParam
, TRUE
);
703 SendMessageW( parent
, msg
, wParam
, lParam
);
710 hi
.cbSize
= sizeof(HELPINFO
);
711 GetCursorPos( &hi
.MousePos
);
712 if (MENU_IsMenuActive())
714 hi
.iContextType
= HELPINFO_MENUITEM
;
715 hi
.hItemHandle
= MENU_IsMenuActive();
716 hi
.iCtrlId
= MenuItemFromPoint( hwnd
, hi
.hItemHandle
, hi
.MousePos
);
717 hi
.dwContextId
= GetMenuContextHelpId( hi
.hItemHandle
);
721 hi
.iContextType
= HELPINFO_WINDOW
;
722 hi
.hItemHandle
= hwnd
;
723 hi
.iCtrlId
= GetWindowLongPtrA( hwnd
, GWLP_ID
);
724 hi
.dwContextId
= GetWindowContextHelpId( hwnd
);
726 SendMessageW( hwnd
, WM_HELP
, 0, (LPARAM
)&hi
);
730 case WM_INPUTLANGCHANGEREQUEST
:
731 ActivateKeyboardLayout( (HKL
)lParam
, 0 );
734 case WM_INPUTLANGCHANGE
:
737 HWND
*win_array
= WIN_ListChildren( hwnd
);
741 while (win_array
[count
])
742 SendMessageW( win_array
[count
++], WM_INPUTLANGCHANGE
, wParam
, lParam
);
743 HeapFree(GetProcessHeap(),0,win_array
);
752 static LPARAM
DEFWND_GetTextA( WND
*wndPtr
, LPSTR dest
, WPARAM wParam
)
760 if (!WideCharToMultiByte( CP_ACP
, 0, wndPtr
->text
, -1,
761 dest
, wParam
, NULL
, NULL
)) dest
[wParam
-1] = 0;
762 result
= strlen( dest
);
774 /***********************************************************************
775 * DefWindowProcA (USER32.@)
777 * See DefWindowProcW.
779 LRESULT WINAPI
DefWindowProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
784 if (!(full_handle
= WIN_IsCurrentProcess( hwnd
)))
786 if (!IsWindow( hwnd
)) return 0;
787 ERR( "called for other process window %p\n", hwnd
);
792 SPY_EnterMessage( SPY_DEFWNDPROC
, hwnd
, msg
, wParam
, lParam
);
799 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
801 DEFWND_SetTextA( hwnd
, cs
->lpszName
);
804 if(cs
->style
& (WS_HSCROLL
| WS_VSCROLL
))
806 SCROLLINFO si
= {sizeof si
, SIF_ALL
, 0, 100, 0, 0, 0};
807 SetScrollInfo( hwnd
, SB_HORZ
, &si
, FALSE
);
808 SetScrollInfo( hwnd
, SB_VERT
, &si
, FALSE
);
813 case WM_GETTEXTLENGTH
:
815 WND
*wndPtr
= WIN_GetPtr( hwnd
);
816 if (wndPtr
&& wndPtr
->text
)
817 result
= WideCharToMultiByte( CP_ACP
, 0, wndPtr
->text
, strlenW(wndPtr
->text
),
818 NULL
, 0, NULL
, NULL
);
819 WIN_ReleasePtr( wndPtr
);
826 LPSTR dest
= (LPSTR
)lParam
;
827 WND
*wndPtr
= WIN_GetPtr( hwnd
);
830 result
= DEFWND_GetTextA( wndPtr
, dest
, wParam
);
832 WIN_ReleasePtr( wndPtr
);
837 if (!DEFWND_SetTextA( hwnd
, (LPCSTR
)lParam
))
839 if( (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
840 NC_HandleNCPaint( hwnd
, (HRGN
)1 ); /* Repaint caption */
841 result
= 1; /* success. FIXME: check text length */
845 if (HIBYTE(wParam
)) PostMessageA( hwnd
, WM_CHAR
, HIBYTE(wParam
), lParam
);
846 PostMessageA( hwnd
, WM_CHAR
, LOBYTE(wParam
), lParam
);
850 result
= PostMessageA( hwnd
, WM_KEYDOWN
, wParam
, lParam
);
854 result
= PostMessageA( hwnd
, WM_KEYUP
, wParam
, lParam
);
857 case WM_IME_COMPOSITION
:
858 if (lParam
& GCS_RESULTSTR
)
861 unsigned char lead
= 0;
863 HIMC himc
= ImmGetContext( hwnd
);
867 if ((size
= ImmGetCompositionStringA( himc
, GCS_RESULTSTR
, NULL
, 0 )))
869 if (!(buf
= HeapAlloc( GetProcessHeap(), 0, size
))) size
= 0;
870 else size
= ImmGetCompositionStringA( himc
, GCS_RESULTSTR
, buf
, size
);
872 ImmReleaseContext( hwnd
, himc
);
874 for (i
= 0; i
< size
; i
++)
876 unsigned char c
= buf
[i
];
879 if (IsDBCSLeadByte( c
))
882 SendMessageA( hwnd
, WM_IME_CHAR
, c
, 1 );
886 SendMessageA( hwnd
, WM_IME_CHAR
, MAKEWORD(c
, lead
), 1 );
890 HeapFree( GetProcessHeap(), 0, buf
);
894 case WM_IME_STARTCOMPOSITION
:
895 case WM_IME_ENDCOMPOSITION
:
900 HWND hwndIME
= ImmGetDefaultIMEWnd( hwnd
);
902 result
= SendMessageA( hwndIME
, msg
, wParam
, lParam
);
905 case WM_IME_SETCONTEXT
:
907 HWND hwndIME
= ImmGetDefaultIMEWnd( hwnd
);
908 if (hwndIME
) result
= ImmIsUIMessageA( hwndIME
, msg
, wParam
, lParam
);
914 CHAR ch
= LOWORD(wParam
);
916 MultiByteToWideChar(CP_ACP
, 0, &ch
, 1, &wch
, 1);
917 wParam
= MAKEWPARAM( wch
, HIWORD(wParam
) );
921 result
= DEFWND_DefWinProc( hwnd
, msg
, wParam
, lParam
);
925 SPY_ExitMessage( SPY_RESULT_DEFWND
, hwnd
, msg
, result
, wParam
, lParam
);
930 static LPARAM
DEFWND_GetTextW( WND
*wndPtr
, LPWSTR dest
, WPARAM wParam
)
938 lstrcpynW( dest
, wndPtr
->text
, wParam
);
939 result
= strlenW( dest
);
952 /***********************************************************************
953 * DefWindowProcW (USER32.@) Calls default window message handler
955 * Calls default window procedure for messages not processed
959 * Return value is dependent upon the message.
961 LRESULT WINAPI
DefWindowProcW(
962 HWND hwnd
, /* [in] window procedure receiving message */
963 UINT msg
, /* [in] message identifier */
964 WPARAM wParam
, /* [in] first message parameter */
965 LPARAM lParam
) /* [in] second message parameter */
970 if (!(full_handle
= WIN_IsCurrentProcess( hwnd
)))
972 if (!IsWindow( hwnd
)) return 0;
973 ERR( "called for other process window %p\n", hwnd
);
977 SPY_EnterMessage( SPY_DEFWNDPROC
, hwnd
, msg
, wParam
, lParam
);
984 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lParam
;
986 DEFWND_SetTextW( hwnd
, cs
->lpszName
);
989 if(cs
->style
& (WS_HSCROLL
| WS_VSCROLL
))
991 SCROLLINFO si
= {sizeof si
, SIF_ALL
, 0, 100, 0, 0, 0};
992 SetScrollInfo( hwnd
, SB_HORZ
, &si
, FALSE
);
993 SetScrollInfo( hwnd
, SB_VERT
, &si
, FALSE
);
998 case WM_GETTEXTLENGTH
:
1000 WND
*wndPtr
= WIN_GetPtr( hwnd
);
1001 if (wndPtr
&& wndPtr
->text
) result
= (LRESULT
)strlenW(wndPtr
->text
);
1002 WIN_ReleasePtr( wndPtr
);
1009 LPWSTR dest
= (LPWSTR
)lParam
;
1010 WND
*wndPtr
= WIN_GetPtr( hwnd
);
1013 result
= DEFWND_GetTextW( wndPtr
, dest
, wParam
);
1014 WIN_ReleasePtr( wndPtr
);
1019 if (!DEFWND_SetTextW( hwnd
, (LPCWSTR
)lParam
))
1021 if( (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1022 NC_HandleNCPaint( hwnd
, (HRGN
)1 ); /* Repaint caption */
1023 result
= 1; /* success. FIXME: check text length */
1027 PostMessageW( hwnd
, WM_CHAR
, wParam
, lParam
);
1030 case WM_IME_KEYDOWN
:
1031 result
= PostMessageW( hwnd
, WM_KEYDOWN
, wParam
, lParam
);
1035 result
= PostMessageW( hwnd
, WM_KEYUP
, wParam
, lParam
);
1038 case WM_IME_SETCONTEXT
:
1040 HWND hwndIME
= ImmGetDefaultIMEWnd( hwnd
);
1041 if (hwndIME
) result
= ImmIsUIMessageW( hwndIME
, msg
, wParam
, lParam
);
1045 case WM_IME_COMPOSITION
:
1046 if (lParam
& GCS_RESULTSTR
)
1050 HIMC himc
= ImmGetContext( hwnd
);
1054 if ((size
= ImmGetCompositionStringW( himc
, GCS_RESULTSTR
, NULL
, 0 )))
1056 if (!(buf
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(WCHAR
) ))) size
= 0;
1057 else size
= ImmGetCompositionStringW( himc
, GCS_RESULTSTR
, buf
, size
* sizeof(WCHAR
) );
1059 ImmReleaseContext( hwnd
, himc
);
1061 for (i
= 0; i
< size
/ sizeof(WCHAR
); i
++)
1062 SendMessageW( hwnd
, WM_IME_CHAR
, buf
[i
], 1 );
1063 HeapFree( GetProcessHeap(), 0, buf
);
1067 case WM_IME_STARTCOMPOSITION
:
1068 case WM_IME_ENDCOMPOSITION
:
1071 case WM_IME_CONTROL
:
1073 HWND hwndIME
= ImmGetDefaultIMEWnd( hwnd
);
1075 result
= SendMessageW( hwndIME
, msg
, wParam
, lParam
);
1080 result
= DEFWND_DefWinProc( hwnd
, msg
, wParam
, lParam
);
1083 SPY_ExitMessage( SPY_RESULT_DEFWND
, hwnd
, msg
, result
, wParam
, lParam
);