Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
nsRegionXlib Class Reference

#include <nsRegionXlib.h>

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

List of all members.

Public Member Functions

 nsRegionXlib ()
virtual ~nsRegionXlib ()
NS_DECL_ISUPPORTS nsresult Init ()
void SetTo (const nsIRegion &aRegion)
 copy operator equivalent that takes another region
void SetTo (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 copy operator equivalent that takes a rect
void Intersect (const nsIRegion &aRegion)
 destructively intersect another region with this one
void Intersect (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 destructively intersect a rect with this region
void Union (const nsIRegion &aRegion)
 destructively union another region with this one
void Union (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 destructively union a rect with this region
void Subtract (const nsIRegion &aRegion)
 destructively subtract another region with this one
void Subtract (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
 destructively subtract a rect from this region
PRBool IsEmpty (void)
 is this region empty? i.e.
PRBool IsEqual (const nsIRegion &aRegion)
 == operator equivalent i.e.
void GetBoundingBox (PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight)
 returns the bounding box of the region i.e.
void Offset (PRInt32 aXOffset, PRInt32 aYOffset)
 offsets the region in x and y
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.

Protected Member Functions

Region xlib_region_copy (Region region)
Region xlib_region_from_rect (PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)

Private Member Functions

Region GetCopyRegion ()
void SetRegionEmpty ()

Private Attributes

Region mRegion

Static Private Attributes

static Region copyRegion = 0

Detailed Description

Definition at line 47 of file nsRegionXlib.h.


Constructor & Destructor Documentation

Definition at line 52 of file nsRegionXlib.cpp.

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

  mRegion = nsnull;
}

Definition at line 62 of file nsRegionXlib.cpp.

{
#ifdef DEBUG_REGIONS
  --nRegions;
  printf("REGIONS- = %i\n", nRegions);
#endif
  
  if (mRegion)
    ::XDestroyRegion(mRegion);
  mRegion = nsnull;
}

Member Function Documentation

PRBool nsRegionXlib::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 315 of file nsRegionXlib.cpp.

{
  return (::XRectInRegion(mRegion, aX, aY, aWidth, aHeight) == RectangleIn) ?
    PR_TRUE : PR_FALSE;
}

Free a rect set returned by GetRects.

Parameters:
aRectsrects to free
Returns:
error status

Implements nsIRegion.

Definition at line 381 of file nsRegionXlib.cpp.

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

  return NS_OK;
}
void nsRegionXlib::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 286 of file nsRegionXlib.cpp.

{
  if (mRegion) {
    XRectangle r;

    ::XClipBox(mRegion, &r);

    *aX = r.x;
    *aY = r.y;
    *aWidth = r.width;
    *aHeight = r.height;
  } else {
    *aX = 0;
    *aY = 0;
    *aWidth = 0;
    *aHeight = 0;
  }
}
Region nsRegionXlib::GetCopyRegion ( ) [inline, private]

Definition at line 77 of file nsRegionXlib.cpp.

{
  if (!copyRegion)
    copyRegion = ::XCreateRegion();
  return copyRegion;
}

Here is the caller graph for this function:

NS_IMETHODIMP nsRegionXlib::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 390 of file nsRegionXlib.cpp.

{
  aRegion = (void *)mRegion;
  return NS_OK;
}
NS_IMETHODIMP nsRegionXlib::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 416 of file nsRegionXlib.cpp.

{
  if (!mRegion)
    *aRects = 0;

  *aRects = mRegion->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 323 of file nsRegionXlib.cpp.

{
  *aRects = nsnull;

  if (!mRegion)
    return NS_OK;

  nsRegionRectSet   *rects;
  int               nbox;
  BOX               *pbox;
  nsRegionRect      *rect;

  NS_ASSERTION(!(nsnull == aRects), "bad ptr");
 
  //code lifted from old xfe. MMP

  pbox = mRegion->rects;
  nbox = mRegion->numRects;
 
  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:

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 397 of file nsRegionXlib.cpp.

{
  // cast to avoid const-ness problems on some compilers
  if (((nsRegionXlib*)this)->IsEmpty())
    aComplexity = eRegionComplexity_empty;
  else 
    aComplexity = eRegionComplexity_rect;
      
  return NS_OK;
}

Here is the call graph for this function:

nsresult nsRegionXlib::Init ( void  ) [virtual]

Implements nsIRegion.

Definition at line 113 of file nsRegionXlib.cpp.

{
  if (mRegion) {
    ::XDestroyRegion(mRegion);
    mRegion = nsnull;
  }

  return NS_OK;
}

Here is the caller graph for this function:

void nsRegionXlib::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 nsRegionXlib.cpp.

{
  nsRegionXlib * pRegion = (nsRegionXlib *)&aRegion;
  
  Region nRegion = XCreateRegion();
  ::XIntersectRegion(mRegion, pRegion->mRegion, nRegion);
  ::XDestroyRegion(mRegion);
  mRegion = nRegion;
}
void nsRegionXlib::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 151 of file nsRegionXlib.cpp.

{
  Region tRegion = xlib_region_from_rect(aX, aY, aWidth, aHeight);
  
  Region nRegion = XCreateRegion();

  ::XIntersectRegion(mRegion, tRegion, nRegion);
  ::XDestroyRegion(tRegion);
  ::XDestroyRegion(mRegion);
  mRegion = nRegion;
}

Here is the call graph for this function:

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 261 of file nsRegionXlib.cpp.

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

Here is the caller graph for this function:

PRBool nsRegionXlib::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 269 of file nsRegionXlib.cpp.

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

  if (mRegion && pRegion->mRegion) {
    return ::XEqualRegion(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 nsRegionXlib::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 307 of file nsRegionXlib.cpp.

{
  if (mRegion) {
    ::XOffsetRegion(mRegion, aXOffset, aYOffset);
  }
}
void nsRegionXlib::SetRegionEmpty ( ) [inline, private]

Definition at line 408 of file nsRegionXlib.cpp.

{
  if (!IsEmpty()) { 
    ::XDestroyRegion(mRegion);
  }
}

Here is the call graph for this function:

void nsRegionXlib::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 nsRegionXlib.cpp.

{
  Init();
  nsRegionXlib * pRegion = (nsRegionXlib *)&aRegion;

  mRegion = xlib_region_copy(pRegion->mRegion);
}

Here is the call graph for this function:

void nsRegionXlib::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 nsRegionXlib.cpp.

{
  Init();
  mRegion = xlib_region_from_rect(aX, aY, aWidth, aHeight);
}

Here is the call graph for this function:

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

destructively subtract another region with this one

Parameters:
regionto subtract
Returns:
void

Implements nsIRegion.

Definition at line 212 of file nsRegionXlib.cpp.

{
#ifdef DEBUG_REGIONS
  printf("nsRegionXlib::Subtract ");
#endif
  nsRegionXlib * pRegion = (nsRegionXlib *)&aRegion;

  if (pRegion->mRegion) {
    if (mRegion) {
#ifdef DEBUG_REGIONS
    printf("-");
#endif
      Region nRegion = ::XCreateRegion();
      ::XSubtractRegion(mRegion, pRegion->mRegion, nRegion);
      ::XDestroyRegion(mRegion);
      mRegion = nRegion;
    } else {
#ifdef DEBUG_REGIONS
    printf("+");
#endif
      mRegion = ::XCreateRegion();
      ::XSubtractRegion(GetCopyRegion(), pRegion->mRegion, mRegion);
    }
  }
#ifdef DEBUG_REGIONS
    printf("\n");
#endif
}

Here is the call graph for this function:

void nsRegionXlib::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 242 of file nsRegionXlib.cpp.

{
  if (mRegion) {
    Region tRegion = xlib_region_from_rect(aX, aY, aWidth, aHeight);

    Region nRegion = ::XCreateRegion();
    ::XSubtractRegion(mRegion, tRegion, nRegion);
    ::XDestroyRegion(mRegion);
    ::XDestroyRegion(tRegion);
    mRegion = nRegion;
  } else {
    Region tRegion = xlib_region_from_rect(aX, aY, aWidth, aHeight);
    mRegion = XCreateRegion();
    ::XSubtractRegion(GetCopyRegion(), tRegion, mRegion);
    ::XDestroyRegion(tRegion);
  }
}

Here is the call graph for this function:

void nsRegionXlib::Union ( const nsIRegion aRegion) [virtual]

destructively union another region with this one

Parameters:
regionto union
Returns:
void

Implements nsIRegion.

Definition at line 164 of file nsRegionXlib.cpp.

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

  if (pRegion->mRegion && !::XEmptyRegion(pRegion->mRegion)) {
    if (mRegion) {
      if (::XEmptyRegion(mRegion)) {
        ::XDestroyRegion(mRegion);
        mRegion = xlib_region_copy(pRegion->mRegion);
      } else {
        Region nRegion = ::XCreateRegion();
        ::XUnionRegion(mRegion, pRegion->mRegion, nRegion);
        ::XDestroyRegion(mRegion);
        mRegion = nRegion;
      }
    } else
      mRegion = xlib_region_copy(pRegion->mRegion);
  }
}

Here is the call graph for this function:

void nsRegionXlib::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 185 of file nsRegionXlib.cpp.

{
  if (mRegion) {
    XRectangle rect;
    
    rect.x = aX;
    rect.y = aY;
    rect.width = aWidth;
    rect.height = aHeight;

    if (rect.width > 0 && rect.height > 0) {
      if (::XEmptyRegion(mRegion)) {
        ::XDestroyRegion(mRegion);
        mRegion = xlib_region_from_rect(aX, aY, aWidth, aHeight);
      } else {
        Region nRegion = ::XCreateRegion();
        ::XUnionRectWithRegion(&rect, mRegion, nRegion);
        ::XDestroyRegion(mRegion);
        mRegion = nRegion;
      }
    }
  } else {
    mRegion = xlib_region_from_rect(aX, aY, aWidth, aHeight);
  }
}

Here is the call graph for this function:

Region nsRegionXlib::xlib_region_copy ( Region  region) [protected]

Definition at line 85 of file nsRegionXlib.cpp.

{
  Region nRegion;
  nRegion = XCreateRegion();

  XUnionRegion(region, GetCopyRegion(), nRegion);

  return nRegion;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Region nsRegionXlib::xlib_region_from_rect ( PRInt32  aX,
PRInt32  aY,
PRInt32  aWidth,
PRInt32  aHeight 
) [protected]

Definition at line 95 of file nsRegionXlib.cpp.

{
  XRectangle rect;
  Region nRegion;

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

  nRegion = XCreateRegion();

  XUnionRectWithRegion(&rect, GetCopyRegion(), nRegion);

  return nRegion;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Region nsRegionXlib::copyRegion = 0 [static, private]

Definition at line 82 of file nsRegionXlib.h.

Region nsRegionXlib::mRegion [private]

Definition at line 81 of file nsRegionXlib.h.


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