From 7ff64980aaae854d35260b57449dd46fb2f70954 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 23 Jul 2004 18:52:18 +0000 Subject: [PATCH] don't modify all wxBitmaps sharing the same wxBitmapRefData when SetMask() is called git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28434 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/bitmap.h | 1 + include/wx/msw/gdiimage.h | 26 ++++++++++++++------- src/msw/bitmap.cpp | 48 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 64 insertions(+), 11 deletions(-) diff --git a/include/wx/msw/bitmap.h b/include/wx/msw/bitmap.h index 0af92d4ea2..701c4a8c9e 100644 --- a/include/wx/msw/bitmap.h +++ b/include/wx/msw/bitmap.h @@ -179,6 +179,7 @@ protected: void Init(); virtual wxGDIImageRefData *CreateData() const; + virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; // creates the bitmap from XPM data, supposed to be called from ctor bool CreateFromXpm(const char **bits); diff --git a/include/wx/msw/gdiimage.h b/include/wx/msw/gdiimage.h index 5598ed0238..ac89747bd5 100644 --- a/include/wx/msw/gdiimage.h +++ b/include/wx/msw/gdiimage.h @@ -44,6 +44,16 @@ public: m_handle = 0; } + wxGDIImageRefData(const wxGDIImageRefData& data) + { + m_width = data.m_width; + m_height = data.m_height; + m_depth = data.m_depth; + + // can't copy handles like this, derived class copy ctor must do it! + m_handle = NULL; + } + // accessors bool IsOk() const { return m_handle != 0; } @@ -142,14 +152,11 @@ public: wxGDIImageRefData *GetGDIImageData() const { return (wxGDIImageRefData *)m_refData; } - // create data if we don't have it yet - void EnsureHasData() { if ( IsNull() ) m_refData = CreateData(); } - // accessors WXHANDLE GetHandle() const { return IsNull() ? 0 : GetGDIImageData()->m_handle; } void SetHandle(WXHANDLE handle) - { EnsureHasData(); GetGDIImageData()->m_handle = handle; } + { AllocExclusive(); GetGDIImageData()->m_handle = handle; } bool Ok() const { return GetHandle() != 0; } @@ -157,13 +164,13 @@ public: int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_height; } int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_depth; } - void SetWidth(int w) { EnsureHasData(); GetGDIImageData()->m_width = w; } - void SetHeight(int h) { EnsureHasData(); GetGDIImageData()->m_height = h; } - void SetDepth(int d) { EnsureHasData(); GetGDIImageData()->m_depth = d; } + void SetWidth(int w) { AllocExclusive(); GetGDIImageData()->m_width = w; } + void SetHeight(int h) { AllocExclusive(); GetGDIImageData()->m_height = h; } + void SetDepth(int d) { AllocExclusive(); GetGDIImageData()->m_depth = d; } void SetSize(int w, int h) { - EnsureHasData(); + AllocExclusive(); GetGDIImageData()->SetSize(w, h); } void SetSize(const wxSize& size) { SetSize(size.x, size.y); } @@ -176,6 +183,9 @@ protected: // create the data for the derived class here virtual wxGDIImageRefData *CreateData() const = 0; + // implement the wxObject method in terms of our, more specific, one + virtual wxObjectRefData *CreateRefData() const { return CreateData(); } + static wxGDIImageHandlerList ms_handlers; }; diff --git a/src/msw/bitmap.cpp b/src/msw/bitmap.cpp index b174fdf9de..5fbb33b963 100644 --- a/src/msw/bitmap.cpp +++ b/src/msw/bitmap.cpp @@ -67,6 +67,7 @@ class WXDLLEXPORT wxBitmapRefData : public wxGDIImageRefData { public: wxBitmapRefData(); + wxBitmapRefData(const wxBitmapRefData& data); virtual ~wxBitmapRefData() { Free(); } virtual void Free(); @@ -120,7 +121,9 @@ private: // optional mask for transparent drawing wxMask *m_bitmapMask; - DECLARE_NO_COPY_CLASS(wxBitmapRefData) + + // not implemented + wxBitmapRefData& operator=(const wxBitmapRefData&); }; // ---------------------------------------------------------------------------- @@ -200,6 +203,23 @@ wxBitmapRefData::wxBitmapRefData() m_hasAlpha = FALSE; } +wxBitmapRefData::wxBitmapRefData(const wxBitmapRefData& data) + : wxGDIImageRefData(data) +{ +#ifdef __WXDEBUG__ + m_selectedInto = NULL; +#endif + + // can't copy the mask as the other bitmap destroys it + m_bitmapMask = NULL; + + wxASSERT_MSG( !data.m_isDIB, + _T("can't copy bitmap locked for raw access!") ); + m_isDIB = FALSE; + + m_hasAlpha = data.m_hasAlpha; +} + void wxBitmapRefData::Free() { wxASSERT_MSG( !m_selectedInto, @@ -236,6 +256,28 @@ wxGDIImageRefData *wxBitmap::CreateData() const return new wxBitmapRefData; } +wxObjectRefData *wxBitmap::CloneRefData(const wxObjectRefData *dataOrig) const +{ + const wxBitmapRefData * + data = wx_static_cast(const wxBitmapRefData *, dataOrig); + if ( !data ) + return NULL; + + wxBitmap *self = wx_const_cast(wxBitmap *, this); + self->m_refData = new wxBitmapRefData(*data); + +#if wxUSE_WXDIB + // copy the other bitmap + if ( data->m_hBitmap ) + { + wxDIB dib((HBITMAP)(data->m_hBitmap)); + self->CopyFromDIB(dib); + } +#endif // wxUSE_WXDIB + + return m_refData; +} + #ifdef __WIN32__ bool wxBitmap::CopyFromIconOrCursor(const wxGDIImage& icon) @@ -1094,7 +1136,7 @@ void wxBitmap::SetSelectedInto(wxDC *dc) void wxBitmap::SetPalette(const wxPalette& palette) { - EnsureHasData(); + AllocExclusive(); GetBitmapData()->m_bitmapPalette = palette; } @@ -1103,7 +1145,7 @@ void wxBitmap::SetPalette(const wxPalette& palette) void wxBitmap::SetMask(wxMask *mask) { - EnsureHasData(); + AllocExclusive(); GetBitmapData()->SetMask(mask); } -- 2.45.2