From aa0e79fade1f4db85e689621132dcd6a438962e0 Mon Sep 17 00:00:00 2001 From: spider Date: Thu, 4 Jun 1998 08:40:58 +0000 Subject: [PATCH] Implemented nsRegionUnix --- gfx/src/motif/nsRegionUnix.cpp | 103 +++++++++++++++++++++++++++++++-- gfx/src/motif/nsRegionUnix.h | 17 +++++- 2 files changed, 115 insertions(+), 5 deletions(-) diff --git a/gfx/src/motif/nsRegionUnix.cpp b/gfx/src/motif/nsRegionUnix.cpp index bb526f4a88a6..813bbf7944d8 100644 --- a/gfx/src/motif/nsRegionUnix.cpp +++ b/gfx/src/motif/nsRegionUnix.cpp @@ -23,10 +23,16 @@ static NS_DEFINE_IID(kRegionIID, NS_IREGION_IID); nsRegionUnix :: nsRegionUnix() { NS_INIT_REFCNT(); + + mRegion = nsnull; + mRegionType = eRegionType_empty; } nsRegionUnix :: ~nsRegionUnix() { + if (mRegion) + ::XDestroyRegion(mRegion); + mRegion = nsnull; } NS_IMPL_QUERY_INTERFACE(nsRegionUnix, kRegionIID) @@ -35,65 +41,154 @@ NS_IMPL_RELEASE(nsRegionUnix) nsresult nsRegionUnix :: Init(void) { + mRegion = ::XCreateRegion(); + mRegionType = eRegionType_empty; + return NS_OK; } void nsRegionUnix :: SetTo(const nsIRegion &aRegion) { + nsRegionUnix * pRegion = (nsRegionUnix *)&aRegion; + + ::XDestroyRegion(mRegion); + mRegion = ::XCreateRegion(); + + ::XUnionRegion(mRegion, pRegion->mRegion, mRegion); + + mRegionType = eRegionType_rect ; // XXX: Should probably set to complex } void nsRegionUnix :: SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight) { + ::XDestroyRegion(mRegion); + mRegion = ::XCreateRegion(); + + ::XOffsetRegion(mRegion, aX, aY); + ::XShrinkRegion(mRegion, -aWidth, -aHeight); + + mRegionType = eRegionType_rect ; } void nsRegionUnix :: Intersect(const nsIRegion &aRegion) { + nsRegionUnix * pRegion = (nsRegionUnix *)&aRegion; + + ::XIntersectRegion(mRegion, pRegion->mRegion, mRegion); + + mRegionType = eRegionType_rect ; } void nsRegionUnix :: Intersect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight) { + Region tRegion; + + tRegion = ::XCreateRegion(); + + ::XOffsetRegion(tRegion, aX, aY); + ::XShrinkRegion(tRegion, -aWidth, -aHeight); + + ::XIntersectRegion(mRegion, tRegion, mRegion); + + ::XDestroyRegion(tRegion); + + mRegionType = eRegionType_rect ; } void nsRegionUnix :: Union(const nsIRegion &aRegion) { + nsRegionUnix * pRegion = (nsRegionUnix *)&aRegion; + + ::XUnionRegion(mRegion, pRegion->mRegion, mRegion); + + mRegionType = eRegionType_rect ; } void nsRegionUnix :: Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight) { + Region tRegion; + + tRegion = ::XCreateRegion(); + + ::XOffsetRegion(tRegion, aX, aY); + ::XShrinkRegion(tRegion, -aWidth, -aHeight); + + ::XUnionRegion(mRegion, tRegion, mRegion); + + ::XDestroyRegion(tRegion); + + mRegionType = eRegionType_rect ; } void nsRegionUnix :: Subtract(const nsIRegion &aRegion) { + nsRegionUnix * pRegion = (nsRegionUnix *)&aRegion; + + ::XSubtractRegion(mRegion, pRegion->mRegion, mRegion); + + mRegionType = eRegionType_rect ; } void nsRegionUnix :: Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight) { + Region tRegion; + + tRegion = ::XCreateRegion(); + + ::XOffsetRegion(tRegion, aX, aY); + ::XShrinkRegion(tRegion, -aWidth, -aHeight); + + ::XSubtractRegion(mRegion, tRegion, mRegion); + + ::XDestroyRegion(tRegion); + + mRegionType = eRegionType_rect ; } PRBool nsRegionUnix :: IsEmpty(void) { - return PR_FALSE; + return (::XEmptyRegion(mRegion)); } PRBool nsRegionUnix :: IsEqual(const nsIRegion &aRegion) { - return PR_FALSE; + nsRegionUnix * pRegion = (nsRegionUnix *)&aRegion; + + return(::XEqualRegion(mRegion, pRegion->mRegion)); + } void nsRegionUnix :: GetBoundingBox(PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight) { - *aX = *aY = *aWidth = *aHeight = 0; + XRectangle rect; + + ::XClipBox(mRegion, &rect); + + *aX = rect.x; + *aY = rect.y; + *aWidth = rect.width; + *aHeight = rect.height; } void nsRegionUnix :: Offset(PRInt32 aXOffset, PRInt32 aYOffset) { + ::XOffsetRegion(mRegion, aXOffset, aYOffset); } PRBool nsRegionUnix :: ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight) { - return PR_TRUE; + PRInt32 containment; + + containment = ::XRectInRegion(mRegion, aX, aY, aWidth, aHeight); + + if (containment == RectangleIn) + return PR_TRUE; + else + return PR_FALSE; + } PRBool nsRegionUnix :: ForEachRect(nsRectInRegionFunc *func, void *closure) { return PR_FALSE; } + diff --git a/gfx/src/motif/nsRegionUnix.h b/gfx/src/motif/nsRegionUnix.h index 0a76a9ba7bf8..77b360c8e84c 100644 --- a/gfx/src/motif/nsRegionUnix.h +++ b/gfx/src/motif/nsRegionUnix.h @@ -21,10 +21,22 @@ #include "nsIRegion.h" +#include "X11/Xlib.h" +#include "X11/Xutil.h" + +enum nsRegionType { + eRegionType_empty, + eRegionType_rect, + eRegionType_poly, + eRegionType_complex, +}; + + class nsRegionUnix : public nsIRegion { public: nsRegionUnix(); + ~nsRegionUnix(); NS_DECL_ISUPPORTS @@ -46,7 +58,10 @@ public: virtual PRBool ForEachRect(nsRectInRegionFunc *func, void *closure); private: - ~nsRegionUnix(); + Region mRegion; + nsRegionType mRegionType; + + }; #endif // nsRegionUnix_h___