X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f7bd3a7d8f16e7056dc41dbf5e3350cd249adee3..5b2f31eb30be576374064413b9d0f63a1bf8c110:/src/msw/region.cpp diff --git a/src/msw/region.cpp b/src/msw/region.cpp index cb214071d0..ec84dd0205 100644 --- a/src/msw/region.cpp +++ b/src/msw/region.cpp @@ -26,8 +26,8 @@ #include "wx/window.h" #include "wx/msw/private.h" - IMPLEMENT_DYNAMIC_CLASS(wxRegion, wxGDIObject) - IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator, wxObject) +IMPLEMENT_DYNAMIC_CLASS(wxRegion, wxGDIObject) +IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator, wxObject) //----------------------------------------------------------------------------- // wxRegionRefData implementation @@ -43,7 +43,7 @@ public: wxRegionRefData(const wxRegionRefData& data) { -#if defined(__WIN32__) +#if defined(__WIN32__) && !defined(__WXMICROWIN__) DWORD noBytes = ::GetRegionData(data.m_region, 0, NULL); RGNDATA *rgnData = (RGNDATA*) new char[noBytes]; ::GetRegionData(data.m_region, noBytes, rgnData); @@ -103,14 +103,37 @@ wxRegion::wxRegion(const wxRect& rect) M_REGION = ::CreateRectRgn(rect.x, rect.y, rect.x + rect.width, rect.y + rect.height); } -/* - * Destroy the region. - */ +wxRegion::wxRegion(size_t n, const wxPoint *points, int fillStyle) +{ +#ifdef __WXMICROWIN__ + m_refData = NULL; + M_REGION = NULL; +#else + m_refData = new wxRegionRefData; + M_REGION = ::CreatePolygonRgn + ( + (POINT*)points, + n, + fillStyle == wxODDEVEN_RULE ? ALTERNATE : WINDING + ); +#endif +} + wxRegion::~wxRegion() { // m_refData unrefed in ~wxObject } +wxObjectRefData *wxRegion::CreateRefData() const +{ + return new wxRegionRefData; +} + +wxObjectRefData *wxRegion::CloneRefData(const wxObjectRefData *data) const +{ + return new wxRegionRefData(*(wxRegionRefData *)data); +} + //----------------------------------------------------------------------------- // Modify region //----------------------------------------------------------------------------- @@ -121,18 +144,30 @@ void wxRegion::Clear() UnRef(); } +bool wxRegion::Offset(wxCoord x, wxCoord y) +{ + if ( !x && !y ) + { + // nothing to do + return TRUE; + } + + AllocExclusive(); + + if ( ::OffsetRgn(GetHrgn(), x, y) == ERROR ) + { + wxLogLastError(_T("OffsetRgn")); + + return FALSE; + } + + return TRUE; +} + // Combine rectangle (x, y, w, h) with this. bool wxRegion::Combine(wxCoord x, wxCoord y, wxCoord width, wxCoord height, wxRegionOp op) { - // Don't change shared data - if (!m_refData) { - m_refData = new wxRegionRefData(); - } else if (m_refData->GetRefCount() > 1) { - wxRegionRefData* ref = (wxRegionRefData*)m_refData; - UnRef(); - m_refData = new wxRegionRefData(*ref); - } - // If ref count is 1, that means it's 'ours' anyway so no action. + AllocExclusive(); HRGN rectRegion = ::CreateRectRgn(x, y, x + width, y + height); @@ -148,7 +183,11 @@ bool wxRegion::Combine(wxCoord x, wxCoord y, wxCoord width, wxCoord height, wxRe mode = RGN_COPY; break ; } - bool success = (ERROR != ::CombineRgn(M_REGION, M_REGION, rectRegion, mode)); + bool success = ::CombineRgn(M_REGION, M_REGION, rectRegion, mode) != ERROR; + if ( !success ) + { + wxLogLastError(_T("CombineRgn")); + } ::DeleteObject(rectRegion); @@ -161,14 +200,7 @@ bool wxRegion::Combine(const wxRegion& region, wxRegionOp op) if (region.Empty()) return FALSE; - // Don't change shared data - if (!m_refData) { - m_refData = new wxRegionRefData(); - } else if (m_refData->GetRefCount() > 1) { - wxRegionRefData* ref = (wxRegionRefData*)m_refData; - UnRef(); - m_refData = new wxRegionRefData(*ref); - } + AllocExclusive(); int mode = 0; switch (op) @@ -197,14 +229,17 @@ bool wxRegion::Combine(const wxRect& rect, wxRegionOp op) // Outer bounds of region void wxRegion::GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const { - if (m_refData) { + if (m_refData) + { RECT rect; ::GetRgnBox(M_REGION, & rect); x = rect.left; y = rect.top; w = rect.right - rect.left; h = rect.bottom - rect.top; - } else { + } + else + { x = y = w = h = 0; } } @@ -219,12 +254,10 @@ wxRect wxRegion::GetBox() const // Is region empty? bool wxRegion::Empty() const { - if (M_REGION == 0) - return TRUE; wxCoord x, y, w, h; GetBox(x, y, w, h); - return ((w == 0) && (h == 0)); + return (w == 0) && (h == 0); } //-----------------------------------------------------------------------------