Back to index

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

#include <nsRegionWin.h>

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

List of all members.

Public Member Functions

 nsRegionWin ()
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.

Public Attributes

HRGN mRegion
int mRegionType

Private Member Functions

 ~nsRegionWin ()

Private Attributes

LPRGNDATA mData
PRUint32 mDataSize

Detailed Description

Definition at line 44 of file nsRegionWin.h.


Constructor & Destructor Documentation

Definition at line 41 of file nsRegionWin.cpp.

{
  mRegion = NULL;
  mRegionType = NULLREGION;
  mData = NULL;
  mDataSize = 0;
}

Definition at line 49 of file nsRegionWin.cpp.

{
  if (NULL != mRegion)
  {
    ::DeleteObject(mRegion);
    mRegion = NULL;
  }

  if (NULL != mData)
  {
    PR_Free(mData);

    mData = NULL;
    mDataSize = 0;
  }
}

Member Function Documentation

PRBool nsRegionWin::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 188 of file nsRegionWin.cpp.

{
  RECT  trect;

  trect.left = aX;
  trect.top = aY;
  trect.right = aX + aWidth;
  trect.bottom = aY + aHeight;

  return ::RectInRegion(mRegion, &trect) ? PR_TRUE : PR_FALSE;
}

Free a rect set returned by GetRects.

Parameters:
aRectsrects to free
Returns:
error status

Implements nsIRegion.

Definition at line 282 of file nsRegionWin.cpp.

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

  if (NULL != mData)
  {
    PR_Free(mData);

    mData = NULL;
    mDataSize = 0;
  }

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

{
  RECT  bounds;

  if (mRegionType != NULLREGION)
  {
    ::GetRgnBox(mRegion, &bounds);

    *aX = bounds.left;
    *aY = bounds.top;
    *aWidth = bounds.right - bounds.left;
    *aHeight = bounds.bottom - bounds.top;
  }
  else
    *aX = *aY = *aWidth = *aHeight = 0;
}
NS_IMETHODIMP nsRegionWin::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 298 of file nsRegionWin.cpp.

{
  aRegion = (void *)mRegion;
  return NS_OK;
}
NS_IMETHOD nsRegionWin::GetNumRects ( PRUint32 aRects) const [inline, 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 71 of file nsRegionWin.h.

{ *aRects = 0; 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 200 of file nsRegionWin.cpp.

{
  nsRegionRectSet *rects;
  nsRegionRect    *rect;
       LPRECT          pRects;
       DWORD           dwCount, dwResult;
       unsigned int    num_rects;

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

  rects = *aRects;

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

  // code lifted from old winfe. MMP

       /* Get the size of the region data */
       dwCount = GetRegionData(mRegion, 0, NULL);

       NS_ASSERTION(!(dwCount == 0), "bad region");

       if (dwCount == 0)
         return NS_OK;

  if (dwCount > mDataSize)
  {
    if (NULL != mData)
      PR_Free(mData);

         mData = (LPRGNDATA)PR_Malloc(dwCount);
  }

       NS_ASSERTION(!(nsnull == mData), "failed allocation");

       if (mData == NULL)
         return NS_OK;

       dwResult = GetRegionData(mRegion, dwCount, mData);

       NS_ASSERTION(!(dwResult == 0), "get data failed");

       if (dwResult == 0)
              return NS_OK;

  if ((nsnull == rects) || (rects->mRectsLen < mData->rdh.nCount))
  {
    void *buf = PR_Realloc(rects, sizeof(nsRegionRectSet) + (sizeof(nsRegionRect) * (mData->rdh.nCount - 1)));

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

      return NS_OK;
    }

    rects = (nsRegionRectSet *)buf;
    rects->mRectsLen = mData->rdh.nCount;
  }

  rects->mNumRects = mData->rdh.nCount;
  rects->mArea = 0;
  rect = &rects->mRects[0];

  for (pRects = (LPRECT)mData->Buffer, num_rects = 0; 
                 num_rects < mData->rdh.nCount; 
                 num_rects++, pRects++, rect++)
  {
              rect->x = pRects->left;
              rect->y = pRects->top;
              rect->width = pRects->right - rect->x;
              rect->height = pRects->bottom - rect->y;

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

  *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 304 of file nsRegionWin.cpp.

{
  switch (mRegionType)
  {
    case NULLREGION:
      aComplexity = eRegionComplexity_empty;
      break;

    case SIMPLEREGION:
      aComplexity = eRegionComplexity_rect;
      break;

    default:
    case COMPLEXREGION:
      aComplexity = eRegionComplexity_complex;
      break;
  }

  return NS_OK;
}
nsresult nsRegionWin::Init ( void  ) [virtual]

Implements nsIRegion.

Definition at line 68 of file nsRegionWin.cpp.

{
  if (NULL != mRegion) {
    ::SetRectRgn(mRegion, 0, 0, 0, 0);
    FreeRects(nsnull);
  }
  else {
    mRegion = ::CreateRectRgn(0, 0, 0, 0);
  }
  
  mRegionType = NULLREGION;

  return NS_OK;
}

Here is the caller graph for this function:

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

destructively intersect another region with this one

Parameters:
regionto intersect
Returns:
void

Implements nsIRegion.

Definition at line 103 of file nsRegionWin.cpp.

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

  mRegionType = ::CombineRgn(mRegion, mRegion, pRegion->mRegion, RGN_AND);
}
void nsRegionWin::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 110 of file nsRegionWin.cpp.

{
  HRGN tRegion;

  tRegion = ::CreateRectRgn(aX, aY, aX + aWidth, aY + aHeight);
  mRegionType = ::CombineRgn(mRegion, mRegion, tRegion, RGN_AND);

  ::DeleteObject(tRegion);
}
PRBool nsRegionWin::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 154 of file nsRegionWin.cpp.

{
  return (mRegionType == NULLREGION) ? PR_TRUE : PR_FALSE;
}
PRBool nsRegionWin::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 159 of file nsRegionWin.cpp.

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

  return ::EqualRgn(mRegion, pRegion->mRegion) ? PR_TRUE : PR_FALSE;
}
void nsRegionWin::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 183 of file nsRegionWin.cpp.

{
  ::OffsetRgn(mRegion, aXOffset, aYOffset);
}
void nsRegionWin::SetTo ( const nsIRegion aRegion) [virtual]

copy operator equivalent that takes another region

Parameters:
regionto copy
Returns:
void

Implements nsIRegion.

Definition at line 83 of file nsRegionWin.cpp.

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

  mRegionType = ::CombineRgn(mRegion, pRegion->mRegion, NULL, RGN_COPY);
}
void nsRegionWin::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 90 of file nsRegionWin.cpp.

