1 /* $Id: defwnd.c,v 1.141 2004/07/03 17:40:23 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
)
473 UserDrawWindowFrame(hdc
, rect
, GetSystemMetrics(SM_CXFRAME
), GetSystemMetrics(SM_CYFRAME
));
477 UserDrawWindowFrame(hdc
, rect
, 1, 1);
482 DefWndDoSizeMove(HWND hwnd
, WORD wParam
)
486 RECT sizingRect
, mouseRect
, origRect
, clipRect
;
488 LONG hittest
= (LONG
)(wParam
& 0x0f);
489 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
490 POINT minTrack
, maxTrack
;
491 POINT capturePoint
, pt
;
492 ULONG Style
= GetWindowLongW(hwnd
, GWL_STYLE
);
493 ULONG ExStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
495 BOOL iconic
= Style
& WS_MINIMIZE
;
497 DWORD dwPoint
= GetMessagePos();
498 BOOL DragFullWindows
= FALSE
;
499 HWND hWndParent
= NULL
;
501 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0);
503 pt
.x
= GET_X_LPARAM(dwPoint
);
504 pt
.y
= GET_Y_LPARAM(dwPoint
);
507 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
))
512 thickframe
= UserHasThickFrameStyle(Style
, ExStyle
) && !(Style
& WS_MINIMIZE
);
513 if ((wParam
& 0xfff0) == SC_MOVE
)
517 hittest
= DefWndStartSizeMove(hwnd
, wParam
, &capturePoint
);
530 if (hittest
&& ((wParam
& 0xfff0) != SC_MOUSEMENU
))
532 hittest
+= (HTLEFT
- WMSZ_LEFT
);
537 hittest
= DefWndStartSizeMove(hwnd
, wParam
, &capturePoint
);
546 if (Style
& WS_CHILD
)
548 hWndParent
= GetParent(hwnd
);
551 /* Get min/max info */
553 WinPosGetMinMaxInfo(hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
554 GetWindowRect(hwnd
, &sizingRect
);
555 if (Style
& WS_CHILD
)
557 MapWindowPoints( 0, hWndParent
, (LPPOINT
)&sizingRect
, 2 );
558 GetClientRect(hWndParent
, &mouseRect
);
559 clipRect
= mouseRect
;
560 MapWindowPoints(hWndParent
, HWND_DESKTOP
, (LPPOINT
)&clipRect
, 2);
564 if(!(ExStyle
& WS_EX_TOPMOST
))
566 SystemParametersInfoW(SPI_GETWORKAREA
, 0, &clipRect
, 0);
567 mouseRect
= clipRect
;
571 SetRect(&mouseRect
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
));
572 clipRect
= mouseRect
;
575 ClipCursor(&clipRect
);
577 origRect
= sizingRect
;
578 if (ON_LEFT_BORDER(hittest
))
580 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
581 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
583 else if (ON_RIGHT_BORDER(hittest
))
585 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
586 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
588 if (ON_TOP_BORDER(hittest
))
590 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
591 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
593 else if (ON_BOTTOM_BORDER(hittest
))
595 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
596 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
598 if (Style
& WS_CHILD
)
600 MapWindowPoints( hWndParent
, 0, (LPPOINT
)&mouseRect
, 2 );
603 SendMessageA( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
604 NtUserSetGUIThreadHandle(MSQ_STATE_MOVESIZE
, hwnd
);
605 if (GetCapture() != hwnd
) SetCapture( hwnd
);
607 if (Style
& WS_CHILD
)
609 /* Retrieve a default cache DC (without using the window style) */
610 hdc
= GetDCEx(hWndParent
, 0, DCX_CACHE
);
616 DesktopRgn
= CreateRectRgnIndirect(&clipRect
);
619 SelectObject(hdc
, DesktopRgn
);
621 if( iconic
) /* create a cursor for dragging */
623 HICON hIcon
= (HICON
)GetClassLongW(hwnd
, GCL_HICON
);
624 if(!hIcon
) hIcon
= (HICON
)SendMessageW( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
625 if( hIcon
) hDragCursor
= CursorIconToCursor( hIcon
, TRUE
);
626 if( !hDragCursor
) iconic
= FALSE
;
629 /* invert frame if WIN31_LOOK to indicate mouse click on caption */
630 if( !iconic
&& !DragFullWindows
)
632 UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
639 GetMessageW(&msg
, 0, 0, 0);
641 /* Exit on button-up, Return, or Esc */
642 if ((msg
.message
== WM_LBUTTONUP
) ||
643 ((msg
.message
== WM_KEYDOWN
) &&
644 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
646 if (msg
.message
== WM_PAINT
)
648 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
649 UpdateWindow( msg
.hwnd
);
650 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
654 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
655 continue; /* We are not interested in other messages */
659 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
661 case VK_UP
: pt
.y
-= 8; break;
662 case VK_DOWN
: pt
.y
+= 8; break;
663 case VK_LEFT
: pt
.x
-= 8; break;
664 case VK_RIGHT
: pt
.x
+= 8; break;
667 pt
.x
= max( pt
.x
, mouseRect
.left
);
668 pt
.x
= min( pt
.x
, mouseRect
.right
);
669 pt
.y
= max( pt
.y
, mouseRect
.top
);
670 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
672 dx
= pt
.x
- capturePoint
.x
;
673 dy
= pt
.y
- capturePoint
.y
;
681 if( iconic
) /* ok, no system popup tracking */
683 hOldCursor
= SetCursor(hDragCursor
);
688 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
691 RECT newRect
= sizingRect
;
692 WPARAM wpSizingHit
= 0;
694 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
695 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
696 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
697 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
698 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
699 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
702 /* determine the hit location */
703 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
704 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
705 SendMessageA( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
710 UserDrawMovingFrame( hdc
, &newRect
, thickframe
);
712 /* To avoid any deadlocks, all the locks on the windows
713 structures must be suspended before the SetWindowPos */
714 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
715 newRect
.right
- newRect
.left
,
716 newRect
.bottom
- newRect
.top
,
717 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
720 sizingRect
= newRect
;
729 if( moved
) /* restore cursors, show icon title later on */
732 SetCursor( hOldCursor
);
734 DestroyCursor( hDragCursor
);
736 else if(!DragFullWindows
)
737 UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
739 if (Style
& WS_CHILD
)
740 ReleaseDC( hWndParent
, hdc
);
746 DeleteObject(DesktopRgn
);
749 NtUserSetGUIThreadHandle(MSQ_STATE_MOVESIZE
, NULL
);
750 SendMessageA( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
751 SendMessageA( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
753 /* window moved or resized */
756 /* if the moving/resizing isn't canceled call SetWindowPos
757 * with the new position or the new size of the window
759 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
761 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
763 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
764 sizingRect
.right
- sizingRect
.left
,
765 sizingRect
.bottom
- sizingRect
.top
,
766 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
768 else { /* restore previous size/position */
770 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
771 origRect
.right
- origRect
.left
,
772 origRect
.bottom
- origRect
.top
,
773 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
778 if( Style
& WS_MINIMIZE
)
780 /* Single click brings up the system menu when iconized */
784 if( Style
& WS_SYSMENU
)
785 SendMessageA( hwnd
, WM_SYSCOMMAND
,
786 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
792 /***********************************************************************
793 * DefWndTrackScrollBar
795 * Track a mouse button press on the horizontal or vertical scroll-bar.
798 DefWndTrackScrollBar(HWND Wnd
, WPARAM wParam
, POINT Pt
)
802 if (SC_HSCROLL
== (wParam
& 0xfff0))
804 if (HTHSCROLL
!= (wParam
& 0x0f))
810 else /* SC_VSCROLL */
812 if (HTVSCROLL
!= (wParam
& 0x0f))
818 ScrollTrackScrollBar(Wnd
, ScrollBar
, Pt
);
823 DefWndHandleSysCommand(HWND hWnd
, WPARAM wParam
, POINT Pt
)
827 switch (wParam
& 0xfff0)
831 DefWndDoSizeMove(hWnd
, wParam
);
834 wp
.length
= sizeof(WINDOWPLACEMENT
);
835 if(GetWindowPlacement(hWnd
, &wp
))
837 wp
.showCmd
= SW_MINIMIZE
;
838 SetWindowPlacement(hWnd
, &wp
);
842 wp
.length
= sizeof(WINDOWPLACEMENT
);
843 if(GetWindowPlacement(hWnd
, &wp
))
845 wp
.showCmd
= SW_MAXIMIZE
;
846 SetWindowPlacement(hWnd
, &wp
);
850 wp
.length
= sizeof(WINDOWPLACEMENT
);
851 if(GetWindowPlacement(hWnd
, &wp
))
853 wp
.showCmd
= SW_RESTORE
;
854 SetWindowPlacement(hWnd
, &wp
);
858 SendMessageA(hWnd
, WM_CLOSE
, 0, 0);
861 MenuTrackMouseMenuBar(hWnd
, wParam
& 0x000f, Pt
);
864 MenuTrackKbdMenuBar(hWnd
, wParam
, Pt
.x
);
868 DefWndTrackScrollBar(hWnd
, wParam
, Pt
);
872 /* FIXME: Implement */
881 DefWndHandleWindowPosChanging(HWND hWnd
, WINDOWPOS
* Pos
)
883 POINT maxSize
, minTrack
;
884 LONG style
= GetWindowLongA(hWnd
, GWL_STYLE
);
886 if (Pos
->flags
& SWP_NOSIZE
) return 0;
887 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
889 WinPosGetMinMaxInfo(hWnd
, &maxSize
, NULL
, &minTrack
, NULL
);
890 Pos
->cx
= min(Pos
->cx
, maxSize
.x
);
891 Pos
->cy
= min(Pos
->cy
, maxSize
.y
);
892 if (!(style
& WS_MINIMIZE
))
894 if (Pos
->cx
< minTrack
.x
) Pos
->cx
= minTrack
.x
;
895 if (Pos
->cy
< minTrack
.y
) Pos
->cy
= minTrack
.y
;
900 Pos
->cx
= max(Pos
->cx
, 0);
901 Pos
->cy
= max(Pos
->cy
, 0);
906 /* Undocumented flags. */
907 #define SWP_NOCLIENTMOVE 0x0800
908 #define SWP_NOCLIENTSIZE 0x1000
911 DefWndHandleWindowPosChanged(HWND hWnd
, WINDOWPOS
* Pos
)
915 GetClientRect(hWnd
, &Rect
);
916 MapWindowPoints(hWnd
, (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CHILD
?
917 GetParent(hWnd
) : NULL
), (LPPOINT
) &Rect
, 2);
919 if (! (Pos
->flags
& SWP_NOCLIENTMOVE
))
921 SendMessageW(hWnd
, WM_MOVE
, 0, MAKELONG(Rect
.left
, Rect
.top
));
924 if (! (Pos
->flags
& SWP_NOCLIENTSIZE
))
926 WPARAM wp
= SIZE_RESTORED
;
931 else if (IsIconic(hWnd
))
935 SendMessageW(hWnd
, WM_SIZE
, wp
,
936 MAKELONG(Rect
.right
- Rect
.left
, Rect
.bottom
- Rect
.top
));
942 /***********************************************************************
945 * Default colors for control painting.
948 DefWndControlColor(HDC hDC
, UINT ctlType
)
950 if (CTLCOLOR_SCROLLBAR
== ctlType
)
952 HBRUSH hb
= GetSysColorBrush(COLOR_SCROLLBAR
);
953 COLORREF bk
= GetSysColor(COLOR_3DHILIGHT
);
954 SetTextColor(hDC
, GetSysColor(COLOR_3DFACE
));
957 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
958 * we better use 0x55aa bitmap brush to make scrollbar's background
959 * look different from the window background.
961 if (bk
== GetSysColor(COLOR_WINDOW
))
963 static const WORD wPattern55AA
[] =
965 0x5555, 0xaaaa, 0x5555, 0xaaaa,
966 0x5555, 0xaaaa, 0x5555, 0xaaaa
968 static HBITMAP hPattern55AABitmap
= NULL
;
969 static HBRUSH hPattern55AABrush
= NULL
;
970 if (hPattern55AABrush
== NULL
)
972 hPattern55AABitmap
= CreateBitmap(8, 8, 1, 1, wPattern55AA
);
973 hPattern55AABrush
= CreatePatternBrush(hPattern55AABitmap
);
975 return hPattern55AABrush
;
981 SetTextColor(hDC
, GetSysColor(COLOR_WINDOWTEXT
));
983 if ((CTLCOLOR_EDIT
== ctlType
) || (CTLCOLOR_LISTBOX
== ctlType
))
985 SetBkColor(hDC
, GetSysColor(COLOR_WINDOW
));
989 SetBkColor(hDC
, GetSysColor(COLOR_3DFACE
));
990 return GetSysColorBrush(COLOR_3DFACE
);
993 return GetSysColorBrush(COLOR_WINDOW
);
997 DefWndScreenshot(HWND hWnd
)
1003 User32DefWindowProc(HWND hWnd
,
1013 return DefWndNCPaint(hWnd
, (HRGN
)wParam
);
1018 return DefWndNCCalcSize(hWnd
, (BOOL
)wParam
, (RECT
*)lParam
);
1023 return DefWndNCActivate(hWnd
, wParam
);
1029 Point
.x
= GET_X_LPARAM(lParam
);
1030 Point
.y
= GET_Y_LPARAM(lParam
);
1031 return (DefWndNCHitTest(hWnd
, Point
));
1034 case WM_NCLBUTTONDOWN
:
1036 return (DefWndNCLButtonDown(hWnd
, wParam
, lParam
));
1039 case WM_NCLBUTTONDBLCLK
:
1041 return (DefWndNCLButtonDblClk(hWnd
, wParam
, lParam
));
1044 case WM_WINDOWPOSCHANGING
:
1046 return (DefWndHandleWindowPosChanging(hWnd
, (WINDOWPOS
*)lParam
));
1049 case WM_WINDOWPOSCHANGED
:
1051 return (DefWndHandleWindowPosChanged(hWnd
, (WINDOWPOS
*)lParam
));
1057 if (hWnd
== GetCapture())
1061 Pt
.x
= GET_X_LPARAM(lParam
);
1062 Pt
.y
= GET_Y_LPARAM(lParam
);
1063 ClientToScreen(hWnd
, &Pt
);
1064 lParam
= MAKELPARAM(Pt
.x
, Pt
.y
);
1067 SendMessageW(hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
1071 SendMessageA(hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
1076 case WM_CONTEXTMENU
:
1078 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1082 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1086 SendMessageA(GetParent(hWnd
), WM_CONTEXTMENU
, wParam
, lParam
);
1095 Style
= GetWindowLongW(hWnd
, GWL_STYLE
);
1097 Pt
.x
= GET_X_LPARAM(lParam
);
1098 Pt
.y
= GET_Y_LPARAM(lParam
);
1099 if (Style
& WS_CHILD
)
1101 ScreenToClient(GetParent(hWnd
), &Pt
);
1104 HitCode
= DefWndNCHitTest(hWnd
, Pt
);
1106 if (HitCode
== HTCAPTION
|| HitCode
== HTSYSMENU
)
1111 if((SystemMenu
= GetSystemMenu(hWnd
, FALSE
)))
1113 MenuInitSysMenuPopup(SystemMenu
, GetWindowLongW(hWnd
, GWL_STYLE
),
1114 GetClassLongW(hWnd
, GCL_STYLE
), HitCode
);
1116 if(HitCode
== HTCAPTION
)
1117 Flags
= TPM_LEFTBUTTON
| TPM_RIGHTBUTTON
;
1119 Flags
= TPM_LEFTBUTTON
;
1121 TrackPopupMenu(SystemMenu
, Flags
,
1122 Pt
.x
, Pt
.y
, 0, hWnd
, NULL
);
1131 /* FIXME: Implement. */
1139 HDC hDC
= BeginPaint(hWnd
, &Ps
);
1143 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
&&
1144 (hIcon
= (HICON
)GetClassLongW(hWnd
, GCL_HICON
)) != NULL
)
1148 GetClientRect(hWnd
, &ClientRect
);
1149 x
= (ClientRect
.right
- ClientRect
.left
-
1150 GetSystemMetrics(SM_CXICON
)) / 2;
1151 y
= (ClientRect
.bottom
- ClientRect
.top
-
1152 GetSystemMetrics(SM_CYICON
)) / 2;
1153 DrawIcon(hDC
, x
, y
, hIcon
);
1155 EndPaint(hWnd
, &Ps
);
1163 hRgn
= CreateRectRgn(0, 0, 0, 0);
1164 if (GetUpdateRgn(hWnd
, hRgn
, FALSE
) != NULLREGION
)
1166 RedrawWindow(hWnd
, NULL
, hRgn
,
1167 RDW_ERASENOW
| RDW_ERASE
| RDW_FRAME
|
1176 DefWndSetRedraw(hWnd
, wParam
);
1182 DestroyWindow(hWnd
);
1186 case WM_MOUSEACTIVATE
:
1188 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1193 Ret
= SendMessageW(GetParent(hWnd
), WM_MOUSEACTIVATE
,
1198 Ret
= SendMessageA(GetParent(hWnd
), WM_MOUSEACTIVATE
,
1206 return ((LOWORD(lParam
) >= HTCLIENT
) ? MA_ACTIVATE
: MA_NOACTIVATE
);
1211 /* Check if the window is minimized. */
1212 if (LOWORD(wParam
) != WA_INACTIVE
&&
1213 !(GetWindowLongW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
1222 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1226 return (SendMessageW(GetParent(hWnd
), WM_MOUSEWHEEL
,
1231 return (SendMessageA(GetParent(hWnd
), WM_MOUSEWHEEL
,
1239 case WM_ICONERASEBKGND
:
1242 HBRUSH hBrush
= (HBRUSH
)GetClassLongW(hWnd
, GCL_HBRBACKGROUND
);
1248 if (GetClassLongW(hWnd
, GCL_STYLE
) & CS_PARENTDC
)
1250 /* can't use GetClipBox with a parent DC or we fill the whole parent */
1251 GetClientRect(hWnd
, &Rect
);
1252 DPtoLP((HDC
)wParam
, (LPPOINT
)&Rect
, 2);
1256 GetClipBox((HDC
)wParam
, &Rect
);
1258 FillRect((HDC
)wParam
, &Rect
, hBrush
);
1262 case WM_CTLCOLORMSGBOX
:
1263 case WM_CTLCOLOREDIT
:
1264 case WM_CTLCOLORLISTBOX
:
1265 case WM_CTLCOLORBTN
:
1266 case WM_CTLCOLORDLG
:
1267 case WM_CTLCOLORSTATIC
:
1268 case WM_CTLCOLORSCROLLBAR
:
1269 return (LRESULT
) DefWndControlColor((HDC
)wParam
, Msg
- WM_CTLCOLORMSGBOX
);
1273 ULONG Style
= GetWindowLongW(hWnd
, GWL_STYLE
);
1275 if (Style
& WS_CHILD
)
1277 if (LOWORD(lParam
) < HTLEFT
|| LOWORD(lParam
) > HTBOTTOMRIGHT
)
1282 bResult
= SendMessageW(GetParent(hWnd
), WM_SETCURSOR
,
1287 bResult
= SendMessageA(GetParent(hWnd
), WM_SETCURSOR
,
1296 return (DefWndHandleSetCursor(hWnd
, wParam
, lParam
, Style
));
1302 Pt
.x
= GET_X_LPARAM(lParam
);
1303 Pt
.y
= GET_Y_LPARAM(lParam
);
1304 return (DefWndHandleSysCommand(hWnd
, wParam
, Pt
));
1307 /* FIXME: Handle key messages. */
1315 /* FIXME: This is also incomplete. */
1318 if (HIWORD(lParam
) & KEYDATA_ALT
)
1320 if (wParam
== VK_F4
) /* Try to close the window */
1322 HWND top
= GetAncestor(hWnd
, GA_ROOT
);
1323 if (!(GetClassLongW(top
, GCL_STYLE
) & CS_NOCLOSE
))
1326 PostMessageW(top
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
1328 PostMessageA(top
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
1331 else if (wParam
== VK_SNAPSHOT
)
1333 DefWndScreenshot(hWnd
);
1345 Style
= GetWindowLongW(hWnd
, GWL_STYLE
);
1346 if (!(Style
& WS_POPUP
))
1348 if ((Style
& WS_VISIBLE
) && wParam
)
1350 if (!(Style
& WS_VISIBLE
) && !wParam
)
1352 if (!GetWindow(hWnd
, GW_OWNER
))
1354 ShowWindow(hWnd
, wParam
? SW_SHOWNA
: SW_HIDE
);
1360 /* FIXME: Check for a desktop. */
1361 if (GetCapture() == hWnd
)
1376 case WM_QUERYDROPOBJECT
:
1378 if (GetWindowLongW(hWnd
, GWL_EXSTYLE
) & WS_EX_ACCEPTFILES
)
1385 case WM_QUERYDRAGICON
:
1390 hIcon
= (HICON
)GetClassLongW(hWnd
, GCL_HICON
);
1393 return ((LRESULT
)hIcon
);
1395 for (Len
= 1; Len
< 64; Len
++)
1397 if ((hIcon
= LoadIconW(NULL
, MAKEINTRESOURCEW(Len
))) != NULL
)
1399 return((LRESULT
)hIcon
);
1402 return ((LRESULT
)LoadIconW(0, IDI_APPLICATION
));
1405 /* FIXME: WM_ISACTIVEICON */
1407 case WM_NOTIFYFORMAT
:
1409 if (IsWindowUnicode(hWnd
))
1411 return(NFR_UNICODE
);
1421 INT Index
= (wParam
!= 0) ? GCL_HICON
: GCL_HICONSM
;
1422 HICON hOldIcon
= (HICON
)GetClassLongW(hWnd
, Index
);
1423 SetClassLongW(hWnd
, Index
, lParam
);
1424 SetWindowPos(hWnd
, 0, 0, 0, 0, 0,
1425 SWP_FRAMECHANGED
| SWP_NOSIZE
| SWP_NOMOVE
|
1426 SWP_NOACTIVATE
| SWP_NOZORDER
);
1427 return ((LRESULT
)hOldIcon
);
1432 INT Index
= (wParam
== ICON_BIG
) ? GCL_HICON
: GCL_HICONSM
;
1433 return (GetClassLongW(hWnd
, Index
));
1440 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1444 SendMessageA(GetParent(hWnd
), Msg
, wParam
, lParam
);
1451 THRDCARETINFO CaretInfo
;
1454 case 0xffff: /* Caret timer */
1455 /* switch showing byte in win32k and get information about the caret */
1456 if(NtUserSwitchCaretShowing(&CaretInfo
) && (CaretInfo
.hWnd
== hWnd
))
1458 DrawCaret(hWnd
, &CaretInfo
);
1466 case WM_QUERYENDSESSION
:
1476 DefWindowProcA(HWND hWnd
,
1488 case WM_GETTEXTLENGTH
:
1490 return (LRESULT
)NtUserInternalGetWindowText(hWnd
, NULL
, 0);
1496 LPSTR AnsiBuffer
= (LPSTR
)lParam
;
1501 *((PWSTR
)lParam
) = '\0';
1503 Buffer
= HeapAlloc(GetProcessHeap(), 0, wParam
* sizeof(WCHAR
));
1506 Length
= NtUserInternalGetWindowText(hWnd
, Buffer
, wParam
);
1507 if (Length
> 0 && wParam
> 0 &&
1508 !WideCharToMultiByte(CP_ACP
, 0, Buffer
, -1,
1509 AnsiBuffer
, wParam
, NULL
, NULL
))
1511 AnsiBuffer
[0] = '\0';
1514 HeapFree(GetProcessHeap(), 0, Buffer
);
1516 return (LRESULT
)Length
;
1521 ANSI_STRING AnsiString
;
1522 UNICODE_STRING UnicodeString
;
1526 RtlInitAnsiString(&AnsiString
, (LPSTR
)lParam
);
1527 RtlAnsiStringToUnicodeString(&UnicodeString
, &AnsiString
, TRUE
);
1528 NtUserDefSetText(hWnd
, &UnicodeString
);
1529 RtlFreeUnicodeString(&UnicodeString
);
1532 NtUserDefSetText(hWnd
, NULL
);
1534 if ((GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1536 DefWndNCPaint(hWnd
, (HRGN
)1);
1542 FIXME: Implement these.
1544 case WM_IME_KEYDOWN:
1546 case WM_IME_STARTCOMPOSITION:
1547 case WM_IME_COMPOSITION:
1548 case WM_IME_ENDCOMPOSITION:
1550 case WM_IME_SETCONTEXT:
1554 return User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, FALSE
);
1559 DefWindowProcW(HWND hWnd
,
1571 case WM_GETTEXTLENGTH
:
1573 return (LRESULT
)NtUserInternalGetWindowText(hWnd
, NULL
, 0);
1580 *((PWSTR
)lParam
) = L
'\0';
1582 return (LRESULT
)NtUserInternalGetWindowText(hWnd
, (PWSTR
)lParam
, wParam
);
1587 UNICODE_STRING UnicodeString
;
1590 RtlInitUnicodeString(&UnicodeString
, (LPWSTR
)lParam
);
1592 NtUserDefSetText(hWnd
, (lParam
? &UnicodeString
: NULL
));
1594 if ((GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1596 DefWndNCPaint(hWnd
, (HRGN
)1);
1603 SendMessageW(hWnd
, WM_CHAR
, wParam
, lParam
);
1607 case WM_IME_SETCONTEXT
:
1614 return User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, TRUE
);