Don't derive wxAnimationImpl from wxObject

This is just unnecessary and having wxAnimation::m_refData->m_refData is
confusing, both in wxGTK version where it's not used and in the generic
one where it is, but can be replaced by more type-safe m_decoder.
This commit is contained in:
Vadim Zeitlin
2020-04-05 23:48:49 +02:00
parent 1bf48dfe29
commit 86d6cb8d1f
5 changed files with 32 additions and 29 deletions

View File

@@ -37,10 +37,11 @@ enum wxAnimationImplType
wxANIMATION_IMPL_TYPE_GENERIC wxANIMATION_IMPL_TYPE_GENERIC
}; };
class WXDLLIMPEXP_CORE wxAnimationImpl : public wxObject, public wxRefCounter class WXDLLIMPEXP_CORE wxAnimationImpl : public wxRefCounter
{ {
public: public:
wxAnimationImpl() {} wxAnimationImpl() {}
virtual ~wxAnimationImpl() {}
virtual wxAnimationImplType GetImplType() = 0; virtual wxAnimationImplType GetImplType() = 0;

View File

@@ -11,8 +11,6 @@
#ifndef _WX_GENERIC_PRIVATE_ANIMATEH__ #ifndef _WX_GENERIC_PRIVATE_ANIMATEH__
#define _WX_GENERIC_PRIVATE_ANIMATEH__ #define _WX_GENERIC_PRIVATE_ANIMATEH__
#include "wx/bitmap.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxAnimationGenericImpl // wxAnimationGenericImpl
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -20,13 +18,14 @@
class WXDLLIMPEXP_ADV wxAnimationGenericImpl : public wxAnimationImpl class WXDLLIMPEXP_ADV wxAnimationGenericImpl : public wxAnimationImpl
{ {
public: public:
wxAnimationGenericImpl() {} wxAnimationGenericImpl() : m_decoder(NULL) {}
virtual ~wxAnimationGenericImpl() { UnRef(); }
virtual wxAnimationImplType GetImplType() wxOVERRIDE virtual wxAnimationImplType GetImplType() wxOVERRIDE
{ return wxANIMATION_IMPL_TYPE_GENERIC; } { return wxANIMATION_IMPL_TYPE_GENERIC; }
virtual bool IsOk() const wxOVERRIDE virtual bool IsOk() const wxOVERRIDE
{ return m_refData != NULL; } { return m_decoder != NULL; }
virtual unsigned int GetFrameCount() const wxOVERRIDE; virtual unsigned int GetFrameCount() const wxOVERRIDE;
virtual int GetDelay(unsigned int i) const wxOVERRIDE; virtual int GetDelay(unsigned int i) const wxOVERRIDE;
@@ -45,9 +44,12 @@ public:
virtual wxColour GetTransparentColour(unsigned int frame) const; virtual wxColour GetTransparentColour(unsigned int frame) const;
virtual wxColour GetBackgroundColour() const; virtual wxColour GetBackgroundColour() const;
protected: private:
void UnRef();
wxAnimationDecoder* m_decoder;
wxDECLARE_NO_COPY_CLASS(wxAnimationGenericImpl); wxDECLARE_NO_COPY_CLASS(wxAnimationGenericImpl);
wxDECLARE_DYNAMIC_CLASS(wxAnimationGenericImpl);
}; };

View File

@@ -64,7 +64,6 @@ private:
typedef wxAnimationImpl base_type; typedef wxAnimationImpl base_type;
wxDECLARE_NO_COPY_CLASS(wxAnimationGTKImpl); wxDECLARE_NO_COPY_CLASS(wxAnimationGTKImpl);
wxDECLARE_DYNAMIC_CLASS(wxAnimationGTKImpl);
}; };

View File

