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 ******************************************************************/
14 DBG_DEFAULT_CHANNEL(UserDce
);
16 /* GLOBALS *******************************************************************/
18 /* NOTE - I think we should store this per window station (including gdi objects) */
19 /* Answer: No, use the DCE pMonitor to compare with! */
21 static LIST_ENTRY LEDce
;
22 static INT DCECount
= 0; // Count of DCE in system.
24 #define DCX_CACHECOMPAREMASK (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN | \
25 DCX_NORESETATTRS | DCX_LOCKWINDOWUPDATE | \
26 DCX_LAYEREDWIN | DCX_CACHE | DCX_WINDOW | \
29 /* FUNCTIONS *****************************************************************/
32 // This should be moved to dc.c or dcutil.c.
35 DceCreateDisplayDC(VOID
)
38 UNICODE_STRING DriverName
;
39 RtlInitUnicodeString(&DriverName
, L
"DISPLAY");
40 hDC
= IntGdiCreateDC(&DriverName
, NULL
, NULL
, NULL
, FALSE
);
42 co_IntGraphicsCheck(TRUE
);
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
);
51 defaultDCstate
= ExAllocatePoolWithTag(PagedPool
, sizeof(DC
), TAG_DC
);
52 RtlZeroMemory(defaultDCstate
, sizeof(DC
));
53 defaultDCstate
->pdcattr
= &defaultDCstate
->dcattr
;
54 DC_vCopyState(dc
, defaultDCstate
, TRUE
);
56 InitializeListHead(&LEDce
);
63 DceGetVisRgn(PWND Window
, ULONG Flags
, HWND hWndChild
, ULONG CFlags
)
67 VisRgn
= VIS_ComputeVisibleRegion( Window
,
68 0 == (Flags
& DCX_WINDOW
),
69 0 != (Flags
& DCX_CLIPCHILDREN
),
70 0 != (Flags
& DCX_CLIPSIBLINGS
));
73 VisRgn
= IntSysCreateRectRgn(0, 0, 0, 0);
79 DceAllocDCE(PWND Window OPTIONAL
, DCE_TYPE Type
)
83 pDce
= ExAllocatePoolWithTag(PagedPool
, sizeof(DCE
), USERTAG_DCE
);
87 pDce
->hDC
= DceCreateDisplayDC();
90 ExFreePoolWithTag(pDce
, USERTAG_DCE
);
94 TRACE("Alloc DCE's! %d\n",DCECount
);
95 pDce
->hwndCurrent
= (Window
? Window
->head
.h
: NULL
);
96 pDce
->pwndOrg
= Window
;
97 pDce
->pwndClip
= Window
;
98 pDce
->hrgnClip
= NULL
;
99 pDce
->hrgnClipPublic
= NULL
;
100 pDce
->hrgnSavedVis
= NULL
;
101 pDce
->ppiOwner
= NULL
;
103 InsertTailList(&LEDce
, &pDce
->List
);
105 DCU_SetDcUndeletable(pDce
->hDC
);
107 if (Type
== DCE_WINDOW_DC
|| Type
== DCE_CLASS_DC
) //Window DCE have ownership.
109 pDce
->ptiOwner
= GetW32ThreadInfo();
113 TRACE("FREE DCATTR!!!! NOT DCE_WINDOW_DC!!!!! hDC-> %x\n", pDce
->hDC
);
114 GreSetDCOwner(pDce
->hDC
, GDI_OBJ_HMGR_NONE
);
115 pDce
->ptiOwner
= NULL
;
118 if (Type
== DCE_CACHE_DC
)
120 pDce
->DCXFlags
= DCX_CACHE
| DCX_DCEEMPTY
;
124 pDce
->DCXFlags
= DCX_DCEBUSY
;
127 if (Type
== DCE_WINDOW_DC
)
129 if (Window
->style
& WS_CLIPCHILDREN
) pDce
->DCXFlags
|= DCX_CLIPCHILDREN
;
130 if (Window
->style
& WS_CLIPSIBLINGS
) pDce
->DCXFlags
|= DCX_CLIPSIBLINGS
;
138 DceSetDrawable( PWND Window OPTIONAL
,
143 DC
*dc
= DC_LockDc(hDC
);
154 if (Flags
& DCX_WINDOW
)
156 dc
->ptlDCOrig
.x
= Window
->rcWindow
.left
;
157 dc
->ptlDCOrig
.y
= Window
->rcWindow
.top
;
161 dc
->ptlDCOrig
.x
= Window
->rcClient
.left
;
162 dc
->ptlDCOrig
.y
= Window
->rcClient
.top
;
170 DceDeleteClipRgn(DCE
* Dce
)
172 Dce
->DCXFlags
&= ~(DCX_EXCLUDERGN
| DCX_INTERSECTRGN
);
174 if (Dce
->DCXFlags
& DCX_KEEPCLIPRGN
)
176 Dce
->DCXFlags
&= ~DCX_KEEPCLIPRGN
;
178 else if (Dce
->hrgnClip
!= NULL
)
180 GreDeleteObject(Dce
->hrgnClip
);
183 Dce
->hrgnClip
= NULL
;
185 /* make it dirty so that the vis rgn gets recomputed next time */
186 Dce
->DCXFlags
|= DCX_DCEDIRTY
;
190 DceReleaseDC(DCE
* dce
, BOOL EndPaint
)
192 if (DCX_DCEBUSY
!= (dce
->DCXFlags
& (DCX_INDESTROY
| DCX_DCEEMPTY
| DCX_DCEBUSY
)))
197 /* restore previous visible region */
198 if ((dce
->DCXFlags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) &&
199 ((dce
->DCXFlags
& DCX_CACHE
) || EndPaint
))
201 DceDeleteClipRgn(dce
);
204 if (dce
->DCXFlags
& DCX_CACHE
)
206 if (!(dce
->DCXFlags
& DCX_NORESETATTRS
))
208 /* make the DC clean so that SetDCState doesn't try to update the vis rgn */
209 IntGdiSetHookFlags(dce
->hDC
, DCHF_VALIDATEVISRGN
);
212 if (!IntGdiCleanDC(dce
->hDC
)) return 0;
214 if (dce
->DCXFlags
& DCX_DCEDIRTY
)
216 /* don't keep around invalidated entries
217 * because SetDCState() disables hVisRgn updates
218 * by removing dirty bit. */
219 dce
->hwndCurrent
= 0;
220 dce
->DCXFlags
&= DCX_CACHE
;
221 dce
->DCXFlags
|= DCX_DCEEMPTY
;
224 dce
->DCXFlags
&= ~DCX_DCEBUSY
;
225 TRACE("Exit!!!!! DCX_CACHE!!!!!! hDC-> %x \n", dce
->hDC
);
226 if (!GreSetDCOwner(dce
->hDC
, GDI_OBJ_HMGR_NONE
))
228 dce
->ptiOwner
= NULL
; // Reset ownership.
229 dce
->ppiOwner
= NULL
;
231 #if 0 // Need to research and fix before this is a "growing" issue.
235 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
238 if (!(pDCE
->DCXFlags
& DCX_DCEBUSY
))
239 { /* Free the unused cache DCEs. */
240 pDCE
= DceFreeDCE(pDCE
, TRUE
);
245 while (pLE
!= &LEDce
);
249 return 1; // Released!
253 DceUpdateVisRgn(DCE
*Dce
, PWND Window
, ULONG Flags
)
255 HANDLE hRgnVisible
= NULL
;
259 if (Flags
& DCX_PARENTCLIP
)
263 Parent
= Window
->spwndParent
;
270 if (Parent
->style
& WS_CLIPSIBLINGS
)
272 DcxFlags
= DCX_CLIPSIBLINGS
|
273 (Flags
& ~(DCX_CLIPCHILDREN
| DCX_WINDOW
));
277 DcxFlags
= Flags
& ~(DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
| DCX_WINDOW
);
279 hRgnVisible
= DceGetVisRgn(Parent
, DcxFlags
, Window
->head
.h
, Flags
);
281 else if (Window
== NULL
)
283 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
284 if (NULL
!= DesktopWindow
)
286 hRgnVisible
= IntSysCreateRectRgnIndirect(&DesktopWindow
->rcWindow
);
295 hRgnVisible
= DceGetVisRgn(Window
, Flags
, 0, 0);
299 if (Flags
& DCX_INTERSECTRGN
)
301 if(Dce
->hrgnClip
!= NULL
)
303 NtGdiCombineRgn(hRgnVisible
, hRgnVisible
, Dce
->hrgnClip
, RGN_AND
);
307 if(hRgnVisible
!= NULL
)
309 GreDeleteObject(hRgnVisible
);
311 hRgnVisible
= IntSysCreateRectRgn(0, 0, 0, 0);
314 else if (Flags
& DCX_EXCLUDERGN
&& Dce
->hrgnClip
!= NULL
)
316 NtGdiCombineRgn(hRgnVisible
, hRgnVisible
, Dce
->hrgnClip
, RGN_DIFF
);
319 Dce
->DCXFlags
&= ~DCX_DCEDIRTY
;
320 GdiSelectVisRgn(Dce
->hDC
, hRgnVisible
);
324 IntEngWindowChanged(Window
, WOC_RGN_CLIENT
);
327 if (hRgnVisible
!= NULL
)
329 GreDeleteObject(hRgnVisible
);
334 UserGetDCEx(PWND Wnd OPTIONAL
, HANDLE ClipRegion
, ULONG Flags
)
339 BOOL UpdateClipOrigin
= FALSE
;
346 Flags
&= ~DCX_USESTYLE
;
350 if (Flags
& (DCX_WINDOW
| DCX_PARENTCLIP
)) Flags
|= DCX_CACHE
;
352 // When GetDC is called with hWnd nz, DCX_CACHE & _WINDOW are clear w _USESTYLE set.
353 if (Flags
& DCX_USESTYLE
)
355 Flags
&= ~(DCX_CLIPCHILDREN
| DCX_CLIPSIBLINGS
| DCX_PARENTCLIP
);
356 if (!(Flags
& DCX_WINDOW
)) // not window rectangle
358 if (Wnd
->pcls
->style
& CS_PARENTDC
)
360 Flags
|= DCX_PARENTCLIP
;
363 if (!(Flags
& DCX_CACHE
) && // Not on the cheap wine list.
364 !(Wnd
->pcls
->style
& CS_OWNDC
) )
366 if (!(Wnd
->pcls
->style
& CS_CLASSDC
))
367 // The window is not POWNED or has any CLASS, so we are looking for cheap wine.
371 if (Wnd
->pcls
->pdce
) hDC
= ((PDCE
)Wnd
->pcls
->pdce
)->hDC
;
372 TRACE("We have CLASS!!\n");
375 /* else // For Testing!
377 DPRINT1("We have POWNER!!\n");
378 if (Window->Dce) DPRINT1("We have POWNER with DCE!!\n");
381 if (Wnd
->style
& WS_CLIPSIBLINGS
)
383 Flags
|= DCX_CLIPSIBLINGS
;
386 if (Wnd
->style
& WS_CLIPCHILDREN
&&
387 !(Wnd
->style
& WS_MINIMIZE
))
389 Flags
|= DCX_CLIPCHILDREN
;
391 /* If minized with icon in the set, we are forced to be cheap! */
392 if (Wnd
->style
& WS_MINIMIZE
&&
400 if (Wnd
->style
& WS_CLIPSIBLINGS
) Flags
|= DCX_CLIPSIBLINGS
;
405 if (Flags
& DCX_WINDOW
) Flags
&= ~DCX_CLIPCHILDREN
;
407 if (Flags
& DCX_NOCLIPCHILDREN
)
410 Flags
&= ~(DCX_PARENTCLIP
| DCX_CLIPCHILDREN
);
413 Parent
= (Wnd
? Wnd
->spwndParent
: NULL
);
415 if (NULL
== Wnd
|| !(Wnd
->style
& WS_CHILD
) || NULL
== Parent
)
417 Flags
&= ~DCX_PARENTCLIP
;
418 Flags
|= DCX_CLIPSIBLINGS
;
421 /* it seems parent clip is ignored when clipping siblings or children */
422 if (Flags
& (DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
)) Flags
&= ~DCX_PARENTCLIP
;
424 if (Flags
& DCX_PARENTCLIP
)
426 if ((Wnd
->style
& WS_VISIBLE
) &&
427 (Parent
->style
& WS_VISIBLE
))
429 Flags
&= ~DCX_CLIPCHILDREN
;
430 if (Parent
->style
& WS_CLIPSIBLINGS
)
432 Flags
|= DCX_CLIPSIBLINGS
;
437 // Window nz, check to see if we still own this or it is just cheap wine tonight.
438 if (!(Flags
& DCX_CACHE
))
440 if ( Wnd
->head
.pti
!= GetW32ThreadInfo())
441 Flags
|= DCX_CACHE
; // Ah~ Not Powned! Forced to be cheap~
444 DcxFlags
= Flags
& DCX_CACHECOMPAREMASK
;
446 if (Flags
& DCX_CACHE
)
447 { // Scan the cheap wine list for our match.
448 DCE
* DceEmpty
= NULL
;
449 DCE
* DceUnused
= NULL
;
450 KeEnterCriticalRegion();
452 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
455 // The reason for this you may ask?
456 // Well, it seems ReactOS calls GetDC with out first creating a desktop DC window!
457 // Need to test for null here. Not sure if this is a bug or a feature.
458 // First time use hax, need to use DceAllocDCE during window display init.
461 // The way I understand this, you can have more than one DC per window.
462 // Only one Owned if one was requested and saved and one Cached.
464 if ((Dce
->DCXFlags
& (DCX_CACHE
| DCX_DCEBUSY
)) == DCX_CACHE
)
467 if (Dce
->DCXFlags
& DCX_DCEEMPTY
)
471 else if (Dce
->hwndCurrent
== (Wnd
? Wnd
->head
.h
: NULL
) &&
472 ((Dce
->DCXFlags
& DCX_CACHECOMPAREMASK
) == DcxFlags
))
474 UpdateClipOrigin
= TRUE
;
478 pLE
= Dce
->List
.Flink
;
479 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
481 while (pLE
!= &LEDce
);
482 KeLeaveCriticalRegion();
484 Dce
= (DceEmpty
== NULL
) ? DceUnused
: DceEmpty
;
488 Dce
= DceAllocDCE(NULL
, DCE_CACHE_DC
);
490 if (!Dce
) return NULL
;
492 Dce
->hwndCurrent
= (Wnd
? Wnd
->head
.h
: NULL
);
494 else // If we are here, we are POWNED or having CLASS.
496 KeEnterCriticalRegion();
498 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
500 { // Check for Window handle than HDC match for CLASS.
501 if ((Dce
->hwndCurrent
== Wnd
->head
.h
) ||
504 pLE
= Dce
->List
.Flink
;
505 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
507 while (pLE
!= &LEDce
);
508 KeLeaveCriticalRegion();
510 if ( (Flags
& (DCX_INTERSECTRGN
|DCX_EXCLUDERGN
)) &&
511 (Dce
->DCXFlags
& (DCX_INTERSECTRGN
|DCX_EXCLUDERGN
)) )
513 DceDeleteClipRgn(Dce
);
516 // First time use hax, need to use DceAllocDCE during window display init.
522 if (!GreIsHandleValid(Dce
->hDC
))
524 ERR("FIXME: Got DCE with invalid hDC! 0x%x\n", Dce
->hDC
);
525 Dce
->hDC
= DceCreateDisplayDC();
526 /* FIXME: Handle error */
529 Dce
->DCXFlags
= Flags
| DCX_DCEBUSY
;
532 Bump it up! This prevents the random errors in wine dce tests and with
533 proper bits set in DCX_CACHECOMPAREMASK.
535 http://www.reactos.org/archives/public/ros-dev/2008-July/010498.html
536 http://www.reactos.org/archives/public/ros-dev/2008-July/010499.html
540 RemoveEntryList(&Dce
->List
);
541 InsertHeadList(&LEDce
, &Dce
->List
);
544 /* Introduced in rev 6691 and modified later. */
545 if ( (Flags
& DCX_INTERSECTUPDATE
) && !ClipRegion
)
547 Flags
|= DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
;
548 Dce
->DCXFlags
|= DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
;
549 ClipRegion
= Wnd
->hrgnUpdate
;
552 if (ClipRegion
== HRGN_WINDOW
)
554 if (!(Flags
& DCX_WINDOW
))
556 Dce
->hrgnClip
= IntSysCreateRectRgnIndirect(&Wnd
->rcClient
);
560 Dce
->hrgnClip
= IntSysCreateRectRgnIndirect(&Wnd
->rcWindow
);
562 Dce
->DCXFlags
&= ~DCX_KEEPCLIPRGN
;
564 else if (ClipRegion
!= NULL
)
566 if (Dce
->hrgnClip
!= NULL
)
568 ERR("Should not be called!!\n");
569 GreDeleteObject(Dce
->hrgnClip
);
570 Dce
->hrgnClip
= NULL
;
572 Dce
->hrgnClip
= ClipRegion
;
575 DceSetDrawable(Wnd
, Dce
->hDC
, Flags
, UpdateClipOrigin
);
577 DceUpdateVisRgn(Dce
, Wnd
, Flags
);
579 if (Dce
->DCXFlags
& DCX_CACHE
)
581 TRACE("ENTER!!!!!! DCX_CACHE!!!!!! hDC-> %x\n", Dce
->hDC
);
582 // Need to set ownership so Sync dcattr will work.
583 GreSetDCOwner(Dce
->hDC
, GDI_OBJ_HMGR_POWNED
);
584 Dce
->ptiOwner
= GetW32ThreadInfo(); // Set the temp owning
588 Wnd
->ExStyle
& WS_EX_LAYOUTRTL
&&
589 !(Flags
& DCX_KEEPLAYOUT
) )
591 NtGdiSetLayout(Dce
->hDC
, -1, LAYOUT_RTL
);
594 if (Dce
->DCXFlags
& DCX_PROCESSOWNED
)
596 ppi
= PsGetCurrentProcessWin32Process();
597 ppi
->W32PF_flags
|= W32PF_OWNDCCLEANUP
;
598 Dce
->ptiOwner
= NULL
;
605 /***********************************************************************
609 DceFreeDCE(PDCE pdce
, BOOLEAN Force
)
615 if (NULL
== pdce
) return NULL
;
617 pLE
= pdce
->List
.Flink
;
618 ret
= CONTAINING_RECORD(pLE
, DCE
, List
);
620 pdce
->DCXFlags
|= DCX_INDESTROY
;
623 GreGetObjectOwner(pdce
->hDC
) != GDI_OBJ_HMGR_POWNED
)
625 TRACE("Change ownership for DCE! -> %x\n" , pdce
);
626 // Note: Windows sets W32PF_OWNDCCLEANUP and moves on.
627 if (GreIsHandleValid(pdce
->hDC
))
629 GreSetDCOwner(pdce
->hDC
, GDI_OBJ_HMGR_POWNED
);
633 ERR("Attempted to change ownership of an DCEhDC 0x%x currently being destroyed!!!\n",pdce
->hDC
);
639 if (GreGetObjectOwner(pdce
->hDC
) == GDI_OBJ_HMGR_PUBLIC
)
640 GreSetDCOwner(pdce
->hDC
, GDI_OBJ_HMGR_POWNED
);
643 if (!Hit
) IntGdiDeleteDC(pdce
->hDC
, TRUE
);
645 if (pdce
->hrgnClip
&& !(pdce
->DCXFlags
& DCX_KEEPCLIPRGN
))
647 GreDeleteObject(pdce
->hrgnClip
);
648 pdce
->hrgnClip
= NULL
;
651 RemoveEntryList(&pdce
->List
);
653 if (IsListEmpty(&pdce
->List
))
655 ERR("List is Empty! DCE! -> %x\n" , pdce
);
659 ExFreePoolWithTag(pdce
, USERTAG_DCE
);
662 TRACE("Freed DCE's! %d \n", DCECount
);
667 /***********************************************************************
670 * Remove owned DCE and reset unreleased cache DCEs.
673 DceFreeWindowDCE(PWND Window
)
680 ERR("FreeWindowDCE No Entry! %d\n",DCECount
);
685 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
690 ERR("FreeWindowDCE No DCE Pointer!\n");
693 if (IsListEmpty(&pDCE
->List
))
695 ERR("FreeWindowDCE List is Empty!!!!\n");
698 if ( pDCE
->hwndCurrent
== Window
->head
.h
&&
699 !(pDCE
->DCXFlags
& DCX_DCEEMPTY
) )
701 if (!(pDCE
->DCXFlags
& DCX_CACHE
)) /* owned or Class DCE*/
703 if (Window
->pcls
->style
& CS_CLASSDC
) /* Test Class first */
705 if (pDCE
->DCXFlags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) /* Class DCE*/
706 DceDeleteClipRgn(pDCE
);
707 // Update and reset Vis Rgn and clear the dirty bit.
708 // Should release VisRgn than reset it to default.
709 DceUpdateVisRgn(pDCE
, Window
, pDCE
->DCXFlags
);
710 pDCE
->DCXFlags
= DCX_DCEEMPTY
|DCX_CACHE
;
711 pDCE
->hwndCurrent
= 0;
713 TRACE("POWNED DCE going Cheap!! DCX_CACHE!! hDC-> %x \n", pDCE
->hDC
);
714 if (!GreSetDCOwner( pDCE
->hDC
, GDI_OBJ_HMGR_NONE
))
716 ERR("Fail Owner Switch hDC-> %x \n", pDCE
->hDC
);
719 /* Do not change owner so thread can clean up! */
721 else if (Window
->pcls
->style
& CS_OWNDC
) /* owned DCE*/
723 pDCE
= DceFreeDCE(pDCE
, FALSE
);
729 ERR("Not POWNED or CLASSDC hwndCurrent -> %x \n", pDCE
->hwndCurrent
);
730 // ASSERT(FALSE); /* bug 5320 */
735 if (pDCE
->DCXFlags
& DCX_DCEBUSY
) /* shared cache DCE */
737 /* FIXME: AFAICS we are doing the right thing here so
738 * this should be a TRACE. But this is best left as an ERR
739 * because the 'application error' is likely to come from
740 * another part of Wine (i.e. it's our fault after all).
741 * We should change this to TRACE when ReactOS is more stable
744 ERR("[%p] GetDC() without ReleaseDC()!\n", Window
->head
.h
);
745 DceReleaseDC(pDCE
, FALSE
);
747 pDCE
->DCXFlags
|= DCX_DCEEMPTY
;
748 pDCE
->hwndCurrent
= 0;
751 pLE
= pDCE
->List
.Flink
;
752 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
754 while (pLE
!= &LEDce
);
758 DceFreeClassDCE(HDC hDC
)
763 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
768 if (pDCE
->hDC
== hDC
)
770 pDCE
= DceFreeDCE(pDCE
, TRUE
); // Might have gone cheap!
774 pLE
= pDCE
->List
.Flink
;
775 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
777 while (pLE
!= &LEDce
);
781 DceFreeThreadDCE(PTHREADINFO pti
)
786 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
791 if (pDCE
->ptiOwner
== pti
)
793 if (pDCE
->DCXFlags
& DCX_CACHE
)
795 pDCE
= DceFreeDCE(pDCE
, TRUE
);
800 pLE
= pDCE
->List
.Flink
;
801 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
803 while (pLE
!= &LEDce
);
812 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
817 pDCE
= DceFreeDCE(pDCE
, TRUE
);
820 while (pLE
!= &LEDce
);
824 DceResetActiveDCEs(PWND Window
)
838 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
843 if(pLE
== &LEDce
) break;
844 if (0 == (pDCE
->DCXFlags
& (DCX_DCEEMPTY
|DCX_INDESTROY
)))
846 if (Window
->head
.h
== pDCE
->hwndCurrent
)
848 CurrentWindow
= Window
;
852 CurrentWindow
= UserGetWindowObject(pDCE
->hwndCurrent
);
853 if (NULL
== CurrentWindow
)
855 pLE
= pDCE
->List
.Flink
;
856 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
861 if (!GreIsHandleValid(pDCE
->hDC
) ||
862 (dc
= DC_LockDc(pDCE
->hDC
)) == NULL
)
864 pLE
= pDCE
->List
.Flink
;
865 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
868 if (Window
== CurrentWindow
|| IntIsChildWindow(Window
, CurrentWindow
))
870 if (pDCE
->DCXFlags
& DCX_WINDOW
)
872 DeltaX
= CurrentWindow
->rcWindow
.left
- dc
->ptlDCOrig
.x
;
873 DeltaY
= CurrentWindow
->rcWindow
.top
- dc
->ptlDCOrig
.y
;
874 dc
->ptlDCOrig
.x
= CurrentWindow
->rcWindow
.left
;
875 dc
->ptlDCOrig
.y
= CurrentWindow
->rcWindow
.top
;
879 DeltaX
= CurrentWindow
->rcClient
.left
- dc
->ptlDCOrig
.x
;
880 DeltaY
= CurrentWindow
->rcClient
.top
- dc
->ptlDCOrig
.y
;
881 dc
->ptlDCOrig
.x
= CurrentWindow
->rcClient
.left
;
882 dc
->ptlDCOrig
.y
= CurrentWindow
->rcClient
.top
;
884 if (NULL
!= dc
->rosdc
.hClipRgn
)
886 NtGdiOffsetRgn(dc
->rosdc
.hClipRgn
, DeltaX
, DeltaY
);
887 CLIPPING_UpdateGCRegion(dc
);
889 if (NULL
!= pDCE
->hrgnClip
)
891 NtGdiOffsetRgn(pDCE
->hrgnClip
, DeltaX
, DeltaY
);
896 DceUpdateVisRgn(pDCE
, CurrentWindow
, pDCE
->DCXFlags
);
898 if (Window
->head
.h
!= pDCE
->hwndCurrent
)
900 // IntEngWindowChanged(CurrentWindow, WOC_RGN_CLIENT);
901 // UserDerefObject(CurrentWindow);
904 pLE
= pDCE
->List
.Flink
;
905 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
907 while (pLE
!= &LEDce
);
911 IntWindowFromDC(HDC hDc
)
918 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
923 if (Dce
->DCXFlags
& DCX_INDESTROY
)
926 Ret
= Dce
->hwndCurrent
;
929 pLE
= Dce
->List
.Flink
;
930 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
932 while (pLE
!= &LEDce
);
937 UserReleaseDC(PWND Window
, HDC hDc
, BOOL EndPaint
)
944 TRACE("%p %p\n", Window
, hDc
);
946 dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
955 pLE
= dce
->List
.Flink
;
956 dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
958 while (pLE
!= &LEDce
);
960 if ( Hit
&& (dce
->DCXFlags
& DCX_DCEBUSY
))
962 nRet
= DceReleaseDC(dce
, EndPaint
);
969 UserGetWindowDC(PWND Wnd
)
971 return UserGetDCEx(Wnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
975 UserGethWnd( HDC hdc
, PWNDOBJ
*pwndo
)
981 hWnd
= IntWindowFromDC(hdc
);
983 if (hWnd
&& !(Wnd
= UserGetWindowObject(hWnd
)))
985 pWndgdi
= (WNDGDI
*)IntGetProp(Wnd
, AtomWndObj
);
987 if ( pWndgdi
&& pWndgdi
->Hwnd
== hWnd
)
989 if (pwndo
) *pwndo
= (PWNDOBJ
)pWndgdi
;
996 NtUserGetDCEx(HWND hWnd OPTIONAL
, HANDLE ClipRegion
, ULONG Flags
)
1001 TRACE("Enter NtUserGetDCEx\n");
1002 UserEnterExclusive();
1004 if (hWnd
&& !(Wnd
= UserGetWindowObject(hWnd
)))
1008 RETURN( UserGetDCEx(Wnd
, ClipRegion
, Flags
));
1011 TRACE("Leave NtUserGetDCEx, ret=%i\n",_ret_
);
1019 * The NtUserGetWindowDC function retrieves the device context (DC) for the
1020 * entire window, including title bar, menus, and scroll bars. A window device
1021 * context permits painting anywhere in a window, because the origin of the
1022 * device context is the upper-left corner of the window instead of the client
1029 NtUserGetWindowDC(HWND hWnd
)
1031 return NtUserGetDCEx(hWnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
1035 NtUserGetDC(HWND hWnd
)
1037 TRACE("NtUGetDC -> %x:%x\n", hWnd
, !hWnd
? DCX_CACHE
| DCX_WINDOW
: DCX_USESTYLE
);
1039 return NtUserGetDCEx(hWnd
, NULL
, NULL
== hWnd
? DCX_CACHE
| DCX_WINDOW
: DCX_USESTYLE
);
1043 * Select logical palette into device context.
1044 * \param hDC handle to the device context
1045 * \param hpal handle to the palette
1046 * \param ForceBackground If this value is FALSE the logical palette will be copied to the device palette only when the applicatioon
1047 * is in the foreground. If this value is TRUE then map the colors in the logical palette to the device
1048 * palette colors in the best way.
1049 * \return old palette
1051 * \todo implement ForceBackground == TRUE
1055 NtUserSelectPalette(HDC hDC
,
1057 BOOL ForceBackground
)
1060 UserEnterExclusive();
1061 // Implement window checks
1062 oldPal
= GdiSelectPalette( hDC
, hpal
, ForceBackground
);