diff --git a/include/wx/animate.h b/include/wx/animate.h index 18f2dbdd71..2a0454a0e8 100644 --- a/include/wx/animate.h +++ b/include/wx/animate.h @@ -37,10 +37,11 @@ enum wxAnimationImplType wxANIMATION_IMPL_TYPE_GENERIC }; -class WXDLLIMPEXP_CORE wxAnimationImpl : public wxObject, public wxRefCounter +class WXDLLIMPEXP_CORE wxAnimationImpl : public wxRefCounter { public: wxAnimationImpl() {} + virtual ~wxAnimationImpl() {} virtual wxAnimationImplType GetImplType() = 0; diff --git a/include/wx/generic/private/animate.h b/include/wx/generic/private/animate.h index d5b89e2ca2..49300d61b4 100644 --- a/include/wx/generic/private/animate.h +++ b/include/wx/generic/private/animate.h @@ -11,8 +11,6 @@ #ifndef _WX_GENERIC_PRIVATE_ANIMATEH__ #define _WX_GENERIC_PRIVATE_ANIMATEH__ -#include "wx/bitmap.h" - // ---------------------------------------------------------------------------- // wxAnimationGenericImpl // ---------------------------------------------------------------------------- @@ -20,13 +18,14 @@ class WXDLLIMPEXP_ADV wxAnimationGenericImpl : public wxAnimationImpl { public: - wxAnimationGenericImpl() {} + wxAnimationGenericImpl() : m_decoder(NULL) {} + virtual ~wxAnimationGenericImpl() { UnRef(); } virtual wxAnimationImplType GetImplType() wxOVERRIDE { return wxANIMATION_IMPL_TYPE_GENERIC; } virtual bool IsOk() const wxOVERRIDE - { return m_refData != NULL; } + { return m_decoder != NULL; } virtual unsigned int GetFrameCount() const wxOVERRIDE; virtual int GetDelay(unsigned int i) const wxOVERRIDE; @@ -45,9 +44,12 @@ public: virtual wxColour GetTransparentColour(unsigned int frame) const; virtual wxColour GetBackgroundColour() const; -protected: +private: + void UnRef(); + + wxAnimationDecoder* m_decoder; + wxDECLARE_NO_COPY_CLASS(wxAnimationGenericImpl); - wxDECLARE_DYNAMIC_CLASS(wxAnimationGenericImpl); }; diff --git a/include/wx/gtk/private/animate.h b/include/wx/gtk/private/animate.h index 6337547ce7..a923984679 100644 --- a/include/wx/gtk/private/animate.h +++ b/include/wx/gtk/private/animate.h @@ -64,7 +64,6 @@ private: typedef wxAnimationImpl base_type; wxDECLARE_NO_COPY_CLASS(wxAnimationGTKImpl); - wxDECLARE_DYNAMIC_CLASS(wxAnimationGTKImpl); }; diff --git a/src/generic/animateg.cpp b/src/generic/animateg.cpp index 97513ad71d..176080b4cc 100644 --- a/src/generic/animateg.cpp +++ b/src/generic/animateg.cpp @@ -32,22 +32,18 @@ // wxAnimation // ---------------------------------------------------------------------------- -wxIMPLEMENT_DYNAMIC_CLASS(wxAnimationGenericImpl, wxAnimationImpl); - -#define M_ANIMDATA static_cast(m_refData) - wxSize wxAnimationGenericImpl::GetSize() const { wxCHECK_MSG( IsOk(), wxDefaultSize, wxT("invalid animation") ); - return M_ANIMDATA->GetAnimationSize(); + return m_decoder->GetAnimationSize(); } unsigned int wxAnimationGenericImpl::GetFrameCount() const { wxCHECK_MSG( IsOk(), 0, wxT("invalid animation") ); - return M_ANIMDATA->GetFrameCount(); + return m_decoder->GetFrameCount(); } wxImage wxAnimationGenericImpl::GetFrame(unsigned int i) const @@ -55,7 +51,7 @@ wxImage wxAnimationGenericImpl::GetFrame(unsigned int i) const wxCHECK_MSG( IsOk(), wxNullImage, wxT("invalid animation") ); wxImage ret; - if (!M_ANIMDATA->ConvertToImage(i, &ret)) + if (!m_decoder->ConvertToImage(i, &ret)) return wxNullImage; return ret; } @@ -64,42 +60,42 @@ int wxAnimationGenericImpl::GetDelay(unsigned int i) const { wxCHECK_MSG( IsOk(), 0, wxT("invalid animation") ); - return M_ANIMDATA->GetDelay(i); + return m_decoder->GetDelay(i); } wxPoint wxAnimationGenericImpl::GetFramePosition(unsigned int frame) const { wxCHECK_MSG( IsOk(), wxDefaultPosition, wxT("invalid animation") ); - return M_ANIMDATA->GetFramePosition(frame); + return m_decoder->GetFramePosition(frame); } wxSize wxAnimationGenericImpl::GetFrameSize(unsigned int frame) const { wxCHECK_MSG( IsOk(), wxDefaultSize, wxT("invalid animation") ); - return M_ANIMDATA->GetFrameSize(frame); + return m_decoder->GetFrameSize(frame); } wxAnimationDisposal wxAnimationGenericImpl::GetDisposalMethod(unsigned int frame) const { wxCHECK_MSG( IsOk(), wxANIM_UNSPECIFIED, wxT("invalid animation") ); - return M_ANIMDATA->GetDisposalMethod(frame); + return m_decoder->GetDisposalMethod(frame); } wxColour wxAnimationGenericImpl::GetTransparentColour(unsigned int frame) const { wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid animation") ); - return M_ANIMDATA->GetTransparentColour(frame); + return m_decoder->GetTransparentColour(frame); } wxColour wxAnimationGenericImpl::GetBackgroundColour() const { wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid animation") ); - return M_ANIMDATA->GetBackgroundColour(); + return m_decoder->GetBackgroundColour(); } bool wxAnimationGenericImpl::LoadFile(const wxString& filename, wxAnimationType type) @@ -127,8 +123,8 @@ bool wxAnimationGenericImpl::Load(wxInputStream &stream, wxAnimationType type) { // do a copy of the handler from the static list which we will own // as our reference data - m_refData = handler->Clone(); - return M_ANIMDATA->Load(stream); + m_decoder = handler->Clone(); + return m_decoder->Load(stream); } } @@ -148,17 +144,25 @@ bool wxAnimationGenericImpl::Load(wxInputStream &stream, wxAnimationType type) // do a copy of the handler from the static list which we will own // as our reference data - m_refData = handler->Clone(); + m_decoder = handler->Clone(); - if (stream.IsSeekable() && !M_ANIMDATA->CanRead(stream)) + if (stream.IsSeekable() && !m_decoder->CanRead(stream)) { wxLogError(_("Animation file is not of type %ld."), type); return false; } else - return M_ANIMDATA->Load(stream); + return m_decoder->Load(stream); } +void wxAnimationGenericImpl::UnRef() +{ + if ( m_decoder ) + { + m_decoder->DecRef(); + m_decoder = NULL; + } +} // ---------------------------------------------------------------------------- // wxAnimationCtrl diff --git a/src/gtk/animate.cpp b/src/gtk/animate.cpp index 6ec9a18e1a..c62a390800 100644 --- a/src/gtk/animate.cpp +++ b/src/gtk/animate.cpp @@ -53,8 +53,6 @@ void gdk_pixbuf_area_updated(GdkPixbufLoader *loader, // wxAnimationGTKImpl //----------------------------------------------------------------------------- -wxIMPLEMENT_DYNAMIC_CLASS(wxAnimationGTKImpl, wxAnimationImpl); - bool wxAnimationGTKImpl::LoadFile(const wxString &name, wxAnimationType WXUNUSED(type)) { UnRef(); @@ -162,7 +160,6 @@ wxSize wxAnimationGTKImpl::GetSize() const void wxAnimationGTKImpl::UnRef() { - base_type::UnRef(); if (m_pixbuf) g_object_unref(m_pixbuf); m_pixbuf = NULL;