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