2 * X11DRV clipping functions
4 * Copyright 1998 Huw Davies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 /***********************************************************************
28 * X11DRV_GetRegionData
30 * Calls GetRegionData on the given region and converts the rectangle
31 * array to XRectangle format. The returned buffer must be freed by
32 * caller using HeapFree(GetProcessHeap(),...).
33 * If hdc_lptodp is not 0, the rectangles are converted through LPtoDP.
35 RGNDATA *X11DRV_GetRegionData( HRGN hrgn, HDC hdc_lptodp )
43 if (!(size = GetRegionData( hrgn, 0, NULL ))) return NULL;
44 if (sizeof(XRectangle) > sizeof(RECT))
46 /* add extra size for XRectangle array */
47 int count = (size - sizeof(RGNDATAHEADER)) / sizeof(RECT);
48 size += count * (sizeof(XRectangle) - sizeof(RECT));
50 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return NULL;
51 if (!GetRegionData( hrgn, size, data ))
53 HeapFree( GetProcessHeap(), 0, data );
57 rect = (RECT *)data->Buffer;
58 xrect = (XRectangle *)data->Buffer;
59 if (hdc_lptodp) /* map to device coordinates */
61 LPtoDP( hdc_lptodp, (POINT *)rect, data->rdh.nCount * 2 );
62 for (i = 0; i < data->rdh.nCount; i++)
64 if (rect[i].right < rect[i].left)
66 INT tmp = rect[i].right;
67 rect[i].right = rect[i].left;
70 if (rect[i].bottom < rect[i].top)
72 INT tmp = rect[i].bottom;
73 rect[i].bottom = rect[i].top;
79 if (sizeof(XRectangle) > sizeof(RECT))
82 /* need to start from the end */
83 for (j = data->rdh.nCount-1; j >= 0; j--)
86 xrect[j].x = tmp.left;
88 xrect[j].width = tmp.right - tmp.left;
89 xrect[j].height = tmp.bottom - tmp.top;
94 for (i = 0; i < data->rdh.nCount; i++)
97 xrect[i].x = tmp.left;
99 xrect[i].width = tmp.right - tmp.left;
100 xrect[i].height = tmp.bottom - tmp.top;
107 /***********************************************************************
108 * X11DRV_SetDeviceClipping
110 void X11DRV_SetDeviceClipping( X11DRV_PDEVICE *physDev, HRGN vis_rgn, HRGN clip_rgn )
114 CombineRgn( physDev->region, vis_rgn, clip_rgn, clip_rgn ? RGN_AND : RGN_COPY );
115 if (!(data = X11DRV_GetRegionData( physDev->region, 0 ))) return;
118 XSetClipRectangles( gdi_display, physDev->gc, physDev->dc_rect.left, physDev->dc_rect.top,
119 (XRectangle *)data->Buffer, data->rdh.nCount, YXBanded );
121 HeapFree( GetProcessHeap(), 0, data );