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
32 #ifdef HAVE_XWIN_CONFIG_H
33 #include <xwin-config.h>
39 * winSetShapeMultiWindow - See Porting Layer Definition - p. 42
43 winSetShapeMultiWindow(WindowPtr pWin
, int kind
)
45 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
47 winScreenPriv(pScreen
);
49 #if CYGMULTIWINDOW_DEBUG
50 ErrorF("winSetShapeMultiWindow - pWin: %08x kind: %i\n", pWin
, kind
);
54 (*pScreen
->SetShape
) (pWin
, kind
);
55 WIN_WRAP(SetShape
, winSetShapeMultiWindow
);
57 /* Update the Windows window's shape */
58 winReshapeMultiWindow(pWin
);
59 winUpdateRgnMultiWindow(pWin
);
65 * winUpdateRgnMultiWindow - Local function to update a Windows window region
69 winUpdateRgnMultiWindow(WindowPtr pWin
)
71 SetWindowRgn(winGetWindowPriv(pWin
)->hWnd
,
72 winGetWindowPriv(pWin
)->hRgn
, TRUE
);
74 /* The system now owns the region specified by the region handle and will delete it when it is no longer needed. */
75 winGetWindowPriv(pWin
)->hRgn
= NULL
;
79 * winReshapeMultiWindow - Computes the composite clipping region for a window
83 winReshapeMultiWindow(WindowPtr pWin
)
87 BoxPtr pShape
, pRects
, pEnd
;
93 winDebug("winReshape ()\n");
96 /* Bail if the window is the root window */
97 if (pWin
->parent
== NULL
)
100 /* Bail if the window is not top level */
101 if (pWin
->parent
->parent
!= NULL
)
104 /* Bail if Windows window handle is invalid */
105 if (pWinPriv
->hWnd
== NULL
)
108 /* Free any existing window region stored in the window privates */
109 if (pWinPriv
->hRgn
!= NULL
) {
110 DeleteObject(pWinPriv
->hRgn
);
111 pWinPriv
->hRgn
= NULL
;
114 /* Bail if the window has no bounding region defined */
115 if (!wBoundingShape(pWin
))
118 RegionNull(&rrNewShape
);
119 RegionCopy(&rrNewShape
, wBoundingShape(pWin
));
120 RegionTranslate(&rrNewShape
, pWin
->borderWidth
, pWin
->borderWidth
);
122 nRects
= RegionNumRects(&rrNewShape
);
123 pShape
= RegionRects(&rrNewShape
);
125 /* Don't do anything if there are no rectangles in the region */
129 int iOffsetX
, iOffsetY
;
131 /* Get client rectangle */
132 if (!GetClientRect(pWinPriv
->hWnd
, &rcClient
)) {
133 ErrorF("winReshape - GetClientRect failed, bailing: %d\n",
134 (int) GetLastError());
138 /* Translate client rectangle coords to screen coords */
139 /* NOTE: Only transforms top and left members */
140 ClientToScreen(pWinPriv
->hWnd
, (LPPOINT
) &rcClient
);
142 /* Get window rectangle */
143 if (!GetWindowRect(pWinPriv
->hWnd
, &rcWindow
)) {
144 ErrorF("winReshape - GetWindowRect failed, bailing: %d\n",
145 (int) GetLastError());
149 /* Calculate offset from window upper-left to client upper-left */
150 iOffsetX
= rcClient
.left
- rcWindow
.left
;
151 iOffsetY
= rcClient
.top
- rcWindow
.top
;
153 /* Create initial Windows region for title bar */
154 /* FIXME: Mean, nasty, ugly hack!!! */
155 hRgn
= CreateRectRgn(0, 0, rcWindow
.right
, iOffsetY
);
157 ErrorF("winReshape - Initial CreateRectRgn (%d, %d, %d, %d) "
159 0, 0, (int) rcWindow
.right
, iOffsetY
, (int) GetLastError());
162 /* Loop through all rectangles in the X region */
163 for (pRects
= pShape
, pEnd
= pShape
+ nRects
; pRects
< pEnd
; pRects
++) {
164 /* Create a Windows region for the X rectangle */
165 hRgnRect
= CreateRectRgn(pRects
->x1
+ iOffsetX
,
166 pRects
->y1
+ iOffsetY
,
167 pRects
->x2
+ iOffsetX
,
168 pRects
->y2
+ iOffsetY
);
169 if (hRgnRect
== NULL
) {
170 ErrorF("winReshape - Loop CreateRectRgn (%d, %d, %d, %d) "
172 "\tx1: %d x2: %d xOff: %d y1: %d y2: %d yOff: %d\n",
173 pRects
->x1
+ iOffsetX
,
174 pRects
->y1
+ iOffsetY
,
175 pRects
->x2
+ iOffsetX
,
176 pRects
->y2
+ iOffsetY
,
177 (int) GetLastError(),
178 pRects
->x1
, pRects
->x2
, iOffsetX
,
179 pRects
->y1
, pRects
->y2
, iOffsetY
);
182 /* Merge the Windows region with the accumulated region */
183 if (CombineRgn(hRgn
, hRgn
, hRgnRect
, RGN_OR
) == ERROR
) {
184 ErrorF("winReshape - CombineRgn () failed: %d\n",
185 (int) GetLastError());
188 /* Delete the temporary Windows region */
189 DeleteObject(hRgnRect
);
192 /* Save a handle to the composite region in the window privates */
193 pWinPriv
->hRgn
= hRgn
;
196 RegionUninit(&rrNewShape
);