]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xmlres.cpp
making sure peer->Move refreshes properly, bringing in synch with carbon, applying...
[wxWidgets.git] / src / xrc / xmlres.cpp
CommitLineData
78d14f80 1/////////////////////////////////////////////////////////////////////////////
88a7a4e1 2// Name: src/xrc/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
78d14f80
VS
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
621be1ec 18#if wxUSE_XRC
a1e4ec87 19
88a7a4e1
WS
20#include "wx/xrc/xmlres.h"
21
22#ifndef WX_PRECOMP
23 #include "wx/intl.h"
e4db172a 24 #include "wx/log.h"
8e609c82 25 #include "wx/panel.h"
76b49cf4 26 #include "wx/frame.h"
fdf565fe 27 #include "wx/dialog.h"
9eddec69 28 #include "wx/settings.h"
0bca0373 29 #include "wx/bitmap.h"
155ecd4c 30 #include "wx/image.h"
02761f6c 31 #include "wx/module.h"
193d0c93 32 #include "wx/wxcrtvararg.h"
88a7a4e1
WS
33#endif
34
e7a3a5a5 35#ifndef __WXWINCE__
88a7a4e1 36 #include <locale.h>
e7a3a5a5 37#endif
1df61962 38
eb2d0d23 39#include "wx/vector.h"
78d14f80
VS
40#include "wx/wfstream.h"
41#include "wx/filesys.h"
317a0d73 42#include "wx/filename.h"
78d14f80
VS
43#include "wx/tokenzr.h"
44#include "wx/fontenum.h"
78d14f80 45#include "wx/fontmap.h"
af1337b0 46#include "wx/artprov.h"
2bb9a404 47#include "wx/dir.h"
34c6bbee 48#include "wx/xml/xml.h"
78d14f80 49
f35fdf7e 50
eb2d0d23
VS
51class wxXmlResourceDataRecord
52{
53public:
54 wxXmlResourceDataRecord() : Doc(NULL) {
55#if wxUSE_DATETIME
56 Time = wxDateTime::Now();
57#endif
58 }
59 ~wxXmlResourceDataRecord() {delete Doc;}
60
61 wxString File;
62 wxXmlDocument *Doc;
63#if wxUSE_DATETIME
64 wxDateTime Time;
65#endif
66};
67
f396e5a7 68class wxXmlResourceDataRecords : public wxVector<wxXmlResourceDataRecord*>
eb2d0d23
VS
69{
70 // this is a class so that it can be forward-declared
71};
78d14f80 72
23239d94
VZ
73namespace
74{
75
76// helper used by DoFindResource() and elsewhere: returns true if this is an
77// object or object_ref node
78//
79// node must be non-NULL
80inline bool IsObjectNode(wxXmlNode *node)
81{
82 return node->GetType() == wxXML_ELEMENT_NODE &&
83 (node->GetName() == wxS("object") ||
84 node->GetName() == wxS("object_ref"));
85}
86
87} // anonymous namespace
88
78d14f80 89
824e8eaa
VS
90wxXmlResource *wxXmlResource::ms_instance = NULL;
91
92/*static*/ wxXmlResource *wxXmlResource::Get()
93{
94 if ( !ms_instance )
95 ms_instance = new wxXmlResource;
96 return ms_instance;
97}
98
99/*static*/ wxXmlResource *wxXmlResource::Set(wxXmlResource *res)
100{
101 wxXmlResource *old = ms_instance;
102 ms_instance = res;
103 return old;
104}
105
d4a724d4 106wxXmlResource::wxXmlResource(int flags, const wxString& domain)
78d14f80 107{
daa85ee3 108 m_flags = flags;
78d14f80 109 m_version = -1;
eb2d0d23 110 m_data = new wxXmlResourceDataRecords;
d7a80cf5 111 SetDomain(domain);
78d14f80
VS
112}
113
d4a724d4 114wxXmlResource::wxXmlResource(const wxString& filemask, int flags, const wxString& domain)
78d14f80 115{
daa85ee3 116 m_flags = flags;
78d14f80 117 m_version = -1;
eb2d0d23 118 m_data = new wxXmlResourceDataRecords;
d7a80cf5 119 SetDomain(domain);
78d14f80
VS
120 Load(filemask);
121}
122
123wxXmlResource::~wxXmlResource()
124{
125 ClearHandlers();
eb2d0d23 126
f396e5a7
VS
127 for ( wxXmlResourceDataRecords::iterator i = m_data->begin();
128 i != m_data->end(); ++i )
129 {
130 delete *i;
131 }
eb2d0d23 132 delete m_data;
78d14f80
VS
133}
134
d7a80cf5 135void wxXmlResource::SetDomain(const wxString& domain)
d4a724d4 136{
d7a80cf5 137 m_domain = domain;
d4a724d4
RD
138}
139
78d14f80 140
60fd818a
VZ
141/* static */
142wxString wxXmlResource::ConvertFileNameToURL(const wxString& filename)
143{
144 wxString fnd(filename);
145
146 // NB: as Load() and Unload() accept both filenames and URLs (should
147 // probably be changed to filenames only, but embedded resources
148 // currently rely on its ability to handle URLs - FIXME) we need to
149 // determine whether found name is filename and not URL and this is the
150 // fastest/simplest way to do it
151 if (wxFileName::FileExists(fnd))
152 {
153 // Make the name absolute filename, because the app may
154 // change working directory later:
155 wxFileName fn(fnd);
156 if (fn.IsRelative())
157 {
158 fn.MakeAbsolute();
159 fnd = fn.GetFullPath();
160 }
161#if wxUSE_FILESYSTEM
162 fnd = wxFileSystem::FileNameToURL(fnd);
163#endif
164 }
165
166 return fnd;
167}
168
169#if wxUSE_FILESYSTEM
170
171/* static */
172bool wxXmlResource::IsArchive(const wxString& filename)
173{
174 const wxString fnd = filename.Lower();
175
176 return fnd.Matches(wxT("*.zip")) || fnd.Matches(wxT("*.xrs"));
177}
178
179#endif // wxUSE_FILESYSTEM
180
04ae32cd
VS
181bool wxXmlResource::LoadFile(const wxFileName& file)
182{
183 return Load(wxFileSystem::FileNameToURL(file));
184}
185
2bb9a404
VS
186bool wxXmlResource::LoadAllFiles(const wxString& dirname)
187{
188 bool ok = true;
189 wxArrayString files;
190
191 wxDir::GetAllFiles(dirname, &files, "*.xrc");
192
193 for ( wxArrayString::const_iterator i = files.begin(); i != files.end(); ++i )
194 {
195 if ( !LoadFile(*i) )
196 ok = false;
197 }
198
199 return ok;
200}
201
acd32ffc 202bool wxXmlResource::Load(const wxString& filemask_)
78d14f80 203{
acd32ffc
VS
204 wxString filemask = ConvertFileNameToURL(filemask_);
205
78d14f80
VS
206#if wxUSE_FILESYSTEM
207 wxFileSystem fsys;
208# define wxXmlFindFirst fsys.FindFirst(filemask, wxFILE)
209# define wxXmlFindNext fsys.FindNext()
210#else
211# define wxXmlFindFirst wxFindFirstFile(filemask, wxFILE)
212# define wxXmlFindNext wxFindNextFile()
213#endif
e5bb501b
VZ
214 wxString fnd = wxXmlFindFirst;
215 if ( fnd.empty() )
216 {
217 wxLogError(_("Cannot load resources from '%s'."), filemask);
218 return false;
219 }
220
ec157c8f 221 while (!fnd.empty())
78d14f80
VS
222 {
223#if wxUSE_FILESYSTEM
60fd818a 224 if ( IsArchive(fnd) )
78d14f80 225 {
e5bb501b
VZ
226 if ( !Load(fnd + wxT("#zip:*.xrc")) )
227 return false;
78d14f80 228 }
60fd818a
VZ
229 else // a single resource URL
230#endif // wxUSE_FILESYSTEM
78d14f80 231 {
f396e5a7
VS
232 wxXmlResourceDataRecord *drec = new wxXmlResourceDataRecord;
233 drec->File = fnd;
eb2d0d23 234 Data().push_back(drec);
78d14f80
VS
235 }
236
e5bb501b 237 fnd = wxXmlFindNext;
78d14f80
VS
238 }
239# undef wxXmlFindFirst
240# undef wxXmlFindNext
e5bb501b
VZ
241
242 return UpdateResources();
78d14f80
VS
243}
244
60fd818a
VZ
245bool wxXmlResource::Unload(const wxString& filename)
246{
247 wxASSERT_MSG( !wxIsWild(filename),
248 _T("wildcards not supported by wxXmlResource::Unload()") );
249
250 wxString fnd = ConvertFileNameToURL(filename);
251#if wxUSE_FILESYSTEM
252 const bool isArchive = IsArchive(fnd);
253 if ( isArchive )
254 fnd += _T("#zip:");
255#endif // wxUSE_FILESYSTEM
256
257 bool unloaded = false;
eb2d0d23
VS
258 for ( wxXmlResourceDataRecords::iterator i = Data().begin();
259 i != Data().end(); ++i )
60fd818a
VZ
260 {
261#if wxUSE_FILESYSTEM
262 if ( isArchive )
263 {
f396e5a7 264 if ( (*i)->File.StartsWith(fnd) )
60fd818a
VZ
265 unloaded = true;
266 // don't break from the loop, we can have other matching files
267 }
268 else // a single resource URL
269#endif // wxUSE_FILESYSTEM
270 {
f396e5a7 271 if ( (*i)->File == fnd )
60fd818a 272 {
f8b1df0b 273 delete *i;
eb2d0d23 274 Data().erase(i);
60fd818a
VZ
275 unloaded = true;
276
277 // no sense in continuing, there is only one file with this URL
278 break;
279 }
280 }
281 }
282
283 return unloaded;
284}
285
78d14f80 286
854e189f 287IMPLEMENT_ABSTRACT_CLASS(wxXmlResourceHandler, wxObject)
78d14f80
VS
288
289void wxXmlResource::AddHandler(wxXmlResourceHandler *handler)
290{
eb2d0d23 291 m_handlers.push_back(handler);
78d14f80
VS
292 handler->SetParentResource(this);
293}
294
92e898b0
RD
295void wxXmlResource::InsertHandler(wxXmlResourceHandler *handler)
296{
eb2d0d23 297 m_handlers.insert(m_handlers.begin(), handler);
92e898b0
RD
298 handler->SetParentResource(this);
299}
300
78d14f80
VS
301
302
303void wxXmlResource::ClearHandlers()
304{
eb2d0d23
VS
305 for ( wxVector<wxXmlResourceHandler*>::iterator i = m_handlers.begin();
306 i != m_handlers.end(); ++i )
307 delete *i;
308 m_handlers.clear();
78d14f80
VS
309}
310
311
78d14f80
VS
312wxMenu *wxXmlResource::LoadMenu(const wxString& name)
313{
314 return (wxMenu*)CreateResFromNode(FindResource(name, wxT("wxMenu")), NULL, NULL);
315}
316
317
318
4a1b9596 319wxMenuBar *wxXmlResource::LoadMenuBar(wxWindow *parent, const wxString& name)
78d14f80 320{
4a1b9596 321 return (wxMenuBar*)CreateResFromNode(FindResource(name, wxT("wxMenuBar")), parent, NULL);
78d14f80
VS
322}
323
324
325
4a1b9596 326#if wxUSE_TOOLBAR
78d14f80
VS
327wxToolBar *wxXmlResource::LoadToolBar(wxWindow *parent, const wxString& name)
328{
329 return (wxToolBar*)CreateResFromNode(FindResource(name, wxT("wxToolBar")), parent, NULL);
330}
4a1b9596 331#endif
78d14f80
VS
332
333
334wxDialog *wxXmlResource::LoadDialog(wxWindow *parent, const wxString& name)
335{
4dd75a6a 336 return (wxDialog*)CreateResFromNode(FindResource(name, wxT("wxDialog")), parent, NULL);
78d14f80
VS
337}
338
339bool wxXmlResource::LoadDialog(wxDialog *dlg, wxWindow *parent, const wxString& name)
340{
341 return CreateResFromNode(FindResource(name, wxT("wxDialog")), parent, dlg) != NULL;
342}
343
344
345
346wxPanel *wxXmlResource::LoadPanel(wxWindow *parent, const wxString& name)
347{
348 return (wxPanel*)CreateResFromNode(FindResource(name, wxT("wxPanel")), parent, NULL);
349}
350
351bool wxXmlResource::LoadPanel(wxPanel *panel, wxWindow *parent, const wxString& name)
352{
353 return CreateResFromNode(FindResource(name, wxT("wxPanel")), parent, panel) != NULL;
354}
355
92e898b0
RD
356wxFrame *wxXmlResource::LoadFrame(wxWindow* parent, const wxString& name)
357{
358 return (wxFrame*)CreateResFromNode(FindResource(name, wxT("wxFrame")), parent, NULL);
359}
360
78d14f80
VS
361bool wxXmlResource::LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name)
362{
363 return CreateResFromNode(FindResource(name, wxT("wxFrame")), parent, frame) != NULL;
364}
365
366wxBitmap wxXmlResource::LoadBitmap(const wxString& name)
367{
368 wxBitmap *bmp = (wxBitmap*)CreateResFromNode(
369 FindResource(name, wxT("wxBitmap")), NULL, NULL);
370 wxBitmap rt;
371
372 if (bmp) { rt = *bmp; delete bmp; }
373 return rt;
374}
375
376wxIcon wxXmlResource::LoadIcon(const wxString& name)
377{
378 wxIcon *icon = (wxIcon*)CreateResFromNode(
379 FindResource(name, wxT("wxIcon")), NULL, NULL);
380 wxIcon rt;
381
382 if (icon) { rt = *icon; delete icon; }
383 return rt;
384}
385
92e898b0
RD
386
387wxObject *wxXmlResource::LoadObject(wxWindow *parent, const wxString& name, const wxString& classname)
388{
389 return CreateResFromNode(FindResource(name, classname), parent, NULL);
390}
391
392bool wxXmlResource::LoadObject(wxObject *instance, wxWindow *parent, const wxString& name, const wxString& classname)
393{
394 return CreateResFromNode(FindResource(name, classname), parent, instance) != NULL;
395}
396
397
78d14f80
VS
398bool wxXmlResource::AttachUnknownControl(const wxString& name,
399 wxWindow *control, wxWindow *parent)
400{
401 if (parent == NULL)
402 parent = control->GetParent();
403 wxWindow *container = parent->FindWindow(name + wxT("_container"));
404 if (!container)
405 {
406 wxLogError(_("Cannot find container for unknown control '%s'."), name.c_str());
f80ea77b 407 return false;
78d14f80
VS
408 }
409 return control->Reparent(container);
410}
411
412
77b2f9b1 413static void ProcessPlatformProperty(wxXmlNode *node)
78d14f80
VS
414{
415 wxString s;
416 bool isok;
417
418 wxXmlNode *c = node->GetChildren();
419 while (c)
420 {
f80ea77b 421 isok = false;
288b6107 422 if (!c->GetAttribute(wxT("platform"), &s))
f80ea77b 423 isok = true;
78d14f80
VS
424 else
425 {
2b5f62a0 426 wxStringTokenizer tkn(s, wxT(" |"));
78d14f80
VS
427
428 while (tkn.HasMoreTokens())
429 {
430 s = tkn.GetNextToken();
84389518 431#ifdef __WINDOWS__
d003330c
VS
432 if (s == wxT("win")) isok = true;
433#endif
b380439d 434#if defined(__MAC__) || defined(__APPLE__)
d003330c 435 if (s == wxT("mac")) isok = true;
b380439d
RD
436#elif defined(__UNIX__)
437 if (s == wxT("unix")) isok = true;
78d14f80 438#endif
d003330c
VS
439#ifdef __OS2__
440 if (s == wxT("os2")) isok = true;
441#endif
442
443 if (isok)
444 break;
78d14f80
VS
445 }
446 }
447
448 if (isok)
d7b1d73c 449 {
78d14f80 450 ProcessPlatformProperty(c);
d7b1d73c
VS
451 c = c->GetNext();
452 }
78d14f80
VS
453 else
454 {
d7b1d73c 455 wxXmlNode *c2 = c->GetNext();
db59a97c 456 node->RemoveChild(c);
78d14f80 457 delete c;
d7b1d73c 458 c = c2;
78d14f80 459 }
78d14f80
VS
460 }
461}
462
463
464
d614f51b 465bool wxXmlResource::UpdateResources()
78d14f80 466{
d614f51b 467 bool rt = true;
78d14f80
VS
468 bool modif;
469# if wxUSE_FILESYSTEM
470 wxFSFile *file = NULL;
19d0f58d 471 wxUnusedVar(file);
78d14f80
VS
472 wxFileSystem fsys;
473# endif
474
480505bc
VS
475 wxString encoding(wxT("UTF-8"));
476#if !wxUSE_UNICODE && wxUSE_INTL
477 if ( (GetFlags() & wxXRC_USE_LOCALE) == 0 )
478 {
75d38380
VS
479 // In case we are not using wxLocale to translate strings, convert the
480 // strings GUI's charset. This must not be done when wxXRC_USE_LOCALE
481 // is on, because it could break wxGetTranslation lookup.
480505bc
VS
482 encoding = wxLocale::GetSystemEncodingName();
483 }
484#endif
485
eb2d0d23
VS
486 for ( wxXmlResourceDataRecords::iterator i = Data().begin();
487 i != Data().end(); ++i )
78d14f80 488 {
f396e5a7
VS
489 wxXmlResourceDataRecord* const rec = *i;
490
491 modif = (rec->Doc == NULL);
78d14f80 492
648db587 493 if (!modif && !(m_flags & wxXRC_NO_RELOADING))
78d14f80
VS
494 {
495# if wxUSE_FILESYSTEM
f396e5a7 496 file = fsys.OpenFile(rec->File);
34af0de4 497# if wxUSE_DATETIME
f396e5a7 498 modif = file && file->GetModificationTime() > rec->Time;
34af0de4
VZ
499# else // wxUSE_DATETIME
500 modif = true;
501# endif // wxUSE_DATETIME
78d14f80 502 if (!file)
d614f51b 503 {
f396e5a7 504 wxLogError(_("Cannot open file '%s'."), rec->File);
d614f51b
VS
505 rt = false;
506 }
78d14f80 507 wxDELETE(file);
19d0f58d 508 wxUnusedVar(file);
34af0de4
VZ
509# else // wxUSE_FILESYSTEM
510# if wxUSE_DATETIME
f396e5a7 511 modif = wxDateTime(wxFileModificationTime(rec->File)) > rec->Time;
34af0de4
VZ
512# else // wxUSE_DATETIME
513 modif = true;
514# endif // wxUSE_DATETIME
515# endif // wxUSE_FILESYSTEM
78d14f80
VS
516 }
517
518 if (modif)
519 {
f396e5a7 520 wxLogTrace(_T("xrc"), _T("opening file '%s'"), rec->File);
648db587 521
480505bc 522 wxInputStream *stream = NULL;
78d14f80
VS
523
524# if wxUSE_FILESYSTEM
f396e5a7 525 file = fsys.OpenFile(rec->File);
f80ea77b
WS
526 if (file)
527 stream = file->GetStream();
78d14f80 528# else
f396e5a7 529 stream = new wxFileInputStream(rec->File);
78d14f80
VS
530# endif
531
532 if (stream)
533 {
f396e5a7
VS
534 delete rec->Doc;
535 rec->Doc = new wxXmlDocument;
78d14f80 536 }
9690b006 537 if (!stream || !stream->IsOk() || !rec->Doc->Load(*stream, encoding))
78d14f80 538 {
480505bc 539 wxLogError(_("Cannot load resources from file '%s'."),
f396e5a7
VS
540 rec->File);
541 wxDELETE(rec->Doc);
d614f51b 542 rt = false;
78d14f80 543 }
f396e5a7 544 else if (rec->Doc->GetRoot()->GetName() != wxT("resource"))
78d14f80 545 {
f396e5a7
VS
546 wxLogError(_("Invalid XRC resource '%s': doesn't have root node 'resource'."), rec->File);
547 wxDELETE(rec->Doc);
d614f51b 548 rt = false;
78d14f80
VS
549 }
550 else
f80ea77b 551 {
78d14f80
VS
552 long version;
553 int v1, v2, v3, v4;
f396e5a7 554 wxString verstr = rec->Doc->GetRoot()->GetAttribute(
78d14f80
VS
555 wxT("version"), wxT("0.0.0.0"));
556 if (wxSscanf(verstr.c_str(), wxT("%i.%i.%i.%i"),
557 &v1, &v2, &v3, &v4) == 4)
558 version = v1*256*256*256+v2*256*256+v3*256+v4;
559 else
560 version = 0;
561 if (m_version == -1)
562 m_version = version;
563 if (m_version != version)
d614f51b 564 {
78d14f80 565 wxLogError(_("Resource files must have same version number!"));
d614f51b
VS
566 rt = false;
567 }
78d14f80 568
f396e5a7 569 ProcessPlatformProperty(rec->Doc->GetRoot());
34af0de4 570#if wxUSE_DATETIME
496f0a58 571#if wxUSE_FILESYSTEM
f396e5a7 572 rec->Time = file->GetModificationTime();
34af0de4 573#else // wxUSE_FILESYSTEM
f396e5a7 574 rec->Time = wxDateTime(wxFileModificationTime(rec->File));
34af0de4
VZ
575#endif // wxUSE_FILESYSTEM
576#endif // wxUSE_DATETIME
f80ea77b 577 }
78d14f80
VS
578
579# if wxUSE_FILESYSTEM
f80ea77b
WS
580 wxDELETE(file);
581 wxUnusedVar(file);
78d14f80 582# else
f80ea77b 583 wxDELETE(stream);
78d14f80
VS
584# endif
585 }
586 }
d614f51b
VS
587
588 return rt;
78d14f80
VS
589}
590
b272b6dc
RD
591wxXmlNode *wxXmlResource::DoFindResource(wxXmlNode *parent,
592 const wxString& name,
593 const wxString& classname,
23239d94 594 bool recursive) const
47793ab8 595{
47793ab8
VS
596 wxXmlNode *node;
597
598 // first search for match at the top-level nodes (as this is
599 // where the resource is most commonly looked for):
600 for (node = parent->GetChildren(); node; node = node->GetNext())
601 {
23239d94 602 if ( IsObjectNode(node) && node->GetAttribute(wxS("name")) == name )
2b5f62a0 603 {
23239d94
VZ
604 // empty class name matches everything
605 if ( classname.empty() )
2b5f62a0 606 return node;
23239d94
VZ
607
608 wxString cls(node->GetAttribute(wxS("class")));
609
288b6107 610 // object_ref may not have 'class' attribute:
23239d94 611 if (cls.empty() && node->GetName() == wxS("object_ref"))
2b5f62a0 612 {
23239d94 613 wxString refName = node->GetAttribute(wxS("ref"));
2b5f62a0
VZ
614 if (refName.empty())
615 continue;
23239d94
VZ
616
617 const wxXmlNode * const refNode = GetResourceNode(refName);
618 if ( refNode )
619 cls = refNode->GetAttribute(wxS("class"));
2b5f62a0 620 }
23239d94
VZ
621
622 if ( cls == classname )
623 return node;
2b5f62a0 624 }
47793ab8
VS
625 }
626
23239d94 627 // then recurse in child nodes
47793ab8 628 if ( recursive )
23239d94 629 {
47793ab8
VS
630 for (node = parent->GetChildren(); node; node = node->GetNext())
631 {
23239d94 632 if ( IsObjectNode(node) )
47793ab8 633 {
f80ea77b 634 wxXmlNode* found = DoFindResource(node, name, classname, true);
47793ab8
VS
635 if ( found )
636 return found;
637 }
638 }
23239d94 639 }
47793ab8 640
23239d94 641 return NULL;
47793ab8 642}
78d14f80 643
b272b6dc 644wxXmlNode *wxXmlResource::FindResource(const wxString& name,
47793ab8
VS
645 const wxString& classname,
646 bool recursive)
78d14f80 647{
23239d94
VZ
648 wxString path;
649 wxXmlNode * const
650 node = GetResourceNodeAndLocation(name, classname, recursive, &path);
651
652 if ( !node )
653 {
654 wxLogError(_("XRC resource '%s' (class '%s') not found!"),
655 name, classname);
656 }
657#if wxUSE_FILESYSTEM
658 else // node was found
659 {
660 // ensure that relative paths work correctly when loading this node
661 // (which should happen as soon as we return as FindResource() result
662 // is always passed to CreateResFromNode())
663 m_curFileSystem.ChangePathTo(path);
664 }
665#endif // wxUSE_FILESYSTEM
666
667 return node;
668}
669
670wxXmlNode *
671wxXmlResource::GetResourceNodeAndLocation(const wxString& name,
672 const wxString& classname,
673 bool recursive,
674 wxString *path) const
675{
676 // ensure everything is up-to-date: this is needed to support on-remand
677 // reloading of XRC files
678 const_cast<wxXmlResource *>(this)->UpdateResources();
78d14f80 679
eb2d0d23
VS
680 for ( wxXmlResourceDataRecords::const_iterator f = Data().begin();
681 f != Data().end(); ++f )
78d14f80 682 {
23239d94
VZ
683 wxXmlResourceDataRecord *const rec = *f;
684 wxXmlDocument * const doc = rec->Doc;
685 if ( !doc || !doc->GetRoot() )
47793ab8
VS
686 continue;
687
23239d94
VZ
688 wxXmlNode * const
689 found = DoFindResource(doc->GetRoot(), name, classname, recursive);
47793ab8
VS
690 if ( found )
691 {
23239d94
VZ
692 if ( path )
693 *path = rec->File;
694
47793ab8
VS
695 return found;
696 }
78d14f80
VS
697 }
698
78d14f80
VS
699 return NULL;
700}
701
47793ab8
VS
702static void MergeNodes(wxXmlNode& dest, wxXmlNode& with)
703{
288b6107
VS
704 // Merge attributes:
705 for ( wxXmlAttribute *attr = with.GetAttributes();
706 attr; attr = attr->GetNext() )
47793ab8 707 {
288b6107
VS
708 wxXmlAttribute *dattr;
709 for (dattr = dest.GetAttributes(); dattr; dattr = dattr->GetNext())
47793ab8 710 {
b272b6dc 711
288b6107 712 if ( dattr->GetName() == attr->GetName() )
47793ab8 713 {
288b6107 714 dattr->SetValue(attr->GetValue());
47793ab8
VS
715 break;
716 }
717 }
78d14f80 718
288b6107
VS
719 if ( !dattr )
720 dest.AddAttribute(attr->GetName(), attr->GetValue());
47793ab8
VS
721 }
722
723 // Merge child nodes:
724 for (wxXmlNode* node = with.GetChildren(); node; node = node->GetNext())
725 {
288b6107 726 wxString name = node->GetAttribute(wxT("name"), wxEmptyString);
47793ab8
VS
727 wxXmlNode *dnode;
728
729 for (dnode = dest.GetChildren(); dnode; dnode = dnode->GetNext() )
730 {
731 if ( dnode->GetName() == node->GetName() &&
288b6107 732 dnode->GetAttribute(wxT("name"), wxEmptyString) == name &&
47793ab8
VS
733 dnode->GetType() == node->GetType() )
734 {
735 MergeNodes(*dnode, *node);
736 break;
737 }
738 }
739
740 if ( !dnode )
b26a650c
VZ
741 {
742 static const wxChar *AT_END = wxT("end");
288b6107 743 wxString insert_pos = node->GetAttribute(wxT("insert_at"), AT_END);
b26a650c
VZ
744 if ( insert_pos == AT_END )
745 {
746 dest.AddChild(new wxXmlNode(*node));
747 }
748 else if ( insert_pos == wxT("begin") )
749 {
750 dest.InsertChild(new wxXmlNode(*node), dest.GetChildren());
751 }
752 }
47793ab8
VS
753 }
754
0bca0373 755 if ( dest.GetType() == wxXML_TEXT_NODE && with.GetContent().length() )
47793ab8
VS
756 dest.SetContent(with.GetContent());
757}
78d14f80 758
317a0d73
VS
759wxObject *wxXmlResource::CreateResFromNode(wxXmlNode *node, wxObject *parent,
760 wxObject *instance,
761 wxXmlResourceHandler *handlerToUse)
78d14f80
VS
762{
763 if (node == NULL) return NULL;
764
47793ab8
VS
765 // handling of referenced resource
766 if ( node->GetName() == wxT("object_ref") )
767 {
288b6107 768 wxString refName = node->GetAttribute(wxT("ref"), wxEmptyString);
f80ea77b 769 wxXmlNode* refNode = FindResource(refName, wxEmptyString, true);
47793ab8
VS
770
771 if ( !refNode )
772 {
b272b6dc 773 wxLogError(_("Referenced object node with ref=\"%s\" not found!"),
47793ab8
VS
774 refName.c_str());
775 return NULL;
776 }
777
778 wxXmlNode copy(*refNode);
779 MergeNodes(copy, *node);
780
781 return CreateResFromNode(&copy, parent, instance);
782 }
783
317a0d73 784 if (handlerToUse)
b380439d 785 {
317a0d73 786 if (handlerToUse->CanHandle(node))
8e8a4e85 787 {
317a0d73 788 return handlerToUse->CreateResource(node, parent, instance);
8e8a4e85 789 }
317a0d73
VS
790 }
791 else if (node->GetName() == wxT("object"))
b380439d 792 {
eb2d0d23
VS
793 for ( wxVector<wxXmlResourceHandler*>::iterator h = m_handlers.begin();
794 h != m_handlers.end(); ++h )
317a0d73 795 {
eb2d0d23 796 wxXmlResourceHandler *handler = *h;
317a0d73 797 if (handler->CanHandle(node))
317a0d73 798 return handler->CreateResource(node, parent, instance);
78d14f80 799 }
78d14f80
VS
800 }
801
802 wxLogError(_("No handler found for XML node '%s', class '%s'!"),
803 node->GetName().c_str(),
288b6107 804 node->GetAttribute(wxT("class"), wxEmptyString).c_str());
78d14f80
VS
805 return NULL;
806}
807
808
eb2d0d23
VS
809class wxXmlSubclassFactories : public wxVector<wxXmlSubclassFactory*>
810{
811 // this is a class so that it can be forward-declared
812};
2b5f62a0 813
eb2d0d23 814wxXmlSubclassFactories *wxXmlResource::ms_subclassFactories = NULL;
2b5f62a0
VZ
815
816/*static*/ void wxXmlResource::AddSubclassFactory(wxXmlSubclassFactory *factory)
817{
818 if (!ms_subclassFactories)
819 {
eb2d0d23 820 ms_subclassFactories = new wxXmlSubclassFactories;
2b5f62a0 821 }
eb2d0d23 822 ms_subclassFactories->push_back(factory);
2b5f62a0
VZ
823}
824
825class wxXmlSubclassFactoryCXX : public wxXmlSubclassFactory
826{
827public:
828 ~wxXmlSubclassFactoryCXX() {}
829
830 wxObject *Create(const wxString& className)
831 {
832 wxClassInfo* classInfo = wxClassInfo::FindClass(className);
833
834 if (classInfo)
835 return classInfo->CreateObject();
836 else
837 return NULL;
838 }
839};
840
841
842
78d14f80 843
78d14f80
VS
844wxXmlResourceHandler::wxXmlResourceHandler()
845 : m_node(NULL), m_parent(NULL), m_instance(NULL),
9a8d8c5a 846 m_parentAsWindow(NULL)
78d14f80
VS
847{}
848
849
850
851wxObject *wxXmlResourceHandler::CreateResource(wxXmlNode *node, wxObject *parent, wxObject *instance)
852{
853 wxXmlNode *myNode = m_node;
854 wxString myClass = m_class;
855 wxObject *myParent = m_parent, *myInstance = m_instance;
9a8d8c5a 856 wxWindow *myParentAW = m_parentAsWindow;
78d14f80 857
daa85ee3 858 m_instance = instance;
288b6107 859 if (!m_instance && node->HasAttribute(wxT("subclass")) &&
daa85ee3
VS
860 !(m_resource->GetFlags() & wxXRC_NO_SUBCLASSING))
861 {
288b6107 862 wxString subclass = node->GetAttribute(wxT("subclass"), wxEmptyString);
2b5f62a0 863 if (!subclass.empty())
daa85ee3 864 {
eb2d0d23
VS
865 for (wxXmlSubclassFactories::iterator i = wxXmlResource::ms_subclassFactories->begin();
866 i != wxXmlResource::ms_subclassFactories->end(); ++i)
2b5f62a0 867 {
eb2d0d23 868 m_instance = (*i)->Create(subclass);
2b5f62a0
VZ
869 if (m_instance)
870 break;
871 }
daa85ee3 872
2b5f62a0
VZ
873 if (!m_instance)
874 {
288b6107 875 wxString name = node->GetAttribute(wxT("name"), wxEmptyString);
2b5f62a0
VZ
876 wxLogError(_("Subclass '%s' not found for resource '%s', not subclassing!"),
877 subclass.c_str(), name.c_str());
878 }
879 }
daa85ee3
VS
880 }
881
78d14f80 882 m_node = node;
288b6107 883 m_class = node->GetAttribute(wxT("class"), wxEmptyString);
78d14f80 884 m_parent = parent;
78d14f80 885 m_parentAsWindow = wxDynamicCast(m_parent, wxWindow);
78d14f80
VS
886
887 wxObject *returned = DoCreateResource();
888
889 m_node = myNode;
890 m_class = myClass;
891 m_parent = myParent; m_parentAsWindow = myParentAW;
9a8d8c5a 892 m_instance = myInstance;
78d14f80
VS
893
894 return returned;
895}
896
897
898void wxXmlResourceHandler::AddStyle(const wxString& name, int value)
899{
900 m_styleNames.Add(name);
901 m_styleValues.Add(value);
902}
903
904
905
906void wxXmlResourceHandler::AddWindowStyles()
907{
9dc579b3 908 XRC_ADD_STYLE(wxCLIP_CHILDREN);
d54a3e73
VZ
909
910 // the border styles all have the old and new names, recognize both for now
911 XRC_ADD_STYLE(wxSIMPLE_BORDER); XRC_ADD_STYLE(wxBORDER_SIMPLE);
912 XRC_ADD_STYLE(wxSUNKEN_BORDER); XRC_ADD_STYLE(wxBORDER_SUNKEN);
913 XRC_ADD_STYLE(wxDOUBLE_BORDER); XRC_ADD_STYLE(wxBORDER_DOUBLE);
914 XRC_ADD_STYLE(wxRAISED_BORDER); XRC_ADD_STYLE(wxBORDER_RAISED);
915 XRC_ADD_STYLE(wxSTATIC_BORDER); XRC_ADD_STYLE(wxBORDER_STATIC);
916 XRC_ADD_STYLE(wxNO_BORDER); XRC_ADD_STYLE(wxBORDER_NONE);
917
daa85ee3
VS
918 XRC_ADD_STYLE(wxTRANSPARENT_WINDOW);
919 XRC_ADD_STYLE(wxWANTS_CHARS);
43840d8b 920 XRC_ADD_STYLE(wxTAB_TRAVERSAL);
daa85ee3 921 XRC_ADD_STYLE(wxNO_FULL_REPAINT_ON_RESIZE);
7539ba56 922 XRC_ADD_STYLE(wxFULL_REPAINT_ON_RESIZE);
162a4f93 923 XRC_ADD_STYLE(wxALWAYS_SHOW_SB);
9f4ed861 924 XRC_ADD_STYLE(wxWS_EX_BLOCK_EVENTS);
b0802e64 925 XRC_ADD_STYLE(wxWS_EX_VALIDATE_RECURSIVELY);
78d14f80
VS
926}
927
928
929
930bool wxXmlResourceHandler::HasParam(const wxString& param)
931{
932 return (GetParamNode(param) != NULL);
933}
934
935
936int wxXmlResourceHandler::GetStyle(const wxString& param, int defaults)
937{
938 wxString s = GetParamValue(param);
939
940 if (!s) return defaults;
941
2b5f62a0 942 wxStringTokenizer tkn(s, wxT("| \t\n"), wxTOKEN_STRTOK);
78d14f80
VS
943 int style = 0;
944 int index;
945 wxString fl;
946 while (tkn.HasMoreTokens())
947 {
948 fl = tkn.GetNextToken();
949 index = m_styleNames.Index(fl);
950 if (index != wxNOT_FOUND)
951 style |= m_styleValues[index];
952 else
953 wxLogError(_("Unknown style flag ") + fl);
954 }
955 return style;
956}
957
958
959
ee1046d1 960wxString wxXmlResourceHandler::GetText(const wxString& param, bool translate)
78d14f80 961{
7b56015f
VS
962 wxXmlNode *parNode = GetParamNode(param);
963 wxString str1(GetNodeContent(parNode));
78d14f80 964 wxString str2;
424af7aa
VS
965
966 // "\\" wasn't translated to "\" prior to 2.5.3.0:
967 const bool escapeBackslash = (m_resource->CompareVersion(2,5,3,0) >= 0);
78d14f80 968
b272b6dc
RD
969 // VS: First version of XRC resources used $ instead of & (which is
970 // illegal in XML), but later I realized that '_' fits this purpose
718cf160 971 // much better (because &File means "File with F underlined").
424af7aa
VS
972 const wxChar amp_char = (m_resource->CompareVersion(2,3,0,1) < 0)
973 ? '$' : '_';
78d14f80 974
424af7aa 975 for ( wxString::const_iterator dt = str1.begin(); dt != str1.end(); ++dt )
78d14f80
VS
976 {
977 // Remap amp_char to &, map double amp_char to amp_char (for things
978 // like "&File..." -- this is illegal in XML, so we use "_File..."):
424af7aa 979 if ( *dt == amp_char )
78d14f80
VS
980 {
981 if ( *(++dt) == amp_char )
982 str2 << amp_char;
983 else
984 str2 << wxT('&') << *dt;
985 }
984c33c9 986 // Remap \n to CR, \r to LF, \t to TAB, \\ to \:
424af7aa
VS
987 else if ( *dt == wxT('\\') )
988 {
989 switch ( (*(++dt)).GetValue() )
78d14f80 990 {
984c33c9
VS
991 case wxT('n'):
992 str2 << wxT('\n');
993 break;
e7a3a5a5 994
984c33c9
VS
995 case wxT('t'):
996 str2 << wxT('\t');
997 break;
e7a3a5a5 998
984c33c9
VS
999 case wxT('r'):
1000 str2 << wxT('\r');
1001 break;
1002
1003 case wxT('\\') :
1004 // "\\" wasn't translated to "\" prior to 2.5.3.0:
424af7aa 1005 if ( escapeBackslash )
984c33c9
VS
1006 {
1007 str2 << wxT('\\');
1008 break;
1009 }
1010 // else fall-through to default: branch below
e7a3a5a5 1011
984c33c9
VS
1012 default:
1013 str2 << wxT('\\') << *dt;
1014 break;
78d14f80 1015 }
424af7aa
VS
1016 }
1017 else
1018 {
1019 str2 << *dt;
1020 }
78d14f80 1021 }
b272b6dc 1022
7b56015f
VS
1023 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
1024 {
1025 if (translate && parNode &&
288b6107 1026 parNode->GetAttribute(wxT("translate"), wxEmptyString) != wxT("0"))
7b56015f 1027 {
d4a724d4 1028 return wxGetTranslation(str2, m_resource->GetDomain());
7b56015f
VS
1029 }
1030 else
1031 {
1032#if wxUSE_UNICODE
1033 return str2;
1034#else
1035 // The string is internally stored as UTF-8, we have to convert
1036 // it into system's default encoding so that it can be displayed:
6251e0ea 1037 return wxString(str2.wc_str(wxConvUTF8), wxConvLocal);
7b56015f
VS
1038#endif
1039 }
1040 }
8516a98b
DS
1041
1042 // If wxXRC_USE_LOCALE is not set, then the string is already in
1043 // system's default encoding in ANSI build, so we don't have to
1044 // do anything special here.
1045 return str2;
78d14f80
VS
1046}
1047
1048
1049
1050long wxXmlResourceHandler::GetLong(const wxString& param, long defaultv)
1051{
1052 long value;
1053 wxString str1 = GetParamValue(param);
1054
1055 if (!str1.ToLong(&value))
1056 value = defaultv;
1057
1058 return value;
1059}
e7a3a5a5 1060
1df61962
VS
1061float wxXmlResourceHandler::GetFloat(const wxString& param, float defaultv)
1062{
1d9473d3 1063 wxString str = GetParamValue(param);
1df61962 1064
cfd91598 1065#if wxUSE_INTL
1d9473d3
VZ
1066 // strings in XRC always use C locale but wxString::ToDouble() uses the
1067 // current one, so transform the string to it supposing that the only
1068 // difference between them is the decimal separator
1069 //
1070 // TODO: use wxString::ToCDouble() when we have it
1071 str.Replace(wxT("."), wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT,
1072 wxLOCALE_CAT_NUMBER));
cfd91598 1073#endif // wxUSE_INTL
e7a3a5a5 1074
1d9473d3
VZ
1075 double value;
1076 if (!str.ToDouble(&value))
1df61962
VS
1077 value = defaultv;
1078
17a1ebd1 1079 return wx_truncate_cast(float, value);
1df61962 1080}
78d14f80 1081
af1337b0 1082
78d14f80
VS
1083int wxXmlResourceHandler::GetID()
1084{
13de23f6 1085 return wxXmlResource::GetXRCID(GetName());
78d14f80
VS
1086}
1087
1088
af1337b0 1089
78d14f80
VS
1090wxString wxXmlResourceHandler::GetName()
1091{
288b6107 1092 return m_node->GetAttribute(wxT("name"), wxT("-1"));
78d14f80
VS
1093}
1094
1095
1096
8758875e
VZ
1097bool wxXmlResourceHandler::GetBoolAttr(const wxString& attr, bool defaultv)
1098{
1099 wxString v;
1100 return m_node->GetAttribute(attr, &v) ? v == '1' : defaultv;
1101}
1102
78d14f80
VS
1103bool wxXmlResourceHandler::GetBool(const wxString& param, bool defaultv)
1104{
8758875e 1105 const wxString v = GetParamValue(param);
8516a98b 1106
8758875e 1107 return v.empty() ? defaultv : (v == '1');
78d14f80
VS
1108}
1109
1110
1df61962
VS
1111static wxColour GetSystemColour(const wxString& name)
1112{
1113 if (!name.empty())
1114 {
1115 #define SYSCLR(clr) \
1116 if (name == _T(#clr)) return wxSystemSettings::GetColour(clr);
1117 SYSCLR(wxSYS_COLOUR_SCROLLBAR)
1118 SYSCLR(wxSYS_COLOUR_BACKGROUND)
1119 SYSCLR(wxSYS_COLOUR_DESKTOP)
1120 SYSCLR(wxSYS_COLOUR_ACTIVECAPTION)
1121 SYSCLR(wxSYS_COLOUR_INACTIVECAPTION)
1122 SYSCLR(wxSYS_COLOUR_MENU)
1123 SYSCLR(wxSYS_COLOUR_WINDOW)
1124 SYSCLR(wxSYS_COLOUR_WINDOWFRAME)
1125 SYSCLR(wxSYS_COLOUR_MENUTEXT)
1126 SYSCLR(wxSYS_COLOUR_WINDOWTEXT)
1127 SYSCLR(wxSYS_COLOUR_CAPTIONTEXT)
1128 SYSCLR(wxSYS_COLOUR_ACTIVEBORDER)
1129 SYSCLR(wxSYS_COLOUR_INACTIVEBORDER)
1130 SYSCLR(wxSYS_COLOUR_APPWORKSPACE)
1131 SYSCLR(wxSYS_COLOUR_HIGHLIGHT)
1132 SYSCLR(wxSYS_COLOUR_HIGHLIGHTTEXT)
1133 SYSCLR(wxSYS_COLOUR_BTNFACE)
1134 SYSCLR(wxSYS_COLOUR_3DFACE)
1135 SYSCLR(wxSYS_COLOUR_BTNSHADOW)
1136 SYSCLR(wxSYS_COLOUR_3DSHADOW)
1137 SYSCLR(wxSYS_COLOUR_GRAYTEXT)
1138 SYSCLR(wxSYS_COLOUR_BTNTEXT)
1139 SYSCLR(wxSYS_COLOUR_INACTIVECAPTIONTEXT)
1140 SYSCLR(wxSYS_COLOUR_BTNHIGHLIGHT)
1141 SYSCLR(wxSYS_COLOUR_BTNHILIGHT)
1142 SYSCLR(wxSYS_COLOUR_3DHIGHLIGHT)
1143 SYSCLR(wxSYS_COLOUR_3DHILIGHT)
1144 SYSCLR(wxSYS_COLOUR_3DDKSHADOW)
1145 SYSCLR(wxSYS_COLOUR_3DLIGHT)
1146 SYSCLR(wxSYS_COLOUR_INFOTEXT)
1147 SYSCLR(wxSYS_COLOUR_INFOBK)
1148 SYSCLR(wxSYS_COLOUR_LISTBOX)
1149 SYSCLR(wxSYS_COLOUR_HOTLIGHT)
1150 SYSCLR(wxSYS_COLOUR_GRADIENTACTIVECAPTION)
1151 SYSCLR(wxSYS_COLOUR_GRADIENTINACTIVECAPTION)
1152 SYSCLR(wxSYS_COLOUR_MENUHILIGHT)
1153 SYSCLR(wxSYS_COLOUR_MENUBAR)
1154 #undef SYSCLR
1155 }
1156
1157 return wxNullColour;
1158}
78d14f80 1159
984f1d84 1160wxColour wxXmlResourceHandler::GetColour(const wxString& param, const wxColour& defaultv)
78d14f80
VS
1161{
1162 wxString v = GetParamValue(param);
984f1d84
VS
1163
1164 if ( v.empty() )
1165 return defaultv;
1166
68b4e4cf 1167 wxColour clr;
1df61962 1168
68b4e4cf
WS
1169 // wxString -> wxColour conversion
1170 if (!clr.Set(v))
78d14f80 1171 {
1df61962
VS
1172 // the colour doesn't use #RRGGBB format, check if it is symbolic
1173 // colour name:
68b4e4cf 1174 clr = GetSystemColour(v);
1df61962
VS
1175 if (clr.Ok())
1176 return clr;
e7a3a5a5 1177
288b6107 1178 wxLogError(_("XRC resource: Incorrect colour specification '%s' for attribute '%s'."),
78d14f80
VS
1179 v.c_str(), param.c_str());
1180 return wxNullColour;
1181 }
1182
68b4e4cf 1183 return clr;
78d14f80
VS
1184}
1185
1186
1187
92e898b0 1188wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param,
db59a97c
VS
1189 const wxArtClient& defaultArtClient,
1190 wxSize size)
78d14f80 1191{
db59a97c
VS
1192 /* If the bitmap is specified as stock item, query wxArtProvider for it: */
1193 wxXmlNode *bmpNode = GetParamNode(param);
1194 if ( bmpNode )
af1337b0 1195 {
288b6107 1196 wxString sid = bmpNode->GetAttribute(wxT("stock_id"), wxEmptyString);
db59a97c
VS
1197 if ( !sid.empty() )
1198 {
288b6107 1199 wxString scl = bmpNode->GetAttribute(wxT("stock_client"), wxEmptyString);
b3e85292
VS
1200 if (scl.empty())
1201 scl = defaultArtClient;
1202 else
1203 scl = wxART_MAKE_CLIENT_ID_FROM_STR(scl);
e7a3a5a5 1204
92e898b0 1205 wxBitmap stockArt =
db59a97c 1206 wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(sid),
b3e85292 1207 scl, size);
db59a97c
VS
1208 if ( stockArt.Ok() )
1209 return stockArt;
1210 }
af1337b0
JS
1211 }
1212
92e898b0 1213 /* ...or load the bitmap from file: */
78d14f80 1214 wxString name = GetParamValue(param);
e7a3a5a5 1215 if (name.empty()) return wxNullBitmap;
78d14f80 1216#if wxUSE_FILESYSTEM
4532786e 1217 wxFSFile *fsfile = GetCurFileSystem().OpenFile(name, wxFS_READ | wxFS_SEEKABLE);
78d14f80
VS
1218 if (fsfile == NULL)
1219 {
d0b50ad9
VS
1220 wxLogError(_("XRC resource: Cannot create bitmap from '%s'."),
1221 name.c_str());
78d14f80
VS
1222 return wxNullBitmap;
1223 }
1224 wxImage img(*(fsfile->GetStream()));
1225 delete fsfile;
1226#else
45f3249b 1227 wxImage img(name);
78d14f80 1228#endif
af1337b0 1229
78d14f80
VS
1230 if (!img.Ok())
1231 {
1df61962 1232 wxLogError(_("XRC resource: Cannot create bitmap from '%s'."),
45f3249b 1233 name.c_str());
78d14f80
VS
1234 return wxNullBitmap;
1235 }
1236 if (!(size == wxDefaultSize)) img.Rescale(size.x, size.y);
b272b6dc 1237 return wxBitmap(img);
78d14f80
VS
1238}
1239
78d14f80 1240
92e898b0 1241wxIcon wxXmlResourceHandler::GetIcon(const wxString& param,
db59a97c
VS
1242 const wxArtClient& defaultArtClient,
1243 wxSize size)
78d14f80 1244{
78d14f80 1245 wxIcon icon;
db59a97c 1246 icon.CopyFromBitmap(GetBitmap(param, defaultArtClient, size));
78d14f80
VS
1247 return icon;
1248}
1249
1250
1251
1252wxXmlNode *wxXmlResourceHandler::GetParamNode(const wxString& param)
1253{
2b5f62a0
VZ
1254 wxCHECK_MSG(m_node, NULL, wxT("You can't access handler data before it was initialized!"));
1255
78d14f80
VS
1256 wxXmlNode *n = m_node->GetChildren();
1257
1258 while (n)
1259 {
1260 if (n->GetType() == wxXML_ELEMENT_NODE && n->GetName() == param)
cffff062
VZ
1261 {
1262 // TODO: check that there are no other properties/parameters with
1263 // the same name and log an error if there are (can't do this
1264 // right now as I'm not sure if it's not going to break code
1265 // using this function in unintentional way (i.e. for
1266 // accessing other things than properties), for example
1267 // wxBitmapComboBoxXmlHandler almost surely does
78d14f80 1268 return n;
cffff062 1269 }
78d14f80
VS
1270 n = n->GetNext();
1271 }
1272 return NULL;
1273}
1274
2d672c46
MW
1275bool wxXmlResourceHandler::IsOfClass(wxXmlNode *node, const wxString& classname)
1276{
288b6107 1277 return node->GetAttribute(wxT("class"), wxEmptyString) == classname;
2d672c46
MW
1278}
1279
1280
1281
78d14f80
VS
1282wxString wxXmlResourceHandler::GetNodeContent(wxXmlNode *node)
1283{
1284 wxXmlNode *n = node;
1285 if (n == NULL) return wxEmptyString;
1286 n = n->GetChildren();
1287
1288 while (n)
1289 {
1290 if (n->GetType() == wxXML_TEXT_NODE ||
1291 n->GetType() == wxXML_CDATA_SECTION_NODE)
1292 return n->GetContent();
1293 n = n->GetNext();
1294 }
1295 return wxEmptyString;
1296}
1297
1298
1299
1300wxString wxXmlResourceHandler::GetParamValue(const wxString& param)
1301{
e7a3a5a5 1302 if (param.empty())
78d14f80
VS
1303 return GetNodeContent(m_node);
1304 else
1305 return GetNodeContent(GetParamNode(param));
1306}
1307
1308
1309
0c00c86f
VS
1310wxSize wxXmlResourceHandler::GetSize(const wxString& param,
1311 wxWindow *windowToUse)
78d14f80
VS
1312{
1313 wxString s = GetParamValue(param);
e7a3a5a5 1314 if (s.empty()) s = wxT("-1,-1");
78d14f80 1315 bool is_dlg;
d1f47235 1316 long sx, sy = 0;
78d14f80 1317
88a7a4e1 1318 is_dlg = s[s.length()-1] == wxT('d');
78d14f80
VS
1319 if (is_dlg) s.RemoveLast();
1320
1321 if (!s.BeforeFirst(wxT(',')).ToLong(&sx) ||
1322 !s.AfterLast(wxT(',')).ToLong(&sy))
1323 {
00393283 1324 wxLogError(_("Cannot parse coordinates from '%s'."), s.c_str());
78d14f80
VS
1325 return wxDefaultSize;
1326 }
1327
1328 if (is_dlg)
1329 {
0c00c86f
VS
1330 if (windowToUse)
1331 {
1332 return wxDLG_UNIT(windowToUse, wxSize(sx, sy));
1333 }
1334 else if (m_parentAsWindow)
1335 {
78d14f80 1336 return wxDLG_UNIT(m_parentAsWindow, wxSize(sx, sy));
0c00c86f 1337 }
78d14f80
VS
1338 else
1339 {
1340 wxLogError(_("Cannot convert dialog units: dialog unknown."));
1341 return wxDefaultSize;
1342 }
1343 }
8516a98b
DS
1344
1345 return wxSize(sx, sy);
78d14f80
VS
1346}
1347
1348
1349
1350wxPoint wxXmlResourceHandler::GetPosition(const wxString& param)
1351{
1352 wxSize sz = GetSize(param);
1353 return wxPoint(sz.x, sz.y);
1354}
1355
1356
1357
0c00c86f
VS
1358wxCoord wxXmlResourceHandler::GetDimension(const wxString& param,
1359 wxCoord defaultv,
1360 wxWindow *windowToUse)
78d14f80
VS
1361{
1362 wxString s = GetParamValue(param);
e7a3a5a5 1363 if (s.empty()) return defaultv;
78d14f80
VS
1364 bool is_dlg;
1365 long sx;
1366
88a7a4e1 1367 is_dlg = s[s.length()-1] == wxT('d');
78d14f80
VS
1368 if (is_dlg) s.RemoveLast();
1369
1370 if (!s.ToLong(&sx))
1371 {
00393283 1372 wxLogError(_("Cannot parse dimension from '%s'."), s.c_str());
78d14f80
VS
1373 return defaultv;
1374 }
1375
1376 if (is_dlg)
1377 {
0c00c86f
VS
1378 if (windowToUse)
1379 {
1380 return wxDLG_UNIT(windowToUse, wxSize(sx, 0)).x;
1381 }
1382 else if (m_parentAsWindow)
1383 {
78d14f80 1384 return wxDLG_UNIT(m_parentAsWindow, wxSize(sx, 0)).x;
0c00c86f 1385 }
78d14f80
VS
1386 else
1387 {
1388 wxLogError(_("Cannot convert dialog units: dialog unknown."));
1389 return defaultv;
1390 }
1391 }
8516a98b
DS
1392
1393 return sx;
78d14f80
VS
1394}
1395
1396
1df61962
VS
1397// Get system font index using indexname
1398static wxFont GetSystemFont(const wxString& name)
1399{
1400 if (!name.empty())
1401 {
1402 #define SYSFNT(fnt) \
1403 if (name == _T(#fnt)) return wxSystemSettings::GetFont(fnt);
1404 SYSFNT(wxSYS_OEM_FIXED_FONT)
1405 SYSFNT(wxSYS_ANSI_FIXED_FONT)
1406 SYSFNT(wxSYS_ANSI_VAR_FONT)
1407 SYSFNT(wxSYS_SYSTEM_FONT)
1408 SYSFNT(wxSYS_DEVICE_DEFAULT_FONT)
1df61962
VS
1409 SYSFNT(wxSYS_SYSTEM_FIXED_FONT)
1410 SYSFNT(wxSYS_DEFAULT_GUI_FONT)
1411 #undef SYSFNT
1412 }
1413
1414 return wxNullFont;
1415}
78d14f80
VS
1416
1417wxFont wxXmlResourceHandler::GetFont(const wxString& param)
1418{
1419 wxXmlNode *font_node = GetParamNode(param);
1420 if (font_node == NULL)
1421 {
00393283 1422 wxLogError(_("Cannot find font node '%s'."), param.c_str());
78d14f80
VS
1423 return wxNullFont;
1424 }
1425
1426 wxXmlNode *oldnode = m_node;
1427 m_node = font_node;
1428
1df61962 1429 // font attributes:
78d14f80 1430
1df61962 1431 // size
94245f6d 1432 int isize = -1;
1df61962 1433 bool hasSize = HasParam(wxT("size"));
e7a3a5a5 1434 if (hasSize)
94245f6d 1435 isize = GetLong(wxT("size"), -1);
78d14f80 1436
1df61962
VS
1437 // style
1438 int istyle = wxNORMAL;
1439 bool hasStyle = HasParam(wxT("style"));
1440 if (hasStyle)
1441 {
1442 wxString style = GetParamValue(wxT("style"));
e7a3a5a5 1443 if (style == wxT("italic"))
1df61962 1444 istyle = wxITALIC;
e7a3a5a5 1445 else if (style == wxT("slant"))
1df61962
VS
1446 istyle = wxSLANT;
1447 }
78d14f80 1448
1df61962
VS
1449 // weight
1450 int iweight = wxNORMAL;
1451 bool hasWeight = HasParam(wxT("weight"));
1452 if (hasWeight)
1453 {
1454 wxString weight = GetParamValue(wxT("weight"));
e7a3a5a5 1455 if (weight == wxT("bold"))
1df61962 1456 iweight = wxBOLD;
e7a3a5a5 1457 else if (weight == wxT("light"))
1df61962
VS
1458 iweight = wxLIGHT;
1459 }
e7a3a5a5 1460
1df61962
VS
1461 // underline
1462 bool hasUnderlined = HasParam(wxT("underlined"));
1463 bool underlined = hasUnderlined ? GetBool(wxT("underlined"), false) : false;
78d14f80 1464
1df61962
VS
1465 // family and facename
1466 int ifamily = wxDEFAULT;
1467 bool hasFamily = HasParam(wxT("family"));
1468 if (hasFamily)
78d14f80 1469 {
1df61962
VS
1470 wxString family = GetParamValue(wxT("family"));
1471 if (family == wxT("decorative")) ifamily = wxDECORATIVE;
1472 else if (family == wxT("roman")) ifamily = wxROMAN;
1473 else if (family == wxT("script")) ifamily = wxSCRIPT;
1474 else if (family == wxT("swiss")) ifamily = wxSWISS;
1475 else if (family == wxT("modern")) ifamily = wxMODERN;
1476 else if (family == wxT("teletype")) ifamily = wxTELETYPE;
1477 }
e7a3a5a5
WS
1478
1479
1df61962
VS
1480 wxString facename;
1481 bool hasFacename = HasParam(wxT("face"));
1482 if (hasFacename)
1483 {
1484 wxString faces = GetParamValue(wxT("face"));
1df61962 1485 wxStringTokenizer tk(faces, wxT(","));
63feebce
VS
1486#if wxUSE_FONTENUM
1487 wxArrayString facenames(wxFontEnumerator::GetFacenames());
1df61962 1488 while (tk.HasMoreTokens())
78d14f80 1489 {
6540132f 1490 int index = facenames.Index(tk.GetNextToken(), false);
1df61962
VS
1491 if (index != wxNOT_FOUND)
1492 {
6540132f 1493 facename = facenames[index];
1df61962
VS
1494 break;
1495 }
78d14f80 1496 }
63feebce
VS
1497#else // !wxUSE_FONTENUM
1498 // just use the first face name if we can't check its availability:
1499 if (tk.HasMoreTokens())
1500 facename = tk.GetNextToken();
1501#endif // wxUSE_FONTENUM/!wxUSE_FONTENUM
78d14f80
VS
1502 }
1503
1df61962
VS
1504 // encoding
1505 wxFontEncoding enc = wxFONTENCODING_DEFAULT;
1506 bool hasEncoding = HasParam(wxT("encoding"));
1507 if (hasEncoding)
1508 {
1509 wxString encoding = GetParamValue(wxT("encoding"));
1510 wxFontMapper mapper;
e7a3a5a5 1511 if (!encoding.empty())
1df61962
VS
1512 enc = mapper.CharsetToEncoding(encoding);
1513 if (enc == wxFONTENCODING_SYSTEM)
1514 enc = wxFONTENCODING_DEFAULT;
1515 }
78d14f80 1516
1df61962 1517 // is this font based on a system font?
94245f6d 1518 wxFont font = GetSystemFont(GetParamValue(wxT("sysfont")));
e7a3a5a5 1519
94245f6d 1520 if (font.Ok())
1df61962 1521 {
94245f6d
VZ
1522 if (hasSize && isize != -1)
1523 font.SetPointSize(isize);
1df61962 1524 else if (HasParam(wxT("relativesize")))
94245f6d 1525 font.SetPointSize(int(font.GetPointSize() *
1df61962 1526 GetFloat(wxT("relativesize"))));
e7a3a5a5 1527
1df61962 1528 if (hasStyle)
94245f6d 1529 font.SetStyle(istyle);
1df61962 1530 if (hasWeight)
94245f6d 1531 font.SetWeight(iweight);
1df61962 1532 if (hasUnderlined)
94245f6d 1533 font.SetUnderlined(underlined);
1df61962 1534 if (hasFamily)
94245f6d 1535 font.SetFamily(ifamily);
1df61962 1536 if (hasFacename)
94245f6d 1537 font.SetFaceName(facename);
1df61962 1538 if (hasEncoding)
94245f6d
VZ
1539 font.SetDefaultEncoding(enc);
1540 }
1541 else // not based on system font
1542 {
1543 font = wxFont(isize == -1 ? wxNORMAL_FONT->GetPointSize() : isize,
1544 ifamily, istyle, iweight,
1545 underlined, facename, enc);
1df61962 1546 }
8516a98b
DS
1547
1548 m_node = oldnode;
94245f6d 1549 return font;
78d14f80
VS
1550}
1551
1552
1553void wxXmlResourceHandler::SetupWindow(wxWindow *wnd)
1554{
1555 //FIXME : add cursor
1556
1557 if (HasParam(wxT("exstyle")))
0099f343
JS
1558 // Have to OR it with existing style, since
1559 // some implementations (e.g. wxGTK) use the extra style
1560 // during creation
1561 wnd->SetExtraStyle(wnd->GetExtraStyle() | GetStyle(wxT("exstyle")));
78d14f80
VS
1562 if (HasParam(wxT("bg")))
1563 wnd->SetBackgroundColour(GetColour(wxT("bg")));
1564 if (HasParam(wxT("fg")))
1565 wnd->SetForegroundColour(GetColour(wxT("fg")));
1566 if (GetBool(wxT("enabled"), 1) == 0)
f80ea77b 1567 wnd->Enable(false);
78d14f80
VS
1568 if (GetBool(wxT("focused"), 0) == 1)
1569 wnd->SetFocus();
1570 if (GetBool(wxT("hidden"), 0) == 1)
f80ea77b 1571 wnd->Show(false);
78d14f80
VS
1572#if wxUSE_TOOLTIPS
1573 if (HasParam(wxT("tooltip")))
1574 wnd->SetToolTip(GetText(wxT("tooltip")));
1575#endif
1576 if (HasParam(wxT("font")))
1577 wnd->SetFont(GetFont());
b23030d6
JS
1578 if (HasParam(wxT("help")))
1579 wnd->SetHelpText(GetText(wxT("help")));
78d14f80
VS
1580}
1581
1582
1583void wxXmlResourceHandler::CreateChildren(wxObject *parent, bool this_hnd_only)
1584{
23239d94 1585 for ( wxXmlNode *n = m_node->GetChildren(); n; n = n->GetNext() )
78d14f80 1586 {
23239d94 1587 if ( IsObjectNode(n) )
78d14f80 1588 {
317a0d73
VS
1589 m_resource->CreateResFromNode(n, parent, NULL,
1590 this_hnd_only ? this : NULL);
78d14f80 1591 }
78d14f80
VS
1592 }
1593}
1594
1595
1596void wxXmlResourceHandler::CreateChildrenPrivately(wxObject *parent, wxXmlNode *rootnode)
1597{
1598 wxXmlNode *root;
1599 if (rootnode == NULL) root = m_node; else root = rootnode;
1600 wxXmlNode *n = root->GetChildren();
1601
1602 while (n)
1603 {
1604 if (n->GetType() == wxXML_ELEMENT_NODE && CanHandle(n))
1605 {
1606 CreateResource(n, parent, NULL);
1607 }
1608 n = n->GetNext();
1609 }
1610}
1611
1612
1613
1614
1615
1616
1617
5ed345b7 1618// --------------- XRCID implementation -----------------------------
78d14f80 1619
5ed345b7 1620#define XRCID_TABLE_SIZE 1024
78d14f80
VS
1621
1622
5ed345b7 1623struct XRCID_record
78d14f80 1624{
cf2810aa
VZ
1625 /* Hold the id so that once an id is allocated for a name, it
1626 does not get created again by NewControlId at least
1627 until we are done with it */
1628 wxWindowIDRef id;
c560da98 1629 char *key;
5ed345b7 1630 XRCID_record *next;
78d14f80
VS
1631};
1632
5ed345b7 1633static XRCID_record *XRCID_Records[XRCID_TABLE_SIZE] = {NULL};
78d14f80 1634
c560da98 1635static int XRCID_Lookup(const char *str_id, int value_if_not_found = wxID_NONE)
78d14f80 1636{
78d14f80
VS
1637 int index = 0;
1638
c560da98 1639 for (const char *c = str_id; *c != '\0'; c++) index += (int)*c;
5ed345b7 1640 index %= XRCID_TABLE_SIZE;
78d14f80 1641
5ed345b7 1642 XRCID_record *oldrec = NULL;
5ed345b7 1643 for (XRCID_record *rec = XRCID_Records[index]; rec; rec = rec->next)
78d14f80 1644 {
00393283 1645 if (wxStrcmp(rec->key, str_id) == 0)
78d14f80
VS
1646 {
1647 return rec->id;
1648 }
78d14f80
VS
1649 oldrec = rec;
1650 }
1651
5ed345b7
VS
1652 XRCID_record **rec_var = (oldrec == NULL) ?
1653 &XRCID_Records[index] : &oldrec->next;
1654 *rec_var = new XRCID_record;
00393283 1655 (*rec_var)->key = wxStrdup(str_id);
78d14f80
VS
1656 (*rec_var)->next = NULL;
1657
c560da98 1658 char *end;
9b2a7469 1659 if (value_if_not_found != wxID_NONE)
13de23f6 1660 (*rec_var)->id = value_if_not_found;
85452d74
VS
1661 else
1662 {
13de23f6
VS
1663 int asint = wxStrtol(str_id, &end, 10);
1664 if (*str_id && *end == 0)
1665 {
1666 // if str_id was integer, keep it verbosely:
1667 (*rec_var)->id = asint;
1668 }
1669 else
1670 {
f35fdf7e 1671 (*rec_var)->id = wxWindowBase::NewControlId();
13de23f6 1672 }
85452d74
VS
1673 }
1674
78d14f80
VS
1675 return (*rec_var)->id;
1676}
1677
3b2a000e
VS
1678static void AddStdXRCID_Records();
1679
9b2a7469 1680/*static*/
c560da98 1681int wxXmlResource::DoGetXRCID(const char *str_id, int value_if_not_found)
13de23f6 1682{
3b2a000e
VS
1683 static bool s_stdIDsAdded = false;
1684
1685 if ( !s_stdIDsAdded )
1686 {
1687 s_stdIDsAdded = true;
1688 AddStdXRCID_Records();
1689 }
1690
9b2a7469 1691 return XRCID_Lookup(str_id, value_if_not_found);
13de23f6
VS
1692}
1693
cc378c2d
VZ
1694/* static */
1695wxString wxXmlResource::FindXRCIDById(int numId)
1696{
1697 for ( int i = 0; i < XRCID_TABLE_SIZE; i++ )
1698 {
1699 for ( XRCID_record *rec = XRCID_Records[i]; rec; rec = rec->next )
1700 {
1701 if ( rec->id == numId )
1702 return wxString(rec->key);
1703 }
1704 }
1705
1706 return wxString();
1707}
78d14f80 1708
5ed345b7 1709static void CleanXRCID_Record(XRCID_record *rec)
78d14f80
VS
1710{
1711 if (rec)
1712 {
5ed345b7 1713 CleanXRCID_Record(rec->next);
f35fdf7e 1714
00393283 1715 free(rec->key);
78d14f80
VS
1716 delete rec;
1717 }
1718}
1719
5ed345b7 1720static void CleanXRCID_Records()
78d14f80 1721{
5ed345b7 1722 for (int i = 0; i < XRCID_TABLE_SIZE; i++)
139c5871 1723 {
5ed345b7 1724 CleanXRCID_Record(XRCID_Records[i]);
139c5871
VS
1725 XRCID_Records[i] = NULL;
1726 }
78d14f80
VS
1727}
1728
13de23f6
VS
1729static void AddStdXRCID_Records()
1730{
c560da98 1731#define stdID(id) XRCID_Lookup(#id, id)
13de23f6 1732 stdID(-1);
c369d4f1
VS
1733
1734 stdID(wxID_ANY);
1735 stdID(wxID_SEPARATOR);
e7a3a5a5 1736
c369d4f1
VS
1737 stdID(wxID_OPEN);
1738 stdID(wxID_CLOSE);
1739 stdID(wxID_NEW);
1740 stdID(wxID_SAVE);
1741 stdID(wxID_SAVEAS);
1742 stdID(wxID_REVERT);
1743 stdID(wxID_EXIT);
1744 stdID(wxID_UNDO);
1745 stdID(wxID_REDO);
1746 stdID(wxID_HELP);
1747 stdID(wxID_PRINT);
1748 stdID(wxID_PRINT_SETUP);
e63f19ba 1749 stdID(wxID_PAGE_SETUP);
c369d4f1
VS
1750 stdID(wxID_PREVIEW);
1751 stdID(wxID_ABOUT);
1752 stdID(wxID_HELP_CONTENTS);
1753 stdID(wxID_HELP_COMMANDS);
1754 stdID(wxID_HELP_PROCEDURES);
1755 stdID(wxID_HELP_CONTEXT);
13de23f6 1756 stdID(wxID_CLOSE_ALL);
c369d4f1 1757 stdID(wxID_PREFERENCES);
d73195fd 1758 stdID(wxID_EDIT);
c369d4f1
VS
1759 stdID(wxID_CUT);
1760 stdID(wxID_COPY);
1761 stdID(wxID_PASTE);
1762 stdID(wxID_CLEAR);
1763 stdID(wxID_FIND);
1764 stdID(wxID_DUPLICATE);
1765 stdID(wxID_SELECTALL);
1766 stdID(wxID_DELETE);
1767 stdID(wxID_REPLACE);
1768 stdID(wxID_REPLACE_ALL);
1769 stdID(wxID_PROPERTIES);
1770 stdID(wxID_VIEW_DETAILS);
1771 stdID(wxID_VIEW_LARGEICONS);
1772 stdID(wxID_VIEW_SMALLICONS);
1773 stdID(wxID_VIEW_LIST);
1774 stdID(wxID_VIEW_SORTDATE);
1775 stdID(wxID_VIEW_SORTNAME);
1776 stdID(wxID_VIEW_SORTSIZE);
1777 stdID(wxID_VIEW_SORTTYPE);
1778 stdID(wxID_FILE1);
1779 stdID(wxID_FILE2);
1780 stdID(wxID_FILE3);
1781 stdID(wxID_FILE4);
1782 stdID(wxID_FILE5);
1783 stdID(wxID_FILE6);
1784 stdID(wxID_FILE7);
1785 stdID(wxID_FILE8);
1786 stdID(wxID_FILE9);
1787 stdID(wxID_OK);
1788 stdID(wxID_CANCEL);
1789 stdID(wxID_APPLY);
1790 stdID(wxID_YES);
1791 stdID(wxID_NO);
1792 stdID(wxID_STATIC);
1793 stdID(wxID_FORWARD);
1794 stdID(wxID_BACKWARD);
1795 stdID(wxID_DEFAULT);
1796 stdID(wxID_MORE);
1797 stdID(wxID_SETUP);
1798 stdID(wxID_RESET);
1799 stdID(wxID_CONTEXT_HELP);
1800 stdID(wxID_YESTOALL);
1801 stdID(wxID_NOTOALL);
1802 stdID(wxID_ABORT);
1803 stdID(wxID_RETRY);
1804 stdID(wxID_IGNORE);
1805 stdID(wxID_ADD);
1806 stdID(wxID_REMOVE);
1807 stdID(wxID_UP);
1808 stdID(wxID_DOWN);
1809 stdID(wxID_HOME);
1810 stdID(wxID_REFRESH);
1811 stdID(wxID_STOP);
1812 stdID(wxID_INDEX);
1813 stdID(wxID_BOLD);
1814 stdID(wxID_ITALIC);
1815 stdID(wxID_JUSTIFY_CENTER);
1816 stdID(wxID_JUSTIFY_FILL);
1817 stdID(wxID_JUSTIFY_RIGHT);
1818 stdID(wxID_JUSTIFY_LEFT);
1819 stdID(wxID_UNDERLINE);
1820 stdID(wxID_INDENT);
1821 stdID(wxID_UNINDENT);
1822 stdID(wxID_ZOOM_100);
1823 stdID(wxID_ZOOM_FIT);
1824 stdID(wxID_ZOOM_IN);
1825 stdID(wxID_ZOOM_OUT);
1826 stdID(wxID_UNDELETE);
1827 stdID(wxID_REVERT_TO_SAVED);
1828 stdID(wxID_SYSTEM_MENU);
1829 stdID(wxID_CLOSE_FRAME);
1830 stdID(wxID_MOVE_FRAME);
1831 stdID(wxID_RESIZE_FRAME);
1832 stdID(wxID_MAXIMIZE_FRAME);
1833 stdID(wxID_ICONIZE_FRAME);
1834 stdID(wxID_RESTORE_FRAME);
6b1eedc1
VZ
1835 stdID(wxID_CDROM);
1836 stdID(wxID_CONVERT);
1837 stdID(wxID_EXECUTE);
1838 stdID(wxID_FLOPPY);
1839 stdID(wxID_HARDDISK);
1840 stdID(wxID_BOTTOM);
1841 stdID(wxID_FIRST);
1842 stdID(wxID_LAST);
1843 stdID(wxID_TOP);
1844 stdID(wxID_INFO);
1845 stdID(wxID_JUMP_TO);
1846 stdID(wxID_NETWORK);
1847 stdID(wxID_SELECT_COLOR);
1848 stdID(wxID_SELECT_FONT);
1849 stdID(wxID_SORT_ASCENDING);
1850 stdID(wxID_SORT_DESCENDING);
1851 stdID(wxID_SPELL_CHECK);
1852 stdID(wxID_STRIKETHROUGH);
c369d4f1 1853
13de23f6
VS
1854#undef stdID
1855}
78d14f80
VS
1856
1857
1858
1859
1860
1861// --------------- module and globals -----------------------------
1862
fd230129
VZ
1863// normally we would do the cleanup from wxXmlResourceModule::OnExit() but it
1864// can happen that some XRC records have been created because of the use of
1865// XRCID() in event tables, which happens during static objects initialization,
1866// but then the application initialization failed and so the wx modules were
1867// neither initialized nor cleaned up -- this static object does the cleanup in
1868// this case
1869static struct wxXRCStaticCleanup
1870{
1871 ~wxXRCStaticCleanup() { CleanXRCID_Records(); }
1872} s_staticCleanup;
1873
78d14f80
VS
1874class wxXmlResourceModule: public wxModule
1875{
1876DECLARE_DYNAMIC_CLASS(wxXmlResourceModule)
1877public:
1878 wxXmlResourceModule() {}
824e8eaa
VS
1879 bool OnInit()
1880 {
2b5f62a0 1881 wxXmlResource::AddSubclassFactory(new wxXmlSubclassFactoryCXX);
f80ea77b 1882 return true;
824e8eaa 1883 }
78d14f80
VS
1884 void OnExit()
1885 {
1542c42e 1886 delete wxXmlResource::Set(NULL);
461932ae 1887 if(wxXmlResource::ms_subclassFactories)
eb2d0d23
VS
1888 {
1889 for ( wxXmlSubclassFactories::iterator i = wxXmlResource::ms_subclassFactories->begin();
1890 i != wxXmlResource::ms_subclassFactories->end(); ++i )
1891 {
1892 delete *i;
1893 }
1894 wxDELETE(wxXmlResource::ms_subclassFactories);
1895 }
5ed345b7 1896 CleanXRCID_Records();
78d14f80
VS
1897 }
1898};
1899
1900IMPLEMENT_DYNAMIC_CLASS(wxXmlResourceModule, wxModule)
1901
1902
1903// When wxXml is loaded dynamically after the application is already running
1904// then the built-in module system won't pick this one up. Add it manually.
1905void wxXmlInitResourceModule()
1906{
1907 wxModule* module = new wxXmlResourceModule;
1908 module->Init();
1909 wxModule::RegisterModule(module);
1910}
a1e4ec87
VS
1911
1912#endif // wxUSE_XRC