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
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 CLIPPING_UpdateGCRegion(DC
* Dc
)
28 PROSRGNDATA CombinedRegion
;
30 if (Dc
->rosdc
.hGCClipRgn
== NULL
)
31 Dc
->rosdc
.hGCClipRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
33 if (Dc
->rosdc
.hClipRgn
== NULL
)
34 NtGdiCombineRgn(Dc
->rosdc
.hGCClipRgn
, Dc
->rosdc
.hVisRgn
, 0, RGN_COPY
);
36 NtGdiCombineRgn(Dc
->rosdc
.hGCClipRgn
, Dc
->rosdc
.hClipRgn
, Dc
->rosdc
.hVisRgn
, RGN_AND
);
37 NtGdiOffsetRgn(Dc
->rosdc
.hGCClipRgn
, Dc
->ptlDCOrig
.x
, Dc
->ptlDCOrig
.y
);
39 if((CombinedRegion
= REGION_LockRgn(Dc
->rosdc
.hGCClipRgn
)))
41 if (Dc
->rosdc
.CombinedClip
!= NULL
)
42 IntEngDeleteClipRegion(Dc
->rosdc
.CombinedClip
);
44 Dc
->rosdc
.CombinedClip
= IntEngCreateClipRegion(
45 CombinedRegion
->rdh
.nCount
,
46 CombinedRegion
->Buffer
,
47 &CombinedRegion
->rdh
.rcBound
);
49 REGION_UnlockRgn(CombinedRegion
);
52 if ( NULL
== Dc
->rosdc
.CombinedClip
)
54 DPRINT1("IntEngCreateClipRegion() failed\n");
58 return NtGdiOffsetRgn(Dc
->rosdc
.hGCClipRgn
, -Dc
->ptlDCOrig
.x
, -Dc
->ptlDCOrig
.y
);
62 GdiSelectVisRgn(HDC hdc
, HRGN hrgn
)
69 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
72 if (!(dc
= DC_LockDc(hdc
)))
74 SetLastWin32Error(ERROR_INVALID_HANDLE
);
78 dc
->fs
&= ~DC_FLAG_DIRTY_RAO
;
80 if (dc
->rosdc
.hVisRgn
== NULL
)
82 dc
->rosdc
.hVisRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
83 GDIOBJ_CopyOwnership(hdc
, dc
->rosdc
.hVisRgn
);
86 retval
= NtGdiCombineRgn(dc
->rosdc
.hVisRgn
, hrgn
, 0, RGN_COPY
);
87 if ( retval
!= ERROR
)
89 NtGdiOffsetRgn(dc
->rosdc
.hVisRgn
, -dc
->ptlDCOrig
.x
, -dc
->ptlDCOrig
.y
);
90 CLIPPING_UpdateGCRegion(dc
);
98 int FASTCALL
GdiExtSelectClipRgn(PDC dc
,
103 // dc->fs &= ~DC_FLAG_DIRTY_RAO;
107 if (fnMode
== RGN_COPY
)
109 if (dc
->rosdc
.hClipRgn
!= NULL
)
111 GreDeleteObject(dc
->rosdc
.hClipRgn
);
112 dc
->rosdc
.hClipRgn
= NULL
;
118 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
124 if (!dc
->rosdc
.hClipRgn
)
128 if((Rgn
= REGION_LockRgn(dc
->rosdc
.hVisRgn
)))
130 REGION_GetRgnBox(Rgn
, &rect
);
131 REGION_UnlockRgn(Rgn
);
132 dc
->rosdc
.hClipRgn
= UnsafeIntCreateRectRgnIndirect(&rect
);
136 dc
->rosdc
.hClipRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
139 if(fnMode
== RGN_COPY
)
141 NtGdiCombineRgn(dc
->rosdc
.hClipRgn
, hrgn
, 0, fnMode
);
144 NtGdiCombineRgn(dc
->rosdc
.hClipRgn
, dc
->rosdc
.hClipRgn
, hrgn
, fnMode
);
147 retval
= CLIPPING_UpdateGCRegion(dc
);
152 int APIENTRY
NtGdiExtSelectClipRgn(HDC hDC
,
159 if (!(dc
= DC_LockDc(hDC
)))
161 SetLastWin32Error(ERROR_INVALID_HANDLE
);
165 retval
= GdiExtSelectClipRgn ( dc
, hrgn
, fnMode
);
172 GdiGetClipBox(HDC hDC
, PRECTL rc
)
178 if (!(dc
= DC_LockDc(hDC
)))
183 if (!(Rgn
= REGION_LockRgn(dc
->rosdc
.hGCClipRgn
)))
188 retval
= REGION_GetRgnBox(Rgn
, rc
);
189 REGION_UnlockRgn(Rgn
);
190 IntDPtoLP(dc
, (LPPOINT
)rc
, 2);
197 NtGdiGetAppClipBox(HDC hDC
, PRECTL rc
)
200 NTSTATUS Status
= STATUS_SUCCESS
;
203 Ret
= GdiGetClipBox(hDC
, &Saferect
);
212 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
214 Status
= _SEH2_GetExceptionCode();
218 if(!NT_SUCCESS(Status
))
220 SetLastNtError(Status
);
227 int APIENTRY
NtGdiExcludeClipRect(HDC hDC
,
236 PDC dc
= DC_LockDc(hDC
);
240 SetLastWin32Error(ERROR_INVALID_HANDLE
);
244 Rect
.left
= LeftRect
;
246 Rect
.right
= RightRect
;
247 Rect
.bottom
= BottomRect
;
249 IntLPtoDP(dc
, (LPPOINT
)&Rect
, 2);
251 NewRgn
= UnsafeIntCreateRectRgnIndirect(&Rect
);
258 if (!dc
->rosdc
.hClipRgn
)
260 dc
->rosdc
.hClipRgn
= NtGdiCreateRectRgn(0, 0, 0, 0);
261 NtGdiCombineRgn(dc
->rosdc
.hClipRgn
, dc
->rosdc
.hVisRgn
, NewRgn
, RGN_DIFF
);
262 Result
= SIMPLEREGION
;
266 Result
= NtGdiCombineRgn(dc
->rosdc
.hClipRgn
, dc
->rosdc
.hClipRgn
, NewRgn
, RGN_DIFF
);
268 GreDeleteObject(NewRgn
);
271 CLIPPING_UpdateGCRegion(dc
);
278 int APIENTRY
NtGdiIntersectClipRect(HDC hDC
,
287 PDC dc
= DC_LockDc(hDC
);
289 DPRINT("NtGdiIntersectClipRect(%x, %d,%d-%d,%d)\n",
290 hDC
, LeftRect
, TopRect
, RightRect
, BottomRect
);
294 SetLastWin32Error(ERROR_INVALID_HANDLE
);
298 Rect
.left
= LeftRect
;
300 Rect
.right
= RightRect
;
301 Rect
.bottom
= BottomRect
;
303 IntLPtoDP(dc
, (LPPOINT
)&Rect
, 2);
305 NewRgn
= UnsafeIntCreateRectRgnIndirect(&Rect
);
310 else if (!dc
->rosdc
.hClipRgn
)
312 dc
->rosdc
.hClipRgn
= NewRgn
;
313 Result
= SIMPLEREGION
;
317 Result
= NtGdiCombineRgn(dc
->rosdc
.hClipRgn
, dc
->rosdc
.hClipRgn
, NewRgn
, RGN_AND
);
318 GreDeleteObject(NewRgn
);
321 CLIPPING_UpdateGCRegion(dc
);
328 int APIENTRY
NtGdiOffsetClipRgn(HDC hDC
,
335 if(!(dc
= DC_LockDc(hDC
)))
337 SetLastWin32Error(ERROR_INVALID_HANDLE
);
341 if(dc
->rosdc
.hClipRgn
!= NULL
)
343 Result
= NtGdiOffsetRgn(dc
->rosdc
.hClipRgn
,
346 CLIPPING_UpdateGCRegion(dc
);
357 BOOL APIENTRY
NtGdiPtVisible(HDC hDC
,
364 if(!(dc
= DC_LockDc(hDC
)))
366 SetLastWin32Error(ERROR_INVALID_HANDLE
);
370 rgn
= dc
->rosdc
.hGCClipRgn
;
373 return (rgn
? NtGdiPtInRegion(rgn
, X
, Y
) : FALSE
);
376 BOOL APIENTRY
NtGdiRectVisible(HDC hDC
,
379 NTSTATUS Status
= STATUS_SUCCESS
;
381 PDC dc
= DC_LockDc(hDC
);
387 SetLastWin32Error(ERROR_INVALID_HANDLE
);
393 ProbeForRead(UnsafeRect
,
398 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
400 Status
= _SEH2_GetExceptionCode();
404 if(!NT_SUCCESS(Status
))
407 SetLastNtError(Status
);
411 if (dc
->rosdc
.hGCClipRgn
)
413 if((Rgn
= (PROSRGNDATA
)REGION_LockRgn(dc
->rosdc
.hGCClipRgn
)))
415 IntLPtoDP(dc
, (LPPOINT
)&Rect
, 2);
416 Result
= REGION_RectInRegion(Rgn
, &Rect
);
417 REGION_UnlockRgn(Rgn
);
427 IntGdiSetMetaRgn(PDC pDC
)
432 if ( pDC
->dclevel
.prgnMeta
)
434 if ( pDC
->dclevel
.prgnClip
)
436 TempRgn
= IntGdiCreateRectRgn(0,0,0,0);
439 Ret
= IntGdiCombineRgn( TempRgn
,
440 pDC
->dclevel
.prgnMeta
,
441 pDC
->dclevel
.prgnClip
,
445 GDIOBJ_ShareUnlockObjByPtr(pDC
->dclevel
.prgnMeta
);
446 if (!((PROSRGNDATA
)pDC
->dclevel
.prgnMeta
)->BaseObject
.ulShareCount
)
447 REGION_Delete(pDC
->dclevel
.prgnMeta
);
449 pDC
->dclevel
.prgnMeta
= TempRgn
;
451 GDIOBJ_ShareUnlockObjByPtr(pDC
->dclevel
.prgnClip
);
452 if (!((PROSRGNDATA
)pDC
->dclevel
.prgnClip
)->BaseObject
.ulShareCount
)
453 REGION_Delete(pDC
->dclevel
.prgnClip
);
455 pDC
->dclevel
.prgnClip
= NULL
;
457 IntGdiReleaseRaoRgn(pDC
);
460 REGION_Delete(TempRgn
);
464 Ret
= REGION_Complexity(pDC
->dclevel
.prgnMeta
);
468 if ( pDC
->dclevel
.prgnClip
)
470 Ret
= REGION_Complexity(pDC
->dclevel
.prgnClip
);
471 pDC
->dclevel
.prgnMeta
= pDC
->dclevel
.prgnClip
;
472 pDC
->dclevel
.prgnClip
= NULL
;
481 int APIENTRY
NtGdiSetMetaRgn(HDC hDC
)
484 PDC pDC
= DC_LockDc(hDC
);
488 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
491 Ret
= IntGdiSetMetaRgn(pDC
);
498 NEW_CLIPPING_UpdateGCRegion(PDC pDC
)
502 if (!pDC
->prgnVis
) return 0;
506 REGION_Delete(pDC
->prgnAPI
);
507 pDC
->prgnAPI
= IntGdiCreateRectRgn(0,0,0,0);
512 REGION_Delete(pDC
->prgnRao
);
513 pDC
->prgnRao
= IntGdiCreateRectRgn(0,0,0,0);
516 if (pDC
->dclevel
.prgnMeta
&& pDC
->dclevel
.prgnClip
)
518 IntGdiCombineRgn( pDC
->prgnAPI
,
519 pDC
->dclevel
.prgnClip
,
520 pDC
->dclevel
.prgnMeta
,
525 if (pDC
->dclevel
.prgnClip
)
526 IntGdiCombineRgn( pDC
->prgnAPI
,
527 pDC
->dclevel
.prgnClip
,
530 else if (pDC
->dclevel
.prgnMeta
)
531 IntGdiCombineRgn( pDC
->prgnAPI
,
532 pDC
->dclevel
.prgnMeta
,
537 IntGdiCombineRgn( pDC
->prgnRao
,
542 RtlCopyMemory(&pDC
->erclClip
, &((PROSRGNDATA
)pDC
->prgnRao
)->rdh
.rcBound
, sizeof(RECTL
));
543 pDC
->fs
&= ~DC_FLAG_DIRTY_RAO
;
545 // if (Dc->CombinedClip != NULL) IntEngDeleteClipRegion(Dc->CombinedClip);
547 co
= IntEngCreateClipRegion( ((PROSRGNDATA
)pDC
->prgnRao
)->rdh
.nCount
,
548 ((PROSRGNDATA
)pDC
->prgnRao
)->Buffer
,
551 return REGION_Complexity(pDC
->prgnRao
);