Use GetAnimation() in wxAnimationCtrlXmlHandler again
This function basically only exists in order to be used in this handler, so extend it to allow doing it by adding wxAnimationCtrlBase argument to it, allowing it to create wxAnimation object compatible with the given control. This reduces code duplication and, incidentally, makes GetAnimation() more useful for any user-defined XRC handlers.
This commit is contained in:
@@ -591,8 +591,10 @@ public:
|
|||||||
wxImageList *GetImageList(const wxString& param = wxT("imagelist")) wxOVERRIDE;
|
wxImageList *GetImageList(const wxString& param = wxT("imagelist")) wxOVERRIDE;
|
||||||
|
|
||||||
#if wxUSE_ANIMATIONCTRL
|
#if wxUSE_ANIMATIONCTRL
|
||||||
// Gets an animation.
|
// Gets an animation creating it using the provided control (so that it
|
||||||
wxAnimation* GetAnimation(const wxString& param = wxT("animation")) wxOVERRIDE;
|
// will be compatible with it) if any.
|
||||||
|
wxAnimation* GetAnimation(const wxString& param = wxT("animation"),
|
||||||
|
wxAnimationCtrlBase* ctrl = NULL) wxOVERRIDE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Gets a font.
|
// Gets a font.
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
#include "wx/window.h"
|
#include "wx/window.h"
|
||||||
|
|
||||||
class WXDLLIMPEXP_FWD_CORE wxAnimation;
|
class WXDLLIMPEXP_FWD_CORE wxAnimation;
|
||||||
|
class WXDLLIMPEXP_FWD_CORE wxAnimationCtrlBase;
|
||||||
|
|
||||||
class WXDLLIMPEXP_FWD_XML wxXmlNode;
|
class WXDLLIMPEXP_FWD_XML wxXmlNode;
|
||||||
class WXDLLIMPEXP_FWD_XML wxXmlResource;
|
class WXDLLIMPEXP_FWD_XML wxXmlResource;
|
||||||
@@ -100,7 +101,8 @@ public:
|
|||||||
virtual wxImageList *GetImageList(const wxString& param = wxT("imagelist")) = 0;
|
virtual wxImageList *GetImageList(const wxString& param = wxT("imagelist")) = 0;
|
||||||
|
|
||||||
#if wxUSE_ANIMATIONCTRL
|
#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
|
#endif
|
||||||
|
|
||||||
virtual wxFont GetFont(const wxString& param = wxT("font"), wxWindow* parent = NULL) = 0;
|
virtual wxFont GetFont(const wxString& param = wxT("font"), wxWindow* parent = NULL) = 0;
|
||||||
@@ -353,9 +355,10 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if wxUSE_ANIMATIONCTRL
|
#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
|
#endif
|
||||||
|
|
||||||
|
@@ -542,8 +542,15 @@ protected:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Creates an animation (see wxAnimation) from the filename specified in @a param.
|
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.
|
Gets a bitmap.
|
||||||
|
@@ -60,37 +60,9 @@ wxObject *wxAnimationCtrlXmlHandler::DoCreateResource()
|
|||||||
if ( GetBool("hidden", 0) == 1 )
|
if ( GetBool("hidden", 0) == 1 )
|
||||||
ctrl->Hide();
|
ctrl->Hide();
|
||||||
|
|
||||||
const wxString aniParam = "animation";
|
wxScopedPtr<wxAnimation> animation(GetAnimation("animation", ctrl));
|
||||||
wxString path = GetFilePath(GetParamNode(aniParam));
|
if ( animation )
|
||||||
// load the animation from file
|
ctrl->SetAnimation(*animation);
|
||||||
if ( !path.empty() )
|
|
||||||
{
|
|
||||||
wxAnimation ani = ctrl->CreateAnimation();
|
|
||||||
#if wxUSE_FILESYSTEM
|
|
||||||
wxScopedPtr<wxFSFile> 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
|
// if no inactive-bitmap has been provided, GetBitmap() will return wxNullBitmap
|
||||||
// which just tells wxAnimationCtrl to use the default for inactive status
|
// which just tells wxAnimationCtrl to use the default for inactive status
|
||||||
@@ -107,14 +79,16 @@ bool wxAnimationCtrlXmlHandler::CanHandle(wxXmlNode *node)
|
|||||||
IsOfClass(node, wxT("wxGenericAnimationCtrl"));
|
IsOfClass(node, wxT("wxGenericAnimationCtrl"));
|
||||||
}
|
}
|
||||||
|
|
||||||
wxAnimation* wxXmlResourceHandlerImpl::GetAnimation(const wxString& param)
|
wxAnimation* wxXmlResourceHandlerImpl::GetAnimation(const wxString& param,
|
||||||
|
wxAnimationCtrlBase* ctrl)
|
||||||
{
|
{
|
||||||
wxString name = GetFilePath(GetParamNode(param));
|
wxString name = GetFilePath(GetParamNode(param));
|
||||||
if ( name.empty() )
|
if ( name.empty() )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
// load the animation from file
|
// load the animation from file
|
||||||
wxScopedPtr<wxAnimation> ani(new wxAnimation);
|
wxScopedPtr<wxAnimation> ani(ctrl ? new wxAnimation(ctrl->CreateAnimation())
|
||||||
|
: new wxAnimation);
|
||||||
#if wxUSE_FILESYSTEM
|
#if wxUSE_FILESYSTEM
|
||||||
wxFSFile * const
|
wxFSFile * const
|
||||||
fsfile = GetCurFileSystem().OpenFile(name, wxFS_READ | wxFS_SEEKABLE);
|
fsfile = GetCurFileSystem().OpenFile(name, wxFS_READ | wxFS_SEEKABLE);
|
||||||
|
Reference in New Issue
Block a user