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
)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 if (!Thread
->cPaintsReady
)
666 if ((MsgFilterMin
!= 0 || MsgFilterMax
!= 0) &&
667 (MsgFilterMin
> WM_PAINT
|| MsgFilterMax
< WM_PAINT
))
670 Message
->hwnd
= IntFindWindowToRepaint(UserGetDesktopWindow(), PsGetCurrentThreadWin32Thread());
672 if (Message
->hwnd
== NULL
)
674 DPRINT1("PAINTING BUG: Thread marked as containing dirty windows, but no dirty windows found! Counts %d\n",Thread
->cPaintsReady
);
675 /* Hack to stop spamming the debuglog ! */
676 Thread
->cPaintsReady
= 0;
680 if (Window
!= NULL
&& Message
->hwnd
!= Window
->head
.h
)
683 Message
->message
= WM_PAINT
;
684 Message
->wParam
= Message
->lParam
= 0;
691 co_IntFixCaret(PWND Window
, RECTL
*lprc
, UINT flags
)
694 PTHRDCARETINFO CaretInfo
;
698 ASSERT_REFS_CO(Window
);
700 Desktop
= ((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->rpdesk
;
701 CaretInfo
= ((PUSER_MESSAGE_QUEUE
)Desktop
->ActiveMessageQueue
)->CaretInfo
;
702 hWndCaret
= CaretInfo
->hWnd
;
704 WndCaret
= UserGetWindowObject(hWndCaret
);
706 //fix: check for WndCaret can be null
707 if (WndCaret
== Window
||
708 ((flags
& SW_SCROLLCHILDREN
) && IntIsChildWindow(Window
, WndCaret
)))
710 POINT pt
, FromOffset
, ToOffset
;
713 pt
.x
= CaretInfo
->Pos
.x
;
714 pt
.y
= CaretInfo
->Pos
.y
;
715 IntGetClientOrigin(WndCaret
, &FromOffset
);
716 IntGetClientOrigin(Window
, &ToOffset
);
719 rcCaret
.right
= pt
.x
+ CaretInfo
->Size
.cx
;
720 rcCaret
.bottom
= pt
.y
+ CaretInfo
->Size
.cy
;
721 if (RECTL_bIntersectRect(lprc
, lprc
, &rcCaret
))
741 INT cx
, cy
, xSrc
, ySrc
;
743 if ( nFlags
& PW_CLIENTONLY
)
745 cx
= pwnd
->rcClient
.right
- pwnd
->rcClient
.left
;
746 cy
= pwnd
->rcClient
.bottom
- pwnd
->rcClient
.top
;
747 xSrc
= pwnd
->rcClient
.left
- pwnd
->rcWindow
.left
;
748 ySrc
= pwnd
->rcClient
.top
- pwnd
->rcWindow
.top
;
752 cx
= pwnd
->rcWindow
.right
- pwnd
->rcWindow
.left
;
753 cy
= pwnd
->rcWindow
.bottom
- pwnd
->rcWindow
.top
;
758 // TODO: Setup Redirection for Print.
761 /* Update the window just incase. */
762 co_IntPaintWindows( pwnd
, RDW_ERASENOW
|RDW_UPDATENOW
, FALSE
);
764 hdcSrc
= UserGetDCEx( pwnd
, NULL
, DCX_CACHE
|DCX_WINDOW
);
765 /* Print window to printer context. */
778 UserReleaseDC( pwnd
, hdcSrc
, FALSE
);
780 // TODO: Release Redirection from Print.
785 /* PUBLIC FUNCTIONS ***********************************************************/
795 NtUserBeginPaint(HWND hWnd
, PAINTSTRUCT
* UnsafePs
)
801 USER_REFERENCE_ENTRY Ref
;
803 DPRINT("Enter NtUserBeginPaint\n");
804 UserEnterExclusive();
806 if (!(Window
= UserGetWindowObject(hWnd
)))
811 UserRefObjectCo(Window
, &Ref
);
813 co_UserHideCaret(Window
);
815 if (Window
->state
& WNDS_SENDNCPAINT
)
819 hRgn
= IntGetNCUpdateRgn(Window
, FALSE
);
820 Window
->state
&= ~WNDS_SENDNCPAINT
;
821 MsqDecPaintCountQueue(Window
->head
.pti
->MessageQueue
);
822 co_IntSendMessage(hWnd
, WM_NCPAINT
, (WPARAM
)hRgn
, 0);
823 if (hRgn
!= (HANDLE
)1 && hRgn
!= NULL
)
825 /* NOTE: The region can already by deleted! */
826 GDIOBJ_FreeObjByHandle(hRgn
, GDI_OBJECT_TYPE_REGION
| GDI_OBJECT_TYPE_SILENT
);
830 RtlZeroMemory(&Ps
, sizeof(PAINTSTRUCT
));
832 Ps
.hdc
= UserGetDCEx( Window
,
834 DCX_INTERSECTRGN
| DCX_USESTYLE
);
840 if (Window
->hrgnUpdate
!= NULL
)
842 MsqDecPaintCountQueue(Window
->head
.pti
->MessageQueue
);
843 GdiGetClipBox(Ps
.hdc
, &Ps
.rcPaint
);
844 IntGdiSetRegionOwner(Window
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
845 /* The region is part of the dc now and belongs to the process! */
846 Window
->hrgnUpdate
= NULL
;
850 if (Window
->state
& WNDS_INTERNALPAINT
)
851 MsqDecPaintCountQueue(Window
->head
.pti
->MessageQueue
);
853 IntGetClientRect(Window
, &Ps
.rcPaint
);
856 Window
->state
&= ~WNDS_INTERNALPAINT
;
858 if (Window
->state
& WNDS_ERASEBACKGROUND
)
860 Window
->state
&= ~WNDS_ERASEBACKGROUND
;
861 Ps
.fErase
= !co_IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)Ps
.hdc
, 0);
867 if (Window
->hrgnUpdate
)
869 if (!(Window
->style
& WS_CLIPCHILDREN
))
872 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
874 IntInvalidateWindows(Child
, Window
->hrgnUpdate
, RDW_FRAME
| RDW_ERASE
| RDW_INVALIDATE
| RDW_ALLCHILDREN
);
879 Status
= MmCopyToCaller(UnsafePs
, &Ps
, sizeof(PAINTSTRUCT
));
880 if (! NT_SUCCESS(Status
))
882 SetLastNtError(Status
);
889 if (Window
) UserDerefObjectCo(Window
);
891 DPRINT("Leave NtUserBeginPaint, ret=%i\n",_ret_
);
905 NtUserEndPaint(HWND hWnd
, CONST PAINTSTRUCT
* pUnsafePs
)
907 NTSTATUS Status
= STATUS_SUCCESS
;
909 DECLARE_RETURN(BOOL
);
910 USER_REFERENCE_ENTRY Ref
;
913 DPRINT("Enter NtUserEndPaint\n");
914 UserEnterExclusive();
916 if (!(Window
= UserGetWindowObject(hWnd
)))
923 ProbeForRead(pUnsafePs
, sizeof(*pUnsafePs
), 1);
924 hdc
= pUnsafePs
->hdc
;
926 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
928 Status
= _SEH2_GetExceptionCode();
931 if (!NT_SUCCESS(Status
))
936 UserReleaseDC(Window
, hdc
, TRUE
);
938 UserRefObjectCo(Window
, &Ref
);
939 co_UserShowCaret(Window
);
940 UserDerefObjectCo(Window
);
945 DPRINT("Leave NtUserEndPaint, ret=%i\n",_ret_
);
952 co_UserGetUpdateRgn(PWND Window
, HRGN hRgn
, BOOL bErase
)
957 ASSERT_REFS_CO(Window
);
959 if (Window
->hrgnUpdate
== NULL
)
961 RegionType
= (NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0) ? NULLREGION
: ERROR
);
965 Rect
= Window
->rcClient
;
966 IntIntersectWithParents(Window
, &Rect
);
967 NtGdiSetRectRgn(hRgn
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
);
968 RegionType
= NtGdiCombineRgn(hRgn
, hRgn
, Window
->hrgnUpdate
, RGN_AND
);
969 NtGdiOffsetRgn(hRgn
, -Window
->rcClient
.left
, -Window
->rcClient
.top
);
972 if (bErase
&& RegionType
!= NULLREGION
&& RegionType
!= ERROR
)
974 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
988 NtUserGetUpdateRgn(HWND hWnd
, HRGN hRgn
, BOOL bErase
)
993 USER_REFERENCE_ENTRY Ref
;
995 DPRINT("Enter NtUserGetUpdateRgn\n");
996 UserEnterExclusive();
998 if (!(Window
= UserGetWindowObject(hWnd
)))
1003 UserRefObjectCo(Window
, &Ref
);
1004 ret
= co_UserGetUpdateRgn(Window
, hRgn
, bErase
);
1005 UserDerefObjectCo(Window
);
1010 DPRINT("Leave NtUserGetUpdateRgn, ret=%i\n",_ret_
);
1016 * NtUserGetUpdateRect
1023 NtUserGetUpdateRect(HWND hWnd
, LPRECT UnsafeRect
, BOOL bErase
)
1028 PROSRGNDATA RgnData
;
1030 DECLARE_RETURN(BOOL
);
1032 DPRINT("Enter NtUserGetUpdateRect\n");
1033 UserEnterExclusive();
1035 if (!(Window
= UserGetWindowObject(hWnd
)))
1040 if (Window
->hrgnUpdate
== NULL
)
1042 Rect
.left
= Rect
.top
= Rect
.right
= Rect
.bottom
= 0;
1046 /* Get the update region bounding box. */
1047 if (Window
->hrgnUpdate
== (HRGN
)1)
1049 Rect
= Window
->rcClient
;
1053 RgnData
= RGNOBJAPI_Lock(Window
->hrgnUpdate
, NULL
);
1054 ASSERT(RgnData
!= NULL
);
1055 RegionType
= REGION_GetRgnBox(RgnData
, &Rect
);
1056 RGNOBJAPI_Unlock(RgnData
);
1058 if (RegionType
!= ERROR
&& RegionType
!= NULLREGION
)
1059 RECTL_bIntersectRect(&Rect
, &Rect
, &Window
->rcClient
);
1062 if (IntIntersectWithParents(Window
, &Rect
))
1064 RECTL_vOffsetRect(&Rect
,
1065 -Window
->rcClient
.left
,
1066 -Window
->rcClient
.top
);
1069 Rect
.left
= Rect
.top
= Rect
.right
= Rect
.bottom
= 0;
1073 if (bErase
&& !RECTL_bIsEmptyRect(&Rect
))
1075 USER_REFERENCE_ENTRY Ref
;
1076 UserRefObjectCo(Window
, &Ref
);
1077 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
1078 UserDerefObjectCo(Window
);
1081 if (UnsafeRect
!= NULL
)
1083 Status
= MmCopyToCaller(UnsafeRect
, &Rect
, sizeof(RECTL
));
1084 if (!NT_SUCCESS(Status
))
1086 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1091 RETURN(!RECTL_bIsEmptyRect(&Rect
));
1094 DPRINT("Leave NtUserGetUpdateRect, ret=%i\n",_ret_
);
1100 * NtUserRedrawWindow
1109 CONST RECT
*lprcUpdate
,
1113 RECTL SafeUpdateRect
;
1116 USER_REFERENCE_ENTRY Ref
;
1117 NTSTATUS Status
= STATUS_SUCCESS
;
1118 DECLARE_RETURN(BOOL
);
1120 DPRINT("Enter NtUserRedrawWindow\n");
1121 UserEnterExclusive();
1123 if (!(Wnd
= UserGetWindowObject(hWnd
? hWnd
: IntGetDesktopWindow())))
1132 ProbeForRead(lprcUpdate
, sizeof(RECTL
), 1);
1133 RtlCopyMemory(&SafeUpdateRect
, lprcUpdate
, sizeof(RECTL
));
1135 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1137 Status
= _SEH2_GetExceptionCode();
1140 if (!NT_SUCCESS(Status
))
1142 SetLastWin32Error(RtlNtStatusToDosError(Status
));
1147 if ( flags
& ~(RDW_ERASE
|RDW_FRAME
|RDW_INTERNALPAINT
|RDW_INVALIDATE
|
1148 RDW_NOERASE
|RDW_NOFRAME
|RDW_NOINTERNALPAINT
|RDW_VALIDATE
|
1149 RDW_ERASENOW
|RDW_UPDATENOW
|RDW_ALLCHILDREN
|RDW_NOCHILDREN
) )
1151 /* RedrawWindow fails only in case that flags are invalid */
1152 SetLastWin32Error(ERROR_INVALID_FLAGS
);
1156 UserRefObjectCo(Wnd
, &Ref
);
1158 Ret
= co_UserRedrawWindow( Wnd
,
1159 lprcUpdate
? &SafeUpdateRect
: NULL
,
1163 UserDerefObjectCo(Wnd
);
1168 DPRINT("Leave NtUserRedrawWindow, ret=%i\n",_ret_
);
1179 const RECTL
*prcScroll
,
1180 const RECTL
*prcClip
,
1185 RECTL rcScroll
, rcClip
, rcSrc
, rcDst
;
1188 GdiGetClipBox(hDC
, &rcClip
);
1192 RECTL_bIntersectRect(&rcClip
, &rcClip
, prcClip
);
1197 rcScroll
= *prcScroll
;
1198 RECTL_bIntersectRect(&rcSrc
, &rcClip
, prcScroll
);
1206 RECTL_vOffsetRect(&rcDst
, dx
, dy
);
1207 RECTL_bIntersectRect(&rcDst
, &rcDst
, &rcClip
);
1209 if (!NtGdiBitBlt( hDC
,
1212 rcDst
.right
- rcDst
.left
,
1213 rcDst
.bottom
- rcDst
.top
,
1224 /* Calculate the region that was invalidated by moving or
1225 could not be copied, because it was not visible */
1226 if (hrgnUpdate
|| prcUpdate
)
1228 HRGN hrgnOwn
, hrgnVisible
, hrgnTmp
;
1230 pDC
= DC_LockDc(hDC
);
1235 hrgnVisible
= ((PROSRGNDATA
)pDC
->prgnVis
)->BaseObject
.hHmgr
; // pDC->prgnRao?
1237 /* Begin with the shifted and then clipped scroll rect */
1239 RECTL_vOffsetRect(&rcDst
, dx
, dy
);
1240 RECTL_bIntersectRect(&rcDst
, &rcDst
, &rcClip
);
1243 hrgnOwn
= hrgnUpdate
;
1244 if (!NtGdiSetRectRgn(hrgnOwn
, rcDst
.left
, rcDst
.top
, rcDst
.right
, rcDst
.bottom
))
1251 hrgnOwn
= IntSysCreateRectRgnIndirect(&rcDst
);
1254 /* Add the source rect */
1255 hrgnTmp
= IntSysCreateRectRgnIndirect(&rcSrc
);
1256 NtGdiCombineRgn(hrgnOwn
, hrgnOwn
, hrgnTmp
, RGN_OR
);
1258 /* Substract the part of the dest that was visible in source */
1259 NtGdiCombineRgn(hrgnTmp
, hrgnTmp
, hrgnVisible
, RGN_AND
);
1260 NtGdiOffsetRgn(hrgnTmp
, dx
, dy
);
1261 Result
= NtGdiCombineRgn(hrgnOwn
, hrgnOwn
, hrgnTmp
, RGN_DIFF
);
1263 /* DO NOT Unlock DC while messing with prgnVis! */
1266 REGION_FreeRgnByHandle(hrgnTmp
);
1270 IntGdiGetRgnBox(hrgnOwn
, prcUpdate
);
1275 REGION_FreeRgnByHandle(hrgnOwn
);
1279 Result
= NULLREGION
;
1295 const RECT
*prcUnsafeScroll
,
1296 const RECT
*prcUnsafeClip
,
1298 LPRECT prcUnsafeUpdate
)
1300 DECLARE_RETURN(DWORD
);
1301 RECTL rcScroll
, rcClip
, rcUpdate
;
1302 NTSTATUS Status
= STATUS_SUCCESS
;
1305 DPRINT("Enter NtUserScrollDC\n");
1306 UserEnterExclusive();
1310 if (prcUnsafeScroll
)
1312 ProbeForRead(prcUnsafeScroll
, sizeof(*prcUnsafeScroll
), 1);
1313 rcScroll
= *prcUnsafeScroll
;
1317 ProbeForRead(prcUnsafeClip
, sizeof(*prcUnsafeClip
), 1);
1318 rcClip
= *prcUnsafeClip
;
1320 if (prcUnsafeUpdate
)
1322 ProbeForWrite(prcUnsafeUpdate
, sizeof(*prcUnsafeUpdate
), 1);
1325 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1327 Status
= _SEH2_GetExceptionCode();
1330 if (!NT_SUCCESS(Status
))
1332 SetLastNtError(Status
);
1336 Result
= UserScrollDC( hDC
,
1339 prcUnsafeScroll
? &rcScroll
: 0,
1340 prcUnsafeClip
? &rcClip
: 0,
1342 prcUnsafeUpdate
? &rcUpdate
: NULL
);
1345 /* FIXME: Only if hRgnUpdate is invalid we should SetLastError(ERROR_INVALID_HANDLE) */
1349 if (prcUnsafeUpdate
)
1353 *prcUnsafeUpdate
= rcUpdate
;
1355 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1357 Status
= _SEH2_GetExceptionCode();
1360 if (!NT_SUCCESS(Status
))
1362 /* FIXME: SetLastError? */
1363 /* FIXME: correct? We have already scrolled! */
1371 DPRINT("Leave NtUserScrollDC, ret=%i\n",_ret_
);
1377 * NtUserScrollWindowEx
1384 NtUserScrollWindowEx(
1388 const RECT
*prcUnsafeScroll
,
1389 const RECT
*prcUnsafeClip
,
1391 LPRECT prcUnsafeUpdate
,
1394 RECTL rcScroll
, rcClip
, rcCaret
, rcUpdate
;
1396 PWND Window
= NULL
, CaretWnd
;
1398 HRGN hrgnOwn
= NULL
, hrgnTemp
;
1400 NTSTATUS Status
= STATUS_SUCCESS
;
1401 DECLARE_RETURN(DWORD
);
1402 USER_REFERENCE_ENTRY Ref
, CaretRef
;
1404 DPRINT("Enter NtUserScrollWindowEx\n");
1405 UserEnterExclusive();
1407 Window
= UserGetWindowObject(hWnd
);
1408 if (!Window
|| !IntIsWindowDrawable(Window
))
1410 Window
= NULL
; /* prevent deref at cleanup */
1413 UserRefObjectCo(Window
, &Ref
);
1415 IntGetClientRect(Window
, &rcClip
);
1419 if (prcUnsafeScroll
)
1421 ProbeForRead(prcUnsafeScroll
, sizeof(*prcUnsafeScroll
), 1);
1422 RECTL_bIntersectRect(&rcScroll
, &rcClip
, prcUnsafeScroll
);
1429 ProbeForRead(prcUnsafeClip
, sizeof(*prcUnsafeClip
), 1);
1430 RECTL_bIntersectRect(&rcClip
, &rcClip
, prcUnsafeClip
);
1433 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1435 Status
= _SEH2_GetExceptionCode();
1439 if (!NT_SUCCESS(Status
))
1441 SetLastNtError(Status
);
1445 if (rcClip
.right
<= rcClip
.left
|| rcClip
.bottom
<= rcClip
.top
||
1446 (dx
== 0 && dy
== 0))
1452 hrgnOwn
= hrgnUpdate
;
1454 hrgnOwn
= IntSysCreateRectRgn(0, 0, 0, 0);
1456 hDC
= UserGetDCEx(Window
, 0, DCX_CACHE
| DCX_USESTYLE
);
1459 /* FIXME: SetLastError? */
1464 hwndCaret
= co_IntFixCaret(Window
, &rcCaret
, flags
);
1466 Result
= UserScrollDC( hDC
,
1472 prcUnsafeUpdate
? &rcUpdate
: NULL
);
1474 UserReleaseDC(Window
, hDC
, FALSE
);
1477 * Take into account the fact that some damage may have occurred during
1481 hrgnTemp
= IntSysCreateRectRgn(0, 0, 0, 0);
1482 if (co_UserGetUpdateRgn(Window
, hrgnTemp
, FALSE
) != NULLREGION
)
1484 HRGN hrgnClip
= IntSysCreateRectRgnIndirect(&rcClip
);
1485 NtGdiOffsetRgn(hrgnTemp
, dx
, dy
);
1486 NtGdiCombineRgn(hrgnTemp
, hrgnTemp
, hrgnClip
, RGN_AND
);
1487 co_UserRedrawWindow(Window
, NULL
, hrgnTemp
, RDW_INVALIDATE
| RDW_ERASE
);
1488 REGION_FreeRgnByHandle(hrgnClip
);
1490 REGION_FreeRgnByHandle(hrgnTemp
);
1492 if (flags
& SW_SCROLLCHILDREN
)
1497 USER_REFERENCE_ENTRY WndRef
;
1500 IntGetClientOrigin(Window
, &ClientOrigin
);
1501 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
1503 rcChild
= Child
->rcWindow
;
1504 rcChild
.left
-= ClientOrigin
.x
;
1505 rcChild
.top
-= ClientOrigin
.y
;
1506 rcChild
.right
-= ClientOrigin
.x
;
1507 rcChild
.bottom
-= ClientOrigin
.y
;
1509 if (! prcUnsafeScroll
|| RECTL_bIntersectRect(&rcDummy
, &rcChild
, &rcScroll
))
1511 UserRefObjectCo(Child
, &WndRef
);
1512 co_WinPosSetWindowPos(Child
, 0, rcChild
.left
+ dx
, rcChild
.top
+ dy
, 0, 0,
1513 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
|
1515 UserDerefObjectCo(Child
);
1520 if (flags
& (SW_INVALIDATE
| SW_ERASE
))
1522 co_UserRedrawWindow(Window
, NULL
, hrgnOwn
, RDW_INVALIDATE
| RDW_ERASE
|
1523 ((flags
& SW_ERASE
) ? RDW_ERASENOW
: 0) |
1524 ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0));
1527 if ((CaretWnd
= UserGetWindowObject(hwndCaret
)))
1529 UserRefObjectCo(CaretWnd
, &CaretRef
);
1531 co_IntSetCaretPos(rcCaret
.left
+ dx
, rcCaret
.top
+ dy
);
1532 co_UserShowCaret(CaretWnd
);
1534 UserDerefObjectCo(CaretWnd
);
1537 if (prcUnsafeUpdate
)
1541 /* Probe here, to not fail on invalid pointer before scrolling */
1542 ProbeForWrite(prcUnsafeUpdate
, sizeof(*prcUnsafeUpdate
), 1);
1543 *prcUnsafeUpdate
= rcUpdate
;
1545 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1547 Status
= _SEH2_GetExceptionCode();
1551 if (!NT_SUCCESS(Status
))
1553 SetLastNtError(Status
);
1561 if (hrgnOwn
&& !hrgnUpdate
)
1563 REGION_FreeRgnByHandle(hrgnOwn
);
1567 UserDerefObjectCo(Window
);
1569 DPRINT("Leave NtUserScrollWindowEx, ret=%i\n",_ret_
);
1576 UserDrawSysMenuButton(
1583 PCURICON_OBJECT pIcon
;
1585 ASSERT(pWnd
&& lpRc
);
1587 /* Get the icon to draw. We don't care about WM_GETICON here. */
1589 hIcon
= pWnd
->pcls
->hIconSm
;
1593 DPRINT("Wnd class has no small icon.\n");
1594 hIcon
= pWnd
->pcls
->hIcon
;
1599 DPRINT("Wnd class hasn't any icon.\n");
1600 //FIXME: Draw "winlogo" icon.
1604 if(!(pIcon
= UserGetCurIconObject(hIcon
)))
1606 DPRINT1("UserGetCurIconObject() failed!\n");
1610 return UserDrawIconEx(hDc
, lpRc
->left
, lpRc
->top
, pIcon
,
1611 UserGetSystemMetrics(SM_CXSMICON
),
1612 UserGetSystemMetrics(SM_CYSMICON
),
1613 0, NULL
, DI_NORMAL
);
1617 UserDrawCaptionText(
1619 const PUNICODE_STRING Text
,
1623 HFONT hOldFont
= NULL
, hFont
= NULL
;
1624 COLORREF OldTextColor
;
1625 NONCLIENTMETRICSW nclm
;
1629 DPRINT("%s:", __FUNCTION__
);
1630 for(i
= 0; i
< Text
->Length
/sizeof(WCHAR
); i
++)
1631 DbgPrint("%C", Text
->Buffer
[i
]);
1632 DbgPrint(", %d\n", Text
->Length
/sizeof(WCHAR
));
1635 nclm
.cbSize
= sizeof(nclm
);
1636 if(!UserSystemParametersInfo(SPI_GETNONCLIENTMETRICS
,
1637 sizeof(NONCLIENTMETRICS
), &nclm
, 0))
1639 DPRINT1("%s: UserSystemParametersInfo() failed!\n", __FUNCTION__
);
1643 IntGdiSetBkMode(hDc
, TRANSPARENT
);
1645 if(uFlags
& DC_SMALLCAP
)
1646 Status
= TextIntCreateFontIndirect(&nclm
.lfSmCaptionFont
, &hFont
);
1647 else Status
= TextIntCreateFontIndirect(&nclm
.lfCaptionFont
, &hFont
);
1649 if(!NT_SUCCESS(Status
))
1651 DPRINT1("%s: TextIntCreateFontIndirect() failed! Status: 0x%x\n",
1652 __FUNCTION__
, Status
);
1656 hOldFont
= NtGdiSelectFont(hDc
, hFont
);
1659 DPRINT1("%s: SelectFont() failed!\n", __FUNCTION__
);
1660 GreDeleteObject(hFont
);
1664 if(uFlags
& DC_INBUTTON
)
1665 OldTextColor
= IntGdiSetTextColor(hDc
, IntGetSysColor(COLOR_BTNTEXT
));
1666 else OldTextColor
= IntGdiSetTextColor(hDc
, IntGetSysColor(uFlags
& DC_ACTIVE
1667 ? COLOR_CAPTIONTEXT
: COLOR_INACTIVECAPTIONTEXT
));
1669 //FIXME: If string doesn't fit to rc, truncate it and add ellipsis.
1671 GreExtTextOutW(hDc
, lpRc
->left
,
1672 lpRc
->top
, 0, NULL
, Text
->Buffer
,
1673 Text
->Length
/sizeof(WCHAR
), NULL
, 0);
1675 IntGdiSetTextColor(hDc
, OldTextColor
);
1676 NtGdiSelectFont(hDc
, hOldFont
);
1677 GreDeleteObject(hFont
);
1682 BOOL
UserDrawCaption(
1688 const PUNICODE_STRING str
,
1692 HBITMAP hMemBmp
= NULL
, hOldBmp
= NULL
;
1693 HBRUSH hOldBrush
= NULL
;
1696 UINT VCenter
= 0, Padding
= 0;
1698 LONG ButtonWidth
, IconWidth
;
1701 //ASSERT(pWnd != NULL);
1703 RECTL_vMakeWellOrdered(lpRc
);
1704 hMemBmp
= NtGdiCreateCompatibleBitmap(hDc
,
1705 lpRc
->right
- lpRc
->left
,
1706 lpRc
->bottom
- lpRc
->top
);
1710 DPRINT1("%s: NtGdiCreateCompatibleBitmap() failed!\n", __FUNCTION__
);
1714 hMemDc
= NtGdiCreateCompatibleDC(hDc
);
1717 DPRINT1("%s: NtGdiCreateCompatibleDC() failed!\n", __FUNCTION__
);
1721 hOldBmp
= NtGdiSelectBitmap(hMemDc
, hMemBmp
);
1724 DPRINT1("%s: NtGdiSelectBitmap() failed!\n", __FUNCTION__
);
1728 Height
= UserGetSystemMetrics(SM_CYCAPTION
) - 1;
1729 VCenter
= (lpRc
->bottom
- lpRc
->top
) / 2;
1730 Padding
= VCenter
- (Height
/ 2);
1732 if ((!hIcon
) && (pWnd
!= NULL
))
1734 HasIcon
= (uFlags
& DC_ICON
) && (pWnd
->style
& WS_SYSMENU
)
1735 && !(uFlags
& DC_SMALLCAP
) && !(pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1736 && !(pWnd
->ExStyle
& WS_EX_TOOLWINDOW
);
1739 HasIcon
= (hIcon
!= 0);
1741 IconWidth
= UserGetSystemMetrics(SM_CXSIZE
) + Padding
;
1744 r
.right
= r
.left
+ (lpRc
->right
- lpRc
->left
);
1746 r
.bottom
= r
.top
+ (Height
/ 2);
1748 // Draw the caption background
1749 if(uFlags
& DC_INBUTTON
)
1751 hOldBrush
= NtGdiSelectBrush(hMemDc
,
1752 IntGetSysColorBrush(COLOR_3DFACE
));
1756 DPRINT1("%s: NtGdiSelectBrush() failed!\n", __FUNCTION__
);
1760 if(!NtGdiPatBlt(hMemDc
, 0, 0,
1761 lpRc
->right
- lpRc
->left
,
1762 lpRc
->bottom
- lpRc
->top
,
1765 DPRINT1("%s: NtGdiPatBlt() failed!\n", __FUNCTION__
);
1769 if(HasIcon
) r
.left
+=IconWidth
;
1773 r
.right
= (lpRc
->right
- lpRc
->left
);
1774 if(uFlags
& DC_SMALLCAP
)
1775 ButtonWidth
= UserGetSystemMetrics(SM_CXSMSIZE
) - 2;
1776 else ButtonWidth
= UserGetSystemMetrics(SM_CXSIZE
) - 2;
1778 hOldBrush
= NtGdiSelectBrush(hMemDc
,
1779 IntGetSysColorBrush(uFlags
& DC_ACTIVE
?
1780 COLOR_ACTIVECAPTION
: COLOR_INACTIVECAPTION
));
1784 DPRINT1("%s: NtGdiSelectBrush() failed!\n", __FUNCTION__
);
1788 if(HasIcon
&& (uFlags
& DC_GRADIENT
))
1790 NtGdiPatBlt(hMemDc
, 0, 0,
1792 lpRc
->bottom
- lpRc
->top
,
1798 NtGdiPatBlt(hMemDc
, 0, 0,
1799 lpRc
->right
- lpRc
->left
,
1800 lpRc
->bottom
- lpRc
->top
,
1804 if(uFlags
& DC_GRADIENT
)
1806 static GRADIENT_RECT gcap
= {0, 1};
1812 if(pWnd
->style
& WS_SYSMENU
)
1814 r
.right
-= 3 + ButtonWidth
;
1815 if(!(uFlags
& DC_SMALLCAP
))
1817 if(pWnd
->style
& (WS_MAXIMIZEBOX
| WS_MINIMIZEBOX
))
1818 r
.right
-= 2 + 2 * ButtonWidth
;
1823 //Draw buttons background
1824 if(!NtGdiSelectBrush(hMemDc
,
1825 IntGetSysColorBrush(uFlags
& DC_ACTIVE
?
1826 COLOR_GRADIENTACTIVECAPTION
:COLOR_GRADIENTINACTIVECAPTION
)))
1828 DPRINT1("%s: NtGdiSelectBrush() failed!\n", __FUNCTION__
);
1835 lpRc
->right
- lpRc
->left
- r
.right
,
1836 lpRc
->bottom
- lpRc
->top
,
1841 Colors
[0] = IntGetSysColor((uFlags
& DC_ACTIVE
) ?
1842 COLOR_ACTIVECAPTION
: COLOR_INACTIVECAPTION
);
1844 Colors
[1] = IntGetSysColor((uFlags
& DC_ACTIVE
) ?
1845 COLOR_GRADIENTACTIVECAPTION
: COLOR_GRADIENTINACTIVECAPTION
);
1849 vert
[0].Red
= (WORD
)Colors
[0]<<8;
1850 vert
[0].Green
= (WORD
)Colors
[0] & 0xFF00;
1851 vert
[0].Blue
= (WORD
)(Colors
[0]>>8) & 0xFF00;
1854 vert
[1].x
= r
.right
;
1855 vert
[1].y
= lpRc
->bottom
- lpRc
->top
;
1856 vert
[1].Red
= (WORD
)Colors
[1]<<8;
1857 vert
[1].Green
= (WORD
)Colors
[1] & 0xFF00;
1858 vert
[1].Blue
= (WORD
)(Colors
[1]>>8) & 0xFF00;
1861 if(!GreGradientFill(hMemDc
, vert
, 2, &gcap
,
1862 1, GRADIENT_FILL_RECT_H
))
1864 DPRINT1("%s: IntGdiGradientFill() failed!\n", __FUNCTION__
);
1867 } //if(uFlags & DC_GRADIENT)
1873 r
.left
-= --IconWidth
;
1874 /* FIXME: Draw the Icon when pWnd == NULL but hIcon is valid */
1876 UserDrawSysMenuButton(pWnd
, hMemDc
, &r
, FALSE
);
1878 r
.left
+= IconWidth
;
1885 r
.bottom
= r
.top
+ Height
;
1887 if((uFlags
& DC_TEXT
))
1889 if(!(uFlags
& DC_GRADIENT
))
1891 r
.right
= (lpRc
->right
- lpRc
->left
);
1893 if(uFlags
& DC_SMALLCAP
)
1894 ButtonWidth
= UserGetSystemMetrics(SM_CXSMSIZE
) - 2;
1895 else ButtonWidth
= UserGetSystemMetrics(SM_CXSIZE
) - 2;
1897 if ((pWnd
!= NULL
) && (pWnd
->style
& WS_SYSMENU
))
1899 r
.right
-= 3 + ButtonWidth
;
1900 if(! (uFlags
& DC_SMALLCAP
))
1902 if(pWnd
->style
& (WS_MAXIMIZEBOX
| WS_MINIMIZEBOX
))
1903 r
.right
-= 2 + 2 * ButtonWidth
;
1910 /* FIXME: hFont isn't handled */
1912 UserDrawCaptionText(hMemDc
, str
, &r
, uFlags
);
1913 else if (pWnd
!= NULL
)
1915 UNICODE_STRING ustr
;
1916 ustr
.Buffer
= pWnd
->strName
.Buffer
;
1917 ustr
.Length
= pWnd
->strName
.Length
;
1918 ustr
.MaximumLength
= pWnd
->strName
.MaximumLength
;
1919 UserDrawCaptionText(hMemDc
, &ustr
, &r
, uFlags
);
1923 if(!NtGdiBitBlt(hDc
, lpRc
->left
, lpRc
->top
,
1924 lpRc
->right
- lpRc
->left
, lpRc
->bottom
- lpRc
->top
,
1925 hMemDc
, 0, 0, SRCCOPY
, 0, 0))
1927 DPRINT1("%s: NtGdiBitBlt() failed!\n", __FUNCTION__
);
1934 if (hOldBrush
) NtGdiSelectBrush(hMemDc
, hOldBrush
);
1935 if (hOldBmp
) NtGdiSelectBitmap(hMemDc
, hOldBmp
);
1936 if (hMemBmp
) GreDeleteObject(hMemBmp
);
1937 if (hMemDc
) NtGdiDeleteObjectApp(hMemDc
);
1944 UserRealizePalette(HDC hdc
)
1949 Ret
= IntGdiRealizePalette(hdc
);
1950 if (Ret
) // There was a change.
1952 hWnd
= IntWindowFromDC(hdc
);
1953 if (hWnd
) // Send broadcast if dc is associated with a window.
1954 { // FYI: Thread locked in CallOneParam.
1955 co_IntSendMessage((HWND
)HWND_BROADCAST
, WM_PALETTECHANGED
, (WPARAM
)hWnd
, 0);
1963 NtUserDrawCaptionTemp(
1969 const PUNICODE_STRING str
,
1973 UNICODE_STRING SafeStr
= {0};
1974 NTSTATUS Status
= STATUS_SUCCESS
;
1978 UserEnterExclusive();
1982 if(!(pWnd
= UserGetWindowObject(hWnd
)))
1991 ProbeForRead(lpRc
, sizeof(RECTL
), sizeof(ULONG
));
1992 RtlCopyMemory(&SafeRect
, lpRc
, sizeof(RECTL
));
1995 SafeStr
= ProbeForReadUnicodeString(str
);
1996 if (SafeStr
.Length
!= 0)
1998 ProbeForRead( SafeStr
.Buffer
,
2004 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2006 Status
= _SEH2_GetExceptionCode();
2010 if (Status
!= STATUS_SUCCESS
)
2012 SetLastNtError(Status
);
2018 Ret
= UserDrawCaption(pWnd
, hDC
, &SafeRect
, hFont
, hIcon
, &SafeStr
, uFlags
);
2020 Ret
= UserDrawCaption(pWnd
, hDC
, &SafeRect
, hFont
, hIcon
, NULL
, uFlags
);
2028 NtUserDrawCaption(HWND hWnd
,
2033 return NtUserDrawCaptionTemp(hWnd
, hDC
, lpRc
, 0, 0, NULL
, uFlags
);
2038 NtUserInvalidateRect(
2040 CONST RECT
*lpUnsafeRect
,
2043 return NtUserRedrawWindow(hWnd
, lpUnsafeRect
, NULL
, RDW_INVALIDATE
| (bErase
? RDW_ERASE
: 0));
2048 NtUserInvalidateRgn(
2053 return NtUserRedrawWindow(hWnd
, NULL
, hRgn
, RDW_INVALIDATE
| (bErase
? RDW_ERASE
: 0));
2066 UserEnterExclusive();
2070 Window
= UserGetWindowObject(hwnd
);
2071 // TODO: Add Desktop and MessageBox check via FNID's.
2074 /* Validate flags and check it as a mask for 0 or 1. */
2075 if ( (nFlags
& PW_CLIENTONLY
) == nFlags
)
2076 Ret
= IntPrintWindow( Window
, hdcBlt
, nFlags
);
2078 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2086 /* ValidateRect gets redirected to NtUserValidateRect:
2087 http://blog.csdn.net/ntdll/archive/2005/10/19/509299.aspx */
2096 return NtUserRedrawWindow(hWnd
, lpRect
, NULL
, RDW_VALIDATE
);
2098 return NtUserRedrawWindow(hWnd
, lpRect
, NULL
, RDW_INVALIDATE
|RDW_ERASE
|RDW_ERASENOW
|RDW_ALLCHILDREN
);