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
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
31 /***********************************************************************
32 * X11DRV_GetRegionData
34 * Calls GetRegionData on the given region and converts the rectangle
35 * array to XRectangle format. The returned buffer must be freed by
36 * caller using HeapFree(GetProcessHeap(),...).
37 * If hdc_lptodp is not 0, the rectangles are converted through LPtoDP.
39 RGNDATA *X11DRV_GetRegionData( HRGN hrgn, HDC hdc_lptodp )
47 if (!(size = GetRegionData( hrgn, 0, NULL ))) return NULL;
48 if (sizeof(XRectangle) > sizeof(RECT))
50 /* add extra size for XRectangle array */
51 int count = (size - sizeof(RGNDATAHEADER)) / sizeof(RECT);
52 size += count * (sizeof(XRectangle) - sizeof(RECT));
54 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return NULL;
55 if (!GetRegionData( hrgn, size, data ))
57 HeapFree( GetProcessHeap(), 0, data );
61 rect = (RECT *)data->Buffer;
62 xrect = (XRectangle *)data->Buffer;
63 if (hdc_lptodp) /* map to device coordinates */
65 LPtoDP( hdc_lptodp, (POINT *)rect, data->rdh.nCount * 2 );
66 for (i = 0; i < data->rdh.nCount; i++)
68 if (rect[i].right < rect[i].left)
70 INT tmp = rect[i].right;
71 rect[i].right = rect[i].left;
74 if (rect[i].bottom < rect[i].top)
76 INT tmp = rect[i].bottom;
77 rect[i].bottom = rect[i].top;
83 if (sizeof(XRectangle) > sizeof(RECT))
85 /* need to start from the end */
86 for (i = data->rdh.nCount-1; i >=0; i--)
89 xrect[i].x = tmp.left;
91 xrect[i].width = tmp.right - tmp.left;
92 xrect[i].height = tmp.bottom - tmp.top;
97 for (i = 0; i < data->rdh.nCount; 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;
110 /***********************************************************************
111 * X11DRV_SetDeviceClipping
113 void X11DRV_SetDeviceClipping( X11DRV_PDEVICE *physDev, HRGN hrgn )
117 if (!(data = X11DRV_GetRegionData( hrgn, 0 ))) return;
119 XSetClipRectangles( gdi_display, physDev->gc, physDev->org.x, physDev->org.y,
120 (XRectangle *)data->Buffer, data->rdh.nCount, YXBanded );
122 HeapFree( GetProcessHeap(), 0, data );
126 /***********************************************************************
129 * Set the drawable, clipping mode and origin for a DC.
131 void X11DRV_SetDrawable( HDC hdc, Drawable drawable, int mode, const POINT *org,
132 const POINT *drawable_org )
134 DC *dc = DC_GetDCPtr( hdc );
137 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
140 X11DRV_XRender_UpdateDrawable( physDev );
143 physDev->drawable = drawable;
144 physDev->drawable_org = *drawable_org;
146 XSetSubwindowMode( gdi_display, physDev->gc, mode );
148 GDI_ReleaseObj( hdc );
153 /***********************************************************************
154 * X11DRV_StartGraphicsExposures
156 * Set the DC in graphics exposures mode
158 void X11DRV_StartGraphicsExposures( HDC hdc )
160 DC *dc = DC_GetDCPtr( hdc );
163 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
165 XSetGraphicsExposures( gdi_display, physDev->gc, True );
167 physDev->exposures = 0;
168 GDI_ReleaseObj( hdc );
173 /***********************************************************************
174 * X11DRV_EndGraphicsExposures
176 * End the graphics exposures mode and process the events
178 void X11DRV_EndGraphicsExposures( HDC hdc, HRGN hrgn )
181 DC *dc = DC_GetDCPtr( hdc );
186 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
188 SetRectRgn( hrgn, 0, 0, 0, 0 );
190 XSetGraphicsExposures( gdi_display, physDev->gc, False );
191 if (physDev->exposures)
195 XWindowEvent( gdi_display, physDev->drawable, ~0, &event );
196 if (event.type == NoExpose) break;
197 if (event.type == GraphicsExpose)
199 int x = event.xgraphicsexpose.x - physDev->org.x;
200 int y = event.xgraphicsexpose.y - physDev->org.y;
202 TRACE( "got %d,%d %dx%d count %d\n",
203 x, y, event.xgraphicsexpose.width, event.xgraphicsexpose.height,
204 event.xgraphicsexpose.count );
206 if (!tmp) tmp = CreateRectRgn( 0, 0, 0, 0 );
207 SetRectRgn( tmp, x, y,
208 x + event.xgraphicsexpose.width,
209 y + event.xgraphicsexpose.height );
210 CombineRgn( hrgn, hrgn, tmp, RGN_OR );
211 if (!event.xgraphicsexpose.count) break;
215 ERR( "got unexpected event %d\n", event.type );
219 if (tmp) DeleteObject( tmp );
222 GDI_ReleaseObj( hdc );