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