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 #define RDW_CLIPCHILDREN 4096
13 #define RDW_NOUPDATEDIRTY 32768
15 /* PRIVATE FUNCTIONS **********************************************************/
18 * @name IntIntersectWithParents
20 * Intersect window rectangle with all parent client rectangles.
23 * Pointer to child window to start intersecting from.
25 * Pointer to rectangle that we want to intersect in screen
26 * coordinates on input and intersected rectangle on output (if TRUE
30 * If any parent is minimized or invisible or the resulting rectangle
31 * is empty then FALSE is returned. Otherwise TRUE is returned.
35 IntIntersectWithParents(PWND Child
, RECTL
*WindowRect
)
39 if (Child
->ExStyle
& WS_EX_REDIRECTED
)
42 ParentWnd
= Child
->spwndParent
;
43 while (ParentWnd
!= NULL
)
45 if (!(ParentWnd
->style
& WS_VISIBLE
) ||
46 (ParentWnd
->style
& WS_MINIMIZE
) ||
47 !RECTL_bIntersectRect(WindowRect
, WindowRect
, &ParentWnd
->rcClient
) )
52 if (ParentWnd
->ExStyle
& WS_EX_REDIRECTED
)
55 ParentWnd
= ParentWnd
->spwndParent
;
62 IntValidateParents(PWND Child
, BOOL Recurse
)
64 RECTL ParentRect
, Rect
;
65 BOOL Start
, Ret
= TRUE
;
66 PWND ParentWnd
= Child
;
69 if (ParentWnd
->style
& WS_CHILD
)
72 ParentWnd
= ParentWnd
->spwndParent
;
73 while (ParentWnd
->style
& WS_CHILD
);
76 // No pending nonclient paints.
77 if (!(ParentWnd
->state
& WNDS_SYNCPAINTPENDING
)) Recurse
= FALSE
;
80 ParentWnd
= Child
->spwndParent
;
83 if (ParentWnd
->style
& WS_CLIPCHILDREN
)
86 if (ParentWnd
->hrgnUpdate
!= 0)
93 // Start with child clipping.
98 Rect
= Child
->rcWindow
;
100 if (!IntIntersectWithParents(Child
, &Rect
)) break;
102 Rgn
= IntSysCreateRectpRgnIndirect(&Rect
);
106 PREGION RgnClip
= REGION_LockRgn(Child
->hrgnClip
);
107 IntGdiCombineRgn(Rgn
, Rgn
, RgnClip
, RGN_AND
);
108 REGION_UnlockRgn(RgnClip
);
112 ParentRect
= ParentWnd
->rcWindow
;
114 if (!IntIntersectWithParents(ParentWnd
, &ParentRect
)) break;
116 IntInvalidateWindows( ParentWnd
,
118 RDW_VALIDATE
| RDW_NOCHILDREN
| RDW_NOUPDATEDIRTY
);
120 ParentWnd
= ParentWnd
->spwndParent
;
123 if (Rgn
) REGION_Delete(Rgn
);
129 Synchronize painting to the top-level windows of other threads.
132 IntSendSyncPaint(PWND Wnd
, ULONG Flags
)
134 PTHREADINFO ptiCur
, ptiWnd
;
135 PUSER_SENT_MESSAGE Message
;
139 ptiWnd
= Wnd
->head
.pti
;
140 ptiCur
= PsGetCurrentThreadWin32Thread();
142 Not the current thread, Wnd is in send Nonclient paint also in send erase background and it is visiable.
144 if ( Wnd
->head
.pti
!= ptiCur
&&
145 Wnd
->state
& WNDS_SENDNCPAINT
&&
146 Wnd
->state
& WNDS_SENDERASEBACKGROUND
&&
147 Wnd
->style
& WS_VISIBLE
)
149 // For testing, if you see this, break out the Champagne and have a party!
150 TRACE("SendSyncPaint Wnd in State!\n");
151 if (!IsListEmpty(&ptiWnd
->SentMessagesListHead
))
153 // Scan sent queue messages to see if we received sync paint messages.
154 Entry
= ptiWnd
->SentMessagesListHead
.Flink
;
155 Message
= CONTAINING_RECORD(Entry
, USER_SENT_MESSAGE
, ListEntry
);
159 if (Message
->Msg
.message
== WM_SYNCPAINT
&&
160 Message
->Msg
.hwnd
== UserHMGetHandle(Wnd
))
161 { // Already received so exit out.
162 ERR("SendSyncPaint Found one in the Sent Msg Queue!\n");
166 Entry
= Message
->ListEntry
.Flink
;
167 Message
= CONTAINING_RECORD(Entry
, USER_SENT_MESSAGE
, ListEntry
);
169 while (Entry
!= &ptiWnd
->SentMessagesListHead
);
173 TRACE("Sending WM_SYNCPAINT\n");
174 // This message has no parameters. But it does! Pass Flags along.
175 co_IntSendMessageNoWait(UserHMGetHandle(Wnd
), WM_SYNCPAINT
, Flags
, 0);
176 Wnd
->state
|= WNDS_SYNCPAINTPENDING
;
180 // Send to all the children if this is the desktop window.
181 if ( Wnd
== UserGetDesktopWindow() )
183 if ( Flags
& RDW_ALLCHILDREN
||
184 ( !(Flags
& RDW_NOCHILDREN
) && Wnd
->style
& WS_CLIPCHILDREN
))
186 PWND spwndChild
= Wnd
->spwndChild
;
189 if ( spwndChild
->style
& WS_CHILD
&&
190 spwndChild
->head
.pti
!= ptiCur
)
192 spwndChild
= spwndChild
->spwndNext
;
195 IntSendSyncPaint( spwndChild
, Flags
);
196 spwndChild
= spwndChild
->spwndNext
;
203 * @name IntCalcWindowRgn
205 * Get a window or client region.
209 IntCalcWindowRgn(PWND Wnd
, BOOL Client
)
215 hRgnWindow
= NtGdiCreateRectRgn(
219 Wnd
->rcClient
.bottom
);
223 hRgnWindow
= NtGdiCreateRectRgn(
227 Wnd
->rcWindow
.bottom
);
230 if (Wnd
->hrgnClip
!= NULL
&& !(Wnd
->style
& WS_MINIMIZE
))
232 NtGdiOffsetRgn(hRgnWindow
,
235 NtGdiCombineRgn(hRgnWindow
, hRgnWindow
, Wnd
->hrgnClip
, RGN_AND
);
236 NtGdiOffsetRgn(hRgnWindow
,
245 * @name IntGetNCUpdateRgn
247 * Get non-client update region of a window and optionally validate it.
250 * Pointer to window to get the NC update region from.
252 * Set to TRUE to force validating the NC update region.
255 * Handle to NC update region. The caller is responsible for deleting
260 IntGetNCUpdateRgn(PWND Window
, BOOL Validate
)
264 UINT RgnType
, NcType
;
267 if (Window
->hrgnUpdate
!= NULL
&&
268 Window
->hrgnUpdate
!= HRGN_WINDOW
)
270 hRgnNonClient
= IntCalcWindowRgn(Window
, FALSE
);
273 * If region creation fails it's safe to fallback to whole
276 if (hRgnNonClient
== NULL
)
281 hRgnWindow
= IntCalcWindowRgn(Window
, TRUE
);
282 if (hRgnWindow
== NULL
)
284 GreDeleteObject(hRgnNonClient
);
288 NcType
= IntGdiGetRgnBox(hRgnNonClient
, &update
);
290 RgnType
= NtGdiCombineRgn(hRgnNonClient
, hRgnNonClient
, hRgnWindow
, RGN_DIFF
);
292 if (RgnType
== ERROR
)
294 GreDeleteObject(hRgnWindow
);
295 GreDeleteObject(hRgnNonClient
);
298 else if (RgnType
== NULLREGION
)
300 GreDeleteObject(hRgnWindow
);
301 GreDeleteObject(hRgnNonClient
);
302 Window
->state
&= ~WNDS_UPDATEDIRTY
;
307 * Remove the nonclient region from the standard update region if
308 * we were asked for it.
313 if (NtGdiCombineRgn(Window
->hrgnUpdate
, Window
->hrgnUpdate
, hRgnWindow
, RGN_AND
) == NULLREGION
)
315 IntGdiSetRegionOwner(Window
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
316 GreDeleteObject(Window
->hrgnUpdate
);
317 Window
->state
&= ~WNDS_UPDATEDIRTY
;
318 Window
->hrgnUpdate
= NULL
;
319 if (!(Window
->state
& WNDS_INTERNALPAINT
))
320 MsqDecPaintCountQueue(Window
->head
.pti
);
324 /* check if update rgn contains complete nonclient area */
325 if (NcType
== SIMPLEREGION
)
328 IntGetWindowRect( Window
, &window
);
330 if (IntEqualRect( &window
, &update
))
332 GreDeleteObject(hRgnNonClient
);
333 hRgnNonClient
= HRGN_WINDOW
;
337 GreDeleteObject(hRgnWindow
);
339 return hRgnNonClient
;
343 return Window
->hrgnUpdate
;
348 IntSendNCPaint(PWND pWnd
, HRGN hRgn
)
350 pWnd
->state
&= ~WNDS_SENDNCPAINT
;
352 if ( pWnd
== GetW32ThreadInfo()->MessageQueue
->spwndActive
&&
353 !(pWnd
->state
& WNDS_ACTIVEFRAME
))
355 pWnd
->state
|= WNDS_ACTIVEFRAME
;
356 pWnd
->state
&= ~WNDS_NONCPAINT
;
360 if (pWnd
->state2
& WNDS2_FORCEFULLNCPAINTCLIPRGN
)
362 pWnd
->state2
&= ~WNDS2_FORCEFULLNCPAINTCLIPRGN
;
366 if (hRgn
) co_IntSendMessage(UserHMGetHandle(pWnd
), WM_NCPAINT
, (WPARAM
)hRgn
, 0);
370 IntSendChildNCPaint(PWND pWnd
)
372 pWnd
= pWnd
->spwndChild
;
375 if (pWnd
->hrgnUpdate
== NULL
&& pWnd
->state
& WNDS_SENDNCPAINT
)
377 USER_REFERENCE_ENTRY Ref
;
378 UserRefObjectCo(pWnd
, &Ref
);
379 IntSendNCPaint(pWnd
, HRGN_WINDOW
);
380 UserDerefObjectCo(pWnd
);
382 pWnd
= pWnd
->spwndNext
;
389 * Internal function used by IntRedrawWindow.
393 co_IntPaintWindows(PWND Wnd
, ULONG Flags
, BOOL Recurse
)
396 HWND hWnd
= Wnd
->head
.h
;
397 HRGN TempRegion
= NULL
;
399 Wnd
->state
&= ~WNDS_PAINTNOTPROCESSED
;
401 if (Wnd
->state
& WNDS_SENDNCPAINT
||
402 Wnd
->state
& WNDS_SENDERASEBACKGROUND
)
404 if (!(Wnd
->style
& WS_VISIBLE
))
406 Wnd
->state
&= ~(WNDS_SENDNCPAINT
|WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
411 if (Wnd
->hrgnUpdate
== NULL
)
413 Wnd
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
416 if (Wnd
->head
.pti
== PsGetCurrentThreadWin32Thread())
418 if (Wnd
->state
& WNDS_SENDNCPAINT
)
420 TempRegion
= IntGetNCUpdateRgn(Wnd
, TRUE
);
422 IntSendNCPaint(Wnd
, TempRegion
);
424 if (TempRegion
> HRGN_WINDOW
&& GreIsHandleValid(TempRegion
))
426 /* NOTE: The region can already be deleted! */
427 GreDeleteObject(TempRegion
);
431 if (Wnd
->state
& WNDS_SENDERASEBACKGROUND
)
433 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
436 hDC
= UserGetDCEx( Wnd
,
438 DCX_CACHE
|DCX_USESTYLE
|DCX_INTERSECTRGN
|DCX_KEEPCLIPRGN
);
440 if (Wnd
->head
.pti
->ppi
!= pti
->ppi
)
442 ERR("Sending DC to another Process!!!\n");
445 Wnd
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
446 // Kill the loop, so Clear before we send.
447 if (!co_IntSendMessage(hWnd
, WM_ERASEBKGND
, (WPARAM
)hDC
, 0))
449 Wnd
->state
|= (WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
451 UserReleaseDC(Wnd
, hDC
, FALSE
);
460 * Check that the window is still valid at this point
462 if (!IntIsWindow(hWnd
))
468 * Paint child windows.
471 if (!(Flags
& RDW_NOCHILDREN
) &&
472 !(Wnd
->style
& WS_MINIMIZE
) &&
473 ( Flags
& RDW_ALLCHILDREN
||
474 (Flags
& RDW_CLIPCHILDREN
&& Wnd
->style
& WS_CLIPCHILDREN
) ) )
477 PTHREADINFO pti
= PsGetCurrentThreadWin32Thread();
479 if ((List
= IntWinListChildren(Wnd
)))
481 for (phWnd
= List
; *phWnd
; ++phWnd
)
483 if ((Wnd
= UserGetWindowObject(*phWnd
)) == NULL
)
486 if (Wnd
->head
.pti
!= pti
&& Wnd
->style
& WS_CHILD
)
489 if (Wnd
->style
& WS_VISIBLE
)
491 USER_REFERENCE_ENTRY Ref
;
492 UserRefObjectCo(Wnd
, &Ref
);
493 co_IntPaintWindows(Wnd
, Flags
, TRUE
);
494 UserDerefObjectCo(Wnd
);
497 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
505 * Internal function used by IntRedrawWindow, simplecall.
509 co_IntUpdateWindows(PWND Wnd
, ULONG Flags
, BOOL Recurse
)
511 HWND hWnd
= Wnd
->head
.h
;
513 if ( Wnd
->hrgnUpdate
!= NULL
|| Wnd
->state
& WNDS_INTERNALPAINT
)
517 if (!IntValidateParents(Wnd
, Recurse
))
523 if (Wnd
->state
& WNDS_INTERNALPAINT
)
525 Wnd
->state
&= ~WNDS_INTERNALPAINT
;
527 if (Wnd
->hrgnUpdate
== NULL
)
528 MsqDecPaintCountQueue(Wnd
->head
.pti
);
531 Wnd
->state
|= WNDS_PAINTNOTPROCESSED
;
532 Wnd
->state
&= ~WNDS_UPDATEDIRTY
;
534 Wnd
->state2
|= WNDS2_WMPAINTSENT
;
535 co_IntSendMessage(hWnd
, WM_PAINT
, 0, 0);
537 if (Wnd
->state
& WNDS_PAINTNOTPROCESSED
)
539 USER_REFERENCE_ENTRY Ref
;
540 UserRefObjectCo(Wnd
, &Ref
);
541 co_IntPaintWindows(Wnd
, RDW_NOCHILDREN
, FALSE
);
542 UserDerefObjectCo(Wnd
);
546 // Force flags as a toggle. Fixes msg:test_paint_messages:WmChildPaintNc.
547 Flags
= (Flags
& RDW_NOCHILDREN
) ? RDW_NOCHILDREN
: RDW_ALLCHILDREN
; // All children is the default.
550 * Update child windows.
553 if (!(Flags
& RDW_NOCHILDREN
) &&
554 Flags
& RDW_ALLCHILDREN
&&
555 Wnd
!= UserGetDesktopWindow() )
559 for (Child
= Wnd
->spwndChild
; Child
; Child
= Child
->spwndNext
)
561 /* transparent window, check for non-transparent sibling to paint first, then skip it */
562 if ( Child
->ExStyle
& WS_EX_TRANSPARENT
&&
563 ( Child
->hrgnUpdate
!= NULL
|| Child
->state
& WNDS_INTERNALPAINT
) )
565 PWND Next
= Child
->spwndNext
;
568 if ( Next
->hrgnUpdate
!= NULL
|| Next
->state
& WNDS_INTERNALPAINT
) break;
570 Next
= Next
->spwndNext
;
576 if (Child
->style
& WS_VISIBLE
)
578 USER_REFERENCE_ENTRY Ref
;
579 UserRefObjectCo(Child
, &Ref
);
580 co_IntUpdateWindows(Child
, Flags
, TRUE
);
581 UserDerefObjectCo(Child
);
588 UserUpdateWindows(PWND pWnd
, ULONG Flags
)
590 // If transparent and any sibling windows below needs to be painted, leave.
591 if (pWnd
->ExStyle
& WS_EX_TRANSPARENT
)
593 PWND Next
= pWnd
->spwndNext
;
597 if ( Next
->head
.pti
== pWnd
->head
.pti
&&
598 ( Next
->hrgnUpdate
!= NULL
|| Next
->state
& WNDS_INTERNALPAINT
) )
603 Next
= Next
->spwndNext
;
606 co_IntUpdateWindows(pWnd
, Flags
, FALSE
);
610 UserSyncAndPaintWindows(PWND pWnd
, ULONG Flags
)
613 // Find parent, if it needs to be painted, leave.
616 if ((Parent
= Parent
->spwndParent
) == NULL
) break;
617 if ( Parent
->style
& WS_CLIPCHILDREN
) break;
618 if ( Parent
->hrgnUpdate
!= NULL
|| Parent
->state
& WNDS_INTERNALPAINT
) return;
621 IntSendSyncPaint(pWnd
, Flags
);
622 co_IntPaintWindows(pWnd
, Flags
, FALSE
);
626 * IntInvalidateWindows
628 * Internal function used by IntRedrawWindow, UserRedrawDesktop,
629 * co_WinPosSetWindowPos, co_UserRedrawWindow.
632 IntInvalidateWindows(PWND Wnd
, PREGION Rgn
, ULONG Flags
)
634 INT RgnType
= NULLREGION
;
635 BOOL HadPaintMessage
;
637 TRACE("IntInvalidateWindows start Rgn %p\n",Rgn
);
639 if ( Rgn
> PRGN_WINDOW
)
642 * If the nonclient is not to be redrawn, clip the region to the client
645 if ((Flags
& RDW_INVALIDATE
) != 0 && (Flags
& RDW_FRAME
) == 0)
649 RgnClient
= IntSysCreateRectpRgnIndirect(&Wnd
->rcClient
);
652 RgnType
= IntGdiCombineRgn(Rgn
, Rgn
, RgnClient
, RGN_AND
);
653 REGION_Delete(RgnClient
);
658 * Clip the given region with window rectangle (or region)
661 if (!Wnd
->hrgnClip
|| (Wnd
->style
& WS_MINIMIZE
))
663 PREGION RgnWindow
= IntSysCreateRectpRgnIndirect(&Wnd
->rcWindow
);
666 RgnType
= IntGdiCombineRgn(Rgn
, Rgn
, RgnWindow
, RGN_AND
);
667 REGION_Delete(RgnWindow
);
672 PREGION RgnClip
= REGION_LockRgn(Wnd
->hrgnClip
);
675 REGION_bOffsetRgn(Rgn
,
678 RgnType
= IntGdiCombineRgn(Rgn
, Rgn
, RgnClip
, RGN_AND
);
679 REGION_bOffsetRgn(Rgn
,
682 REGION_UnlockRgn(RgnClip
);
688 RgnType
= NULLREGION
;
692 * Save current state of pending updates
695 HadPaintMessage
= IntIsWindowDirty(Wnd
);
698 * Update the region and flags
701 // The following flags are used to invalidate the window.
702 if (Flags
& (RDW_INVALIDATE
|RDW_INTERNALPAINT
|RDW_ERASE
|RDW_FRAME
))
704 if (Flags
& RDW_INTERNALPAINT
)
706 Wnd
->state
|= WNDS_INTERNALPAINT
;
709 if (Flags
& RDW_INVALIDATE
)
713 Wnd
->state
&= ~WNDS_NONCPAINT
;
715 /* If not the same thread set it dirty. */
716 if (Wnd
->head
.pti
!= PsGetCurrentThreadWin32Thread())
718 Wnd
->state
|= WNDS_UPDATEDIRTY
;
719 if (Wnd
->state2
& WNDS2_WMPAINTSENT
)
720 Wnd
->state2
|= WNDS2_ENDPAINTINVALIDATE
;
723 if (Flags
& RDW_FRAME
)
724 Wnd
->state
|= WNDS_SENDNCPAINT
;
726 if (Flags
& RDW_ERASE
)
727 Wnd
->state
|= WNDS_SENDERASEBACKGROUND
;
729 if (RgnType
!= NULLREGION
&& Rgn
> PRGN_WINDOW
)
731 if (Wnd
->hrgnUpdate
== NULL
)
733 Wnd
->hrgnUpdate
= NtGdiCreateRectRgn(0, 0, 0, 0);
734 IntGdiSetRegionOwner(Wnd
->hrgnUpdate
, GDI_OBJ_HMGR_PUBLIC
);
737 if (Wnd
->hrgnUpdate
!= HRGN_WINDOW
)
739 RgnUpdate
= REGION_LockRgn(Wnd
->hrgnUpdate
);
742 RgnType
= IntGdiCombineRgn(RgnUpdate
, RgnUpdate
, Rgn
, RGN_OR
);
743 REGION_UnlockRgn(RgnUpdate
);
744 if (RgnType
== NULLREGION
)
746 IntGdiSetRegionOwner(Wnd
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
747 GreDeleteObject(Wnd
->hrgnUpdate
);
748 Wnd
->hrgnUpdate
= NULL
;
754 Flags
|= RDW_ERASE
|RDW_FRAME
; // For children.
758 if (!HadPaintMessage
&& IntIsWindowDirty(Wnd
))
760 MsqIncPaintCountQueue(Wnd
->head
.pti
);
763 } // The following flags are used to validate the window.
764 else if (Flags
& (RDW_VALIDATE
|RDW_NOINTERNALPAINT
|RDW_NOERASE
|RDW_NOFRAME
))
766 if (Wnd
->state
& WNDS_UPDATEDIRTY
&& !(Flags
& RDW_NOUPDATEDIRTY
))
769 if (Flags
& RDW_NOINTERNALPAINT
)
771 Wnd
->state
&= ~WNDS_INTERNALPAINT
;
774 if (Flags
& RDW_VALIDATE
)
776 if (Flags
& RDW_NOFRAME
)
777 Wnd
->state
&= ~WNDS_SENDNCPAINT
;
779 if (Flags
& RDW_NOERASE
)
780 Wnd
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
782 if (Wnd
->hrgnUpdate
> HRGN_WINDOW
&& RgnType
!= NULLREGION
&& Rgn
> PRGN_WINDOW
)
784 PREGION RgnUpdate
= REGION_LockRgn(Wnd
->hrgnUpdate
);
788 RgnType
= IntGdiCombineRgn(RgnUpdate
, RgnUpdate
, Rgn
, RGN_DIFF
);
789 REGION_UnlockRgn(RgnUpdate
);
791 if (RgnType
== NULLREGION
)
793 IntGdiSetRegionOwner(Wnd
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
794 GreDeleteObject(Wnd
->hrgnUpdate
);
795 Wnd
->hrgnUpdate
= NULL
;
799 // If update is null, do not erase.
800 if (Wnd
->hrgnUpdate
== NULL
)
802 Wnd
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
806 if (HadPaintMessage
&& !IntIsWindowDirty(Wnd
))
808 MsqDecPaintCountQueue(Wnd
->head
.pti
);
813 * Process children if needed
816 if (!(Flags
& RDW_NOCHILDREN
) &&
817 !(Wnd
->style
& WS_MINIMIZE
) &&
818 ((Flags
& RDW_ALLCHILDREN
) || !(Wnd
->style
& WS_CLIPCHILDREN
)))
822 for (Child
= Wnd
->spwndChild
; Child
; Child
= Child
->spwndNext
)
824 if (Child
->style
& WS_VISIBLE
)
827 * Recursive call to update children hrgnUpdate
829 PREGION RgnTemp
= IntSysCreateRectpRgn(0, 0, 0, 0);
832 if (Rgn
> PRGN_WINDOW
) IntGdiCombineRgn(RgnTemp
, Rgn
, 0, RGN_COPY
);
833 IntInvalidateWindows(Child
, ((Rgn
> PRGN_WINDOW
)?RgnTemp
:Rgn
), Flags
);
834 REGION_Delete(RgnTemp
);
839 TRACE("IntInvalidateWindows exit\n");
843 * IntIsWindowDrawable
846 * Window is drawable when it is visible and all parents are not
851 IntIsWindowDrawable(PWND Wnd
)
855 for (WndObject
= Wnd
; WndObject
!= NULL
; WndObject
= WndObject
->spwndParent
)
857 if ( WndObject
->state2
& WNDS2_INDESTROY
||
858 WndObject
->state
& WNDS_DESTROYED
||
860 !(WndObject
->style
& WS_VISIBLE
) ||
861 ((WndObject
->style
& WS_MINIMIZE
) && (WndObject
!= Wnd
)))
873 * Internal version of NtUserRedrawWindow that takes WND as
880 const RECTL
* UpdateRect
,
884 PREGION TmpRgn
= NULL
;
885 TRACE("co_UserRedrawWindow start Rgn %p\n",UpdateRgn
);
889 * Validation of passed parameters.
892 if (!IntIsWindowDrawable(Window
))
894 return TRUE
; // Just do nothing!!!
899 Window
= UserGetDesktopWindow();
904 * Transform the parameters UpdateRgn and UpdateRect into
905 * a region hRgn specified in screen coordinates.
908 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
)) // Both are OKAY!
910 /* We can't hold lock on GDI objects while doing roundtrips to user mode,
911 * so use a copy instead */
914 TmpRgn
= IntSysCreateRectpRgn(0, 0, 0, 0);
916 if (UpdateRgn
> PRGN_WINDOW
)
918 IntGdiCombineRgn(TmpRgn
, UpdateRgn
, NULL
, RGN_COPY
);
921 if (Window
!= UserGetDesktopWindow())
923 REGION_bOffsetRgn(TmpRgn
, Window
->rcClient
.left
, Window
->rcClient
.top
);
928 if (UpdateRect
!= NULL
)
930 if (Window
== UserGetDesktopWindow())
932 TmpRgn
= IntSysCreateRectpRgnIndirect(UpdateRect
);
936 TmpRgn
= IntSysCreateRectpRgn(Window
->rcClient
.left
+ UpdateRect
->left
,
937 Window
->rcClient
.top
+ UpdateRect
->top
,
938 Window
->rcClient
.left
+ UpdateRect
->right
,
939 Window
->rcClient
.top
+ UpdateRect
->bottom
);
944 if ((Flags
& (RDW_INVALIDATE
| RDW_FRAME
)) == (RDW_INVALIDATE
| RDW_FRAME
) ||
945 (Flags
& (RDW_VALIDATE
| RDW_NOFRAME
)) == (RDW_VALIDATE
| RDW_NOFRAME
))
947 if (!RECTL_bIsEmptyRect(&Window
->rcWindow
))
948 TmpRgn
= IntSysCreateRectpRgnIndirect(&Window
->rcWindow
);
952 if (!RECTL_bIsEmptyRect(&Window
->rcClient
))
953 TmpRgn
= IntSysCreateRectpRgnIndirect(&Window
->rcClient
);
959 /* Fixes test RDW_INTERNALPAINT behavior */
962 TmpRgn
= PRGN_WINDOW
; // Need a region so the bits can be set!!!
967 * Adjust the window update region depending on hRgn and flags.
970 if (Flags
& (RDW_INVALIDATE
| RDW_VALIDATE
| RDW_INTERNALPAINT
| RDW_NOINTERNALPAINT
) &&
973 IntInvalidateWindows(Window
, TmpRgn
, Flags
);
978 * Repaint and erase windows if needed.
981 if (Flags
& RDW_UPDATENOW
)
983 UserUpdateWindows(Window
, Flags
);
985 else if (Flags
& RDW_ERASENOW
)
987 if ((Flags
& (RDW_NOCHILDREN
|RDW_ALLCHILDREN
)) == 0)
988 Flags
|= RDW_CLIPCHILDREN
;
990 UserSyncAndPaintWindows(Window
, Flags
);
998 if (TmpRgn
> PRGN_WINDOW
)
1000 REGION_Delete(TmpRgn
);
1002 TRACE("co_UserRedrawWindow exit\n");
1008 PaintSuspendedWindow(PWND pwnd
, HRGN hrgnOrig
)
1010 if (pwnd
->hrgnUpdate
)
1013 INT Flags
= DC_NC
|DC_NOSENDMSG
;
1019 if (pwnd
->hrgnUpdate
> HRGN_WINDOW
)
1021 hrgnTemp
= NtGdiCreateRectRgn(0, 0, 0, 0);
1022 type
= NtGdiCombineRgn( hrgnTemp
, pwnd
->hrgnUpdate
, 0, RGN_COPY
);
1025 GreDeleteObject(hrgnTemp
);
1026 hrgnTemp
= HRGN_WINDOW
;
1031 hrgnTemp
= GreCreateRectRgnIndirect(&pwnd
->rcWindow
);
1035 hrgnTemp
> HRGN_WINDOW
&&
1036 NtGdiCombineRgn(hrgnTemp
, hrgnTemp
, hrgnOrig
, RGN_AND
) == NULLREGION
)
1038 GreDeleteObject(hrgnTemp
);
1042 hDC
= UserGetDCEx(pwnd
, hrgnTemp
, DCX_WINDOW
|DCX_INTERSECTRGN
|DCX_USESTYLE
|DCX_KEEPCLIPRGN
);
1044 Rect
= pwnd
->rcWindow
;
1045 RECTL_vOffsetRect(&Rect
, -pwnd
->rcWindow
.left
, -pwnd
->rcWindow
.top
);
1047 // Clear out client area!
1048 FillRect(hDC
, &Rect
, IntGetSysColorBrush(COLOR_WINDOW
));
1050 NC_DoNCPaint(pwnd
, hDC
, Flags
); // Redraw without MENUs.
1052 UserReleaseDC(pwnd
, hDC
, FALSE
);
1054 prgn
= REGION_LockRgn(hrgnTemp
);
1055 IntInvalidateWindows(pwnd
, prgn
, RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ALLCHILDREN
);
1056 REGION_UnlockRgn(prgn
);
1058 // Set updates for this window.
1059 pwnd
->state
|= WNDS_SENDNCPAINT
|WNDS_SENDERASEBACKGROUND
|WNDS_UPDATEDIRTY
;
1061 // DCX_KEEPCLIPRGN is set. Check it anyway.
1062 if (hrgnTemp
> HRGN_WINDOW
&& GreIsHandleValid(hrgnTemp
)) GreDeleteObject(hrgnTemp
);
1067 UpdateTheadChildren(PWND pWnd
, HRGN hRgn
)
1069 PaintSuspendedWindow( pWnd
, hRgn
);
1071 if (!(pWnd
->style
& WS_CLIPCHILDREN
))
1074 pWnd
= pWnd
->spwndChild
; // invalidate children if any.
1077 UpdateTheadChildren( pWnd
, hRgn
);
1078 pWnd
= pWnd
->spwndNext
;
1083 UpdateThreadWindows(PWND pWnd
, PTHREADINFO pti
, HRGN hRgn
)
1087 for ( pwndTemp
= pWnd
;
1089 pwndTemp
= pwndTemp
->spwndNext
)
1091 if (pwndTemp
->head
.pti
== pti
)
1093 UserUpdateWindows(pwndTemp
, RDW_ALLCHILDREN
);
1097 if (IsThreadSuspended(pwndTemp
->head
.pti
))
1099 UpdateTheadChildren(pwndTemp
, hRgn
);
1102 UserUpdateWindows(pwndTemp
, RDW_ALLCHILDREN
);
1108 IntIsWindowDirty(PWND Wnd
)
1110 return ( Wnd
->style
& WS_VISIBLE
&&
1111 ( Wnd
->hrgnUpdate
!= NULL
||
1112 Wnd
->state
& WNDS_INTERNALPAINT
) );
1116 Conditions to paint any window:
1118 1. Update region is not null.
1119 2. Internal paint flag is set.
1120 3. Paint count is not zero.
1124 IntFindWindowToRepaint(PWND Window
, PTHREADINFO Thread
)
1129 for (; Window
!= NULL
; Window
= Window
->spwndNext
)
1131 if (IntWndBelongsToThread(Window
, Thread
))
1133 if (IntIsWindowDirty(Window
))
1135 /* Make sure all non-transparent siblings are already drawn. */
1136 if (Window
->ExStyle
& WS_EX_TRANSPARENT
)
1138 for (TempWindow
= Window
->spwndNext
; TempWindow
!= NULL
;
1139 TempWindow
= TempWindow
->spwndNext
)
1141 if (!(TempWindow
->ExStyle
& WS_EX_TRANSPARENT
) &&
1142 IntWndBelongsToThread(TempWindow
, Thread
) &&
1143 IntIsWindowDirty(TempWindow
))
1152 /* find a child of the specified window that needs repainting */
1153 if (Window
->spwndChild
)
1155 hChild
= IntFindWindowToRepaint(Window
->spwndChild
, Thread
);
1172 PWND PaintWnd
, StartWnd
;
1174 if ((MsgFilterMin
!= 0 || MsgFilterMax
!= 0) &&
1175 (MsgFilterMin
> WM_PAINT
|| MsgFilterMax
< WM_PAINT
))
1178 if (Thread
->TIF_flags
& TIF_SYSTEMTHREAD
)
1180 ERR("WM_PAINT is in a System Thread!\n");
1183 StartWnd
= UserGetDesktopWindow();
1184 PaintWnd
= IntFindWindowToRepaint(StartWnd
, Thread
);
1186 Message
->hwnd
= PaintWnd
? UserHMGetHandle(PaintWnd
) : NULL
;
1188 if (Message
->hwnd
== NULL
&& Thread
->cPaintsReady
)
1190 // Find note in window.c:"PAINTING BUG".
1191 ERR("WARNING SOMETHING HAS GONE WRONG: Thread marked as containing dirty windows, but no dirty windows found! Counts %u\n",Thread
->cPaintsReady
);
1192 /* Hack to stop spamming the debug log ! */
1193 Thread
->cPaintsReady
= 0;
1197 if (Message
->hwnd
== NULL
)
1200 if (!(Window
== NULL
||
1201 PaintWnd
== Window
||
1202 IntIsChildWindow(Window
, PaintWnd
))) /* check that it is a child of the specified parent */
1205 if (PaintWnd
->state
& WNDS_INTERNALPAINT
)
1207 PaintWnd
->state
&= ~WNDS_INTERNALPAINT
;
1208 if (!PaintWnd
->hrgnUpdate
)
1209 MsqDecPaintCountQueue(Thread
);
1211 PaintWnd
->state2
&= ~WNDS2_STARTPAINT
;
1212 PaintWnd
->state
&= ~WNDS_UPDATEDIRTY
;
1215 while( Window
&& Window
!= UserGetDesktopWindow())
1217 // Role back and check for clip children, do not set if any.
1218 if (Window
->spwndParent
&& !(Window
->spwndParent
->style
& WS_CLIPCHILDREN
))
1220 PaintWnd
->state2
|= WNDS2_WMPAINTSENT
;
1222 Window
= Window
->spwndParent
;
1225 Message
->wParam
= Message
->lParam
= 0;
1226 Message
->message
= WM_PAINT
;
1238 INT cx
, cy
, xSrc
, ySrc
;
1240 if ( nFlags
& PW_CLIENTONLY
)
1242 cx
= pwnd
->rcClient
.right
- pwnd
->rcClient
.left
;
1243 cy
= pwnd
->rcClient
.bottom
- pwnd
->rcClient
.top
;
1244 xSrc
= pwnd
->rcClient
.left
- pwnd
->rcWindow
.left
;
1245 ySrc
= pwnd
->rcClient
.top
- pwnd
->rcWindow
.top
;
1249 cx
= pwnd
->rcWindow
.right
- pwnd
->rcWindow
.left
;
1250 cy
= pwnd
->rcWindow
.bottom
- pwnd
->rcWindow
.top
;
1255 // TODO: Setup Redirection for Print.
1258 /* Update the window just incase. */
1259 co_IntUpdateWindows( pwnd
, RDW_ALLCHILDREN
, FALSE
);
1261 hdcSrc
= UserGetDCEx( pwnd
, NULL
, DCX_CACHE
|DCX_WINDOW
);
1262 /* Print window to printer context. */
1263 NtGdiBitBlt( hdcBlt
,
1275 UserReleaseDC( pwnd
, hdcSrc
, FALSE
);
1277 // TODO: Release Redirection from Print.
1284 IntFlashWindowEx(PWND pWnd
, PFLASHWINFO pfwi
)
1287 UINT uCount
= pfwi
->uCount
;
1288 BOOL Activate
= FALSE
, Ret
= FALSE
;
1292 FlashState
= (DWORD
)UserGetProp(pWnd
, AtomFlashWndState
, TRUE
);
1294 if (FlashState
== FLASHW_FINISHED
)
1296 // Cycle has finished, kill timer and set this to Stop.
1297 FlashState
|= FLASHW_KILLSYSTIMER
;
1298 pfwi
->dwFlags
= FLASHW_STOP
;
1304 if (pfwi
->dwFlags
== FLASHW_SYSTIMER
)
1306 // Called from system timer, restore flags, counts and state.
1307 pfwi
->dwFlags
= LOWORD(FlashState
);
1308 uCount
= HIWORD(FlashState
);
1309 FlashState
= MAKELONG(LOWORD(FlashState
),0);
1313 // Clean out the trash! Fix SeaMonkey crash after restart.
1318 if (FlashState
== 0)
1319 { // First time in cycle, setup flash state.
1320 if ( pWnd
->state
& WNDS_ACTIVEFRAME
||
1321 (pfwi
->dwFlags
& FLASHW_CAPTION
&& pWnd
->style
& (WS_BORDER
|WS_DLGFRAME
)))
1323 FlashState
= FLASHW_STARTED
|FLASHW_ACTIVE
;
1327 // Set previous window state.
1328 Ret
= !!(FlashState
& FLASHW_ACTIVE
);
1330 if ( (pfwi
->dwFlags
& FLASHW_TIMERNOFG
) == FLASHW_TIMERNOFG
&&
1331 gpqForeground
== pWnd
->head
.pti
->MessageQueue
)
1333 // Flashing until foreground, set this to Stop.
1334 pfwi
->dwFlags
= FLASHW_STOP
;
1338 // Toggle activate flag.
1339 if ( pfwi
->dwFlags
== FLASHW_STOP
)
1341 if (gpqForeground
&& gpqForeground
->spwndActive
== pWnd
)
1348 Activate
= (FlashState
& FLASHW_ACTIVE
) == 0;
1351 if ( pfwi
->dwFlags
== FLASHW_STOP
|| pfwi
->dwFlags
& FLASHW_CAPTION
)
1353 co_IntSendMessage(UserHMGetHandle(pWnd
), WM_NCACTIVATE
, Activate
, 0);
1356 // FIXME: Check for a Stop Sign here.
1357 if ( pfwi
->dwFlags
& FLASHW_TRAY
)
1359 // Need some shell work here too.
1360 TRACE("FIXME: Flash window no Tray support!\n");
1363 if ( pfwi
->dwFlags
== FLASHW_STOP
)
1365 if (FlashState
& FLASHW_KILLSYSTIMER
)
1367 IntKillTimer(pWnd
, ID_EVENT_SYSTIMER_FLASHWIN
, TRUE
);
1370 UserRemoveProp(pWnd
, AtomFlashWndState
, TRUE
);
1373 { // Have a count and started, set timer.
1376 FlashState
|= FLASHW_COUNT
;
1378 if (!(Activate
^ !!(FlashState
& FLASHW_STARTED
)))
1381 if (!(FlashState
& FLASHW_KILLSYSTIMER
))
1382 pfwi
->dwFlags
|= FLASHW_TIMER
;
1385 if (pfwi
->dwFlags
& FLASHW_TIMER
)
1387 FlashState
|= FLASHW_KILLSYSTIMER
;
1390 ID_EVENT_SYSTIMER_FLASHWIN
,
1391 pfwi
->dwTimeout
? pfwi
->dwTimeout
: gpsi
->dtCaretBlink
,
1396 if (FlashState
& FLASHW_COUNT
&& uCount
== 0)
1398 // Keep spinning? Nothing else to do.
1399 FlashState
= FLASHW_FINISHED
;
1403 // Save state and flags so this can be restored next time through.
1404 FlashState
^= (FlashState
^ -!!(Activate
)) & FLASHW_ACTIVE
;
1405 FlashState
^= (FlashState
^ pfwi
->dwFlags
) & (FLASHW_MASK
& ~FLASHW_TIMER
);
1407 FlashState
= MAKELONG(LOWORD(FlashState
),uCount
);
1408 UserSetProp(pWnd
, AtomFlashWndState
, (HANDLE
)FlashState
, TRUE
);
1414 IntBeginPaint(PWND Window
, PPAINTSTRUCT Ps
)
1420 co_UserHideCaret(Window
);
1422 Window
->state2
|= WNDS2_STARTPAINT
;
1423 Window
->state
&= ~WNDS_PAINTNOTPROCESSED
;
1425 if (Window
->state
& WNDS_SENDNCPAINT
)
1428 // Application can keep update dirty.
1431 Window
->state
&= ~WNDS_UPDATEDIRTY
;
1432 hRgn
= IntGetNCUpdateRgn(Window
, FALSE
);
1433 IntSendNCPaint(Window
, hRgn
);
1434 if (hRgn
> HRGN_WINDOW
&& GreIsHandleValid(hRgn
))
1436 /* NOTE: The region can already be deleted! */
1437 GreDeleteObject(hRgn
);
1440 while(Window
->state
& WNDS_UPDATEDIRTY
);
1444 Window
->state
&= ~WNDS_UPDATEDIRTY
;
1447 RtlZeroMemory(Ps
, sizeof(PAINTSTRUCT
));
1449 if (Window
->state2
& WNDS2_ENDPAINTINVALIDATE
)
1451 ERR("BP: Another thread invalidated this window\n");
1454 Ps
->hdc
= UserGetDCEx( Window
,
1456 DCX_INTERSECTRGN
| DCX_USESTYLE
);
1462 // If set, always clear flags out due to the conditions later on for sending the message.
1463 if (Window
->state
& WNDS_SENDERASEBACKGROUND
)
1465 Window
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
1469 if (Window
->hrgnUpdate
!= NULL
)
1471 MsqDecPaintCountQueue(Window
->head
.pti
);
1472 IntGdiSetRegionOwner(Window
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
1473 /* The region is part of the dc now and belongs to the process! */
1474 Window
->hrgnUpdate
= NULL
;
1478 if (Window
->state
& WNDS_INTERNALPAINT
)
1479 MsqDecPaintCountQueue(Window
->head
.pti
);
1482 type
= GdiGetClipBox(Ps
->hdc
, &Ps
->rcPaint
);
1484 IntGetClientRect(Window
, &Rect
);
1486 Window
->state
&= ~WNDS_INTERNALPAINT
;
1488 if ( Erase
&& // Set to erase,
1489 type
!= NULLREGION
&& // don't erase if the clip box is empty,
1490 (!(Window
->pcls
->style
& CS_PARENTDC
) || // not parent dc or
1491 RECTL_bIntersectRect( &Rect
, &Rect
, &Ps
->rcPaint
) ) ) // intersecting.
1493 Ps
->fErase
= !co_IntSendMessage(UserHMGetHandle(Window
), WM_ERASEBKGND
, (WPARAM
)Ps
->hdc
, 0);
1496 Window
->state
|= (WNDS_SENDERASEBACKGROUND
|WNDS_ERASEBACKGROUND
);
1504 IntSendChildNCPaint(Window
);
1510 IntEndPaint(PWND Wnd
, PPAINTSTRUCT Ps
)
1516 UserReleaseDC(Wnd
, hdc
, TRUE
);
1518 if (Wnd
->state2
& WNDS2_ENDPAINTINVALIDATE
)
1520 ERR("EP: Another thread invalidated this window\n");
1521 Wnd
->state2
&= ~WNDS2_ENDPAINTINVALIDATE
;
1524 Wnd
->state2
&= ~(WNDS2_WMPAINTSENT
|WNDS2_STARTPAINT
);
1526 co_UserShowCaret(Wnd
);
1531 /* PUBLIC FUNCTIONS ***********************************************************/
1541 NtUserBeginPaint(HWND hWnd
, PAINTSTRUCT
* UnsafePs
)
1547 USER_REFERENCE_ENTRY Ref
;
1548 DECLARE_RETURN(HDC
);
1550 TRACE("Enter NtUserBeginPaint\n");
1551 UserEnterExclusive();
1553 if (!(Window
= UserGetWindowObject(hWnd
)))
1558 UserRefObjectCo(Window
, &Ref
);
1560 hDC
= IntBeginPaint(Window
, &Ps
);
1562 Status
= MmCopyToCaller(UnsafePs
, &Ps
, sizeof(PAINTSTRUCT
));
1563 if (! NT_SUCCESS(Status
))
1565 SetLastNtError(Status
);
1572 if (Window
) UserDerefObjectCo(Window
);
1574 TRACE("Leave NtUserBeginPaint, ret=%p\n",_ret_
);
1588 NtUserEndPaint(HWND hWnd
, CONST PAINTSTRUCT
* pUnsafePs
)
1590 NTSTATUS Status
= STATUS_SUCCESS
;
1593 USER_REFERENCE_ENTRY Ref
;
1594 DECLARE_RETURN(BOOL
);
1596 TRACE("Enter NtUserEndPaint\n");
1597 UserEnterExclusive();
1599 if (!(Window
= UserGetWindowObject(hWnd
)))
1604 UserRefObjectCo(Window
, &Ref
); // Here for the exception.
1608 ProbeForRead(pUnsafePs
, sizeof(*pUnsafePs
), 1);
1609 RtlCopyMemory(&Ps
, pUnsafePs
, sizeof(PAINTSTRUCT
));
1611 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1613 Status
= _SEH2_GetExceptionCode();
1616 if (!NT_SUCCESS(Status
))
1621 RETURN(IntEndPaint(Window
, &Ps
));
1624 if (Window
) UserDerefObjectCo(Window
);
1626 TRACE("Leave NtUserEndPaint, ret=%i\n",_ret_
);
1635 NtUserFlashWindowEx(IN PFLASHWINFO pfwi
)
1638 FLASHWINFO finfo
= {0};
1641 UserEnterExclusive();
1645 ProbeForRead(pfwi
, sizeof(FLASHWINFO
), 1);
1646 RtlCopyMemory(&finfo
, pfwi
, sizeof(FLASHWINFO
));
1648 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1650 SetLastNtError(_SEH2_GetExceptionCode());
1651 _SEH2_YIELD(goto Exit
);
1655 if (!( pWnd
= ValidateHwndNoErr(finfo
.hwnd
)) ||
1656 finfo
.cbSize
!= sizeof(FLASHWINFO
) ||
1657 finfo
.dwFlags
& ~(FLASHW_ALL
|FLASHW_TIMER
|FLASHW_TIMERNOFG
) )
1659 EngSetLastError(ERROR_INVALID_PARAMETER
);
1663 Ret
= IntFlashWindowEx(pWnd
, &finfo
);
1671 GetUpdateRgn, this fails the same as the old one.
1674 co_UserGetUpdateRgn(PWND Window
, HRGN hRgn
, BOOL bErase
)
1680 ASSERT_REFS_CO(Window
);
1684 USER_REFERENCE_ENTRY Ref
;
1685 UserRefObjectCo(Window
, &Ref
);
1686 co_IntPaintWindows(Window
, RDW_NOCHILDREN
, FALSE
);
1687 UserDerefObjectCo(Window
);
1690 Window
->state
&= ~WNDS_UPDATEDIRTY
;
1692 if (Window
->hrgnUpdate
== NULL
)
1694 NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0);
1698 Rect
= Window
->rcClient
;
1699 Type
= IntIntersectWithParents(Window
, &Rect
);
1701 if (Window
->hrgnUpdate
== HRGN_WINDOW
)
1704 ERR("GURn: Caller is passing Window Region 1\n");
1707 NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0);
1711 RegionType
= SIMPLEREGION
;
1713 if (Window
!= UserGetDesktopWindow()) // Window->fnid == FNID_DESKTOP
1715 RECTL_vOffsetRect(&Rect
,
1716 -Window
->rcClient
.left
,
1717 -Window
->rcClient
.top
);
1719 GreSetRectRgnIndirect(hRgn
, &Rect
);
1723 HRGN hrgnTemp
= GreCreateRectRgnIndirect(&Rect
);
1725 RegionType
= NtGdiCombineRgn(hRgn
, hrgnTemp
, Window
->hrgnUpdate
, RGN_AND
);
1727 if (RegionType
== ERROR
|| RegionType
== NULLREGION
)
1729 if (hrgnTemp
) GreDeleteObject(hrgnTemp
);
1730 NtGdiSetRectRgn(hRgn
, 0, 0, 0, 0);
1734 if (Window
!= UserGetDesktopWindow()) // Window->fnid == FNID_DESKTOP
1736 NtGdiOffsetRgn(hRgn
,
1737 -Window
->rcClient
.left
,
1738 -Window
->rcClient
.top
);
1740 if (hrgnTemp
) GreDeleteObject(hrgnTemp
);
1746 co_UserGetUpdateRect(PWND Window
, PRECT pRect
, BOOL bErase
)
1753 USER_REFERENCE_ENTRY Ref
;
1754 UserRefObjectCo(Window
, &Ref
);
1755 co_IntPaintWindows(Window
, RDW_NOCHILDREN
, FALSE
);
1756 UserDerefObjectCo(Window
);
1759 Window
->state
&= ~WNDS_UPDATEDIRTY
;
1761 if (Window
->hrgnUpdate
== NULL
)
1763 pRect
->left
= pRect
->top
= pRect
->right
= pRect
->bottom
= 0;
1768 /* Get the update region bounding box. */
1769 if (Window
->hrgnUpdate
== HRGN_WINDOW
)
1771 *pRect
= Window
->rcClient
;
1772 ERR("GURt: Caller is retrieving Window Region 1\n");
1776 RegionType
= IntGdiGetRgnBox(Window
->hrgnUpdate
, pRect
);
1778 if (RegionType
!= ERROR
&& RegionType
!= NULLREGION
)
1779 RECTL_bIntersectRect(pRect
, pRect
, &Window
->rcClient
);
1782 if (IntIntersectWithParents(Window
, pRect
))
1784 if (Window
!= UserGetDesktopWindow()) // Window->fnid == FNID_DESKTOP
1786 RECTL_vOffsetRect(pRect
,
1787 -Window
->rcClient
.left
,
1788 -Window
->rcClient
.top
);
1790 if (Window
->pcls
->style
& CS_OWNDC
)
1794 hdc
= UserGetDCEx(Window
, NULL
, DCX_USESTYLE
);
1795 //layout = NtGdiSetLayout(hdc, -1, 0);
1796 //IntMapWindowPoints( 0, Window, (LPPOINT)pRect, 2 );
1797 GreDPtoLP( hdc
, (LPPOINT
)pRect
, 2 );
1798 //NtGdiSetLayout(hdc, -1, layout);
1799 UserReleaseDC(Window
, hdc
, FALSE
);
1804 pRect
->left
= pRect
->top
= pRect
->right
= pRect
->bottom
= 0;
1811 * NtUserGetUpdateRgn
1818 NtUserGetUpdateRgn(HWND hWnd
, HRGN hRgn
, BOOL bErase
)
1820 DECLARE_RETURN(INT
);
1824 TRACE("Enter NtUserGetUpdateRgn\n");
1825 UserEnterExclusive();
1827 if (!(Window
= UserGetWindowObject(hWnd
)))
1832 ret
= co_UserGetUpdateRgn(Window
, hRgn
, bErase
);
1837 TRACE("Leave NtUserGetUpdateRgn, ret=%i\n",_ret_
);
1843 * NtUserGetUpdateRect
1850 NtUserGetUpdateRect(HWND hWnd
, LPRECT UnsafeRect
, BOOL bErase
)
1856 DECLARE_RETURN(BOOL
);
1858 TRACE("Enter NtUserGetUpdateRect\n");
1859 UserEnterExclusive();
1861 if (!(Window
= UserGetWindowObject(hWnd
)))
1866 Ret
= co_UserGetUpdateRect(Window
, &Rect
, bErase
);
1868 if (UnsafeRect
!= NULL
)
1870 Status
= MmCopyToCaller(UnsafeRect
, &Rect
, sizeof(RECTL
));
1871 if (!NT_SUCCESS(Status
))
1873 EngSetLastError(ERROR_INVALID_PARAMETER
);
1881 TRACE("Leave NtUserGetUpdateRect, ret=%i\n",_ret_
);
1887 * NtUserRedrawWindow
1896 CONST RECT
*lprcUpdate
,
1900 RECTL SafeUpdateRect
;
1903 USER_REFERENCE_ENTRY Ref
;
1904 NTSTATUS Status
= STATUS_SUCCESS
;
1905 PREGION RgnUpdate
= NULL
;
1906 DECLARE_RETURN(BOOL
);
1908 TRACE("Enter NtUserRedrawWindow\n");
1909 UserEnterExclusive();
1911 if (!(Wnd
= UserGetWindowObject(hWnd
? hWnd
: IntGetDesktopWindow())))
1920 ProbeForRead(lprcUpdate
, sizeof(RECTL
), 1);
1921 RtlCopyMemory(&SafeUpdateRect
, lprcUpdate
, sizeof(RECTL
));
1923 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1925 Status
= _SEH2_GetExceptionCode();
1928 if (!NT_SUCCESS(Status
))
1930 EngSetLastError(RtlNtStatusToDosError(Status
));
1935 if ( flags
& ~(RDW_ERASE
|RDW_FRAME
|RDW_INTERNALPAINT
|RDW_INVALIDATE
|
1936 RDW_NOERASE
|RDW_NOFRAME
|RDW_NOINTERNALPAINT
|RDW_VALIDATE
|
1937 RDW_ERASENOW
|RDW_UPDATENOW
|RDW_ALLCHILDREN
|RDW_NOCHILDREN
) )
1939 /* RedrawWindow fails only in case that flags are invalid */
1940 EngSetLastError(ERROR_INVALID_FLAGS
);
1944 /* We can't hold lock on GDI objects while doing roundtrips to user mode,
1945 * so it will be copied.
1947 if (hrgnUpdate
> HRGN_WINDOW
)
1949 RgnUpdate
= REGION_LockRgn(hrgnUpdate
);
1952 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1955 REGION_UnlockRgn(RgnUpdate
);
1957 else if (hrgnUpdate
== HRGN_WINDOW
) // Trap it out.
1959 ERR("NTRW: Caller is passing Window Region 1\n");
1962 UserRefObjectCo(Wnd
, &Ref
);
1964 Ret
= co_UserRedrawWindow( Wnd
,
1965 lprcUpdate
? &SafeUpdateRect
: NULL
,
1969 UserDerefObjectCo(Wnd
);
1974 TRACE("Leave NtUserRedrawWindow, ret=%i\n",_ret_
);
1980 UserDrawCaptionText(
1983 const PUNICODE_STRING Text
,
1988 HFONT hOldFont
= NULL
;
1989 COLORREF OldTextColor
;
1990 NONCLIENTMETRICSW nclm
;
1992 BOOLEAN bDeleteFont
= FALSE
;
1995 ULONG fit
= 0, Length
;
1998 TRACE("UserDrawCaptionText: %wZ\n", Text
);
2000 nclm
.cbSize
= sizeof(nclm
);
2001 if(!UserSystemParametersInfo(SPI_GETNONCLIENTMETRICS
, sizeof(NONCLIENTMETRICS
), &nclm
, 0))
2003 ERR("UserSystemParametersInfo() failed!\n");
2009 if(uFlags
& DC_SMALLCAP
)
2010 Status
= TextIntCreateFontIndirect(&nclm
.lfSmCaptionFont
, &hFont
);
2012 Status
= TextIntCreateFontIndirect(&nclm
.lfCaptionFont
, &hFont
);
2014 if(!NT_SUCCESS(Status
))
2016 ERR("TextIntCreateFontIndirect() failed! Status: 0x%x\n", Status
);
2023 IntGdiSetBkMode(hDc
, TRANSPARENT
);
2025 hOldFont
= NtGdiSelectFont(hDc
, hFont
);
2027 if(uFlags
& DC_INBUTTON
)
2028 OldTextColor
= IntGdiSetTextColor(hDc
, IntGetSysColor(COLOR_BTNTEXT
));
2030 OldTextColor
= IntGdiSetTextColor(hDc
,
2031 IntGetSysColor(uFlags
& DC_ACTIVE
? COLOR_CAPTIONTEXT
: COLOR_INACTIVECAPTIONTEXT
));
2033 // Adjust for system menu.
2034 if (pWnd
&& pWnd
->style
& WS_SYSMENU
)
2036 r
.right
-= UserGetSystemMetrics(SM_CYCAPTION
) - 1;
2037 if ((pWnd
->style
& (WS_MAXIMIZEBOX
| WS_MINIMIZEBOX
)) && !(pWnd
->ExStyle
& WS_EX_TOOLWINDOW
))
2039 r
.right
-= UserGetSystemMetrics(SM_CXSIZE
) + 1;
2040 r
.right
-= UserGetSystemMetrics(SM_CXSIZE
) + 1;
2044 GreGetTextExtentExW(hDc
, Text
->Buffer
, Text
->Length
/sizeof(WCHAR
), r
.right
- r
.left
, &fit
, 0, &Size
, 0);
2046 Length
= (Text
->Length
/sizeof(WCHAR
) == fit
? fit
: fit
+1);
2048 if (Text
->Length
/sizeof(WCHAR
) > Length
)
2054 { // Faster while in setup.
2055 GreExtTextOutW( hDc
,
2057 lpRc
->top
+ (lpRc
->bottom
- lpRc
->top
) / 2 - Size
.cy
/ 2, // DT_SINGLELINE && DT_VCENTER
2069 Text
->Length
/sizeof(WCHAR
),
2071 DT_END_ELLIPSIS
|DT_SINGLELINE
|DT_VCENTER
|DT_NOPREFIX
|DT_LEFT
);
2074 IntGdiSetTextColor(hDc
, OldTextColor
);
2077 NtGdiSelectFont(hDc
, hOldFont
);
2080 GreDeleteObject(hFont
);
2086 // This draws Buttons, Icons and Text...
2088 BOOL
UserDrawCaption(
2094 const PUNICODE_STRING Str
,
2098 HBRUSH hBgBrush
, hOldBrush
= NULL
;
2102 RECTL_vMakeWellOrdered(lpRc
);
2104 /* Determine whether the icon needs to be displayed */
2105 if (!hIcon
&& pWnd
!= NULL
)
2107 HasIcon
= (uFlags
& DC_ICON
) && !(uFlags
& DC_SMALLCAP
) &&
2108 (pWnd
->style
& WS_SYSMENU
) && !(pWnd
->ExStyle
& WS_EX_TOOLWINDOW
);
2111 HasIcon
= (hIcon
!= NULL
);
2113 // Draw the caption background
2114 if((uFlags
& DC_GRADIENT
) && !(uFlags
& DC_INBUTTON
))
2116 static GRADIENT_RECT gcap
= {0, 1};
2117 TRIVERTEX Vertices
[2];
2120 Colors
[0] = IntGetSysColor((uFlags
& DC_ACTIVE
) ?
2121 COLOR_ACTIVECAPTION
: COLOR_INACTIVECAPTION
);
2123 Colors
[1] = IntGetSysColor((uFlags
& DC_ACTIVE
) ?
2124 COLOR_GRADIENTACTIVECAPTION
: COLOR_GRADIENTINACTIVECAPTION
);
2126 Vertices
[0].x
= Rect
.left
;
2127 Vertices
[0].y
= Rect
.top
;
2128 Vertices
[0].Red
= (WORD
)Colors
[0]<<8;
2129 Vertices
[0].Green
= (WORD
)Colors
[0] & 0xFF00;
2130 Vertices
[0].Blue
= (WORD
)(Colors
[0]>>8) & 0xFF00;
2131 Vertices
[0].Alpha
= 0;
2133 Vertices
[1].x
= Rect
.right
;
2134 Vertices
[1].y
= Rect
.bottom
;
2135 Vertices
[1].Red
= (WORD
)Colors
[1]<<8;
2136 Vertices
[1].Green
= (WORD
)Colors
[1] & 0xFF00;
2137 Vertices
[1].Blue
= (WORD
)(Colors
[1]>>8) & 0xFF00;
2138 Vertices
[1].Alpha
= 0;
2140 if(!GreGradientFill(hDc
, Vertices
, 2, &gcap
, 1, GRADIENT_FILL_RECT_H
))
2142 ERR("GreGradientFill() failed!\n");
2148 if(uFlags
& DC_INBUTTON
)
2149 hBgBrush
= IntGetSysColorBrush(COLOR_3DFACE
);
2150 else if(uFlags
& DC_ACTIVE
)
2151 hBgBrush
= IntGetSysColorBrush(COLOR_ACTIVECAPTION
);
2153 hBgBrush
= IntGetSysColorBrush(COLOR_INACTIVECAPTION
);
2155 hOldBrush
= NtGdiSelectBrush(hDc
, hBgBrush
);
2159 ERR("NtGdiSelectBrush() failed!\n");
2163 if(!NtGdiPatBlt(hDc
, Rect
.left
, Rect
.top
,
2164 Rect
.right
- Rect
.left
,
2165 Rect
.bottom
- Rect
.top
,
2168 ERR("NtGdiPatBlt() failed!\n");
2176 PCURICON_OBJECT pIcon
= NULL
;
2180 pIcon
= UserGetCurIconObject(hIcon
);
2184 pIcon
= NC_IconForWindow(pWnd
);
2185 // FIXME: NC_IconForWindow should reference it for us */
2187 UserReferenceObject(pIcon
);
2192 LONG cx
= UserGetSystemMetrics(SM_CXSMICON
);
2193 LONG cy
= UserGetSystemMetrics(SM_CYSMICON
);
2194 LONG x
= Rect
.left
- cx
/2 + 1 + (Rect
.bottom
- Rect
.top
)/2; // this is really what Window does
2195 LONG y
= (Rect
.top
+ Rect
.bottom
- cy
)/2; // center
2196 UserDrawIconEx(hDc
, x
, y
, pIcon
, cx
, cy
, 0, NULL
, DI_NORMAL
);
2197 UserDereferenceObject(pIcon
);
2206 Rect
.left
+= Rect
.bottom
- Rect
.top
;
2208 if((uFlags
& DC_TEXT
))
2214 Set
= UserDrawCaptionText(pWnd
, hDc
, Str
, &Rect
, uFlags
, hFont
);
2215 else if (pWnd
!= NULL
) // FIXME: Windows does not do that
2217 UNICODE_STRING ustr
;
2218 ustr
.Buffer
= pWnd
->strName
.Buffer
; // FIXME: LARGE_STRING truncated!
2219 ustr
.Length
= (USHORT
)min(pWnd
->strName
.Length
, MAXUSHORT
);
2220 ustr
.MaximumLength
= (USHORT
)min(pWnd
->strName
.MaximumLength
, MAXUSHORT
);
2221 Set
= UserDrawCaptionText(pWnd
, hDc
, &ustr
, &Rect
, uFlags
, hFont
);
2226 pWnd
->state2
&= ~WNDS2_CAPTIONTEXTTRUNCATED
;
2228 pWnd
->state2
|= WNDS2_CAPTIONTEXTTRUNCATED
;
2235 if (hOldBrush
) NtGdiSelectBrush(hDc
, hOldBrush
);
2242 UserRealizePalette(HDC hdc
)
2244 HWND hWnd
, hWndDesktop
;
2247 Ret
= IntGdiRealizePalette(hdc
);
2248 if (Ret
) // There was a change.
2250 hWnd
= IntWindowFromDC(hdc
);
2251 if (hWnd
) // Send broadcast if dc is associated with a window.
2252 { // FYI: Thread locked in CallOneParam.
2253 hWndDesktop
= IntGetDesktopWindow();
2254 if ( hWndDesktop
!= hWnd
)
2256 PWND pWnd
= UserGetWindowObject(hWndDesktop
);
2257 ERR("RealizePalette Desktop.");
2258 hdc
= UserGetWindowDC(pWnd
);
2259 IntPaintDesktop(hdc
);
2260 UserReleaseDC(pWnd
,hdc
,FALSE
);
2262 UserSendNotifyMessage((HWND
)HWND_BROADCAST
, WM_PALETTECHANGED
, (WPARAM
)hWnd
, 0);
2270 NtUserDrawCaptionTemp(
2276 const PUNICODE_STRING str
,
2280 UNICODE_STRING SafeStr
= {0};
2281 NTSTATUS Status
= STATUS_SUCCESS
;
2285 UserEnterExclusive();
2289 if(!(pWnd
= UserGetWindowObject(hWnd
)))
2298 ProbeForRead(lpRc
, sizeof(RECTL
), sizeof(ULONG
));
2299 RtlCopyMemory(&SafeRect
, lpRc
, sizeof(RECTL
));
2302 SafeStr
= ProbeForReadUnicodeString(str
);
2303 if (SafeStr
.Length
!= 0)
2305 ProbeForRead( SafeStr
.Buffer
,
2311 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2313 Status
= _SEH2_GetExceptionCode();
2317 if (Status
!= STATUS_SUCCESS
)
2319 SetLastNtError(Status
);
2325 Ret
= UserDrawCaption(pWnd
, hDC
, &SafeRect
, hFont
, hIcon
, &SafeStr
, uFlags
);
2328 if ( RECTL_bIsEmptyRect(&SafeRect
) && hFont
== 0 && hIcon
== 0 )
2331 if (uFlags
& DC_DRAWCAPTIONMD
)
2333 ERR("NC Caption Mode\n");
2334 UserDrawCaptionBar(pWnd
, hDC
, uFlags
);
2337 else if (uFlags
& DC_DRAWFRAMEMD
)
2339 ERR("NC Paint Mode\n");
2340 NC_DoNCPaint(pWnd
, hDC
, uFlags
); // Update Menus too!
2344 Ret
= UserDrawCaption(pWnd
, hDC
, &SafeRect
, hFont
, hIcon
, NULL
, uFlags
);
2353 NtUserDrawCaption(HWND hWnd
,
2358 return NtUserDrawCaptionTemp(hWnd
, hDC
, lpRc
, 0, 0, NULL
, uFlags
);
2363 NtUserInvalidateRect(
2365 CONST RECT
*lpUnsafeRect
,
2368 UINT flags
= RDW_INVALIDATE
| (bErase
? RDW_ERASE
: 0);
2371 flags
= RDW_ALLCHILDREN
| RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ERASENOW
;
2372 lpUnsafeRect
= NULL
;
2374 return NtUserRedrawWindow(hWnd
, lpUnsafeRect
, NULL
, flags
);
2379 NtUserInvalidateRgn(
2386 EngSetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2389 return NtUserRedrawWindow(hWnd
, NULL
, hRgn
, RDW_INVALIDATE
| (bErase
? RDW_ERASE
: 0));
2402 UserEnterExclusive();
2406 if (!(Window
= UserGetWindowObject(hwnd
)) || // FIXME:
2407 Window
== UserGetDesktopWindow() || // pWnd->fnid == FNID_DESKTOP
2408 Window
== UserGetMessageWindow() ) // pWnd->fnid == FNID_MESSAGEWND
2415 /* Validate flags and check it as a mask for 0 or 1. */
2416 if ( (nFlags
& PW_CLIENTONLY
) == nFlags
)
2417 Ret
= IntPrintWindow( Window
, hdcBlt
, nFlags
);
2419 EngSetLastError(ERROR_INVALID_PARAMETER
);
2427 /* ValidateRect gets redirected to NtUserValidateRect:
2428 http://blog.csdn.net/ntdll/archive/2005/10/19/509299.aspx */
2435 UINT flags
= RDW_VALIDATE
;
2438 flags
= RDW_ALLCHILDREN
| RDW_INVALIDATE
| RDW_FRAME
| RDW_ERASE
| RDW_ERASENOW
;
2441 return NtUserRedrawWindow(hWnd
, lpRect
, NULL
, flags
);