Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Attributes
nsRegionGTK Class Reference

#include <nsRegionGTK.h>

Inheritance diagram for nsRegionGTK:
Inheritance graph
[legend]
Collaboration diagram for nsRegionGTK:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsRegionGTK ()
virtual ~nsRegionGTK ()
virtual NS_DECL_ISUPPORTS nsresult Init ()
virtual void SetTo (const nsIRegion &aRegion)
 copy operator equivalent that takes another region
virtual void SetTo (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 copy operator equivalent that takes a rect
virtual void Intersect (const nsIRegion &aRegion)
 destructively intersect another region with this one
virtual void Intersect (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 destructively intersect a rect with this region
virtual void Union (const nsIRegion &aRegion)
 destructively union another region with this one
virtual void Union (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 destructively union a rect with this region
virtual void Subtract (const nsIRegion &aRegion)
 destructively subtract another region with this one
virtual void Subtract (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 destructively subtract a rect from this region
virtual PRBool IsEmpty (void)
 is this region empty? i.e.
virtual PRBool IsEqual (const nsIRegion &aRegion)
 == operator equivalent i.e.
virtual void GetBoundingBox (PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight)
 returns the bounding box of the region i.e.
virtual void Offset (PRInt32 aXOffset, PRInt32 aYOffset)
 offsets the region in x and y
virtual PRBool ContainsRect (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 does the region intersect the rectangle?
NS_IMETHOD GetRects (nsRegionRectSet **aRects)
 get the set of rects which make up this region.
NS_IMETHOD FreeRects (nsRegionRectSet *aRects)
 Free a rect set returned by GetRects.
NS_IMETHOD GetNativeRegion (void *&aRegion) const
 Get the native region that this nsIRegion represents.
NS_IMETHOD GetRegionComplexity (nsRegionComplexity &aComplexity) const
 Get the complexity of the region as defined by the nsRegionComplexity enum.
NS_IMETHOD GetNumRects (PRUint32 *aRects) const
 get the number of rects which make up this region.

Private Attributes

GdkRegion * mRegion

Detailed Description

Definition at line 47 of file nsRegionGTK.h.


Constructor & Destructor Documentation

Definition at line 53 of file nsRegionGTK.cpp.

{
#ifdef DEBUG_REGIONS
  ++nRegions;
  printf("REGIONS+ = %i\n", nRegions);
#endif

  mRegion = nsnull;
}

Definition at line 63 of file nsRegionGTK.cpp.

{
#ifdef DEBUG_REGIONS
  --nRegions;
  printf("REGIONS- = %i\n", nRegions);
#endif

  if (mRegion)
    ::gdk_region_destroy(mRegion);
  mRegion = nsnull;
}

Member Function Documentation

PRBool nsRegionGTK::ContainsRect ( PRInt32  aX,
PRInt32  aY,
PRInt32  aWidth,
PRInt32  aHeight 
) [virtual]

does the region intersect the rectangle?

Parameters:
rectto check for containment
Returns:
true if the region intersects the rect

Implements nsIRegion.

Definition at line 291 of file nsRegionGTK.cpp.

{
  if (mRegion) {
    GdkOverlapType containment;
    GdkRectangle rect;
   
    rect.x = aX;
    rect.y = aY;
    rect.width = aWidth;
    rect.height = aHeight;
   
    containment = ::gdk_region_rect_in(mRegion, &rect);

    if (containment != GDK_OVERLAP_RECTANGLE_OUT)
      return PR_TRUE;
  }
  return PR_FALSE;
}

Free a rect set returned by GetRects.

Parameters:
aRectsrects to free
Returns:
error status

Implements nsIRegion.

Definition at line 374 of file nsRegionGTK.cpp.

{
  if (nsnull != aRects)
    PR_Free((void *)aRects);

  return NS_OK;
}

Here is the caller graph for this function:

void nsRegionGTK::GetBoundingBox ( PRInt32 aX,
PRInt32 aY,
PRInt32 aWidth,
PRInt32 aHeight 
) [virtual]

returns the bounding box of the region i.e.

the smallest rectangle that completely contains the region.

Parameters:
aXout parameter for xoffset of bounding rect for region
aYout parameter for yoffset of bounding rect for region
aWidthout parameter for width of bounding rect for region
aHeightout parameter for height of bounding rect for region
Returns:
void

Implements nsIRegion.

Definition at line 265 of file nsRegionGTK.cpp.

{
  if (mRegion) {
    GdkRectangle rect;

    ::gdk_region_get_clipbox(mRegion, &rect);

    *aX = rect.x;
    *aY = rect.y;
    *aWidth = rect.width;
    *aHeight = rect.height;
  } else {
    *aX = 0;
    *aY = 0;
    *aWidth = 0;
    *aHeight = 0;
  }
}
NS_IMETHODIMP nsRegionGTK::GetNativeRegion ( void *&  aRegion) const [virtual]

Get the native region that this nsIRegion represents.

Parameters:
aRegionout parameter for native region handle
Returns:
error status

Implements nsIRegion.

Definition at line 382 of file nsRegionGTK.cpp.

{
  aRegion = (void *)mRegion;
  return NS_OK;
}
NS_IMETHODIMP nsRegionGTK::GetNumRects ( PRUint32 aRects) const [virtual]

get the number of rects which make up this region.

Parameters:
aRectsout parameter containing the number of rects comprising the region
Returns:
error status

Implements nsIRegion.

Definition at line 406 of file nsRegionGTK.cpp.

{
  if (!mRegion)
    *aRects = 0;

  GdkRegionPrivate  *priv = (GdkRegionPrivate *)mRegion;
  Region pRegion = priv->xregion;

  *aRects = pRegion->numRects;

  return NS_OK;
}

get the set of rects which make up this region.

the aRects parameter must be freed by calling FreeRects before the region is deleted. aRects may be passed in again when requesting the rect list as a recycling method.

Parameters:
aRectsout parameter containing set of rects comprising the region
Returns:
error status

Implements nsIRegion.

Definition at line 310 of file nsRegionGTK.cpp.

{

  *aRects = nsnull;

  if (!mRegion)
    return NS_OK;

  nsRegionRectSet   *rects = nsnull;
  GdkRegionPrivate  *priv = nsnull;
  Region            pRegion;
  int               nbox = 0;
  BOX               *pbox = nsnull;
  nsRegionRect      *rect = nsnull;

  priv = (GdkRegionPrivate *)mRegion;
  pRegion = priv->xregion;
  pbox = pRegion->rects;
  nbox = pRegion->numRects;

  NS_ASSERTION(!(nsnull == aRects), "bad ptr");

  //code lifted from old xfe. MMP

  rects = *aRects;

  if ((nsnull == rects) || (rects->mRectsLen < (PRUint32)nbox))
  {
    void *buf = PR_Realloc(rects, sizeof(nsRegionRectSet) + (sizeof(nsRegionRect) * (nbox - 1)));

    if (nsnull == buf)
    {
      if (nsnull != rects)
        rects->mNumRects = 0;

      return NS_OK;
    }

    rects = (nsRegionRectSet *)buf;
    rects->mRectsLen = nbox;
  }

  rects->mNumRects = nbox;
  rects->mArea = 0;
  rect = &rects->mRects[0];

  while (nbox--)
  {
    rect->x = pbox->x1;
    rect->width = (pbox->x2 - pbox->x1);
    rect->y = pbox->y1;
    rect->height = (pbox->y2 - pbox->y1);

    rects->mArea += rect->width * rect->height;

    pbox++;
    rect++;
  }

  *aRects = rects;

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Get the complexity of the region as defined by the nsRegionComplexity enum.

Parameters:
aComplexityout parameter for region complexity
Returns:
error status

Implements nsIRegion.

Definition at line 388 of file nsRegionGTK.cpp.

{
  // cast to avoid const-ness problems on some compilers
  if (((nsRegionGTK*)this)->IsEmpty())
    aComplexity = eRegionComplexity_empty;
  else
    aComplexity = eRegionComplexity_complex;

  return NS_OK;
}

Here is the call graph for this function:

nsresult nsRegionGTK::Init ( void  ) [virtual]

Implements nsIRegion.

Definition at line 114 of file nsRegionGTK.cpp.

{
  if (mRegion) {
    gdk_region_destroy(mRegion);
    mRegion = nsnull;
  }

  return NS_OK;
}

Here is the caller graph for this function:

void nsRegionGTK::Intersect ( const nsIRegion aRegion) [virtual]

destructively intersect another region with this one

Parameters:
regionto intersect
Returns:
void

Implements nsIRegion.

Definition at line 140 of file nsRegionGTK.cpp.

{
  if(!mRegion) {
    NS_WARNING("mRegion is NULL");
    return;
  }

  nsRegionGTK * pRegion = (nsRegionGTK *)&aRegion;

  GdkRegion *nRegion = ::gdk_regions_intersect(mRegion, pRegion->mRegion);
  ::gdk_region_destroy(mRegion);
  mRegion = nRegion;
}

Here is the caller graph for this function:

void nsRegionGTK::Intersect ( PRInt32  aX,
PRInt32  aY,
PRInt32  aWidth,
PRInt32  aHeight 
) [virtual]

destructively intersect a rect with this region

Parameters:
aXxoffset of rect to intersect with region
aYyoffset of rect to intersect with region
aWidthwidth of rect to intersect with region
aHeightheight of rect to intersect with region
Returns:
void

Implements nsIRegion.

Definition at line 154 of file nsRegionGTK.cpp.

{
  if(!mRegion) {
    NS_WARNING("mRegion is NULL");
    return;
  }

  GdkRegion *tRegion = gdk_region_from_rect(aX, aY, aWidth, aHeight);

  GdkRegion *nRegion = ::gdk_regions_intersect(mRegion, tRegion);
  ::gdk_region_destroy(tRegion);
  ::gdk_region_destroy(mRegion);
  mRegion = nRegion;
}
PRBool nsRegionGTK::IsEmpty ( void  ) [virtual]

is this region empty? i.e.

does it contain any pixels

Parameters:
none
Returns:
returns whether the region is empty

Implements nsIRegion.

Definition at line 243 of file nsRegionGTK.cpp.

{
  if (!mRegion)
    return PR_TRUE;
  return (::gdk_region_empty(mRegion));
}

Here is the caller graph for this function:

PRBool nsRegionGTK::IsEqual ( const nsIRegion aRegion) [virtual]

== operator equivalent i.e.

do the regions contain exactly the same pixels

Parameters:
regionto compare
Returns:
whether the regions are identical

Implements nsIRegion.

Definition at line 250 of file nsRegionGTK.cpp.

{
  nsRegionGTK *pRegion = (nsRegionGTK *)&aRegion;

  if (mRegion && pRegion->mRegion) {
    return(::gdk_region_equal(mRegion, pRegion->mRegion));
  } else if (!mRegion && !pRegion->mRegion) {
    return PR_TRUE;
  } else if ((mRegion && !pRegion->mRegion) || (!mRegion && pRegion->mRegion)) {
    return PR_FALSE;
  }

  return PR_FALSE;
}
void nsRegionGTK::Offset ( PRInt32  aXOffset,
PRInt32  aYOffset 
) [virtual]

offsets the region in x and y

Parameters:
xoffsetpixel offset in x
yoffsetpixel offset in y
Returns:
void

Implements nsIRegion.

Definition at line 284 of file nsRegionGTK.cpp.

{
  if (mRegion) {
    ::gdk_region_offset(mRegion, aXOffset, aYOffset);
  }
}
void nsRegionGTK::SetTo ( const nsIRegion aRegion) [virtual]

copy operator equivalent that takes another region

Parameters:
regionto copy
Returns:
void

Implements nsIRegion.

Definition at line 124 of file nsRegionGTK.cpp.

{
  Init();

  nsRegionGTK *pRegion = (nsRegionGTK *)&aRegion;

  mRegion = gdk_region_copy(pRegion->mRegion);
}

Here is the call graph for this function:

void nsRegionGTK::SetTo ( PRInt32  aX,
PRInt32  aY,
PRInt32  aWidth,
PRInt32  aHeight 
) [virtual]

copy operator equivalent that takes a rect

Parameters:
aXxoffset of rect to set region to
aYyoffset of rect to set region to
aWidthwidth of rect to set region to
aHeightheight of rect to set region to
Returns:
void

Implements nsIRegion.

Definition at line 133 of file nsRegionGTK.cpp.

{
  Init();

  mRegion = gdk_region_from_rect(aX, aY, aWidth, aHeight);
}

Here is the call graph for this function:

void nsRegionGTK::Subtract ( const nsIRegion aRegion) [virtual]

destructively subtract another region with this one

Parameters:
regionto subtract
Returns:
void

Implements nsIRegion.

Definition at line 213 of file nsRegionGTK.cpp.

{
  nsRegionGTK *pRegion = (nsRegionGTK *)&aRegion;
  if (pRegion->mRegion) {
    if (mRegion) {
      GdkRegion *nRegion = ::gdk_regions_subtract(mRegion, pRegion->mRegion);
      ::gdk_region_destroy(mRegion);
      mRegion = nRegion;
    } else {
      mRegion = ::gdk_regions_subtract(GetCopyRegion(), pRegion->mRegion);
    }
  }
}
void nsRegionGTK::Subtract ( PRInt32  aX,
PRInt32  aY,
PRInt32  aWidth,
PRInt32  aHeight 
) [virtual]

destructively subtract a rect from this region

Parameters:
aXxoffset of rect to subtract with region
aYyoffset of rect to subtract with region
aWidthwidth of rect to subtract with region
aHeightheight of rect to subtract with region
Returns:
void

Implements nsIRegion.

Definition at line 227 of file nsRegionGTK.cpp.

{
  if (mRegion) {
    GdkRegion *tRegion = gdk_region_from_rect(aX, aY, aWidth, aHeight);
    
    GdkRegion *nRegion = ::gdk_regions_subtract(mRegion, tRegion);
    ::gdk_region_destroy(mRegion);
    ::gdk_region_destroy(tRegion);
    mRegion = nRegion;
  } else {
    GdkRegion *tRegion = gdk_region_from_rect(aX, aY, aWidth, aHeight);
    mRegion = ::gdk_regions_subtract(GetCopyRegion(), tRegion);
    ::gdk_region_destroy(tRegion);
  }
}
void nsRegionGTK::Union ( const nsIRegion aRegion) [virtual]

destructively union another region with this one

Parameters:
regionto union
Returns:
void

Implements nsIRegion.

Definition at line 169 of file nsRegionGTK.cpp.

{
  nsRegionGTK *pRegion = (nsRegionGTK *)&aRegion;

  if (pRegion->mRegion && !::gdk_region_empty(pRegion->mRegion)) {
    if (mRegion) {
      if (::gdk_region_empty(mRegion)) {
        ::gdk_region_destroy(mRegion);
        mRegion = gdk_region_copy(pRegion->mRegion);
      } else {
        GdkRegion *nRegion = ::gdk_regions_union(mRegion, pRegion->mRegion);
        ::gdk_region_destroy(mRegion);
        mRegion = nRegion;
      }
    } else
      mRegion = gdk_region_copy(pRegion->mRegion);
  }
}
void nsRegionGTK::Union ( PRInt32  aX,
PRInt32  aY,
PRInt32  aWidth,
PRInt32  aHeight 
) [virtual]

destructively union a rect with this region

Parameters:
aXxoffset of rect to union with region
aYyoffset of rect to union with region
aWidthwidth of rect to union with region
aHeightheight of rect to union with region
Returns:
void

Implements nsIRegion.

Definition at line 188 of file nsRegionGTK.cpp.

{
  if (mRegion) {
    GdkRectangle grect;

    grect.x = aX;
    grect.y = aY;
    grect.width = aWidth;
    grect.height = aHeight;

    if (grect.width > 0 && grect.height > 0) {
      if (::gdk_region_empty(mRegion)) {
        ::gdk_region_destroy(mRegion);
        mRegion = gdk_region_from_rect(aX, aY, aWidth, aHeight);
      } else {
        GdkRegion *nRegion = ::gdk_region_union_with_rect(mRegion, &grect);
        ::gdk_region_destroy(mRegion);
        mRegion = nRegion;
      }
    }
  } else {
    mRegion = gdk_region_from_rect(aX, aY, aWidth, aHeight);
  }
}

Member Data Documentation

GdkRegion* nsRegionGTK::mRegion [private]

Definition at line 93 of file nsRegionGTK.h.


The documentation for this class was generated from the following files: