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.
19 * $Id: painting.c,v 1.52 2003/12/23 21:33:25 weiden Exp $
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 ******************************************************************/
33 #include <ddk/ntddk.h>
34 #include <internal/safe.h>
35 #include <win32k/win32k.h>
36 #include <include/object.h>
37 #include <include/guicheck.h>
38 #include <include/window.h>
39 #include <include/desktop.h>
40 #include <include/winpos.h>
41 #include <include/class.h>
42 #include <include/caret.h>
43 #include <include/error.h>
44 #include <include/winsta.h>
46 #include <include/painting.h>
47 #include <user32/wininternal.h>
48 #include <include/rect.h>
49 #include <win32k/coord.h>
50 #include <win32k/region.h>
51 #include <include/vis.h>
52 #include <include/intgdi.h>
57 /* PRIVATE FUNCTIONS **********************************************************/
60 IntValidateParent(PWINDOW_OBJECT Child
)
63 PWINDOW_OBJECT ParentWindow
;
65 Parent
= NtUserGetAncestor(Child
->Self
, GA_PARENT
);
66 while (Parent
&& Parent
!= IntGetDesktopWindow())
68 ParentWindow
= IntGetWindowObject(Parent
);
69 if (ParentWindow
&& !(ParentWindow
->Style
& WS_CLIPCHILDREN
))
71 if (ParentWindow
->UpdateRegion
!= 0)
76 * We must offset the child region by the offset of the
77 * child rect in the parent.
79 OffsetX
= Child
->WindowRect
.left
- ParentWindow
->WindowRect
.left
;
80 OffsetY
= Child
->WindowRect
.top
- ParentWindow
->WindowRect
.top
;
81 NtGdiOffsetRgn(Child
->UpdateRegion
, OffsetX
, OffsetY
);
82 NtGdiCombineRgn(ParentWindow
->UpdateRegion
, ParentWindow
->UpdateRegion
,
83 Child
->UpdateRegion
, RGN_DIFF
);
84 /* FIXME: If the resulting region is empty, remove fake posted paint message */
85 NtGdiOffsetRgn(Child
->UpdateRegion
, -OffsetX
, -OffsetY
);
88 IntReleaseWindowObject(ParentWindow
);
89 Parent
= NtUserGetAncestor(Parent
, GA_PARENT
);
94 * IntGetNCUpdateRegion
96 * Get nonclient part of window update region.
99 * Handle to region that represents invalid nonclient window area. The
100 * caller is responsible for deleting it.
103 * This function also marks the nonclient update region of window
104 * as valid, clears the WINDOWOBJECT_NEED_NCPAINT flag and removes
105 * the fake paint message from message queue if the Remove is set
110 IntGetNCUpdateRegion(PWINDOW_OBJECT Window
, BOOL Remove
)
115 WindowRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->ClientRect
);
116 NtGdiOffsetRgn(WindowRgn
,
117 -Window
->WindowRect
.left
,
118 -Window
->WindowRect
.top
);
119 NonclientRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
120 if (NtGdiCombineRgn(NonclientRgn
, Window
->UpdateRegion
,
121 WindowRgn
, RGN_DIFF
) == NULLREGION
)
123 NtGdiDeleteObject(NonclientRgn
);
128 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
129 WindowRgn
, RGN_AND
) == NULLREGION
)
131 NtGdiDeleteObject(Window
->UpdateRegion
);
132 Window
->UpdateRegion
= NULL
;
134 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
135 MsqDecPaintCountQueue(Window
->MessageQueue
);
144 * Internal function used by IntRedrawWindow.
148 IntPaintWindows(PWINDOW_OBJECT Window
, ULONG Flags
)
151 HWND hWnd
= Window
->Self
;
153 if (! (Window
->Style
& WS_VISIBLE
))
158 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
160 if (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
)
162 IntSendMessage(hWnd
, WM_NCPAINT
, (WPARAM
)IntGetNCUpdateRegion(Window
, TRUE
), 0, TRUE
);
165 if (Window
->Flags
& WINDOWOBJECT_NEED_ERASEBKGND
)
167 if (Window
->UpdateRegion
)
169 hDC
= NtUserGetDCEx(hWnd
, 0, DCX_CACHE
| DCX_USESTYLE
|
170 DCX_INTERSECTUPDATE
);
173 if (IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)hDC
, 0, TRUE
))
175 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
177 NtUserReleaseDC(hWnd
, hDC
);
182 if (Flags
& RDW_UPDATENOW
)
184 if (Window
->UpdateRegion
!= NULL
||
185 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
187 IntSendMessage(hWnd
, WM_PAINT
, 0, 0, TRUE
);
188 if (Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
190 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
191 if (Window
->UpdateRegion
== NULL
)
193 MsqDecPaintCountQueue(Window
->MessageQueue
);
201 * Check that the window is still valid at this point
204 if (! IntIsWindow(hWnd
))
210 * Paint child windows.
212 if (!(Flags
& RDW_NOCHILDREN
) && !(Window
->Style
& WS_MINIMIZE
) &&
213 ((Flags
& RDW_ALLCHILDREN
) || !(Window
->Style
& WS_CLIPCHILDREN
)) &&
214 ! IntIsDesktopWindow(Window
))
218 if ((List
= IntWinListChildren(Window
)))
220 for (phWnd
= List
; *phWnd
; ++phWnd
)
222 Window
= IntGetWindowObject(*phWnd
);
225 IntPaintWindows(Window
, Flags
);
226 IntReleaseWindowObject(Window
);
235 * IntInvalidateWindows
237 * Internal function used by IntRedrawWindow.
241 IntInvalidateWindows(PWINDOW_OBJECT Window
, HRGN hRgn
, ULONG Flags
,
245 BOOL HadPaintMessage
, HadNCPaintMessage
;
246 BOOL HasPaintMessage
, HasNCPaintMessage
;
250 * Clip the given region with window rectangle (or region)
254 if (!Window
->WindowRegion
)
257 hRgnWindow
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
258 NtGdiOffsetRgn(hRgnWindow
,
259 -Window
->WindowRect
.left
,
260 -Window
->WindowRect
.top
);
261 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, hRgnWindow
, RGN_AND
);
262 NtGdiDeleteObject(hRgnWindow
);
267 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, Window
->WindowRegion
, RGN_AND
);
272 * Save current state of pending updates
275 HadPaintMessage
= Window
->UpdateRegion
!= NULL
||
276 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
;
277 HadNCPaintMessage
= Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
;
280 * Update the region and flags
283 if (Flags
& RDW_INVALIDATE
&& RgnType
!= NULLREGION
)
285 if (Window
->UpdateRegion
== NULL
)
287 Window
->UpdateRegion
= NtGdiCreateRectRgn(0, 0, 0, 0);
290 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
291 hRgn
, RGN_OR
) == NULLREGION
)
293 NtGdiDeleteObject(Window
->UpdateRegion
);
294 Window
->UpdateRegion
= NULL
;
297 if (Flags
& RDW_FRAME
)
298 Window
->Flags
|= WINDOWOBJECT_NEED_NCPAINT
;
299 if (Flags
& RDW_ERASE
)
300 Window
->Flags
|= WINDOWOBJECT_NEED_ERASEBKGND
;
305 if (Flags
& RDW_VALIDATE
&& RgnType
!= NULLREGION
)
307 if (Window
->UpdateRegion
!= NULL
)
309 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
310 hRgn
, RGN_DIFF
) == NULLREGION
)
312 NtGdiDeleteObject(Window
->UpdateRegion
);
313 Window
->UpdateRegion
= NULL
;
317 if (Window
->UpdateRegion
== NULL
)
318 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
319 if (Flags
& RDW_NOFRAME
)
320 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
321 if (Flags
& RDW_NOERASE
)
322 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
325 if (Flags
& RDW_INTERNALPAINT
)
327 Window
->Flags
|= WINDOWOBJECT_NEED_INTERNALPAINT
;
330 if (Flags
& RDW_NOINTERNALPAINT
)
332 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
336 * Validate parent covered by region
341 IntValidateParent(Window
);
345 * Process children if needed
348 if (!(Flags
& RDW_NOCHILDREN
) && !(Window
->Style
& WS_MINIMIZE
) &&
349 ((Flags
& RDW_ALLCHILDREN
) || !(Window
->Style
& WS_CLIPCHILDREN
)))
352 PWINDOW_OBJECT Child
;
354 if ((List
= IntWinListChildren(Window
)))
356 for (phWnd
= List
; *phWnd
; ++phWnd
)
358 Child
= IntGetWindowObject(*phWnd
);
363 if ((Child
->Style
& (WS_VISIBLE
| WS_MINIMIZE
)) == WS_VISIBLE
)
366 * Recursive call to update children UpdateRegion
368 HRGN hRgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
369 NtGdiCombineRgn(hRgnTemp
, hRgn
, 0, RGN_COPY
);
370 NtGdiOffsetRgn(hRgnTemp
,
371 Window
->WindowRect
.left
- Child
->WindowRect
.left
,
372 Window
->WindowRect
.top
- Child
->WindowRect
.top
);
373 IntInvalidateWindows(Child
, hRgnTemp
, Flags
, FALSE
);
376 * Update our UpdateRegion depending on children
378 NtGdiCombineRgn(hRgnTemp
, Child
->UpdateRegion
, 0, RGN_COPY
);
379 NtGdiOffsetRgn(hRgnTemp
,
380 Child
->WindowRect
.left
- Window
->WindowRect
.left
,
381 Child
->WindowRect
.top
- Window
->WindowRect
.top
);
382 hRgnWindow
= UnsafeIntCreateRectRgnIndirect(&Window
->ClientRect
);
383 NtGdiOffsetRgn(hRgnWindow
,
384 -Window
->WindowRect
.left
,
385 -Window
->WindowRect
.top
);
386 NtGdiCombineRgn(hRgnTemp
, hRgnTemp
, hRgnWindow
, RGN_AND
);
387 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
388 hRgnTemp
, RGN_DIFF
) == NULLREGION
)
390 NtGdiDeleteObject(Window
->UpdateRegion
);
391 Window
->UpdateRegion
= NULL
;
393 NtGdiDeleteObject(hRgnTemp
);
395 IntReleaseWindowObject(Child
);
402 * Fake post paint messages to window message queue if needed
404 HasPaintMessage
= Window
->UpdateRegion
!= NULL
||
405 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
;
406 HasNCPaintMessage
= Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
;
408 if (HasPaintMessage
!= HadPaintMessage
)
411 MsqDecPaintCountQueue(Window
->MessageQueue
);
413 MsqIncPaintCountQueue(Window
->MessageQueue
);
416 if (HasNCPaintMessage
!= HadNCPaintMessage
)
418 if (HadNCPaintMessage
)
419 MsqDecPaintCountQueue(Window
->MessageQueue
);
421 MsqIncPaintCountQueue(Window
->MessageQueue
);
426 * IntIsWindowDrawable
429 * Window is drawable when it is visible, all parents are not
430 * minimized, and it is itself not minimized.
434 IntIsWindowDrawable(PWINDOW_OBJECT Window
)
436 for (; Window
; Window
= Window
->Parent
)
438 if ((Window
->Style
& (WS_VISIBLE
| WS_MINIMIZE
)) != WS_VISIBLE
)
448 * Internal version of NtUserRedrawWindow that takes WINDOW_OBJECT as
453 IntRedrawWindow(PWINDOW_OBJECT Window
, const RECT
* UpdateRect
, HRGN UpdateRgn
,
460 * Validation of passed parameters.
463 if (!IntIsWindowDrawable(Window
) ||
464 (Flags
& (RDW_VALIDATE
| RDW_INVALIDATE
)) ==
465 (RDW_VALIDATE
| RDW_INVALIDATE
))
472 * Transform the parameters UpdateRgn and UpdateRect into
473 * a region hRgn specified in window coordinates.
476 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
))
478 if (UpdateRgn
!= NULL
)
480 hRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
481 NtGdiCombineRgn(hRgn
, UpdateRgn
, NULL
, RGN_COPY
);
483 Window
->ClientRect
.left
- Window
->WindowRect
.left
,
484 Window
->ClientRect
.top
- Window
->WindowRect
.top
);
486 if (UpdateRect
!= NULL
)
488 hRgn
= UnsafeIntCreateRectRgnIndirect((RECT
*)UpdateRect
);
490 Window
->ClientRect
.left
- Window
->WindowRect
.left
,
491 Window
->ClientRect
.top
- Window
->WindowRect
.top
);
493 if ((Flags
& (RDW_INVALIDATE
| RDW_FRAME
)) == (RDW_INVALIDATE
| RDW_FRAME
) ||
494 (Flags
& (RDW_VALIDATE
| RDW_NOFRAME
)) == (RDW_VALIDATE
| RDW_NOFRAME
))
496 hRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
498 -Window
->WindowRect
.left
,
499 -Window
->WindowRect
.top
);
503 hRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->ClientRect
);
505 -Window
->WindowRect
.left
,
506 -Window
->WindowRect
.top
);
512 * Adjust the window update region depending on hRgn and flags.
515 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
| RDW_INTERNALPAINT
| RDW_NOINTERNALPAINT
))
517 IntInvalidateWindows(Window
, hRgn
, Flags
, TRUE
);
519 if (Window
->UpdateRegion
!= NULL
&& Flags
& RDW_ERASENOW
)
521 /* Validate parent covered by region. */
522 IntValidateParent(Window
);
527 * Repaint and erase windows if needed.
530 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
532 IntPaintWindows(Window
, Flags
);
542 NtGdiDeleteObject(hRgn
);
549 IntFindWindowToRepaint(HWND hWnd
, PW32THREAD Thread
)
551 PWINDOW_OBJECT Window
;
552 PWINDOW_OBJECT Child
;
553 HWND hFoundWnd
= NULL
;
557 PLIST_ENTRY CurrentEntry
;
559 ExAcquireFastMutex(&Thread
->WindowListLock
);
561 for (CurrentEntry
= Thread
->WindowListHead
.Flink
;
562 CurrentEntry
!= &Thread
->WindowListHead
;
563 CurrentEntry
= CurrentEntry
->Flink
)
565 Window
= CONTAINING_RECORD(CurrentEntry
, WINDOW_OBJECT
, ThreadListEntry
);
566 if (Window
->Parent
!= NULL
&& !IntIsDesktopWindow(Window
->Parent
))
570 if (Window
->Style
& WS_VISIBLE
)
572 hFoundWnd
= IntFindWindowToRepaint(Window
->Self
, Thread
);
573 if (hFoundWnd
!= NULL
)
575 ExReleaseFastMutex(&Thread
->WindowListLock
);
581 ExReleaseFastMutex(&Thread
->WindowListLock
);
586 Window
= IntGetWindowObject(hWnd
);
590 if ((Window
->UpdateRegion
!= NULL
||
591 Window
->Flags
& (WINDOWOBJECT_NEED_INTERNALPAINT
| WINDOWOBJECT_NEED_NCPAINT
)) &&
592 IntWndBelongsToThread(Window
, Thread
))
594 IntReleaseWindowObject(Window
);
598 ExAcquireFastMutex(&Window
->ChildrenListLock
);
600 for (Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
602 if (Child
->Style
& WS_VISIBLE
&&
603 (Child
->UpdateRegion
!= NULL
||
604 Child
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
||
605 Child
->Flags
& WINDOWOBJECT_NEED_NCPAINT
))
607 hFoundWnd
= Child
->Self
;
612 if (hFoundWnd
== NULL
)
614 for (Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
616 if (Child
->Style
& WS_VISIBLE
)
618 hFoundWnd
= IntFindWindowToRepaint(Child
->Self
, Thread
);
619 if (hFoundWnd
!= NULL
)
625 ExReleaseFastMutex(&Window
->ChildrenListLock
);
626 IntReleaseWindowObject(Window
);
633 IntGetPaintMessage(HWND hWnd
, PW32THREAD Thread
, MSG
*Message
,
636 PWINDOW_OBJECT Window
;
637 PUSER_MESSAGE_QUEUE MessageQueue
= (PUSER_MESSAGE_QUEUE
)Thread
->MessageQueue
;
639 if (!MessageQueue
->PaintPosted
)
643 Message
->hwnd
= IntFindWindowToRepaint(hWnd
, PsGetWin32Thread());
645 Message
->hwnd
= IntFindWindowToRepaint(NULL
, PsGetWin32Thread());
647 if (Message
->hwnd
== NULL
)
650 DPRINT1("PAINTING BUG: Thread marked as containing dirty windows, but no dirty windows found!\n");
651 /* FIXME: Lock the queue! */
652 MessageQueue
->PaintPosted
= 0;
653 MessageQueue
->PaintCount
= 0;
658 Window
= IntGetWindowObject(Message
->hwnd
);
661 if (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
)
663 Message
->message
= WM_NCPAINT
;
664 Message
->wParam
= (WPARAM
)IntGetNCUpdateRegion(Window
, Remove
);
668 Message
->message
= WM_PAINT
;
669 Message
->wParam
= Message
->lParam
= 0;
670 if (Remove
&& Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
672 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
673 if (Window
->UpdateRegion
== NULL
)
675 MsqDecPaintCountQueue(Window
->MessageQueue
);
680 IntReleaseWindowObject(Window
);
688 IntFixCaret(HWND hWnd
, LPRECT lprc
, UINT flags
)
692 if (!NtUserGetGUIThreadInfo(0, &info
))
696 if (info
.hwndCaret
== hWnd
||
697 ((flags
& SW_SCROLLCHILDREN
) && IntIsChildWindow(hWnd
, info
.hwndCaret
)))
699 POINT pt
, FromOffset
, ToOffset
, Offset
;
701 pt
.x
= info
.rcCaret
.left
;
702 pt
.y
= info
.rcCaret
.top
;
704 IntGetClientOrigin(info
.hwndCaret
, &FromOffset
);
705 IntGetClientOrigin(hWnd
, &ToOffset
);
706 Offset
.x
= FromOffset
.x
- ToOffset
.x
;
707 Offset
.y
= FromOffset
.y
- ToOffset
.y
;
708 info
.rcCaret
.left
+= Offset
.x
;
709 info
.rcCaret
.top
+= Offset
.y
;
710 info
.rcCaret
.right
+= Offset
.x
;
711 info
.rcCaret
.bottom
+= Offset
.y
;
712 if (NtGdiIntersectRect(lprc
, lprc
, &info
.rcCaret
))
717 return info
.hwndCaret
;
724 /* PUBLIC FUNCTIONS ***********************************************************/
734 NtUserBeginPaint(HWND hWnd
, PAINTSTRUCT
* lPs
)
736 PWINDOW_OBJECT Window
;
741 if (!(Window
= IntGetWindowObject(hWnd
)))
743 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
747 NtUserHideCaret(hWnd
);
749 DcxFlags
= DCX_INTERSECTUPDATE
| DCX_WINDOWPAINT
| DCX_USESTYLE
;
751 lPs
->hdc
= NtUserGetDCEx(hWnd
, 0, DcxFlags
);
755 IntReleaseWindowObject(Window
);
759 /* IntRedrawWindow(Window, NULL, 0, RDW_NOINTERNALPAINT | RDW_VALIDATE | RDW_NOCHILDREN);*/
760 if (Window
->UpdateRegion
!= NULL
)
762 MsqDecPaintCountQueue(Window
->MessageQueue
);
763 IntValidateParent(Window
);
764 NtGdiDeleteObject(Window
->UpdateRegion
);
765 Window
->UpdateRegion
= NULL
;
768 IntGetClientRect(Window
, &ClientRect
);
769 IntGdiGetClipBox(lPs
->hdc
, &ClipRect
);
770 NtGdiLPtoDP(lPs
->hdc
, (LPPOINT
)&ClipRect
, 2);
771 NtGdiIntersectRect(&lPs
->rcPaint
, &ClientRect
, &ClipRect
);
772 NtGdiDPtoLP(lPs
->hdc
, (LPPOINT
)&lPs
->rcPaint
, 2);
774 if (Window
->Flags
& WINDOWOBJECT_NEED_ERASEBKGND
)
776 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
777 lPs
->fErase
= !IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)lPs
->hdc
, 0, TRUE
);
784 IntReleaseWindowObject(Window
);
797 NtUserEndPaint(HWND hWnd
, CONST PAINTSTRUCT
* lPs
)
799 NtUserReleaseDC(hWnd
, lPs
->hdc
);
800 NtUserShowCaret(hWnd
);
806 * NtUserInvalidateRect
813 NtUserInvalidateRect(HWND hWnd
, CONST RECT
*Rect
, BOOL Erase
)
815 return NtUserRedrawWindow(hWnd
, Rect
, 0, RDW_INVALIDATE
| (Erase
? RDW_ERASE
: 0));
819 * NtUserInvalidateRgn
826 NtUserInvalidateRgn(HWND hWnd
, HRGN Rgn
, BOOL Erase
)
828 return NtUserRedrawWindow(hWnd
, NULL
, Rgn
, RDW_INVALIDATE
| (Erase
? RDW_ERASE
: 0));
839 NtUserValidateRgn(HWND hWnd
, HRGN hRgn
)
841 return NtUserRedrawWindow(hWnd
, NULL
, hRgn
, RDW_VALIDATE
| RDW_NOCHILDREN
);
852 NtUserUpdateWindow(HWND hWnd
)
854 return NtUserRedrawWindow(hWnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
865 NtUserGetUpdateRgn(HWND hWnd
, HRGN hRgn
, BOOL bErase
)
867 PWINDOW_OBJECT Window
;
870 if (!(Window
= IntGetWindowObject(hWnd
)))
872 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
876 if (Window
->UpdateRegion
== NULL
)
878 RegionType
= (NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0) ? NULLREGION
: ERROR
);
882 RegionType
= NtGdiCombineRgn(hRgn
, Window
->UpdateRegion
, hRgn
, RGN_COPY
);
885 Window
->WindowRect
.left
- Window
->ClientRect
.left
,
886 Window
->WindowRect
.top
- Window
->ClientRect
.top
);
889 IntReleaseWindowObject(Window
);
891 if (bErase
&& RegionType
!= NULLREGION
&& RegionType
!= ERROR
)
893 NtUserRedrawWindow(hWnd
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
900 * NtUserGetUpdateRect
907 NtUserGetUpdateRect(HWND hWnd
, LPRECT lpRect
, BOOL fErase
)
909 HRGN hRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
913 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
917 NtUserGetUpdateRgn(hWnd
, hRgn
, fErase
);
918 NtGdiGetRgnBox(hRgn
, lpRect
);
920 return lpRect
->left
< lpRect
->right
&& lpRect
->top
< lpRect
->bottom
;
931 NtUserRedrawWindow(HWND hWnd
, CONST RECT
*lprcUpdate
, HRGN hrgnUpdate
,
938 if (!(Wnd
= IntGetWindowObject(hWnd
? hWnd
: IntGetDesktopWindow())))
940 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
944 if (lprcUpdate
!= NULL
)
946 Status
= MmCopyFromCaller(&SafeUpdateRect
, (PRECT
)lprcUpdate
,
949 if (!NT_SUCCESS(Status
))
951 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
956 Status
= IntRedrawWindow(Wnd
, NULL
== lprcUpdate
? NULL
: &SafeUpdateRect
,
959 if (!NT_SUCCESS(Status
))
961 /* IntRedrawWindow fails only in case that flags are invalid */
962 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
977 NtUserScrollDC(HDC hDC
, INT dx
, INT dy
, const RECT
*lprcScroll
,
978 const RECT
*lprcClip
, HRGN hrgnUpdate
, LPRECT lprcUpdate
)
980 RECT rSrc
, rClipped_src
, rClip
, rDst
, offset
;
983 * Compute device clipping region (in device coordinates).
989 IntGdiGetClipBox(hDC
, &rSrc
);
990 NtGdiLPtoDP(hDC
, (LPPOINT
)&rSrc
, 2);
995 IntGdiGetClipBox(hDC
, &rClip
);
996 NtGdiLPtoDP(hDC
, (LPPOINT
)&rClip
, 2);
998 NtGdiIntersectRect(&rClipped_src
, &rSrc
, &rClip
);
1000 rDst
= rClipped_src
;
1001 NtGdiSetRect(&offset
, 0, 0, dx
, dy
);
1002 NtGdiLPtoDP(hDC
, (LPPOINT
)&offset
, 2);
1003 NtGdiOffsetRect(&rDst
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
1004 NtGdiIntersectRect(&rDst
, &rDst
, &rClip
);
1007 * Copy bits, if possible.
1010 if (rDst
.bottom
> rDst
.top
&& rDst
.right
> rDst
.left
)
1012 RECT rDst_lp
= rDst
, rSrc_lp
= rDst
;
1014 NtGdiOffsetRect(&rSrc_lp
, offset
.left
- offset
.right
, offset
.top
- offset
.bottom
);
1015 NtGdiDPtoLP(hDC
, (LPPOINT
)&rDst_lp
, 2);
1016 NtGdiDPtoLP(hDC
, (LPPOINT
)&rSrc_lp
, 2);
1018 if (!NtGdiBitBlt(hDC
, rDst_lp
.left
, rDst_lp
.top
, rDst_lp
.right
- rDst_lp
.left
,
1019 rDst_lp
.bottom
- rDst_lp
.top
, hDC
, rSrc_lp
.left
, rSrc_lp
.top
,
1025 * Compute update areas. This is the clipped source or'ed with the
1026 * unclipped source translated minus the clipped src translated (rDst)
1027 * all clipped to rClip.
1030 if (hrgnUpdate
|| lprcUpdate
)
1032 HRGN hRgn
= hrgnUpdate
, hRgn2
;
1035 NtGdiSetRectRgn(hRgn
, rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
1037 hRgn
= NtGdiCreateRectRgn(rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
1039 hRgn2
= NtGdiCreateRectRgnIndirect(&rSrc
);
1040 NtGdiOffsetRgn(hRgn2
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
1041 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_OR
);
1043 NtGdiSetRectRgn(hRgn2
, rDst
.left
, rDst
.top
, rDst
.right
, rDst
.bottom
);
1044 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_DIFF
);
1046 NtGdiSetRectRgn(hRgn2
, rClip
.left
, rClip
.top
, rClip
.right
, rClip
.bottom
);
1047 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_AND
);
1051 NtGdiGetRgnBox(hRgn
, lprcUpdate
);
1053 /* Put the lprcUpdate in logical coordinate */
1054 NtGdiDPtoLP(hDC
, (LPPOINT
)lprcUpdate
, 2);
1057 NtGdiDeleteObject(hRgn
);
1058 NtGdiDeleteObject(hRgn2
);
1064 * NtUserScrollWindowEx
1071 NtUserScrollWindowEx(HWND hWnd
, INT dx
, INT dy
, const RECT
*rect
,
1072 const RECT
*clipRect
, HRGN hrgnUpdate
, LPRECT rcUpdate
, UINT flags
)
1074 RECT rc
, cliprc
, caretrc
;
1076 PWINDOW_OBJECT Window
;
1080 BOOL bUpdate
= (rcUpdate
|| hrgnUpdate
|| flags
& (SW_INVALIDATE
| SW_ERASE
));
1081 BOOL bOwnRgn
= TRUE
;
1083 Window
= IntGetWindowObject(hWnd
);
1084 if (!Window
|| !IntIsWindowDrawable(Window
))
1086 IntReleaseWindowObject(Window
);
1090 IntGetClientRect(Window
, &rc
);
1092 NtGdiIntersectRect(&rc
, &rc
, rect
);
1095 NtGdiIntersectRect(&cliprc
, &rc
, clipRect
);
1099 if (cliprc
.right
<= cliprc
.left
|| cliprc
.bottom
<= cliprc
.top
||
1100 (dx
== 0 && dy
== 0))
1106 hwndCaret
= IntFixCaret(hWnd
, &caretrc
, flags
);
1111 hrgnUpdate
= NtGdiCreateRectRgn(0, 0, 0, 0);
1113 hDC
= NtUserGetDCEx( hWnd
, 0, DCX_CACHE
| DCX_USESTYLE
);
1116 HRGN hRgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
1118 NtUserScrollDC(hDC
, dx
, dy
, &rc
, &cliprc
, hrgnUpdate
, rcUpdate
);
1119 NtUserReleaseDC(hWnd
, hDC
);
1121 NtGdiCombineRgn(hrgnUpdate
, hrgnUpdate
, hRgn
, RGN_OR
);
1123 NtUserRedrawWindow(hWnd
, NULL
, hRgn
, RDW_INVALIDATE
| RDW_ERASE
);
1124 NtGdiDeleteObject(hRgn
);
1128 * Take into account the fact that some damage may have occurred during
1132 hrgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
1133 Result
= NtUserGetUpdateRgn(hWnd
, hrgnTemp
, FALSE
);
1134 if (Result
!= NULLREGION
)
1136 HRGN hrgnClip
= NtGdiCreateRectRgnIndirect(&cliprc
);
1137 NtGdiOffsetRgn(hrgnTemp
, dx
, dy
);
1138 NtGdiCombineRgn(hrgnTemp
, hrgnTemp
, hrgnClip
, RGN_AND
);
1139 NtUserRedrawWindow(hWnd
, NULL
, hrgnTemp
, RDW_INVALIDATE
| RDW_ERASE
);
1140 NtGdiDeleteObject(hrgnClip
);
1142 NtGdiDeleteObject(hrgnTemp
);
1144 if (flags
& SW_SCROLLCHILDREN
)
1146 HWND
*List
= IntWinListChildren(Window
);
1153 for (i
= 0; List
[i
]; i
++)
1155 NtUserGetWindowRect(List
[i
], &r
);
1156 IntGetClientOrigin(hWnd
, &ClientOrigin
);
1157 r
.left
-= ClientOrigin
.x
;
1158 r
.top
-= ClientOrigin
.y
;
1159 r
.right
-= ClientOrigin
.x
;
1160 r
.bottom
-= ClientOrigin
.y
;
1161 if (!rect
|| NtGdiIntersectRect(&dummy
, &r
, &rc
))
1162 WinPosSetWindowPos(List
[i
], 0, r
.left
+ dx
, r
.top
+ dy
, 0, 0,
1163 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
|
1170 if (flags
& (SW_INVALIDATE
| SW_ERASE
))
1171 NtUserRedrawWindow(hWnd
, NULL
, hrgnUpdate
, RDW_INVALIDATE
| RDW_ERASE
|
1172 ((flags
& SW_ERASE
) ? RDW_ERASENOW
: 0) |
1173 ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0));
1175 if (bOwnRgn
&& hrgnUpdate
)
1176 NtGdiDeleteObject(hrgnUpdate
);
1180 IntSetCaretPos(caretrc
.left
+ dx
, caretrc
.top
+ dy
);
1181 NtUserShowCaret(hwndCaret
);
1184 IntReleaseWindowObject(Window
);