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"
47 #include "wx/imaglist.h"
49 #include "wx/xml/xml.h"
50 #include "wx/hashset.h"
51 #include "wx/scopedptr.h"
56 // Helper function to get modification time of either a wxFileSystem URI or
57 // just a normal file name, depending on the build.
60 wxDateTime
GetXRCFileModTime(const wxString
& filename
)
64 wxScopedPtr
<wxFSFile
> file(fsys
.OpenFile(filename
));
66 return file
? file
->GetModificationTime() : wxDateTime();
67 #else // wxUSE_FILESYSTEM
68 return wxDateTime(wxFileModificationTime(filename
));
69 #endif // wxUSE_FILESYSTEM
72 #endif // wxUSE_DATETIME
74 } // anonymous namespace
76 // Assign the given value to the specified entry or add a new value with this
78 static void XRCID_Assign(const wxString
& str_id
, int value
);
80 class wxXmlResourceDataRecord
83 // Ctor takes ownership of the document pointer.
84 wxXmlResourceDataRecord(const wxString
& File_
,
87 : File(File_
), Doc(Doc_
)
90 Time
= GetXRCFileModTime(File
);
94 ~wxXmlResourceDataRecord() {delete Doc
;}
102 wxDECLARE_NO_COPY_CLASS(wxXmlResourceDataRecord
);
105 class wxXmlResourceDataRecords
: public wxVector
<wxXmlResourceDataRecord
*>
107 // this is a class so that it can be forward-declared
110 WX_DECLARE_HASH_SET_PTR(int, wxIntegerHash
, wxIntegerEqual
, wxHashSetInt
);
112 class wxIdRange
// Holds data for a particular rangename
115 wxIdRange(const wxXmlNode
* node
,
116 const wxString
& rname
,
117 const wxString
& startno
,
118 const wxString
& rsize
);
120 // Note the existence of an item within the range
121 void NoteItem(const wxXmlNode
* node
, const wxString
& item
);
123 // The manager is telling us that it's finished adding items
124 void Finalise(const wxXmlNode
* node
);
126 wxString
GetName() const { return m_name
; }
127 bool IsFinalised() const { return m_finalised
; }
129 const wxString m_name
;
133 bool m_item_end_found
;
135 wxHashSetInt m_indices
;
137 friend class wxIdRangeManager
;
140 class wxIdRangeManager
144 // Gets the global resources object or creates one if none exists.
145 static wxIdRangeManager
*Get();
147 // Sets the global resources object and returns a pointer to the previous
148 // one (may be NULL).
149 static wxIdRangeManager
*Set(wxIdRangeManager
*res
);
151 // Create a new IDrange from this node
152 void AddRange(const wxXmlNode
* node
);
153 // Tell the IdRange that this item exists, and should be pre-allocated an ID
154 void NotifyRangeOfItem(const wxXmlNode
* node
, const wxString
& item
) const;
155 // Tells all IDranges that they're now complete, and can create their IDs
156 void FinaliseRanges(const wxXmlNode
* node
) const;
157 // Searches for a known IdRange matching 'name', returning its index or -1
158 int Find(const wxString
& rangename
) const;
161 wxIdRange
* FindRangeForItem(const wxXmlNode
* node
,
162 const wxString
& item
,
163 wxString
& value
) const;
164 wxVector
<wxIdRange
*> m_IdRanges
;
167 static wxIdRangeManager
*ms_instance
;
173 // helper used by DoFindResource() and elsewhere: returns true if this is an
174 // object or object_ref node
176 // node must be non-NULL
177 inline bool IsObjectNode(wxXmlNode
*node
)
179 return node
->GetType() == wxXML_ELEMENT_NODE
&&
180 (node
->GetName() == wxS("object") ||
181 node
->GetName() == wxS("object_ref"));
184 // special XML attribute with name of input file, see GetFileNameFromNode()
185 const char *ATTR_INPUT_FILENAME
= "__wx:filename";
187 // helper to get filename corresponding to an XML node
189 GetFileNameFromNode(const wxXmlNode
*node
, const wxXmlResourceDataRecords
& files
)
191 // this loop does two things: it looks for ATTR_INPUT_FILENAME among
192 // parents and if it isn't used, it finds the root of the XML tree 'node'
196 // in some rare cases (specifically, when an <object_ref> is used, see
197 // wxXmlResource::CreateResFromNode() and MergeNodesOver()), we work
198 // with XML nodes that are not rooted in any document from 'files'
199 // (because a new node was created by CreateResFromNode() to merge the
200 // content of <object_ref> and the referenced <object>); in that case,
201 // we hack around the problem by putting the information about input
202 // file into a custom attribute
203 if ( node
->HasAttribute(ATTR_INPUT_FILENAME
) )
204 return node
->GetAttribute(ATTR_INPUT_FILENAME
);
206 if ( !node
->GetParent() )
207 break; // we found the root of this XML tree
209 node
= node
->GetParent();
212 // NB: 'node' now points to the root of XML document
214 for ( wxXmlResourceDataRecords::const_iterator i
= files
.begin();
215 i
!= files
.end(); ++i
)
217 if ( (*i
)->Doc
->GetRoot() == node
)
223 return wxEmptyString
; // not found
226 } // anonymous namespace
229 wxXmlResource
*wxXmlResource::ms_instance
= NULL
;
231 /*static*/ wxXmlResource
*wxXmlResource::Get()
234 ms_instance
= new wxXmlResource
;
238 /*static*/ wxXmlResource
*wxXmlResource::Set(wxXmlResource
*res
)
240 wxXmlResource
*old
= ms_instance
;
245 wxXmlResource::wxXmlResource(int flags
, const wxString
& domain
)
249 m_data
= new wxXmlResourceDataRecords
;
253 wxXmlResource::wxXmlResource(const wxString
& filemask
, int flags
, const wxString
& domain
)
257 m_data
= new wxXmlResourceDataRecords
;
262 wxXmlResource::~wxXmlResource()
266 for ( wxXmlResourceDataRecords::iterator i
= m_data
->begin();
267 i
!= m_data
->end(); ++i
)
274 void wxXmlResource::SetDomain(const wxString
& domain
)
281 wxString
wxXmlResource::ConvertFileNameToURL(const wxString
& filename
)
283 wxString
fnd(filename
);
285 // NB: as Load() and Unload() accept both filenames and URLs (should
286 // probably be changed to filenames only, but embedded resources
287 // currently rely on its ability to handle URLs - FIXME) we need to
288 // determine whether found name is filename and not URL and this is the
289 // fastest/simplest way to do it
290 if (wxFileName::FileExists(fnd
))
292 // Make the name absolute filename, because the app may
293 // change working directory later:
298 fnd
= fn
.GetFullPath();
301 fnd
= wxFileSystem::FileNameToURL(fnd
);
311 bool wxXmlResource::IsArchive(const wxString
& filename
)
313 const wxString fnd
= filename
.Lower();
315 return fnd
.Matches(wxT("*.zip")) || fnd
.Matches(wxT("*.xrs"));
318 #endif // wxUSE_FILESYSTEM
320 bool wxXmlResource::LoadFile(const wxFileName
& file
)
323 return Load(wxFileSystem::FileNameToURL(file
));
325 return Load(file
.GetFullPath());
329 bool wxXmlResource::LoadAllFiles(const wxString
& dirname
)
334 wxDir::GetAllFiles(dirname
, &files
, "*.xrc");
336 for ( wxArrayString::const_iterator i
= files
.begin(); i
!= files
.end(); ++i
)
345 bool wxXmlResource::Load(const wxString
& filemask_
)
347 wxString filemask
= ConvertFileNameToURL(filemask_
);
353 # define wxXmlFindFirst fsys.FindFirst(filemask, wxFILE)
354 # define wxXmlFindNext fsys.FindNext()
356 # define wxXmlFindFirst wxFindFirstFile(filemask, wxFILE)
357 # define wxXmlFindNext wxFindNextFile()
359 wxString fnd
= wxXmlFindFirst
;
362 wxLogError(_("Cannot load resources from '%s'."), filemask
);
369 if ( IsArchive(fnd
) )
371 if ( !Load(fnd
+ wxT("#zip:*.xrc")) )
374 else // a single resource URL
375 #endif // wxUSE_FILESYSTEM
377 wxXmlDocument
* const doc
= DoLoadFile(fnd
);
381 Data().push_back(new wxXmlResourceDataRecord(fnd
, doc
));
386 # undef wxXmlFindFirst
387 # undef wxXmlFindNext
392 bool wxXmlResource::Unload(const wxString
& filename
)
394 wxASSERT_MSG( !wxIsWild(filename
),
395 wxT("wildcards not supported by wxXmlResource::Unload()") );
397 wxString fnd
= ConvertFileNameToURL(filename
);
399 const bool isArchive
= IsArchive(fnd
);
402 #endif // wxUSE_FILESYSTEM
404 bool unloaded
= false;
405 for ( wxXmlResourceDataRecords::iterator i
= Data().begin();
406 i
!= Data().end(); ++i
)
411 if ( (*i
)->File
.StartsWith(fnd
) )
413 // don't break from the loop, we can have other matching files
415 else // a single resource URL
416 #endif // wxUSE_FILESYSTEM
418 if ( (*i
)->File
== fnd
)
424 // no sense in continuing, there is only one file with this URL
434 void wxXmlResource::AddHandler(wxXmlResourceHandler
*handler
)
436 wxXmlResourceHandlerImpl
*impl
= new wxXmlResourceHandlerImpl(handler
);
437 handler
->SetImpl(impl
);
438 m_handlers
.push_back(handler
);
439 handler
->SetParentResource(this);
442 void wxXmlResource::InsertHandler(wxXmlResourceHandler
*handler
)
444 wxXmlResourceHandlerImpl
*impl
= new wxXmlResourceHandlerImpl(handler
);
445 handler
->SetImpl(impl
);
446 m_handlers
.insert(m_handlers
.begin(), handler
);
447 handler
->SetParentResource(this);
452 void wxXmlResource::ClearHandlers()
454 for ( wxVector
<wxXmlResourceHandler
*>::iterator i
= m_handlers
.begin();
455 i
!= m_handlers
.end(); ++i
)
461 wxMenu
*wxXmlResource::LoadMenu(const wxString
& name
)
463 return (wxMenu
*)CreateResFromNode(FindResource(name
, wxT("wxMenu")), NULL
, NULL
);
468 wxMenuBar
*wxXmlResource::LoadMenuBar(wxWindow
*parent
, const wxString
& name
)
470 return (wxMenuBar
*)CreateResFromNode(FindResource(name
, wxT("wxMenuBar")), parent
, NULL
);
476 wxToolBar
*wxXmlResource::LoadToolBar(wxWindow
*parent
, const wxString
& name
)
478 return (wxToolBar
*)CreateResFromNode(FindResource(name
, wxT("wxToolBar")), parent
, NULL
);
483 wxDialog
*wxXmlResource::LoadDialog(wxWindow
*parent
, const wxString
& name
)
485 return (wxDialog
*)CreateResFromNode(FindResource(name
, wxT("wxDialog")), parent
, NULL
);
488 bool wxXmlResource::LoadDialog(wxDialog
*dlg
, wxWindow
*parent
, const wxString
& name
)
490 return CreateResFromNode(FindResource(name
, wxT("wxDialog")), parent
, dlg
) != NULL
;
495 wxPanel
*wxXmlResource::LoadPanel(wxWindow
*parent
, const wxString
& name
)
497 return (wxPanel
*)CreateResFromNode(FindResource(name
, wxT("wxPanel")), parent
, NULL
);
500 bool wxXmlResource::LoadPanel(wxPanel
*panel
, wxWindow
*parent
, const wxString
& name
)
502 return CreateResFromNode(FindResource(name
, wxT("wxPanel")), parent
, panel
) != NULL
;
505 wxFrame
*wxXmlResource::LoadFrame(wxWindow
* parent
, const wxString
& name
)
507 return (wxFrame
*)CreateResFromNode(FindResource(name
, wxT("wxFrame")), parent
, NULL
);
510 bool wxXmlResource::LoadFrame(wxFrame
* frame
, wxWindow
*parent
, const wxString
& name
)
512 return CreateResFromNode(FindResource(name
, wxT("wxFrame")), parent
, frame
) != NULL
;
515 wxBitmap
wxXmlResource::LoadBitmap(const wxString
& name
)
517 wxBitmap
*bmp
= (wxBitmap
*)CreateResFromNode(
518 FindResource(name
, wxT("wxBitmap")), NULL
, NULL
);
521 if (bmp
) { rt
= *bmp
; delete bmp
; }
525 wxIcon
wxXmlResource::LoadIcon(const wxString
& name
)
527 wxIcon
*icon
= (wxIcon
*)CreateResFromNode(
528 FindResource(name
, wxT("wxIcon")), NULL
, NULL
);
531 if (icon
) { rt
= *icon
; delete icon
; }
537 wxXmlResource::DoLoadObject(wxWindow
*parent
,
538 const wxString
& name
,
539 const wxString
& classname
,
542 wxXmlNode
* const node
= FindResource(name
, classname
, recursive
);
544 return node
? DoCreateResFromNode(*node
, parent
, NULL
) : NULL
;
548 wxXmlResource::DoLoadObject(wxObject
*instance
,
550 const wxString
& name
,
551 const wxString
& classname
,
554 wxXmlNode
* const node
= FindResource(name
, classname
, recursive
);
556 return node
&& DoCreateResFromNode(*node
, parent
, instance
) != NULL
;
560 bool wxXmlResource::AttachUnknownControl(const wxString
& name
,
561 wxWindow
*control
, wxWindow
*parent
)
564 parent
= control
->GetParent();
565 wxWindow
*container
= parent
->FindWindow(name
+ wxT("_container"));
568 wxLogError("Cannot find container for unknown control '%s'.", name
);
571 return control
->Reparent(container
);
575 static void ProcessPlatformProperty(wxXmlNode
*node
)
580 wxXmlNode
*c
= node
->GetChildren();
584 if (!c
->GetAttribute(wxT("platform"), &s
))
588 wxStringTokenizer
tkn(s
, wxT(" |"));
590 while (tkn
.HasMoreTokens())
592 s
= tkn
.GetNextToken();
594 if (s
== wxT("win")) isok
= true;
596 #if defined(__MAC__) || defined(__APPLE__)
597 if (s
== wxT("mac")) isok
= true;
598 #elif defined(__UNIX__)
599 if (s
== wxT("unix")) isok
= true;
602 if (s
== wxT("os2")) isok
= true;
612 ProcessPlatformProperty(c
);
617 wxXmlNode
*c2
= c
->GetNext();
618 node
->RemoveChild(c
);
625 static void PreprocessForIdRanges(wxXmlNode
*rootnode
)
627 // First go through the top level, looking for the names of ID ranges
628 // as processing items is a lot easier if names are already known
629 wxXmlNode
*c
= rootnode
->GetChildren();
632 if (c
->GetName() == wxT("ids-range"))
633 wxIdRangeManager::Get()->AddRange(c
);
637 // Next, examine every 'name' for the '[' that denotes an ID in a range
638 c
= rootnode
->GetChildren();
641 wxString name
= c
->GetAttribute(wxT("name"));
642 if (name
.find('[') != wxString::npos
)
643 wxIdRangeManager::Get()->NotifyRangeOfItem(rootnode
, name
);
645 // Do any children by recursion, then proceed to the next sibling
646 PreprocessForIdRanges(c
);
651 bool wxXmlResource::UpdateResources()
655 for ( wxXmlResourceDataRecords::iterator i
= Data().begin();
656 i
!= Data().end(); ++i
)
658 wxXmlResourceDataRecord
* const rec
= *i
;
660 // Check if we need to reload this one.
662 // We never do it if this flag is specified.
663 if ( m_flags
& wxXRC_NO_RELOADING
)
666 // Otherwise check its modification time if we can.
668 const wxDateTime lastModTime
= GetXRCFileModTime(rec
->File
);
670 if ( lastModTime
.IsValid() && lastModTime
<= rec
->Time
)
671 #else // !wxUSE_DATETIME
672 // Never reload the file contents: we can't know whether it changed or
673 // not in this build configuration and it would be unexpected and
674 // counter-productive to get a performance hit (due to constant
675 // reloading of XRC files) in a minimal wx build which is presumably
676 // used because of resource constraints of the current platform.
677 #endif // wxUSE_DATETIME/!wxUSE_DATETIME
679 // No need to reload, the file wasn't modified since we did it
684 wxXmlDocument
* const doc
= DoLoadFile(rec
->File
);
687 // Notice that we keep the old XML document: it seems better to
688 // preserve it instead of throwing it away if we have nothing to
694 // Replace the old resource contents with the new one.
698 // And, now that we loaded it successfully, update the last load time.
700 rec
->Time
= lastModTime
.IsValid() ? lastModTime
: wxDateTime::Now();
701 #endif // wxUSE_DATETIME
707 wxXmlDocument
*wxXmlResource::DoLoadFile(const wxString
& filename
)
709 wxLogTrace(wxT("xrc"), wxT("opening file '%s'"), filename
);
711 wxInputStream
*stream
= NULL
;
715 wxScopedPtr
<wxFSFile
> file(fsys
.OpenFile(filename
));
718 // Notice that we don't have ownership of the stream in this case, it
719 // remains owned by wxFSFile.
720 stream
= file
->GetStream();
722 #else // !wxUSE_FILESYSTEM
723 wxFileInputStream
fstream(filename
);
725 #endif // wxUSE_FILESYSTEM/!wxUSE_FILESYSTEM
727 if ( !stream
|| !stream
->IsOk() )
729 wxLogError(_("Cannot open resources file '%s'."), filename
);
733 wxString
encoding(wxT("UTF-8"));
734 #if !wxUSE_UNICODE && wxUSE_INTL
735 if ( (GetFlags() & wxXRC_USE_LOCALE
) == 0 )
737 // In case we are not using wxLocale to translate strings, convert the
738 // strings GUI's charset. This must not be done when wxXRC_USE_LOCALE
739 // is on, because it could break wxGetTranslation lookup.
740 encoding
= wxLocale::GetSystemEncodingName();
744 wxScopedPtr
<wxXmlDocument
> doc(new wxXmlDocument
);
745 if (!doc
->Load(*stream
, encoding
))
747 wxLogError(_("Cannot load resources from file '%s'."), filename
);
751 wxXmlNode
* const root
= doc
->GetRoot();
752 if (root
->GetName() != wxT("resource"))
757 "invalid XRC resource, doesn't have root node <resource>"
764 wxString verstr
= root
->GetAttribute(wxT("version"), wxT("0.0.0.0"));
765 if (wxSscanf(verstr
, wxT("%i.%i.%i.%i"), &v1
, &v2
, &v3
, &v4
) == 4)
766 version
= v1
*256*256*256+v2
*256*256+v3
*256+v4
;
771 if (m_version
!= version
)
773 wxLogWarning("Resource files must have same version number.");
776 ProcessPlatformProperty(root
);
777 PreprocessForIdRanges(root
);
778 wxIdRangeManager::Get()->FinaliseRanges(root
);
780 return doc
.release();
783 wxXmlNode
*wxXmlResource::DoFindResource(wxXmlNode
*parent
,
784 const wxString
& name
,
785 const wxString
& classname
,
786 bool recursive
) const
790 // first search for match at the top-level nodes (as this is
791 // where the resource is most commonly looked for):
792 for (node
= parent
->GetChildren(); node
; node
= node
->GetNext())
794 if ( IsObjectNode(node
) && node
->GetAttribute(wxS("name")) == name
)
796 // empty class name matches everything
797 if ( classname
.empty() )
800 wxString
cls(node
->GetAttribute(wxS("class")));
802 // object_ref may not have 'class' attribute:
803 if (cls
.empty() && node
->GetName() == wxS("object_ref"))
805 wxString refName
= node
->GetAttribute(wxS("ref"));
809 const wxXmlNode
* const refNode
= GetResourceNode(refName
);
811 cls
= refNode
->GetAttribute(wxS("class"));
814 if ( cls
== classname
)
819 // then recurse in child nodes
822 for (node
= parent
->GetChildren(); node
; node
= node
->GetNext())
824 if ( IsObjectNode(node
) )
826 wxXmlNode
* found
= DoFindResource(node
, name
, classname
, true);
836 wxXmlNode
*wxXmlResource::FindResource(const wxString
& name
,
837 const wxString
& classname
,
842 node
= GetResourceNodeAndLocation(name
, classname
, recursive
, &path
);
851 "XRC resource \"%s\" (class \"%s\") not found",
857 else // node was found
859 // ensure that relative paths work correctly when loading this node
860 // (which should happen as soon as we return as FindResource() result
861 // is always passed to CreateResFromNode())
862 m_curFileSystem
.ChangePathTo(path
);
864 #endif // wxUSE_FILESYSTEM
870 wxXmlResource::GetResourceNodeAndLocation(const wxString
& name
,
871 const wxString
& classname
,
873 wxString
*path
) const
875 // ensure everything is up-to-date: this is needed to support on-demand
876 // reloading of XRC files
877 const_cast<wxXmlResource
*>(this)->UpdateResources();
879 for ( wxXmlResourceDataRecords::const_iterator f
= Data().begin();
880 f
!= Data().end(); ++f
)
882 wxXmlResourceDataRecord
*const rec
= *f
;
883 wxXmlDocument
* const doc
= rec
->Doc
;
884 if ( !doc
|| !doc
->GetRoot() )
888 found
= DoFindResource(doc
->GetRoot(), name
, classname
, recursive
);
901 static void MergeNodesOver(wxXmlNode
& dest
, wxXmlNode
& overwriteWith
,
902 const wxString
& overwriteFilename
)
905 for ( wxXmlAttribute
*attr
= overwriteWith
.GetAttributes();
906 attr
; attr
= attr
->GetNext() )
908 wxXmlAttribute
*dattr
;
909 for (dattr
= dest
.GetAttributes(); dattr
; dattr
= dattr
->GetNext())
912 if ( dattr
->GetName() == attr
->GetName() )
914 dattr
->SetValue(attr
->GetValue());
920 dest
.AddAttribute(attr
->GetName(), attr
->GetValue());
923 // Merge child nodes:
924 for (wxXmlNode
* node
= overwriteWith
.GetChildren(); node
; node
= node
->GetNext())
926 wxString name
= node
->GetAttribute(wxT("name"), wxEmptyString
);
929 for (dnode
= dest
.GetChildren(); dnode
; dnode
= dnode
->GetNext() )
931 if ( dnode
->GetName() == node
->GetName() &&
932 dnode
->GetAttribute(wxT("name"), wxEmptyString
) == name
&&
933 dnode
->GetType() == node
->GetType() )
935 MergeNodesOver(*dnode
, *node
, overwriteFilename
);
942 wxXmlNode
*copyOfNode
= new wxXmlNode(*node
);
943 // remember referenced object's file, see GetFileNameFromNode()
944 copyOfNode
->AddAttribute(ATTR_INPUT_FILENAME
, overwriteFilename
);
946 static const wxChar
*AT_END
= wxT("end");
947 wxString insert_pos
= node
->GetAttribute(wxT("insert_at"), AT_END
);
948 if ( insert_pos
== AT_END
)
950 dest
.AddChild(copyOfNode
);
952 else if ( insert_pos
== wxT("begin") )
954 dest
.InsertChild(copyOfNode
, dest
.GetChildren());
959 if ( dest
.GetType() == wxXML_TEXT_NODE
&& overwriteWith
.GetContent().length() )
960 dest
.SetContent(overwriteWith
.GetContent());
964 wxXmlResource::DoCreateResFromNode(wxXmlNode
& node
,
967 wxXmlResourceHandler
*handlerToUse
)
969 // handling of referenced resource
970 if ( node
.GetName() == wxT("object_ref") )
972 wxString refName
= node
.GetAttribute(wxT("ref"), wxEmptyString
);
973 wxXmlNode
* refNode
= FindResource(refName
, wxEmptyString
, true);
982 "referenced object node with ref=\"%s\" not found",
989 const bool hasOnlyRefAttr
= node
.GetAttributes() != NULL
&&
990 node
.GetAttributes()->GetNext() == NULL
;
992 if ( hasOnlyRefAttr
&& !node
.GetChildren() )
994 // In the typical, simple case, <object_ref> is used to link
995 // to another node and doesn't have any content of its own that
996 // would overwrite linked object's properties. In this case,
997 // we can simply create the resource from linked node.
999 return DoCreateResFromNode(*refNode
, parent
, instance
);
1003 // In the more complicated (but rare) case, <object_ref> has
1004 // subnodes that partially overwrite content of the referenced
1005 // object. In this case, we need to merge both XML trees and
1006 // load the resource from result of the merge.
1008 wxXmlNode
copy(*refNode
);
1009 MergeNodesOver(copy
, node
, GetFileNameFromNode(&node
, Data()));
1011 // remember referenced object's file, see GetFileNameFromNode()
1012 copy
.AddAttribute(ATTR_INPUT_FILENAME
,
1013 GetFileNameFromNode(refNode
, Data()));
1015 return DoCreateResFromNode(copy
, parent
, instance
);
1021 if (handlerToUse
->CanHandle(&node
))
1023 return handlerToUse
->CreateResource(&node
, parent
, instance
);
1026 else if (node
.GetName() == wxT("object"))
1028 for ( wxVector
<wxXmlResourceHandler
*>::iterator h
= m_handlers
.begin();
1029 h
!= m_handlers
.end(); ++h
)
1031 wxXmlResourceHandler
*handler
= *h
;
1032 if (handler
->CanHandle(&node
))
1033 return handler
->CreateResource(&node
, parent
, instance
);
1042 "no handler found for XML node \"%s\" (class \"%s\")",
1044 node
.GetAttribute("class", wxEmptyString
)
1050 wxIdRange::wxIdRange(const wxXmlNode
* node
,
1051 const wxString
& rname
,
1052 const wxString
& startno
,
1053 const wxString
& rsize
)
1057 m_item_end_found(0),
1061 if ( startno
.ToLong(&l
) )
1069 wxXmlResource::Get()->ReportError
1072 "a negative id-range start parameter was given"
1078 wxXmlResource::Get()->ReportError
1081 "the id-range start parameter was malformed"
1086 if ( rsize
.ToULong(&ul
) )
1092 wxXmlResource::Get()->ReportError
1095 "the id-range size parameter was malformed"
1100 void wxIdRange::NoteItem(const wxXmlNode
* node
, const wxString
& item
)
1102 // Nothing gets added here, but the existence of each item is noted
1103 // thus getting an accurate count. 'item' will be either an integer e.g.
1104 // [0] [123]: will eventually create an XRCID as start+integer or [start]
1105 // or [end] which are synonyms for [0] or [range_size-1] respectively.
1106 wxString
content(item
.Mid(1, item
.length()-2));
1108 // Check that basename+item wasn't foo[]
1109 if (content
.empty())
1111 wxXmlResource::Get()->ReportError(node
, "an empty id-range item found");
1115 if (content
=="start")
1117 // "start" means [0], so store that in the set
1118 if (m_indices
.count(0) == 0)
1120 m_indices
.insert(0);
1124 wxXmlResource::Get()->ReportError
1127 "duplicate id-range item found"
1131 else if (content
=="end")
1133 // We can't yet be certain which XRCID this will be equivalent to, so
1134 // just note that there's an item with this name, in case we need to
1135 // inc the range size
1136 m_item_end_found
= true;
1140 // Anything else will be an integer, or rubbish
1142 if ( content
.ToULong(&l
) )
1144 if (m_indices
.count(l
) == 0)
1146 m_indices
.insert(l
);
1147 // Check that this item wouldn't fall outside the current range
1156 wxXmlResource::Get()->ReportError
1159 "duplicate id-range item found"
1166 wxXmlResource::Get()->ReportError
1169 "an id-range item had a malformed index"
1175 void wxIdRange::Finalise(const wxXmlNode
* node
)
1177 wxCHECK_RET( !IsFinalised(),
1178 "Trying to finalise an already-finalised range" );
1180 // Now we know about all the items, we can get an accurate range size
1181 // Expand any requested range-size if there were more items than would fit
1182 m_size
= wxMax(m_size
, m_indices
.size());
1184 // If an item is explicitly called foo[end], ensure it won't clash with
1186 if ( m_item_end_found
&& m_indices
.count(m_size
-1) )
1190 // This will happen if someone creates a range but no items in this xrc
1191 // file Report the error and abort, but don't finalise, in case items
1193 wxXmlResource::Get()->ReportError
1196 "trying to create an empty id-range"
1203 // This is the usual case, where the user didn't specify a start ID
1204 // So get the range using NewControlId().
1206 // NB: negative numbers, but NewControlId already returns the most
1208 m_start
= wxWindow::NewControlId(m_size
);
1209 wxCHECK_RET( m_start
!= wxID_NONE
,
1210 "insufficient IDs available to create range" );
1211 m_end
= m_start
+ m_size
- 1;
1215 // The user already specified a start value, which must be positive
1216 m_end
= m_start
+ m_size
- 1;
1219 // Create the XRCIDs
1220 for (int i
=m_start
; i
<= m_end
; ++i
)
1222 // Ensure that we overwrite any existing value as otherwise
1223 // wxXmlResource::Unload() followed by Load() wouldn't work correctly.
1224 XRCID_Assign(m_name
+ wxString::Format("[%i]", i
-m_start
), i
);
1226 wxLogTrace("xrcrange",
1227 "integer = %i %s now returns %i",
1229 m_name
+ wxString::Format("[%i]", i
-m_start
),
1230 XRCID((m_name
+ wxString::Format("[%i]", i
-m_start
)).mb_str()));
1232 // and these special ones
1233 XRCID_Assign(m_name
+ "[start]", m_start
);
1234 XRCID_Assign(m_name
+ "[end]", m_end
);
1235 wxLogTrace("xrcrange","%s[start] = %i %s[end] = %i",
1236 m_name
.mb_str(),XRCID(wxString(m_name
+"[start]").mb_str()),
1237 m_name
.mb_str(),XRCID(wxString(m_name
+"[end]").mb_str()));
1242 wxIdRangeManager
*wxIdRangeManager::ms_instance
= NULL
;
1244 /*static*/ wxIdRangeManager
*wxIdRangeManager::Get()
1247 ms_instance
= new wxIdRangeManager
;
1251 /*static*/ wxIdRangeManager
*wxIdRangeManager::Set(wxIdRangeManager
*res
)
1253 wxIdRangeManager
*old
= ms_instance
;
1258 wxIdRangeManager::~wxIdRangeManager()
1260 for ( wxVector
<wxIdRange
*>::iterator i
= m_IdRanges
.begin();
1261 i
!= m_IdRanges
.end(); ++i
)
1270 void wxIdRangeManager::AddRange(const wxXmlNode
* node
)
1272 wxString name
= node
->GetAttribute("name");
1273 wxString start
= node
->GetAttribute("start", "0");
1274 wxString size
= node
->GetAttribute("size", "0");
1277 wxXmlResource::Get()->ReportError
1280 "xrc file contains an id-range without a name"
1285 int index
= Find(name
);
1286 if (index
== wxNOT_FOUND
)
1288 wxLogTrace("xrcrange",
1289 "Adding ID range, name=%s start=%s size=%s",
1292 m_IdRanges
.push_back(new wxIdRange(node
, name
, start
, size
));
1296 // There was already a range with this name. Let's hope this is
1297 // from an Unload()/(re)Load(), not an unintentional duplication
1298 wxLogTrace("xrcrange",
1299 "Replacing ID range, name=%s start=%s size=%s",
1302 wxIdRange
* oldrange
= m_IdRanges
.at(index
);
1303 m_IdRanges
.at(index
) = new wxIdRange(node
, name
, start
, size
);
1309 wxIdRangeManager::FindRangeForItem(const wxXmlNode
* node
,
1310 const wxString
& item
,
1311 wxString
& value
) const
1313 wxString basename
= item
.BeforeFirst('[');
1314 wxCHECK_MSG( !basename
.empty(), NULL
,
1315 "an id-range item without a range name" );
1317 int index
= Find(basename
);
1318 if (index
== wxNOT_FOUND
)
1320 // Don't assert just because we've found an unexpected foo[123]
1321 // Someone might just want such a name, nothing to do with ranges
1325 value
= item
.Mid(basename
.Len());
1326 if (value
.at(value
.length()-1)==']')
1328 return m_IdRanges
.at(index
);
1330 wxXmlResource::Get()->ReportError(node
, "a malformed id-range item");
1335 wxIdRangeManager::NotifyRangeOfItem(const wxXmlNode
* node
,
1336 const wxString
& item
) const
1339 wxIdRange
* range
= FindRangeForItem(node
, item
, value
);
1341 range
->NoteItem(node
, value
);
1344 int wxIdRangeManager::Find(const wxString
& rangename
) const
1346 for ( int i
=0; i
< (int)m_IdRanges
.size(); ++i
)
1348 if (m_IdRanges
.at(i
)->GetName() == rangename
)
1355 void wxIdRangeManager::FinaliseRanges(const wxXmlNode
* node
) const
1357 for ( wxVector
<wxIdRange
*>::const_iterator i
= m_IdRanges
.begin();
1358 i
!= m_IdRanges
.end(); ++i
)
1360 // Check if this range has already been finalised. Quite possible,
1361 // as FinaliseRanges() gets called for each .xrc file loaded
1362 if (!(*i
)->IsFinalised())
1364 wxLogTrace("xrcrange", "Finalising ID range %s", (*i
)->GetName());
1365 (*i
)->Finalise(node
);
1371 class wxXmlSubclassFactories
: public wxVector
<wxXmlSubclassFactory
*>
1373 // this is a class so that it can be forward-declared
1376 wxXmlSubclassFactories
*wxXmlResource::ms_subclassFactories
= NULL
;
1378 /*static*/ void wxXmlResource::AddSubclassFactory(wxXmlSubclassFactory
*factory
)
1380 if (!ms_subclassFactories
)
1382 ms_subclassFactories
= new wxXmlSubclassFactories
;
1384 ms_subclassFactories
->push_back(factory
);
1387 class wxXmlSubclassFactoryCXX
: public wxXmlSubclassFactory
1390 ~wxXmlSubclassFactoryCXX() {}
1392 wxObject
*Create(const wxString
& className
)
1394 wxClassInfo
* classInfo
= wxClassInfo::FindClass(className
);
1397 return classInfo
->CreateObject();
1406 wxXmlResourceHandlerImpl::wxXmlResourceHandlerImpl(wxXmlResourceHandler
*handler
)
1407 :wxXmlResourceHandlerImplBase(handler
)
1411 wxObject
*wxXmlResourceHandlerImpl::CreateResFromNode(wxXmlNode
*node
,
1412 wxObject
*parent
, wxObject
*instance
)
1414 return m_handler
->m_resource
->CreateResFromNode(node
, parent
, instance
);
1417 #if wxUSE_FILESYSTEM
1418 wxFileSystem
& wxXmlResourceHandlerImpl::GetCurFileSystem()
1420 return m_handler
->m_resource
->GetCurFileSystem();
1425 wxObject
*wxXmlResourceHandlerImpl::CreateResource(wxXmlNode
*node
, wxObject
*parent
, wxObject
*instance
)
1427 wxXmlNode
*myNode
= m_handler
->m_node
;
1428 wxString myClass
= m_handler
->m_class
;
1429 wxObject
*myParent
= m_handler
->m_parent
, *myInstance
= m_handler
->m_instance
;
1430 wxWindow
*myParentAW
= m_handler
->m_parentAsWindow
;
1432 m_handler
->m_instance
= instance
;
1433 if (!m_handler
->m_instance
&& node
->HasAttribute(wxT("subclass")) &&
1434 !(m_handler
->m_resource
->GetFlags() & wxXRC_NO_SUBCLASSING
))
1436 wxString subclass
= node
->GetAttribute(wxT("subclass"), wxEmptyString
);
1437 if (!subclass
.empty())
1439 for (wxXmlSubclassFactories::iterator i
= wxXmlResource::ms_subclassFactories
->begin();
1440 i
!= wxXmlResource::ms_subclassFactories
->end(); ++i
)
1442 m_handler
->m_instance
= (*i
)->Create(subclass
);
1443 if (m_handler
->m_instance
)
1447 if (!m_handler
->m_instance
)
1449 wxString name
= node
->GetAttribute(wxT("name"), wxEmptyString
);
1455 "subclass \"%s\" not found for resource \"%s\", not subclassing",
1463 m_handler
->m_node
= node
;
1464 m_handler
->m_class
= node
->GetAttribute(wxT("class"), wxEmptyString
);
1465 m_handler
->m_parent
= parent
;
1466 m_handler
->m_parentAsWindow
= wxDynamicCast(m_handler
->m_parent
, wxWindow
);
1468 wxObject
*returned
= GetHandler()->DoCreateResource();
1470 m_handler
->m_node
= myNode
;
1471 m_handler
->m_class
= myClass
;
1472 m_handler
->m_parent
= myParent
; m_handler
->m_parentAsWindow
= myParentAW
;
1473 m_handler
->m_instance
= myInstance
;
1478 bool wxXmlResourceHandlerImpl::HasParam(const wxString
& param
)
1480 return (GetParamNode(param
) != NULL
);
1484 int wxXmlResourceHandlerImpl::GetStyle(const wxString
& param
, int defaults
)
1486 wxString s
= GetParamValue(param
);
1488 if (!s
) return defaults
;
1490 wxStringTokenizer
tkn(s
, wxT("| \t\n"), wxTOKEN_STRTOK
);
1494 while (tkn
.HasMoreTokens())
1496 fl
= tkn
.GetNextToken();
1497 index
= m_handler
->m_styleNames
.Index(fl
);
1498 if (index
!= wxNOT_FOUND
)
1500 style
|= m_handler
->m_styleValues
[index
];
1507 wxString::Format("unknown style flag \"%s\"", fl
)
1516 wxString
wxXmlResourceHandlerImpl::GetText(const wxString
& param
, bool translate
)
1518 wxXmlNode
*parNode
= GetParamNode(param
);
1519 wxString
str1(GetNodeContent(parNode
));
1522 // "\\" wasn't translated to "\" prior to 2.5.3.0:
1523 const bool escapeBackslash
= (m_handler
->m_resource
->CompareVersion(2,5,3,0) >= 0);
1525 // VS: First version of XRC resources used $ instead of & (which is
1526 // illegal in XML), but later I realized that '_' fits this purpose
1527 // much better (because &File means "File with F underlined").
1528 const wxChar amp_char
= (m_handler
->m_resource
->CompareVersion(2,3,0,1) < 0)
1531 for ( wxString::const_iterator dt
= str1
.begin(); dt
!= str1
.end(); ++dt
)
1533 // Remap amp_char to &, map double amp_char to amp_char (for things
1534 // like "&File..." -- this is illegal in XML, so we use "_File..."):
1535 if ( *dt
== amp_char
)
1537 if ( dt
+1 == str1
.end() || *(++dt
) == amp_char
)
1540 str2
<< wxT('&') << *dt
;
1542 // Remap \n to CR, \r to LF, \t to TAB, \\ to \:
1543 else if ( *dt
== wxT('\\') )
1545 switch ( (*(++dt
)).GetValue() )
1560 // "\\" wasn't translated to "\" prior to 2.5.3.0:
1561 if ( escapeBackslash
)
1566 // else fall-through to default: branch below
1569 str2
<< wxT('\\') << *dt
;
1579 if (m_handler
->m_resource
->GetFlags() & wxXRC_USE_LOCALE
)
1581 if (translate
&& parNode
&&
1582 parNode
->GetAttribute(wxT("translate"), wxEmptyString
) != wxT("0"))
1584 return wxGetTranslation(str2
, m_handler
->m_resource
->GetDomain());
1591 // The string is internally stored as UTF-8, we have to convert
1592 // it into system's default encoding so that it can be displayed:
1593 return wxString(str2
.wc_str(wxConvUTF8
), wxConvLocal
);
1598 // If wxXRC_USE_LOCALE is not set, then the string is already in
1599 // system's default encoding in ANSI build, so we don't have to
1600 // do anything special here.
1606 long wxXmlResourceHandlerImpl::GetLong(const wxString
& param
, long defaultv
)
1608 long value
= defaultv
;
1609 wxString str1
= GetParamValue(param
);
1613 if (!str1
.ToLong(&value
))
1618 wxString::Format("invalid long specification \"%s\"", str1
)
1626 float wxXmlResourceHandlerImpl::GetFloat(const wxString
& param
, float defaultv
)
1628 wxString str
= GetParamValue(param
);
1630 // strings in XRC always use C locale so make sure to use the
1631 // locale-independent wxString::ToCDouble() and not ToDouble() which uses
1632 // the current locale with a potentially different decimal point character
1633 double value
= defaultv
;
1636 if (!str
.ToCDouble(&value
))
1641 wxString::Format("invalid float specification \"%s\"", str
)
1646 return wx_truncate_cast(float, value
);
1650 int wxXmlResourceHandlerImpl::GetID()
1652 return wxXmlResource::GetXRCID(GetName());
1657 wxString
wxXmlResourceHandlerImpl::GetName()
1659 return m_handler
->m_node
->GetAttribute(wxT("name"), wxT("-1"));
1664 bool wxXmlResourceHandlerImpl::GetBoolAttr(const wxString
& attr
, bool defaultv
)
1667 return m_handler
->m_node
->GetAttribute(attr
, &v
) ? v
== '1' : defaultv
;
1670 bool wxXmlResourceHandlerImpl::GetBool(const wxString
& param
, bool defaultv
)
1672 const wxString v
= GetParamValue(param
);
1674 return v
.empty() ? defaultv
: (v
== '1');
1678 static wxColour
GetSystemColour(const wxString
& name
)
1682 #define SYSCLR(clr) \
1683 if (name == wxT(#clr)) return wxSystemSettings::GetColour(clr);
1684 SYSCLR(wxSYS_COLOUR_SCROLLBAR
)
1685 SYSCLR(wxSYS_COLOUR_BACKGROUND
)
1686 SYSCLR(wxSYS_COLOUR_DESKTOP
)
1687 SYSCLR(wxSYS_COLOUR_ACTIVECAPTION
)
1688 SYSCLR(wxSYS_COLOUR_INACTIVECAPTION
)
1689 SYSCLR(wxSYS_COLOUR_MENU
)
1690 SYSCLR(wxSYS_COLOUR_WINDOW
)
1691 SYSCLR(wxSYS_COLOUR_WINDOWFRAME
)
1692 SYSCLR(wxSYS_COLOUR_MENUTEXT
)
1693 SYSCLR(wxSYS_COLOUR_WINDOWTEXT
)
1694 SYSCLR(wxSYS_COLOUR_CAPTIONTEXT
)
1695 SYSCLR(wxSYS_COLOUR_ACTIVEBORDER
)
1696 SYSCLR(wxSYS_COLOUR_INACTIVEBORDER
)
1697 SYSCLR(wxSYS_COLOUR_APPWORKSPACE
)
1698 SYSCLR(wxSYS_COLOUR_HIGHLIGHT
)
1699 SYSCLR(wxSYS_COLOUR_HIGHLIGHTTEXT
)
1700 SYSCLR(wxSYS_COLOUR_BTNFACE
)
1701 SYSCLR(wxSYS_COLOUR_3DFACE
)
1702 SYSCLR(wxSYS_COLOUR_BTNSHADOW
)
1703 SYSCLR(wxSYS_COLOUR_3DSHADOW
)
1704 SYSCLR(wxSYS_COLOUR_GRAYTEXT
)
1705 SYSCLR(wxSYS_COLOUR_BTNTEXT
)
1706 SYSCLR(wxSYS_COLOUR_INACTIVECAPTIONTEXT
)
1707 SYSCLR(wxSYS_COLOUR_BTNHIGHLIGHT
)
1708 SYSCLR(wxSYS_COLOUR_BTNHILIGHT
)
1709 SYSCLR(wxSYS_COLOUR_3DHIGHLIGHT
)
1710 SYSCLR(wxSYS_COLOUR_3DHILIGHT
)
1711 SYSCLR(wxSYS_COLOUR_3DDKSHADOW
)
1712 SYSCLR(wxSYS_COLOUR_3DLIGHT
)
1713 SYSCLR(wxSYS_COLOUR_INFOTEXT
)
1714 SYSCLR(wxSYS_COLOUR_INFOBK
)
1715 SYSCLR(wxSYS_COLOUR_LISTBOX
)
1716 SYSCLR(wxSYS_COLOUR_HOTLIGHT
)
1717 SYSCLR(wxSYS_COLOUR_GRADIENTACTIVECAPTION
)
1718 SYSCLR(wxSYS_COLOUR_GRADIENTINACTIVECAPTION
)
1719 SYSCLR(wxSYS_COLOUR_MENUHILIGHT
)
1720 SYSCLR(wxSYS_COLOUR_MENUBAR
)
1724 return wxNullColour
;
1727 wxColour
wxXmlResourceHandlerImpl::GetColour(const wxString
& param
, const wxColour
& defaultv
)
1729 wxString v
= GetParamValue(param
);
1736 // wxString -> wxColour conversion
1739 // the colour doesn't use #RRGGBB format, check if it is symbolic
1741 clr
= GetSystemColour(v
);
1748 wxString::Format("incorrect colour specification \"%s\"", v
)
1750 return wxNullColour
;
1759 // if 'param' has stock_id/stock_client, extracts them and returns true
1760 bool GetStockArtAttrs(const wxXmlNode
*paramNode
,
1761 const wxString
& defaultArtClient
,
1762 wxString
& art_id
, wxString
& art_client
)
1766 art_id
= paramNode
->GetAttribute("stock_id", "");
1768 if ( !art_id
.empty() )
1770 art_id
= wxART_MAKE_ART_ID_FROM_STR(art_id
);
1772 art_client
= paramNode
->GetAttribute("stock_client", "");
1773 if ( art_client
.empty() )
1774 art_client
= defaultArtClient
;
1776 art_client
= wxART_MAKE_CLIENT_ID_FROM_STR(art_client
);
1785 } // anonymous namespace
1787 wxBitmap
wxXmlResourceHandlerImpl::GetBitmap(const wxString
& param
,
1788 const wxArtClient
& defaultArtClient
,
1791 // it used to be possible to pass an empty string here to indicate that the
1792 // bitmap name should be read from this node itself but this is not
1793 // supported any more because GetBitmap(m_node) can be used directly
1795 wxASSERT_MSG( !param
.empty(), "bitmap parameter name can't be empty" );
1797 const wxXmlNode
* const node
= GetParamNode(param
);
1801 // this is not an error as bitmap parameter could be optional
1802 return wxNullBitmap
;
1805 return GetBitmap(node
, defaultArtClient
, size
);
1808 wxBitmap
wxXmlResourceHandlerImpl::GetBitmap(const wxXmlNode
* node
,
1809 const wxArtClient
& defaultArtClient
,
1812 wxCHECK_MSG( node
, wxNullBitmap
, "bitmap node can't be NULL" );
1814 /* If the bitmap is specified as stock item, query wxArtProvider for it: */
1815 wxString art_id
, art_client
;
1816 if ( GetStockArtAttrs(node
, defaultArtClient
,
1817 art_id
, art_client
) )
1819 wxBitmap
stockArt(wxArtProvider::GetBitmap(art_id
, art_client
, size
));
1820 if ( stockArt
.IsOk() )
1824 /* ...or load the bitmap from file: */
1825 wxString name
= GetParamValue(node
);
1826 if (name
.empty()) return wxNullBitmap
;
1827 #if wxUSE_FILESYSTEM
1828 wxFSFile
*fsfile
= GetCurFileSystem().OpenFile(name
, wxFS_READ
| wxFS_SEEKABLE
);
1834 wxString::Format("cannot open bitmap resource \"%s\"", name
)
1836 return wxNullBitmap
;
1838 wxImage
img(*(fsfile
->GetStream()));
1849 wxString::Format("cannot create bitmap from \"%s\"", name
)
1851 return wxNullBitmap
;
1853 if (!(size
== wxDefaultSize
)) img
.Rescale(size
.x
, size
.y
);
1854 return wxBitmap(img
);
1858 wxIcon
wxXmlResourceHandlerImpl::GetIcon(const wxString
& param
,
1859 const wxArtClient
& defaultArtClient
,
1862 // see comment in GetBitmap(wxString) overload
1863 wxASSERT_MSG( !param
.empty(), "icon parameter name can't be empty" );
1865 const wxXmlNode
* const node
= GetParamNode(param
);
1869 // this is not an error as icon parameter could be optional
1873 return GetIcon(node
, defaultArtClient
, size
);
1876 wxIcon
wxXmlResourceHandlerImpl::GetIcon(const wxXmlNode
* node
,
1877 const wxArtClient
& defaultArtClient
,
1881 icon
.CopyFromBitmap(GetBitmap(node
, defaultArtClient
, size
));
1886 wxIconBundle
wxXmlResourceHandlerImpl::GetIconBundle(const wxString
& param
,
1887 const wxArtClient
& defaultArtClient
)
1889 wxString art_id
, art_client
;
1890 if ( GetStockArtAttrs(GetParamNode(param
), defaultArtClient
,
1891 art_id
, art_client
) )
1893 wxIconBundle
stockArt(wxArtProvider::GetIconBundle(art_id
, art_client
));
1894 if ( stockArt
.IsOk() )
1898 const wxString name
= GetParamValue(param
);
1900 return wxNullIconBundle
;
1902 #if wxUSE_FILESYSTEM
1903 wxFSFile
*fsfile
= GetCurFileSystem().OpenFile(name
, wxFS_READ
| wxFS_SEEKABLE
);
1904 if ( fsfile
== NULL
)
1909 wxString::Format("cannot open icon resource \"%s\"", name
)
1911 return wxNullIconBundle
;
1914 wxIconBundle
bundle(*(fsfile
->GetStream()));
1917 wxIconBundle
bundle(name
);
1920 if ( !bundle
.IsOk() )
1925 wxString::Format("cannot create icon from \"%s\"", name
)
1927 return wxNullIconBundle
;
1934 wxImageList
*wxXmlResourceHandlerImpl::GetImageList(const wxString
& param
)
1936 wxXmlNode
* const imagelist_node
= GetParamNode(param
);
1937 if ( !imagelist_node
)
1940 wxXmlNode
* const oldnode
= m_handler
->m_node
;
1941 m_handler
->m_node
= imagelist_node
;
1943 // Get the size if we have it, otherwise we will use the size of the first
1945 wxSize size
= GetSize();
1947 // Start adding images, we'll create the image list when adding the first
1949 wxImageList
* imagelist
= NULL
;
1950 wxString parambitmap
= wxT("bitmap");
1951 if ( HasParam(parambitmap
) )
1953 wxXmlNode
*n
= m_handler
->m_node
->GetChildren();
1956 if (n
->GetType() == wxXML_ELEMENT_NODE
&& n
->GetName() == parambitmap
)
1958 wxIcon icon
= GetIcon(n
, wxART_OTHER
, size
);
1961 // We need the real image list size to create it.
1962 if ( size
== wxDefaultSize
)
1963 size
= icon
.GetSize();
1965 // We use the mask by default.
1966 bool mask
= !HasParam(wxS("mask")) || GetBool(wxS("mask"));
1968 imagelist
= new wxImageList(size
.x
, size
.y
, mask
);
1971 // add icon instead of bitmap to keep the bitmap mask
1972 imagelist
->Add(icon
);
1978 m_handler
->m_node
= oldnode
;
1982 wxXmlNode
*wxXmlResourceHandlerImpl::GetParamNode(const wxString
& param
)
1984 wxCHECK_MSG(m_handler
->m_node
, NULL
, wxT("You can't access handler data before it was initialized!"));
1986 wxXmlNode
*n
= m_handler
->m_node
->GetChildren();
1990 if (n
->GetType() == wxXML_ELEMENT_NODE
&& n
->GetName() == param
)
1992 // TODO: check that there are no other properties/parameters with
1993 // the same name and log an error if there are (can't do this
1994 // right now as I'm not sure if it's not going to break code
1995 // using this function in unintentional way (i.e. for
1996 // accessing other things than properties), for example
1997 // wxBitmapComboBoxXmlHandler almost surely does
2005 bool wxXmlResourceHandlerImpl::IsOfClass(wxXmlNode
*node
, const wxString
& classname
) const
2007 return node
->GetAttribute(wxT("class")) == classname
;
2012 wxString
wxXmlResourceHandlerImpl::GetNodeContent(const wxXmlNode
*node
)
2014 const wxXmlNode
*n
= node
;
2015 if (n
== NULL
) return wxEmptyString
;
2016 n
= n
->GetChildren();
2020 if (n
->GetType() == wxXML_TEXT_NODE
||
2021 n
->GetType() == wxXML_CDATA_SECTION_NODE
)
2022 return n
->GetContent();
2025 return wxEmptyString
;
2030 wxString
wxXmlResourceHandlerImpl::GetParamValue(const wxString
& param
)
2033 return GetNodeContent(m_handler
->m_node
);
2035 return GetNodeContent(GetParamNode(param
));
2038 wxString
wxXmlResourceHandlerImpl::GetParamValue(const wxXmlNode
* node
)
2040 return GetNodeContent(node
);
2044 wxSize
wxXmlResourceHandlerImpl::GetSize(const wxString
& param
,
2045 wxWindow
*windowToUse
)
2047 wxString s
= GetParamValue(param
);
2048 if (s
.empty()) s
= wxT("-1,-1");
2052 is_dlg
= s
[s
.length()-1] == wxT('d');
2053 if (is_dlg
) s
.RemoveLast();
2055 if (!s
.BeforeFirst(wxT(',')).ToLong(&sx
) ||
2056 !s
.AfterLast(wxT(',')).ToLong(&sy
))
2061 wxString::Format("cannot parse coordinates value \"%s\"", s
)
2063 return wxDefaultSize
;
2070 return wxDLG_UNIT(windowToUse
, wxSize(sx
, sy
));
2072 else if (m_handler
->m_parentAsWindow
)
2074 return wxDLG_UNIT(m_handler
->m_parentAsWindow
, wxSize(sx
, sy
));
2081 "cannot convert dialog units: dialog unknown"
2083 return wxDefaultSize
;
2087 return wxSize(sx
, sy
);
2092 wxPoint
wxXmlResourceHandlerImpl::GetPosition(const wxString
& param
)
2094 wxSize sz
= GetSize(param
);
2095 return wxPoint(sz
.x
, sz
.y
);
2100 wxCoord
wxXmlResourceHandlerImpl::GetDimension(const wxString
& param
,
2102 wxWindow
*windowToUse
)
2104 wxString s
= GetParamValue(param
);
2105 if (s
.empty()) return defaultv
;
2109 is_dlg
= s
[s
.length()-1] == wxT('d');
2110 if (is_dlg
) s
.RemoveLast();
2117 wxString::Format("cannot parse dimension value \"%s\"", s
)
2126 return wxDLG_UNIT(windowToUse
, wxSize(sx
, 0)).x
;
2128 else if (m_handler
->m_parentAsWindow
)
2130 return wxDLG_UNIT(m_handler
->m_parentAsWindow
, wxSize(sx
, 0)).x
;
2137 "cannot convert dialog units: dialog unknown"
2147 wxXmlResourceHandlerImpl::GetDirection(const wxString
& param
, wxDirection dirDefault
)
2151 const wxString dirstr
= GetParamValue(param
);
2152 if ( dirstr
.empty() )
2154 else if ( dirstr
== "wxLEFT" )
2156 else if ( dirstr
== "wxRIGHT" )
2158 else if ( dirstr
== "wxTOP" )
2160 else if ( dirstr
== "wxBOTTOM" )
2166 GetParamNode(param
),
2169 "Invalid direction \"%s\": must be one of "
2170 "wxLEFT|wxRIGHT|wxTOP|wxBOTTOM.",
2181 // Get system font index using indexname
2182 static wxFont
GetSystemFont(const wxString
& name
)
2186 #define SYSFNT(fnt) \
2187 if (name == wxT(#fnt)) return wxSystemSettings::GetFont(fnt);
2188 SYSFNT(wxSYS_OEM_FIXED_FONT
)
2189 SYSFNT(wxSYS_ANSI_FIXED_FONT
)
2190 SYSFNT(wxSYS_ANSI_VAR_FONT
)
2191 SYSFNT(wxSYS_SYSTEM_FONT
)
2192 SYSFNT(wxSYS_DEVICE_DEFAULT_FONT
)
2193 SYSFNT(wxSYS_SYSTEM_FIXED_FONT
)
2194 SYSFNT(wxSYS_DEFAULT_GUI_FONT
)
2201 wxFont
wxXmlResourceHandlerImpl::GetFont(const wxString
& param
, wxWindow
* parent
)
2203 wxXmlNode
*font_node
= GetParamNode(param
);
2204 if (font_node
== NULL
)
2207 wxString::Format("cannot find font node \"%s\"", param
));
2211 wxXmlNode
*oldnode
= m_handler
->m_node
;
2212 m_handler
->m_node
= font_node
;
2218 bool hasSize
= HasParam(wxT("size"));
2220 isize
= GetLong(wxT("size"), -1);
2223 int istyle
= wxNORMAL
;
2224 bool hasStyle
= HasParam(wxT("style"));
2227 wxString style
= GetParamValue(wxT("style"));
2228 if (style
== wxT("italic"))
2230 else if (style
== wxT("slant"))
2232 else if (style
!= wxT("normal"))
2237 wxString::Format("unknown font style \"%s\"", style
)
2243 int iweight
= wxNORMAL
;
2244 bool hasWeight
= HasParam(wxT("weight"));
2247 wxString weight
= GetParamValue(wxT("weight"));
2248 if (weight
== wxT("bold"))
2250 else if (weight
== wxT("light"))
2252 else if (weight
!= wxT("normal"))
2257 wxString::Format("unknown font weight \"%s\"", weight
)
2263 bool hasUnderlined
= HasParam(wxT("underlined"));
2264 bool underlined
= hasUnderlined
? GetBool(wxT("underlined"), false) : false;
2266 // family and facename
2267 int ifamily
= wxDEFAULT
;
2268 bool hasFamily
= HasParam(wxT("family"));
2271 wxString family
= GetParamValue(wxT("family"));
2272 if (family
== wxT("decorative")) ifamily
= wxDECORATIVE
;
2273 else if (family
== wxT("roman")) ifamily
= wxROMAN
;
2274 else if (family
== wxT("script")) ifamily
= wxSCRIPT
;
2275 else if (family
== wxT("swiss")) ifamily
= wxSWISS
;
2276 else if (family
== wxT("modern")) ifamily
= wxMODERN
;
2277 else if (family
== wxT("teletype")) ifamily
= wxTELETYPE
;
2283 wxString::Format("unknown font family \"%s\"", family
)
2290 bool hasFacename
= HasParam(wxT("face"));
2293 wxString faces
= GetParamValue(wxT("face"));
2294 wxStringTokenizer
tk(faces
, wxT(","));
2296 wxArrayString
facenames(wxFontEnumerator::GetFacenames());
2297 while (tk
.HasMoreTokens())
2299 int index
= facenames
.Index(tk
.GetNextToken(), false);
2300 if (index
!= wxNOT_FOUND
)
2302 facename
= facenames
[index
];
2306 #else // !wxUSE_FONTENUM
2307 // just use the first face name if we can't check its availability:
2308 if (tk
.HasMoreTokens())
2309 facename
= tk
.GetNextToken();
2310 #endif // wxUSE_FONTENUM/!wxUSE_FONTENUM
2314 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
2315 bool hasEncoding
= HasParam(wxT("encoding"));
2319 wxString encoding
= GetParamValue(wxT("encoding"));
2320 wxFontMapper mapper
;
2321 if (!encoding
.empty())
2322 enc
= mapper
.CharsetToEncoding(encoding
);
2323 if (enc
== wxFONTENCODING_SYSTEM
)
2324 enc
= wxFONTENCODING_DEFAULT
;
2326 #endif // wxUSE_FONTMAP
2330 // is this font based on a system font?
2331 if (HasParam(wxT("sysfont")))
2333 font
= GetSystemFont(GetParamValue(wxT("sysfont")));
2334 if (HasParam(wxT("inherit")))
2339 "double specification of \"sysfont\" and \"inherit\""
2343 // or should the font of the widget be used?
2344 else if (GetBool(wxT("inherit"), false))
2347 font
= parent
->GetFont();
2353 "no parent window specified to derive the font from"
2360 if (hasSize
&& isize
!= -1)
2362 font
.SetPointSize(isize
);
2363 if (HasParam(wxT("relativesize")))
2368 "double specification of \"size\" and \"relativesize\""
2372 else if (HasParam(wxT("relativesize")))
2373 font
.SetPointSize(int(font
.GetPointSize() *
2374 GetFloat(wxT("relativesize"))));
2377 font
.SetStyle(istyle
);
2379 font
.SetWeight(iweight
);
2381 font
.SetUnderlined(underlined
);
2383 font
.SetFamily(ifamily
);
2385 font
.SetFaceName(facename
);
2387 font
.SetDefaultEncoding(enc
);
2389 else // not based on system font
2391 font
= wxFont(isize
== -1 ? wxNORMAL_FONT
->GetPointSize() : isize
,
2392 ifamily
, istyle
, iweight
,
2393 underlined
, facename
, enc
);
2396 m_handler
->m_node
= oldnode
;
2401 void wxXmlResourceHandlerImpl::SetupWindow(wxWindow
*wnd
)
2403 //FIXME : add cursor
2405 if (HasParam(wxT("exstyle")))
2406 // Have to OR it with existing style, since
2407 // some implementations (e.g. wxGTK) use the extra style
2409 wnd
->SetExtraStyle(wnd
->GetExtraStyle() | GetStyle(wxT("exstyle")));
2410 if (HasParam(wxT("bg")))
2411 wnd
->SetBackgroundColour(GetColour(wxT("bg")));
2412 if (HasParam(wxT("ownbg")))
2413 wnd
->SetOwnBackgroundColour(GetColour(wxT("ownbg")));
2414 if (HasParam(wxT("fg")))
2415 wnd
->SetForegroundColour(GetColour(wxT("fg")));
2416 if (HasParam(wxT("ownfg")))
2417 wnd
->SetOwnForegroundColour(GetColour(wxT("ownfg")));
2418 if (GetBool(wxT("enabled"), 1) == 0)
2420 if (GetBool(wxT("focused"), 0) == 1)
2422 if (GetBool(wxT("hidden"), 0) == 1)
2425 if (HasParam(wxT("tooltip")))
2426 wnd
->SetToolTip(GetText(wxT("tooltip")));
2428 if (HasParam(wxT("font")))
2429 wnd
->SetFont(GetFont(wxT("font"), wnd
));
2430 if (HasParam(wxT("ownfont")))
2431 wnd
->SetOwnFont(GetFont(wxT("ownfont"), wnd
));
2432 if (HasParam(wxT("help")))
2433 wnd
->SetHelpText(GetText(wxT("help")));
2437 void wxXmlResourceHandlerImpl::CreateChildren(wxObject
*parent
, bool this_hnd_only
)
2439 for ( wxXmlNode
*n
= m_handler
->m_node
->GetChildren(); n
; n
= n
->GetNext() )
2441 if ( IsObjectNode(n
) )
2443 m_handler
->m_resource
->DoCreateResFromNode(*n
, parent
, NULL
,
2444 this_hnd_only
? this->GetHandler() : NULL
);
2450 void wxXmlResourceHandlerImpl::CreateChildrenPrivately(wxObject
*parent
, wxXmlNode
*rootnode
)
2453 if (rootnode
== NULL
) root
= m_handler
->m_node
; else root
= rootnode
;
2454 wxXmlNode
*n
= root
->GetChildren();
2458 if (n
->GetType() == wxXML_ELEMENT_NODE
&& GetHandler()->CanHandle(n
))
2460 CreateResource(n
, parent
, NULL
);
2467 //-----------------------------------------------------------------------------
2469 //-----------------------------------------------------------------------------
2471 void wxXmlResourceHandlerImpl::ReportError(const wxString
& message
)
2473 m_handler
->m_resource
->ReportError(m_handler
->m_node
, message
);
2476 void wxXmlResourceHandlerImpl::ReportError(wxXmlNode
*context
,
2477 const wxString
& message
)
2479 m_handler
->m_resource
->ReportError(context
? context
: m_handler
->m_node
, message
);
2482 void wxXmlResourceHandlerImpl::ReportParamError(const wxString
& param
,
2483 const wxString
& message
)
2485 m_handler
->m_resource
->ReportError(GetParamNode(param
), message
);
2488 void wxXmlResource::ReportError(const wxXmlNode
*context
, const wxString
& message
)
2492 DoReportError("", NULL
, message
);
2496 // We need to find out the file that 'context' is part of. Performance of
2497 // this code is not critical, so we simply find the root XML node and
2498 // compare it with all loaded XRC files.
2499 const wxString filename
= GetFileNameFromNode(context
, Data());
2501 DoReportError(filename
, context
, message
);
2504 void wxXmlResource::DoReportError(const wxString
& xrcFile
, const wxXmlNode
*position
,
2505 const wxString
& message
)
2507 const int line
= position
? position
->GetLineNumber() : -1;
2510 if ( !xrcFile
.empty() )
2511 loc
= xrcFile
+ ':';
2513 loc
+= wxString::Format("%d:", line
);
2517 wxLogError("XRC error: %s%s", loc
, message
);
2521 //-----------------------------------------------------------------------------
2522 // XRCID implementation
2523 //-----------------------------------------------------------------------------
2525 #define XRCID_TABLE_SIZE 1024
2530 /* Hold the id so that once an id is allocated for a name, it
2531 does not get created again by NewControlId at least
2532 until we are done with it */
2538 static XRCID_record
*XRCID_Records
[XRCID_TABLE_SIZE
] = {NULL
};
2540 // Extremely simplistic hash function which probably ought to be replaced with
2541 // wxStringHash::stringHash().
2542 static inline unsigned XRCIdHash(const char *str_id
)
2546 for (const char *c
= str_id
; *c
!= '\0'; c
++) index
+= (unsigned int)*c
;
2547 index
%= XRCID_TABLE_SIZE
;
2552 static void XRCID_Assign(const wxString
& str_id
, int value
)
2554 const wxCharBuffer
buf_id(str_id
.mb_str());
2555 const unsigned index
= XRCIdHash(buf_id
);
2558 XRCID_record
*oldrec
= NULL
;
2559 for (XRCID_record
*rec
= XRCID_Records
[index
]; rec
; rec
= rec
->next
)
2561 if (wxStrcmp(rec
->key
, buf_id
) == 0)
2569 XRCID_record
**rec_var
= (oldrec
== NULL
) ?
2570 &XRCID_Records
[index
] : &oldrec
->next
;
2571 *rec_var
= new XRCID_record
;
2572 (*rec_var
)->key
= wxStrdup(str_id
);
2573 (*rec_var
)->id
= value
;
2574 (*rec_var
)->next
= NULL
;
2577 static int XRCID_Lookup(const char *str_id
, int value_if_not_found
= wxID_NONE
)
2579 const unsigned index
= XRCIdHash(str_id
);
2582 XRCID_record
*oldrec
= NULL
;
2583 for (XRCID_record
*rec
= XRCID_Records
[index
]; rec
; rec
= rec
->next
)
2585 if (wxStrcmp(rec
->key
, str_id
) == 0)
2592 XRCID_record
**rec_var
= (oldrec
== NULL
) ?
2593 &XRCID_Records
[index
] : &oldrec
->next
;
2594 *rec_var
= new XRCID_record
;
2595 (*rec_var
)->key
= wxStrdup(str_id
);
2596 (*rec_var
)->next
= NULL
;
2599 if (value_if_not_found
!= wxID_NONE
)
2600 (*rec_var
)->id
= value_if_not_found
;
2603 int asint
= wxStrtol(str_id
, &end
, 10);
2604 if (*str_id
&& *end
== 0)
2606 // if str_id was integer, keep it verbosely:
2607 (*rec_var
)->id
= asint
;
2611 (*rec_var
)->id
= wxWindowBase::NewControlId();
2615 return (*rec_var
)->id
;
2621 // flag indicating whether standard XRC ids were already initialized
2622 static bool gs_stdIDsAdded
= false;
2624 void AddStdXRCID_Records()
2626 #define stdID(id) XRCID_Lookup(#id, id)
2630 stdID(wxID_SEPARATOR
);
2643 stdID(wxID_PRINT_SETUP
);
2644 stdID(wxID_PAGE_SETUP
);
2645 stdID(wxID_PREVIEW
);
2647 stdID(wxID_HELP_CONTENTS
);
2648 stdID(wxID_HELP_INDEX
),
2649 stdID(wxID_HELP_SEARCH
),
2650 stdID(wxID_HELP_COMMANDS
);
2651 stdID(wxID_HELP_PROCEDURES
);
2652 stdID(wxID_HELP_CONTEXT
);
2653 stdID(wxID_CLOSE_ALL
);
2654 stdID(wxID_PREFERENCES
);
2662 stdID(wxID_DUPLICATE
);
2663 stdID(wxID_SELECTALL
);
2665 stdID(wxID_REPLACE
);
2666 stdID(wxID_REPLACE_ALL
);
2667 stdID(wxID_PROPERTIES
);
2669 stdID(wxID_VIEW_DETAILS
);
2670 stdID(wxID_VIEW_LARGEICONS
);
2671 stdID(wxID_VIEW_SMALLICONS
);
2672 stdID(wxID_VIEW_LIST
);
2673 stdID(wxID_VIEW_SORTDATE
);
2674 stdID(wxID_VIEW_SORTNAME
);
2675 stdID(wxID_VIEW_SORTSIZE
);
2676 stdID(wxID_VIEW_SORTTYPE
);
2696 stdID(wxID_FORWARD
);
2697 stdID(wxID_BACKWARD
);
2698 stdID(wxID_DEFAULT
);
2702 stdID(wxID_CONTEXT_HELP
);
2703 stdID(wxID_YESTOALL
);
2704 stdID(wxID_NOTOALL
);
2714 stdID(wxID_REFRESH
);
2720 stdID(wxID_JUSTIFY_CENTER
);
2721 stdID(wxID_JUSTIFY_FILL
);
2722 stdID(wxID_JUSTIFY_RIGHT
);
2723 stdID(wxID_JUSTIFY_LEFT
);
2724 stdID(wxID_UNDERLINE
);
2726 stdID(wxID_UNINDENT
);
2727 stdID(wxID_ZOOM_100
);
2728 stdID(wxID_ZOOM_FIT
);
2729 stdID(wxID_ZOOM_IN
);
2730 stdID(wxID_ZOOM_OUT
);
2731 stdID(wxID_UNDELETE
);
2732 stdID(wxID_REVERT_TO_SAVED
);
2734 stdID(wxID_CONVERT
);
2735 stdID(wxID_EXECUTE
);
2737 stdID(wxID_HARDDISK
);
2743 stdID(wxID_JUMP_TO
);
2744 stdID(wxID_NETWORK
);
2745 stdID(wxID_SELECT_COLOR
);
2746 stdID(wxID_SELECT_FONT
);
2747 stdID(wxID_SORT_ASCENDING
);
2748 stdID(wxID_SORT_DESCENDING
);
2749 stdID(wxID_SPELL_CHECK
);
2750 stdID(wxID_STRIKETHROUGH
);
2753 stdID(wxID_SYSTEM_MENU
);
2754 stdID(wxID_CLOSE_FRAME
);
2755 stdID(wxID_MOVE_FRAME
);
2756 stdID(wxID_RESIZE_FRAME
);
2757 stdID(wxID_MAXIMIZE_FRAME
);
2758 stdID(wxID_ICONIZE_FRAME
);
2759 stdID(wxID_RESTORE_FRAME
);
2763 stdID(wxID_MDI_WINDOW_CASCADE
);
2764 stdID(wxID_MDI_WINDOW_TILE_HORZ
);
2765 stdID(wxID_MDI_WINDOW_TILE_VERT
);
2766 stdID(wxID_MDI_WINDOW_ARRANGE_ICONS
);
2767 stdID(wxID_MDI_WINDOW_PREV
);
2768 stdID(wxID_MDI_WINDOW_NEXT
);
2772 } // anonymous namespace
2776 int wxXmlResource::DoGetXRCID(const char *str_id
, int value_if_not_found
)
2778 if ( !gs_stdIDsAdded
)
2780 gs_stdIDsAdded
= true;
2781 AddStdXRCID_Records();
2784 return XRCID_Lookup(str_id
, value_if_not_found
);
2788 wxString
wxXmlResource::FindXRCIDById(int numId
)
2790 for ( int i
= 0; i
< XRCID_TABLE_SIZE
; i
++ )
2792 for ( XRCID_record
*rec
= XRCID_Records
[i
]; rec
; rec
= rec
->next
)
2794 if ( rec
->id
== numId
)
2795 return wxString(rec
->key
);
2802 static void CleanXRCID_Record(XRCID_record
*rec
)
2806 CleanXRCID_Record(rec
->next
);
2813 static void CleanXRCID_Records()
2815 for (int i
= 0; i
< XRCID_TABLE_SIZE
; i
++)
2817 CleanXRCID_Record(XRCID_Records
[i
]);
2818 XRCID_Records
[i
] = NULL
;
2821 gs_stdIDsAdded
= false;
2825 //-----------------------------------------------------------------------------
2826 // module and globals
2827 //-----------------------------------------------------------------------------
2829 // normally we would do the cleanup from wxXmlResourceModule::OnExit() but it
2830 // can happen that some XRC records have been created because of the use of
2831 // XRCID() in event tables, which happens during static objects initialization,
2832 // but then the application initialization failed and so the wx modules were
2833 // neither initialized nor cleaned up -- this static object does the cleanup in
2835 static struct wxXRCStaticCleanup
2837 ~wxXRCStaticCleanup() { CleanXRCID_Records(); }
2840 class wxXmlResourceModule
: public wxModule
2842 DECLARE_DYNAMIC_CLASS(wxXmlResourceModule
)
2844 wxXmlResourceModule() {}
2847 wxXmlResource::AddSubclassFactory(new wxXmlSubclassFactoryCXX
);
2852 delete wxXmlResource::Set(NULL
);
2853 delete wxIdRangeManager::Set(NULL
);
2854 if(wxXmlResource::ms_subclassFactories
)
2856 for ( wxXmlSubclassFactories::iterator i
= wxXmlResource::ms_subclassFactories
->begin();
2857 i
!= wxXmlResource::ms_subclassFactories
->end(); ++i
)
2861 wxDELETE(wxXmlResource::ms_subclassFactories
);
2863 CleanXRCID_Records();
2867 IMPLEMENT_DYNAMIC_CLASS(wxXmlResourceModule
, wxModule
)
2870 // When wxXml is loaded dynamically after the application is already running
2871 // then the built-in module system won't pick this one up. Add it manually.
2872 void wxXmlInitResourceModule()
2874 wxModule
* module = new wxXmlResourceModule
;
2876 wxModule::RegisterModule(module);