[ 1581391 ] wxAnimationCtrl XRC handler

(most of)


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42196 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2006-10-21 13:59:25 +00:00
parent 8e458bb539
commit 9e29cd0a28
7 changed files with 134 additions and 0 deletions

View File

@@ -2920,6 +2920,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
<!-- ====================================================================== --> <!-- ====================================================================== -->
<set var="XRC_SRC" hints="files"> <set var="XRC_SRC" hints="files">
src/xrc/xh_animatctrl.cpp
src/xrc/xh_bmp.cpp src/xrc/xh_bmp.cpp
src/xrc/xh_bmpcbox.cpp src/xrc/xh_bmpcbox.cpp
src/xrc/xh_bmpbt.cpp src/xrc/xh_bmpbt.cpp
@@ -2975,6 +2976,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
</set> </set>
<set var="XRC_HDR" hints="files"> <set var="XRC_HDR" hints="files">
wx/xrc/xh_all.h wx/xrc/xh_all.h
wx/xrc/xh_animatctrl.h
wx/xrc/xh_bmpbt.h wx/xrc/xh_bmpbt.h
wx/xrc/xh_bmp.h wx/xrc/xh_bmp.h
wx/xrc/xh_bmpcbox.h wx/xrc/xh_bmpcbox.h

View File

@@ -64,5 +64,6 @@
#include "wx/xrc/xh_dirpicker.h" #include "wx/xrc/xh_dirpicker.h"
#include "wx/xrc/xh_hyperlink.h" #include "wx/xrc/xh_hyperlink.h"
#include "wx/xrc/xh_bmpcbox.h" #include "wx/xrc/xh_bmpcbox.h"
#include "wx/xrc/xh_animatctrl.h"
#endif // _WX_XH_ALL_H_ #endif // _WX_XH_ALL_H_

View File

@@ -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_

View File

@@ -25,6 +25,7 @@
#include "wx/icon.h" #include "wx/icon.h"
#include "wx/artprov.h" #include "wx/artprov.h"
#include "wx/colour.h" #include "wx/colour.h"
#include "wx/animate.h"
#include "wx/xml/xml.h" #include "wx/xml/xml.h"
@@ -127,6 +128,8 @@ public:
// Destructor. // Destructor.
virtual ~wxXmlResource(); virtual ~wxXmlResource();
wxXmlNode *GetFirstRoot();
// Loads resources from XML files that match given filemask. // Loads resources from XML files that match given filemask.
// This method understands VFS (see filesys.h). // This method understands VFS (see filesys.h).
bool Load(const wxString& filemask); bool Load(const wxString& filemask);
@@ -450,6 +453,11 @@ protected:
const wxArtClient& defaultArtClient = wxART_OTHER, const wxArtClient& defaultArtClient = wxART_OTHER,
wxSize size = wxDefaultSize); wxSize size = wxDefaultSize);
#if wxUSE_ANIMATIONCTRL
// Gets an animation.
wxAnimation GetAnimation(const wxString& param = wxT("animation"));
#endif
// Gets a font. // Gets a font.
wxFont GetFont(const wxString& param = wxT("font")); wxFont GetFont(const wxString& param = wxT("font"));

57
src/xrc/xh_animatctrl.cpp Normal file
View File

@@ -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

View File

@@ -1139,6 +1139,39 @@ wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param,
return wxBitmap(img); 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, wxIcon wxXmlResourceHandler::GetIcon(const wxString& param,

View File

@@ -167,6 +167,9 @@ void wxXmlResource::InitAllHandlers()
#if wxUSE_HYPERLINKCTRL #if wxUSE_HYPERLINKCTRL
AddHandler( new wxHyperlinkCtrlXmlHandler); AddHandler( new wxHyperlinkCtrlXmlHandler);
#endif #endif
#if wxUSE_ANIMATIONCTRL
AddHandler( new wxAnimationCtrlXmlHandler);
#endif
} }
#endif // wxUSE_XRC #endif // wxUSE_XRC