2 * Default window procedure
4 * Copyright 1993, 1996 Alexandre Julliard
13 #include "nonclient.h"
17 #include "sysmetrics.h"
23 #define COLOR_MAX COLOR_BTNHIGHLIGHT
25 /* bits in the dwKeyData */
26 #define KEYDATA_ALT 0x2000
27 #define KEYDATA_PREVSTATE 0x4000
29 static short iF10Key
= 0;
30 static short iMenuSysKey
= 0;
32 /***********************************************************************
33 * DEFWND_HandleWindowPosChanged
35 * Handle the WM_WINDOWPOSCHANGED message.
37 static void DEFWND_HandleWindowPosChanged( WND
*wndPtr
, UINT32 flags
)
39 WPARAM16 wp
= SIZE_RESTORED
;
41 if (!(flags
& SWP_NOCLIENTMOVE
))
42 SendMessage16( wndPtr
->hwndSelf
, WM_MOVE
, 0,
43 MAKELONG(wndPtr
->rectClient
.left
, wndPtr
->rectClient
.top
));
44 if (!(flags
& SWP_NOCLIENTSIZE
))
46 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wp
= SIZE_MAXIMIZED
;
47 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wp
= SIZE_MINIMIZED
;
49 SendMessage16( wndPtr
->hwndSelf
, WM_SIZE
, wp
,
50 MAKELONG(wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
51 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
));
56 /***********************************************************************
59 * Set the window text.
61 void DEFWND_SetText( WND
*wndPtr
, LPCSTR text
)
64 if (wndPtr
->text
) HeapFree( SystemHeap
, 0, wndPtr
->text
);
65 wndPtr
->text
= HEAP_strdupA( SystemHeap
, 0, text
);
66 if (wndPtr
->window
) XStoreName( display
, wndPtr
->window
, wndPtr
->text
);
70 /***********************************************************************
73 * Default window procedure for messages that are the same in Win16 and Win32.
75 static LRESULT
DEFWND_DefWinProc( WND
*wndPtr
, UINT32 msg
, WPARAM32 wParam
,
81 return NC_HandleNCPaint( wndPtr
->hwndSelf
, (HRGN32
)wParam
);
84 return NC_HandleNCHitTest( wndPtr
->hwndSelf
, MAKEPOINT16(lParam
) );
86 case WM_NCLBUTTONDOWN
:
87 return NC_HandleNCLButtonDown( wndPtr
->hwndSelf
, wParam
, lParam
);
89 case WM_LBUTTONDBLCLK
:
90 case WM_NCLBUTTONDBLCLK
:
91 return NC_HandleNCLButtonDblClk( wndPtr
, wParam
, lParam
);
94 return NC_HandleNCActivate( wndPtr
, wParam
);
97 if (wndPtr
->text
) HeapFree( SystemHeap
, 0, wndPtr
->text
);
99 if (wndPtr
->pVScroll
) HeapFree( SystemHeap
, 0, wndPtr
->pVScroll
);
100 if (wndPtr
->pHScroll
) HeapFree( SystemHeap
, 0, wndPtr
->pHScroll
);
101 wndPtr
->pVScroll
= wndPtr
->pHScroll
= NULL
;
108 HDC16 hdc
= BeginPaint16( wndPtr
->hwndSelf
, &ps
);
111 if( (wndPtr
->dwStyle
& WS_MINIMIZE
) && wndPtr
->class->hIcon
)
113 int x
= (wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
-
114 SYSMETRICS_CXICON
)/2;
115 int y
= (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
-
116 SYSMETRICS_CYICON
)/2;
117 dprintf_win(stddeb
,"Painting class icon: vis rect=(%i,%i - %i,%i)\n",
118 ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
119 DrawIcon( hdc
, x
, y
, wndPtr
->class->hIcon
);
121 EndPaint16( wndPtr
->hwndSelf
, &ps
);
129 ValidateRect32( wndPtr
->hwndSelf
, NULL
);
130 wndPtr
->flags
|= WIN_NO_REDRAW
;
132 else wndPtr
->flags
&= ~WIN_NO_REDRAW
;
136 DestroyWindow( wndPtr
->hwndSelf
);
139 case WM_MOUSEACTIVATE
:
140 if (wndPtr
->dwStyle
& WS_CHILD
)
142 LONG ret
= SendMessage16( wndPtr
->parent
->hwndSelf
,
143 WM_MOUSEACTIVATE
, wParam
, lParam
);
149 if (LOWORD(wParam
) != WA_INACTIVE
) SetFocus32( wndPtr
->hwndSelf
);
153 case WM_ICONERASEBKGND
:
155 if (!wndPtr
->class->hbrBackground
) return 0;
157 /* FIXME: should fill icon text with hbrushActiveCaption
160 if (wndPtr
->dwStyle
& WS_MINIMIZE
)
162 if( wndPtr
->flags
& WIN_NCACTIVATED
)
164 FillWindow( GetParent16(wndPtr
->hwndSelf
), wndPtr
->hwndSelf
,
165 (HDC16
)wParam
, sysColorObjects
.hbrushActiveCaption
);
169 /* FIXME: should draw parent' background somehow
170 (e.g for textured desktop) ? */
173 if (wndPtr
->class->hbrBackground
<= (HBRUSH16
)(COLOR_MAX
+1))
175 HBRUSH16 hbrush
= CreateSolidBrush(
176 GetSysColor(((DWORD
)wndPtr
->class->hbrBackground
)-1));
177 FillWindow( GetParent16(wndPtr
->hwndSelf
), wndPtr
->hwndSelf
,
178 (HDC16
)wParam
, hbrush
);
179 DeleteObject (hbrush
);
181 else FillWindow( GetParent16(wndPtr
->hwndSelf
), wndPtr
->hwndSelf
,
182 (HDC16
)wParam
, wndPtr
->class->hbrBackground
);
189 case WM_CTLCOLORMSGBOX
:
190 case WM_CTLCOLOREDIT
:
191 case WM_CTLCOLORLISTBOX
:
194 case WM_CTLCOLORSTATIC
:
195 SetBkColor( (HDC32
)wParam
, GetSysColor(COLOR_WINDOW
) );
196 SetTextColor( (HDC32
)wParam
, GetSysColor(COLOR_WINDOWTEXT
) );
197 return (LRESULT
)sysColorObjects
.hbrushWindow
;
199 case WM_CTLCOLORSCROLLBAR
:
200 SetBkColor( (HDC32
)wParam
, RGB(255, 255, 255) );
201 SetTextColor( (HDC32
)wParam
, RGB(0, 0, 0) );
202 UnrealizeObject( sysColorObjects
.hbrushScrollbar
);
203 return (LRESULT
)sysColorObjects
.hbrushScrollbar
;
207 if (HIWORD(lParam
) == CTLCOLOR_SCROLLBAR
)
209 SetBkColor( (HDC32
)wParam
, RGB(255, 255, 255) );
210 SetTextColor( (HDC32
)wParam
, RGB(0, 0, 0) );
211 UnrealizeObject( sysColorObjects
.hbrushScrollbar
);
212 return (LRESULT
)sysColorObjects
.hbrushScrollbar
;
216 SetBkColor( (HDC32
)wParam
, GetSysColor(COLOR_WINDOW
) );
217 SetTextColor( (HDC32
)wParam
, GetSysColor(COLOR_WINDOWTEXT
) );
218 return (LRESULT
)sysColorObjects
.hbrushWindow
;
222 case WM_GETTEXTLENGTH
:
223 if (wndPtr
->text
) return (LRESULT
)strlen(wndPtr
->text
);
227 if (wndPtr
->dwStyle
& WS_CHILD
)
228 if (SendMessage16(wndPtr
->parent
->hwndSelf
, WM_SETCURSOR
,
231 return NC_HandleSetCursor( wndPtr
->hwndSelf
, wParam
, lParam
);
234 return NC_HandleSysCommand( wndPtr
->hwndSelf
, wParam
,
235 MAKEPOINT16(lParam
) );
238 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
242 if( HIWORD(lParam
) & KEYDATA_ALT
)
244 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
245 if( wParam
== VK_MENU
&& !iMenuSysKey
)
253 else if( wParam
== VK_F10
)
256 if( wParam
== VK_ESCAPE
&& GetKeyState(VK_SHIFT
) < 0 )
257 SendMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
258 (WPARAM16
)SC_KEYMENU
, (LPARAM
)VK_SPACE
);
263 /* Press and release F10 or ALT */
264 if (((wParam
== VK_MENU
) && iMenuSysKey
) ||
265 ((wParam
== VK_F10
) && iF10Key
))
266 SendMessage16( WIN_GetTopParent(wndPtr
->hwndSelf
),
267 WM_SYSCOMMAND
, SC_KEYMENU
, 0L );
268 iMenuSysKey
= iF10Key
= 0;
273 if (wParam
== VK_RETURN
&& (wndPtr
->dwStyle
& WS_MINIMIZE
))
275 PostMessage( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
276 (WPARAM16
)SC_RESTORE
, 0L );
279 if ((HIWORD(lParam
) & KEYDATA_ALT
) && wParam
)
281 if (wParam
== VK_TAB
|| wParam
== VK_ESCAPE
) break;
282 if (wParam
== VK_SPACE
&& (wndPtr
->dwStyle
& WS_CHILD
))
283 SendMessage16( wndPtr
->parent
->hwndSelf
, msg
, wParam
, lParam
);
285 SendMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
286 (WPARAM16
)SC_KEYMENU
, (LPARAM
)(DWORD
)wParam
);
288 else /* check for Ctrl-Esc */
289 if (wParam
!= VK_ESCAPE
) MessageBeep(0);
293 if (!lParam
) return 0; /* sent from ShowWindow */
294 if (!(wndPtr
->dwStyle
& WS_POPUP
) || !wndPtr
->owner
) return 0;
295 if ((wndPtr
->dwStyle
& WS_VISIBLE
) && wParam
) return 0;
296 else if (!(wndPtr
->dwStyle
& WS_VISIBLE
) && !wParam
) return 0;
297 ShowWindow( wndPtr
->hwndSelf
, wParam
? SW_SHOWNOACTIVATE
: SW_HIDE
);
301 /* EndMenu() should be called if in menu state but currently it's
302 impossible to detect - menu code should be updated*/
303 if (GetCapture32() == wndPtr
->hwndSelf
) ReleaseCapture();
313 case WM_QUERYDROPOBJECT
:
314 if (wndPtr
->dwExStyle
& WS_EX_ACCEPTFILES
) return 1;
317 case WM_QUERYDRAGICON
:
322 if( (hI
= LoadIcon16(wndPtr
->hInstance
,MAKEINTRESOURCE(len
))) )
328 case WM_QUERYENDSESSION
:
336 /***********************************************************************
337 * DefWindowProc16 (USER.107)
339 LRESULT
DefWindowProc16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
342 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
345 if (!wndPtr
) return 0;
346 SPY_EnterMessage( SPY_DEFWNDPROC16
, hwnd
, msg
, wParam
, lParam
);
352 CREATESTRUCT16
*cs
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
);
354 DEFWND_SetText( wndPtr
, (LPSTR
)PTR_SEG_TO_LIN(cs
->lpszName
) );
360 result
= NC_HandleNCCalcSize(wndPtr
, (RECT16
*)PTR_SEG_TO_LIN(lParam
));
363 case WM_WINDOWPOSCHANGING
:
364 result
= WINPOS_HandleWindowPosChanging16( wndPtr
,
365 (WINDOWPOS16
*)PTR_SEG_TO_LIN(lParam
) );
368 case WM_WINDOWPOSCHANGED
:
370 WINDOWPOS16
* winPos
= (WINDOWPOS16
*)PTR_SEG_TO_LIN(lParam
);
371 DEFWND_HandleWindowPosChanged( wndPtr
, winPos
->flags
);
376 if (wParam
&& wndPtr
->text
)
378 lstrcpyn32A( (LPSTR
)PTR_SEG_TO_LIN(lParam
), wndPtr
->text
, wParam
);
379 result
= (LRESULT
)strlen( (LPSTR
)PTR_SEG_TO_LIN(lParam
) ) + 1;
384 DEFWND_SetText( wndPtr
, (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
385 NC_HandleNCPaint( hwnd
, (HRGN32
)1 ); /* Repaint caption */
389 result
= DEFWND_DefWinProc( wndPtr
, msg
, wParam
, lParam
);
393 SPY_ExitMessage( SPY_RESULT_OK16
, hwnd
, msg
, result
);
398 /***********************************************************************
399 * DefWindowProc32A (USER32.125)
401 LRESULT
DefWindowProc32A( HWND32 hwnd
, UINT32 msg
, WPARAM32 wParam
,
404 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
407 if (!wndPtr
) return 0;
408 SPY_EnterMessage( SPY_DEFWNDPROC32
, hwnd
, msg
, wParam
, lParam
);
414 CREATESTRUCT32A
*cs
= (CREATESTRUCT32A
*)lParam
;
415 if (cs
->lpszName
) DEFWND_SetText( wndPtr
, cs
->lpszName
);
423 CONV_RECT32TO16( (RECT32
*)lParam
, &rect16
);
424 result
= NC_HandleNCCalcSize( wndPtr
, &rect16
);
425 CONV_RECT16TO32( &rect16
, (RECT32
*)lParam
);
429 case WM_WINDOWPOSCHANGING
:
430 result
= WINPOS_HandleWindowPosChanging32( wndPtr
,
431 (WINDOWPOS32
*)lParam
);
434 case WM_WINDOWPOSCHANGED
:
436 WINDOWPOS32
* winPos
= (WINDOWPOS32
*)lParam
;
437 DEFWND_HandleWindowPosChanged( wndPtr
, winPos
->flags
);
442 if (wParam
&& wndPtr
->text
)
444 lstrcpyn32A( (LPSTR
)lParam
, wndPtr
->text
, wParam
);
445 result
= (LRESULT
)strlen( (LPSTR
)lParam
) + 1;
450 DEFWND_SetText( wndPtr
, (LPSTR
)lParam
);
451 NC_HandleNCPaint( hwnd
, (HRGN32
)1 ); /* Repaint caption */
455 result
= DEFWND_DefWinProc( wndPtr
, msg
, wParam
, lParam
);
459 SPY_ExitMessage( SPY_RESULT_OK32
, hwnd
, msg
, result
);
464 /***********************************************************************
465 * DefWindowProc32W (USER32.126)
467 LRESULT
DefWindowProc32W( HWND32 hwnd
, UINT32 msg
, WPARAM32 wParam
,
476 CREATESTRUCT32W
*cs
= (CREATESTRUCT32W
*)lParam
;
479 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
480 LPSTR str
= STRING32_DupUniToAnsi( cs
->lpszName
);
481 DEFWND_SetText( wndPtr
, str
);
490 LPSTR str
= malloc( wParam
);
491 result
= DefWindowProc32A( hwnd
, msg
, wParam
, (LPARAM
)str
);
492 STRING32_AnsiToUni( (LPWSTR
)lParam
, str
);
499 LPSTR str
= STRING32_DupUniToAnsi( (LPWSTR
)lParam
);
500 result
= DefWindowProc32A( hwnd
, msg
, wParam
, (LPARAM
)str
);
506 result
= DefWindowProc32A( hwnd
, msg
, wParam
, lParam
);