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.73 2004/02/24 01:30:57 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>
55 #include <win32k/debug1.h>
57 /* PRIVATE FUNCTIONS **********************************************************/
60 IntValidateParent(PWINDOW_OBJECT Child
, HRGN ValidRegion
)
62 PWINDOW_OBJECT ParentWindow
= IntGetParentObject(Child
), OldWindow
;
66 if (!(ParentWindow
->Style
& WS_CLIPCHILDREN
))
68 ExAcquireFastMutex(&ParentWindow
->UpdateLock
);
69 if (ParentWindow
->UpdateRegion
!= 0)
74 * We must offset the child region by the offset of the
75 * child rect in the parent.
77 OffsetX
= Child
->WindowRect
.left
- ParentWindow
->WindowRect
.left
;
78 OffsetY
= Child
->WindowRect
.top
- ParentWindow
->WindowRect
.top
;
79 NtGdiOffsetRgn(ValidRegion
, OffsetX
, OffsetY
);
80 NtGdiCombineRgn(ParentWindow
->UpdateRegion
, ParentWindow
->UpdateRegion
,
81 ValidRegion
, RGN_DIFF
);
82 /* FIXME: If the resulting region is empty, remove fake posted paint message */
83 NtGdiOffsetRgn(ValidRegion
, -OffsetX
, -OffsetY
);
85 ExReleaseFastMutex(&ParentWindow
->UpdateLock
);
87 OldWindow
= ParentWindow
;
88 ParentWindow
= IntGetParentObject(ParentWindow
);
89 IntReleaseWindowObject(OldWindow
);
96 * Internal function used by IntRedrawWindow.
100 IntPaintWindows(PWINDOW_OBJECT Window
, ULONG Flags
)
103 HWND hWnd
= Window
->Self
;
106 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
108 if (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
)
110 ExAcquireFastMutex(&Window
->UpdateLock
);
111 if (Window
->NCUpdateRegion
)
113 IntValidateParent(Window
, Window
->NCUpdateRegion
);
115 TempRegion
= Window
->NCUpdateRegion
;
116 Window
->NCUpdateRegion
= NULL
;
117 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
118 MsqDecPaintCountQueue(Window
->MessageQueue
);
119 ExReleaseFastMutex(&Window
->UpdateLock
);
120 IntSendMessage(hWnd
, WM_NCPAINT
, (WPARAM
)TempRegion
, 0);
123 if (Window
->Flags
& WINDOWOBJECT_NEED_ERASEBKGND
)
125 if (Window
->UpdateRegion
)
127 IntValidateParent(Window
, Window
->UpdateRegion
);
128 hDC
= NtUserGetDCEx(hWnd
, 0, DCX_CACHE
| DCX_USESTYLE
|
129 DCX_INTERSECTUPDATE
);
132 if (IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)hDC
, 0))
134 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
136 NtUserReleaseDC(hWnd
, hDC
);
141 if (Flags
& RDW_UPDATENOW
)
143 if (Window
->UpdateRegion
!= NULL
||
144 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
146 IntSendMessage(hWnd
, WM_PAINT
, 0, 0);
147 ExAcquireFastMutex(&Window
->UpdateLock
);
148 if (Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
150 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
151 if (Window
->UpdateRegion
== NULL
)
153 MsqDecPaintCountQueue(Window
->MessageQueue
);
156 ExReleaseFastMutex(&Window
->UpdateLock
);
162 * Check that the window is still valid at this point
165 if (! IntIsWindow(hWnd
))
171 * Paint child windows.
173 if (!(Flags
& RDW_NOCHILDREN
) && !(Window
->Style
& WS_MINIMIZE
) &&
174 ((Flags
& RDW_ALLCHILDREN
) || !(Window
->Style
& WS_CLIPCHILDREN
)))
178 if ((List
= IntWinListChildren(Window
)))
180 for (phWnd
= List
; *phWnd
; ++phWnd
)
182 Window
= IntGetWindowObject(*phWnd
);
183 if (Window
&& (Window
->Style
& WS_VISIBLE
))
185 IntPaintWindows(Window
, Flags
);
186 IntReleaseWindowObject(Window
);
195 * IntInvalidateWindows
197 * Internal function used by IntRedrawWindow.
201 IntInvalidateWindows(PWINDOW_OBJECT Window
, HRGN hRgn
, ULONG Flags
)
204 BOOL HadPaintMessage
, HadNCPaintMessage
;
205 BOOL HasPaintMessage
, HasNCPaintMessage
;
208 * Clip the given region with window rectangle (or region)
212 if (!Window
->WindowRegion
)
217 hRgnWindow
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
218 NtGdiOffsetRgn(hRgnWindow
,
219 -Window
->WindowRect
.left
,
220 -Window
->WindowRect
.top
);
221 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, hRgnWindow
, RGN_AND
);
222 NtGdiDeleteObject(hRgnWindow
);
227 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, Window
->WindowRegion
, RGN_AND
);
232 * Save current state of pending updates
235 ExAcquireFastMutex(&Window
->UpdateLock
);
236 HadPaintMessage
= Window
->UpdateRegion
!= NULL
||
237 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
;
238 HadNCPaintMessage
= Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
;
241 * Update the region and flags
244 if (Flags
& RDW_INVALIDATE
&& RgnType
!= NULLREGION
)
246 if (Window
->UpdateRegion
== NULL
)
248 Window
->UpdateRegion
= NtGdiCreateRectRgn(0, 0, 0, 0);
251 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
252 hRgn
, RGN_OR
) == NULLREGION
)
254 NtGdiDeleteObject(Window
->UpdateRegion
);
255 Window
->UpdateRegion
= NULL
;
258 if (Flags
& RDW_FRAME
)
259 Window
->Flags
|= WINDOWOBJECT_NEED_NCPAINT
;
260 if (Flags
& RDW_ERASE
)
261 Window
->Flags
|= WINDOWOBJECT_NEED_ERASEBKGND
;
266 if (Flags
& RDW_VALIDATE
&& RgnType
!= NULLREGION
)
268 if (Window
->UpdateRegion
!= NULL
)
270 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
271 hRgn
, RGN_DIFF
) == NULLREGION
)
273 NtGdiDeleteObject(Window
->UpdateRegion
);
274 Window
->UpdateRegion
= NULL
;
278 if (Window
->UpdateRegion
== NULL
)
279 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
280 if (Flags
& RDW_NOFRAME
)
281 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
282 if (Flags
& RDW_NOERASE
)
283 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
286 if (Flags
& RDW_INTERNALPAINT
)
288 Window
->Flags
|= WINDOWOBJECT_NEED_INTERNALPAINT
;
291 if (Flags
& RDW_NOINTERNALPAINT
)
293 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
297 * Split the nonclient update region.
301 HRGN hRgnWindow
, hRgnNonClient
;
303 hRgnWindow
= UnsafeIntCreateRectRgnIndirect(&Window
->ClientRect
);
304 NtGdiOffsetRgn(hRgnWindow
,
305 -Window
->WindowRect
.left
,
306 -Window
->WindowRect
.top
);
308 hRgnNonClient
= NtGdiCreateRectRgn(0, 0, 0, 0);
309 if (NtGdiCombineRgn(hRgnNonClient
, Window
->UpdateRegion
,
310 hRgnWindow
, RGN_DIFF
) == NULLREGION
)
312 NtGdiDeleteObject(hRgnNonClient
);
313 hRgnNonClient
= NULL
;
317 * Remove the nonclient region from the standard update region.
320 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
321 hRgnWindow
, RGN_AND
) == NULLREGION
)
323 NtGdiDeleteObject(Window
->UpdateRegion
);
324 Window
->UpdateRegion
= NULL
;
327 if (Window
->NCUpdateRegion
== NULL
)
329 Window
->NCUpdateRegion
= hRgnNonClient
;
333 NtGdiCombineRgn(Window
->NCUpdateRegion
, Window
->NCUpdateRegion
,
334 hRgnNonClient
, RGN_OR
);
337 NtGdiDeleteObject(hRgnWindow
);
341 * Process children if needed
344 if (!(Flags
& RDW_NOCHILDREN
) && !(Window
->Style
& WS_MINIMIZE
) &&
345 ((Flags
& RDW_ALLCHILDREN
) || !(Window
->Style
& WS_CLIPCHILDREN
)))
348 PWINDOW_OBJECT Child
;
350 if ((List
= IntWinListChildren(Window
)))
352 for (phWnd
= List
; *phWnd
; ++phWnd
)
354 Child
= IntGetWindowObject(*phWnd
);
359 if (Child
->Style
& WS_VISIBLE
)
362 * Recursive call to update children UpdateRegion
364 HRGN hRgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
365 NtGdiCombineRgn(hRgnTemp
, hRgn
, 0, RGN_COPY
);
366 NtGdiOffsetRgn(hRgnTemp
,
367 Window
->WindowRect
.left
- Child
->WindowRect
.left
,
368 Window
->WindowRect
.top
- Child
->WindowRect
.top
);
369 IntInvalidateWindows(Child
, hRgnTemp
, Flags
);
370 NtGdiDeleteObject(hRgnTemp
);
372 IntReleaseWindowObject(Child
);
379 * Fake post paint messages to window message queue if needed
382 HasPaintMessage
= Window
->UpdateRegion
!= NULL
||
383 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
;
384 HasNCPaintMessage
= Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
;
386 if (HasPaintMessage
!= HadPaintMessage
)
389 MsqDecPaintCountQueue(Window
->MessageQueue
);
391 MsqIncPaintCountQueue(Window
->MessageQueue
);
394 if (HasNCPaintMessage
!= HadNCPaintMessage
)
396 if (HadNCPaintMessage
)
397 MsqDecPaintCountQueue(Window
->MessageQueue
);
399 MsqIncPaintCountQueue(Window
->MessageQueue
);
402 ExReleaseFastMutex(&Window
->UpdateLock
);
406 * IntIsWindowDrawable
409 * Window is drawable when it is visible and all parents are not
414 IntIsWindowDrawable(PWINDOW_OBJECT Window
)
416 PWINDOW_OBJECT Old
, Wnd
= Window
;
418 IntReferenceWindowObject(Wnd
);
421 if (!(Wnd
->Style
& WS_VISIBLE
) ||
422 ((Wnd
->Style
& WS_MINIMIZE
) && (Wnd
!= Window
)))
424 IntReleaseWindowObject(Wnd
);
428 Wnd
= IntGetParentObject(Wnd
);
429 IntReleaseWindowObject(Old
);
438 * Internal version of NtUserRedrawWindow that takes WINDOW_OBJECT as
443 IntRedrawWindow(PWINDOW_OBJECT Window
, const RECT
* UpdateRect
, HRGN UpdateRgn
,
450 * Validation of passed parameters.
453 if (!IntIsWindowDrawable(Window
) ||
454 (Flags
& (RDW_VALIDATE
| RDW_INVALIDATE
)) ==
455 (RDW_VALIDATE
| RDW_INVALIDATE
))
462 * Transform the parameters UpdateRgn and UpdateRect into
463 * a region hRgn specified in window coordinates.
466 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
))
468 if (UpdateRgn
!= NULL
)
470 hRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
471 NtGdiCombineRgn(hRgn
, UpdateRgn
, NULL
, RGN_COPY
);
473 Window
->ClientRect
.left
- Window
->WindowRect
.left
,
474 Window
->ClientRect
.top
- Window
->WindowRect
.top
);
476 if (UpdateRect
!= NULL
)
478 hRgn
= UnsafeIntCreateRectRgnIndirect((RECT
*)UpdateRect
);
480 Window
->ClientRect
.left
- Window
->WindowRect
.left
,
481 Window
->ClientRect
.top
- Window
->WindowRect
.top
);
483 if ((Flags
& (RDW_INVALIDATE
| RDW_FRAME
)) == (RDW_INVALIDATE
| RDW_FRAME
) ||
484 (Flags
& (RDW_VALIDATE
| RDW_NOFRAME
)) == (RDW_VALIDATE
| RDW_NOFRAME
))
486 hRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
488 -Window
->WindowRect
.left
,
489 -Window
->WindowRect
.top
);
493 hRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->ClientRect
);
495 -Window
->WindowRect
.left
,
496 -Window
->WindowRect
.top
);
502 * Adjust the window update region depending on hRgn and flags.
505 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
| RDW_INTERNALPAINT
| RDW_NOINTERNALPAINT
))
507 IntInvalidateWindows(Window
, hRgn
, Flags
);
512 * Repaint and erase windows if needed.
515 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
517 IntPaintWindows(Window
, Flags
);
527 NtGdiDeleteObject(hRgn
);
534 IntIsWindowDirty(PWINDOW_OBJECT Window
)
536 return (Window
->Style
& WS_VISIBLE
) &&
537 ((Window
->UpdateRegion
!= NULL
) ||
538 (Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
) ||
539 (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
));
543 IntFindWindowToRepaint(HWND hWnd
, PW32THREAD Thread
)
545 PWINDOW_OBJECT Window
;
546 PWINDOW_OBJECT Child
;
547 HWND hFoundWnd
= NULL
;
549 Window
= IntGetWindowObject(hWnd
);
553 if (IntIsWindowDirty(Window
) &&
554 IntWndBelongsToThread(Window
, Thread
))
556 IntReleaseWindowObject(Window
);
560 IntLockRelatives(Window
);
561 for (Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
563 if (IntIsWindowDirty(Child
) &&
564 IntWndBelongsToThread(Child
, Thread
))
566 hFoundWnd
= Child
->Self
;
570 IntUnLockRelatives(Window
);
572 if (hFoundWnd
== NULL
)
577 List
= IntWinListChildren(Window
);
580 for (i
= 0; List
[i
]; i
++)
582 hFoundWnd
= IntFindWindowToRepaint(List
[i
], Thread
);
583 if (hFoundWnd
!= NULL
)
590 IntReleaseWindowObject(Window
);
596 IntGetPaintMessage(HWND hWnd
, PW32THREAD Thread
, MSG
*Message
,
599 PWINDOW_OBJECT Window
;
600 PUSER_MESSAGE_QUEUE MessageQueue
= (PUSER_MESSAGE_QUEUE
)Thread
->MessageQueue
;
602 if (!MessageQueue
->PaintPosted
)
606 Message
->hwnd
= IntFindWindowToRepaint(hWnd
, PsGetWin32Thread());
608 Message
->hwnd
= IntFindWindowToRepaint(IntGetDesktopWindow(), PsGetWin32Thread());
610 if (Message
->hwnd
== NULL
)
613 DPRINT1("PAINTING BUG: Thread marked as containing dirty windows, but no dirty windows found!\n");
615 ExAcquireFastMutex(&MessageQueue
->Lock
);
616 MessageQueue
->PaintPosted
= 0;
617 MessageQueue
->PaintCount
= 0;
618 ExReleaseFastMutex(&MessageQueue
->Lock
);
622 Window
= IntGetWindowObject(Message
->hwnd
);
625 ExAcquireFastMutex(&Window
->UpdateLock
);
626 if (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
)
628 Message
->message
= WM_NCPAINT
;
629 Message
->wParam
= (WPARAM
)Window
->NCUpdateRegion
;
633 IntValidateParent(Window
, Window
->NCUpdateRegion
);
634 Window
->NCUpdateRegion
= NULL
;
635 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
636 MsqDecPaintCountQueue(Window
->MessageQueue
);
640 Message
->message
= WM_PAINT
;
641 Message
->wParam
= Message
->lParam
= 0;
642 if (Remove
&& Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
644 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
645 if (Window
->UpdateRegion
== NULL
)
647 MsqDecPaintCountQueue(Window
->MessageQueue
);
651 ExReleaseFastMutex(&Window
->UpdateLock
);
653 IntReleaseWindowObject(Window
);
661 IntFixCaret(HWND hWnd
, LPRECT lprc
, UINT flags
)
663 PDESKTOP_OBJECT Desktop
;
664 PTHRDCARETINFO CaretInfo
;
667 Desktop
= PsGetCurrentThread()->Win32Thread
->Desktop
;
668 CaretInfo
= ((PUSER_MESSAGE_QUEUE
)Desktop
->ActiveMessageQueue
)->CaretInfo
;
669 hWndCaret
= CaretInfo
->hWnd
;
670 if (hWndCaret
== hWnd
||
671 ((flags
& SW_SCROLLCHILDREN
) && IntIsChildWindow(hWnd
, hWndCaret
)))
673 POINT pt
, FromOffset
, ToOffset
, Offset
;
676 pt
.x
= CaretInfo
->Pos
.x
;
677 pt
.y
= CaretInfo
->Pos
.y
;
678 IntGetClientOrigin(hWndCaret
, &FromOffset
);
679 IntGetClientOrigin(hWnd
, &ToOffset
);
680 Offset
.x
= FromOffset
.x
- ToOffset
.x
;
681 Offset
.y
= FromOffset
.y
- ToOffset
.y
;
684 rcCaret
.right
= pt
.x
+ CaretInfo
->Size
.cx
;
685 rcCaret
.bottom
= pt
.y
+ CaretInfo
->Size
.cy
;
686 if (NtGdiIntersectRect(lprc
, lprc
, &rcCaret
))
698 /* PUBLIC FUNCTIONS ***********************************************************/
708 NtUserBeginPaint(HWND hWnd
, PAINTSTRUCT
* lPs
)
710 PWINDOW_OBJECT Window
;
712 if (!(Window
= IntGetWindowObject(hWnd
)))
714 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
718 NtUserHideCaret(hWnd
);
720 lPs
->hdc
= NtUserGetDCEx(hWnd
, 0, DCX_INTERSECTUPDATE
| DCX_WINDOWPAINT
|
725 IntReleaseWindowObject(Window
);
729 ExAcquireFastMutex(&Window
->UpdateLock
);
730 if (Window
->UpdateRegion
!= NULL
)
732 MsqDecPaintCountQueue(Window
->MessageQueue
);
733 IntValidateParent(Window
, Window
->UpdateRegion
);
734 NtGdiGetRgnBox(Window
->UpdateRegion
, &lPs
->rcPaint
);
735 NtGdiOffsetRect(&lPs
->rcPaint
,
736 Window
->WindowRect
.left
- Window
->ClientRect
.left
,
737 Window
->WindowRect
.top
- Window
->ClientRect
.top
);
738 NtGdiDeleteObject(Window
->UpdateRegion
);
739 Window
->UpdateRegion
= NULL
;
743 NtUserGetClientRect(Window
, &lPs
->rcPaint
);
745 ExReleaseFastMutex(&Window
->UpdateLock
);
747 if (Window
->Flags
& WINDOWOBJECT_NEED_ERASEBKGND
)
749 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
750 lPs
->fErase
= !IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)lPs
->hdc
, 0);
757 IntReleaseWindowObject(Window
);
770 NtUserEndPaint(HWND hWnd
, CONST PAINTSTRUCT
* lPs
)
772 NtUserReleaseDC(hWnd
, lPs
->hdc
);
773 NtUserShowCaret(hWnd
);
779 * NtUserInvalidateRect
786 NtUserInvalidateRect(HWND hWnd
, CONST RECT
*Rect
, BOOL Erase
)
788 return NtUserRedrawWindow(hWnd
, Rect
, 0, RDW_INVALIDATE
| (Erase
? RDW_ERASE
: 0));
792 * NtUserInvalidateRgn
799 NtUserInvalidateRgn(HWND hWnd
, HRGN Rgn
, BOOL Erase
)
801 return NtUserRedrawWindow(hWnd
, NULL
, Rgn
, RDW_INVALIDATE
| (Erase
? RDW_ERASE
: 0));
812 NtUserValidateRgn(HWND hWnd
, HRGN hRgn
)
814 return NtUserRedrawWindow(hWnd
, NULL
, hRgn
, RDW_VALIDATE
| RDW_NOCHILDREN
);
825 NtUserUpdateWindow(HWND hWnd
)
827 return NtUserRedrawWindow(hWnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
838 NtUserGetUpdateRgn(HWND hWnd
, HRGN hRgn
, BOOL bErase
)
840 PWINDOW_OBJECT Window
;
843 if (!(Window
= IntGetWindowObject(hWnd
)))
845 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
849 if (Window
->UpdateRegion
== NULL
)
851 RegionType
= (NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0) ? NULLREGION
: ERROR
);
855 RegionType
= NtGdiCombineRgn(hRgn
, Window
->UpdateRegion
, hRgn
, RGN_COPY
);
858 Window
->WindowRect
.left
- Window
->ClientRect
.left
,
859 Window
->WindowRect
.top
- Window
->ClientRect
.top
);
862 IntReleaseWindowObject(Window
);
864 if (bErase
&& RegionType
!= NULLREGION
&& RegionType
!= ERROR
)
866 NtUserRedrawWindow(hWnd
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
873 * NtUserGetUpdateRect
880 NtUserGetUpdateRect(HWND hWnd
, LPRECT lpRect
, BOOL fErase
)
882 HRGN hRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
886 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
890 NtUserGetUpdateRgn(hWnd
, hRgn
, fErase
);
891 NtGdiGetRgnBox(hRgn
, lpRect
);
892 NtGdiDeleteObject(hRgn
);
894 return lpRect
->left
< lpRect
->right
&& lpRect
->top
< lpRect
->bottom
;
905 NtUserRedrawWindow(HWND hWnd
, CONST RECT
*lprcUpdate
, HRGN hrgnUpdate
,
912 if (!(Wnd
= IntGetWindowObject(hWnd
? hWnd
: IntGetDesktopWindow())))
914 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
918 if (lprcUpdate
!= NULL
)
920 Status
= MmCopyFromCaller(&SafeUpdateRect
, (PRECT
)lprcUpdate
,
923 if (!NT_SUCCESS(Status
))
925 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
926 IntReleaseWindowObject(Wnd
);
931 Status
= IntRedrawWindow(Wnd
, NULL
== lprcUpdate
? NULL
: &SafeUpdateRect
,
934 if (!NT_SUCCESS(Status
))
936 /* IntRedrawWindow fails only in case that flags are invalid */
937 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
938 IntReleaseWindowObject(Wnd
);
942 IntReleaseWindowObject(Wnd
);
954 NtUserScrollDC(HDC hDC
, INT dx
, INT dy
, const RECT
*lprcScroll
,
955 const RECT
*lprcClip
, HRGN hrgnUpdate
, LPRECT lprcUpdate
)
957 RECT rSrc
, rClipped_src
, rClip
, rDst
, offset
;
961 * Compute device clipping region (in device coordinates).
972 IntGdiGetClipBox(hDC
, &rSrc
);
973 IntLPtoDP(DC
, (LPPOINT
)&rSrc
, 2);
978 IntGdiGetClipBox(hDC
, &rClip
);
979 IntLPtoDP(DC
, (LPPOINT
)&rClip
, 2);
981 NtGdiIntersectRect(&rClipped_src
, &rSrc
, &rClip
);
984 NtGdiSetRect(&offset
, 0, 0, dx
, dy
);
985 IntLPtoDP(DC
, (LPPOINT
)&offset
, 2);
986 NtGdiOffsetRect(&rDst
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
987 NtGdiIntersectRect(&rDst
, &rDst
, &rClip
);
990 * Copy bits, if possible.
993 if (rDst
.bottom
> rDst
.top
&& rDst
.right
> rDst
.left
)
995 RECT rDst_lp
= rDst
, rSrc_lp
= rDst
;
997 NtGdiOffsetRect(&rSrc_lp
, offset
.left
- offset
.right
, offset
.top
- offset
.bottom
);
998 IntDPtoLP(DC
, (LPPOINT
)&rDst_lp
, 2);
999 IntDPtoLP(DC
, (LPPOINT
)&rSrc_lp
, 2);
1002 if (!NtGdiBitBlt(hDC
, rDst_lp
.left
, rDst_lp
.top
, rDst_lp
.right
- rDst_lp
.left
,
1003 rDst_lp
.bottom
- rDst_lp
.top
, hDC
, rSrc_lp
.left
, rSrc_lp
.top
,
1013 * Compute update areas. This is the clipped source or'ed with the
1014 * unclipped source translated minus the clipped src translated (rDst)
1015 * all clipped to rClip.
1018 if (hrgnUpdate
|| lprcUpdate
)
1020 HRGN hRgn
= hrgnUpdate
, hRgn2
;
1023 NtGdiSetRectRgn(hRgn
, rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
1025 hRgn
= NtGdiCreateRectRgn(rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
1027 hRgn2
= UnsafeIntCreateRectRgnIndirect(&rSrc
);
1028 NtGdiOffsetRgn(hRgn2
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
1029 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_OR
);
1031 NtGdiSetRectRgn(hRgn2
, rDst
.left
, rDst
.top
, rDst
.right
, rDst
.bottom
);
1032 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_DIFF
);
1034 NtGdiSetRectRgn(hRgn2
, rClip
.left
, rClip
.top
, rClip
.right
, rClip
.bottom
);
1035 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_AND
);
1039 NtGdiGetRgnBox(hRgn
, lprcUpdate
);
1041 /* Put the lprcUpdate in logical coordinate */
1042 NtGdiDPtoLP(hDC
, (LPPOINT
)lprcUpdate
, 2);
1045 NtGdiDeleteObject(hRgn
);
1046 NtGdiDeleteObject(hRgn2
);
1052 * NtUserScrollWindowEx
1059 NtUserScrollWindowEx(HWND hWnd
, INT dx
, INT dy
, const RECT
*rect
,
1060 const RECT
*clipRect
, HRGN hrgnUpdate
, LPRECT rcUpdate
, UINT flags
)
1062 RECT rc
, cliprc
, caretrc
;
1064 PWINDOW_OBJECT Window
;
1068 BOOL bUpdate
= (rcUpdate
|| hrgnUpdate
|| flags
& (SW_INVALIDATE
| SW_ERASE
));
1069 BOOL bOwnRgn
= TRUE
;
1071 Window
= IntGetWindowObject(hWnd
);
1072 if (!Window
|| !IntIsWindowDrawable(Window
))
1074 IntReleaseWindowObject(Window
);
1078 IntGetClientRect(Window
, &rc
);
1080 NtGdiIntersectRect(&rc
, &rc
, rect
);
1083 NtGdiIntersectRect(&cliprc
, &rc
, clipRect
);
1087 if (cliprc
.right
<= cliprc
.left
|| cliprc
.bottom
<= cliprc
.top
||
1088 (dx
== 0 && dy
== 0))
1094 hwndCaret
= IntFixCaret(hWnd
, &caretrc
, flags
);
1099 hrgnUpdate
= NtGdiCreateRectRgn(0, 0, 0, 0);
1101 hDC
= NtUserGetDCEx(hWnd
, 0, DCX_CACHE
| DCX_USESTYLE
);
1104 NtUserScrollDC(hDC
, dx
, dy
, &rc
, &cliprc
, hrgnUpdate
, rcUpdate
);
1105 NtUserReleaseDC(hWnd
, hDC
);
1109 * Take into account the fact that some damage may have occurred during
1113 hrgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
1114 Result
= NtUserGetUpdateRgn(hWnd
, hrgnTemp
, FALSE
);
1115 if (Result
!= NULLREGION
)
1117 HRGN hrgnClip
= UnsafeIntCreateRectRgnIndirect(&cliprc
);
1118 NtGdiOffsetRgn(hrgnTemp
, dx
, dy
);
1119 NtGdiCombineRgn(hrgnTemp
, hrgnTemp
, hrgnClip
, RGN_AND
);
1120 NtUserRedrawWindow(hWnd
, NULL
, hrgnTemp
, RDW_INVALIDATE
| RDW_ERASE
);
1121 NtGdiDeleteObject(hrgnClip
);
1123 NtGdiDeleteObject(hrgnTemp
);
1125 if (flags
& SW_SCROLLCHILDREN
)
1127 HWND
*List
= IntWinListChildren(Window
);
1134 for (i
= 0; List
[i
]; i
++)
1136 NtUserGetWindowRect(List
[i
], &r
);
1137 IntGetClientOrigin(hWnd
, &ClientOrigin
);
1138 r
.left
-= ClientOrigin
.x
;
1139 r
.top
-= ClientOrigin
.y
;
1140 r
.right
-= ClientOrigin
.x
;
1141 r
.bottom
-= ClientOrigin
.y
;
1142 if (!rect
|| NtGdiIntersectRect(&dummy
, &r
, &rc
))
1143 WinPosSetWindowPos(List
[i
], 0, r
.left
+ dx
, r
.top
+ dy
, 0, 0,
1144 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
|
1151 if (flags
& (SW_INVALIDATE
| SW_ERASE
))
1152 NtUserRedrawWindow(hWnd
, NULL
, hrgnUpdate
, RDW_INVALIDATE
| RDW_ERASE
|
1153 ((flags
& SW_ERASE
) ? RDW_ERASENOW
: 0) |
1154 ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0));
1156 if (bOwnRgn
&& hrgnUpdate
)
1157 NtGdiDeleteObject(hrgnUpdate
);
1161 IntSetCaretPos(caretrc
.left
+ dx
, caretrc
.top
+ dy
);
1162 NtUserShowCaret(hwndCaret
);
1165 IntReleaseWindowObject(Window
);