Version: 3.3.0
wxXmlResourceHandler Class Referenceabstract

#include <wx/xrc/xmlres.h>

+ Inheritance diagram for wxXmlResourceHandler:

Detailed Description

wxSizerXmlHandler is a class for resource handlers capable of creating a wxSizer object from an XML node.

wxXmlResourceHandler is an abstract base class for resource handlers capable of creating a control from an XML node.

See also
wxXmlResourceHandler, wxSizer

Library:  wxXRC
Category:  XML Based Resource System (XRC)

See XML Based Resource System (XRC) for details.

Library:  wxXRC
Category:  XML Based Resource System (XRC)

Public Member Functions

 wxXmlResourceHandler ()
 Default constructor. More...
 
virtual ~wxXmlResourceHandler ()
 Destructor. More...
 
wxObjectCreateResource (wxXmlNode *node, wxObject *parent, wxObject *instance)
 Creates an object (menu, dialog, control, ...) from an XML node. More...
 
virtual wxObjectDoCreateResource ()=0
 Called from CreateResource after variables were filled. More...
 
virtual bool CanHandle (wxXmlNode *node)=0
 Returns true if it understands this node and can create a resource from it, false otherwise. More...
 
void SetParentResource (wxXmlResource *res)
 Sets the parent resource. More...
 
- Public Member Functions inherited from wxObject
 wxObject ()
 Default ctor; initializes to nullptr the internal reference data. More...
 
 wxObject (const wxObject &other)
 Copy ctor. More...
 
virtual ~wxObject ()
 Destructor. More...
 
virtual wxClassInfoGetClassInfo () const
 This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More...
 
wxObjectRefDataGetRefData () const
 Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More...
 
bool IsKindOf (const wxClassInfo *info) const
 Determines whether this class is a subclass of (or the same class as) the given class. More...
 
bool IsSameAs (const wxObject &obj) const
 Returns true if this object has the same data pointer as obj. More...
 
void Ref (const wxObject &clone)
 Makes this object refer to the data in clone. More...
 
void SetRefData (wxObjectRefData *data)
 Sets the wxObject::m_refData pointer. More...
 
void UnRef ()
 Decrements the reference count in the associated data, and if it is zero, deletes the data. More...
 
void UnShare ()
 This is the same of AllocExclusive() but this method is public. More...
 
void operator delete (void *buf)
 The delete operator is defined for debugging versions of the library only, when the identifier __WXDEBUG__ is defined. More...
 
void * operator new (size_t size, const wxString &filename=nullptr, int lineNum=0)
 The new operator is defined for debugging versions of the library only, when the identifier __WXDEBUG__ is defined. More...
 

Protected Member Functions

