X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/92e898b0b47f5b881453bf75778c5f8f08b38c89..695fe764bd0ebfdc01d854033c26adb9ff248560:/contrib/include/wx/xrc/xmlres.h diff --git a/contrib/include/wx/xrc/xmlres.h b/contrib/include/wx/xrc/xmlres.h index 4e539a17c5..76dbd1e972 100644 --- a/contrib/include/wx/xrc/xmlres.h +++ b/contrib/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 @@ -26,7 +26,15 @@ #include "wx/icon.h" #include "wx/artprov.h" -#include "wx/xrc/xml.h" +#include "wx/xml/xml.h" + +#ifdef WXMAKINGDLL_XRC + #define WXDLLIMPEXP_XRC WXEXPORT +#elif defined(WXUSINGDLL) + #define WXDLLIMPEXP_XRC WXIMPORT +#else // not making nor using DLL + #define WXDLLIMPEXP_XRC +#endif class WXDLLEXPORT wxMenu; class WXDLLEXPORT wxMenuBar; @@ -36,26 +44,29 @@ class WXDLLEXPORT wxWindow; class WXDLLEXPORT wxFrame; class WXDLLEXPORT wxToolBar; -class WXXMLDLLEXPORT wxXmlResourceHandler; +class WXDLLIMPEXP_XRC wxXmlResourceHandler; +class WXDLLIMPEXP_XRC wxXmlSubclassFactory; +class WXDLLIMPEXP_XRC 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. +// - 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 +// the wxWidgets 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 "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 + \ @@ -63,7 +74,7 @@ class WXXMLDLLEXPORT wxXmlResourceHandler; WX_XMLRES_CURRENT_VERSION_RELEASE * 256 + \ WX_XMLRES_CURRENT_VERSION_REVISION) -class WXXMLDLLEXPORT wxXmlResourceDataRecord +class WXDLLIMPEXP_XRC wxXmlResourceDataRecord { public: wxXmlResourceDataRecord() : Doc(NULL), Time(wxDateTime::Now()) {} @@ -75,11 +86,9 @@ public: }; -#ifdef WXXMLISDLL -WX_DECLARE_EXPORTED_OBJARRAY(wxXmlResourceDataRecord, wxXmlResourceDataRecords); -#else -WX_DECLARE_OBJARRAY(wxXmlResourceDataRecord, wxXmlResourceDataRecords); -#endif +WX_DECLARE_USER_EXPORTED_OBJARRAY(wxXmlResourceDataRecord, + wxXmlResourceDataRecords, + WXDLLIMPEXP_XRC); enum wxXmlResourceFlags { @@ -90,7 +99,7 @@ enum wxXmlResourceFlags // This class holds XML resources from one or more .xml files // (or derived forms, either binary or zipped -- see manual for // details). -class WXXMLDLLEXPORT wxXmlResource : public wxObject +class WXDLLIMPEXP_XRC wxXmlResource : public wxObject { public: // Constructor. @@ -118,14 +127,14 @@ public: // Initialize handlers for all supported controls/windows. This will // make the executable quite big because it forces linking against - // most of the wxWindows library. + // most of the wxWidgets 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. + // 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 @@ -134,6 +143,11 @@ public: // 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); @@ -215,22 +229,27 @@ public: // 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(); + bool UpdateResources(); // Finds a resource (calls UpdateResources) and returns a node containing it. - wxXmlNode *FindResource(const wxString& name, const wxString& classname, bool recursive = FALSE); + 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); - - // 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; @@ -244,6 +263,9 @@ private: #endif friend class wxXmlResourceHandler; + friend class wxXmlResourceModule; + + static wxXmlSubclassFactoriesList *ms_subclassFactories; // singleton instance: static wxXmlResource *ms_instance; @@ -252,7 +274,7 @@ private: // This macro translates string identifier (as used in XML resource, // e.g. ...) to integer id that is needed by -// wxWindows event tables. +// wxWidgets event tables. // Example: // BEGIN_EVENT_TABLE(MyFrame, wxFrame) // EVT_MENU(XRCID("quit"), MyFrame::OnQuit) @@ -284,8 +306,9 @@ private: // wxXmlResourceHandler is an abstract base class for resource handlers // capable of creating a control from an XML node. -class WXXMLDLLEXPORT wxXmlResourceHandler : public wxObject +class WXDLLIMPEXP_XRC wxXmlResourceHandler : public wxObject { +DECLARE_ABSTRACT_CLASS(wxXmlResourceHandler) public: // Constructor. wxXmlResourceHandler(); @@ -306,8 +329,8 @@ public: // were filled. virtual wxObject *DoCreateResource() = 0; - // Returns TRUE if it understands this node and can create - // a resource from it, FALSE otherwise. + // Returns true if it understands this node and can create + // a resource from it, false otherwise. virtual bool CanHandle(wxXmlNode *node) = 0; // Sets the parent resource. @@ -362,7 +385,7 @@ protected: // - replaces \n, \r, \t by respective chars (according to C syntax) // - replaces _ by & and __ by _ (needed for _File => &File because of XML) // - calls wxGetTranslations (unless disabled in wxXmlResource) - wxString GetText(const wxString& param, bool translate = TRUE); + wxString GetText(const wxString& param, bool translate = true); // Returns the XRCID. int GetID(); @@ -370,8 +393,8 @@ protected: // Returns the resource name. wxString GetName(); - // Gets a bool flag (1, t, yes, on, true are TRUE, everything else is FALSE). - bool GetBool(const wxString& param, bool defaultv = FALSE); + // Gets a bool flag (1, t, yes, on, true are true, everything else is false). + bool GetBool(const wxString& param, bool defaultv = false); // Gets the integer value from the parameter. long GetLong( const wxString& param, long defaultv = 0 ); @@ -405,7 +428,7 @@ protected: void SetupWindow(wxWindow *wnd); // Creates children. - void CreateChildren(wxObject *parent, bool this_hnd_only = FALSE); + void CreateChildren(wxObject *parent, bool this_hnd_only = false); // Helper function. void CreateChildrenPrivately(wxObject *parent, wxXmlNode *rootnode = NULL); @@ -435,18 +458,35 @@ protected: // FIXME -- remove this $%^#$%#$@# as soon as Ron checks his changes in!! -void wxXmlInitResourceModule(); +WXDLLIMPEXP_XRC 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 wxWidgets' RTTI mechanism. This class is useful +// only for language bindings developer who need a way to implement subclassing +// in wxWidgets ports that don't support wxRTTI (e.g. wxPython). +class WXDLLIMPEXP_XRC 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 -#define GetXMLID GetXRCID +#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_