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: Harold L Hunt II
32 #ifdef HAVE_XWIN_CONFIG_H
33 #include <xwin-config.h>
39 * Prototypes for local functions
43 winAddRgn (WindowPtr pWindow
, pointer data
);
47 winUpdateRgnRootless (WindowPtr pWindow
);
52 winReshapeRootless (WindowPtr pWin
);
57 /* See Porting Layer Definition - p. 37 */
58 /* See mfb/mfbwindow.c - mfbCreateWindow() */
61 winCreateWindowNativeGDI (WindowPtr pWin
)
63 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
65 winScreenPriv(pScreen
);
68 winTrace ("winCreateWindowNativeGDI (%p)\n", pWin
);
71 WIN_UNWRAP(CreateWindow
);
72 fResult
= (*pScreen
->CreateWindow
) (pWin
);
73 WIN_WRAP(CreateWindow
, winCreateWindowNativeGDI
);
79 /* See Porting Layer Definition - p. 37 */
80 /* See mfb/mfbwindow.c - mfbDestroyWindow() */
83 winDestroyWindowNativeGDI (WindowPtr pWin
)
86 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
88 winScreenPriv(pScreen
);
91 winTrace ("winDestroyWindowNativeGDI (%p)\n", pWin
);
94 WIN_UNWRAP(DestroyWindow
);
95 fResult
= (*pScreen
->DestroyWindow
)(pWin
);
96 WIN_WRAP(DestroyWindow
, winDestroyWindowNativeGDI
);
102 /* See Porting Layer Definition - p. 37 */
103 /* See mfb/mfbwindow.c - mfbPositionWindow() */
106 winPositionWindowNativeGDI (WindowPtr pWin
, int x
, int y
)
109 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
111 winScreenPriv(pScreen
);
114 winTrace ("winPositionWindowNativeGDI (%p)\n", pWin
);
117 WIN_UNWRAP(PositionWindow
);
118 fResult
= (*pScreen
->PositionWindow
)(pWin
, x
, y
);
119 WIN_WRAP(PositionWindow
, winPositionWindowNativeGDI
);
125 /* See Porting Layer Definition - p. 39 */
126 /* See mfb/mfbwindow.c - mfbCopyWindow() */
129 winCopyWindowNativeGDI (WindowPtr pWin
,
130 DDXPointRec ptOldOrg
,
141 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
142 winScreenPriv(pScreen
);
145 ErrorF ("winCopyWindow\n");
148 /* Get a pointer to the root window */
149 pwinRoot
= WindowTable
[pWin
->drawable
.pScreen
->myNum
];
151 /* Create a region for the destination */
152 prgnDst
= REGION_CREATE(pWin
->drawable
.pScreen
, NULL
, 1);
154 /* Calculate the shift from the source to the destination */
155 dx
= ptOldOrg
.x
- pWin
->drawable
.x
;
156 dy
= ptOldOrg
.y
- pWin
->drawable
.y
;
158 /* Translate the region from the destination to the source? */
159 REGION_TRANSLATE(pWin
->drawable
.pScreen
, prgnSrc
, -dx
, -dy
);
160 REGION_INTERSECT(pWin
->drawable
.pScreen
, prgnDst
, &pWin
->borderClip
,
163 /* Get a pointer to the first box in the region to be copied */
164 pBox
= REGION_RECTS(prgnDst
);
166 /* Get the number of boxes in the region */
167 nbox
= REGION_NUM_RECTS(prgnDst
);
169 /* Allocate source points for each box */
170 if(!(pptSrc
= (DDXPointPtr
)ALLOCATE_LOCAL(nbox
* sizeof(DDXPointRec
))))
173 /* Set an iterator pointer */
176 /* Calculate the source point of each box? */
177 for (i
= nbox
; --i
>= 0; ppt
++, pBox
++)
179 ppt
->x
= pBox
->x1
+ dx
;
180 ppt
->y
= pBox
->y1
+ dy
;
183 /* Setup loop pointers again */
184 pBoxDst
= REGION_RECTS(prgnDst
);
188 ErrorF ("winCopyWindow - x1\tx2\ty1\ty2\tx\ty\n");
191 /* BitBlt each source to the destination point */
192 for (i
= nbox
; --i
>= 0; pBoxDst
++, ppt
++)
195 ErrorF ("winCopyWindow - %d\t%d\t%d\t%d\t%d\t%d\n",
196 pBoxDst
->x1
, pBoxDst
->x2
, pBoxDst
->y1
, pBoxDst
->y2
,
200 BitBlt (pScreenPriv
->hdcScreen
,
201 pBoxDst
->x1
, pBoxDst
->y1
,
202 pBoxDst
->x2
- pBoxDst
->x1
, pBoxDst
->y2
- pBoxDst
->y1
,
203 pScreenPriv
->hdcScreen
,
208 /* Cleanup the regions, etc. */
209 DEALLOCATE_LOCAL(pptSrc
);
210 REGION_DESTROY(pWin
->drawable
.pScreen
, prgnDst
);
214 /* See Porting Layer Definition - p. 37 */
215 /* See mfb/mfbwindow.c - mfbChangeWindowAttributes() */
218 winChangeWindowAttributesNativeGDI (WindowPtr pWin
, unsigned long mask
)
221 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
223 winScreenPriv(pScreen
);
226 winTrace ("winChangeWindowAttributesNativeGDI (%p)\n", pWin
);
229 WIN_UNWRAP(ChangeWindowAttributes
);
230 fResult
= (*pScreen
->ChangeWindowAttributes
)(pWin
, mask
);
231 WIN_WRAP(ChangeWindowAttributes
, winChangeWindowAttributesNativeGDI
);
234 * NOTE: We do not currently need to do anything here.
241 /* See Porting Layer Definition - p. 37
242 * Also referred to as UnrealizeWindow
246 winUnmapWindowNativeGDI (WindowPtr pWin
)
249 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
251 winScreenPriv(pScreen
);
254 winTrace ("winUnmapWindowNativeGDI (%p)\n", pWin
);
257 WIN_UNWRAP(UnrealizeWindow
);
258 fResult
= (*pScreen
->UnrealizeWindow
)(pWin
);
259 WIN_WRAP(UnrealizeWindow
, winUnmapWindowNativeGDI
);
265 /* See Porting Layer Definition - p. 37
266 * Also referred to as RealizeWindow
270 winMapWindowNativeGDI (WindowPtr pWin
)
273 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
275 winScreenPriv(pScreen
);
278 winTrace ("winMapWindowNativeGDI (%p)\n", pWin
);
281 WIN_UNWRAP(RealizeWindow
);
282 fResult
= (*pScreen
->RealizeWindow
)(pWin
);
283 WIN_WRAP(RealizeWindow
, winMapWindowMultiWindow
);
291 /* See Porting Layer Definition - p. 37 */
292 /* See mfb/mfbwindow.c - mfbCreateWindow() */
295 winCreateWindowRootless (WindowPtr pWin
)
297 Bool fResult
= FALSE
;
298 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
300 winScreenPriv(pScreen
);
303 winTrace ("winCreateWindowRootless (%p)\n", pWin
);
306 WIN_UNWRAP(CreateWindow
);
307 fResult
= (*pScreen
->CreateWindow
) (pWin
);
308 WIN_WRAP(CreateWindow
, winCreateWindowRootless
);
310 pWinPriv
->hRgn
= NULL
;
316 /* See Porting Layer Definition - p. 37 */
317 /* See mfb/mfbwindow.c - mfbDestroyWindow() */
320 winDestroyWindowRootless (WindowPtr pWin
)
322 Bool fResult
= FALSE
;
323 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
325 winScreenPriv(pScreen
);
328 winTrace ("winDestroyWindowRootless (%p)\n", pWin
);
331 WIN_UNWRAP(DestroyWindow
);
332 fResult
= (*pScreen
->DestroyWindow
)(pWin
);
333 WIN_WRAP(DestroyWindow
, winDestroyWindowRootless
);
335 if (pWinPriv
->hRgn
!= NULL
)
337 DeleteObject(pWinPriv
->hRgn
);
338 pWinPriv
->hRgn
= NULL
;
341 winUpdateRgnRootless (pWin
);
347 /* See Porting Layer Definition - p. 37 */
348 /* See mfb/mfbwindow.c - mfbPositionWindow() */
351 winPositionWindowRootless (WindowPtr pWin
, int x
, int y
)
353 Bool fResult
= FALSE
;
354 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
356 winScreenPriv(pScreen
);
360 winTrace ("winPositionWindowRootless (%p)\n", pWin
);
363 WIN_UNWRAP(PositionWindow
);
364 fResult
= (*pScreen
->PositionWindow
)(pWin
, x
, y
);
365 WIN_WRAP(PositionWindow
, winPositionWindowRootless
);
367 winUpdateRgnRootless (pWin
);
373 /* See Porting Layer Definition - p. 37 */
374 /* See mfb/mfbwindow.c - mfbChangeWindowAttributes() */
377 winChangeWindowAttributesRootless (WindowPtr pWin
, unsigned long mask
)
379 Bool fResult
= FALSE
;
380 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
382 winScreenPriv(pScreen
);
385 winTrace ("winChangeWindowAttributesRootless (%p)\n", pWin
);
388 WIN_UNWRAP(ChangeWindowAttributes
);
389 fResult
= (*pScreen
->ChangeWindowAttributes
)(pWin
, mask
);
390 WIN_WRAP(ChangeWindowAttributes
, winChangeWindowAttributesRootless
);
392 winUpdateRgnRootless (pWin
);
398 /* See Porting Layer Definition - p. 37
399 * Also referred to as UnrealizeWindow
403 winUnmapWindowRootless (WindowPtr pWin
)
405 Bool fResult
= FALSE
;
406 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
408 winScreenPriv(pScreen
);
411 winTrace ("winUnmapWindowRootless (%p)\n", pWin
);
414 WIN_UNWRAP(UnrealizeWindow
);
415 fResult
= (*pScreen
->UnrealizeWindow
)(pWin
);
416 WIN_WRAP(UnrealizeWindow
, winUnmapWindowRootless
);
418 if (pWinPriv
->hRgn
!= NULL
)
420 DeleteObject(pWinPriv
->hRgn
);
421 pWinPriv
->hRgn
= NULL
;
424 winUpdateRgnRootless (pWin
);
430 /* See Porting Layer Definition - p. 37
431 * Also referred to as RealizeWindow
435 winMapWindowRootless (WindowPtr pWin
)
437 Bool fResult
= FALSE
;
438 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
440 winScreenPriv(pScreen
);
443 winTrace ("winMapWindowRootless (%p)\n", pWin
);
446 WIN_UNWRAP(RealizeWindow
);
447 fResult
= (*pScreen
->RealizeWindow
)(pWin
);
448 WIN_WRAP(RealizeWindow
, winMapWindowRootless
);
451 winReshapeRootless (pWin
);
454 winUpdateRgnRootless (pWin
);
462 winSetShapeRootless (WindowPtr pWin
)
464 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
466 winScreenPriv(pScreen
);
469 winTrace ("winSetShapeRootless (%p)\n", pWin
);
472 WIN_UNWRAP(SetShape
);
473 (*pScreen
->SetShape
)(pWin
);
474 WIN_WRAP(SetShape
, winSetShapeRootless
);
476 winReshapeRootless (pWin
);
477 winUpdateRgnRootless (pWin
);
485 * Local function for adding a region to the Windows window region
490 winAddRgn (WindowPtr pWin
, pointer data
)
492 int iX
, iY
, iWidth
, iHeight
, iBorder
;
493 HRGN hRgn
= *(HRGN
*)data
;
497 /* If pWin is not Root */
498 if (pWin
->parent
!= NULL
)
501 winDebug ("winAddRgn ()\n");
505 iBorder
= wBorderWidth (pWin
);
507 iX
= pWin
->drawable
.x
- iBorder
;
508 iY
= pWin
->drawable
.y
- iBorder
;
510 iWidth
= pWin
->drawable
.width
+ iBorder
* 2;
511 iHeight
= pWin
->drawable
.height
+ iBorder
* 2;
513 hRgnWin
= CreateRectRgn (0, 0, iWidth
, iHeight
);
517 ErrorF ("winAddRgn - CreateRectRgn () failed\n");
518 ErrorF (" Rect %d %d %d %d\n",
519 iX
, iY
, iX
+ iWidth
, iY
+ iHeight
);
524 if (CombineRgn (hRgnWin
, hRgnWin
, pWinPriv
->hRgn
, RGN_AND
)
527 ErrorF ("winAddRgn - CombineRgn () failed\n");
531 OffsetRgn (hRgnWin
, iX
, iY
);
533 if (CombineRgn (hRgn
, hRgn
, hRgnWin
, RGN_OR
) == ERROR
)
535 ErrorF ("winAddRgn - CombineRgn () failed\n");
538 DeleteObject (hRgnWin
);
540 return WT_DONTWALKCHILDREN
;
544 return WT_WALKCHILDREN
;
550 * Local function to update the Windows window's region
555 winUpdateRgnRootless (WindowPtr pWin
)
557 HRGN hRgn
= CreateRectRgn (0, 0, 0, 0);
561 WalkTree (pWin
->drawable
.pScreen
, winAddRgn
, &hRgn
);
562 SetWindowRgn (winGetScreenPriv(pWin
->drawable
.pScreen
)->hwndScreen
,
567 ErrorF ("winUpdateRgnRootless - CreateRectRgn failed.\n");
575 winReshapeRootless (WindowPtr pWin
)
578 /* ScreenPtr pScreen = pWin->drawable.pScreen;*/
579 RegionRec rrNewShape
;
580 BoxPtr pShape
, pRects
, pEnd
;
585 winDebug ("winReshapeRootless ()\n");
588 /* Bail if the window is the root window */
589 if (pWin
->parent
== NULL
)
592 /* Bail if the window is not top level */
593 if (pWin
->parent
->parent
!= NULL
)
596 /* Free any existing window region stored in the window privates */
597 if (pWinPriv
->hRgn
!= NULL
)
599 DeleteObject (pWinPriv
->hRgn
);
600 pWinPriv
->hRgn
= NULL
;
603 /* Bail if the window has no bounding region defined */
604 if (!wBoundingShape (pWin
))
607 REGION_NULL(pScreen
, &rrNewShape
);
608 REGION_COPY(pScreen
, &rrNewShape
, wBoundingShape(pWin
));
609 REGION_TRANSLATE(pScreen
, &rrNewShape
, pWin
->borderWidth
,
612 nRects
= REGION_NUM_RECTS(&rrNewShape
);
613 pShape
= REGION_RECTS(&rrNewShape
);
617 /* Create initial empty Windows region */
618 hRgn
= CreateRectRgn (0, 0, 0, 0);
620 /* Loop through all rectangles in the X region */
621 for (pRects
= pShape
, pEnd
= pShape
+ nRects
; pRects
< pEnd
; pRects
++)
623 /* Create a Windows region for the X rectangle */
624 hRgnRect
= CreateRectRgn (pRects
->x1
, pRects
->y1
,
625 pRects
->x2
, pRects
->y2
);
626 if (hRgnRect
== NULL
)
628 ErrorF("winReshapeRootless - CreateRectRgn() failed\n");
631 /* Merge the Windows region with the accumulated region */
632 if (CombineRgn (hRgn
, hRgn
, hRgnRect
, RGN_OR
) == ERROR
)
634 ErrorF("winReshapeRootless - CombineRgn() failed\n");
637 /* Delete the temporary Windows region */
638 DeleteObject (hRgnRect
);
641 /* Save a handle to the composite region in the window privates */
642 pWinPriv
->hRgn
= hRgn
;
645 REGION_UNINIT(pScreen
, &rrNewShape
);