2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Win32k subsystem
4 * PURPOSE: Window painting function
5 * FILE: win32ss/user/ntuser/painting.c
6 * PROGRAMER: Filip Navara (xnavara@volny.cz)
10 DBG_DEFAULT_CHANNEL(UserPainting
);
12 /* PRIVATE FUNCTIONS **********************************************************/
15 * @name IntIntersectWithParents
17 * Intersect window rectangle with all parent client rectangles.
20 * Pointer to child window to start intersecting from.
22 * Pointer to rectangle that we want to intersect in screen
23 * coordinates on input and intersected rectangle on output (if TRUE
27 * If any parent is minimized or invisible or the resulting rectangle
28 * is empty then FALSE is returned. Otherwise TRUE is returned.
32 IntIntersectWithParents(PWND Child
, RECTL
*WindowRect
)
36 if (Child
->ExStyle
& WS_EX_REDIRECTED
)
39 ParentWnd
= Child
->spwndParent
;
40 while (ParentWnd
!= NULL
)
42 if (!(ParentWnd
->style
& WS_VISIBLE
) ||
43 (ParentWnd
->style
& WS_MINIMIZE
) ||
44 !RECTL_bIntersectRect(WindowRect
, WindowRect
, &ParentWnd
->rcClient
) )
49 if (ParentWnd
->ExStyle
& WS_EX_REDIRECTED
)
52 ParentWnd
= ParentWnd
->spwndParent
;
59 IntValidateParents(PWND Child
, BOOL Recurse
)
61 RECTL ParentRect
, Rect
;
62 BOOL Start
, Ret
= TRUE
;
63 PWND ParentWnd
= Child
;
66 if (ParentWnd
->style
& WS_CHILD
)
69 ParentWnd
= ParentWnd
->spwndParent
;
70 while (ParentWnd
->style
& WS_CHILD
);
73 // No pending nonclient paints.
74 if (!(ParentWnd
->state
& WNDS_SYNCPAINTPENDING
)) Recurse
= FALSE
;
77 ParentWnd
= Child
->spwndParent
;
80 if (ParentWnd
->style
& WS_CLIPCHILDREN
)
83 if (ParentWnd
->hrgnUpdate
!= 0)
90 // Start with child clipping.
95 Rect
= Child
->rcWindow
;
97 if (!IntIntersectWithParents(Child
, &Rect
)) break;
99 Rgn
= IntSysCreateRectpRgnIndirect(&Rect
);
103 PREGION RgnClip
= REGION_LockRgn(Child
->hrgnClip
);
104 IntGdiCombineRgn(Rgn
, Rgn
, RgnClip
, RGN_AND
);
105 REGION_UnlockRgn(RgnClip
);
109 ParentRect
= ParentWnd
->rcWindow
;
111 if (!IntIntersectWithParents(ParentWnd
, &ParentRect
)) break;
113 IntInvalidateWindows( ParentWnd
,
115 RDW_VALIDATE
| RDW_NOCHILDREN
| RDW_NOUPDATEDIRTY
);
117 ParentWnd
= ParentWnd
->spwndParent
;
120 if (Rgn
) REGION_Delete(Rgn
);
126 Synchronize painting to the top-level windows of other threads.
129 IntSendSyncPaint(PWND Wnd
, ULONG Flags
)
131 PTHREADINFO ptiCur
, ptiWnd
;
132 PUSER_SENT_MESSAGE Message
;
136 ptiWnd
= Wnd
->head
.pti
;
137 ptiCur
= PsGetCurrentThreadWin32Thread();
139 Not the current thread, Wnd is in send Nonclient paint also in send erase background and it is visiable.
141 if ( Wnd
->head
.pti
!= ptiCur
&&
142 Wnd
->state
& WNDS_SENDNCPAINT
&&
143 Wnd
->state
& WNDS_SENDERASEBACKGROUND
&&
144 Wnd
->style
& WS_VISIBLE
)
146 // For testing, if you see this, break out the Champagne and have a party!
147 TRACE("SendSyncPaint Wnd in State!\n");
148 if (!IsListEmpty(&ptiWnd
->SentMessagesListHead
))
150 // Scan sent queue messages to see if we received sync paint messages.
151 Entry
= ptiWnd
->SentMessagesListHead
.Flink
;
152 Message
= CONTAINING_RECORD(Entry
, USER_SENT_MESSAGE
, ListEntry
);
156 if (Message
->Msg
.message
== WM_SYNCPAINT
&&
157 Message
->Msg
.hwnd
== UserHMGetHandle(Wnd
))
158 { // Already received so exit out.
159 ERR("SendSyncPaint Found one in the Sent Msg Queue!\n");
163 Entry
= Message
->ListEntry
.Flink
;
164 Message
= CONTAINING_RECORD(Entry
, USER_SENT_MESSAGE
, ListEntry
);
166 while (Entry
!= &ptiWnd
->SentMessagesListHead
);
170 TRACE("Sending WM_SYNCPAINT\n");
171 // This message has no parameters. But it does! Pass Flags along.
172 co_IntSendMessageNoWait(UserHMGetHandle(Wnd
), WM_SYNCPAINT
, Flags
, 0);
173 Wnd
->state
|= WNDS_SYNCPAINTPENDING
;
177 // Send to all the children if this is the desktop window.
178 if ( Wnd
== UserGetDesktopWindow() )
180 if ( Flags
& RDW_ALLCHILDREN
||
181 ( !(Flags
& RDW_NOCHILDREN
) && Wnd
->style
& WS_CLIPCHILDREN
))
183 PWND spwndChild
= Wnd
->spwndChild
;
186 if ( spwndChild
->style
& WS_CHILD
&&
187 spwndChild
->head
.pti
!= ptiCur
)
189 spwndChild
= spwndChild
->spwndNext
;
192 IntSendSyncPaint( spwndChild
, Flags
);
193 spwndChild
= spwndChild
->spwndNext
;
200 * @name IntCalcWindowRgn
202 * Get a window or client region.
206 IntCalcWindowRgn(PWND Wnd
, BOOL Client
)
212 hRgnWindow
= NtGdiCreateRectRgn(
216 Wnd
->rcClient
.bottom
);
220 hRgnWindow
= NtGdiCreateRectRgn(
224 Wnd
->rcWindow
.bottom
);
227 if (Wnd
->hrgnClip
!= NULL
&& !(Wnd
->style
& WS_MINIMIZE
))
229 NtGdiOffsetRgn(hRgnWindow
,
232 NtGdiCombineRgn(hRgnWindow
, hRgnWindow
, Wnd
->hrgnClip
, RGN_AND
);
233 NtGdiOffsetRgn(hRgnWindow
,
242 * @name IntGetNCUpdateRgn
244 * Get non-client update region of a window and optionally validate it.
247 * Pointer to window to get the NC update region from.
249 * Set to TRUE to force validating the NC update region.
252 * Handle to NC update region. The caller is responsible for deleting
257 IntGetNCUpdateRgn(PWND Window
, BOOL Validate
)
261 UINT RgnType
, NcType
;
264 if (Window
->hrgnUpdate
!= NULL
&&
265 Window
->hrgnUpdate
!= HRGN_WINDOW
)
267 hRgnNonClient
= IntCalcWindowRgn(Window
, FALSE
);
270 * If region creation fails it's safe to fallback to whole
273 if (hRgnNonClient
== NULL
)
278 hRgnWindow
= IntCalcWindowRgn(Window
, TRUE
);
279 if (hRgnWindow
== NULL
)
281 GreDeleteObject(hRgnNonClient
);
285 NcType
= IntGdiGetRgnBox(hRgnNonClient
, &update
);
287 RgnType
= NtGdiCombineRgn(hRgnNonClient
, hRgnNonClient
, hRgnWindow
, RGN_DIFF
);
289 if (RgnType
== ERROR
)
291 GreDeleteObject(hRgnWindow
);
292 GreDeleteObject(hRgnNonClient
);
295 else if (RgnType
== NULLREGION
)
297 GreDeleteObject(hRgnWindow
);
298 GreDeleteObject(hRgnNonClient
);
299 Window
->state
&= ~WNDS_UPDATEDIRTY
;
304 * Remove the nonclient region from the standard update region if
305 * we were asked for it.
310 if (NtGdiCombineRgn(Window
->hrgnUpdate
, Window
->hrgnUpdate
, hRgnWindow
, RGN_AND
) == NULLREGION
)
312 IntGdiSetRegionOwner(Window
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
313 GreDeleteObject(Window
->hrgnUpdate
);
314 Window
->state
&= ~WNDS_UPDATEDIRTY
;
315 Window
->hrgnUpdate
= NULL
;
316 if (!(Window
->state
& WNDS_INTERNALPAINT
))
317 MsqDecPaintCountQueue(Window
->head
.pti
);
321 /* check if update rgn contains complete nonclient area */
322 if (NcType
== SIMPLEREGION
)
325 IntGetWindowRect( Window
, &window
);
327 if (IntEqualRect( &window
, &update
))
329 GreDeleteObject(hRgnNonClient
);
330 hRgnNonClient
= HRGN_WINDOW
;
334 GreDeleteObject(hRgnWindow
);
336 return hRgnNonClient
;
340 return Window
->hrgnUpdate
;
345 IntSendNCPaint(PWND pWnd
, HRGN hRgn
)
347 pWnd
->state
&= ~WNDS_SENDNCPAINT
;
349 if ( pWnd
== GetW32ThreadInfo()->MessageQueue
->spwndActive
&&
350 !(pWnd
->state
& WNDS_ACTIVEFRAME
))
352 pWnd
->state
|= WNDS_ACTIVEFRAME
;
353 pWnd
->state
&= ~WNDS_NONCPAINT
;
357 if (pWnd
->state2
& WNDS2_FORCEFULLNCPAINTCLIPRGN
)
359 pWnd
->state2
&= ~WNDS2_FORCEFULLNCPAINTCLIPRGN
;
363 if (hRgn
) co_IntSendMessage(UserHMGetHandle(pWnd
), WM_NCPAINT
, (WPARAM
)hRgn
, 0);
367 IntSendChildNCPaint(PWND pWnd
)
369 pWnd
= pWnd
->spwndChild
;
372 if (pWnd
->hrgnUpdate
== NULL
&& pWnd
->state
& WNDS_SENDNCPAINT
)
374 USER_REFERENCE_ENTRY Ref
;
375 UserRefObjectCo(pWnd
, &Ref
);
376 IntSendNCPaint(pWnd
, HRGN_WINDOW
);
377 UserDerefObjectCo(pWnd
);
379 pWnd
= pWnd
->spwndNext
;
386 * Internal function used by IntRedrawWindow.
390 co_IntPaintWindows(PWND Wnd
, ULONG Flags
, BOOL Recurse
)
393 HWND hWnd
= Wnd
->head
.h
;
394 HRGN TempRegion
= NULL
;
396 Wnd
->state
&= ~WNDS_PAINTNOTPROCESSED
;
398 if (Wnd
->state
& WNDS_SENDNCPAINT
||
399 Wnd
->state
& WNDS_SENDERASEBACKGROUND
)
401 if (!(Wnd
->style
& WS_VISIBLE
))
403 Wnd
->state
&= ~(WNDS_SENDNCPAINT
|WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
408 if (Wnd
->hrgnUpdate
== NULL
)
410 Wnd
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
413 if (Wnd
->head
.pti
== PsGetCurrentThreadWin32Thread())
415 if (Wnd
->state
& WNDS_SENDNCPAINT
)
417 TempRegion
= IntGetNCUpdateRgn(Wnd
, TRUE
);
419 IntSendNCPaint(Wnd
, TempRegion
);
421 if (TempRegion
> HRGN_WINDOW
&& GreIsHandleValid(TempRegion
))
423 /* NOTE: The region can already be deleted! */
424 GreDeleteObject(TempRegion
);
428 if (Wnd
->state
& WNDS_SENDERASEBACKGROUND
)
430 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
433 hDC
= UserGetDCEx( Wnd
,
435 DCX_CACHE
|DCX_USESTYLE
|DCX_INTERSECTRGN
|DCX_KEEPCLIPRGN
);
437 if (Wnd
->head
.pti
->ppi
!= pti
->ppi
)
439 ERR("Sending DC to another Process!!!\n");
442 Wnd
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
443 // Kill the loop, so Clear before we send.
444 if (!co_IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)hDC
, 0))
446 Wnd
->state
|= (WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
448 UserReleaseDC(Wnd
, hDC
, FALSE
);
457 * Check that the window is still valid at this point
459 if (!IntIsWindow(hWnd
))
465 * Paint child windows.
468 if (!(Flags
& RDW_NOCHILDREN
) &&
469 !(Wnd
->style
& WS_MINIMIZE
) &&
470 ( Flags
& RDW_ALLCHILDREN
||
471 (Flags
& RDW_CLIPCHILDREN
&& Wnd
->style
& WS_CLIPCHILDREN
) ) )
474 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
476 if ((List
= IntWinListChildren(Wnd
)))
478 for (phWnd
= List
; *phWnd
; ++phWnd
)
480 if ((Wnd
= UserGetWindowObject(*phWnd
)) == NULL
)
483 if (Wnd
->head
.pti
!= pti
&& Wnd
->style
& WS_CHILD
)
486 if (Wnd
->style
& WS_VISIBLE
)
488 USER_REFERENCE_ENTRY Ref
;
489 UserRefObjectCo(Wnd
, &Ref
);
490 co_IntPaintWindows(Wnd
, Flags
, TRUE
);
491 UserDerefObjectCo(Wnd
);
494 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
502 * Internal function used by IntRedrawWindow, simplecall.
506 co_IntUpdateWindows(PWND Wnd
, ULONG Flags
, BOOL Recurse
)
508 HWND hWnd
= Wnd
->head
.h
;
510 if ( Wnd
->hrgnUpdate
!= NULL
|| Wnd
->state
& WNDS_INTERNALPAINT
)
514 if (!IntValidateParents(Wnd
, Recurse
))
520 if (Wnd
->state
& WNDS_INTERNALPAINT
)
522 Wnd
->state
&= ~WNDS_INTERNALPAINT
;
524 if (Wnd
->hrgnUpdate
== NULL
)
525 MsqDecPaintCountQueue(Wnd
->head
.pti
);
528 Wnd
->state
|= WNDS_PAINTNOTPROCESSED
;
529 Wnd
->state
&= ~WNDS_UPDATEDIRTY
;
531 Wnd
->state2
|= WNDS2_WMPAINTSENT
;
532 co_IntSendMessage(hWnd
, WM_PAINT
, 0, 0);
534 if (Wnd
->state
& WNDS_PAINTNOTPROCESSED
)
536 USER_REFERENCE_ENTRY Ref
;
537 UserRefObjectCo(Wnd
, &Ref
);
538 co_IntPaintWindows(Wnd
, RDW_NOCHILDREN
, FALSE
);
539 UserDerefObjectCo(Wnd
);
543 // Force flags as a toggle. Fixes msg:test_paint_messages:WmChildPaintNc.
544 Flags
= (Flags
& RDW_NOCHILDREN
) ? RDW_NOCHILDREN
: RDW_ALLCHILDREN
; // All children is the default.
547 * Update child windows.
550 if (!(Flags
& RDW_NOCHILDREN
) &&
551 Flags
& RDW_ALLCHILDREN
&&
552 Wnd
!= UserGetDesktopWindow() )
556 for (Child
= Wnd
->spwndChild
; Child
; Child
= Child
->spwndNext
)
558 /* transparent window, check for non-transparent sibling to paint first, then skip it */
559 if ( Child
->ExStyle
& WS_EX_TRANSPARENT
&&
560 ( Child
->hrgnUpdate
!= NULL
|| Child
->state
& WNDS_INTERNALPAINT
) )
562 PWND Next
= Child
->spwndNext
;
565 if ( Next
->hrgnUpdate
!= NULL
|| Next
->state
& WNDS_INTERNALPAINT
) break;
567 Next
= Next
->spwndNext
;
573 if (Child
->style
& WS_VISIBLE
)
575 USER_REFERENCE_ENTRY Ref
;
576 UserRefObjectCo(Child
, &Ref
);
577 co_IntUpdateWindows(Child
, Flags
, TRUE
);
578 UserDerefObjectCo(Child
);
585 UserUpdateWindows(PWND pWnd
, ULONG Flags
)
587 // If transparent and any sibling windows below needs to be painted, leave.
588 if (pWnd
->ExStyle
& WS_EX_TRANSPARENT
)
590 PWND Next
= pWnd
->spwndNext
;
594 if ( Next
->head
.pti
== pWnd
->head
.pti
&&
595 ( Next
->hrgnUpdate
!= NULL
|| Next
->state
& WNDS_INTERNALPAINT
) )
600 Next
= Next
->spwndNext
;
603 co_IntUpdateWindows(pWnd
, Flags
, FALSE
);
607 UserSyncAndPaintWindows(PWND pWnd
, ULONG Flags
)
610 // Find parent, if it needs to be painted, leave.
613 if ((Parent
= Parent
->spwndParent
) == NULL
) break;
614 if ( Parent
->style
& WS_CLIPCHILDREN
) break;
615 if ( Parent
->hrgnUpdate
!= NULL
|| Parent
->state
& WNDS_INTERNALPAINT
) return;
618 IntSendSyncPaint(pWnd
, Flags
);
619 co_IntPaintWindows(pWnd
, Flags
, FALSE
);
623 * IntInvalidateWindows
625 * Internal function used by IntRedrawWindow, UserRedrawDesktop,
626 * co_WinPosSetWindowPos, co_UserRedrawWindow.
629 IntInvalidateWindows(PWND Wnd
, PREGION Rgn
, ULONG Flags
)
631 INT RgnType
= NULLREGION
;
632 BOOL HadPaintMessage
;
634 TRACE("IntInvalidateWindows start Rgn %p\n",Rgn
);
636 if ( Rgn
> PRGN_WINDOW
)
639 * If the nonclient is not to be redrawn, clip the region to the client
642 if ((Flags
& RDW_INVALIDATE
) != 0 && (Flags
& RDW_FRAME
) == 0)
646 RgnClient
= IntSysCreateRectpRgnIndirect(&Wnd
->rcClient
);
649 RgnType
= IntGdiCombineRgn(Rgn
, Rgn
, RgnClient
, RGN_AND
);
650 REGION_Delete(RgnClient
);
655 * Clip the given region with window rectangle (or region)
658 if (!Wnd
->hrgnClip
|| (Wnd
->style
& WS_MINIMIZE
))
660 PREGION RgnWindow
= IntSysCreateRectpRgnIndirect(&Wnd
->rcWindow
);
663 RgnType
= IntGdiCombineRgn(Rgn
, Rgn
, RgnWindow
, RGN_AND
);
664 REGION_Delete(RgnWindow
);
669 PREGION RgnClip
= REGION_LockRgn(Wnd
->hrgnClip
);
672 REGION_bOffsetRgn(Rgn
,
675 RgnType
= IntGdiCombineRgn(Rgn
, Rgn
, RgnClip
, RGN_AND
);
676 REGION_bOffsetRgn(Rgn
,
679 REGION_UnlockRgn(RgnClip
);
685 RgnType
= NULLREGION
;
689 * Save current state of pending updates
692 HadPaintMessage
= IntIsWindowDirty(Wnd
);
695 * Update the region and flags
698 // The following flags are used to invalidate the window.
699 if (Flags
& (RDW_INVALIDATE
|RDW_INTERNALPAINT
|RDW_ERASE
|RDW_FRAME
))
701 if (Flags
& RDW_INTERNALPAINT
)
703 Wnd
->state
|= WNDS_INTERNALPAINT
;
706 if (Flags
& RDW_INVALIDATE
)
710 Wnd
->state
&= ~WNDS_NONCPAINT
;
712 /* If not the same thread set it dirty. */
713 if (Wnd
->head
.pti
!= PsGetCurrentThreadWin32Thread())
715 Wnd
->state
|= WNDS_UPDATEDIRTY
;
716 if (Wnd
->state2
& WNDS2_WMPAINTSENT
)
717 Wnd
->state2
|= WNDS2_ENDPAINTINVALIDATE
;
720 if (Flags
& RDW_FRAME
)
721 Wnd
->state
|= WNDS_SENDNCPAINT
;
723 if (Flags
& RDW_ERASE
)
724 Wnd
->state
|= WNDS_SENDERASEBACKGROUND
;
726 if (RgnType
!= NULLREGION
&& Rgn
> PRGN_WINDOW
)
728 if (Wnd
->hrgnUpdate
== NULL
)
730 Wnd
->hrgnUpdate
= NtGdiCreateRectRgn(0, 0, 0, 0);
731 IntGdiSetRegionOwner(Wnd
->hrgnUpdate
, GDI_OBJ_HMGR_PUBLIC
);
734 if (Wnd
->hrgnUpdate
!= HRGN_WINDOW
)
736 RgnUpdate
= REGION_LockRgn(Wnd
->hrgnUpdate
);
739 RgnType
= IntGdiCombineRgn(RgnUpdate
, RgnUpdate
, Rgn
, RGN_OR
);
740 REGION_UnlockRgn(RgnUpdate
);
741 if (RgnType
== NULLREGION
)
743 IntGdiSetRegionOwner(Wnd
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
744 GreDeleteObject(Wnd
->hrgnUpdate
);
745 Wnd
->hrgnUpdate
= NULL
;
751 Flags
|= RDW_ERASE
|RDW_FRAME
; // For children.
755 if (!HadPaintMessage
&& IntIsWindowDirty(Wnd
))
757 MsqIncPaintCountQueue(Wnd
->head
.pti
);
760 } // The following flags are used to validate the window.
761 else if (Flags
& (RDW_VALIDATE
|RDW_NOINTERNALPAINT
|RDW_NOERASE
|RDW_NOFRAME
))
763 if (Wnd
->state
& WNDS_UPDATEDIRTY
&& !(Flags
& RDW_NOUPDATEDIRTY
))
766 if (Flags
& RDW_NOINTERNALPAINT
)
768 Wnd
->state
&= ~WNDS_INTERNALPAINT
;
771 if (Flags
& RDW_VALIDATE
)
773 if (Flags
& RDW_NOFRAME
)
774 Wnd
->state
&= ~WNDS_SENDNCPAINT
;
776 if (Flags
& RDW_NOERASE
)
777 Wnd
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
779 if (Wnd
->hrgnUpdate
> HRGN_WINDOW
&& RgnType
!= NULLREGION
&& Rgn
> PRGN_WINDOW
)
781 PREGION RgnUpdate
= REGION_LockRgn(Wnd
->hrgnUpdate
);
785 RgnType
= IntGdiCombineRgn(RgnUpdate
, RgnUpdate
, Rgn
, RGN_DIFF
);
786 REGION_UnlockRgn(RgnUpdate
);
788 if (RgnType
== NULLREGION
)
790 IntGdiSetRegionOwner(Wnd
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
791 GreDeleteObject(Wnd
->hrgnUpdate
);
792 Wnd
->hrgnUpdate
= NULL
;
796 // If update is null, do not erase.
797 if (Wnd
->hrgnUpdate
== NULL
)
799 Wnd
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
803 if (HadPaintMessage
&& !IntIsWindowDirty(Wnd
))
805 MsqDecPaintCountQueue(Wnd
->head
.pti
);
810 * Process children if needed
813 if (!(Flags
& RDW_NOCHILDREN
) &&
814 !(Wnd
->style
& WS_MINIMIZE
) &&
815 ((Flags
& RDW_ALLCHILDREN
) || !(Wnd
->style
& WS_CLIPCHILDREN
)))
819 for (Child
= Wnd
->spwndChild
; Child
; Child
= Child
->spwndNext
)
821 if (Child
->style
& WS_VISIBLE
)
824 * Recursive call to update children hrgnUpdate
826 PREGION RgnTemp
= IntSysCreateRectpRgn(0, 0, 0, 0);
829 if (Rgn
> PRGN_WINDOW
) IntGdiCombineRgn(RgnTemp
, Rgn
, 0, RGN_COPY
);
830 IntInvalidateWindows(Child
, ((Rgn
> PRGN_WINDOW
)?RgnTemp
:Rgn
), Flags
);
831 REGION_Delete(RgnTemp
);
836 TRACE("IntInvalidateWindows exit\n");
840 * IntIsWindowDrawable
843 * Window is drawable when it is visible and all parents are not
848 IntIsWindowDrawable(PWND Wnd
)
852 for (WndObject
= Wnd
; WndObject
!= NULL
; WndObject
= WndObject
->spwndParent
)
854 if ( WndObject
->state2
& WNDS2_INDESTROY
||
855 WndObject
->state
& WNDS_DESTROYED
||
857 !(WndObject
->style
& WS_VISIBLE
) ||
858 ((WndObject
->style
& WS_MINIMIZE
) && (WndObject
!= Wnd
)))
870 * Internal version of NtUserRedrawWindow that takes WND as
877 const RECTL
* UpdateRect
,
881 PREGION TmpRgn
= NULL
;
882 TRACE("co_UserRedrawWindow start Rgn %p\n",UpdateRgn
);
886 * Validation of passed parameters.
889 if (!IntIsWindowDrawable(Window
))
891 return TRUE
; // Just do nothing!!!
896 Window
= UserGetDesktopWindow();
901 * Transform the parameters UpdateRgn and UpdateRect into
902 * a region hRgn specified in screen coordinates.
905 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
)) // Both are OKAY!
907 /* We can't hold lock on GDI objects while doing roundtrips to user mode,
908 * so use a copy instead */
911 TmpRgn
= IntSysCreateRectpRgn(0, 0, 0, 0);
913 if (UpdateRgn
> PRGN_WINDOW
)
915 IntGdiCombineRgn(TmpRgn
, UpdateRgn
, NULL
, RGN_COPY
);
918 if (Window
!= UserGetDesktopWindow())
920 REGION_bOffsetRgn(TmpRgn
, Window
->rcClient
.left
, Window
->rcClient
.top
);
925 if (UpdateRect
!= NULL
)
927 if (Window
== UserGetDesktopWindow())
929 TmpRgn
= IntSysCreateRectpRgnIndirect(UpdateRect
);
933 TmpRgn
= IntSysCreateRectpRgn(Window
->rcClient
.left
+ UpdateRect
->left
,
934 Window
->rcClient
.top
+ UpdateRect
->top
,
935 Window
->rcClient
.left
+ UpdateRect
->right
,
936 Window
->rcClient
.top
+ UpdateRect
->bottom
);
941 if ((Flags
& (RDW_INVALIDATE
| RDW_FRAME
)) == (RDW_INVALIDATE
| RDW_FRAME
) ||
942 (Flags
& (RDW_VALIDATE
| RDW_NOFRAME
)) == (RDW_VALIDATE
| RDW_NOFRAME
))
944 if (!RECTL_bIsEmptyRect(&Window
->rcWindow
))
945 TmpRgn
= IntSysCreateRectpRgnIndirect(&Window
->rcWindow
);
949 if (!RECTL_bIsEmptyRect(&Window
->rcClient
))
950 TmpRgn
= IntSysCreateRectpRgnIndirect(&Window
->rcClient
);
956 /* Fixes test RDW_INTERNALPAINT behavior */
959 TmpRgn
= PRGN_WINDOW
; // Need a region so the bits can be set!!!
964 * Adjust the window update region depending on hRgn and flags.
967 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
| RDW_INTERNALPAINT
| RDW_NOINTERNALPAINT
) &&
970 IntInvalidateWindows(Window
, TmpRgn
, Flags
);
975 * Repaint and erase windows if needed.
978 if (Flags
& RDW_UPDATENOW
)
980 UserUpdateWindows(Window
, Flags
);
982 else if (Flags
& RDW_ERASENOW
)
984 if ((Flags
& (RDW_NOCHILDREN
|RDW_ALLCHILDREN
)) == 0)
985 Flags
|= RDW_CLIPCHILDREN
;
987 UserSyncAndPaintWindows(Window
, Flags
);
995 if (TmpRgn
> PRGN_WINDOW
)
997 REGION_Delete(TmpRgn
);
999 TRACE("co_UserRedrawWindow exit\n");
1005 PaintSuspendedWindow(PWND pwnd
, HRGN hrgnOrig
)
1007 if (pwnd
->hrgnUpdate
)
1010 INT Flags
= DC_NC
|DC_NOSENDMSG
;
1016 if (pwnd
->hrgnUpdate
> HRGN_WINDOW
)
1018 hrgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
1019 type
= NtGdiCombineRgn( hrgnTemp
, pwnd
->hrgnUpdate
, 0, RGN_COPY
);
1022 GreDeleteObject(hrgnTemp
);
1023 hrgnTemp
= HRGN_WINDOW
;
1028 hrgnTemp
= GreCreateRectRgnIndirect(&pwnd
->rcWindow
);
1032 hrgnTemp
> HRGN_WINDOW
&&
1033 NtGdiCombineRgn(hrgnTemp
, hrgnTemp
, hrgnOrig
, RGN_AND
) == NULLREGION
)
1035 GreDeleteObject(hrgnTemp
);
1039 hDC
= UserGetDCEx(pwnd
, hrgnTemp
, DCX_WINDOW
|DCX_INTERSECTRGN
|DCX_USESTYLE
|DCX_KEEPCLIPRGN
);
1041 Rect
= pwnd
->rcWindow
;
1042 RECTL_vOffsetRect(&Rect
, -pwnd
->rcWindow
.left
, -pwnd
->rcWindow
.top
);
1044 // Clear out client area!
1045 FillRect(hDC
, &Rect
, IntGetSysColorBrush(COLOR_WINDOW
));
1047 NC_DoNCPaint(pwnd
, hDC
, Flags
); // Redraw without MENUs.
1049 UserReleaseDC(pwnd
, hDC
, FALSE
);
1051 prgn
= REGION_LockRgn(hrgnTemp
);
1052 IntInvalidateWindows(pwnd
, prgn
, RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ALLCHILDREN
);
1053 REGION_UnlockRgn(prgn
);
1055 // Set updates for this window.
1056 pwnd
->state
|= WNDS_SENDNCPAINT
|WNDS_SENDERASEBACKGROUND
|WNDS_UPDATEDIRTY
;
1058 // DCX_KEEPCLIPRGN is set. Check it anyway.
1059 if (hrgnTemp
> HRGN_WINDOW
&& GreIsHandleValid(hrgnTemp
)) GreDeleteObject(hrgnTemp
);
1064 UpdateTheadChildren(PWND pWnd
, HRGN hRgn
)
1066 PaintSuspendedWindow( pWnd
, hRgn
);
1068 if (!(pWnd
->style
& WS_CLIPCHILDREN
))
1071 pWnd
= pWnd
->spwndChild
; // invalidate children if any.
1074 UpdateTheadChildren( pWnd
, hRgn
);
1075 pWnd
= pWnd
->spwndNext
;
1080 UpdateThreadWindows(PWND pWnd
, PTHREADINFO pti
, HRGN hRgn
)
1084 for ( pwndTemp
= pWnd
;
1086 pwndTemp
= pwndTemp
->spwndNext
)
1088 if (pwndTemp
->head
.pti
== pti
)
1090 UserUpdateWindows(pwndTemp
, RDW_ALLCHILDREN
);
1094 if (IsThreadSuspended(pwndTemp
->head
.pti
))
1096 UpdateTheadChildren(pwndTemp
, hRgn
);
1099 UserUpdateWindows(pwndTemp
, RDW_ALLCHILDREN
);
1105 IntIsWindowDirty(PWND Wnd
)
1107 return ( Wnd
->style
& WS_VISIBLE
&&
1108 ( Wnd
->hrgnUpdate
!= NULL
||
1109 Wnd
->state
& WNDS_INTERNALPAINT
) );
1113 Conditions to paint any window:
1115 1. Update region is not null.
1116 2. Internal paint flag is set.
1117 3. Paint count is not zero.
1121 IntFindWindowToRepaint(PWND Window
, PTHREADINFO Thread
)
1126 for (; Window
!= NULL
; Window
= Window
->spwndNext
)
1128 if (IntWndBelongsToThread(Window
, Thread
))
1130 if (IntIsWindowDirty(Window
))
1132 /* Make sure all non-transparent siblings are already drawn. */
1133 if (Window
->ExStyle
& WS_EX_TRANSPARENT
)
1135 for (TempWindow
= Window
->spwndNext
; TempWindow
!= NULL
;
1136 TempWindow
= TempWindow
->spwndNext
)
1138 if (!(TempWindow
->ExStyle
& WS_EX_TRANSPARENT
) &&
1139 IntWndBelongsToThread(TempWindow
, Thread
) &&
1140 IntIsWindowDirty(TempWindow
))
1149 /* find a child of the specified window that needs repainting */
1150 if (Window
->spwndChild
)
1152 hChild
= IntFindWindowToRepaint(Window
->spwndChild
, Thread
);
1161 // Internal painting of windows.
1164 IntPaintWindow( PWND Window
)
1166 // Handle normal painting.
1167 co_IntPaintWindows( Window
, RDW_NOCHILDREN
, FALSE
);
1179 PWND PaintWnd
, StartWnd
;
1181 if ((MsgFilterMin
!= 0 || MsgFilterMax
!= 0) &&
1182 (MsgFilterMin
> WM_PAINT
|| MsgFilterMax
< WM_PAINT
))
1185 if (Thread
->TIF_flags
& TIF_SYSTEMTHREAD
)
1187 ERR("WM_PAINT is in a System Thread!\n");
1190 StartWnd
= UserGetDesktopWindow();
1191 PaintWnd
= IntFindWindowToRepaint(StartWnd
, Thread
);
1193 Message
->hwnd
= PaintWnd
? UserHMGetHandle(PaintWnd
) : NULL
;
1195 if (Message
->hwnd
== NULL
&& Thread
->cPaintsReady
)
1197 // Find note in window.c:"PAINTING BUG".
1198 ERR("WARNING SOMETHING HAS GONE WRONG: Thread marked as containing dirty windows, but no dirty windows found! Counts %u\n",Thread
->cPaintsReady
);
1199 /* Hack to stop spamming the debug log ! */
1200 Thread
->cPaintsReady
= 0;
1204 if (Message
->hwnd
== NULL
)
1207 if (!(Window
== NULL
||
1208 PaintWnd
== Window
||
1209 IntIsChildWindow(Window
, PaintWnd
))) /* check that it is a child of the specified parent */
1212 if (PaintWnd
->state
& WNDS_INTERNALPAINT
)
1214 PaintWnd
->state
&= ~WNDS_INTERNALPAINT
;
1215 if (!PaintWnd
->hrgnUpdate
)
1216 MsqDecPaintCountQueue(Thread
);
1218 PaintWnd
->state2
&= ~WNDS2_STARTPAINT
;
1219 PaintWnd
->state
&= ~WNDS_UPDATEDIRTY
;
1222 while( Window
&& Window
!= UserGetDesktopWindow())
1224 // Role back and check for clip children, do not set if any.
1225 if (Window
->spwndParent
&& !(Window
->spwndParent
->style
& WS_CLIPCHILDREN
))
1227 PaintWnd
->state2
|= WNDS2_WMPAINTSENT
;
1229 Window
= Window
->spwndParent
;
1232 Message
->wParam
= Message
->lParam
= 0;
1233 Message
->message
= WM_PAINT
;
1245 INT cx
, cy
, xSrc
, ySrc
;
1247 if ( nFlags
& PW_CLIENTONLY
)
1249 cx
= pwnd
->rcClient
.right
- pwnd
->rcClient
.left
;
1250 cy
= pwnd
->rcClient
.bottom
- pwnd
->rcClient
.top
;
1251 xSrc
= pwnd
->rcClient
.left
- pwnd
->rcWindow
.left
;
1252 ySrc
= pwnd
->rcClient
.top
- pwnd
->rcWindow
.top
;
1256 cx
= pwnd
->rcWindow
.right
- pwnd
->rcWindow
.left
;
1257 cy
= pwnd
->rcWindow
.bottom
- pwnd
->rcWindow
.top
;
1262 // TODO: Setup Redirection for Print.
1265 /* Update the window just incase. */
1266 co_IntUpdateWindows( pwnd
, RDW_ALLCHILDREN
, FALSE
);
1268 hdcSrc
= UserGetDCEx( pwnd
, NULL
, DCX_CACHE
|DCX_WINDOW
);
1269 /* Print window to printer context. */
1270 NtGdiBitBlt( hdcBlt
,
1282 UserReleaseDC( pwnd
, hdcSrc
, FALSE
);
1284 // TODO: Release Redirection from Print.
1291 IntFlashWindowEx(PWND pWnd
, PFLASHWINFO pfwi
)
1294 UINT uCount
= pfwi
->uCount
;
1295 BOOL Activate
= FALSE
, Ret
= FALSE
;
1299 FlashState
= (DWORD
)UserGetProp(pWnd
, AtomFlashWndState
, TRUE
);
1301 if (FlashState
== FLASHW_FINISHED
)
1303 // Cycle has finished, kill timer and set this to Stop.
1304 FlashState
|= FLASHW_KILLSYSTIMER
;
1305 pfwi
->dwFlags
= FLASHW_STOP
;
1311 if (pfwi
->dwFlags
== FLASHW_SYSTIMER
)
1313 // Called from system timer, restore flags, counts and state.
1314 pfwi
->dwFlags
= LOWORD(FlashState
);
1315 uCount
= HIWORD(FlashState
);
1316 FlashState
= MAKELONG(LOWORD(FlashState
),0);
1320 // Clean out the trash! Fix SeaMonkey crash after restart.
1325 if (FlashState
== 0)
1326 { // First time in cycle, setup flash state.
1327 if ( pWnd
->state
& WNDS_ACTIVEFRAME
||
1328 (pfwi
->dwFlags
& FLASHW_CAPTION
&& pWnd
->style
& (WS_BORDER
|WS_DLGFRAME
)))
1330 FlashState
= FLASHW_STARTED
|FLASHW_ACTIVE
;
1334 // Set previous window state.
1335 Ret
= !!(FlashState
& FLASHW_ACTIVE
);
1337 if ( (pfwi
->dwFlags
& FLASHW_TIMERNOFG
) == FLASHW_TIMERNOFG
&&
1338 gpqForeground
== pWnd
->head
.pti
->MessageQueue
)
1340 // Flashing until foreground, set this to Stop.
1341 pfwi
->dwFlags
= FLASHW_STOP
;
1345 // Toggle activate flag.
1346 if ( pfwi
->dwFlags
== FLASHW_STOP
)
1348 if (gpqForeground
&& gpqForeground
->spwndActive
== pWnd
)
1355 Activate
= (FlashState
& FLASHW_ACTIVE
) == 0;
1358 if ( pfwi
->dwFlags
== FLASHW_STOP
|| pfwi
->dwFlags
& FLASHW_CAPTION
)
1360 co_IntSendMessage(UserHMGetHandle(pWnd
), WM_NCACTIVATE
, Activate
, 0);
1363 // FIXME: Check for a Stop Sign here.
1364 if ( pfwi
->dwFlags
& FLASHW_TRAY
)
1366 // Need some shell work here too.
1367 TRACE("FIXME: Flash window no Tray support!\n");
1370 if ( pfwi
->dwFlags
== FLASHW_STOP
)
1372 if (FlashState
& FLASHW_KILLSYSTIMER
)
1374 IntKillTimer(pWnd
, ID_EVENT_SYSTIMER_FLASHWIN
, TRUE
);
1377 UserRemoveProp(pWnd
, AtomFlashWndState
, TRUE
);
1380 { // Have a count and started, set timer.
1383 FlashState
|= FLASHW_COUNT
;
1385 if (!(Activate
^ !!(FlashState
& FLASHW_STARTED
)))
1388 if (!(FlashState
& FLASHW_KILLSYSTIMER
))
1389 pfwi
->dwFlags
|= FLASHW_TIMER
;
1392 if (pfwi
->dwFlags
& FLASHW_TIMER
)
1394 FlashState
|= FLASHW_KILLSYSTIMER
;
1397 ID_EVENT_SYSTIMER_FLASHWIN
,
1398 pfwi
->dwTimeout
? pfwi
->dwTimeout
: gpsi
->dtCaretBlink
,
1403 if (FlashState
& FLASHW_COUNT
&& uCount
== 0)
1405 // Keep spinning? Nothing else to do.
1406 FlashState
= FLASHW_FINISHED
;
1410 // Save state and flags so this can be restored next time through.
1411 FlashState
^= (FlashState
^ -!!(Activate
)) & FLASHW_ACTIVE
;
1412 FlashState
^= (FlashState
^ pfwi
->dwFlags
) & (FLASHW_MASK
& ~FLASHW_TIMER
);
1414 FlashState
= MAKELONG(LOWORD(FlashState
),uCount
);
1415 UserSetProp(pWnd
, AtomFlashWndState
, (HANDLE
)FlashState
, TRUE
);
1421 IntBeginPaint(PWND Window
, PPAINTSTRUCT Ps
)
1427 co_UserHideCaret(Window
);
1429 Window
->state2
|= WNDS2_STARTPAINT
;
1430 Window
->state
&= ~WNDS_PAINTNOTPROCESSED
;
1432 if (Window
->state
& WNDS_SENDNCPAINT
)
1435 // Application can keep update dirty.
1438 Window
->state
&= ~WNDS_UPDATEDIRTY
;
1439 hRgn
= IntGetNCUpdateRgn(Window
, FALSE
);
1440 IntSendNCPaint(Window
, hRgn
);
1441 if (hRgn
> HRGN_WINDOW
&& GreIsHandleValid(hRgn
))
1443 /* NOTE: The region can already be deleted! */
1444 GreDeleteObject(hRgn
);
1447 while(Window
->state
& WNDS_UPDATEDIRTY
);
1451 Window
->state
&= ~WNDS_UPDATEDIRTY
;
1454 RtlZeroMemory(Ps
, sizeof(PAINTSTRUCT
));
1456 if (Window
->state2
& WNDS2_ENDPAINTINVALIDATE
)
1458 ERR("BP: Another thread invalidated this window\n");
1461 Ps
->hdc
= UserGetDCEx( Window
,
1463 DCX_INTERSECTRGN
| DCX_USESTYLE
);
1469 // If set, always clear flags out due to the conditions later on for sending the message.
1470 if (Window
->state
& WNDS_SENDERASEBACKGROUND
)
1472 Window
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
1476 if (Window
->hrgnUpdate
!= NULL
)
1478 MsqDecPaintCountQueue(Window
->head
.pti
);
1479 IntGdiSetRegionOwner(Window
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
1480 /* The region is part of the dc now and belongs to the process! */
1481 Window
->hrgnUpdate
= NULL
;
1485 if (Window
->state
& WNDS_INTERNALPAINT
)
1486 MsqDecPaintCountQueue(Window
->head
.pti
);
1489 type
= GdiGetClipBox(Ps
->hdc
, &Ps
->rcPaint
);
1491 IntGetClientRect(Window
, &Rect
);
1493 Window
->state
&= ~WNDS_INTERNALPAINT
;
1495 if ( Erase
&& // Set to erase,
1496 type
!= NULLREGION
&& // don't erase if the clip box is empty,
1497 (!(Window
->pcls
->style
& CS_PARENTDC
) || // not parent dc or
1498 RECTL_bIntersectRect( &Rect
, &Rect
, &Ps
->rcPaint
) ) ) // intersecting.
1500 Ps
->fErase
= !co_IntSendMessage(UserHMGetHandle(Window
), WM_ERASEBKGND
, (WPARAM
)Ps
->hdc
, 0);
1503 Window
->state
|= (WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
1511 IntSendChildNCPaint(Window
);
1517 IntEndPaint(PWND Wnd
, PPAINTSTRUCT Ps
)
1523 UserReleaseDC(Wnd
, hdc
, TRUE
);
1525 if (Wnd
->state2
& WNDS2_ENDPAINTINVALIDATE
)
1527 ERR("EP: Another thread invalidated this window\n");
1528 Wnd
->state2
&= ~WNDS2_ENDPAINTINVALIDATE
;
1531 Wnd
->state2
&= ~(WNDS2_WMPAINTSENT
|WNDS2_STARTPAINT
);
1533 co_UserShowCaret(Wnd
);
1538 /* PUBLIC FUNCTIONS ***********************************************************/
1548 NtUserBeginPaint(HWND hWnd
, PAINTSTRUCT
* UnsafePs
)
1554 USER_REFERENCE_ENTRY Ref
;
1555 DECLARE_RETURN(HDC
);
1557 TRACE("Enter NtUserBeginPaint\n");
1558 UserEnterExclusive();
1560 if (!(Window
= UserGetWindowObject(hWnd
)))
1565 UserRefObjectCo(Window
, &Ref
);
1567 hDC
= IntBeginPaint(Window
, &Ps
);
1569 Status
= MmCopyToCaller(UnsafePs
, &Ps
, sizeof(PAINTSTRUCT
));
1570 if (! NT_SUCCESS(Status
))
1572 SetLastNtError(Status
);
1579 if (Window
) UserDerefObjectCo(Window
);
1581 TRACE("Leave NtUserBeginPaint, ret=%p\n",_ret_
);
1595 NtUserEndPaint(HWND hWnd
, CONST PAINTSTRUCT
* pUnsafePs
)
1597 NTSTATUS Status
= STATUS_SUCCESS
;
1600 USER_REFERENCE_ENTRY Ref
;
1601 DECLARE_RETURN(BOOL
);
1603 TRACE("Enter NtUserEndPaint\n");
1604 UserEnterExclusive();
1606 if (!(Window
= UserGetWindowObject(hWnd
)))
1611 UserRefObjectCo(Window
, &Ref
); // Here for the exception.
1615 ProbeForRead(pUnsafePs
, sizeof(*pUnsafePs
), 1);
1616 RtlCopyMemory(&Ps
, pUnsafePs
, sizeof(PAINTSTRUCT
));
1618 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1620 Status
= _SEH2_GetExceptionCode();
1623 if (!NT_SUCCESS(Status
))
1628 RETURN(IntEndPaint(Window
, &Ps
));
1631 if (Window
) UserDerefObjectCo(Window
);
1633 TRACE("Leave NtUserEndPaint, ret=%i\n",_ret_
);
1642 NtUserFlashWindowEx(IN PFLASHWINFO pfwi
)
1645 FLASHWINFO finfo
= {0};
1648 UserEnterExclusive();
1652 ProbeForRead(pfwi
, sizeof(FLASHWINFO
), 1);
1653 RtlCopyMemory(&finfo
, pfwi
, sizeof(FLASHWINFO
));
1655 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1657 SetLastNtError(_SEH2_GetExceptionCode());
1658 _SEH2_YIELD(goto Exit
);
1662 if (!( pWnd
= ValidateHwndNoErr(finfo
.hwnd
)) ||
1663 finfo
.cbSize
!= sizeof(FLASHWINFO
) ||
1664 finfo
.dwFlags
& ~(FLASHW_ALL
|FLASHW_TIMER
|FLASHW_TIMERNOFG
) )
1666 EngSetLastError(ERROR_INVALID_PARAMETER
);
1670 Ret
= IntFlashWindowEx(pWnd
, &finfo
);
1678 GetUpdateRgn, this fails the same as the old one.
1681 co_UserGetUpdateRgn(PWND Window
, HRGN hRgn
, BOOL bErase
)
1687 ASSERT_REFS_CO(Window
);
1691 USER_REFERENCE_ENTRY Ref
;
1692 UserRefObjectCo(Window
, &Ref
);
1693 co_IntPaintWindows(Window
, RDW_NOCHILDREN
, FALSE
);
1694 UserDerefObjectCo(Window
);
1697 Window
->state
&= ~WNDS_UPDATEDIRTY
;
1699 if (Window
->hrgnUpdate
== NULL
)
1701 NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0);
1705 Rect
= Window
->rcClient
;
1706 Type
= IntIntersectWithParents(Window
, &Rect
);
1708 if (Window
->hrgnUpdate
== HRGN_WINDOW
)
1711 ERR("GURn: Caller is passing Window Region 1\n");
1714 NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0);
1718 RegionType
= SIMPLEREGION
;
1720 if (Window
!= UserGetDesktopWindow()) // Window->fnid == FNID_DESKTOP
1722 RECTL_vOffsetRect(&Rect
,
1723 -Window
->rcClient
.left
,
1724 -Window
->rcClient
.top
);
1726 GreSetRectRgnIndirect(hRgn
, &Rect
);
1730 HRGN hrgnTemp
= GreCreateRectRgnIndirect(&Rect
);
1732 RegionType
= NtGdiCombineRgn(hRgn
, hrgnTemp
, Window
->hrgnUpdate
, RGN_AND
);
1734 if (RegionType
== ERROR
|| RegionType
== NULLREGION
)
1736 if (hrgnTemp
) GreDeleteObject(hrgnTemp
);
1737 NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0);
1741 if (Window
!= UserGetDesktopWindow()) // Window->fnid == FNID_DESKTOP
1743 NtGdiOffsetRgn(hRgn
,
1744 -Window
->rcClient
.left
,
1745 -Window
->rcClient
.top
);
1747 if (hrgnTemp
) GreDeleteObject(hrgnTemp
);
1753 co_UserGetUpdateRect(PWND Window
, PRECT pRect
, BOOL bErase
)
1760 USER_REFERENCE_ENTRY Ref
;
1761 UserRefObjectCo(Window
, &Ref
);
1762 co_IntPaintWindows(Window
, RDW_NOCHILDREN
, FALSE
);
1763 UserDerefObjectCo(Window
);
1766 Window
->state
&= ~WNDS_UPDATEDIRTY
;
1768 if (Window
->hrgnUpdate
== NULL
)
1770 pRect
->left
= pRect
->top
= pRect
->right
= pRect
->bottom
= 0;
1775 /* Get the update region bounding box. */
1776 if (Window
->hrgnUpdate
== HRGN_WINDOW
)
1778 *pRect
= Window
->rcClient
;
1779 ERR("GURt: Caller is retrieving Window Region 1\n");
1783 RegionType
= IntGdiGetRgnBox(Window
->hrgnUpdate
, pRect
);
1785 if (RegionType
!= ERROR
&& RegionType
!= NULLREGION
)
1786 RECTL_bIntersectRect(pRect
, pRect
, &Window
->rcClient
);
1789 if (IntIntersectWithParents(Window
, pRect
))
1791 if (Window
!= UserGetDesktopWindow()) // Window->fnid == FNID_DESKTOP
1793 RECTL_vOffsetRect(pRect
,
1794 -Window
->rcClient
.left
,
1795 -Window
->rcClient
.top
);
1797 if (Window
->pcls
->style
& CS_OWNDC
)
1801 hdc
= UserGetDCEx(Window
, NULL
, DCX_USESTYLE
);
1802 //layout = NtGdiSetLayout(hdc, -1, 0);
1803 //IntMapWindowPoints( 0, Window, (LPPOINT)pRect, 2 );
1804 GreDPtoLP( hdc
, (LPPOINT
)pRect
, 2 );
1805 //NtGdiSetLayout(hdc, -1, layout);
1806 UserReleaseDC(Window
, hdc
, FALSE
);
1811 pRect
->left
= pRect
->top
= pRect
->right
= pRect
->bottom
= 0;
1818 * NtUserGetUpdateRgn
1825 NtUserGetUpdateRgn(HWND hWnd
, HRGN hRgn
, BOOL bErase
)
1827 DECLARE_RETURN(INT
);
1831 TRACE("Enter NtUserGetUpdateRgn\n");
1832 UserEnterExclusive();
1834 if (!(Window
= UserGetWindowObject(hWnd
)))
1839 ret
= co_UserGetUpdateRgn(Window
, hRgn
, bErase
);
1844 TRACE("Leave NtUserGetUpdateRgn, ret=%i\n",_ret_
);
1850 * NtUserGetUpdateRect
1857 NtUserGetUpdateRect(HWND hWnd
, LPRECT UnsafeRect
, BOOL bErase
)
1863 DECLARE_RETURN(BOOL
);
1865 TRACE("Enter NtUserGetUpdateRect\n");
1866 UserEnterExclusive();
1868 if (!(Window
= UserGetWindowObject(hWnd
)))
1873 Ret
= co_UserGetUpdateRect(Window
, &Rect
, bErase
);
1875 if (UnsafeRect
!= NULL
)
1877 Status
= MmCopyToCaller(UnsafeRect
, &Rect
, sizeof(RECTL
));
1878 if (!NT_SUCCESS(Status
))
1880 EngSetLastError(ERROR_INVALID_PARAMETER
);
1888 TRACE("Leave NtUserGetUpdateRect, ret=%i\n",_ret_
);
1894 * NtUserRedrawWindow
1903 CONST RECT
*lprcUpdate
,
1907 RECTL SafeUpdateRect
;
1910 USER_REFERENCE_ENTRY Ref
;
1911 NTSTATUS Status
= STATUS_SUCCESS
;
1912 PREGION RgnUpdate
= NULL
;
1913 DECLARE_RETURN(BOOL
);
1915 TRACE("Enter NtUserRedrawWindow\n");
1916 UserEnterExclusive();
1918 if (!(Wnd
= UserGetWindowObject(hWnd
? hWnd
: IntGetDesktopWindow())))
1927 ProbeForRead(lprcUpdate
, sizeof(RECTL
), 1);
1928 RtlCopyMemory(&SafeUpdateRect
, lprcUpdate
, sizeof(RECTL
));
1930 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1932 Status
= _SEH2_GetExceptionCode();
1935 if (!NT_SUCCESS(Status
))
1937 EngSetLastError(RtlNtStatusToDosError(Status
));
1942 if ( flags
& ~(RDW_ERASE
|RDW_FRAME
|RDW_INTERNALPAINT
|RDW_INVALIDATE
|
1943 RDW_NOERASE
|RDW_NOFRAME
|RDW_NOINTERNALPAINT
|RDW_VALIDATE
|
1944 RDW_ERASENOW
|RDW_UPDATENOW
|RDW_ALLCHILDREN
|RDW_NOCHILDREN
) )
1946 /* RedrawWindow fails only in case that flags are invalid */
1947 EngSetLastError(ERROR_INVALID_FLAGS
);
1951 /* We can't hold lock on GDI objects while doing roundtrips to user mode,
1952 * so it will be copied.
1954 if (hrgnUpdate
> HRGN_WINDOW
)
1956 RgnUpdate
= REGION_LockRgn(hrgnUpdate
);
1959 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1962 REGION_UnlockRgn(RgnUpdate
);
1964 else if (hrgnUpdate
== HRGN_WINDOW
) // Trap it out.
1966 ERR("NTRW: Caller is passing Window Region 1\n");
1969 UserRefObjectCo(Wnd
, &Ref
);
1971 Ret
= co_UserRedrawWindow( Wnd
,
1972 lprcUpdate
? &SafeUpdateRect
: NULL
,
1976 UserDerefObjectCo(Wnd
);
1981 TRACE("Leave NtUserRedrawWindow, ret=%i\n",_ret_
);
1987 UserDrawCaptionText(
1990 const PUNICODE_STRING Text
,
1995 HFONT hOldFont
= NULL
;
1996 COLORREF OldTextColor
;
1997 NONCLIENTMETRICSW nclm
;
1999 BOOLEAN bDeleteFont
= FALSE
;
2002 ULONG fit
= 0, Length
;
2005 TRACE("UserDrawCaptionText: %wZ\n", Text
);
2007 nclm
.cbSize
= sizeof(nclm
);
2008 if (!UserSystemParametersInfo(SPI_GETNONCLIENTMETRICS
, nclm
.cbSize
, &nclm
, 0))
2010 ERR("UserSystemParametersInfo() failed!\n");
2016 if(uFlags
& DC_SMALLCAP
)
2017 Status
= TextIntCreateFontIndirect(&nclm
.lfSmCaptionFont
, &hFont
);
2019 Status
= TextIntCreateFontIndirect(&nclm
.lfCaptionFont
, &hFont
);
2021 if(!NT_SUCCESS(Status
))
2023 ERR("TextIntCreateFontIndirect() failed! Status: 0x%x\n", Status
);
2030 IntGdiSetBkMode(hDc
, TRANSPARENT
);
2032 hOldFont
= NtGdiSelectFont(hDc
, hFont
);
2034 if(uFlags
& DC_INBUTTON
)
2035 OldTextColor
= IntGdiSetTextColor(hDc
, IntGetSysColor(COLOR_BTNTEXT
));
2037 OldTextColor
= IntGdiSetTextColor(hDc
,
2038 IntGetSysColor(uFlags
& DC_ACTIVE
? COLOR_CAPTIONTEXT
: COLOR_INACTIVECAPTIONTEXT
));
2040 // Adjust for system menu.
2041 if (pWnd
&& pWnd
->style
& WS_SYSMENU
)
2043 r
.right
-= UserGetSystemMetrics(SM_CYCAPTION
) - 1;
2044 if ((pWnd
->style
& (WS_MAXIMIZEBOX
| WS_MINIMIZEBOX
)) && !(pWnd
->ExStyle
& WS_EX_TOOLWINDOW
))
2046 r
.right
-= UserGetSystemMetrics(SM_CXSIZE
) + 1;
2047 r
.right
-= UserGetSystemMetrics(SM_CXSIZE
) + 1;
2051 GreGetTextExtentExW(hDc
, Text
->Buffer
, Text
->Length
/sizeof(WCHAR
), r
.right
- r
.left
, &fit
, 0, &Size
, 0);
2053 Length
= (Text
->Length
/sizeof(WCHAR
) == fit
? fit
: fit
+1);
2055 if (Text
->Length
/sizeof(WCHAR
) > Length
)
2061 { // Faster while in setup.
2062 GreExtTextOutW( hDc
,
2064 lpRc
->top
+ (lpRc
->bottom
- lpRc
->top
) / 2 - Size
.cy
/ 2, // DT_SINGLELINE && DT_VCENTER
2076 Text
->Length
/sizeof(WCHAR
),
2078 DT_END_ELLIPSIS
|DT_SINGLELINE
|DT_VCENTER
|DT_NOPREFIX
|DT_LEFT
);
2081 IntGdiSetTextColor(hDc
, OldTextColor
);
2084 NtGdiSelectFont(hDc
, hOldFont
);
2087 GreDeleteObject(hFont
);
2093 // This draws Buttons, Icons and Text...
2095 BOOL
UserDrawCaption(
2101 const PUNICODE_STRING Str
,
2105 HBRUSH hBgBrush
, hOldBrush
= NULL
;
2109 RECTL_vMakeWellOrdered(lpRc
);
2111 /* Determine whether the icon needs to be displayed */
2112 if (!hIcon
&& pWnd
!= NULL
)
2114 HasIcon
= (uFlags
& DC_ICON
) && !(uFlags
& DC_SMALLCAP
) &&
2115 (pWnd
->style
& WS_SYSMENU
) && !(pWnd
->ExStyle
& WS_EX_TOOLWINDOW
);
2118 HasIcon
= (hIcon
!= NULL
);
2120 // Draw the caption background
2121 if((uFlags
& DC_GRADIENT
) && !(uFlags
& DC_INBUTTON
))
2123 static GRADIENT_RECT gcap
= {0, 1};
2124 TRIVERTEX Vertices
[2];
2127 Colors
[0] = IntGetSysColor((uFlags
& DC_ACTIVE
) ?
2128 COLOR_ACTIVECAPTION
: COLOR_INACTIVECAPTION
);
2130 Colors
[1] = IntGetSysColor((uFlags
& DC_ACTIVE
) ?
2131 COLOR_GRADIENTACTIVECAPTION
: COLOR_GRADIENTINACTIVECAPTION
);
2133 Vertices
[0].x
= Rect
.left
;
2134 Vertices
[0].y
= Rect
.top
;
2135 Vertices
[0].Red
= (WORD
)Colors
[0]<<8;
2136 Vertices
[0].Green
= (WORD
)Colors
[0] & 0xFF00;
2137 Vertices
[0].Blue
= (WORD
)(Colors
[0]>>8) & 0xFF00;
2138 Vertices
[0].Alpha
= 0;
2140 Vertices
[1].x
= Rect
.right
;
2141 Vertices
[1].y
= Rect
.bottom
;
2142 Vertices
[1].Red
= (WORD
)Colors
[1]<<8;
2143 Vertices
[1].Green
= (WORD
)Colors
[1] & 0xFF00;
2144 Vertices
[1].Blue
= (WORD
)(Colors
[1]>>8) & 0xFF00;
2145 Vertices
[1].Alpha
= 0;
2147 if(!GreGradientFill(hDc
, Vertices
, 2, &gcap
, 1, GRADIENT_FILL_RECT_H
))
2149 ERR("GreGradientFill() failed!\n");
2155 if(uFlags
& DC_INBUTTON
)
2156 hBgBrush
= IntGetSysColorBrush(COLOR_3DFACE
);
2157 else if(uFlags
& DC_ACTIVE
)
2158 hBgBrush
= IntGetSysColorBrush(COLOR_ACTIVECAPTION
);
2160 hBgBrush
= IntGetSysColorBrush(COLOR_INACTIVECAPTION
);
2162 hOldBrush
= NtGdiSelectBrush(hDc
, hBgBrush
);
2166 ERR("NtGdiSelectBrush() failed!\n");
2170 if(!NtGdiPatBlt(hDc
, Rect
.left
, Rect
.top
,
2171 Rect
.right
- Rect
.left
,
2172 Rect
.bottom
- Rect
.top
,
2175 ERR("NtGdiPatBlt() failed!\n");
2183 PCURICON_OBJECT pIcon
= NULL
;
2187 pIcon
= UserGetCurIconObject(hIcon
);
2191 pIcon
= NC_IconForWindow(pWnd
);
2192 // FIXME: NC_IconForWindow should reference it for us */
2194 UserReferenceObject(pIcon
);
2199 LONG cx
= UserGetSystemMetrics(SM_CXSMICON
);
2200 LONG cy
= UserGetSystemMetrics(SM_CYSMICON
);
2201 LONG x
= Rect
.left
- cx
/2 + 1 + (Rect
.bottom
- Rect
.top
)/2; // this is really what Window does
2202 LONG y
= (Rect
.top
+ Rect
.bottom
- cy
)/2; // center
2203 UserDrawIconEx(hDc
, x
, y
, pIcon
, cx
, cy
, 0, NULL
, DI_NORMAL
);
2204 UserDereferenceObject(pIcon
);
2213 Rect
.left
+= Rect
.bottom
- Rect
.top
;
2215 if((uFlags
& DC_TEXT
))
2221 Set
= UserDrawCaptionText(pWnd
, hDc
, Str
, &Rect
, uFlags
, hFont
);
2222 else if (pWnd
!= NULL
) // FIXME: Windows does not do that
2224 UNICODE_STRING ustr
;
2225 ustr
.Buffer
= pWnd
->strName
.Buffer
; // FIXME: LARGE_STRING truncated!
2226 ustr
.Length
= (USHORT
)min(pWnd
->strName
.Length
, MAXUSHORT
);
2227 ustr
.MaximumLength
= (USHORT
)min(pWnd
->strName
.MaximumLength
, MAXUSHORT
);
2228 Set
= UserDrawCaptionText(pWnd
, hDc
, &ustr
, &Rect
, uFlags
, hFont
);
2233 pWnd
->state2
&= ~WNDS2_CAPTIONTEXTTRUNCATED
;
2235 pWnd
->state2
|= WNDS2_CAPTIONTEXTTRUNCATED
;
2242 if (hOldBrush
) NtGdiSelectBrush(hDc
, hOldBrush
);
2249 UserRealizePalette(HDC hdc
)
2251 HWND hWnd
, hWndDesktop
;
2254 Ret
= IntGdiRealizePalette(hdc
);
2255 if (Ret
) // There was a change.
2257 hWnd
= IntWindowFromDC(hdc
);
2258 if (hWnd
) // Send broadcast if dc is associated with a window.
2259 { // FYI: Thread locked in CallOneParam.
2260 hWndDesktop
= IntGetDesktopWindow();
2261 if ( hWndDesktop
!= hWnd
)
2263 PWND pWnd
= UserGetWindowObject(hWndDesktop
);
2264 ERR("RealizePalette Desktop.");
2265 hdc
= UserGetWindowDC(pWnd
);
2266 IntPaintDesktop(hdc
);
2267 UserReleaseDC(pWnd
,hdc
,FALSE
);
2269 UserSendNotifyMessage((HWND
)HWND_BROADCAST
, WM_PALETTECHANGED
, (WPARAM
)hWnd
, 0);
2277 NtUserDrawCaptionTemp(
2283 const PUNICODE_STRING str
,
2287 UNICODE_STRING SafeStr
= {0};
2288 NTSTATUS Status
= STATUS_SUCCESS
;
2292 UserEnterExclusive();
2296 if(!(pWnd
= UserGetWindowObject(hWnd
)))
2305 ProbeForRead(lpRc
, sizeof(RECTL
), sizeof(ULONG
));
2306 RtlCopyMemory(&SafeRect
, lpRc
, sizeof(RECTL
));
2309 SafeStr
= ProbeForReadUnicodeString(str
);
2310 if (SafeStr
.Length
!= 0)
2312 ProbeForRead( SafeStr
.Buffer
,
2318 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2320 Status
= _SEH2_GetExceptionCode();
2324 if (Status
!= STATUS_SUCCESS
)
2326 SetLastNtError(Status
);
2332 Ret
= UserDrawCaption(pWnd
, hDC
, &SafeRect
, hFont
, hIcon
, &SafeStr
, uFlags
);
2335 if ( RECTL_bIsEmptyRect(&SafeRect
) && hFont
== 0 && hIcon
== 0 )
2338 if (uFlags
& DC_DRAWCAPTIONMD
)
2340 ERR("NC Caption Mode\n");
2341 UserDrawCaptionBar(pWnd
, hDC
, uFlags
);
2344 else if (uFlags
& DC_DRAWFRAMEMD
)
2346 ERR("NC Paint Mode\n");
2347 NC_DoNCPaint(pWnd
, hDC
, uFlags
); // Update Menus too!
2351 Ret
= UserDrawCaption(pWnd
, hDC
, &SafeRect
, hFont
, hIcon
, NULL
, uFlags
);
2360 NtUserDrawCaption(HWND hWnd
,
2365 return NtUserDrawCaptionTemp(hWnd
, hDC
, lpRc
, 0, 0, NULL
, uFlags
);
2370 NtUserInvalidateRect(
2372 CONST RECT
*lpUnsafeRect
,
2375 UINT flags
= RDW_INVALIDATE
| (bErase
? RDW_ERASE
: 0);
2378 flags
= RDW_ALLCHILDREN
| RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ERASENOW
;
2379 lpUnsafeRect
= NULL
;
2381 return NtUserRedrawWindow(hWnd
, lpUnsafeRect
, NULL
, flags
);
2386 NtUserInvalidateRgn(
2393 EngSetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2396 return NtUserRedrawWindow(hWnd
, NULL
, hRgn
, RDW_INVALIDATE
| (bErase
? RDW_ERASE
: 0));
2409 UserEnterExclusive();
2413 if (!(Window
= UserGetWindowObject(hwnd
)) || // FIXME:
2414 Window
== UserGetDesktopWindow() || // pWnd->fnid == FNID_DESKTOP
2415 Window
== UserGetMessageWindow() ) // pWnd->fnid == FNID_MESSAGEWND
2422 /* Validate flags and check it as a mask for 0 or 1. */
2423 if ( (nFlags
& PW_CLIENTONLY
) == nFlags
)
2424 Ret
= IntPrintWindow( Window
, hdcBlt
, nFlags
);
2426 EngSetLastError(ERROR_INVALID_PARAMETER
);
2434 /* ValidateRect gets redirected to NtUserValidateRect:
2435 http://blog.csdn.net/ntdll/archive/2005/10/19/509299.aspx */
2442 UINT flags
= RDW_VALIDATE
;
2445 flags
= RDW_ALLCHILDREN
| RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ERASENOW
;
2448 return NtUserRedrawWindow(hWnd
, lpRect
, NULL
, flags
);