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 UserRefObjectCo(Window
);
299 co_IntPaintWindows(Window
, Flags
);
300 UserDerefObjectCo(Window
);
309 * IntInvalidateWindows
311 * Internal function used by IntRedrawWindow.
315 IntInvalidateWindows(PWINDOW_OBJECT Window
, HRGN hRgn
, ULONG Flags
)
318 BOOL HadPaintMessage
, HadNCPaintMessage
;
319 BOOL HasPaintMessage
, HasNCPaintMessage
;
322 * Clip the given region with window rectangle (or region)
325 if (!Window
->WindowRegion
|| (Window
->Style
& WS_MINIMIZE
))
329 hRgnWindow
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
330 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, hRgnWindow
, RGN_AND
);
331 NtGdiDeleteObject(hRgnWindow
);
336 -Window
->WindowRect
.left
,
337 -Window
->WindowRect
.top
);
338 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, Window
->WindowRegion
, RGN_AND
);
340 Window
->WindowRect
.left
,
341 Window
->WindowRect
.top
);
345 * Save current state of pending updates
348 HadPaintMessage
= Window
->UpdateRegion
!= NULL
||
349 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
;
350 HadNCPaintMessage
= Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
;
353 * Update the region and flags
356 if (Flags
& RDW_INVALIDATE
&& RgnType
!= NULLREGION
)
358 if (Window
->UpdateRegion
== NULL
)
360 Window
->UpdateRegion
= NtGdiCreateRectRgn(0, 0, 0, 0);
361 GDIOBJ_SetOwnership(Window
->UpdateRegion
, NULL
);
364 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
365 hRgn
, RGN_OR
) == NULLREGION
)
367 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
368 NtGdiDeleteObject(Window
->UpdateRegion
);
369 Window
->UpdateRegion
= NULL
;
372 if (Flags
& RDW_FRAME
)
373 Window
->Flags
|= WINDOWOBJECT_NEED_NCPAINT
;
374 if (Flags
& RDW_ERASE
)
375 Window
->Flags
|= WINDOWOBJECT_NEED_ERASEBKGND
;
380 if (Flags
& RDW_VALIDATE
&& RgnType
!= NULLREGION
)
382 if (Window
->UpdateRegion
!= NULL
)
384 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
385 hRgn
, RGN_DIFF
) == NULLREGION
)
387 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
388 NtGdiDeleteObject(Window
->UpdateRegion
);
389 Window
->UpdateRegion
= NULL
;
393 if (Window
->UpdateRegion
== NULL
)
394 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
395 if (Flags
& RDW_NOFRAME
)
396 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
397 if (Flags
& RDW_NOERASE
)
398 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
401 if (Flags
& RDW_INTERNALPAINT
)
403 Window
->Flags
|= WINDOWOBJECT_NEED_INTERNALPAINT
;
406 if (Flags
& RDW_NOINTERNALPAINT
)
408 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
412 * Process children if needed
415 if (!(Flags
& RDW_NOCHILDREN
) && !(Window
->Style
& WS_MINIMIZE
) &&
416 ((Flags
& RDW_ALLCHILDREN
) || !(Window
->Style
& WS_CLIPCHILDREN
)))
418 PWINDOW_OBJECT Child
;
420 for (Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
422 if (Child
->Style
& WS_VISIBLE
)
425 * Recursive call to update children UpdateRegion
427 HRGN hRgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
428 NtGdiCombineRgn(hRgnTemp
, hRgn
, 0, RGN_COPY
);
429 IntInvalidateWindows(Child
, hRgnTemp
, Flags
);
430 NtGdiDeleteObject(hRgnTemp
);
437 * Fake post paint messages to window message queue if needed
440 HasPaintMessage
= Window
->UpdateRegion
!= NULL
||
441 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
;
442 HasNCPaintMessage
= Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
;
444 if (HasPaintMessage
!= HadPaintMessage
)
447 MsqDecPaintCountQueue(Window
->MessageQueue
);
449 MsqIncPaintCountQueue(Window
->MessageQueue
);
452 if (HasNCPaintMessage
!= HadNCPaintMessage
)
454 if (HadNCPaintMessage
)
455 MsqDecPaintCountQueue(Window
->MessageQueue
);
457 MsqIncPaintCountQueue(Window
->MessageQueue
);
463 * IntIsWindowDrawable
466 * Window is drawable when it is visible and all parents are not
471 IntIsWindowDrawable(PWINDOW_OBJECT Window
)
475 for (Wnd
= Window
; Wnd
!= NULL
; Wnd
= Wnd
->Parent
)
477 if (!(Wnd
->Style
& WS_VISIBLE
) ||
478 ((Wnd
->Style
& WS_MINIMIZE
) && (Wnd
!= Window
)))
490 * Internal version of NtUserRedrawWindow that takes WINDOW_OBJECT as
495 co_UserRedrawWindow(PWINDOW_OBJECT Window
, const RECT
* UpdateRect
, HRGN UpdateRgn
,
502 * Validation of passed parameters.
505 if (!IntIsWindowDrawable(Window
) ||
506 (Flags
& (RDW_VALIDATE
| RDW_INVALIDATE
)) ==
507 (RDW_VALIDATE
| RDW_INVALIDATE
))
514 * Transform the parameters UpdateRgn and UpdateRect into
515 * a region hRgn specified in screen coordinates.
518 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
))
520 if (UpdateRgn
!= NULL
)
522 hRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
523 if (NtGdiCombineRgn(hRgn
, UpdateRgn
, NULL
, RGN_COPY
) == NULLREGION
)
524 NtGdiDeleteObject(hRgn
);
526 NtGdiOffsetRgn(hRgn
, Window
->ClientRect
.left
, Window
->ClientRect
.top
);
528 else if (UpdateRect
!= NULL
)
530 if (!IntGdiIsEmptyRect(UpdateRect
))
532 hRgn
= UnsafeIntCreateRectRgnIndirect((RECT
*)UpdateRect
);
533 NtGdiOffsetRgn(hRgn
, Window
->ClientRect
.left
, Window
->ClientRect
.top
);
536 else if ((Flags
& (RDW_INVALIDATE
| RDW_FRAME
)) == (RDW_INVALIDATE
| RDW_FRAME
) ||
537 (Flags
& (RDW_VALIDATE
| RDW_NOFRAME
)) == (RDW_VALIDATE
| RDW_NOFRAME
))
539 if (!IntGdiIsEmptyRect(&Window
->WindowRect
))
540 hRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
544 if (!IntGdiIsEmptyRect(&Window
->ClientRect
))
545 hRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->ClientRect
);
551 * Adjust the window update region depending on hRgn and flags.
554 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
| RDW_INTERNALPAINT
| RDW_NOINTERNALPAINT
) &&
557 IntInvalidateWindows(Window
, hRgn
, Flags
);
562 * Repaint and erase windows if needed.
565 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
567 co_IntPaintWindows(Window
, Flags
);
577 NtGdiDeleteObject(hRgn
);
584 IntIsWindowDirty(PWINDOW_OBJECT Window
)
586 return (Window
->Style
& WS_VISIBLE
) &&
587 ((Window
->UpdateRegion
!= NULL
) ||
588 (Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
) ||
589 (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
));
593 IntFindWindowToRepaint(PWINDOW_OBJECT Window
, PW32THREAD Thread
)
596 PWINDOW_OBJECT TempWindow
;
598 for (; Window
!= NULL
; Window
= Window
->NextSibling
)
600 if (IntWndBelongsToThread(Window
, Thread
) &&
601 IntIsWindowDirty(Window
))
603 /* Make sure all non-transparent siblings are already drawn. */
604 if (Window
->ExStyle
& WS_EX_TRANSPARENT
)
606 for (TempWindow
= Window
->NextSibling
; TempWindow
!= NULL
;
607 TempWindow
= TempWindow
->NextSibling
)
609 if (!(TempWindow
->ExStyle
& WS_EX_TRANSPARENT
) &&
610 IntWndBelongsToThread(TempWindow
, Thread
) &&
611 IntIsWindowDirty(TempWindow
))
613 return TempWindow
->hSelf
;
618 return Window
->hSelf
;
621 if (Window
->FirstChild
)
623 hChild
= IntFindWindowToRepaint(Window
->FirstChild
, Thread
);
633 IntGetPaintMessage(HWND hWnd
, UINT MsgFilterMin
, UINT MsgFilterMax
,
634 PW32THREAD Thread
, MSG
*Message
, BOOL Remove
)
636 PUSER_MESSAGE_QUEUE MessageQueue
= (PUSER_MESSAGE_QUEUE
)Thread
->MessageQueue
;
638 if (!MessageQueue
->PaintCount
)
641 if ((MsgFilterMin
!= 0 || MsgFilterMax
!= 0) &&
642 (MsgFilterMin
> WM_PAINT
|| MsgFilterMax
< WM_PAINT
))
645 Message
->hwnd
= IntFindWindowToRepaint(UserGetDesktopWindow(), PsGetWin32Thread());
647 if (Message
->hwnd
== NULL
)
649 DPRINT1("PAINTING BUG: Thread marked as containing dirty windows, but no dirty windows found!\n");
653 if (hWnd
!= NULL
&& Message
->hwnd
!= hWnd
)
656 Message
->message
= WM_PAINT
;
657 Message
->wParam
= Message
->lParam
= 0;
664 co_IntFixCaret(PWINDOW_OBJECT Window
, LPRECT lprc
, UINT flags
)
666 PDESKTOP_OBJECT Desktop
;
667 PTHRDCARETINFO CaretInfo
;
669 PWINDOW_OBJECT WndCaret
;
671 ASSERT_REFS_CO(Window
);
673 Desktop
= PsGetCurrentThread()->Tcb
.Win32Thread
->Desktop
;
674 CaretInfo
= ((PUSER_MESSAGE_QUEUE
)Desktop
->ActiveMessageQueue
)->CaretInfo
;
675 hWndCaret
= CaretInfo
->hWnd
;
677 WndCaret
= UserGetWindowObject(hWndCaret
);
679 //fix: check for WndCaret can be null
680 if (WndCaret
== Window
||
681 ((flags
& SW_SCROLLCHILDREN
) && IntIsChildWindow(Window
, WndCaret
)))
683 POINT pt
, FromOffset
, ToOffset
, Offset
;
686 pt
.x
= CaretInfo
->Pos
.x
;
687 pt
.y
= CaretInfo
->Pos
.y
;
688 IntGetClientOrigin(WndCaret
, &FromOffset
);
689 IntGetClientOrigin(Window
, &ToOffset
);
690 Offset
.x
= FromOffset
.x
- ToOffset
.x
;
691 Offset
.y
= FromOffset
.y
- ToOffset
.y
;
694 rcCaret
.right
= pt
.x
+ CaretInfo
->Size
.cx
;
695 rcCaret
.bottom
= pt
.y
+ CaretInfo
->Size
.cy
;
696 if (IntGdiIntersectRect(lprc
, lprc
, &rcCaret
))
708 /* PUBLIC FUNCTIONS ***********************************************************/
718 NtUserBeginPaint(HWND hWnd
, PAINTSTRUCT
* UnsafePs
)
720 PWINDOW_OBJECT Window
= NULL
;
726 DPRINT("Enter NtUserBeginPaint\n");
727 UserEnterExclusive();
729 if (!(Window
= UserGetWindowObject(hWnd
)))
734 UserRefObjectCo(Window
);
736 co_UserHideCaret(Window
);
738 if (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
)
742 hRgn
= IntGetNCUpdateRgn(Window
, FALSE
);
743 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
744 MsqDecPaintCountQueue(Window
->MessageQueue
);
745 co_IntSendMessage(hWnd
, WM_NCPAINT
, (WPARAM
)hRgn
, 0);
746 if (hRgn
!= (HANDLE
)1 && hRgn
!= NULL
)
748 /* NOTE: The region can already by deleted! */
749 GDIOBJ_FreeObj(hRgn
, GDI_OBJECT_TYPE_REGION
| GDI_OBJECT_TYPE_SILENT
);
753 RtlZeroMemory(&Ps
, sizeof(PAINTSTRUCT
));
755 Ps
.hdc
= UserGetDCEx(Window
, Window
->UpdateRegion
, DCX_INTERSECTRGN
| DCX_USESTYLE
);
761 if (Window
->UpdateRegion
!= NULL
)
763 MsqDecPaintCountQueue(Window
->MessageQueue
);
764 Rgn
= RGNDATA_LockRgn(Window
->UpdateRegion
);
767 UnsafeIntGetRgnBox(Rgn
, &Ps
.rcPaint
);
768 RGNDATA_UnlockRgn(Rgn
);
769 IntGdiIntersectRect(&Ps
.rcPaint
, &Ps
.rcPaint
, &Window
->ClientRect
);
770 IntGdiOffsetRect(&Ps
.rcPaint
,
771 -Window
->ClientRect
.left
,
772 -Window
->ClientRect
.top
);
776 IntGetClientRect(Window
, &Ps
.rcPaint
);
778 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
779 Window
->UpdateRegion
= NULL
;
783 if (Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
784 MsqDecPaintCountQueue(Window
->MessageQueue
);
786 IntGetClientRect(Window
, &Ps
.rcPaint
);
789 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
791 if (Window
->Flags
& WINDOWOBJECT_NEED_ERASEBKGND
)
793 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
794 Ps
.fErase
= !co_IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)Ps
.hdc
, 0);
801 Status
= MmCopyToCaller(UnsafePs
, &Ps
, sizeof(PAINTSTRUCT
));
802 if (! NT_SUCCESS(Status
))
804 SetLastNtError(Status
);
811 if (Window
) UserDerefObjectCo(Window
);
813 DPRINT("Leave NtUserBeginPaint, ret=%i\n",_ret_
);
827 NtUserEndPaint(HWND hWnd
, CONST PAINTSTRUCT
* lPs
)
829 PWINDOW_OBJECT Window
;
830 DECLARE_RETURN(BOOL
);
832 DPRINT("Enter NtUserEndPaint\n");
833 UserEnterExclusive();
835 if (!(Window
= UserGetWindowObject(hWnd
)))
840 UserReleaseDC(Window
, lPs
->hdc
, TRUE
);
842 UserRefObjectCo(Window
);
843 co_UserShowCaret(Window
);
844 UserDerefObjectCo(Window
);
849 DPRINT("Leave NtUserEndPaint, ret=%i\n",_ret_
);
856 co_UserGetUpdateRgn(PWINDOW_OBJECT Window
, HRGN hRgn
, BOOL bErase
)
861 ASSERT_REFS_CO(Window
);
863 if (Window
->UpdateRegion
== NULL
)
865 RegionType
= (NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0) ? NULLREGION
: ERROR
);
869 Rect
= Window
->ClientRect
;
870 IntIntersectWithParents(Window
, &Rect
);
871 NtGdiSetRectRgn(hRgn
, Rect
.left
, Rect
.top
, Rect
.right
, Rect
.bottom
);
872 RegionType
= NtGdiCombineRgn(hRgn
, hRgn
, Window
->UpdateRegion
, RGN_AND
);
873 NtGdiOffsetRgn(hRgn
, -Window
->ClientRect
.left
, -Window
->ClientRect
.top
);
876 if (bErase
&& RegionType
!= NULLREGION
&& RegionType
!= ERROR
)
878 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
892 NtUserGetUpdateRgn(HWND hWnd
, HRGN hRgn
, BOOL bErase
)
895 PWINDOW_OBJECT Window
;
898 DPRINT("Enter NtUserGetUpdateRgn\n");
899 UserEnterExclusive();
901 if (!(Window
= UserGetWindowObject(hWnd
)))
906 UserRefObjectCo(Window
);
907 ret
= co_UserGetUpdateRgn(Window
, hRgn
, bErase
);
908 UserDerefObjectCo(Window
);
913 DPRINT("Leave NtUserGetUpdateRgn, ret=%i\n",_ret_
);
919 * NtUserGetUpdateRect
926 NtUserGetUpdateRect(HWND hWnd
, LPRECT UnsafeRect
, BOOL bErase
)
928 PWINDOW_OBJECT Window
;
933 DECLARE_RETURN(BOOL
);
935 DPRINT("Enter NtUserGetUpdateRect\n");
936 UserEnterExclusive();
938 if (!(Window
= UserGetWindowObject(hWnd
)))
943 if (Window
->UpdateRegion
== NULL
)
945 Rect
.left
= Rect
.top
= Rect
.right
= Rect
.bottom
= 0;
949 /* Get the update region bounding box. */
950 if (Window
->UpdateRegion
== (HRGN
)1)
952 Rect
= Window
->ClientRect
;
956 RgnData
= RGNDATA_LockRgn(Window
->UpdateRegion
);
957 ASSERT(RgnData
!= NULL
);
958 RegionType
= UnsafeIntGetRgnBox(RgnData
, &Rect
);
959 RGNDATA_UnlockRgn(RgnData
);
961 if (RegionType
!= ERROR
&& RegionType
!= NULLREGION
)
962 IntGdiIntersectRect(&Rect
, &Rect
, &Window
->ClientRect
);
965 if (IntIntersectWithParents(Window
, &Rect
))
967 IntGdiOffsetRect(&Rect
,
968 -Window
->ClientRect
.left
,
969 -Window
->ClientRect
.top
);
972 Rect
.left
= Rect
.top
= Rect
.right
= Rect
.bottom
= 0;
976 if (bErase
&& !IntGdiIsEmptyRect(&Rect
))
978 UserRefObjectCo(Window
);
979 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
980 UserDerefObjectCo(Window
);
983 if (UnsafeRect
!= NULL
)
985 Status
= MmCopyToCaller(UnsafeRect
, &Rect
, sizeof(RECT
));
986 if (!NT_SUCCESS(Status
))
988 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
993 RETURN(Window
->UpdateRegion
!= NULL
);
996 DPRINT("Leave NtUserGetUpdateRect, ret=%i\n",_ret_
);
1002 * NtUserRedrawWindow
1009 NtUserRedrawWindow(HWND hWnd
, CONST RECT
*lprcUpdate
, HRGN hrgnUpdate
,
1012 RECT SafeUpdateRect
;
1015 DECLARE_RETURN(BOOL
);
1017 DPRINT("Enter NtUserRedrawWindow\n");
1018 UserEnterExclusive();
1020 if (!(Wnd
= UserGetWindowObject(hWnd
? hWnd
: IntGetDesktopWindow())))
1025 if (lprcUpdate
!= NULL
)
1027 Status
= MmCopyFromCaller(&SafeUpdateRect
, (PRECT
)lprcUpdate
,
1030 if (!NT_SUCCESS(Status
))
1032 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1037 UserRefObjectCo(Wnd
);
1039 Status
= co_UserRedrawWindow(Wnd
, NULL
== lprcUpdate
? NULL
: &SafeUpdateRect
,
1042 UserDerefObjectCo(Wnd
);
1044 if (!NT_SUCCESS(Status
))
1046 /* IntRedrawWindow fails only in case that flags are invalid */
1047 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1054 DPRINT("Leave NtUserRedrawWindow, ret=%i\n",_ret_
);
1063 UserScrollDC(HDC hDC
, INT dx
, INT dy
, const RECT
*lprcScroll
,
1064 const RECT
*lprcClip
, HRGN hrgnUpdate
, LPRECT lprcUpdate
)
1066 RECT rSrc
, rClipped_src
, rClip
, rDst
, offset
;
1070 * Compute device clipping region (in device coordinates).
1073 DC
= DC_LockDc(hDC
);
1081 IntGdiGetClipBox(hDC
, &rSrc
);
1082 IntLPtoDP(DC
, (LPPOINT
)&rSrc
, 2);
1087 IntGdiGetClipBox(hDC
, &rClip
);
1088 IntLPtoDP(DC
, (LPPOINT
)&rClip
, 2);
1090 IntGdiIntersectRect(&rClipped_src
, &rSrc
, &rClip
);
1092 rDst
= rClipped_src
;
1093 IntGdiSetRect(&offset
, 0, 0, dx
, dy
);
1094 IntLPtoDP(DC
, (LPPOINT
)&offset
, 2);
1095 IntGdiOffsetRect(&rDst
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
1096 IntGdiIntersectRect(&rDst
, &rDst
, &rClip
);
1099 * Copy bits, if possible.
1102 if (rDst
.bottom
> rDst
.top
&& rDst
.right
> rDst
.left
)
1104 RECT rDst_lp
= rDst
, rSrc_lp
= rDst
;
1106 IntGdiOffsetRect(&rSrc_lp
, offset
.left
- offset
.right
, offset
.top
- offset
.bottom
);
1107 IntDPtoLP(DC
, (LPPOINT
)&rDst_lp
, 2);
1108 IntDPtoLP(DC
, (LPPOINT
)&rSrc_lp
, 2);
1111 if (!NtGdiBitBlt(hDC
, rDst_lp
.left
, rDst_lp
.top
, rDst_lp
.right
- rDst_lp
.left
,
1112 rDst_lp
.bottom
- rDst_lp
.top
, hDC
, rSrc_lp
.left
, rSrc_lp
.top
,
1122 * Compute update areas. This is the clipped source or'ed with the
1123 * unclipped source translated minus the clipped src translated (rDst)
1124 * all clipped to rClip.
1127 if (hrgnUpdate
|| lprcUpdate
)
1129 HRGN hRgn
= hrgnUpdate
, hRgn2
;
1132 NtGdiSetRectRgn(hRgn
, rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
1134 hRgn
= NtGdiCreateRectRgn(rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
1136 hRgn2
= UnsafeIntCreateRectRgnIndirect(&rSrc
);
1137 NtGdiOffsetRgn(hRgn2
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
1138 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_OR
);
1140 NtGdiSetRectRgn(hRgn2
, rDst
.left
, rDst
.top
, rDst
.right
, rDst
.bottom
);
1141 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_DIFF
);
1143 NtGdiSetRectRgn(hRgn2
, rClip
.left
, rClip
.top
, rClip
.right
, rClip
.bottom
);
1144 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_AND
);
1148 NtGdiGetRgnBox(hRgn
, lprcUpdate
);
1150 /* Put the lprcUpdate in logical coordinate */
1151 NtGdiDPtoLP(hDC
, (LPPOINT
)lprcUpdate
, 2);
1154 NtGdiDeleteObject(hRgn
);
1155 NtGdiDeleteObject(hRgn2
);
1171 NtUserScrollDC(HDC hDC
, INT dx
, INT dy
, const RECT
*lprcScroll
,
1172 const RECT
*lprcClip
, HRGN hrgnUpdate
, LPRECT lprcUpdate
)
1174 DECLARE_RETURN(DWORD
);
1176 DPRINT("Enter NtUserScrollDC\n");
1177 UserEnterExclusive();
1179 RETURN( UserScrollDC(hDC
, dx
, dy
, lprcScroll
, lprcClip
, hrgnUpdate
, lprcUpdate
));
1182 DPRINT("Leave NtUserScrollDC, ret=%i\n",_ret_
);
1189 * NtUserScrollWindowEx
1196 NtUserScrollWindowEx(HWND hWnd
, INT dx
, INT dy
, const RECT
*UnsafeRect
,
1197 const RECT
*UnsafeClipRect
, HRGN hrgnUpdate
, LPRECT rcUpdate
, UINT flags
)
1199 RECT rc
, cliprc
, caretrc
, rect
, clipRect
;
1201 PWINDOW_OBJECT Window
= NULL
, CaretWnd
;
1205 BOOL bUpdate
= (rcUpdate
|| hrgnUpdate
|| flags
& (SW_INVALIDATE
| SW_ERASE
));
1206 BOOL bOwnRgn
= TRUE
;
1208 DECLARE_RETURN(DWORD
);
1210 DPRINT("Enter NtUserScrollWindowEx\n");
1211 UserEnterExclusive();
1213 Window
= UserGetWindowObject(hWnd
);
1214 if (!Window
|| !IntIsWindowDrawable(Window
))
1216 Window
= NULL
; /* prevent deref at cleanup */
1219 UserRefObjectCo(Window
);
1221 IntGetClientRect(Window
, &rc
);
1223 if (NULL
!= UnsafeRect
)
1225 Status
= MmCopyFromCaller(&rect
, UnsafeRect
, sizeof(RECT
));
1226 if (! NT_SUCCESS(Status
))
1228 SetLastNtError(Status
);
1231 IntGdiIntersectRect(&rc
, &rc
, &rect
);
1234 if (NULL
!= UnsafeClipRect
)
1236 Status
= MmCopyFromCaller(&clipRect
, UnsafeClipRect
, sizeof(RECT
));
1237 if (! NT_SUCCESS(Status
))
1239 SetLastNtError(Status
);
1242 IntGdiIntersectRect(&cliprc
, &rc
, &clipRect
);
1247 if (cliprc
.right
<= cliprc
.left
|| cliprc
.bottom
<= cliprc
.top
||
1248 (dx
== 0 && dy
== 0))
1250 RETURN( NULLREGION
);
1254 hwndCaret
= co_IntFixCaret(Window
, &caretrc
, flags
);
1259 hrgnUpdate
= NtGdiCreateRectRgn(0, 0, 0, 0);
1261 hDC
= UserGetDCEx(Window
, 0, DCX_CACHE
| DCX_USESTYLE
);
1264 UserScrollDC(hDC
, dx
, dy
, &rc
, &cliprc
, hrgnUpdate
, rcUpdate
);
1265 UserReleaseDC(Window
, hDC
, FALSE
);
1269 * Take into account the fact that some damage may have occurred during
1273 hrgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
1274 Result
= co_UserGetUpdateRgn(Window
, hrgnTemp
, FALSE
);
1275 if (Result
!= NULLREGION
)
1277 HRGN hrgnClip
= UnsafeIntCreateRectRgnIndirect(&cliprc
);
1278 NtGdiOffsetRgn(hrgnTemp
, dx
, dy
);
1279 NtGdiCombineRgn(hrgnTemp
, hrgnTemp
, hrgnClip
, RGN_AND
);
1280 co_UserRedrawWindow(Window
, NULL
, hrgnTemp
, RDW_INVALIDATE
| RDW_ERASE
);
1281 NtGdiDeleteObject(hrgnClip
);
1284 NtGdiDeleteObject(hrgnTemp
);
1286 if (flags
& SW_SCROLLCHILDREN
)
1288 HWND
*List
= IntWinListChildren(Window
);
1296 IntGetClientOrigin(Window
, &ClientOrigin
);
1297 for (i
= 0; List
[i
]; i
++)
1299 if (!(Wnd
= UserGetWindowObject(List
[i
])))
1302 r
= Wnd
->WindowRect
;
1303 r
.left
-= ClientOrigin
.x
;
1304 r
.top
-= ClientOrigin
.y
;
1305 r
.right
-= ClientOrigin
.x
;
1306 r
.bottom
-= ClientOrigin
.y
;
1308 if (! UnsafeRect
|| IntGdiIntersectRect(&dummy
, &r
, &rc
))
1310 UserRefObjectCo(Wnd
);
1311 co_WinPosSetWindowPos(Wnd
, 0, r
.left
+ dx
, r
.top
+ dy
, 0, 0,
1312 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
|
1314 UserDerefObjectCo(Wnd
);
1322 if (flags
& (SW_INVALIDATE
| SW_ERASE
))
1323 co_UserRedrawWindow(Window
, NULL
, hrgnUpdate
, RDW_INVALIDATE
| RDW_ERASE
|
1324 ((flags
& SW_ERASE
) ? RDW_ERASENOW
: 0) |
1325 ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0));
1327 if (bOwnRgn
&& hrgnUpdate
)
1328 NtGdiDeleteObject(hrgnUpdate
);
1330 if ((CaretWnd
= UserGetWindowObject(hwndCaret
)))
1332 UserRefObjectCo(CaretWnd
);
1334 co_IntSetCaretPos(caretrc
.left
+ dx
, caretrc
.top
+ dy
);
1335 co_UserShowCaret(CaretWnd
);
1337 UserDerefObjectCo(CaretWnd
);
1344 UserDerefObjectCo(Window
);
1346 DPRINT("Leave NtUserScrollWindowEx, ret=%i\n",_ret_
);