1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xmlres.cpp
3 // Purpose: XRC resources
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2000 Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
20 #include "wx/xrc/xmlres.h"
27 #include "wx/dialog.h"
28 #include "wx/settings.h"
29 #include "wx/bitmap.h"
31 #include "wx/module.h"
32 #include "wx/wxcrtvararg.h"
39 #include "wx/vector.h"
40 #include "wx/wfstream.h"
41 #include "wx/filesys.h"
42 #include "wx/filename.h"
43 #include "wx/tokenzr.h"
44 #include "wx/fontenum.h"
45 #include "wx/fontmap.h"
46 #include "wx/artprov.h"
48 #include "wx/xml/xml.h"
51 class wxXmlResourceDataRecord
54 wxXmlResourceDataRecord() : Doc(NULL
) {
56 Time
= wxDateTime::Now();
59 ~wxXmlResourceDataRecord() {delete Doc
;}
68 class wxXmlResourceDataRecords
: public wxVector
<wxXmlResourceDataRecord
*>
70 // this is a class so that it can be forward-declared
76 // helper used by DoFindResource() and elsewhere: returns true if this is an
77 // object or object_ref node
79 // node must be non-NULL
80 inline bool IsObjectNode(wxXmlNode
*node
)
82 return node
->GetType() == wxXML_ELEMENT_NODE
&&
83 (node
->GetName() == wxS("object") ||
84 node
->GetName() == wxS("object_ref"));
87 } // anonymous namespace
90 wxXmlResource
*wxXmlResource::ms_instance
= NULL
;
92 /*static*/ wxXmlResource
*wxXmlResource::Get()
95 ms_instance
= new wxXmlResource
;
99 /*static*/ wxXmlResource
*wxXmlResource::Set(wxXmlResource
*res
)
101 wxXmlResource
*old
= ms_instance
;
106 wxXmlResource::wxXmlResource(int flags
, const wxString
& domain
)
110 m_data
= new wxXmlResourceDataRecords
;
114 wxXmlResource::wxXmlResource(const wxString
& filemask
, int flags
, const wxString
& domain
)
118 m_data
= new wxXmlResourceDataRecords
;
123 wxXmlResource::~wxXmlResource()
127 for ( wxXmlResourceDataRecords::iterator i
= m_data
->begin();
128 i
!= m_data
->end(); ++i
)
135 void wxXmlResource::SetDomain(const wxString
& domain
)
142 wxString
wxXmlResource::ConvertFileNameToURL(const wxString
& filename
)
144 wxString
fnd(filename
);
146 // NB: as Load() and Unload() accept both filenames and URLs (should
147 // probably be changed to filenames only, but embedded resources
148 // currently rely on its ability to handle URLs - FIXME) we need to
149 // determine whether found name is filename and not URL and this is the
150 // fastest/simplest way to do it
151 if (wxFileName::FileExists(fnd
))
153 // Make the name absolute filename, because the app may
154 // change working directory later:
159 fnd
= fn
.GetFullPath();
162 fnd
= wxFileSystem::FileNameToURL(fnd
);
172 bool wxXmlResource::IsArchive(const wxString
& filename
)
174 const wxString fnd
= filename
.Lower();
176 return fnd
.Matches(wxT("*.zip")) || fnd
.Matches(wxT("*.xrs"));
179 #endif // wxUSE_FILESYSTEM
181 bool wxXmlResource::LoadFile(const wxFileName
& file
)
184 return Load(wxFileSystem::FileNameToURL(file
));
186 return Load(file
.GetFullPath());
190 bool wxXmlResource::LoadAllFiles(const wxString
& dirname
)
195 wxDir::GetAllFiles(dirname
, &files
, "*.xrc");
197 for ( wxArrayString::const_iterator i
= files
.begin(); i
!= files
.end(); ++i
)
206 bool wxXmlResource::Load(const wxString
& filemask_
)
208 wxString filemask
= ConvertFileNameToURL(filemask_
);
212 # define wxXmlFindFirst fsys.FindFirst(filemask, wxFILE)
213 # define wxXmlFindNext fsys.FindNext()
215 # define wxXmlFindFirst wxFindFirstFile(filemask, wxFILE)
216 # define wxXmlFindNext wxFindNextFile()
218 wxString fnd
= wxXmlFindFirst
;
221 wxLogError(_("Cannot load resources from '%s'."), filemask
);
228 if ( IsArchive(fnd
) )
230 if ( !Load(fnd
+ wxT("#zip:*.xrc")) )
233 else // a single resource URL
234 #endif // wxUSE_FILESYSTEM
236 wxXmlResourceDataRecord
*drec
= new wxXmlResourceDataRecord
;
238 Data().push_back(drec
);
243 # undef wxXmlFindFirst
244 # undef wxXmlFindNext
246 return UpdateResources();
249 bool wxXmlResource::Unload(const wxString
& filename
)
251 wxASSERT_MSG( !wxIsWild(filename
),
252 _T("wildcards not supported by wxXmlResource::Unload()") );
254 wxString fnd
= ConvertFileNameToURL(filename
);
256 const bool isArchive
= IsArchive(fnd
);
259 #endif // wxUSE_FILESYSTEM
261 bool unloaded
= false;
262 for ( wxXmlResourceDataRecords::iterator i
= Data().begin();
263 i
!= Data().end(); ++i
)
268 if ( (*i
)->File
.StartsWith(fnd
) )
270 // don't break from the loop, we can have other matching files
272 else // a single resource URL
273 #endif // wxUSE_FILESYSTEM
275 if ( (*i
)->File
== fnd
)
281 // no sense in continuing, there is only one file with this URL
291 IMPLEMENT_ABSTRACT_CLASS(wxXmlResourceHandler
, wxObject
)
293 void wxXmlResource::AddHandler(wxXmlResourceHandler
*handler
)
295 m_handlers
.push_back(handler
);
296 handler
->SetParentResource(this);
299 void wxXmlResource::InsertHandler(wxXmlResourceHandler
*handler
)
301 m_handlers
.insert(m_handlers
.begin(), handler
);
302 handler
->SetParentResource(this);
307 void wxXmlResource::ClearHandlers()
309 for ( wxVector
<wxXmlResourceHandler
*>::iterator i
= m_handlers
.begin();
310 i
!= m_handlers
.end(); ++i
)
316 wxMenu
*wxXmlResource::LoadMenu(const wxString
& name
)
318 return (wxMenu
*)CreateResFromNode(FindResource(name
, wxT("wxMenu")), NULL
, NULL
);
323 wxMenuBar
*wxXmlResource::LoadMenuBar(wxWindow
*parent
, const wxString
& name
)
325 return (wxMenuBar
*)CreateResFromNode(FindResource(name
, wxT("wxMenuBar")), parent
, NULL
);
331 wxToolBar
*wxXmlResource::LoadToolBar(wxWindow
*parent
, const wxString
& name
)
333 return (wxToolBar
*)CreateResFromNode(FindResource(name
, wxT("wxToolBar")), parent
, NULL
);
338 wxDialog
*wxXmlResource::LoadDialog(wxWindow
*parent
, const wxString
& name
)
340 return (wxDialog
*)CreateResFromNode(FindResource(name
, wxT("wxDialog")), parent
, NULL
);
343 bool wxXmlResource::LoadDialog(wxDialog
*dlg
, wxWindow
*parent
, const wxString
& name
)
345 return CreateResFromNode(FindResource(name
, wxT("wxDialog")), parent
, dlg
) != NULL
;
350 wxPanel
*wxXmlResource::LoadPanel(wxWindow
*parent
, const wxString
& name
)
352 return (wxPanel
*)CreateResFromNode(FindResource(name
, wxT("wxPanel")), parent
, NULL
);
355 bool wxXmlResource::LoadPanel(wxPanel
*panel
, wxWindow
*parent
, const wxString
& name
)
357 return CreateResFromNode(FindResource(name
, wxT("wxPanel")), parent
, panel
) != NULL
;
360 wxFrame
*wxXmlResource::LoadFrame(wxWindow
* parent
, const wxString
& name
)
362 return (wxFrame
*)CreateResFromNode(FindResource(name
, wxT("wxFrame")), parent
, NULL
);
365 bool wxXmlResource::LoadFrame(wxFrame
* frame
, wxWindow
*parent
, const wxString
& name
)
367 return CreateResFromNode(FindResource(name
, wxT("wxFrame")), parent
, frame
) != NULL
;
370 wxBitmap
wxXmlResource::LoadBitmap(const wxString
& name
)
372 wxBitmap
*bmp
= (wxBitmap
*)CreateResFromNode(
373 FindResource(name
, wxT("wxBitmap")), NULL
, NULL
);
376 if (bmp
) { rt
= *bmp
; delete bmp
; }
380 wxIcon
wxXmlResource::LoadIcon(const wxString
& name
)
382 wxIcon
*icon
= (wxIcon
*)CreateResFromNode(
383 FindResource(name
, wxT("wxIcon")), NULL
, NULL
);
386 if (icon
) { rt
= *icon
; delete icon
; }
391 wxObject
*wxXmlResource::LoadObject(wxWindow
*parent
, const wxString
& name
, const wxString
& classname
)
393 return CreateResFromNode(FindResource(name
, classname
), parent
, NULL
);
396 bool wxXmlResource::LoadObject(wxObject
*instance
, wxWindow
*parent
, const wxString
& name
, const wxString
& classname
)
398 return CreateResFromNode(FindResource(name
, classname
), parent
, instance
) != NULL
;
402 bool wxXmlResource::AttachUnknownControl(const wxString
& name
,
403 wxWindow
*control
, wxWindow
*parent
)
406 parent
= control
->GetParent();
407 wxWindow
*container
= parent
->FindWindow(name
+ wxT("_container"));
410 wxLogError("Cannot find container for unknown control '%s'.", name
);
413 return control
->Reparent(container
);
417 static void ProcessPlatformProperty(wxXmlNode
*node
)
422 wxXmlNode
*c
= node
->GetChildren();
426 if (!c
->GetAttribute(wxT("platform"), &s
))
430 wxStringTokenizer
tkn(s
, wxT(" |"));
432 while (tkn
.HasMoreTokens())
434 s
= tkn
.GetNextToken();
436 if (s
== wxT("win")) isok
= true;
438 #if defined(__MAC__) || defined(__APPLE__)
439 if (s
== wxT("mac")) isok
= true;
440 #elif defined(__UNIX__)
441 if (s
== wxT("unix")) isok
= true;
444 if (s
== wxT("os2")) isok
= true;
454 ProcessPlatformProperty(c
);
459 wxXmlNode
*c2
= c
->GetNext();
460 node
->RemoveChild(c
);
469 bool wxXmlResource::UpdateResources()
473 # if wxUSE_FILESYSTEM
474 wxFSFile
*file
= NULL
;
479 wxString
encoding(wxT("UTF-8"));
480 #if !wxUSE_UNICODE && wxUSE_INTL
481 if ( (GetFlags() & wxXRC_USE_LOCALE
) == 0 )
483 // In case we are not using wxLocale to translate strings, convert the
484 // strings GUI's charset. This must not be done when wxXRC_USE_LOCALE
485 // is on, because it could break wxGetTranslation lookup.
486 encoding
= wxLocale::GetSystemEncodingName();
490 for ( wxXmlResourceDataRecords::iterator i
= Data().begin();
491 i
!= Data().end(); ++i
)
493 wxXmlResourceDataRecord
* const rec
= *i
;
495 modif
= (rec
->Doc
== NULL
);
497 if (!modif
&& !(m_flags
& wxXRC_NO_RELOADING
))
499 # if wxUSE_FILESYSTEM
500 file
= fsys
.OpenFile(rec
->File
);
502 modif
= file
&& file
->GetModificationTime() > rec
->Time
;
503 # else // wxUSE_DATETIME
505 # endif // wxUSE_DATETIME
508 wxLogError(_("Cannot open file '%s'."), rec
->File
);
513 # else // wxUSE_FILESYSTEM
515 modif
= wxDateTime(wxFileModificationTime(rec
->File
)) > rec
->Time
;
516 # else // wxUSE_DATETIME
518 # endif // wxUSE_DATETIME
519 # endif // wxUSE_FILESYSTEM
524 wxLogTrace(_T("xrc"), _T("opening file '%s'"), rec
->File
);
526 wxInputStream
*stream
= NULL
;
528 # if wxUSE_FILESYSTEM
529 file
= fsys
.OpenFile(rec
->File
);
531 stream
= file
->GetStream();
533 stream
= new wxFileInputStream(rec
->File
);
539 rec
->Doc
= new wxXmlDocument
;
541 if (!stream
|| !stream
->IsOk() || !rec
->Doc
->Load(*stream
, encoding
))
543 wxLogError(_("Cannot load resources from file '%s'."),
548 else if (rec
->Doc
->GetRoot()->GetName() != wxT("resource"))
553 "invalid XRC resource, doesn't have root node <resource>"
562 wxString verstr
= rec
->Doc
->GetRoot()->GetAttribute(
563 wxT("version"), wxT("0.0.0.0"));
564 if (wxSscanf(verstr
.c_str(), wxT("%i.%i.%i.%i"),
565 &v1
, &v2
, &v3
, &v4
) == 4)
566 version
= v1
*256*256*256+v2
*256*256+v3
*256+v4
;
571 if (m_version
!= version
)
573 wxLogError("Resource files must have same version number.");
577 ProcessPlatformProperty(rec
->Doc
->GetRoot());
580 rec
->Time
= file
->GetModificationTime();
581 #else // wxUSE_FILESYSTEM
582 rec
->Time
= wxDateTime(wxFileModificationTime(rec
->File
));
583 #endif // wxUSE_FILESYSTEM
584 #endif // wxUSE_DATETIME
587 # if wxUSE_FILESYSTEM
599 wxXmlNode
*wxXmlResource::DoFindResource(wxXmlNode
*parent
,
600 const wxString
& name
,
601 const wxString
& classname
,
602 bool recursive
) const
606 // first search for match at the top-level nodes (as this is
607 // where the resource is most commonly looked for):
608 for (node
= parent
->GetChildren(); node
; node
= node
->GetNext())
610 if ( IsObjectNode(node
) && node
->GetAttribute(wxS("name")) == name
)
612 // empty class name matches everything
613 if ( classname
.empty() )
616 wxString
cls(node
->GetAttribute(wxS("class")));
618 // object_ref may not have 'class' attribute:
619 if (cls
.empty() && node
->GetName() == wxS("object_ref"))
621 wxString refName
= node
->GetAttribute(wxS("ref"));
625 const wxXmlNode
* const refNode
= GetResourceNode(refName
);
627 cls
= refNode
->GetAttribute(wxS("class"));
630 if ( cls
== classname
)
635 // then recurse in child nodes
638 for (node
= parent
->GetChildren(); node
; node
= node
->GetNext())
640 if ( IsObjectNode(node
) )
642 wxXmlNode
* found
= DoFindResource(node
, name
, classname
, true);
652 wxXmlNode
*wxXmlResource::FindResource(const wxString
& name
,
653 const wxString
& classname
,
658 node
= GetResourceNodeAndLocation(name
, classname
, recursive
, &path
);
667 "XRC resource \"%s\" (class \"%s\") not found",
673 else // node was found
675 // ensure that relative paths work correctly when loading this node
676 // (which should happen as soon as we return as FindResource() result
677 // is always passed to CreateResFromNode())
678 m_curFileSystem
.ChangePathTo(path
);
680 #endif // wxUSE_FILESYSTEM
686 wxXmlResource::GetResourceNodeAndLocation(const wxString
& name
,
687 const wxString
& classname
,
689 wxString
*path
) const
691 // ensure everything is up-to-date: this is needed to support on-remand
692 // reloading of XRC files
693 const_cast<wxXmlResource
*>(this)->UpdateResources();
695 for ( wxXmlResourceDataRecords::const_iterator f
= Data().begin();
696 f
!= Data().end(); ++f
)
698 wxXmlResourceDataRecord
*const rec
= *f
;
699 wxXmlDocument
* const doc
= rec
->Doc
;
700 if ( !doc
|| !doc
->GetRoot() )
704 found
= DoFindResource(doc
->GetRoot(), name
, classname
, recursive
);
717 static void MergeNodes(wxXmlNode
& dest
, wxXmlNode
& with
)
720 for ( wxXmlAttribute
*attr
= with
.GetAttributes();
721 attr
; attr
= attr
->GetNext() )
723 wxXmlAttribute
*dattr
;
724 for (dattr
= dest
.GetAttributes(); dattr
; dattr
= dattr
->GetNext())
727 if ( dattr
->GetName() == attr
->GetName() )
729 dattr
->SetValue(attr
->GetValue());
735 dest
.AddAttribute(attr
->GetName(), attr
->GetValue());
738 // Merge child nodes:
739 for (wxXmlNode
* node
= with
.GetChildren(); node
; node
= node
->GetNext())
741 wxString name
= node
->GetAttribute(wxT("name"), wxEmptyString
);
744 for (dnode
= dest
.GetChildren(); dnode
; dnode
= dnode
->GetNext() )
746 if ( dnode
->GetName() == node
->GetName() &&
747 dnode
->GetAttribute(wxT("name"), wxEmptyString
) == name
&&
748 dnode
->GetType() == node
->GetType() )
750 MergeNodes(*dnode
, *node
);
757 static const wxChar
*AT_END
= wxT("end");
758 wxString insert_pos
= node
->GetAttribute(wxT("insert_at"), AT_END
);
759 if ( insert_pos
== AT_END
)
761 dest
.AddChild(new wxXmlNode(*node
));
763 else if ( insert_pos
== wxT("begin") )
765 dest
.InsertChild(new wxXmlNode(*node
), dest
.GetChildren());
770 if ( dest
.GetType() == wxXML_TEXT_NODE
&& with
.GetContent().length() )
771 dest
.SetContent(with
.GetContent());
774 wxObject
*wxXmlResource::CreateResFromNode(wxXmlNode
*node
, wxObject
*parent
,
776 wxXmlResourceHandler
*handlerToUse
)
778 if (node
== NULL
) return NULL
;
780 // handling of referenced resource
781 if ( node
->GetName() == wxT("object_ref") )
783 wxString refName
= node
->GetAttribute(wxT("ref"), wxEmptyString
);
784 wxXmlNode
* refNode
= FindResource(refName
, wxEmptyString
, true);
793 "referenced object node with ref=\"%s\" not found",
800 wxXmlNode
copy(*refNode
);
801 MergeNodes(copy
, *node
);
803 return CreateResFromNode(©
, parent
, instance
);
808 if (handlerToUse
->CanHandle(node
))
810 return handlerToUse
->CreateResource(node
, parent
, instance
);
813 else if (node
->GetName() == wxT("object"))
815 for ( wxVector
<wxXmlResourceHandler
*>::iterator h
= m_handlers
.begin();
816 h
!= m_handlers
.end(); ++h
)
818 wxXmlResourceHandler
*handler
= *h
;
819 if (handler
->CanHandle(node
))
820 return handler
->CreateResource(node
, parent
, instance
);
829 "no handler found for XML node \"%s\" (class \"%s\")",
831 node
->GetAttribute("class", wxEmptyString
)
838 class wxXmlSubclassFactories
: public wxVector
<wxXmlSubclassFactory
*>
840 // this is a class so that it can be forward-declared
843 wxXmlSubclassFactories
*wxXmlResource::ms_subclassFactories
= NULL
;
845 /*static*/ void wxXmlResource::AddSubclassFactory(wxXmlSubclassFactory
*factory
)
847 if (!ms_subclassFactories
)
849 ms_subclassFactories
= new wxXmlSubclassFactories
;
851 ms_subclassFactories
->push_back(factory
);
854 class wxXmlSubclassFactoryCXX
: public wxXmlSubclassFactory
857 ~wxXmlSubclassFactoryCXX() {}
859 wxObject
*Create(const wxString
& className
)
861 wxClassInfo
* classInfo
= wxClassInfo::FindClass(className
);
864 return classInfo
->CreateObject();
873 wxXmlResourceHandler::wxXmlResourceHandler()
874 : m_node(NULL
), m_parent(NULL
), m_instance(NULL
),
875 m_parentAsWindow(NULL
)
880 wxObject
*wxXmlResourceHandler::CreateResource(wxXmlNode
*node
, wxObject
*parent
, wxObject
*instance
)
882 wxXmlNode
*myNode
= m_node
;
883 wxString myClass
= m_class
;
884 wxObject
*myParent
= m_parent
, *myInstance
= m_instance
;
885 wxWindow
*myParentAW
= m_parentAsWindow
;
887 m_instance
= instance
;
888 if (!m_instance
&& node
->HasAttribute(wxT("subclass")) &&
889 !(m_resource
->GetFlags() & wxXRC_NO_SUBCLASSING
))
891 wxString subclass
= node
->GetAttribute(wxT("subclass"), wxEmptyString
);
892 if (!subclass
.empty())
894 for (wxXmlSubclassFactories::iterator i
= wxXmlResource::ms_subclassFactories
->begin();
895 i
!= wxXmlResource::ms_subclassFactories
->end(); ++i
)
897 m_instance
= (*i
)->Create(subclass
);
904 wxString name
= node
->GetAttribute(wxT("name"), wxEmptyString
);
910 "subclass \"%s\" not found for resource \"%s\", not subclassing",
919 m_class
= node
->GetAttribute(wxT("class"), wxEmptyString
);
921 m_parentAsWindow
= wxDynamicCast(m_parent
, wxWindow
);
923 wxObject
*returned
= DoCreateResource();
927 m_parent
= myParent
; m_parentAsWindow
= myParentAW
;
928 m_instance
= myInstance
;
934 void wxXmlResourceHandler::AddStyle(const wxString
& name
, int value
)
936 m_styleNames
.Add(name
);
937 m_styleValues
.Add(value
);
942 void wxXmlResourceHandler::AddWindowStyles()
944 XRC_ADD_STYLE(wxCLIP_CHILDREN
);
946 // the border styles all have the old and new names, recognize both for now
947 XRC_ADD_STYLE(wxSIMPLE_BORDER
); XRC_ADD_STYLE(wxBORDER_SIMPLE
);
948 XRC_ADD_STYLE(wxSUNKEN_BORDER
); XRC_ADD_STYLE(wxBORDER_SUNKEN
);
949 XRC_ADD_STYLE(wxDOUBLE_BORDER
); XRC_ADD_STYLE(wxBORDER_DOUBLE
);
950 XRC_ADD_STYLE(wxRAISED_BORDER
); XRC_ADD_STYLE(wxBORDER_RAISED
);
951 XRC_ADD_STYLE(wxSTATIC_BORDER
); XRC_ADD_STYLE(wxBORDER_STATIC
);
952 XRC_ADD_STYLE(wxNO_BORDER
); XRC_ADD_STYLE(wxBORDER_NONE
);
954 XRC_ADD_STYLE(wxTRANSPARENT_WINDOW
);
955 XRC_ADD_STYLE(wxWANTS_CHARS
);
956 XRC_ADD_STYLE(wxTAB_TRAVERSAL
);
957 XRC_ADD_STYLE(wxNO_FULL_REPAINT_ON_RESIZE
);
958 XRC_ADD_STYLE(wxFULL_REPAINT_ON_RESIZE
);
959 XRC_ADD_STYLE(wxALWAYS_SHOW_SB
);
960 XRC_ADD_STYLE(wxWS_EX_BLOCK_EVENTS
);
961 XRC_ADD_STYLE(wxWS_EX_VALIDATE_RECURSIVELY
);
966 bool wxXmlResourceHandler::HasParam(const wxString
& param
)
968 return (GetParamNode(param
) != NULL
);
972 int wxXmlResourceHandler::GetStyle(const wxString
& param
, int defaults
)
974 wxString s
= GetParamValue(param
);
976 if (!s
) return defaults
;
978 wxStringTokenizer
tkn(s
, wxT("| \t\n"), wxTOKEN_STRTOK
);
982 while (tkn
.HasMoreTokens())
984 fl
= tkn
.GetNextToken();
985 index
= m_styleNames
.Index(fl
);
986 if (index
!= wxNOT_FOUND
)
988 style
|= m_styleValues
[index
];
995 wxString::Format("unknown style flag \"%s\"", fl
)
1004 wxString
wxXmlResourceHandler::GetText(const wxString
& param
, bool translate
)
1006 wxXmlNode
*parNode
= GetParamNode(param
);
1007 wxString
str1(GetNodeContent(parNode
));
1010 // "\\" wasn't translated to "\" prior to 2.5.3.0:
1011 const bool escapeBackslash
= (m_resource
->CompareVersion(2,5,3,0) >= 0);
1013 // VS: First version of XRC resources used $ instead of & (which is
1014 // illegal in XML), but later I realized that '_' fits this purpose
1015 // much better (because &File means "File with F underlined").
1016 const wxChar amp_char
= (m_resource
->CompareVersion(2,3,0,1) < 0)
1019 for ( wxString::const_iterator dt
= str1
.begin(); dt
!= str1
.end(); ++dt
)
1021 // Remap amp_char to &, map double amp_char to amp_char (for things
1022 // like "&File..." -- this is illegal in XML, so we use "_File..."):
1023 if ( *dt
== amp_char
)
1025 if ( *(++dt
) == amp_char
)
1028 str2
<< wxT('&') << *dt
;
1030 // Remap \n to CR, \r to LF, \t to TAB, \\ to \:
1031 else if ( *dt
== wxT('\\') )
1033 switch ( (*(++dt
)).GetValue() )
1048 // "\\" wasn't translated to "\" prior to 2.5.3.0:
1049 if ( escapeBackslash
)
1054 // else fall-through to default: branch below
1057 str2
<< wxT('\\') << *dt
;
1067 if (m_resource
->GetFlags() & wxXRC_USE_LOCALE
)
1069 if (translate
&& parNode
&&
1070 parNode
->GetAttribute(wxT("translate"), wxEmptyString
) != wxT("0"))
1072 return wxGetTranslation(str2
, m_resource
->GetDomain());
1079 // The string is internally stored as UTF-8, we have to convert
1080 // it into system's default encoding so that it can be displayed:
1081 return wxString(str2
.wc_str(wxConvUTF8
), wxConvLocal
);
1086 // If wxXRC_USE_LOCALE is not set, then the string is already in
1087 // system's default encoding in ANSI build, so we don't have to
1088 // do anything special here.
1094 long wxXmlResourceHandler::GetLong(const wxString
& param
, long defaultv
)
1097 wxString str1
= GetParamValue(param
);
1099 if (!str1
.ToLong(&value
))
1105 float wxXmlResourceHandler::GetFloat(const wxString
& param
, float defaultv
)
1107 wxString str
= GetParamValue(param
);
1110 // strings in XRC always use C locale but wxString::ToDouble() uses the
1111 // current one, so transform the string to it supposing that the only
1112 // difference between them is the decimal separator
1114 // TODO: use wxString::ToCDouble() when we have it
1115 str
.Replace(wxT("."), wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT
,
1116 wxLOCALE_CAT_NUMBER
));
1117 #endif // wxUSE_INTL
1120 if (!str
.ToDouble(&value
))
1123 return wx_truncate_cast(float, value
);
1127 int wxXmlResourceHandler::GetID()
1129 return wxXmlResource::GetXRCID(GetName());
1134 wxString
wxXmlResourceHandler::GetName()
1136 return m_node
->GetAttribute(wxT("name"), wxT("-1"));
1141 bool wxXmlResourceHandler::GetBoolAttr(const wxString
& attr
, bool defaultv
)
1144 return m_node
->GetAttribute(attr
, &v
) ? v
== '1' : defaultv
;
1147 bool wxXmlResourceHandler::GetBool(const wxString
& param
, bool defaultv
)
1149 const wxString v
= GetParamValue(param
);
1151 return v
.empty() ? defaultv
: (v
== '1');
1155 static wxColour
GetSystemColour(const wxString
& name
)
1159 #define SYSCLR(clr) \
1160 if (name == _T(#clr)) return wxSystemSettings::GetColour(clr);
1161 SYSCLR(wxSYS_COLOUR_SCROLLBAR
)
1162 SYSCLR(wxSYS_COLOUR_BACKGROUND
)
1163 SYSCLR(wxSYS_COLOUR_DESKTOP
)
1164 SYSCLR(wxSYS_COLOUR_ACTIVECAPTION
)
1165 SYSCLR(wxSYS_COLOUR_INACTIVECAPTION
)
1166 SYSCLR(wxSYS_COLOUR_MENU
)
1167 SYSCLR(wxSYS_COLOUR_WINDOW
)
1168 SYSCLR(wxSYS_COLOUR_WINDOWFRAME
)
1169 SYSCLR(wxSYS_COLOUR_MENUTEXT
)
1170 SYSCLR(wxSYS_COLOUR_WINDOWTEXT
)
1171 SYSCLR(wxSYS_COLOUR_CAPTIONTEXT
)
1172 SYSCLR(wxSYS_COLOUR_ACTIVEBORDER
)
1173 SYSCLR(wxSYS_COLOUR_INACTIVEBORDER
)
1174 SYSCLR(wxSYS_COLOUR_APPWORKSPACE
)
1175 SYSCLR(wxSYS_COLOUR_HIGHLIGHT
)
1176 SYSCLR(wxSYS_COLOUR_HIGHLIGHTTEXT
)
1177 SYSCLR(wxSYS_COLOUR_BTNFACE
)
1178 SYSCLR(wxSYS_COLOUR_3DFACE
)
1179 SYSCLR(wxSYS_COLOUR_BTNSHADOW
)
1180 SYSCLR(wxSYS_COLOUR_3DSHADOW
)
1181 SYSCLR(wxSYS_COLOUR_GRAYTEXT
)
1182 SYSCLR(wxSYS_COLOUR_BTNTEXT
)
1183 SYSCLR(wxSYS_COLOUR_INACTIVECAPTIONTEXT
)
1184 SYSCLR(wxSYS_COLOUR_BTNHIGHLIGHT
)
1185 SYSCLR(wxSYS_COLOUR_BTNHILIGHT
)
1186 SYSCLR(wxSYS_COLOUR_3DHIGHLIGHT
)
1187 SYSCLR(wxSYS_COLOUR_3DHILIGHT
)
1188 SYSCLR(wxSYS_COLOUR_3DDKSHADOW
)
1189 SYSCLR(wxSYS_COLOUR_3DLIGHT
)
1190 SYSCLR(wxSYS_COLOUR_INFOTEXT
)
1191 SYSCLR(wxSYS_COLOUR_INFOBK
)
1192 SYSCLR(wxSYS_COLOUR_LISTBOX
)
1193 SYSCLR(wxSYS_COLOUR_HOTLIGHT
)
1194 SYSCLR(wxSYS_COLOUR_GRADIENTACTIVECAPTION
)
1195 SYSCLR(wxSYS_COLOUR_GRADIENTINACTIVECAPTION
)
1196 SYSCLR(wxSYS_COLOUR_MENUHILIGHT
)
1197 SYSCLR(wxSYS_COLOUR_MENUBAR
)
1201 return wxNullColour
;
1204 wxColour
wxXmlResourceHandler::GetColour(const wxString
& param
, const wxColour
& defaultv
)
1206 wxString v
= GetParamValue(param
);
1213 // wxString -> wxColour conversion
1216 // the colour doesn't use #RRGGBB format, check if it is symbolic
1218 clr
= GetSystemColour(v
);
1225 wxString::Format("incorrect colour specification \"%s\"", v
)
1227 return wxNullColour
;
1235 wxBitmap
wxXmlResourceHandler::GetBitmap(const wxString
& param
,
1236 const wxArtClient
& defaultArtClient
,
1239 /* If the bitmap is specified as stock item, query wxArtProvider for it: */
1240 wxXmlNode
*bmpNode
= GetParamNode(param
);
1243 wxString sid
= bmpNode
->GetAttribute(wxT("stock_id"), wxEmptyString
);
1246 wxString scl
= bmpNode
->GetAttribute(wxT("stock_client"), wxEmptyString
);
1248 scl
= defaultArtClient
;
1250 scl
= wxART_MAKE_CLIENT_ID_FROM_STR(scl
);
1253 wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(sid
),
1255 if ( stockArt
.Ok() )
1260 /* ...or load the bitmap from file: */
1261 wxString name
= GetParamValue(param
);
1262 if (name
.empty()) return wxNullBitmap
;
1263 #if wxUSE_FILESYSTEM
1264 wxFSFile
*fsfile
= GetCurFileSystem().OpenFile(name
, wxFS_READ
| wxFS_SEEKABLE
);
1270 wxString::Format("cannot open bitmap resource \"%s\"", name
)
1272 return wxNullBitmap
;
1274 wxImage
img(*(fsfile
->GetStream()));
1285 wxString::Format("cannot create bitmap from \"%s\"", name
)
1287 return wxNullBitmap
;
1289 if (!(size
== wxDefaultSize
)) img
.Rescale(size
.x
, size
.y
);
1290 return wxBitmap(img
);
1294 wxIcon
wxXmlResourceHandler::GetIcon(const wxString
& param
,
1295 const wxArtClient
& defaultArtClient
,
1299 icon
.CopyFromBitmap(GetBitmap(param
, defaultArtClient
, size
));
1305 wxXmlNode
*wxXmlResourceHandler::GetParamNode(const wxString
& param
)
1307 wxCHECK_MSG(m_node
, NULL
, wxT("You can't access handler data before it was initialized!"));
1309 wxXmlNode
*n
= m_node
->GetChildren();
1313 if (n
->GetType() == wxXML_ELEMENT_NODE
&& n
->GetName() == param
)
1315 // TODO: check that there are no other properties/parameters with
1316 // the same name and log an error if there are (can't do this
1317 // right now as I'm not sure if it's not going to break code
1318 // using this function in unintentional way (i.e. for
1319 // accessing other things than properties), for example
1320 // wxBitmapComboBoxXmlHandler almost surely does
1328 bool wxXmlResourceHandler::IsOfClass(wxXmlNode
*node
, const wxString
& classname
)
1330 return node
->GetAttribute(wxT("class"), wxEmptyString
) == classname
;
1335 wxString
wxXmlResourceHandler::GetNodeContent(wxXmlNode
*node
)
1337 wxXmlNode
*n
= node
;
1338 if (n
== NULL
) return wxEmptyString
;
1339 n
= n
->GetChildren();
1343 if (n
->GetType() == wxXML_TEXT_NODE
||
1344 n
->GetType() == wxXML_CDATA_SECTION_NODE
)
1345 return n
->GetContent();
1348 return wxEmptyString
;
1353 wxString
wxXmlResourceHandler::GetParamValue(const wxString
& param
)
1356 return GetNodeContent(m_node
);
1358 return GetNodeContent(GetParamNode(param
));
1363 wxSize
wxXmlResourceHandler::GetSize(const wxString
& param
,
1364 wxWindow
*windowToUse
)
1366 wxString s
= GetParamValue(param
);
1367 if (s
.empty()) s
= wxT("-1,-1");
1371 is_dlg
= s
[s
.length()-1] == wxT('d');
1372 if (is_dlg
) s
.RemoveLast();
1374 if (!s
.BeforeFirst(wxT(',')).ToLong(&sx
) ||
1375 !s
.AfterLast(wxT(',')).ToLong(&sy
))
1380 wxString::Format("cannot parse coordinates value \"%s\"", s
)
1382 return wxDefaultSize
;
1389 return wxDLG_UNIT(windowToUse
, wxSize(sx
, sy
));
1391 else if (m_parentAsWindow
)
1393 return wxDLG_UNIT(m_parentAsWindow
, wxSize(sx
, sy
));
1400 "cannot convert dialog units: dialog unknown"
1402 return wxDefaultSize
;
1406 return wxSize(sx
, sy
);
1411 wxPoint
wxXmlResourceHandler::GetPosition(const wxString
& param
)
1413 wxSize sz
= GetSize(param
);
1414 return wxPoint(sz
.x
, sz
.y
);
1419 wxCoord
wxXmlResourceHandler::GetDimension(const wxString
& param
,
1421 wxWindow
*windowToUse
)
1423 wxString s
= GetParamValue(param
);
1424 if (s
.empty()) return defaultv
;
1428 is_dlg
= s
[s
.length()-1] == wxT('d');
1429 if (is_dlg
) s
.RemoveLast();
1436 wxString::Format("cannot parse dimension value \"%s\"", s
)
1445 return wxDLG_UNIT(windowToUse
, wxSize(sx
, 0)).x
;
1447 else if (m_parentAsWindow
)
1449 return wxDLG_UNIT(m_parentAsWindow
, wxSize(sx
, 0)).x
;
1456 "cannot convert dialog units: dialog unknown"
1466 // Get system font index using indexname
1467 static wxFont
GetSystemFont(const wxString
& name
)
1471 #define SYSFNT(fnt) \
1472 if (name == _T(#fnt)) return wxSystemSettings::GetFont(fnt);
1473 SYSFNT(wxSYS_OEM_FIXED_FONT
)
1474 SYSFNT(wxSYS_ANSI_FIXED_FONT
)
1475 SYSFNT(wxSYS_ANSI_VAR_FONT
)
1476 SYSFNT(wxSYS_SYSTEM_FONT
)
1477 SYSFNT(wxSYS_DEVICE_DEFAULT_FONT
)
1478 SYSFNT(wxSYS_SYSTEM_FIXED_FONT
)
1479 SYSFNT(wxSYS_DEFAULT_GUI_FONT
)
1486 wxFont
wxXmlResourceHandler::GetFont(const wxString
& param
)
1488 wxXmlNode
*font_node
= GetParamNode(param
);
1489 if (font_node
== NULL
)
1492 wxString::Format("cannot find font node \"%s\"", param
));
1496 wxXmlNode
*oldnode
= m_node
;
1503 bool hasSize
= HasParam(wxT("size"));
1505 isize
= GetLong(wxT("size"), -1);
1508 int istyle
= wxNORMAL
;
1509 bool hasStyle
= HasParam(wxT("style"));
1512 wxString style
= GetParamValue(wxT("style"));
1513 if (style
== wxT("italic"))
1515 else if (style
== wxT("slant"))
1520 int iweight
= wxNORMAL
;
1521 bool hasWeight
= HasParam(wxT("weight"));
1524 wxString weight
= GetParamValue(wxT("weight"));
1525 if (weight
== wxT("bold"))
1527 else if (weight
== wxT("light"))
1532 bool hasUnderlined
= HasParam(wxT("underlined"));
1533 bool underlined
= hasUnderlined
? GetBool(wxT("underlined"), false) : false;
1535 // family and facename
1536 int ifamily
= wxDEFAULT
;
1537 bool hasFamily
= HasParam(wxT("family"));
1540 wxString family
= GetParamValue(wxT("family"));
1541 if (family
== wxT("decorative")) ifamily
= wxDECORATIVE
;
1542 else if (family
== wxT("roman")) ifamily
= wxROMAN
;
1543 else if (family
== wxT("script")) ifamily
= wxSCRIPT
;
1544 else if (family
== wxT("swiss")) ifamily
= wxSWISS
;
1545 else if (family
== wxT("modern")) ifamily
= wxMODERN
;
1546 else if (family
== wxT("teletype")) ifamily
= wxTELETYPE
;
1551 bool hasFacename
= HasParam(wxT("face"));
1554 wxString faces
= GetParamValue(wxT("face"));
1555 wxStringTokenizer
tk(faces
, wxT(","));
1557 wxArrayString
facenames(wxFontEnumerator::GetFacenames());
1558 while (tk
.HasMoreTokens())
1560 int index
= facenames
.Index(tk
.GetNextToken(), false);
1561 if (index
!= wxNOT_FOUND
)
1563 facename
= facenames
[index
];
1567 #else // !wxUSE_FONTENUM
1568 // just use the first face name if we can't check its availability:
1569 if (tk
.HasMoreTokens())
1570 facename
= tk
.GetNextToken();
1571 #endif // wxUSE_FONTENUM/!wxUSE_FONTENUM
1575 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
1576 bool hasEncoding
= HasParam(wxT("encoding"));
1579 wxString encoding
= GetParamValue(wxT("encoding"));
1580 wxFontMapper mapper
;
1581 if (!encoding
.empty())
1582 enc
= mapper
.CharsetToEncoding(encoding
);
1583 if (enc
== wxFONTENCODING_SYSTEM
)
1584 enc
= wxFONTENCODING_DEFAULT
;
1587 // is this font based on a system font?
1588 wxFont font
= GetSystemFont(GetParamValue(wxT("sysfont")));
1592 if (hasSize
&& isize
!= -1)
1593 font
.SetPointSize(isize
);
1594 else if (HasParam(wxT("relativesize")))
1595 font
.SetPointSize(int(font
.GetPointSize() *
1596 GetFloat(wxT("relativesize"))));
1599 font
.SetStyle(istyle
);
1601 font
.SetWeight(iweight
);
1603 font
.SetUnderlined(underlined
);
1605 font
.SetFamily(ifamily
);
1607 font
.SetFaceName(facename
);
1609 font
.SetDefaultEncoding(enc
);
1611 else // not based on system font
1613 font
= wxFont(isize
== -1 ? wxNORMAL_FONT
->GetPointSize() : isize
,
1614 ifamily
, istyle
, iweight
,
1615 underlined
, facename
, enc
);
1623 void wxXmlResourceHandler::SetupWindow(wxWindow
*wnd
)
1625 //FIXME : add cursor
1627 if (HasParam(wxT("exstyle")))
1628 // Have to OR it with existing style, since
1629 // some implementations (e.g. wxGTK) use the extra style
1631 wnd
->SetExtraStyle(wnd
->GetExtraStyle() | GetStyle(wxT("exstyle")));
1632 if (HasParam(wxT("bg")))
1633 wnd
->SetBackgroundColour(GetColour(wxT("bg")));
1634 if (HasParam(wxT("fg")))
1635 wnd
->SetForegroundColour(GetColour(wxT("fg")));
1636 if (GetBool(wxT("enabled"), 1) == 0)
1638 if (GetBool(wxT("focused"), 0) == 1)
1640 if (GetBool(wxT("hidden"), 0) == 1)
1643 if (HasParam(wxT("tooltip")))
1644 wnd
->SetToolTip(GetText(wxT("tooltip")));
1646 if (HasParam(wxT("font")))
1647 wnd
->SetFont(GetFont());
1648 if (HasParam(wxT("help")))
1649 wnd
->SetHelpText(GetText(wxT("help")));
1653 void wxXmlResourceHandler::CreateChildren(wxObject
*parent
, bool this_hnd_only
)
1655 for ( wxXmlNode
*n
= m_node
->GetChildren(); n
; n
= n
->GetNext() )
1657 if ( IsObjectNode(n
) )
1659 m_resource
->CreateResFromNode(n
, parent
, NULL
,
1660 this_hnd_only
? this : NULL
);
1666 void wxXmlResourceHandler::CreateChildrenPrivately(wxObject
*parent
, wxXmlNode
*rootnode
)
1669 if (rootnode
== NULL
) root
= m_node
; else root
= rootnode
;
1670 wxXmlNode
*n
= root
->GetChildren();
1674 if (n
->GetType() == wxXML_ELEMENT_NODE
&& CanHandle(n
))
1676 CreateResource(n
, parent
, NULL
);
1683 //-----------------------------------------------------------------------------
1685 //-----------------------------------------------------------------------------
1687 void wxXmlResourceHandler::ReportError(const wxString
& message
)
1689 m_resource
->ReportError(m_node
, message
);
1692 void wxXmlResourceHandler::ReportError(wxXmlNode
*context
,
1693 const wxString
& message
)
1695 m_resource
->ReportError(context
? context
: m_node
, message
);
1698 void wxXmlResourceHandler::ReportParamError(const wxString
& param
,
1699 const wxString
& message
)
1701 m_resource
->ReportError(GetParamNode(param
), message
);
1708 GetFileNameFromNode(wxXmlNode
*node
, const wxXmlResourceDataRecords
& files
)
1710 wxXmlNode
*root
= node
;
1711 while ( root
->GetParent() )
1712 root
= root
->GetParent();
1714 for ( wxXmlResourceDataRecords::const_iterator i
= files
.begin();
1715 i
!= files
.end(); ++i
)
1717 if ( (*i
)->Doc
->GetRoot() == root
)
1723 return wxEmptyString
; // not found
1726 } // anonymous namespace
1728 void wxXmlResource::ReportError(wxXmlNode
*context
, const wxString
& message
)
1732 DoReportError("", NULL
, message
);
1736 // We need to find out the file that 'context' is part of. Performance of
1737 // this code is not critical, so we simply find the root XML node and
1738 // compare it with all loaded XRC files.
1739 const wxString filename
= GetFileNameFromNode(context
, Data());
1741 DoReportError(filename
, context
, message
);
1744 void wxXmlResource::DoReportError(const wxString
& xrcFile
, wxXmlNode
*position
,
1745 const wxString
& message
)
1747 const int line
= position
? position
->GetLineNumber() : -1;
1750 if ( !xrcFile
.empty() )
1751 loc
= xrcFile
+ ':';
1753 loc
+= wxString::Format("%d:", line
);
1757 wxLogError("XRC error: %s%s", loc
, message
);
1761 //-----------------------------------------------------------------------------
1762 // XRCID implementation
1763 //-----------------------------------------------------------------------------
1765 #define XRCID_TABLE_SIZE 1024
1770 /* Hold the id so that once an id is allocated for a name, it
1771 does not get created again by NewControlId at least
1772 until we are done with it */
1778 static XRCID_record
*XRCID_Records
[XRCID_TABLE_SIZE
] = {NULL
};
1780 static int XRCID_Lookup(const char *str_id
, int value_if_not_found
= wxID_NONE
)
1784 for (const char *c
= str_id
; *c
!= '\0'; c
++) index
+= (int)*c
;
1785 index
%= XRCID_TABLE_SIZE
;
1787 XRCID_record
*oldrec
= NULL
;
1788 for (XRCID_record
*rec
= XRCID_Records
[index
]; rec
; rec
= rec
->next
)
1790 if (wxStrcmp(rec
->key
, str_id
) == 0)
1797 XRCID_record
**rec_var
= (oldrec
== NULL
) ?
1798 &XRCID_Records
[index
] : &oldrec
->next
;
1799 *rec_var
= new XRCID_record
;
1800 (*rec_var
)->key
= wxStrdup(str_id
);
1801 (*rec_var
)->next
= NULL
;
1804 if (value_if_not_found
!= wxID_NONE
)
1805 (*rec_var
)->id
= value_if_not_found
;
1808 int asint
= wxStrtol(str_id
, &end
, 10);
1809 if (*str_id
&& *end
== 0)
1811 // if str_id was integer, keep it verbosely:
1812 (*rec_var
)->id
= asint
;
1816 (*rec_var
)->id
= wxWindowBase::NewControlId();
1820 return (*rec_var
)->id
;
1823 static void AddStdXRCID_Records();
1826 int wxXmlResource::DoGetXRCID(const char *str_id
, int value_if_not_found
)
1828 static bool s_stdIDsAdded
= false;
1830 if ( !s_stdIDsAdded
)
1832 s_stdIDsAdded
= true;
1833 AddStdXRCID_Records();
1836 return XRCID_Lookup(str_id
, value_if_not_found
);
1840 wxString
wxXmlResource::FindXRCIDById(int numId
)
1842 for ( int i
= 0; i
< XRCID_TABLE_SIZE
; i
++ )
1844 for ( XRCID_record
*rec
= XRCID_Records
[i
]; rec
; rec
= rec
->next
)
1846 if ( rec
->id
== numId
)
1847 return wxString(rec
->key
);
1854 static void CleanXRCID_Record(XRCID_record
*rec
)
1858 CleanXRCID_Record(rec
->next
);
1865 static void CleanXRCID_Records()
1867 for (int i
= 0; i
< XRCID_TABLE_SIZE
; i
++)
1869 CleanXRCID_Record(XRCID_Records
[i
]);
1870 XRCID_Records
[i
] = NULL
;
1874 static void AddStdXRCID_Records()
1876 #define stdID(id) XRCID_Lookup(#id, id)
1880 stdID(wxID_SEPARATOR
);
1893 stdID(wxID_PRINT_SETUP
);
1894 stdID(wxID_PAGE_SETUP
);
1895 stdID(wxID_PREVIEW
);
1897 stdID(wxID_HELP_CONTENTS
);
1898 stdID(wxID_HELP_COMMANDS
);
1899 stdID(wxID_HELP_PROCEDURES
);
1900 stdID(wxID_HELP_CONTEXT
);
1901 stdID(wxID_CLOSE_ALL
);
1902 stdID(wxID_PREFERENCES
);
1909 stdID(wxID_DUPLICATE
);
1910 stdID(wxID_SELECTALL
);
1912 stdID(wxID_REPLACE
);
1913 stdID(wxID_REPLACE_ALL
);
1914 stdID(wxID_PROPERTIES
);
1915 stdID(wxID_VIEW_DETAILS
);
1916 stdID(wxID_VIEW_LARGEICONS
);
1917 stdID(wxID_VIEW_SMALLICONS
);
1918 stdID(wxID_VIEW_LIST
);
1919 stdID(wxID_VIEW_SORTDATE
);
1920 stdID(wxID_VIEW_SORTNAME
);
1921 stdID(wxID_VIEW_SORTSIZE
);
1922 stdID(wxID_VIEW_SORTTYPE
);
1938 stdID(wxID_FORWARD
);
1939 stdID(wxID_BACKWARD
);
1940 stdID(wxID_DEFAULT
);
1944 stdID(wxID_CONTEXT_HELP
);
1945 stdID(wxID_YESTOALL
);
1946 stdID(wxID_NOTOALL
);
1955 stdID(wxID_REFRESH
);
1960 stdID(wxID_JUSTIFY_CENTER
);
1961 stdID(wxID_JUSTIFY_FILL
);
1962 stdID(wxID_JUSTIFY_RIGHT
);
1963 stdID(wxID_JUSTIFY_LEFT
);
1964 stdID(wxID_UNDERLINE
);
1966 stdID(wxID_UNINDENT
);
1967 stdID(wxID_ZOOM_100
);
1968 stdID(wxID_ZOOM_FIT
);
1969 stdID(wxID_ZOOM_IN
);
1970 stdID(wxID_ZOOM_OUT
);
1971 stdID(wxID_UNDELETE
);
1972 stdID(wxID_REVERT_TO_SAVED
);
1973 stdID(wxID_SYSTEM_MENU
);
1974 stdID(wxID_CLOSE_FRAME
);
1975 stdID(wxID_MOVE_FRAME
);
1976 stdID(wxID_RESIZE_FRAME
);
1977 stdID(wxID_MAXIMIZE_FRAME
);
1978 stdID(wxID_ICONIZE_FRAME
);
1979 stdID(wxID_RESTORE_FRAME
);
1981 stdID(wxID_CONVERT
);
1982 stdID(wxID_EXECUTE
);
1984 stdID(wxID_HARDDISK
);
1990 stdID(wxID_JUMP_TO
);
1991 stdID(wxID_NETWORK
);
1992 stdID(wxID_SELECT_COLOR
);
1993 stdID(wxID_SELECT_FONT
);
1994 stdID(wxID_SORT_ASCENDING
);
1995 stdID(wxID_SORT_DESCENDING
);
1996 stdID(wxID_SPELL_CHECK
);
1997 stdID(wxID_STRIKETHROUGH
);
2006 //-----------------------------------------------------------------------------
2007 // module and globals
2008 //-----------------------------------------------------------------------------
2010 // normally we would do the cleanup from wxXmlResourceModule::OnExit() but it
2011 // can happen that some XRC records have been created because of the use of
2012 // XRCID() in event tables, which happens during static objects initialization,
2013 // but then the application initialization failed and so the wx modules were
2014 // neither initialized nor cleaned up -- this static object does the cleanup in
2016 static struct wxXRCStaticCleanup
2018 ~wxXRCStaticCleanup() { CleanXRCID_Records(); }
2021 class wxXmlResourceModule
: public wxModule
2023 DECLARE_DYNAMIC_CLASS(wxXmlResourceModule
)
2025 wxXmlResourceModule() {}
2028 wxXmlResource::AddSubclassFactory(new wxXmlSubclassFactoryCXX
);
2033 delete wxXmlResource::Set(NULL
);
2034 if(wxXmlResource::ms_subclassFactories
)
2036 for ( wxXmlSubclassFactories::iterator i
= wxXmlResource::ms_subclassFactories
->begin();
2037 i
!= wxXmlResource::ms_subclassFactories
->end(); ++i
)
2041 wxDELETE(wxXmlResource::ms_subclassFactories
);
2043 CleanXRCID_Records();
2047 IMPLEMENT_DYNAMIC_CLASS(wxXmlResourceModule
, wxModule
)
2050 // When wxXml is loaded dynamically after the application is already running
2051 // then the built-in module system won't pick this one up. Add it manually.
2052 void wxXmlInitResourceModule()
2054 wxModule
* module = new wxXmlResourceModule
;
2056 wxModule::RegisterModule(module);