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
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(x11drv
);
33 /***********************************************************************
34 * X11DRV_GetRegionData
36 * Calls GetRegionData on the given region and converts the rectangle
37 * array to XRectangle format. The returned buffer must be freed by
38 * caller using HeapFree(GetProcessHeap(),...).
39 * If hdc_lptodp is not 0, the rectangles are converted through LPtoDP.
41 RGNDATA
*X11DRV_GetRegionData( HRGN hrgn
, HDC hdc_lptodp
)
49 if (!(size
= GetRegionData( hrgn
, 0, NULL
))) return NULL
;
50 if (sizeof(XRectangle
) > sizeof(RECT
))
52 /* add extra size for XRectangle array */
53 int count
= (size
- sizeof(RGNDATAHEADER
)) / sizeof(RECT
);
54 size
+= count
* (sizeof(XRectangle
) - sizeof(RECT
));
56 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return NULL
;
57 if (!GetRegionData( hrgn
, size
, data
))
59 HeapFree( GetProcessHeap(), 0, data
);
63 rect
= (RECT
*)data
->Buffer
;
64 xrect
= (XRectangle
*)data
->Buffer
;
65 if (hdc_lptodp
) /* map to device coordinates */
67 LPtoDP( hdc_lptodp
, (POINT
*)rect
, data
->rdh
.nCount
* 2 );
68 for (i
= 0; i
< data
->rdh
.nCount
; i
++)
70 if (rect
[i
].right
< rect
[i
].left
)
72 INT tmp
= rect
[i
].right
;
73 rect
[i
].right
= rect
[i
].left
;
76 if (rect
[i
].bottom
< rect
[i
].top
)
78 INT tmp
= rect
[i
].bottom
;
79 rect
[i
].bottom
= rect
[i
].top
;
85 if (sizeof(XRectangle
) > sizeof(RECT
))
87 /* need to start from the end */
88 for (i
= data
->rdh
.nCount
-1; i
>=0; i
--)
91 xrect
[i
].x
= tmp
.left
;
93 xrect
[i
].width
= tmp
.right
- tmp
.left
;
94 xrect
[i
].height
= tmp
.bottom
- tmp
.top
;
99 for (i
= 0; i
< data
->rdh
.nCount
; i
++)
102 xrect
[i
].x
= tmp
.left
;
103 xrect
[i
].y
= tmp
.top
;
104 xrect
[i
].width
= tmp
.right
- tmp
.left
;
105 xrect
[i
].height
= tmp
.bottom
- tmp
.top
;
112 /***********************************************************************
113 * X11DRV_SetDeviceClipping
115 void X11DRV_SetDeviceClipping( X11DRV_PDEVICE
*physDev
, HRGN hrgn
)
119 if (!(data
= X11DRV_GetRegionData( hrgn
, 0 ))) return;
120 TSXSetClipRectangles( gdi_display
, physDev
->gc
, physDev
->org
.x
, physDev
->org
.y
,
121 (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
;
145 TSXSetSubwindowMode( gdi_display
, physDev
->gc
, mode
);
146 GDI_ReleaseObj( hdc
);
151 /***********************************************************************
152 * X11DRV_StartGraphicsExposures
154 * Set the DC in graphics exposures mode
156 void X11DRV_StartGraphicsExposures( HDC hdc
)
158 DC
*dc
= DC_GetDCPtr( hdc
);
161 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
162 TSXSetGraphicsExposures( gdi_display
, physDev
->gc
, True
);
163 physDev
->exposures
= 0;
164 GDI_ReleaseObj( hdc
);
169 /***********************************************************************
170 * X11DRV_EndGraphicsExposures
172 * End the graphics exposures mode and process the events
174 void X11DRV_EndGraphicsExposures( HDC hdc
, HRGN hrgn
)
177 DC
*dc
= DC_GetDCPtr( hdc
);
182 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
184 SetRectRgn( hrgn
, 0, 0, 0, 0 );
186 XSetGraphicsExposures( gdi_display
, physDev
->gc
, False
);
187 if (physDev
->exposures
)
189 XSync( gdi_display
, False
);
192 XWindowEvent( gdi_display
, physDev
->drawable
, ~0, &event
);
193 if (event
.type
== NoExpose
) break;
194 if (event
.type
== GraphicsExpose
)
196 int x
= event
.xgraphicsexpose
.x
- physDev
->org
.x
;
197 int y
= event
.xgraphicsexpose
.y
- physDev
->org
.y
;
199 TRACE( "got %d,%d %dx%d count %d\n",
200 x
, y
, event
.xgraphicsexpose
.width
, event
.xgraphicsexpose
.height
,
201 event
.xgraphicsexpose
.count
);
203 if (!tmp
) tmp
= CreateRectRgn( 0, 0, 0, 0 );
204 SetRectRgn( tmp
, x
, y
,
205 x
+ event
.xgraphicsexpose
.width
,
206 y
+ event
.xgraphicsexpose
.height
);
207 CombineRgn( hrgn
, hrgn
, tmp
, RGN_OR
);
208 if (!event
.xgraphicsexpose
.count
) break;
212 ERR( "got unexpected event %d\n", event
.type
);
216 if (tmp
) DeleteObject( tmp
);
219 GDI_ReleaseObj( hdc
);