2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: Window painting function
5 * FILE: subsys/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
)1)
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 REGION_FreeRgnByHandle(hRgnNonClient
);
164 RgnType
= NtGdiCombineRgn(hRgnNonClient
, hRgnNonClient
,
165 hRgnWindow
, RGN_DIFF
);
166 if (RgnType
== ERROR
)
168 REGION_FreeRgnByHandle(hRgnWindow
);
169 REGION_FreeRgnByHandle(hRgnNonClient
);
172 else if (RgnType
== NULLREGION
)
174 REGION_FreeRgnByHandle(hRgnWindow
);
175 REGION_FreeRgnByHandle(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 REGION_FreeRgnByHandle(Window
->hrgnUpdate
);
191 Window
->hrgnUpdate
= NULL
;
192 if (!(Window
->state
& WNDS_INTERNALPAINT
))
193 MsqDecPaintCountQueue(Window
->head
.pti
->MessageQueue
);
197 REGION_FreeRgnByHandle(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);
245 if ( (HANDLE
) 1 != TempRegion
&&
248 /* NOTE: The region can already be deleted! */
249 GDIOBJ_FreeObjByHandle(TempRegion
, GDI_OBJECT_TYPE_REGION
| GDI_OBJECT_TYPE_SILENT
);
253 if (Wnd
->state
& WNDS_ERASEBACKGROUND
)
257 hDC
= UserGetDCEx( Wnd
,
259 DCX_CACHE
|DCX_USESTYLE
|DCX_INTERSECTRGN
|DCX_KEEPCLIPRGN
);
261 if (co_IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)hDC
, 0))
263 Wnd
->state
&= ~WNDS_ERASEBACKGROUND
;
265 UserReleaseDC(Wnd
, hDC
, FALSE
);
272 * Check that the window is still valid at this point
274 if (!IntIsWindow(hWnd
))
280 * Paint child windows.
282 if (!(Flags
& RDW_NOCHILDREN
) &&
283 !(Wnd
->style
& WS_MINIMIZE
) &&
284 ((Flags
& RDW_ALLCHILDREN
) || !(Wnd
->style
& WS_CLIPCHILDREN
)) )
288 if ((List
= IntWinListChildren(Wnd
)))
290 /* FIXME: Handle WS_EX_TRANSPARENT */
291 for (phWnd
= List
; *phWnd
; ++phWnd
)
293 Wnd
= UserGetWindowObject(*phWnd
);
294 if (Wnd
&& (Wnd
->style
& WS_VISIBLE
))
296 USER_REFERENCE_ENTRY Ref
;
297 UserRefObjectCo(Wnd
, &Ref
);
298 co_IntPaintWindows(Wnd
, Flags
, TRUE
);
299 UserDerefObjectCo(Wnd
);
308 * IntInvalidateWindows
310 * Internal function used by IntRedrawWindow.
314 IntInvalidateWindows(PWND Wnd
, HRGN hRgn
, ULONG Flags
)
317 BOOL HadPaintMessage
, HadNCPaintMessage
;
318 BOOL HasPaintMessage
, HasNCPaintMessage
;
320 DPRINT("IntInvalidateWindows start\n");
322 * If the nonclient is not to be redrawn, clip the region to the client
325 if (0 != (Flags
& RDW_INVALIDATE
) && 0 == (Flags
& RDW_FRAME
))
329 hRgnClient
= IntSysCreateRectRgnIndirect(&Wnd
->rcClient
);
330 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, hRgnClient
, RGN_AND
);
331 REGION_FreeRgnByHandle(hRgnClient
);
335 * Clip the given region with window rectangle (or region)
338 if (!Wnd
->hrgnClip
|| (Wnd
->style
& WS_MINIMIZE
))
342 hRgnWindow
= IntSysCreateRectRgnIndirect(&Wnd
->rcWindow
);
343 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, hRgnWindow
, RGN_AND
);
344 REGION_FreeRgnByHandle(hRgnWindow
);
348 NtGdiOffsetRgn( hRgn
,
351 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, Wnd
->hrgnClip
, RGN_AND
);
352 NtGdiOffsetRgn( hRgn
,
358 * Save current state of pending updates
361 HadPaintMessage
= Wnd
->hrgnUpdate
!= NULL
||
362 Wnd
->state
& WNDS_INTERNALPAINT
;
363 HadNCPaintMessage
= Wnd
->state
& WNDS_SENDNCPAINT
;
366 * Update the region and flags
369 if (Flags
& RDW_INVALIDATE
&& RgnType
!= NULLREGION
)
371 if (Wnd
->hrgnUpdate
== NULL
)
373 Wnd
->hrgnUpdate
= IntSysCreateRectRgn(0, 0, 0, 0);
374 IntGdiSetRegionOwner(Wnd
->hrgnUpdate
, GDI_OBJ_HMGR_PUBLIC
);
377 if (NtGdiCombineRgn(Wnd
->hrgnUpdate
, Wnd
->hrgnUpdate
,
378 hRgn
, RGN_OR
) == NULLREGION
)
380 IntGdiSetRegionOwner(Wnd
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
381 REGION_FreeRgnByHandle(Wnd
->hrgnUpdate
);
382 Wnd
->hrgnUpdate
= NULL
;
385 if (Flags
& RDW_FRAME
)
386 Wnd
->state
|= WNDS_SENDNCPAINT
;
387 if (Flags
& RDW_ERASE
)
388 Wnd
->state
|= WNDS_ERASEBACKGROUND
;
393 if (Flags
& RDW_VALIDATE
&& RgnType
!= NULLREGION
)
395 if (Wnd
->hrgnUpdate
!= NULL
)
397 if (NtGdiCombineRgn(Wnd
->hrgnUpdate
, Wnd
->hrgnUpdate
,
398 hRgn
, RGN_DIFF
) == NULLREGION
)
400 IntGdiSetRegionOwner(Wnd
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
401 REGION_FreeRgnByHandle(Wnd
->hrgnUpdate
);
402 Wnd
->hrgnUpdate
= NULL
;
406 if (Wnd
->hrgnUpdate
== NULL
)
407 Wnd
->state
&= ~WNDS_ERASEBACKGROUND
;
408 if (Flags
& RDW_NOFRAME
)
409 Wnd
->state
&= ~WNDS_SENDNCPAINT
;
410 if (Flags
& RDW_NOERASE
)
411 Wnd
->state
&= ~WNDS_ERASEBACKGROUND
;
414 if (Flags
& RDW_INTERNALPAINT
)
416 Wnd
->state
|= WNDS_INTERNALPAINT
;
419 if (Flags
& RDW_NOINTERNALPAINT
)
421 Wnd
->state
&= ~WNDS_INTERNALPAINT
;
425 * Process children if needed
428 if (!(Flags
& RDW_NOCHILDREN
) && !(Wnd
->style
& WS_MINIMIZE
) &&
429 ((Flags
& RDW_ALLCHILDREN
) || !(Wnd
->style
& WS_CLIPCHILDREN
)))
433 for (Child
= Wnd
->spwndChild
; Child
; Child
= Child
->spwndNext
)
435 if (Child
->style
& WS_VISIBLE
)
438 * Recursive call to update children hrgnUpdate
440 HRGN hRgnTemp
= IntSysCreateRectRgn(0, 0, 0, 0);
441 NtGdiCombineRgn(hRgnTemp
, hRgn
, 0, RGN_COPY
);
442 IntInvalidateWindows(Child
, hRgnTemp
, Flags
);
443 REGION_FreeRgnByHandle(hRgnTemp
);
450 * Fake post paint messages to window message queue if needed
453 HasPaintMessage
= Wnd
->hrgnUpdate
!= NULL
||
454 Wnd
->state
& WNDS_INTERNALPAINT
;
455 HasNCPaintMessage
= Wnd
->state
& WNDS_SENDNCPAINT
;
457 if (HasPaintMessage
!= HadPaintMessage
)
460 MsqDecPaintCountQueue(Wnd
->head
.pti
->MessageQueue
);
462 MsqIncPaintCountQueue(Wnd
->head
.pti
->MessageQueue
);
465 if (HasNCPaintMessage
!= HadNCPaintMessage
)
467 if (HadNCPaintMessage
)
468 MsqDecPaintCountQueue(Wnd
->head
.pti
->MessageQueue
);
470 MsqIncPaintCountQueue(Wnd
->head
.pti
->MessageQueue
);
472 DPRINT("IntInvalidateWindows exit\n");
476 * IntIsWindowDrawable
479 * Window is drawable when it is visible and all parents are not
484 IntIsWindowDrawable(PWND Wnd
)
488 for (WndObject
= Wnd
; WndObject
!= NULL
; WndObject
= WndObject
->spwndParent
)
490 if ( WndObject
->state2
& WNDS2_INDESTROY
||
491 WndObject
->state
& WNDS_DESTROYED
||
493 !(WndObject
->style
& WS_VISIBLE
) ||
494 ((WndObject
->style
& WS_MINIMIZE
) && (WndObject
!= Wnd
)))
506 * Internal version of NtUserRedrawWindow that takes WND as
513 const RECTL
* UpdateRect
,
518 DPRINT("co_UserRedrawWindow start\n");
522 * Validation of passed parameters.
525 if (!IntIsWindowDrawable(Window
))
527 return TRUE
; // Just do nothing!!!
532 * Transform the parameters UpdateRgn and UpdateRect into
533 * a region hRgn specified in screen coordinates.
536 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
)) // Both are OKAY!
538 if (UpdateRgn
!= NULL
)
540 hRgn
= IntSysCreateRectRgn(0, 0, 0, 0);
541 if (NtGdiCombineRgn(hRgn
, UpdateRgn
, NULL
, RGN_COPY
) == NULLREGION
)
543 REGION_FreeRgnByHandle(hRgn
);
547 NtGdiOffsetRgn(hRgn
, Window
->rcClient
.left
, Window
->rcClient
.top
);
549 else if (UpdateRect
!= NULL
)
551 if (!RECTL_bIsEmptyRect(UpdateRect
))
553 hRgn
= IntSysCreateRectRgnIndirect((RECTL
*)UpdateRect
);
554 NtGdiOffsetRgn(hRgn
, Window
->rcClient
.left
, Window
->rcClient
.top
);
557 else if ((Flags
& (RDW_INVALIDATE
| RDW_FRAME
)) == (RDW_INVALIDATE
| RDW_FRAME
) ||
558 (Flags
& (RDW_VALIDATE
| RDW_NOFRAME
)) == (RDW_VALIDATE
| RDW_NOFRAME
))
560 if (!RECTL_bIsEmptyRect(&Window
->rcWindow
))
561 hRgn
= IntSysCreateRectRgnIndirect(&Window
->rcWindow
);
565 if (!RECTL_bIsEmptyRect(&Window
->rcClient
))
566 hRgn
= IntSysCreateRectRgnIndirect(&Window
->rcClient
);
572 * Adjust the window update region depending on hRgn and flags.
575 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
| RDW_INTERNALPAINT
| RDW_NOINTERNALPAINT
) &&
578 IntInvalidateWindows(Window
, hRgn
, Flags
);
583 * Repaint and erase windows if needed.
586 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
588 co_IntPaintWindows(Window
, Flags
, FALSE
);
598 REGION_FreeRgnByHandle(hRgn
);
600 DPRINT("co_UserRedrawWindow exit\n");
606 IntIsWindowDirty(PWND Wnd
)
608 return (Wnd
->style
& WS_VISIBLE
) &&
609 ((Wnd
->hrgnUpdate
!= NULL
) ||
610 (Wnd
->state
& WNDS_INTERNALPAINT
) ||
611 (Wnd
->state
& WNDS_SENDNCPAINT
));
615 IntFindWindowToRepaint(PWND Window
, PTHREADINFO Thread
)
620 for (; Window
!= NULL
; Window
= Window
->spwndNext
)
622 if (IntWndBelongsToThread(Window
, Thread
) &&
623 IntIsWindowDirty(Window
))
625 /* Make sure all non-transparent siblings are already drawn. */
626 if (Window
->ExStyle
& WS_EX_TRANSPARENT
)
628 for (TempWindow
= Window
->spwndNext
; TempWindow
!= NULL
;
629 TempWindow
= TempWindow
->spwndNext
)
631 if (!(TempWindow
->ExStyle
& WS_EX_TRANSPARENT
) &&
632 IntWndBelongsToThread(TempWindow
, Thread
) &&
633 IntIsWindowDirty(TempWindow
))
635 return TempWindow
->head
.h
;
640 return Window
->head
.h
;
643 if (Window
->spwndChild
)
645 hChild
= IntFindWindowToRepaint(Window
->spwndChild
, Thread
);
663 PUSER_MESSAGE_QUEUE MessageQueue
= (PUSER_MESSAGE_QUEUE
)Thread
->MessageQueue
;
665 if (!MessageQueue
->PaintCount
)
668 if ((MsgFilterMin
!= 0 || MsgFilterMax
!= 0) &&
669 (MsgFilterMin
> WM_PAINT
|| MsgFilterMax
< WM_PAINT
))
672 Message
->hwnd
= IntFindWindowToRepaint(UserGetDesktopWindow(), PsGetCurrentThreadWin32Thread());
674 if (Message
->hwnd
== NULL
)
676 DPRINT1("PAINTING BUG: Thread marked as containing dirty windows, but no dirty windows found!\n");
677 /* Hack to stop spamming the debuglog ! */
678 MessageQueue
->PaintCount
= 0;
682 if (Window
!= NULL
&& Message
->hwnd
!= Window
->head
.h
)
685 Message
->message
= WM_PAINT
;
686 Message
->wParam
= Message
->lParam
= 0;
693 co_IntFixCaret(PWND Window
, RECTL
*lprc
, UINT flags
)
696 PTHRDCARETINFO CaretInfo
;
700 ASSERT_REFS_CO(Window
);
702 Desktop
= ((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->rpdesk
;
703 CaretInfo
= ((PUSER_MESSAGE_QUEUE
)Desktop
->ActiveMessageQueue
)->CaretInfo
;
704 hWndCaret
= CaretInfo
->hWnd
;
706 WndCaret
= UserGetWindowObject(hWndCaret
);
708 //fix: check for WndCaret can be null
709 if (WndCaret
== Window
||
710 ((flags
& SW_SCROLLCHILDREN
) && IntIsChildWindow(Window
, WndCaret
)))
712 POINT pt
, FromOffset
, ToOffset
;
715 pt
.x
= CaretInfo
->Pos
.x
;
716 pt
.y
= CaretInfo
->Pos
.y
;
717 IntGetClientOrigin(WndCaret
, &FromOffset
);
718 IntGetClientOrigin(Window
, &ToOffset
);
721 rcCaret
.right
= pt
.x
+ CaretInfo
->Size
.cx
;
722 rcCaret
.bottom
= pt
.y
+ CaretInfo
->Size
.cy
;
723 if (RECTL_bIntersectRect(lprc
, lprc
, &rcCaret
))
743 INT cx
, cy
, xSrc
, ySrc
;
745 if ( nFlags
& PW_CLIENTONLY
)
747 cx
= pwnd
->rcClient
.right
- pwnd
->rcClient
.left
;
748 cy
= pwnd
->rcClient
.bottom
- pwnd
->rcClient
.top
;
749 xSrc
= pwnd
->rcClient
.left
- pwnd
->rcWindow
.left
;
750 ySrc
= pwnd
->rcClient
.top
- pwnd
->rcWindow
.top
;
754 cx
= pwnd
->rcWindow
.right
- pwnd
->rcWindow
.left
;
755 cy
= pwnd
->rcWindow
.bottom
- pwnd
->rcWindow
.top
;
760 // TODO: Setup Redirection for Print.
763 /* Update the window just incase. */
764 co_IntPaintWindows( pwnd
, RDW_ERASENOW
|RDW_UPDATENOW
, FALSE
);
766 hdcSrc
= UserGetDCEx( pwnd
, NULL
, DCX_CACHE
|DCX_WINDOW
);
767 /* Print window to printer context. */
780 UserReleaseDC( pwnd
, hdcSrc
, FALSE
);
782 // TODO: Release Redirection from Print.
787 /* PUBLIC FUNCTIONS ***********************************************************/
797 NtUserBeginPaint(HWND hWnd
, PAINTSTRUCT
* UnsafePs
)
803 USER_REFERENCE_ENTRY Ref
;
805 DPRINT("Enter NtUserBeginPaint\n");
806 UserEnterExclusive();
808 if (!(Window
= UserGetWindowObject(hWnd
)))
813 UserRefObjectCo(Window
, &Ref
);
815 co_UserHideCaret(Window
);
817 if (Window
->state
& WNDS_SENDNCPAINT
)
821 hRgn
= IntGetNCUpdateRgn(Window
, FALSE
);
822 Window
->state
&= ~WNDS_SENDNCPAINT
;
823 MsqDecPaintCountQueue(Window
->head
.pti
->MessageQueue
);
824 co_IntSendMessage(hWnd
, WM_NCPAINT
, (WPARAM
)hRgn
, 0);
825 if (hRgn
!= (HANDLE
)1 && hRgn
!= NULL
)
827 /* NOTE: The region can already by deleted! */
828 GDIOBJ_FreeObjByHandle(hRgn
, GDI_OBJECT_TYPE_REGION
| GDI_OBJECT_TYPE_SILENT
);
832 RtlZeroMemory(&Ps
, sizeof(PAINTSTRUCT
));
834 Ps
.hdc
= UserGetDCEx( Window
,
836 DCX_INTERSECTRGN
| DCX_USESTYLE
);
842 if (Window
->hrgnUpdate
!= NULL
)
844 MsqDecPaintCountQueue(Window
->head
.pti
->MessageQueue
);
845 GdiGetClipBox(Ps
.hdc
, &Ps
.rcPaint
);
846 IntGdiSetRegionOwner(Window
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
847 /* The region is part of the dc now and belongs to the process! */
848 Window
->hrgnUpdate
= NULL
;
852 if (Window
->state
& WNDS_INTERNALPAINT
)
853 MsqDecPaintCountQueue(Window
->head
.pti
->MessageQueue
);
855 IntGetClientRect(Window
, &Ps
.rcPaint
);
858 Window
->state
&= ~WNDS_INTERNALPAINT
;
860 if (Window
->state
& WNDS_ERASEBACKGROUND
)
862 Window
->state
&= ~WNDS_ERASEBACKGROUND
;
863 Ps
.fErase
= !co_IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)Ps
.hdc
, 0);
869 if (Window
->hrgnUpdate
)
871 if (!(Window
->style
& WS_CLIPCHILDREN
))
874 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
876 IntInvalidateWindows(Child
, Window
->hrgnUpdate
, RDW_FRAME
| RDW_ERASE
| RDW_INVALIDATE
| RDW_ALLCHILDREN
);
881 Status
= MmCopyToCaller(UnsafePs
, &Ps
, sizeof(PAINTSTRUCT
));
882 if (! NT_SUCCESS(Status
))
884 SetLastNtError(Status
);
891 if (Window
) UserDerefObjectCo(Window
);
893 DPRINT("Leave NtUserBeginPaint, ret=%i\n",_ret_
);
907 NtUserEndPaint(HWND hWnd
, CONST PAINTSTRUCT
* pUnsafePs
)
909 NTSTATUS Status
= STATUS_SUCCESS
;
911 DECLARE_RETURN(BOOL
);
912 USER_REFERENCE_ENTRY Ref
;
915 DPRINT("Enter NtUserEndPaint\n");
916 UserEnterExclusive();
918 if (!(Window
= UserGetWindowObject(hWnd
)))
925 ProbeForRead(pUnsafePs
, sizeof(*pUnsafePs
), 1);
926 hdc
= pUnsafePs
->hdc
;
928 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
930 Status
= _SEH2_GetExceptionCode();
933 if (!NT_SUCCESS(Status
))
938 UserReleaseDC(Window
, hdc
, TRUE
);
940 UserRefObjectCo(Window
, &Ref
);
941 co_UserShowCaret(Window
);
942 UserDerefObjectCo(Window
);
947 DPRINT("Leave NtUserEndPaint, ret=%i\n",_ret_
);
954 co_UserGetUpdateRgn(PWND Window
, HRGN hRgn
, BOOL bErase
)
959 ASSERT_REFS_CO(Window
);
961 if (Window
->hrgnUpdate
== NULL
)
963 RegionType
= (NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0) ? NULLREGION
: ERROR
);
967 Rect
= Window
->rcClient
;
968 IntIntersectWithParents(Window
, &Rect
);
969 NtGdiSetRectRgn(hRgn
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
);
970 RegionType
= NtGdiCombineRgn(hRgn
, hRgn
, Window
->hrgnUpdate
, RGN_AND
);
971 NtGdiOffsetRgn(hRgn
, -Window
->rcClient
.left
, -Window
->rcClient
.top
);
974 if (bErase
&& RegionType
!= NULLREGION
&& RegionType
!= ERROR
)
976 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
990 NtUserGetUpdateRgn(HWND hWnd
, HRGN hRgn
, BOOL bErase
)
995 USER_REFERENCE_ENTRY Ref
;
997 DPRINT("Enter NtUserGetUpdateRgn\n");
998 UserEnterExclusive();
1000 if (!(Window
= UserGetWindowObject(hWnd
)))
1005 UserRefObjectCo(Window
, &Ref
);
1006 ret
= co_UserGetUpdateRgn(Window
, hRgn
, bErase
);
1007 UserDerefObjectCo(Window
);
1012 DPRINT("Leave NtUserGetUpdateRgn, ret=%i\n",_ret_
);
1018 * NtUserGetUpdateRect
1025 NtUserGetUpdateRect(HWND hWnd
, LPRECT UnsafeRect
, BOOL bErase
)
1030 PROSRGNDATA RgnData
;
1032 DECLARE_RETURN(BOOL
);
1034 DPRINT("Enter NtUserGetUpdateRect\n");
1035 UserEnterExclusive();
1037 if (!(Window
= UserGetWindowObject(hWnd
)))
1042 if (Window
->hrgnUpdate
== NULL
)
1044 Rect
.left
= Rect
.top
= Rect
.right
= Rect
.bottom
= 0;
1048 /* Get the update region bounding box. */
1049 if (Window
->hrgnUpdate
== (HRGN
)1)
1051 Rect
= Window
->rcClient
;
1055 RgnData
= RGNOBJAPI_Lock(Window
->hrgnUpdate
, NULL
);
1056 ASSERT(RgnData
!= NULL
);
1057 RegionType
= REGION_GetRgnBox(RgnData
, &Rect
);
1058 RGNOBJAPI_Unlock(RgnData
);
1060 if (RegionType
!= ERROR
&& RegionType
!= NULLREGION
)
1061 RECTL_bIntersectRect(&Rect
, &Rect
, &Window
->rcClient
);
1064 if (IntIntersectWithParents(Window
, &Rect
))
1066 RECTL_vOffsetRect(&Rect
,
1067 -Window
->rcClient
.left
,
1068 -Window
->rcClient
.top
);
1071 Rect
.left
= Rect
.top
= Rect
.right
= Rect
.bottom
= 0;
1075 if (bErase
&& !RECTL_bIsEmptyRect(&Rect
))
1077 USER_REFERENCE_ENTRY Ref
;
1078 UserRefObjectCo(Window
, &Ref
);
1079 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
1080 UserDerefObjectCo(Window
);
1083 if (UnsafeRect
!= NULL
)
1085 Status
= MmCopyToCaller(UnsafeRect
, &Rect
, sizeof(RECTL
));
1086 if (!NT_SUCCESS(Status
))
1088 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1093 RETURN(!RECTL_bIsEmptyRect(&Rect
));
1096 DPRINT("Leave NtUserGetUpdateRect, ret=%i\n",_ret_
);
1102 * NtUserRedrawWindow
1111 CONST RECT
*lprcUpdate
,
1115 RECTL SafeUpdateRect
;
1118 USER_REFERENCE_ENTRY Ref
;
1119 NTSTATUS Status
= STATUS_SUCCESS
;
1120 DECLARE_RETURN(BOOL
);
1122 DPRINT("Enter NtUserRedrawWindow\n");
1123 UserEnterExclusive();
1125 if (!(Wnd
= UserGetWindowObject(hWnd
? hWnd
: IntGetDesktopWindow())))
1134 ProbeForRead(lprcUpdate
, sizeof(RECTL
), 1);
1135 RtlCopyMemory(&SafeUpdateRect
, lprcUpdate
, sizeof(RECTL
));
1137 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1139 Status
= _SEH2_GetExceptionCode();
1142 if (!NT_SUCCESS(Status
))
1144 SetLastWin32Error(RtlNtStatusToDosError(Status
));
1149 if ( flags
& ~(RDW_ERASE
|RDW_FRAME
|RDW_INTERNALPAINT
|RDW_INVALIDATE
|
1150 RDW_NOERASE
|RDW_NOFRAME
|RDW_NOINTERNALPAINT
|RDW_VALIDATE
|
1151 RDW_ERASENOW
|RDW_UPDATENOW
|RDW_ALLCHILDREN
|RDW_NOCHILDREN
) )
1153 /* RedrawWindow fails only in case that flags are invalid */
1154 SetLastWin32Error(ERROR_INVALID_FLAGS
);
1158 UserRefObjectCo(Wnd
, &Ref
);
1160 Ret
= co_UserRedrawWindow( Wnd
,
1161 lprcUpdate
? &SafeUpdateRect
: NULL
,
1165 UserDerefObjectCo(Wnd
);
1170 DPRINT("Leave NtUserRedrawWindow, ret=%i\n",_ret_
);
1181 const RECTL
*prcScroll
,
1182 const RECTL
*prcClip
,
1187 RECTL rcScroll
, rcClip
, rcSrc
, rcDst
;
1190 GdiGetClipBox(hDC
, &rcClip
);
1194 RECTL_bIntersectRect(&rcClip
, &rcClip
, prcClip
);
1199 rcScroll
= *prcScroll
;
1200 RECTL_bIntersectRect(&rcSrc
, &rcClip
, prcScroll
);
1208 RECTL_vOffsetRect(&rcDst
, dx
, dy
);
1209 RECTL_bIntersectRect(&rcDst
, &rcDst
, &rcClip
);
1211 if (!NtGdiBitBlt( hDC
,
1214 rcDst
.right
- rcDst
.left
,
1215 rcDst
.bottom
- rcDst
.top
,
1226 /* Calculate the region that was invalidated by moving or
1227 could not be copied, because it was not visible */
1228 if (hrgnUpdate
|| prcUpdate
)
1230 HRGN hrgnOwn
, hrgnVisible
, hrgnTmp
;
1232 pDC
= DC_LockDc(hDC
);
1237 hrgnVisible
= ((PROSRGNDATA
)pDC
->prgnVis
)->BaseObject
.hHmgr
; // pDC->prgnRao?
1239 /* Begin with the shifted and then clipped scroll rect */
1241 RECTL_vOffsetRect(&rcDst
, dx
, dy
);
1242 RECTL_bIntersectRect(&rcDst
, &rcDst
, &rcClip
);
1245 hrgnOwn
= hrgnUpdate
;
1246 if (!NtGdiSetRectRgn(hrgnOwn
, rcDst
.left
, rcDst
.top
, rcDst
.right
, rcDst
.bottom
))
1253 hrgnOwn
= IntSysCreateRectRgnIndirect(&rcDst
);
1256 /* Add the source rect */
1257 hrgnTmp
= IntSysCreateRectRgnIndirect(&rcSrc
);
1258 NtGdiCombineRgn(hrgnOwn
, hrgnOwn
, hrgnTmp
, RGN_OR
);
1260 /* Substract the part of the dest that was visible in source */
1261 NtGdiCombineRgn(hrgnTmp
, hrgnTmp
, hrgnVisible
, RGN_AND
);
1262 NtGdiOffsetRgn(hrgnTmp
, dx
, dy
);
1263 Result
= NtGdiCombineRgn(hrgnOwn
, hrgnOwn
, hrgnTmp
, RGN_DIFF
);
1265 /* DO NOT Unlock DC while messing with prgnVis! */
1268 REGION_FreeRgnByHandle(hrgnTmp
);
1272 IntGdiGetRgnBox(hrgnOwn
, prcUpdate
);
1277 REGION_FreeRgnByHandle(hrgnOwn
);
1281 Result
= NULLREGION
;
1297 const RECT
*prcUnsafeScroll
,
1298 const RECT
*prcUnsafeClip
,
1300 LPRECT prcUnsafeUpdate
)
1302 DECLARE_RETURN(DWORD
);
1303 RECTL rcScroll
, rcClip
, rcUpdate
;
1304 NTSTATUS Status
= STATUS_SUCCESS
;
1307 DPRINT("Enter NtUserScrollDC\n");
1308 UserEnterExclusive();
1312 if (prcUnsafeScroll
)
1314 ProbeForRead(prcUnsafeScroll
, sizeof(*prcUnsafeScroll
), 1);
1315 rcScroll
= *prcUnsafeScroll
;
1319 ProbeForRead(prcUnsafeClip
, sizeof(*prcUnsafeClip
), 1);
1320 rcClip
= *prcUnsafeClip
;
1322 if (prcUnsafeUpdate
)
1324 ProbeForWrite(prcUnsafeUpdate
, sizeof(*prcUnsafeUpdate
), 1);
1327 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1329 Status
= _SEH2_GetExceptionCode();
1332 if (!NT_SUCCESS(Status
))
1334 SetLastNtError(Status
);
1338 Result
= UserScrollDC( hDC
,
1341 prcUnsafeScroll
? &rcScroll
: 0,
1342 prcUnsafeClip
? &rcClip
: 0,
1344 prcUnsafeUpdate
? &rcUpdate
: NULL
);
1347 /* FIXME: Only if hRgnUpdate is invalid we should SetLastError(ERROR_INVALID_HANDLE) */
1351 if (prcUnsafeUpdate
)
1355 *prcUnsafeUpdate
= rcUpdate
;
1357 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1359 Status
= _SEH2_GetExceptionCode();
1362 if (!NT_SUCCESS(Status
))
1364 /* FIXME: SetLastError? */
1365 /* FIXME: correct? We have already scrolled! */
1373 DPRINT("Leave NtUserScrollDC, ret=%i\n",_ret_
);
1379 * NtUserScrollWindowEx
1386 NtUserScrollWindowEx(
1390 const RECT
*prcUnsafeScroll
,
1391 const RECT
*prcUnsafeClip
,
1393 LPRECT prcUnsafeUpdate
,
1396 RECTL rcScroll
, rcClip
, rcCaret
, rcUpdate
;
1398 PWND Window
= NULL
, CaretWnd
;
1400 HRGN hrgnOwn
= NULL
, hrgnTemp
;
1402 NTSTATUS Status
= STATUS_SUCCESS
;
1403 DECLARE_RETURN(DWORD
);
1404 USER_REFERENCE_ENTRY Ref
, CaretRef
;
1406 DPRINT("Enter NtUserScrollWindowEx\n");
1407 UserEnterExclusive();
1409 Window
= UserGetWindowObject(hWnd
);
1410 if (!Window
|| !IntIsWindowDrawable(Window
))
1412 Window
= NULL
; /* prevent deref at cleanup */
1415 UserRefObjectCo(Window
, &Ref
);
1417 IntGetClientRect(Window
, &rcClip
);
1421 if (prcUnsafeScroll
)
1423 ProbeForRead(prcUnsafeScroll
, sizeof(*prcUnsafeScroll
), 1);
1424 RECTL_bIntersectRect(&rcScroll
, &rcClip
, prcUnsafeScroll
);
1431 ProbeForRead(prcUnsafeClip
, sizeof(*prcUnsafeClip
), 1);
1432 RECTL_bIntersectRect(&rcClip
, &rcClip
, prcUnsafeClip
);
1435 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1437 Status
= _SEH2_GetExceptionCode();
1441 if (!NT_SUCCESS(Status
))
1443 SetLastNtError(Status
);
1447 if (rcClip
.right
<= rcClip
.left
|| rcClip
.bottom
<= rcClip
.top
||
1448 (dx
== 0 && dy
== 0))
1454 hrgnOwn
= hrgnUpdate
;
1456 hrgnOwn
= IntSysCreateRectRgn(0, 0, 0, 0);
1458 hDC
= UserGetDCEx(Window
, 0, DCX_CACHE
| DCX_USESTYLE
);
1461 /* FIXME: SetLastError? */
1466 hwndCaret
= co_IntFixCaret(Window
, &rcCaret
, flags
);
1468 Result
= UserScrollDC( hDC
,
1474 prcUnsafeUpdate
? &rcUpdate
: NULL
);
1476 UserReleaseDC(Window
, hDC
, FALSE
);
1479 * Take into account the fact that some damage may have occurred during
1483 hrgnTemp
= IntSysCreateRectRgn(0, 0, 0, 0);
1484 if (co_UserGetUpdateRgn(Window
, hrgnTemp
, FALSE
) != NULLREGION
)
1486 HRGN hrgnClip
= IntSysCreateRectRgnIndirect(&rcClip
);
1487 NtGdiOffsetRgn(hrgnTemp
, dx
, dy
);
1488 NtGdiCombineRgn(hrgnTemp
, hrgnTemp
, hrgnClip
, RGN_AND
);
1489 co_UserRedrawWindow(Window
, NULL
, hrgnTemp
, RDW_INVALIDATE
| RDW_ERASE
);
1490 REGION_FreeRgnByHandle(hrgnClip
);
1492 REGION_FreeRgnByHandle(hrgnTemp
);
1494 if (flags
& SW_SCROLLCHILDREN
)
1499 USER_REFERENCE_ENTRY WndRef
;
1502 IntGetClientOrigin(Window
, &ClientOrigin
);
1503 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
1505 rcChild
= Child
->rcWindow
;
1506 rcChild
.left
-= ClientOrigin
.x
;
1507 rcChild
.top
-= ClientOrigin
.y
;
1508 rcChild
.right
-= ClientOrigin
.x
;
1509 rcChild
.bottom
-= ClientOrigin
.y
;
1511 if (! prcUnsafeScroll
|| RECTL_bIntersectRect(&rcDummy
, &rcChild
, &rcScroll
))
1513 UserRefObjectCo(Child
, &WndRef
);
1514 co_WinPosSetWindowPos(Child
, 0, rcChild
.left
+ dx
, rcChild
.top
+ dy
, 0, 0,
1515 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
|
1517 UserDerefObjectCo(Child
);
1522 if (flags
& (SW_INVALIDATE
| SW_ERASE
))
1524 co_UserRedrawWindow(Window
, NULL
, hrgnOwn
, RDW_INVALIDATE
| RDW_ERASE
|
1525 ((flags
& SW_ERASE
) ? RDW_ERASENOW
: 0) |
1526 ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0));
1529 if ((CaretWnd
= UserGetWindowObject(hwndCaret
)))
1531 UserRefObjectCo(CaretWnd
, &CaretRef
);
1533 co_IntSetCaretPos(rcCaret
.left
+ dx
, rcCaret
.top
+ dy
);
1534 co_UserShowCaret(CaretWnd
);
1536 UserDerefObjectCo(CaretWnd
);
1539 if (prcUnsafeUpdate
)
1543 /* Probe here, to not fail on invalid pointer before scrolling */
1544 ProbeForWrite(prcUnsafeUpdate
, sizeof(*prcUnsafeUpdate
), 1);
1545 *prcUnsafeUpdate
= rcUpdate
;
1547 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1549 Status
= _SEH2_GetExceptionCode();
1553 if (!NT_SUCCESS(Status
))
1555 SetLastNtError(Status
);
1563 if (hrgnOwn
&& !hrgnUpdate
)
1565 REGION_FreeRgnByHandle(hrgnOwn
);
1569 UserDerefObjectCo(Window
);
1571 DPRINT("Leave NtUserScrollWindowEx, ret=%i\n",_ret_
);
1578 UserDrawSysMenuButton(
1585 PCURICON_OBJECT pIcon
;
1587 ASSERT(pWnd
&& lpRc
);
1589 /* Get the icon to draw. We don't care about WM_GETICON here. */
1591 hIcon
= pWnd
->pcls
->hIconSm
;
1595 DPRINT("Wnd class has no small icon.\n");
1596 hIcon
= pWnd
->pcls
->hIcon
;
1601 DPRINT("Wnd class hasn't any icon.\n");
1602 //FIXME: Draw "winlogo" icon.
1606 if(!(pIcon
= UserGetCurIconObject(hIcon
)))
1608 DPRINT1("UserGetCurIconObject() failed!\n");
1612 return UserDrawIconEx(hDc
, lpRc
->left
, lpRc
->top
, pIcon
,
1613 UserGetSystemMetrics(SM_CXSMICON
),
1614 UserGetSystemMetrics(SM_CYSMICON
),
1615 0, NULL
, DI_NORMAL
);
1619 UserDrawCaptionText(
1621 const PUNICODE_STRING Text
,
1625 HFONT hOldFont
= NULL
, hFont
= NULL
;
1626 COLORREF OldTextColor
;
1627 NONCLIENTMETRICSW nclm
;
1631 DPRINT("%s:", __FUNCTION__
);
1632 for(i
= 0; i
< Text
->Length
/sizeof(WCHAR
); i
++)
1633 DbgPrint("%C", Text
->Buffer
[i
]);
1634 DbgPrint(", %d\n", Text
->Length
/sizeof(WCHAR
));
1637 nclm
.cbSize
= sizeof(nclm
);
1638 if(!UserSystemParametersInfo(SPI_GETNONCLIENTMETRICS
,
1639 sizeof(NONCLIENTMETRICS
), &nclm
, 0))
1641 DPRINT1("%s: UserSystemParametersInfo() failed!\n", __FUNCTION__
);
1645 IntGdiSetBkMode(hDc
, TRANSPARENT
);
1647 if(uFlags
& DC_SMALLCAP
)
1648 Status
= TextIntCreateFontIndirect(&nclm
.lfSmCaptionFont
, &hFont
);
1649 else Status
= TextIntCreateFontIndirect(&nclm
.lfCaptionFont
, &hFont
);
1651 if(!NT_SUCCESS(Status
))
1653 DPRINT1("%s: TextIntCreateFontIndirect() failed! Status: 0x%x\n",
1654 __FUNCTION__
, Status
);
1658 hOldFont
= NtGdiSelectFont(hDc
, hFont
);
1661 DPRINT1("%s: SelectFont() failed!\n", __FUNCTION__
);
1662 GreDeleteObject(hFont
);
1666 if(uFlags
& DC_INBUTTON
)
1667 OldTextColor
= IntGdiSetTextColor(hDc
, IntGetSysColor(COLOR_BTNTEXT
));
1668 else OldTextColor
= IntGdiSetTextColor(hDc
, IntGetSysColor(uFlags
& DC_ACTIVE
1669 ? COLOR_CAPTIONTEXT
: COLOR_INACTIVECAPTIONTEXT
));
1671 //FIXME: If string doesn't fit to rc, truncate it and add ellipsis.
1673 GreExtTextOutW(hDc
, lpRc
->left
,
1674 lpRc
->top
, 0, NULL
, Text
->Buffer
,
1675 Text
->Length
/sizeof(WCHAR
), NULL
, 0);
1677 IntGdiSetTextColor(hDc
, OldTextColor
);
1678 NtGdiSelectFont(hDc
, hOldFont
);
1679 GreDeleteObject(hFont
);
1684 BOOL
UserDrawCaption(
1690 const PUNICODE_STRING str
,
1694 HBITMAP hMemBmp
= NULL
, hOldBmp
= NULL
;
1695 HBRUSH hOldBrush
= NULL
;
1698 UINT VCenter
= 0, Padding
= 0;
1700 LONG ButtonWidth
, IconWidth
;
1703 //ASSERT(pWnd != NULL);
1705 RECTL_vMakeWellOrdered(lpRc
);
1706 hMemBmp
= NtGdiCreateCompatibleBitmap(hDc
,
1707 lpRc
->right
- lpRc
->left
,
1708 lpRc
->bottom
- lpRc
->top
);
1712 DPRINT1("%s: NtGdiCreateCompatibleBitmap() failed!\n", __FUNCTION__
);
1716 hMemDc
= NtGdiCreateCompatibleDC(hDc
);
1719 DPRINT1("%s: NtGdiCreateCompatibleDC() failed!\n", __FUNCTION__
);
1723 hOldBmp
= NtGdiSelectBitmap(hMemDc
, hMemBmp
);
1726 DPRINT1("%s: NtGdiSelectBitmap() failed!\n", __FUNCTION__
);
1730 Height
= UserGetSystemMetrics(SM_CYCAPTION
) - 1;
1731 VCenter
= (lpRc
->bottom
- lpRc
->top
) / 2;
1732 Padding
= VCenter
- (Height
/ 2);
1734 if ((!hIcon
) && (pWnd
!= NULL
))
1736 HasIcon
= (uFlags
& DC_ICON
) && (pWnd
->style
& WS_SYSMENU
)
1737 && !(uFlags
& DC_SMALLCAP
) && !(pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1738 && !(pWnd
->ExStyle
& WS_EX_TOOLWINDOW
);
1741 HasIcon
= (hIcon
!= 0);
1743 IconWidth
= UserGetSystemMetrics(SM_CXSIZE
) + Padding
;
1746 r
.right
= r
.left
+ (lpRc
->right
- lpRc
->left
);
1748 r
.bottom
= r
.top
+ (Height
/ 2);
1750 // Draw the caption background
1751 if(uFlags
& DC_INBUTTON
)
1753 hOldBrush
= NtGdiSelectBrush(hMemDc
,
1754 IntGetSysColorBrush(COLOR_3DFACE
));
1758 DPRINT1("%s: NtGdiSelectBrush() failed!\n", __FUNCTION__
);
1762 if(!NtGdiPatBlt(hMemDc
, 0, 0,
1763 lpRc
->right
- lpRc
->left
,
1764 lpRc
->bottom
- lpRc
->top
,
1767 DPRINT1("%s: NtGdiPatBlt() failed!\n", __FUNCTION__
);
1771 if(HasIcon
) r
.left
+=IconWidth
;
1775 r
.right
= (lpRc
->right
- lpRc
->left
);
1776 if(uFlags
& DC_SMALLCAP
)
1777 ButtonWidth
= UserGetSystemMetrics(SM_CXSMSIZE
) - 2;
1778 else ButtonWidth
= UserGetSystemMetrics(SM_CXSIZE
) - 2;
1780 hOldBrush
= NtGdiSelectBrush(hMemDc
,
1781 IntGetSysColorBrush(uFlags
& DC_ACTIVE
?
1782 COLOR_ACTIVECAPTION
: COLOR_INACTIVECAPTION
));
1786 DPRINT1("%s: NtGdiSelectBrush() failed!\n", __FUNCTION__
);
1790 if(HasIcon
&& (uFlags
& DC_GRADIENT
))
1792 NtGdiPatBlt(hMemDc
, 0, 0,
1794 lpRc
->bottom
- lpRc
->top
,
1800 NtGdiPatBlt(hMemDc
, 0, 0,
1801 lpRc
->right
- lpRc
->left
,
1802 lpRc
->bottom
- lpRc
->top
,
1806 if(uFlags
& DC_GRADIENT
)
1808 static GRADIENT_RECT gcap
= {0, 1};
1814 if(pWnd
->style
& WS_SYSMENU
)
1816 r
.right
-= 3 + ButtonWidth
;
1817 if(!(uFlags
& DC_SMALLCAP
))
1819 if(pWnd
->style
& (WS_MAXIMIZEBOX
| WS_MINIMIZEBOX
))
1820 r
.right
-= 2 + 2 * ButtonWidth
;
1825 //Draw buttons background
1826 if(!NtGdiSelectBrush(hMemDc
,
1827 IntGetSysColorBrush(uFlags
& DC_ACTIVE
?
1828 COLOR_GRADIENTACTIVECAPTION
:COLOR_GRADIENTINACTIVECAPTION
)))
1830 DPRINT1("%s: NtGdiSelectBrush() failed!\n", __FUNCTION__
);
1837 lpRc
->right
- lpRc
->left
- r
.right
,
1838 lpRc
->bottom
- lpRc
->top
,
1843 Colors
[0] = IntGetSysColor((uFlags
& DC_ACTIVE
) ?
1844 COLOR_ACTIVECAPTION
: COLOR_INACTIVECAPTION
);
1846 Colors
[1] = IntGetSysColor((uFlags
& DC_ACTIVE
) ?
1847 COLOR_GRADIENTACTIVECAPTION
: COLOR_GRADIENTINACTIVECAPTION
);
1851 vert
[0].Red
= (WORD
)Colors
[0]<<8;
1852 vert
[0].Green
= (WORD
)Colors
[0] & 0xFF00;
1853 vert
[0].Blue
= (WORD
)(Colors
[0]>>8) & 0xFF00;
1856 vert
[1].x
= r
.right
;
1857 vert
[1].y
= lpRc
->bottom
- lpRc
->top
;
1858 vert
[1].Red
= (WORD
)Colors
[1]<<8;
1859 vert
[1].Green
= (WORD
)Colors
[1] & 0xFF00;
1860 vert
[1].Blue
= (WORD
)(Colors
[1]>>8) & 0xFF00;
1863 if(!GreGradientFill(hMemDc
, vert
, 2, &gcap
,
1864 1, GRADIENT_FILL_RECT_H
))
1866 DPRINT1("%s: IntGdiGradientFill() failed!\n", __FUNCTION__
);
1869 } //if(uFlags & DC_GRADIENT)
1875 r
.left
-= --IconWidth
;
1876 /* FIXME: Draw the Icon when pWnd == NULL but hIcon is valid */
1878 UserDrawSysMenuButton(pWnd
, hMemDc
, &r
, FALSE
);
1880 r
.left
+= IconWidth
;
1887 r
.bottom
= r
.top
+ Height
;
1889 if((uFlags
& DC_TEXT
))
1891 if(!(uFlags
& DC_GRADIENT
))
1893 r
.right
= (lpRc
->right
- lpRc
->left
);
1895 if(uFlags
& DC_SMALLCAP
)
1896 ButtonWidth
= UserGetSystemMetrics(SM_CXSMSIZE
) - 2;
1897 else ButtonWidth
= UserGetSystemMetrics(SM_CXSIZE
) - 2;
1899 if ((pWnd
!= NULL
) && (pWnd
->style
& WS_SYSMENU
))
1901 r
.right
-= 3 + ButtonWidth
;
1902 if(! (uFlags
& DC_SMALLCAP
))
1904 if(pWnd
->style
& (WS_MAXIMIZEBOX
| WS_MINIMIZEBOX
))
1905 r
.right
-= 2 + 2 * ButtonWidth
;
1912 /* FIXME: hFont isn't handled */
1914 UserDrawCaptionText(hMemDc
, str
, &r
, uFlags
);
1915 else if (pWnd
!= NULL
)
1917 UNICODE_STRING ustr
;
1918 ustr
.Buffer
= pWnd
->strName
.Buffer
;
1919 ustr
.Length
= pWnd
->strName
.Length
;
1920 ustr
.MaximumLength
= pWnd
->strName
.MaximumLength
;
1921 UserDrawCaptionText(hMemDc
, &ustr
, &r
, uFlags
);
1925 if(!NtGdiBitBlt(hDc
, lpRc
->left
, lpRc
->top
,
1926 lpRc
->right
- lpRc
->left
, lpRc
->bottom
- lpRc
->top
,
1927 hMemDc
, 0, 0, SRCCOPY
, 0, 0))
1929 DPRINT1("%s: NtGdiBitBlt() failed!\n", __FUNCTION__
);
1936 if (hOldBrush
) NtGdiSelectBrush(hMemDc
, hOldBrush
);
1937 if (hOldBmp
) NtGdiSelectBitmap(hMemDc
, hOldBmp
);
1938 if (hMemBmp
) GreDeleteObject(hMemBmp
);
1939 if (hMemDc
) NtGdiDeleteObjectApp(hMemDc
);
1946 UserRealizePalette(HDC hdc
)
1951 Ret
= IntGdiRealizePalette(hdc
);
1952 if (Ret
) // There was a change.
1954 hWnd
= IntWindowFromDC(hdc
);
1955 if (hWnd
) // Send broadcast if dc is associated with a window.
1956 { // FYI: Thread locked in CallOneParam.
1957 co_IntSendMessage((HWND
)HWND_BROADCAST
, WM_PALETTECHANGED
, (WPARAM
)hWnd
, 0);
1965 NtUserDrawCaptionTemp(
1971 const PUNICODE_STRING str
,
1975 UNICODE_STRING SafeStr
= {0};
1976 NTSTATUS Status
= STATUS_SUCCESS
;
1980 UserEnterExclusive();
1984 if(!(pWnd
= UserGetWindowObject(hWnd
)))
1993 ProbeForRead(lpRc
, sizeof(RECTL
), sizeof(ULONG
));
1994 RtlCopyMemory(&SafeRect
, lpRc
, sizeof(RECTL
));
1997 SafeStr
= ProbeForReadUnicodeString(str
);
1998 if (SafeStr
.Length
!= 0)
2000 ProbeForRead( SafeStr
.Buffer
,
2006 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2008 Status
= _SEH2_GetExceptionCode();
2012 if (Status
!= STATUS_SUCCESS
)
2014 SetLastNtError(Status
);
2020 Ret
= UserDrawCaption(pWnd
, hDC
, &SafeRect
, hFont
, hIcon
, &SafeStr
, uFlags
);
2022 Ret
= UserDrawCaption(pWnd
, hDC
, &SafeRect
, hFont
, hIcon
, NULL
, uFlags
);
2030 NtUserDrawCaption(HWND hWnd
,
2035 return NtUserDrawCaptionTemp(hWnd
, hDC
, lpRc
, 0, 0, NULL
, uFlags
);
2040 NtUserInvalidateRect(
2042 CONST RECT
*lpUnsafeRect
,
2045 return NtUserRedrawWindow(hWnd
, lpUnsafeRect
, NULL
, RDW_INVALIDATE
| (bErase
? RDW_ERASE
: 0));
2050 NtUserInvalidateRgn(
2055 return NtUserRedrawWindow(hWnd
, NULL
, hRgn
, RDW_INVALIDATE
| (bErase
? RDW_ERASE
: 0));
2068 UserEnterExclusive();
2072 Window
= UserGetWindowObject(hwnd
);
2073 // TODO: Add Desktop and MessageBox check via FNID's.
2076 /* Validate flags and check it as a mask for 0 or 1. */
2077 if ( (nFlags
& PW_CLIENTONLY
) == nFlags
)
2078 Ret
= IntPrintWindow( Window
, hdcBlt
, nFlags
);
2080 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2088 /* ValidateRect gets redirected to NtUserValidateRect:
2089 http://blog.csdn.net/ntdll/archive/2005/10/19/509299.aspx */
2098 return NtUserRedrawWindow(hWnd
, lpRect
, NULL
, RDW_VALIDATE
);
2100 return NtUserRedrawWindow(hWnd
, lpRect
, NULL
, RDW_INVALIDATE
|RDW_ERASE
|RDW_ERASENOW
|RDW_ALLCHILDREN
);