diff --git a/include/wx/animate.h b/include/wx/animate.h index d2c650c765..2a078d167c 100644 --- a/include/wx/animate.h +++ b/include/wx/animate.h @@ -20,9 +20,11 @@ #include "wx/timer.h" #include "wx/bitmap.h" +class WXDLLIMPEXP_FWD_CORE wxAnimation; class WXDLLIMPEXP_FWD_CORE wxGenericAnimation; -extern WXDLLIMPEXP_DATA_CORE(wxGenericAnimation) wxNullAnimation; +extern WXDLLIMPEXP_DATA_CORE(wxAnimation) wxNullAnimation; +extern WXDLLIMPEXP_DATA_CORE(wxGenericAnimation) wxNullGenericAnimation; extern WXDLLIMPEXP_DATA_CORE(const char) wxAnimationCtrlNameStr[]; @@ -32,46 +34,38 @@ extern WXDLLIMPEXP_DATA_CORE(const char) wxAnimationCtrlNameStr[]; WX_DECLARE_LIST_WITH_DECL(wxAnimationDecoder, wxAnimationDecoderList, class WXDLLIMPEXP_ADV); -class WXDLLIMPEXP_ADV wxGenericAnimation : public wxObject +// ---------------------------------------------------------------------------- +// wxAnimationBase +// ---------------------------------------------------------------------------- + +class WXDLLIMPEXP_CORE wxAnimationBase : public wxObject { public: - wxGenericAnimation() {} - wxGenericAnimation(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY) - { LoadFile(name, type); } + wxAnimationBase() {} - virtual bool IsOk() const - { return m_refData != NULL; } + virtual bool IsOk() const = 0; - virtual unsigned int GetFrameCount() const; - virtual int GetDelay(unsigned int i) const; - virtual wxImage GetFrame(unsigned int i) const; - virtual wxSize GetSize() const; + // can be -1 + virtual int GetDelay(unsigned int frame) const = 0; - virtual bool LoadFile(const wxString& filename, - wxAnimationType type = wxANIMATION_TYPE_ANY); + virtual unsigned int GetFrameCount() const = 0; + virtual wxImage GetFrame(unsigned int frame) const = 0; + virtual wxSize GetSize() const = 0; + + virtual bool LoadFile(const wxString& name, + wxAnimationType type = wxANIMATION_TYPE_ANY) = 0; virtual bool Load(wxInputStream& stream, - wxAnimationType type = wxANIMATION_TYPE_ANY); + wxAnimationType type = wxANIMATION_TYPE_ANY) = 0; - // extended interface used by the generic implementation of wxAnimationCtrl - virtual wxPoint GetFramePosition(unsigned int frame) const; - virtual wxSize GetFrameSize(unsigned int frame) const; - virtual wxAnimationDisposal GetDisposalMethod(unsigned int frame) const; - virtual wxColour GetTransparentColour(unsigned int frame) const; - virtual wxColour GetBackgroundColour() const; + // extended interface used only by the generic implementation of wxAnimationCtrl + virtual wxPoint GetFramePosition(unsigned int frame) const = 0; + virtual wxSize GetFrameSize(unsigned int frame) const = 0; + virtual wxAnimationDisposal GetDisposalMethod(unsigned int frame) const = 0; + virtual wxColour GetTransparentColour(unsigned int frame) const = 0; + virtual wxColour GetBackgroundColour() const = 0; protected: - static wxAnimationDecoderList sm_handlers; - -public: - static inline wxAnimationDecoderList& GetHandlers() { return sm_handlers; } - static void AddHandler(wxAnimationDecoder *handler); - static void InsertHandler(wxAnimationDecoder *handler); - static const wxAnimationDecoder *FindHandler( wxAnimationType animType ); - - static void CleanUpHandlers(); - static void InitStandardHandlers(); - - wxDECLARE_DYNAMIC_CLASS(wxGenericAnimation); + wxDECLARE_ABSTRACT_CLASS(wxAnimationBase); }; @@ -98,9 +92,6 @@ public: virtual bool Load(wxInputStream& stream, wxAnimationType type = wxANIMATION_TYPE_ANY) = 0; - virtual void SetAnimation(const wxGenericAnimation &anim) = 0; - virtual wxGenericAnimation GetAnimation() const = 0; - virtual bool Play() = 0; virtual void Stop() = 0; @@ -135,7 +126,8 @@ private: // include the platform-specific version of the wxAnimationCtrl class // ---------------------------------------------------------------------------- -#if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__) +#if defined(__WXGTK20__) + #include "wx/generic/animate.h" #include "wx/gtk/animate.h" #else #include "wx/generic/animate.h" @@ -147,6 +139,8 @@ private: : wxGenericAnimation() {} wxAnimation(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY) : wxGenericAnimation(name, type) {} + wxAnimation(const wxGenericAnimation& other) + : wxGenericAnimation(other) {} private: wxDECLARE_DYNAMIC_CLASS(wxAnimation); }; @@ -154,18 +148,22 @@ private: class WXDLLIMPEXP_ADV wxAnimationCtrl : public wxGenericAnimationCtrl { public: - wxAnimationCtrl() + wxAnimationCtrl() : wxGenericAnimationCtrl() {} wxAnimationCtrl(wxWindow *parent, wxWindowID id, - const wxGenericAnimation& anim = wxNullAnimation, + const wxAnimation& anim = wxNullAnimation, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxAC_DEFAULT_STYLE, const wxString& name = wxAnimationCtrlNameStr) : wxGenericAnimationCtrl(parent, id, anim, pos, size, style, name) {} + + virtual wxAnimation GetAnimation() const + { return wxAnimation(m_animation) ; } + private: wxDECLARE_DYNAMIC_CLASS(wxAnimationCtrl); }; diff --git a/include/wx/generic/animate.h b/include/wx/generic/animate.h index 2ca6fe2f58..73252e29ea 100644 --- a/include/wx/generic/animate.h +++ b/include/wx/generic/animate.h @@ -13,6 +13,53 @@ #include "wx/bitmap.h" +// ---------------------------------------------------------------------------- +// wxGenericAnimation +// ---------------------------------------------------------------------------- + +class WXDLLIMPEXP_ADV wxGenericAnimation : public wxAnimationBase +{ +public: + wxGenericAnimation() {} + wxGenericAnimation(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY) + { LoadFile(name, type); } + + virtual bool IsOk() const + { return m_refData != NULL; } + + virtual unsigned int GetFrameCount() const wxOVERRIDE; + virtual int GetDelay(unsigned int i) const wxOVERRIDE; + virtual wxImage GetFrame(unsigned int i) const wxOVERRIDE; + virtual wxSize GetSize() const wxOVERRIDE; + + virtual bool LoadFile(const wxString& filename, + wxAnimationType type = wxANIMATION_TYPE_ANY) wxOVERRIDE; + virtual bool Load(wxInputStream& stream, + wxAnimationType type = wxANIMATION_TYPE_ANY) wxOVERRIDE; + + // extended interface used only by the generic implementation of wxAnimationCtrl + virtual wxPoint GetFramePosition(unsigned int frame) const wxOVERRIDE; + virtual wxSize GetFrameSize(unsigned int frame) const wxOVERRIDE; + virtual wxAnimationDisposal GetDisposalMethod(unsigned int frame) const wxOVERRIDE; + virtual wxColour GetTransparentColour(unsigned int frame) const wxOVERRIDE; + virtual wxColour GetBackgroundColour() const wxOVERRIDE; + +protected: + static wxAnimationDecoderList sm_handlers; + +public: + static inline wxAnimationDecoderList& GetHandlers() { return sm_handlers; } + static void AddHandler(wxAnimationDecoder *handler); + static void InsertHandler(wxAnimationDecoder *handler); + static const wxAnimationDecoder *FindHandler( wxAnimationType animType ); + + static void CleanUpHandlers(); + static void InitStandardHandlers(); + + wxDECLARE_DYNAMIC_CLASS(wxGenericAnimation); +}; + + // ---------------------------------------------------------------------------- // wxGenericAnimationCtrl // ---------------------------------------------------------------------------- @@ -23,7 +70,7 @@ public: wxGenericAnimationCtrl() { Init(); } wxGenericAnimationCtrl(wxWindow *parent, wxWindowID id, - const wxGenericAnimation& anim = wxNullAnimation, + const wxGenericAnimation& anim = wxNullGenericAnimation, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxAC_DEFAULT_STYLE, @@ -37,7 +84,7 @@ public: void Init(); bool Create(wxWindow *parent, wxWindowID id, - const wxGenericAnimation& anim = wxNullAnimation, + const wxGenericAnimation& anim = wxNullGenericAnimation, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxAC_DEFAULT_STYLE, @@ -45,6 +92,7 @@ public: ~wxGenericAnimationCtrl(); + public: virtual bool LoadFile(const wxString& filename, wxAnimationType type = wxANIMATION_TYPE_ANY) wxOVERRIDE; virtual bool Load(wxInputStream& stream, wxAnimationType type = wxANIMATION_TYPE_ANY) wxOVERRIDE; @@ -55,8 +103,8 @@ public: virtual bool IsPlaying() const wxOVERRIDE { return m_isPlaying; } - void SetAnimation(const wxGenericAnimation &animation) wxOVERRIDE; - wxGenericAnimation GetAnimation() const wxOVERRIDE + void SetAnimation(const wxGenericAnimation &animation); + wxGenericAnimation GetAnimation() const { return m_animation; } virtual void SetInactiveBitmap(const wxBitmap &bmp) wxOVERRIDE; diff --git a/include/wx/gtk/animate.h b/include/wx/gtk/animate.h index f07fdea939..0cd4280d02 100644 --- a/include/wx/gtk/animate.h +++ b/include/wx/gtk/animate.h @@ -38,20 +38,32 @@ public: { return m_pixbuf != NULL; } - // unfortunately GdkPixbufAnimation does not expose these info: - - virtual unsigned int GetFrameCount() const wxOVERRIDE { return 0; } - virtual wxImage GetFrame(unsigned int frame) const wxOVERRIDE; - // we can retrieve the delay for a frame only after building // a GdkPixbufAnimationIter... virtual int GetDelay(unsigned int WXUNUSED(frame)) const wxOVERRIDE { return 0; } - virtual wxSize GetSize() const wxOVERRIDE; virtual bool LoadFile(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY) wxOVERRIDE; virtual bool Load(wxInputStream &stream, wxAnimationType type = wxANIMATION_TYPE_ANY) wxOVERRIDE; + // unfortunately GdkPixbufAnimation does not expose these info: + + virtual unsigned int GetFrameCount() const wxOVERRIDE + { return 0; } + virtual wxImage GetFrame(unsigned int WXUNUSED(frame)) const wxOVERRIDE + { return wxNullImage; } + virtual wxPoint GetFramePosition(unsigned int WXUNUSED(frame)) const wxOVERRIDE + { return wxDefaultPosition; } + virtual wxSize GetFrameSize(unsigned int WXUNUSED(frame)) const wxOVERRIDE + { return wxDefaultSize; } + virtual wxAnimationDisposal GetDisposalMethod(unsigned int WXUNUSED(frame)) const wxOVERRIDE + { return wxANIM_UNSPECIFIED; } + virtual wxColour GetTransparentColour(unsigned int WXUNUSED(frame)) const wxOVERRIDE + { return wxNullColour; } + virtual wxColour GetBackgroundColour() const wxOVERRIDE + { return wxNullColour; } + + // Implementation public: // used by GTK callbacks @@ -112,9 +124,9 @@ public: // public API virtual bool LoadFile(const wxString& filename, wxAnimationType type = wxANIMATION_TYPE_ANY) wxOVERRIDE; virtual bool Load(wxInputStream& stream, wxAnimationType type = wxANIMATION_TYPE_ANY) wxOVERRIDE; - virtual void SetAnimation(const wxAnimation &anim) wxOVERRIDE; - virtual wxAnimation GetAnimation() const wxOVERRIDE - { return wxAnimation(m_anim); } + void SetAnimation(const wxAnimation &anim); + wxAnimation GetAnimation() const + { return wxAnimation(m_anim) ; } virtual bool Play() wxOVERRIDE; virtual void Stop() wxOVERRIDE; diff --git a/src/common/animatecmn.cpp b/src/common/animatecmn.cpp index a5e22342b8..ea34aca2d1 100644 --- a/src/common/animatecmn.cpp +++ b/src/common/animatecmn.cpp @@ -30,14 +30,18 @@ #include "wx/dcmemory.h" const char wxAnimationCtrlNameStr[] = "animationctrl"; +wxGenericAnimation wxNullGenericAnimation; +wxAnimation wxNullAnimation; -// global object -wxGenericAnimation wxNullAnimation; - -wxIMPLEMENT_DYNAMIC_CLASS(wxAnimation, wxGenericAnimation); +wxIMPLEMENT_ABSTRACT_CLASS(wxAnimationBase, wxObject); wxIMPLEMENT_ABSTRACT_CLASS(wxAnimationCtrlBase, wxControl); -wxIMPLEMENT_DYNAMIC_CLASS(wxAnimationCtrl, wxAnimationCtrlBase); +wxIMPLEMENT_DYNAMIC_CLASS(wxAnimation, wxAnimationBase); +wxIMPLEMENT_DYNAMIC_CLASS(wxGenericAnimation, wxAnimationBase); +#if !defined(__WXGTK20__) + // In this case the "native" ctrl is the generic ctrl. See wx/animate.h + wxIMPLEMENT_CLASS(wxAnimationCtrl, wxGenericAnimationCtrl); +#endif // ---------------------------------------------------------------------------- // wxAnimationCtrlBase diff --git a/src/generic/animateg.cpp b/src/generic/animateg.cpp index b4cf4fc181..affbbeb77b 100644 --- a/src/generic/animateg.cpp +++ b/src/generic/animateg.cpp @@ -39,7 +39,6 @@ wxAnimationDecoderList wxGenericAnimation::sm_handlers; // wxAnimation // ---------------------------------------------------------------------------- -wxIMPLEMENT_DYNAMIC_CLASS(wxGenericAnimation, wxObject); #define M_ANIMDATA static_cast(m_refData) wxSize wxGenericAnimation::GetSize() const @@ -313,7 +312,7 @@ bool wxGenericAnimationCtrl::LoadFile(const wxString& filename, wxAnimationType bool wxGenericAnimationCtrl::Load(wxInputStream& stream, wxAnimationType type) { - wxAnimation anim; + wxGenericAnimation anim; if ( !anim.Load(stream, type) || !anim.IsOk() ) return false; @@ -554,7 +553,7 @@ void wxGenericAnimationCtrl::DisplayStaticImage() if (!m_animation.IsOk() || !RebuildBackingStoreUpToFrame(0)) { - m_animation = wxNullAnimation; + m_animation = wxNullGenericAnimation; DisposeToBackground(); } } diff --git a/src/gtk/animate.cpp b/src/gtk/animate.cpp index c39d804dc7..5a1cebb545 100644 --- a/src/gtk/animate.cpp +++ b/src/gtk/animate.cpp @@ -14,7 +14,6 @@ #if wxUSE_ANIMATIONCTRL #include "wx/animate.h" -#if !wxUSE_GENERIC_ANIMATIONCTRL #ifndef WX_PRECOMP #include "wx/image.h" @@ -53,7 +52,6 @@ void gdk_pixbuf_area_updated(GdkPixbufLoader *loader, // wxAnimation //----------------------------------------------------------------------------- -wxIMPLEMENT_DYNAMIC_CLASS(wxAnimation, wxAnimationBase); wxAnimation::wxAnimation(const wxAnimation& that) : base_type(that) @@ -177,11 +175,6 @@ bool wxAnimation::Load(wxInputStream &stream, wxAnimationType type) return data_written; } -wxImage wxAnimation::GetFrame(unsigned int WXUNUSED(frame)) const -{ - return wxNullImage; -} - wxSize wxAnimation::GetSize() const { return wxSize(gdk_pixbuf_animation_get_width(m_pixbuf), @@ -467,5 +460,4 @@ void wxAnimationCtrl::OnTimer(wxTimerEvent& WXUNUSED(ev)) } } -#endif // !wxUSE_GENERIC_ANIMATIONCTRL #endif // wxUSE_ANIMATIONCTRL