2 * Default window procedure
4 * Copyright 1993, 1996 Alexandre Julliard
13 #include "nonclient.h"
19 #include "wine/winuser16.h"
21 DEFAULT_DEBUG_CHANNEL(win
)
24 #define COLOR_MAX COLOR_BTNHIGHLIGHT
26 /* bits in the dwKeyData */
27 #define KEYDATA_ALT 0x2000
28 #define KEYDATA_PREVSTATE 0x4000
30 static short iF10Key
= 0;
31 static short iMenuSysKey
= 0;
33 /***********************************************************************
34 * DEFWND_HandleWindowPosChanged
36 * Handle the WM_WINDOWPOSCHANGED message.
38 static void DEFWND_HandleWindowPosChanged( WND
*wndPtr
, UINT flags
)
40 WPARAM16 wp
= SIZE_RESTORED
;
42 if (!(flags
& SWP_NOCLIENTMOVE
))
43 SendMessage16( wndPtr
->hwndSelf
, WM_MOVE
, 0,
44 MAKELONG(wndPtr
->rectClient
.left
, wndPtr
->rectClient
.top
));
45 if (!(flags
& SWP_NOCLIENTSIZE
))
47 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wp
= SIZE_MAXIMIZED
;
48 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wp
= SIZE_MINIMIZED
;
50 SendMessage16( wndPtr
->hwndSelf
, WM_SIZE
, wp
,
51 MAKELONG(wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
52 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
));
57 /***********************************************************************
60 * Set the window text.
62 void DEFWND_SetText( WND
*wndPtr
, LPCSTR text
)
65 if (wndPtr
->text
) HeapFree( SystemHeap
, 0, wndPtr
->text
);
66 wndPtr
->text
= HEAP_strdupA( SystemHeap
, 0, text
);
67 wndPtr
->pDriver
->pSetText(wndPtr
, wndPtr
->text
);
70 /***********************************************************************
73 * Default colors for control painting.
75 HBRUSH
DEFWND_ControlColor( HDC hDC
, UINT16 ctlType
)
77 if( ctlType
== CTLCOLOR_SCROLLBAR
)
79 HBRUSH hb
= GetSysColorBrush(COLOR_SCROLLBAR
);
80 SetBkColor( hDC
, RGB(255, 255, 255) );
81 SetTextColor( hDC
, RGB(0, 0, 0) );
82 UnrealizeObject( hb
);
86 SetTextColor( hDC
, GetSysColor(COLOR_WINDOWTEXT
));
88 if (TWEAK_WineLook
> WIN31_LOOK
) {
89 if ((ctlType
== CTLCOLOR_EDIT
) || (ctlType
== CTLCOLOR_LISTBOX
))
90 SetBkColor( hDC
, GetSysColor(COLOR_WINDOW
) );
92 SetBkColor( hDC
, GetSysColor(COLOR_3DFACE
) );
93 return GetSysColorBrush(COLOR_3DFACE
);
97 SetBkColor( hDC
, GetSysColor(COLOR_WINDOW
) );
98 return GetSysColorBrush(COLOR_WINDOW
);
102 /***********************************************************************
105 static void DEFWND_SetRedraw( WND
* wndPtr
, WPARAM wParam
)
107 BOOL bVisible
= wndPtr
->dwStyle
& WS_VISIBLE
;
109 TRACE(win
,"%04x %i\n", wndPtr
->hwndSelf
, (wParam
!=0) );
115 wndPtr
->dwStyle
|= WS_VISIBLE
;
116 DCE_InvalidateDCE( wndPtr
, &wndPtr
->rectWindow
);
121 if( wndPtr
->dwStyle
& WS_MINIMIZE
) wParam
= RDW_VALIDATE
;
122 else wParam
= RDW_ALLCHILDREN
| RDW_VALIDATE
;
124 PAINT_RedrawWindow( wndPtr
->hwndSelf
, NULL
, 0, wParam
, 0 );
125 DCE_InvalidateDCE( wndPtr
, &wndPtr
->rectWindow
);
126 wndPtr
->dwStyle
&= ~WS_VISIBLE
;
130 /***********************************************************************
133 * This method handles the default behavior for the WM_PRINT message.
135 static void DEFWND_Print(
143 if ( (uFlags
& PRF_CHECKVISIBLE
) &&
144 !IsWindowVisible(wndPtr
->hwndSelf
) )
148 * Unimplemented flags.
150 if ( (uFlags
& PRF_CHILDREN
) ||
151 (uFlags
& PRF_OWNED
) ||
152 (uFlags
& PRF_NONCLIENT
) )
154 WARN(win
,"WM_PRINT message with unsupported flags\n");
160 if ( uFlags
& PRF_ERASEBKGND
)
161 SendMessageA(wndPtr
->hwndSelf
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
166 if ( uFlags
& PRF_CLIENT
)
167 SendMessageA(wndPtr
->hwndSelf
, WM_PRINTCLIENT
, (WPARAM
)hdc
, PRF_CLIENT
);
170 /***********************************************************************
173 * Default window procedure for messages that are the same in Win16 and Win32.
175 static LRESULT
DEFWND_DefWinProc( WND
*wndPtr
, UINT msg
, WPARAM wParam
,
181 return NC_HandleNCPaint( wndPtr
->hwndSelf
, (HRGN
)wParam
);
184 return NC_HandleNCHitTest( wndPtr
->hwndSelf
, MAKEPOINT16(lParam
) );
186 case WM_NCLBUTTONDOWN
:
187 return NC_HandleNCLButtonDown( wndPtr
, wParam
, lParam
);
189 case WM_LBUTTONDBLCLK
:
190 case WM_NCLBUTTONDBLCLK
:
191 return NC_HandleNCLButtonDblClk( wndPtr
, wParam
, lParam
);
194 case WM_NCRBUTTONDOWN
:
195 if ((wndPtr
->flags
& WIN_ISWIN32
) || (TWEAK_WineLook
> WIN31_LOOK
))
197 ClientToScreen16(wndPtr
->hwndSelf
, (LPPOINT16
)&lParam
);
198 SendMessageA( wndPtr
->hwndSelf
, WM_CONTEXTMENU
,
199 wndPtr
->hwndSelf
, lParam
);
204 if( wndPtr
->dwStyle
& WS_CHILD
)
205 SendMessageA( wndPtr
->parent
->hwndSelf
, msg
, wParam
, lParam
);
207 if (wndPtr
->hSysMenu
)
209 TrackPopupMenu32(wndPtr->hSysMenu,TPM_LEFTALIGN | TPM_RETURNCMD,LOWORD(lParam),HIWORD(lParam),0,wndPtr->hwndSelf,NULL);
210 DestroyMenu32(wndPtr->hSysMenu);
212 FIXME(win
,"Display default popup menu\n");
213 /* Track system popup if click was in the caption area. */
218 return NC_HandleNCActivate( wndPtr
, wParam
);
221 if (wndPtr
->text
) HeapFree( SystemHeap
, 0, wndPtr
->text
);
223 if (wndPtr
->pVScroll
) HeapFree( SystemHeap
, 0, wndPtr
->pVScroll
);
224 if (wndPtr
->pHScroll
) HeapFree( SystemHeap
, 0, wndPtr
->pHScroll
);
225 wndPtr
->pVScroll
= wndPtr
->pHScroll
= NULL
;
229 DEFWND_Print(wndPtr
, (HDC
)wParam
, lParam
);
236 HDC16 hdc
= BeginPaint16( wndPtr
->hwndSelf
, &ps
);
239 if( (wndPtr
->dwStyle
& WS_MINIMIZE
) && wndPtr
->class->hIcon
)
241 int x
= (wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
-
242 GetSystemMetrics(SM_CXICON
))/2;
243 int y
= (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
-
244 GetSystemMetrics(SM_CYICON
))/2;
245 TRACE(win
,"Painting class icon: vis rect=(%i,%i - %i,%i)\n",
246 ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
247 DrawIcon( hdc
, x
, y
, wndPtr
->class->hIcon
);
249 EndPaint16( wndPtr
->hwndSelf
, &ps
);
255 DEFWND_SetRedraw( wndPtr
, wParam
);
259 DestroyWindow( wndPtr
->hwndSelf
);
262 case WM_MOUSEACTIVATE
:
263 if (wndPtr
->dwStyle
& WS_CHILD
)
265 LONG ret
= SendMessage16( wndPtr
->parent
->hwndSelf
,
266 WM_MOUSEACTIVATE
, wParam
, lParam
);
270 /* Caption clicks are handled by the NC_HandleNCLButtonDown() */
271 return (LOWORD(lParam
) == HTCAPTION
) ? MA_NOACTIVATE
: MA_ACTIVATE
;
274 /* The default action in Windows is to set the keyboard focus to
275 * the window, if it's being activated and not minimized */
276 if (LOWORD(wParam
) != WA_INACTIVE
) {
277 /* I don't know who put this SetWindowPos here, it does not
278 * seem very logical to have it here... (FIXME?) */
279 SetWindowPos(wndPtr
->hwndSelf
, HWND_TOP
, 0, 0, 0, 0,
280 SWP_NOMOVE
| SWP_NOSIZE
);
281 if (!(wndPtr
->dwStyle
& WS_MINIMIZE
))
282 SetFocus(wndPtr
->hwndSelf
);
287 case WM_ICONERASEBKGND
:
289 if (!wndPtr
->class->hbrBackground
) return 0;
291 if (wndPtr
->class->hbrBackground
<= (HBRUSH16
)(COLOR_MAX
+1))
293 HBRUSH hbrush
= CreateSolidBrush(
294 GetSysColor(((DWORD
)wndPtr
->class->hbrBackground
)-1));
295 FillWindow16( GetParent16(wndPtr
->hwndSelf
), wndPtr
->hwndSelf
,
296 (HDC16
)wParam
, hbrush
);
297 DeleteObject( hbrush
);
299 else FillWindow16( GetParent16(wndPtr
->hwndSelf
), wndPtr
->hwndSelf
,
300 (HDC16
)wParam
, wndPtr
->class->hbrBackground
);
307 case WM_CTLCOLORMSGBOX
:
308 case WM_CTLCOLOREDIT
:
309 case WM_CTLCOLORLISTBOX
:
312 case WM_CTLCOLORSTATIC
:
313 case WM_CTLCOLORSCROLLBAR
:
314 return (LRESULT
)DEFWND_ControlColor( (HDC
)wParam
, msg
- WM_CTLCOLORMSGBOX
);
317 return (LRESULT
)DEFWND_ControlColor( (HDC
)wParam
, HIWORD(lParam
) );
319 case WM_GETTEXTLENGTH
:
320 if (wndPtr
->text
) return (LRESULT
)strlen(wndPtr
->text
);
324 if (wndPtr
->dwStyle
& WS_CHILD
)
325 if (SendMessage16(wndPtr
->parent
->hwndSelf
, WM_SETCURSOR
,
328 return NC_HandleSetCursor( wndPtr
->hwndSelf
, wParam
, lParam
);
331 return NC_HandleSysCommand( wndPtr
->hwndSelf
, wParam
,
332 MAKEPOINT16(lParam
) );
335 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
339 if( HIWORD(lParam
) & KEYDATA_ALT
)
341 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
342 if( wParam
== VK_MENU
&& !iMenuSysKey
)
349 if( wParam
== VK_F4
) /* try to close the window */
351 HWND hWnd
= WIN_GetTopParent( wndPtr
->hwndSelf
);
352 wndPtr
= WIN_FindWndPtr( hWnd
);
353 if( wndPtr
&& !(wndPtr
->class->style
& CS_NOCLOSE
) )
354 PostMessage16( hWnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0 );
355 WIN_ReleaseWndPtr(wndPtr
);
358 else if( wParam
== VK_F10
)
361 if( wParam
== VK_ESCAPE
&& (GetKeyState(VK_SHIFT
) & 0x8000))
362 SendMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
363 (WPARAM16
)SC_KEYMENU
, (LPARAM
)VK_SPACE
);
368 /* Press and release F10 or ALT */
369 if (((wParam
== VK_MENU
) && iMenuSysKey
) ||
370 ((wParam
== VK_F10
) && iF10Key
))
371 SendMessage16( WIN_GetTopParent(wndPtr
->hwndSelf
),
372 WM_SYSCOMMAND
, SC_KEYMENU
, 0L );
373 iMenuSysKey
= iF10Key
= 0;
378 if (wParam
== VK_RETURN
&& (wndPtr
->dwStyle
& WS_MINIMIZE
))
380 PostMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
381 (WPARAM16
)SC_RESTORE
, 0L );
384 if ((HIWORD(lParam
) & KEYDATA_ALT
) && wParam
)
386 if (wParam
== VK_TAB
|| wParam
== VK_ESCAPE
) break;
387 if (wParam
== VK_SPACE
&& (wndPtr
->dwStyle
& WS_CHILD
))
388 SendMessage16( wndPtr
->parent
->hwndSelf
, msg
, wParam
, lParam
);
390 SendMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
391 (WPARAM16
)SC_KEYMENU
, (LPARAM
)(DWORD
)wParam
);
393 else /* check for Ctrl-Esc */
394 if (wParam
!= VK_ESCAPE
) MessageBeep(0);
398 if (!lParam
) return 0; /* sent from ShowWindow */
399 if (!(wndPtr
->dwStyle
& WS_POPUP
) || !wndPtr
->owner
) return 0;
400 if ((wndPtr
->dwStyle
& WS_VISIBLE
) && wParam
) return 0;
401 else if (!(wndPtr
->dwStyle
& WS_VISIBLE
) && !wParam
) return 0;
402 ShowWindow( wndPtr
->hwndSelf
, wParam
? SW_SHOWNOACTIVATE
: SW_HIDE
);
406 if (wndPtr
->parent
== WIN_GetDesktop()) EndMenu();
407 if (GetCapture() == wndPtr
->hwndSelf
) ReleaseCapture();
408 WIN_ReleaseDesktop();
418 case WM_QUERYDROPOBJECT
:
419 if (wndPtr
->dwExStyle
& WS_EX_ACCEPTFILES
) return 1;
422 case WM_QUERYDRAGICON
:
427 if( (hIcon
=wndPtr
->class->hCursor
) ) return (LRESULT
)hIcon
;
428 for(len
=1; len
<64; len
++)
429 if((hIcon
=LoadIcon16(wndPtr
->hInstance
,MAKEINTRESOURCE16(len
))))
430 return (LRESULT
)hIcon
;
431 return (LRESULT
)LoadIcon16(0,IDI_APPLICATION16
);
435 case WM_ISACTIVEICON
:
436 return ((wndPtr
->flags
& WIN_NCACTIVATED
) != 0);
438 case WM_NOTIFYFORMAT
:
439 if (IsWindowUnicode(wndPtr
->hwndSelf
)) return NFR_UNICODE
;
440 else return NFR_ANSI
;
443 case WM_QUERYENDSESSION
:
451 /***********************************************************************
452 * DefWindowProc16 (USER.107)
454 LRESULT WINAPI
DefWindowProc16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
457 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
460 if (!wndPtr
) return 0;
461 SPY_EnterMessage( SPY_DEFWNDPROC16
, hwnd
, msg
, wParam
, lParam
);
467 CREATESTRUCT16
*cs
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
);
469 DEFWND_SetText( wndPtr
, (LPSTR
)PTR_SEG_TO_LIN(cs
->lpszName
) );
477 CONV_RECT16TO32( (RECT16
*)PTR_SEG_TO_LIN(lParam
), &rect32
);
478 result
= NC_HandleNCCalcSize( wndPtr
, &rect32
);
479 CONV_RECT32TO16( &rect32
, (RECT16
*)PTR_SEG_TO_LIN(lParam
) );
483 case WM_WINDOWPOSCHANGING
:
484 result
= WINPOS_HandleWindowPosChanging16( wndPtr
,
485 (WINDOWPOS16
*)PTR_SEG_TO_LIN(lParam
) );
488 case WM_WINDOWPOSCHANGED
:
490 WINDOWPOS16
* winPos
= (WINDOWPOS16
*)PTR_SEG_TO_LIN(lParam
);
491 DEFWND_HandleWindowPosChanged( wndPtr
, winPos
->flags
);
496 if (wParam
&& wndPtr
->text
)
498 lstrcpynA( (LPSTR
)PTR_SEG_TO_LIN(lParam
), wndPtr
->text
, wParam
);
499 result
= (LRESULT
)strlen( (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
504 DEFWND_SetText( wndPtr
, (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
505 if( wndPtr
->dwStyle
& WS_CAPTION
) NC_HandleNCPaint( hwnd
, (HRGN
)1 );
509 result
= DEFWND_DefWinProc( wndPtr
, msg
, wParam
, lParam
);
513 WIN_ReleaseWndPtr(wndPtr
);
514 SPY_ExitMessage( SPY_RESULT_DEFWND16
, hwnd
, msg
, result
);
519 /***********************************************************************
520 * DefWindowProc32A [USER32.126]
523 LRESULT WINAPI
DefWindowProcA( HWND hwnd
, UINT msg
, WPARAM wParam
,
526 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
529 if (!wndPtr
) return 0;
530 SPY_EnterMessage( SPY_DEFWNDPROC
, hwnd
, msg
, wParam
, lParam
);
536 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
537 if (cs
->lpszName
) DEFWND_SetText( wndPtr
, cs
->lpszName
);
543 result
= NC_HandleNCCalcSize( wndPtr
, (RECT
*)lParam
);
546 case WM_WINDOWPOSCHANGING
:
547 result
= WINPOS_HandleWindowPosChanging( wndPtr
,
548 (WINDOWPOS
*)lParam
);
551 case WM_WINDOWPOSCHANGED
:
553 WINDOWPOS
* winPos
= (WINDOWPOS
*)lParam
;
554 DEFWND_HandleWindowPosChanged( wndPtr
, winPos
->flags
);
559 if (wParam
&& wndPtr
->text
)
561 lstrcpynA( (LPSTR
)lParam
, wndPtr
->text
, wParam
);
562 result
= (LRESULT
)strlen( (LPSTR
)lParam
);
567 DEFWND_SetText( wndPtr
, (LPSTR
)lParam
);
568 NC_HandleNCPaint( hwnd
, (HRGN
)1 ); /* Repaint caption */
572 result
= DEFWND_DefWinProc( wndPtr
, msg
, wParam
, lParam
);
576 WIN_ReleaseWndPtr(wndPtr
);
577 SPY_ExitMessage( SPY_RESULT_DEFWND
, hwnd
, msg
, result
);
582 /***********************************************************************
583 * DefWindowProc32W [USER32.127] Calls default window message handler
585 * Calls default window procedure for messages not processed
589 * Return value is dependent upon the message.
591 LRESULT WINAPI
DefWindowProcW(
592 HWND hwnd
, /* [in] window procedure recieving message */
593 UINT msg
, /* [in] message identifier */
594 WPARAM wParam
, /* [in] first message parameter */
595 LPARAM lParam
) /* [in] second message parameter */
603 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lParam
;
606 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
607 LPSTR str
= HEAP_strdupWtoA(GetProcessHeap(), 0, cs
->lpszName
);
608 DEFWND_SetText( wndPtr
, str
);
609 HeapFree( GetProcessHeap(), 0, str
);
610 WIN_ReleaseWndPtr(wndPtr
);
618 LPSTR str
= HeapAlloc( GetProcessHeap(), 0, wParam
);
619 result
= DefWindowProcA( hwnd
, msg
, wParam
, (LPARAM
)str
);
620 lstrcpynAtoW( (LPWSTR
)lParam
, str
, wParam
);
621 HeapFree( GetProcessHeap(), 0, str
);
627 LPSTR str
= HEAP_strdupWtoA( GetProcessHeap(), 0, (LPWSTR
)lParam
);
628 result
= DefWindowProcA( hwnd
, msg
, wParam
, (LPARAM
)str
);
629 HeapFree( GetProcessHeap(), 0, str
);
634 result
= DefWindowProcA( hwnd
, msg
, wParam
, lParam
);