1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: XML resources
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2000 Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "xmlres.h"
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
22 #include "wx/dialog.h"
25 #include "wx/wfstream.h"
26 #include "wx/filesys.h"
29 #include "wx/tokenzr.h"
30 #include "wx/fontenum.h"
31 #include "wx/module.h"
32 #include "wx/bitmap.h"
34 #include "wx/fontmap.h"
36 #include "wx/xml/xml.h"
37 #include "wx/xml/xmlres.h"
39 #include "wx/arrimpl.cpp"
40 WX_DEFINE_OBJARRAY(wxXmlResourceDataRecords
);
43 wxXmlResource::wxXmlResource(bool use_locale
)
45 m_handlers
.DeleteContents(TRUE
);
46 m_useLocale
= use_locale
;
50 wxXmlResource::wxXmlResource(const wxString
& filemask
, bool use_locale
)
52 m_useLocale
= use_locale
;
54 m_handlers
.DeleteContents(TRUE
);
58 wxXmlResource::~wxXmlResource()
64 bool wxXmlResource::Load(const wxString
& filemask
)
67 wxXmlResourceDataRecord
*drec
;
68 bool iswild
= wxIsWild(filemask
);
73 # define wxXmlFindFirst fsys.FindFirst(filemask, wxFILE)
74 # define wxXmlFindNext fsys.FindNext()
76 # define wxXmlFindFirst wxFindFirstFile(filemask, wxFILE)
77 # define wxXmlFindNext wxFindNextFile()
86 if (filemask
.Lower().Matches("*.zip") ||
87 filemask
.Lower().Matches("*.rsc"))
89 rt
= rt
&& Load(fnd
+ wxT("#zip:*.xmb"));
90 rt
= rt
&& Load(fnd
+ wxT("#zip:*.xrc"));
95 drec
= new wxXmlResourceDataRecord
;
105 # undef wxXmlFindFirst
106 # undef wxXmlFindNext
112 void wxXmlResource::AddHandler(wxXmlResourceHandler
*handler
)
114 m_handlers
.Append(handler
);
115 handler
->SetParentResource(this);
120 void wxXmlResource::ClearHandlers()
127 wxMenu
*wxXmlResource::LoadMenu(const wxString
& name
)
129 return (wxMenu
*)CreateResFromNode(FindResource(name
, wxT("wxMenu")), NULL
, NULL
);
134 wxMenuBar
*wxXmlResource::LoadMenuBar(const wxString
& name
)
136 return (wxMenuBar
*)CreateResFromNode(FindResource(name
, wxT("wxMenuBar")), NULL
, NULL
);
141 wxToolBar
*wxXmlResource::LoadToolBar(wxWindow
*parent
, const wxString
& name
)
143 return (wxToolBar
*)CreateResFromNode(FindResource(name
, wxT("wxToolBar")), parent
, NULL
);
148 wxDialog
*wxXmlResource::LoadDialog(wxWindow
*parent
, const wxString
& name
)
150 wxDialog
*dialog
= new wxDialog
;
151 if (!LoadDialog(dialog
, parent
, name
))
152 { delete dialog
; return NULL
; }
156 bool wxXmlResource::LoadDialog(wxDialog
*dlg
, wxWindow
*parent
, const wxString
& name
)
158 return CreateResFromNode(FindResource(name
, wxT("wxDialog")), parent
, dlg
) != NULL
;
163 wxPanel
*wxXmlResource::LoadPanel(wxWindow
*parent
, const wxString
& name
)
165 return (wxPanel
*)CreateResFromNode(FindResource(name
, wxT("wxPanel")), parent
, NULL
);
168 bool wxXmlResource::LoadPanel(wxPanel
*panel
, wxWindow
*parent
, const wxString
& name
)
170 return CreateResFromNode(FindResource(name
, wxT("wxPanel")), parent
, panel
) != NULL
;
173 bool wxXmlResource::LoadFrame(wxFrame
* frame
, wxWindow
*parent
, const wxString
& name
)
175 return CreateResFromNode(FindResource(name
, wxT("wxFrame")), parent
, frame
) != NULL
;
178 wxBitmap
wxXmlResource::LoadBitmap(const wxString
& name
)
180 wxBitmap
*bmp
= (wxBitmap
*)CreateResFromNode(
181 FindResource(name
, wxT("wxBitmap")), NULL
, NULL
);
184 if (bmp
) { rt
= *bmp
; delete bmp
; }
188 wxIcon
wxXmlResource::LoadIcon(const wxString
& name
)
190 wxIcon
*icon
= (wxIcon
*)CreateResFromNode(
191 FindResource(name
, wxT("wxIcon")), NULL
, NULL
);
194 if (icon
) { rt
= *icon
; delete icon
; }
200 void wxXmlResource::ProcessPlatformProperty(wxXmlNode
*node
)
205 wxXmlNode
*c
= node
->GetChildren();
209 if (!c
->GetPropVal(wxT("platform"), &s
))
213 wxStringTokenizer
tkn(s
, " |");
215 while (tkn
.HasMoreTokens())
217 s
= tkn
.GetNextToken();
220 s
== wxString(wxT("win"))
221 #elif defined(__UNIX__)
222 s
== wxString(wxT("unix"))
223 #elif defined(__MAC__)
224 s
== wxString(wxT("mac"))
225 #elif defined(__OS2__)
226 s
== wxString(wxT("os2"))
235 ProcessPlatformProperty(c
);
238 node
->RemoveChild(c
);
248 void wxXmlResource::UpdateResources()
251 # if wxUSE_FILESYSTEM
252 wxFSFile
*file
= NULL
;
256 for (size_t i
= 0; i
< m_data
.GetCount(); i
++)
258 modif
= (m_data
[i
].Doc
== NULL
);
262 # if wxUSE_FILESYSTEM
263 file
= fsys
.OpenFile(m_data
[i
].File
);
264 modif
= file
&& file
->GetModificationTime() > m_data
[i
].Time
;
266 wxLogError(_("Cannot open file '%s'."), m_data
[i
].File
.c_str());
269 modif
= wxDateTime(wxFileModificationTime(m_data
[i
].File
)) > m_data
[i
].Time
;
275 wxInputStream
*stream
= NULL
;
277 # if wxUSE_FILESYSTEM
278 file
= fsys
.OpenFile(m_data
[i
].File
);
280 stream
= file
->GetStream();
282 stream
= new wxFileInputStream(m_data
[i
].File
);
287 delete m_data
[i
].Doc
;
288 m_data
[i
].Doc
= new wxXmlDocument
;
290 if (!stream
|| !m_data
[i
].Doc
->Load(*stream
))
292 wxLogError(_("Cannot load resources from file '%s'."), m_data
[i
].File
.c_str());
293 wxDELETE(m_data
[i
].Doc
);
295 else if (m_data
[i
].Doc
->GetRoot()->GetName() != wxT("resource"))
297 wxLogError(_("Invalid XML resource '%s': doesn't have root node 'resource'."), m_data
[i
].File
.c_str());
298 wxDELETE(m_data
[i
].Doc
);
304 wxString verstr
= m_data
[i
].Doc
->GetRoot()->GetPropVal(
305 wxT("version"), wxT("0.0.0.0"));
306 if (wxSscanf(verstr
.c_str(), wxT("%i.%i.%i.%i"),
307 &v1
, &v2
, &v3
, &v4
) == 4)
308 version
= v1
*256*256*256+v2
*256*256+v3
*256+v4
;
313 if (m_version
!= version
)
314 wxLogError(_("Resource files must have same version number!"));
316 ProcessPlatformProperty(m_data
[i
].Doc
->GetRoot());
317 m_data
[i
].Time
= file
->GetModificationTime();
320 # if wxUSE_FILESYSTEM
331 wxXmlNode
*wxXmlResource::FindResource(const wxString
& name
, const wxString
& classname
)
333 UpdateResources(); //ensure everything is up-to-date
336 for (size_t f
= 0; f
< m_data
.GetCount(); f
++)
338 if (m_data
[f
].Doc
== NULL
|| m_data
[f
].Doc
->GetRoot() == NULL
) continue;
339 for (wxXmlNode
*node
= m_data
[f
].Doc
->GetRoot()->GetChildren();
340 node
; node
= node
->GetNext())
341 if (node
->GetType() == wxXML_ELEMENT_NODE
&&
343 node
->GetPropVal(wxT("class"), wxEmptyString
) == classname
) &&
344 node
->GetName() == wxT("object") &&
345 node
->GetPropVal(wxT("name"), &dummy
) &&
349 m_curFileSystem
.ChangePathTo(m_data
[f
].File
);
355 wxLogError(_("XML resource '%s' (class '%s') not found!"),
356 name
.c_str(), classname
.c_str());
362 wxObject
*wxXmlResource::CreateResFromNode(wxXmlNode
*node
, wxObject
*parent
, wxObject
*instance
)
364 if (node
== NULL
) return NULL
;
366 wxXmlResourceHandler
*handler
;
368 wxNode
* ND
= m_handlers
.GetFirst();
371 handler
= (wxXmlResourceHandler
*)ND
->GetData();
372 if (node
->GetName() == wxT("object") && handler
->CanHandle(node
))
374 ret
= handler
->CreateResource(node
, parent
, instance
);
380 wxLogError(_("No handler found for XML node '%s', class '%s'!"),
381 node
->GetName().c_str(),
382 node
->GetPropVal(wxT("class"), wxEmptyString
).c_str());
394 wxXmlResourceHandler::wxXmlResourceHandler()
395 : m_node(NULL
), m_parent(NULL
), m_instance(NULL
),
396 m_parentAsWindow(NULL
), m_instanceAsWindow(NULL
)
401 wxObject
*wxXmlResourceHandler::CreateResource(wxXmlNode
*node
, wxObject
*parent
, wxObject
*instance
)
403 wxXmlNode
*myNode
= m_node
;
404 wxString myClass
= m_class
;
405 wxObject
*myParent
= m_parent
, *myInstance
= m_instance
;
406 wxWindow
*myParentAW
= m_parentAsWindow
, *myInstanceAW
= m_instanceAsWindow
;
409 m_class
= node
->GetPropVal(wxT("class"), wxEmptyString
);
411 m_instance
= instance
;
412 m_parentAsWindow
= wxDynamicCast(m_parent
, wxWindow
);
413 m_instanceAsWindow
= wxDynamicCast(m_instance
, wxWindow
);
415 wxObject
*returned
= DoCreateResource();
419 m_parent
= myParent
; m_parentAsWindow
= myParentAW
;
420 m_instance
= myInstance
; m_instanceAsWindow
= myInstanceAW
;
426 void wxXmlResourceHandler::AddStyle(const wxString
& name
, int value
)
428 m_styleNames
.Add(name
);
429 m_styleValues
.Add(value
);
434 void wxXmlResourceHandler::AddWindowStyles()
436 ADD_STYLE(wxSIMPLE_BORDER
);
437 ADD_STYLE(wxSUNKEN_BORDER
);
438 ADD_STYLE(wxDOUBLE_BORDER
);
439 ADD_STYLE(wxRAISED_BORDER
);
440 ADD_STYLE(wxSTATIC_BORDER
);
441 ADD_STYLE(wxTRANSPARENT_WINDOW
);
442 ADD_STYLE(wxWANTS_CHARS
);
443 ADD_STYLE(wxNO_FULL_REPAINT_ON_RESIZE
);
448 bool wxXmlResourceHandler::HasParam(const wxString
& param
)
450 return (GetParamNode(param
) != NULL
);
454 int wxXmlResourceHandler::GetStyle(const wxString
& param
, int defaults
)
456 wxString s
= GetParamValue(param
);
458 if (!s
) return defaults
;
460 wxStringTokenizer
tkn(s
, wxT("| "), wxTOKEN_STRTOK
);
464 while (tkn
.HasMoreTokens())
466 fl
= tkn
.GetNextToken();
467 index
= m_styleNames
.Index(fl
);
468 if (index
!= wxNOT_FOUND
)
469 style
|= m_styleValues
[index
];
471 wxLogError(_("Unknown style flag ") + fl
);
478 wxString
wxXmlResourceHandler::GetText(const wxString
& param
)
480 wxString str1
= GetParamValue(param
);
485 // VS: First version of XML resources used $ instead of & (which is illegal in XML),
486 // but later I realized that '_' fits this purpose much better (because
487 // &File means "File with F underlined").
488 if (m_resource
->CompareVersion(2,3,0,1) < 0)
493 for (dt
= str1
.c_str(); *dt
; dt
++)
495 // Remap amp_char to &, map double amp_char to amp_char (for things
496 // like "&File..." -- this is illegal in XML, so we use "_File..."):
499 if ( *(++dt
) == amp_char
)
502 str2
<< wxT('&') << *dt
;
504 // Remap \n to CR, \r to LF, \t to TAB:
505 else if (*dt
== wxT('\\'))
508 case wxT('n') : str2
<< wxT('\n'); break;
509 case wxT('t') : str2
<< wxT('\t'); break;
510 case wxT('r') : str2
<< wxT('\r'); break;
511 default : str2
<< wxT('\\') << *dt
; break;
516 if (m_resource
->GetUseLocale())
517 return wxGetTranslation(str2
);
524 long wxXmlResourceHandler::GetLong(const wxString
& param
, long defaultv
)
527 wxString str1
= GetParamValue(param
);
529 if (!str1
.ToLong(&value
))
536 int wxXmlResourceHandler::GetID()
538 wxString sid
= GetName();
541 if (sid
== wxT("-1")) return -1;
542 else if (sid
.IsNumber() && sid
.ToLong(&num
)) return num
;
543 #define stdID(id) else if (sid == wxT(#id)) return id
544 stdID(wxID_OPEN
); stdID(wxID_CLOSE
); stdID(wxID_NEW
);
545 stdID(wxID_SAVE
); stdID(wxID_SAVEAS
); stdID(wxID_REVERT
);
546 stdID(wxID_EXIT
); stdID(wxID_UNDO
); stdID(wxID_REDO
);
547 stdID(wxID_HELP
); stdID(wxID_PRINT
); stdID(wxID_PRINT_SETUP
);
548 stdID(wxID_PREVIEW
); stdID(wxID_ABOUT
); stdID(wxID_HELP_CONTENTS
);
549 stdID(wxID_HELP_COMMANDS
); stdID(wxID_HELP_PROCEDURES
);
550 stdID(wxID_CUT
); stdID(wxID_COPY
); stdID(wxID_PASTE
);
551 stdID(wxID_CLEAR
); stdID(wxID_FIND
); stdID(wxID_DUPLICATE
);
552 stdID(wxID_SELECTALL
); stdID(wxID_OK
); stdID(wxID_CANCEL
);
553 stdID(wxID_APPLY
); stdID(wxID_YES
); stdID(wxID_NO
);
554 stdID(wxID_STATIC
); stdID(wxID_FORWARD
); stdID(wxID_BACKWARD
);
555 stdID(wxID_DEFAULT
); stdID(wxID_MORE
); stdID(wxID_SETUP
);
556 stdID(wxID_RESET
); stdID(wxID_HELP_CONTEXT
);
558 else return XMLID(sid
.c_str());
562 wxString
wxXmlResourceHandler::GetName()
564 return m_node
->GetPropVal(wxT("name"), wxT("-1"));
569 bool wxXmlResourceHandler::GetBool(const wxString
& param
, bool defaultv
)
571 wxString v
= GetParamValue(param
);
573 if (!v
) return defaultv
;
574 else return (v
== wxT("1"));
579 wxColour
wxXmlResourceHandler::GetColour(const wxString
& param
)
581 wxString v
= GetParamValue(param
);
582 unsigned long tmp
= 0;
584 if (v
.Length() != 7 || v
[0u] != wxT('#') ||
585 wxSscanf(v
.c_str(), wxT("#%lX"), &tmp
) != 1)
587 wxLogError(_("XML resource: Incorrect colour specification '%s' for property '%s'."),
588 v
.c_str(), param
.c_str());
592 return wxColour((tmp
& 0xFF0000) >> 16 ,
593 (tmp
& 0x00FF00) >> 8,
599 wxBitmap
wxXmlResourceHandler::GetBitmap(const wxString
& param
, wxSize size
)
601 wxString name
= GetParamValue(param
);
602 if (name
.IsEmpty()) return wxNullBitmap
;
604 wxFSFile
*fsfile
= GetCurFileSystem().OpenFile(name
);
607 wxLogError(_("XML resource: Cannot create bitmap from '%s'."), param
.mb_str());
610 wxImage
img(*(fsfile
->GetStream()));
613 wxImage
img(GetParamValue(wxT("bitmap")));
617 wxLogError(_("XML resource: Cannot create bitmap from '%s'."), param
.mb_str());
620 if (!(size
== wxDefaultSize
)) img
.Rescale(size
.x
, size
.y
);
621 return img
.ConvertToBitmap();
626 wxIcon
wxXmlResourceHandler::GetIcon(const wxString
& param
, wxSize size
)
628 #if wxCHECK_VERSION(2,3,0) || defined(__WXMSW__)
630 icon
.CopyFromBitmap(GetBitmap(param
, size
));
633 wxBitmap bmppt
= GetBitmap(param
, size
);
634 iconpt
= (wxIcon
*)(&bmppt
);
635 wxIcon
icon(*iconpt
);
642 wxXmlNode
*wxXmlResourceHandler::GetParamNode(const wxString
& param
)
644 wxXmlNode
*n
= m_node
->GetChildren();
648 if (n
->GetType() == wxXML_ELEMENT_NODE
&& n
->GetName() == param
)
656 wxString
wxXmlResourceHandler::GetNodeContent(wxXmlNode
*node
)
659 if (n
== NULL
) return wxEmptyString
;
660 n
= n
->GetChildren();
664 if (n
->GetType() == wxXML_TEXT_NODE
||
665 n
->GetType() == wxXML_CDATA_SECTION_NODE
)
666 return n
->GetContent();
669 return wxEmptyString
;
674 wxString
wxXmlResourceHandler::GetParamValue(const wxString
& param
)
677 return GetNodeContent(m_node
);
679 return GetNodeContent(GetParamNode(param
));
684 wxSize
wxXmlResourceHandler::GetSize(const wxString
& param
)
686 wxString s
= GetParamValue(param
);
687 if (s
.IsEmpty()) s
= wxT("-1,-1");
691 is_dlg
= s
[s
.Length()-1] == wxT('d');
692 if (is_dlg
) s
.RemoveLast();
694 if (!s
.BeforeFirst(wxT(',')).ToLong(&sx
) ||
695 !s
.AfterLast(wxT(',')).ToLong(&sy
))
697 wxLogError(_("Cannot parse coordinates from '%s'."), s
.mb_str());
698 return wxDefaultSize
;
703 if (m_instanceAsWindow
)
704 return wxDLG_UNIT(m_instanceAsWindow
, wxSize(sx
, sy
));
705 else if (m_parentAsWindow
)
706 return wxDLG_UNIT(m_parentAsWindow
, wxSize(sx
, sy
));
709 wxLogError(_("Cannot convert dialog units: dialog unknown."));
710 return wxDefaultSize
;
713 else return wxSize(sx
, sy
);
718 wxPoint
wxXmlResourceHandler::GetPosition(const wxString
& param
)
720 wxSize sz
= GetSize(param
);
721 return wxPoint(sz
.x
, sz
.y
);
726 wxCoord
wxXmlResourceHandler::GetDimension(const wxString
& param
, wxCoord defaultv
)
728 wxString s
= GetParamValue(param
);
729 if (s
.IsEmpty()) return defaultv
;
733 is_dlg
= s
[s
.Length()-1] == wxT('d');
734 if (is_dlg
) s
.RemoveLast();
738 wxLogError(_("Cannot parse dimension from '%s'."), s
.mb_str());
744 if (m_instanceAsWindow
)
745 return wxDLG_UNIT(m_instanceAsWindow
, wxSize(sx
, 0)).x
;
746 else if (m_parentAsWindow
)
747 return wxDLG_UNIT(m_parentAsWindow
, wxSize(sx
, 0)).x
;
750 wxLogError(_("Cannot convert dialog units: dialog unknown."));
759 wxFont
wxXmlResourceHandler::GetFont(const wxString
& param
)
761 wxXmlNode
*font_node
= GetParamNode(param
);
762 if (font_node
== NULL
)
764 wxLogError(_("Cannot find font node '%s'."), param
.mb_str());
768 wxXmlNode
*oldnode
= m_node
;
771 long size
= GetLong(wxT("size"), 12);
773 wxString style
= GetParamValue(wxT("style"));
774 wxString weight
= GetParamValue(wxT("weight"));
775 int istyle
= wxNORMAL
, iweight
= wxNORMAL
;
776 if (style
== wxT("italic")) istyle
= wxITALIC
;
777 else if (style
== wxT("slant")) istyle
= wxSLANT
;
778 if (weight
== wxT("bold")) iweight
= wxBOLD
;
779 else if (weight
== wxT("light")) iweight
= wxLIGHT
;
781 wxString family
= GetParamValue(wxT("family"));
782 int ifamily
= wxDEFAULT
;
783 if (family
== wxT("decorative")) ifamily
= wxDECORATIVE
;
784 else if (family
== wxT("roman")) ifamily
= wxROMAN
;
785 else if (family
== wxT("script")) ifamily
= wxSCRIPT
;
786 else if (family
== wxT("swiss")) ifamily
= wxSWISS
;
787 else if (family
== wxT("modern")) ifamily
= wxMODERN
;
789 bool underlined
= GetBool(wxT("underlined"), FALSE
);
791 wxString encoding
= GetParamValue(wxT("encoding"));
793 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
794 if (!encoding
.IsEmpty()) enc
= mapper
.CharsetToEncoding(encoding
);
795 if (enc
== wxFONTENCODING_SYSTEM
) enc
= wxFONTENCODING_SYSTEM
;
797 wxString faces
= GetParamValue(wxT("face"));
798 wxString facename
= wxEmptyString
;
799 wxFontEnumerator enu
;
800 enu
.EnumerateFacenames();
801 wxStringTokenizer
tk(faces
, wxT(","));
802 while (tk
.HasMoreTokens())
804 int index
= enu
.GetFacenames()->Index(tk
.GetNextToken(), FALSE
);
805 if (index
!= wxNOT_FOUND
)
807 facename
= (*enu
.GetFacenames())[index
];
814 wxFont
font(size
, ifamily
, istyle
, iweight
, underlined
, facename
, enc
);
819 void wxXmlResourceHandler::SetupWindow(wxWindow
*wnd
)
823 if (HasParam(wxT("exstyle")))
824 wnd
->SetExtraStyle(GetStyle(wxT("exstyle")));
825 if (HasParam(wxT("bg")))
826 wnd
->SetBackgroundColour(GetColour(wxT("bg")));
827 if (HasParam(wxT("fg")))
828 wnd
->SetForegroundColour(GetColour(wxT("fg")));
829 if (GetBool(wxT("enabled"), 1) == 0)
831 if (GetBool(wxT("focused"), 0) == 1)
833 if (GetBool(wxT("hidden"), 0) == 1)
836 if (HasParam(wxT("tooltip")))
837 wnd
->SetToolTip(GetText(wxT("tooltip")));
839 if (HasParam(wxT("font")))
840 wnd
->SetFont(GetFont());
844 void wxXmlResourceHandler::CreateChildren(wxObject
*parent
, bool this_hnd_only
)
846 wxXmlNode
*n
= m_node
->GetChildren();
850 if (n
->GetType() == wxXML_ELEMENT_NODE
&&
851 n
->GetName() == wxT("object"))
853 if (this_hnd_only
&& CanHandle(n
))
854 CreateResource(n
, parent
, NULL
);
856 m_resource
->CreateResFromNode(n
, parent
, NULL
);
863 void wxXmlResourceHandler::CreateChildrenPrivately(wxObject
*parent
, wxXmlNode
*rootnode
)
866 if (rootnode
== NULL
) root
= m_node
; else root
= rootnode
;
867 wxXmlNode
*n
= root
->GetChildren();
871 if (n
->GetType() == wxXML_ELEMENT_NODE
&& CanHandle(n
))
873 CreateResource(n
, parent
, NULL
);
887 // --------------- XMLID implementation -----------------------------
889 #define XMLID_TABLE_SIZE 1024
899 static XMLID_record
*XMLID_Records
[XMLID_TABLE_SIZE
] = {NULL
};
901 /*static*/ int wxXmlResource::GetXMLID(const char *str_id
)
903 static int XMLID_LastID
= wxID_HIGHEST
;
907 for (const char *c
= str_id
; *c
!= '\0'; c
++) index
+= (int)*c
;
908 index
%= XMLID_TABLE_SIZE
;
910 XMLID_record
*oldrec
= NULL
;
912 for (XMLID_record
*rec
= XMLID_Records
[index
]; rec
; rec
= rec
->next
)
914 if (strcmp(rec
->key
, str_id
) == 0)
922 XMLID_record
**rec_var
= (oldrec
== NULL
) ?
923 &XMLID_Records
[index
] : &oldrec
->next
;
924 *rec_var
= new XMLID_record
;
925 (*rec_var
)->id
= ++XMLID_LastID
;
926 (*rec_var
)->key
= strdup(str_id
);
927 (*rec_var
)->next
= NULL
;
929 return (*rec_var
)->id
;
933 static void CleanXMLID_Record(XMLID_record
*rec
)
937 CleanXMLID_Record(rec
->next
);
943 static void CleanXMLID_Records()
945 for (int i
= 0; i
< XMLID_TABLE_SIZE
; i
++)
946 CleanXMLID_Record(XMLID_Records
[i
]);
956 // --------------- module and globals -----------------------------
959 static wxXmlResource gs_XmlResource
;
961 wxXmlResource
*wxTheXmlResource
= &gs_XmlResource
;
964 class wxXmlResourceModule
: public wxModule
966 DECLARE_DYNAMIC_CLASS(wxXmlResourceModule
)
968 wxXmlResourceModule() {}
969 bool OnInit() {return TRUE
;}
972 wxTheXmlResource
->ClearHandlers();
973 CleanXMLID_Records();
977 IMPLEMENT_DYNAMIC_CLASS(wxXmlResourceModule
, wxModule
)