📄 xmlres.h
字号:
/////////////////////////////////////////////////////////////////////////////// Name: xmlres.h// Purpose: XML resources// Author: Vaclav Slavik// Created: 2000/03/05// RCS-ID: $Id: xmlres.h,v 1.2 2004/09/28 09:04:12 HopeSeekr Exp $// Copyright: (c) 2000 Vaclav Slavik// Licence: wxWindows licence/////////////////////////////////////////////////////////////////////////////#ifndef _WX_XMLRES_H_#define _WX_XMLRES_H_#if defined(__GNUG__) && !defined(__APPLE__)#pragma interface "xmlres.h"#endif#include <list> // Needed for std::list#include <vector> // Needed for std::vector#include "wx/defs.h"#include "wx/string.h"#include "wx/dynarray.h"#include "wx/datetime.h"#include "wx/gdicmn.h"#include "wx/filesys.h"#include "wx/bitmap.h"#include "wx/icon.h"#include "wx/artprov.h"#include "wx/xrc/xml.h"class wxMenu;class wxMenuBar;class wxDialog;class wxPanel;class wxWindow;class wxFrame;class wxToolBar;class wxXmlResourceHandler;class wxXmlSubclassFactory;typedef std::list<wxXmlSubclassFactory *> wxXmlSubclassFactoriesList;class wxXmlResourceModule;// These macros indicate current version of XML resources (this information is// encoded in root node of XRC file as "version" property).//// Rules for increasing version number:// - change it only if you made incompatible change to the format. Addition of new// attribute to control handler is _not_ incompatible change, because older// versions of the library may ignore it.// - if you change version number, follow these steps:// - set major, minor and release numbers to respective version numbers of// the wxWindows library (see wx/version.h)// - reset revision to 0 unless the first three are same as before, in which// case you should increase revision by one#define WX_XMLRES_CURRENT_VERSION_MAJOR 2#define WX_XMLRES_CURRENT_VERSION_MINOR 3#define WX_XMLRES_CURRENT_VERSION_RELEASE 0#define WX_XMLRES_CURRENT_VERSION_REVISION 1#define WX_XMLRES_CURRENT_VERSION_STRING wxT("2.3.0.1")#define WX_XMLRES_CURRENT_VERSION \ (WX_XMLRES_CURRENT_VERSION_MAJOR * 256*256*256 + \ WX_XMLRES_CURRENT_VERSION_MINOR * 256*256 + \ WX_XMLRES_CURRENT_VERSION_RELEASE * 256 + \ WX_XMLRES_CURRENT_VERSION_REVISION)class wxXmlResourceDataRecord{public: wxXmlResourceDataRecord() : Doc(NULL), Time(wxDateTime::Now()) {} ~wxXmlResourceDataRecord() {delete Doc;} wxString File; wxXmlDocument *Doc; wxDateTime Time;};enum wxXmlResourceFlags{ wxXRC_USE_LOCALE = 1, wxXRC_NO_SUBCLASSING = 2};// This class holds XML resources from one or more .xml files// (or derived forms, either binary or zipped -- see manual for// details).class wxXmlResource : public wxObject{public: // Constructor. // Flags: wxXRC_USE_LOCALE // translatable strings will be translated via _() // wxXRC_NO_SUBCLASSING // subclass property of object nodes will be ignored // (useful for previews in XRC editors) wxXmlResource(); wxXmlResource(int flags); // Constructor. // Flags: wxXRC_USE_LOCALE // translatable strings will be translated via _() // wxXRC_NO_SUBCLASSING // subclass property of object nodes will be ignored // (useful for previews in XRC editors) wxXmlResource(const wxString& filemask, int flags = wxXRC_USE_LOCALE); // Destructor. ~wxXmlResource(); // Loads resources from XML files that match given filemask. // This method understands VFS (see filesys.h). bool Load(const wxString& filemask); // Initialize handlers for all supported controls/windows. This will // make the executable quite big because it forces linking against // most of the wxWindows library. void InitAllHandlers(); // Initialize only a specific handler (or custom handler). Convention says // that handler name is equal to the control's name plus 'XmlHandler', for example // wxTextCtrlXmlHandler, wxHtmlWindowXmlHandler. The XML resource compiler // (xmlres) can create include file that contains initialization code for // all controls used within the resource. void AddHandler(wxXmlResourceHandler *handler); // Add a new handler at the begining of the handler list void InsertHandler(wxXmlResourceHandler *handler); // Removes all handlers void ClearHandlers(); // Registers subclasses factory for use in XRC. This function is not meant // for public use, please see the comment above wxXmlSubclassFactory // definition. static void AddSubclassFactory(wxXmlSubclassFactory *factory); // Loads menu from resource. Returns NULL on failure. wxMenu *LoadMenu(const wxString& name); // Loads menubar from resource. Returns NULL on failure. wxMenuBar *LoadMenuBar(wxWindow *parent, const wxString& name); // Loads menubar from resource. Returns NULL on failure. wxMenuBar *LoadMenuBar(const wxString& name) { return LoadMenuBar(NULL, name); }#if wxUSE_TOOLBAR // Loads a toolbar. wxToolBar *LoadToolBar(wxWindow *parent, const wxString& name);#endif // Loads a dialog. dlg points to parent window (if any). wxDialog *LoadDialog(wxWindow *parent, const wxString& name); // Loads a dialog. dlg points to parent window (if any). This form // is used to finish creation of already existing instance (main reason // for this is that you may want to use derived class with new event table) // Example (typical usage): // MyDialog dlg; // wxTheXmlResource->LoadDialog(&dlg, mainFrame, "my_dialog"); // dlg->ShowModal(); bool LoadDialog(wxDialog *dlg, wxWindow *parent, const wxString& name); // Loads a panel. panel points to parent window (if any). wxPanel *LoadPanel(wxWindow *parent, const wxString& name); // Loads a panel. panel points to parent window (if any). This form // is used to finish creation of already existing instance. bool LoadPanel(wxPanel *panel, wxWindow *parent, const wxString& name); // Loads a frame. wxFrame *LoadFrame(wxWindow* parent, const wxString& name); bool LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name); // Load an object from the resource specifying both the resource name and // the classname. This lets you load nonstandard container windows. wxObject *LoadObject(wxWindow *parent, const wxString& name, const wxString& classname); // Load an object from the resource specifying both the resource name and // the classname. This form lets you finish the creation of an existing // instance. bool LoadObject(wxObject *instance, wxWindow *parent, const wxString& name, const wxString& classname); // Loads a bitmap resource from a file. wxBitmap LoadBitmap(const wxString& name); // Loads an icon resource from a file. wxIcon LoadIcon(const wxString& name); // Attaches an unknown control to the given panel/window/dialog. // Unknown controls are used in conjunction with <object class="unknown">. bool AttachUnknownControl(const wxString& name, wxWindow *control, wxWindow *parent = NULL); // Returns a numeric ID that is equivalent to the string id used in an XML // resource. To be used in event tables. // Macro XRCID is provided for convenience static int GetXRCID(const wxChar *str_id); // Returns version information (a.b.c.d = d+ 256*c + 256^2*b + 256^3*a). long GetVersion() const { return m_version; } // Compares resources version to argument. Returns -1 if resources version // is less than the argument, +1 if greater and 0 if they equal. int CompareVersion(int major, int minor, int release, int revision) const { return GetVersion() - (major*256*256*256 + minor*256*256 + release*256 + revision); }//// Singleton accessors. // Gets the global resources object or creates one if none exists. static wxXmlResource *Get(); // Sets the global resources object and returns a pointer to the previous one (may be NULL). static wxXmlResource *Set(wxXmlResource *res); // Returns flags, which may be a bitlist of wxXRC_USE_LOCALE and wxXRC_NO_SUBCLASSING. int GetFlags() const { return m_flags; } // Set flags after construction. void SetFlags(int flags) { m_flags = flags; }protected: // Scans the resources list for unloaded files and loads them. Also reloads // files that have been modified since last loading. void UpdateResources(); // Finds a resource (calls UpdateResources) and returns a node containing it. wxXmlNode *FindResource(const wxString& name, const wxString& classname, bool recursive = FALSE); // Helper function: finds a resource (calls UpdateResources) and returns a node containing it. wxXmlNode *DoFindResource(wxXmlNode *parent, const wxString& name, const wxString& classname, bool recursive); // Creates a resource from information in the given node. wxObject *CreateResFromNode(wxXmlNode *node, wxObject *parent, wxObject *instance = NULL); // Creates a resource from information in the given node // (Uses only 'handlerToUse' if != NULL)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -