2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * PURPOSE: Window painting function
24 * FILE: subsys/win32k/ntuser/painting.c
25 * PROGRAMER: Filip Navara (xnavara@volny.cz)
27 * 06/06/2001 Created (?)
28 * 18/11/2003 Complete rewrite
31 /* INCLUDES ******************************************************************/
38 /* PRIVATE FUNCTIONS **********************************************************/
41 * @name IntIntersectWithParents
43 * Intersect window rectangle with all parent client rectangles.
46 * Pointer to child window to start intersecting from.
48 * Pointer to rectangle that we want to intersect in screen
49 * coordinates on input and intersected rectangle on output (if TRUE
53 * If any parent is minimized or invisible or the resulting rectangle
54 * is empty then FALSE is returned. Otherwise TRUE is returned.
58 IntIntersectWithParents(PWINDOW_OBJECT Child
, PRECT WindowRect
)
60 PWINDOW_OBJECT ParentWindow
;
62 ParentWindow
= Child
->Parent
;
63 while (ParentWindow
!= NULL
)
65 if (!(ParentWindow
->Style
& WS_VISIBLE
) ||
66 (ParentWindow
->Style
& WS_MINIMIZE
))
71 if (!IntGdiIntersectRect(WindowRect
, WindowRect
, &ParentWindow
->ClientRect
))
76 /* FIXME: Layered windows. */
78 ParentWindow
= ParentWindow
->Parent
;
85 IntValidateParent(PWINDOW_OBJECT Child
, HRGN ValidRegion
)
87 PWINDOW_OBJECT ParentWindow
= Child
->Parent
;
91 if (ParentWindow
->Style
& WS_CLIPCHILDREN
)
94 if (ParentWindow
->UpdateRegion
!= 0)
96 NtGdiCombineRgn(ParentWindow
->UpdateRegion
, ParentWindow
->UpdateRegion
,
97 ValidRegion
, RGN_DIFF
);
98 /* FIXME: If the resulting region is empty, remove fake posted paint message */
101 ParentWindow
= ParentWindow
->Parent
;
106 * @name IntCalcWindowRgn
108 * Get a window or client region.
112 IntCalcWindowRgn(PWINDOW_OBJECT Window
, BOOL Client
)
118 hRgnWindow
= UnsafeIntCreateRectRgnIndirect(&Window
->ClientRect
);
120 hRgnWindow
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
122 if (Window
->WindowRegion
!= NULL
&& !(Window
->Style
& WS_MINIMIZE
))
124 NtGdiOffsetRgn(hRgnWindow
,
125 -Window
->WindowRect
.left
,
126 -Window
->WindowRect
.top
);
127 RgnType
= NtGdiCombineRgn(hRgnWindow
, hRgnWindow
, Window
->WindowRegion
, RGN_AND
);
128 NtGdiOffsetRgn(hRgnWindow
,
129 Window
->WindowRect
.left
,
130 Window
->WindowRect
.top
);
137 * @name IntGetNCUpdateRgn
139 * Get non-client update region of a window and optionally validate it.
142 * Pointer to window to get the NC update region from.
144 * Set to TRUE to force validating the NC update region.
147 * Handle to NC update region. The caller is responsible for deleting
152 IntGetNCUpdateRgn(PWINDOW_OBJECT Window
, BOOL Validate
)
158 if (Window
->UpdateRegion
!= NULL
&&
159 Window
->UpdateRegion
!= (HRGN
)1)
161 hRgnNonClient
= NtGdiCreateRectRgn(0, 0, 0, 0);
162 hRgnWindow
= IntCalcWindowRgn(Window
, TRUE
);
165 * If region creation fails it's safe to fallback to whole
169 if (hRgnNonClient
== NULL
)
174 RgnType
= NtGdiCombineRgn(hRgnNonClient
, Window
->UpdateRegion
,
175 hRgnWindow
, RGN_DIFF
);
176 if (RgnType
== ERROR
)
178 NtGdiDeleteObject(hRgnNonClient
);
181 else if (RgnType
== NULLREGION
)
183 NtGdiDeleteObject(hRgnNonClient
);
188 * Remove the nonclient region from the standard update region if
189 * we were asked for it.
194 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
195 hRgnWindow
, RGN_AND
) == NULLREGION
)
197 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
198 NtGdiDeleteObject(Window
->UpdateRegion
);
199 Window
->UpdateRegion
= NULL
;
200 if (!(Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
))
201 MsqDecPaintCountQueue(Window
->MessageQueue
);
205 NtGdiDeleteObject(hRgnWindow
);
207 return hRgnNonClient
;
211 return Window
->UpdateRegion
;
218 * Internal function used by IntRedrawWindow.
222 co_IntPaintWindows(PWINDOW_OBJECT Window
, ULONG Flags
)
225 HWND hWnd
= Window
->hSelf
;
228 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
230 if (Window
->UpdateRegion
)
232 IntValidateParent(Window
, Window
->UpdateRegion
);
235 if (Flags
& RDW_UPDATENOW
)
237 if (Window
->UpdateRegion
!= NULL
||
238 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
240 co_IntSendMessage(hWnd
, WM_PAINT
, 0, 0);
245 if (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
)
247 TempRegion
= IntGetNCUpdateRgn(Window
, TRUE
);
248 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
249 MsqDecPaintCountQueue(Window
->MessageQueue
);
250 co_IntSendMessage(hWnd
, WM_NCPAINT
, (WPARAM
)TempRegion
, 0);
251 if ((HANDLE
) 1 != TempRegion
&& NULL
!= TempRegion
)
253 /* NOTE: The region can already be deleted! */
254 GDIOBJ_FreeObj(TempRegion
, GDI_OBJECT_TYPE_REGION
| GDI_OBJECT_TYPE_SILENT
);
258 if (Window
->Flags
& WINDOWOBJECT_NEED_ERASEBKGND
)
260 if (Window
->UpdateRegion
)
262 hDC
= UserGetDCEx(Window
, Window
->UpdateRegion
,
263 DCX_CACHE
| DCX_USESTYLE
|
264 DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
);
265 if (co_IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)hDC
, 0))
267 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
269 UserReleaseDC(Window
, hDC
, FALSE
);
276 * Check that the window is still valid at this point
278 if (!IntIsWindow(hWnd
))
284 * Paint child windows.
286 if (!(Flags
& RDW_NOCHILDREN
) && !(Window
->Style
& WS_MINIMIZE
) &&
287 ((Flags
& RDW_ALLCHILDREN
) || !(Window
->Style
& WS_CLIPCHILDREN
)))
291 if ((List
= IntWinListChildren(Window
)))
293 for (phWnd
= List
; *phWnd
; ++phWnd
)
295 Window
= UserGetWindowObject(*phWnd
);
296 if (Window
&& (Window
->Style
& WS_VISIBLE
))
298 UserRefObjectCo(Window
);
299 co_IntPaintWindows(Window
, Flags
);
300 UserDerefObjectCo(Window
);
309 * IntInvalidateWindows
311 * Internal function used by IntRedrawWindow.
315 IntInvalidateWindows(PWINDOW_OBJECT Window
, HRGN hRgn
, ULONG Flags
)
318 BOOL HadPaintMessage
, HadNCPaintMessage
;
319 BOOL HasPaintMessage
, HasNCPaintMessage
;
322 * Clip the given region with window rectangle (or region)
325 if (!Window
->WindowRegion
|| (Window
->Style
& WS_MINIMIZE
))
329 hRgnWindow
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
330 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, hRgnWindow
, RGN_AND
);
331 NtGdiDeleteObject(hRgnWindow
);
336 -Window
->WindowRect
.left
,
337 -Window
->WindowRect
.top
);
338 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, Window
->WindowRegion
, RGN_AND
);
340 Window
->WindowRect
.left
,
341 Window
->WindowRect
.top
);
345 * Save current state of pending updates
348 HadPaintMessage
= Window
->UpdateRegion
!= NULL
||
349 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
;
350 HadNCPaintMessage
= Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
;
353 * Update the region and flags
356 if (Flags
& RDW_INVALIDATE
&& RgnType
!= NULLREGION
)
358 if (Window
->UpdateRegion
== NULL
)
360 Window
->UpdateRegion
= NtGdiCreateRectRgn(0, 0, 0, 0);
361 GDIOBJ_SetOwnership(Window
->UpdateRegion
, NULL
);
364 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
365 hRgn
, RGN_OR
) == NULLREGION
)
367 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
368 NtGdiDeleteObject(Window
->UpdateRegion
);
369 Window
->UpdateRegion
= NULL
;
372 if (Flags
& RDW_FRAME
)
373 Window
->Flags
|= WINDOWOBJECT_NEED_NCPAINT
;
374 if (Flags
& RDW_ERASE
)
375 Window
->Flags
|= WINDOWOBJECT_NEED_ERASEBKGND
;
380 if (Flags
& RDW_VALIDATE
&& RgnType
!= NULLREGION
)
382 if (Window
->UpdateRegion
!= NULL
)
384 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
385 hRgn
, RGN_DIFF
) == NULLREGION
)
387 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
388 NtGdiDeleteObject(Window
->UpdateRegion
);
389 Window
->UpdateRegion
= NULL
;
393 if (Window
->UpdateRegion
== NULL
)
394 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
395 if (Flags
& RDW_NOFRAME
)
396 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
397 if (Flags
& RDW_NOERASE
)
398 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
401 if (Flags
& RDW_INTERNALPAINT
)
403 Window
->Flags
|= WINDOWOBJECT_NEED_INTERNALPAINT
;
406 if (Flags
& RDW_NOINTERNALPAINT
)
408 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
412 * Process children if needed
415 if (!(Flags
& RDW_NOCHILDREN
) && !(Window
->Style
& WS_MINIMIZE
) &&
416 ((Flags
& RDW_ALLCHILDREN
) || !(Window
->Style
& WS_CLIPCHILDREN
)))
418 PWINDOW_OBJECT Child
;
420 for (Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
422 if (Child
->Style
& WS_VISIBLE
)
425 * Recursive call to update children UpdateRegion
427 HRGN hRgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
428 NtGdiCombineRgn(hRgnTemp
, hRgn
, 0, RGN_COPY
);
429 IntInvalidateWindows(Child
, hRgnTemp
, Flags
);
430 NtGdiDeleteObject(hRgnTemp
);
437 * Fake post paint messages to window message queue if needed
440 HasPaintMessage
= Window
->UpdateRegion
!= NULL
||
441 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
;
442 HasNCPaintMessage
= Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
;
444 if (HasPaintMessage
!= HadPaintMessage
)
447 MsqDecPaintCountQueue(Window
->MessageQueue
);
449 MsqIncPaintCountQueue(Window
->MessageQueue
);
452 if (HasNCPaintMessage
!= HadNCPaintMessage
)
454 if (HadNCPaintMessage
)
455 MsqDecPaintCountQueue(Window
->MessageQueue
);
457 MsqIncPaintCountQueue(Window
->MessageQueue
);
463 * IntIsWindowDrawable
466 * Window is drawable when it is visible and all parents are not
471 IntIsWindowDrawable(PWINDOW_OBJECT Window
)
475 for (Wnd
= Window
; Wnd
!= NULL
; Wnd
= Wnd
->Parent
)
477 if (!(Wnd
->Style
& WS_VISIBLE
) ||
478 ((Wnd
->Style
& WS_MINIMIZE
) && (Wnd
!= Window
)))
490 * Internal version of NtUserRedrawWindow that takes WINDOW_OBJECT as
495 co_UserRedrawWindow(PWINDOW_OBJECT Window
, const RECT
* UpdateRect
, HRGN UpdateRgn
,
502 * Validation of passed parameters.
505 if (!IntIsWindowDrawable(Window
) ||
506 (Flags
& (RDW_VALIDATE
| RDW_INVALIDATE
)) ==
507 (RDW_VALIDATE
| RDW_INVALIDATE
))
514 * Transform the parameters UpdateRgn and UpdateRect into
515 * a region hRgn specified in screen coordinates.
518 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
))
520 if (UpdateRgn
!= NULL
)
522 hRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
523 if (NtGdiCombineRgn(hRgn
, UpdateRgn
, NULL
, RGN_COPY
) == NULLREGION
)
524 NtGdiDeleteObject(hRgn
);
526 NtGdiOffsetRgn(hRgn
, Window
->ClientRect
.left
, Window
->ClientRect
.top
);
528 else if (UpdateRect
!= NULL
)
530 if (!IntGdiIsEmptyRect(UpdateRect
))
532 hRgn
= UnsafeIntCreateRectRgnIndirect((RECT
*)UpdateRect
);
533 NtGdiOffsetRgn(hRgn
, Window
->ClientRect
.left
, Window
->ClientRect
.top
);
536 else if ((Flags
& (RDW_INVALIDATE
| RDW_FRAME
)) == (RDW_INVALIDATE
| RDW_FRAME
) ||
537 (Flags
& (RDW_VALIDATE
| RDW_NOFRAME
)) == (RDW_VALIDATE
| RDW_NOFRAME
))
539 if (!IntGdiIsEmptyRect(&Window
->WindowRect
))
540 hRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
544 if (!IntGdiIsEmptyRect(&Window
->ClientRect
))
545 hRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->ClientRect
);
551 * Adjust the window update region depending on hRgn and flags.
554 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
| RDW_INTERNALPAINT
| RDW_NOINTERNALPAINT
) &&
557 IntInvalidateWindows(Window
, hRgn
, Flags
);
562 * Repaint and erase windows if needed.
565 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
567 co_IntPaintWindows(Window
, Flags
);
577 NtGdiDeleteObject(hRgn
);
584 IntIsWindowDirty(PWINDOW_OBJECT Window
)
586 return (Window
->Style
& WS_VISIBLE
) &&
587 ((Window
->UpdateRegion
!= NULL
) ||
588 (Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
) ||
589 (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
));
593 IntFindWindowToRepaint(PWINDOW_OBJECT Window
, PW32THREAD Thread
)
596 PWINDOW_OBJECT TempWindow
;
598 for (; Window
!= NULL
; Window
= Window
->NextSibling
)
600 if (IntWndBelongsToThread(Window
, Thread
) &&
601 IntIsWindowDirty(Window
))
603 /* Make sure all non-transparent siblings are already drawn. */
604 if (Window
->ExStyle
& WS_EX_TRANSPARENT
)
606 for (TempWindow
= Window
->NextSibling
; TempWindow
!= NULL
;
607 TempWindow
= TempWindow
->NextSibling
)
609 if (!(TempWindow
->ExStyle
& WS_EX_TRANSPARENT
) &&
610 IntWndBelongsToThread(TempWindow
, Thread
) &&
611 IntIsWindowDirty(TempWindow
))
613 return TempWindow
->hSelf
;
618 return Window
->hSelf
;
621 if (Window
->FirstChild
)
623 hChild
= IntFindWindowToRepaint(Window
->FirstChild
, Thread
);
633 IntGetPaintMessage(HWND hWnd
, UINT MsgFilterMin
, UINT MsgFilterMax
,
634 PW32THREAD Thread
, MSG
*Message
, BOOL Remove
)
636 PUSER_MESSAGE_QUEUE MessageQueue
= (PUSER_MESSAGE_QUEUE
)Thread
->MessageQueue
;
638 if (!MessageQueue
->PaintCount
)
641 if ((MsgFilterMin
!= 0 || MsgFilterMax
!= 0) &&
642 (MsgFilterMin
> WM_PAINT
|| MsgFilterMax
< WM_PAINT
))
645 Message
->hwnd
= IntFindWindowToRepaint(UserGetDesktopWindow(), PsGetWin32Thread());
647 if (Message
->hwnd
== NULL
)
649 DPRINT1("PAINTING BUG: Thread marked as containing dirty windows, but no dirty windows found!\n");
653 if (hWnd
!= NULL
&& Message
->hwnd
!= hWnd
)
656 Message
->message
= WM_PAINT
;
657 Message
->wParam
= Message
->lParam
= 0;
664 co_IntFixCaret(PWINDOW_OBJECT Window
, LPRECT lprc
, UINT flags
)
666 PDESKTOP_OBJECT Desktop
;
667 PTHRDCARETINFO CaretInfo
;
669 PWINDOW_OBJECT WndCaret
;
671 ASSERT_REFS_CO(Window
);
673 Desktop
= PsGetCurrentThread()->Tcb
.Win32Thread
->Desktop
;
674 CaretInfo
= ((PUSER_MESSAGE_QUEUE
)Desktop
->ActiveMessageQueue
)->CaretInfo
;
675 hWndCaret
= CaretInfo
->hWnd
;
677 WndCaret
= UserGetWindowObject(hWndCaret
);
679 //fix: check for WndCaret can be null
680 if (WndCaret
== Window
||
681 ((flags
& SW_SCROLLCHILDREN
) && IntIsChildWindow(Window
, WndCaret
)))
683 POINT pt
, FromOffset
, ToOffset
, Offset
;
686 pt
.x
= CaretInfo
->Pos
.x
;
687 pt
.y
= CaretInfo
->Pos
.y
;
688 IntGetClientOrigin(WndCaret
, &FromOffset
);
689 IntGetClientOrigin(Window
, &ToOffset
);
690 Offset
.x
= FromOffset
.x
- ToOffset
.x
;
691 Offset
.y
= FromOffset
.y
- ToOffset
.y
;
694 rcCaret
.right
= pt
.x
+ CaretInfo
->Size
.cx
;
695 rcCaret
.bottom
= pt
.y
+ CaretInfo
->Size
.cy
;
696 if (IntGdiIntersectRect(lprc
, lprc
, &rcCaret
))
708 /* PUBLIC FUNCTIONS ***********************************************************/
718 NtUserBeginPaint(HWND hWnd
, PAINTSTRUCT
* UnsafePs
)
720 PWINDOW_OBJECT Window
= NULL
;
726 DPRINT("Enter NtUserBeginPaint\n");
727 UserEnterExclusive();
729 if (!(Window
= UserGetWindowObject(hWnd
)))
734 UserRefObjectCo(Window
);
736 co_UserHideCaret(Window
);
738 if (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
)
742 hRgn
= IntGetNCUpdateRgn(Window
, FALSE
);
743 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
744 MsqDecPaintCountQueue(Window
->MessageQueue
);
745 co_IntSendMessage(hWnd
, WM_NCPAINT
, (WPARAM
)hRgn
, 0);
746 if (hRgn
!= (HANDLE
)1 && hRgn
!= NULL
)
748 /* NOTE: The region can already by deleted! */
749 GDIOBJ_FreeObj(hRgn
, GDI_OBJECT_TYPE_REGION
| GDI_OBJECT_TYPE_SILENT
);
753 RtlZeroMemory(&Ps
, sizeof(PAINTSTRUCT
));
755 Ps
.hdc
= UserGetDCEx(Window
, Window
->UpdateRegion
, DCX_INTERSECTRGN
| DCX_USESTYLE
);
761 if (Window
->UpdateRegion
!= NULL
)
763 MsqDecPaintCountQueue(Window
->MessageQueue
);
764 Rgn
= RGNDATA_LockRgn(Window
->UpdateRegion
);
767 UnsafeIntGetRgnBox(Rgn
, &Ps
.rcPaint
);
768 RGNDATA_UnlockRgn(Rgn
);
769 IntGdiOffsetRect(&Ps
.rcPaint
,
770 -Window
->ClientRect
.left
,
771 -Window
->ClientRect
.top
);
775 IntGetClientRect(Window
, &Ps
.rcPaint
);
777 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
778 Window
->UpdateRegion
= NULL
;
782 if (Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
783 MsqDecPaintCountQueue(Window
->MessageQueue
);
785 IntGetClientRect(Window
, &Ps
.rcPaint
);
788 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
790 if (Window
->Flags
& WINDOWOBJECT_NEED_ERASEBKGND
)
792 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
793 Ps
.fErase
= !co_IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)Ps
.hdc
, 0);
800 Status
= MmCopyToCaller(UnsafePs
, &Ps
, sizeof(PAINTSTRUCT
));
801 if (! NT_SUCCESS(Status
))
803 SetLastNtError(Status
);
810 if (Window
) UserDerefObjectCo(Window
);
812 DPRINT("Leave NtUserBeginPaint, ret=%i\n",_ret_
);
826 NtUserEndPaint(HWND hWnd
, CONST PAINTSTRUCT
* lPs
)
828 PWINDOW_OBJECT Window
;
829 DECLARE_RETURN(BOOL
);
831 DPRINT("Enter NtUserEndPaint\n");
832 UserEnterExclusive();
834 if (!(Window
= UserGetWindowObject(hWnd
)))
839 UserReleaseDC(Window
, lPs
->hdc
, TRUE
);
841 UserRefObjectCo(Window
);
842 co_UserShowCaret(Window
);
843 UserDerefObjectCo(Window
);
848 DPRINT("Leave NtUserEndPaint, ret=%i\n",_ret_
);
855 co_UserGetUpdateRgn(PWINDOW_OBJECT Window
, HRGN hRgn
, BOOL bErase
)
859 ASSERT_REFS_CO(Window
);
861 if (Window
->UpdateRegion
== NULL
)
863 RegionType
= (NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0) ? NULLREGION
: ERROR
);
867 RegionType
= NtGdiCombineRgn(hRgn
, Window
->UpdateRegion
, hRgn
, RGN_COPY
);
868 NtGdiOffsetRgn(hRgn
, -Window
->ClientRect
.left
, -Window
->ClientRect
.top
);
871 if (bErase
&& RegionType
!= NULLREGION
&& RegionType
!= ERROR
)
873 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
886 NtUserGetUpdateRgn(HWND hWnd
, HRGN hRgn
, BOOL bErase
)
889 PWINDOW_OBJECT Window
;
892 DPRINT("Enter NtUserGetUpdateRgn\n");
893 UserEnterExclusive();
895 if (!(Window
= UserGetWindowObject(hWnd
)))
900 UserRefObjectCo(Window
);
901 ret
= co_UserGetUpdateRgn(Window
, hRgn
, bErase
);
902 UserDerefObjectCo(Window
);
907 DPRINT("Leave NtUserGetUpdateRgn, ret=%i\n",_ret_
);
913 * NtUserGetUpdateRect
920 NtUserGetUpdateRect(HWND hWnd
, LPRECT UnsafeRect
, BOOL bErase
)
922 PWINDOW_OBJECT Window
;
928 DECLARE_RETURN(BOOL
);
930 DPRINT("Enter NtUserGetUpdateRect\n");
931 UserEnterExclusive();
933 if (!(Window
= UserGetWindowObject(hWnd
)))
938 if (Window
->UpdateRegion
== NULL
)
940 Rect
.left
= Rect
.top
= Rect
.right
= Rect
.bottom
= 0;
944 RgnData
= RGNDATA_LockRgn(Window
->UpdateRegion
);
945 ASSERT(RgnData
!= NULL
);
946 RegionType
= UnsafeIntGetRgnBox(RgnData
, &Rect
);
947 ASSERT(RegionType
!= ERROR
);
948 RGNDATA_UnlockRgn(RgnData
);
950 AlwaysPaint
= (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
) ||
951 (Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
);
953 if (bErase
&& Rect
.left
< Rect
.right
&& Rect
.top
< Rect
.bottom
)
955 UserRefObjectCo(Window
);
956 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
957 UserDerefObjectCo(Window
);
960 if (UnsafeRect
!= NULL
)
962 Status
= MmCopyToCaller(UnsafeRect
, &Rect
, sizeof(RECT
));
963 if (!NT_SUCCESS(Status
))
965 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
970 RETURN( (Rect
.left
< Rect
.right
&& Rect
.top
< Rect
.bottom
) || AlwaysPaint
);
973 DPRINT("Leave NtUserGetUpdateRect, ret=%i\n",_ret_
);
986 NtUserRedrawWindow(HWND hWnd
, CONST RECT
*lprcUpdate
, HRGN hrgnUpdate
,
992 DECLARE_RETURN(BOOL
);
994 DPRINT("Enter NtUserRedrawWindow\n");
995 UserEnterExclusive();
997 if (!(Wnd
= UserGetWindowObject(hWnd
? hWnd
: IntGetDesktopWindow())))
1002 if (lprcUpdate
!= NULL
)
1004 Status
= MmCopyFromCaller(&SafeUpdateRect
, (PRECT
)lprcUpdate
,
1007 if (!NT_SUCCESS(Status
))
1009 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1014 UserRefObjectCo(Wnd
);
1016 Status
= co_UserRedrawWindow(Wnd
, NULL
== lprcUpdate
? NULL
: &SafeUpdateRect
,
1019 UserDerefObjectCo(Wnd
);
1021 if (!NT_SUCCESS(Status
))
1023 /* IntRedrawWindow fails only in case that flags are invalid */
1024 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1031 DPRINT("Leave NtUserRedrawWindow, ret=%i\n",_ret_
);
1040 UserScrollDC(HDC hDC
, INT dx
, INT dy
, const RECT
*lprcScroll
,
1041 const RECT
*lprcClip
, HRGN hrgnUpdate
, LPRECT lprcUpdate
)
1043 RECT rSrc
, rClipped_src
, rClip
, rDst
, offset
;
1047 * Compute device clipping region (in device coordinates).
1050 DC
= DC_LockDc(hDC
);
1058 IntGdiGetClipBox(hDC
, &rSrc
);
1059 IntLPtoDP(DC
, (LPPOINT
)&rSrc
, 2);
1064 IntGdiGetClipBox(hDC
, &rClip
);
1065 IntLPtoDP(DC
, (LPPOINT
)&rClip
, 2);
1067 IntGdiIntersectRect(&rClipped_src
, &rSrc
, &rClip
);
1069 rDst
= rClipped_src
;
1070 IntGdiSetRect(&offset
, 0, 0, dx
, dy
);
1071 IntLPtoDP(DC
, (LPPOINT
)&offset
, 2);
1072 IntGdiOffsetRect(&rDst
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
1073 IntGdiIntersectRect(&rDst
, &rDst
, &rClip
);
1076 * Copy bits, if possible.
1079 if (rDst
.bottom
> rDst
.top
&& rDst
.right
> rDst
.left
)
1081 RECT rDst_lp
= rDst
, rSrc_lp
= rDst
;
1083 IntGdiOffsetRect(&rSrc_lp
, offset
.left
- offset
.right
, offset
.top
- offset
.bottom
);
1084 IntDPtoLP(DC
, (LPPOINT
)&rDst_lp
, 2);
1085 IntDPtoLP(DC
, (LPPOINT
)&rSrc_lp
, 2);
1088 if (!NtGdiBitBlt(hDC
, rDst_lp
.left
, rDst_lp
.top
, rDst_lp
.right
- rDst_lp
.left
,
1089 rDst_lp
.bottom
- rDst_lp
.top
, hDC
, rSrc_lp
.left
, rSrc_lp
.top
,
1099 * Compute update areas. This is the clipped source or'ed with the
1100 * unclipped source translated minus the clipped src translated (rDst)
1101 * all clipped to rClip.
1104 if (hrgnUpdate
|| lprcUpdate
)
1106 HRGN hRgn
= hrgnUpdate
, hRgn2
;
1109 NtGdiSetRectRgn(hRgn
, rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
1111 hRgn
= NtGdiCreateRectRgn(rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
1113 hRgn2
= UnsafeIntCreateRectRgnIndirect(&rSrc
);
1114 NtGdiOffsetRgn(hRgn2
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
1115 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_OR
);
1117 NtGdiSetRectRgn(hRgn2
, rDst
.left
, rDst
.top
, rDst
.right
, rDst
.bottom
);
1118 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_DIFF
);
1120 NtGdiSetRectRgn(hRgn2
, rClip
.left
, rClip
.top
, rClip
.right
, rClip
.bottom
);
1121 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_AND
);
1125 NtGdiGetRgnBox(hRgn
, lprcUpdate
);
1127 /* Put the lprcUpdate in logical coordinate */
1128 NtGdiDPtoLP(hDC
, (LPPOINT
)lprcUpdate
, 2);
1131 NtGdiDeleteObject(hRgn
);
1132 NtGdiDeleteObject(hRgn2
);
1148 NtUserScrollDC(HDC hDC
, INT dx
, INT dy
, const RECT
*lprcScroll
,
1149 const RECT
*lprcClip
, HRGN hrgnUpdate
, LPRECT lprcUpdate
)
1151 DECLARE_RETURN(DWORD
);
1153 DPRINT("Enter NtUserScrollDC\n");
1154 UserEnterExclusive();
1156 RETURN( UserScrollDC(hDC
, dx
, dy
, lprcScroll
, lprcClip
, hrgnUpdate
, lprcUpdate
));
1159 DPRINT("Leave NtUserScrollDC, ret=%i\n",_ret_
);
1166 * NtUserScrollWindowEx
1173 NtUserScrollWindowEx(HWND hWnd
, INT dx
, INT dy
, const RECT
*UnsafeRect
,
1174 const RECT
*UnsafeClipRect
, HRGN hrgnUpdate
, LPRECT rcUpdate
, UINT flags
)
1176 RECT rc
, cliprc
, caretrc
, rect
, clipRect
;
1178 PWINDOW_OBJECT Window
= NULL
, CaretWnd
;
1182 BOOL bUpdate
= (rcUpdate
|| hrgnUpdate
|| flags
& (SW_INVALIDATE
| SW_ERASE
));
1183 BOOL bOwnRgn
= TRUE
;
1185 DECLARE_RETURN(DWORD
);
1187 DPRINT("Enter NtUserScrollWindowEx\n");
1188 UserEnterExclusive();
1190 Window
= UserGetWindowObject(hWnd
);
1191 if (!Window
|| !IntIsWindowDrawable(Window
))
1193 Window
= NULL
; /* prevent deref at cleanup */
1196 UserRefObjectCo(Window
);
1198 IntGetClientRect(Window
, &rc
);
1200 if (NULL
!= UnsafeRect
)
1202 Status
= MmCopyFromCaller(&rect
, UnsafeRect
, sizeof(RECT
));
1203 if (! NT_SUCCESS(Status
))
1205 SetLastNtError(Status
);
1208 IntGdiIntersectRect(&rc
, &rc
, &rect
);
1211 if (NULL
!= UnsafeClipRect
)
1213 Status
= MmCopyFromCaller(&clipRect
, UnsafeClipRect
, sizeof(RECT
));
1214 if (! NT_SUCCESS(Status
))
1216 SetLastNtError(Status
);
1219 IntGdiIntersectRect(&cliprc
, &rc
, &clipRect
);
1224 if (cliprc
.right
<= cliprc
.left
|| cliprc
.bottom
<= cliprc
.top
||
1225 (dx
== 0 && dy
== 0))
1227 RETURN( NULLREGION
);
1231 hwndCaret
= co_IntFixCaret(Window
, &caretrc
, flags
);
1236 hrgnUpdate
= NtGdiCreateRectRgn(0, 0, 0, 0);
1238 hDC
= UserGetDCEx(Window
, 0, DCX_CACHE
| DCX_USESTYLE
);
1241 UserScrollDC(hDC
, dx
, dy
, &rc
, &cliprc
, hrgnUpdate
, rcUpdate
);
1242 UserReleaseDC(Window
, hDC
, FALSE
);
1246 * Take into account the fact that some damage may have occurred during
1250 hrgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
1251 Result
= co_UserGetUpdateRgn(Window
, hrgnTemp
, FALSE
);
1252 if (Result
!= NULLREGION
)
1254 HRGN hrgnClip
= UnsafeIntCreateRectRgnIndirect(&cliprc
);
1255 NtGdiOffsetRgn(hrgnTemp
, dx
, dy
);
1256 NtGdiCombineRgn(hrgnTemp
, hrgnTemp
, hrgnClip
, RGN_AND
);
1257 co_UserRedrawWindow(Window
, NULL
, hrgnTemp
, RDW_INVALIDATE
| RDW_ERASE
);
1258 NtGdiDeleteObject(hrgnClip
);
1261 NtGdiDeleteObject(hrgnTemp
);
1263 if (flags
& SW_SCROLLCHILDREN
)
1265 HWND
*List
= IntWinListChildren(Window
);
1273 IntGetClientOrigin(Window
, &ClientOrigin
);
1274 for (i
= 0; List
[i
]; i
++)
1276 if (!(Wnd
= UserGetWindowObject(List
[i
])))
1279 r
= Wnd
->WindowRect
;
1280 r
.left
-= ClientOrigin
.x
;
1281 r
.top
-= ClientOrigin
.y
;
1282 r
.right
-= ClientOrigin
.x
;
1283 r
.bottom
-= ClientOrigin
.y
;
1285 if (! UnsafeRect
|| IntGdiIntersectRect(&dummy
, &r
, &rc
))
1287 UserRefObjectCo(Wnd
);
1288 co_WinPosSetWindowPos(Wnd
, 0, r
.left
+ dx
, r
.top
+ dy
, 0, 0,
1289 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
|
1291 UserDerefObjectCo(Wnd
);
1299 if (flags
& (SW_INVALIDATE
| SW_ERASE
))
1300 co_UserRedrawWindow(Window
, NULL
, hrgnUpdate
, RDW_INVALIDATE
| RDW_ERASE
|
1301 ((flags
& SW_ERASE
) ? RDW_ERASENOW
: 0) |
1302 ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0));
1304 if (bOwnRgn
&& hrgnUpdate
)
1305 NtGdiDeleteObject(hrgnUpdate
);
1307 if ((CaretWnd
= UserGetWindowObject(hwndCaret
)))
1309 UserRefObjectCo(CaretWnd
);
1311 co_IntSetCaretPos(caretrc
.left
+ dx
, caretrc
.top
+ dy
);
1312 co_UserShowCaret(CaretWnd
);
1314 UserDerefObjectCo(CaretWnd
);
1321 UserDerefObjectCo(Window
);
1323 DPRINT("Leave NtUserScrollWindowEx, ret=%i\n",_ret_
);