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