From c2f12218ce9231e0d21a0d5516fcaa7df3e0a2a0 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Tue, 10 Oct 2006 04:27:54 +0000 Subject: [PATCH] wxAnimationCtrl cleanup git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41852 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/animatctrl.tex | 4 +- docs/latex/wx/animation.tex | 6 +-- include/wx/animate.h | 12 ++--- include/wx/animdecod.h | 6 ++- include/wx/generic/animate.h | 32 +------------- include/wx/gtk/animate.h | 64 ++++++++------------------- src/generic/animateg.cpp | 34 ++++++++------ src/gtk/animate.cpp | 86 ++++++++++++++++++++++++++++++++---- 8 files changed, 130 insertions(+), 114 deletions(-) diff --git a/docs/latex/wx/animatctrl.tex b/docs/latex/wx/animatctrl.tex index d66bac7f0c..021dbfc37a 100644 --- a/docs/latex/wx/animatctrl.tex +++ b/docs/latex/wx/animatctrl.tex @@ -34,8 +34,8 @@ It is only available if \texttt{wxUSE\_ANIMATIONCTRL} is set to $1$ (the default \twocolwidtha{5cm}% \begin{twocollist}\itemsep=0pt -\twocolitem{\windowstyle{wxAC\_DEFAULT\_STYLE}}{The default style: wxNO_BORDER.} -\twocolitem{\windowstyle{wxAC\_NO_AUTORESIZE}}{By default, the control will adjust +\twocolitem{\windowstyle{wxAC\_DEFAULT\_STYLE}}{The default style: wxNO\_BORDER.} +\twocolitem{\windowstyle{wxAC\_NO\_AUTORESIZE}}{By default, the control will adjust its size to exactly fit to the size of the animation when \helpref{SetAnimation}{wxanimationctrlsetanimation} is called. If this style flag is given, the control will not change its size} \end{twocollist} diff --git a/docs/latex/wx/animation.tex b/docs/latex/wx/animation.tex index 298c9f1df4..9e3e6df825 100644 --- a/docs/latex/wx/animation.tex +++ b/docs/latex/wx/animation.tex @@ -68,7 +68,7 @@ data be deleted. \membersection{wxAnimation::GetDelay}\label{wxanimationgetdelay} -\constfunc{int}{GetDelay}{\param{size_t }{i}} +\constfunc{int}{GetDelay}{\param{size\_t }{i}} Returns the delay for the i-th frame in milliseconds. If {\tt -1} is returned the frame is to be displayed forever. @@ -76,14 +76,14 @@ If {\tt -1} is returned the frame is to be displayed forever. \membersection{wxAnimation::GetFrameCount}\label{wxanimationgetframecount} -\constfunc{size_t}{GetFrameCount}{\void} +\constfunc{size\_t}{GetFrameCount}{\void} Returns the number of frames for this animation. \membersection{wxAnimation::GetFrame}\label{wxanimationgetframe} -\constfunc{wxImage}{GetFrame}{\param{size_t }{i}} +\constfunc{wxImage}{GetFrame}{\param{size\_t }{i}} Returns the i-th frame as a \helpref{wxImage}{wximage}. diff --git a/include/wx/animate.h b/include/wx/animate.h index c10a05ba47..b9cde65251 100644 --- a/include/wx/animate.h +++ b/include/wx/animate.h @@ -16,15 +16,9 @@ #if wxUSE_ANIMATIONCTRL -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "wx/animdecod.h" +#include "wx/control.h" +#include "wx/timer.h" class WXDLLIMPEXP_ADV wxAnimation; diff --git a/include/wx/animdecod.h b/include/wx/animdecod.h index eeae13b1cc..4e89b4f9e9 100644 --- a/include/wx/animdecod.h +++ b/include/wx/animdecod.h @@ -14,9 +14,11 @@ #if wxUSE_STREAMS && wxUSE_GIF -#include "wx/stream.h" -#include "wx/image.h" #include "wx/colour.h" +#include "wx/gdicmn.h" + +class WXDLLIMPEXP_BASE wxInputStream; +class WXDLLIMPEXP_CORE wxImage; /* diff --git a/include/wx/generic/animate.h b/include/wx/generic/animate.h index 8b9dc20120..2b84863e40 100644 --- a/include/wx/generic/animate.h +++ b/include/wx/generic/animate.h @@ -12,23 +12,6 @@ #ifndef _WX_GENERIC_ANIMATEH__ #define _WX_GENERIC_ANIMATEH__ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class WXDLLIMPEXP_ADV wxAnimationBase; -class WXDLLIMPEXP_ADV wxAnimationPlayer; -class WXDLLEXPORT wxImage; -class WXDLLEXPORT wxGIFDecoder; -class WXDLLIMPEXP_ADV wxAnimation; - - // ---------------------------------------------------------------------------- // wxAnimation // ---------------------------------------------------------------------------- @@ -38,17 +21,6 @@ WX_DECLARE_LIST(wxAnimationDecoder, wxAnimationDecoderList); class WXDLLIMPEXP_ADV wxAnimation : public wxAnimationBase { public: - wxAnimation(const wxAnimation &tocopy) - { Ref(tocopy); } - wxAnimation() {} - ~wxAnimation() { UnRef(); } - - wxAnimation &operator= (const wxAnimation &tocopy) - { - Ref(tocopy); - return *this; - } - bool operator == (const wxAnimation& anim) const { return m_refData == anim.m_refData; } bool operator != (const wxAnimation& anim) const @@ -83,7 +55,6 @@ public: static void CleanUpHandlers(); static void InitStandardHandlers(); -protected: DECLARE_DYNAMIC_CLASS(wxAnimation) }; @@ -95,7 +66,7 @@ protected: class WXDLLIMPEXP_ADV wxAnimationCtrl: public wxAnimationCtrlBase { public: - wxAnimationCtrl() {} + wxAnimationCtrl(); wxAnimationCtrl(wxWindow *parent, wxWindowID id, const wxAnimation& anim = wxNullAnimation, @@ -182,6 +153,7 @@ protected: // on the screen private: + typedef wxAnimationCtrlBase base_type; DECLARE_DYNAMIC_CLASS(wxAnimationCtrl) DECLARE_EVENT_TABLE() }; diff --git a/include/wx/gtk/animate.h b/include/wx/gtk/animate.h index 6e4704a42c..6e43a643c9 100644 --- a/include/wx/gtk/animate.h +++ b/include/wx/gtk/animate.h @@ -12,8 +12,8 @@ #ifndef _WX_GTKANIMATEH__ #define _WX_GTKANIMATEH__ -#include "wx/defs.h" -#include +typedef struct _GdkPixbufAnimation GdkPixbufAnimation; +typedef struct _GdkPixbufAnimationIter GdkPixbufAnimationIter; // ---------------------------------------------------------------------------- // wxAnimation @@ -27,19 +27,11 @@ class WXDLLEXPORT wxAnimation : public wxAnimationBase { public: - wxAnimation(const wxAnimation &tocopy) - { m_pixbuf=tocopy.m_pixbuf; if (m_pixbuf) g_object_ref(m_pixbuf); } - wxAnimation(GdkPixbufAnimation *p = NULL) - { m_pixbuf=p; } - ~wxAnimation() - { UnRef(); } - - wxAnimation &operator= (const wxAnimation &tocopy) - { - m_pixbuf=tocopy.m_pixbuf; - if (m_pixbuf) g_object_ref(m_pixbuf); - return *this; - } + wxAnimation(GdkPixbufAnimation *p = NULL) { m_pixbuf = p; } + wxAnimation(const wxAnimation&); + ~wxAnimation() { UnRef(); } + + wxAnimation& operator= (const wxAnimation&); bool operator == (const wxAnimation& anim) const { return m_pixbuf == anim.m_pixbuf; } @@ -54,34 +46,24 @@ public: virtual size_t GetFrameCount() const { return 0; } - virtual wxImage GetFrame(size_t i) const - { return wxNullImage; } + virtual wxImage GetFrame(size_t i) const; // we can retrieve the delay for a frame only after building // a GdkPixbufAnimationIter... virtual int GetDelay(size_t i) const { return 0; } - virtual wxSize GetSize() const - { return wxSize(gdk_pixbuf_animation_get_width(m_pixbuf), - gdk_pixbuf_animation_get_height(m_pixbuf)); } + virtual wxSize GetSize() const; virtual bool LoadFile(const wxString &name, wxAnimationType type = wxANIMATION_TYPE_ANY); virtual bool Load(wxInputStream &stream, wxAnimationType type = wxANIMATION_TYPE_ANY); - void UnRef() - { - if (m_pixbuf) - g_object_unref(m_pixbuf); - m_pixbuf = NULL; - } - + // Implementation public: // used by GTK callbacks GdkPixbufAnimation *GetPixbuf() const { return m_pixbuf; } - void SetPixbuf(GdkPixbufAnimation *p) - { m_pixbuf=p; if (m_pixbuf) g_object_ref(m_pixbuf); } + void SetPixbuf(GdkPixbufAnimation* p); protected: GdkPixbufAnimation *m_pixbuf; @@ -89,12 +71,14 @@ protected: // used temporary by Load() //bool m_bLoadComplete; -protected: +private: + void UnRef(); + + typedef wxAnimationBase base_type; DECLARE_DYNAMIC_CLASS(wxAnimation) }; - // ---------------------------------------------------------------------------- // wxAnimationCtrl // ---------------------------------------------------------------------------- @@ -105,7 +89,7 @@ protected: class WXDLLIMPEXP_ADV wxAnimationCtrl: public wxAnimationCtrlBase { public: - wxAnimationCtrl() {} + wxAnimationCtrl(); wxAnimationCtrl(wxWindow *parent, wxWindowID id, const wxAnimation& anim = wxNullAnimation, @@ -151,19 +135,8 @@ protected: void FitToAnimation(); void ClearToBackgroundColour(); - void ResetAnim() - { - if (m_anim) - g_object_unref(m_anim); - m_anim = NULL; - } - - void ResetIter() - { - if (m_iter) - g_object_unref(m_iter); - m_iter = NULL; - } + void ResetAnim(); + void ResetIter(); protected: // internal vars @@ -174,6 +147,7 @@ protected: // internal vars bool m_bPlaying; private: + typedef wxAnimationCtrlBase base_type; DECLARE_DYNAMIC_CLASS(wxAnimationCtrl) DECLARE_EVENT_TABLE() }; diff --git a/src/generic/animateg.cpp b/src/generic/animateg.cpp index d03b9b2dbc..124f394071 100644 --- a/src/generic/animateg.cpp +++ b/src/generic/animateg.cpp @@ -15,28 +15,28 @@ #pragma hdrstop #endif //__BORLANDC__ - #if wxUSE_ANIMATIONCTRL -#include "wx/log.h" +#include "wx/animate.h" + +#ifndef WX_PRECOMP + #include "wx/log.h" + #include "wx/image.h" + #include "wx/dcmemory.h" + #include "wx/dcclient.h" + #include "wx/module.h" +#endif + #include "wx/wfstream.h" -#include "wx/image.h" #include "wx/gifdecod.h" #include "wx/anidecod.h" -#include "wx/dcmemory.h" -#include "wx/dc.h" -#include "wx/dcclient.h" -#include "wx/animate.h" -#include "wx/animdecod.h" - -#include +#include "wx/listimpl.cpp" WX_DEFINE_LIST(wxAnimationDecoderList); wxAnimationDecoderList wxAnimation::sm_handlers; - // ---------------------------------------------------------------------------- // wxAnimation // ---------------------------------------------------------------------------- @@ -244,8 +244,6 @@ public: IMPLEMENT_DYNAMIC_CLASS(wxAnimationModule, wxModule) - - // ---------------------------------------------------------------------------- // wxAnimationCtrl // ---------------------------------------------------------------------------- @@ -257,6 +255,14 @@ BEGIN_EVENT_TABLE(wxAnimationCtrl, wxAnimationCtrlBase) EVT_TIMER(wxID_ANY, wxAnimationCtrl::OnTimer) END_EVENT_TABLE() +wxAnimationCtrl::wxAnimationCtrl() +{ + m_currentFrame = 0; + m_looped = false; + m_isPlaying = false; + m_useWinBackgroundColour = false; +} + bool wxAnimationCtrl::Create(wxWindow *parent, wxWindowID id, const wxAnimation& animation, const wxPoint& pos, const wxSize& size, long style, const wxString& name) @@ -268,7 +274,7 @@ bool wxAnimationCtrl::Create(wxWindow *parent, wxWindowID id, m_useWinBackgroundColour = false; m_timer.SetOwner(this); - if (!wxControl::Create(parent, id, pos, size, style, wxDefaultValidator, name)) + if (!base_type::Create(parent, id, pos, size, style, wxDefaultValidator, name)) return false; // by default we get the same background colour of our parent diff --git a/src/gtk/animate.cpp b/src/gtk/animate.cpp index 27e535f8ef..1eb6239e95 100644 --- a/src/gtk/animate.cpp +++ b/src/gtk/animate.cpp @@ -9,20 +9,20 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #if wxUSE_ANIMATIONCTRL #include "wx/animate.h" -#include "wx/log.h" + +#ifndef WX_PRECOMP + #include "wx/image.h" + #include "wx/log.h" + #include "wx/stream.h" +#endif + #include -#include // ============================================================================ @@ -51,6 +51,27 @@ void gdk_pixbuf_area_updated(GdkPixbufLoader *loader, IMPLEMENT_DYNAMIC_CLASS(wxAnimation, wxAnimationBase) +wxAnimation::wxAnimation(const wxAnimation& that) + : base_type(that) +{ + m_pixbuf = that.m_pixbuf; + if (m_pixbuf) + g_object_ref(m_pixbuf); +} + +wxAnimation& wxAnimation::operator=(const wxAnimation& that) +{ + if (this != &that) + { + base_type::operator=(that); + UnRef(); + m_pixbuf = that.m_pixbuf; + if (m_pixbuf) + g_object_ref(m_pixbuf); + } + return *this; +} + bool wxAnimation::LoadFile(const wxString &name, wxAnimationType WXUNUSED(type)) { UnRef(); @@ -75,6 +96,7 @@ bool wxAnimation::Load(wxInputStream &stream, wxAnimationType type) break; default: + anim_type[0] = '\0'; break; } @@ -100,7 +122,7 @@ bool wxAnimation::Load(wxInputStream &stream, wxAnimationType type) while (stream.IsOk()) { // read a chunk of data - stream.Read(buf, 2048); + stream.Read(buf, sizeof(buf)); // fetch all data into the loader if (!gdk_pixbuf_loader_write(loader, buf, stream.LastRead(), &error)) @@ -123,6 +145,31 @@ bool wxAnimation::Load(wxInputStream &stream, wxAnimationType type) return true; } +wxImage wxAnimation::GetFrame(size_t i) const +{ + return wxNullImage; +} + +wxSize wxAnimation::GetSize() const +{ + return wxSize(gdk_pixbuf_animation_get_width(m_pixbuf), + gdk_pixbuf_animation_get_height(m_pixbuf)); +} + +void wxAnimation::UnRef() +{ + if (m_pixbuf) + g_object_unref(m_pixbuf); + m_pixbuf = NULL; +} + +void wxAnimation::SetPixbuf(GdkPixbufAnimation* p) +{ + UnRef(); + m_pixbuf = p; + if (m_pixbuf) + g_object_ref(m_pixbuf); +} //----------------------------------------------------------------------------- // wxAnimationCtrl @@ -133,6 +180,13 @@ BEGIN_EVENT_TABLE(wxAnimationCtrl, wxAnimationCtrlBase) EVT_TIMER(wxID_ANY, wxAnimationCtrl::OnTimer) END_EVENT_TABLE() +wxAnimationCtrl::wxAnimationCtrl() +{ + m_anim = NULL; + m_iter = NULL; + m_bPlaying = false; +} + bool wxAnimationCtrl::Create( wxWindow *parent, wxWindowID id, const wxAnimation& anim, const wxPoint& pos, @@ -144,7 +198,7 @@ bool wxAnimationCtrl::Create( wxWindow *parent, wxWindowID id, m_acceptsFocus = true; if (!PreCreation( parent, pos, size ) || - !wxControl::CreateBase(parent, id, pos, size, style & wxWINDOW_STYLE_MASK, + !base_type::CreateBase(parent, id, pos, size, style & wxWINDOW_STYLE_MASK, wxDefaultValidator, name)) { wxFAIL_MSG( wxT("wxAnimationCtrl creation failed") ); @@ -234,6 +288,20 @@ void wxAnimationCtrl::FitToAnimation() SetSize(w, h); } +void wxAnimationCtrl::ResetAnim() +{ + if (m_anim) + g_object_unref(m_anim); + m_anim = NULL; +} + +void wxAnimationCtrl::ResetIter() +{ + if (m_iter) + g_object_unref(m_iter); + m_iter = NULL; +} + bool wxAnimationCtrl::Play() { if (m_anim == NULL) -- 2.47.2