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
, 0, 0,
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
, int org_x
, int org_y
)
133 DC
*dc
= DC_GetDCPtr( hdc
);
136 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
138 * This function change the coordinate system (DCOrgX,DCOrgY)
139 * values. When it moves the origin, other data like the current clipping
140 * region will not be moved to that new origin. In the case of DCs that are class
141 * or window DCs that clipping region might be a valid value from a previous use
142 * of the DC and changing the origin of the DC without moving the clip region
143 * results in a clip region that is not placed properly in the DC.
144 * This code will save the dc origin, let the SetDrawable
145 * modify the origin and reset the clipping. When the clipping is set,
146 * it is moved according to the new DC origin.
148 if (dc
->hClipRgn
) OffsetRgn( dc
->hClipRgn
, org_x
- dc
->DCOrgX
, org_y
- dc
->DCOrgY
);
151 physDev
->drawable
= drawable
;
152 TSXSetSubwindowMode( gdi_display
, physDev
->gc
, mode
);
154 X11DRV_XRender_UpdateDrawable( physDev
);
155 GDI_ReleaseObj( hdc
);
160 /***********************************************************************
161 * X11DRV_StartGraphicsExposures
163 * Set the DC in graphics exposures mode
165 void X11DRV_StartGraphicsExposures( HDC hdc
)
167 DC
*dc
= DC_GetDCPtr( hdc
);
170 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
171 TSXSetGraphicsExposures( gdi_display
, physDev
->gc
, True
);
172 physDev
->exposures
= 0;
173 GDI_ReleaseObj( hdc
);
178 /***********************************************************************
179 * X11DRV_EndGraphicsExposures
181 * End the graphics exposures mode and process the events
183 void X11DRV_EndGraphicsExposures( HDC hdc
, HRGN hrgn
)
186 DC
*dc
= DC_GetDCPtr( hdc
);
191 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
193 SetRectRgn( hrgn
, 0, 0, 0, 0 );
195 XSetGraphicsExposures( gdi_display
, physDev
->gc
, False
);
196 if (physDev
->exposures
)
198 XSync( gdi_display
, False
);
201 XWindowEvent( gdi_display
, physDev
->drawable
, ~0, &event
);
202 if (event
.type
== NoExpose
) break;
203 if (event
.type
== GraphicsExpose
)
205 int x
= event
.xgraphicsexpose
.x
- dc
->DCOrgX
;
206 int y
= event
.xgraphicsexpose
.y
- dc
->DCOrgY
;
208 TRACE( "got %d,%d %dx%d count %d\n",
209 x
, y
, event
.xgraphicsexpose
.width
, event
.xgraphicsexpose
.height
,
210 event
.xgraphicsexpose
.count
);
212 if (!tmp
) tmp
= CreateRectRgn( 0, 0, 0, 0 );
213 SetRectRgn( tmp
, x
, y
,
214 x
+ event
.xgraphicsexpose
.width
,
215 y
+ event
.xgraphicsexpose
.height
);
216 CombineRgn( hrgn
, hrgn
, tmp
, RGN_OR
);
217 if (!event
.xgraphicsexpose
.count
) break;
221 ERR( "got unexpected event %d\n", event
.type
);
224 if (tmp
) DeleteObject( tmp
);
228 GDI_ReleaseObj( hdc
);