2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: Window painting function
5 * FILE: subsystems/win32/win32k/ntuser/painting.c
6 * PROGRAMER: Filip Navara (xnavara@volny.cz)
8 * 06/06/2001 Created (?)
9 * 18/11/2003 Complete rewrite
12 /* INCLUDES ******************************************************************/
19 /* PRIVATE FUNCTIONS **********************************************************/
22 * @name IntIntersectWithParents
24 * Intersect window rectangle with all parent client rectangles.
27 * Pointer to child window to start intersecting from.
29 * Pointer to rectangle that we want to intersect in screen
30 * coordinates on input and intersected rectangle on output (if TRUE
34 * If any parent is minimized or invisible or the resulting rectangle
35 * is empty then FALSE is returned. Otherwise TRUE is returned.
39 IntIntersectWithParents(PWND Child
, RECTL
*WindowRect
)
43 ParentWnd
= Child
->spwndParent
;
44 while (ParentWnd
!= NULL
)
46 if (!(ParentWnd
->style
& WS_VISIBLE
) ||
47 (ParentWnd
->style
& WS_MINIMIZE
))
52 if (!RECTL_bIntersectRect(WindowRect
, WindowRect
, &ParentWnd
->rcClient
))
57 /* FIXME: Layered windows. */
59 ParentWnd
= ParentWnd
->spwndParent
;
66 IntValidateParent(PWND Child
, HRGN hValidateRgn
, BOOL Recurse
)
68 PWND ParentWnd
= Child
->spwndParent
;
72 if (ParentWnd
->style
& WS_CLIPCHILDREN
)
75 if (ParentWnd
->hrgnUpdate
!= 0)
80 IntInvalidateWindows( ParentWnd
,
82 RDW_VALIDATE
| RDW_NOCHILDREN
);
85 ParentWnd
= ParentWnd
->spwndParent
;
92 * @name IntCalcWindowRgn
94 * Get a window or client region.
98 IntCalcWindowRgn(PWND Wnd
, BOOL Client
)
103 hRgnWindow
= IntSysCreateRectRgnIndirect(&Wnd
->rcClient
);
105 hRgnWindow
= IntSysCreateRectRgnIndirect(&Wnd
->rcWindow
);
107 if (Wnd
->hrgnClip
!= NULL
&& !(Wnd
->style
& WS_MINIMIZE
))
109 NtGdiOffsetRgn(hRgnWindow
,
112 NtGdiCombineRgn(hRgnWindow
, hRgnWindow
, Wnd
->hrgnClip
, RGN_AND
);
113 NtGdiOffsetRgn(hRgnWindow
,
122 * @name IntGetNCUpdateRgn
124 * Get non-client update region of a window and optionally validate it.
127 * Pointer to window to get the NC update region from.
129 * Set to TRUE to force validating the NC update region.
132 * Handle to NC update region. The caller is responsible for deleting
137 IntGetNCUpdateRgn(PWND Window
, BOOL Validate
)
143 if (Window
->hrgnUpdate
!= NULL
&&
144 Window
->hrgnUpdate
!= HRGN_WINDOW
)
146 hRgnNonClient
= IntCalcWindowRgn(Window
, FALSE
);
149 * If region creation fails it's safe to fallback to whole
152 if (hRgnNonClient
== NULL
)
157 hRgnWindow
= IntCalcWindowRgn(Window
, TRUE
);
158 if (hRgnWindow
== NULL
)
160 GreDeleteObject(hRgnNonClient
);
164 RgnType
= NtGdiCombineRgn(hRgnNonClient
, hRgnNonClient
,
165 hRgnWindow
, RGN_DIFF
);
166 if (RgnType
== ERROR
)
168 GreDeleteObject(hRgnWindow
);
169 GreDeleteObject(hRgnNonClient
);
172 else if (RgnType
== NULLREGION
)
174 GreDeleteObject(hRgnWindow
);
175 GreDeleteObject(hRgnNonClient
);
180 * Remove the nonclient region from the standard update region if
181 * we were asked for it.
186 if (NtGdiCombineRgn(Window
->hrgnUpdate
, Window
->hrgnUpdate
,
187 hRgnWindow
, RGN_AND
) == NULLREGION
)
189 IntGdiSetRegionOwner(Window
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
190 GreDeleteObject(Window
->hrgnUpdate
);
191 Window
->hrgnUpdate
= NULL
;
192 if (!(Window
->state
& WNDS_INTERNALPAINT
))
193 MsqDecPaintCountQueue(Window
->head
.pti
->MessageQueue
);
197 GreDeleteObject(hRgnWindow
);
199 return hRgnNonClient
;
203 return Window
->hrgnUpdate
;
210 * Internal function used by IntRedrawWindow.
214 co_IntPaintWindows(PWND Wnd
, ULONG Flags
, BOOL Recurse
)
217 HWND hWnd
= Wnd
->head
.h
;
220 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
224 if (!IntValidateParent(Wnd
, Wnd
->hrgnUpdate
, Recurse
))
228 if (Flags
& RDW_UPDATENOW
)
230 if (Wnd
->hrgnUpdate
!= NULL
||
231 Wnd
->state
& WNDS_INTERNALPAINT
)
233 co_IntSendMessage(hWnd
, WM_PAINT
, 0, 0);
238 if (Wnd
->state
& WNDS_SENDNCPAINT
)
240 TempRegion
= IntGetNCUpdateRgn(Wnd
, TRUE
);
241 Wnd
->state
&= ~WNDS_SENDNCPAINT
;
242 MsqDecPaintCountQueue(Wnd
->head
.pti
->MessageQueue
);
243 co_IntSendMessage(hWnd
, WM_NCPAINT
, (WPARAM
)TempRegion
, 0);
247 if (Wnd
->state
& WNDS_SENDERASEBACKGROUND
)
251 hDC
= UserGetDCEx( Wnd
,
253 DCX_CACHE
|DCX_USESTYLE
|DCX_INTERSECTRGN
|DCX_KEEPCLIPRGN
);
255 Wnd
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
256 // Kill the loop, so Clear before we send.
257 if (!co_IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)hDC
, 0))
259 Wnd
->state
|= (WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
261 UserReleaseDC(Wnd
, hDC
, FALSE
);
268 * Check that the window is still valid at this point
270 if (!IntIsWindow(hWnd
))
276 * Paint child windows.
278 if (!(Flags
& RDW_NOCHILDREN
) &&
279 !(Wnd
->style
& WS_MINIMIZE
) &&
280 ((Flags
& RDW_ALLCHILDREN
) || !(Wnd
->style
& WS_CLIPCHILDREN
)) )
284 if ((List
= IntWinListChildren(Wnd
)))
286 /* FIXME: Handle WS_EX_TRANSPARENT */
287 for (phWnd
= List
; *phWnd
; ++phWnd
)
289 Wnd
= UserGetWindowObject(*phWnd
);
290 if (Wnd
&& (Wnd
->style
& WS_VISIBLE
))
292 USER_REFERENCE_ENTRY Ref
;
293 UserRefObjectCo(Wnd
, &Ref
);
294 co_IntPaintWindows(Wnd
, Flags
, TRUE
);
295 UserDerefObjectCo(Wnd
);
304 * IntInvalidateWindows
306 * Internal function used by IntRedrawWindow, UserRedrawDesktop,
307 * co_WinPosSetWindowPos, IntValidateParent, co_UserRedrawWindow.
310 IntInvalidateWindows(PWND Wnd
, HRGN hRgn
, ULONG Flags
)
313 BOOL HadPaintMessage
, HadNCPaintMessage
;
314 BOOL HasPaintMessage
, HasNCPaintMessage
;
316 DPRINT("IntInvalidateWindows start\n");
318 * If the nonclient is not to be redrawn, clip the region to the client
321 if (0 != (Flags
& RDW_INVALIDATE
) && 0 == (Flags
& RDW_FRAME
))
325 hRgnClient
= IntSysCreateRectRgnIndirect(&Wnd
->rcClient
);
326 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, hRgnClient
, RGN_AND
);
327 GreDeleteObject(hRgnClient
);
331 * Clip the given region with window rectangle (or region)
334 if (!Wnd
->hrgnClip
|| (Wnd
->style
& WS_MINIMIZE
))
338 hRgnWindow
= IntSysCreateRectRgnIndirect(&Wnd
->rcWindow
);
339 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, hRgnWindow
, RGN_AND
);
340 GreDeleteObject(hRgnWindow
);
344 NtGdiOffsetRgn( hRgn
,
347 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, Wnd
->hrgnClip
, RGN_AND
);
348 NtGdiOffsetRgn( hRgn
,
354 * Save current state of pending updates
357 HadPaintMessage
= Wnd
->hrgnUpdate
!= NULL
||
358 Wnd
->state
& WNDS_INTERNALPAINT
;
359 HadNCPaintMessage
= Wnd
->state
& WNDS_SENDNCPAINT
;
362 * Update the region and flags
365 if (Flags
& RDW_INVALIDATE
&& RgnType
!= NULLREGION
)
367 if (Wnd
->hrgnUpdate
== NULL
)
369 Wnd
->hrgnUpdate
= IntSysCreateRectRgn(0, 0, 0, 0);
370 IntGdiSetRegionOwner(Wnd
->hrgnUpdate
, GDI_OBJ_HMGR_PUBLIC
);
373 if (NtGdiCombineRgn(Wnd
->hrgnUpdate
, Wnd
->hrgnUpdate
,
374 hRgn
, RGN_OR
) == NULLREGION
)
376 IntGdiSetRegionOwner(Wnd
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
377 GreDeleteObject(Wnd
->hrgnUpdate
);
378 Wnd
->hrgnUpdate
= NULL
;
381 if (Flags
& RDW_FRAME
)
382 Wnd
->state
|= WNDS_SENDNCPAINT
;
383 if (Flags
& RDW_ERASE
)
384 Wnd
->state
|= WNDS_SENDERASEBACKGROUND
;
389 if (Flags
& RDW_VALIDATE
&& RgnType
!= NULLREGION
)
391 if (Wnd
->hrgnUpdate
!= NULL
)
393 if (NtGdiCombineRgn(Wnd
->hrgnUpdate
, Wnd
->hrgnUpdate
,
394 hRgn
, RGN_DIFF
) == NULLREGION
)
396 IntGdiSetRegionOwner(Wnd
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
397 GreDeleteObject(Wnd
->hrgnUpdate
);
398 Wnd
->hrgnUpdate
= NULL
;
402 if (Wnd
->hrgnUpdate
== NULL
)
403 Wnd
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
404 if (Flags
& RDW_NOFRAME
)
405 Wnd
->state
&= ~WNDS_SENDNCPAINT
;
406 if (Flags
& RDW_NOERASE
)
407 Wnd
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
410 if (Flags
& RDW_INTERNALPAINT
)
412 Wnd
->state
|= WNDS_INTERNALPAINT
;
415 if (Flags
& RDW_NOINTERNALPAINT
)
417 Wnd
->state
&= ~WNDS_INTERNALPAINT
;
421 * Process children if needed
424 if (!(Flags
& RDW_NOCHILDREN
) && !(Wnd
->style
& WS_MINIMIZE
) &&
425 ((Flags
& RDW_ALLCHILDREN
) || !(Wnd
->style
& WS_CLIPCHILDREN
)))
429 for (Child
= Wnd
->spwndChild
; Child
; Child
= Child
->spwndNext
)
431 if (Child
->style
& WS_VISIBLE
)
434 * Recursive call to update children hrgnUpdate
436 HRGN hRgnTemp
= IntSysCreateRectRgn(0, 0, 0, 0);
437 NtGdiCombineRgn(hRgnTemp
, hRgn
, 0, RGN_COPY
);
438 IntInvalidateWindows(Child
, hRgnTemp
, Flags
);
439 GreDeleteObject(hRgnTemp
);
446 * Fake post paint messages to window message queue if needed
449 HasPaintMessage
= Wnd
->hrgnUpdate
!= NULL
||
450 Wnd
->state
& WNDS_INTERNALPAINT
;
451 HasNCPaintMessage
= Wnd
->state
& WNDS_SENDNCPAINT
;
453 if (HasPaintMessage
!= HadPaintMessage
)
456 MsqDecPaintCountQueue(Wnd
->head
.pti
->MessageQueue
);
458 MsqIncPaintCountQueue(Wnd
->head
.pti
->MessageQueue
);
461 if (HasNCPaintMessage
!= HadNCPaintMessage
)
463 if (HadNCPaintMessage
)
464 MsqDecPaintCountQueue(Wnd
->head
.pti
->MessageQueue
);
466 MsqIncPaintCountQueue(Wnd
->head
.pti
->MessageQueue
);
468 DPRINT("IntInvalidateWindows exit\n");
472 * IntIsWindowDrawable
475 * Window is drawable when it is visible and all parents are not
480 IntIsWindowDrawable(PWND Wnd
)
484 for (WndObject
= Wnd
; WndObject
!= NULL
; WndObject
= WndObject
->spwndParent
)
486 if ( WndObject
->state2
& WNDS2_INDESTROY
||
487 WndObject
->state
& WNDS_DESTROYED
||
489 !(WndObject
->style
& WS_VISIBLE
) ||
490 ((WndObject
->style
& WS_MINIMIZE
) && (WndObject
!= Wnd
)))
502 * Internal version of NtUserRedrawWindow that takes WND as
509 const RECTL
* UpdateRect
,
514 DPRINT("co_UserRedrawWindow start\n");
518 * Validation of passed parameters.
521 if (!IntIsWindowDrawable(Window
))
523 return TRUE
; // Just do nothing!!!
528 * Transform the parameters UpdateRgn and UpdateRect into
529 * a region hRgn specified in screen coordinates.
532 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
)) // Both are OKAY!
534 if (UpdateRgn
!= NULL
)
536 hRgn
= IntSysCreateRectRgn(0, 0, 0, 0);
537 if (NtGdiCombineRgn(hRgn
, UpdateRgn
, NULL
, RGN_COPY
) == NULLREGION
)
539 GreDeleteObject(hRgn
);
543 NtGdiOffsetRgn(hRgn
, Window
->rcClient
.left
, Window
->rcClient
.top
);
545 else if (UpdateRect
!= NULL
)
547 if (!RECTL_bIsEmptyRect(UpdateRect
))
549 hRgn
= IntSysCreateRectRgnIndirect((RECTL
*)UpdateRect
);
550 NtGdiOffsetRgn(hRgn
, Window
->rcClient
.left
, Window
->rcClient
.top
);
553 else if ((Flags
& (RDW_INVALIDATE
| RDW_FRAME
)) == (RDW_INVALIDATE
| RDW_FRAME
) ||
554 (Flags
& (RDW_VALIDATE
| RDW_NOFRAME
)) == (RDW_VALIDATE
| RDW_NOFRAME
))
556 if (!RECTL_bIsEmptyRect(&Window
->rcWindow
))
557 hRgn
= IntSysCreateRectRgnIndirect(&Window
->rcWindow
);
561 if (!RECTL_bIsEmptyRect(&Window
->rcClient
))
562 hRgn
= IntSysCreateRectRgnIndirect(&Window
->rcClient
);
568 * Adjust the window update region depending on hRgn and flags.
571 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
| RDW_INTERNALPAINT
| RDW_NOINTERNALPAINT
) &&
574 IntInvalidateWindows(Window
, hRgn
, Flags
);
579 * Repaint and erase windows if needed.
582 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
584 co_IntPaintWindows(Window
, Flags
, FALSE
);
594 GreDeleteObject(hRgn
);
596 DPRINT("co_UserRedrawWindow exit\n");
602 IntIsWindowDirty(PWND Wnd
)
604 return (Wnd
->style
& WS_VISIBLE
) &&
605 ((Wnd
->hrgnUpdate
!= NULL
) ||
606 (Wnd
->state
& WNDS_INTERNALPAINT
) ||
607 (Wnd
->state
& WNDS_SENDNCPAINT
));
611 IntFindWindowToRepaint(PWND Window
, PTHREADINFO Thread
)
616 for (; Window
!= NULL
; Window
= Window
->spwndNext
)
618 if (IntWndBelongsToThread(Window
, Thread
) &&
619 IntIsWindowDirty(Window
))
621 /* Make sure all non-transparent siblings are already drawn. */
622 if (Window
->ExStyle
& WS_EX_TRANSPARENT
)
624 for (TempWindow
= Window
->spwndNext
; TempWindow
!= NULL
;
625 TempWindow
= TempWindow
->spwndNext
)
627 if (!(TempWindow
->ExStyle
& WS_EX_TRANSPARENT
) &&
628 IntWndBelongsToThread(TempWindow
, Thread
) &&
629 IntIsWindowDirty(TempWindow
))
631 return TempWindow
->head
.h
;
636 return Window
->head
.h
;
639 if (Window
->spwndChild
)
641 hChild
= IntFindWindowToRepaint(Window
->spwndChild
, Thread
);
659 if (!Thread
->cPaintsReady
)
662 if ((MsgFilterMin
!= 0 || MsgFilterMax
!= 0) &&
663 (MsgFilterMin
> WM_PAINT
|| MsgFilterMax
< WM_PAINT
))
666 Message
->hwnd
= IntFindWindowToRepaint(UserGetDesktopWindow(), PsGetCurrentThreadWin32Thread());
668 if (Message
->hwnd
== NULL
)
670 DPRINT1("PAINTING BUG: Thread marked as containing dirty windows, but no dirty windows found! Counts %d\n",Thread
->cPaintsReady
);
671 /* Hack to stop spamming the debuglog ! */
672 Thread
->cPaintsReady
= 0;
676 if (Window
!= NULL
&& Message
->hwnd
!= Window
->head
.h
)
679 Message
->message
= WM_PAINT
;
680 Message
->wParam
= Message
->lParam
= 0;
687 co_IntFixCaret(PWND Window
, RECTL
*lprc
, UINT flags
)
690 PTHRDCARETINFO CaretInfo
;
692 PUSER_MESSAGE_QUEUE ActiveMessageQueue
;
696 ASSERT_REFS_CO(Window
);
698 pti
= PsGetCurrentThreadWin32Thread();
699 Desktop
= pti
->rpdesk
;
700 ActiveMessageQueue
= Desktop
->ActiveMessageQueue
;
701 if (!ActiveMessageQueue
) return 0;
702 CaretInfo
= ActiveMessageQueue
->CaretInfo
;
703 hWndCaret
= CaretInfo
->hWnd
;
705 WndCaret
= UserGetWindowObject(hWndCaret
);
707 //fix: check for WndCaret can be null
708 if (WndCaret
== Window
||
709 ((flags
& SW_SCROLLCHILDREN
) && IntIsChildWindow(Window
, WndCaret
)))
711 POINT pt
, FromOffset
, ToOffset
;
714 pt
.x
= CaretInfo
->Pos
.x
;
715 pt
.y
= CaretInfo
->Pos
.y
;
716 IntGetClientOrigin(WndCaret
, &FromOffset
);
717 IntGetClientOrigin(Window
, &ToOffset
);
720 rcCaret
.right
= pt
.x
+ CaretInfo
->Size
.cx
;
721 rcCaret
.bottom
= pt
.y
+ CaretInfo
->Size
.cy
;
722 if (RECTL_bIntersectRect(lprc
, lprc
, &rcCaret
))
742 INT cx
, cy
, xSrc
, ySrc
;
744 if ( nFlags
& PW_CLIENTONLY
)
746 cx
= pwnd
->rcClient
.right
- pwnd
->rcClient
.left
;
747 cy
= pwnd
->rcClient
.bottom
- pwnd
->rcClient
.top
;
748 xSrc
= pwnd
->rcClient
.left
- pwnd
->rcWindow
.left
;
749 ySrc
= pwnd
->rcClient
.top
- pwnd
->rcWindow
.top
;
753 cx
= pwnd
->rcWindow
.right
- pwnd
->rcWindow
.left
;
754 cy
= pwnd
->rcWindow
.bottom
- pwnd
->rcWindow
.top
;
759 // TODO: Setup Redirection for Print.
762 /* Update the window just incase. */
763 co_IntPaintWindows( pwnd
, RDW_ERASENOW
|RDW_UPDATENOW
, FALSE
);
765 hdcSrc
= UserGetDCEx( pwnd
, NULL
, DCX_CACHE
|DCX_WINDOW
);
766 /* Print window to printer context. */
779 UserReleaseDC( pwnd
, hdcSrc
, FALSE
);
781 // TODO: Release Redirection from Print.
786 /* PUBLIC FUNCTIONS ***********************************************************/
796 NtUserBeginPaint(HWND hWnd
, PAINTSTRUCT
* UnsafePs
)
802 USER_REFERENCE_ENTRY Ref
;
804 DPRINT("Enter NtUserBeginPaint\n");
805 UserEnterExclusive();
807 if (!(Window
= UserGetWindowObject(hWnd
)))
812 UserRefObjectCo(Window
, &Ref
);
814 co_UserHideCaret(Window
);
816 if (Window
->state
& WNDS_SENDNCPAINT
)
820 hRgn
= IntGetNCUpdateRgn(Window
, FALSE
);
821 Window
->state
&= ~WNDS_SENDNCPAINT
;
822 MsqDecPaintCountQueue(Window
->head
.pti
->MessageQueue
);
823 co_IntSendMessage(hWnd
, WM_NCPAINT
, (WPARAM
)hRgn
, 0);
824 if (hRgn
!= HRGN_WINDOW
&& hRgn
!= NULL
&& GreIsHandleValid(hRgn
))
826 /* NOTE: The region can already by deleted! */
827 GreDeleteObject(hRgn
);
831 RtlZeroMemory(&Ps
, sizeof(PAINTSTRUCT
));
833 Ps
.hdc
= UserGetDCEx( Window
,
835 DCX_INTERSECTRGN
| DCX_USESTYLE
);
841 if (Window
->hrgnUpdate
!= NULL
)
843 MsqDecPaintCountQueue(Window
->head
.pti
->MessageQueue
);
844 GdiGetClipBox(Ps
.hdc
, &Ps
.rcPaint
);
845 IntGdiSetRegionOwner(Window
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
846 /* The region is part of the dc now and belongs to the process! */
847 Window
->hrgnUpdate
= NULL
;
851 if (Window
->state
& WNDS_INTERNALPAINT
)
852 MsqDecPaintCountQueue(Window
->head
.pti
->MessageQueue
);
854 IntGetClientRect(Window
, &Ps
.rcPaint
);
857 Window
->state
&= ~WNDS_INTERNALPAINT
;
859 if (Window
->state
& WNDS_SENDERASEBACKGROUND
)
861 Window
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
862 Ps
.fErase
= !co_IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)Ps
.hdc
, 0);
865 Window
->state
|= (WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
872 if (Window
->hrgnUpdate
)
874 if (!(Window
->style
& WS_CLIPCHILDREN
))
877 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
879 IntInvalidateWindows(Child
, Window
->hrgnUpdate
, RDW_FRAME
| RDW_ERASE
| RDW_INVALIDATE
| RDW_ALLCHILDREN
);
884 Status
= MmCopyToCaller(UnsafePs
, &Ps
, sizeof(PAINTSTRUCT
));
885 if (! NT_SUCCESS(Status
))
887 SetLastNtError(Status
);
894 if (Window
) UserDerefObjectCo(Window
);
896 DPRINT("Leave NtUserBeginPaint, ret=%i\n",_ret_
);
910 NtUserEndPaint(HWND hWnd
, CONST PAINTSTRUCT
* pUnsafePs
)
912 NTSTATUS Status
= STATUS_SUCCESS
;
914 DECLARE_RETURN(BOOL
);
915 USER_REFERENCE_ENTRY Ref
;
918 DPRINT("Enter NtUserEndPaint\n");
919 UserEnterExclusive();
921 if (!(Window
= UserGetWindowObject(hWnd
)))
928 ProbeForRead(pUnsafePs
, sizeof(*pUnsafePs
), 1);
929 hdc
= pUnsafePs
->hdc
;
931 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
933 Status
= _SEH2_GetExceptionCode();
936 if (!NT_SUCCESS(Status
))
941 UserReleaseDC(Window
, hdc
, TRUE
);
943 UserRefObjectCo(Window
, &Ref
);
944 co_UserShowCaret(Window
);
945 UserDerefObjectCo(Window
);
950 DPRINT("Leave NtUserEndPaint, ret=%i\n",_ret_
);
957 co_UserGetUpdateRgn(PWND Window
, HRGN hRgn
, BOOL bErase
)
962 ASSERT_REFS_CO(Window
);
964 if (Window
->hrgnUpdate
== NULL
)
966 RegionType
= (NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0) ? NULLREGION
: ERROR
);
970 Rect
= Window
->rcClient
;
971 IntIntersectWithParents(Window
, &Rect
);
972 NtGdiSetRectRgn(hRgn
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
);
973 RegionType
= NtGdiCombineRgn(hRgn
, hRgn
, Window
->hrgnUpdate
, RGN_AND
);
974 NtGdiOffsetRgn(hRgn
, -Window
->rcClient
.left
, -Window
->rcClient
.top
);
977 if (bErase
&& RegionType
!= NULLREGION
&& RegionType
!= ERROR
)
979 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
993 NtUserGetUpdateRgn(HWND hWnd
, HRGN hRgn
, BOOL bErase
)
998 USER_REFERENCE_ENTRY Ref
;
1000 DPRINT("Enter NtUserGetUpdateRgn\n");
1001 UserEnterExclusive();
1003 if (!(Window
= UserGetWindowObject(hWnd
)))
1008 UserRefObjectCo(Window
, &Ref
);
1009 ret
= co_UserGetUpdateRgn(Window
, hRgn
, bErase
);
1010 UserDerefObjectCo(Window
);
1015 DPRINT("Leave NtUserGetUpdateRgn, ret=%i\n",_ret_
);
1021 * NtUserGetUpdateRect
1028 NtUserGetUpdateRect(HWND hWnd
, LPRECT UnsafeRect
, BOOL bErase
)
1033 PROSRGNDATA RgnData
;
1035 DECLARE_RETURN(BOOL
);
1037 DPRINT("Enter NtUserGetUpdateRect\n");
1038 UserEnterExclusive();
1040 if (!(Window
= UserGetWindowObject(hWnd
)))
1045 if (Window
->hrgnUpdate
== NULL
)
1047 Rect
.left
= Rect
.top
= Rect
.right
= Rect
.bottom
= 0;
1051 /* Get the update region bounding box. */
1052 if (Window
->hrgnUpdate
== HRGN_WINDOW
)
1054 Rect
= Window
->rcClient
;
1058 RgnData
= RGNOBJAPI_Lock(Window
->hrgnUpdate
, NULL
);
1059 ASSERT(RgnData
!= NULL
);
1060 RegionType
= REGION_GetRgnBox(RgnData
, &Rect
);
1061 RGNOBJAPI_Unlock(RgnData
);
1063 if (RegionType
!= ERROR
&& RegionType
!= NULLREGION
)
1064 RECTL_bIntersectRect(&Rect
, &Rect
, &Window
->rcClient
);
1067 if (IntIntersectWithParents(Window
, &Rect
))
1069 RECTL_vOffsetRect(&Rect
,
1070 -Window
->rcClient
.left
,
1071 -Window
->rcClient
.top
);
1074 Rect
.left
= Rect
.top
= Rect
.right
= Rect
.bottom
= 0;
1078 if (bErase
&& !RECTL_bIsEmptyRect(&Rect
))
1080 USER_REFERENCE_ENTRY Ref
;
1081 UserRefObjectCo(Window
, &Ref
);
1082 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
1083 UserDerefObjectCo(Window
);
1086 if (UnsafeRect
!= NULL
)
1088 Status
= MmCopyToCaller(UnsafeRect
, &Rect
, sizeof(RECTL
));
1089 if (!NT_SUCCESS(Status
))
1091 EngSetLastError(ERROR_INVALID_PARAMETER
);
1096 RETURN(!RECTL_bIsEmptyRect(&Rect
));
1099 DPRINT("Leave NtUserGetUpdateRect, ret=%i\n",_ret_
);
1105 * NtUserRedrawWindow
1114 CONST RECT
*lprcUpdate
,
1118 RECTL SafeUpdateRect
;
1121 USER_REFERENCE_ENTRY Ref
;
1122 NTSTATUS Status
= STATUS_SUCCESS
;
1123 DECLARE_RETURN(BOOL
);
1125 DPRINT("Enter NtUserRedrawWindow\n");
1126 UserEnterExclusive();
1128 if (!(Wnd
= UserGetWindowObject(hWnd
? hWnd
: IntGetDesktopWindow())))
1137 ProbeForRead(lprcUpdate
, sizeof(RECTL
), 1);
1138 RtlCopyMemory(&SafeUpdateRect
, lprcUpdate
, sizeof(RECTL
));
1140 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1142 Status
= _SEH2_GetExceptionCode();
1145 if (!NT_SUCCESS(Status
))
1147 EngSetLastError(RtlNtStatusToDosError(Status
));
1152 if ( flags
& ~(RDW_ERASE
|RDW_FRAME
|RDW_INTERNALPAINT
|RDW_INVALIDATE
|
1153 RDW_NOERASE
|RDW_NOFRAME
|RDW_NOINTERNALPAINT
|RDW_VALIDATE
|
1154 RDW_ERASENOW
|RDW_UPDATENOW
|RDW_ALLCHILDREN
|RDW_NOCHILDREN
) )
1156 /* RedrawWindow fails only in case that flags are invalid */
1157 EngSetLastError(ERROR_INVALID_FLAGS
);
1161 UserRefObjectCo(Wnd
, &Ref
);
1163 Ret
= co_UserRedrawWindow( Wnd
,
1164 lprcUpdate
? &SafeUpdateRect
: NULL
,
1168 UserDerefObjectCo(Wnd
);
1173 DPRINT("Leave NtUserRedrawWindow, ret=%i\n",_ret_
);
1184 const RECTL
*prcScroll
,
1185 const RECTL
*prcClip
,
1190 RECTL rcScroll
, rcClip
, rcSrc
, rcDst
;
1193 GdiGetClipBox(hDC
, &rcClip
);
1197 RECTL_bIntersectRect(&rcClip
, &rcClip
, prcClip
);
1202 rcScroll
= *prcScroll
;
1203 RECTL_bIntersectRect(&rcSrc
, &rcClip
, prcScroll
);
1211 RECTL_vOffsetRect(&rcDst
, dx
, dy
);
1212 RECTL_bIntersectRect(&rcDst
, &rcDst
, &rcClip
);
1214 if (!NtGdiBitBlt( hDC
,
1217 rcDst
.right
- rcDst
.left
,
1218 rcDst
.bottom
- rcDst
.top
,
1229 /* Calculate the region that was invalidated by moving or
1230 could not be copied, because it was not visible */
1231 if (hrgnUpdate
|| prcUpdate
)
1233 HRGN hrgnOwn
, hrgnTmp
;
1236 pDC
= DC_LockDc(hDC
);
1242 /* Begin with the shifted and then clipped scroll rect */
1244 RECTL_vOffsetRect(&rcDst
, dx
, dy
);
1245 RECTL_bIntersectRect(&rcDst
, &rcDst
, &rcClip
);
1248 hrgnOwn
= hrgnUpdate
;
1249 if (!NtGdiSetRectRgn(hrgnOwn
, rcDst
.left
, rcDst
.top
, rcDst
.right
, rcDst
.bottom
))
1257 hrgnOwn
= IntSysCreateRectRgnIndirect(&rcDst
);
1260 /* Add the source rect */
1261 hrgnTmp
= IntSysCreateRectRgnIndirect(&rcSrc
);
1262 NtGdiCombineRgn(hrgnOwn
, hrgnOwn
, hrgnTmp
, RGN_OR
);
1264 /* Substract the part of the dest that was visible in source */
1265 prgnTmp
= RGNOBJAPI_Lock(hrgnTmp
, NULL
);
1266 IntGdiCombineRgn(prgnTmp
, prgnTmp
, pDC
->prgnVis
, RGN_AND
);
1267 RGNOBJAPI_Unlock(prgnTmp
);
1268 NtGdiOffsetRgn(hrgnTmp
, dx
, dy
);
1269 Result
= NtGdiCombineRgn(hrgnOwn
, hrgnOwn
, hrgnTmp
, RGN_DIFF
);
1271 /* DO NOT Unlock DC while messing with prgnVis! */
1274 GreDeleteObject(hrgnTmp
);
1278 IntGdiGetRgnBox(hrgnOwn
, prcUpdate
);
1283 GreDeleteObject(hrgnOwn
);
1287 Result
= NULLREGION
;
1303 const RECT
*prcUnsafeScroll
,
1304 const RECT
*prcUnsafeClip
,
1306 LPRECT prcUnsafeUpdate
)
1308 DECLARE_RETURN(DWORD
);
1309 RECTL rcScroll
, rcClip
, rcUpdate
;
1310 NTSTATUS Status
= STATUS_SUCCESS
;
1313 DPRINT("Enter NtUserScrollDC\n");
1314 UserEnterExclusive();
1318 if (prcUnsafeScroll
)
1320 ProbeForRead(prcUnsafeScroll
, sizeof(*prcUnsafeScroll
), 1);
1321 rcScroll
= *prcUnsafeScroll
;
1325 ProbeForRead(prcUnsafeClip
, sizeof(*prcUnsafeClip
), 1);
1326 rcClip
= *prcUnsafeClip
;
1328 if (prcUnsafeUpdate
)
1330 ProbeForWrite(prcUnsafeUpdate
, sizeof(*prcUnsafeUpdate
), 1);
1333 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1335 Status
= _SEH2_GetExceptionCode();
1338 if (!NT_SUCCESS(Status
))
1340 SetLastNtError(Status
);
1344 Result
= UserScrollDC( hDC
,
1347 prcUnsafeScroll
? &rcScroll
: 0,
1348 prcUnsafeClip
? &rcClip
: 0,
1350 prcUnsafeUpdate
? &rcUpdate
: NULL
);
1353 /* FIXME: Only if hRgnUpdate is invalid we should SetLastError(ERROR_INVALID_HANDLE) */
1357 if (prcUnsafeUpdate
)
1361 *prcUnsafeUpdate
= rcUpdate
;
1363 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1365 Status
= _SEH2_GetExceptionCode();
1368 if (!NT_SUCCESS(Status
))
1370 /* FIXME: SetLastError? */
1371 /* FIXME: correct? We have already scrolled! */
1379 DPRINT("Leave NtUserScrollDC, ret=%i\n",_ret_
);
1385 * NtUserScrollWindowEx
1392 NtUserScrollWindowEx(
1396 const RECT
*prcUnsafeScroll
,
1397 const RECT
*prcUnsafeClip
,
1399 LPRECT prcUnsafeUpdate
,
1402 RECTL rcScroll
, rcClip
, rcCaret
, rcUpdate
;
1404 PWND Window
= NULL
, CaretWnd
;
1406 HRGN hrgnOwn
= NULL
, hrgnTemp
;
1408 NTSTATUS Status
= STATUS_SUCCESS
;
1409 DECLARE_RETURN(DWORD
);
1410 USER_REFERENCE_ENTRY Ref
, CaretRef
;
1412 DPRINT("Enter NtUserScrollWindowEx\n");
1413 UserEnterExclusive();
1415 Window
= UserGetWindowObject(hWnd
);
1416 if (!Window
|| !IntIsWindowDrawable(Window
))
1418 Window
= NULL
; /* prevent deref at cleanup */
1421 UserRefObjectCo(Window
, &Ref
);
1423 IntGetClientRect(Window
, &rcClip
);
1427 if (prcUnsafeScroll
)
1429 ProbeForRead(prcUnsafeScroll
, sizeof(*prcUnsafeScroll
), 1);
1430 RECTL_bIntersectRect(&rcScroll
, &rcClip
, prcUnsafeScroll
);
1437 ProbeForRead(prcUnsafeClip
, sizeof(*prcUnsafeClip
), 1);
1438 RECTL_bIntersectRect(&rcClip
, &rcClip
, prcUnsafeClip
);
1441 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1443 Status
= _SEH2_GetExceptionCode();
1447 if (!NT_SUCCESS(Status
))
1449 SetLastNtError(Status
);
1453 if (rcClip
.right
<= rcClip
.left
|| rcClip
.bottom
<= rcClip
.top
||
1454 (dx
== 0 && dy
== 0))
1460 hrgnOwn
= hrgnUpdate
;
1462 hrgnOwn
= IntSysCreateRectRgn(0, 0, 0, 0);
1464 hDC
= UserGetDCEx(Window
, 0, DCX_CACHE
| DCX_USESTYLE
);
1467 /* FIXME: SetLastError? */
1472 hwndCaret
= co_IntFixCaret(Window
, &rcCaret
, flags
);
1474 Result
= UserScrollDC( hDC
,
1480 prcUnsafeUpdate
? &rcUpdate
: NULL
);
1482 UserReleaseDC(Window
, hDC
, FALSE
);
1485 * Take into account the fact that some damage may have occurred during
1489 hrgnTemp
= IntSysCreateRectRgn(0, 0, 0, 0);
1490 if (co_UserGetUpdateRgn(Window
, hrgnTemp
, FALSE
) != NULLREGION
)
1492 HRGN hrgnClip
= IntSysCreateRectRgnIndirect(&rcClip
);
1493 NtGdiOffsetRgn(hrgnTemp
, dx
, dy
);
1494 NtGdiCombineRgn(hrgnTemp
, hrgnTemp
, hrgnClip
, RGN_AND
);
1495 co_UserRedrawWindow(Window
, NULL
, hrgnTemp
, RDW_INVALIDATE
| RDW_ERASE
);
1496 GreDeleteObject(hrgnClip
);
1498 GreDeleteObject(hrgnTemp
);
1500 if (flags
& SW_SCROLLCHILDREN
)
1505 USER_REFERENCE_ENTRY WndRef
;
1508 IntGetClientOrigin(Window
, &ClientOrigin
);
1509 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
1511 rcChild
= Child
->rcWindow
;
1512 rcChild
.left
-= ClientOrigin
.x
;
1513 rcChild
.top
-= ClientOrigin
.y
;
1514 rcChild
.right
-= ClientOrigin
.x
;
1515 rcChild
.bottom
-= ClientOrigin
.y
;
1517 if (! prcUnsafeScroll
|| RECTL_bIntersectRect(&rcDummy
, &rcChild
, &rcScroll
))
1519 UserRefObjectCo(Child
, &WndRef
);
1520 co_WinPosSetWindowPos(Child
, 0, rcChild
.left
+ dx
, rcChild
.top
+ dy
, 0, 0,
1521 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
|
1523 UserDerefObjectCo(Child
);
1528 if (flags
& (SW_INVALIDATE
| SW_ERASE
))
1530 co_UserRedrawWindow(Window
, NULL
, hrgnOwn
, RDW_INVALIDATE
| RDW_ERASE
|
1531 ((flags
& SW_ERASE
) ? RDW_ERASENOW
: 0) |
1532 ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0));
1535 if ((CaretWnd
= UserGetWindowObject(hwndCaret
)))
1537 UserRefObjectCo(CaretWnd
, &CaretRef
);
1539 co_IntSetCaretPos(rcCaret
.left
+ dx
, rcCaret
.top
+ dy
);
1540 co_UserShowCaret(CaretWnd
);
1542 UserDerefObjectCo(CaretWnd
);
1545 if (prcUnsafeUpdate
)
1549 /* Probe here, to not fail on invalid pointer before scrolling */
1550 ProbeForWrite(prcUnsafeUpdate
, sizeof(*prcUnsafeUpdate
), 1);
1551 *prcUnsafeUpdate
= rcUpdate
;
1553 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1555 Status
= _SEH2_GetExceptionCode();
1559 if (!NT_SUCCESS(Status
))
1561 SetLastNtError(Status
);
1569 if (hrgnOwn
&& !hrgnUpdate
)
1571 GreDeleteObject(hrgnOwn
);
1575 UserDerefObjectCo(Window
);
1577 DPRINT("Leave NtUserScrollWindowEx, ret=%i\n",_ret_
);
1584 UserDrawSysMenuButton(
1591 PCURICON_OBJECT pIcon
;
1593 ASSERT(pWnd
&& lpRc
);
1595 /* Get the icon to draw. We don't care about WM_GETICON here. */
1597 hIcon
= pWnd
->pcls
->hIconSm
;
1601 DPRINT("Wnd class has no small icon.\n");
1602 hIcon
= pWnd
->pcls
->hIcon
;
1607 DPRINT("Wnd class hasn't any icon.\n");
1608 //FIXME: Draw "winlogo" icon.
1612 if(!(pIcon
= UserGetCurIconObject(hIcon
)))
1614 DPRINT1("UserGetCurIconObject() failed!\n");
1618 return UserDrawIconEx(hDc
, lpRc
->left
, lpRc
->top
, pIcon
,
1619 UserGetSystemMetrics(SM_CXSMICON
),
1620 UserGetSystemMetrics(SM_CYSMICON
),
1621 0, NULL
, DI_NORMAL
);
1625 UserDrawCaptionText(
1627 const PUNICODE_STRING Text
,
1631 HFONT hOldFont
= NULL
, hFont
= NULL
;
1632 COLORREF OldTextColor
;
1633 NONCLIENTMETRICSW nclm
;
1637 DPRINT("%s:", __FUNCTION__
);
1638 for(i
= 0; i
< Text
->Length
/sizeof(WCHAR
); i
++)
1639 DbgPrint("%C", Text
->Buffer
[i
]);
1640 DbgPrint(", %d\n", Text
->Length
/sizeof(WCHAR
));
1643 nclm
.cbSize
= sizeof(nclm
);
1644 if(!UserSystemParametersInfo(SPI_GETNONCLIENTMETRICS
,
1645 sizeof(NONCLIENTMETRICS
), &nclm
, 0))
1647 DPRINT1("%s: UserSystemParametersInfo() failed!\n", __FUNCTION__
);
1651 IntGdiSetBkMode(hDc
, TRANSPARENT
);
1653 if(uFlags
& DC_SMALLCAP
)
1654 Status
= TextIntCreateFontIndirect(&nclm
.lfSmCaptionFont
, &hFont
);
1655 else Status
= TextIntCreateFontIndirect(&nclm
.lfCaptionFont
, &hFont
);
1657 if(!NT_SUCCESS(Status
))
1659 DPRINT1("%s: TextIntCreateFontIndirect() failed! Status: 0x%x\n",
1660 __FUNCTION__
, Status
);
1664 hOldFont
= NtGdiSelectFont(hDc
, hFont
);
1667 DPRINT1("%s: SelectFont() failed!\n", __FUNCTION__
);
1668 GreDeleteObject(hFont
);
1672 if(uFlags
& DC_INBUTTON
)
1673 OldTextColor
= IntGdiSetTextColor(hDc
, IntGetSysColor(COLOR_BTNTEXT
));
1674 else OldTextColor
= IntGdiSetTextColor(hDc
, IntGetSysColor(uFlags
& DC_ACTIVE
1675 ? COLOR_CAPTIONTEXT
: COLOR_INACTIVECAPTIONTEXT
));
1677 //FIXME: If string doesn't fit to rc, truncate it and add ellipsis.
1679 GreExtTextOutW(hDc
, lpRc
->left
,
1680 lpRc
->top
, 0, NULL
, Text
->Buffer
,
1681 Text
->Length
/sizeof(WCHAR
), NULL
, 0);
1683 IntGdiSetTextColor(hDc
, OldTextColor
);
1684 NtGdiSelectFont(hDc
, hOldFont
);
1685 GreDeleteObject(hFont
);
1690 BOOL
UserDrawCaption(
1696 const PUNICODE_STRING str
,
1700 HBITMAP hMemBmp
= NULL
, hOldBmp
= NULL
;
1701 HBRUSH hOldBrush
= NULL
;
1704 UINT VCenter
= 0, Padding
= 0;
1706 LONG ButtonWidth
, IconWidth
;
1709 //ASSERT(pWnd != NULL);
1711 RECTL_vMakeWellOrdered(lpRc
);
1712 hMemBmp
= NtGdiCreateCompatibleBitmap(hDc
,
1713 lpRc
->right
- lpRc
->left
,
1714 lpRc
->bottom
- lpRc
->top
);
1718 DPRINT1("%s: NtGdiCreateCompatibleBitmap() failed!\n", __FUNCTION__
);
1722 hMemDc
= NtGdiCreateCompatibleDC(hDc
);
1725 DPRINT1("%s: NtGdiCreateCompatibleDC() failed!\n", __FUNCTION__
);
1729 hOldBmp
= NtGdiSelectBitmap(hMemDc
, hMemBmp
);
1732 DPRINT1("%s: NtGdiSelectBitmap() failed!\n", __FUNCTION__
);
1736 Height
= UserGetSystemMetrics(SM_CYCAPTION
) - 1;
1737 VCenter
= (lpRc
->bottom
- lpRc
->top
) / 2;
1738 Padding
= VCenter
- (Height
/ 2);
1740 if ((!hIcon
) && (pWnd
!= NULL
))
1742 HasIcon
= (uFlags
& DC_ICON
) && (pWnd
->style
& WS_SYSMENU
)
1743 && !(uFlags
& DC_SMALLCAP
) && !(pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1744 && !(pWnd
->ExStyle
& WS_EX_TOOLWINDOW
);
1747 HasIcon
= (hIcon
!= 0);
1749 IconWidth
= UserGetSystemMetrics(SM_CXSIZE
) + Padding
;
1752 r
.right
= r
.left
+ (lpRc
->right
- lpRc
->left
);
1754 r
.bottom
= r
.top
+ (Height
/ 2);
1756 // Draw the caption background
1757 if(uFlags
& DC_INBUTTON
)
1759 hOldBrush
= NtGdiSelectBrush(hMemDc
,
1760 IntGetSysColorBrush(COLOR_3DFACE
));
1764 DPRINT1("%s: NtGdiSelectBrush() failed!\n", __FUNCTION__
);
1768 if(!NtGdiPatBlt(hMemDc
, 0, 0,
1769 lpRc
->right
- lpRc
->left
,
1770 lpRc
->bottom
- lpRc
->top
,
1773 DPRINT1("%s: NtGdiPatBlt() failed!\n", __FUNCTION__
);
1777 if(HasIcon
) r
.left
+=IconWidth
;
1781 r
.right
= (lpRc
->right
- lpRc
->left
);
1782 if(uFlags
& DC_SMALLCAP
)
1783 ButtonWidth
= UserGetSystemMetrics(SM_CXSMSIZE
) - 2;
1784 else ButtonWidth
= UserGetSystemMetrics(SM_CXSIZE
) - 2;
1786 hOldBrush
= NtGdiSelectBrush(hMemDc
,
1787 IntGetSysColorBrush(uFlags
& DC_ACTIVE
?
1788 COLOR_ACTIVECAPTION
: COLOR_INACTIVECAPTION
));
1792 DPRINT1("%s: NtGdiSelectBrush() failed!\n", __FUNCTION__
);
1796 if(HasIcon
&& (uFlags
& DC_GRADIENT
))
1798 NtGdiPatBlt(hMemDc
, 0, 0,
1800 lpRc
->bottom
- lpRc
->top
,
1806 NtGdiPatBlt(hMemDc
, 0, 0,
1807 lpRc
->right
- lpRc
->left
,
1808 lpRc
->bottom
- lpRc
->top
,
1812 if(uFlags
& DC_GRADIENT
)
1814 static GRADIENT_RECT gcap
= {0, 1};
1820 if(pWnd
->style
& WS_SYSMENU
)
1822 r
.right
-= 3 + ButtonWidth
;
1823 if(!(uFlags
& DC_SMALLCAP
))
1825 if(pWnd
->style
& (WS_MAXIMIZEBOX
| WS_MINIMIZEBOX
))
1826 r
.right
-= 2 + 2 * ButtonWidth
;
1831 //Draw buttons background
1832 if(!NtGdiSelectBrush(hMemDc
,
1833 IntGetSysColorBrush(uFlags
& DC_ACTIVE
?
1834 COLOR_GRADIENTACTIVECAPTION
:COLOR_GRADIENTINACTIVECAPTION
)))
1836 DPRINT1("%s: NtGdiSelectBrush() failed!\n", __FUNCTION__
);
1843 lpRc
->right
- lpRc
->left
- r
.right
,
1844 lpRc
->bottom
- lpRc
->top
,
1849 Colors
[0] = IntGetSysColor((uFlags
& DC_ACTIVE
) ?
1850 COLOR_ACTIVECAPTION
: COLOR_INACTIVECAPTION
);
1852 Colors
[1] = IntGetSysColor((uFlags
& DC_ACTIVE
) ?
1853 COLOR_GRADIENTACTIVECAPTION
: COLOR_GRADIENTINACTIVECAPTION
);
1857 vert
[0].Red
= (WORD
)Colors
[0]<<8;
1858 vert
[0].Green
= (WORD
)Colors
[0] & 0xFF00;
1859 vert
[0].Blue
= (WORD
)(Colors
[0]>>8) & 0xFF00;
1862 vert
[1].x
= r
.right
;
1863 vert
[1].y
= lpRc
->bottom
- lpRc
->top
;
1864 vert
[1].Red
= (WORD
)Colors
[1]<<8;
1865 vert
[1].Green
= (WORD
)Colors
[1] & 0xFF00;
1866 vert
[1].Blue
= (WORD
)(Colors
[1]>>8) & 0xFF00;
1869 if(!GreGradientFill(hMemDc
, vert
, 2, &gcap
,
1870 1, GRADIENT_FILL_RECT_H
))
1872 DPRINT1("%s: IntGdiGradientFill() failed!\n", __FUNCTION__
);
1875 } //if(uFlags & DC_GRADIENT)
1881 r
.left
-= --IconWidth
;
1882 /* FIXME: Draw the Icon when pWnd == NULL but hIcon is valid */
1884 UserDrawSysMenuButton(pWnd
, hMemDc
, &r
, FALSE
);
1886 r
.left
+= IconWidth
;
1893 r
.bottom
= r
.top
+ Height
;
1895 if((uFlags
& DC_TEXT
))
1897 if(!(uFlags
& DC_GRADIENT
))
1899 r
.right
= (lpRc
->right
- lpRc
->left
);
1901 if(uFlags
& DC_SMALLCAP
)
1902 ButtonWidth
= UserGetSystemMetrics(SM_CXSMSIZE
) - 2;
1903 else ButtonWidth
= UserGetSystemMetrics(SM_CXSIZE
) - 2;
1905 if ((pWnd
!= NULL
) && (pWnd
->style
& WS_SYSMENU
))
1907 r
.right
-= 3 + ButtonWidth
;
1908 if(! (uFlags
& DC_SMALLCAP
))
1910 if(pWnd
->style
& (WS_MAXIMIZEBOX
| WS_MINIMIZEBOX
))
1911 r
.right
-= 2 + 2 * ButtonWidth
;
1918 /* FIXME: hFont isn't handled */
1920 UserDrawCaptionText(hMemDc
, str
, &r
, uFlags
);
1921 else if (pWnd
!= NULL
)
1923 UNICODE_STRING ustr
;
1924 ustr
.Buffer
= pWnd
->strName
.Buffer
;
1925 ustr
.Length
= pWnd
->strName
.Length
;
1926 ustr
.MaximumLength
= pWnd
->strName
.MaximumLength
;
1927 UserDrawCaptionText(hMemDc
, &ustr
, &r
, uFlags
);
1931 if(!NtGdiBitBlt(hDc
, lpRc
->left
, lpRc
->top
,
1932 lpRc
->right
- lpRc
->left
, lpRc
->bottom
- lpRc
->top
,
1933 hMemDc
, 0, 0, SRCCOPY
, 0, 0))
1935 DPRINT1("%s: NtGdiBitBlt() failed!\n", __FUNCTION__
);
1942 if (hOldBrush
) NtGdiSelectBrush(hMemDc
, hOldBrush
);
1943 if (hOldBmp
) NtGdiSelectBitmap(hMemDc
, hOldBmp
);
1944 if (hMemBmp
) GreDeleteObject(hMemBmp
);
1945 if (hMemDc
) NtGdiDeleteObjectApp(hMemDc
);
1952 UserRealizePalette(HDC hdc
)
1957 Ret
= IntGdiRealizePalette(hdc
);
1958 if (Ret
) // There was a change.
1960 hWnd
= IntWindowFromDC(hdc
);
1961 if (hWnd
) // Send broadcast if dc is associated with a window.
1962 { // FYI: Thread locked in CallOneParam.
1963 UserSendNotifyMessage((HWND
)HWND_BROADCAST
, WM_PALETTECHANGED
, (WPARAM
)hWnd
, 0);
1971 NtUserDrawCaptionTemp(
1977 const PUNICODE_STRING str
,
1981 UNICODE_STRING SafeStr
= {0};
1982 NTSTATUS Status
= STATUS_SUCCESS
;
1986 UserEnterExclusive();
1990 if(!(pWnd
= UserGetWindowObject(hWnd
)))
1999 ProbeForRead(lpRc
, sizeof(RECTL
), sizeof(ULONG
));
2000 RtlCopyMemory(&SafeRect
, lpRc
, sizeof(RECTL
));
2003 SafeStr
= ProbeForReadUnicodeString(str
);
2004 if (SafeStr
.Length
!= 0)
2006 ProbeForRead( SafeStr
.Buffer
,
2012 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2014 Status
= _SEH2_GetExceptionCode();
2018 if (Status
!= STATUS_SUCCESS
)
2020 SetLastNtError(Status
);
2026 Ret
= UserDrawCaption(pWnd
, hDC
, &SafeRect
, hFont
, hIcon
, &SafeStr
, uFlags
);
2028 Ret
= UserDrawCaption(pWnd
, hDC
, &SafeRect
, hFont
, hIcon
, NULL
, uFlags
);
2036 NtUserDrawCaption(HWND hWnd
,
2041 return NtUserDrawCaptionTemp(hWnd
, hDC
, lpRc
, 0, 0, NULL
, uFlags
);
2046 NtUserInvalidateRect(
2048 CONST RECT
*lpUnsafeRect
,
2051 return NtUserRedrawWindow(hWnd
, lpUnsafeRect
, NULL
, RDW_INVALIDATE
| (bErase
? RDW_ERASE
: 0));
2056 NtUserInvalidateRgn(
2061 return NtUserRedrawWindow(hWnd
, NULL
, hRgn
, RDW_INVALIDATE
| (bErase
? RDW_ERASE
: 0));
2074 UserEnterExclusive();
2078 Window
= UserGetWindowObject(hwnd
);
2079 // TODO: Add Desktop and MessageBox check via FNID's.
2082 /* Validate flags and check it as a mask for 0 or 1. */
2083 if ( (nFlags
& PW_CLIENTONLY
) == nFlags
)
2084 Ret
= IntPrintWindow( Window
, hdcBlt
, nFlags
);
2086 EngSetLastError(ERROR_INVALID_PARAMETER
);
2094 /* ValidateRect gets redirected to NtUserValidateRect:
2095 http://blog.csdn.net/ntdll/archive/2005/10/19/509299.aspx */
2104 return NtUserRedrawWindow(hWnd
, lpRect
, NULL
, RDW_VALIDATE
);
2106 return NtUserRedrawWindow(hWnd
, lpRect
, NULL
, RDW_INVALIDATE
|RDW_ERASE
|RDW_ERASENOW
|RDW_ALLCHILDREN
);