Version: 2.9.4
Public Member Functions | Static Public Member Functions | Protected Member Functions
wxXmlResource Class Reference

#include </home/zeitlin/src/wx/github/interface/wx/xrc/xmlres.h>

Inheritance diagram for wxXmlResource:

Detailed Description

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.

参照:
XML Based Resource System (XRC), XRC File Format

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

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).
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 wxStringGetDomain () 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 wxXmlNodeGetResourceNode (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.
wxDialogLoadDialog (wxWindow *parent, const wxString &name)
 Loads a dialog.
bool LoadDialog (wxDialog *dlg, wxWindow *parent, const wxString &name)
 Loads a dialog.
bool LoadFrame (wxFrame *frame, wxWindow *parent, const wxString &name)
 Loads a frame.
wxIcon LoadIcon (const wxString &name)
 Loads an icon resource from a file.
wxMenuLoadMenu (const wxString &name)
 Loads menu from resource.
wxPanelLoadPanel (wxWindow *parent, const wxString &name)
 Loads a panel.
bool LoadPanel (wxPanel *panel, wxWindow *parent, const wxString &name)
 Loads a panel.
wxToolBarLoadToolBar (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().
wxMenuBarLoadMenuBar (wxWindow *parent, const wxString &name)
 Loads a menubar from resource.
wxMenuBarLoadMenuBar (const wxString &name)
 Loads a menubar from resource.
wxObjectLoadObject (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.
wxObjectLoadObjectRecursively (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.

Static Public Member Functions

static wxString FindXRCIDById (int numId)
 Returns a string ID corresponding to the given numeric ID.
static wxXmlResourceGet ()
 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 wxXmlResourceSet (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.

List of all members.


Constructor & Destructor Documentation

wxXmlResource::wxXmlResource ( const wxString filemask,
int  flags = wxXRC_USE_LOCALE,
const wxString domain = wxEmptyString 
)

Constructor.

Parameters:
filemaskThe XRC file, archive file, or wildcard specification that will be used to load all resource files inside a zip archive.
flagsOne or more value of the wxXmlResourceFlags enumeration.
domainThe 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.

Parameters:
flagsOne or more value of the wxXmlResourceFlags enumeration.
domainThe 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 wxXmlResource::~wxXmlResource ( ) [virtual]

Destructor.


Member Function Documentation

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.

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.

virtual void wxXmlResource::DoReportError ( const wxString xrcFile,
const wxXmlNode position,
const wxString message 
) [protected, virtual]

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().

Parameters:
xrcFileFile the error occurred in or empty string if it couldn't be determined.
positionXML node where the error occurred or NULL if it couldn't be determined.
messageText of the error message. See ReportError() documentation for details of the string's format.
注:
You may override this method in a derived class to customize errors reporting. If you do so, you'll need to either use the derived class in all your code or call wxXmlResource::Set() to change the global wxXmlResource instance to your class.
Since:
2.9.0
参照:
ReportError()
static wxString wxXmlResource::FindXRCIDById ( int  numId) [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.

Since:
2.9.0
static wxXmlResource* wxXmlResource::Get ( ) [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.

const wxXmlNode* wxXmlResource::GetResourceNode ( const wxString name) const

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.

Parameters:
nameThe 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.
Returns:
The node corresponding to the resource with the given name or NULL.
long wxXmlResource::GetVersion ( ) const

Returns version information (a.b.c.d = d + 256*c + 2562*b + 2563*a).

static int wxXmlResource::GetXRCID ( const wxString str_id,
int  value_if_not_found = wxID_NONE 
) [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.

注:
IDs returned by XRCID() cannot be used with the 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.

bool wxXmlResource::Load ( const wxString filemask)

Loads resources from XML files that match given filemask.

例:

            if (!wxXmlResource::Get()->Load("rc/*.xrc"))
                wxLogError("Couldn't load resources!");
注:
If wxUSE_FILESYS is enabled, this method understands wxFileSystem URLs (see wxFileSystem::FindFirst()).
If you are sure that the argument is name of single XRC file (rather than an URL or a wildcard), use LoadFile() instead.
参照:
LoadFile(), LoadAllFiles()
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.

Since:
2.9.0
参照:
LoadFile(), Load()
wxBitmap wxXmlResource::LoadBitmap ( const wxString name)

Loads a bitmap resource from a file.

wxDialog* wxXmlResource::LoadDialog ( wxWindow parent,
const wxString name 
)

Loads a dialog.

parent points to parent window (if any).

bool wxXmlResource::LoadDialog ( wxDialog dlg,
wxWindow parent,
const wxString name 
)

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). 例:

          MyDialog dlg;
          wxXmlResource::Get()->LoadDialog(&dlg, mainFrame, "my_dialog");
          dlg.ShowModal();
bool wxXmlResource::LoadFile ( const wxFileName file)

Simpler form of Load() for loading a single XRC file.

Since:
2.9.0
参照:
Load(), LoadAllFiles()
bool wxXmlResource::LoadFrame ( wxFrame frame,
wxWindow parent,
const wxString name 
)

Loads a frame.

wxIcon wxXmlResource::LoadIcon ( const wxString name)

Loads an icon resource from a file.

wxMenu* wxXmlResource::LoadMenu ( const wxString name)

Loads menu from resource.

Returns NULL on failure.

wxMenuBar* wxXmlResource::LoadMenuBar ( wxWindow parent,
const wxString name 
)

Loads a menubar from resource.

Returns NULL on failure.

wxMenuBar* wxXmlResource::LoadMenuBar ( const wxString name)

Loads a menubar from resource.

Returns NULL on failure.

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::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::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.

Since:
2.9.1
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.

Since:
2.9.1
bool wxXmlResource::LoadPanel ( wxPanel panel,
wxWindow parent,
const wxString name 
)

Loads a panel.

parent points to the parent window. This form is used to finish creation of an already existing instance.

wxPanel* wxXmlResource::LoadPanel ( wxWindow parent,
const wxString name 
)

Loads a panel.

parent points to the parent window.

wxToolBar* wxXmlResource::LoadToolBar ( wxWindow parent,
const wxString name 
)

Loads a toolbar.

void wxXmlResource::ReportError ( const wxXmlNode context,
const wxString message 
) [protected]

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.

Parameters:
contextXML 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.
messageText 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.
Since:
2.9.0
参照:
wxXmlResourceHandler::ReportError(), DoReportError()
static wxXmlResource* wxXmlResource::Set ( wxXmlResource res) [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).

bool wxXmlResource::Unload ( const wxString filename)

This function unloads a resource previously loaded by Load().

Returns true if the resource was successfully unloaded and false if it hasn't been found in the list of loaded resources.

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines