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 #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 co_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 co_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
= UserGetDCEx(Window
, 0, DCX_CACHE
| DCX_USESTYLE
|
129 DCX_INTERSECTUPDATE
);
132 if (co_IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)hDC
, 0))
134 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
136 UserReleaseDC(Window
, hDC
);
141 if (Flags
& RDW_UPDATENOW
)
143 if (Window
->UpdateRegion
!= NULL
||
144 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
146 co_IntSendMessage(hWnd
, WM_PAINT
, 0, 0);
152 * Check that the window is still valid at this point
155 if (! IntIsWindow(hWnd
))
161 * Paint child windows.
163 if (!(Flags
& RDW_NOCHILDREN
) && !(Window
->Style
& WS_MINIMIZE
) &&
164 ((Flags
& RDW_ALLCHILDREN
) || !(Window
->Style
& WS_CLIPCHILDREN
)))
168 if ((List
= IntWinListChildren(Window
)))
170 for (phWnd
= List
; *phWnd
; ++phWnd
)
172 Window
= IntGetWindowObject(*phWnd
);
173 if (Window
&& (Window
->Style
& WS_VISIBLE
))
175 co_IntPaintWindows(Window
, Flags
);
176 IntReleaseWindowObject(Window
);
185 * IntInvalidateWindows
187 * Internal function used by IntRedrawWindow.
191 IntInvalidateWindows(PWINDOW_OBJECT Window
, HRGN hRgn
, ULONG Flags
)
194 BOOL HadPaintMessage
, HadNCPaintMessage
;
195 BOOL HasPaintMessage
, HasNCPaintMessage
;
198 * Clip the given region with window rectangle (or region)
201 IntLockWindowUpdate(Window
);
202 if (!Window
->WindowRegion
|| (Window
->Style
& WS_MINIMIZE
))
206 IntUnLockWindowUpdate(Window
);
207 hRgnWindow
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
208 NtGdiOffsetRgn(hRgnWindow
,
209 -Window
->WindowRect
.left
,
210 -Window
->WindowRect
.top
);
211 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, hRgnWindow
, RGN_AND
);
212 NtGdiDeleteObject(hRgnWindow
);
216 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, Window
->WindowRegion
, RGN_AND
);
217 IntUnLockWindowUpdate(Window
);
221 * Save current state of pending updates
224 IntLockWindowUpdate(Window
);
225 HadPaintMessage
= Window
->UpdateRegion
!= NULL
||
226 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
;
227 HadNCPaintMessage
= Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
;
230 * Update the region and flags
233 if (Flags
& RDW_INVALIDATE
&& RgnType
!= NULLREGION
)
235 if (Window
->UpdateRegion
== NULL
)
237 Window
->UpdateRegion
= NtGdiCreateRectRgn(0, 0, 0, 0);
238 GDIOBJ_SetOwnership(Window
->UpdateRegion
, NULL
);
241 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
242 hRgn
, RGN_OR
) == NULLREGION
)
244 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
245 NtGdiDeleteObject(Window
->UpdateRegion
);
246 Window
->UpdateRegion
= NULL
;
249 if (Flags
& RDW_FRAME
)
250 Window
->Flags
|= WINDOWOBJECT_NEED_NCPAINT
;
251 if (Flags
& RDW_ERASE
)
252 Window
->Flags
|= WINDOWOBJECT_NEED_ERASEBKGND
;
257 if (Flags
& RDW_VALIDATE
&& RgnType
!= NULLREGION
)
259 if (Window
->UpdateRegion
!= NULL
)
261 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
262 hRgn
, RGN_DIFF
) == NULLREGION
)
264 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
265 NtGdiDeleteObject(Window
->UpdateRegion
);
266 Window
->UpdateRegion
= NULL
;
270 if (Window
->UpdateRegion
== NULL
)
271 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
272 if (Flags
& RDW_NOFRAME
)
273 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
274 if (Flags
& RDW_NOERASE
)
275 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
278 if (Flags
& RDW_INTERNALPAINT
)
280 Window
->Flags
|= WINDOWOBJECT_NEED_INTERNALPAINT
;
283 if (Flags
& RDW_NOINTERNALPAINT
)
285 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
289 * Split the nonclient update region.
292 if (NULL
!= Window
->UpdateRegion
)
294 HRGN hRgnWindow
, hRgnNonClient
;
296 hRgnWindow
= UnsafeIntCreateRectRgnIndirect(&Window
->ClientRect
);
297 NtGdiOffsetRgn(hRgnWindow
,
298 -Window
->WindowRect
.left
,
299 -Window
->WindowRect
.top
);
301 hRgnNonClient
= NtGdiCreateRectRgn(0, 0, 0, 0);
302 if (NtGdiCombineRgn(hRgnNonClient
, Window
->UpdateRegion
,
303 hRgnWindow
, RGN_DIFF
) == NULLREGION
)
305 NtGdiDeleteObject(hRgnNonClient
);
306 hRgnNonClient
= NULL
;
310 GDIOBJ_SetOwnership(hRgnNonClient
, NULL
);
314 * Remove the nonclient region from the standard update region.
316 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
317 hRgnWindow
, RGN_AND
) == NULLREGION
)
319 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
320 NtGdiDeleteObject(Window
->UpdateRegion
);
321 Window
->UpdateRegion
= NULL
;
324 if (Window
->NCUpdateRegion
== NULL
)
326 Window
->NCUpdateRegion
= hRgnNonClient
;
330 if(NULL
!= hRgnNonClient
)
332 NtGdiCombineRgn(Window
->NCUpdateRegion
, Window
->NCUpdateRegion
,
333 hRgnNonClient
, RGN_OR
);
334 GDIOBJ_SetOwnership(hRgnNonClient
, PsGetCurrentProcess());
335 NtGdiDeleteObject(hRgnNonClient
);
339 NtGdiDeleteObject(hRgnWindow
);
343 * Process children if needed
346 if (!(Flags
& RDW_NOCHILDREN
) && !(Window
->Style
& WS_MINIMIZE
) &&
347 ((Flags
& RDW_ALLCHILDREN
) || !(Window
->Style
& WS_CLIPCHILDREN
)))
350 PWINDOW_OBJECT Child
;
352 if ((List
= IntWinListChildren(Window
)))
354 for (phWnd
= List
; *phWnd
; ++phWnd
)
356 Child
= IntGetWindowObject(*phWnd
);
361 if (Child
->Style
& WS_VISIBLE
)
364 * Recursive call to update children UpdateRegion
366 HRGN hRgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
367 NtGdiCombineRgn(hRgnTemp
, hRgn
, 0, RGN_COPY
);
368 NtGdiOffsetRgn(hRgnTemp
,
369 Window
->WindowRect
.left
- Child
->WindowRect
.left
,
370 Window
->WindowRect
.top
- Child
->WindowRect
.top
);
371 IntInvalidateWindows(Child
, hRgnTemp
, Flags
);
372 NtGdiDeleteObject(hRgnTemp
);
374 IntReleaseWindowObject(Child
);
381 * Fake post paint messages to window message queue if needed
384 HasPaintMessage
= Window
->UpdateRegion
!= NULL
||
385 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
;
386 HasNCPaintMessage
= Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
;
388 if (HasPaintMessage
!= HadPaintMessage
)
391 MsqDecPaintCountQueue(Window
->MessageQueue
);
393 MsqIncPaintCountQueue(Window
->MessageQueue
);
396 if (HasNCPaintMessage
!= HadNCPaintMessage
)
398 if (HadNCPaintMessage
)
399 MsqDecPaintCountQueue(Window
->MessageQueue
);
401 MsqIncPaintCountQueue(Window
->MessageQueue
);
404 IntUnLockWindowUpdate(Window
);
408 * IntIsWindowDrawable
411 * Window is drawable when it is visible and all parents are not
416 IntIsWindowDrawable(PWINDOW_OBJECT Window
)
418 PWINDOW_OBJECT Old
, Wnd
= Window
;
420 IntReferenceWindowObject(Wnd
);
423 if (!(Wnd
->Style
& WS_VISIBLE
) ||
424 ((Wnd
->Style
& WS_MINIMIZE
) && (Wnd
!= Window
)))
426 IntReleaseWindowObject(Wnd
);
430 Wnd
= IntGetParentObject(Wnd
);
431 IntReleaseWindowObject(Old
);
440 * Internal version of NtUserRedrawWindow that takes WINDOW_OBJECT as
445 co_UserRedrawWindow(PWINDOW_OBJECT Window
, const RECT
* UpdateRect
, HRGN UpdateRgn
,
452 * Validation of passed parameters.
455 if (!IntIsWindowDrawable(Window
) ||
456 (Flags
& (RDW_VALIDATE
| RDW_INVALIDATE
)) ==
457 (RDW_VALIDATE
| RDW_INVALIDATE
))
464 * Transform the parameters UpdateRgn and UpdateRect into
465 * a region hRgn specified in window coordinates.
468 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
))
470 if (UpdateRgn
!= NULL
)
472 hRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
473 NtGdiCombineRgn(hRgn
, UpdateRgn
, NULL
, RGN_COPY
);
475 Window
->ClientRect
.left
- Window
->WindowRect
.left
,
476 Window
->ClientRect
.top
- Window
->WindowRect
.top
);
478 if (UpdateRect
!= NULL
)
480 hRgn
= UnsafeIntCreateRectRgnIndirect((RECT
*)UpdateRect
);
482 Window
->ClientRect
.left
- Window
->WindowRect
.left
,
483 Window
->ClientRect
.top
- Window
->WindowRect
.top
);
485 if ((Flags
& (RDW_INVALIDATE
| RDW_FRAME
)) == (RDW_INVALIDATE
| RDW_FRAME
) ||
486 (Flags
& (RDW_VALIDATE
| RDW_NOFRAME
)) == (RDW_VALIDATE
| RDW_NOFRAME
))
488 hRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
490 -Window
->WindowRect
.left
,
491 -Window
->WindowRect
.top
);
495 hRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->ClientRect
);
497 -Window
->WindowRect
.left
,
498 -Window
->WindowRect
.top
);
504 * Adjust the window update region depending on hRgn and flags.
507 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
| RDW_INTERNALPAINT
| RDW_NOINTERNALPAINT
))
509 IntInvalidateWindows(Window
, hRgn
, Flags
);
514 * Repaint and erase windows if needed.
517 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
519 co_IntPaintWindows(Window
, Flags
);
529 NtGdiDeleteObject(hRgn
);
536 IntIsWindowDirty(PWINDOW_OBJECT Window
)
538 return (Window
->Style
& WS_VISIBLE
) &&
539 ((Window
->UpdateRegion
!= NULL
) ||
540 (Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
) ||
541 (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
));
545 IntFindWindowToRepaint(HWND hWnd
, PW32THREAD Thread
)
547 PWINDOW_OBJECT Window
;
548 PWINDOW_OBJECT Child
;
549 HWND hFoundWnd
= NULL
;
551 Window
= IntGetWindowObject(hWnd
);
555 if (IntIsWindowDirty(Window
) &&
556 IntWndBelongsToThread(Window
, Thread
))
558 IntReleaseWindowObject(Window
);
562 for (Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
564 if (IntIsWindowDirty(Child
) &&
565 IntWndBelongsToThread(Child
, Thread
))
567 hFoundWnd
= Child
->Self
;
572 if (hFoundWnd
== NULL
)
577 List
= IntWinListChildren(Window
);
580 for (i
= 0; List
[i
]; i
++)
582 hFoundWnd
= IntFindWindowToRepaint(List
[i
], Thread
);
583 if (hFoundWnd
!= NULL
)
590 IntReleaseWindowObject(Window
);
596 IntGetPaintMessage(HWND hWnd
, UINT MsgFilterMin
, UINT MsgFilterMax
,
597 PW32THREAD Thread
, MSG
*Message
, BOOL Remove
)
599 PWINDOW_OBJECT Window
;
600 PUSER_MESSAGE_QUEUE MessageQueue
= (PUSER_MESSAGE_QUEUE
)Thread
->MessageQueue
;
602 if (!MessageQueue
->PaintPosted
)
605 if ((MsgFilterMin
!= 0 || MsgFilterMax
!= 0) &&
606 (MsgFilterMin
> WM_PAINT
|| MsgFilterMax
< WM_PAINT
))
610 Message
->hwnd
= IntFindWindowToRepaint(hWnd
, PsGetWin32Thread());
612 Message
->hwnd
= IntFindWindowToRepaint(IntGetDesktopWindow(), PsGetWin32Thread());
614 if (Message
->hwnd
== NULL
)
618 DPRINT1("PAINTING BUG: Thread marked as containing dirty windows, but no dirty windows found!\n");
619 IntLockMessageQueue(MessageQueue
);
620 MessageQueue
->PaintPosted
= 0;
621 MessageQueue
->PaintCount
= 0;
622 IntUnLockMessageQueue(MessageQueue
);
627 Window
= IntGetWindowObject(Message
->hwnd
);
630 Message
->message
= WM_PAINT
;
631 Message
->wParam
= Message
->lParam
= 0;
632 IntReleaseWindowObject(Window
);
642 co_IntFixCaret(HWND hWnd
, LPRECT lprc
, UINT flags
)
644 PDESKTOP_OBJECT Desktop
;
645 PTHRDCARETINFO CaretInfo
;
648 Desktop
= PsGetCurrentThread()->Tcb
.Win32Thread
->Desktop
;
649 CaretInfo
= ((PUSER_MESSAGE_QUEUE
)Desktop
->ActiveMessageQueue
)->CaretInfo
;
650 hWndCaret
= CaretInfo
->hWnd
;
651 if (hWndCaret
== hWnd
||
652 ((flags
& SW_SCROLLCHILDREN
) && IntIsChildWindow(hWnd
, hWndCaret
)))
654 POINT pt
, FromOffset
, ToOffset
, Offset
;
657 pt
.x
= CaretInfo
->Pos
.x
;
658 pt
.y
= CaretInfo
->Pos
.y
;
659 IntGetClientOrigin(hWndCaret
, &FromOffset
);
660 IntGetClientOrigin(hWnd
, &ToOffset
);
661 Offset
.x
= FromOffset
.x
- ToOffset
.x
;
662 Offset
.y
= FromOffset
.y
- ToOffset
.y
;
665 rcCaret
.right
= pt
.x
+ CaretInfo
->Size
.cx
;
666 rcCaret
.bottom
= pt
.y
+ CaretInfo
->Size
.cy
;
667 if (IntGdiIntersectRect(lprc
, lprc
, &rcCaret
))
679 /* PUBLIC FUNCTIONS ***********************************************************/
689 NtUserBeginPaint(HWND hWnd
, PAINTSTRUCT
* UnsafePs
)
691 PWINDOW_OBJECT Window
;
697 DPRINT("Enter NtUserBeginPaint\n");
698 UserEnterExclusive();
700 if (!(Window
= IntGetWindowObject(hWnd
)))
702 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
706 co_UserHideCaret(Window
);
708 if (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
)
712 if (Window
->NCUpdateRegion
!= (HANDLE
)1 &&
713 Window
->NCUpdateRegion
!= NULL
)
715 GDIOBJ_SetOwnership(Window
->NCUpdateRegion
, PsGetCurrentProcess());
717 hRgn
= Window
->NCUpdateRegion
;
718 IntValidateParent(Window
, Window
->NCUpdateRegion
);
719 Window
->NCUpdateRegion
= NULL
;
720 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
721 MsqDecPaintCountQueue(Window
->MessageQueue
);
722 co_IntSendMessage(hWnd
, WM_NCPAINT
, (WPARAM
)hRgn
, 0);
723 if (hRgn
!= (HANDLE
)1 && hRgn
!= NULL
)
725 /* NOTE: The region can already by deleted! */
726 GDIOBJ_FreeObj(hRgn
, GDI_OBJECT_TYPE_REGION
| GDI_OBJECT_TYPE_SILENT
);
730 RtlZeroMemory(&Ps
, sizeof(PAINTSTRUCT
));
732 Ps
.hdc
= UserGetDCEx(Window
, 0, DCX_INTERSECTUPDATE
| DCX_WINDOWPAINT
| DCX_USESTYLE
);
736 IntReleaseWindowObject(Window
);
740 IntLockWindowUpdate(Window
);
741 if (Window
->UpdateRegion
!= NULL
)
743 MsqDecPaintCountQueue(Window
->MessageQueue
);
744 IntValidateParent(Window
, Window
->UpdateRegion
);
745 Rgn
= RGNDATA_LockRgn(Window
->UpdateRegion
);
748 UnsafeIntGetRgnBox(Rgn
, &Ps
.rcPaint
);
749 RGNDATA_UnlockRgn(Rgn
);
750 IntGdiOffsetRect(&Ps
.rcPaint
,
751 Window
->WindowRect
.left
- Window
->ClientRect
.left
,
752 Window
->WindowRect
.top
- Window
->ClientRect
.top
);
756 IntGetClientRect(Window
, &Ps
.rcPaint
);
758 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
759 NtGdiDeleteObject(Window
->UpdateRegion
);
760 Window
->UpdateRegion
= NULL
;
764 if (Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
765 MsqDecPaintCountQueue(Window
->MessageQueue
);
766 IntGetClientRect(Window
, &Ps
.rcPaint
);
768 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
769 IntUnLockWindowUpdate(Window
);
771 if (Window
->Flags
& WINDOWOBJECT_NEED_ERASEBKGND
)
773 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
774 Ps
.fErase
= !co_IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)Ps
.hdc
, 0);
781 IntReleaseWindowObject(Window
);
783 Status
= MmCopyToCaller(UnsafePs
, &Ps
, sizeof(PAINTSTRUCT
));
784 if (! NT_SUCCESS(Status
))
786 SetLastNtError(Status
);
793 DPRINT("Leave NtUserBeginPaint, ret=%i\n",_ret_
);
807 NtUserEndPaint(HWND hWnd
, CONST PAINTSTRUCT
* lPs
)
809 PWINDOW_OBJECT Window
;
810 DECLARE_RETURN(BOOL
);
812 DPRINT("Enter NtUserEndPaint\n");
813 UserEnterExclusive();
815 if (!(Window
= IntGetWindowObject(hWnd
)))
820 UserReleaseDC(Window
, lPs
->hdc
);
821 co_UserShowCaret(Window
);
823 IntReleaseWindowObject(Window
); //temp hack
828 DPRINT("Leave NtUserEndPaint, ret=%i\n",_ret_
);
834 * NtUserInvalidateRect
841 NtUserInvalidateRect(HWND hWnd
, CONST RECT
*Rect
, BOOL Erase
)
843 return NtUserRedrawWindow(hWnd
, Rect
, 0, RDW_INVALIDATE
| (Erase
? RDW_ERASE
: 0));
847 * NtUserInvalidateRgn
854 NtUserInvalidateRgn(HWND hWnd
, HRGN Rgn
, BOOL Erase
)
856 return NtUserRedrawWindow(hWnd
, NULL
, Rgn
, RDW_INVALIDATE
| (Erase
? RDW_ERASE
: 0));
862 UserValidateRgn(HWND hWnd
, HRGN hRgn
)
864 PWINDOW_OBJECT Window
;
867 if (!(Window
= IntGetWindowObject(hWnd
))) return FALSE
;
868 ret
= co_UserRedrawWindow(Window
, NULL
, hRgn
, RDW_VALIDATE
| RDW_NOCHILDREN
);
869 IntReleaseWindowObject(Window
);//temp hack
881 NtUserValidateRgn(HWND hWnd
, HRGN hRgn
)
883 return NtUserRedrawWindow(hWnd
, NULL
, hRgn
, RDW_VALIDATE
| RDW_NOCHILDREN
);
894 NtUserUpdateWindow(HWND hWnd
)
896 return NtUserRedrawWindow(hWnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
904 co_UserGetUpdateRgn(HWND hWnd
, HRGN hRgn
, BOOL bErase
)
906 PWINDOW_OBJECT Window
;
909 if (!(Window
= IntGetWindowObject(hWnd
)))
911 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
915 IntLockWindowUpdate(Window
);
916 if (Window
->UpdateRegion
== NULL
)
918 RegionType
= (NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0) ? NULLREGION
: ERROR
);
922 RegionType
= NtGdiCombineRgn(hRgn
, Window
->UpdateRegion
, hRgn
, RGN_COPY
);
925 Window
->WindowRect
.left
- Window
->ClientRect
.left
,
926 Window
->WindowRect
.top
- Window
->ClientRect
.top
);
928 IntUnLockWindowUpdate(Window
);
930 if (bErase
&& RegionType
!= NULLREGION
&& RegionType
!= ERROR
)
932 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
935 IntReleaseWindowObject(Window
);
947 NtUserGetUpdateRgn(HWND hWnd
, HRGN hRgn
, BOOL bErase
)
951 DPRINT("Enter NtUserGetUpdateRgn\n");
952 UserEnterExclusive();
954 RETURN(co_UserGetUpdateRgn(hWnd
, hRgn
, bErase
));
957 DPRINT("Leave NtUserGetUpdateRgn, ret=%i\n",_ret_
);
963 * NtUserGetUpdateRect
970 NtUserGetUpdateRect(HWND hWnd
, LPRECT UnsafeRect
, BOOL bErase
)
972 PWINDOW_OBJECT Window
;
978 DECLARE_RETURN(BOOL
);
980 DPRINT("Enter NtUserGetUpdateRect\n");
981 UserEnterExclusive();
983 if (!(Window
= IntGetWindowObject(hWnd
)))
985 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
989 IntLockWindowUpdate(Window
);
990 if (Window
->UpdateRegion
== NULL
)
992 Rect
.left
= Rect
.top
= Rect
.right
= Rect
.bottom
= 0;
996 RgnData
= RGNDATA_LockRgn(Window
->UpdateRegion
);
997 ASSERT(RgnData
!= NULL
);
998 RegionType
= UnsafeIntGetRgnBox(RgnData
, &Rect
);
999 ASSERT(RegionType
!= ERROR
);
1000 RGNDATA_UnlockRgn(RgnData
);
1002 AlwaysPaint
= (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
) ||
1003 (Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
);
1004 IntUnLockWindowUpdate(Window
);
1006 if (bErase
&& Rect
.left
< Rect
.right
&& Rect
.top
< Rect
.bottom
)
1008 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
1011 IntReleaseWindowObject(Window
);
1013 if (UnsafeRect
!= NULL
)
1015 Status
= MmCopyToCaller(UnsafeRect
, &Rect
, sizeof(RECT
));
1016 if (!NT_SUCCESS(Status
))
1018 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1023 RETURN( (Rect
.left
< Rect
.right
&& Rect
.top
< Rect
.bottom
) || AlwaysPaint
);
1026 DPRINT("Leave NtUserGetUpdateRect, ret=%i\n",_ret_
);
1032 * NtUserRedrawWindow
1039 NtUserRedrawWindow(HWND hWnd
, CONST RECT
*lprcUpdate
, HRGN hrgnUpdate
,
1042 RECT SafeUpdateRect
;
1045 DECLARE_RETURN(BOOL
);
1047 DPRINT("Enter NtUserRedrawWindow\n");
1048 UserEnterExclusive();
1050 if (!(Wnd
= IntGetWindowObject(hWnd
? hWnd
: IntGetDesktopWindow())))
1052 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
1056 if (lprcUpdate
!= NULL
)
1058 Status
= MmCopyFromCaller(&SafeUpdateRect
, (PRECT
)lprcUpdate
,
1061 if (!NT_SUCCESS(Status
))
1063 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1064 IntReleaseWindowObject(Wnd
);
1069 Status
= co_UserRedrawWindow(Wnd
, NULL
== lprcUpdate
? NULL
: &SafeUpdateRect
,
1072 if (!NT_SUCCESS(Status
))
1074 /* IntRedrawWindow fails only in case that flags are invalid */
1075 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1076 IntReleaseWindowObject(Wnd
);
1080 IntReleaseWindowObject(Wnd
);
1084 DPRINT("Leave NtUserRedrawWindow, ret=%i\n",_ret_
);
1093 UserScrollDC(HDC hDC
, INT dx
, INT dy
, const RECT
*lprcScroll
,
1094 const RECT
*lprcClip
, HRGN hrgnUpdate
, LPRECT lprcUpdate
)
1096 RECT rSrc
, rClipped_src
, rClip
, rDst
, offset
;
1100 * Compute device clipping region (in device coordinates).
1103 DC
= DC_LockDc(hDC
);
1111 IntGdiGetClipBox(hDC
, &rSrc
);
1112 IntLPtoDP(DC
, (LPPOINT
)&rSrc
, 2);
1117 IntGdiGetClipBox(hDC
, &rClip
);
1118 IntLPtoDP(DC
, (LPPOINT
)&rClip
, 2);
1120 IntGdiIntersectRect(&rClipped_src
, &rSrc
, &rClip
);
1122 rDst
= rClipped_src
;
1123 IntGdiSetRect(&offset
, 0, 0, dx
, dy
);
1124 IntLPtoDP(DC
, (LPPOINT
)&offset
, 2);
1125 IntGdiOffsetRect(&rDst
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
1126 IntGdiIntersectRect(&rDst
, &rDst
, &rClip
);
1129 * Copy bits, if possible.
1132 if (rDst
.bottom
> rDst
.top
&& rDst
.right
> rDst
.left
)
1134 RECT rDst_lp
= rDst
, rSrc_lp
= rDst
;
1136 IntGdiOffsetRect(&rSrc_lp
, offset
.left
- offset
.right
, offset
.top
- offset
.bottom
);
1137 IntDPtoLP(DC
, (LPPOINT
)&rDst_lp
, 2);
1138 IntDPtoLP(DC
, (LPPOINT
)&rSrc_lp
, 2);
1141 if (!NtGdiBitBlt(hDC
, rDst_lp
.left
, rDst_lp
.top
, rDst_lp
.right
- rDst_lp
.left
,
1142 rDst_lp
.bottom
- rDst_lp
.top
, hDC
, rSrc_lp
.left
, rSrc_lp
.top
,
1152 * Compute update areas. This is the clipped source or'ed with the
1153 * unclipped source translated minus the clipped src translated (rDst)
1154 * all clipped to rClip.
1157 if (hrgnUpdate
|| lprcUpdate
)
1159 HRGN hRgn
= hrgnUpdate
, hRgn2
;
1162 NtGdiSetRectRgn(hRgn
, rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
1164 hRgn
= NtGdiCreateRectRgn(rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
1166 hRgn2
= UnsafeIntCreateRectRgnIndirect(&rSrc
);
1167 NtGdiOffsetRgn(hRgn2
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
1168 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_OR
);
1170 NtGdiSetRectRgn(hRgn2
, rDst
.left
, rDst
.top
, rDst
.right
, rDst
.bottom
);
1171 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_DIFF
);
1173 NtGdiSetRectRgn(hRgn2
, rClip
.left
, rClip
.top
, rClip
.right
, rClip
.bottom
);
1174 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_AND
);
1178 NtGdiGetRgnBox(hRgn
, lprcUpdate
);
1180 /* Put the lprcUpdate in logical coordinate */
1181 NtGdiDPtoLP(hDC
, (LPPOINT
)lprcUpdate
, 2);
1184 NtGdiDeleteObject(hRgn
);
1185 NtGdiDeleteObject(hRgn2
);
1201 NtUserScrollDC(HDC hDC
, INT dx
, INT dy
, const RECT
*lprcScroll
,
1202 const RECT
*lprcClip
, HRGN hrgnUpdate
, LPRECT lprcUpdate
)
1204 DECLARE_RETURN(DWORD
);
1206 DPRINT("Enter NtUserScrollDC\n");
1207 UserEnterExclusive();
1209 RETURN( UserScrollDC(hDC
, dx
, dy
, lprcScroll
, lprcClip
, hrgnUpdate
, lprcUpdate
));
1212 DPRINT("Leave NtUserScrollDC, ret=%i\n",_ret_
);
1219 * NtUserScrollWindowEx
1226 NtUserScrollWindowEx(HWND hWnd
, INT dx
, INT dy
, const RECT
*UnsafeRect
,
1227 const RECT
*UnsafeClipRect
, HRGN hrgnUpdate
, LPRECT rcUpdate
, UINT flags
)
1229 RECT rc
, cliprc
, caretrc
, rect
, clipRect
;
1231 PWINDOW_OBJECT Window
, CaretWnd
;
1235 BOOL bUpdate
= (rcUpdate
|| hrgnUpdate
|| flags
& (SW_INVALIDATE
| SW_ERASE
));
1236 BOOL bOwnRgn
= TRUE
;
1238 DECLARE_RETURN(DWORD
);
1240 DPRINT("Enter NtUserScrollWindowEx\n");
1241 UserEnterExclusive();
1243 Window
= IntGetWindowObject(hWnd
);
1244 if (!Window
|| !IntIsWindowDrawable(Window
))
1246 IntReleaseWindowObject(Window
);
1250 IntGetClientRect(Window
, &rc
);
1251 if (NULL
!= UnsafeRect
)
1253 Status
= MmCopyFromCaller(&rect
, UnsafeRect
, sizeof(RECT
));
1254 if (! NT_SUCCESS(Status
))
1256 SetLastNtError(Status
);
1259 IntGdiIntersectRect(&rc
, &rc
, &rect
);
1262 if (NULL
!= UnsafeClipRect
)
1264 Status
= MmCopyFromCaller(&clipRect
, UnsafeClipRect
, sizeof(RECT
));
1265 if (! NT_SUCCESS(Status
))
1267 SetLastNtError(Status
);
1270 IntGdiIntersectRect(&cliprc
, &rc
, &clipRect
);
1275 if (cliprc
.right
<= cliprc
.left
|| cliprc
.bottom
<= cliprc
.top
||
1276 (dx
== 0 && dy
== 0))
1278 RETURN( NULLREGION
);
1282 hwndCaret
= co_IntFixCaret(hWnd
, &caretrc
, flags
);
1287 hrgnUpdate
= NtGdiCreateRectRgn(0, 0, 0, 0);
1289 hDC
= UserGetDCEx(Window
, 0, DCX_CACHE
| DCX_USESTYLE
);
1292 UserScrollDC(hDC
, dx
, dy
, &rc
, &cliprc
, hrgnUpdate
, rcUpdate
);
1293 UserReleaseDC(Window
, hDC
);
1297 * Take into account the fact that some damage may have occurred during
1301 hrgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
1302 Result
= co_UserGetUpdateRgn(hWnd
, hrgnTemp
, FALSE
);
1303 if (Result
!= NULLREGION
)
1305 HRGN hrgnClip
= UnsafeIntCreateRectRgnIndirect(&cliprc
);
1306 NtGdiOffsetRgn(hrgnTemp
, dx
, dy
);
1307 NtGdiCombineRgn(hrgnTemp
, hrgnTemp
, hrgnClip
, RGN_AND
);
1308 co_UserRedrawWindow(Window
, NULL
, hrgnTemp
, RDW_INVALIDATE
| RDW_ERASE
);
1309 NtGdiDeleteObject(hrgnClip
);
1311 NtGdiDeleteObject(hrgnTemp
);
1313 if (flags
& SW_SCROLLCHILDREN
)
1315 HWND
*List
= IntWinListChildren(Window
);
1321 PWINDOW_OBJECT WindowObject
;
1323 IntGetClientOrigin(hWnd
, &ClientOrigin
);
1324 for (i
= 0; List
[i
]; i
++)
1326 WindowObject
= IntGetWindowObject(List
[i
]);
1327 if (!WindowObject
) continue;
1328 r
= WindowObject
->WindowRect
;
1329 r
.left
-= ClientOrigin
.x
;
1330 r
.top
-= ClientOrigin
.y
;
1331 r
.right
-= ClientOrigin
.x
;
1332 r
.bottom
-= ClientOrigin
.y
;
1333 IntReleaseWindowObject(WindowObject
);
1334 if (! UnsafeRect
|| IntGdiIntersectRect(&dummy
, &r
, &rc
))
1335 co_WinPosSetWindowPos(List
[i
], 0, r
.left
+ dx
, r
.top
+ dy
, 0, 0,
1336 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
|
1343 if (flags
& (SW_INVALIDATE
| SW_ERASE
))
1344 co_UserRedrawWindow(Window
, NULL
, hrgnUpdate
, RDW_INVALIDATE
| RDW_ERASE
|
1345 ((flags
& SW_ERASE
) ? RDW_ERASENOW
: 0) |
1346 ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0));
1348 if (bOwnRgn
&& hrgnUpdate
)
1349 NtGdiDeleteObject(hrgnUpdate
);
1351 if ((CaretWnd
= IntGetWindowObject(hwndCaret
)))
1353 co_IntSetCaretPos(caretrc
.left
+ dx
, caretrc
.top
+ dy
);
1354 co_UserShowCaret(CaretWnd
);
1355 IntReleaseWindowObject(CaretWnd
);
1358 IntReleaseWindowObject(Window
);
1363 DPRINT("Leave NtUserScrollWindowEx, ret=%i\n",_ret_
);