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 ******************************************************************/
38 /* PRIVATE FUNCTIONS **********************************************************/
41 * @name IntIntersectWithParents
43 * Intersect window rectangle with all parent client rectangles.
46 * Pointer to child window to start intersecting from.
48 * Pointer to rectangle that we want to intersect in screen
49 * coordinates on input and intersected rectangle on output (if TRUE
53 * If any parent is minimized or invisible or the resulting rectangle
54 * is empty then FALSE is returned. Otherwise TRUE is returned.
58 IntIntersectWithParents(PWINDOW_OBJECT Child
, PRECT WindowRect
)
60 PWINDOW_OBJECT ParentWindow
;
62 ParentWindow
= Child
->Parent
;
63 while (ParentWindow
!= NULL
)
65 if (!(ParentWindow
->Style
& WS_VISIBLE
) ||
66 (ParentWindow
->Style
& WS_MINIMIZE
))
71 if (!IntGdiIntersectRect(WindowRect
, WindowRect
, &ParentWindow
->ClientRect
))
76 /* FIXME: Layered windows. */
78 ParentWindow
= ParentWindow
->Parent
;
85 IntValidateParent(PWINDOW_OBJECT Child
, HRGN ValidRegion
)
87 PWINDOW_OBJECT ParentWindow
= Child
->Parent
;
91 if (ParentWindow
->Style
& WS_CLIPCHILDREN
)
94 if (ParentWindow
->UpdateRegion
!= 0)
96 NtGdiCombineRgn(ParentWindow
->UpdateRegion
, ParentWindow
->UpdateRegion
,
97 ValidRegion
, RGN_DIFF
);
98 /* FIXME: If the resulting region is empty, remove fake posted paint message */
101 ParentWindow
= ParentWindow
->Parent
;
106 * @name IntCalcWindowRgn
108 * Get a window or client region.
112 IntCalcWindowRgn(PWINDOW_OBJECT Window
, BOOL Client
)
118 hRgnWindow
= UnsafeIntCreateRectRgnIndirect(&Window
->ClientRect
);
120 hRgnWindow
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
122 if (Window
->WindowRegion
!= NULL
&& !(Window
->Style
& WS_MINIMIZE
))
124 NtGdiOffsetRgn(hRgnWindow
,
125 -Window
->WindowRect
.left
,
126 -Window
->WindowRect
.top
);
127 RgnType
= NtGdiCombineRgn(hRgnWindow
, hRgnWindow
, Window
->WindowRegion
, RGN_AND
);
128 NtGdiOffsetRgn(hRgnWindow
,
129 Window
->WindowRect
.left
,
130 Window
->WindowRect
.top
);
137 * @name IntGetNCUpdateRgn
139 * Get non-client update region of a window and optionally validate it.
142 * Pointer to window to get the NC update region from.
144 * Set to TRUE to force validating the NC update region.
147 * Handle to NC update region. The caller is responsible for deleting
152 IntGetNCUpdateRgn(PWINDOW_OBJECT Window
, BOOL Validate
)
158 if (Window
->UpdateRegion
!= NULL
&&
159 Window
->UpdateRegion
!= (HRGN
)1)
161 hRgnNonClient
= NtGdiCreateRectRgn(0, 0, 0, 0);
162 hRgnWindow
= IntCalcWindowRgn(Window
, TRUE
);
165 * If region creation fails it's safe to fallback to whole
169 if (hRgnNonClient
== NULL
)
174 RgnType
= NtGdiCombineRgn(hRgnNonClient
, Window
->UpdateRegion
,
175 hRgnWindow
, RGN_DIFF
);
176 if (RgnType
== ERROR
)
178 NtGdiDeleteObject(hRgnNonClient
);
181 else if (RgnType
== NULLREGION
)
183 NtGdiDeleteObject(hRgnNonClient
);
188 * Remove the nonclient region from the standard update region if
189 * we were asked for it.
194 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
195 hRgnWindow
, RGN_AND
) == NULLREGION
)
197 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
198 NtGdiDeleteObject(Window
->UpdateRegion
);
199 Window
->UpdateRegion
= NULL
;
200 if (!(Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
))
201 MsqDecPaintCountQueue(Window
->MessageQueue
);
205 NtGdiDeleteObject(hRgnWindow
);
207 return hRgnNonClient
;
211 return Window
->UpdateRegion
;
218 * Internal function used by IntRedrawWindow.
222 co_IntPaintWindows(PWINDOW_OBJECT Window
, ULONG Flags
)
225 HWND hWnd
= Window
->hSelf
;
228 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
230 if (Window
->UpdateRegion
)
232 IntValidateParent(Window
, Window
->UpdateRegion
);
235 if (Flags
& RDW_UPDATENOW
)
237 if (Window
->UpdateRegion
!= NULL
||
238 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
240 co_IntSendMessage(hWnd
, WM_PAINT
, 0, 0);
245 if (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
)
247 TempRegion
= IntGetNCUpdateRgn(Window
, TRUE
);
248 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
249 MsqDecPaintCountQueue(Window
->MessageQueue
);
250 co_IntSendMessage(hWnd
, WM_NCPAINT
, (WPARAM
)TempRegion
, 0);
251 if ((HANDLE
) 1 != TempRegion
&& NULL
!= TempRegion
)
253 /* NOTE: The region can already be deleted! */
254 GDIOBJ_FreeObj(TempRegion
, GDI_OBJECT_TYPE_REGION
| GDI_OBJECT_TYPE_SILENT
);
258 if (Window
->Flags
& WINDOWOBJECT_NEED_ERASEBKGND
)
260 if (Window
->UpdateRegion
)
262 hDC
= UserGetDCEx(Window
, Window
->UpdateRegion
,
263 DCX_CACHE
| DCX_USESTYLE
|
264 DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
);
265 if (co_IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)hDC
, 0))
267 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
269 UserReleaseDC(Window
, hDC
, FALSE
);
276 * Check that the window is still valid at this point
278 if (!IntIsWindow(hWnd
))
284 * Paint child windows.
286 if (!(Flags
& RDW_NOCHILDREN
) && !(Window
->Style
& WS_MINIMIZE
) &&
287 ((Flags
& RDW_ALLCHILDREN
) || !(Window
->Style
& WS_CLIPCHILDREN
)))
291 if ((List
= IntWinListChildren(Window
)))
293 for (phWnd
= List
; *phWnd
; ++phWnd
)
295 Window
= UserGetWindowObject(*phWnd
);
296 if (Window
&& (Window
->Style
& WS_VISIBLE
))
298 USER_REFERENCE_ENTRY Ref
;
299 UserRefObjectCo(Window
, &Ref
);
300 co_IntPaintWindows(Window
, Flags
);
301 UserDerefObjectCo(Window
);
310 * IntInvalidateWindows
312 * Internal function used by IntRedrawWindow.
316 IntInvalidateWindows(PWINDOW_OBJECT Window
, HRGN hRgn
, ULONG Flags
)
319 BOOL HadPaintMessage
, HadNCPaintMessage
;
320 BOOL HasPaintMessage
, HasNCPaintMessage
;
323 * Clip the given region with window rectangle (or region)
326 if (!Window
->WindowRegion
|| (Window
->Style
& WS_MINIMIZE
))
330 hRgnWindow
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
331 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, hRgnWindow
, RGN_AND
);
332 NtGdiDeleteObject(hRgnWindow
);
337 -Window
->WindowRect
.left
,
338 -Window
->WindowRect
.top
);
339 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, Window
->WindowRegion
, RGN_AND
);
341 Window
->WindowRect
.left
,
342 Window
->WindowRect
.top
);
346 * Save current state of pending updates
349 HadPaintMessage
= Window
->UpdateRegion
!= NULL
||
350 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
;
351 HadNCPaintMessage
= Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
;
354 * Update the region and flags
357 if (Flags
& RDW_INVALIDATE
&& RgnType
!= NULLREGION
)
359 if (Window
->UpdateRegion
== NULL
)
361 Window
->UpdateRegion
= NtGdiCreateRectRgn(0, 0, 0, 0);
362 GDIOBJ_SetOwnership(Window
->UpdateRegion
, NULL
);
365 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
366 hRgn
, RGN_OR
) == NULLREGION
)
368 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
369 NtGdiDeleteObject(Window
->UpdateRegion
);
370 Window
->UpdateRegion
= NULL
;
373 if (Flags
& RDW_FRAME
)
374 Window
->Flags
|= WINDOWOBJECT_NEED_NCPAINT
;
375 if (Flags
& RDW_ERASE
)
376 Window
->Flags
|= WINDOWOBJECT_NEED_ERASEBKGND
;
381 if (Flags
& RDW_VALIDATE
&& RgnType
!= NULLREGION
)
383 if (Window
->UpdateRegion
!= NULL
)
385 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
386 hRgn
, RGN_DIFF
) == NULLREGION
)
388 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
389 NtGdiDeleteObject(Window
->UpdateRegion
);
390 Window
->UpdateRegion
= NULL
;
394 if (Window
->UpdateRegion
== NULL
)
395 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
396 if (Flags
& RDW_NOFRAME
)
397 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
398 if (Flags
& RDW_NOERASE
)
399 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
402 if (Flags
& RDW_INTERNALPAINT
)
404 Window
->Flags
|= WINDOWOBJECT_NEED_INTERNALPAINT
;
407 if (Flags
& RDW_NOINTERNALPAINT
)
409 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
413 * Process children if needed
416 if (!(Flags
& RDW_NOCHILDREN
) && !(Window
->Style
& WS_MINIMIZE
) &&
417 ((Flags
& RDW_ALLCHILDREN
) || !(Window
->Style
& WS_CLIPCHILDREN
)))
419 PWINDOW_OBJECT Child
;
421 for (Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
423 if (Child
->Style
& WS_VISIBLE
)
426 * Recursive call to update children UpdateRegion
428 HRGN hRgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
429 NtGdiCombineRgn(hRgnTemp
, hRgn
, 0, RGN_COPY
);
430 IntInvalidateWindows(Child
, hRgnTemp
, Flags
);
431 NtGdiDeleteObject(hRgnTemp
);
438 * Fake post paint messages to window message queue if needed
441 HasPaintMessage
= Window
->UpdateRegion
!= NULL
||
442 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
;
443 HasNCPaintMessage
= Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
;
445 if (HasPaintMessage
!= HadPaintMessage
)
448 MsqDecPaintCountQueue(Window
->MessageQueue
);
450 MsqIncPaintCountQueue(Window
->MessageQueue
);
453 if (HasNCPaintMessage
!= HadNCPaintMessage
)
455 if (HadNCPaintMessage
)
456 MsqDecPaintCountQueue(Window
->MessageQueue
);
458 MsqIncPaintCountQueue(Window
->MessageQueue
);
464 * IntIsWindowDrawable
467 * Window is drawable when it is visible and all parents are not
472 IntIsWindowDrawable(PWINDOW_OBJECT Window
)
476 for (Wnd
= Window
; Wnd
!= NULL
; Wnd
= Wnd
->Parent
)
478 if (!(Wnd
->Style
& WS_VISIBLE
) ||
479 ((Wnd
->Style
& WS_MINIMIZE
) && (Wnd
!= Window
)))
491 * Internal version of NtUserRedrawWindow that takes WINDOW_OBJECT as
496 co_UserRedrawWindow(PWINDOW_OBJECT Window
, const RECT
* UpdateRect
, HRGN UpdateRgn
,
503 * Validation of passed parameters.
506 if (!IntIsWindowDrawable(Window
) ||
507 (Flags
& (RDW_VALIDATE
| RDW_INVALIDATE
)) ==
508 (RDW_VALIDATE
| RDW_INVALIDATE
))
515 * Transform the parameters UpdateRgn and UpdateRect into
516 * a region hRgn specified in screen coordinates.
519 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
))
521 if (UpdateRgn
!= NULL
)
523 hRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
524 if (NtGdiCombineRgn(hRgn
, UpdateRgn
, NULL
, RGN_COPY
) == NULLREGION
)
525 NtGdiDeleteObject(hRgn
);
527 NtGdiOffsetRgn(hRgn
, Window
->ClientRect
.left
, Window
->ClientRect
.top
);
529 else if (UpdateRect
!= NULL
)
531 if (!IntGdiIsEmptyRect(UpdateRect
))
533 hRgn
= UnsafeIntCreateRectRgnIndirect((RECT
*)UpdateRect
);
534 NtGdiOffsetRgn(hRgn
, Window
->ClientRect
.left
, Window
->ClientRect
.top
);
537 else if ((Flags
& (RDW_INVALIDATE
| RDW_FRAME
)) == (RDW_INVALIDATE
| RDW_FRAME
) ||
538 (Flags
& (RDW_VALIDATE
| RDW_NOFRAME
)) == (RDW_VALIDATE
| RDW_NOFRAME
))
540 if (!IntGdiIsEmptyRect(&Window
->WindowRect
))
541 hRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
545 if (!IntGdiIsEmptyRect(&Window
->ClientRect
))
546 hRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->ClientRect
);
552 * Adjust the window update region depending on hRgn and flags.
555 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
| RDW_INTERNALPAINT
| RDW_NOINTERNALPAINT
) &&
558 IntInvalidateWindows(Window
, hRgn
, Flags
);
563 * Repaint and erase windows if needed.
566 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
568 co_IntPaintWindows(Window
, Flags
);
578 NtGdiDeleteObject(hRgn
);
585 IntIsWindowDirty(PWINDOW_OBJECT Window
)
587 return (Window
->Style
& WS_VISIBLE
) &&
588 ((Window
->UpdateRegion
!= NULL
) ||
589 (Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
) ||
590 (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
));
594 IntFindWindowToRepaint(PWINDOW_OBJECT Window
, PW32THREAD Thread
)
597 PWINDOW_OBJECT TempWindow
;
599 for (; Window
!= NULL
; Window
= Window
->NextSibling
)
601 if (IntWndBelongsToThread(Window
, Thread
) &&
602 IntIsWindowDirty(Window
))
604 /* Make sure all non-transparent siblings are already drawn. */
605 if (Window
->ExStyle
& WS_EX_TRANSPARENT
)
607 for (TempWindow
= Window
->NextSibling
; TempWindow
!= NULL
;
608 TempWindow
= TempWindow
->NextSibling
)
610 if (!(TempWindow
->ExStyle
& WS_EX_TRANSPARENT
) &&
611 IntWndBelongsToThread(TempWindow
, Thread
) &&
612 IntIsWindowDirty(TempWindow
))
614 return TempWindow
->hSelf
;
619 return Window
->hSelf
;
622 if (Window
->FirstChild
)
624 hChild
= IntFindWindowToRepaint(Window
->FirstChild
, Thread
);
634 IntGetPaintMessage(HWND hWnd
, UINT MsgFilterMin
, UINT MsgFilterMax
,
635 PW32THREAD Thread
, MSG
*Message
, BOOL Remove
)
637 PUSER_MESSAGE_QUEUE MessageQueue
= (PUSER_MESSAGE_QUEUE
)Thread
->MessageQueue
;
639 if (!MessageQueue
->PaintCount
)
642 if ((MsgFilterMin
!= 0 || MsgFilterMax
!= 0) &&
643 (MsgFilterMin
> WM_PAINT
|| MsgFilterMax
< WM_PAINT
))
646 Message
->hwnd
= IntFindWindowToRepaint(UserGetDesktopWindow(), PsGetWin32Thread());
648 if (Message
->hwnd
== NULL
)
650 DPRINT1("PAINTING BUG: Thread marked as containing dirty windows, but no dirty windows found!\n");
654 if (hWnd
!= NULL
&& Message
->hwnd
!= hWnd
)
657 Message
->message
= WM_PAINT
;
658 Message
->wParam
= Message
->lParam
= 0;
665 co_IntFixCaret(PWINDOW_OBJECT Window
, LPRECT lprc
, UINT flags
)
667 PDESKTOP_OBJECT Desktop
;
668 PTHRDCARETINFO CaretInfo
;
670 PWINDOW_OBJECT WndCaret
;
672 ASSERT_REFS_CO(Window
);
674 Desktop
= ((PW32THREAD
)PsGetCurrentThread()->Tcb
.Win32Thread
)->Desktop
;
675 CaretInfo
= ((PUSER_MESSAGE_QUEUE
)Desktop
->ActiveMessageQueue
)->CaretInfo
;
676 hWndCaret
= CaretInfo
->hWnd
;
678 WndCaret
= UserGetWindowObject(hWndCaret
);
680 //fix: check for WndCaret can be null
681 if (WndCaret
== Window
||
682 ((flags
& SW_SCROLLCHILDREN
) && IntIsChildWindow(Window
, WndCaret
)))
684 POINT pt
, FromOffset
, ToOffset
, Offset
;
687 pt
.x
= CaretInfo
->Pos
.x
;
688 pt
.y
= CaretInfo
->Pos
.y
;
689 IntGetClientOrigin(WndCaret
, &FromOffset
);
690 IntGetClientOrigin(Window
, &ToOffset
);
691 Offset
.x
= FromOffset
.x
- ToOffset
.x
;
692 Offset
.y
= FromOffset
.y
- ToOffset
.y
;
695 rcCaret
.right
= pt
.x
+ CaretInfo
->Size
.cx
;
696 rcCaret
.bottom
= pt
.y
+ CaretInfo
->Size
.cy
;
697 if (IntGdiIntersectRect(lprc
, lprc
, &rcCaret
))
709 /* PUBLIC FUNCTIONS ***********************************************************/
719 NtUserBeginPaint(HWND hWnd
, PAINTSTRUCT
* UnsafePs
)
721 PWINDOW_OBJECT Window
= NULL
;
726 USER_REFERENCE_ENTRY Ref
;
728 DPRINT("Enter NtUserBeginPaint\n");
729 UserEnterExclusive();
731 if (!(Window
= UserGetWindowObject(hWnd
)))
736 UserRefObjectCo(Window
, &Ref
);
738 co_UserHideCaret(Window
);
740 if (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
)
744 hRgn
= IntGetNCUpdateRgn(Window
, FALSE
);
745 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
746 MsqDecPaintCountQueue(Window
->MessageQueue
);
747 co_IntSendMessage(hWnd
, WM_NCPAINT
, (WPARAM
)hRgn
, 0);
748 if (hRgn
!= (HANDLE
)1 && hRgn
!= NULL
)
750 /* NOTE: The region can already by deleted! */
751 GDIOBJ_FreeObj(hRgn
, GDI_OBJECT_TYPE_REGION
| GDI_OBJECT_TYPE_SILENT
);
755 RtlZeroMemory(&Ps
, sizeof(PAINTSTRUCT
));
757 Ps
.hdc
= UserGetDCEx(Window
, Window
->UpdateRegion
, DCX_INTERSECTRGN
| DCX_USESTYLE
);
763 if (Window
->UpdateRegion
!= NULL
)
765 MsqDecPaintCountQueue(Window
->MessageQueue
);
766 Rgn
= RGNDATA_LockRgn(Window
->UpdateRegion
);
769 UnsafeIntGetRgnBox(Rgn
, &Ps
.rcPaint
);
770 RGNDATA_UnlockRgn(Rgn
);
771 IntGdiIntersectRect(&Ps
.rcPaint
, &Ps
.rcPaint
, &Window
->ClientRect
);
772 IntGdiOffsetRect(&Ps
.rcPaint
,
773 -Window
->ClientRect
.left
,
774 -Window
->ClientRect
.top
);
778 IntGetClientRect(Window
, &Ps
.rcPaint
);
780 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
781 Window
->UpdateRegion
= NULL
;
785 if (Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
786 MsqDecPaintCountQueue(Window
->MessageQueue
);
788 IntGetClientRect(Window
, &Ps
.rcPaint
);
791 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
793 if (Window
->Flags
& WINDOWOBJECT_NEED_ERASEBKGND
)
795 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
796 Ps
.fErase
= !co_IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)Ps
.hdc
, 0);
803 Status
= MmCopyToCaller(UnsafePs
, &Ps
, sizeof(PAINTSTRUCT
));
804 if (! NT_SUCCESS(Status
))
806 SetLastNtError(Status
);
813 if (Window
) UserDerefObjectCo(Window
);
815 DPRINT("Leave NtUserBeginPaint, ret=%i\n",_ret_
);
829 NtUserEndPaint(HWND hWnd
, CONST PAINTSTRUCT
* lPs
)
831 PWINDOW_OBJECT Window
;
832 DECLARE_RETURN(BOOL
);
833 USER_REFERENCE_ENTRY Ref
;
835 DPRINT("Enter NtUserEndPaint\n");
836 UserEnterExclusive();
838 if (!(Window
= UserGetWindowObject(hWnd
)))
843 UserReleaseDC(Window
, lPs
->hdc
, TRUE
);
845 UserRefObjectCo(Window
, &Ref
);
846 co_UserShowCaret(Window
);
847 UserDerefObjectCo(Window
);
852 DPRINT("Leave NtUserEndPaint, ret=%i\n",_ret_
);
859 co_UserGetUpdateRgn(PWINDOW_OBJECT Window
, HRGN hRgn
, BOOL bErase
)
864 ASSERT_REFS_CO(Window
);
866 if (Window
->UpdateRegion
== NULL
)
868 RegionType
= (NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0) ? NULLREGION
: ERROR
);
872 Rect
= Window
->ClientRect
;
873 IntIntersectWithParents(Window
, &Rect
);
874 NtGdiSetRectRgn(hRgn
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
);
875 RegionType
= NtGdiCombineRgn(hRgn
, hRgn
, Window
->UpdateRegion
, RGN_AND
);
876 NtGdiOffsetRgn(hRgn
, -Window
->ClientRect
.left
, -Window
->ClientRect
.top
);
879 if (bErase
&& RegionType
!= NULLREGION
&& RegionType
!= ERROR
)
881 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
895 NtUserGetUpdateRgn(HWND hWnd
, HRGN hRgn
, BOOL bErase
)
898 PWINDOW_OBJECT Window
;
900 USER_REFERENCE_ENTRY Ref
;
902 DPRINT("Enter NtUserGetUpdateRgn\n");
903 UserEnterExclusive();
905 if (!(Window
= UserGetWindowObject(hWnd
)))
910 UserRefObjectCo(Window
, &Ref
);
911 ret
= co_UserGetUpdateRgn(Window
, hRgn
, bErase
);
912 UserDerefObjectCo(Window
);
917 DPRINT("Leave NtUserGetUpdateRgn, ret=%i\n",_ret_
);
923 * NtUserGetUpdateRect
930 NtUserGetUpdateRect(HWND hWnd
, LPRECT UnsafeRect
, BOOL bErase
)
932 PWINDOW_OBJECT Window
;
937 DECLARE_RETURN(BOOL
);
939 DPRINT("Enter NtUserGetUpdateRect\n");
940 UserEnterExclusive();
942 if (!(Window
= UserGetWindowObject(hWnd
)))
947 if (Window
->UpdateRegion
== NULL
)
949 Rect
.left
= Rect
.top
= Rect
.right
= Rect
.bottom
= 0;
953 /* Get the update region bounding box. */
954 if (Window
->UpdateRegion
== (HRGN
)1)
956 Rect
= Window
->ClientRect
;
960 RgnData
= RGNDATA_LockRgn(Window
->UpdateRegion
);
961 ASSERT(RgnData
!= NULL
);
962 RegionType
= UnsafeIntGetRgnBox(RgnData
, &Rect
);
963 RGNDATA_UnlockRgn(RgnData
);
965 if (RegionType
!= ERROR
&& RegionType
!= NULLREGION
)
966 IntGdiIntersectRect(&Rect
, &Rect
, &Window
->ClientRect
);
969 if (IntIntersectWithParents(Window
, &Rect
))
971 IntGdiOffsetRect(&Rect
,
972 -Window
->ClientRect
.left
,
973 -Window
->ClientRect
.top
);
976 Rect
.left
= Rect
.top
= Rect
.right
= Rect
.bottom
= 0;
980 if (bErase
&& !IntGdiIsEmptyRect(&Rect
))
982 USER_REFERENCE_ENTRY Ref
;
983 UserRefObjectCo(Window
, &Ref
);
984 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
985 UserDerefObjectCo(Window
);
988 if (UnsafeRect
!= NULL
)
990 Status
= MmCopyToCaller(UnsafeRect
, &Rect
, sizeof(RECT
));
991 if (!NT_SUCCESS(Status
))
993 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
998 RETURN(Window
->UpdateRegion
!= NULL
);
1001 DPRINT("Leave NtUserGetUpdateRect, ret=%i\n",_ret_
);
1007 * NtUserRedrawWindow
1014 NtUserRedrawWindow(HWND hWnd
, CONST RECT
*lprcUpdate
, HRGN hrgnUpdate
,
1017 RECT SafeUpdateRect
;
1020 DECLARE_RETURN(BOOL
);
1021 USER_REFERENCE_ENTRY Ref
;
1023 DPRINT("Enter NtUserRedrawWindow\n");
1024 UserEnterExclusive();
1026 if (!(Wnd
= UserGetWindowObject(hWnd
? hWnd
: IntGetDesktopWindow())))
1031 if (lprcUpdate
!= NULL
)
1033 Status
= MmCopyFromCaller(&SafeUpdateRect
, (PRECT
)lprcUpdate
,
1036 if (!NT_SUCCESS(Status
))
1038 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1043 UserRefObjectCo(Wnd
, &Ref
);
1045 Status
= co_UserRedrawWindow(Wnd
, NULL
== lprcUpdate
? NULL
: &SafeUpdateRect
,
1048 UserDerefObjectCo(Wnd
);
1050 if (!NT_SUCCESS(Status
))
1052 /* IntRedrawWindow fails only in case that flags are invalid */
1053 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1060 DPRINT("Leave NtUserRedrawWindow, ret=%i\n",_ret_
);
1069 UserScrollDC(HDC hDC
, INT dx
, INT dy
, const RECT
*lprcScroll
,
1070 const RECT
*lprcClip
, HRGN hrgnUpdate
, LPRECT lprcUpdate
)
1072 RECT rSrc
, rClipped_src
, rClip
, rDst
, offset
;
1076 * Compute device clipping region (in device coordinates).
1079 DC
= DC_LockDc(hDC
);
1087 IntGdiGetClipBox(hDC
, &rSrc
);
1088 IntLPtoDP(DC
, (LPPOINT
)&rSrc
, 2);
1093 IntGdiGetClipBox(hDC
, &rClip
);
1094 IntLPtoDP(DC
, (LPPOINT
)&rClip
, 2);
1096 IntGdiIntersectRect(&rClipped_src
, &rSrc
, &rClip
);
1098 rDst
= rClipped_src
;
1099 IntGdiSetRect(&offset
, 0, 0, dx
, dy
);
1100 IntLPtoDP(DC
, (LPPOINT
)&offset
, 2);
1101 IntGdiOffsetRect(&rDst
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
1102 IntGdiIntersectRect(&rDst
, &rDst
, &rClip
);
1105 * Copy bits, if possible.
1108 if (rDst
.bottom
> rDst
.top
&& rDst
.right
> rDst
.left
)
1110 RECT rDst_lp
= rDst
, rSrc_lp
= rDst
;
1112 IntGdiOffsetRect(&rSrc_lp
, offset
.left
- offset
.right
, offset
.top
- offset
.bottom
);
1113 IntDPtoLP(DC
, (LPPOINT
)&rDst_lp
, 2);
1114 IntDPtoLP(DC
, (LPPOINT
)&rSrc_lp
, 2);
1117 if (!NtGdiBitBlt(hDC
, rDst_lp
.left
, rDst_lp
.top
, rDst_lp
.right
- rDst_lp
.left
,
1118 rDst_lp
.bottom
- rDst_lp
.top
, hDC
, rSrc_lp
.left
, rSrc_lp
.top
,
1128 * Compute update areas. This is the clipped source or'ed with the
1129 * unclipped source translated minus the clipped src translated (rDst)
1130 * all clipped to rClip.
1133 if (hrgnUpdate
|| lprcUpdate
)
1135 HRGN hRgn
= hrgnUpdate
, hRgn2
;
1138 NtGdiSetRectRgn(hRgn
, rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
1140 hRgn
= NtGdiCreateRectRgn(rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
1142 hRgn2
= UnsafeIntCreateRectRgnIndirect(&rSrc
);
1143 NtGdiOffsetRgn(hRgn2
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
1144 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_OR
);
1146 NtGdiSetRectRgn(hRgn2
, rDst
.left
, rDst
.top
, rDst
.right
, rDst
.bottom
);
1147 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_DIFF
);
1149 NtGdiSetRectRgn(hRgn2
, rClip
.left
, rClip
.top
, rClip
.right
, rClip
.bottom
);
1150 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_AND
);
1154 NtGdiGetRgnBox(hRgn
, lprcUpdate
);
1156 /* Put the lprcUpdate in logical coordinate */
1157 NtGdiDPtoLP(hDC
, (LPPOINT
)lprcUpdate
, 2);
1160 NtGdiDeleteObject(hRgn
);
1161 NtGdiDeleteObject(hRgn2
);
1177 NtUserScrollDC(HDC hDC
, INT dx
, INT dy
, const RECT
*lprcScroll
,
1178 const RECT
*lprcClip
, HRGN hrgnUpdate
, LPRECT lprcUpdate
)
1180 DECLARE_RETURN(DWORD
);
1182 DPRINT("Enter NtUserScrollDC\n");
1183 UserEnterExclusive();
1185 RETURN( UserScrollDC(hDC
, dx
, dy
, lprcScroll
, lprcClip
, hrgnUpdate
, lprcUpdate
));
1188 DPRINT("Leave NtUserScrollDC, ret=%i\n",_ret_
);
1195 * NtUserScrollWindowEx
1202 NtUserScrollWindowEx(HWND hWnd
, INT dx
, INT dy
, const RECT
*UnsafeRect
,
1203 const RECT
*UnsafeClipRect
, HRGN hrgnUpdate
, LPRECT rcUpdate
, UINT flags
)
1205 RECT rc
, cliprc
, caretrc
, rect
, clipRect
;
1207 PWINDOW_OBJECT Window
= NULL
, CaretWnd
;
1211 BOOL bUpdate
= (rcUpdate
|| hrgnUpdate
|| flags
& (SW_INVALIDATE
| SW_ERASE
));
1212 BOOL bOwnRgn
= TRUE
;
1214 DECLARE_RETURN(DWORD
);
1215 USER_REFERENCE_ENTRY Ref
, CaretRef
;
1217 DPRINT("Enter NtUserScrollWindowEx\n");
1218 UserEnterExclusive();
1220 Window
= UserGetWindowObject(hWnd
);
1221 if (!Window
|| !IntIsWindowDrawable(Window
))
1223 Window
= NULL
; /* prevent deref at cleanup */
1226 UserRefObjectCo(Window
, &Ref
);
1228 IntGetClientRect(Window
, &rc
);
1230 if (NULL
!= UnsafeRect
)
1232 Status
= MmCopyFromCaller(&rect
, UnsafeRect
, sizeof(RECT
));
1233 if (! NT_SUCCESS(Status
))
1235 SetLastNtError(Status
);
1238 IntGdiIntersectRect(&rc
, &rc
, &rect
);
1241 if (NULL
!= UnsafeClipRect
)
1243 Status
= MmCopyFromCaller(&clipRect
, UnsafeClipRect
, sizeof(RECT
));
1244 if (! NT_SUCCESS(Status
))
1246 SetLastNtError(Status
);
1249 IntGdiIntersectRect(&cliprc
, &rc
, &clipRect
);
1254 if (cliprc
.right
<= cliprc
.left
|| cliprc
.bottom
<= cliprc
.top
||
1255 (dx
== 0 && dy
== 0))
1257 RETURN( NULLREGION
);
1261 hwndCaret
= co_IntFixCaret(Window
, &caretrc
, flags
);
1266 hrgnUpdate
= NtGdiCreateRectRgn(0, 0, 0, 0);
1268 hDC
= UserGetDCEx(Window
, 0, DCX_CACHE
| DCX_USESTYLE
);
1271 UserScrollDC(hDC
, dx
, dy
, &rc
, &cliprc
, hrgnUpdate
, rcUpdate
);
1272 UserReleaseDC(Window
, hDC
, FALSE
);
1276 * Take into account the fact that some damage may have occurred during
1280 hrgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
1281 Result
= co_UserGetUpdateRgn(Window
, hrgnTemp
, FALSE
);
1282 if (Result
!= NULLREGION
)
1284 HRGN hrgnClip
= UnsafeIntCreateRectRgnIndirect(&cliprc
);
1285 NtGdiOffsetRgn(hrgnTemp
, dx
, dy
);
1286 NtGdiCombineRgn(hrgnTemp
, hrgnTemp
, hrgnClip
, RGN_AND
);
1287 co_UserRedrawWindow(Window
, NULL
, hrgnTemp
, RDW_INVALIDATE
| RDW_ERASE
);
1288 NtGdiDeleteObject(hrgnClip
);
1291 NtGdiDeleteObject(hrgnTemp
);
1293 if (flags
& SW_SCROLLCHILDREN
)
1295 HWND
*List
= IntWinListChildren(Window
);
1302 USER_REFERENCE_ENTRY WndRef
;
1304 IntGetClientOrigin(Window
, &ClientOrigin
);
1305 for (i
= 0; List
[i
]; i
++)
1307 if (!(Wnd
= UserGetWindowObject(List
[i
])))
1310 r
= Wnd
->WindowRect
;
1311 r
.left
-= ClientOrigin
.x
;
1312 r
.top
-= ClientOrigin
.y
;
1313 r
.right
-= ClientOrigin
.x
;
1314 r
.bottom
-= ClientOrigin
.y
;
1316 if (! UnsafeRect
|| IntGdiIntersectRect(&dummy
, &r
, &rc
))
1318 UserRefObjectCo(Wnd
, &WndRef
);
1319 co_WinPosSetWindowPos(Wnd
, 0, r
.left
+ dx
, r
.top
+ dy
, 0, 0,
1320 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
|
1322 UserDerefObjectCo(Wnd
);
1330 if (flags
& (SW_INVALIDATE
| SW_ERASE
))
1331 co_UserRedrawWindow(Window
, NULL
, hrgnUpdate
, RDW_INVALIDATE
| RDW_ERASE
|
1332 ((flags
& SW_ERASE
) ? RDW_ERASENOW
: 0) |
1333 ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0));
1335 if (bOwnRgn
&& hrgnUpdate
)
1336 NtGdiDeleteObject(hrgnUpdate
);
1338 if ((CaretWnd
= UserGetWindowObject(hwndCaret
)))
1340 UserRefObjectCo(CaretWnd
, &CaretRef
);
1342 co_IntSetCaretPos(caretrc
.left
+ dx
, caretrc
.top
+ dy
);
1343 co_UserShowCaret(CaretWnd
);
1345 UserDerefObjectCo(CaretWnd
);
1352 UserDerefObjectCo(Window
);
1354 DPRINT("Leave NtUserScrollWindowEx, ret=%i\n",_ret_
);