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
= Child
->Parent
;
49 if (!(ParentWindow
->Style
& WS_CLIPCHILDREN
))
51 if (ParentWindow
->UpdateRegion
!= 0)
56 * We must offset the child region by the offset of the
57 * child rect in the parent.
59 OffsetX
= Child
->WindowRect
.left
- ParentWindow
->WindowRect
.left
;
60 OffsetY
= Child
->WindowRect
.top
- ParentWindow
->WindowRect
.top
;
61 NtGdiOffsetRgn(ValidRegion
, OffsetX
, OffsetY
);
62 NtGdiCombineRgn(ParentWindow
->UpdateRegion
, ParentWindow
->UpdateRegion
,
63 ValidRegion
, RGN_DIFF
);
64 /* FIXME: If the resulting region is empty, remove fake posted paint message */
65 NtGdiOffsetRgn(ValidRegion
, -OffsetX
, -OffsetY
);
69 ParentWindow
= ParentWindow
->Parent
;
76 * Internal function used by IntRedrawWindow.
80 co_IntPaintWindows(PWINDOW_OBJECT Window
, ULONG Flags
)
83 HWND hWnd
= Window
->hSelf
;
86 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
88 if (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
)
90 if (Window
->NCUpdateRegion
)
92 IntValidateParent(Window
, Window
->NCUpdateRegion
);
94 TempRegion
= Window
->NCUpdateRegion
;
95 if ((HANDLE
) 1 != TempRegion
&& NULL
!= TempRegion
)
97 GDIOBJ_SetOwnership(TempRegion
, PsGetCurrentProcess());
99 Window
->NCUpdateRegion
= NULL
;
100 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
101 MsqDecPaintCountQueue(Window
->MessageQueue
);
102 co_IntSendMessage(hWnd
, WM_NCPAINT
, (WPARAM
)TempRegion
, 0);
103 if ((HANDLE
) 1 != TempRegion
&& NULL
!= TempRegion
)
105 /* NOTE: The region can already be deleted! */
106 GDIOBJ_FreeObj(TempRegion
, GDI_OBJECT_TYPE_REGION
| GDI_OBJECT_TYPE_SILENT
);
110 if (Window
->Flags
& WINDOWOBJECT_NEED_ERASEBKGND
)
112 if (Window
->UpdateRegion
)
115 * This surely wrong! Why we would want to validate the parent?
116 * It breaks quite a few things including dummy WM_ERASEBKGND
117 * implementations that return only TRUE and have corresponding
118 * WM_PAINT that doesn't paint the whole client area.
119 * I left the code here so that no one will readd it again!
122 /* IntValidateParent(Window, Window->UpdateRegion); */
123 hDC
= UserGetDCEx(Window
, 0, DCX_CACHE
| DCX_USESTYLE
|
124 DCX_INTERSECTUPDATE
);
127 if (co_IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)hDC
, 0))
129 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
131 UserReleaseDC(Window
, hDC
);
136 if (Flags
& RDW_UPDATENOW
)
138 if (Window
->UpdateRegion
!= NULL
||
139 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
141 co_IntSendMessage(hWnd
, WM_PAINT
, 0, 0);
147 * Check that the window is still valid at this point
150 if (! IntIsWindow(hWnd
))
156 * Paint child windows.
158 if (!(Flags
& RDW_NOCHILDREN
) && !(Window
->Style
& WS_MINIMIZE
) &&
159 ((Flags
& RDW_ALLCHILDREN
) || !(Window
->Style
& WS_CLIPCHILDREN
)))
163 if ((List
= IntWinListChildren(Window
)))
165 for (phWnd
= List
; *phWnd
; ++phWnd
)
167 Window
= IntGetWindowObject(*phWnd
);
168 if (Window
&& (Window
->Style
& WS_VISIBLE
))
170 co_IntPaintWindows(Window
, Flags
);
171 IntReleaseWindowObject(Window
);
180 * IntInvalidateWindows
182 * Internal function used by IntRedrawWindow.
186 IntInvalidateWindows(PWINDOW_OBJECT Window
, HRGN hRgn
, ULONG Flags
)
189 BOOL HadPaintMessage
, HadNCPaintMessage
;
190 BOOL HasPaintMessage
, HasNCPaintMessage
;
193 * Clip the given region with window rectangle (or region)
196 if (!Window
->WindowRegion
|| (Window
->Style
& WS_MINIMIZE
))
200 hRgnWindow
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
201 NtGdiOffsetRgn(hRgnWindow
,
202 -Window
->WindowRect
.left
,
203 -Window
->WindowRect
.top
);
204 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, hRgnWindow
, RGN_AND
);
205 NtGdiDeleteObject(hRgnWindow
);
209 RgnType
= NtGdiCombineRgn(hRgn
, hRgn
, Window
->WindowRegion
, RGN_AND
);
213 * Save current state of pending updates
216 HadPaintMessage
= Window
->UpdateRegion
!= NULL
||
217 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
;
218 HadNCPaintMessage
= Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
;
221 * Update the region and flags
224 if (Flags
& RDW_INVALIDATE
&& RgnType
!= NULLREGION
)
226 if (Window
->UpdateRegion
== NULL
)
228 Window
->UpdateRegion
= NtGdiCreateRectRgn(0, 0, 0, 0);
229 GDIOBJ_SetOwnership(Window
->UpdateRegion
, NULL
);
232 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
233 hRgn
, RGN_OR
) == NULLREGION
)
235 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
236 NtGdiDeleteObject(Window
->UpdateRegion
);
237 Window
->UpdateRegion
= NULL
;
240 if (Flags
& RDW_FRAME
)
241 Window
->Flags
|= WINDOWOBJECT_NEED_NCPAINT
;
242 if (Flags
& RDW_ERASE
)
243 Window
->Flags
|= WINDOWOBJECT_NEED_ERASEBKGND
;
248 if (Flags
& RDW_VALIDATE
&& RgnType
!= NULLREGION
)
250 if (Window
->UpdateRegion
!= NULL
)
252 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
253 hRgn
, RGN_DIFF
) == NULLREGION
)
255 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
256 NtGdiDeleteObject(Window
->UpdateRegion
);
257 Window
->UpdateRegion
= NULL
;
261 if (Window
->UpdateRegion
== NULL
)
262 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
263 if (Flags
& RDW_NOFRAME
)
264 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
265 if (Flags
& RDW_NOERASE
)
266 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
269 if (Flags
& RDW_INTERNALPAINT
)
271 Window
->Flags
|= WINDOWOBJECT_NEED_INTERNALPAINT
;
274 if (Flags
& RDW_NOINTERNALPAINT
)
276 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
280 * Split the nonclient update region.
283 if (NULL
!= Window
->UpdateRegion
)
285 HRGN hRgnWindow
, hRgnNonClient
;
287 hRgnWindow
= UnsafeIntCreateRectRgnIndirect(&Window
->ClientRect
);
288 NtGdiOffsetRgn(hRgnWindow
,
289 -Window
->WindowRect
.left
,
290 -Window
->WindowRect
.top
);
292 hRgnNonClient
= NtGdiCreateRectRgn(0, 0, 0, 0);
293 if (NtGdiCombineRgn(hRgnNonClient
, Window
->UpdateRegion
,
294 hRgnWindow
, RGN_DIFF
) == NULLREGION
)
296 NtGdiDeleteObject(hRgnNonClient
);
297 hRgnNonClient
= NULL
;
301 GDIOBJ_SetOwnership(hRgnNonClient
, NULL
);
305 * Remove the nonclient region from the standard update region.
307 if (NtGdiCombineRgn(Window
->UpdateRegion
, Window
->UpdateRegion
,
308 hRgnWindow
, RGN_AND
) == NULLREGION
)
310 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
311 NtGdiDeleteObject(Window
->UpdateRegion
);
312 Window
->UpdateRegion
= NULL
;
315 if (Window
->NCUpdateRegion
== NULL
)
317 Window
->NCUpdateRegion
= hRgnNonClient
;
321 if(NULL
!= hRgnNonClient
)
323 NtGdiCombineRgn(Window
->NCUpdateRegion
, Window
->NCUpdateRegion
,
324 hRgnNonClient
, RGN_OR
);
325 GDIOBJ_SetOwnership(hRgnNonClient
, PsGetCurrentProcess());
326 NtGdiDeleteObject(hRgnNonClient
);
330 NtGdiDeleteObject(hRgnWindow
);
334 * Process children if needed
337 if (!(Flags
& RDW_NOCHILDREN
) && !(Window
->Style
& WS_MINIMIZE
) &&
338 ((Flags
& RDW_ALLCHILDREN
) || !(Window
->Style
& WS_CLIPCHILDREN
)))
341 PWINDOW_OBJECT Child
;
343 if ((List
= IntWinListChildren(Window
)))
345 for (phWnd
= List
; *phWnd
; ++phWnd
)
347 Child
= IntGetWindowObject(*phWnd
);
352 if (Child
->Style
& WS_VISIBLE
)
355 * Recursive call to update children UpdateRegion
357 HRGN hRgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
358 NtGdiCombineRgn(hRgnTemp
, hRgn
, 0, RGN_COPY
);
359 NtGdiOffsetRgn(hRgnTemp
,
360 Window
->WindowRect
.left
- Child
->WindowRect
.left
,
361 Window
->WindowRect
.top
- Child
->WindowRect
.top
);
362 IntInvalidateWindows(Child
, hRgnTemp
, Flags
);
363 NtGdiDeleteObject(hRgnTemp
);
365 IntReleaseWindowObject(Child
);
372 * Fake post paint messages to window message queue if needed
375 HasPaintMessage
= Window
->UpdateRegion
!= NULL
||
376 Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
;
377 HasNCPaintMessage
= Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
;
379 if (HasPaintMessage
!= HadPaintMessage
)
382 MsqDecPaintCountQueue(Window
->MessageQueue
);
384 MsqIncPaintCountQueue(Window
->MessageQueue
);
387 if (HasNCPaintMessage
!= HadNCPaintMessage
)
389 if (HadNCPaintMessage
)
390 MsqDecPaintCountQueue(Window
->MessageQueue
);
392 MsqIncPaintCountQueue(Window
->MessageQueue
);
398 * IntIsWindowDrawable
401 * Window is drawable when it is visible and all parents are not
406 IntIsWindowDrawable(PWINDOW_OBJECT Window
)
408 PWINDOW_OBJECT Old
, Wnd
= Window
;
410 IntReferenceWindowObject(Wnd
);
413 if (!(Wnd
->Style
& WS_VISIBLE
) ||
414 ((Wnd
->Style
& WS_MINIMIZE
) && (Wnd
!= Window
)))
416 IntReleaseWindowObject(Wnd
);
420 Wnd
= IntGetParentObject(Wnd
);
421 IntReleaseWindowObject(Old
);
430 * Internal version of NtUserRedrawWindow that takes WINDOW_OBJECT as
435 co_UserRedrawWindow(PWINDOW_OBJECT Window
, const RECT
* UpdateRect
, HRGN UpdateRgn
,
442 * Validation of passed parameters.
445 if (!IntIsWindowDrawable(Window
) ||
446 (Flags
& (RDW_VALIDATE
| RDW_INVALIDATE
)) ==
447 (RDW_VALIDATE
| RDW_INVALIDATE
))
454 * Transform the parameters UpdateRgn and UpdateRect into
455 * a region hRgn specified in window coordinates.
458 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
))
460 if (UpdateRgn
!= NULL
)
462 hRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
463 NtGdiCombineRgn(hRgn
, UpdateRgn
, NULL
, RGN_COPY
);
465 Window
->ClientRect
.left
- Window
->WindowRect
.left
,
466 Window
->ClientRect
.top
- Window
->WindowRect
.top
);
468 if (UpdateRect
!= NULL
)
470 hRgn
= UnsafeIntCreateRectRgnIndirect((RECT
*)UpdateRect
);
472 Window
->ClientRect
.left
- Window
->WindowRect
.left
,
473 Window
->ClientRect
.top
- Window
->WindowRect
.top
);
475 if ((Flags
& (RDW_INVALIDATE
| RDW_FRAME
)) == (RDW_INVALIDATE
| RDW_FRAME
) ||
476 (Flags
& (RDW_VALIDATE
| RDW_NOFRAME
)) == (RDW_VALIDATE
| RDW_NOFRAME
))
478 hRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
480 -Window
->WindowRect
.left
,
481 -Window
->WindowRect
.top
);
485 hRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->ClientRect
);
487 -Window
->WindowRect
.left
,
488 -Window
->WindowRect
.top
);
494 * Adjust the window update region depending on hRgn and flags.
497 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
| RDW_INTERNALPAINT
| RDW_NOINTERNALPAINT
))
499 IntInvalidateWindows(Window
, hRgn
, Flags
);
504 * Repaint and erase windows if needed.
507 if (Flags
& (RDW_ERASENOW
| RDW_UPDATENOW
))
509 co_IntPaintWindows(Window
, Flags
);
519 NtGdiDeleteObject(hRgn
);
526 IntIsWindowDirty(PWINDOW_OBJECT Window
)
528 return (Window
->Style
& WS_VISIBLE
) &&
529 ((Window
->UpdateRegion
!= NULL
) ||
530 (Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
) ||
531 (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
));
535 IntFindWindowToRepaint(HWND hWnd
, PW32THREAD Thread
)
537 PWINDOW_OBJECT Window
;
538 PWINDOW_OBJECT Child
;
539 HWND hFoundWnd
= NULL
;
541 Window
= IntGetWindowObject(hWnd
);
545 if (IntIsWindowDirty(Window
) &&
546 IntWndBelongsToThread(Window
, Thread
))
548 IntReleaseWindowObject(Window
);
552 for (Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
554 if (IntIsWindowDirty(Child
) &&
555 IntWndBelongsToThread(Child
, Thread
))
557 hFoundWnd
= Child
->hSelf
;
562 if (hFoundWnd
== NULL
)
567 List
= IntWinListChildren(Window
);
570 for (i
= 0; List
[i
]; i
++)
572 hFoundWnd
= IntFindWindowToRepaint(List
[i
], Thread
);
573 if (hFoundWnd
!= NULL
)
580 IntReleaseWindowObject(Window
);
586 IntGetPaintMessage(HWND hWnd
, UINT MsgFilterMin
, UINT MsgFilterMax
,
587 PW32THREAD Thread
, MSG
*Message
, BOOL Remove
)
589 PWINDOW_OBJECT Window
;
590 PUSER_MESSAGE_QUEUE MessageQueue
= (PUSER_MESSAGE_QUEUE
)Thread
->MessageQueue
;
592 if (!MessageQueue
->PaintPosted
)
595 if ((MsgFilterMin
!= 0 || MsgFilterMax
!= 0) &&
596 (MsgFilterMin
> WM_PAINT
|| MsgFilterMax
< WM_PAINT
))
600 Message
->hwnd
= IntFindWindowToRepaint(hWnd
, PsGetWin32Thread());
602 Message
->hwnd
= IntFindWindowToRepaint(IntGetDesktopWindow(), PsGetWin32Thread());
604 if (Message
->hwnd
== NULL
)
608 DPRINT1("PAINTING BUG: Thread marked as containing dirty windows, but no dirty windows found!\n");
609 MessageQueue
->PaintPosted
= 0;
610 MessageQueue
->PaintCount
= 0;
615 Window
= IntGetWindowObject(Message
->hwnd
);
618 Message
->message
= WM_PAINT
;
619 Message
->wParam
= Message
->lParam
= 0;
620 IntReleaseWindowObject(Window
);
630 co_IntFixCaret(HWND hWnd
, LPRECT lprc
, UINT flags
)
632 PDESKTOP_OBJECT Desktop
;
633 PTHRDCARETINFO CaretInfo
;
636 Desktop
= PsGetCurrentThread()->Tcb
.Win32Thread
->Desktop
;
637 CaretInfo
= ((PUSER_MESSAGE_QUEUE
)Desktop
->ActiveMessageQueue
)->CaretInfo
;
638 hWndCaret
= CaretInfo
->hWnd
;
639 if (hWndCaret
== hWnd
||
640 ((flags
& SW_SCROLLCHILDREN
) && IntIsChildWindow(hWnd
, hWndCaret
)))
642 POINT pt
, FromOffset
, ToOffset
, Offset
;
645 pt
.x
= CaretInfo
->Pos
.x
;
646 pt
.y
= CaretInfo
->Pos
.y
;
647 IntGetClientOrigin(hWndCaret
, &FromOffset
);
648 IntGetClientOrigin(hWnd
, &ToOffset
);
649 Offset
.x
= FromOffset
.x
- ToOffset
.x
;
650 Offset
.y
= FromOffset
.y
- ToOffset
.y
;
653 rcCaret
.right
= pt
.x
+ CaretInfo
->Size
.cx
;
654 rcCaret
.bottom
= pt
.y
+ CaretInfo
->Size
.cy
;
655 if (IntGdiIntersectRect(lprc
, lprc
, &rcCaret
))
667 /* PUBLIC FUNCTIONS ***********************************************************/
677 NtUserBeginPaint(HWND hWnd
, PAINTSTRUCT
* UnsafePs
)
679 PWINDOW_OBJECT Window
;
685 DPRINT("Enter NtUserBeginPaint\n");
686 UserEnterExclusive();
688 if (!(Window
= IntGetWindowObject(hWnd
)))
690 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
694 co_UserHideCaret(Window
);
696 if (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
)
700 if (Window
->NCUpdateRegion
!= (HANDLE
)1 &&
701 Window
->NCUpdateRegion
!= NULL
)
703 GDIOBJ_SetOwnership(Window
->NCUpdateRegion
, PsGetCurrentProcess());
705 hRgn
= Window
->NCUpdateRegion
;
706 IntValidateParent(Window
, Window
->NCUpdateRegion
);
707 Window
->NCUpdateRegion
= NULL
;
708 Window
->Flags
&= ~WINDOWOBJECT_NEED_NCPAINT
;
709 MsqDecPaintCountQueue(Window
->MessageQueue
);
710 co_IntSendMessage(hWnd
, WM_NCPAINT
, (WPARAM
)hRgn
, 0);
711 if (hRgn
!= (HANDLE
)1 && hRgn
!= NULL
)
713 /* NOTE: The region can already by deleted! */
714 GDIOBJ_FreeObj(hRgn
, GDI_OBJECT_TYPE_REGION
| GDI_OBJECT_TYPE_SILENT
);
718 RtlZeroMemory(&Ps
, sizeof(PAINTSTRUCT
));
720 Ps
.hdc
= UserGetDCEx(Window
, 0, DCX_INTERSECTUPDATE
| DCX_WINDOWPAINT
| DCX_USESTYLE
);
724 IntReleaseWindowObject(Window
);
728 if (Window
->UpdateRegion
!= NULL
)
730 MsqDecPaintCountQueue(Window
->MessageQueue
);
731 IntValidateParent(Window
, Window
->UpdateRegion
);
732 Rgn
= RGNDATA_LockRgn(Window
->UpdateRegion
);
735 UnsafeIntGetRgnBox(Rgn
, &Ps
.rcPaint
);
736 RGNDATA_UnlockRgn(Rgn
);
737 IntGdiOffsetRect(&Ps
.rcPaint
,
738 Window
->WindowRect
.left
- Window
->ClientRect
.left
,
739 Window
->WindowRect
.top
- Window
->ClientRect
.top
);
743 IntGetClientRect(Window
, &Ps
.rcPaint
);
745 GDIOBJ_SetOwnership(Window
->UpdateRegion
, PsGetCurrentProcess());
746 NtGdiDeleteObject(Window
->UpdateRegion
);
747 Window
->UpdateRegion
= NULL
;
751 if (Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
)
752 MsqDecPaintCountQueue(Window
->MessageQueue
);
753 IntGetClientRect(Window
, &Ps
.rcPaint
);
755 Window
->Flags
&= ~WINDOWOBJECT_NEED_INTERNALPAINT
;
757 if (Window
->Flags
& WINDOWOBJECT_NEED_ERASEBKGND
)
759 Window
->Flags
&= ~WINDOWOBJECT_NEED_ERASEBKGND
;
760 Ps
.fErase
= !co_IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)Ps
.hdc
, 0);
767 IntReleaseWindowObject(Window
);
769 Status
= MmCopyToCaller(UnsafePs
, &Ps
, sizeof(PAINTSTRUCT
));
770 if (! NT_SUCCESS(Status
))
772 SetLastNtError(Status
);
779 DPRINT("Leave NtUserBeginPaint, ret=%i\n",_ret_
);
793 NtUserEndPaint(HWND hWnd
, CONST PAINTSTRUCT
* lPs
)
795 PWINDOW_OBJECT Window
;
796 DECLARE_RETURN(BOOL
);
798 DPRINT("Enter NtUserEndPaint\n");
799 UserEnterExclusive();
801 if (!(Window
= IntGetWindowObject(hWnd
)))
806 UserReleaseDC(Window
, lPs
->hdc
);
807 co_UserShowCaret(Window
);
809 IntReleaseWindowObject(Window
); //temp hack
814 DPRINT("Leave NtUserEndPaint, ret=%i\n",_ret_
);
820 * NtUserInvalidateRect
827 NtUserInvalidateRect(HWND hWnd
, CONST RECT
*Rect
, BOOL Erase
)
829 return NtUserRedrawWindow(hWnd
, Rect
, 0, RDW_INVALIDATE
| (Erase
? RDW_ERASE
: 0));
833 * NtUserInvalidateRgn
840 NtUserInvalidateRgn(HWND hWnd
, HRGN Rgn
, BOOL Erase
)
842 return NtUserRedrawWindow(hWnd
, NULL
, Rgn
, RDW_INVALIDATE
| (Erase
? RDW_ERASE
: 0));
848 UserValidateRgn(HWND hWnd
, HRGN hRgn
)
850 PWINDOW_OBJECT Window
;
853 if (!(Window
= IntGetWindowObject(hWnd
))) return FALSE
;
854 ret
= co_UserRedrawWindow(Window
, NULL
, hRgn
, RDW_VALIDATE
| RDW_NOCHILDREN
);
855 IntReleaseWindowObject(Window
);//temp hack
867 NtUserValidateRgn(HWND hWnd
, HRGN hRgn
)
869 return NtUserRedrawWindow(hWnd
, NULL
, hRgn
, RDW_VALIDATE
| RDW_NOCHILDREN
);
880 NtUserUpdateWindow(HWND hWnd
)
882 return NtUserRedrawWindow(hWnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
890 co_UserGetUpdateRgn(HWND hWnd
, HRGN hRgn
, BOOL bErase
)
892 PWINDOW_OBJECT Window
;
895 if (!(Window
= IntGetWindowObject(hWnd
)))
897 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
901 if (Window
->UpdateRegion
== NULL
)
903 RegionType
= (NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0) ? NULLREGION
: ERROR
);
907 RegionType
= NtGdiCombineRgn(hRgn
, Window
->UpdateRegion
, hRgn
, RGN_COPY
);
910 Window
->WindowRect
.left
- Window
->ClientRect
.left
,
911 Window
->WindowRect
.top
- Window
->ClientRect
.top
);
914 if (bErase
&& RegionType
!= NULLREGION
&& RegionType
!= ERROR
)
916 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
919 IntReleaseWindowObject(Window
);
931 NtUserGetUpdateRgn(HWND hWnd
, HRGN hRgn
, BOOL bErase
)
935 DPRINT("Enter NtUserGetUpdateRgn\n");
936 UserEnterExclusive();
938 RETURN(co_UserGetUpdateRgn(hWnd
, hRgn
, bErase
));
941 DPRINT("Leave NtUserGetUpdateRgn, ret=%i\n",_ret_
);
947 * NtUserGetUpdateRect
954 NtUserGetUpdateRect(HWND hWnd
, LPRECT UnsafeRect
, BOOL bErase
)
956 PWINDOW_OBJECT Window
;
962 DECLARE_RETURN(BOOL
);
964 DPRINT("Enter NtUserGetUpdateRect\n");
965 UserEnterExclusive();
967 if (!(Window
= IntGetWindowObject(hWnd
)))
969 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
973 if (Window
->UpdateRegion
== NULL
)
975 Rect
.left
= Rect
.top
= Rect
.right
= Rect
.bottom
= 0;
979 RgnData
= RGNDATA_LockRgn(Window
->UpdateRegion
);
980 ASSERT(RgnData
!= NULL
);
981 RegionType
= UnsafeIntGetRgnBox(RgnData
, &Rect
);
982 ASSERT(RegionType
!= ERROR
);
983 RGNDATA_UnlockRgn(RgnData
);
985 AlwaysPaint
= (Window
->Flags
& WINDOWOBJECT_NEED_NCPAINT
) ||
986 (Window
->Flags
& WINDOWOBJECT_NEED_INTERNALPAINT
);
988 if (bErase
&& Rect
.left
< Rect
.right
&& Rect
.top
< Rect
.bottom
)
990 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_ERASENOW
| RDW_NOCHILDREN
);
993 IntReleaseWindowObject(Window
);
995 if (UnsafeRect
!= NULL
)
997 Status
= MmCopyToCaller(UnsafeRect
, &Rect
, sizeof(RECT
));
998 if (!NT_SUCCESS(Status
))
1000 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1005 RETURN( (Rect
.left
< Rect
.right
&& Rect
.top
< Rect
.bottom
) || AlwaysPaint
);
1008 DPRINT("Leave NtUserGetUpdateRect, ret=%i\n",_ret_
);
1014 * NtUserRedrawWindow
1021 NtUserRedrawWindow(HWND hWnd
, CONST RECT
*lprcUpdate
, HRGN hrgnUpdate
,
1024 RECT SafeUpdateRect
;
1027 DECLARE_RETURN(BOOL
);
1029 DPRINT("Enter NtUserRedrawWindow\n");
1030 UserEnterExclusive();
1032 if (!(Wnd
= IntGetWindowObject(hWnd
? hWnd
: IntGetDesktopWindow())))
1034 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
1038 if (lprcUpdate
!= NULL
)
1040 Status
= MmCopyFromCaller(&SafeUpdateRect
, (PRECT
)lprcUpdate
,
1043 if (!NT_SUCCESS(Status
))
1045 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1046 IntReleaseWindowObject(Wnd
);
1051 Status
= co_UserRedrawWindow(Wnd
, NULL
== lprcUpdate
? NULL
: &SafeUpdateRect
,
1054 if (!NT_SUCCESS(Status
))
1056 /* IntRedrawWindow fails only in case that flags are invalid */
1057 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1058 IntReleaseWindowObject(Wnd
);
1062 IntReleaseWindowObject(Wnd
);
1066 DPRINT("Leave NtUserRedrawWindow, ret=%i\n",_ret_
);
1075 UserScrollDC(HDC hDC
, INT dx
, INT dy
, const RECT
*lprcScroll
,
1076 const RECT
*lprcClip
, HRGN hrgnUpdate
, LPRECT lprcUpdate
)
1078 RECT rSrc
, rClipped_src
, rClip
, rDst
, offset
;
1082 * Compute device clipping region (in device coordinates).
1085 DC
= DC_LockDc(hDC
);
1093 IntGdiGetClipBox(hDC
, &rSrc
);
1094 IntLPtoDP(DC
, (LPPOINT
)&rSrc
, 2);
1099 IntGdiGetClipBox(hDC
, &rClip
);
1100 IntLPtoDP(DC
, (LPPOINT
)&rClip
, 2);
1102 IntGdiIntersectRect(&rClipped_src
, &rSrc
, &rClip
);
1104 rDst
= rClipped_src
;
1105 IntGdiSetRect(&offset
, 0, 0, dx
, dy
);
1106 IntLPtoDP(DC
, (LPPOINT
)&offset
, 2);
1107 IntGdiOffsetRect(&rDst
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
1108 IntGdiIntersectRect(&rDst
, &rDst
, &rClip
);
1111 * Copy bits, if possible.
1114 if (rDst
.bottom
> rDst
.top
&& rDst
.right
> rDst
.left
)
1116 RECT rDst_lp
= rDst
, rSrc_lp
= rDst
;
1118 IntGdiOffsetRect(&rSrc_lp
, offset
.left
- offset
.right
, offset
.top
- offset
.bottom
);
1119 IntDPtoLP(DC
, (LPPOINT
)&rDst_lp
, 2);
1120 IntDPtoLP(DC
, (LPPOINT
)&rSrc_lp
, 2);
1123 if (!NtGdiBitBlt(hDC
, rDst_lp
.left
, rDst_lp
.top
, rDst_lp
.right
- rDst_lp
.left
,
1124 rDst_lp
.bottom
- rDst_lp
.top
, hDC
, rSrc_lp
.left
, rSrc_lp
.top
,
1134 * Compute update areas. This is the clipped source or'ed with the
1135 * unclipped source translated minus the clipped src translated (rDst)
1136 * all clipped to rClip.
1139 if (hrgnUpdate
|| lprcUpdate
)
1141 HRGN hRgn
= hrgnUpdate
, hRgn2
;
1144 NtGdiSetRectRgn(hRgn
, rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
1146 hRgn
= NtGdiCreateRectRgn(rClipped_src
.left
, rClipped_src
.top
, rClipped_src
.right
, rClipped_src
.bottom
);
1148 hRgn2
= UnsafeIntCreateRectRgnIndirect(&rSrc
);
1149 NtGdiOffsetRgn(hRgn2
, offset
.right
- offset
.left
, offset
.bottom
- offset
.top
);
1150 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_OR
);
1152 NtGdiSetRectRgn(hRgn2
, rDst
.left
, rDst
.top
, rDst
.right
, rDst
.bottom
);
1153 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_DIFF
);
1155 NtGdiSetRectRgn(hRgn2
, rClip
.left
, rClip
.top
, rClip
.right
, rClip
.bottom
);
1156 NtGdiCombineRgn(hRgn
, hRgn
, hRgn2
, RGN_AND
);
1160 NtGdiGetRgnBox(hRgn
, lprcUpdate
);
1162 /* Put the lprcUpdate in logical coordinate */
1163 NtGdiDPtoLP(hDC
, (LPPOINT
)lprcUpdate
, 2);
1166 NtGdiDeleteObject(hRgn
);
1167 NtGdiDeleteObject(hRgn2
);
1183 NtUserScrollDC(HDC hDC
, INT dx
, INT dy
, const RECT
*lprcScroll
,
1184 const RECT
*lprcClip
, HRGN hrgnUpdate
, LPRECT lprcUpdate
)
1186 DECLARE_RETURN(DWORD
);
1188 DPRINT("Enter NtUserScrollDC\n");
1189 UserEnterExclusive();
1191 RETURN( UserScrollDC(hDC
, dx
, dy
, lprcScroll
, lprcClip
, hrgnUpdate
, lprcUpdate
));
1194 DPRINT("Leave NtUserScrollDC, ret=%i\n",_ret_
);
1201 * NtUserScrollWindowEx
1208 NtUserScrollWindowEx(HWND hWnd
, INT dx
, INT dy
, const RECT
*UnsafeRect
,
1209 const RECT
*UnsafeClipRect
, HRGN hrgnUpdate
, LPRECT rcUpdate
, UINT flags
)
1211 RECT rc
, cliprc
, caretrc
, rect
, clipRect
;
1213 PWINDOW_OBJECT Window
, CaretWnd
;
1217 BOOL bUpdate
= (rcUpdate
|| hrgnUpdate
|| flags
& (SW_INVALIDATE
| SW_ERASE
));
1218 BOOL bOwnRgn
= TRUE
;
1220 DECLARE_RETURN(DWORD
);
1222 DPRINT("Enter NtUserScrollWindowEx\n");
1223 UserEnterExclusive();
1225 Window
= IntGetWindowObject(hWnd
);
1226 if (!Window
|| !IntIsWindowDrawable(Window
))
1228 IntReleaseWindowObject(Window
);
1232 IntGetClientRect(Window
, &rc
);
1233 if (NULL
!= UnsafeRect
)
1235 Status
= MmCopyFromCaller(&rect
, UnsafeRect
, sizeof(RECT
));
1236 if (! NT_SUCCESS(Status
))
1238 SetLastNtError(Status
);
1241 IntGdiIntersectRect(&rc
, &rc
, &rect
);
1244 if (NULL
!= UnsafeClipRect
)
1246 Status
= MmCopyFromCaller(&clipRect
, UnsafeClipRect
, sizeof(RECT
));
1247 if (! NT_SUCCESS(Status
))
1249 SetLastNtError(Status
);
1252 IntGdiIntersectRect(&cliprc
, &rc
, &clipRect
);
1257 if (cliprc
.right
<= cliprc
.left
|| cliprc
.bottom
<= cliprc
.top
||
1258 (dx
== 0 && dy
== 0))
1260 RETURN( NULLREGION
);
1264 hwndCaret
= co_IntFixCaret(hWnd
, &caretrc
, flags
);
1269 hrgnUpdate
= NtGdiCreateRectRgn(0, 0, 0, 0);
1271 hDC
= UserGetDCEx(Window
, 0, DCX_CACHE
| DCX_USESTYLE
);
1274 UserScrollDC(hDC
, dx
, dy
, &rc
, &cliprc
, hrgnUpdate
, rcUpdate
);
1275 UserReleaseDC(Window
, hDC
);
1279 * Take into account the fact that some damage may have occurred during
1283 hrgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
1284 Result
= co_UserGetUpdateRgn(hWnd
, hrgnTemp
, FALSE
);
1285 if (Result
!= NULLREGION
)
1287 HRGN hrgnClip
= UnsafeIntCreateRectRgnIndirect(&cliprc
);
1288 NtGdiOffsetRgn(hrgnTemp
, dx
, dy
);
1289 NtGdiCombineRgn(hrgnTemp
, hrgnTemp
, hrgnClip
, RGN_AND
);
1290 co_UserRedrawWindow(Window
, NULL
, hrgnTemp
, RDW_INVALIDATE
| RDW_ERASE
);
1291 NtGdiDeleteObject(hrgnClip
);
1293 NtGdiDeleteObject(hrgnTemp
);
1295 if (flags
& SW_SCROLLCHILDREN
)
1297 HWND
*List
= IntWinListChildren(Window
);
1303 PWINDOW_OBJECT WindowObject
;
1305 IntGetClientOrigin(hWnd
, &ClientOrigin
);
1306 for (i
= 0; List
[i
]; i
++)
1308 WindowObject
= IntGetWindowObject(List
[i
]);
1309 if (!WindowObject
) continue;
1310 r
= WindowObject
->WindowRect
;
1311 r
.left
-= ClientOrigin
.x
;
1312 r
.top
-= ClientOrigin
.y
;
1313 r
.right
-= ClientOrigin
.x
;
1314 r
.bottom
-= ClientOrigin
.y
;
1315 IntReleaseWindowObject(WindowObject
);
1316 if (! UnsafeRect
|| IntGdiIntersectRect(&dummy
, &r
, &rc
))
1317 co_WinPosSetWindowPos(List
[i
], 0, r
.left
+ dx
, r
.top
+ dy
, 0, 0,
1318 SWP_NOZORDER
| SWP_NOSIZE
| SWP_NOACTIVATE
|
1325 if (flags
& (SW_INVALIDATE
| SW_ERASE
))
1326 co_UserRedrawWindow(Window
, NULL
, hrgnUpdate
, RDW_INVALIDATE
| RDW_ERASE
|
1327 ((flags
& SW_ERASE
) ? RDW_ERASENOW
: 0) |
1328 ((flags
& SW_SCROLLCHILDREN
) ? RDW_ALLCHILDREN
: 0));
1330 if (bOwnRgn
&& hrgnUpdate
)
1331 NtGdiDeleteObject(hrgnUpdate
);
1333 if ((CaretWnd
= IntGetWindowObject(hwndCaret
)))
1335 co_IntSetCaretPos(caretrc
.left
+ dx
, caretrc
.top
+ dy
);
1336 co_UserShowCaret(CaretWnd
);
1337 IntReleaseWindowObject(CaretWnd
);
1340 IntReleaseWindowObject(Window
);
1345 DPRINT("Leave NtUserScrollWindowEx, ret=%i\n",_ret_
);