]> git.saurik.com Git - wxWidgets.git/blobdiff - include/wx/xrc/xmlres.h
More bug fix updates.
[wxWidgets.git] / include / wx / xrc / xmlres.h
index 7843e4f1611642d0f595c4b325165456354e4bfc..fb076250ebbe2bce8f0bc299432ef44a66eb1d67 100644 (file)
@@ -80,21 +80,28 @@ WX_DECLARE_EXPORTED_OBJARRAY(wxXmlResourceDataRecord, wxXmlResourceDataRecords);
 WX_DECLARE_OBJARRAY(wxXmlResourceDataRecord, wxXmlResourceDataRecords);
 #endif
 
+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 WXXMLDLLEXPORT wxXmlResource : public wxObject
 {
 public:
-    // Ctor. If use_locale is TRUE, translatable strings are
-    // translated via _(). You can disable it by passing use_locale=FALSE
-    // (for example if you provide resource file for each locale)
-    wxXmlResource(bool use_locale = TRUE);
-    wxXmlResource(const wxString& filemask, bool use_locale = TRUE);
+    // Ctor. 
+    // 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(int flags = wxXRC_USE_LOCALE);
+    wxXmlResource(const wxString& filemask, int flags = wxXRC_USE_LOCALE);
     ~wxXmlResource();
-
+    
     // Loads resources from XML files that match given filemask.
     // This method understands VFS (see filesys.h).
     bool Load(const wxString& filemask);
@@ -118,7 +125,8 @@ public:
     wxMenu *LoadMenu(const wxString& name);
 
     // Loads menubar from resource. Returns NULL on failure.
-    wxMenuBar *LoadMenuBar(const wxString& name);
+    wxMenuBar *LoadMenuBar(wxWindow *parent, const wxString& name);
+    wxMenuBar *LoadMenuBar(const wxString& name) { return LoadMenuBar(NULL, name); }
 
 #if wxUSE_TOOLBAR
     // Loads toolbar
@@ -164,6 +172,13 @@ 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 global resources object or create one if none exists
+    static wxXmlResource *Get();
+    // Sets global resources object and returns pointer to previous one (may be NULL).
+    static wxXmlResource *Set(wxXmlResource *res);
 
 protected:
     // Scans resources list for unloaded files and loads them. Also reloads
@@ -171,17 +186,18 @@ protected:
     void UpdateResources();
 
     // Finds resource (calls UpdateResources) and returns node containing it
-    wxXmlNode *FindResource(const wxString& name, const wxString& classname);
+    wxXmlNode *FindResource(const wxString& name, const wxString& classname, bool recursive = FALSE);
+    wxXmlNode *DoFindResource(wxXmlNode *parent, const wxString& name, const wxString& classname, bool recursive);
 
     // Creates resource from info in given node:
     wxObject *CreateResFromNode(wxXmlNode *node, wxObject *parent, wxObject *instance = NULL);
 
-    bool GetUseLocale() { return m_useLocale; }
+    int GetFlags() { return m_flags; }
 
 private:
     long m_version;
 
-    bool m_useLocale;
+    int m_flags;
     wxList m_handlers;
     wxXmlResourceDataRecords m_data;
 #if wxUSE_FILESYSTEM
@@ -190,12 +206,12 @@ private:
 #endif
 
     friend class wxXmlResourceHandler;
+    
+    // singleton instance:
+    static wxXmlResource *ms_instance;
 };
 
 
-// Global instance of resource class. For your convenience.
-extern WXXMLDLLEXPORT wxXmlResource *wxTheXmlResource;
-
 // This macro translates string identifier (as used in XML resource,
 // e.g. <menuitem id="my_menu">...</menuitem>) to integer id that is needed by
 // wxWindows event tables.
@@ -216,7 +232,7 @@ extern WXXMLDLLEXPORT wxXmlResource *wxTheXmlResource;
 // controls.
 // Example:
 //    wxDialog dlg;
-//    wxTheXmlResource->LoadDialog(&dlg, mainFrame, "my_dialog");
+//    wxXmlResource::Get()->LoadDialog(&dlg, mainFrame, "my_dialog");
 //    XMLCTRL(dlg, "my_textctrl", wxTextCtrl)->SetValue(wxT("default value"));
 
 #ifdef __WXDEBUG__
@@ -255,7 +271,6 @@ public:
 
 
 protected:
-
     wxXmlResource *m_resource;
     wxArrayString m_styleNames;
     wxArrayInt m_styleValues;
@@ -348,9 +363,30 @@ protected:
 #endif
 };
 
-#define ADD_STYLE(style) AddStyle(wxT(#style), style)
 
+// Programmer-friendly macros for writing XRC handlers:
+
+#define XRC_ADD_STYLE(style) AddStyle(wxT(#style), style)
 
+#define XRC_MAKE_INSTANCE(variable, classname) \
+   classname *variable = NULL; \
+   if (m_instance) \
+       variable = wxStaticCast(m_instance, classname); \
+   if (!variable) \
+       variable = new classname;
+
+
+// FIXME -- remove this $%^#$%#$@# as soon as Ron checks his changes in!!
 void wxXmlInitResourceModule();
 
+
+/* ------------------------------------------------------------------------- 
+   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()
+
+
+
 #endif // _WX_XMLRES_H_