diff --git a/samples/xrc/myframe.cpp b/samples/xrc/myframe.cpp index 7fcf80ccbb..70ebe38069 100644 --- a/samples/xrc/myframe.cpp +++ b/samples/xrc/myframe.cpp @@ -52,6 +52,7 @@ #include "objrefdlg.h" // For functions to manipulate the corresponding controls. #include "wx/animate.h" +#include "wx/generic/animate.h" #include "wx/infobar.h" #include "wx/treectrl.h" #include "wx/listctrl.h" @@ -206,14 +207,17 @@ void MyFrame::OnAnimationCtrlPlay(wxCommandEvent& event) wxWindow *win = btn->GetParent(); wxAnimationCtrl *ctrl = XRCCTRL(*win, "controls_animation_ctrl", wxAnimationCtrl); + wxGenericAnimationCtrl *generic = + XRCCTRL(*win, "controls_generic_animation_ctrl", wxGenericAnimationCtrl); if (ctrl->IsPlaying()) { ctrl->Stop(); + generic->Stop(); btn->SetLabel("Play"); } else { - if (ctrl->Play()) + if ( ctrl->Play() && generic->Play() ) btn->SetLabel("Stop"); else wxLogError("Cannot play the animation..."); diff --git a/samples/xrc/rc/controls.xrc b/samples/xrc/rc/controls.xrc index 993b2a2441..13f0d85e4a 100644 --- a/samples/xrc/rc/controls.xrc +++ b/samples/xrc/rc/controls.xrc @@ -68,7 +68,7 @@ 2 - 1 + 2 0 0 0,1 @@ -91,6 +91,17 @@ + + + + wxALIGN_CENTRE|wxALL + 5 + + throbber.gif + stop.xpm + + + diff --git a/src/xrc/xh_animatctrl.cpp b/src/xrc/xh_animatctrl.cpp index d2e8444352..b34874c25c 100644 --- a/src/xrc/xh_animatctrl.cpp +++ b/src/xrc/xh_animatctrl.cpp @@ -18,6 +18,7 @@ #include "wx/xrc/xh_animatctrl.h" #include "wx/animate.h" +#include "wx/generic/animate.h" #include "wx/scopedptr.h" wxIMPLEMENT_DYNAMIC_CLASS(wxAnimationCtrlXmlHandler, wxXmlResourceHandler); @@ -31,16 +32,65 @@ wxAnimationCtrlXmlHandler::wxAnimationCtrlXmlHandler() : wxXmlResourceHandler() wxObject *wxAnimationCtrlXmlHandler::DoCreateResource() { - XRC_MAKE_INSTANCE(ctrl, wxAnimationCtrl) + wxAnimationCtrlBase *ctrl = NULL; + if ( m_instance ) + ctrl = wxStaticCast(m_instance, wxAnimationCtrlBase); - wxScopedPtr animation(GetAnimation(wxT("animation"))); + if ( !ctrl ) + { + if ( m_class == "wxAnimationCtrl" ) + { + ctrl = new wxAnimationCtrl(m_parentAsWindow, + GetID(), + wxNullAnimation, + GetPosition(), GetSize(), + GetStyle("style", wxAC_DEFAULT_STYLE), + GetName()); + } + else + { + ctrl = new wxGenericAnimationCtrl(m_parentAsWindow, + GetID(), + wxNullAnimation, + GetPosition(), GetSize(), + GetStyle("style", wxAC_DEFAULT_STYLE), + GetName()); + } + } + if ( GetBool("hidden", 0) == 1 ) + ctrl->Hide(); - ctrl->Create(m_parentAsWindow, - GetID(), - animation ? *animation : wxNullAnimation, - GetPosition(), GetSize(), - GetStyle(wxT("style"), wxAC_DEFAULT_STYLE), - GetName()); + const wxString aniParam = "animation"; + wxString path = GetFilePath(GetParamNode(aniParam)); + // load the animation from file + if ( !path.empty() ) + { + wxAnimation ani = ctrl->CreateAnimation(); +#if wxUSE_FILESYSTEM + wxScopedPtr fsfile( + GetCurFileSystem().OpenFile(path, wxFS_READ | wxFS_SEEKABLE) + ); + if (fsfile) + { + ani.Load(*fsfile->GetStream()); + } +#else + ani.LoadFile(name); +#endif + + if ( ani.IsOk() ) + { + ctrl->SetAnimation(ani); + } + else + { + ReportParamError + ( + aniParam, + wxString::Format("cannot create animation from \"%s\"", path) + ); + } + } // if no inactive-bitmap has been provided, GetBitmap() will return wxNullBitmap // which just tells wxAnimationCtrl to use the default for inactive status @@ -53,7 +103,8 @@ wxObject *wxAnimationCtrlXmlHandler::DoCreateResource() bool wxAnimationCtrlXmlHandler::CanHandle(wxXmlNode *node) { - return IsOfClass(node, wxT("wxAnimationCtrl")); + return IsOfClass(node, wxT("wxAnimationCtrl")) || + IsOfClass(node, wxT("wxGenericAnimationCtrl")); } #endif // wxUSE_XRC && wxUSE_ANIMATIONCTRL