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.
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 ******************************************************************/
36 #include <win32k/debug1.h>
38 #define DCX_USESTYLE 0x10000
40 /* PRIVATE FUNCTIONS **********************************************************/
43 IntValidateParent(PWINDOW_OBJECT Child
, HRGN ValidRegion
)
45 PWINDOW_OBJECT ParentWindow
= IntGetParentObject(Child
), OldWindow
;
49 if (!(ParentWindow
->Style
& WS_CLIPCHILDREN
))
51 IntLockWindowUpdate(ParentWindow
);
52 if (ParentWindow
->UpdateRegion
!= 0)
57 * We must offset the child region by the offset of the
58 * child rect in the parent.
60 OffsetX
= Child
->WindowRect
.left
- ParentWindow
->WindowRect
.left
;
61 OffsetY
= Child
->WindowRect
.top
- ParentWindow
->WindowRect
.top
;
62 NtGdiOffsetRgn(ValidRegion
, OffsetX
, OffsetY
);
63 NtGdiCombineRgn(ParentWindow
->UpdateRegion
, ParentWindow
->UpdateRegion
,
64 ValidRegion
, RGN_DIFF
);
65 /* FIXME: If the resulting region is empty, remove fake posted paint message */
66 NtGdiOffsetRgn(ValidRegion
, -OffsetX
, -OffsetY
);
68 IntUnLockWindowUpdate(ParentWindow
);
70 OldWindow
= ParentWindow
;
71 ParentWindow
= IntGetParentObject(ParentWindow
);
72 IntReleaseWindowObject(OldWindow
);
79 * Internal function used by IntRedrawWindow.
83 IntPaintWindows(PWINDOW_OBJECT Window
, ULONG Flags
)
86 HWND hWnd
= Window
->Self
;
89 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
91 if (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
)
93 IntLockWindowUpdate(Window
);
94 if (Window
->NCUpdateRegion
)
96 IntValidateParent(Window
, Window
->NCUpdateRegion
);
98 TempRegion
= Window
->NCUpdateRegion
;
99 if ((HANDLE
) 1 != TempRegion
&& NULL
!= TempRegion
)
101 GDIOBJ_SetOwnership(TempRegion
, PsGetCurrentProcess());
103 Window
->NCUpdateRegion
= NULL
;
104 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
105 MsqDecPaintCountQueue(Window
->MessageQueue
);
106 IntUnLockWindowUpdate(Window
);
107 IntSendMessage(hWnd
, WM_NCPAINT
, (WPARAM
)TempRegion
, 0);
108 if ((HANDLE
) 1 != TempRegion
&& NULL
!= TempRegion
)
110 /* NOTE: The region can already be deleted! */
111 GDIOBJ_FreeObj(TempRegion
, GDI_OBJECT_TYPE_REGION
| GDI_OBJECT_TYPE_SILENT
);
115 if (Window
->Flags
& WINDOWOBJECT_NEED_ERASEBKGND
)
117 if (Window
->UpdateRegion
)
120 * This surely wrong! Why we would want to validate the parent?
121 * It breaks quite a few things including dummy WM_ERASEBKGND
122 * implementations that return only TRUE and have corresponding
123 * WM_PAINT that doesn't paint the whole client area.
124 * I left the code here so that no one will readd it again!
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 IntLockWindowUpdate(Window
);
148 if (Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
150 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
151 if (Window
->UpdateRegion
== NULL
)
153 MsqDecPaintCountQueue(Window
->MessageQueue
);
156 IntUnLockWindowUpdate(Window
);
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)
211 IntLockWindowUpdate(Window
);
212 if (!Window
->WindowRegion
|| (Window
->Style
& WS_MINIMIZE
))
216 IntUnLockWindowUpdate(Window
);
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
);
226 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, Window
->WindowRegion
, RGN_AND
);
227 IntUnLockWindowUpdate(Window
);
231 * Save current state of pending updates
234 IntLockWindowUpdate(Window
);
235 HadPaintMessage
= Window
->UpdateRegion
!= NULL
||
236 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
;
237 HadNCPaintMessage
= Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
;
240 * Update the region and flags
243 if (Flags
& RDW_INVALIDATE
&& RgnType
!= NULLREGION
)
245 if (Window
->UpdateRegion
== NULL
)
247 Window
->UpdateRegion
= NtGdiCreateRectRgn(0, 0, 0, 0);
248 GDIOBJ_SetOwnership(Window
->UpdateRegion
, NULL
);
251 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
252 hRgn
, RGN_OR
) == NULLREGION
)
254 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
255 NtGdiDeleteObject(Window
->UpdateRegion
);
256 Window
->UpdateRegion
= NULL
;
259 if (Flags
& RDW_FRAME
)
260 Window
->Flags
|= WINDOWOBJECT_NEED_NCPAINT
;
261 if (Flags
& RDW_ERASE
)
262 Window
->Flags
|= WINDOWOBJECT_NEED_ERASEBKGND
;
267 if (Flags
& RDW_VALIDATE
&& RgnType
!= NULLREGION
)
269 if (Window
->UpdateRegion
!= NULL
)
271 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
272 hRgn
, RGN_DIFF
) == NULLREGION
)
274 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
275 NtGdiDeleteObject(Window
->UpdateRegion
);
276 Window
->UpdateRegion
= NULL
;
280 if (Window
->UpdateRegion
== NULL
)
281 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
282 if (Flags
& RDW_NOFRAME
)
283 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
284 if (Flags
& RDW_NOERASE
)
285 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
288 if (Flags
& RDW_INTERNALPAINT
)
290 Window
->Flags
|= WINDOWOBJECT_NEED_INTERNALPAINT
;
293 if (Flags
& RDW_NOINTERNALPAINT
)
295 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
299 * Split the nonclient update region.
302 if (NULL
!= Window
->UpdateRegion
)
304 HRGN hRgnWindow
, hRgnNonClient
;
306 hRgnWindow
= UnsafeIntCreateRectRgnIndirect(&Window
->ClientRect
);
307 NtGdiOffsetRgn(hRgnWindow
,
308 -Window
->WindowRect
.left
,
309 -Window
->WindowRect
.top
);
311 hRgnNonClient
= NtGdiCreateRectRgn(0, 0, 0, 0);
312 if (NtGdiCombineRgn(hRgnNonClient
, Window
->UpdateRegion
,
313 hRgnWindow
, RGN_DIFF
) == NULLREGION
)
315 NtGdiDeleteObject(hRgnNonClient
);
316 hRgnNonClient
= NULL
;
320 GDIOBJ_SetOwnership(hRgnNonClient
, NULL
);
324 * Remove the nonclient region from the standard update region.
326 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
327 hRgnWindow
, RGN_AND
) == NULLREGION
)
329 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
330 NtGdiDeleteObject(Window
->UpdateRegion
);
331 Window
->UpdateRegion
= NULL
;
334 if (Window
->NCUpdateRegion
== NULL
)
336 Window
->NCUpdateRegion
= hRgnNonClient
;
340 if(NULL
!= hRgnNonClient
)
342 NtGdiCombineRgn(Window
->NCUpdateRegion
, Window
->NCUpdateRegion
,
343 hRgnNonClient
, RGN_OR
);
344 GDIOBJ_SetOwnership(hRgnNonClient
, PsGetCurrentProcess());
345 NtGdiDeleteObject(hRgnNonClient
);
349 NtGdiDeleteObject(hRgnWindow
);
353 * Process children if needed
356 if (!(Flags
& RDW_NOCHILDREN
) && !(Window
->Style
& WS_MINIMIZE
) &&
357 ((Flags
& RDW_ALLCHILDREN
) || !(Window
->Style
& WS_CLIPCHILDREN
)))
360 PWINDOW_OBJECT Child
;
362 if ((List
= IntWinListChildren(Window
)))
364 for (phWnd
= List
; *phWnd
; ++phWnd
)
366 Child
= IntGetWindowObject(*phWnd
);
371 if (Child
->Style
& WS_VISIBLE
)
374 * Recursive call to update children UpdateRegion
376 HRGN hRgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
377 NtGdiCombineRgn(hRgnTemp
, hRgn
, 0, RGN_COPY
);
378 NtGdiOffsetRgn(hRgnTemp
,
379 Window
->WindowRect
.left
- Child
->WindowRect
.left
,
380 Window
->WindowRect
.top
- Child
->WindowRect
.top
);
381 IntInvalidateWindows(Child
, hRgnTemp
, Flags
);
382 NtGdiDeleteObject(hRgnTemp
);
384 IntReleaseWindowObject(Child
);
391 * Fake post paint messages to window message queue if needed
394 HasPaintMessage
= Window
->UpdateRegion
!= NULL
||
395 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
;
396 HasNCPaintMessage
= Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
;
398 if (HasPaintMessage
!= HadPaintMessage
)
401 MsqDecPaintCountQueue(Window
->MessageQueue
);
403 MsqIncPaintCountQueue(Window
->MessageQueue
);
406 if (HasNCPaintMessage
!= HadNCPaintMessage
)
408 if (HadNCPaintMessage
)
409 MsqDecPaintCountQueue(Window
->MessageQueue
);
411 MsqIncPaintCountQueue(Window
->MessageQueue
);
414 IntUnLockWindowUpdate(Window
);
418 * IntIsWindowDrawable
421 * Window is drawable when it is visible and all parents are not
426 IntIsWindowDrawable(PWINDOW_OBJECT Window
)
428 PWINDOW_OBJECT Old
, Wnd
= Window
;
430 IntReferenceWindowObject(Wnd
);
433 if (!(Wnd
->Style
& WS_VISIBLE
) ||
434 ((Wnd
->Style
& WS_MINIMIZE
) && (Wnd
!= Window
)))
436 IntReleaseWindowObject(Wnd
);
440 Wnd
= IntGetParentObject(Wnd
);
441 IntReleaseWindowObject(Old
);
450 * Internal version of NtUserRedrawWindow that takes WINDOW_OBJECT as
455 IntRedrawWindow(PWINDOW_OBJECT Window
, const RECT
* UpdateRect
, HRGN UpdateRgn
,
462 * Validation of passed parameters.
465 if (!IntIsWindowDrawable(Window
) ||
466 (Flags
& (RDW_VALIDATE
| RDW_INVALIDATE
)) ==
467 (RDW_VALIDATE
| RDW_INVALIDATE
))
474 * Transform the parameters UpdateRgn and UpdateRect into
475 * a region hRgn specified in window coordinates.
478 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
))
480 if (UpdateRgn
!= NULL
)
482 hRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
483 NtGdiCombineRgn(hRgn
, UpdateRgn
, NULL
, RGN_COPY
);
485 Window
->ClientRect
.left
- Window
->WindowRect
.left
,
486 Window
->ClientRect
.top
- Window
->WindowRect
.top
);
488 if (UpdateRect
!= NULL
)
490 hRgn
= UnsafeIntCreateRectRgnIndirect((RECT
*)UpdateRect
);
492 Window
->ClientRect
.left
- Window
->WindowRect
.left
,
493 Window
->ClientRect
.top
- Window
->WindowRect
.top
);
495 if ((Flags
& (RDW_INVALIDATE
| RDW_FRAME
)) == (RDW_INVALIDATE
| RDW_FRAME
) ||
496 (Flags
& (RDW_VALIDATE
| RDW_NOFRAME
)) == (RDW_VALIDATE
| RDW_NOFRAME
))
498 hRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
500 -Window
->WindowRect
.left
,
501 -Window
->WindowRect
.top
);
505 hRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->ClientRect
);
507 -Window
->WindowRect
.left
,
508 -Window
->WindowRect
.top
);
514 * Adjust the window update region depending on hRgn and flags.
517 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
| RDW_INTERNALPAINT
| RDW_NOINTERNALPAINT
))
519 IntInvalidateWindows(Window
, hRgn
, Flags
);
524 * Repaint and erase windows if needed.
527 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
529 IntPaintWindows(Window
, Flags
);
539 NtGdiDeleteObject(hRgn
);
546 IntIsWindowDirty(PWINDOW_OBJECT Window
)
548 return (Window
->Style
& WS_VISIBLE
) &&
549 ((Window
->UpdateRegion
!= NULL
) ||
550 (Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
) ||
551 (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
));
555 IntFindWindowToRepaint(HWND hWnd
, PW32THREAD Thread
)
557 PWINDOW_OBJECT Window
;
558 PWINDOW_OBJECT Child
;
559 HWND hFoundWnd
= NULL
;
561 Window
= IntGetWindowObject(hWnd
);
565 if (IntIsWindowDirty(Window
) &&
566 IntWndBelongsToThread(Window
, Thread
))
568 IntReleaseWindowObject(Window
);
572 IntLockRelatives(Window
);
573 for (Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
575 if (IntIsWindowDirty(Child
) &&
576 IntWndBelongsToThread(Child
, Thread
))
578 hFoundWnd
= Child
->Self
;
582 IntUnLockRelatives(Window
);
584 if (hFoundWnd
== NULL
)
589 List
= IntWinListChildren(Window
);
592 for (i
= 0; List
[i
]; i
++)
594 hFoundWnd
= IntFindWindowToRepaint(List
[i
], Thread
);
595 if (hFoundWnd
!= NULL
)
602 IntReleaseWindowObject(Window
);
608 IntGetPaintMessage(HWND hWnd
, UINT MsgFilterMin
, UINT MsgFilterMax
,
609 PW32THREAD Thread
, MSG
*Message
, BOOL Remove
)
611 PWINDOW_OBJECT Window
;
612 PUSER_MESSAGE_QUEUE MessageQueue
= (PUSER_MESSAGE_QUEUE
)Thread
->MessageQueue
;
614 if (!MessageQueue
->PaintPosted
)
618 Message
->hwnd
= IntFindWindowToRepaint(hWnd
, PsGetWin32Thread());
620 Message
->hwnd
= IntFindWindowToRepaint(IntGetDesktopWindow(), PsGetWin32Thread());
622 if (Message
->hwnd
== NULL
)
626 DPRINT1("PAINTING BUG: Thread marked as containing dirty windows, but no dirty windows found!\n");
627 IntLockMessageQueue(MessageQueue
);
628 MessageQueue
->PaintPosted
= 0;
629 MessageQueue
->PaintCount
= 0;
630 IntUnLockMessageQueue(MessageQueue
);
635 Window
= IntGetWindowObject(Message
->hwnd
);
638 IntLockWindowUpdate(Window
);
640 if ((MsgFilterMin
== 0 && MsgFilterMax
== 0) ||
641 (MsgFilterMin
<= WM_PAINT
&& WM_PAINT
<= MsgFilterMax
))
643 Message
->message
= WM_PAINT
;
644 Message
->wParam
= Message
->lParam
= 0;
645 if (Remove
&& Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
647 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
648 if (Window
->UpdateRegion
== NULL
)
650 MsqDecPaintCountQueue(Window
->MessageQueue
);
654 IntUnLockWindowUpdate(Window
);
656 IntReleaseWindowObject(Window
);
664 IntFixCaret(HWND hWnd
, LPRECT lprc
, UINT flags
)
666 PDESKTOP_OBJECT Desktop
;
667 PTHRDCARETINFO CaretInfo
;
670 Desktop
= PsGetCurrentThread()->Tcb
.Win32Thread
->Desktop
;
671 CaretInfo
= ((PUSER_MESSAGE_QUEUE
)Desktop
->ActiveMessageQueue
)->CaretInfo
;
672 hWndCaret
= CaretInfo
->hWnd
;
673 if (hWndCaret
== hWnd
||
674 ((flags
& SW_SCROLLCHILDREN
) && IntIsChildWindow(hWnd
, hWndCaret
)))
676 POINT pt
, FromOffset
, ToOffset
, Offset
;
679 pt
.x
= CaretInfo
->Pos
.x
;
680 pt
.y
= CaretInfo
->Pos
.y
;
681 IntGetClientOrigin(hWndCaret
, &FromOffset
);
682 IntGetClientOrigin(hWnd
, &ToOffset
);
683 Offset
.x
= FromOffset
.x
- ToOffset
.x
;
684 Offset
.y
= FromOffset
.y
- ToOffset
.y
;
687 rcCaret
.right
= pt
.x
+ CaretInfo
->Size
.cx
;
688 rcCaret
.bottom
= pt
.y
+ CaretInfo
->Size
.cy
;
689 if (IntGdiIntersectRect(lprc
, lprc
, &rcCaret
))
701 /* PUBLIC FUNCTIONS ***********************************************************/
711 NtUserBeginPaint(HWND hWnd
, PAINTSTRUCT
* UnsafePs
)
713 PWINDOW_OBJECT Window
;
718 if (!(Window
= IntGetWindowObject(hWnd
)))
720 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
724 NtUserHideCaret(hWnd
);
726 if (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
)
730 if (Window
->NCUpdateRegion
!= (HANDLE
)1 &&
731 Window
->NCUpdateRegion
!= NULL
)
733 GDIOBJ_SetOwnership(Window
->NCUpdateRegion
, PsGetCurrentProcess());
735 hRgn
= Window
->NCUpdateRegion
;
736 IntValidateParent(Window
, Window
->NCUpdateRegion
);
737 Window
->NCUpdateRegion
= NULL
;
738 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
739 MsqDecPaintCountQueue(Window
->MessageQueue
);
740 IntSendMessage(hWnd
, WM_NCPAINT
, (WPARAM
)hRgn
, 0);
741 if (hRgn
!= (HANDLE
)1 && hRgn
!= NULL
)
743 /* NOTE: The region can already by deleted! */
744 GDIOBJ_FreeObj(hRgn
, GDI_OBJECT_TYPE_REGION
| GDI_OBJECT_TYPE_SILENT
);
748 RtlZeroMemory(&Ps
, sizeof(PAINTSTRUCT
));
749 Ps
.hdc
= NtUserGetDCEx(hWnd
, 0, DCX_INTERSECTUPDATE
| DCX_WINDOWPAINT
|
754 IntReleaseWindowObject(Window
);
758 IntLockWindowUpdate(Window
);
759 if (Window
->UpdateRegion
!= NULL
)
761 MsqDecPaintCountQueue(Window
->MessageQueue
);
762 IntValidateParent(Window
, Window
->UpdateRegion
);
763 Rgn
= RGNDATA_LockRgn(Window
->UpdateRegion
);
766 UnsafeIntGetRgnBox(Rgn
, &Ps
.rcPaint
);
767 RGNDATA_UnlockRgn(Window
->UpdateRegion
);
768 IntGdiOffsetRect(&Ps
.rcPaint
,
769 Window
->WindowRect
.left
- Window
->ClientRect
.left
,
770 Window
->WindowRect
.top
- Window
->ClientRect
.top
);
774 IntGetClientRect(Window
, &Ps
.rcPaint
);
776 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
777 NtGdiDeleteObject(Window
->UpdateRegion
);
778 Window
->UpdateRegion
= NULL
;
782 IntGetClientRect(Window
, &Ps
.rcPaint
);
784 IntUnLockWindowUpdate(Window
);
786 if (Window
->Flags
& WINDOWOBJECT_NEED_ERASEBKGND
)
788 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
789 Ps
.fErase
= !IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)Ps
.hdc
, 0);
796 IntReleaseWindowObject(Window
);
798 Status
= MmCopyToCaller(UnsafePs
, &Ps
, sizeof(PAINTSTRUCT
));
799 if (! NT_SUCCESS(Status
))
801 SetLastNtError(Status
);
816 NtUserEndPaint(HWND hWnd
, CONST PAINTSTRUCT
* lPs
)
818 NtUserReleaseDC(hWnd
, lPs
->hdc
);
819 NtUserShowCaret(hWnd
);
825 * NtUserInvalidateRect
832 NtUserInvalidateRect(HWND hWnd
, CONST RECT
*Rect
, BOOL Erase
)
834 return NtUserRedrawWindow(hWnd
, Rect
, 0, RDW_INVALIDATE
| (Erase
? RDW_ERASE
: 0));
838 * NtUserInvalidateRgn
845 NtUserInvalidateRgn(HWND hWnd
, HRGN Rgn
, BOOL Erase
)
847 return NtUserRedrawWindow(hWnd
, NULL
, Rgn
, RDW_INVALIDATE
| (Erase
? RDW_ERASE
: 0));
858 NtUserValidateRgn(HWND hWnd
, HRGN hRgn
)
860 return NtUserRedrawWindow(hWnd
, NULL
, hRgn
, RDW_VALIDATE
| RDW_NOCHILDREN
);
871 NtUserUpdateWindow(HWND hWnd
)
873 return NtUserRedrawWindow(hWnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
884 NtUserGetUpdateRgn(HWND hWnd
, HRGN hRgn
, BOOL bErase
)
886 PWINDOW_OBJECT Window
;
889 if (!(Window
= IntGetWindowObject(hWnd
)))
891 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
895 if (Window
->UpdateRegion
== NULL
)
897 RegionType
= (NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0) ? NULLREGION
: ERROR
);
901 RegionType
= NtGdiCombineRgn(hRgn
, Window
->UpdateRegion
, hRgn
, RGN_COPY
);
904 Window
->WindowRect
.left
- Window
->ClientRect
.left
,
905 Window
->WindowRect
.top
- Window
->ClientRect
.top
);
908 IntReleaseWindowObject(Window
);
910 if (bErase
&& RegionType
!= NULLREGION
&& RegionType
!= ERROR
)
912 NtUserRedrawWindow(hWnd
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
919 * NtUserGetUpdateRect
926 NtUserGetUpdateRect(HWND Wnd
, LPRECT UnsafeRect
, BOOL Erase
)
933 Rgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
936 NtGdiDeleteObject(Rgn
);
937 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
940 NtUserGetUpdateRgn(Wnd
, Rgn
, Erase
);
941 RgnData
= RGNDATA_LockRgn(Rgn
);
944 NtGdiDeleteObject(Rgn
);
945 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
948 if (ERROR
== UnsafeIntGetRgnBox(RgnData
, &Rect
))
950 RGNDATA_UnlockRgn(Rgn
);
951 NtGdiDeleteObject(Rgn
);
952 SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES
);
955 RGNDATA_UnlockRgn(Rgn
);
956 NtGdiDeleteObject(Rgn
);
958 if (UnsafeRect
!= NULL
)
960 Status
= MmCopyToCaller(UnsafeRect
, &Rect
, sizeof(RECT
));
961 if (! NT_SUCCESS(Status
))
963 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
968 return Rect
.left
< Rect
.right
&& Rect
.top
< Rect
.bottom
;
979 NtUserRedrawWindow(HWND hWnd
, CONST RECT
*lprcUpdate
, HRGN hrgnUpdate
,
986 if (!(Wnd
= IntGetWindowObject(hWnd
? hWnd
: IntGetDesktopWindow())))
988 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
992 if (lprcUpdate
!= NULL
)
994 Status
= MmCopyFromCaller(&SafeUpdateRect
, (PRECT
)lprcUpdate
,
997 if (!NT_SUCCESS(Status
))
999 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1000 IntReleaseWindowObject(Wnd
);
1005 Status
= IntRedrawWindow(Wnd
, NULL
== lprcUpdate
? NULL
: &SafeUpdateRect
,
1008 if (!NT_SUCCESS(Status
))
1010 /* IntRedrawWindow fails only in case that flags are invalid */
1011 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1012 IntReleaseWindowObject(Wnd
);
1016 IntReleaseWindowObject(Wnd
);
1028 NtUserScrollDC(HDC hDC
, INT dx
, INT dy
, const RECT
*lprcScroll
,
1029 const RECT
*lprcClip
, HRGN hrgnUpdate
, LPRECT lprcUpdate
)
1031 RECT rSrc
, rClipped_src
, rClip
, rDst
, offset
;
1035 * Compute device clipping region (in device coordinates).
1038 DC
= DC_LockDc(hDC
);
1046 IntGdiGetClipBox(hDC
, &rSrc
);
1047 IntLPtoDP(DC
, (LPPOINT
)&rSrc
, 2);
1052 IntGdiGetClipBox(hDC
, &rClip
);
1053 IntLPtoDP(DC
, (LPPOINT
)&rClip
, 2);
1055 IntGdiIntersectRect(&rClipped_src
, &rSrc
, &rClip
);
1057 rDst
= rClipped_src
;
1058 IntGdiSetRect(&offset
, 0, 0, dx
, dy
);
1059 IntLPtoDP(DC
, (LPPOINT
)&offset
, 2);
1060 IntGdiOffsetRect(&rDst
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
1061 IntGdiIntersectRect(&rDst
, &rDst
, &rClip
);
1064 * Copy bits, if possible.
1067 if (rDst
.bottom
> rDst
.top
&& rDst
.right
> rDst
.left
)
1069 RECT rDst_lp
= rDst
, rSrc_lp
= rDst
;
1071 IntGdiOffsetRect(&rSrc_lp
, offset
.left
- offset
.right
, offset
.top
- offset
.bottom
);
1072 IntDPtoLP(DC
, (LPPOINT
)&rDst_lp
, 2);
1073 IntDPtoLP(DC
, (LPPOINT
)&rSrc_lp
, 2);
1076 if (!NtGdiBitBlt(hDC
, rDst_lp
.left
, rDst_lp
.top
, rDst_lp
.right
- rDst_lp
.left
,
1077 rDst_lp
.bottom
- rDst_lp
.top
, hDC
, rSrc_lp
.left
, rSrc_lp
.top
,
1087 * Compute update areas. This is the clipped source or'ed with the
1088 * unclipped source translated minus the clipped src translated (rDst)
1089 * all clipped to rClip.
1092 if (hrgnUpdate
|| lprcUpdate
)
1094 HRGN hRgn
= hrgnUpdate
, hRgn2
;
1097 NtGdiSetRectRgn(hRgn
, rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
1099 hRgn
= NtGdiCreateRectRgn(rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
1101 hRgn2
= UnsafeIntCreateRectRgnIndirect(&rSrc
);
1102 NtGdiOffsetRgn(hRgn2
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
1103 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_OR
);
1105 NtGdiSetRectRgn(hRgn2
, rDst
.left
, rDst
.top
, rDst
.right
, rDst
.bottom
);
1106 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_DIFF
);
1108 NtGdiSetRectRgn(hRgn2
, rClip
.left
, rClip
.top
, rClip
.right
, rClip
.bottom
);
1109 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_AND
);
1113 NtGdiGetRgnBox(hRgn
, lprcUpdate
);
1115 /* Put the lprcUpdate in logical coordinate */
1116 NtGdiDPtoLP(hDC
, (LPPOINT
)lprcUpdate
, 2);
1119 NtGdiDeleteObject(hRgn
);
1120 NtGdiDeleteObject(hRgn2
);
1126 * NtUserScrollWindowEx
1133 NtUserScrollWindowEx(HWND hWnd
, INT dx
, INT dy
, const RECT
*UnsafeRect
,
1134 const RECT
*UnsafeClipRect
, HRGN hrgnUpdate
, LPRECT rcUpdate
, UINT flags
)
1136 RECT rc
, cliprc
, caretrc
, rect
, clipRect
;
1138 PWINDOW_OBJECT Window
;
1142 BOOL bUpdate
= (rcUpdate
|| hrgnUpdate
|| flags
& (SW_INVALIDATE
| SW_ERASE
));
1143 BOOL bOwnRgn
= TRUE
;
1146 Window
= IntGetWindowObject(hWnd
);
1147 if (!Window
|| !IntIsWindowDrawable(Window
))
1149 IntReleaseWindowObject(Window
);
1153 IntGetClientRect(Window
, &rc
);
1154 if (NULL
!= UnsafeRect
)
1156 Status
= MmCopyFromCaller(&rect
, UnsafeRect
, sizeof(RECT
));
1157 if (! NT_SUCCESS(Status
))
1159 SetLastNtError(Status
);
1162 IntGdiIntersectRect(&rc
, &rc
, &rect
);
1165 if (NULL
!= UnsafeClipRect
)
1167 Status
= MmCopyFromCaller(&clipRect
, UnsafeClipRect
, sizeof(RECT
));
1168 if (! NT_SUCCESS(Status
))
1170 SetLastNtError(Status
);
1173 IntGdiIntersectRect(&cliprc
, &rc
, &clipRect
);
1178 if (cliprc
.right
<= cliprc
.left
|| cliprc
.bottom
<= cliprc
.top
||
1179 (dx
== 0 && dy
== 0))
1185 hwndCaret
= IntFixCaret(hWnd
, &caretrc
, flags
);
1190 hrgnUpdate
= NtGdiCreateRectRgn(0, 0, 0, 0);
1192 hDC
= NtUserGetDCEx(hWnd
, 0, DCX_CACHE
| DCX_USESTYLE
);
1195 NtUserScrollDC(hDC
, dx
, dy
, &rc
, &cliprc
, hrgnUpdate
, rcUpdate
);
1196 NtUserReleaseDC(hWnd
, hDC
);
1200 * Take into account the fact that some damage may have occurred during
1204 hrgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
1205 Result
= NtUserGetUpdateRgn(hWnd
, hrgnTemp
, FALSE
);
1206 if (Result
!= NULLREGION
)
1208 HRGN hrgnClip
= UnsafeIntCreateRectRgnIndirect(&cliprc
);
1209 NtGdiOffsetRgn(hrgnTemp
, dx
, dy
);
1210 NtGdiCombineRgn(hrgnTemp
, hrgnTemp
, hrgnClip
, RGN_AND
);
1211 NtUserRedrawWindow(hWnd
, NULL
, hrgnTemp
, RDW_INVALIDATE
| RDW_ERASE
);
1212 NtGdiDeleteObject(hrgnClip
);
1214 NtGdiDeleteObject(hrgnTemp
);
1216 if (flags
& SW_SCROLLCHILDREN
)
1218 HWND
*List
= IntWinListChildren(Window
);
1225 for (i
= 0; List
[i
]; i
++)
1227 NtUserGetWindowRect(List
[i
], &r
);
1228 IntGetClientOrigin(hWnd
, &ClientOrigin
);
1229 r
.left
-= ClientOrigin
.x
;
1230 r
.top
-= ClientOrigin
.y
;
1231 r
.right
-= ClientOrigin
.x
;
1232 r
.bottom
-= ClientOrigin
.y
;
1233 if (! UnsafeRect
|| IntGdiIntersectRect(&dummy
, &r
, &rc
))
1234 WinPosSetWindowPos(List
[i
], 0, r
.left
+ dx
, r
.top
+ dy
, 0, 0,
1235 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
|
1242 if (flags
& (SW_INVALIDATE
| SW_ERASE
))
1243 NtUserRedrawWindow(hWnd
, NULL
, hrgnUpdate
, RDW_INVALIDATE
| RDW_ERASE
|
1244 ((flags
& SW_ERASE
) ? RDW_ERASENOW
: 0) |
1245 ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0));
1247 if (bOwnRgn
&& hrgnUpdate
)
1248 NtGdiDeleteObject(hrgnUpdate
);
1252 IntSetCaretPos(caretrc
.left
+ dx
, caretrc
.top
+ dy
);
1253 NtUserShowCaret(hwndCaret
);
1256 IntReleaseWindowObject(Window
);