]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: _xml.i | |
3 | // Purpose: SWIG interface for other wxXml classes | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 4-June-2001 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2003 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | // Not a %module | |
14 | ||
15 | ||
16 | //--------------------------------------------------------------------------- | |
17 | %newgroup | |
18 | ||
19 | ||
20 | ||
21 | %{ // C++ version of Python aware wxXmlResourceHandler, for the pure virtual | |
22 | // callbacks, as well as to make some protected things public so they can | |
23 | // be wrapped. | |
24 | class wxPyXmlResourceHandler : public wxXmlResourceHandler { | |
25 | public: | |
26 | wxPyXmlResourceHandler() : wxXmlResourceHandler() {} | |
27 | //~wxPyXmlResourceHandler(); | |
28 | ||
29 | // Base class virtuals | |
30 | ||
31 | DEC_PYCALLBACK_OBJECT__pure(DoCreateResource); | |
32 | DEC_PYCALLBACK_BOOL_NODE_pure(CanHandle); | |
33 | ||
34 | ||
35 | // accessors for protected members | |
36 | ||
37 | wxXmlResource* GetResource() { return m_resource; } | |
38 | wxXmlNode* GetNode() { return m_node; } | |
39 | wxString GetClass() { return m_class; } | |
40 | wxObject* GetParent() { return m_parent; } | |
41 | wxObject* GetInstance() { return m_instance; } | |
42 | wxWindow* GetParentAsWindow() { return m_parentAsWindow; } | |
d14a1e28 RD |
43 | |
44 | ||
45 | // turn some protected methods into public via delegation | |
46 | ||
47 | bool IsOfClass(wxXmlNode *node, const wxString& classname) | |
48 | { return wxXmlResourceHandler::IsOfClass(node, classname); } | |
49 | ||
50 | wxString GetNodeContent(wxXmlNode *node) | |
51 | { return wxXmlResourceHandler::GetNodeContent(node); } | |
52 | ||
53 | bool HasParam(const wxString& param) | |
54 | { return wxXmlResourceHandler::HasParam(param); } | |
55 | ||
56 | wxXmlNode *GetParamNode(const wxString& param) | |
57 | { return wxXmlResourceHandler::GetParamNode(param); } | |
58 | ||
59 | wxString GetParamValue(const wxString& param) | |
60 | { return wxXmlResourceHandler::GetParamValue(param); } | |
61 | ||
62 | void AddStyle(const wxString& name, int value) | |
63 | { wxXmlResourceHandler::AddStyle(name, value); } | |
64 | ||
65 | void AddWindowStyles() | |
66 | { wxXmlResourceHandler::AddWindowStyles(); } | |
67 | ||
68 | int GetStyle(const wxString& param = wxT("style"), int defaults = 0) | |
69 | { return wxXmlResourceHandler::GetStyle(param, defaults); } | |
70 | ||
a72f4631 | 71 | wxString GetText(const wxString& param, bool translate = true) |
d14a1e28 RD |
72 | { return wxXmlResourceHandler::GetText(param, translate); } |
73 | ||
74 | int GetID() | |
75 | { return wxXmlResourceHandler::GetID(); } | |
76 | ||
77 | wxString GetName() | |
78 | { return wxXmlResourceHandler::GetName(); } | |
79 | ||
a72f4631 | 80 | bool GetBool(const wxString& param, bool defaultv = false) |
d14a1e28 RD |
81 | { return wxXmlResourceHandler::GetBool(param, defaultv); } |
82 | ||
83 | long GetLong( const wxString& param, long defaultv = 0 ) | |
84 | { return wxXmlResourceHandler::GetLong(param, defaultv); } | |
85 | ||
86 | wxColour GetColour(const wxString& param) | |
87 | { return wxXmlResourceHandler::GetColour(param); } | |
88 | ||
89 | wxSize GetSize(const wxString& param = wxT("size")) | |
90 | { return wxXmlResourceHandler::GetSize(param); } | |
91 | ||
92 | wxPoint GetPosition(const wxString& param = wxT("pos")) | |
93 | { return wxXmlResourceHandler::GetPosition(param); } | |
94 | ||
95 | wxCoord GetDimension(const wxString& param, wxCoord defaultv = 0) | |
96 | { return wxXmlResourceHandler::GetDimension(param, defaultv); } | |
97 | ||
98 | wxBitmap GetBitmap(const wxString& param = wxT("bitmap"), | |
99 | const wxArtClient& defaultArtClient = wxART_OTHER, | |
100 | wxSize size = wxDefaultSize) | |
101 | { return wxXmlResourceHandler::GetBitmap(param, defaultArtClient, size); } | |
102 | ||
103 | wxIcon GetIcon(const wxString& param = wxT("icon"), | |
104 | const wxArtClient& defaultArtClient = wxART_OTHER, | |
105 | wxSize size = wxDefaultSize) | |
106 | { return wxXmlResourceHandler::GetIcon(param, defaultArtClient, size); } | |
107 | ||
9a9ed319 RD |
108 | wxAnimation GetAnimation(const wxString& param = wxT("animation")) |
109 | { return wxXmlResourceHandler::GetAnimation(param); } | |
110 | ||
d14a1e28 RD |
111 | wxFont GetFont(const wxString& param = wxT("font")) |
112 | { return wxXmlResourceHandler::GetFont(param); } | |
113 | ||
114 | void SetupWindow(wxWindow *wnd) | |
115 | { wxXmlResourceHandler::SetupWindow(wnd); } | |
116 | ||
a72f4631 | 117 | void CreateChildren(wxObject *parent, bool this_hnd_only = false) |
d14a1e28 RD |
118 | { wxXmlResourceHandler::CreateChildren(parent, this_hnd_only); } |
119 | ||
120 | void CreateChildrenPrivately(wxObject *parent, wxXmlNode *rootnode = NULL) | |
121 | { wxXmlResourceHandler::CreateChildrenPrivately(parent, rootnode); } | |
122 | ||
123 | wxObject *CreateResFromNode(wxXmlNode *node, | |
124 | wxObject *parent, wxObject *instance = NULL) | |
125 | { return wxXmlResourceHandler::CreateResFromNode(node, parent, instance); } | |
126 | ||
127 | wxFileSystem& GetCurFileSystem() | |
128 | { return wxXmlResourceHandler::GetCurFileSystem(); } | |
129 | ||
130 | ||
131 | PYPRIVATE; | |
132 | }; | |
133 | ||
134 | IMP_PYCALLBACK_OBJECT__pure(wxPyXmlResourceHandler, wxXmlResourceHandler, DoCreateResource); | |
135 | IMP_PYCALLBACK_BOOL_NODE_pure(wxPyXmlResourceHandler, wxXmlResourceHandler, CanHandle); | |
136 | ||
137 | %} | |
138 | ||
139 | ||
140 | // Now the version that will be SWIGged. | |
141 | ||
142 | ||
1b8c7ba6 RD |
143 | %rename(XmlResourceHandler) wxPyXmlResourceHandler; |
144 | class wxPyXmlResourceHandler : public wxObject { | |
d14a1e28 | 145 | public: |
2b9048c5 | 146 | %pythonAppend wxPyXmlResourceHandler "self._setCallbackInfo(self, XmlResourceHandler)" |
d14a1e28 | 147 | wxPyXmlResourceHandler() : wxXmlResourceHandler() {} |
14cb220a | 148 | ~wxPyXmlResourceHandler(); |
d14a1e28 RD |
149 | |
150 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
151 | ||
152 | ||
153 | // Creates an object (menu, dialog, control, ...) from an XML node. | |
154 | // Should check for validity. | |
155 | // parent is a higher-level object (usually window, dialog or panel) | |
156 | // that is often neccessary to create the resource. | |
157 | // If instance is non-NULL it should not create a new instance via 'new' but | |
158 | // should rather use this one, and call its Create method. | |
159 | wxObject *CreateResource(wxXmlNode *node, wxObject *parent, | |
160 | wxObject *instance); | |
161 | ||
162 | // Sets the parent resource. | |
163 | void SetParentResource(wxXmlResource *res); | |
164 | ||
165 | ||
166 | wxXmlResource* GetResource() { return m_resource; } | |
167 | wxXmlNode* GetNode() { return m_node; } | |
168 | wxString GetClass() { return m_class; } | |
169 | wxObject* GetParent() { return m_parent; } | |
170 | wxObject* GetInstance() { return m_instance; } | |
171 | wxWindow* GetParentAsWindow() { return m_parentAsWindow; } | |
7aada1e0 | 172 | // wxWindow* GetInstanceAsWindow() { return m_instanceAsWindow; } |
d14a1e28 RD |
173 | |
174 | ||
175 | // Returns true if the node has a property class equal to classname, | |
176 | // e.g. <object class="wxDialog">. | |
177 | bool IsOfClass(wxXmlNode *node, const wxString& classname); | |
178 | ||
179 | // Gets node content from wxXML_ENTITY_NODE | |
180 | // The problem is, <tag>content<tag> is represented as | |
181 | // wxXML_ENTITY_NODE name="tag", content="" | |
182 | // |-- wxXML_TEXT_NODE or | |
183 | // wxXML_CDATA_SECTION_NODE name="" content="content" | |
184 | wxString GetNodeContent(wxXmlNode *node); | |
185 | ||
186 | // Check to see if a parameter exists. | |
187 | bool HasParam(const wxString& param); | |
188 | ||
189 | // Finds the node or returns NULL. | |
190 | wxXmlNode *GetParamNode(const wxString& param); | |
191 | ||
192 | // Finds the parameter value or returns the empty string. | |
193 | wxString GetParamValue(const wxString& param); | |
194 | ||
195 | // Add a style flag (e.g. wxMB_DOCKABLE) to the list of flags | |
196 | // understood by this handler. | |
197 | void AddStyle(const wxString& name, int value); | |
198 | ||
199 | // Add styles common to all wxWindow-derived classes. | |
200 | void AddWindowStyles(); | |
201 | ||
202 | // Gets style flags from text in form "flag | flag2| flag3 |..." | |
203 | // Only understads flags added with AddStyle | |
204 | int GetStyle(const wxString& param = wxPyStyleString, int defaults = 0); | |
205 | ||
206 | // Gets text from param and does some conversions: | |
207 | // - replaces \n, \r, \t by respective chars (according to C syntax) | |
208 | // - replaces _ by & and __ by _ (needed for _File => &File because of XML) | |
209 | // - calls wxGetTranslations (unless disabled in wxXmlResource) | |
a72f4631 | 210 | wxString GetText(const wxString& param, bool translate = true); |
d14a1e28 RD |
211 | |
212 | // Returns the XRCID. | |
213 | int GetID(); | |
214 | ||
215 | // Returns the resource name. | |
216 | wxString GetName(); | |
217 | ||
a72f4631 RD |
218 | // Gets a bool flag (1, t, yes, on, true are True, everything else is false). |
219 | bool GetBool(const wxString& param, bool defaultv = false); | |
d14a1e28 RD |
220 | |
221 | // Gets the integer value from the parameter. | |
222 | long GetLong( const wxString& param, long defaultv = 0 ); | |
223 | ||
224 | // Gets colour in HTML syntax (#RRGGBB). | |
225 | wxColour GetColour(const wxString& param); | |
226 | ||
227 | // Gets the size (may be in dialog units). | |
228 | wxSize GetSize(const wxString& param = wxPySizeString); | |
229 | ||
230 | // Gets the position (may be in dialog units). | |
231 | wxPoint GetPosition(const wxString& param = wxPyPosString); | |
232 | ||
233 | // Gets a dimension (may be in dialog units). | |
234 | wxCoord GetDimension(const wxString& param, wxCoord defaultv = 0); | |
235 | ||
236 | // Gets a bitmap. | |
237 | wxBitmap GetBitmap(const wxString& param = wxPyBitmapString, | |
238 | const wxArtClient& defaultArtClient = wxART_OTHER, | |
239 | wxSize size = wxDefaultSize); | |
240 | ||
241 | // Gets an icon. | |
242 | wxIcon GetIcon(const wxString& param = wxPyIconString, | |
243 | const wxArtClient& defaultArtClient = wxART_OTHER, | |
244 | wxSize size = wxDefaultSize); | |
245 | ||
246 | // Gets a font. | |
247 | wxFont GetFont(const wxString& param = wxPyFontString); | |
248 | ||
9a9ed319 RD |
249 | // Gets an animation. |
250 | wxAnimation GetAnimation(const wxString& param = wxPyAnimationString); | |
251 | ||
d14a1e28 RD |
252 | // Sets common window options. |
253 | void SetupWindow(wxWindow *wnd); | |
254 | ||
255 | // Creates children. | |
a72f4631 | 256 | void CreateChildren(wxObject *parent, bool this_hnd_only = false); |
d14a1e28 RD |
257 | |
258 | // Helper function. | |
259 | void CreateChildrenPrivately(wxObject *parent, wxXmlNode *rootnode = NULL); | |
260 | ||
261 | // Creates a resource from a node. | |
262 | wxObject *CreateResFromNode(wxXmlNode *node, | |
263 | wxObject *parent, wxObject *instance = NULL); | |
264 | ||
265 | // helper | |
266 | wxFileSystem& GetCurFileSystem(); | |
e70b4d2d RD |
267 | |
268 | %property(Class, GetClass, doc="See `GetClass`"); | |
269 | %property(CurFileSystem, GetCurFileSystem, doc="See `GetCurFileSystem`"); | |
270 | %property(ID, GetID, doc="See `GetID`"); | |
271 | %property(Instance, GetInstance, doc="See `GetInstance`"); | |
272 | %property(Name, GetName, doc="See `GetName`"); | |
273 | %property(Node, GetNode, doc="See `GetNode`"); | |
274 | %property(Parent, GetParent, doc="See `GetParent`"); | |
275 | %property(ParentAsWindow, GetParentAsWindow, doc="See `GetParentAsWindow`"); | |
276 | %property(Resource, GetResource, doc="See `GetResource`"); | |
d14a1e28 RD |
277 | }; |
278 | ||
279 | ||
280 | ||
281 | //--------------------------------------------------------------------------- | |
282 | //--------------------------------------------------------------------------- |