]>
Commit | Line | Data |
---|---|---|
78d14f80 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: xmlres.cpp | |
b5d6954b | 3 | // Purpose: XRC resources |
78d14f80 VS |
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 | #ifdef __GNUG__ | |
12 | #pragma implementation "xmlres.h" | |
13 | #endif | |
14 | ||
15 | // For compilers that support precompilation, includes "wx.h". | |
16 | #include "wx/wxprec.h" | |
17 | ||
18 | #ifdef __BORLANDC__ | |
19 | #pragma hdrstop | |
20 | #endif | |
21 | ||
621be1ec | 22 | #if wxUSE_XRC |
a1e4ec87 | 23 | |
1df61962 VS |
24 | #include <locale.h> |
25 | ||
78d14f80 VS |
26 | #include "wx/dialog.h" |
27 | #include "wx/panel.h" | |
28 | #include "wx/frame.h" | |
29 | #include "wx/wfstream.h" | |
30 | #include "wx/filesys.h" | |
317a0d73 | 31 | #include "wx/filename.h" |
78d14f80 VS |
32 | #include "wx/log.h" |
33 | #include "wx/intl.h" | |
34 | #include "wx/tokenzr.h" | |
35 | #include "wx/fontenum.h" | |
36 | #include "wx/module.h" | |
37 | #include "wx/bitmap.h" | |
38 | #include "wx/image.h" | |
39 | #include "wx/fontmap.h" | |
af1337b0 | 40 | #include "wx/artprov.h" |
32efded3 | 41 | #include "wx/settings.h" |
78d14f80 | 42 | |
34c6bbee | 43 | #include "wx/xml/xml.h" |
78d14f80 VS |
44 | #include "wx/xrc/xmlres.h" |
45 | ||
46 | #include "wx/arrimpl.cpp" | |
47 | WX_DEFINE_OBJARRAY(wxXmlResourceDataRecords); | |
48 | ||
49 | ||
824e8eaa VS |
50 | wxXmlResource *wxXmlResource::ms_instance = NULL; |
51 | ||
52 | /*static*/ wxXmlResource *wxXmlResource::Get() | |
53 | { | |
54 | if ( !ms_instance ) | |
55 | ms_instance = new wxXmlResource; | |
56 | return ms_instance; | |
57 | } | |
58 | ||
59 | /*static*/ wxXmlResource *wxXmlResource::Set(wxXmlResource *res) | |
60 | { | |
61 | wxXmlResource *old = ms_instance; | |
62 | ms_instance = res; | |
63 | return old; | |
64 | } | |
65 | ||
daa85ee3 | 66 | wxXmlResource::wxXmlResource(int flags) |
78d14f80 | 67 | { |
daa85ee3 | 68 | m_flags = flags; |
78d14f80 VS |
69 | m_version = -1; |
70 | } | |
71 | ||
daa85ee3 | 72 | wxXmlResource::wxXmlResource(const wxString& filemask, int flags) |
78d14f80 | 73 | { |
daa85ee3 | 74 | m_flags = flags; |
78d14f80 | 75 | m_version = -1; |
78d14f80 VS |
76 | Load(filemask); |
77 | } | |
78 | ||
79 | wxXmlResource::~wxXmlResource() | |
80 | { | |
81 | ClearHandlers(); | |
82 | } | |
83 | ||
84 | ||
85 | bool wxXmlResource::Load(const wxString& filemask) | |
86 | { | |
87 | wxString fnd; | |
88 | wxXmlResourceDataRecord *drec; | |
89 | bool iswild = wxIsWild(filemask); | |
f80ea77b | 90 | bool rt = true; |
78d14f80 VS |
91 | |
92 | #if wxUSE_FILESYSTEM | |
93 | wxFileSystem fsys; | |
94 | # define wxXmlFindFirst fsys.FindFirst(filemask, wxFILE) | |
95 | # define wxXmlFindNext fsys.FindNext() | |
96 | #else | |
97 | # define wxXmlFindFirst wxFindFirstFile(filemask, wxFILE) | |
98 | # define wxXmlFindNext wxFindNextFile() | |
99 | #endif | |
100 | if (iswild) | |
101 | fnd = wxXmlFindFirst; | |
102 | else | |
103 | fnd = filemask; | |
104 | while (!!fnd) | |
105 | { | |
317a0d73 VS |
106 | // NB: Load() accepts both filenames and URLs (should probably be |
107 | // changed to filenames only, but embedded resources currently | |
108 | // rely on its ability to handle URLs - FIXME). This check | |
109 | // serves as a quick way to determine whether found name is | |
110 | // filename and not URL: | |
111 | if (wxFileName::FileExists(fnd)) | |
112 | { | |
b380439d | 113 | // Make the name absolute filename, because the app may |
317a0d73 VS |
114 | // change working directory later: |
115 | wxFileName fn(fnd); | |
116 | if (fn.IsRelative()) | |
117 | { | |
56acdfef | 118 | fn.MakeAbsolute(); |
317a0d73 VS |
119 | fnd = fn.GetFullPath(); |
120 | } | |
75d38380 VS |
121 | #if wxUSE_FILESYSTEM |
122 | fnd = wxFileSystem::FileNameToURL(fnd); | |
123 | #endif | |
317a0d73 | 124 | } |
b380439d | 125 | |
78d14f80 | 126 | #if wxUSE_FILESYSTEM |
317a0d73 VS |
127 | if (fnd.Lower().Matches(wxT("*.zip")) || |
128 | fnd.Lower().Matches(wxT("*.xrs"))) | |
78d14f80 | 129 | { |
f9d243a3 | 130 | rt = rt && Load(fnd + wxT("#zip:*.xrc")); |
78d14f80 VS |
131 | } |
132 | else | |
133 | #endif | |
134 | { | |
135 | drec = new wxXmlResourceDataRecord; | |
136 | drec->File = fnd; | |
137 | m_data.Add(drec); | |
138 | } | |
139 | ||
140 | if (iswild) | |
141 | fnd = wxXmlFindNext; | |
142 | else | |
143 | fnd = wxEmptyString; | |
144 | } | |
145 | # undef wxXmlFindFirst | |
146 | # undef wxXmlFindNext | |
d614f51b | 147 | return rt && UpdateResources(); |
78d14f80 VS |
148 | } |
149 | ||
150 | ||
854e189f | 151 | IMPLEMENT_ABSTRACT_CLASS(wxXmlResourceHandler, wxObject) |
78d14f80 VS |
152 | |
153 | void wxXmlResource::AddHandler(wxXmlResourceHandler *handler) | |
154 | { | |
155 | m_handlers.Append(handler); | |
156 | handler->SetParentResource(this); | |
157 | } | |
158 | ||
92e898b0 RD |
159 | void wxXmlResource::InsertHandler(wxXmlResourceHandler *handler) |
160 | { | |
161 | m_handlers.Insert(handler); | |
162 | handler->SetParentResource(this); | |
163 | } | |
164 | ||
78d14f80 VS |
165 | |
166 | ||
167 | void wxXmlResource::ClearHandlers() | |
168 | { | |
461932ae | 169 | WX_CLEAR_LIST(wxList, m_handlers); |
78d14f80 VS |
170 | } |
171 | ||
172 | ||
78d14f80 VS |
173 | wxMenu *wxXmlResource::LoadMenu(const wxString& name) |
174 | { | |
175 | return (wxMenu*)CreateResFromNode(FindResource(name, wxT("wxMenu")), NULL, NULL); | |
176 | } | |
177 | ||
178 | ||
179 | ||
4a1b9596 | 180 | wxMenuBar *wxXmlResource::LoadMenuBar(wxWindow *parent, const wxString& name) |
78d14f80 | 181 | { |
4a1b9596 | 182 | return (wxMenuBar*)CreateResFromNode(FindResource(name, wxT("wxMenuBar")), parent, NULL); |
78d14f80 VS |
183 | } |
184 | ||
185 | ||
186 | ||
4a1b9596 | 187 | #if wxUSE_TOOLBAR |
78d14f80 VS |
188 | wxToolBar *wxXmlResource::LoadToolBar(wxWindow *parent, const wxString& name) |
189 | { | |
190 | return (wxToolBar*)CreateResFromNode(FindResource(name, wxT("wxToolBar")), parent, NULL); | |
191 | } | |
4a1b9596 | 192 | #endif |
78d14f80 VS |
193 | |
194 | ||
195 | wxDialog *wxXmlResource::LoadDialog(wxWindow *parent, const wxString& name) | |
196 | { | |
4dd75a6a | 197 | return (wxDialog*)CreateResFromNode(FindResource(name, wxT("wxDialog")), parent, NULL); |
78d14f80 VS |
198 | } |
199 | ||
200 | bool wxXmlResource::LoadDialog(wxDialog *dlg, wxWindow *parent, const wxString& name) | |
201 | { | |
202 | return CreateResFromNode(FindResource(name, wxT("wxDialog")), parent, dlg) != NULL; | |
203 | } | |
204 | ||
205 | ||
206 | ||
207 | wxPanel *wxXmlResource::LoadPanel(wxWindow *parent, const wxString& name) | |
208 | { | |
209 | return (wxPanel*)CreateResFromNode(FindResource(name, wxT("wxPanel")), parent, NULL); | |
210 | } | |
211 | ||
212 | bool wxXmlResource::LoadPanel(wxPanel *panel, wxWindow *parent, const wxString& name) | |
213 | { | |
214 | return CreateResFromNode(FindResource(name, wxT("wxPanel")), parent, panel) != NULL; | |
215 | } | |
216 | ||
92e898b0 RD |
217 | wxFrame *wxXmlResource::LoadFrame(wxWindow* parent, const wxString& name) |
218 | { | |
219 | return (wxFrame*)CreateResFromNode(FindResource(name, wxT("wxFrame")), parent, NULL); | |
220 | } | |
221 | ||
78d14f80 VS |
222 | bool wxXmlResource::LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name) |
223 | { | |
224 | return CreateResFromNode(FindResource(name, wxT("wxFrame")), parent, frame) != NULL; | |
225 | } | |
226 | ||
227 | wxBitmap wxXmlResource::LoadBitmap(const wxString& name) | |
228 | { | |
229 | wxBitmap *bmp = (wxBitmap*)CreateResFromNode( | |
230 | FindResource(name, wxT("wxBitmap")), NULL, NULL); | |
231 | wxBitmap rt; | |
232 | ||
233 | if (bmp) { rt = *bmp; delete bmp; } | |
234 | return rt; | |
235 | } | |
236 | ||
237 | wxIcon wxXmlResource::LoadIcon(const wxString& name) | |
238 | { | |
239 | wxIcon *icon = (wxIcon*)CreateResFromNode( | |
240 | FindResource(name, wxT("wxIcon")), NULL, NULL); | |
241 | wxIcon rt; | |
242 | ||
243 | if (icon) { rt = *icon; delete icon; } | |
244 | return rt; | |
245 | } | |
246 | ||
92e898b0 RD |
247 | |
248 | wxObject *wxXmlResource::LoadObject(wxWindow *parent, const wxString& name, const wxString& classname) | |
249 | { | |
250 | return CreateResFromNode(FindResource(name, classname), parent, NULL); | |
251 | } | |
252 | ||
253 | bool wxXmlResource::LoadObject(wxObject *instance, wxWindow *parent, const wxString& name, const wxString& classname) | |
254 | { | |
255 | return CreateResFromNode(FindResource(name, classname), parent, instance) != NULL; | |
256 | } | |
257 | ||
258 | ||
78d14f80 VS |
259 | bool wxXmlResource::AttachUnknownControl(const wxString& name, |
260 | wxWindow *control, wxWindow *parent) | |
261 | { | |
262 | if (parent == NULL) | |
263 | parent = control->GetParent(); | |
264 | wxWindow *container = parent->FindWindow(name + wxT("_container")); | |
265 | if (!container) | |
266 | { | |
267 | wxLogError(_("Cannot find container for unknown control '%s'."), name.c_str()); | |
f80ea77b | 268 | return false; |
78d14f80 VS |
269 | } |
270 | return control->Reparent(container); | |
271 | } | |
272 | ||
273 | ||
77b2f9b1 | 274 | static void ProcessPlatformProperty(wxXmlNode *node) |
78d14f80 VS |
275 | { |
276 | wxString s; | |
277 | bool isok; | |
278 | ||
279 | wxXmlNode *c = node->GetChildren(); | |
280 | while (c) | |
281 | { | |
f80ea77b | 282 | isok = false; |
78d14f80 | 283 | if (!c->GetPropVal(wxT("platform"), &s)) |
f80ea77b | 284 | isok = true; |
78d14f80 VS |
285 | else |
286 | { | |
2b5f62a0 | 287 | wxStringTokenizer tkn(s, wxT(" |")); |
78d14f80 VS |
288 | |
289 | while (tkn.HasMoreTokens()) | |
290 | { | |
291 | s = tkn.GetNextToken(); | |
84389518 | 292 | #ifdef __WINDOWS__ |
d003330c VS |
293 | if (s == wxT("win")) isok = true; |
294 | #endif | |
b380439d | 295 | #if defined(__MAC__) || defined(__APPLE__) |
d003330c | 296 | if (s == wxT("mac")) isok = true; |
b380439d RD |
297 | #elif defined(__UNIX__) |
298 | if (s == wxT("unix")) isok = true; | |
78d14f80 | 299 | #endif |
d003330c VS |
300 | #ifdef __OS2__ |
301 | if (s == wxT("os2")) isok = true; | |
302 | #endif | |
303 | ||
304 | if (isok) | |
305 | break; | |
78d14f80 VS |
306 | } |
307 | } | |
308 | ||
309 | if (isok) | |
d7b1d73c | 310 | { |
78d14f80 | 311 | ProcessPlatformProperty(c); |
d7b1d73c VS |
312 | c = c->GetNext(); |
313 | } | |
78d14f80 VS |
314 | else |
315 | { | |
d7b1d73c | 316 | wxXmlNode *c2 = c->GetNext(); |
db59a97c | 317 | node->RemoveChild(c); |
78d14f80 | 318 | delete c; |
d7b1d73c | 319 | c = c2; |
78d14f80 | 320 | } |
78d14f80 VS |
321 | } |
322 | } | |
323 | ||
324 | ||
325 | ||
d614f51b | 326 | bool wxXmlResource::UpdateResources() |
78d14f80 | 327 | { |
d614f51b | 328 | bool rt = true; |
78d14f80 VS |
329 | bool modif; |
330 | # if wxUSE_FILESYSTEM | |
331 | wxFSFile *file = NULL; | |
19d0f58d | 332 | wxUnusedVar(file); |
78d14f80 VS |
333 | wxFileSystem fsys; |
334 | # endif | |
335 | ||
480505bc VS |
336 | wxString encoding(wxT("UTF-8")); |
337 | #if !wxUSE_UNICODE && wxUSE_INTL | |
338 | if ( (GetFlags() & wxXRC_USE_LOCALE) == 0 ) | |
339 | { | |
75d38380 VS |
340 | // In case we are not using wxLocale to translate strings, convert the |
341 | // strings GUI's charset. This must not be done when wxXRC_USE_LOCALE | |
342 | // is on, because it could break wxGetTranslation lookup. | |
480505bc VS |
343 | encoding = wxLocale::GetSystemEncodingName(); |
344 | } | |
345 | #endif | |
346 | ||
78d14f80 VS |
347 | for (size_t i = 0; i < m_data.GetCount(); i++) |
348 | { | |
349 | modif = (m_data[i].Doc == NULL); | |
350 | ||
648db587 | 351 | if (!modif && !(m_flags & wxXRC_NO_RELOADING)) |
78d14f80 VS |
352 | { |
353 | # if wxUSE_FILESYSTEM | |
354 | file = fsys.OpenFile(m_data[i].File); | |
355 | modif = file && file->GetModificationTime() > m_data[i].Time; | |
356 | if (!file) | |
d614f51b | 357 | { |
78d14f80 | 358 | wxLogError(_("Cannot open file '%s'."), m_data[i].File.c_str()); |
d614f51b VS |
359 | rt = false; |
360 | } | |
78d14f80 | 361 | wxDELETE(file); |
19d0f58d | 362 | wxUnusedVar(file); |
78d14f80 VS |
363 | # else |
364 | modif = wxDateTime(wxFileModificationTime(m_data[i].File)) > m_data[i].Time; | |
365 | # endif | |
366 | } | |
367 | ||
368 | if (modif) | |
369 | { | |
648db587 VS |
370 | wxLogTrace(_T("xrc"), |
371 | _T("opening file '%s'"), m_data[i].File.c_str()); | |
372 | ||
480505bc | 373 | wxInputStream *stream = NULL; |
78d14f80 VS |
374 | |
375 | # if wxUSE_FILESYSTEM | |
376 | file = fsys.OpenFile(m_data[i].File); | |
f80ea77b WS |
377 | if (file) |
378 | stream = file->GetStream(); | |
78d14f80 VS |
379 | # else |
380 | stream = new wxFileInputStream(m_data[i].File); | |
381 | # endif | |
382 | ||
383 | if (stream) | |
384 | { | |
385 | delete m_data[i].Doc; | |
386 | m_data[i].Doc = new wxXmlDocument; | |
387 | } | |
4d876ee3 | 388 | if (!stream || !m_data[i].Doc->Load(*stream, encoding)) |
78d14f80 | 389 | { |
480505bc VS |
390 | wxLogError(_("Cannot load resources from file '%s'."), |
391 | m_data[i].File.c_str()); | |
78d14f80 | 392 | wxDELETE(m_data[i].Doc); |
d614f51b | 393 | rt = false; |
78d14f80 VS |
394 | } |
395 | else if (m_data[i].Doc->GetRoot()->GetName() != wxT("resource")) | |
396 | { | |
b5d6954b | 397 | wxLogError(_("Invalid XRC resource '%s': doesn't have root node 'resource'."), m_data[i].File.c_str()); |
78d14f80 | 398 | wxDELETE(m_data[i].Doc); |
d614f51b | 399 | rt = false; |
78d14f80 VS |
400 | } |
401 | else | |
f80ea77b | 402 | { |
78d14f80 VS |
403 | long version; |
404 | int v1, v2, v3, v4; | |
405 | wxString verstr = m_data[i].Doc->GetRoot()->GetPropVal( | |
406 | wxT("version"), wxT("0.0.0.0")); | |
407 | if (wxSscanf(verstr.c_str(), wxT("%i.%i.%i.%i"), | |
408 | &v1, &v2, &v3, &v4) == 4) | |
409 | version = v1*256*256*256+v2*256*256+v3*256+v4; | |
410 | else | |
411 | version = 0; | |
412 | if (m_version == -1) | |
413 | m_version = version; | |
414 | if (m_version != version) | |
d614f51b | 415 | { |
78d14f80 | 416 | wxLogError(_("Resource files must have same version number!")); |
d614f51b VS |
417 | rt = false; |
418 | } | |
78d14f80 VS |
419 | |
420 | ProcessPlatformProperty(m_data[i].Doc->GetRoot()); | |
496f0a58 | 421 | #if wxUSE_FILESYSTEM |
f80ea77b | 422 | m_data[i].Time = file->GetModificationTime(); |
496f0a58 VS |
423 | #else |
424 | m_data[i].Time = wxDateTime(wxFileModificationTime(m_data[i].File)); | |
425 | #endif | |
f80ea77b | 426 | } |
78d14f80 VS |
427 | |
428 | # if wxUSE_FILESYSTEM | |
f80ea77b WS |
429 | wxDELETE(file); |
430 | wxUnusedVar(file); | |
78d14f80 | 431 | # else |
f80ea77b | 432 | wxDELETE(stream); |
78d14f80 VS |
433 | # endif |
434 | } | |
435 | } | |
d614f51b VS |
436 | |
437 | return rt; | |
78d14f80 VS |
438 | } |
439 | ||
440 | ||
b272b6dc RD |
441 | wxXmlNode *wxXmlResource::DoFindResource(wxXmlNode *parent, |
442 | const wxString& name, | |
443 | const wxString& classname, | |
47793ab8 VS |
444 | bool recursive) |
445 | { | |
446 | wxString dummy; | |
447 | wxXmlNode *node; | |
448 | ||
449 | // first search for match at the top-level nodes (as this is | |
450 | // where the resource is most commonly looked for): | |
451 | for (node = parent->GetChildren(); node; node = node->GetNext()) | |
452 | { | |
b272b6dc RD |
453 | if ( node->GetType() == wxXML_ELEMENT_NODE && |
454 | (node->GetName() == wxT("object") || | |
47793ab8 | 455 | node->GetName() == wxT("object_ref")) && |
2b5f62a0 VZ |
456 | node->GetPropVal(wxT("name"), &dummy) && dummy == name ) |
457 | { | |
458 | wxString cls(node->GetPropVal(wxT("class"), wxEmptyString)); | |
459 | if (!classname || cls == classname) | |
460 | return node; | |
461 | // object_ref may not have 'class' property: | |
462 | if (cls.empty() && node->GetName() == wxT("object_ref")) | |
463 | { | |
464 | wxString refName = node->GetPropVal(wxT("ref"), wxEmptyString); | |
465 | if (refName.empty()) | |
466 | continue; | |
f80ea77b | 467 | wxXmlNode* refNode = FindResource(refName, wxEmptyString, true); |
2b5f62a0 VZ |
468 | if (refNode && |
469 | refNode->GetPropVal(wxT("class"), wxEmptyString) == classname) | |
470 | { | |
471 | return node; | |
472 | } | |
473 | } | |
474 | } | |
47793ab8 VS |
475 | } |
476 | ||
477 | if ( recursive ) | |
478 | for (node = parent->GetChildren(); node; node = node->GetNext()) | |
479 | { | |
b272b6dc RD |
480 | if ( node->GetType() == wxXML_ELEMENT_NODE && |
481 | (node->GetName() == wxT("object") || | |
47793ab8 VS |
482 | node->GetName() == wxT("object_ref")) ) |
483 | { | |
f80ea77b | 484 | wxXmlNode* found = DoFindResource(node, name, classname, true); |
47793ab8 VS |
485 | if ( found ) |
486 | return found; | |
487 | } | |
488 | } | |
489 | ||
490 | return NULL; | |
491 | } | |
78d14f80 | 492 | |
b272b6dc | 493 | wxXmlNode *wxXmlResource::FindResource(const wxString& name, |
47793ab8 VS |
494 | const wxString& classname, |
495 | bool recursive) | |
78d14f80 VS |
496 | { |
497 | UpdateResources(); //ensure everything is up-to-date | |
498 | ||
499 | wxString dummy; | |
500 | for (size_t f = 0; f < m_data.GetCount(); f++) | |
501 | { | |
47793ab8 VS |
502 | if ( m_data[f].Doc == NULL || m_data[f].Doc->GetRoot() == NULL ) |
503 | continue; | |
504 | ||
b272b6dc | 505 | wxXmlNode* found = DoFindResource(m_data[f].Doc->GetRoot(), |
47793ab8 VS |
506 | name, classname, recursive); |
507 | if ( found ) | |
508 | { | |
78d14f80 | 509 | #if wxUSE_FILESYSTEM |
47793ab8 | 510 | m_curFileSystem.ChangePathTo(m_data[f].File); |
78d14f80 | 511 | #endif |
47793ab8 VS |
512 | return found; |
513 | } | |
78d14f80 VS |
514 | } |
515 | ||
b5d6954b | 516 | wxLogError(_("XRC resource '%s' (class '%s') not found!"), |
78d14f80 VS |
517 | name.c_str(), classname.c_str()); |
518 | return NULL; | |
519 | } | |
520 | ||
47793ab8 VS |
521 | static void MergeNodes(wxXmlNode& dest, wxXmlNode& with) |
522 | { | |
523 | // Merge properties: | |
524 | for (wxXmlProperty *prop = with.GetProperties(); prop; prop = prop->GetNext()) | |
525 | { | |
526 | wxXmlProperty *dprop; | |
527 | for (dprop = dest.GetProperties(); dprop; dprop = dprop->GetNext()) | |
528 | { | |
b272b6dc | 529 | |
47793ab8 VS |
530 | if ( dprop->GetName() == prop->GetName() ) |
531 | { | |
532 | dprop->SetValue(prop->GetValue()); | |
533 | break; | |
534 | } | |
535 | } | |
78d14f80 | 536 | |
47793ab8 VS |
537 | if ( !dprop ) |
538 | dest.AddProperty(prop->GetName(), prop->GetValue()); | |
539 | } | |
540 | ||
541 | // Merge child nodes: | |
542 | for (wxXmlNode* node = with.GetChildren(); node; node = node->GetNext()) | |
543 | { | |
544 | wxString name = node->GetPropVal(wxT("name"), wxEmptyString); | |
545 | wxXmlNode *dnode; | |
546 | ||
547 | for (dnode = dest.GetChildren(); dnode; dnode = dnode->GetNext() ) | |
548 | { | |
549 | if ( dnode->GetName() == node->GetName() && | |
2b5f62a0 | 550 | dnode->GetPropVal(wxT("name"), wxEmptyString) == name && |
47793ab8 VS |
551 | dnode->GetType() == node->GetType() ) |
552 | { | |
553 | MergeNodes(*dnode, *node); | |
554 | break; | |
555 | } | |
556 | } | |
557 | ||
558 | if ( !dnode ) | |
559 | dest.AddChild(new wxXmlNode(*node)); | |
560 | } | |
561 | ||
562 | if ( dest.GetType() == wxXML_TEXT_NODE && with.GetContent().Length() ) | |
563 | dest.SetContent(with.GetContent()); | |
564 | } | |
78d14f80 | 565 | |
317a0d73 VS |
566 | wxObject *wxXmlResource::CreateResFromNode(wxXmlNode *node, wxObject *parent, |
567 | wxObject *instance, | |
568 | wxXmlResourceHandler *handlerToUse) | |
78d14f80 VS |
569 | { |
570 | if (node == NULL) return NULL; | |
571 | ||
47793ab8 VS |
572 | // handling of referenced resource |
573 | if ( node->GetName() == wxT("object_ref") ) | |
574 | { | |
575 | wxString refName = node->GetPropVal(wxT("ref"), wxEmptyString); | |
f80ea77b | 576 | wxXmlNode* refNode = FindResource(refName, wxEmptyString, true); |
47793ab8 VS |
577 | |
578 | if ( !refNode ) | |
579 | { | |
b272b6dc | 580 | wxLogError(_("Referenced object node with ref=\"%s\" not found!"), |
47793ab8 VS |
581 | refName.c_str()); |
582 | return NULL; | |
583 | } | |
584 | ||
585 | wxXmlNode copy(*refNode); | |
586 | MergeNodes(copy, *node); | |
587 | ||
588 | return CreateResFromNode(©, parent, instance); | |
589 | } | |
590 | ||
78d14f80 | 591 | wxXmlResourceHandler *handler; |
317a0d73 VS |
592 | |
593 | if (handlerToUse) | |
b380439d | 594 | { |
317a0d73 | 595 | if (handlerToUse->CanHandle(node)) |
78d14f80 | 596 | { |
317a0d73 VS |
597 | return handlerToUse->CreateResource(node, parent, instance); |
598 | } | |
599 | } | |
600 | else if (node->GetName() == wxT("object")) | |
b380439d | 601 | { |
461932ae | 602 | wxList::compatibility_iterator ND = m_handlers.GetFirst(); |
317a0d73 VS |
603 | while (ND) |
604 | { | |
605 | handler = (wxXmlResourceHandler*)ND->GetData(); | |
606 | if (handler->CanHandle(node)) | |
607 | { | |
608 | return handler->CreateResource(node, parent, instance); | |
609 | } | |
610 | ND = ND->GetNext(); | |
78d14f80 | 611 | } |
78d14f80 VS |
612 | } |
613 | ||
614 | wxLogError(_("No handler found for XML node '%s', class '%s'!"), | |
615 | node->GetName().c_str(), | |
616 | node->GetPropVal(wxT("class"), wxEmptyString).c_str()); | |
617 | return NULL; | |
618 | } | |
619 | ||
620 | ||
2b5f62a0 VZ |
621 | #include "wx/listimpl.cpp" |
622 | WX_DECLARE_LIST(wxXmlSubclassFactory, wxXmlSubclassFactoriesList); | |
623 | WX_DEFINE_LIST(wxXmlSubclassFactoriesList); | |
624 | ||
625 | wxXmlSubclassFactoriesList *wxXmlResource::ms_subclassFactories = NULL; | |
626 | ||
627 | /*static*/ void wxXmlResource::AddSubclassFactory(wxXmlSubclassFactory *factory) | |
628 | { | |
629 | if (!ms_subclassFactories) | |
630 | { | |
631 | ms_subclassFactories = new wxXmlSubclassFactoriesList; | |
2b5f62a0 VZ |
632 | } |
633 | ms_subclassFactories->Append(factory); | |
634 | } | |
635 | ||
636 | class wxXmlSubclassFactoryCXX : public wxXmlSubclassFactory | |
637 | { | |
638 | public: | |
639 | ~wxXmlSubclassFactoryCXX() {} | |
640 | ||
641 | wxObject *Create(const wxString& className) | |
642 | { | |
643 | wxClassInfo* classInfo = wxClassInfo::FindClass(className); | |
644 | ||
645 | if (classInfo) | |
646 | return classInfo->CreateObject(); | |
647 | else | |
648 | return NULL; | |
649 | } | |
650 | }; | |
651 | ||
652 | ||
653 | ||
78d14f80 | 654 | |
78d14f80 VS |
655 | wxXmlResourceHandler::wxXmlResourceHandler() |
656 | : m_node(NULL), m_parent(NULL), m_instance(NULL), | |
9a8d8c5a | 657 | m_parentAsWindow(NULL) |
78d14f80 VS |
658 | {} |
659 | ||
660 | ||
661 | ||
662 | wxObject *wxXmlResourceHandler::CreateResource(wxXmlNode *node, wxObject *parent, wxObject *instance) | |
663 | { | |
664 | wxXmlNode *myNode = m_node; | |
665 | wxString myClass = m_class; | |
666 | wxObject *myParent = m_parent, *myInstance = m_instance; | |
9a8d8c5a | 667 | wxWindow *myParentAW = m_parentAsWindow; |
78d14f80 | 668 | |
daa85ee3 | 669 | m_instance = instance; |
b272b6dc | 670 | if (!m_instance && node->HasProp(wxT("subclass")) && |
daa85ee3 VS |
671 | !(m_resource->GetFlags() & wxXRC_NO_SUBCLASSING)) |
672 | { | |
673 | wxString subclass = node->GetPropVal(wxT("subclass"), wxEmptyString); | |
2b5f62a0 | 674 | if (!subclass.empty()) |
daa85ee3 | 675 | { |
461932ae | 676 | for (wxXmlSubclassFactoriesList::compatibility_iterator i = wxXmlResource::ms_subclassFactories->GetFirst(); |
2b5f62a0 VZ |
677 | i; i = i->GetNext()) |
678 | { | |
679 | m_instance = i->GetData()->Create(subclass); | |
680 | if (m_instance) | |
681 | break; | |
682 | } | |
daa85ee3 | 683 | |
2b5f62a0 VZ |
684 | if (!m_instance) |
685 | { | |
686 | wxString name = node->GetPropVal(wxT("name"), wxEmptyString); | |
687 | wxLogError(_("Subclass '%s' not found for resource '%s', not subclassing!"), | |
688 | subclass.c_str(), name.c_str()); | |
689 | } | |
690 | } | |
daa85ee3 VS |
691 | } |
692 | ||
78d14f80 VS |
693 | m_node = node; |
694 | m_class = node->GetPropVal(wxT("class"), wxEmptyString); | |
695 | m_parent = parent; | |
78d14f80 | 696 | m_parentAsWindow = wxDynamicCast(m_parent, wxWindow); |
78d14f80 VS |
697 | |
698 | wxObject *returned = DoCreateResource(); | |
699 | ||
700 | m_node = myNode; | |
701 | m_class = myClass; | |
702 | m_parent = myParent; m_parentAsWindow = myParentAW; | |
9a8d8c5a | 703 | m_instance = myInstance; |
78d14f80 VS |
704 | |
705 | return returned; | |
706 | } | |
707 | ||
708 | ||
709 | void wxXmlResourceHandler::AddStyle(const wxString& name, int value) | |
710 | { | |
711 | m_styleNames.Add(name); | |
712 | m_styleValues.Add(value); | |
713 | } | |
714 | ||
715 | ||
716 | ||
717 | void wxXmlResourceHandler::AddWindowStyles() | |
718 | { | |
9dc579b3 | 719 | XRC_ADD_STYLE(wxCLIP_CHILDREN); |
daa85ee3 VS |
720 | XRC_ADD_STYLE(wxSIMPLE_BORDER); |
721 | XRC_ADD_STYLE(wxSUNKEN_BORDER); | |
722 | XRC_ADD_STYLE(wxDOUBLE_BORDER); | |
723 | XRC_ADD_STYLE(wxRAISED_BORDER); | |
724 | XRC_ADD_STYLE(wxSTATIC_BORDER); | |
725 | XRC_ADD_STYLE(wxNO_BORDER); | |
726 | XRC_ADD_STYLE(wxTRANSPARENT_WINDOW); | |
727 | XRC_ADD_STYLE(wxWANTS_CHARS); | |
728 | XRC_ADD_STYLE(wxNO_FULL_REPAINT_ON_RESIZE); | |
7539ba56 | 729 | XRC_ADD_STYLE(wxFULL_REPAINT_ON_RESIZE); |
9f4ed861 | 730 | XRC_ADD_STYLE(wxWS_EX_BLOCK_EVENTS); |
78d14f80 VS |
731 | } |
732 | ||
733 | ||
734 | ||
735 | bool wxXmlResourceHandler::HasParam(const wxString& param) | |
736 | { | |
737 | return (GetParamNode(param) != NULL); | |
738 | } | |
739 | ||
740 | ||
741 | int wxXmlResourceHandler::GetStyle(const wxString& param, int defaults) | |
742 | { | |
743 | wxString s = GetParamValue(param); | |
744 | ||
745 | if (!s) return defaults; | |
746 | ||
2b5f62a0 | 747 | wxStringTokenizer tkn(s, wxT("| \t\n"), wxTOKEN_STRTOK); |
78d14f80 VS |
748 | int style = 0; |
749 | int index; | |
750 | wxString fl; | |
751 | while (tkn.HasMoreTokens()) | |
752 | { | |
753 | fl = tkn.GetNextToken(); | |
754 | index = m_styleNames.Index(fl); | |
755 | if (index != wxNOT_FOUND) | |
756 | style |= m_styleValues[index]; | |
757 | else | |
758 | wxLogError(_("Unknown style flag ") + fl); | |
759 | } | |
760 | return style; | |
761 | } | |
762 | ||
763 | ||
764 | ||
ee1046d1 | 765 | wxString wxXmlResourceHandler::GetText(const wxString& param, bool translate) |
78d14f80 | 766 | { |
7b56015f VS |
767 | wxXmlNode *parNode = GetParamNode(param); |
768 | wxString str1(GetNodeContent(parNode)); | |
78d14f80 VS |
769 | wxString str2; |
770 | const wxChar *dt; | |
771 | wxChar amp_char; | |
772 | ||
b272b6dc RD |
773 | // VS: First version of XRC resources used $ instead of & (which is |
774 | // illegal in XML), but later I realized that '_' fits this purpose | |
718cf160 | 775 | // much better (because &File means "File with F underlined"). |
78d14f80 VS |
776 | if (m_resource->CompareVersion(2,3,0,1) < 0) |
777 | amp_char = wxT('$'); | |
778 | else | |
779 | amp_char = wxT('_'); | |
780 | ||
781 | for (dt = str1.c_str(); *dt; dt++) | |
782 | { | |
783 | // Remap amp_char to &, map double amp_char to amp_char (for things | |
784 | // like "&File..." -- this is illegal in XML, so we use "_File..."): | |
785 | if (*dt == amp_char) | |
786 | { | |
787 | if ( *(++dt) == amp_char ) | |
788 | str2 << amp_char; | |
789 | else | |
790 | str2 << wxT('&') << *dt; | |
791 | } | |
984c33c9 | 792 | // Remap \n to CR, \r to LF, \t to TAB, \\ to \: |
78d14f80 VS |
793 | else if (*dt == wxT('\\')) |
794 | switch (*(++dt)) | |
795 | { | |
984c33c9 VS |
796 | case wxT('n'): |
797 | str2 << wxT('\n'); | |
798 | break; | |
799 | ||
800 | case wxT('t'): | |
801 | str2 << wxT('\t'); | |
802 | break; | |
803 | ||
804 | case wxT('r'): | |
805 | str2 << wxT('\r'); | |
806 | break; | |
807 | ||
808 | case wxT('\\') : | |
809 | // "\\" wasn't translated to "\" prior to 2.5.3.0: | |
810 | if (m_resource->CompareVersion(2,5,3,0) >= 0) | |
811 | { | |
812 | str2 << wxT('\\'); | |
813 | break; | |
814 | } | |
815 | // else fall-through to default: branch below | |
816 | ||
817 | default: | |
818 | str2 << wxT('\\') << *dt; | |
819 | break; | |
78d14f80 VS |
820 | } |
821 | else str2 << *dt; | |
822 | } | |
b272b6dc | 823 | |
7b56015f VS |
824 | if (m_resource->GetFlags() & wxXRC_USE_LOCALE) |
825 | { | |
826 | if (translate && parNode && | |
827 | parNode->GetPropVal(wxT("translate"), wxEmptyString) != wxT("0")) | |
828 | { | |
829 | return wxGetTranslation(str2); | |
830 | } | |
831 | else | |
832 | { | |
833 | #if wxUSE_UNICODE | |
834 | return str2; | |
835 | #else | |
836 | // The string is internally stored as UTF-8, we have to convert | |
837 | // it into system's default encoding so that it can be displayed: | |
838 | return wxString(str2.mb_str(wxConvUTF8), wxConvLocal); | |
839 | #endif | |
840 | } | |
841 | } | |
718cf160 | 842 | else |
7b56015f VS |
843 | { |
844 | // If wxXRC_USE_LOCALE is not set, then the string is already in | |
845 | // system's default encoding in ANSI build, so we don't have to | |
846 | // do anything special here. | |
718cf160 | 847 | return str2; |
7b56015f | 848 | } |
78d14f80 VS |
849 | } |
850 | ||
851 | ||
852 | ||
853 | long wxXmlResourceHandler::GetLong(const wxString& param, long defaultv) | |
854 | { | |
855 | long value; | |
856 | wxString str1 = GetParamValue(param); | |
857 | ||
858 | if (!str1.ToLong(&value)) | |
859 | value = defaultv; | |
860 | ||
861 | return value; | |
862 | } | |
1df61962 VS |
863 | |
864 | float wxXmlResourceHandler::GetFloat(const wxString& param, float defaultv) | |
865 | { | |
866 | double value; | |
867 | wxString str1 = GetParamValue(param); | |
868 | ||
869 | const char *prevlocale = setlocale(LC_NUMERIC, "C"); | |
870 | ||
871 | if (!str1.ToDouble(&value)) | |
872 | value = defaultv; | |
873 | ||
874 | setlocale(LC_NUMERIC, prevlocale); | |
78d14f80 | 875 | |
1df61962 VS |
876 | return value; |
877 | } | |
78d14f80 | 878 | |
af1337b0 | 879 | |
78d14f80 VS |
880 | int wxXmlResourceHandler::GetID() |
881 | { | |
13de23f6 | 882 | return wxXmlResource::GetXRCID(GetName()); |
78d14f80 VS |
883 | } |
884 | ||
885 | ||
af1337b0 | 886 | |
78d14f80 VS |
887 | wxString wxXmlResourceHandler::GetName() |
888 | { | |
889 | return m_node->GetPropVal(wxT("name"), wxT("-1")); | |
890 | } | |
891 | ||
892 | ||
893 | ||
894 | bool wxXmlResourceHandler::GetBool(const wxString& param, bool defaultv) | |
895 | { | |
896 | wxString v = GetParamValue(param); | |
897 | v.MakeLower(); | |
898 | if (!v) return defaultv; | |
899 | else return (v == wxT("1")); | |
900 | } | |
901 | ||
902 | ||
1df61962 VS |
903 | static wxColour GetSystemColour(const wxString& name) |
904 | { | |
905 | if (!name.empty()) | |
906 | { | |
907 | #define SYSCLR(clr) \ | |
908 | if (name == _T(#clr)) return wxSystemSettings::GetColour(clr); | |
909 | SYSCLR(wxSYS_COLOUR_SCROLLBAR) | |
910 | SYSCLR(wxSYS_COLOUR_BACKGROUND) | |
911 | SYSCLR(wxSYS_COLOUR_DESKTOP) | |
912 | SYSCLR(wxSYS_COLOUR_ACTIVECAPTION) | |
913 | SYSCLR(wxSYS_COLOUR_INACTIVECAPTION) | |
914 | SYSCLR(wxSYS_COLOUR_MENU) | |
915 | SYSCLR(wxSYS_COLOUR_WINDOW) | |
916 | SYSCLR(wxSYS_COLOUR_WINDOWFRAME) | |
917 | SYSCLR(wxSYS_COLOUR_MENUTEXT) | |
918 | SYSCLR(wxSYS_COLOUR_WINDOWTEXT) | |
919 | SYSCLR(wxSYS_COLOUR_CAPTIONTEXT) | |
920 | SYSCLR(wxSYS_COLOUR_ACTIVEBORDER) | |
921 | SYSCLR(wxSYS_COLOUR_INACTIVEBORDER) | |
922 | SYSCLR(wxSYS_COLOUR_APPWORKSPACE) | |
923 | SYSCLR(wxSYS_COLOUR_HIGHLIGHT) | |
924 | SYSCLR(wxSYS_COLOUR_HIGHLIGHTTEXT) | |
925 | SYSCLR(wxSYS_COLOUR_BTNFACE) | |
926 | SYSCLR(wxSYS_COLOUR_3DFACE) | |
927 | SYSCLR(wxSYS_COLOUR_BTNSHADOW) | |
928 | SYSCLR(wxSYS_COLOUR_3DSHADOW) | |
929 | SYSCLR(wxSYS_COLOUR_GRAYTEXT) | |
930 | SYSCLR(wxSYS_COLOUR_BTNTEXT) | |
931 | SYSCLR(wxSYS_COLOUR_INACTIVECAPTIONTEXT) | |
932 | SYSCLR(wxSYS_COLOUR_BTNHIGHLIGHT) | |
933 | SYSCLR(wxSYS_COLOUR_BTNHILIGHT) | |
934 | SYSCLR(wxSYS_COLOUR_3DHIGHLIGHT) | |
935 | SYSCLR(wxSYS_COLOUR_3DHILIGHT) | |
936 | SYSCLR(wxSYS_COLOUR_3DDKSHADOW) | |
937 | SYSCLR(wxSYS_COLOUR_3DLIGHT) | |
938 | SYSCLR(wxSYS_COLOUR_INFOTEXT) | |
939 | SYSCLR(wxSYS_COLOUR_INFOBK) | |
940 | SYSCLR(wxSYS_COLOUR_LISTBOX) | |
941 | SYSCLR(wxSYS_COLOUR_HOTLIGHT) | |
942 | SYSCLR(wxSYS_COLOUR_GRADIENTACTIVECAPTION) | |
943 | SYSCLR(wxSYS_COLOUR_GRADIENTINACTIVECAPTION) | |
944 | SYSCLR(wxSYS_COLOUR_MENUHILIGHT) | |
945 | SYSCLR(wxSYS_COLOUR_MENUBAR) | |
946 | #undef SYSCLR | |
947 | } | |
948 | ||
949 | return wxNullColour; | |
950 | } | |
78d14f80 VS |
951 | |
952 | wxColour wxXmlResourceHandler::GetColour(const wxString& param) | |
953 | { | |
954 | wxString v = GetParamValue(param); | |
1df61962 VS |
955 | |
956 | // find colour using HTML syntax (#RRGGBB) | |
78d14f80 VS |
957 | unsigned long tmp = 0; |
958 | ||
959 | if (v.Length() != 7 || v[0u] != wxT('#') || | |
960 | wxSscanf(v.c_str(), wxT("#%lX"), &tmp) != 1) | |
961 | { | |
1df61962 VS |
962 | // the colour doesn't use #RRGGBB format, check if it is symbolic |
963 | // colour name: | |
964 | wxColour clr = GetSystemColour(v); | |
965 | if (clr.Ok()) | |
966 | return clr; | |
967 | ||
b5d6954b | 968 | wxLogError(_("XRC resource: Incorrect colour specification '%s' for property '%s'."), |
78d14f80 VS |
969 | v.c_str(), param.c_str()); |
970 | return wxNullColour; | |
971 | } | |
972 | ||
973 | return wxColour((unsigned char) ((tmp & 0xFF0000) >> 16) , | |
974 | (unsigned char) ((tmp & 0x00FF00) >> 8), | |
975 | (unsigned char) ((tmp & 0x0000FF))); | |
976 | } | |
977 | ||
978 | ||
979 | ||
92e898b0 | 980 | wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param, |
db59a97c VS |
981 | const wxArtClient& defaultArtClient, |
982 | wxSize size) | |
78d14f80 | 983 | { |
db59a97c VS |
984 | /* If the bitmap is specified as stock item, query wxArtProvider for it: */ |
985 | wxXmlNode *bmpNode = GetParamNode(param); | |
986 | if ( bmpNode ) | |
af1337b0 | 987 | { |
db59a97c VS |
988 | wxString sid = bmpNode->GetPropVal(wxT("stock_id"), wxEmptyString); |
989 | if ( !sid.empty() ) | |
990 | { | |
b3e85292 VS |
991 | wxString scl = bmpNode->GetPropVal(wxT("stock_client"), wxEmptyString); |
992 | if (scl.empty()) | |
993 | scl = defaultArtClient; | |
994 | else | |
995 | scl = wxART_MAKE_CLIENT_ID_FROM_STR(scl); | |
996 | ||
92e898b0 | 997 | wxBitmap stockArt = |
db59a97c | 998 | wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(sid), |
b3e85292 | 999 | scl, size); |
db59a97c VS |
1000 | if ( stockArt.Ok() ) |
1001 | return stockArt; | |
1002 | } | |
af1337b0 JS |
1003 | } |
1004 | ||
92e898b0 | 1005 | /* ...or load the bitmap from file: */ |
78d14f80 | 1006 | wxString name = GetParamValue(param); |
92e898b0 | 1007 | if (name.IsEmpty()) return wxNullBitmap; |
78d14f80 VS |
1008 | #if wxUSE_FILESYSTEM |
1009 | wxFSFile *fsfile = GetCurFileSystem().OpenFile(name); | |
1010 | if (fsfile == NULL) | |
1011 | { | |
d0b50ad9 VS |
1012 | wxLogError(_("XRC resource: Cannot create bitmap from '%s'."), |
1013 | name.c_str()); | |
78d14f80 VS |
1014 | return wxNullBitmap; |
1015 | } | |
1016 | wxImage img(*(fsfile->GetStream())); | |
1017 | delete fsfile; | |
1018 | #else | |
1019 | wxImage img(GetParamValue(wxT("bitmap"))); | |
1020 | #endif | |
af1337b0 | 1021 | |
78d14f80 VS |
1022 | if (!img.Ok()) |
1023 | { | |
1df61962 VS |
1024 | wxLogError(_("XRC resource: Cannot create bitmap from '%s'."), |
1025 | param.c_str()); | |
78d14f80 VS |
1026 | return wxNullBitmap; |
1027 | } | |
1028 | if (!(size == wxDefaultSize)) img.Rescale(size.x, size.y); | |
b272b6dc | 1029 | return wxBitmap(img); |
af1337b0 | 1030 | |
78d14f80 VS |
1031 | } |
1032 | ||
1033 | ||
1034 | ||
92e898b0 | 1035 | wxIcon wxXmlResourceHandler::GetIcon(const wxString& param, |
db59a97c VS |
1036 | const wxArtClient& defaultArtClient, |
1037 | wxSize size) | |
78d14f80 | 1038 | { |
78d14f80 | 1039 | wxIcon icon; |
db59a97c | 1040 | icon.CopyFromBitmap(GetBitmap(param, defaultArtClient, size)); |
78d14f80 VS |
1041 | return icon; |
1042 | } | |
1043 | ||
1044 | ||
1045 | ||
1046 | wxXmlNode *wxXmlResourceHandler::GetParamNode(const wxString& param) | |
1047 | { | |
2b5f62a0 VZ |
1048 | wxCHECK_MSG(m_node, NULL, wxT("You can't access handler data before it was initialized!")); |
1049 | ||
78d14f80 VS |
1050 | wxXmlNode *n = m_node->GetChildren(); |
1051 | ||
1052 | while (n) | |
1053 | { | |
1054 | if (n->GetType() == wxXML_ELEMENT_NODE && n->GetName() == param) | |
1055 | return n; | |
1056 | n = n->GetNext(); | |
1057 | } | |
1058 | return NULL; | |
1059 | } | |
1060 | ||
1061 | ||
1062 | wxString wxXmlResourceHandler::GetNodeContent(wxXmlNode *node) | |
1063 | { | |
1064 | wxXmlNode *n = node; | |
1065 | if (n == NULL) return wxEmptyString; | |
1066 | n = n->GetChildren(); | |
1067 | ||
1068 | while (n) | |
1069 | { | |
1070 | if (n->GetType() == wxXML_TEXT_NODE || | |
1071 | n->GetType() == wxXML_CDATA_SECTION_NODE) | |
1072 | return n->GetContent(); | |
1073 | n = n->GetNext(); | |
1074 | } | |
1075 | return wxEmptyString; | |
1076 | } | |
1077 | ||
1078 | ||
1079 | ||
1080 | wxString wxXmlResourceHandler::GetParamValue(const wxString& param) | |
1081 | { | |
1082 | if (param.IsEmpty()) | |
1083 | return GetNodeContent(m_node); | |
1084 | else | |
1085 | return GetNodeContent(GetParamNode(param)); | |
1086 | } | |
1087 | ||
1088 | ||
1089 | ||
1090 | wxSize wxXmlResourceHandler::GetSize(const wxString& param) | |
1091 | { | |
1092 | wxString s = GetParamValue(param); | |
1093 | if (s.IsEmpty()) s = wxT("-1,-1"); | |
1094 | bool is_dlg; | |
d1f47235 | 1095 | long sx, sy = 0; |
78d14f80 VS |
1096 | |
1097 | is_dlg = s[s.Length()-1] == wxT('d'); | |
1098 | if (is_dlg) s.RemoveLast(); | |
1099 | ||
1100 | if (!s.BeforeFirst(wxT(',')).ToLong(&sx) || | |
1101 | !s.AfterLast(wxT(',')).ToLong(&sy)) | |
1102 | { | |
00393283 | 1103 | wxLogError(_("Cannot parse coordinates from '%s'."), s.c_str()); |
78d14f80 VS |
1104 | return wxDefaultSize; |
1105 | } | |
1106 | ||
1107 | if (is_dlg) | |
1108 | { | |
9a8d8c5a | 1109 | if (m_parentAsWindow) |
78d14f80 VS |
1110 | return wxDLG_UNIT(m_parentAsWindow, wxSize(sx, sy)); |
1111 | else | |
1112 | { | |
1113 | wxLogError(_("Cannot convert dialog units: dialog unknown.")); | |
1114 | return wxDefaultSize; | |
1115 | } | |
1116 | } | |
1117 | else return wxSize(sx, sy); | |
1118 | } | |
1119 | ||
1120 | ||
1121 | ||
1122 | wxPoint wxXmlResourceHandler::GetPosition(const wxString& param) | |
1123 | { | |
1124 | wxSize sz = GetSize(param); | |
1125 | return wxPoint(sz.x, sz.y); | |
1126 | } | |
1127 | ||
1128 | ||
1129 | ||
1130 | wxCoord wxXmlResourceHandler::GetDimension(const wxString& param, wxCoord defaultv) | |
1131 | { | |
1132 | wxString s = GetParamValue(param); | |
1133 | if (s.IsEmpty()) return defaultv; | |
1134 | bool is_dlg; | |
1135 | long sx; | |
1136 | ||
1137 | is_dlg = s[s.Length()-1] == wxT('d'); | |
1138 | if (is_dlg) s.RemoveLast(); | |
1139 | ||
1140 | if (!s.ToLong(&sx)) | |
1141 | { | |
00393283 | 1142 | wxLogError(_("Cannot parse dimension from '%s'."), s.c_str()); |
78d14f80 VS |
1143 | return defaultv; |
1144 | } | |
1145 | ||
1146 | if (is_dlg) | |
1147 | { | |
9a8d8c5a | 1148 | if (m_parentAsWindow) |
78d14f80 VS |
1149 | return wxDLG_UNIT(m_parentAsWindow, wxSize(sx, 0)).x; |
1150 | else | |
1151 | { | |
1152 | wxLogError(_("Cannot convert dialog units: dialog unknown.")); | |
1153 | return defaultv; | |
1154 | } | |
1155 | } | |
1156 | else return sx; | |
1157 | } | |
1158 | ||
1159 | ||
1df61962 VS |
1160 | // Get system font index using indexname |
1161 | static wxFont GetSystemFont(const wxString& name) | |
1162 | { | |
1163 | if (!name.empty()) | |
1164 | { | |
1165 | #define SYSFNT(fnt) \ | |
1166 | if (name == _T(#fnt)) return wxSystemSettings::GetFont(fnt); | |
1167 | SYSFNT(wxSYS_OEM_FIXED_FONT) | |
1168 | SYSFNT(wxSYS_ANSI_FIXED_FONT) | |
1169 | SYSFNT(wxSYS_ANSI_VAR_FONT) | |
1170 | SYSFNT(wxSYS_SYSTEM_FONT) | |
1171 | SYSFNT(wxSYS_DEVICE_DEFAULT_FONT) | |
1172 | SYSFNT(wxSYS_DEFAULT_PALETTE) | |
1173 | SYSFNT(wxSYS_SYSTEM_FIXED_FONT) | |
1174 | SYSFNT(wxSYS_DEFAULT_GUI_FONT) | |
1175 | #undef SYSFNT | |
1176 | } | |
1177 | ||
1178 | return wxNullFont; | |
1179 | } | |
78d14f80 VS |
1180 | |
1181 | wxFont wxXmlResourceHandler::GetFont(const wxString& param) | |
1182 | { | |
1183 | wxXmlNode *font_node = GetParamNode(param); | |
1184 | if (font_node == NULL) | |
1185 | { | |
00393283 | 1186 | wxLogError(_("Cannot find font node '%s'."), param.c_str()); |
78d14f80 VS |
1187 | return wxNullFont; |
1188 | } | |
1189 | ||
1190 | wxXmlNode *oldnode = m_node; | |
1191 | m_node = font_node; | |
1192 | ||
1df61962 | 1193 | // font attributes: |
78d14f80 | 1194 | |
1df61962 VS |
1195 | // size |
1196 | int isize = wxDEFAULT; | |
1197 | bool hasSize = HasParam(wxT("size")); | |
1198 | if (hasSize) | |
1199 | isize = GetLong(wxT("size"), wxDEFAULT); | |
78d14f80 | 1200 | |
1df61962 VS |
1201 | // style |
1202 | int istyle = wxNORMAL; | |
1203 | bool hasStyle = HasParam(wxT("style")); | |
1204 | if (hasStyle) | |
1205 | { | |
1206 | wxString style = GetParamValue(wxT("style")); | |
1207 | if (style == wxT("italic")) | |
1208 | istyle = wxITALIC; | |
1209 | else if (style == wxT("slant")) | |
1210 | istyle = wxSLANT; | |
1211 | } | |
78d14f80 | 1212 | |
1df61962 VS |
1213 | // weight |
1214 | int iweight = wxNORMAL; | |
1215 | bool hasWeight = HasParam(wxT("weight")); | |
1216 | if (hasWeight) | |
1217 | { | |
1218 | wxString weight = GetParamValue(wxT("weight")); | |
1219 | if (weight == wxT("bold")) | |
1220 | iweight = wxBOLD; | |
1221 | else if (weight == wxT("light")) | |
1222 | iweight = wxLIGHT; | |
1223 | } | |
1224 | ||
1225 | // underline | |
1226 | bool hasUnderlined = HasParam(wxT("underlined")); | |
1227 | bool underlined = hasUnderlined ? GetBool(wxT("underlined"), false) : false; | |
78d14f80 | 1228 | |
1df61962 VS |
1229 | // family and facename |
1230 | int ifamily = wxDEFAULT; | |
1231 | bool hasFamily = HasParam(wxT("family")); | |
1232 | if (hasFamily) | |
78d14f80 | 1233 | { |
1df61962 VS |
1234 | wxString family = GetParamValue(wxT("family")); |
1235 | if (family == wxT("decorative")) ifamily = wxDECORATIVE; | |
1236 | else if (family == wxT("roman")) ifamily = wxROMAN; | |
1237 | else if (family == wxT("script")) ifamily = wxSCRIPT; | |
1238 | else if (family == wxT("swiss")) ifamily = wxSWISS; | |
1239 | else if (family == wxT("modern")) ifamily = wxMODERN; | |
1240 | else if (family == wxT("teletype")) ifamily = wxTELETYPE; | |
1241 | } | |
1242 | ||
1243 | ||
1244 | wxString facename; | |
1245 | bool hasFacename = HasParam(wxT("face")); | |
1246 | if (hasFacename) | |
1247 | { | |
1248 | wxString faces = GetParamValue(wxT("face")); | |
1249 | wxFontEnumerator enu; | |
1250 | enu.EnumerateFacenames(); | |
1251 | wxStringTokenizer tk(faces, wxT(",")); | |
1252 | while (tk.HasMoreTokens()) | |
78d14f80 | 1253 | { |
1df61962 VS |
1254 | int index = enu.GetFacenames()->Index(tk.GetNextToken(), false); |
1255 | if (index != wxNOT_FOUND) | |
1256 | { | |
1257 | facename = (*enu.GetFacenames())[index]; | |
1258 | break; | |
1259 | } | |
78d14f80 VS |
1260 | } |
1261 | } | |
1262 | ||
1df61962 VS |
1263 | // encoding |
1264 | wxFontEncoding enc = wxFONTENCODING_DEFAULT; | |
1265 | bool hasEncoding = HasParam(wxT("encoding")); | |
1266 | if (hasEncoding) | |
1267 | { | |
1268 | wxString encoding = GetParamValue(wxT("encoding")); | |
1269 | wxFontMapper mapper; | |
1270 | if (!encoding.IsEmpty()) | |
1271 | enc = mapper.CharsetToEncoding(encoding); | |
1272 | if (enc == wxFONTENCODING_SYSTEM) | |
1273 | enc = wxFONTENCODING_DEFAULT; | |
1274 | } | |
78d14f80 | 1275 | |
1df61962 VS |
1276 | // is this font based on a system font? |
1277 | wxFont sysfont = GetSystemFont(GetParamValue(wxT("sysfont"))); | |
1278 | ||
1279 | if (sysfont.Ok()) | |
1280 | { | |
1281 | if (hasSize) | |
1282 | sysfont.SetPointSize(isize); | |
1283 | else if (HasParam(wxT("relativesize"))) | |
1284 | sysfont.SetPointSize(int(sysfont.GetPointSize() * | |
1285 | GetFloat(wxT("relativesize")))); | |
1286 | ||
1287 | if (hasStyle) | |
1288 | sysfont.SetStyle(istyle); | |
1289 | if (hasWeight) | |
1290 | sysfont.SetWeight(iweight); | |
1291 | if (hasUnderlined) | |
1292 | sysfont.SetUnderlined(underlined); | |
1293 | if (hasFamily) | |
1294 | sysfont.SetFamily(ifamily); | |
1295 | if (hasFacename) | |
1296 | sysfont.SetFaceName(facename); | |
1297 | if (hasEncoding) | |
1298 | sysfont.SetDefaultEncoding(enc); | |
1299 | ||
1300 | m_node = oldnode; | |
1301 | return sysfont; | |
1302 | } | |
1303 | else | |
1304 | { | |
1305 | m_node = oldnode; | |
1306 | return wxFont(isize, ifamily, istyle, iweight, | |
1307 | underlined, facename, enc); | |
1308 | } | |
78d14f80 VS |
1309 | } |
1310 | ||
1311 | ||
1312 | void wxXmlResourceHandler::SetupWindow(wxWindow *wnd) | |
1313 | { | |
1314 | //FIXME : add cursor | |
1315 | ||
1316 | if (HasParam(wxT("exstyle"))) | |
0099f343 JS |
1317 | // Have to OR it with existing style, since |
1318 | // some implementations (e.g. wxGTK) use the extra style | |
1319 | // during creation | |
1320 | wnd->SetExtraStyle(wnd->GetExtraStyle() | GetStyle(wxT("exstyle"))); | |
78d14f80 VS |
1321 | if (HasParam(wxT("bg"))) |
1322 | wnd->SetBackgroundColour(GetColour(wxT("bg"))); | |
1323 | if (HasParam(wxT("fg"))) | |
1324 | wnd->SetForegroundColour(GetColour(wxT("fg"))); | |
1325 | if (GetBool(wxT("enabled"), 1) == 0) | |
f80ea77b | 1326 | wnd->Enable(false); |
78d14f80 VS |
1327 | if (GetBool(wxT("focused"), 0) == 1) |
1328 | wnd->SetFocus(); | |
1329 | if (GetBool(wxT("hidden"), 0) == 1) | |
f80ea77b | 1330 | wnd->Show(false); |
78d14f80 VS |
1331 | #if wxUSE_TOOLTIPS |
1332 | if (HasParam(wxT("tooltip"))) | |
1333 | wnd->SetToolTip(GetText(wxT("tooltip"))); | |
1334 | #endif | |
1335 | if (HasParam(wxT("font"))) | |
1336 | wnd->SetFont(GetFont()); | |
1337 | } | |
1338 | ||
1339 | ||
1340 | void wxXmlResourceHandler::CreateChildren(wxObject *parent, bool this_hnd_only) | |
1341 | { | |
1342 | wxXmlNode *n = m_node->GetChildren(); | |
1343 | ||
1344 | while (n) | |
1345 | { | |
1346 | if (n->GetType() == wxXML_ELEMENT_NODE && | |
0fa2e104 | 1347 | (n->GetName() == wxT("object") || n->GetName() == wxT("object_ref"))) |
78d14f80 | 1348 | { |
317a0d73 VS |
1349 | m_resource->CreateResFromNode(n, parent, NULL, |
1350 | this_hnd_only ? this : NULL); | |
78d14f80 VS |
1351 | } |
1352 | n = n->GetNext(); | |
1353 | } | |
1354 | } | |
1355 | ||
1356 | ||
1357 | void wxXmlResourceHandler::CreateChildrenPrivately(wxObject *parent, wxXmlNode *rootnode) | |
1358 | { | |
1359 | wxXmlNode *root; | |
1360 | if (rootnode == NULL) root = m_node; else root = rootnode; | |
1361 | wxXmlNode *n = root->GetChildren(); | |
1362 | ||
1363 | while (n) | |
1364 | { | |
1365 | if (n->GetType() == wxXML_ELEMENT_NODE && CanHandle(n)) | |
1366 | { | |
1367 | CreateResource(n, parent, NULL); | |
1368 | } | |
1369 | n = n->GetNext(); | |
1370 | } | |
1371 | } | |
1372 | ||
1373 | ||
1374 | ||
1375 | ||
1376 | ||
1377 | ||
1378 | ||
5ed345b7 | 1379 | // --------------- XRCID implementation ----------------------------- |
78d14f80 | 1380 | |
5ed345b7 | 1381 | #define XRCID_TABLE_SIZE 1024 |
78d14f80 VS |
1382 | |
1383 | ||
5ed345b7 | 1384 | struct XRCID_record |
78d14f80 VS |
1385 | { |
1386 | int id; | |
00393283 | 1387 | wxChar *key; |
5ed345b7 | 1388 | XRCID_record *next; |
78d14f80 VS |
1389 | }; |
1390 | ||
5ed345b7 | 1391 | static XRCID_record *XRCID_Records[XRCID_TABLE_SIZE] = {NULL}; |
78d14f80 | 1392 | |
13de23f6 | 1393 | static int XRCID_Lookup(const wxChar *str_id, int value_if_not_found = -2) |
78d14f80 | 1394 | { |
78d14f80 VS |
1395 | int index = 0; |
1396 | ||
00393283 | 1397 | for (const wxChar *c = str_id; *c != wxT('\0'); c++) index += (int)*c; |
5ed345b7 | 1398 | index %= XRCID_TABLE_SIZE; |
78d14f80 | 1399 | |
5ed345b7 | 1400 | XRCID_record *oldrec = NULL; |
5ed345b7 | 1401 | for (XRCID_record *rec = XRCID_Records[index]; rec; rec = rec->next) |
78d14f80 | 1402 | { |
00393283 | 1403 | if (wxStrcmp(rec->key, str_id) == 0) |
78d14f80 VS |
1404 | { |
1405 | return rec->id; | |
1406 | } | |
78d14f80 VS |
1407 | oldrec = rec; |
1408 | } | |
1409 | ||
5ed345b7 VS |
1410 | XRCID_record **rec_var = (oldrec == NULL) ? |
1411 | &XRCID_Records[index] : &oldrec->next; | |
1412 | *rec_var = new XRCID_record; | |
00393283 | 1413 | (*rec_var)->key = wxStrdup(str_id); |
78d14f80 VS |
1414 | (*rec_var)->next = NULL; |
1415 | ||
85452d74 | 1416 | wxChar *end; |
13de23f6 VS |
1417 | if (value_if_not_found != -2) |
1418 | (*rec_var)->id = value_if_not_found; | |
85452d74 VS |
1419 | else |
1420 | { | |
13de23f6 VS |
1421 | int asint = wxStrtol(str_id, &end, 10); |
1422 | if (*str_id && *end == 0) | |
1423 | { | |
1424 | // if str_id was integer, keep it verbosely: | |
1425 | (*rec_var)->id = asint; | |
1426 | } | |
1427 | else | |
1428 | { | |
3a301301 | 1429 | (*rec_var)->id = wxNewId(); |
13de23f6 | 1430 | } |
85452d74 VS |
1431 | } |
1432 | ||
78d14f80 VS |
1433 | return (*rec_var)->id; |
1434 | } | |
1435 | ||
13de23f6 VS |
1436 | /*static*/ int wxXmlResource::GetXRCID(const wxChar *str_id) |
1437 | { | |
1438 | return XRCID_Lookup(str_id); | |
1439 | } | |
1440 | ||
78d14f80 | 1441 | |
5ed345b7 | 1442 | static void CleanXRCID_Record(XRCID_record *rec) |
78d14f80 VS |
1443 | { |
1444 | if (rec) | |
1445 | { | |
5ed345b7 | 1446 | CleanXRCID_Record(rec->next); |
00393283 | 1447 | free(rec->key); |
78d14f80 VS |
1448 | delete rec; |
1449 | } | |
1450 | } | |
1451 | ||
5ed345b7 | 1452 | static void CleanXRCID_Records() |
78d14f80 | 1453 | { |
5ed345b7 | 1454 | for (int i = 0; i < XRCID_TABLE_SIZE; i++) |
139c5871 | 1455 | { |
5ed345b7 | 1456 | CleanXRCID_Record(XRCID_Records[i]); |
139c5871 VS |
1457 | XRCID_Records[i] = NULL; |
1458 | } | |
78d14f80 VS |
1459 | } |
1460 | ||
13de23f6 VS |
1461 | static void AddStdXRCID_Records() |
1462 | { | |
1463 | #define stdID(id) XRCID_Lookup(wxT(#id), id) | |
1464 | stdID(-1); | |
c369d4f1 VS |
1465 | |
1466 | stdID(wxID_ANY); | |
1467 | stdID(wxID_SEPARATOR); | |
1468 | ||
1469 | stdID(wxID_OPEN); | |
1470 | stdID(wxID_CLOSE); | |
1471 | stdID(wxID_NEW); | |
1472 | stdID(wxID_SAVE); | |
1473 | stdID(wxID_SAVEAS); | |
1474 | stdID(wxID_REVERT); | |
1475 | stdID(wxID_EXIT); | |
1476 | stdID(wxID_UNDO); | |
1477 | stdID(wxID_REDO); | |
1478 | stdID(wxID_HELP); | |
1479 | stdID(wxID_PRINT); | |
1480 | stdID(wxID_PRINT_SETUP); | |
1481 | stdID(wxID_PREVIEW); | |
1482 | stdID(wxID_ABOUT); | |
1483 | stdID(wxID_HELP_CONTENTS); | |
1484 | stdID(wxID_HELP_COMMANDS); | |
1485 | stdID(wxID_HELP_PROCEDURES); | |
1486 | stdID(wxID_HELP_CONTEXT); | |
13de23f6 | 1487 | stdID(wxID_CLOSE_ALL); |
c369d4f1 VS |
1488 | stdID(wxID_PREFERENCES); |
1489 | stdID(wxID_CUT); | |
1490 | stdID(wxID_COPY); | |
1491 | stdID(wxID_PASTE); | |
1492 | stdID(wxID_CLEAR); | |
1493 | stdID(wxID_FIND); | |
1494 | stdID(wxID_DUPLICATE); | |
1495 | stdID(wxID_SELECTALL); | |
1496 | stdID(wxID_DELETE); | |
1497 | stdID(wxID_REPLACE); | |
1498 | stdID(wxID_REPLACE_ALL); | |
1499 | stdID(wxID_PROPERTIES); | |
1500 | stdID(wxID_VIEW_DETAILS); | |
1501 | stdID(wxID_VIEW_LARGEICONS); | |
1502 | stdID(wxID_VIEW_SMALLICONS); | |
1503 | stdID(wxID_VIEW_LIST); | |
1504 | stdID(wxID_VIEW_SORTDATE); | |
1505 | stdID(wxID_VIEW_SORTNAME); | |
1506 | stdID(wxID_VIEW_SORTSIZE); | |
1507 | stdID(wxID_VIEW_SORTTYPE); | |
1508 | stdID(wxID_FILE1); | |
1509 | stdID(wxID_FILE2); | |
1510 | stdID(wxID_FILE3); | |
1511 | stdID(wxID_FILE4); | |
1512 | stdID(wxID_FILE5); | |
1513 | stdID(wxID_FILE6); | |
1514 | stdID(wxID_FILE7); | |
1515 | stdID(wxID_FILE8); | |
1516 | stdID(wxID_FILE9); | |
1517 | stdID(wxID_OK); | |
1518 | stdID(wxID_CANCEL); | |
1519 | stdID(wxID_APPLY); | |
1520 | stdID(wxID_YES); | |
1521 | stdID(wxID_NO); | |
1522 | stdID(wxID_STATIC); | |
1523 | stdID(wxID_FORWARD); | |
1524 | stdID(wxID_BACKWARD); | |
1525 | stdID(wxID_DEFAULT); | |
1526 | stdID(wxID_MORE); | |
1527 | stdID(wxID_SETUP); | |
1528 | stdID(wxID_RESET); | |
1529 | stdID(wxID_CONTEXT_HELP); | |
1530 | stdID(wxID_YESTOALL); | |
1531 | stdID(wxID_NOTOALL); | |
1532 | stdID(wxID_ABORT); | |
1533 | stdID(wxID_RETRY); | |
1534 | stdID(wxID_IGNORE); | |
1535 | stdID(wxID_ADD); | |
1536 | stdID(wxID_REMOVE); | |
1537 | stdID(wxID_UP); | |
1538 | stdID(wxID_DOWN); | |
1539 | stdID(wxID_HOME); | |
1540 | stdID(wxID_REFRESH); | |
1541 | stdID(wxID_STOP); | |
1542 | stdID(wxID_INDEX); | |
1543 | stdID(wxID_BOLD); | |
1544 | stdID(wxID_ITALIC); | |
1545 | stdID(wxID_JUSTIFY_CENTER); | |
1546 | stdID(wxID_JUSTIFY_FILL); | |
1547 | stdID(wxID_JUSTIFY_RIGHT); | |
1548 | stdID(wxID_JUSTIFY_LEFT); | |
1549 | stdID(wxID_UNDERLINE); | |
1550 | stdID(wxID_INDENT); | |
1551 | stdID(wxID_UNINDENT); | |
1552 | stdID(wxID_ZOOM_100); | |
1553 | stdID(wxID_ZOOM_FIT); | |
1554 | stdID(wxID_ZOOM_IN); | |
1555 | stdID(wxID_ZOOM_OUT); | |
1556 | stdID(wxID_UNDELETE); | |
1557 | stdID(wxID_REVERT_TO_SAVED); | |
1558 | stdID(wxID_SYSTEM_MENU); | |
1559 | stdID(wxID_CLOSE_FRAME); | |
1560 | stdID(wxID_MOVE_FRAME); | |
1561 | stdID(wxID_RESIZE_FRAME); | |
1562 | stdID(wxID_MAXIMIZE_FRAME); | |
1563 | stdID(wxID_ICONIZE_FRAME); | |
1564 | stdID(wxID_RESTORE_FRAME); | |
1565 | ||
13de23f6 VS |
1566 | #undef stdID |
1567 | } | |
78d14f80 VS |
1568 | |
1569 | ||
1570 | ||
1571 | ||
1572 | ||
1573 | // --------------- module and globals ----------------------------- | |
1574 | ||
78d14f80 VS |
1575 | class wxXmlResourceModule: public wxModule |
1576 | { | |
1577 | DECLARE_DYNAMIC_CLASS(wxXmlResourceModule) | |
1578 | public: | |
1579 | wxXmlResourceModule() {} | |
824e8eaa VS |
1580 | bool OnInit() |
1581 | { | |
13de23f6 | 1582 | AddStdXRCID_Records(); |
2b5f62a0 | 1583 | wxXmlResource::AddSubclassFactory(new wxXmlSubclassFactoryCXX); |
f80ea77b | 1584 | return true; |
824e8eaa | 1585 | } |
78d14f80 VS |
1586 | void OnExit() |
1587 | { | |
1542c42e | 1588 | delete wxXmlResource::Set(NULL); |
461932ae MB |
1589 | if(wxXmlResource::ms_subclassFactories) |
1590 | WX_CLEAR_LIST(wxXmlSubclassFactoriesList, *wxXmlResource::ms_subclassFactories); | |
2b5f62a0 | 1591 | wxDELETE(wxXmlResource::ms_subclassFactories); |
5ed345b7 | 1592 | CleanXRCID_Records(); |
78d14f80 VS |
1593 | } |
1594 | }; | |
1595 | ||
1596 | IMPLEMENT_DYNAMIC_CLASS(wxXmlResourceModule, wxModule) | |
1597 | ||
1598 | ||
1599 | // When wxXml is loaded dynamically after the application is already running | |
1600 | // then the built-in module system won't pick this one up. Add it manually. | |
1601 | void wxXmlInitResourceModule() | |
1602 | { | |
1603 | wxModule* module = new wxXmlResourceModule; | |
1604 | module->Init(); | |
1605 | wxModule::RegisterModule(module); | |
1606 | } | |
a1e4ec87 VS |
1607 | |
1608 | #endif // wxUSE_XRC |