1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xmlres.cpp
3 // Purpose: XRC resources
4 // Author: Vaclav Slavik
6 // Copyright: (c) 2000 Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
19 #include "wx/xrc/xmlres.h"
26 #include "wx/dialog.h"
27 #include "wx/settings.h"
28 #include "wx/bitmap.h"
30 #include "wx/module.h"
31 #include "wx/wxcrtvararg.h"
38 #include "wx/vector.h"
39 #include "wx/wfstream.h"
40 #include "wx/filesys.h"
41 #include "wx/filename.h"
42 #include "wx/tokenzr.h"
43 #include "wx/fontenum.h"
44 #include "wx/fontmap.h"
45 #include "wx/artprov.h"
46 #include "wx/imaglist.h"
48 #include "wx/xml/xml.h"
49 #include "wx/hashset.h"
50 #include "wx/scopedptr.h"
55 // Helper function to get modification time of either a wxFileSystem URI or
56 // just a normal file name, depending on the build.
59 wxDateTime
GetXRCFileModTime(const wxString
& filename
)
63 wxScopedPtr
<wxFSFile
> file(fsys
.OpenFile(filename
));
65 return file
? file
->GetModificationTime() : wxDateTime();
66 #else // wxUSE_FILESYSTEM
67 return wxDateTime(wxFileModificationTime(filename
));
68 #endif // wxUSE_FILESYSTEM
71 #endif // wxUSE_DATETIME
73 } // anonymous namespace
75 // Assign the given value to the specified entry or add a new value with this
77 static void XRCID_Assign(const wxString
& str_id
, int value
);
79 class wxXmlResourceDataRecord
82 // Ctor takes ownership of the document pointer.
83 wxXmlResourceDataRecord(const wxString
& File_
,
86 : File(File_
), Doc(Doc_
)
89 Time
= GetXRCFileModTime(File
);
93 ~wxXmlResourceDataRecord() {delete Doc
;}
101 wxDECLARE_NO_COPY_CLASS(wxXmlResourceDataRecord
);
104 class wxXmlResourceDataRecords
: public wxVector
<wxXmlResourceDataRecord
*>
106 // this is a class so that it can be forward-declared
109 WX_DECLARE_HASH_SET_PTR(int, wxIntegerHash
, wxIntegerEqual
, wxHashSetInt
);
111 class wxIdRange
// Holds data for a particular rangename
114 wxIdRange(const wxXmlNode
* node
,
115 const wxString
& rname
,
116 const wxString
& startno
,
117 const wxString
& rsize
);
119 // Note the existence of an item within the range
120 void NoteItem(const wxXmlNode
* node
, const wxString
& item
);
122 // The manager is telling us that it's finished adding items
123 void Finalise(const wxXmlNode
* node
);
125 wxString
GetName() const { return m_name
; }
126 bool IsFinalised() const { return m_finalised
; }
128 const wxString m_name
;
132 bool m_item_end_found
;
134 wxHashSetInt m_indices
;
136 friend class wxIdRangeManager
;
139 class wxIdRangeManager
143 // Gets the global resources object or creates one if none exists.
144 static wxIdRangeManager
*Get();
146 // Sets the global resources object and returns a pointer to the previous
147 // one (may be NULL).
148 static wxIdRangeManager
*Set(wxIdRangeManager
*res
);
150 // Create a new IDrange from this node
151 void AddRange(const wxXmlNode
* node
);
152 // Tell the IdRange that this item exists, and should be pre-allocated an ID
153 void NotifyRangeOfItem(const wxXmlNode
* node
, const wxString
& item
) const;
154 // Tells all IDranges that they're now complete, and can create their IDs
155 void FinaliseRanges(const wxXmlNode
* node
) const;
156 // Searches for a known IdRange matching 'name', returning its index or -1
157 int Find(const wxString
& rangename
) const;
160 wxIdRange
* FindRangeForItem(const wxXmlNode
* node
,
161 const wxString
& item
,
162 wxString
& value
) const;
163 wxVector
<wxIdRange
*> m_IdRanges
;
166 static wxIdRangeManager
*ms_instance
;
172 // helper used by DoFindResource() and elsewhere: returns true if this is an
173 // object or object_ref node
175 // node must be non-NULL
176 inline bool IsObjectNode(wxXmlNode
*node
)
178 return node
->GetType() == wxXML_ELEMENT_NODE
&&
179 (node
->GetName() == wxS("object") ||
180 node
->GetName() == wxS("object_ref"));
183 // special XML attribute with name of input file, see GetFileNameFromNode()
184 const char *ATTR_INPUT_FILENAME
= "__wx:filename";
186 // helper to get filename corresponding to an XML node
188 GetFileNameFromNode(const wxXmlNode
*node
, const wxXmlResourceDataRecords
& files
)
190 // this loop does two things: it looks for ATTR_INPUT_FILENAME among
191 // parents and if it isn't used, it finds the root of the XML tree 'node'
195 // in some rare cases (specifically, when an <object_ref> is used, see
196 // wxXmlResource::CreateResFromNode() and MergeNodesOver()), we work
197 // with XML nodes that are not rooted in any document from 'files'
198 // (because a new node was created by CreateResFromNode() to merge the
199 // content of <object_ref> and the referenced <object>); in that case,
200 // we hack around the problem by putting the information about input
201 // file into a custom attribute
202 if ( node
->HasAttribute(ATTR_INPUT_FILENAME
) )
203 return node
->GetAttribute(ATTR_INPUT_FILENAME
);
205 if ( !node
->GetParent() )
206 break; // we found the root of this XML tree
208 node
= node
->GetParent();
211 // NB: 'node' now points to the root of XML document
213 for ( wxXmlResourceDataRecords::const_iterator i
= files
.begin();
214 i
!= files
.end(); ++i
)
216 if ( (*i
)->Doc
->GetRoot() == node
)
222 return wxEmptyString
; // not found
225 } // anonymous namespace
228 wxXmlResource
*wxXmlResource::ms_instance
= NULL
;
230 /*static*/ wxXmlResource
*wxXmlResource::Get()
233 ms_instance
= new wxXmlResource
;
237 /*static*/ wxXmlResource
*wxXmlResource::Set(wxXmlResource
*res
)
239 wxXmlResource
*old
= ms_instance
;
244 wxXmlResource::wxXmlResource(int flags
, const wxString
& domain
)
248 m_data
= new wxXmlResourceDataRecords
;
252 wxXmlResource::wxXmlResource(const wxString
& filemask
, int flags
, const wxString
& domain
)
256 m_data
= new wxXmlResourceDataRecords
;
261 wxXmlResource::~wxXmlResource()
265 for ( wxXmlResourceDataRecords::iterator i
= m_data
->begin();
266 i
!= m_data
->end(); ++i
)
273 void wxXmlResource::SetDomain(const wxString
& domain
)
280 wxString
wxXmlResource::ConvertFileNameToURL(const wxString
& filename
)
282 wxString
fnd(filename
);
284 // NB: as Load() and Unload() accept both filenames and URLs (should
285 // probably be changed to filenames only, but embedded resources
286 // currently rely on its ability to handle URLs - FIXME) we need to
287 // determine whether found name is filename and not URL and this is the
288 // fastest/simplest way to do it
289 if (wxFileName::FileExists(fnd
))
291 // Make the name absolute filename, because the app may
292 // change working directory later:
297 fnd
= fn
.GetFullPath();
300 fnd
= wxFileSystem::FileNameToURL(fnd
);
310 bool wxXmlResource::IsArchive(const wxString
& filename
)
312 const wxString fnd
= filename
.Lower();
314 return fnd
.Matches(wxT("*.zip")) || fnd
.Matches(wxT("*.xrs"));
317 #endif // wxUSE_FILESYSTEM
319 bool wxXmlResource::LoadFile(const wxFileName
& file
)
322 return Load(wxFileSystem::FileNameToURL(file
));
324 return Load(file
.GetFullPath());
328 bool wxXmlResource::LoadAllFiles(const wxString
& dirname
)
333 wxDir::GetAllFiles(dirname
, &files
, "*.xrc");
335 for ( wxArrayString::const_iterator i
= files
.begin(); i
!= files
.end(); ++i
)
344 bool wxXmlResource::Load(const wxString
& filemask_
)
346 wxString filemask
= ConvertFileNameToURL(filemask_
);
352 # define wxXmlFindFirst fsys.FindFirst(filemask, wxFILE)
353 # define wxXmlFindNext fsys.FindNext()
355 # define wxXmlFindFirst wxFindFirstFile(filemask, wxFILE)
356 # define wxXmlFindNext wxFindNextFile()
358 wxString fnd
= wxXmlFindFirst
;
361 wxLogError(_("Cannot load resources from '%s'."), filemask
);
368 if ( IsArchive(fnd
) )
370 if ( !Load(fnd
+ wxT("#zip:*.xrc")) )
373 else // a single resource URL
374 #endif // wxUSE_FILESYSTEM
376 wxXmlDocument
* const doc
= DoLoadFile(fnd
);
380 Data().push_back(new wxXmlResourceDataRecord(fnd
, doc
));
385 # undef wxXmlFindFirst
386 # undef wxXmlFindNext
391 bool wxXmlResource::Unload(const wxString
& filename
)
393 wxASSERT_MSG( !wxIsWild(filename
),
394 wxT("wildcards not supported by wxXmlResource::Unload()") );
396 wxString fnd
= ConvertFileNameToURL(filename
);
398 const bool isArchive
= IsArchive(fnd
);
401 #endif // wxUSE_FILESYSTEM
403 bool unloaded
= false;
404 for ( wxXmlResourceDataRecords::iterator i
= Data().begin();
405 i
!= Data().end(); ++i
)
410 if ( (*i
)->File
.StartsWith(fnd
) )
412 // don't break from the loop, we can have other matching files
414 else // a single resource URL
415 #endif // wxUSE_FILESYSTEM
417 if ( (*i
)->File
== fnd
)
423 // no sense in continuing, there is only one file with this URL
433 void wxXmlResource::AddHandler(wxXmlResourceHandler
*handler
)
435 wxXmlResourceHandlerImpl
*impl
= new wxXmlResourceHandlerImpl(handler
);
436 handler
->SetImpl(impl
);
437 m_handlers
.push_back(handler
);
438 handler
->SetParentResource(this);
441 void wxXmlResource::InsertHandler(wxXmlResourceHandler
*handler
)
443 wxXmlResourceHandlerImpl
*impl
= new wxXmlResourceHandlerImpl(handler
);
444 handler
->SetImpl(impl
);
445 m_handlers
.insert(m_handlers
.begin(), handler
);
446 handler
->SetParentResource(this);
451 void wxXmlResource::ClearHandlers()
453 for ( wxVector
<wxXmlResourceHandler
*>::iterator i
= m_handlers
.begin();
454 i
!= m_handlers
.end(); ++i
)
460 wxMenu
*wxXmlResource::LoadMenu(const wxString
& name
)
462 return (wxMenu
*)CreateResFromNode(FindResource(name
, wxT("wxMenu")), NULL
, NULL
);
467 wxMenuBar
*wxXmlResource::LoadMenuBar(wxWindow
*parent
, const wxString
& name
)
469 return (wxMenuBar
*)CreateResFromNode(FindResource(name
, wxT("wxMenuBar")), parent
, NULL
);
475 wxToolBar
*wxXmlResource::LoadToolBar(wxWindow
*parent
, const wxString
& name
)
477 return (wxToolBar
*)CreateResFromNode(FindResource(name
, wxT("wxToolBar")), parent
, NULL
);
482 wxDialog
*wxXmlResource::LoadDialog(wxWindow
*parent
, const wxString
& name
)
484 return (wxDialog
*)CreateResFromNode(FindResource(name
, wxT("wxDialog")), parent
, NULL
);
487 bool wxXmlResource::LoadDialog(wxDialog
*dlg
, wxWindow
*parent
, const wxString
& name
)
489 return CreateResFromNode(FindResource(name
, wxT("wxDialog")), parent
, dlg
) != NULL
;
494 wxPanel
*wxXmlResource::LoadPanel(wxWindow
*parent
, const wxString
& name
)
496 return (wxPanel
*)CreateResFromNode(FindResource(name
, wxT("wxPanel")), parent
, NULL
);
499 bool wxXmlResource::LoadPanel(wxPanel
*panel
, wxWindow
*parent
, const wxString
& name
)
501 return CreateResFromNode(FindResource(name
, wxT("wxPanel")), parent
, panel
) != NULL
;
504 wxFrame
*wxXmlResource::LoadFrame(wxWindow
* parent
, const wxString
& name
)
506 return (wxFrame
*)CreateResFromNode(FindResource(name
, wxT("wxFrame")), parent
, NULL
);
509 bool wxXmlResource::LoadFrame(wxFrame
* frame
, wxWindow
*parent
, const wxString
& name
)
511 return CreateResFromNode(FindResource(name
, wxT("wxFrame")), parent
, frame
) != NULL
;
514 wxBitmap
wxXmlResource::LoadBitmap(const wxString
& name
)
516 wxBitmap
*bmp
= (wxBitmap
*)CreateResFromNode(
517 FindResource(name
, wxT("wxBitmap")), NULL
, NULL
);
520 if (bmp
) { rt
= *bmp
; delete bmp
; }
524 wxIcon
wxXmlResource::LoadIcon(const wxString
& name
)
526 wxIcon
*icon
= (wxIcon
*)CreateResFromNode(
527 FindResource(name
, wxT("wxIcon")), NULL
, NULL
);
530 if (icon
) { rt
= *icon
; delete icon
; }
536 wxXmlResource::DoLoadObject(wxWindow
*parent
,
537 const wxString
& name
,
538 const wxString
& classname
,
541 wxXmlNode
* const node
= FindResource(name
, classname
, recursive
);
543 return node
? DoCreateResFromNode(*node
, parent
, NULL
) : NULL
;
547 wxXmlResource::DoLoadObject(wxObject
*instance
,
549 const wxString
& name
,
550 const wxString
& classname
,
553 wxXmlNode
* const node
= FindResource(name
, classname
, recursive
);
555 return node
&& DoCreateResFromNode(*node
, parent
, instance
) != NULL
;
559 bool wxXmlResource::AttachUnknownControl(const wxString
& name
,
560 wxWindow
*control
, wxWindow
*parent
)
563 parent
= control
->GetParent();
564 wxWindow
*container
= parent
->FindWindow(name
+ wxT("_container"));
567 wxLogError("Cannot find container for unknown control '%s'.", name
);
570 return control
->Reparent(container
);
574 static void ProcessPlatformProperty(wxXmlNode
*node
)
579 wxXmlNode
*c
= node
->GetChildren();
583 if (!c
->GetAttribute(wxT("platform"), &s
))
587 wxStringTokenizer
tkn(s
, wxT(" |"));
589 while (tkn
.HasMoreTokens())
591 s
= tkn
.GetNextToken();
593 if (s
== wxT("win")) isok
= true;
595 #if defined(__MAC__) || defined(__APPLE__)
596 if (s
== wxT("mac")) isok
= true;
597 #elif defined(__UNIX__)
598 if (s
== wxT("unix")) isok
= true;
601 if (s
== wxT("os2")) isok
= true;
611 ProcessPlatformProperty(c
);
616 wxXmlNode
*c2
= c
->GetNext();
617 node
->RemoveChild(c
);
624 static void PreprocessForIdRanges(wxXmlNode
*rootnode
)
626 // First go through the top level, looking for the names of ID ranges
627 // as processing items is a lot easier if names are already known
628 wxXmlNode
*c
= rootnode
->GetChildren();
631 if (c
->GetName() == wxT("ids-range"))
632 wxIdRangeManager::Get()->AddRange(c
);
636 // Next, examine every 'name' for the '[' that denotes an ID in a range
637 c
= rootnode
->GetChildren();
640 wxString name
= c
->GetAttribute(wxT("name"));
641 if (name
.find('[') != wxString::npos
)
642 wxIdRangeManager::Get()->NotifyRangeOfItem(rootnode
, name
);
644 // Do any children by recursion, then proceed to the next sibling
645 PreprocessForIdRanges(c
);
650 bool wxXmlResource::UpdateResources()
654 for ( wxXmlResourceDataRecords::iterator i
= Data().begin();
655 i
!= Data().end(); ++i
)
657 wxXmlResourceDataRecord
* const rec
= *i
;
659 // Check if we need to reload this one.
661 // We never do it if this flag is specified.
662 if ( m_flags
& wxXRC_NO_RELOADING
)
665 // Otherwise check its modification time if we can.
667 const wxDateTime lastModTime
= GetXRCFileModTime(rec
->File
);
669 if ( lastModTime
.IsValid() && lastModTime
<= rec
->Time
)
670 #else // !wxUSE_DATETIME
671 // Never reload the file contents: we can't know whether it changed or
672 // not in this build configuration and it would be unexpected and
673 // counter-productive to get a performance hit (due to constant
674 // reloading of XRC files) in a minimal wx build which is presumably
675 // used because of resource constraints of the current platform.
676 #endif // wxUSE_DATETIME/!wxUSE_DATETIME
678 // No need to reload, the file wasn't modified since we did it
683 wxXmlDocument
* const doc
= DoLoadFile(rec
->File
);
686 // Notice that we keep the old XML document: it seems better to
687 // preserve it instead of throwing it away if we have nothing to
693 // Replace the old resource contents with the new one.
697 // And, now that we loaded it successfully, update the last load time.
699 rec
->Time
= lastModTime
.IsValid() ? lastModTime
: wxDateTime::Now();
700 #endif // wxUSE_DATETIME
706 wxXmlDocument
*wxXmlResource::DoLoadFile(const wxString
& filename
)
708 wxLogTrace(wxT("xrc"), wxT("opening file '%s'"), filename
);
710 wxInputStream
*stream
= NULL
;
714 wxScopedPtr
<wxFSFile
> file(fsys
.OpenFile(filename
));
717 // Notice that we don't have ownership of the stream in this case, it
718 // remains owned by wxFSFile.
719 stream
= file
->GetStream();
721 #else // !wxUSE_FILESYSTEM
722 wxFileInputStream
fstream(filename
);
724 #endif // wxUSE_FILESYSTEM/!wxUSE_FILESYSTEM
726 if ( !stream
|| !stream
->IsOk() )
728 wxLogError(_("Cannot open resources file '%s'."), filename
);
732 wxString
encoding(wxT("UTF-8"));
733 #if !wxUSE_UNICODE && wxUSE_INTL
734 if ( (GetFlags() & wxXRC_USE_LOCALE
) == 0 )
736 // In case we are not using wxLocale to translate strings, convert the
737 // strings GUI's charset. This must not be done when wxXRC_USE_LOCALE
738 // is on, because it could break wxGetTranslation lookup.
739 encoding
= wxLocale::GetSystemEncodingName();
743 wxScopedPtr
<wxXmlDocument
> doc(new wxXmlDocument
);
744 if (!doc
->Load(*stream
, encoding
))
746 wxLogError(_("Cannot load resources from file '%s'."), filename
);
750 wxXmlNode
* const root
= doc
->GetRoot();
751 if (root
->GetName() != wxT("resource"))
756 "invalid XRC resource, doesn't have root node <resource>"
763 wxString verstr
= root
->GetAttribute(wxT("version"), wxT("0.0.0.0"));
764 if (wxSscanf(verstr
, wxT("%i.%i.%i.%i"), &v1
, &v2
, &v3
, &v4
) == 4)
765 version
= v1
*256*256*256+v2
*256*256+v3
*256+v4
;
770 if (m_version
!= version
)
772 wxLogWarning("Resource files must have same version number.");
775 ProcessPlatformProperty(root
);
776 PreprocessForIdRanges(root
);
777 wxIdRangeManager::Get()->FinaliseRanges(root
);
779 return doc
.release();
782 wxXmlNode
*wxXmlResource::DoFindResource(wxXmlNode
*parent
,
783 const wxString
& name
,
784 const wxString
& classname
,
785 bool recursive
) const
789 // first search for match at the top-level nodes (as this is
790 // where the resource is most commonly looked for):
791 for (node
= parent
->GetChildren(); node
; node
= node
->GetNext())
793 if ( IsObjectNode(node
) && node
->GetAttribute(wxS("name")) == name
)
795 // empty class name matches everything
796 if ( classname
.empty() )
799 wxString
cls(node
->GetAttribute(wxS("class")));
801 // object_ref may not have 'class' attribute:
802 if (cls
.empty() && node
->GetName() == wxS("object_ref"))
804 wxString refName
= node
->GetAttribute(wxS("ref"));
808 const wxXmlNode
* const refNode
= GetResourceNode(refName
);
810 cls
= refNode
->GetAttribute(wxS("class"));
813 if ( cls
== classname
)
818 // then recurse in child nodes
821 for (node
= parent
->GetChildren(); node
; node
= node
->GetNext())
823 if ( IsObjectNode(node
) )
825 wxXmlNode
* found
= DoFindResource(node
, name
, classname
, true);
835 wxXmlNode
*wxXmlResource::FindResource(const wxString
& name
,
836 const wxString
& classname
,
841 node
= GetResourceNodeAndLocation(name
, classname
, recursive
, &path
);
850 "XRC resource \"%s\" (class \"%s\") not found",
856 else // node was found
858 // ensure that relative paths work correctly when loading this node
859 // (which should happen as soon as we return as FindResource() result
860 // is always passed to CreateResFromNode())
861 m_curFileSystem
.ChangePathTo(path
);
863 #endif // wxUSE_FILESYSTEM
869 wxXmlResource::GetResourceNodeAndLocation(const wxString
& name
,
870 const wxString
& classname
,
872 wxString
*path
) const
874 // ensure everything is up-to-date: this is needed to support on-demand
875 // reloading of XRC files
876 const_cast<wxXmlResource
*>(this)->UpdateResources();
878 for ( wxXmlResourceDataRecords::const_iterator f
= Data().begin();
879 f
!= Data().end(); ++f
)
881 wxXmlResourceDataRecord
*const rec
= *f
;
882 wxXmlDocument
* const doc
= rec
->Doc
;
883 if ( !doc
|| !doc
->GetRoot() )
887 found
= DoFindResource(doc
->GetRoot(), name
, classname
, recursive
);
900 static void MergeNodesOver(wxXmlNode
& dest
, wxXmlNode
& overwriteWith
,
901 const wxString
& overwriteFilename
)
904 for ( wxXmlAttribute
*attr
= overwriteWith
.GetAttributes();
905 attr
; attr
= attr
->GetNext() )
907 wxXmlAttribute
*dattr
;
908 for (dattr
= dest
.GetAttributes(); dattr
; dattr
= dattr
->GetNext())
911 if ( dattr
->GetName() == attr
->GetName() )
913 dattr
->SetValue(attr
->GetValue());
919 dest
.AddAttribute(attr
->GetName(), attr
->GetValue());
922 // Merge child nodes:
923 for (wxXmlNode
* node
= overwriteWith
.GetChildren(); node
; node
= node
->GetNext())
925 wxString name
= node
->GetAttribute(wxT("name"), wxEmptyString
);
928 for (dnode
= dest
.GetChildren(); dnode
; dnode
= dnode
->GetNext() )
930 if ( dnode
->GetName() == node
->GetName() &&
931 dnode
->GetAttribute(wxT("name"), wxEmptyString
) == name
&&
932 dnode
->GetType() == node
->GetType() )
934 MergeNodesOver(*dnode
, *node
, overwriteFilename
);
941 wxXmlNode
*copyOfNode
= new wxXmlNode(*node
);
942 // remember referenced object's file, see GetFileNameFromNode()
943 copyOfNode
->AddAttribute(ATTR_INPUT_FILENAME
, overwriteFilename
);
945 static const wxChar
*AT_END
= wxT("end");
946 wxString insert_pos
= node
->GetAttribute(wxT("insert_at"), AT_END
);
947 if ( insert_pos
== AT_END
)
949 dest
.AddChild(copyOfNode
);
951 else if ( insert_pos
== wxT("begin") )
953 dest
.InsertChild(copyOfNode
, dest
.GetChildren());
958 if ( dest
.GetType() == wxXML_TEXT_NODE
&& overwriteWith
.GetContent().length() )
959 dest
.SetContent(overwriteWith
.GetContent());
963 wxXmlResource::DoCreateResFromNode(wxXmlNode
& node
,
966 wxXmlResourceHandler
*handlerToUse
)
968 // handling of referenced resource
969 if ( node
.GetName() == wxT("object_ref") )
971 wxString refName
= node
.GetAttribute(wxT("ref"), wxEmptyString
);
972 wxXmlNode
* refNode
= FindResource(refName
, wxEmptyString
, true);
981 "referenced object node with ref=\"%s\" not found",
988 const bool hasOnlyRefAttr
= node
.GetAttributes() != NULL
&&
989 node
.GetAttributes()->GetNext() == NULL
;
991 if ( hasOnlyRefAttr
&& !node
.GetChildren() )
993 // In the typical, simple case, <object_ref> is used to link
994 // to another node and doesn't have any content of its own that
995 // would overwrite linked object's properties. In this case,
996 // we can simply create the resource from linked node.
998 return DoCreateResFromNode(*refNode
, parent
, instance
);
1002 // In the more complicated (but rare) case, <object_ref> has
1003 // subnodes that partially overwrite content of the referenced
1004 // object. In this case, we need to merge both XML trees and
1005 // load the resource from result of the merge.
1007 wxXmlNode
copy(*refNode
);
1008 MergeNodesOver(copy
, node
, GetFileNameFromNode(&node
, Data()));
1010 // remember referenced object's file, see GetFileNameFromNode()
1011 copy
.AddAttribute(ATTR_INPUT_FILENAME
,
1012 GetFileNameFromNode(refNode
, Data()));
1014 return DoCreateResFromNode(copy
, parent
, instance
);
1020 if (handlerToUse
->CanHandle(&node
))
1022 return handlerToUse
->CreateResource(&node
, parent
, instance
);
1025 else if (node
.GetName() == wxT("object"))
1027 for ( wxVector
<wxXmlResourceHandler
*>::iterator h
= m_handlers
.begin();
1028 h
!= m_handlers
.end(); ++h
)
1030 wxXmlResourceHandler
*handler
= *h
;
1031 if (handler
->CanHandle(&node
))
1032 return handler
->CreateResource(&node
, parent
, instance
);
1041 "no handler found for XML node \"%s\" (class \"%s\")",
1043 node
.GetAttribute("class", wxEmptyString
)
1049 wxIdRange::wxIdRange(const wxXmlNode
* node
,
1050 const wxString
& rname
,
1051 const wxString
& startno
,
1052 const wxString
& rsize
)
1056 m_item_end_found(0),
1060 if ( startno
.ToLong(&l
) )
1068 wxXmlResource::Get()->ReportError
1071 "a negative id-range start parameter was given"
1077 wxXmlResource::Get()->ReportError
1080 "the id-range start parameter was malformed"
1085 if ( rsize
.ToULong(&ul
) )
1091 wxXmlResource::Get()->ReportError
1094 "the id-range size parameter was malformed"
1099 void wxIdRange::NoteItem(const wxXmlNode
* node
, const wxString
& item
)
1101 // Nothing gets added here, but the existence of each item is noted
1102 // thus getting an accurate count. 'item' will be either an integer e.g.
1103 // [0] [123]: will eventually create an XRCID as start+integer or [start]
1104 // or [end] which are synonyms for [0] or [range_size-1] respectively.
1105 wxString
content(item
.Mid(1, item
.length()-2));
1107 // Check that basename+item wasn't foo[]
1108 if (content
.empty())
1110 wxXmlResource::Get()->ReportError(node
, "an empty id-range item found");
1114 if (content
=="start")
1116 // "start" means [0], so store that in the set
1117 if (m_indices
.count(0) == 0)
1119 m_indices
.insert(0);
1123 wxXmlResource::Get()->ReportError
1126 "duplicate id-range item found"
1130 else if (content
=="end")
1132 // We can't yet be certain which XRCID this will be equivalent to, so
1133 // just note that there's an item with this name, in case we need to
1134 // inc the range size
1135 m_item_end_found
= true;
1139 // Anything else will be an integer, or rubbish
1141 if ( content
.ToULong(&l
) )
1143 if (m_indices
.count(l
) == 0)
1145 m_indices
.insert(l
);
1146 // Check that this item wouldn't fall outside the current range
1155 wxXmlResource::Get()->ReportError
1158 "duplicate id-range item found"
1165 wxXmlResource::Get()->ReportError
1168 "an id-range item had a malformed index"
1174 void wxIdRange::Finalise(const wxXmlNode
* node
)
1176 wxCHECK_RET( !IsFinalised(),
1177 "Trying to finalise an already-finalised range" );
1179 // Now we know about all the items, we can get an accurate range size
1180 // Expand any requested range-size if there were more items than would fit
1181 m_size
= wxMax(m_size
, m_indices
.size());
1183 // If an item is explicitly called foo[end], ensure it won't clash with
1185 if ( m_item_end_found
&& m_indices
.count(m_size
-1) )
1189 // This will happen if someone creates a range but no items in this xrc
1190 // file Report the error and abort, but don't finalise, in case items
1192 wxXmlResource::Get()->ReportError
1195 "trying to create an empty id-range"
1202 // This is the usual case, where the user didn't specify a start ID
1203 // So get the range using NewControlId().
1205 // NB: negative numbers, but NewControlId already returns the most
1207 m_start
= wxWindow::NewControlId(m_size
);
1208 wxCHECK_RET( m_start
!= wxID_NONE
,
1209 "insufficient IDs available to create range" );
1210 m_end
= m_start
+ m_size
- 1;
1214 // The user already specified a start value, which must be positive
1215 m_end
= m_start
+ m_size
- 1;
1218 // Create the XRCIDs
1219 for (int i
=m_start
; i
<= m_end
; ++i
)
1221 // Ensure that we overwrite any existing value as otherwise
1222 // wxXmlResource::Unload() followed by Load() wouldn't work correctly.
1223 XRCID_Assign(m_name
+ wxString::Format("[%i]", i
-m_start
), i
);
1225 wxLogTrace("xrcrange",
1226 "integer = %i %s now returns %i",
1228 m_name
+ wxString::Format("[%i]", i
-m_start
),
1229 XRCID((m_name
+ wxString::Format("[%i]", i
-m_start
)).mb_str()));
1231 // and these special ones
1232 XRCID_Assign(m_name
+ "[start]", m_start
);
1233 XRCID_Assign(m_name
+ "[end]", m_end
);
1234 wxLogTrace("xrcrange","%s[start] = %i %s[end] = %i",
1235 m_name
.mb_str(),XRCID(wxString(m_name
+"[start]").mb_str()),
1236 m_name
.mb_str(),XRCID(wxString(m_name
+"[end]").mb_str()));
1241 wxIdRangeManager
*wxIdRangeManager::ms_instance
= NULL
;
1243 /*static*/ wxIdRangeManager
*wxIdRangeManager::Get()
1246 ms_instance
= new wxIdRangeManager
;
1250 /*static*/ wxIdRangeManager
*wxIdRangeManager::Set(wxIdRangeManager
*res
)
1252 wxIdRangeManager
*old
= ms_instance
;
1257 wxIdRangeManager::~wxIdRangeManager()
1259 for ( wxVector
<wxIdRange
*>::iterator i
= m_IdRanges
.begin();
1260 i
!= m_IdRanges
.end(); ++i
)
1269 void wxIdRangeManager::AddRange(const wxXmlNode
* node
)
1271 wxString name
= node
->GetAttribute("name");
1272 wxString start
= node
->GetAttribute("start", "0");
1273 wxString size
= node
->GetAttribute("size", "0");
1276 wxXmlResource::Get()->ReportError
1279 "xrc file contains an id-range without a name"
1284 int index
= Find(name
);
1285 if (index
== wxNOT_FOUND
)
1287 wxLogTrace("xrcrange",
1288 "Adding ID range, name=%s start=%s size=%s",
1291 m_IdRanges
.push_back(new wxIdRange(node
, name
, start
, size
));
1295 // There was already a range with this name. Let's hope this is
1296 // from an Unload()/(re)Load(), not an unintentional duplication
1297 wxLogTrace("xrcrange",
1298 "Replacing ID range, name=%s start=%s size=%s",
1301 wxIdRange
* oldrange
= m_IdRanges
.at(index
);
1302 m_IdRanges
.at(index
) = new wxIdRange(node
, name
, start
, size
);
1308 wxIdRangeManager::FindRangeForItem(const wxXmlNode
* node
,
1309 const wxString
& item
,
1310 wxString
& value
) const
1312 wxString basename
= item
.BeforeFirst('[');
1313 wxCHECK_MSG( !basename
.empty(), NULL
,
1314 "an id-range item without a range name" );
1316 int index
= Find(basename
);
1317 if (index
== wxNOT_FOUND
)
1319 // Don't assert just because we've found an unexpected foo[123]
1320 // Someone might just want such a name, nothing to do with ranges
1324 value
= item
.Mid(basename
.Len());
1325 if (value
.at(value
.length()-1)==']')
1327 return m_IdRanges
.at(index
);
1329 wxXmlResource::Get()->ReportError(node
, "a malformed id-range item");
1334 wxIdRangeManager::NotifyRangeOfItem(const wxXmlNode
* node
,
1335 const wxString
& item
) const
1338 wxIdRange
* range
= FindRangeForItem(node
, item
, value
);
1340 range
->NoteItem(node
, value
);
1343 int wxIdRangeManager::Find(const wxString
& rangename
) const
1345 for ( int i
=0; i
< (int)m_IdRanges
.size(); ++i
)
1347 if (m_IdRanges
.at(i
)->GetName() == rangename
)
1354 void wxIdRangeManager::FinaliseRanges(const wxXmlNode
* node
) const
1356 for ( wxVector
<wxIdRange
*>::const_iterator i
= m_IdRanges
.begin();
1357 i
!= m_IdRanges
.end(); ++i
)
1359 // Check if this range has already been finalised. Quite possible,
1360 // as FinaliseRanges() gets called for each .xrc file loaded
1361 if (!(*i
)->IsFinalised())
1363 wxLogTrace("xrcrange", "Finalising ID range %s", (*i
)->GetName());
1364 (*i
)->Finalise(node
);
1370 class wxXmlSubclassFactories
: public wxVector
<wxXmlSubclassFactory
*>
1372 // this is a class so that it can be forward-declared
1375 wxXmlSubclassFactories
*wxXmlResource::ms_subclassFactories
= NULL
;
1377 /*static*/ void wxXmlResource::AddSubclassFactory(wxXmlSubclassFactory
*factory
)
1379 if (!ms_subclassFactories
)
1381 ms_subclassFactories
= new wxXmlSubclassFactories
;
1383 ms_subclassFactories
->push_back(factory
);
1386 class wxXmlSubclassFactoryCXX
: public wxXmlSubclassFactory
1389 ~wxXmlSubclassFactoryCXX() {}
1391 wxObject
*Create(const wxString
& className
)
1393 wxClassInfo
* classInfo
= wxClassInfo::FindClass(className
);
1396 return classInfo
->CreateObject();
1405 wxXmlResourceHandlerImpl::wxXmlResourceHandlerImpl(wxXmlResourceHandler
*handler
)
1406 :wxXmlResourceHandlerImplBase(handler
)
1410 wxObject
*wxXmlResourceHandlerImpl::CreateResFromNode(wxXmlNode
*node
,
1411 wxObject
*parent
, wxObject
*instance
)
1413 return m_handler
->m_resource
->CreateResFromNode(node
, parent
, instance
);
1416 #if wxUSE_FILESYSTEM
1417 wxFileSystem
& wxXmlResourceHandlerImpl::GetCurFileSystem()
1419 return m_handler
->m_resource
->GetCurFileSystem();
1424 wxObject
*wxXmlResourceHandlerImpl::CreateResource(wxXmlNode
*node
, wxObject
*parent
, wxObject
*instance
)
1426 wxXmlNode
*myNode
= m_handler
->m_node
;
1427 wxString myClass
= m_handler
->m_class
;
1428 wxObject
*myParent
= m_handler
->m_parent
, *myInstance
= m_handler
->m_instance
;
1429 wxWindow
*myParentAW
= m_handler
->m_parentAsWindow
;
1431 m_handler
->m_instance
= instance
;
1432 if (!m_handler
->m_instance
&& node
->HasAttribute(wxT("subclass")) &&
1433 !(m_handler
->m_resource
->GetFlags() & wxXRC_NO_SUBCLASSING
))
1435 wxString subclass
= node
->GetAttribute(wxT("subclass"), wxEmptyString
);
1436 if (!subclass
.empty())
1438 for (wxXmlSubclassFactories::iterator i
= wxXmlResource::ms_subclassFactories
->begin();
1439 i
!= wxXmlResource::ms_subclassFactories
->end(); ++i
)
1441 m_handler
->m_instance
= (*i
)->Create(subclass
);
1442 if (m_handler
->m_instance
)
1446 if (!m_handler
->m_instance
)
1448 wxString name
= node
->GetAttribute(wxT("name"), wxEmptyString
);
1454 "subclass \"%s\" not found for resource \"%s\", not subclassing",
1462 m_handler
->m_node
= node
;
1463 m_handler
->m_class
= node
->GetAttribute(wxT("class"), wxEmptyString
);
1464 m_handler
->m_parent
= parent
;
1465 m_handler
->m_parentAsWindow
= wxDynamicCast(m_handler
->m_parent
, wxWindow
);
1467 wxObject
*returned
= GetHandler()->DoCreateResource();
1469 m_handler
->m_node
= myNode
;
1470 m_handler
->m_class
= myClass
;
1471 m_handler
->m_parent
= myParent
; m_handler
->m_parentAsWindow
= myParentAW
;
1472 m_handler
->m_instance
= myInstance
;
1477 bool wxXmlResourceHandlerImpl::HasParam(const wxString
& param
)
1479 return (GetParamNode(param
) != NULL
);
1483 int wxXmlResourceHandlerImpl::GetStyle(const wxString
& param
, int defaults
)
1485 wxString s
= GetParamValue(param
);
1487 if (!s
) return defaults
;
1489 wxStringTokenizer
tkn(s
, wxT("| \t\n"), wxTOKEN_STRTOK
);
1493 while (tkn
.HasMoreTokens())
1495 fl
= tkn
.GetNextToken();
1496 index
= m_handler
->m_styleNames
.Index(fl
);
1497 if (index
!= wxNOT_FOUND
)
1499 style
|= m_handler
->m_styleValues
[index
];
1506 wxString::Format("unknown style flag \"%s\"", fl
)
1515 wxString
wxXmlResourceHandlerImpl::GetText(const wxString
& param
, bool translate
)
1517 wxXmlNode
*parNode
= GetParamNode(param
);
1518 wxString
str1(GetNodeContent(parNode
));
1521 // "\\" wasn't translated to "\" prior to 2.5.3.0:
1522 const bool escapeBackslash
= (m_handler
->m_resource
->CompareVersion(2,5,3,0) >= 0);
1524 // VS: First version of XRC resources used $ instead of & (which is
1525 // illegal in XML), but later I realized that '_' fits this purpose
1526 // much better (because &File means "File with F underlined").
1527 const wxChar amp_char
= (m_handler
->m_resource
->CompareVersion(2,3,0,1) < 0)
1530 for ( wxString::const_iterator dt
= str1
.begin(); dt
!= str1
.end(); ++dt
)
1532 // Remap amp_char to &, map double amp_char to amp_char (for things
1533 // like "&File..." -- this is illegal in XML, so we use "_File..."):
1534 if ( *dt
== amp_char
)
1536 if ( dt
+1 == str1
.end() || *(++dt
) == amp_char
)
1539 str2
<< wxT('&') << *dt
;
1541 // Remap \n to CR, \r to LF, \t to TAB, \\ to \:
1542 else if ( *dt
== wxT('\\') )
1544 switch ( (*(++dt
)).GetValue() )
1559 // "\\" wasn't translated to "\" prior to 2.5.3.0:
1560 if ( escapeBackslash
)
1565 // else fall-through to default: branch below
1568 str2
<< wxT('\\') << *dt
;
1578 if (m_handler
->m_resource
->GetFlags() & wxXRC_USE_LOCALE
)
1580 if (translate
&& parNode
&&
1581 parNode
->GetAttribute(wxT("translate"), wxEmptyString
) != wxT("0"))
1583 return wxGetTranslation(str2
, m_handler
->m_resource
->GetDomain());
1590 // The string is internally stored as UTF-8, we have to convert
1591 // it into system's default encoding so that it can be displayed:
1592 return wxString(str2
.wc_str(wxConvUTF8
), wxConvLocal
);
1597 // If wxXRC_USE_LOCALE is not set, then the string is already in
1598 // system's default encoding in ANSI build, so we don't have to
1599 // do anything special here.
1605 long wxXmlResourceHandlerImpl::GetLong(const wxString
& param
, long defaultv
)
1607 long value
= defaultv
;
1608 wxString str1
= GetParamValue(param
);
1612 if (!str1
.ToLong(&value
))
1617 wxString::Format("invalid long specification \"%s\"", str1
)
1625 float wxXmlResourceHandlerImpl::GetFloat(const wxString
& param
, float defaultv
)
1627 wxString str
= GetParamValue(param
);
1629 // strings in XRC always use C locale so make sure to use the
1630 // locale-independent wxString::ToCDouble() and not ToDouble() which uses
1631 // the current locale with a potentially different decimal point character
1632 double value
= defaultv
;
1635 if (!str
.ToCDouble(&value
))
1640 wxString::Format("invalid float specification \"%s\"", str
)
1645 return wx_truncate_cast(float, value
);
1649 int wxXmlResourceHandlerImpl::GetID()
1651 return wxXmlResource::GetXRCID(GetName());
1656 wxString
wxXmlResourceHandlerImpl::GetName()
1658 return m_handler
->m_node
->GetAttribute(wxT("name"), wxT("-1"));
1663 bool wxXmlResourceHandlerImpl::GetBoolAttr(const wxString
& attr
, bool defaultv
)
1666 return m_handler
->m_node
->GetAttribute(attr
, &v
) ? v
== '1' : defaultv
;
1669 bool wxXmlResourceHandlerImpl::GetBool(const wxString
& param
, bool defaultv
)
1671 const wxString v
= GetParamValue(param
);
1673 return v
.empty() ? defaultv
: (v
== '1');
1677 static wxColour
GetSystemColour(const wxString
& name
)
1681 #define SYSCLR(clr) \
1682 if (name == wxT(#clr)) return wxSystemSettings::GetColour(clr);
1683 SYSCLR(wxSYS_COLOUR_SCROLLBAR
)
1684 SYSCLR(wxSYS_COLOUR_BACKGROUND
)
1685 SYSCLR(wxSYS_COLOUR_DESKTOP
)
1686 SYSCLR(wxSYS_COLOUR_ACTIVECAPTION
)
1687 SYSCLR(wxSYS_COLOUR_INACTIVECAPTION
)
1688 SYSCLR(wxSYS_COLOUR_MENU
)
1689 SYSCLR(wxSYS_COLOUR_WINDOW
)
1690 SYSCLR(wxSYS_COLOUR_WINDOWFRAME
)
1691 SYSCLR(wxSYS_COLOUR_MENUTEXT
)
1692 SYSCLR(wxSYS_COLOUR_WINDOWTEXT
)
1693 SYSCLR(wxSYS_COLOUR_CAPTIONTEXT
)
1694 SYSCLR(wxSYS_COLOUR_ACTIVEBORDER
)
1695 SYSCLR(wxSYS_COLOUR_INACTIVEBORDER
)
1696 SYSCLR(wxSYS_COLOUR_APPWORKSPACE
)
1697 SYSCLR(wxSYS_COLOUR_HIGHLIGHT
)
1698 SYSCLR(wxSYS_COLOUR_HIGHLIGHTTEXT
)
1699 SYSCLR(wxSYS_COLOUR_BTNFACE
)
1700 SYSCLR(wxSYS_COLOUR_3DFACE
)
1701 SYSCLR(wxSYS_COLOUR_BTNSHADOW
)
1702 SYSCLR(wxSYS_COLOUR_3DSHADOW
)
1703 SYSCLR(wxSYS_COLOUR_GRAYTEXT
)
1704 SYSCLR(wxSYS_COLOUR_BTNTEXT
)
1705 SYSCLR(wxSYS_COLOUR_INACTIVECAPTIONTEXT
)
1706 SYSCLR(wxSYS_COLOUR_BTNHIGHLIGHT
)
1707 SYSCLR(wxSYS_COLOUR_BTNHILIGHT
)
1708 SYSCLR(wxSYS_COLOUR_3DHIGHLIGHT
)
1709 SYSCLR(wxSYS_COLOUR_3DHILIGHT
)
1710 SYSCLR(wxSYS_COLOUR_3DDKSHADOW
)
1711 SYSCLR(wxSYS_COLOUR_3DLIGHT
)
1712 SYSCLR(wxSYS_COLOUR_INFOTEXT
)
1713 SYSCLR(wxSYS_COLOUR_INFOBK
)
1714 SYSCLR(wxSYS_COLOUR_LISTBOX
)
1715 SYSCLR(wxSYS_COLOUR_HOTLIGHT
)
1716 SYSCLR(wxSYS_COLOUR_GRADIENTACTIVECAPTION
)
1717 SYSCLR(wxSYS_COLOUR_GRADIENTINACTIVECAPTION
)
1718 SYSCLR(wxSYS_COLOUR_MENUHILIGHT
)
1719 SYSCLR(wxSYS_COLOUR_MENUBAR
)
1723 return wxNullColour
;
1726 wxColour
wxXmlResourceHandlerImpl::GetColour(const wxString
& param
, const wxColour
& defaultv
)
1728 wxString v
= GetParamValue(param
);
1735 // wxString -> wxColour conversion
1738 // the colour doesn't use #RRGGBB format, check if it is symbolic
1740 clr
= GetSystemColour(v
);
1747 wxString::Format("incorrect colour specification \"%s\"", v
)
1749 return wxNullColour
;
1758 // if 'param' has stock_id/stock_client, extracts them and returns true
1759 bool GetStockArtAttrs(const wxXmlNode
*paramNode
,
1760 const wxString
& defaultArtClient
,
1761 wxString
& art_id
, wxString
& art_client
)
1765 art_id
= paramNode
->GetAttribute("stock_id", "");
1767 if ( !art_id
.empty() )
1769 art_id
= wxART_MAKE_ART_ID_FROM_STR(art_id
);
1771 art_client
= paramNode
->GetAttribute("stock_client", "");
1772 if ( art_client
.empty() )
1773 art_client
= defaultArtClient
;
1775 art_client
= wxART_MAKE_CLIENT_ID_FROM_STR(art_client
);
1784 } // anonymous namespace
1786 wxBitmap
wxXmlResourceHandlerImpl::GetBitmap(const wxString
& param
,
1787 const wxArtClient
& defaultArtClient
,
1790 // it used to be possible to pass an empty string here to indicate that the
1791 // bitmap name should be read from this node itself but this is not
1792 // supported any more because GetBitmap(m_node) can be used directly
1794 wxASSERT_MSG( !param
.empty(), "bitmap parameter name can't be empty" );
1796 const wxXmlNode
* const node
= GetParamNode(param
);
1800 // this is not an error as bitmap parameter could be optional
1801 return wxNullBitmap
;
1804 return GetBitmap(node
, defaultArtClient
, size
);
1807 wxBitmap
wxXmlResourceHandlerImpl::GetBitmap(const wxXmlNode
* node
,
1808 const wxArtClient
& defaultArtClient
,
1811 wxCHECK_MSG( node
, wxNullBitmap
, "bitmap node can't be NULL" );
1813 /* If the bitmap is specified as stock item, query wxArtProvider for it: */
1814 wxString art_id
, art_client
;
1815 if ( GetStockArtAttrs(node
, defaultArtClient
,
1816 art_id
, art_client
) )
1818 wxBitmap
stockArt(wxArtProvider::GetBitmap(art_id
, art_client
, size
));
1819 if ( stockArt
.IsOk() )
1823 /* ...or load the bitmap from file: */
1824 wxString name
= GetParamValue(node
);
1825 if (name
.empty()) return wxNullBitmap
;
1826 #if wxUSE_FILESYSTEM
1827 wxFSFile
*fsfile
= GetCurFileSystem().OpenFile(name
, wxFS_READ
| wxFS_SEEKABLE
);
1833 wxString::Format("cannot open bitmap resource \"%s\"", name
)
1835 return wxNullBitmap
;
1837 wxImage
img(*(fsfile
->GetStream()));
1848 wxString::Format("cannot create bitmap from \"%s\"", name
)
1850 return wxNullBitmap
;
1852 if (!(size
== wxDefaultSize
)) img
.Rescale(size
.x
, size
.y
);
1853 return wxBitmap(img
);
1857 wxIcon
wxXmlResourceHandlerImpl::GetIcon(const wxString
& param
,
1858 const wxArtClient
& defaultArtClient
,
1861 // see comment in GetBitmap(wxString) overload
1862 wxASSERT_MSG( !param
.empty(), "icon parameter name can't be empty" );
1864 const wxXmlNode
* const node
= GetParamNode(param
);
1868 // this is not an error as icon parameter could be optional
1872 return GetIcon(node
, defaultArtClient
, size
);
1875 wxIcon
wxXmlResourceHandlerImpl::GetIcon(const wxXmlNode
* node
,
1876 const wxArtClient
& defaultArtClient
,
1880 icon
.CopyFromBitmap(GetBitmap(node
, defaultArtClient
, size
));
1885 wxIconBundle
wxXmlResourceHandlerImpl::GetIconBundle(const wxString
& param
,
1886 const wxArtClient
& defaultArtClient
)
1888 wxString art_id
, art_client
;
1889 if ( GetStockArtAttrs(GetParamNode(param
), defaultArtClient
,
1890 art_id
, art_client
) )
1892 wxIconBundle
stockArt(wxArtProvider::GetIconBundle(art_id
, art_client
));
1893 if ( stockArt
.IsOk() )
1897 const wxString name
= GetParamValue(param
);
1899 return wxNullIconBundle
;
1901 #if wxUSE_FILESYSTEM
1902 wxFSFile
*fsfile
= GetCurFileSystem().OpenFile(name
, wxFS_READ
| wxFS_SEEKABLE
);
1903 if ( fsfile
== NULL
)
1908 wxString::Format("cannot open icon resource \"%s\"", name
)
1910 return wxNullIconBundle
;
1913 wxIconBundle
bundle(*(fsfile
->GetStream()));
1916 wxIconBundle
bundle(name
);
1919 if ( !bundle
.IsOk() )
1924 wxString::Format("cannot create icon from \"%s\"", name
)
1926 return wxNullIconBundle
;
1933 wxImageList
*wxXmlResourceHandlerImpl::GetImageList(const wxString
& param
)
1935 wxXmlNode
* const imagelist_node
= GetParamNode(param
);
1936 if ( !imagelist_node
)
1939 wxXmlNode
* const oldnode
= m_handler
->m_node
;
1940 m_handler
->m_node
= imagelist_node
;
1942 // Get the size if we have it, otherwise we will use the size of the first
1944 wxSize size
= GetSize();
1946 // Start adding images, we'll create the image list when adding the first
1948 wxImageList
* imagelist
= NULL
;
1949 wxString parambitmap
= wxT("bitmap");
1950 if ( HasParam(parambitmap
) )
1952 wxXmlNode
*n
= m_handler
->m_node
->GetChildren();
1955 if (n
->GetType() == wxXML_ELEMENT_NODE
&& n
->GetName() == parambitmap
)
1957 wxIcon icon
= GetIcon(n
, wxART_OTHER
, size
);
1960 // We need the real image list size to create it.
1961 if ( size
== wxDefaultSize
)
1962 size
= icon
.GetSize();
1964 // We use the mask by default.
1965 bool mask
= !HasParam(wxS("mask")) || GetBool(wxS("mask"));
1967 imagelist
= new wxImageList(size
.x
, size
.y
, mask
);
1970 // add icon instead of bitmap to keep the bitmap mask
1971 imagelist
->Add(icon
);
1977 m_handler
->m_node
= oldnode
;
1981 wxXmlNode
*wxXmlResourceHandlerImpl::GetParamNode(const wxString
& param
)
1983 wxCHECK_MSG(m_handler
->m_node
, NULL
, wxT("You can't access handler data before it was initialized!"));
1985 wxXmlNode
*n
= m_handler
->m_node
->GetChildren();
1989 if (n
->GetType() == wxXML_ELEMENT_NODE
&& n
->GetName() == param
)
1991 // TODO: check that there are no other properties/parameters with
1992 // the same name and log an error if there are (can't do this
1993 // right now as I'm not sure if it's not going to break code
1994 // using this function in unintentional way (i.e. for
1995 // accessing other things than properties), for example
1996 // wxBitmapComboBoxXmlHandler almost surely does
2004 bool wxXmlResourceHandlerImpl::IsOfClass(wxXmlNode
*node
, const wxString
& classname
) const
2006 return node
->GetAttribute(wxT("class")) == classname
;
2011 wxString
wxXmlResourceHandlerImpl::GetNodeContent(const wxXmlNode
*node
)
2013 const wxXmlNode
*n
= node
;
2014 if (n
== NULL
) return wxEmptyString
;
2015 n
= n
->GetChildren();
2019 if (n
->GetType() == wxXML_TEXT_NODE
||
2020 n
->GetType() == wxXML_CDATA_SECTION_NODE
)
2021 return n
->GetContent();
2024 return wxEmptyString
;
2029 wxString
wxXmlResourceHandlerImpl::GetParamValue(const wxString
& param
)
2032 return GetNodeContent(m_handler
->m_node
);
2034 return GetNodeContent(GetParamNode(param
));
2037 wxString
wxXmlResourceHandlerImpl::GetParamValue(const wxXmlNode
* node
)
2039 return GetNodeContent(node
);
2043 wxSize
wxXmlResourceHandlerImpl::GetSize(const wxString
& param
,
2044 wxWindow
*windowToUse
)
2046 wxString s
= GetParamValue(param
);
2047 if (s
.empty()) s
= wxT("-1,-1");
2051 is_dlg
= s
[s
.length()-1] == wxT('d');
2052 if (is_dlg
) s
.RemoveLast();
2054 if (!s
.BeforeFirst(wxT(',')).ToLong(&sx
) ||
2055 !s
.AfterLast(wxT(',')).ToLong(&sy
))
2060 wxString::Format("cannot parse coordinates value \"%s\"", s
)
2062 return wxDefaultSize
;
2069 return wxDLG_UNIT(windowToUse
, wxSize(sx
, sy
));
2071 else if (m_handler
->m_parentAsWindow
)
2073 return wxDLG_UNIT(m_handler
->m_parentAsWindow
, wxSize(sx
, sy
));
2080 "cannot convert dialog units: dialog unknown"
2082 return wxDefaultSize
;
2086 return wxSize(sx
, sy
);
2091 wxPoint
wxXmlResourceHandlerImpl::GetPosition(const wxString
& param
)
2093 wxSize sz
= GetSize(param
);
2094 return wxPoint(sz
.x
, sz
.y
);
2099 wxCoord
wxXmlResourceHandlerImpl::GetDimension(const wxString
& param
,
2101 wxWindow
*windowToUse
)
2103 wxString s
= GetParamValue(param
);
2104 if (s
.empty()) return defaultv
;
2108 is_dlg
= s
[s
.length()-1] == wxT('d');
2109 if (is_dlg
) s
.RemoveLast();
2116 wxString::Format("cannot parse dimension value \"%s\"", s
)
2125 return wxDLG_UNIT(windowToUse
, wxSize(sx
, 0)).x
;
2127 else if (m_handler
->m_parentAsWindow
)
2129 return wxDLG_UNIT(m_handler
->m_parentAsWindow
, wxSize(sx
, 0)).x
;
2136 "cannot convert dialog units: dialog unknown"
2146 wxXmlResourceHandlerImpl::GetDirection(const wxString
& param
, wxDirection dirDefault
)
2150 const wxString dirstr
= GetParamValue(param
);
2151 if ( dirstr
.empty() )
2153 else if ( dirstr
== "wxLEFT" )
2155 else if ( dirstr
== "wxRIGHT" )
2157 else if ( dirstr
== "wxTOP" )
2159 else if ( dirstr
== "wxBOTTOM" )
2165 GetParamNode(param
),
2168 "Invalid direction \"%s\": must be one of "
2169 "wxLEFT|wxRIGHT|wxTOP|wxBOTTOM.",
2180 // Get system font index using indexname
2181 static wxFont
GetSystemFont(const wxString
& name
)
2185 #define SYSFNT(fnt) \
2186 if (name == wxT(#fnt)) return wxSystemSettings::GetFont(fnt);
2187 SYSFNT(wxSYS_OEM_FIXED_FONT
)
2188 SYSFNT(wxSYS_ANSI_FIXED_FONT
)
2189 SYSFNT(wxSYS_ANSI_VAR_FONT
)
2190 SYSFNT(wxSYS_SYSTEM_FONT
)
2191 SYSFNT(wxSYS_DEVICE_DEFAULT_FONT
)
2192 SYSFNT(wxSYS_SYSTEM_FIXED_FONT
)
2193 SYSFNT(wxSYS_DEFAULT_GUI_FONT
)
2200 wxFont
wxXmlResourceHandlerImpl::GetFont(const wxString
& param
, wxWindow
* parent
)
2202 wxXmlNode
*font_node
= GetParamNode(param
);
2203 if (font_node
== NULL
)
2206 wxString::Format("cannot find font node \"%s\"", param
));
2210 wxXmlNode
*oldnode
= m_handler
->m_node
;
2211 m_handler
->m_node
= font_node
;
2217 bool hasSize
= HasParam(wxT("size"));
2219 isize
= GetLong(wxT("size"), -1);
2222 int istyle
= wxNORMAL
;
2223 bool hasStyle
= HasParam(wxT("style"));
2226 wxString style
= GetParamValue(wxT("style"));
2227 if (style
== wxT("italic"))
2229 else if (style
== wxT("slant"))
2231 else if (style
!= wxT("normal"))
2236 wxString::Format("unknown font style \"%s\"", style
)
2242 int iweight
= wxNORMAL
;
2243 bool hasWeight
= HasParam(wxT("weight"));
2246 wxString weight
= GetParamValue(wxT("weight"));
2247 if (weight
== wxT("bold"))
2249 else if (weight
== wxT("light"))
2251 else if (weight
!= wxT("normal"))
2256 wxString::Format("unknown font weight \"%s\"", weight
)
2262 bool hasUnderlined
= HasParam(wxT("underlined"));
2263 bool underlined
= hasUnderlined
? GetBool(wxT("underlined"), false) : false;
2265 // family and facename
2266 int ifamily
= wxDEFAULT
;
2267 bool hasFamily
= HasParam(wxT("family"));
2270 wxString family
= GetParamValue(wxT("family"));
2271 if (family
== wxT("decorative")) ifamily
= wxDECORATIVE
;
2272 else if (family
== wxT("roman")) ifamily
= wxROMAN
;
2273 else if (family
== wxT("script")) ifamily
= wxSCRIPT
;
2274 else if (family
== wxT("swiss")) ifamily
= wxSWISS
;
2275 else if (family
== wxT("modern")) ifamily
= wxMODERN
;
2276 else if (family
== wxT("teletype")) ifamily
= wxTELETYPE
;
2282 wxString::Format("unknown font family \"%s\"", family
)
2289 bool hasFacename
= HasParam(wxT("face"));
2292 wxString faces
= GetParamValue(wxT("face"));
2293 wxStringTokenizer
tk(faces
, wxT(","));
2295 wxArrayString
facenames(wxFontEnumerator::GetFacenames());
2296 while (tk
.HasMoreTokens())
2298 int index
= facenames
.Index(tk
.GetNextToken(), false);
2299 if (index
!= wxNOT_FOUND
)
2301 facename
= facenames
[index
];
2305 #else // !wxUSE_FONTENUM
2306 // just use the first face name if we can't check its availability:
2307 if (tk
.HasMoreTokens())
2308 facename
= tk
.GetNextToken();
2309 #endif // wxUSE_FONTENUM/!wxUSE_FONTENUM
2313 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
2314 bool hasEncoding
= HasParam(wxT("encoding"));
2318 wxString encoding
= GetParamValue(wxT("encoding"));
2319 wxFontMapper mapper
;
2320 if (!encoding
.empty())
2321 enc
= mapper
.CharsetToEncoding(encoding
);
2322 if (enc
== wxFONTENCODING_SYSTEM
)
2323 enc
= wxFONTENCODING_DEFAULT
;
2325 #endif // wxUSE_FONTMAP
2329 // is this font based on a system font?
2330 if (HasParam(wxT("sysfont")))
2332 font
= GetSystemFont(GetParamValue(wxT("sysfont")));
2333 if (HasParam(wxT("inherit")))
2338 "double specification of \"sysfont\" and \"inherit\""
2342 // or should the font of the widget be used?
2343 else if (GetBool(wxT("inherit"), false))
2346 font
= parent
->GetFont();
2352 "no parent window specified to derive the font from"
2359 if (hasSize
&& isize
!= -1)
2361 font
.SetPointSize(isize
);
2362 if (HasParam(wxT("relativesize")))
2367 "double specification of \"size\" and \"relativesize\""
2371 else if (HasParam(wxT("relativesize")))
2372 font
.SetPointSize(int(font
.GetPointSize() *
2373 GetFloat(wxT("relativesize"))));
2376 font
.SetStyle(istyle
);
2378 font
.SetWeight(iweight
);
2380 font
.SetUnderlined(underlined
);
2382 font
.SetFamily(ifamily
);
2384 font
.SetFaceName(facename
);
2386 font
.SetDefaultEncoding(enc
);
2388 else // not based on system font
2390 font
= wxFont(isize
== -1 ? wxNORMAL_FONT
->GetPointSize() : isize
,
2391 ifamily
, istyle
, iweight
,
2392 underlined
, facename
, enc
);
2395 m_handler
->m_node
= oldnode
;
2400 void wxXmlResourceHandlerImpl::SetupWindow(wxWindow
*wnd
)
2402 //FIXME : add cursor
2404 if (HasParam(wxT("exstyle")))
2405 // Have to OR it with existing style, since
2406 // some implementations (e.g. wxGTK) use the extra style
2408 wnd
->SetExtraStyle(wnd
->GetExtraStyle() | GetStyle(wxT("exstyle")));
2409 if (HasParam(wxT("bg")))
2410 wnd
->SetBackgroundColour(GetColour(wxT("bg")));
2411 if (HasParam(wxT("ownbg")))
2412 wnd
->SetOwnBackgroundColour(GetColour(wxT("ownbg")));
2413 if (HasParam(wxT("fg")))
2414 wnd
->SetForegroundColour(GetColour(wxT("fg")));
2415 if (HasParam(wxT("ownfg")))
2416 wnd
->SetOwnForegroundColour(GetColour(wxT("ownfg")));
2417 if (GetBool(wxT("enabled"), 1) == 0)
2419 if (GetBool(wxT("focused"), 0) == 1)
2421 if (GetBool(wxT("hidden"), 0) == 1)
2424 if (HasParam(wxT("tooltip")))
2425 wnd
->SetToolTip(GetText(wxT("tooltip")));
2427 if (HasParam(wxT("font")))
2428 wnd
->SetFont(GetFont(wxT("font"), wnd
));
2429 if (HasParam(wxT("ownfont")))
2430 wnd
->SetOwnFont(GetFont(wxT("ownfont"), wnd
));
2431 if (HasParam(wxT("help")))
2432 wnd
->SetHelpText(GetText(wxT("help")));
2436 void wxXmlResourceHandlerImpl::CreateChildren(wxObject
*parent
, bool this_hnd_only
)
2438 for ( wxXmlNode
*n
= m_handler
->m_node
->GetChildren(); n
; n
= n
->GetNext() )
2440 if ( IsObjectNode(n
) )
2442 m_handler
->m_resource
->DoCreateResFromNode(*n
, parent
, NULL
,
2443 this_hnd_only
? this->GetHandler() : NULL
);
2449 void wxXmlResourceHandlerImpl::CreateChildrenPrivately(wxObject
*parent
, wxXmlNode
*rootnode
)
2452 if (rootnode
== NULL
) root
= m_handler
->m_node
; else root
= rootnode
;
2453 wxXmlNode
*n
= root
->GetChildren();
2457 if (n
->GetType() == wxXML_ELEMENT_NODE
&& GetHandler()->CanHandle(n
))
2459 CreateResource(n
, parent
, NULL
);
2466 //-----------------------------------------------------------------------------
2468 //-----------------------------------------------------------------------------
2470 void wxXmlResourceHandlerImpl::ReportError(const wxString
& message
)
2472 m_handler
->m_resource
->ReportError(m_handler
->m_node
, message
);
2475 void wxXmlResourceHandlerImpl::ReportError(wxXmlNode
*context
,
2476 const wxString
& message
)
2478 m_handler
->m_resource
->ReportError(context
? context
: m_handler
->m_node
, message
);
2481 void wxXmlResourceHandlerImpl::ReportParamError(const wxString
& param
,
2482 const wxString
& message
)
2484 m_handler
->m_resource
->ReportError(GetParamNode(param
), message
);
2487 void wxXmlResource::ReportError(const wxXmlNode
*context
, const wxString
& message
)
2491 DoReportError("", NULL
, message
);
2495 // We need to find out the file that 'context' is part of. Performance of
2496 // this code is not critical, so we simply find the root XML node and
2497 // compare it with all loaded XRC files.
2498 const wxString filename
= GetFileNameFromNode(context
, Data());
2500 DoReportError(filename
, context
, message
);
2503 void wxXmlResource::DoReportError(const wxString
& xrcFile
, const wxXmlNode
*position
,
2504 const wxString
& message
)
2506 const int line
= position
? position
->GetLineNumber() : -1;
2509 if ( !xrcFile
.empty() )
2510 loc
= xrcFile
+ ':';
2512 loc
+= wxString::Format("%d:", line
);
2516 wxLogError("XRC error: %s%s", loc
, message
);
2520 //-----------------------------------------------------------------------------
2521 // XRCID implementation
2522 //-----------------------------------------------------------------------------
2524 #define XRCID_TABLE_SIZE 1024
2529 /* Hold the id so that once an id is allocated for a name, it
2530 does not get created again by NewControlId at least
2531 until we are done with it */
2537 static XRCID_record
*XRCID_Records
[XRCID_TABLE_SIZE
] = {NULL
};
2539 // Extremely simplistic hash function which probably ought to be replaced with
2540 // wxStringHash::stringHash().
2541 static inline unsigned XRCIdHash(const char *str_id
)
2545 for (const char *c
= str_id
; *c
!= '\0'; c
++) index
+= (unsigned int)*c
;
2546 index
%= XRCID_TABLE_SIZE
;
2551 static void XRCID_Assign(const wxString
& str_id
, int value
)
2553 const wxCharBuffer
buf_id(str_id
.mb_str());
2554 const unsigned index
= XRCIdHash(buf_id
);
2557 XRCID_record
*oldrec
= NULL
;
2558 for (XRCID_record
*rec
= XRCID_Records
[index
]; rec
; rec
= rec
->next
)
2560 if (wxStrcmp(rec
->key
, buf_id
) == 0)
2568 XRCID_record
**rec_var
= (oldrec
== NULL
) ?
2569 &XRCID_Records
[index
] : &oldrec
->next
;
2570 *rec_var
= new XRCID_record
;
2571 (*rec_var
)->key
= wxStrdup(str_id
);
2572 (*rec_var
)->id
= value
;
2573 (*rec_var
)->next
= NULL
;
2576 static int XRCID_Lookup(const char *str_id
, int value_if_not_found
= wxID_NONE
)
2578 const unsigned index
= XRCIdHash(str_id
);
2581 XRCID_record
*oldrec
= NULL
;
2582 for (XRCID_record
*rec
= XRCID_Records
[index
]; rec
; rec
= rec
->next
)
2584 if (wxStrcmp(rec
->key
, str_id
) == 0)
2591 XRCID_record
**rec_var
= (oldrec
== NULL
) ?
2592 &XRCID_Records
[index
] : &oldrec
->next
;
2593 *rec_var
= new XRCID_record
;
2594 (*rec_var
)->key
= wxStrdup(str_id
);
2595 (*rec_var
)->next
= NULL
;
2598 if (value_if_not_found
!= wxID_NONE
)
2599 (*rec_var
)->id
= value_if_not_found
;
2602 int asint
= wxStrtol(str_id
, &end
, 10);
2603 if (*str_id
&& *end
== 0)
2605 // if str_id was integer, keep it verbosely:
2606 (*rec_var
)->id
= asint
;
2610 (*rec_var
)->id
= wxWindowBase::NewControlId();
2614 return (*rec_var
)->id
;
2620 // flag indicating whether standard XRC ids were already initialized
2621 static bool gs_stdIDsAdded
= false;
2623 void AddStdXRCID_Records()
2625 #define stdID(id) XRCID_Lookup(#id, id)
2629 stdID(wxID_SEPARATOR
);
2642 stdID(wxID_PRINT_SETUP
);
2643 stdID(wxID_PAGE_SETUP
);
2644 stdID(wxID_PREVIEW
);
2646 stdID(wxID_HELP_CONTENTS
);
2647 stdID(wxID_HELP_INDEX
),
2648 stdID(wxID_HELP_SEARCH
),
2649 stdID(wxID_HELP_COMMANDS
);
2650 stdID(wxID_HELP_PROCEDURES
);
2651 stdID(wxID_HELP_CONTEXT
);
2652 stdID(wxID_CLOSE_ALL
);
2653 stdID(wxID_PREFERENCES
);
2661 stdID(wxID_DUPLICATE
);
2662 stdID(wxID_SELECTALL
);
2664 stdID(wxID_REPLACE
);
2665 stdID(wxID_REPLACE_ALL
);
2666 stdID(wxID_PROPERTIES
);
2668 stdID(wxID_VIEW_DETAILS
);
2669 stdID(wxID_VIEW_LARGEICONS
);
2670 stdID(wxID_VIEW_SMALLICONS
);
2671 stdID(wxID_VIEW_LIST
);
2672 stdID(wxID_VIEW_SORTDATE
);
2673 stdID(wxID_VIEW_SORTNAME
);
2674 stdID(wxID_VIEW_SORTSIZE
);
2675 stdID(wxID_VIEW_SORTTYPE
);
2695 stdID(wxID_FORWARD
);
2696 stdID(wxID_BACKWARD
);
2697 stdID(wxID_DEFAULT
);
2701 stdID(wxID_CONTEXT_HELP
);
2702 stdID(wxID_YESTOALL
);
2703 stdID(wxID_NOTOALL
);
2713 stdID(wxID_REFRESH
);
2719 stdID(wxID_JUSTIFY_CENTER
);
2720 stdID(wxID_JUSTIFY_FILL
);
2721 stdID(wxID_JUSTIFY_RIGHT
);
2722 stdID(wxID_JUSTIFY_LEFT
);
2723 stdID(wxID_UNDERLINE
);
2725 stdID(wxID_UNINDENT
);
2726 stdID(wxID_ZOOM_100
);
2727 stdID(wxID_ZOOM_FIT
);
2728 stdID(wxID_ZOOM_IN
);
2729 stdID(wxID_ZOOM_OUT
);
2730 stdID(wxID_UNDELETE
);
2731 stdID(wxID_REVERT_TO_SAVED
);
2733 stdID(wxID_CONVERT
);
2734 stdID(wxID_EXECUTE
);
2736 stdID(wxID_HARDDISK
);
2742 stdID(wxID_JUMP_TO
);
2743 stdID(wxID_NETWORK
);
2744 stdID(wxID_SELECT_COLOR
);
2745 stdID(wxID_SELECT_FONT
);
2746 stdID(wxID_SORT_ASCENDING
);
2747 stdID(wxID_SORT_DESCENDING
);
2748 stdID(wxID_SPELL_CHECK
);
2749 stdID(wxID_STRIKETHROUGH
);
2752 stdID(wxID_SYSTEM_MENU
);
2753 stdID(wxID_CLOSE_FRAME
);
2754 stdID(wxID_MOVE_FRAME
);
2755 stdID(wxID_RESIZE_FRAME
);
2756 stdID(wxID_MAXIMIZE_FRAME
);
2757 stdID(wxID_ICONIZE_FRAME
);
2758 stdID(wxID_RESTORE_FRAME
);
2762 stdID(wxID_MDI_WINDOW_CASCADE
);
2763 stdID(wxID_MDI_WINDOW_TILE_HORZ
);
2764 stdID(wxID_MDI_WINDOW_TILE_VERT
);
2765 stdID(wxID_MDI_WINDOW_ARRANGE_ICONS
);
2766 stdID(wxID_MDI_WINDOW_PREV
);
2767 stdID(wxID_MDI_WINDOW_NEXT
);
2771 } // anonymous namespace
2775 int wxXmlResource::DoGetXRCID(const char *str_id
, int value_if_not_found
)
2777 if ( !gs_stdIDsAdded
)
2779 gs_stdIDsAdded
= true;
2780 AddStdXRCID_Records();
2783 return XRCID_Lookup(str_id
, value_if_not_found
);
2787 wxString
wxXmlResource::FindXRCIDById(int numId
)
2789 for ( int i
= 0; i
< XRCID_TABLE_SIZE
; i
++ )
2791 for ( XRCID_record
*rec
= XRCID_Records
[i
]; rec
; rec
= rec
->next
)
2793 if ( rec
->id
== numId
)
2794 return wxString(rec
->key
);
2801 static void CleanXRCID_Record(XRCID_record
*rec
)
2805 CleanXRCID_Record(rec
->next
);
2812 static void CleanXRCID_Records()
2814 for (int i
= 0; i
< XRCID_TABLE_SIZE
; i
++)
2816 CleanXRCID_Record(XRCID_Records
[i
]);
2817 XRCID_Records
[i
] = NULL
;
2820 gs_stdIDsAdded
= false;
2824 //-----------------------------------------------------------------------------
2825 // module and globals
2826 //-----------------------------------------------------------------------------
2828 // normally we would do the cleanup from wxXmlResourceModule::OnExit() but it
2829 // can happen that some XRC records have been created because of the use of
2830 // XRCID() in event tables, which happens during static objects initialization,
2831 // but then the application initialization failed and so the wx modules were
2832 // neither initialized nor cleaned up -- this static object does the cleanup in
2834 static struct wxXRCStaticCleanup
2836 ~wxXRCStaticCleanup() { CleanXRCID_Records(); }
2839 class wxXmlResourceModule
: public wxModule
2841 DECLARE_DYNAMIC_CLASS(wxXmlResourceModule
)
2843 wxXmlResourceModule() {}
2846 wxXmlResource::AddSubclassFactory(new wxXmlSubclassFactoryCXX
);
2851 delete wxXmlResource::Set(NULL
);
2852 delete wxIdRangeManager::Set(NULL
);
2853 if(wxXmlResource::ms_subclassFactories
)
2855 for ( wxXmlSubclassFactories::iterator i
= wxXmlResource::ms_subclassFactories
->begin();
2856 i
!= wxXmlResource::ms_subclassFactories
->end(); ++i
)
2860 wxDELETE(wxXmlResource::ms_subclassFactories
);
2862 CleanXRCID_Records();
2866 IMPLEMENT_DYNAMIC_CLASS(wxXmlResourceModule
, wxModule
)
2869 // When wxXml is loaded dynamically after the application is already running
2870 // then the built-in module system won't pick this one up. Add it manually.
2871 void wxXmlInitResourceModule()
2873 wxModule
* module = new wxXmlResourceModule
;
2874 wxModule::RegisterModule(module);
2875 wxModule::InitializeModules();