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 case WM_NCRBUTTONDOWN
:
98 if( wndPtr
->flags
& WIN_ISWIN32
)
100 ClientToScreen16(wndPtr
->hwndSelf
, (LPPOINT16
)&lParam
);
101 SendMessage32A( wndPtr
->hwndSelf
, WM_CONTEXTMENU
,
102 wndPtr
->hwndSelf
, lParam
);
107 if( wndPtr
->dwStyle
& WS_CHILD
)
108 SendMessage32A( wndPtr
->parent
->hwndSelf
, msg
, wParam
, lParam
);
111 * FIXME: Track system popup if click was in the caption area. */
116 return NC_HandleNCActivate( wndPtr
, wParam
);
119 if (wndPtr
->text
) HeapFree( SystemHeap
, 0, wndPtr
->text
);
121 if (wndPtr
->pVScroll
) HeapFree( SystemHeap
, 0, wndPtr
->pVScroll
);
122 if (wndPtr
->pHScroll
) HeapFree( SystemHeap
, 0, wndPtr
->pHScroll
);
123 wndPtr
->pVScroll
= wndPtr
->pHScroll
= NULL
;
130 HDC16 hdc
= BeginPaint16( wndPtr
->hwndSelf
, &ps
);
133 if( (wndPtr
->dwStyle
& WS_MINIMIZE
) && wndPtr
->class->hIcon
)
135 int x
= (wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
-
136 SYSMETRICS_CXICON
)/2;
137 int y
= (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
-
138 SYSMETRICS_CYICON
)/2;
139 dprintf_win(stddeb
,"Painting class icon: vis rect=(%i,%i - %i,%i)\n",
140 ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
141 DrawIcon32( hdc
, x
, y
, wndPtr
->class->hIcon
);
143 EndPaint16( wndPtr
->hwndSelf
, &ps
);
151 ValidateRect32( wndPtr
->hwndSelf
, NULL
);
152 wndPtr
->flags
|= WIN_NO_REDRAW
;
156 wndPtr
->flags
&= ~WIN_NO_REDRAW
;
157 ShowWindow32( wndPtr
->hwndSelf
, SW_SHOW
);
162 DestroyWindow32( wndPtr
->hwndSelf
);
165 case WM_MOUSEACTIVATE
:
166 if (wndPtr
->dwStyle
& WS_CHILD
)
168 LONG ret
= SendMessage16( wndPtr
->parent
->hwndSelf
,
169 WM_MOUSEACTIVATE
, wParam
, lParam
);
175 if (LOWORD(wParam
) != WA_INACTIVE
) SetFocus32( wndPtr
->hwndSelf
);
179 case WM_ICONERASEBKGND
:
181 if (!wndPtr
->class->hbrBackground
) return 0;
183 /* FIXME: should fill icon text with hbrushActiveCaption
186 if (wndPtr
->dwStyle
& WS_MINIMIZE
)
188 if( wndPtr
->flags
& WIN_NCACTIVATED
)
190 FillWindow( GetParent16(wndPtr
->hwndSelf
), wndPtr
->hwndSelf
,
191 (HDC16
)wParam
, sysColorObjects
.hbrushActiveCaption
);
196 if (wndPtr
->class->hbrBackground
<= (HBRUSH16
)(COLOR_MAX
+1))
198 HBRUSH32 hbrush
= CreateSolidBrush32(
199 GetSysColor32(((DWORD
)wndPtr
->class->hbrBackground
)-1));
200 FillWindow( GetParent16(wndPtr
->hwndSelf
), wndPtr
->hwndSelf
,
201 (HDC16
)wParam
, hbrush
);
202 DeleteObject32( hbrush
);
204 else FillWindow( GetParent16(wndPtr
->hwndSelf
), wndPtr
->hwndSelf
,
205 (HDC16
)wParam
, wndPtr
->class->hbrBackground
);
212 case WM_CTLCOLORMSGBOX
:
213 case WM_CTLCOLOREDIT
:
214 case WM_CTLCOLORLISTBOX
:
217 case WM_CTLCOLORSTATIC
:
218 SetBkColor( (HDC32
)wParam
, GetSysColor32(COLOR_WINDOW
) );
219 SetTextColor( (HDC32
)wParam
, GetSysColor32(COLOR_WINDOWTEXT
) );
220 return (LRESULT
)sysColorObjects
.hbrushWindow
;
222 case WM_CTLCOLORSCROLLBAR
:
223 SetBkColor( (HDC32
)wParam
, RGB(255, 255, 255) );
224 SetTextColor( (HDC32
)wParam
, RGB(0, 0, 0) );
225 UnrealizeObject32( sysColorObjects
.hbrushScrollbar
);
226 return (LRESULT
)sysColorObjects
.hbrushScrollbar
;
230 if (HIWORD(lParam
) == CTLCOLOR_SCROLLBAR
)
232 SetBkColor( (HDC32
)wParam
, RGB(255, 255, 255) );
233 SetTextColor( (HDC32
)wParam
, RGB(0, 0, 0) );
234 UnrealizeObject32( sysColorObjects
.hbrushScrollbar
);
235 return (LRESULT
)sysColorObjects
.hbrushScrollbar
;
239 SetBkColor( (HDC32
)wParam
, GetSysColor32(COLOR_WINDOW
) );
240 SetTextColor( (HDC32
)wParam
, GetSysColor32(COLOR_WINDOWTEXT
) );
241 return (LRESULT
)sysColorObjects
.hbrushWindow
;
245 case WM_GETTEXTLENGTH
:
246 if (wndPtr
->text
) return (LRESULT
)strlen(wndPtr
->text
);
250 if (wndPtr
->dwStyle
& WS_CHILD
)
251 if (SendMessage16(wndPtr
->parent
->hwndSelf
, WM_SETCURSOR
,
254 return NC_HandleSetCursor( wndPtr
->hwndSelf
, wParam
, lParam
);
257 return NC_HandleSysCommand( wndPtr
->hwndSelf
, wParam
,
258 MAKEPOINT16(lParam
) );
261 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
265 if( HIWORD(lParam
) & KEYDATA_ALT
)
267 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
268 if( wParam
== VK_MENU
&& !iMenuSysKey
)
276 else if( wParam
== VK_F10
)
279 if( wParam
== VK_ESCAPE
&& (GetKeyState32(VK_SHIFT
) & 0x8000))
280 SendMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
281 (WPARAM16
)SC_KEYMENU
, (LPARAM
)VK_SPACE
);
286 /* Press and release F10 or ALT */
287 if (((wParam
== VK_MENU
) && iMenuSysKey
) ||
288 ((wParam
== VK_F10
) && iF10Key
))
289 SendMessage16( WIN_GetTopParent(wndPtr
->hwndSelf
),
290 WM_SYSCOMMAND
, SC_KEYMENU
, 0L );
291 iMenuSysKey
= iF10Key
= 0;
296 if (wParam
== VK_RETURN
&& (wndPtr
->dwStyle
& WS_MINIMIZE
))
298 PostMessage( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
299 (WPARAM16
)SC_RESTORE
, 0L );
302 if ((HIWORD(lParam
) & KEYDATA_ALT
) && wParam
)
304 if (wParam
== VK_TAB
|| wParam
== VK_ESCAPE
) break;
305 if (wParam
== VK_SPACE
&& (wndPtr
->dwStyle
& WS_CHILD
))
306 SendMessage16( wndPtr
->parent
->hwndSelf
, msg
, wParam
, lParam
);
308 SendMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
309 (WPARAM16
)SC_KEYMENU
, (LPARAM
)(DWORD
)wParam
);
311 else /* check for Ctrl-Esc */
312 if (wParam
!= VK_ESCAPE
) MessageBeep32(0);
316 if (!lParam
) return 0; /* sent from ShowWindow */
317 if (!(wndPtr
->dwStyle
& WS_POPUP
) || !wndPtr
->owner
) return 0;
318 if ((wndPtr
->dwStyle
& WS_VISIBLE
) && wParam
) return 0;
319 else if (!(wndPtr
->dwStyle
& WS_VISIBLE
) && !wParam
) return 0;
320 ShowWindow32( wndPtr
->hwndSelf
, wParam
? SW_SHOWNOACTIVATE
: SW_HIDE
);
324 /* EndMenu() should be called if in menu state but currently it's
325 impossible to detect - menu code should be updated*/
326 if (GetCapture32() == wndPtr
->hwndSelf
) ReleaseCapture();
336 case WM_QUERYDROPOBJECT
:
337 if (wndPtr
->dwExStyle
& WS_EX_ACCEPTFILES
) return 1;
340 case WM_QUERYDRAGICON
:
345 if( (hI
= LoadIcon16(wndPtr
->hInstance
,MAKEINTRESOURCE(len
))) )
351 case WM_QUERYENDSESSION
:
359 /***********************************************************************
360 * DefWindowProc16 (USER.107)
362 LRESULT
DefWindowProc16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
365 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
368 if (!wndPtr
) return 0;
369 SPY_EnterMessage( SPY_DEFWNDPROC16
, hwnd
, msg
, wParam
, lParam
);
375 CREATESTRUCT16
*cs
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
);
377 DEFWND_SetText( wndPtr
, (LPSTR
)PTR_SEG_TO_LIN(cs
->lpszName
) );
383 result
= NC_HandleNCCalcSize(wndPtr
, (RECT16
*)PTR_SEG_TO_LIN(lParam
));
386 case WM_WINDOWPOSCHANGING
:
387 result
= WINPOS_HandleWindowPosChanging16( wndPtr
,
388 (WINDOWPOS16
*)PTR_SEG_TO_LIN(lParam
) );
391 case WM_WINDOWPOSCHANGED
:
393 WINDOWPOS16
* winPos
= (WINDOWPOS16
*)PTR_SEG_TO_LIN(lParam
);
394 DEFWND_HandleWindowPosChanged( wndPtr
, winPos
->flags
);
399 if (wParam
&& wndPtr
->text
)
401 lstrcpyn32A( (LPSTR
)PTR_SEG_TO_LIN(lParam
), wndPtr
->text
, wParam
);
402 result
= (LRESULT
)strlen( (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
407 DEFWND_SetText( wndPtr
, (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
408 NC_HandleNCPaint( hwnd
, (HRGN32
)1 ); /* Repaint caption */
412 result
= DEFWND_DefWinProc( wndPtr
, msg
, wParam
, lParam
);
416 SPY_ExitMessage( SPY_RESULT_OK16
, hwnd
, msg
, result
);
421 /***********************************************************************
422 * DefWindowProc32A (USER32.125)
424 LRESULT
DefWindowProc32A( HWND32 hwnd
, UINT32 msg
, WPARAM32 wParam
,
427 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
430 if (!wndPtr
) return 0;
431 SPY_EnterMessage( SPY_DEFWNDPROC32
, hwnd
, msg
, wParam
, lParam
);
437 CREATESTRUCT32A
*cs
= (CREATESTRUCT32A
*)lParam
;
438 if (cs
->lpszName
) DEFWND_SetText( wndPtr
, cs
->lpszName
);
446 CONV_RECT32TO16( (RECT32
*)lParam
, &rect16
);
447 result
= NC_HandleNCCalcSize( wndPtr
, &rect16
);
448 CONV_RECT16TO32( &rect16
, (RECT32
*)lParam
);
452 case WM_WINDOWPOSCHANGING
:
453 result
= WINPOS_HandleWindowPosChanging32( wndPtr
,
454 (WINDOWPOS32
*)lParam
);
457 case WM_WINDOWPOSCHANGED
:
459 WINDOWPOS32
* winPos
= (WINDOWPOS32
*)lParam
;
460 DEFWND_HandleWindowPosChanged( wndPtr
, winPos
->flags
);
465 if (wParam
&& wndPtr
->text
)
467 lstrcpyn32A( (LPSTR
)lParam
, wndPtr
->text
, wParam
);
468 result
= (LRESULT
)strlen( (LPSTR
)lParam
);
473 DEFWND_SetText( wndPtr
, (LPSTR
)lParam
);
474 NC_HandleNCPaint( hwnd
, (HRGN32
)1 ); /* Repaint caption */
478 result
= DEFWND_DefWinProc( wndPtr
, msg
, wParam
, lParam
);
482 SPY_ExitMessage( SPY_RESULT_OK32
, hwnd
, msg
, result
);
487 /***********************************************************************
488 * DefWindowProc32W (USER32.126)
490 LRESULT
DefWindowProc32W( HWND32 hwnd
, UINT32 msg
, WPARAM32 wParam
,
499 CREATESTRUCT32W
*cs
= (CREATESTRUCT32W
*)lParam
;
502 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
503 LPSTR str
= HEAP_strdupWtoA(GetProcessHeap(), 0, cs
->lpszName
);
504 DEFWND_SetText( wndPtr
, str
);
505 HeapFree( GetProcessHeap(), 0, str
);
513 LPSTR str
= HeapAlloc( GetProcessHeap(), 0, wParam
);
514 result
= DefWindowProc32A( hwnd
, msg
, wParam
, (LPARAM
)str
);
515 lstrcpynAtoW( (LPWSTR
)lParam
, str
, wParam
);
516 HeapFree( GetProcessHeap(), 0, str
);
522 LPSTR str
= HEAP_strdupWtoA( GetProcessHeap(), 0, (LPWSTR
)lParam
);
523 result
= DefWindowProc32A( hwnd
, msg
, wParam
, (LPARAM
)str
);
524 HeapFree( GetProcessHeap(), 0, str
);
529 result
= DefWindowProc32A( hwnd
, msg
, wParam
, lParam
);