1 /* $Id: defwnd.c,v 1.136 2004/05/12 20:34:38 navaraf Exp $
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS user32.dll
5 * FILE: lib/user32/windows/window.c
6 * PURPOSE: Window management
7 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
9 * 06-06-2001 CSH Created
12 /* INCLUDES ******************************************************************/
18 #include <user32/wininternal.h>
29 #define WM_SETVISIBLE 9
31 #ifndef WM_QUERYDROPOBJECT
32 #define WM_QUERYDROPOBJECT 0x022B
35 LRESULT
DefWndNCPaint(HWND hWnd
, HRGN hRgn
);
36 LRESULT
DefWndNCCalcSize(HWND hWnd
, BOOL CalcSizeStruct
, RECT
*Rect
);
37 LRESULT
DefWndNCActivate(HWND hWnd
, WPARAM wParam
);
38 LRESULT
DefWndNCHitTest(HWND hWnd
, POINT Point
);
39 LRESULT
DefWndNCLButtonDown(HWND hWnd
, WPARAM wParam
, LPARAM lParam
);
40 LRESULT
DefWndNCLButtonDblClk(HWND hWnd
, WPARAM wParam
, LPARAM lParam
);
41 void FASTCALL
MenuInitSysMenuPopup(HMENU Menu
, DWORD Style
, DWORD ClsStyle
, LONG HitTest
);
43 /* GLOBALS *******************************************************************/
45 /* TODO: widgets will be cached here.
46 static HBITMAP hbClose;
47 static HBITMAP hbCloseD;
48 static HBITMAP hbMinimize;
49 static HBITMAP hbMinimizeD;
50 static HBITMAP hbRestore;
51 static HBITMAP hbRestoreD;
52 static HBITMAP hbMaximize;
53 static HBITMAP hbScrUp;
54 static HBITMAP hbScrDwn;
55 static HBITMAP hbScrLeft;
56 static HBITMAP hbScrRight;
60 static COLORREF SysColors
[] =
62 RGB(192, 192, 192) /* COLOR_SCROLLBAR */,
63 RGB(58, 110, 165) /* COLOR_BACKGROUND */,
64 RGB(10, 36, 106) /* COLOR_ACTIVECAPTION */,
65 RGB(128, 128, 128) /* COLOR_INACTIVECAPTION */,
66 RGB(192, 192, 192) /* COLOR_MENU */,
67 RGB(255, 255, 255) /* COLOR_WINDOW */,
68 RGB(0, 0, 0) /* COLOR_WINDOWFRAME */,
69 RGB(0, 0, 0) /* COLOR_MENUTEXT */,
70 RGB(0, 0, 0) /* COLOR_WINDOWTEXT */,
71 RGB(255, 255, 255) /* COLOR_CAPTIONTEXT */,
72 RGB(192, 192, 192) /* COLOR_ACTIVEBORDER */,
73 RGB(192, 192, 192) /* COLOR_INACTIVEBORDER */,
74 RGB(128, 128, 128) /* COLOR_APPWORKSPACE */,
75 RGB(0, 0, 128) /* COLOR_HILIGHT */,
76 RGB(255, 255, 255) /* COLOR_HILIGHTTEXT */,
77 RGB(192, 192, 192) /* COLOR_BTNFACE */,
78 RGB(128, 128, 128) /* COLOR_BTNSHADOW */,
79 RGB(128, 128, 128) /* COLOR_GRAYTEXT */,
80 RGB(0, 0, 0) /* COLOR_BTNTEXT */,
81 RGB(192, 192, 192) /* COLOR_INACTIVECAPTIONTEXT */,
82 RGB(255, 255, 255) /* COLOR_BTNHILIGHT */,
83 RGB(32, 32, 32) /* COLOR_3DDKSHADOW */,
84 RGB(192, 192, 192) /* COLOR_3DLIGHT */,
85 RGB(0, 0, 0) /* COLOR_INFOTEXT */,
86 RGB(255, 255, 192) /* COLOR_INFOBK */,
87 RGB(180, 180, 180) /* COLOR_ALTERNATEBTNFACE */,
88 RGB(0, 0, 255) /* COLOR_HOTLIGHT */,
89 RGB(166, 202, 240) /* COLOR_GRADIENTACTIVECAPTION */,
90 RGB(192, 192, 192) /* COLOR_GRADIENTINACTIVECAPTION */,
93 #define NUM_SYSCOLORS (sizeof(SysColors) / sizeof(SysColors[0]))
95 /* Bits in the dwKeyData */
96 #define KEYDATA_ALT 0x2000
98 /* FUNCTIONS *****************************************************************/
104 GetSysColor(int nIndex
)
106 return SysColors
[nIndex
];
113 GetSysColorPen(int nIndex
)
115 static HPEN SysPens
[NUM_SYSCOLORS
];
117 if (nIndex
< 0 || NUM_SYSCOLORS
< nIndex
)
119 SetLastError(ERROR_INVALID_PARAMETER
);
123 /* FIXME should register this object with DeleteObject() so it
125 if (NULL
== SysPens
[nIndex
])
127 SysPens
[nIndex
] = CreatePen(PS_SOLID
, 1, SysColors
[nIndex
]);
130 return SysPens
[nIndex
];
137 GetSysColorBrush(int nIndex
)
139 static HBRUSH SysBrushes
[NUM_SYSCOLORS
];
141 if (nIndex
< 0 || NUM_SYSCOLORS
< nIndex
)
143 SetLastError(ERROR_INVALID_PARAMETER
);
147 /* FIXME should register this object with DeleteObject() so it
149 if (NULL
== SysBrushes
[nIndex
])
151 SysBrushes
[nIndex
] = (HBRUSH
) ((DWORD
) CreateSolidBrush(SysColors
[nIndex
]) | 0x00800000);
154 return SysBrushes
[nIndex
];
162 DefFrameProcA( HWND hWnd,
178 DefFrameProcW(HWND hWnd,
190 UserHasAnyFrameStyle(ULONG Style
, ULONG ExStyle
)
192 return ((Style
& (WS_THICKFRAME
| WS_DLGFRAME
| WS_BORDER
)) ||
193 (ExStyle
& WS_EX_DLGMODALFRAME
) ||
194 (!(Style
& (WS_CHILD
| WS_POPUP
))));
198 UserHasDlgFrameStyle(ULONG Style
, ULONG ExStyle
)
200 return ((ExStyle
& WS_EX_DLGMODALFRAME
) ||
201 ((Style
& WS_DLGFRAME
) && (!(Style
& WS_THICKFRAME
))));
205 UserHasThickFrameStyle(ULONG Style
, ULONG ExStyle
)
207 return ((Style
& WS_THICKFRAME
) &&
208 (!((Style
& (WS_DLGFRAME
| WS_BORDER
)) == WS_DLGFRAME
)));
212 UserHasThinFrameStyle(ULONG Style
, ULONG ExStyle
)
214 return ((Style
& WS_BORDER
) || (!(Style
& (WS_CHILD
| WS_POPUP
))));
218 UserHasBigFrameStyle(ULONG Style
, ULONG ExStyle
)
220 return ((Style
& (WS_THICKFRAME
| WS_DLGFRAME
)) ||
221 (ExStyle
& WS_EX_DLGMODALFRAME
));
225 UserGetInsideRectNC(HWND hWnd
, RECT
*rect
)
231 Style
= GetWindowLongW(hWnd
, GWL_STYLE
);
232 ExStyle
= GetWindowLongW(hWnd
, GWL_EXSTYLE
);
233 GetWindowRect(hWnd
, &WindowRect
);
234 rect
->top
= rect
->left
= 0;
235 rect
->right
= WindowRect
.right
- WindowRect
.left
;
236 rect
->bottom
= WindowRect
.bottom
- WindowRect
.top
;
238 if (Style
& WS_ICONIC
)
243 /* Remove frame from rectangle */
244 if (UserHasThickFrameStyle(Style
, ExStyle
))
246 InflateRect(rect
, -GetSystemMetrics(SM_CXFRAME
),
247 -GetSystemMetrics(SM_CYFRAME
));
251 if (UserHasDlgFrameStyle(Style
, ExStyle
))
253 InflateRect(rect
, -GetSystemMetrics(SM_CXDLGFRAME
),
254 -GetSystemMetrics(SM_CYDLGFRAME
));
255 /* FIXME: this isn't in NC_AdjustRect? why not? */
256 if (ExStyle
& WS_EX_DLGMODALFRAME
)
257 InflateRect( rect
, -1, 0 );
261 if (UserHasThinFrameStyle(Style
, ExStyle
))
263 InflateRect(rect
, -GetSystemMetrics(SM_CXBORDER
),
264 -GetSystemMetrics(SM_CYBORDER
));
272 DefWndSetRedraw(HWND hWnd
, WPARAM wParam
)
279 DefWndHandleSetCursor(HWND hWnd
, WPARAM wParam
, LPARAM lParam
, ULONG Style
)
281 /* Not for child windows. */
282 if (hWnd
!= (HWND
)wParam
)
287 switch(LOWORD(lParam
))
291 WORD Msg
= HIWORD(lParam
);
292 if (Msg
== WM_LBUTTONDOWN
|| Msg
== WM_MBUTTONDOWN
||
293 Msg
== WM_RBUTTONDOWN
|| Msg
== WM_XBUTTONDOWN
)
302 HICON hCursor
= (HICON
)GetClassLongW(hWnd
, GCL_HCURSOR
);
314 if (Style
& WS_MAXIMIZE
)
318 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZEWE
)));
324 if (Style
& WS_MAXIMIZE
)
328 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENS
)));
334 if (Style
& WS_MAXIMIZE
)
338 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENWSE
)));
344 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_MAXIMIZE
)
348 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENESW
)));
351 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_ARROW
)));
355 DefWndStartSizeMove(HWND hWnd
, WPARAM wParam
, POINT
*capturePoint
)
361 ULONG Style
= GetWindowLongW(hWnd
, GWL_STYLE
);
363 GetWindowRect(hWnd
, &rectWindow
);
365 if ((wParam
& 0xfff0) == SC_MOVE
)
367 /* Move pointer at the center of the caption */
369 UserGetInsideRectNC(hWnd
, &rect
);
370 if (Style
& WS_SYSMENU
)
371 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
372 if (Style
& WS_MINIMIZEBOX
)
373 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
374 if (Style
& WS_MAXIMIZEBOX
)
375 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
376 pt
.x
= rectWindow
.left
+ (rect
.right
- rect
.left
) / 2;
377 pt
.y
= rectWindow
.top
+ rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
385 GetMessageW(&msg
, NULL
, 0, 0);
389 hittest
= DefWndNCHitTest(hWnd
, msg
.pt
);
390 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
))
402 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
403 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
407 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
408 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
412 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
413 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
417 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
418 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
421 case VK_ESCAPE
: return 0;
427 SetCursorPos( pt
.x
, pt
.y
);
428 DefWndHandleSetCursor(hWnd
, (WPARAM
)hWnd
, MAKELONG(hittest
, WM_MOUSEMOVE
), Style
);
432 #define ON_LEFT_BORDER(hit) \
433 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
434 #define ON_RIGHT_BORDER(hit) \
435 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
436 #define ON_TOP_BORDER(hit) \
437 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
438 #define ON_BOTTOM_BORDER(hit) \
439 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
442 UserDrawWindowFrame(HDC hdc
, const RECT
*rect
,
443 ULONG width
, ULONG height
)
445 static HBRUSH hDraggingRectBrush
= NULL
;
447 if(!hDraggingRectBrush
)
449 static HBITMAP hDraggingPattern
= NULL
;
450 const DWORD Pattern
[4] = {0x5555AAAA, 0x5555AAAA, 0x5555AAAA, 0x5555AAAA};
452 hDraggingPattern
= CreateBitmap(8, 8, 1, 1, Pattern
);
453 hDraggingRectBrush
= CreatePatternBrush(hDraggingPattern
);
456 HBRUSH hbrush
= SelectObject( hdc
, hDraggingRectBrush
);
457 PatBlt( hdc
, rect
->left
, rect
->top
,
458 rect
->right
- rect
->left
- width
, height
, PATINVERT
);
459 PatBlt( hdc
, rect
->left
, rect
->top
+ height
, width
,
460 rect
->bottom
- rect
->top
- height
, PATINVERT
);
461 PatBlt( hdc
, rect
->left
+ width
, rect
->bottom
- 1,
462 rect
->right
- rect
->left
- width
, -height
, PATINVERT
);
463 PatBlt( hdc
, rect
->right
- 1, rect
->top
, -width
,
464 rect
->bottom
- rect
->top
- height
, PATINVERT
);
465 SelectObject( hdc
, hbrush
);
469 UserDrawMovingFrame(HDC hdc
, RECT
*rect
, BOOL thickframe
, HRGN ClipRgn
)
475 OldObj
= SelectObject(hdc
, ClipRgn
);
480 UserDrawWindowFrame(hdc
, rect
, GetSystemMetrics(SM_CXFRAME
), GetSystemMetrics(SM_CYFRAME
));
484 UserDrawWindowFrame(hdc
, rect
, 1, 1);
489 SelectObject(hdc
, OldObj
);
494 DefWndDoSizeMove(HWND hwnd
, WORD wParam
)
498 RECT sizingRect
, mouseRect
, origRect
, clipRect
;
500 LONG hittest
= (LONG
)(wParam
& 0x0f);
501 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
502 POINT minTrack
, maxTrack
;
503 POINT capturePoint
, pt
;
504 ULONG Style
= GetWindowLongW(hwnd
, GWL_STYLE
);
505 ULONG ExStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
507 BOOL iconic
= Style
& WS_MINIMIZE
;
509 DWORD dwPoint
= GetMessagePos();
510 BOOL DragFullWindows
= FALSE
;
513 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0);
515 pt
.x
= GET_X_LPARAM(dwPoint
);
516 pt
.y
= GET_Y_LPARAM(dwPoint
);
519 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
))
524 thickframe
= UserHasThickFrameStyle(Style
, ExStyle
) && !(Style
& WS_MINIMIZE
);
525 if ((wParam
& 0xfff0) == SC_MOVE
)
529 hittest
= DefWndStartSizeMove(hwnd
, wParam
, &capturePoint
);
542 if (hittest
&& ((wParam
& 0xfff0) != SC_MOUSEMENU
))
544 hittest
+= (HTLEFT
- WMSZ_LEFT
);
549 hittest
= DefWndStartSizeMove(hwnd
, wParam
, &capturePoint
);
558 if (Style
& WS_CHILD
)
560 hWndParent
= GetParent(hwnd
);
563 /* Get min/max info */
565 WinPosGetMinMaxInfo(hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
566 GetWindowRect(hwnd
, &sizingRect
);
567 if (Style
& WS_CHILD
)
569 MapWindowPoints( 0, hWndParent
, (LPPOINT
)&sizingRect
, 2 );
570 GetClientRect(hWndParent
, &mouseRect
);
571 clipRect
= mouseRect
;
572 MapWindowPoints(hWndParent
, HWND_DESKTOP
, (LPPOINT
)&clipRect
, 2);
576 SetRect(&mouseRect
, 0, 0, GetSystemMetrics(SM_CXSCREEN
),
577 GetSystemMetrics(SM_CYSCREEN
));
578 clipRect
= mouseRect
;
580 ClipCursor(&clipRect
);
582 origRect
= sizingRect
;
583 if (ON_LEFT_BORDER(hittest
))
585 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
586 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
588 else if (ON_RIGHT_BORDER(hittest
))
590 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
591 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
593 if (ON_TOP_BORDER(hittest
))
595 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
596 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
598 else if (ON_BOTTOM_BORDER(hittest
))
600 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
601 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
603 if (Style
& WS_CHILD
)
605 MapWindowPoints( hWndParent
, 0, (LPPOINT
)&mouseRect
, 2 );
608 SendMessageA( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
609 NtUserSetGUIThreadHandle(MSQ_STATE_MOVESIZE
, hwnd
);
610 if (GetCapture() != hwnd
) SetCapture( hwnd
);
612 if (Style
& WS_CHILD
)
614 /* Retrieve a default cache DC (without using the window style) */
615 hdc
= GetDCEx(hWndParent
, 0, DCX_CACHE
);
621 DesktopRgn
= CreateRectRgnIndirect(&clipRect
);
624 if( iconic
) /* create a cursor for dragging */
626 HICON hIcon
= (HICON
)GetClassLongW(hwnd
, GCL_HICON
);
627 if(!hIcon
) hIcon
= (HICON
)SendMessageW( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
628 if( hIcon
) hDragCursor
= CursorIconToCursor( hIcon
, TRUE
);
629 if( !hDragCursor
) iconic
= FALSE
;
632 /* invert frame if WIN31_LOOK to indicate mouse click on caption */
633 if( !iconic
&& !DragFullWindows
)
635 UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
, DesktopRgn
);
642 GetMessageW(&msg
, 0, 0, 0);
644 /* Exit on button-up, Return, or Esc */
645 if ((msg
.message
== WM_LBUTTONUP
) ||
646 ((msg
.message
== WM_KEYDOWN
) &&
647 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
649 if (msg
.message
== WM_PAINT
)
651 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
, DesktopRgn
);
652 UpdateWindow( msg
.hwnd
);
653 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
, DesktopRgn
);
657 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
658 continue; /* We are not interested in other messages */
662 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
664 case VK_UP
: pt
.y
-= 8; break;
665 case VK_DOWN
: pt
.y
+= 8; break;
666 case VK_LEFT
: pt
.x
-= 8; break;
667 case VK_RIGHT
: pt
.x
+= 8; break;
670 pt
.x
= max( pt
.x
, mouseRect
.left
);
671 pt
.x
= min( pt
.x
, mouseRect
.right
);
672 pt
.y
= max( pt
.y
, mouseRect
.top
);
673 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
675 dx
= pt
.x
- capturePoint
.x
;
676 dy
= pt
.y
- capturePoint
.y
;
684 if( iconic
) /* ok, no system popup tracking */
686 hOldCursor
= SetCursor(hDragCursor
);
691 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
694 RECT newRect
= sizingRect
;
695 WPARAM wpSizingHit
= 0;
697 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
698 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
699 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
700 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
701 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
702 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
, DesktopRgn
);
705 /* determine the hit location */
706 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
707 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
708 SendMessageA( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
713 UserDrawMovingFrame( hdc
, &newRect
, thickframe
, DesktopRgn
);
715 /* To avoid any deadlocks, all the locks on the windows
716 structures must be suspended before the SetWindowPos */
717 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
718 newRect
.right
- newRect
.left
,
719 newRect
.bottom
- newRect
.top
,
720 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
723 sizingRect
= newRect
;
732 if( moved
) /* restore cursors, show icon title later on */
735 SetCursor( hOldCursor
);
737 DestroyCursor( hDragCursor
);
739 else if(!DragFullWindows
)
740 UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
, DesktopRgn
);
742 if (Style
& WS_CHILD
)
743 ReleaseDC( hWndParent
, hdc
);
749 DeleteObject(DesktopRgn
);
752 NtUserSetGUIThreadHandle(MSQ_STATE_MOVESIZE
, NULL
);
753 SendMessageA( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
754 SendMessageA( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
756 /* window moved or resized */
759 /* if the moving/resizing isn't canceled call SetWindowPos
760 * with the new position or the new size of the window
762 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
764 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
766 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
767 sizingRect
.right
- sizingRect
.left
,
768 sizingRect
.bottom
- sizingRect
.top
,
769 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
771 else { /* restore previous size/position */
773 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
774 origRect
.right
- origRect
.left
,
775 origRect
.bottom
- origRect
.top
,
776 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
781 if( Style
& WS_MINIMIZE
)
783 /* Single click brings up the system menu when iconized */
787 if( Style
& WS_SYSMENU
)
788 SendMessageA( hwnd
, WM_SYSCOMMAND
,
789 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
795 /***********************************************************************
796 * DefWndTrackScrollBar
798 * Track a mouse button press on the horizontal or vertical scroll-bar.
801 DefWndTrackScrollBar(HWND Wnd
, WPARAM wParam
, POINT Pt
)
805 if (SC_HSCROLL
== (wParam
& 0xfff0))
807 if (HTHSCROLL
!= (wParam
& 0x0f))
813 else /* SC_VSCROLL */
815 if (HTVSCROLL
!= (wParam
& 0x0f))
821 ScrollTrackScrollBar(Wnd
, ScrollBar
, Pt
);
826 DefWndHandleSysCommand(HWND hWnd
, WPARAM wParam
, POINT Pt
)
830 switch (wParam
& 0xfff0)
834 DefWndDoSizeMove(hWnd
, wParam
);
837 wp
.length
= sizeof(WINDOWPLACEMENT
);
838 if(GetWindowPlacement(hWnd
, &wp
))
840 wp
.showCmd
= SW_MINIMIZE
;
841 SetWindowPlacement(hWnd
, &wp
);
845 wp
.length
= sizeof(WINDOWPLACEMENT
);
846 if(GetWindowPlacement(hWnd
, &wp
))
848 wp
.showCmd
= SW_MAXIMIZE
;
849 SetWindowPlacement(hWnd
, &wp
);
853 wp
.length
= sizeof(WINDOWPLACEMENT
);
854 if(GetWindowPlacement(hWnd
, &wp
))
856 wp
.showCmd
= SW_RESTORE
;
857 SetWindowPlacement(hWnd
, &wp
);
861 SendMessageA(hWnd
, WM_CLOSE
, 0, 0);
864 MenuTrackMouseMenuBar(hWnd
, wParam
& 0x000f, Pt
);
867 MenuTrackKbdMenuBar(hWnd
, wParam
, Pt
.x
);
871 DefWndTrackScrollBar(hWnd
, wParam
, Pt
);
875 /* FIXME: Implement */
884 DefWndHandleWindowPosChanging(HWND hWnd
, WINDOWPOS
* Pos
)
886 POINT maxSize
, minTrack
;
887 LONG style
= GetWindowLongA(hWnd
, GWL_STYLE
);
889 if (Pos
->flags
& SWP_NOSIZE
) return 0;
890 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
892 WinPosGetMinMaxInfo(hWnd
, &maxSize
, NULL
, &minTrack
, NULL
);
893 Pos
->cx
= min(Pos
->cx
, maxSize
.x
);
894 Pos
->cy
= min(Pos
->cy
, maxSize
.y
);
895 if (!(style
& WS_MINIMIZE
))
897 if (Pos
->cx
< minTrack
.x
) Pos
->cx
= minTrack
.x
;
898 if (Pos
->cy
< minTrack
.y
) Pos
->cy
= minTrack
.y
;
904 /* Undocumented flags. */
905 #define SWP_NOCLIENTMOVE 0x0800
906 #define SWP_NOCLIENTSIZE 0x1000
909 DefWndHandleWindowPosChanged(HWND hWnd
, WINDOWPOS
* Pos
)
913 GetClientRect(hWnd
, &Rect
);
914 MapWindowPoints(hWnd
, (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CHILD
?
915 GetParent(hWnd
) : NULL
), (LPPOINT
) &Rect
, 2);
917 if (! (Pos
->flags
& SWP_NOCLIENTMOVE
))
919 SendMessageW(hWnd
, WM_MOVE
, 0, MAKELONG(Rect
.left
, Rect
.top
));
922 if (! (Pos
->flags
& SWP_NOCLIENTSIZE
))
924 WPARAM wp
= SIZE_RESTORED
;
929 else if (IsIconic(hWnd
))
933 SendMessageW(hWnd
, WM_SIZE
, wp
,
934 MAKELONG(Rect
.right
- Rect
.left
, Rect
.bottom
- Rect
.top
));
940 /***********************************************************************
943 * Default colors for control painting.
946 DefWndControlColor(HDC hDC
, UINT ctlType
)
948 if (CTLCOLOR_SCROLLBAR
== ctlType
)
950 HBRUSH hb
= GetSysColorBrush(COLOR_SCROLLBAR
);
951 COLORREF bk
= GetSysColor(COLOR_3DHILIGHT
);
952 SetTextColor(hDC
, GetSysColor(COLOR_3DFACE
));
955 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
956 * we better use 0x55aa bitmap brush to make scrollbar's background
957 * look different from the window background.
959 if (bk
== GetSysColor(COLOR_WINDOW
))
961 static const WORD wPattern55AA
[] =
963 0x5555, 0xaaaa, 0x5555, 0xaaaa,
964 0x5555, 0xaaaa, 0x5555, 0xaaaa
966 static HBITMAP hPattern55AABitmap
= NULL
;
967 static HBRUSH hPattern55AABrush
= NULL
;
968 if (hPattern55AABrush
== NULL
)
970 hPattern55AABitmap
= CreateBitmap(8, 8, 1, 1, wPattern55AA
);
971 hPattern55AABrush
= CreatePatternBrush(hPattern55AABitmap
);
973 return hPattern55AABrush
;
979 SetTextColor(hDC
, GetSysColor(COLOR_WINDOWTEXT
));
981 if ((CTLCOLOR_EDIT
== ctlType
) || (CTLCOLOR_LISTBOX
== ctlType
))
983 SetBkColor(hDC
, GetSysColor(COLOR_WINDOW
));
987 SetBkColor(hDC
, GetSysColor(COLOR_3DFACE
));
988 return GetSysColorBrush(COLOR_3DFACE
);
991 return GetSysColorBrush(COLOR_WINDOW
);
995 DefWndScreenshot(HWND hWnd
)
1001 User32DefWindowProc(HWND hWnd
,
1011 return DefWndNCPaint(hWnd
, (HRGN
)wParam
);
1016 return DefWndNCCalcSize(hWnd
, (BOOL
)wParam
, (RECT
*)lParam
);
1021 return DefWndNCActivate(hWnd
, wParam
);
1027 Point
.x
= GET_X_LPARAM(lParam
);
1028 Point
.y
= GET_Y_LPARAM(lParam
);
1029 return (DefWndNCHitTest(hWnd
, Point
));
1032 case WM_NCLBUTTONDOWN
:
1034 return (DefWndNCLButtonDown(hWnd
, wParam
, lParam
));
1037 case WM_NCLBUTTONDBLCLK
:
1039 return (DefWndNCLButtonDblClk(hWnd
, wParam
, lParam
));
1042 case WM_WINDOWPOSCHANGING
:
1044 return (DefWndHandleWindowPosChanging(hWnd
, (WINDOWPOS
*)lParam
));
1047 case WM_WINDOWPOSCHANGED
:
1049 return (DefWndHandleWindowPosChanged(hWnd
, (WINDOWPOS
*)lParam
));
1055 if (hWnd
== GetCapture())
1059 Pt
.x
= GET_X_LPARAM(lParam
);
1060 Pt
.y
= GET_Y_LPARAM(lParam
);
1061 ClientToScreen(hWnd
, &Pt
);
1062 lParam
= MAKELPARAM(Pt
.x
, Pt
.y
);
1065 SendMessageW(hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
1069 SendMessageA(hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
1074 case WM_CONTEXTMENU
:
1076 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1080 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1084 SendMessageA(GetParent(hWnd
), WM_CONTEXTMENU
, wParam
, lParam
);
1093 Style
= GetWindowLongW(hWnd
, GWL_STYLE
);
1095 Pt
.x
= GET_X_LPARAM(lParam
);
1096 Pt
.y
= GET_Y_LPARAM(lParam
);
1097 if (Style
& WS_CHILD
)
1099 ScreenToClient(GetParent(hWnd
), &Pt
);
1102 HitCode
= DefWndNCHitTest(hWnd
, Pt
);
1104 if (HitCode
== HTCAPTION
|| HitCode
== HTSYSMENU
)
1109 if((SystemMenu
= GetSystemMenu(hWnd
, FALSE
)))
1111 MenuInitSysMenuPopup(SystemMenu
, GetWindowLongW(hWnd
, GWL_STYLE
),
1112 GetClassLongW(hWnd
, GCL_STYLE
), HitCode
);
1114 if(HitCode
== HTCAPTION
)
1115 Flags
= TPM_LEFTBUTTON
| TPM_RIGHTBUTTON
;
1117 Flags
= TPM_LEFTBUTTON
;
1119 TrackPopupMenu(SystemMenu
, Flags
,
1120 Pt
.x
, Pt
.y
, 0, hWnd
, NULL
);
1129 /* FIXME: Implement. */
1137 HDC hDC
= BeginPaint(hWnd
, &Ps
);
1141 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
&&
1142 (hIcon
= (HICON
)GetClassLongW(hWnd
, GCL_HICON
)) != NULL
)
1146 GetClientRect(hWnd
, &ClientRect
);
1147 x
= (ClientRect
.right
- ClientRect
.left
-
1148 GetSystemMetrics(SM_CXICON
)) / 2;
1149 y
= (ClientRect
.bottom
- ClientRect
.top
-
1150 GetSystemMetrics(SM_CYICON
)) / 2;
1151 DrawIcon(hDC
, x
, y
, hIcon
);
1153 EndPaint(hWnd
, &Ps
);
1161 hRgn
= CreateRectRgn(0, 0, 0, 0);
1162 if (GetUpdateRgn(hWnd
, hRgn
, FALSE
) != NULLREGION
)
1164 RedrawWindow(hWnd
, NULL
, hRgn
,
1165 RDW_ERASENOW
| RDW_ERASE
| RDW_FRAME
|
1174 DefWndSetRedraw(hWnd
, wParam
);
1180 DestroyWindow(hWnd
);
1184 case WM_MOUSEACTIVATE
:
1186 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1191 Ret
= SendMessageW(GetParent(hWnd
), WM_MOUSEACTIVATE
,
1196 Ret
= SendMessageA(GetParent(hWnd
), WM_MOUSEACTIVATE
,
1204 return ((LOWORD(lParam
) >= HTCLIENT
) ? MA_ACTIVATE
: MA_NOACTIVATE
);
1209 /* Check if the window is minimized. */
1210 if (LOWORD(wParam
) != WA_INACTIVE
&&
1211 !(GetWindowLongW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
1220 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1224 return (SendMessageW(GetParent(hWnd
), WM_MOUSEWHEEL
,
1229 return (SendMessageA(GetParent(hWnd
), WM_MOUSEWHEEL
,
1237 case WM_ICONERASEBKGND
:
1240 HBRUSH hBrush
= (HBRUSH
)GetClassLongW(hWnd
, GCL_HBRBACKGROUND
);
1246 if (GetClassLongW(hWnd
, GCL_STYLE
) & CS_PARENTDC
)
1248 /* can't use GetClipBox with a parent DC or we fill the whole parent */
1249 GetClientRect(hWnd
, &Rect
);
1250 DPtoLP((HDC
)wParam
, (LPPOINT
)&Rect
, 2);
1254 GetClipBox((HDC
)wParam
, &Rect
);
1256 FillRect((HDC
)wParam
, &Rect
, hBrush
);
1260 case WM_CTLCOLORMSGBOX
:
1261 case WM_CTLCOLOREDIT
:
1262 case WM_CTLCOLORLISTBOX
:
1263 case WM_CTLCOLORBTN
:
1264 case WM_CTLCOLORDLG
:
1265 case WM_CTLCOLORSTATIC
:
1266 case WM_CTLCOLORSCROLLBAR
:
1267 return (LRESULT
) DefWndControlColor((HDC
)wParam
, Msg
- WM_CTLCOLORMSGBOX
);
1271 ULONG Style
= GetWindowLongW(hWnd
, GWL_STYLE
);
1273 if (Style
& WS_CHILD
)
1275 if (LOWORD(lParam
) < HTLEFT
|| LOWORD(lParam
) > HTBOTTOMRIGHT
)
1280 bResult
= SendMessageW(GetParent(hWnd
), WM_SETCURSOR
,
1285 bResult
= SendMessageA(GetParent(hWnd
), WM_SETCURSOR
,
1294 return (DefWndHandleSetCursor(hWnd
, wParam
, lParam
, Style
));
1300 Pt
.x
= GET_X_LPARAM(lParam
);
1301 Pt
.y
= GET_Y_LPARAM(lParam
);
1302 return (DefWndHandleSysCommand(hWnd
, wParam
, Pt
));
1305 /* FIXME: Handle key messages. */
1313 /* FIXME: This is also incomplete. */
1316 if (HIWORD(lParam
) & KEYDATA_ALT
)
1318 if (wParam
== VK_F4
) /* Try to close the window */
1320 HWND top
= GetAncestor(hWnd
, GA_ROOT
);
1321 if (!(GetClassLongW(top
, GCL_STYLE
) & CS_NOCLOSE
))
1324 PostMessageW(top
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
1326 PostMessageA(top
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
1329 else if (wParam
== VK_SNAPSHOT
)
1331 DefWndScreenshot(hWnd
);
1343 Style
= GetWindowLongW(hWnd
, GWL_STYLE
);
1344 if (!(Style
& WS_POPUP
))
1346 if ((Style
& WS_VISIBLE
) && wParam
)
1348 if (!(Style
& WS_VISIBLE
) && !wParam
)
1350 if (!GetWindow(hWnd
, GW_OWNER
))
1352 ShowWindow(hWnd
, wParam
? SW_SHOWNA
: SW_HIDE
);
1358 /* FIXME: Check for a desktop. */
1359 if (GetCapture() == hWnd
)
1374 case WM_QUERYDROPOBJECT
:
1376 if (GetWindowLongW(hWnd
, GWL_EXSTYLE
) & WS_EX_ACCEPTFILES
)
1383 case WM_QUERYDRAGICON
:
1388 hIcon
= (HICON
)GetClassLongW(hWnd
, GCL_HICON
);
1391 return ((LRESULT
)hIcon
);
1393 for (Len
= 1; Len
< 64; Len
++)
1395 if ((hIcon
= LoadIconW(NULL
, MAKEINTRESOURCEW(Len
))) != NULL
)
1397 return((LRESULT
)hIcon
);
1400 return ((LRESULT
)LoadIconW(0, IDI_APPLICATION
));
1403 /* FIXME: WM_ISACTIVEICON */
1405 case WM_NOTIFYFORMAT
:
1407 if (IsWindowUnicode(hWnd
))
1409 return(NFR_UNICODE
);
1419 INT Index
= (wParam
!= 0) ? GCL_HICON
: GCL_HICONSM
;
1420 HICON hOldIcon
= (HICON
)GetClassLongW(hWnd
, Index
);
1421 SetClassLongW(hWnd
, Index
, lParam
);
1422 SetWindowPos(hWnd
, 0, 0, 0, 0, 0,
1423 SWP_FRAMECHANGED
| SWP_NOSIZE
| SWP_NOMOVE
|
1424 SWP_NOACTIVATE
| SWP_NOZORDER
);
1425 return ((LRESULT
)hOldIcon
);
1430 INT Index
= (wParam
== ICON_BIG
) ? GCL_HICON
: GCL_HICONSM
;
1431 return (GetClassLongW(hWnd
, Index
));
1438 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1442 SendMessageA(GetParent(hWnd
), Msg
, wParam
, lParam
);
1449 THRDCARETINFO CaretInfo
;
1452 case 0xffff: /* Caret timer */
1453 /* switch showing byte in win32k and get information about the caret */
1454 if(NtUserSwitchCaretShowing(&CaretInfo
) && (CaretInfo
.hWnd
== hWnd
))
1456 DrawCaret(hWnd
, &CaretInfo
);
1464 case WM_QUERYENDSESSION
:
1474 DefWindowProcA(HWND hWnd
,
1486 case WM_GETTEXTLENGTH
:
1488 return (LRESULT
)NtUserInternalGetWindowText(hWnd
, NULL
, 0);
1494 LPSTR AnsiBuffer
= (LPSTR
)lParam
;
1499 *((PWSTR
)lParam
) = '\0';
1501 Buffer
= HeapAlloc(GetProcessHeap(), 0, wParam
* sizeof(WCHAR
));
1504 Length
= NtUserInternalGetWindowText(hWnd
, Buffer
, wParam
);
1505 if (Length
> 0 && wParam
> 0 &&
1506 !WideCharToMultiByte(CP_ACP
, 0, Buffer
, -1,
1507 AnsiBuffer
, wParam
, NULL
, NULL
))
1509 AnsiBuffer
[0] = '\0';
1512 HeapFree(GetProcessHeap(), 0, Buffer
);
1514 return (LRESULT
)Length
;
1519 ANSI_STRING AnsiString
;
1520 UNICODE_STRING UnicodeString
;
1524 RtlInitAnsiString(&AnsiString
, (LPSTR
)lParam
);
1525 RtlAnsiStringToUnicodeString(&UnicodeString
, &AnsiString
, TRUE
);
1526 NtUserDefSetText(hWnd
, &UnicodeString
);
1527 RtlFreeUnicodeString(&UnicodeString
);
1530 NtUserDefSetText(hWnd
, NULL
);
1532 if ((GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1534 DefWndNCPaint(hWnd
, (HRGN
)1);
1540 FIXME: Implement these.
1542 case WM_IME_KEYDOWN:
1544 case WM_IME_STARTCOMPOSITION:
1545 case WM_IME_COMPOSITION:
1546 case WM_IME_ENDCOMPOSITION:
1548 case WM_IME_SETCONTEXT:
1552 return User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, FALSE
);
1557 DefWindowProcW(HWND hWnd
,
1569 case WM_GETTEXTLENGTH
:
1571 return (LRESULT
)NtUserInternalGetWindowText(hWnd
, NULL
, 0);
1578 *((PWSTR
)lParam
) = L
'\0';
1580 return (LRESULT
)NtUserInternalGetWindowText(hWnd
, (PWSTR
)lParam
, wParam
);
1585 UNICODE_STRING UnicodeString
;
1588 RtlInitUnicodeString(&UnicodeString
, (LPWSTR
)lParam
);
1590 NtUserDefSetText(hWnd
, (lParam
? &UnicodeString
: NULL
));
1592 if ((GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1594 DefWndNCPaint(hWnd
, (HRGN
)1);
1601 SendMessageW(hWnd
, WM_CHAR
, wParam
, lParam
);
1605 case WM_IME_SETCONTEXT
:
1612 return User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, TRUE
);