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("%p %p %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 hdc16, HRGN16 hrgn )
126 HDC hdc = HDC_32( hdc16 );
129 if (!hrgn) return ERROR;
130 if (!(dc = DC_GetDCPtr( hdc ))) return ERROR;
132 TRACE("%p %04x\n", hdc, hrgn );
134 dc->flags &= ~DC_DIRTY;
136 retval = CombineRgn( dc->hVisRgn, HRGN_32(hrgn), 0, RGN_COPY );
137 CLIPPING_UpdateGCRegion( dc );
138 GDI_ReleaseObj( hdc );
143 /***********************************************************************
144 * OffsetClipRgn (GDI32.@)
146 INT WINAPI OffsetClipRgn( HDC hdc, INT x, INT y )
148 INT ret = SIMPLEREGION;
149 DC *dc = DC_GetDCUpdate( hdc );
150 if (!dc) return ERROR;
152 TRACE("%p %d,%d\n", hdc, x, y );
154 if(dc->funcs->pOffsetClipRgn)
155 ret = dc->funcs->pOffsetClipRgn( dc->physDev, x, y );
156 else if (dc->hClipRgn) {
157 ret = OffsetRgn( dc->hClipRgn, XLSTODS(dc,x), YLSTODS(dc,y));
158 CLIPPING_UpdateGCRegion( dc );
160 GDI_ReleaseObj( hdc );
165 /***********************************************************************
166 * OffsetVisRgn (GDI.102)
168 INT16 WINAPI OffsetVisRgn16( HDC16 hdc16, INT16 x, INT16 y )
171 HDC hdc = HDC_32( hdc16 );
172 DC * dc = DC_GetDCUpdate( hdc );
173 if (!dc) return ERROR;
174 TRACE("%p %d,%d\n", hdc, x, y );
175 retval = OffsetRgn( dc->hVisRgn, x, y );
176 CLIPPING_UpdateGCRegion( dc );
177 GDI_ReleaseObj( hdc );
182 /***********************************************************************
183 * ExcludeClipRect (GDI32.@)
185 INT WINAPI ExcludeClipRect( HDC hdc, INT left, INT top,
186 INT right, INT bottom )
190 DC *dc = DC_GetDCUpdate( hdc );
191 if (!dc) return ERROR;
193 TRACE("%p %dx%d,%dx%d\n", hdc, left, top, right, bottom );
195 if(dc->funcs->pExcludeClipRect)
196 ret = dc->funcs->pExcludeClipRect( dc->physDev, left, top, right, bottom );
205 LPtoDP( hdc, pt, 2 );
206 if (!(newRgn = CreateRectRgn( pt[0].x, pt[0].y, pt[1].x, pt[1].y ))) ret = ERROR;
211 dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
212 CombineRgn( dc->hClipRgn, dc->hVisRgn, 0, RGN_COPY );
214 ret = CombineRgn( dc->hClipRgn, dc->hClipRgn, newRgn, RGN_DIFF );
215 DeleteObject( newRgn );
217 if (ret != ERROR) CLIPPING_UpdateGCRegion( dc );
219 GDI_ReleaseObj( hdc );
224 /***********************************************************************
225 * IntersectClipRect (GDI32.@)
227 INT WINAPI IntersectClipRect( HDC hdc, INT left, INT top, INT right, INT bottom )
230 DC *dc = DC_GetDCUpdate( hdc );
231 if (!dc) return ERROR;
233 TRACE("%p %d,%d - %d,%d\n", hdc, left, top, right, bottom );
235 if(dc->funcs->pIntersectClipRect)
236 ret = dc->funcs->pIntersectClipRect( dc->physDev, left, top, right, bottom );
246 LPtoDP( hdc, pt, 2 );
250 dc->hClipRgn = CreateRectRgn( pt[0].x, pt[0].y, pt[1].x, pt[1].y );
257 if (!(newRgn = CreateRectRgn( pt[0].x, pt[0].y, pt[1].x, pt[1].y ))) ret = ERROR;
260 ret = CombineRgn( dc->hClipRgn, dc->hClipRgn, newRgn, RGN_AND );
261 DeleteObject( newRgn );
264 if (ret != ERROR) CLIPPING_UpdateGCRegion( dc );
266 GDI_ReleaseObj( hdc );
271 /***********************************************************************
272 * ExcludeVisRect (GDI.73)
274 INT16 WINAPI ExcludeVisRect16( HDC16 hdc16, INT16 left, INT16 top, INT16 right, INT16 bottom )
279 HDC hdc = HDC_32( hdc16 );
280 DC * dc = DC_GetDCUpdate( hdc );
281 if (!dc) return ERROR;
288 LPtoDP( hdc, pt, 2 );
290 TRACE("%p %ld,%ld - %ld,%ld\n", hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y);
292 if (!(tempRgn = CreateRectRgn( pt[0].x, pt[0].y, pt[1].x, pt[1].y ))) ret = ERROR;
295 ret = CombineRgn( dc->hVisRgn, dc->hVisRgn, tempRgn, RGN_DIFF );
296 DeleteObject( tempRgn );
298 if (ret != ERROR) CLIPPING_UpdateGCRegion( dc );
299 GDI_ReleaseObj( hdc );
304 /***********************************************************************
305 * IntersectVisRect (GDI.98)
307 INT16 WINAPI IntersectVisRect16( HDC16 hdc16, INT16 left, INT16 top, INT16 right, INT16 bottom )
312 HDC hdc = HDC_32( hdc16 );
313 DC * dc = DC_GetDCUpdate( hdc );
314 if (!dc) return ERROR;
321 LPtoDP( hdc, pt, 2 );
323 TRACE("%p %ld,%ld - %ld,%ld\n", hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y);
326 if (!(tempRgn = CreateRectRgn( pt[0].x, pt[0].y, pt[1].x, pt[1].y ))) ret = ERROR;
329 ret = CombineRgn( dc->hVisRgn, dc->hVisRgn, tempRgn, RGN_AND );
330 DeleteObject( tempRgn );
332 if (ret != ERROR) CLIPPING_UpdateGCRegion( dc );
333 GDI_ReleaseObj( hdc );
338 /***********************************************************************
339 * PtVisible (GDI32.@)
341 BOOL WINAPI PtVisible( HDC hdc, INT x, INT y )
344 DC *dc = DC_GetDCUpdate( hdc );
346 TRACE("%p %d,%d\n", hdc, x, y );
347 if (!dc) return FALSE;
354 LPtoDP( hdc, &pt, 1 );
355 ret = PtInRegion( dc->hGCClipRgn, pt.x, pt.y );
357 GDI_ReleaseObj( hdc );
362 /***********************************************************************
363 * RectVisible (GDI32.@)
365 BOOL WINAPI RectVisible( HDC hdc, const RECT* rect )
368 DC *dc = DC_GetDCUpdate( hdc );
369 if (!dc) return FALSE;
370 TRACE("%p %ld,%ldx%ld,%ld\n", hdc, rect->left, rect->top, rect->right, rect->bottom );
376 pt[0].x = rect->left;
378 pt[1].x = rect->right;
379 pt[1].y = rect->bottom;
380 LPtoDP( hdc, pt, 2 );
381 tmpRect.left = pt[0].x;
382 tmpRect.top = pt[0].y;
383 tmpRect.right = pt[1].x;
384 tmpRect.bottom = pt[1].y;
385 ret = RectInRegion( dc->hGCClipRgn, &tmpRect );
387 GDI_ReleaseObj( hdc );
392 /***********************************************************************
393 * GetClipBox (GDI32.@)
395 INT WINAPI GetClipBox( HDC hdc, LPRECT rect )
398 DC *dc = DC_GetDCUpdate( hdc );
399 if (!dc) return ERROR;
400 ret = GetRgnBox( dc->hGCClipRgn, rect );
401 DPtoLP( hdc, (LPPOINT)rect, 2 );
402 GDI_ReleaseObj( hdc );
407 /***********************************************************************
408 * GetClipRgn (GDI32.@)
410 INT WINAPI GetClipRgn( HDC hdc, HRGN hRgn )
414 if (hRgn && (dc = DC_GetDCPtr( hdc )))
418 if( CombineRgn(hRgn, dc->hClipRgn, 0, RGN_COPY) != ERROR ) ret = 1;
421 GDI_ReleaseObj( hdc );
426 /***********************************************************************
427 * SaveVisRgn (GDI.129)
429 HRGN16 WINAPI SaveVisRgn16( HDC16 hdc16 )
432 GDIOBJHDR *obj, *copyObj;
433 HDC hdc = HDC_32( hdc16 );
434 DC *dc = DC_GetDCUpdate( hdc );
439 if (!(obj = GDI_GetObjPtr( dc->hVisRgn, REGION_MAGIC )))
441 GDI_ReleaseObj( hdc );
444 if (!(copy = CreateRectRgn( 0, 0, 0, 0 )))
446 GDI_ReleaseObj( dc->hVisRgn );
447 GDI_ReleaseObj( hdc );
450 CombineRgn( copy, dc->hVisRgn, 0, RGN_COPY );
451 if (!(copyObj = GDI_GetObjPtr( copy, REGION_MAGIC )))
453 DeleteObject( copy );
454 GDI_ReleaseObj( dc->hVisRgn );
455 GDI_ReleaseObj( hdc );
458 copyObj->hNext = obj->hNext;
459 obj->hNext = HRGN_16(copy);
460 GDI_ReleaseObj( copy );
461 GDI_ReleaseObj( dc->hVisRgn );
462 GDI_ReleaseObj( hdc );
463 return HRGN_16(copy);
467 /***********************************************************************
468 * RestoreVisRgn (GDI.130)
470 INT16 WINAPI RestoreVisRgn16( HDC16 hdc16 )
473 GDIOBJHDR *obj, *savedObj;
474 HDC hdc = HDC_32( hdc16 );
475 DC *dc = DC_GetDCPtr( hdc );
478 if (!dc) return ERROR;
482 if (!(obj = GDI_GetObjPtr( dc->hVisRgn, REGION_MAGIC ))) goto done;
483 saved = HRGN_32(obj->hNext);
485 if ((savedObj = GDI_GetObjPtr( saved, REGION_MAGIC )))
487 ret = CombineRgn( dc->hVisRgn, saved, 0, RGN_COPY );
488 obj->hNext = savedObj->hNext;
489 GDI_ReleaseObj( saved );
490 DeleteObject( saved );
491 dc->flags &= ~DC_DIRTY;
492 CLIPPING_UpdateGCRegion( dc );
494 GDI_ReleaseObj( dc->hVisRgn );
496 GDI_ReleaseObj( hdc );