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
;
135 else wndPtr
->flags
&= ~WIN_NO_REDRAW
;
139 DestroyWindow( wndPtr
->hwndSelf
);
142 case WM_MOUSEACTIVATE
:
143 if (wndPtr
->dwStyle
& WS_CHILD
)
145 LONG ret
= SendMessage16( wndPtr
->parent
->hwndSelf
,
146 WM_MOUSEACTIVATE
, wParam
, lParam
);
152 if (LOWORD(wParam
) != WA_INACTIVE
) SetFocus32( wndPtr
->hwndSelf
);
156 case WM_ICONERASEBKGND
:
158 if (!wndPtr
->class->hbrBackground
) return 0;
160 /* FIXME: should fill icon text with hbrushActiveCaption
163 if (wndPtr
->dwStyle
& WS_MINIMIZE
)
165 if( wndPtr
->flags
& WIN_NCACTIVATED
)
167 FillWindow( GetParent16(wndPtr
->hwndSelf
), wndPtr
->hwndSelf
,
168 (HDC16
)wParam
, sysColorObjects
.hbrushActiveCaption
);
172 /* FIXME: should draw parent' background somehow
173 (e.g for textured desktop) ? */
176 if (wndPtr
->class->hbrBackground
<= (HBRUSH16
)(COLOR_MAX
+1))
178 HBRUSH32 hbrush
= CreateSolidBrush32(
179 GetSysColor(((DWORD
)wndPtr
->class->hbrBackground
)-1));
180 FillWindow( GetParent16(wndPtr
->hwndSelf
), wndPtr
->hwndSelf
,
181 (HDC16
)wParam
, hbrush
);
182 DeleteObject32( hbrush
);
184 else FillWindow( GetParent16(wndPtr
->hwndSelf
), wndPtr
->hwndSelf
,
185 (HDC16
)wParam
, wndPtr
->class->hbrBackground
);
192 case WM_CTLCOLORMSGBOX
:
193 case WM_CTLCOLOREDIT
:
194 case WM_CTLCOLORLISTBOX
:
197 case WM_CTLCOLORSTATIC
:
198 SetBkColor( (HDC32
)wParam
, GetSysColor(COLOR_WINDOW
) );
199 SetTextColor( (HDC32
)wParam
, GetSysColor(COLOR_WINDOWTEXT
) );
200 return (LRESULT
)sysColorObjects
.hbrushWindow
;
202 case WM_CTLCOLORSCROLLBAR
:
203 SetBkColor( (HDC32
)wParam
, RGB(255, 255, 255) );
204 SetTextColor( (HDC32
)wParam
, RGB(0, 0, 0) );
205 UnrealizeObject32( sysColorObjects
.hbrushScrollbar
);
206 return (LRESULT
)sysColorObjects
.hbrushScrollbar
;
210 if (HIWORD(lParam
) == CTLCOLOR_SCROLLBAR
)
212 SetBkColor( (HDC32
)wParam
, RGB(255, 255, 255) );
213 SetTextColor( (HDC32
)wParam
, RGB(0, 0, 0) );
214 UnrealizeObject32( sysColorObjects
.hbrushScrollbar
);
215 return (LRESULT
)sysColorObjects
.hbrushScrollbar
;
219 SetBkColor( (HDC32
)wParam
, GetSysColor(COLOR_WINDOW
) );
220 SetTextColor( (HDC32
)wParam
, GetSysColor(COLOR_WINDOWTEXT
) );
221 return (LRESULT
)sysColorObjects
.hbrushWindow
;
225 case WM_GETTEXTLENGTH
:
226 if (wndPtr
->text
) return (LRESULT
)strlen(wndPtr
->text
);
230 if (wndPtr
->dwStyle
& WS_CHILD
)
231 if (SendMessage16(wndPtr
->parent
->hwndSelf
, WM_SETCURSOR
,
234 return NC_HandleSetCursor( wndPtr
->hwndSelf
, wParam
, lParam
);
237 return NC_HandleSysCommand( wndPtr
->hwndSelf
, wParam
,
238 MAKEPOINT16(lParam
) );
241 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
245 if( HIWORD(lParam
) & KEYDATA_ALT
)
247 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
248 if( wParam
== VK_MENU
&& !iMenuSysKey
)
256 else if( wParam
== VK_F10
)
259 if( wParam
== VK_ESCAPE
&& GetKeyState(VK_SHIFT
) < 0 )
260 SendMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
261 (WPARAM16
)SC_KEYMENU
, (LPARAM
)VK_SPACE
);
266 /* Press and release F10 or ALT */
267 if (((wParam
== VK_MENU
) && iMenuSysKey
) ||
268 ((wParam
== VK_F10
) && iF10Key
))
269 SendMessage16( WIN_GetTopParent(wndPtr
->hwndSelf
),
270 WM_SYSCOMMAND
, SC_KEYMENU
, 0L );
271 iMenuSysKey
= iF10Key
= 0;
276 if (wParam
== VK_RETURN
&& (wndPtr
->dwStyle
& WS_MINIMIZE
))
278 PostMessage( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
279 (WPARAM16
)SC_RESTORE
, 0L );
282 if ((HIWORD(lParam
) & KEYDATA_ALT
) && wParam
)
284 if (wParam
== VK_TAB
|| wParam
== VK_ESCAPE
) break;
285 if (wParam
== VK_SPACE
&& (wndPtr
->dwStyle
& WS_CHILD
))
286 SendMessage16( wndPtr
->parent
->hwndSelf
, msg
, wParam
, lParam
);
288 SendMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
289 (WPARAM16
)SC_KEYMENU
, (LPARAM
)(DWORD
)wParam
);
291 else /* check for Ctrl-Esc */
292 if (wParam
!= VK_ESCAPE
) MessageBeep(0);
296 if (!lParam
) return 0; /* sent from ShowWindow */
297 if (!(wndPtr
->dwStyle
& WS_POPUP
) || !wndPtr
->owner
) return 0;
298 if ((wndPtr
->dwStyle
& WS_VISIBLE
) && wParam
) return 0;
299 else if (!(wndPtr
->dwStyle
& WS_VISIBLE
) && !wParam
) return 0;
300 ShowWindow( wndPtr
->hwndSelf
, wParam
? SW_SHOWNOACTIVATE
: SW_HIDE
);
304 /* EndMenu() should be called if in menu state but currently it's
305 impossible to detect - menu code should be updated*/
306 if (GetCapture32() == wndPtr
->hwndSelf
) ReleaseCapture();
316 case WM_QUERYDROPOBJECT
:
317 if (wndPtr
->dwExStyle
& WS_EX_ACCEPTFILES
) return 1;
320 case WM_QUERYDRAGICON
:
325 if( (hI
= LoadIcon16(wndPtr
->hInstance
,MAKEINTRESOURCE(len
))) )
331 case WM_QUERYENDSESSION
:
339 /***********************************************************************
340 * DefWindowProc16 (USER.107)
342 LRESULT
DefWindowProc16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
345 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
348 if (!wndPtr
) return 0;
349 SPY_EnterMessage( SPY_DEFWNDPROC16
, hwnd
, msg
, wParam
, lParam
);
355 CREATESTRUCT16
*cs
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
);
357 DEFWND_SetText( wndPtr
, (LPSTR
)PTR_SEG_TO_LIN(cs
->lpszName
) );
363 result
= NC_HandleNCCalcSize(wndPtr
, (RECT16
*)PTR_SEG_TO_LIN(lParam
));
366 case WM_WINDOWPOSCHANGING
:
367 result
= WINPOS_HandleWindowPosChanging16( wndPtr
,
368 (WINDOWPOS16
*)PTR_SEG_TO_LIN(lParam
) );
371 case WM_WINDOWPOSCHANGED
:
373 WINDOWPOS16
* winPos
= (WINDOWPOS16
*)PTR_SEG_TO_LIN(lParam
);
374 DEFWND_HandleWindowPosChanged( wndPtr
, winPos
->flags
);
379 if (wParam
&& wndPtr
->text
)
381 lstrcpyn32A( (LPSTR
)PTR_SEG_TO_LIN(lParam
), wndPtr
->text
, wParam
);
382 result
= (LRESULT
)strlen( (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
387 DEFWND_SetText( wndPtr
, (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
388 NC_HandleNCPaint( hwnd
, (HRGN32
)1 ); /* Repaint caption */
392 result
= DEFWND_DefWinProc( wndPtr
, msg
, wParam
, lParam
);
396 SPY_ExitMessage( SPY_RESULT_OK16
, hwnd
, msg
, result
);
401 /***********************************************************************
402 * DefWindowProc32A (USER32.125)
404 LRESULT
DefWindowProc32A( HWND32 hwnd
, UINT32 msg
, WPARAM32 wParam
,
407 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
410 if (!wndPtr
) return 0;
411 SPY_EnterMessage( SPY_DEFWNDPROC32
, hwnd
, msg
, wParam
, lParam
);
417 CREATESTRUCT32A
*cs
= (CREATESTRUCT32A
*)lParam
;
418 if (cs
->lpszName
) DEFWND_SetText( wndPtr
, cs
->lpszName
);
426 CONV_RECT32TO16( (RECT32
*)lParam
, &rect16
);
427 result
= NC_HandleNCCalcSize( wndPtr
, &rect16
);
428 CONV_RECT16TO32( &rect16
, (RECT32
*)lParam
);
432 case WM_WINDOWPOSCHANGING
:
433 result
= WINPOS_HandleWindowPosChanging32( wndPtr
,
434 (WINDOWPOS32
*)lParam
);
437 case WM_WINDOWPOSCHANGED
:
439 WINDOWPOS32
* winPos
= (WINDOWPOS32
*)lParam
;
440 DEFWND_HandleWindowPosChanged( wndPtr
, winPos
->flags
);
445 if (wParam
&& wndPtr
->text
)
447 lstrcpyn32A( (LPSTR
)lParam
, wndPtr
->text
, wParam
);
448 result
= (LRESULT
)strlen( (LPSTR
)lParam
);
453 DEFWND_SetText( wndPtr
, (LPSTR
)lParam
);
454 NC_HandleNCPaint( hwnd
, (HRGN32
)1 ); /* Repaint caption */
458 result
= DEFWND_DefWinProc( wndPtr
, msg
, wParam
, lParam
);
462 SPY_ExitMessage( SPY_RESULT_OK32
, hwnd
, msg
, result
);
467 /***********************************************************************
468 * DefWindowProc32W (USER32.126)
470 LRESULT
DefWindowProc32W( HWND32 hwnd
, UINT32 msg
, WPARAM32 wParam
,
479 CREATESTRUCT32W
*cs
= (CREATESTRUCT32W
*)lParam
;
482 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
483 LPSTR str
= HEAP_strdupWtoA(GetProcessHeap(), 0, cs
->lpszName
);
484 DEFWND_SetText( wndPtr
, str
);
485 HeapFree( GetProcessHeap(), 0, str
);
493 LPSTR str
= HeapAlloc( GetProcessHeap(), 0, wParam
);
494 result
= DefWindowProc32A( hwnd
, msg
, wParam
, (LPARAM
)str
);
495 lstrcpynAtoW( (LPWSTR
)lParam
, str
, wParam
);
496 HeapFree( GetProcessHeap(), 0, str
);
502 LPSTR str
= HEAP_strdupWtoA( GetProcessHeap(), 0, (LPWSTR
)lParam
);
503 result
= DefWindowProc32A( hwnd
, msg
, wParam
, (LPARAM
)str
);
504 HeapFree( GetProcessHeap(), 0, str
);
509 result
= DefWindowProc32A( hwnd
, msg
, wParam
, lParam
);