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
24 #include "wine/winuser16.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(clipping);
31 /***********************************************************************
32 * CLIPPING_UpdateGCRegion
34 * Update the GC clip region when the ClipRgn or VisRgn have changed.
36 void CLIPPING_UpdateGCRegion( DC * dc )
38 if (!dc->hGCClipRgn) dc->hGCClipRgn = CreateRectRgn( 0, 0, 0, 0 );
42 ERR("hVisRgn is zero. Please report this.\n" );
46 if (dc->flags & DC_DIRTY) ERR( "DC is dirty. Please report this.\n" );
49 CombineRgn( dc->hGCClipRgn, dc->hVisRgn, 0, RGN_COPY );
51 CombineRgn(dc->hGCClipRgn, dc->hClipRgn, dc->hVisRgn, RGN_AND);
52 if (dc->funcs->pSetDeviceClipping)
53 dc->funcs->pSetDeviceClipping( dc->physDev, dc->hGCClipRgn );
57 /***********************************************************************
58 * SelectClipRgn (GDI32.@)
60 INT WINAPI SelectClipRgn( HDC hdc, HRGN hrgn )
62 return ExtSelectClipRgn( hdc, hrgn, RGN_COPY );
66 /******************************************************************************
67 * ExtSelectClipRgn [GDI32.@]
69 INT WINAPI ExtSelectClipRgn( HDC hdc, HRGN hrgn, INT fnMode )
72 DC * dc = DC_GetDCUpdate( hdc );
73 if (!dc) return ERROR;
75 TRACE("%04x %04x %d\n", hdc, hrgn, fnMode );
77 if (dc->funcs->pExtSelectClipRgn)
79 retval = dc->funcs->pExtSelectClipRgn( dc->physDev, hrgn, fnMode );
80 GDI_ReleaseObj( hdc );
86 if (fnMode == RGN_COPY)
88 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
90 retval = SIMPLEREGION; /* Clip region == whole DC */
94 FIXME("Unimplemented: hrgn NULL in mode: %d\n", fnMode);
95 GDI_ReleaseObj( hdc );
104 GetRgnBox( dc->hVisRgn, &rect );
105 dc->hClipRgn = CreateRectRgnIndirect( &rect );
108 if(fnMode == RGN_COPY)
109 retval = CombineRgn( dc->hClipRgn, hrgn, 0, fnMode );
111 retval = CombineRgn( dc->hClipRgn, dc->hClipRgn, hrgn, fnMode);
114 CLIPPING_UpdateGCRegion( dc );
115 GDI_ReleaseObj( hdc );
119 /***********************************************************************
120 * SelectVisRgn (GDI.105)
121 * SelectVisRgn16 (GDI32.@)
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 = CombineRgn16( dc->hVisRgn, 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)
270 * ExcludeVisRect16 (GDI32.@)
272 INT16 WINAPI ExcludeVisRect16( HDC16 hdc, INT16 left, INT16 top,
273 INT16 right, INT16 bottom )
278 DC * dc = DC_GetDCUpdate( hdc );
279 if (!dc) return ERROR;
284 rect.bottom = bottom;
285 LPtoDP( hdc, (POINT*)&rect, 2 );
287 TRACE("%04x %d,%d - %d,%d\n", hdc, rect.left, rect.top, rect.right, rect.bottom );
289 if (!(tempRgn = CreateRectRgn( rect.left, rect.top, rect.right, rect.bottom ))) ret = ERROR;
292 ret = CombineRgn( dc->hVisRgn, dc->hVisRgn, tempRgn, RGN_DIFF );
293 DeleteObject( tempRgn );
295 if (ret != ERROR) CLIPPING_UpdateGCRegion( dc );
296 GDI_ReleaseObj( hdc );
301 /***********************************************************************
302 * IntersectVisRect (GDI.98)
303 * IntersectVisRect16 (GDI32.@)
305 INT16 WINAPI IntersectVisRect16( HDC16 hdc, INT16 left, INT16 top,
306 INT16 right, INT16 bottom )
311 DC * dc = DC_GetDCUpdate( hdc );
312 if (!dc) return ERROR;
317 rect.bottom = bottom;
318 LPtoDP( hdc, (POINT*)&rect, 2 );
320 TRACE("%04x %d,%d - %d,%d\n", hdc, rect.left, rect.top, rect.right, rect.bottom );
322 if (!(tempRgn = CreateRectRgn( rect.left, rect.top, rect.right, rect.bottom ))) ret = ERROR;
325 ret = CombineRgn( dc->hVisRgn, dc->hVisRgn, tempRgn, RGN_AND );
326 DeleteObject( tempRgn );
328 if (ret != ERROR) CLIPPING_UpdateGCRegion( dc );
329 GDI_ReleaseObj( hdc );
334 /***********************************************************************
335 * PtVisible (GDI32.@)
337 BOOL WINAPI PtVisible( HDC hdc, INT x, INT y )
340 DC *dc = DC_GetDCUpdate( hdc );
342 TRACE("%04x %d,%d\n", hdc, x, y );
343 if (!dc) return FALSE;
350 LPtoDP( hdc, &pt, 1 );
351 ret = PtInRegion( dc->hGCClipRgn, pt.x, pt.y );
353 GDI_ReleaseObj( hdc );
358 /***********************************************************************
359 * RectVisible (GDI32.@)
361 BOOL WINAPI RectVisible( HDC hdc, const RECT* rect )
365 DC *dc = DC_GetDCUpdate( hdc );
366 if (!dc) return FALSE;
367 TRACE("%04x %d,%dx%d,%d\n",
368 hdc, rect->left, rect->top, rect->right, rect->bottom );
371 /* copy rectangle to avoid overwriting by LPtoDP */
373 LPtoDP( hdc, (LPPOINT)&tmpRect, 2 );
374 ret = RectInRegion( dc->hGCClipRgn, &tmpRect );
376 GDI_ReleaseObj( hdc );
381 /***********************************************************************
382 * GetClipBox (GDI32.@)
384 INT WINAPI GetClipBox( HDC hdc, LPRECT rect )
387 DC *dc = DC_GetDCUpdate( hdc );
388 if (!dc) return ERROR;
389 ret = GetRgnBox( dc->hGCClipRgn, rect );
390 DPtoLP( hdc, (LPPOINT)rect, 2 );
391 GDI_ReleaseObj( hdc );
396 /***********************************************************************
397 * GetClipRgn (GDI32.@)
399 INT WINAPI GetClipRgn( HDC hdc, HRGN hRgn )
403 if (hRgn && (dc = DC_GetDCPtr( hdc )))
407 if( CombineRgn(hRgn, dc->hClipRgn, 0, RGN_COPY) != ERROR ) ret = 1;
410 GDI_ReleaseObj( hdc );
415 /***********************************************************************
416 * SaveVisRgn (GDI.129)
417 * SaveVisRgn16 (GDI32.@)
419 HRGN16 WINAPI SaveVisRgn16( HDC16 hdc )
422 GDIOBJHDR *obj, *copyObj;
423 DC *dc = DC_GetDCUpdate( hdc );
426 TRACE("%04x\n", hdc );
428 if (!(obj = GDI_GetObjPtr( dc->hVisRgn, REGION_MAGIC )))
430 GDI_ReleaseObj( hdc );
433 if (!(copy = CreateRectRgn( 0, 0, 0, 0 )))
435 GDI_ReleaseObj( dc->hVisRgn );
436 GDI_ReleaseObj( hdc );
439 CombineRgn( copy, dc->hVisRgn, 0, RGN_COPY );
440 if (!(copyObj = GDI_GetObjPtr( copy, REGION_MAGIC )))
442 DeleteObject( copy );
443 GDI_ReleaseObj( dc->hVisRgn );
444 GDI_ReleaseObj( hdc );
447 copyObj->hNext = obj->hNext;
449 GDI_ReleaseObj( copy );
450 GDI_ReleaseObj( dc->hVisRgn );
451 GDI_ReleaseObj( hdc );
456 /***********************************************************************
457 * RestoreVisRgn (GDI.130)
458 * RestoreVisRgn16 (GDI32.@)
460 INT16 WINAPI RestoreVisRgn16( HDC16 hdc )
463 GDIOBJHDR *obj, *savedObj;
464 DC *dc = DC_GetDCPtr( hdc );
467 if (!dc) return ERROR;
469 TRACE("%04x\n", hdc );
471 if (!(obj = GDI_GetObjPtr( dc->hVisRgn, REGION_MAGIC ))) goto done;
474 if ((savedObj = GDI_GetObjPtr( saved, REGION_MAGIC )))
476 ret = CombineRgn( dc->hVisRgn, saved, 0, RGN_COPY );
477 obj->hNext = savedObj->hNext;
478 GDI_ReleaseObj( saved );
479 DeleteObject( saved );
480 dc->flags &= ~DC_DIRTY;
481 CLIPPING_UpdateGCRegion( dc );
483 GDI_ReleaseObj( dc->hVisRgn );
485 GDI_ReleaseObj( hdc );