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 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 #ifdef NEW_CURSORICON
407 if (Wnd
->style
& WS_MINIMIZE
&& Wnd
->pcls
->spicn
)
409 if (Wnd
->style
& WS_MINIMIZE
&& Wnd
->pcls
->hIcon
)
417 if (Wnd
->style
& WS_CLIPSIBLINGS
) Flags
|= DCX_CLIPSIBLINGS
;
422 if (Flags
& DCX_WINDOW
) Flags
&= ~DCX_CLIPCHILDREN
;
424 if (Flags
& DCX_NOCLIPCHILDREN
)
427 Flags
&= ~(DCX_PARENTCLIP
| DCX_CLIPCHILDREN
);
430 Parent
= (Wnd
? Wnd
->spwndParent
: NULL
);
432 if (NULL
== Wnd
|| !(Wnd
->style
& WS_CHILD
) || NULL
== Parent
)
434 Flags
&= ~DCX_PARENTCLIP
;
435 Flags
|= DCX_CLIPSIBLINGS
;
438 /* It seems parent clip is ignored when clipping siblings or children */
439 if (Flags
& (DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
)) Flags
&= ~DCX_PARENTCLIP
;
441 if (Flags
& DCX_PARENTCLIP
)
443 if ((Wnd
->style
& WS_VISIBLE
) &&
444 (Parent
->style
& WS_VISIBLE
))
446 Flags
&= ~DCX_CLIPCHILDREN
;
447 if (Parent
->style
& WS_CLIPSIBLINGS
)
449 Flags
|= DCX_CLIPSIBLINGS
;
454 // Window nz, check to see if we still own this or it is just cheap wine tonight.
455 if (!(Flags
& DCX_CACHE
))
457 if ( Wnd
->head
.pti
!= GetW32ThreadInfo())
458 Flags
|= DCX_CACHE
; // Ah~ Not Powned! Forced to be cheap~
461 DcxFlags
= Flags
& DCX_CACHECOMPAREMASK
;
463 if (Flags
& DCX_CACHE
)
464 { // Scan the cheap wine list for our match.
465 DCE
* DceEmpty
= NULL
;
466 DCE
* DceUnused
= NULL
;
467 KeEnterCriticalRegion();
468 ListEntry
= LEDce
.Flink
;
469 while (ListEntry
!= &LEDce
)
471 Dce
= CONTAINING_RECORD(ListEntry
, DCE
, List
);
472 ListEntry
= ListEntry
->Flink
;
474 // The way I understand this, you can have more than one DC per window.
475 // Only one Owned if one was requested and saved and one Cached.
477 if ((Dce
->DCXFlags
& (DCX_CACHE
| DCX_DCEBUSY
)) == DCX_CACHE
)
480 if (Dce
->DCXFlags
& DCX_DCEEMPTY
)
484 else if (Dce
->hwndCurrent
== (Wnd
? Wnd
->head
.h
: NULL
) &&
485 ((Dce
->DCXFlags
& DCX_CACHECOMPAREMASK
) == DcxFlags
))
487 UpdateClipOrigin
= TRUE
;
491 Dce
= NULL
; // Loop issue?
493 KeLeaveCriticalRegion();
495 Dce
= (DceEmpty
== NULL
) ? DceUnused
: DceEmpty
;
499 Dce
= DceAllocDCE(NULL
, DCE_CACHE_DC
);
501 if (Dce
== NULL
) return NULL
;
503 Dce
->hwndCurrent
= (Wnd
? Wnd
->head
.h
: NULL
);
504 Dce
->pwndOrg
= Dce
->pwndClip
= Wnd
;
506 else // If we are here, we are POWNED or having CLASS.
508 KeEnterCriticalRegion();
509 ListEntry
= LEDce
.Flink
;
510 while (ListEntry
!= &LEDce
)
512 Dce
= CONTAINING_RECORD(ListEntry
, DCE
, List
);
513 ListEntry
= ListEntry
->Flink
;
515 // Skip Cache DCE entries.
516 if (!(Dce
->DCXFlags
& DCX_CACHE
))
518 // Check for Window handle than HDC match for CLASS.
519 if (Dce
->hwndCurrent
== Wnd
->head
.h
)
521 bUpdateVisRgn
= FALSE
;
524 else if (Dce
->hDC
== hDC
) break;
526 Dce
= NULL
; // Loop issue?
528 KeLeaveCriticalRegion();
535 if ( (Flags
& (DCX_INTERSECTRGN
|DCX_EXCLUDERGN
)) &&
536 (Dce
->DCXFlags
& (DCX_INTERSECTRGN
|DCX_EXCLUDERGN
)) )
538 DceDeleteClipRgn(Dce
);
541 // First time use hax, need to use DceAllocDCE during window display init.
547 if (!GreIsHandleValid(Dce
->hDC
))
549 ERR("FIXME: Got DCE with invalid hDC! %p\n", Dce
->hDC
);
550 Dce
->hDC
= DceCreateDisplayDC();
551 /* FIXME: Handle error */
554 Dce
->DCXFlags
= Flags
| DCX_DCEBUSY
;
557 * Bump it up! This prevents the random errors in wine dce tests and with
558 * proper bits set in DCX_CACHECOMPAREMASK.
560 * http://www.reactos.org/archives/public/ros-dev/2008-July/010498.html
561 * http://www.reactos.org/archives/public/ros-dev/2008-July/010499.html
563 RemoveEntryList(&Dce
->List
);
564 InsertHeadList(&LEDce
, &Dce
->List
);
566 /* Introduced in rev 6691 and modified later. */
567 if ( (Flags
& DCX_INTERSECTUPDATE
) && !ClipRegion
)
569 Flags
|= DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
;
570 Dce
->DCXFlags
|= DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
;
571 ClipRegion
= Wnd
->hrgnUpdate
;
572 bUpdateVisRgn
= TRUE
;
575 if (ClipRegion
== HRGN_WINDOW
)
577 if (!(Flags
& DCX_WINDOW
))
579 Dce
->hrgnClip
= NtGdiCreateRectRgn(
583 Wnd
->rcClient
.bottom
);
587 Dce
->hrgnClip
= NtGdiCreateRectRgn(
591 Wnd
->rcWindow
.bottom
);
593 Dce
->DCXFlags
&= ~DCX_KEEPCLIPRGN
;
594 bUpdateVisRgn
= TRUE
;
596 else if (ClipRegion
!= NULL
)
598 if (Dce
->hrgnClip
!= NULL
)
600 ERR("Should not be called!!\n");
601 GreDeleteObject(Dce
->hrgnClip
);
602 Dce
->hrgnClip
= NULL
;
604 Dce
->hrgnClip
= ClipRegion
;
605 bUpdateVisRgn
= TRUE
;
608 if (IntGdiSetHookFlags(Dce
->hDC
, DCHF_VALIDATEVISRGN
)) bUpdateVisRgn
= TRUE
;
610 DceSetDrawable(Wnd
, Dce
->hDC
, Flags
, UpdateClipOrigin
);
612 if (bUpdateVisRgn
) DceUpdateVisRgn(Dce
, Wnd
, Flags
);
614 if (Dce
->DCXFlags
& DCX_CACHE
)
616 TRACE("ENTER!!!!!! DCX_CACHE!!!!!! hDC-> %p\n", Dce
->hDC
);
617 // Need to set ownership so Sync dcattr will work.
618 GreSetDCOwner(Dce
->hDC
, GDI_OBJ_HMGR_POWNED
);
619 Dce
->ptiOwner
= GetW32ThreadInfo(); // Set the temp owning
623 Wnd
->ExStyle
& WS_EX_LAYOUTRTL
&&
624 !(Flags
& DCX_KEEPLAYOUT
) )
626 NtGdiSetLayout(Dce
->hDC
, -1, LAYOUT_RTL
);
629 if (Dce
->DCXFlags
& DCX_PROCESSOWNED
)
631 ppi
= PsGetCurrentProcessWin32Process();
632 ppi
->W32PF_flags
|= W32PF_OWNDCCLEANUP
;
633 Dce
->ptiOwner
= NULL
;
640 /***********************************************************************
644 DceFreeDCE(PDCE pdce
, BOOLEAN Force
)
648 ASSERT(pdce
!= NULL
);
649 if (NULL
== pdce
) return;
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 ExFreePoolWithTag(pdce
, USERTAG_DCE
);
688 TRACE("Freed DCE's! %d \n", DCECount
);
691 /***********************************************************************
694 * Remove owned DCE and reset unreleased cache DCEs.
697 DceFreeWindowDCE(PWND Window
)
700 PLIST_ENTRY ListEntry
;
704 ERR("FreeWindowDCE No Entry! %d\n",DCECount
);
708 ListEntry
= LEDce
.Flink
;
709 while (ListEntry
!= &LEDce
)
711 pDCE
= CONTAINING_RECORD(ListEntry
, DCE
, List
);
712 ListEntry
= ListEntry
->Flink
;
713 if ( pDCE
->hwndCurrent
== Window
->head
.h
&&
714 !(pDCE
->DCXFlags
& DCX_DCEEMPTY
) )
716 if (!(pDCE
->DCXFlags
& DCX_CACHE
)) /* Owned or Class DCE */
718 if (Window
->pcls
->style
& CS_CLASSDC
) /* Test Class first */
720 if (pDCE
->DCXFlags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) /* Class DCE */
721 DceDeleteClipRgn(pDCE
);
722 // Update and reset Vis Rgn and clear the dirty bit.
723 // Should release VisRgn than reset it to default.
724 DceUpdateVisRgn(pDCE
, Window
, pDCE
->DCXFlags
);
725 pDCE
->DCXFlags
= DCX_DCEEMPTY
|DCX_CACHE
;
726 pDCE
->hwndCurrent
= 0;
727 pDCE
->pwndOrg
= pDCE
->pwndClip
= NULL
;
729 TRACE("POWNED DCE going Cheap!! DCX_CACHE!! hDC-> %p \n",
731 if (!GreSetDCOwner( pDCE
->hDC
, GDI_OBJ_HMGR_NONE
))
733 ERR("Fail Owner Switch hDC-> %p \n", pDCE
->hDC
);
736 /* Do not change owner so thread can clean up! */
738 else if (Window
->pcls
->style
& CS_OWNDC
) /* Owned DCE */
740 DceFreeDCE(pDCE
, FALSE
);
745 ERR("Not POWNED or CLASSDC hwndCurrent -> %p \n",
747 // ASSERT(FALSE); /* bug 5320 */
752 if (pDCE
->DCXFlags
& DCX_DCEBUSY
) /* Shared cache DCE */
754 /* FIXME: AFAICS we are doing the right thing here so
755 * this should be a TRACE. But this is best left as an ERR
756 * because the 'application error' is likely to come from
757 * another part of Wine (i.e. it's our fault after all).
758 * We should change this to TRACE when ReactOS is more stable
761 ERR("[%p] GetDC() without ReleaseDC()!\n", Window
->head
.h
);
762 DceReleaseDC(pDCE
, FALSE
);
764 pDCE
->DCXFlags
|= DCX_DCEEMPTY
;
765 pDCE
->hwndCurrent
= 0;
766 pDCE
->pwndOrg
= pDCE
->pwndClip
= NULL
;
773 DceFreeClassDCE(HDC hDC
)
776 PLIST_ENTRY ListEntry
;
778 ListEntry
= LEDce
.Flink
;
779 while (ListEntry
!= &LEDce
)
781 pDCE
= CONTAINING_RECORD(ListEntry
, DCE
, List
);
782 ListEntry
= ListEntry
->Flink
;
783 if (pDCE
->hDC
== hDC
)
785 DceFreeDCE(pDCE
, TRUE
); // Might have gone cheap!
791 DceFreeThreadDCE(PTHREADINFO pti
)
794 PLIST_ENTRY ListEntry
;
796 ListEntry
= LEDce
.Flink
;
797 while (ListEntry
!= &LEDce
)
799 pDCE
= CONTAINING_RECORD(ListEntry
, DCE
, List
);
800 ListEntry
= ListEntry
->Flink
;
801 if (pDCE
->ptiOwner
== pti
)
803 if (pDCE
->DCXFlags
& DCX_CACHE
)
805 DceFreeDCE(pDCE
, TRUE
);
815 PLIST_ENTRY ListEntry
;
817 ListEntry
= LEDce
.Flink
;
818 while (ListEntry
!= &LEDce
)
820 pDCE
= CONTAINING_RECORD(ListEntry
, DCE
, List
);
821 ListEntry
= ListEntry
->Flink
;
822 DceFreeDCE(pDCE
, TRUE
);
827 DceResetActiveDCEs(PWND Window
)
834 PLIST_ENTRY ListEntry
;
841 ListEntry
= LEDce
.Flink
;
842 while (ListEntry
!= &LEDce
)
844 pDCE
= CONTAINING_RECORD(ListEntry
, DCE
, List
);
845 ListEntry
= ListEntry
->Flink
;
846 if (0 == (pDCE
->DCXFlags
& (DCX_DCEEMPTY
|DCX_INDESTROY
)))
848 if (Window
->head
.h
== pDCE
->hwndCurrent
)
850 CurrentWindow
= Window
;
854 if (!pDCE
->hwndCurrent
)
855 CurrentWindow
= NULL
;
857 CurrentWindow
= UserGetWindowObject(pDCE
->hwndCurrent
);
858 if (NULL
== CurrentWindow
)
864 if (!GreIsHandleValid(pDCE
->hDC
) ||
865 (dc
= DC_LockDc(pDCE
->hDC
)) == NULL
)
869 if (Window
== CurrentWindow
|| IntIsChildWindow(Window
, CurrentWindow
))
871 if (pDCE
->DCXFlags
& DCX_WINDOW
)
873 DeltaX
= CurrentWindow
->rcWindow
.left
- dc
->ptlDCOrig
.x
;
874 DeltaY
= CurrentWindow
->rcWindow
.top
- dc
->ptlDCOrig
.y
;
875 dc
->ptlDCOrig
.x
= CurrentWindow
->rcWindow
.left
;
876 dc
->ptlDCOrig
.y
= CurrentWindow
->rcWindow
.top
;
880 DeltaX
= CurrentWindow
->rcClient
.left
- dc
->ptlDCOrig
.x
;
881 DeltaY
= CurrentWindow
->rcClient
.top
- dc
->ptlDCOrig
.y
;
882 dc
->ptlDCOrig
.x
= CurrentWindow
->rcClient
.left
;
883 dc
->ptlDCOrig
.y
= CurrentWindow
->rcClient
.top
;
886 if (NULL
!= dc
->dclevel
.prgnClip
)
888 REGION_bOffsetRgn(dc
->dclevel
.prgnClip
, DeltaX
, DeltaY
);
889 dc
->fs
|= DC_FLAG_DIRTY_RAO
;
891 if (NULL
!= pDCE
->hrgnClip
)
893 NtGdiOffsetRgn(pDCE
->hrgnClip
, DeltaX
, DeltaY
);
898 DceUpdateVisRgn(pDCE
, CurrentWindow
, pDCE
->DCXFlags
);
899 IntGdiSetHookFlags(pDCE
->hDC
, DCHF_VALIDATEVISRGN
);
905 IntWindowFromDC(HDC hDc
)
908 PLIST_ENTRY ListEntry
;
911 ListEntry
= LEDce
.Flink
;
912 while (ListEntry
!= &LEDce
)
914 Dce
= CONTAINING_RECORD(ListEntry
, DCE
, List
);
915 ListEntry
= ListEntry
->Flink
;
918 if (Dce
->DCXFlags
& DCX_INDESTROY
)
921 Ret
= Dce
->hwndCurrent
;
929 UserReleaseDC(PWND Window
, HDC hDc
, BOOL EndPaint
)
932 PLIST_ENTRY ListEntry
;
936 TRACE("%p %p\n", Window
, hDc
);
937 ListEntry
= LEDce
.Flink
;
938 while (ListEntry
!= &LEDce
)
940 dce
= CONTAINING_RECORD(ListEntry
, DCE
, List
);
941 ListEntry
= ListEntry
->Flink
;
949 if ( Hit
&& (dce
->DCXFlags
& DCX_DCEBUSY
))
951 nRet
= DceReleaseDC(dce
, EndPaint
);
958 UserGetWindowDC(PWND Wnd
)
960 return UserGetDCEx(Wnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
964 UserGethWnd( HDC hdc
, PWNDOBJ
*pwndo
)
971 hWnd
= IntWindowFromDC(hdc
);
973 if (hWnd
&& (Wnd
= UserGetWindowObject(hWnd
)))
975 pprop
= IntGetProp(Wnd
, AtomWndObj
);
977 Clip
= (XCLIPOBJ
*)pprop
->Data
;
979 if ( Clip
&& Clip
->Hwnd
== hWnd
)
981 if (pwndo
) *pwndo
= &Clip
->WndObj
;
988 NtUserGetDCEx(HWND hWnd OPTIONAL
, HANDLE ClipRegion
, ULONG Flags
)
993 TRACE("Enter NtUserGetDCEx: hWnd %p, ClipRegion %p, Flags %x.\n",
994 hWnd
, ClipRegion
, Flags
);
995 UserEnterExclusive();
997 if (hWnd
&& !(Wnd
= UserGetWindowObject(hWnd
)))
1001 RETURN( UserGetDCEx(Wnd
, ClipRegion
, Flags
));
1004 TRACE("Leave NtUserGetDCEx, ret=%p\n", _ret_
);
1012 * The NtUserGetWindowDC function retrieves the device context (DC) for the
1013 * entire window, including title bar, menus, and scroll bars. A window device
1014 * context permits painting anywhere in a window, because the origin of the
1015 * device context is the upper-left corner of the window instead of the client
1022 NtUserGetWindowDC(HWND hWnd
)
1024 return NtUserGetDCEx(hWnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
1028 NtUserGetDC(HWND hWnd
)
1030 TRACE("NtUGetDC -> %p:%x\n", hWnd
, !hWnd
? DCX_CACHE
| DCX_WINDOW
: DCX_USESTYLE
);
1032 return NtUserGetDCEx(hWnd
, NULL
, NULL
== hWnd
? DCX_CACHE
| DCX_WINDOW
: DCX_USESTYLE
);
1036 * Select logical palette into device context.
1037 * \param hDC handle to the device context
1038 * \param hpal handle to the palette
1039 * \param ForceBackground If this value is FALSE the logical palette will be copied to the device palette only when the applicatioon
1040 * is in the foreground. If this value is TRUE then map the colors in the logical palette to the device
1041 * palette colors in the best way.
1042 * \return old palette
1044 * \todo implement ForceBackground == TRUE
1048 NtUserSelectPalette(HDC hDC
,
1050 BOOL ForceBackground
)
1053 UserEnterExclusive();
1054 // Implement window checks
1055 oldPal
= GdiSelectPalette( hDC
, hpal
, ForceBackground
);