]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xmlres.cpp
This should work on SuSE and Mandrake icon themes.
[wxWidgets.git] / 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);
85 bool rt = TRUE;
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());
263 return FALSE;
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 {
277 isok = FALSE;
278 if (!c->GetPropVal(wxT("platform"), &s))
279 isok = TRUE;
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
346 if (!modif)
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 {
480505bc 365 wxInputStream *stream = NULL;
78d14f80
VS
366
367# if wxUSE_FILESYSTEM
368 file = fsys.OpenFile(m_data[i].File);
369 if (file)
370 stream = file->GetStream();
371# else
372 stream = new wxFileInputStream(m_data[i].File);
373# endif
374
375 if (stream)
376 {
377 delete m_data[i].Doc;
378 m_data[i].Doc = new wxXmlDocument;
379 }
4d876ee3 380 if (!stream || !m_data[i].Doc->Load(*stream, encoding))
78d14f80 381 {
480505bc
VS
382 wxLogError(_("Cannot load resources from file '%s'."),
383 m_data[i].File.c_str());
78d14f80 384 wxDELETE(m_data[i].Doc);
d614f51b 385 rt = false;
78d14f80
VS
386 }
387 else if (m_data[i].Doc->GetRoot()->GetName() != wxT("resource"))
388 {
b5d6954b 389 wxLogError(_("Invalid XRC resource '%s': doesn't have root node 'resource'."), m_data[i].File.c_str());
78d14f80 390 wxDELETE(m_data[i].Doc);
d614f51b 391 rt = false;
78d14f80
VS
392 }
393 else
394 {
395 long version;
396 int v1, v2, v3, v4;
397 wxString verstr = m_data[i].Doc->GetRoot()->GetPropVal(
398 wxT("version"), wxT("0.0.0.0"));
399 if (wxSscanf(verstr.c_str(), wxT("%i.%i.%i.%i"),
400 &v1, &v2, &v3, &v4) == 4)
401 version = v1*256*256*256+v2*256*256+v3*256+v4;
402 else
403 version = 0;
404 if (m_version == -1)
405 m_version = version;
406 if (m_version != version)
d614f51b 407 {
78d14f80 408 wxLogError(_("Resource files must have same version number!"));
d614f51b
VS
409 rt = false;
410 }
78d14f80
VS
411
412 ProcessPlatformProperty(m_data[i].Doc->GetRoot());
413 m_data[i].Time = file->GetModificationTime();
414 }
415
416# if wxUSE_FILESYSTEM
417 wxDELETE(file);
19d0f58d 418 wxUnusedVar(file);
78d14f80
VS
419# else
420 wxDELETE(stream);
421# endif
422 }
423 }
d614f51b
VS
424
425 return rt;
78d14f80
VS
426}
427
428
b272b6dc
RD
429wxXmlNode *wxXmlResource::DoFindResource(wxXmlNode *parent,
430 const wxString& name,
431 const wxString& classname,
47793ab8
VS
432 bool recursive)
433{
434 wxString dummy;
435 wxXmlNode *node;
436
437 // first search for match at the top-level nodes (as this is
438 // where the resource is most commonly looked for):
439 for (node = parent->GetChildren(); node; node = node->GetNext())
440 {
b272b6dc
RD
441 if ( node->GetType() == wxXML_ELEMENT_NODE &&
442 (node->GetName() == wxT("object") ||
47793ab8 443 node->GetName() == wxT("object_ref")) &&
2b5f62a0
VZ
444 node->GetPropVal(wxT("name"), &dummy) && dummy == name )
445 {
446 wxString cls(node->GetPropVal(wxT("class"), wxEmptyString));
447 if (!classname || cls == classname)
448 return node;
449 // object_ref may not have 'class' property:
450 if (cls.empty() && node->GetName() == wxT("object_ref"))
451 {
452 wxString refName = node->GetPropVal(wxT("ref"), wxEmptyString);
453 if (refName.empty())
454 continue;
455 wxXmlNode* refNode = FindResource(refName, wxEmptyString, TRUE);
456 if (refNode &&
457 refNode->GetPropVal(wxT("class"), wxEmptyString) == classname)
458 {
459 return node;
460 }
461 }
462 }
47793ab8
VS
463 }
464
465 if ( recursive )
466 for (node = parent->GetChildren(); node; node = node->GetNext())
467 {
b272b6dc
RD
468 if ( node->GetType() == wxXML_ELEMENT_NODE &&
469 (node->GetName() == wxT("object") ||
47793ab8
VS
470 node->GetName() == wxT("object_ref")) )
471 {
472 wxXmlNode* found = DoFindResource(node, name, classname, TRUE);
473 if ( found )
474 return found;
475 }
476 }
477
478 return NULL;
479}
78d14f80 480
b272b6dc 481wxXmlNode *wxXmlResource::FindResource(const wxString& name,
47793ab8
VS
482 const wxString& classname,
483 bool recursive)
78d14f80
VS
484{
485 UpdateResources(); //ensure everything is up-to-date
486
487 wxString dummy;
488 for (size_t f = 0; f < m_data.GetCount(); f++)
489 {
47793ab8
VS
490 if ( m_data[f].Doc == NULL || m_data[f].Doc->GetRoot() == NULL )
491 continue;
492
b272b6dc 493 wxXmlNode* found = DoFindResource(m_data[f].Doc->GetRoot(),
47793ab8
VS
494 name, classname, recursive);
495 if ( found )
496 {
78d14f80 497#if wxUSE_FILESYSTEM
47793ab8 498 m_curFileSystem.ChangePathTo(m_data[f].File);
78d14f80 499#endif
47793ab8
VS
500 return found;
501 }
78d14f80
VS
502 }
503
b5d6954b 504 wxLogError(_("XRC resource '%s' (class '%s') not found!"),
78d14f80
VS
505 name.c_str(), classname.c_str());
506 return NULL;
507}
508
47793ab8
VS
509static void MergeNodes(wxXmlNode& dest, wxXmlNode& with)
510{
511 // Merge properties:
512 for (wxXmlProperty *prop = with.GetProperties(); prop; prop = prop->GetNext())
513 {
514 wxXmlProperty *dprop;
515 for (dprop = dest.GetProperties(); dprop; dprop = dprop->GetNext())
516 {
b272b6dc 517
47793ab8
VS
518 if ( dprop->GetName() == prop->GetName() )
519 {
520 dprop->SetValue(prop->GetValue());
521 break;
522 }
523 }
78d14f80 524
47793ab8
VS
525 if ( !dprop )
526 dest.AddProperty(prop->GetName(), prop->GetValue());
527 }
528
529 // Merge child nodes:
530 for (wxXmlNode* node = with.GetChildren(); node; node = node->GetNext())
531 {
532 wxString name = node->GetPropVal(wxT("name"), wxEmptyString);
533 wxXmlNode *dnode;
534
535 for (dnode = dest.GetChildren(); dnode; dnode = dnode->GetNext() )
536 {
537 if ( dnode->GetName() == node->GetName() &&
2b5f62a0 538 dnode->GetPropVal(wxT("name"), wxEmptyString) == name &&
47793ab8
VS
539 dnode->GetType() == node->GetType() )
540 {
541 MergeNodes(*dnode, *node);
542 break;
543 }
544 }
545
546 if ( !dnode )
547 dest.AddChild(new wxXmlNode(*node));
548 }
549
550 if ( dest.GetType() == wxXML_TEXT_NODE && with.GetContent().Length() )
551 dest.SetContent(with.GetContent());
552}
78d14f80 553
317a0d73
VS
554wxObject *wxXmlResource::CreateResFromNode(wxXmlNode *node, wxObject *parent,
555 wxObject *instance,
556 wxXmlResourceHandler *handlerToUse)
78d14f80
VS
557{
558 if (node == NULL) return NULL;
559
47793ab8
VS
560 // handling of referenced resource
561 if ( node->GetName() == wxT("object_ref") )
562 {
563 wxString refName = node->GetPropVal(wxT("ref"), wxEmptyString);
564 wxXmlNode* refNode = FindResource(refName, wxEmptyString, TRUE);
565
566 if ( !refNode )
567 {
b272b6dc 568 wxLogError(_("Referenced object node with ref=\"%s\" not found!"),
47793ab8
VS
569 refName.c_str());
570 return NULL;
571 }
572
573 wxXmlNode copy(*refNode);
574 MergeNodes(copy, *node);
575
576 return CreateResFromNode(&copy, parent, instance);
577 }
578
78d14f80 579 wxXmlResourceHandler *handler;
317a0d73
VS
580
581 if (handlerToUse)
b380439d 582 {
317a0d73 583 if (handlerToUse->CanHandle(node))
78d14f80 584 {
317a0d73
VS
585 return handlerToUse->CreateResource(node, parent, instance);
586 }
587 }
588 else if (node->GetName() == wxT("object"))
b380439d 589 {
461932ae 590 wxList::compatibility_iterator ND = m_handlers.GetFirst();
317a0d73
VS
591 while (ND)
592 {
593 handler = (wxXmlResourceHandler*)ND->GetData();
594 if (handler->CanHandle(node))
595 {
596 return handler->CreateResource(node, parent, instance);
597 }
598 ND = ND->GetNext();
78d14f80 599 }
78d14f80
VS
600 }
601
602 wxLogError(_("No handler found for XML node '%s', class '%s'!"),
603 node->GetName().c_str(),
604 node->GetPropVal(wxT("class"), wxEmptyString).c_str());
605 return NULL;
606}
607
608
2b5f62a0
VZ
609#include "wx/listimpl.cpp"
610WX_DECLARE_LIST(wxXmlSubclassFactory, wxXmlSubclassFactoriesList);
611WX_DEFINE_LIST(wxXmlSubclassFactoriesList);
612
613wxXmlSubclassFactoriesList *wxXmlResource::ms_subclassFactories = NULL;
614
615/*static*/ void wxXmlResource::AddSubclassFactory(wxXmlSubclassFactory *factory)
616{
617 if (!ms_subclassFactories)
618 {
619 ms_subclassFactories = new wxXmlSubclassFactoriesList;
2b5f62a0
VZ
620 }
621 ms_subclassFactories->Append(factory);
622}
623
624class wxXmlSubclassFactoryCXX : public wxXmlSubclassFactory
625{
626public:
627 ~wxXmlSubclassFactoryCXX() {}
628
629 wxObject *Create(const wxString& className)
630 {
631 wxClassInfo* classInfo = wxClassInfo::FindClass(className);
632
633 if (classInfo)
634 return classInfo->CreateObject();
635 else
636 return NULL;
637 }
638};
639
640
641
78d14f80
VS
642
643
78d14f80
VS
644wxXmlResourceHandler::wxXmlResourceHandler()
645 : m_node(NULL), m_parent(NULL), m_instance(NULL),
646 m_parentAsWindow(NULL), m_instanceAsWindow(NULL)
647{}
648
649
650
651wxObject *wxXmlResourceHandler::CreateResource(wxXmlNode *node, wxObject *parent, wxObject *instance)
652{
653 wxXmlNode *myNode = m_node;
654 wxString myClass = m_class;
655 wxObject *myParent = m_parent, *myInstance = m_instance;
656 wxWindow *myParentAW = m_parentAsWindow, *myInstanceAW = m_instanceAsWindow;
657
daa85ee3 658 m_instance = instance;
b272b6dc 659 if (!m_instance && node->HasProp(wxT("subclass")) &&
daa85ee3
VS
660 !(m_resource->GetFlags() & wxXRC_NO_SUBCLASSING))
661 {
662 wxString subclass = node->GetPropVal(wxT("subclass"), wxEmptyString);
2b5f62a0 663 if (!subclass.empty())
daa85ee3 664 {
461932ae 665 for (wxXmlSubclassFactoriesList::compatibility_iterator i = wxXmlResource::ms_subclassFactories->GetFirst();
2b5f62a0
VZ
666 i; i = i->GetNext())
667 {
668 m_instance = i->GetData()->Create(subclass);
669 if (m_instance)
670 break;
671 }
daa85ee3 672
2b5f62a0
VZ
673 if (!m_instance)
674 {
675 wxString name = node->GetPropVal(wxT("name"), wxEmptyString);
676 wxLogError(_("Subclass '%s' not found for resource '%s', not subclassing!"),
677 subclass.c_str(), name.c_str());
678 }
679 }
daa85ee3
VS
680 }
681
78d14f80
VS
682 m_node = node;
683 m_class = node->GetPropVal(wxT("class"), wxEmptyString);
684 m_parent = parent;
78d14f80
VS
685 m_parentAsWindow = wxDynamicCast(m_parent, wxWindow);
686 m_instanceAsWindow = wxDynamicCast(m_instance, wxWindow);
687
688 wxObject *returned = DoCreateResource();
689
690 m_node = myNode;
691 m_class = myClass;
692 m_parent = myParent; m_parentAsWindow = myParentAW;
693 m_instance = myInstance; m_instanceAsWindow = myInstanceAW;
694
695 return returned;
696}
697
698
699void wxXmlResourceHandler::AddStyle(const wxString& name, int value)
700{
701 m_styleNames.Add(name);
702 m_styleValues.Add(value);
703}
704
705
706
707void wxXmlResourceHandler::AddWindowStyles()
708{
daa85ee3
VS
709 XRC_ADD_STYLE(wxSIMPLE_BORDER);
710 XRC_ADD_STYLE(wxSUNKEN_BORDER);
711 XRC_ADD_STYLE(wxDOUBLE_BORDER);
712 XRC_ADD_STYLE(wxRAISED_BORDER);
713 XRC_ADD_STYLE(wxSTATIC_BORDER);
714 XRC_ADD_STYLE(wxNO_BORDER);
715 XRC_ADD_STYLE(wxTRANSPARENT_WINDOW);
716 XRC_ADD_STYLE(wxWANTS_CHARS);
717 XRC_ADD_STYLE(wxNO_FULL_REPAINT_ON_RESIZE);
9f4ed861 718 XRC_ADD_STYLE(wxWS_EX_BLOCK_EVENTS);
78d14f80
VS
719}
720
721
722
723bool wxXmlResourceHandler::HasParam(const wxString& param)
724{
725 return (GetParamNode(param) != NULL);
726}
727
728
729int wxXmlResourceHandler::GetStyle(const wxString& param, int defaults)
730{
731 wxString s = GetParamValue(param);
732
733 if (!s) return defaults;
734
2b5f62a0 735 wxStringTokenizer tkn(s, wxT("| \t\n"), wxTOKEN_STRTOK);
78d14f80
VS
736 int style = 0;
737 int index;
738 wxString fl;
739 while (tkn.HasMoreTokens())
740 {
741 fl = tkn.GetNextToken();
742 index = m_styleNames.Index(fl);
743 if (index != wxNOT_FOUND)
744 style |= m_styleValues[index];
745 else
746 wxLogError(_("Unknown style flag ") + fl);
747 }
748 return style;
749}
750
751
752
ee1046d1 753wxString wxXmlResourceHandler::GetText(const wxString& param, bool translate)
78d14f80 754{
7b56015f
VS
755 wxXmlNode *parNode = GetParamNode(param);
756 wxString str1(GetNodeContent(parNode));
78d14f80
VS
757 wxString str2;
758 const wxChar *dt;
759 wxChar amp_char;
760
b272b6dc
RD
761 // VS: First version of XRC resources used $ instead of & (which is
762 // illegal in XML), but later I realized that '_' fits this purpose
718cf160 763 // much better (because &File means "File with F underlined").
78d14f80
VS
764 if (m_resource->CompareVersion(2,3,0,1) < 0)
765 amp_char = wxT('$');
766 else
767 amp_char = wxT('_');
768
769 for (dt = str1.c_str(); *dt; dt++)
770 {
771 // Remap amp_char to &, map double amp_char to amp_char (for things
772 // like "&File..." -- this is illegal in XML, so we use "_File..."):
773 if (*dt == amp_char)
774 {
775 if ( *(++dt) == amp_char )
776 str2 << amp_char;
777 else
778 str2 << wxT('&') << *dt;
779 }
780 // Remap \n to CR, \r to LF, \t to TAB:
781 else if (*dt == wxT('\\'))
782 switch (*(++dt))
783 {
784 case wxT('n') : str2 << wxT('\n'); break;
785 case wxT('t') : str2 << wxT('\t'); break;
786 case wxT('r') : str2 << wxT('\r'); break;
787 default : str2 << wxT('\\') << *dt; break;
788 }
789 else str2 << *dt;
790 }
b272b6dc 791
7b56015f
VS
792 if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
793 {
794 if (translate && parNode &&
795 parNode->GetPropVal(wxT("translate"), wxEmptyString) != wxT("0"))
796 {
797 return wxGetTranslation(str2);
798 }
799 else
800 {
801#if wxUSE_UNICODE
802 return str2;
803#else
804 // The string is internally stored as UTF-8, we have to convert
805 // it into system's default encoding so that it can be displayed:
806 return wxString(str2.mb_str(wxConvUTF8), wxConvLocal);
807#endif
808 }
809 }
718cf160 810 else
7b56015f
VS
811 {
812 // If wxXRC_USE_LOCALE is not set, then the string is already in
813 // system's default encoding in ANSI build, so we don't have to
814 // do anything special here.
718cf160 815 return str2;
7b56015f 816 }
78d14f80
VS
817}
818
819
820
821long wxXmlResourceHandler::GetLong(const wxString& param, long defaultv)
822{
823 long value;
824 wxString str1 = GetParamValue(param);
825
826 if (!str1.ToLong(&value))
827 value = defaultv;
828
829 return value;
830}
831
832
af1337b0 833
78d14f80
VS
834int wxXmlResourceHandler::GetID()
835{
13de23f6 836 return wxXmlResource::GetXRCID(GetName());
78d14f80
VS
837}
838
839
af1337b0 840
78d14f80
VS
841wxString wxXmlResourceHandler::GetName()
842{
843 return m_node->GetPropVal(wxT("name"), wxT("-1"));
844}
845
846
847
848bool wxXmlResourceHandler::GetBool(const wxString& param, bool defaultv)
849{
850 wxString v = GetParamValue(param);
851 v.MakeLower();
852 if (!v) return defaultv;
853 else return (v == wxT("1"));
854}
855
856
857
858wxColour wxXmlResourceHandler::GetColour(const wxString& param)
859{
860 wxString v = GetParamValue(param);
861 unsigned long tmp = 0;
862
863 if (v.Length() != 7 || v[0u] != wxT('#') ||
864 wxSscanf(v.c_str(), wxT("#%lX"), &tmp) != 1)
865 {
b5d6954b 866 wxLogError(_("XRC resource: Incorrect colour specification '%s' for property '%s'."),
78d14f80
VS
867 v.c_str(), param.c_str());
868 return wxNullColour;
869 }
870
871 return wxColour((unsigned char) ((tmp & 0xFF0000) >> 16) ,
872 (unsigned char) ((tmp & 0x00FF00) >> 8),
873 (unsigned char) ((tmp & 0x0000FF)));
874}
875
876
877
92e898b0 878wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param,
db59a97c
VS
879 const wxArtClient& defaultArtClient,
880 wxSize size)
78d14f80 881{
db59a97c
VS
882 /* If the bitmap is specified as stock item, query wxArtProvider for it: */
883 wxXmlNode *bmpNode = GetParamNode(param);
884 if ( bmpNode )
af1337b0 885 {
db59a97c
VS
886 wxString sid = bmpNode->GetPropVal(wxT("stock_id"), wxEmptyString);
887 if ( !sid.empty() )
888 {
889 wxString scl = bmpNode->GetPropVal(wxT("stock_client"), defaultArtClient);
92e898b0 890 wxBitmap stockArt =
db59a97c
VS
891 wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(sid),
892 wxART_MAKE_CLIENT_ID_FROM_STR(scl),
893 size);
894 if ( stockArt.Ok() )
895 return stockArt;
896 }
af1337b0
JS
897 }
898
92e898b0 899 /* ...or load the bitmap from file: */
78d14f80 900 wxString name = GetParamValue(param);
92e898b0 901 if (name.IsEmpty()) return wxNullBitmap;
78d14f80
VS
902#if wxUSE_FILESYSTEM
903 wxFSFile *fsfile = GetCurFileSystem().OpenFile(name);
904 if (fsfile == NULL)
905 {
d0b50ad9
VS
906 wxLogError(_("XRC resource: Cannot create bitmap from '%s'."),
907 name.c_str());
78d14f80
VS
908 return wxNullBitmap;
909 }
910 wxImage img(*(fsfile->GetStream()));
911 delete fsfile;
912#else
913 wxImage img(GetParamValue(wxT("bitmap")));
914#endif
af1337b0 915
78d14f80
VS
916 if (!img.Ok())
917 {
b5d6954b 918 wxLogError(_("XRC resource: Cannot create bitmap from '%s'."), param.c_str());
78d14f80
VS
919 return wxNullBitmap;
920 }
921 if (!(size == wxDefaultSize)) img.Rescale(size.x, size.y);
b272b6dc 922 return wxBitmap(img);
af1337b0 923
78d14f80
VS
924}
925
926
927
92e898b0 928wxIcon wxXmlResourceHandler::GetIcon(const wxString& param,
db59a97c
VS
929 const wxArtClient& defaultArtClient,
930 wxSize size)
78d14f80 931{
78d14f80 932 wxIcon icon;
db59a97c 933 icon.CopyFromBitmap(GetBitmap(param, defaultArtClient, size));
78d14f80
VS
934 return icon;
935}
936
937
938
939wxXmlNode *wxXmlResourceHandler::GetParamNode(const wxString& param)
940{
2b5f62a0
VZ
941 wxCHECK_MSG(m_node, NULL, wxT("You can't access handler data before it was initialized!"));
942
78d14f80
VS
943 wxXmlNode *n = m_node->GetChildren();
944
945 while (n)
946 {
947 if (n->GetType() == wxXML_ELEMENT_NODE && n->GetName() == param)
948 return n;
949 n = n->GetNext();
950 }
951 return NULL;
952}
953
954
955wxString wxXmlResourceHandler::GetNodeContent(wxXmlNode *node)
956{
957 wxXmlNode *n = node;
958 if (n == NULL) return wxEmptyString;
959 n = n->GetChildren();
960
961 while (n)
962 {
963 if (n->GetType() == wxXML_TEXT_NODE ||
964 n->GetType() == wxXML_CDATA_SECTION_NODE)
965 return n->GetContent();
966 n = n->GetNext();
967 }
968 return wxEmptyString;
969}
970
971
972
973wxString wxXmlResourceHandler::GetParamValue(const wxString& param)
974{
975 if (param.IsEmpty())
976 return GetNodeContent(m_node);
977 else
978 return GetNodeContent(GetParamNode(param));
979}
980
981
982
983wxSize wxXmlResourceHandler::GetSize(const wxString& param)
984{
985 wxString s = GetParamValue(param);
986 if (s.IsEmpty()) s = wxT("-1,-1");
987 bool is_dlg;
988 long sx, sy;
989
990 is_dlg = s[s.Length()-1] == wxT('d');
991 if (is_dlg) s.RemoveLast();
992
993 if (!s.BeforeFirst(wxT(',')).ToLong(&sx) ||
994 !s.AfterLast(wxT(',')).ToLong(&sy))
995 {
00393283 996 wxLogError(_("Cannot parse coordinates from '%s'."), s.c_str());
78d14f80
VS
997 return wxDefaultSize;
998 }
999
1000 if (is_dlg)
1001 {
1002 if (m_instanceAsWindow)
1003 return wxDLG_UNIT(m_instanceAsWindow, wxSize(sx, sy));
1004 else if (m_parentAsWindow)
1005 return wxDLG_UNIT(m_parentAsWindow, wxSize(sx, sy));
1006 else
1007 {
1008 wxLogError(_("Cannot convert dialog units: dialog unknown."));
1009 return wxDefaultSize;
1010 }
1011 }
1012 else return wxSize(sx, sy);
1013}
1014
1015
1016
1017wxPoint wxXmlResourceHandler::GetPosition(const wxString& param)
1018{
1019 wxSize sz = GetSize(param);
1020 return wxPoint(sz.x, sz.y);
1021}
1022
1023
1024
1025wxCoord wxXmlResourceHandler::GetDimension(const wxString& param, wxCoord defaultv)
1026{
1027 wxString s = GetParamValue(param);
1028 if (s.IsEmpty()) return defaultv;
1029 bool is_dlg;
1030 long sx;
1031
1032 is_dlg = s[s.Length()-1] == wxT('d');
1033 if (is_dlg) s.RemoveLast();
1034
1035 if (!s.ToLong(&sx))
1036 {
00393283 1037 wxLogError(_("Cannot parse dimension from '%s'."), s.c_str());
78d14f80
VS
1038 return defaultv;
1039 }
1040
1041 if (is_dlg)
1042 {
1043 if (m_instanceAsWindow)
1044 return wxDLG_UNIT(m_instanceAsWindow, wxSize(sx, 0)).x;
1045 else if (m_parentAsWindow)
1046 return wxDLG_UNIT(m_parentAsWindow, wxSize(sx, 0)).x;
1047 else
1048 {
1049 wxLogError(_("Cannot convert dialog units: dialog unknown."));
1050 return defaultv;
1051 }
1052 }
1053 else return sx;
1054}
1055
1056
1057
1058wxFont wxXmlResourceHandler::GetFont(const wxString& param)
1059{
1060 wxXmlNode *font_node = GetParamNode(param);
1061 if (font_node == NULL)
1062 {
00393283 1063 wxLogError(_("Cannot find font node '%s'."), param.c_str());
78d14f80
VS
1064 return wxNullFont;
1065 }
1066
1067 wxXmlNode *oldnode = m_node;
1068 m_node = font_node;
1069
1070 long size = GetLong(wxT("size"), 12);
1071
1072 wxString style = GetParamValue(wxT("style"));
1073 wxString weight = GetParamValue(wxT("weight"));
1074 int istyle = wxNORMAL, iweight = wxNORMAL;
1075 if (style == wxT("italic")) istyle = wxITALIC;
1076 else if (style == wxT("slant")) istyle = wxSLANT;
1077 if (weight == wxT("bold")) iweight = wxBOLD;
1078 else if (weight == wxT("light")) iweight = wxLIGHT;
1079
1080 wxString family = GetParamValue(wxT("family"));
1081 int ifamily = wxDEFAULT;
1082 if (family == wxT("decorative")) ifamily = wxDECORATIVE;
1083 else if (family == wxT("roman")) ifamily = wxROMAN;
1084 else if (family == wxT("script")) ifamily = wxSCRIPT;
1085 else if (family == wxT("swiss")) ifamily = wxSWISS;
1086 else if (family == wxT("modern")) ifamily = wxMODERN;
1087
1088 bool underlined = GetBool(wxT("underlined"), FALSE);
1089
1090 wxString encoding = GetParamValue(wxT("encoding"));
1091 wxFontMapper mapper;
1092 wxFontEncoding enc = wxFONTENCODING_DEFAULT;
91cddacf
VS
1093 if (!encoding.IsEmpty())
1094 enc = mapper.CharsetToEncoding(encoding);
1095 if (enc == wxFONTENCODING_SYSTEM)
1096 enc = wxFONTENCODING_DEFAULT;
78d14f80
VS
1097
1098 wxString faces = GetParamValue(wxT("face"));
1099 wxString facename = wxEmptyString;
1100 wxFontEnumerator enu;
1101 enu.EnumerateFacenames();
1102 wxStringTokenizer tk(faces, wxT(","));
1103 while (tk.HasMoreTokens())
1104 {
1105 int index = enu.GetFacenames()->Index(tk.GetNextToken(), FALSE);
1106 if (index != wxNOT_FOUND)
1107 {
1108 facename = (*enu.GetFacenames())[index];
1109 break;
1110 }
1111 }
1112
1113 m_node = oldnode;
1114
1115 wxFont font(size, ifamily, istyle, iweight, underlined, facename, enc);
1116 return font;
1117}
1118
1119
1120void wxXmlResourceHandler::SetupWindow(wxWindow *wnd)
1121{
1122 //FIXME : add cursor
1123
1124 if (HasParam(wxT("exstyle")))
1125 wnd->SetExtraStyle(GetStyle(wxT("exstyle")));
1126 if (HasParam(wxT("bg")))
1127 wnd->SetBackgroundColour(GetColour(wxT("bg")));
1128 if (HasParam(wxT("fg")))
1129 wnd->SetForegroundColour(GetColour(wxT("fg")));
1130 if (GetBool(wxT("enabled"), 1) == 0)
1131 wnd->Enable(FALSE);
1132 if (GetBool(wxT("focused"), 0) == 1)
1133 wnd->SetFocus();
1134 if (GetBool(wxT("hidden"), 0) == 1)
1135 wnd->Show(FALSE);
1136#if wxUSE_TOOLTIPS
1137 if (HasParam(wxT("tooltip")))
1138 wnd->SetToolTip(GetText(wxT("tooltip")));
1139#endif
1140 if (HasParam(wxT("font")))
1141 wnd->SetFont(GetFont());
1142}
1143
1144
1145void wxXmlResourceHandler::CreateChildren(wxObject *parent, bool this_hnd_only)
1146{
1147 wxXmlNode *n = m_node->GetChildren();
1148
1149 while (n)
1150 {
1151 if (n->GetType() == wxXML_ELEMENT_NODE &&
0fa2e104 1152 (n->GetName() == wxT("object") || n->GetName() == wxT("object_ref")))
78d14f80 1153 {
317a0d73
VS
1154 m_resource->CreateResFromNode(n, parent, NULL,
1155 this_hnd_only ? this : NULL);
78d14f80
VS
1156 }
1157 n = n->GetNext();
1158 }
1159}
1160
1161
1162void wxXmlResourceHandler::CreateChildrenPrivately(wxObject *parent, wxXmlNode *rootnode)
1163{
1164 wxXmlNode *root;
1165 if (rootnode == NULL) root = m_node; else root = rootnode;
1166 wxXmlNode *n = root->GetChildren();
1167
1168 while (n)
1169 {
1170 if (n->GetType() == wxXML_ELEMENT_NODE && CanHandle(n))
1171 {
1172 CreateResource(n, parent, NULL);
1173 }
1174 n = n->GetNext();
1175 }
1176}
1177
1178
1179
1180
1181
1182
1183
5ed345b7 1184// --------------- XRCID implementation -----------------------------
78d14f80 1185
5ed345b7 1186#define XRCID_TABLE_SIZE 1024
78d14f80
VS
1187
1188
5ed345b7 1189struct XRCID_record
78d14f80
VS
1190{
1191 int id;
00393283 1192 wxChar *key;
5ed345b7 1193 XRCID_record *next;
78d14f80
VS
1194};
1195
5ed345b7 1196static XRCID_record *XRCID_Records[XRCID_TABLE_SIZE] = {NULL};
78d14f80 1197
13de23f6 1198static int XRCID_Lookup(const wxChar *str_id, int value_if_not_found = -2)
78d14f80 1199{
5ed345b7 1200 static int XRCID_LastID = wxID_HIGHEST;
78d14f80
VS
1201
1202 int index = 0;
1203
00393283 1204 for (const wxChar *c = str_id; *c != wxT('\0'); c++) index += (int)*c;
5ed345b7 1205 index %= XRCID_TABLE_SIZE;
78d14f80 1206
5ed345b7 1207 XRCID_record *oldrec = NULL;
5ed345b7 1208 for (XRCID_record *rec = XRCID_Records[index]; rec; rec = rec->next)
78d14f80 1209 {
00393283 1210 if (wxStrcmp(rec->key, str_id) == 0)
78d14f80
VS
1211 {
1212 return rec->id;
1213 }
78d14f80
VS
1214 oldrec = rec;
1215 }
1216
5ed345b7
VS
1217 XRCID_record **rec_var = (oldrec == NULL) ?
1218 &XRCID_Records[index] : &oldrec->next;
1219 *rec_var = new XRCID_record;
00393283 1220 (*rec_var)->key = wxStrdup(str_id);
78d14f80
VS
1221 (*rec_var)->next = NULL;
1222
85452d74 1223 wxChar *end;
13de23f6
VS
1224 if (value_if_not_found != -2)
1225 (*rec_var)->id = value_if_not_found;
85452d74
VS
1226 else
1227 {
13de23f6
VS
1228 int asint = wxStrtol(str_id, &end, 10);
1229 if (*str_id && *end == 0)
1230 {
1231 // if str_id was integer, keep it verbosely:
1232 (*rec_var)->id = asint;
1233 }
1234 else
1235 {
1236 (*rec_var)->id = ++XRCID_LastID;
1237 }
85452d74
VS
1238 }
1239
78d14f80
VS
1240 return (*rec_var)->id;
1241}
1242
13de23f6
VS
1243/*static*/ int wxXmlResource::GetXRCID(const wxChar *str_id)
1244{
1245 return XRCID_Lookup(str_id);
1246}
1247
78d14f80 1248
5ed345b7 1249static void CleanXRCID_Record(XRCID_record *rec)
78d14f80
VS
1250{
1251 if (rec)
1252 {
5ed345b7 1253 CleanXRCID_Record(rec->next);
00393283 1254 free(rec->key);
78d14f80
VS
1255 delete rec;
1256 }
1257}
1258
5ed345b7 1259static void CleanXRCID_Records()
78d14f80 1260{
5ed345b7 1261 for (int i = 0; i < XRCID_TABLE_SIZE; i++)
139c5871 1262 {
5ed345b7 1263 CleanXRCID_Record(XRCID_Records[i]);
139c5871
VS
1264 XRCID_Records[i] = NULL;
1265 }
78d14f80
VS
1266}
1267
13de23f6
VS
1268static void AddStdXRCID_Records()
1269{
1270#define stdID(id) XRCID_Lookup(wxT(#id), id)
1271 stdID(-1);
1272 stdID(wxID_OPEN); stdID(wxID_CLOSE); stdID(wxID_NEW);
1273 stdID(wxID_SAVE); stdID(wxID_SAVEAS); stdID(wxID_REVERT);
1274 stdID(wxID_EXIT); stdID(wxID_UNDO); stdID(wxID_REDO);
1275 stdID(wxID_HELP); stdID(wxID_PRINT); stdID(wxID_PRINT_SETUP);
1276 stdID(wxID_PREVIEW); stdID(wxID_ABOUT); stdID(wxID_HELP_CONTENTS);
1277 stdID(wxID_HELP_COMMANDS); stdID(wxID_HELP_PROCEDURES);
1278 stdID(wxID_CUT); stdID(wxID_COPY); stdID(wxID_PASTE);
1279 stdID(wxID_CLEAR); stdID(wxID_FIND); stdID(wxID_DUPLICATE);
1280 stdID(wxID_SELECTALL); stdID(wxID_OK); stdID(wxID_CANCEL);
1281 stdID(wxID_APPLY); stdID(wxID_YES); stdID(wxID_NO);
1282 stdID(wxID_STATIC); stdID(wxID_FORWARD); stdID(wxID_BACKWARD);
1283 stdID(wxID_DEFAULT); stdID(wxID_MORE); stdID(wxID_SETUP);
1284 stdID(wxID_RESET); stdID(wxID_HELP_CONTEXT);
1285 stdID(wxID_CLOSE_ALL);
1286#undef stdID
1287}
78d14f80
VS
1288
1289
1290
1291
1292
1293// --------------- module and globals -----------------------------
1294
78d14f80
VS
1295class wxXmlResourceModule: public wxModule
1296{
1297DECLARE_DYNAMIC_CLASS(wxXmlResourceModule)
1298public:
1299 wxXmlResourceModule() {}
824e8eaa
VS
1300 bool OnInit()
1301 {
13de23f6 1302 AddStdXRCID_Records();
2b5f62a0 1303 wxXmlResource::AddSubclassFactory(new wxXmlSubclassFactoryCXX);
824e8eaa
VS
1304 return TRUE;
1305 }
78d14f80
VS
1306 void OnExit()
1307 {
1542c42e 1308 delete wxXmlResource::Set(NULL);
461932ae
MB
1309 if(wxXmlResource::ms_subclassFactories)
1310 WX_CLEAR_LIST(wxXmlSubclassFactoriesList, *wxXmlResource::ms_subclassFactories);
2b5f62a0 1311 wxDELETE(wxXmlResource::ms_subclassFactories);
5ed345b7 1312 CleanXRCID_Records();
78d14f80
VS
1313 }
1314};
1315
1316IMPLEMENT_DYNAMIC_CLASS(wxXmlResourceModule, wxModule)
1317
1318
1319// When wxXml is loaded dynamically after the application is already running
1320// then the built-in module system won't pick this one up. Add it manually.
1321void wxXmlInitResourceModule()
1322{
1323 wxModule* module = new wxXmlResourceModule;
1324 module->Init();
1325 wxModule::RegisterModule(module);
1326}