2 * PROJECT: ReactOS Kernel
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
10 /* INCLUDES ******************************************************************/
17 int FASTCALL
CLIPPING_UpdateGCRegion(DC
* Dc
);
19 /* GLOBALS *******************************************************************/
21 /* NOTE - I think we should store this per window station (including gdi objects) */
22 /* Answer: No, use the DCE pMonitor to compare with! */
24 static LIST_ENTRY LEDce
;
25 static INT DCECount
= 0; // Count of DCE in system.
27 #define DCX_CACHECOMPAREMASK (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN | \
28 DCX_NORESETATTRS | DCX_LOCKWINDOWUPDATE | \
29 DCX_LAYEREDWIN | DCX_CACHE | DCX_WINDOW | \
32 /* FUNCTIONS *****************************************************************/
35 // This should be moved to dc.c or dcutil.c.
38 DceCreateDisplayDC(VOID
)
41 UNICODE_STRING DriverName
;
42 RtlInitUnicodeString(&DriverName
, L
"DISPLAY");
43 hDC
= IntGdiCreateDC(&DriverName
, NULL
, NULL
, NULL
, FALSE
);
45 co_IntGraphicsCheck(TRUE
);
48 // If NULL, first time through! Build the default window dc!
50 if (hDC
&& !defaultDCstate
) // Ultra HAX! Dedicated to GvG!
51 { // This is a cheesy way to do this.
52 PDC dc
= DC_LockDc ( hDC
);
53 defaultDCstate
= ExAllocatePoolWithTag(PagedPool
, sizeof(DC
), TAG_DC
);
54 RtlZeroMemory(defaultDCstate
, sizeof(DC
));
55 defaultDCstate
->pdcattr
= &defaultDCstate
->dcattr
;
56 DC_vCopyState(dc
, defaultDCstate
, TRUE
);
58 InitializeListHead(&LEDce
);
65 DceGetVisRgn(PWND Window
, ULONG Flags
, HWND hWndChild
, ULONG CFlags
)
69 VisRgn
= VIS_ComputeVisibleRegion( Window
,
70 0 == (Flags
& DCX_WINDOW
),
71 0 != (Flags
& DCX_CLIPCHILDREN
),
72 0 != (Flags
& DCX_CLIPSIBLINGS
));
75 VisRgn
= IntSysCreateRectRgn(0, 0, 0, 0);
81 DceAllocDCE(PWND Window OPTIONAL
, DCE_TYPE Type
)
85 pDce
= ExAllocatePoolWithTag(PagedPool
, sizeof(DCE
), TAG_PDCE
);
89 pDce
->hDC
= DceCreateDisplayDC();
92 ExFreePoolWithTag(pDce
, TAG_PDCE
);
96 DPRINT("Alloc DCE's! %d\n",DCECount
);
97 pDce
->hwndCurrent
= (Window
? Window
->head
.h
: NULL
);
98 pDce
->pwndOrg
= Window
;
99 pDce
->pwndClip
= Window
;
100 pDce
->hrgnClip
= NULL
;
101 pDce
->hrgnClipPublic
= NULL
;
102 pDce
->hrgnSavedVis
= NULL
;
103 pDce
->ppiOwner
= NULL
;
105 InsertTailList(&LEDce
, &pDce
->List
);
107 DCU_SetDcUndeletable(pDce
->hDC
);
109 if (Type
== DCE_WINDOW_DC
|| Type
== DCE_CLASS_DC
) //Window DCE have ownership.
111 pDce
->ptiOwner
= GetW32ThreadInfo();
115 DPRINT("FREE DCATTR!!!! NOT DCE_WINDOW_DC!!!!! hDC-> %x\n", pDce
->hDC
);
116 IntGdiSetDCOwnerEx( pDce
->hDC
, GDI_OBJ_HMGR_NONE
, FALSE
);
117 pDce
->ptiOwner
= NULL
;
120 if (Type
== DCE_CACHE_DC
)
122 pDce
->DCXFlags
= DCX_CACHE
| DCX_DCEEMPTY
;
126 pDce
->DCXFlags
= DCX_DCEBUSY
;
129 if (Type
== DCE_WINDOW_DC
)
131 if (Window
->style
& WS_CLIPCHILDREN
) pDce
->DCXFlags
|= DCX_CLIPCHILDREN
;
132 if (Window
->style
& WS_CLIPSIBLINGS
) pDce
->DCXFlags
|= DCX_CLIPSIBLINGS
;
140 DceSetDrawable( PWND Window OPTIONAL
,
145 DC
*dc
= DC_LockDc(hDC
);
156 if (Flags
& DCX_WINDOW
)
158 dc
->ptlDCOrig
.x
= Window
->rcWindow
.left
;
159 dc
->ptlDCOrig
.y
= Window
->rcWindow
.top
;
163 dc
->ptlDCOrig
.x
= Window
->rcClient
.left
;
164 dc
->ptlDCOrig
.y
= Window
->rcClient
.top
;
172 DceDeleteClipRgn(DCE
* Dce
)
174 Dce
->DCXFlags
&= ~(DCX_EXCLUDERGN
| DCX_INTERSECTRGN
);
176 if (Dce
->DCXFlags
& DCX_KEEPCLIPRGN
)
178 Dce
->DCXFlags
&= ~DCX_KEEPCLIPRGN
;
180 else if (Dce
->hrgnClip
!= NULL
)
182 GDIOBJ_FreeObjByHandle(Dce
->hrgnClip
, GDI_OBJECT_TYPE_REGION
|GDI_OBJECT_TYPE_SILENT
);
185 Dce
->hrgnClip
= NULL
;
187 /* make it dirty so that the vis rgn gets recomputed next time */
188 Dce
->DCXFlags
|= DCX_DCEDIRTY
;
192 DceReleaseDC(DCE
* dce
, BOOL EndPaint
)
194 if (DCX_DCEBUSY
!= (dce
->DCXFlags
& (DCX_INDESTROY
| DCX_DCEEMPTY
| DCX_DCEBUSY
)))
199 /* restore previous visible region */
200 if ((dce
->DCXFlags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) &&
201 ((dce
->DCXFlags
& DCX_CACHE
) || EndPaint
))
203 DceDeleteClipRgn(dce
);
206 if (dce
->DCXFlags
& DCX_CACHE
)
208 if (!(dce
->DCXFlags
& DCX_NORESETATTRS
))
210 /* make the DC clean so that SetDCState doesn't try to update the vis rgn */
211 IntGdiSetHookFlags(dce
->hDC
, DCHF_VALIDATEVISRGN
);
214 if (!IntGdiCleanDC(dce
->hDC
)) return 0;
216 if (dce
->DCXFlags
& DCX_DCEDIRTY
)
218 /* don't keep around invalidated entries
219 * because SetDCState() disables hVisRgn updates
220 * by removing dirty bit. */
221 dce
->hwndCurrent
= 0;
222 dce
->DCXFlags
&= DCX_CACHE
;
223 dce
->DCXFlags
|= DCX_DCEEMPTY
;
226 dce
->DCXFlags
&= ~DCX_DCEBUSY
;
227 DPRINT("Exit!!!!! DCX_CACHE!!!!!! hDC-> %x \n", dce
->hDC
);
228 if (!IntGdiSetDCOwnerEx( dce
->hDC
, GDI_OBJ_HMGR_NONE
, FALSE
))
230 dce
->ptiOwner
= NULL
; // Reset ownership.
231 dce
->ppiOwner
= NULL
;
233 #if 0 // Need to research and fix before this is a "growing" issue.
237 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
240 if (!(pDCE
->DCXFlags
& DCX_DCEBUSY
))
241 { /* Free the unused cache DCEs. */
242 pDCE
= DceFreeDCE(pDCE
, TRUE
);
247 while (pLE
!= &LEDce
);
251 return 1; // Released!
255 DceUpdateVisRgn(DCE
*Dce
, PWND Window
, ULONG Flags
)
257 HANDLE hRgnVisible
= NULL
;
261 if (Flags
& DCX_PARENTCLIP
)
265 Parent
= Window
->spwndParent
;
272 if (Parent
->style
& WS_CLIPSIBLINGS
)
274 DcxFlags
= DCX_CLIPSIBLINGS
|
275 (Flags
& ~(DCX_CLIPCHILDREN
| DCX_WINDOW
));
279 DcxFlags
= Flags
& ~(DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
| DCX_WINDOW
);
281 hRgnVisible
= DceGetVisRgn(Parent
, DcxFlags
, Window
->head
.h
, Flags
);
283 else if (Window
== NULL
)
285 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
286 if (NULL
!= DesktopWindow
)
288 hRgnVisible
= IntSysCreateRectRgnIndirect(&DesktopWindow
->rcWindow
);
297 hRgnVisible
= DceGetVisRgn(Window
, Flags
, 0, 0);
301 if (Flags
& DCX_INTERSECTRGN
)
303 if(Dce
->hrgnClip
!= NULL
)
305 NtGdiCombineRgn(hRgnVisible
, hRgnVisible
, Dce
->hrgnClip
, RGN_AND
);
309 if(hRgnVisible
!= NULL
)
311 REGION_FreeRgnByHandle(hRgnVisible
);
313 hRgnVisible
= IntSysCreateRectRgn(0, 0, 0, 0);
316 else if (Flags
& DCX_EXCLUDERGN
&& Dce
->hrgnClip
!= NULL
)
318 NtGdiCombineRgn(hRgnVisible
, hRgnVisible
, Dce
->hrgnClip
, RGN_DIFF
);
321 Dce
->DCXFlags
&= ~DCX_DCEDIRTY
;
322 GdiSelectVisRgn(Dce
->hDC
, hRgnVisible
);
326 IntEngWindowChanged(Window
, WOC_RGN_CLIENT
);
329 if (hRgnVisible
!= NULL
)
331 REGION_FreeRgnByHandle(hRgnVisible
);
336 UserGetDCEx(PWND Wnd OPTIONAL
, HANDLE ClipRegion
, ULONG Flags
)
341 BOOL UpdateClipOrigin
= FALSE
;
348 Flags
&= ~DCX_USESTYLE
;
352 if (Flags
& (DCX_WINDOW
| DCX_PARENTCLIP
)) Flags
|= DCX_CACHE
;
354 // When GetDC is called with hWnd nz, DCX_CACHE & _WINDOW are clear w _USESTYLE set.
355 if (Flags
& DCX_USESTYLE
)
357 Flags
&= ~(DCX_CLIPCHILDREN
| DCX_CLIPSIBLINGS
| DCX_PARENTCLIP
);
358 if (!(Flags
& DCX_WINDOW
)) // not window rectangle
360 if (Wnd
->pcls
->style
& CS_PARENTDC
)
362 Flags
|= DCX_PARENTCLIP
;
365 if (!(Flags
& DCX_CACHE
) && // Not on the cheap wine list.
366 !(Wnd
->pcls
->style
& CS_OWNDC
) )
368 if (!(Wnd
->pcls
->style
& CS_CLASSDC
))
369 // The window is not POWNED or has any CLASS, so we are looking for cheap wine.
373 if (Wnd
->pcls
->pdce
) hDC
= ((PDCE
)Wnd
->pcls
->pdce
)->hDC
;
374 DPRINT("We have CLASS!!\n");
377 /* else // For Testing!
379 DPRINT1("We have POWNER!!\n");
380 if (Window->Dce) DPRINT1("We have POWNER with DCE!!\n");
383 if (Wnd
->style
& WS_CLIPSIBLINGS
)
385 Flags
|= DCX_CLIPSIBLINGS
;
388 if (Wnd
->style
& WS_CLIPCHILDREN
&&
389 !(Wnd
->style
& WS_MINIMIZE
))
391 Flags
|= DCX_CLIPCHILDREN
;
393 /* If minized with icon in the set, we are forced to be cheap! */
394 if (Wnd
->style
& WS_MINIMIZE
&&
402 if (Wnd
->style
& WS_CLIPSIBLINGS
) Flags
|= DCX_CLIPSIBLINGS
;
407 if (Flags
& DCX_WINDOW
) Flags
&= ~DCX_CLIPCHILDREN
;
409 if (Flags
& DCX_NOCLIPCHILDREN
)
412 Flags
&= ~(DCX_PARENTCLIP
| DCX_CLIPCHILDREN
);
415 Parent
= (Wnd
? Wnd
->spwndParent
: NULL
);
417 if (NULL
== Wnd
|| !(Wnd
->style
& WS_CHILD
) || NULL
== Parent
)
419 Flags
&= ~DCX_PARENTCLIP
;
420 Flags
|= DCX_CLIPSIBLINGS
;
423 /* it seems parent clip is ignored when clipping siblings or children */
424 if (Flags
& (DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
)) Flags
&= ~DCX_PARENTCLIP
;
426 if (Flags
& DCX_PARENTCLIP
)
428 if ((Wnd
->style
& WS_VISIBLE
) &&
429 (Parent
->style
& WS_VISIBLE
))
431 Flags
&= ~DCX_CLIPCHILDREN
;
432 if (Parent
->style
& WS_CLIPSIBLINGS
)
434 Flags
|= DCX_CLIPSIBLINGS
;
439 // Window nz, check to see if we still own this or it is just cheap wine tonight.
440 if (!(Flags
& DCX_CACHE
))
442 if ( Wnd
->head
.pti
!= GetW32ThreadInfo())
443 Flags
|= DCX_CACHE
; // Ah~ Not Powned! Forced to be cheap~
446 DcxFlags
= Flags
& DCX_CACHECOMPAREMASK
;
448 if (Flags
& DCX_CACHE
)
449 { // Scan the cheap wine list for our match.
450 DCE
* DceEmpty
= NULL
;
451 DCE
* DceUnused
= NULL
;
452 KeEnterCriticalRegion();
454 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
457 // The reason for this you may ask?
458 // Well, it seems ReactOS calls GetDC with out first creating a desktop DC window!
459 // Need to test for null here. Not sure if this is a bug or a feature.
460 // First time use hax, need to use DceAllocDCE during window display init.
463 // The way I understand this, you can have more than one DC per window.
464 // Only one Owned if one was requested and saved and one Cached.
466 if ((Dce
->DCXFlags
& (DCX_CACHE
| DCX_DCEBUSY
)) == DCX_CACHE
)
469 if (Dce
->DCXFlags
& DCX_DCEEMPTY
)
473 else if (Dce
->hwndCurrent
== (Wnd
? Wnd
->head
.h
: NULL
) &&
474 ((Dce
->DCXFlags
& DCX_CACHECOMPAREMASK
) == DcxFlags
))
476 UpdateClipOrigin
= TRUE
;
480 pLE
= Dce
->List
.Flink
;
481 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
483 while (pLE
!= &LEDce
);
484 KeLeaveCriticalRegion();
486 Dce
= (DceEmpty
== NULL
) ? DceUnused
: DceEmpty
;
490 Dce
= DceAllocDCE(NULL
, DCE_CACHE_DC
);
492 if (!Dce
) return NULL
;
494 Dce
->hwndCurrent
= (Wnd
? Wnd
->head
.h
: NULL
);
496 else // If we are here, we are POWNED or having CLASS.
498 KeEnterCriticalRegion();
500 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
502 { // Check for Window handle than HDC match for CLASS.
503 if ((Dce
->hwndCurrent
== Wnd
->head
.h
) ||
506 pLE
= Dce
->List
.Flink
;
507 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
509 while (pLE
!= &LEDce
);
510 KeLeaveCriticalRegion();
512 if ( (Flags
& (DCX_INTERSECTRGN
|DCX_EXCLUDERGN
)) &&
513 (Dce
->DCXFlags
& (DCX_INTERSECTRGN
|DCX_EXCLUDERGN
)) )
515 DceDeleteClipRgn(Dce
);
518 // First time use hax, need to use DceAllocDCE during window display init.
524 if (!GDIOBJ_ValidateHandle(Dce
->hDC
, GDI_OBJECT_TYPE_DC
))
526 DPRINT1("FIXME: Got DCE with invalid hDC! 0x%x\n", Dce
->hDC
);
527 Dce
->hDC
= DceCreateDisplayDC();
528 /* FIXME: Handle error */
531 Dce
->DCXFlags
= Flags
| DCX_DCEBUSY
;
534 Bump it up! This prevents the random errors in wine dce tests and with
535 proper bits set in DCX_CACHECOMPAREMASK.
537 http://www.reactos.org/archives/public/ros-dev/2008-July/010498.html
538 http://www.reactos.org/archives/public/ros-dev/2008-July/010499.html
542 RemoveEntryList(&Dce
->List
);
543 InsertHeadList(&LEDce
, &Dce
->List
);
546 /* Introduced in rev 6691 and modified later. */
547 if ( (Flags
& DCX_INTERSECTUPDATE
) && !ClipRegion
)
549 Flags
|= DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
;
550 Dce
->DCXFlags
|= DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
;
551 ClipRegion
= Wnd
->hrgnUpdate
;
554 if (ClipRegion
== (HRGN
) 1)
556 if (!(Flags
& DCX_WINDOW
))
558 Dce
->hrgnClip
= IntSysCreateRectRgnIndirect(&Wnd
->rcClient
);
562 Dce
->hrgnClip
= IntSysCreateRectRgnIndirect(&Wnd
->rcWindow
);
564 Dce
->DCXFlags
&= ~DCX_KEEPCLIPRGN
;
566 else if (ClipRegion
!= NULL
)
568 if (Dce
->hrgnClip
!= NULL
)
570 DPRINT1("Should not be called!!\n");
571 GDIOBJ_FreeObjByHandle(Dce
->hrgnClip
, GDI_OBJECT_TYPE_REGION
|GDI_OBJECT_TYPE_SILENT
);
572 Dce
->hrgnClip
= NULL
;
574 Dce
->hrgnClip
= ClipRegion
;
577 DceSetDrawable(Wnd
, Dce
->hDC
, Flags
, UpdateClipOrigin
);
579 DceUpdateVisRgn(Dce
, Wnd
, Flags
);
581 if (Dce
->DCXFlags
& DCX_CACHE
)
583 DPRINT("ENTER!!!!!! DCX_CACHE!!!!!! hDC-> %x\n", Dce
->hDC
);
584 // Need to set ownership so Sync dcattr will work.
585 IntGdiSetDCOwnerEx( Dce
->hDC
, GDI_OBJ_HMGR_POWNED
, FALSE
);
586 Dce
->ptiOwner
= GetW32ThreadInfo(); // Set the temp owning
590 Wnd
->ExStyle
& WS_EX_LAYOUTRTL
&&
591 !(Flags
& DCX_KEEPLAYOUT
) )
593 NtGdiSetLayout(Dce
->hDC
, -1, LAYOUT_RTL
);
596 if (Dce
->DCXFlags
& DCX_PROCESSOWNED
)
598 ppi
= PsGetCurrentProcessWin32Process();
599 ppi
->W32PF_flags
|= W32PF_OWNDCCLEANUP
;
600 Dce
->ptiOwner
= NULL
;
607 /***********************************************************************
611 DceFreeDCE(PDCE pdce
, BOOLEAN Force
)
617 if (NULL
== pdce
) return NULL
;
619 pLE
= pdce
->List
.Flink
;
620 ret
= CONTAINING_RECORD(pLE
, DCE
, List
);
622 pdce
->DCXFlags
|= DCX_INDESTROY
;
624 if (Force
&& !GDIOBJ_OwnedByCurrentProcess(pdce
->hDC
))
626 DPRINT("Change ownership for DCE! -> %x\n" , pdce
);
627 // Note: Windows sets W32PF_OWNDCCLEANUP and moves on.
628 if (!IsObjectDead((HGDIOBJ
) pdce
->hDC
))
630 DC_SetOwnership( pdce
->hDC
, PsGetCurrentProcess());
634 DPRINT1("Attempted to change ownership of an DCEhDC 0x%x currently being destroyed!!!\n",pdce
->hDC
);
640 if (!GreGetObjectOwner(pdce
->hDC
, GDIObjType_DC_TYPE
))
641 DC_SetOwnership( pdce
->hDC
, PsGetCurrentProcess());
644 if (!Hit
) IntGdiDeleteDC(pdce
->hDC
, TRUE
);
646 if (pdce
->hrgnClip
&& !(pdce
->DCXFlags
& DCX_KEEPCLIPRGN
))
648 GDIOBJ_FreeObjByHandle(pdce
->hrgnClip
, GDI_OBJECT_TYPE_REGION
|GDI_OBJECT_TYPE_SILENT
);
649 pdce
->hrgnClip
= NULL
;
652 RemoveEntryList(&pdce
->List
);
654 if (IsListEmpty(&pdce
->List
))
656 DPRINT1("List is Empty! DCE! -> %x\n" , pdce
);
660 ExFreePoolWithTag(pdce
, TAG_PDCE
);
663 DPRINT("Freed DCE's! %d \n", DCECount
);
668 /***********************************************************************
671 * Remove owned DCE and reset unreleased cache DCEs.
674 DceFreeWindowDCE(PWND Window
)
681 DPRINT1("FreeWindowDCE No Entry! %d\n",DCECount
);
686 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
691 DPRINT1("FreeWindowDCE No DCE Pointer!\n");
694 if (IsListEmpty(&pDCE
->List
))
696 DPRINT1("FreeWindowDCE List is Empty!!!!\n");
699 if ( pDCE
->hwndCurrent
== Window
->head
.h
&&
700 !(pDCE
->DCXFlags
& DCX_DCEEMPTY
) )
702 if (!(pDCE
->DCXFlags
& DCX_CACHE
)) /* owned or Class DCE*/
704 if (Window
->pcls
->style
& CS_CLASSDC
) /* Test Class first */
706 if (pDCE
->DCXFlags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) /* Class DCE*/
707 DceDeleteClipRgn(pDCE
);
708 // Update and reset Vis Rgn and clear the dirty bit.
709 // Should release VisRgn than reset it to default.
710 DceUpdateVisRgn(pDCE
, Window
, pDCE
->DCXFlags
);
711 pDCE
->DCXFlags
= DCX_DCEEMPTY
|DCX_CACHE
;
712 pDCE
->hwndCurrent
= 0;
714 DPRINT("POWNED DCE going Cheap!! DCX_CACHE!! hDC-> %x \n", pDCE
->hDC
);
715 if (!IntGdiSetDCOwnerEx( pDCE
->hDC
, GDI_OBJ_HMGR_NONE
, FALSE
))
717 DPRINT1("Fail Owner Switch hDC-> %x \n", pDCE
->hDC
);
720 /* Do not change owner so thread can clean up! */
722 else if (Window
->pcls
->style
& CS_OWNDC
) /* owned DCE*/
724 pDCE
= DceFreeDCE(pDCE
, FALSE
);
730 DPRINT1("Not POWNED or CLASSDC hwndCurrent -> %x \n", pDCE
->hwndCurrent
);
736 if (pDCE
->DCXFlags
& DCX_DCEBUSY
) /* shared cache DCE */
738 /* FIXME: AFAICS we are doing the right thing here so
739 * this should be a DPRINT. But this is best left as an ERR
740 * because the 'application error' is likely to come from
741 * another part of Wine (i.e. it's our fault after all).
742 * We should change this to DPRINT when ReactOS is more stable
745 DPRINT1("[%p] GetDC() without ReleaseDC()!\n", Window
->head
.h
);
746 DceReleaseDC(pDCE
, FALSE
);
748 pDCE
->DCXFlags
|= DCX_DCEEMPTY
;
749 pDCE
->hwndCurrent
= 0;
752 pLE
= pDCE
->List
.Flink
;
753 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
755 while (pLE
!= &LEDce
);
759 DceFreeClassDCE(HDC hDC
)
764 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
769 if (pDCE
->hDC
== hDC
)
771 pDCE
= DceFreeDCE(pDCE
, TRUE
); // Might have gone cheap!
775 pLE
= pDCE
->List
.Flink
;
776 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
778 while (pLE
!= &LEDce
);
782 DceFreeThreadDCE(PTHREADINFO pti
)
787 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
792 if (pDCE
->ptiOwner
== pti
)
794 if (pDCE
->DCXFlags
& DCX_CACHE
)
796 pDCE
= DceFreeDCE(pDCE
, TRUE
);
801 pLE
= pDCE
->List
.Flink
;
802 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
804 while (pLE
!= &LEDce
);
813 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
818 pDCE
= DceFreeDCE(pDCE
, TRUE
);
821 while (pLE
!= &LEDce
);
825 DceResetActiveDCEs(PWND Window
)
839 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
840 if(!pDCE
) return; // Another null test!
844 if(pLE
== &LEDce
) break;
845 if (0 == (pDCE
->DCXFlags
& (DCX_DCEEMPTY
|DCX_INDESTROY
)))
847 if (Window
->head
.h
== pDCE
->hwndCurrent
)
849 CurrentWindow
= Window
;
853 CurrentWindow
= UserGetWindowObject(pDCE
->hwndCurrent
);
854 if (NULL
== CurrentWindow
)
856 pLE
= pDCE
->List
.Flink
;
857 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
862 if (!GDIOBJ_ValidateHandle(pDCE
->hDC
, GDI_OBJECT_TYPE_DC
) ||
863 (dc
= DC_LockDc(pDCE
->hDC
)) == NULL
)
865 pLE
= pDCE
->List
.Flink
;
866 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
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
;
885 if (NULL
!= dc
->rosdc
.hClipRgn
)
887 NtGdiOffsetRgn(dc
->rosdc
.hClipRgn
, DeltaX
, DeltaY
);
888 CLIPPING_UpdateGCRegion(dc
);
890 if (NULL
!= pDCE
->hrgnClip
)
892 NtGdiOffsetRgn(pDCE
->hrgnClip
, DeltaX
, DeltaY
);
897 DceUpdateVisRgn(pDCE
, CurrentWindow
, pDCE
->DCXFlags
);
899 if (Window
->head
.h
!= pDCE
->hwndCurrent
)
901 // IntEngWindowChanged(CurrentWindow, WOC_RGN_CLIENT);
902 // UserDerefObject(CurrentWindow);
905 pLE
= pDCE
->List
.Flink
;
906 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
908 while (pLE
!= &LEDce
);
912 IntWindowFromDC(HDC hDc
)
919 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
924 if (Dce
->DCXFlags
& DCX_INDESTROY
)
927 Ret
= Dce
->hwndCurrent
;
930 pLE
= Dce
->List
.Flink
;
931 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
933 while (pLE
!= &LEDce
);
938 UserReleaseDC(PWND Window
, HDC hDc
, BOOL EndPaint
)
945 DPRINT("%p %p\n", Window
, hDc
);
947 dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
956 pLE
= dce
->List
.Flink
;
957 dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
959 while (pLE
!= &LEDce
);
961 if ( Hit
&& (dce
->DCXFlags
& DCX_DCEBUSY
))
963 nRet
= DceReleaseDC(dce
, EndPaint
);
970 UserGetWindowDC(PWND Wnd
)
972 return UserGetDCEx(Wnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
976 UserGethWnd( HDC hdc
, PWNDOBJ
*pwndo
)
982 hWnd
= IntWindowFromDC(hdc
);
984 if (hWnd
&& !(Wnd
= UserGetWindowObject(hWnd
)))
986 pWndgdi
= (WNDGDI
*)IntGetProp(Wnd
, AtomWndObj
);
988 if ( pWndgdi
&& pWndgdi
->Hwnd
== hWnd
)
990 if (pwndo
) *pwndo
= (PWNDOBJ
)pWndgdi
;
997 NtUserGetDCEx(HWND hWnd OPTIONAL
, HANDLE ClipRegion
, ULONG Flags
)
1000 DECLARE_RETURN(HDC
);
1002 DPRINT("Enter NtUserGetDCEx\n");
1003 UserEnterExclusive();
1005 if (hWnd
&& !(Wnd
= UserGetWindowObject(hWnd
)))
1009 RETURN( UserGetDCEx(Wnd
, ClipRegion
, Flags
));
1012 DPRINT("Leave NtUserGetDCEx, ret=%i\n",_ret_
);
1020 * The NtUserGetWindowDC function retrieves the device context (DC) for the
1021 * entire window, including title bar, menus, and scroll bars. A window device
1022 * context permits painting anywhere in a window, because the origin of the
1023 * device context is the upper-left corner of the window instead of the client
1030 NtUserGetWindowDC(HWND hWnd
)
1032 return NtUserGetDCEx(hWnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
1036 NtUserGetDC(HWND hWnd
)
1038 DPRINT("NtUGetDC -> %x:%x\n", hWnd
, !hWnd
? DCX_CACHE
| DCX_WINDOW
: DCX_USESTYLE
);
1040 return NtUserGetDCEx(hWnd
, NULL
, NULL
== hWnd
? DCX_CACHE
| DCX_WINDOW
: DCX_USESTYLE
);
1044 * Select logical palette into device context.
1045 * \param hDC handle to the device context
1046 * \param hpal handle to the palette
1047 * \param ForceBackground If this value is FALSE the logical palette will be copied to the device palette only when the applicatioon
1048 * is in the foreground. If this value is TRUE then map the colors in the logical palette to the device
1049 * palette colors in the best way.
1050 * \return old palette
1052 * \todo implement ForceBackground == TRUE
1056 NtUserSelectPalette(HDC hDC
,
1058 BOOL ForceBackground
)
1061 UserEnterExclusive();
1062 // Implement window checks
1063 oldPal
= GdiSelectPalette( hDC
, hpal
, ForceBackground
);