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