From 6dcbb6d0d98b4b85ba1ba66cec336ea5ead333b7 Mon Sep 17 00:00:00 2001 From: Gilles Depeyrot Date: Wed, 15 May 2002 06:22:01 +0000 Subject: [PATCH] applied copy constructor fix to assignment operator as well git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15569 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/mac/region.h | 6 +++-- src/mac/carbon/region.cpp | 56 ++++++++++++++++++++++++--------------- src/mac/region.cpp | 56 ++++++++++++++++++++++++--------------- 3 files changed, 74 insertions(+), 44 deletions(-) diff --git a/include/wx/mac/region.h b/include/wx/mac/region.h index ee40f921f7..d9fc31f073 100644 --- a/include/wx/mac/region.h +++ b/include/wx/mac/region.h @@ -128,13 +128,13 @@ public: ~wxRegionIterator(); wxRegionIterator& operator=(const wxRegionIterator& iterator); - + void Reset() { m_current = 0; } void Reset(const wxRegion& region); operator bool () const { return m_current < m_numRects; } bool HaveRects() const { return m_current < m_numRects; } - + wxRegionIterator& operator++(); wxRegionIterator operator++(int); @@ -146,6 +146,8 @@ public: long GetHeight() const { return GetH(); } wxRect GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); } private: + void SetRects(long numRects, wxRect *rects); + long m_current; long m_numRects; wxRegion m_region; diff --git a/src/mac/carbon/region.cpp b/src/mac/carbon/region.cpp index c8ffc4632b..b4dddad04b 100644 --- a/src/mac/carbon/region.cpp +++ b/src/mac/carbon/region.cpp @@ -302,33 +302,47 @@ wxRegionIterator::wxRegionIterator() wxRegionIterator::~wxRegionIterator() { - if (m_rects) + if (m_rects) { delete[] m_rects; + m_rects = NULL; + } } wxRegionIterator::wxRegionIterator(const wxRegionIterator& iterator) : wxObject() , m_current(iterator.m_current) - , m_numRects(iterator.m_numRects) + , m_numRects(0) , m_rects(NULL) { - int i; - if (iterator.m_rects) - { - m_rects = new wxRect[iterator.m_numRects]; - for (i = 0; i < iterator.m_numRects; i++) - m_rects[i] = iterator.m_rects[i]; - } + SetRects(iterator.m_numRects, iterator.m_rects); } wxRegionIterator& wxRegionIterator::operator=(const wxRegionIterator& iterator) { m_current = iterator.m_current; - m_numRects = iterator.m_numRects; - m_rects = iterator.m_rects; + SetRects(iterator.m_numRects, iterator.m_rects); return *this; } +/*! + * Set iterator rects for region + */ +void wxRegionIterator::SetRects(long numRects, wxRect *rects) +{ + if (m_rects) { + delete[] m_rects; + m_rects = NULL; + } + if (rects) + { + int i; + m_rects = new wxRect[numRects]; + for (i = 0; i < numRects; i++) + m_rects[i] = rects[i]; + } + m_numRects = numRects; +} + /*! * Initialize iterator for region */ @@ -344,22 +358,22 @@ wxRegionIterator::wxRegionIterator(const wxRegion& region) */ void wxRegionIterator::Reset(const wxRegion& region) { - m_current = 0; - m_region = region; + m_current = 0; + m_region = region; - if (m_rects) + if (m_rects) { delete[] m_rects; + m_rects = NULL; + } - m_rects = NULL; - - if (m_region.Empty()) - m_numRects = 0; - else + if (m_region.Empty()) + m_numRects = 0; + else { // we cannot dissolve it into rects on mac m_rects = new wxRect[1]; - Rect rect ; - GetRegionBounds( OTHER_M_REGION( region ) , &rect ) ; + Rect rect ; + GetRegionBounds( OTHER_M_REGION( region ) , &rect ) ; m_rects[0].x = rect.left; m_rects[0].y = rect.top; m_rects[0].width = rect.right - rect.left; diff --git a/src/mac/region.cpp b/src/mac/region.cpp index c8ffc4632b..b4dddad04b 100644 --- a/src/mac/region.cpp +++ b/src/mac/region.cpp @@ -302,33 +302,47 @@ wxRegionIterator::wxRegionIterator() wxRegionIterator::~wxRegionIterator() { - if (m_rects) + if (m_rects) { delete[] m_rects; + m_rects = NULL; + } } wxRegionIterator::wxRegionIterator(const wxRegionIterator& iterator) : wxObject() , m_current(iterator.m_current) - , m_numRects(iterator.m_numRects) + , m_numRects(0) , m_rects(NULL) { - int i; - if (iterator.m_rects) - { - m_rects = new wxRect[iterator.m_numRects]; - for (i = 0; i < iterator.m_numRects; i++) - m_rects[i] = iterator.m_rects[i]; - } + SetRects(iterator.m_numRects, iterator.m_rects); } wxRegionIterator& wxRegionIterator::operator=(const wxRegionIterator& iterator) { m_current = iterator.m_current; - m_numRects = iterator.m_numRects; - m_rects = iterator.m_rects; + SetRects(iterator.m_numRects, iterator.m_rects); return *this; } +/*! + * Set iterator rects for region + */ +void wxRegionIterator::SetRects(long numRects, wxRect *rects) +{ + if (m_rects) { + delete[] m_rects; + m_rects = NULL; + } + if (rects) + { + int i; + m_rects = new wxRect[numRects]; + for (i = 0; i < numRects; i++) + m_rects[i] = rects[i]; + } + m_numRects = numRects; +} + /*! * Initialize iterator for region */ @@ -344,22 +358,22 @@ wxRegionIterator::wxRegionIterator(const wxRegion& region) */ void wxRegionIterator::Reset(const wxRegion& region) { - m_current = 0; - m_region = region; + m_current = 0; + m_region = region; - if (m_rects) + if (m_rects) { delete[] m_rects; + m_rects = NULL; + } - m_rects = NULL; - - if (m_region.Empty()) - m_numRects = 0; - else + if (m_region.Empty()) + m_numRects = 0; + else { // we cannot dissolve it into rects on mac m_rects = new wxRect[1]; - Rect rect ; - GetRegionBounds( OTHER_M_REGION( region ) , &rect ) ; + Rect rect ; + GetRegionBounds( OTHER_M_REGION( region ) , &rect ) ; m_rects[0].x = rect.left; m_rects[0].y = rect.top; m_rects[0].width = rect.right - rect.left; -- 2.45.2