]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: _xmlres.i | |
3 | // Purpose: SWIG interface for wxXmlResource | |
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 | class wxPyXmlSubclassFactory; | |
22 | ||
23 | enum { | |
24 | WX_XMLRES_CURRENT_VERSION_MAJOR, | |
25 | WX_XMLRES_CURRENT_VERSION_MINOR, | |
26 | WX_XMLRES_CURRENT_VERSION_RELEASE, | |
27 | WX_XMLRES_CURRENT_VERSION_REVISION, | |
28 | }; | |
29 | ||
30 | ||
31 | enum wxXmlResourceFlags | |
32 | { | |
2937186c RD |
33 | wxXRC_USE_LOCALE, |
34 | wxXRC_NO_SUBCLASSING, | |
35 | wxXRC_NO_RELOADING | |
d14a1e28 RD |
36 | }; |
37 | ||
38 | ||
39 | ||
40 | // This class holds XML resources from one or more .xml files | |
41 | // (or derived forms, either binary or zipped -- see manual for | |
42 | // details). | |
43 | ||
44 | class wxXmlResource : public wxObject | |
45 | { | |
46 | public: | |
47 | ||
d4a724d4 RD |
48 | %pythonAppend wxXmlResource(const wxString& filemask, int flags, |
49 | const wxString& domain=wxEmptyString) "self.InitAllHandlers()" | |
50 | %pythonAppend wxXmlResource(int flags, | |
51 | const wxString& domain=wxEmptyString) "val.InitAllHandlers()" | |
d14a1e28 RD |
52 | |
53 | // Ctors. | |
54 | // Flags: wxXRC_USE_LOCALE | |
55 | // translatable strings will be translated via _() | |
56 | // wxXRC_NO_SUBCLASSING | |
57 | // subclass property of object nodes will be ignored | |
58 | // (useful for previews in XRC editors) | |
d4a724d4 RD |
59 | wxXmlResource(const wxString& filemask, int flags = wxXRC_USE_LOCALE, |
60 | const wxString& domain=wxEmptyString); | |
61 | %RenameCtor(EmptyXmlResource, wxXmlResource(int flags = wxXRC_USE_LOCALE, | |
62 | const wxString& domain=wxEmptyString)); | |
63 | ||
d14a1e28 RD |
64 | ~wxXmlResource(); |
65 | ||
66 | ||
67 | // Loads resources from XML files that match given filemask. | |
68 | // This method understands VFS (see filesys.h). | |
69 | bool Load(const wxString& filemask); | |
70 | ||
71 | %extend { | |
72 | bool LoadFromString(const wxString& data) { | |
73 | static int s_memFileIdx = 0; | |
74 | ||
75 | // Check for memory FS. If not present, load the handler: | |
76 | wxMemoryFSHandler::AddFile(wxT("XRC_resource/dummy_file"), | |
77 | wxT("dummy data")); | |
78 | wxFileSystem fsys; | |
79 | wxFSFile *f = fsys.OpenFile(wxT("memory:XRC_resource/dummy_file")); | |
80 | wxMemoryFSHandler::RemoveFile(wxT("XRC_resource/dummy_file")); | |
81 | if (f) | |
82 | delete f; | |
83 | else | |
84 | wxFileSystem::AddHandler(new wxMemoryFSHandler); | |
85 | ||
86 | // Now put the resource data into the memory FS | |
87 | wxString filename(wxT("XRC_resource/data_string_")); | |
88 | filename << s_memFileIdx; | |
89 | s_memFileIdx += 1; | |
90 | wxMemoryFSHandler::AddFile(filename, data); | |
91 | ||
92 | // Load the "file" into the resource object | |
93 | bool retval = self->Load(wxT("memory:") + filename ); | |
94 | ||
95 | return retval; | |
96 | } | |
97 | } | |
98 | ||
02b800ce RD |
99 | // Unload resource from the given XML file (wildcards not allowed) |
100 | bool Unload(const wxString& filename); | |
101 | ||
d14a1e28 RD |
102 | // Initialize handlers for all supported controls/windows. |
103 | void InitAllHandlers(); | |
104 | ||
14cb220a RD |
105 | |
106 | %disownarg( wxPyXmlResourceHandler *handler ); | |
107 | ||
d14a1e28 RD |
108 | // Initialize only specific handler (or custom handler). Convention says |
109 | // that handler name is equal to control's name plus 'XmlHandler', e.g. | |
110 | // wxTextCtrlXmlHandler, wxHtmlWindowXmlHandler. XML resource compiler | |
111 | // (xmlres) can create include file that contains initialization code for | |
112 | // all controls used within the resource. | |
113 | void AddHandler(wxPyXmlResourceHandler *handler); | |
114 | ||
115 | // Add a new handler at the begining of the handler list | |
116 | void InsertHandler(wxPyXmlResourceHandler *handler); | |
117 | ||
14cb220a RD |
118 | %cleardisown( wxPyXmlResourceHandler *handler ); |
119 | ||
120 | ||
d14a1e28 RD |
121 | // Removes all handlers |
122 | void ClearHandlers(); | |
123 | ||
124 | // Registers subclasses factory for use in XRC. This function is not meant | |
125 | // for public use, please see the comment above wxXmlSubclassFactory | |
126 | // definition. | |
127 | static void AddSubclassFactory(wxPyXmlSubclassFactory *factory); | |
128 | ||
129 | ||
130 | // Loads menu from resource. Returns NULL on failure. | |
131 | wxMenu *LoadMenu(const wxString& name); | |
132 | ||
133 | // Loads menubar from resource. Returns NULL on failure. | |
134 | wxMenuBar *LoadMenuBar(const wxString& name); | |
1b8c7ba6 | 135 | %Rename(LoadMenuBarOnFrame, wxMenuBar* , LoadMenuBar(wxWindow *parent, const wxString& name)); |
d14a1e28 RD |
136 | |
137 | ||
138 | // Loads toolbar | |
139 | wxToolBar *LoadToolBar(wxWindow *parent, const wxString& name); | |
140 | ||
141 | // Loads dialog. dlg points to parent window (if any). Second form | |
142 | // is used to finish creation of already existing instance (main reason | |
143 | // for this is that you may want to use derived class with new event table) | |
144 | // Example (typical usage): | |
145 | // MyDialog dlg; | |
146 | // wxTheXmlResource->LoadDialog(&dlg, mainFrame, "my_dialog"); | |
147 | // dlg->ShowModal(); | |
148 | wxDialog *LoadDialog(wxWindow *parent, const wxString& name); | |
1b8c7ba6 | 149 | %Rename(LoadOnDialog, bool, LoadDialog(wxDialog *dlg, wxWindow *parent, const wxString& name)); |
d14a1e28 RD |
150 | |
151 | // Loads panel. panel points to parent window (if any). Second form | |
152 | // is used to finish creation of already existing instance. | |
153 | wxPanel *LoadPanel(wxWindow *parent, const wxString& name); | |
1b8c7ba6 | 154 | %Rename(LoadOnPanel, bool, LoadPanel(wxPanel *panel, wxWindow *parent, const wxString& name)); |
d14a1e28 RD |
155 | |
156 | // Load a frame's contents from a resource | |
157 | wxFrame *LoadFrame(wxWindow* parent, const wxString& name); | |
1b8c7ba6 | 158 | %Rename(LoadOnFrame, bool, LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name)); |
d14a1e28 RD |
159 | |
160 | // Load an object from the resource specifying both the resource name and | |
161 | // the classname. This lets you load nonstandard container windows. | |
162 | wxObject *LoadObject(wxWindow *parent, const wxString& name, | |
163 | const wxString& classname); | |
164 | ||
165 | // Load an object from the resource specifying both the resource name and | |
166 | // the classname. This form lets you finish the creation of an existing | |
167 | // instance. | |
1b8c7ba6 RD |
168 | %Rename(LoadOnObject, bool, LoadObject(wxObject *instance, wxWindow *parent, const wxString& name, |
169 | const wxString& classname)); | |
d14a1e28 RD |
170 | |
171 | // Loads a bitmap resource from a file. | |
172 | wxBitmap LoadBitmap(const wxString& name); | |
173 | ||
174 | // Loads an icon resource from a file. | |
175 | wxIcon LoadIcon(const wxString& name); | |
176 | ||
177 | // Attaches unknown control into given panel/window/dialog: | |
178 | // (unknown controls are used in conjunction with <object class="unknown">) | |
179 | bool AttachUnknownControl(const wxString& name, wxWindow *control, | |
180 | wxWindow *parent = NULL); | |
181 | ||
7e25260c RD |
182 | // Returns a numeric ID that is equivalent to the string ID used in an XML |
183 | // resource. If an unknown str_id is requested (i.e. other than wxID_XXX | |
184 | // or integer), a new record is created which associates the given string | |
185 | // with a number. If value_if_not_found == wxID_NONE, the number is obtained via | |
186 | // wxNewId(). Otherwise value_if_not_found is used. | |
187 | // Macro XRCID(name) is provided for convenient use in event tables. | |
c15893b5 | 188 | static int GetXRCID(const wxString& str_id, int value_if_not_found = wxID_NONE); |
d14a1e28 RD |
189 | |
190 | // Returns version info (a.b.c.d = d+ 256*c + 256^2*b + 256^3*a) | |
191 | long GetVersion() const; | |
192 | ||
193 | // Compares resources version to argument. Returns -1 if resources version | |
194 | // is less than the argument, +1 if greater and 0 if they equal. | |
195 | int CompareVersion(int major, int minor, int release, int revision) const; | |
196 | ||
197 | ||
198 | // Gets global resources object or create one if none exists | |
199 | static wxXmlResource *Get(); | |
200 | // Sets global resources object and returns pointer to previous one (may be NULL). | |
201 | static wxXmlResource *Set(wxXmlResource *res); | |
202 | ||
203 | // Returns flags, which may be a bitlist of wxXRC_USE_LOCALE and wxXRC_NO_SUBCLASSING. | |
204 | int GetFlags(); | |
205 | ||
206 | // Set flags after construction. | |
207 | void SetFlags(int flags) { m_flags = flags; } | |
208 | ||
d4a724d4 RD |
209 | // Get/Set the domain to be passed to the translation functions, defaults to NULL. |
210 | wxString GetDomain() const; | |
211 | void SetDomain(const wxString& domain); | |
e70b4d2d RD |
212 | |
213 | %property(Domain, GetDomain, SetDomain, doc="See `GetDomain` and `SetDomain`"); | |
214 | %property(Flags, GetFlags, SetFlags, doc="See `GetFlags` and `SetFlags`"); | |
215 | %property(Version, GetVersion, doc="See `GetVersion`"); | |
d14a1e28 RD |
216 | }; |
217 | ||
218 | //---------------------------------------------------------------------- | |
219 | ||
220 | %pythoncode { | |
7e25260c RD |
221 | def XRCID(str_id, value_if_not_found = wx.ID_NONE): |
222 | return XmlResource_GetXRCID(str_id, value_if_not_found) | |
d14a1e28 RD |
223 | |
224 | def XRCCTRL(window, str_id, *ignoreargs): | |
225 | return window.FindWindowById(XRCID(str_id)) | |
226 | }; | |
227 | ||
228 | //--------------------------------------------------------------------------- |