Initial commit
[xorg_rtime.git] / xorg-server-1.4 / hw / xwin / winmultiwindowshape.c
blob33deae337a1f082cc8160fd9c3ef19b671374cb1
1 /*
2 *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
4 *Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 *"Software"), to deal in the Software without restriction, including
7 *without limitation the rights to use, copy, modify, merge, publish,
8 *distribute, sublicense, and/or sell copies of the Software, and to
9 *permit persons to whom the Software is furnished to do so, subject to
10 *the following conditions:
12 *The above copyright notice and this permission notice shall be
13 *included in all copies or substantial portions of the Software.
15 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
19 *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *Except as contained in this notice, the name of the XFree86 Project
24 *shall not be used in advertising or otherwise to promote the sale, use
25 *or other dealings in this Software without prior written authorization
26 *from the XFree86 Project.
28 * Authors: Kensuke Matsuzaki
29 * Harold L Hunt II
32 #ifdef HAVE_XWIN_CONFIG_H
33 #include <xwin-config.h>
34 #endif
35 #ifdef SHAPE
37 #include "win.h"
41 * winSetShapeMultiWindow - See Porting Layer Definition - p. 42
44 void
45 winSetShapeMultiWindow (WindowPtr pWin)
47 ScreenPtr pScreen = pWin->drawable.pScreen;
48 winWindowPriv(pWin);
49 winScreenPriv(pScreen);
51 #if CYGMULTIWINDOW_DEBUG
52 ErrorF ("winSetShapeMultiWindow - pWin: %08x\n", pWin);
53 #endif
55 WIN_UNWRAP(SetShape);
56 (*pScreen->SetShape)(pWin);
57 WIN_WRAP(SetShape, winSetShapeMultiWindow);
59 /* Update the Windows window's shape */
60 winReshapeMultiWindow (pWin);
61 winUpdateRgnMultiWindow (pWin);
63 return;
68 * winUpdateRgnMultiWindow - Local function to update a Windows window region
71 void
72 winUpdateRgnMultiWindow (WindowPtr pWin)
74 SetWindowRgn (winGetWindowPriv(pWin)->hWnd,
75 winGetWindowPriv(pWin)->hRgn, TRUE);
80 * winReshapeMultiWindow - Computes the composite clipping region for a window
83 void
84 winReshapeMultiWindow (WindowPtr pWin)
86 int nRects;
87 RegionRec rrNewShape;
88 BoxPtr pShape, pRects, pEnd;
89 HRGN hRgn, hRgnRect;
90 winWindowPriv(pWin);
92 #if CYGDEBUG
93 winDebug ("winReshape ()\n");
94 #endif
96 /* Bail if the window is the root window */
97 if (pWin->parent == NULL)
98 return;
100 /* Bail if the window is not top level */
101 if (pWin->parent->parent != NULL)
102 return;
104 /* Bail if Windows window handle is invalid */
105 if (pWinPriv->hWnd == NULL)
106 return;
108 /* Free any existing window region stored in the window privates */
109 if (pWinPriv->hRgn != NULL)
111 DeleteObject (pWinPriv->hRgn);
112 pWinPriv->hRgn = NULL;
115 /* Bail if the window has no bounding region defined */
116 if (!wBoundingShape (pWin))
117 return;
119 REGION_NULL(pWin->drawable.pScreen, &rrNewShape);
120 REGION_COPY(pWin->drawable.pScreen, &rrNewShape, wBoundingShape(pWin));
121 REGION_TRANSLATE(pWin->drawable.pScreen,
122 &rrNewShape,
123 pWin->borderWidth,
124 pWin->borderWidth);
126 nRects = REGION_NUM_RECTS(&rrNewShape);
127 pShape = REGION_RECTS(&rrNewShape);
129 /* Don't do anything if there are no rectangles in the region */
130 if (nRects > 0)
132 RECT rcClient;
133 RECT rcWindow;
134 int iOffsetX, iOffsetY;
136 /* Get client rectangle */
137 if (!GetClientRect (pWinPriv->hWnd, &rcClient))
139 ErrorF ("winReshape - GetClientRect failed, bailing: %d\n",
140 (int) GetLastError ());
141 return;
144 /* Translate client rectangle coords to screen coords */
145 /* NOTE: Only transforms top and left members */
146 ClientToScreen (pWinPriv->hWnd, (LPPOINT) &rcClient);
148 /* Get window rectangle */
149 if (!GetWindowRect (pWinPriv->hWnd, &rcWindow))
151 ErrorF ("winReshape - GetWindowRect failed, bailing: %d\n",
152 (int) GetLastError ());
153 return;
156 /* Calculate offset from window upper-left to client upper-left */
157 iOffsetX = rcClient.left - rcWindow.left;
158 iOffsetY = rcClient.top - rcWindow.top;
160 /* Create initial Windows region for title bar */
161 /* FIXME: Mean, nasty, ugly hack!!! */
162 hRgn = CreateRectRgn (0, 0, rcWindow.right, iOffsetY);
163 if (hRgn == NULL)
165 ErrorF ("winReshape - Initial CreateRectRgn (%d, %d, %d, %d) "
166 "failed: %d\n",
167 0, 0, (int) rcWindow.right, iOffsetY, (int) GetLastError ());
170 /* Loop through all rectangles in the X region */
171 for (pRects = pShape, pEnd = pShape + nRects; pRects < pEnd; pRects++)
173 /* Create a Windows region for the X rectangle */
174 hRgnRect = CreateRectRgn (pRects->x1 + iOffsetX,
175 pRects->y1 + iOffsetY,
176 pRects->x2 + iOffsetX,
177 pRects->y2 + iOffsetY);
178 if (hRgnRect == NULL)
180 ErrorF ("winReshape - Loop CreateRectRgn (%d, %d, %d, %d) "
181 "failed: %d\n"
182 "\tx1: %d x2: %d xOff: %d y1: %d y2: %d yOff: %d\n",
183 pRects->x1 + iOffsetX,
184 pRects->y1 + iOffsetY,
185 pRects->x2 + iOffsetX,
186 pRects->y2 + iOffsetY,
187 (int) GetLastError (),
188 pRects->x1, pRects->x2, iOffsetX,
189 pRects->y1, pRects->y2, iOffsetY);
192 /* Merge the Windows region with the accumulated region */
193 if (CombineRgn (hRgn, hRgn, hRgnRect, RGN_OR) == ERROR)
195 ErrorF ("winReshape - CombineRgn () failed: %d\n",
196 (int) GetLastError ());
199 /* Delete the temporary Windows region */
200 DeleteObject (hRgnRect);
203 /* Save a handle to the composite region in the window privates */
204 pWinPriv->hRgn = hRgn;
207 REGION_UNINIT(pWin->drawable.pScreen, &rrNewShape);
209 return;
211 #endif