2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 CLIPPING_UpdateGCRegion(DC
* Dc
)
28 PROSRGNDATA CombinedRegion
;
30 /* Experiment with API region based on wine.. */
31 if (Dc
->rosdc
.hClipRgn
&& Dc
->dclevel
.prgnMeta
)
35 if ((pClipRgn
= RGNOBJAPI_Lock(Dc
->rosdc
.hClipRgn
, NULL
)))
37 if (!Dc
->prgnAPI
) Dc
->prgnAPI
= IntSysCreateRectpRgn( 0, 0, 0, 0 );
39 IntGdiCombineRgn( Dc
->prgnAPI
,
43 RGNOBJAPI_Unlock(pClipRgn
);
49 GreDeleteObject(((PROSRGNDATA
)Dc
->prgnAPI
)->BaseObject
.hHmgr
);
53 if (Dc
->rosdc
.hGCClipRgn
== NULL
)
54 Dc
->rosdc
.hGCClipRgn
= IntSysCreateRectRgn(0, 0, 0, 0);
56 if (Dc
->rosdc
.hClipRgn
== NULL
)
57 NtGdiCombineRgn(Dc
->rosdc
.hGCClipRgn
, Dc
->rosdc
.hVisRgn
, 0, RGN_COPY
);
59 NtGdiCombineRgn(Dc
->rosdc
.hGCClipRgn
, Dc
->rosdc
.hClipRgn
, Dc
->rosdc
.hVisRgn
, RGN_AND
);
61 NtGdiOffsetRgn(Dc
->rosdc
.hGCClipRgn
, Dc
->ptlDCOrig
.x
, Dc
->ptlDCOrig
.y
);
63 if((CombinedRegion
= RGNOBJAPI_Lock(Dc
->rosdc
.hGCClipRgn
, NULL
)))
65 if (Dc
->rosdc
.CombinedClip
!= NULL
)
66 IntEngDeleteClipRegion(Dc
->rosdc
.CombinedClip
);
68 Dc
->rosdc
.CombinedClip
= IntEngCreateClipRegion(
69 CombinedRegion
->rdh
.nCount
,
70 CombinedRegion
->Buffer
,
71 &CombinedRegion
->rdh
.rcBound
);
73 RGNOBJAPI_Unlock(CombinedRegion
);
76 if ( NULL
== Dc
->rosdc
.CombinedClip
)
78 DPRINT1("IntEngCreateClipRegion() failed\n");
82 return NtGdiOffsetRgn(Dc
->rosdc
.hGCClipRgn
, -Dc
->ptlDCOrig
.x
, -Dc
->ptlDCOrig
.y
);
86 GdiSelectVisRgn(HDC hdc
, HRGN hrgn
)
93 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
96 if (!(dc
= DC_LockDc(hdc
)))
98 SetLastWin32Error(ERROR_INVALID_HANDLE
);
102 dc
->fs
&= ~DC_FLAG_DIRTY_RAO
;
104 if (dc
->rosdc
.hVisRgn
== NULL
)
106 dc
->rosdc
.hVisRgn
= IntSysCreateRectRgn(0, 0, 0, 0);
107 GDIOBJ_CopyOwnership(hdc
, dc
->rosdc
.hVisRgn
);
110 retval
= NtGdiCombineRgn(dc
->rosdc
.hVisRgn
, hrgn
, 0, RGN_COPY
);
111 if ( retval
!= ERROR
)
113 NtGdiOffsetRgn(dc
->rosdc
.hVisRgn
, -dc
->ptlDCOrig
.x
, -dc
->ptlDCOrig
.y
);
114 CLIPPING_UpdateGCRegion(dc
);
123 int FASTCALL
GdiExtSelectClipRgn(PDC dc
,
127 // dc->fs &= ~DC_FLAG_DIRTY_RAO;
131 if (fnMode
== RGN_COPY
)
133 if (dc
->rosdc
.hClipRgn
!= NULL
)
135 REGION_FreeRgnByHandle(dc
->rosdc
.hClipRgn
);
136 dc
->rosdc
.hClipRgn
= NULL
;
141 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
147 if (!dc
->rosdc
.hClipRgn
)
151 if((Rgn
= RGNOBJAPI_Lock(dc
->rosdc
.hVisRgn
, NULL
)))
153 REGION_GetRgnBox(Rgn
, &rect
);
154 RGNOBJAPI_Unlock(Rgn
);
155 dc
->rosdc
.hClipRgn
= IntSysCreateRectRgnIndirect(&rect
);
159 dc
->rosdc
.hClipRgn
= IntSysCreateRectRgn(0, 0, 0, 0);
162 if(fnMode
== RGN_COPY
)
164 NtGdiCombineRgn(dc
->rosdc
.hClipRgn
, hrgn
, 0, fnMode
);
167 NtGdiCombineRgn(dc
->rosdc
.hClipRgn
, dc
->rosdc
.hClipRgn
, hrgn
, fnMode
);
169 return CLIPPING_UpdateGCRegion(dc
);
173 int APIENTRY
NtGdiExtSelectClipRgn(HDC hDC
,
180 if (!(dc
= DC_LockDc(hDC
)))
182 SetLastWin32Error(ERROR_INVALID_HANDLE
);
186 retval
= GdiExtSelectClipRgn ( dc
, hrgn
, fnMode
);
193 GdiGetClipBox(HDC hDC
, PRECTL rc
)
198 HRGN hRgnNew
, hRgn
= NULL
;
200 if (!(dc
= DC_LockDc(hDC
)))
205 if (dc
->prgnAPI
) // APIRGN
207 hRgn
= ((PROSRGNDATA
)dc
->prgnAPI
)->BaseObject
.hHmgr
;
209 else if (dc
->dclevel
.prgnMeta
) // METARGN
211 hRgn
= ((PROSRGNDATA
)dc
->dclevel
.prgnMeta
)->BaseObject
.hHmgr
;
215 hRgn
= dc
->rosdc
.hClipRgn
; // CLIPRGN
220 hRgnNew
= IntSysCreateRectRgn( 0, 0, 0, 0 );
222 NtGdiCombineRgn(hRgnNew
, dc
->rosdc
.hVisRgn
, hRgn
, RGN_AND
);
224 if (!(Rgn
= RGNOBJAPI_Lock(hRgnNew
, NULL
)))
230 retval
= REGION_GetRgnBox(Rgn
, rc
);
232 REGION_FreeRgnByHandle(hRgnNew
);
233 RGNOBJAPI_Unlock(Rgn
);
238 if (!(Rgn
= RGNOBJAPI_Lock(dc
->rosdc
.hVisRgn
, NULL
)))
243 retval
= REGION_GetRgnBox(Rgn
, rc
);
244 RGNOBJAPI_Unlock(Rgn
);
245 IntDPtoLP(dc
, (LPPOINT
)rc
, 2);
252 NtGdiGetAppClipBox(HDC hDC
, PRECTL rc
)
255 NTSTATUS Status
= STATUS_SUCCESS
;
258 Ret
= GdiGetClipBox(hDC
, &Saferect
);
267 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
269 Status
= _SEH2_GetExceptionCode();
273 if(!NT_SUCCESS(Status
))
275 SetLastNtError(Status
);
282 int APIENTRY
NtGdiExcludeClipRect(HDC hDC
,
291 PDC dc
= DC_LockDc(hDC
);
295 SetLastWin32Error(ERROR_INVALID_HANDLE
);
299 Rect
.left
= LeftRect
;
301 Rect
.right
= RightRect
;
302 Rect
.bottom
= BottomRect
;
304 IntLPtoDP(dc
, (LPPOINT
)&Rect
, 2);
306 NewRgn
= IntSysCreateRectRgnIndirect(&Rect
);
313 if (!dc
->rosdc
.hClipRgn
)
315 dc
->rosdc
.hClipRgn
= IntSysCreateRectRgn(0, 0, 0, 0);
316 NtGdiCombineRgn(dc
->rosdc
.hClipRgn
, dc
->rosdc
.hVisRgn
, NewRgn
, RGN_DIFF
);
317 Result
= SIMPLEREGION
;
321 Result
= NtGdiCombineRgn(dc
->rosdc
.hClipRgn
, dc
->rosdc
.hClipRgn
, NewRgn
, RGN_DIFF
);
323 REGION_FreeRgnByHandle(NewRgn
);
326 CLIPPING_UpdateGCRegion(dc
);
333 int APIENTRY
NtGdiIntersectClipRect(HDC hDC
,
342 PDC dc
= DC_LockDc(hDC
);
344 DPRINT("NtGdiIntersectClipRect(%x, %d,%d-%d,%d)\n",
345 hDC
, LeftRect
, TopRect
, RightRect
, BottomRect
);
349 SetLastWin32Error(ERROR_INVALID_HANDLE
);
353 Rect
.left
= LeftRect
;
355 Rect
.right
= RightRect
;
356 Rect
.bottom
= BottomRect
;
358 IntLPtoDP(dc
, (LPPOINT
)&Rect
, 2);
360 NewRgn
= IntSysCreateRectRgnIndirect(&Rect
);
365 else if (!dc
->rosdc
.hClipRgn
)
367 dc
->rosdc
.hClipRgn
= NewRgn
;
368 Result
= SIMPLEREGION
;
372 Result
= NtGdiCombineRgn(dc
->rosdc
.hClipRgn
, dc
->rosdc
.hClipRgn
, NewRgn
, RGN_AND
);
373 REGION_FreeRgnByHandle(NewRgn
);
376 CLIPPING_UpdateGCRegion(dc
);
383 int APIENTRY
NtGdiOffsetClipRgn(HDC hDC
,
390 if(!(dc
= DC_LockDc(hDC
)))
392 SetLastWin32Error(ERROR_INVALID_HANDLE
);
396 if(dc
->rosdc
.hClipRgn
!= NULL
)
398 Result
= NtGdiOffsetRgn(dc
->rosdc
.hClipRgn
,
401 CLIPPING_UpdateGCRegion(dc
);
412 BOOL APIENTRY
NtGdiPtVisible(HDC hDC
,
419 if(!(dc
= DC_LockDc(hDC
)))
421 SetLastWin32Error(ERROR_INVALID_HANDLE
);
425 rgn
= dc
->rosdc
.hGCClipRgn
;
428 return (rgn
? NtGdiPtInRegion(rgn
, X
, Y
) : FALSE
);
431 BOOL APIENTRY
NtGdiRectVisible(HDC hDC
,
434 NTSTATUS Status
= STATUS_SUCCESS
;
436 PDC dc
= DC_LockDc(hDC
);
442 SetLastWin32Error(ERROR_INVALID_HANDLE
);
448 ProbeForRead(UnsafeRect
,
453 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
455 Status
= _SEH2_GetExceptionCode();
459 if(!NT_SUCCESS(Status
))
462 SetLastNtError(Status
);
466 if (dc
->rosdc
.hGCClipRgn
)
468 if((Rgn
= (PROSRGNDATA
)RGNOBJAPI_Lock(dc
->rosdc
.hGCClipRgn
, NULL
)))
470 IntLPtoDP(dc
, (LPPOINT
)&Rect
, 2);
471 Result
= REGION_RectInRegion(Rgn
, &Rect
);
472 RGNOBJAPI_Unlock(Rgn
);
482 IntGdiSetMetaRgn(PDC pDC
)
487 if ( pDC
->dclevel
.prgnMeta
)
489 if ( pDC
->dclevel
.prgnClip
)
491 TempRgn
= IntSysCreateRectpRgn(0,0,0,0);
494 Ret
= IntGdiCombineRgn( TempRgn
,
495 pDC
->dclevel
.prgnMeta
,
496 pDC
->dclevel
.prgnClip
,
500 GDIOBJ_ShareUnlockObjByPtr(pDC
->dclevel
.prgnMeta
);
501 if (!((PROSRGNDATA
)pDC
->dclevel
.prgnMeta
)->BaseObject
.ulShareCount
)
502 REGION_Delete(pDC
->dclevel
.prgnMeta
);
504 pDC
->dclevel
.prgnMeta
= TempRgn
;
506 GDIOBJ_ShareUnlockObjByPtr(pDC
->dclevel
.prgnClip
);
507 if (!((PROSRGNDATA
)pDC
->dclevel
.prgnClip
)->BaseObject
.ulShareCount
)
508 REGION_Delete(pDC
->dclevel
.prgnClip
);
510 pDC
->dclevel
.prgnClip
= NULL
;
512 IntGdiReleaseRaoRgn(pDC
);
515 REGION_Delete(TempRgn
);
519 Ret
= REGION_Complexity(pDC
->dclevel
.prgnMeta
);
523 if ( pDC
->dclevel
.prgnClip
)
525 Ret
= REGION_Complexity(pDC
->dclevel
.prgnClip
);
526 pDC
->dclevel
.prgnMeta
= pDC
->dclevel
.prgnClip
;
527 pDC
->dclevel
.prgnClip
= NULL
;
535 int APIENTRY
NtGdiSetMetaRgn(HDC hDC
)
538 PDC pDC
= DC_LockDc(hDC
);
542 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
545 Ret
= IntGdiSetMetaRgn(pDC
);
552 NEW_CLIPPING_UpdateGCRegion(PDC pDC
)
556 /* Must have VisRgn set to a valid state! */
557 if (!pDC
->prgnVis
) return ERROR
;
561 REGION_Delete(pDC
->prgnAPI
);
562 pDC
->prgnAPI
= IntSysCreateRectpRgn(0,0,0,0);
567 REGION_Delete(pDC
->prgnRao
);
568 pDC
->prgnRao
= IntSysCreateRectpRgn(0,0,0,0);
571 if (pDC
->dclevel
.prgnMeta
&& pDC
->dclevel
.prgnClip
)
573 IntGdiCombineRgn( pDC
->prgnAPI
,
574 pDC
->dclevel
.prgnClip
,
575 pDC
->dclevel
.prgnMeta
,
580 if (pDC
->dclevel
.prgnClip
)
582 IntGdiCombineRgn( pDC
->prgnAPI
,
583 pDC
->dclevel
.prgnClip
,
587 else if (pDC
->dclevel
.prgnMeta
)
589 IntGdiCombineRgn( pDC
->prgnAPI
,
590 pDC
->dclevel
.prgnMeta
,
596 IntGdiCombineRgn( pDC
->prgnRao
,
601 RtlCopyMemory( &pDC
->erclClip
,
602 &((PROSRGNDATA
)pDC
->prgnRao
)->rdh
.rcBound
,
605 pDC
->fs
&= ~DC_FLAG_DIRTY_RAO
;
607 IntGdiOffsetRgn(pDC
->prgnRao
, pDC
->ptlDCOrig
.x
, pDC
->ptlDCOrig
.y
);
609 if (pDC
->rosdc
.CombinedClip
!= NULL
)
610 IntEngDeleteClipRegion(pDC
->rosdc
.CombinedClip
);
612 // pDC->co should be used. Example, CLIPOBJ_cEnumStart uses XCLIPOBJ to build
613 // the rects from region objects rects in pClipRgn->Buffer.
614 // With pDC->co.pClipRgn->Buffer,
615 // pDC->co.pClipRgn = pDC->prgnRao ? pDC->prgnRao : pDC->prgnVis;
617 co
= IntEngCreateClipRegion( ((PROSRGNDATA
)pDC
->prgnRao
)->rdh
.nCount
,
618 ((PROSRGNDATA
)pDC
->prgnRao
)->Buffer
,
621 pDC
->rosdc
.CombinedClip
= co
;
623 return IntGdiOffsetRgn(pDC
->prgnRao
, -pDC
->ptlDCOrig
.x
, -pDC
->ptlDCOrig
.y
);