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 // If NULL, first time through! Build the default window dc!
47 if (hDC
&& !defaultDCstate
) // Ultra HAX! Dedicated to GvG!
48 { // This is a cheesy way to do this.
49 PDC dc
= DC_LockDc ( hDC
);
50 defaultDCstate
= ExAllocatePoolWithTag(PagedPool
, sizeof(DC
), TAG_DC
);
51 RtlZeroMemory(defaultDCstate
, sizeof(DC
));
52 defaultDCstate
->pdcattr
= &defaultDCstate
->dcattr
;
53 DC_vCopyState(dc
, defaultDCstate
, TRUE
);
55 InitializeListHead(&LEDce
);
62 DceGetVisRgn(PWND Window
, ULONG Flags
, HWND hWndChild
, ULONG CFlags
)
66 VisRgn
= VIS_ComputeVisibleRegion( Window
,
67 0 == (Flags
& DCX_WINDOW
),
68 0 != (Flags
& DCX_CLIPCHILDREN
),
69 0 != (Flags
& DCX_CLIPSIBLINGS
));
72 VisRgn
= IntSysCreateRectRgn(0, 0, 0, 0);
78 DceAllocDCE(PWND Window OPTIONAL
, DCE_TYPE Type
)
82 pDce
= ExAllocatePoolWithTag(PagedPool
, sizeof(DCE
), TAG_PDCE
);
86 pDce
->hDC
= DceCreateDisplayDC();
89 ExFreePoolWithTag(pDce
, TAG_PDCE
);
93 DPRINT("Alloc DCE's! %d\n",DCECount
);
94 pDce
->hwndCurrent
= (Window
? Window
->head
.h
: NULL
);
95 pDce
->pwndOrg
= Window
;
96 pDce
->pwndClip
= Window
;
97 pDce
->hrgnClip
= NULL
;
98 pDce
->hrgnClipPublic
= NULL
;
99 pDce
->hrgnSavedVis
= NULL
;
100 pDce
->ppiOwner
= NULL
;
102 InsertTailList(&LEDce
, &pDce
->List
);
104 DCU_SetDcUndeletable(pDce
->hDC
);
106 if (Type
== DCE_WINDOW_DC
|| Type
== DCE_CLASS_DC
) //Window DCE have ownership.
108 pDce
->ptiOwner
= GetW32ThreadInfo();
112 DPRINT("FREE DCATTR!!!! NOT DCE_WINDOW_DC!!!!! hDC-> %x\n", pDce
->hDC
);
113 IntGdiSetDCOwnerEx( pDce
->hDC
, GDI_OBJ_HMGR_NONE
, FALSE
);
114 pDce
->ptiOwner
= NULL
;
117 if (Type
== DCE_CACHE_DC
)
119 pDce
->DCXFlags
= DCX_CACHE
| DCX_DCEEMPTY
;
123 pDce
->DCXFlags
= DCX_DCEBUSY
;
126 if (Type
== DCE_WINDOW_DC
)
128 if (Window
->style
& WS_CLIPCHILDREN
) pDce
->DCXFlags
|= DCX_CLIPCHILDREN
;
129 if (Window
->style
& WS_CLIPSIBLINGS
) pDce
->DCXFlags
|= DCX_CLIPSIBLINGS
;
137 DceSetDrawable( PWND Window OPTIONAL
,
142 DC
*dc
= DC_LockDc(hDC
);
153 if (Flags
& DCX_WINDOW
)
155 dc
->ptlDCOrig
.x
= Window
->rcWindow
.left
;
156 dc
->ptlDCOrig
.y
= Window
->rcWindow
.top
;
160 dc
->ptlDCOrig
.x
= Window
->rcClient
.left
;
161 dc
->ptlDCOrig
.y
= Window
->rcClient
.top
;
169 DceDeleteClipRgn(DCE
* Dce
)
171 Dce
->DCXFlags
&= ~(DCX_EXCLUDERGN
| DCX_INTERSECTRGN
);
173 if (Dce
->DCXFlags
& DCX_KEEPCLIPRGN
)
175 Dce
->DCXFlags
&= ~DCX_KEEPCLIPRGN
;
177 else if (Dce
->hrgnClip
!= NULL
)
179 GDIOBJ_FreeObjByHandle(Dce
->hrgnClip
, GDI_OBJECT_TYPE_REGION
|GDI_OBJECT_TYPE_SILENT
);
182 Dce
->hrgnClip
= NULL
;
184 /* make it dirty so that the vis rgn gets recomputed next time */
185 Dce
->DCXFlags
|= DCX_DCEDIRTY
;
189 DceReleaseDC(DCE
* dce
, BOOL EndPaint
)
191 if (DCX_DCEBUSY
!= (dce
->DCXFlags
& (DCX_INDESTROY
| DCX_DCEEMPTY
| DCX_DCEBUSY
)))
196 /* restore previous visible region */
197 if ((dce
->DCXFlags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) &&
198 ((dce
->DCXFlags
& DCX_CACHE
) || EndPaint
))
200 DceDeleteClipRgn(dce
);
203 if (dce
->DCXFlags
& DCX_CACHE
)
205 if (!(dce
->DCXFlags
& DCX_NORESETATTRS
))
207 /* make the DC clean so that SetDCState doesn't try to update the vis rgn */
208 IntGdiSetHookFlags(dce
->hDC
, DCHF_VALIDATEVISRGN
);
211 if (!IntGdiCleanDC(dce
->hDC
)) return 0;
213 if (dce
->DCXFlags
& DCX_DCEDIRTY
)
215 /* don't keep around invalidated entries
216 * because SetDCState() disables hVisRgn updates
217 * by removing dirty bit. */
218 dce
->hwndCurrent
= 0;
219 dce
->DCXFlags
&= DCX_CACHE
;
220 dce
->DCXFlags
|= DCX_DCEEMPTY
;
223 dce
->DCXFlags
&= ~DCX_DCEBUSY
;
224 DPRINT("Exit!!!!! DCX_CACHE!!!!!! hDC-> %x \n", dce
->hDC
);
225 if (!IntGdiSetDCOwnerEx( dce
->hDC
, GDI_OBJ_HMGR_NONE
, FALSE
))
227 dce
->ptiOwner
= NULL
; // Reset ownership.
228 dce
->ppiOwner
= NULL
;
230 #if 0 // Need to research and fix before this is a "growing" issue.
234 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
237 if (!(pDCE
->DCXFlags
& DCX_DCEBUSY
))
238 { /* Free the unused cache DCEs. */
239 pDCE
= DceFreeDCE(pDCE
, TRUE
);
244 while (pLE
!= &LEDce
);
248 return 1; // Released!
252 DceUpdateVisRgn(DCE
*Dce
, PWND Window
, ULONG Flags
)
254 HANDLE hRgnVisible
= NULL
;
258 if (Flags
& DCX_PARENTCLIP
)
262 Parent
= Window
->spwndParent
;
269 if (Parent
->style
& WS_CLIPSIBLINGS
)
271 DcxFlags
= DCX_CLIPSIBLINGS
|
272 (Flags
& ~(DCX_CLIPCHILDREN
| DCX_WINDOW
));
276 DcxFlags
= Flags
& ~(DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
| DCX_WINDOW
);
278 hRgnVisible
= DceGetVisRgn(Parent
, DcxFlags
, Window
->head
.h
, Flags
);
280 else if (Window
== NULL
)
282 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
283 if (NULL
!= DesktopWindow
)
285 hRgnVisible
= IntSysCreateRectRgnIndirect(&DesktopWindow
->rcWindow
);
294 hRgnVisible
= DceGetVisRgn(Window
, Flags
, 0, 0);
298 if (Flags
& DCX_INTERSECTRGN
)
300 if(Dce
->hrgnClip
!= NULL
)
302 NtGdiCombineRgn(hRgnVisible
, hRgnVisible
, Dce
->hrgnClip
, RGN_AND
);
306 if(hRgnVisible
!= NULL
)
308 REGION_FreeRgnByHandle(hRgnVisible
);
310 hRgnVisible
= IntSysCreateRectRgn(0, 0, 0, 0);
313 else if (Flags
& DCX_EXCLUDERGN
&& Dce
->hrgnClip
!= NULL
)
315 NtGdiCombineRgn(hRgnVisible
, hRgnVisible
, Dce
->hrgnClip
, RGN_DIFF
);
318 Dce
->DCXFlags
&= ~DCX_DCEDIRTY
;
319 GdiSelectVisRgn(Dce
->hDC
, hRgnVisible
);
323 IntEngWindowChanged(Window
, WOC_RGN_CLIENT
);
326 if (hRgnVisible
!= NULL
)
328 REGION_FreeRgnByHandle(hRgnVisible
);
333 UserGetDCEx(PWND Wnd OPTIONAL
, HANDLE ClipRegion
, ULONG Flags
)
338 BOOL UpdateClipOrigin
= FALSE
;
345 Flags
&= ~DCX_USESTYLE
;
349 if (Flags
& (DCX_WINDOW
| DCX_PARENTCLIP
)) Flags
|= DCX_CACHE
;
351 // When GetDC is called with hWnd nz, DCX_CACHE & _WINDOW are clear w _USESTYLE set.
352 if (Flags
& DCX_USESTYLE
)
354 Flags
&= ~(DCX_CLIPCHILDREN
| DCX_CLIPSIBLINGS
| DCX_PARENTCLIP
);
355 if (!(Flags
& DCX_WINDOW
)) // not window rectangle
357 if (Wnd
->pcls
->style
& CS_PARENTDC
)
359 Flags
|= DCX_PARENTCLIP
;
362 if (!(Flags
& DCX_CACHE
) && // Not on the cheap wine list.
363 !(Wnd
->pcls
->style
& CS_OWNDC
) )
365 if (!(Wnd
->pcls
->style
& CS_CLASSDC
))
366 // The window is not POWNED or has any CLASS, so we are looking for cheap wine.
370 if (Wnd
->pcls
->pdce
) hDC
= ((PDCE
)Wnd
->pcls
->pdce
)->hDC
;
371 DPRINT("We have CLASS!!\n");
374 /* else // For Testing!
376 DPRINT1("We have POWNER!!\n");
377 if (Window->Dce) DPRINT1("We have POWNER with DCE!!\n");
380 if (Wnd
->style
& WS_CLIPSIBLINGS
)
382 Flags
|= DCX_CLIPSIBLINGS
;
385 if (Wnd
->style
& WS_CLIPCHILDREN
&&
386 !(Wnd
->style
& WS_MINIMIZE
))
388 Flags
|= DCX_CLIPCHILDREN
;
390 /* If minized with icon in the set, we are forced to be cheap! */
391 if (Wnd
->style
& WS_MINIMIZE
&&
399 if (Wnd
->style
& WS_CLIPSIBLINGS
) Flags
|= DCX_CLIPSIBLINGS
;
404 if (Flags
& DCX_WINDOW
) Flags
&= ~DCX_CLIPCHILDREN
;
406 if (Flags
& DCX_NOCLIPCHILDREN
)
409 Flags
&= ~(DCX_PARENTCLIP
| DCX_CLIPCHILDREN
);
412 Parent
= (Wnd
? Wnd
->spwndParent
: NULL
);
414 if (NULL
== Wnd
|| !(Wnd
->style
& WS_CHILD
) || NULL
== Parent
)
416 Flags
&= ~DCX_PARENTCLIP
;
417 Flags
|= DCX_CLIPSIBLINGS
;
420 /* it seems parent clip is ignored when clipping siblings or children */
421 if (Flags
& (DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
)) Flags
&= ~DCX_PARENTCLIP
;
423 if (Flags
& DCX_PARENTCLIP
)
425 if ((Wnd
->style
& WS_VISIBLE
) &&
426 (Parent
->style
& WS_VISIBLE
))
428 Flags
&= ~DCX_CLIPCHILDREN
;
429 if (Parent
->style
& WS_CLIPSIBLINGS
)
431 Flags
|= DCX_CLIPSIBLINGS
;
436 // Window nz, check to see if we still own this or it is just cheap wine tonight.
437 if (!(Flags
& DCX_CACHE
))
439 if ( Wnd
->head
.pti
!= GetW32ThreadInfo())
440 Flags
|= DCX_CACHE
; // Ah~ Not Powned! Forced to be cheap~
443 DcxFlags
= Flags
& DCX_CACHECOMPAREMASK
;
445 if (Flags
& DCX_CACHE
)
446 { // Scan the cheap wine list for our match.
447 DCE
* DceEmpty
= NULL
;
448 DCE
* DceUnused
= NULL
;
449 KeEnterCriticalRegion();
451 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
454 // The reason for this you may ask?
455 // Well, it seems ReactOS calls GetDC with out first creating a desktop DC window!
456 // Need to test for null here. Not sure if this is a bug or a feature.
457 // First time use hax, need to use DceAllocDCE during window display init.
460 // The way I understand this, you can have more than one DC per window.
461 // Only one Owned if one was requested and saved and one Cached.
463 if ((Dce
->DCXFlags
& (DCX_CACHE
| DCX_DCEBUSY
)) == DCX_CACHE
)
466 if (Dce
->DCXFlags
& DCX_DCEEMPTY
)
470 else if (Dce
->hwndCurrent
== (Wnd
? Wnd
->head
.h
: NULL
) &&
471 ((Dce
->DCXFlags
& DCX_CACHECOMPAREMASK
) == DcxFlags
))
473 UpdateClipOrigin
= TRUE
;
477 pLE
= Dce
->List
.Flink
;
478 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
480 while (pLE
!= &LEDce
);
481 KeLeaveCriticalRegion();
483 Dce
= (DceEmpty
== NULL
) ? DceUnused
: DceEmpty
;
487 Dce
= DceAllocDCE(NULL
, DCE_CACHE_DC
);
489 if (!Dce
) return NULL
;
491 Dce
->hwndCurrent
= (Wnd
? Wnd
->head
.h
: NULL
);
493 else // If we are here, we are POWNED or having CLASS.
495 KeEnterCriticalRegion();
497 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
499 { // Check for Window handle than HDC match for CLASS.
500 if ((Dce
->hwndCurrent
== Wnd
->head
.h
) ||
503 pLE
= Dce
->List
.Flink
;
504 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
506 while (pLE
!= &LEDce
);
507 KeLeaveCriticalRegion();
509 if ( (Flags
& (DCX_INTERSECTRGN
|DCX_EXCLUDERGN
)) &&
510 (Dce
->DCXFlags
& (DCX_INTERSECTRGN
|DCX_EXCLUDERGN
)) )
512 DceDeleteClipRgn(Dce
);
515 // First time use hax, need to use DceAllocDCE during window display init.
521 if (!GDIOBJ_ValidateHandle(Dce
->hDC
, GDI_OBJECT_TYPE_DC
))
523 DPRINT1("FIXME: Got DCE with invalid hDC! 0x%x\n", Dce
->hDC
);
524 Dce
->hDC
= DceCreateDisplayDC();
525 /* FIXME: Handle error */
528 Dce
->DCXFlags
= Flags
| DCX_DCEBUSY
;
531 Bump it up! This prevents the random errors in wine dce tests and with
532 proper bits set in DCX_CACHECOMPAREMASK.
534 http://www.reactos.org/archives/public/ros-dev/2008-July/010498.html
535 http://www.reactos.org/archives/public/ros-dev/2008-July/010499.html
539 RemoveEntryList(&Dce
->List
);
540 InsertHeadList(&LEDce
, &Dce
->List
);
543 /* Introduced in rev 6691 and modified later. */
544 if ( (Flags
& DCX_INTERSECTUPDATE
) && !ClipRegion
)
546 Flags
|= DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
;
547 Dce
->DCXFlags
|= DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
;
548 ClipRegion
= Wnd
->hrgnUpdate
;
551 if (ClipRegion
== (HRGN
) 1)
553 if (!(Flags
& DCX_WINDOW
))
555 Dce
->hrgnClip
= IntSysCreateRectRgnIndirect(&Wnd
->rcClient
);
559 Dce
->hrgnClip
= IntSysCreateRectRgnIndirect(&Wnd
->rcWindow
);
561 Dce
->DCXFlags
&= ~DCX_KEEPCLIPRGN
;
563 else if (ClipRegion
!= NULL
)
565 if (Dce
->hrgnClip
!= NULL
)
567 DPRINT1("Should not be called!!\n");
568 GDIOBJ_FreeObjByHandle(Dce
->hrgnClip
, GDI_OBJECT_TYPE_REGION
|GDI_OBJECT_TYPE_SILENT
);
569 Dce
->hrgnClip
= NULL
;
571 Dce
->hrgnClip
= ClipRegion
;
574 DceSetDrawable(Wnd
, Dce
->hDC
, Flags
, UpdateClipOrigin
);
576 DceUpdateVisRgn(Dce
, Wnd
, Flags
);
578 if (Dce
->DCXFlags
& DCX_CACHE
)
580 DPRINT("ENTER!!!!!! DCX_CACHE!!!!!! hDC-> %x\n", Dce
->hDC
);
581 // Need to set ownership so Sync dcattr will work.
582 IntGdiSetDCOwnerEx( Dce
->hDC
, GDI_OBJ_HMGR_POWNED
, FALSE
);
583 Dce
->ptiOwner
= GetW32ThreadInfo(); // Set the temp owning
587 Wnd
->ExStyle
& WS_EX_LAYOUTRTL
&&
588 !(Flags
& DCX_KEEPLAYOUT
) )
590 NtGdiSetLayout(Dce
->hDC
, -1, LAYOUT_RTL
);
593 if (Dce
->DCXFlags
& DCX_PROCESSOWNED
)
595 ppi
= PsGetCurrentProcessWin32Process();
596 ppi
->W32PF_flags
|= W32PF_OWNDCCLEANUP
;
597 Dce
->ptiOwner
= NULL
;
604 /***********************************************************************
608 DceFreeDCE(PDCE pdce
, BOOLEAN Force
)
614 if (NULL
== pdce
) return NULL
;
616 pLE
= pdce
->List
.Flink
;
617 ret
= CONTAINING_RECORD(pLE
, DCE
, List
);
619 pdce
->DCXFlags
|= DCX_INDESTROY
;
621 if (Force
&& !GDIOBJ_OwnedByCurrentProcess(pdce
->hDC
))
623 DPRINT("Change ownership for DCE! -> %x\n" , pdce
);
624 // Note: Windows sets W32PF_OWNDCCLEANUP and moves on.
625 if (!IsObjectDead((HGDIOBJ
) pdce
->hDC
))
627 DC_SetOwnership( pdce
->hDC
, PsGetCurrentProcess());
631 DPRINT1("Attempted to change ownership of an DCEhDC 0x%x currently being destroyed!!!\n",pdce
->hDC
);
637 if (!GreGetObjectOwner(pdce
->hDC
, GDIObjType_DC_TYPE
))
638 DC_SetOwnership( pdce
->hDC
, PsGetCurrentProcess());
641 if (!Hit
) IntGdiDeleteDC(pdce
->hDC
, TRUE
);
643 if (pdce
->hrgnClip
&& !(pdce
->DCXFlags
& DCX_KEEPCLIPRGN
))
645 GDIOBJ_FreeObjByHandle(pdce
->hrgnClip
, GDI_OBJECT_TYPE_REGION
|GDI_OBJECT_TYPE_SILENT
);
646 pdce
->hrgnClip
= NULL
;
649 RemoveEntryList(&pdce
->List
);
651 if (IsListEmpty(&pdce
->List
))
653 DPRINT1("List is Empty! DCE! -> %x\n" , pdce
);
657 ExFreePoolWithTag(pdce
, TAG_PDCE
);
660 DPRINT("Freed DCE's! %d \n", DCECount
);
665 /***********************************************************************
668 * Remove owned DCE and reset unreleased cache DCEs.
671 DceFreeWindowDCE(PWND Window
)
678 DPRINT1("FreeWindowDCE No Entry! %d\n",DCECount
);
683 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
688 DPRINT1("FreeWindowDCE No DCE Pointer!\n");
691 if (IsListEmpty(&pDCE
->List
))
693 DPRINT1("FreeWindowDCE List is Empty!!!!\n");
696 if ( pDCE
->hwndCurrent
== Window
->head
.h
&&
697 !(pDCE
->DCXFlags
& DCX_DCEEMPTY
) )
699 if (!(pDCE
->DCXFlags
& DCX_CACHE
)) /* owned or Class DCE*/
701 if (Window
->pcls
->style
& CS_CLASSDC
) /* Test Class first */
703 if (pDCE
->DCXFlags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) /* Class DCE*/
704 DceDeleteClipRgn(pDCE
);
705 // Update and reset Vis Rgn and clear the dirty bit.
706 // Should release VisRgn than reset it to default.
707 DceUpdateVisRgn(pDCE
, Window
, pDCE
->DCXFlags
);
708 pDCE
->DCXFlags
= DCX_DCEEMPTY
|DCX_CACHE
;
709 pDCE
->hwndCurrent
= 0;
711 DPRINT("POWNED DCE going Cheap!! DCX_CACHE!! hDC-> %x \n", pDCE
->hDC
);
712 if (!IntGdiSetDCOwnerEx( pDCE
->hDC
, GDI_OBJ_HMGR_NONE
, FALSE
))
714 DPRINT1("Fail Owner Switch hDC-> %x \n", pDCE
->hDC
);
717 /* Do not change owner so thread can clean up! */
719 else if (Window
->pcls
->style
& CS_OWNDC
) /* owned DCE*/
721 pDCE
= DceFreeDCE(pDCE
, FALSE
);
727 DPRINT1("Not POWNED or CLASSDC hwndCurrent -> %x \n", pDCE
->hwndCurrent
);
733 if (pDCE
->DCXFlags
& DCX_DCEBUSY
) /* shared cache DCE */
735 /* FIXME: AFAICS we are doing the right thing here so
736 * this should be a DPRINT. But this is best left as an ERR
737 * because the 'application error' is likely to come from
738 * another part of Wine (i.e. it's our fault after all).
739 * We should change this to DPRINT when ReactOS is more stable
742 DPRINT1("[%p] GetDC() without ReleaseDC()!\n", Window
->head
.h
);
743 DceReleaseDC(pDCE
, FALSE
);
745 pDCE
->DCXFlags
|= DCX_DCEEMPTY
;
746 pDCE
->hwndCurrent
= 0;
749 pLE
= pDCE
->List
.Flink
;
750 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
752 while (pLE
!= &LEDce
);
756 DceFreeClassDCE(HDC hDC
)
761 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
766 if (pDCE
->hDC
== hDC
)
768 pDCE
= DceFreeDCE(pDCE
, TRUE
); // Might have gone cheap!
772 pLE
= pDCE
->List
.Flink
;
773 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
775 while (pLE
!= &LEDce
);
779 DceFreeThreadDCE(PTHREADINFO pti
)
784 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
789 if (pDCE
->ptiOwner
== pti
)
791 if (pDCE
->DCXFlags
& DCX_CACHE
)
793 pDCE
= DceFreeDCE(pDCE
, TRUE
);
798 pLE
= pDCE
->List
.Flink
;
799 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
801 while (pLE
!= &LEDce
);
810 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
815 pDCE
= DceFreeDCE(pDCE
, TRUE
);
818 while (pLE
!= &LEDce
);
822 DceResetActiveDCEs(PWND Window
)
836 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
837 if(!pDCE
) return; // Another null test!
841 if(pLE
== &LEDce
) break;
842 if (0 == (pDCE
->DCXFlags
& (DCX_DCEEMPTY
|DCX_INDESTROY
)))
844 if (Window
->head
.h
== pDCE
->hwndCurrent
)
846 CurrentWindow
= Window
;
850 CurrentWindow
= UserGetWindowObject(pDCE
->hwndCurrent
);
851 if (NULL
== CurrentWindow
)
853 pLE
= pDCE
->List
.Flink
;
854 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
859 if (!GDIOBJ_ValidateHandle(pDCE
->hDC
, GDI_OBJECT_TYPE_DC
) ||
860 (dc
= DC_LockDc(pDCE
->hDC
)) == NULL
)
862 pLE
= pDCE
->List
.Flink
;
863 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
866 if (Window
== CurrentWindow
|| IntIsChildWindow(Window
, CurrentWindow
))
868 if (pDCE
->DCXFlags
& DCX_WINDOW
)
870 DeltaX
= CurrentWindow
->rcWindow
.left
- dc
->ptlDCOrig
.x
;
871 DeltaY
= CurrentWindow
->rcWindow
.top
- dc
->ptlDCOrig
.y
;
872 dc
->ptlDCOrig
.x
= CurrentWindow
->rcWindow
.left
;
873 dc
->ptlDCOrig
.y
= CurrentWindow
->rcWindow
.top
;
877 DeltaX
= CurrentWindow
->rcClient
.left
- dc
->ptlDCOrig
.x
;
878 DeltaY
= CurrentWindow
->rcClient
.top
- dc
->ptlDCOrig
.y
;
879 dc
->ptlDCOrig
.x
= CurrentWindow
->rcClient
.left
;
880 dc
->ptlDCOrig
.y
= CurrentWindow
->rcClient
.top
;
882 if (NULL
!= dc
->rosdc
.hClipRgn
)
884 NtGdiOffsetRgn(dc
->rosdc
.hClipRgn
, DeltaX
, DeltaY
);
885 CLIPPING_UpdateGCRegion(dc
);
887 if (NULL
!= pDCE
->hrgnClip
)
889 NtGdiOffsetRgn(pDCE
->hrgnClip
, DeltaX
, DeltaY
);
894 DceUpdateVisRgn(pDCE
, CurrentWindow
, pDCE
->DCXFlags
);
896 if (Window
->head
.h
!= pDCE
->hwndCurrent
)
898 // IntEngWindowChanged(CurrentWindow, WOC_RGN_CLIENT);
899 // UserDerefObject(CurrentWindow);
902 pLE
= pDCE
->List
.Flink
;
903 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
905 while (pLE
!= &LEDce
);
909 IntWindowFromDC(HDC hDc
)
916 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
921 if (Dce
->DCXFlags
& DCX_INDESTROY
)
924 Ret
= Dce
->hwndCurrent
;
927 pLE
= Dce
->List
.Flink
;
928 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
930 while (pLE
!= &LEDce
);
935 UserReleaseDC(PWND Window
, HDC hDc
, BOOL EndPaint
)
942 DPRINT("%p %p\n", Window
, hDc
);
944 dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
953 pLE
= dce
->List
.Flink
;
954 dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
956 while (pLE
!= &LEDce
);
958 if ( Hit
&& (dce
->DCXFlags
& DCX_DCEBUSY
))
960 nRet
= DceReleaseDC(dce
, EndPaint
);
967 UserGetWindowDC(PWND Wnd
)
969 return UserGetDCEx(Wnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
973 UserGethWnd( HDC hdc
, PWNDOBJ
*pwndo
)
979 hWnd
= IntWindowFromDC(hdc
);
981 if (hWnd
&& !(Wnd
= UserGetWindowObject(hWnd
)))
983 pWndgdi
= (WNDGDI
*)IntGetProp(Wnd
, AtomWndObj
);
985 if ( pWndgdi
&& pWndgdi
->Hwnd
== hWnd
)
987 if (pwndo
) *pwndo
= (PWNDOBJ
)pWndgdi
;
994 NtUserGetDCEx(HWND hWnd OPTIONAL
, HANDLE ClipRegion
, ULONG Flags
)
999 DPRINT("Enter NtUserGetDCEx\n");
1000 UserEnterExclusive();
1002 if (hWnd
&& !(Wnd
= UserGetWindowObject(hWnd
)))
1006 RETURN( UserGetDCEx(Wnd
, ClipRegion
, Flags
));
1009 DPRINT("Leave NtUserGetDCEx, ret=%i\n",_ret_
);
1017 * The NtUserGetWindowDC function retrieves the device context (DC) for the
1018 * entire window, including title bar, menus, and scroll bars. A window device
1019 * context permits painting anywhere in a window, because the origin of the
1020 * device context is the upper-left corner of the window instead of the client
1027 NtUserGetWindowDC(HWND hWnd
)
1029 return NtUserGetDCEx(hWnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
1033 NtUserGetDC(HWND hWnd
)
1035 DPRINT("NtUGetDC -> %x:%x\n", hWnd
, !hWnd
? DCX_CACHE
| DCX_WINDOW
: DCX_USESTYLE
);
1037 return NtUserGetDCEx(hWnd
, NULL
, NULL
== hWnd
? DCX_CACHE
| DCX_WINDOW
: DCX_USESTYLE
);
1041 * Select logical palette into device context.
1042 * \param hDC handle to the device context
1043 * \param hpal handle to the palette
1044 * \param ForceBackground If this value is FALSE the logical palette will be copied to the device palette only when the applicatioon
1045 * is in the foreground. If this value is TRUE then map the colors in the logical palette to the device
1046 * palette colors in the best way.
1047 * \return old palette
1049 * \todo implement ForceBackground == TRUE
1053 NtUserSelectPalette(HDC hDC
,
1055 BOOL ForceBackground
)
1058 UserEnterExclusive();
1059 // Implement window checks
1060 oldPal
= GdiSelectPalette( hDC
, hpal
, ForceBackground
);