{
  if (NULL != mRegion)
    ::SetRectRgn(mRegion, aX, aY, aX + aWidth, aY + aHeight);
  else
    mRegion = ::CreateRectRgn(aX, aY, aX + aWidth, aY + aHeight);

  if ((aWidth == 0) || (aHeight == 0))
    mRegionType = NULLREGION;
  else
    mRegionType = SIMPLEREGION;
}
void nsRegionWin::Subtract ( const nsIRegion aRegion) [virtual]

destructively subtract another region with this one

Parameters:
regionto subtract
Returns:
void

Implements nsIRegion.

Definition at line 137 of file nsRegionWin.cpp.

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

  mRegionType = ::CombineRgn(mRegion, mRegion, pRegion->mRegion, RGN_DIFF);
}
void nsRegionWin::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 144 of file nsRegionWin.cpp.

{
  HRGN tRegion;

  tRegion = ::CreateRectRgn(aX, aY, aX + aWidth, aY + aHeight);
  mRegionType = ::CombineRgn(mRegion, mRegion, tRegion, RGN_DIFF);

  ::DeleteObject(tRegion);
}
void nsRegionWin::Union ( const nsIRegion aRegion) [virtual]

destructively union another region with this one

Parameters:
regionto union
Returns:
void

Implements nsIRegion.

Definition at line 120 of file nsRegionWin.cpp.

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

  mRegionType = ::CombineRgn(mRegion, mRegion, pRegion->mRegion, RGN_OR);
}
void nsRegionWin::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 127 of file nsRegionWin.cpp.

{
  HRGN tRegion;

  tRegion = ::CreateRectRgn(aX, aY, aX + aWidth, aY + aHeight);
  mRegionType = ::CombineRgn(mRegion, mRegion, tRegion, RGN_OR);

  ::DeleteObject(tRegion);
}

Member Data Documentation

LPRGNDATA nsRegionWin::mData [private]

Definition at line 75 of file nsRegionWin.h.

Definition at line 76 of file nsRegionWin.h.

Definition at line 80 of file nsRegionWin.h.

Definition at line 81 of file nsRegionWin.h.


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