X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3317223b08943c74ee4c7956b6aa9a3e72f87d77..3e1924dd5f5744c3e2a8973de9b3e4f372b7fd85:/src/msw/region.cpp?ds=sidebyside diff --git a/src/msw/region.cpp b/src/msw/region.cpp index dc33bc15a2..329f150d01 100644 --- a/src/msw/region.cpp +++ b/src/msw/region.cpp @@ -1,37 +1,43 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: msw/region.cpp -// Purpose: Region handling for wxWindows/X11 -// Author: Markus Holzem +// Name: src/msw/region.cpp +// Purpose: wxRegion implementation using Win32 API +// Author: Vadim Zeitlin // Modified by: // Created: Fri Oct 24 10:46:34 MET 1997 // RCS-ID: $Id$ -// Copyright: (c) 1997 Julian Smart and Markus Holzem +// Copyright: (c) 1997-2002 wxWidgets team // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "region.h" -#endif +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif -#include "wx/msw/region.h" -#include "wx/gdicmn.h" +#include "wx/region.h" + +#ifndef WX_PRECOMP + #include "wx/gdicmn.h" +#endif -#include "wx/window.h" #include "wx/msw/private.h" IMPLEMENT_DYNAMIC_CLASS(wxRegion, wxGDIObject) IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator, wxObject) -//----------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- // wxRegionRefData implementation -//----------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- class WXDLLEXPORT wxRegionRefData : public wxGDIRefData { @@ -41,9 +47,9 @@ public: m_region = 0; } - wxRegionRefData(const wxRegionRefData& data) + wxRegionRefData(const wxRegionRefData& data) : wxGDIRefData() { -#if defined(__WIN32__) && !defined(__WXMICROWIN__) +#if defined(__WIN32__) && !defined(__WXMICROWIN__) && !defined(__WXWINCE__) DWORD noBytes = ::GetRegionData(data.m_region, 0, NULL); RGNDATA *rgnData = (RGNDATA*) new char[noBytes]; ::GetRegionData(data.m_region, noBytes, rgnData); @@ -56,25 +62,34 @@ public: #endif } - ~wxRegionRefData() + virtual ~wxRegionRefData() { ::DeleteObject(m_region); m_region = 0; } HRGN m_region; + +private: +// Cannot use +// DECLARE_NO_COPY_CLASS(wxRegionRefData) +// because copy constructor is explicitly declared above; +// but no copy assignment operator is defined, so declare +// it private to prevent the compiler from defining it: + wxRegionRefData& operator=(const wxRegionRefData&); }; #define M_REGION (((wxRegionRefData*)m_refData)->m_region) #define M_REGION_OF(rgn) (((wxRegionRefData*)(rgn.m_refData))->m_region) -//----------------------------------------------------------------------------- -// wxRegion -//----------------------------------------------------------------------------- +// ============================================================================ +// wxRegion implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// ctors and dtor +// ---------------------------------------------------------------------------- -/* - * Create an empty region. - */ wxRegion::wxRegion() { m_refData = (wxRegionRefData *)NULL; @@ -106,7 +121,10 @@ wxRegion::wxRegion(const wxRect& rect) wxRegion::wxRegion(size_t n, const wxPoint *points, int fillStyle) { -#ifdef __WXMICROWIN__ +#if defined(__WXMICROWIN__) || defined(__WXWINCE__) + wxUnusedVar(n); + wxUnusedVar(points); + wxUnusedVar(fillStyle); m_refData = NULL; M_REGION = NULL; #else @@ -125,19 +143,19 @@ wxRegion::~wxRegion() // m_refData unrefed in ~wxObject } -wxObjectRefData *wxRegion::CreateRefData() const +wxGDIRefData *wxRegion::CreateGDIRefData() const { return new wxRegionRefData; } -wxObjectRefData *wxRegion::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxRegion::CloneGDIRefData(const wxGDIRefData *data) const { return new wxRegionRefData(*(wxRegionRefData *)data); } -//----------------------------------------------------------------------------- -// Modify region -//----------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- +// wxRegion operations +// ---------------------------------------------------------------------------- // Clear current region void wxRegion::Clear() @@ -145,14 +163,14 @@ void wxRegion::Clear() UnRef(); } -bool wxRegion::Offset(wxCoord x, wxCoord y) +bool wxRegion::DoOffset(wxCoord x, wxCoord y) { - wxCHECK_MSG( M_REGION, FALSE, _T("invalid wxRegion") ); + wxCHECK_MSG( M_REGION, false, _T("invalid wxRegion") ); if ( !x && !y ) { // nothing to do - return TRUE; + return true; } AllocExclusive(); @@ -161,14 +179,14 @@ bool wxRegion::Offset(wxCoord x, wxCoord y) { wxLogLastError(_T("OffsetRgn")); - return FALSE; + return false; } - return TRUE; + return true; } // combine another region with this one -bool wxRegion::Combine(const wxRegion& rgn, wxRegionOp op) +bool wxRegion::DoCombine(const wxRegion& rgn, wxRegionOp op) { // we can't use the API functions if we don't have a valid region handle if ( !m_refData ) @@ -190,11 +208,13 @@ bool wxRegion::Combine(const wxRegion& rgn, wxRegionOp op) case wxRGN_AND: case wxRGN_DIFF: // leave empty/invalid - return FALSE; + return false; } } else // we have a valid region { + AllocExclusive(); + int mode; switch ( op ) { @@ -227,33 +247,19 @@ bool wxRegion::Combine(const wxRegion& rgn, wxRegionOp op) { wxLogLastError(_T("CombineRgn")); - return FALSE; + return false; } } - return TRUE; + return true; } -// Combine rectangle (x, y, w, h) with this. -bool wxRegion::Combine(wxCoord x, wxCoord y, - wxCoord width, wxCoord height, - wxRegionOp op) -{ - return Combine(wxRegion(x, y, width, height), op); -} - -bool wxRegion::Combine(const wxRect& rect, wxRegionOp op) -{ - return Combine(rect.GetLeft(), rect.GetTop(), - rect.GetWidth(), rect.GetHeight(), op); -} - -//----------------------------------------------------------------------------- -// Information on region -//----------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- +// wxRegion bounding box +// ---------------------------------------------------------------------------- // Outer bounds of region -void wxRegion::GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const +bool wxRegion::DoGetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const { if (m_refData) { @@ -263,22 +269,19 @@ void wxRegion::GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const y = rect.top; w = rect.right - rect.left; h = rect.bottom - rect.top; + + return true; } else { x = y = w = h = 0; - } -} -wxRect wxRegion::GetBox() const -{ - wxCoord x, y, w, h; - GetBox(x, y, w, h); - return wxRect(x, y, w, h); + return false; + } } // Is region empty? -bool wxRegion::Empty() const +bool wxRegion::IsEmpty() const { wxCoord x, y, w, h; GetBox(x, y, w, h); @@ -286,96 +289,64 @@ bool wxRegion::Empty() const return (w == 0) && (h == 0); } -//----------------------------------------------------------------------------- -// Tests -//----------------------------------------------------------------------------- - -// Does the region contain the point (x,y)? -wxRegionContain wxRegion::Contains(wxCoord x, wxCoord y) const +bool wxRegion::DoIsEqual(const wxRegion& region) const { - if (!m_refData) - return wxOutRegion; - - if (::PtInRegion(M_REGION, (int) x, (int) y)) - return wxInRegion; - else - return wxOutRegion; + return ::EqualRgn(M_REGION, M_REGION_OF(region)) != 0; } -// Does the region contain the point pt? -wxRegionContain wxRegion::Contains(const wxPoint& pt) const +// ---------------------------------------------------------------------------- +// wxRegion hit testing +// ---------------------------------------------------------------------------- + +// Does the region contain the point (x,y)? +wxRegionContain wxRegion::DoContainsPoint(wxCoord x, wxCoord y) const { if (!m_refData) return wxOutRegion; - if (::PtInRegion(M_REGION, (int) pt.x, (int) pt.y)) - return wxInRegion; - else - return wxOutRegion; + return ::PtInRegion(M_REGION, (int) x, (int) y) ? wxInRegion : wxOutRegion; } // Does the region contain the rectangle (x, y, w, h)? -wxRegionContain wxRegion::Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const +wxRegionContain wxRegion::DoContainsRect(const wxRect& rect) const { if (!m_refData) return wxOutRegion; - RECT rect; - rect.left = x; - rect.top = y; - rect.right = x + w; - rect.bottom = y + h; + RECT rc; + wxCopyRectToRECT(rect, rc); - if (::RectInRegion(M_REGION, & rect)) - return wxInRegion; - else - return wxOutRegion; -} - -// Does the region contain the rectangle rect -wxRegionContain wxRegion::Contains(const wxRect& rect) const -{ - if (!m_refData) - return wxOutRegion; - - wxCoord x, y, w, h; - x = rect.x; - y = rect.y; - w = rect.GetWidth(); - h = rect.GetHeight(); - return Contains(x, y, w, h); + return ::RectInRegion(M_REGION, &rc) ? wxInRegion : wxOutRegion; } // Get internal region handle WXHRGN wxRegion::GetHRGN() const { - if (!m_refData) - return (WXHRGN) 0; - return (WXHRGN) M_REGION; + return (WXHRGN)(m_refData ? M_REGION : 0); } -/////////////////////////////////////////////////////////////////////////////// -// // -// wxRegionIterator // -// // -/////////////////////////////////////////////////////////////////////////////// +// ============================================================================ +// wxRegionIterator implementation +// ============================================================================ -/* - * Initialize empty iterator - */ -wxRegionIterator::wxRegionIterator() : m_current(0), m_numRects(0), m_rects(NULL) +// ---------------------------------------------------------------------------- +// wxRegionIterator ctors/dtor +// ---------------------------------------------------------------------------- + +void wxRegionIterator::Init() { + m_current = + m_numRects = 0; + + m_rects = NULL; } wxRegionIterator::~wxRegionIterator() { - if (m_rects) - delete[] m_rects; + delete [] m_rects; } -/* - * Initialize iterator for region - */ +// Initialize iterator for region wxRegionIterator::wxRegionIterator(const wxRegion& region) { m_rects = NULL; @@ -383,24 +354,47 @@ wxRegionIterator::wxRegionIterator(const wxRegion& region) Reset(region); } -/* - * Reset iterator for a new /e region. - */ +wxRegionIterator& wxRegionIterator::operator=(const wxRegionIterator& ri) +{ + delete [] m_rects; + + m_current = ri.m_current; + m_numRects = ri.m_numRects; + if ( m_numRects ) + { + m_rects = new wxRect[m_numRects]; + for ( long n = 0; n < m_numRects; n++ ) + m_rects[n] = ri.m_rects[n]; + } + else + { + m_rects = NULL; + } + + return *this; +} + +// ---------------------------------------------------------------------------- +// wxRegionIterator operations +// ---------------------------------------------------------------------------- + +// Reset iterator for a new region. void wxRegionIterator::Reset(const wxRegion& region) { m_current = 0; m_region = region; if (m_rects) + { delete[] m_rects; - m_rects = NULL; + m_rects = NULL; + } if (m_region.Empty()) m_numRects = 0; else { -#if defined(__WIN32__) DWORD noBytes = ::GetRegionData(((wxRegionRefData*)region.m_refData)->m_region, 0, NULL); RGNDATA *rgnData = (RGNDATA*) new char[noBytes]; ::GetRegionData(((wxRegionRefData*)region.m_refData)->m_region, noBytes, rgnData); @@ -421,65 +415,54 @@ void wxRegionIterator::Reset(const wxRegion& region) m_numRects = header->nCount; delete[] (char*) rgnData; -#else - RECT rect; - ::GetRgnBox(((wxRegionRefData*)region.m_refData)->m_region, &rect); - m_rects = new wxRect[1]; - m_rects[0].x = rect.left; - m_rects[0].y = rect.top; - m_rects[0].width = rect.right - rect.left; - m_rects[0].height = rect.bottom - rect.top; - - m_numRects = 1; -#endif } } -/* - * Increment iterator. The rectangle returned is the one after the - * incrementation. - */ -void wxRegionIterator::operator ++ () +wxRegionIterator& wxRegionIterator::operator++() { if (m_current < m_numRects) ++m_current; + + return *this; } -/* - * Increment iterator. The rectangle returned is the one before the - * incrementation. - */ -void wxRegionIterator::operator ++ (int) +wxRegionIterator wxRegionIterator::operator ++ (int) { + wxRegionIterator tmp = *this; if (m_current < m_numRects) ++m_current; + + return tmp; } +// ---------------------------------------------------------------------------- +// wxRegionIterator accessors +// ---------------------------------------------------------------------------- + wxCoord wxRegionIterator::GetX() const { - if (m_current < m_numRects) - return m_rects[m_current].x; - return 0; + wxCHECK_MSG( m_current < m_numRects, 0, _T("invalid wxRegionIterator") ); + + return m_rects[m_current].x; } wxCoord wxRegionIterator::GetY() const { - if (m_current < m_numRects) - return m_rects[m_current].y; - return 0; + wxCHECK_MSG( m_current < m_numRects, 0, _T("invalid wxRegionIterator") ); + + return m_rects[m_current].y; } wxCoord wxRegionIterator::GetW() const { - if (m_current < m_numRects) - return m_rects[m_current].width; - return 0; + wxCHECK_MSG( m_current < m_numRects, 0, _T("invalid wxRegionIterator") ); + + return m_rects[m_current].width; } wxCoord wxRegionIterator::GetH() const { - if (m_current < m_numRects) - return m_rects[m_current].height; - return 0; -} + wxCHECK_MSG( m_current < m_numRects, 0, _T("invalid wxRegionIterator") ); + return m_rects[m_current].height; +}