2 * Default window procedure
4 * Copyright 1993, 1996 Alexandre Julliard
12 #include "nonclient.h"
15 #include "sysmetrics.h"
21 #define COLOR_MAX COLOR_BTNHIGHLIGHT
23 /* bits in the dwKeyData */
24 #define KEYDATA_ALT 0x2000
25 #define KEYDATA_PREVSTATE 0x4000
27 static short iF10Key
= 0;
28 static short iMenuSysKey
= 0;
30 /***********************************************************************
31 * DEFWND_HandleWindowPosChanged
33 * Handle the WM_WINDOWPOSCHANGED message.
35 static void DEFWND_HandleWindowPosChanged( WND
*wndPtr
, UINT32 flags
)
37 WPARAM16 wp
= SIZE_RESTORED
;
39 if (!(flags
& SWP_NOCLIENTMOVE
))
40 SendMessage16( wndPtr
->hwndSelf
, WM_MOVE
, 0,
41 MAKELONG(wndPtr
->rectClient
.left
, wndPtr
->rectClient
.top
));
42 if (!(flags
& SWP_NOCLIENTSIZE
))
44 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wp
= SIZE_MAXIMIZED
;
45 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wp
= SIZE_MINIMIZED
;
47 SendMessage16( wndPtr
->hwndSelf
, WM_SIZE
, wp
,
48 MAKELONG(wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
49 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
));
54 /***********************************************************************
57 * Set the window text.
59 void DEFWND_SetText( WND
*wndPtr
, LPCSTR text
)
62 if (wndPtr
->text
) HeapFree( SystemHeap
, 0, wndPtr
->text
);
63 wndPtr
->text
= HEAP_strdupA( SystemHeap
, 0, text
);
64 wndPtr
->pDriver
->pSetText(wndPtr
, wndPtr
->text
);
67 /***********************************************************************
70 * Default colors for control painting.
72 HBRUSH32
DEFWND_ControlColor( HDC32 hDC
, UINT16 ctlType
)
74 if( ctlType
== CTLCOLOR_SCROLLBAR
)
76 HBRUSH32 hb
= GetSysColorBrush32(COLOR_SCROLLBAR
);
77 SetBkColor32( hDC
, RGB(255, 255, 255) );
78 SetTextColor32( hDC
, RGB(0, 0, 0) );
79 UnrealizeObject32( hb
);
83 SetTextColor32( hDC
, GetSysColor32(COLOR_WINDOWTEXT
));
85 if (TWEAK_WineLook
> WIN31_LOOK
) {
86 if ((ctlType
== CTLCOLOR_EDIT
) || (ctlType
== CTLCOLOR_LISTBOX
))
87 SetBkColor32( hDC
, GetSysColor32(COLOR_WINDOW
) );
89 SetBkColor32( hDC
, GetSysColor32(COLOR_3DFACE
) );
90 return GetSysColorBrush32(COLOR_3DFACE
);
94 SetBkColor32( hDC
, GetSysColor32(COLOR_WINDOW
) );
95 return GetSysColorBrush32(COLOR_WINDOW
);
99 /***********************************************************************
102 static void DEFWND_SetRedraw( WND
* wndPtr
, WPARAM32 wParam
)
104 BOOL32 bVisible
= wndPtr
->dwStyle
& WS_VISIBLE
;
106 TRACE(win
,"%04x %i\n", wndPtr
->hwndSelf
, (wParam
!=0) );
112 wndPtr
->dwStyle
|= WS_VISIBLE
;
113 DCE_InvalidateDCE( wndPtr
, &wndPtr
->rectWindow
);
118 if( wndPtr
->dwStyle
& WS_MINIMIZE
) wParam
= RDW_VALIDATE
;
119 else wParam
= RDW_ALLCHILDREN
| RDW_VALIDATE
;
121 PAINT_RedrawWindow( wndPtr
->hwndSelf
, NULL
, 0, wParam
, 0 );
122 DCE_InvalidateDCE( wndPtr
, &wndPtr
->rectWindow
);
123 wndPtr
->dwStyle
&= ~WS_VISIBLE
;
127 /***********************************************************************
130 * Default window procedure for messages that are the same in Win16 and Win32.
132 static LRESULT
DEFWND_DefWinProc( WND
*wndPtr
, UINT32 msg
, WPARAM32 wParam
,
138 return NC_HandleNCPaint( wndPtr
->hwndSelf
, (HRGN32
)wParam
);
141 return NC_HandleNCHitTest( wndPtr
->hwndSelf
, MAKEPOINT16(lParam
) );
143 case WM_NCLBUTTONDOWN
:
144 return NC_HandleNCLButtonDown( wndPtr
, wParam
, lParam
);
146 case WM_LBUTTONDBLCLK
:
147 case WM_NCLBUTTONDBLCLK
:
148 return NC_HandleNCLButtonDblClk( wndPtr
, wParam
, lParam
);
151 case WM_NCRBUTTONDOWN
:
152 if ((wndPtr
->flags
& WIN_ISWIN32
) || (TWEAK_WineLook
> WIN31_LOOK
))
154 ClientToScreen16(wndPtr
->hwndSelf
, (LPPOINT16
)&lParam
);
155 SendMessage32A( wndPtr
->hwndSelf
, WM_CONTEXTMENU
,
156 wndPtr
->hwndSelf
, lParam
);
161 if( wndPtr
->dwStyle
& WS_CHILD
)
162 SendMessage32A( wndPtr
->parent
->hwndSelf
, msg
, wParam
, lParam
);
164 if (wndPtr
->hSysMenu
)
166 TrackPopupMenu32(wndPtr->hSysMenu,TPM_LEFTALIGN | TPM_RETURNCMD,LOWORD(lParam),HIWORD(lParam),0,wndPtr->hwndSelf,NULL);
167 DestroyMenu32(wndPtr->hSysMenu);
169 FIXME(win
,"Display default popup menu\n");
170 /* Track system popup if click was in the caption area. */
175 return NC_HandleNCActivate( wndPtr
, wParam
);
178 if (wndPtr
->text
) HeapFree( SystemHeap
, 0, wndPtr
->text
);
180 if (wndPtr
->pVScroll
) HeapFree( SystemHeap
, 0, wndPtr
->pVScroll
);
181 if (wndPtr
->pHScroll
) HeapFree( SystemHeap
, 0, wndPtr
->pHScroll
);
182 wndPtr
->pVScroll
= wndPtr
->pHScroll
= NULL
;
189 HDC16 hdc
= BeginPaint16( wndPtr
->hwndSelf
, &ps
);
192 if( (wndPtr
->dwStyle
& WS_MINIMIZE
) && wndPtr
->class->hIcon
)
194 int x
= (wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
-
195 SYSMETRICS_CXICON
)/2;
196 int y
= (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
-
197 SYSMETRICS_CYICON
)/2;
198 TRACE(win
,"Painting class icon: vis rect=(%i,%i - %i,%i)\n",
199 ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
200 DrawIcon32( hdc
, x
, y
, wndPtr
->class->hIcon
);
202 EndPaint16( wndPtr
->hwndSelf
, &ps
);
208 DEFWND_SetRedraw( wndPtr
, wParam
);
212 DestroyWindow32( wndPtr
->hwndSelf
);
215 case WM_MOUSEACTIVATE
:
216 if (wndPtr
->dwStyle
& WS_CHILD
)
218 LONG ret
= SendMessage16( wndPtr
->parent
->hwndSelf
,
219 WM_MOUSEACTIVATE
, wParam
, lParam
);
223 /* Caption clicks are handled by the NC_HandleNCLButtonDown() */
224 return (LOWORD(lParam
) == HTCAPTION
) ? MA_NOACTIVATE
: MA_ACTIVATE
;
227 if (LOWORD(wParam
) != WA_INACTIVE
)
228 SetWindowPos32(wndPtr
->hwndSelf
, HWND_TOP
, 0, 0, 0, 0,
229 SWP_NOMOVE
| SWP_NOSIZE
);
233 case WM_ICONERASEBKGND
:
235 if (!wndPtr
->class->hbrBackground
) return 0;
237 if (wndPtr
->class->hbrBackground
<= (HBRUSH16
)(COLOR_MAX
+1))
239 HBRUSH32 hbrush
= CreateSolidBrush32(
240 GetSysColor32(((DWORD
)wndPtr
->class->hbrBackground
)-1));
241 FillWindow( GetParent16(wndPtr
->hwndSelf
), wndPtr
->hwndSelf
,
242 (HDC16
)wParam
, hbrush
);
243 DeleteObject32( hbrush
);
245 else FillWindow( GetParent16(wndPtr
->hwndSelf
), wndPtr
->hwndSelf
,
246 (HDC16
)wParam
, wndPtr
->class->hbrBackground
);
253 case WM_CTLCOLORMSGBOX
:
254 case WM_CTLCOLOREDIT
:
255 case WM_CTLCOLORLISTBOX
:
258 case WM_CTLCOLORSTATIC
:
259 case WM_CTLCOLORSCROLLBAR
:
260 return (LRESULT
)DEFWND_ControlColor( (HDC32
)wParam
, msg
- WM_CTLCOLORMSGBOX
);
263 return (LRESULT
)DEFWND_ControlColor( (HDC32
)wParam
, HIWORD(lParam
) );
265 case WM_GETTEXTLENGTH
:
266 if (wndPtr
->text
) return (LRESULT
)strlen(wndPtr
->text
);
270 if (wndPtr
->dwStyle
& WS_CHILD
)
271 if (SendMessage16(wndPtr
->parent
->hwndSelf
, WM_SETCURSOR
,
274 return NC_HandleSetCursor( wndPtr
->hwndSelf
, wParam
, lParam
);
277 return NC_HandleSysCommand( wndPtr
->hwndSelf
, wParam
,
278 MAKEPOINT16(lParam
) );
281 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
285 if( HIWORD(lParam
) & KEYDATA_ALT
)
287 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
288 if( wParam
== VK_MENU
&& !iMenuSysKey
)
295 if( wParam
== VK_F4
) /* try to close the window */
297 HWND32 hWnd
= WIN_GetTopParent( wndPtr
->hwndSelf
);
298 wndPtr
= WIN_FindWndPtr( hWnd
);
299 if( wndPtr
&& !(wndPtr
->class->style
& CS_NOCLOSE
) )
300 PostMessage16( hWnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0 );
303 else if( wParam
== VK_F10
)
306 if( wParam
== VK_ESCAPE
&& (GetKeyState32(VK_SHIFT
) & 0x8000))
307 SendMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
308 (WPARAM16
)SC_KEYMENU
, (LPARAM
)VK_SPACE
);
313 /* Press and release F10 or ALT */
314 if (((wParam
== VK_MENU
) && iMenuSysKey
) ||
315 ((wParam
== VK_F10
) && iF10Key
))
316 SendMessage16( WIN_GetTopParent(wndPtr
->hwndSelf
),
317 WM_SYSCOMMAND
, SC_KEYMENU
, 0L );
318 iMenuSysKey
= iF10Key
= 0;
323 if (wParam
== VK_RETURN
&& (wndPtr
->dwStyle
& WS_MINIMIZE
))
325 PostMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
326 (WPARAM16
)SC_RESTORE
, 0L );
329 if ((HIWORD(lParam
) & KEYDATA_ALT
) && wParam
)
331 if (wParam
== VK_TAB
|| wParam
== VK_ESCAPE
) break;
332 if (wParam
== VK_SPACE
&& (wndPtr
->dwStyle
& WS_CHILD
))
333 SendMessage16( wndPtr
->parent
->hwndSelf
, msg
, wParam
, lParam
);
335 SendMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
336 (WPARAM16
)SC_KEYMENU
, (LPARAM
)(DWORD
)wParam
);
338 else /* check for Ctrl-Esc */
339 if (wParam
!= VK_ESCAPE
) MessageBeep32(0);
343 if (!lParam
) return 0; /* sent from ShowWindow */
344 if (!(wndPtr
->dwStyle
& WS_POPUP
) || !wndPtr
->owner
) return 0;
345 if ((wndPtr
->dwStyle
& WS_VISIBLE
) && wParam
) return 0;
346 else if (!(wndPtr
->dwStyle
& WS_VISIBLE
) && !wParam
) return 0;
347 ShowWindow32( wndPtr
->hwndSelf
, wParam
? SW_SHOWNOACTIVATE
: SW_HIDE
);
351 if (wndPtr
->parent
== WIN_GetDesktop()) EndMenu();
352 if (GetCapture32() == wndPtr
->hwndSelf
) ReleaseCapture();
362 case WM_QUERYDROPOBJECT
:
363 if (wndPtr
->dwExStyle
& WS_EX_ACCEPTFILES
) return 1;
366 case WM_QUERYDRAGICON
:
371 if( (hIcon
=wndPtr
->class->hCursor
) ) return (LRESULT
)hIcon
;
372 for(len
=1; len
<64; len
++)
373 if((hIcon
=LoadIcon16(wndPtr
->hInstance
,MAKEINTRESOURCE16(len
))))
374 return (LRESULT
)hIcon
;
375 return (LRESULT
)LoadIcon16(0,IDI_APPLICATION16
);
379 case WM_ISACTIVEICON
:
380 return ((wndPtr
->flags
& WIN_NCACTIVATED
) != 0);
383 case WM_QUERYENDSESSION
:
391 /***********************************************************************
392 * DefWindowProc16 (USER.107)
394 LRESULT WINAPI
DefWindowProc16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
397 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
400 if (!wndPtr
) return 0;
401 SPY_EnterMessage( SPY_DEFWNDPROC16
, hwnd
, msg
, wParam
, lParam
);
407 CREATESTRUCT16
*cs
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
);
409 DEFWND_SetText( wndPtr
, (LPSTR
)PTR_SEG_TO_LIN(cs
->lpszName
) );
417 CONV_RECT16TO32( (RECT16
*)PTR_SEG_TO_LIN(lParam
), &rect32
);
418 result
= NC_HandleNCCalcSize( wndPtr
, &rect32
);
419 CONV_RECT32TO16( &rect32
, (RECT16
*)PTR_SEG_TO_LIN(lParam
) );
423 case WM_WINDOWPOSCHANGING
:
424 result
= WINPOS_HandleWindowPosChanging16( wndPtr
,
425 (WINDOWPOS16
*)PTR_SEG_TO_LIN(lParam
) );
428 case WM_WINDOWPOSCHANGED
:
430 WINDOWPOS16
* winPos
= (WINDOWPOS16
*)PTR_SEG_TO_LIN(lParam
);
431 DEFWND_HandleWindowPosChanged( wndPtr
, winPos
->flags
);
436 if (wParam
&& wndPtr
->text
)
438 lstrcpyn32A( (LPSTR
)PTR_SEG_TO_LIN(lParam
), wndPtr
->text
, wParam
);
439 result
= (LRESULT
)strlen( (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
444 DEFWND_SetText( wndPtr
, (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
445 if( wndPtr
->dwStyle
& WS_CAPTION
) NC_HandleNCPaint( hwnd
, (HRGN32
)1 );
449 result
= DEFWND_DefWinProc( wndPtr
, msg
, wParam
, lParam
);
453 SPY_ExitMessage( SPY_RESULT_DEFWND16
, hwnd
, msg
, result
);
458 /***********************************************************************
459 * DefWindowProc32A [USER32.126]
462 LRESULT WINAPI
DefWindowProc32A( HWND32 hwnd
, UINT32 msg
, WPARAM32 wParam
,
465 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
468 if (!wndPtr
) return 0;
469 SPY_EnterMessage( SPY_DEFWNDPROC32
, hwnd
, msg
, wParam
, lParam
);
475 CREATESTRUCT32A
*cs
= (CREATESTRUCT32A
*)lParam
;
476 if (cs
->lpszName
) DEFWND_SetText( wndPtr
, cs
->lpszName
);
482 result
= NC_HandleNCCalcSize( wndPtr
, (RECT32
*)lParam
);
485 case WM_WINDOWPOSCHANGING
:
486 result
= WINPOS_HandleWindowPosChanging32( wndPtr
,
487 (WINDOWPOS32
*)lParam
);
490 case WM_WINDOWPOSCHANGED
:
492 WINDOWPOS32
* winPos
= (WINDOWPOS32
*)lParam
;
493 DEFWND_HandleWindowPosChanged( wndPtr
, winPos
->flags
);
498 if (wParam
&& wndPtr
->text
)
500 lstrcpyn32A( (LPSTR
)lParam
, wndPtr
->text
, wParam
);
501 result
= (LRESULT
)strlen( (LPSTR
)lParam
);
506 DEFWND_SetText( wndPtr
, (LPSTR
)lParam
);
507 NC_HandleNCPaint( hwnd
, (HRGN32
)1 ); /* Repaint caption */
511 result
= DEFWND_DefWinProc( wndPtr
, msg
, wParam
, lParam
);
515 SPY_ExitMessage( SPY_RESULT_DEFWND32
, hwnd
, msg
, result
);
520 /***********************************************************************
521 * DefWindowProc32W [USER32.127] Calls default window message handler
523 * Calls default window procedure for messages not processed
527 * Return value is dependent upon the message.
529 LRESULT WINAPI
DefWindowProc32W(
530 HWND32 hwnd
, /* [in] window procedure recieving message */
531 UINT32 msg
, /* [in] message identifier */
532 WPARAM32 wParam
, /* [in] first message parameter */
533 LPARAM lParam
) /* [in] second message parameter */
541 CREATESTRUCT32W
*cs
= (CREATESTRUCT32W
*)lParam
;
544 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
545 LPSTR str
= HEAP_strdupWtoA(GetProcessHeap(), 0, cs
->lpszName
);
546 DEFWND_SetText( wndPtr
, str
);
547 HeapFree( GetProcessHeap(), 0, str
);
555 LPSTR str
= HeapAlloc( GetProcessHeap(), 0, wParam
);
556 result
= DefWindowProc32A( hwnd
, msg
, wParam
, (LPARAM
)str
);
557 lstrcpynAtoW( (LPWSTR
)lParam
, str
, wParam
);
558 HeapFree( GetProcessHeap(), 0, str
);
564 LPSTR str
= HEAP_strdupWtoA( GetProcessHeap(), 0, (LPWSTR
)lParam
);
565 result
= DefWindowProc32A( hwnd
, msg
, wParam
, (LPARAM
)str
);
566 HeapFree( GetProcessHeap(), 0, str
);
571 result
= DefWindowProc32A( hwnd
, msg
, wParam
, lParam
);