@@ -32,22 +32,18 @@
// wxAnimation // wxAnimation
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
wxIMPLEMENT_DYNAMIC_CLASS(wxAnimationGenericImpl, wxAnimationImpl);
#define M_ANIMDATA static_cast<wxAnimationDecoder*>(m_refData)
wxSize wxAnimationGenericImpl::GetSize() const wxSize wxAnimationGenericImpl::GetSize() const
{ {
wxCHECK_MSG( IsOk(), wxDefaultSize, wxT("invalid animation") ); wxCHECK_MSG( IsOk(), wxDefaultSize, wxT("invalid animation") );
return M_ANIMDATA->GetAnimationSize(); return m_decoder->GetAnimationSize();
} }
unsigned int wxAnimationGenericImpl::GetFrameCount() const unsigned int wxAnimationGenericImpl::GetFrameCount() const
{ {
wxCHECK_MSG( IsOk(), 0, wxT("invalid animation") ); wxCHECK_MSG( IsOk(), 0, wxT("invalid animation") );
return M_ANIMDATA->GetFrameCount(); return m_decoder->GetFrameCount();
} }
wxImage wxAnimationGenericImpl::GetFrame(unsigned int i) const 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") ); wxCHECK_MSG( IsOk(), wxNullImage, wxT("invalid animation") );
wxImage ret; wxImage ret;
if (!M_ANIMDATA->ConvertToImage(i, &ret)) if (!m_decoder->ConvertToImage(i, &ret))
return wxNullImage; return wxNullImage;
return ret; return ret;
} }
@@ -64,42 +60,42 @@ int wxAnimationGenericImpl::GetDelay(unsigned int i) const
{ {
wxCHECK_MSG( IsOk(), 0, wxT("invalid animation") ); wxCHECK_MSG( IsOk(), 0, wxT("invalid animation") );
return M_ANIMDATA->GetDelay(i); return m_decoder->GetDelay(i);
} }
wxPoint wxAnimationGenericImpl::GetFramePosition(unsigned int frame) const wxPoint wxAnimationGenericImpl::GetFramePosition(unsigned int frame) const
{ {
wxCHECK_MSG( IsOk(), wxDefaultPosition, wxT("invalid animation") ); wxCHECK_MSG( IsOk(), wxDefaultPosition, wxT("invalid animation") );
return M_ANIMDATA->GetFramePosition(frame); return m_decoder->GetFramePosition(frame);
} }
wxSize wxAnimationGenericImpl::GetFrameSize(unsigned int frame) const wxSize wxAnimationGenericImpl::GetFrameSize(unsigned int frame) const
{ {
wxCHECK_MSG( IsOk(), wxDefaultSize, wxT("invalid animation") ); wxCHECK_MSG( IsOk(), wxDefaultSize, wxT("invalid animation") );
return M_ANIMDATA->GetFrameSize(frame); return m_decoder->GetFrameSize(frame);
} }
wxAnimationDisposal wxAnimationGenericImpl::GetDisposalMethod(unsigned int frame) const wxAnimationDisposal wxAnimationGenericImpl::GetDisposalMethod(unsigned int frame) const
{ {
wxCHECK_MSG( IsOk(), wxANIM_UNSPECIFIED, wxT("invalid animation") ); 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 wxColour wxAnimationGenericImpl::GetTransparentColour(unsigned int frame) const
{ {
wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid animation") ); wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid animation") );
return M_ANIMDATA->GetTransparentColour(frame); return m_decoder->GetTransparentColour(frame);
} }
wxColour wxAnimationGenericImpl::GetBackgroundColour() const wxColour wxAnimationGenericImpl::GetBackgroundColour() const
{ {
wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid animation") ); wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid animation") );
return M_ANIMDATA->GetBackgroundColour(); return m_decoder->GetBackgroundColour();
} }
bool wxAnimationGenericImpl::LoadFile(const wxString& filename, wxAnimationType type) 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 // do a copy of the handler from the static list which we will own
// as our reference data // as our reference data
m_refData = handler->Clone(); m_decoder = handler->Clone();
return M_ANIMDATA->Load(stream); 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 // do a copy of the handler from the static list which we will own
// as our reference data // 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); wxLogError(_("Animation file is not of type %ld."), type);
return false; return false;
} }
else else
return M_ANIMDATA->Load(stream); return m_decoder->Load(stream);
} }
void wxAnimationGenericImpl::UnRef()
{
if ( m_decoder )
{
m_decoder->DecRef();
m_decoder = NULL;
}
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxAnimationCtrl // wxAnimationCtrl

View File

@@ -53,8 +53,6 @@ void gdk_pixbuf_area_updated(GdkPixbufLoader *loader,
// wxAnimationGTKImpl // wxAnimationGTKImpl
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
wxIMPLEMENT_DYNAMIC_CLASS(wxAnimationGTKImpl, wxAnimationImpl);
bool wxAnimationGTKImpl::LoadFile(const wxString &name, wxAnimationType WXUNUSED(type)) bool wxAnimationGTKImpl::LoadFile(const wxString &name, wxAnimationType WXUNUSED(type))
{ {
UnRef(); UnRef();
@@ -162,7 +160,6 @@ wxSize wxAnimationGTKImpl::GetSize() const
void wxAnimationGTKImpl::UnRef() void wxAnimationGTKImpl::UnRef()
{ {
base_type::UnRef();
if (m_pixbuf) if (m_pixbuf)
g_object_unref(m_pixbuf); g_object_unref(m_pixbuf);
m_pixbuf = NULL; m_pixbuf = NULL;