reactos/reactos/subsystems/win32/win32k/ntuser/windc.c

911 lines
22 KiB
C
Raw Normal View History

/*
* PROJECT: ReactOS Kernel
* LICENSE: GPL - See COPYING in the top level directory
* FILE: subsystems/win32/win32k/ntuser/windc.c
* PURPOSE: Window DC management
* COPYRIGHT: Copyright 2007 ReactOS
*
*/
/* INCLUDES ******************************************************************/
#include <w32k.h>
#define NDEBUG
#include <debug.h>
int FASTCALL CLIPPING_UpdateGCRegion(DC* Dc);
/* GLOBALS *******************************************************************/
/* NOTE - I think we should store this per window station (including gdi objects) */
static PDCE FirstDce = NULL;
//static INT DCECount = 0; // Count of DCE in system.
#define DCX_CACHECOMPAREMASK (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN | \
DCX_NORESETATTRS | DCX_LOCKWINDOWUPDATE | \
DCX_LAYEREDWIN | DCX_CACHE | DCX_WINDOW | \
DCX_PARENTCLIP)
/* FUNCTIONS *****************************************************************/
//
// This should be moved to dc.c or dcutil.c.
//
HDC FASTCALL
DceCreateDisplayDC(VOID)
{
HDC hDC;
UNICODE_STRING DriverName;
RtlInitUnicodeString(&DriverName, L"DISPLAY");
hDC = IntGdiCreateDC(&DriverName, NULL, NULL, NULL, FALSE);
//
// If NULL, first time through! Build the default window dc!
//
if (hDC && !defaultDCstate) // Ultra HAX! Dedicated to GvG!
{ // This is a cheesy way to do this.
PDC dc = DC_LockDc ( hDC );
defaultDCstate = ExAllocatePoolWithTag(PagedPool, sizeof(DC), TAG_DC);
RtlZeroMemory(defaultDCstate, sizeof(DC));
defaultDCstate->pdcattr = &defaultDCstate->dcattr;
DC_vCopyState(dc, defaultDCstate, TRUE);
DC_UnlockDc( dc );
}
return hDC;
}
static
HRGN FASTCALL
DceGetVisRgn(PWINDOW_OBJECT Window, ULONG Flags, HWND hWndChild, ULONG CFlags)
{
HRGN VisRgn;
VisRgn = VIS_ComputeVisibleRegion( Window,
0 == (Flags & DCX_WINDOW),
0 != (Flags & DCX_CLIPCHILDREN),
0 != (Flags & DCX_CLIPSIBLINGS));
if (VisRgn == NULL)
VisRgn = IntSysCreateRectRgn(0, 0, 0, 0);
return VisRgn;
}
PDCE FASTCALL
DceAllocDCE(PWINDOW_OBJECT Window OPTIONAL, DCE_TYPE Type)
{
PDCE pDce;
PWND Wnd = NULL;
if (Window) Wnd = Window->Wnd;
pDce = ExAllocatePoolWithTag(PagedPool, sizeof(DCE), TAG_PDCE);
if(!pDce)
return NULL;
pDce->hDC = DceCreateDisplayDC();
if (!pDce->hDC)
{
ExFreePoolWithTag(pDce, TAG_PDCE);
return NULL;
}
pDce->hwndCurrent = (Window ? Window->hSelf : NULL);
pDce->pwndOrg = Wnd;
pDce->pwndClip = Wnd;
pDce->hrgnClip = NULL;
pDce->hrgnClipPublic = NULL;
pDce->hrgnSavedVis = NULL;
pDce->ppiOwner = NULL;
KeEnterCriticalRegion();
if (FirstDce == NULL)
{
FirstDce = pDce;
InitializeListHead(&FirstDce->List);
}
else
InsertTailList(&FirstDce->List, &pDce->List);
KeLeaveCriticalRegion();
DCU_SetDcUndeletable(pDce->hDC);
if (Type == DCE_WINDOW_DC || Type == DCE_CLASS_DC) //Window DCE have ownership.
{
pDce->ptiOwner = GetW32ThreadInfo();
}
else
{
DPRINT("FREE DCATTR!!!! NOT DCE_WINDOW_DC!!!!! hDC-> %x\n", pDce->hDC);
IntGdiSetDCOwnerEx( pDce->hDC, GDI_OBJ_HMGR_NONE, FALSE);
pDce->ptiOwner = NULL;
}
if (Type == DCE_CACHE_DC)
{
pDce->DCXFlags = DCX_CACHE | DCX_DCEEMPTY;
}
else
{
pDce->DCXFlags = DCX_DCEBUSY;
if (Wnd)
{
if (Type == DCE_WINDOW_DC)
{
if (Wnd->style & WS_CLIPCHILDREN) pDce->DCXFlags |= DCX_CLIPCHILDREN;
if (Wnd->style & WS_CLIPSIBLINGS) pDce->DCXFlags |= DCX_CLIPSIBLINGS;
}
}
}
return(pDce);
}
static VOID APIENTRY
DceSetDrawable( PWINDOW_OBJECT Window OPTIONAL,
HDC hDC,
ULONG Flags,
BOOL SetClipOrigin)
{
PWND Wnd;
DC *dc = DC_LockDc(hDC);
if(!dc)
return;
if (Window == NULL)
{
dc->ptlDCOrig.x = 0;
dc->ptlDCOrig.y = 0;
}
else
{
Wnd = Window->Wnd;
if (Flags & DCX_WINDOW)
{
dc->ptlDCOrig.x = Wnd->rcWindow.left;
dc->ptlDCOrig.y = Wnd->rcWindow.top;
}
else
{
dc->ptlDCOrig.x = Wnd->rcClient.left;
dc->ptlDCOrig.y = Wnd->rcClient.top;
}
}
DC_UnlockDc(dc);
}
static VOID FASTCALL
DceDeleteClipRgn(DCE* Dce)
{
Dce->DCXFlags &= ~(DCX_EXCLUDERGN | DCX_INTERSECTRGN);
if (Dce->DCXFlags & DCX_KEEPCLIPRGN )
{
Dce->DCXFlags &= ~DCX_KEEPCLIPRGN;
}
else if (Dce->hrgnClip != NULL)
{
REGION_FreeRgnByHandle(Dce->hrgnClip);
}
Dce->hrgnClip = NULL;
/* make it dirty so that the vis rgn gets recomputed next time */
Dce->DCXFlags |= DCX_DCEDIRTY;
}
static INT FASTCALL
DceReleaseDC(DCE* dce, BOOL EndPaint)
{
if (DCX_DCEBUSY != (dce->DCXFlags & (DCX_DCEEMPTY | DCX_DCEBUSY)))
{
return 0;
}
/* restore previous visible region */
if ((dce->DCXFlags & (DCX_INTERSECTRGN | DCX_EXCLUDERGN)) &&
((dce->DCXFlags & DCX_CACHE) || EndPaint))
{
DceDeleteClipRgn(dce);
}
if (dce->DCXFlags & DCX_CACHE)
{
if (!(dce->DCXFlags & DCX_NORESETATTRS))
{
/* make the DC clean so that SetDCState doesn't try to update the vis rgn */
IntGdiSetHookFlags(dce->hDC, DCHF_VALIDATEVISRGN);
// Clean the DC
if (!IntGdiCleanDC(dce->hDC)) return 0;
if (dce->DCXFlags & DCX_DCEDIRTY)
{
/* don't keep around invalidated entries
* because SetDCState() disables hVisRgn updates
* by removing dirty bit. */
dce->hwndCurrent = 0;
dce->DCXFlags &= DCX_CACHE;
dce->DCXFlags |= DCX_DCEEMPTY;
}
}
dce->DCXFlags &= ~DCX_DCEBUSY;
DPRINT("Exit!!!!! DCX_CACHE!!!!!! hDC-> %x \n", dce->hDC);
if (!IntGdiSetDCOwnerEx( dce->hDC, GDI_OBJ_HMGR_NONE, FALSE))
return 0;
dce->ptiOwner = NULL; // Reset ownership.
dce->ppiOwner = NULL;
}
return 1; // Released!
}
static VOID FASTCALL
DceUpdateVisRgn(DCE *Dce, PWINDOW_OBJECT Window, ULONG Flags)
{
HANDLE hRgnVisible = NULL;
ULONG DcxFlags;
PWINDOW_OBJECT DesktopWindow;
if (Flags & DCX_PARENTCLIP)
{
PWINDOW_OBJECT Parent;
PWND ParentWnd;
Parent = Window->spwndParent;
if(!Parent)
{
hRgnVisible = NULL;
goto noparent;
}
ParentWnd = Parent->Wnd;
if (ParentWnd->style & WS_CLIPSIBLINGS)
{
DcxFlags = DCX_CLIPSIBLINGS |
(Flags & ~(DCX_CLIPCHILDREN | DCX_WINDOW));
}
else
{
DcxFlags = Flags & ~(DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN | DCX_WINDOW);
}
hRgnVisible = DceGetVisRgn(Parent, DcxFlags, Window->hSelf, Flags);
}
else if (Window == NULL)
{
DesktopWindow = UserGetWindowObject(IntGetDesktopWindow());
if (NULL != DesktopWindow)
{
hRgnVisible = IntSysCreateRectRgnIndirect(&DesktopWindow->Wnd->rcWindow);
}
else
{
hRgnVisible = NULL;
}
}
else
{
hRgnVisible = DceGetVisRgn(Window, Flags, 0, 0);
}
noparent:
if (Flags & DCX_INTERSECTRGN)
{
if(Dce->hrgnClip != NULL)
{
NtGdiCombineRgn(hRgnVisible, hRgnVisible, Dce->hrgnClip, RGN_AND);
}
else
{
if(hRgnVisible != NULL)
{
REGION_FreeRgnByHandle(hRgnVisible);
}
hRgnVisible = IntSysCreateRectRgn(0, 0, 0, 0);
}
}
else if (Flags & DCX_EXCLUDERGN && Dce->hrgnClip != NULL)
{
NtGdiCombineRgn(hRgnVisible, hRgnVisible, Dce->hrgnClip, RGN_DIFF);
}
Dce->DCXFlags &= ~DCX_DCEDIRTY;
GdiSelectVisRgn(Dce->hDC, hRgnVisible);
if (Window != NULL)
{
IntEngWindowChanged(Window, WOC_RGN_CLIENT);
}
if (hRgnVisible != NULL)
{
REGION_FreeRgnByHandle(hRgnVisible);
}
}
HDC FASTCALL
UserGetDCEx(PWINDOW_OBJECT Window OPTIONAL, HANDLE ClipRegion, ULONG Flags)
{
PWINDOW_OBJECT Parent;
ULONG DcxFlags;
DCE* Dce = NULL;
BOOL UpdateClipOrigin = FALSE;
PWND Wnd = NULL;
HDC hDC = NULL;
PPROCESSINFO ppi;
if (NULL == Window)
{
Flags &= ~DCX_USESTYLE;
Flags |= DCX_CACHE;
}
else
Wnd = Window->Wnd;
if (Flags & (DCX_WINDOW | DCX_PARENTCLIP)) Flags |= DCX_CACHE;
// When GetDC is called with hWnd nz, DCX_CACHE & _WINDOW are clear w _USESTYLE set.
if (Flags & DCX_USESTYLE)
{
Flags &= ~(DCX_CLIPCHILDREN | DCX_CLIPSIBLINGS | DCX_PARENTCLIP);
if (!(Flags & DCX_WINDOW)) // not window rectangle
{
if (Wnd->pcls->style & CS_PARENTDC)
{
Flags |= DCX_PARENTCLIP;
}
if (!(Flags & DCX_CACHE) && // Not on the cheap wine list.
!(Wnd->pcls->style & CS_OWNDC) )
{
if (!(Wnd->pcls->style & CS_CLASSDC))
// The window is not POWNED or has any CLASS, so we are looking for cheap wine.
Flags |= DCX_CACHE;
else
{
if (Wnd->pcls->pdce) hDC = ((PDCE)Wnd->pcls->pdce)->hDC;
DPRINT("We have CLASS!!\n");
}
}
/* else // For Testing!
{
DPRINT1("We have POWNER!!\n");
if (Window->Dce) DPRINT1("We have POWNER with DCE!!\n");
}
*/
if (Wnd->style & WS_CLIPSIBLINGS)
{
Flags |= DCX_CLIPSIBLINGS;
}
if (Wnd->style & WS_CLIPCHILDREN &&
!(Wnd->style & WS_MINIMIZE))
{
Flags |= DCX_CLIPCHILDREN;
}
/* If minized with icon in the set, we are forced to be cheap! */
if (Wnd->style & WS_MINIMIZE &&
Wnd->pcls->hIcon)
{
Flags |= DCX_CACHE;
}
}
else
{
if (Wnd->style & WS_CLIPSIBLINGS) Flags |= DCX_CLIPSIBLINGS;
Flags |= DCX_CACHE;
}
}
if (Flags & DCX_WINDOW) Flags &= ~DCX_CLIPCHILDREN;
if (Flags & DCX_NOCLIPCHILDREN)
{
Flags |= DCX_CACHE;
Flags &= ~(DCX_PARENTCLIP | DCX_CLIPCHILDREN);
}
Parent = (Window ? Window->spwndParent : NULL);
if (NULL == Window || !(Wnd->style & WS_CHILD) || NULL == Parent)
{
Flags &= ~DCX_PARENTCLIP;
Flags |= DCX_CLIPSIBLINGS;
}
/* it seems parent clip is ignored when clipping siblings or children */
if (Flags & (DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN)) Flags &= ~DCX_PARENTCLIP;
if (Flags & DCX_PARENTCLIP)
{
if ((Wnd->style & WS_VISIBLE) &&
(Parent->Wnd->style & WS_VISIBLE))
{
Flags &= ~DCX_CLIPCHILDREN;
if (Parent->Wnd->style & WS_CLIPSIBLINGS)
{
Flags |= DCX_CLIPSIBLINGS;
}
}
}
// Window nz, check to see if we still own this or it is just cheap wine tonight.
if (!(Flags & DCX_CACHE))
{
if ( Wnd->head.pti != GetW32ThreadInfo())
Flags |= DCX_CACHE; // Ah~ Not Powned! Forced to be cheap~
}
DcxFlags = Flags & DCX_CACHECOMPAREMASK;
if (Flags & DCX_CACHE)
{ // Scan the cheap wine list for our match.
DCE* DceEmpty = NULL;
DCE* DceUnused = NULL;
KeEnterCriticalRegion();
Dce = FirstDce;
do
{
// The reason for this you may ask?
// Well, it seems ReactOS calls GetDC with out first creating a desktop DC window!
// Need to test for null here. Not sure if this is a bug or a feature.
// First time use hax, need to use DceAllocDCE during window display init.
if (!Dce) break;
//
// The way I understand this, you can have more than one DC per window.
// Only one Owned if one was requested and saved and one Cached.
//
if ((Dce->DCXFlags & (DCX_CACHE | DCX_DCEBUSY)) == DCX_CACHE)
{
DceUnused = Dce;
if (Dce->DCXFlags & DCX_DCEEMPTY)
{
DceEmpty = Dce;
}
else if (Dce->hwndCurrent == (Window ? Window->hSelf : NULL) &&
((Dce->DCXFlags & DCX_CACHECOMPAREMASK) == DcxFlags))
{
UpdateClipOrigin = TRUE;
break;
}
}
Dce = (PDCE)Dce->List.Flink;
} while (Dce != FirstDce);
KeLeaveCriticalRegion();
Dce = (DceEmpty == NULL) ? DceUnused : DceEmpty;
if (Dce == NULL)
{
Dce = DceAllocDCE(NULL, DCE_CACHE_DC);
}
if (!Dce) return NULL;
Dce->hwndCurrent = (Window ? Window->hSelf : NULL);
}
else // If we are here, we are POWNED or having CLASS.
{
KeEnterCriticalRegion();
Dce = FirstDce;
do
{ // Check for Window handle than HDC match for CLASS.
if ((Dce->hwndCurrent == Window->hSelf) ||
(Dce->hDC == hDC))
break;
Dce = (PDCE)Dce->List.Flink;
} while (Dce != FirstDce);
KeLeaveCriticalRegion();
if ( (Flags & (DCX_INTERSECTRGN|DCX_EXCLUDERGN)) &&
(Dce->DCXFlags & (DCX_INTERSECTRGN|DCX_EXCLUDERGN)) )
{
DceDeleteClipRgn(Dce);
}
}
// First time use hax, need to use DceAllocDCE during window display init.
if (NULL == Dce)
{
return(NULL);
}
if (!GDIOBJ_ValidateHandle(Dce->hDC, GDI_OBJECT_TYPE_DC))
{
DPRINT1("FIXME: Got DCE with invalid hDC! 0x%x\n", Dce->hDC);
Dce->hDC = DceCreateDisplayDC();
/* FIXME: Handle error */
}
Dce->DCXFlags = Flags | DCX_DCEBUSY;
/*
Bump it up! This prevents the random errors in wine dce tests and with
proper bits set in DCX_CACHECOMPAREMASK.
Reference:
http://www.reactos.org/archives/public/ros-dev/2008-July/010498.html
http://www.reactos.org/archives/public/ros-dev/2008-July/010499.html
*/
if ((Dce != FirstDce))
{
RemoveEntryList(&Dce->List);
InsertHeadList(&FirstDce->List, &Dce->List);
FirstDce = Dce;
}
/* Introduced in rev 6691 and modified later. */
if ( (Flags & DCX_INTERSECTUPDATE) && !ClipRegion )
{
Flags |= DCX_INTERSECTRGN | DCX_KEEPCLIPRGN;
Dce->DCXFlags |= DCX_INTERSECTRGN | DCX_KEEPCLIPRGN;
ClipRegion = Window->hrgnUpdate;
}
if (ClipRegion == (HRGN) 1)
{
if (!(Flags & DCX_WINDOW))
{
Dce->hrgnClip = IntSysCreateRectRgnIndirect(&Window->Wnd->rcClient);
}
else
{
Dce->hrgnClip = IntSysCreateRectRgnIndirect(&Window->Wnd->rcWindow);
}
Dce->DCXFlags &= ~DCX_KEEPCLIPRGN;
}
else if (ClipRegion != NULL)
{
Dce->hrgnClip = ClipRegion;
}
DceSetDrawable(Window, Dce->hDC, Flags, UpdateClipOrigin);
DceUpdateVisRgn(Dce, Window, Flags);
if (Dce->DCXFlags & DCX_CACHE)
{
DPRINT("ENTER!!!!!! DCX_CACHE!!!!!! hDC-> %x\n", Dce->hDC);
// Need to set ownership so Sync dcattr will work.
IntGdiSetDCOwnerEx( Dce->hDC, GDI_OBJ_HMGR_POWNED, FALSE);
Dce->ptiOwner = GetW32ThreadInfo(); // Set the temp owning
}
if ( Wnd &&
Wnd->ExStyle & WS_EX_LAYOUTRTL &&
!(Flags & DCX_KEEPLAYOUT) )
{
NtGdiSetLayout(Dce->hDC, -1, LAYOUT_RTL);
}
if (Dce->DCXFlags & DCX_PROCESSOWNED)
{
ppi = PsGetCurrentProcessWin32Process();
ppi->W32PF_flags |= W32PF_OWNDCCLEANUP;
Dce->ptiOwner = NULL;
Dce->ppiOwner = ppi;
}
return(Dce->hDC);
}
/***********************************************************************
* DceFreeDCE
*/
PDCE FASTCALL
DceFreeDCE(PDCE pdce, BOOLEAN Force)
{
DCE *ret;
BOOL Hit = FALSE;
if (NULL == pdce) return NULL;
ret = (PDCE) pdce->List.Flink;
#if 0 /* FIXME */
SetDCHook(pdce->hDC, NULL, 0L);
#endif
if (Force && !GDIOBJ_OwnedByCurrentProcess(pdce->hDC))
{
DPRINT("Change ownership for DCE! -> %x\n" , pdce);
// Note: Windows sets W32PF_OWNDCCLEANUP and moves on.
if (!IsObjectDead((HGDIOBJ) pdce->hDC))
{
DC_SetOwnership( pdce->hDC, PsGetCurrentProcess());
}
else
{
DPRINT1("Attempted to change ownership of an DCEhDC 0x%x currently being destroyed!!!\n",pdce->hDC);
Hit = TRUE;
}
}
if (!Hit) IntGdiDeleteDC(pdce->hDC, TRUE);
if (pdce->hrgnClip && ! (pdce->DCXFlags & DCX_KEEPCLIPRGN))
{
REGION_FreeRgnByHandle(pdce->hrgnClip);
}
RemoveEntryList(&pdce->List);
if (IsListEmpty(&pdce->List))
{
DPRINT1("List is Empty! DCE! -> %x\n" , pdce);
FirstDce = NULL;
ret = NULL;
}
ExFreePoolWithTag(pdce, TAG_PDCE);
return ret;
}
void FASTCALL
DceFreeClassDCE(HDC hDC)
{
PDCE pDCE = FirstDce;
KeEnterCriticalRegion();
do
{
if(!pDCE) break;
if (pDCE->hDC == hDC)
{
pDCE = DceFreeDCE(pDCE, FALSE);
if(!pDCE) break;
continue;
}
pDCE = (PDCE)pDCE->List.Flink;
} while (pDCE != FirstDce);
KeLeaveCriticalRegion();
}
VOID FASTCALL
DceEmptyCache(VOID)
{
PDCE pDCE = FirstDce;
KeEnterCriticalRegion();
do
{
if(!pDCE) break;
pDCE = DceFreeDCE(pDCE, TRUE);
if(!pDCE) break;
} while (pDCE != FirstDce);
KeLeaveCriticalRegion();
FirstDce = NULL;
}
VOID FASTCALL
DceResetActiveDCEs(PWINDOW_OBJECT Window)
{
DCE *pDCE;
PDC dc;
PWINDOW_OBJECT CurrentWindow;
INT DeltaX;
INT DeltaY;
if (NULL == Window)
{
return;
}
pDCE = FirstDce;
if(!pDCE) return; // Another null test!
do
{
if(!pDCE) break;
if (0 == (pDCE->DCXFlags & DCX_DCEEMPTY))
{
if (Window->hSelf == pDCE->hwndCurrent)
{
CurrentWindow = Window;
}
else
{
CurrentWindow = UserGetWindowObject(pDCE->hwndCurrent);
if (NULL == CurrentWindow)
{
pDCE = (PDCE) pDCE->List.Flink;
continue;
}
}
if (!GDIOBJ_ValidateHandle(pDCE->hDC, GDI_OBJECT_TYPE_DC) ||
(dc = DC_LockDc(pDCE->hDC)) == NULL)
{
pDCE = (PDCE) pDCE->List.Flink;
continue;
}
if (Window == CurrentWindow || IntIsChildWindow(Window, CurrentWindow))
{
if (pDCE->DCXFlags & DCX_WINDOW)
{
DeltaX = CurrentWindow->Wnd->rcWindow.left - dc->ptlDCOrig.x;
DeltaY = CurrentWindow->Wnd->rcWindow.top - dc->ptlDCOrig.y;
dc->ptlDCOrig.x = CurrentWindow->Wnd->rcWindow.left;
dc->ptlDCOrig.y = CurrentWindow->Wnd->rcWindow.top;
}
else
{
DeltaX = CurrentWindow->Wnd->rcClient.left - dc->ptlDCOrig.x;
DeltaY = CurrentWindow->Wnd->rcClient.top - dc->ptlDCOrig.y;
dc->ptlDCOrig.x = CurrentWindow->Wnd->rcClient.left;
dc->ptlDCOrig.y = CurrentWindow->Wnd->rcClient.top;
}
if (NULL != dc->rosdc.hClipRgn)
{
NtGdiOffsetRgn(dc->rosdc.hClipRgn, DeltaX, DeltaY);
CLIPPING_UpdateGCRegion(dc);
}
if (NULL != pDCE->hrgnClip)
{
NtGdiOffsetRgn(pDCE->hrgnClip, DeltaX, DeltaY);
}
}
DC_UnlockDc(dc);
DceUpdateVisRgn(pDCE, CurrentWindow, pDCE->DCXFlags);
if (Window->hSelf != pDCE->hwndCurrent)
{
// IntEngWindowChanged(CurrentWindow, WOC_RGN_CLIENT);
// UserDerefObject(CurrentWindow);
}
}
pDCE =(PDCE) pDCE->List.Flink;
} while (pDCE != FirstDce);
}
HWND FASTCALL
IntWindowFromDC(HDC hDc)
{
DCE *Dce;
HWND Ret = NULL;
KeEnterCriticalRegion();
Dce = FirstDce;
do
{
if(Dce->hDC == hDc)
{
Ret = Dce->hwndCurrent;
break;
}
Dce = (PDCE)Dce->List.Flink;
} while (Dce != FirstDce);
KeLeaveCriticalRegion();
return Ret;
}
INT FASTCALL
UserReleaseDC(PWINDOW_OBJECT Window, HDC hDc, BOOL EndPaint)
{
PDCE dce;
INT nRet = 0;
BOOL Hit = FALSE;
DPRINT("%p %p\n", Window, hDc);
dce = FirstDce;
KeEnterCriticalRegion();
do
{
if(!dce) break;
if (dce->hDC == hDc)
{
Hit = TRUE;
break;
}
dce = (PDCE) dce->List.Flink;
}
while (dce != FirstDce );
KeLeaveCriticalRegion();
if ( Hit && (dce->DCXFlags & DCX_DCEBUSY))
{
nRet = DceReleaseDC(dce, EndPaint);
}
return nRet;
}
HDC FASTCALL
UserGetWindowDC(PWINDOW_OBJECT Wnd)
{
return UserGetDCEx(Wnd, 0, DCX_USESTYLE | DCX_WINDOW);
}
HWND FASTCALL
UserGethWnd( HDC hdc, PWNDOBJ *pwndo)
{
PWNDGDI pWndgdi;
PWINDOW_OBJECT Wnd;
HWND hWnd;
hWnd = IntWindowFromDC(hdc);
if (hWnd && !(Wnd = UserGetWindowObject(hWnd)))
{
pWndgdi = (WNDGDI *)IntGetProp(Wnd, AtomWndObj);
if ( pWndgdi && pWndgdi->Hwnd == hWnd )
{
if (pwndo) *pwndo = (PWNDOBJ)pWndgdi;
}
}
return hWnd;
}
HDC APIENTRY
NtUserGetDCEx(HWND hWnd OPTIONAL, HANDLE ClipRegion, ULONG Flags)
{
PWINDOW_OBJECT Wnd=NULL;
DECLARE_RETURN(HDC);
DPRINT("Enter NtUserGetDCEx\n");
UserEnterExclusive();
if (hWnd && !(Wnd = UserGetWindowObject(hWnd)))
{
RETURN(NULL);
}
RETURN( UserGetDCEx(Wnd, ClipRegion, Flags));
CLEANUP:
DPRINT("Leave NtUserGetDCEx, ret=%i\n",_ret_);
UserLeave();
END_CLEANUP;
}
/*
* NtUserGetWindowDC
*
* The NtUserGetWindowDC function retrieves the device context (DC) for the
* entire window, including title bar, menus, and scroll bars. A window device
* context permits painting anywhere in a window, because the origin of the
* device context is the upper-left corner of the window instead of the client
* area.
*
* Status
* @implemented
*/
HDC APIENTRY
NtUserGetWindowDC(HWND hWnd)
{
return NtUserGetDCEx(hWnd, 0, DCX_USESTYLE | DCX_WINDOW);
}
HDC APIENTRY
NtUserGetDC(HWND hWnd)
{
DPRINT("NtUGetDC -> %x:%x\n", hWnd, !hWnd ? DCX_CACHE | DCX_WINDOW : DCX_USESTYLE );
return NtUserGetDCEx(hWnd, NULL, NULL == hWnd ? DCX_CACHE | DCX_WINDOW : DCX_USESTYLE);
}
/*!
* Select logical palette into device context.
* \param hDC handle to the device context
* \param hpal handle to the palette
* \param ForceBackground If this value is FALSE the logical palette will be copied to the device palette only when the applicatioon
* is in the foreground. If this value is TRUE then map the colors in the logical palette to the device
* palette colors in the best way.
* \return old palette
*
* \todo implement ForceBackground == TRUE
*/
HPALETTE
APIENTRY
NtUserSelectPalette(HDC hDC,
HPALETTE hpal,
BOOL ForceBackground)
{
HPALETTE oldPal;
UserEnterExclusive();
// Implement window checks
oldPal = GdiSelectPalette( hDC, hpal, ForceBackground);
UserLeave();
return oldPal;
}
/* EOF */