#ifdef HAVE_XWIN_CONFIG_H
#include <xwin-config.h>
#endif
#include "win.h"
static int
winAddRgn (WindowPtr pWindow, pointer data);
static
void
winUpdateRgnRootless (WindowPtr pWindow);
#ifdef SHAPE
static
void
winReshapeRootless (WindowPtr pWin);
#endif
#ifdef XWIN_NATIVEGDI
Bool
winCreateWindowNativeGDI (WindowPtr pWin)
{
ScreenPtr pScreen = pWin->drawable.pScreen;
winWindowPriv(pWin);
winScreenPriv(pScreen);
#if CYGDEBUG
winTrace ("winCreateWindowNativeGDI (%p)\n", pWin);
#endif
WIN_UNWRAP(CreateWindow);
fResult = (*pScreen->CreateWindow) (pWin);
WIN_WRAP(CreateWindow, winCreateWindowNativeGDI);
return fResult;
}
Bool
winDestroyWindowNativeGDI (WindowPtr pWin)
{
Bool fResult = TRUE;
ScreenPtr pScreen = pWin->drawable.pScreen;
winWindowPriv(pWin);
winScreenPriv(pScreen);
#if CYGDEBUG
winTrace ("winDestroyWindowNativeGDI (%p)\n", pWin);
#endif
WIN_UNWRAP(DestroyWindow);
fResult = (*pScreen->DestroyWindow)(pWin);
WIN_WRAP(DestroyWindow, winDestroyWindowNativeGDI);
return fResult;
}
Bool
winPositionWindowNativeGDI (WindowPtr pWin, int x, int y)
{
Bool fResult = TRUE;
ScreenPtr pScreen = pWin->drawable.pScreen;
winWindowPriv(pWin);
winScreenPriv(pScreen);
#if CYGDEBUG
winTrace ("winPositionWindowNativeGDI (%p)\n", pWin);
#endif
WIN_UNWRAP(PositionWindow);
fResult = (*pScreen->PositionWindow)(pWin, x, y);
WIN_WRAP(PositionWindow, winPositionWindowNativeGDI);
return fResult;
}
void
winCopyWindowNativeGDI (WindowPtr pWin,
DDXPointRec ptOldOrg,
RegionPtr prgnSrc)
{
DDXPointPtr pptSrc;
DDXPointPtr ppt;
RegionPtr prgnDst;
BoxPtr pBox;
int dx, dy;
int i, nbox;
WindowPtr pwinRoot;
BoxPtr pBoxDst;
ScreenPtr pScreen = pWin->drawable.pScreen;
winScreenPriv(pScreen);
#if 0
ErrorF ("winCopyWindow\n");
#endif
pwinRoot = WindowTable[pWin->drawable.pScreen->myNum];
prgnDst = REGION_CREATE(pWin->drawable.pScreen, NULL, 1);
dx = ptOldOrg.x - pWin->drawable.x;
dy = ptOldOrg.y - pWin->drawable.y;
REGION_TRANSLATE(pWin->drawable.pScreen, prgnSrc, -dx, -dy);
REGION_INTERSECT(pWin->drawable.pScreen, prgnDst, &pWin->borderClip,
prgnSrc);
pBox = REGION_RECTS(prgnDst);
nbox = REGION_NUM_RECTS(prgnDst);
if(!(pptSrc = (DDXPointPtr )ALLOCATE_LOCAL(nbox * sizeof(DDXPointRec))))
return;
ppt = pptSrc;
for (i = nbox; --i >= 0; ppt++, pBox++)
{
ppt->x = pBox->x1 + dx;
ppt->y = pBox->y1 + dy;
}
pBoxDst = REGION_RECTS(prgnDst);
ppt = pptSrc;
#if 0
ErrorF ("winCopyWindow - x1\tx2\ty1\ty2\tx\ty\n");
#endif
for (i = nbox; --i >= 0; pBoxDst++, ppt++)
{
#if 0
ErrorF ("winCopyWindow - %d\t%d\t%d\t%d\t%d\t%d\n",
pBoxDst->x1, pBoxDst->x2, pBoxDst->y1, pBoxDst->y2,
ppt->x, ppt->y);
#endif
BitBlt (pScreenPriv->hdcScreen,
pBoxDst->x1, pBoxDst->y1,
pBoxDst->x2 - pBoxDst->x1, pBoxDst->y2 - pBoxDst->y1,
pScreenPriv->hdcScreen,
ppt->x, ppt->y,
SRCCOPY);
}
DEALLOCATE_LOCAL(pptSrc);
REGION_DESTROY(pWin->drawable.pScreen, prgnDst);
}
Bool
winChangeWindowAttributesNativeGDI (WindowPtr pWin, unsigned long mask)
{
Bool fResult = TRUE;
ScreenPtr pScreen = pWin->drawable.pScreen;
winWindowPriv(pWin);
winScreenPriv(pScreen);
#if CYGDEBUG
winTrace ("winChangeWindowAttributesNativeGDI (%p)\n", pWin);
#endif
WIN_UNWRAP(ChangeWindowAttributes);
fResult = (*pScreen->ChangeWindowAttributes)(pWin, mask);
WIN_WRAP(ChangeWindowAttributes, winChangeWindowAttributesNativeGDI);
return fResult;
}
Bool
winUnmapWindowNativeGDI (WindowPtr pWin)
{
Bool fResult = TRUE;
ScreenPtr pScreen = pWin->drawable.pScreen;
winWindowPriv(pWin);
winScreenPriv(pScreen);
#if CYGDEBUG
winTrace ("winUnmapWindowNativeGDI (%p)\n", pWin);
#endif
WIN_UNWRAP(UnrealizeWindow);
fResult = (*pScreen->UnrealizeWindow)(pWin);
WIN_WRAP(UnrealizeWindow, winUnmapWindowNativeGDI);
return fResult;
}
Bool
winMapWindowNativeGDI (WindowPtr pWin)
{
Bool fResult = TRUE;
ScreenPtr pScreen = pWin->drawable.pScreen;
winWindowPriv(pWin);
winScreenPriv(pScreen);
#if CYGDEBUG
winTrace ("winMapWindowNativeGDI (%p)\n", pWin);
#endif
WIN_UNWRAP(RealizeWindow);
fResult = (*pScreen->RealizeWindow)(pWin);
WIN_WRAP(RealizeWindow, winMapWindowMultiWindow);
return fResult;
}
#endif
Bool
winCreateWindowRootless (WindowPtr pWin)
{
Bool fResult = FALSE;
ScreenPtr pScreen = pWin->drawable.pScreen;
winWindowPriv(pWin);
winScreenPriv(pScreen);
#if CYGDEBUG
winTrace ("winCreateWindowRootless (%p)\n", pWin);
#endif
WIN_UNWRAP(CreateWindow);
fResult = (*pScreen->CreateWindow) (pWin);
WIN_WRAP(CreateWindow, winCreateWindowRootless);
pWinPriv->hRgn = NULL;
return fResult;
}
Bool
winDestroyWindowRootless (WindowPtr pWin)
{
Bool fResult = FALSE;
ScreenPtr pScreen = pWin->drawable.pScreen;
winWindowPriv(pWin);
winScreenPriv(pScreen);
#if CYGDEBUG
winTrace ("winDestroyWindowRootless (%p)\n", pWin);
#endif
WIN_UNWRAP(DestroyWindow);
fResult = (*pScreen->DestroyWindow)(pWin);
WIN_WRAP(DestroyWindow, winDestroyWindowRootless);
if (pWinPriv->hRgn != NULL)
{
DeleteObject(pWinPriv->hRgn);
pWinPriv->hRgn = NULL;
}
winUpdateRgnRootless (pWin);
return fResult;
}
Bool
winPositionWindowRootless (WindowPtr pWin, int x, int y)
{
Bool fResult = FALSE;
ScreenPtr pScreen = pWin->drawable.pScreen;
winWindowPriv(pWin);
winScreenPriv(pScreen);
#if CYGDEBUG
winTrace ("winPositionWindowRootless (%p)\n", pWin);
#endif
WIN_UNWRAP(PositionWindow);
fResult = (*pScreen->PositionWindow)(pWin, x, y);
WIN_WRAP(PositionWindow, winPositionWindowRootless);
winUpdateRgnRootless (pWin);
return fResult;
}
Bool
winChangeWindowAttributesRootless (WindowPtr pWin, unsigned long mask)
{
Bool fResult = FALSE;
ScreenPtr pScreen = pWin->drawable.pScreen;
winWindowPriv(pWin);
winScreenPriv(pScreen);
#if CYGDEBUG
winTrace ("winChangeWindowAttributesRootless (%p)\n", pWin);
#endif
WIN_UNWRAP(ChangeWindowAttributes);
fResult = (*pScreen->ChangeWindowAttributes)(pWin, mask);
WIN_WRAP(ChangeWindowAttributes, winChangeWindowAttributesRootless);
winUpdateRgnRootless (pWin);
return fResult;
}
Bool
winUnmapWindowRootless (WindowPtr pWin)
{
Bool fResult = FALSE;
ScreenPtr pScreen = pWin->drawable.pScreen;
winWindowPriv(pWin);
winScreenPriv(pScreen);
#if CYGDEBUG
winTrace ("winUnmapWindowRootless (%p)\n", pWin);
#endif
WIN_UNWRAP(UnrealizeWindow);
fResult = (*pScreen->UnrealizeWindow)(pWin);
WIN_WRAP(UnrealizeWindow, winUnmapWindowRootless);
if (pWinPriv->hRgn != NULL)
{
DeleteObject(pWinPriv->hRgn);
pWinPriv->hRgn = NULL;
}
winUpdateRgnRootless (pWin);
return fResult;
}
Bool
winMapWindowRootless (WindowPtr pWin)
{
Bool fResult = FALSE;
ScreenPtr pScreen = pWin->drawable.pScreen;
winWindowPriv(pWin);
winScreenPriv(pScreen);
#if CYGDEBUG
winTrace ("winMapWindowRootless (%p)\n", pWin);
#endif
WIN_UNWRAP(RealizeWindow);
fResult = (*pScreen->RealizeWindow)(pWin);
WIN_WRAP(RealizeWindow, winMapWindowRootless);
#ifdef SHAPE
winReshapeRootless (pWin);
#endif
winUpdateRgnRootless (pWin);
return fResult;
}
#ifdef SHAPE
void
winSetShapeRootless (WindowPtr pWin)
{
ScreenPtr pScreen = pWin->drawable.pScreen;
winWindowPriv(pWin);
winScreenPriv(pScreen);
#if CYGDEBUG
winTrace ("winSetShapeRootless (%p)\n", pWin);
#endif
WIN_UNWRAP(SetShape);
(*pScreen->SetShape)(pWin);
WIN_WRAP(SetShape, winSetShapeRootless);
winReshapeRootless (pWin);
winUpdateRgnRootless (pWin);
return;
}
#endif
static
int
winAddRgn (WindowPtr pWin, pointer data)
{
int iX, iY, iWidth, iHeight, iBorder;
HRGN hRgn = *(HRGN*)data;
HRGN hRgnWin;
winWindowPriv(pWin);
if (pWin->parent != NULL)
{
#if CYGDEBUG
winDebug ("winAddRgn ()\n");
#endif
if (pWin->mapped)
{
iBorder = wBorderWidth (pWin);
iX = pWin->drawable.x - iBorder;
iY = pWin->drawable.y - iBorder;
iWidth = pWin->drawable.width + iBorder * 2;
iHeight = pWin->drawable.height + iBorder * 2;
hRgnWin = CreateRectRgn (0, 0, iWidth, iHeight);
if (hRgnWin == NULL)
{
ErrorF ("winAddRgn - CreateRectRgn () failed\n");
ErrorF (" Rect %d %d %d %d\n",
iX, iY, iX + iWidth, iY + iHeight);
}
if (pWinPriv->hRgn)
{
if (CombineRgn (hRgnWin, hRgnWin, pWinPriv->hRgn, RGN_AND)
== ERROR)
{
ErrorF ("winAddRgn - CombineRgn () failed\n");
}
}
OffsetRgn (hRgnWin, iX, iY);
if (CombineRgn (hRgn, hRgn, hRgnWin, RGN_OR) == ERROR)
{
ErrorF ("winAddRgn - CombineRgn () failed\n");
}
DeleteObject (hRgnWin);
}
return WT_DONTWALKCHILDREN;
}
else
{
return WT_WALKCHILDREN;
}
}
static
void
winUpdateRgnRootless (WindowPtr pWin)
{
HRGN hRgn = CreateRectRgn (0, 0, 0, 0);
if (hRgn != NULL)
{
WalkTree (pWin->drawable.pScreen, winAddRgn, &hRgn);
SetWindowRgn (winGetScreenPriv(pWin->drawable.pScreen)->hwndScreen,
hRgn, TRUE);
}
else
{
ErrorF ("winUpdateRgnRootless - CreateRectRgn failed.\n");
}
}
#ifdef SHAPE
static
void
winReshapeRootless (WindowPtr pWin)
{
int nRects;
RegionRec rrNewShape;
BoxPtr pShape, pRects, pEnd;
HRGN hRgn, hRgnRect;
winWindowPriv(pWin);
#if CYGDEBUG
winDebug ("winReshapeRootless ()\n");
#endif
if (pWin->parent == NULL)
return;
if (pWin->parent->parent != NULL)
return;
if (pWinPriv->hRgn != NULL)
{
DeleteObject (pWinPriv->hRgn);
pWinPriv->hRgn = NULL;
}
if (!wBoundingShape (pWin))
return;
REGION_NULL(pScreen, &rrNewShape);
REGION_COPY(pScreen, &rrNewShape, wBoundingShape(pWin));
REGION_TRANSLATE(pScreen, &rrNewShape, pWin->borderWidth,
pWin->borderWidth);
nRects = REGION_NUM_RECTS(&rrNewShape);
pShape = REGION_RECTS(&rrNewShape);
if (nRects > 0)
{
hRgn = CreateRectRgn (0, 0, 0, 0);
for (pRects = pShape, pEnd = pShape + nRects; pRects < pEnd; pRects++)
{
hRgnRect = CreateRectRgn (pRects->x1, pRects->y1,
pRects->x2, pRects->y2);
if (hRgnRect == NULL)
{
ErrorF("winReshapeRootless - CreateRectRgn() failed\n");
}
if (CombineRgn (hRgn, hRgn, hRgnRect, RGN_OR) == ERROR)
{
ErrorF("winReshapeRootless - CombineRgn() failed\n");
}
DeleteObject (hRgnRect);
}
pWinPriv->hRgn = hRgn;
}
REGION_UNINIT(pScreen, &rrNewShape);
return;
}
#endif