Initial commit
[xorg_rtime.git] / xorg-server-1.4 / hw / xwin / winwindow.c
blobe844dbfb35904708bc24c08d42edb7d07c530ae4
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: Harold L Hunt II
29 * Kensuke Matsuzaki
32 #ifdef HAVE_XWIN_CONFIG_H
33 #include <xwin-config.h>
34 #endif
35 #include "win.h"
39 * Prototypes for local functions
42 static int
43 winAddRgn (WindowPtr pWindow, pointer data);
45 static
46 void
47 winUpdateRgnRootless (WindowPtr pWindow);
49 #ifdef SHAPE
50 static
51 void
52 winReshapeRootless (WindowPtr pWin);
53 #endif
56 #ifdef XWIN_NATIVEGDI
57 /* See Porting Layer Definition - p. 37 */
58 /* See mfb/mfbwindow.c - mfbCreateWindow() */
60 Bool
61 winCreateWindowNativeGDI (WindowPtr pWin)
63 ScreenPtr pScreen = pWin->drawable.pScreen;
64 winWindowPriv(pWin);
65 winScreenPriv(pScreen);
67 #if CYGDEBUG
68 winTrace ("winCreateWindowNativeGDI (%p)\n", pWin);
69 #endif
71 WIN_UNWRAP(CreateWindow);
72 fResult = (*pScreen->CreateWindow) (pWin);
73 WIN_WRAP(CreateWindow, winCreateWindowNativeGDI);
75 return fResult;
79 /* See Porting Layer Definition - p. 37 */
80 /* See mfb/mfbwindow.c - mfbDestroyWindow() */
82 Bool
83 winDestroyWindowNativeGDI (WindowPtr pWin)
85 Bool fResult = TRUE;
86 ScreenPtr pScreen = pWin->drawable.pScreen;
87 winWindowPriv(pWin);
88 winScreenPriv(pScreen);
90 #if CYGDEBUG
91 winTrace ("winDestroyWindowNativeGDI (%p)\n", pWin);
92 #endif
94 WIN_UNWRAP(DestroyWindow);
95 fResult = (*pScreen->DestroyWindow)(pWin);
96 WIN_WRAP(DestroyWindow, winDestroyWindowNativeGDI);
98 return fResult;
102 /* See Porting Layer Definition - p. 37 */
103 /* See mfb/mfbwindow.c - mfbPositionWindow() */
105 Bool
106 winPositionWindowNativeGDI (WindowPtr pWin, int x, int y)
108 Bool fResult = TRUE;
109 ScreenPtr pScreen = pWin->drawable.pScreen;
110 winWindowPriv(pWin);
111 winScreenPriv(pScreen);
113 #if CYGDEBUG
114 winTrace ("winPositionWindowNativeGDI (%p)\n", pWin);
115 #endif
117 WIN_UNWRAP(PositionWindow);
118 fResult = (*pScreen->PositionWindow)(pWin, x, y);
119 WIN_WRAP(PositionWindow, winPositionWindowNativeGDI);
121 return fResult;
125 /* See Porting Layer Definition - p. 39 */
126 /* See mfb/mfbwindow.c - mfbCopyWindow() */
128 void
129 winCopyWindowNativeGDI (WindowPtr pWin,
130 DDXPointRec ptOldOrg,
131 RegionPtr prgnSrc)
133 DDXPointPtr pptSrc;
134 DDXPointPtr ppt;
135 RegionPtr prgnDst;
136 BoxPtr pBox;
137 int dx, dy;
138 int i, nbox;
139 WindowPtr pwinRoot;
140 BoxPtr pBoxDst;
141 ScreenPtr pScreen = pWin->drawable.pScreen;
142 winScreenPriv(pScreen);
144 #if 0
145 ErrorF ("winCopyWindow\n");
146 #endif
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,
161 prgnSrc);
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))))
171 return;
173 /* Set an iterator pointer */
174 ppt = pptSrc;
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);
185 ppt = pptSrc;
187 #if 0
188 ErrorF ("winCopyWindow - x1\tx2\ty1\ty2\tx\ty\n");
189 #endif
191 /* BitBlt each source to the destination point */
192 for (i = nbox; --i >= 0; pBoxDst++, ppt++)
194 #if 0
195 ErrorF ("winCopyWindow - %d\t%d\t%d\t%d\t%d\t%d\n",
196 pBoxDst->x1, pBoxDst->x2, pBoxDst->y1, pBoxDst->y2,
197 ppt->x, ppt->y);
198 #endif
200 BitBlt (pScreenPriv->hdcScreen,
201 pBoxDst->x1, pBoxDst->y1,
202 pBoxDst->x2 - pBoxDst->x1, pBoxDst->y2 - pBoxDst->y1,
203 pScreenPriv->hdcScreen,
204 ppt->x, ppt->y,
205 SRCCOPY);
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() */
217 Bool
218 winChangeWindowAttributesNativeGDI (WindowPtr pWin, unsigned long mask)
220 Bool fResult = TRUE;
221 ScreenPtr pScreen = pWin->drawable.pScreen;
222 winWindowPriv(pWin);
223 winScreenPriv(pScreen);
225 #if CYGDEBUG
226 winTrace ("winChangeWindowAttributesNativeGDI (%p)\n", pWin);
227 #endif
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.
237 return fResult;
241 /* See Porting Layer Definition - p. 37
242 * Also referred to as UnrealizeWindow
245 Bool
246 winUnmapWindowNativeGDI (WindowPtr pWin)
248 Bool fResult = TRUE;
249 ScreenPtr pScreen = pWin->drawable.pScreen;
250 winWindowPriv(pWin);
251 winScreenPriv(pScreen);
253 #if CYGDEBUG
254 winTrace ("winUnmapWindowNativeGDI (%p)\n", pWin);
255 #endif
257 WIN_UNWRAP(UnrealizeWindow);
258 fResult = (*pScreen->UnrealizeWindow)(pWin);
259 WIN_WRAP(UnrealizeWindow, winUnmapWindowNativeGDI);
261 return fResult;
265 /* See Porting Layer Definition - p. 37
266 * Also referred to as RealizeWindow
269 Bool
270 winMapWindowNativeGDI (WindowPtr pWin)
272 Bool fResult = TRUE;
273 ScreenPtr pScreen = pWin->drawable.pScreen;
274 winWindowPriv(pWin);
275 winScreenPriv(pScreen);
277 #if CYGDEBUG
278 winTrace ("winMapWindowNativeGDI (%p)\n", pWin);
279 #endif
281 WIN_UNWRAP(RealizeWindow);
282 fResult = (*pScreen->RealizeWindow)(pWin);
283 WIN_WRAP(RealizeWindow, winMapWindowMultiWindow);
285 return fResult;
288 #endif
291 /* See Porting Layer Definition - p. 37 */
292 /* See mfb/mfbwindow.c - mfbCreateWindow() */
294 Bool
295 winCreateWindowRootless (WindowPtr pWin)
297 Bool fResult = FALSE;
298 ScreenPtr pScreen = pWin->drawable.pScreen;
299 winWindowPriv(pWin);
300 winScreenPriv(pScreen);
302 #if CYGDEBUG
303 winTrace ("winCreateWindowRootless (%p)\n", pWin);
304 #endif
306 WIN_UNWRAP(CreateWindow);
307 fResult = (*pScreen->CreateWindow) (pWin);
308 WIN_WRAP(CreateWindow, winCreateWindowRootless);
310 pWinPriv->hRgn = NULL;
312 return fResult;
316 /* See Porting Layer Definition - p. 37 */
317 /* See mfb/mfbwindow.c - mfbDestroyWindow() */
319 Bool
320 winDestroyWindowRootless (WindowPtr pWin)
322 Bool fResult = FALSE;
323 ScreenPtr pScreen = pWin->drawable.pScreen;
324 winWindowPriv(pWin);
325 winScreenPriv(pScreen);
327 #if CYGDEBUG
328 winTrace ("winDestroyWindowRootless (%p)\n", pWin);
329 #endif
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);
343 return fResult;
347 /* See Porting Layer Definition - p. 37 */
348 /* See mfb/mfbwindow.c - mfbPositionWindow() */
350 Bool
351 winPositionWindowRootless (WindowPtr pWin, int x, int y)
353 Bool fResult = FALSE;
354 ScreenPtr pScreen = pWin->drawable.pScreen;
355 winWindowPriv(pWin);
356 winScreenPriv(pScreen);
359 #if CYGDEBUG
360 winTrace ("winPositionWindowRootless (%p)\n", pWin);
361 #endif
363 WIN_UNWRAP(PositionWindow);
364 fResult = (*pScreen->PositionWindow)(pWin, x, y);
365 WIN_WRAP(PositionWindow, winPositionWindowRootless);
367 winUpdateRgnRootless (pWin);
369 return fResult;
373 /* See Porting Layer Definition - p. 37 */
374 /* See mfb/mfbwindow.c - mfbChangeWindowAttributes() */
376 Bool
377 winChangeWindowAttributesRootless (WindowPtr pWin, unsigned long mask)
379 Bool fResult = FALSE;
380 ScreenPtr pScreen = pWin->drawable.pScreen;
381 winWindowPriv(pWin);
382 winScreenPriv(pScreen);
384 #if CYGDEBUG
385 winTrace ("winChangeWindowAttributesRootless (%p)\n", pWin);
386 #endif
388 WIN_UNWRAP(ChangeWindowAttributes);
389 fResult = (*pScreen->ChangeWindowAttributes)(pWin, mask);
390 WIN_WRAP(ChangeWindowAttributes, winChangeWindowAttributesRootless);
392 winUpdateRgnRootless (pWin);
394 return fResult;
398 /* See Porting Layer Definition - p. 37
399 * Also referred to as UnrealizeWindow
402 Bool
403 winUnmapWindowRootless (WindowPtr pWin)
405 Bool fResult = FALSE;
406 ScreenPtr pScreen = pWin->drawable.pScreen;
407 winWindowPriv(pWin);
408 winScreenPriv(pScreen);
410 #if CYGDEBUG
411 winTrace ("winUnmapWindowRootless (%p)\n", pWin);
412 #endif
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);
426 return fResult;
430 /* See Porting Layer Definition - p. 37
431 * Also referred to as RealizeWindow
434 Bool
435 winMapWindowRootless (WindowPtr pWin)
437 Bool fResult = FALSE;
438 ScreenPtr pScreen = pWin->drawable.pScreen;
439 winWindowPriv(pWin);
440 winScreenPriv(pScreen);
442 #if CYGDEBUG
443 winTrace ("winMapWindowRootless (%p)\n", pWin);
444 #endif
446 WIN_UNWRAP(RealizeWindow);
447 fResult = (*pScreen->RealizeWindow)(pWin);
448 WIN_WRAP(RealizeWindow, winMapWindowRootless);
450 #ifdef SHAPE
451 winReshapeRootless (pWin);
452 #endif
454 winUpdateRgnRootless (pWin);
456 return fResult;
460 #ifdef SHAPE
461 void
462 winSetShapeRootless (WindowPtr pWin)
464 ScreenPtr pScreen = pWin->drawable.pScreen;
465 winWindowPriv(pWin);
466 winScreenPriv(pScreen);
468 #if CYGDEBUG
469 winTrace ("winSetShapeRootless (%p)\n", pWin);
470 #endif
472 WIN_UNWRAP(SetShape);
473 (*pScreen->SetShape)(pWin);
474 WIN_WRAP(SetShape, winSetShapeRootless);
476 winReshapeRootless (pWin);
477 winUpdateRgnRootless (pWin);
479 return;
481 #endif
485 * Local function for adding a region to the Windows window region
488 static
490 winAddRgn (WindowPtr pWin, pointer data)
492 int iX, iY, iWidth, iHeight, iBorder;
493 HRGN hRgn = *(HRGN*)data;
494 HRGN hRgnWin;
495 winWindowPriv(pWin);
497 /* If pWin is not Root */
498 if (pWin->parent != NULL)
500 #if CYGDEBUG
501 winDebug ("winAddRgn ()\n");
502 #endif
503 if (pWin->mapped)
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);
515 if (hRgnWin == NULL)
517 ErrorF ("winAddRgn - CreateRectRgn () failed\n");
518 ErrorF (" Rect %d %d %d %d\n",
519 iX, iY, iX + iWidth, iY + iHeight);
522 if (pWinPriv->hRgn)
524 if (CombineRgn (hRgnWin, hRgnWin, pWinPriv->hRgn, RGN_AND)
525 == ERROR)
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;
542 else
544 return WT_WALKCHILDREN;
550 * Local function to update the Windows window's region
553 static
554 void
555 winUpdateRgnRootless (WindowPtr pWin)
557 HRGN hRgn = CreateRectRgn (0, 0, 0, 0);
559 if (hRgn != NULL)
561 WalkTree (pWin->drawable.pScreen, winAddRgn, &hRgn);
562 SetWindowRgn (winGetScreenPriv(pWin->drawable.pScreen)->hwndScreen,
563 hRgn, TRUE);
565 else
567 ErrorF ("winUpdateRgnRootless - CreateRectRgn failed.\n");
572 #ifdef SHAPE
573 static
574 void
575 winReshapeRootless (WindowPtr pWin)
577 int nRects;
578 /* ScreenPtr pScreen = pWin->drawable.pScreen;*/
579 RegionRec rrNewShape;
580 BoxPtr pShape, pRects, pEnd;
581 HRGN hRgn, hRgnRect;
582 winWindowPriv(pWin);
584 #if CYGDEBUG
585 winDebug ("winReshapeRootless ()\n");
586 #endif
588 /* Bail if the window is the root window */
589 if (pWin->parent == NULL)
590 return;
592 /* Bail if the window is not top level */
593 if (pWin->parent->parent != NULL)
594 return;
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))
605 return;
607 REGION_NULL(pScreen, &rrNewShape);
608 REGION_COPY(pScreen, &rrNewShape, wBoundingShape(pWin));
609 REGION_TRANSLATE(pScreen, &rrNewShape, pWin->borderWidth,
610 pWin->borderWidth);
612 nRects = REGION_NUM_RECTS(&rrNewShape);
613 pShape = REGION_RECTS(&rrNewShape);
615 if (nRects > 0)
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);
647 return;
649 #endif