#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. More... | |
wxXmlResource (int flags=wxXRC_USE_LOCALE, const wxString &domain=wxEmptyString) | |
Constructor. More... | |
virtual | ~wxXmlResource () |
Destructor. More... | |
void | AddHandler (wxXmlResourceHandler *handler) |
Initializes only a specific handler (or custom handler). More... | |
void | InsertHandler (wxXmlResourceHandler *handler) |
Add a new handler at the begining of the handler list. More... | |
bool | AttachUnknownControl (const wxString &name, wxWindow *control, wxWindow *parent=NULL) |
Attaches an unknown control to the given panel/window/dialog. More... | |
void | ClearHandlers () |
Removes all handlers and deletes them (this means that any handlers added using AddHandler() must be allocated on the heap). More... | |
int | CompareVersion (int major, int minor, int release, int revision) const |
Compares the XRC version to the argument. More... | |
const wxString & | GetDomain () const |
Returns the domain (message catalog) that will be used to load translatable strings in the XRC. More... | |
int | GetFlags () const |
Returns flags, which may be a bitlist of wxXmlResourceFlags enumeration values. More... | |
const wxXmlNode * | GetResourceNode (const wxString &name) const |
Returns the wxXmlNode containing the definition of the object with the given name or NULL. More... | |
long | GetVersion () const |
Returns version information (a.b.c.d = d + 256*c + 2562*b + 2563*a). More... | |
void | InitAllHandlers () |
Initializes handlers for all supported controls/windows. More... | |
bool | Load (const wxString &filemask) |
Loads resources from XML files that match given filemask. More... | |
bool | LoadFile (const wxFileName &file) |
Simpler form of Load() for loading a single XRC file. More... | |
bool | LoadAllFiles (const wxString &dirname) |
Loads all .xrc files from directory dirname. More... | |
wxBitmap | LoadBitmap (const wxString &name) |
Loads a bitmap resource from a file. More... | |
wxDialog * | LoadDialog (wxWindow *parent, const wxString &name) |
Loads a dialog. More... | |
bool | LoadDialog (wxDialog *dlg, wxWindow *parent, const wxString &name) |
Loads a dialog. More... | |
wxFrame * | LoadFrame (wxWindow *parent, const wxString &name) |
Loads a frame from the resource. More... | |
bool | LoadFrame (wxFrame *frame, wxWindow *parent, const wxString &name) |
Loads the contents of a frame onto an existing wxFrame. More... | |
wxIcon | LoadIcon (const wxString &name) |
Loads an icon resource from a file. More... | |
wxMenu * | LoadMenu (const wxString &name) |
Loads menu from resource. More... | |
wxPanel * | LoadPanel (wxWindow *parent, const wxString &name) |
Loads a panel. More... | |
bool | LoadPanel (wxPanel *panel, wxWindow *parent, const wxString &name) |
Loads a panel. More... | |
wxToolBar * | LoadToolBar (wxWindow *parent, const wxString &name) |
Loads a toolbar. More... | |
void | SetDomain (const wxString &domain) |
Sets the domain (message catalog) that will be used to load translatable strings in the XRC. More... | |
void | SetFlags (int flags) |
Sets flags (bitlist of wxXmlResourceFlags enumeration values). More... | |
bool | Unload (const wxString &filename) |
This function unloads a resource previously loaded by Load(). More... | |
wxMenuBar * | LoadMenuBar (wxWindow *parent, const wxString &name) |
Loads a menubar from resource. More... | |
wxMenuBar * | LoadMenuBar (const wxString &name) |
Loads a menubar from resource. More... | |
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. More... | |
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. More... | |
wxObject * | LoadObjectRecursively (wxWindow *parent, const wxString &name, const wxString &classname) |
Load an object from anywhere in the resource tree. More... | |
bool | LoadObjectRecursively (wxObject *instance, wxWindow *parent, const wxString &name, const wxString &classname) |
Load an object from anywhere in the resource tree. More... | |
Public Member Functions inherited from wxObject | |
wxObject () | |
Default ctor; initializes to NULL the internal reference data. More... | |
wxObject (const wxObject &other) | |
Copy ctor. More... | |
virtual | ~wxObject () |
Destructor. More... | |
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). More... | |
wxObjectRefData * | GetRefData () 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=NULL, int lineNum=0) |
The new operator is defined for debugging versions of the library only, when the identifier WXDEBUG is defined. More... | |
Static Public Member Functions | |
static void | AddSubclassFactory (wxXmlSubclassFactory *factory) |
Registers subclasses factory for use in XRC. More... | |
static wxString | FindXRCIDById (int numId) |
Returns a string ID corresponding to the given numeric ID. More... | |
static wxXmlResource * | Get () |
Gets the global resources object or creates one if none exists. More... | |
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. More... | |
static wxXmlResource * | Set (wxXmlResource *res) |
Sets the global resources object and returns a pointer to the previous one (may be NULL). More... | |
Protected Member Functions | |
void | ReportError (const wxXmlNode *context, const wxString &message) |
Reports error in XRC resources to the user. More... | |
virtual void | DoReportError (const wxString &xrcFile, const wxXmlNode *position, const wxString &message) |
Implementation of XRC resources errors reporting. More... | |
Protected Member Functions inherited from wxObject | |
void | AllocExclusive () |
Ensure that this object's data is not shared with any other object. More... | |
virtual wxObjectRefData * | CreateRefData () const |
Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More... | |
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. More... | |
Additional Inherited Members | |
Protected Attributes inherited from wxObject | |
wxObjectRefData * | m_refData |
Pointer to an object which is the object's reference-counted data. More... | |
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).