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
31
/* $XFree86: xc/programs/Xserver/hw/xwin/winwindow.c,v 1.9 2003/11/10 18:22:44 tsi Exp $ */
33
#ifdef HAVE_XWIN_CONFIG_H
34
#include <xwin-config.h>
40
* Prototypes for local functions
44
winAddRgn (WindowPtr pWindow, pointer data);
48
winUpdateRgnRootless (WindowPtr pWindow);
53
winReshapeRootless (WindowPtr pWin);
58
/* See Porting Layer Definition - p. 37 */
59
/* See mfb/mfbwindow.c - mfbCreateWindow() */
62
winCreateWindowNativeGDI (WindowPtr pWin)
64
ScreenPtr pScreen = pWin->drawable.pScreen;
66
winScreenPriv(pScreen);
69
winTrace ("winCreateWindowNativeGDI (%p)\n", pWin);
72
WIN_UNWRAP(CreateWindow);
73
fResult = (*pScreen->CreateWindow) (pWin);
74
WIN_WRAP(CreateWindow, winCreateWindowNativeGDI);
80
/* See Porting Layer Definition - p. 37 */
81
/* See mfb/mfbwindow.c - mfbDestroyWindow() */
84
winDestroyWindowNativeGDI (WindowPtr pWin)
87
ScreenPtr pScreen = pWin->drawable.pScreen;
89
winScreenPriv(pScreen);
92
winTrace ("winDestroyWindowNativeGDI (%p)\n", pWin);
95
WIN_UNWRAP(DestroyWindow);
96
fResult = (*pScreen->DestroyWindow)(pWin);
97
WIN_WRAP(DestroyWindow, winDestroyWindowNativeGDI);
103
/* See Porting Layer Definition - p. 37 */
104
/* See mfb/mfbwindow.c - mfbPositionWindow() */
107
winPositionWindowNativeGDI (WindowPtr pWin, int x, int y)
110
ScreenPtr pScreen = pWin->drawable.pScreen;
112
winScreenPriv(pScreen);
115
winTrace ("winPositionWindowNativeGDI (%p)\n", pWin);
118
WIN_UNWRAP(PositionWindow);
119
fResult = (*pScreen->PositionWindow)(pWin, x, y);
120
WIN_WRAP(PositionWindow, winPositionWindowNativeGDI);
126
/* See Porting Layer Definition - p. 39 */
127
/* See mfb/mfbwindow.c - mfbCopyWindow() */
130
winCopyWindowNativeGDI (WindowPtr pWin,
131
DDXPointRec ptOldOrg,
142
ScreenPtr pScreen = pWin->drawable.pScreen;
143
winScreenPriv(pScreen);
146
ErrorF ("winCopyWindow\n");
149
/* Get a pointer to the root window */
150
pwinRoot = WindowTable[pWin->drawable.pScreen->myNum];
152
/* Create a region for the destination */
153
prgnDst = REGION_CREATE(pWin->drawable.pScreen, NULL, 1);
155
/* Calculate the shift from the source to the destination */
156
dx = ptOldOrg.x - pWin->drawable.x;
157
dy = ptOldOrg.y - pWin->drawable.y;
159
/* Translate the region from the destination to the source? */
160
REGION_TRANSLATE(pWin->drawable.pScreen, prgnSrc, -dx, -dy);
161
REGION_INTERSECT(pWin->drawable.pScreen, prgnDst, &pWin->borderClip,
164
/* Get a pointer to the first box in the region to be copied */
165
pBox = REGION_RECTS(prgnDst);
167
/* Get the number of boxes in the region */
168
nbox = REGION_NUM_RECTS(prgnDst);
170
/* Allocate source points for each box */
171
if(!(pptSrc = (DDXPointPtr )ALLOCATE_LOCAL(nbox * sizeof(DDXPointRec))))
174
/* Set an iterator pointer */
177
/* Calculate the source point of each box? */
178
for (i = nbox; --i >= 0; ppt++, pBox++)
180
ppt->x = pBox->x1 + dx;
181
ppt->y = pBox->y1 + dy;
184
/* Setup loop pointers again */
185
pBoxDst = REGION_RECTS(prgnDst);
189
ErrorF ("winCopyWindow - x1\tx2\ty1\ty2\tx\ty\n");
192
/* BitBlt each source to the destination point */
193
for (i = nbox; --i >= 0; pBoxDst++, ppt++)
196
ErrorF ("winCopyWindow - %d\t%d\t%d\t%d\t%d\t%d\n",
197
pBoxDst->x1, pBoxDst->x2, pBoxDst->y1, pBoxDst->y2,
201
BitBlt (pScreenPriv->hdcScreen,
202
pBoxDst->x1, pBoxDst->y1,
203
pBoxDst->x2 - pBoxDst->x1, pBoxDst->y2 - pBoxDst->y1,
204
pScreenPriv->hdcScreen,
209
/* Cleanup the regions, etc. */
210
DEALLOCATE_LOCAL(pptSrc);
211
REGION_DESTROY(pWin->drawable.pScreen, prgnDst);
215
/* See Porting Layer Definition - p. 37 */
216
/* See mfb/mfbwindow.c - mfbChangeWindowAttributes() */
219
winChangeWindowAttributesNativeGDI (WindowPtr pWin, unsigned long mask)
222
ScreenPtr pScreen = pWin->drawable.pScreen;
224
winScreenPriv(pScreen);
227
winTrace ("winChangeWindowAttributesNativeGDI (%p)\n", pWin);
230
WIN_UNWRAP(ChangeWindowAttributes);
231
fResult = (*pScreen->ChangeWindowAttributes)(pWin, mask);
232
WIN_WRAP(ChangeWindowAttributes, winChangeWindowAttributesNativeGDI);
235
* NOTE: We do not currently need to do anything here.
242
/* See Porting Layer Definition - p. 37
243
* Also referred to as UnrealizeWindow
247
winUnmapWindowNativeGDI (WindowPtr pWin)
250
ScreenPtr pScreen = pWin->drawable.pScreen;
252
winScreenPriv(pScreen);
255
winTrace ("winUnmapWindowNativeGDI (%p)\n", pWin);
258
WIN_UNWRAP(UnrealizeWindow);
259
fResult = (*pScreen->UnrealizeWindow)(pWin);
260
WIN_WRAP(UnrealizeWindow, winUnmapWindowNativeGDI);
266
/* See Porting Layer Definition - p. 37
267
* Also referred to as RealizeWindow
271
winMapWindowNativeGDI (WindowPtr pWin)
274
ScreenPtr pScreen = pWin->drawable.pScreen;
276
winScreenPriv(pScreen);
279
winTrace ("winMapWindowNativeGDI (%p)\n", pWin);
282
WIN_UNWRAP(RealizeWindow);
283
fResult = (*pScreen->RealizeWindow)(pWin);
284
WIN_WRAP(RealizeWindow, winMapWindowMultiWindow);
292
/* See Porting Layer Definition - p. 37 */
293
/* See mfb/mfbwindow.c - mfbCreateWindow() */
296
winCreateWindowRootless (WindowPtr pWin)
298
Bool fResult = FALSE;
299
ScreenPtr pScreen = pWin->drawable.pScreen;
301
winScreenPriv(pScreen);
304
winTrace ("winCreateWindowRootless (%p)\n", pWin);
307
WIN_UNWRAP(CreateWindow);
308
fResult = (*pScreen->CreateWindow) (pWin);
309
WIN_WRAP(CreateWindow, winCreateWindowRootless);
311
pWinPriv->hRgn = NULL;
317
/* See Porting Layer Definition - p. 37 */
318
/* See mfb/mfbwindow.c - mfbDestroyWindow() */
321
winDestroyWindowRootless (WindowPtr pWin)
323
Bool fResult = FALSE;
324
ScreenPtr pScreen = pWin->drawable.pScreen;
326
winScreenPriv(pScreen);
329
winTrace ("winDestroyWindowRootless (%p)\n", pWin);
332
WIN_UNWRAP(DestroyWindow);
333
fResult = (*pScreen->DestroyWindow)(pWin);
334
WIN_WRAP(DestroyWindow, winDestroyWindowRootless);
336
if (pWinPriv->hRgn != NULL)
338
DeleteObject(pWinPriv->hRgn);
339
pWinPriv->hRgn = NULL;
342
winUpdateRgnRootless (pWin);
348
/* See Porting Layer Definition - p. 37 */
349
/* See mfb/mfbwindow.c - mfbPositionWindow() */
352
winPositionWindowRootless (WindowPtr pWin, int x, int y)
354
Bool fResult = FALSE;
355
ScreenPtr pScreen = pWin->drawable.pScreen;
357
winScreenPriv(pScreen);
361
winTrace ("winPositionWindowRootless (%p)\n", pWin);
364
WIN_UNWRAP(PositionWindow);
365
fResult = (*pScreen->PositionWindow)(pWin, x, y);
366
WIN_WRAP(PositionWindow, winPositionWindowRootless);
368
winUpdateRgnRootless (pWin);
374
/* See Porting Layer Definition - p. 37 */
375
/* See mfb/mfbwindow.c - mfbChangeWindowAttributes() */
378
winChangeWindowAttributesRootless (WindowPtr pWin, unsigned long mask)
380
Bool fResult = FALSE;
381
ScreenPtr pScreen = pWin->drawable.pScreen;
383
winScreenPriv(pScreen);
386
winTrace ("winChangeWindowAttributesRootless (%p)\n", pWin);
389
WIN_UNWRAP(ChangeWindowAttributes);
390
fResult = (*pScreen->ChangeWindowAttributes)(pWin, mask);
391
WIN_WRAP(ChangeWindowAttributes, winChangeWindowAttributesRootless);
393
winUpdateRgnRootless (pWin);
399
/* See Porting Layer Definition - p. 37
400
* Also referred to as UnrealizeWindow
404
winUnmapWindowRootless (WindowPtr pWin)
406
Bool fResult = FALSE;
407
ScreenPtr pScreen = pWin->drawable.pScreen;
409
winScreenPriv(pScreen);
412
winTrace ("winUnmapWindowRootless (%p)\n", pWin);
415
WIN_UNWRAP(UnrealizeWindow);
416
fResult = (*pScreen->UnrealizeWindow)(pWin);
417
WIN_WRAP(UnrealizeWindow, winUnmapWindowRootless);
419
if (pWinPriv->hRgn != NULL)
421
DeleteObject(pWinPriv->hRgn);
422
pWinPriv->hRgn = NULL;
425
winUpdateRgnRootless (pWin);
431
/* See Porting Layer Definition - p. 37
432
* Also referred to as RealizeWindow
436
winMapWindowRootless (WindowPtr pWin)
438
Bool fResult = FALSE;
439
ScreenPtr pScreen = pWin->drawable.pScreen;
441
winScreenPriv(pScreen);
444
winTrace ("winMapWindowRootless (%p)\n", pWin);
447
WIN_UNWRAP(RealizeWindow);
448
fResult = (*pScreen->RealizeWindow)(pWin);
449
WIN_WRAP(RealizeWindow, winMapWindowRootless);
452
winReshapeRootless (pWin);
455
winUpdateRgnRootless (pWin);
463
winSetShapeRootless (WindowPtr pWin)
465
ScreenPtr pScreen = pWin->drawable.pScreen;
467
winScreenPriv(pScreen);
470
winTrace ("winSetShapeRootless (%p)\n", pWin);
473
WIN_UNWRAP(SetShape);
474
(*pScreen->SetShape)(pWin);
475
WIN_WRAP(SetShape, winSetShapeRootless);
477
winReshapeRootless (pWin);
478
winUpdateRgnRootless (pWin);
486
* Local function for adding a region to the Windows window region
491
winAddRgn (WindowPtr pWin, pointer data)
493
int iX, iY, iWidth, iHeight, iBorder;
494
HRGN hRgn = *(HRGN*)data;
498
/* If pWin is not Root */
499
if (pWin->parent != NULL)
502
winDebug ("winAddRgn ()\n");
506
iBorder = wBorderWidth (pWin);
508
iX = pWin->drawable.x - iBorder;
509
iY = pWin->drawable.y - iBorder;
511
iWidth = pWin->drawable.width + iBorder * 2;
512
iHeight = pWin->drawable.height + iBorder * 2;
514
hRgnWin = CreateRectRgn (0, 0, iWidth, iHeight);
518
ErrorF ("winAddRgn - CreateRectRgn () failed\n");
519
ErrorF (" Rect %d %d %d %d\n",
520
iX, iY, iX + iWidth, iY + iHeight);
525
if (CombineRgn (hRgnWin, hRgnWin, pWinPriv->hRgn, RGN_AND)
528
ErrorF ("winAddRgn - CombineRgn () failed\n");
532
OffsetRgn (hRgnWin, iX, iY);
534
if (CombineRgn (hRgn, hRgn, hRgnWin, RGN_OR) == ERROR)
536
ErrorF ("winAddRgn - CombineRgn () failed\n");
539
DeleteObject (hRgnWin);
541
return WT_DONTWALKCHILDREN;
545
return WT_WALKCHILDREN;
551
* Local function to update the Windows window's region
556
winUpdateRgnRootless (WindowPtr pWin)
558
HRGN hRgn = CreateRectRgn (0, 0, 0, 0);
562
WalkTree (pWin->drawable.pScreen, winAddRgn, &hRgn);
563
SetWindowRgn (winGetScreenPriv(pWin->drawable.pScreen)->hwndScreen,
568
ErrorF ("winUpdateRgnRootless - CreateRectRgn failed.\n");
576
winReshapeRootless (WindowPtr pWin)
579
/* ScreenPtr pScreen = pWin->drawable.pScreen;*/
580
RegionRec rrNewShape;
581
BoxPtr pShape, pRects, pEnd;
586
winDebug ("winReshapeRootless ()\n");
589
/* Bail if the window is the root window */
590
if (pWin->parent == NULL)
593
/* Bail if the window is not top level */
594
if (pWin->parent->parent != NULL)
597
/* Free any existing window region stored in the window privates */
598
if (pWinPriv->hRgn != NULL)
600
DeleteObject (pWinPriv->hRgn);
601
pWinPriv->hRgn = NULL;
604
/* Bail if the window has no bounding region defined */
605
if (!wBoundingShape (pWin))
608
REGION_NULL(pScreen, &rrNewShape);
609
REGION_COPY(pScreen, &rrNewShape, wBoundingShape(pWin));
610
REGION_TRANSLATE(pScreen, &rrNewShape, pWin->borderWidth,
613
nRects = REGION_NUM_RECTS(&rrNewShape);
614
pShape = REGION_RECTS(&rrNewShape);
618
/* Create initial empty Windows region */
619
hRgn = CreateRectRgn (0, 0, 0, 0);
621
/* Loop through all rectangles in the X region */
622
for (pRects = pShape, pEnd = pShape + nRects; pRects < pEnd; pRects++)
624
/* Create a Windows region for the X rectangle */
625
hRgnRect = CreateRectRgn (pRects->x1, pRects->y1,
626
pRects->x2, pRects->y2);
627
if (hRgnRect == NULL)
629
ErrorF("winReshapeRootless - CreateRectRgn() failed\n");
632
/* Merge the Windows region with the accumulated region */
633
if (CombineRgn (hRgn, hRgn, hRgnRect, RGN_OR) == ERROR)
635
ErrorF("winReshapeRootless - CombineRgn() failed\n");
638
/* Delete the temporary Windows region */
639
DeleteObject (hRgnRect);
642
/* Save a handle to the composite region in the window privates */
643
pWinPriv->hRgn = hRgn;
646
REGION_UNINIT(pScreen, &rrNewShape);