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