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>
38 * Prototypes for local functions
42 winAddRgn(WindowPtr pWindow
, pointer data
);
46 winUpdateRgnRootless(WindowPtr pWindow
);
50 winReshapeRootless(WindowPtr pWin
);
53 /* See Porting Layer Definition - p. 37 */
54 /* See mfb/mfbwindow.c - mfbCreateWindow() */
57 winCreateWindowNativeGDI(WindowPtr pWin
)
60 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
62 winScreenPriv(pScreen
);
65 winTrace("winCreateWindowNativeGDI (%p)\n", pWin
);
68 WIN_UNWRAP(CreateWindow
);
69 fResult
= (*pScreen
->CreateWindow
) (pWin
);
70 WIN_WRAP(CreateWindow
, winCreateWindowNativeGDI
);
75 /* See Porting Layer Definition - p. 37 */
76 /* See mfb/mfbwindow.c - mfbDestroyWindow() */
79 winDestroyWindowNativeGDI(WindowPtr pWin
)
82 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
84 winScreenPriv(pScreen
);
87 winTrace("winDestroyWindowNativeGDI (%p)\n", pWin
);
90 WIN_UNWRAP(DestroyWindow
);
91 fResult
= (*pScreen
->DestroyWindow
) (pWin
);
92 WIN_WRAP(DestroyWindow
, winDestroyWindowNativeGDI
);
97 /* See Porting Layer Definition - p. 37 */
98 /* See mfb/mfbwindow.c - mfbPositionWindow() */
101 winPositionWindowNativeGDI(WindowPtr pWin
, int x
, int y
)
104 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
106 winScreenPriv(pScreen
);
109 winTrace("winPositionWindowNativeGDI (%p)\n", pWin
);
112 WIN_UNWRAP(PositionWindow
);
113 fResult
= (*pScreen
->PositionWindow
) (pWin
, x
, y
);
114 WIN_WRAP(PositionWindow
, winPositionWindowNativeGDI
);
119 /* See Porting Layer Definition - p. 39 */
120 /* See mfb/mfbwindow.c - mfbCopyWindow() */
123 winCopyWindowNativeGDI(WindowPtr pWin
, DDXPointRec ptOldOrg
, RegionPtr prgnSrc
)
132 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
134 winScreenPriv(pScreen
);
137 ErrorF("winCopyWindow\n");
140 /* Create a region for the destination */
141 prgnDst
= RegionCreate(NULL
, 1);
143 /* Calculate the shift from the source to the destination */
144 dx
= ptOldOrg
.x
- pWin
->drawable
.x
;
145 dy
= ptOldOrg
.y
- pWin
->drawable
.y
;
147 /* Translate the region from the destination to the source? */
148 RegionTranslate(prgnSrc
, -dx
, -dy
);
149 RegionIntersect(prgnDst
, &pWin
->borderClip
, prgnSrc
);
151 /* Get a pointer to the first box in the region to be copied */
152 pBox
= RegionRects(prgnDst
);
154 /* Get the number of boxes in the region */
155 nbox
= RegionNumRects(prgnDst
);
157 /* Allocate source points for each box */
158 if (!(pptSrc
= (DDXPointPtr
) malloc(nbox
* sizeof(DDXPointRec
))))
161 /* Set an iterator pointer */
164 /* Calculate the source point of each box? */
165 for (i
= nbox
; --i
>= 0; ppt
++, pBox
++) {
166 ppt
->x
= pBox
->x1
+ dx
;
167 ppt
->y
= pBox
->y1
+ dy
;
170 /* Setup loop pointers again */
171 pBoxDst
= RegionRects(prgnDst
);
175 ErrorF("winCopyWindow - x1\tx2\ty1\ty2\tx\ty\n");
178 /* BitBlt each source to the destination point */
179 for (i
= nbox
; --i
>= 0; pBoxDst
++, ppt
++) {
181 ErrorF("winCopyWindow - %d\t%d\t%d\t%d\t%d\t%d\n",
182 pBoxDst
->x1
, pBoxDst
->x2
, pBoxDst
->y1
, pBoxDst
->y2
,
186 BitBlt(pScreenPriv
->hdcScreen
,
187 pBoxDst
->x1
, pBoxDst
->y1
,
188 pBoxDst
->x2
- pBoxDst
->x1
, pBoxDst
->y2
- pBoxDst
->y1
,
189 pScreenPriv
->hdcScreen
, ppt
->x
, ppt
->y
, SRCCOPY
);
192 /* Cleanup the regions, etc. */
194 RegionDestroy(prgnDst
);
197 /* See Porting Layer Definition - p. 37 */
198 /* See mfb/mfbwindow.c - mfbChangeWindowAttributes() */
201 winChangeWindowAttributesNativeGDI(WindowPtr pWin
, unsigned long mask
)
204 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
206 winScreenPriv(pScreen
);
209 winTrace("winChangeWindowAttributesNativeGDI (%p)\n", pWin
);
212 WIN_UNWRAP(ChangeWindowAttributes
);
213 fResult
= (*pScreen
->ChangeWindowAttributes
) (pWin
, mask
);
214 WIN_WRAP(ChangeWindowAttributes
, winChangeWindowAttributesNativeGDI
);
217 * NOTE: We do not currently need to do anything here.
223 /* See Porting Layer Definition - p. 37
224 * Also referred to as UnrealizeWindow
228 winUnmapWindowNativeGDI(WindowPtr pWin
)
231 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
233 winScreenPriv(pScreen
);
236 winTrace("winUnmapWindowNativeGDI (%p)\n", pWin
);
239 WIN_UNWRAP(UnrealizeWindow
);
240 fResult
= (*pScreen
->UnrealizeWindow
) (pWin
);
241 WIN_WRAP(UnrealizeWindow
, winUnmapWindowNativeGDI
);
246 /* See Porting Layer Definition - p. 37
247 * Also referred to as RealizeWindow
251 winMapWindowNativeGDI(WindowPtr pWin
)
254 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
256 winScreenPriv(pScreen
);
259 winTrace("winMapWindowNativeGDI (%p)\n", pWin
);
262 WIN_UNWRAP(RealizeWindow
);
263 fResult
= (*pScreen
->RealizeWindow
) (pWin
);
264 WIN_WRAP(RealizeWindow
, winMapWindowMultiWindow
);
271 /* See Porting Layer Definition - p. 37 */
272 /* See mfb/mfbwindow.c - mfbCreateWindow() */
275 winCreateWindowRootless(WindowPtr pWin
)
277 Bool fResult
= FALSE
;
278 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
281 winScreenPriv(pScreen
);
284 winTrace("winCreateWindowRootless (%p)\n", pWin
);
287 WIN_UNWRAP(CreateWindow
);
288 fResult
= (*pScreen
->CreateWindow
) (pWin
);
289 WIN_WRAP(CreateWindow
, winCreateWindowRootless
);
291 pWinPriv
->hRgn
= NULL
;
296 /* See Porting Layer Definition - p. 37 */
297 /* See mfb/mfbwindow.c - mfbDestroyWindow() */
300 winDestroyWindowRootless(WindowPtr pWin
)
302 Bool fResult
= FALSE
;
303 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
306 winScreenPriv(pScreen
);
309 winTrace("winDestroyWindowRootless (%p)\n", pWin
);
312 WIN_UNWRAP(DestroyWindow
);
313 fResult
= (*pScreen
->DestroyWindow
) (pWin
);
314 WIN_WRAP(DestroyWindow
, winDestroyWindowRootless
);
316 if (pWinPriv
->hRgn
!= NULL
) {
317 DeleteObject(pWinPriv
->hRgn
);
318 pWinPriv
->hRgn
= NULL
;
321 winUpdateRgnRootless(pWin
);
326 /* See Porting Layer Definition - p. 37 */
327 /* See mfb/mfbwindow.c - mfbPositionWindow() */
330 winPositionWindowRootless(WindowPtr pWin
, int x
, int y
)
332 Bool fResult
= FALSE
;
333 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
335 winScreenPriv(pScreen
);
338 winTrace("winPositionWindowRootless (%p)\n", pWin
);
341 WIN_UNWRAP(PositionWindow
);
342 fResult
= (*pScreen
->PositionWindow
) (pWin
, x
, y
);
343 WIN_WRAP(PositionWindow
, winPositionWindowRootless
);
345 winUpdateRgnRootless(pWin
);
350 /* See Porting Layer Definition - p. 37 */
351 /* See mfb/mfbwindow.c - mfbChangeWindowAttributes() */
354 winChangeWindowAttributesRootless(WindowPtr pWin
, unsigned long mask
)
356 Bool fResult
= FALSE
;
357 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
359 winScreenPriv(pScreen
);
362 winTrace("winChangeWindowAttributesRootless (%p)\n", pWin
);
365 WIN_UNWRAP(ChangeWindowAttributes
);
366 fResult
= (*pScreen
->ChangeWindowAttributes
) (pWin
, mask
);
367 WIN_WRAP(ChangeWindowAttributes
, winChangeWindowAttributesRootless
);
369 winUpdateRgnRootless(pWin
);
374 /* See Porting Layer Definition - p. 37
375 * Also referred to as UnrealizeWindow
379 winUnmapWindowRootless(WindowPtr pWin
)
381 Bool fResult
= FALSE
;
382 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
385 winScreenPriv(pScreen
);
388 winTrace("winUnmapWindowRootless (%p)\n", pWin
);
391 WIN_UNWRAP(UnrealizeWindow
);
392 fResult
= (*pScreen
->UnrealizeWindow
) (pWin
);
393 WIN_WRAP(UnrealizeWindow
, winUnmapWindowRootless
);
395 if (pWinPriv
->hRgn
!= NULL
) {
396 DeleteObject(pWinPriv
->hRgn
);
397 pWinPriv
->hRgn
= NULL
;
400 winUpdateRgnRootless(pWin
);
405 /* See Porting Layer Definition - p. 37
406 * Also referred to as RealizeWindow
410 winMapWindowRootless(WindowPtr pWin
)
412 Bool fResult
= FALSE
;
413 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
415 winScreenPriv(pScreen
);
418 winTrace("winMapWindowRootless (%p)\n", pWin
);
421 WIN_UNWRAP(RealizeWindow
);
422 fResult
= (*pScreen
->RealizeWindow
) (pWin
);
423 WIN_WRAP(RealizeWindow
, winMapWindowRootless
);
425 winReshapeRootless(pWin
);
427 winUpdateRgnRootless(pWin
);
433 winSetShapeRootless(WindowPtr pWin
, int kind
)
435 ScreenPtr pScreen
= pWin
->drawable
.pScreen
;
437 winScreenPriv(pScreen
);
440 winTrace("winSetShapeRootless (%p, %i)\n", pWin
, kind
);
443 WIN_UNWRAP(SetShape
);
444 (*pScreen
->SetShape
) (pWin
, kind
);
445 WIN_WRAP(SetShape
, winSetShapeRootless
);
447 winReshapeRootless(pWin
);
448 winUpdateRgnRootless(pWin
);
454 * Local function for adding a region to the Windows window region
459 winAddRgn(WindowPtr pWin
, pointer data
)
461 int iX
, iY
, iWidth
, iHeight
, iBorder
;
462 HRGN hRgn
= *(HRGN
*) data
;
467 /* If pWin is not Root */
468 if (pWin
->parent
!= NULL
) {
470 winDebug("winAddRgn ()\n");
473 iBorder
= wBorderWidth(pWin
);
475 iX
= pWin
->drawable
.x
- iBorder
;
476 iY
= pWin
->drawable
.y
- iBorder
;
478 iWidth
= pWin
->drawable
.width
+ iBorder
* 2;
479 iHeight
= pWin
->drawable
.height
+ iBorder
* 2;
481 hRgnWin
= CreateRectRgn(0, 0, iWidth
, iHeight
);
483 if (hRgnWin
== NULL
) {
484 ErrorF("winAddRgn - CreateRectRgn () failed\n");
485 ErrorF(" Rect %d %d %d %d\n",
486 iX
, iY
, iX
+ iWidth
, iY
+ iHeight
);
489 if (pWinPriv
->hRgn
) {
490 if (CombineRgn(hRgnWin
, hRgnWin
, pWinPriv
->hRgn
, RGN_AND
)
492 ErrorF("winAddRgn - CombineRgn () failed\n");
496 OffsetRgn(hRgnWin
, iX
, iY
);
498 if (CombineRgn(hRgn
, hRgn
, hRgnWin
, RGN_OR
) == ERROR
) {
499 ErrorF("winAddRgn - CombineRgn () failed\n");
502 DeleteObject(hRgnWin
);
504 return WT_DONTWALKCHILDREN
;
507 return WT_WALKCHILDREN
;
512 * Local function to update the Windows window's region
517 winUpdateRgnRootless(WindowPtr pWin
)
519 HRGN hRgn
= CreateRectRgn(0, 0, 0, 0);
522 WalkTree(pWin
->drawable
.pScreen
, winAddRgn
, &hRgn
);
523 SetWindowRgn(winGetScreenPriv(pWin
->drawable
.pScreen
)->hwndScreen
,
527 ErrorF("winUpdateRgnRootless - CreateRectRgn failed.\n");
533 winReshapeRootless(WindowPtr pWin
)
536 RegionRec rrNewShape
;
537 BoxPtr pShape
, pRects
, pEnd
;
543 winDebug("winReshapeRootless ()\n");
546 /* Bail if the window is the root window */
547 if (pWin
->parent
== NULL
)
550 /* Bail if the window is not top level */
551 if (pWin
->parent
->parent
!= NULL
)
554 /* Free any existing window region stored in the window privates */
555 if (pWinPriv
->hRgn
!= NULL
) {
556 DeleteObject(pWinPriv
->hRgn
);
557 pWinPriv
->hRgn
= NULL
;
560 /* Bail if the window has no bounding region defined */
561 if (!wBoundingShape(pWin
))
564 RegionNull(&rrNewShape
);
565 RegionCopy(&rrNewShape
, wBoundingShape(pWin
));
566 RegionTranslate(&rrNewShape
, pWin
->borderWidth
, pWin
->borderWidth
);
568 nRects
= RegionNumRects(&rrNewShape
);
569 pShape
= RegionRects(&rrNewShape
);
572 /* Create initial empty Windows region */
573 hRgn
= CreateRectRgn(0, 0, 0, 0);
575 /* Loop through all rectangles in the X region */
576 for (pRects
= pShape
, pEnd
= pShape
+ nRects
; pRects
< pEnd
; pRects
++) {
577 /* Create a Windows region for the X rectangle */
578 hRgnRect
= CreateRectRgn(pRects
->x1
, pRects
->y1
,
579 pRects
->x2
, pRects
->y2
);
580 if (hRgnRect
== NULL
) {
581 ErrorF("winReshapeRootless - CreateRectRgn() failed\n");
584 /* Merge the Windows region with the accumulated region */
585 if (CombineRgn(hRgn
, hRgn
, hRgnRect
, RGN_OR
) == ERROR
) {
586 ErrorF("winReshapeRootless - CombineRgn() failed\n");
589 /* Delete the temporary Windows region */
590 DeleteObject(hRgnRect
);
593 /* Save a handle to the composite region in the window privates */
594 pWinPriv
->hRgn
= hRgn
;
597 RegionUninit(&rrNewShape
);