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.71 2004/02/21 23:30:18 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
);
563 for (Child
= Window
->LastChild
; Child
; Child
= Child
->PrevSibling
)
565 if (IntIsWindowDirty(Child
) &&
566 IntWndBelongsToThread(Child
, Thread
))
568 hFoundWnd
= Child
->Self
;
572 ExReleaseFastMutex(&Window
->ChildrenListLock
);
574 if (hFoundWnd
== NULL
)
579 List
= IntWinListChildren(Window
);
582 for (i
= 0; List
[i
]; i
++)
584 hFoundWnd
= IntFindWindowToRepaint(List
[i
], Thread
);
585 if (hFoundWnd
!= NULL
)
592 IntReleaseWindowObject(Window
);
598 IntGetPaintMessage(HWND hWnd
, PW32THREAD Thread
, MSG
*Message
,
601 PWINDOW_OBJECT Window
;
602 PUSER_MESSAGE_QUEUE MessageQueue
= (PUSER_MESSAGE_QUEUE
)Thread
->MessageQueue
;
604 if (!MessageQueue
->PaintPosted
)
608 Message
->hwnd
= IntFindWindowToRepaint(hWnd
, PsGetWin32Thread());
610 Message
->hwnd
= IntFindWindowToRepaint(IntGetDesktopWindow(), PsGetWin32Thread());
612 if (Message
->hwnd
== NULL
)
615 DPRINT1("PAINTING BUG: Thread marked as containing dirty windows, but no dirty windows found!\n");
617 ExAcquireFastMutex(&MessageQueue
->Lock
);
618 MessageQueue
->PaintPosted
= 0;
619 MessageQueue
->PaintCount
= 0;
620 ExReleaseFastMutex(&MessageQueue
->Lock
);
624 Window
= IntGetWindowObject(Message
->hwnd
);
627 ExAcquireFastMutex(&Window
->UpdateLock
);
628 if (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
)
630 Message
->message
= WM_NCPAINT
;
631 Message
->wParam
= (WPARAM
)Window
->NCUpdateRegion
;
635 IntValidateParent(Window
, Window
->NCUpdateRegion
);
636 Window
->NCUpdateRegion
= NULL
;
637 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
638 MsqDecPaintCountQueue(Window
->MessageQueue
);
642 Message
->message
= WM_PAINT
;
643 Message
->wParam
= Message
->lParam
= 0;
644 if (Remove
&& Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
646 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
647 if (Window
->UpdateRegion
== NULL
)
649 MsqDecPaintCountQueue(Window
->MessageQueue
);
653 ExReleaseFastMutex(&Window
->UpdateLock
);
655 IntReleaseWindowObject(Window
);
663 IntFixCaret(HWND hWnd
, LPRECT lprc
, UINT flags
)
665 PDESKTOP_OBJECT Desktop
;
666 PTHRDCARETINFO CaretInfo
;
669 Desktop
= PsGetCurrentThread()->Win32Thread
->Desktop
;
670 CaretInfo
= ((PUSER_MESSAGE_QUEUE
)Desktop
->ActiveMessageQueue
)->CaretInfo
;
671 hWndCaret
= CaretInfo
->hWnd
;
672 if (hWndCaret
== hWnd
||
673 ((flags
& SW_SCROLLCHILDREN
) && IntIsChildWindow(hWnd
, hWndCaret
)))
675 POINT pt
, FromOffset
, ToOffset
, Offset
;
678 pt
.x
= CaretInfo
->Pos
.x
;
679 pt
.y
= CaretInfo
->Pos
.y
;
680 IntGetClientOrigin(hWndCaret
, &FromOffset
);
681 IntGetClientOrigin(hWnd
, &ToOffset
);
682 Offset
.x
= FromOffset
.x
- ToOffset
.x
;
683 Offset
.y
= FromOffset
.y
- ToOffset
.y
;
686 rcCaret
.right
= pt
.x
+ CaretInfo
->Size
.cx
;
687 rcCaret
.bottom
= pt
.y
+ CaretInfo
->Size
.cy
;
688 if (NtGdiIntersectRect(lprc
, lprc
, &rcCaret
))
700 /* PUBLIC FUNCTIONS ***********************************************************/
710 NtUserBeginPaint(HWND hWnd
, PAINTSTRUCT
* lPs
)
712 PWINDOW_OBJECT Window
;
714 if (!(Window
= IntGetWindowObject(hWnd
)))
716 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
720 NtUserHideCaret(hWnd
);
722 lPs
->hdc
= NtUserGetDCEx(hWnd
, 0, DCX_INTERSECTUPDATE
| DCX_WINDOWPAINT
|
727 IntReleaseWindowObject(Window
);
731 ExAcquireFastMutex(&Window
->UpdateLock
);
732 if (Window
->UpdateRegion
!= NULL
)
734 MsqDecPaintCountQueue(Window
->MessageQueue
);
735 IntValidateParent(Window
, Window
->UpdateRegion
);
736 NtGdiGetRgnBox(Window
->UpdateRegion
, &lPs
->rcPaint
);
737 NtGdiOffsetRect(&lPs
->rcPaint
,
738 Window
->WindowRect
.left
- Window
->ClientRect
.left
,
739 Window
->WindowRect
.top
- Window
->ClientRect
.top
);
740 NtGdiDeleteObject(Window
->UpdateRegion
);
741 Window
->UpdateRegion
= NULL
;
745 NtUserGetClientRect(Window
, &lPs
->rcPaint
);
747 ExReleaseFastMutex(&Window
->UpdateLock
);
749 if (Window
->Flags
& WINDOWOBJECT_NEED_ERASEBKGND
)
751 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
752 lPs
->fErase
= !IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)lPs
->hdc
, 0);
759 IntReleaseWindowObject(Window
);
772 NtUserEndPaint(HWND hWnd
, CONST PAINTSTRUCT
* lPs
)
774 NtUserReleaseDC(hWnd
, lPs
->hdc
);
775 NtUserShowCaret(hWnd
);
781 * NtUserInvalidateRect
788 NtUserInvalidateRect(HWND hWnd
, CONST RECT
*Rect
, BOOL Erase
)
790 return NtUserRedrawWindow(hWnd
, Rect
, 0, RDW_INVALIDATE
| (Erase
? RDW_ERASE
: 0));
794 * NtUserInvalidateRgn
801 NtUserInvalidateRgn(HWND hWnd
, HRGN Rgn
, BOOL Erase
)
803 return NtUserRedrawWindow(hWnd
, NULL
, Rgn
, RDW_INVALIDATE
| (Erase
? RDW_ERASE
: 0));
814 NtUserValidateRgn(HWND hWnd
, HRGN hRgn
)
816 return NtUserRedrawWindow(hWnd
, NULL
, hRgn
, RDW_VALIDATE
| RDW_NOCHILDREN
);
827 NtUserUpdateWindow(HWND hWnd
)
829 return NtUserRedrawWindow(hWnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
840 NtUserGetUpdateRgn(HWND hWnd
, HRGN hRgn
, BOOL bErase
)
842 PWINDOW_OBJECT Window
;
845 if (!(Window
= IntGetWindowObject(hWnd
)))
847 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
851 if (Window
->UpdateRegion
== NULL
)
853 RegionType
= (NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0) ? NULLREGION
: ERROR
);
857 RegionType
= NtGdiCombineRgn(hRgn
, Window
->UpdateRegion
, hRgn
, RGN_COPY
);
860 Window
->WindowRect
.left
- Window
->ClientRect
.left
,
861 Window
->WindowRect
.top
- Window
->ClientRect
.top
);
864 IntReleaseWindowObject(Window
);
866 if (bErase
&& RegionType
!= NULLREGION
&& RegionType
!= ERROR
)
868 NtUserRedrawWindow(hWnd
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
875 * NtUserGetUpdateRect
882 NtUserGetUpdateRect(HWND hWnd
, LPRECT lpRect
, BOOL fErase
)
884 HRGN hRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
888 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
892 NtUserGetUpdateRgn(hWnd
, hRgn
, fErase
);
893 NtGdiGetRgnBox(hRgn
, lpRect
);
894 NtGdiDeleteObject(hRgn
);
896 return lpRect
->left
< lpRect
->right
&& lpRect
->top
< lpRect
->bottom
;
907 NtUserRedrawWindow(HWND hWnd
, CONST RECT
*lprcUpdate
, HRGN hrgnUpdate
,
914 if (!(Wnd
= IntGetWindowObject(hWnd
? hWnd
: IntGetDesktopWindow())))
916 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
920 if (lprcUpdate
!= NULL
)
922 Status
= MmCopyFromCaller(&SafeUpdateRect
, (PRECT
)lprcUpdate
,
925 if (!NT_SUCCESS(Status
))
927 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
928 IntReleaseWindowObject(Wnd
);
933 Status
= IntRedrawWindow(Wnd
, NULL
== lprcUpdate
? NULL
: &SafeUpdateRect
,
936 if (!NT_SUCCESS(Status
))
938 /* IntRedrawWindow fails only in case that flags are invalid */
939 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
940 IntReleaseWindowObject(Wnd
);
944 IntReleaseWindowObject(Wnd
);
956 NtUserScrollDC(HDC hDC
, INT dx
, INT dy
, const RECT
*lprcScroll
,
957 const RECT
*lprcClip
, HRGN hrgnUpdate
, LPRECT lprcUpdate
)
959 RECT rSrc
, rClipped_src
, rClip
, rDst
, offset
;
963 * Compute device clipping region (in device coordinates).
974 IntGdiGetClipBox(hDC
, &rSrc
);
975 IntLPtoDP(DC
, (LPPOINT
)&rSrc
, 2);
980 IntGdiGetClipBox(hDC
, &rClip
);
981 IntLPtoDP(DC
, (LPPOINT
)&rClip
, 2);
983 NtGdiIntersectRect(&rClipped_src
, &rSrc
, &rClip
);
986 NtGdiSetRect(&offset
, 0, 0, dx
, dy
);
987 IntLPtoDP(DC
, (LPPOINT
)&offset
, 2);
988 NtGdiOffsetRect(&rDst
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
989 NtGdiIntersectRect(&rDst
, &rDst
, &rClip
);
992 * Copy bits, if possible.
995 if (rDst
.bottom
> rDst
.top
&& rDst
.right
> rDst
.left
)
997 RECT rDst_lp
= rDst
, rSrc_lp
= rDst
;
999 NtGdiOffsetRect(&rSrc_lp
, offset
.left
- offset
.right
, offset
.top
- offset
.bottom
);
1000 IntDPtoLP(DC
, (LPPOINT
)&rDst_lp
, 2);
1001 IntDPtoLP(DC
, (LPPOINT
)&rSrc_lp
, 2);
1004 if (!NtGdiBitBlt(hDC
, rDst_lp
.left
, rDst_lp
.top
, rDst_lp
.right
- rDst_lp
.left
,
1005 rDst_lp
.bottom
- rDst_lp
.top
, hDC
, rSrc_lp
.left
, rSrc_lp
.top
,
1015 * Compute update areas. This is the clipped source or'ed with the
1016 * unclipped source translated minus the clipped src translated (rDst)
1017 * all clipped to rClip.
1020 if (hrgnUpdate
|| lprcUpdate
)
1022 HRGN hRgn
= hrgnUpdate
, hRgn2
;
1025 NtGdiSetRectRgn(hRgn
, rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
1027 hRgn
= NtGdiCreateRectRgn(rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
1029 hRgn2
= UnsafeIntCreateRectRgnIndirect(&rSrc
);
1030 NtGdiOffsetRgn(hRgn2
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
1031 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_OR
);
1033 NtGdiSetRectRgn(hRgn2
, rDst
.left
, rDst
.top
, rDst
.right
, rDst
.bottom
);
1034 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_DIFF
);
1036 NtGdiSetRectRgn(hRgn2
, rClip
.left
, rClip
.top
, rClip
.right
, rClip
.bottom
);
1037 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_AND
);
1041 NtGdiGetRgnBox(hRgn
, lprcUpdate
);
1043 /* Put the lprcUpdate in logical coordinate */
1044 NtGdiDPtoLP(hDC
, (LPPOINT
)lprcUpdate
, 2);
1047 NtGdiDeleteObject(hRgn
);
1048 NtGdiDeleteObject(hRgn2
);
1054 * NtUserScrollWindowEx
1061 NtUserScrollWindowEx(HWND hWnd
, INT dx
, INT dy
, const RECT
*rect
,
1062 const RECT
*clipRect
, HRGN hrgnUpdate
, LPRECT rcUpdate
, UINT flags
)
1064 RECT rc
, cliprc
, caretrc
;
1066 PWINDOW_OBJECT Window
;
1070 BOOL bUpdate
= (rcUpdate
|| hrgnUpdate
|| flags
& (SW_INVALIDATE
| SW_ERASE
));
1071 BOOL bOwnRgn
= TRUE
;
1073 Window
= IntGetWindowObject(hWnd
);
1074 if (!Window
|| !IntIsWindowDrawable(Window
))
1076 IntReleaseWindowObject(Window
);
1080 IntGetClientRect(Window
, &rc
);
1082 NtGdiIntersectRect(&rc
, &rc
, rect
);
1085 NtGdiIntersectRect(&cliprc
, &rc
, clipRect
);
1089 if (cliprc
.right
<= cliprc
.left
|| cliprc
.bottom
<= cliprc
.top
||
1090 (dx
== 0 && dy
== 0))
1096 hwndCaret
= IntFixCaret(hWnd
, &caretrc
, flags
);
1101 hrgnUpdate
= NtGdiCreateRectRgn(0, 0, 0, 0);
1103 hDC
= NtUserGetDCEx(hWnd
, 0, DCX_CACHE
| DCX_USESTYLE
);
1106 NtUserScrollDC(hDC
, dx
, dy
, &rc
, &cliprc
, hrgnUpdate
, rcUpdate
);
1107 NtUserReleaseDC(hWnd
, hDC
);
1111 * Take into account the fact that some damage may have occurred during
1115 hrgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
1116 Result
= NtUserGetUpdateRgn(hWnd
, hrgnTemp
, FALSE
);
1117 if (Result
!= NULLREGION
)
1119 HRGN hrgnClip
= UnsafeIntCreateRectRgnIndirect(&cliprc
);
1120 NtGdiOffsetRgn(hrgnTemp
, dx
, dy
);
1121 NtGdiCombineRgn(hrgnTemp
, hrgnTemp
, hrgnClip
, RGN_AND
);
1122 NtUserRedrawWindow(hWnd
, NULL
, hrgnTemp
, RDW_INVALIDATE
| RDW_ERASE
);
1123 NtGdiDeleteObject(hrgnClip
);
1125 NtGdiDeleteObject(hrgnTemp
);
1127 if (flags
& SW_SCROLLCHILDREN
)
1129 HWND
*List
= IntWinListChildren(Window
);
1136 for (i
= 0; List
[i
]; i
++)
1138 NtUserGetWindowRect(List
[i
], &r
);
1139 IntGetClientOrigin(hWnd
, &ClientOrigin
);
1140 r
.left
-= ClientOrigin
.x
;
1141 r
.top
-= ClientOrigin
.y
;
1142 r
.right
-= ClientOrigin
.x
;
1143 r
.bottom
-= ClientOrigin
.y
;
1144 if (!rect
|| NtGdiIntersectRect(&dummy
, &r
, &rc
))
1145 WinPosSetWindowPos(List
[i
], 0, r
.left
+ dx
, r
.top
+ dy
, 0, 0,
1146 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
|
1153 if (flags
& (SW_INVALIDATE
| SW_ERASE
))
1154 NtUserRedrawWindow(hWnd
, NULL
, hrgnUpdate
, RDW_INVALIDATE
| RDW_ERASE
|
1155 ((flags
& SW_ERASE
) ? RDW_ERASENOW
: 0) |
1156 ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0));
1158 if (bOwnRgn
&& hrgnUpdate
)
1159 NtGdiDeleteObject(hrgnUpdate
);
1163 IntSetCaretPos(caretrc
.left
+ dx
, caretrc
.top
+ dy
);
1164 NtUserShowCaret(hwndCaret
);
1167 IntReleaseWindowObject(Window
);