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:
@@ -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;
|
||||
|
||||
|
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
|
@@ -64,7 +64,6 @@ private:
|
||||
|
||||
typedef wxAnimationImpl base_type;
|
||||
wxDECLARE_NO_COPY_CLASS(wxAnimationGTKImpl);
|
||||
wxDECLARE_DYNAMIC_CLASS(wxAnimationGTKImpl);
|
||||
};
|
||||
|
||||
|
||||
|
@@ -32,22 +32,18 @@
|
||||
// wxAnimation
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxIMPLEMENT_DYNAMIC_CLASS(wxAnimationGenericImpl, wxAnimationImpl);
|
||||
|
||||
#define M_ANIMDATA static_cast<wxAnimationDecoder*>(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
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user