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 IMPLEMENT_ABSTRACT_CLASS(wxXmlResourceHandler
, wxObject
)
436 void wxXmlResource::AddHandler(wxXmlResourceHandler
*handler
)
438 m_handlers
.push_back(handler
);
439 handler
->SetParentResource(this);
442 void wxXmlResource::InsertHandler(wxXmlResourceHandler
*handler
)
444 m_handlers
.insert(m_handlers
.begin(), handler
);
445 handler
->SetParentResource(this);
450 void wxXmlResource::ClearHandlers()
452 for ( wxVector
<wxXmlResourceHandler
*>::iterator i
= m_handlers
.begin();
453 i
!= m_handlers
.end(); ++i
)
459 wxMenu
*wxXmlResource::LoadMenu(const wxString
& name
)
461 return (wxMenu
*)CreateResFromNode(FindResource(name
, wxT("wxMenu")), NULL
, NULL
);
466 wxMenuBar
*wxXmlResource::LoadMenuBar(wxWindow
*parent
, const wxString
& name
)
468 return (wxMenuBar
*)CreateResFromNode(FindResource(name
, wxT("wxMenuBar")), parent
, NULL
);
474 wxToolBar
*wxXmlResource::LoadToolBar(wxWindow
*parent
, const wxString
& name
)
476 return (wxToolBar
*)CreateResFromNode(FindResource(name
, wxT("wxToolBar")), parent
, NULL
);
481 wxDialog
*wxXmlResource::LoadDialog(wxWindow
*parent
, const wxString
& name
)
483 return (wxDialog
*)CreateResFromNode(FindResource(name
, wxT("wxDialog")), parent
, NULL
);
486 bool wxXmlResource::LoadDialog(wxDialog
*dlg
, wxWindow
*parent
, const wxString
& name
)
488 return CreateResFromNode(FindResource(name
, wxT("wxDialog")), parent
, dlg
) != NULL
;
493 wxPanel
*wxXmlResource::LoadPanel(wxWindow
*parent
, const wxString
& name
)
495 return (wxPanel
*)CreateResFromNode(FindResource(name
, wxT("wxPanel")), parent
, NULL
);
498 bool wxXmlResource::LoadPanel(wxPanel
*panel
, wxWindow
*parent
, const wxString
& name
)
500 return CreateResFromNode(FindResource(name
, wxT("wxPanel")), parent
, panel
) != NULL
;
503 wxFrame
*wxXmlResource::LoadFrame(wxWindow
* parent
, const wxString
& name
)
505 return (wxFrame
*)CreateResFromNode(FindResource(name
, wxT("wxFrame")), parent
, NULL
);
508 bool wxXmlResource::LoadFrame(wxFrame
* frame
, wxWindow
*parent
, const wxString
& name
)
510 return CreateResFromNode(FindResource(name
, wxT("wxFrame")), parent
, frame
) != NULL
;
513 wxBitmap
wxXmlResource::LoadBitmap(const wxString
& name
)
515 wxBitmap
*bmp
= (wxBitmap
*)CreateResFromNode(
516 FindResource(name
, wxT("wxBitmap")), NULL
, NULL
);
519 if (bmp
) { rt
= *bmp
; delete bmp
; }
523 wxIcon
wxXmlResource::LoadIcon(const wxString
& name
)
525 wxIcon
*icon
= (wxIcon
*)CreateResFromNode(
526 FindResource(name
, wxT("wxIcon")), NULL
, NULL
);
529 if (icon
) { rt
= *icon
; delete icon
; }
535 wxXmlResource::DoLoadObject(wxWindow
*parent
,
536 const wxString
& name
,
537 const wxString
& classname
,
540 wxXmlNode
* const node
= FindResource(name
, classname
, recursive
);
542 return node
? DoCreateResFromNode(*node
, parent
, NULL
) : NULL
;
546 wxXmlResource::DoLoadObject(wxObject
*instance
,
548 const wxString
& name
,
549 const wxString
& classname
,
552 wxXmlNode
* const node
= FindResource(name
, classname
, recursive
);
554 return node
&& DoCreateResFromNode(*node
, parent
, instance
) != NULL
;
558 bool wxXmlResource::AttachUnknownControl(const wxString
& name
,
559 wxWindow
*control
, wxWindow
*parent
)
562 parent
= control
->GetParent();
563 wxWindow
*container
= parent
->FindWindow(name
+ wxT("_container"));
566 wxLogError("Cannot find container for unknown control '%s'.", name
);
569 return control
->Reparent(container
);
573 static void ProcessPlatformProperty(wxXmlNode
*node
)
578 wxXmlNode
*c
= node
->GetChildren();
582 if (!c
->GetAttribute(wxT("platform"), &s
))
586 wxStringTokenizer
tkn(s
, wxT(" |"));
588 while (tkn
.HasMoreTokens())
590 s
= tkn
.GetNextToken();
592 if (s
== wxT("win")) isok
= true;
594 #if defined(__MAC__) || defined(__APPLE__)
595 if (s
== wxT("mac")) isok
= true;
596 #elif defined(__UNIX__)
597 if (s
== wxT("unix")) isok
= true;
600 if (s
== wxT("os2")) isok
= true;
610 ProcessPlatformProperty(c
);
615 wxXmlNode
*c2
= c
->GetNext();
616 node
->RemoveChild(c
);
623 static void PreprocessForIdRanges(wxXmlNode
*rootnode
)
625 // First go through the top level, looking for the names of ID ranges
626 // as processing items is a lot easier if names are already known
627 wxXmlNode
*c
= rootnode
->GetChildren();
630 if (c
->GetName() == wxT("ids-range"))
631 wxIdRangeManager::Get()->AddRange(c
);
635 // Next, examine every 'name' for the '[' that denotes an ID in a range
636 c
= rootnode
->GetChildren();
639 wxString name
= c
->GetAttribute(wxT("name"));
640 if (name
.find('[') != wxString::npos
)
641 wxIdRangeManager::Get()->NotifyRangeOfItem(rootnode
, name
);
643 // Do any children by recursion, then proceed to the next sibling
644 PreprocessForIdRanges(c
);
649 bool wxXmlResource::UpdateResources()
653 for ( wxXmlResourceDataRecords::iterator i
= Data().begin();
654 i
!= Data().end(); ++i
)
656 wxXmlResourceDataRecord
* const rec
= *i
;
658 // Check if we need to reload this one.
660 // We never do it if this flag is specified.
661 if ( m_flags
& wxXRC_NO_RELOADING
)
664 // Otherwise check its modification time if we can.
666 const wxDateTime lastModTime
= GetXRCFileModTime(rec
->File
);
668 if ( lastModTime
.IsValid() && lastModTime
<= rec
->Time
)
669 #else // !wxUSE_DATETIME
670 // Never reload the file contents: we can't know whether it changed or
671 // not in this build configuration and it would be unexpected and
672 // counter-productive to get a performance hit (due to constant
673 // reloading of XRC files) in a minimal wx build which is presumably
674 // used because of resource constraints of the current platform.
675 #endif // wxUSE_DATETIME/!wxUSE_DATETIME
677 // No need to reload, the file wasn't modified since we did it
682 wxXmlDocument
* const doc
= DoLoadFile(rec
->File
);
685 // Notice that we keep the old XML document: it seems better to
686 // preserve it instead of throwing it away if we have nothing to
692 // Replace the old resource contents with the new one.
696 // And, now that we loaded it successfully, update the last load time.
698 rec
->Time
= lastModTime
.IsValid() ? lastModTime
: wxDateTime::Now();
699 #endif // wxUSE_DATETIME
705 wxXmlDocument
*wxXmlResource::DoLoadFile(const wxString
& filename
)
707 wxLogTrace(wxT("xrc"), wxT("opening file '%s'"), filename
);
709 wxInputStream
*stream
= NULL
;
713 wxScopedPtr
<wxFSFile
> file(fsys
.OpenFile(filename
));
716 // Notice that we don't have ownership of the stream in this case, it
717 // remains owned by wxFSFile.
718 stream
= file
->GetStream();
720 #else // !wxUSE_FILESYSTEM
721 wxFileInputStream
fstream(filename
);
723 #endif // wxUSE_FILESYSTEM/!wxUSE_FILESYSTEM
725 if ( !stream
|| !stream
->IsOk() )
727 wxLogError(_("Cannot open resources file '%s'."), filename
);
731 wxString
encoding(wxT("UTF-8"));
732 #if !wxUSE_UNICODE && wxUSE_INTL
733 if ( (GetFlags() & wxXRC_USE_LOCALE
) == 0 )
735 // In case we are not using wxLocale to translate strings, convert the
736 // strings GUI's charset. This must not be done when wxXRC_USE_LOCALE
737 // is on, because it could break wxGetTranslation lookup.
738 encoding
= wxLocale::GetSystemEncodingName();
742 wxScopedPtr
<wxXmlDocument
> doc(new wxXmlDocument
);
743 if (!doc
->Load(*stream
, encoding
))
745 wxLogError(_("Cannot load resources from file '%s'."), filename
);
749 wxXmlNode
* const root
= doc
->GetRoot();
750 if (root
->GetName() != wxT("resource"))
755 "invalid XRC resource, doesn't have root node <resource>"
762 wxString verstr
= root
->GetAttribute(wxT("version"), wxT("0.0.0.0"));
763 if (wxSscanf(verstr
, wxT("%i.%i.%i.%i"), &v1
, &v2
, &v3
, &v4
) == 4)
764 version
= v1
*256*256*256+v2
*256*256+v3
*256+v4
;
769 if (m_version
!= version
)
771 wxLogWarning("Resource files must have same version number.");
774 ProcessPlatformProperty(root
);
775 PreprocessForIdRanges(root
);
776 wxIdRangeManager::Get()->FinaliseRanges(root
);
778 return doc
.release();
781 wxXmlNode
*wxXmlResource::DoFindResource(wxXmlNode
*parent
,
782 const wxString
& name
,
783 const wxString
& classname
,
784 bool recursive
) const
788 // first search for match at the top-level nodes (as this is
789 // where the resource is most commonly looked for):
790 for (node
= parent
->GetChildren(); node
; node
= node
->GetNext())
792 if ( IsObjectNode(node
) && node
->GetAttribute(wxS("name")) == name
)
794 // empty class name matches everything
795 if ( classname
.empty() )
798 wxString
cls(node
->GetAttribute(wxS("class")));
800 // object_ref may not have 'class' attribute:
801 if (cls
.empty() && node
->GetName() == wxS("object_ref"))
803 wxString refName
= node
->GetAttribute(wxS("ref"));
807 const wxXmlNode
* const refNode
= GetResourceNode(refName
);
809 cls
= refNode
->GetAttribute(wxS("class"));
812 if ( cls
== classname
)
817 // then recurse in child nodes
820 for (node
= parent
->GetChildren(); node
; node
= node
->GetNext())
822 if ( IsObjectNode(node
) )
824 wxXmlNode
* found
= DoFindResource(node
, name
, classname
, true);
834 wxXmlNode
*wxXmlResource::FindResource(const wxString
& name
,
835 const wxString
& classname
,
840 node
= GetResourceNodeAndLocation(name
, classname
, recursive
, &path
);
849 "XRC resource \"%s\" (class \"%s\") not found",
855 else // node was found
857 // ensure that relative paths work correctly when loading this node
858 // (which should happen as soon as we return as FindResource() result
859 // is always passed to CreateResFromNode())
860 m_curFileSystem
.ChangePathTo(path
);
862 #endif // wxUSE_FILESYSTEM
868 wxXmlResource::GetResourceNodeAndLocation(const wxString
& name
,
869 const wxString
& classname
,
871 wxString
*path
) const
873 // ensure everything is up-to-date: this is needed to support on-demand
874 // reloading of XRC files
875 const_cast<wxXmlResource
*>(this)->UpdateResources();
877 for ( wxXmlResourceDataRecords::const_iterator f
= Data().begin();
878 f
!= Data().end(); ++f
)
880 wxXmlResourceDataRecord
*const rec
= *f
;
881 wxXmlDocument
* const doc
= rec
->Doc
;
882 if ( !doc
|| !doc
->GetRoot() )
886 found
= DoFindResource(doc
->GetRoot(), name
, classname
, recursive
);
899 static void MergeNodesOver(wxXmlNode
& dest
, wxXmlNode
& overwriteWith
,
900 const wxString
& overwriteFilename
)
903 for ( wxXmlAttribute
*attr
= overwriteWith
.GetAttributes();
904 attr
; attr
= attr
->GetNext() )
906 wxXmlAttribute
*dattr
;
907 for (dattr
= dest
.GetAttributes(); dattr
; dattr
= dattr
->GetNext())
910 if ( dattr
->GetName() == attr
->GetName() )
912 dattr
->SetValue(attr
->GetValue());
918 dest
.AddAttribute(attr
->GetName(), attr
->GetValue());
921 // Merge child nodes:
922 for (wxXmlNode
* node
= overwriteWith
.GetChildren(); node
; node
= node
->GetNext())
924 wxString name
= node
->GetAttribute(wxT("name"), wxEmptyString
);
927 for (dnode
= dest
.GetChildren(); dnode
; dnode
= dnode
->GetNext() )
929 if ( dnode
->GetName() == node
->GetName() &&
930 dnode
->GetAttribute(wxT("name"), wxEmptyString
) == name
&&
931 dnode
->GetType() == node
->GetType() )
933 MergeNodesOver(*dnode
, *node
, overwriteFilename
);
940 wxXmlNode
*copyOfNode
= new wxXmlNode(*node
);
941 // remember referenced object's file, see GetFileNameFromNode()
942 copyOfNode
->AddAttribute(ATTR_INPUT_FILENAME
, overwriteFilename
);
944 static const wxChar
*AT_END
= wxT("end");
945 wxString insert_pos
= node
->GetAttribute(wxT("insert_at"), AT_END
);
946 if ( insert_pos
== AT_END
)
948 dest
.AddChild(copyOfNode
);
950 else if ( insert_pos
== wxT("begin") )
952 dest
.InsertChild(copyOfNode
, dest
.GetChildren());
957 if ( dest
.GetType() == wxXML_TEXT_NODE
&& overwriteWith
.GetContent().length() )
958 dest
.SetContent(overwriteWith
.GetContent());
962 wxXmlResource::DoCreateResFromNode(wxXmlNode
& node
,
965 wxXmlResourceHandler
*handlerToUse
)
967 // handling of referenced resource
968 if ( node
.GetName() == wxT("object_ref") )
970 wxString refName
= node
.GetAttribute(wxT("ref"), wxEmptyString
);
971 wxXmlNode
* refNode
= FindResource(refName
, wxEmptyString
, true);
980 "referenced object node with ref=\"%s\" not found",
987 const bool hasOnlyRefAttr
= node
.GetAttributes() != NULL
&&
988 node
.GetAttributes()->GetNext() == NULL
;
990 if ( hasOnlyRefAttr
&& !node
.GetChildren() )
992 // In the typical, simple case, <object_ref> is used to link
993 // to another node and doesn't have any content of its own that
994 // would overwrite linked object's properties. In this case,
995 // we can simply create the resource from linked node.
997 return DoCreateResFromNode(*refNode
, parent
, instance
);
1001 // In the more complicated (but rare) case, <object_ref> has
1002 // subnodes that partially overwrite content of the referenced
1003 // object. In this case, we need to merge both XML trees and
1004 // load the resource from result of the merge.
1006 wxXmlNode
copy(*refNode
);
1007 MergeNodesOver(copy
, node
, GetFileNameFromNode(&node
, Data()));
1009 // remember referenced object's file, see GetFileNameFromNode()
1010 copy
.AddAttribute(ATTR_INPUT_FILENAME
,
1011 GetFileNameFromNode(refNode
, Data()));
1013 return DoCreateResFromNode(copy
, parent
, instance
);
1019 if (handlerToUse
->CanHandle(&node
))
1021 return handlerToUse
->CreateResource(&node
, parent
, instance
);
1024 else if (node
.GetName() == wxT("object"))
1026 for ( wxVector
<wxXmlResourceHandler
*>::iterator h
= m_handlers
.begin();
1027 h
!= m_handlers
.end(); ++h
)
1029 wxXmlResourceHandler
*handler
= *h
;
1030 if (handler
->CanHandle(&node
))
1031 return handler
->CreateResource(&node
, parent
, instance
);
1040 "no handler found for XML node \"%s\" (class \"%s\")",
1042 node
.GetAttribute("class", wxEmptyString
)
1048 wxIdRange::wxIdRange(const wxXmlNode
* node
,
1049 const wxString
& rname
,
1050 const wxString
& startno
,
1051 const wxString
& rsize
)
1055 m_item_end_found(0),
1059 if ( startno
.ToLong(&l
) )
1067 wxXmlResource::Get()->ReportError
1070 "a negative id-range start parameter was given"
1076 wxXmlResource::Get()->ReportError
1079 "the id-range start parameter was malformed"
1084 if ( rsize
.ToULong(&ul
) )
1090 wxXmlResource::Get()->ReportError
1093 "the id-range size parameter was malformed"
1098 void wxIdRange::NoteItem(const wxXmlNode
* node
, const wxString
& item
)
1100 // Nothing gets added here, but the existence of each item is noted
1101 // thus getting an accurate count. 'item' will be either an integer e.g.
1102 // [0] [123]: will eventually create an XRCID as start+integer or [start]
1103 // or [end] which are synonyms for [0] or [range_size-1] respectively.
1104 wxString
content(item
.Mid(1, item
.length()-2));
1106 // Check that basename+item wasn't foo[]
1107 if (content
.empty())
1109 wxXmlResource::Get()->ReportError(node
, "an empty id-range item found");
1113 if (content
=="start")
1115 // "start" means [0], so store that in the set
1116 if (m_indices
.count(0) == 0)
1118 m_indices
.insert(0);
1122 wxXmlResource::Get()->ReportError
1125 "duplicate id-range item found"
1129 else if (content
=="end")
1131 // We can't yet be certain which XRCID this will be equivalent to, so
1132 // just note that there's an item with this name, in case we need to
1133 // inc the range size
1134 m_item_end_found
= true;
1138 // Anything else will be an integer, or rubbish
1140 if ( content
.ToULong(&l
) )
1142 if (m_indices
.count(l
) == 0)
1144 m_indices
.insert(l
);
1145 // Check that this item wouldn't fall outside the current range
1154 wxXmlResource::Get()->ReportError
1157 "duplicate id-range item found"
1164 wxXmlResource::Get()->ReportError
1167 "an id-range item had a malformed index"
1173 void wxIdRange::Finalise(const wxXmlNode
* node
)
1175 wxCHECK_RET( !IsFinalised(),
1176 "Trying to finalise an already-finalised range" );
1178 // Now we know about all the items, we can get an accurate range size
1179 // Expand any requested range-size if there were more items than would fit
1180 m_size
= wxMax(m_size
, m_indices
.size());
1182 // If an item is explicitly called foo[end], ensure it won't clash with
1184 if ( m_item_end_found
&& m_indices
.count(m_size
-1) )
1188 // This will happen if someone creates a range but no items in this xrc
1189 // file Report the error and abort, but don't finalise, in case items
1191 wxXmlResource::Get()->ReportError
1194 "trying to create an empty id-range"
1201 // This is the usual case, where the user didn't specify a start ID
1202 // So get the range using NewControlId().
1204 // NB: negative numbers, but NewControlId already returns the most
1206 m_start
= wxWindow::NewControlId(m_size
);
1207 wxCHECK_RET( m_start
!= wxID_NONE
,
1208 "insufficient IDs available to create range" );
1209 m_end
= m_start
+ m_size
- 1;
1213 // The user already specified a start value, which must be positive
1214 m_end
= m_start
+ m_size
- 1;
1217 // Create the XRCIDs
1218 for (int i
=m_start
; i
<= m_end
; ++i
)
1220 // Ensure that we overwrite any existing value as otherwise
1221 // wxXmlResource::Unload() followed by Load() wouldn't work correctly.
1222 XRCID_Assign(m_name
+ wxString::Format("[%i]", i
-m_start
), i
);
1224 wxLogTrace("xrcrange",
1225 "integer = %i %s now returns %i",
1227 m_name
+ wxString::Format("[%i]", i
-m_start
),
1228 XRCID((m_name
+ wxString::Format("[%i]", i
-m_start
)).mb_str()));
1230 // and these special ones
1231 XRCID_Assign(m_name
+ "[start]", m_start
);
1232 XRCID_Assign(m_name
+ "[end]", m_end
);
1233 wxLogTrace("xrcrange","%s[start] = %i %s[end] = %i",
1234 m_name
.mb_str(),XRCID(wxString(m_name
+"[start]").mb_str()),
1235 m_name
.mb_str(),XRCID(wxString(m_name
+"[end]").mb_str()));
1240 wxIdRangeManager
*wxIdRangeManager::ms_instance
= NULL
;
1242 /*static*/ wxIdRangeManager
*wxIdRangeManager::Get()
1245 ms_instance
= new wxIdRangeManager
;
1249 /*static*/ wxIdRangeManager
*wxIdRangeManager::Set(wxIdRangeManager
*res
)
1251 wxIdRangeManager
*old
= ms_instance
;
1256 wxIdRangeManager::~wxIdRangeManager()
1258 for ( wxVector
<wxIdRange
*>::iterator i
= m_IdRanges
.begin();
1259 i
!= m_IdRanges
.end(); ++i
)
1268 void wxIdRangeManager::AddRange(const wxXmlNode
* node
)
1270 wxString name
= node
->GetAttribute("name");
1271 wxString start
= node
->GetAttribute("start", "0");
1272 wxString size
= node
->GetAttribute("size", "0");
1275 wxXmlResource::Get()->ReportError
1278 "xrc file contains an id-range without a name"
1283 int index
= Find(name
);
1284 if (index
== wxNOT_FOUND
)
1286 wxLogTrace("xrcrange",
1287 "Adding ID range, name=%s start=%s size=%s",
1290 m_IdRanges
.push_back(new wxIdRange(node
, name
, start
, size
));
1294 // There was already a range with this name. Let's hope this is
1295 // from an Unload()/(re)Load(), not an unintentional duplication
1296 wxLogTrace("xrcrange",
1297 "Replacing ID range, name=%s start=%s size=%s",
1300 wxIdRange
* oldrange
= m_IdRanges
.at(index
);
1301 m_IdRanges
.at(index
) = new wxIdRange(node
, name
, start
, size
);
1307 wxIdRangeManager::FindRangeForItem(const wxXmlNode
* node
,
1308 const wxString
& item
,
1309 wxString
& value
) const
1311 wxString basename
= item
.BeforeFirst('[');
1312 wxCHECK_MSG( !basename
.empty(), NULL
,
1313 "an id-range item without a range name" );
1315 int index
= Find(basename
);
1316 if (index
== wxNOT_FOUND
)
1318 // Don't assert just because we've found an unexpected foo[123]
1319 // Someone might just want such a name, nothing to do with ranges
1323 value
= item
.Mid(basename
.Len());
1324 if (value
.at(value
.length()-1)==']')
1326 return m_IdRanges
.at(index
);
1328 wxXmlResource::Get()->ReportError(node
, "a malformed id-range item");
1333 wxIdRangeManager::NotifyRangeOfItem(const wxXmlNode
* node
,
1334 const wxString
& item
) const
1337 wxIdRange
* range
= FindRangeForItem(node
, item
, value
);
1339 range
->NoteItem(node
, value
);
1342 int wxIdRangeManager::Find(const wxString
& rangename
) const
1344 for ( int i
=0; i
< (int)m_IdRanges
.size(); ++i
)
1346 if (m_IdRanges
.at(i
)->GetName() == rangename
)
1353 void wxIdRangeManager::FinaliseRanges(const wxXmlNode
* node
) const
1355 for ( wxVector
<wxIdRange
*>::const_iterator i
= m_IdRanges
.begin();
1356 i
!= m_IdRanges
.end(); ++i
)
1358 // Check if this range has already been finalised. Quite possible,
1359 // as FinaliseRanges() gets called for each .xrc file loaded
1360 if (!(*i
)->IsFinalised())
1362 wxLogTrace("xrcrange", "Finalising ID range %s", (*i
)->GetName());
1363 (*i
)->Finalise(node
);
1369 class wxXmlSubclassFactories
: public wxVector
<wxXmlSubclassFactory
*>
1371 // this is a class so that it can be forward-declared
1374 wxXmlSubclassFactories
*wxXmlResource::ms_subclassFactories
= NULL
;
1376 /*static*/ void wxXmlResource::AddSubclassFactory(wxXmlSubclassFactory
*factory
)
1378 if (!ms_subclassFactories
)
1380 ms_subclassFactories
= new wxXmlSubclassFactories
;
1382 ms_subclassFactories
->push_back(factory
);
1385 class wxXmlSubclassFactoryCXX
: public wxXmlSubclassFactory
1388 ~wxXmlSubclassFactoryCXX() {}
1390 wxObject
*Create(const wxString
& className
)
1392 wxClassInfo
* classInfo
= wxClassInfo::FindClass(className
);
1395 return classInfo
->CreateObject();
1404 wxXmlResourceHandler::wxXmlResourceHandler()
1405 : m_node(NULL
), m_parent(NULL
), m_instance(NULL
),
1406 m_parentAsWindow(NULL
)
1411 wxObject
*wxXmlResourceHandler::CreateResource(wxXmlNode
*node
, wxObject
*parent
, wxObject
*instance
)
1413 wxXmlNode
*myNode
= m_node
;
1414 wxString myClass
= m_class
;
1415 wxObject
*myParent
= m_parent
, *myInstance
= m_instance
;
1416 wxWindow
*myParentAW
= m_parentAsWindow
;
1418 m_instance
= instance
;
1419 if (!m_instance
&& node
->HasAttribute(wxT("subclass")) &&
1420 !(m_resource
->GetFlags() & wxXRC_NO_SUBCLASSING
))
1422 wxString subclass
= node
->GetAttribute(wxT("subclass"), wxEmptyString
);
1423 if (!subclass
.empty())
1425 for (wxXmlSubclassFactories::iterator i
= wxXmlResource::ms_subclassFactories
->begin();
1426 i
!= wxXmlResource::ms_subclassFactories
->end(); ++i
)
1428 m_instance
= (*i
)->Create(subclass
);
1435 wxString name
= node
->GetAttribute(wxT("name"), wxEmptyString
);
1441 "subclass \"%s\" not found for resource \"%s\", not subclassing",
1450 m_class
= node
->GetAttribute(wxT("class"), wxEmptyString
);
1452 m_parentAsWindow
= wxDynamicCast(m_parent
, wxWindow
);
1454 wxObject
*returned
= DoCreateResource();
1458 m_parent
= myParent
; m_parentAsWindow
= myParentAW
;
1459 m_instance
= myInstance
;
1465 void wxXmlResourceHandler::AddStyle(const wxString
& name
, int value
)
1467 m_styleNames
.Add(name
);
1468 m_styleValues
.Add(value
);
1473 void wxXmlResourceHandler::AddWindowStyles()
1475 XRC_ADD_STYLE(wxCLIP_CHILDREN
);
1477 // the border styles all have the old and new names, recognize both for now
1478 XRC_ADD_STYLE(wxSIMPLE_BORDER
); XRC_ADD_STYLE(wxBORDER_SIMPLE
);
1479 XRC_ADD_STYLE(wxSUNKEN_BORDER
); XRC_ADD_STYLE(wxBORDER_SUNKEN
);
1480 XRC_ADD_STYLE(wxDOUBLE_BORDER
); XRC_ADD_STYLE(wxBORDER_DOUBLE
); // deprecated
1481 XRC_ADD_STYLE(wxBORDER_THEME
);
1482 XRC_ADD_STYLE(wxRAISED_BORDER
); XRC_ADD_STYLE(wxBORDER_RAISED
);
1483 XRC_ADD_STYLE(wxSTATIC_BORDER
); XRC_ADD_STYLE(wxBORDER_STATIC
);
1484 XRC_ADD_STYLE(wxNO_BORDER
); XRC_ADD_STYLE(wxBORDER_NONE
);
1485 XRC_ADD_STYLE(wxBORDER_DEFAULT
);
1487 XRC_ADD_STYLE(wxTRANSPARENT_WINDOW
);
1488 XRC_ADD_STYLE(wxWANTS_CHARS
);
1489 XRC_ADD_STYLE(wxTAB_TRAVERSAL
);
1490 XRC_ADD_STYLE(wxNO_FULL_REPAINT_ON_RESIZE
);
1491 XRC_ADD_STYLE(wxFULL_REPAINT_ON_RESIZE
);
1492 XRC_ADD_STYLE(wxVSCROLL
);
1493 XRC_ADD_STYLE(wxHSCROLL
);
1494 XRC_ADD_STYLE(wxALWAYS_SHOW_SB
);
1496 XRC_ADD_STYLE(wxWS_EX_BLOCK_EVENTS
);
1497 XRC_ADD_STYLE(wxWS_EX_VALIDATE_RECURSIVELY
);
1498 XRC_ADD_STYLE(wxWS_EX_TRANSIENT
);
1499 XRC_ADD_STYLE(wxWS_EX_CONTEXTHELP
);
1500 XRC_ADD_STYLE(wxWS_EX_PROCESS_IDLE
);
1501 XRC_ADD_STYLE(wxWS_EX_PROCESS_UI_UPDATES
);
1506 bool wxXmlResourceHandler::HasParam(const wxString
& param
)
1508 return (GetParamNode(param
) != NULL
);
1512 int wxXmlResourceHandler::GetStyle(const wxString
& param
, int defaults
)
1514 wxString s
= GetParamValue(param
);
1516 if (!s
) return defaults
;
1518 wxStringTokenizer
tkn(s
, wxT("| \t\n"), wxTOKEN_STRTOK
);
1522 while (tkn
.HasMoreTokens())
1524 fl
= tkn
.GetNextToken();
1525 index
= m_styleNames
.Index(fl
);
1526 if (index
!= wxNOT_FOUND
)
1528 style
|= m_styleValues
[index
];
1535 wxString::Format("unknown style flag \"%s\"", fl
)
1544 wxString
wxXmlResourceHandler::GetText(const wxString
& param
, bool translate
)
1546 wxXmlNode
*parNode
= GetParamNode(param
);
1547 wxString
str1(GetNodeContent(parNode
));
1550 // "\\" wasn't translated to "\" prior to 2.5.3.0:
1551 const bool escapeBackslash
= (m_resource
->CompareVersion(2,5,3,0) >= 0);
1553 // VS: First version of XRC resources used $ instead of & (which is
1554 // illegal in XML), but later I realized that '_' fits this purpose
1555 // much better (because &File means "File with F underlined").
1556 const wxChar amp_char
= (m_resource
->CompareVersion(2,3,0,1) < 0)
1559 for ( wxString::const_iterator dt
= str1
.begin(); dt
!= str1
.end(); ++dt
)
1561 // Remap amp_char to &, map double amp_char to amp_char (for things
1562 // like "&File..." -- this is illegal in XML, so we use "_File..."):
1563 if ( *dt
== amp_char
)
1565 if ( dt
+1 == str1
.end() || *(++dt
) == amp_char
)
1568 str2
<< wxT('&') << *dt
;
1570 // Remap \n to CR, \r to LF, \t to TAB, \\ to \:
1571 else if ( *dt
== wxT('\\') )
1573 switch ( (*(++dt
)).GetValue() )
1588 // "\\" wasn't translated to "\" prior to 2.5.3.0:
1589 if ( escapeBackslash
)
1594 // else fall-through to default: branch below
1597 str2
<< wxT('\\') << *dt
;
1607 if (m_resource
->GetFlags() & wxXRC_USE_LOCALE
)
1609 if (translate
&& parNode
&&
1610 parNode
->GetAttribute(wxT("translate"), wxEmptyString
) != wxT("0"))
1612 return wxGetTranslation(str2
, m_resource
->GetDomain());
1619 // The string is internally stored as UTF-8, we have to convert
1620 // it into system's default encoding so that it can be displayed:
1621 return wxString(str2
.wc_str(wxConvUTF8
), wxConvLocal
);
1626 // If wxXRC_USE_LOCALE is not set, then the string is already in
1627 // system's default encoding in ANSI build, so we don't have to
1628 // do anything special here.
1634 long wxXmlResourceHandler::GetLong(const wxString
& param
, long defaultv
)
1636 long value
= defaultv
;
1637 wxString str1
= GetParamValue(param
);
1641 if (!str1
.ToLong(&value
))
1646 wxString::Format("invalid long specification \"%s\"", str1
)
1654 float wxXmlResourceHandler::GetFloat(const wxString
& param
, float defaultv
)
1656 wxString str
= GetParamValue(param
);
1658 // strings in XRC always use C locale so make sure to use the
1659 // locale-independent wxString::ToCDouble() and not ToDouble() which uses
1660 // the current locale with a potentially different decimal point character
1661 double value
= defaultv
;
1664 if (!str
.ToCDouble(&value
))
1669 wxString::Format("invalid float specification \"%s\"", str
)
1674 return wx_truncate_cast(float, value
);
1678 int wxXmlResourceHandler::GetID()
1680 return wxXmlResource::GetXRCID(GetName());
1685 wxString
wxXmlResourceHandler::GetName()
1687 return m_node
->GetAttribute(wxT("name"), wxT("-1"));
1692 bool wxXmlResourceHandler::GetBoolAttr(const wxString
& attr
, bool defaultv
)
1695 return m_node
->GetAttribute(attr
, &v
) ? v
== '1' : defaultv
;
1698 bool wxXmlResourceHandler::GetBool(const wxString
& param
, bool defaultv
)
1700 const wxString v
= GetParamValue(param
);
1702 return v
.empty() ? defaultv
: (v
== '1');
1706 static wxColour
GetSystemColour(const wxString
& name
)
1710 #define SYSCLR(clr) \
1711 if (name == wxT(#clr)) return wxSystemSettings::GetColour(clr);
1712 SYSCLR(wxSYS_COLOUR_SCROLLBAR
)
1713 SYSCLR(wxSYS_COLOUR_BACKGROUND
)
1714 SYSCLR(wxSYS_COLOUR_DESKTOP
)
1715 SYSCLR(wxSYS_COLOUR_ACTIVECAPTION
)
1716 SYSCLR(wxSYS_COLOUR_INACTIVECAPTION
)
1717 SYSCLR(wxSYS_COLOUR_MENU
)
1718 SYSCLR(wxSYS_COLOUR_WINDOW
)
1719 SYSCLR(wxSYS_COLOUR_WINDOWFRAME
)
1720 SYSCLR(wxSYS_COLOUR_MENUTEXT
)
1721 SYSCLR(wxSYS_COLOUR_WINDOWTEXT
)
1722 SYSCLR(wxSYS_COLOUR_CAPTIONTEXT
)
1723 SYSCLR(wxSYS_COLOUR_ACTIVEBORDER
)
1724 SYSCLR(wxSYS_COLOUR_INACTIVEBORDER
)
1725 SYSCLR(wxSYS_COLOUR_APPWORKSPACE
)
1726 SYSCLR(wxSYS_COLOUR_HIGHLIGHT
)
1727 SYSCLR(wxSYS_COLOUR_HIGHLIGHTTEXT
)
1728 SYSCLR(wxSYS_COLOUR_BTNFACE
)
1729 SYSCLR(wxSYS_COLOUR_3DFACE
)
1730 SYSCLR(wxSYS_COLOUR_BTNSHADOW
)
1731 SYSCLR(wxSYS_COLOUR_3DSHADOW
)
1732 SYSCLR(wxSYS_COLOUR_GRAYTEXT
)
1733 SYSCLR(wxSYS_COLOUR_BTNTEXT
)
1734 SYSCLR(wxSYS_COLOUR_INACTIVECAPTIONTEXT
)
1735 SYSCLR(wxSYS_COLOUR_BTNHIGHLIGHT
)
1736 SYSCLR(wxSYS_COLOUR_BTNHILIGHT
)
1737 SYSCLR(wxSYS_COLOUR_3DHIGHLIGHT
)
1738 SYSCLR(wxSYS_COLOUR_3DHILIGHT
)
1739 SYSCLR(wxSYS_COLOUR_3DDKSHADOW
)
1740 SYSCLR(wxSYS_COLOUR_3DLIGHT
)
1741 SYSCLR(wxSYS_COLOUR_INFOTEXT
)
1742 SYSCLR(wxSYS_COLOUR_INFOBK
)
1743 SYSCLR(wxSYS_COLOUR_LISTBOX
)
1744 SYSCLR(wxSYS_COLOUR_HOTLIGHT
)
1745 SYSCLR(wxSYS_COLOUR_GRADIENTACTIVECAPTION
)
1746 SYSCLR(wxSYS_COLOUR_GRADIENTINACTIVECAPTION
)
1747 SYSCLR(wxSYS_COLOUR_MENUHILIGHT
)
1748 SYSCLR(wxSYS_COLOUR_MENUBAR
)
1752 return wxNullColour
;
1755 wxColour
wxXmlResourceHandler::GetColour(const wxString
& param
, const wxColour
& defaultv
)
1757 wxString v
= GetParamValue(param
);
1764 // wxString -> wxColour conversion
1767 // the colour doesn't use #RRGGBB format, check if it is symbolic
1769 clr
= GetSystemColour(v
);
1776 wxString::Format("incorrect colour specification \"%s\"", v
)
1778 return wxNullColour
;
1787 // if 'param' has stock_id/stock_client, extracts them and returns true
1788 bool GetStockArtAttrs(const wxXmlNode
*paramNode
,
1789 const wxString
& defaultArtClient
,
1790 wxString
& art_id
, wxString
& art_client
)
1794 art_id
= paramNode
->GetAttribute("stock_id", "");
1796 if ( !art_id
.empty() )
1798 art_id
= wxART_MAKE_ART_ID_FROM_STR(art_id
);
1800 art_client
= paramNode
->GetAttribute("stock_client", "");
1801 if ( art_client
.empty() )
1802 art_client
= defaultArtClient
;
1804 art_client
= wxART_MAKE_CLIENT_ID_FROM_STR(art_client
);
1813 } // anonymous namespace
1815 wxBitmap
wxXmlResourceHandler::GetBitmap(const wxString
& param
,
1816 const wxArtClient
& defaultArtClient
,
1819 // it used to be possible to pass an empty string here to indicate that the
1820 // bitmap name should be read from this node itself but this is not
1821 // supported any more because GetBitmap(m_node) can be used directly
1823 wxASSERT_MSG( !param
.empty(), "bitmap parameter name can't be empty" );
1825 const wxXmlNode
* const node
= GetParamNode(param
);
1829 // this is not an error as bitmap parameter could be optional
1830 return wxNullBitmap
;
1833 return GetBitmap(node
, defaultArtClient
, size
);
1836 wxBitmap
wxXmlResourceHandler::GetBitmap(const wxXmlNode
* node
,
1837 const wxArtClient
& defaultArtClient
,
1840 wxCHECK_MSG( node
, wxNullBitmap
, "bitmap node can't be NULL" );
1842 /* If the bitmap is specified as stock item, query wxArtProvider for it: */
1843 wxString art_id
, art_client
;
1844 if ( GetStockArtAttrs(node
, defaultArtClient
,
1845 art_id
, art_client
) )
1847 wxBitmap
stockArt(wxArtProvider::GetBitmap(art_id
, art_client
, size
));
1848 if ( stockArt
.IsOk() )
1852 /* ...or load the bitmap from file: */
1853 wxString name
= GetParamValue(node
);
1854 if (name
.empty()) return wxNullBitmap
;
1855 #if wxUSE_FILESYSTEM
1856 wxFSFile
*fsfile
= GetCurFileSystem().OpenFile(name
, wxFS_READ
| wxFS_SEEKABLE
);
1862 wxString::Format("cannot open bitmap resource \"%s\"", name
)
1864 return wxNullBitmap
;
1866 wxImage
img(*(fsfile
->GetStream()));
1877 wxString::Format("cannot create bitmap from \"%s\"", name
)
1879 return wxNullBitmap
;
1881 if (!(size
== wxDefaultSize
)) img
.Rescale(size
.x
, size
.y
);
1882 return wxBitmap(img
);
1886 wxIcon
wxXmlResourceHandler::GetIcon(const wxString
& param
,
1887 const wxArtClient
& defaultArtClient
,
1890 // see comment in GetBitmap(wxString) overload
1891 wxASSERT_MSG( !param
.empty(), "icon parameter name can't be empty" );
1893 const wxXmlNode
* const node
= GetParamNode(param
);
1897 // this is not an error as icon parameter could be optional
1901 return GetIcon(node
, defaultArtClient
, size
);
1904 wxIcon
wxXmlResourceHandler::GetIcon(const wxXmlNode
* node
,
1905 const wxArtClient
& defaultArtClient
,
1909 icon
.CopyFromBitmap(GetBitmap(node
, defaultArtClient
, size
));
1914 wxIconBundle
wxXmlResourceHandler::GetIconBundle(const wxString
& param
,
1915 const wxArtClient
& defaultArtClient
)
1917 wxString art_id
, art_client
;
1918 if ( GetStockArtAttrs(GetParamNode(param
), defaultArtClient
,
1919 art_id
, art_client
) )
1921 wxIconBundle
stockArt(wxArtProvider::GetIconBundle(art_id
, art_client
));
1922 if ( stockArt
.IsOk() )
1926 const wxString name
= GetParamValue(param
);
1928 return wxNullIconBundle
;
1930 #if wxUSE_FILESYSTEM
1931 wxFSFile
*fsfile
= GetCurFileSystem().OpenFile(name
, wxFS_READ
| wxFS_SEEKABLE
);
1932 if ( fsfile
== NULL
)
1937 wxString::Format("cannot open icon resource \"%s\"", name
)
1939 return wxNullIconBundle
;
1942 wxIconBundle
bundle(*(fsfile
->GetStream()));
1945 wxIconBundle
bundle(name
);
1948 if ( !bundle
.IsOk() )
1953 wxString::Format("cannot create icon from \"%s\"", name
)
1955 return wxNullIconBundle
;
1962 wxImageList
*wxXmlResourceHandler::GetImageList(const wxString
& param
)
1964 wxXmlNode
* const imagelist_node
= GetParamNode(param
);
1965 if ( !imagelist_node
)
1968 wxXmlNode
* const oldnode
= m_node
;
1969 m_node
= imagelist_node
;
1971 // Get the size if we have it, otherwise we will use the size of the first
1973 wxSize size
= GetSize();
1975 // Start adding images, we'll create the image list when adding the first
1977 wxImageList
* imagelist
= NULL
;
1978 wxString parambitmap
= wxT("bitmap");
1979 if ( HasParam(parambitmap
) )
1981 wxXmlNode
*n
= m_node
->GetChildren();
1984 if (n
->GetType() == wxXML_ELEMENT_NODE
&& n
->GetName() == parambitmap
)
1986 wxIcon icon
= GetIcon(n
, wxART_OTHER
, size
);
1989 // We need the real image list size to create it.
1990 if ( size
== wxDefaultSize
)
1991 size
= icon
.GetSize();
1993 // We use the mask by default.
1994 bool mask
= !HasParam(wxS("mask")) || GetBool(wxS("mask"));
1996 imagelist
= new wxImageList(size
.x
, size
.y
, mask
);
1999 // add icon instead of bitmap to keep the bitmap mask
2000 imagelist
->Add(icon
);
2010 wxXmlNode
*wxXmlResourceHandler::GetParamNode(const wxString
& param
)
2012 wxCHECK_MSG(m_node
, NULL
, wxT("You can't access handler data before it was initialized!"));
2014 wxXmlNode
*n
= m_node
->GetChildren();
2018 if (n
->GetType() == wxXML_ELEMENT_NODE
&& n
->GetName() == param
)
2020 // TODO: check that there are no other properties/parameters with
2021 // the same name and log an error if there are (can't do this
2022 // right now as I'm not sure if it's not going to break code
2023 // using this function in unintentional way (i.e. for
2024 // accessing other things than properties), for example
2025 // wxBitmapComboBoxXmlHandler almost surely does
2034 bool wxXmlResourceHandler::IsOfClass(wxXmlNode
*node
, const wxString
& classname
)
2036 return node
->GetAttribute(wxT("class")) == classname
;
2041 wxString
wxXmlResourceHandler::GetNodeContent(const wxXmlNode
*node
)
2043 const wxXmlNode
*n
= node
;
2044 if (n
== NULL
) return wxEmptyString
;
2045 n
= n
->GetChildren();
2049 if (n
->GetType() == wxXML_TEXT_NODE
||
2050 n
->GetType() == wxXML_CDATA_SECTION_NODE
)
2051 return n
->GetContent();
2054 return wxEmptyString
;
2059 wxString
wxXmlResourceHandler::GetParamValue(const wxString
& param
)
2062 return GetNodeContent(m_node
);
2064 return GetNodeContent(GetParamNode(param
));
2067 wxString
wxXmlResourceHandler::GetParamValue(const wxXmlNode
* node
)
2069 return GetNodeContent(node
);
2073 wxSize
wxXmlResourceHandler::GetSize(const wxString
& param
,
2074 wxWindow
*windowToUse
)
2076 wxString s
= GetParamValue(param
);
2077 if (s
.empty()) s
= wxT("-1,-1");
2081 is_dlg
= s
[s
.length()-1] == wxT('d');
2082 if (is_dlg
) s
.RemoveLast();
2084 if (!s
.BeforeFirst(wxT(',')).ToLong(&sx
) ||
2085 !s
.AfterLast(wxT(',')).ToLong(&sy
))
2090 wxString::Format("cannot parse coordinates value \"%s\"", s
)
2092 return wxDefaultSize
;
2099 return wxDLG_UNIT(windowToUse
, wxSize(sx
, sy
));
2101 else if (m_parentAsWindow
)
2103 return wxDLG_UNIT(m_parentAsWindow
, wxSize(sx
, sy
));
2110 "cannot convert dialog units: dialog unknown"
2112 return wxDefaultSize
;
2116 return wxSize(sx
, sy
);
2121 wxPoint
wxXmlResourceHandler::GetPosition(const wxString
& param
)
2123 wxSize sz
= GetSize(param
);
2124 return wxPoint(sz
.x
, sz
.y
);
2129 wxCoord
wxXmlResourceHandler::GetDimension(const wxString
& param
,
2131 wxWindow
*windowToUse
)
2133 wxString s
= GetParamValue(param
);
2134 if (s
.empty()) return defaultv
;
2138 is_dlg
= s
[s
.length()-1] == wxT('d');
2139 if (is_dlg
) s
.RemoveLast();
2146 wxString::Format("cannot parse dimension value \"%s\"", s
)
2155 return wxDLG_UNIT(windowToUse
, wxSize(sx
, 0)).x
;
2157 else if (m_parentAsWindow
)
2159 return wxDLG_UNIT(m_parentAsWindow
, wxSize(sx
, 0)).x
;
2166 "cannot convert dialog units: dialog unknown"
2176 wxXmlResourceHandler::GetDirection(const wxString
& param
, wxDirection dirDefault
)
2180 const wxString dirstr
= GetParamValue(param
);
2181 if ( dirstr
.empty() )
2183 else if ( dirstr
== "wxLEFT" )
2185 else if ( dirstr
== "wxRIGHT" )
2187 else if ( dirstr
== "wxTOP" )
2189 else if ( dirstr
== "wxBOTTOM" )
2195 GetParamNode(param
),
2198 "Invalid direction \"%s\": must be one of "
2199 "wxLEFT|wxRIGHT|wxTOP|wxBOTTOM.",
2210 // Get system font index using indexname
2211 static wxFont
GetSystemFont(const wxString
& name
)
2215 #define SYSFNT(fnt) \
2216 if (name == wxT(#fnt)) return wxSystemSettings::GetFont(fnt);
2217 SYSFNT(wxSYS_OEM_FIXED_FONT
)
2218 SYSFNT(wxSYS_ANSI_FIXED_FONT
)
2219 SYSFNT(wxSYS_ANSI_VAR_FONT
)
2220 SYSFNT(wxSYS_SYSTEM_FONT
)
2221 SYSFNT(wxSYS_DEVICE_DEFAULT_FONT
)
2222 SYSFNT(wxSYS_SYSTEM_FIXED_FONT
)
2223 SYSFNT(wxSYS_DEFAULT_GUI_FONT
)
2230 wxFont
wxXmlResourceHandler::GetFont(const wxString
& param
, wxWindow
* parent
)
2232 wxXmlNode
*font_node
= GetParamNode(param
);
2233 if (font_node
== NULL
)
2236 wxString::Format("cannot find font node \"%s\"", param
));
2240 wxXmlNode
*oldnode
= m_node
;
2247 bool hasSize
= HasParam(wxT("size"));
2249 isize
= GetLong(wxT("size"), -1);
2252 int istyle
= wxNORMAL
;
2253 bool hasStyle
= HasParam(wxT("style"));
2256 wxString style
= GetParamValue(wxT("style"));
2257 if (style
== wxT("italic"))
2259 else if (style
== wxT("slant"))
2261 else if (style
!= wxT("normal"))
2266 wxString::Format("unknown font style \"%s\"", style
)
2272 int iweight
= wxNORMAL
;
2273 bool hasWeight
= HasParam(wxT("weight"));
2276 wxString weight
= GetParamValue(wxT("weight"));
2277 if (weight
== wxT("bold"))
2279 else if (weight
== wxT("light"))
2281 else if (weight
!= wxT("normal"))
2286 wxString::Format("unknown font weight \"%s\"", weight
)
2292 bool hasUnderlined
= HasParam(wxT("underlined"));
2293 bool underlined
= hasUnderlined
? GetBool(wxT("underlined"), false) : false;
2295 // family and facename
2296 int ifamily
= wxDEFAULT
;
2297 bool hasFamily
= HasParam(wxT("family"));
2300 wxString family
= GetParamValue(wxT("family"));
2301 if (family
== wxT("decorative")) ifamily
= wxDECORATIVE
;
2302 else if (family
== wxT("roman")) ifamily
= wxROMAN
;
2303 else if (family
== wxT("script")) ifamily
= wxSCRIPT
;
2304 else if (family
== wxT("swiss")) ifamily
= wxSWISS
;
2305 else if (family
== wxT("modern")) ifamily
= wxMODERN
;
2306 else if (family
== wxT("teletype")) ifamily
= wxTELETYPE
;
2312 wxString::Format("unknown font family \"%s\"", family
)
2319 bool hasFacename
= HasParam(wxT("face"));
2322 wxString faces
= GetParamValue(wxT("face"));
2323 wxStringTokenizer
tk(faces
, wxT(","));
2325 wxArrayString
facenames(wxFontEnumerator::GetFacenames());
2326 while (tk
.HasMoreTokens())
2328 int index
= facenames
.Index(tk
.GetNextToken(), false);
2329 if (index
!= wxNOT_FOUND
)
2331 facename
= facenames
[index
];
2335 #else // !wxUSE_FONTENUM
2336 // just use the first face name if we can't check its availability:
2337 if (tk
.HasMoreTokens())
2338 facename
= tk
.GetNextToken();
2339 #endif // wxUSE_FONTENUM/!wxUSE_FONTENUM
2343 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
2344 bool hasEncoding
= HasParam(wxT("encoding"));
2348 wxString encoding
= GetParamValue(wxT("encoding"));
2349 wxFontMapper mapper
;
2350 if (!encoding
.empty())
2351 enc
= mapper
.CharsetToEncoding(encoding
);
2352 if (enc
== wxFONTENCODING_SYSTEM
)
2353 enc
= wxFONTENCODING_DEFAULT
;
2355 #endif // wxUSE_FONTMAP
2359 // is this font based on a system font?
2360 if (HasParam(wxT("sysfont")))
2362 font
= GetSystemFont(GetParamValue(wxT("sysfont")));
2363 if (HasParam(wxT("inherit")))
2368 "double specification of \"sysfont\" and \"inherit\""
2372 // or should the font of the widget be used?
2373 else if (GetBool(wxT("inherit"), false))
2376 font
= parent
->GetFont();
2382 "no parent window specified to derive the font from"
2389 if (hasSize
&& isize
!= -1)
2391 font
.SetPointSize(isize
);
2392 if (HasParam(wxT("relativesize")))
2397 "double specification of \"size\" and \"relativesize\""
2401 else if (HasParam(wxT("relativesize")))
2402 font
.SetPointSize(int(font
.GetPointSize() *
2403 GetFloat(wxT("relativesize"))));
2406 font
.SetStyle(istyle
);
2408 font
.SetWeight(iweight
);
2410 font
.SetUnderlined(underlined
);
2412 font
.SetFamily(ifamily
);
2414 font
.SetFaceName(facename
);
2416 font
.SetDefaultEncoding(enc
);
2418 else // not based on system font
2420 font
= wxFont(isize
== -1 ? wxNORMAL_FONT
->GetPointSize() : isize
,
2421 ifamily
, istyle
, iweight
,
2422 underlined
, facename
, enc
);
2430 void wxXmlResourceHandler::SetupWindow(wxWindow
*wnd
)
2432 //FIXME : add cursor
2434 if (HasParam(wxT("exstyle")))
2435 // Have to OR it with existing style, since
2436 // some implementations (e.g. wxGTK) use the extra style
2438 wnd
->SetExtraStyle(wnd
->GetExtraStyle() | GetStyle(wxT("exstyle")));
2439 if (HasParam(wxT("bg")))
2440 wnd
->SetBackgroundColour(GetColour(wxT("bg")));
2441 if (HasParam(wxT("ownbg")))
2442 wnd
->SetOwnBackgroundColour(GetColour(wxT("ownbg")));
2443 if (HasParam(wxT("fg")))
2444 wnd
->SetForegroundColour(GetColour(wxT("fg")));
2445 if (HasParam(wxT("ownfg")))
2446 wnd
->SetOwnForegroundColour(GetColour(wxT("ownfg")));
2447 if (GetBool(wxT("enabled"), 1) == 0)
2449 if (GetBool(wxT("focused"), 0) == 1)
2451 if (GetBool(wxT("hidden"), 0) == 1)
2454 if (HasParam(wxT("tooltip")))
2455 wnd
->SetToolTip(GetText(wxT("tooltip")));
2457 if (HasParam(wxT("font")))
2458 wnd
->SetFont(GetFont(wxT("font"), wnd
));
2459 if (HasParam(wxT("ownfont")))
2460 wnd
->SetOwnFont(GetFont(wxT("ownfont"), wnd
));
2461 if (HasParam(wxT("help")))
2462 wnd
->SetHelpText(GetText(wxT("help")));
2466 void wxXmlResourceHandler::CreateChildren(wxObject
*parent
, bool this_hnd_only
)
2468 for ( wxXmlNode
*n
= m_node
->GetChildren(); n
; n
= n
->GetNext() )
2470 if ( IsObjectNode(n
) )
2472 m_resource
->DoCreateResFromNode(*n
, parent
, NULL
,
2473 this_hnd_only
? this : NULL
);
2479 void wxXmlResourceHandler::CreateChildrenPrivately(wxObject
*parent
, wxXmlNode
*rootnode
)
2482 if (rootnode
== NULL
) root
= m_node
; else root
= rootnode
;
2483 wxXmlNode
*n
= root
->GetChildren();
2487 if (n
->GetType() == wxXML_ELEMENT_NODE
&& CanHandle(n
))
2489 CreateResource(n
, parent
, NULL
);
2496 //-----------------------------------------------------------------------------
2498 //-----------------------------------------------------------------------------
2500 void wxXmlResourceHandler::ReportError(const wxString
& message
)
2502 m_resource
->ReportError(m_node
, message
);
2505 void wxXmlResourceHandler::ReportError(wxXmlNode
*context
,
2506 const wxString
& message
)
2508 m_resource
->ReportError(context
? context
: m_node
, message
);
2511 void wxXmlResourceHandler::ReportParamError(const wxString
& param
,
2512 const wxString
& message
)
2514 m_resource
->ReportError(GetParamNode(param
), message
);
2517 void wxXmlResource::ReportError(const wxXmlNode
*context
, const wxString
& message
)
2521 DoReportError("", NULL
, message
);
2525 // We need to find out the file that 'context' is part of. Performance of
2526 // this code is not critical, so we simply find the root XML node and
2527 // compare it with all loaded XRC files.
2528 const wxString filename
= GetFileNameFromNode(context
, Data());
2530 DoReportError(filename
, context
, message
);
2533 void wxXmlResource::DoReportError(const wxString
& xrcFile
, const wxXmlNode
*position
,
2534 const wxString
& message
)
2536 const int line
= position
? position
->GetLineNumber() : -1;
2539 if ( !xrcFile
.empty() )
2540 loc
= xrcFile
+ ':';
2542 loc
+= wxString::Format("%d:", line
);
2546 wxLogError("XRC error: %s%s", loc
, message
);
2550 //-----------------------------------------------------------------------------
2551 // XRCID implementation
2552 //-----------------------------------------------------------------------------
2554 #define XRCID_TABLE_SIZE 1024
2559 /* Hold the id so that once an id is allocated for a name, it
2560 does not get created again by NewControlId at least
2561 until we are done with it */
2567 static XRCID_record
*XRCID_Records
[XRCID_TABLE_SIZE
] = {NULL
};
2569 // Extremely simplistic hash function which probably ought to be replaced with
2570 // wxStringHash::stringHash().
2571 static inline unsigned XRCIdHash(const char *str_id
)
2575 for (const char *c
= str_id
; *c
!= '\0'; c
++) index
+= (unsigned int)*c
;
2576 index
%= XRCID_TABLE_SIZE
;
2581 static void XRCID_Assign(const wxString
& str_id
, int value
)
2583 const wxCharBuffer
buf_id(str_id
.mb_str());
2584 const unsigned index
= XRCIdHash(buf_id
);
2587 XRCID_record
*oldrec
= NULL
;
2588 for (XRCID_record
*rec
= XRCID_Records
[index
]; rec
; rec
= rec
->next
)
2590 if (wxStrcmp(rec
->key
, buf_id
) == 0)
2598 XRCID_record
**rec_var
= (oldrec
== NULL
) ?
2599 &XRCID_Records
[index
] : &oldrec
->next
;
2600 *rec_var
= new XRCID_record
;
2601 (*rec_var
)->key
= wxStrdup(str_id
);
2602 (*rec_var
)->id
= value
;
2603 (*rec_var
)->next
= NULL
;
2606 static int XRCID_Lookup(const char *str_id
, int value_if_not_found
= wxID_NONE
)
2608 const unsigned index
= XRCIdHash(str_id
);
2611 XRCID_record
*oldrec
= NULL
;
2612 for (XRCID_record
*rec
= XRCID_Records
[index
]; rec
; rec
= rec
->next
)
2614 if (wxStrcmp(rec
->key
, str_id
) == 0)
2621 XRCID_record
**rec_var
= (oldrec
== NULL
) ?
2622 &XRCID_Records
[index
] : &oldrec
->next
;
2623 *rec_var
= new XRCID_record
;
2624 (*rec_var
)->key
= wxStrdup(str_id
);
2625 (*rec_var
)->next
= NULL
;
2628 if (value_if_not_found
!= wxID_NONE
)
2629 (*rec_var
)->id
= value_if_not_found
;
2632 int asint
= wxStrtol(str_id
, &end
, 10);
2633 if (*str_id
&& *end
== 0)
2635 // if str_id was integer, keep it verbosely:
2636 (*rec_var
)->id
= asint
;
2640 (*rec_var
)->id
= wxWindowBase::NewControlId();
2644 return (*rec_var
)->id
;
2650 // flag indicating whether standard XRC ids were already initialized
2651 static bool gs_stdIDsAdded
= false;
2653 void AddStdXRCID_Records()
2655 #define stdID(id) XRCID_Lookup(#id, id)
2659 stdID(wxID_SEPARATOR
);
2672 stdID(wxID_PRINT_SETUP
);
2673 stdID(wxID_PAGE_SETUP
);
2674 stdID(wxID_PREVIEW
);
2676 stdID(wxID_HELP_CONTENTS
);
2677 stdID(wxID_HELP_INDEX
),
2678 stdID(wxID_HELP_SEARCH
),
2679 stdID(wxID_HELP_COMMANDS
);
2680 stdID(wxID_HELP_PROCEDURES
);
2681 stdID(wxID_HELP_CONTEXT
);
2682 stdID(wxID_CLOSE_ALL
);
2683 stdID(wxID_PREFERENCES
);
2691 stdID(wxID_DUPLICATE
);
2692 stdID(wxID_SELECTALL
);
2694 stdID(wxID_REPLACE
);
2695 stdID(wxID_REPLACE_ALL
);
2696 stdID(wxID_PROPERTIES
);
2698 stdID(wxID_VIEW_DETAILS
);
2699 stdID(wxID_VIEW_LARGEICONS
);
2700 stdID(wxID_VIEW_SMALLICONS
);
2701 stdID(wxID_VIEW_LIST
);
2702 stdID(wxID_VIEW_SORTDATE
);
2703 stdID(wxID_VIEW_SORTNAME
);
2704 stdID(wxID_VIEW_SORTSIZE
);
2705 stdID(wxID_VIEW_SORTTYPE
);
2725 stdID(wxID_FORWARD
);
2726 stdID(wxID_BACKWARD
);
2727 stdID(wxID_DEFAULT
);
2731 stdID(wxID_CONTEXT_HELP
);
2732 stdID(wxID_YESTOALL
);
2733 stdID(wxID_NOTOALL
);
2743 stdID(wxID_REFRESH
);
2749 stdID(wxID_JUSTIFY_CENTER
);
2750 stdID(wxID_JUSTIFY_FILL
);
2751 stdID(wxID_JUSTIFY_RIGHT
);
2752 stdID(wxID_JUSTIFY_LEFT
);
2753 stdID(wxID_UNDERLINE
);
2755 stdID(wxID_UNINDENT
);
2756 stdID(wxID_ZOOM_100
);
2757 stdID(wxID_ZOOM_FIT
);
2758 stdID(wxID_ZOOM_IN
);
2759 stdID(wxID_ZOOM_OUT
);
2760 stdID(wxID_UNDELETE
);
2761 stdID(wxID_REVERT_TO_SAVED
);
2763 stdID(wxID_CONVERT
);
2764 stdID(wxID_EXECUTE
);
2766 stdID(wxID_HARDDISK
);
2772 stdID(wxID_JUMP_TO
);
2773 stdID(wxID_NETWORK
);
2774 stdID(wxID_SELECT_COLOR
);
2775 stdID(wxID_SELECT_FONT
);
2776 stdID(wxID_SORT_ASCENDING
);
2777 stdID(wxID_SORT_DESCENDING
);
2778 stdID(wxID_SPELL_CHECK
);
2779 stdID(wxID_STRIKETHROUGH
);
2782 stdID(wxID_SYSTEM_MENU
);
2783 stdID(wxID_CLOSE_FRAME
);
2784 stdID(wxID_MOVE_FRAME
);
2785 stdID(wxID_RESIZE_FRAME
);
2786 stdID(wxID_MAXIMIZE_FRAME
);
2787 stdID(wxID_ICONIZE_FRAME
);
2788 stdID(wxID_RESTORE_FRAME
);
2792 stdID(wxID_MDI_WINDOW_CASCADE
);
2793 stdID(wxID_MDI_WINDOW_TILE_HORZ
);
2794 stdID(wxID_MDI_WINDOW_TILE_VERT
);
2795 stdID(wxID_MDI_WINDOW_ARRANGE_ICONS
);
2796 stdID(wxID_MDI_WINDOW_PREV
);
2797 stdID(wxID_MDI_WINDOW_NEXT
);
2801 } // anonymous namespace
2805 int wxXmlResource::DoGetXRCID(const char *str_id
, int value_if_not_found
)
2807 if ( !gs_stdIDsAdded
)
2809 gs_stdIDsAdded
= true;
2810 AddStdXRCID_Records();
2813 return XRCID_Lookup(str_id
, value_if_not_found
);
2817 wxString
wxXmlResource::FindXRCIDById(int numId
)
2819 for ( int i
= 0; i
< XRCID_TABLE_SIZE
; i
++ )
2821 for ( XRCID_record
*rec
= XRCID_Records
[i
]; rec
; rec
= rec
->next
)
2823 if ( rec
->id
== numId
)
2824 return wxString(rec
->key
);
2831 static void CleanXRCID_Record(XRCID_record
*rec
)
2835 CleanXRCID_Record(rec
->next
);
2842 static void CleanXRCID_Records()
2844 for (int i
= 0; i
< XRCID_TABLE_SIZE
; i
++)
2846 CleanXRCID_Record(XRCID_Records
[i
]);
2847 XRCID_Records
[i
] = NULL
;
2850 gs_stdIDsAdded
= false;
2854 //-----------------------------------------------------------------------------
2855 // module and globals
2856 //-----------------------------------------------------------------------------
2858 // normally we would do the cleanup from wxXmlResourceModule::OnExit() but it
2859 // can happen that some XRC records have been created because of the use of
2860 // XRCID() in event tables, which happens during static objects initialization,
2861 // but then the application initialization failed and so the wx modules were
2862 // neither initialized nor cleaned up -- this static object does the cleanup in
2864 static struct wxXRCStaticCleanup
2866 ~wxXRCStaticCleanup() { CleanXRCID_Records(); }
2869 class wxXmlResourceModule
: public wxModule
2871 DECLARE_DYNAMIC_CLASS(wxXmlResourceModule
)
2873 wxXmlResourceModule() {}
2876 wxXmlResource::AddSubclassFactory(new wxXmlSubclassFactoryCXX
);
2881 delete wxXmlResource::Set(NULL
);
2882 delete wxIdRangeManager::Set(NULL
);
2883 if(wxXmlResource::ms_subclassFactories
)
2885 for ( wxXmlSubclassFactories::iterator i
= wxXmlResource::ms_subclassFactories
->begin();
2886 i
!= wxXmlResource::ms_subclassFactories
->end(); ++i
)
2890 wxDELETE(wxXmlResource::ms_subclassFactories
);
2892 CleanXRCID_Records();
2896 IMPLEMENT_DYNAMIC_CLASS(wxXmlResourceModule
, wxModule
)
2899 // When wxXml is loaded dynamically after the application is already running
2900 // then the built-in module system won't pick this one up. Add it manually.
2901 void wxXmlInitResourceModule()
2903 wxModule
* module = new wxXmlResourceModule
;
2905 wxModule::RegisterModule(module);