7 SortRects(PRECT pRect
, INT nCount
)
9 INT i
= 0, a
= 0, b
= 0, c
, s
;
14 i
= 1; // set index point
15 c
= nCount
; // set inverse count
18 s
= i
; // set sort count
25 if(pRect
[b
].top
!= pRect
[i
].bottom
) break;
26 if(pRect
[b
].left
< pRect
[a
].left
)
34 } while ( s
< nCount
);
42 * I thought it was okay to have this in DeleteObject but~ Speed. (jt)
46 DeleteRegion( HRGN hRgn
)
51 if ((GdiGetHandleUserData((HGDIOBJ
) hRgn
, GDI_OBJECT_TYPE_REGION
, (PVOID
) &Rgn_Attr
)) &&
54 PTEB pTeb
= NtCurrentTeb();
55 if (pTeb
->Win32ThreadInfo
!= NULL
)
57 if ((pTeb
->GdiTebBatch
.Offset
+ sizeof(GDIBSOBJECT
)) <= GDIBATCHBUFSIZE
)
59 PGDIBSOBJECT pgO
= (PGDIBSOBJECT
)(&pTeb
->GdiTebBatch
.Buffer
[0] +
60 pTeb
->GdiTebBatch
.Offset
);
61 pgO
->gbHdr
.Cmd
= GdiBCDelRgn
;
62 pgO
->gbHdr
.Size
= sizeof(GDIBSOBJECT
);
63 pgO
->hgdiobj
= (HGDIOBJ
)hRgn
;
65 pTeb
->GdiTebBatch
.Offset
+= sizeof(GDIBSOBJECT
);
66 pTeb
->GdiBatchCount
++;
67 if (pTeb
->GdiBatchCount
>= GDI_BatchLimit
) NtGdiFlush();
73 return NtGdiDeleteObjectApp((HGDIOBJ
) hRgn
);
78 MirrorRgnByWidth(HRGN hRgn
, INT Width
, HRGN
*phRgn
)
80 INT cRgnDSize
, Ret
= 0;
83 cRgnDSize
= NtGdiGetRegionData(hRgn
, 0, NULL
);
87 pRgnData
= LocalAlloc(LMEM_FIXED
, cRgnDSize
* sizeof(LONG
));
90 if ( GetRegionData(hRgn
, cRgnDSize
, pRgnData
) )
94 INT SaveL
= pRgnData
->rdh
.rcBound
.left
;
95 pRgnData
->rdh
.rcBound
.left
= Width
- pRgnData
->rdh
.rcBound
.right
;
96 pRgnData
->rdh
.rcBound
.right
= Width
- SaveL
;
97 if (pRgnData
->rdh
.nCount
> 0)
99 PRECT pRect
= (PRECT
)&pRgnData
->Buffer
;
100 for (i
= 0; i
< pRgnData
->rdh
.nCount
; i
++)
102 SaveL
= pRect
[i
].left
;
103 pRect
[i
].left
= Width
- pRect
[i
].right
;
104 pRect
[i
].right
= Width
- SaveL
;
107 SortRects((PRECT
)&pRgnData
->Buffer
, pRgnData
->rdh
.nCount
);
108 hRgnex
= ExtCreateRegion(NULL
, cRgnDSize
, pRgnData
);
111 if (phRgn
) phRgn
= (HRGN
*)hRgnex
;
114 CombineRgn(hRgn
, hRgnex
, 0, RGN_COPY
);
115 DeleteObject(hRgnex
);
128 MirrorRgnDC(HDC hdc
, HRGN hRgn
, HRGN
*phRgn
)
130 if (!GdiIsHandleValid((HGDIOBJ
) hdc
) ||
131 (GDI_HANDLE_GET_TYPE(hdc
) != GDI_OBJECT_TYPE_DC
)) return 0;
133 return MirrorRgnByWidth(hRgn
, NtGdiGetDeviceWidth(hdc
), phRgn
);
136 /* FUNCTIONS *****************************************************************/
143 CreatePolygonRgn( const POINT
* lppt
, int cPoints
, int fnPolyFillMode
)
145 return (HRGN
) NtGdiPolyPolyDraw( (HDC
) fnPolyFillMode
, (PPOINT
) lppt
, (PULONG
) &cPoints
, 1, GdiPolyPolyRgn
);
154 CreatePolyPolygonRgn( const POINT
* lppt
,
155 const INT
* lpPolyCounts
,
159 return (HRGN
) NtGdiPolyPolyDraw( (HDC
) fnPolyFillMode
, (PPOINT
) lppt
, (PULONG
) lpPolyCounts
, (ULONG
) nCount
, GdiPolyPolyRgn
);
168 CreateEllipticRgnIndirect(
172 /* Notes if prc is NULL it will crash on All Windows NT I checked 2000/XP/VISTA */
173 return NtGdiCreateEllipticRgn(prc
->left
, prc
->top
, prc
->right
, prc
->bottom
);
182 CreateRectRgn(int x1
, int y1
, int x2
,int y2
)
184 /* FIXME Some part need be done in user mode */
185 return NtGdiCreateRectRgn(x1
,y1
,x2
,y2
);
193 CreateRectRgnIndirect(
197 /* Notes if prc is NULL it will crash on All Windows NT I checked 2000/XP/VISTA */
198 return CreateRectRgn(prc
->left
, prc
->top
, prc
->right
, prc
->bottom
);
208 CONST XFORM
* lpXform
,
210 CONST RGNDATA
* lpRgnData
215 if ((!lpXform
) && (lpRgnData
->rdh
.nCount
== 1))
217 PRECT pRect
= (PRECT
)&lpRgnData
->Buffer
[0];
218 return CreateRectRgn(pRect
->left
, pRect
->top
, pRect
->right
, pRect
->bottom
);
220 return NtGdiExtCreateRegion((LPXFORM
) lpXform
, nCount
,(LPRGNDATA
) lpRgnData
);
222 SetLastError(ERROR_INVALID_PARAMETER
);
236 INT Ret
= NtGdiGetRandomRgn(hdc
, hrgn
, CLIPRGN
);
239 // if(GetLayout(hdc) & LAYOUT_RTL) MirrorRgnDC(hdc,(HRGN)Ret, NULL);
252 return NtGdiGetRandomRgn(hdc
, hrgn
, METARGN
);
260 MirrorRgn(HWND hwnd
, HRGN hrgn
)
263 GetWindowRect(hwnd
, &Rect
);
264 return MirrorRgnByWidth(hrgn
, Rect
.right
- Rect
.left
, NULL
);
276 return ExtSelectClipRgn(hdc
, hrgn
, RGN_COPY
);
284 SetRectRgn(HRGN hrgn
,
293 if (!GdiGetHandleUserData((HGDIOBJ
) hrgn
, GDI_OBJECT_TYPE_REGION
, (PVOID
) &Rgn_Attr
))
295 return NtGdiSetRectRgn(hrgn
, nLeftRect
, nTopRect
, nRightRect
, nBottomRect
);
297 if ((nLeftRect
== nRightRect
) || (nTopRect
== nBottomRect
))
299 Rgn_Attr
->flFlags
|= DIRTY_RGNATTR
;
300 Rgn_Attr
->dwType
= RGNATTR_INIT
;
301 Rgn_Attr
->rcBound
.left
= Rgn_Attr
->rcBound
.top
=
302 Rgn_Attr
->rcBound
.right
= Rgn_Attr
->rcBound
.bottom
= 0;
306 Rgn_Attr
->rcBound
.left
= nLeftRect
;
307 Rgn_Attr
->rcBound
.top
= nTopRect
;
308 Rgn_Attr
->rcBound
.right
= nRightRect
;
309 Rgn_Attr
->rcBound
.bottom
= nBottomRect
;
311 if(nLeftRect
> nRightRect
)
313 Rgn_Attr
->rcBound
.left
= nRightRect
;
314 Rgn_Attr
->rcBound
.right
= nLeftRect
;
316 if(nTopRect
> nBottomRect
)
318 Rgn_Attr
->rcBound
.top
= nBottomRect
;
319 Rgn_Attr
->rcBound
.bottom
= nTopRect
;
322 Rgn_Attr
->flFlags
|= DIRTY_RGNATTR
;
323 Rgn_Attr
->dwType
= RGNATTR_SET
;
333 SetMetaRgn( HDC hDC
)
335 if (GDI_HANDLE_GET_TYPE(hDC
) == GDI_OBJECT_TYPE_DC
)
336 return NtGdiSetMetaRgn(hDC
);
338 PLDC pLDC
= GdiGetLDC(hDC
);
339 if ( pLDC
&& GDI_HANDLE_GET_TYPE(hDC
) != GDI_OBJECT_TYPE_METADC
)
341 if (pLDC
->iType
== LDC_EMFLDC
|| EMFDRV_SetMetaRgn(hDC
))
343 return NtGdiSetMetaRgn(hDC
);
346 SetLastError(ERROR_INVALID_HANDLE
);