/////////////////////////////////////////////////////////////////////////////
-// Name: generic/region.cpp
+// Name: src/generic/region.cpp
// Purpose: generic wxRegion class
// Author: David Elliott
// Modified by:
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#include "wx/generic/region.h"
-#include "wx/utils.h"
+
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+ #pragma hdrstop
+#endif
+
+#include "wx/region.h"
+
+#ifndef WX_PRECOMP
+ #include "wx/utils.h"
+#endif
// ========================================================================
// Classes to interface with X.org code
public:
// Default constructor initializes nothing
REGION() {}
+
REGION(const wxRect& rect)
{
rects = &extents;
extents.y2 = rect.y + rect.height;
size = 1;
}
- BoxPtr GetBox(int i) { if(i<numRects) return rects+i; else return NULL; }
+
+ BoxPtr GetBox(int i)
+ {
+ return i < numRects ? rects + i : NULL;
+ }
// X.org methods
static bool XClipBox(
// ========================================================================
// wxRegionRefData
// ========================================================================
-class wxRegionRefData : public wxObjectRefData, public REGION
+
+class wxRegionRefData : public wxObjectRefData,
+ public REGION
{
public:
wxRegionRefData()
- /* XCreateRegion */
- { size = 1;
+ : wxObjectRefData(),
+ REGION()
+ {
+ size = 1;
numRects = 0;
rects = ( BOX * )malloc( (unsigned) sizeof( BOX ));
extents.x1 = 0;
extents.y1 = 0;
extents.y2 = 0;
}
+
wxRegionRefData(const wxPoint& topLeft, const wxPoint& bottomRight)
- : wxObjectRefData()
- , REGION()
- { rects = (BOX*)malloc(sizeof(BOX));
+ : wxObjectRefData(),
+ REGION()
+ {
+ rects = (BOX*)malloc(sizeof(BOX));
size = 1;
numRects = 1;
extents.x1 = topLeft.x;
extents.y2 = bottomRight.y;
*rects = extents;
}
+
wxRegionRefData(const wxRect& rect)
- : wxObjectRefData()
- , REGION(rect)
- { rects = (BOX*)malloc(sizeof(BOX));
+ : wxObjectRefData(),
+ REGION(rect)
+ {
+ rects = (BOX*)malloc(sizeof(BOX));
*rects = extents;
}
+
wxRegionRefData(const wxRegionRefData& refData)
- : wxObjectRefData()
- , REGION()
+ : wxObjectRefData(),
+ REGION()
{
size = refData.size;
numRects = refData.numRects;
rects = (Box*)malloc(numRects*sizeof(Box));
+ memcpy(rects, refData.rects, numRects*sizeof(Box));
extents = refData.extents;
}
- ~wxRegionRefData()
+
+ virtual ~wxRegionRefData()
{
free(rects);
}
+
private:
// Don't allow this
wxRegionRefData(const REGION&);
// ========================================================================
// wxRegionGeneric
// ========================================================================
-//IMPLEMENT_DYNAMIC_CLASS(wxRegionGeneric, wxGDIObject);
+//IMPLEMENT_DYNAMIC_CLASS(wxRegionGeneric, wxGDIObject)
#define M_REGIONDATA ((wxRegionRefData *)m_refData)
#define M_REGIONDATA_OF(rgn) ((wxRegionRefData *)(rgn.m_refData))
return new wxRegionRefData(*(wxRegionRefData *)data);
}
-bool wxRegionGeneric::operator== (const wxRegionGeneric& region)
+bool wxRegionGeneric::operator== (const wxRegionGeneric& region) const
{
wxASSERT(m_refData && region.m_refData);
return REGION::XEqualRegion(M_REGIONDATA,M_REGIONDATA_OF(region));
// ========================================================================
// wxRegionIteratorGeneric
// ========================================================================
-//IMPLEMENT_DYNAMIC_CLASS(wxRegionIteratorGeneric,wxObject);
+//IMPLEMENT_DYNAMIC_CLASS(wxRegionIteratorGeneric,wxObject)
wxRegionIteratorGeneric::wxRegionIteratorGeneric()
{
*/
/* Create a new empty region */
-Region REGION::
-XCreateRegion(void)
+Region REGION::XCreateRegion(void)
{
- Region temp;
+ Region temp = new REGION;
- if (! (temp = new REGION))
+ if (!temp)
return (Region) NULL;
- if (! (temp->rects = ( BOX * )malloc( (unsigned) sizeof( BOX )))) {
+
+ temp->rects = ( BOX * )malloc( (unsigned) sizeof( BOX ));
+
+ if (!temp->rects)
+ {
free((char *) temp);
return (Region) NULL;
}
return( temp );
}
-bool REGION::
-XClipBox(
- Region r,
- wxRect *rect)
+bool REGION::XClipBox(Region r, wxRect *rect)
{
rect->x = r->extents.x1;
rect->y = r->extents.y1;
{
BOX *prevRects = dstrgn->rects;
- if (! (dstrgn->rects = (BOX *)
+ dstrgn->rects = (BOX *)
realloc((char *) dstrgn->rects,
- (unsigned) rgn->numRects * (sizeof(BOX)))))
+ (unsigned) rgn->numRects * (sizeof(BOX)));
+ if (!dstrgn->rects)
{
free(prevRects);
return;
*/
newReg->size = wxMax(reg1->numRects,reg2->numRects) * 2;
- if (! (newReg->rects = (BoxPtr)
- malloc ((unsigned) (sizeof(BoxRec) * newReg->size)))) {
+ newReg->rects = (BoxPtr)malloc((unsigned) (sizeof(BoxRec) * newReg->size));
+
+ if (!newReg->rects)
+ {
newReg->size = 0;
return;
}
*-----------------------------------------------------------------------
*/
-bool REGION::
-XSubtractRegion(
- Region regM,
- Region regS,
- register Region regD)
+bool REGION::XSubtractRegion(Region regM, Region regS, register Region regD)
{
/* check for trivial reject */
if ( (!(regM->numRects)) || (!(regS->numRects)) ||
return true;
}
-bool REGION::
-XXorRegion(Region sra, Region srb, Region dr)
+bool REGION::XXorRegion(Region sra, Region srb, Region dr)
{
- Region tra, trb;
+ Region tra = XCreateRegion();
+
+ wxCHECK_MSG( tra, false, wxT("region not created") );
+
+ Region trb = XCreateRegion();
+
+ wxCHECK_MSG( trb, false, wxT("region not created") );
- if ((! (tra = XCreateRegion())) || (! (trb = XCreateRegion())))
- return 0;
(void) XSubtractRegion(sra,srb,tra);
(void) XSubtractRegion(srb,sra,trb);
(void) XUnionRegion(tra,trb,dr);
* Check to see if the region is empty. Assumes a region is passed
* as a parameter
*/
-bool REGION::
-XEmptyRegion(
- Region r)
+bool REGION::XEmptyRegion(Region r)
{
if( r->numRects == 0 ) return true;
else return false;
/*
* Check to see if two regions are equal
*/
-bool REGION::
-XEqualRegion(Region r1, Region r2)
+bool REGION::XEqualRegion(Region r1, Region r2)
{
int i;
return true;
}
-bool REGION::
-XPointInRegion(
- Region pRegion,
- int x, int y)
+bool REGION::XPointInRegion(Region pRegion, int x, int y)
{
int i;
return false;
}
-wxRegionContain REGION::
-XRectInRegion(
- register Region region,
- int rx, int ry,
- unsigned int rwidth, unsigned int rheight)
+wxRegionContain REGION::XRectInRegion(register Region region,
+ int rx, int ry,
+ unsigned int rwidth,
+ unsigned int rheight)
{
register BoxPtr pbox;
register BoxPtr pboxEnd;
return(partIn ? ((ry < prect->y2) ? wxPartRegion : wxInRegion) :
wxOutRegion);
}
-