diff --git a/include/wx/xrc/xmlres.h b/include/wx/xrc/xmlres.h index 984536230f..9b74828fc2 100644 --- a/include/wx/xrc/xmlres.h +++ b/include/wx/xrc/xmlres.h @@ -591,8 +591,10 @@ public: wxImageList *GetImageList(const wxString& param = wxT("imagelist")) wxOVERRIDE; #if wxUSE_ANIMATIONCTRL - // Gets an animation. - wxAnimation* GetAnimation(const wxString& param = wxT("animation")) wxOVERRIDE; + // Gets an animation creating it using the provided control (so that it + // will be compatible with it) if any. + wxAnimation* GetAnimation(const wxString& param = wxT("animation"), + wxAnimationCtrlBase* ctrl = NULL) wxOVERRIDE; #endif // Gets a font. diff --git a/include/wx/xrc/xmlreshandler.h b/include/wx/xrc/xmlreshandler.h index c4630915ac..b478356d6d 100644 --- a/include/wx/xrc/xmlreshandler.h +++ b/include/wx/xrc/xmlreshandler.h @@ -22,6 +22,7 @@ #include "wx/window.h" class WXDLLIMPEXP_FWD_CORE wxAnimation; +class WXDLLIMPEXP_FWD_CORE wxAnimationCtrlBase; class WXDLLIMPEXP_FWD_XML wxXmlNode; class WXDLLIMPEXP_FWD_XML wxXmlResource; @@ -100,7 +101,8 @@ public: virtual wxImageList *GetImageList(const wxString& param = wxT("imagelist")) = 0; #if wxUSE_ANIMATIONCTRL - virtual wxAnimation* GetAnimation(const wxString& param = wxT("animation")) = 0; + virtual wxAnimation* GetAnimation(const wxString& param = wxT("animation"), + wxAnimationCtrlBase* ctrl = NULL) = 0; #endif virtual wxFont GetFont(const wxString& param = wxT("font"), wxWindow* parent = NULL) = 0; @@ -353,9 +355,10 @@ protected: } #if wxUSE_ANIMATIONCTRL - wxAnimation* GetAnimation(const wxString& param = wxT("animation")) + wxAnimation* GetAnimation(const wxString& param = wxT("animation"), + wxAnimationCtrlBase* ctrl = NULL) { - return GetImpl()->GetAnimation(param); + return GetImpl()->GetAnimation(param, ctrl); } #endif diff --git a/interface/wx/xrc/xmlres.h b/interface/wx/xrc/xmlres.h index 0c625ce724..9feca5980f 100644 --- a/interface/wx/xrc/xmlres.h +++ b/interface/wx/xrc/xmlres.h @@ -542,8 +542,15 @@ protected: /** Creates an animation (see wxAnimation) from the filename specified in @a param. + + It is recommended to provide @a ctrl argument to this function (which + is only available in wxWidgets 3.1.4 or later) to make sure that the + created animation is compatible with the specified control, otherwise a + wxAnimation object compatible with the default wxAnimationCtrl + implementation is created. */ - wxAnimation* GetAnimation(const wxString& param = "animation"); + wxAnimation* GetAnimation(const wxString& param = "animation", + wxAnimationCtrlBase* ctrl = NULL); /** Gets a bitmap. diff --git a/src/xrc/xh_animatctrl.cpp b/src/xrc/xh_animatctrl.cpp index fb98705bf7..d75502b1ce 100644 --- a/src/xrc/xh_animatctrl.cpp +++ b/src/xrc/xh_animatctrl.cpp @@ -60,37 +60,9 @@ wxObject *wxAnimationCtrlXmlHandler::DoCreateResource() if ( GetBool("hidden", 0) == 1 ) ctrl->Hide(); - 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) - ); - } - } + wxScopedPtr animation(GetAnimation("animation", ctrl)); + if ( animation ) + ctrl->SetAnimation(*animation); // if no inactive-bitmap has been provided, GetBitmap() will return wxNullBitmap // which just tells wxAnimationCtrl to use the default for inactive status @@ -107,14 +79,16 @@ bool wxAnimationCtrlXmlHandler::CanHandle(wxXmlNode *node) IsOfClass(node, wxT("wxGenericAnimationCtrl")); } -wxAnimation* wxXmlResourceHandlerImpl::GetAnimation(const wxString& param) +wxAnimation* wxXmlResourceHandlerImpl::GetAnimation(const wxString& param, + wxAnimationCtrlBase* ctrl) { wxString name = GetFilePath(GetParamNode(param)); if ( name.empty() ) return NULL; // load the animation from file - wxScopedPtr ani(new wxAnimation); + wxScopedPtr ani(ctrl ? new wxAnimation(ctrl->CreateAnimation()) + : new wxAnimation); #if wxUSE_FILESYSTEM wxFSFile * const fsfile = GetCurFileSystem().OpenFile(name, wxFS_READ | wxFS_SEEKABLE);