winwindow.c revision 05b261ec
105b261ecSmrg/*
205b261ecSmrg *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
305b261ecSmrg *
405b261ecSmrg *Permission is hereby granted, free of charge, to any person obtaining
505b261ecSmrg * a copy of this software and associated documentation files (the
605b261ecSmrg *"Software"), to deal in the Software without restriction, including
705b261ecSmrg *without limitation the rights to use, copy, modify, merge, publish,
805b261ecSmrg *distribute, sublicense, and/or sell copies of the Software, and to
905b261ecSmrg *permit persons to whom the Software is furnished to do so, subject to
1005b261ecSmrg *the following conditions:
1105b261ecSmrg *
1205b261ecSmrg *The above copyright notice and this permission notice shall be
1305b261ecSmrg *included in all copies or substantial portions of the Software.
1405b261ecSmrg *
1505b261ecSmrg *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
1605b261ecSmrg *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1705b261ecSmrg *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
1805b261ecSmrg *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
1905b261ecSmrg *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
2005b261ecSmrg *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2105b261ecSmrg *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2205b261ecSmrg *
2305b261ecSmrg *Except as contained in this notice, the name of the XFree86 Project
2405b261ecSmrg *shall not be used in advertising or otherwise to promote the sale, use
2505b261ecSmrg *or other dealings in this Software without prior written authorization
2605b261ecSmrg *from the XFree86 Project.
2705b261ecSmrg *
2805b261ecSmrg * Authors:	Harold L Hunt II
2905b261ecSmrg *		Kensuke Matsuzaki
3005b261ecSmrg */
3105b261ecSmrg
3205b261ecSmrg#ifdef HAVE_XWIN_CONFIG_H
3305b261ecSmrg#include <xwin-config.h>
3405b261ecSmrg#endif
3505b261ecSmrg#include "win.h"
3605b261ecSmrg
3705b261ecSmrg
3805b261ecSmrg/*
3905b261ecSmrg * Prototypes for local functions
4005b261ecSmrg */
4105b261ecSmrg
4205b261ecSmrgstatic int
4305b261ecSmrgwinAddRgn (WindowPtr pWindow, pointer data);
4405b261ecSmrg
4505b261ecSmrgstatic
4605b261ecSmrgvoid
4705b261ecSmrgwinUpdateRgnRootless (WindowPtr pWindow);
4805b261ecSmrg
4905b261ecSmrg#ifdef SHAPE
5005b261ecSmrgstatic
5105b261ecSmrgvoid
5205b261ecSmrgwinReshapeRootless (WindowPtr pWin);
5305b261ecSmrg#endif
5405b261ecSmrg
5505b261ecSmrg
5605b261ecSmrg#ifdef XWIN_NATIVEGDI
5705b261ecSmrg/* See Porting Layer Definition - p. 37 */
5805b261ecSmrg/* See mfb/mfbwindow.c - mfbCreateWindow() */
5905b261ecSmrg
6005b261ecSmrgBool
6105b261ecSmrgwinCreateWindowNativeGDI (WindowPtr pWin)
6205b261ecSmrg{
6305b261ecSmrg  ScreenPtr		pScreen = pWin->drawable.pScreen;
6405b261ecSmrg  winWindowPriv(pWin);
6505b261ecSmrg  winScreenPriv(pScreen);
6605b261ecSmrg
6705b261ecSmrg#if CYGDEBUG
6805b261ecSmrg  winTrace ("winCreateWindowNativeGDI (%p)\n", pWin);
6905b261ecSmrg#endif
7005b261ecSmrg
7105b261ecSmrg  WIN_UNWRAP(CreateWindow);
7205b261ecSmrg  fResult = (*pScreen->CreateWindow) (pWin);
7305b261ecSmrg  WIN_WRAP(CreateWindow, winCreateWindowNativeGDI);
7405b261ecSmrg
7505b261ecSmrg  return fResult;
7605b261ecSmrg}
7705b261ecSmrg
7805b261ecSmrg
7905b261ecSmrg/* See Porting Layer Definition - p. 37 */
8005b261ecSmrg/* See mfb/mfbwindow.c - mfbDestroyWindow() */
8105b261ecSmrg
8205b261ecSmrgBool
8305b261ecSmrgwinDestroyWindowNativeGDI (WindowPtr pWin)
8405b261ecSmrg{
8505b261ecSmrg  Bool			fResult = TRUE;
8605b261ecSmrg  ScreenPtr		pScreen = pWin->drawable.pScreen;
8705b261ecSmrg  winWindowPriv(pWin);
8805b261ecSmrg  winScreenPriv(pScreen);
8905b261ecSmrg
9005b261ecSmrg#if CYGDEBUG
9105b261ecSmrg  winTrace ("winDestroyWindowNativeGDI (%p)\n", pWin);
9205b261ecSmrg#endif
9305b261ecSmrg
9405b261ecSmrg  WIN_UNWRAP(DestroyWindow);
9505b261ecSmrg  fResult = (*pScreen->DestroyWindow)(pWin);
9605b261ecSmrg  WIN_WRAP(DestroyWindow, winDestroyWindowNativeGDI);
9705b261ecSmrg
9805b261ecSmrg  return fResult;
9905b261ecSmrg}
10005b261ecSmrg
10105b261ecSmrg
10205b261ecSmrg/* See Porting Layer Definition - p. 37 */
10305b261ecSmrg/* See mfb/mfbwindow.c - mfbPositionWindow() */
10405b261ecSmrg
10505b261ecSmrgBool
10605b261ecSmrgwinPositionWindowNativeGDI (WindowPtr pWin, int x, int y)
10705b261ecSmrg{
10805b261ecSmrg  Bool			fResult = TRUE;
10905b261ecSmrg  ScreenPtr		pScreen = pWin->drawable.pScreen;
11005b261ecSmrg  winWindowPriv(pWin);
11105b261ecSmrg  winScreenPriv(pScreen);
11205b261ecSmrg
11305b261ecSmrg#if CYGDEBUG
11405b261ecSmrg  winTrace ("winPositionWindowNativeGDI (%p)\n", pWin);
11505b261ecSmrg#endif
11605b261ecSmrg
11705b261ecSmrg  WIN_UNWRAP(PositionWindow);
11805b261ecSmrg  fResult = (*pScreen->PositionWindow)(pWin, x, y);
11905b261ecSmrg  WIN_WRAP(PositionWindow, winPositionWindowNativeGDI);
12005b261ecSmrg
12105b261ecSmrg  return fResult;
12205b261ecSmrg}
12305b261ecSmrg
12405b261ecSmrg
12505b261ecSmrg/* See Porting Layer Definition - p. 39 */
12605b261ecSmrg/* See mfb/mfbwindow.c - mfbCopyWindow() */
12705b261ecSmrg
12805b261ecSmrgvoid
12905b261ecSmrgwinCopyWindowNativeGDI (WindowPtr pWin,
13005b261ecSmrg			DDXPointRec ptOldOrg,
13105b261ecSmrg			RegionPtr prgnSrc)
13205b261ecSmrg{
13305b261ecSmrg  DDXPointPtr		pptSrc;
13405b261ecSmrg  DDXPointPtr		ppt;
13505b261ecSmrg  RegionPtr		prgnDst;
13605b261ecSmrg  BoxPtr		pBox;
13705b261ecSmrg  int			dx, dy;
13805b261ecSmrg  int			i, nbox;
13905b261ecSmrg  WindowPtr		pwinRoot;
14005b261ecSmrg  BoxPtr		pBoxDst;
14105b261ecSmrg  ScreenPtr		pScreen = pWin->drawable.pScreen;
14205b261ecSmrg  winScreenPriv(pScreen);
14305b261ecSmrg
14405b261ecSmrg#if 0
14505b261ecSmrg  ErrorF ("winCopyWindow\n");
14605b261ecSmrg#endif
14705b261ecSmrg
14805b261ecSmrg  /* Get a pointer to the root window */
14905b261ecSmrg  pwinRoot = WindowTable[pWin->drawable.pScreen->myNum];
15005b261ecSmrg
15105b261ecSmrg  /* Create a region for the destination */
15205b261ecSmrg  prgnDst = REGION_CREATE(pWin->drawable.pScreen, NULL, 1);
15305b261ecSmrg
15405b261ecSmrg  /* Calculate the shift from the source to the destination */
15505b261ecSmrg  dx = ptOldOrg.x - pWin->drawable.x;
15605b261ecSmrg  dy = ptOldOrg.y - pWin->drawable.y;
15705b261ecSmrg
15805b261ecSmrg  /* Translate the region from the destination to the source? */
15905b261ecSmrg  REGION_TRANSLATE(pWin->drawable.pScreen, prgnSrc, -dx, -dy);
16005b261ecSmrg  REGION_INTERSECT(pWin->drawable.pScreen, prgnDst, &pWin->borderClip,
16105b261ecSmrg		   prgnSrc);
16205b261ecSmrg
16305b261ecSmrg  /* Get a pointer to the first box in the region to be copied */
16405b261ecSmrg  pBox = REGION_RECTS(prgnDst);
16505b261ecSmrg
16605b261ecSmrg  /* Get the number of boxes in the region */
16705b261ecSmrg  nbox = REGION_NUM_RECTS(prgnDst);
16805b261ecSmrg
16905b261ecSmrg  /* Allocate source points for each box */
17005b261ecSmrg  if(!(pptSrc = (DDXPointPtr )ALLOCATE_LOCAL(nbox * sizeof(DDXPointRec))))
17105b261ecSmrg    return;
17205b261ecSmrg
17305b261ecSmrg  /* Set an iterator pointer */
17405b261ecSmrg  ppt = pptSrc;
17505b261ecSmrg
17605b261ecSmrg  /* Calculate the source point of each box? */
17705b261ecSmrg  for (i = nbox; --i >= 0; ppt++, pBox++)
17805b261ecSmrg    {
17905b261ecSmrg      ppt->x = pBox->x1 + dx;
18005b261ecSmrg      ppt->y = pBox->y1 + dy;
18105b261ecSmrg    }
18205b261ecSmrg
18305b261ecSmrg  /* Setup loop pointers again */
18405b261ecSmrg  pBoxDst = REGION_RECTS(prgnDst);
18505b261ecSmrg  ppt = pptSrc;
18605b261ecSmrg
18705b261ecSmrg#if 0
18805b261ecSmrg  ErrorF ("winCopyWindow - x1\tx2\ty1\ty2\tx\ty\n");
18905b261ecSmrg#endif
19005b261ecSmrg
19105b261ecSmrg  /* BitBlt each source to the destination point */
19205b261ecSmrg  for (i = nbox; --i >= 0; pBoxDst++, ppt++)
19305b261ecSmrg    {
19405b261ecSmrg#if 0
19505b261ecSmrg      ErrorF ("winCopyWindow - %d\t%d\t%d\t%d\t%d\t%d\n",
19605b261ecSmrg	      pBoxDst->x1, pBoxDst->x2, pBoxDst->y1, pBoxDst->y2,
19705b261ecSmrg	      ppt->x, ppt->y);
19805b261ecSmrg#endif
19905b261ecSmrg
20005b261ecSmrg      BitBlt (pScreenPriv->hdcScreen,
20105b261ecSmrg	      pBoxDst->x1, pBoxDst->y1,
20205b261ecSmrg	      pBoxDst->x2 - pBoxDst->x1, pBoxDst->y2 - pBoxDst->y1,
20305b261ecSmrg	      pScreenPriv->hdcScreen,
20405b261ecSmrg	      ppt->x, ppt->y,
20505b261ecSmrg	      SRCCOPY);
20605b261ecSmrg    }
20705b261ecSmrg
20805b261ecSmrg  /* Cleanup the regions, etc. */
20905b261ecSmrg  DEALLOCATE_LOCAL(pptSrc);
21005b261ecSmrg  REGION_DESTROY(pWin->drawable.pScreen, prgnDst);
21105b261ecSmrg}
21205b261ecSmrg
21305b261ecSmrg
21405b261ecSmrg/* See Porting Layer Definition - p. 37 */
21505b261ecSmrg/* See mfb/mfbwindow.c - mfbChangeWindowAttributes() */
21605b261ecSmrg
21705b261ecSmrgBool
21805b261ecSmrgwinChangeWindowAttributesNativeGDI (WindowPtr pWin, unsigned long mask)
21905b261ecSmrg{
22005b261ecSmrg  Bool			fResult = TRUE;
22105b261ecSmrg  ScreenPtr		pScreen = pWin->drawable.pScreen;
22205b261ecSmrg  winWindowPriv(pWin);
22305b261ecSmrg  winScreenPriv(pScreen);
22405b261ecSmrg
22505b261ecSmrg#if CYGDEBUG
22605b261ecSmrg  winTrace ("winChangeWindowAttributesNativeGDI (%p)\n", pWin);
22705b261ecSmrg#endif
22805b261ecSmrg
22905b261ecSmrg  WIN_UNWRAP(ChangeWindowAttributes);
23005b261ecSmrg  fResult = (*pScreen->ChangeWindowAttributes)(pWin, mask);
23105b261ecSmrg  WIN_WRAP(ChangeWindowAttributes, winChangeWindowAttributesNativeGDI);
23205b261ecSmrg
23305b261ecSmrg  /*
23405b261ecSmrg   * NOTE: We do not currently need to do anything here.
23505b261ecSmrg   */
23605b261ecSmrg
23705b261ecSmrg  return fResult;
23805b261ecSmrg}
23905b261ecSmrg
24005b261ecSmrg
24105b261ecSmrg/* See Porting Layer Definition - p. 37
24205b261ecSmrg * Also referred to as UnrealizeWindow
24305b261ecSmrg */
24405b261ecSmrg
24505b261ecSmrgBool
24605b261ecSmrgwinUnmapWindowNativeGDI (WindowPtr pWin)
24705b261ecSmrg{
24805b261ecSmrg  Bool			fResult = TRUE;
24905b261ecSmrg  ScreenPtr		pScreen = pWin->drawable.pScreen;
25005b261ecSmrg  winWindowPriv(pWin);
25105b261ecSmrg  winScreenPriv(pScreen);
25205b261ecSmrg
25305b261ecSmrg#if CYGDEBUG
25405b261ecSmrg  winTrace ("winUnmapWindowNativeGDI (%p)\n", pWin);
25505b261ecSmrg#endif
25605b261ecSmrg
25705b261ecSmrg  WIN_UNWRAP(UnrealizeWindow);
25805b261ecSmrg  fResult = (*pScreen->UnrealizeWindow)(pWin);
25905b261ecSmrg  WIN_WRAP(UnrealizeWindow, winUnmapWindowNativeGDI);
26005b261ecSmrg
26105b261ecSmrg  return fResult;
26205b261ecSmrg}
26305b261ecSmrg
26405b261ecSmrg
26505b261ecSmrg/* See Porting Layer Definition - p. 37
26605b261ecSmrg * Also referred to as RealizeWindow
26705b261ecSmrg */
26805b261ecSmrg
26905b261ecSmrgBool
27005b261ecSmrgwinMapWindowNativeGDI (WindowPtr pWin)
27105b261ecSmrg{
27205b261ecSmrg  Bool			fResult = TRUE;
27305b261ecSmrg  ScreenPtr		pScreen = pWin->drawable.pScreen;
27405b261ecSmrg  winWindowPriv(pWin);
27505b261ecSmrg  winScreenPriv(pScreen);
27605b261ecSmrg
27705b261ecSmrg#if CYGDEBUG
27805b261ecSmrg  winTrace ("winMapWindowNativeGDI (%p)\n", pWin);
27905b261ecSmrg#endif
28005b261ecSmrg
28105b261ecSmrg  WIN_UNWRAP(RealizeWindow);
28205b261ecSmrg  fResult = (*pScreen->RealizeWindow)(pWin);
28305b261ecSmrg  WIN_WRAP(RealizeWindow, winMapWindowMultiWindow);
28405b261ecSmrg
28505b261ecSmrg  return fResult;
28605b261ecSmrg
28705b261ecSmrg}
28805b261ecSmrg#endif
28905b261ecSmrg
29005b261ecSmrg
29105b261ecSmrg/* See Porting Layer Definition - p. 37 */
29205b261ecSmrg/* See mfb/mfbwindow.c - mfbCreateWindow() */
29305b261ecSmrg
29405b261ecSmrgBool
29505b261ecSmrgwinCreateWindowRootless (WindowPtr pWin)
29605b261ecSmrg{
29705b261ecSmrg  Bool			fResult = FALSE;
29805b261ecSmrg  ScreenPtr		pScreen = pWin->drawable.pScreen;
29905b261ecSmrg  winWindowPriv(pWin);
30005b261ecSmrg  winScreenPriv(pScreen);
30105b261ecSmrg
30205b261ecSmrg#if CYGDEBUG
30305b261ecSmrg  winTrace ("winCreateWindowRootless (%p)\n", pWin);
30405b261ecSmrg#endif
30505b261ecSmrg
30605b261ecSmrg  WIN_UNWRAP(CreateWindow);
30705b261ecSmrg  fResult = (*pScreen->CreateWindow) (pWin);
30805b261ecSmrg  WIN_WRAP(CreateWindow, winCreateWindowRootless);
30905b261ecSmrg
31005b261ecSmrg  pWinPriv->hRgn = NULL;
31105b261ecSmrg
31205b261ecSmrg  return fResult;
31305b261ecSmrg}
31405b261ecSmrg
31505b261ecSmrg
31605b261ecSmrg/* See Porting Layer Definition - p. 37 */
31705b261ecSmrg/* See mfb/mfbwindow.c - mfbDestroyWindow() */
31805b261ecSmrg
31905b261ecSmrgBool
32005b261ecSmrgwinDestroyWindowRootless (WindowPtr pWin)
32105b261ecSmrg{
32205b261ecSmrg  Bool			fResult = FALSE;
32305b261ecSmrg  ScreenPtr		pScreen = pWin->drawable.pScreen;
32405b261ecSmrg  winWindowPriv(pWin);
32505b261ecSmrg  winScreenPriv(pScreen);
32605b261ecSmrg
32705b261ecSmrg#if CYGDEBUG
32805b261ecSmrg  winTrace ("winDestroyWindowRootless (%p)\n", pWin);
32905b261ecSmrg#endif
33005b261ecSmrg
33105b261ecSmrg  WIN_UNWRAP(DestroyWindow);
33205b261ecSmrg  fResult = (*pScreen->DestroyWindow)(pWin);
33305b261ecSmrg  WIN_WRAP(DestroyWindow, winDestroyWindowRootless);
33405b261ecSmrg
33505b261ecSmrg  if (pWinPriv->hRgn != NULL)
33605b261ecSmrg    {
33705b261ecSmrg      DeleteObject(pWinPriv->hRgn);
33805b261ecSmrg      pWinPriv->hRgn = NULL;
33905b261ecSmrg    }
34005b261ecSmrg
34105b261ecSmrg  winUpdateRgnRootless (pWin);
34205b261ecSmrg
34305b261ecSmrg  return fResult;
34405b261ecSmrg}
34505b261ecSmrg
34605b261ecSmrg
34705b261ecSmrg/* See Porting Layer Definition - p. 37 */
34805b261ecSmrg/* See mfb/mfbwindow.c - mfbPositionWindow() */
34905b261ecSmrg
35005b261ecSmrgBool
35105b261ecSmrgwinPositionWindowRootless (WindowPtr pWin, int x, int y)
35205b261ecSmrg{
35305b261ecSmrg  Bool			fResult = FALSE;
35405b261ecSmrg  ScreenPtr		pScreen = pWin->drawable.pScreen;
35505b261ecSmrg  winWindowPriv(pWin);
35605b261ecSmrg  winScreenPriv(pScreen);
35705b261ecSmrg
35805b261ecSmrg
35905b261ecSmrg#if CYGDEBUG
36005b261ecSmrg  winTrace ("winPositionWindowRootless (%p)\n", pWin);
36105b261ecSmrg#endif
36205b261ecSmrg
36305b261ecSmrg  WIN_UNWRAP(PositionWindow);
36405b261ecSmrg  fResult = (*pScreen->PositionWindow)(pWin, x, y);
36505b261ecSmrg  WIN_WRAP(PositionWindow, winPositionWindowRootless);
36605b261ecSmrg
36705b261ecSmrg  winUpdateRgnRootless (pWin);
36805b261ecSmrg
36905b261ecSmrg  return fResult;
37005b261ecSmrg}
37105b261ecSmrg
37205b261ecSmrg
37305b261ecSmrg/* See Porting Layer Definition - p. 37 */
37405b261ecSmrg/* See mfb/mfbwindow.c - mfbChangeWindowAttributes() */
37505b261ecSmrg
37605b261ecSmrgBool
37705b261ecSmrgwinChangeWindowAttributesRootless (WindowPtr pWin, unsigned long mask)
37805b261ecSmrg{
37905b261ecSmrg  Bool			fResult = FALSE;
38005b261ecSmrg  ScreenPtr		pScreen = pWin->drawable.pScreen;
38105b261ecSmrg  winWindowPriv(pWin);
38205b261ecSmrg  winScreenPriv(pScreen);
38305b261ecSmrg
38405b261ecSmrg#if CYGDEBUG
38505b261ecSmrg  winTrace ("winChangeWindowAttributesRootless (%p)\n", pWin);
38605b261ecSmrg#endif
38705b261ecSmrg
38805b261ecSmrg  WIN_UNWRAP(ChangeWindowAttributes);
38905b261ecSmrg  fResult = (*pScreen->ChangeWindowAttributes)(pWin, mask);
39005b261ecSmrg  WIN_WRAP(ChangeWindowAttributes, winChangeWindowAttributesRootless);
39105b261ecSmrg
39205b261ecSmrg  winUpdateRgnRootless (pWin);
39305b261ecSmrg
39405b261ecSmrg  return fResult;
39505b261ecSmrg}
39605b261ecSmrg
39705b261ecSmrg
39805b261ecSmrg/* See Porting Layer Definition - p. 37
39905b261ecSmrg * Also referred to as UnrealizeWindow
40005b261ecSmrg */
40105b261ecSmrg
40205b261ecSmrgBool
40305b261ecSmrgwinUnmapWindowRootless (WindowPtr pWin)
40405b261ecSmrg{
40505b261ecSmrg  Bool			fResult = FALSE;
40605b261ecSmrg  ScreenPtr		pScreen = pWin->drawable.pScreen;
40705b261ecSmrg  winWindowPriv(pWin);
40805b261ecSmrg  winScreenPriv(pScreen);
40905b261ecSmrg
41005b261ecSmrg#if CYGDEBUG
41105b261ecSmrg  winTrace ("winUnmapWindowRootless (%p)\n", pWin);
41205b261ecSmrg#endif
41305b261ecSmrg
41405b261ecSmrg  WIN_UNWRAP(UnrealizeWindow);
41505b261ecSmrg  fResult = (*pScreen->UnrealizeWindow)(pWin);
41605b261ecSmrg  WIN_WRAP(UnrealizeWindow, winUnmapWindowRootless);
41705b261ecSmrg
41805b261ecSmrg  if (pWinPriv->hRgn != NULL)
41905b261ecSmrg    {
42005b261ecSmrg      DeleteObject(pWinPriv->hRgn);
42105b261ecSmrg      pWinPriv->hRgn = NULL;
42205b261ecSmrg    }
42305b261ecSmrg
42405b261ecSmrg  winUpdateRgnRootless (pWin);
42505b261ecSmrg
42605b261ecSmrg  return fResult;
42705b261ecSmrg}
42805b261ecSmrg
42905b261ecSmrg
43005b261ecSmrg/* See Porting Layer Definition - p. 37
43105b261ecSmrg * Also referred to as RealizeWindow
43205b261ecSmrg */
43305b261ecSmrg
43405b261ecSmrgBool
43505b261ecSmrgwinMapWindowRootless (WindowPtr pWin)
43605b261ecSmrg{
43705b261ecSmrg  Bool			fResult = FALSE;
43805b261ecSmrg  ScreenPtr		pScreen = pWin->drawable.pScreen;
43905b261ecSmrg  winWindowPriv(pWin);
44005b261ecSmrg  winScreenPriv(pScreen);
44105b261ecSmrg
44205b261ecSmrg#if CYGDEBUG
44305b261ecSmrg  winTrace ("winMapWindowRootless (%p)\n", pWin);
44405b261ecSmrg#endif
44505b261ecSmrg
44605b261ecSmrg  WIN_UNWRAP(RealizeWindow);
44705b261ecSmrg  fResult = (*pScreen->RealizeWindow)(pWin);
44805b261ecSmrg  WIN_WRAP(RealizeWindow, winMapWindowRootless);
44905b261ecSmrg
45005b261ecSmrg#ifdef SHAPE
45105b261ecSmrg  winReshapeRootless (pWin);
45205b261ecSmrg#endif
45305b261ecSmrg
45405b261ecSmrg  winUpdateRgnRootless (pWin);
45505b261ecSmrg
45605b261ecSmrg  return fResult;
45705b261ecSmrg}
45805b261ecSmrg
45905b261ecSmrg
46005b261ecSmrg#ifdef SHAPE
46105b261ecSmrgvoid
46205b261ecSmrgwinSetShapeRootless (WindowPtr pWin)
46305b261ecSmrg{
46405b261ecSmrg  ScreenPtr		pScreen = pWin->drawable.pScreen;
46505b261ecSmrg  winWindowPriv(pWin);
46605b261ecSmrg  winScreenPriv(pScreen);
46705b261ecSmrg
46805b261ecSmrg#if CYGDEBUG
46905b261ecSmrg  winTrace ("winSetShapeRootless (%p)\n", pWin);
47005b261ecSmrg#endif
47105b261ecSmrg
47205b261ecSmrg  WIN_UNWRAP(SetShape);
47305b261ecSmrg  (*pScreen->SetShape)(pWin);
47405b261ecSmrg  WIN_WRAP(SetShape, winSetShapeRootless);
47505b261ecSmrg
47605b261ecSmrg  winReshapeRootless (pWin);
47705b261ecSmrg  winUpdateRgnRootless (pWin);
47805b261ecSmrg
47905b261ecSmrg  return;
48005b261ecSmrg}
48105b261ecSmrg#endif
48205b261ecSmrg
48305b261ecSmrg
48405b261ecSmrg/*
48505b261ecSmrg * Local function for adding a region to the Windows window region
48605b261ecSmrg */
48705b261ecSmrg
48805b261ecSmrgstatic
48905b261ecSmrgint
49005b261ecSmrgwinAddRgn (WindowPtr pWin, pointer data)
49105b261ecSmrg{
49205b261ecSmrg  int		iX, iY, iWidth, iHeight, iBorder;
49305b261ecSmrg  HRGN		hRgn = *(HRGN*)data;
49405b261ecSmrg  HRGN		hRgnWin;
49505b261ecSmrg  winWindowPriv(pWin);
49605b261ecSmrg
49705b261ecSmrg  /* If pWin is not Root */
49805b261ecSmrg  if (pWin->parent != NULL)
49905b261ecSmrg    {
50005b261ecSmrg#if CYGDEBUG
50105b261ecSmrg      winDebug ("winAddRgn ()\n");
50205b261ecSmrg#endif
50305b261ecSmrg      if (pWin->mapped)
50405b261ecSmrg	{
50505b261ecSmrg	  iBorder = wBorderWidth (pWin);
50605b261ecSmrg
50705b261ecSmrg	  iX = pWin->drawable.x - iBorder;
50805b261ecSmrg	  iY = pWin->drawable.y - iBorder;
50905b261ecSmrg
51005b261ecSmrg	  iWidth = pWin->drawable.width + iBorder * 2;
51105b261ecSmrg	  iHeight = pWin->drawable.height + iBorder * 2;
51205b261ecSmrg
51305b261ecSmrg	  hRgnWin = CreateRectRgn (0, 0, iWidth, iHeight);
51405b261ecSmrg
51505b261ecSmrg	  if (hRgnWin == NULL)
51605b261ecSmrg	    {
51705b261ecSmrg	      ErrorF ("winAddRgn - CreateRectRgn () failed\n");
51805b261ecSmrg	      ErrorF ("  Rect %d %d %d %d\n",
51905b261ecSmrg		      iX, iY, iX + iWidth, iY + iHeight);
52005b261ecSmrg	    }
52105b261ecSmrg
52205b261ecSmrg	  if (pWinPriv->hRgn)
52305b261ecSmrg	    {
52405b261ecSmrg	      if (CombineRgn (hRgnWin, hRgnWin, pWinPriv->hRgn, RGN_AND)
52505b261ecSmrg		  == ERROR)
52605b261ecSmrg		{
52705b261ecSmrg		  ErrorF ("winAddRgn - CombineRgn () failed\n");
52805b261ecSmrg		}
52905b261ecSmrg	    }
53005b261ecSmrg
53105b261ecSmrg	  OffsetRgn (hRgnWin, iX, iY);
53205b261ecSmrg
53305b261ecSmrg	  if (CombineRgn (hRgn, hRgn, hRgnWin, RGN_OR) == ERROR)
53405b261ecSmrg	    {
53505b261ecSmrg	      ErrorF ("winAddRgn - CombineRgn () failed\n");
53605b261ecSmrg	    }
53705b261ecSmrg
53805b261ecSmrg	  DeleteObject (hRgnWin);
53905b261ecSmrg	}
54005b261ecSmrg      return WT_DONTWALKCHILDREN;
54105b261ecSmrg    }
54205b261ecSmrg  else
54305b261ecSmrg    {
54405b261ecSmrg      return WT_WALKCHILDREN;
54505b261ecSmrg    }
54605b261ecSmrg}
54705b261ecSmrg
54805b261ecSmrg
54905b261ecSmrg/*
55005b261ecSmrg * Local function to update the Windows window's region
55105b261ecSmrg */
55205b261ecSmrg
55305b261ecSmrgstatic
55405b261ecSmrgvoid
55505b261ecSmrgwinUpdateRgnRootless (WindowPtr pWin)
55605b261ecSmrg{
55705b261ecSmrg  HRGN		hRgn = CreateRectRgn (0, 0, 0, 0);
55805b261ecSmrg
55905b261ecSmrg  if (hRgn != NULL)
56005b261ecSmrg    {
56105b261ecSmrg      WalkTree (pWin->drawable.pScreen, winAddRgn, &hRgn);
56205b261ecSmrg      SetWindowRgn (winGetScreenPriv(pWin->drawable.pScreen)->hwndScreen,
56305b261ecSmrg		    hRgn, TRUE);
56405b261ecSmrg    }
56505b261ecSmrg  else
56605b261ecSmrg    {
56705b261ecSmrg      ErrorF ("winUpdateRgnRootless - CreateRectRgn failed.\n");
56805b261ecSmrg    }
56905b261ecSmrg}
57005b261ecSmrg
57105b261ecSmrg
57205b261ecSmrg#ifdef SHAPE
57305b261ecSmrgstatic
57405b261ecSmrgvoid
57505b261ecSmrgwinReshapeRootless (WindowPtr pWin)
57605b261ecSmrg{
57705b261ecSmrg  int		nRects;
57805b261ecSmrg  /* ScreenPtr	pScreen = pWin->drawable.pScreen;*/
57905b261ecSmrg  RegionRec	rrNewShape;
58005b261ecSmrg  BoxPtr	pShape, pRects, pEnd;
58105b261ecSmrg  HRGN		hRgn, hRgnRect;
58205b261ecSmrg  winWindowPriv(pWin);
58305b261ecSmrg
58405b261ecSmrg#if CYGDEBUG
58505b261ecSmrg  winDebug ("winReshapeRootless ()\n");
58605b261ecSmrg#endif
58705b261ecSmrg
58805b261ecSmrg  /* Bail if the window is the root window */
58905b261ecSmrg  if (pWin->parent == NULL)
59005b261ecSmrg    return;
59105b261ecSmrg
59205b261ecSmrg  /* Bail if the window is not top level */
59305b261ecSmrg  if (pWin->parent->parent != NULL)
59405b261ecSmrg    return;
59505b261ecSmrg
59605b261ecSmrg  /* Free any existing window region stored in the window privates */
59705b261ecSmrg  if (pWinPriv->hRgn != NULL)
59805b261ecSmrg    {
59905b261ecSmrg      DeleteObject (pWinPriv->hRgn);
60005b261ecSmrg      pWinPriv->hRgn = NULL;
60105b261ecSmrg    }
60205b261ecSmrg
60305b261ecSmrg  /* Bail if the window has no bounding region defined */
60405b261ecSmrg  if (!wBoundingShape (pWin))
60505b261ecSmrg    return;
60605b261ecSmrg
60705b261ecSmrg  REGION_NULL(pScreen, &rrNewShape);
60805b261ecSmrg  REGION_COPY(pScreen, &rrNewShape, wBoundingShape(pWin));
60905b261ecSmrg  REGION_TRANSLATE(pScreen, &rrNewShape, pWin->borderWidth,
61005b261ecSmrg                   pWin->borderWidth);
61105b261ecSmrg
61205b261ecSmrg  nRects = REGION_NUM_RECTS(&rrNewShape);
61305b261ecSmrg  pShape = REGION_RECTS(&rrNewShape);
61405b261ecSmrg
61505b261ecSmrg  if (nRects > 0)
61605b261ecSmrg    {
61705b261ecSmrg      /* Create initial empty Windows region */
61805b261ecSmrg      hRgn = CreateRectRgn (0, 0, 0, 0);
61905b261ecSmrg
62005b261ecSmrg      /* Loop through all rectangles in the X region */
62105b261ecSmrg      for (pRects = pShape, pEnd = pShape + nRects; pRects < pEnd; pRects++)
62205b261ecSmrg        {
62305b261ecSmrg	  /* Create a Windows region for the X rectangle */
62405b261ecSmrg	  hRgnRect = CreateRectRgn (pRects->x1, pRects->y1,
62505b261ecSmrg				    pRects->x2, pRects->y2);
62605b261ecSmrg	  if (hRgnRect == NULL)
62705b261ecSmrg	    {
62805b261ecSmrg	      ErrorF("winReshapeRootless - CreateRectRgn() failed\n");
62905b261ecSmrg	    }
63005b261ecSmrg
63105b261ecSmrg	  /* Merge the Windows region with the accumulated region */
63205b261ecSmrg	  if (CombineRgn (hRgn, hRgn, hRgnRect, RGN_OR) == ERROR)
63305b261ecSmrg	    {
63405b261ecSmrg	      ErrorF("winReshapeRootless - CombineRgn() failed\n");
63505b261ecSmrg	    }
63605b261ecSmrg
63705b261ecSmrg	  /* Delete the temporary Windows region */
63805b261ecSmrg	  DeleteObject (hRgnRect);
63905b261ecSmrg        }
64005b261ecSmrg
64105b261ecSmrg      /* Save a handle to the composite region in the window privates */
64205b261ecSmrg      pWinPriv->hRgn = hRgn;
64305b261ecSmrg    }
64405b261ecSmrg
64505b261ecSmrg  REGION_UNINIT(pScreen, &rrNewShape);
64605b261ecSmrg
64705b261ecSmrg  return;
64805b261ecSmrg}
64905b261ecSmrg#endif
650