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