2 * Default window procedure
4 * Copyright 1993, 1996 Alexandre Julliard
14 #include "nonclient.h"
17 #include "debugtools.h"
23 #include "wine/winuser16.h"
25 DEFAULT_DEBUG_CHANNEL(win)
27 /* bits in the dwKeyData */
28 #define KEYDATA_ALT 0x2000
29 #define KEYDATA_PREVSTATE 0x4000
31 static short iF10Key = 0;
32 static short iMenuSysKey = 0;
34 /***********************************************************************
35 * DEFWND_HandleWindowPosChanged
37 * Handle the WM_WINDOWPOSCHANGED message.
39 static void DEFWND_HandleWindowPosChanged( WND *wndPtr, UINT flags )
41 WPARAM16 wp = SIZE_RESTORED;
43 if (!(flags & SWP_NOCLIENTMOVE))
44 SendMessage16( wndPtr->hwndSelf, WM_MOVE, 0,
45 MAKELONG(wndPtr->rectClient.left, wndPtr->rectClient.top));
46 if (!(flags & SWP_NOCLIENTSIZE))
48 if (wndPtr->dwStyle & WS_MAXIMIZE) wp = SIZE_MAXIMIZED;
49 else if (wndPtr->dwStyle & WS_MINIMIZE) wp = SIZE_MINIMIZED;
51 SendMessage16( wndPtr->hwndSelf, WM_SIZE, wp,
52 MAKELONG(wndPtr->rectClient.right-wndPtr->rectClient.left,
53 wndPtr->rectClient.bottom-wndPtr->rectClient.top));
58 /***********************************************************************
61 * Set the window text.
63 void DEFWND_SetText( WND *wndPtr, LPCSTR text )
66 if (wndPtr->text) HeapFree( SystemHeap, 0, wndPtr->text );
67 wndPtr->text = HEAP_strdupA( SystemHeap, 0, text );
68 wndPtr->pDriver->pSetText(wndPtr, wndPtr->text);
71 /***********************************************************************
74 * Default colors for control painting.
76 HBRUSH DEFWND_ControlColor( HDC hDC, UINT16 ctlType )
78 if( ctlType == CTLCOLOR_SCROLLBAR)
80 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
81 if (TWEAK_WineLook == WIN31_LOOK) {
82 SetTextColor( hDC, RGB(0, 0, 0) );
83 SetBkColor( hDC, RGB(255, 255, 255) );
85 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
86 SetTextColor( hDC, GetSysColor(COLOR_3DFACE));
89 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
90 * we better use 0x55aa bitmap brush to make scrollbar's background
91 * look different from the window background.
93 if (bk == GetSysColor(COLOR_WINDOW)) {
94 return CACHE_GetPattern55AABrush();
97 UnrealizeObject( hb );
101 SetTextColor( hDC, GetSysColor(COLOR_WINDOWTEXT));
103 if (TWEAK_WineLook > WIN31_LOOK) {
104 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
105 SetBkColor( hDC, GetSysColor(COLOR_WINDOW) );
107 SetBkColor( hDC, GetSysColor(COLOR_3DFACE) );
108 return GetSysColorBrush(COLOR_3DFACE);
112 SetBkColor( hDC, GetSysColor(COLOR_WINDOW) );
113 return GetSysColorBrush(COLOR_WINDOW);
117 /***********************************************************************
120 static void DEFWND_SetRedraw( WND* wndPtr, WPARAM wParam )
122 BOOL bVisible = wndPtr->dwStyle & WS_VISIBLE;
124 TRACE("%04x %i\n", wndPtr->hwndSelf, (wParam!=0) );
130 wndPtr->dwStyle |= WS_VISIBLE;
131 DCE_InvalidateDCE( wndPtr, &wndPtr->rectWindow );
136 if( wndPtr->dwStyle & WS_MINIMIZE ) wParam = RDW_VALIDATE;
137 else wParam = RDW_ALLCHILDREN | RDW_VALIDATE;
139 PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, 0, wParam, 0 );
140 DCE_InvalidateDCE( wndPtr, &wndPtr->rectWindow );
141 wndPtr->dwStyle &= ~WS_VISIBLE;
145 /***********************************************************************
148 * This method handles the default behavior for the WM_PRINT message.
150 static void DEFWND_Print(
158 if ( (uFlags & PRF_CHECKVISIBLE) &&
159 !IsWindowVisible(wndPtr->hwndSelf) )
163 * Unimplemented flags.
165 if ( (uFlags & PRF_CHILDREN) ||
166 (uFlags & PRF_OWNED) ||
167 (uFlags & PRF_NONCLIENT) )
169 WARN("WM_PRINT message with unsupported flags\n");
175 if ( uFlags & PRF_ERASEBKGND)
176 SendMessageA(wndPtr->hwndSelf, WM_ERASEBKGND, (WPARAM)hdc, 0);
181 if ( uFlags & PRF_CLIENT)
182 SendMessageA(wndPtr->hwndSelf, WM_PRINTCLIENT, (WPARAM)hdc, PRF_CLIENT);
185 /***********************************************************************
188 * Default window procedure for messages that are the same in Win16 and Win32.
190 static LRESULT DEFWND_DefWinProc( WND *wndPtr, UINT msg, WPARAM wParam,
196 return NC_HandleNCPaint( wndPtr->hwndSelf, (HRGN)wParam );
199 return NC_HandleNCHitTest( wndPtr->hwndSelf, MAKEPOINT16(lParam) );
201 case WM_NCLBUTTONDOWN:
202 return NC_HandleNCLButtonDown( wndPtr, wParam, lParam );
204 case WM_LBUTTONDBLCLK:
205 case WM_NCLBUTTONDBLCLK:
206 return NC_HandleNCLButtonDblClk( wndPtr, wParam, lParam );
210 if ((wndPtr->flags & WIN_ISWIN32) || (TWEAK_WineLook > WIN31_LOOK))
212 ClientToScreen16(wndPtr->hwndSelf, (LPPOINT16)&lParam);
213 SendMessageA( wndPtr->hwndSelf, WM_CONTEXTMENU,
214 wndPtr->hwndSelf, lParam);
219 if( wndPtr->dwStyle & WS_CHILD )
220 SendMessageA( wndPtr->parent->hwndSelf, msg, wParam, lParam );
221 else if (wndPtr->hSysMenu)
224 POINT16 pt = MAKEPOINT16(lParam);
226 ScreenToClient16(wndPtr->hwndSelf, &pt);
227 hitcode = NC_HandleNCHitTest(wndPtr->hwndSelf, pt);
229 /* Track system popup if click was in the caption area. */
230 if (hitcode==HTCAPTION || hitcode==HTSYSMENU)
231 TrackPopupMenu(GetSystemMenu(wndPtr->hwndSelf, FALSE),
232 TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
233 pt.x, pt.y, 0, wndPtr->hwndSelf, NULL);
238 return NC_HandleNCActivate( wndPtr, wParam );
241 if (wndPtr->text) HeapFree( SystemHeap, 0, wndPtr->text );
243 if (wndPtr->pVScroll) HeapFree( SystemHeap, 0, wndPtr->pVScroll );
244 if (wndPtr->pHScroll) HeapFree( SystemHeap, 0, wndPtr->pHScroll );
245 wndPtr->pVScroll = wndPtr->pHScroll = NULL;
249 DEFWND_Print(wndPtr, (HDC)wParam, lParam);
256 HDC16 hdc = BeginPaint16( wndPtr->hwndSelf, &ps );
259 if( (wndPtr->dwStyle & WS_MINIMIZE) && wndPtr->class->hIcon )
261 int x = (wndPtr->rectWindow.right - wndPtr->rectWindow.left -
262 GetSystemMetrics(SM_CXICON))/2;
263 int y = (wndPtr->rectWindow.bottom - wndPtr->rectWindow.top -
264 GetSystemMetrics(SM_CYICON))/2;
265 TRACE("Painting class icon: vis rect=(%i,%i - %i,%i)\n",
266 ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom );
267 DrawIcon( hdc, x, y, wndPtr->class->hIcon );
269 EndPaint16( wndPtr->hwndSelf, &ps );
275 DEFWND_SetRedraw( wndPtr, wParam );
279 DestroyWindow( wndPtr->hwndSelf );
282 case WM_MOUSEACTIVATE:
283 if (wndPtr->dwStyle & WS_CHILD)
285 LONG ret = SendMessage16( wndPtr->parent->hwndSelf,
286 WM_MOUSEACTIVATE, wParam, lParam );
290 /* Caption clicks are handled by the NC_HandleNCLButtonDown() */
291 return (LOWORD(lParam) >= HTCLIENT) ? MA_ACTIVATE : MA_NOACTIVATE;
294 /* The default action in Windows is to set the keyboard focus to
295 * the window, if it's being activated and not minimized */
296 if (LOWORD(wParam) != WA_INACTIVE) {
297 if (!(wndPtr->dwStyle & WS_MINIMIZE))
298 SetFocus(wndPtr->hwndSelf);
303 case WM_ICONERASEBKGND:
307 if (!wndPtr->class->hbrBackground) return 0;
309 /* Since WM_ERASEBKGND may receive either a window dc or a */
310 /* client dc, the area to be erased has to be retrieved from */
311 /* the device context. */
312 GetClipBox( (HDC)wParam, &rect );
314 /* Always call the Win32 variant of FillRect even on Win16,
315 * since despite the fact that Win16, as well as Win32,
316 * supports special background brushes for a window class,
317 * the Win16 variant of FillRect does not.
319 FillRect( (HDC) wParam, &rect, wndPtr->class->hbrBackground);
326 case WM_CTLCOLORMSGBOX:
327 case WM_CTLCOLOREDIT:
328 case WM_CTLCOLORLISTBOX:
331 case WM_CTLCOLORSTATIC:
332 case WM_CTLCOLORSCROLLBAR:
333 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, msg - WM_CTLCOLORMSGBOX );
336 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, HIWORD(lParam) );
338 case WM_GETTEXTLENGTH:
339 if (wndPtr->text) return (LRESULT)strlen(wndPtr->text);
343 if (wndPtr->dwStyle & WS_CHILD)
344 if (SendMessage16(wndPtr->parent->hwndSelf, WM_SETCURSOR,
347 return NC_HandleSetCursor( wndPtr->hwndSelf, wParam, lParam );
350 return NC_HandleSysCommand( wndPtr->hwndSelf, wParam,
351 MAKEPOINT16(lParam) );
354 if(wParam == VK_F10) iF10Key = VK_F10;
358 if( HIWORD(lParam) & KEYDATA_ALT )
360 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
361 if( wParam == VK_MENU && !iMenuSysKey )
368 if( wParam == VK_F4 ) /* try to close the window */
370 HWND hWnd = WIN_GetTopParent( wndPtr->hwndSelf );
371 wndPtr = WIN_FindWndPtr( hWnd );
372 if( wndPtr && !(wndPtr->class->style & CS_NOCLOSE) )
373 PostMessage16( hWnd, WM_SYSCOMMAND, SC_CLOSE, 0 );
374 WIN_ReleaseWndPtr(wndPtr);
377 else if( wParam == VK_F10 )
380 if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
381 SendMessage16( wndPtr->hwndSelf, WM_SYSCOMMAND,
382 (WPARAM16)SC_KEYMENU, (LPARAM)VK_SPACE);
387 /* Press and release F10 or ALT */
388 if (((wParam == VK_MENU) && iMenuSysKey) ||
389 ((wParam == VK_F10) && iF10Key))
390 SendMessage16( WIN_GetTopParent(wndPtr->hwndSelf),
391 WM_SYSCOMMAND, SC_KEYMENU, 0L );
392 iMenuSysKey = iF10Key = 0;
397 if (wParam == VK_RETURN && (wndPtr->dwStyle & WS_MINIMIZE))
399 PostMessage16( wndPtr->hwndSelf, WM_SYSCOMMAND,
400 (WPARAM16)SC_RESTORE, 0L );
403 if ((HIWORD(lParam) & KEYDATA_ALT) && wParam)
405 if (wParam == VK_TAB || wParam == VK_ESCAPE) break;
406 if (wParam == VK_SPACE && (wndPtr->dwStyle & WS_CHILD))
407 SendMessage16( wndPtr->parent->hwndSelf, msg, wParam, lParam );
409 SendMessage16( wndPtr->hwndSelf, WM_SYSCOMMAND,
410 (WPARAM16)SC_KEYMENU, (LPARAM)(DWORD)wParam );
412 else /* check for Ctrl-Esc */
413 if (wParam != VK_ESCAPE) MessageBeep(0);
417 if (!lParam) return 0; /* sent from ShowWindow */
418 if (!(wndPtr->dwStyle & WS_POPUP) || !wndPtr->owner) return 0;
419 if ((wndPtr->dwStyle & WS_VISIBLE) && wParam) return 0;
420 else if (!(wndPtr->dwStyle & WS_VISIBLE) && !wParam) return 0;
421 ShowWindow( wndPtr->hwndSelf, wParam ? SW_SHOWNOACTIVATE : SW_HIDE );
425 if (wndPtr->parent == WIN_GetDesktop()) EndMenu();
426 if (GetCapture() == wndPtr->hwndSelf) ReleaseCapture();
427 WIN_ReleaseDesktop();
437 case WM_QUERYDROPOBJECT:
438 if (wndPtr->dwExStyle & WS_EX_ACCEPTFILES) return 1;
441 case WM_QUERYDRAGICON:
446 if( (hIcon=wndPtr->class->hCursor) ) return (LRESULT)hIcon;
447 for(len=1; len<64; len++)
448 if((hIcon=LoadIcon16(wndPtr->hInstance,MAKEINTRESOURCE16(len))))
449 return (LRESULT)hIcon;
450 return (LRESULT)LoadIcon16(0,IDI_APPLICATION16);
454 case WM_ISACTIVEICON:
455 return ((wndPtr->flags & WIN_NCACTIVATED) != 0);
457 case WM_NOTIFYFORMAT:
458 if (IsWindowUnicode(wndPtr->hwndSelf)) return NFR_UNICODE;
459 else return NFR_ANSI;
462 case WM_QUERYENDSESSION:
469 int index = GCL_HICON;
471 if (wParam == ICON_SMALL)
474 result = GetClassLongA(wndPtr->hwndSelf, index);
476 if (msg == WM_SETICON)
477 SetClassLongA(wndPtr->hwndSelf, index, lParam);
482 SendMessageA( wndPtr->parent->hwndSelf, msg, wParam, lParam );
491 /***********************************************************************
492 * DefWindowProc16 (USER.107)
494 LRESULT WINAPI DefWindowProc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
497 WND * wndPtr = WIN_FindWndPtr( hwnd );
500 if (!wndPtr) return 0;
501 SPY_EnterMessage( SPY_DEFWNDPROC16, hwnd, msg, wParam, lParam );
507 CREATESTRUCT16 *cs = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam);
509 DEFWND_SetText( wndPtr, (LPSTR)PTR_SEG_TO_LIN(cs->lpszName) );
517 CONV_RECT16TO32( (RECT16 *)PTR_SEG_TO_LIN(lParam), &rect32 );
518 result = NC_HandleNCCalcSize( wndPtr, &rect32 );
519 CONV_RECT32TO16( &rect32, (RECT16 *)PTR_SEG_TO_LIN(lParam) );
523 case WM_WINDOWPOSCHANGING:
524 result = WINPOS_HandleWindowPosChanging16( wndPtr,
525 (WINDOWPOS16 *)PTR_SEG_TO_LIN(lParam) );
528 case WM_WINDOWPOSCHANGED:
530 WINDOWPOS16 * winPos = (WINDOWPOS16 *)PTR_SEG_TO_LIN(lParam);
531 DEFWND_HandleWindowPosChanged( wndPtr, winPos->flags );
536 if (wParam && wndPtr->text)
538 lstrcpynA( (LPSTR)PTR_SEG_TO_LIN(lParam), wndPtr->text, wParam );
539 result = (LRESULT)strlen( (LPSTR)PTR_SEG_TO_LIN(lParam) );
544 DEFWND_SetText( wndPtr, (LPSTR)PTR_SEG_TO_LIN(lParam) );
545 if( wndPtr->dwStyle & WS_CAPTION ) NC_HandleNCPaint( hwnd , (HRGN)1 );
549 result = DEFWND_DefWinProc( wndPtr, msg, wParam, lParam );
553 WIN_ReleaseWndPtr(wndPtr);
554 SPY_ExitMessage( SPY_RESULT_DEFWND16, hwnd, msg, result );
559 /***********************************************************************
560 * DefWindowProcA [USER32.126]
563 LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam,
566 WND * wndPtr = WIN_FindWndPtr( hwnd );
569 if (!wndPtr) return 0;
570 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
576 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
577 if (cs->lpszName) DEFWND_SetText( wndPtr, cs->lpszName );
583 result = NC_HandleNCCalcSize( wndPtr, (RECT *)lParam );
586 case WM_WINDOWPOSCHANGING:
587 result = WINPOS_HandleWindowPosChanging( wndPtr,
588 (WINDOWPOS *)lParam );
591 case WM_WINDOWPOSCHANGED:
593 WINDOWPOS * winPos = (WINDOWPOS *)lParam;
594 DEFWND_HandleWindowPosChanged( wndPtr, winPos->flags );
599 if (wParam && wndPtr->text)
601 lstrcpynA( (LPSTR)lParam, wndPtr->text, wParam );
602 result = (LRESULT)strlen( (LPSTR)lParam );
607 DEFWND_SetText( wndPtr, (LPSTR)lParam );
608 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
612 result = DEFWND_DefWinProc( wndPtr, msg, wParam, lParam );
616 WIN_ReleaseWndPtr(wndPtr);
617 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result );
622 /***********************************************************************
623 * DefWindowProcW [USER32.127] Calls default window message handler
625 * Calls default window procedure for messages not processed
629 * Return value is dependent upon the message.
631 LRESULT WINAPI DefWindowProcW(
632 HWND hwnd, /* [in] window procedure recieving message */
633 UINT msg, /* [in] message identifier */
634 WPARAM wParam, /* [in] first message parameter */
635 LPARAM lParam ) /* [in] second message parameter */
643 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
646 WND *wndPtr = WIN_FindWndPtr( hwnd );
647 LPSTR str = HEAP_strdupWtoA(GetProcessHeap(), 0, cs->lpszName);
648 DEFWND_SetText( wndPtr, str );
649 HeapFree( GetProcessHeap(), 0, str );
650 WIN_ReleaseWndPtr(wndPtr);
658 LPSTR str = HeapAlloc( GetProcessHeap(), 0, wParam );
659 result = DefWindowProcA( hwnd, msg, wParam, (LPARAM)str );
660 lstrcpynAtoW( (LPWSTR)lParam, str, wParam );
661 HeapFree( GetProcessHeap(), 0, str );
667 LPSTR str = HEAP_strdupWtoA( GetProcessHeap(), 0, (LPWSTR)lParam );
668 result = DefWindowProcA( hwnd, msg, wParam, (LPARAM)str );
669 HeapFree( GetProcessHeap(), 0, str );
674 result = DefWindowProcA( hwnd, msg, wParam, lParam );