X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/44bf7fe3d043bfd096ee2218712154b5ab992504..6ba718d7aee2f519d9146b90424ccec9e2243479:/src/generic/regiong.cpp diff --git a/src/generic/regiong.cpp b/src/generic/regiong.cpp index 218f5a324c..7580c44432 100644 --- a/src/generic/regiong.cpp +++ b/src/generic/regiong.cpp @@ -1,16 +1,26 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: generic/region.cpp +// Name: src/generic/regiong.cpp // Purpose: generic wxRegion class // Author: David Elliott // Modified by: // Created: 2004/04/12 -// RCS-ID: $Id$ // Copyright: (c) 2004 David Elliott // 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 @@ -165,12 +175,12 @@ protected: // wxRegionRefData // ======================================================================== -class wxRegionRefData : public wxObjectRefData, +class wxRegionRefData : public wxGDIRefData, public REGION { public: wxRegionRefData() - : wxObjectRefData(), + : wxGDIRefData(), REGION() { size = 1; @@ -183,7 +193,7 @@ public: } wxRegionRefData(const wxPoint& topLeft, const wxPoint& bottomRight) - : wxObjectRefData(), + : wxGDIRefData(), REGION() { rects = (BOX*)malloc(sizeof(BOX)); @@ -197,7 +207,7 @@ public: } wxRegionRefData(const wxRect& rect) - : wxObjectRefData(), + : wxGDIRefData(), REGION(rect) { rects = (BOX*)malloc(sizeof(BOX)); @@ -205,7 +215,7 @@ public: } wxRegionRefData(const wxRegionRefData& refData) - : wxObjectRefData(), + : wxGDIRefData(), REGION() { size = refData.size; @@ -215,7 +225,7 @@ public: extents = refData.extents; } - ~wxRegionRefData() + virtual ~wxRegionRefData() { free(rects); } @@ -228,7 +238,7 @@ private: // ======================================================================== // 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)) @@ -260,115 +270,104 @@ wxRegionGeneric::wxRegionGeneric(const wxPoint& topLeft, const wxPoint& bottomRi m_refData = new wxRegionRefData(topLeft, bottomRight); } +wxRegionGeneric::wxRegionGeneric(const wxBitmap& bmp) +{ + wxFAIL_MSG("NOT IMPLEMENTED: wxRegionGeneric::wxRegionGeneric(const wxBitmap& bmp)"); +} + +wxRegionGeneric::wxRegionGeneric(size_t n, const wxPoint *points, wxPolygonFillMode fillStyle) +{ + wxFAIL_MSG("NOT IMPLEMENTED: wxRegionGeneric::wxRegionGeneric(size_t n, const wxPoint *points, wxPolygonFillMode fillStyle)"); +} + +wxRegionGeneric::wxRegionGeneric(const wxBitmap& bmp, const wxColour& transp, int tolerance) +{ + wxFAIL_MSG("NOT IMPLEMENTED: wxRegionGeneric::wxRegionGeneric(const wxBitmap& bmp, const wxColour& transp, int tolerance)"); +} + void wxRegionGeneric::Clear() { UnRef(); + if (!m_refData) + m_refData = new wxRegionRefData(wxRect(0,0,0,0)); } -wxObjectRefData *wxRegionGeneric::CreateRefData() const +wxGDIRefData *wxRegionGeneric::CreateGDIRefData() const { return new wxRegionRefData; } -wxObjectRefData *wxRegionGeneric::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxRegionGeneric::CloneGDIRefData(const wxGDIRefData *data) const { return new wxRegionRefData(*(wxRegionRefData *)data); } -bool wxRegionGeneric::operator== (const wxRegionGeneric& region) +bool wxRegionGeneric::DoIsEqual(const wxRegion& region) const { - wxASSERT(m_refData && region.m_refData); return REGION::XEqualRegion(M_REGIONDATA,M_REGIONDATA_OF(region)); } -wxRect wxRegionGeneric::GetBox() const +bool wxRegionGeneric::DoGetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const { - wxASSERT(m_refData); - wxRect rect; - REGION::XClipBox(M_REGIONDATA,&rect); - return rect; -} + if ( !m_refData ) + return false; -void wxRegionGeneric::GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const -{ - wxASSERT(m_refData); wxRect rect; REGION::XClipBox(M_REGIONDATA,&rect); x = rect.x; y = rect.y; w = rect.width; h = rect.height; + return true; } // ---------------------------------------------------------------------------- // wxRegionGeneric operations // ---------------------------------------------------------------------------- -bool wxRegionGeneric::Union(const wxRect& rect) -/* XUnionRectWithRegion */ +bool wxRegionGeneric::DoUnionWithRect(const wxRect& rect) { - if (!rect.width || !rect.height) - return false; + if ( rect.IsEmpty() ) + { + // nothing to do + return true; + } AllocExclusive(); REGION region(rect); return REGION::XUnionRegion(®ion,M_REGIONDATA,M_REGIONDATA); } -bool wxRegionGeneric::Union(const wxRegionGeneric& region) +bool wxRegionGeneric::DoUnionWithRegion(const wxRegion& region) { AllocExclusive(); return REGION::XUnionRegion(M_REGIONDATA_OF(region),M_REGIONDATA,M_REGIONDATA); } -bool wxRegionGeneric::Intersect(const wxRect& rect) -{ - if (!rect.width || !rect.height) - return false; - AllocExclusive(); - REGION region(rect); - - return REGION::XIntersectRegion(®ion,M_REGIONDATA,M_REGIONDATA); -} - -bool wxRegionGeneric::Intersect(const wxRegionGeneric& region) +bool wxRegionGeneric::DoIntersect(const wxRegion& region) { AllocExclusive(); return REGION::XIntersectRegion(M_REGIONDATA_OF(region),M_REGIONDATA,M_REGIONDATA); } -bool wxRegionGeneric::Subtract(const wxRect& rect) +bool wxRegionGeneric::DoSubtract(const wxRegion& region) { - if (!rect.width || !rect.height) - return false; - AllocExclusive(); - REGION region(rect); - - return REGION::XSubtractRegion(®ion,M_REGIONDATA,M_REGIONDATA); -} + if ( region.IsEmpty() ) + { + // nothing to do + return true; + } -bool wxRegionGeneric::Subtract(const wxRegionGeneric& region) -{ return REGION::XSubtractRegion(M_REGIONDATA_OF(region),M_REGIONDATA,M_REGIONDATA); } -bool wxRegionGeneric::Xor(const wxRect& rect) -{ - if (!rect.width || !rect.height) - return false; - AllocExclusive(); - REGION region(rect); - - return REGION::XXorRegion(®ion,M_REGIONDATA,M_REGIONDATA); -} - -bool wxRegionGeneric::Xor(const wxRegionGeneric& region) +bool wxRegionGeneric::DoXor(const wxRegion& region) { AllocExclusive(); return REGION::XXorRegion(M_REGIONDATA_OF(region),M_REGIONDATA,M_REGIONDATA); } -bool wxRegionGeneric::Offset(wxCoord x, wxCoord y) +bool wxRegionGeneric::DoOffset(wxCoord x, wxCoord y) { AllocExclusive(); return REGION::XOffsetRegion(M_REGIONDATA, x, y); @@ -378,35 +377,21 @@ bool wxRegionGeneric::Offset(wxCoord x, wxCoord y) // wxRegionGeneric comparison // ---------------------------------------------------------------------------- -bool wxRegionGeneric::Empty() const +bool wxRegionGeneric::IsEmpty() const { wxASSERT(m_refData); return REGION::XEmptyRegion(M_REGIONDATA); } // Does the region contain the point (x,y)? -wxRegionContain wxRegionGeneric::Contains(long x, long y) const -{ - wxASSERT(m_refData); - return REGION::XPointInRegion(M_REGIONDATA,x,y)?wxInRegion:wxOutRegion; -} - -// Does the region contain the point pt? -wxRegionContain wxRegionGeneric::Contains(const wxPoint& pt) const -{ - wxASSERT(m_refData); - return REGION::XPointInRegion(M_REGIONDATA,pt.x,pt.y)?wxInRegion:wxOutRegion; -} - -// Does the region contain the rectangle (x, y, w, h)? -wxRegionContain wxRegionGeneric::Contains(long x, long y, long w, long h) const +wxRegionContain wxRegionGeneric::DoContainsPoint(wxCoord x, wxCoord y) const { wxASSERT(m_refData); - return REGION::XRectInRegion(M_REGIONDATA,x,y,w,h); + return REGION::XPointInRegion(M_REGIONDATA,x,y) ? wxInRegion : wxOutRegion; } // Does the region contain the rectangle rect? -wxRegionContain wxRegionGeneric::Contains(const wxRect& rect) const +wxRegionContain wxRegionGeneric::DoContainsRect(const wxRect& rect) const { wxASSERT(m_refData); return REGION::XRectInRegion(M_REGIONDATA,rect.x,rect.y,rect.width,rect.height); @@ -415,7 +400,7 @@ wxRegionContain wxRegionGeneric::Contains(const wxRect& rect) const // ======================================================================== // wxRegionIteratorGeneric // ======================================================================== -//IMPLEMENT_DYNAMIC_CLASS(wxRegionIteratorGeneric,wxObject); +//IMPLEMENT_DYNAMIC_CLASS(wxRegionIteratorGeneric,wxObject) wxRegionIteratorGeneric::wxRegionIteratorGeneric() { @@ -620,15 +605,18 @@ SOFTWARE. */ /* 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 )))) { - free((char *) temp); + + temp->rects = ( BOX * )malloc( (unsigned) sizeof( BOX )); + + if (!temp->rects) + { + delete temp; return (Region) NULL; } temp->numRects = 0; @@ -640,10 +628,7 @@ XCreateRegion(void) 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; @@ -699,7 +684,7 @@ miSetExtents (Region pReg) pExtents->x2 = pBoxEnd->x2; pExtents->y2 = pBoxEnd->y2; - assert(pExtents->y1 < pExtents->y2); + wxASSERT_LEVEL_2(pExtents->y1 < pExtents->y2); while (pBox <= pBoxEnd) { if (pBox->x1 < pExtents->x1) @@ -712,7 +697,7 @@ miSetExtents (Region pReg) } pBox++; } - assert(pExtents->x1 < pExtents->x2); + wxASSERT_LEVEL_2(pExtents->x1 < pExtents->x2); } bool REGION:: @@ -803,7 +788,7 @@ miIntersectO ( */ if (x1 < x2) { - assert(y1rects); pNextRect->x1 = x1; @@ -812,7 +797,7 @@ miIntersectO ( pNextRect->y2 = y2; pReg->numRects += 1; pNextRect++; - assert(pReg->numRects <= pReg->size); + wxASSERT_LEVEL_2(pReg->numRects <= pReg->size); } /* @@ -876,9 +861,10 @@ miRegionCopy( { 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; @@ -1145,8 +1131,10 @@ miRegionOp( */ 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; } @@ -1390,11 +1378,11 @@ miUnionNonO ( pNextRect = &pReg->rects[pReg->numRects]; - assert(y1 < y2); + wxASSERT_LEVEL_2(y1 < y2); while (r != rEnd) { - assert(r->x1 < r->x2); + wxASSERT_LEVEL_2(r->x1 < r->x2); MEMCHECK(pReg, pNextRect, pReg->rects); pNextRect->x1 = r->x1; pNextRect->y1 = y1; @@ -1403,7 +1391,7 @@ miUnionNonO ( pReg->numRects += 1; pNextRect++; - assert(pReg->numRects<=pReg->size); + wxASSERT_LEVEL_2(pReg->numRects<=pReg->size); r++; } return 0; /* lint */ @@ -1450,7 +1438,7 @@ miUnionO ( if (pNextRect[-1].x2 < r->x2) \ { \ pNextRect[-1].x2 = r->x2; \ - assert(pNextRect[-1].x1numRects += 1; \ pNextRect += 1; \ } \ - assert(pReg->numRects<=pReg->size);\ + wxASSERT_LEVEL_2(pReg->numRects<=pReg->size);\ r++; - assert (y1x1 < r2->x1) @@ -1591,11 +1579,11 @@ miSubtractNonO1 ( pNextRect = &pReg->rects[pReg->numRects]; - assert(y1x1x2); + wxASSERT_LEVEL_2(r->x1x2); MEMCHECK(pReg, pNextRect, pReg->rects); pNextRect->x1 = r->x1; pNextRect->y1 = y1; @@ -1604,7 +1592,7 @@ miSubtractNonO1 ( pReg->numRects += 1; pNextRect++; - assert(pReg->numRects <= pReg->size); + wxASSERT_LEVEL_2(pReg->numRects <= pReg->size); r++; } @@ -1641,7 +1629,7 @@ miSubtractO ( x1 = r1->x1; - assert(y1rects[pReg->numRects]; while ((r1 != r1End) && (r2 != r2End)) @@ -1656,7 +1644,7 @@ miSubtractO ( else if (r2->x1 <= x1) { /* - * Subtrahend preceeds minuend: nuke left edge of minuend. + * Subtrahend precedes minuend: nuke left edge of minuend. */ x1 = r2->x2; if (x1 >= r1->x2) @@ -1684,7 +1672,7 @@ miSubtractO ( * Left part of subtrahend covers part of minuend: add uncovered * part of minuend to region and skip to next subtrahend. */ - assert(x1x1); + wxASSERT_LEVEL_2(x1x1); MEMCHECK(pReg, pNextRect, pReg->rects); pNextRect->x1 = x1; pNextRect->y1 = y1; @@ -1693,7 +1681,7 @@ miSubtractO ( pReg->numRects += 1; pNextRect++; - assert(pReg->numRects<=pReg->size); + wxASSERT_LEVEL_2(pReg->numRects<=pReg->size); x1 = r2->x2; if (x1 >= r1->x2) @@ -1727,7 +1715,7 @@ miSubtractO ( pNextRect->y2 = y2; pReg->numRects += 1; pNextRect++; - assert(pReg->numRects<=pReg->size); + wxASSERT_LEVEL_2(pReg->numRects<=pReg->size); } r1++; if (r1 != r1End) @@ -1740,7 +1728,7 @@ miSubtractO ( */ while (r1 != r1End) { - assert(x1x2); + wxASSERT_LEVEL_2(x1x2); MEMCHECK(pReg, pNextRect, pReg->rects); pNextRect->x1 = x1; pNextRect->y1 = y1; @@ -1749,7 +1737,7 @@ miSubtractO ( pReg->numRects += 1; pNextRect++; - assert(pReg->numRects<=pReg->size); + wxASSERT_LEVEL_2(pReg->numRects<=pReg->size); r1++; if (r1 != r1End) @@ -1775,11 +1763,7 @@ miSubtractO ( *----------------------------------------------------------------------- */ -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)) || @@ -1803,13 +1787,16 @@ XSubtractRegion( 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); @@ -1822,9 +1809,7 @@ XXorRegion(Region sra, Region srb, Region 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; @@ -1833,8 +1818,7 @@ XEmptyRegion( /* * Check to see if two regions are equal */ -bool REGION:: -XEqualRegion(Region r1, Region r2) +bool REGION::XEqualRegion(Region r1, Region r2) { int i; @@ -1853,10 +1837,7 @@ XEqualRegion(Region r1, Region r2) return true; } -bool REGION:: -XPointInRegion( - Region pRegion, - int x, int y) +bool REGION::XPointInRegion(Region pRegion, int x, int y) { int i; @@ -1872,11 +1853,10 @@ XPointInRegion( 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; @@ -1953,4 +1933,3 @@ XRectInRegion( return(partIn ? ((ry < prect->y2) ? wxPartRegion : wxInRegion) : wxOutRegion); } -