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(PWINDOW_OBJECT Child
, RECTL
*WindowRect
)
41 PWINDOW_OBJECT ParentWindow
;
44 ParentWindow
= Child
->spwndParent
;
45 while (ParentWindow
!= NULL
)
47 ParentWnd
= ParentWindow
->Wnd
;
48 if (!(ParentWnd
->style
& WS_VISIBLE
) ||
49 (ParentWnd
->style
& WS_MINIMIZE
))
54 if (!RECTL_bIntersectRect(WindowRect
, WindowRect
, &ParentWnd
->rcClient
))
59 /* FIXME: Layered windows. */
61 ParentWindow
= ParentWindow
->spwndParent
;
68 IntValidateParent(PWINDOW_OBJECT Child
, HRGN hValidateRgn
, BOOL Recurse
)
70 PWINDOW_OBJECT ParentWindow
= Child
->spwndParent
;
75 ParentWnd
= ParentWindow
->Wnd
;
76 if (ParentWnd
->style
& WS_CLIPCHILDREN
)
79 if (ParentWindow
->hrgnUpdate
!= 0)
84 IntInvalidateWindows(ParentWindow
, hValidateRgn
,
85 RDW_VALIDATE
| RDW_NOCHILDREN
);
88 ParentWindow
= ParentWindow
->spwndParent
;
95 * @name IntCalcWindowRgn
97 * Get a window or client region.
101 IntCalcWindowRgn(PWINDOW_OBJECT Window
, BOOL Client
)
109 hRgnWindow
= IntSysCreateRectRgnIndirect(&Wnd
->rcClient
);
111 hRgnWindow
= IntSysCreateRectRgnIndirect(&Wnd
->rcWindow
);
113 if (Window
->hrgnClip
!= NULL
&& !(Wnd
->style
& WS_MINIMIZE
))
115 NtGdiOffsetRgn(hRgnWindow
,
118 RgnType
= NtGdiCombineRgn(hRgnWindow
, hRgnWindow
, Window
->hrgnClip
, RGN_AND
);
119 NtGdiOffsetRgn(hRgnWindow
,
128 * @name IntGetNCUpdateRgn
130 * Get non-client update region of a window and optionally validate it.
133 * Pointer to window to get the NC update region from.
135 * Set to TRUE to force validating the NC update region.
138 * Handle to NC update region. The caller is responsible for deleting
143 IntGetNCUpdateRgn(PWINDOW_OBJECT Window
, BOOL Validate
)
149 if (Window
->hrgnUpdate
!= NULL
&&
150 Window
->hrgnUpdate
!= (HRGN
)1)
152 hRgnNonClient
= IntCalcWindowRgn(Window
, FALSE
);
155 * If region creation fails it's safe to fallback to whole
158 if (hRgnNonClient
== NULL
)
163 hRgnWindow
= IntCalcWindowRgn(Window
, TRUE
);
164 if (hRgnWindow
== NULL
)
166 REGION_FreeRgnByHandle(hRgnNonClient
);
170 RgnType
= NtGdiCombineRgn(hRgnNonClient
, hRgnNonClient
,
171 hRgnWindow
, RGN_DIFF
);
172 if (RgnType
== ERROR
)
174 REGION_FreeRgnByHandle(hRgnWindow
);
175 REGION_FreeRgnByHandle(hRgnNonClient
);
178 else if (RgnType
== NULLREGION
)
180 REGION_FreeRgnByHandle(hRgnWindow
);
181 REGION_FreeRgnByHandle(hRgnNonClient
);
186 * Remove the nonclient region from the standard update region if
187 * we were asked for it.
192 if (NtGdiCombineRgn(Window
->hrgnUpdate
, Window
->hrgnUpdate
,
193 hRgnWindow
, RGN_AND
) == NULLREGION
)
195 IntGdiSetRegionOwner(Window
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
196 REGION_FreeRgnByHandle(Window
->hrgnUpdate
);
197 Window
->hrgnUpdate
= NULL
;
198 if (!(Window
->state
& WINDOWOBJECT_NEED_INTERNALPAINT
))
199 MsqDecPaintCountQueue(Window
->pti
->MessageQueue
);
203 REGION_FreeRgnByHandle(hRgnWindow
);
205 return hRgnNonClient
;
209 return Window
->hrgnUpdate
;
216 * Internal function used by IntRedrawWindow.
220 co_IntPaintWindows(PWINDOW_OBJECT Window
, ULONG Flags
, BOOL Recurse
)
223 HWND hWnd
= Window
->hSelf
;
229 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
231 if (Window
->hrgnUpdate
)
233 if (!IntValidateParent(Window
, Window
->hrgnUpdate
, Recurse
))
237 if (Flags
& RDW_UPDATENOW
)
239 if (Window
->hrgnUpdate
!= NULL
||
240 Window
->state
& WINDOWOBJECT_NEED_INTERNALPAINT
)
242 co_IntSendMessage(hWnd
, WM_PAINT
, 0, 0);
247 if (Window
->state
& WINDOWOBJECT_NEED_NCPAINT
)
249 TempRegion
= IntGetNCUpdateRgn(Window
, TRUE
);
250 Window
->state
&= ~WINDOWOBJECT_NEED_NCPAINT
;
251 MsqDecPaintCountQueue(Window
->pti
->MessageQueue
);
252 co_IntSendMessage(hWnd
, WM_NCPAINT
, (WPARAM
)TempRegion
, 0);
253 if ((HANDLE
) 1 != TempRegion
&& NULL
!= TempRegion
)
255 /* NOTE: The region can already be deleted! */
256 GDIOBJ_FreeObjByHandle(TempRegion
, GDI_OBJECT_TYPE_REGION
| GDI_OBJECT_TYPE_SILENT
);
260 if (Window
->state
& WINDOWOBJECT_NEED_ERASEBKGND
)
262 if (Window
->hrgnUpdate
)
264 hDC
= UserGetDCEx(Window
, Window
->hrgnUpdate
,
265 DCX_CACHE
| DCX_USESTYLE
|
266 DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
);
267 if (co_IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)hDC
, 0))
269 Window
->state
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
271 UserReleaseDC(Window
, hDC
, FALSE
);
278 * Check that the window is still valid at this point
280 if (!IntIsWindow(hWnd
))
286 * Paint child windows.
288 if (!(Flags
& RDW_NOCHILDREN
) && !(Wnd
->style
& WS_MINIMIZE
) &&
289 ((Flags
& RDW_ALLCHILDREN
) || !(Wnd
->style
& WS_CLIPCHILDREN
)))
293 if ((List
= IntWinListChildren(Window
)))
295 /* FIXME: Handle WS_EX_TRANSPARENT */
296 for (phWnd
= List
; *phWnd
; ++phWnd
)
298 Window
= UserGetWindowObject(*phWnd
);
300 if (Window
&& (Wnd
->style
& WS_VISIBLE
))
302 USER_REFERENCE_ENTRY Ref
;
303 UserRefObjectCo(Window
, &Ref
);
304 co_IntPaintWindows(Window
, Flags
, TRUE
);
305 UserDerefObjectCo(Window
);
314 * IntInvalidateWindows
316 * Internal function used by IntRedrawWindow.
320 IntInvalidateWindows(PWINDOW_OBJECT Window
, HRGN hRgn
, ULONG Flags
)
324 BOOL HadPaintMessage
, HadNCPaintMessage
;
325 BOOL HasPaintMessage
, HasNCPaintMessage
;
330 * If the nonclient is not to be redrawn, clip the region to the client
333 if (0 != (Flags
& RDW_INVALIDATE
) && 0 == (Flags
& RDW_FRAME
))
337 hRgnClient
= IntSysCreateRectRgnIndirect(&Window
->Wnd
->rcClient
);
338 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, hRgnClient
, RGN_AND
);
339 REGION_FreeRgnByHandle(hRgnClient
);
343 * Clip the given region with window rectangle (or region)
346 if (!Window
->hrgnClip
|| (Wnd
->style
& WS_MINIMIZE
))
350 hRgnWindow
= IntSysCreateRectRgnIndirect(&Window
->Wnd
->rcWindow
);
351 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, hRgnWindow
, RGN_AND
);
352 REGION_FreeRgnByHandle(hRgnWindow
);
359 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, Window
->hrgnClip
, RGN_AND
);
366 * Save current state of pending updates
369 HadPaintMessage
= Window
->hrgnUpdate
!= NULL
||
370 Window
->state
& WINDOWOBJECT_NEED_INTERNALPAINT
;
371 HadNCPaintMessage
= Window
->state
& WINDOWOBJECT_NEED_NCPAINT
;
374 * Update the region and flags
377 if (Flags
& RDW_INVALIDATE
&& RgnType
!= NULLREGION
)
379 if (Window
->hrgnUpdate
== NULL
)
381 Window
->hrgnUpdate
= IntSysCreateRectRgn(0, 0, 0, 0);
382 IntGdiSetRegionOwner(Window
->hrgnUpdate
, GDI_OBJ_HMGR_PUBLIC
);
385 if (NtGdiCombineRgn(Window
->hrgnUpdate
, Window
->hrgnUpdate
,
386 hRgn
, RGN_OR
) == NULLREGION
)
388 IntGdiSetRegionOwner(Window
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
389 REGION_FreeRgnByHandle(Window
->hrgnUpdate
);
390 Window
->hrgnUpdate
= NULL
;
393 if (Flags
& RDW_FRAME
)
394 Window
->state
|= WINDOWOBJECT_NEED_NCPAINT
;
395 if (Flags
& RDW_ERASE
)
396 Window
->state
|= WINDOWOBJECT_NEED_ERASEBKGND
;
401 if (Flags
& RDW_VALIDATE
&& RgnType
!= NULLREGION
)
403 if (Window
->hrgnUpdate
!= NULL
)
405 if (NtGdiCombineRgn(Window
->hrgnUpdate
, Window
->hrgnUpdate
,
406 hRgn
, RGN_DIFF
) == NULLREGION
)
408 IntGdiSetRegionOwner(Window
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
409 REGION_FreeRgnByHandle(Window
->hrgnUpdate
);
410 Window
->hrgnUpdate
= NULL
;
414 if (Window
->hrgnUpdate
== NULL
)
415 Window
->state
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
416 if (Flags
& RDW_NOFRAME
)
417 Window
->state
&= ~WINDOWOBJECT_NEED_NCPAINT
;
418 if (Flags
& RDW_NOERASE
)
419 Window
->state
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
422 if (Flags
& RDW_INTERNALPAINT
)
424 Window
->state
|= WINDOWOBJECT_NEED_INTERNALPAINT
;
427 if (Flags
& RDW_NOINTERNALPAINT
)
429 Window
->state
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
433 * Process children if needed
436 if (!(Flags
& RDW_NOCHILDREN
) && !(Wnd
->style
& WS_MINIMIZE
) &&
437 ((Flags
& RDW_ALLCHILDREN
) || !(Wnd
->style
& WS_CLIPCHILDREN
)))
439 PWINDOW_OBJECT Child
;
441 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
443 if (Child
->Wnd
->style
& WS_VISIBLE
)
446 * Recursive call to update children hrgnUpdate
448 HRGN hRgnTemp
= IntSysCreateRectRgn(0, 0, 0, 0);
449 NtGdiCombineRgn(hRgnTemp
, hRgn
, 0, RGN_COPY
);
450 IntInvalidateWindows(Child
, hRgnTemp
, Flags
);
451 REGION_FreeRgnByHandle(hRgnTemp
);
458 * Fake post paint messages to window message queue if needed
461 HasPaintMessage
= Window
->hrgnUpdate
!= NULL
||
462 Window
->state
& WINDOWOBJECT_NEED_INTERNALPAINT
;
463 HasNCPaintMessage
= Window
->state
& WINDOWOBJECT_NEED_NCPAINT
;
465 if (HasPaintMessage
!= HadPaintMessage
)
468 MsqDecPaintCountQueue(Window
->pti
->MessageQueue
);
470 MsqIncPaintCountQueue(Window
->pti
->MessageQueue
);
473 if (HasNCPaintMessage
!= HadNCPaintMessage
)
475 if (HadNCPaintMessage
)
476 MsqDecPaintCountQueue(Window
->pti
->MessageQueue
);
478 MsqIncPaintCountQueue(Window
->pti
->MessageQueue
);
484 * IntIsWindowDrawable
487 * Window is drawable when it is visible and all parents are not
492 IntIsWindowDrawable(PWINDOW_OBJECT Window
)
494 PWINDOW_OBJECT WndObject
;
497 for (WndObject
= Window
; WndObject
!= NULL
; WndObject
= WndObject
->spwndParent
)
499 Wnd
= WndObject
->Wnd
;
500 if (!(Wnd
->style
& WS_VISIBLE
) ||
501 ((Wnd
->style
& WS_MINIMIZE
) && (WndObject
!= Window
)))
513 * Internal version of NtUserRedrawWindow that takes WINDOW_OBJECT as
518 co_UserRedrawWindow(PWINDOW_OBJECT Window
, const RECTL
* UpdateRect
, HRGN UpdateRgn
,
525 * Validation of passed parameters.
528 if (!IntIsWindowDrawable(Window
) ||
529 (Flags
& (RDW_VALIDATE
| RDW_INVALIDATE
)) ==
530 (RDW_VALIDATE
| RDW_INVALIDATE
))
537 * Transform the parameters UpdateRgn and UpdateRect into
538 * a region hRgn specified in screen coordinates.
541 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
))
543 if (UpdateRgn
!= NULL
)
545 hRgn
= IntSysCreateRectRgn(0, 0, 0, 0);
546 if (NtGdiCombineRgn(hRgn
, UpdateRgn
, NULL
, RGN_COPY
) == NULLREGION
)
548 REGION_FreeRgnByHandle(hRgn
);
552 NtGdiOffsetRgn(hRgn
, Window
->Wnd
->rcClient
.left
, Window
->Wnd
->rcClient
.top
);
554 else if (UpdateRect
!= NULL
)
556 if (!RECTL_bIsEmptyRect(UpdateRect
))
558 hRgn
= IntSysCreateRectRgnIndirect((RECTL
*)UpdateRect
);
559 NtGdiOffsetRgn(hRgn
, Window
->Wnd
->rcClient
.left
, Window
->Wnd
->rcClient
.top
);
562 else if ((Flags
& (RDW_INVALIDATE
| RDW_FRAME
)) == (RDW_INVALIDATE
| RDW_FRAME
) ||
563 (Flags
& (RDW_VALIDATE
| RDW_NOFRAME
)) == (RDW_VALIDATE
| RDW_NOFRAME
))
565 if (!RECTL_bIsEmptyRect(&Window
->Wnd
->rcWindow
))
566 hRgn
= IntSysCreateRectRgnIndirect(&Window
->Wnd
->rcWindow
);
570 if (!RECTL_bIsEmptyRect(&Window
->Wnd
->rcClient
))
571 hRgn
= IntSysCreateRectRgnIndirect(&Window
->Wnd
->rcClient
);
577 * Adjust the window update region depending on hRgn and flags.
580 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
| RDW_INTERNALPAINT
| RDW_NOINTERNALPAINT
) &&
583 IntInvalidateWindows(Window
, hRgn
, Flags
);
588 * Repaint and erase windows if needed.
591 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
593 co_IntPaintWindows(Window
, Flags
, FALSE
);
603 REGION_FreeRgnByHandle(hRgn
);
610 IntIsWindowDirty(PWINDOW_OBJECT Window
)
612 PWND Wnd
= Window
->Wnd
;
613 return (Wnd
->style
& WS_VISIBLE
) &&
614 ((Window
->hrgnUpdate
!= NULL
) ||
615 (Window
->state
& WINDOWOBJECT_NEED_INTERNALPAINT
) ||
616 (Window
->state
& WINDOWOBJECT_NEED_NCPAINT
));
620 IntFindWindowToRepaint(PWINDOW_OBJECT Window
, PTHREADINFO Thread
)
623 PWINDOW_OBJECT TempWindow
;
626 for (; Window
!= NULL
; Window
= Window
->spwndNext
)
629 if (IntWndBelongsToThread(Window
, Thread
) &&
630 IntIsWindowDirty(Window
))
632 /* Make sure all non-transparent siblings are already drawn. */
633 if (Wnd
->ExStyle
& WS_EX_TRANSPARENT
)
635 for (TempWindow
= Window
->spwndNext
; TempWindow
!= NULL
;
636 TempWindow
= TempWindow
->spwndNext
)
638 TempWnd
= TempWindow
->Wnd
;
639 if (!(TempWnd
->ExStyle
& WS_EX_TRANSPARENT
) &&
640 IntWndBelongsToThread(TempWindow
, Thread
) &&
641 IntIsWindowDirty(TempWindow
))
643 return TempWindow
->hSelf
;
648 return Window
->hSelf
;
651 if (Window
->spwndChild
)
653 hChild
= IntFindWindowToRepaint(Window
->spwndChild
, Thread
);
663 IntGetPaintMessage(PWINDOW_OBJECT Window
, UINT MsgFilterMin
, UINT MsgFilterMax
,
664 PTHREADINFO Thread
, MSG
*Message
, BOOL Remove
)
666 PUSER_MESSAGE_QUEUE MessageQueue
= (PUSER_MESSAGE_QUEUE
)Thread
->MessageQueue
;
668 if (!MessageQueue
->PaintCount
)
671 if ((MsgFilterMin
!= 0 || MsgFilterMax
!= 0) &&
672 (MsgFilterMin
> WM_PAINT
|| MsgFilterMax
< WM_PAINT
))
675 Message
->hwnd
= IntFindWindowToRepaint(UserGetDesktopWindow(), PsGetCurrentThreadWin32Thread());
677 if (Message
->hwnd
== NULL
)
679 DPRINT1("PAINTING BUG: Thread marked as containing dirty windows, but no dirty windows found!\n");
680 /* Hack to stop spamming the debuglog ! */
681 MessageQueue
->PaintCount
= 0;
685 if (Window
!= NULL
&& Message
->hwnd
!= Window
->hSelf
)
688 Message
->message
= WM_PAINT
;
689 Message
->wParam
= Message
->lParam
= 0;
696 co_IntFixCaret(PWINDOW_OBJECT Window
, RECTL
*lprc
, UINT flags
)
699 PTHRDCARETINFO CaretInfo
;
701 PWINDOW_OBJECT WndCaret
;
703 ASSERT_REFS_CO(Window
);
705 Desktop
= ((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->rpdesk
;
706 CaretInfo
= ((PUSER_MESSAGE_QUEUE
)Desktop
->ActiveMessageQueue
)->CaretInfo
;
707 hWndCaret
= CaretInfo
->hWnd
;
709 WndCaret
= UserGetWindowObject(hWndCaret
);
711 //fix: check for WndCaret can be null
712 if (WndCaret
== Window
||
713 ((flags
& SW_SCROLLCHILDREN
) && IntIsChildWindow(Window
, WndCaret
)))
715 POINT pt
, FromOffset
, ToOffset
, Offset
;
718 pt
.x
= CaretInfo
->Pos
.x
;
719 pt
.y
= CaretInfo
->Pos
.y
;
720 IntGetClientOrigin(WndCaret
, &FromOffset
);
721 IntGetClientOrigin(Window
, &ToOffset
);
722 Offset
.x
= FromOffset
.x
- ToOffset
.x
;
723 Offset
.y
= FromOffset
.y
- ToOffset
.y
;
726 rcCaret
.right
= pt
.x
+ CaretInfo
->Size
.cx
;
727 rcCaret
.bottom
= pt
.y
+ CaretInfo
->Size
.cy
;
728 if (RECTL_bIntersectRect(lprc
, lprc
, &rcCaret
))
740 /* PUBLIC FUNCTIONS ***********************************************************/
750 NtUserBeginPaint(HWND hWnd
, PAINTSTRUCT
* UnsafePs
)
752 PWINDOW_OBJECT Window
= NULL
;
756 USER_REFERENCE_ENTRY Ref
;
759 DPRINT("Enter NtUserBeginPaint\n");
760 UserEnterExclusive();
762 if (!(Window
= UserGetWindowObject(hWnd
)))
767 UserRefObjectCo(Window
, &Ref
);
771 co_UserHideCaret(Window
);
773 if (Window
->state
& WINDOWOBJECT_NEED_NCPAINT
)
777 hRgn
= IntGetNCUpdateRgn(Window
, FALSE
);
778 Window
->state
&= ~WINDOWOBJECT_NEED_NCPAINT
;
779 MsqDecPaintCountQueue(Window
->pti
->MessageQueue
);
780 co_IntSendMessage(hWnd
, WM_NCPAINT
, (WPARAM
)hRgn
, 0);
781 if (hRgn
!= (HANDLE
)1 && hRgn
!= NULL
)
783 /* NOTE: The region can already by deleted! */
784 GDIOBJ_FreeObjByHandle(hRgn
, GDI_OBJECT_TYPE_REGION
| GDI_OBJECT_TYPE_SILENT
);
788 RtlZeroMemory(&Ps
, sizeof(PAINTSTRUCT
));
790 Ps
.hdc
= UserGetDCEx(Window
, Window
->hrgnUpdate
, DCX_INTERSECTRGN
| DCX_USESTYLE
);
796 if (Window
->hrgnUpdate
!= NULL
)
798 MsqDecPaintCountQueue(Window
->pti
->MessageQueue
);
799 GdiGetClipBox(Ps
.hdc
, &Ps
.rcPaint
);
800 IntGdiSetRegionOwner(Window
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
801 /* The region is part of the dc now and belongs to the process! */
802 Window
->hrgnUpdate
= NULL
;
806 if (Window
->state
& WINDOWOBJECT_NEED_INTERNALPAINT
)
807 MsqDecPaintCountQueue(Window
->pti
->MessageQueue
);
809 IntGetClientRect(Window
, &Ps
.rcPaint
);
812 Window
->state
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
814 if (Window
->state
& WINDOWOBJECT_NEED_ERASEBKGND
)
816 Window
->state
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
817 Ps
.fErase
= !co_IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)Ps
.hdc
, 0);
823 if (Window
->hrgnUpdate
)
825 if (!(Wnd
->style
& WS_CLIPCHILDREN
))
827 PWINDOW_OBJECT Child
;
828 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
830 IntInvalidateWindows(Child
, Window
->hrgnUpdate
, RDW_FRAME
| RDW_ERASE
| RDW_INVALIDATE
| RDW_ALLCHILDREN
);
835 Status
= MmCopyToCaller(UnsafePs
, &Ps
, sizeof(PAINTSTRUCT
));
836 if (! NT_SUCCESS(Status
))
838 SetLastNtError(Status
);
845 if (Window
) UserDerefObjectCo(Window
);
847 DPRINT("Leave NtUserBeginPaint, ret=%i\n",_ret_
);
861 NtUserEndPaint(HWND hWnd
, CONST PAINTSTRUCT
* pUnsafePs
)
863 NTSTATUS Status
= STATUS_SUCCESS
;
864 PWINDOW_OBJECT Window
;
865 DECLARE_RETURN(BOOL
);
866 USER_REFERENCE_ENTRY Ref
;
869 DPRINT("Enter NtUserEndPaint\n");
870 UserEnterExclusive();
872 if (!(Window
= UserGetWindowObject(hWnd
)))
879 ProbeForRead(pUnsafePs
, sizeof(*pUnsafePs
), 1);
880 hdc
= pUnsafePs
->hdc
;
882 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
884 Status
= _SEH2_GetExceptionCode();
887 if (!NT_SUCCESS(Status
))
892 UserReleaseDC(Window
, hdc
, TRUE
);
894 UserRefObjectCo(Window
, &Ref
);
895 co_UserShowCaret(Window
);
896 UserDerefObjectCo(Window
);
901 DPRINT("Leave NtUserEndPaint, ret=%i\n",_ret_
);
908 co_UserGetUpdateRgn(PWINDOW_OBJECT Window
, HRGN hRgn
, BOOL bErase
)
913 ASSERT_REFS_CO(Window
);
915 if (Window
->hrgnUpdate
== NULL
)
917 RegionType
= (NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0) ? NULLREGION
: ERROR
);
921 Rect
= Window
->Wnd
->rcClient
;
922 IntIntersectWithParents(Window
, &Rect
);
923 NtGdiSetRectRgn(hRgn
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
);
924 RegionType
= NtGdiCombineRgn(hRgn
, hRgn
, Window
->hrgnUpdate
, RGN_AND
);
925 NtGdiOffsetRgn(hRgn
, -Window
->Wnd
->rcClient
.left
, -Window
->Wnd
->rcClient
.top
);
928 if (bErase
&& RegionType
!= NULLREGION
&& RegionType
!= ERROR
)
930 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
944 NtUserGetUpdateRgn(HWND hWnd
, HRGN hRgn
, BOOL bErase
)
947 PWINDOW_OBJECT Window
;
949 USER_REFERENCE_ENTRY Ref
;
951 DPRINT("Enter NtUserGetUpdateRgn\n");
952 UserEnterExclusive();
954 if (!(Window
= UserGetWindowObject(hWnd
)))
959 UserRefObjectCo(Window
, &Ref
);
960 ret
= co_UserGetUpdateRgn(Window
, hRgn
, bErase
);
961 UserDerefObjectCo(Window
);
966 DPRINT("Leave NtUserGetUpdateRgn, ret=%i\n",_ret_
);
972 * NtUserGetUpdateRect
979 NtUserGetUpdateRect(HWND hWnd
, LPRECT UnsafeRect
, BOOL bErase
)
981 PWINDOW_OBJECT Window
;
986 DECLARE_RETURN(BOOL
);
988 DPRINT("Enter NtUserGetUpdateRect\n");
989 UserEnterExclusive();
991 if (!(Window
= UserGetWindowObject(hWnd
)))
996 if (Window
->hrgnUpdate
== NULL
)
998 Rect
.left
= Rect
.top
= Rect
.right
= Rect
.bottom
= 0;
1002 /* Get the update region bounding box. */
1003 if (Window
->hrgnUpdate
== (HRGN
)1)
1005 Rect
= Window
->Wnd
->rcClient
;
1009 RgnData
= RGNOBJAPI_Lock(Window
->hrgnUpdate
, NULL
);
1010 ASSERT(RgnData
!= NULL
);
1011 RegionType
= REGION_GetRgnBox(RgnData
, &Rect
);
1012 RGNOBJAPI_Unlock(RgnData
);
1014 if (RegionType
!= ERROR
&& RegionType
!= NULLREGION
)
1015 RECTL_bIntersectRect(&Rect
, &Rect
, &Window
->Wnd
->rcClient
);
1018 if (IntIntersectWithParents(Window
, &Rect
))
1020 RECTL_vOffsetRect(&Rect
,
1021 -Window
->Wnd
->rcClient
.left
,
1022 -Window
->Wnd
->rcClient
.top
);
1025 Rect
.left
= Rect
.top
= Rect
.right
= Rect
.bottom
= 0;
1029 if (bErase
&& !RECTL_bIsEmptyRect(&Rect
))
1031 USER_REFERENCE_ENTRY Ref
;
1032 UserRefObjectCo(Window
, &Ref
);
1033 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
1034 UserDerefObjectCo(Window
);
1037 if (UnsafeRect
!= NULL
)
1039 Status
= MmCopyToCaller(UnsafeRect
, &Rect
, sizeof(RECTL
));
1040 if (!NT_SUCCESS(Status
))
1042 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1047 RETURN(!RECTL_bIsEmptyRect(&Rect
));
1050 DPRINT("Leave NtUserGetUpdateRect, ret=%i\n",_ret_
);
1056 * NtUserRedrawWindow
1063 NtUserRedrawWindow(HWND hWnd
, CONST RECT
*lprcUpdate
, HRGN hrgnUpdate
,
1066 RECTL SafeUpdateRect
;
1069 DECLARE_RETURN(BOOL
);
1070 USER_REFERENCE_ENTRY Ref
;
1072 DPRINT("Enter NtUserRedrawWindow\n");
1073 UserEnterExclusive();
1075 if (!(Wnd
= UserGetWindowObject(hWnd
? hWnd
: IntGetDesktopWindow())))
1080 if (lprcUpdate
!= NULL
)
1082 Status
= MmCopyFromCaller(&SafeUpdateRect
, lprcUpdate
,
1085 if (!NT_SUCCESS(Status
))
1087 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1092 UserRefObjectCo(Wnd
, &Ref
);
1094 Status
= co_UserRedrawWindow(Wnd
, NULL
== lprcUpdate
? NULL
: &SafeUpdateRect
,
1097 UserDerefObjectCo(Wnd
);
1099 if (!NT_SUCCESS(Status
))
1101 /* IntRedrawWindow fails only in case that flags are invalid */
1102 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1109 DPRINT("Leave NtUserRedrawWindow, ret=%i\n",_ret_
);
1116 UserScrollDC(HDC hDC
, INT dx
, INT dy
, const RECTL
*prcScroll
,
1117 const RECTL
*prcClip
, HRGN hrgnUpdate
, RECTL
*prcUpdate
)
1120 RECTL rcScroll
, rcClip
, rcSrc
, rcDst
;
1123 GdiGetClipBox(hDC
, &rcClip
);
1127 RECTL_bIntersectRect(&rcClip
, &rcClip
, prcClip
);
1132 rcScroll
= *prcScroll
;
1133 RECTL_bIntersectRect(&rcSrc
, &rcClip
, prcScroll
);
1141 RECTL_vOffsetRect(&rcDst
, dx
, dy
);
1142 RECTL_bIntersectRect(&rcDst
, &rcDst
, &rcClip
);
1144 if (!NtGdiBitBlt(hDC
, rcDst
.left
, rcDst
.top
,
1145 rcDst
.right
- rcDst
.left
, rcDst
.bottom
- rcDst
.top
,
1146 hDC
, rcDst
.left
- dx
, rcDst
.top
- dy
, SRCCOPY
, 0, 0))
1151 /* Calculate the region that was invalidated by moving or
1152 could not be copied, because it was not visible */
1153 if (hrgnUpdate
|| prcUpdate
)
1155 HRGN hrgnOwn
, hrgnVisible
, hrgnTmp
;
1157 pDC
= DC_LockDc(hDC
);
1162 hrgnVisible
= pDC
->rosdc
.hVisRgn
; // pDC->w.hGCClipRgn?
1165 /* Begin with the shifted and then clipped scroll rect */
1167 RECTL_vOffsetRect(&rcDst
, dx
, dy
);
1168 RECTL_bIntersectRect(&rcDst
, &rcDst
, &rcClip
);
1171 hrgnOwn
= hrgnUpdate
;
1172 if (!NtGdiSetRectRgn(hrgnOwn
, rcDst
.left
, rcDst
.top
, rcDst
.right
, rcDst
.bottom
))
1179 hrgnOwn
= IntSysCreateRectRgnIndirect(&rcDst
);
1182 /* Add the source rect */
1183 hrgnTmp
= IntSysCreateRectRgnIndirect(&rcSrc
);
1184 NtGdiCombineRgn(hrgnOwn
, hrgnOwn
, hrgnTmp
, RGN_OR
);
1186 /* Substract the part of the dest that was visible in source */
1187 NtGdiCombineRgn(hrgnTmp
, hrgnTmp
, hrgnVisible
, RGN_AND
);
1188 NtGdiOffsetRgn(hrgnTmp
, dx
, dy
);
1189 Result
= NtGdiCombineRgn(hrgnOwn
, hrgnOwn
, hrgnTmp
, RGN_DIFF
);
1191 REGION_FreeRgnByHandle(hrgnTmp
);
1195 IntGdiGetRgnBox(hrgnOwn
, prcUpdate
);
1200 REGION_FreeRgnByHandle(hrgnOwn
);
1204 Result
= NULLREGION
;
1220 const RECT
*prcUnsafeScroll
,
1221 const RECT
*prcUnsafeClip
,
1223 LPRECT prcUnsafeUpdate
)
1225 DECLARE_RETURN(DWORD
);
1226 RECTL rcScroll
, rcClip
, rcUpdate
;
1227 NTSTATUS Status
= STATUS_SUCCESS
;
1230 DPRINT("Enter NtUserScrollDC\n");
1231 UserEnterExclusive();
1235 if (prcUnsafeScroll
)
1237 ProbeForRead(prcUnsafeScroll
, sizeof(*prcUnsafeScroll
), 1);
1238 rcScroll
= *prcUnsafeScroll
;
1242 ProbeForRead(prcUnsafeClip
, sizeof(*prcUnsafeClip
), 1);
1243 rcClip
= *prcUnsafeClip
;
1245 if (prcUnsafeUpdate
)
1247 ProbeForWrite(prcUnsafeUpdate
, sizeof(*prcUnsafeUpdate
), 1);
1250 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1252 Status
= _SEH2_GetExceptionCode();
1255 if (!NT_SUCCESS(Status
))
1257 SetLastNtError(Status
);
1261 Result
= UserScrollDC( hDC
,
1264 prcUnsafeScroll
? &rcScroll
: 0,
1265 prcUnsafeClip
? &rcClip
: 0,
1267 prcUnsafeUpdate
? &rcUpdate
: NULL
);
1270 /* FIXME: Only if hRgnUpdate is invalid we should SetLastError(ERROR_INVALID_HANDLE) */
1274 if (prcUnsafeUpdate
)
1278 *prcUnsafeUpdate
= rcUpdate
;
1280 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1282 Status
= _SEH2_GetExceptionCode();
1285 if (!NT_SUCCESS(Status
))
1287 /* FIXME: SetLastError? */
1288 /* FIXME: correct? We have already scrolled! */
1296 DPRINT("Leave NtUserScrollDC, ret=%i\n",_ret_
);
1302 * NtUserScrollWindowEx
1309 NtUserScrollWindowEx(
1313 const RECT
*prcUnsafeScroll
,
1314 const RECT
*prcUnsafeClip
,
1316 LPRECT prcUnsafeUpdate
,
1319 RECTL rcScroll
, rcClip
, rcCaret
, rcUpdate
;
1321 PWINDOW_OBJECT Window
= NULL
, CaretWnd
;
1323 HRGN hrgnOwn
= NULL
, hrgnTemp
;
1325 NTSTATUS Status
= STATUS_SUCCESS
;
1326 DECLARE_RETURN(DWORD
);
1327 USER_REFERENCE_ENTRY Ref
, CaretRef
;
1329 DPRINT("Enter NtUserScrollWindowEx\n");
1330 UserEnterExclusive();
1332 Window
= UserGetWindowObject(hWnd
);
1333 if (!Window
|| !IntIsWindowDrawable(Window
))
1335 Window
= NULL
; /* prevent deref at cleanup */
1338 UserRefObjectCo(Window
, &Ref
);
1340 IntGetClientRect(Window
, &rcClip
);
1344 if (prcUnsafeScroll
)
1346 ProbeForRead(prcUnsafeScroll
, sizeof(*prcUnsafeScroll
), 1);
1347 RECTL_bIntersectRect(&rcScroll
, &rcClip
, prcUnsafeScroll
);
1354 ProbeForRead(prcUnsafeClip
, sizeof(*prcUnsafeClip
), 1);
1355 RECTL_bIntersectRect(&rcClip
, &rcClip
, prcUnsafeClip
);
1358 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1360 Status
= _SEH2_GetExceptionCode();
1364 if (!NT_SUCCESS(Status
))
1366 SetLastNtError(Status
);
1370 if (rcClip
.right
<= rcClip
.left
|| rcClip
.bottom
<= rcClip
.top
||
1371 (dx
== 0 && dy
== 0))
1377 hrgnOwn
= hrgnUpdate
;
1379 hrgnOwn
= IntSysCreateRectRgn(0, 0, 0, 0);
1381 hDC
= UserGetDCEx(Window
, 0, DCX_CACHE
| DCX_USESTYLE
);
1384 /* FIXME: SetLastError? */
1389 hwndCaret
= co_IntFixCaret(Window
, &rcCaret
, flags
);
1391 Result
= UserScrollDC( hDC
,
1397 prcUnsafeUpdate
? &rcUpdate
: NULL
);
1399 UserReleaseDC(Window
, hDC
, FALSE
);
1402 * Take into account the fact that some damage may have occurred during
1406 hrgnTemp
= IntSysCreateRectRgn(0, 0, 0, 0);
1407 if (co_UserGetUpdateRgn(Window
, hrgnTemp
, FALSE
) != NULLREGION
)
1409 HRGN hrgnClip
= IntSysCreateRectRgnIndirect(&rcClip
);
1410 NtGdiOffsetRgn(hrgnTemp
, dx
, dy
);
1411 NtGdiCombineRgn(hrgnTemp
, hrgnTemp
, hrgnClip
, RGN_AND
);
1412 co_UserRedrawWindow(Window
, NULL
, hrgnTemp
, RDW_INVALIDATE
| RDW_ERASE
);
1413 REGION_FreeRgnByHandle(hrgnClip
);
1415 REGION_FreeRgnByHandle(hrgnTemp
);
1417 if (flags
& SW_SCROLLCHILDREN
)
1419 PWINDOW_OBJECT Child
;
1422 USER_REFERENCE_ENTRY WndRef
;
1425 IntGetClientOrigin(Window
, &ClientOrigin
);
1426 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
1428 rcChild
= Child
->Wnd
->rcWindow
;
1429 rcChild
.left
-= ClientOrigin
.x
;
1430 rcChild
.top
-= ClientOrigin
.y
;
1431 rcChild
.right
-= ClientOrigin
.x
;
1432 rcChild
.bottom
-= ClientOrigin
.y
;
1434 if (! prcUnsafeScroll
|| RECTL_bIntersectRect(&rcDummy
, &rcChild
, &rcScroll
))
1436 UserRefObjectCo(Child
, &WndRef
);
1437 co_WinPosSetWindowPos(Child
, 0, rcChild
.left
+ dx
, rcChild
.top
+ dy
, 0, 0,
1438 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
|
1440 UserDerefObjectCo(Child
);
1445 if (flags
& (SW_INVALIDATE
| SW_ERASE
))
1447 co_UserRedrawWindow(Window
, NULL
, hrgnOwn
, RDW_INVALIDATE
| RDW_ERASE
|
1448 ((flags
& SW_ERASE
) ? RDW_ERASENOW
: 0) |
1449 ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0));
1452 if ((CaretWnd
= UserGetWindowObject(hwndCaret
)))
1454 UserRefObjectCo(CaretWnd
, &CaretRef
);
1456 co_IntSetCaretPos(rcCaret
.left
+ dx
, rcCaret
.top
+ dy
);
1457 co_UserShowCaret(CaretWnd
);
1459 UserDerefObjectCo(CaretWnd
);
1462 if (prcUnsafeUpdate
)
1466 /* Probe here, to not fail on invalid pointer before scrolling */
1467 ProbeForWrite(prcUnsafeUpdate
, sizeof(*prcUnsafeUpdate
), 1);
1468 *prcUnsafeUpdate
= rcUpdate
;
1470 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1472 Status
= _SEH2_GetExceptionCode();
1476 if (!NT_SUCCESS(Status
))
1478 SetLastNtError(Status
);
1486 if (hrgnOwn
&& !hrgnUpdate
)
1488 REGION_FreeRgnByHandle(hrgnOwn
);
1492 UserDerefObjectCo(Window
);
1494 DPRINT("Leave NtUserScrollWindowEx, ret=%i\n",_ret_
);
1501 UserDrawSysMenuButton(
1502 PWINDOW_OBJECT pWnd
,
1508 PCURICON_OBJECT pIcon
;
1510 ASSERT(pWnd
&& lpRc
);
1512 /* Get the icon to draw. We don't care about WM_GETICON here. */
1514 hIcon
= pWnd
->Wnd
->pcls
->hIconSm
;
1518 DPRINT("Wnd class has no small icon.\n");
1519 hIcon
= pWnd
->Wnd
->pcls
->hIcon
;
1524 DPRINT("Wnd class hasn't any icon.\n");
1525 //FIXME: Draw "winlogo" icon.
1529 if(!(pIcon
= UserGetCurIconObject(hIcon
)))
1531 DPRINT1("UserGetCurIconObject() failed!\n");
1535 return UserDrawIconEx(hDc
, lpRc
->left
, lpRc
->top
, pIcon
,
1536 UserGetSystemMetrics(SM_CXSMICON
),
1537 UserGetSystemMetrics(SM_CYSMICON
),
1538 0, NULL
, DI_NORMAL
);
1542 UserDrawCaptionText(HDC hDc
,
1543 const PUNICODE_STRING Text
,
1547 HFONT hOldFont
= NULL
, hFont
= NULL
;
1548 COLORREF OldTextColor
;
1549 NONCLIENTMETRICSW nclm
;
1553 DPRINT("%s:", __FUNCTION__
);
1554 for(i
= 0; i
< Text
->Length
/sizeof(WCHAR
); i
++)
1555 DbgPrint("%C", Text
->Buffer
[i
]);
1556 DbgPrint(", %d\n", Text
->Length
/sizeof(WCHAR
));
1559 nclm
.cbSize
= sizeof(nclm
);
1560 if(!UserSystemParametersInfo(SPI_GETNONCLIENTMETRICS
,
1561 sizeof(NONCLIENTMETRICS
), &nclm
, 0))
1563 DPRINT1("%s: UserSystemParametersInfo() failed!\n", __FUNCTION__
);
1567 IntGdiSetBkMode(hDc
, TRANSPARENT
);
1569 if(uFlags
& DC_SMALLCAP
)
1570 Status
= TextIntCreateFontIndirect(&nclm
.lfSmCaptionFont
, &hFont
);
1571 else Status
= TextIntCreateFontIndirect(&nclm
.lfCaptionFont
, &hFont
);
1573 if(!NT_SUCCESS(Status
))
1575 DPRINT1("%s: TextIntCreateFontIndirect() failed! Status: 0x%x\n",
1576 __FUNCTION__
, Status
);
1580 hOldFont
= NtGdiSelectFont(hDc
, hFont
);
1583 DPRINT1("%s: SelectFont() failed!\n", __FUNCTION__
);
1584 GreDeleteObject(hFont
);
1588 if(uFlags
& DC_INBUTTON
)
1589 OldTextColor
= IntGdiSetTextColor(hDc
, IntGetSysColor(COLOR_BTNTEXT
));
1590 else OldTextColor
= IntGdiSetTextColor(hDc
, IntGetSysColor(uFlags
& DC_ACTIVE
1591 ? COLOR_CAPTIONTEXT
: COLOR_INACTIVECAPTIONTEXT
));
1593 //FIXME: If string doesn't fit to rc, truncate it and add ellipsis.
1595 GreExtTextOutW(hDc
, lpRc
->left
,
1596 lpRc
->top
, 0, NULL
, Text
->Buffer
,
1597 Text
->Length
/sizeof(WCHAR
), NULL
, 0);
1599 IntGdiSetTextColor(hDc
, OldTextColor
);
1600 NtGdiSelectFont(hDc
, hOldFont
);
1601 GreDeleteObject(hFont
);
1606 BOOL
UserDrawCaption(
1607 PWINDOW_OBJECT pWnd
,
1612 const PUNICODE_STRING str
,
1616 HBITMAP hMemBmp
= NULL
, hOldBmp
= NULL
;
1617 HBRUSH hOldBrush
= NULL
;
1620 UINT VCenter
= 0, Padding
= 0;
1622 LONG ButtonWidth
, IconWidth
;
1626 //ASSERT(pWnd != NULL);
1631 RECTL_vMakeWellOrdered(lpRc
);
1632 hMemBmp
= NtGdiCreateCompatibleBitmap(hDc
,
1633 lpRc
->right
- lpRc
->left
,
1634 lpRc
->bottom
- lpRc
->top
);
1638 DPRINT1("%s: NtGdiCreateCompatibleBitmap() failed!\n", __FUNCTION__
);
1642 hMemDc
= NtGdiCreateCompatibleDC(hDc
);
1645 DPRINT1("%s: NtGdiCreateCompatibleDC() failed!\n", __FUNCTION__
);
1649 hOldBmp
= NtGdiSelectBitmap(hMemDc
, hMemBmp
);
1652 DPRINT1("%s: NtGdiSelectBitmap() failed!\n", __FUNCTION__
);
1656 Height
= UserGetSystemMetrics(SM_CYCAPTION
) - 1;
1657 VCenter
= (lpRc
->bottom
- lpRc
->top
) / 2;
1658 Padding
= VCenter
- (Height
/ 2);
1660 if ((!hIcon
) && (Wnd
!= NULL
))
1662 HasIcon
= (uFlags
& DC_ICON
) && (Wnd
->style
& WS_SYSMENU
)
1663 && !(uFlags
& DC_SMALLCAP
) && !(Wnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1664 && !(Wnd
->ExStyle
& WS_EX_TOOLWINDOW
);
1667 HasIcon
= (hIcon
!= 0);
1669 IconWidth
= UserGetSystemMetrics(SM_CXSIZE
) + Padding
;
1672 r
.right
= r
.left
+ (lpRc
->right
- lpRc
->left
);
1674 r
.bottom
= r
.top
+ (Height
/ 2);
1676 // Draw the caption background
1677 if(uFlags
& DC_INBUTTON
)
1679 hOldBrush
= NtGdiSelectBrush(hMemDc
,
1680 IntGetSysColorBrush(COLOR_3DFACE
));
1684 DPRINT1("%s: NtGdiSelectBrush() failed!\n", __FUNCTION__
);
1688 if(!NtGdiPatBlt(hMemDc
, 0, 0,
1689 lpRc
->right
- lpRc
->left
,
1690 lpRc
->bottom
- lpRc
->top
,
1693 DPRINT1("%s: NtGdiPatBlt() failed!\n", __FUNCTION__
);
1697 if(HasIcon
) r
.left
+=IconWidth
;
1701 r
.right
= (lpRc
->right
- lpRc
->left
);
1702 if(uFlags
& DC_SMALLCAP
)
1703 ButtonWidth
= UserGetSystemMetrics(SM_CXSMSIZE
) - 2;
1704 else ButtonWidth
= UserGetSystemMetrics(SM_CXSIZE
) - 2;
1706 hOldBrush
= NtGdiSelectBrush(hMemDc
,
1707 IntGetSysColorBrush(uFlags
& DC_ACTIVE
?
1708 COLOR_ACTIVECAPTION
: COLOR_INACTIVECAPTION
));
1712 DPRINT1("%s: NtGdiSelectBrush() failed!\n", __FUNCTION__
);
1716 if(HasIcon
&& (uFlags
& DC_GRADIENT
))
1718 NtGdiPatBlt(hMemDc
, 0, 0,
1720 lpRc
->bottom
- lpRc
->top
,
1726 NtGdiPatBlt(hMemDc
, 0, 0,
1727 lpRc
->right
- lpRc
->left
,
1728 lpRc
->bottom
- lpRc
->top
,
1732 if(uFlags
& DC_GRADIENT
)
1734 static GRADIENT_RECT gcap
= {0, 1};
1741 if(Wnd
->style
& WS_SYSMENU
)
1743 r
.right
-= 3 + ButtonWidth
;
1744 if(!(uFlags
& DC_SMALLCAP
))
1746 if(Wnd
->style
& (WS_MAXIMIZEBOX
| WS_MINIMIZEBOX
))
1747 r
.right
-= 2 + 2 * ButtonWidth
;
1752 //Draw buttons background
1753 if(!NtGdiSelectBrush(hMemDc
,
1754 IntGetSysColorBrush(uFlags
& DC_ACTIVE
?
1755 COLOR_GRADIENTACTIVECAPTION
:COLOR_GRADIENTINACTIVECAPTION
)))
1757 DPRINT1("%s: NtGdiSelectBrush() failed!\n", __FUNCTION__
);
1764 lpRc
->right
- lpRc
->left
- r
.right
,
1765 lpRc
->bottom
- lpRc
->top
,
1770 Colors
[0] = IntGetSysColor((uFlags
& DC_ACTIVE
) ?
1771 COLOR_ACTIVECAPTION
: COLOR_INACTIVECAPTION
);
1773 Colors
[1] = IntGetSysColor((uFlags
& DC_ACTIVE
) ?
1774 COLOR_GRADIENTACTIVECAPTION
: COLOR_GRADIENTINACTIVECAPTION
);
1778 vert
[0].Red
= (WORD
)Colors
[0]<<8;
1779 vert
[0].Green
= (WORD
)Colors
[0] & 0xFF00;
1780 vert
[0].Blue
= (WORD
)(Colors
[0]>>8) & 0xFF00;
1783 vert
[1].x
= r
.right
;
1784 vert
[1].y
= lpRc
->bottom
- lpRc
->top
;
1785 vert
[1].Red
= (WORD
)Colors
[1]<<8;
1786 vert
[1].Green
= (WORD
)Colors
[1] & 0xFF00;
1787 vert
[1].Blue
= (WORD
)(Colors
[1]>>8) & 0xFF00;
1790 pMemDc
= DC_LockDc(hMemDc
);
1793 DPRINT1("%s: Can't lock dc!\n", __FUNCTION__
);
1797 if(!IntGdiGradientFill(pMemDc
, vert
, 2, &gcap
,
1798 1, GRADIENT_FILL_RECT_H
))
1800 DPRINT1("%s: IntGdiGradientFill() failed!\n", __FUNCTION__
);
1803 DC_UnlockDc(pMemDc
);
1804 } //if(uFlags & DC_GRADIENT)
1810 r
.left
-= --IconWidth
;
1811 /* FIXME: Draw the Icon when pWnd == NULL but hIcon is valid */
1813 UserDrawSysMenuButton(pWnd
, hMemDc
, &r
, FALSE
);
1815 r
.left
+= IconWidth
;
1822 r
.bottom
= r
.top
+ Height
;
1824 if((uFlags
& DC_TEXT
))
1826 if(!(uFlags
& DC_GRADIENT
))
1828 r
.right
= (lpRc
->right
- lpRc
->left
);
1830 if(uFlags
& DC_SMALLCAP
)
1831 ButtonWidth
= UserGetSystemMetrics(SM_CXSMSIZE
) - 2;
1832 else ButtonWidth
= UserGetSystemMetrics(SM_CXSIZE
) - 2;
1834 if ((Wnd
!= NULL
) && (Wnd
->style
& WS_SYSMENU
))
1836 r
.right
-= 3 + ButtonWidth
;
1837 if(! (uFlags
& DC_SMALLCAP
))
1839 if(Wnd
->style
& (WS_MAXIMIZEBOX
| WS_MINIMIZEBOX
))
1840 r
.right
-= 2 + 2 * ButtonWidth
;
1847 /* FIXME: hFont isn't handled */
1849 UserDrawCaptionText(hMemDc
, str
, &r
, uFlags
);
1850 else if (pWnd
!= NULL
)
1851 UserDrawCaptionText(hMemDc
, &pWnd
->Wnd
->strName
, &r
, uFlags
);
1854 if(!NtGdiBitBlt(hDc
, lpRc
->left
, lpRc
->top
,
1855 lpRc
->right
- lpRc
->left
, lpRc
->bottom
- lpRc
->top
,
1856 hMemDc
, 0, 0, SRCCOPY
, 0, 0))
1858 DPRINT1("%s: NtGdiBitBlt() failed!\n", __FUNCTION__
);
1865 if (hOldBrush
) NtGdiSelectBrush(hMemDc
, hOldBrush
);
1866 if (hOldBmp
) NtGdiSelectBitmap(hMemDc
, hOldBmp
);
1867 if (hMemBmp
) GreDeleteObject(hMemBmp
);
1868 if (hMemDc
) NtGdiDeleteObjectApp(hMemDc
);
1875 UserRealizePalette(HDC hdc
)
1880 Ret
= IntGdiRealizePalette(hdc
);
1881 if (Ret
) // There was a change.
1883 hWnd
= IntWindowFromDC(hdc
);
1884 if (hWnd
) // Send broadcast if dc is associated with a window.
1885 { // FYI: Thread locked in CallOneParam.
1886 co_IntSendMessage((HWND
)HWND_BROADCAST
, WM_PALETTECHANGED
, (WPARAM
)hWnd
, 0);
1894 NtUserDrawCaptionTemp(
1900 const PUNICODE_STRING str
,
1903 PWINDOW_OBJECT pWnd
= NULL
;
1904 UNICODE_STRING SafeStr
= {0};
1905 NTSTATUS Status
= STATUS_SUCCESS
;
1909 UserEnterExclusive();
1913 if(!(pWnd
= UserGetWindowObject(hWnd
)))
1922 ProbeForRead(lpRc
, sizeof(RECTL
), sizeof(ULONG
));
1923 RtlCopyMemory(&SafeRect
, lpRc
, sizeof(RECTL
));
1926 SafeStr
= ProbeForReadUnicodeString(str
);
1927 if (SafeStr
.Length
!= 0)
1929 ProbeForRead( SafeStr
.Buffer
,
1935 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1937 Status
= _SEH2_GetExceptionCode();
1941 if (Status
!= STATUS_SUCCESS
)
1943 SetLastNtError(Status
);
1949 Ret
= UserDrawCaption(pWnd
, hDC
, &SafeRect
, hFont
, hIcon
, &SafeStr
, uFlags
);
1951 Ret
= UserDrawCaption(pWnd
, hDC
, &SafeRect
, hFont
, hIcon
, NULL
, uFlags
);
1959 NtUserDrawCaption(HWND hWnd
,
1964 return NtUserDrawCaptionTemp(hWnd
, hDC
, lpRc
, 0, 0, NULL
, uFlags
);
1969 NtUserInvalidateRect(
1971 CONST RECT
*lpUnsafeRect
,
1974 return NtUserRedrawWindow(hWnd
, lpUnsafeRect
, NULL
, RDW_INVALIDATE
| (bErase
? RDW_ERASE
: 0));
1979 NtUserInvalidateRgn(
1984 return NtUserRedrawWindow(hWnd
, NULL
, hRgn
, RDW_INVALIDATE
| (bErase
? RDW_ERASE
: 0));