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
= IntGetWindowObject(*phWnd
);
296 if (Window
&& (Window
->Style
& WS_VISIBLE
))
298 co_IntPaintWindows(Window
, Flags
);
299 ObmDereferenceObject(Window
);
308 * IntInvalidateWindows
310 * Internal function used by IntRedrawWindow.
314 IntInvalidateWindows(PWINDOW_OBJECT Window
, HRGN hRgn
, ULONG Flags
)
317 BOOL HadPaintMessage
, HadNCPaintMessage
;
318 BOOL HasPaintMessage
, HasNCPaintMessage
;
321 * Clip the given region with window rectangle (or region)
324 if (!Window
->WindowRegion
|| (Window
->Style
& WS_MINIMIZE
))
328 hRgnWindow
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
329 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, hRgnWindow
, RGN_AND
);
330 NtGdiDeleteObject(hRgnWindow
);
335 -Window
->WindowRect
.left
,
336 -Window
->WindowRect
.top
);
337 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, Window
->WindowRegion
, RGN_AND
);
339 Window
->WindowRect
.left
,
340 Window
->WindowRect
.top
);
344 * Save current state of pending updates
347 HadPaintMessage
= Window
->UpdateRegion
!= NULL
||
348 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
;
349 HadNCPaintMessage
= Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
;
352 * Update the region and flags
355 if (Flags
& RDW_INVALIDATE
&& RgnType
!= NULLREGION
)
357 if (Window
->UpdateRegion
== NULL
)
359 Window
->UpdateRegion
= NtGdiCreateRectRgn(0, 0, 0, 0);
360 GDIOBJ_SetOwnership(Window
->UpdateRegion
, NULL
);
363 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
364 hRgn
, RGN_OR
) == NULLREGION
)
366 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
367 NtGdiDeleteObject(Window
->UpdateRegion
);
368 Window
->UpdateRegion
= NULL
;
371 if (Flags
& RDW_FRAME
)
372 Window
->Flags
|= WINDOWOBJECT_NEED_NCPAINT
;
373 if (Flags
& RDW_ERASE
)
374 Window
->Flags
|= WINDOWOBJECT_NEED_ERASEBKGND
;
379 if (Flags
& RDW_VALIDATE
&& RgnType
!= NULLREGION
)
381 if (Window
->UpdateRegion
!= NULL
)
383 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
384 hRgn
, RGN_DIFF
) == NULLREGION
)
386 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
387 NtGdiDeleteObject(Window
->UpdateRegion
);
388 Window
->UpdateRegion
= NULL
;
392 if (Window
->UpdateRegion
== NULL
)
393 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
394 if (Flags
& RDW_NOFRAME
)
395 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
396 if (Flags
& RDW_NOERASE
)
397 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
400 if (Flags
& RDW_INTERNALPAINT
)
402 Window
->Flags
|= WINDOWOBJECT_NEED_INTERNALPAINT
;
405 if (Flags
& RDW_NOINTERNALPAINT
)
407 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
411 * Process children if needed
414 if (!(Flags
& RDW_NOCHILDREN
) && !(Window
->Style
& WS_MINIMIZE
) &&
415 ((Flags
& RDW_ALLCHILDREN
) || !(Window
->Style
& WS_CLIPCHILDREN
)))
418 PWINDOW_OBJECT Child
;
420 if ((List
= IntWinListChildren(Window
)))
422 for (phWnd
= List
; *phWnd
; ++phWnd
)
424 if(!(Child
= UserGetWindowObject(*phWnd
)))
429 if (Child
->Style
& WS_VISIBLE
)
432 * Recursive call to update children UpdateRegion
434 HRGN hRgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
435 NtGdiCombineRgn(hRgnTemp
, hRgn
, 0, RGN_COPY
);
436 IntInvalidateWindows(Child
, hRgnTemp
, Flags
);
437 NtGdiDeleteObject(hRgnTemp
);
446 * Fake post paint messages to window message queue if needed
449 HasPaintMessage
= Window
->UpdateRegion
!= NULL
||
450 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
;
451 HasNCPaintMessage
= Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
;
453 if (HasPaintMessage
!= HadPaintMessage
)
456 MsqDecPaintCountQueue(Window
->MessageQueue
);
458 MsqIncPaintCountQueue(Window
->MessageQueue
);
461 if (HasNCPaintMessage
!= HadNCPaintMessage
)
463 if (HadNCPaintMessage
)
464 MsqDecPaintCountQueue(Window
->MessageQueue
);
466 MsqIncPaintCountQueue(Window
->MessageQueue
);
472 * IntIsWindowDrawable
475 * Window is drawable when it is visible and all parents are not
480 IntIsWindowDrawable(PWINDOW_OBJECT Window
)
484 for (Wnd
= Window
; Wnd
!= NULL
; Wnd
= Wnd
->Parent
)
486 if (!(Wnd
->Style
& WS_VISIBLE
) ||
487 ((Wnd
->Style
& WS_MINIMIZE
) && (Wnd
!= Window
)))
499 * Internal version of NtUserRedrawWindow that takes WINDOW_OBJECT as
504 co_UserRedrawWindow(PWINDOW_OBJECT Window
, const RECT
* UpdateRect
, HRGN UpdateRgn
,
511 * Validation of passed parameters.
514 if (!IntIsWindowDrawable(Window
) ||
515 (Flags
& (RDW_VALIDATE
| RDW_INVALIDATE
)) ==
516 (RDW_VALIDATE
| RDW_INVALIDATE
))
523 * Transform the parameters UpdateRgn and UpdateRect into
524 * a region hRgn specified in screen coordinates.
527 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
))
529 if (UpdateRgn
!= NULL
)
531 hRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
532 if (NtGdiCombineRgn(hRgn
, UpdateRgn
, NULL
, RGN_COPY
) == NULLREGION
)
533 NtGdiDeleteObject(hRgn
);
535 NtGdiOffsetRgn(hRgn
, Window
->ClientRect
.left
, Window
->ClientRect
.top
);
537 else if (UpdateRect
!= NULL
)
539 if (!IntGdiIsEmptyRect(UpdateRect
))
541 hRgn
= UnsafeIntCreateRectRgnIndirect((RECT
*)UpdateRect
);
542 NtGdiOffsetRgn(hRgn
, Window
->ClientRect
.left
, Window
->ClientRect
.top
);
545 else if ((Flags
& (RDW_INVALIDATE
| RDW_FRAME
)) == (RDW_INVALIDATE
| RDW_FRAME
) ||
546 (Flags
& (RDW_VALIDATE
| RDW_NOFRAME
)) == (RDW_VALIDATE
| RDW_NOFRAME
))
548 if (!IntGdiIsEmptyRect(&Window
->WindowRect
))
549 hRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
553 if (!IntGdiIsEmptyRect(&Window
->ClientRect
))
554 hRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->ClientRect
);
560 * Adjust the window update region depending on hRgn and flags.
563 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
| RDW_INTERNALPAINT
| RDW_NOINTERNALPAINT
) &&
566 IntInvalidateWindows(Window
, hRgn
, Flags
);
571 * Repaint and erase windows if needed.
574 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
576 co_IntPaintWindows(Window
, Flags
);
586 NtGdiDeleteObject(hRgn
);
593 IntIsWindowDirty(PWINDOW_OBJECT Window
)
595 return (Window
->Style
& WS_VISIBLE
) &&
596 ((Window
->UpdateRegion
!= NULL
) ||
597 (Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
) ||
598 (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
));
602 IntFindWindowToRepaint(PWINDOW_OBJECT Window
, PW32THREAD Thread
)
605 PWINDOW_OBJECT TempWindow
;
607 for (; Window
!= NULL
; Window
= Window
->NextSibling
)
609 if (IntWndBelongsToThread(Window
, Thread
) &&
610 IntIsWindowDirty(Window
))
612 /* Make sure all non-transparent siblings are already drawn. */
613 if (Window
->ExStyle
& WS_EX_TRANSPARENT
)
615 for (TempWindow
= Window
->NextSibling
; TempWindow
!= NULL
;
616 TempWindow
= TempWindow
->NextSibling
)
618 if (!(TempWindow
->ExStyle
& WS_EX_TRANSPARENT
) &&
619 IntWndBelongsToThread(TempWindow
, Thread
) &&
620 IntIsWindowDirty(TempWindow
))
622 return TempWindow
->hSelf
;
627 return Window
->hSelf
;
630 if (Window
->FirstChild
)
632 hChild
= IntFindWindowToRepaint(Window
->FirstChild
, Thread
);
642 IntGetPaintMessage(HWND hWnd
, UINT MsgFilterMin
, UINT MsgFilterMax
,
643 PW32THREAD Thread
, MSG
*Message
, BOOL Remove
)
645 PUSER_MESSAGE_QUEUE MessageQueue
= (PUSER_MESSAGE_QUEUE
)Thread
->MessageQueue
;
647 if (!MessageQueue
->PaintCount
)
650 if ((MsgFilterMin
!= 0 || MsgFilterMax
!= 0) &&
651 (MsgFilterMin
> WM_PAINT
|| MsgFilterMax
< WM_PAINT
))
654 Message
->hwnd
= IntFindWindowToRepaint(UserGetDesktopWindow(), PsGetWin32Thread());
656 if (Message
->hwnd
== NULL
)
658 DPRINT1("PAINTING BUG: Thread marked as containing dirty windows, but no dirty windows found!\n");
662 if (hWnd
!= NULL
&& Message
->hwnd
!= hWnd
)
665 Message
->message
= WM_PAINT
;
666 Message
->wParam
= Message
->lParam
= 0;
673 co_IntFixCaret(PWINDOW_OBJECT Window
, LPRECT lprc
, UINT flags
)
675 PDESKTOP_OBJECT Desktop
;
676 PTHRDCARETINFO CaretInfo
;
678 PWINDOW_OBJECT WndCaret
;
680 ASSERT_REFS_CO(Window
);
682 Desktop
= PsGetCurrentThread()->Tcb
.Win32Thread
->Desktop
;
683 CaretInfo
= ((PUSER_MESSAGE_QUEUE
)Desktop
->ActiveMessageQueue
)->CaretInfo
;
684 hWndCaret
= CaretInfo
->hWnd
;
686 WndCaret
= UserGetWindowObject(hWndCaret
);
688 //fix: check for WndCaret can be null
689 if (WndCaret
== Window
||
690 ((flags
& SW_SCROLLCHILDREN
) && IntIsChildWindow(Window
, WndCaret
)))
692 POINT pt
, FromOffset
, ToOffset
, Offset
;
695 pt
.x
= CaretInfo
->Pos
.x
;
696 pt
.y
= CaretInfo
->Pos
.y
;
697 IntGetClientOrigin(WndCaret
, &FromOffset
);
698 IntGetClientOrigin(Window
, &ToOffset
);
699 Offset
.x
= FromOffset
.x
- ToOffset
.x
;
700 Offset
.y
= FromOffset
.y
- ToOffset
.y
;
703 rcCaret
.right
= pt
.x
+ CaretInfo
->Size
.cx
;
704 rcCaret
.bottom
= pt
.y
+ CaretInfo
->Size
.cy
;
705 if (IntGdiIntersectRect(lprc
, lprc
, &rcCaret
))
717 /* PUBLIC FUNCTIONS ***********************************************************/
727 NtUserBeginPaint(HWND hWnd
, PAINTSTRUCT
* UnsafePs
)
729 PWINDOW_OBJECT Window
= NULL
;
735 DPRINT("Enter NtUserBeginPaint\n");
736 UserEnterExclusive();
738 if (!(Window
= UserGetWindowObject(hWnd
)))
743 UserRefObjectCo(Window
);
745 co_UserHideCaret(Window
);
747 if (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
)
751 hRgn
= IntGetNCUpdateRgn(Window
, FALSE
);
752 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
753 MsqDecPaintCountQueue(Window
->MessageQueue
);
754 co_IntSendMessage(hWnd
, WM_NCPAINT
, (WPARAM
)hRgn
, 0);
755 if (hRgn
!= (HANDLE
)1 && hRgn
!= NULL
)
757 /* NOTE: The region can already by deleted! */
758 GDIOBJ_FreeObj(hRgn
, GDI_OBJECT_TYPE_REGION
| GDI_OBJECT_TYPE_SILENT
);
762 RtlZeroMemory(&Ps
, sizeof(PAINTSTRUCT
));
764 Ps
.hdc
= UserGetDCEx(Window
, Window
->UpdateRegion
, DCX_INTERSECTRGN
| DCX_USESTYLE
);
770 if (Window
->UpdateRegion
!= NULL
)
772 MsqDecPaintCountQueue(Window
->MessageQueue
);
773 Rgn
= RGNDATA_LockRgn(Window
->UpdateRegion
);
776 UnsafeIntGetRgnBox(Rgn
, &Ps
.rcPaint
);
777 RGNDATA_UnlockRgn(Rgn
);
778 IntGdiOffsetRect(&Ps
.rcPaint
,
779 -Window
->ClientRect
.left
,
780 -Window
->ClientRect
.top
);
784 IntGetClientRect(Window
, &Ps
.rcPaint
);
786 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
787 Window
->UpdateRegion
= NULL
;
791 if (Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
792 MsqDecPaintCountQueue(Window
->MessageQueue
);
794 IntGetClientRect(Window
, &Ps
.rcPaint
);
797 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
799 if (Window
->Flags
& WINDOWOBJECT_NEED_ERASEBKGND
)
801 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
802 Ps
.fErase
= !co_IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)Ps
.hdc
, 0);
809 Status
= MmCopyToCaller(UnsafePs
, &Ps
, sizeof(PAINTSTRUCT
));
810 if (! NT_SUCCESS(Status
))
812 SetLastNtError(Status
);
819 if (Window
) UserDerefObjectCo(Window
);
821 DPRINT("Leave NtUserBeginPaint, ret=%i\n",_ret_
);
835 NtUserEndPaint(HWND hWnd
, CONST PAINTSTRUCT
* lPs
)
837 PWINDOW_OBJECT Window
;
838 DECLARE_RETURN(BOOL
);
840 DPRINT("Enter NtUserEndPaint\n");
841 UserEnterExclusive();
843 if (!(Window
= UserGetWindowObject(hWnd
)))
848 UserReleaseDC(Window
, lPs
->hdc
, TRUE
);
850 UserRefObjectCo(Window
);
851 co_UserShowCaret(Window
);
852 UserDerefObjectCo(Window
);
857 DPRINT("Leave NtUserEndPaint, ret=%i\n",_ret_
);
863 * NtUserInvalidateRect
870 NtUserInvalidateRect(HWND hWnd
, CONST RECT
*Rect
, BOOL Erase
)
872 return NtUserRedrawWindow(hWnd
, Rect
, 0, RDW_INVALIDATE
| (Erase
? RDW_ERASE
: 0));
876 * NtUserInvalidateRgn
883 NtUserInvalidateRgn(HWND hWnd
, HRGN Rgn
, BOOL Erase
)
885 return NtUserRedrawWindow(hWnd
, NULL
, Rgn
, RDW_INVALIDATE
| (Erase
? RDW_ERASE
: 0));
891 co_UserValidateRgn(PWINDOW_OBJECT Window
, HRGN hRgn
)
893 return co_UserRedrawWindow(Window
, NULL
, hRgn
, RDW_VALIDATE
| RDW_NOCHILDREN
);
904 NtUserValidateRgn(HWND hWnd
, HRGN hRgn
)
906 return NtUserRedrawWindow(hWnd
, NULL
, hRgn
, RDW_VALIDATE
| RDW_NOCHILDREN
);
917 NtUserUpdateWindow(HWND hWnd
)
919 return NtUserRedrawWindow(hWnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
927 co_UserGetUpdateRgn(PWINDOW_OBJECT Window
, HRGN hRgn
, BOOL bErase
)
931 ASSERT_REFS_CO(Window
);
933 if (Window
->UpdateRegion
== NULL
)
935 RegionType
= (NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0) ? NULLREGION
: ERROR
);
939 RegionType
= NtGdiCombineRgn(hRgn
, Window
->UpdateRegion
, hRgn
, RGN_COPY
);
940 NtGdiOffsetRgn(hRgn
, -Window
->ClientRect
.left
, -Window
->ClientRect
.top
);
943 if (bErase
&& RegionType
!= NULLREGION
&& RegionType
!= ERROR
)
945 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
958 NtUserGetUpdateRgn(HWND hWnd
, HRGN hRgn
, BOOL bErase
)
961 PWINDOW_OBJECT Window
;
964 DPRINT("Enter NtUserGetUpdateRgn\n");
965 UserEnterExclusive();
967 if (!(Window
= UserGetWindowObject(hWnd
)))
972 UserRefObjectCo(Window
);
973 ret
= co_UserGetUpdateRgn(Window
, hRgn
, bErase
);
974 UserDerefObjectCo(Window
);
979 DPRINT("Leave NtUserGetUpdateRgn, ret=%i\n",_ret_
);
985 * NtUserGetUpdateRect
992 NtUserGetUpdateRect(HWND hWnd
, LPRECT UnsafeRect
, BOOL bErase
)
994 PWINDOW_OBJECT Window
;
1000 DECLARE_RETURN(BOOL
);
1002 DPRINT("Enter NtUserGetUpdateRect\n");
1003 UserEnterExclusive();
1005 if (!(Window
= UserGetWindowObject(hWnd
)))
1010 if (Window
->UpdateRegion
== NULL
)
1012 Rect
.left
= Rect
.top
= Rect
.right
= Rect
.bottom
= 0;
1016 RgnData
= RGNDATA_LockRgn(Window
->UpdateRegion
);
1017 ASSERT(RgnData
!= NULL
);
1018 RegionType
= UnsafeIntGetRgnBox(RgnData
, &Rect
);
1019 ASSERT(RegionType
!= ERROR
);
1020 RGNDATA_UnlockRgn(RgnData
);
1022 AlwaysPaint
= (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
) ||
1023 (Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
);
1025 if (bErase
&& Rect
.left
< Rect
.right
&& Rect
.top
< Rect
.bottom
)
1027 UserRefObjectCo(Window
);
1028 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
1029 UserDerefObjectCo(Window
);
1032 if (UnsafeRect
!= NULL
)
1034 Status
= MmCopyToCaller(UnsafeRect
, &Rect
, sizeof(RECT
));
1035 if (!NT_SUCCESS(Status
))
1037 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1042 RETURN( (Rect
.left
< Rect
.right
&& Rect
.top
< Rect
.bottom
) || AlwaysPaint
);
1045 DPRINT("Leave NtUserGetUpdateRect, ret=%i\n",_ret_
);
1051 * NtUserRedrawWindow
1058 NtUserRedrawWindow(HWND hWnd
, CONST RECT
*lprcUpdate
, HRGN hrgnUpdate
,
1061 RECT SafeUpdateRect
;
1064 DECLARE_RETURN(BOOL
);
1066 DPRINT("Enter NtUserRedrawWindow\n");
1067 UserEnterExclusive();
1069 if (!(Wnd
= UserGetWindowObject(hWnd
? hWnd
: IntGetDesktopWindow())))
1074 if (lprcUpdate
!= NULL
)
1076 Status
= MmCopyFromCaller(&SafeUpdateRect
, (PRECT
)lprcUpdate
,
1079 if (!NT_SUCCESS(Status
))
1081 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1086 UserRefObjectCo(Wnd
);
1088 Status
= co_UserRedrawWindow(Wnd
, NULL
== lprcUpdate
? NULL
: &SafeUpdateRect
,
1091 UserDerefObjectCo(Wnd
);
1093 if (!NT_SUCCESS(Status
))
1095 /* IntRedrawWindow fails only in case that flags are invalid */
1096 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1103 DPRINT("Leave NtUserRedrawWindow, ret=%i\n",_ret_
);
1112 UserScrollDC(HDC hDC
, INT dx
, INT dy
, const RECT
*lprcScroll
,
1113 const RECT
*lprcClip
, HRGN hrgnUpdate
, LPRECT lprcUpdate
)
1115 RECT rSrc
, rClipped_src
, rClip
, rDst
, offset
;
1119 * Compute device clipping region (in device coordinates).
1122 DC
= DC_LockDc(hDC
);
1130 IntGdiGetClipBox(hDC
, &rSrc
);
1131 IntLPtoDP(DC
, (LPPOINT
)&rSrc
, 2);
1136 IntGdiGetClipBox(hDC
, &rClip
);
1137 IntLPtoDP(DC
, (LPPOINT
)&rClip
, 2);
1139 IntGdiIntersectRect(&rClipped_src
, &rSrc
, &rClip
);
1141 rDst
= rClipped_src
;
1142 IntGdiSetRect(&offset
, 0, 0, dx
, dy
);
1143 IntLPtoDP(DC
, (LPPOINT
)&offset
, 2);
1144 IntGdiOffsetRect(&rDst
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
1145 IntGdiIntersectRect(&rDst
, &rDst
, &rClip
);
1148 * Copy bits, if possible.
1151 if (rDst
.bottom
> rDst
.top
&& rDst
.right
> rDst
.left
)
1153 RECT rDst_lp
= rDst
, rSrc_lp
= rDst
;
1155 IntGdiOffsetRect(&rSrc_lp
, offset
.left
- offset
.right
, offset
.top
- offset
.bottom
);
1156 IntDPtoLP(DC
, (LPPOINT
)&rDst_lp
, 2);
1157 IntDPtoLP(DC
, (LPPOINT
)&rSrc_lp
, 2);
1160 if (!NtGdiBitBlt(hDC
, rDst_lp
.left
, rDst_lp
.top
, rDst_lp
.right
- rDst_lp
.left
,
1161 rDst_lp
.bottom
- rDst_lp
.top
, hDC
, rSrc_lp
.left
, rSrc_lp
.top
,
1171 * Compute update areas. This is the clipped source or'ed with the
1172 * unclipped source translated minus the clipped src translated (rDst)
1173 * all clipped to rClip.
1176 if (hrgnUpdate
|| lprcUpdate
)
1178 HRGN hRgn
= hrgnUpdate
, hRgn2
;
1181 NtGdiSetRectRgn(hRgn
, rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
1183 hRgn
= NtGdiCreateRectRgn(rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
1185 hRgn2
= UnsafeIntCreateRectRgnIndirect(&rSrc
);
1186 NtGdiOffsetRgn(hRgn2
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
1187 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_OR
);
1189 NtGdiSetRectRgn(hRgn2
, rDst
.left
, rDst
.top
, rDst
.right
, rDst
.bottom
);
1190 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_DIFF
);
1192 NtGdiSetRectRgn(hRgn2
, rClip
.left
, rClip
.top
, rClip
.right
, rClip
.bottom
);
1193 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_AND
);
1197 NtGdiGetRgnBox(hRgn
, lprcUpdate
);
1199 /* Put the lprcUpdate in logical coordinate */
1200 NtGdiDPtoLP(hDC
, (LPPOINT
)lprcUpdate
, 2);
1203 NtGdiDeleteObject(hRgn
);
1204 NtGdiDeleteObject(hRgn2
);
1220 NtUserScrollDC(HDC hDC
, INT dx
, INT dy
, const RECT
*lprcScroll
,
1221 const RECT
*lprcClip
, HRGN hrgnUpdate
, LPRECT lprcUpdate
)
1223 DECLARE_RETURN(DWORD
);
1225 DPRINT("Enter NtUserScrollDC\n");
1226 UserEnterExclusive();
1228 RETURN( UserScrollDC(hDC
, dx
, dy
, lprcScroll
, lprcClip
, hrgnUpdate
, lprcUpdate
));
1231 DPRINT("Leave NtUserScrollDC, ret=%i\n",_ret_
);
1238 * NtUserScrollWindowEx
1245 NtUserScrollWindowEx(HWND hWnd
, INT dx
, INT dy
, const RECT
*UnsafeRect
,
1246 const RECT
*UnsafeClipRect
, HRGN hrgnUpdate
, LPRECT rcUpdate
, UINT flags
)
1248 RECT rc
, cliprc
, caretrc
, rect
, clipRect
;
1250 PWINDOW_OBJECT Window
= NULL
, CaretWnd
;
1254 BOOL bUpdate
= (rcUpdate
|| hrgnUpdate
|| flags
& (SW_INVALIDATE
| SW_ERASE
));
1255 BOOL bOwnRgn
= TRUE
;
1257 DECLARE_RETURN(DWORD
);
1259 DPRINT("Enter NtUserScrollWindowEx\n");
1260 UserEnterExclusive();
1262 Window
= UserGetWindowObject(hWnd
);
1263 if (!Window
|| !IntIsWindowDrawable(Window
))
1265 Window
= NULL
; /* prevent deref at cleanup */
1268 UserRefObjectCo(Window
);
1270 IntGetClientRect(Window
, &rc
);
1272 if (NULL
!= UnsafeRect
)
1274 Status
= MmCopyFromCaller(&rect
, UnsafeRect
, sizeof(RECT
));
1275 if (! NT_SUCCESS(Status
))
1277 SetLastNtError(Status
);
1280 IntGdiIntersectRect(&rc
, &rc
, &rect
);
1283 if (NULL
!= UnsafeClipRect
)
1285 Status
= MmCopyFromCaller(&clipRect
, UnsafeClipRect
, sizeof(RECT
));
1286 if (! NT_SUCCESS(Status
))
1288 SetLastNtError(Status
);
1291 IntGdiIntersectRect(&cliprc
, &rc
, &clipRect
);
1296 if (cliprc
.right
<= cliprc
.left
|| cliprc
.bottom
<= cliprc
.top
||
1297 (dx
== 0 && dy
== 0))
1299 RETURN( NULLREGION
);
1303 hwndCaret
= co_IntFixCaret(Window
, &caretrc
, flags
);
1308 hrgnUpdate
= NtGdiCreateRectRgn(0, 0, 0, 0);
1310 hDC
= UserGetDCEx(Window
, 0, DCX_CACHE
| DCX_USESTYLE
);
1313 UserScrollDC(hDC
, dx
, dy
, &rc
, &cliprc
, hrgnUpdate
, rcUpdate
);
1314 UserReleaseDC(Window
, hDC
, FALSE
);
1318 * Take into account the fact that some damage may have occurred during
1322 hrgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
1323 Result
= co_UserGetUpdateRgn(Window
, hrgnTemp
, FALSE
);
1324 if (Result
!= NULLREGION
)
1326 HRGN hrgnClip
= UnsafeIntCreateRectRgnIndirect(&cliprc
);
1327 NtGdiOffsetRgn(hrgnTemp
, dx
, dy
);
1328 NtGdiCombineRgn(hrgnTemp
, hrgnTemp
, hrgnClip
, RGN_AND
);
1329 co_UserRedrawWindow(Window
, NULL
, hrgnTemp
, RDW_INVALIDATE
| RDW_ERASE
);
1330 NtGdiDeleteObject(hrgnClip
);
1333 NtGdiDeleteObject(hrgnTemp
);
1335 if (flags
& SW_SCROLLCHILDREN
)
1337 HWND
*List
= IntWinListChildren(Window
);
1345 IntGetClientOrigin(Window
, &ClientOrigin
);
1346 for (i
= 0; List
[i
]; i
++)
1348 if (!(Wnd
= UserGetWindowObject(List
[i
])))
1351 r
= Wnd
->WindowRect
;
1352 r
.left
-= ClientOrigin
.x
;
1353 r
.top
-= ClientOrigin
.y
;
1354 r
.right
-= ClientOrigin
.x
;
1355 r
.bottom
-= ClientOrigin
.y
;
1357 if (! UnsafeRect
|| IntGdiIntersectRect(&dummy
, &r
, &rc
))
1359 UserRefObjectCo(Wnd
);
1360 co_WinPosSetWindowPos(Wnd
, 0, r
.left
+ dx
, r
.top
+ dy
, 0, 0,
1361 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
|
1363 UserDerefObjectCo(Wnd
);
1371 if (flags
& (SW_INVALIDATE
| SW_ERASE
))
1372 co_UserRedrawWindow(Window
, NULL
, hrgnUpdate
, RDW_INVALIDATE
| RDW_ERASE
|
1373 ((flags
& SW_ERASE
) ? RDW_ERASENOW
: 0) |
1374 ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0));
1376 if (bOwnRgn
&& hrgnUpdate
)
1377 NtGdiDeleteObject(hrgnUpdate
);
1379 if ((CaretWnd
= UserGetWindowObject(hwndCaret
)))
1381 UserRefObjectCo(CaretWnd
);
1383 co_IntSetCaretPos(caretrc
.left
+ dx
, caretrc
.top
+ dy
);
1384 co_UserShowCaret(CaretWnd
);
1386 UserDerefObjectCo(CaretWnd
);
1393 UserDerefObjectCo(Window
);
1395 DPRINT("Leave NtUserScrollWindowEx, ret=%i\n",_ret_
);