2 * PROJECT: ReactOS Win32k subsystem
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 Team
10 DBG_DEFAULT_CHANNEL(UserDce
);
12 /* GLOBALS *******************************************************************/
14 /* NOTE: I think we should store this per window station (including GDI objects) */
15 /* Answer: No, use the DCE pMonitor to compare with! */
17 static LIST_ENTRY LEDce
;
18 static INT DCECount
= 0; // Count of DCE in system.
20 #define DCX_CACHECOMPAREMASK (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN | \
21 DCX_NORESETATTRS | DCX_LOCKWINDOWUPDATE | \
22 DCX_LAYEREDWIN | DCX_CACHE | DCX_WINDOW | \
25 /* FUNCTIONS *****************************************************************/
32 InitializeListHead(&LEDce
);
33 return STATUS_SUCCESS
;
37 // This should be moved to dc.c or dcutil.c.
40 DceCreateDisplayDC(VOID
)
42 UNICODE_STRING DriverName
= RTL_CONSTANT_STRING(L
"DISPLAY");
44 co_IntGraphicsCheck(TRUE
);
46 return IntGdiCreateDC(&DriverName
, NULL
, NULL
, NULL
, FALSE
);
51 DceGetVisRgn(PWND Window
, ULONG Flags
, HWND hWndChild
, ULONG CFlags
)
55 VisRgn
= VIS_ComputeVisibleRegion( Window
,
56 0 == (Flags
& DCX_WINDOW
),
57 0 != (Flags
& DCX_CLIPCHILDREN
),
58 0 != (Flags
& DCX_CLIPSIBLINGS
));
61 VisRgn
= IntSysCreateRectRgn(0, 0, 0, 0);
67 DceAllocDCE(PWND Window OPTIONAL
, DCE_TYPE Type
)
71 pDce
= ExAllocatePoolWithTag(PagedPool
, sizeof(DCE
), USERTAG_DCE
);
75 pDce
->hDC
= DceCreateDisplayDC();
78 ExFreePoolWithTag(pDce
, USERTAG_DCE
);
82 TRACE("Alloc DCE's! %d\n",DCECount
);
83 pDce
->hwndCurrent
= (Window
? Window
->head
.h
: NULL
);
84 pDce
->pwndOrg
= Window
;
85 pDce
->pwndClip
= Window
;
86 pDce
->hrgnClip
= NULL
;
87 pDce
->hrgnClipPublic
= NULL
;
88 pDce
->hrgnSavedVis
= NULL
;
89 pDce
->ppiOwner
= NULL
;
91 InsertTailList(&LEDce
, &pDce
->List
);
93 DCU_SetDcUndeletable(pDce
->hDC
);
95 if (Type
== DCE_WINDOW_DC
|| Type
== DCE_CLASS_DC
) // Window DCE have ownership.
97 pDce
->ptiOwner
= GetW32ThreadInfo();
101 TRACE("FREE DCATTR!!!! NOT DCE_WINDOW_DC!!!!! hDC-> %x\n", pDce
->hDC
);
102 GreSetDCOwner(pDce
->hDC
, GDI_OBJ_HMGR_NONE
);
103 pDce
->ptiOwner
= NULL
;
106 if (Type
== DCE_CACHE_DC
)
108 pDce
->DCXFlags
= DCX_CACHE
| DCX_DCEEMPTY
;
112 pDce
->DCXFlags
= DCX_DCEBUSY
;
115 if (Type
== DCE_WINDOW_DC
)
117 if (Window
->style
& WS_CLIPCHILDREN
) pDce
->DCXFlags
|= DCX_CLIPCHILDREN
;
118 if (Window
->style
& WS_CLIPSIBLINGS
) pDce
->DCXFlags
|= DCX_CLIPSIBLINGS
;
126 DceSetDrawable( PWND Window OPTIONAL
,
131 DC
*dc
= DC_LockDc(hDC
);
142 if (Flags
& DCX_WINDOW
)
144 dc
->ptlDCOrig
.x
= Window
->rcWindow
.left
;
145 dc
->ptlDCOrig
.y
= Window
->rcWindow
.top
;
149 dc
->ptlDCOrig
.x
= Window
->rcClient
.left
;
150 dc
->ptlDCOrig
.y
= Window
->rcClient
.top
;
158 DceDeleteClipRgn(DCE
* Dce
)
160 Dce
->DCXFlags
&= ~(DCX_EXCLUDERGN
| DCX_INTERSECTRGN
);
162 if (Dce
->DCXFlags
& DCX_KEEPCLIPRGN
)
164 Dce
->DCXFlags
&= ~DCX_KEEPCLIPRGN
;
166 else if (Dce
->hrgnClip
!= NULL
)
168 GreDeleteObject(Dce
->hrgnClip
);
171 Dce
->hrgnClip
= NULL
;
173 /* Make it dirty so that the vis rgn gets recomputed next time */
174 Dce
->DCXFlags
|= DCX_DCEDIRTY
;
178 DceReleaseDC(DCE
* dce
, BOOL EndPaint
)
180 if (DCX_DCEBUSY
!= (dce
->DCXFlags
& (DCX_INDESTROY
| DCX_DCEEMPTY
| DCX_DCEBUSY
)))
185 /* Restore previous visible region */
186 if ((dce
->DCXFlags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) &&
187 ((dce
->DCXFlags
& DCX_CACHE
) || EndPaint
))
189 DceDeleteClipRgn(dce
);
192 if (dce
->DCXFlags
& DCX_CACHE
)
194 if (!(dce
->DCXFlags
& DCX_NORESETATTRS
))
196 /* Make the DC clean so that SetDCState doesn't try to update the vis rgn */
197 IntGdiSetHookFlags(dce
->hDC
, DCHF_VALIDATEVISRGN
);
200 if (!IntGdiCleanDC(dce
->hDC
)) return 0;
202 if (dce
->DCXFlags
& DCX_DCEDIRTY
)
204 /* Don't keep around invalidated entries
205 * because SetDCState() disables hVisRgn updates
206 * by removing dirty bit. */
207 dce
->hwndCurrent
= 0;
208 dce
->DCXFlags
&= DCX_CACHE
;
209 dce
->DCXFlags
|= DCX_DCEEMPTY
;
212 dce
->DCXFlags
&= ~DCX_DCEBUSY
;
213 TRACE("Exit!!!!! DCX_CACHE!!!!!! hDC-> %x \n", dce
->hDC
);
214 if (!GreSetDCOwner(dce
->hDC
, GDI_OBJ_HMGR_NONE
))
216 dce
->ptiOwner
= NULL
; // Reset ownership.
217 dce
->ppiOwner
= NULL
;
219 #if 0 // Need to research and fix before this is a "growing" issue.
223 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
226 if (!(pDCE
->DCXFlags
& DCX_DCEBUSY
))
227 { /* Free the unused cache DCEs. */
228 pDCE
= DceFreeDCE(pDCE
, TRUE
);
233 while (pLE
!= &LEDce
);
237 return 1; // Released!
241 DceUpdateVisRgn(DCE
*Dce
, PWND Window
, ULONG Flags
)
243 HANDLE hRgnVisible
= NULL
;
247 if (Flags
& DCX_PARENTCLIP
)
251 Parent
= Window
->spwndParent
;
258 if (Parent
->style
& WS_CLIPSIBLINGS
)
260 DcxFlags
= DCX_CLIPSIBLINGS
|
261 (Flags
& ~(DCX_CLIPCHILDREN
| DCX_WINDOW
));
265 DcxFlags
= Flags
& ~(DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
| DCX_WINDOW
);
267 hRgnVisible
= DceGetVisRgn(Parent
, DcxFlags
, Window
->head
.h
, Flags
);
269 else if (Window
== NULL
)
271 DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow());
272 if (NULL
!= DesktopWindow
)
274 hRgnVisible
= IntSysCreateRectRgnIndirect(&DesktopWindow
->rcWindow
);
283 hRgnVisible
= DceGetVisRgn(Window
, Flags
, 0, 0);
287 if (Flags
& DCX_INTERSECTRGN
)
289 if(Dce
->hrgnClip
!= NULL
)
291 NtGdiCombineRgn(hRgnVisible
, hRgnVisible
, Dce
->hrgnClip
, RGN_AND
);
295 if(hRgnVisible
!= NULL
)
297 GreDeleteObject(hRgnVisible
);
299 hRgnVisible
= IntSysCreateRectRgn(0, 0, 0, 0);
302 else if (Flags
& DCX_EXCLUDERGN
&& Dce
->hrgnClip
!= NULL
)
304 NtGdiCombineRgn(hRgnVisible
, hRgnVisible
, Dce
->hrgnClip
, RGN_DIFF
);
307 Dce
->DCXFlags
&= ~DCX_DCEDIRTY
;
308 GdiSelectVisRgn(Dce
->hDC
, hRgnVisible
);
312 IntEngWindowChanged(Window
, WOC_RGN_CLIENT
);
315 if (hRgnVisible
!= NULL
)
317 GreDeleteObject(hRgnVisible
);
322 UserGetDCEx(PWND Wnd OPTIONAL
, HANDLE ClipRegion
, ULONG Flags
)
327 BOOL UpdateClipOrigin
= FALSE
;
334 Flags
&= ~DCX_USESTYLE
;
338 if (Flags
& (DCX_WINDOW
| DCX_PARENTCLIP
)) Flags
|= DCX_CACHE
;
340 // When GetDC is called with hWnd nz, DCX_CACHE & _WINDOW are clear w _USESTYLE set.
341 if (Flags
& DCX_USESTYLE
)
343 Flags
&= ~(DCX_CLIPCHILDREN
| DCX_CLIPSIBLINGS
| DCX_PARENTCLIP
);
344 if (!(Flags
& DCX_WINDOW
)) // Not window rectangle
346 if (Wnd
->pcls
->style
& CS_PARENTDC
)
348 Flags
|= DCX_PARENTCLIP
;
351 if (!(Flags
& DCX_CACHE
) && // Not on the cheap wine list.
352 !(Wnd
->pcls
->style
& CS_OWNDC
) )
354 if (!(Wnd
->pcls
->style
& CS_CLASSDC
))
355 // The window is not POWNED or has any CLASS, so we are looking for cheap wine.
359 if (Wnd
->pcls
->pdce
) hDC
= ((PDCE
)Wnd
->pcls
->pdce
)->hDC
;
360 TRACE("We have CLASS!!\n");
363 /* else // For Testing!
365 DPRINT1("We have POWNER!!\n");
366 if (Window->Dce) DPRINT1("We have POWNER with DCE!!\n");
369 if (Wnd
->style
& WS_CLIPSIBLINGS
)
371 Flags
|= DCX_CLIPSIBLINGS
;
374 if (Wnd
->style
& WS_CLIPCHILDREN
&&
375 !(Wnd
->style
& WS_MINIMIZE
))
377 Flags
|= DCX_CLIPCHILDREN
;
379 /* If minized with icon in the set, we are forced to be cheap! */
380 if (Wnd
->style
& WS_MINIMIZE
&&
388 if (Wnd
->style
& WS_CLIPSIBLINGS
) Flags
|= DCX_CLIPSIBLINGS
;
393 if (Flags
& DCX_WINDOW
) Flags
&= ~DCX_CLIPCHILDREN
;
395 if (Flags
& DCX_NOCLIPCHILDREN
)
398 Flags
&= ~(DCX_PARENTCLIP
| DCX_CLIPCHILDREN
);
401 Parent
= (Wnd
? Wnd
->spwndParent
: NULL
);
403 if (NULL
== Wnd
|| !(Wnd
->style
& WS_CHILD
) || NULL
== Parent
)
405 Flags
&= ~DCX_PARENTCLIP
;
406 Flags
|= DCX_CLIPSIBLINGS
;
409 /* It seems parent clip is ignored when clipping siblings or children */
410 if (Flags
& (DCX_CLIPSIBLINGS
| DCX_CLIPCHILDREN
)) Flags
&= ~DCX_PARENTCLIP
;
412 if (Flags
& DCX_PARENTCLIP
)
414 if ((Wnd
->style
& WS_VISIBLE
) &&
415 (Parent
->style
& WS_VISIBLE
))
417 Flags
&= ~DCX_CLIPCHILDREN
;
418 if (Parent
->style
& WS_CLIPSIBLINGS
)
420 Flags
|= DCX_CLIPSIBLINGS
;
425 // Window nz, check to see if we still own this or it is just cheap wine tonight.
426 if (!(Flags
& DCX_CACHE
))
428 if ( Wnd
->head
.pti
!= GetW32ThreadInfo())
429 Flags
|= DCX_CACHE
; // Ah~ Not Powned! Forced to be cheap~
432 DcxFlags
= Flags
& DCX_CACHECOMPAREMASK
;
434 if (Flags
& DCX_CACHE
)
435 { // Scan the cheap wine list for our match.
436 DCE
* DceEmpty
= NULL
;
437 DCE
* DceUnused
= NULL
;
438 KeEnterCriticalRegion();
440 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
443 // The reason for this you may ask?
444 // Well, it seems ReactOS calls GetDC with out first creating a desktop DC window!
445 // Need to test for null here. Not sure if this is a bug or a feature.
446 // First time use hax, need to use DceAllocDCE during window display init.
449 // The way I understand this, you can have more than one DC per window.
450 // Only one Owned if one was requested and saved and one Cached.
452 if ((Dce
->DCXFlags
& (DCX_CACHE
| DCX_DCEBUSY
)) == DCX_CACHE
)
455 if (Dce
->DCXFlags
& DCX_DCEEMPTY
)
459 else if (Dce
->hwndCurrent
== (Wnd
? Wnd
->head
.h
: NULL
) &&
460 ((Dce
->DCXFlags
& DCX_CACHECOMPAREMASK
) == DcxFlags
))
462 UpdateClipOrigin
= TRUE
;
466 pLE
= Dce
->List
.Flink
;
467 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
469 while (pLE
!= &LEDce
);
470 KeLeaveCriticalRegion();
472 Dce
= (DceEmpty
== NULL
) ? DceUnused
: DceEmpty
;
476 Dce
= DceAllocDCE(NULL
, DCE_CACHE_DC
);
478 if (!Dce
) return NULL
;
480 Dce
->hwndCurrent
= (Wnd
? Wnd
->head
.h
: NULL
);
482 else // If we are here, we are POWNED or having CLASS.
484 KeEnterCriticalRegion();
486 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
488 { // Check for Window handle than HDC match for CLASS.
489 if ((Dce
->hwndCurrent
== Wnd
->head
.h
) ||
492 pLE
= Dce
->List
.Flink
;
493 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
495 while (pLE
!= &LEDce
);
496 KeLeaveCriticalRegion();
498 if ( (Flags
& (DCX_INTERSECTRGN
|DCX_EXCLUDERGN
)) &&
499 (Dce
->DCXFlags
& (DCX_INTERSECTRGN
|DCX_EXCLUDERGN
)) )
501 DceDeleteClipRgn(Dce
);
504 // First time use hax, need to use DceAllocDCE during window display init.
510 if (!GreIsHandleValid(Dce
->hDC
))
512 ERR("FIXME: Got DCE with invalid hDC! 0x%x\n", Dce
->hDC
);
513 Dce
->hDC
= DceCreateDisplayDC();
514 /* FIXME: Handle error */
517 Dce
->DCXFlags
= Flags
| DCX_DCEBUSY
;
520 * Bump it up! This prevents the random errors in wine dce tests and with
521 * proper bits set in DCX_CACHECOMPAREMASK.
523 * http://www.reactos.org/archives/public/ros-dev/2008-July/010498.html
524 * http://www.reactos.org/archives/public/ros-dev/2008-July/010499.html
528 RemoveEntryList(&Dce
->List
);
529 InsertHeadList(&LEDce
, &Dce
->List
);
532 /* Introduced in rev 6691 and modified later. */
533 if ( (Flags
& DCX_INTERSECTUPDATE
) && !ClipRegion
)
535 Flags
|= DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
;
536 Dce
->DCXFlags
|= DCX_INTERSECTRGN
| DCX_KEEPCLIPRGN
;
537 ClipRegion
= Wnd
->hrgnUpdate
;
540 if (ClipRegion
== HRGN_WINDOW
)
542 if (!(Flags
& DCX_WINDOW
))
544 Dce
->hrgnClip
= IntSysCreateRectRgnIndirect(&Wnd
->rcClient
);
548 Dce
->hrgnClip
= IntSysCreateRectRgnIndirect(&Wnd
->rcWindow
);
550 Dce
->DCXFlags
&= ~DCX_KEEPCLIPRGN
;
552 else if (ClipRegion
!= NULL
)
554 if (Dce
->hrgnClip
!= NULL
)
556 ERR("Should not be called!!\n");
557 GreDeleteObject(Dce
->hrgnClip
);
558 Dce
->hrgnClip
= NULL
;
560 Dce
->hrgnClip
= ClipRegion
;
563 DceSetDrawable(Wnd
, Dce
->hDC
, Flags
, UpdateClipOrigin
);
565 DceUpdateVisRgn(Dce
, Wnd
, Flags
);
567 if (Dce
->DCXFlags
& DCX_CACHE
)
569 TRACE("ENTER!!!!!! DCX_CACHE!!!!!! hDC-> %x\n", Dce
->hDC
);
570 // Need to set ownership so Sync dcattr will work.
571 GreSetDCOwner(Dce
->hDC
, GDI_OBJ_HMGR_POWNED
);
572 Dce
->ptiOwner
= GetW32ThreadInfo(); // Set the temp owning
576 Wnd
->ExStyle
& WS_EX_LAYOUTRTL
&&
577 !(Flags
& DCX_KEEPLAYOUT
) )
579 NtGdiSetLayout(Dce
->hDC
, -1, LAYOUT_RTL
);
582 if (Dce
->DCXFlags
& DCX_PROCESSOWNED
)
584 ppi
= PsGetCurrentProcessWin32Process();
585 ppi
->W32PF_flags
|= W32PF_OWNDCCLEANUP
;
586 Dce
->ptiOwner
= NULL
;
593 /***********************************************************************
597 DceFreeDCE(PDCE pdce
, BOOLEAN Force
)
603 if (NULL
== pdce
) return NULL
;
605 pLE
= pdce
->List
.Flink
;
606 ret
= CONTAINING_RECORD(pLE
, DCE
, List
);
608 pdce
->DCXFlags
|= DCX_INDESTROY
;
611 GreGetObjectOwner(pdce
->hDC
) != GDI_OBJ_HMGR_POWNED
)
613 TRACE("Change ownership for DCE! -> %x\n" , pdce
);
614 // NOTE: Windows sets W32PF_OWNDCCLEANUP and moves on.
615 if (GreIsHandleValid(pdce
->hDC
))
617 GreSetDCOwner(pdce
->hDC
, GDI_OBJ_HMGR_POWNED
);
621 ERR("Attempted to change ownership of an DCEhDC 0x%x currently being destroyed!!!\n",pdce
->hDC
);
627 if (GreGetObjectOwner(pdce
->hDC
) == GDI_OBJ_HMGR_PUBLIC
)
628 GreSetDCOwner(pdce
->hDC
, GDI_OBJ_HMGR_POWNED
);
631 if (!Hit
) IntGdiDeleteDC(pdce
->hDC
, TRUE
);
633 if (pdce
->hrgnClip
&& !(pdce
->DCXFlags
& DCX_KEEPCLIPRGN
))
635 GreDeleteObject(pdce
->hrgnClip
);
636 pdce
->hrgnClip
= NULL
;
639 RemoveEntryList(&pdce
->List
);
641 if (IsListEmpty(&pdce
->List
))
643 ERR("List is Empty! DCE! -> %x\n" , pdce
);
647 ExFreePoolWithTag(pdce
, USERTAG_DCE
);
650 TRACE("Freed DCE's! %d \n", DCECount
);
655 /***********************************************************************
658 * Remove owned DCE and reset unreleased cache DCEs.
661 DceFreeWindowDCE(PWND Window
)
668 ERR("FreeWindowDCE No Entry! %d\n",DCECount
);
673 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
678 ERR("FreeWindowDCE No DCE Pointer!\n");
681 if (IsListEmpty(&pDCE
->List
))
683 ERR("FreeWindowDCE List is Empty!!!!\n");
686 if ( pDCE
->hwndCurrent
== Window
->head
.h
&&
687 !(pDCE
->DCXFlags
& DCX_DCEEMPTY
) )
689 if (!(pDCE
->DCXFlags
& DCX_CACHE
)) /* Owned or Class DCE */
691 if (Window
->pcls
->style
& CS_CLASSDC
) /* Test Class first */
693 if (pDCE
->DCXFlags
& (DCX_INTERSECTRGN
| DCX_EXCLUDERGN
)) /* Class DCE */
694 DceDeleteClipRgn(pDCE
);
695 // Update and reset Vis Rgn and clear the dirty bit.
696 // Should release VisRgn than reset it to default.
697 DceUpdateVisRgn(pDCE
, Window
, pDCE
->DCXFlags
);
698 pDCE
->DCXFlags
= DCX_DCEEMPTY
|DCX_CACHE
;
699 pDCE
->hwndCurrent
= 0;
701 TRACE("POWNED DCE going Cheap!! DCX_CACHE!! hDC-> %x \n", pDCE
->hDC
);
702 if (!GreSetDCOwner( pDCE
->hDC
, GDI_OBJ_HMGR_NONE
))
704 ERR("Fail Owner Switch hDC-> %x \n", pDCE
->hDC
);
707 /* Do not change owner so thread can clean up! */
709 else if (Window
->pcls
->style
& CS_OWNDC
) /* Owned DCE */
711 pDCE
= DceFreeDCE(pDCE
, FALSE
);
717 ERR("Not POWNED or CLASSDC hwndCurrent -> %x \n", pDCE
->hwndCurrent
);
718 // ASSERT(FALSE); /* bug 5320 */
723 if (pDCE
->DCXFlags
& DCX_DCEBUSY
) /* Shared cache DCE */
725 /* FIXME: AFAICS we are doing the right thing here so
726 * this should be a TRACE. But this is best left as an ERR
727 * because the 'application error' is likely to come from
728 * another part of Wine (i.e. it's our fault after all).
729 * We should change this to TRACE when ReactOS is more stable
732 ERR("[%p] GetDC() without ReleaseDC()!\n", Window
->head
.h
);
733 DceReleaseDC(pDCE
, FALSE
);
735 pDCE
->DCXFlags
|= DCX_DCEEMPTY
;
736 pDCE
->hwndCurrent
= 0;
739 pLE
= pDCE
->List
.Flink
;
740 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
742 while (pLE
!= &LEDce
);
746 DceFreeClassDCE(HDC hDC
)
751 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
756 if (pDCE
->hDC
== hDC
)
758 pDCE
= DceFreeDCE(pDCE
, TRUE
); // Might have gone cheap!
762 pLE
= pDCE
->List
.Flink
;
763 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
765 while (pLE
!= &LEDce
);
769 DceFreeThreadDCE(PTHREADINFO pti
)
774 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
779 if (pDCE
->ptiOwner
== pti
)
781 if (pDCE
->DCXFlags
& DCX_CACHE
)
783 pDCE
= DceFreeDCE(pDCE
, TRUE
);
788 pLE
= pDCE
->List
.Flink
;
789 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
791 while (pLE
!= &LEDce
);
800 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
805 pDCE
= DceFreeDCE(pDCE
, TRUE
);
808 while (pLE
!= &LEDce
);
812 DceResetActiveDCEs(PWND Window
)
826 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
831 if(pLE
== &LEDce
) break;
832 if (0 == (pDCE
->DCXFlags
& (DCX_DCEEMPTY
|DCX_INDESTROY
)))
834 if (Window
->head
.h
== pDCE
->hwndCurrent
)
836 CurrentWindow
= Window
;
840 CurrentWindow
= UserGetWindowObject(pDCE
->hwndCurrent
);
841 if (NULL
== CurrentWindow
)
843 pLE
= pDCE
->List
.Flink
;
844 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
849 if (!GreIsHandleValid(pDCE
->hDC
) ||
850 (dc
= DC_LockDc(pDCE
->hDC
)) == NULL
)
852 pLE
= pDCE
->List
.Flink
;
853 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
856 if (Window
== CurrentWindow
|| IntIsChildWindow(Window
, CurrentWindow
))
858 if (pDCE
->DCXFlags
& DCX_WINDOW
)
860 DeltaX
= CurrentWindow
->rcWindow
.left
- dc
->ptlDCOrig
.x
;
861 DeltaY
= CurrentWindow
->rcWindow
.top
- dc
->ptlDCOrig
.y
;
862 dc
->ptlDCOrig
.x
= CurrentWindow
->rcWindow
.left
;
863 dc
->ptlDCOrig
.y
= CurrentWindow
->rcWindow
.top
;
867 DeltaX
= CurrentWindow
->rcClient
.left
- dc
->ptlDCOrig
.x
;
868 DeltaY
= CurrentWindow
->rcClient
.top
- dc
->ptlDCOrig
.y
;
869 dc
->ptlDCOrig
.x
= CurrentWindow
->rcClient
.left
;
870 dc
->ptlDCOrig
.y
= CurrentWindow
->rcClient
.top
;
872 if (NULL
!= dc
->rosdc
.hClipRgn
)
874 NtGdiOffsetRgn(dc
->rosdc
.hClipRgn
, DeltaX
, DeltaY
);
875 CLIPPING_UpdateGCRegion(dc
);
877 if (NULL
!= pDCE
->hrgnClip
)
879 NtGdiOffsetRgn(pDCE
->hrgnClip
, DeltaX
, DeltaY
);
884 DceUpdateVisRgn(pDCE
, CurrentWindow
, pDCE
->DCXFlags
);
886 if (Window
->head
.h
!= pDCE
->hwndCurrent
)
888 // IntEngWindowChanged(CurrentWindow, WOC_RGN_CLIENT);
889 // UserDerefObject(CurrentWindow);
892 pLE
= pDCE
->List
.Flink
;
893 pDCE
= CONTAINING_RECORD(pLE
, DCE
, List
);
895 while (pLE
!= &LEDce
);
899 IntWindowFromDC(HDC hDc
)
906 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
911 if (Dce
->DCXFlags
& DCX_INDESTROY
)
914 Ret
= Dce
->hwndCurrent
;
917 pLE
= Dce
->List
.Flink
;
918 Dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
920 while (pLE
!= &LEDce
);
925 UserReleaseDC(PWND Window
, HDC hDc
, BOOL EndPaint
)
932 TRACE("%p %p\n", Window
, hDc
);
934 dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
943 pLE
= dce
->List
.Flink
;
944 dce
= CONTAINING_RECORD(pLE
, DCE
, List
);
946 while (pLE
!= &LEDce
);
948 if ( Hit
&& (dce
->DCXFlags
& DCX_DCEBUSY
))
950 nRet
= DceReleaseDC(dce
, EndPaint
);
957 UserGetWindowDC(PWND Wnd
)
959 return UserGetDCEx(Wnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
963 UserGethWnd( HDC hdc
, PWNDOBJ
*pwndo
)
970 hWnd
= IntWindowFromDC(hdc
);
972 if (hWnd
&& !(Wnd
= UserGetWindowObject(hWnd
)))
974 pprop
= IntGetProp(Wnd
, AtomWndObj
);
976 pWndgdi
= (WNDGDI
*)pprop
->Data
;
978 if ( pWndgdi
&& pWndgdi
->Hwnd
== hWnd
)
980 if (pwndo
) *pwndo
= (PWNDOBJ
)pWndgdi
;
987 NtUserGetDCEx(HWND hWnd OPTIONAL
, HANDLE ClipRegion
, ULONG Flags
)
992 TRACE("Enter NtUserGetDCEx\n");
993 UserEnterExclusive();
995 if (hWnd
&& !(Wnd
= UserGetWindowObject(hWnd
)))
999 RETURN( UserGetDCEx(Wnd
, ClipRegion
, Flags
));
1002 TRACE("Leave NtUserGetDCEx, ret=%i\n",_ret_
);
1010 * The NtUserGetWindowDC function retrieves the device context (DC) for the
1011 * entire window, including title bar, menus, and scroll bars. A window device
1012 * context permits painting anywhere in a window, because the origin of the
1013 * device context is the upper-left corner of the window instead of the client
1020 NtUserGetWindowDC(HWND hWnd
)
1022 return NtUserGetDCEx(hWnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
1026 NtUserGetDC(HWND hWnd
)
1028 TRACE("NtUGetDC -> %x:%x\n", hWnd
, !hWnd
? DCX_CACHE
| DCX_WINDOW
: DCX_USESTYLE
);
1030 return NtUserGetDCEx(hWnd
, NULL
, NULL
== hWnd
? DCX_CACHE
| DCX_WINDOW
: DCX_USESTYLE
);
1034 * Select logical palette into device context.
1035 * \param hDC handle to the device context
1036 * \param hpal handle to the palette
1037 * \param ForceBackground If this value is FALSE the logical palette will be copied to the device palette only when the applicatioon
1038 * is in the foreground. If this value is TRUE then map the colors in the logical palette to the device
1039 * palette colors in the best way.
1040 * \return old palette
1042 * \todo implement ForceBackground == TRUE
1046 NtUserSelectPalette(HDC hDC
,
1048 BOOL ForceBackground
)
1051 UserEnterExclusive();
1052 // Implement window checks
1053 oldPal
= GdiSelectPalette( hDC
, hpal
, ForceBackground
);