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
76 // helper used by DoFindResource() and elsewhere: returns true if this is an
77 // object or object_ref node
79 // node must be non-NULL
80 inline bool IsObjectNode(wxXmlNode
*node
)
82 return node
->GetType() == wxXML_ELEMENT_NODE
&&
83 (node
->GetName() == wxS("object") ||
84 node
->GetName() == wxS("object_ref"));
87 } // anonymous namespace
90 wxXmlResource
*wxXmlResource
::ms_instance
= NULL
;
92 /*static*/ wxXmlResource
*wxXmlResource
::Get()
95 ms_instance
= new wxXmlResource
;
99 /*static*/ wxXmlResource
*wxXmlResource
::Set(wxXmlResource
*res
)
101 wxXmlResource
*old
= ms_instance
;
106 wxXmlResource
::wxXmlResource(int flags
, const wxString
& domain
)
110 m_data
= new wxXmlResourceDataRecords
;
114 wxXmlResource
::wxXmlResource(const wxString
& filemask
, int flags
, const wxString
& domain
)
118 m_data
= new wxXmlResourceDataRecords
;
123 wxXmlResource
::~wxXmlResource()
127 for ( wxXmlResourceDataRecords
::iterator i
= m_data
->begin();
128 i
!= m_data
->end(); ++i
)
135 void wxXmlResource
::SetDomain(const wxString
& domain
)
142 wxString wxXmlResource
::ConvertFileNameToURL(const wxString
& filename
)
144 wxString
fnd(filename
);
146 // NB: as Load() and Unload() accept both filenames and URLs (should
147 // probably be changed to filenames only, but embedded resources
148 // currently rely on its ability to handle URLs - FIXME) we need to
149 // determine whether found name is filename and not URL and this is the
150 // fastest/simplest way to do it
151 if (wxFileName
::FileExists(fnd
))
153 // Make the name absolute filename, because the app may
154 // change working directory later:
159 fnd
= fn
.GetFullPath();
162 fnd
= wxFileSystem
::FileNameToURL(fnd
);
172 bool wxXmlResource
::IsArchive(const wxString
& filename
)
174 const wxString fnd
= filename
.Lower();
176 return fnd
.Matches(wxT("*.zip")) || fnd
.Matches(wxT("*.xrs"));
179 #endif // wxUSE_FILESYSTEM
181 bool wxXmlResource
::LoadFile(const wxFileName
& file
)
183 return Load(wxFileSystem
::FileNameToURL(file
));
186 bool wxXmlResource
::LoadAllFiles(const wxString
& dirname
)
191 wxDir
::GetAllFiles(dirname
, &files
, "*.xrc");
193 for ( wxArrayString
::const_iterator i
= files
.begin(); i
!= files
.end(); ++i
)
202 bool wxXmlResource
::Load(const wxString
& filemask_
)
204 wxString filemask
= ConvertFileNameToURL(filemask_
);
208 # define wxXmlFindFirst fsys.FindFirst(filemask, wxFILE)
209 # define wxXmlFindNext fsys.FindNext()
211 # define wxXmlFindFirst wxFindFirstFile(filemask, wxFILE)
212 # define wxXmlFindNext wxFindNextFile()
214 wxString fnd
= wxXmlFindFirst
;
217 wxLogError(_("Cannot load resources from '%s'."), filemask
);
224 if ( IsArchive(fnd
) )
226 if ( !Load(fnd
+ wxT("#zip:*.xrc")) )
229 else // a single resource URL
230 #endif // wxUSE_FILESYSTEM
232 wxXmlResourceDataRecord
*drec
= new wxXmlResourceDataRecord
;
234 Data().push_back(drec
);
239 # undef wxXmlFindFirst
240 # undef wxXmlFindNext
242 return UpdateResources();
245 bool wxXmlResource
::Unload(const wxString
& filename
)
247 wxASSERT_MSG( !wxIsWild(filename
),
248 _T("wildcards not supported by wxXmlResource::Unload()") );
250 wxString fnd
= ConvertFileNameToURL(filename
);
252 const bool isArchive
= IsArchive(fnd
);
255 #endif // wxUSE_FILESYSTEM
257 bool unloaded
= false;
258 for ( wxXmlResourceDataRecords
::iterator i
= Data().begin();
259 i
!= Data().end(); ++i
)
264 if ( (*i
)->File
.StartsWith(fnd
) )
266 // don't break from the loop, we can have other matching files
268 else // a single resource URL
269 #endif // wxUSE_FILESYSTEM
271 if ( (*i
)->File
== fnd
)
277 // no sense in continuing, there is only one file with this URL
287 IMPLEMENT_ABSTRACT_CLASS(wxXmlResourceHandler
, wxObject
)
289 void wxXmlResource
::AddHandler(wxXmlResourceHandler
*handler
)
291 m_handlers
.push_back(handler
);
292 handler
->SetParentResource(this);
295 void wxXmlResource
::InsertHandler(wxXmlResourceHandler
*handler
)
297 m_handlers
.insert(m_handlers
.begin(), handler
);
298 handler
->SetParentResource(this);
303 void wxXmlResource
::ClearHandlers()
305 for ( wxVector
<wxXmlResourceHandler
*>::iterator i
= m_handlers
.begin();
306 i
!= m_handlers
.end(); ++i
)
312 wxMenu
*wxXmlResource
::LoadMenu(const wxString
& name
)
314 return (wxMenu
*)CreateResFromNode(FindResource(name
, wxT("wxMenu")), NULL
, NULL
);
319 wxMenuBar
*wxXmlResource
::LoadMenuBar(wxWindow
*parent
, const wxString
& name
)
321 return (wxMenuBar
*)CreateResFromNode(FindResource(name
, wxT("wxMenuBar")), parent
, NULL
);
327 wxToolBar
*wxXmlResource
::LoadToolBar(wxWindow
*parent
, const wxString
& name
)
329 return (wxToolBar
*)CreateResFromNode(FindResource(name
, wxT("wxToolBar")), parent
, NULL
);
334 wxDialog
*wxXmlResource
::LoadDialog(wxWindow
*parent
, const wxString
& name
)
336 return (wxDialog
*)CreateResFromNode(FindResource(name
, wxT("wxDialog")), parent
, NULL
);
339 bool wxXmlResource
::LoadDialog(wxDialog
*dlg
, wxWindow
*parent
, const wxString
& name
)
341 return CreateResFromNode(FindResource(name
, wxT("wxDialog")), parent
, dlg
) != NULL
;
346 wxPanel
*wxXmlResource
::LoadPanel(wxWindow
*parent
, const wxString
& name
)
348 return (wxPanel
*)CreateResFromNode(FindResource(name
, wxT("wxPanel")), parent
, NULL
);
351 bool wxXmlResource
::LoadPanel(wxPanel
*panel
, wxWindow
*parent
, const wxString
& name
)
353 return CreateResFromNode(FindResource(name
, wxT("wxPanel")), parent
, panel
) != NULL
;
356 wxFrame
*wxXmlResource
::LoadFrame(wxWindow
* parent
, const wxString
& name
)
358 return (wxFrame
*)CreateResFromNode(FindResource(name
, wxT("wxFrame")), parent
, NULL
);
361 bool wxXmlResource
::LoadFrame(wxFrame
* frame
, wxWindow
*parent
, const wxString
& name
)
363 return CreateResFromNode(FindResource(name
, wxT("wxFrame")), parent
, frame
) != NULL
;
366 wxBitmap wxXmlResource
::LoadBitmap(const wxString
& name
)
368 wxBitmap
*bmp
= (wxBitmap
*)CreateResFromNode(
369 FindResource(name
, wxT("wxBitmap")), NULL
, NULL
);
372 if (bmp
) { rt
= *bmp
; delete bmp
; }
376 wxIcon wxXmlResource
::LoadIcon(const wxString
& name
)
378 wxIcon
*icon
= (wxIcon
*)CreateResFromNode(
379 FindResource(name
, wxT("wxIcon")), NULL
, NULL
);
382 if (icon
) { rt
= *icon
; delete icon
; }
387 wxObject
*wxXmlResource
::LoadObject(wxWindow
*parent
, const wxString
& name
, const wxString
& classname
)
389 return CreateResFromNode(FindResource(name
, classname
), parent
, NULL
);
392 bool wxXmlResource
::LoadObject(wxObject
*instance
, wxWindow
*parent
, const wxString
& name
, const wxString
& classname
)
394 return CreateResFromNode(FindResource(name
, classname
), parent
, instance
) != NULL
;
398 bool wxXmlResource
::AttachUnknownControl(const wxString
& name
,
399 wxWindow
*control
, wxWindow
*parent
)
402 parent
= control
->GetParent();
403 wxWindow
*container
= parent
->FindWindow(name
+ wxT("_container"));
406 wxLogError(_("Cannot find container for unknown control '%s'."), name
.c_str());
409 return control
->Reparent(container
);
413 static void ProcessPlatformProperty(wxXmlNode
*node
)
418 wxXmlNode
*c
= node
->GetChildren();
422 if (!c
->GetAttribute(wxT("platform"), &s
))
426 wxStringTokenizer
tkn(s
, wxT(" |"));
428 while (tkn
.HasMoreTokens())
430 s
= tkn
.GetNextToken();
432 if (s
== wxT("win")) isok
= true;
434 #if defined(__MAC__) || defined(__APPLE__)
435 if (s
== wxT("mac")) isok
= true;
436 #elif defined(__UNIX__)
437 if (s
== wxT("unix")) isok
= true;
440 if (s
== wxT("os2")) isok
= true;
450 ProcessPlatformProperty(c
);
455 wxXmlNode
*c2
= c
->GetNext();
456 node
->RemoveChild(c
);
465 bool wxXmlResource
::UpdateResources()
469 # if wxUSE_FILESYSTEM
470 wxFSFile
*file
= NULL
;
475 wxString
encoding(wxT("UTF-8"));
476 #if !wxUSE_UNICODE && wxUSE_INTL
477 if ( (GetFlags() & wxXRC_USE_LOCALE
) == 0 )
479 // In case we are not using wxLocale to translate strings, convert the
480 // strings GUI's charset. This must not be done when wxXRC_USE_LOCALE
481 // is on, because it could break wxGetTranslation lookup.
482 encoding
= wxLocale
::GetSystemEncodingName();
486 for ( wxXmlResourceDataRecords
::iterator i
= Data().begin();
487 i
!= Data().end(); ++i
)
489 wxXmlResourceDataRecord
* const rec
= *i
;
491 modif
= (rec
->Doc
== NULL
);
493 if (!modif
&& !(m_flags
& wxXRC_NO_RELOADING
))
495 # if wxUSE_FILESYSTEM
496 file
= fsys
.OpenFile(rec
->File
);
498 modif
= file
&& file
->GetModificationTime() > rec
->Time
;
499 # else // wxUSE_DATETIME
501 # endif // wxUSE_DATETIME
504 wxLogError(_("Cannot open file '%s'."), rec
->File
);
509 # else // wxUSE_FILESYSTEM
511 modif
= wxDateTime(wxFileModificationTime(rec
->File
)) > rec
->Time
;
512 # else // wxUSE_DATETIME
514 # endif // wxUSE_DATETIME
515 # endif // wxUSE_FILESYSTEM
520 wxLogTrace(_T("xrc"), _T("opening file '%s'"), rec
->File
);
522 wxInputStream
*stream
= NULL
;
524 # if wxUSE_FILESYSTEM
525 file
= fsys
.OpenFile(rec
->File
);
527 stream
= file
->GetStream();
529 stream
= new wxFileInputStream(rec
->File
);
535 rec
->Doc
= new wxXmlDocument
;
537 if (!stream
|| !stream
->IsOk() || !rec
->Doc
->Load(*stream
, encoding
))
539 wxLogError(_("Cannot load resources from file '%s'."),
544 else if (rec
->Doc
->GetRoot()->GetName() != wxT("resource"))
546 wxLogError(_("Invalid XRC resource '%s': doesn't have root node 'resource'."), rec
->File
);
554 wxString verstr
= rec
->Doc
->GetRoot()->GetAttribute(
555 wxT("version"), wxT("0.0.0.0"));
556 if (wxSscanf(verstr
.c_str(), wxT("%i.%i.%i.%i"),
557 &v1
, &v2
, &v3
, &v4
) == 4)
558 version
= v1
*256*256*256+v2
*256*256+v3
*256+v4
;
563 if (m_version
!= version
)
565 wxLogError(_("Resource files must have same version number!"));
569 ProcessPlatformProperty(rec
->Doc
->GetRoot());
572 rec
->Time
= file
->GetModificationTime();
573 #else // wxUSE_FILESYSTEM
574 rec
->Time
= wxDateTime(wxFileModificationTime(rec
->File
));
575 #endif // wxUSE_FILESYSTEM
576 #endif // wxUSE_DATETIME
579 # if wxUSE_FILESYSTEM
591 wxXmlNode
*wxXmlResource
::DoFindResource(wxXmlNode
*parent
,
592 const wxString
& name
,
593 const wxString
& classname
,
594 bool recursive
) const
598 // first search for match at the top-level nodes (as this is
599 // where the resource is most commonly looked for):
600 for (node
= parent
->GetChildren(); node
; node
= node
->GetNext())
602 if ( IsObjectNode(node
) && node
->GetAttribute(wxS("name")) == name
)
604 // empty class name matches everything
605 if ( classname
.empty() )
608 wxString
cls(node
->GetAttribute(wxS("class")));
610 // object_ref may not have 'class' attribute:
611 if (cls
.empty() && node
->GetName() == wxS("object_ref"))
613 wxString refName
= node
->GetAttribute(wxS("ref"));
617 const wxXmlNode
* const refNode
= GetResourceNode(refName
);
619 cls
= refNode
->GetAttribute(wxS("class"));
622 if ( cls
== classname
)
627 // then recurse in child nodes
630 for (node
= parent
->GetChildren(); node
; node
= node
->GetNext())
632 if ( IsObjectNode(node
) )
634 wxXmlNode
* found
= DoFindResource(node
, name
, classname
, true);
644 wxXmlNode
*wxXmlResource
::FindResource(const wxString
& name
,
645 const wxString
& classname
,
650 node
= GetResourceNodeAndLocation(name
, classname
, recursive
, &path
);
654 wxLogError(_("XRC resource '%s' (class '%s') not found!"),
658 else // node was found
660 // ensure that relative paths work correctly when loading this node
661 // (which should happen as soon as we return as FindResource() result
662 // is always passed to CreateResFromNode())
663 m_curFileSystem
.ChangePathTo(path
);
665 #endif // wxUSE_FILESYSTEM
671 wxXmlResource
::GetResourceNodeAndLocation(const wxString
& name
,
672 const wxString
& classname
,
674 wxString
*path
) const
676 // ensure everything is up-to-date: this is needed to support on-remand
677 // reloading of XRC files
678 const_cast<wxXmlResource
*>(this)->UpdateResources();
680 for ( wxXmlResourceDataRecords
::const_iterator f
= Data().begin();
681 f
!= Data().end(); ++f
)
683 wxXmlResourceDataRecord
*const rec
= *f
;
684 wxXmlDocument
* const doc
= rec
->Doc
;
685 if ( !doc
|| !doc
->GetRoot() )
689 found
= DoFindResource(doc
->GetRoot(), name
, classname
, recursive
);
702 static void MergeNodes(wxXmlNode
& dest
, wxXmlNode
& with
)
705 for ( wxXmlAttribute
*attr
= with
.GetAttributes();
706 attr
; attr
= attr
->GetNext() )
708 wxXmlAttribute
*dattr
;
709 for (dattr
= dest
.GetAttributes(); dattr
; dattr
= dattr
->GetNext())
712 if ( dattr
->GetName() == attr
->GetName() )
714 dattr
->SetValue(attr
->GetValue());
720 dest
.AddAttribute(attr
->GetName(), attr
->GetValue());
723 // Merge child nodes:
724 for (wxXmlNode
* node
= with
.GetChildren(); node
; node
= node
->GetNext())
726 wxString name
= node
->GetAttribute(wxT("name"), wxEmptyString
);
729 for (dnode
= dest
.GetChildren(); dnode
; dnode
= dnode
->GetNext() )
731 if ( dnode
->GetName() == node
->GetName() &&
732 dnode
->GetAttribute(wxT("name"), wxEmptyString
) == name
&&
733 dnode
->GetType() == node
->GetType() )
735 MergeNodes(*dnode
, *node
);
742 static const wxChar
*AT_END
= wxT("end");
743 wxString insert_pos
= node
->GetAttribute(wxT("insert_at"), AT_END
);
744 if ( insert_pos
== AT_END
)
746 dest
.AddChild(new wxXmlNode(*node
));
748 else if ( insert_pos
== wxT("begin") )
750 dest
.InsertChild(new wxXmlNode(*node
), dest
.GetChildren());
755 if ( dest
.GetType() == wxXML_TEXT_NODE
&& with
.GetContent().length() )
756 dest
.SetContent(with
.GetContent());
759 wxObject
*wxXmlResource
::CreateResFromNode(wxXmlNode
*node
, wxObject
*parent
,
761 wxXmlResourceHandler
*handlerToUse
)
763 if (node
== NULL
) return NULL
;
765 // handling of referenced resource
766 if ( node
->GetName() == wxT("object_ref") )
768 wxString refName
= node
->GetAttribute(wxT("ref"), wxEmptyString
);
769 wxXmlNode
* refNode
= FindResource(refName
, wxEmptyString
, true);
773 wxLogError(_("Referenced object node with ref=\"%s\" not found!"),
778 wxXmlNode
copy(*refNode
);
779 MergeNodes(copy
, *node
);
781 return CreateResFromNode(©
, parent
, instance
);
786 if (handlerToUse
->CanHandle(node
))
788 return handlerToUse
->CreateResource(node
, parent
, instance
);
791 else if (node
->GetName() == wxT("object"))
793 for ( wxVector
<wxXmlResourceHandler
*>::iterator h
= m_handlers
.begin();
794 h
!= m_handlers
.end(); ++h
)
796 wxXmlResourceHandler
*handler
= *h
;
797 if (handler
->CanHandle(node
))
798 return handler
->CreateResource(node
, parent
, instance
);
802 wxLogError(_("No handler found for XML node '%s', class '%s'!"),
803 node
->GetName().c_str(),
804 node
->GetAttribute(wxT("class"), wxEmptyString
).c_str());
809 class wxXmlSubclassFactories
: public wxVector
<wxXmlSubclassFactory
*>
811 // this is a class so that it can be forward-declared
814 wxXmlSubclassFactories
*wxXmlResource
::ms_subclassFactories
= NULL
;
816 /*static*/ void wxXmlResource
::AddSubclassFactory(wxXmlSubclassFactory
*factory
)
818 if (!ms_subclassFactories
)
820 ms_subclassFactories
= new wxXmlSubclassFactories
;
822 ms_subclassFactories
->push_back(factory
);
825 class wxXmlSubclassFactoryCXX
: public wxXmlSubclassFactory
828 ~wxXmlSubclassFactoryCXX() {}
830 wxObject
*Create(const wxString
& className
)
832 wxClassInfo
* classInfo
= wxClassInfo
::FindClass(className
);
835 return classInfo
->CreateObject();
844 wxXmlResourceHandler
::wxXmlResourceHandler()
845 : m_node(NULL
), m_parent(NULL
), m_instance(NULL
),
846 m_parentAsWindow(NULL
)
851 wxObject
*wxXmlResourceHandler
::CreateResource(wxXmlNode
*node
, wxObject
*parent
, wxObject
*instance
)
853 wxXmlNode
*myNode
= m_node
;
854 wxString myClass
= m_class
;
855 wxObject
*myParent
= m_parent
, *myInstance
= m_instance
;
856 wxWindow
*myParentAW
= m_parentAsWindow
;
858 m_instance
= instance
;
859 if (!m_instance
&& node
->HasAttribute(wxT("subclass")) &&
860 !(m_resource
->GetFlags() & wxXRC_NO_SUBCLASSING
))
862 wxString subclass
= node
->GetAttribute(wxT("subclass"), wxEmptyString
);
863 if (!subclass
.empty())
865 for (wxXmlSubclassFactories
::iterator i
= wxXmlResource
::ms_subclassFactories
->begin();
866 i
!= wxXmlResource
::ms_subclassFactories
->end(); ++i
)
868 m_instance
= (*i
)->Create(subclass
);
875 wxString name
= node
->GetAttribute(wxT("name"), wxEmptyString
);
876 wxLogError(_("Subclass '%s' not found for resource '%s', not subclassing!"),
877 subclass
.c_str(), name
.c_str());
883 m_class
= node
->GetAttribute(wxT("class"), wxEmptyString
);
885 m_parentAsWindow
= wxDynamicCast(m_parent
, wxWindow
);
887 wxObject
*returned
= DoCreateResource();
891 m_parent
= myParent
; m_parentAsWindow
= myParentAW
;
892 m_instance
= myInstance
;
898 void wxXmlResourceHandler
::AddStyle(const wxString
& name
, int value
)
900 m_styleNames
.Add(name
);
901 m_styleValues
.Add(value
);
906 void wxXmlResourceHandler
::AddWindowStyles()
908 XRC_ADD_STYLE(wxCLIP_CHILDREN
);
910 // the border styles all have the old and new names, recognize both for now
911 XRC_ADD_STYLE(wxSIMPLE_BORDER
); XRC_ADD_STYLE(wxBORDER_SIMPLE
);
912 XRC_ADD_STYLE(wxSUNKEN_BORDER
); XRC_ADD_STYLE(wxBORDER_SUNKEN
);
913 XRC_ADD_STYLE(wxDOUBLE_BORDER
); XRC_ADD_STYLE(wxBORDER_DOUBLE
);
914 XRC_ADD_STYLE(wxRAISED_BORDER
); XRC_ADD_STYLE(wxBORDER_RAISED
);
915 XRC_ADD_STYLE(wxSTATIC_BORDER
); XRC_ADD_STYLE(wxBORDER_STATIC
);
916 XRC_ADD_STYLE(wxNO_BORDER
); XRC_ADD_STYLE(wxBORDER_NONE
);
918 XRC_ADD_STYLE(wxTRANSPARENT_WINDOW
);
919 XRC_ADD_STYLE(wxWANTS_CHARS
);
920 XRC_ADD_STYLE(wxTAB_TRAVERSAL
);
921 XRC_ADD_STYLE(wxNO_FULL_REPAINT_ON_RESIZE
);
922 XRC_ADD_STYLE(wxFULL_REPAINT_ON_RESIZE
);
923 XRC_ADD_STYLE(wxALWAYS_SHOW_SB
);
924 XRC_ADD_STYLE(wxWS_EX_BLOCK_EVENTS
);
925 XRC_ADD_STYLE(wxWS_EX_VALIDATE_RECURSIVELY
);
930 bool wxXmlResourceHandler
::HasParam(const wxString
& param
)
932 return (GetParamNode(param
) != NULL
);
936 int wxXmlResourceHandler
::GetStyle(const wxString
& param
, int defaults
)
938 wxString s
= GetParamValue(param
);
940 if (!s
) return defaults
;
942 wxStringTokenizer
tkn(s
, wxT("| \t\n"), wxTOKEN_STRTOK
);
946 while (tkn
.HasMoreTokens())
948 fl
= tkn
.GetNextToken();
949 index
= m_styleNames
.Index(fl
);
950 if (index
!= wxNOT_FOUND
)
951 style
|= m_styleValues
[index
];
953 wxLogError(_("Unknown style flag ") + fl
);
960 wxString wxXmlResourceHandler
::GetText(const wxString
& param
, bool translate
)
962 wxXmlNode
*parNode
= GetParamNode(param
);
963 wxString
str1(GetNodeContent(parNode
));
966 // "\\" wasn't translated to "\" prior to 2.5.3.0:
967 const bool escapeBackslash
= (m_resource
->CompareVersion(2,5,3,0) >= 0);
969 // VS: First version of XRC resources used $ instead of & (which is
970 // illegal in XML), but later I realized that '_' fits this purpose
971 // much better (because &File means "File with F underlined").
972 const wxChar amp_char
= (m_resource
->CompareVersion(2,3,0,1) < 0)
975 for ( wxString
::const_iterator dt
= str1
.begin(); dt
!= str1
.end(); ++dt
)
977 // Remap amp_char to &, map double amp_char to amp_char (for things
978 // like "&File..." -- this is illegal in XML, so we use "_File..."):
979 if ( *dt
== amp_char
)
981 if ( *(++dt
) == amp_char
)
984 str2
<< wxT('&') << *dt
;
986 // Remap \n to CR, \r to LF, \t to TAB, \\ to \:
987 else if ( *dt
== wxT('\\') )
989 switch ( (*(++dt
)).GetValue() )
1004 // "\\" wasn't translated to "\" prior to 2.5.3.0:
1005 if ( escapeBackslash
)
1010 // else fall-through to default: branch below
1013 str2
<< wxT('\\') << *dt
;
1023 if (m_resource
->GetFlags() & wxXRC_USE_LOCALE
)
1025 if (translate
&& parNode
&&
1026 parNode
->GetAttribute(wxT("translate"), wxEmptyString
) != wxT("0"))
1028 return wxGetTranslation(str2
, m_resource
->GetDomain());
1035 // The string is internally stored as UTF-8, we have to convert
1036 // it into system's default encoding so that it can be displayed:
1037 return wxString(str2
.wc_str(wxConvUTF8
), wxConvLocal
);
1042 // If wxXRC_USE_LOCALE is not set, then the string is already in
1043 // system's default encoding in ANSI build, so we don't have to
1044 // do anything special here.
1050 long wxXmlResourceHandler
::GetLong(const wxString
& param
, long defaultv
)
1053 wxString str1
= GetParamValue(param
);
1055 if (!str1
.ToLong(&value
))
1061 float wxXmlResourceHandler
::GetFloat(const wxString
& param
, float defaultv
)
1063 wxString str
= GetParamValue(param
);
1066 // strings in XRC always use C locale but wxString::ToDouble() uses the
1067 // current one, so transform the string to it supposing that the only
1068 // difference between them is the decimal separator
1070 // TODO: use wxString::ToCDouble() when we have it
1071 str
.Replace(wxT("."), wxLocale
::GetInfo(wxLOCALE_DECIMAL_POINT
,
1072 wxLOCALE_CAT_NUMBER
));
1073 #endif // wxUSE_INTL
1076 if (!str
.ToDouble(&value
))
1079 return wx_truncate_cast(float, value
);
1083 int wxXmlResourceHandler
::GetID()
1085 return wxXmlResource
::GetXRCID(GetName());
1090 wxString wxXmlResourceHandler
::GetName()
1092 return m_node
->GetAttribute(wxT("name"), wxT("-1"));
1097 bool wxXmlResourceHandler
::GetBoolAttr(const wxString
& attr
, bool defaultv
)
1100 return m_node
->GetAttribute(attr
, &v
) ? v
== '1' : defaultv
;
1103 bool wxXmlResourceHandler
::GetBool(const wxString
& param
, bool defaultv
)
1105 const wxString v
= GetParamValue(param
);
1107 return v
.empty() ? defaultv
: (v
== '1');
1111 static wxColour
GetSystemColour(const wxString
& name
)
1115 #define SYSCLR(clr) \
1116 if (name == _T(#clr)) return wxSystemSettings::GetColour(clr);
1117 SYSCLR(wxSYS_COLOUR_SCROLLBAR
)
1118 SYSCLR(wxSYS_COLOUR_BACKGROUND
)
1119 SYSCLR(wxSYS_COLOUR_DESKTOP
)
1120 SYSCLR(wxSYS_COLOUR_ACTIVECAPTION
)
1121 SYSCLR(wxSYS_COLOUR_INACTIVECAPTION
)
1122 SYSCLR(wxSYS_COLOUR_MENU
)
1123 SYSCLR(wxSYS_COLOUR_WINDOW
)
1124 SYSCLR(wxSYS_COLOUR_WINDOWFRAME
)
1125 SYSCLR(wxSYS_COLOUR_MENUTEXT
)
1126 SYSCLR(wxSYS_COLOUR_WINDOWTEXT
)
1127 SYSCLR(wxSYS_COLOUR_CAPTIONTEXT
)
1128 SYSCLR(wxSYS_COLOUR_ACTIVEBORDER
)
1129 SYSCLR(wxSYS_COLOUR_INACTIVEBORDER
)
1130 SYSCLR(wxSYS_COLOUR_APPWORKSPACE
)
1131 SYSCLR(wxSYS_COLOUR_HIGHLIGHT
)
1132 SYSCLR(wxSYS_COLOUR_HIGHLIGHTTEXT
)
1133 SYSCLR(wxSYS_COLOUR_BTNFACE
)
1134 SYSCLR(wxSYS_COLOUR_3DFACE
)
1135 SYSCLR(wxSYS_COLOUR_BTNSHADOW
)
1136 SYSCLR(wxSYS_COLOUR_3DSHADOW
)
1137 SYSCLR(wxSYS_COLOUR_GRAYTEXT
)
1138 SYSCLR(wxSYS_COLOUR_BTNTEXT
)
1139 SYSCLR(wxSYS_COLOUR_INACTIVECAPTIONTEXT
)
1140 SYSCLR(wxSYS_COLOUR_BTNHIGHLIGHT
)
1141 SYSCLR(wxSYS_COLOUR_BTNHILIGHT
)
1142 SYSCLR(wxSYS_COLOUR_3DHIGHLIGHT
)
1143 SYSCLR(wxSYS_COLOUR_3DHILIGHT
)
1144 SYSCLR(wxSYS_COLOUR_3DDKSHADOW
)
1145 SYSCLR(wxSYS_COLOUR_3DLIGHT
)
1146 SYSCLR(wxSYS_COLOUR_INFOTEXT
)
1147 SYSCLR(wxSYS_COLOUR_INFOBK
)
1148 SYSCLR(wxSYS_COLOUR_LISTBOX
)
1149 SYSCLR(wxSYS_COLOUR_HOTLIGHT
)
1150 SYSCLR(wxSYS_COLOUR_GRADIENTACTIVECAPTION
)
1151 SYSCLR(wxSYS_COLOUR_GRADIENTINACTIVECAPTION
)
1152 SYSCLR(wxSYS_COLOUR_MENUHILIGHT
)
1153 SYSCLR(wxSYS_COLOUR_MENUBAR
)
1157 return wxNullColour
;
1160 wxColour wxXmlResourceHandler
::GetColour(const wxString
& param
, const wxColour
& defaultv
)
1162 wxString v
= GetParamValue(param
);
1169 // wxString -> wxColour conversion
1172 // the colour doesn't use #RRGGBB format, check if it is symbolic
1174 clr
= GetSystemColour(v
);
1178 wxLogError(_("XRC resource: Incorrect colour specification '%s' for attribute '%s'."),
1179 v
.c_str(), param
.c_str());
1180 return wxNullColour
;
1188 wxBitmap wxXmlResourceHandler
::GetBitmap(const wxString
& param
,
1189 const wxArtClient
& defaultArtClient
,
1192 /* If the bitmap is specified as stock item, query wxArtProvider for it: */
1193 wxXmlNode
*bmpNode
= GetParamNode(param
);
1196 wxString sid
= bmpNode
->GetAttribute(wxT("stock_id"), wxEmptyString
);
1199 wxString scl
= bmpNode
->GetAttribute(wxT("stock_client"), wxEmptyString
);
1201 scl
= defaultArtClient
;
1203 scl
= wxART_MAKE_CLIENT_ID_FROM_STR(scl
);
1206 wxArtProvider
::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(sid
),
1208 if ( stockArt
.Ok() )
1213 /* ...or load the bitmap from file: */
1214 wxString name
= GetParamValue(param
);
1215 if (name
.empty()) return wxNullBitmap
;
1216 #if wxUSE_FILESYSTEM
1217 wxFSFile
*fsfile
= GetCurFileSystem().OpenFile(name
, wxFS_READ
| wxFS_SEEKABLE
);
1220 wxLogError(_("XRC resource: Cannot create bitmap from '%s'."),
1222 return wxNullBitmap
;
1224 wxImage
img(*(fsfile
->GetStream()));
1232 wxLogError(_("XRC resource: Cannot create bitmap from '%s'."),
1234 return wxNullBitmap
;
1236 if (!(size
== wxDefaultSize
)) img
.Rescale(size
.x
, size
.y
);
1237 return wxBitmap(img
);
1241 wxIcon wxXmlResourceHandler
::GetIcon(const wxString
& param
,
1242 const wxArtClient
& defaultArtClient
,
1246 icon
.CopyFromBitmap(GetBitmap(param
, defaultArtClient
, size
));
1252 wxXmlNode
*wxXmlResourceHandler
::GetParamNode(const wxString
& param
)
1254 wxCHECK_MSG(m_node
, NULL
, wxT("You can't access handler data before it was initialized!"));
1256 wxXmlNode
*n
= m_node
->GetChildren();
1260 if (n
->GetType() == wxXML_ELEMENT_NODE
&& n
->GetName() == param
)
1262 // TODO: check that there are no other properties/parameters with
1263 // the same name and log an error if there are (can't do this
1264 // right now as I'm not sure if it's not going to break code
1265 // using this function in unintentional way (i.e. for
1266 // accessing other things than properties), for example
1267 // wxBitmapComboBoxXmlHandler almost surely does
1275 bool wxXmlResourceHandler
::IsOfClass(wxXmlNode
*node
, const wxString
& classname
)
1277 return node
->GetAttribute(wxT("class"), wxEmptyString
) == classname
;
1282 wxString wxXmlResourceHandler
::GetNodeContent(wxXmlNode
*node
)
1284 wxXmlNode
*n
= node
;
1285 if (n
== NULL
) return wxEmptyString
;
1286 n
= n
->GetChildren();
1290 if (n
->GetType() == wxXML_TEXT_NODE
||
1291 n
->GetType() == wxXML_CDATA_SECTION_NODE
)
1292 return n
->GetContent();
1295 return wxEmptyString
;
1300 wxString wxXmlResourceHandler
::GetParamValue(const wxString
& param
)
1303 return GetNodeContent(m_node
);
1305 return GetNodeContent(GetParamNode(param
));
1310 wxSize wxXmlResourceHandler
::GetSize(const wxString
& param
,
1311 wxWindow
*windowToUse
)
1313 wxString s
= GetParamValue(param
);
1314 if (s
.empty()) s
= wxT("-1,-1");
1318 is_dlg
= s
[s
.length()-1] == wxT('d');
1319 if (is_dlg
) s
.RemoveLast();
1321 if (!s
.BeforeFirst(wxT(',')).ToLong(&sx
) ||
1322 !s
.AfterLast(wxT(',')).ToLong(&sy
))
1324 wxLogError(_("Cannot parse coordinates from '%s'."), s
.c_str());
1325 return wxDefaultSize
;
1332 return wxDLG_UNIT(windowToUse
, wxSize(sx
, sy
));
1334 else if (m_parentAsWindow
)
1336 return wxDLG_UNIT(m_parentAsWindow
, wxSize(sx
, sy
));
1340 wxLogError(_("Cannot convert dialog units: dialog unknown."));
1341 return wxDefaultSize
;
1345 return wxSize(sx
, sy
);
1350 wxPoint wxXmlResourceHandler
::GetPosition(const wxString
& param
)
1352 wxSize sz
= GetSize(param
);
1353 return wxPoint(sz
.x
, sz
.y
);
1358 wxCoord wxXmlResourceHandler
::GetDimension(const wxString
& param
,
1360 wxWindow
*windowToUse
)
1362 wxString s
= GetParamValue(param
);
1363 if (s
.empty()) return defaultv
;
1367 is_dlg
= s
[s
.length()-1] == wxT('d');
1368 if (is_dlg
) s
.RemoveLast();
1372 wxLogError(_("Cannot parse dimension from '%s'."), s
.c_str());
1380 return wxDLG_UNIT(windowToUse
, wxSize(sx
, 0)).x
;
1382 else if (m_parentAsWindow
)
1384 return wxDLG_UNIT(m_parentAsWindow
, wxSize(sx
, 0)).x
;
1388 wxLogError(_("Cannot convert dialog units: dialog unknown."));
1397 // Get system font index using indexname
1398 static wxFont
GetSystemFont(const wxString
& name
)
1402 #define SYSFNT(fnt) \
1403 if (name == _T(#fnt)) return wxSystemSettings::GetFont(fnt);
1404 SYSFNT(wxSYS_OEM_FIXED_FONT
)
1405 SYSFNT(wxSYS_ANSI_FIXED_FONT
)
1406 SYSFNT(wxSYS_ANSI_VAR_FONT
)
1407 SYSFNT(wxSYS_SYSTEM_FONT
)
1408 SYSFNT(wxSYS_DEVICE_DEFAULT_FONT
)
1409 SYSFNT(wxSYS_SYSTEM_FIXED_FONT
)
1410 SYSFNT(wxSYS_DEFAULT_GUI_FONT
)
1417 wxFont wxXmlResourceHandler
::GetFont(const wxString
& param
)
1419 wxXmlNode
*font_node
= GetParamNode(param
);
1420 if (font_node
== NULL
)
1422 wxLogError(_("Cannot find font node '%s'."), param
.c_str());
1426 wxXmlNode
*oldnode
= m_node
;
1433 bool hasSize
= HasParam(wxT("size"));
1435 isize
= GetLong(wxT("size"), -1);
1438 int istyle
= wxNORMAL
;
1439 bool hasStyle
= HasParam(wxT("style"));
1442 wxString style
= GetParamValue(wxT("style"));
1443 if (style
== wxT("italic"))
1445 else if (style
== wxT("slant"))
1450 int iweight
= wxNORMAL
;
1451 bool hasWeight
= HasParam(wxT("weight"));
1454 wxString weight
= GetParamValue(wxT("weight"));
1455 if (weight
== wxT("bold"))
1457 else if (weight
== wxT("light"))
1462 bool hasUnderlined
= HasParam(wxT("underlined"));
1463 bool underlined
= hasUnderlined ?
GetBool(wxT("underlined"), false) : false;
1465 // family and facename
1466 int ifamily
= wxDEFAULT
;
1467 bool hasFamily
= HasParam(wxT("family"));
1470 wxString family
= GetParamValue(wxT("family"));
1471 if (family
== wxT("decorative")) ifamily
= wxDECORATIVE
;
1472 else if (family
== wxT("roman")) ifamily
= wxROMAN
;
1473 else if (family
== wxT("script")) ifamily
= wxSCRIPT
;
1474 else if (family
== wxT("swiss")) ifamily
= wxSWISS
;
1475 else if (family
== wxT("modern")) ifamily
= wxMODERN
;
1476 else if (family
== wxT("teletype")) ifamily
= wxTELETYPE
;
1481 bool hasFacename
= HasParam(wxT("face"));
1484 wxString faces
= GetParamValue(wxT("face"));
1485 wxStringTokenizer
tk(faces
, wxT(","));
1487 wxArrayString
facenames(wxFontEnumerator
::GetFacenames());
1488 while (tk
.HasMoreTokens())
1490 int index
= facenames
.Index(tk
.GetNextToken(), false);
1491 if (index
!= wxNOT_FOUND
)
1493 facename
= facenames
[index
];
1497 #else // !wxUSE_FONTENUM
1498 // just use the first face name if we can't check its availability:
1499 if (tk
.HasMoreTokens())
1500 facename
= tk
.GetNextToken();
1501 #endif // wxUSE_FONTENUM/!wxUSE_FONTENUM
1505 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
1506 bool hasEncoding
= HasParam(wxT("encoding"));
1509 wxString encoding
= GetParamValue(wxT("encoding"));
1510 wxFontMapper mapper
;
1511 if (!encoding
.empty())
1512 enc
= mapper
.CharsetToEncoding(encoding
);
1513 if (enc
== wxFONTENCODING_SYSTEM
)
1514 enc
= wxFONTENCODING_DEFAULT
;
1517 // is this font based on a system font?
1518 wxFont font
= GetSystemFont(GetParamValue(wxT("sysfont")));
1522 if (hasSize
&& isize
!= -1)
1523 font
.SetPointSize(isize
);
1524 else if (HasParam(wxT("relativesize")))
1525 font
.SetPointSize(int(font
.GetPointSize() *
1526 GetFloat(wxT("relativesize"))));
1529 font
.SetStyle(istyle
);
1531 font
.SetWeight(iweight
);
1533 font
.SetUnderlined(underlined
);
1535 font
.SetFamily(ifamily
);
1537 font
.SetFaceName(facename
);
1539 font
.SetDefaultEncoding(enc
);
1541 else // not based on system font
1543 font
= wxFont(isize
== -1 ? wxNORMAL_FONT
->GetPointSize() : isize
,
1544 ifamily
, istyle
, iweight
,
1545 underlined
, facename
, enc
);
1553 void wxXmlResourceHandler
::SetupWindow(wxWindow
*wnd
)
1555 //FIXME : add cursor
1557 if (HasParam(wxT("exstyle")))
1558 // Have to OR it with existing style, since
1559 // some implementations (e.g. wxGTK) use the extra style
1561 wnd
->SetExtraStyle(wnd
->GetExtraStyle() | GetStyle(wxT("exstyle")));
1562 if (HasParam(wxT("bg")))
1563 wnd
->SetBackgroundColour(GetColour(wxT("bg")));
1564 if (HasParam(wxT("fg")))
1565 wnd
->SetForegroundColour(GetColour(wxT("fg")));
1566 if (GetBool(wxT("enabled"), 1) == 0)
1568 if (GetBool(wxT("focused"), 0) == 1)
1570 if (GetBool(wxT("hidden"), 0) == 1)
1573 if (HasParam(wxT("tooltip")))
1574 wnd
->SetToolTip(GetText(wxT("tooltip")));
1576 if (HasParam(wxT("font")))
1577 wnd
->SetFont(GetFont());
1578 if (HasParam(wxT("help")))
1579 wnd
->SetHelpText(GetText(wxT("help")));
1583 void wxXmlResourceHandler
::CreateChildren(wxObject
*parent
, bool this_hnd_only
)
1585 for ( wxXmlNode
*n
= m_node
->GetChildren(); n
; n
= n
->GetNext() )
1587 if ( IsObjectNode(n
) )
1589 m_resource
->CreateResFromNode(n
, parent
, NULL
,
1590 this_hnd_only ?
this : NULL
);
1596 void wxXmlResourceHandler
::CreateChildrenPrivately(wxObject
*parent
, wxXmlNode
*rootnode
)
1599 if (rootnode
== NULL
) root
= m_node
; else root
= rootnode
;
1600 wxXmlNode
*n
= root
->GetChildren();
1604 if (n
->GetType() == wxXML_ELEMENT_NODE
&& CanHandle(n
))
1606 CreateResource(n
, parent
, NULL
);
1618 // --------------- XRCID implementation -----------------------------
1620 #define XRCID_TABLE_SIZE 1024
1625 /* Hold the id so that once an id is allocated for a name, it
1626 does not get created again by NewControlId at least
1627 until we are done with it */
1633 static XRCID_record
*XRCID_Records
[XRCID_TABLE_SIZE
] = {NULL
};
1635 static int XRCID_Lookup(const char *str_id
, int value_if_not_found
= wxID_NONE
)
1639 for (const char *c
= str_id
; *c
!= '\0'; c
++) index
+= (int)*c
;
1640 index
%= XRCID_TABLE_SIZE
;
1642 XRCID_record
*oldrec
= NULL
;
1643 for (XRCID_record
*rec
= XRCID_Records
[index
]; rec
; rec
= rec
->next
)
1645 if (wxStrcmp(rec
->key
, str_id
) == 0)
1652 XRCID_record
**rec_var
= (oldrec
== NULL
) ?
1653 &XRCID_Records
[index
] : &oldrec
->next
;
1654 *rec_var
= new XRCID_record
;
1655 (*rec_var
)->key
= wxStrdup(str_id
);
1656 (*rec_var
)->next
= NULL
;
1659 if (value_if_not_found
!= wxID_NONE
)
1660 (*rec_var
)->id
= value_if_not_found
;
1663 int asint
= wxStrtol(str_id
, &end
, 10);
1664 if (*str_id
&& *end
== 0)
1666 // if str_id was integer, keep it verbosely:
1667 (*rec_var
)->id
= asint
;
1671 (*rec_var
)->id
= wxWindowBase
::NewControlId();
1675 return (*rec_var
)->id
;
1678 static void AddStdXRCID_Records();
1681 int wxXmlResource
::DoGetXRCID(const char *str_id
, int value_if_not_found
)
1683 static bool s_stdIDsAdded
= false;
1685 if ( !s_stdIDsAdded
)
1687 s_stdIDsAdded
= true;
1688 AddStdXRCID_Records();
1691 return XRCID_Lookup(str_id
, value_if_not_found
);
1695 wxString wxXmlResource
::FindXRCIDById(int numId
)
1697 for ( int i
= 0; i
< XRCID_TABLE_SIZE
; i
++ )
1699 for ( XRCID_record
*rec
= XRCID_Records
[i
]; rec
; rec
= rec
->next
)
1701 if ( rec
->id
== numId
)
1702 return wxString(rec
->key
);
1709 static void CleanXRCID_Record(XRCID_record
*rec
)
1713 CleanXRCID_Record(rec
->next
);
1720 static void CleanXRCID_Records()
1722 for (int i
= 0; i
< XRCID_TABLE_SIZE
; i
++)
1724 CleanXRCID_Record(XRCID_Records
[i
]);
1725 XRCID_Records
[i
] = NULL
;
1729 static void AddStdXRCID_Records()
1731 #define stdID(id) XRCID_Lookup(#id, id)
1735 stdID(wxID_SEPARATOR
);
1748 stdID(wxID_PRINT_SETUP
);
1749 stdID(wxID_PAGE_SETUP
);
1750 stdID(wxID_PREVIEW
);
1752 stdID(wxID_HELP_CONTENTS
);
1753 stdID(wxID_HELP_COMMANDS
);
1754 stdID(wxID_HELP_PROCEDURES
);
1755 stdID(wxID_HELP_CONTEXT
);
1756 stdID(wxID_CLOSE_ALL
);
1757 stdID(wxID_PREFERENCES
);
1764 stdID(wxID_DUPLICATE
);
1765 stdID(wxID_SELECTALL
);
1767 stdID(wxID_REPLACE
);
1768 stdID(wxID_REPLACE_ALL
);
1769 stdID(wxID_PROPERTIES
);
1770 stdID(wxID_VIEW_DETAILS
);
1771 stdID(wxID_VIEW_LARGEICONS
);
1772 stdID(wxID_VIEW_SMALLICONS
);
1773 stdID(wxID_VIEW_LIST
);
1774 stdID(wxID_VIEW_SORTDATE
);
1775 stdID(wxID_VIEW_SORTNAME
);
1776 stdID(wxID_VIEW_SORTSIZE
);
1777 stdID(wxID_VIEW_SORTTYPE
);
1793 stdID(wxID_FORWARD
);
1794 stdID(wxID_BACKWARD
);
1795 stdID(wxID_DEFAULT
);
1799 stdID(wxID_CONTEXT_HELP
);
1800 stdID(wxID_YESTOALL
);
1801 stdID(wxID_NOTOALL
);
1810 stdID(wxID_REFRESH
);
1815 stdID(wxID_JUSTIFY_CENTER
);
1816 stdID(wxID_JUSTIFY_FILL
);
1817 stdID(wxID_JUSTIFY_RIGHT
);
1818 stdID(wxID_JUSTIFY_LEFT
);
1819 stdID(wxID_UNDERLINE
);
1821 stdID(wxID_UNINDENT
);
1822 stdID(wxID_ZOOM_100
);
1823 stdID(wxID_ZOOM_FIT
);
1824 stdID(wxID_ZOOM_IN
);
1825 stdID(wxID_ZOOM_OUT
);
1826 stdID(wxID_UNDELETE
);
1827 stdID(wxID_REVERT_TO_SAVED
);
1828 stdID(wxID_SYSTEM_MENU
);
1829 stdID(wxID_CLOSE_FRAME
);
1830 stdID(wxID_MOVE_FRAME
);
1831 stdID(wxID_RESIZE_FRAME
);
1832 stdID(wxID_MAXIMIZE_FRAME
);
1833 stdID(wxID_ICONIZE_FRAME
);
1834 stdID(wxID_RESTORE_FRAME
);
1836 stdID(wxID_CONVERT
);
1837 stdID(wxID_EXECUTE
);
1839 stdID(wxID_HARDDISK
);
1845 stdID(wxID_JUMP_TO
);
1846 stdID(wxID_NETWORK
);
1847 stdID(wxID_SELECT_COLOR
);
1848 stdID(wxID_SELECT_FONT
);
1849 stdID(wxID_SORT_ASCENDING
);
1850 stdID(wxID_SORT_DESCENDING
);
1851 stdID(wxID_SPELL_CHECK
);
1852 stdID(wxID_STRIKETHROUGH
);
1861 // --------------- module and globals -----------------------------
1863 // normally we would do the cleanup from wxXmlResourceModule::OnExit() but it
1864 // can happen that some XRC records have been created because of the use of
1865 // XRCID() in event tables, which happens during static objects initialization,
1866 // but then the application initialization failed and so the wx modules were
1867 // neither initialized nor cleaned up -- this static object does the cleanup in
1869 static struct wxXRCStaticCleanup
1871 ~wxXRCStaticCleanup() { CleanXRCID_Records(); }
1874 class wxXmlResourceModule
: public wxModule
1876 DECLARE_DYNAMIC_CLASS(wxXmlResourceModule
)
1878 wxXmlResourceModule() {}
1881 wxXmlResource
::AddSubclassFactory(new wxXmlSubclassFactoryCXX
);
1886 delete wxXmlResource
::Set(NULL
);
1887 if(wxXmlResource
::ms_subclassFactories
)
1889 for ( wxXmlSubclassFactories
::iterator i
= wxXmlResource
::ms_subclassFactories
->begin();
1890 i
!= wxXmlResource
::ms_subclassFactories
->end(); ++i
)
1894 wxDELETE(wxXmlResource
::ms_subclassFactories
);
1896 CleanXRCID_Records();
1900 IMPLEMENT_DYNAMIC_CLASS(wxXmlResourceModule
, wxModule
)
1903 // When wxXml is loaded dynamically after the application is already running
1904 // then the built-in module system won't pick this one up. Add it manually.
1905 void wxXmlInitResourceModule()
1907 wxModule
* module
= new wxXmlResourceModule
;
1909 wxModule
::RegisterModule(module
);