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(PWINDOW_OBJECT 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(PWINDOW_OBJECT Window OPTIONAL
, DCE_TYPE Type
)
86 if (Window
) Wnd
= Window
->Wnd
;
88 pDce
= ExAllocatePoolWithTag(PagedPool
, sizeof(DCE
), TAG_PDCE
);
92 pDce
->hDC
= DceCreateDisplayDC();
95 ExFreePoolWithTag(pDce
, TAG_PDCE
);
99 DPRINT("Alloc DCE's! %d\n",DCECount
);
100 pDce
->hwndCurrent
= (Window
? Window
->hSelf
: NULL
);
102 pDce
->pwndClip
= Wnd
;
103 pDce
->hrgnClip
= NULL
;
104 pDce
->hrgnClipPublic
= NULL
;
105 pDce
->hrgnSavedVis
= NULL
;
106 pDce
->ppiOwner
= NULL
;
108 InsertTailList(&LEDce
, &pDce
->List
);
110 DCU_SetDcUndeletable(pDce
->hDC
);
112 if (Type
== DCE_WINDOW_DC
|| Type
== DCE_CLASS_DC
) //Window DCE have ownership.
114 pDce
->ptiOwner
= GetW32ThreadInfo();
118 DPRINT("FREE DCATTR!!!! NOT DCE_WINDOW_DC!!!!! hDC-> %x\n", pDce
->hDC
);
119 IntGdiSetDCOwnerEx( pDce
->hDC
, GDI_OBJ_HMGR_NONE
, FALSE
);
120 pDce
->ptiOwner
= NULL
;
123 if (Type
== DCE_CACHE_DC
)
125 pDce
->DCXFlags
= DCX_CACHE
| DCX_DCEEMPTY
;
129 pDce
->DCXFlags
= DCX_DCEBUSY
;
132 if (Type
== DCE_WINDOW_DC
)
134 if (Wnd
->style
& WS_CLIPCHILDREN
) pDce
->DCXFlags
|= DCX_CLIPCHILDREN
;
135 if (Wnd
->style
& WS_CLIPSIBLINGS
) pDce
->DCXFlags
|= DCX_CLIPSIBLINGS
;
143 DceSetDrawable( PWINDOW_OBJECT Window OPTIONAL
,
149 DC
*dc
= DC_LockDc(hDC
);
161 if (Flags
& DCX_WINDOW
)
163 dc
->ptlDCOrig
.x
= Wnd
->rcWindow
.left
;
164 dc
->ptlDCOrig
.y
= Wnd
->rcWindow
.top
;
168 dc
->ptlDCOrig
.x
= Wnd
->rcClient
.left
;
169 dc
->ptlDCOrig
.y
= Wnd
->rcClient
.top
;
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 GDIOBJ_FreeObjByHandle(Dce
->hrgnClip
, GDI_OBJECT_TYPE_REGION
|GDI_OBJECT_TYPE_SILENT
);
190 Dce
->hrgnClip
= NULL
;
192 /* make it dirty so that the vis rgn gets recomputed next time */
193 Dce
->DCXFlags
|= DCX_DCEDIRTY
;
197 DceReleaseDC(DCE
* dce
, BOOL EndPaint
)
199 if (DCX_DCEBUSY
!= (dce
->DCXFlags
& (DCX_INDESTROY
| DCX_DCEEMPTY
| DCX_DCEBUSY
)))
204 /* restore previous visible region */
205 if ((dce
->DCXFlags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) &&
206 ((dce
->DCXFlags
& DCX_CACHE
) || EndPaint
))
208 DceDeleteClipRgn(dce
);
211 if (dce
->DCXFlags
& DCX_CACHE
)
213 if (!(dce
->DCXFlags
& DCX_NORESETATTRS
))
215 /* make the DC clean so that SetDCState doesn't try to update the vis rgn */
216 IntGdiSetHookFlags(dce
->hDC
, DCHF_VALIDATEVISRGN
);
219 if (!IntGdiCleanDC(dce
->hDC
)) return 0;
221 if (dce
->DCXFlags
& DCX_DCEDIRTY
)
223 /* don't keep around invalidated entries
224 * because SetDCState() disables hVisRgn updates
225 * by removing dirty bit. */
226 dce
->hwndCurrent
= 0;
227 dce
->DCXFlags
&= DCX_CACHE
;
228 dce
->DCXFlags
|= DCX_DCEEMPTY
;
231 dce
->DCXFlags
&= ~DCX_DCEBUSY
;
232 DPRINT("Exit!!!!! DCX_CACHE!!!!!! hDC-> %x \n", dce
->hDC
);
233 if (!IntGdiSetDCOwnerEx( dce
->hDC
, GDI_OBJ_HMGR_NONE
, FALSE
))
235 dce
->ptiOwner
= NULL
; // Reset ownership.
236 dce
->ppiOwner
= NULL
;
238 #if 0 // Need to research and fix before this is a "growing" issue.
242 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
245 if (!(pDCE
->DCXFlags
& DCX_DCEBUSY
))
246 { /* Free the unused cache DCEs. */
247 pDCE
= DceFreeDCE(pDCE
, TRUE
);
252 while (pLE
!= &LEDce
);
256 return 1; // Released!
260 DceUpdateVisRgn(DCE
*Dce
, PWINDOW_OBJECT Window
, ULONG Flags
)
262 HANDLE hRgnVisible
= NULL
;
264 PWINDOW_OBJECT DesktopWindow
;
266 if (Flags
& DCX_PARENTCLIP
)
268 PWINDOW_OBJECT Parent
;
271 Parent
= Window
->spwndParent
;
278 ParentWnd
= Parent
->Wnd
;
280 if (ParentWnd
->style
& WS_CLIPSIBLINGS
)
282 DcxFlags
= DCX_CLIPSIBLINGS
|
283 (Flags
& ~(DCX_CLIPCHILDREN
| DCX_WINDOW
));
287 DcxFlags
= Flags
& ~(DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
| DCX_WINDOW
);
289 hRgnVisible
= DceGetVisRgn(Parent
, DcxFlags
, Window
->hSelf
, Flags
);
291 else if (Window
== NULL
)
293 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
294 if (NULL
!= DesktopWindow
)
296 hRgnVisible
= IntSysCreateRectRgnIndirect(&DesktopWindow
->Wnd
->rcWindow
);
305 hRgnVisible
= DceGetVisRgn(Window
, Flags
, 0, 0);
309 if (Flags
& DCX_INTERSECTRGN
)
311 if(Dce
->hrgnClip
!= NULL
)
313 NtGdiCombineRgn(hRgnVisible
, hRgnVisible
, Dce
->hrgnClip
, RGN_AND
);
317 if(hRgnVisible
!= NULL
)
319 REGION_FreeRgnByHandle(hRgnVisible
);
321 hRgnVisible
= IntSysCreateRectRgn(0, 0, 0, 0);
324 else if (Flags
& DCX_EXCLUDERGN
&& Dce
->hrgnClip
!= NULL
)
326 NtGdiCombineRgn(hRgnVisible
, hRgnVisible
, Dce
->hrgnClip
, RGN_DIFF
);
329 Dce
->DCXFlags
&= ~DCX_DCEDIRTY
;
330 GdiSelectVisRgn(Dce
->hDC
, hRgnVisible
);
334 IntEngWindowChanged(Window
, WOC_RGN_CLIENT
);
337 if (hRgnVisible
!= NULL
)
339 REGION_FreeRgnByHandle(hRgnVisible
);
344 UserGetDCEx(PWINDOW_OBJECT Window OPTIONAL
, HANDLE ClipRegion
, ULONG Flags
)
346 PWINDOW_OBJECT Parent
;
349 BOOL UpdateClipOrigin
= FALSE
;
357 Flags
&= ~DCX_USESTYLE
;
363 if (Flags
& (DCX_WINDOW
| DCX_PARENTCLIP
)) Flags
|= DCX_CACHE
;
365 // When GetDC is called with hWnd nz, DCX_CACHE & _WINDOW are clear w _USESTYLE set.
366 if (Flags
& DCX_USESTYLE
)
368 Flags
&= ~(DCX_CLIPCHILDREN
| DCX_CLIPSIBLINGS
| DCX_PARENTCLIP
);
369 if (!(Flags
& DCX_WINDOW
)) // not window rectangle
371 if (Wnd
->pcls
->style
& CS_PARENTDC
)
373 Flags
|= DCX_PARENTCLIP
;
376 if (!(Flags
& DCX_CACHE
) && // Not on the cheap wine list.
377 !(Wnd
->pcls
->style
& CS_OWNDC
) )
379 if (!(Wnd
->pcls
->style
& CS_CLASSDC
))
380 // The window is not POWNED or has any CLASS, so we are looking for cheap wine.
384 if (Wnd
->pcls
->pdce
) hDC
= ((PDCE
)Wnd
->pcls
->pdce
)->hDC
;
385 DPRINT("We have CLASS!!\n");
388 /* else // For Testing!
390 DPRINT1("We have POWNER!!\n");
391 if (Window->Dce) DPRINT1("We have POWNER with DCE!!\n");
394 if (Wnd
->style
& WS_CLIPSIBLINGS
)
396 Flags
|= DCX_CLIPSIBLINGS
;
399 if (Wnd
->style
& WS_CLIPCHILDREN
&&
400 !(Wnd
->style
& WS_MINIMIZE
))
402 Flags
|= DCX_CLIPCHILDREN
;
404 /* If minized with icon in the set, we are forced to be cheap! */
405 if (Wnd
->style
& WS_MINIMIZE
&&
413 if (Wnd
->style
& WS_CLIPSIBLINGS
) Flags
|= DCX_CLIPSIBLINGS
;
418 if (Flags
& DCX_WINDOW
) Flags
&= ~DCX_CLIPCHILDREN
;
420 if (Flags
& DCX_NOCLIPCHILDREN
)
423 Flags
&= ~(DCX_PARENTCLIP
| DCX_CLIPCHILDREN
);
426 Parent
= (Window
? Window
->spwndParent
: NULL
);
428 if (NULL
== Window
|| !(Wnd
->style
& WS_CHILD
) || NULL
== Parent
)
430 Flags
&= ~DCX_PARENTCLIP
;
431 Flags
|= DCX_CLIPSIBLINGS
;
434 /* it seems parent clip is ignored when clipping siblings or children */
435 if (Flags
& (DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
)) Flags
&= ~DCX_PARENTCLIP
;
437 if (Flags
& DCX_PARENTCLIP
)
439 if ((Wnd
->style
& WS_VISIBLE
) &&
440 (Parent
->Wnd
->style
& WS_VISIBLE
))
442 Flags
&= ~DCX_CLIPCHILDREN
;
443 if (Parent
->Wnd
->style
& WS_CLIPSIBLINGS
)
445 Flags
|= DCX_CLIPSIBLINGS
;
450 // Window nz, check to see if we still own this or it is just cheap wine tonight.
451 if (!(Flags
& DCX_CACHE
))
453 if ( Wnd
->head
.pti
!= GetW32ThreadInfo())
454 Flags
|= DCX_CACHE
; // Ah~ Not Powned! Forced to be cheap~
457 DcxFlags
= Flags
& DCX_CACHECOMPAREMASK
;
459 if (Flags
& DCX_CACHE
)
460 { // Scan the cheap wine list for our match.
461 DCE
* DceEmpty
= NULL
;
462 DCE
* DceUnused
= NULL
;
463 KeEnterCriticalRegion();
465 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
468 // The reason for this you may ask?
469 // Well, it seems ReactOS calls GetDC with out first creating a desktop DC window!
470 // Need to test for null here. Not sure if this is a bug or a feature.
471 // First time use hax, need to use DceAllocDCE during window display init.
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
== (Window
? Window
->hSelf
: NULL
) &&
485 ((Dce
->DCXFlags
& DCX_CACHECOMPAREMASK
) == DcxFlags
))
487 UpdateClipOrigin
= TRUE
;
491 pLE
= Dce
->List
.Flink
;
492 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
494 while (pLE
!= &LEDce
);
495 KeLeaveCriticalRegion();
497 Dce
= (DceEmpty
== NULL
) ? DceUnused
: DceEmpty
;
501 Dce
= DceAllocDCE(NULL
, DCE_CACHE_DC
);
503 if (!Dce
) return NULL
;
505 Dce
->hwndCurrent
= (Window
? Window
->hSelf
: NULL
);
507 else // If we are here, we are POWNED or having CLASS.
509 KeEnterCriticalRegion();
511 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
513 { // Check for Window handle than HDC match for CLASS.
514 if ((Dce
->hwndCurrent
== Window
->hSelf
) ||
517 pLE
= Dce
->List
.Flink
;
518 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
520 while (pLE
!= &LEDce
);
521 KeLeaveCriticalRegion();
523 if ( (Flags
& (DCX_INTERSECTRGN
|DCX_EXCLUDERGN
)) &&
524 (Dce
->DCXFlags
& (DCX_INTERSECTRGN
|DCX_EXCLUDERGN
)) )
526 DceDeleteClipRgn(Dce
);
529 // First time use hax, need to use DceAllocDCE during window display init.
535 if (!GDIOBJ_ValidateHandle(Dce
->hDC
, GDI_OBJECT_TYPE_DC
))
537 DPRINT1("FIXME: Got DCE with invalid hDC! 0x%x\n", Dce
->hDC
);
538 Dce
->hDC
= DceCreateDisplayDC();
539 /* FIXME: Handle error */
542 Dce
->DCXFlags
= Flags
| DCX_DCEBUSY
;
545 Bump it up! This prevents the random errors in wine dce tests and with
546 proper bits set in DCX_CACHECOMPAREMASK.
548 http://www.reactos.org/archives/public/ros-dev/2008-July/010498.html
549 http://www.reactos.org/archives/public/ros-dev/2008-July/010499.html
553 RemoveEntryList(&Dce
->List
);
554 InsertHeadList(&LEDce
, &Dce
->List
);
557 /* Introduced in rev 6691 and modified later. */
558 if ( (Flags
& DCX_INTERSECTUPDATE
) && !ClipRegion
)
560 Flags
|= DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
;
561 Dce
->DCXFlags
|= DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
;
562 ClipRegion
= Window
->hrgnUpdate
;
565 if (ClipRegion
== (HRGN
) 1)
567 if (!(Flags
& DCX_WINDOW
))
569 Dce
->hrgnClip
= IntSysCreateRectRgnIndirect(&Window
->Wnd
->rcClient
);
573 Dce
->hrgnClip
= IntSysCreateRectRgnIndirect(&Window
->Wnd
->rcWindow
);
575 Dce
->DCXFlags
&= ~DCX_KEEPCLIPRGN
;
577 else if (ClipRegion
!= NULL
)
579 if (Dce
->hrgnClip
!= NULL
)
581 DPRINT1("Should not be called!!\n");
582 GDIOBJ_FreeObjByHandle(Dce
->hrgnClip
, GDI_OBJECT_TYPE_REGION
|GDI_OBJECT_TYPE_SILENT
);
583 Dce
->hrgnClip
= NULL
;
585 Dce
->hrgnClip
= ClipRegion
;
588 DceSetDrawable(Window
, Dce
->hDC
, Flags
, UpdateClipOrigin
);
590 DceUpdateVisRgn(Dce
, Window
, Flags
);
592 if (Dce
->DCXFlags
& DCX_CACHE
)
594 DPRINT("ENTER!!!!!! DCX_CACHE!!!!!! hDC-> %x\n", Dce
->hDC
);
595 // Need to set ownership so Sync dcattr will work.
596 IntGdiSetDCOwnerEx( Dce
->hDC
, GDI_OBJ_HMGR_POWNED
, FALSE
);
597 Dce
->ptiOwner
= GetW32ThreadInfo(); // Set the temp owning
601 Wnd
->ExStyle
& WS_EX_LAYOUTRTL
&&
602 !(Flags
& DCX_KEEPLAYOUT
) )
604 NtGdiSetLayout(Dce
->hDC
, -1, LAYOUT_RTL
);
607 if (Dce
->DCXFlags
& DCX_PROCESSOWNED
)
609 ppi
= PsGetCurrentProcessWin32Process();
610 ppi
->W32PF_flags
|= W32PF_OWNDCCLEANUP
;
611 Dce
->ptiOwner
= NULL
;
618 /***********************************************************************
622 DceFreeDCE(PDCE pdce
, BOOLEAN Force
)
628 if (NULL
== pdce
) return NULL
;
630 pLE
= pdce
->List
.Flink
;
631 ret
= CONTAINING_RECORD(pLE
, DCE
, List
);
633 pdce
->DCXFlags
|= DCX_INDESTROY
;
635 if (Force
&& !GDIOBJ_OwnedByCurrentProcess(pdce
->hDC
))
637 DPRINT("Change ownership for DCE! -> %x\n" , pdce
);
638 // Note: Windows sets W32PF_OWNDCCLEANUP and moves on.
639 if (!IsObjectDead((HGDIOBJ
) pdce
->hDC
))
641 DC_SetOwnership( pdce
->hDC
, PsGetCurrentProcess());
645 DPRINT1("Attempted to change ownership of an DCEhDC 0x%x currently being destroyed!!!\n",pdce
->hDC
);
651 if (!GreGetObjectOwner(pdce
->hDC
, GDIObjType_DC_TYPE
))
652 DC_SetOwnership( pdce
->hDC
, PsGetCurrentProcess());
655 if (!Hit
) IntGdiDeleteDC(pdce
->hDC
, TRUE
);
657 if (pdce
->hrgnClip
&& !(pdce
->DCXFlags
& DCX_KEEPCLIPRGN
))
659 GDIOBJ_FreeObjByHandle(pdce
->hrgnClip
, GDI_OBJECT_TYPE_REGION
|GDI_OBJECT_TYPE_SILENT
);
660 pdce
->hrgnClip
= NULL
;
663 RemoveEntryList(&pdce
->List
);
665 if (IsListEmpty(&pdce
->List
))
667 DPRINT1("List is Empty! DCE! -> %x\n" , pdce
);
671 ExFreePoolWithTag(pdce
, TAG_PDCE
);
674 DPRINT("Freed DCE's! %d \n", DCECount
);
679 /***********************************************************************
682 * Remove owned DCE and reset unreleased cache DCEs.
685 DceFreeWindowDCE(PWINDOW_OBJECT Window
)
692 DPRINT1("FreeWindowDCE No Entry! %d\n",DCECount
);
697 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
702 DPRINT1("FreeWindowDCE No DCE Pointer!\n");
705 if (IsListEmpty(&pDCE
->List
))
707 DPRINT1("FreeWindowDCE List is Empty!!!!\n");
710 if ( pDCE
->hwndCurrent
== Window
->hSelf
&&
711 !(pDCE
->DCXFlags
& DCX_DCEEMPTY
) )
713 if (!(pDCE
->DCXFlags
& DCX_CACHE
)) /* owned or Class DCE*/
715 if (Window
->Wnd
->pcls
->style
& CS_CLASSDC
) /* Test Class first */
717 if (pDCE
->DCXFlags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) /* Class DCE*/
718 DceDeleteClipRgn(pDCE
);
719 // Update and reset Vis Rgn and clear the dirty bit.
720 // Should release VisRgn than reset it to default.
721 DceUpdateVisRgn(pDCE
, Window
, pDCE
->DCXFlags
);
722 pDCE
->DCXFlags
= DCX_DCEEMPTY
|DCX_CACHE
;
723 pDCE
->hwndCurrent
= 0;
725 DPRINT("POWNED DCE going Cheap!! DCX_CACHE!! hDC-> %x \n", pDCE
->hDC
);
726 if (!IntGdiSetDCOwnerEx( pDCE
->hDC
, GDI_OBJ_HMGR_NONE
, FALSE
))
728 DPRINT1("Fail Owner Switch hDC-> %x \n", pDCE
->hDC
);
731 /* Do not change owner so thread can clean up! */
733 else if (Window
->Wnd
->pcls
->style
& CS_OWNDC
) /* owned DCE*/
735 pDCE
= DceFreeDCE(pDCE
, FALSE
);
741 DPRINT1("Not POWNED or CLASSDC hwndCurrent -> %x \n", pDCE
->hwndCurrent
);
747 if (pDCE
->DCXFlags
& DCX_DCEBUSY
) /* shared cache DCE */
749 /* FIXME: AFAICS we are doing the right thing here so
750 * this should be a DPRINT. But this is best left as an ERR
751 * because the 'application error' is likely to come from
752 * another part of Wine (i.e. it's our fault after all).
753 * We should change this to DPRINT when ReactOS is more stable
756 DPRINT1("[%p] GetDC() without ReleaseDC()!\n", Window
->hSelf
);
757 DceReleaseDC(pDCE
, FALSE
);
759 pDCE
->DCXFlags
|= DCX_DCEEMPTY
;
760 pDCE
->hwndCurrent
= 0;
763 pLE
= pDCE
->List
.Flink
;
764 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
766 while (pLE
!= &LEDce
);
770 DceFreeClassDCE(HDC hDC
)
775 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
780 if (pDCE
->hDC
== hDC
)
782 pDCE
= DceFreeDCE(pDCE
, TRUE
); // Might have gone cheap!
786 pLE
= pDCE
->List
.Flink
;
787 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
789 while (pLE
!= &LEDce
);
793 DceFreeThreadDCE(PTHREADINFO pti
)
798 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
803 if (pDCE
->ptiOwner
== pti
)
805 if (pDCE
->DCXFlags
& DCX_CACHE
)
807 pDCE
= DceFreeDCE(pDCE
, TRUE
);
812 pLE
= pDCE
->List
.Flink
;
813 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
815 while (pLE
!= &LEDce
);
824 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
829 pDCE
= DceFreeDCE(pDCE
, TRUE
);
832 while (pLE
!= &LEDce
);
836 DceResetActiveDCEs(PWINDOW_OBJECT Window
)
840 PWINDOW_OBJECT CurrentWindow
;
850 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
851 if(!pDCE
) return; // Another null test!
855 if(pLE
== &LEDce
) break;
856 if (0 == (pDCE
->DCXFlags
& (DCX_DCEEMPTY
|DCX_INDESTROY
)))
858 if (Window
->hSelf
== pDCE
->hwndCurrent
)
860 CurrentWindow
= Window
;
864 CurrentWindow
= UserGetWindowObject(pDCE
->hwndCurrent
);
865 if (NULL
== CurrentWindow
)
867 pLE
= pDCE
->List
.Flink
;
868 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
873 if (!GDIOBJ_ValidateHandle(pDCE
->hDC
, GDI_OBJECT_TYPE_DC
) ||
874 (dc
= DC_LockDc(pDCE
->hDC
)) == NULL
)
876 pLE
= pDCE
->List
.Flink
;
877 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
880 if (Window
== CurrentWindow
|| IntIsChildWindow(Window
, CurrentWindow
))
882 if (pDCE
->DCXFlags
& DCX_WINDOW
)
884 DeltaX
= CurrentWindow
->Wnd
->rcWindow
.left
- dc
->ptlDCOrig
.x
;
885 DeltaY
= CurrentWindow
->Wnd
->rcWindow
.top
- dc
->ptlDCOrig
.y
;
886 dc
->ptlDCOrig
.x
= CurrentWindow
->Wnd
->rcWindow
.left
;
887 dc
->ptlDCOrig
.y
= CurrentWindow
->Wnd
->rcWindow
.top
;
891 DeltaX
= CurrentWindow
->Wnd
->rcClient
.left
- dc
->ptlDCOrig
.x
;
892 DeltaY
= CurrentWindow
->Wnd
->rcClient
.top
- dc
->ptlDCOrig
.y
;
893 dc
->ptlDCOrig
.x
= CurrentWindow
->Wnd
->rcClient
.left
;
894 dc
->ptlDCOrig
.y
= CurrentWindow
->Wnd
->rcClient
.top
;
896 if (NULL
!= dc
->rosdc
.hClipRgn
)
898 NtGdiOffsetRgn(dc
->rosdc
.hClipRgn
, DeltaX
, DeltaY
);
899 CLIPPING_UpdateGCRegion(dc
);
901 if (NULL
!= pDCE
->hrgnClip
)
903 NtGdiOffsetRgn(pDCE
->hrgnClip
, DeltaX
, DeltaY
);
908 DceUpdateVisRgn(pDCE
, CurrentWindow
, pDCE
->DCXFlags
);
910 if (Window
->hSelf
!= pDCE
->hwndCurrent
)
912 // IntEngWindowChanged(CurrentWindow, WOC_RGN_CLIENT);
913 // UserDerefObject(CurrentWindow);
916 pLE
= pDCE
->List
.Flink
;
917 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
919 while (pLE
!= &LEDce
);
923 IntWindowFromDC(HDC hDc
)
930 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
935 if (Dce
->DCXFlags
& DCX_INDESTROY
)
938 Ret
= Dce
->hwndCurrent
;
941 pLE
= Dce
->List
.Flink
;
942 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
944 while (pLE
!= &LEDce
);
949 UserReleaseDC(PWINDOW_OBJECT Window
, HDC hDc
, BOOL EndPaint
)
956 DPRINT("%p %p\n", Window
, hDc
);
958 dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
967 pLE
= dce
->List
.Flink
;
968 dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
970 while (pLE
!= &LEDce
);
972 if ( Hit
&& (dce
->DCXFlags
& DCX_DCEBUSY
))
974 nRet
= DceReleaseDC(dce
, EndPaint
);
981 UserGetWindowDC(PWINDOW_OBJECT Wnd
)
983 return UserGetDCEx(Wnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
987 UserGethWnd( HDC hdc
, PWNDOBJ
*pwndo
)
993 hWnd
= IntWindowFromDC(hdc
);
995 if (hWnd
&& !(Wnd
= UserGetWindowObject(hWnd
)))
997 pWndgdi
= (WNDGDI
*)IntGetProp(Wnd
, AtomWndObj
);
999 if ( pWndgdi
&& pWndgdi
->Hwnd
== hWnd
)
1001 if (pwndo
) *pwndo
= (PWNDOBJ
)pWndgdi
;
1008 NtUserGetDCEx(HWND hWnd OPTIONAL
, HANDLE ClipRegion
, ULONG Flags
)
1010 PWINDOW_OBJECT Wnd
=NULL
;
1011 DECLARE_RETURN(HDC
);
1013 DPRINT("Enter NtUserGetDCEx\n");
1014 UserEnterExclusive();
1016 if (hWnd
&& !(Wnd
= UserGetWindowObject(hWnd
)))
1020 RETURN( UserGetDCEx(Wnd
, ClipRegion
, Flags
));
1023 DPRINT("Leave NtUserGetDCEx, ret=%i\n",_ret_
);
1031 * The NtUserGetWindowDC function retrieves the device context (DC) for the
1032 * entire window, including title bar, menus, and scroll bars. A window device
1033 * context permits painting anywhere in a window, because the origin of the
1034 * device context is the upper-left corner of the window instead of the client
1041 NtUserGetWindowDC(HWND hWnd
)
1043 return NtUserGetDCEx(hWnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
1047 NtUserGetDC(HWND hWnd
)
1049 DPRINT("NtUGetDC -> %x:%x\n", hWnd
, !hWnd
? DCX_CACHE
| DCX_WINDOW
: DCX_USESTYLE
);
1051 return NtUserGetDCEx(hWnd
, NULL
, NULL
== hWnd
? DCX_CACHE
| DCX_WINDOW
: DCX_USESTYLE
);
1055 * Select logical palette into device context.
1056 * \param hDC handle to the device context
1057 * \param hpal handle to the palette
1058 * \param ForceBackground If this value is FALSE the logical palette will be copied to the device palette only when the applicatioon
1059 * is in the foreground. If this value is TRUE then map the colors in the logical palette to the device
1060 * palette colors in the best way.
1061 * \return old palette
1063 * \todo implement ForceBackground == TRUE
1067 NtUserSelectPalette(HDC hDC
,
1069 BOOL ForceBackground
)
1072 UserEnterExclusive();
1073 // Implement window checks
1074 oldPal
= GdiSelectPalette( hDC
, hpal
, ForceBackground
);