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 (UserIsDesktopWindow(Wnd
))
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 for (pWnd
= pWnd
->spwndChild
; pWnd
; pWnd
= pWnd
->spwndNext
)
371 if ((pWnd
->hrgnUpdate
== NULL
) && (pWnd
->state
& WNDS_SENDNCPAINT
))
373 USER_REFERENCE_ENTRY Ref
;
374 UserRefObjectCo(pWnd
, &Ref
);
375 IntSendNCPaint(pWnd
, HRGN_WINDOW
);
376 UserDerefObjectCo(pWnd
);
384 * Internal function used by IntRedrawWindow.
388 co_IntPaintWindows(PWND Wnd
, ULONG Flags
, BOOL Recurse
)
391 HWND hWnd
= Wnd
->head
.h
;
392 HRGN TempRegion
= NULL
;
394 Wnd
->state
&= ~WNDS_PAINTNOTPROCESSED
;
396 if (Wnd
->state
& WNDS_SENDNCPAINT
||
397 Wnd
->state
& WNDS_SENDERASEBACKGROUND
)
399 if (!(Wnd
->style
& WS_VISIBLE
))
401 Wnd
->state
&= ~(WNDS_SENDNCPAINT
|WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
406 if (Wnd
->hrgnUpdate
== NULL
)
408 Wnd
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
411 if (Wnd
->head
.pti
== PsGetCurrentThreadWin32Thread())
413 if (Wnd
->state
& WNDS_SENDNCPAINT
)
415 TempRegion
= IntGetNCUpdateRgn(Wnd
, TRUE
);
417 IntSendNCPaint(Wnd
, TempRegion
);
419 if (TempRegion
> HRGN_WINDOW
&& GreIsHandleValid(TempRegion
))
421 /* NOTE: The region can already be deleted! */
422 GreDeleteObject(TempRegion
);
426 if (Wnd
->state
& WNDS_SENDERASEBACKGROUND
)
428 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
431 hDC
= UserGetDCEx( Wnd
,
433 DCX_CACHE
|DCX_USESTYLE
|DCX_INTERSECTRGN
|DCX_KEEPCLIPRGN
);
435 if (Wnd
->head
.pti
->ppi
!= pti
->ppi
)
437 ERR("Sending DC to another Process!!!\n");
440 Wnd
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
441 // Kill the loop, so Clear before we send.
442 if (!co_IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)hDC
, 0))
444 Wnd
->state
|= (WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
446 UserReleaseDC(Wnd
, hDC
, FALSE
);
455 * Check that the window is still valid at this point
457 if (!IntIsWindow(hWnd
))
463 * Paint child windows.
466 if (!(Flags
& RDW_NOCHILDREN
) &&
467 !(Wnd
->style
& WS_MINIMIZE
) &&
468 ( Flags
& RDW_ALLCHILDREN
||
469 (Flags
& RDW_CLIPCHILDREN
&& Wnd
->style
& WS_CLIPCHILDREN
) ) )
472 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
474 if ((List
= IntWinListChildren(Wnd
)))
476 for (phWnd
= List
; *phWnd
; ++phWnd
)
478 if ((Wnd
= UserGetWindowObject(*phWnd
)) == NULL
)
481 if (Wnd
->head
.pti
!= pti
&& Wnd
->style
& WS_CHILD
)
484 if (Wnd
->style
& WS_VISIBLE
)
486 USER_REFERENCE_ENTRY Ref
;
487 UserRefObjectCo(Wnd
, &Ref
);
488 co_IntPaintWindows(Wnd
, Flags
, TRUE
);
489 UserDerefObjectCo(Wnd
);
492 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
500 * Internal function used by IntRedrawWindow, simplecall.
504 co_IntUpdateWindows(PWND Wnd
, ULONG Flags
, BOOL Recurse
)
506 HWND hWnd
= Wnd
->head
.h
;
508 if ( Wnd
->hrgnUpdate
!= NULL
|| Wnd
->state
& WNDS_INTERNALPAINT
)
512 if (!IntValidateParents(Wnd
, Recurse
))
518 if (Wnd
->state
& WNDS_INTERNALPAINT
)
520 Wnd
->state
&= ~WNDS_INTERNALPAINT
;
522 if (Wnd
->hrgnUpdate
== NULL
)
523 MsqDecPaintCountQueue(Wnd
->head
.pti
);
526 Wnd
->state
|= WNDS_PAINTNOTPROCESSED
;
527 Wnd
->state
&= ~WNDS_UPDATEDIRTY
;
529 Wnd
->state2
|= WNDS2_WMPAINTSENT
;
530 co_IntSendMessage(hWnd
, WM_PAINT
, 0, 0);
532 if (Wnd
->state
& WNDS_PAINTNOTPROCESSED
)
534 USER_REFERENCE_ENTRY Ref
;
535 UserRefObjectCo(Wnd
, &Ref
);
536 co_IntPaintWindows(Wnd
, RDW_NOCHILDREN
, FALSE
);
537 UserDerefObjectCo(Wnd
);
541 // Force flags as a toggle. Fixes msg:test_paint_messages:WmChildPaintNc.
542 Flags
= (Flags
& RDW_NOCHILDREN
) ? RDW_NOCHILDREN
: RDW_ALLCHILDREN
; // All children is the default.
545 * Update child windows.
548 if (!(Flags
& RDW_NOCHILDREN
) &&
549 (Flags
& RDW_ALLCHILDREN
) &&
550 !UserIsDesktopWindow(Wnd
))
554 for (Child
= Wnd
->spwndChild
; Child
; Child
= Child
->spwndNext
)
556 /* transparent window, check for non-transparent sibling to paint first, then skip it */
557 if ( Child
->ExStyle
& WS_EX_TRANSPARENT
&&
558 ( Child
->hrgnUpdate
!= NULL
|| Child
->state
& WNDS_INTERNALPAINT
) )
560 PWND Next
= Child
->spwndNext
;
563 if ( Next
->hrgnUpdate
!= NULL
|| Next
->state
& WNDS_INTERNALPAINT
) break;
565 Next
= Next
->spwndNext
;
571 if (Child
->style
& WS_VISIBLE
)
573 USER_REFERENCE_ENTRY Ref
;
574 UserRefObjectCo(Child
, &Ref
);
575 co_IntUpdateWindows(Child
, Flags
, TRUE
);
576 UserDerefObjectCo(Child
);
583 UserUpdateWindows(PWND pWnd
, ULONG Flags
)
585 // If transparent and any sibling windows below needs to be painted, leave.
586 if (pWnd
->ExStyle
& WS_EX_TRANSPARENT
)
588 PWND Next
= pWnd
->spwndNext
;
592 if ( Next
->head
.pti
== pWnd
->head
.pti
&&
593 ( Next
->hrgnUpdate
!= NULL
|| Next
->state
& WNDS_INTERNALPAINT
) )
598 Next
= Next
->spwndNext
;
601 co_IntUpdateWindows(pWnd
, Flags
, FALSE
);
605 UserSyncAndPaintWindows(PWND pWnd
, ULONG Flags
)
608 // Find parent, if it needs to be painted, leave.
611 if ((Parent
= Parent
->spwndParent
) == NULL
) break;
612 if ( Parent
->style
& WS_CLIPCHILDREN
) break;
613 if ( Parent
->hrgnUpdate
!= NULL
|| Parent
->state
& WNDS_INTERNALPAINT
) return;
616 IntSendSyncPaint(pWnd
, Flags
);
617 co_IntPaintWindows(pWnd
, Flags
, FALSE
);
621 * IntInvalidateWindows
623 * Internal function used by IntRedrawWindow, UserRedrawDesktop,
624 * co_WinPosSetWindowPos, co_UserRedrawWindow.
627 IntInvalidateWindows(PWND Wnd
, PREGION Rgn
, ULONG Flags
)
629 INT RgnType
= NULLREGION
;
630 BOOL HadPaintMessage
;
632 TRACE("IntInvalidateWindows start Rgn %p\n",Rgn
);
634 if ( Rgn
> PRGN_WINDOW
)
637 * If the nonclient is not to be redrawn, clip the region to the client
640 if ((Flags
& RDW_INVALIDATE
) != 0 && (Flags
& RDW_FRAME
) == 0)
644 RgnClient
= IntSysCreateRectpRgnIndirect(&Wnd
->rcClient
);
647 RgnType
= IntGdiCombineRgn(Rgn
, Rgn
, RgnClient
, RGN_AND
);
648 REGION_Delete(RgnClient
);
653 * Clip the given region with window rectangle (or region)
656 if (!Wnd
->hrgnClip
|| (Wnd
->style
& WS_MINIMIZE
))
658 PREGION RgnWindow
= IntSysCreateRectpRgnIndirect(&Wnd
->rcWindow
);
661 RgnType
= IntGdiCombineRgn(Rgn
, Rgn
, RgnWindow
, RGN_AND
);
662 REGION_Delete(RgnWindow
);
667 PREGION RgnClip
= REGION_LockRgn(Wnd
->hrgnClip
);
670 REGION_bOffsetRgn(Rgn
,
673 RgnType
= IntGdiCombineRgn(Rgn
, Rgn
, RgnClip
, RGN_AND
);
674 REGION_bOffsetRgn(Rgn
,
677 REGION_UnlockRgn(RgnClip
);
683 RgnType
= NULLREGION
;
687 * Save current state of pending updates
690 HadPaintMessage
= IntIsWindowDirty(Wnd
);
693 * Update the region and flags
696 // The following flags are used to invalidate the window.
697 if (Flags
& (RDW_INVALIDATE
|RDW_INTERNALPAINT
|RDW_ERASE
|RDW_FRAME
))
699 if (Flags
& RDW_INTERNALPAINT
)
701 Wnd
->state
|= WNDS_INTERNALPAINT
;
704 if (Flags
& RDW_INVALIDATE
)
708 Wnd
->state
&= ~WNDS_NONCPAINT
;
710 /* If not the same thread set it dirty. */
711 if (Wnd
->head
.pti
!= PsGetCurrentThreadWin32Thread())
713 Wnd
->state
|= WNDS_UPDATEDIRTY
;
714 if (Wnd
->state2
& WNDS2_WMPAINTSENT
)
715 Wnd
->state2
|= WNDS2_ENDPAINTINVALIDATE
;
718 if (Flags
& RDW_FRAME
)
719 Wnd
->state
|= WNDS_SENDNCPAINT
;
721 if (Flags
& RDW_ERASE
)
722 Wnd
->state
|= WNDS_SENDERASEBACKGROUND
;
724 if (RgnType
!= NULLREGION
&& Rgn
> PRGN_WINDOW
)
726 if (Wnd
->hrgnUpdate
== NULL
)
728 Wnd
->hrgnUpdate
= NtGdiCreateRectRgn(0, 0, 0, 0);
729 IntGdiSetRegionOwner(Wnd
->hrgnUpdate
, GDI_OBJ_HMGR_PUBLIC
);
732 if (Wnd
->hrgnUpdate
!= HRGN_WINDOW
)
734 RgnUpdate
= REGION_LockRgn(Wnd
->hrgnUpdate
);
737 RgnType
= IntGdiCombineRgn(RgnUpdate
, RgnUpdate
, Rgn
, RGN_OR
);
738 REGION_UnlockRgn(RgnUpdate
);
739 if (RgnType
== NULLREGION
)
741 IntGdiSetRegionOwner(Wnd
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
742 GreDeleteObject(Wnd
->hrgnUpdate
);
743 Wnd
->hrgnUpdate
= NULL
;
749 Flags
|= RDW_ERASE
|RDW_FRAME
; // For children.
753 if (!HadPaintMessage
&& IntIsWindowDirty(Wnd
))
755 MsqIncPaintCountQueue(Wnd
->head
.pti
);
758 } // The following flags are used to validate the window.
759 else if (Flags
& (RDW_VALIDATE
|RDW_NOINTERNALPAINT
|RDW_NOERASE
|RDW_NOFRAME
))
761 if (Wnd
->state
& WNDS_UPDATEDIRTY
&& !(Flags
& RDW_NOUPDATEDIRTY
))
764 if (Flags
& RDW_NOINTERNALPAINT
)
766 Wnd
->state
&= ~WNDS_INTERNALPAINT
;
769 if (Flags
& RDW_VALIDATE
)
771 if (Flags
& RDW_NOFRAME
)
772 Wnd
->state
&= ~WNDS_SENDNCPAINT
;
774 if (Flags
& RDW_NOERASE
)
775 Wnd
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
777 if (Wnd
->hrgnUpdate
> HRGN_WINDOW
&& RgnType
!= NULLREGION
&& Rgn
> PRGN_WINDOW
)
779 PREGION RgnUpdate
= REGION_LockRgn(Wnd
->hrgnUpdate
);
783 RgnType
= IntGdiCombineRgn(RgnUpdate
, RgnUpdate
, Rgn
, RGN_DIFF
);
784 REGION_UnlockRgn(RgnUpdate
);
786 if (RgnType
== NULLREGION
)
788 IntGdiSetRegionOwner(Wnd
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
789 GreDeleteObject(Wnd
->hrgnUpdate
);
790 Wnd
->hrgnUpdate
= NULL
;
794 // If update is null, do not erase.
795 if (Wnd
->hrgnUpdate
== NULL
)
797 Wnd
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
801 if (HadPaintMessage
&& !IntIsWindowDirty(Wnd
))
803 MsqDecPaintCountQueue(Wnd
->head
.pti
);
808 * Process children if needed
811 if (!(Flags
& RDW_NOCHILDREN
) &&
812 !(Wnd
->style
& WS_MINIMIZE
) &&
813 ((Flags
& RDW_ALLCHILDREN
) || !(Wnd
->style
& WS_CLIPCHILDREN
)))
817 for (Child
= Wnd
->spwndChild
; Child
; Child
= Child
->spwndNext
)
819 if (Child
->style
& WS_VISIBLE
)
822 * Recursive call to update children hrgnUpdate
824 PREGION RgnTemp
= IntSysCreateRectpRgn(0, 0, 0, 0);
827 if (Rgn
> PRGN_WINDOW
) IntGdiCombineRgn(RgnTemp
, Rgn
, 0, RGN_COPY
);
828 IntInvalidateWindows(Child
, ((Rgn
> PRGN_WINDOW
)?RgnTemp
:Rgn
), Flags
);
829 REGION_Delete(RgnTemp
);
834 TRACE("IntInvalidateWindows exit\n");
838 * IntIsWindowDrawable
841 * Window is drawable when it is visible and all parents are not
846 IntIsWindowDrawable(PWND Wnd
)
850 for (WndObject
= Wnd
; WndObject
!= NULL
; WndObject
= WndObject
->spwndParent
)
852 if ( WndObject
->state2
& WNDS2_INDESTROY
||
853 WndObject
->state
& WNDS_DESTROYED
||
855 !(WndObject
->style
& WS_VISIBLE
) ||
856 ((WndObject
->style
& WS_MINIMIZE
) && (WndObject
!= Wnd
)))
868 * Internal version of NtUserRedrawWindow that takes WND as
875 const RECTL
* UpdateRect
,
879 PREGION TmpRgn
= NULL
;
880 TRACE("co_UserRedrawWindow start Rgn %p\n",UpdateRgn
);
884 * Validation of passed parameters.
887 if (!IntIsWindowDrawable(Window
))
889 return TRUE
; // Just do nothing!!!
894 Window
= UserGetDesktopWindow();
899 * Transform the parameters UpdateRgn and UpdateRect into
900 * a region hRgn specified in screen coordinates.
903 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
)) // Both are OKAY!
905 /* We can't hold lock on GDI objects while doing roundtrips to user mode,
906 * so use a copy instead */
909 TmpRgn
= IntSysCreateRectpRgn(0, 0, 0, 0);
911 if (UpdateRgn
> PRGN_WINDOW
)
913 IntGdiCombineRgn(TmpRgn
, UpdateRgn
, NULL
, RGN_COPY
);
916 if (Window
!= UserGetDesktopWindow())
918 REGION_bOffsetRgn(TmpRgn
, Window
->rcClient
.left
, Window
->rcClient
.top
);
923 if (UpdateRect
!= NULL
)
925 if (Window
== UserGetDesktopWindow())
927 TmpRgn
= IntSysCreateRectpRgnIndirect(UpdateRect
);
931 TmpRgn
= IntSysCreateRectpRgn(Window
->rcClient
.left
+ UpdateRect
->left
,
932 Window
->rcClient
.top
+ UpdateRect
->top
,
933 Window
->rcClient
.left
+ UpdateRect
->right
,
934 Window
->rcClient
.top
+ UpdateRect
->bottom
);
939 if ((Flags
& (RDW_INVALIDATE
| RDW_FRAME
)) == (RDW_INVALIDATE
| RDW_FRAME
) ||
940 (Flags
& (RDW_VALIDATE
| RDW_NOFRAME
)) == (RDW_VALIDATE
| RDW_NOFRAME
))
942 if (!RECTL_bIsEmptyRect(&Window
->rcWindow
))
943 TmpRgn
= IntSysCreateRectpRgnIndirect(&Window
->rcWindow
);
947 if (!RECTL_bIsEmptyRect(&Window
->rcClient
))
948 TmpRgn
= IntSysCreateRectpRgnIndirect(&Window
->rcClient
);
954 /* Fixes test RDW_INTERNALPAINT behavior */
957 TmpRgn
= PRGN_WINDOW
; // Need a region so the bits can be set!!!
962 * Adjust the window update region depending on hRgn and flags.
965 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
| RDW_INTERNALPAINT
| RDW_NOINTERNALPAINT
) &&
968 IntInvalidateWindows(Window
, TmpRgn
, Flags
);
973 * Repaint and erase windows if needed.
976 if (Flags
& RDW_UPDATENOW
)
978 UserUpdateWindows(Window
, Flags
);
980 else if (Flags
& RDW_ERASENOW
)
982 if ((Flags
& (RDW_NOCHILDREN
|RDW_ALLCHILDREN
)) == 0)
983 Flags
|= RDW_CLIPCHILDREN
;
985 UserSyncAndPaintWindows(Window
, Flags
);
993 if (TmpRgn
> PRGN_WINDOW
)
995 REGION_Delete(TmpRgn
);
997 TRACE("co_UserRedrawWindow exit\n");
1003 PaintSuspendedWindow(PWND pwnd
, HRGN hrgnOrig
)
1005 if (pwnd
->hrgnUpdate
)
1008 INT Flags
= DC_NC
|DC_NOSENDMSG
;
1014 if (pwnd
->hrgnUpdate
> HRGN_WINDOW
)
1016 hrgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
1017 type
= NtGdiCombineRgn( hrgnTemp
, pwnd
->hrgnUpdate
, 0, RGN_COPY
);
1020 GreDeleteObject(hrgnTemp
);
1021 hrgnTemp
= HRGN_WINDOW
;
1026 hrgnTemp
= GreCreateRectRgnIndirect(&pwnd
->rcWindow
);
1030 hrgnTemp
> HRGN_WINDOW
&&
1031 NtGdiCombineRgn(hrgnTemp
, hrgnTemp
, hrgnOrig
, RGN_AND
) == NULLREGION
)
1033 GreDeleteObject(hrgnTemp
);
1037 hDC
= UserGetDCEx(pwnd
, hrgnTemp
, DCX_WINDOW
|DCX_INTERSECTRGN
|DCX_USESTYLE
|DCX_KEEPCLIPRGN
);
1039 Rect
= pwnd
->rcWindow
;
1040 RECTL_vOffsetRect(&Rect
, -pwnd
->rcWindow
.left
, -pwnd
->rcWindow
.top
);
1042 // Clear out client area!
1043 FillRect(hDC
, &Rect
, IntGetSysColorBrush(COLOR_WINDOW
));
1045 NC_DoNCPaint(pwnd
, hDC
, Flags
); // Redraw without MENUs.
1047 UserReleaseDC(pwnd
, hDC
, FALSE
);
1049 prgn
= REGION_LockRgn(hrgnTemp
);
1050 IntInvalidateWindows(pwnd
, prgn
, RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ALLCHILDREN
);
1051 REGION_UnlockRgn(prgn
);
1053 // Set updates for this window.
1054 pwnd
->state
|= WNDS_SENDNCPAINT
|WNDS_SENDERASEBACKGROUND
|WNDS_UPDATEDIRTY
;
1056 // DCX_KEEPCLIPRGN is set. Check it anyway.
1057 if (hrgnTemp
> HRGN_WINDOW
&& GreIsHandleValid(hrgnTemp
)) GreDeleteObject(hrgnTemp
);
1062 UpdateTheadChildren(PWND pWnd
, HRGN hRgn
)
1064 PaintSuspendedWindow( pWnd
, hRgn
);
1066 if (!(pWnd
->style
& WS_CLIPCHILDREN
))
1069 pWnd
= pWnd
->spwndChild
; // invalidate children if any.
1072 UpdateTheadChildren( pWnd
, hRgn
);
1073 pWnd
= pWnd
->spwndNext
;
1078 UpdateThreadWindows(PWND pWnd
, PTHREADINFO pti
, HRGN hRgn
)
1082 for ( pwndTemp
= pWnd
;
1084 pwndTemp
= pwndTemp
->spwndNext
)
1086 if (pwndTemp
->head
.pti
== pti
)
1088 UserUpdateWindows(pwndTemp
, RDW_ALLCHILDREN
);
1092 if (IsThreadSuspended(pwndTemp
->head
.pti
) || MsqIsHung(pwndTemp
->head
.pti
))
1094 UpdateTheadChildren(pwndTemp
, hRgn
);
1097 UserUpdateWindows(pwndTemp
, RDW_ALLCHILDREN
);
1103 IntIsWindowDirty(PWND Wnd
)
1105 return ( Wnd
->style
& WS_VISIBLE
&&
1106 ( Wnd
->hrgnUpdate
!= NULL
||
1107 Wnd
->state
& WNDS_INTERNALPAINT
) );
1111 Conditions to paint any window:
1113 1. Update region is not null.
1114 2. Internal paint flag is set.
1115 3. Paint count is not zero.
1119 IntFindWindowToRepaint(PWND Window
, PTHREADINFO Thread
)
1124 for (; Window
!= NULL
; Window
= Window
->spwndNext
)
1126 if (IntWndBelongsToThread(Window
, Thread
))
1128 if (IntIsWindowDirty(Window
))
1130 /* Make sure all non-transparent siblings are already drawn. */
1131 if (Window
->ExStyle
& WS_EX_TRANSPARENT
)
1133 for (TempWindow
= Window
->spwndNext
; TempWindow
!= NULL
;
1134 TempWindow
= TempWindow
->spwndNext
)
1136 if (!(TempWindow
->ExStyle
& WS_EX_TRANSPARENT
) &&
1137 IntWndBelongsToThread(TempWindow
, Thread
) &&
1138 IntIsWindowDirty(TempWindow
))
1147 /* find a child of the specified window that needs repainting */
1148 if (Window
->spwndChild
)
1150 hChild
= IntFindWindowToRepaint(Window
->spwndChild
, Thread
);
1159 // Internal painting of windows.
1162 IntPaintWindow( PWND Window
)
1164 // Handle normal painting.
1165 co_IntPaintWindows( Window
, RDW_NOCHILDREN
, FALSE
);
1177 PWND PaintWnd
, StartWnd
;
1179 if ((MsgFilterMin
!= 0 || MsgFilterMax
!= 0) &&
1180 (MsgFilterMin
> WM_PAINT
|| MsgFilterMax
< WM_PAINT
))
1183 if (Thread
->TIF_flags
& TIF_SYSTEMTHREAD
)
1185 ERR("WM_PAINT is in a System Thread!\n");
1188 StartWnd
= UserGetDesktopWindow();
1189 PaintWnd
= IntFindWindowToRepaint(StartWnd
, Thread
);
1191 Message
->hwnd
= PaintWnd
? UserHMGetHandle(PaintWnd
) : NULL
;
1193 if (Message
->hwnd
== NULL
&& Thread
->cPaintsReady
)
1195 // Find note in window.c:"PAINTING BUG".
1196 ERR("WARNING SOMETHING HAS GONE WRONG: Thread marked as containing dirty windows, but no dirty windows found! Counts %u\n",Thread
->cPaintsReady
);
1197 /* Hack to stop spamming the debug log ! */
1198 Thread
->cPaintsReady
= 0;
1202 if (Message
->hwnd
== NULL
)
1205 if (!(Window
== NULL
||
1206 PaintWnd
== Window
||
1207 IntIsChildWindow(Window
, PaintWnd
))) /* check that it is a child of the specified parent */
1210 if (PaintWnd
->state
& WNDS_INTERNALPAINT
)
1212 PaintWnd
->state
&= ~WNDS_INTERNALPAINT
;
1213 if (!PaintWnd
->hrgnUpdate
)
1214 MsqDecPaintCountQueue(Thread
);
1216 PaintWnd
->state2
&= ~WNDS2_STARTPAINT
;
1217 PaintWnd
->state
&= ~WNDS_UPDATEDIRTY
;
1220 while (Window
&& !UserIsDesktopWindow(Window
))
1222 // Role back and check for clip children, do not set if any.
1223 if (Window
->spwndParent
&& !(Window
->spwndParent
->style
& WS_CLIPCHILDREN
))
1225 PaintWnd
->state2
|= WNDS2_WMPAINTSENT
;
1227 Window
= Window
->spwndParent
;
1230 Message
->wParam
= Message
->lParam
= 0;
1231 Message
->message
= WM_PAINT
;
1243 INT cx
, cy
, xSrc
, ySrc
;
1245 if ( nFlags
& PW_CLIENTONLY
)
1247 cx
= pwnd
->rcClient
.right
- pwnd
->rcClient
.left
;
1248 cy
= pwnd
->rcClient
.bottom
- pwnd
->rcClient
.top
;
1249 xSrc
= pwnd
->rcClient
.left
- pwnd
->rcWindow
.left
;
1250 ySrc
= pwnd
->rcClient
.top
- pwnd
->rcWindow
.top
;
1254 cx
= pwnd
->rcWindow
.right
- pwnd
->rcWindow
.left
;
1255 cy
= pwnd
->rcWindow
.bottom
- pwnd
->rcWindow
.top
;
1260 // TODO: Setup Redirection for Print.
1263 /* Update the window just incase. */
1264 co_IntUpdateWindows( pwnd
, RDW_ALLCHILDREN
, FALSE
);
1266 hdcSrc
= UserGetDCEx( pwnd
, NULL
, DCX_CACHE
|DCX_WINDOW
);
1267 /* Print window to printer context. */
1268 NtGdiBitBlt( hdcBlt
,
1280 UserReleaseDC( pwnd
, hdcSrc
, FALSE
);
1282 // TODO: Release Redirection from Print.
1289 IntFlashWindowEx(PWND pWnd
, PFLASHWINFO pfwi
)
1291 DWORD_PTR FlashState
;
1292 UINT uCount
= pfwi
->uCount
;
1293 BOOL Activate
= FALSE
, Ret
= FALSE
;
1297 FlashState
= (DWORD_PTR
)UserGetProp(pWnd
, AtomFlashWndState
, TRUE
);
1299 if (FlashState
== FLASHW_FINISHED
)
1301 // Cycle has finished, kill timer and set this to Stop.
1302 FlashState
|= FLASHW_KILLSYSTIMER
;
1303 pfwi
->dwFlags
= FLASHW_STOP
;
1309 if (pfwi
->dwFlags
== FLASHW_SYSTIMER
)
1311 // Called from system timer, restore flags, counts and state.
1312 pfwi
->dwFlags
= LOWORD(FlashState
);
1313 uCount
= HIWORD(FlashState
);
1314 FlashState
= MAKELONG(LOWORD(FlashState
),0);
1318 // Clean out the trash! Fix SeaMonkey crash after restart.
1323 if (FlashState
== 0)
1324 { // First time in cycle, setup flash state.
1325 if ( pWnd
->state
& WNDS_ACTIVEFRAME
||
1326 (pfwi
->dwFlags
& FLASHW_CAPTION
&& pWnd
->style
& (WS_BORDER
|WS_DLGFRAME
)))
1328 FlashState
= FLASHW_STARTED
|FLASHW_ACTIVE
;
1332 // Set previous window state.
1333 Ret
= !!(FlashState
& FLASHW_ACTIVE
);
1335 if ( (pfwi
->dwFlags
& FLASHW_TIMERNOFG
) == FLASHW_TIMERNOFG
&&
1336 gpqForeground
== pWnd
->head
.pti
->MessageQueue
)
1338 // Flashing until foreground, set this to Stop.
1339 pfwi
->dwFlags
= FLASHW_STOP
;
1343 // Toggle activate flag.
1344 if ( pfwi
->dwFlags
== FLASHW_STOP
)
1346 if (gpqForeground
&& gpqForeground
->spwndActive
== pWnd
)
1353 Activate
= (FlashState
& FLASHW_ACTIVE
) == 0;
1356 if ( pfwi
->dwFlags
== FLASHW_STOP
|| pfwi
->dwFlags
& FLASHW_CAPTION
)
1358 co_IntSendMessage(UserHMGetHandle(pWnd
), WM_NCACTIVATE
, Activate
, 0);
1361 // FIXME: Check for a Stop Sign here.
1362 if ( pfwi
->dwFlags
& FLASHW_TRAY
)
1364 // Need some shell work here too.
1365 TRACE("FIXME: Flash window no Tray support!\n");
1368 if ( pfwi
->dwFlags
== FLASHW_STOP
)
1370 if (FlashState
& FLASHW_KILLSYSTIMER
)
1372 IntKillTimer(pWnd
, ID_EVENT_SYSTIMER_FLASHWIN
, TRUE
);
1375 UserRemoveProp(pWnd
, AtomFlashWndState
, TRUE
);
1378 { // Have a count and started, set timer.
1381 FlashState
|= FLASHW_COUNT
;
1383 if (!(Activate
^ !!(FlashState
& FLASHW_STARTED
)))
1386 if (!(FlashState
& FLASHW_KILLSYSTIMER
))
1387 pfwi
->dwFlags
|= FLASHW_TIMER
;
1390 if (pfwi
->dwFlags
& FLASHW_TIMER
)
1392 FlashState
|= FLASHW_KILLSYSTIMER
;
1395 ID_EVENT_SYSTIMER_FLASHWIN
,
1396 pfwi
->dwTimeout
? pfwi
->dwTimeout
: gpsi
->dtCaretBlink
,
1401 if (FlashState
& FLASHW_COUNT
&& uCount
== 0)
1403 // Keep spinning? Nothing else to do.
1404 FlashState
= FLASHW_FINISHED
;
1408 // Save state and flags so this can be restored next time through.
1409 FlashState
^= (FlashState
^ -!!(Activate
)) & FLASHW_ACTIVE
;
1410 FlashState
^= (FlashState
^ pfwi
->dwFlags
) & (FLASHW_MASK
& ~FLASHW_TIMER
);
1412 FlashState
= MAKELONG(LOWORD(FlashState
),uCount
);
1413 UserSetProp(pWnd
, AtomFlashWndState
, (HANDLE
)FlashState
, TRUE
);
1419 IntBeginPaint(PWND Window
, PPAINTSTRUCT Ps
)
1425 co_UserHideCaret(Window
);
1427 Window
->state2
|= WNDS2_STARTPAINT
;
1428 Window
->state
&= ~WNDS_PAINTNOTPROCESSED
;
1430 if (Window
->state
& WNDS_SENDNCPAINT
)
1433 // Application can keep update dirty.
1436 Window
->state
&= ~WNDS_UPDATEDIRTY
;
1437 hRgn
= IntGetNCUpdateRgn(Window
, FALSE
);
1438 IntSendNCPaint(Window
, hRgn
);
1439 if (hRgn
> HRGN_WINDOW
&& GreIsHandleValid(hRgn
))
1441 /* NOTE: The region can already be deleted! */
1442 GreDeleteObject(hRgn
);
1445 while(Window
->state
& WNDS_UPDATEDIRTY
);
1449 Window
->state
&= ~WNDS_UPDATEDIRTY
;
1452 RtlZeroMemory(Ps
, sizeof(PAINTSTRUCT
));
1454 if (Window
->state2
& WNDS2_ENDPAINTINVALIDATE
)
1456 ERR("BP: Another thread invalidated this window\n");
1459 Ps
->hdc
= UserGetDCEx( Window
,
1461 DCX_INTERSECTRGN
| DCX_USESTYLE
);
1467 // If set, always clear flags out due to the conditions later on for sending the message.
1468 if (Window
->state
& WNDS_SENDERASEBACKGROUND
)
1470 Window
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
1474 if (Window
->hrgnUpdate
!= NULL
)
1476 MsqDecPaintCountQueue(Window
->head
.pti
);
1477 IntGdiSetRegionOwner(Window
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
1478 /* The region is part of the dc now and belongs to the process! */
1479 Window
->hrgnUpdate
= NULL
;
1483 if (Window
->state
& WNDS_INTERNALPAINT
)
1484 MsqDecPaintCountQueue(Window
->head
.pti
);
1487 type
= GdiGetClipBox(Ps
->hdc
, &Ps
->rcPaint
);
1489 IntGetClientRect(Window
, &Rect
);
1491 Window
->state
&= ~WNDS_INTERNALPAINT
;
1493 if ( Erase
&& // Set to erase,
1494 type
!= NULLREGION
&& // don't erase if the clip box is empty,
1495 (!(Window
->pcls
->style
& CS_PARENTDC
) || // not parent dc or
1496 RECTL_bIntersectRect( &Rect
, &Rect
, &Ps
->rcPaint
) ) ) // intersecting.
1498 Ps
->fErase
= !co_IntSendMessage(UserHMGetHandle(Window
), WM_ERASEBKGND
, (WPARAM
)Ps
->hdc
, 0);
1501 Window
->state
|= (WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
1509 IntSendChildNCPaint(Window
);
1515 IntEndPaint(PWND Wnd
, PPAINTSTRUCT Ps
)
1521 UserReleaseDC(Wnd
, hdc
, TRUE
);
1523 if (Wnd
->state2
& WNDS2_ENDPAINTINVALIDATE
)
1525 ERR("EP: Another thread invalidated this window\n");
1526 Wnd
->state2
&= ~WNDS2_ENDPAINTINVALIDATE
;
1529 Wnd
->state2
&= ~(WNDS2_WMPAINTSENT
|WNDS2_STARTPAINT
);
1531 co_UserShowCaret(Wnd
);
1537 IntFillWindow(PWND pWndParent
,
1548 type
= GdiGetClipBox(hDC
, &Rect
);
1550 IntGetClientRect(pWnd
, &Rect1
);
1552 if ( type
!= NULLREGION
&& // Clip box is not empty,
1553 (!(pWnd
->pcls
->style
& CS_PARENTDC
) || // not parent dc or
1554 RECTL_bIntersectRect( &Rect
, &Rect
, &Rect1
) ) ) // intersecting.
1559 if (!UserIsDesktopWindow(pWndParent
))
1561 x
= pWndParent
->rcClient
.left
- pWnd
->rcClient
.left
;
1562 y
= pWndParent
->rcClient
.top
- pWnd
->rcClient
.top
;
1565 GreSetBrushOrg(hDC
, x
, y
, &ppt
);
1567 if ( hBrush
< (HBRUSH
)CTLCOLOR_MAX
)
1568 hBrush
= GetControlColor( pWndParent
, pWnd
, hDC
, HandleToUlong(hBrush
) + WM_CTLCOLORMSGBOX
);
1570 FillRect(hDC
, &Rect
, hBrush
);
1572 GreSetBrushOrg(hDC
, ppt
.x
, ppt
.y
, NULL
);
1580 /* PUBLIC FUNCTIONS ***********************************************************/
1590 NtUserBeginPaint(HWND hWnd
, PAINTSTRUCT
* UnsafePs
)
1596 USER_REFERENCE_ENTRY Ref
;
1597 DECLARE_RETURN(HDC
);
1599 TRACE("Enter NtUserBeginPaint\n");
1600 UserEnterExclusive();
1602 if (!(Window
= UserGetWindowObject(hWnd
)))
1607 UserRefObjectCo(Window
, &Ref
);
1609 hDC
= IntBeginPaint(Window
, &Ps
);
1611 Status
= MmCopyToCaller(UnsafePs
, &Ps
, sizeof(PAINTSTRUCT
));
1612 if (! NT_SUCCESS(Status
))
1614 SetLastNtError(Status
);
1621 if (Window
) UserDerefObjectCo(Window
);
1623 TRACE("Leave NtUserBeginPaint, ret=%p\n",_ret_
);
1637 NtUserEndPaint(HWND hWnd
, CONST PAINTSTRUCT
* pUnsafePs
)
1639 NTSTATUS Status
= STATUS_SUCCESS
;
1642 USER_REFERENCE_ENTRY Ref
;
1643 DECLARE_RETURN(BOOL
);
1645 TRACE("Enter NtUserEndPaint\n");
1646 UserEnterExclusive();
1648 if (!(Window
= UserGetWindowObject(hWnd
)))
1653 UserRefObjectCo(Window
, &Ref
); // Here for the exception.
1657 ProbeForRead(pUnsafePs
, sizeof(*pUnsafePs
), 1);
1658 RtlCopyMemory(&Ps
, pUnsafePs
, sizeof(PAINTSTRUCT
));
1660 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1662 Status
= _SEH2_GetExceptionCode();
1665 if (!NT_SUCCESS(Status
))
1670 RETURN(IntEndPaint(Window
, &Ps
));
1673 if (Window
) UserDerefObjectCo(Window
);
1675 TRACE("Leave NtUserEndPaint, ret=%i\n",_ret_
);
1681 * FillWindow: Called from User; Dialog, Edit and ListBox procs during a WM_ERASEBKGND.
1687 NtUserFillWindow(HWND hWndParent
,
1693 PWND pWnd
, pWndParent
= NULL
;
1694 USER_REFERENCE_ENTRY Ref
;
1696 TRACE("Enter NtUserFillWindow\n");
1697 UserEnterExclusive();
1704 if (!(pWnd
= UserGetWindowObject(hWnd
)))
1709 if (hWndParent
&& !(pWndParent
= UserGetWindowObject(hWndParent
)))
1714 UserRefObjectCo(pWnd
, &Ref
);
1715 ret
= IntFillWindow( pWndParent
, pWnd
, hDC
, hBrush
);
1716 UserDerefObjectCo(pWnd
);
1719 TRACE("Leave NtUserFillWindow, ret=%i\n",ret
);
1728 NtUserFlashWindowEx(IN PFLASHWINFO pfwi
)
1731 FLASHWINFO finfo
= {0};
1734 UserEnterExclusive();
1738 ProbeForRead(pfwi
, sizeof(FLASHWINFO
), 1);
1739 RtlCopyMemory(&finfo
, pfwi
, sizeof(FLASHWINFO
));
1741 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1743 SetLastNtError(_SEH2_GetExceptionCode());
1744 _SEH2_YIELD(goto Exit
);
1748 if (!( pWnd
= ValidateHwndNoErr(finfo
.hwnd
)) ||
1749 finfo
.cbSize
!= sizeof(FLASHWINFO
) ||
1750 finfo
.dwFlags
& ~(FLASHW_ALL
|FLASHW_TIMER
|FLASHW_TIMERNOFG
) )
1752 EngSetLastError(ERROR_INVALID_PARAMETER
);
1756 Ret
= IntFlashWindowEx(pWnd
, &finfo
);
1764 GetUpdateRgn, this fails the same as the old one.
1767 co_UserGetUpdateRgn(PWND Window
, HRGN hRgn
, BOOL bErase
)
1773 ASSERT_REFS_CO(Window
);
1777 USER_REFERENCE_ENTRY Ref
;
1778 UserRefObjectCo(Window
, &Ref
);
1779 co_IntPaintWindows(Window
, RDW_NOCHILDREN
, FALSE
);
1780 UserDerefObjectCo(Window
);
1783 Window
->state
&= ~WNDS_UPDATEDIRTY
;
1785 if (Window
->hrgnUpdate
== NULL
)
1787 NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0);
1791 Rect
= Window
->rcClient
;
1792 Type
= IntIntersectWithParents(Window
, &Rect
);
1794 if (Window
->hrgnUpdate
== HRGN_WINDOW
)
1797 ERR("GURn: Caller is passing Window Region 1\n");
1800 NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0);
1804 RegionType
= SIMPLEREGION
;
1806 if (!UserIsDesktopWindow(Window
))
1808 RECTL_vOffsetRect(&Rect
,
1809 -Window
->rcClient
.left
,
1810 -Window
->rcClient
.top
);
1812 GreSetRectRgnIndirect(hRgn
, &Rect
);
1816 HRGN hrgnTemp
= GreCreateRectRgnIndirect(&Rect
);
1818 RegionType
= NtGdiCombineRgn(hRgn
, hrgnTemp
, Window
->hrgnUpdate
, RGN_AND
);
1820 if (RegionType
== ERROR
|| RegionType
== NULLREGION
)
1822 if (hrgnTemp
) GreDeleteObject(hrgnTemp
);
1823 NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0);
1827 if (!UserIsDesktopWindow(Window
))
1829 NtGdiOffsetRgn(hRgn
,
1830 -Window
->rcClient
.left
,
1831 -Window
->rcClient
.top
);
1833 if (hrgnTemp
) GreDeleteObject(hrgnTemp
);
1839 co_UserGetUpdateRect(PWND Window
, PRECT pRect
, BOOL bErase
)
1846 USER_REFERENCE_ENTRY Ref
;
1847 UserRefObjectCo(Window
, &Ref
);
1848 co_IntPaintWindows(Window
, RDW_NOCHILDREN
, FALSE
);
1849 UserDerefObjectCo(Window
);
1852 Window
->state
&= ~WNDS_UPDATEDIRTY
;
1854 if (Window
->hrgnUpdate
== NULL
)
1856 pRect
->left
= pRect
->top
= pRect
->right
= pRect
->bottom
= 0;
1861 /* Get the update region bounding box. */
1862 if (Window
->hrgnUpdate
== HRGN_WINDOW
)
1864 *pRect
= Window
->rcClient
;
1865 ERR("GURt: Caller is retrieving Window Region 1\n");
1869 RegionType
= IntGdiGetRgnBox(Window
->hrgnUpdate
, pRect
);
1871 if (RegionType
!= ERROR
&& RegionType
!= NULLREGION
)
1872 RECTL_bIntersectRect(pRect
, pRect
, &Window
->rcClient
);
1875 if (IntIntersectWithParents(Window
, pRect
))
1877 if (!UserIsDesktopWindow(Window
))
1879 RECTL_vOffsetRect(pRect
,
1880 -Window
->rcClient
.left
,
1881 -Window
->rcClient
.top
);
1883 if (Window
->pcls
->style
& CS_OWNDC
)
1887 hdc
= UserGetDCEx(Window
, NULL
, DCX_USESTYLE
);
1888 //layout = NtGdiSetLayout(hdc, -1, 0);
1889 //IntMapWindowPoints( 0, Window, (LPPOINT)pRect, 2 );
1890 GreDPtoLP( hdc
, (LPPOINT
)pRect
, 2 );
1891 //NtGdiSetLayout(hdc, -1, layout);
1892 UserReleaseDC(Window
, hdc
, FALSE
);
1897 pRect
->left
= pRect
->top
= pRect
->right
= pRect
->bottom
= 0;
1904 * NtUserGetUpdateRgn
1911 NtUserGetUpdateRgn(HWND hWnd
, HRGN hRgn
, BOOL bErase
)
1913 DECLARE_RETURN(INT
);
1917 TRACE("Enter NtUserGetUpdateRgn\n");
1918 UserEnterExclusive();
1920 if (!(Window
= UserGetWindowObject(hWnd
)))
1925 ret
= co_UserGetUpdateRgn(Window
, hRgn
, bErase
);
1930 TRACE("Leave NtUserGetUpdateRgn, ret=%i\n",_ret_
);
1936 * NtUserGetUpdateRect
1943 NtUserGetUpdateRect(HWND hWnd
, LPRECT UnsafeRect
, BOOL bErase
)
1949 DECLARE_RETURN(BOOL
);
1951 TRACE("Enter NtUserGetUpdateRect\n");
1952 UserEnterExclusive();
1954 if (!(Window
= UserGetWindowObject(hWnd
)))
1959 Ret
= co_UserGetUpdateRect(Window
, &Rect
, bErase
);
1961 if (UnsafeRect
!= NULL
)
1963 Status
= MmCopyToCaller(UnsafeRect
, &Rect
, sizeof(RECTL
));
1964 if (!NT_SUCCESS(Status
))
1966 EngSetLastError(ERROR_INVALID_PARAMETER
);
1974 TRACE("Leave NtUserGetUpdateRect, ret=%i\n",_ret_
);
1980 * NtUserRedrawWindow
1989 CONST RECT
*lprcUpdate
,
1993 RECTL SafeUpdateRect
;
1996 USER_REFERENCE_ENTRY Ref
;
1997 NTSTATUS Status
= STATUS_SUCCESS
;
1998 PREGION RgnUpdate
= NULL
;
1999 DECLARE_RETURN(BOOL
);
2001 TRACE("Enter NtUserRedrawWindow\n");
2002 UserEnterExclusive();
2004 if (!(Wnd
= UserGetWindowObject(hWnd
? hWnd
: IntGetDesktopWindow())))
2013 ProbeForRead(lprcUpdate
, sizeof(RECTL
), 1);
2014 RtlCopyMemory(&SafeUpdateRect
, lprcUpdate
, sizeof(RECTL
));
2016 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2018 Status
= _SEH2_GetExceptionCode();
2021 if (!NT_SUCCESS(Status
))
2023 EngSetLastError(RtlNtStatusToDosError(Status
));
2028 if ( flags
& ~(RDW_ERASE
|RDW_FRAME
|RDW_INTERNALPAINT
|RDW_INVALIDATE
|
2029 RDW_NOERASE
|RDW_NOFRAME
|RDW_NOINTERNALPAINT
|RDW_VALIDATE
|
2030 RDW_ERASENOW
|RDW_UPDATENOW
|RDW_ALLCHILDREN
|RDW_NOCHILDREN
) )
2032 /* RedrawWindow fails only in case that flags are invalid */
2033 EngSetLastError(ERROR_INVALID_FLAGS
);
2037 /* We can't hold lock on GDI objects while doing roundtrips to user mode,
2038 * so it will be copied.
2040 if (hrgnUpdate
> HRGN_WINDOW
)
2042 RgnUpdate
= REGION_LockRgn(hrgnUpdate
);
2045 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2048 REGION_UnlockRgn(RgnUpdate
);
2050 else if (hrgnUpdate
== HRGN_WINDOW
) // Trap it out.
2052 ERR("NTRW: Caller is passing Window Region 1\n");
2055 UserRefObjectCo(Wnd
, &Ref
);
2057 Ret
= co_UserRedrawWindow( Wnd
,
2058 lprcUpdate
? &SafeUpdateRect
: NULL
,
2062 UserDerefObjectCo(Wnd
);
2067 TRACE("Leave NtUserRedrawWindow, ret=%i\n",_ret_
);
2073 UserDrawCaptionText(
2076 const PUNICODE_STRING Text
,
2081 HFONT hOldFont
= NULL
;
2082 COLORREF OldTextColor
;
2083 NONCLIENTMETRICSW nclm
;
2085 BOOLEAN bDeleteFont
= FALSE
;
2088 ULONG fit
= 0, Length
;
2091 TRACE("UserDrawCaptionText: %wZ\n", Text
);
2093 nclm
.cbSize
= sizeof(nclm
);
2094 if (!UserSystemParametersInfo(SPI_GETNONCLIENTMETRICS
, nclm
.cbSize
, &nclm
, 0))
2096 ERR("UserSystemParametersInfo() failed!\n");
2102 if(uFlags
& DC_SMALLCAP
)
2103 Status
= TextIntCreateFontIndirect(&nclm
.lfSmCaptionFont
, &hFont
);
2105 Status
= TextIntCreateFontIndirect(&nclm
.lfCaptionFont
, &hFont
);
2107 if(!NT_SUCCESS(Status
))
2109 ERR("TextIntCreateFontIndirect() failed! Status: 0x%x\n", Status
);
2116 IntGdiSetBkMode(hDc
, TRANSPARENT
);
2118 hOldFont
= NtGdiSelectFont(hDc
, hFont
);
2120 if(uFlags
& DC_INBUTTON
)
2121 OldTextColor
= IntGdiSetTextColor(hDc
, IntGetSysColor(COLOR_BTNTEXT
));
2123 OldTextColor
= IntGdiSetTextColor(hDc
,
2124 IntGetSysColor(uFlags
& DC_ACTIVE
? COLOR_CAPTIONTEXT
: COLOR_INACTIVECAPTIONTEXT
));
2126 // Adjust for system menu.
2127 if (pWnd
&& pWnd
->style
& WS_SYSMENU
)
2129 r
.right
-= UserGetSystemMetrics(SM_CYCAPTION
) - 1;
2130 if ((pWnd
->style
& (WS_MAXIMIZEBOX
| WS_MINIMIZEBOX
)) && !(pWnd
->ExStyle
& WS_EX_TOOLWINDOW
))
2132 r
.right
-= UserGetSystemMetrics(SM_CXSIZE
) + 1;
2133 r
.right
-= UserGetSystemMetrics(SM_CXSIZE
) + 1;
2137 GreGetTextExtentExW(hDc
, Text
->Buffer
, Text
->Length
/sizeof(WCHAR
), r
.right
- r
.left
, &fit
, 0, &Size
, 0);
2139 Length
= (Text
->Length
/sizeof(WCHAR
) == fit
? fit
: fit
+1);
2141 if (Text
->Length
/sizeof(WCHAR
) > Length
)
2147 { // Faster while in setup.
2148 GreExtTextOutW( hDc
,
2150 lpRc
->top
+ (lpRc
->bottom
- lpRc
->top
- Size
.cy
) / 2, // DT_SINGLELINE && DT_VCENTER
2162 Text
->Length
/sizeof(WCHAR
),
2164 DT_END_ELLIPSIS
|DT_SINGLELINE
|DT_VCENTER
|DT_NOPREFIX
|DT_LEFT
);
2167 IntGdiSetTextColor(hDc
, OldTextColor
);
2170 NtGdiSelectFont(hDc
, hOldFont
);
2173 GreDeleteObject(hFont
);
2179 // This draws Buttons, Icons and Text...
2181 BOOL
UserDrawCaption(
2187 const PUNICODE_STRING Str
,
2191 HBRUSH hBgBrush
, hOldBrush
= NULL
;
2195 RECTL_vMakeWellOrdered(lpRc
);
2197 /* Determine whether the icon needs to be displayed */
2198 if (!hIcon
&& pWnd
!= NULL
)
2200 HasIcon
= (uFlags
& DC_ICON
) && !(uFlags
& DC_SMALLCAP
) &&
2201 (pWnd
->style
& WS_SYSMENU
) && !(pWnd
->ExStyle
& WS_EX_TOOLWINDOW
);
2204 HasIcon
= (hIcon
!= NULL
);
2206 // Draw the caption background
2207 if((uFlags
& DC_GRADIENT
) && !(uFlags
& DC_INBUTTON
))
2209 static GRADIENT_RECT gcap
= {0, 1};
2210 TRIVERTEX Vertices
[2];
2213 Colors
[0] = IntGetSysColor((uFlags
& DC_ACTIVE
) ?
2214 COLOR_ACTIVECAPTION
: COLOR_INACTIVECAPTION
);
2216 Colors
[1] = IntGetSysColor((uFlags
& DC_ACTIVE
) ?
2217 COLOR_GRADIENTACTIVECAPTION
: COLOR_GRADIENTINACTIVECAPTION
);
2219 Vertices
[0].x
= Rect
.left
;
2220 Vertices
[0].y
= Rect
.top
;
2221 Vertices
[0].Red
= (WORD
)Colors
[0]<<8;
2222 Vertices
[0].Green
= (WORD
)Colors
[0] & 0xFF00;
2223 Vertices
[0].Blue
= (WORD
)(Colors
[0]>>8) & 0xFF00;
2224 Vertices
[0].Alpha
= 0;
2226 Vertices
[1].x
= Rect
.right
;
2227 Vertices
[1].y
= Rect
.bottom
;
2228 Vertices
[1].Red
= (WORD
)Colors
[1]<<8;
2229 Vertices
[1].Green
= (WORD
)Colors
[1] & 0xFF00;
2230 Vertices
[1].Blue
= (WORD
)(Colors
[1]>>8) & 0xFF00;
2231 Vertices
[1].Alpha
= 0;
2233 if(!GreGradientFill(hDc
, Vertices
, 2, &gcap
, 1, GRADIENT_FILL_RECT_H
))
2235 ERR("GreGradientFill() failed!\n");
2241 if(uFlags
& DC_INBUTTON
)
2242 hBgBrush
= IntGetSysColorBrush(COLOR_3DFACE
);
2243 else if(uFlags
& DC_ACTIVE
)
2244 hBgBrush
= IntGetSysColorBrush(COLOR_ACTIVECAPTION
);
2246 hBgBrush
= IntGetSysColorBrush(COLOR_INACTIVECAPTION
);
2248 hOldBrush
= NtGdiSelectBrush(hDc
, hBgBrush
);
2252 ERR("NtGdiSelectBrush() failed!\n");
2256 if(!NtGdiPatBlt(hDc
, Rect
.left
, Rect
.top
,
2257 Rect
.right
- Rect
.left
,
2258 Rect
.bottom
- Rect
.top
,
2261 ERR("NtGdiPatBlt() failed!\n");
2269 PCURICON_OBJECT pIcon
= NULL
;
2273 pIcon
= UserGetCurIconObject(hIcon
);
2277 pIcon
= NC_IconForWindow(pWnd
);
2278 // FIXME: NC_IconForWindow should reference it for us */
2280 UserReferenceObject(pIcon
);
2285 LONG cx
= UserGetSystemMetrics(SM_CXSMICON
);
2286 LONG cy
= UserGetSystemMetrics(SM_CYSMICON
);
2287 LONG x
= Rect
.left
- cx
/2 + 1 + (Rect
.bottom
- Rect
.top
)/2; // this is really what Window does
2288 LONG y
= (Rect
.top
+ Rect
.bottom
- cy
)/2; // center
2289 UserDrawIconEx(hDc
, x
, y
, pIcon
, cx
, cy
, 0, NULL
, DI_NORMAL
);
2290 UserDereferenceObject(pIcon
);
2299 Rect
.left
+= Rect
.bottom
- Rect
.top
;
2301 if((uFlags
& DC_TEXT
))
2307 Set
= UserDrawCaptionText(pWnd
, hDc
, Str
, &Rect
, uFlags
, hFont
);
2308 else if (pWnd
!= NULL
) // FIXME: Windows does not do that
2310 UNICODE_STRING ustr
;
2311 ustr
.Buffer
= pWnd
->strName
.Buffer
; // FIXME: LARGE_STRING truncated!
2312 ustr
.Length
= (USHORT
)min(pWnd
->strName
.Length
, MAXUSHORT
);
2313 ustr
.MaximumLength
= (USHORT
)min(pWnd
->strName
.MaximumLength
, MAXUSHORT
);
2314 Set
= UserDrawCaptionText(pWnd
, hDc
, &ustr
, &Rect
, uFlags
, hFont
);
2319 pWnd
->state2
&= ~WNDS2_CAPTIONTEXTTRUNCATED
;
2321 pWnd
->state2
|= WNDS2_CAPTIONTEXTTRUNCATED
;
2328 if (hOldBrush
) NtGdiSelectBrush(hDc
, hOldBrush
);
2335 UserRealizePalette(HDC hdc
)
2337 HWND hWnd
, hWndDesktop
;
2340 Ret
= IntGdiRealizePalette(hdc
);
2341 if (Ret
) // There was a change.
2343 hWnd
= IntWindowFromDC(hdc
);
2344 if (hWnd
) // Send broadcast if dc is associated with a window.
2345 { // FYI: Thread locked in CallOneParam.
2346 hWndDesktop
= IntGetDesktopWindow();
2347 if ( hWndDesktop
!= hWnd
)
2349 PWND pWnd
= UserGetWindowObject(hWndDesktop
);
2350 ERR("RealizePalette Desktop.");
2351 hdc
= UserGetWindowDC(pWnd
);
2352 IntPaintDesktop(hdc
);
2353 UserReleaseDC(pWnd
,hdc
,FALSE
);
2355 UserSendNotifyMessage((HWND
)HWND_BROADCAST
, WM_PALETTECHANGED
, (WPARAM
)hWnd
, 0);
2363 NtUserDrawCaptionTemp(
2369 const PUNICODE_STRING str
,
2373 UNICODE_STRING SafeStr
= {0};
2374 NTSTATUS Status
= STATUS_SUCCESS
;
2378 UserEnterExclusive();
2382 if(!(pWnd
= UserGetWindowObject(hWnd
)))
2391 ProbeForRead(lpRc
, sizeof(RECTL
), sizeof(ULONG
));
2392 RtlCopyMemory(&SafeRect
, lpRc
, sizeof(RECTL
));
2395 SafeStr
= ProbeForReadUnicodeString(str
);
2396 if (SafeStr
.Length
!= 0)
2398 ProbeForRead( SafeStr
.Buffer
,
2404 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2406 Status
= _SEH2_GetExceptionCode();
2410 if (Status
!= STATUS_SUCCESS
)
2412 SetLastNtError(Status
);
2418 Ret
= UserDrawCaption(pWnd
, hDC
, &SafeRect
, hFont
, hIcon
, &SafeStr
, uFlags
);
2421 if ( RECTL_bIsEmptyRect(&SafeRect
) && hFont
== 0 && hIcon
== 0 )
2424 if (uFlags
& DC_DRAWCAPTIONMD
)
2426 ERR("NC Caption Mode\n");
2427 UserDrawCaptionBar(pWnd
, hDC
, uFlags
);
2430 else if (uFlags
& DC_DRAWFRAMEMD
)
2432 ERR("NC Paint Mode\n");
2433 NC_DoNCPaint(pWnd
, hDC
, uFlags
); // Update Menus too!
2437 Ret
= UserDrawCaption(pWnd
, hDC
, &SafeRect
, hFont
, hIcon
, NULL
, uFlags
);
2446 NtUserDrawCaption(HWND hWnd
,
2451 return NtUserDrawCaptionTemp(hWnd
, hDC
, lpRc
, 0, 0, NULL
, uFlags
);
2455 co_UserExcludeUpdateRgn(HDC hDC
, PWND Window
)
2460 if (Window
->hrgnUpdate
)
2462 if (Window
->hrgnUpdate
== HRGN_WINDOW
)
2464 return NtGdiIntersectClipRect(hDC
, 0, 0, 0, 0);
2469 HRGN hrgn
= NtGdiCreateRectRgn(0,0,0,0);
2471 if ( hrgn
&& GreGetDCPoint( hDC
, GdiGetDCOrg
, &pt
) )
2473 if ( NtGdiGetRandomRgn( hDC
, hrgn
, CLIPRGN
) == NULLREGION
)
2475 NtGdiOffsetRgn(hrgn
, pt
.x
, pt
.y
);
2480 PMONITOR pm
= UserGetPrimaryMonitor();
2481 hrgnScreen
= NtGdiCreateRectRgn(0,0,0,0);
2482 NtGdiCombineRgn(hrgnScreen
, hrgnScreen
, pm
->hrgnMonitor
, RGN_OR
);
2484 NtGdiCombineRgn(hrgn
, hrgnScreen
, NULL
, RGN_COPY
);
2486 GreDeleteObject(hrgnScreen
);
2489 NtGdiCombineRgn(hrgn
, hrgn
, Window
->hrgnUpdate
, RGN_DIFF
);
2491 NtGdiOffsetRgn(hrgn
, -pt
.x
, -pt
.y
);
2493 ret
= NtGdiExtSelectClipRgn(hDC
, hrgn
, RGN_COPY
);
2495 GreDeleteObject(hrgn
);
2502 return GdiGetClipBox( hDC
, &rc
);
2508 NtUserExcludeUpdateRgn(
2515 TRACE("Enter NtUserExcludeUpdateRgn\n");
2516 UserEnterExclusive();
2518 pWnd
= UserGetWindowObject(hWnd
);
2521 ret
= co_UserExcludeUpdateRgn(hDC
, pWnd
);
2523 TRACE("Leave NtUserExcludeUpdateRgn, ret=%i\n", ret
);
2531 NtUserInvalidateRect(
2533 CONST RECT
*lpUnsafeRect
,
2536 UINT flags
= RDW_INVALIDATE
| (bErase
? RDW_ERASE
: 0);
2539 flags
= RDW_ALLCHILDREN
| RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ERASENOW
;
2540 lpUnsafeRect
= NULL
;
2542 return NtUserRedrawWindow(hWnd
, lpUnsafeRect
, NULL
, flags
);
2547 NtUserInvalidateRgn(
2554 EngSetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2557 return NtUserRedrawWindow(hWnd
, NULL
, hRgn
, RDW_INVALIDATE
| (bErase
? RDW_ERASE
: 0));
2570 UserEnterExclusive();
2574 if (!(Window
= UserGetWindowObject(hwnd
)) ||
2575 UserIsDesktopWindow(Window
) || UserIsMessageWindow(Window
))
2582 /* Validate flags and check it as a mask for 0 or 1. */
2583 if ( (nFlags
& PW_CLIENTONLY
) == nFlags
)
2584 Ret
= IntPrintWindow( Window
, hdcBlt
, nFlags
);
2586 EngSetLastError(ERROR_INVALID_PARAMETER
);
2594 /* ValidateRect gets redirected to NtUserValidateRect:
2595 http://blog.csdn.net/ntdll/archive/2005/10/19/509299.aspx */
2602 UINT flags
= RDW_VALIDATE
;
2605 flags
= RDW_ALLCHILDREN
| RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ERASENOW
;
2608 return NtUserRedrawWindow(hWnd
, lpRect
, NULL
, flags
);