2 * Default window procedure
4 * Copyright 1993, 1996 Alexandre Julliard
13 #include "nonclient.h"
16 #include "sysmetrics.h"
22 #define COLOR_MAX COLOR_BTNHIGHLIGHT
24 /* bits in the dwKeyData */
25 #define KEYDATA_ALT 0x2000
26 #define KEYDATA_PREVSTATE 0x4000
28 static short iF10Key
= 0;
29 static short iMenuSysKey
= 0;
31 /***********************************************************************
32 * DEFWND_HandleWindowPosChanged
34 * Handle the WM_WINDOWPOSCHANGED message.
36 static void DEFWND_HandleWindowPosChanged( WND
*wndPtr
, UINT32 flags
)
38 WPARAM16 wp
= SIZE_RESTORED
;
40 if (!(flags
& SWP_NOCLIENTMOVE
))
41 SendMessage16( wndPtr
->hwndSelf
, WM_MOVE
, 0,
42 MAKELONG(wndPtr
->rectClient
.left
, wndPtr
->rectClient
.top
));
43 if (!(flags
& SWP_NOCLIENTSIZE
))
45 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wp
= SIZE_MAXIMIZED
;
46 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wp
= SIZE_MINIMIZED
;
48 SendMessage16( wndPtr
->hwndSelf
, WM_SIZE
, wp
,
49 MAKELONG(wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
50 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
));
55 /***********************************************************************
58 * Set the window text.
60 void DEFWND_SetText( WND
*wndPtr
, LPCSTR text
)
63 if (wndPtr
->text
) HeapFree( SystemHeap
, 0, wndPtr
->text
);
64 wndPtr
->text
= HEAP_strdupA( SystemHeap
, 0, text
);
67 XStoreName( display
, wndPtr
->window
, wndPtr
->text
);
68 XSetIconName( display
, wndPtr
->window
, wndPtr
->text
);
73 /***********************************************************************
76 * Default window procedure for messages that are the same in Win16 and Win32.
78 static LRESULT
DEFWND_DefWinProc( WND
*wndPtr
, UINT32 msg
, WPARAM32 wParam
,
84 return NC_HandleNCPaint( wndPtr
->hwndSelf
, (HRGN32
)wParam
);
87 return NC_HandleNCHitTest( wndPtr
->hwndSelf
, MAKEPOINT16(lParam
) );
89 case WM_NCLBUTTONDOWN
:
90 return NC_HandleNCLButtonDown( wndPtr
->hwndSelf
, wParam
, lParam
);
92 case WM_LBUTTONDBLCLK
:
93 case WM_NCLBUTTONDBLCLK
:
94 return NC_HandleNCLButtonDblClk( wndPtr
, wParam
, lParam
);
97 return NC_HandleNCActivate( wndPtr
, wParam
);
100 if (wndPtr
->text
) HeapFree( SystemHeap
, 0, wndPtr
->text
);
102 if (wndPtr
->pVScroll
) HeapFree( SystemHeap
, 0, wndPtr
->pVScroll
);
103 if (wndPtr
->pHScroll
) HeapFree( SystemHeap
, 0, wndPtr
->pHScroll
);
104 wndPtr
->pVScroll
= wndPtr
->pHScroll
= NULL
;
111 HDC16 hdc
= BeginPaint16( wndPtr
->hwndSelf
, &ps
);
114 if( (wndPtr
->dwStyle
& WS_MINIMIZE
) && wndPtr
->class->hIcon
)
116 int x
= (wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
-
117 SYSMETRICS_CXICON
)/2;
118 int y
= (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
-
119 SYSMETRICS_CYICON
)/2;
120 dprintf_win(stddeb
,"Painting class icon: vis rect=(%i,%i - %i,%i)\n",
121 ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
122 DrawIcon( hdc
, x
, y
, wndPtr
->class->hIcon
);
124 EndPaint16( wndPtr
->hwndSelf
, &ps
);
132 ValidateRect32( wndPtr
->hwndSelf
, NULL
);
133 wndPtr
->flags
|= WIN_NO_REDRAW
;
137 wndPtr
->flags
&= ~WIN_NO_REDRAW
;
138 ShowWindow32( wndPtr
->hwndSelf
, SW_SHOW
);
143 DestroyWindow32( wndPtr
->hwndSelf
);
146 case WM_MOUSEACTIVATE
:
147 if (wndPtr
->dwStyle
& WS_CHILD
)
149 LONG ret
= SendMessage16( wndPtr
->parent
->hwndSelf
,
150 WM_MOUSEACTIVATE
, wParam
, lParam
);
156 if (LOWORD(wParam
) != WA_INACTIVE
) SetFocus32( wndPtr
->hwndSelf
);
160 case WM_ICONERASEBKGND
:
162 if (!wndPtr
->class->hbrBackground
) return 0;
164 /* FIXME: should fill icon text with hbrushActiveCaption
167 if (wndPtr
->dwStyle
& WS_MINIMIZE
)
169 if( wndPtr
->flags
& WIN_NCACTIVATED
)
171 FillWindow( GetParent16(wndPtr
->hwndSelf
), wndPtr
->hwndSelf
,
172 (HDC16
)wParam
, sysColorObjects
.hbrushActiveCaption
);
176 /* FIXME: should draw parent' background somehow
177 (e.g for textured desktop) ? */
180 if (wndPtr
->class->hbrBackground
<= (HBRUSH16
)(COLOR_MAX
+1))
182 HBRUSH32 hbrush
= CreateSolidBrush32(
183 GetSysColor(((DWORD
)wndPtr
->class->hbrBackground
)-1));
184 FillWindow( GetParent16(wndPtr
->hwndSelf
), wndPtr
->hwndSelf
,
185 (HDC16
)wParam
, hbrush
);
186 DeleteObject32( hbrush
);
188 else FillWindow( GetParent16(wndPtr
->hwndSelf
), wndPtr
->hwndSelf
,
189 (HDC16
)wParam
, wndPtr
->class->hbrBackground
);
196 case WM_CTLCOLORMSGBOX
:
197 case WM_CTLCOLOREDIT
:
198 case WM_CTLCOLORLISTBOX
:
201 case WM_CTLCOLORSTATIC
:
202 SetBkColor( (HDC32
)wParam
, GetSysColor(COLOR_WINDOW
) );
203 SetTextColor( (HDC32
)wParam
, GetSysColor(COLOR_WINDOWTEXT
) );
204 return (LRESULT
)sysColorObjects
.hbrushWindow
;
206 case WM_CTLCOLORSCROLLBAR
:
207 SetBkColor( (HDC32
)wParam
, RGB(255, 255, 255) );
208 SetTextColor( (HDC32
)wParam
, RGB(0, 0, 0) );
209 UnrealizeObject32( sysColorObjects
.hbrushScrollbar
);
210 return (LRESULT
)sysColorObjects
.hbrushScrollbar
;
214 if (HIWORD(lParam
) == CTLCOLOR_SCROLLBAR
)
216 SetBkColor( (HDC32
)wParam
, RGB(255, 255, 255) );
217 SetTextColor( (HDC32
)wParam
, RGB(0, 0, 0) );
218 UnrealizeObject32( sysColorObjects
.hbrushScrollbar
);
219 return (LRESULT
)sysColorObjects
.hbrushScrollbar
;
223 SetBkColor( (HDC32
)wParam
, GetSysColor(COLOR_WINDOW
) );
224 SetTextColor( (HDC32
)wParam
, GetSysColor(COLOR_WINDOWTEXT
) );
225 return (LRESULT
)sysColorObjects
.hbrushWindow
;
229 case WM_GETTEXTLENGTH
:
230 if (wndPtr
->text
) return (LRESULT
)strlen(wndPtr
->text
);
234 if (wndPtr
->dwStyle
& WS_CHILD
)
235 if (SendMessage16(wndPtr
->parent
->hwndSelf
, WM_SETCURSOR
,
238 return NC_HandleSetCursor( wndPtr
->hwndSelf
, wParam
, lParam
);
241 return NC_HandleSysCommand( wndPtr
->hwndSelf
, wParam
,
242 MAKEPOINT16(lParam
) );
245 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
249 if( HIWORD(lParam
) & KEYDATA_ALT
)
251 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
252 if( wParam
== VK_MENU
&& !iMenuSysKey
)
260 else if( wParam
== VK_F10
)
263 if( wParam
== VK_ESCAPE
&& GetKeyState(VK_SHIFT
) < 0 )
264 SendMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
265 (WPARAM16
)SC_KEYMENU
, (LPARAM
)VK_SPACE
);
270 /* Press and release F10 or ALT */
271 if (((wParam
== VK_MENU
) && iMenuSysKey
) ||
272 ((wParam
== VK_F10
) && iF10Key
))
273 SendMessage16( WIN_GetTopParent(wndPtr
->hwndSelf
),
274 WM_SYSCOMMAND
, SC_KEYMENU
, 0L );
275 iMenuSysKey
= iF10Key
= 0;
280 if (wParam
== VK_RETURN
&& (wndPtr
->dwStyle
& WS_MINIMIZE
))
282 PostMessage( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
283 (WPARAM16
)SC_RESTORE
, 0L );
286 if ((HIWORD(lParam
) & KEYDATA_ALT
) && wParam
)
288 if (wParam
== VK_TAB
|| wParam
== VK_ESCAPE
) break;
289 if (wParam
== VK_SPACE
&& (wndPtr
->dwStyle
& WS_CHILD
))
290 SendMessage16( wndPtr
->parent
->hwndSelf
, msg
, wParam
, lParam
);
292 SendMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
293 (WPARAM16
)SC_KEYMENU
, (LPARAM
)(DWORD
)wParam
);
295 else /* check for Ctrl-Esc */
296 if (wParam
!= VK_ESCAPE
) MessageBeep(0);
300 if (!lParam
) return 0; /* sent from ShowWindow */
301 if (!(wndPtr
->dwStyle
& WS_POPUP
) || !wndPtr
->owner
) return 0;
302 if ((wndPtr
->dwStyle
& WS_VISIBLE
) && wParam
) return 0;
303 else if (!(wndPtr
->dwStyle
& WS_VISIBLE
) && !wParam
) return 0;
304 ShowWindow32( wndPtr
->hwndSelf
, wParam
? SW_SHOWNOACTIVATE
: SW_HIDE
);
308 /* EndMenu() should be called if in menu state but currently it's
309 impossible to detect - menu code should be updated*/
310 if (GetCapture32() == wndPtr
->hwndSelf
) ReleaseCapture();
320 case WM_QUERYDROPOBJECT
:
321 if (wndPtr
->dwExStyle
& WS_EX_ACCEPTFILES
) return 1;
324 case WM_QUERYDRAGICON
:
329 if( (hI
= LoadIcon16(wndPtr
->hInstance
,MAKEINTRESOURCE(len
))) )
335 case WM_QUERYENDSESSION
:
343 /***********************************************************************
344 * DefWindowProc16 (USER.107)
346 LRESULT
DefWindowProc16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
349 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
352 if (!wndPtr
) return 0;
353 SPY_EnterMessage( SPY_DEFWNDPROC16
, hwnd
, msg
, wParam
, lParam
);
359 CREATESTRUCT16
*cs
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
);
361 DEFWND_SetText( wndPtr
, (LPSTR
)PTR_SEG_TO_LIN(cs
->lpszName
) );
367 result
= NC_HandleNCCalcSize(wndPtr
, (RECT16
*)PTR_SEG_TO_LIN(lParam
));
370 case WM_WINDOWPOSCHANGING
:
371 result
= WINPOS_HandleWindowPosChanging16( wndPtr
,
372 (WINDOWPOS16
*)PTR_SEG_TO_LIN(lParam
) );
375 case WM_WINDOWPOSCHANGED
:
377 WINDOWPOS16
* winPos
= (WINDOWPOS16
*)PTR_SEG_TO_LIN(lParam
);
378 DEFWND_HandleWindowPosChanged( wndPtr
, winPos
->flags
);
383 if (wParam
&& wndPtr
->text
)
385 lstrcpyn32A( (LPSTR
)PTR_SEG_TO_LIN(lParam
), wndPtr
->text
, wParam
);
386 result
= (LRESULT
)strlen( (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
391 DEFWND_SetText( wndPtr
, (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
392 NC_HandleNCPaint( hwnd
, (HRGN32
)1 ); /* Repaint caption */
396 result
= DEFWND_DefWinProc( wndPtr
, msg
, wParam
, lParam
);
400 SPY_ExitMessage( SPY_RESULT_OK16
, hwnd
, msg
, result
);
405 /***********************************************************************
406 * DefWindowProc32A (USER32.125)
408 LRESULT
DefWindowProc32A( HWND32 hwnd
, UINT32 msg
, WPARAM32 wParam
,
411 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
414 if (!wndPtr
) return 0;
415 SPY_EnterMessage( SPY_DEFWNDPROC32
, hwnd
, msg
, wParam
, lParam
);
421 CREATESTRUCT32A
*cs
= (CREATESTRUCT32A
*)lParam
;
422 if (cs
->lpszName
) DEFWND_SetText( wndPtr
, cs
->lpszName
);
430 CONV_RECT32TO16( (RECT32
*)lParam
, &rect16
);
431 result
= NC_HandleNCCalcSize( wndPtr
, &rect16
);
432 CONV_RECT16TO32( &rect16
, (RECT32
*)lParam
);
436 case WM_WINDOWPOSCHANGING
:
437 result
= WINPOS_HandleWindowPosChanging32( wndPtr
,
438 (WINDOWPOS32
*)lParam
);
441 case WM_WINDOWPOSCHANGED
:
443 WINDOWPOS32
* winPos
= (WINDOWPOS32
*)lParam
;
444 DEFWND_HandleWindowPosChanged( wndPtr
, winPos
->flags
);
449 if (wParam
&& wndPtr
->text
)
451 lstrcpyn32A( (LPSTR
)lParam
, wndPtr
->text
, wParam
);
452 result
= (LRESULT
)strlen( (LPSTR
)lParam
);
457 DEFWND_SetText( wndPtr
, (LPSTR
)lParam
);
458 NC_HandleNCPaint( hwnd
, (HRGN32
)1 ); /* Repaint caption */
462 result
= DEFWND_DefWinProc( wndPtr
, msg
, wParam
, lParam
);
466 SPY_ExitMessage( SPY_RESULT_OK32
, hwnd
, msg
, result
);
471 /***********************************************************************
472 * DefWindowProc32W (USER32.126)
474 LRESULT
DefWindowProc32W( HWND32 hwnd
, UINT32 msg
, WPARAM32 wParam
,
483 CREATESTRUCT32W
*cs
= (CREATESTRUCT32W
*)lParam
;
486 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
487 LPSTR str
= HEAP_strdupWtoA(GetProcessHeap(), 0, cs
->lpszName
);
488 DEFWND_SetText( wndPtr
, str
);
489 HeapFree( GetProcessHeap(), 0, str
);
497 LPSTR str
= HeapAlloc( GetProcessHeap(), 0, wParam
);
498 result
= DefWindowProc32A( hwnd
, msg
, wParam
, (LPARAM
)str
);
499 lstrcpynAtoW( (LPWSTR
)lParam
, str
, wParam
);
500 HeapFree( GetProcessHeap(), 0, str
);
506 LPSTR str
= HEAP_strdupWtoA( GetProcessHeap(), 0, (LPWSTR
)lParam
);
507 result
= DefWindowProc32A( hwnd
, msg
, wParam
, (LPARAM
)str
);
508 HeapFree( GetProcessHeap(), 0, str
);
513 result
= DefWindowProc32A( hwnd
, msg
, wParam
, lParam
);