void AddStyle (const wxString &name, int value)
 Add a style flag (e.g. More...
 
void AddWindowStyles ()
 Add styles common to all wxWindow-derived classes. More...
 
void CreateChildren (wxObject *parent, bool this_hnd_only=false)
 Creates children. More...
 
void CreateChildrenPrivately (wxObject *parent, wxXmlNode *rootnode=nullptr)
 Helper function. More...
 
wxObjectCreateResFromNode (wxXmlNode *node, wxObject *parent, wxObject *instance=nullptr)
 Creates a resource from a node. More...
 
wxAnimationGetAnimation (const wxString &param="animation", wxAnimationCtrlBase *ctrl=nullptr)
 Creates an animation (see wxAnimation) from the filename specified in param. More...
 
wxBitmap GetBitmap (const wxString &param="bitmap", const wxArtClient &defaultArtClient=wxART_OTHER, wxSize size=wxDefaultSize)
 Gets a bitmap. More...
 
wxBitmap GetBitmap (const wxXmlNode *node, const wxArtClient &defaultArtClient=wxART_OTHER, wxSize size=wxDefaultSize)
 Gets a bitmap from an XmlNode. More...
 
wxBitmapBundle GetBitmapBundle (const wxString &param="bitmap", const wxArtClient &defaultArtClient=wxART_OTHER, wxSize size=wxDefaultSize)
 Gets a bitmap bundle. More...
 
wxBitmapBundle GetBitmapBundle (const wxXmlNode *node, const wxArtClient &defaultArtClient=wxART_OTHER, wxSize size=wxDefaultSize)
 Gets a bitmap bundle from the provided node. More...
 
bool GetBool (const wxString &param, bool defaultv=false)
 Gets a bool flag (1, t, yes, on, true are true, everything else is false). More...
 
wxColour GetColour (const wxString &param, const wxColour &defaultLight=wxNullColour, const wxColour &defaultDark=wxNullColour)
 Gets colour from the given parameter. More...
 
wxFileSystemGetCurFileSystem ()
 Returns the current file system. More...
 
wxCoord GetDimension (const wxString &param, wxCoord defaultv=0, wxWindow *windowToUse=nullptr)
 Gets a dimension (may be in dialog units). More...
 
wxDirection GetDirection (const wxString &param, wxDirection dirDefault=wxLEFT)
 Gets a direction. More...
 
wxFont GetFont (const wxString &param="font")
 Gets a font. More...
 
int GetID ()
 Returns the XRCID. More...
 
wxIcon GetIcon (const wxString &param="icon", const wxArtClient &defaultArtClient=wxART_OTHER, wxSize size=wxDefaultSize)
 Returns an icon. More...
 
wxIcon GetIcon (const wxXmlNode *node, const wxArtClient &defaultArtClient=wxART_OTHER, wxSize size=wxDefaultSize)
 Gets an icon from an XmlNode. More...
 
wxIconBundle GetIconBundle (const wxString &param, const wxArtClient &defaultArtClient=wxART_OTHER)
 Returns an icon bundle. More...
 
wxImageListGetImageList (const wxString &param="imagelist")
 Creates an image list from the param markup data. More...
 
long GetLong (const wxString &param, long defaultv=0)
 Gets the integer value from the parameter. More...
 
float GetFloat (const wxString &param, float defaultv=0)
 Gets a float value from the parameter. More...
 
wxString GetName ()
 Returns the resource name. More...
 
bool IsObjectNode (const wxXmlNode *node) const
 Checks if the given node is an object node. More...
 
wxString GetNodeName (wxXmlNode *node) const
 Returns the node name. More...
 
wxString GetNodeAttribute (const wxXmlNode *node, const wxString &attrName, const wxString &defaultValue={}) const
 Gets the node attribute value. More...
 
wxString GetNodeContent (wxXmlNode *node) const
 Gets node content from wxXML_ENTITY_NODE. More...
 
wxXmlNodeGetNodeParent (const wxXmlNode *node) const
 Gets the parent of the node given. More...
 
wxXmlNodeGetNodeNext (const wxXmlNode *node) const
 Gets the next sibling node related to the given node, possibly nullptr. More...
 
wxXmlNodeGetNodeChildren (const wxXmlNode *node) const
 Gets the first child of the given node or nullptr. More...
 
wxXmlNodeGetParamNode (const wxString &param)
 Finds the node or returns nullptr. More...
 
wxString GetParamValue (const wxString &param)
 Finds the parameter value or returns the empty string. More...
 
wxString GetParamValue (const wxXmlNode *node)
 Returns the node parameter value. More...
 
wxPoint GetPosition (const wxString &param="pos", wxWindow *windowToUse=nullptr)
 Gets the position (may be in dialog units). More...
 
wxSize GetSize (const wxString &param="size", wxWindow *windowToUse=nullptr)
 Gets the size (may be in dialog units). More...
 
int GetStyle (const wxString &param="style", int defaults=0)
 Gets style flags from text in form "flag | flag2| flag3 |..." Only understands flags added with AddStyle(). More...
 
wxString GetText (const wxString &param, bool translate=true)
 Gets text from param and does some conversions: More...
 
wxString GetFilePath (const wxXmlNode *node)
 Gets a file path from the given node. More...
 
bool HasParam (const wxString &param)
 Check to see if a parameter exists. More...
 
bool IsOfClass (wxXmlNode *node, const wxString &classname)
 Convenience function. More...
 
void SetupWindow (wxWindow *wnd)
 Sets common window options. More...
 
void ReportError (wxXmlNode *context, const wxString &message)
 Reports error in XRC resources to the user. More...
 
void ReportError (const wxString &message)
 Like ReportError(wxXmlNode*, const wxString&), but uses the node of currently processed object (m_node) as the context. More...
 
void ReportParamError (const wxString &param, const wxString &message)
 Like ReportError(wxXmlNode*, const wxString&), but uses the node of parameter param of the currently processed object as the context. More...
 
wxXmlResourceGetResource () const
 After CreateResource has been called this will return the current wxXmlResource object. More...
 
wxXmlNodeGetNode () const
 After CreateResource has been called this will return the XML node being processed. More...
 
wxString GetClass () const
 After CreateResource has been called this will return the class name of the XML resource node being processed. More...
 
wxObjectGetParent () const
 After CreateResource has been called this will return the current item's parent, if any. More...
 
wxObjectGetInstance () const
 After CreateResource has been called this will return the instance that the XML resource content should be created upon, if it has already been created. More...
 
wxWindowGetParentAsWindow () const
 After CreateResource has been called this will return the item's parent as a wxWindow. More...
 
- Protected Member Functions inherited from wxObject
void AllocExclusive ()
 Ensure that this object's data is not shared with any other object. More...
 
virtual wxObjectRefDataCreateRefData () const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More...
 
virtual wxObjectRefDataCloneRefData (const wxObjectRefData *data) const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More...
 

Additional Inherited Members

- Protected Attributes inherited from wxObject
wxObjectRefDatam_refData
 Pointer to an object which is the object's reference-counted data. More...
 

Constructor & Destructor Documentation

◆ wxXmlResourceHandler()

wxXmlResourceHandler::wxXmlResourceHandler ( )

Default constructor.

◆ ~wxXmlResourceHandler()

virtual wxXmlResourceHandler::~wxXmlResourceHandler ( )
virtual

Destructor.

Member Function Documentation

◆ AddStyle()

void wxXmlResourceHandler::AddStyle ( const wxString name,
int  value 
)
protected

Add a style flag (e.g.

wxMB_DOCKABLE) to the list of flags understood by this handler.

◆ AddWindowStyles()

void wxXmlResourceHandler::AddWindowStyles ( )
protected

Add styles common to all wxWindow-derived classes.

◆ CanHandle()

virtual bool wxXmlResourceHandler::CanHandle ( wxXmlNode node)
pure virtual

Returns true if it understands this node and can create a resource from it, false otherwise.

Note
You must not call any wxXmlResourceHandler methods except IsOfClass() from this method! The instance is not yet initialized with node data at the time CanHandle() is called and it is only safe to operate on node directly or to call IsOfClass().

Implemented in wxSizerXmlHandler.

◆ CreateChildren()

void wxXmlResourceHandler::CreateChildren ( wxObject parent,
bool  this_hnd_only = false 
)
protected

Creates children.

◆ CreateChildrenPrivately()

void wxXmlResourceHandler::CreateChildrenPrivately ( wxObject parent,
wxXmlNode rootnode = nullptr 
)
protected

Helper function.

◆ CreateResFromNode()

wxObject* wxXmlResourceHandler::CreateResFromNode ( wxXmlNode node,
wxObject parent,
wxObject instance = nullptr 
)
protected

Creates a resource from a node.

◆ CreateResource()

wxObject* wxXmlResourceHandler::CreateResource ( wxXmlNode node,
wxObject parent,
wxObject instance 
)

Creates an object (menu, dialog, control, ...) from an XML node.

Should check for validity. parent is a higher-level object (usually window, dialog or panel) that is often necessary to create the resource.

If instance is non-null it should not create a new instance via 'new' but should rather use this one, and call its Create method.

◆ DoCreateResource()

virtual wxObject* wxXmlResourceHandler::DoCreateResource ( )
pure virtual

Called from CreateResource after variables were filled.

Implemented in wxSizerXmlHandler.

◆ GetAnimation()

wxAnimation* wxXmlResourceHandler::GetAnimation ( const wxString param = "animation",
wxAnimationCtrlBase *  ctrl = nullptr 
)
protected

Creates an animation (see wxAnimation) from the filename specified in param.

It is recommended to provide 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.

◆ GetBitmap() [1/2]

wxBitmap wxXmlResourceHandler::GetBitmap ( const wxString param = "bitmap",
const wxArtClient defaultArtClient = wxART_OTHER,
wxSize  size = wxDefaultSize 
)
protected

Gets a bitmap.

◆ GetBitmap() [2/2]

wxBitmap wxXmlResourceHandler::GetBitmap ( const wxXmlNode node,
const wxArtClient defaultArtClient = wxART_OTHER,
wxSize  size = wxDefaultSize 
)
protected

Gets a bitmap from an XmlNode.

Since
2.9.1

◆ GetBitmapBundle() [1/2]

wxBitmapBundle wxXmlResourceHandler::GetBitmapBundle ( const wxString param = "bitmap",
const wxArtClient defaultArtClient = wxART_OTHER,
wxSize  size = wxDefaultSize 
)
protected

Gets a bitmap bundle.

Since
3.1.6

◆ GetBitmapBundle() [2/2]

wxBitmapBundle wxXmlResourceHandler::GetBitmapBundle ( const wxXmlNode node,
const wxArtClient defaultArtClient = wxART_OTHER,
wxSize  size = wxDefaultSize 
)
protected

Gets a bitmap bundle from the provided node.

Since
3.1.6

◆ GetBool()

bool wxXmlResourceHandler::GetBool ( const wxString param,
bool  defaultv = false 
)
protected

Gets a bool flag (1, t, yes, on, true are true, everything else is false).

◆ GetClass()

wxString wxXmlResourceHandler::GetClass ( ) const
protected

After CreateResource has been called this will return the class name of the XML resource node being processed.

Since
2.9.5

◆ GetColour()

wxColour wxXmlResourceHandler::GetColour ( const wxString param,
const wxColour defaultLight = wxNullColour,
const wxColour defaultDark = wxNullColour 
)
protected

Gets colour from the given parameter.

If the colour is not specified, returns defaultLight or defaultDark if the application is using dark mode.

Parameter defaultDark is only available since wxWidgets 3.3.0.

◆ GetCurFileSystem()

wxFileSystem& wxXmlResourceHandler::GetCurFileSystem ( )
protected

Returns the current file system.

◆ GetDimension()

wxCoord wxXmlResourceHandler::GetDimension ( const wxString param,
wxCoord  defaultv = 0,
wxWindow windowToUse = nullptr 
)
protected

Gets a dimension (may be in dialog units).

◆ GetDirection()

wxDirection wxXmlResourceHandler::GetDirection ( const wxString param,
wxDirection  dirDefault = wxLEFT 
)
protected

Gets a direction.

If the given param is not present or has empty value, dirDefault is returned by default. Otherwise the value of the parameter is parsed and a warning is generated if it's not one of wxLEFT, wxTOP, wxRIGHT or wxBOTTOM.

Since
2.9.3

◆ GetFilePath()

wxString wxXmlResourceHandler::GetFilePath ( const wxXmlNode node)
protected

Gets a file path from the given node.

This function expands environment variables in the path if wxXRC_USE_ENVVARS is used.

Since
3.1.3

◆ GetFloat()

float wxXmlResourceHandler::GetFloat ( const wxString param,
float  defaultv = 0 
)
protected

Gets a float value from the parameter.

◆ GetFont()

wxFont wxXmlResourceHandler::GetFont ( const wxString param = "font")
protected

Gets a font.

◆ GetIcon() [1/2]

wxIcon wxXmlResourceHandler::GetIcon ( const wxString param = "icon",
const wxArtClient defaultArtClient = wxART_OTHER,
wxSize  size = wxDefaultSize 
)
protected

Returns an icon.

◆ GetIcon() [2/2]

wxIcon wxXmlResourceHandler::GetIcon ( const wxXmlNode node,
const wxArtClient defaultArtClient = wxART_OTHER,
wxSize  size = wxDefaultSize 
)
protected

Gets an icon from an XmlNode.

Since
2.9.1

◆ GetIconBundle()

wxIconBundle wxXmlResourceHandler::GetIconBundle ( const wxString param,
const wxArtClient defaultArtClient = wxART_OTHER 
)
protected

Returns an icon bundle.

Note
Bundles can be loaded either with stock IDs or from files that contain more than one image (e.g. Windows icon files). If a file contains only single image, a bundle with only one icon will be created.
Since
2.9.0

◆ GetID()

int wxXmlResourceHandler::GetID ( )
protected

Returns the XRCID.

◆ GetImageList()

wxImageList* wxXmlResourceHandler::GetImageList ( const wxString param = "imagelist")
protected

Creates an image list from the param markup data.

Returns
The new instance of wxImageList or nullptr if no data is found.
Since
2.9.1

◆ GetInstance()

wxObject* wxXmlResourceHandler::GetInstance ( ) const
protected

After CreateResource has been called this will return the instance that the XML resource content should be created upon, if it has already been created.

If nullptr then the handler should create the object itself.

Since
2.9.5

◆ GetLong()

long wxXmlResourceHandler::GetLong ( const wxString param,
long  defaultv = 0 
)
protected

Gets the integer value from the parameter.

◆ GetName()

wxString wxXmlResourceHandler::GetName ( )
protected

Returns the resource name.

◆ GetNode()

wxXmlNode* wxXmlResourceHandler::GetNode ( ) const
protected

After CreateResource has been called this will return the XML node being processed.

Since
2.9.5

◆ GetNodeAttribute()

wxString wxXmlResourceHandler::GetNodeAttribute ( const wxXmlNode node,
const wxString attrName,
const wxString defaultValue = {} 
) const
protected

Gets the node attribute value.

If node is nullptr or the attribute is not present, returns defaultValue.

Since
3.3.0

◆ GetNodeChildren()

wxXmlNode* wxXmlResourceHandler::GetNodeChildren ( const wxXmlNode node) const
protected

Gets the first child of the given node or nullptr.

This method is safe to call with nullptr argument, it just returns nullptr in this case.

Since
3.1.0

◆ GetNodeContent()

wxString wxXmlResourceHandler::GetNodeContent ( wxXmlNode node) const
protected

Gets node content from wxXML_ENTITY_NODE.

◆ GetNodeName()

wxString wxXmlResourceHandler::GetNodeName ( wxXmlNode node) const
protected

Returns the node name.

Returns empty string if node is nullptr.

Since
3.3.0

◆ GetNodeNext()

wxXmlNode* wxXmlResourceHandler::GetNodeNext ( const wxXmlNode node) const
protected

Gets the next sibling node related to the given node, possibly nullptr.

This method is safe to call with nullptr argument, it just returns nullptr in this case.

Since
3.1.0

◆ GetNodeParent()

wxXmlNode* wxXmlResourceHandler::GetNodeParent ( const wxXmlNode node) const
protected

Gets the parent of the node given.

This method is safe to call with nullptr argument, it just returns nullptr in this case.

Since
3.1.0

◆ GetParamNode()

wxXmlNode* wxXmlResourceHandler::GetParamNode ( const wxString param)
protected

Finds the node or returns nullptr.

◆ GetParamValue() [1/2]

wxString wxXmlResourceHandler::GetParamValue ( const wxString param)
protected

Finds the parameter value or returns the empty string.

◆ GetParamValue() [2/2]

wxString wxXmlResourceHandler::GetParamValue ( const wxXmlNode node)
protected

Returns the node parameter value.

Since
2.9.1

◆ GetParent()

wxObject* wxXmlResourceHandler::GetParent ( ) const
protected

After CreateResource has been called this will return the current item's parent, if any.

Since
2.9.5

◆ GetParentAsWindow()

wxWindow* wxXmlResourceHandler::GetParentAsWindow ( ) const
protected

After CreateResource has been called this will return the item's parent as a wxWindow.

Since
2.9.5

◆ GetPosition()

wxPoint wxXmlResourceHandler::GetPosition ( const wxString param = "pos",
wxWindow windowToUse = nullptr 
)
protected

Gets the position (may be in dialog units).

The windowToUse argument is only available since wxWidgets 3.3.0.

◆ GetResource()

wxXmlResource* wxXmlResourceHandler::GetResource ( ) const
protected

After CreateResource has been called this will return the current wxXmlResource object.

Since
2.9.5

◆ GetSize()

wxSize wxXmlResourceHandler::GetSize ( const wxString param = "size",
wxWindow windowToUse = nullptr 
)
protected

Gets the size (may be in dialog units).

◆ GetStyle()

int wxXmlResourceHandler::GetStyle ( const wxString param = "style",
int  defaults = 0 
)
protected

Gets style flags from text in form "flag | flag2| flag3 |..." Only understands flags added with AddStyle().

◆ GetText()

wxString wxXmlResourceHandler::GetText ( const wxString param,
bool  translate = true 
)
protected

Gets text from param and does some conversions:

  • replaces \n, \r, \t by respective characters (according to C syntax)
  • replaces $ by and $$ by $ (needed for _File to File translation because of XML syntax)
  • calls wxGetTranslations (unless disabled in wxXmlResource)

◆ HasParam()

bool wxXmlResourceHandler::HasParam ( const wxString param)
protected

Check to see if a parameter exists.

◆ IsObjectNode()

bool wxXmlResourceHandler::IsObjectNode ( const wxXmlNode node) const
protected

Checks if the given node is an object node.

Object nodes are those named "object" or "object_ref".

Since
3.1.0

◆ IsOfClass()

bool wxXmlResourceHandler::IsOfClass ( wxXmlNode node,
const wxString classname 
)
protected

Convenience function.

Returns true if the node has a property class equal to classname, e.g. object class="wxDialog".

◆ ReportError() [1/2]

void wxXmlResourceHandler::ReportError ( const wxString message)
protected

Like ReportError(wxXmlNode*, const wxString&), but uses the node of currently processed object (m_node) as the context.

Since
2.9.0

◆ ReportError() [2/2]

void wxXmlResourceHandler::ReportError ( wxXmlNode context,
const wxString message 
)
protected

Reports error in XRC resources to the user.

See wxXmlResource::ReportError() for more information.

Since
2.9.0

◆ ReportParamError()

void wxXmlResourceHandler::ReportParamError ( const wxString param,
const wxString message 
)
protected

Like ReportError(wxXmlNode*, const wxString&), but uses the node of parameter param of the currently processed object as the context.

This is convenience function for reporting errors in particular parameters.

Since
2.9.0

◆ SetParentResource()

void wxXmlResourceHandler::SetParentResource ( wxXmlResource res)

Sets the parent resource.

◆ SetupWindow()

void wxXmlResourceHandler::SetupWindow ( wxWindow wnd)
protected

Sets common window options.