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
)
74 DC
* dc
= DC_GetDCUpdate( hdc
);
75 if (!dc
) return ERROR
;
77 TRACE("%p %p %d\n", hdc
, hrgn
, fnMode
);
79 if (dc
->funcs
->pExtSelectClipRgn
)
81 retval
= dc
->funcs
->pExtSelectClipRgn( dc
->physDev
, hrgn
, fnMode
);
82 GDI_ReleaseObj( hdc
);
88 if (fnMode
== RGN_COPY
)
90 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
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 CombineRgn( dc
->hClipRgn
, hrgn
, 0, fnMode
);
112 CombineRgn( dc
->hClipRgn
, dc
->hClipRgn
, hrgn
, fnMode
);
115 CLIPPING_UpdateGCRegion( dc
);
116 GDI_ReleaseObj( hdc
);
118 return GetClipBox(hdc
, &rect
);
121 /***********************************************************************
122 * SelectVisRgn (GDI.105)
124 INT16 WINAPI
SelectVisRgn16( HDC16 hdc16
, HRGN16 hrgn
)
127 HDC hdc
= HDC_32( hdc16
);
130 if (!hrgn
) return ERROR
;
131 if (!(dc
= DC_GetDCPtr( hdc
))) return ERROR
;
133 TRACE("%p %04x\n", hdc
, hrgn
);
135 dc
->flags
&= ~DC_DIRTY
;
137 retval
= CombineRgn( dc
->hVisRgn
, HRGN_32(hrgn
), 0, RGN_COPY
);
138 CLIPPING_UpdateGCRegion( dc
);
139 GDI_ReleaseObj( hdc
);
144 /***********************************************************************
145 * OffsetClipRgn (GDI32.@)
147 INT WINAPI
OffsetClipRgn( HDC hdc
, INT x
, INT y
)
149 INT ret
= SIMPLEREGION
;
150 DC
*dc
= DC_GetDCUpdate( hdc
);
151 if (!dc
) return ERROR
;
153 TRACE("%p %d,%d\n", hdc
, x
, y
);
155 if(dc
->funcs
->pOffsetClipRgn
)
156 ret
= dc
->funcs
->pOffsetClipRgn( dc
->physDev
, x
, y
);
157 else if (dc
->hClipRgn
) {
158 ret
= OffsetRgn( dc
->hClipRgn
, XLSTODS(dc
,x
), YLSTODS(dc
,y
));
159 CLIPPING_UpdateGCRegion( dc
);
161 GDI_ReleaseObj( hdc
);
166 /***********************************************************************
167 * OffsetVisRgn (GDI.102)
169 INT16 WINAPI
OffsetVisRgn16( HDC16 hdc16
, INT16 x
, INT16 y
)
172 HDC hdc
= HDC_32( hdc16
);
173 DC
* dc
= DC_GetDCUpdate( hdc
);
174 if (!dc
) return ERROR
;
175 TRACE("%p %d,%d\n", hdc
, x
, y
);
176 retval
= OffsetRgn( dc
->hVisRgn
, x
, y
);
177 CLIPPING_UpdateGCRegion( dc
);
178 GDI_ReleaseObj( hdc
);
183 /***********************************************************************
184 * ExcludeClipRect (GDI32.@)
186 INT WINAPI
ExcludeClipRect( HDC hdc
, INT left
, INT top
,
187 INT right
, INT bottom
)
191 DC
*dc
= DC_GetDCUpdate( hdc
);
192 if (!dc
) return ERROR
;
194 TRACE("%p %dx%d,%dx%d\n", hdc
, left
, top
, right
, bottom
);
196 if(dc
->funcs
->pExcludeClipRect
)
197 ret
= dc
->funcs
->pExcludeClipRect( dc
->physDev
, left
, top
, right
, bottom
);
206 LPtoDP( hdc
, pt
, 2 );
207 if (!(newRgn
= CreateRectRgn( pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
))) ret
= ERROR
;
212 dc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
213 CombineRgn( dc
->hClipRgn
, dc
->hVisRgn
, 0, RGN_COPY
);
215 ret
= CombineRgn( dc
->hClipRgn
, dc
->hClipRgn
, newRgn
, RGN_DIFF
);
216 DeleteObject( newRgn
);
218 if (ret
!= ERROR
) CLIPPING_UpdateGCRegion( dc
);
220 GDI_ReleaseObj( hdc
);
225 /***********************************************************************
226 * IntersectClipRect (GDI32.@)
228 INT WINAPI
IntersectClipRect( HDC hdc
, INT left
, INT top
, INT right
, INT bottom
)
231 DC
*dc
= DC_GetDCUpdate( hdc
);
232 if (!dc
) return ERROR
;
234 TRACE("%p %d,%d - %d,%d\n", hdc
, left
, top
, right
, bottom
);
236 if(dc
->funcs
->pIntersectClipRect
)
237 ret
= dc
->funcs
->pIntersectClipRect( dc
->physDev
, left
, top
, right
, bottom
);
247 LPtoDP( hdc
, pt
, 2 );
251 dc
->hClipRgn
= CreateRectRgn( pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
258 if (!(newRgn
= CreateRectRgn( pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
))) ret
= ERROR
;
261 ret
= CombineRgn( dc
->hClipRgn
, dc
->hClipRgn
, newRgn
, RGN_AND
);
262 DeleteObject( newRgn
);
265 if (ret
!= ERROR
) CLIPPING_UpdateGCRegion( dc
);
267 GDI_ReleaseObj( hdc
);
272 /***********************************************************************
273 * ExcludeVisRect (GDI.73)
275 INT16 WINAPI
ExcludeVisRect16( HDC16 hdc16
, INT16 left
, INT16 top
, INT16 right
, INT16 bottom
)
280 HDC hdc
= HDC_32( hdc16
);
281 DC
* dc
= DC_GetDCUpdate( hdc
);
282 if (!dc
) return ERROR
;
289 LPtoDP( hdc
, pt
, 2 );
291 TRACE("%p %ld,%ld - %ld,%ld\n", hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
293 if (!(tempRgn
= CreateRectRgn( pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
))) ret
= ERROR
;
296 ret
= CombineRgn( dc
->hVisRgn
, dc
->hVisRgn
, tempRgn
, RGN_DIFF
);
297 DeleteObject( tempRgn
);
299 if (ret
!= ERROR
) CLIPPING_UpdateGCRegion( dc
);
300 GDI_ReleaseObj( hdc
);
305 /***********************************************************************
306 * IntersectVisRect (GDI.98)
308 INT16 WINAPI
IntersectVisRect16( HDC16 hdc16
, INT16 left
, INT16 top
, INT16 right
, INT16 bottom
)
313 HDC hdc
= HDC_32( hdc16
);
314 DC
* dc
= DC_GetDCUpdate( hdc
);
315 if (!dc
) return ERROR
;
322 LPtoDP( hdc
, pt
, 2 );
324 TRACE("%p %ld,%ld - %ld,%ld\n", hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
327 if (!(tempRgn
= CreateRectRgn( pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
))) ret
= ERROR
;
330 ret
= CombineRgn( dc
->hVisRgn
, dc
->hVisRgn
, tempRgn
, RGN_AND
);
331 DeleteObject( tempRgn
);
333 if (ret
!= ERROR
) CLIPPING_UpdateGCRegion( dc
);
334 GDI_ReleaseObj( hdc
);
339 /***********************************************************************
340 * PtVisible (GDI32.@)
342 BOOL WINAPI
PtVisible( HDC hdc
, INT x
, INT y
)
345 DC
*dc
= DC_GetDCUpdate( hdc
);
347 TRACE("%p %d,%d\n", hdc
, x
, y
);
348 if (!dc
) return FALSE
;
355 LPtoDP( hdc
, &pt
, 1 );
356 ret
= PtInRegion( dc
->hGCClipRgn
, pt
.x
, pt
.y
);
358 GDI_ReleaseObj( hdc
);
363 /***********************************************************************
364 * RectVisible (GDI32.@)
366 BOOL WINAPI
RectVisible( HDC hdc
, const RECT
* rect
)
369 DC
*dc
= DC_GetDCUpdate( hdc
);
370 if (!dc
) return FALSE
;
371 TRACE("%p %ld,%ldx%ld,%ld\n", hdc
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
377 pt
[0].x
= rect
->left
;
379 pt
[1].x
= rect
->right
;
380 pt
[1].y
= rect
->bottom
;
381 LPtoDP( hdc
, pt
, 2 );
382 tmpRect
.left
= pt
[0].x
;
383 tmpRect
.top
= pt
[0].y
;
384 tmpRect
.right
= pt
[1].x
;
385 tmpRect
.bottom
= pt
[1].y
;
386 ret
= RectInRegion( dc
->hGCClipRgn
, &tmpRect
);
388 GDI_ReleaseObj( hdc
);
393 /***********************************************************************
394 * GetClipBox (GDI32.@)
396 INT WINAPI
GetClipBox( HDC hdc
, LPRECT rect
)
399 DC
*dc
= DC_GetDCUpdate( hdc
);
400 if (!dc
) return ERROR
;
401 ret
= GetRgnBox( dc
->hGCClipRgn
, rect
);
402 DPtoLP( hdc
, (LPPOINT
)rect
, 2 );
403 GDI_ReleaseObj( hdc
);
408 /***********************************************************************
409 * GetClipRgn (GDI32.@)
411 INT WINAPI
GetClipRgn( HDC hdc
, HRGN hRgn
)
415 if (hRgn
&& (dc
= DC_GetDCPtr( hdc
)))
419 if( CombineRgn(hRgn
, dc
->hClipRgn
, 0, RGN_COPY
) != ERROR
) ret
= 1;
422 GDI_ReleaseObj( hdc
);
427 /***********************************************************************
428 * SaveVisRgn (GDI.129)
430 HRGN16 WINAPI
SaveVisRgn16( HDC16 hdc16
)
433 GDIOBJHDR
*obj
, *copyObj
;
434 HDC hdc
= HDC_32( hdc16
);
435 DC
*dc
= DC_GetDCUpdate( hdc
);
440 if (!(obj
= GDI_GetObjPtr( dc
->hVisRgn
, REGION_MAGIC
)))
442 GDI_ReleaseObj( hdc
);
445 if (!(copy
= CreateRectRgn( 0, 0, 0, 0 )))
447 GDI_ReleaseObj( dc
->hVisRgn
);
448 GDI_ReleaseObj( hdc
);
451 CombineRgn( copy
, dc
->hVisRgn
, 0, RGN_COPY
);
452 if (!(copyObj
= GDI_GetObjPtr( copy
, REGION_MAGIC
)))
454 DeleteObject( copy
);
455 GDI_ReleaseObj( dc
->hVisRgn
);
456 GDI_ReleaseObj( hdc
);
459 copyObj
->hNext
= obj
->hNext
;
460 obj
->hNext
= HRGN_16(copy
);
461 GDI_ReleaseObj( copy
);
462 GDI_ReleaseObj( dc
->hVisRgn
);
463 GDI_ReleaseObj( hdc
);
464 return HRGN_16(copy
);
468 /***********************************************************************
469 * RestoreVisRgn (GDI.130)
471 INT16 WINAPI
RestoreVisRgn16( HDC16 hdc16
)
474 GDIOBJHDR
*obj
, *savedObj
;
475 HDC hdc
= HDC_32( hdc16
);
476 DC
*dc
= DC_GetDCPtr( hdc
);
479 if (!dc
) return ERROR
;
483 if (!(obj
= GDI_GetObjPtr( dc
->hVisRgn
, REGION_MAGIC
))) goto done
;
484 saved
= HRGN_32(obj
->hNext
);
486 if ((savedObj
= GDI_GetObjPtr( saved
, REGION_MAGIC
)))
488 ret
= CombineRgn( dc
->hVisRgn
, saved
, 0, RGN_COPY
);
489 obj
->hNext
= savedObj
->hNext
;
490 GDI_ReleaseObj( saved
);
491 DeleteObject( saved
);
492 dc
->flags
&= ~DC_DIRTY
;
493 CLIPPING_UpdateGCRegion( dc
);
495 GDI_ReleaseObj( dc
->hVisRgn
);
497 GDI_ReleaseObj( hdc
);
502 /***********************************************************************
503 * GetRandomRgn [GDI32.@]
506 * This function is documented in MSDN online for the case of
507 * dwCode == SYSRGN (4).
509 * For dwCode == 1 it should return the clip region
510 * 2 " " " the meta region
511 * 3 " " " the intersection of the clip with
512 * the meta region (== 'Rao' region).
514 * See http://www.codeproject.com/gdi/cliprgnguide.asp
516 INT WINAPI
GetRandomRgn(HDC hDC
, HRGN hRgn
, DWORD dwCode
)
520 case SYSRGN
: /* == 4 */
522 DC
*dc
= DC_GetDCPtr (hDC
);
525 CombineRgn (hRgn
, dc
->hVisRgn
, 0, RGN_COPY
);
526 GDI_ReleaseObj( hDC
);
528 * On Windows NT/2000,
529 * the region returned is in screen coordinates.
531 * the region returned is in window coordinates
533 if (!(GetVersion() & 0x80000000))
536 GetDCOrgEx(hDC
, &org
);
537 OffsetRgn(hRgn
, org
.x
, org
.y
);
542 case 1: /* clip region */
543 return GetClipRgn (hDC
, hRgn
);
546 WARN("Unknown dwCode %ld\n", dwCode
);
554 /***********************************************************************
555 * GetMetaRgn (GDI32.@)
557 INT WINAPI
GetMetaRgn( HDC hdc
, HRGN hRgn
)
565 /***********************************************************************
566 * SetMetaRgn (GDI32.@)
568 INT WINAPI
SetMetaRgn( HDC hdc
)