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.70 2004/02/21 22:22:26 navaraf 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>
55 #include <win32k/debug1.h>
57 /* PRIVATE FUNCTIONS **********************************************************/
60 IntValidateParent(PWINDOW_OBJECT Child
, HRGN ValidRegion
)
63 PWINDOW_OBJECT ParentWindow
;
65 Parent
= NtUserGetAncestor(Child
->Self
, GA_PARENT
);
68 ParentWindow
= IntGetWindowObject(Parent
);
69 if (ParentWindow
&& !(ParentWindow
->Style
& WS_CLIPCHILDREN
))
71 ExAcquireFastMutex(&ParentWindow
->UpdateLock
);
72 if (ParentWindow
->UpdateRegion
!= 0)
77 * We must offset the child region by the offset of the
78 * child rect in the parent.
80 OffsetX
= Child
->WindowRect
.left
- ParentWindow
->WindowRect
.left
;
81 OffsetY
= Child
->WindowRect
.top
- ParentWindow
->WindowRect
.top
;
82 NtGdiOffsetRgn(ValidRegion
, OffsetX
, OffsetY
);
83 NtGdiCombineRgn(ParentWindow
->UpdateRegion
, ParentWindow
->UpdateRegion
,
84 ValidRegion
, RGN_DIFF
);
85 /* FIXME: If the resulting region is empty, remove fake posted paint message */
86 NtGdiOffsetRgn(ValidRegion
, -OffsetX
, -OffsetY
);
88 ExReleaseFastMutex(&ParentWindow
->UpdateLock
);
92 IntReleaseWindowObject(ParentWindow
);
93 Parent
= NtUserGetAncestor(Parent
, GA_PARENT
);
105 * Internal function used by IntRedrawWindow.
109 IntPaintWindows(PWINDOW_OBJECT Window
, ULONG Flags
)
112 HWND hWnd
= Window
->Self
;
115 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
117 if (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
)
119 ExAcquireFastMutex(&Window
->UpdateLock
);
120 if (Window
->NCUpdateRegion
)
122 IntValidateParent(Window
, Window
->NCUpdateRegion
);
124 TempRegion
= Window
->NCUpdateRegion
;
125 Window
->NCUpdateRegion
= NULL
;
126 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
127 MsqDecPaintCountQueue(Window
->MessageQueue
);
128 ExReleaseFastMutex(&Window
->UpdateLock
);
129 IntSendMessage(hWnd
, WM_NCPAINT
, (WPARAM
)TempRegion
, 0);
132 if (Window
->Flags
& WINDOWOBJECT_NEED_ERASEBKGND
)
134 if (Window
->UpdateRegion
)
136 IntValidateParent(Window
, Window
->UpdateRegion
);
137 hDC
= NtUserGetDCEx(hWnd
, 0, DCX_CACHE
| DCX_USESTYLE
|
138 DCX_INTERSECTUPDATE
);
141 if (IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)hDC
, 0))
143 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
145 NtUserReleaseDC(hWnd
, hDC
);
150 if (Flags
& RDW_UPDATENOW
)
152 if (Window
->UpdateRegion
!= NULL
||
153 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
155 IntSendMessage(hWnd
, WM_PAINT
, 0, 0);
156 ExAcquireFastMutex(&Window
->UpdateLock
);
157 if (Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
159 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
160 if (Window
->UpdateRegion
== NULL
)
162 MsqDecPaintCountQueue(Window
->MessageQueue
);
165 ExReleaseFastMutex(&Window
->UpdateLock
);
171 * Check that the window is still valid at this point
174 if (! IntIsWindow(hWnd
))
180 * Paint child windows.
182 if (!(Flags
& RDW_NOCHILDREN
) && !(Window
->Style
& WS_MINIMIZE
) &&
183 ((Flags
& RDW_ALLCHILDREN
) || !(Window
->Style
& WS_CLIPCHILDREN
)))
187 if ((List
= IntWinListChildren(Window
)))
189 for (phWnd
= List
; *phWnd
; ++phWnd
)
191 Window
= IntGetWindowObject(*phWnd
);
192 if (Window
&& (Window
->Style
& WS_VISIBLE
))
194 IntPaintWindows(Window
, Flags
);
195 IntReleaseWindowObject(Window
);
204 * IntInvalidateWindows
206 * Internal function used by IntRedrawWindow.
210 IntInvalidateWindows(PWINDOW_OBJECT Window
, HRGN hRgn
, ULONG Flags
)
213 BOOL HadPaintMessage
, HadNCPaintMessage
;
214 BOOL HasPaintMessage
, HasNCPaintMessage
;
217 * Clip the given region with window rectangle (or region)
221 if (!Window
->WindowRegion
)
226 hRgnWindow
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
227 NtGdiOffsetRgn(hRgnWindow
,
228 -Window
->WindowRect
.left
,
229 -Window
->WindowRect
.top
);
230 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, hRgnWindow
, RGN_AND
);
231 NtGdiDeleteObject(hRgnWindow
);
236 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, Window
->WindowRegion
, RGN_AND
);
241 * Save current state of pending updates
244 ExAcquireFastMutex(&Window
->UpdateLock
);
245 HadPaintMessage
= Window
->UpdateRegion
!= NULL
||
246 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
;
247 HadNCPaintMessage
= Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
;
250 * Update the region and flags
253 if (Flags
& RDW_INVALIDATE
&& RgnType
!= NULLREGION
)
255 if (Window
->UpdateRegion
== NULL
)
257 Window
->UpdateRegion
= NtGdiCreateRectRgn(0, 0, 0, 0);
260 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
261 hRgn
, RGN_OR
) == NULLREGION
)
263 NtGdiDeleteObject(Window
->UpdateRegion
);
264 Window
->UpdateRegion
= NULL
;
267 if (Flags
& RDW_FRAME
)
268 Window
->Flags
|= WINDOWOBJECT_NEED_NCPAINT
;
269 if (Flags
& RDW_ERASE
)
270 Window
->Flags
|= WINDOWOBJECT_NEED_ERASEBKGND
;
275 if (Flags
& RDW_VALIDATE
&& RgnType
!= NULLREGION
)
277 if (Window
->UpdateRegion
!= NULL
)
279 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
280 hRgn
, RGN_DIFF
) == NULLREGION
)
282 NtGdiDeleteObject(Window
->UpdateRegion
);
283 Window
->UpdateRegion
= NULL
;
287 if (Window
->UpdateRegion
== NULL
)
288 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
289 if (Flags
& RDW_NOFRAME
)
290 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
291 if (Flags
& RDW_NOERASE
)
292 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
295 if (Flags
& RDW_INTERNALPAINT
)
297 Window
->Flags
|= WINDOWOBJECT_NEED_INTERNALPAINT
;
300 if (Flags
& RDW_NOINTERNALPAINT
)
302 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
306 * Split the nonclient update region.
310 HRGN hRgnWindow
, hRgnNonClient
;
312 hRgnWindow
= UnsafeIntCreateRectRgnIndirect(&Window
->ClientRect
);
313 NtGdiOffsetRgn(hRgnWindow
,
314 -Window
->WindowRect
.left
,
315 -Window
->WindowRect
.top
);
317 hRgnNonClient
= NtGdiCreateRectRgn(0, 0, 0, 0);
318 if (NtGdiCombineRgn(hRgnNonClient
, Window
->UpdateRegion
,
319 hRgnWindow
, RGN_DIFF
) == NULLREGION
)
321 NtGdiDeleteObject(hRgnNonClient
);
322 hRgnNonClient
= NULL
;
326 * Remove the nonclient region from the standard update region.
329 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
330 hRgnWindow
, RGN_AND
) == NULLREGION
)
332 NtGdiDeleteObject(Window
->UpdateRegion
);
333 Window
->UpdateRegion
= NULL
;
336 if (Window
->NCUpdateRegion
== NULL
)
338 Window
->NCUpdateRegion
= hRgnNonClient
;
342 NtGdiCombineRgn(Window
->NCUpdateRegion
, Window
->NCUpdateRegion
,
343 hRgnNonClient
, RGN_OR
);
346 NtGdiDeleteObject(hRgnWindow
);
350 * Process children if needed
353 if (!(Flags
& RDW_NOCHILDREN
) && !(Window
->Style
& WS_MINIMIZE
) &&
354 ((Flags
& RDW_ALLCHILDREN
) || !(Window
->Style
& WS_CLIPCHILDREN
)))
357 PWINDOW_OBJECT Child
;
359 if ((List
= IntWinListChildren(Window
)))
361 for (phWnd
= List
; *phWnd
; ++phWnd
)
363 Child
= IntGetWindowObject(*phWnd
);
368 if (Child
->Style
& WS_VISIBLE
)
371 * Recursive call to update children UpdateRegion
373 HRGN hRgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
374 NtGdiCombineRgn(hRgnTemp
, hRgn
, 0, RGN_COPY
);
375 NtGdiOffsetRgn(hRgnTemp
,
376 Window
->WindowRect
.left
- Child
->WindowRect
.left
,
377 Window
->WindowRect
.top
- Child
->WindowRect
.top
);
378 IntInvalidateWindows(Child
, hRgnTemp
, Flags
);
379 NtGdiDeleteObject(hRgnTemp
);
381 IntReleaseWindowObject(Child
);
388 * Fake post paint messages to window message queue if needed
391 HasPaintMessage
= Window
->UpdateRegion
!= NULL
||
392 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
;
393 HasNCPaintMessage
= Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
;
395 if (HasPaintMessage
!= HadPaintMessage
)
398 MsqDecPaintCountQueue(Window
->MessageQueue
);
400 MsqIncPaintCountQueue(Window
->MessageQueue
);
403 if (HasNCPaintMessage
!= HadNCPaintMessage
)
405 if (HadNCPaintMessage
)
406 MsqDecPaintCountQueue(Window
->MessageQueue
);
408 MsqIncPaintCountQueue(Window
->MessageQueue
);
411 ExReleaseFastMutex(&Window
->UpdateLock
);
415 * IntIsWindowDrawable
418 * Window is drawable when it is visible and all parents are not
423 IntIsWindowDrawable(PWINDOW_OBJECT Window
)
425 PWINDOW_OBJECT Wnd
= Window
;
427 for (; Wnd
; Wnd
= Wnd
->Parent
)
429 if (!(Wnd
->Style
& WS_VISIBLE
) ||
430 ((Wnd
->Style
& WS_MINIMIZE
) && (Wnd
!= Window
)))
440 * Internal version of NtUserRedrawWindow that takes WINDOW_OBJECT as
445 IntRedrawWindow(PWINDOW_OBJECT Window
, const RECT
* UpdateRect
, HRGN UpdateRgn
,
452 * Validation of passed parameters.
455 if (!IntIsWindowDrawable(Window
) ||
456 (Flags
& (RDW_VALIDATE
| RDW_INVALIDATE
)) ==
457 (RDW_VALIDATE
| RDW_INVALIDATE
))
464 * Transform the parameters UpdateRgn and UpdateRect into
465 * a region hRgn specified in window coordinates.
468 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
))
470 if (UpdateRgn
!= NULL
)
472 hRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
473 NtGdiCombineRgn(hRgn
, UpdateRgn
, NULL
, RGN_COPY
);
475 Window
->ClientRect
.left
- Window
->WindowRect
.left
,
476 Window
->ClientRect
.top
- Window
->WindowRect
.top
);
478 if (UpdateRect
!= NULL
)
480 hRgn
= UnsafeIntCreateRectRgnIndirect((RECT
*)UpdateRect
);
482 Window
->ClientRect
.left
- Window
->WindowRect
.left
,
483 Window
->ClientRect
.top
- Window
->WindowRect
.top
);
485 if ((Flags
& (RDW_INVALIDATE
| RDW_FRAME
)) == (RDW_INVALIDATE
| RDW_FRAME
) ||
486 (Flags
& (RDW_VALIDATE
| RDW_NOFRAME
)) == (RDW_VALIDATE
| RDW_NOFRAME
))
488 hRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
490 -Window
->WindowRect
.left
,
491 -Window
->WindowRect
.top
);
495 hRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->ClientRect
);
497 -Window
->WindowRect
.left
,
498 -Window
->WindowRect
.top
);
504 * Adjust the window update region depending on hRgn and flags.
507 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
| RDW_INTERNALPAINT
| RDW_NOINTERNALPAINT
))
509 IntInvalidateWindows(Window
, hRgn
, Flags
);
514 * Repaint and erase windows if needed.
517 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
519 IntPaintWindows(Window
, Flags
);
529 NtGdiDeleteObject(hRgn
);
536 IntIsWindowDirty(PWINDOW_OBJECT Window
)
538 return (Window
->Style
& WS_VISIBLE
) &&
539 ((Window
->UpdateRegion
!= NULL
) ||
540 (Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
) ||
541 (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
));
545 IntFindWindowToRepaint(HWND hWnd
, PW32THREAD Thread
)
547 PWINDOW_OBJECT Window
;
548 PWINDOW_OBJECT Child
;
549 HWND hFoundWnd
= NULL
;
551 Window
= IntGetWindowObject(hWnd
);
555 if (IntIsWindowDirty(Window
) &&
556 IntWndBelongsToThread(Window
, Thread
))
558 IntReleaseWindowObject(Window
);
562 ExAcquireFastMutex(&Window
->ChildrenListLock
);
564 for (Child
= Window
->LastChild
; Child
; Child
= Child
->PrevSibling
)
566 if (IntIsWindowDirty(Child
) &&
567 IntWndBelongsToThread(Child
, Thread
))
569 hFoundWnd
= Child
->Self
;
574 if (hFoundWnd
== NULL
)
576 for (Child
= Window
->LastChild
; Child
; Child
= Child
->PrevSibling
)
578 if (Child
->Style
& WS_VISIBLE
)
580 hFoundWnd
= IntFindWindowToRepaint(Child
->Self
, Thread
);
581 if (hFoundWnd
!= NULL
)
587 ExReleaseFastMutex(&Window
->ChildrenListLock
);
588 IntReleaseWindowObject(Window
);
594 IntGetPaintMessage(HWND hWnd
, PW32THREAD Thread
, MSG
*Message
,
597 PWINDOW_OBJECT Window
;
598 PUSER_MESSAGE_QUEUE MessageQueue
= (PUSER_MESSAGE_QUEUE
)Thread
->MessageQueue
;
600 if (!MessageQueue
->PaintPosted
)
604 Message
->hwnd
= IntFindWindowToRepaint(hWnd
, PsGetWin32Thread());
606 Message
->hwnd
= IntFindWindowToRepaint(IntGetDesktopWindow(), PsGetWin32Thread());
608 if (Message
->hwnd
== NULL
)
611 DPRINT1("PAINTING BUG: Thread marked as containing dirty windows, but no dirty windows found!\n");
613 ExAcquireFastMutex(&MessageQueue
->Lock
);
614 MessageQueue
->PaintPosted
= 0;
615 MessageQueue
->PaintCount
= 0;
616 ExReleaseFastMutex(&MessageQueue
->Lock
);
620 Window
= IntGetWindowObject(Message
->hwnd
);
623 ExAcquireFastMutex(&Window
->UpdateLock
);
624 if (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
)
626 Message
->message
= WM_NCPAINT
;
627 Message
->wParam
= (WPARAM
)Window
->NCUpdateRegion
;
631 IntValidateParent(Window
, Window
->NCUpdateRegion
);
632 Window
->NCUpdateRegion
= NULL
;
633 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
634 MsqDecPaintCountQueue(Window
->MessageQueue
);
638 Message
->message
= WM_PAINT
;
639 Message
->wParam
= Message
->lParam
= 0;
640 if (Remove
&& Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
642 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
643 if (Window
->UpdateRegion
== NULL
)
645 MsqDecPaintCountQueue(Window
->MessageQueue
);
649 ExReleaseFastMutex(&Window
->UpdateLock
);
651 IntReleaseWindowObject(Window
);
659 IntFixCaret(HWND hWnd
, LPRECT lprc
, UINT flags
)
661 PDESKTOP_OBJECT Desktop
;
662 PTHRDCARETINFO CaretInfo
;
665 Desktop
= PsGetCurrentThread()->Win32Thread
->Desktop
;
666 CaretInfo
= ((PUSER_MESSAGE_QUEUE
)Desktop
->ActiveMessageQueue
)->CaretInfo
;
667 hWndCaret
= CaretInfo
->hWnd
;
668 if (hWndCaret
== hWnd
||
669 ((flags
& SW_SCROLLCHILDREN
) && IntIsChildWindow(hWnd
, hWndCaret
)))
671 POINT pt
, FromOffset
, ToOffset
, Offset
;
674 pt
.x
= CaretInfo
->Pos
.x
;
675 pt
.y
= CaretInfo
->Pos
.y
;
676 IntGetClientOrigin(hWndCaret
, &FromOffset
);
677 IntGetClientOrigin(hWnd
, &ToOffset
);
678 Offset
.x
= FromOffset
.x
- ToOffset
.x
;
679 Offset
.y
= FromOffset
.y
- ToOffset
.y
;
682 rcCaret
.right
= pt
.x
+ CaretInfo
->Size
.cx
;
683 rcCaret
.bottom
= pt
.y
+ CaretInfo
->Size
.cy
;
684 if (NtGdiIntersectRect(lprc
, lprc
, &rcCaret
))
696 /* PUBLIC FUNCTIONS ***********************************************************/
706 NtUserBeginPaint(HWND hWnd
, PAINTSTRUCT
* lPs
)
708 PWINDOW_OBJECT Window
;
710 if (!(Window
= IntGetWindowObject(hWnd
)))
712 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
716 NtUserHideCaret(hWnd
);
718 lPs
->hdc
= NtUserGetDCEx(hWnd
, 0, DCX_INTERSECTUPDATE
| DCX_WINDOWPAINT
|
723 IntReleaseWindowObject(Window
);
727 ExAcquireFastMutex(&Window
->UpdateLock
);
728 if (Window
->UpdateRegion
!= NULL
)
730 MsqDecPaintCountQueue(Window
->MessageQueue
);
731 IntValidateParent(Window
, Window
->UpdateRegion
);
732 NtGdiGetRgnBox(Window
->UpdateRegion
, &lPs
->rcPaint
);
733 NtGdiOffsetRect(&lPs
->rcPaint
,
734 Window
->WindowRect
.left
- Window
->ClientRect
.left
,
735 Window
->WindowRect
.top
- Window
->ClientRect
.top
);
736 NtGdiDeleteObject(Window
->UpdateRegion
);
737 Window
->UpdateRegion
= NULL
;
741 NtUserGetClientRect(Window
, &lPs
->rcPaint
);
743 ExReleaseFastMutex(&Window
->UpdateLock
);
745 if (Window
->Flags
& WINDOWOBJECT_NEED_ERASEBKGND
)
747 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
748 lPs
->fErase
= !IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)lPs
->hdc
, 0);
755 IntReleaseWindowObject(Window
);
768 NtUserEndPaint(HWND hWnd
, CONST PAINTSTRUCT
* lPs
)
770 NtUserReleaseDC(hWnd
, lPs
->hdc
);
771 NtUserShowCaret(hWnd
);
777 * NtUserInvalidateRect
784 NtUserInvalidateRect(HWND hWnd
, CONST RECT
*Rect
, BOOL Erase
)
786 return NtUserRedrawWindow(hWnd
, Rect
, 0, RDW_INVALIDATE
| (Erase
? RDW_ERASE
: 0));
790 * NtUserInvalidateRgn
797 NtUserInvalidateRgn(HWND hWnd
, HRGN Rgn
, BOOL Erase
)
799 return NtUserRedrawWindow(hWnd
, NULL
, Rgn
, RDW_INVALIDATE
| (Erase
? RDW_ERASE
: 0));
810 NtUserValidateRgn(HWND hWnd
, HRGN hRgn
)
812 return NtUserRedrawWindow(hWnd
, NULL
, hRgn
, RDW_VALIDATE
| RDW_NOCHILDREN
);
823 NtUserUpdateWindow(HWND hWnd
)
825 return NtUserRedrawWindow(hWnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
836 NtUserGetUpdateRgn(HWND hWnd
, HRGN hRgn
, BOOL bErase
)
838 PWINDOW_OBJECT Window
;
841 if (!(Window
= IntGetWindowObject(hWnd
)))
843 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
847 if (Window
->UpdateRegion
== NULL
)
849 RegionType
= (NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0) ? NULLREGION
: ERROR
);
853 RegionType
= NtGdiCombineRgn(hRgn
, Window
->UpdateRegion
, hRgn
, RGN_COPY
);
856 Window
->WindowRect
.left
- Window
->ClientRect
.left
,
857 Window
->WindowRect
.top
- Window
->ClientRect
.top
);
860 IntReleaseWindowObject(Window
);
862 if (bErase
&& RegionType
!= NULLREGION
&& RegionType
!= ERROR
)
864 NtUserRedrawWindow(hWnd
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
871 * NtUserGetUpdateRect
878 NtUserGetUpdateRect(HWND hWnd
, LPRECT lpRect
, BOOL fErase
)
880 HRGN hRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
884 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
888 NtUserGetUpdateRgn(hWnd
, hRgn
, fErase
);
889 NtGdiGetRgnBox(hRgn
, lpRect
);
890 NtGdiDeleteObject(hRgn
);
892 return lpRect
->left
< lpRect
->right
&& lpRect
->top
< lpRect
->bottom
;
903 NtUserRedrawWindow(HWND hWnd
, CONST RECT
*lprcUpdate
, HRGN hrgnUpdate
,
910 if (!(Wnd
= IntGetWindowObject(hWnd
? hWnd
: IntGetDesktopWindow())))
912 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
916 if (lprcUpdate
!= NULL
)
918 Status
= MmCopyFromCaller(&SafeUpdateRect
, (PRECT
)lprcUpdate
,
921 if (!NT_SUCCESS(Status
))
923 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
924 IntReleaseWindowObject(Wnd
);
929 Status
= IntRedrawWindow(Wnd
, NULL
== lprcUpdate
? NULL
: &SafeUpdateRect
,
932 if (!NT_SUCCESS(Status
))
934 /* IntRedrawWindow fails only in case that flags are invalid */
935 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
936 IntReleaseWindowObject(Wnd
);
940 IntReleaseWindowObject(Wnd
);
952 NtUserScrollDC(HDC hDC
, INT dx
, INT dy
, const RECT
*lprcScroll
,
953 const RECT
*lprcClip
, HRGN hrgnUpdate
, LPRECT lprcUpdate
)
955 RECT rSrc
, rClipped_src
, rClip
, rDst
, offset
;
959 * Compute device clipping region (in device coordinates).
970 IntGdiGetClipBox(hDC
, &rSrc
);
971 IntLPtoDP(DC
, (LPPOINT
)&rSrc
, 2);
976 IntGdiGetClipBox(hDC
, &rClip
);
977 IntLPtoDP(DC
, (LPPOINT
)&rClip
, 2);
979 NtGdiIntersectRect(&rClipped_src
, &rSrc
, &rClip
);
982 NtGdiSetRect(&offset
, 0, 0, dx
, dy
);
983 IntLPtoDP(DC
, (LPPOINT
)&offset
, 2);
984 NtGdiOffsetRect(&rDst
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
985 NtGdiIntersectRect(&rDst
, &rDst
, &rClip
);
988 * Copy bits, if possible.
991 if (rDst
.bottom
> rDst
.top
&& rDst
.right
> rDst
.left
)
993 RECT rDst_lp
= rDst
, rSrc_lp
= rDst
;
995 NtGdiOffsetRect(&rSrc_lp
, offset
.left
- offset
.right
, offset
.top
- offset
.bottom
);
996 IntDPtoLP(DC
, (LPPOINT
)&rDst_lp
, 2);
997 IntDPtoLP(DC
, (LPPOINT
)&rSrc_lp
, 2);
1000 if (!NtGdiBitBlt(hDC
, rDst_lp
.left
, rDst_lp
.top
, rDst_lp
.right
- rDst_lp
.left
,
1001 rDst_lp
.bottom
- rDst_lp
.top
, hDC
, rSrc_lp
.left
, rSrc_lp
.top
,
1011 * Compute update areas. This is the clipped source or'ed with the
1012 * unclipped source translated minus the clipped src translated (rDst)
1013 * all clipped to rClip.
1016 if (hrgnUpdate
|| lprcUpdate
)
1018 HRGN hRgn
= hrgnUpdate
, hRgn2
;
1021 NtGdiSetRectRgn(hRgn
, rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
1023 hRgn
= NtGdiCreateRectRgn(rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
1025 hRgn2
= UnsafeIntCreateRectRgnIndirect(&rSrc
);
1026 NtGdiOffsetRgn(hRgn2
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
1027 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_OR
);
1029 NtGdiSetRectRgn(hRgn2
, rDst
.left
, rDst
.top
, rDst
.right
, rDst
.bottom
);
1030 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_DIFF
);
1032 NtGdiSetRectRgn(hRgn2
, rClip
.left
, rClip
.top
, rClip
.right
, rClip
.bottom
);
1033 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_AND
);
1037 NtGdiGetRgnBox(hRgn
, lprcUpdate
);
1039 /* Put the lprcUpdate in logical coordinate */
1040 NtGdiDPtoLP(hDC
, (LPPOINT
)lprcUpdate
, 2);
1043 NtGdiDeleteObject(hRgn
);
1044 NtGdiDeleteObject(hRgn2
);
1050 * NtUserScrollWindowEx
1057 NtUserScrollWindowEx(HWND hWnd
, INT dx
, INT dy
, const RECT
*rect
,
1058 const RECT
*clipRect
, HRGN hrgnUpdate
, LPRECT rcUpdate
, UINT flags
)
1060 RECT rc
, cliprc
, caretrc
;
1062 PWINDOW_OBJECT Window
;
1066 BOOL bUpdate
= (rcUpdate
|| hrgnUpdate
|| flags
& (SW_INVALIDATE
| SW_ERASE
));
1067 BOOL bOwnRgn
= TRUE
;
1069 Window
= IntGetWindowObject(hWnd
);
1070 if (!Window
|| !IntIsWindowDrawable(Window
))
1072 IntReleaseWindowObject(Window
);
1076 IntGetClientRect(Window
, &rc
);
1078 NtGdiIntersectRect(&rc
, &rc
, rect
);
1081 NtGdiIntersectRect(&cliprc
, &rc
, clipRect
);
1085 if (cliprc
.right
<= cliprc
.left
|| cliprc
.bottom
<= cliprc
.top
||
1086 (dx
== 0 && dy
== 0))
1092 hwndCaret
= IntFixCaret(hWnd
, &caretrc
, flags
);
1097 hrgnUpdate
= NtGdiCreateRectRgn(0, 0, 0, 0);
1099 hDC
= NtUserGetDCEx(hWnd
, 0, DCX_CACHE
| DCX_USESTYLE
);
1102 NtUserScrollDC(hDC
, dx
, dy
, &rc
, &cliprc
, hrgnUpdate
, rcUpdate
);
1103 NtUserReleaseDC(hWnd
, hDC
);
1107 * Take into account the fact that some damage may have occurred during
1111 hrgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
1112 Result
= NtUserGetUpdateRgn(hWnd
, hrgnTemp
, FALSE
);
1113 if (Result
!= NULLREGION
)
1115 HRGN hrgnClip
= UnsafeIntCreateRectRgnIndirect(&cliprc
);
1116 NtGdiOffsetRgn(hrgnTemp
, dx
, dy
);
1117 NtGdiCombineRgn(hrgnTemp
, hrgnTemp
, hrgnClip
, RGN_AND
);
1118 NtUserRedrawWindow(hWnd
, NULL
, hrgnTemp
, RDW_INVALIDATE
| RDW_ERASE
);
1119 NtGdiDeleteObject(hrgnClip
);
1121 NtGdiDeleteObject(hrgnTemp
);
1123 if (flags
& SW_SCROLLCHILDREN
)
1125 HWND
*List
= IntWinListChildren(Window
);
1132 for (i
= 0; List
[i
]; i
++)
1134 NtUserGetWindowRect(List
[i
], &r
);
1135 IntGetClientOrigin(hWnd
, &ClientOrigin
);
1136 r
.left
-= ClientOrigin
.x
;
1137 r
.top
-= ClientOrigin
.y
;
1138 r
.right
-= ClientOrigin
.x
;
1139 r
.bottom
-= ClientOrigin
.y
;
1140 if (!rect
|| NtGdiIntersectRect(&dummy
, &r
, &rc
))
1141 WinPosSetWindowPos(List
[i
], 0, r
.left
+ dx
, r
.top
+ dy
, 0, 0,
1142 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
|
1149 if (flags
& (SW_INVALIDATE
| SW_ERASE
))
1150 NtUserRedrawWindow(hWnd
, NULL
, hrgnUpdate
, RDW_INVALIDATE
| RDW_ERASE
|
1151 ((flags
& SW_ERASE
) ? RDW_ERASENOW
: 0) |
1152 ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0));
1154 if (bOwnRgn
&& hrgnUpdate
)
1155 NtGdiDeleteObject(hrgnUpdate
);
1159 IntSetCaretPos(caretrc
.left
+ dx
, caretrc
.top
+ dy
);
1160 NtUserShowCaret(hwndCaret
);
1163 IntReleaseWindowObject(Window
);