added system colours and fonts support to XRC (based on patch #1038207)
[wxWidgets.git] / src / xrc / xmlres.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: xmlres.cpp
3 // Purpose: XRC resources
4 // Author: Vaclav Slavik
5 // Created: 2000/03/05
6 // RCS-ID: $Id$
7 // Copyright: (c) 2000 Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifdef __GNUG__
12 #pragma implementation "xmlres.h"
13 #endif
14
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
17
18 #ifdef __BORLANDC__
19 #pragma hdrstop
20 #endif
21
22 #if wxUSE_XRC
23
24 #include <locale.h>
25
26 #include "wx/dialog.h"
27 #include "wx/panel.h"
28 #include "wx/frame.h"
29 #include "wx/wfstream.h"
30 #include "wx/filesys.h"
31 #include "wx/filename.h"
32 #include "wx/log.h"
33 #include "wx/intl.h"
34 #include "wx/tokenzr.h"
35 #include "wx/fontenum.h"
36 #include "wx/module.h"
37 #include "wx/bitmap.h"
38 #include "wx/image.h"
39 #include "wx/fontmap.h"
40 #include "wx/artprov.h"
41
42 #include "wx/xml/xml.h"
43 #include "wx/xrc/xmlres.h"
44
45 #include "wx/arrimpl.cpp"
46 WX_DEFINE_OBJARRAY(wxXmlResourceDataRecords);
47
48
49 wxXmlResource *wxXmlResource::ms_instance = NULL;
50
51 /*static*/ wxXmlResource *wxXmlResource::Get()
52 {
53 if ( !ms_instance )
54 ms_instance = new wxXmlResource;
55 return ms_instance;
56 }
57
58 /*static*/ wxXmlResource *wxXmlResource::Set(wxXmlResource *res)
59 {
60 wxXmlResource *old = ms_instance;
61 ms_instance = res;
62 return old;
63 }
64
65 wxXmlResource::wxXmlResource(int flags)
66 {
67 m_flags = flags;
68 m_version = -1;
69 }
70
71 wxXmlResource::wxXmlResource(const wxString& filemask, int flags)
72 {
73 m_flags = flags;
74 m_version = -1;
75 Load(filemask);
76 }
77
78 wxXmlResource::~wxXmlResource()
79 {
80 ClearHandlers();
81 }
82
83
84 bool wxXmlResource::Load(const wxString& filemask)
85 {
86 wxString fnd;
87 wxXmlResourceDataRecord *drec;
88 bool iswild = wxIsWild(filemask);
89 bool rt = true;
90
91 #if wxUSE_FILESYSTEM
92 wxFileSystem fsys;
93 # define wxXmlFindFirst fsys.FindFirst(filemask, wxFILE)
94 # define wxXmlFindNext fsys.FindNext()
95 #else
96 # define wxXmlFindFirst wxFindFirstFile(filemask, wxFILE)
97 # define wxXmlFindNext wxFindNextFile()
98 #endif
99 if (iswild)
100 fnd = wxXmlFindFirst;
101 else
102 fnd = filemask;
103 while (!!fnd)
104 {
105 // NB: Load() accepts both filenames and URLs (should probably be
106 // changed to filenames only, but embedded resources currently
107 // rely on its ability to handle URLs - FIXME). This check
108 // serves as a quick way to determine whether found name is
109 // filename and not URL:
110 if (wxFileName::FileExists(fnd))
111 {
112 // Make the name absolute filename, because the app may
113 // change working directory later:
114 wxFileName fn(fnd);
115 if (fn.IsRelative())
116 {
117 fn.MakeAbsolute();
118 fnd = fn.GetFullPath();
119 }
120 #if wxUSE_FILESYSTEM
121 fnd = wxFileSystem::FileNameToURL(fnd);
122 #endif
123 }
124
125 #if wxUSE_FILESYSTEM
126 if (fnd.Lower().Matches(wxT("*.zip")) ||
127 fnd.Lower().Matches(wxT("*.xrs")))
128 {
129 rt = rt && Load(fnd + wxT("#zip:*.xrc"));
130 }
131 else
132 #endif
133 {
134 drec = new wxXmlResourceDataRecord;
135 drec->File = fnd;
136 m_data.Add(drec);
137 }
138
139 if (iswild)
140 fnd = wxXmlFindNext;
141 else
142 fnd = wxEmptyString;
143 }
144 # undef wxXmlFindFirst
145 # undef wxXmlFindNext
146 return rt && UpdateResources();
147 }
148
149
150 IMPLEMENT_ABSTRACT_CLASS(wxXmlResourceHandler, wxObject)
151
152 void wxXmlResource::AddHandler(wxXmlResourceHandler *handler)
153 {
154 m_handlers.Append(handler);
155 handler->SetParentResource(this);
156 }
157
158 void wxXmlResource::InsertHandler(wxXmlResourceHandler *handler)
159 {
160 m_handlers.Insert(handler);
161 handler->SetParentResource(this);
162 }
163
164
165
166 void wxXmlResource::ClearHandlers()
167 {
168 WX_CLEAR_LIST(wxList, m_handlers);
169 }
170
171
172 wxMenu *wxXmlResource::LoadMenu(const wxString& name)
173 {
174 return (wxMenu*)CreateResFromNode(FindResource(name, wxT("wxMenu")), NULL, NULL);
175 }
176
177
178
179 wxMenuBar *wxXmlResource::LoadMenuBar(wxWindow *parent, const wxString& name)
180 {
181 return (wxMenuBar*)CreateResFromNode(FindResource(name, wxT("wxMenuBar")), parent, NULL);
182 }
183
184
185
186 #if wxUSE_TOOLBAR
187 wxToolBar *wxXmlResource::LoadToolBar(wxWindow *parent, const wxString& name)
188 {
189 return (wxToolBar*)CreateResFromNode(FindResource(name, wxT("wxToolBar")), parent, NULL);
190 }
191 #endif
192
193
194 wxDialog *wxXmlResource::LoadDialog(wxWindow *parent, const wxString& name)
195 {
196 return (wxDialog*)CreateResFromNode(FindResource(name, wxT("wxDialog")), parent, NULL);
197 }
198
199 bool wxXmlResource::LoadDialog(wxDialog *dlg, wxWindow *parent, const wxString& name)
200 {
201 return CreateResFromNode(FindResource(name, wxT("wxDialog")), parent, dlg) != NULL;
202 }
203
204
205
206 wxPanel *wxXmlResource::LoadPanel(wxWindow *parent, const wxString& name)
207 {
208 return (wxPanel*)CreateResFromNode(FindResource(name, wxT("wxPanel")), parent, NULL);
209 }
210
211 bool wxXmlResource::LoadPanel(wxPanel *panel, wxWindow *parent, const wxString& name)
212 {
213 return CreateResFromNode(FindResource(name, wxT("wxPanel")), parent, panel) != NULL;
214 }
215
216 wxFrame *wxXmlResource::LoadFrame(wxWindow* parent, const wxString& name)
217 {
218 return (wxFrame*)CreateResFromNode(FindResource(name, wxT("wxFrame")), parent, NULL);
219 }
220
221 bool wxXmlResource::LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name)
222 {
223 return CreateResFromNode(FindResource(name, wxT("wxFrame")), parent, frame) != NULL;
224 }
225
226 wxBitmap wxXmlResource::LoadBitmap(const wxString& name)
227 {
228 wxBitmap *bmp = (wxBitmap*)CreateResFromNode(
229 FindResource(name, wxT("wxBitmap")), NULL, NULL);
230 wxBitmap rt;
231
232 if (bmp) { rt = *bmp; delete bmp; }
233 return rt;
234 }
235
236 wxIcon wxXmlResource::LoadIcon(const wxString& name)
237 {
238 wxIcon *icon = (wxIcon*)CreateResFromNode(
239 FindResource(name, wxT("wxIcon")), NULL, NULL);
240 wxIcon rt;
241
242 if (icon) { rt = *icon; delete icon; }
243 return rt;
244 }
245
246
247 wxObject *wxXmlResource::LoadObject(wxWindow *parent, const wxString& name, const wxString& classname)
248 {
249 return CreateResFromNode(FindResource(name, classname), parent, NULL);
250 }
251
252 bool wxXmlResource::LoadObject(wxObject *instance, wxWindow *parent, const wxString& name, const wxString& classname)
253 {
254 return CreateResFromNode(FindResource(name, classname), parent, instance) != NULL;
255 }
256
257
258 bool wxXmlResource::AttachUnknownControl(const wxString& name,
259 wxWindow *control, wxWindow *parent)
260 {
261 if (parent == NULL)
262 parent = control->GetParent();
263 wxWindow *container = parent->FindWindow(name + wxT("_container"));
264 if (!container)
265 {
266 wxLogError(_("Cannot find container for unknown control '%s'."), name.c_str());
267 return false;
268 }
269 return control->Reparent(container);
270 }
271
272
273 static void ProcessPlatformProperty(wxXmlNode *node)
274 {
275 wxString s;
276 bool isok;
277
278 wxXmlNode *c = node->GetChildren();
279 while (c)
280 {
281 isok = false;
282 if (!c->GetPropVal(wxT("platform"), &s))
283 isok = true;
284 else
285 {
286 wxStringTokenizer tkn(s, wxT(" |"));
287
288 while (tkn.HasMoreTokens())
289 {
290 s = tkn.GetNextToken();
291 #ifdef __WINDOWS__
292 if (s == wxT("win")) isok = true;
293 #endif
294 #if defined(__MAC__) || defined(__APPLE__)
295 if (s == wxT("mac")) isok = true;
296 #elif defined(__UNIX__)
297 if (s == wxT("unix")) isok = true;
298 #endif
299 #ifdef __OS2__
300 if (s == wxT("os2")) isok = true;
301 #endif
302
303 if (isok)
304 break;
305 }
306 }
307
308 if (isok)
309 {
310 ProcessPlatformProperty(c);
311 c = c->GetNext();
312 }
313 else
314 {
315 wxXmlNode *c2 = c->GetNext();
316 node->RemoveChild(c);
317 delete c;
318 c = c2;
319 }
320 }
321 }
322
323
324
325 bool wxXmlResource::UpdateResources()
326 {
327 bool rt = true;
328 bool modif;
329 # if wxUSE_FILESYSTEM
330 wxFSFile *file = NULL;
331 wxUnusedVar(file);
332 wxFileSystem fsys;
333 # endif
334
335 wxString encoding(wxT("UTF-8"));
336 #if !wxUSE_UNICODE && wxUSE_INTL
337 if ( (GetFlags() & wxXRC_USE_LOCALE) == 0 )
338 {
339 // In case we are not using wxLocale to translate strings, convert the
340 // strings GUI's charset. This must not be done when wxXRC_USE_LOCALE
341 // is on, because it could break wxGetTranslation lookup.
342 encoding = wxLocale::GetSystemEncodingName();
343 }
344 #endif
345
346 for (size_t i = 0; i < m_data.GetCount(); i++)
347 {
348 modif = (m_data[i].Doc == NULL);
349
350 if (!modif && !(m_flags & wxXRC_NO_RELOADING))
351 {
352 # if wxUSE_FILESYSTEM
353 file = fsys.OpenFile(m_data[i].File);
354 modif = file && file->GetModificationTime() > m_data[i].Time;
355 if (!file)
356 {
357 wxLogError(_("Cannot open file '%s'."), m_data[i].File.c_str());
358 rt = false;
359 }
360 wxDELETE(file);
361 wxUnusedVar(file);
362 # else
363 modif = wxDateTime(wxFileModificationTime(m_data[i].File)) > m_data[i].Time;
364 # endif
365 }
366
367 if (modif)
368 {
369 wxLogTrace(_T("xrc"),
370 _T("opening file '%s'"), m_data[i].File.c_str());
371
372 wxInputStream *stream = NULL;
373
374 # if wxUSE_FILESYSTEM
375 file = fsys.OpenFile(m_data[i].File);
376 if (file)
377 stream = file->GetStream();
378 # else
379 stream = new wxFileInputStream(m_data[i].File);
380 # endif
381
382 if (stream)
383 {
384 delete m_data[i].Doc;
385 m_data[i].Doc = new wxXmlDocument;
386 }
387 if (!stream || !m_data[i].Doc->Load(*stream, encoding))
388 {
389 wxLogError(_("Cannot load resources from file '%s'."),
390 m_data[i].File.c_str());
391 wxDELETE(m_data[i].Doc);
392 rt = false;
393 }
394 else if (m_data[i].Doc->GetRoot()->GetName() != wxT("resource"))
395 {
396 wxLogError(_("Invalid XRC resource '%s': doesn't have root node 'resource'."), m_data[i].File.c_str());
397 wxDELETE(m_data[i].Doc);
398 rt = false;
399 }
400 else
401 {
402 long version;
403 int v1, v2, v3, v4;
404 wxString verstr = m_data[i].Doc->GetRoot()->GetPropVal(
405 wxT("version"), wxT("0.0.0.0"));
406 if (wxSscanf(verstr.c_str(), wxT("%i.%i.%i.%i"),
407 &v1, &v2, &v3, &v4) == 4)
408 version = v1*256*256*256+v2*256*256+v3*256+v4;
409 else
410 version = 0;
411 if (m_version == -1)
412 m_version = version;
413 if (m_version != version)
414 {
415 wxLogError(_("Resource files must have same version number!"));
416 rt = false;
417 }
418
419 ProcessPlatformProperty(m_data[i].Doc->GetRoot());
420 #if wxUSE_FILESYSTEM
421 m_data[i].Time = file->GetModificationTime();
422 #else
423 m_data[i].Time = wxDateTime(wxFileModificationTime(m_data[i].File));
424 #endif
425 }
426
427 # if wxUSE_FILESYSTEM
428 wxDELETE(file);
429 wxUnusedVar(file);
430 # else
431 wxDELETE(stream);
432 # endif
433 }
434 }
435
436 return rt;
437 }
438
439
440 wxXmlNode *wxXmlResource::DoFindResource(wxXmlNode *parent,
441 const wxString& name,
442 const wxString& classname,
443 bool recursive)
444 {
445 wxString dummy;
446 wxXmlNode *node;
447
448 // first search for match at the top-level nodes (as this is
449 // where the resource is most commonly looked for):
450 for (node = parent->GetChildren(); node; node = node->GetNext())
451 {
452 if ( node->GetType() == wxXML_ELEMENT_NODE &&
453 (node->GetName() == wxT("object") ||
454 node->GetName() == wxT("object_ref")) &&
455 node->GetPropVal(wxT("name"), &dummy) && dummy == name )
456 {
457 wxString cls(node->GetPropVal(wxT("class"), wxEmptyString));
458 if (!classname || cls == classname)
459 return node;
460 // object_ref may not have 'class' property:
461 if (cls.empty() && node->GetName() == wxT("object_ref"))
462 {
463 wxString refName = node->GetPropVal(wxT("ref"), wxEmptyString);
464 if (refName.empty())
465 continue;
466 wxXmlNode* refNode = FindResource(refName, wxEmptyString, true);
467 if (refNode &&
468 refNode->GetPropVal(wxT("class"), wxEmptyString) == classname)
469 {
470 return node;
471 }
472 }
473 }
474 }
475
476 if ( recursive )
477 for (node = parent->GetChildren(); node; node = node->GetNext())
478 {
479 if ( node->GetType() == wxXML_ELEMENT_NODE &&
480 (node->GetName() == wxT("object") ||
481 node->GetName() == wxT("object_ref")) )
482 {
483 wxXmlNode* found = DoFindResource(node, name, classname, true);
484 if ( found )
485 return found;
486 }
487 }
488
489 return NULL;
490 }
491
492 wxXmlNode *wxXmlResource::FindResource(const wxString& name,
493 const wxString& classname,
494 bool recursive)
495 {
496 UpdateResources(); //ensure everything is up-to-date
497
498 wxString dummy;
499 for (size_t f = 0; f < m_data.GetCount(); f++)
500 {
501 if ( m_data[f].Doc == NULL || m_data[f].Doc->GetRoot() == NULL )
502 continue;
503
504 wxXmlNode* found = DoFindResource(m_data[f].Doc->GetRoot(),
505 name, classname, recursive);
506 if ( found )
507 {
508 #if wxUSE_FILESYSTEM
509 m_curFileSystem.ChangePathTo(m_data[f].File);
510 #endif
511 return found;
512 }
513 }
514
515 wxLogError(_("XRC resource '%s' (class '%s') not found!"),
516 name.c_str(), classname.c_str());
517 return NULL;
518 }
519
520 static void MergeNodes(wxXmlNode& dest, wxXmlNode& with)
521 {
522 // Merge properties:
523 for (wxXmlProperty *prop = with.GetProperties(); prop; prop = prop->GetNext())
524 {
525 wxXmlProperty *dprop;
526 for (dprop = dest.GetProperties(); dprop; dprop = dprop->GetNext())
527 {
528
529 if ( dprop->GetName() == prop->GetName() )
530 {
531 dprop->SetValue(prop->GetValue());
532 break;
533 }
534 }
535
536 if ( !dprop )
537 dest.AddProperty(prop->GetName(), prop->GetValue());
538 }
539
540 // Merge child nodes:
541 for (wxXmlNode* node = with.GetChildren(); node; node = node->GetNext())
542 {
543 wxString name = node->GetPropVal(wxT("name"), wxEmptyString);
544 wxXmlNode *dnode;
545
546 for (dnode = dest.GetChildren(); dnode; dnode = dnode->GetNext() )
547 {
548 if ( dnode->GetName() == node->GetName() &&
549 dnode->GetPropVal(wxT("name"), wxEmptyString) == name &&
550 dnode->GetType() == node->GetType() )
551 {
552 MergeNodes(*dnode, *node);
553 break;
554 }
555 }
556
557 if ( !dnode )
558 dest.AddChild(new wxXmlNode(*node));
559 }
560
561 if ( dest.GetType() == wxXML_TEXT_NODE && with.GetContent().Length() )
562 dest.SetContent(with.GetContent());
563 }
564
565 wxObject *wxXmlResource::CreateResFromNode(wxXmlNode *node, wxObject *parent,
566 wxObject *instance,
567 wxXmlResourceHandler *handlerToUse)
568 {
569 if (node == NULL) return NULL;
570
571 // handling of referenced resource
572 if ( node->GetName() == wxT("object_ref") )
573 {
574 wxString refName = node->GetPropVal(wxT("ref"), wxEmptyString);
575 wxXmlNode* refNode = FindResource(refName, wxEmptyString, true);
576
577 if ( !refNode )
578 {
579 wxLogError(_("Referenced object node with ref=\"%s\" not found!"),
580 refName.c_str());
581 return NULL;
582 }
583
584 wxXmlNode copy(*refNode);
585 MergeNodes(copy, *node);
586
587 return CreateResFromNode(&copy, parent, instance);
588 }
589
590 wxXmlResourceHandler *handler;
591
592 if (handlerToUse)
593 {
594 if (handlerToUse->CanHandle(node))
595 {
596 return handlerToUse->CreateResource(node, parent, instance);
597 }
598 }
599 else if (node->GetName() == wxT("object"))
600 {
601 wxList::compatibility_iterator ND = m_handlers.GetFirst();
602 while (ND)
603 {
604 handler = (wxXmlResourceHandler*)ND->GetData();
605 if (handler->CanHandle(node))
606 {
607 return handler->CreateResource(node, parent, instance);
608 }
609 ND = ND->GetNext();
610 }
611 }
612
613 wxLogError(_("No handler found for XML node '%s', class '%s'!"),
614 node->GetName().c_str(),
615 node->GetPropVal(wxT("class"), wxEmptyString).c_str());
616 return NULL;
617 }
618
619
620 #include "wx/listimpl.cpp"
621 WX_DECLARE_LIST(wxXmlSubclassFactory, wxXmlSubclassFactoriesList);
622 WX_DEFINE_LIST(wxXmlSubclassFactoriesList);
623
624 wxXmlSubclassFactoriesList *wxXmlResource::ms_subclassFactories = NULL;
625
626 /*static*/ void wxXmlResource::AddSubclassFactory(wxXmlSubclassFactory *factory)
627 {
628 if (!ms_subclassFactories)
629 {
630 ms_subclassFactories = new wxXmlSubclassFactoriesList;
631 }
632 ms_subclassFactories->Append(factory);
633 }
634
635 class wxXmlSubclassFactoryCXX : public wxXmlSubclassFactory
636 {
637 public:
638 ~wxXmlSubclassFactoryCXX() {}
639
640 wxObject *Create(const wxString& className)
641 {
642 wxClassInfo* classInfo = wxClassInfo::FindClass(className);
643
644 if (classInfo)
645 return classInfo->CreateObject();
646 else
647 return NULL;
648 }
649 };
650
651
652
653
654 wxXmlResourceHandler::wxXmlResourceHandler()
655 : m_node(NULL), m_parent(NULL), m_instance(NULL),
656 m_parentAsWindow(NULL)
657 {}
658
659
660
661 wxObject *wxXmlResourceHandler::CreateResource(wxXmlNode *node, wxObject *parent, wxObject *instance)
662 {
663 wxXmlNode *myNode = m_node;
664 wxString myClass = m_class;
665 wxObject *myParent = m_parent, *myInstance = m_instance;
666 wxWindow *myParentAW = m_parentAsWindow;
667
668 m_instance = instance;
669 if (!m_instance && node->HasProp(wxT("subclass")) &&
670 !(m_resource->GetFlags() & wxXRC_NO_SUBCLASSING))
671 {
672 wxString subclass = node->GetPropVal(wxT("subclass"), wxEmptyString);
673 if (!subclass.empty())
674 {
675 for (wxXmlSubclassFactoriesList::compatibility_iterator i = wxXmlResource::ms_subclassFactories->GetFirst();
676 i; i = i->GetNext())
677 {
678 m_instance = i->GetData()->Create(subclass);
679 if (m_instance)
680 break;
681 }
682
683 if (!m_instance)
684 {
685 wxString name = node->GetPropVal(wxT("name"), wxEmptyString);
686 wxLogError(_("Subclass '%s' not found for resource '%s', not subclassing!"),
687 subclass.c_str(), name.c_str());
688 }
689 }
690 }
691
692 m_node = node;
693 m_class = node->GetPropVal(wxT("class"), wxEmptyString);
694 m_parent = parent;
695 m_parentAsWindow = wxDynamicCast(m_parent, wxWindow);
696
697 wxObject *returned = DoCreateResource();
698
699 m_node = myNode;
700 m_class = myClass;
701 m_parent = myParent; m_parentAsWindow = myParentAW;
702 m_instance = myInstance;
703
704 return returned;
705 }
706
707
708 void wxXmlResourceHandler::AddStyle(const wxString& name, int value)
709 {
710 m_styleNames.Add(name);
711 m_styleValues.Add(value);
712 }
713
714
715
716 void wxXmlResourceHandler::AddWindowStyles()
717 {
718 XRC_ADD_STYLE(wxCLIP_CHILDREN);
719 XRC_ADD_STYLE(wxSIMPLE_BORDER);
720 XRC_ADD_STYLE(wxSUNKEN_BORDER);
721 XRC_ADD_STYLE(wxDOUBLE_BORDER);
722 XRC_ADD_STYLE(wxRAISED_BORDER);
723 XRC_ADD_STYLE(wxSTATIC_BORDER);
724 XRC_ADD_STYLE(wxNO_BORDER);
725 XRC_ADD_STYLE(wxTRANSPARENT_WINDOW);
726 XRC_ADD_STYLE(wxWANTS_CHARS);
727 XRC_ADD_STYLE(wxNO_FULL_REPAINT_ON_RESIZE);
728 XRC_ADD_STYLE(wxFULL_REPAINT_ON_RESIZE);
729 XRC_ADD_STYLE(wxWS_EX_BLOCK_EVENTS);
730 }
731
732
733
734 bool wxXmlResourceHandler::HasParam(const wxString& param)
735 {
736 return (GetParamNode(param) != NULL);
737 }
738
739
740 int wxXmlResourceHandler::GetStyle(const wxString& param, int defaults)
741 {
742 wxString s = GetParamValue(param);
743
744 if (!s) return defaults;
745
746 wxStringTokenizer tkn(s, wxT("| \t\n"), wxTOKEN_STRTOK);
747 int style = 0;
748 int index;
749 wxString fl;
750 while (tkn.HasMoreTokens())
751 {
752 fl = tkn.GetNextToken();
753 index = m_styleNames.Index(fl);
754 if (index != wxNOT_FOUND)
755 style |= m_styleValues[index];
756 else
757 wxLogError(_("Unknown style flag ") + fl);
758 }
759 return style;
760 }
761
762
763
764 wxString wxXmlResourceHandler::GetText(const wxString& param, bool translate)
765 {
766 wxXmlNode *parNode = GetParamNode(param);
767 wxString str1(GetNodeContent(parNode));
768 wxString str2;
769 const wxChar *dt;
770 wxChar amp_char;
771
772 // VS: First version of XRC resources used $ instead of & (which is
773 // illegal in XML), but later I realized that '_' fits this purpose
774 // much better (because &File means "File with F underlined").
775 if (m_resource->CompareVersion(2,3,0,1) < 0)
776 amp_char = wxT('$');
777 else
778 amp_char = wxT('_');
779
780 for (dt = str1.c_str(); *dt; dt++)
781 {
782 // Remap amp_char to &, map double amp_char to amp_char (for things
783 // like "&File..." -- this is illegal in XML, so we use "_File..."):
784 if (*dt == amp_char)
785 {
786 if ( *(++dt) == amp_char )
787 str2 << amp_char;
788 else
789 str2 << wxT('&') << *dt;
790 }
791 // Remap \n to CR, \r to LF, \t to TAB, \\ to \:
792 else if (*dt == wxT('\\'))
793 switch (*(++dt))
794 {
795 case wxT('n'):
796 str2 << wxT('\n');
797 break;
798
799 case wxT('t'):
800 str2 << wxT('\t');
801 break;
802
803 case wxT('r'):
804 str2 << wxT('\r');
805 break;
806
807 case wxT('\\') :
808 // "\\" wasn't translated to "\" prior to 2.5.3.0:
809 if (m_resource->CompareVersion(2,5,3,0) >= 0)
810 {
811 str2 << wxT('\\');
812 break;
813 }
814 // else fall-through to default: branch below
815
816 default:
817 str2 << wxT('\\') << *dt;
818 break;
819 }
820 else str2 << *dt;
821 }
822
823 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
824 {
825 if (translate && parNode &&
826 parNode->GetPropVal(wxT("translate"), wxEmptyString) != wxT("0"))
827 {
828 return wxGetTranslation(str2);
829 }
830 else
831 {
832 #if wxUSE_UNICODE
833 return str2;
834 #else
835 // The string is internally stored as UTF-8, we have to convert
836 // it into system's default encoding so that it can be displayed:
837 return wxString(str2.mb_str(wxConvUTF8), wxConvLocal);
838 #endif
839 }
840 }
841 else
842 {
843 // If wxXRC_USE_LOCALE is not set, then the string is already in
844 // system's default encoding in ANSI build, so we don't have to
845 // do anything special here.
846 return str2;
847 }
848 }
849
850
851
852 long wxXmlResourceHandler::GetLong(const wxString& param, long defaultv)
853 {
854 long value;
855 wxString str1 = GetParamValue(param);
856
857 if (!str1.ToLong(&value))
858 value = defaultv;
859
860 return value;
861 }
862
863 float wxXmlResourceHandler::GetFloat(const wxString& param, float defaultv)
864 {
865 double value;
866 wxString str1 = GetParamValue(param);
867
868 const char *prevlocale = setlocale(LC_NUMERIC, "C");
869
870 if (!str1.ToDouble(&value))
871 value = defaultv;
872
873 setlocale(LC_NUMERIC, prevlocale);
874
875 return value;
876 }
877
878
879 int wxXmlResourceHandler::GetID()
880 {
881 return wxXmlResource::GetXRCID(GetName());
882 }
883
884
885
886 wxString wxXmlResourceHandler::GetName()
887 {
888 return m_node->GetPropVal(wxT("name"), wxT("-1"));
889 }
890
891
892
893 bool wxXmlResourceHandler::GetBool(const wxString& param, bool defaultv)
894 {
895 wxString v = GetParamValue(param);
896 v.MakeLower();
897 if (!v) return defaultv;
898 else return (v == wxT("1"));
899 }
900
901
902 static wxColour GetSystemColour(const wxString& name)
903 {
904 if (!name.empty())
905 {
906 #define SYSCLR(clr) \
907 if (name == _T(#clr)) return wxSystemSettings::GetColour(clr);
908 SYSCLR(wxSYS_COLOUR_SCROLLBAR)
909 SYSCLR(wxSYS_COLOUR_BACKGROUND)
910 SYSCLR(wxSYS_COLOUR_DESKTOP)
911 SYSCLR(wxSYS_COLOUR_ACTIVECAPTION)
912 SYSCLR(wxSYS_COLOUR_INACTIVECAPTION)
913 SYSCLR(wxSYS_COLOUR_MENU)
914 SYSCLR(wxSYS_COLOUR_WINDOW)
915 SYSCLR(wxSYS_COLOUR_WINDOWFRAME)
916 SYSCLR(wxSYS_COLOUR_MENUTEXT)
917 SYSCLR(wxSYS_COLOUR_WINDOWTEXT)
918 SYSCLR(wxSYS_COLOUR_CAPTIONTEXT)
919 SYSCLR(wxSYS_COLOUR_ACTIVEBORDER)
920 SYSCLR(wxSYS_COLOUR_INACTIVEBORDER)
921 SYSCLR(wxSYS_COLOUR_APPWORKSPACE)
922 SYSCLR(wxSYS_COLOUR_HIGHLIGHT)
923 SYSCLR(wxSYS_COLOUR_HIGHLIGHTTEXT)
924 SYSCLR(wxSYS_COLOUR_BTNFACE)
925 SYSCLR(wxSYS_COLOUR_3DFACE)
926 SYSCLR(wxSYS_COLOUR_BTNSHADOW)
927 SYSCLR(wxSYS_COLOUR_3DSHADOW)
928 SYSCLR(wxSYS_COLOUR_GRAYTEXT)
929 SYSCLR(wxSYS_COLOUR_BTNTEXT)
930 SYSCLR(wxSYS_COLOUR_INACTIVECAPTIONTEXT)
931 SYSCLR(wxSYS_COLOUR_BTNHIGHLIGHT)
932 SYSCLR(wxSYS_COLOUR_BTNHILIGHT)
933 SYSCLR(wxSYS_COLOUR_3DHIGHLIGHT)
934 SYSCLR(wxSYS_COLOUR_3DHILIGHT)
935 SYSCLR(wxSYS_COLOUR_3DDKSHADOW)
936 SYSCLR(wxSYS_COLOUR_3DLIGHT)
937 SYSCLR(wxSYS_COLOUR_INFOTEXT)
938 SYSCLR(wxSYS_COLOUR_INFOBK)
939 SYSCLR(wxSYS_COLOUR_LISTBOX)
940 SYSCLR(wxSYS_COLOUR_HOTLIGHT)
941 SYSCLR(wxSYS_COLOUR_GRADIENTACTIVECAPTION)
942 SYSCLR(wxSYS_COLOUR_GRADIENTINACTIVECAPTION)
943 SYSCLR(wxSYS_COLOUR_MENUHILIGHT)
944 SYSCLR(wxSYS_COLOUR_MENUBAR)
945 #undef SYSCLR
946 }
947
948 return wxNullColour;
949 }
950
951 wxColour wxXmlResourceHandler::GetColour(const wxString& param)
952 {
953 wxString v = GetParamValue(param);
954
955 // find colour using HTML syntax (#RRGGBB)
956 unsigned long tmp = 0;
957
958 if (v.Length() != 7 || v[0u] != wxT('#') ||
959 wxSscanf(v.c_str(), wxT("#%lX"), &tmp) != 1)
960 {
961 // the colour doesn't use #RRGGBB format, check if it is symbolic
962 // colour name:
963 wxColour clr = GetSystemColour(v);
964 if (clr.Ok())
965 return clr;
966
967 wxLogError(_("XRC resource: Incorrect colour specification '%s' for property '%s'."),
968 v.c_str(), param.c_str());
969 return wxNullColour;
970 }
971
972 return wxColour((unsigned char) ((tmp & 0xFF0000) >> 16) ,
973 (unsigned char) ((tmp & 0x00FF00) >> 8),
974 (unsigned char) ((tmp & 0x0000FF)));
975 }
976
977
978
979 wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param,
980 const wxArtClient& defaultArtClient,
981 wxSize size)
982 {
983 /* If the bitmap is specified as stock item, query wxArtProvider for it: */
984 wxXmlNode *bmpNode = GetParamNode(param);
985 if ( bmpNode )
986 {
987 wxString sid = bmpNode->GetPropVal(wxT("stock_id"), wxEmptyString);
988 if ( !sid.empty() )
989 {
990 wxString scl = bmpNode->GetPropVal(wxT("stock_client"), wxEmptyString);
991 if (scl.empty())
992 scl = defaultArtClient;
993 else
994 scl = wxART_MAKE_CLIENT_ID_FROM_STR(scl);
995
996 wxBitmap stockArt =
997 wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(sid),
998 scl, size);
999 if ( stockArt.Ok() )
1000 return stockArt;
1001 }
1002 }
1003
1004 /* ...or load the bitmap from file: */
1005 wxString name = GetParamValue(param);
1006 if (name.IsEmpty()) return wxNullBitmap;
1007 #if wxUSE_FILESYSTEM
1008 wxFSFile *fsfile = GetCurFileSystem().OpenFile(name);
1009 if (fsfile == NULL)
1010 {
1011 wxLogError(_("XRC resource: Cannot create bitmap from '%s'."),
1012 name.c_str());
1013 return wxNullBitmap;
1014 }
1015 wxImage img(*(fsfile->GetStream()));
1016 delete fsfile;
1017 #else
1018 wxImage img(GetParamValue(wxT("bitmap")));
1019 #endif
1020
1021 if (!img.Ok())
1022 {
1023 wxLogError(_("XRC resource: Cannot create bitmap from '%s'."),
1024 param.c_str());
1025 return wxNullBitmap;
1026 }
1027 if (!(size == wxDefaultSize)) img.Rescale(size.x, size.y);
1028 return wxBitmap(img);
1029
1030 }
1031
1032
1033
1034 wxIcon wxXmlResourceHandler::GetIcon(const wxString& param,
1035 const wxArtClient& defaultArtClient,
1036 wxSize size)
1037 {
1038 wxIcon icon;
1039 icon.CopyFromBitmap(GetBitmap(param, defaultArtClient, size));
1040 return icon;
1041 }
1042
1043
1044
1045 wxXmlNode *wxXmlResourceHandler::GetParamNode(const wxString& param)
1046 {
1047 wxCHECK_MSG(m_node, NULL, wxT("You can't access handler data before it was initialized!"));
1048
1049 wxXmlNode *n = m_node->GetChildren();
1050
1051 while (n)
1052 {
1053 if (n->GetType() == wxXML_ELEMENT_NODE && n->GetName() == param)
1054 return n;
1055 n = n->GetNext();
1056 }
1057 return NULL;
1058 }
1059
1060
1061 wxString wxXmlResourceHandler::GetNodeContent(wxXmlNode *node)
1062 {
1063 wxXmlNode *n = node;
1064 if (n == NULL) return wxEmptyString;
1065 n = n->GetChildren();
1066
1067 while (n)
1068 {
1069 if (n->GetType() == wxXML_TEXT_NODE ||
1070 n->GetType() == wxXML_CDATA_SECTION_NODE)
1071 return n->GetContent();
1072 n = n->GetNext();
1073 }
1074 return wxEmptyString;
1075 }
1076
1077
1078
1079 wxString wxXmlResourceHandler::GetParamValue(const wxString& param)
1080 {
1081 if (param.IsEmpty())
1082 return GetNodeContent(m_node);
1083 else
1084 return GetNodeContent(GetParamNode(param));
1085 }
1086
1087
1088
1089 wxSize wxXmlResourceHandler::GetSize(const wxString& param)
1090 {
1091 wxString s = GetParamValue(param);
1092 if (s.IsEmpty()) s = wxT("-1,-1");
1093 bool is_dlg;
1094 long sx, sy = 0;
1095
1096 is_dlg = s[s.Length()-1] == wxT('d');
1097 if (is_dlg) s.RemoveLast();
1098
1099 if (!s.BeforeFirst(wxT(',')).ToLong(&sx) ||
1100 !s.AfterLast(wxT(',')).ToLong(&sy))
1101 {
1102 wxLogError(_("Cannot parse coordinates from '%s'."), s.c_str());
1103 return wxDefaultSize;
1104 }
1105
1106 if (is_dlg)
1107 {
1108 if (m_parentAsWindow)
1109 return wxDLG_UNIT(m_parentAsWindow, wxSize(sx, sy));
1110 else
1111 {
1112 wxLogError(_("Cannot convert dialog units: dialog unknown."));
1113 return wxDefaultSize;
1114 }
1115 }
1116 else return wxSize(sx, sy);
1117 }
1118
1119
1120
1121 wxPoint wxXmlResourceHandler::GetPosition(const wxString& param)
1122 {
1123 wxSize sz = GetSize(param);
1124 return wxPoint(sz.x, sz.y);
1125 }
1126
1127
1128
1129 wxCoord wxXmlResourceHandler::GetDimension(const wxString& param, wxCoord defaultv)
1130 {
1131 wxString s = GetParamValue(param);
1132 if (s.IsEmpty()) return defaultv;
1133 bool is_dlg;
1134 long sx;
1135
1136 is_dlg = s[s.Length()-1] == wxT('d');
1137 if (is_dlg) s.RemoveLast();
1138
1139 if (!s.ToLong(&sx))
1140 {
1141 wxLogError(_("Cannot parse dimension from '%s'."), s.c_str());
1142 return defaultv;
1143 }
1144
1145 if (is_dlg)
1146 {
1147 if (m_parentAsWindow)
1148 return wxDLG_UNIT(m_parentAsWindow, wxSize(sx, 0)).x;
1149 else
1150 {
1151 wxLogError(_("Cannot convert dialog units: dialog unknown."));
1152 return defaultv;
1153 }
1154 }
1155 else return sx;
1156 }
1157
1158
1159 // Get system font index using indexname
1160 static wxFont GetSystemFont(const wxString& name)
1161 {
1162 if (!name.empty())
1163 {
1164 #define SYSFNT(fnt) \
1165 if (name == _T(#fnt)) return wxSystemSettings::GetFont(fnt);
1166 SYSFNT(wxSYS_OEM_FIXED_FONT)
1167 SYSFNT(wxSYS_ANSI_FIXED_FONT)
1168 SYSFNT(wxSYS_ANSI_VAR_FONT)
1169 SYSFNT(wxSYS_SYSTEM_FONT)
1170 SYSFNT(wxSYS_DEVICE_DEFAULT_FONT)
1171 SYSFNT(wxSYS_DEFAULT_PALETTE)
1172 SYSFNT(wxSYS_SYSTEM_FIXED_FONT)
1173 SYSFNT(wxSYS_DEFAULT_GUI_FONT)
1174 #undef SYSFNT
1175 }
1176
1177 return wxNullFont;
1178 }
1179
1180 wxFont wxXmlResourceHandler::GetFont(const wxString& param)
1181 {
1182 wxXmlNode *font_node = GetParamNode(param);
1183 if (font_node == NULL)
1184 {
1185 wxLogError(_("Cannot find font node '%s'."), param.c_str());
1186 return wxNullFont;
1187 }
1188
1189 wxXmlNode *oldnode = m_node;
1190 m_node = font_node;
1191
1192 // font attributes:
1193
1194 // size
1195 int isize = wxDEFAULT;
1196 bool hasSize = HasParam(wxT("size"));
1197 if (hasSize)
1198 isize = GetLong(wxT("size"), wxDEFAULT);
1199
1200 // style
1201 int istyle = wxNORMAL;
1202 bool hasStyle = HasParam(wxT("style"));
1203 if (hasStyle)
1204 {
1205 wxString style = GetParamValue(wxT("style"));
1206 if (style == wxT("italic"))
1207 istyle = wxITALIC;
1208 else if (style == wxT("slant"))
1209 istyle = wxSLANT;
1210 }
1211
1212 // weight
1213 int iweight = wxNORMAL;
1214 bool hasWeight = HasParam(wxT("weight"));
1215 if (hasWeight)
1216 {
1217 wxString weight = GetParamValue(wxT("weight"));
1218 if (weight == wxT("bold"))
1219 iweight = wxBOLD;
1220 else if (weight == wxT("light"))
1221 iweight = wxLIGHT;
1222 }
1223
1224 // underline
1225 bool hasUnderlined = HasParam(wxT("underlined"));
1226 bool underlined = hasUnderlined ? GetBool(wxT("underlined"), false) : false;
1227
1228 // family and facename
1229 int ifamily = wxDEFAULT;
1230 bool hasFamily = HasParam(wxT("family"));
1231 if (hasFamily)
1232 {
1233 wxString family = GetParamValue(wxT("family"));
1234 if (family == wxT("decorative")) ifamily = wxDECORATIVE;
1235 else if (family == wxT("roman")) ifamily = wxROMAN;
1236 else if (family == wxT("script")) ifamily = wxSCRIPT;
1237 else if (family == wxT("swiss")) ifamily = wxSWISS;
1238 else if (family == wxT("modern")) ifamily = wxMODERN;
1239 else if (family == wxT("teletype")) ifamily = wxTELETYPE;
1240 }
1241
1242
1243 wxString facename;
1244 bool hasFacename = HasParam(wxT("face"));
1245 if (hasFacename)
1246 {
1247 wxString faces = GetParamValue(wxT("face"));
1248 wxFontEnumerator enu;
1249 enu.EnumerateFacenames();
1250 wxStringTokenizer tk(faces, wxT(","));
1251 while (tk.HasMoreTokens())
1252 {
1253 int index = enu.GetFacenames()->Index(tk.GetNextToken(), false);
1254 if (index != wxNOT_FOUND)
1255 {
1256 facename = (*enu.GetFacenames())[index];
1257 break;
1258 }
1259 }
1260 }
1261
1262 // encoding
1263 wxFontEncoding enc = wxFONTENCODING_DEFAULT;
1264 bool hasEncoding = HasParam(wxT("encoding"));
1265 if (hasEncoding)
1266 {
1267 wxString encoding = GetParamValue(wxT("encoding"));
1268 wxFontMapper mapper;
1269 if (!encoding.IsEmpty())
1270 enc = mapper.CharsetToEncoding(encoding);
1271 if (enc == wxFONTENCODING_SYSTEM)
1272 enc = wxFONTENCODING_DEFAULT;
1273 }
1274
1275 // is this font based on a system font?
1276 wxFont sysfont = GetSystemFont(GetParamValue(wxT("sysfont")));
1277
1278 if (sysfont.Ok())
1279 {
1280 if (hasSize)
1281 sysfont.SetPointSize(isize);
1282 else if (HasParam(wxT("relativesize")))
1283 sysfont.SetPointSize(int(sysfont.GetPointSize() *
1284 GetFloat(wxT("relativesize"))));
1285
1286 if (hasStyle)
1287 sysfont.SetStyle(istyle);
1288 if (hasWeight)
1289 sysfont.SetWeight(iweight);
1290 if (hasUnderlined)
1291 sysfont.SetUnderlined(underlined);
1292 if (hasFamily)
1293 sysfont.SetFamily(ifamily);
1294 if (hasFacename)
1295 sysfont.SetFaceName(facename);
1296 if (hasEncoding)
1297 sysfont.SetDefaultEncoding(enc);
1298
1299 m_node = oldnode;
1300 return sysfont;
1301 }
1302 else
1303 {
1304 m_node = oldnode;
1305 return wxFont(isize, ifamily, istyle, iweight,
1306 underlined, facename, enc);
1307 }
1308 }
1309
1310
1311 void wxXmlResourceHandler::SetupWindow(wxWindow *wnd)
1312 {
1313 //FIXME : add cursor
1314
1315 if (HasParam(wxT("exstyle")))
1316 // Have to OR it with existing style, since
1317 // some implementations (e.g. wxGTK) use the extra style
1318 // during creation
1319 wnd->SetExtraStyle(wnd->GetExtraStyle() | GetStyle(wxT("exstyle")));
1320 if (HasParam(wxT("bg")))
1321 wnd->SetBackgroundColour(GetColour(wxT("bg")));
1322 if (HasParam(wxT("fg")))
1323 wnd->SetForegroundColour(GetColour(wxT("fg")));
1324 if (GetBool(wxT("enabled"), 1) == 0)
1325 wnd->Enable(false);
1326 if (GetBool(wxT("focused"), 0) == 1)
1327 wnd->SetFocus();
1328 if (GetBool(wxT("hidden"), 0) == 1)
1329 wnd->Show(false);
1330 #if wxUSE_TOOLTIPS
1331 if (HasParam(wxT("tooltip")))
1332 wnd->SetToolTip(GetText(wxT("tooltip")));
1333 #endif
1334 if (HasParam(wxT("font")))
1335 wnd->SetFont(GetFont());
1336 }
1337
1338
1339 void wxXmlResourceHandler::CreateChildren(wxObject *parent, bool this_hnd_only)
1340 {
1341 wxXmlNode *n = m_node->GetChildren();
1342
1343 while (n)
1344 {
1345 if (n->GetType() == wxXML_ELEMENT_NODE &&
1346 (n->GetName() == wxT("object") || n->GetName() == wxT("object_ref")))
1347 {
1348 m_resource->CreateResFromNode(n, parent, NULL,
1349 this_hnd_only ? this : NULL);
1350 }
1351 n = n->GetNext();
1352 }
1353 }
1354
1355
1356 void wxXmlResourceHandler::CreateChildrenPrivately(wxObject *parent, wxXmlNode *rootnode)
1357 {
1358 wxXmlNode *root;
1359 if (rootnode == NULL) root = m_node; else root = rootnode;
1360 wxXmlNode *n = root->GetChildren();
1361
1362 while (n)
1363 {
1364 if (n->GetType() == wxXML_ELEMENT_NODE && CanHandle(n))
1365 {
1366 CreateResource(n, parent, NULL);
1367 }
1368 n = n->GetNext();
1369 }
1370 }
1371
1372
1373
1374
1375
1376
1377
1378 // --------------- XRCID implementation -----------------------------
1379
1380 #define XRCID_TABLE_SIZE 1024
1381
1382
1383 struct XRCID_record
1384 {
1385 int id;
1386 wxChar *key;
1387 XRCID_record *next;
1388 };
1389
1390 static XRCID_record *XRCID_Records[XRCID_TABLE_SIZE] = {NULL};
1391
1392 static int XRCID_Lookup(const wxChar *str_id, int value_if_not_found = -2)
1393 {
1394 int index = 0;
1395
1396 for (const wxChar *c = str_id; *c != wxT('\0'); c++) index += (int)*c;
1397 index %= XRCID_TABLE_SIZE;
1398
1399 XRCID_record *oldrec = NULL;
1400 for (XRCID_record *rec = XRCID_Records[index]; rec; rec = rec->next)
1401 {
1402 if (wxStrcmp(rec->key, str_id) == 0)
1403 {
1404 return rec->id;
1405 }
1406 oldrec = rec;
1407 }
1408
1409 XRCID_record **rec_var = (oldrec == NULL) ?
1410 &XRCID_Records[index] : &oldrec->next;
1411 *rec_var = new XRCID_record;
1412 (*rec_var)->key = wxStrdup(str_id);
1413 (*rec_var)->next = NULL;
1414
1415 wxChar *end;
1416 if (value_if_not_found != -2)
1417 (*rec_var)->id = value_if_not_found;
1418 else
1419 {
1420 int asint = wxStrtol(str_id, &end, 10);
1421 if (*str_id && *end == 0)
1422 {
1423 // if str_id was integer, keep it verbosely:
1424 (*rec_var)->id = asint;
1425 }
1426 else
1427 {
1428 (*rec_var)->id = wxNewId();
1429 }
1430 }
1431
1432 return (*rec_var)->id;
1433 }
1434
1435 /*static*/ int wxXmlResource::GetXRCID(const wxChar *str_id)
1436 {
1437 return XRCID_Lookup(str_id);
1438 }
1439
1440
1441 static void CleanXRCID_Record(XRCID_record *rec)
1442 {
1443 if (rec)
1444 {
1445 CleanXRCID_Record(rec->next);
1446 free(rec->key);
1447 delete rec;
1448 }
1449 }
1450
1451 static void CleanXRCID_Records()
1452 {
1453 for (int i = 0; i < XRCID_TABLE_SIZE; i++)
1454 {
1455 CleanXRCID_Record(XRCID_Records[i]);
1456 XRCID_Records[i] = NULL;
1457 }
1458 }
1459
1460 static void AddStdXRCID_Records()
1461 {
1462 #define stdID(id) XRCID_Lookup(wxT(#id), id)
1463 stdID(-1);
1464
1465 stdID(wxID_ANY);
1466 stdID(wxID_SEPARATOR);
1467
1468 stdID(wxID_OPEN);
1469 stdID(wxID_CLOSE);
1470 stdID(wxID_NEW);
1471 stdID(wxID_SAVE);
1472 stdID(wxID_SAVEAS);
1473 stdID(wxID_REVERT);
1474 stdID(wxID_EXIT);
1475 stdID(wxID_UNDO);
1476 stdID(wxID_REDO);
1477 stdID(wxID_HELP);
1478 stdID(wxID_PRINT);
1479 stdID(wxID_PRINT_SETUP);
1480 stdID(wxID_PREVIEW);
1481 stdID(wxID_ABOUT);
1482 stdID(wxID_HELP_CONTENTS);
1483 stdID(wxID_HELP_COMMANDS);
1484 stdID(wxID_HELP_PROCEDURES);
1485 stdID(wxID_HELP_CONTEXT);
1486 stdID(wxID_CLOSE_ALL);
1487 stdID(wxID_PREFERENCES);
1488 stdID(wxID_CUT);
1489 stdID(wxID_COPY);
1490 stdID(wxID_PASTE);
1491 stdID(wxID_CLEAR);
1492 stdID(wxID_FIND);
1493 stdID(wxID_DUPLICATE);
1494 stdID(wxID_SELECTALL);
1495 stdID(wxID_DELETE);
1496 stdID(wxID_REPLACE);
1497 stdID(wxID_REPLACE_ALL);
1498 stdID(wxID_PROPERTIES);
1499 stdID(wxID_VIEW_DETAILS);
1500 stdID(wxID_VIEW_LARGEICONS);
1501 stdID(wxID_VIEW_SMALLICONS);
1502 stdID(wxID_VIEW_LIST);
1503 stdID(wxID_VIEW_SORTDATE);
1504 stdID(wxID_VIEW_SORTNAME);
1505 stdID(wxID_VIEW_SORTSIZE);
1506 stdID(wxID_VIEW_SORTTYPE);
1507 stdID(wxID_FILE1);
1508 stdID(wxID_FILE2);
1509 stdID(wxID_FILE3);
1510 stdID(wxID_FILE4);
1511 stdID(wxID_FILE5);
1512 stdID(wxID_FILE6);
1513 stdID(wxID_FILE7);
1514 stdID(wxID_FILE8);
1515 stdID(wxID_FILE9);
1516 stdID(wxID_OK);
1517 stdID(wxID_CANCEL);
1518 stdID(wxID_APPLY);
1519 stdID(wxID_YES);
1520 stdID(wxID_NO);
1521 stdID(wxID_STATIC);
1522 stdID(wxID_FORWARD);
1523 stdID(wxID_BACKWARD);
1524 stdID(wxID_DEFAULT);
1525 stdID(wxID_MORE);
1526 stdID(wxID_SETUP);
1527 stdID(wxID_RESET);
1528 stdID(wxID_CONTEXT_HELP);
1529 stdID(wxID_YESTOALL);
1530 stdID(wxID_NOTOALL);
1531 stdID(wxID_ABORT);
1532 stdID(wxID_RETRY);
1533 stdID(wxID_IGNORE);
1534 stdID(wxID_ADD);
1535 stdID(wxID_REMOVE);
1536 stdID(wxID_UP);
1537 stdID(wxID_DOWN);
1538 stdID(wxID_HOME);
1539 stdID(wxID_REFRESH);
1540 stdID(wxID_STOP);
1541 stdID(wxID_INDEX);
1542 stdID(wxID_BOLD);
1543 stdID(wxID_ITALIC);
1544 stdID(wxID_JUSTIFY_CENTER);
1545 stdID(wxID_JUSTIFY_FILL);
1546 stdID(wxID_JUSTIFY_RIGHT);
1547 stdID(wxID_JUSTIFY_LEFT);
1548 stdID(wxID_UNDERLINE);
1549 stdID(wxID_INDENT);
1550 stdID(wxID_UNINDENT);
1551 stdID(wxID_ZOOM_100);
1552 stdID(wxID_ZOOM_FIT);
1553 stdID(wxID_ZOOM_IN);
1554 stdID(wxID_ZOOM_OUT);
1555 stdID(wxID_UNDELETE);
1556 stdID(wxID_REVERT_TO_SAVED);
1557 stdID(wxID_SYSTEM_MENU);
1558 stdID(wxID_CLOSE_FRAME);
1559 stdID(wxID_MOVE_FRAME);
1560 stdID(wxID_RESIZE_FRAME);
1561 stdID(wxID_MAXIMIZE_FRAME);
1562 stdID(wxID_ICONIZE_FRAME);
1563 stdID(wxID_RESTORE_FRAME);
1564
1565 #undef stdID
1566 }
1567
1568
1569
1570
1571
1572 // --------------- module and globals -----------------------------
1573
1574 class wxXmlResourceModule: public wxModule
1575 {
1576 DECLARE_DYNAMIC_CLASS(wxXmlResourceModule)
1577 public:
1578 wxXmlResourceModule() {}
1579 bool OnInit()
1580 {
1581 AddStdXRCID_Records();
1582 wxXmlResource::AddSubclassFactory(new wxXmlSubclassFactoryCXX);
1583 return true;
1584 }
1585 void OnExit()
1586 {
1587 delete wxXmlResource::Set(NULL);
1588 if(wxXmlResource::ms_subclassFactories)
1589 WX_CLEAR_LIST(wxXmlSubclassFactoriesList, *wxXmlResource::ms_subclassFactories);
1590 wxDELETE(wxXmlResource::ms_subclassFactories);
1591 CleanXRCID_Records();
1592 }
1593 };
1594
1595 IMPLEMENT_DYNAMIC_CLASS(wxXmlResourceModule, wxModule)
1596
1597
1598 // When wxXml is loaded dynamically after the application is already running
1599 // then the built-in module system won't pick this one up. Add it manually.
1600 void wxXmlInitResourceModule()
1601 {
1602 wxModule* module = new wxXmlResourceModule;
1603 module->Init();
1604 wxModule::RegisterModule(module);
1605 }
1606
1607 #endif // wxUSE_XRC