2 * Default window procedure
4 * Copyright 1993, 1996 Alexandre Julliard
13 #include "nonclient.h"
16 #include "debugtools.h"
20 #include "wine/winuser16.h"
22 DEFAULT_DEBUG_CHANNEL(win
)
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
, UINT 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
);
65 wndPtr
->pDriver
->pSetText(wndPtr
, wndPtr
->text
);
68 /***********************************************************************
71 * Default colors for control painting.
73 HBRUSH
DEFWND_ControlColor( HDC hDC
, UINT16 ctlType
)
75 if( ctlType
== CTLCOLOR_SCROLLBAR
)
77 HBRUSH hb
= GetSysColorBrush(COLOR_SCROLLBAR
);
78 if (TWEAK_WineLook
== WIN31_LOOK
) {
79 SetTextColor( hDC
, RGB(0, 0, 0) );
80 SetBkColor( hDC
, RGB(255, 255, 255) );
82 COLORREF bk
= GetSysColor(COLOR_3DHILIGHT
);
83 SetTextColor( hDC
, GetSysColor(COLOR_3DFACE
));
86 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
87 * we better use 0x55aa bitmap brush to make scrollbar's background
88 * look different from the window background.
90 if (bk
== GetSysColor(COLOR_WINDOW
)) {
91 return CACHE_GetPattern55AABrush();
94 UnrealizeObject( hb
);
98 SetTextColor( hDC
, GetSysColor(COLOR_WINDOWTEXT
));
100 if (TWEAK_WineLook
> WIN31_LOOK
) {
101 if ((ctlType
== CTLCOLOR_EDIT
) || (ctlType
== CTLCOLOR_LISTBOX
))
102 SetBkColor( hDC
, GetSysColor(COLOR_WINDOW
) );
104 SetBkColor( hDC
, GetSysColor(COLOR_3DFACE
) );
105 return GetSysColorBrush(COLOR_3DFACE
);
109 SetBkColor( hDC
, GetSysColor(COLOR_WINDOW
) );
110 return GetSysColorBrush(COLOR_WINDOW
);
114 /***********************************************************************
117 static void DEFWND_SetRedraw( WND
* wndPtr
, WPARAM wParam
)
119 BOOL bVisible
= wndPtr
->dwStyle
& WS_VISIBLE
;
121 TRACE("%04x %i\n", wndPtr
->hwndSelf
, (wParam
!=0) );
127 wndPtr
->dwStyle
|= WS_VISIBLE
;
128 DCE_InvalidateDCE( wndPtr
, &wndPtr
->rectWindow
);
133 if( wndPtr
->dwStyle
& WS_MINIMIZE
) wParam
= RDW_VALIDATE
;
134 else wParam
= RDW_ALLCHILDREN
| RDW_VALIDATE
;
136 PAINT_RedrawWindow( wndPtr
->hwndSelf
, NULL
, 0, wParam
, 0 );
137 DCE_InvalidateDCE( wndPtr
, &wndPtr
->rectWindow
);
138 wndPtr
->dwStyle
&= ~WS_VISIBLE
;
142 /***********************************************************************
145 * This method handles the default behavior for the WM_PRINT message.
147 static void DEFWND_Print(
155 if ( (uFlags
& PRF_CHECKVISIBLE
) &&
156 !IsWindowVisible(wndPtr
->hwndSelf
) )
160 * Unimplemented flags.
162 if ( (uFlags
& PRF_CHILDREN
) ||
163 (uFlags
& PRF_OWNED
) ||
164 (uFlags
& PRF_NONCLIENT
) )
166 WARN("WM_PRINT message with unsupported flags\n");
172 if ( uFlags
& PRF_ERASEBKGND
)
173 SendMessageA(wndPtr
->hwndSelf
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
178 if ( uFlags
& PRF_CLIENT
)
179 SendMessageA(wndPtr
->hwndSelf
, WM_PRINTCLIENT
, (WPARAM
)hdc
, PRF_CLIENT
);
182 /***********************************************************************
185 * Default window procedure for messages that are the same in Win16 and Win32.
187 static LRESULT
DEFWND_DefWinProc( WND
*wndPtr
, UINT msg
, WPARAM wParam
,
193 return NC_HandleNCPaint( wndPtr
->hwndSelf
, (HRGN
)wParam
);
196 return NC_HandleNCHitTest( wndPtr
->hwndSelf
, MAKEPOINT16(lParam
) );
198 case WM_NCLBUTTONDOWN
:
199 return NC_HandleNCLButtonDown( wndPtr
, wParam
, lParam
);
201 case WM_LBUTTONDBLCLK
:
202 case WM_NCLBUTTONDBLCLK
:
203 return NC_HandleNCLButtonDblClk( wndPtr
, wParam
, lParam
);
207 if ((wndPtr
->flags
& WIN_ISWIN32
) || (TWEAK_WineLook
> WIN31_LOOK
))
209 ClientToScreen16(wndPtr
->hwndSelf
, (LPPOINT16
)&lParam
);
210 SendMessageA( wndPtr
->hwndSelf
, WM_CONTEXTMENU
,
211 wndPtr
->hwndSelf
, lParam
);
216 if( wndPtr
->dwStyle
& WS_CHILD
)
217 SendMessageA( wndPtr
->parent
->hwndSelf
, msg
, wParam
, lParam
);
219 if (wndPtr
->hSysMenu
)
221 TrackPopupMenu32(wndPtr->hSysMenu,TPM_LEFTALIGN | TPM_RETURNCMD,LOWORD(lParam),HIWORD(lParam),0,wndPtr->hwndSelf,NULL);
222 DestroyMenu32(wndPtr->hSysMenu);
224 FIXME("Display default popup menu\n");
225 /* Track system popup if click was in the caption area. */
230 return NC_HandleNCActivate( wndPtr
, wParam
);
233 if (wndPtr
->text
) HeapFree( SystemHeap
, 0, wndPtr
->text
);
235 if (wndPtr
->pVScroll
) HeapFree( SystemHeap
, 0, wndPtr
->pVScroll
);
236 if (wndPtr
->pHScroll
) HeapFree( SystemHeap
, 0, wndPtr
->pHScroll
);
237 wndPtr
->pVScroll
= wndPtr
->pHScroll
= NULL
;
241 DEFWND_Print(wndPtr
, (HDC
)wParam
, lParam
);
248 HDC16 hdc
= BeginPaint16( wndPtr
->hwndSelf
, &ps
);
251 if( (wndPtr
->dwStyle
& WS_MINIMIZE
) && wndPtr
->class->hIcon
)
253 int x
= (wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
-
254 GetSystemMetrics(SM_CXICON
))/2;
255 int y
= (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
-
256 GetSystemMetrics(SM_CYICON
))/2;
257 TRACE("Painting class icon: vis rect=(%i,%i - %i,%i)\n",
258 ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
259 DrawIcon( hdc
, x
, y
, wndPtr
->class->hIcon
);
261 EndPaint16( wndPtr
->hwndSelf
, &ps
);
267 DEFWND_SetRedraw( wndPtr
, wParam
);
271 DestroyWindow( wndPtr
->hwndSelf
);
274 case WM_MOUSEACTIVATE
:
275 if (wndPtr
->dwStyle
& WS_CHILD
)
277 LONG ret
= SendMessage16( wndPtr
->parent
->hwndSelf
,
278 WM_MOUSEACTIVATE
, wParam
, lParam
);
282 /* Caption clicks are handled by the NC_HandleNCLButtonDown() */
283 return (LOWORD(lParam
) >= HTCLIENT
) ? MA_ACTIVATE
: MA_NOACTIVATE
;
286 /* The default action in Windows is to set the keyboard focus to
287 * the window, if it's being activated and not minimized */
288 if (LOWORD(wParam
) != WA_INACTIVE
) {
289 /* I don't know who put this SetWindowPos here, it does not
290 * seem very logical to have it here... (FIXME?) */
291 SetWindowPos(wndPtr
->hwndSelf
, HWND_TOP
, 0, 0, 0, 0,
292 SWP_NOMOVE
| SWP_NOSIZE
);
293 if (!(wndPtr
->dwStyle
& WS_MINIMIZE
))
294 SetFocus(wndPtr
->hwndSelf
);
299 case WM_ICONERASEBKGND
:
303 if (!wndPtr
->class->hbrBackground
) return 0;
305 /* Since WM_ERASEBKGND may receive either a window dc or a */
306 /* client dc, the area to be erased has to be retrieved from */
307 /* the device context. */
308 GetClipBox( (HDC
)wParam
, &rect
);
310 /* Always call the Win32 variant of FillRect even on Win16,
311 * since despite the fact that Win16, as well as Win32,
312 * supports special background brushes for a window class,
313 * the Win16 variant of FillRect does not.
315 FillRect( (HDC
) wParam
, &rect
, wndPtr
->class->hbrBackground
);
322 case WM_CTLCOLORMSGBOX
:
323 case WM_CTLCOLOREDIT
:
324 case WM_CTLCOLORLISTBOX
:
327 case WM_CTLCOLORSTATIC
:
328 case WM_CTLCOLORSCROLLBAR
:
329 return (LRESULT
)DEFWND_ControlColor( (HDC
)wParam
, msg
- WM_CTLCOLORMSGBOX
);
332 return (LRESULT
)DEFWND_ControlColor( (HDC
)wParam
, HIWORD(lParam
) );
334 case WM_GETTEXTLENGTH
:
335 if (wndPtr
->text
) return (LRESULT
)strlen(wndPtr
->text
);
339 if (wndPtr
->dwStyle
& WS_CHILD
)
340 if (SendMessage16(wndPtr
->parent
->hwndSelf
, WM_SETCURSOR
,
343 return NC_HandleSetCursor( wndPtr
->hwndSelf
, wParam
, lParam
);
346 return NC_HandleSysCommand( wndPtr
->hwndSelf
, wParam
,
347 MAKEPOINT16(lParam
) );
350 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
354 if( HIWORD(lParam
) & KEYDATA_ALT
)
356 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
357 if( wParam
== VK_MENU
&& !iMenuSysKey
)
364 if( wParam
== VK_F4
) /* try to close the window */
366 HWND hWnd
= WIN_GetTopParent( wndPtr
->hwndSelf
);
367 wndPtr
= WIN_FindWndPtr( hWnd
);
368 if( wndPtr
&& !(wndPtr
->class->style
& CS_NOCLOSE
) )
369 PostMessage16( hWnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0 );
370 WIN_ReleaseWndPtr(wndPtr
);
373 else if( wParam
== VK_F10
)
376 if( wParam
== VK_ESCAPE
&& (GetKeyState(VK_SHIFT
) & 0x8000))
377 SendMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
378 (WPARAM16
)SC_KEYMENU
, (LPARAM
)VK_SPACE
);
383 /* Press and release F10 or ALT */
384 if (((wParam
== VK_MENU
) && iMenuSysKey
) ||
385 ((wParam
== VK_F10
) && iF10Key
))
386 SendMessage16( WIN_GetTopParent(wndPtr
->hwndSelf
),
387 WM_SYSCOMMAND
, SC_KEYMENU
, 0L );
388 iMenuSysKey
= iF10Key
= 0;
393 if (wParam
== VK_RETURN
&& (wndPtr
->dwStyle
& WS_MINIMIZE
))
395 PostMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
396 (WPARAM16
)SC_RESTORE
, 0L );
399 if ((HIWORD(lParam
) & KEYDATA_ALT
) && wParam
)
401 if (wParam
== VK_TAB
|| wParam
== VK_ESCAPE
) break;
402 if (wParam
== VK_SPACE
&& (wndPtr
->dwStyle
& WS_CHILD
))
403 SendMessage16( wndPtr
->parent
->hwndSelf
, msg
, wParam
, lParam
);
405 SendMessage16( wndPtr
->hwndSelf
, WM_SYSCOMMAND
,
406 (WPARAM16
)SC_KEYMENU
, (LPARAM
)(DWORD
)wParam
);
408 else /* check for Ctrl-Esc */
409 if (wParam
!= VK_ESCAPE
) MessageBeep(0);
413 if (!lParam
) return 0; /* sent from ShowWindow */
414 if (!(wndPtr
->dwStyle
& WS_POPUP
) || !wndPtr
->owner
) return 0;
415 if ((wndPtr
->dwStyle
& WS_VISIBLE
) && wParam
) return 0;
416 else if (!(wndPtr
->dwStyle
& WS_VISIBLE
) && !wParam
) return 0;
417 ShowWindow( wndPtr
->hwndSelf
, wParam
? SW_SHOWNOACTIVATE
: SW_HIDE
);
421 if (wndPtr
->parent
== WIN_GetDesktop()) EndMenu();
422 if (GetCapture() == wndPtr
->hwndSelf
) ReleaseCapture();
423 WIN_ReleaseDesktop();
433 case WM_QUERYDROPOBJECT
:
434 if (wndPtr
->dwExStyle
& WS_EX_ACCEPTFILES
) return 1;
437 case WM_QUERYDRAGICON
:
442 if( (hIcon
=wndPtr
->class->hCursor
) ) return (LRESULT
)hIcon
;
443 for(len
=1; len
<64; len
++)
444 if((hIcon
=LoadIcon16(wndPtr
->hInstance
,MAKEINTRESOURCE16(len
))))
445 return (LRESULT
)hIcon
;
446 return (LRESULT
)LoadIcon16(0,IDI_APPLICATION16
);
450 case WM_ISACTIVEICON
:
451 return ((wndPtr
->flags
& WIN_NCACTIVATED
) != 0);
453 case WM_NOTIFYFORMAT
:
454 if (IsWindowUnicode(wndPtr
->hwndSelf
)) return NFR_UNICODE
;
455 else return NFR_ANSI
;
458 case WM_QUERYENDSESSION
:
465 int index
= GCL_HICON
;
467 if (wParam
== ICON_SMALL
)
470 result
= GetClassLongA(wndPtr
->hwndSelf
, index
);
472 if (msg
== WM_SETICON
)
473 SetClassLongA(wndPtr
->hwndSelf
, index
, lParam
);
484 /***********************************************************************
485 * DefWindowProc16 (USER.107)
487 LRESULT WINAPI
DefWindowProc16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
490 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
493 if (!wndPtr
) return 0;
494 SPY_EnterMessage( SPY_DEFWNDPROC16
, hwnd
, msg
, wParam
, lParam
);
500 CREATESTRUCT16
*cs
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
);
502 DEFWND_SetText( wndPtr
, (LPSTR
)PTR_SEG_TO_LIN(cs
->lpszName
) );
510 CONV_RECT16TO32( (RECT16
*)PTR_SEG_TO_LIN(lParam
), &rect32
);
511 result
= NC_HandleNCCalcSize( wndPtr
, &rect32
);
512 CONV_RECT32TO16( &rect32
, (RECT16
*)PTR_SEG_TO_LIN(lParam
) );
516 case WM_WINDOWPOSCHANGING
:
517 result
= WINPOS_HandleWindowPosChanging16( wndPtr
,
518 (WINDOWPOS16
*)PTR_SEG_TO_LIN(lParam
) );
521 case WM_WINDOWPOSCHANGED
:
523 WINDOWPOS16
* winPos
= (WINDOWPOS16
*)PTR_SEG_TO_LIN(lParam
);
524 DEFWND_HandleWindowPosChanged( wndPtr
, winPos
->flags
);
529 if (wParam
&& wndPtr
->text
)
531 lstrcpynA( (LPSTR
)PTR_SEG_TO_LIN(lParam
), wndPtr
->text
, wParam
);
532 result
= (LRESULT
)strlen( (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
537 DEFWND_SetText( wndPtr
, (LPSTR
)PTR_SEG_TO_LIN(lParam
) );
538 if( wndPtr
->dwStyle
& WS_CAPTION
) NC_HandleNCPaint( hwnd
, (HRGN
)1 );
542 result
= DEFWND_DefWinProc( wndPtr
, msg
, wParam
, lParam
);
546 WIN_ReleaseWndPtr(wndPtr
);
547 SPY_ExitMessage( SPY_RESULT_DEFWND16
, hwnd
, msg
, result
);
552 /***********************************************************************
553 * DefWindowProc32A [USER32.126]
556 LRESULT WINAPI
DefWindowProcA( HWND hwnd
, UINT msg
, WPARAM wParam
,
559 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
562 if (!wndPtr
) return 0;
563 SPY_EnterMessage( SPY_DEFWNDPROC
, hwnd
, msg
, wParam
, lParam
);
569 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
570 if (cs
->lpszName
) DEFWND_SetText( wndPtr
, cs
->lpszName
);
576 result
= NC_HandleNCCalcSize( wndPtr
, (RECT
*)lParam
);
579 case WM_WINDOWPOSCHANGING
:
580 result
= WINPOS_HandleWindowPosChanging( wndPtr
,
581 (WINDOWPOS
*)lParam
);
584 case WM_WINDOWPOSCHANGED
:
586 WINDOWPOS
* winPos
= (WINDOWPOS
*)lParam
;
587 DEFWND_HandleWindowPosChanged( wndPtr
, winPos
->flags
);
592 if (wParam
&& wndPtr
->text
)
594 lstrcpynA( (LPSTR
)lParam
, wndPtr
->text
, wParam
);
595 result
= (LRESULT
)strlen( (LPSTR
)lParam
);
600 DEFWND_SetText( wndPtr
, (LPSTR
)lParam
);
601 NC_HandleNCPaint( hwnd
, (HRGN
)1 ); /* Repaint caption */
605 result
= DEFWND_DefWinProc( wndPtr
, msg
, wParam
, lParam
);
609 WIN_ReleaseWndPtr(wndPtr
);
610 SPY_ExitMessage( SPY_RESULT_DEFWND
, hwnd
, msg
, result
);
615 /***********************************************************************
616 * DefWindowProc32W [USER32.127] Calls default window message handler
618 * Calls default window procedure for messages not processed
622 * Return value is dependent upon the message.
624 LRESULT WINAPI
DefWindowProcW(
625 HWND hwnd
, /* [in] window procedure recieving message */
626 UINT msg
, /* [in] message identifier */
627 WPARAM wParam
, /* [in] first message parameter */
628 LPARAM lParam
) /* [in] second message parameter */
636 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lParam
;
639 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
640 LPSTR str
= HEAP_strdupWtoA(GetProcessHeap(), 0, cs
->lpszName
);
641 DEFWND_SetText( wndPtr
, str
);
642 HeapFree( GetProcessHeap(), 0, str
);
643 WIN_ReleaseWndPtr(wndPtr
);
651 LPSTR str
= HeapAlloc( GetProcessHeap(), 0, wParam
);
652 result
= DefWindowProcA( hwnd
, msg
, wParam
, (LPARAM
)str
);
653 lstrcpynAtoW( (LPWSTR
)lParam
, str
, wParam
);
654 HeapFree( GetProcessHeap(), 0, str
);
660 LPSTR str
= HEAP_strdupWtoA( GetProcessHeap(), 0, (LPWSTR
)lParam
);
661 result
= DefWindowProcA( hwnd
, msg
, wParam
, (LPARAM
)str
);
662 HeapFree( GetProcessHeap(), 0, str
);
667 result
= DefWindowProcA( hwnd
, msg
, wParam
, lParam
);