X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5ed345b7edec3552c51b3cf9453a81b29568e946..1338c59a025505bc066be220fe56e898a72b3ad3:/include/wx/xrc/xmlres.h diff --git a/include/wx/xrc/xmlres.h b/include/wx/xrc/xmlres.h index 77bc74433e..7500a893b0 100644 --- a/include/wx/xrc/xmlres.h +++ b/include/wx/xrc/xmlres.h @@ -11,7 +11,7 @@ #ifndef _WX_XMLRES_H_ #define _WX_XMLRES_H_ -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(__APPLE__) #pragma interface "xmlres.h" #endif @@ -24,6 +24,7 @@ #include "wx/filesys.h" #include "wx/bitmap.h" #include "wx/icon.h" +#include "wx/artprov.h" #include "wx/xrc/xml.h" @@ -36,6 +37,9 @@ class WXDLLEXPORT wxFrame; class WXDLLEXPORT wxToolBar; class WXXMLDLLEXPORT wxXmlResourceHandler; +class WXXMLDLLEXPORT wxXmlSubclassFactory; +class WXXMLDLLEXPORT wxXmlSubclassFactoriesList; +class wxXmlResourceModule; // These macros indicate current version of XML resources (this information is @@ -54,7 +58,7 @@ class WXXMLDLLEXPORT wxXmlResourceHandler; #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 "2.3.0.1" +#define WX_XMLRES_CURRENT_VERSION_STRING _T("2.3.0.1") #define WX_XMLRES_CURRENT_VERSION \ (WX_XMLRES_CURRENT_VERSION_MAJOR * 256*256*256 + \ @@ -110,7 +114,7 @@ public: // Destructor. ~wxXmlResource(); - + // Loads resources from XML files that match given filemask. // This method understands VFS (see filesys.h). bool Load(const wxString& filemask); @@ -127,8 +131,16 @@ public: // 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); @@ -164,8 +176,20 @@ public: 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); @@ -190,15 +214,20 @@ public: 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. @@ -210,11 +239,11 @@ protected: // 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); - - // Returns flags, which may be a bitlist of wxXRC_USE_LOCALE and wxXRC_NO_SUBCLASSING. - int GetFlags() { return m_flags; } + // Creates a resource from information in the given node + // (Uses only 'handlerToUse' if != NULL) + wxObject *CreateResFromNode(wxXmlNode *node, wxObject *parent, + wxObject *instance = NULL, + wxXmlResourceHandler *handlerToUse = NULL); private: long m_version; @@ -228,7 +257,10 @@ private: #endif friend class wxXmlResourceHandler; - + friend class wxXmlResourceModule; + + static wxXmlSubclassFactoriesList *ms_subclassFactories; + // singleton instance: static wxXmlResource *ms_instance; }; @@ -344,9 +376,9 @@ protected: // Gets text from param and does some conversions: // - replaces \n, \r, \t by respective chars (according to C syntax) - // - replaces $ by & and $$ by $ (needed for $File => &File because of XML) + // - replaces _ by & and __ by _ (needed for _File => &File because of XML) // - calls wxGetTranslations (unless disabled in wxXmlResource) - wxString GetText(const wxString& param); + wxString GetText(const wxString& param, bool translate = TRUE); // Returns the XRCID. int GetID(); @@ -374,10 +406,12 @@ protected: // Gets a bitmap. wxBitmap GetBitmap(const wxString& param = wxT("bitmap"), + const wxArtClient& defaultArtClient = wxART_OTHER, wxSize size = wxDefaultSize); // Gets an icon. wxIcon GetIcon(const wxString& param = wxT("icon"), + const wxArtClient& defaultArtClient = wxART_OTHER, wxSize size = wxDefaultSize); // Gets a font. @@ -420,14 +454,31 @@ protected: void wxXmlInitResourceModule(); -/* ------------------------------------------------------------------------- +// This class is used to create instances of XRC "object" nodes with "subclass" +// property. It is _not_ supposed to be used by XRC users, you should instead +// register your subclasses via wxWindows' RTTI mechanism. This class is useful +// only for language bindings developer who need a way to implement subclassing +// in wxWindows ports that don't support wxRTTI (e.g. wxPython). +class WXXMLDLLEXPORT wxXmlSubclassFactory +{ +public: + // Try to create instance of given class and return it, return NULL on failure: + virtual wxObject *Create(const wxString& className) = 0; + virtual ~wxXmlSubclassFactory() {} +}; + + +/* ------------------------------------------------------------------------- Backward compatibility macros. Do *NOT* use, they may disappear in future versions of the XRC library! ------------------------------------------------------------------------- */ -#define ADD_STYLE XRC_ADD_STYLE -#define wxTheXmlResource wxXmlResource::Get() -#define XMLID XRCID -#define XMLCTRL XRCCTRL +#if WXWIN_COMPATIBILITY_2_4 + #define ADD_STYLE XRC_ADD_STYLE + #define wxTheXmlResource wxXmlResource::Get() + #define XMLID XRCID + #define XMLCTRL XRCCTRL + #define GetXMLID GetXRCID +#endif #endif // _WX_XMLRES_H_