]>
Commit | Line | Data |
---|---|---|
d56cebe7 RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: xrc.i | |
3 | // Purpose: Wrappers for the XML based Resource system | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 4-June-2001 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2001 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | %module xrc | |
14 | ||
15 | ||
16 | %{ | |
6e2129f9 | 17 | #include "wxPython.h" |
628c7f79 | 18 | #include "pyistream.h" |
3ef86e32 | 19 | #include "wx/xml/xml.h" |
d56cebe7 | 20 | #include "wx/xrc/xmlres.h" |
cd834e7b RD |
21 | #include <wx/filesys.h> |
22 | #include <wx/fs_mem.h> | |
d56cebe7 RD |
23 | %} |
24 | ||
25 | //--------------------------------------------------------------------------- | |
26 | ||
27 | %include typemaps.i | |
28 | %include my_typemaps.i | |
29 | ||
30 | %extern wx.i | |
31 | %extern windows.i | |
32 | %extern _defs.i | |
33 | %extern events.i | |
34 | %extern controls.i | |
35 | ||
628c7f79 RD |
36 | %extern streams.i |
37 | ||
d56cebe7 | 38 | |
628c7f79 RD |
39 | //--------------------------------------------------------------------------- |
40 | %{ | |
41 | // Put some wx default wxChar* values into wxStrings. | |
42 | static const wxString wxPyEmptyString(wxT("")); | |
43 | static const wxString wxPyUTF8String(wxT("UTF-8")); | |
44 | static const wxString wxPyStyleString(wxT("style")); | |
45 | static const wxString wxPySizeString(wxT("size")); | |
46 | static const wxString wxPyPosString(wxT("pos")); | |
47 | static const wxString wxPyBitmapString(wxT("bitmap")); | |
48 | static const wxString wxPyIconString(wxT("icon")); | |
49 | static const wxString wxPyFontString(wxT("font")); | |
50 | %} | |
1e4a197e RD |
51 | |
52 | class wxPyXmlSubclassFactory; | |
53 | ||
d56cebe7 RD |
54 | //--------------------------------------------------------------------------- |
55 | ||
b5a5d647 RD |
56 | enum wxXmlResourceFlags |
57 | { | |
58 | wxXRC_USE_LOCALE = 1, | |
59 | wxXRC_NO_SUBCLASSING = 2 | |
60 | }; | |
61 | ||
62 | ||
d56cebe7 RD |
63 | // This class holds XML resources from one or more .xml files |
64 | // (or derived forms, either binary or zipped -- see manual for | |
65 | // details). | |
66 | ||
67 | class wxXmlResource : public wxObject | |
68 | { | |
69 | public: | |
cd834e7b | 70 | // Ctors. |
b5a5d647 RD |
71 | // Flags: wxXRC_USE_LOCALE |
72 | // translatable strings will be translated via _() | |
73 | // wxXRC_NO_SUBCLASSING | |
74 | // subclass property of object nodes will be ignored | |
75 | // (useful for previews in XRC editors) | |
cd834e7b RD |
76 | wxXmlResource(const wxString& filemask, int flags = wxXRC_USE_LOCALE); |
77 | %name(wxEmptyXmlResource) wxXmlResource(int flags = wxXRC_USE_LOCALE); | |
78 | %pragma(python) addtomethod = "__init__:self.InitAllHandlers()" | |
79 | %pragma(python) addtomethod = "wxEmptyXmlResource:val.InitAllHandlers()" | |
d56cebe7 RD |
80 | |
81 | ~wxXmlResource(); | |
82 | ||
83 | ||
84 | // Loads resources from XML files that match given filemask. | |
85 | // This method understands VFS (see filesys.h). | |
86 | bool Load(const wxString& filemask); | |
87 | ||
cd834e7b RD |
88 | %addmethods { |
89 | bool LoadFromString(const wxString& data) { | |
90 | static int s_memFileIdx = 0; | |
91 | ||
92 | // Check for memory FS. If not present, load the handler: | |
93 | wxMemoryFSHandler::AddFile(wxT("XRC_resource/dummy_file"), | |
94 | wxT("dummy data")); | |
95 | wxFileSystem fsys; | |
96 | wxFSFile *f = fsys.OpenFile(wxT("memory:XRC_resource/dummy_file")); | |
97 | wxMemoryFSHandler::RemoveFile(wxT("XRC_resource/dummy_file")); | |
98 | if (f) | |
99 | delete f; | |
100 | else | |
101 | wxFileSystem::AddHandler(new wxMemoryFSHandler); | |
102 | ||
103 | // Now put the resource data into the memory FS | |
104 | wxString filename(wxT("XRC_resource/data_string_")); | |
105 | filename << s_memFileIdx; | |
106 | s_memFileIdx += 1; | |
107 | wxMemoryFSHandler::AddFile(filename, data); | |
108 | ||
109 | // Load the "file" into the resource object | |
110 | bool retval = self->Load(wxT("memory:") + filename ); | |
111 | ||
112 | return retval; | |
113 | } | |
114 | } | |
115 | ||
d56cebe7 RD |
116 | // Initialize handlers for all supported controls/windows. This will |
117 | // make the executable quite big because it forces linking against | |
118 | // most of wxWin library | |
119 | void InitAllHandlers(); | |
120 | ||
121 | // Initialize only specific handler (or custom handler). Convention says | |
122 | // that handler name is equal to control's name plus 'XmlHandler', e.g. | |
123 | // wxTextCtrlXmlHandler, wxHtmlWindowXmlHandler. XML resource compiler | |
124 | // (xmlres) can create include file that contains initialization code for | |
125 | // all controls used within the resource. | |
628c7f79 RD |
126 | void AddHandler(wxPyXmlResourceHandler *handler); |
127 | ||
128 | // Add a new handler at the begining of the handler list | |
129 | void InsertHandler(wxPyXmlResourceHandler *handler); | |
d56cebe7 RD |
130 | |
131 | // Removes all handlers | |
132 | void ClearHandlers(); | |
133 | ||
1e4a197e RD |
134 | // Registers subclasses factory for use in XRC. This function is not meant |
135 | // for public use, please see the comment above wxXmlSubclassFactory | |
136 | // definition. | |
137 | static void AddSubclassFactory(wxPyXmlSubclassFactory *factory); | |
138 | ||
139 | ||
d56cebe7 RD |
140 | // Loads menu from resource. Returns NULL on failure. |
141 | wxMenu *LoadMenu(const wxString& name); | |
142 | ||
143 | // Loads menubar from resource. Returns NULL on failure. | |
144 | wxMenuBar *LoadMenuBar(const wxString& name); | |
32a85500 RD |
145 | %name(LoadMenuBarOnFrame) wxMenuBar *LoadMenuBar(wxWindow *parent, const wxString& name); |
146 | ||
d56cebe7 RD |
147 | |
148 | // Loads toolbar | |
149 | wxToolBar *LoadToolBar(wxWindow *parent, const wxString& name); | |
150 | ||
151 | // Loads dialog. dlg points to parent window (if any). Second form | |
152 | // is used to finish creation of already existing instance (main reason | |
153 | // for this is that you may want to use derived class with new event table) | |
154 | // Example (typical usage): | |
155 | // MyDialog dlg; | |
156 | // wxTheXmlResource->LoadDialog(&dlg, mainFrame, "my_dialog"); | |
157 | // dlg->ShowModal(); | |
158 | wxDialog *LoadDialog(wxWindow *parent, const wxString& name); | |
159 | %name(LoadOnDialog)bool LoadDialog(wxDialog *dlg, wxWindow *parent, const wxString& name); | |
160 | ||
161 | // Loads panel. panel points to parent window (if any). Second form | |
162 | // is used to finish creation of already existing instance. | |
163 | wxPanel *LoadPanel(wxWindow *parent, const wxString& name); | |
164 | %name(LoadOnPanel)bool LoadPanel(wxPanel *panel, wxWindow *parent, const wxString& name); | |
165 | ||
628c7f79 RD |
166 | // Load a frame's contents from a resource |
167 | wxFrame *LoadFrame(wxWindow* parent, const wxString& name); | |
168 | %name(LoadOnFrame)bool LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name); | |
d56cebe7 | 169 | |
628c7f79 RD |
170 | // Load an object from the resource specifying both the resource name and |
171 | // the classname. This lets you load nonstandard container windows. | |
172 | wxObject *LoadObject(wxWindow *parent, const wxString& name, | |
173 | const wxString& classname); | |
174 | ||
175 | // Load an object from the resource specifying both the resource name and | |
176 | // the classname. This form lets you finish the creation of an existing | |
177 | // instance. | |
178 | %name(LoadOnObject)bool LoadObject(wxObject *instance, wxWindow *parent, const wxString& name, | |
179 | const wxString& classname); | |
180 | ||
181 | // Loads bitmap or icon resource from file: | |
d56cebe7 RD |
182 | wxBitmap LoadBitmap(const wxString& name); |
183 | wxIcon LoadIcon(const wxString& name); | |
184 | ||
185 | // Attaches unknown control into given panel/window/dialog: | |
186 | // (unknown controls are used in conjunction with <object class="unknown">) | |
187 | bool AttachUnknownControl(const wxString& name, wxWindow *control, | |
188 | wxWindow *parent = NULL); | |
189 | ||
190 | // Returns numeric ID that is equivalent to string id used in XML | |
191 | // resource. To be used in event tables | |
192 | // Macro XMLID is provided for convenience | |
1496068d | 193 | static int GetXRCID(const wxString& str_id); |
d56cebe7 RD |
194 | |
195 | // Returns version info (a.b.c.d = d+ 256*c + 256^2*b + 256^3*a) | |
196 | long GetVersion() const; | |
197 | ||
198 | // Compares resources version to argument. Returns -1 if resources version | |
199 | // is less than the argument, +1 if greater and 0 if they equal. | |
200 | int CompareVersion(int major, int minor, int release, int revision) const; | |
201 | ||
d56cebe7 | 202 | |
ce914f73 RD |
203 | // Gets global resources object or create one if none exists |
204 | static wxXmlResource *Get(); | |
205 | // Sets global resources object and returns pointer to previous one (may be NULL). | |
206 | static wxXmlResource *Set(wxXmlResource *res); | |
d56cebe7 | 207 | |
fd512ba2 RD |
208 | // Returns flags, which may be a bitlist of wxXRC_USE_LOCALE and wxXRC_NO_SUBCLASSING. |
209 | int GetFlags(); | |
210 | ||
1e4a197e RD |
211 | // Set flags after construction. |
212 | void SetFlags(int flags) { m_flags = flags; } | |
213 | ||
ce914f73 | 214 | }; |
d56cebe7 RD |
215 | |
216 | //---------------------------------------------------------------------- | |
217 | ||
218 | %pragma(python) code = " | |
c6c593e8 RD |
219 | def XRCID(str_id): |
220 | return wxXmlResource_GetXRCID(str_id) | |
d56cebe7 | 221 | |
c6c593e8 RD |
222 | def XRCCTRL(window, str_id, *ignoreargs): |
223 | return window.FindWindowById(XRCID(str_id)) | |
d56cebe7 | 224 | |
c6c593e8 RD |
225 | XMLID = XRCID |
226 | XMLCTRL = XRCCTRL | |
d56cebe7 RD |
227 | " |
228 | ||
229 | //---------------------------------------------------------------------- | |
1e4a197e RD |
230 | // wxXmlSubclassFactory |
231 | ||
232 | ||
233 | %{ | |
234 | class wxPyXmlSubclassFactory : public wxXmlSubclassFactory | |
235 | { | |
236 | public: | |
237 | wxPyXmlSubclassFactory() {} | |
238 | DEC_PYCALLBACK_OBJECT_STRING_pure(Create); | |
239 | PYPRIVATE; | |
240 | }; | |
241 | ||
242 | IMP_PYCALLBACK_OBJECT_STRING_pure(wxPyXmlSubclassFactory, wxXmlSubclassFactory, Create); | |
243 | %} | |
244 | ||
245 | ||
246 | %name(wxXmlSubclassFactory)class wxPyXmlSubclassFactory { | |
247 | public: | |
248 | wxPyXmlSubclassFactory(); | |
249 | ||
250 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
251 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxXmlSubclassFactory)" | |
252 | }; | |
253 | ||
254 | ||
628c7f79 RD |
255 | //---------------------------------------------------------------------- |
256 | // In order to provide wrappers for wxXmlResourceHandler we need to also | |
257 | // provide the classes for representing and parsing XML. | |
258 | ||
259 | ||
260 | // Represents XML node type. | |
261 | enum wxXmlNodeType | |
262 | { | |
263 | // note: values are synchronized with xmlElementType from libxml | |
264 | wxXML_ELEMENT_NODE, | |
265 | wxXML_ATTRIBUTE_NODE, | |
266 | wxXML_TEXT_NODE, | |
267 | wxXML_CDATA_SECTION_NODE, | |
268 | wxXML_ENTITY_REF_NODE, | |
269 | wxXML_ENTITY_NODE, | |
270 | wxXML_PI_NODE, | |
271 | wxXML_COMMENT_NODE, | |
272 | wxXML_DOCUMENT_NODE, | |
273 | wxXML_DOCUMENT_TYPE_NODE, | |
274 | wxXML_DOCUMENT_FRAG_NODE, | |
275 | wxXML_NOTATION_NODE, | |
276 | wxXML_HTML_DOCUMENT_NODE | |
277 | }; | |
278 | ||
279 | ||
280 | ||
281 | // Represents node property(ies). | |
282 | // Example: in <img src="hello.gif" id="3"/> "src" is property with value | |
283 | // "hello.gif" and "id" is property with value "3". | |
284 | class wxXmlProperty | |
285 | { | |
286 | public: | |
287 | wxXmlProperty(const wxString& name = wxPyEmptyString, | |
288 | const wxString& value = wxPyEmptyString, | |
289 | wxXmlProperty *next = NULL); | |
290 | ||
291 | wxString GetName() const; | |
292 | wxString GetValue() const; | |
293 | wxXmlProperty *GetNext() const; | |
294 | ||
295 | void SetName(const wxString& name); | |
296 | void SetValue(const wxString& value); | |
297 | void SetNext(wxXmlProperty *next); | |
298 | }; | |
299 | ||
300 | ||
301 | ||
302 | ||
303 | // Represents node in XML document. Node has name and may have content | |
304 | // and properties. Most common node types are wxXML_TEXT_NODE (name and props | |
305 | // are irrelevant) and wxXML_ELEMENT_NODE (e.g. in <title>hi</title> there is | |
306 | // element with name="title", irrelevant content and one child (wxXML_TEXT_NODE | |
307 | // with content="hi"). | |
308 | // | |
309 | // If wxUSE_UNICODE is 0, all strings are encoded in the encoding given to Load | |
310 | // (default is UTF-8). | |
311 | class wxXmlNode | |
312 | { | |
313 | public: | |
314 | wxXmlNode(wxXmlNode *parent = NULL, | |
315 | wxXmlNodeType type = 0, | |
316 | const wxString& name = wxPyEmptyString, | |
317 | const wxString& content = wxPyEmptyString, | |
318 | wxXmlProperty *props = NULL, | |
319 | wxXmlNode *next = NULL); | |
320 | ~wxXmlNode(); | |
321 | ||
322 | ||
323 | // user-friendly creation: | |
324 | %name(wxXmlNodeEasy)wxXmlNode(wxXmlNodeType type, const wxString& name, | |
325 | const wxString& content = wxPyEmptyString); | |
326 | ||
327 | void AddChild(wxXmlNode *child); | |
328 | void InsertChild(wxXmlNode *child, wxXmlNode *before_node); | |
329 | bool RemoveChild(wxXmlNode *child); | |
330 | void AddProperty(wxXmlProperty *prop); | |
331 | %name(AddPropertyName)void AddProperty(const wxString& name, const wxString& value); | |
332 | bool DeleteProperty(const wxString& name); | |
333 | ||
334 | // access methods: | |
335 | wxXmlNodeType GetType() const; | |
336 | wxString GetName() const; | |
337 | wxString GetContent() const; | |
338 | ||
339 | wxXmlNode *GetParent() const; | |
340 | wxXmlNode *GetNext() const; | |
341 | wxXmlNode *GetChildren() const; | |
342 | ||
343 | wxXmlProperty *GetProperties() const; | |
344 | wxString GetPropVal(const wxString& propName, | |
345 | const wxString& defaultVal) const; | |
346 | bool HasProp(const wxString& propName) const; | |
347 | ||
348 | void SetType(wxXmlNodeType type); | |
349 | void SetName(const wxString& name); | |
350 | void SetContent(const wxString& con); | |
351 | ||
352 | void SetParent(wxXmlNode *parent); | |
353 | void SetNext(wxXmlNode *next); | |
354 | void SetChildren(wxXmlNode *child); | |
355 | ||
356 | void SetProperties(wxXmlProperty *prop); | |
357 | }; | |
358 | ||
359 | ||
360 | ||
361 | // This class holds XML data/document as parsed by XML parser. | |
362 | class wxXmlDocument : public wxObject | |
363 | { | |
364 | public: | |
365 | wxXmlDocument(const wxString& filename, | |
366 | const wxString& encoding = wxPyUTF8String); | |
367 | %name(wxXmlDocumentFromStream)wxXmlDocument(wxInputStream& stream, | |
368 | const wxString& encoding = wxPyUTF8String); | |
369 | %name(wxEmptyXmlDocument)wxXmlDocument(); | |
370 | ||
371 | ~wxXmlDocument(); | |
372 | ||
373 | ||
374 | // Parses .xml file and loads data. Returns TRUE on success, FALSE | |
375 | // otherwise. | |
376 | bool Load(const wxString& filename, | |
377 | const wxString& encoding = wxPyUTF8String); | |
378 | %name(LoadFromStream)bool Load(wxInputStream& stream, | |
379 | const wxString& encoding = wxPyUTF8String); | |
380 | ||
381 | // Saves document as .xml file. | |
382 | bool Save(const wxString& filename) const; | |
383 | %name(SaveToStream)bool Save(wxOutputStream& stream) const; | |
384 | ||
385 | bool IsOk() const; | |
386 | ||
387 | // Returns root node of the document. | |
388 | wxXmlNode *GetRoot() const; | |
389 | ||
390 | // Returns version of document (may be empty). | |
391 | wxString GetVersion() const; | |
392 | ||
393 | // Returns encoding of document (may be empty). | |
394 | // Note: this is the encoding original file was saved in, *not* the | |
395 | // encoding of in-memory representation! | |
396 | wxString GetFileEncoding() const; | |
397 | ||
398 | // Write-access methods: | |
399 | void SetRoot(wxXmlNode *node); | |
400 | void SetVersion(const wxString& version); | |
401 | void SetFileEncoding(const wxString& encoding); | |
402 | ||
403 | %addmethods { | |
404 | // Returns encoding of in-memory representation of the document (same | |
405 | // as passed to Load or ctor, defaults to UTF-8). NB: this is | |
406 | // meaningless in Unicode build where data are stored as wchar_t* | |
407 | wxString GetEncoding() { | |
408 | #if wxUSE_UNICODE | |
409 | return wxPyEmptyString; | |
410 | #else | |
411 | return self->GetEncoding(); | |
412 | #endif | |
413 | } | |
1e4a197e RD |
414 | void SetEncoding(const wxString& enc) { |
415 | #if wxUSE_UNICODE | |
416 | // do nothing | |
417 | #else | |
418 | self->SetEncoding(enc); | |
419 | #endif | |
420 | } | |
628c7f79 RD |
421 | } |
422 | }; | |
423 | ||
424 | ||
425 | //---------------------------------------------------------------------- | |
426 | // And now for wxXmlResourceHandler... | |
427 | ||
428 | ||
429 | ||
430 | %{ // C++ version of Python aware wxXmlResourceHandler, for the pure virtual | |
431 | // callbacks, as well as to make some protected things public so they can | |
432 | // be wrapped. | |
433 | class wxPyXmlResourceHandler : public wxXmlResourceHandler { | |
434 | public: | |
435 | wxPyXmlResourceHandler() : wxXmlResourceHandler() {} | |
436 | //~wxPyXmlResourceHandler(); | |
437 | ||
438 | // Base class virtuals | |
439 | ||
440 | DEC_PYCALLBACK_OBJECT__pure(DoCreateResource); | |
441 | DEC_PYCALLBACK_BOOL_NODE_pure(CanHandle); | |
442 | ||
628c7f79 RD |
443 | |
444 | // accessors for protected members | |
445 | ||
446 | wxXmlResource* GetResource() { return m_resource; } | |
447 | wxXmlNode* GetNode() { return m_node; } | |
448 | wxString GetClass() { return m_class; } | |
449 | wxObject* GetParent() { return m_parent; } | |
450 | wxObject* GetInstance() { return m_instance; } | |
451 | wxWindow* GetParentAsWindow() { return m_parentAsWindow; } | |
452 | wxWindow* GetInstanceAsWindow() { return m_instanceAsWindow; } | |
453 | ||
454 | ||
455 | // turn some protected methods into public via delegation | |
456 | ||
457 | bool IsOfClass(wxXmlNode *node, const wxString& classname) | |
458 | { return wxXmlResourceHandler::IsOfClass(node, classname); } | |
459 | ||
460 | wxString GetNodeContent(wxXmlNode *node) | |
461 | { return wxXmlResourceHandler::GetNodeContent(node); } | |
462 | ||
463 | bool HasParam(const wxString& param) | |
464 | { return wxXmlResourceHandler::HasParam(param); } | |
465 | ||
466 | wxXmlNode *GetParamNode(const wxString& param) | |
467 | { return wxXmlResourceHandler::GetParamNode(param); } | |
468 | ||
469 | wxString GetParamValue(const wxString& param) | |
470 | { return wxXmlResourceHandler::GetParamValue(param); } | |
471 | ||
472 | void AddStyle(const wxString& name, int value) | |
473 | { wxXmlResourceHandler::AddStyle(name, value); } | |
474 | ||
475 | void AddWindowStyles() | |
476 | { wxXmlResourceHandler::AddWindowStyles(); } | |
477 | ||
478 | int GetStyle(const wxString& param = wxT("style"), int defaults = 0) | |
479 | { return wxXmlResourceHandler::GetStyle(param, defaults); } | |
480 | ||
481 | wxString GetText(const wxString& param, bool translate = TRUE) | |
482 | { return wxXmlResourceHandler::GetText(param, translate); } | |
483 | ||
484 | int GetID() | |
485 | { return wxXmlResourceHandler::GetID(); } | |
486 | ||
487 | wxString GetName() | |
488 | { return wxXmlResourceHandler::GetName(); } | |
489 | ||
490 | bool GetBool(const wxString& param, bool defaultv = FALSE) | |
491 | { return wxXmlResourceHandler::GetBool(param, defaultv); } | |
492 | ||
493 | long GetLong( const wxString& param, long defaultv = 0 ) | |
494 | { return wxXmlResourceHandler::GetLong(param, defaultv); } | |
495 | ||
496 | wxColour GetColour(const wxString& param) | |
497 | { return wxXmlResourceHandler::GetColour(param); } | |
498 | ||
499 | wxSize GetSize(const wxString& param = wxT("size")) | |
500 | { return wxXmlResourceHandler::GetSize(param); } | |
501 | ||
502 | wxPoint GetPosition(const wxString& param = wxT("pos")) | |
503 | { return wxXmlResourceHandler::GetPosition(param); } | |
504 | ||
505 | wxCoord GetDimension(const wxString& param, wxCoord defaultv = 0) | |
506 | { return wxXmlResourceHandler::GetDimension(param, defaultv); } | |
507 | ||
508 | wxBitmap GetBitmap(const wxString& param = wxT("bitmap"), | |
509 | const wxArtClient& defaultArtClient = wxART_OTHER, | |
510 | wxSize size = wxDefaultSize) | |
511 | { return wxXmlResourceHandler::GetBitmap(param, defaultArtClient, size); } | |
512 | ||
513 | wxIcon GetIcon(const wxString& param = wxT("icon"), | |
514 | const wxArtClient& defaultArtClient = wxART_OTHER, | |
515 | wxSize size = wxDefaultSize) | |
516 | { return wxXmlResourceHandler::GetIcon(param, defaultArtClient, size); } | |
517 | ||
518 | wxFont GetFont(const wxString& param = wxT("font")) | |
519 | { return wxXmlResourceHandler::GetFont(param); } | |
520 | ||
521 | void SetupWindow(wxWindow *wnd) | |
522 | { wxXmlResourceHandler::SetupWindow(wnd); } | |
523 | ||
524 | void CreateChildren(wxObject *parent, bool this_hnd_only = FALSE) | |
525 | { wxXmlResourceHandler::CreateChildren(parent, this_hnd_only); } | |
526 | ||
527 | void CreateChildrenPrivately(wxObject *parent, wxXmlNode *rootnode = NULL) | |
528 | { wxXmlResourceHandler::CreateChildrenPrivately(parent, rootnode); } | |
529 | ||
530 | wxObject *CreateResFromNode(wxXmlNode *node, | |
531 | wxObject *parent, wxObject *instance = NULL) | |
532 | { return wxXmlResourceHandler::CreateResFromNode(node, parent, instance); } | |
533 | ||
534 | wxFileSystem& GetCurFileSystem() | |
535 | { return wxXmlResourceHandler::GetCurFileSystem(); } | |
536 | ||
537 | ||
538 | PYPRIVATE; | |
539 | }; | |
540 | ||
541 | IMP_PYCALLBACK_OBJECT__pure(wxPyXmlResourceHandler, wxXmlResourceHandler, DoCreateResource); | |
542 | IMP_PYCALLBACK_BOOL_NODE_pure(wxPyXmlResourceHandler, wxXmlResourceHandler, CanHandle); | |
543 | ||
544 | %} | |
545 | ||
546 | ||
547 | //---------------------------------------------------------------------- | |
548 | // Now the version that will be SWIGged. | |
549 | ||
550 | ||
551 | %name(wxXmlResourceHandler) class wxPyXmlResourceHandler : public wxObject { | |
552 | public: | |
553 | wxPyXmlResourceHandler() : wxXmlResourceHandler() {} | |
554 | //~wxPyXmlResourceHandler(); | |
555 | ||
556 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
557 | %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxXmlResourceHandler)" | |
d56cebe7 | 558 | |
d56cebe7 | 559 | |
628c7f79 RD |
560 | |
561 | // Creates an object (menu, dialog, control, ...) from an XML node. | |
562 | // Should check for validity. | |
563 | // parent is a higher-level object (usually window, dialog or panel) | |
564 | // that is often neccessary to create the resource. | |
565 | // If instance is non-NULL it should not create a new instance via 'new' but | |
566 | // should rather use this one, and call its Create method. | |
567 | wxObject *CreateResource(wxXmlNode *node, wxObject *parent, | |
568 | wxObject *instance); | |
569 | ||
570 | // Sets the parent resource. | |
571 | void SetParentResource(wxXmlResource *res); | |
572 | ||
573 | ||
574 | wxXmlResource* GetResource() { return m_resource; } | |
575 | wxXmlNode* GetNode() { return m_node; } | |
576 | wxString GetClass() { return m_class; } | |
577 | wxObject* GetParent() { return m_parent; } | |
578 | wxObject* GetInstance() { return m_instance; } | |
579 | wxWindow* GetParentAsWindow() { return m_parentAsWindow; } | |
580 | wxWindow* GetInstanceAsWindow() { return m_instanceAsWindow; } | |
581 | ||
582 | ||
583 | // Returns true if the node has a property class equal to classname, | |
584 | // e.g. <object class="wxDialog">. | |
585 | bool IsOfClass(wxXmlNode *node, const wxString& classname); | |
586 | ||
587 | // Gets node content from wxXML_ENTITY_NODE | |
588 | // The problem is, <tag>content<tag> is represented as | |
589 | // wxXML_ENTITY_NODE name="tag", content="" | |
590 | // |-- wxXML_TEXT_NODE or | |
591 | // wxXML_CDATA_SECTION_NODE name="" content="content" | |
592 | wxString GetNodeContent(wxXmlNode *node); | |
593 | ||
594 | // Check to see if a parameter exists. | |
595 | bool HasParam(const wxString& param); | |
596 | ||
597 | // Finds the node or returns NULL. | |
598 | wxXmlNode *GetParamNode(const wxString& param); | |
599 | ||
600 | // Finds the parameter value or returns the empty string. | |
601 | wxString GetParamValue(const wxString& param); | |
602 | ||
603 | // Add a style flag (e.g. wxMB_DOCKABLE) to the list of flags | |
604 | // understood by this handler. | |
605 | void AddStyle(const wxString& name, int value); | |
606 | ||
607 | // Add styles common to all wxWindow-derived classes. | |
608 | void AddWindowStyles(); | |
609 | ||
610 | // Gets style flags from text in form "flag | flag2| flag3 |..." | |
611 | // Only understads flags added with AddStyle | |
612 | int GetStyle(const wxString& param = wxPyStyleString, int defaults = 0); | |
613 | ||
614 | // Gets text from param and does some conversions: | |
615 | // - replaces \n, \r, \t by respective chars (according to C syntax) | |
616 | // - replaces _ by & and __ by _ (needed for _File => &File because of XML) | |
617 | // - calls wxGetTranslations (unless disabled in wxXmlResource) | |
618 | wxString GetText(const wxString& param, bool translate = TRUE); | |
619 | ||
620 | // Returns the XRCID. | |
621 | int GetID(); | |
622 | ||
623 | // Returns the resource name. | |
624 | wxString GetName(); | |
625 | ||
626 | // Gets a bool flag (1, t, yes, on, true are TRUE, everything else is FALSE). | |
627 | bool GetBool(const wxString& param, bool defaultv = FALSE); | |
628 | ||
629 | // Gets the integer value from the parameter. | |
630 | long GetLong( const wxString& param, long defaultv = 0 ); | |
631 | ||
632 | // Gets colour in HTML syntax (#RRGGBB). | |
633 | wxColour GetColour(const wxString& param); | |
634 | ||
635 | // Gets the size (may be in dialog units). | |
636 | wxSize GetSize(const wxString& param = wxPySizeString); | |
637 | ||
638 | // Gets the position (may be in dialog units). | |
639 | wxPoint GetPosition(const wxString& param = wxPyPosString); | |
640 | ||
641 | // Gets a dimension (may be in dialog units). | |
642 | wxCoord GetDimension(const wxString& param, wxCoord defaultv = 0); | |
643 | ||
644 | // Gets a bitmap. | |
645 | wxBitmap GetBitmap(const wxString& param = wxPyBitmapString, | |
646 | const wxArtClient& defaultArtClient = wxART_OTHER, | |
647 | wxSize size = wxDefaultSize); | |
648 | ||
649 | // Gets an icon. | |
650 | wxIcon GetIcon(const wxString& param = wxPyIconString, | |
651 | const wxArtClient& defaultArtClient = wxART_OTHER, | |
652 | wxSize size = wxDefaultSize); | |
653 | ||
654 | // Gets a font. | |
655 | wxFont GetFont(const wxString& param = wxPyFontString); | |
656 | ||
657 | // Sets common window options. | |
658 | void SetupWindow(wxWindow *wnd); | |
659 | ||
660 | // Creates children. | |
661 | void CreateChildren(wxObject *parent, bool this_hnd_only = FALSE); | |
662 | ||
663 | // Helper function. | |
664 | void CreateChildrenPrivately(wxObject *parent, wxXmlNode *rootnode = NULL); | |
665 | ||
666 | // Creates a resource from a node. | |
667 | wxObject *CreateResFromNode(wxXmlNode *node, | |
668 | wxObject *parent, wxObject *instance = NULL); | |
669 | ||
670 | // helper | |
671 | wxFileSystem& GetCurFileSystem(); | |
672 | }; | |
673 | ||
674 | ||
675 | //---------------------------------------------------------------------- | |
d56cebe7 RD |
676 | //---------------------------------------------------------------------- |
677 | ||
678 | %init %{ | |
679 | ||
d56cebe7 | 680 | wxXmlInitResourceModule(); |
ce914f73 | 681 | wxXmlResource::Get()->InitAllHandlers(); |
d56cebe7 RD |
682 | |
683 | %} | |
684 | ||
ce914f73 RD |
685 | //---------------------------------------------------------------------- |
686 | // This file gets appended to the shadow class file. | |
687 | //---------------------------------------------------------------------- | |
688 | ||
689 | %pragma(python) include="_xrcextras.py"; | |
690 | ||
691 |