From 9e29cd0a2896d37d609bfa92216041589b26c931 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sat, 21 Oct 2006 13:59:25 +0000 Subject: [PATCH] [ 1581391 ] wxAnimationCtrl XRC handler (most of) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42196 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- build/bakefiles/files.bkl | 2 ++ include/wx/xrc/xh_all.h | 1 + include/wx/xrc/xh_animatctrl.h | 30 ++++++++++++++++++ include/wx/xrc/xmlres.h | 8 +++++ src/xrc/xh_animatctrl.cpp | 57 ++++++++++++++++++++++++++++++++++ src/xrc/xmlres.cpp | 33 ++++++++++++++++++++ src/xrc/xmlrsall.cpp | 3 ++ 7 files changed, 134 insertions(+) create mode 100644 include/wx/xrc/xh_animatctrl.h create mode 100644 src/xrc/xh_animatctrl.cpp diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl index d02d1fde70..465904f3a0 100644 --- a/build/bakefiles/files.bkl +++ b/build/bakefiles/files.bkl @@ -2920,6 +2920,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! + src/xrc/xh_animatctrl.cpp src/xrc/xh_bmp.cpp src/xrc/xh_bmpcbox.cpp src/xrc/xh_bmpbt.cpp @@ -2975,6 +2976,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! wx/xrc/xh_all.h + wx/xrc/xh_animatctrl.h wx/xrc/xh_bmpbt.h wx/xrc/xh_bmp.h wx/xrc/xh_bmpcbox.h diff --git a/include/wx/xrc/xh_all.h b/include/wx/xrc/xh_all.h index 4e4922ef20..d3364fc18e 100644 --- a/include/wx/xrc/xh_all.h +++ b/include/wx/xrc/xh_all.h @@ -64,5 +64,6 @@ #include "wx/xrc/xh_dirpicker.h" #include "wx/xrc/xh_hyperlink.h" #include "wx/xrc/xh_bmpcbox.h" +#include "wx/xrc/xh_animatctrl.h" #endif // _WX_XH_ALL_H_ diff --git a/include/wx/xrc/xh_animatctrl.h b/include/wx/xrc/xh_animatctrl.h new file mode 100644 index 0000000000..4831187453 --- /dev/null +++ b/include/wx/xrc/xh_animatctrl.h @@ -0,0 +1,30 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: wx/xrc/xh_animatctrl.h +// Purpose: XML resource handler for wxAnimationCtrl +// Author: Francesco Montorsi +// Created: 2006-10-15 +// RCS-ID: $Id$ +// Copyright: (c) 2006 Francesco Montorsi +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_XH_ANIMATIONCTRL_H_ +#define _WX_XH_ANIMATIONCTRL_H_ + +#include "wx/xrc/xmlres.h" + +#if wxUSE_XRC && wxUSE_ANIMATIONCTRL + +class WXDLLIMPEXP_XRC wxAnimationCtrlXmlHandler : public wxXmlResourceHandler +{ + DECLARE_DYNAMIC_CLASS(wxAnimationCtrlXmlHandler) + +public: + wxAnimationCtrlXmlHandler(); + virtual wxObject *DoCreateResource(); + virtual bool CanHandle(wxXmlNode *node); +}; + +#endif // wxUSE_XRC && wxUSE_ANIMATIONCTRL + +#endif // _WX_XH_ANIMATIONCTRL_H_ diff --git a/include/wx/xrc/xmlres.h b/include/wx/xrc/xmlres.h index 0c9a105cf4..c581aafc8b 100644 --- a/include/wx/xrc/xmlres.h +++ b/include/wx/xrc/xmlres.h @@ -25,6 +25,7 @@ #include "wx/icon.h" #include "wx/artprov.h" #include "wx/colour.h" +#include "wx/animate.h" #include "wx/xml/xml.h" @@ -127,6 +128,8 @@ public: // Destructor. virtual ~wxXmlResource(); + wxXmlNode *GetFirstRoot(); + // Loads resources from XML files that match given filemask. // This method understands VFS (see filesys.h). bool Load(const wxString& filemask); @@ -450,6 +453,11 @@ protected: const wxArtClient& defaultArtClient = wxART_OTHER, wxSize size = wxDefaultSize); +#if wxUSE_ANIMATIONCTRL + // Gets an animation. + wxAnimation GetAnimation(const wxString& param = wxT("animation")); +#endif + // Gets a font. wxFont GetFont(const wxString& param = wxT("font")); diff --git a/src/xrc/xh_animatctrl.cpp b/src/xrc/xh_animatctrl.cpp new file mode 100644 index 0000000000..78e53e09d0 --- /dev/null +++ b/src/xrc/xh_animatctrl.cpp @@ -0,0 +1,57 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: src/xrc/xh_animatctrl.cpp +// Purpose: XML resource handler for wxAnimationCtrl +// Author: Francesco Montorsi +// Created: 2006-10-15 +// RCS-ID: $Id$ +// Copyright: (c) 2006 Francesco Montorsi +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#if wxUSE_XRC && wxUSE_ANIMATIONCTRL + +#include "wx/xrc/xh_animatctrl.h" +#include "wx/animate.h" + +IMPLEMENT_DYNAMIC_CLASS(wxAnimationCtrlXmlHandler, wxXmlResourceHandler) + +wxAnimationCtrlXmlHandler::wxAnimationCtrlXmlHandler() : wxXmlResourceHandler() +{ + XRC_ADD_STYLE(wxAC_NO_AUTORESIZE); + XRC_ADD_STYLE(wxAC_DEFAULT_STYLE); + AddWindowStyles(); +} + +wxObject *wxAnimationCtrlXmlHandler::DoCreateResource() +{ + XRC_MAKE_INSTANCE(ctrl, wxAnimationCtrl) + + ctrl->Create(m_parentAsWindow, + GetID(), + GetAnimation(wxT("animation")), + GetPosition(), GetSize(), + GetStyle(_T("style"), wxAC_DEFAULT_STYLE), + GetName()); + + // if no inactive-bitmap has been provided, GetBitmap() will return wxNullBitmap + // which just tells wxAnimationCtrl to use the default for inactive status + ctrl->SetInactiveBitmap(GetBitmap(wxT("inactive-bitmap"))); + + SetupWindow(ctrl); + + return ctrl; +} + +bool wxAnimationCtrlXmlHandler::CanHandle(wxXmlNode *node) +{ + return IsOfClass(node, wxT("wxAnimationCtrl")); +} + +#endif // wxUSE_XRC && wxUSE_ANIMATIONCTRL diff --git a/src/xrc/xmlres.cpp b/src/xrc/xmlres.cpp index 17ee409812..c2aa6a5586 100644 --- a/src/xrc/xmlres.cpp +++ b/src/xrc/xmlres.cpp @@ -1139,6 +1139,39 @@ wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param, return wxBitmap(img); } +#if wxUSE_ANIMATIONCTRL +wxAnimation wxXmlResourceHandler::GetAnimation(const wxString& param) +{ + wxAnimation ani; + + /* load the animation from file: */ + wxString name = GetParamValue(param); + if (name.empty()) return wxNullAnimation; +#if wxUSE_FILESYSTEM + wxFSFile *fsfile = GetCurFileSystem().OpenFile(name); + if (fsfile == NULL) + { + wxLogError(_("XRC resource: Cannot create animation from '%s'."), + name.c_str()); + return wxNullAnimation; + } + ani.Load(*(fsfile->GetStream())); + delete fsfile; +#else + ani.LoadFile(name); +#endif + + if (!ani.IsOk()) + { + wxLogError(_("XRC resource: Cannot create animation from '%s'."), + name.c_str()); + return wxNullAnimation; + } + + return ani; +} +#endif // wxUSE_ANIMATIONCTRL + wxIcon wxXmlResourceHandler::GetIcon(const wxString& param, diff --git a/src/xrc/xmlrsall.cpp b/src/xrc/xmlrsall.cpp index c87da9a592..01cd0874d1 100644 --- a/src/xrc/xmlrsall.cpp +++ b/src/xrc/xmlrsall.cpp @@ -167,6 +167,9 @@ void wxXmlResource::InitAllHandlers() #if wxUSE_HYPERLINKCTRL AddHandler( new wxHyperlinkCtrlXmlHandler); #endif +#if wxUSE_ANIMATIONCTRL + AddHandler( new wxAnimationCtrlXmlHandler); +#endif } #endif // wxUSE_XRC -- 2.45.2