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
);
1169 PWND PaintWnd
, StartWnd
;
1171 if ((MsgFilterMin
!= 0 || MsgFilterMax
!= 0) &&
1172 (MsgFilterMin
> WM_PAINT
|| MsgFilterMax
< WM_PAINT
))
1175 if (Thread
->TIF_flags
& TIF_SYSTEMTHREAD
)
1177 ERR("WM_PAINT is in a System Thread!\n");
1180 StartWnd
= UserGetDesktopWindow();
1181 PaintWnd
= IntFindWindowToRepaint(StartWnd
, Thread
);
1183 Message
->hwnd
= PaintWnd
? UserHMGetHandle(PaintWnd
) : NULL
;
1185 if (Message
->hwnd
== NULL
&& Thread
->cPaintsReady
)
1187 // Find note in window.c:"PAINTING BUG".
1188 ERR("WARNING SOMETHING HAS GONE WRONG: Thread marked as containing dirty windows, but no dirty windows found! Counts %u\n",Thread
->cPaintsReady
);
1189 /* Hack to stop spamming the debug log ! */
1190 Thread
->cPaintsReady
= 0;
1194 if (Message
->hwnd
== NULL
)
1197 if (!(Window
== NULL
||
1198 PaintWnd
== Window
||
1199 IntIsChildWindow(Window
, PaintWnd
))) /* check that it is a child of the specified parent */
1202 if (PaintWnd
->state
& WNDS_INTERNALPAINT
)
1204 PaintWnd
->state
&= ~WNDS_INTERNALPAINT
;
1205 if (!PaintWnd
->hrgnUpdate
)
1206 MsqDecPaintCountQueue(Thread
);
1208 PaintWnd
->state2
&= ~WNDS2_STARTPAINT
;
1209 PaintWnd
->state
&= ~WNDS_UPDATEDIRTY
;
1212 while( Window
&& Window
!= UserGetDesktopWindow())
1214 // Role back and check for clip children, do not set if any.
1215 if (Window
->spwndParent
&& !(Window
->spwndParent
->style
& WS_CLIPCHILDREN
))
1217 PaintWnd
->state2
|= WNDS2_WMPAINTSENT
;
1219 Window
= Window
->spwndParent
;
1222 Message
->wParam
= Message
->lParam
= 0;
1223 Message
->message
= WM_PAINT
;
1235 INT cx
, cy
, xSrc
, ySrc
;
1237 if ( nFlags
& PW_CLIENTONLY
)
1239 cx
= pwnd
->rcClient
.right
- pwnd
->rcClient
.left
;
1240 cy
= pwnd
->rcClient
.bottom
- pwnd
->rcClient
.top
;
1241 xSrc
= pwnd
->rcClient
.left
- pwnd
->rcWindow
.left
;
1242 ySrc
= pwnd
->rcClient
.top
- pwnd
->rcWindow
.top
;
1246 cx
= pwnd
->rcWindow
.right
- pwnd
->rcWindow
.left
;
1247 cy
= pwnd
->rcWindow
.bottom
- pwnd
->rcWindow
.top
;
1252 // TODO: Setup Redirection for Print.
1255 /* Update the window just incase. */
1256 co_IntUpdateWindows( pwnd
, RDW_ALLCHILDREN
, FALSE
);
1258 hdcSrc
= UserGetDCEx( pwnd
, NULL
, DCX_CACHE
|DCX_WINDOW
);
1259 /* Print window to printer context. */
1260 NtGdiBitBlt( hdcBlt
,
1272 UserReleaseDC( pwnd
, hdcSrc
, FALSE
);
1274 // TODO: Release Redirection from Print.
1281 IntFlashWindowEx(PWND pWnd
, PFLASHWINFO pfwi
)
1284 UINT uCount
= pfwi
->uCount
;
1285 BOOL Activate
= FALSE
, Ret
= FALSE
;
1289 FlashState
= (DWORD
)UserGetProp(pWnd
, AtomFlashWndState
, TRUE
);
1291 if (FlashState
== FLASHW_FINISHED
)
1293 // Cycle has finished, kill timer and set this to Stop.
1294 FlashState
|= FLASHW_KILLSYSTIMER
;
1295 pfwi
->dwFlags
= FLASHW_STOP
;
1301 if (pfwi
->dwFlags
== FLASHW_SYSTIMER
)
1303 // Called from system timer, restore flags, counts and state.
1304 pfwi
->dwFlags
= LOWORD(FlashState
);
1305 uCount
= HIWORD(FlashState
);
1306 FlashState
= MAKELONG(LOWORD(FlashState
),0);
1310 // Clean out the trash! Fix SeaMonkey crash after restart.
1315 if (FlashState
== 0)
1316 { // First time in cycle, setup flash state.
1317 if ( pWnd
->state
& WNDS_ACTIVEFRAME
||
1318 (pfwi
->dwFlags
& FLASHW_CAPTION
&& pWnd
->style
& (WS_BORDER
|WS_DLGFRAME
)))
1320 FlashState
= FLASHW_STARTED
|FLASHW_ACTIVE
;
1324 // Set previous window state.
1325 Ret
= !!(FlashState
& FLASHW_ACTIVE
);
1327 if ( (pfwi
->dwFlags
& FLASHW_TIMERNOFG
) == FLASHW_TIMERNOFG
&&
1328 gpqForeground
== pWnd
->head
.pti
->MessageQueue
)
1330 // Flashing until foreground, set this to Stop.
1331 pfwi
->dwFlags
= FLASHW_STOP
;
1335 // Toggle activate flag.
1336 if ( pfwi
->dwFlags
== FLASHW_STOP
)
1338 if (gpqForeground
&& gpqForeground
->spwndActive
== pWnd
)
1345 Activate
= (FlashState
& FLASHW_ACTIVE
) == 0;
1348 if ( pfwi
->dwFlags
== FLASHW_STOP
|| pfwi
->dwFlags
& FLASHW_CAPTION
)
1350 co_IntSendMessage(UserHMGetHandle(pWnd
), WM_NCACTIVATE
, Activate
, 0);
1353 // FIXME: Check for a Stop Sign here.
1354 if ( pfwi
->dwFlags
& FLASHW_TRAY
)
1356 // Need some shell work here too.
1357 TRACE("FIXME: Flash window no Tray support!\n");
1360 if ( pfwi
->dwFlags
== FLASHW_STOP
)
1362 if (FlashState
& FLASHW_KILLSYSTIMER
)
1364 IntKillTimer(pWnd
, ID_EVENT_SYSTIMER_FLASHWIN
, TRUE
);
1367 UserRemoveProp(pWnd
, AtomFlashWndState
, TRUE
);
1370 { // Have a count and started, set timer.
1373 FlashState
|= FLASHW_COUNT
;
1375 if (!(Activate
^ !!(FlashState
& FLASHW_STARTED
)))
1378 if (!(FlashState
& FLASHW_KILLSYSTIMER
))
1379 pfwi
->dwFlags
|= FLASHW_TIMER
;
1382 if (pfwi
->dwFlags
& FLASHW_TIMER
)
1384 FlashState
|= FLASHW_KILLSYSTIMER
;
1387 ID_EVENT_SYSTIMER_FLASHWIN
,
1388 pfwi
->dwTimeout
? pfwi
->dwTimeout
: gpsi
->dtCaretBlink
,
1393 if (FlashState
& FLASHW_COUNT
&& uCount
== 0)
1395 // Keep spinning? Nothing else to do.
1396 FlashState
= FLASHW_FINISHED
;
1400 // Save state and flags so this can be restored next time through.
1401 FlashState
^= (FlashState
^ -!!(Activate
)) & FLASHW_ACTIVE
;
1402 FlashState
^= (FlashState
^ pfwi
->dwFlags
) & (FLASHW_MASK
& ~FLASHW_TIMER
);
1404 FlashState
= MAKELONG(LOWORD(FlashState
),uCount
);
1405 UserSetProp(pWnd
, AtomFlashWndState
, (HANDLE
)FlashState
, TRUE
);
1411 IntBeginPaint(PWND Window
, PPAINTSTRUCT Ps
)
1417 co_UserHideCaret(Window
);
1419 Window
->state2
|= WNDS2_STARTPAINT
;
1420 Window
->state
&= ~WNDS_PAINTNOTPROCESSED
;
1422 if (Window
->state
& WNDS_SENDNCPAINT
)
1425 // Application can keep update dirty.
1428 Window
->state
&= ~WNDS_UPDATEDIRTY
;
1429 hRgn
= IntGetNCUpdateRgn(Window
, FALSE
);
1430 IntSendNCPaint(Window
, hRgn
);
1431 if (hRgn
> HRGN_WINDOW
&& GreIsHandleValid(hRgn
))
1433 /* NOTE: The region can already be deleted! */
1434 GreDeleteObject(hRgn
);
1437 while(Window
->state
& WNDS_UPDATEDIRTY
);
1441 Window
->state
&= ~WNDS_UPDATEDIRTY
;
1444 RtlZeroMemory(Ps
, sizeof(PAINTSTRUCT
));
1446 if (Window
->state2
& WNDS2_ENDPAINTINVALIDATE
)
1448 ERR("BP: Another thread invalidated this window\n");
1451 Ps
->hdc
= UserGetDCEx( Window
,
1453 DCX_INTERSECTRGN
| DCX_USESTYLE
);
1459 // If set, always clear flags out due to the conditions later on for sending the message.
1460 if (Window
->state
& WNDS_SENDERASEBACKGROUND
)
1462 Window
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
1466 if (Window
->hrgnUpdate
!= NULL
)
1468 MsqDecPaintCountQueue(Window
->head
.pti
);
1469 IntGdiSetRegionOwner(Window
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
1470 /* The region is part of the dc now and belongs to the process! */
1471 Window
->hrgnUpdate
= NULL
;
1475 if (Window
->state
& WNDS_INTERNALPAINT
)
1476 MsqDecPaintCountQueue(Window
->head
.pti
);
1479 type
= GdiGetClipBox(Ps
->hdc
, &Ps
->rcPaint
);
1481 IntGetClientRect(Window
, &Rect
);
1483 Window
->state
&= ~WNDS_INTERNALPAINT
;
1485 if ( Erase
&& // Set to erase,
1486 type
!= NULLREGION
&& // don't erase if the clip box is empty,
1487 (!(Window
->pcls
->style
& CS_PARENTDC
) || // not parent dc or
1488 RECTL_bIntersectRect( &Rect
, &Rect
, &Ps
->rcPaint
) ) ) // intersecting.
1490 Ps
->fErase
= !co_IntSendMessage(UserHMGetHandle(Window
), WM_ERASEBKGND
, (WPARAM
)Ps
->hdc
, 0);
1493 Window
->state
|= (WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
1501 IntSendChildNCPaint(Window
);
1507 IntEndPaint(PWND Wnd
, PPAINTSTRUCT Ps
)
1513 UserReleaseDC(Wnd
, hdc
, TRUE
);
1515 if (Wnd
->state2
& WNDS2_ENDPAINTINVALIDATE
)
1517 ERR("EP: Another thread invalidated this window\n");
1518 Wnd
->state2
&= ~WNDS2_ENDPAINTINVALIDATE
;
1521 Wnd
->state2
&= ~(WNDS2_WMPAINTSENT
|WNDS2_STARTPAINT
);
1523 co_UserShowCaret(Wnd
);
1528 /* PUBLIC FUNCTIONS ***********************************************************/
1538 NtUserBeginPaint(HWND hWnd
, PAINTSTRUCT
* UnsafePs
)
1544 USER_REFERENCE_ENTRY Ref
;
1545 DECLARE_RETURN(HDC
);
1547 TRACE("Enter NtUserBeginPaint\n");
1548 UserEnterExclusive();
1550 if (!(Window
= UserGetWindowObject(hWnd
)))
1555 UserRefObjectCo(Window
, &Ref
);
1557 hDC
= IntBeginPaint(Window
, &Ps
);
1559 Status
= MmCopyToCaller(UnsafePs
, &Ps
, sizeof(PAINTSTRUCT
));
1560 if (! NT_SUCCESS(Status
))
1562 SetLastNtError(Status
);
1569 if (Window
) UserDerefObjectCo(Window
);
1571 TRACE("Leave NtUserBeginPaint, ret=%p\n",_ret_
);
1585 NtUserEndPaint(HWND hWnd
, CONST PAINTSTRUCT
* pUnsafePs
)
1587 NTSTATUS Status
= STATUS_SUCCESS
;
1590 USER_REFERENCE_ENTRY Ref
;
1591 DECLARE_RETURN(BOOL
);
1593 TRACE("Enter NtUserEndPaint\n");
1594 UserEnterExclusive();
1596 if (!(Window
= UserGetWindowObject(hWnd
)))
1601 UserRefObjectCo(Window
, &Ref
); // Here for the exception.
1605 ProbeForRead(pUnsafePs
, sizeof(*pUnsafePs
), 1);
1606 RtlCopyMemory(&Ps
, pUnsafePs
, sizeof(PAINTSTRUCT
));
1608 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1610 Status
= _SEH2_GetExceptionCode();
1613 if (!NT_SUCCESS(Status
))
1618 RETURN(IntEndPaint(Window
, &Ps
));
1621 if (Window
) UserDerefObjectCo(Window
);
1623 TRACE("Leave NtUserEndPaint, ret=%i\n",_ret_
);
1632 NtUserFlashWindowEx(IN PFLASHWINFO pfwi
)
1635 FLASHWINFO finfo
= {0};
1638 UserEnterExclusive();
1642 ProbeForRead(pfwi
, sizeof(FLASHWINFO
), 1);
1643 RtlCopyMemory(&finfo
, pfwi
, sizeof(FLASHWINFO
));
1645 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1647 SetLastNtError(_SEH2_GetExceptionCode());
1648 _SEH2_YIELD(goto Exit
);
1652 if (!( pWnd
= ValidateHwndNoErr(finfo
.hwnd
)) ||
1653 finfo
.cbSize
!= sizeof(FLASHWINFO
) ||
1654 finfo
.dwFlags
& ~(FLASHW_ALL
|FLASHW_TIMER
|FLASHW_TIMERNOFG
) )
1656 EngSetLastError(ERROR_INVALID_PARAMETER
);
1660 Ret
= IntFlashWindowEx(pWnd
, &finfo
);
1668 GetUpdateRgn, this fails the same as the old one.
1671 co_UserGetUpdateRgn(PWND Window
, HRGN hRgn
, BOOL bErase
)
1677 ASSERT_REFS_CO(Window
);
1681 USER_REFERENCE_ENTRY Ref
;
1682 UserRefObjectCo(Window
, &Ref
);
1683 co_IntPaintWindows(Window
, RDW_NOCHILDREN
, FALSE
);
1684 UserDerefObjectCo(Window
);
1687 Window
->state
&= ~WNDS_UPDATEDIRTY
;
1689 if (Window
->hrgnUpdate
== NULL
)
1691 NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0);
1695 Rect
= Window
->rcClient
;
1696 Type
= IntIntersectWithParents(Window
, &Rect
);
1698 if (Window
->hrgnUpdate
== HRGN_WINDOW
)
1701 ERR("GURn: Caller is passing Window Region 1\n");
1704 NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0);
1708 RegionType
= SIMPLEREGION
;
1710 if (Window
!= UserGetDesktopWindow()) // Window->fnid == FNID_DESKTOP
1712 RECTL_vOffsetRect(&Rect
,
1713 -Window
->rcClient
.left
,
1714 -Window
->rcClient
.top
);
1716 GreSetRectRgnIndirect(hRgn
, &Rect
);
1720 HRGN hrgnTemp
= GreCreateRectRgnIndirect(&Rect
);
1722 RegionType
= NtGdiCombineRgn(hRgn
, hrgnTemp
, Window
->hrgnUpdate
, RGN_AND
);
1724 if (RegionType
== ERROR
|| RegionType
== NULLREGION
)
1726 if (hrgnTemp
) GreDeleteObject(hrgnTemp
);
1727 NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0);
1731 if (Window
!= UserGetDesktopWindow()) // Window->fnid == FNID_DESKTOP
1733 NtGdiOffsetRgn(hRgn
,
1734 -Window
->rcClient
.left
,
1735 -Window
->rcClient
.top
);
1737 if (hrgnTemp
) GreDeleteObject(hrgnTemp
);
1743 co_UserGetUpdateRect(PWND Window
, PRECT pRect
, BOOL bErase
)
1750 USER_REFERENCE_ENTRY Ref
;
1751 UserRefObjectCo(Window
, &Ref
);
1752 co_IntPaintWindows(Window
, RDW_NOCHILDREN
, FALSE
);
1753 UserDerefObjectCo(Window
);
1756 Window
->state
&= ~WNDS_UPDATEDIRTY
;
1758 if (Window
->hrgnUpdate
== NULL
)
1760 pRect
->left
= pRect
->top
= pRect
->right
= pRect
->bottom
= 0;
1765 /* Get the update region bounding box. */
1766 if (Window
->hrgnUpdate
== HRGN_WINDOW
)
1768 *pRect
= Window
->rcClient
;
1769 ERR("GURt: Caller is retrieving Window Region 1\n");
1773 RegionType
= IntGdiGetRgnBox(Window
->hrgnUpdate
, pRect
);
1775 if (RegionType
!= ERROR
&& RegionType
!= NULLREGION
)
1776 RECTL_bIntersectRect(pRect
, pRect
, &Window
->rcClient
);
1779 if (IntIntersectWithParents(Window
, pRect
))
1781 if (Window
!= UserGetDesktopWindow()) // Window->fnid == FNID_DESKTOP
1783 RECTL_vOffsetRect(pRect
,
1784 -Window
->rcClient
.left
,
1785 -Window
->rcClient
.top
);
1787 if (Window
->pcls
->style
& CS_OWNDC
)
1791 hdc
= UserGetDCEx(Window
, NULL
, DCX_USESTYLE
);
1792 //layout = NtGdiSetLayout(hdc, -1, 0);
1793 //IntMapWindowPoints( 0, Window, (LPPOINT)pRect, 2 );
1794 GreDPtoLP( hdc
, (LPPOINT
)pRect
, 2 );
1795 //NtGdiSetLayout(hdc, -1, layout);
1796 UserReleaseDC(Window
, hdc
, FALSE
);
1801 pRect
->left
= pRect
->top
= pRect
->right
= pRect
->bottom
= 0;
1808 * NtUserGetUpdateRgn
1815 NtUserGetUpdateRgn(HWND hWnd
, HRGN hRgn
, BOOL bErase
)
1817 DECLARE_RETURN(INT
);
1821 TRACE("Enter NtUserGetUpdateRgn\n");
1822 UserEnterExclusive();
1824 if (!(Window
= UserGetWindowObject(hWnd
)))
1829 ret
= co_UserGetUpdateRgn(Window
, hRgn
, bErase
);
1834 TRACE("Leave NtUserGetUpdateRgn, ret=%i\n",_ret_
);
1840 * NtUserGetUpdateRect
1847 NtUserGetUpdateRect(HWND hWnd
, LPRECT UnsafeRect
, BOOL bErase
)
1853 DECLARE_RETURN(BOOL
);
1855 TRACE("Enter NtUserGetUpdateRect\n");
1856 UserEnterExclusive();
1858 if (!(Window
= UserGetWindowObject(hWnd
)))
1863 Ret
= co_UserGetUpdateRect(Window
, &Rect
, bErase
);
1865 if (UnsafeRect
!= NULL
)
1867 Status
= MmCopyToCaller(UnsafeRect
, &Rect
, sizeof(RECTL
));
1868 if (!NT_SUCCESS(Status
))
1870 EngSetLastError(ERROR_INVALID_PARAMETER
);
1878 TRACE("Leave NtUserGetUpdateRect, ret=%i\n",_ret_
);
1884 * NtUserRedrawWindow
1893 CONST RECT
*lprcUpdate
,
1897 RECTL SafeUpdateRect
;
1900 USER_REFERENCE_ENTRY Ref
;
1901 NTSTATUS Status
= STATUS_SUCCESS
;
1902 PREGION RgnUpdate
= NULL
;
1903 DECLARE_RETURN(BOOL
);
1905 TRACE("Enter NtUserRedrawWindow\n");
1906 UserEnterExclusive();
1908 if (!(Wnd
= UserGetWindowObject(hWnd
? hWnd
: IntGetDesktopWindow())))
1917 ProbeForRead(lprcUpdate
, sizeof(RECTL
), 1);
1918 RtlCopyMemory(&SafeUpdateRect
, lprcUpdate
, sizeof(RECTL
));
1920 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1922 Status
= _SEH2_GetExceptionCode();
1925 if (!NT_SUCCESS(Status
))
1927 EngSetLastError(RtlNtStatusToDosError(Status
));
1932 if ( flags
& ~(RDW_ERASE
|RDW_FRAME
|RDW_INTERNALPAINT
|RDW_INVALIDATE
|
1933 RDW_NOERASE
|RDW_NOFRAME
|RDW_NOINTERNALPAINT
|RDW_VALIDATE
|
1934 RDW_ERASENOW
|RDW_UPDATENOW
|RDW_ALLCHILDREN
|RDW_NOCHILDREN
) )
1936 /* RedrawWindow fails only in case that flags are invalid */
1937 EngSetLastError(ERROR_INVALID_FLAGS
);
1941 /* We can't hold lock on GDI objects while doing roundtrips to user mode,
1942 * so it will be copied.
1944 if (hrgnUpdate
> HRGN_WINDOW
)
1946 RgnUpdate
= REGION_LockRgn(hrgnUpdate
);
1949 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1952 REGION_UnlockRgn(RgnUpdate
);
1954 else if (hrgnUpdate
== HRGN_WINDOW
) // Trap it out.
1956 ERR("NTRW: Caller is passing Window Region 1\n");
1959 UserRefObjectCo(Wnd
, &Ref
);
1961 Ret
= co_UserRedrawWindow( Wnd
,
1962 lprcUpdate
? &SafeUpdateRect
: NULL
,
1966 UserDerefObjectCo(Wnd
);
1971 TRACE("Leave NtUserRedrawWindow, ret=%i\n",_ret_
);
1977 UserDrawCaptionText(
1980 const PUNICODE_STRING Text
,
1985 HFONT hOldFont
= NULL
;
1986 COLORREF OldTextColor
;
1987 NONCLIENTMETRICSW nclm
;
1989 BOOLEAN bDeleteFont
= FALSE
;
1992 ULONG fit
= 0, Length
;
1995 TRACE("UserDrawCaptionText: %wZ\n", Text
);
1997 nclm
.cbSize
= sizeof(nclm
);
1998 if(!UserSystemParametersInfo(SPI_GETNONCLIENTMETRICS
, sizeof(NONCLIENTMETRICS
), &nclm
, 0))
2000 ERR("UserSystemParametersInfo() failed!\n");
2006 if(uFlags
& DC_SMALLCAP
)
2007 Status
= TextIntCreateFontIndirect(&nclm
.lfSmCaptionFont
, &hFont
);
2009 Status
= TextIntCreateFontIndirect(&nclm
.lfCaptionFont
, &hFont
);
2011 if(!NT_SUCCESS(Status
))
2013 ERR("TextIntCreateFontIndirect() failed! Status: 0x%x\n", Status
);
2020 IntGdiSetBkMode(hDc
, TRANSPARENT
);
2022 hOldFont
= NtGdiSelectFont(hDc
, hFont
);
2024 if(uFlags
& DC_INBUTTON
)
2025 OldTextColor
= IntGdiSetTextColor(hDc
, IntGetSysColor(COLOR_BTNTEXT
));
2027 OldTextColor
= IntGdiSetTextColor(hDc
,
2028 IntGetSysColor(uFlags
& DC_ACTIVE
? COLOR_CAPTIONTEXT
: COLOR_INACTIVECAPTIONTEXT
));
2030 // Adjust for system menu.
2031 if (pWnd
&& pWnd
->style
& WS_SYSMENU
)
2033 r
.right
-= UserGetSystemMetrics(SM_CYCAPTION
) - 1;
2034 if ((pWnd
->style
& (WS_MAXIMIZEBOX
| WS_MINIMIZEBOX
)) && !(pWnd
->ExStyle
& WS_EX_TOOLWINDOW
))
2036 r
.right
-= UserGetSystemMetrics(SM_CXSIZE
) + 1;
2037 r
.right
-= UserGetSystemMetrics(SM_CXSIZE
) + 1;
2041 GreGetTextExtentExW(hDc
, Text
->Buffer
, Text
->Length
/sizeof(WCHAR
), r
.right
- r
.left
, &fit
, 0, &Size
, 0);
2043 Length
= (Text
->Length
/sizeof(WCHAR
) == fit
? fit
: fit
+1);
2045 if (Text
->Length
/sizeof(WCHAR
) > Length
)
2051 { // Faster while in setup.
2052 GreExtTextOutW( hDc
,
2054 lpRc
->top
+ (lpRc
->bottom
- lpRc
->top
) / 2 - Size
.cy
/ 2, // DT_SINGLELINE && DT_VCENTER
2066 Text
->Length
/sizeof(WCHAR
),
2068 DT_END_ELLIPSIS
|DT_SINGLELINE
|DT_VCENTER
|DT_NOPREFIX
|DT_LEFT
);
2071 IntGdiSetTextColor(hDc
, OldTextColor
);
2074 NtGdiSelectFont(hDc
, hOldFont
);
2077 GreDeleteObject(hFont
);
2083 // This draws Buttons, Icons and Text...
2085 BOOL
UserDrawCaption(
2091 const PUNICODE_STRING Str
,
2095 HBRUSH hBgBrush
, hOldBrush
= NULL
;
2099 RECTL_vMakeWellOrdered(lpRc
);
2101 /* Determine whether the icon needs to be displayed */
2102 if (!hIcon
&& pWnd
!= NULL
)
2104 HasIcon
= (uFlags
& DC_ICON
) && !(uFlags
& DC_SMALLCAP
) &&
2105 (pWnd
->style
& WS_SYSMENU
) && !(pWnd
->ExStyle
& WS_EX_TOOLWINDOW
);
2108 HasIcon
= (hIcon
!= NULL
);
2110 // Draw the caption background
2111 if((uFlags
& DC_GRADIENT
) && !(uFlags
& DC_INBUTTON
))
2113 static GRADIENT_RECT gcap
= {0, 1};
2114 TRIVERTEX Vertices
[2];
2117 Colors
[0] = IntGetSysColor((uFlags
& DC_ACTIVE
) ?
2118 COLOR_ACTIVECAPTION
: COLOR_INACTIVECAPTION
);
2120 Colors
[1] = IntGetSysColor((uFlags
& DC_ACTIVE
) ?
2121 COLOR_GRADIENTACTIVECAPTION
: COLOR_GRADIENTINACTIVECAPTION
);
2123 Vertices
[0].x
= Rect
.left
;
2124 Vertices
[0].y
= Rect
.top
;
2125 Vertices
[0].Red
= (WORD
)Colors
[0]<<8;
2126 Vertices
[0].Green
= (WORD
)Colors
[0] & 0xFF00;
2127 Vertices
[0].Blue
= (WORD
)(Colors
[0]>>8) & 0xFF00;
2128 Vertices
[0].Alpha
= 0;
2130 Vertices
[1].x
= Rect
.right
;
2131 Vertices
[1].y
= Rect
.bottom
;
2132 Vertices
[1].Red
= (WORD
)Colors
[1]<<8;
2133 Vertices
[1].Green
= (WORD
)Colors
[1] & 0xFF00;
2134 Vertices
[1].Blue
= (WORD
)(Colors
[1]>>8) & 0xFF00;
2135 Vertices
[1].Alpha
= 0;
2137 if(!GreGradientFill(hDc
, Vertices
, 2, &gcap
, 1, GRADIENT_FILL_RECT_H
))
2139 ERR("GreGradientFill() failed!\n");
2145 if(uFlags
& DC_INBUTTON
)
2146 hBgBrush
= IntGetSysColorBrush(COLOR_3DFACE
);
2147 else if(uFlags
& DC_ACTIVE
)
2148 hBgBrush
= IntGetSysColorBrush(COLOR_ACTIVECAPTION
);
2150 hBgBrush
= IntGetSysColorBrush(COLOR_INACTIVECAPTION
);
2152 hOldBrush
= NtGdiSelectBrush(hDc
, hBgBrush
);
2156 ERR("NtGdiSelectBrush() failed!\n");
2160 if(!NtGdiPatBlt(hDc
, Rect
.left
, Rect
.top
,
2161 Rect
.right
- Rect
.left
,
2162 Rect
.bottom
- Rect
.top
,
2165 ERR("NtGdiPatBlt() failed!\n");
2173 PCURICON_OBJECT pIcon
= NULL
;
2177 pIcon
= UserGetCurIconObject(hIcon
);
2181 pIcon
= NC_IconForWindow(pWnd
);
2182 // FIXME: NC_IconForWindow should reference it for us */
2184 UserReferenceObject(pIcon
);
2189 LONG cx
= UserGetSystemMetrics(SM_CXSMICON
);
2190 LONG cy
= UserGetSystemMetrics(SM_CYSMICON
);
2191 LONG x
= Rect
.left
- cx
/2 + 1 + (Rect
.bottom
- Rect
.top
)/2; // this is really what Window does
2192 LONG y
= (Rect
.top
+ Rect
.bottom
- cy
)/2; // center
2193 UserDrawIconEx(hDc
, x
, y
, pIcon
, cx
, cy
, 0, NULL
, DI_NORMAL
);
2194 UserDereferenceObject(pIcon
);
2203 Rect
.left
+= Rect
.bottom
- Rect
.top
;
2205 if((uFlags
& DC_TEXT
))
2211 Set
= UserDrawCaptionText(pWnd
, hDc
, Str
, &Rect
, uFlags
, hFont
);
2212 else if (pWnd
!= NULL
) // FIXME: Windows does not do that
2214 UNICODE_STRING ustr
;
2215 ustr
.Buffer
= pWnd
->strName
.Buffer
; // FIXME: LARGE_STRING truncated!
2216 ustr
.Length
= (USHORT
)min(pWnd
->strName
.Length
, MAXUSHORT
);
2217 ustr
.MaximumLength
= (USHORT
)min(pWnd
->strName
.MaximumLength
, MAXUSHORT
);
2218 Set
= UserDrawCaptionText(pWnd
, hDc
, &ustr
, &Rect
, uFlags
, hFont
);
2223 pWnd
->state2
&= ~WNDS2_CAPTIONTEXTTRUNCATED
;
2225 pWnd
->state2
|= WNDS2_CAPTIONTEXTTRUNCATED
;
2232 if (hOldBrush
) NtGdiSelectBrush(hDc
, hOldBrush
);
2239 UserRealizePalette(HDC hdc
)
2241 HWND hWnd
, hWndDesktop
;
2244 Ret
= IntGdiRealizePalette(hdc
);
2245 if (Ret
) // There was a change.
2247 hWnd
= IntWindowFromDC(hdc
);
2248 if (hWnd
) // Send broadcast if dc is associated with a window.
2249 { // FYI: Thread locked in CallOneParam.
2250 hWndDesktop
= IntGetDesktopWindow();
2251 if ( hWndDesktop
!= hWnd
)
2253 PWND pWnd
= UserGetWindowObject(hWndDesktop
);
2254 ERR("RealizePalette Desktop.");
2255 hdc
= UserGetWindowDC(pWnd
);
2256 IntPaintDesktop(hdc
);
2257 UserReleaseDC(pWnd
,hdc
,FALSE
);
2259 UserSendNotifyMessage((HWND
)HWND_BROADCAST
, WM_PALETTECHANGED
, (WPARAM
)hWnd
, 0);
2267 NtUserDrawCaptionTemp(
2273 const PUNICODE_STRING str
,
2277 UNICODE_STRING SafeStr
= {0};
2278 NTSTATUS Status
= STATUS_SUCCESS
;
2282 UserEnterExclusive();
2286 if(!(pWnd
= UserGetWindowObject(hWnd
)))
2295 ProbeForRead(lpRc
, sizeof(RECTL
), sizeof(ULONG
));
2296 RtlCopyMemory(&SafeRect
, lpRc
, sizeof(RECTL
));
2299 SafeStr
= ProbeForReadUnicodeString(str
);
2300 if (SafeStr
.Length
!= 0)
2302 ProbeForRead( SafeStr
.Buffer
,
2308 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2310 Status
= _SEH2_GetExceptionCode();
2314 if (Status
!= STATUS_SUCCESS
)
2316 SetLastNtError(Status
);
2322 Ret
= UserDrawCaption(pWnd
, hDC
, &SafeRect
, hFont
, hIcon
, &SafeStr
, uFlags
);
2325 if ( RECTL_bIsEmptyRect(&SafeRect
) && hFont
== 0 && hIcon
== 0 )
2328 if (uFlags
& DC_DRAWCAPTIONMD
)
2330 ERR("NC Caption Mode\n");
2331 UserDrawCaptionBar(pWnd
, hDC
, uFlags
);
2334 else if (uFlags
& DC_DRAWFRAMEMD
)
2336 ERR("NC Paint Mode\n");
2337 NC_DoNCPaint(pWnd
, hDC
, uFlags
); // Update Menus too!
2341 Ret
= UserDrawCaption(pWnd
, hDC
, &SafeRect
, hFont
, hIcon
, NULL
, uFlags
);
2350 NtUserDrawCaption(HWND hWnd
,
2355 return NtUserDrawCaptionTemp(hWnd
, hDC
, lpRc
, 0, 0, NULL
, uFlags
);
2360 NtUserInvalidateRect(
2362 CONST RECT
*lpUnsafeRect
,
2365 UINT flags
= RDW_INVALIDATE
| (bErase
? RDW_ERASE
: 0);
2368 flags
= RDW_ALLCHILDREN
| RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ERASENOW
;
2369 lpUnsafeRect
= NULL
;
2371 return NtUserRedrawWindow(hWnd
, lpUnsafeRect
, NULL
, flags
);
2376 NtUserInvalidateRgn(
2383 EngSetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2386 return NtUserRedrawWindow(hWnd
, NULL
, hRgn
, RDW_INVALIDATE
| (bErase
? RDW_ERASE
: 0));
2399 UserEnterExclusive();
2403 if (!(Window
= UserGetWindowObject(hwnd
)) || // FIXME:
2404 Window
== UserGetDesktopWindow() || // pWnd->fnid == FNID_DESKTOP
2405 Window
== UserGetMessageWindow() ) // pWnd->fnid == FNID_MESSAGEWND
2412 /* Validate flags and check it as a mask for 0 or 1. */
2413 if ( (nFlags
& PW_CLIENTONLY
) == nFlags
)
2414 Ret
= IntPrintWindow( Window
, hdcBlt
, nFlags
);
2416 EngSetLastError(ERROR_INVALID_PARAMETER
);
2424 /* ValidateRect gets redirected to NtUserValidateRect:
2425 http://blog.csdn.net/ntdll/archive/2005/10/19/509299.aspx */
2432 UINT flags
= RDW_VALIDATE
;
2435 flags
= RDW_ALLCHILDREN
| RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ERASENOW
;
2438 return NtUserRedrawWindow(hWnd
, lpRect
, NULL
, flags
);