xmlres.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/xrc/xmlres.h
  3. // Purpose: XML resources
  4. // Author: Vaclav Slavik
  5. // Created: 2000/03/05
  6. // Copyright: (c) 2000 Vaclav Slavik
  7. // Licence: wxWindows licence
  8. /////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_XMLRES_H_
  10. #define _WX_XMLRES_H_
  11. #include "wx/defs.h"
  12. #if wxUSE_XRC
  13. #include "wx/string.h"
  14. #include "wx/dynarray.h"
  15. #include "wx/arrstr.h"
  16. #include "wx/datetime.h"
  17. #include "wx/list.h"
  18. #include "wx/gdicmn.h"
  19. #include "wx/filesys.h"
  20. #include "wx/bitmap.h"
  21. #include "wx/icon.h"
  22. #include "wx/artprov.h"
  23. #include "wx/colour.h"
  24. #include "wx/vector.h"
  25. #include "wx/xrc/xmlreshandler.h"
  26. class WXDLLIMPEXP_FWD_BASE wxFileName;
  27. class WXDLLIMPEXP_FWD_CORE wxIconBundle;
  28. class WXDLLIMPEXP_FWD_CORE wxImageList;
  29. class WXDLLIMPEXP_FWD_CORE wxMenu;
  30. class WXDLLIMPEXP_FWD_CORE wxMenuBar;
  31. class WXDLLIMPEXP_FWD_CORE wxDialog;
  32. class WXDLLIMPEXP_FWD_CORE wxPanel;
  33. class WXDLLIMPEXP_FWD_CORE wxWindow;
  34. class WXDLLIMPEXP_FWD_CORE wxFrame;
  35. class WXDLLIMPEXP_FWD_CORE wxToolBar;
  36. class WXDLLIMPEXP_FWD_XML wxXmlDocument;
  37. class WXDLLIMPEXP_FWD_XML wxXmlNode;
  38. class WXDLLIMPEXP_FWD_XRC wxXmlSubclassFactory;
  39. class wxXmlSubclassFactories;
  40. class wxXmlResourceModule;
  41. class wxXmlResourceDataRecords;
  42. // These macros indicate current version of XML resources (this information is
  43. // encoded in root node of XRC file as "version" property).
  44. //
  45. // Rules for increasing version number:
  46. // - change it only if you made incompatible change to the format. Addition
  47. // of new attribute to control handler is _not_ incompatible change, because
  48. // older versions of the library may ignore it.
  49. // - if you change version number, follow these steps:
  50. // - set major, minor and release numbers to respective version numbers of
  51. // the wxWidgets library (see wx/version.h)
  52. // - reset revision to 0 unless the first three are same as before,
  53. // in which case you should increase revision by one
  54. #define WX_XMLRES_CURRENT_VERSION_MAJOR 2
  55. #define WX_XMLRES_CURRENT_VERSION_MINOR 5
  56. #define WX_XMLRES_CURRENT_VERSION_RELEASE 3
  57. #define WX_XMLRES_CURRENT_VERSION_REVISION 0
  58. #define WX_XMLRES_CURRENT_VERSION_STRING wxT("2.5.3.0")
  59. #define WX_XMLRES_CURRENT_VERSION \
  60. (WX_XMLRES_CURRENT_VERSION_MAJOR * 256*256*256 + \
  61. WX_XMLRES_CURRENT_VERSION_MINOR * 256*256 + \
  62. WX_XMLRES_CURRENT_VERSION_RELEASE * 256 + \
  63. WX_XMLRES_CURRENT_VERSION_REVISION)
  64. enum wxXmlResourceFlags
  65. {
  66. wxXRC_USE_LOCALE = 1,
  67. wxXRC_NO_SUBCLASSING = 2,
  68. wxXRC_NO_RELOADING = 4
  69. };
  70. // This class holds XML resources from one or more .xml files
  71. // (or derived forms, either binary or zipped -- see manual for
  72. // details).
  73. class WXDLLIMPEXP_XRC wxXmlResource : public wxObject
  74. {
  75. public:
  76. // Constructor.
  77. // Flags: wxXRC_USE_LOCALE
  78. // translatable strings will be translated via _()
  79. // using the given domain if specified
  80. // wxXRC_NO_SUBCLASSING
  81. // subclass property of object nodes will be ignored
  82. // (useful for previews in XRC editors)
  83. // wxXRC_NO_RELOADING
  84. // don't check the modification time of the XRC files and
  85. // reload them if they have changed on disk
  86. wxXmlResource(int flags = wxXRC_USE_LOCALE,
  87. const wxString& domain = wxEmptyString);
  88. // Constructor.
  89. // Flags: wxXRC_USE_LOCALE
  90. // translatable strings will be translated via _()
  91. // using the given domain if specified
  92. // wxXRC_NO_SUBCLASSING
  93. // subclass property of object nodes will be ignored
  94. // (useful for previews in XRC editors)
  95. wxXmlResource(const wxString& filemask, int flags = wxXRC_USE_LOCALE,
  96. const wxString& domain = wxEmptyString);
  97. // Destructor.
  98. virtual ~wxXmlResource();
  99. // Loads resources from XML files that match given filemask.
  100. // This method understands wxFileSystem URLs if wxUSE_FILESYS.
  101. bool Load(const wxString& filemask);
  102. // Loads resources from single XRC file.
  103. bool LoadFile(const wxFileName& file);
  104. // Loads all XRC files from a directory.
  105. bool LoadAllFiles(const wxString& dirname);
  106. // Unload resource from the given XML file (wildcards not allowed)
  107. bool Unload(const wxString& filename);
  108. // Initialize handlers for all supported controls/windows. This will
  109. // make the executable quite big because it forces linking against
  110. // most of the wxWidgets library.
  111. void InitAllHandlers();
  112. // Initialize only a specific handler (or custom handler). Convention says
  113. // that handler name is equal to the control's name plus 'XmlHandler', for
  114. // example wxTextCtrlXmlHandler, wxHtmlWindowXmlHandler. The XML resource
  115. // compiler (xmlres) can create include file that contains initialization
  116. // code for all controls used within the resource.
  117. void AddHandler(wxXmlResourceHandler *handler);
  118. // Add a new handler at the beginning of the handler list
  119. void InsertHandler(wxXmlResourceHandler *handler);
  120. // Removes all handlers
  121. void ClearHandlers();
  122. // Registers subclasses factory for use in XRC. This function is not meant
  123. // for public use, please see the comment above wxXmlSubclassFactory
  124. // definition.
  125. static void AddSubclassFactory(wxXmlSubclassFactory *factory);
  126. // Loads menu from resource. Returns NULL on failure.
  127. wxMenu *LoadMenu(const wxString& name);
  128. // Loads menubar from resource. Returns NULL on failure.
  129. wxMenuBar *LoadMenuBar(wxWindow *parent, const wxString& name);
  130. // Loads menubar from resource. Returns NULL on failure.
  131. wxMenuBar *LoadMenuBar(const wxString& name) { return LoadMenuBar(NULL, name); }
  132. #if wxUSE_TOOLBAR
  133. // Loads a toolbar.
  134. wxToolBar *LoadToolBar(wxWindow *parent, const wxString& name);
  135. #endif
  136. // Loads a dialog. dlg points to parent window (if any).
  137. wxDialog *LoadDialog(wxWindow *parent, const wxString& name);
  138. // Loads a dialog. dlg points to parent window (if any). This form
  139. // is used to finish creation of already existing instance (main reason
  140. // for this is that you may want to use derived class with new event table)
  141. // Example (typical usage):
  142. // MyDialog dlg;
  143. // wxTheXmlResource->LoadDialog(&dlg, mainFrame, "my_dialog");
  144. // dlg->ShowModal();
  145. bool LoadDialog(wxDialog *dlg, wxWindow *parent, const wxString& name);
  146. // Loads a panel. panel points to parent window (if any).
  147. wxPanel *LoadPanel(wxWindow *parent, const wxString& name);
  148. // Loads a panel. panel points to parent window (if any). This form
  149. // is used to finish creation of already existing instance.
  150. bool LoadPanel(wxPanel *panel, wxWindow *parent, const wxString& name);
  151. // Loads a frame.
  152. wxFrame *LoadFrame(wxWindow* parent, const wxString& name);
  153. bool LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name);
  154. // Load an object from the resource specifying both the resource name and
  155. // the classname. This lets you load nonstandard container windows.
  156. wxObject *LoadObject(wxWindow *parent, const wxString& name,
  157. const wxString& classname)
  158. {
  159. return DoLoadObject(parent, name, classname, false /* !recursive */);
  160. }
  161. // Load an object from the resource specifying both the resource name and
  162. // the classname. This form lets you finish the creation of an existing
  163. // instance.
  164. bool LoadObject(wxObject *instance,
  165. wxWindow *parent,
  166. const wxString& name,
  167. const wxString& classname)
  168. {
  169. return DoLoadObject(instance, parent, name, classname, false);
  170. }
  171. // These versions of LoadObject() look for the object with the given name
  172. // recursively (breadth first) and can be used to instantiate an individual
  173. // control defined anywhere in an XRC file. No check is done that the name
  174. // is unique, it's up to the caller to ensure this.
  175. wxObject *LoadObjectRecursively(wxWindow *parent,
  176. const wxString& name,
  177. const wxString& classname)
  178. {
  179. return DoLoadObject(parent, name, classname, true /* recursive */);
  180. }
  181. bool LoadObjectRecursively(wxObject *instance,
  182. wxWindow *parent,
  183. const wxString& name,
  184. const wxString& classname)
  185. {
  186. return DoLoadObject(instance, parent, name, classname, true);
  187. }
  188. // Loads a bitmap resource from a file.
  189. wxBitmap LoadBitmap(const wxString& name);
  190. // Loads an icon resource from a file.
  191. wxIcon LoadIcon(const wxString& name);
  192. // Attaches an unknown control to the given panel/window/dialog.
  193. // Unknown controls are used in conjunction with <object class="unknown">.
  194. bool AttachUnknownControl(const wxString& name, wxWindow *control,
  195. wxWindow *parent = NULL);
  196. // Returns a numeric ID that is equivalent to the string ID used in an XML
  197. // resource. If an unknown str_id is requested (i.e. other than wxID_XXX
  198. // or integer), a new record is created which associates the given string
  199. // with a number. If value_if_not_found == wxID_NONE, the number is obtained via
  200. // wxWindow::NewControlId(). Otherwise value_if_not_found is used.
  201. // Macro XRCID(name) is provided for convenient use in event tables.
  202. static int GetXRCID(const wxString& str_id, int value_if_not_found = wxID_NONE)
  203. { return DoGetXRCID(str_id.mb_str(), value_if_not_found); }
  204. // version for internal use only
  205. static int DoGetXRCID(const char *str_id, int value_if_not_found = wxID_NONE);
  206. // Find the string ID with the given numeric value, returns an empty string
  207. // if no such ID is found.
  208. //
  209. // Notice that unlike GetXRCID(), which is fast, this operation is slow as
  210. // it checks all the IDs used in XRC.
  211. static wxString FindXRCIDById(int numId);
  212. // Returns version information (a.b.c.d = d+ 256*c + 256^2*b + 256^3*a).
  213. long GetVersion() const { return m_version; }
  214. // Compares resources version to argument. Returns -1 if resources version
  215. // is less than the argument, +1 if greater and 0 if they equal.
  216. int CompareVersion(int major, int minor, int release, int revision) const
  217. {
  218. long diff = GetVersion() -
  219. (major*256*256*256 + minor*256*256 + release*256 + revision);
  220. if ( diff < 0 )
  221. return -1;
  222. else if ( diff > 0 )
  223. return +1;
  224. else
  225. return 0;
  226. }
  227. //// Singleton accessors.
  228. // Gets the global resources object or creates one if none exists.
  229. static wxXmlResource *Get();
  230. // Sets the global resources object and returns a pointer to the previous one (may be NULL).
  231. static wxXmlResource *Set(wxXmlResource *res);
  232. // Returns flags, which may be a bitlist of wxXRC_USE_LOCALE and wxXRC_NO_SUBCLASSING.
  233. int GetFlags() const { return m_flags; }
  234. // Set flags after construction.
  235. void SetFlags(int flags) { m_flags = flags; }
  236. // Get/Set the domain to be passed to the translation functions, defaults
  237. // to empty string (no domain).
  238. const wxString& GetDomain() const { return m_domain; }
  239. void SetDomain(const wxString& domain);
  240. // This function returns the wxXmlNode containing the definition of the
  241. // object with the given name or NULL.
  242. //
  243. // It can be used to access additional information defined in the XRC file
  244. // and not used by wxXmlResource itself.
  245. const wxXmlNode *GetResourceNode(const wxString& name) const
  246. { return GetResourceNodeAndLocation(name, wxString(), true); }
  247. protected:
  248. // reports input error at position 'context'
  249. void ReportError(const wxXmlNode *context, const wxString& message);
  250. // override this in derived class to customize errors reporting
  251. virtual void DoReportError(const wxString& xrcFile, const wxXmlNode *position,
  252. const wxString& message);
  253. // Load the contents of a single file and returns its contents as a new
  254. // wxXmlDocument (which will be owned by caller) on success or NULL.
  255. wxXmlDocument *DoLoadFile(const wxString& file);
  256. // Scans the resources list for unloaded files and loads them. Also reloads
  257. // files that have been modified since last loading.
  258. bool UpdateResources();
  259. // Common implementation of GetResourceNode() and FindResource(): searches
  260. // all top-level or all (if recursive == true) nodes if all loaded XRC
  261. // files and returns the node, if found, as well as the path of the file it
  262. // was found in if path is non-NULL
  263. wxXmlNode *GetResourceNodeAndLocation(const wxString& name,
  264. const wxString& classname,
  265. bool recursive = false,
  266. wxString *path = NULL) const;
  267. // Note that these functions are used outside of wxWidgets itself, e.g.
  268. // there are several known cases of inheriting from wxXmlResource just to
  269. // be able to call FindResource() so we keep them for compatibility even if
  270. // their names are not really consistent with GetResourceNode() public
  271. // function and FindResource() is also non-const because it changes the
  272. // current path of m_curFileSystem to ensure that relative paths work
  273. // correctly when CreateResFromNode() is called immediately afterwards
  274. // (something const public function intentionally does not do)
  275. // Returns the node containing the resource with the given name and class
  276. // name unless it's empty (then any class matches) or NULL if not found.
  277. wxXmlNode *FindResource(const wxString& name, const wxString& classname,
  278. bool recursive = false);
  279. // Helper function used by FindResource() to look under the given node.
  280. wxXmlNode *DoFindResource(wxXmlNode *parent, const wxString& name,
  281. const wxString& classname, bool recursive) const;
  282. // Creates a resource from information in the given node
  283. // (Uses only 'handlerToUse' if != NULL)
  284. wxObject *CreateResFromNode(wxXmlNode *node, wxObject *parent,
  285. wxObject *instance = NULL,
  286. wxXmlResourceHandler *handlerToUse = NULL)
  287. {
  288. return node ? DoCreateResFromNode(*node, parent, instance, handlerToUse)
  289. : NULL;
  290. }
  291. // Helper of Load() and Unload(): returns the URL corresponding to the
  292. // given file if it's indeed a file, otherwise returns the original string
  293. // unmodified
  294. static wxString ConvertFileNameToURL(const wxString& filename);
  295. // loading resources from archives is impossible without wxFileSystem
  296. #if wxUSE_FILESYSTEM
  297. // Another helper: detect if the filename is a ZIP or XRS file
  298. static bool IsArchive(const wxString& filename);
  299. #endif // wxUSE_FILESYSTEM
  300. private:
  301. wxXmlResourceDataRecords& Data() { return *m_data; }
  302. const wxXmlResourceDataRecords& Data() const { return *m_data; }
  303. // the real implementation of CreateResFromNode(): this should be only
  304. // called if node is non-NULL
  305. wxObject *DoCreateResFromNode(wxXmlNode& node,
  306. wxObject *parent,
  307. wxObject *instance,
  308. wxXmlResourceHandler *handlerToUse = NULL);
  309. // common part of LoadObject() and LoadObjectRecursively()
  310. wxObject *DoLoadObject(wxWindow *parent,
  311. const wxString& name,
  312. const wxString& classname,
  313. bool recursive);
  314. bool DoLoadObject(wxObject *instance,
  315. wxWindow *parent,
  316. const wxString& name,
  317. const wxString& classname,
  318. bool recursive);
  319. private:
  320. long m_version;
  321. int m_flags;
  322. wxVector<wxXmlResourceHandler*> m_handlers;
  323. wxXmlResourceDataRecords *m_data;
  324. #if wxUSE_FILESYSTEM
  325. wxFileSystem m_curFileSystem;
  326. wxFileSystem& GetCurFileSystem() { return m_curFileSystem; }
  327. #endif
  328. // domain to pass to translation functions, if any.
  329. wxString m_domain;
  330. friend class wxXmlResourceHandlerImpl;
  331. friend class wxXmlResourceModule;
  332. friend class wxIdRangeManager;
  333. friend class wxIdRange;
  334. static wxXmlSubclassFactories *ms_subclassFactories;
  335. // singleton instance:
  336. static wxXmlResource *ms_instance;
  337. };
  338. // This macro translates string identifier (as used in XML resource,
  339. // e.g. <menuitem id="my_menu">...</menuitem>) to integer id that is needed by
  340. // wxWidgets event tables.
  341. // Example:
  342. // BEGIN_EVENT_TABLE(MyFrame, wxFrame)
  343. // EVT_MENU(XRCID("quit"), MyFrame::OnQuit)
  344. // EVT_MENU(XRCID("about"), MyFrame::OnAbout)
  345. // EVT_MENU(XRCID("new"), MyFrame::OnNew)
  346. // EVT_MENU(XRCID("open"), MyFrame::OnOpen)
  347. // END_EVENT_TABLE()
  348. #define XRCID(str_id) \
  349. wxXmlResource::DoGetXRCID(str_id)
  350. // This macro returns pointer to particular control in dialog
  351. // created using XML resources. You can use it to set/get values from
  352. // controls.
  353. // Example:
  354. // wxDialog dlg;
  355. // wxXmlResource::Get()->LoadDialog(&dlg, mainFrame, "my_dialog");
  356. // XRCCTRL(dlg, "my_textctrl", wxTextCtrl)->SetValue(wxT("default value"));
  357. #define XRCCTRL(window, id, type) \
  358. (wxStaticCast((window).FindWindow(XRCID(id)), type))
  359. // This macro returns pointer to sizer item
  360. // Example:
  361. //
  362. // <object class="spacer" name="area">
  363. // <size>400, 300</size>
  364. // </object>
  365. //
  366. // wxSizerItem* item = XRCSIZERITEM(*this, "area")
  367. #define XRCSIZERITEM(window, id) \
  368. ((window).GetSizer() ? (window).GetSizer()->GetItemById(XRCID(id)) : NULL)
  369. // wxXmlResourceHandlerImpl is the back-end of the wxXmlResourceHander class to
  370. // really implementing all its functionality. It is defined in the "xrc"
  371. // library unlike wxXmlResourceHandler itself which is defined in "core" to
  372. // allow inheriting from it in the code from the other libraries too.
  373. class WXDLLIMPEXP_XRC wxXmlResourceHandlerImpl : public wxXmlResourceHandlerImplBase
  374. {
  375. public:
  376. // Constructor.
  377. wxXmlResourceHandlerImpl(wxXmlResourceHandler *handler);
  378. // Destructor.
  379. virtual ~wxXmlResourceHandlerImpl() {}
  380. // Creates an object (menu, dialog, control, ...) from an XML node.
  381. // Should check for validity.
  382. // parent is a higher-level object (usually window, dialog or panel)
  383. // that is often necessary to create the resource.
  384. // If instance is non-NULL it should not create a new instance via 'new' but
  385. // should rather use this one, and call its Create method.
  386. wxObject *CreateResource(wxXmlNode *node, wxObject *parent,
  387. wxObject *instance);
  388. // --- Handy methods:
  389. // Returns true if the node has a property class equal to classname,
  390. // e.g. <object class="wxDialog">.
  391. bool IsOfClass(wxXmlNode *node, const wxString& classname) const;
  392. // Gets node content from wxXML_ENTITY_NODE
  393. // The problem is, <tag>content<tag> is represented as
  394. // wxXML_ENTITY_NODE name="tag", content=""
  395. // |-- wxXML_TEXT_NODE or
  396. // wxXML_CDATA_SECTION_NODE name="" content="content"
  397. wxString GetNodeContent(const wxXmlNode *node);
  398. // Check to see if a parameter exists.
  399. bool HasParam(const wxString& param);
  400. // Finds the node or returns NULL.
  401. wxXmlNode *GetParamNode(const wxString& param);
  402. // Finds the parameter value or returns the empty string.
  403. wxString GetParamValue(const wxString& param);
  404. // Returns the parameter value from given node.
  405. wxString GetParamValue(const wxXmlNode* node);
  406. // Gets style flags from text in form "flag | flag2| flag3 |..."
  407. // Only understands flags added with AddStyle
  408. int GetStyle(const wxString& param = wxT("style"), int defaults = 0);
  409. // Gets text from param and does some conversions:
  410. // - replaces \n, \r, \t by respective chars (according to C syntax)
  411. // - replaces _ by & and __ by _ (needed for _File => &File because of XML)
  412. // - calls wxGetTranslations (unless disabled in wxXmlResource)
  413. wxString GetText(const wxString& param, bool translate = true);
  414. // Returns the XRCID.
  415. int GetID();
  416. // Returns the resource name.
  417. wxString GetName();
  418. // Gets a bool flag (1, t, yes, on, true are true, everything else is false).
  419. bool GetBool(const wxString& param, bool defaultv = false);
  420. // Gets an integer value from the parameter.
  421. long GetLong(const wxString& param, long defaultv = 0);
  422. // Gets a float value from the parameter.
  423. float GetFloat(const wxString& param, float defaultv = 0);
  424. // Gets colour in HTML syntax (#RRGGBB).
  425. wxColour GetColour(const wxString& param, const wxColour& defaultv = wxNullColour);
  426. // Gets the size (may be in dialog units).
  427. wxSize GetSize(const wxString& param = wxT("size"),
  428. wxWindow *windowToUse = NULL);
  429. // Gets the position (may be in dialog units).
  430. wxPoint GetPosition(const wxString& param = wxT("pos"));
  431. // Gets a dimension (may be in dialog units).
  432. wxCoord GetDimension(const wxString& param, wxCoord defaultv = 0,
  433. wxWindow *windowToUse = NULL);
  434. // Gets a direction, complains if the value is invalid.
  435. wxDirection GetDirection(const wxString& param, wxDirection dirDefault = wxLEFT);
  436. // Gets a bitmap.
  437. wxBitmap GetBitmap(const wxString& param = wxT("bitmap"),
  438. const wxArtClient& defaultArtClient = wxART_OTHER,
  439. wxSize size = wxDefaultSize);
  440. // Gets a bitmap from an XmlNode.
  441. wxBitmap GetBitmap(const wxXmlNode* node,
  442. const wxArtClient& defaultArtClient = wxART_OTHER,
  443. wxSize size = wxDefaultSize);
  444. // Gets an icon.
  445. wxIcon GetIcon(const wxString& param = wxT("icon"),
  446. const wxArtClient& defaultArtClient = wxART_OTHER,
  447. wxSize size = wxDefaultSize);
  448. // Gets an icon from an XmlNode.
  449. wxIcon GetIcon(const wxXmlNode* node,
  450. const wxArtClient& defaultArtClient = wxART_OTHER,
  451. wxSize size = wxDefaultSize);
  452. // Gets an icon bundle.
  453. wxIconBundle GetIconBundle(const wxString& param,
  454. const wxArtClient& defaultArtClient = wxART_OTHER);
  455. // Gets an image list.
  456. wxImageList *GetImageList(const wxString& param = wxT("imagelist"));
  457. #if wxUSE_ANIMATIONCTRL
  458. // Gets an animation.
  459. wxAnimation* GetAnimation(const wxString& param = wxT("animation"));
  460. #endif
  461. // Gets a font.
  462. wxFont GetFont(const wxString& param = wxT("font"), wxWindow* parent = NULL);
  463. // Gets the value of a boolean attribute (only "0" and "1" are valid values)
  464. bool GetBoolAttr(const wxString& attr, bool defaultv);
  465. // Sets common window options.
  466. void SetupWindow(wxWindow *wnd);
  467. // Creates children.
  468. void CreateChildren(wxObject *parent, bool this_hnd_only = false);
  469. // Helper function.
  470. void CreateChildrenPrivately(wxObject *parent, wxXmlNode *rootnode = NULL);
  471. // Creates a resource from a node.
  472. wxObject *CreateResFromNode(wxXmlNode *node,
  473. wxObject *parent, wxObject *instance = NULL);
  474. // helper
  475. #if wxUSE_FILESYSTEM
  476. wxFileSystem& GetCurFileSystem();
  477. #endif
  478. // reports input error at position 'context'
  479. void ReportError(wxXmlNode *context, const wxString& message);
  480. // reports input error at m_node
  481. void ReportError(const wxString& message);
  482. // reports input error when parsing parameter with given name
  483. void ReportParamError(const wxString& param, const wxString& message);
  484. };
  485. // Programmer-friendly macros for writing XRC handlers:
  486. #define XRC_MAKE_INSTANCE(variable, classname) \
  487. classname *variable = NULL; \
  488. if (m_instance) \
  489. variable = wxStaticCast(m_instance, classname); \
  490. if (!variable) \
  491. variable = new classname;
  492. // FIXME -- remove this $%^#$%#$@# as soon as Ron checks his changes in!!
  493. WXDLLIMPEXP_XRC void wxXmlInitResourceModule();
  494. // This class is used to create instances of XRC "object" nodes with "subclass"
  495. // property. It is _not_ supposed to be used by XRC users, you should instead
  496. // register your subclasses via wxWidgets' RTTI mechanism. This class is useful
  497. // only for language bindings developer who need a way to implement subclassing
  498. // in wxWidgets ports that don't support wxRTTI (e.g. wxPython).
  499. class WXDLLIMPEXP_XRC wxXmlSubclassFactory
  500. {
  501. public:
  502. // Try to create instance of given class and return it, return NULL on
  503. // failure:
  504. virtual wxObject *Create(const wxString& className) = 0;
  505. virtual ~wxXmlSubclassFactory() {}
  506. };
  507. /* -------------------------------------------------------------------------
  508. Backward compatibility macros. Do *NOT* use, they may disappear in future
  509. versions of the XRC library!
  510. ------------------------------------------------------------------------- */
  511. #endif // wxUSE_XRC
  512. #endif // _WX_XMLRES_H_