2 * Default window procedure
4 * Copyright 1993, 1996 Alexandre Julliard
13 #include "nonclient.h"
16 #include "sysmetrics.h"
20 #include "wine/winuser16.h"
22 DEFAULT_DEBUG_CHANNEL(win
)
25 #define COLOR_MAX COLOR_BTNHIGHLIGHT
27 /* bits in the dwKeyData */
28 #define KEYDATA_ALT 0x2000
29 #define KEYDATA_PREVSTATE 0x4000
31 static short iF10Key
= 0;
32 static short iMenuSysKey
= 0;
34 /***********************************************************************
35 * DEFWND_HandleWindowPosChanged
37 * Handle the WM_WINDOWPOSCHANGED message.
39 static void DEFWND_HandleWindowPosChanged( WND
*wndPtr
, UINT flags
)
41 WPARAM16 wp
= SIZE_RESTORED
;
43 if (!(flags
& SWP_NOCLIENTMOVE
))
44 SendMessage16( wndPtr
->hwndSelf
, WM_MOVE
, 0,
45 MAKELONG(wndPtr
->rectClient
.left
, wndPtr
->rectClient
.top
));
46 if (!(flags
& SWP_NOCLIENTSIZE
))
48 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wp
= SIZE_MAXIMIZED
;
49 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wp
= SIZE_MINIMIZED
;
51 SendMessage16( wndPtr
->hwndSelf
, WM_SIZE
, wp
,
52 MAKELONG(wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
53 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
));
58 /***********************************************************************
61 * Set the window text.
63 void DEFWND_SetText( WND
*wndPtr
, LPCSTR text
)
66 if (wndPtr
->text
) HeapFree( SystemHeap
, 0, wndPtr
->text
);
67 wndPtr
->text
= HEAP_strdupA( SystemHeap
, 0, text
);
68 wndPtr
->pDriver
->pSetText(wndPtr
, wndPtr
->text
);
71 /***********************************************************************
74 * Default colors for control painting.
76 HBRUSH
DEFWND_ControlColor( HDC hDC
, UINT16 ctlType
)
78 if( ctlType
== CTLCOLOR_SCROLLBAR
)
80 HBRUSH hb
= GetSysColorBrush(COLOR_SCROLLBAR
);
81 SetBkColor( hDC
, RGB(255, 255, 255) );
82 SetTextColor( hDC
, RGB(0, 0, 0) );
83 UnrealizeObject( hb
);
87 SetTextColor( hDC
, GetSysColor(COLOR_WINDOWTEXT
));
89 if (TWEAK_WineLook
> WIN31_LOOK
) {
90 if ((ctlType
== CTLCOLOR_EDIT
) || (ctlType
== CTLCOLOR_LISTBOX
))
91 SetBkColor( hDC
, GetSysColor(COLOR_WINDOW
) );
93 SetBkColor( hDC
, GetSysColor(COLOR_3DFACE
) );
94 return GetSysColorBrush(COLOR_3DFACE
);
98 SetBkColor( hDC
, GetSysColor(COLOR_WINDOW
) );
99 return GetSysColorBrush(COLOR_WINDOW
);
103 /***********************************************************************
106 static void DEFWND_SetRedraw( WND
* wndPtr
, WPARAM wParam
)
108 BOOL bVisible
= wndPtr
->dwStyle
& WS_VISIBLE
;
110 TRACE(win
,"%04x %i\n", wndPtr
->hwndSelf
, (wParam
!=0) );
116 wndPtr
->dwStyle
|= WS_VISIBLE
;
117 DCE_InvalidateDCE( wndPtr
, &wndPtr
->rectWindow
);
122 if( wndPtr
->dwStyle
& WS_MINIMIZE
) wParam
= RDW_VALIDATE
;
123 else wParam
= RDW_ALLCHILDREN
| RDW_VALIDATE
;
125 PAINT_RedrawWindow( wndPtr
->hwndSelf
, NULL
, 0, wParam
, 0 );
126 DCE_InvalidateDCE( wndPtr
, &wndPtr
->rectWindow
);
127 wndPtr
->dwStyle
&= ~WS_VISIBLE
;
131 /***********************************************************************
134 * This method handles the default behavior for the WM_PRINT message.
136 static void DEFWND_Print(
144 if ( (uFlags
& PRF_CHECKVISIBLE
) &&
145 !IsWindowVisible(wndPtr
->hwndSelf
) )
149 * Unimplemented flags.
151 if ( (uFlags
& PRF_CHILDREN
) ||
152 (uFlags
& PRF_OWNED
) ||
153 (uFlags
& PRF_NONCLIENT
) )
155 WARN(win
,"WM_PRINT message with unsupported flags\n");
161 if ( uFlags
& PRF_ERASEBKGND
)
162 SendMessageA(wndPtr
->hwndSelf
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
167 if ( uFlags
& PRF_CLIENT
)
168 SendMessageA(wndPtr
->hwndSelf
, WM_PRINTCLIENT
, (WPARAM
)hdc
, PRF_CLIENT
);
171 /***********************************************************************
174 * Default window procedure for messages that are the same in Win16 and Win32.
176 static LRESULT
DEFWND_DefWinProc( WND
*wndPtr
, UINT msg
, WPARAM wParam
,
182 return NC_HandleNCPaint( wndPtr
->hwndSelf
, (HRGN
)wParam
);
185 return NC_HandleNCHitTest( wndPtr
->hwndSelf
, MAKEPOINT16(lParam
) );
187 case WM_NCLBUTTONDOWN
:
188 return NC_HandleNCLButtonDown( wndPtr
, wParam
, lParam
);
190 case WM_LBUTTONDBLCLK
:
191 case WM_NCLBUTTONDBLCLK
:
192 return NC_HandleNCLButtonDblClk( wndPtr
, wParam
, lParam
);
195 case WM_NCRBUTTONDOWN
:
196 if ((wndPtr
->flags
& WIN_ISWIN32
) || (TWEAK_WineLook
> WIN31_LOOK
))
198 ClientToScreen16(wndPtr
->hwndSelf
, (LPPOINT16
)&lParam
);
199 SendMessageA( wndPtr
->hwndSelf
, WM_CONTEXTMENU
,
200 wndPtr
->hwndSelf
, lParam
);
205 if( wndPtr
->dwStyle
& WS_CHILD
)
206 SendMessageA( wndPtr
->parent
->hwndSelf
, msg
, wParam
, lParam
);
208 if (wndPtr
->hSysMenu
)
210 TrackPopupMenu32(wndPtr->hSysMenu,TPM_LEFTALIGN | TPM_RETURNCMD,LOWORD(lParam),HIWORD(lParam),0,wndPtr->hwndSelf,NULL);
211 DestroyMenu32(wndPtr->hSysMenu);
213 FIXME(win
,"Display default popup menu\n");
214 /* Track system popup if click was in the caption area. */
219 return NC_HandleNCActivate( wndPtr
, wParam
);
222 if (wndPtr
->text
) HeapFree( SystemHeap
, 0, wndPtr
->text
);
224 if (wndPtr
->pVScroll
) HeapFree( SystemHeap
, 0, wndPtr
->pVScroll
);
225 if (wndPtr
->pHScroll
) HeapFree( SystemHeap
, 0, wndPtr
->pHScroll
);
226 wndPtr
->pVScroll
= wndPtr
->pHScroll
= NULL
;
230 DEFWND_Print(wndPtr
, (HDC
)wParam
, lParam
);
237 HDC16 hdc
= BeginPaint16( wndPtr
->hwndSelf
, &ps
);
240 if( (wndPtr
->dwStyle
& WS_MINIMIZE
) && wndPtr
->class->hIcon
)
242 int x
= (wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
-
243 SYSMETRICS_CXICON
)/2;
244 int y
= (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
-
245 SYSMETRICS_CYICON
)/2;
246 TRACE(win
,"Painting class icon: vis rect=(%i,%i - %i,%i)\n",
247 ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
248 DrawIcon( hdc
, x
, y
, wndPtr
->class->hIcon
);
250 EndPaint16( wndPtr
->hwndSelf
, &ps
);
256 DEFWND_SetRedraw( wndPtr
, wParam
);
260 DestroyWindow( wndPtr
->hwndSelf
);
263 case WM_MOUSEACTIVATE
:
264 if (wndPtr
->dwStyle
& WS_CHILD
)
266 LONG ret
= SendMessage16( wndPtr
->parent
->hwndSelf
,
267 WM_MOUSEACTIVATE
, wParam
, lParam
);
271 /* Caption clicks are handled by the NC_HandleNCLButtonDown() */
272 return (LOWORD(lParam
) == HTCAPTION
) ? MA_NOACTIVATE
: MA_ACTIVATE
;
275 /* The default action in Windows is to set the keyboard focus to
276 * the window, if it's being activated and not minimized */
277 if (LOWORD(wParam
) != WA_INACTIVE
) {
278 /* I don't know who put this SetWindowPos here, it does not
279 * seem very logical to have it here... (FIXME?) */
280 SetWindowPos(wndPtr
->hwndSelf
, HWND_TOP
, 0, 0, 0, 0,
281 SWP_NOMOVE
| SWP_NOSIZE
);
282 if (!(wndPtr
->dwStyle
& WS_MINIMIZE
))
283 SetFocus(wndPtr
->hwndSelf
);
288 case WM_ICONERASEBKGND
:
290 if (!wndPtr
->class->hbrBackground
) return 0;
292 if (wndPtr
->class->hbrBackground
<= (HBRUSH16
)(COLOR_MAX
+1))
294 HBRUSH hbrush
= CreateSolidBrush(
295 GetSysColor(((DWORD
)wndPtr
->class->hbrBackground
)-1));
296 FillWindow16( GetParent16(wndPtr
->hwndSelf
), wndPtr
->hwndSelf
,
297 (HDC16
)wParam
, hbrush
);
298 DeleteObject( hbrush
);
300 else FillWindow16( GetParent16(wndPtr
->hwndSelf
), wndPtr
->hwndSelf
,
301 (HDC16
)wParam
, wndPtr
->class->hbrBackground
);
308 case WM_CTLCOLORMSGBOX
:
309 case WM_CTLCOLOREDIT
:
310 case WM_CTLCOLORLISTBOX
:
313 case WM_CTLCOLORSTATIC
:
314 case WM_CTLCOLORSCROLLBAR
:
315 return (LRESULT
)DEFWND_ControlColor( (HDC
)wParam
, msg
- WM_CTLCOLORMSGBOX
);
318 return (LRESULT
)DEFWND_ControlColor( (HDC
)wParam
, HIWORD(lParam
) );
320 case WM_GETTEXTLENGTH
:
321 if (wndPtr
->text
) return (LRESULT
)strlen(wndPtr
->text
);
325 if (wndPtr
->dwStyle
& WS_CHILD
)
326 if (SendMessage16(wndPtr
->parent
->hwndSelf
, WM_SETCURSOR
,
329 return NC_HandleSetCursor( wndPtr
->hwndSelf
, wParam
, lParam
);
332 return NC_HandleSysCommand( wndPtr
->hwndSelf
, wParam
,
333 MAKEPOINT16(lParam
) );
336 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
340 if( HIWORD(lParam
) & KEYDATA_ALT
)
342 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
343 if( wParam
== VK_MENU
&& !iMenuSysKey
)
350 if( wParam
== VK_F4
) /* try to close the window */
352 HWND hWnd
= WIN_GetTopParent( wndPtr
->hwndSelf
);
353 wndPtr
= WIN_FindWndPtr( hWnd
);
354 if( wndPtr
&& !(wndPtr
->class->style
& CS_NOCLOSE
) )
355 PostMessage16( hWnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0 );
356 WIN_ReleaseWndPtr(wndPtr
);
359 else if( wParam
== VK_F10
)
362 if( wParam
== VK_ESCAPE
&& (GetKeyState(VK_SHIFT
) & 0x8000))
363 SendMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
364 (WPARAM16
)SC_KEYMENU
, (LPARAM
)VK_SPACE
);
369 /* Press and release F10 or ALT */
370 if (((wParam
== VK_MENU
) && iMenuSysKey
) ||
371 ((wParam
== VK_F10
) && iF10Key
))
372 SendMessage16( WIN_GetTopParent(wndPtr
->hwndSelf
),
373 WM_SYSCOMMAND
, SC_KEYMENU
, 0L );
374 iMenuSysKey
= iF10Key
= 0;
379 if (wParam
== VK_RETURN
&& (wndPtr
->dwStyle
& WS_MINIMIZE
))
381 PostMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
382 (WPARAM16
)SC_RESTORE
, 0L );
385 if ((HIWORD(lParam
) & KEYDATA_ALT
) && wParam
)
387 if (wParam
== VK_TAB
|| wParam
== VK_ESCAPE
) break;
388 if (wParam
== VK_SPACE
&& (wndPtr
->dwStyle
& WS_CHILD
))
389 SendMessage16( wndPtr
->parent
->hwndSelf
, msg
, wParam
, lParam
);
391 SendMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
392 (WPARAM16
)SC_KEYMENU
, (LPARAM
)(DWORD
)wParam
);
394 else /* check for Ctrl-Esc */
395 if (wParam
!= VK_ESCAPE
) MessageBeep(0);
399 if (!lParam
) return 0; /* sent from ShowWindow */
400 if (!(wndPtr
->dwStyle
& WS_POPUP
) || !wndPtr
->owner
) return 0;
401 if ((wndPtr
->dwStyle
& WS_VISIBLE
) && wParam
) return 0;
402 else if (!(wndPtr
->dwStyle
& WS_VISIBLE
) && !wParam
) return 0;
403 ShowWindow( wndPtr
->hwndSelf
, wParam
? SW_SHOWNOACTIVATE
: SW_HIDE
);
407 if (wndPtr
->parent
== WIN_GetDesktop()) EndMenu();
408 if (GetCapture() == wndPtr
->hwndSelf
) ReleaseCapture();
409 WIN_ReleaseDesktop();
419 case WM_QUERYDROPOBJECT
:
420 if (wndPtr
->dwExStyle
& WS_EX_ACCEPTFILES
) return 1;
423 case WM_QUERYDRAGICON
:
428 if( (hIcon
=wndPtr
->class->hCursor
) ) return (LRESULT
)hIcon
;
429 for(len
=1; len
<64; len
++)
430 if((hIcon
=LoadIcon16(wndPtr
->hInstance
,MAKEINTRESOURCE16(len
))))
431 return (LRESULT
)hIcon
;
432 return (LRESULT
)LoadIcon16(0,IDI_APPLICATION16
);
436 case WM_ISACTIVEICON
:
437 return ((wndPtr
->flags
& WIN_NCACTIVATED
) != 0);
439 case WM_NOTIFYFORMAT
:
440 if (IsWindowUnicode(wndPtr
->hwndSelf
)) return NFR_UNICODE
;
441 else return NFR_ANSI
;
444 case WM_QUERYENDSESSION
:
452 /***********************************************************************
453 * DefWindowProc16 (USER.107)
455 LRESULT WINAPI
DefWindowProc16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
458 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
461 if (!wndPtr
) return 0;
462 SPY_EnterMessage( SPY_DEFWNDPROC16
, hwnd
, msg
, wParam
, lParam
);
468 CREATESTRUCT16
*cs
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
);
470 DEFWND_SetText( wndPtr
, (LPSTR
)PTR_SEG_TO_LIN(cs
->lpszName
) );
478 CONV_RECT16TO32( (RECT16
*)PTR_SEG_TO_LIN(lParam
), &rect32
);
479 result
= NC_HandleNCCalcSize( wndPtr
, &rect32
);
480 CONV_RECT32TO16( &rect32
, (RECT16
*)PTR_SEG_TO_LIN(lParam
) );
484 case WM_WINDOWPOSCHANGING
:
485 result
= WINPOS_HandleWindowPosChanging16( wndPtr
,
486 (WINDOWPOS16
*)PTR_SEG_TO_LIN(lParam
) );
489 case WM_WINDOWPOSCHANGED
:
491 WINDOWPOS16
* winPos
= (WINDOWPOS16
*)PTR_SEG_TO_LIN(lParam
);
492 DEFWND_HandleWindowPosChanged( wndPtr
, winPos
->flags
);
497 if (wParam
&& wndPtr
->text
)
499 lstrcpynA( (LPSTR
)PTR_SEG_TO_LIN(lParam
), wndPtr
->text
, wParam
);
500 result
= (LRESULT
)strlen( (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
505 DEFWND_SetText( wndPtr
, (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
506 if( wndPtr
->dwStyle
& WS_CAPTION
) NC_HandleNCPaint( hwnd
, (HRGN
)1 );
510 result
= DEFWND_DefWinProc( wndPtr
, msg
, wParam
, lParam
);
514 WIN_ReleaseWndPtr(wndPtr
);
515 SPY_ExitMessage( SPY_RESULT_DEFWND16
, hwnd
, msg
, result
);
520 /***********************************************************************
521 * DefWindowProc32A [USER32.126]
524 LRESULT WINAPI
DefWindowProcA( HWND hwnd
, UINT msg
, WPARAM wParam
,
527 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
530 if (!wndPtr
) return 0;
531 SPY_EnterMessage( SPY_DEFWNDPROC
, hwnd
, msg
, wParam
, lParam
);
537 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
538 if (cs
->lpszName
) DEFWND_SetText( wndPtr
, cs
->lpszName
);
544 result
= NC_HandleNCCalcSize( wndPtr
, (RECT
*)lParam
);
547 case WM_WINDOWPOSCHANGING
:
548 result
= WINPOS_HandleWindowPosChanging( wndPtr
,
549 (WINDOWPOS
*)lParam
);
552 case WM_WINDOWPOSCHANGED
:
554 WINDOWPOS
* winPos
= (WINDOWPOS
*)lParam
;
555 DEFWND_HandleWindowPosChanged( wndPtr
, winPos
->flags
);
560 if (wParam
&& wndPtr
->text
)
562 lstrcpynA( (LPSTR
)lParam
, wndPtr
->text
, wParam
);
563 result
= (LRESULT
)strlen( (LPSTR
)lParam
);
568 DEFWND_SetText( wndPtr
, (LPSTR
)lParam
);
569 NC_HandleNCPaint( hwnd
, (HRGN
)1 ); /* Repaint caption */
573 result
= DEFWND_DefWinProc( wndPtr
, msg
, wParam
, lParam
);
577 WIN_ReleaseWndPtr(wndPtr
);
578 SPY_ExitMessage( SPY_RESULT_DEFWND
, hwnd
, msg
, result
);
583 /***********************************************************************
584 * DefWindowProc32W [USER32.127] Calls default window message handler
586 * Calls default window procedure for messages not processed
590 * Return value is dependent upon the message.
592 LRESULT WINAPI
DefWindowProcW(
593 HWND hwnd
, /* [in] window procedure recieving message */
594 UINT msg
, /* [in] message identifier */
595 WPARAM wParam
, /* [in] first message parameter */
596 LPARAM lParam
) /* [in] second message parameter */
604 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lParam
;
607 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
608 LPSTR str
= HEAP_strdupWtoA(GetProcessHeap(), 0, cs
->lpszName
);
609 DEFWND_SetText( wndPtr
, str
);
610 HeapFree( GetProcessHeap(), 0, str
);
611 WIN_ReleaseWndPtr(wndPtr
);
619 LPSTR str
= HeapAlloc( GetProcessHeap(), 0, wParam
);
620 result
= DefWindowProcA( hwnd
, msg
, wParam
, (LPARAM
)str
);
621 lstrcpynAtoW( (LPWSTR
)lParam
, str
, wParam
);
622 HeapFree( GetProcessHeap(), 0, str
);
628 LPSTR str
= HEAP_strdupWtoA( GetProcessHeap(), 0, (LPWSTR
)lParam
);
629 result
= DefWindowProcA( hwnd
, msg
, wParam
, (LPARAM
)str
);
630 HeapFree( GetProcessHeap(), 0, str
);
635 result
= DefWindowProcA( hwnd
, msg
, wParam
, lParam
);