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
);
54 defaultDCstate
= ExAllocatePoolWithTag(PagedPool
, sizeof(DC
), TAG_DC
);
55 RtlZeroMemory(defaultDCstate
, sizeof(DC
));
56 defaultDCstate
->pdcattr
= &defaultDCstate
->dcattr
;
57 DC_vCopyState(dc
, defaultDCstate
, TRUE
);
59 InitializeListHead(&LEDce
);
66 DceGetVisRgn(PWND Window
, ULONG Flags
, HWND hWndChild
, ULONG CFlags
)
70 VisRgn
= VIS_ComputeVisibleRegion( Window
,
71 0 == (Flags
& DCX_WINDOW
),
72 0 != (Flags
& DCX_CLIPCHILDREN
),
73 0 != (Flags
& DCX_CLIPSIBLINGS
));
76 VisRgn
= IntSysCreateRectRgn(0, 0, 0, 0);
82 DceAllocDCE(PWND Window OPTIONAL
, DCE_TYPE Type
)
86 pDce
= ExAllocatePoolWithTag(PagedPool
, sizeof(DCE
), USERTAG_DCE
);
90 pDce
->hDC
= DceCreateDisplayDC();
93 ExFreePoolWithTag(pDce
, USERTAG_DCE
);
97 DPRINT("Alloc DCE's! %d\n",DCECount
);
98 pDce
->hwndCurrent
= (Window
? Window
->head
.h
: NULL
);
99 pDce
->pwndOrg
= Window
;
100 pDce
->pwndClip
= Window
;
101 pDce
->hrgnClip
= NULL
;
102 pDce
->hrgnClipPublic
= NULL
;
103 pDce
->hrgnSavedVis
= NULL
;
104 pDce
->ppiOwner
= NULL
;
106 InsertTailList(&LEDce
, &pDce
->List
);
108 DCU_SetDcUndeletable(pDce
->hDC
);
110 if (Type
== DCE_WINDOW_DC
|| Type
== DCE_CLASS_DC
) //Window DCE have ownership.
112 pDce
->ptiOwner
= GetW32ThreadInfo();
116 DPRINT("FREE DCATTR!!!! NOT DCE_WINDOW_DC!!!!! hDC-> %x\n", pDce
->hDC
);
117 GreSetDCOwner(pDce
->hDC
, GDI_OBJ_HMGR_NONE
);
118 pDce
->ptiOwner
= NULL
;
121 if (Type
== DCE_CACHE_DC
)
123 pDce
->DCXFlags
= DCX_CACHE
| DCX_DCEEMPTY
;
127 pDce
->DCXFlags
= DCX_DCEBUSY
;
130 if (Type
== DCE_WINDOW_DC
)
132 if (Window
->style
& WS_CLIPCHILDREN
) pDce
->DCXFlags
|= DCX_CLIPCHILDREN
;
133 if (Window
->style
& WS_CLIPSIBLINGS
) pDce
->DCXFlags
|= DCX_CLIPSIBLINGS
;
141 DceSetDrawable( PWND Window OPTIONAL
,
146 DC
*dc
= DC_LockDc(hDC
);
157 if (Flags
& DCX_WINDOW
)
159 dc
->ptlDCOrig
.x
= Window
->rcWindow
.left
;
160 dc
->ptlDCOrig
.y
= Window
->rcWindow
.top
;
164 dc
->ptlDCOrig
.x
= Window
->rcClient
.left
;
165 dc
->ptlDCOrig
.y
= Window
->rcClient
.top
;
173 DceDeleteClipRgn(DCE
* Dce
)
175 Dce
->DCXFlags
&= ~(DCX_EXCLUDERGN
| DCX_INTERSECTRGN
);
177 if (Dce
->DCXFlags
& DCX_KEEPCLIPRGN
)
179 Dce
->DCXFlags
&= ~DCX_KEEPCLIPRGN
;
181 else if (Dce
->hrgnClip
!= NULL
)
183 GreDeleteObject(Dce
->hrgnClip
);
186 Dce
->hrgnClip
= NULL
;
188 /* make it dirty so that the vis rgn gets recomputed next time */
189 Dce
->DCXFlags
|= DCX_DCEDIRTY
;
193 DceReleaseDC(DCE
* dce
, BOOL EndPaint
)
195 if (DCX_DCEBUSY
!= (dce
->DCXFlags
& (DCX_INDESTROY
| DCX_DCEEMPTY
| DCX_DCEBUSY
)))
200 /* restore previous visible region */
201 if ((dce
->DCXFlags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) &&
202 ((dce
->DCXFlags
& DCX_CACHE
) || EndPaint
))
204 DceDeleteClipRgn(dce
);
207 if (dce
->DCXFlags
& DCX_CACHE
)
209 if (!(dce
->DCXFlags
& DCX_NORESETATTRS
))
211 /* make the DC clean so that SetDCState doesn't try to update the vis rgn */
212 IntGdiSetHookFlags(dce
->hDC
, DCHF_VALIDATEVISRGN
);
215 if (!IntGdiCleanDC(dce
->hDC
)) return 0;
217 if (dce
->DCXFlags
& DCX_DCEDIRTY
)
219 /* don't keep around invalidated entries
220 * because SetDCState() disables hVisRgn updates
221 * by removing dirty bit. */
222 dce
->hwndCurrent
= 0;
223 dce
->DCXFlags
&= DCX_CACHE
;
224 dce
->DCXFlags
|= DCX_DCEEMPTY
;
227 dce
->DCXFlags
&= ~DCX_DCEBUSY
;
228 DPRINT("Exit!!!!! DCX_CACHE!!!!!! hDC-> %x \n", dce
->hDC
);
229 if (!GreSetDCOwner(dce
->hDC
, GDI_OBJ_HMGR_NONE
))
231 dce
->ptiOwner
= NULL
; // Reset ownership.
232 dce
->ppiOwner
= NULL
;
234 #if 0 // Need to research and fix before this is a "growing" issue.
238 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
241 if (!(pDCE
->DCXFlags
& DCX_DCEBUSY
))
242 { /* Free the unused cache DCEs. */
243 pDCE
= DceFreeDCE(pDCE
, TRUE
);
248 while (pLE
!= &LEDce
);
252 return 1; // Released!
256 DceUpdateVisRgn(DCE
*Dce
, PWND Window
, ULONG Flags
)
258 HANDLE hRgnVisible
= NULL
;
262 if (Flags
& DCX_PARENTCLIP
)
266 Parent
= Window
->spwndParent
;
273 if (Parent
->style
& WS_CLIPSIBLINGS
)
275 DcxFlags
= DCX_CLIPSIBLINGS
|
276 (Flags
& ~(DCX_CLIPCHILDREN
| DCX_WINDOW
));
280 DcxFlags
= Flags
& ~(DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
| DCX_WINDOW
);
282 hRgnVisible
= DceGetVisRgn(Parent
, DcxFlags
, Window
->head
.h
, Flags
);
284 else if (Window
== NULL
)
286 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
287 if (NULL
!= DesktopWindow
)
289 hRgnVisible
= IntSysCreateRectRgnIndirect(&DesktopWindow
->rcWindow
);
298 hRgnVisible
= DceGetVisRgn(Window
, Flags
, 0, 0);
302 if (Flags
& DCX_INTERSECTRGN
)
304 if(Dce
->hrgnClip
!= NULL
)
306 NtGdiCombineRgn(hRgnVisible
, hRgnVisible
, Dce
->hrgnClip
, RGN_AND
);
310 if(hRgnVisible
!= NULL
)
312 GreDeleteObject(hRgnVisible
);
314 hRgnVisible
= IntSysCreateRectRgn(0, 0, 0, 0);
317 else if (Flags
& DCX_EXCLUDERGN
&& Dce
->hrgnClip
!= NULL
)
319 NtGdiCombineRgn(hRgnVisible
, hRgnVisible
, Dce
->hrgnClip
, RGN_DIFF
);
322 Dce
->DCXFlags
&= ~DCX_DCEDIRTY
;
323 GdiSelectVisRgn(Dce
->hDC
, hRgnVisible
);
327 IntEngWindowChanged(Window
, WOC_RGN_CLIENT
);
330 if (hRgnVisible
!= NULL
)
332 GreDeleteObject(hRgnVisible
);
337 UserGetDCEx(PWND Wnd OPTIONAL
, HANDLE ClipRegion
, ULONG Flags
)
342 BOOL UpdateClipOrigin
= FALSE
;
349 Flags
&= ~DCX_USESTYLE
;
353 if (Flags
& (DCX_WINDOW
| DCX_PARENTCLIP
)) Flags
|= DCX_CACHE
;
355 // When GetDC is called with hWnd nz, DCX_CACHE & _WINDOW are clear w _USESTYLE set.
356 if (Flags
& DCX_USESTYLE
)
358 Flags
&= ~(DCX_CLIPCHILDREN
| DCX_CLIPSIBLINGS
| DCX_PARENTCLIP
);
359 if (!(Flags
& DCX_WINDOW
)) // not window rectangle
361 if (Wnd
->pcls
->style
& CS_PARENTDC
)
363 Flags
|= DCX_PARENTCLIP
;
366 if (!(Flags
& DCX_CACHE
) && // Not on the cheap wine list.
367 !(Wnd
->pcls
->style
& CS_OWNDC
) )
369 if (!(Wnd
->pcls
->style
& CS_CLASSDC
))
370 // The window is not POWNED or has any CLASS, so we are looking for cheap wine.
374 if (Wnd
->pcls
->pdce
) hDC
= ((PDCE
)Wnd
->pcls
->pdce
)->hDC
;
375 DPRINT("We have CLASS!!\n");
378 /* else // For Testing!
380 DPRINT1("We have POWNER!!\n");
381 if (Window->Dce) DPRINT1("We have POWNER with DCE!!\n");
384 if (Wnd
->style
& WS_CLIPSIBLINGS
)
386 Flags
|= DCX_CLIPSIBLINGS
;
389 if (Wnd
->style
& WS_CLIPCHILDREN
&&
390 !(Wnd
->style
& WS_MINIMIZE
))
392 Flags
|= DCX_CLIPCHILDREN
;
394 /* If minized with icon in the set, we are forced to be cheap! */
395 if (Wnd
->style
& WS_MINIMIZE
&&
403 if (Wnd
->style
& WS_CLIPSIBLINGS
) Flags
|= DCX_CLIPSIBLINGS
;
408 if (Flags
& DCX_WINDOW
) Flags
&= ~DCX_CLIPCHILDREN
;
410 if (Flags
& DCX_NOCLIPCHILDREN
)
413 Flags
&= ~(DCX_PARENTCLIP
| DCX_CLIPCHILDREN
);
416 Parent
= (Wnd
? Wnd
->spwndParent
: NULL
);
418 if (NULL
== Wnd
|| !(Wnd
->style
& WS_CHILD
) || NULL
== Parent
)
420 Flags
&= ~DCX_PARENTCLIP
;
421 Flags
|= DCX_CLIPSIBLINGS
;
424 /* it seems parent clip is ignored when clipping siblings or children */
425 if (Flags
& (DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
)) Flags
&= ~DCX_PARENTCLIP
;
427 if (Flags
& DCX_PARENTCLIP
)
429 if ((Wnd
->style
& WS_VISIBLE
) &&
430 (Parent
->style
& WS_VISIBLE
))
432 Flags
&= ~DCX_CLIPCHILDREN
;
433 if (Parent
->style
& WS_CLIPSIBLINGS
)
435 Flags
|= DCX_CLIPSIBLINGS
;
440 // Window nz, check to see if we still own this or it is just cheap wine tonight.
441 if (!(Flags
& DCX_CACHE
))
443 if ( Wnd
->head
.pti
!= GetW32ThreadInfo())
444 Flags
|= DCX_CACHE
; // Ah~ Not Powned! Forced to be cheap~
447 DcxFlags
= Flags
& DCX_CACHECOMPAREMASK
;
449 if (Flags
& DCX_CACHE
)
450 { // Scan the cheap wine list for our match.
451 DCE
* DceEmpty
= NULL
;
452 DCE
* DceUnused
= NULL
;
453 KeEnterCriticalRegion();
455 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
458 // The reason for this you may ask?
459 // Well, it seems ReactOS calls GetDC with out first creating a desktop DC window!
460 // Need to test for null here. Not sure if this is a bug or a feature.
461 // First time use hax, need to use DceAllocDCE during window display init.
464 // The way I understand this, you can have more than one DC per window.
465 // Only one Owned if one was requested and saved and one Cached.
467 if ((Dce
->DCXFlags
& (DCX_CACHE
| DCX_DCEBUSY
)) == DCX_CACHE
)
470 if (Dce
->DCXFlags
& DCX_DCEEMPTY
)
474 else if (Dce
->hwndCurrent
== (Wnd
? Wnd
->head
.h
: NULL
) &&
475 ((Dce
->DCXFlags
& DCX_CACHECOMPAREMASK
) == DcxFlags
))
477 UpdateClipOrigin
= TRUE
;
481 pLE
= Dce
->List
.Flink
;
482 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
484 while (pLE
!= &LEDce
);
485 KeLeaveCriticalRegion();
487 Dce
= (DceEmpty
== NULL
) ? DceUnused
: DceEmpty
;
491 Dce
= DceAllocDCE(NULL
, DCE_CACHE_DC
);
493 if (!Dce
) return NULL
;
495 Dce
->hwndCurrent
= (Wnd
? Wnd
->head
.h
: NULL
);
497 else // If we are here, we are POWNED or having CLASS.
499 KeEnterCriticalRegion();
501 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
503 { // Check for Window handle than HDC match for CLASS.
504 if ((Dce
->hwndCurrent
== Wnd
->head
.h
) ||
507 pLE
= Dce
->List
.Flink
;
508 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
510 while (pLE
!= &LEDce
);
511 KeLeaveCriticalRegion();
513 if ( (Flags
& (DCX_INTERSECTRGN
|DCX_EXCLUDERGN
)) &&
514 (Dce
->DCXFlags
& (DCX_INTERSECTRGN
|DCX_EXCLUDERGN
)) )
516 DceDeleteClipRgn(Dce
);
519 // First time use hax, need to use DceAllocDCE during window display init.
525 if (!GreIsHandleValid(Dce
->hDC
))
527 DPRINT1("FIXME: Got DCE with invalid hDC! 0x%x\n", Dce
->hDC
);
528 Dce
->hDC
= DceCreateDisplayDC();
529 /* FIXME: Handle error */
532 Dce
->DCXFlags
= Flags
| DCX_DCEBUSY
;
535 Bump it up! This prevents the random errors in wine dce tests and with
536 proper bits set in DCX_CACHECOMPAREMASK.
538 http://www.reactos.org/archives/public/ros-dev/2008-July/010498.html
539 http://www.reactos.org/archives/public/ros-dev/2008-July/010499.html
543 RemoveEntryList(&Dce
->List
);
544 InsertHeadList(&LEDce
, &Dce
->List
);
547 /* Introduced in rev 6691 and modified later. */
548 if ( (Flags
& DCX_INTERSECTUPDATE
) && !ClipRegion
)
550 Flags
|= DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
;
551 Dce
->DCXFlags
|= DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
;
552 ClipRegion
= Wnd
->hrgnUpdate
;
555 if (ClipRegion
== HRGN_WINDOW
)
557 if (!(Flags
& DCX_WINDOW
))
559 Dce
->hrgnClip
= IntSysCreateRectRgnIndirect(&Wnd
->rcClient
);
563 Dce
->hrgnClip
= IntSysCreateRectRgnIndirect(&Wnd
->rcWindow
);
565 Dce
->DCXFlags
&= ~DCX_KEEPCLIPRGN
;
567 else if (ClipRegion
!= NULL
)
569 if (Dce
->hrgnClip
!= NULL
)
571 DPRINT1("Should not be called!!\n");
572 GreDeleteObject(Dce
->hrgnClip
);
573 Dce
->hrgnClip
= NULL
;
575 Dce
->hrgnClip
= ClipRegion
;
578 DceSetDrawable(Wnd
, Dce
->hDC
, Flags
, UpdateClipOrigin
);
580 DceUpdateVisRgn(Dce
, Wnd
, Flags
);
582 if (Dce
->DCXFlags
& DCX_CACHE
)
584 DPRINT("ENTER!!!!!! DCX_CACHE!!!!!! hDC-> %x\n", Dce
->hDC
);
585 // Need to set ownership so Sync dcattr will work.
586 GreSetDCOwner(Dce
->hDC
, GDI_OBJ_HMGR_POWNED
);
587 Dce
->ptiOwner
= GetW32ThreadInfo(); // Set the temp owning
591 Wnd
->ExStyle
& WS_EX_LAYOUTRTL
&&
592 !(Flags
& DCX_KEEPLAYOUT
) )
594 NtGdiSetLayout(Dce
->hDC
, -1, LAYOUT_RTL
);
597 if (Dce
->DCXFlags
& DCX_PROCESSOWNED
)
599 ppi
= PsGetCurrentProcessWin32Process();
600 ppi
->W32PF_flags
|= W32PF_OWNDCCLEANUP
;
601 Dce
->ptiOwner
= NULL
;
608 /***********************************************************************
612 DceFreeDCE(PDCE pdce
, BOOLEAN Force
)
618 if (NULL
== pdce
) return NULL
;
620 pLE
= pdce
->List
.Flink
;
621 ret
= CONTAINING_RECORD(pLE
, DCE
, List
);
623 pdce
->DCXFlags
|= DCX_INDESTROY
;
626 GreGetObjectOwner(pdce
->hDC
) != GDI_OBJ_HMGR_POWNED
)
628 DPRINT("Change ownership for DCE! -> %x\n" , pdce
);
629 // Note: Windows sets W32PF_OWNDCCLEANUP and moves on.
630 if (GreIsHandleValid(pdce
->hDC
))
632 GreSetDCOwner(pdce
->hDC
, GDI_OBJ_HMGR_POWNED
);
636 DPRINT1("Attempted to change ownership of an DCEhDC 0x%x currently being destroyed!!!\n",pdce
->hDC
);
642 if (GreGetObjectOwner(pdce
->hDC
) == GDI_OBJ_HMGR_PUBLIC
)
643 GreSetDCOwner(pdce
->hDC
, GDI_OBJ_HMGR_POWNED
);
646 if (!Hit
) IntGdiDeleteDC(pdce
->hDC
, TRUE
);
648 if (pdce
->hrgnClip
&& !(pdce
->DCXFlags
& DCX_KEEPCLIPRGN
))
650 GreDeleteObject(pdce
->hrgnClip
);
651 pdce
->hrgnClip
= NULL
;
654 RemoveEntryList(&pdce
->List
);
656 if (IsListEmpty(&pdce
->List
))
658 DPRINT1("List is Empty! DCE! -> %x\n" , pdce
);
662 ExFreePoolWithTag(pdce
, USERTAG_DCE
);
665 DPRINT("Freed DCE's! %d \n", DCECount
);
670 /***********************************************************************
673 * Remove owned DCE and reset unreleased cache DCEs.
676 DceFreeWindowDCE(PWND Window
)
683 DPRINT1("FreeWindowDCE No Entry! %d\n",DCECount
);
688 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
693 DPRINT1("FreeWindowDCE No DCE Pointer!\n");
696 if (IsListEmpty(&pDCE
->List
))
698 DPRINT1("FreeWindowDCE List is Empty!!!!\n");
701 if ( pDCE
->hwndCurrent
== Window
->head
.h
&&
702 !(pDCE
->DCXFlags
& DCX_DCEEMPTY
) )
704 if (!(pDCE
->DCXFlags
& DCX_CACHE
)) /* owned or Class DCE*/
706 if (Window
->pcls
->style
& CS_CLASSDC
) /* Test Class first */
708 if (pDCE
->DCXFlags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) /* Class DCE*/
709 DceDeleteClipRgn(pDCE
);
710 // Update and reset Vis Rgn and clear the dirty bit.
711 // Should release VisRgn than reset it to default.
712 DceUpdateVisRgn(pDCE
, Window
, pDCE
->DCXFlags
);
713 pDCE
->DCXFlags
= DCX_DCEEMPTY
|DCX_CACHE
;
714 pDCE
->hwndCurrent
= 0;
716 DPRINT("POWNED DCE going Cheap!! DCX_CACHE!! hDC-> %x \n", pDCE
->hDC
);
717 if (!GreSetDCOwner( pDCE
->hDC
, GDI_OBJ_HMGR_NONE
))
719 DPRINT1("Fail Owner Switch hDC-> %x \n", pDCE
->hDC
);
722 /* Do not change owner so thread can clean up! */
724 else if (Window
->pcls
->style
& CS_OWNDC
) /* owned DCE*/
726 pDCE
= DceFreeDCE(pDCE
, FALSE
);
732 DPRINT1("Not POWNED or CLASSDC hwndCurrent -> %x \n", pDCE
->hwndCurrent
);
738 if (pDCE
->DCXFlags
& DCX_DCEBUSY
) /* shared cache DCE */
740 /* FIXME: AFAICS we are doing the right thing here so
741 * this should be a DPRINT. But this is best left as an ERR
742 * because the 'application error' is likely to come from
743 * another part of Wine (i.e. it's our fault after all).
744 * We should change this to DPRINT when ReactOS is more stable
747 DPRINT1("[%p] GetDC() without ReleaseDC()!\n", Window
->head
.h
);
748 DceReleaseDC(pDCE
, FALSE
);
750 pDCE
->DCXFlags
|= DCX_DCEEMPTY
;
751 pDCE
->hwndCurrent
= 0;
754 pLE
= pDCE
->List
.Flink
;
755 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
757 while (pLE
!= &LEDce
);
761 DceFreeClassDCE(HDC hDC
)
766 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
771 if (pDCE
->hDC
== hDC
)
773 pDCE
= DceFreeDCE(pDCE
, TRUE
); // Might have gone cheap!
777 pLE
= pDCE
->List
.Flink
;
778 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
780 while (pLE
!= &LEDce
);
784 DceFreeThreadDCE(PTHREADINFO pti
)
789 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
794 if (pDCE
->ptiOwner
== pti
)
796 if (pDCE
->DCXFlags
& DCX_CACHE
)
798 pDCE
= DceFreeDCE(pDCE
, TRUE
);
803 pLE
= pDCE
->List
.Flink
;
804 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
806 while (pLE
!= &LEDce
);
815 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
820 pDCE
= DceFreeDCE(pDCE
, TRUE
);
823 while (pLE
!= &LEDce
);
827 DceResetActiveDCEs(PWND Window
)
841 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
846 if(pLE
== &LEDce
) break;
847 if (0 == (pDCE
->DCXFlags
& (DCX_DCEEMPTY
|DCX_INDESTROY
)))
849 if (Window
->head
.h
== pDCE
->hwndCurrent
)
851 CurrentWindow
= Window
;
855 CurrentWindow
= UserGetWindowObject(pDCE
->hwndCurrent
);
856 if (NULL
== CurrentWindow
)
858 pLE
= pDCE
->List
.Flink
;
859 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
864 if (!GreIsHandleValid(pDCE
->hDC
) ||
865 (dc
= DC_LockDc(pDCE
->hDC
)) == NULL
)
867 pLE
= pDCE
->List
.Flink
;
868 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
871 if (Window
== CurrentWindow
|| IntIsChildWindow(Window
, CurrentWindow
))
873 if (pDCE
->DCXFlags
& DCX_WINDOW
)
875 DeltaX
= CurrentWindow
->rcWindow
.left
- dc
->ptlDCOrig
.x
;
876 DeltaY
= CurrentWindow
->rcWindow
.top
- dc
->ptlDCOrig
.y
;
877 dc
->ptlDCOrig
.x
= CurrentWindow
->rcWindow
.left
;
878 dc
->ptlDCOrig
.y
= CurrentWindow
->rcWindow
.top
;
882 DeltaX
= CurrentWindow
->rcClient
.left
- dc
->ptlDCOrig
.x
;
883 DeltaY
= CurrentWindow
->rcClient
.top
- dc
->ptlDCOrig
.y
;
884 dc
->ptlDCOrig
.x
= CurrentWindow
->rcClient
.left
;
885 dc
->ptlDCOrig
.y
= CurrentWindow
->rcClient
.top
;
887 if (NULL
!= dc
->rosdc
.hClipRgn
)
889 NtGdiOffsetRgn(dc
->rosdc
.hClipRgn
, DeltaX
, DeltaY
);
890 CLIPPING_UpdateGCRegion(dc
);
892 if (NULL
!= pDCE
->hrgnClip
)
894 NtGdiOffsetRgn(pDCE
->hrgnClip
, DeltaX
, DeltaY
);
899 DceUpdateVisRgn(pDCE
, CurrentWindow
, pDCE
->DCXFlags
);
901 if (Window
->head
.h
!= pDCE
->hwndCurrent
)
903 // IntEngWindowChanged(CurrentWindow, WOC_RGN_CLIENT);
904 // UserDerefObject(CurrentWindow);
907 pLE
= pDCE
->List
.Flink
;
908 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
910 while (pLE
!= &LEDce
);
914 IntWindowFromDC(HDC hDc
)
921 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
926 if (Dce
->DCXFlags
& DCX_INDESTROY
)
929 Ret
= Dce
->hwndCurrent
;
932 pLE
= Dce
->List
.Flink
;
933 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
935 while (pLE
!= &LEDce
);
940 UserReleaseDC(PWND Window
, HDC hDc
, BOOL EndPaint
)
947 DPRINT("%p %p\n", Window
, hDc
);
949 dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
958 pLE
= dce
->List
.Flink
;
959 dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
961 while (pLE
!= &LEDce
);
963 if ( Hit
&& (dce
->DCXFlags
& DCX_DCEBUSY
))
965 nRet
= DceReleaseDC(dce
, EndPaint
);
972 UserGetWindowDC(PWND Wnd
)
974 return UserGetDCEx(Wnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
978 UserGethWnd( HDC hdc
, PWNDOBJ
*pwndo
)
984 hWnd
= IntWindowFromDC(hdc
);
986 if (hWnd
&& !(Wnd
= UserGetWindowObject(hWnd
)))
988 pWndgdi
= (WNDGDI
*)IntGetProp(Wnd
, AtomWndObj
);
990 if ( pWndgdi
&& pWndgdi
->Hwnd
== hWnd
)
992 if (pwndo
) *pwndo
= (PWNDOBJ
)pWndgdi
;
999 NtUserGetDCEx(HWND hWnd OPTIONAL
, HANDLE ClipRegion
, ULONG Flags
)
1002 DECLARE_RETURN(HDC
);
1004 DPRINT("Enter NtUserGetDCEx\n");
1005 UserEnterExclusive();
1007 if (hWnd
&& !(Wnd
= UserGetWindowObject(hWnd
)))
1011 RETURN( UserGetDCEx(Wnd
, ClipRegion
, Flags
));
1014 DPRINT("Leave NtUserGetDCEx, ret=%i\n",_ret_
);
1022 * The NtUserGetWindowDC function retrieves the device context (DC) for the
1023 * entire window, including title bar, menus, and scroll bars. A window device
1024 * context permits painting anywhere in a window, because the origin of the
1025 * device context is the upper-left corner of the window instead of the client
1032 NtUserGetWindowDC(HWND hWnd
)
1034 return NtUserGetDCEx(hWnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
1038 NtUserGetDC(HWND hWnd
)
1040 DPRINT("NtUGetDC -> %x:%x\n", hWnd
, !hWnd
? DCX_CACHE
| DCX_WINDOW
: DCX_USESTYLE
);
1042 return NtUserGetDCEx(hWnd
, NULL
, NULL
== hWnd
? DCX_CACHE
| DCX_WINDOW
: DCX_USESTYLE
);
1046 * Select logical palette into device context.
1047 * \param hDC handle to the device context
1048 * \param hpal handle to the palette
1049 * \param ForceBackground If this value is FALSE the logical palette will be copied to the device palette only when the applicatioon
1050 * is in the foreground. If this value is TRUE then map the colors in the logical palette to the device
1051 * palette colors in the best way.
1052 * \return old palette
1054 * \todo implement ForceBackground == TRUE
1058 NtUserSelectPalette(HDC hDC
,
1060 BOOL ForceBackground
)
1063 UserEnterExclusive();
1064 // Implement window checks
1065 oldPal
= GdiSelectPalette( hDC
, hpal
, ForceBackground
);