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 extern void EndMenu(void);
33 /***********************************************************************
34 * DEFWND_HandleWindowPosChanged
36 * Handle the WM_WINDOWPOSCHANGED message.
38 static void DEFWND_HandleWindowPosChanged( WND
*wndPtr
, UINT32 flags
)
40 WPARAM16 wp
= SIZE_RESTORED
;
42 if (!(flags
& SWP_NOCLIENTMOVE
))
43 SendMessage16( wndPtr
->hwndSelf
, WM_MOVE
, 0,
44 MAKELONG(wndPtr
->rectClient
.left
, wndPtr
->rectClient
.top
));
45 if (!(flags
& SWP_NOCLIENTSIZE
))
47 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wp
= SIZE_MAXIMIZED
;
48 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wp
= SIZE_MINIMIZED
;
50 SendMessage16( wndPtr
->hwndSelf
, WM_SIZE
, wp
,
51 MAKELONG(wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
52 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
));
57 /***********************************************************************
60 * Set the window text.
62 void DEFWND_SetText( WND
*wndPtr
, LPCSTR text
)
65 if (wndPtr
->text
) HeapFree( SystemHeap
, 0, wndPtr
->text
);
66 wndPtr
->text
= HEAP_strdupA( SystemHeap
, 0, text
);
69 XStoreName( display
, wndPtr
->window
, wndPtr
->text
);
70 XSetIconName( display
, wndPtr
->window
, wndPtr
->text
);
75 /***********************************************************************
78 * Default window procedure for messages that are the same in Win16 and Win32.
80 static LRESULT
DEFWND_DefWinProc( WND
*wndPtr
, UINT32 msg
, WPARAM32 wParam
,
86 return NC_HandleNCPaint( wndPtr
->hwndSelf
, (HRGN32
)wParam
);
89 return NC_HandleNCHitTest( wndPtr
->hwndSelf
, MAKEPOINT16(lParam
) );
91 case WM_NCLBUTTONDOWN
:
92 return NC_HandleNCLButtonDown( wndPtr
->hwndSelf
, wParam
, lParam
);
94 case WM_LBUTTONDBLCLK
:
95 case WM_NCLBUTTONDBLCLK
:
96 return NC_HandleNCLButtonDblClk( wndPtr
, wParam
, lParam
);
99 case WM_NCRBUTTONDOWN
:
100 if( wndPtr
->flags
& WIN_ISWIN32
)
102 ClientToScreen16(wndPtr
->hwndSelf
, (LPPOINT16
)&lParam
);
103 SendMessage32A( wndPtr
->hwndSelf
, WM_CONTEXTMENU
,
104 wndPtr
->hwndSelf
, lParam
);
109 if( wndPtr
->dwStyle
& WS_CHILD
)
110 SendMessage32A( wndPtr
->parent
->hwndSelf
, msg
, wParam
, lParam
);
113 * FIXME: Track system popup if click was in the caption area. */
118 return NC_HandleNCActivate( wndPtr
, wParam
);
121 if (wndPtr
->text
) HeapFree( SystemHeap
, 0, wndPtr
->text
);
123 if (wndPtr
->pVScroll
) HeapFree( SystemHeap
, 0, wndPtr
->pVScroll
);
124 if (wndPtr
->pHScroll
) HeapFree( SystemHeap
, 0, wndPtr
->pHScroll
);
125 wndPtr
->pVScroll
= wndPtr
->pHScroll
= NULL
;
132 HDC16 hdc
= BeginPaint16( wndPtr
->hwndSelf
, &ps
);
135 if( (wndPtr
->dwStyle
& WS_MINIMIZE
) && wndPtr
->class->hIcon
)
137 int x
= (wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
-
138 SYSMETRICS_CXICON
)/2;
139 int y
= (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
-
140 SYSMETRICS_CYICON
)/2;
141 dprintf_win(stddeb
,"Painting class icon: vis rect=(%i,%i - %i,%i)\n",
142 ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
143 DrawIcon32( hdc
, x
, y
, wndPtr
->class->hIcon
);
145 EndPaint16( wndPtr
->hwndSelf
, &ps
);
153 ValidateRect32( wndPtr
->hwndSelf
, NULL
);
154 wndPtr
->flags
|= WIN_NO_REDRAW
;
158 wndPtr
->flags
&= ~WIN_NO_REDRAW
;
159 ShowWindow32( wndPtr
->hwndSelf
, SW_SHOW
);
164 DestroyWindow32( wndPtr
->hwndSelf
);
167 case WM_MOUSEACTIVATE
:
168 if (wndPtr
->dwStyle
& WS_CHILD
)
170 LONG ret
= SendMessage16( wndPtr
->parent
->hwndSelf
,
171 WM_MOUSEACTIVATE
, wParam
, lParam
);
175 /* Caption clicks are handled by the NC_HandleNCLButtonDown() */
176 return (LOWORD(lParam
) == HTCAPTION
) ? MA_NOACTIVATE
: MA_ACTIVATE
;
179 if (LOWORD(wParam
) != WA_INACTIVE
) SetFocus32( wndPtr
->hwndSelf
);
183 case WM_ICONERASEBKGND
:
185 if (!wndPtr
->class->hbrBackground
) return 0;
187 if (wndPtr
->class->hbrBackground
<= (HBRUSH16
)(COLOR_MAX
+1))
189 HBRUSH32 hbrush
= CreateSolidBrush32(
190 GetSysColor32(((DWORD
)wndPtr
->class->hbrBackground
)-1));
191 FillWindow( GetParent16(wndPtr
->hwndSelf
), wndPtr
->hwndSelf
,
192 (HDC16
)wParam
, hbrush
);
193 DeleteObject32( hbrush
);
195 else FillWindow( GetParent16(wndPtr
->hwndSelf
), wndPtr
->hwndSelf
,
196 (HDC16
)wParam
, wndPtr
->class->hbrBackground
);
203 case WM_CTLCOLORMSGBOX
:
204 case WM_CTLCOLOREDIT
:
205 case WM_CTLCOLORLISTBOX
:
208 case WM_CTLCOLORSTATIC
:
209 SetBkColor32( (HDC32
)wParam
, GetSysColor32(COLOR_WINDOW
) );
210 SetTextColor32( (HDC32
)wParam
, GetSysColor32(COLOR_WINDOWTEXT
) );
211 return (LRESULT
)sysColorObjects
.hbrushWindow
;
213 case WM_CTLCOLORSCROLLBAR
:
214 SetBkColor32( (HDC32
)wParam
, RGB(255, 255, 255) );
215 SetTextColor32( (HDC32
)wParam
, RGB(0, 0, 0) );
216 UnrealizeObject32( sysColorObjects
.hbrushScrollbar
);
217 return (LRESULT
)sysColorObjects
.hbrushScrollbar
;
221 if (HIWORD(lParam
) == CTLCOLOR_SCROLLBAR
)
223 SetBkColor32( (HDC32
)wParam
, RGB(255, 255, 255) );
224 SetTextColor32( (HDC32
)wParam
, RGB(0, 0, 0) );
225 UnrealizeObject32( sysColorObjects
.hbrushScrollbar
);
226 return (LRESULT
)sysColorObjects
.hbrushScrollbar
;
230 SetBkColor32( (HDC32
)wParam
, GetSysColor32(COLOR_WINDOW
) );
231 SetTextColor32((HDC32
)wParam
, GetSysColor32(COLOR_WINDOWTEXT
));
232 return (LRESULT
)sysColorObjects
.hbrushWindow
;
236 case WM_GETTEXTLENGTH
:
237 if (wndPtr
->text
) return (LRESULT
)strlen(wndPtr
->text
);
241 if (wndPtr
->dwStyle
& WS_CHILD
)
242 if (SendMessage16(wndPtr
->parent
->hwndSelf
, WM_SETCURSOR
,
245 return NC_HandleSetCursor( wndPtr
->hwndSelf
, wParam
, lParam
);
248 return NC_HandleSysCommand( wndPtr
->hwndSelf
, wParam
,
249 MAKEPOINT16(lParam
) );
252 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
256 if( HIWORD(lParam
) & KEYDATA_ALT
)
258 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
259 if( wParam
== VK_MENU
&& !iMenuSysKey
)
266 if( wParam
== VK_F4
) /* try to close the window */
268 HWND32 hWnd
= WIN_GetTopParent( wndPtr
->hwndSelf
);
269 wndPtr
= WIN_FindWndPtr( hWnd
);
270 if( wndPtr
&& !(wndPtr
->class->style
& CS_NOCLOSE
) )
271 PostMessage16( hWnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0 );
274 else if( wParam
== VK_F10
)
277 if( wParam
== VK_ESCAPE
&& (GetKeyState32(VK_SHIFT
) & 0x8000))
278 SendMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
279 (WPARAM16
)SC_KEYMENU
, (LPARAM
)VK_SPACE
);
284 /* Press and release F10 or ALT */
285 if (((wParam
== VK_MENU
) && iMenuSysKey
) ||
286 ((wParam
== VK_F10
) && iF10Key
))
287 SendMessage16( WIN_GetTopParent(wndPtr
->hwndSelf
),
288 WM_SYSCOMMAND
, SC_KEYMENU
, 0L );
289 iMenuSysKey
= iF10Key
= 0;
294 if (wParam
== VK_RETURN
&& (wndPtr
->dwStyle
& WS_MINIMIZE
))
296 PostMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
297 (WPARAM16
)SC_RESTORE
, 0L );
300 if ((HIWORD(lParam
) & KEYDATA_ALT
) && wParam
)
302 if (wParam
== VK_TAB
|| wParam
== VK_ESCAPE
) break;
303 if (wParam
== VK_SPACE
&& (wndPtr
->dwStyle
& WS_CHILD
))
304 SendMessage16( wndPtr
->parent
->hwndSelf
, msg
, wParam
, lParam
);
306 SendMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
307 (WPARAM16
)SC_KEYMENU
, (LPARAM
)(DWORD
)wParam
);
309 else /* check for Ctrl-Esc */
310 if (wParam
!= VK_ESCAPE
) MessageBeep32(0);
314 if (!lParam
) return 0; /* sent from ShowWindow */
315 if (!(wndPtr
->dwStyle
& WS_POPUP
) || !wndPtr
->owner
) return 0;
316 if ((wndPtr
->dwStyle
& WS_VISIBLE
) && wParam
) return 0;
317 else if (!(wndPtr
->dwStyle
& WS_VISIBLE
) && !wParam
) return 0;
318 ShowWindow32( wndPtr
->hwndSelf
, wParam
? SW_SHOWNOACTIVATE
: SW_HIDE
);
322 if (wndPtr
->parent
== WIN_GetDesktop()) EndMenu();
323 if (GetCapture32() == wndPtr
->hwndSelf
) ReleaseCapture();
333 case WM_QUERYDROPOBJECT
:
334 if (wndPtr
->dwExStyle
& WS_EX_ACCEPTFILES
) return 1;
337 case WM_QUERYDRAGICON
:
342 if( (hI
= LoadIcon16(wndPtr
->hInstance
,MAKEINTRESOURCE(len
))) )
347 case WM_ISACTIVEICON
:
348 return ((wndPtr
->flags
& WIN_NCACTIVATED
) != 0);
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 if( wndPtr
->dwStyle
& WS_CAPTION
) NC_HandleNCPaint( hwnd
, (HRGN32
)1 );
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
);