#include <wx/xrc/xmlres.h>
This is the main class for interacting with the XML-based resource system.
The class holds XML resources from one or more .xml files, binary files or zip archive files.
Note that this is a singleton class and you'll never allocate/deallocate it. Just use the static wxXmlResource::Get() getter.
Public Member Functions | |
wxXmlResource (const wxString &filemask, int flags=wxXRC_USE_LOCALE, const wxString &domain=wxEmptyString) | |
Constructor. | |
wxXmlResource (int flags=wxXRC_USE_LOCALE, const wxString &domain=wxEmptyString) | |
Constructor. | |
virtual | ~wxXmlResource () |
Destructor. | |
void | AddHandler (wxXmlResourceHandler *handler) |
Initializes only a specific handler (or custom handler). | |
void | InsertHandler (wxXmlResourceHandler *handler) |
Add a new handler at the begining of the handler list. | |
bool | AttachUnknownControl (const wxString &name, wxWindow *control, wxWindow *parent=NULL) |
Attaches an unknown control to the given panel/window/dialog. | |
void | ClearHandlers () |
Removes all handlers and deletes them (this means that any handlers added using AddHandler() must be allocated on the heap). | |
int | CompareVersion (int major, int minor, int release, int revision) const |
Compares the XRC version to the argument. | |
const wxString & | GetDomain () const |
Returns the domain (message catalog) that will be used to load translatable strings in the XRC. | |
int | GetFlags () const |
Returns flags, which may be a bitlist of wxXmlResourceFlags enumeration values. | |
const wxXmlNode * | GetResourceNode (const wxString &name) const |
Returns the wxXmlNode containing the definition of the object with the given name or NULL. | |
long | GetVersion () const |
Returns version information (a.b.c.d = d + 256*c + 2562*b + 2563*a). | |
void | InitAllHandlers () |
Initializes handlers for all supported controls/windows. | |
bool | Load (const wxString &filemask) |
Loads resources from XML files that match given filemask. | |
bool | LoadFile (const wxFileName &file) |
Simpler form of Load() for loading a single XRC file. | |
bool | LoadAllFiles (const wxString &dirname) |
Loads all .xrc files from directory dirname. | |
wxBitmap | LoadBitmap (const wxString &name) |
Loads a bitmap resource from a file. | |
wxDialog * | LoadDialog (wxWindow *parent, const wxString &name) |
Loads a dialog. | |
bool | LoadDialog (wxDialog *dlg, wxWindow *parent, const wxString &name) |
Loads a dialog. | |
wxFrame * | LoadFrame (wxWindow *parent, const wxString &name) |
Loads a frame from the resource. | |
bool | LoadFrame (wxFrame *frame, wxWindow *parent, const wxString &name) |
Loads the contents of a frame onto an existing wxFrame. | |
wxIcon | LoadIcon (const wxString &name) |
Loads an icon resource from a file. | |
wxMenu * | LoadMenu (const wxString &name) |
Loads menu from resource. | |
wxPanel * | LoadPanel (wxWindow *parent, const wxString &name) |
Loads a panel. | |
bool | LoadPanel (wxPanel *panel, wxWindow *parent, const wxString &name) |
Loads a panel. | |
wxToolBar * | LoadToolBar (wxWindow *parent, const wxString &name) |
Loads a toolbar. | |
void | SetDomain (const wxString &domain) |
Sets the domain (message catalog) that will be used to load translatable strings in the XRC. | |
void | SetFlags (int flags) |
Sets flags (bitlist of wxXmlResourceFlags enumeration values). | |
bool | Unload (const wxString &filename) |
This function unloads a resource previously loaded by Load(). | |
wxMenuBar * | LoadMenuBar (wxWindow *parent, const wxString &name) |
Loads a menubar from resource. | |
wxMenuBar * | LoadMenuBar (const wxString &name) |
Loads a menubar from resource. | |
wxObject * | LoadObject (wxWindow *parent, const wxString &name, const wxString &classname) |
Load an object from the resource specifying both the resource name and the class name. | |
bool | LoadObject (wxObject *instance, wxWindow *parent, const wxString &name, const wxString &classname) |
Load an object from the resource specifying both the resource name and the class name. | |
wxObject * | LoadObjectRecursively (wxWindow *parent, const wxString &name, const wxString &classname) |
Load an object from anywhere in the resource tree. | |
bool | LoadObjectRecursively (wxObject *instance, wxWindow *parent, const wxString &name, const wxString &classname) |
Load an object from anywhere in the resource tree. | |
Public Member Functions inherited from wxObject | |
wxObject () | |
Default ctor; initializes to NULL the internal reference data. | |
wxObject (const wxObject &other) | |
Copy ctor. | |
virtual | ~wxObject () |
Destructor. | |
virtual wxClassInfo * | GetClassInfo () const |
This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). | |
wxObjectRefData * | GetRefData () const |
Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. | |
bool | IsKindOf (const wxClassInfo *info) const |
Determines whether this class is a subclass of (or the same class as) the given class. | |
bool | IsSameAs (const wxObject &obj) const |
Returns true if this object has the same data pointer as obj. | |
void | Ref (const wxObject &clone) |
Makes this object refer to the data in clone. | |
void | SetRefData (wxObjectRefData *data) |
Sets the wxObject::m_refData pointer. | |
void | UnRef () |
Decrements the reference count in the associated data, and if it is zero, deletes the data. | |
void | UnShare () |
This is the same of AllocExclusive() but this method is public. | |
void | operator delete (void *buf) |
The delete operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined. | |
void * | operator new (size_t size, const wxString &filename=NULL, int lineNum=0) |
The new operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined. | |
Static Public Member Functions | |
static void | AddSubclassFactory (wxXmlSubclassFactory *factory) |
Registers subclasses factory for use in XRC. | |
static wxString | FindXRCIDById (int numId) |
Returns a string ID corresponding to the given numeric ID. | |
static wxXmlResource * | Get () |
Gets the global resources object or creates one if none exists. | |
static int | GetXRCID (const wxString &str_id, int value_if_not_found=wxID_NONE) |
Returns a numeric ID that is equivalent to the string ID used in an XML resource. | |
static wxXmlResource * | Set (wxXmlResource *res) |
Sets the global resources object and returns a pointer to the previous one (may be NULL). | |
Protected Member Functions | |
void | ReportError (const wxXmlNode *context, const wxString &message) |
Reports error in XRC resources to the user. | |
virtual void | DoReportError (const wxString &xrcFile, const wxXmlNode *position, const wxString &message) |
Implementation of XRC resources errors reporting. | |
Protected Member Functions inherited from wxObject | |
void | AllocExclusive () |
Ensure that this object's data is not shared with any other object. | |
virtual wxObjectRefData * | CreateRefData () const |
Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. | |
virtual wxObjectRefData * | CloneRefData (const wxObjectRefData *data) const |
Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. | |
Additional Inherited Members | |
Protected Attributes inherited from wxObject | |
wxObjectRefData * | m_refData |
Pointer to an object which is the object's reference-counted data. | |
wxXmlResource::wxXmlResource | ( | const wxString & | filemask, |
int | flags = wxXRC_USE_LOCALE , |
||
const wxString & | domain = wxEmptyString |
||
) |
Constructor.
filemask | The XRC file, archive file, or wildcard specification that will be used to load all resource files inside a zip archive. |
flags | One or more value of the wxXmlResourceFlags enumeration. |
domain | The name of the gettext catalog to search for translatable strings. By default all loaded catalogs will be searched. This provides a way to allow the strings to only come from a specific catalog. |
wxXmlResource::wxXmlResource | ( | int | flags = wxXRC_USE_LOCALE , |
const wxString & | domain = wxEmptyString |
||
) |
Constructor.
flags | One or more value of the wxXmlResourceFlags enumeration. |
domain | The name of the gettext catalog to search for translatable strings. By default all loaded catalogs will be searched. This provides a way to allow the strings to only come from a specific catalog. |
|
virtual |
Destructor.
void wxXmlResource::AddHandler | ( | wxXmlResourceHandler * | handler | ) |
Initializes only a specific handler (or custom handler).
Convention says that the handler name is equal to the control's name plus 'XmlHandler', for example wxTextCtrlXmlHandler, wxHtmlWindowXmlHandler.
The XML resource compiler (wxxrc) can create include file that contains initialization code for all controls used within the resource. Note that this handler must be allocated on the heap, since it will be deleted by ClearHandlers() later.
|
static |
Registers subclasses factory for use in XRC.
This is useful only for language bindings developers who need a way to implement subclassing in wxWidgets ports that don't support wxRTTI (e.g. wxPython).
bool wxXmlResource::AttachUnknownControl | ( | const wxString & | name, |
wxWindow * | control, | ||
wxWindow * | parent = NULL |
||
) |
Attaches an unknown control to the given panel/window/dialog.
Unknown controls are used in conjunction with <object class="unknown">.
void wxXmlResource::ClearHandlers | ( | ) |
Removes all handlers and deletes them (this means that any handlers added using AddHandler() must be allocated on the heap).
int wxXmlResource::CompareVersion | ( | int | major, |
int | minor, | ||
int | release, | ||
int | revision | ||
) | const |
Compares the XRC version to the argument.
Returns -1 if the XRC version is less than the argument, +1 if greater, and 0 if they are equal.
|
protectedvirtual |
Implementation of XRC resources errors reporting.
This method is called by ReportError() and shouldn't be called directly; use ReportError() or wxXmlResourceHandler::ReportError() to log errors.
Default implementation uses wxLogError().
xrcFile | File the error occurred in or empty string if it couldn't be determined. |
position | XML node where the error occurred or NULL if it couldn't be determined. |
message | Text of the error message. See ReportError() documentation for details of the string's format. |
|
static |
Returns a string ID corresponding to the given numeric ID.
The string returned is such that calling GetXRCID() with it as parameter yields numId. If there is no string identifier corresponding to the given numeric one, an empty string is returned.
Notice that, unlike GetXRCID(), this function is slow as it checks all of the identifiers used in XRC.
|
static |
Gets the global resources object or creates one if none exists.
const wxString& wxXmlResource::GetDomain | ( | ) | const |
Returns the domain (message catalog) that will be used to load translatable strings in the XRC.
int wxXmlResource::GetFlags | ( | ) | const |
Returns flags, which may be a bitlist of wxXmlResourceFlags enumeration values.
Returns the wxXmlNode containing the definition of the object with the given name or NULL.
This function recursively searches all the loaded XRC files for an object with the specified name. If the object is found, the wxXmlNode corresponding to it is returned, so this function can be used to access additional information defined in the XRC file and not used by wxXmlResource itself, e.g. contents of application-specific XML tags.
name | The name of the resource which must be unique for this function to work correctly, if there is more than one resource with the given name the choice of the one returned by this function is undefined. |
long wxXmlResource::GetVersion | ( | ) | const |
Returns version information (a.b.c.d = d + 256*c + 2562*b + 2563*a).
|
static |
Returns a numeric ID that is equivalent to the string ID used in an XML resource.
If an unknown str_id is requested (i.e. other than wxID_XXX or integer), a new record is created which associates the given string with a number.
If value_if_not_found is wxID_NONE
, the number is obtained via wxNewId(). Otherwise value_if_not_found is used.
Macro XRCID(name)
is provided for convenient use in event tables.
EVT_*_RANGE
macros, because the order in which they are assigned to symbolic name values is not guaranteed. void wxXmlResource::InitAllHandlers | ( | ) |
Initializes handlers for all supported controls/windows.
This will make the executable quite big because it forces linking against most of the wxWidgets library.
void wxXmlResource::InsertHandler | ( | wxXmlResourceHandler * | handler | ) |
Add a new handler at the begining of the handler list.
bool wxXmlResource::Load | ( | const wxString & | filemask | ) |
Loads resources from XML files that match given filemask.
Example:
bool wxXmlResource::LoadAllFiles | ( | const wxString & | dirname | ) |
Loads all .xrc files from directory dirname.
Tries to load as many files as possible; if there's an error while loading one file, it still attempts to load other files.
Loads a dialog.
parent points to parent window (if any).
Loads a dialog.
parent points to parent window (if any).
This form is used to finish creation of an already existing instance (the main reason for this is that you may want to use derived class with a new event table). Example:
bool wxXmlResource::LoadFile | ( | const wxFileName & | file | ) |
Loads a frame from the resource.
parent points to parent window (if any).
Loads the contents of a frame onto an existing wxFrame.
This form is used to finish creation of an already existing instance (the main reason for this is that you may want to use derived class with a new event table).
Loads menu from resource.
Returns NULL on failure.
Loads a menubar from resource.
Returns NULL on failure.
Loads a menubar from resource.
Returns NULL on failure.
wxObject* wxXmlResource::LoadObject | ( | wxWindow * | parent, |
const wxString & | name, | ||
const wxString & | classname | ||
) |
Load an object from the resource specifying both the resource name and the class name.
The first overload lets you load nonstandard container windows and returns NULL on failure. The second one lets you finish the creation of an existing instance and returns false on failure.
In either case, only the resources defined at the top level of XRC files can be loaded by this function, use LoadObjectRecursively() if you need to load an object defined deeper in the hierarchy.
bool wxXmlResource::LoadObject | ( | wxObject * | instance, |
wxWindow * | parent, | ||
const wxString & | name, | ||
const wxString & | classname | ||
) |
Load an object from the resource specifying both the resource name and the class name.
The first overload lets you load nonstandard container windows and returns NULL on failure. The second one lets you finish the creation of an existing instance and returns false on failure.
In either case, only the resources defined at the top level of XRC files can be loaded by this function, use LoadObjectRecursively() if you need to load an object defined deeper in the hierarchy.
wxObject* wxXmlResource::LoadObjectRecursively | ( | wxWindow * | parent, |
const wxString & | name, | ||
const wxString & | classname | ||
) |
Load an object from anywhere in the resource tree.
These methods are similar to LoadObject() but may be used to load an object from anywhere in the resource tree and not only the top level. Note that you will very rarely need to do this as in normal use the entire container window (defined at the top level) is loaded and not its individual children but this method can be useful in some particular situations.
bool wxXmlResource::LoadObjectRecursively | ( | wxObject * | instance, |
wxWindow * | parent, | ||
const wxString & | name, | ||
const wxString & | classname | ||
) |
Load an object from anywhere in the resource tree.
These methods are similar to LoadObject() but may be used to load an object from anywhere in the resource tree and not only the top level. Note that you will very rarely need to do this as in normal use the entire container window (defined at the top level) is loaded and not its individual children but this method can be useful in some particular situations.
Loads a panel.
parent points to the parent window.
Loads a panel.
parent points to the parent window. This form is used to finish creation of an already existing instance.
Reports error in XRC resources to the user.
Any errors in XRC input files should be reported using this method (or its wxXmlResourceHandler::ReportError() equivalent). Unlike wxLogError(), this method presents the error to the user in a more usable form. In particular, the output is compiler-like and contains information about the exact location of the error.
context | XML node the error occurred in or relates to. This can be NULL, but should be the most specific node possible, as its line number is what is reported to the user. |
message | Text of the error message. This string should always be in English (i.e. not wrapped in _()). It shouldn't be a sentence – it should start with lower-case letter and shouldn't have a trailing period or exclamation point. |
|
static |
Sets the global resources object and returns a pointer to the previous one (may be NULL).
void wxXmlResource::SetDomain | ( | const wxString & | domain | ) |
Sets the domain (message catalog) that will be used to load translatable strings in the XRC.
void wxXmlResource::SetFlags | ( | int | flags | ) |
Sets flags (bitlist of wxXmlResourceFlags enumeration values).