2 * PROJECT: ReactOS Win32k subsystem
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: subsystems/win32/win32k/ntuser/windc.c
5 * PURPOSE: Window DC management
6 * COPYRIGHT: Copyright 2007 ReactOS Team
10 DBG_DEFAULT_CHANNEL(UserDce
);
12 /* GLOBALS *******************************************************************/
14 /* NOTE: I think we should store this per window station (including GDI objects) */
15 /* Answer: No, use the DCE pMonitor to compare with! */
17 static LIST_ENTRY LEDce
;
18 static INT DCECount
= 0; // Count of DCE in system.
20 #define DCX_CACHECOMPAREMASK (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN | \
21 DCX_NORESETATTRS | DCX_LOCKWINDOWUPDATE | \
22 DCX_LAYEREDWIN | DCX_CACHE | DCX_WINDOW | \
25 /* FUNCTIONS *****************************************************************/
32 InitializeListHead(&LEDce
);
33 return STATUS_SUCCESS
;
37 // This should be moved to dc.c or dcutil.c.
40 DceCreateDisplayDC(VOID
)
42 UNICODE_STRING DriverName
= RTL_CONSTANT_STRING(L
"DISPLAY");
44 co_IntGraphicsCheck(TRUE
);
46 return IntGdiCreateDC(&DriverName
, NULL
, NULL
, NULL
, FALSE
);
49 /* Returns the DCE pointer from the HDC handle */
52 DceGetDceFromDC(HDC hdc
)
54 LIST_ENTRY
* Entry
= LEDce
.Flink
;
57 while (Entry
!= &LEDce
)
59 dce
= CONTAINING_RECORD(Entry
, DCE
, List
);
70 DceGetVisRgn(PWND Window
, ULONG Flags
, HWND hWndChild
, ULONG CFlags
)
74 hVisRgn
= VIS_ComputeVisibleRegion( Window
,
75 0 == (Flags
& DCX_WINDOW
),
76 0 != (Flags
& DCX_CLIPCHILDREN
),
77 0 != (Flags
& DCX_CLIPSIBLINGS
));
79 RetRgn
= IntSysCreateRectpRgn(0, 0, 0, 0);
83 PREGION VisRgn
= REGION_LockRgn(hVisRgn
);
84 IntGdiCombineRgn(RetRgn
, VisRgn
, NULL
, RGN_COPY
);
85 REGION_UnlockRgn(VisRgn
);
86 GreDeleteObject(hVisRgn
);
93 DceAllocDCE(PWND Window OPTIONAL
, DCE_TYPE Type
)
97 pDce
= ExAllocatePoolWithTag(PagedPool
, sizeof(DCE
), USERTAG_DCE
);
101 pDce
->hDC
= DceCreateDisplayDC();
104 ExFreePoolWithTag(pDce
, USERTAG_DCE
);
108 TRACE("Alloc DCE's! %d\n",DCECount
);
109 pDce
->hwndCurrent
= (Window
? Window
->head
.h
: NULL
);
110 pDce
->pwndOrg
= Window
;
111 pDce
->pwndClip
= Window
;
112 pDce
->hrgnClip
= NULL
;
113 pDce
->hrgnClipPublic
= NULL
;
114 pDce
->hrgnSavedVis
= NULL
;
115 pDce
->ppiOwner
= NULL
;
117 InsertTailList(&LEDce
, &pDce
->List
);
119 DCU_SetDcUndeletable(pDce
->hDC
);
121 if (Type
== DCE_WINDOW_DC
|| Type
== DCE_CLASS_DC
) // Window DCE have ownership.
123 pDce
->ptiOwner
= GetW32ThreadInfo();
127 TRACE("FREE DCATTR!!!! NOT DCE_WINDOW_DC!!!!! hDC-> %p\n", pDce
->hDC
);
128 GreSetDCOwner(pDce
->hDC
, GDI_OBJ_HMGR_NONE
);
129 pDce
->ptiOwner
= NULL
;
132 if (Type
== DCE_CACHE_DC
)
134 pDce
->DCXFlags
= DCX_CACHE
| DCX_DCEEMPTY
;
138 pDce
->DCXFlags
= DCX_DCEBUSY
;
141 if (Type
== DCE_WINDOW_DC
)
143 if (Window
->style
& WS_CLIPCHILDREN
) pDce
->DCXFlags
|= DCX_CLIPCHILDREN
;
144 if (Window
->style
& WS_CLIPSIBLINGS
) pDce
->DCXFlags
|= DCX_CLIPSIBLINGS
;
152 DceSetDrawable( PWND Window OPTIONAL
,
157 DC
*dc
= DC_LockDc(hDC
);
168 if (Flags
& DCX_WINDOW
)
170 dc
->ptlDCOrig
.x
= Window
->rcWindow
.left
;
171 dc
->ptlDCOrig
.y
= Window
->rcWindow
.top
;
175 dc
->ptlDCOrig
.x
= Window
->rcClient
.left
;
176 dc
->ptlDCOrig
.y
= Window
->rcClient
.top
;
179 dc
->fs
|= DC_FLAG_DIRTY_RAO
;
185 DceDeleteClipRgn(DCE
* Dce
)
187 Dce
->DCXFlags
&= ~(DCX_EXCLUDERGN
| DCX_INTERSECTRGN
);
189 if (Dce
->DCXFlags
& DCX_KEEPCLIPRGN
)
191 Dce
->DCXFlags
&= ~DCX_KEEPCLIPRGN
;
193 else if (Dce
->hrgnClip
!= NULL
)
195 GreDeleteObject(Dce
->hrgnClip
);
198 Dce
->hrgnClip
= NULL
;
200 /* Make it dirty so that the vis rgn gets recomputed next time */
201 Dce
->DCXFlags
|= DCX_DCEDIRTY
;
202 IntGdiSetHookFlags(Dce
->hDC
, DCHF_INVALIDATEVISRGN
);
207 DceUpdateVisRgn(DCE
*Dce
, PWND Window
, ULONG Flags
)
209 PREGION RgnVisible
= NULL
;
213 if (Flags
& DCX_PARENTCLIP
)
217 Parent
= Window
->spwndParent
;
224 if (Parent
->style
& WS_CLIPSIBLINGS
)
226 DcxFlags
= DCX_CLIPSIBLINGS
|
227 (Flags
& ~(DCX_CLIPCHILDREN
| DCX_WINDOW
));
231 DcxFlags
= Flags
& ~(DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
| DCX_WINDOW
);
233 RgnVisible
= DceGetVisRgn(Parent
, DcxFlags
, Window
->head
.h
, Flags
);
235 else if (Window
== NULL
)
237 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
238 if (NULL
!= DesktopWindow
)
240 RgnVisible
= IntSysCreateRectpRgnIndirect(&DesktopWindow
->rcWindow
);
249 RgnVisible
= DceGetVisRgn(Window
, Flags
, 0, 0);
253 if (Flags
& DCX_INTERSECTRGN
)
255 if(Dce
->hrgnClip
!= NULL
)
257 PREGION RgnClip
= REGION_LockRgn(Dce
->hrgnClip
);
258 IntGdiCombineRgn(RgnVisible
, RgnVisible
, RgnClip
, RGN_AND
);
259 REGION_UnlockRgn(RgnClip
);
263 if(RgnVisible
!= NULL
)
265 REGION_Delete(RgnVisible
);
267 RgnVisible
= IntSysCreateRectpRgn(0, 0, 0, 0);
270 else if ((Flags
& DCX_EXCLUDERGN
) && Dce
->hrgnClip
!= NULL
)
272 PREGION RgnClip
= REGION_LockRgn(Dce
->hrgnClip
);
273 IntGdiCombineRgn(RgnVisible
, RgnVisible
, RgnClip
, RGN_DIFF
);
274 REGION_UnlockRgn(RgnClip
);
277 Dce
->DCXFlags
&= ~DCX_DCEDIRTY
;
278 GdiSelectVisRgn(Dce
->hDC
, RgnVisible
);
280 if (VerifyWnd(Window
)) // Window maybe dead by this time before finishing the DCE release.
282 IntEngWindowChanged(Window
, WOC_RGN_CLIENT
);
285 if (RgnVisible
!= NULL
)
287 REGION_Delete(RgnVisible
);
292 DceReleaseDC(DCE
* dce
, BOOL EndPaint
)
294 if (DCX_DCEBUSY
!= (dce
->DCXFlags
& (DCX_INDESTROY
| DCX_DCEEMPTY
| DCX_DCEBUSY
)))
299 /* Restore previous visible region */
302 DceUpdateVisRgn(dce
, dce
->pwndOrg
, dce
->DCXFlags
);
305 if ((dce
->DCXFlags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) &&
306 ((dce
->DCXFlags
& DCX_CACHE
) || EndPaint
))
308 DceDeleteClipRgn(dce
);
311 if (dce
->DCXFlags
& DCX_CACHE
)
313 if (!(dce
->DCXFlags
& DCX_NORESETATTRS
))
316 if (!IntGdiCleanDC(dce
->hDC
)) return 0;
318 if (dce
->DCXFlags
& DCX_DCEDIRTY
)
320 /* Don't keep around invalidated entries
321 * because SetDCState() disables hVisRgn updates
322 * by removing dirty bit. */
323 dce
->hwndCurrent
= 0;
325 dce
->pwndClip
= NULL
;
326 dce
->DCXFlags
&= DCX_CACHE
;
327 dce
->DCXFlags
|= DCX_DCEEMPTY
;
330 dce
->DCXFlags
&= ~DCX_DCEBUSY
;
331 TRACE("Exit!!!!! DCX_CACHE!!!!!! hDC-> %p \n", dce
->hDC
);
332 if (!GreSetDCOwner(dce
->hDC
, GDI_OBJ_HMGR_NONE
))
334 dce
->ptiOwner
= NULL
; // Reset ownership.
335 dce
->ppiOwner
= NULL
;
337 #if 0 // Need to research and fix before this is a "growing" issue.
341 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
344 if (!(pDCE
->DCXFlags
& DCX_DCEBUSY
))
345 { /* Free the unused cache DCEs. */
346 pDCE
= DceFreeDCE(pDCE
, TRUE
);
351 while (pLE
!= &LEDce
);
355 return 1; // Released!
360 UserGetDCEx(PWND Wnd OPTIONAL
, HANDLE ClipRegion
, ULONG Flags
)
365 BOOL UpdateClipOrigin
= FALSE
;
366 BOOL bUpdateVisRgn
= TRUE
;
373 Flags
&= ~DCX_USESTYLE
;
377 if (Flags
& (DCX_WINDOW
| DCX_PARENTCLIP
)) Flags
|= DCX_CACHE
;
379 // When GetDC is called with hWnd nz, DCX_CACHE & _WINDOW are clear w _USESTYLE set.
380 if (Flags
& DCX_USESTYLE
)
382 Flags
&= ~(DCX_CLIPCHILDREN
| DCX_CLIPSIBLINGS
| DCX_PARENTCLIP
);
383 if (!(Flags
& DCX_WINDOW
)) // Not window rectangle
385 if (Wnd
->pcls
->style
& CS_PARENTDC
)
387 Flags
|= DCX_PARENTCLIP
;
390 if (!(Flags
& DCX_CACHE
) && // Not on the cheap wine list.
391 !(Wnd
->pcls
->style
& CS_OWNDC
) )
393 if (!(Wnd
->pcls
->style
& CS_CLASSDC
))
394 // The window is not POWNED or has any CLASS, so we are looking for cheap wine.
398 if (Wnd
->pcls
->pdce
) hDC
= ((PDCE
)Wnd
->pcls
->pdce
)->hDC
;
399 TRACE("We have CLASS!!\n");
403 if (Wnd
->style
& WS_CLIPSIBLINGS
)
405 Flags
|= DCX_CLIPSIBLINGS
;
408 if (Wnd
->style
& WS_CLIPCHILDREN
&&
409 !(Wnd
->style
& WS_MINIMIZE
))
411 Flags
|= DCX_CLIPCHILDREN
;
413 /* If minized with icon in the set, we are forced to be cheap! */
414 if (Wnd
->style
& WS_MINIMIZE
&&
422 if (Wnd
->style
& WS_CLIPSIBLINGS
) Flags
|= DCX_CLIPSIBLINGS
;
427 if (Flags
& DCX_WINDOW
) Flags
&= ~DCX_CLIPCHILDREN
;
429 if (Flags
& DCX_NOCLIPCHILDREN
)
432 Flags
&= ~(DCX_PARENTCLIP
| DCX_CLIPCHILDREN
);
435 Parent
= (Wnd
? Wnd
->spwndParent
: NULL
);
437 if (NULL
== Wnd
|| !(Wnd
->style
& WS_CHILD
) || NULL
== Parent
)
439 Flags
&= ~DCX_PARENTCLIP
;
440 Flags
|= DCX_CLIPSIBLINGS
;
443 /* It seems parent clip is ignored when clipping siblings or children */
444 if (Flags
& (DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
)) Flags
&= ~DCX_PARENTCLIP
;
446 if (Flags
& DCX_PARENTCLIP
)
448 if ((Wnd
->style
& WS_VISIBLE
) &&
449 (Parent
->style
& WS_VISIBLE
))
451 Flags
&= ~DCX_CLIPCHILDREN
;
452 if (Parent
->style
& WS_CLIPSIBLINGS
)
454 Flags
|= DCX_CLIPSIBLINGS
;
459 // Window nz, check to see if we still own this or it is just cheap wine tonight.
460 if (!(Flags
& DCX_CACHE
))
462 if ( Wnd
->head
.pti
!= GetW32ThreadInfo())
463 Flags
|= DCX_CACHE
; // Ah~ Not Powned! Forced to be cheap~
466 DcxFlags
= Flags
& DCX_CACHECOMPAREMASK
;
468 if (Flags
& DCX_CACHE
)
469 { // Scan the cheap wine list for our match.
470 DCE
* DceEmpty
= NULL
;
471 DCE
* DceUnused
= NULL
;
472 KeEnterCriticalRegion();
474 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
477 // The reason for this you may ask?
478 // Well, it seems ReactOS calls GetDC without first creating a desktop DC window!
479 // Need to test for null here. Not sure if this is a bug or a feature.
480 // First time use hax, need to use DceAllocDCE during window display init.
483 // The way I understand this, you can have more than one DC per window.
484 // Only one Owned if one was requested and saved and one Cached.
486 if ((Dce
->DCXFlags
& (DCX_CACHE
| DCX_DCEBUSY
)) == DCX_CACHE
)
489 if (Dce
->DCXFlags
& DCX_DCEEMPTY
)
493 else if (Dce
->hwndCurrent
== (Wnd
? Wnd
->head
.h
: NULL
) &&
494 ((Dce
->DCXFlags
& DCX_CACHECOMPAREMASK
) == DcxFlags
))
496 UpdateClipOrigin
= TRUE
;
500 pLE
= Dce
->List
.Flink
;
501 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
503 while (pLE
!= &LEDce
);
504 KeLeaveCriticalRegion();
506 Dce
= (DceEmpty
== NULL
) ? DceUnused
: DceEmpty
;
510 Dce
= DceAllocDCE(NULL
, DCE_CACHE_DC
);
512 if (!Dce
) return NULL
;
514 Dce
->hwndCurrent
= (Wnd
? Wnd
->head
.h
: NULL
);
515 Dce
->pwndOrg
= Dce
->pwndClip
= Wnd
;
517 else // If we are here, we are POWNED or having CLASS.
519 KeEnterCriticalRegion();
521 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
523 { // Check for Window handle than HDC match for CLASS.
524 if (Dce
->hwndCurrent
== Wnd
->head
.h
)
526 bUpdateVisRgn
= FALSE
;
529 if (Dce
->hDC
== hDC
) break;
530 pLE
= Dce
->List
.Flink
;
531 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
533 while (pLE
!= &LEDce
);
534 KeLeaveCriticalRegion();
536 if ( (Flags
& (DCX_INTERSECTRGN
|DCX_EXCLUDERGN
)) &&
537 (Dce
->DCXFlags
& (DCX_INTERSECTRGN
|DCX_EXCLUDERGN
)) )
539 DceDeleteClipRgn(Dce
);
542 // First time use hax, need to use DceAllocDCE during window display init.
548 if (!GreIsHandleValid(Dce
->hDC
))
550 ERR("FIXME: Got DCE with invalid hDC! %p\n", Dce
->hDC
);
551 Dce
->hDC
= DceCreateDisplayDC();
552 /* FIXME: Handle error */
555 Dce
->DCXFlags
= Flags
| DCX_DCEBUSY
;
558 * Bump it up! This prevents the random errors in wine dce tests and with
559 * proper bits set in DCX_CACHECOMPAREMASK.
561 * http://www.reactos.org/archives/public/ros-dev/2008-July/010498.html
562 * http://www.reactos.org/archives/public/ros-dev/2008-July/010499.html
566 RemoveEntryList(&Dce
->List
);
567 InsertHeadList(&LEDce
, &Dce
->List
);
570 /* Introduced in rev 6691 and modified later. */
571 if ( (Flags
& DCX_INTERSECTUPDATE
) && !ClipRegion
)
573 Flags
|= DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
;
574 Dce
->DCXFlags
|= DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
;
575 ClipRegion
= Wnd
->hrgnUpdate
;
576 bUpdateVisRgn
= TRUE
;
579 if (ClipRegion
== HRGN_WINDOW
)
581 if (!(Flags
& DCX_WINDOW
))
583 Dce
->hrgnClip
= IntSysCreateRectRgnIndirect(&Wnd
->rcClient
);
587 Dce
->hrgnClip
= IntSysCreateRectRgnIndirect(&Wnd
->rcWindow
);
589 Dce
->DCXFlags
&= ~DCX_KEEPCLIPRGN
;
590 bUpdateVisRgn
= TRUE
;
592 else if (ClipRegion
!= NULL
)
594 if (Dce
->hrgnClip
!= NULL
)
596 ERR("Should not be called!!\n");
597 GreDeleteObject(Dce
->hrgnClip
);
598 Dce
->hrgnClip
= NULL
;
600 Dce
->hrgnClip
= ClipRegion
;
601 bUpdateVisRgn
= TRUE
;
604 if (IntGdiSetHookFlags(Dce
->hDC
, DCHF_VALIDATEVISRGN
)) bUpdateVisRgn
= TRUE
;
606 DceSetDrawable(Wnd
, Dce
->hDC
, Flags
, UpdateClipOrigin
);
608 if (bUpdateVisRgn
) DceUpdateVisRgn(Dce
, Wnd
, Flags
);
610 if (Dce
->DCXFlags
& DCX_CACHE
)
612 TRACE("ENTER!!!!!! DCX_CACHE!!!!!! hDC-> %p\n", Dce
->hDC
);
613 // Need to set ownership so Sync dcattr will work.
614 GreSetDCOwner(Dce
->hDC
, GDI_OBJ_HMGR_POWNED
);
615 Dce
->ptiOwner
= GetW32ThreadInfo(); // Set the temp owning
619 Wnd
->ExStyle
& WS_EX_LAYOUTRTL
&&
620 !(Flags
& DCX_KEEPLAYOUT
) )
622 NtGdiSetLayout(Dce
->hDC
, -1, LAYOUT_RTL
);
625 if (Dce
->DCXFlags
& DCX_PROCESSOWNED
)
627 ppi
= PsGetCurrentProcessWin32Process();
628 ppi
->W32PF_flags
|= W32PF_OWNDCCLEANUP
;
629 Dce
->ptiOwner
= NULL
;
636 /***********************************************************************
640 DceFreeDCE(PDCE pdce
, BOOLEAN Force
)
646 if (NULL
== pdce
) return NULL
;
648 pLE
= pdce
->List
.Flink
;
649 ret
= CONTAINING_RECORD(pLE
, DCE
, List
);
651 pdce
->DCXFlags
|= DCX_INDESTROY
;
654 GreGetObjectOwner(pdce
->hDC
) != GDI_OBJ_HMGR_POWNED
)
656 TRACE("Change ownership for DCE! -> %p\n" , pdce
);
657 // NOTE: Windows sets W32PF_OWNDCCLEANUP and moves on.
658 if (GreIsHandleValid(pdce
->hDC
))
660 GreSetDCOwner(pdce
->hDC
, GDI_OBJ_HMGR_POWNED
);
664 ERR("Attempted to change ownership of an DCEhDC %p currently being destroyed!!!\n",
671 if (GreGetObjectOwner(pdce
->hDC
) == GDI_OBJ_HMGR_PUBLIC
)
672 GreSetDCOwner(pdce
->hDC
, GDI_OBJ_HMGR_POWNED
);
675 if (!Hit
) IntGdiDeleteDC(pdce
->hDC
, TRUE
);
677 if (pdce
->hrgnClip
&& !(pdce
->DCXFlags
& DCX_KEEPCLIPRGN
))
679 GreDeleteObject(pdce
->hrgnClip
);
680 pdce
->hrgnClip
= NULL
;
683 RemoveEntryList(&pdce
->List
);
685 if (IsListEmpty(&pdce
->List
))
687 ERR("List is Empty! DCE! -> %p\n" , pdce
);
691 ExFreePoolWithTag(pdce
, USERTAG_DCE
);
694 TRACE("Freed DCE's! %d \n", DCECount
);
699 /***********************************************************************
702 * Remove owned DCE and reset unreleased cache DCEs.
705 DceFreeWindowDCE(PWND Window
)
712 ERR("FreeWindowDCE No Entry! %d\n",DCECount
);
717 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
722 ERR("FreeWindowDCE No DCE Pointer!\n");
725 if (IsListEmpty(&pDCE
->List
))
727 ERR("FreeWindowDCE List is Empty!!!!\n");
730 if ( pDCE
->hwndCurrent
== Window
->head
.h
&&
731 !(pDCE
->DCXFlags
& DCX_DCEEMPTY
) )
733 if (!(pDCE
->DCXFlags
& DCX_CACHE
)) /* Owned or Class DCE */
735 if (Window
->pcls
->style
& CS_CLASSDC
) /* Test Class first */
737 if (pDCE
->DCXFlags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) /* Class DCE */
738 DceDeleteClipRgn(pDCE
);
739 // Update and reset Vis Rgn and clear the dirty bit.
740 // Should release VisRgn than reset it to default.
741 DceUpdateVisRgn(pDCE
, Window
, pDCE
->DCXFlags
);
742 pDCE
->DCXFlags
= DCX_DCEEMPTY
|DCX_CACHE
;
743 pDCE
->hwndCurrent
= 0;
744 pDCE
->pwndOrg
= pDCE
->pwndClip
= NULL
;
746 TRACE("POWNED DCE going Cheap!! DCX_CACHE!! hDC-> %p \n",
748 if (!GreSetDCOwner( pDCE
->hDC
, GDI_OBJ_HMGR_NONE
))
750 ERR("Fail Owner Switch hDC-> %p \n", pDCE
->hDC
);
753 /* Do not change owner so thread can clean up! */
755 else if (Window
->pcls
->style
& CS_OWNDC
) /* Owned DCE */
757 pDCE
= DceFreeDCE(pDCE
, FALSE
);
763 ERR("Not POWNED or CLASSDC hwndCurrent -> %p \n",
765 // ASSERT(FALSE); /* bug 5320 */
770 if (pDCE
->DCXFlags
& DCX_DCEBUSY
) /* Shared cache DCE */
772 /* FIXME: AFAICS we are doing the right thing here so
773 * this should be a TRACE. But this is best left as an ERR
774 * because the 'application error' is likely to come from
775 * another part of Wine (i.e. it's our fault after all).
776 * We should change this to TRACE when ReactOS is more stable
779 ERR("[%p] GetDC() without ReleaseDC()!\n", Window
->head
.h
);
780 DceReleaseDC(pDCE
, FALSE
);
782 pDCE
->DCXFlags
|= DCX_DCEEMPTY
;
783 pDCE
->hwndCurrent
= 0;
784 pDCE
->pwndOrg
= pDCE
->pwndClip
= NULL
;
787 pLE
= pDCE
->List
.Flink
;
788 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
790 while (pLE
!= &LEDce
);
794 DceFreeClassDCE(HDC hDC
)
799 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
804 if (pDCE
->hDC
== hDC
)
806 pDCE
= DceFreeDCE(pDCE
, TRUE
); // Might have gone cheap!
810 pLE
= pDCE
->List
.Flink
;
811 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
813 while (pLE
!= &LEDce
);
817 DceFreeThreadDCE(PTHREADINFO pti
)
822 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
827 if (pDCE
->ptiOwner
== pti
)
829 if (pDCE
->DCXFlags
& DCX_CACHE
)
831 pDCE
= DceFreeDCE(pDCE
, TRUE
);
836 pLE
= pDCE
->List
.Flink
;
837 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
839 while (pLE
!= &LEDce
);
848 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
853 pDCE
= DceFreeDCE(pDCE
, TRUE
);
856 while (pLE
!= &LEDce
);
860 DceResetActiveDCEs(PWND Window
)
874 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
879 if(pLE
== &LEDce
) break;
880 if (0 == (pDCE
->DCXFlags
& (DCX_DCEEMPTY
|DCX_INDESTROY
)))
882 if (Window
->head
.h
== pDCE
->hwndCurrent
)
884 CurrentWindow
= Window
;
888 if (!pDCE
->hwndCurrent
)
889 CurrentWindow
= NULL
;
891 CurrentWindow
= UserGetWindowObject(pDCE
->hwndCurrent
);
892 if (NULL
== CurrentWindow
)
894 pLE
= pDCE
->List
.Flink
;
895 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
900 if (!GreIsHandleValid(pDCE
->hDC
) ||
901 (dc
= DC_LockDc(pDCE
->hDC
)) == NULL
)
903 pLE
= pDCE
->List
.Flink
;
904 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
907 if (Window
== CurrentWindow
|| IntIsChildWindow(Window
, CurrentWindow
))
909 if (pDCE
->DCXFlags
& DCX_WINDOW
)
911 DeltaX
= CurrentWindow
->rcWindow
.left
- dc
->ptlDCOrig
.x
;
912 DeltaY
= CurrentWindow
->rcWindow
.top
- dc
->ptlDCOrig
.y
;
913 dc
->ptlDCOrig
.x
= CurrentWindow
->rcWindow
.left
;
914 dc
->ptlDCOrig
.y
= CurrentWindow
->rcWindow
.top
;
918 DeltaX
= CurrentWindow
->rcClient
.left
- dc
->ptlDCOrig
.x
;
919 DeltaY
= CurrentWindow
->rcClient
.top
- dc
->ptlDCOrig
.y
;
920 dc
->ptlDCOrig
.x
= CurrentWindow
->rcClient
.left
;
921 dc
->ptlDCOrig
.y
= CurrentWindow
->rcClient
.top
;
924 if (NULL
!= dc
->dclevel
.prgnClip
)
926 IntGdiOffsetRgn(dc
->dclevel
.prgnClip
, DeltaX
, DeltaY
);
927 dc
->fs
|= DC_FLAG_DIRTY_RAO
;
929 if (NULL
!= pDCE
->hrgnClip
)
931 NtGdiOffsetRgn(pDCE
->hrgnClip
, DeltaX
, DeltaY
);
936 DceUpdateVisRgn(pDCE
, CurrentWindow
, pDCE
->DCXFlags
);
937 IntGdiSetHookFlags(pDCE
->hDC
, DCHF_VALIDATEVISRGN
);
939 if (Window
->head
.h
!= pDCE
->hwndCurrent
)
941 // IntEngWindowChanged(CurrentWindow, WOC_RGN_CLIENT);
942 // UserDerefObject(CurrentWindow);
945 pLE
= pDCE
->List
.Flink
;
946 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
948 while (pLE
!= &LEDce
);
952 IntWindowFromDC(HDC hDc
)
959 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
964 if (Dce
->DCXFlags
& DCX_INDESTROY
)
967 Ret
= Dce
->hwndCurrent
;
970 pLE
= Dce
->List
.Flink
;
971 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
973 while (pLE
!= &LEDce
);
978 UserReleaseDC(PWND Window
, HDC hDc
, BOOL EndPaint
)
985 TRACE("%p %p\n", Window
, hDc
);
987 dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
996 pLE
= dce
->List
.Flink
;
997 dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
999 while (pLE
!= &LEDce
);
1001 if ( Hit
&& (dce
->DCXFlags
& DCX_DCEBUSY
))
1003 nRet
= DceReleaseDC(dce
, EndPaint
);
1010 UserGetWindowDC(PWND Wnd
)
1012 return UserGetDCEx(Wnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
1016 UserGethWnd( HDC hdc
, PWNDOBJ
*pwndo
)
1023 hWnd
= IntWindowFromDC(hdc
);
1025 if (hWnd
&& !(Wnd
= UserGetWindowObject(hWnd
)))
1027 pprop
= IntGetProp(Wnd
, AtomWndObj
);
1029 pWndgdi
= (WNDGDI
*)pprop
->Data
;
1031 if ( pWndgdi
&& pWndgdi
->Hwnd
== hWnd
)
1033 if (pwndo
) *pwndo
= (PWNDOBJ
)pWndgdi
;
1040 NtUserGetDCEx(HWND hWnd OPTIONAL
, HANDLE ClipRegion
, ULONG Flags
)
1043 DECLARE_RETURN(HDC
);
1045 TRACE("Enter NtUserGetDCEx\n");
1046 UserEnterExclusive();
1048 if (hWnd
&& !(Wnd
= UserGetWindowObject(hWnd
)))
1052 RETURN( UserGetDCEx(Wnd
, ClipRegion
, Flags
));
1055 TRACE("Leave NtUserGetDCEx, ret=%p\n", _ret_
);
1063 * The NtUserGetWindowDC function retrieves the device context (DC) for the
1064 * entire window, including title bar, menus, and scroll bars. A window device
1065 * context permits painting anywhere in a window, because the origin of the
1066 * device context is the upper-left corner of the window instead of the client
1073 NtUserGetWindowDC(HWND hWnd
)
1075 return NtUserGetDCEx(hWnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
1079 NtUserGetDC(HWND hWnd
)
1081 TRACE("NtUGetDC -> %p:%x\n", hWnd
, !hWnd
? DCX_CACHE
| DCX_WINDOW
: DCX_USESTYLE
);
1083 return NtUserGetDCEx(hWnd
, NULL
, NULL
== hWnd
? DCX_CACHE
| DCX_WINDOW
: DCX_USESTYLE
);
1087 * Select logical palette into device context.
1088 * \param hDC handle to the device context
1089 * \param hpal handle to the palette
1090 * \param ForceBackground If this value is FALSE the logical palette will be copied to the device palette only when the applicatioon
1091 * is in the foreground. If this value is TRUE then map the colors in the logical palette to the device
1092 * palette colors in the best way.
1093 * \return old palette
1095 * \todo implement ForceBackground == TRUE
1099 NtUserSelectPalette(HDC hDC
,
1101 BOOL ForceBackground
)
1104 UserEnterExclusive();
1105 // Implement window checks
1106 oldPal
= GdiSelectPalette( hDC
, hpal
, ForceBackground
);