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
This commit is contained in:
		@@ -179,6 +179,7 @@ protected:
 | 
				
			|||||||
    void Init();
 | 
					    void Init();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    virtual wxGDIImageRefData *CreateData() const;
 | 
					    virtual wxGDIImageRefData *CreateData() const;
 | 
				
			||||||
 | 
					    virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // creates the bitmap from XPM data, supposed to be called from ctor
 | 
					    // creates the bitmap from XPM data, supposed to be called from ctor
 | 
				
			||||||
    bool CreateFromXpm(const char **bits);
 | 
					    bool CreateFromXpm(const char **bits);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -44,6 +44,16 @@ public:
 | 
				
			|||||||
        m_handle = 0;
 | 
					        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
 | 
					    // accessors
 | 
				
			||||||
    bool IsOk() const { return m_handle != 0; }
 | 
					    bool IsOk() const { return m_handle != 0; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -142,14 +152,11 @@ public:
 | 
				
			|||||||
    wxGDIImageRefData *GetGDIImageData() const
 | 
					    wxGDIImageRefData *GetGDIImageData() const
 | 
				
			||||||
        { return (wxGDIImageRefData *)m_refData; }
 | 
					        { return (wxGDIImageRefData *)m_refData; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // create data if we don't have it yet
 | 
					 | 
				
			||||||
    void EnsureHasData() { if ( IsNull() ) m_refData = CreateData(); }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // accessors
 | 
					    // accessors
 | 
				
			||||||
    WXHANDLE GetHandle() const
 | 
					    WXHANDLE GetHandle() const
 | 
				
			||||||
        { return IsNull() ? 0 : GetGDIImageData()->m_handle; }
 | 
					        { return IsNull() ? 0 : GetGDIImageData()->m_handle; }
 | 
				
			||||||
    void SetHandle(WXHANDLE handle)
 | 
					    void SetHandle(WXHANDLE handle)
 | 
				
			||||||
        { EnsureHasData(); GetGDIImageData()->m_handle = handle; }
 | 
					        { AllocExclusive(); GetGDIImageData()->m_handle = handle; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bool Ok() const { return GetHandle() != 0; }
 | 
					    bool Ok() const { return GetHandle() != 0; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -157,13 +164,13 @@ public:
 | 
				
			|||||||
    int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_height; }
 | 
					    int GetHeight() const { return IsNull() ? 0 : GetGDIImageData()->m_height; }
 | 
				
			||||||
    int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_depth; }
 | 
					    int GetDepth() const { return IsNull() ? 0 : GetGDIImageData()->m_depth; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void SetWidth(int w) { EnsureHasData(); GetGDIImageData()->m_width = w; }
 | 
					    void SetWidth(int w) { AllocExclusive(); GetGDIImageData()->m_width = w; }
 | 
				
			||||||
    void SetHeight(int h) { EnsureHasData(); GetGDIImageData()->m_height = h; }
 | 
					    void SetHeight(int h) { AllocExclusive(); GetGDIImageData()->m_height = h; }
 | 
				
			||||||
    void SetDepth(int d) { EnsureHasData(); GetGDIImageData()->m_depth = d; }
 | 
					    void SetDepth(int d) { AllocExclusive(); GetGDIImageData()->m_depth = d; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void SetSize(int w, int h)
 | 
					    void SetSize(int w, int h)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        EnsureHasData();
 | 
					        AllocExclusive();
 | 
				
			||||||
        GetGDIImageData()->SetSize(w, h);
 | 
					        GetGDIImageData()->SetSize(w, h);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    void SetSize(const wxSize& size) { SetSize(size.x, size.y); }
 | 
					    void SetSize(const wxSize& size) { SetSize(size.x, size.y); }
 | 
				
			||||||
@@ -176,6 +183,9 @@ protected:
 | 
				
			|||||||
    // create the data for the derived class here
 | 
					    // create the data for the derived class here
 | 
				
			||||||
    virtual wxGDIImageRefData *CreateData() const = 0;
 | 
					    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;
 | 
					    static wxGDIImageHandlerList ms_handlers;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -67,6 +67,7 @@ class WXDLLEXPORT wxBitmapRefData : public wxGDIImageRefData
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    wxBitmapRefData();
 | 
					    wxBitmapRefData();
 | 
				
			||||||
 | 
					    wxBitmapRefData(const wxBitmapRefData& data);
 | 
				
			||||||
    virtual ~wxBitmapRefData() { Free(); }
 | 
					    virtual ~wxBitmapRefData() { Free(); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    virtual void Free();
 | 
					    virtual void Free();
 | 
				
			||||||
@@ -120,7 +121,9 @@ private:
 | 
				
			|||||||
    // optional mask for transparent drawing
 | 
					    // optional mask for transparent drawing
 | 
				
			||||||
    wxMask       *m_bitmapMask;
 | 
					    wxMask       *m_bitmapMask;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    DECLARE_NO_COPY_CLASS(wxBitmapRefData)
 | 
					
 | 
				
			||||||
 | 
					    // not implemented
 | 
				
			||||||
 | 
					    wxBitmapRefData& operator=(const wxBitmapRefData&);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// ----------------------------------------------------------------------------
 | 
					// ----------------------------------------------------------------------------
 | 
				
			||||||
@@ -200,6 +203,23 @@ wxBitmapRefData::wxBitmapRefData()
 | 
				
			|||||||
    m_hasAlpha = FALSE;
 | 
					    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()
 | 
					void wxBitmapRefData::Free()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    wxASSERT_MSG( !m_selectedInto,
 | 
					    wxASSERT_MSG( !m_selectedInto,
 | 
				
			||||||
@@ -236,6 +256,28 @@ wxGDIImageRefData *wxBitmap::CreateData() const
 | 
				
			|||||||
    return new wxBitmapRefData;
 | 
					    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__
 | 
					#ifdef __WIN32__
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool wxBitmap::CopyFromIconOrCursor(const wxGDIImage& icon)
 | 
					bool wxBitmap::CopyFromIconOrCursor(const wxGDIImage& icon)
 | 
				
			||||||
@@ -1094,7 +1136,7 @@ void wxBitmap::SetSelectedInto(wxDC *dc)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void wxBitmap::SetPalette(const wxPalette& palette)
 | 
					void wxBitmap::SetPalette(const wxPalette& palette)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    EnsureHasData();
 | 
					    AllocExclusive();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    GetBitmapData()->m_bitmapPalette = palette;
 | 
					    GetBitmapData()->m_bitmapPalette = palette;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -1103,7 +1145,7 @@ void wxBitmap::SetPalette(const wxPalette& palette)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void wxBitmap::SetMask(wxMask *mask)
 | 
					void wxBitmap::SetMask(wxMask *mask)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    EnsureHasData();
 | 
					    AllocExclusive();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    GetBitmapData()->SetMask(mask);
 | 
					    GetBitmapData()->SetMask(mask);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user