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
);
66 TSXStoreName( display
, wndPtr
->window
, wndPtr
->text
);
67 TSXSetIconName( display
, wndPtr
->window
, wndPtr
->text
);
71 /***********************************************************************
74 * Default colors for control painting.
76 HBRUSH32
DEFWND_ControlColor( HDC32 hDC
, UINT16 ctlType
)
78 if( ctlType
== CTLCOLOR_SCROLLBAR
)
80 HBRUSH32 hb
= GetSysColorBrush32(COLOR_SCROLLBAR
);
81 SetBkColor32( hDC
, RGB(255, 255, 255) );
82 SetTextColor32( hDC
, RGB(0, 0, 0) );
83 UnrealizeObject32( hb
);
87 SetTextColor32( hDC
, GetSysColor32(COLOR_WINDOWTEXT
));
89 if (TWEAK_WineLook
> WIN31_LOOK
) {
90 if ((ctlType
== CTLCOLOR_EDIT
) || (ctlType
== CTLCOLOR_LISTBOX
))
91 SetBkColor32( hDC
, GetSysColor32(COLOR_WINDOW
) );
93 SetBkColor32( hDC
, GetSysColor32(COLOR_3DFACE
) );
94 return GetSysColorBrush32(COLOR_3DFACE
);
98 SetBkColor32( hDC
, GetSysColor32(COLOR_WINDOW
) );
99 return GetSysColorBrush32(COLOR_WINDOW
);
103 /***********************************************************************
106 static void DEFWND_SetRedraw( WND
* wndPtr
, WPARAM32 wParam
)
108 BOOL32 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 * Default window procedure for messages that are the same in Win16 and Win32.
136 static LRESULT
DEFWND_DefWinProc( WND
*wndPtr
, UINT32 msg
, WPARAM32 wParam
,
142 return NC_HandleNCPaint( wndPtr
->hwndSelf
, (HRGN32
)wParam
);
145 return NC_HandleNCHitTest( wndPtr
->hwndSelf
, MAKEPOINT16(lParam
) );
147 case WM_NCLBUTTONDOWN
:
148 return NC_HandleNCLButtonDown( wndPtr
, wParam
, lParam
);
150 case WM_LBUTTONDBLCLK
:
151 case WM_NCLBUTTONDBLCLK
:
152 return NC_HandleNCLButtonDblClk( wndPtr
, wParam
, lParam
);
155 case WM_NCRBUTTONDOWN
:
156 if ((wndPtr
->flags
& WIN_ISWIN32
) || (TWEAK_WineLook
> WIN31_LOOK
))
158 ClientToScreen16(wndPtr
->hwndSelf
, (LPPOINT16
)&lParam
);
159 SendMessage32A( wndPtr
->hwndSelf
, WM_CONTEXTMENU
,
160 wndPtr
->hwndSelf
, lParam
);
165 if( wndPtr
->dwStyle
& WS_CHILD
)
166 SendMessage32A( wndPtr
->parent
->hwndSelf
, msg
, wParam
, lParam
);
168 if (wndPtr
->hSysMenu
)
170 TrackPopupMenu32(wndPtr->hSysMenu,TPM_LEFTALIGN | TPM_RETURNCMD,LOWORD(lParam),HIWORD(lParam),0,wndPtr->hwndSelf,NULL);
171 DestroyMenu32(wndPtr->hSysMenu);
173 FIXME(win
,"Display default popup menu\n");
174 /* Track system popup if click was in the caption area. */
179 return NC_HandleNCActivate( wndPtr
, wParam
);
182 if (wndPtr
->text
) HeapFree( SystemHeap
, 0, wndPtr
->text
);
184 if (wndPtr
->pVScroll
) HeapFree( SystemHeap
, 0, wndPtr
->pVScroll
);
185 if (wndPtr
->pHScroll
) HeapFree( SystemHeap
, 0, wndPtr
->pHScroll
);
186 wndPtr
->pVScroll
= wndPtr
->pHScroll
= NULL
;
193 HDC16 hdc
= BeginPaint16( wndPtr
->hwndSelf
, &ps
);
196 if( (wndPtr
->dwStyle
& WS_MINIMIZE
) && wndPtr
->class->hIcon
)
198 int x
= (wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
-
199 SYSMETRICS_CXICON
)/2;
200 int y
= (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
-
201 SYSMETRICS_CYICON
)/2;
202 TRACE(win
,"Painting class icon: vis rect=(%i,%i - %i,%i)\n",
203 ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
204 DrawIcon32( hdc
, x
, y
, wndPtr
->class->hIcon
);
206 EndPaint16( wndPtr
->hwndSelf
, &ps
);
212 DEFWND_SetRedraw( wndPtr
, wParam
);
216 DestroyWindow32( wndPtr
->hwndSelf
);
219 case WM_MOUSEACTIVATE
:
220 if (wndPtr
->dwStyle
& WS_CHILD
)
222 LONG ret
= SendMessage16( wndPtr
->parent
->hwndSelf
,
223 WM_MOUSEACTIVATE
, wParam
, lParam
);
227 /* Caption clicks are handled by the NC_HandleNCLButtonDown() */
228 return (LOWORD(lParam
) == HTCAPTION
) ? MA_NOACTIVATE
: MA_ACTIVATE
;
231 if (LOWORD(wParam
) != WA_INACTIVE
) SetFocus32( wndPtr
->hwndSelf
);
235 case WM_ICONERASEBKGND
:
237 if (!wndPtr
->class->hbrBackground
) return 0;
239 if (wndPtr
->class->hbrBackground
<= (HBRUSH16
)(COLOR_MAX
+1))
241 HBRUSH32 hbrush
= CreateSolidBrush32(
242 GetSysColor32(((DWORD
)wndPtr
->class->hbrBackground
)-1));
243 FillWindow( GetParent16(wndPtr
->hwndSelf
), wndPtr
->hwndSelf
,
244 (HDC16
)wParam
, hbrush
);
245 DeleteObject32( hbrush
);
247 else FillWindow( GetParent16(wndPtr
->hwndSelf
), wndPtr
->hwndSelf
,
248 (HDC16
)wParam
, wndPtr
->class->hbrBackground
);
255 case WM_CTLCOLORMSGBOX
:
256 case WM_CTLCOLOREDIT
:
257 case WM_CTLCOLORLISTBOX
:
260 case WM_CTLCOLORSTATIC
:
261 case WM_CTLCOLORSCROLLBAR
:
262 return (LRESULT
)DEFWND_ControlColor( (HDC32
)wParam
, msg
- WM_CTLCOLORMSGBOX
);
265 return (LRESULT
)DEFWND_ControlColor( (HDC32
)wParam
, HIWORD(lParam
) );
267 case WM_GETTEXTLENGTH
:
268 if (wndPtr
->text
) return (LRESULT
)strlen(wndPtr
->text
);
272 if (wndPtr
->dwStyle
& WS_CHILD
)
273 if (SendMessage16(wndPtr
->parent
->hwndSelf
, WM_SETCURSOR
,
276 return NC_HandleSetCursor( wndPtr
->hwndSelf
, wParam
, lParam
);
279 return NC_HandleSysCommand( wndPtr
->hwndSelf
, wParam
,
280 MAKEPOINT16(lParam
) );
283 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
287 if( HIWORD(lParam
) & KEYDATA_ALT
)
289 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
290 if( wParam
== VK_MENU
&& !iMenuSysKey
)
297 if( wParam
== VK_F4
) /* try to close the window */
299 HWND32 hWnd
= WIN_GetTopParent( wndPtr
->hwndSelf
);
300 wndPtr
= WIN_FindWndPtr( hWnd
);
301 if( wndPtr
&& !(wndPtr
->class->style
& CS_NOCLOSE
) )
302 PostMessage16( hWnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0 );
305 else if( wParam
== VK_F10
)
308 if( wParam
== VK_ESCAPE
&& (GetKeyState32(VK_SHIFT
) & 0x8000))
309 SendMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
310 (WPARAM16
)SC_KEYMENU
, (LPARAM
)VK_SPACE
);
315 /* Press and release F10 or ALT */
316 if (((wParam
== VK_MENU
) && iMenuSysKey
) ||
317 ((wParam
== VK_F10
) && iF10Key
))
318 SendMessage16( WIN_GetTopParent(wndPtr
->hwndSelf
),
319 WM_SYSCOMMAND
, SC_KEYMENU
, 0L );
320 iMenuSysKey
= iF10Key
= 0;
325 if (wParam
== VK_RETURN
&& (wndPtr
->dwStyle
& WS_MINIMIZE
))
327 PostMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
328 (WPARAM16
)SC_RESTORE
, 0L );
331 if ((HIWORD(lParam
) & KEYDATA_ALT
) && wParam
)
333 if (wParam
== VK_TAB
|| wParam
== VK_ESCAPE
) break;
334 if (wParam
== VK_SPACE
&& (wndPtr
->dwStyle
& WS_CHILD
))
335 SendMessage16( wndPtr
->parent
->hwndSelf
, msg
, wParam
, lParam
);
337 SendMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
338 (WPARAM16
)SC_KEYMENU
, (LPARAM
)(DWORD
)wParam
);
340 else /* check for Ctrl-Esc */
341 if (wParam
!= VK_ESCAPE
) MessageBeep32(0);
345 if (!lParam
) return 0; /* sent from ShowWindow */
346 if (!(wndPtr
->dwStyle
& WS_POPUP
) || !wndPtr
->owner
) return 0;
347 if ((wndPtr
->dwStyle
& WS_VISIBLE
) && wParam
) return 0;
348 else if (!(wndPtr
->dwStyle
& WS_VISIBLE
) && !wParam
) return 0;
349 ShowWindow32( wndPtr
->hwndSelf
, wParam
? SW_SHOWNOACTIVATE
: SW_HIDE
);
353 if (wndPtr
->parent
== WIN_GetDesktop()) EndMenu();
354 if (GetCapture32() == wndPtr
->hwndSelf
) ReleaseCapture();
364 case WM_QUERYDROPOBJECT
:
365 if (wndPtr
->dwExStyle
& WS_EX_ACCEPTFILES
) return 1;
368 case WM_QUERYDRAGICON
:
373 if( (hIcon
=wndPtr
->class->hCursor
) ) return (LRESULT
)hIcon
;
374 for(len
=1; len
<64; len
++)
375 if((hIcon
=LoadIcon16(wndPtr
->hInstance
,MAKEINTRESOURCE16(len
))))
376 return (LRESULT
)hIcon
;
377 return (LRESULT
)LoadIcon16(NULL
,IDI_APPLICATION16
);
381 case WM_ISACTIVEICON
:
382 return ((wndPtr
->flags
& WIN_NCACTIVATED
) != 0);
385 case WM_QUERYENDSESSION
:
393 /***********************************************************************
394 * DefWindowProc16 (USER.107)
396 LRESULT WINAPI
DefWindowProc16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
399 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
402 if (!wndPtr
) return 0;
403 SPY_EnterMessage( SPY_DEFWNDPROC16
, hwnd
, msg
, wParam
, lParam
);
409 CREATESTRUCT16
*cs
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
);
411 DEFWND_SetText( wndPtr
, (LPSTR
)PTR_SEG_TO_LIN(cs
->lpszName
) );
419 CONV_RECT16TO32( (RECT16
*)PTR_SEG_TO_LIN(lParam
), &rect32
);
420 result
= NC_HandleNCCalcSize( wndPtr
, &rect32
);
421 CONV_RECT32TO16( &rect32
, (RECT16
*)PTR_SEG_TO_LIN(lParam
) );
425 case WM_WINDOWPOSCHANGING
:
426 result
= WINPOS_HandleWindowPosChanging16( wndPtr
,
427 (WINDOWPOS16
*)PTR_SEG_TO_LIN(lParam
) );
430 case WM_WINDOWPOSCHANGED
:
432 WINDOWPOS16
* winPos
= (WINDOWPOS16
*)PTR_SEG_TO_LIN(lParam
);
433 DEFWND_HandleWindowPosChanged( wndPtr
, winPos
->flags
);
438 if (wParam
&& wndPtr
->text
)
440 lstrcpyn32A( (LPSTR
)PTR_SEG_TO_LIN(lParam
), wndPtr
->text
, wParam
);
441 result
= (LRESULT
)strlen( (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
446 DEFWND_SetText( wndPtr
, (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
447 if( wndPtr
->dwStyle
& WS_CAPTION
) NC_HandleNCPaint( hwnd
, (HRGN32
)1 );
451 result
= DEFWND_DefWinProc( wndPtr
, msg
, wParam
, lParam
);
455 SPY_ExitMessage( SPY_RESULT_DEFWND16
, hwnd
, msg
, result
);
460 /***********************************************************************
461 * DefWindowProc32A [USER32.126]
464 LRESULT WINAPI
DefWindowProc32A( HWND32 hwnd
, UINT32 msg
, WPARAM32 wParam
,
467 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
470 if (!wndPtr
) return 0;
471 SPY_EnterMessage( SPY_DEFWNDPROC32
, hwnd
, msg
, wParam
, lParam
);
477 CREATESTRUCT32A
*cs
= (CREATESTRUCT32A
*)lParam
;
478 if (cs
->lpszName
) DEFWND_SetText( wndPtr
, cs
->lpszName
);
484 result
= NC_HandleNCCalcSize( wndPtr
, (RECT32
*)lParam
);
487 case WM_WINDOWPOSCHANGING
:
488 result
= WINPOS_HandleWindowPosChanging32( wndPtr
,
489 (WINDOWPOS32
*)lParam
);
492 case WM_WINDOWPOSCHANGED
:
494 WINDOWPOS32
* winPos
= (WINDOWPOS32
*)lParam
;
495 DEFWND_HandleWindowPosChanged( wndPtr
, winPos
->flags
);
500 if (wParam
&& wndPtr
->text
)
502 lstrcpyn32A( (LPSTR
)lParam
, wndPtr
->text
, wParam
);
503 result
= (LRESULT
)strlen( (LPSTR
)lParam
);
508 DEFWND_SetText( wndPtr
, (LPSTR
)lParam
);
509 NC_HandleNCPaint( hwnd
, (HRGN32
)1 ); /* Repaint caption */
513 result
= DEFWND_DefWinProc( wndPtr
, msg
, wParam
, lParam
);
517 SPY_ExitMessage( SPY_RESULT_DEFWND32
, hwnd
, msg
, result
);
522 /***********************************************************************
523 * DefWindowProc32W [USER32.127] Calls default window message handler
525 * Calls default window procedure for messages not processed
529 * Return value is dependent upon the message.
531 LRESULT WINAPI
DefWindowProc32W(
532 HWND32 hwnd
, /* [in] window procedure recieving message */
533 UINT32 msg
, /* [in] message identifier */
534 WPARAM32 wParam
, /* [in] first message parameter */
535 LPARAM lParam
) /* [in] second message parameter */
543 CREATESTRUCT32W
*cs
= (CREATESTRUCT32W
*)lParam
;
546 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
547 LPSTR str
= HEAP_strdupWtoA(GetProcessHeap(), 0, cs
->lpszName
);
548 DEFWND_SetText( wndPtr
, str
);
549 HeapFree( GetProcessHeap(), 0, str
);
557 LPSTR str
= HeapAlloc( GetProcessHeap(), 0, wParam
);
558 result
= DefWindowProc32A( hwnd
, msg
, wParam
, (LPARAM
)str
);
559 lstrcpynAtoW( (LPWSTR
)lParam
, str
, wParam
);
560 HeapFree( GetProcessHeap(), 0, str
);
566 LPSTR str
= HEAP_strdupWtoA( GetProcessHeap(), 0, (LPWSTR
)lParam
);
567 result
= DefWindowProc32A( hwnd
, msg
, wParam
, (LPARAM
)str
);
568 HeapFree( GetProcessHeap(), 0, str
);
573 result
= DefWindowProc32A( hwnd
, msg
, wParam
, lParam
);