msvcrt: New implementation of fcvt.
[wine/multimedia.git] / dlls / winex11.drv / clipping.c
blob5cf806f2d16de1aa4e30b88aaf1fd60fd6edd19a
1 /*
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
21 #include "config.h"
23 #include <stdio.h>
25 #include "x11drv.h"
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 )
37 RGNDATA *data;
38 DWORD size;
39 unsigned int i;
40 RECT *rect, tmp;
41 XRectangle *xrect;
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 );
54 return NULL;
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;
68 rect[i].left = tmp;
70 if (rect[i].bottom < rect[i].top)
72 INT tmp = rect[i].bottom;
73 rect[i].bottom = rect[i].top;
74 rect[i].top = tmp;
79 if (sizeof(XRectangle) > sizeof(RECT))
81 int j;
82 /* need to start from the end */
83 for (j = data->rdh.nCount-1; j >= 0; j--)
85 tmp = rect[j];
86 xrect[j].x = tmp.left;
87 xrect[j].y = tmp.top;
88 xrect[j].width = tmp.right - tmp.left;
89 xrect[j].height = tmp.bottom - tmp.top;
92 else
94 for (i = 0; i < data->rdh.nCount; i++)
96 tmp = rect[i];
97 xrect[i].x = tmp.left;
98 xrect[i].y = tmp.top;
99 xrect[i].width = tmp.right - tmp.left;
100 xrect[i].height = tmp.bottom - tmp.top;
103 return data;
107 /***********************************************************************
108 * X11DRV_SetDeviceClipping
110 void X11DRV_SetDeviceClipping( X11DRV_PDEVICE *physDev, HRGN vis_rgn, HRGN clip_rgn )
112 RGNDATA *data;
114 CombineRgn( physDev->region, vis_rgn, clip_rgn, clip_rgn ? RGN_AND : RGN_COPY );
115 if (!(data = X11DRV_GetRegionData( physDev->region, 0 ))) return;
117 wine_tsx11_lock();
118 XSetClipRectangles( gdi_display, physDev->gc, physDev->dc_rect.left, physDev->dc_rect.top,
119 (XRectangle *)data->Buffer, data->rdh.nCount, YXBanded );
120 wine_tsx11_unlock();
121 HeapFree( GetProcessHeap(), 0, data );