]>
Commit | Line | Data |
---|---|---|
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; } | |
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 | ||
71 | wxString GetText(const wxString& param, bool translate = true) | |
72 | { return wxXmlResourceHandler::GetText(param, translate); } | |
73 | ||
74 | int GetID() | |
75 | { return wxXmlResourceHandler::GetID(); } | |
76 | ||
77 | wxString GetName() | |
78 | { return wxXmlResourceHandler::GetName(); } | |
79 | ||
80 | bool GetBool(const wxString& param, bool defaultv = false) | |
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 | ||
108 | wxFont GetFont(const wxString& param = wxT("font")) | |
109 | { return wxXmlResourceHandler::GetFont(param); } | |
110 | ||
111 | void SetupWindow(wxWindow *wnd) | |
112 | { wxXmlResourceHandler::SetupWindow(wnd); } | |
113 | ||
114 | void CreateChildren(wxObject *parent, bool this_hnd_only = false) | |
115 | { wxXmlResourceHandler::CreateChildren(parent, this_hnd_only); } | |
116 | ||
117 | void CreateChildrenPrivately(wxObject *parent, wxXmlNode *rootnode = NULL) | |
118 | { wxXmlResourceHandler::CreateChildrenPrivately(parent, rootnode); } | |
119 | ||
120 | wxObject *CreateResFromNode(wxXmlNode *node, | |
121 | wxObject *parent, wxObject *instance = NULL) | |
122 | { return wxXmlResourceHandler::CreateResFromNode(node, parent, instance); } | |
123 | ||
124 | wxFileSystem& GetCurFileSystem() | |
125 | { return wxXmlResourceHandler::GetCurFileSystem(); } | |
126 | ||
127 | ||
128 | PYPRIVATE; | |
129 | }; | |
130 | ||
131 | IMP_PYCALLBACK_OBJECT__pure(wxPyXmlResourceHandler, wxXmlResourceHandler, DoCreateResource); | |
132 | IMP_PYCALLBACK_BOOL_NODE_pure(wxPyXmlResourceHandler, wxXmlResourceHandler, CanHandle); | |
133 | ||
134 | %} | |
135 | ||
136 | ||
137 | // Now the version that will be SWIGged. | |
138 | ||
139 | ||
140 | %rename(XmlResourceHandler) wxPyXmlResourceHandler; | |
141 | class wxPyXmlResourceHandler : public wxObject { | |
142 | public: | |
143 | %pythonAppend wxPyXmlResourceHandler "self._setCallbackInfo(self, XmlResourceHandler)" | |
144 | wxPyXmlResourceHandler() : wxXmlResourceHandler() {} | |
145 | //~wxPyXmlResourceHandler(); | |
146 | ||
147 | void _setCallbackInfo(PyObject* self, PyObject* _class); | |
148 | ||
149 | ||
150 | // Creates an object (menu, dialog, control, ...) from an XML node. | |
151 | // Should check for validity. | |
152 | // parent is a higher-level object (usually window, dialog or panel) | |
153 | // that is often neccessary to create the resource. | |
154 | // If instance is non-NULL it should not create a new instance via 'new' but | |
155 | // should rather use this one, and call its Create method. | |
156 | wxObject *CreateResource(wxXmlNode *node, wxObject *parent, | |
157 | wxObject *instance); | |
158 | ||
159 | // Sets the parent resource. | |
160 | void SetParentResource(wxXmlResource *res); | |
161 | ||
162 | ||
163 | wxXmlResource* GetResource() { return m_resource; } | |
164 | wxXmlNode* GetNode() { return m_node; } | |
165 | wxString GetClass() { return m_class; } | |
166 | wxObject* GetParent() { return m_parent; } | |
167 | wxObject* GetInstance() { return m_instance; } | |
168 | wxWindow* GetParentAsWindow() { return m_parentAsWindow; } | |
169 | // wxWindow* GetInstanceAsWindow() { return m_instanceAsWindow; } | |
170 | ||
171 | ||
172 | // Returns true if the node has a property class equal to classname, | |
173 | // e.g. <object class="wxDialog">. | |
174 | bool IsOfClass(wxXmlNode *node, const wxString& classname); | |
175 | ||
176 | // Gets node content from wxXML_ENTITY_NODE | |
177 | // The problem is, <tag>content<tag> is represented as | |
178 | // wxXML_ENTITY_NODE name="tag", content="" | |
179 | // |-- wxXML_TEXT_NODE or | |
180 | // wxXML_CDATA_SECTION_NODE name="" content="content" | |
181 | wxString GetNodeContent(wxXmlNode *node); | |
182 | ||
183 | // Check to see if a parameter exists. | |
184 | bool HasParam(const wxString& param); | |
185 | ||
186 | // Finds the node or returns NULL. | |
187 | wxXmlNode *GetParamNode(const wxString& param); | |
188 | ||
189 | // Finds the parameter value or returns the empty string. | |
190 | wxString GetParamValue(const wxString& param); | |
191 | ||
192 | // Add a style flag (e.g. wxMB_DOCKABLE) to the list of flags | |
193 | // understood by this handler. | |
194 | void AddStyle(const wxString& name, int value); | |
195 | ||
196 | // Add styles common to all wxWindow-derived classes. | |
197 | void AddWindowStyles(); | |
198 | ||
199 | // Gets style flags from text in form "flag | flag2| flag3 |..." | |
200 | // Only understads flags added with AddStyle | |
201 | int GetStyle(const wxString& param = wxPyStyleString, int defaults = 0); | |
202 | ||
203 | // Gets text from param and does some conversions: | |
204 | // - replaces \n, \r, \t by respective chars (according to C syntax) | |
205 | // - replaces _ by & and __ by _ (needed for _File => &File because of XML) | |
206 | // - calls wxGetTranslations (unless disabled in wxXmlResource) | |
207 | wxString GetText(const wxString& param, bool translate = true); | |
208 | ||
209 | // Returns the XRCID. | |
210 | int GetID(); | |
211 | ||
212 | // Returns the resource name. | |
213 | wxString GetName(); | |
214 | ||
215 | // Gets a bool flag (1, t, yes, on, true are True, everything else is false). | |
216 | bool GetBool(const wxString& param, bool defaultv = false); | |
217 | ||
218 | // Gets the integer value from the parameter. | |
219 | long GetLong( const wxString& param, long defaultv = 0 ); | |
220 | ||
221 | // Gets colour in HTML syntax (#RRGGBB). | |
222 | wxColour GetColour(const wxString& param); | |
223 | ||
224 | // Gets the size (may be in dialog units). | |
225 | wxSize GetSize(const wxString& param = wxPySizeString); | |
226 | ||
227 | // Gets the position (may be in dialog units). | |
228 | wxPoint GetPosition(const wxString& param = wxPyPosString); | |
229 | ||
230 | // Gets a dimension (may be in dialog units). | |
231 | wxCoord GetDimension(const wxString& param, wxCoord defaultv = 0); | |
232 | ||
233 | // Gets a bitmap. | |
234 | wxBitmap GetBitmap(const wxString& param = wxPyBitmapString, | |
235 | const wxArtClient& defaultArtClient = wxART_OTHER, | |
236 | wxSize size = wxDefaultSize); | |
237 | ||
238 | // Gets an icon. | |
239 | wxIcon GetIcon(const wxString& param = wxPyIconString, | |
240 | const wxArtClient& defaultArtClient = wxART_OTHER, | |
241 | wxSize size = wxDefaultSize); | |
242 | ||
243 | // Gets a font. | |
244 | wxFont GetFont(const wxString& param = wxPyFontString); | |
245 | ||
246 | // Sets common window options. | |
247 | void SetupWindow(wxWindow *wnd); | |
248 | ||
249 | // Creates children. | |
250 | void CreateChildren(wxObject *parent, bool this_hnd_only = false); | |
251 | ||
252 | // Helper function. | |
253 | void CreateChildrenPrivately(wxObject *parent, wxXmlNode *rootnode = NULL); | |
254 | ||
255 | // Creates a resource from a node. | |
256 | wxObject *CreateResFromNode(wxXmlNode *node, | |
257 | wxObject *parent, wxObject *instance = NULL); | |
258 | ||
259 | // helper | |
260 | wxFileSystem& GetCurFileSystem(); | |
261 | }; | |
262 | ||
263 | ||
264 | ||
265 | //--------------------------------------------------------------------------- | |
266 | //--------------------------------------------------------------------------- |