2 * DC clipping functions
4 * Copyright 1993 Alexandre Julliard
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
25 #include "wine/winuser16.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(clipping);
32 /***********************************************************************
33 * CLIPPING_UpdateGCRegion
35 * Update the GC clip region when the ClipRgn or VisRgn have changed.
37 void CLIPPING_UpdateGCRegion( DC * dc )
39 if (!dc->hGCClipRgn) dc->hGCClipRgn = CreateRectRgn( 0, 0, 0, 0 );
43 ERR("hVisRgn is zero. Please report this.\n" );
47 if (dc->flags & DC_DIRTY) ERR( "DC is dirty. Please report this.\n" );
50 CombineRgn( dc->hGCClipRgn, dc->hVisRgn, 0, RGN_COPY );
52 CombineRgn(dc->hGCClipRgn, dc->hClipRgn, dc->hVisRgn, RGN_AND);
53 if (dc->funcs->pSetDeviceClipping)
54 dc->funcs->pSetDeviceClipping( dc->physDev, dc->hGCClipRgn );
58 /***********************************************************************
59 * SelectClipRgn (GDI32.@)
61 INT WINAPI SelectClipRgn( HDC hdc, HRGN hrgn )
63 return ExtSelectClipRgn( hdc, hrgn, RGN_COPY );
67 /******************************************************************************
68 * ExtSelectClipRgn [GDI32.@]
70 INT WINAPI ExtSelectClipRgn( HDC hdc, HRGN hrgn, INT fnMode )
73 DC * dc = DC_GetDCUpdate( hdc );
74 if (!dc) return ERROR;
76 TRACE("%04x %04x %d\n", hdc, hrgn, fnMode );
78 if (dc->funcs->pExtSelectClipRgn)
80 retval = dc->funcs->pExtSelectClipRgn( dc->physDev, hrgn, fnMode );
81 GDI_ReleaseObj( hdc );
87 if (fnMode == RGN_COPY)
89 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
91 retval = SIMPLEREGION; /* Clip region == whole DC */
95 FIXME("Unimplemented: hrgn NULL in mode: %d\n", fnMode);
96 GDI_ReleaseObj( hdc );
105 GetRgnBox( dc->hVisRgn, &rect );
106 dc->hClipRgn = CreateRectRgnIndirect( &rect );
109 if(fnMode == RGN_COPY)
110 retval = CombineRgn( dc->hClipRgn, hrgn, 0, fnMode );
112 retval = CombineRgn( dc->hClipRgn, dc->hClipRgn, hrgn, fnMode);
115 CLIPPING_UpdateGCRegion( dc );
116 GDI_ReleaseObj( hdc );
120 /***********************************************************************
121 * SelectVisRgn (GDI.105)
123 INT16 WINAPI SelectVisRgn16( HDC16 hdc, HRGN16 hrgn )
128 if (!hrgn) return ERROR;
129 if (!(dc = DC_GetDCPtr( hdc ))) return ERROR;
131 TRACE("%04x %04x\n", hdc, hrgn );
133 dc->flags &= ~DC_DIRTY;
135 retval = CombineRgn( dc->hVisRgn, HRGN_32(hrgn), 0, RGN_COPY );
136 CLIPPING_UpdateGCRegion( dc );
137 GDI_ReleaseObj( hdc );
142 /***********************************************************************
143 * OffsetClipRgn (GDI32.@)
145 INT WINAPI OffsetClipRgn( HDC hdc, INT x, INT y )
147 INT ret = SIMPLEREGION;
148 DC *dc = DC_GetDCUpdate( hdc );
149 if (!dc) return ERROR;
151 TRACE("%04x %d,%d\n", hdc, x, y );
153 if(dc->funcs->pOffsetClipRgn)
154 ret = dc->funcs->pOffsetClipRgn( dc->physDev, x, y );
155 else if (dc->hClipRgn) {
156 ret = OffsetRgn( dc->hClipRgn, XLSTODS(dc,x), YLSTODS(dc,y));
157 CLIPPING_UpdateGCRegion( dc );
159 GDI_ReleaseObj( hdc );
164 /***********************************************************************
165 * OffsetVisRgn (GDI.102)
167 INT16 WINAPI OffsetVisRgn16( HDC16 hdc, INT16 x, INT16 y )
170 DC * dc = DC_GetDCUpdate( hdc );
171 if (!dc) return ERROR;
172 TRACE("%04x %d,%d\n", hdc, x, y );
173 retval = OffsetRgn( dc->hVisRgn, x, y );
174 CLIPPING_UpdateGCRegion( dc );
175 GDI_ReleaseObj( hdc );
180 /***********************************************************************
181 * ExcludeClipRect (GDI32.@)
183 INT WINAPI ExcludeClipRect( HDC hdc, INT left, INT top,
184 INT right, INT bottom )
188 DC *dc = DC_GetDCUpdate( hdc );
189 if (!dc) return ERROR;
191 TRACE("%04x %dx%d,%dx%d\n", hdc, left, top, right, bottom );
193 if(dc->funcs->pExcludeClipRect)
194 ret = dc->funcs->pExcludeClipRect( dc->physDev, left, top, right, bottom );
201 rect.bottom = bottom;
202 LPtoDP( hdc, (POINT*)&rect, 2 );
204 if (!(newRgn = CreateRectRgn( rect.left, rect.top, rect.right, rect.bottom ))) ret = ERROR;
209 dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
210 CombineRgn( dc->hClipRgn, dc->hVisRgn, 0, RGN_COPY );
212 ret = CombineRgn( dc->hClipRgn, dc->hClipRgn, newRgn, RGN_DIFF );
213 DeleteObject( newRgn );
215 if (ret != ERROR) CLIPPING_UpdateGCRegion( dc );
217 GDI_ReleaseObj( hdc );
222 /***********************************************************************
223 * IntersectClipRect (GDI32.@)
225 INT WINAPI IntersectClipRect( HDC hdc, INT left, INT top, INT right, INT bottom )
228 DC *dc = DC_GetDCUpdate( hdc );
229 if (!dc) return ERROR;
231 TRACE("%04x %d,%d - %d,%d\n", hdc, left, top, right, bottom );
233 if(dc->funcs->pIntersectClipRect)
234 ret = dc->funcs->pIntersectClipRect( dc->physDev, left, top, right, bottom );
242 rect.bottom = bottom;
243 LPtoDP( hdc, (POINT*)&rect, 2 );
247 dc->hClipRgn = CreateRectRgn( rect.left, rect.top, rect.right, rect.bottom );
254 if (!(newRgn = CreateRectRgn( rect.left, rect.top, rect.right, rect.bottom))) ret = ERROR;
257 ret = CombineRgn( dc->hClipRgn, dc->hClipRgn, newRgn, RGN_AND );
258 DeleteObject( newRgn );
261 if (ret != ERROR) CLIPPING_UpdateGCRegion( dc );
263 GDI_ReleaseObj( hdc );
268 /***********************************************************************
269 * ExcludeVisRect (GDI.73)
271 INT16 WINAPI ExcludeVisRect16( HDC16 hdc, INT16 left, INT16 top,
272 INT16 right, INT16 bottom )
277 DC * dc = DC_GetDCUpdate( hdc );
278 if (!dc) return ERROR;
283 rect.bottom = bottom;
284 LPtoDP( hdc, (POINT*)&rect, 2 );
286 TRACE("%04x %d,%d - %d,%d\n", hdc, rect.left, rect.top, rect.right, rect.bottom );
288 if (!(tempRgn = CreateRectRgn( rect.left, rect.top, rect.right, rect.bottom ))) ret = ERROR;
291 ret = CombineRgn( dc->hVisRgn, dc->hVisRgn, tempRgn, RGN_DIFF );
292 DeleteObject( tempRgn );
294 if (ret != ERROR) CLIPPING_UpdateGCRegion( dc );
295 GDI_ReleaseObj( hdc );
300 /***********************************************************************
301 * IntersectVisRect (GDI.98)
303 INT16 WINAPI IntersectVisRect16( HDC16 hdc, INT16 left, INT16 top,
304 INT16 right, INT16 bottom )
309 DC * dc = DC_GetDCUpdate( hdc );
310 if (!dc) return ERROR;
315 rect.bottom = bottom;
316 LPtoDP( hdc, (POINT*)&rect, 2 );
318 TRACE("%04x %d,%d - %d,%d\n", hdc, rect.left, rect.top, rect.right, rect.bottom );
320 if (!(tempRgn = CreateRectRgn( rect.left, rect.top, rect.right, rect.bottom ))) ret = ERROR;
323 ret = CombineRgn( dc->hVisRgn, dc->hVisRgn, tempRgn, RGN_AND );
324 DeleteObject( tempRgn );
326 if (ret != ERROR) CLIPPING_UpdateGCRegion( dc );
327 GDI_ReleaseObj( hdc );
332 /***********************************************************************
333 * PtVisible (GDI32.@)
335 BOOL WINAPI PtVisible( HDC hdc, INT x, INT y )
338 DC *dc = DC_GetDCUpdate( hdc );
340 TRACE("%04x %d,%d\n", hdc, x, y );
341 if (!dc) return FALSE;
348 LPtoDP( hdc, &pt, 1 );
349 ret = PtInRegion( dc->hGCClipRgn, pt.x, pt.y );
351 GDI_ReleaseObj( hdc );
356 /***********************************************************************
357 * RectVisible (GDI32.@)
359 BOOL WINAPI RectVisible( HDC hdc, const RECT* rect )
363 DC *dc = DC_GetDCUpdate( hdc );
364 if (!dc) return FALSE;
365 TRACE("%04x %d,%dx%d,%d\n",
366 hdc, rect->left, rect->top, rect->right, rect->bottom );
369 /* copy rectangle to avoid overwriting by LPtoDP */
371 LPtoDP( hdc, (LPPOINT)&tmpRect, 2 );
372 ret = RectInRegion( dc->hGCClipRgn, &tmpRect );
374 GDI_ReleaseObj( hdc );
379 /***********************************************************************
380 * GetClipBox (GDI32.@)
382 INT WINAPI GetClipBox( HDC hdc, LPRECT rect )
385 DC *dc = DC_GetDCUpdate( hdc );
386 if (!dc) return ERROR;
387 ret = GetRgnBox( dc->hGCClipRgn, rect );
388 DPtoLP( hdc, (LPPOINT)rect, 2 );
389 GDI_ReleaseObj( hdc );
394 /***********************************************************************
395 * GetClipRgn (GDI32.@)
397 INT WINAPI GetClipRgn( HDC hdc, HRGN hRgn )
401 if (hRgn && (dc = DC_GetDCPtr( hdc )))
405 if( CombineRgn(hRgn, dc->hClipRgn, 0, RGN_COPY) != ERROR ) ret = 1;
408 GDI_ReleaseObj( hdc );
413 /***********************************************************************
414 * SaveVisRgn (GDI.129)
416 HRGN16 WINAPI SaveVisRgn16( HDC16 hdc )
419 GDIOBJHDR *obj, *copyObj;
420 DC *dc = DC_GetDCUpdate( hdc );
423 TRACE("%04x\n", hdc );
425 if (!(obj = GDI_GetObjPtr( dc->hVisRgn, REGION_MAGIC )))
427 GDI_ReleaseObj( hdc );
430 if (!(copy = CreateRectRgn( 0, 0, 0, 0 )))
432 GDI_ReleaseObj( dc->hVisRgn );
433 GDI_ReleaseObj( hdc );
436 CombineRgn( copy, dc->hVisRgn, 0, RGN_COPY );
437 if (!(copyObj = GDI_GetObjPtr( copy, REGION_MAGIC )))
439 DeleteObject( copy );
440 GDI_ReleaseObj( dc->hVisRgn );
441 GDI_ReleaseObj( hdc );
444 copyObj->hNext = obj->hNext;
446 GDI_ReleaseObj( copy );
447 GDI_ReleaseObj( dc->hVisRgn );
448 GDI_ReleaseObj( hdc );
453 /***********************************************************************
454 * RestoreVisRgn (GDI.130)
456 INT16 WINAPI RestoreVisRgn16( HDC16 hdc )
459 GDIOBJHDR *obj, *savedObj;
460 DC *dc = DC_GetDCPtr( hdc );
463 if (!dc) return ERROR;
465 TRACE("%04x\n", hdc );
467 if (!(obj = GDI_GetObjPtr( dc->hVisRgn, REGION_MAGIC ))) goto done;
470 if ((savedObj = GDI_GetObjPtr( saved, REGION_MAGIC )))
472 ret = CombineRgn( dc->hVisRgn, saved, 0, RGN_COPY );
473 obj->hNext = savedObj->hNext;
474 GDI_ReleaseObj( saved );
475 DeleteObject( saved );
476 dc->flags &= ~DC_DIRTY;
477 CLIPPING_UpdateGCRegion( dc );
479 GDI_ReleaseObj( dc->hVisRgn );
481 GDI_ReleaseObj( hdc );