From 6cfbcd06d452cf04b95d7048dda57160b3896991 Mon Sep 17 00:00:00 2001 From: "michaelp%netscape.com" Date: Wed, 2 Dec 1998 00:36:56 +0000 Subject: [PATCH] added GetNativeRegion() and GetRegionComplexity() methods. --- gfx/src/gtk/nsRegionGTK.cpp | 20 ++++++++--------- gfx/src/gtk/nsRegionGTK.h | 16 ++++---------- gfx/src/gtk/nsRenderingContextGTK.cpp | 4 ++-- gfx/src/mac/nsRegionMac.cpp | 14 ++++++++++-- gfx/src/mac/nsRegionMac.h | 15 ++++--------- gfx/src/mac/nsRenderingContextMac.cpp | 4 +--- gfx/src/motif/nsRegionMotif.cpp | 12 ++++++++--- gfx/src/motif/nsRegionMotif.h | 15 ++++--------- gfx/src/motif/nsRenderingContextMotif.cpp | 4 ++-- gfx/src/nsIRegion.h | 24 ++++++++++++++++++++- gfx/src/windows/nsRegionWin.cpp | 26 +++++++++++++++++++++-- gfx/src/windows/nsRegionWin.h | 6 ++---- gfx/src/windows/nsRenderingContextWin.cpp | 5 +++-- 13 files changed, 99 insertions(+), 66 deletions(-) diff --git a/gfx/src/gtk/nsRegionGTK.cpp b/gfx/src/gtk/nsRegionGTK.cpp index f0aa059bc9cd..ad98e8210f8d 100644 --- a/gfx/src/gtk/nsRegionGTK.cpp +++ b/gfx/src/gtk/nsRegionGTK.cpp @@ -212,10 +212,16 @@ PRBool nsRegionGTK :: ForEachRect(nsRectInRegionFunc *func, void *closure) return PR_FALSE; } - -GdkRegion * nsRegionGTK :: GetGTKRegion(void) +NS_IMETHODIMP nsRegionGTK :: GetNativeRegion(void *&aRegion) const { - return (mRegion); + aRegion = (void *)mRegion; + return NS_OK; +} + +NS_IMETHODIMP nsRegionGTK :: GetRegionComplexity(nsRegionComplexity &aComplexity) const +{ + aComplexity = mRegionType; + return NS_OK; } void nsRegionGTK :: SetRegionType() @@ -247,11 +253,3 @@ GdkRegion * nsRegionGTK :: CreateRectRegion(PRInt32 aX, PRInt32 aY, PRInt32 aWid return (rRegion); } - - - - - - - - diff --git a/gfx/src/gtk/nsRegionGTK.h b/gfx/src/gtk/nsRegionGTK.h index 54cca84ebc09..de226b556f2e 100644 --- a/gfx/src/gtk/nsRegionGTK.h +++ b/gfx/src/gtk/nsRegionGTK.h @@ -21,14 +21,6 @@ #include "nsIRegion.h" -enum nsRegionType { - eRegionType_empty, - eRegionType_rect, - eRegionType_poly, - eRegionType_complex -}; - - class nsRegionGTK : public nsIRegion { public: @@ -53,12 +45,12 @@ public: virtual void Offset(PRInt32 aXOffset, PRInt32 aYOffset); virtual PRBool ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); virtual PRBool ForEachRect(nsRectInRegionFunc *func, void *closure); - - GdkRegion * GetGTKRegion(void); + NS_IMETHOD GetNativeRegion(void *&aRegion) const; + NS_IMETHOD GetRegionComplexity(nsRegionComplexity &aComplexity) const; private: - GdkRegion *mRegion; - nsRegionType mRegionType; + GdkRegion *mRegion; + nsRegionComplexity mRegionType; private: virtual void SetRegionType(); diff --git a/gfx/src/gtk/nsRenderingContextGTK.cpp b/gfx/src/gtk/nsRenderingContextGTK.cpp index a968791d19a2..4e7714bc84a9 100644 --- a/gfx/src/gtk/nsRenderingContextGTK.cpp +++ b/gfx/src/gtk/nsRenderingContextGTK.cpp @@ -334,9 +334,9 @@ NS_IMETHODIMP nsRenderingContextGTK::SetClipRegion(const nsIRegion& aRegion, { nsRect rect; GdkRectangle gdk_rect; + GdkRegion *gdk_region; - nsRegionGTK *pRegion = (nsRegionGTK *)&aRegion; - GdkRegion *gdk_region = pRegion->GetGTKRegion(); + aRegion.GetNativeRegion((void *&)gdk_region); ::gdk_region_get_clipbox (gdk_region, &gdk_rect); diff --git a/gfx/src/mac/nsRegionMac.cpp b/gfx/src/mac/nsRegionMac.cpp index cf93c282948f..98bfb56e06e8 100644 --- a/gfx/src/mac/nsRegionMac.cpp +++ b/gfx/src/mac/nsRegionMac.cpp @@ -226,9 +226,19 @@ PRBool nsRegionMac :: ForEachRect(nsRectInRegionFunc *func, void *closure) //--------------------------------------------------------------------- -RgnHandle nsRegionMac :: GetRegion(void) + +NS_IMETHODIMP nsRegionMac :: GetNativeRegion(void *&aRegion) const { - return (mRegion); + aRegion = (void *)mRegion; + return NS_OK; +} + +//--------------------------------------------------------------------- + +NS_IMETHODIMP nsRegionMac :: GetRegionComplexity(nsRegionComplexity &aComplexity) const +{ + aComplexity = mRegionType; + return NS_OK; } //--------------------------------------------------------------------- diff --git a/gfx/src/mac/nsRegionMac.h b/gfx/src/mac/nsRegionMac.h index 3c08adb32e0e..addecd687463 100644 --- a/gfx/src/mac/nsRegionMac.h +++ b/gfx/src/mac/nsRegionMac.h @@ -22,13 +22,6 @@ #include "nsIRegion.h" #include -enum nsRegionType { - eRegionType_empty, - eRegionType_rect, - eRegionType_poly, - eRegionType_complex -}; - class nsRegionMac : public nsIRegion { @@ -54,12 +47,12 @@ public: virtual void Offset(PRInt32 aXOffset, PRInt32 aYOffset); virtual PRBool ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); virtual PRBool ForEachRect(nsRectInRegionFunc *func, void *closure); - - RgnHandle GetRegion(void); + NS_IMETHOD GetNativeRegion(void *&aRegion) const; + NS_IMETHOD GetRegionComplexity(nsRegionComplexity &aComplexity) const; private: - RgnHandle mRegion; - nsRegionType mRegionType; + RgnHandle mRegion; + nsRegionComplexity mRegionType; private: virtual void SetRegionType(); diff --git a/gfx/src/mac/nsRenderingContextMac.cpp b/gfx/src/mac/nsRenderingContextMac.cpp index 15a904e5441a..9166f1bd0d6a 100644 --- a/gfx/src/mac/nsRenderingContextMac.cpp +++ b/gfx/src/mac/nsRenderingContextMac.cpp @@ -475,10 +475,8 @@ NS_IMETHODIMP nsRenderingContextMac :: SetClipRegion(const nsIRegion& aRegion, n nsRect rect; Rect mrect; RgnHandle mregion; - - nsRegionMac *pRegion = (nsRegionMac *)&aRegion; - mregion = pRegion->GetRegion(); + aRegion.GetNativeRegion((void *&)mregion); mrect = (**mregion).rgnBBox; rect.x = mrect.left; diff --git a/gfx/src/motif/nsRegionMotif.cpp b/gfx/src/motif/nsRegionMotif.cpp index 7c0660ab11a4..7702f7e14ed6 100644 --- a/gfx/src/motif/nsRegionMotif.cpp +++ b/gfx/src/motif/nsRegionMotif.cpp @@ -192,10 +192,16 @@ PRBool nsRegionMotif :: ForEachRect(nsRectInRegionFunc *func, void *closure) return PR_FALSE; } - -Region nsRegionMotif :: GetXRegion(void) +NS_IMETHODIMP nsRegionMotif :: GetNativeRegion(void *&aRegion) const { - return (mRegion); + aRegion = (void *)mRegion; + return NS_OK; +} + +NS_IMETHODIMP nsRegionMotif :: GetRegionComplexity(nsRegionComplexity &aComplexity) const +{ + aComplexity = mRegionType; + return NS_OK; } void nsRegionMotif :: SetRegionType() diff --git a/gfx/src/motif/nsRegionMotif.h b/gfx/src/motif/nsRegionMotif.h index a4f22313e5d7..5708287ccb63 100644 --- a/gfx/src/motif/nsRegionMotif.h +++ b/gfx/src/motif/nsRegionMotif.h @@ -24,13 +24,6 @@ #include "X11/Xlib.h" #include "X11/Xutil.h" -enum nsRegionType { - eRegionType_empty, - eRegionType_rect, - eRegionType_poly, - eRegionType_complex -}; - class nsRegionMotif : public nsIRegion { @@ -56,12 +49,12 @@ public: virtual void Offset(PRInt32 aXOffset, PRInt32 aYOffset); virtual PRBool ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); virtual PRBool ForEachRect(nsRectInRegionFunc *func, void *closure); - - Region GetXRegion(void); + NS_IMETHOD GetNativeRegion(void *&aRegion) const; + NS_IMETHOD GetRegionComplexity(nsRegionComplexity &aComplexity) const; private: - Region mRegion; - nsRegionType mRegionType; + Region mRegion; + nsRegionComplexity mRegionType; private: virtual void SetRegionType(); diff --git a/gfx/src/motif/nsRenderingContextMotif.cpp b/gfx/src/motif/nsRenderingContextMotif.cpp index 52a9bc3ea0ea..069cc6800687 100644 --- a/gfx/src/motif/nsRenderingContextMotif.cpp +++ b/gfx/src/motif/nsRenderingContextMotif.cpp @@ -495,9 +495,9 @@ NS_IMETHODIMP nsRenderingContextMotif :: SetClipRegion(const nsIRegion& aRegion, { nsRect rect; XRectangle xrect; + Region xregion; - nsRegionMotif *pRegion = (nsRegionMotif *)&aRegion; - Region xregion = pRegion->GetXRegion(); + aRegion.GetNativeRegion((void *&)xregion); ::XClipBox(xregion, &xrect); diff --git a/gfx/src/nsIRegion.h b/gfx/src/nsIRegion.h index 3ac5f2972914..e418c6ae72d4 100644 --- a/gfx/src/nsIRegion.h +++ b/gfx/src/nsIRegion.h @@ -27,6 +27,13 @@ // for each rectangle in a region typedef void (*nsRectInRegionFunc)(void *closure, nsRect& rect); +enum nsRegionComplexity +{ + eRegionComplexity_empty = 0, + eRegionComplexity_rect = 1, + eRegionComplexity_complex = 2 +}; + // An implementation of a region primitive that can be used to // represent arbitrary pixel areas. Probably implemented on top // of the native region primitive. The assumption is that, at worst, @@ -39,7 +46,7 @@ typedef void (*nsRectInRegionFunc)(void *closure, nsRect& rect); class nsIRegion : public nsISupports { public: - virtual nsresult Init() = 0; + virtual nsresult Init(void) = 0; /** * copy operator equivalent that takes another region @@ -196,6 +203,21 @@ public: * **/ virtual PRBool ForEachRect(nsRectInRegionFunc *func, void *closure) = 0; + + /** + * Get the native region that this nsIRegion represents. + * @param aRegion out parameter for native region handle + * @return error status + **/ + NS_IMETHOD GetNativeRegion(void *&aRegion) const = 0; + + /** + * Get the complexity of the region as defined by the + * nsRegionComplexity enum. + * @param aComplexity out parameter for region complexity + * @return error status + **/ + NS_IMETHOD GetRegionComplexity(nsRegionComplexity &aComplexity) const = 0; }; #endif // nsRIegion_h___ diff --git a/gfx/src/windows/nsRegionWin.cpp b/gfx/src/windows/nsRegionWin.cpp index a9b1de35b32d..035452a33273 100644 --- a/gfx/src/windows/nsRegionWin.cpp +++ b/gfx/src/windows/nsRegionWin.cpp @@ -171,7 +171,29 @@ PRBool nsRegionWin :: ForEachRect(nsRectInRegionFunc *func, void *closure) return PR_FALSE; } -HRGN nsRegionWin :: GetHRGN(void) +NS_IMETHODIMP nsRegionWin :: GetNativeRegion(void *&aRegion) const { - return mRegion; + aRegion = (void *)mRegion; + return NS_OK; +} + +NS_IMETHODIMP nsRegionWin :: GetRegionComplexity(nsRegionComplexity &aComplexity) const +{ + switch (mRegionType) + { + case NULLREGION: + aComplexity = eRegionComplexity_empty; + break; + + case SIMPLEREGION: + aComplexity = eRegionComplexity_rect; + break; + + default: + case COMPLEXREGION: + aComplexity = eRegionComplexity_complex; + break; + } + + return NS_OK; } diff --git a/gfx/src/windows/nsRegionWin.h b/gfx/src/windows/nsRegionWin.h index bba6510f3573..30d70724cfaf 100644 --- a/gfx/src/windows/nsRegionWin.h +++ b/gfx/src/windows/nsRegionWin.h @@ -45,10 +45,8 @@ public: virtual void Offset(PRInt32 aXOffset, PRInt32 aYOffset); virtual PRBool ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); virtual PRBool ForEachRect(nsRectInRegionFunc *func, void *closure); - - //windows specific - - HRGN GetHRGN(void); + NS_IMETHOD GetNativeRegion(void *&aRegion) const; + NS_IMETHOD GetRegionComplexity(nsRegionComplexity &aComplexity) const; private: ~nsRegionWin(); diff --git a/gfx/src/windows/nsRenderingContextWin.cpp b/gfx/src/windows/nsRenderingContextWin.cpp index 54c702f2c685..afd3117a6a6a 100644 --- a/gfx/src/windows/nsRenderingContextWin.cpp +++ b/gfx/src/windows/nsRenderingContextWin.cpp @@ -928,10 +928,11 @@ NS_IMETHODIMP nsRenderingContextWin :: GetClipRect(nsRect &aRect, PRBool &aClipV NS_IMETHODIMP nsRenderingContextWin :: SetClipRegion(const nsIRegion& aRegion, nsClipCombine aCombine, PRBool &aClipEmpty) { - nsRegionWin *pRegion = (nsRegionWin *)&aRegion; - HRGN hrgn = pRegion->GetHRGN(); + HRGN hrgn; int cmode, cliptype; + aRegion.GetNativeRegion((void *&)hrgn); + switch (aCombine) { case nsClipCombine_kIntersect: