- stubs for SHLWAPI.295 (create a URL shortcut ?) and SHLWAPI.394
[wine/multimedia.git] / objects / clipping.c
blob697fd1125c9dff8fa1204b47bfa3dd446aeab13f
1 /*
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
21 #include <stdlib.h>
22 #include "windef.h"
23 #include "wingdi.h"
24 #include "wine/winuser16.h"
25 #include "gdi.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 );
40 if (!dc->hVisRgn)
42 ERR("hVisRgn is zero. Please report this.\n" );
43 exit(1);
46 if (dc->flags & DC_DIRTY) ERR( "DC is dirty. Please report this.\n" );
48 if (!dc->hClipRgn)
49 CombineRgn( dc->hGCClipRgn, dc->hVisRgn, 0, RGN_COPY );
50 else
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 (GDI.44)
60 INT16 WINAPI SelectClipRgn16( HDC16 hdc, HRGN16 hrgn )
62 return (INT16)SelectClipRgn( hdc, hrgn );
66 /***********************************************************************
67 * SelectClipRgn (GDI32.@)
69 INT WINAPI SelectClipRgn( HDC hdc, HRGN hrgn )
71 return ExtSelectClipRgn( hdc, hrgn, RGN_COPY );
74 /******************************************************************************
75 * ExtSelectClipRgn [GDI.508]
77 INT16 WINAPI ExtSelectClipRgn16( HDC16 hdc, HRGN16 hrgn, INT16 fnMode )
79 return (INT16) ExtSelectClipRgn((HDC) hdc, (HRGN) hrgn, fnMode);
82 /******************************************************************************
83 * ExtSelectClipRgn [GDI32.@]
85 INT WINAPI ExtSelectClipRgn( HDC hdc, HRGN hrgn, INT fnMode )
87 INT retval;
88 DC * dc = DC_GetDCUpdate( hdc );
89 if (!dc) return ERROR;
91 TRACE("%04x %04x %d\n", hdc, hrgn, fnMode );
93 if (dc->funcs->pExtSelectClipRgn)
95 retval = dc->funcs->pExtSelectClipRgn( dc->physDev, hrgn, fnMode );
96 GDI_ReleaseObj( hdc );
97 return retval;
100 if (!hrgn)
102 if (fnMode == RGN_COPY)
104 if (dc->hClipRgn) DeleteObject( dc->hClipRgn );
105 dc->hClipRgn = 0;
106 retval = SIMPLEREGION; /* Clip region == whole DC */
108 else
110 FIXME("Unimplemented: hrgn NULL in mode: %d\n", fnMode);
111 GDI_ReleaseObj( hdc );
112 return ERROR;
115 else
117 if (!dc->hClipRgn)
119 RECT rect;
120 GetRgnBox( dc->hVisRgn, &rect );
121 dc->hClipRgn = CreateRectRgnIndirect( &rect );
124 if(fnMode == RGN_COPY)
125 retval = CombineRgn( dc->hClipRgn, hrgn, 0, fnMode );
126 else
127 retval = CombineRgn( dc->hClipRgn, dc->hClipRgn, hrgn, fnMode);
130 CLIPPING_UpdateGCRegion( dc );
131 GDI_ReleaseObj( hdc );
132 return retval;
135 /***********************************************************************
136 * SelectVisRgn (GDI.105)
138 INT16 WINAPI SelectVisRgn16( HDC16 hdc, HRGN16 hrgn )
140 int retval;
141 DC * dc;
143 if (!hrgn) return ERROR;
144 if (!(dc = DC_GetDCPtr( hdc ))) return ERROR;
146 TRACE("%04x %04x\n", hdc, hrgn );
148 dc->flags &= ~DC_DIRTY;
150 retval = CombineRgn16( dc->hVisRgn, hrgn, 0, RGN_COPY );
151 CLIPPING_UpdateGCRegion( dc );
152 GDI_ReleaseObj( hdc );
153 return retval;
157 /***********************************************************************
158 * OffsetClipRgn (GDI.32)
160 INT16 WINAPI OffsetClipRgn16( HDC16 hdc, INT16 x, INT16 y )
162 return (INT16)OffsetClipRgn( hdc, x, y );
166 /***********************************************************************
167 * OffsetClipRgn (GDI32.@)
169 INT WINAPI OffsetClipRgn( HDC hdc, INT x, INT y )
171 INT ret = SIMPLEREGION;
172 DC *dc = DC_GetDCUpdate( hdc );
173 if (!dc) return ERROR;
175 TRACE("%04x %d,%d\n", hdc, x, y );
177 if(dc->funcs->pOffsetClipRgn)
178 ret = dc->funcs->pOffsetClipRgn( dc->physDev, x, y );
179 else if (dc->hClipRgn) {
180 ret = OffsetRgn( dc->hClipRgn, XLSTODS(dc,x), YLSTODS(dc,y));
181 CLIPPING_UpdateGCRegion( dc );
183 GDI_ReleaseObj( hdc );
184 return ret;
188 /***********************************************************************
189 * OffsetVisRgn (GDI.102)
191 INT16 WINAPI OffsetVisRgn16( HDC16 hdc, INT16 x, INT16 y )
193 INT16 retval;
194 DC * dc = DC_GetDCUpdate( hdc );
195 if (!dc) return ERROR;
196 TRACE("%04x %d,%d\n", hdc, x, y );
197 retval = OffsetRgn( dc->hVisRgn, x, y );
198 CLIPPING_UpdateGCRegion( dc );
199 GDI_ReleaseObj( hdc );
200 return retval;
204 /***********************************************************************
205 * ExcludeClipRect (GDI.21)
207 INT16 WINAPI ExcludeClipRect16( HDC16 hdc, INT16 left, INT16 top,
208 INT16 right, INT16 bottom )
210 return (INT16)ExcludeClipRect( hdc, left, top, right, bottom );
214 /***********************************************************************
215 * ExcludeClipRect (GDI32.@)
217 INT WINAPI ExcludeClipRect( HDC hdc, INT left, INT top,
218 INT right, INT bottom )
220 HRGN newRgn;
221 INT ret;
222 DC *dc = DC_GetDCUpdate( hdc );
223 if (!dc) return ERROR;
225 TRACE("%04x %dx%d,%dx%d\n", hdc, left, top, right, bottom );
227 if(dc->funcs->pExcludeClipRect)
228 ret = dc->funcs->pExcludeClipRect( dc->physDev, left, top, right, bottom );
229 else
231 RECT rect;
232 rect.left = left;
233 rect.top = top;
234 rect.right = right;
235 rect.bottom = bottom;
236 LPtoDP( hdc, (POINT*)&rect, 2 );
238 if (!(newRgn = CreateRectRgn( rect.left, rect.top, rect.right, rect.bottom ))) ret = ERROR;
239 else
241 if (!dc->hClipRgn)
243 dc->hClipRgn = CreateRectRgn( 0, 0, 0, 0 );
244 CombineRgn( dc->hClipRgn, dc->hVisRgn, 0, RGN_COPY );
246 ret = CombineRgn( dc->hClipRgn, dc->hClipRgn, newRgn, RGN_DIFF );
247 DeleteObject( newRgn );
249 if (ret != ERROR) CLIPPING_UpdateGCRegion( dc );
251 GDI_ReleaseObj( hdc );
252 return ret;
256 /***********************************************************************
257 * IntersectClipRect (GDI.22)
259 INT16 WINAPI IntersectClipRect16( HDC16 hdc, INT16 left, INT16 top,
260 INT16 right, INT16 bottom )
262 return (INT16)IntersectClipRect( hdc, left, top, right, bottom );
266 /***********************************************************************
267 * IntersectClipRect (GDI32.@)
269 INT WINAPI IntersectClipRect( HDC hdc, INT left, INT top,
270 INT right, INT bottom )
272 INT ret;
273 DC *dc = DC_GetDCUpdate( hdc );
274 if (!dc) return ERROR;
276 TRACE("%04x %d,%d - %d,%d\n", hdc, left, top, right, bottom );
278 if(dc->funcs->pIntersectClipRect)
279 ret = dc->funcs->pIntersectClipRect( dc->physDev, left, top, right, bottom );
280 else
282 RECT rect;
284 rect.left = left;
285 rect.top = top;
286 rect.right = right;
287 rect.bottom = bottom;
288 LPtoDP( hdc, (POINT*)&rect, 2 );
290 if (!dc->hClipRgn)
292 dc->hClipRgn = CreateRectRgn( rect.left, rect.top, rect.right, rect.bottom );
293 ret = SIMPLEREGION;
295 else
297 HRGN newRgn;
299 if (!(newRgn = CreateRectRgn( rect.left, rect.top, rect.right, rect.bottom))) ret = ERROR;
300 else
302 ret = CombineRgn( dc->hClipRgn, dc->hClipRgn, newRgn, RGN_AND );
303 DeleteObject( newRgn );
306 if (ret != ERROR) CLIPPING_UpdateGCRegion( dc );
308 GDI_ReleaseObj( hdc );
309 return ret;
313 /***********************************************************************
314 * ExcludeVisRect (GDI.73)
316 INT16 WINAPI ExcludeVisRect16( HDC16 hdc, INT16 left, INT16 top,
317 INT16 right, INT16 bottom )
319 HRGN tempRgn;
320 INT16 ret;
321 RECT rect;
322 DC * dc = DC_GetDCUpdate( hdc );
323 if (!dc) return ERROR;
325 rect.left = left;
326 rect.top = top;
327 rect.right = right;
328 rect.bottom = bottom;
329 LPtoDP( hdc, (POINT*)&rect, 2 );
331 TRACE("%04x %d,%d - %d,%d\n", hdc, rect.left, rect.top, rect.right, rect.bottom );
333 if (!(tempRgn = CreateRectRgn( rect.left, rect.top, rect.right, rect.bottom ))) ret = ERROR;
334 else
336 ret = CombineRgn( dc->hVisRgn, dc->hVisRgn, tempRgn, RGN_DIFF );
337 DeleteObject( tempRgn );
339 if (ret != ERROR) CLIPPING_UpdateGCRegion( dc );
340 GDI_ReleaseObj( hdc );
341 return ret;
345 /***********************************************************************
346 * IntersectVisRect (GDI.98)
348 INT16 WINAPI IntersectVisRect16( HDC16 hdc, INT16 left, INT16 top,
349 INT16 right, INT16 bottom )
351 HRGN tempRgn;
352 INT16 ret;
353 RECT rect;
354 DC * dc = DC_GetDCUpdate( hdc );
355 if (!dc) return ERROR;
357 rect.left = left;
358 rect.top = top;
359 rect.right = right;
360 rect.bottom = bottom;
361 LPtoDP( hdc, (POINT*)&rect, 2 );
363 TRACE("%04x %d,%d - %d,%d\n", hdc, rect.left, rect.top, rect.right, rect.bottom );
365 if (!(tempRgn = CreateRectRgn( rect.left, rect.top, rect.right, rect.bottom ))) ret = ERROR;
366 else
368 ret = CombineRgn( dc->hVisRgn, dc->hVisRgn, tempRgn, RGN_AND );
369 DeleteObject( tempRgn );
371 if (ret != ERROR) CLIPPING_UpdateGCRegion( dc );
372 GDI_ReleaseObj( hdc );
373 return ret;
377 /***********************************************************************
378 * PtVisible (GDI.103)
380 BOOL16 WINAPI PtVisible16( HDC16 hdc, INT16 x, INT16 y )
382 return PtVisible( hdc, x, y );
386 /***********************************************************************
387 * PtVisible (GDI32.@)
389 BOOL WINAPI PtVisible( HDC hdc, INT x, INT y )
391 BOOL ret = FALSE;
392 DC *dc = DC_GetDCUpdate( hdc );
394 TRACE("%04x %d,%d\n", hdc, x, y );
395 if (!dc) return FALSE;
396 if (dc->hGCClipRgn)
398 POINT pt;
400 pt.x = x;
401 pt.y = y;
402 LPtoDP( hdc, &pt, 1 );
403 ret = PtInRegion( dc->hGCClipRgn, pt.x, pt.y );
405 GDI_ReleaseObj( hdc );
406 return ret;
410 /***********************************************************************
411 * RectVisible (GDI.465)
412 * RectVisibleOld (GDI.104)
414 BOOL16 WINAPI RectVisible16( HDC16 hdc, const RECT16* rect16 )
416 RECT rect;
417 CONV_RECT16TO32( rect16, &rect );
418 return RectVisible( hdc, &rect );
422 /***********************************************************************
423 * RectVisible (GDI32.@)
425 BOOL WINAPI RectVisible( HDC hdc, const RECT* rect )
427 BOOL ret = FALSE;
428 RECT tmpRect;
429 DC *dc = DC_GetDCUpdate( hdc );
430 if (!dc) return FALSE;
431 TRACE("%04x %d,%dx%d,%d\n",
432 hdc, rect->left, rect->top, rect->right, rect->bottom );
433 if (dc->hGCClipRgn)
435 /* copy rectangle to avoid overwriting by LPtoDP */
436 tmpRect = *rect;
437 LPtoDP( hdc, (LPPOINT)&tmpRect, 2 );
438 ret = RectInRegion( dc->hGCClipRgn, &tmpRect );
440 GDI_ReleaseObj( hdc );
441 return ret;
445 /***********************************************************************
446 * GetClipBox (GDI.77)
448 INT16 WINAPI GetClipBox16( HDC16 hdc, LPRECT16 rect )
450 int ret;
451 DC *dc = DC_GetDCUpdate( hdc );
452 if (!dc) return ERROR;
453 ret = GetRgnBox16( dc->hGCClipRgn, rect );
454 DPtoLP16( hdc, (LPPOINT16)rect, 2 );
455 TRACE("%d,%d-%d,%d\n", rect->left,rect->top,rect->right,rect->bottom );
456 GDI_ReleaseObj( hdc );
457 return ret;
461 /***********************************************************************
462 * GetClipBox (GDI32.@)
464 INT WINAPI GetClipBox( HDC hdc, LPRECT rect )
466 INT ret;
467 DC *dc = DC_GetDCUpdate( hdc );
468 if (!dc) return ERROR;
469 ret = GetRgnBox( dc->hGCClipRgn, rect );
470 DPtoLP( hdc, (LPPOINT)rect, 2 );
471 GDI_ReleaseObj( hdc );
472 return ret;
476 /***********************************************************************
477 * GetClipRgn (GDI32.@)
479 INT WINAPI GetClipRgn( HDC hdc, HRGN hRgn )
481 INT ret = -1;
482 DC * dc;
483 if (hRgn && (dc = DC_GetDCPtr( hdc )))
485 if( dc->hClipRgn )
487 if( CombineRgn(hRgn, dc->hClipRgn, 0, RGN_COPY) != ERROR ) ret = 1;
489 else ret = 0;
490 GDI_ReleaseObj( hdc );
492 return ret;
495 /***********************************************************************
496 * SaveVisRgn (GDI.129)
498 HRGN16 WINAPI SaveVisRgn16( HDC16 hdc )
500 HRGN copy;
501 GDIOBJHDR *obj, *copyObj;
502 DC *dc = DC_GetDCUpdate( hdc );
504 if (!dc) return 0;
505 TRACE("%04x\n", hdc );
507 if (!(obj = GDI_GetObjPtr( dc->hVisRgn, REGION_MAGIC )))
509 GDI_ReleaseObj( hdc );
510 return 0;
512 if (!(copy = CreateRectRgn( 0, 0, 0, 0 )))
514 GDI_ReleaseObj( dc->hVisRgn );
515 GDI_ReleaseObj( hdc );
516 return 0;
518 CombineRgn( copy, dc->hVisRgn, 0, RGN_COPY );
519 if (!(copyObj = GDI_GetObjPtr( copy, REGION_MAGIC )))
521 DeleteObject( copy );
522 GDI_ReleaseObj( dc->hVisRgn );
523 GDI_ReleaseObj( hdc );
524 return 0;
526 copyObj->hNext = obj->hNext;
527 obj->hNext = copy;
528 GDI_ReleaseObj( copy );
529 GDI_ReleaseObj( dc->hVisRgn );
530 GDI_ReleaseObj( hdc );
531 return copy;
535 /***********************************************************************
536 * RestoreVisRgn (GDI.130)
538 INT16 WINAPI RestoreVisRgn16( HDC16 hdc )
540 HRGN saved;
541 GDIOBJHDR *obj, *savedObj;
542 DC *dc = DC_GetDCPtr( hdc );
543 INT16 ret = ERROR;
545 if (!dc) return ERROR;
547 TRACE("%04x\n", hdc );
549 if (!(obj = GDI_GetObjPtr( dc->hVisRgn, REGION_MAGIC ))) goto done;
550 saved = obj->hNext;
552 if ((savedObj = GDI_GetObjPtr( saved, REGION_MAGIC )))
554 ret = CombineRgn( dc->hVisRgn, saved, 0, RGN_COPY );
555 obj->hNext = savedObj->hNext;
556 GDI_ReleaseObj( saved );
557 DeleteObject( saved );
558 dc->flags &= ~DC_DIRTY;
559 CLIPPING_UpdateGCRegion( dc );
561 GDI_ReleaseObj( dc->hVisRgn );
562 done:
563 GDI_ReleaseObj( hdc );
564 return ret;