1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xmlres.cpp
3 // Purpose: XRC resources
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2000 Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
20 #include "wx/xrc/xmlres.h"
27 #include "wx/dialog.h"
28 #include "wx/settings.h"
29 #include "wx/bitmap.h"
31 #include "wx/module.h"
32 #include "wx/wxcrtvararg.h"
39 #include "wx/vector.h"
40 #include "wx/wfstream.h"
41 #include "wx/filesys.h"
42 #include "wx/filename.h"
43 #include "wx/tokenzr.h"
44 #include "wx/fontenum.h"
45 #include "wx/fontmap.h"
46 #include "wx/artprov.h"
48 #include "wx/xml/xml.h"
51 class wxXmlResourceDataRecord
54 wxXmlResourceDataRecord() : Doc(NULL
) {
56 Time
= wxDateTime::Now();
59 ~wxXmlResourceDataRecord() {delete Doc
;}
68 class wxXmlResourceDataRecords
: public wxVector
<wxXmlResourceDataRecord
*>
70 // this is a class so that it can be forward-declared
74 wxXmlResource
*wxXmlResource::ms_instance
= NULL
;
76 /*static*/ wxXmlResource
*wxXmlResource::Get()
79 ms_instance
= new wxXmlResource
;
83 /*static*/ wxXmlResource
*wxXmlResource::Set(wxXmlResource
*res
)
85 wxXmlResource
*old
= ms_instance
;
90 wxXmlResource::wxXmlResource(int flags
, const wxString
& domain
)
94 m_data
= new wxXmlResourceDataRecords
;
98 wxXmlResource::wxXmlResource(const wxString
& filemask
, int flags
, const wxString
& domain
)
102 m_data
= new wxXmlResourceDataRecords
;
107 wxXmlResource::~wxXmlResource()
111 for ( wxXmlResourceDataRecords::iterator i
= m_data
->begin();
112 i
!= m_data
->end(); ++i
)
119 void wxXmlResource::SetDomain(const wxString
& domain
)
126 wxString
wxXmlResource::ConvertFileNameToURL(const wxString
& filename
)
128 wxString
fnd(filename
);
130 // NB: as Load() and Unload() accept both filenames and URLs (should
131 // probably be changed to filenames only, but embedded resources
132 // currently rely on its ability to handle URLs - FIXME) we need to
133 // determine whether found name is filename and not URL and this is the
134 // fastest/simplest way to do it
135 if (wxFileName::FileExists(fnd
))
137 // Make the name absolute filename, because the app may
138 // change working directory later:
143 fnd
= fn
.GetFullPath();
146 fnd
= wxFileSystem::FileNameToURL(fnd
);
156 bool wxXmlResource::IsArchive(const wxString
& filename
)
158 const wxString fnd
= filename
.Lower();
160 return fnd
.Matches(wxT("*.zip")) || fnd
.Matches(wxT("*.xrs"));
163 #endif // wxUSE_FILESYSTEM
165 bool wxXmlResource::Load(const wxString
& filemask
)
169 # define wxXmlFindFirst fsys.FindFirst(filemask, wxFILE)
170 # define wxXmlFindNext fsys.FindNext()
172 # define wxXmlFindFirst wxFindFirstFile(filemask, wxFILE)
173 # define wxXmlFindNext wxFindNextFile()
175 wxString fnd
= wxXmlFindFirst
;
178 wxLogError(_("Cannot load resources from '%s'."), filemask
);
184 fnd
= ConvertFileNameToURL(fnd
);
187 if ( IsArchive(fnd
) )
189 if ( !Load(fnd
+ wxT("#zip:*.xrc")) )
192 else // a single resource URL
193 #endif // wxUSE_FILESYSTEM
195 wxXmlResourceDataRecord
*drec
= new wxXmlResourceDataRecord
;
197 Data().push_back(drec
);
202 # undef wxXmlFindFirst
203 # undef wxXmlFindNext
205 return UpdateResources();
208 bool wxXmlResource::Unload(const wxString
& filename
)
210 wxASSERT_MSG( !wxIsWild(filename
),
211 _T("wildcards not supported by wxXmlResource::Unload()") );
213 wxString fnd
= ConvertFileNameToURL(filename
);
215 const bool isArchive
= IsArchive(fnd
);
218 #endif // wxUSE_FILESYSTEM
220 bool unloaded
= false;
221 for ( wxXmlResourceDataRecords::iterator i
= Data().begin();
222 i
!= Data().end(); ++i
)
227 if ( (*i
)->File
.StartsWith(fnd
) )
229 // don't break from the loop, we can have other matching files
231 else // a single resource URL
232 #endif // wxUSE_FILESYSTEM
234 if ( (*i
)->File
== fnd
)
240 // no sense in continuing, there is only one file with this URL
250 IMPLEMENT_ABSTRACT_CLASS(wxXmlResourceHandler
, wxObject
)
252 void wxXmlResource::AddHandler(wxXmlResourceHandler
*handler
)
254 m_handlers
.push_back(handler
);
255 handler
->SetParentResource(this);
258 void wxXmlResource::InsertHandler(wxXmlResourceHandler
*handler
)
260 m_handlers
.insert(m_handlers
.begin(), handler
);
261 handler
->SetParentResource(this);
266 void wxXmlResource::ClearHandlers()
268 for ( wxVector
<wxXmlResourceHandler
*>::iterator i
= m_handlers
.begin();
269 i
!= m_handlers
.end(); ++i
)
275 wxMenu
*wxXmlResource::LoadMenu(const wxString
& name
)
277 return (wxMenu
*)CreateResFromNode(FindResource(name
, wxT("wxMenu")), NULL
, NULL
);
282 wxMenuBar
*wxXmlResource::LoadMenuBar(wxWindow
*parent
, const wxString
& name
)
284 return (wxMenuBar
*)CreateResFromNode(FindResource(name
, wxT("wxMenuBar")), parent
, NULL
);
290 wxToolBar
*wxXmlResource::LoadToolBar(wxWindow
*parent
, const wxString
& name
)
292 return (wxToolBar
*)CreateResFromNode(FindResource(name
, wxT("wxToolBar")), parent
, NULL
);
297 wxDialog
*wxXmlResource::LoadDialog(wxWindow
*parent
, const wxString
& name
)
299 return (wxDialog
*)CreateResFromNode(FindResource(name
, wxT("wxDialog")), parent
, NULL
);
302 bool wxXmlResource::LoadDialog(wxDialog
*dlg
, wxWindow
*parent
, const wxString
& name
)
304 return CreateResFromNode(FindResource(name
, wxT("wxDialog")), parent
, dlg
) != NULL
;
309 wxPanel
*wxXmlResource::LoadPanel(wxWindow
*parent
, const wxString
& name
)
311 return (wxPanel
*)CreateResFromNode(FindResource(name
, wxT("wxPanel")), parent
, NULL
);
314 bool wxXmlResource::LoadPanel(wxPanel
*panel
, wxWindow
*parent
, const wxString
& name
)
316 return CreateResFromNode(FindResource(name
, wxT("wxPanel")), parent
, panel
) != NULL
;
319 wxFrame
*wxXmlResource::LoadFrame(wxWindow
* parent
, const wxString
& name
)
321 return (wxFrame
*)CreateResFromNode(FindResource(name
, wxT("wxFrame")), parent
, NULL
);
324 bool wxXmlResource::LoadFrame(wxFrame
* frame
, wxWindow
*parent
, const wxString
& name
)
326 return CreateResFromNode(FindResource(name
, wxT("wxFrame")), parent
, frame
) != NULL
;
329 wxBitmap
wxXmlResource::LoadBitmap(const wxString
& name
)
331 wxBitmap
*bmp
= (wxBitmap
*)CreateResFromNode(
332 FindResource(name
, wxT("wxBitmap")), NULL
, NULL
);
335 if (bmp
) { rt
= *bmp
; delete bmp
; }
339 wxIcon
wxXmlResource::LoadIcon(const wxString
& name
)
341 wxIcon
*icon
= (wxIcon
*)CreateResFromNode(
342 FindResource(name
, wxT("wxIcon")), NULL
, NULL
);
345 if (icon
) { rt
= *icon
; delete icon
; }
350 wxObject
*wxXmlResource::LoadObject(wxWindow
*parent
, const wxString
& name
, const wxString
& classname
)
352 return CreateResFromNode(FindResource(name
, classname
), parent
, NULL
);
355 bool wxXmlResource::LoadObject(wxObject
*instance
, wxWindow
*parent
, const wxString
& name
, const wxString
& classname
)
357 return CreateResFromNode(FindResource(name
, classname
), parent
, instance
) != NULL
;
361 bool wxXmlResource::AttachUnknownControl(const wxString
& name
,
362 wxWindow
*control
, wxWindow
*parent
)
365 parent
= control
->GetParent();
366 wxWindow
*container
= parent
->FindWindow(name
+ wxT("_container"));
369 wxLogError(_("Cannot find container for unknown control '%s'."), name
.c_str());
372 return control
->Reparent(container
);
376 static void ProcessPlatformProperty(wxXmlNode
*node
)
381 wxXmlNode
*c
= node
->GetChildren();
385 if (!c
->GetAttribute(wxT("platform"), &s
))
389 wxStringTokenizer
tkn(s
, wxT(" |"));
391 while (tkn
.HasMoreTokens())
393 s
= tkn
.GetNextToken();
395 if (s
== wxT("win")) isok
= true;
397 #if defined(__MAC__) || defined(__APPLE__)
398 if (s
== wxT("mac")) isok
= true;
399 #elif defined(__UNIX__)
400 if (s
== wxT("unix")) isok
= true;
403 if (s
== wxT("os2")) isok
= true;
413 ProcessPlatformProperty(c
);
418 wxXmlNode
*c2
= c
->GetNext();
419 node
->RemoveChild(c
);
428 bool wxXmlResource::UpdateResources()
432 # if wxUSE_FILESYSTEM
433 wxFSFile
*file
= NULL
;
438 wxString
encoding(wxT("UTF-8"));
439 #if !wxUSE_UNICODE && wxUSE_INTL
440 if ( (GetFlags() & wxXRC_USE_LOCALE
) == 0 )
442 // In case we are not using wxLocale to translate strings, convert the
443 // strings GUI's charset. This must not be done when wxXRC_USE_LOCALE
444 // is on, because it could break wxGetTranslation lookup.
445 encoding
= wxLocale::GetSystemEncodingName();
449 for ( wxXmlResourceDataRecords::iterator i
= Data().begin();
450 i
!= Data().end(); ++i
)
452 wxXmlResourceDataRecord
* const rec
= *i
;
454 modif
= (rec
->Doc
== NULL
);
456 if (!modif
&& !(m_flags
& wxXRC_NO_RELOADING
))
458 # if wxUSE_FILESYSTEM
459 file
= fsys
.OpenFile(rec
->File
);
461 modif
= file
&& file
->GetModificationTime() > rec
->Time
;
462 # else // wxUSE_DATETIME
464 # endif // wxUSE_DATETIME
467 wxLogError(_("Cannot open file '%s'."), rec
->File
);
472 # else // wxUSE_FILESYSTEM
474 modif
= wxDateTime(wxFileModificationTime(rec
->File
)) > rec
->Time
;
475 # else // wxUSE_DATETIME
477 # endif // wxUSE_DATETIME
478 # endif // wxUSE_FILESYSTEM
483 wxLogTrace(_T("xrc"), _T("opening file '%s'"), rec
->File
);
485 wxInputStream
*stream
= NULL
;
487 # if wxUSE_FILESYSTEM
488 file
= fsys
.OpenFile(rec
->File
);
490 stream
= file
->GetStream();
492 stream
= new wxFileInputStream(rec
->File
);
498 rec
->Doc
= new wxXmlDocument
;
500 if (!stream
|| !rec
->Doc
->Load(*stream
, encoding
))
502 wxLogError(_("Cannot load resources from file '%s'."),
507 else if (rec
->Doc
->GetRoot()->GetName() != wxT("resource"))
509 wxLogError(_("Invalid XRC resource '%s': doesn't have root node 'resource'."), rec
->File
);
517 wxString verstr
= rec
->Doc
->GetRoot()->GetAttribute(
518 wxT("version"), wxT("0.0.0.0"));
519 if (wxSscanf(verstr
.c_str(), wxT("%i.%i.%i.%i"),
520 &v1
, &v2
, &v3
, &v4
) == 4)
521 version
= v1
*256*256*256+v2
*256*256+v3
*256+v4
;
526 if (m_version
!= version
)
528 wxLogError(_("Resource files must have same version number!"));
532 ProcessPlatformProperty(rec
->Doc
->GetRoot());
535 rec
->Time
= file
->GetModificationTime();
536 #else // wxUSE_FILESYSTEM
537 rec
->Time
= wxDateTime(wxFileModificationTime(rec
->File
));
538 #endif // wxUSE_FILESYSTEM
539 #endif // wxUSE_DATETIME
542 # if wxUSE_FILESYSTEM
555 wxXmlNode
*wxXmlResource::DoFindResource(wxXmlNode
*parent
,
556 const wxString
& name
,
557 const wxString
& classname
,
563 // first search for match at the top-level nodes (as this is
564 // where the resource is most commonly looked for):
565 for (node
= parent
->GetChildren(); node
; node
= node
->GetNext())
567 if ( node
->GetType() == wxXML_ELEMENT_NODE
&&
568 (node
->GetName() == wxT("object") ||
569 node
->GetName() == wxT("object_ref")) &&
570 node
->GetAttribute(wxT("name"), &dummy
) && dummy
== name
)
572 wxString
cls(node
->GetAttribute(wxT("class"), wxEmptyString
));
573 if (!classname
|| cls
== classname
)
575 // object_ref may not have 'class' attribute:
576 if (cls
.empty() && node
->GetName() == wxT("object_ref"))
578 wxString refName
= node
->GetAttribute(wxT("ref"), wxEmptyString
);
581 wxXmlNode
* refNode
= FindResource(refName
, wxEmptyString
, true);
583 refNode
->GetAttribute(wxT("class"), wxEmptyString
) == classname
)
592 for (node
= parent
->GetChildren(); node
; node
= node
->GetNext())
594 if ( node
->GetType() == wxXML_ELEMENT_NODE
&&
595 (node
->GetName() == wxT("object") ||
596 node
->GetName() == wxT("object_ref")) )
598 wxXmlNode
* found
= DoFindResource(node
, name
, classname
, true);
607 wxXmlNode
*wxXmlResource::FindResource(const wxString
& name
,
608 const wxString
& classname
,
611 UpdateResources(); //ensure everything is up-to-date
614 for ( wxXmlResourceDataRecords::const_iterator f
= Data().begin();
615 f
!= Data().end(); ++f
)
617 wxXmlResourceDataRecord
* const rec
= *f
;
618 if ( rec
->Doc
== NULL
|| rec
->Doc
->GetRoot() == NULL
)
621 wxXmlNode
* found
= DoFindResource(rec
->Doc
->GetRoot(),
622 name
, classname
, recursive
);
626 m_curFileSystem
.ChangePathTo(rec
->File
);
632 wxLogError(_("XRC resource '%s' (class '%s') not found!"),
633 name
.c_str(), classname
.c_str());
637 static void MergeNodes(wxXmlNode
& dest
, wxXmlNode
& with
)
640 for ( wxXmlAttribute
*attr
= with
.GetAttributes();
641 attr
; attr
= attr
->GetNext() )
643 wxXmlAttribute
*dattr
;
644 for (dattr
= dest
.GetAttributes(); dattr
; dattr
= dattr
->GetNext())
647 if ( dattr
->GetName() == attr
->GetName() )
649 dattr
->SetValue(attr
->GetValue());
655 dest
.AddAttribute(attr
->GetName(), attr
->GetValue());
658 // Merge child nodes:
659 for (wxXmlNode
* node
= with
.GetChildren(); node
; node
= node
->GetNext())
661 wxString name
= node
->GetAttribute(wxT("name"), wxEmptyString
);
664 for (dnode
= dest
.GetChildren(); dnode
; dnode
= dnode
->GetNext() )
666 if ( dnode
->GetName() == node
->GetName() &&
667 dnode
->GetAttribute(wxT("name"), wxEmptyString
) == name
&&
668 dnode
->GetType() == node
->GetType() )
670 MergeNodes(*dnode
, *node
);
677 static const wxChar
*AT_END
= wxT("end");
678 wxString insert_pos
= node
->GetAttribute(wxT("insert_at"), AT_END
);
679 if ( insert_pos
== AT_END
)
681 dest
.AddChild(new wxXmlNode(*node
));
683 else if ( insert_pos
== wxT("begin") )
685 dest
.InsertChild(new wxXmlNode(*node
), dest
.GetChildren());
690 if ( dest
.GetType() == wxXML_TEXT_NODE
&& with
.GetContent().length() )
691 dest
.SetContent(with
.GetContent());
694 wxObject
*wxXmlResource::CreateResFromNode(wxXmlNode
*node
, wxObject
*parent
,
696 wxXmlResourceHandler
*handlerToUse
)
698 if (node
== NULL
) return NULL
;
700 // handling of referenced resource
701 if ( node
->GetName() == wxT("object_ref") )
703 wxString refName
= node
->GetAttribute(wxT("ref"), wxEmptyString
);
704 wxXmlNode
* refNode
= FindResource(refName
, wxEmptyString
, true);
708 wxLogError(_("Referenced object node with ref=\"%s\" not found!"),
713 wxXmlNode
copy(*refNode
);
714 MergeNodes(copy
, *node
);
716 return CreateResFromNode(©
, parent
, instance
);
721 if (handlerToUse
->CanHandle(node
))
723 return handlerToUse
->CreateResource(node
, parent
, instance
);
726 else if (node
->GetName() == wxT("object"))
728 for ( wxVector
<wxXmlResourceHandler
*>::iterator h
= m_handlers
.begin();
729 h
!= m_handlers
.end(); ++h
)
731 wxXmlResourceHandler
*handler
= *h
;
732 if (handler
->CanHandle(node
))
733 return handler
->CreateResource(node
, parent
, instance
);
737 wxLogError(_("No handler found for XML node '%s', class '%s'!"),
738 node
->GetName().c_str(),
739 node
->GetAttribute(wxT("class"), wxEmptyString
).c_str());
744 class wxXmlSubclassFactories
: public wxVector
<wxXmlSubclassFactory
*>
746 // this is a class so that it can be forward-declared
749 wxXmlSubclassFactories
*wxXmlResource::ms_subclassFactories
= NULL
;
751 /*static*/ void wxXmlResource::AddSubclassFactory(wxXmlSubclassFactory
*factory
)
753 if (!ms_subclassFactories
)
755 ms_subclassFactories
= new wxXmlSubclassFactories
;
757 ms_subclassFactories
->push_back(factory
);
760 class wxXmlSubclassFactoryCXX
: public wxXmlSubclassFactory
763 ~wxXmlSubclassFactoryCXX() {}
765 wxObject
*Create(const wxString
& className
)
767 wxClassInfo
* classInfo
= wxClassInfo::FindClass(className
);
770 return classInfo
->CreateObject();
779 wxXmlResourceHandler::wxXmlResourceHandler()
780 : m_node(NULL
), m_parent(NULL
), m_instance(NULL
),
781 m_parentAsWindow(NULL
)
786 wxObject
*wxXmlResourceHandler::CreateResource(wxXmlNode
*node
, wxObject
*parent
, wxObject
*instance
)
788 wxXmlNode
*myNode
= m_node
;
789 wxString myClass
= m_class
;
790 wxObject
*myParent
= m_parent
, *myInstance
= m_instance
;
791 wxWindow
*myParentAW
= m_parentAsWindow
;
793 m_instance
= instance
;
794 if (!m_instance
&& node
->HasAttribute(wxT("subclass")) &&
795 !(m_resource
->GetFlags() & wxXRC_NO_SUBCLASSING
))
797 wxString subclass
= node
->GetAttribute(wxT("subclass"), wxEmptyString
);
798 if (!subclass
.empty())
800 for (wxXmlSubclassFactories::iterator i
= wxXmlResource::ms_subclassFactories
->begin();
801 i
!= wxXmlResource::ms_subclassFactories
->end(); ++i
)
803 m_instance
= (*i
)->Create(subclass
);
810 wxString name
= node
->GetAttribute(wxT("name"), wxEmptyString
);
811 wxLogError(_("Subclass '%s' not found for resource '%s', not subclassing!"),
812 subclass
.c_str(), name
.c_str());
818 m_class
= node
->GetAttribute(wxT("class"), wxEmptyString
);
820 m_parentAsWindow
= wxDynamicCast(m_parent
, wxWindow
);
822 wxObject
*returned
= DoCreateResource();
826 m_parent
= myParent
; m_parentAsWindow
= myParentAW
;
827 m_instance
= myInstance
;
833 void wxXmlResourceHandler::AddStyle(const wxString
& name
, int value
)
835 m_styleNames
.Add(name
);
836 m_styleValues
.Add(value
);
841 void wxXmlResourceHandler::AddWindowStyles()
843 XRC_ADD_STYLE(wxCLIP_CHILDREN
);
845 // the border styles all have the old and new names, recognize both for now
846 XRC_ADD_STYLE(wxSIMPLE_BORDER
); XRC_ADD_STYLE(wxBORDER_SIMPLE
);
847 XRC_ADD_STYLE(wxSUNKEN_BORDER
); XRC_ADD_STYLE(wxBORDER_SUNKEN
);
848 XRC_ADD_STYLE(wxDOUBLE_BORDER
); XRC_ADD_STYLE(wxBORDER_DOUBLE
);
849 XRC_ADD_STYLE(wxRAISED_BORDER
); XRC_ADD_STYLE(wxBORDER_RAISED
);
850 XRC_ADD_STYLE(wxSTATIC_BORDER
); XRC_ADD_STYLE(wxBORDER_STATIC
);
851 XRC_ADD_STYLE(wxNO_BORDER
); XRC_ADD_STYLE(wxBORDER_NONE
);
853 XRC_ADD_STYLE(wxTRANSPARENT_WINDOW
);
854 XRC_ADD_STYLE(wxWANTS_CHARS
);
855 XRC_ADD_STYLE(wxTAB_TRAVERSAL
);
856 XRC_ADD_STYLE(wxNO_FULL_REPAINT_ON_RESIZE
);
857 XRC_ADD_STYLE(wxFULL_REPAINT_ON_RESIZE
);
858 XRC_ADD_STYLE(wxALWAYS_SHOW_SB
);
859 XRC_ADD_STYLE(wxWS_EX_BLOCK_EVENTS
);
860 XRC_ADD_STYLE(wxWS_EX_VALIDATE_RECURSIVELY
);
865 bool wxXmlResourceHandler::HasParam(const wxString
& param
)
867 return (GetParamNode(param
) != NULL
);
871 int wxXmlResourceHandler::GetStyle(const wxString
& param
, int defaults
)
873 wxString s
= GetParamValue(param
);
875 if (!s
) return defaults
;
877 wxStringTokenizer
tkn(s
, wxT("| \t\n"), wxTOKEN_STRTOK
);
881 while (tkn
.HasMoreTokens())
883 fl
= tkn
.GetNextToken();
884 index
= m_styleNames
.Index(fl
);
885 if (index
!= wxNOT_FOUND
)
886 style
|= m_styleValues
[index
];
888 wxLogError(_("Unknown style flag ") + fl
);
895 wxString
wxXmlResourceHandler::GetText(const wxString
& param
, bool translate
)
897 wxXmlNode
*parNode
= GetParamNode(param
);
898 wxString
str1(GetNodeContent(parNode
));
901 // "\\" wasn't translated to "\" prior to 2.5.3.0:
902 const bool escapeBackslash
= (m_resource
->CompareVersion(2,5,3,0) >= 0);
904 // VS: First version of XRC resources used $ instead of & (which is
905 // illegal in XML), but later I realized that '_' fits this purpose
906 // much better (because &File means "File with F underlined").
907 const wxChar amp_char
= (m_resource
->CompareVersion(2,3,0,1) < 0)
910 for ( wxString::const_iterator dt
= str1
.begin(); dt
!= str1
.end(); ++dt
)
912 // Remap amp_char to &, map double amp_char to amp_char (for things
913 // like "&File..." -- this is illegal in XML, so we use "_File..."):
914 if ( *dt
== amp_char
)
916 if ( *(++dt
) == amp_char
)
919 str2
<< wxT('&') << *dt
;
921 // Remap \n to CR, \r to LF, \t to TAB, \\ to \:
922 else if ( *dt
== wxT('\\') )
924 switch ( (*(++dt
)).GetValue() )
939 // "\\" wasn't translated to "\" prior to 2.5.3.0:
940 if ( escapeBackslash
)
945 // else fall-through to default: branch below
948 str2
<< wxT('\\') << *dt
;
958 if (m_resource
->GetFlags() & wxXRC_USE_LOCALE
)
960 if (translate
&& parNode
&&
961 parNode
->GetAttribute(wxT("translate"), wxEmptyString
) != wxT("0"))
963 return wxGetTranslation(str2
, m_resource
->GetDomain());
970 // The string is internally stored as UTF-8, we have to convert
971 // it into system's default encoding so that it can be displayed:
972 return wxString(str2
.wc_str(wxConvUTF8
), wxConvLocal
);
977 // If wxXRC_USE_LOCALE is not set, then the string is already in
978 // system's default encoding in ANSI build, so we don't have to
979 // do anything special here.
985 long wxXmlResourceHandler::GetLong(const wxString
& param
, long defaultv
)
988 wxString str1
= GetParamValue(param
);
990 if (!str1
.ToLong(&value
))
996 float wxXmlResourceHandler::GetFloat(const wxString
& param
, float defaultv
)
998 wxString str
= GetParamValue(param
);
1001 // strings in XRC always use C locale but wxString::ToDouble() uses the
1002 // current one, so transform the string to it supposing that the only
1003 // difference between them is the decimal separator
1005 // TODO: use wxString::ToCDouble() when we have it
1006 str
.Replace(wxT("."), wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT
,
1007 wxLOCALE_CAT_NUMBER
));
1008 #endif // wxUSE_INTL
1011 if (!str
.ToDouble(&value
))
1014 return wx_truncate_cast(float, value
);
1018 int wxXmlResourceHandler::GetID()
1020 return wxXmlResource::GetXRCID(GetName());
1025 wxString
wxXmlResourceHandler::GetName()
1027 return m_node
->GetAttribute(wxT("name"), wxT("-1"));
1032 bool wxXmlResourceHandler::GetBoolAttr(const wxString
& attr
, bool defaultv
)
1035 return m_node
->GetAttribute(attr
, &v
) ? v
== '1' : defaultv
;
1038 bool wxXmlResourceHandler::GetBool(const wxString
& param
, bool defaultv
)
1040 const wxString v
= GetParamValue(param
);
1042 return v
.empty() ? defaultv
: (v
== '1');
1046 static wxColour
GetSystemColour(const wxString
& name
)
1050 #define SYSCLR(clr) \
1051 if (name == _T(#clr)) return wxSystemSettings::GetColour(clr);
1052 SYSCLR(wxSYS_COLOUR_SCROLLBAR
)
1053 SYSCLR(wxSYS_COLOUR_BACKGROUND
)
1054 SYSCLR(wxSYS_COLOUR_DESKTOP
)
1055 SYSCLR(wxSYS_COLOUR_ACTIVECAPTION
)
1056 SYSCLR(wxSYS_COLOUR_INACTIVECAPTION
)
1057 SYSCLR(wxSYS_COLOUR_MENU
)
1058 SYSCLR(wxSYS_COLOUR_WINDOW
)
1059 SYSCLR(wxSYS_COLOUR_WINDOWFRAME
)
1060 SYSCLR(wxSYS_COLOUR_MENUTEXT
)
1061 SYSCLR(wxSYS_COLOUR_WINDOWTEXT
)
1062 SYSCLR(wxSYS_COLOUR_CAPTIONTEXT
)
1063 SYSCLR(wxSYS_COLOUR_ACTIVEBORDER
)
1064 SYSCLR(wxSYS_COLOUR_INACTIVEBORDER
)
1065 SYSCLR(wxSYS_COLOUR_APPWORKSPACE
)
1066 SYSCLR(wxSYS_COLOUR_HIGHLIGHT
)
1067 SYSCLR(wxSYS_COLOUR_HIGHLIGHTTEXT
)
1068 SYSCLR(wxSYS_COLOUR_BTNFACE
)
1069 SYSCLR(wxSYS_COLOUR_3DFACE
)
1070 SYSCLR(wxSYS_COLOUR_BTNSHADOW
)
1071 SYSCLR(wxSYS_COLOUR_3DSHADOW
)
1072 SYSCLR(wxSYS_COLOUR_GRAYTEXT
)
1073 SYSCLR(wxSYS_COLOUR_BTNTEXT
)
1074 SYSCLR(wxSYS_COLOUR_INACTIVECAPTIONTEXT
)
1075 SYSCLR(wxSYS_COLOUR_BTNHIGHLIGHT
)
1076 SYSCLR(wxSYS_COLOUR_BTNHILIGHT
)
1077 SYSCLR(wxSYS_COLOUR_3DHIGHLIGHT
)
1078 SYSCLR(wxSYS_COLOUR_3DHILIGHT
)
1079 SYSCLR(wxSYS_COLOUR_3DDKSHADOW
)
1080 SYSCLR(wxSYS_COLOUR_3DLIGHT
)
1081 SYSCLR(wxSYS_COLOUR_INFOTEXT
)
1082 SYSCLR(wxSYS_COLOUR_INFOBK
)
1083 SYSCLR(wxSYS_COLOUR_LISTBOX
)
1084 SYSCLR(wxSYS_COLOUR_HOTLIGHT
)
1085 SYSCLR(wxSYS_COLOUR_GRADIENTACTIVECAPTION
)
1086 SYSCLR(wxSYS_COLOUR_GRADIENTINACTIVECAPTION
)
1087 SYSCLR(wxSYS_COLOUR_MENUHILIGHT
)
1088 SYSCLR(wxSYS_COLOUR_MENUBAR
)
1092 return wxNullColour
;
1095 wxColour
wxXmlResourceHandler::GetColour(const wxString
& param
, const wxColour
& defaultv
)
1097 wxString v
= GetParamValue(param
);
1104 // wxString -> wxColour conversion
1107 // the colour doesn't use #RRGGBB format, check if it is symbolic
1109 clr
= GetSystemColour(v
);
1113 wxLogError(_("XRC resource: Incorrect colour specification '%s' for attribute '%s'."),
1114 v
.c_str(), param
.c_str());
1115 return wxNullColour
;
1123 wxBitmap
wxXmlResourceHandler::GetBitmap(const wxString
& param
,
1124 const wxArtClient
& defaultArtClient
,
1127 /* If the bitmap is specified as stock item, query wxArtProvider for it: */
1128 wxXmlNode
*bmpNode
= GetParamNode(param
);
1131 wxString sid
= bmpNode
->GetAttribute(wxT("stock_id"), wxEmptyString
);
1134 wxString scl
= bmpNode
->GetAttribute(wxT("stock_client"), wxEmptyString
);
1136 scl
= defaultArtClient
;
1138 scl
= wxART_MAKE_CLIENT_ID_FROM_STR(scl
);
1141 wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(sid
),
1143 if ( stockArt
.Ok() )
1148 /* ...or load the bitmap from file: */
1149 wxString name
= GetParamValue(param
);
1150 if (name
.empty()) return wxNullBitmap
;
1151 #if wxUSE_FILESYSTEM
1152 wxFSFile
*fsfile
= GetCurFileSystem().OpenFile(name
, wxFS_READ
| wxFS_SEEKABLE
);
1155 wxLogError(_("XRC resource: Cannot create bitmap from '%s'."),
1157 return wxNullBitmap
;
1159 wxImage
img(*(fsfile
->GetStream()));
1167 wxLogError(_("XRC resource: Cannot create bitmap from '%s'."),
1169 return wxNullBitmap
;
1171 if (!(size
== wxDefaultSize
)) img
.Rescale(size
.x
, size
.y
);
1172 return wxBitmap(img
);
1176 wxIcon
wxXmlResourceHandler::GetIcon(const wxString
& param
,
1177 const wxArtClient
& defaultArtClient
,
1181 icon
.CopyFromBitmap(GetBitmap(param
, defaultArtClient
, size
));
1187 wxXmlNode
*wxXmlResourceHandler::GetParamNode(const wxString
& param
)
1189 wxCHECK_MSG(m_node
, NULL
, wxT("You can't access handler data before it was initialized!"));
1191 wxXmlNode
*n
= m_node
->GetChildren();
1195 if (n
->GetType() == wxXML_ELEMENT_NODE
&& n
->GetName() == param
)
1197 // TODO: check that there are no other properties/parameters with
1198 // the same name and log an error if there are (can't do this
1199 // right now as I'm not sure if it's not going to break code
1200 // using this function in unintentional way (i.e. for
1201 // accessing other things than properties), for example
1202 // wxBitmapComboBoxXmlHandler almost surely does
1210 bool wxXmlResourceHandler::IsOfClass(wxXmlNode
*node
, const wxString
& classname
)
1212 return node
->GetAttribute(wxT("class"), wxEmptyString
) == classname
;
1217 wxString
wxXmlResourceHandler::GetNodeContent(wxXmlNode
*node
)
1219 wxXmlNode
*n
= node
;
1220 if (n
== NULL
) return wxEmptyString
;
1221 n
= n
->GetChildren();
1225 if (n
->GetType() == wxXML_TEXT_NODE
||
1226 n
->GetType() == wxXML_CDATA_SECTION_NODE
)
1227 return n
->GetContent();
1230 return wxEmptyString
;
1235 wxString
wxXmlResourceHandler::GetParamValue(const wxString
& param
)
1238 return GetNodeContent(m_node
);
1240 return GetNodeContent(GetParamNode(param
));
1245 wxSize
wxXmlResourceHandler::GetSize(const wxString
& param
,
1246 wxWindow
*windowToUse
)
1248 wxString s
= GetParamValue(param
);
1249 if (s
.empty()) s
= wxT("-1,-1");
1253 is_dlg
= s
[s
.length()-1] == wxT('d');
1254 if (is_dlg
) s
.RemoveLast();
1256 if (!s
.BeforeFirst(wxT(',')).ToLong(&sx
) ||
1257 !s
.AfterLast(wxT(',')).ToLong(&sy
))
1259 wxLogError(_("Cannot parse coordinates from '%s'."), s
.c_str());
1260 return wxDefaultSize
;
1267 return wxDLG_UNIT(windowToUse
, wxSize(sx
, sy
));
1269 else if (m_parentAsWindow
)
1271 return wxDLG_UNIT(m_parentAsWindow
, wxSize(sx
, sy
));
1275 wxLogError(_("Cannot convert dialog units: dialog unknown."));
1276 return wxDefaultSize
;
1280 return wxSize(sx
, sy
);
1285 wxPoint
wxXmlResourceHandler::GetPosition(const wxString
& param
)
1287 wxSize sz
= GetSize(param
);
1288 return wxPoint(sz
.x
, sz
.y
);
1293 wxCoord
wxXmlResourceHandler::GetDimension(const wxString
& param
,
1295 wxWindow
*windowToUse
)
1297 wxString s
= GetParamValue(param
);
1298 if (s
.empty()) return defaultv
;
1302 is_dlg
= s
[s
.length()-1] == wxT('d');
1303 if (is_dlg
) s
.RemoveLast();
1307 wxLogError(_("Cannot parse dimension from '%s'."), s
.c_str());
1315 return wxDLG_UNIT(windowToUse
, wxSize(sx
, 0)).x
;
1317 else if (m_parentAsWindow
)
1319 return wxDLG_UNIT(m_parentAsWindow
, wxSize(sx
, 0)).x
;
1323 wxLogError(_("Cannot convert dialog units: dialog unknown."));
1332 // Get system font index using indexname
1333 static wxFont
GetSystemFont(const wxString
& name
)
1337 #define SYSFNT(fnt) \
1338 if (name == _T(#fnt)) return wxSystemSettings::GetFont(fnt);
1339 SYSFNT(wxSYS_OEM_FIXED_FONT
)
1340 SYSFNT(wxSYS_ANSI_FIXED_FONT
)
1341 SYSFNT(wxSYS_ANSI_VAR_FONT
)
1342 SYSFNT(wxSYS_SYSTEM_FONT
)
1343 SYSFNT(wxSYS_DEVICE_DEFAULT_FONT
)
1344 SYSFNT(wxSYS_DEFAULT_PALETTE
)
1345 SYSFNT(wxSYS_SYSTEM_FIXED_FONT
)
1346 SYSFNT(wxSYS_DEFAULT_GUI_FONT
)
1353 wxFont
wxXmlResourceHandler::GetFont(const wxString
& param
)
1355 wxXmlNode
*font_node
= GetParamNode(param
);
1356 if (font_node
== NULL
)
1358 wxLogError(_("Cannot find font node '%s'."), param
.c_str());
1362 wxXmlNode
*oldnode
= m_node
;
1369 bool hasSize
= HasParam(wxT("size"));
1371 isize
= GetLong(wxT("size"), -1);
1374 int istyle
= wxNORMAL
;
1375 bool hasStyle
= HasParam(wxT("style"));
1378 wxString style
= GetParamValue(wxT("style"));
1379 if (style
== wxT("italic"))
1381 else if (style
== wxT("slant"))
1386 int iweight
= wxNORMAL
;
1387 bool hasWeight
= HasParam(wxT("weight"));
1390 wxString weight
= GetParamValue(wxT("weight"));
1391 if (weight
== wxT("bold"))
1393 else if (weight
== wxT("light"))
1398 bool hasUnderlined
= HasParam(wxT("underlined"));
1399 bool underlined
= hasUnderlined
? GetBool(wxT("underlined"), false) : false;
1401 // family and facename
1402 int ifamily
= wxDEFAULT
;
1403 bool hasFamily
= HasParam(wxT("family"));
1406 wxString family
= GetParamValue(wxT("family"));
1407 if (family
== wxT("decorative")) ifamily
= wxDECORATIVE
;
1408 else if (family
== wxT("roman")) ifamily
= wxROMAN
;
1409 else if (family
== wxT("script")) ifamily
= wxSCRIPT
;
1410 else if (family
== wxT("swiss")) ifamily
= wxSWISS
;
1411 else if (family
== wxT("modern")) ifamily
= wxMODERN
;
1412 else if (family
== wxT("teletype")) ifamily
= wxTELETYPE
;
1417 bool hasFacename
= HasParam(wxT("face"));
1420 wxString faces
= GetParamValue(wxT("face"));
1421 wxStringTokenizer
tk(faces
, wxT(","));
1423 wxArrayString
facenames(wxFontEnumerator::GetFacenames());
1424 while (tk
.HasMoreTokens())
1426 int index
= facenames
.Index(tk
.GetNextToken(), false);
1427 if (index
!= wxNOT_FOUND
)
1429 facename
= facenames
[index
];
1433 #else // !wxUSE_FONTENUM
1434 // just use the first face name if we can't check its availability:
1435 if (tk
.HasMoreTokens())
1436 facename
= tk
.GetNextToken();
1437 #endif // wxUSE_FONTENUM/!wxUSE_FONTENUM
1441 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
1442 bool hasEncoding
= HasParam(wxT("encoding"));
1445 wxString encoding
= GetParamValue(wxT("encoding"));
1446 wxFontMapper mapper
;
1447 if (!encoding
.empty())
1448 enc
= mapper
.CharsetToEncoding(encoding
);
1449 if (enc
== wxFONTENCODING_SYSTEM
)
1450 enc
= wxFONTENCODING_DEFAULT
;
1453 // is this font based on a system font?
1454 wxFont font
= GetSystemFont(GetParamValue(wxT("sysfont")));
1458 if (hasSize
&& isize
!= -1)
1459 font
.SetPointSize(isize
);
1460 else if (HasParam(wxT("relativesize")))
1461 font
.SetPointSize(int(font
.GetPointSize() *
1462 GetFloat(wxT("relativesize"))));
1465 font
.SetStyle(istyle
);
1467 font
.SetWeight(iweight
);
1469 font
.SetUnderlined(underlined
);
1471 font
.SetFamily(ifamily
);
1473 font
.SetFaceName(facename
);
1475 font
.SetDefaultEncoding(enc
);
1477 else // not based on system font
1479 font
= wxFont(isize
== -1 ? wxNORMAL_FONT
->GetPointSize() : isize
,
1480 ifamily
, istyle
, iweight
,
1481 underlined
, facename
, enc
);
1489 void wxXmlResourceHandler::SetupWindow(wxWindow
*wnd
)
1491 //FIXME : add cursor
1493 if (HasParam(wxT("exstyle")))
1494 // Have to OR it with existing style, since
1495 // some implementations (e.g. wxGTK) use the extra style
1497 wnd
->SetExtraStyle(wnd
->GetExtraStyle() | GetStyle(wxT("exstyle")));
1498 if (HasParam(wxT("bg")))
1499 wnd
->SetBackgroundColour(GetColour(wxT("bg")));
1500 if (HasParam(wxT("fg")))
1501 wnd
->SetForegroundColour(GetColour(wxT("fg")));
1502 if (GetBool(wxT("enabled"), 1) == 0)
1504 if (GetBool(wxT("focused"), 0) == 1)
1506 if (GetBool(wxT("hidden"), 0) == 1)
1509 if (HasParam(wxT("tooltip")))
1510 wnd
->SetToolTip(GetText(wxT("tooltip")));
1512 if (HasParam(wxT("font")))
1513 wnd
->SetFont(GetFont());
1514 if (HasParam(wxT("help")))
1515 wnd
->SetHelpText(GetText(wxT("help")));
1519 void wxXmlResourceHandler::CreateChildren(wxObject
*parent
, bool this_hnd_only
)
1521 wxXmlNode
*n
= m_node
->GetChildren();
1525 if (n
->GetType() == wxXML_ELEMENT_NODE
&&
1526 (n
->GetName() == wxT("object") || n
->GetName() == wxT("object_ref")))
1528 m_resource
->CreateResFromNode(n
, parent
, NULL
,
1529 this_hnd_only
? this : NULL
);
1536 void wxXmlResourceHandler::CreateChildrenPrivately(wxObject
*parent
, wxXmlNode
*rootnode
)
1539 if (rootnode
== NULL
) root
= m_node
; else root
= rootnode
;
1540 wxXmlNode
*n
= root
->GetChildren();
1544 if (n
->GetType() == wxXML_ELEMENT_NODE
&& CanHandle(n
))
1546 CreateResource(n
, parent
, NULL
);
1558 // --------------- XRCID implementation -----------------------------
1560 #define XRCID_TABLE_SIZE 1024
1565 /* Hold the id so that once an id is allocated for a name, it
1566 does not get created again by NewControlId at least
1567 until we are done with it */
1573 static XRCID_record
*XRCID_Records
[XRCID_TABLE_SIZE
] = {NULL
};
1575 static int XRCID_Lookup(const char *str_id
, int value_if_not_found
= wxID_NONE
)
1579 for (const char *c
= str_id
; *c
!= '\0'; c
++) index
+= (int)*c
;
1580 index
%= XRCID_TABLE_SIZE
;
1582 XRCID_record
*oldrec
= NULL
;
1583 for (XRCID_record
*rec
= XRCID_Records
[index
]; rec
; rec
= rec
->next
)
1585 if (wxStrcmp(rec
->key
, str_id
) == 0)
1592 XRCID_record
**rec_var
= (oldrec
== NULL
) ?
1593 &XRCID_Records
[index
] : &oldrec
->next
;
1594 *rec_var
= new XRCID_record
;
1595 (*rec_var
)->key
= wxStrdup(str_id
);
1596 (*rec_var
)->next
= NULL
;
1599 if (value_if_not_found
!= wxID_NONE
)
1600 (*rec_var
)->id
= value_if_not_found
;
1603 int asint
= wxStrtol(str_id
, &end
, 10);
1604 if (*str_id
&& *end
== 0)
1606 // if str_id was integer, keep it verbosely:
1607 (*rec_var
)->id
= asint
;
1611 (*rec_var
)->id
= wxWindowBase::NewControlId();
1615 return (*rec_var
)->id
;
1618 static void AddStdXRCID_Records();
1621 int wxXmlResource::DoGetXRCID(const char *str_id
, int value_if_not_found
)
1623 static bool s_stdIDsAdded
= false;
1625 if ( !s_stdIDsAdded
)
1627 s_stdIDsAdded
= true;
1628 AddStdXRCID_Records();
1631 return XRCID_Lookup(str_id
, value_if_not_found
);
1635 wxString
wxXmlResource::FindXRCIDById(int numId
)
1637 for ( int i
= 0; i
< XRCID_TABLE_SIZE
; i
++ )
1639 for ( XRCID_record
*rec
= XRCID_Records
[i
]; rec
; rec
= rec
->next
)
1641 if ( rec
->id
== numId
)
1642 return wxString(rec
->key
);
1649 static void CleanXRCID_Record(XRCID_record
*rec
)
1653 CleanXRCID_Record(rec
->next
);
1660 static void CleanXRCID_Records()
1662 for (int i
= 0; i
< XRCID_TABLE_SIZE
; i
++)
1664 CleanXRCID_Record(XRCID_Records
[i
]);
1665 XRCID_Records
[i
] = NULL
;
1669 static void AddStdXRCID_Records()
1671 #define stdID(id) XRCID_Lookup(#id, id)
1675 stdID(wxID_SEPARATOR
);
1688 stdID(wxID_PRINT_SETUP
);
1689 stdID(wxID_PAGE_SETUP
);
1690 stdID(wxID_PREVIEW
);
1692 stdID(wxID_HELP_CONTENTS
);
1693 stdID(wxID_HELP_COMMANDS
);
1694 stdID(wxID_HELP_PROCEDURES
);
1695 stdID(wxID_HELP_CONTEXT
);
1696 stdID(wxID_CLOSE_ALL
);
1697 stdID(wxID_PREFERENCES
);
1704 stdID(wxID_DUPLICATE
);
1705 stdID(wxID_SELECTALL
);
1707 stdID(wxID_REPLACE
);
1708 stdID(wxID_REPLACE_ALL
);
1709 stdID(wxID_PROPERTIES
);
1710 stdID(wxID_VIEW_DETAILS
);
1711 stdID(wxID_VIEW_LARGEICONS
);
1712 stdID(wxID_VIEW_SMALLICONS
);
1713 stdID(wxID_VIEW_LIST
);
1714 stdID(wxID_VIEW_SORTDATE
);
1715 stdID(wxID_VIEW_SORTNAME
);
1716 stdID(wxID_VIEW_SORTSIZE
);
1717 stdID(wxID_VIEW_SORTTYPE
);
1733 stdID(wxID_FORWARD
);
1734 stdID(wxID_BACKWARD
);
1735 stdID(wxID_DEFAULT
);
1739 stdID(wxID_CONTEXT_HELP
);
1740 stdID(wxID_YESTOALL
);
1741 stdID(wxID_NOTOALL
);
1750 stdID(wxID_REFRESH
);
1755 stdID(wxID_JUSTIFY_CENTER
);
1756 stdID(wxID_JUSTIFY_FILL
);
1757 stdID(wxID_JUSTIFY_RIGHT
);
1758 stdID(wxID_JUSTIFY_LEFT
);
1759 stdID(wxID_UNDERLINE
);
1761 stdID(wxID_UNINDENT
);
1762 stdID(wxID_ZOOM_100
);
1763 stdID(wxID_ZOOM_FIT
);
1764 stdID(wxID_ZOOM_IN
);
1765 stdID(wxID_ZOOM_OUT
);
1766 stdID(wxID_UNDELETE
);
1767 stdID(wxID_REVERT_TO_SAVED
);
1768 stdID(wxID_SYSTEM_MENU
);
1769 stdID(wxID_CLOSE_FRAME
);
1770 stdID(wxID_MOVE_FRAME
);
1771 stdID(wxID_RESIZE_FRAME
);
1772 stdID(wxID_MAXIMIZE_FRAME
);
1773 stdID(wxID_ICONIZE_FRAME
);
1774 stdID(wxID_RESTORE_FRAME
);
1776 stdID(wxID_CONVERT
);
1777 stdID(wxID_EXECUTE
);
1779 stdID(wxID_HARDDISK
);
1785 stdID(wxID_JUMP_TO
);
1786 stdID(wxID_NETWORK
);
1787 stdID(wxID_SELECT_COLOR
);
1788 stdID(wxID_SELECT_FONT
);
1789 stdID(wxID_SORT_ASCENDING
);
1790 stdID(wxID_SORT_DESCENDING
);
1791 stdID(wxID_SPELL_CHECK
);
1792 stdID(wxID_STRIKETHROUGH
);
1801 // --------------- module and globals -----------------------------
1803 // normally we would do the cleanup from wxXmlResourceModule::OnExit() but it
1804 // can happen that some XRC records have been created because of the use of
1805 // XRCID() in event tables, which happens during static objects initialization,
1806 // but then the application initialization failed and so the wx modules were
1807 // neither initialized nor cleaned up -- this static object does the cleanup in
1809 static struct wxXRCStaticCleanup
1811 ~wxXRCStaticCleanup() { CleanXRCID_Records(); }
1814 class wxXmlResourceModule
: public wxModule
1816 DECLARE_DYNAMIC_CLASS(wxXmlResourceModule
)
1818 wxXmlResourceModule() {}
1821 wxXmlResource::AddSubclassFactory(new wxXmlSubclassFactoryCXX
);
1826 delete wxXmlResource::Set(NULL
);
1827 if(wxXmlResource::ms_subclassFactories
)
1829 for ( wxXmlSubclassFactories::iterator i
= wxXmlResource::ms_subclassFactories
->begin();
1830 i
!= wxXmlResource::ms_subclassFactories
->end(); ++i
)
1834 wxDELETE(wxXmlResource::ms_subclassFactories
);
1836 CleanXRCID_Records();
1840 IMPLEMENT_DYNAMIC_CLASS(wxXmlResourceModule
, wxModule
)
1843 // When wxXml is loaded dynamically after the application is already running
1844 // then the built-in module system won't pick this one up. Add it manually.
1845 void wxXmlInitResourceModule()
1847 wxModule
* module = new wxXmlResourceModule
;
1849 wxModule::RegisterModule(module);