X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a246f95e96183bc81bf5be5e1927d9bb53094f55..0cc66b6c0b7b50bfba244e4f8e48a9b071e75ae2:/src/mgl/region.cpp diff --git a/src/mgl/region.cpp b/src/mgl/region.cpp index 2002add8b8..b7ba0b5c09 100644 --- a/src/mgl/region.cpp +++ b/src/mgl/region.cpp @@ -3,11 +3,11 @@ // Purpose: Region handling for wxWindows/MGL // Author: Vaclav Slavik // RCS-ID: $Id$ -// Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com) +// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com) // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "region.h" #endif @@ -21,6 +21,7 @@ #include "wx/region.h" #include "wx/gdicmn.h" #include "wx/thread.h" +#include "wx/module.h" #include @@ -37,18 +38,14 @@ IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator, wxObject) class WXDLLEXPORT wxRegionRefData : public wxGDIRefData { public: - wxRegionRefData() - { - } + wxRegionRefData() {} wxRegionRefData(const wxRegionRefData& data) { m_region = data.m_region; } - ~wxRegionRefData() - { - } + ~wxRegionRefData() {} MGLRegion m_region; }; @@ -60,12 +57,22 @@ public: // wxRegion //----------------------------------------------------------------------------- +wxObjectRefData *wxRegion::CreateRefData() const +{ + return new wxRegionRefData; +} + +wxObjectRefData *wxRegion::CloneRefData(const wxObjectRefData *data) const +{ + return new wxRegionRefData(*(wxRegionRefData *)data); +} + /* * Create an empty region. */ wxRegion::wxRegion() { - m_refData = (wxRegionRefData *)NULL; + m_refData = NULL; } wxRegion::wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h) @@ -156,17 +163,24 @@ bool wxRegion::Empty() const // Modifications //----------------------------------------------------------------------------- +bool wxRegion::Offset(wxCoord x, wxCoord y) +{ + AllocExclusive(); + M_REGION.offset(x, y); + return TRUE; +} + // Union rectangle or region with this. bool wxRegion::Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { - Unshare(); + AllocExclusive(); M_REGION += MGLRect(x, y, x + width, y + height); return TRUE; } bool wxRegion::Union(const wxRegion& region) { - Unshare(); + AllocExclusive(); M_REGION += M_REGION_OF(region); return TRUE; } @@ -174,14 +188,14 @@ bool wxRegion::Union(const wxRegion& region) // Intersect rectangle or region with this. bool wxRegion::Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { - Unshare(); + AllocExclusive(); M_REGION &= MGLRect(x, y, x + width, y + height); return TRUE; } bool wxRegion::Intersect(const wxRegion& region) { - Unshare(); + AllocExclusive(); M_REGION &= M_REGION_OF(region); return TRUE; } @@ -190,14 +204,14 @@ bool wxRegion::Intersect(const wxRegion& region) // Combines the parts of 'this' that are not part of the second region. bool wxRegion::Subtract(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { - Unshare(); + AllocExclusive(); M_REGION -= MGLRect(x, y, x + width, y + height); return TRUE; } bool wxRegion::Subtract(const wxRegion& region) { - Unshare(); + AllocExclusive(); M_REGION -= M_REGION_OF(region); return TRUE; } @@ -205,7 +219,7 @@ bool wxRegion::Subtract(const wxRegion& region) // XOR: the union of two combined regions except for any overlapping areas. bool wxRegion::Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { - Unshare(); + AllocExclusive(); MGLRect rect(x, y, x + width, y + height); MGLRegion rg1 = M_REGION + rect, rg2 = M_REGION & rect; @@ -215,7 +229,7 @@ bool wxRegion::Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height) bool wxRegion::Xor(const wxRegion& region) { - Unshare(); + AllocExclusive(); MGLRegion rg1 = M_REGION + M_REGION_OF(region), rg2 = M_REGION & M_REGION_OF(region); M_REGION = rg1 - rg2; @@ -273,28 +287,30 @@ wxRegionContain wxRegion::Contains(const wxRect& rect) const } +/////////////////////////////////////////////////////////////////////////////// +// wxRegionIterator // +/////////////////////////////////////////////////////////////////////////////// + +#if wxUSE_THREADS +static wxMutex *gs_mutexIterator; -void wxRegion::Unshare() +class wxMglRegionModule : public wxModule { - if (!m_refData) +public: + virtual bool OnInit() { - m_refData = new wxRegionRefData(); + gs_mutexIterator = new wxMutex(); + return TRUE; } - else + virtual void OnExit() { - wxRegionRefData* ref = new wxRegionRefData(*(wxRegionRefData*)m_refData); - UnRef(); - m_refData = ref; + wxDELETE(gs_mutexIterator); } -} - - - - -/////////////////////////////////////////////////////////////////////////////// -// wxRegionIterator // -/////////////////////////////////////////////////////////////////////////////// + DECLARE_DYNAMIC_CLASS(wxMglRegionModule) +}; +IMPLEMENT_DYNAMIC_CLASS(wxMglRegionModule, wxModule) +#endif /* * Initialize empty iterator @@ -337,10 +353,11 @@ void wxRegionIterator::Reset(const wxRegion& region) if (!region.Empty()) { - wxMutexGuiEnter(); +#if wxUSE_THREADS + wxMutexLocker(*gs_mutexIterator); +#endif gs_rectList = &m_rects; M_REGION_OF(region).traverse(wxMGL_region_callback); - wxMutexGuiLeave(); m_currentNode = m_rects.GetFirst(); } } @@ -396,4 +413,3 @@ wxCoord wxRegionIterator::GetH() const else return 0; } -