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
,
86 RDW_VALIDATE
| RDW_NOCHILDREN
);
89 ParentWindow
= ParentWindow
->spwndParent
;
96 * @name IntCalcWindowRgn
98 * Get a window or client region.
102 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 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
->Wnd
->state
& WNDS_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 Wnd
->state
& WNDS_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);
254 if ( (HANDLE
) 1 != TempRegion
&&
257 /* NOTE: The region can already be deleted! */
258 GDIOBJ_FreeObjByHandle(TempRegion
, GDI_OBJECT_TYPE_REGION
| GDI_OBJECT_TYPE_SILENT
);
262 if (Window
->state
& WINDOWOBJECT_NEED_ERASEBKGND
)
264 if (Window
->hrgnUpdate
)
266 hDC
= UserGetDCEx( Window
,
268 DCX_CACHE
|DCX_USESTYLE
|DCX_INTERSECTRGN
|DCX_KEEPCLIPRGN
);
270 if (co_IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)hDC
, 0))
272 Window
->state
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
274 UserReleaseDC(Window
, hDC
, FALSE
);
281 * Check that the window is still valid at this point
283 if (!IntIsWindow(hWnd
))
289 * Paint child windows.
291 if (!(Flags
& RDW_NOCHILDREN
) &&
292 !(Wnd
->style
& WS_MINIMIZE
) &&
293 ((Flags
& RDW_ALLCHILDREN
) || !(Wnd
->style
& WS_CLIPCHILDREN
)) )
297 if ((List
= IntWinListChildren(Window
)))
299 /* FIXME: Handle WS_EX_TRANSPARENT */
300 for (phWnd
= List
; *phWnd
; ++phWnd
)
302 Window
= UserGetWindowObject(*phWnd
);
304 if (Window
&& (Wnd
->style
& WS_VISIBLE
))
306 USER_REFERENCE_ENTRY Ref
;
307 UserRefObjectCo(Window
, &Ref
);
308 co_IntPaintWindows(Window
, Flags
, TRUE
);
309 UserDerefObjectCo(Window
);
318 * IntInvalidateWindows
320 * Internal function used by IntRedrawWindow.
324 IntInvalidateWindows(PWINDOW_OBJECT Window
, HRGN hRgn
, ULONG Flags
)
328 BOOL HadPaintMessage
, HadNCPaintMessage
;
329 BOOL HasPaintMessage
, HasNCPaintMessage
;
332 DPRINT("IntInvalidateWindows start\n");
334 * If the nonclient is not to be redrawn, clip the region to the client
337 if (0 != (Flags
& RDW_INVALIDATE
) && 0 == (Flags
& RDW_FRAME
))
341 hRgnClient
= IntSysCreateRectRgnIndirect(&Window
->Wnd
->rcClient
);
342 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, hRgnClient
, RGN_AND
);
343 REGION_FreeRgnByHandle(hRgnClient
);
347 * Clip the given region with window rectangle (or region)
350 if (!Window
->hrgnClip
|| (Wnd
->style
& WS_MINIMIZE
))
354 hRgnWindow
= IntSysCreateRectRgnIndirect(&Window
->Wnd
->rcWindow
);
355 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, hRgnWindow
, RGN_AND
);
356 REGION_FreeRgnByHandle(hRgnWindow
);
360 NtGdiOffsetRgn( hRgn
,
363 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, Window
->hrgnClip
, RGN_AND
);
364 NtGdiOffsetRgn( hRgn
,
370 * Save current state of pending updates
373 HadPaintMessage
= Window
->hrgnUpdate
!= NULL
||
374 Wnd
->state
& WNDS_INTERNALPAINT
;
375 HadNCPaintMessage
= Window
->state
& WINDOWOBJECT_NEED_NCPAINT
;
378 * Update the region and flags
381 if (Flags
& RDW_INVALIDATE
&& RgnType
!= NULLREGION
)
383 if (Window
->hrgnUpdate
== NULL
)
385 Window
->hrgnUpdate
= IntSysCreateRectRgn(0, 0, 0, 0);
386 IntGdiSetRegionOwner(Window
->hrgnUpdate
, GDI_OBJ_HMGR_PUBLIC
);
389 if (NtGdiCombineRgn(Window
->hrgnUpdate
, Window
->hrgnUpdate
,
390 hRgn
, RGN_OR
) == NULLREGION
)
392 IntGdiSetRegionOwner(Window
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
393 REGION_FreeRgnByHandle(Window
->hrgnUpdate
);
394 Window
->hrgnUpdate
= NULL
;
397 if (Flags
& RDW_FRAME
)
398 Window
->state
|= WINDOWOBJECT_NEED_NCPAINT
;
399 if (Flags
& RDW_ERASE
)
400 Window
->state
|= WINDOWOBJECT_NEED_ERASEBKGND
;
405 if (Flags
& RDW_VALIDATE
&& RgnType
!= NULLREGION
)
407 if (Window
->hrgnUpdate
!= NULL
)
409 if (NtGdiCombineRgn(Window
->hrgnUpdate
, Window
->hrgnUpdate
,
410 hRgn
, RGN_DIFF
) == NULLREGION
)
412 IntGdiSetRegionOwner(Window
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
413 REGION_FreeRgnByHandle(Window
->hrgnUpdate
);
414 Window
->hrgnUpdate
= NULL
;
418 if (Window
->hrgnUpdate
== NULL
)
419 Window
->state
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
420 if (Flags
& RDW_NOFRAME
)
421 Window
->state
&= ~WINDOWOBJECT_NEED_NCPAINT
;
422 if (Flags
& RDW_NOERASE
)
423 Window
->state
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
426 if (Flags
& RDW_INTERNALPAINT
)
428 Wnd
->state
|= WNDS_INTERNALPAINT
;
431 if (Flags
& RDW_NOINTERNALPAINT
)
433 Wnd
->state
&= ~WNDS_INTERNALPAINT
;
437 * Process children if needed
440 if (!(Flags
& RDW_NOCHILDREN
) && !(Wnd
->style
& WS_MINIMIZE
) &&
441 ((Flags
& RDW_ALLCHILDREN
) || !(Wnd
->style
& WS_CLIPCHILDREN
)))
443 PWINDOW_OBJECT Child
;
445 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
447 if (Child
->Wnd
->style
& WS_VISIBLE
)
450 * Recursive call to update children hrgnUpdate
452 HRGN hRgnTemp
= IntSysCreateRectRgn(0, 0, 0, 0);
453 NtGdiCombineRgn(hRgnTemp
, hRgn
, 0, RGN_COPY
);
454 IntInvalidateWindows(Child
, hRgnTemp
, Flags
);
455 REGION_FreeRgnByHandle(hRgnTemp
);
462 * Fake post paint messages to window message queue if needed
465 HasPaintMessage
= Window
->hrgnUpdate
!= NULL
||
466 Wnd
->state
& WNDS_INTERNALPAINT
;
467 HasNCPaintMessage
= Window
->state
& WINDOWOBJECT_NEED_NCPAINT
;
469 if (HasPaintMessage
!= HadPaintMessage
)
472 MsqDecPaintCountQueue(Window
->pti
->MessageQueue
);
474 MsqIncPaintCountQueue(Window
->pti
->MessageQueue
);
477 if (HasNCPaintMessage
!= HadNCPaintMessage
)
479 if (HadNCPaintMessage
)
480 MsqDecPaintCountQueue(Window
->pti
->MessageQueue
);
482 MsqIncPaintCountQueue(Window
->pti
->MessageQueue
);
484 DPRINT("IntInvalidateWindows exit\n");
488 * IntIsWindowDrawable
491 * Window is drawable when it is visible and all parents are not
496 IntIsWindowDrawable(PWINDOW_OBJECT Window
)
498 PWINDOW_OBJECT WndObject
;
501 for (WndObject
= Window
; WndObject
!= NULL
; WndObject
= WndObject
->spwndParent
)
503 Wnd
= WndObject
->Wnd
;
504 if ( Window
->state
& WINDOWSTATUS_DESTROYING
|| // state2
505 Window
->state
& WINDOWSTATUS_DESTROYED
||
507 !(Wnd
->style
& WS_VISIBLE
) ||
508 ((Wnd
->style
& WS_MINIMIZE
) && (WndObject
!= Window
)))
520 * Internal version of NtUserRedrawWindow that takes WINDOW_OBJECT as
526 PWINDOW_OBJECT Window
,
527 const RECTL
* UpdateRect
,
532 DPRINT("co_UserRedrawWindow start\n");
536 * Validation of passed parameters.
539 if (!IntIsWindowDrawable(Window
))
541 return TRUE
; // Just do nothing!!!
546 * Transform the parameters UpdateRgn and UpdateRect into
547 * a region hRgn specified in screen coordinates.
550 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
)) // Both are OKAY!
552 if (UpdateRgn
!= NULL
)
554 hRgn
= IntSysCreateRectRgn(0, 0, 0, 0);
555 if (NtGdiCombineRgn(hRgn
, UpdateRgn
, NULL
, RGN_COPY
) == NULLREGION
)
557 REGION_FreeRgnByHandle(hRgn
);
561 NtGdiOffsetRgn(hRgn
, Window
->Wnd
->rcClient
.left
, Window
->Wnd
->rcClient
.top
);
563 else if (UpdateRect
!= NULL
)
565 if (!RECTL_bIsEmptyRect(UpdateRect
))
567 hRgn
= IntSysCreateRectRgnIndirect((RECTL
*)UpdateRect
);
568 NtGdiOffsetRgn(hRgn
, Window
->Wnd
->rcClient
.left
, Window
->Wnd
->rcClient
.top
);
571 else if ((Flags
& (RDW_INVALIDATE
| RDW_FRAME
)) == (RDW_INVALIDATE
| RDW_FRAME
) ||
572 (Flags
& (RDW_VALIDATE
| RDW_NOFRAME
)) == (RDW_VALIDATE
| RDW_NOFRAME
))
574 if (!RECTL_bIsEmptyRect(&Window
->Wnd
->rcWindow
))
575 hRgn
= IntSysCreateRectRgnIndirect(&Window
->Wnd
->rcWindow
);
579 if (!RECTL_bIsEmptyRect(&Window
->Wnd
->rcClient
))
580 hRgn
= IntSysCreateRectRgnIndirect(&Window
->Wnd
->rcClient
);
586 * Adjust the window update region depending on hRgn and flags.
589 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
| RDW_INTERNALPAINT
| RDW_NOINTERNALPAINT
) &&
592 IntInvalidateWindows(Window
, hRgn
, Flags
);
597 * Repaint and erase windows if needed.
600 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
602 co_IntPaintWindows(Window
, Flags
, FALSE
);
612 REGION_FreeRgnByHandle(hRgn
);
614 DPRINT("co_UserRedrawWindow exit\n");
620 IntIsWindowDirty(PWINDOW_OBJECT Window
)
622 PWND Wnd
= Window
->Wnd
;
623 return (Wnd
->style
& WS_VISIBLE
) &&
624 ((Window
->hrgnUpdate
!= NULL
) ||
625 (Wnd
->state
& WNDS_INTERNALPAINT
) ||
626 (Window
->state
& WINDOWOBJECT_NEED_NCPAINT
));
630 IntFindWindowToRepaint(PWINDOW_OBJECT Window
, PTHREADINFO Thread
)
633 PWINDOW_OBJECT TempWindow
;
636 for (; Window
!= NULL
; Window
= Window
->spwndNext
)
639 if (IntWndBelongsToThread(Window
, Thread
) &&
640 IntIsWindowDirty(Window
))
642 /* Make sure all non-transparent siblings are already drawn. */
643 if (Wnd
->ExStyle
& WS_EX_TRANSPARENT
)
645 for (TempWindow
= Window
->spwndNext
; TempWindow
!= NULL
;
646 TempWindow
= TempWindow
->spwndNext
)
648 TempWnd
= TempWindow
->Wnd
;
649 if (!(TempWnd
->ExStyle
& WS_EX_TRANSPARENT
) &&
650 IntWndBelongsToThread(TempWindow
, Thread
) &&
651 IntIsWindowDirty(TempWindow
))
653 return TempWindow
->hSelf
;
658 return Window
->hSelf
;
661 if (Window
->spwndChild
)
663 hChild
= IntFindWindowToRepaint(Window
->spwndChild
, Thread
);
674 PWINDOW_OBJECT Window
,
681 PUSER_MESSAGE_QUEUE MessageQueue
= (PUSER_MESSAGE_QUEUE
)Thread
->MessageQueue
;
683 if (!MessageQueue
->PaintCount
)
686 if ((MsgFilterMin
!= 0 || MsgFilterMax
!= 0) &&
687 (MsgFilterMin
> WM_PAINT
|| MsgFilterMax
< WM_PAINT
))
690 Message
->hwnd
= IntFindWindowToRepaint(UserGetDesktopWindow(), PsGetCurrentThreadWin32Thread());
692 if (Message
->hwnd
== NULL
)
694 DPRINT1("PAINTING BUG: Thread marked as containing dirty windows, but no dirty windows found!\n");
695 /* Hack to stop spamming the debuglog ! */
696 MessageQueue
->PaintCount
= 0;
700 if (Window
!= NULL
&& Message
->hwnd
!= Window
->hSelf
)
703 Message
->message
= WM_PAINT
;
704 Message
->wParam
= Message
->lParam
= 0;
711 co_IntFixCaret(PWINDOW_OBJECT Window
, RECTL
*lprc
, UINT flags
)
714 PTHRDCARETINFO CaretInfo
;
716 PWINDOW_OBJECT WndCaret
;
718 ASSERT_REFS_CO(Window
);
720 Desktop
= ((PTHREADINFO
)PsGetCurrentThread()->Tcb
.Win32Thread
)->rpdesk
;
721 CaretInfo
= ((PUSER_MESSAGE_QUEUE
)Desktop
->ActiveMessageQueue
)->CaretInfo
;
722 hWndCaret
= CaretInfo
->hWnd
;
724 WndCaret
= UserGetWindowObject(hWndCaret
);
726 //fix: check for WndCaret can be null
727 if (WndCaret
== Window
||
728 ((flags
& SW_SCROLLCHILDREN
) && IntIsChildWindow(Window
, WndCaret
)))
730 POINT pt
, FromOffset
, ToOffset
;
733 pt
.x
= CaretInfo
->Pos
.x
;
734 pt
.y
= CaretInfo
->Pos
.y
;
735 IntGetClientOrigin(WndCaret
, &FromOffset
);
736 IntGetClientOrigin(Window
, &ToOffset
);
739 rcCaret
.right
= pt
.x
+ CaretInfo
->Size
.cx
;
740 rcCaret
.bottom
= pt
.y
+ CaretInfo
->Size
.cy
;
741 if (RECTL_bIntersectRect(lprc
, lprc
, &rcCaret
))
753 /* PUBLIC FUNCTIONS ***********************************************************/
763 NtUserBeginPaint(HWND hWnd
, PAINTSTRUCT
* UnsafePs
)
765 PWINDOW_OBJECT Window
= NULL
;
769 USER_REFERENCE_ENTRY Ref
;
772 DPRINT("Enter NtUserBeginPaint\n");
773 UserEnterExclusive();
775 if (!(Window
= UserGetWindowObject(hWnd
)))
780 UserRefObjectCo(Window
, &Ref
);
784 co_UserHideCaret(Window
);
786 if (Window
->state
& WINDOWOBJECT_NEED_NCPAINT
)
790 hRgn
= IntGetNCUpdateRgn(Window
, FALSE
);
791 Window
->state
&= ~WINDOWOBJECT_NEED_NCPAINT
;
792 MsqDecPaintCountQueue(Window
->pti
->MessageQueue
);
793 co_IntSendMessage(hWnd
, WM_NCPAINT
, (WPARAM
)hRgn
, 0);
794 if (hRgn
!= (HANDLE
)1 && hRgn
!= NULL
)
796 /* NOTE: The region can already by deleted! */
797 GDIOBJ_FreeObjByHandle(hRgn
, GDI_OBJECT_TYPE_REGION
| GDI_OBJECT_TYPE_SILENT
);
801 RtlZeroMemory(&Ps
, sizeof(PAINTSTRUCT
));
803 Ps
.hdc
= UserGetDCEx( Window
,
805 DCX_INTERSECTRGN
| DCX_USESTYLE
);
811 if (Window
->hrgnUpdate
!= NULL
)
813 MsqDecPaintCountQueue(Window
->pti
->MessageQueue
);
814 GdiGetClipBox(Ps
.hdc
, &Ps
.rcPaint
);
815 IntGdiSetRegionOwner(Window
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
816 /* The region is part of the dc now and belongs to the process! */
817 Window
->hrgnUpdate
= NULL
;
821 if (Wnd
->state
& WNDS_INTERNALPAINT
)
822 MsqDecPaintCountQueue(Window
->pti
->MessageQueue
);
824 IntGetClientRect(Window
, &Ps
.rcPaint
);
827 Wnd
->state
&= ~WNDS_INTERNALPAINT
;
829 if (Window
->state
& WINDOWOBJECT_NEED_ERASEBKGND
)
831 Window
->state
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
832 Ps
.fErase
= !co_IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)Ps
.hdc
, 0);
838 if (Window
->hrgnUpdate
)
840 if (!(Wnd
->style
& WS_CLIPCHILDREN
))
842 PWINDOW_OBJECT Child
;
843 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
845 IntInvalidateWindows(Child
, Window
->hrgnUpdate
, RDW_FRAME
| RDW_ERASE
| RDW_INVALIDATE
| RDW_ALLCHILDREN
);
850 Status
= MmCopyToCaller(UnsafePs
, &Ps
, sizeof(PAINTSTRUCT
));
851 if (! NT_SUCCESS(Status
))
853 SetLastNtError(Status
);
860 if (Window
) UserDerefObjectCo(Window
);
862 DPRINT("Leave NtUserBeginPaint, ret=%i\n",_ret_
);
876 NtUserEndPaint(HWND hWnd
, CONST PAINTSTRUCT
* pUnsafePs
)
878 NTSTATUS Status
= STATUS_SUCCESS
;
879 PWINDOW_OBJECT Window
;
880 DECLARE_RETURN(BOOL
);
881 USER_REFERENCE_ENTRY Ref
;
884 DPRINT("Enter NtUserEndPaint\n");
885 UserEnterExclusive();
887 if (!(Window
= UserGetWindowObject(hWnd
)))
894 ProbeForRead(pUnsafePs
, sizeof(*pUnsafePs
), 1);
895 hdc
= pUnsafePs
->hdc
;
897 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
899 Status
= _SEH2_GetExceptionCode();
902 if (!NT_SUCCESS(Status
))
907 UserReleaseDC(Window
, hdc
, TRUE
);
909 UserRefObjectCo(Window
, &Ref
);
910 co_UserShowCaret(Window
);
911 UserDerefObjectCo(Window
);
916 DPRINT("Leave NtUserEndPaint, ret=%i\n",_ret_
);
923 co_UserGetUpdateRgn(PWINDOW_OBJECT Window
, HRGN hRgn
, BOOL bErase
)
928 ASSERT_REFS_CO(Window
);
930 if (Window
->hrgnUpdate
== NULL
)
932 RegionType
= (NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0) ? NULLREGION
: ERROR
);
936 Rect
= Window
->Wnd
->rcClient
;
937 IntIntersectWithParents(Window
, &Rect
);
938 NtGdiSetRectRgn(hRgn
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
);
939 RegionType
= NtGdiCombineRgn(hRgn
, hRgn
, Window
->hrgnUpdate
, RGN_AND
);
940 NtGdiOffsetRgn(hRgn
, -Window
->Wnd
->rcClient
.left
, -Window
->Wnd
->rcClient
.top
);
943 if (bErase
&& RegionType
!= NULLREGION
&& RegionType
!= ERROR
)
945 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
959 NtUserGetUpdateRgn(HWND hWnd
, HRGN hRgn
, BOOL bErase
)
962 PWINDOW_OBJECT Window
;
964 USER_REFERENCE_ENTRY Ref
;
966 DPRINT("Enter NtUserGetUpdateRgn\n");
967 UserEnterExclusive();
969 if (!(Window
= UserGetWindowObject(hWnd
)))
974 UserRefObjectCo(Window
, &Ref
);
975 ret
= co_UserGetUpdateRgn(Window
, hRgn
, bErase
);
976 UserDerefObjectCo(Window
);
981 DPRINT("Leave NtUserGetUpdateRgn, ret=%i\n",_ret_
);
987 * NtUserGetUpdateRect
994 NtUserGetUpdateRect(HWND hWnd
, LPRECT UnsafeRect
, BOOL bErase
)
996 PWINDOW_OBJECT Window
;
1001 DECLARE_RETURN(BOOL
);
1003 DPRINT("Enter NtUserGetUpdateRect\n");
1004 UserEnterExclusive();
1006 if (!(Window
= UserGetWindowObject(hWnd
)))
1011 if (Window
->hrgnUpdate
== NULL
)
1013 Rect
.left
= Rect
.top
= Rect
.right
= Rect
.bottom
= 0;
1017 /* Get the update region bounding box. */
1018 if (Window
->hrgnUpdate
== (HRGN
)1)
1020 Rect
= Window
->Wnd
->rcClient
;
1024 RgnData
= RGNOBJAPI_Lock(Window
->hrgnUpdate
, NULL
);
1025 ASSERT(RgnData
!= NULL
);
1026 RegionType
= REGION_GetRgnBox(RgnData
, &Rect
);
1027 RGNOBJAPI_Unlock(RgnData
);
1029 if (RegionType
!= ERROR
&& RegionType
!= NULLREGION
)
1030 RECTL_bIntersectRect(&Rect
, &Rect
, &Window
->Wnd
->rcClient
);
1033 if (IntIntersectWithParents(Window
, &Rect
))
1035 RECTL_vOffsetRect(&Rect
,
1036 -Window
->Wnd
->rcClient
.left
,
1037 -Window
->Wnd
->rcClient
.top
);
1040 Rect
.left
= Rect
.top
= Rect
.right
= Rect
.bottom
= 0;
1044 if (bErase
&& !RECTL_bIsEmptyRect(&Rect
))
1046 USER_REFERENCE_ENTRY Ref
;
1047 UserRefObjectCo(Window
, &Ref
);
1048 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
1049 UserDerefObjectCo(Window
);
1052 if (UnsafeRect
!= NULL
)
1054 Status
= MmCopyToCaller(UnsafeRect
, &Rect
, sizeof(RECTL
));
1055 if (!NT_SUCCESS(Status
))
1057 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1062 RETURN(!RECTL_bIsEmptyRect(&Rect
));
1065 DPRINT("Leave NtUserGetUpdateRect, ret=%i\n",_ret_
);
1071 * NtUserRedrawWindow
1080 CONST RECT
*lprcUpdate
,
1084 RECTL SafeUpdateRect
;
1087 USER_REFERENCE_ENTRY Ref
;
1088 NTSTATUS Status
= STATUS_SUCCESS
;
1089 DECLARE_RETURN(BOOL
);
1091 DPRINT("Enter NtUserRedrawWindow\n");
1092 UserEnterExclusive();
1094 if (!(Wnd
= UserGetWindowObject(hWnd
? hWnd
: IntGetDesktopWindow())))
1103 ProbeForRead(lprcUpdate
, sizeof(RECTL
), 1);
1104 RtlCopyMemory(&SafeUpdateRect
, lprcUpdate
, sizeof(RECTL
));
1106 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1108 Status
= _SEH2_GetExceptionCode();
1111 if (!NT_SUCCESS(Status
))
1113 SetLastWin32Error(RtlNtStatusToDosError(Status
));
1118 if ( flags
& ~(RDW_ERASE
|RDW_FRAME
|RDW_INTERNALPAINT
|RDW_INVALIDATE
|
1119 RDW_NOERASE
|RDW_NOFRAME
|RDW_NOINTERNALPAINT
|RDW_VALIDATE
|
1120 RDW_ERASENOW
|RDW_UPDATENOW
|RDW_ALLCHILDREN
|RDW_NOCHILDREN
) )
1122 /* RedrawWindow fails only in case that flags are invalid */
1123 SetLastWin32Error(ERROR_INVALID_FLAGS
);
1127 UserRefObjectCo(Wnd
, &Ref
);
1129 Ret
= co_UserRedrawWindow( Wnd
,
1130 lprcUpdate
? &SafeUpdateRect
: NULL
,
1134 UserDerefObjectCo(Wnd
);
1139 DPRINT("Leave NtUserRedrawWindow, ret=%i\n",_ret_
);
1150 const RECTL
*prcScroll
,
1151 const RECTL
*prcClip
,
1156 RECTL rcScroll
, rcClip
, rcSrc
, rcDst
;
1159 GdiGetClipBox(hDC
, &rcClip
);
1163 RECTL_bIntersectRect(&rcClip
, &rcClip
, prcClip
);
1168 rcScroll
= *prcScroll
;
1169 RECTL_bIntersectRect(&rcSrc
, &rcClip
, prcScroll
);
1177 RECTL_vOffsetRect(&rcDst
, dx
, dy
);
1178 RECTL_bIntersectRect(&rcDst
, &rcDst
, &rcClip
);
1180 if (!NtGdiBitBlt( hDC
,
1183 rcDst
.right
- rcDst
.left
,
1184 rcDst
.bottom
- rcDst
.top
,
1195 /* Calculate the region that was invalidated by moving or
1196 could not be copied, because it was not visible */
1197 if (hrgnUpdate
|| prcUpdate
)
1199 HRGN hrgnOwn
, hrgnVisible
, hrgnTmp
;
1201 pDC
= DC_LockDc(hDC
);
1206 hrgnVisible
= ((PROSRGNDATA
)pDC
->prgnVis
)->BaseObject
.hHmgr
; // pDC->prgnRao?
1208 /* Begin with the shifted and then clipped scroll rect */
1210 RECTL_vOffsetRect(&rcDst
, dx
, dy
);
1211 RECTL_bIntersectRect(&rcDst
, &rcDst
, &rcClip
);
1214 hrgnOwn
= hrgnUpdate
;
1215 if (!NtGdiSetRectRgn(hrgnOwn
, rcDst
.left
, rcDst
.top
, rcDst
.right
, rcDst
.bottom
))
1222 hrgnOwn
= IntSysCreateRectRgnIndirect(&rcDst
);
1225 /* Add the source rect */
1226 hrgnTmp
= IntSysCreateRectRgnIndirect(&rcSrc
);
1227 NtGdiCombineRgn(hrgnOwn
, hrgnOwn
, hrgnTmp
, RGN_OR
);
1229 /* Substract the part of the dest that was visible in source */
1230 NtGdiCombineRgn(hrgnTmp
, hrgnTmp
, hrgnVisible
, RGN_AND
);
1231 NtGdiOffsetRgn(hrgnTmp
, dx
, dy
);
1232 Result
= NtGdiCombineRgn(hrgnOwn
, hrgnOwn
, hrgnTmp
, RGN_DIFF
);
1234 /* DO NOT Unlock DC while messing with prgnVis! */
1237 REGION_FreeRgnByHandle(hrgnTmp
);
1241 IntGdiGetRgnBox(hrgnOwn
, prcUpdate
);
1246 REGION_FreeRgnByHandle(hrgnOwn
);
1250 Result
= NULLREGION
;
1266 const RECT
*prcUnsafeScroll
,
1267 const RECT
*prcUnsafeClip
,
1269 LPRECT prcUnsafeUpdate
)
1271 DECLARE_RETURN(DWORD
);
1272 RECTL rcScroll
, rcClip
, rcUpdate
;
1273 NTSTATUS Status
= STATUS_SUCCESS
;
1276 DPRINT("Enter NtUserScrollDC\n");
1277 UserEnterExclusive();
1281 if (prcUnsafeScroll
)
1283 ProbeForRead(prcUnsafeScroll
, sizeof(*prcUnsafeScroll
), 1);
1284 rcScroll
= *prcUnsafeScroll
;
1288 ProbeForRead(prcUnsafeClip
, sizeof(*prcUnsafeClip
), 1);
1289 rcClip
= *prcUnsafeClip
;
1291 if (prcUnsafeUpdate
)
1293 ProbeForWrite(prcUnsafeUpdate
, sizeof(*prcUnsafeUpdate
), 1);
1296 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1298 Status
= _SEH2_GetExceptionCode();
1301 if (!NT_SUCCESS(Status
))
1303 SetLastNtError(Status
);
1307 Result
= UserScrollDC( hDC
,
1310 prcUnsafeScroll
? &rcScroll
: 0,
1311 prcUnsafeClip
? &rcClip
: 0,
1313 prcUnsafeUpdate
? &rcUpdate
: NULL
);
1316 /* FIXME: Only if hRgnUpdate is invalid we should SetLastError(ERROR_INVALID_HANDLE) */
1320 if (prcUnsafeUpdate
)
1324 *prcUnsafeUpdate
= rcUpdate
;
1326 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1328 Status
= _SEH2_GetExceptionCode();
1331 if (!NT_SUCCESS(Status
))
1333 /* FIXME: SetLastError? */
1334 /* FIXME: correct? We have already scrolled! */
1342 DPRINT("Leave NtUserScrollDC, ret=%i\n",_ret_
);
1348 * NtUserScrollWindowEx
1355 NtUserScrollWindowEx(
1359 const RECT
*prcUnsafeScroll
,
1360 const RECT
*prcUnsafeClip
,
1362 LPRECT prcUnsafeUpdate
,
1365 RECTL rcScroll
, rcClip
, rcCaret
, rcUpdate
;
1367 PWINDOW_OBJECT Window
= NULL
, CaretWnd
;
1369 HRGN hrgnOwn
= NULL
, hrgnTemp
;
1371 NTSTATUS Status
= STATUS_SUCCESS
;
1372 DECLARE_RETURN(DWORD
);
1373 USER_REFERENCE_ENTRY Ref
, CaretRef
;
1375 DPRINT("Enter NtUserScrollWindowEx\n");
1376 UserEnterExclusive();
1378 Window
= UserGetWindowObject(hWnd
);
1379 if (!Window
|| !IntIsWindowDrawable(Window
))
1381 Window
= NULL
; /* prevent deref at cleanup */
1384 UserRefObjectCo(Window
, &Ref
);
1386 IntGetClientRect(Window
, &rcClip
);
1390 if (prcUnsafeScroll
)
1392 ProbeForRead(prcUnsafeScroll
, sizeof(*prcUnsafeScroll
), 1);
1393 RECTL_bIntersectRect(&rcScroll
, &rcClip
, prcUnsafeScroll
);
1400 ProbeForRead(prcUnsafeClip
, sizeof(*prcUnsafeClip
), 1);
1401 RECTL_bIntersectRect(&rcClip
, &rcClip
, prcUnsafeClip
);
1404 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1406 Status
= _SEH2_GetExceptionCode();
1410 if (!NT_SUCCESS(Status
))
1412 SetLastNtError(Status
);
1416 if (rcClip
.right
<= rcClip
.left
|| rcClip
.bottom
<= rcClip
.top
||
1417 (dx
== 0 && dy
== 0))
1423 hrgnOwn
= hrgnUpdate
;
1425 hrgnOwn
= IntSysCreateRectRgn(0, 0, 0, 0);
1427 hDC
= UserGetDCEx(Window
, 0, DCX_CACHE
| DCX_USESTYLE
);
1430 /* FIXME: SetLastError? */
1435 hwndCaret
= co_IntFixCaret(Window
, &rcCaret
, flags
);
1437 Result
= UserScrollDC( hDC
,
1443 prcUnsafeUpdate
? &rcUpdate
: NULL
);
1445 UserReleaseDC(Window
, hDC
, FALSE
);
1448 * Take into account the fact that some damage may have occurred during
1452 hrgnTemp
= IntSysCreateRectRgn(0, 0, 0, 0);
1453 if (co_UserGetUpdateRgn(Window
, hrgnTemp
, FALSE
) != NULLREGION
)
1455 HRGN hrgnClip
= IntSysCreateRectRgnIndirect(&rcClip
);
1456 NtGdiOffsetRgn(hrgnTemp
, dx
, dy
);
1457 NtGdiCombineRgn(hrgnTemp
, hrgnTemp
, hrgnClip
, RGN_AND
);
1458 co_UserRedrawWindow(Window
, NULL
, hrgnTemp
, RDW_INVALIDATE
| RDW_ERASE
);
1459 REGION_FreeRgnByHandle(hrgnClip
);
1461 REGION_FreeRgnByHandle(hrgnTemp
);
1463 if (flags
& SW_SCROLLCHILDREN
)
1465 PWINDOW_OBJECT Child
;
1468 USER_REFERENCE_ENTRY WndRef
;
1471 IntGetClientOrigin(Window
, &ClientOrigin
);
1472 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
1474 rcChild
= Child
->Wnd
->rcWindow
;
1475 rcChild
.left
-= ClientOrigin
.x
;
1476 rcChild
.top
-= ClientOrigin
.y
;
1477 rcChild
.right
-= ClientOrigin
.x
;
1478 rcChild
.bottom
-= ClientOrigin
.y
;
1480 if (! prcUnsafeScroll
|| RECTL_bIntersectRect(&rcDummy
, &rcChild
, &rcScroll
))
1482 UserRefObjectCo(Child
, &WndRef
);
1483 co_WinPosSetWindowPos(Child
, 0, rcChild
.left
+ dx
, rcChild
.top
+ dy
, 0, 0,
1484 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
|
1486 UserDerefObjectCo(Child
);
1491 if (flags
& (SW_INVALIDATE
| SW_ERASE
))
1493 co_UserRedrawWindow(Window
, NULL
, hrgnOwn
, RDW_INVALIDATE
| RDW_ERASE
|
1494 ((flags
& SW_ERASE
) ? RDW_ERASENOW
: 0) |
1495 ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0));
1498 if ((CaretWnd
= UserGetWindowObject(hwndCaret
)))
1500 UserRefObjectCo(CaretWnd
, &CaretRef
);
1502 co_IntSetCaretPos(rcCaret
.left
+ dx
, rcCaret
.top
+ dy
);
1503 co_UserShowCaret(CaretWnd
);
1505 UserDerefObjectCo(CaretWnd
);
1508 if (prcUnsafeUpdate
)
1512 /* Probe here, to not fail on invalid pointer before scrolling */
1513 ProbeForWrite(prcUnsafeUpdate
, sizeof(*prcUnsafeUpdate
), 1);
1514 *prcUnsafeUpdate
= rcUpdate
;
1516 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1518 Status
= _SEH2_GetExceptionCode();
1522 if (!NT_SUCCESS(Status
))
1524 SetLastNtError(Status
);
1532 if (hrgnOwn
&& !hrgnUpdate
)
1534 REGION_FreeRgnByHandle(hrgnOwn
);
1538 UserDerefObjectCo(Window
);
1540 DPRINT("Leave NtUserScrollWindowEx, ret=%i\n",_ret_
);
1547 UserDrawSysMenuButton(
1548 PWINDOW_OBJECT pWnd
,
1554 PCURICON_OBJECT pIcon
;
1556 ASSERT(pWnd
&& lpRc
);
1558 /* Get the icon to draw. We don't care about WM_GETICON here. */
1560 hIcon
= pWnd
->Wnd
->pcls
->hIconSm
;
1564 DPRINT("Wnd class has no small icon.\n");
1565 hIcon
= pWnd
->Wnd
->pcls
->hIcon
;
1570 DPRINT("Wnd class hasn't any icon.\n");
1571 //FIXME: Draw "winlogo" icon.
1575 if(!(pIcon
= UserGetCurIconObject(hIcon
)))
1577 DPRINT1("UserGetCurIconObject() failed!\n");
1581 return UserDrawIconEx(hDc
, lpRc
->left
, lpRc
->top
, pIcon
,
1582 UserGetSystemMetrics(SM_CXSMICON
),
1583 UserGetSystemMetrics(SM_CYSMICON
),
1584 0, NULL
, DI_NORMAL
);
1588 UserDrawCaptionText(
1590 const PUNICODE_STRING Text
,
1594 HFONT hOldFont
= NULL
, hFont
= NULL
;
1595 COLORREF OldTextColor
;
1596 NONCLIENTMETRICSW nclm
;
1600 DPRINT("%s:", __FUNCTION__
);
1601 for(i
= 0; i
< Text
->Length
/sizeof(WCHAR
); i
++)
1602 DbgPrint("%C", Text
->Buffer
[i
]);
1603 DbgPrint(", %d\n", Text
->Length
/sizeof(WCHAR
));
1606 nclm
.cbSize
= sizeof(nclm
);
1607 if(!UserSystemParametersInfo(SPI_GETNONCLIENTMETRICS
,
1608 sizeof(NONCLIENTMETRICS
), &nclm
, 0))
1610 DPRINT1("%s: UserSystemParametersInfo() failed!\n", __FUNCTION__
);
1614 IntGdiSetBkMode(hDc
, TRANSPARENT
);
1616 if(uFlags
& DC_SMALLCAP
)
1617 Status
= TextIntCreateFontIndirect(&nclm
.lfSmCaptionFont
, &hFont
);
1618 else Status
= TextIntCreateFontIndirect(&nclm
.lfCaptionFont
, &hFont
);
1620 if(!NT_SUCCESS(Status
))
1622 DPRINT1("%s: TextIntCreateFontIndirect() failed! Status: 0x%x\n",
1623 __FUNCTION__
, Status
);
1627 hOldFont
= NtGdiSelectFont(hDc
, hFont
);
1630 DPRINT1("%s: SelectFont() failed!\n", __FUNCTION__
);
1631 GreDeleteObject(hFont
);
1635 if(uFlags
& DC_INBUTTON
)
1636 OldTextColor
= IntGdiSetTextColor(hDc
, IntGetSysColor(COLOR_BTNTEXT
));
1637 else OldTextColor
= IntGdiSetTextColor(hDc
, IntGetSysColor(uFlags
& DC_ACTIVE
1638 ? COLOR_CAPTIONTEXT
: COLOR_INACTIVECAPTIONTEXT
));
1640 //FIXME: If string doesn't fit to rc, truncate it and add ellipsis.
1642 GreExtTextOutW(hDc
, lpRc
->left
,
1643 lpRc
->top
, 0, NULL
, Text
->Buffer
,
1644 Text
->Length
/sizeof(WCHAR
), NULL
, 0);
1646 IntGdiSetTextColor(hDc
, OldTextColor
);
1647 NtGdiSelectFont(hDc
, hOldFont
);
1648 GreDeleteObject(hFont
);
1653 BOOL
UserDrawCaption(
1654 PWINDOW_OBJECT pWnd
,
1659 const PUNICODE_STRING str
,
1663 HBITMAP hMemBmp
= NULL
, hOldBmp
= NULL
;
1664 HBRUSH hOldBrush
= NULL
;
1667 UINT VCenter
= 0, Padding
= 0;
1669 LONG ButtonWidth
, IconWidth
;
1673 //ASSERT(pWnd != NULL);
1678 RECTL_vMakeWellOrdered(lpRc
);
1679 hMemBmp
= NtGdiCreateCompatibleBitmap(hDc
,
1680 lpRc
->right
- lpRc
->left
,
1681 lpRc
->bottom
- lpRc
->top
);
1685 DPRINT1("%s: NtGdiCreateCompatibleBitmap() failed!\n", __FUNCTION__
);
1689 hMemDc
= NtGdiCreateCompatibleDC(hDc
);
1692 DPRINT1("%s: NtGdiCreateCompatibleDC() failed!\n", __FUNCTION__
);
1696 hOldBmp
= NtGdiSelectBitmap(hMemDc
, hMemBmp
);
1699 DPRINT1("%s: NtGdiSelectBitmap() failed!\n", __FUNCTION__
);
1703 Height
= UserGetSystemMetrics(SM_CYCAPTION
) - 1;
1704 VCenter
= (lpRc
->bottom
- lpRc
->top
) / 2;
1705 Padding
= VCenter
- (Height
/ 2);
1707 if ((!hIcon
) && (Wnd
!= NULL
))
1709 HasIcon
= (uFlags
& DC_ICON
) && (Wnd
->style
& WS_SYSMENU
)
1710 && !(uFlags
& DC_SMALLCAP
) && !(Wnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1711 && !(Wnd
->ExStyle
& WS_EX_TOOLWINDOW
);
1714 HasIcon
= (hIcon
!= 0);
1716 IconWidth
= UserGetSystemMetrics(SM_CXSIZE
) + Padding
;
1719 r
.right
= r
.left
+ (lpRc
->right
- lpRc
->left
);
1721 r
.bottom
= r
.top
+ (Height
/ 2);
1723 // Draw the caption background
1724 if(uFlags
& DC_INBUTTON
)
1726 hOldBrush
= NtGdiSelectBrush(hMemDc
,
1727 IntGetSysColorBrush(COLOR_3DFACE
));
1731 DPRINT1("%s: NtGdiSelectBrush() failed!\n", __FUNCTION__
);
1735 if(!NtGdiPatBlt(hMemDc
, 0, 0,
1736 lpRc
->right
- lpRc
->left
,
1737 lpRc
->bottom
- lpRc
->top
,
1740 DPRINT1("%s: NtGdiPatBlt() failed!\n", __FUNCTION__
);
1744 if(HasIcon
) r
.left
+=IconWidth
;
1748 r
.right
= (lpRc
->right
- lpRc
->left
);
1749 if(uFlags
& DC_SMALLCAP
)
1750 ButtonWidth
= UserGetSystemMetrics(SM_CXSMSIZE
) - 2;
1751 else ButtonWidth
= UserGetSystemMetrics(SM_CXSIZE
) - 2;
1753 hOldBrush
= NtGdiSelectBrush(hMemDc
,
1754 IntGetSysColorBrush(uFlags
& DC_ACTIVE
?
1755 COLOR_ACTIVECAPTION
: COLOR_INACTIVECAPTION
));
1759 DPRINT1("%s: NtGdiSelectBrush() failed!\n", __FUNCTION__
);
1763 if(HasIcon
&& (uFlags
& DC_GRADIENT
))
1765 NtGdiPatBlt(hMemDc
, 0, 0,
1767 lpRc
->bottom
- lpRc
->top
,
1773 NtGdiPatBlt(hMemDc
, 0, 0,
1774 lpRc
->right
- lpRc
->left
,
1775 lpRc
->bottom
- lpRc
->top
,
1779 if(uFlags
& DC_GRADIENT
)
1781 static GRADIENT_RECT gcap
= {0, 1};
1787 if(Wnd
->style
& WS_SYSMENU
)
1789 r
.right
-= 3 + ButtonWidth
;
1790 if(!(uFlags
& DC_SMALLCAP
))
1792 if(Wnd
->style
& (WS_MAXIMIZEBOX
| WS_MINIMIZEBOX
))
1793 r
.right
-= 2 + 2 * ButtonWidth
;
1798 //Draw buttons background
1799 if(!NtGdiSelectBrush(hMemDc
,
1800 IntGetSysColorBrush(uFlags
& DC_ACTIVE
?
1801 COLOR_GRADIENTACTIVECAPTION
:COLOR_GRADIENTINACTIVECAPTION
)))
1803 DPRINT1("%s: NtGdiSelectBrush() failed!\n", __FUNCTION__
);
1810 lpRc
->right
- lpRc
->left
- r
.right
,
1811 lpRc
->bottom
- lpRc
->top
,
1816 Colors
[0] = IntGetSysColor((uFlags
& DC_ACTIVE
) ?
1817 COLOR_ACTIVECAPTION
: COLOR_INACTIVECAPTION
);
1819 Colors
[1] = IntGetSysColor((uFlags
& DC_ACTIVE
) ?
1820 COLOR_GRADIENTACTIVECAPTION
: COLOR_GRADIENTINACTIVECAPTION
);
1824 vert
[0].Red
= (WORD
)Colors
[0]<<8;
1825 vert
[0].Green
= (WORD
)Colors
[0] & 0xFF00;
1826 vert
[0].Blue
= (WORD
)(Colors
[0]>>8) & 0xFF00;
1829 vert
[1].x
= r
.right
;
1830 vert
[1].y
= lpRc
->bottom
- lpRc
->top
;
1831 vert
[1].Red
= (WORD
)Colors
[1]<<8;
1832 vert
[1].Green
= (WORD
)Colors
[1] & 0xFF00;
1833 vert
[1].Blue
= (WORD
)(Colors
[1]>>8) & 0xFF00;
1836 if(!GreGradientFill(hMemDc
, vert
, 2, &gcap
,
1837 1, GRADIENT_FILL_RECT_H
))
1839 DPRINT1("%s: IntGdiGradientFill() failed!\n", __FUNCTION__
);
1842 } //if(uFlags & DC_GRADIENT)
1848 r
.left
-= --IconWidth
;
1849 /* FIXME: Draw the Icon when pWnd == NULL but hIcon is valid */
1851 UserDrawSysMenuButton(pWnd
, hMemDc
, &r
, FALSE
);
1853 r
.left
+= IconWidth
;
1860 r
.bottom
= r
.top
+ Height
;
1862 if((uFlags
& DC_TEXT
))
1864 if(!(uFlags
& DC_GRADIENT
))
1866 r
.right
= (lpRc
->right
- lpRc
->left
);
1868 if(uFlags
& DC_SMALLCAP
)
1869 ButtonWidth
= UserGetSystemMetrics(SM_CXSMSIZE
) - 2;
1870 else ButtonWidth
= UserGetSystemMetrics(SM_CXSIZE
) - 2;
1872 if ((Wnd
!= NULL
) && (Wnd
->style
& WS_SYSMENU
))
1874 r
.right
-= 3 + ButtonWidth
;
1875 if(! (uFlags
& DC_SMALLCAP
))
1877 if(Wnd
->style
& (WS_MAXIMIZEBOX
| WS_MINIMIZEBOX
))
1878 r
.right
-= 2 + 2 * ButtonWidth
;
1885 /* FIXME: hFont isn't handled */
1887 UserDrawCaptionText(hMemDc
, str
, &r
, uFlags
);
1888 else if (pWnd
!= NULL
)
1890 UNICODE_STRING ustr
;
1891 ustr
.Buffer
= pWnd
->Wnd
->strName
.Buffer
;
1892 ustr
.Length
= pWnd
->Wnd
->strName
.Length
;
1893 ustr
.MaximumLength
= pWnd
->Wnd
->strName
.MaximumLength
;
1894 UserDrawCaptionText(hMemDc
, &ustr
, &r
, uFlags
);
1898 if(!NtGdiBitBlt(hDc
, lpRc
->left
, lpRc
->top
,
1899 lpRc
->right
- lpRc
->left
, lpRc
->bottom
- lpRc
->top
,
1900 hMemDc
, 0, 0, SRCCOPY
, 0, 0))
1902 DPRINT1("%s: NtGdiBitBlt() failed!\n", __FUNCTION__
);
1909 if (hOldBrush
) NtGdiSelectBrush(hMemDc
, hOldBrush
);
1910 if (hOldBmp
) NtGdiSelectBitmap(hMemDc
, hOldBmp
);
1911 if (hMemBmp
) GreDeleteObject(hMemBmp
);
1912 if (hMemDc
) NtGdiDeleteObjectApp(hMemDc
);
1919 UserRealizePalette(HDC hdc
)
1924 Ret
= IntGdiRealizePalette(hdc
);
1925 if (Ret
) // There was a change.
1927 hWnd
= IntWindowFromDC(hdc
);
1928 if (hWnd
) // Send broadcast if dc is associated with a window.
1929 { // FYI: Thread locked in CallOneParam.
1930 co_IntSendMessage((HWND
)HWND_BROADCAST
, WM_PALETTECHANGED
, (WPARAM
)hWnd
, 0);
1938 NtUserDrawCaptionTemp(
1944 const PUNICODE_STRING str
,
1947 PWINDOW_OBJECT pWnd
= NULL
;
1948 UNICODE_STRING SafeStr
= {0};
1949 NTSTATUS Status
= STATUS_SUCCESS
;
1953 UserEnterExclusive();
1957 if(!(pWnd
= UserGetWindowObject(hWnd
)))
1966 ProbeForRead(lpRc
, sizeof(RECTL
), sizeof(ULONG
));
1967 RtlCopyMemory(&SafeRect
, lpRc
, sizeof(RECTL
));
1970 SafeStr
= ProbeForReadUnicodeString(str
);
1971 if (SafeStr
.Length
!= 0)
1973 ProbeForRead( SafeStr
.Buffer
,
1979 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1981 Status
= _SEH2_GetExceptionCode();
1985 if (Status
!= STATUS_SUCCESS
)
1987 SetLastNtError(Status
);
1993 Ret
= UserDrawCaption(pWnd
, hDC
, &SafeRect
, hFont
, hIcon
, &SafeStr
, uFlags
);
1995 Ret
= UserDrawCaption(pWnd
, hDC
, &SafeRect
, hFont
, hIcon
, NULL
, uFlags
);
2003 NtUserDrawCaption(HWND hWnd
,
2008 return NtUserDrawCaptionTemp(hWnd
, hDC
, lpRc
, 0, 0, NULL
, uFlags
);
2013 NtUserInvalidateRect(
2015 CONST RECT
*lpUnsafeRect
,
2018 return NtUserRedrawWindow(hWnd
, lpUnsafeRect
, NULL
, RDW_INVALIDATE
| (bErase
? RDW_ERASE
: 0));
2023 NtUserInvalidateRgn(
2028 return NtUserRedrawWindow(hWnd
, NULL
, hRgn
, RDW_INVALIDATE
| (bErase
? RDW_ERASE
: 0));
2031 /* ValidateRect gets redirected to NtUserValidateRect:
2032 http://blog.csdn.net/ntdll/archive/2005/10/19/509299.aspx */
2041 return NtUserRedrawWindow(hWnd
, lpRect
, NULL
, RDW_VALIDATE
);
2043 return NtUserRedrawWindow(hWnd
, lpRect
, NULL
, RDW_INVALIDATE
|RDW_ERASE
|RDW_ERASENOW
|RDW_ALLCHILDREN
);