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.56 2003/12/30 16:55:00 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 /* #define FIN_DEBUG */
59 /* PRIVATE FUNCTIONS **********************************************************/
62 IntValidateParent(PWINDOW_OBJECT Child
, HRGN ValidRegion
)
65 PWINDOW_OBJECT ParentWindow
;
67 Parent
= NtUserGetAncestor(Child
->Self
, GA_PARENT
);
68 while (Parent
&& Parent
!= IntGetDesktopWindow())
70 ParentWindow
= IntGetWindowObject(Parent
);
71 if (ParentWindow
&& !(ParentWindow
->Style
& WS_CLIPCHILDREN
))
73 if (ParentWindow
->UpdateRegion
!= 0)
78 * We must offset the child region by the offset of the
79 * child rect in the parent.
81 OffsetX
= Child
->WindowRect
.left
- ParentWindow
->WindowRect
.left
;
82 OffsetY
= Child
->WindowRect
.top
- ParentWindow
->WindowRect
.top
;
83 NtGdiOffsetRgn(ValidRegion
, OffsetX
, OffsetY
);
84 NtGdiCombineRgn(ParentWindow
->UpdateRegion
, ParentWindow
->UpdateRegion
,
85 ValidRegion
, RGN_DIFF
);
86 /* FIXME: If the resulting region is empty, remove fake posted paint message */
87 NtGdiOffsetRgn(ValidRegion
, -OffsetX
, -OffsetY
);
90 IntReleaseWindowObject(ParentWindow
);
91 Parent
= NtUserGetAncestor(Parent
, GA_PARENT
);
96 * IntGetNCUpdateRegion
98 * Get nonclient part of window update region.
101 * Handle to region that represents invalid nonclient window area. The
102 * caller is responsible for deleting it.
105 * This function also marks the nonclient update region of window
106 * as valid, clears the WINDOWOBJECT_NEED_NCPAINT flag.
110 IntGetNCUpdateRegion(PWINDOW_OBJECT Window
)
116 * Generate the update region.
119 WindowRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->ClientRect
);
120 NtGdiOffsetRgn(WindowRgn
,
121 -Window
->WindowRect
.left
,
122 -Window
->WindowRect
.top
);
123 NonclientRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
124 if (NtGdiCombineRgn(NonclientRgn
, Window
->UpdateRegion
,
125 WindowRgn
, RGN_DIFF
) == NULLREGION
)
127 NtGdiDeleteObject(NonclientRgn
);
132 * Remove the nonclient region from the standard update region.
135 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
136 WindowRgn
, RGN_AND
) == NULLREGION
)
138 NtGdiDeleteObject(Window
->UpdateRegion
);
139 Window
->UpdateRegion
= NULL
;
148 * Internal function used by IntRedrawWindow.
152 IntPaintWindows(PWINDOW_OBJECT Window
, ULONG Flags
)
155 HWND hWnd
= Window
->Self
;
157 if (! (Window
->Style
& WS_VISIBLE
))
162 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
164 if (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
)
166 IntSendMessage(hWnd
, WM_NCPAINT
, (WPARAM
)Window
->NCUpdateRegion
, 0);
167 Window
->NCUpdateRegion
= NULL
;
168 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
169 MsqDecPaintCountQueue(Window
->MessageQueue
);
172 if (Window
->Flags
& WINDOWOBJECT_NEED_ERASEBKGND
)
174 if (Window
->UpdateRegion
)
179 UnsafeIntGetRgnBox(Window
->UpdateRegion
, &TempRect
);
180 DPRINT1("Sending WM_ERASEBKGND[1]: %d,%d-%d,%d\n",
181 TempRect
.left
, TempRect
.top
, TempRect
.right
, TempRect
.bottom
);
184 hDC
= NtUserGetDCEx(hWnd
, 0, DCX_CACHE
| DCX_USESTYLE
|
185 DCX_INTERSECTUPDATE
);
188 if (IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)hDC
, 0))
190 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
192 NtUserReleaseDC(hWnd
, hDC
);
197 if (Flags
& RDW_UPDATENOW
)
199 if (Window
->UpdateRegion
!= NULL
||
200 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
205 UnsafeIntGetRgnBox(Window
->UpdateRegion
, &TempRect
);
206 DPRINT1("Sending WM_PAINT[1]: %d,%d-%d,%d\n",
207 TempRect
.left
, TempRect
.top
, TempRect
.right
, TempRect
.bottom
);
210 IntSendMessage(hWnd
, WM_PAINT
, 0, 0);
211 if (Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
213 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
214 if (Window
->UpdateRegion
== NULL
)
216 MsqDecPaintCountQueue(Window
->MessageQueue
);
224 * Check that the window is still valid at this point
227 if (! IntIsWindow(hWnd
))
233 * Paint child windows.
235 if (!(Flags
& RDW_NOCHILDREN
) && !(Window
->Style
& WS_MINIMIZE
) &&
236 ((Flags
& RDW_ALLCHILDREN
) || !(Window
->Style
& WS_CLIPCHILDREN
)) &&
237 ! IntIsDesktopWindow(Window
))
241 if ((List
= IntWinListChildren(Window
)))
243 for (phWnd
= List
; *phWnd
; ++phWnd
)
245 Window
= IntGetWindowObject(*phWnd
);
248 IntPaintWindows(Window
, Flags
);
249 IntReleaseWindowObject(Window
);
258 * IntInvalidateWindows
260 * Internal function used by IntRedrawWindow.
264 IntInvalidateWindows(PWINDOW_OBJECT Window
, HRGN hRgn
, ULONG Flags
,
268 BOOL HadPaintMessage
, HadNCPaintMessage
;
269 BOOL HasPaintMessage
, HasNCPaintMessage
;
273 * Clip the given region with window rectangle (or region)
277 if (!Window
->WindowRegion
)
280 hRgnWindow
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
281 NtGdiOffsetRgn(hRgnWindow
,
282 -Window
->WindowRect
.left
,
283 -Window
->WindowRect
.top
);
284 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, hRgnWindow
, RGN_AND
);
285 NtGdiDeleteObject(hRgnWindow
);
290 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, Window
->WindowRegion
, RGN_AND
);
295 * Save current state of pending updates
298 HadPaintMessage
= Window
->UpdateRegion
!= NULL
||
299 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
;
300 HadNCPaintMessage
= Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
;
303 * Update the region and flags
306 if (Flags
& RDW_INVALIDATE
&& RgnType
!= NULLREGION
)
308 if (Window
->UpdateRegion
== NULL
)
310 Window
->UpdateRegion
= NtGdiCreateRectRgn(0, 0, 0, 0);
313 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
314 hRgn
, RGN_OR
) == NULLREGION
)
316 NtGdiDeleteObject(Window
->UpdateRegion
);
317 Window
->UpdateRegion
= NULL
;
320 if (Flags
& RDW_FRAME
)
321 Window
->Flags
|= WINDOWOBJECT_NEED_NCPAINT
;
322 if (Flags
& RDW_ERASE
)
323 Window
->Flags
|= WINDOWOBJECT_NEED_ERASEBKGND
;
328 if (Flags
& RDW_VALIDATE
&& RgnType
!= NULLREGION
)
330 if (Window
->UpdateRegion
!= NULL
)
332 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
333 hRgn
, RGN_DIFF
) == NULLREGION
)
335 NtGdiDeleteObject(Window
->UpdateRegion
);
336 Window
->UpdateRegion
= NULL
;
340 if (Window
->UpdateRegion
== NULL
)
341 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
342 if (Flags
& RDW_NOFRAME
)
343 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
344 if (Flags
& RDW_NOERASE
)
345 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
348 if (Flags
& RDW_INTERNALPAINT
)
350 Window
->Flags
|= WINDOWOBJECT_NEED_INTERNALPAINT
;
353 if (Flags
& RDW_NOINTERNALPAINT
)
355 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
359 * Validate parent covered by region
364 IntValidateParent(Window
, Window
->UpdateRegion
);
368 * Split the nonclient update region.
371 if (Window
->NCUpdateRegion
== NULL
)
373 Window
->NCUpdateRegion
= IntGetNCUpdateRegion(Window
);
377 HRGN hRgnNonClient
= IntGetNCUpdateRegion(Window
);
378 NtGdiCombineRgn(Window
->NCUpdateRegion
, Window
->NCUpdateRegion
,
379 hRgnNonClient
, RGN_OR
);
380 NtGdiDeleteObject(hRgnNonClient
);
384 * Process children if needed
387 if (!(Flags
& RDW_NOCHILDREN
) && !(Window
->Style
& WS_MINIMIZE
) &&
388 ((Flags
& RDW_ALLCHILDREN
) || !(Window
->Style
& WS_CLIPCHILDREN
)))
391 PWINDOW_OBJECT Child
;
393 if ((List
= IntWinListChildren(Window
)))
395 for (phWnd
= List
; *phWnd
; ++phWnd
)
397 Child
= IntGetWindowObject(*phWnd
);
402 if (Child
->Style
& WS_VISIBLE
)
407 * Recursive call to update children UpdateRegion
409 HRGN hRgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
410 NtGdiCombineRgn(hRgnTemp
, hRgn
, 0, RGN_COPY
);
411 NtGdiOffsetRgn(hRgnTemp
,
412 Window
->WindowRect
.left
- Child
->WindowRect
.left
,
413 Window
->WindowRect
.top
- Child
->WindowRect
.top
);
414 IntInvalidateWindows(Child
, hRgnTemp
, Flags
, FALSE
);
417 * Update our UpdateRegion depending on children
420 if (Window
->UpdateRegion
!= NULL
)
422 UnsafeIntGetRgnBox(Window
->UpdateRegion
, &TempRect
);
423 NtGdiCombineRgn(hRgnTemp
, Child
->UpdateRegion
, 0, RGN_COPY
);
424 NtGdiCombineRgn(hRgnTemp
, hRgnTemp
, Child
->NCUpdateRegion
, RGN_OR
);
425 NtGdiOffsetRgn(hRgnTemp
,
426 Child
->WindowRect
.left
- Window
->WindowRect
.left
,
427 Child
->WindowRect
.top
- Window
->WindowRect
.top
);
428 UnsafeIntGetRgnBox(hRgnTemp
, &TempRect
);
429 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
430 hRgnTemp
, RGN_DIFF
) == NULLREGION
)
432 NtGdiDeleteObject(Window
->UpdateRegion
);
433 Window
->UpdateRegion
= NULL
;
436 NtGdiDeleteObject(hRgnTemp
);
438 IntReleaseWindowObject(Child
);
445 * Fake post paint messages to window message queue if needed
447 HasPaintMessage
= Window
->UpdateRegion
!= NULL
||
448 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
;
449 HasNCPaintMessage
= Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
;
451 if (HasPaintMessage
!= HadPaintMessage
)
454 MsqDecPaintCountQueue(Window
->MessageQueue
);
456 MsqIncPaintCountQueue(Window
->MessageQueue
);
459 if (HasNCPaintMessage
!= HadNCPaintMessage
)
461 if (HadNCPaintMessage
)
462 MsqDecPaintCountQueue(Window
->MessageQueue
);
464 MsqIncPaintCountQueue(Window
->MessageQueue
);
469 * IntIsWindowDrawable
472 * Window is drawable when it is visible and all parents are not
477 IntIsWindowDrawable(PWINDOW_OBJECT Window
)
479 PWINDOW_OBJECT Wnd
= Window
;
481 for (; Wnd
; Wnd
= Wnd
->Parent
)
483 if (!(Wnd
->Style
& WS_VISIBLE
) ||
484 ((Wnd
->Style
& WS_MINIMIZE
) && (Wnd
!= Window
)))
494 * Internal version of NtUserRedrawWindow that takes WINDOW_OBJECT as
499 IntRedrawWindow(PWINDOW_OBJECT Window
, const RECT
* UpdateRect
, HRGN UpdateRgn
,
506 * Validation of passed parameters.
509 if (!IntIsWindowDrawable(Window
) ||
510 (Flags
& (RDW_VALIDATE
| RDW_INVALIDATE
)) ==
511 (RDW_VALIDATE
| RDW_INVALIDATE
))
518 * Transform the parameters UpdateRgn and UpdateRect into
519 * a region hRgn specified in window coordinates.
522 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
))
524 if (UpdateRgn
!= NULL
)
526 hRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
527 NtGdiCombineRgn(hRgn
, UpdateRgn
, NULL
, RGN_COPY
);
529 Window
->ClientRect
.left
- Window
->WindowRect
.left
,
530 Window
->ClientRect
.top
- Window
->WindowRect
.top
);
532 if (UpdateRect
!= NULL
)
534 hRgn
= UnsafeIntCreateRectRgnIndirect((RECT
*)UpdateRect
);
536 Window
->ClientRect
.left
- Window
->WindowRect
.left
,
537 Window
->ClientRect
.top
- Window
->WindowRect
.top
);
539 if ((Flags
& (RDW_INVALIDATE
| RDW_FRAME
)) == (RDW_INVALIDATE
| RDW_FRAME
) ||
540 (Flags
& (RDW_VALIDATE
| RDW_NOFRAME
)) == (RDW_VALIDATE
| RDW_NOFRAME
))
542 hRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
544 -Window
->WindowRect
.left
,
545 -Window
->WindowRect
.top
);
549 hRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->ClientRect
);
551 -Window
->WindowRect
.left
,
552 -Window
->WindowRect
.top
);
558 * Adjust the window update region depending on hRgn and flags.
561 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
| RDW_INTERNALPAINT
| RDW_NOINTERNALPAINT
))
563 IntInvalidateWindows(Window
, hRgn
, Flags
, TRUE
);
565 if (Window
->UpdateRegion
!= NULL
&& Flags
& RDW_ERASENOW
)
567 /* Validate parent covered by region. */
568 IntValidateParent(Window
, Window
->UpdateRegion
);
573 * Repaint and erase windows if needed.
576 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
578 IntPaintWindows(Window
, Flags
);
588 NtGdiDeleteObject(hRgn
);
595 IntFindWindowToRepaint(HWND hWnd
, PW32THREAD Thread
)
597 PWINDOW_OBJECT Window
;
598 PWINDOW_OBJECT Child
;
599 HWND hFoundWnd
= NULL
;
603 PLIST_ENTRY CurrentEntry
;
605 ExAcquireFastMutex(&Thread
->WindowListLock
);
607 for (CurrentEntry
= Thread
->WindowListHead
.Flink
;
608 CurrentEntry
!= &Thread
->WindowListHead
;
609 CurrentEntry
= CurrentEntry
->Flink
)
611 Window
= CONTAINING_RECORD(CurrentEntry
, WINDOW_OBJECT
, ThreadListEntry
);
612 if (Window
->Parent
!= NULL
&& !IntIsDesktopWindow(Window
->Parent
))
616 if (Window
->Style
& WS_VISIBLE
)
618 hFoundWnd
= IntFindWindowToRepaint(Window
->Self
, Thread
);
619 if (hFoundWnd
!= NULL
)
621 ExReleaseFastMutex(&Thread
->WindowListLock
);
627 ExReleaseFastMutex(&Thread
->WindowListLock
);
632 Window
= IntGetWindowObject(hWnd
);
636 if ((Window
->UpdateRegion
!= NULL
||
637 Window
->Flags
& (WINDOWOBJECT_NEED_INTERNALPAINT
| WINDOWOBJECT_NEED_NCPAINT
)) &&
638 IntWndBelongsToThread(Window
, Thread
))
640 IntReleaseWindowObject(Window
);
644 ExAcquireFastMutex(&Window
->ChildrenListLock
);
646 for (Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
648 if (Child
->Style
& WS_VISIBLE
&&
649 (Child
->UpdateRegion
!= NULL
||
650 Child
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
||
651 Child
->Flags
& WINDOWOBJECT_NEED_NCPAINT
))
653 hFoundWnd
= Child
->Self
;
658 if (hFoundWnd
== NULL
)
660 for (Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
662 if (Child
->Style
& WS_VISIBLE
)
664 hFoundWnd
= IntFindWindowToRepaint(Child
->Self
, Thread
);
665 if (hFoundWnd
!= NULL
)
671 ExReleaseFastMutex(&Window
->ChildrenListLock
);
672 IntReleaseWindowObject(Window
);
679 IntGetPaintMessage(HWND hWnd
, PW32THREAD Thread
, MSG
*Message
,
682 PWINDOW_OBJECT Window
;
683 PUSER_MESSAGE_QUEUE MessageQueue
= (PUSER_MESSAGE_QUEUE
)Thread
->MessageQueue
;
685 if (!MessageQueue
->PaintPosted
)
689 Message
->hwnd
= IntFindWindowToRepaint(hWnd
, PsGetWin32Thread());
691 Message
->hwnd
= IntFindWindowToRepaint(NULL
, PsGetWin32Thread());
693 if (Message
->hwnd
== NULL
)
696 DPRINT1("PAINTING BUG: Thread marked as containing dirty windows, but no dirty windows found!\n");
697 /* FIXME: Lock the queue! */
698 MessageQueue
->PaintPosted
= 0;
699 MessageQueue
->PaintCount
= 0;
704 Window
= IntGetWindowObject(Message
->hwnd
);
707 if (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
)
709 Message
->message
= WM_NCPAINT
;
710 Message
->wParam
= (WPARAM
)Window
->NCUpdateRegion
;
714 Window
->NCUpdateRegion
= NULL
;
715 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
716 MsqDecPaintCountQueue(Window
->MessageQueue
);
723 UnsafeIntGetRgnBox(Window
->UpdateRegion
, &TempRect
);
724 DPRINT1("Sending WM_PAINT[2]: %d,%d-%d,%d\n",
725 TempRect
.left
, TempRect
.top
, TempRect
.right
, TempRect
.bottom
);
728 Message
->message
= WM_PAINT
;
729 Message
->wParam
= Message
->lParam
= 0;
730 if (Remove
&& Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
732 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
733 if (Window
->UpdateRegion
== NULL
)
735 MsqDecPaintCountQueue(Window
->MessageQueue
);
740 IntReleaseWindowObject(Window
);
748 IntFixCaret(HWND hWnd
, LPRECT lprc
, UINT flags
)
752 if (!NtUserGetGUIThreadInfo(0, &info
))
756 if (info
.hwndCaret
== hWnd
||
757 ((flags
& SW_SCROLLCHILDREN
) && IntIsChildWindow(hWnd
, info
.hwndCaret
)))
759 POINT pt
, FromOffset
, ToOffset
, Offset
;
761 pt
.x
= info
.rcCaret
.left
;
762 pt
.y
= info
.rcCaret
.top
;
764 IntGetClientOrigin(info
.hwndCaret
, &FromOffset
);
765 IntGetClientOrigin(hWnd
, &ToOffset
);
766 Offset
.x
= FromOffset
.x
- ToOffset
.x
;
767 Offset
.y
= FromOffset
.y
- ToOffset
.y
;
768 info
.rcCaret
.left
+= Offset
.x
;
769 info
.rcCaret
.top
+= Offset
.y
;
770 info
.rcCaret
.right
+= Offset
.x
;
771 info
.rcCaret
.bottom
+= Offset
.y
;
772 if (NtGdiIntersectRect(lprc
, lprc
, &info
.rcCaret
))
777 return info
.hwndCaret
;
784 /* PUBLIC FUNCTIONS ***********************************************************/
794 NtUserBeginPaint(HWND hWnd
, PAINTSTRUCT
* lPs
)
796 PWINDOW_OBJECT Window
;
801 if (!(Window
= IntGetWindowObject(hWnd
)))
803 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
807 NtUserHideCaret(hWnd
);
809 DcxFlags
= DCX_INTERSECTUPDATE
| DCX_WINDOWPAINT
| DCX_USESTYLE
;
811 lPs
->hdc
= NtUserGetDCEx(hWnd
, 0, DcxFlags
);
815 IntReleaseWindowObject(Window
);
819 /* IntRedrawWindow(Window, NULL, 0, RDW_NOINTERNALPAINT | RDW_VALIDATE | RDW_NOCHILDREN);*/
821 if (Window
->Flags
& WINDOWOBJECT_NEED_ERASEBKGND
)
824 UnsafeIntGetRgnBox(Window
->UpdateRegion
, &TempRect
);
825 DPRINT1("Sending WM_ERASEBKGND[2]: %d,%d-%d,%d\n",
826 TempRect
.left
, TempRect
.top
, TempRect
.right
, TempRect
.bottom
);
830 if (Window
->UpdateRegion
!= NULL
)
832 MsqDecPaintCountQueue(Window
->MessageQueue
);
833 IntValidateParent(Window
, Window
->UpdateRegion
);
834 NtGdiDeleteObject(Window
->UpdateRegion
);
835 Window
->UpdateRegion
= NULL
;
838 IntGetClientRect(Window
, &ClientRect
);
839 IntGdiGetClipBox(lPs
->hdc
, &ClipRect
);
840 NtGdiLPtoDP(lPs
->hdc
, (LPPOINT
)&ClipRect
, 2);
841 NtGdiIntersectRect(&lPs
->rcPaint
, &ClientRect
, &ClipRect
);
842 NtGdiDPtoLP(lPs
->hdc
, (LPPOINT
)&lPs
->rcPaint
, 2);
844 if (Window
->Flags
& WINDOWOBJECT_NEED_ERASEBKGND
)
846 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
847 lPs
->fErase
= !IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)lPs
->hdc
, 0);
854 IntReleaseWindowObject(Window
);
867 NtUserEndPaint(HWND hWnd
, CONST PAINTSTRUCT
* lPs
)
869 NtUserReleaseDC(hWnd
, lPs
->hdc
);
870 NtUserShowCaret(hWnd
);
876 * NtUserInvalidateRect
883 NtUserInvalidateRect(HWND hWnd
, CONST RECT
*Rect
, BOOL Erase
)
885 return NtUserRedrawWindow(hWnd
, Rect
, 0, RDW_INVALIDATE
| (Erase
? RDW_ERASE
: 0));
889 * NtUserInvalidateRgn
896 NtUserInvalidateRgn(HWND hWnd
, HRGN Rgn
, BOOL Erase
)
898 return NtUserRedrawWindow(hWnd
, NULL
, Rgn
, RDW_INVALIDATE
| (Erase
? RDW_ERASE
: 0));
909 NtUserValidateRgn(HWND hWnd
, HRGN hRgn
)
911 return NtUserRedrawWindow(hWnd
, NULL
, hRgn
, RDW_VALIDATE
| RDW_NOCHILDREN
);
922 NtUserUpdateWindow(HWND hWnd
)
924 return NtUserRedrawWindow(hWnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
935 NtUserGetUpdateRgn(HWND hWnd
, HRGN hRgn
, BOOL bErase
)
937 PWINDOW_OBJECT Window
;
940 if (!(Window
= IntGetWindowObject(hWnd
)))
942 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
946 if (Window
->UpdateRegion
== NULL
)
948 RegionType
= (NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0) ? NULLREGION
: ERROR
);
952 RegionType
= NtGdiCombineRgn(hRgn
, Window
->UpdateRegion
, hRgn
, RGN_COPY
);
955 Window
->WindowRect
.left
- Window
->ClientRect
.left
,
956 Window
->WindowRect
.top
- Window
->ClientRect
.top
);
959 IntReleaseWindowObject(Window
);
961 if (bErase
&& RegionType
!= NULLREGION
&& RegionType
!= ERROR
)
963 NtUserRedrawWindow(hWnd
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
970 * NtUserGetUpdateRect
977 NtUserGetUpdateRect(HWND hWnd
, LPRECT lpRect
, BOOL fErase
)
979 HRGN hRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
983 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
987 NtUserGetUpdateRgn(hWnd
, hRgn
, fErase
);
988 NtGdiGetRgnBox(hRgn
, lpRect
);
990 return lpRect
->left
< lpRect
->right
&& lpRect
->top
< lpRect
->bottom
;
1001 NtUserRedrawWindow(HWND hWnd
, CONST RECT
*lprcUpdate
, HRGN hrgnUpdate
,
1004 RECT SafeUpdateRect
;
1008 if (!(Wnd
= IntGetWindowObject(hWnd
? hWnd
: IntGetDesktopWindow())))
1010 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
1014 if (lprcUpdate
!= NULL
)
1016 Status
= MmCopyFromCaller(&SafeUpdateRect
, (PRECT
)lprcUpdate
,
1019 if (!NT_SUCCESS(Status
))
1021 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1026 Status
= IntRedrawWindow(Wnd
, NULL
== lprcUpdate
? NULL
: &SafeUpdateRect
,
1029 if (!NT_SUCCESS(Status
))
1031 /* IntRedrawWindow fails only in case that flags are invalid */
1032 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1047 NtUserScrollDC(HDC hDC
, INT dx
, INT dy
, const RECT
*lprcScroll
,
1048 const RECT
*lprcClip
, HRGN hrgnUpdate
, LPRECT lprcUpdate
)
1050 RECT rSrc
, rClipped_src
, rClip
, rDst
, offset
;
1053 * Compute device clipping region (in device coordinates).
1059 IntGdiGetClipBox(hDC
, &rSrc
);
1060 NtGdiLPtoDP(hDC
, (LPPOINT
)&rSrc
, 2);
1065 IntGdiGetClipBox(hDC
, &rClip
);
1066 NtGdiLPtoDP(hDC
, (LPPOINT
)&rClip
, 2);
1068 NtGdiIntersectRect(&rClipped_src
, &rSrc
, &rClip
);
1070 rDst
= rClipped_src
;
1071 NtGdiSetRect(&offset
, 0, 0, dx
, dy
);
1072 NtGdiLPtoDP(hDC
, (LPPOINT
)&offset
, 2);
1073 NtGdiOffsetRect(&rDst
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
1074 NtGdiIntersectRect(&rDst
, &rDst
, &rClip
);
1077 * Copy bits, if possible.
1080 if (rDst
.bottom
> rDst
.top
&& rDst
.right
> rDst
.left
)
1082 RECT rDst_lp
= rDst
, rSrc_lp
= rDst
;
1084 NtGdiOffsetRect(&rSrc_lp
, offset
.left
- offset
.right
, offset
.top
- offset
.bottom
);
1085 NtGdiDPtoLP(hDC
, (LPPOINT
)&rDst_lp
, 2);
1086 NtGdiDPtoLP(hDC
, (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
,
1095 * Compute update areas. This is the clipped source or'ed with the
1096 * unclipped source translated minus the clipped src translated (rDst)
1097 * all clipped to rClip.
1100 if (hrgnUpdate
|| lprcUpdate
)
1102 HRGN hRgn
= hrgnUpdate
, hRgn2
;
1105 NtGdiSetRectRgn(hRgn
, rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
1107 hRgn
= NtGdiCreateRectRgn(rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
1109 hRgn2
= NtGdiCreateRectRgnIndirect(&rSrc
);
1110 NtGdiOffsetRgn(hRgn2
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
1111 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_OR
);
1113 NtGdiSetRectRgn(hRgn2
, rDst
.left
, rDst
.top
, rDst
.right
, rDst
.bottom
);
1114 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_DIFF
);
1116 NtGdiSetRectRgn(hRgn2
, rClip
.left
, rClip
.top
, rClip
.right
, rClip
.bottom
);
1117 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_AND
);
1121 NtGdiGetRgnBox(hRgn
, lprcUpdate
);
1123 /* Put the lprcUpdate in logical coordinate */
1124 NtGdiDPtoLP(hDC
, (LPPOINT
)lprcUpdate
, 2);
1127 NtGdiDeleteObject(hRgn
);
1128 NtGdiDeleteObject(hRgn2
);
1134 * NtUserScrollWindowEx
1141 NtUserScrollWindowEx(HWND hWnd
, INT dx
, INT dy
, const RECT
*rect
,
1142 const RECT
*clipRect
, HRGN hrgnUpdate
, LPRECT rcUpdate
, UINT flags
)
1144 RECT rc
, cliprc
, caretrc
;
1146 PWINDOW_OBJECT Window
;
1150 BOOL bUpdate
= (rcUpdate
|| hrgnUpdate
|| flags
& (SW_INVALIDATE
| SW_ERASE
));
1151 BOOL bOwnRgn
= TRUE
;
1153 Window
= IntGetWindowObject(hWnd
);
1154 if (!Window
|| !IntIsWindowDrawable(Window
))
1156 IntReleaseWindowObject(Window
);
1160 IntGetClientRect(Window
, &rc
);
1162 NtGdiIntersectRect(&rc
, &rc
, rect
);
1165 NtGdiIntersectRect(&cliprc
, &rc
, clipRect
);
1169 if (cliprc
.right
<= cliprc
.left
|| cliprc
.bottom
<= cliprc
.top
||
1170 (dx
== 0 && dy
== 0))
1176 hwndCaret
= IntFixCaret(hWnd
, &caretrc
, flags
);
1181 hrgnUpdate
= NtGdiCreateRectRgn(0, 0, 0, 0);
1183 hDC
= NtUserGetDCEx( hWnd
, 0, DCX_CACHE
| DCX_USESTYLE
);
1186 HRGN hRgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
1188 NtUserScrollDC(hDC
, dx
, dy
, &rc
, &cliprc
, hrgnUpdate
, rcUpdate
);
1189 NtUserReleaseDC(hWnd
, hDC
);
1191 NtGdiCombineRgn(hrgnUpdate
, hrgnUpdate
, hRgn
, RGN_OR
);
1193 NtUserRedrawWindow(hWnd
, NULL
, hRgn
, RDW_INVALIDATE
| RDW_ERASE
);
1194 NtGdiDeleteObject(hRgn
);
1198 * Take into account the fact that some damage may have occurred during
1202 hrgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
1203 Result
= NtUserGetUpdateRgn(hWnd
, hrgnTemp
, FALSE
);
1204 if (Result
!= NULLREGION
)
1206 HRGN hrgnClip
= NtGdiCreateRectRgnIndirect(&cliprc
);
1207 NtGdiOffsetRgn(hrgnTemp
, dx
, dy
);
1208 NtGdiCombineRgn(hrgnTemp
, hrgnTemp
, hrgnClip
, RGN_AND
);
1209 NtUserRedrawWindow(hWnd
, NULL
, hrgnTemp
, RDW_INVALIDATE
| RDW_ERASE
);
1210 NtGdiDeleteObject(hrgnClip
);
1212 NtGdiDeleteObject(hrgnTemp
);
1214 if (flags
& SW_SCROLLCHILDREN
)
1216 HWND
*List
= IntWinListChildren(Window
);
1223 for (i
= 0; List
[i
]; i
++)
1225 NtUserGetWindowRect(List
[i
], &r
);
1226 IntGetClientOrigin(hWnd
, &ClientOrigin
);
1227 r
.left
-= ClientOrigin
.x
;
1228 r
.top
-= ClientOrigin
.y
;
1229 r
.right
-= ClientOrigin
.x
;
1230 r
.bottom
-= ClientOrigin
.y
;
1231 if (!rect
|| NtGdiIntersectRect(&dummy
, &r
, &rc
))
1232 WinPosSetWindowPos(List
[i
], 0, r
.left
+ dx
, r
.top
+ dy
, 0, 0,
1233 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
|
1240 if (flags
& (SW_INVALIDATE
| SW_ERASE
))
1241 NtUserRedrawWindow(hWnd
, NULL
, hrgnUpdate
, RDW_INVALIDATE
| RDW_ERASE
|
1242 ((flags
& SW_ERASE
) ? RDW_ERASENOW
: 0) |
1243 ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0));
1245 if (bOwnRgn
&& hrgnUpdate
)
1246 NtGdiDeleteObject(hrgnUpdate
);
1250 IntSetCaretPos(caretrc
.left
+ dx
, caretrc
.top
+ dy
);
1251 NtUserShowCaret(hwndCaret
);
1254 IntReleaseWindowObject(Window
);