2 * Default window procedure
4 * Copyright 1993 Alexandre Julliard
12 #include "nonclient.h"
16 /* #define DEBUG_MESSAGE */
21 #define COLOR_MAX COLOR_BTNHIGHLIGHT
23 /* bits in the dwKeyData */
24 #define KEYDATA_ALT 0x2000
25 #define KEYDATA_PREVSTATE 0x4000
27 static short iF10Key
= 0;
28 static short iMenuSysKey
= 0;
30 /***********************************************************************
33 * Set the window text.
35 void DEFWND_SetText( WND
*wndPtr
, LPSTR text
)
40 if (wndPtr
->hText
) USER_HEAP_FREE( wndPtr
->hText
);
41 wndPtr
->hText
= USER_HEAP_ALLOC( strlen(text
) + 1 );
42 textPtr
= (LPSTR
) USER_HEAP_LIN_ADDR( wndPtr
->hText
);
43 strcpy( textPtr
, text
);
45 XStoreName( display
, wndPtr
->window
, text
);
49 /***********************************************************************
50 * DefWindowProc (USER.107)
52 LRESULT
DefWindowProc( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
56 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
58 SPY_EnterMessage( SPY_DEFWNDPROC
, hwnd
, msg
, wParam
, lParam
);
64 CREATESTRUCT
*createStruct
= (CREATESTRUCT
*)PTR_SEG_TO_LIN(lParam
);
65 if (createStruct
->lpszName
)
66 DEFWND_SetText( wndPtr
,
67 (LPSTR
)PTR_SEG_TO_LIN(createStruct
->lpszName
) );
72 return NC_HandleNCCalcSize( hwnd
,
73 (NCCALCSIZE_PARAMS
*)PTR_SEG_TO_LIN(lParam
) );
77 return NC_HandleNCPaint( hwnd
, (HRGN
)wParam
);
81 POINT pt
= { LOWORD(lParam
), HIWORD(lParam
) };
82 return NC_HandleNCHitTest( hwnd
, pt
);
85 case WM_NCLBUTTONDOWN
:
86 return NC_HandleNCLButtonDown( hwnd
, wParam
, lParam
);
88 case WM_LBUTTONDBLCLK
:
89 case WM_NCLBUTTONDBLCLK
:
90 return NC_HandleNCLButtonDblClk( hwnd
, wParam
, lParam
);
93 return NC_HandleNCActivate( hwnd
, wParam
);
96 if (wndPtr
->hText
) USER_HEAP_FREE(wndPtr
->hText
);
97 if (wndPtr
->hVScroll
) USER_HEAP_FREE(wndPtr
->hVScroll
);
98 if (wndPtr
->hHScroll
) USER_HEAP_FREE(wndPtr
->hHScroll
);
99 wndPtr
->hText
= wndPtr
->hVScroll
= wndPtr
->hHScroll
= 0;
104 PAINTSTRUCT paintstruct
;
105 BeginPaint( hwnd
, &paintstruct
);
106 EndPaint( hwnd
, &paintstruct
);
113 ValidateRect( hwnd
, NULL
);
114 wndPtr
->flags
|= WIN_NO_REDRAW
;
116 else wndPtr
->flags
&= ~WIN_NO_REDRAW
;
120 DestroyWindow( hwnd
);
123 case WM_MOUSEACTIVATE
:
124 if (wndPtr
->dwStyle
& WS_CHILD
)
126 LONG ret
= SendMessage( wndPtr
->parent
->hwndSelf
, WM_MOUSEACTIVATE
,
133 /* LOWORD() needed for WINELIB32 implementation. Should be fine. */
134 if (LOWORD(wParam
)!=WA_INACTIVE
) SetFocus( hwnd
);
137 case WM_WINDOWPOSCHANGING
:
138 return WINPOS_HandleWindowPosChanging( (WINDOWPOS
*)PTR_SEG_TO_LIN(lParam
) );
140 case WM_WINDOWPOSCHANGED
:
142 WINDOWPOS
* winPos
= (WINDOWPOS
*)PTR_SEG_TO_LIN(lParam
);
143 WPARAM wp
= SIZE_RESTORED
;
145 if (!(winPos
->flags
& SWP_NOCLIENTMOVE
))
146 SendMessage( hwnd
, WM_MOVE
, 0,
147 MAKELONG( wndPtr
->rectClient
.left
,
148 wndPtr
->rectClient
.top
));
149 if (!(winPos
->flags
& SWP_NOCLIENTSIZE
))
151 if( wndPtr
->dwStyle
& WS_MAXIMIZE
) wp
= SIZE_MAXIMIZED
;
152 else if(wndPtr
->dwStyle
& WS_MINIMIZE
) wp
= SIZE_MINIMIZED
;
154 SendMessage( hwnd
, WM_SIZE
, wp
,
155 MAKELONG(wndPtr
->rectClient
.right
-wndPtr
->rectClient
.left
,
156 wndPtr
->rectClient
.bottom
-wndPtr
->rectClient
.top
));
163 case WM_ICONERASEBKGND
:
165 if (!wndPtr
->class->wc
.hbrBackground
) return 0;
166 if (wndPtr
->class->wc
.hbrBackground
<= (HBRUSH
)(COLOR_MAX
+1))
169 hbrush
= CreateSolidBrush(
170 GetSysColor(((DWORD
)wndPtr
->class->wc
.hbrBackground
)-1));
171 FillWindow( GetParent(hwnd
), hwnd
, (HDC
)wParam
, hbrush
);
172 DeleteObject (hbrush
);
175 FillWindow( GetParent(hwnd
), hwnd
, (HDC
)wParam
,
176 wndPtr
->class->wc
.hbrBackground
);
183 case WM_CTLCOLORMSGBOX
:
184 case WM_CTLCOLOREDIT
:
185 case WM_CTLCOLORLISTBOX
:
188 case WM_CTLCOLORSTATIC
:
189 SetBkColor( (HDC
)wParam
, GetSysColor(COLOR_WINDOW
) );
190 SetTextColor( (HDC
)wParam
, GetSysColor(COLOR_WINDOWTEXT
) );
191 return (LONG
)sysColorObjects
.hbrushWindow
;
193 case WM_CTLCOLORSCROLLBAR
:
194 SetBkColor( (HDC
)wParam
, RGB(255, 255, 255) );
195 SetTextColor( (HDC
)wParam
, RGB(0, 0, 0) );
196 UnrealizeObject( sysColorObjects
.hbrushScrollbar
);
197 return (LONG
)sysColorObjects
.hbrushScrollbar
;
201 if (HIWORD(lParam
) == CTLCOLOR_SCROLLBAR
)
203 SetBkColor( (HDC
)wParam
, RGB(255, 255, 255) );
204 SetTextColor( (HDC
)wParam
, RGB(0, 0, 0) );
205 UnrealizeObject( sysColorObjects
.hbrushScrollbar
);
206 return (LONG
)sysColorObjects
.hbrushScrollbar
;
210 SetBkColor( (HDC
)wParam
, GetSysColor(COLOR_WINDOW
) );
211 SetTextColor( (HDC
)wParam
, GetSysColor(COLOR_WINDOWTEXT
) );
212 return (LONG
)sysColorObjects
.hbrushWindow
;
222 textPtr
= (LPSTR
)USER_HEAP_LIN_ADDR(wndPtr
->hText
);
223 if ((int)wParam
> (len
= strlen(textPtr
)))
225 strcpy((char *)PTR_SEG_TO_LIN(lParam
), textPtr
);
233 case WM_GETTEXTLENGTH
:
237 textPtr
= (LPSTR
)USER_HEAP_LIN_ADDR(wndPtr
->hText
);
238 return (DWORD
)strlen(textPtr
);
244 DEFWND_SetText( wndPtr
, (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
245 NC_HandleNCPaint( hwnd
, (HRGN
)1 ); /* Repaint caption */
249 if (wndPtr
->dwStyle
& WS_CHILD
)
250 if (SendMessage(wndPtr
->parent
->hwndSelf
, WM_SETCURSOR
,
253 return NC_HandleSetCursor( hwnd
, wParam
, lParam
);
257 POINT pt
= { LOWORD(lParam
), HIWORD(lParam
) };
258 return NC_HandleSysCommand( hwnd
, wParam
, pt
);
262 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
267 if( HIWORD(lParam
) & KEYDATA_ALT
)
269 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
270 if( wParam
== VK_MENU
&& !iMenuSysKey
)
278 else if( wParam
== VK_F10
)
281 if( wParam
== VK_ESCAPE
&& GetKeyState(VK_SHIFT
) < 0 )
282 SendMessage( hwnd
, WM_SYSCOMMAND
, (WPARAM
)SC_KEYMENU
,
289 /* Press and release F10 or ALT */
291 if( ( wParam
== VK_MENU
&& iMenuSysKey
)
292 || ( wParam
== VK_F10
&& iF10Key
) )
294 SendMessage( WIN_GetTopParent(hwnd
), WM_SYSCOMMAND
,
297 iMenuSysKey
= iF10Key
= 0;
304 if( wParam
== VK_RETURN
&& (wndPtr
->dwStyle
& WS_MINIMIZE
) )
306 PostMessage(hwnd
, WM_SYSCOMMAND
, (WPARAM
)SC_RESTORE
, 0L );
310 if( (HIWORD(lParam
) & KEYDATA_ALT
) && wParam
)
312 if( wParam
== VK_TAB
|| wParam
== VK_ESCAPE
)
315 if( wParam
== VK_SPACE
&& (wndPtr
->dwStyle
& WS_CHILD
) )
316 SendMessage( wndPtr
->parent
->hwndSelf
, msg
, wParam
, lParam
);
318 SendMessage(hwnd
, WM_SYSCOMMAND
, (WPARAM
)SC_KEYMENU
, (LPARAM
)(DWORD
)wParam
);
321 /* check for Ctrl-Esc */
322 if( wParam
!= VK_ESCAPE
)
328 if( !lParam
) return 0; /* sent from ShowWindow */
330 if( !(wndPtr
->dwStyle
& WS_POPUP
) || !wndPtr
->owner
)
333 if( wndPtr
->dwStyle
& WS_VISIBLE
)
334 { if( wParam
) return 0; }
336 if(!wParam
) return 0;
338 ShowWindow(hwnd
,(wParam
)? SW_SHOWNOACTIVATE
: SW_HIDE
);
343 /* EndMenu() should be called if in menu state but currently it's
344 impossible to detect - menu code should be updated*/
346 if( GetCapture() == hwnd
)
358 case WM_QUERYDROPOBJECT
:
359 if(wndPtr
->dwExStyle
& WS_EX_ACCEPTFILES
)
363 case WM_QUERYDRAGICON
:
369 if( (hI
= LoadIcon(wndPtr
->hInstance
,MAKEINTRESOURCE(len
))) )
375 case WM_QUERYENDSESSION
: