Updated trace to support VERSIONED_PRINTER.
[wine/multimedia.git] / dlls / x11drv / clipping.c
bloba4e91fcb969d0e85b63b8533c7f4eb626443d17b
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include <stdio.h>
25 #include "x11drv.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
30 /***********************************************************************
31 * X11DRV_GetRegionData
33 * Calls GetRegionData on the given region and converts the rectangle
34 * array to XRectangle format. The returned buffer must be freed by
35 * caller using HeapFree(GetProcessHeap(),...).
36 * If hdc_lptodp is not 0, the rectangles are converted through LPtoDP.
38 RGNDATA *X11DRV_GetRegionData( HRGN hrgn, HDC hdc_lptodp )
40 RGNDATA *data;
41 DWORD size;
42 unsigned int i;
43 RECT *rect, tmp;
44 XRectangle *xrect;
46 if (!(size = GetRegionData( hrgn, 0, NULL ))) return NULL;
47 if (sizeof(XRectangle) > sizeof(RECT))
49 /* add extra size for XRectangle array */
50 int count = (size - sizeof(RGNDATAHEADER)) / sizeof(RECT);
51 size += count * (sizeof(XRectangle) - sizeof(RECT));
53 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return NULL;
54 if (!GetRegionData( hrgn, size, data ))
56 HeapFree( GetProcessHeap(), 0, data );
57 return NULL;
60 rect = (RECT *)data->Buffer;
61 xrect = (XRectangle *)data->Buffer;
62 if (hdc_lptodp) /* map to device coordinates */
64 LPtoDP( hdc_lptodp, (POINT *)rect, data->rdh.nCount * 2 );
65 for (i = 0; i < data->rdh.nCount; i++)
67 if (rect[i].right < rect[i].left)
69 INT tmp = rect[i].right;
70 rect[i].right = rect[i].left;
71 rect[i].left = tmp;
73 if (rect[i].bottom < rect[i].top)
75 INT tmp = rect[i].bottom;
76 rect[i].bottom = rect[i].top;
77 rect[i].top = tmp;
82 if (sizeof(XRectangle) > sizeof(RECT))
84 int j;
85 /* need to start from the end */
86 for (j = data->rdh.nCount-1; j >= 0; j--)
88 tmp = rect[j];
89 xrect[j].x = tmp.left;
90 xrect[j].y = tmp.top;
91 xrect[j].width = tmp.right - tmp.left;
92 xrect[j].height = tmp.bottom - tmp.top;
95 else
97 for (i = 0; i < data->rdh.nCount; i++)
99 tmp = rect[i];
100 xrect[i].x = tmp.left;
101 xrect[i].y = tmp.top;
102 xrect[i].width = tmp.right - tmp.left;
103 xrect[i].height = tmp.bottom - tmp.top;
106 return data;
110 /***********************************************************************
111 * X11DRV_SetDeviceClipping
113 void X11DRV_SetDeviceClipping( X11DRV_PDEVICE *physDev, HRGN vis_rgn, HRGN clip_rgn )
115 RGNDATA *data;
117 CombineRgn( physDev->region, vis_rgn, clip_rgn, clip_rgn ? RGN_AND : RGN_COPY );
118 if (!(data = X11DRV_GetRegionData( physDev->region, 0 ))) return;
120 wine_tsx11_lock();
121 XSetClipRectangles( gdi_display, physDev->gc, physDev->org.x, physDev->org.y,
122 (XRectangle *)data->Buffer, data->rdh.nCount, YXBanded );
123 wine_tsx11_unlock();
124 HeapFree( GetProcessHeap(), 0, data );