2 * Default window procedure
4 * Copyright 1993 Alexandre Julliard
13 #include "nonclient.h"
17 /* #define DEBUG_MESSAGE */
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 /***********************************************************************
34 * Set the window text.
36 void DEFWND_SetText( HWND hwnd
, LPSTR text
)
39 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
42 if (wndPtr
->hText
) USER_HEAP_FREE( wndPtr
->hText
);
43 wndPtr
->hText
= USER_HEAP_ALLOC( strlen(text
) + 1 );
44 textPtr
= (LPSTR
) USER_HEAP_LIN_ADDR( wndPtr
->hText
);
45 strcpy( textPtr
, text
);
47 XStoreName( display
, wndPtr
->window
, text
);
51 /***********************************************************************
52 * DefWindowProc (USER.107)
54 LRESULT
DefWindowProc( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
59 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
61 SPY_EnterMessage( SPY_DEFWNDPROC
, hwnd
, msg
, wParam
, lParam
);
67 CREATESTRUCT
*createStruct
= (CREATESTRUCT
*)PTR_SEG_TO_LIN(lParam
);
68 if (createStruct
->lpszName
)
70 (LPSTR
)PTR_SEG_TO_LIN(createStruct
->lpszName
) );
75 return NC_HandleNCCalcSize( hwnd
,
76 (NCCALCSIZE_PARAMS
*)PTR_SEG_TO_LIN(lParam
) );
80 return NC_HandleNCPaint( hwnd
, (HRGN
)wParam
);
84 POINT pt
= { LOWORD(lParam
), HIWORD(lParam
) };
85 return NC_HandleNCHitTest( hwnd
, pt
);
88 case WM_NCLBUTTONDOWN
:
89 return NC_HandleNCLButtonDown( hwnd
, wParam
, lParam
);
91 case WM_LBUTTONDBLCLK
:
92 case WM_NCLBUTTONDBLCLK
:
93 return NC_HandleNCLButtonDblClk( hwnd
, wParam
, lParam
);
96 return NC_HandleNCActivate( hwnd
, wParam
);
99 if (wndPtr
->hText
) USER_HEAP_FREE(wndPtr
->hText
);
100 if (wndPtr
->hVScroll
) USER_HEAP_FREE(wndPtr
->hVScroll
);
101 if (wndPtr
->hHScroll
) USER_HEAP_FREE(wndPtr
->hHScroll
);
102 wndPtr
->hText
= wndPtr
->hVScroll
= wndPtr
->hHScroll
= 0;
107 PAINTSTRUCT paintstruct
;
108 BeginPaint( hwnd
, &paintstruct
);
109 EndPaint( hwnd
, &paintstruct
);
116 ValidateRect( hwnd
, NULL
);
117 wndPtr
->flags
|= WIN_NO_REDRAW
;
119 else wndPtr
->flags
&= ~WIN_NO_REDRAW
;
123 DestroyWindow( hwnd
);
126 case WM_MOUSEACTIVATE
:
127 if (wndPtr
->dwStyle
& WS_CHILD
)
129 LONG ret
= SendMessage( wndPtr
->parent
->hwndSelf
, WM_MOUSEACTIVATE
,
136 /* LOWORD() needed for WINELIB32 implementation. Should be fine. */
137 if (LOWORD(wParam
)!=WA_INACTIVE
) SetFocus( hwnd
);
140 case WM_WINDOWPOSCHANGING
:
141 return WINPOS_HandleWindowPosChanging( (WINDOWPOS
*)PTR_SEG_TO_LIN(lParam
) );
143 case WM_WINDOWPOSCHANGED
:
145 /* Note: Windoze uses unknown SWP flags 0x1000 and 0x0800 to
146 * decide whether to send WM_MOVE or/and WM_SIZE respectively
149 WINDOWPOS
* winPos
= (WINDOWPOS
*)PTR_SEG_TO_LIN(lParam
);
150 WPARAM wp
= SIZE_RESTORED
;
152 if (!(winPos
->flags
& SWP_NOMOVE
))
153 SendMessage( hwnd
, WM_MOVE
, 0,
154 MAKELONG( wndPtr
->rectClient
.left
,
155 wndPtr
->rectClient
.top
));
156 if (!(winPos
->flags
& SWP_NOSIZE
))
158 if( wndPtr
->dwStyle
& WS_MAXIMIZE
) wp
= SIZE_MAXIMIZED
;
159 else if(wndPtr
->dwStyle
& WS_MINIMIZE
) wp
= SIZE_MINIMIZED
;
161 SendMessage( hwnd
, WM_SIZE
, wp
,
162 MAKELONG(wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
163 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
));
170 case WM_ICONERASEBKGND
:
172 if (!(classPtr
= CLASS_FindClassPtr( wndPtr
->hClass
))) return 0;
173 if (!classPtr
->wc
.hbrBackground
) return 0;
174 if (classPtr
->wc
.hbrBackground
<= (HBRUSH
)(COLOR_MAX
+1))
177 hbrush
= CreateSolidBrush(
178 GetSysColor(((DWORD
)classPtr
->wc
.hbrBackground
)-1));
179 FillWindow( GetParent(hwnd
), hwnd
, (HDC
)wParam
, hbrush
);
180 DeleteObject (hbrush
);
183 FillWindow( GetParent(hwnd
), hwnd
, (HDC
)wParam
,
184 classPtr
->wc
.hbrBackground
);
191 case WM_CTLCOLORMSGBOX
:
192 case WM_CTLCOLOREDIT
:
193 case WM_CTLCOLORLISTBOX
:
196 case WM_CTLCOLORSTATIC
:
197 SetBkColor( (HDC
)wParam
, GetSysColor(COLOR_WINDOW
) );
198 SetTextColor( (HDC
)wParam
, GetSysColor(COLOR_WINDOWTEXT
) );
199 return (LONG
)sysColorObjects
.hbrushWindow
;
201 case WM_CTLCOLORSCROLLBAR
:
202 SetBkColor( (HDC
)wParam
, RGB(255, 255, 255) );
203 SetTextColor( (HDC
)wParam
, RGB(0, 0, 0) );
204 UnrealizeObject( sysColorObjects
.hbrushScrollbar
);
205 return (LONG
)sysColorObjects
.hbrushScrollbar
;
209 if (HIWORD(lParam
) == CTLCOLOR_SCROLLBAR
)
211 SetBkColor( (HDC
)wParam
, RGB(255, 255, 255) );
212 SetTextColor( (HDC
)wParam
, RGB(0, 0, 0) );
213 UnrealizeObject( sysColorObjects
.hbrushScrollbar
);
214 return (LONG
)sysColorObjects
.hbrushScrollbar
;
218 SetBkColor( (HDC
)wParam
, GetSysColor(COLOR_WINDOW
) );
219 SetTextColor( (HDC
)wParam
, GetSysColor(COLOR_WINDOWTEXT
) );
220 return (LONG
)sysColorObjects
.hbrushWindow
;
230 textPtr
= (LPSTR
)USER_HEAP_LIN_ADDR(wndPtr
->hText
);
231 if ((int)wParam
> (len
= strlen(textPtr
)))
233 strcpy((char *)PTR_SEG_TO_LIN(lParam
), textPtr
);
241 case WM_GETTEXTLENGTH
:
245 textPtr
= (LPSTR
)USER_HEAP_LIN_ADDR(wndPtr
->hText
);
246 return (DWORD
)strlen(textPtr
);
252 DEFWND_SetText( hwnd
, (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
253 NC_HandleNCPaint( hwnd
, (HRGN
)1 ); /* Repaint caption */
257 if (wndPtr
->dwStyle
& WS_CHILD
)
258 if (SendMessage(wndPtr
->parent
->hwndSelf
, WM_SETCURSOR
,
261 return NC_HandleSetCursor( hwnd
, wParam
, lParam
);
265 POINT pt
= { LOWORD(lParam
), HIWORD(lParam
) };
266 return NC_HandleSysCommand( hwnd
, wParam
, pt
);
270 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
275 if( HIWORD(lParam
) & KEYDATA_ALT
)
277 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
278 if( wParam
== VK_MENU
&& !iMenuSysKey
)
286 else if( wParam
== VK_F10
)
289 if( wParam
== VK_ESCAPE
&& GetKeyState(VK_SHIFT
) < 0 )
290 SendMessage( hwnd
, WM_SYSCOMMAND
, (WPARAM
)SC_KEYMENU
,
297 /* Press and release F10 or ALT */
299 if( ( wParam
== VK_MENU
&& iMenuSysKey
)
300 || ( wParam
== VK_F10
&& iF10Key
) )
302 SendMessage( WIN_GetTopParent(hwnd
), WM_SYSCOMMAND
,
305 iMenuSysKey
= iF10Key
= 0;
312 if( wParam
== VK_RETURN
&& (wndPtr
->dwStyle
& WS_MINIMIZE
) )
314 PostMessage(hwnd
, WM_SYSCOMMAND
, (WPARAM
)SC_RESTORE
, 0L );
318 if( (HIWORD(lParam
) & KEYDATA_ALT
) && wParam
)
320 if( wParam
== VK_TAB
|| wParam
== VK_ESCAPE
)
323 if( wParam
== VK_SPACE
&& (wndPtr
->dwStyle
& WS_CHILD
) )
324 SendMessage( wndPtr
->parent
->hwndSelf
, msg
, wParam
, lParam
);
326 SendMessage(hwnd
, WM_SYSCOMMAND
, (WPARAM
)SC_KEYMENU
, (LPARAM
)(DWORD
)wParam
);
329 /* check for Ctrl-Esc */
330 if( wParam
!= VK_ESCAPE
)
336 if( !lParam
) return 0; /* sent from ShowWindow */
338 if( !(wndPtr
->dwStyle
& WS_POPUP
) || !wndPtr
->owner
)
341 if( wndPtr
->dwStyle
& WS_VISIBLE
)
342 { if( wParam
) return 0; }
344 if(!wParam
) return 0;
346 ShowWindow(hwnd
,(wParam
)? SW_SHOWNOACTIVATE
: SW_HIDE
);
351 /* EndMenu() should be called if in menu state but currently it's
352 impossible to detect - menu code should be updated*/
354 if( GetCapture() == hwnd
)
366 case WM_QUERYDROPOBJECT
:
367 if(wndPtr
->dwExStyle
& WS_EX_ACCEPTFILES
)
371 case WM_QUERYDRAGICON
:
377 if( (hI
= LoadIcon(wndPtr
->hInstance
,MAKEINTRESOURCE(len
))) )
383 case WM_QUERYENDSESSION
: