2 * PROJECT: ReactOS Win32k subsystem
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: win32ss/user/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 PLIST_ENTRY ListEntry
;
57 ListEntry
= LEDce
.Flink
;
58 while (ListEntry
!= &LEDce
)
60 dce
= CONTAINING_RECORD(ListEntry
, DCE
, List
);
61 ListEntry
= ListEntry
->Flink
;
71 DceGetVisRgn(PWND Window
, ULONG Flags
, HWND hWndChild
, ULONG CFlags
)
74 Rgn
= VIS_ComputeVisibleRegion( Window
,
75 0 == (Flags
& DCX_WINDOW
),
76 0 != (Flags
& DCX_CLIPCHILDREN
),
77 0 != (Flags
& DCX_CLIPSIBLINGS
));
78 /* Caller expects a non-null region */
80 Rgn
= IntSysCreateRectpRgn(0, 0, 0, 0);
85 DceAllocDCE(PWND Window OPTIONAL
, DCE_TYPE Type
)
89 pDce
= ExAllocatePoolWithTag(PagedPool
, sizeof(DCE
), USERTAG_DCE
);
93 pDce
->hDC
= DceCreateDisplayDC();
96 ExFreePoolWithTag(pDce
, USERTAG_DCE
);
100 TRACE("Alloc DCE's! %d\n",DCECount
);
101 pDce
->hwndCurrent
= (Window
? Window
->head
.h
: NULL
);
102 pDce
->pwndOrg
= Window
;
103 pDce
->pwndClip
= Window
;
104 pDce
->hrgnClip
= NULL
;
105 pDce
->hrgnClipPublic
= NULL
;
106 pDce
->hrgnSavedVis
= NULL
;
107 pDce
->ppiOwner
= NULL
;
109 InsertTailList(&LEDce
, &pDce
->List
);
111 DCU_SetDcUndeletable(pDce
->hDC
);
113 if (Type
== DCE_WINDOW_DC
|| Type
== DCE_CLASS_DC
) // Window DCE have ownership.
115 pDce
->ptiOwner
= GetW32ThreadInfo();
119 TRACE("FREE DCATTR!!!! NOT DCE_WINDOW_DC!!!!! hDC-> %p\n", pDce
->hDC
);
120 GreSetDCOwner(pDce
->hDC
, GDI_OBJ_HMGR_NONE
);
121 pDce
->ptiOwner
= NULL
;
124 if (Type
== DCE_CACHE_DC
)
126 pDce
->DCXFlags
= DCX_CACHE
| DCX_DCEEMPTY
;
130 pDce
->DCXFlags
= DCX_DCEBUSY
;
133 if (Type
== DCE_WINDOW_DC
)
135 if (Window
->style
& WS_CLIPCHILDREN
) pDce
->DCXFlags
|= DCX_CLIPCHILDREN
;
136 if (Window
->style
& WS_CLIPSIBLINGS
) pDce
->DCXFlags
|= DCX_CLIPSIBLINGS
;
144 DceSetDrawable( PWND Window OPTIONAL
,
149 DC
*dc
= DC_LockDc(hDC
);
160 if (Flags
& DCX_WINDOW
)
162 dc
->ptlDCOrig
.x
= Window
->rcWindow
.left
;
163 dc
->ptlDCOrig
.y
= Window
->rcWindow
.top
;
167 dc
->ptlDCOrig
.x
= Window
->rcClient
.left
;
168 dc
->ptlDCOrig
.y
= Window
->rcClient
.top
;
171 dc
->fs
|= DC_FLAG_DIRTY_RAO
;
177 DceDeleteClipRgn(DCE
* Dce
)
179 Dce
->DCXFlags
&= ~(DCX_EXCLUDERGN
| DCX_INTERSECTRGN
);
181 if (Dce
->DCXFlags
& DCX_KEEPCLIPRGN
)
183 Dce
->DCXFlags
&= ~DCX_KEEPCLIPRGN
;
185 else if (Dce
->hrgnClip
!= NULL
)
187 GreDeleteObject(Dce
->hrgnClip
);
190 Dce
->hrgnClip
= NULL
;
192 /* Make it dirty so that the vis rgn gets recomputed next time */
193 Dce
->DCXFlags
|= DCX_DCEDIRTY
;
194 IntGdiSetHookFlags(Dce
->hDC
, DCHF_INVALIDATEVISRGN
);
199 DceUpdateVisRgn(DCE
*Dce
, PWND Window
, ULONG Flags
)
201 PREGION RgnVisible
= NULL
;
205 if (Flags
& DCX_PARENTCLIP
)
209 Parent
= Window
->spwndParent
;
216 if (Parent
->style
& WS_CLIPSIBLINGS
)
218 DcxFlags
= DCX_CLIPSIBLINGS
|
219 (Flags
& ~(DCX_CLIPCHILDREN
| DCX_WINDOW
));
223 DcxFlags
= Flags
& ~(DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
| DCX_WINDOW
);
225 RgnVisible
= DceGetVisRgn(Parent
, DcxFlags
, Window
->head
.h
, Flags
);
227 else if (Window
== NULL
)
229 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
230 if (NULL
!= DesktopWindow
)
232 RgnVisible
= IntSysCreateRectpRgnIndirect(&DesktopWindow
->rcWindow
);
241 RgnVisible
= DceGetVisRgn(Window
, Flags
, 0, 0);
245 if (Flags
& DCX_INTERSECTRGN
)
247 PREGION RgnClip
= NULL
;
249 if (Dce
->hrgnClip
!= NULL
)
250 RgnClip
= REGION_LockRgn(Dce
->hrgnClip
);
254 IntGdiCombineRgn(RgnVisible
, RgnVisible
, RgnClip
, RGN_AND
);
255 REGION_UnlockRgn(RgnClip
);
259 if (RgnVisible
!= NULL
)
261 REGION_Delete(RgnVisible
);
263 RgnVisible
= IntSysCreateRectpRgn(0, 0, 0, 0);
266 else if ((Flags
& DCX_EXCLUDERGN
) && Dce
->hrgnClip
!= NULL
)
268 PREGION RgnClip
= REGION_LockRgn(Dce
->hrgnClip
);
269 IntGdiCombineRgn(RgnVisible
, RgnVisible
, RgnClip
, RGN_DIFF
);
270 REGION_UnlockRgn(RgnClip
);
273 Dce
->DCXFlags
&= ~DCX_DCEDIRTY
;
274 GdiSelectVisRgn(Dce
->hDC
, RgnVisible
);
275 /* Tell GDI driver */
277 IntEngWindowChanged(Window
, WOC_RGN_CLIENT
);
279 if (RgnVisible
!= NULL
)
281 REGION_Delete(RgnVisible
);
286 DceReleaseDC(DCE
* dce
, BOOL EndPaint
)
288 if (DCX_DCEBUSY
!= (dce
->DCXFlags
& (DCX_INDESTROY
| DCX_DCEEMPTY
| DCX_DCEBUSY
)))
293 /* Restore previous visible region */
296 DceUpdateVisRgn(dce
, dce
->pwndOrg
, dce
->DCXFlags
);
299 if ((dce
->DCXFlags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) &&
300 ((dce
->DCXFlags
& DCX_CACHE
) || EndPaint
))
302 DceDeleteClipRgn(dce
);
305 if (dce
->DCXFlags
& DCX_CACHE
)
307 if (!(dce
->DCXFlags
& DCX_NORESETATTRS
))
310 if (!IntGdiCleanDC(dce
->hDC
)) return 0;
312 if (dce
->DCXFlags
& DCX_DCEDIRTY
)
314 /* Don't keep around invalidated entries
315 * because SetDCState() disables hVisRgn updates
316 * by removing dirty bit. */
317 dce
->hwndCurrent
= 0;
319 dce
->pwndClip
= NULL
;
320 dce
->DCXFlags
&= DCX_CACHE
;
321 dce
->DCXFlags
|= DCX_DCEEMPTY
;
324 dce
->DCXFlags
&= ~DCX_DCEBUSY
;
325 TRACE("Exit!!!!! DCX_CACHE!!!!!! hDC-> %p \n", dce
->hDC
);
326 if (!GreSetDCOwner(dce
->hDC
, GDI_OBJ_HMGR_NONE
))
328 dce
->ptiOwner
= NULL
; // Reset ownership.
329 dce
->ppiOwner
= NULL
;
331 #if 0 // Need to research and fix before this is a "growing" issue.
334 ListEntry
= LEDce
.Flink
;
335 while (ListEntry
!= &LEDce
)
337 pDCE
= CONTAINING_RECORD(ListEntry
, DCE
, List
);
338 ListEntry
= ListEntry
->Flink
;
339 if (!(pDCE
->DCXFlags
& DCX_DCEBUSY
))
340 { /* Free the unused cache DCEs. */
341 DceFreeDCE(pDCE
, TRUE
);
347 return 1; // Released!
352 UserGetDCEx(PWND Wnd OPTIONAL
, HANDLE ClipRegion
, ULONG Flags
)
357 BOOL UpdateClipOrigin
= FALSE
;
358 BOOL bUpdateVisRgn
= TRUE
;
361 PLIST_ENTRY ListEntry
;
365 Flags
&= ~DCX_USESTYLE
;
369 if (Flags
& DCX_PARENTCLIP
) Flags
|= DCX_CACHE
;
371 // When GetDC is called with hWnd nz, DCX_CACHE & _WINDOW are clear w _USESTYLE set.
372 if (Flags
& DCX_USESTYLE
)
374 Flags
&= ~(DCX_CLIPCHILDREN
| DCX_CLIPSIBLINGS
| DCX_PARENTCLIP
);
375 if (!(Flags
& DCX_WINDOW
)) // Not window rectangle
377 if (Wnd
->pcls
->style
& CS_PARENTDC
)
379 Flags
|= DCX_PARENTCLIP
;
382 if (!(Flags
& DCX_CACHE
) && // Not on the cheap wine list.
383 !(Wnd
->pcls
->style
& CS_OWNDC
) )
385 if (!(Wnd
->pcls
->style
& CS_CLASSDC
))
386 // The window is not POWNED or has any CLASS, so we are looking for cheap wine.
390 if (Wnd
->pcls
->pdce
) hDC
= ((PDCE
)Wnd
->pcls
->pdce
)->hDC
;
391 TRACE("We have CLASS!!\n");
395 if (Wnd
->style
& WS_CLIPSIBLINGS
)
397 Flags
|= DCX_CLIPSIBLINGS
;
400 if (Wnd
->style
& WS_CLIPCHILDREN
&&
401 !(Wnd
->style
& WS_MINIMIZE
))
403 Flags
|= DCX_CLIPCHILDREN
;
405 /* If minized with icon in the set, we are forced to be cheap! */
406 if (Wnd
->style
& WS_MINIMIZE
&& Wnd
->pcls
->spicn
)
413 if (Wnd
->style
& WS_CLIPSIBLINGS
) Flags
|= DCX_CLIPSIBLINGS
;
418 if (Flags
& DCX_WINDOW
) Flags
&= ~DCX_CLIPCHILDREN
;
420 if (Flags
& DCX_NOCLIPCHILDREN
)
423 Flags
&= ~(DCX_PARENTCLIP
| DCX_CLIPCHILDREN
);
426 Parent
= (Wnd
? Wnd
->spwndParent
: NULL
);
428 if (NULL
== Wnd
|| !(Wnd
->style
& WS_CHILD
) || NULL
== Parent
)
430 Flags
&= ~DCX_PARENTCLIP
;
431 Flags
|= DCX_CLIPSIBLINGS
;
434 /* It seems parent clip is ignored when clipping siblings or children */
435 if (Flags
& (DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
)) Flags
&= ~DCX_PARENTCLIP
;
437 if (Flags
& DCX_PARENTCLIP
)
439 if ((Wnd
->style
& WS_VISIBLE
) &&
440 (Parent
->style
& WS_VISIBLE
))
442 Flags
&= ~DCX_CLIPCHILDREN
;
443 if (Parent
->style
& WS_CLIPSIBLINGS
)
445 Flags
|= DCX_CLIPSIBLINGS
;
450 // Window nz, check to see if we still own this or it is just cheap wine tonight.
451 if (!(Flags
& DCX_CACHE
))
453 if ( Wnd
->head
.pti
!= GetW32ThreadInfo())
454 Flags
|= DCX_CACHE
; // Ah~ Not Powned! Forced to be cheap~
457 DcxFlags
= Flags
& DCX_CACHECOMPAREMASK
;
459 if (Flags
& DCX_CACHE
)
460 { // Scan the cheap wine list for our match.
461 DCE
* DceEmpty
= NULL
;
462 DCE
* DceUnused
= NULL
;
463 KeEnterCriticalRegion();
464 ListEntry
= LEDce
.Flink
;
465 while (ListEntry
!= &LEDce
)
467 Dce
= CONTAINING_RECORD(ListEntry
, DCE
, List
);
468 ListEntry
= ListEntry
->Flink
;
470 // The way I understand this, you can have more than one DC per window.
471 // Only one Owned if one was requested and saved and one Cached.
473 if ((Dce
->DCXFlags
& (DCX_CACHE
| DCX_DCEBUSY
)) == DCX_CACHE
)
476 if (Dce
->DCXFlags
& DCX_DCEEMPTY
)
480 else if (Dce
->hwndCurrent
== (Wnd
? Wnd
->head
.h
: NULL
) &&
481 ((Dce
->DCXFlags
& DCX_CACHECOMPAREMASK
) == DcxFlags
))
483 UpdateClipOrigin
= TRUE
;
487 Dce
= NULL
; // Loop issue?
489 KeLeaveCriticalRegion();
491 Dce
= (DceEmpty
== NULL
) ? DceUnused
: DceEmpty
;
495 Dce
= DceAllocDCE(NULL
, DCE_CACHE_DC
);
497 if (Dce
== NULL
) return NULL
;
499 Dce
->hwndCurrent
= (Wnd
? Wnd
->head
.h
: NULL
);
500 Dce
->pwndOrg
= Dce
->pwndClip
= Wnd
;
502 else // If we are here, we are POWNED or having CLASS.
504 KeEnterCriticalRegion();
505 ListEntry
= LEDce
.Flink
;
506 while (ListEntry
!= &LEDce
)
508 Dce
= CONTAINING_RECORD(ListEntry
, DCE
, List
);
509 ListEntry
= ListEntry
->Flink
;
511 // Skip Cache DCE entries.
512 if (!(Dce
->DCXFlags
& DCX_CACHE
))
514 // Check for Window handle than HDC match for CLASS.
515 if (Dce
->hwndCurrent
== Wnd
->head
.h
)
517 bUpdateVisRgn
= FALSE
;
520 else if (Dce
->hDC
== hDC
) break;
522 Dce
= NULL
; // Loop issue?
524 KeLeaveCriticalRegion();
531 if ( (Flags
& (DCX_INTERSECTRGN
|DCX_EXCLUDERGN
)) &&
532 (Dce
->DCXFlags
& (DCX_INTERSECTRGN
|DCX_EXCLUDERGN
)) )
534 DceDeleteClipRgn(Dce
);
537 // First time use hax, need to use DceAllocDCE during window display init.
543 if (!GreIsHandleValid(Dce
->hDC
))
545 ERR("FIXME: Got DCE with invalid hDC! %p\n", Dce
->hDC
);
546 Dce
->hDC
= DceCreateDisplayDC();
547 /* FIXME: Handle error */
550 Dce
->DCXFlags
= Flags
| DCX_DCEBUSY
;
553 * Bump it up! This prevents the random errors in wine dce tests and with
554 * proper bits set in DCX_CACHECOMPAREMASK.
556 * http://www.reactos.org/archives/public/ros-dev/2008-July/010498.html
557 * http://www.reactos.org/archives/public/ros-dev/2008-July/010499.html
559 RemoveEntryList(&Dce
->List
);
560 InsertHeadList(&LEDce
, &Dce
->List
);
562 /* Introduced in rev 6691 and modified later. */
563 if ( (Flags
& DCX_INTERSECTUPDATE
) && !ClipRegion
)
565 Flags
|= DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
;
566 Dce
->DCXFlags
|= DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
;
567 ClipRegion
= Wnd
->hrgnUpdate
;
568 bUpdateVisRgn
= TRUE
;
571 if (ClipRegion
== HRGN_WINDOW
)
573 if (!(Flags
& DCX_WINDOW
))
575 Dce
->hrgnClip
= NtGdiCreateRectRgn(
579 Wnd
->rcClient
.bottom
);
583 Dce
->hrgnClip
= NtGdiCreateRectRgn(
587 Wnd
->rcWindow
.bottom
);
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
)
644 ASSERT(pdce
!= NULL
);
645 if (NULL
== pdce
) return;
647 pdce
->DCXFlags
|= DCX_INDESTROY
;
650 GreGetObjectOwner(pdce
->hDC
) != GDI_OBJ_HMGR_POWNED
)
652 TRACE("Change ownership for DCE! -> %p\n" , pdce
);
653 // NOTE: Windows sets W32PF_OWNDCCLEANUP and moves on.
654 if (GreIsHandleValid(pdce
->hDC
))
656 GreSetDCOwner(pdce
->hDC
, GDI_OBJ_HMGR_POWNED
);
660 ERR("Attempted to change ownership of an DCEhDC %p currently being destroyed!!!\n",
667 if (GreGetObjectOwner(pdce
->hDC
) == GDI_OBJ_HMGR_PUBLIC
)
668 GreSetDCOwner(pdce
->hDC
, GDI_OBJ_HMGR_POWNED
);
671 if (!Hit
) IntGdiDeleteDC(pdce
->hDC
, TRUE
);
673 if (pdce
->hrgnClip
&& !(pdce
->DCXFlags
& DCX_KEEPCLIPRGN
))
675 GreDeleteObject(pdce
->hrgnClip
);
676 pdce
->hrgnClip
= NULL
;
679 RemoveEntryList(&pdce
->List
);
681 ExFreePoolWithTag(pdce
, USERTAG_DCE
);
684 TRACE("Freed DCE's! %d \n", DCECount
);
687 /***********************************************************************
690 * Remove owned DCE and reset unreleased cache DCEs.
693 DceFreeWindowDCE(PWND Window
)
696 PLIST_ENTRY ListEntry
;
700 ERR("FreeWindowDCE No Entry! %d\n",DCECount
);
704 ListEntry
= LEDce
.Flink
;
705 while (ListEntry
!= &LEDce
)
707 pDCE
= CONTAINING_RECORD(ListEntry
, DCE
, List
);
708 ListEntry
= ListEntry
->Flink
;
709 if ( pDCE
->hwndCurrent
== Window
->head
.h
&&
710 !(pDCE
->DCXFlags
& DCX_DCEEMPTY
) )
712 if (!(pDCE
->DCXFlags
& DCX_CACHE
)) /* Owned or Class DCE */
714 if (Window
->pcls
->style
& CS_CLASSDC
) /* Test Class first */
716 if (pDCE
->DCXFlags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) /* Class DCE */
717 DceDeleteClipRgn(pDCE
);
718 // Update and reset Vis Rgn and clear the dirty bit.
719 // Should release VisRgn than reset it to default.
720 DceUpdateVisRgn(pDCE
, Window
, pDCE
->DCXFlags
);
721 pDCE
->DCXFlags
= DCX_DCEEMPTY
|DCX_CACHE
;
722 pDCE
->hwndCurrent
= 0;
723 pDCE
->pwndOrg
= pDCE
->pwndClip
= NULL
;
725 TRACE("POWNED DCE going Cheap!! DCX_CACHE!! hDC-> %p \n",
727 if (!GreSetDCOwner( pDCE
->hDC
, GDI_OBJ_HMGR_NONE
))
729 ERR("Fail Owner Switch hDC-> %p \n", pDCE
->hDC
);
732 /* Do not change owner so thread can clean up! */
734 else if (Window
->pcls
->style
& CS_OWNDC
) /* Owned DCE */
736 DceFreeDCE(pDCE
, FALSE
);
741 ERR("Not POWNED or CLASSDC hwndCurrent -> %p \n",
743 // ASSERT(FALSE); /* bug 5320 */
748 if (pDCE
->DCXFlags
& DCX_DCEBUSY
) /* Shared cache DCE */
750 /* FIXME: AFAICS we are doing the right thing here so
751 * this should be a TRACE. But this is best left as an ERR
752 * because the 'application error' is likely to come from
753 * another part of Wine (i.e. it's our fault after all).
754 * We should change this to TRACE when ReactOS is more stable
757 ERR("[%p] GetDC() without ReleaseDC()!\n", Window
->head
.h
);
758 DceReleaseDC(pDCE
, FALSE
);
760 pDCE
->DCXFlags
|= DCX_DCEEMPTY
;
761 pDCE
->hwndCurrent
= 0;
762 pDCE
->pwndOrg
= pDCE
->pwndClip
= NULL
;
769 DceFreeClassDCE(PDCE pdceClass
)
772 PLIST_ENTRY ListEntry
;
774 ListEntry
= LEDce
.Flink
;
775 while (ListEntry
!= &LEDce
)
777 pDCE
= CONTAINING_RECORD(ListEntry
, DCE
, List
);
778 ListEntry
= ListEntry
->Flink
;
779 if (pDCE
== pdceClass
)
781 DceFreeDCE(pDCE
, TRUE
); // Might have gone cheap!
787 DceFreeThreadDCE(PTHREADINFO pti
)
790 PLIST_ENTRY ListEntry
;
792 ListEntry
= LEDce
.Flink
;
793 while (ListEntry
!= &LEDce
)
795 pDCE
= CONTAINING_RECORD(ListEntry
, DCE
, List
);
796 ListEntry
= ListEntry
->Flink
;
797 if (pDCE
->ptiOwner
== pti
)
799 if (pDCE
->DCXFlags
& DCX_CACHE
)
801 DceFreeDCE(pDCE
, TRUE
);
811 PLIST_ENTRY ListEntry
;
813 ListEntry
= LEDce
.Flink
;
814 while (ListEntry
!= &LEDce
)
816 pDCE
= CONTAINING_RECORD(ListEntry
, DCE
, List
);
817 ListEntry
= ListEntry
->Flink
;
818 DceFreeDCE(pDCE
, TRUE
);
823 DceResetActiveDCEs(PWND Window
)
830 PLIST_ENTRY ListEntry
;
837 ListEntry
= LEDce
.Flink
;
838 while (ListEntry
!= &LEDce
)
840 pDCE
= CONTAINING_RECORD(ListEntry
, DCE
, List
);
841 ListEntry
= ListEntry
->Flink
;
842 if (0 == (pDCE
->DCXFlags
& (DCX_DCEEMPTY
|DCX_INDESTROY
)))
844 if (Window
->head
.h
== pDCE
->hwndCurrent
)
846 CurrentWindow
= Window
;
850 if (!pDCE
->hwndCurrent
)
851 CurrentWindow
= NULL
;
853 CurrentWindow
= UserGetWindowObject(pDCE
->hwndCurrent
);
854 if (NULL
== CurrentWindow
)
860 if (!GreIsHandleValid(pDCE
->hDC
) ||
861 (dc
= DC_LockDc(pDCE
->hDC
)) == NULL
)
865 if (Window
== CurrentWindow
|| IntIsChildWindow(Window
, CurrentWindow
))
867 if (pDCE
->DCXFlags
& DCX_WINDOW
)
869 DeltaX
= CurrentWindow
->rcWindow
.left
- dc
->ptlDCOrig
.x
;
870 DeltaY
= CurrentWindow
->rcWindow
.top
- dc
->ptlDCOrig
.y
;
871 dc
->ptlDCOrig
.x
= CurrentWindow
->rcWindow
.left
;
872 dc
->ptlDCOrig
.y
= CurrentWindow
->rcWindow
.top
;
876 DeltaX
= CurrentWindow
->rcClient
.left
- dc
->ptlDCOrig
.x
;
877 DeltaY
= CurrentWindow
->rcClient
.top
- dc
->ptlDCOrig
.y
;
878 dc
->ptlDCOrig
.x
= CurrentWindow
->rcClient
.left
;
879 dc
->ptlDCOrig
.y
= CurrentWindow
->rcClient
.top
;
882 if (NULL
!= dc
->dclevel
.prgnClip
)
884 REGION_bOffsetRgn(dc
->dclevel
.prgnClip
, DeltaX
, DeltaY
);
885 dc
->fs
|= DC_FLAG_DIRTY_RAO
;
887 if (NULL
!= pDCE
->hrgnClip
)
889 NtGdiOffsetRgn(pDCE
->hrgnClip
, DeltaX
, DeltaY
);
894 DceUpdateVisRgn(pDCE
, CurrentWindow
, pDCE
->DCXFlags
);
895 IntGdiSetHookFlags(pDCE
->hDC
, DCHF_VALIDATEVISRGN
);
901 IntWindowFromDC(HDC hDc
)
904 PLIST_ENTRY ListEntry
;
907 ListEntry
= LEDce
.Flink
;
908 while (ListEntry
!= &LEDce
)
910 Dce
= CONTAINING_RECORD(ListEntry
, DCE
, List
);
911 ListEntry
= ListEntry
->Flink
;
914 if (Dce
->DCXFlags
& DCX_INDESTROY
)
917 Ret
= Dce
->hwndCurrent
;
925 UserReleaseDC(PWND Window
, HDC hDc
, BOOL EndPaint
)
928 PLIST_ENTRY ListEntry
;
932 TRACE("%p %p\n", Window
, hDc
);
933 ListEntry
= LEDce
.Flink
;
934 while (ListEntry
!= &LEDce
)
936 dce
= CONTAINING_RECORD(ListEntry
, DCE
, List
);
937 ListEntry
= ListEntry
->Flink
;
945 if ( Hit
&& (dce
->DCXFlags
& DCX_DCEBUSY
))
947 nRet
= DceReleaseDC(dce
, EndPaint
);
954 UserGetWindowDC(PWND Wnd
)
956 return UserGetDCEx(Wnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
960 UserGethWnd( HDC hdc
, PWNDOBJ
*pwndo
)
966 hWnd
= IntWindowFromDC(hdc
);
968 if (hWnd
&& (Wnd
= UserGetWindowObject(hWnd
)))
970 Clip
= (XCLIPOBJ
*)UserGetProp(Wnd
, AtomWndObj
, TRUE
);
972 if ( Clip
&& Clip
->Hwnd
== hWnd
)
974 if (pwndo
) *pwndo
= &Clip
->WndObj
;
981 NtUserGetDCEx(HWND hWnd OPTIONAL
, HANDLE ClipRegion
, ULONG Flags
)
986 TRACE("Enter NtUserGetDCEx: hWnd %p, ClipRegion %p, Flags %x.\n",
987 hWnd
, ClipRegion
, Flags
);
988 UserEnterExclusive();
990 if (hWnd
&& !(Wnd
= UserGetWindowObject(hWnd
)))
994 RETURN( UserGetDCEx(Wnd
, ClipRegion
, Flags
));
997 TRACE("Leave NtUserGetDCEx, ret=%p\n", _ret_
);
1005 * The NtUserGetWindowDC function retrieves the device context (DC) for the
1006 * entire window, including title bar, menus, and scroll bars. A window device
1007 * context permits painting anywhere in a window, because the origin of the
1008 * device context is the upper-left corner of the window instead of the client
1015 NtUserGetWindowDC(HWND hWnd
)
1017 return NtUserGetDCEx(hWnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
1021 NtUserGetDC(HWND hWnd
)
1023 TRACE("NtUGetDC -> %p:%x\n", hWnd
, !hWnd
? DCX_CACHE
| DCX_WINDOW
: DCX_USESTYLE
);
1025 return NtUserGetDCEx(hWnd
, NULL
, NULL
== hWnd
? DCX_CACHE
| DCX_WINDOW
: DCX_USESTYLE
);
1029 * Select logical palette into device context.
1030 * \param hDC handle to the device context
1031 * \param hpal handle to the palette
1032 * \param ForceBackground If this value is FALSE the logical palette will be copied to the device palette only when the applicatioon
1033 * is in the foreground. If this value is TRUE then map the colors in the logical palette to the device
1034 * palette colors in the best way.
1035 * \return old palette
1037 * \todo implement ForceBackground == TRUE
1041 NtUserSelectPalette(HDC hDC
,
1043 BOOL ForceBackground
)
1046 UserEnterExclusive();
1047 // Implement window checks
1048 oldPal
= GdiSelectPalette( hDC
, hpal
, ForceBackground
);