2 * Default window procedure
4 * Copyright 1993 Alexandre Julliard
13 #include "nonclient.h"
18 /* #define DEBUG_MESSAGE */
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;
33 /***********************************************************************
34 * DEFWND_InitSysMenuPopup
36 * Handle the WM_INITMENUPOPUP message on the system menu.
38 static void DEFWND_InitSysMenuPopup( HMENU hmenu
, DWORD style
, DWORD clsStyle
)
42 gray
= !(style
& WS_THICKFRAME
) || (style
& (WS_MAXIMIZE
| WS_MINIMIZE
));
43 EnableMenuItem( hmenu
, SC_SIZE
, (gray
? MF_GRAYED
: MF_ENABLED
) );
44 gray
= ((style
& WS_MAXIMIZE
) != 0);
45 EnableMenuItem( hmenu
, SC_MOVE
, (gray
? MF_GRAYED
: MF_ENABLED
) );
46 gray
= !(style
& WS_MINIMIZEBOX
) || (style
& WS_MINIMIZE
);
47 EnableMenuItem( hmenu
, SC_MINIMIZE
, (gray
? MF_GRAYED
: MF_ENABLED
) );
48 gray
= !(style
& WS_MAXIMIZEBOX
) || (style
& WS_MAXIMIZE
);
49 EnableMenuItem( hmenu
, SC_MAXIMIZE
, (gray
? MF_GRAYED
: MF_ENABLED
) );
50 gray
= !(style
& (WS_MAXIMIZE
| WS_MINIMIZE
));
51 EnableMenuItem( hmenu
, SC_RESTORE
, (gray
? MF_GRAYED
: MF_ENABLED
) );
52 gray
= (clsStyle
& CS_NOCLOSE
) != 0;
53 EnableMenuItem( hmenu
, SC_CLOSE
, (gray
? MF_GRAYED
: MF_ENABLED
) );
57 /***********************************************************************
58 * DEFWND_HandleWindowPosChanged
60 * Handle the WM_WINDOWPOSCHANGED message.
62 static void DEFWND_HandleWindowPosChanged( WND
*wndPtr
, UINT32 flags
)
64 WPARAM16 wp
= SIZE_RESTORED
;
66 if (!(flags
& SWP_NOCLIENTMOVE
))
67 SendMessage16( wndPtr
->hwndSelf
, WM_MOVE
, 0,
68 MAKELONG(wndPtr
->rectClient
.left
, wndPtr
->rectClient
.top
));
69 if (!(flags
& SWP_NOCLIENTSIZE
))
71 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wp
= SIZE_MAXIMIZED
;
72 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wp
= SIZE_MINIMIZED
;
74 SendMessage16( wndPtr
->hwndSelf
, WM_SIZE
, wp
,
75 MAKELONG(wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
76 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
));
81 /***********************************************************************
84 * Set the window text.
86 void DEFWND_SetText( WND
*wndPtr
, LPCSTR text
)
89 if (wndPtr
->text
) HeapFree( SystemHeap
, 0, wndPtr
->text
);
90 wndPtr
->text
= HEAP_strdupA( SystemHeap
, 0, text
);
91 if (wndPtr
->window
) XStoreName( display
, wndPtr
->window
, wndPtr
->text
);
95 /***********************************************************************
98 * Default window procedure for messages that are the same in Win16 and Win32.
100 static LRESULT
DEFWND_DefWinProc( WND
*wndPtr
, UINT32 msg
, WPARAM32 wParam
,
103 HWND16 hwnd
= wndPtr
->hwndSelf
;
109 return NC_HandleNCPaint( hwnd
, (HRGN
)wParam
);
112 return NC_HandleNCHitTest( hwnd
, MAKEPOINT16(lParam
) );
114 case WM_NCLBUTTONDOWN
:
115 return NC_HandleNCLButtonDown( hwnd
, wParam
, lParam
);
117 case WM_LBUTTONDBLCLK
:
118 case WM_NCLBUTTONDBLCLK
:
119 return NC_HandleNCLButtonDblClk( wndPtr
, wParam
, lParam
);
122 return NC_HandleNCActivate( hwnd
, wParam
);
125 if (wndPtr
->text
) HeapFree( SystemHeap
, 0, wndPtr
->text
);
127 if (wndPtr
->hVScroll
) USER_HEAP_FREE(wndPtr
->hVScroll
);
128 if (wndPtr
->hHScroll
) USER_HEAP_FREE(wndPtr
->hHScroll
);
129 wndPtr
->hVScroll
= wndPtr
->hHScroll
= 0;
134 PAINTSTRUCT16 paintstruct
;
135 BeginPaint16( hwnd
, &paintstruct
);
136 EndPaint16( hwnd
, &paintstruct
);
143 ValidateRect32( hwnd
, NULL
);
144 wndPtr
->flags
|= WIN_NO_REDRAW
;
146 else wndPtr
->flags
&= ~WIN_NO_REDRAW
;
150 DestroyWindow( hwnd
);
153 case WM_MOUSEACTIVATE
:
154 if (wndPtr
->dwStyle
& WS_CHILD
)
156 LONG ret
= SendMessage16( wndPtr
->parent
->hwndSelf
, WM_MOUSEACTIVATE
,
163 if (LOWORD(wParam
) != WA_INACTIVE
) SetFocus( hwnd
);
167 case WM_ICONERASEBKGND
:
169 if (!wndPtr
->class->hbrBackground
) return 0;
170 if (wndPtr
->class->hbrBackground
<= (HBRUSH
)(COLOR_MAX
+1))
173 hbrush
= CreateSolidBrush(
174 GetSysColor(((DWORD
)wndPtr
->class->hbrBackground
)-1));
175 FillWindow( GetParent(hwnd
), hwnd
, (HDC
)wParam
, hbrush
);
176 DeleteObject (hbrush
);
179 FillWindow( GetParent(hwnd
), hwnd
, (HDC
)wParam
,
180 wndPtr
->class->hbrBackground
);
187 case WM_CTLCOLORMSGBOX
:
188 case WM_CTLCOLOREDIT
:
189 case WM_CTLCOLORLISTBOX
:
192 case WM_CTLCOLORSTATIC
:
193 SetBkColor( (HDC
)wParam
, GetSysColor(COLOR_WINDOW
) );
194 SetTextColor( (HDC
)wParam
, GetSysColor(COLOR_WINDOWTEXT
) );
195 return (LRESULT
)sysColorObjects
.hbrushWindow
;
197 case WM_CTLCOLORSCROLLBAR
:
198 SetBkColor( (HDC
)wParam
, RGB(255, 255, 255) );
199 SetTextColor( (HDC
)wParam
, RGB(0, 0, 0) );
200 UnrealizeObject( sysColorObjects
.hbrushScrollbar
);
201 return (LRESULT
)sysColorObjects
.hbrushScrollbar
;
205 if (HIWORD(lParam
) == CTLCOLOR_SCROLLBAR
)
207 SetBkColor( (HDC
)wParam
, RGB(255, 255, 255) );
208 SetTextColor( (HDC
)wParam
, RGB(0, 0, 0) );
209 UnrealizeObject( sysColorObjects
.hbrushScrollbar
);
210 return (LRESULT
)sysColorObjects
.hbrushScrollbar
;
214 SetBkColor( (HDC
)wParam
, GetSysColor(COLOR_WINDOW
) );
215 SetTextColor( (HDC
)wParam
, GetSysColor(COLOR_WINDOWTEXT
) );
216 return (LRESULT
)sysColorObjects
.hbrushWindow
;
220 case WM_GETTEXTLENGTH
:
221 if (wndPtr
->text
) return (LRESULT
)strlen(wndPtr
->text
);
225 if (wndPtr
->dwStyle
& WS_CHILD
)
226 if (SendMessage16(wndPtr
->parent
->hwndSelf
, WM_SETCURSOR
,
229 return NC_HandleSetCursor( hwnd
, wParam
, lParam
);
232 return NC_HandleSysCommand( hwnd
, wParam
, MAKEPOINT16(lParam
) );
235 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
239 if( HIWORD(lParam
) & KEYDATA_ALT
)
241 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
242 if( wParam
== VK_MENU
&& !iMenuSysKey
)
250 else if( wParam
== VK_F10
)
253 if( wParam
== VK_ESCAPE
&& GetKeyState(VK_SHIFT
) < 0 )
254 SendMessage16( hwnd
, WM_SYSCOMMAND
, (WPARAM
)SC_KEYMENU
,
260 /* Press and release F10 or ALT */
261 if (((wParam
== VK_MENU
) && iMenuSysKey
) ||
262 ((wParam
== VK_F10
) && iF10Key
))
263 SendMessage16( WIN_GetTopParent(hwnd
), WM_SYSCOMMAND
,
265 iMenuSysKey
= iF10Key
= 0;
270 if (wParam
== VK_RETURN
&& (wndPtr
->dwStyle
& WS_MINIMIZE
))
272 PostMessage(hwnd
, WM_SYSCOMMAND
, (WPARAM
)SC_RESTORE
, 0L );
275 if ((HIWORD(lParam
) & KEYDATA_ALT
) && wParam
)
277 if (wParam
== VK_TAB
|| wParam
== VK_ESCAPE
) break;
278 if (wParam
== VK_SPACE
&& (wndPtr
->dwStyle
& WS_CHILD
))
279 SendMessage16( wndPtr
->parent
->hwndSelf
, msg
, wParam
, lParam
);
281 SendMessage16( hwnd
, WM_SYSCOMMAND
, (WPARAM
)SC_KEYMENU
, (LPARAM
)(DWORD
)wParam
);
283 else /* check for Ctrl-Esc */
284 if (wParam
!= VK_ESCAPE
) MessageBeep(0);
288 if (!lParam
) return 0; /* sent from ShowWindow */
289 if (!(wndPtr
->dwStyle
& WS_POPUP
) || !wndPtr
->owner
) return 0;
290 if ((wndPtr
->dwStyle
& WS_VISIBLE
) && wParam
) return 0;
291 else if (!(wndPtr
->dwStyle
& WS_VISIBLE
) && !wParam
) return 0;
292 ShowWindow( hwnd
, wParam
? SW_SHOWNOACTIVATE
: SW_HIDE
);
295 case WM_INITMENUPOPUP
:
296 /* Not absolutely sure this belongs here -- AJ */
297 if (HIWORD(lParam
)) /* system menu */
298 DEFWND_InitSysMenuPopup( (HMENU
)wParam
, wndPtr
->dwStyle
,
299 wndPtr
->class->style
);
303 /* EndMenu() should be called if in menu state but currently it's
304 impossible to detect - menu code should be updated*/
305 if (GetCapture() == hwnd
) ReleaseCapture();
315 case WM_QUERYDROPOBJECT
:
316 if (wndPtr
->dwExStyle
& WS_EX_ACCEPTFILES
) return 1;
319 case WM_QUERYDRAGICON
:
324 if( (hI
= LoadIcon(wndPtr
->hInstance
,MAKEINTRESOURCE(len
))) )
330 case WM_QUERYENDSESSION
:
338 /***********************************************************************
339 * DefWindowProc16 (USER.107)
341 LRESULT
DefWindowProc16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
344 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
347 SPY_EnterMessage( SPY_DEFWNDPROC16
, hwnd
, msg
, wParam
, lParam
);
353 CREATESTRUCT16
*cs
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
);
355 DEFWND_SetText( wndPtr
, (LPSTR
)PTR_SEG_TO_LIN(cs
->lpszName
) );
361 result
= NC_HandleNCCalcSize(wndPtr
, (RECT16
*)PTR_SEG_TO_LIN(lParam
));
364 case WM_WINDOWPOSCHANGING
:
365 result
= WINPOS_HandleWindowPosChanging16( wndPtr
,
366 (WINDOWPOS16
*)PTR_SEG_TO_LIN(lParam
) );
369 case WM_WINDOWPOSCHANGED
:
371 WINDOWPOS16
* winPos
= (WINDOWPOS16
*)PTR_SEG_TO_LIN(lParam
);
372 DEFWND_HandleWindowPosChanged( wndPtr
, winPos
->flags
);
377 if (wParam
&& wndPtr
->text
)
379 lstrcpyn( (LPSTR
)PTR_SEG_TO_LIN(lParam
), wndPtr
->text
, wParam
);
380 result
= (LRESULT
)strlen( (LPSTR
)PTR_SEG_TO_LIN(lParam
) ) + 1;
385 DEFWND_SetText( wndPtr
, (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
386 NC_HandleNCPaint( hwnd
, (HRGN
)1 ); /* Repaint caption */
390 result
= DEFWND_DefWinProc( wndPtr
, msg
, wParam
, lParam
);
394 SPY_ExitMessage( SPY_RESULT_OK16
, hwnd
, msg
, result
);
399 /***********************************************************************
400 * DefWindowProc32A (USER32.125)
402 LRESULT
DefWindowProc32A( HWND32 hwnd
, UINT32 msg
, WPARAM32 wParam
,
405 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
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 lstrcpyn( (LPSTR
)lParam
, wndPtr
->text
, wParam
);
445 result
= (LRESULT
)strlen( (LPSTR
)lParam
) + 1;
450 DEFWND_SetText( wndPtr
, (LPSTR
)lParam
);
451 NC_HandleNCPaint( hwnd
, (HRGN
)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
);
489 LPSTR str
= malloc( wParam
);
490 result
= DefWindowProc32A( hwnd
, msg
, wParam
, (LPARAM
)str
);
491 STRING32_AnsiToUni( (LPWSTR
)lParam
, str
);
498 LPSTR str
= STRING32_DupUniToAnsi( (LPWSTR
)lParam
);
499 result
= DefWindowProc32A( hwnd
, msg
, wParam
, (LPARAM
)str
);
505 result
= DefWindowProc32A( hwnd
, msg
, wParam
, lParam
);