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