]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: contrib/src/deprecated/resource.cpp | |
3 | // Purpose: Resource system | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // For compilers that support precompilation, includes "wx.h". | |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
16 | #pragma hdrstop | |
17 | #endif | |
18 | ||
19 | #include "wx/deprecated/setup.h" | |
20 | ||
21 | #if wxUSE_WX_RESOURCES | |
22 | ||
23 | #ifdef __VISUALC__ | |
24 | #pragma warning(disable:4706) // assignment within conditional expression | |
25 | #endif // VC++ | |
26 | ||
27 | #ifndef WX_PRECOMP | |
28 | #include "wx/list.h" | |
29 | #include "wx/hash.h" | |
30 | #include "wx/gdicmn.h" | |
31 | #include "wx/utils.h" | |
32 | #include "wx/types.h" | |
33 | #include "wx/menu.h" | |
34 | #include "wx/stattext.h" | |
35 | #include "wx/button.h" | |
36 | #include "wx/bmpbuttn.h" | |
37 | #include "wx/radiobox.h" | |
38 | #include "wx/listbox.h" | |
39 | #include "wx/choice.h" | |
40 | #include "wx/checkbox.h" | |
41 | #include "wx/settings.h" | |
42 | #include "wx/slider.h" | |
43 | #include "wx/icon.h" | |
44 | #include "wx/statbox.h" | |
45 | #include "wx/statbmp.h" | |
46 | #include "wx/gauge.h" | |
47 | #include "wx/textctrl.h" | |
48 | #include "wx/msgdlg.h" | |
49 | #include "wx/intl.h" | |
50 | #endif | |
51 | ||
52 | #include "wx/treebase.h" | |
53 | #include "wx/listctrl.h" | |
54 | ||
55 | #if wxUSE_RADIOBTN | |
56 | #include "wx/radiobut.h" | |
57 | #endif | |
58 | ||
59 | #if wxUSE_SCROLLBAR | |
60 | #include "wx/scrolbar.h" | |
61 | #endif | |
62 | ||
63 | #if wxUSE_COMBOBOX | |
64 | #include "wx/combobox.h" | |
65 | #endif | |
66 | ||
67 | #include "wx/splitter.h" | |
68 | #include "wx/toolbar.h" | |
69 | ||
70 | #include "wx/validate.h" | |
71 | #include "wx/log.h" | |
72 | #include "wx/module.h" | |
73 | ||
74 | #include <ctype.h> | |
75 | #include <math.h> | |
76 | #include <stdlib.h> | |
77 | #include <string.h> | |
78 | ||
79 | #include "wx/string.h" | |
80 | #include "wx/settings.h" | |
81 | #include "wx/stream.h" | |
82 | ||
83 | #include "wx/deprecated/resource.h" | |
84 | #include "wx/deprecated/wxexpr.h" | |
85 | ||
86 | #if !WXWIN_COMPATIBILITY_2_4 | |
87 | static inline wxChar* copystring(const wxChar* s) | |
88 | { return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); } | |
89 | #endif | |
90 | ||
91 | // Forward (private) declarations | |
92 | bool wxResourceInterpretResources(wxResourceTable& table, wxExprDatabase& db); | |
93 | wxItemResource *wxResourceInterpretDialog(wxResourceTable& table, wxExpr *expr, bool isPanel = false); | |
94 | wxItemResource *wxResourceInterpretControl(wxResourceTable& table, wxExpr *expr); | |
95 | wxItemResource *wxResourceInterpretMenu(wxResourceTable& table, wxExpr *expr); | |
96 | wxItemResource *wxResourceInterpretMenuBar(wxResourceTable& table, wxExpr *expr); | |
97 | wxItemResource *wxResourceInterpretString(wxResourceTable& table, wxExpr *expr); | |
98 | wxItemResource *wxResourceInterpretBitmap(wxResourceTable& table, wxExpr *expr); | |
99 | wxItemResource *wxResourceInterpretIcon(wxResourceTable& table, wxExpr *expr); | |
100 | // Interpret list expression | |
101 | wxFont wxResourceInterpretFontSpec(wxExpr *expr); | |
102 | ||
103 | bool wxResourceReadOneResource(FILE *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table = (wxResourceTable *) NULL); | |
104 | bool wxResourceReadOneResource(wxInputStream *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table) ; | |
105 | bool wxResourceParseIncludeFile(const wxString& f, wxResourceTable *table = (wxResourceTable *) NULL); | |
106 | ||
107 | wxResourceTable *wxDefaultResourceTable = (wxResourceTable *) NULL; | |
108 | ||
109 | char *wxResourceBuffer = (char *) NULL; | |
110 | long wxResourceBufferSize = 0; | |
111 | long wxResourceBufferCount = 0; | |
112 | int wxResourceStringPtr = 0; | |
113 | ||
114 | void wxInitializeResourceSystem() | |
115 | { | |
116 | if (!wxDefaultResourceTable) | |
117 | wxDefaultResourceTable = new wxResourceTable; | |
118 | } | |
119 | ||
120 | void wxCleanUpResourceSystem() | |
121 | { | |
122 | delete wxDefaultResourceTable; | |
123 | if (wxResourceBuffer) | |
124 | delete[] wxResourceBuffer; | |
125 | } | |
126 | ||
127 | // Module to ensure the resource system data gets initialized | |
128 | // and cleaned up. | |
129 | ||
130 | class wxResourceModule: public wxModule | |
131 | { | |
132 | public: | |
133 | wxResourceModule() : wxModule() {} | |
134 | virtual bool OnInit() { wxInitializeResourceSystem(); return true; } | |
135 | virtual void OnExit() { wxCleanUpResourceSystem(); } | |
136 | ||
137 | DECLARE_DYNAMIC_CLASS(wxResourceModule) | |
138 | }; | |
139 | ||
140 | IMPLEMENT_DYNAMIC_CLASS(wxResourceModule, wxModule) | |
141 | ||
142 | ||
143 | IMPLEMENT_DYNAMIC_CLASS(wxItemResource, wxObject) | |
144 | IMPLEMENT_DYNAMIC_CLASS(wxResourceTable, wxHashTable) | |
145 | ||
146 | wxItemResource::wxItemResource() | |
147 | { | |
148 | m_itemType = wxEmptyString; | |
149 | m_title = wxEmptyString; | |
150 | m_name = wxEmptyString; | |
151 | m_windowStyle = 0; | |
152 | m_x = m_y = m_width = m_height = 0; | |
153 | m_value1 = m_value2 = m_value3 = m_value5 = 0; | |
154 | m_value4 = wxEmptyString; | |
155 | m_windowId = 0; | |
156 | m_exStyle = 0; | |
157 | } | |
158 | ||
159 | wxItemResource::~wxItemResource() | |
160 | { | |
161 | wxNode *node = m_children.GetFirst(); | |
162 | while (node) | |
163 | { | |
164 | wxItemResource *item = (wxItemResource *)node->GetData(); | |
165 | delete item; | |
166 | delete node; | |
167 | node = m_children.GetFirst(); | |
168 | } | |
169 | } | |
170 | ||
171 | /* | |
172 | * Resource table | |
173 | */ | |
174 | ||
175 | wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING), identifiers(wxKEY_STRING) | |
176 | { | |
177 | } | |
178 | ||
179 | wxResourceTable::~wxResourceTable() | |
180 | { | |
181 | ClearTable(); | |
182 | } | |
183 | ||
184 | wxItemResource *wxResourceTable::FindResource(const wxString& name) const | |
185 | { | |
186 | wxItemResource *item = (wxItemResource *)Get(WXSTRINGCAST name); | |
187 | return item; | |
188 | } | |
189 | ||
190 | void wxResourceTable::AddResource(wxItemResource *item) | |
191 | { | |
192 | wxString name = item->GetName(); | |
193 | if (name.empty()) | |
194 | name = item->GetTitle(); | |
195 | if (name.empty()) | |
196 | name = wxT("no name"); | |
197 | ||
198 | // Delete existing resource, if any. | |
199 | Delete(name); | |
200 | ||
201 | Put(name, item); | |
202 | } | |
203 | ||
204 | bool wxResourceTable::DeleteResource(const wxString& name) | |
205 | { | |
206 | wxItemResource *item = (wxItemResource *)Delete(WXSTRINGCAST name); | |
207 | if (item) | |
208 | { | |
209 | // See if any resource has this as its child; if so, delete from | |
210 | // parent's child list. | |
211 | BeginFind(); | |
212 | wxHashTable::Node *node = Next(); | |
213 | while (node != NULL) | |
214 | { | |
215 | wxItemResource *parent = (wxItemResource *)node->GetData(); | |
216 | if (parent->GetChildren().Member(item)) | |
217 | { | |
218 | parent->GetChildren().DeleteObject(item); | |
219 | break; | |
220 | } | |
221 | node = Next(); | |
222 | } | |
223 | ||
224 | delete item; | |
225 | return true; | |
226 | } | |
227 | else | |
228 | return false; | |
229 | } | |
230 | ||
231 | bool wxResourceTable::ParseResourceFile( wxInputStream *is ) | |
232 | { | |
233 | wxExprDatabase db; | |
234 | int len = is->GetSize() ; | |
235 | ||
236 | bool eof = false; | |
237 | while ( is->TellI() + 10 < len) // it's a hack because the streams dont support EOF | |
238 | { | |
239 | wxResourceReadOneResource(is, db, &eof, this) ; | |
240 | } | |
241 | return wxResourceInterpretResources(*this, db); | |
242 | } | |
243 | ||
244 | bool wxResourceTable::ParseResourceFile(const wxString& filename) | |
245 | { | |
246 | wxExprDatabase db; | |
247 | ||
248 | FILE *fd = wxFopen(filename, wxT("r")); | |
249 | if (!fd) | |
250 | return false; | |
251 | bool eof = false; | |
252 | while (wxResourceReadOneResource(fd, db, &eof, this) && !eof) | |
253 | { | |
254 | // Loop | |
255 | } | |
256 | fclose(fd); | |
257 | return wxResourceInterpretResources(*this, db); | |
258 | } | |
259 | ||
260 | bool wxResourceTable::ParseResourceData(const wxString& data) | |
261 | { | |
262 | wxExprDatabase db; | |
263 | if (!db.ReadFromString(data)) | |
264 | { | |
265 | wxLogWarning(_("Ill-formed resource file syntax.")); | |
266 | return false; | |
267 | } | |
268 | ||
269 | return wxResourceInterpretResources(*this, db); | |
270 | } | |
271 | ||
272 | bool wxResourceTable::RegisterResourceBitmapData(const wxString& name, char bits[], int width, int height) | |
273 | { | |
274 | // Register pre-loaded bitmap data | |
275 | wxItemResource *item = new wxItemResource; | |
276 | // item->SetType(wxRESOURCE_TYPE_XBM_DATA); | |
277 | item->SetType(wxT("wxXBMData")); | |
278 | item->SetName(name); | |
279 | item->SetValue1((long)bits); | |
280 | item->SetValue2((long)width); | |
281 | item->SetValue3((long)height); | |
282 | AddResource(item); | |
283 | return true; | |
284 | } | |
285 | ||
286 | bool wxResourceTable::RegisterResourceBitmapData(const wxString& name, char **data) | |
287 | { | |
288 | // Register pre-loaded bitmap data | |
289 | wxItemResource *item = new wxItemResource; | |
290 | // item->SetType(wxRESOURCE_TYPE_XPM_DATA); | |
291 | item->SetType(wxT("wxXPMData")); | |
292 | item->SetName(name); | |
293 | item->SetValue1((long)data); | |
294 | AddResource(item); | |
295 | return true; | |
296 | } | |
297 | ||
298 | bool wxResourceTable::SaveResource(const wxString& WXUNUSED(filename)) | |
299 | { | |
300 | return false; | |
301 | } | |
302 | ||
303 | void wxResourceTable::ClearTable() | |
304 | { | |
305 | BeginFind(); | |
306 | wxHashTable::Node *node = Next(); | |
307 | while (node) | |
308 | { | |
309 | wxHashTable::Node *next = Next(); | |
310 | wxItemResource *item = (wxItemResource *)node->GetData(); | |
311 | delete item; | |
312 | delete node; | |
313 | node = next; | |
314 | } | |
315 | } | |
316 | ||
317 | wxControl *wxResourceTable::CreateItem(wxWindow *parent, const wxItemResource* childResource, const wxItemResource* parentResource) const | |
318 | { | |
319 | int id = childResource->GetId(); | |
320 | if ( id == 0 ) | |
321 | id = wxID_ANY; | |
322 | ||
323 | bool dlgUnits = ((parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0); | |
324 | ||
325 | wxControl *control = (wxControl *) NULL; | |
326 | wxString itemType(childResource->GetType()); | |
327 | ||
328 | wxPoint pos; | |
329 | wxSize size; | |
330 | if (dlgUnits) | |
331 | { | |
332 | pos = parent->ConvertDialogToPixels(wxPoint(childResource->GetX(), childResource->GetY())); | |
333 | size = parent->ConvertDialogToPixels(wxSize(childResource->GetWidth(), childResource->GetHeight())); | |
334 | } | |
335 | else | |
336 | { | |
337 | pos = wxPoint(childResource->GetX(), childResource->GetY()); | |
338 | size = wxSize(childResource->GetWidth(), childResource->GetHeight()); | |
339 | } | |
340 | ||
341 | if (itemType == wxString(wxT("wxButton")) || itemType == wxString(wxT("wxBitmapButton"))) | |
342 | { | |
343 | if (!childResource->GetValue4().empty()) | |
344 | { | |
345 | // Bitmap button | |
346 | wxBitmap bitmap = childResource->GetBitmap(); | |
347 | if (!bitmap.Ok()) | |
348 | { | |
349 | bitmap = wxResourceCreateBitmap(childResource->GetValue4(), (wxResourceTable *)this); | |
350 | ((wxItemResource*) childResource)->SetBitmap(bitmap); | |
351 | } | |
352 | if (!bitmap.Ok()) | |
353 | #if defined(__WXPM__) | |
354 | // | |
355 | // OS/2 uses integer id's to access resources, not file name strings | |
356 | // | |
357 | bitmap.LoadFile(wxCROSS_BITMAP, wxBITMAP_TYPE_BMP_RESOURCE); | |
358 | #else | |
359 | bitmap.LoadFile(wxT("cross_bmp"), wxBITMAP_TYPE_BMP_RESOURCE); | |
360 | #endif | |
361 | control = new wxBitmapButton(parent, id, bitmap, pos, size, | |
362 | childResource->GetStyle() | wxBU_AUTODRAW, wxDefaultValidator, childResource->GetName()); | |
363 | } | |
364 | else | |
365 | // Normal, text button | |
366 | control = new wxButton(parent, id, childResource->GetTitle(), pos, size, | |
367 | childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); | |
368 | } | |
369 | else if (itemType == wxString(wxT("wxMessage")) || itemType == wxString(wxT("wxStaticText")) || | |
370 | itemType == wxString(wxT("wxStaticBitmap"))) | |
371 | { | |
372 | if (!childResource->GetValue4().empty() || itemType == wxString(wxT("wxStaticBitmap")) ) | |
373 | { | |
374 | // Bitmap message | |
375 | wxBitmap bitmap = childResource->GetBitmap(); | |
376 | if (!bitmap.Ok()) | |
377 | { | |
378 | bitmap = wxResourceCreateBitmap(childResource->GetValue4(), (wxResourceTable *)this); | |
379 | ((wxItemResource*) childResource)->SetBitmap(bitmap); | |
380 | } | |
381 | #if wxUSE_BITMAP_MESSAGE | |
382 | #ifdef __WXMSW__ | |
383 | // Use a default bitmap | |
384 | if (!bitmap.Ok()) | |
385 | bitmap.LoadFile(wxT("cross_bmp"), wxBITMAP_TYPE_BMP_RESOURCE); | |
386 | #endif | |
387 | ||
388 | if (bitmap.Ok()) | |
389 | control = new wxStaticBitmap(parent, id, bitmap, pos, size, | |
390 | childResource->GetStyle(), childResource->GetName()); | |
391 | #endif | |
392 | } | |
393 | else | |
394 | { | |
395 | control = new wxStaticText(parent, id, childResource->GetTitle(), pos, size, | |
396 | childResource->GetStyle(), childResource->GetName()); | |
397 | } | |
398 | } | |
399 | else if (itemType == wxString(wxT("wxText")) || itemType == wxString(wxT("wxTextCtrl")) || itemType == wxString(wxT("wxMultiText"))) | |
400 | { | |
401 | control = new wxTextCtrl(parent, id, childResource->GetValue4(), pos, size, | |
402 | childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); | |
403 | } | |
404 | else if (itemType == wxString(wxT("wxCheckBox"))) | |
405 | { | |
406 | control = new wxCheckBox(parent, id, childResource->GetTitle(), pos, size, | |
407 | childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); | |
408 | ||
409 | ((wxCheckBox *)control)->SetValue((childResource->GetValue1() != 0)); | |
410 | } | |
411 | #if wxUSE_GAUGE | |
412 | else if (itemType == wxString(wxT("wxGauge"))) | |
413 | { | |
414 | control = new wxGauge(parent, id, (int)childResource->GetValue2(), pos, size, | |
415 | childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); | |
416 | ||
417 | ((wxGauge *)control)->SetValue((int)childResource->GetValue1()); | |
418 | } | |
419 | #endif | |
420 | #if wxUSE_RADIOBTN | |
421 | else if (itemType == wxString(wxT("wxRadioButton"))) | |
422 | { | |
423 | control = new wxRadioButton(parent, id, childResource->GetTitle(), // (int)childResource->GetValue1(), | |
424 | pos, size, | |
425 | childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); | |
426 | } | |
427 | #endif | |
428 | #if wxUSE_SCROLLBAR | |
429 | else if (itemType == wxString(wxT("wxScrollBar"))) | |
430 | { | |
431 | control = new wxScrollBar(parent, id, pos, size, | |
432 | childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); | |
433 | /* | |
434 | ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1()); | |
435 | ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2()); | |
436 | ((wxScrollBar *)control)->SetObjectLength((int)childResource->GetValue3()); | |
437 | ((wxScrollBar *)control)->SetViewLength((int)(long)childResource->GetValue5()); | |
438 | */ | |
439 | ((wxScrollBar *)control)->SetScrollbar((int)childResource->GetValue1(),(int)childResource->GetValue2(), | |
440 | (int)childResource->GetValue3(),(int)(long)childResource->GetValue5(),false); | |
441 | ||
442 | } | |
443 | #endif | |
444 | else if (itemType == wxString(wxT("wxSlider"))) | |
445 | { | |
446 | control = new wxSlider(parent, id, (int)childResource->GetValue1(), | |
447 | (int)childResource->GetValue2(), (int)childResource->GetValue3(), pos, size, | |
448 | childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); | |
449 | } | |
450 | else if (itemType == wxString(wxT("wxGroupBox")) || itemType == wxString(wxT("wxStaticBox"))) | |
451 | { | |
452 | control = new wxStaticBox(parent, id, childResource->GetTitle(), pos, size, | |
453 | childResource->GetStyle(), childResource->GetName()); | |
454 | } | |
455 | else if (itemType == wxString(wxT("wxListBox"))) | |
456 | { | |
457 | wxStringList& stringList = childResource->GetStringValues(); | |
458 | wxString *strings = (wxString *) NULL; | |
459 | int noStrings = 0; | |
460 | if (stringList.GetCount() > 0) | |
461 | { | |
462 | noStrings = stringList.GetCount(); | |
463 | strings = new wxString[noStrings]; | |
464 | wxStringListNode *node = stringList.GetFirst(); | |
465 | int i = 0; | |
466 | while (node) | |
467 | { | |
468 | strings[i] = (wxChar *)node->GetData(); | |
469 | i ++; | |
470 | node = node->GetNext(); | |
471 | } | |
472 | } | |
473 | control = new wxListBox(parent, id, pos, size, | |
474 | noStrings, strings, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); | |
475 | ||
476 | if (strings) | |
477 | delete[] strings; | |
478 | } | |
479 | else if (itemType == wxString(wxT("wxChoice"))) | |
480 | { | |
481 | wxStringList& stringList = childResource->GetStringValues(); | |
482 | wxString *strings = (wxString *) NULL; | |
483 | int noStrings = 0; | |
484 | if (stringList.GetCount() > 0) | |
485 | { | |
486 | noStrings = stringList.GetCount(); | |
487 | strings = new wxString[noStrings]; | |
488 | wxStringListNode *node = stringList.GetFirst(); | |
489 | int i = 0; | |
490 | while (node) | |
491 | { | |
492 | strings[i] = (wxChar *)node->GetData(); | |
493 | i ++; | |
494 | node = node->GetNext(); | |
495 | } | |
496 | } | |
497 | control = new wxChoice(parent, id, pos, size, | |
498 | noStrings, strings, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); | |
499 | ||
500 | if (strings) | |
501 | delete[] strings; | |
502 | } | |
503 | #if wxUSE_COMBOBOX | |
504 | else if (itemType == wxString(wxT("wxComboBox"))) | |
505 | { | |
506 | wxStringList& stringList = childResource->GetStringValues(); | |
507 | wxString *strings = (wxString *) NULL; | |
508 | int noStrings = 0; | |
509 | if (stringList.GetCount() > 0) | |
510 | { | |
511 | noStrings = stringList.GetCount(); | |
512 | strings = new wxString[noStrings]; | |
513 | wxStringListNode *node = stringList.GetFirst(); | |
514 | int i = 0; | |
515 | while (node) | |
516 | { | |
517 | strings[i] = (wxChar *)node->GetData(); | |
518 | i ++; | |
519 | node = node->GetNext(); | |
520 | } | |
521 | } | |
522 | control = new wxComboBox(parent, id, childResource->GetValue4(), pos, size, | |
523 | noStrings, strings, childResource->GetStyle(), wxDefaultValidator, childResource->GetName()); | |
524 | ||
525 | if (strings) | |
526 | delete[] strings; | |
527 | } | |
528 | #endif | |
529 | else if (itemType == wxString(wxT("wxRadioBox"))) | |
530 | { | |
531 | wxStringList& stringList = childResource->GetStringValues(); | |
532 | wxString *strings = (wxString *) NULL; | |
533 | int noStrings = 0; | |
534 | if (stringList.GetCount() > 0) | |
535 | { | |
536 | noStrings = stringList.GetCount(); | |
537 | strings = new wxString[noStrings]; | |
538 | wxStringListNode *node = stringList.GetFirst(); | |
539 | int i = 0; | |
540 | while (node) | |
541 | { | |
542 | strings[i] = (wxChar *)node->GetData(); | |
543 | i ++; | |
544 | node = node->GetNext(); | |
545 | } | |
546 | } | |
547 | control = new wxRadioBox(parent, (wxWindowID) id, wxString(childResource->GetTitle()), pos, size, | |
548 | noStrings, strings, (int)childResource->GetValue1(), childResource->GetStyle(), wxDefaultValidator, | |
549 | childResource->GetName()); | |
550 | ||
551 | if (strings) | |
552 | delete[] strings; | |
553 | } | |
554 | ||
555 | if ((parentResource->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS) != 0) | |
556 | { | |
557 | // Don't set font; will be inherited from parent. | |
558 | } | |
559 | else | |
560 | { | |
561 | if (control && childResource->GetFont().Ok()) | |
562 | { | |
563 | control->SetFont(childResource->GetFont()); | |
564 | ||
565 | #ifdef __WXMSW__ | |
566 | // Force the layout algorithm since the size changes the layout | |
567 | if (control->IsKindOf(CLASSINFO(wxRadioBox))) | |
568 | { | |
569 | control->SetSize(wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, wxDefaultCoord, wxSIZE_AUTO_WIDTH|wxSIZE_AUTO_HEIGHT); | |
570 | } | |
571 | #endif | |
572 | } | |
573 | } | |
574 | return control; | |
575 | } | |
576 | ||
577 | /* | |
578 | * Interpret database as a series of resources | |
579 | */ | |
580 | ||
581 | bool wxResourceInterpretResources(wxResourceTable& table, wxExprDatabase& db) | |
582 | { | |
583 | wxNode *node = db.GetFirst(); | |
584 | while (node) | |
585 | { | |
586 | wxExpr *clause = (wxExpr *)node->GetData(); | |
587 | wxString functor(clause->Functor()); | |
588 | ||
589 | wxItemResource *item = (wxItemResource *) NULL; | |
590 | if (functor == wxT("dialog")) | |
591 | item = wxResourceInterpretDialog(table, clause); | |
592 | else if (functor == wxT("panel")) | |
593 | item = wxResourceInterpretDialog(table, clause, true); | |
594 | else if (functor == wxT("menubar")) | |
595 | item = wxResourceInterpretMenuBar(table, clause); | |
596 | else if (functor == wxT("menu")) | |
597 | item = wxResourceInterpretMenu(table, clause); | |
598 | else if (functor == wxT("string")) | |
599 | item = wxResourceInterpretString(table, clause); | |
600 | else if (functor == wxT("bitmap")) | |
601 | item = wxResourceInterpretBitmap(table, clause); | |
602 | else if (functor == wxT("icon")) | |
603 | item = wxResourceInterpretIcon(table, clause); | |
604 | ||
605 | if (item) | |
606 | { | |
607 | // Remove any existing resource of same name | |
608 | if (!item->GetName().empty()) | |
609 | table.DeleteResource(item->GetName()); | |
610 | table.AddResource(item); | |
611 | } | |
612 | node = node->GetNext(); | |
613 | } | |
614 | return true; | |
615 | } | |
616 | ||
617 | static const wxChar *g_ValidControlClasses[] = | |
618 | { | |
619 | wxT("wxButton"), | |
620 | wxT("wxBitmapButton"), | |
621 | wxT("wxMessage"), | |
622 | wxT("wxStaticText"), | |
623 | wxT("wxStaticBitmap"), | |
624 | wxT("wxText"), | |
625 | wxT("wxTextCtrl"), | |
626 | wxT("wxMultiText"), | |
627 | wxT("wxListBox"), | |
628 | wxT("wxRadioBox"), | |
629 | wxT("wxRadioButton"), | |
630 | wxT("wxCheckBox"), | |
631 | wxT("wxBitmapCheckBox"), | |
632 | wxT("wxGroupBox"), | |
633 | wxT("wxStaticBox"), | |
634 | wxT("wxSlider"), | |
635 | wxT("wxGauge"), | |
636 | wxT("wxScrollBar"), | |
637 | wxT("wxChoice"), | |
638 | wxT("wxComboBox") | |
639 | }; | |
640 | ||
641 | static bool wxIsValidControlClass(const wxString& c) | |
642 | { | |
643 | for ( size_t i = 0; i < WXSIZEOF(g_ValidControlClasses); i++ ) | |
644 | { | |
645 | if ( c == g_ValidControlClasses[i] ) | |
646 | return true; | |
647 | } | |
648 | return false; | |
649 | } | |
650 | ||
651 | wxItemResource *wxResourceInterpretDialog(wxResourceTable& table, wxExpr *expr, bool isPanel) | |
652 | { | |
653 | wxItemResource *dialogItem = new wxItemResource; | |
654 | if (isPanel) | |
655 | dialogItem->SetType(wxT("wxPanel")); | |
656 | else | |
657 | dialogItem->SetType(wxT("wxDialog")); | |
658 | wxString style = wxEmptyString; | |
659 | wxString title = wxEmptyString; | |
660 | wxString name = wxEmptyString; | |
661 | wxString backColourHex = wxEmptyString; | |
662 | wxString labelColourHex = wxEmptyString; | |
663 | wxString buttonColourHex = wxEmptyString; | |
664 | ||
665 | long windowStyle = wxDEFAULT_DIALOG_STYLE; | |
666 | if (isPanel) | |
667 | windowStyle = 0; | |
668 | ||
669 | int x = 0; int y = 0; int width = wxDefaultCoord; int height = wxDefaultCoord; | |
670 | int isModal = 0; | |
671 | wxExpr *labelFontExpr = (wxExpr *) NULL; | |
672 | wxExpr *buttonFontExpr = (wxExpr *) NULL; | |
673 | wxExpr *fontExpr = (wxExpr *) NULL; | |
674 | expr->GetAttributeValue(wxT("style"), style); | |
675 | expr->GetAttributeValue(wxT("name"), name); | |
676 | expr->GetAttributeValue(wxT("title"), title); | |
677 | expr->GetAttributeValue(wxT("x"), x); | |
678 | expr->GetAttributeValue(wxT("y"), y); | |
679 | expr->GetAttributeValue(wxT("width"), width); | |
680 | expr->GetAttributeValue(wxT("height"), height); | |
681 | expr->GetAttributeValue(wxT("modal"), isModal); | |
682 | expr->GetAttributeValue(wxT("label_font"), &labelFontExpr); | |
683 | expr->GetAttributeValue(wxT("button_font"), &buttonFontExpr); | |
684 | expr->GetAttributeValue(wxT("font"), &fontExpr); | |
685 | expr->GetAttributeValue(wxT("background_colour"), backColourHex); | |
686 | expr->GetAttributeValue(wxT("label_colour"), labelColourHex); | |
687 | expr->GetAttributeValue(wxT("button_colour"), buttonColourHex); | |
688 | ||
689 | int useDialogUnits = 0; | |
690 | expr->GetAttributeValue(wxT("use_dialog_units"), useDialogUnits); | |
691 | if (useDialogUnits != 0) | |
692 | dialogItem->SetResourceStyle(dialogItem->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS); | |
693 | ||
694 | int useDefaults = 0; | |
695 | expr->GetAttributeValue(wxT("use_system_defaults"), useDefaults); | |
696 | if (useDefaults != 0) | |
697 | dialogItem->SetResourceStyle(dialogItem->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS); | |
698 | ||
699 | int id = 0; | |
700 | expr->GetAttributeValue(wxT("id"), id); | |
701 | dialogItem->SetId(id); | |
702 | ||
703 | if (!style.empty()) | |
704 | { | |
705 | windowStyle = wxParseWindowStyle(style); | |
706 | } | |
707 | dialogItem->SetStyle(windowStyle); | |
708 | dialogItem->SetValue1(isModal); | |
709 | ||
710 | #if WXWIN_COMPATIBILITY_2_6 | |
711 | ||
712 | #ifdef __VMS | |
713 | #pragma message disable CODCAUUNR | |
714 | #endif | |
715 | if (windowStyle & wxDIALOG_MODAL) // Uses style in wxWin 2 | |
716 | dialogItem->SetValue1(true); | |
717 | #ifdef __VMS | |
718 | #pragma message enable CODCAUUNR | |
719 | #endif | |
720 | ||
721 | #endif // WXWIN_COMPATIBILITY_2_6 | |
722 | ||
723 | dialogItem->SetName(name); | |
724 | dialogItem->SetTitle(title); | |
725 | dialogItem->SetSize(x, y, width, height); | |
726 | ||
727 | // Check for wxWin 1.68-style specifications | |
728 | if (style.Find(wxT("VERTICAL_LABEL")) != wxNOT_FOUND) | |
729 | dialogItem->SetResourceStyle(dialogItem->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL); | |
730 | else if (style.Find(wxT("HORIZONTAL_LABEL")) != wxNOT_FOUND) | |
731 | dialogItem->SetResourceStyle(dialogItem->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL); | |
732 | ||
733 | if (!backColourHex.empty()) | |
734 | { | |
735 | int r = 0; | |
736 | int g = 0; | |
737 | int b = 0; | |
738 | r = wxHexToDec(backColourHex.Mid(0, 2)); | |
739 | g = wxHexToDec(backColourHex.Mid(2, 2)); | |
740 | b = wxHexToDec(backColourHex.Mid(4, 2)); | |
741 | dialogItem->SetBackgroundColour(wxColour((unsigned char)r,(unsigned char)g,(unsigned char)b)); | |
742 | } | |
743 | if (!labelColourHex.empty()) | |
744 | { | |
745 | int r = 0; | |
746 | int g = 0; | |
747 | int b = 0; | |
748 | r = wxHexToDec(labelColourHex.Mid(0, 2)); | |
749 | g = wxHexToDec(labelColourHex.Mid(2, 2)); | |
750 | b = wxHexToDec(labelColourHex.Mid(4, 2)); | |
751 | dialogItem->SetLabelColour(wxColour((unsigned char)r,(unsigned char)g,(unsigned char)b)); | |
752 | } | |
753 | if (!buttonColourHex.empty()) | |
754 | { | |
755 | int r = 0; | |
756 | int g = 0; | |
757 | int b = 0; | |
758 | r = wxHexToDec(buttonColourHex.Mid(0, 2)); | |
759 | g = wxHexToDec(buttonColourHex.Mid(2, 2)); | |
760 | b = wxHexToDec(buttonColourHex.Mid(4, 2)); | |
761 | dialogItem->SetButtonColour(wxColour((unsigned char)r,(unsigned char)g,(unsigned char)b)); | |
762 | } | |
763 | ||
764 | if (fontExpr) | |
765 | dialogItem->SetFont(wxResourceInterpretFontSpec(fontExpr)); | |
766 | else if (buttonFontExpr) | |
767 | dialogItem->SetFont(wxResourceInterpretFontSpec(buttonFontExpr)); | |
768 | else if (labelFontExpr) | |
769 | dialogItem->SetFont(wxResourceInterpretFontSpec(labelFontExpr)); | |
770 | ||
771 | // Now parse all controls | |
772 | wxExpr *controlExpr = expr->GetFirst(); | |
773 | while (controlExpr) | |
774 | { | |
775 | if (controlExpr->Number() == 3) | |
776 | { | |
777 | wxString controlKeyword(controlExpr->Nth(1)->StringValue()); | |
778 | if (!controlKeyword.empty() && controlKeyword == wxT("control")) | |
779 | { | |
780 | // The value part: always a list. | |
781 | wxExpr *listExpr = controlExpr->Nth(2); | |
782 | if (listExpr->Type() == PrologList) | |
783 | { | |
784 | wxItemResource *controlItem = wxResourceInterpretControl(table, listExpr); | |
785 | if (controlItem) | |
786 | { | |
787 | dialogItem->GetChildren().Append(controlItem); | |
788 | } | |
789 | } | |
790 | } | |
791 | } | |
792 | controlExpr = controlExpr->GetNext(); | |
793 | } | |
794 | return dialogItem; | |
795 | } | |
796 | ||
797 | wxItemResource *wxResourceInterpretControl(wxResourceTable& table, wxExpr *expr) | |
798 | { | |
799 | wxItemResource *controlItem = new wxItemResource; | |
800 | ||
801 | // First, find the standard features of a control definition: | |
802 | // [optional integer/string id], control name, title, style, name, x, y, width, height | |
803 | ||
804 | wxString controlType; | |
805 | wxString style; | |
806 | wxString title; | |
807 | wxString name; | |
808 | int id = 0; | |
809 | long windowStyle = 0; | |
810 | int x = 0; int y = 0; int width = wxDefaultCoord; int height = wxDefaultCoord; | |
811 | int count = 0; | |
812 | ||
813 | wxExpr *expr1 = expr->Nth(0); | |
814 | ||
815 | if ( expr1->Type() == PrologString || expr1->Type() == PrologWord ) | |
816 | { | |
817 | if ( wxIsValidControlClass(expr1->StringValue()) ) | |
818 | { | |
819 | count = 1; | |
820 | controlType = expr1->StringValue(); | |
821 | } | |
822 | else | |
823 | { | |
824 | wxString str(expr1->StringValue()); | |
825 | id = wxResourceGetIdentifier(str, &table); | |
826 | if (id == 0) | |
827 | { | |
828 | wxLogWarning(_("Could not resolve control class or id '%s'. Use (non-zero) integer instead\n or provide #define (see manual for caveats)"), | |
829 | (const wxChar*) expr1->StringValue()); | |
830 | delete controlItem; | |
831 | return (wxItemResource *) NULL; | |
832 | } | |
833 | else | |
834 | { | |
835 | // Success - we have an id, so the 2nd element must be the control class. | |
836 | controlType = expr->Nth(1)->StringValue(); | |
837 | count = 2; | |
838 | } | |
839 | } | |
840 | } | |
841 | else if (expr1->Type() == PrologInteger) | |
842 | { | |
843 | id = (int)expr1->IntegerValue(); | |
844 | // Success - we have an id, so the 2nd element must be the control class. | |
845 | controlType = expr->Nth(1)->StringValue(); | |
846 | count = 2; | |
847 | } | |
848 | ||
849 | expr1 = expr->Nth(count); | |
850 | count ++; | |
851 | if ( expr1 ) | |
852 | title = expr1->StringValue(); | |
853 | ||
854 | expr1 = expr->Nth(count); | |
855 | count ++; | |
856 | if (expr1) | |
857 | { | |
858 | style = expr1->StringValue(); | |
859 | windowStyle = wxParseWindowStyle(style); | |
860 | } | |
861 | ||
862 | expr1 = expr->Nth(count); | |
863 | count ++; | |
864 | if (expr1) | |
865 | name = expr1->StringValue(); | |
866 | ||
867 | expr1 = expr->Nth(count); | |
868 | count ++; | |
869 | if (expr1) | |
870 | x = (int)expr1->IntegerValue(); | |
871 | ||
872 | expr1 = expr->Nth(count); | |
873 | count ++; | |
874 | if (expr1) | |
875 | y = (int)expr1->IntegerValue(); | |
876 | ||
877 | expr1 = expr->Nth(count); | |
878 | count ++; | |
879 | if (expr1) | |
880 | width = (int)expr1->IntegerValue(); | |
881 | ||
882 | expr1 = expr->Nth(count); | |
883 | count ++; | |
884 | if (expr1) | |
885 | height = (int)expr1->IntegerValue(); | |
886 | ||
887 | controlItem->SetStyle(windowStyle); | |
888 | controlItem->SetName(name); | |
889 | controlItem->SetTitle(title); | |
890 | controlItem->SetSize(x, y, width, height); | |
891 | controlItem->SetType(controlType); | |
892 | controlItem->SetId(id); | |
893 | ||
894 | // Check for wxWin 1.68-style specifications | |
895 | if (style.Find(wxT("VERTICAL_LABEL")) != wxNOT_FOUND) | |
896 | controlItem->SetResourceStyle(controlItem->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL); | |
897 | else if (style.Find(wxT("HORIZONTAL_LABEL")) != wxNOT_FOUND) | |
898 | controlItem->SetResourceStyle(controlItem->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL); | |
899 | ||
900 | if (controlType == wxT("wxButton")) | |
901 | { | |
902 | // Check for bitmap resource name (in case loading old-style resource file) | |
903 | if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord))) | |
904 | { | |
905 | wxString str(expr->Nth(count)->StringValue()); | |
906 | count ++; | |
907 | ||
908 | if (!str.empty()) | |
909 | { | |
910 | controlItem->SetValue4(str); | |
911 | controlItem->SetType(wxT("wxBitmapButton")); | |
912 | } | |
913 | } | |
914 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) | |
915 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); | |
916 | } | |
917 | else if (controlType == wxT("wxBitmapButton")) | |
918 | { | |
919 | // Check for bitmap resource name | |
920 | if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord))) | |
921 | { | |
922 | wxString str(expr->Nth(count)->StringValue()); | |
923 | controlItem->SetValue4(str); | |
924 | count ++; | |
925 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) | |
926 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); | |
927 | } | |
928 | } | |
929 | else if (controlType == wxT("wxCheckBox")) | |
930 | { | |
931 | // Check for default value | |
932 | if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) | |
933 | { | |
934 | controlItem->SetValue1(expr->Nth(count)->IntegerValue()); | |
935 | count ++; | |
936 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) | |
937 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); | |
938 | } | |
939 | } | |
940 | #if wxUSE_RADIOBTN | |
941 | else if (controlType == wxT("wxRadioButton")) | |
942 | { | |
943 | // Check for default value | |
944 | if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) | |
945 | { | |
946 | controlItem->SetValue1(expr->Nth(count)->IntegerValue()); | |
947 | count ++; | |
948 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) | |
949 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); | |
950 | } | |
951 | } | |
952 | #endif | |
953 | else if (controlType == wxT("wxText") || controlType == wxT("wxTextCtrl") || controlType == wxT("wxMultiText")) | |
954 | { | |
955 | // Check for default value | |
956 | if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord))) | |
957 | { | |
958 | wxString str(expr->Nth(count)->StringValue()); | |
959 | controlItem->SetValue4(str); | |
960 | count ++; | |
961 | ||
962 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) | |
963 | { | |
964 | // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count))); | |
965 | // Skip past the obsolete label font spec if there are two consecutive specs | |
966 | if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList) | |
967 | count ++; | |
968 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); | |
969 | } | |
970 | } | |
971 | } | |
972 | else if (controlType == wxT("wxMessage") || controlType == wxT("wxStaticText")) | |
973 | { | |
974 | // Check for bitmap resource name (in case it's an old-style .wxr file) | |
975 | if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord))) | |
976 | { | |
977 | wxString str(expr->Nth(count)->StringValue()); | |
978 | controlItem->SetValue4(str); | |
979 | count ++; | |
980 | controlItem->SetType(wxT("wxStaticText")); | |
981 | } | |
982 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) | |
983 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); | |
984 | } | |
985 | else if (controlType == wxT("wxStaticBitmap")) | |
986 | { | |
987 | // Check for bitmap resource name | |
988 | if (expr->Nth(count) && ((expr->Nth(count)->Type() == PrologString) || (expr->Nth(count)->Type() == PrologWord))) | |
989 | { | |
990 | wxString str(expr->Nth(count)->StringValue()); | |
991 | controlItem->SetValue4(str); | |
992 | count ++; | |
993 | } | |
994 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) | |
995 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); | |
996 | } | |
997 | else if (controlType == wxT("wxGroupBox") || controlType == wxT("wxStaticBox")) | |
998 | { | |
999 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) | |
1000 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); | |
1001 | } | |
1002 | else if (controlType == wxT("wxGauge")) | |
1003 | { | |
1004 | // Check for default value | |
1005 | if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) | |
1006 | { | |
1007 | controlItem->SetValue1(expr->Nth(count)->IntegerValue()); | |
1008 | count ++; | |
1009 | ||
1010 | // Check for range | |
1011 | if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) | |
1012 | { | |
1013 | controlItem->SetValue2(expr->Nth(count)->IntegerValue()); | |
1014 | count ++; | |
1015 | ||
1016 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) | |
1017 | { | |
1018 | // Skip past the obsolete label font spec if there are two consecutive specs | |
1019 | if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList) | |
1020 | count ++; | |
1021 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); | |
1022 | } | |
1023 | } | |
1024 | } | |
1025 | } | |
1026 | else if (controlType == wxT("wxSlider")) | |
1027 | { | |
1028 | // Check for default value | |
1029 | if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) | |
1030 | { | |
1031 | controlItem->SetValue1(expr->Nth(count)->IntegerValue()); | |
1032 | count ++; | |
1033 | ||
1034 | // Check for min | |
1035 | if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) | |
1036 | { | |
1037 | controlItem->SetValue2(expr->Nth(count)->IntegerValue()); | |
1038 | count ++; | |
1039 | ||
1040 | // Check for max | |
1041 | if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) | |
1042 | { | |
1043 | controlItem->SetValue3(expr->Nth(count)->IntegerValue()); | |
1044 | count ++; | |
1045 | ||
1046 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) | |
1047 | { | |
1048 | // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count))); | |
1049 | // do nothing | |
1050 | count ++; | |
1051 | ||
1052 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) | |
1053 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); | |
1054 | } | |
1055 | } | |
1056 | } | |
1057 | } | |
1058 | } | |
1059 | else if (controlType == wxT("wxScrollBar")) | |
1060 | { | |
1061 | // DEFAULT VALUE | |
1062 | if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) | |
1063 | { | |
1064 | controlItem->SetValue1(expr->Nth(count)->IntegerValue()); | |
1065 | count ++; | |
1066 | ||
1067 | // PAGE LENGTH | |
1068 | if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) | |
1069 | { | |
1070 | controlItem->SetValue2(expr->Nth(count)->IntegerValue()); | |
1071 | count ++; | |
1072 | ||
1073 | // OBJECT LENGTH | |
1074 | if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) | |
1075 | { | |
1076 | controlItem->SetValue3(expr->Nth(count)->IntegerValue()); | |
1077 | count ++; | |
1078 | ||
1079 | // VIEW LENGTH | |
1080 | if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) | |
1081 | controlItem->SetValue5(expr->Nth(count)->IntegerValue()); | |
1082 | } | |
1083 | } | |
1084 | } | |
1085 | } | |
1086 | else if (controlType == wxT("wxListBox")) | |
1087 | { | |
1088 | wxExpr *valueList = (wxExpr *) NULL; | |
1089 | ||
1090 | if (((valueList = expr->Nth(count)) != 0) && (valueList->Type() == PrologList)) | |
1091 | { | |
1092 | wxStringList stringList; | |
1093 | wxExpr *stringExpr = valueList->GetFirst(); | |
1094 | while (stringExpr) | |
1095 | { | |
1096 | stringList.Add(stringExpr->StringValue()); | |
1097 | stringExpr = stringExpr->GetNext(); | |
1098 | } | |
1099 | controlItem->SetStringValues(stringList); | |
1100 | count ++; | |
1101 | // This is now obsolete: it's in the window style. | |
1102 | // Check for wxSINGLE/wxMULTIPLE | |
1103 | wxExpr *mult = (wxExpr *) NULL; | |
1104 | /* | |
1105 | controlItem->SetValue1(wxLB_SINGLE); | |
1106 | */ | |
1107 | if (((mult = expr->Nth(count)) != 0) && ((mult->Type() == PrologString)||(mult->Type() == PrologWord))) | |
1108 | { | |
1109 | /* | |
1110 | wxString m(mult->StringValue()); | |
1111 | if (m == "wxLB_MULTIPLE") | |
1112 | controlItem->SetValue1(wxLB_MULTIPLE); | |
1113 | else if (m == "wxLB_EXTENDED") | |
1114 | controlItem->SetValue1(wxLB_EXTENDED); | |
1115 | */ | |
1116 | // Ignore the value | |
1117 | count ++; | |
1118 | } | |
1119 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) | |
1120 | { | |
1121 | // Skip past the obsolete label font spec if there are two consecutive specs | |
1122 | if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList) | |
1123 | count ++; | |
1124 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); | |
1125 | } | |
1126 | } | |
1127 | } | |
1128 | else if (controlType == wxT("wxChoice")) | |
1129 | { | |
1130 | wxExpr *valueList = (wxExpr *) NULL; | |
1131 | // Check for default value list | |
1132 | if (((valueList = expr->Nth(count)) != 0) && (valueList->Type() == PrologList)) | |
1133 | { | |
1134 | wxStringList stringList; | |
1135 | wxExpr *stringExpr = valueList->GetFirst(); | |
1136 | while (stringExpr) | |
1137 | { | |
1138 | stringList.Add(stringExpr->StringValue()); | |
1139 | stringExpr = stringExpr->GetNext(); | |
1140 | } | |
1141 | controlItem->SetStringValues(stringList); | |
1142 | ||
1143 | count ++; | |
1144 | ||
1145 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) | |
1146 | { | |
1147 | // Skip past the obsolete label font spec if there are two consecutive specs | |
1148 | if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList) | |
1149 | count ++; | |
1150 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); | |
1151 | } | |
1152 | } | |
1153 | } | |
1154 | #if wxUSE_COMBOBOX | |
1155 | else if (controlType == wxT("wxComboBox")) | |
1156 | { | |
1157 | wxExpr *textValue = expr->Nth(count); | |
1158 | if (textValue && (textValue->Type() == PrologString || textValue->Type() == PrologWord)) | |
1159 | { | |
1160 | wxString str(textValue->StringValue()); | |
1161 | controlItem->SetValue4(str); | |
1162 | ||
1163 | count ++; | |
1164 | ||
1165 | wxExpr *valueList = (wxExpr *) NULL; | |
1166 | // Check for default value list | |
1167 | if (((valueList = expr->Nth(count)) != 0) && (valueList->Type() == PrologList)) | |
1168 | { | |
1169 | wxStringList stringList; | |
1170 | wxExpr *stringExpr = valueList->GetFirst(); | |
1171 | while (stringExpr) | |
1172 | { | |
1173 | stringList.Add(stringExpr->StringValue()); | |
1174 | stringExpr = stringExpr->GetNext(); | |
1175 | } | |
1176 | controlItem->SetStringValues(stringList); | |
1177 | ||
1178 | count ++; | |
1179 | ||
1180 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) | |
1181 | { | |
1182 | // Skip past the obsolete label font spec if there are two consecutive specs | |
1183 | if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList) | |
1184 | count ++; | |
1185 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); | |
1186 | } | |
1187 | } | |
1188 | } | |
1189 | } | |
1190 | #endif | |
1191 | #if 1 | |
1192 | else if (controlType == wxT("wxRadioBox")) | |
1193 | { | |
1194 | wxExpr *valueList = (wxExpr *) NULL; | |
1195 | // Check for default value list | |
1196 | if (((valueList = expr->Nth(count)) != 0) && (valueList->Type() == PrologList)) | |
1197 | { | |
1198 | wxStringList stringList; | |
1199 | wxExpr *stringExpr = valueList->GetFirst(); | |
1200 | while (stringExpr) | |
1201 | { | |
1202 | stringList.Add(stringExpr->StringValue()); | |
1203 | stringExpr = stringExpr->GetNext(); | |
1204 | } | |
1205 | controlItem->SetStringValues(stringList); | |
1206 | count ++; | |
1207 | ||
1208 | // majorDim (number of rows or cols) | |
1209 | if (expr->Nth(count) && (expr->Nth(count)->Type() == PrologInteger)) | |
1210 | { | |
1211 | controlItem->SetValue1(expr->Nth(count)->IntegerValue()); | |
1212 | count ++; | |
1213 | } | |
1214 | else | |
1215 | controlItem->SetValue1(0); | |
1216 | ||
1217 | if (expr->Nth(count) && expr->Nth(count)->Type() == PrologList) | |
1218 | { | |
1219 | // Skip past the obsolete label font spec if there are two consecutive specs | |
1220 | if (expr->Nth(count+1) && expr->Nth(count+1)->Type() == PrologList) | |
1221 | count ++; | |
1222 | controlItem->SetFont(wxResourceInterpretFontSpec(expr->Nth(count))); | |
1223 | } | |
1224 | } | |
1225 | } | |
1226 | #endif | |
1227 | else | |
1228 | { | |
1229 | delete controlItem; | |
1230 | return (wxItemResource *) NULL; | |
1231 | } | |
1232 | return controlItem; | |
1233 | } | |
1234 | ||
1235 | // Forward declaration | |
1236 | wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr); | |
1237 | ||
1238 | /* | |
1239 | * Interpet a menu item | |
1240 | */ | |
1241 | ||
1242 | wxItemResource *wxResourceInterpretMenuItem(wxResourceTable& table, wxExpr *expr) | |
1243 | { | |
1244 | wxItemResource *item = new wxItemResource; | |
1245 | ||
1246 | wxExpr *labelExpr = expr->Nth(0); | |
1247 | wxExpr *idExpr = expr->Nth(1); | |
1248 | wxExpr *helpExpr = expr->Nth(2); | |
1249 | wxExpr *checkableExpr = expr->Nth(3); | |
1250 | ||
1251 | // Further keywords/attributes to follow sometime... | |
1252 | if (expr->Number() == 0) | |
1253 | { | |
1254 | // item->SetType(wxRESOURCE_TYPE_SEPARATOR); | |
1255 | item->SetType(wxT("wxMenuSeparator")); | |
1256 | return item; | |
1257 | } | |
1258 | else | |
1259 | { | |
1260 | // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter. | |
1261 | item->SetType(wxT("wxMenu")); // Well, menu item, but doesn't matter. | |
1262 | if (labelExpr) | |
1263 | { | |
1264 | wxString str(labelExpr->StringValue()); | |
1265 | item->SetTitle(str); | |
1266 | } | |
1267 | if (idExpr) | |
1268 | { | |
1269 | int id = 0; | |
1270 | // If a string or word, must look up in identifier table. | |
1271 | if ((idExpr->Type() == PrologString) || (idExpr->Type() == PrologWord)) | |
1272 | { | |
1273 | wxString str(idExpr->StringValue()); | |
1274 | id = wxResourceGetIdentifier(str, &table); | |
1275 | if (id == 0) | |
1276 | { | |
1277 | wxLogWarning(_("Could not resolve menu id '%s'. Use (non-zero) integer instead\nor provide #define (see manual for caveats)"), | |
1278 | (const wxChar*) idExpr->StringValue()); | |
1279 | } | |
1280 | } | |
1281 | else if (idExpr->Type() == PrologInteger) | |
1282 | id = (int)idExpr->IntegerValue(); | |
1283 | item->SetValue1(id); | |
1284 | } | |
1285 | if (helpExpr) | |
1286 | { | |
1287 | wxString str(helpExpr->StringValue()); | |
1288 | item->SetValue4(str); | |
1289 | } | |
1290 | if (checkableExpr) | |
1291 | item->SetValue2(checkableExpr->IntegerValue()); | |
1292 | ||
1293 | // Find the first expression that's a list, for submenu | |
1294 | wxExpr *subMenuExpr = expr->GetFirst(); | |
1295 | while (subMenuExpr && (subMenuExpr->Type() != PrologList)) | |
1296 | subMenuExpr = subMenuExpr->GetNext(); | |
1297 | ||
1298 | while (subMenuExpr) | |
1299 | { | |
1300 | wxItemResource *child = wxResourceInterpretMenuItem(table, subMenuExpr); | |
1301 | item->GetChildren().Append(child); | |
1302 | subMenuExpr = subMenuExpr->GetNext(); | |
1303 | } | |
1304 | } | |
1305 | return item; | |
1306 | } | |
1307 | ||
1308 | /* | |
1309 | * Interpret a nested list as a menu | |
1310 | */ | |
1311 | /* | |
1312 | wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr) | |
1313 | { | |
1314 | wxItemResource *menu = new wxItemResource; | |
1315 | // menu->SetType(wxTYPE_MENU); | |
1316 | menu->SetType("wxMenu"); | |
1317 | wxExpr *element = expr->GetFirst(); | |
1318 | while (element) | |
1319 | { | |
1320 | wxItemResource *item = wxResourceInterpretMenuItem(table, element); | |
1321 | if (item) | |
1322 | menu->GetChildren().Append(item); | |
1323 | element = element->GetNext(); | |
1324 | } | |
1325 | return menu; | |
1326 | } | |
1327 | */ | |
1328 | ||
1329 | wxItemResource *wxResourceInterpretMenu(wxResourceTable& table, wxExpr *expr) | |
1330 | { | |
1331 | wxExpr *listExpr = (wxExpr *) NULL; | |
1332 | expr->GetAttributeValue(wxT("menu"), &listExpr); | |
1333 | if (!listExpr) | |
1334 | return (wxItemResource *) NULL; | |
1335 | ||
1336 | wxItemResource *menuResource = wxResourceInterpretMenuItem(table, listExpr); | |
1337 | ||
1338 | if (!menuResource) | |
1339 | return (wxItemResource *) NULL; | |
1340 | ||
1341 | wxString name; | |
1342 | if (expr->GetAttributeValue(wxT("name"), name)) | |
1343 | { | |
1344 | menuResource->SetName(name); | |
1345 | } | |
1346 | ||
1347 | return menuResource; | |
1348 | } | |
1349 | ||
1350 | wxItemResource *wxResourceInterpretMenuBar(wxResourceTable& table, wxExpr *expr) | |
1351 | { | |
1352 | wxExpr *listExpr = (wxExpr *) NULL; | |
1353 | expr->GetAttributeValue(wxT("menu"), &listExpr); | |
1354 | if (!listExpr) | |
1355 | return (wxItemResource *) NULL; | |
1356 | ||
1357 | wxItemResource *resource = new wxItemResource; | |
1358 | resource->SetType(wxT("wxMenu")); | |
1359 | // resource->SetType(wxTYPE_MENU); | |
1360 | ||
1361 | wxExpr *element = listExpr->GetFirst(); | |
1362 | while (element) | |
1363 | { | |
1364 | wxItemResource *menuResource = wxResourceInterpretMenuItem(table, listExpr); | |
1365 | resource->GetChildren().Append(menuResource); | |
1366 | element = element->GetNext(); | |
1367 | } | |
1368 | ||
1369 | wxString name; | |
1370 | if (expr->GetAttributeValue(wxT("name"), name)) | |
1371 | { | |
1372 | resource->SetName(name); | |
1373 | } | |
1374 | ||
1375 | return resource; | |
1376 | } | |
1377 | ||
1378 | wxItemResource *wxResourceInterpretString(wxResourceTable& WXUNUSED(table), wxExpr *WXUNUSED(expr)) | |
1379 | { | |
1380 | return (wxItemResource *) NULL; | |
1381 | } | |
1382 | ||
1383 | wxItemResource *wxResourceInterpretBitmap(wxResourceTable& WXUNUSED(table), wxExpr *expr) | |
1384 | { | |
1385 | wxItemResource *bitmapItem = new wxItemResource; | |
1386 | // bitmapItem->SetType(wxTYPE_BITMAP); | |
1387 | bitmapItem->SetType(wxT("wxBitmap")); | |
1388 | wxString name; | |
1389 | if (expr->GetAttributeValue(wxT("name"), name)) | |
1390 | { | |
1391 | bitmapItem->SetName(name); | |
1392 | } | |
1393 | // Now parse all bitmap specifications | |
1394 | wxExpr *bitmapExpr = expr->GetFirst(); | |
1395 | while (bitmapExpr) | |
1396 | { | |
1397 | if (bitmapExpr->Number() == 3) | |
1398 | { | |
1399 | wxString bitmapKeyword(bitmapExpr->Nth(1)->StringValue()); | |
1400 | if (bitmapKeyword == wxT("bitmap") || bitmapKeyword == wxT("icon")) | |
1401 | { | |
1402 | // The value part: always a list. | |
1403 | wxExpr *listExpr = bitmapExpr->Nth(2); | |
1404 | if (listExpr->Type() == PrologList) | |
1405 | { | |
1406 | wxItemResource *bitmapSpec = new wxItemResource; | |
1407 | // bitmapSpec->SetType(wxTYPE_BITMAP); | |
1408 | bitmapSpec->SetType(wxT("wxBitmap")); | |
1409 | ||
1410 | // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution] | |
1411 | // where everything after 'filename' is optional. | |
1412 | wxExpr *nameExpr = listExpr->Nth(0); | |
1413 | wxExpr *typeExpr = listExpr->Nth(1); | |
1414 | wxExpr *platformExpr = listExpr->Nth(2); | |
1415 | wxExpr *coloursExpr = listExpr->Nth(3); | |
1416 | wxExpr *xresExpr = listExpr->Nth(4); | |
1417 | wxExpr *yresExpr = listExpr->Nth(5); | |
1418 | if (nameExpr && !nameExpr->StringValue().empty()) | |
1419 | { | |
1420 | bitmapSpec->SetName(nameExpr->StringValue()); | |
1421 | } | |
1422 | if (typeExpr && !typeExpr->StringValue().empty()) | |
1423 | { | |
1424 | bitmapSpec->SetValue1(wxParseWindowStyle(typeExpr->StringValue())); | |
1425 | } | |
1426 | else | |
1427 | bitmapSpec->SetValue1(0); | |
1428 | ||
1429 | if (platformExpr && !platformExpr->StringValue().empty()) | |
1430 | { | |
1431 | wxString plat(platformExpr->StringValue()); | |
1432 | if (plat == wxT("windows") || plat == wxT("WINDOWS")) | |
1433 | bitmapSpec->SetValue2(RESOURCE_PLATFORM_WINDOWS); | |
1434 | else if (plat == wxT("x") || plat == wxT("X")) | |
1435 | bitmapSpec->SetValue2(RESOURCE_PLATFORM_X); | |
1436 | else if (plat == wxT("mac") || plat == wxT("MAC")) | |
1437 | bitmapSpec->SetValue2(RESOURCE_PLATFORM_MAC); | |
1438 | else | |
1439 | bitmapSpec->SetValue2(RESOURCE_PLATFORM_ANY); | |
1440 | } | |
1441 | else | |
1442 | bitmapSpec->SetValue2(RESOURCE_PLATFORM_ANY); | |
1443 | ||
1444 | if (coloursExpr) | |
1445 | bitmapSpec->SetValue3(coloursExpr->IntegerValue()); | |
1446 | int xres = 0; | |
1447 | int yres = 0; | |
1448 | if (xresExpr) | |
1449 | xres = (int)xresExpr->IntegerValue(); | |
1450 | if (yresExpr) | |
1451 | yres = (int)yresExpr->IntegerValue(); | |
1452 | bitmapSpec->SetSize(0, 0, xres, yres); | |
1453 | ||
1454 | bitmapItem->GetChildren().Append(bitmapSpec); | |
1455 | } | |
1456 | } | |
1457 | } | |
1458 | bitmapExpr = bitmapExpr->GetNext(); | |
1459 | } | |
1460 | ||
1461 | return bitmapItem; | |
1462 | } | |
1463 | ||
1464 | wxItemResource *wxResourceInterpretIcon(wxResourceTable& table, wxExpr *expr) | |
1465 | { | |
1466 | wxItemResource *item = wxResourceInterpretBitmap(table, expr); | |
1467 | if (item) | |
1468 | { | |
1469 | // item->SetType(wxTYPE_ICON); | |
1470 | item->SetType(wxT("wxIcon")); | |
1471 | return item; | |
1472 | } | |
1473 | else | |
1474 | return (wxItemResource *) NULL; | |
1475 | } | |
1476 | ||
1477 | // Interpret list expression as a font | |
1478 | wxFont wxResourceInterpretFontSpec(wxExpr *expr) | |
1479 | { | |
1480 | if (expr->Type() != PrologList) | |
1481 | return wxNullFont; | |
1482 | ||
1483 | int point = 10; | |
1484 | int family = wxSWISS; | |
1485 | int style = wxNORMAL; | |
1486 | int weight = wxNORMAL; | |
1487 | int underline = 0; | |
1488 | wxString faceName; | |
1489 | ||
1490 | wxExpr *pointExpr = expr->Nth(0); | |
1491 | wxExpr *familyExpr = expr->Nth(1); | |
1492 | wxExpr *styleExpr = expr->Nth(2); | |
1493 | wxExpr *weightExpr = expr->Nth(3); | |
1494 | wxExpr *underlineExpr = expr->Nth(4); | |
1495 | wxExpr *faceNameExpr = expr->Nth(5); | |
1496 | if (pointExpr) | |
1497 | point = (int)pointExpr->IntegerValue(); | |
1498 | ||
1499 | wxString str; | |
1500 | if (familyExpr) | |
1501 | { | |
1502 | str = familyExpr->StringValue(); | |
1503 | family = (int)wxParseWindowStyle(str); | |
1504 | } | |
1505 | if (styleExpr) | |
1506 | { | |
1507 | str = styleExpr->StringValue(); | |
1508 | style = (int)wxParseWindowStyle(str); | |
1509 | } | |
1510 | if (weightExpr) | |
1511 | { | |
1512 | str = weightExpr->StringValue(); | |
1513 | weight = (int)wxParseWindowStyle(str); | |
1514 | } | |
1515 | if (underlineExpr) | |
1516 | underline = (int)underlineExpr->IntegerValue(); | |
1517 | if (faceNameExpr) | |
1518 | faceName = faceNameExpr->StringValue(); | |
1519 | ||
1520 | return *wxTheFontList->FindOrCreateFont(point, family, style, weight, | |
1521 | (underline != 0), faceName); | |
1522 | } | |
1523 | ||
1524 | /* | |
1525 | * (Re)allocate buffer for reading in from resource file | |
1526 | */ | |
1527 | ||
1528 | bool wxReallocateResourceBuffer() | |
1529 | { | |
1530 | if (!wxResourceBuffer) | |
1531 | { | |
1532 | wxResourceBufferSize = 1000; | |
1533 | wxResourceBuffer = new char[wxResourceBufferSize]; | |
1534 | return true; | |
1535 | } | |
1536 | if (wxResourceBuffer) | |
1537 | { | |
1538 | long newSize = wxResourceBufferSize + 1000; | |
1539 | char *tmp = new char[(int)newSize]; | |
1540 | strncpy(tmp, wxResourceBuffer, (int)wxResourceBufferCount); | |
1541 | delete[] wxResourceBuffer; | |
1542 | wxResourceBuffer = tmp; | |
1543 | wxResourceBufferSize = newSize; | |
1544 | } | |
1545 | return true; | |
1546 | } | |
1547 | ||
1548 | static bool wxEatWhiteSpace(FILE *fd) | |
1549 | { | |
1550 | int ch; | |
1551 | ||
1552 | while ((ch = getc(fd)) != EOF) | |
1553 | { | |
1554 | switch (ch) | |
1555 | { | |
1556 | case ' ': | |
1557 | case 0x0a: | |
1558 | case 0x0d: | |
1559 | case 0x09: | |
1560 | break; | |
1561 | case '/': | |
1562 | { | |
1563 | int prev_ch = ch; | |
1564 | ch = getc(fd); | |
1565 | if (ch == EOF) | |
1566 | { | |
1567 | ungetc(prev_ch, fd); | |
1568 | return true; | |
1569 | } | |
1570 | ||
1571 | if (ch == '*') | |
1572 | { | |
1573 | // Eat C comment | |
1574 | prev_ch = 0; | |
1575 | while ((ch = getc(fd)) != EOF) | |
1576 | { | |
1577 | if (ch == '/' && prev_ch == '*') | |
1578 | break; | |
1579 | prev_ch = ch; | |
1580 | } | |
1581 | } | |
1582 | else if (ch == '/') | |
1583 | { | |
1584 | // Eat C++ comment | |
1585 | static char buffer[255]; | |
1586 | fgets(buffer, 255, fd); | |
1587 | } | |
1588 | else | |
1589 | { | |
1590 | ungetc(prev_ch, fd); | |
1591 | ungetc(ch, fd); | |
1592 | return true; | |
1593 | } | |
1594 | } | |
1595 | break; | |
1596 | default: | |
1597 | ungetc(ch, fd); | |
1598 | return true; | |
1599 | ||
1600 | } | |
1601 | } | |
1602 | return false; | |
1603 | } | |
1604 | static bool wxEatWhiteSpace(wxInputStream *is) | |
1605 | { | |
1606 | char ch = is->GetC() ; | |
1607 | if ((ch != ' ') && (ch != '/') && (ch != ' ') && (ch != 10) && (ch != 13) && (ch != 9)) | |
1608 | { | |
1609 | is->Ungetch(ch); | |
1610 | return true; | |
1611 | } | |
1612 | ||
1613 | // Eat whitespace | |
1614 | while (ch == ' ' || ch == 10 || ch == 13 || ch == 9) | |
1615 | ch = is->GetC(); | |
1616 | // Check for comment | |
1617 | if (ch == '/') | |
1618 | { | |
1619 | ch = is->GetC(); | |
1620 | if (ch == '*') | |
1621 | { | |
1622 | bool finished = false; | |
1623 | while (!finished) | |
1624 | { | |
1625 | ch = is->GetC(); | |
1626 | if (is->LastRead() == 0) | |
1627 | return false; | |
1628 | if (ch == '*') | |
1629 | { | |
1630 | int newCh = is->GetC(); | |
1631 | if (newCh == '/') | |
1632 | finished = true; | |
1633 | else | |
1634 | { | |
1635 | is->Ungetch(ch); | |
1636 | } | |
1637 | } | |
1638 | } | |
1639 | } | |
1640 | else // False alarm | |
1641 | return false; | |
1642 | } | |
1643 | else | |
1644 | is->Ungetch(ch); | |
1645 | return wxEatWhiteSpace(is); | |
1646 | } | |
1647 | ||
1648 | bool wxGetResourceToken(FILE *fd) | |
1649 | { | |
1650 | if (!wxResourceBuffer) | |
1651 | wxReallocateResourceBuffer(); | |
1652 | wxResourceBuffer[0] = 0; | |
1653 | wxEatWhiteSpace(fd); | |
1654 | ||
1655 | int ch = getc(fd); | |
1656 | if (ch == '"') | |
1657 | { | |
1658 | // Get string | |
1659 | wxResourceBufferCount = 0; | |
1660 | ch = getc(fd); | |
1661 | while (ch != '"') | |
1662 | { | |
1663 | int actualCh = ch; | |
1664 | if (ch == EOF) | |
1665 | { | |
1666 | wxResourceBuffer[wxResourceBufferCount] = 0; | |
1667 | return false; | |
1668 | } | |
1669 | // Escaped characters | |
1670 | else if (ch == '\\') | |
1671 | { | |
1672 | int newCh = getc(fd); | |
1673 | if (newCh == '"') | |
1674 | actualCh = '"'; | |
1675 | else if (newCh == 10) | |
1676 | actualCh = 10; | |
1677 | else | |
1678 | { | |
1679 | ungetc(newCh, fd); | |
1680 | } | |
1681 | } | |
1682 | ||
1683 | if (wxResourceBufferCount >= wxResourceBufferSize-1) | |
1684 | wxReallocateResourceBuffer(); | |
1685 | wxResourceBuffer[wxResourceBufferCount] = (char)actualCh; | |
1686 | wxResourceBufferCount ++; | |
1687 | ch = getc(fd); | |
1688 | } | |
1689 | wxResourceBuffer[wxResourceBufferCount] = 0; | |
1690 | } | |
1691 | else | |
1692 | { | |
1693 | wxResourceBufferCount = 0; | |
1694 | // Any other token | |
1695 | while (ch != ' ' && ch != EOF && ch != ' ' && ch != 13 && ch != 9 && ch != 10) | |
1696 | { | |
1697 | if (wxResourceBufferCount >= wxResourceBufferSize-1) | |
1698 | wxReallocateResourceBuffer(); | |
1699 | wxResourceBuffer[wxResourceBufferCount] = (char)ch; | |
1700 | wxResourceBufferCount ++; | |
1701 | ||
1702 | ch = getc(fd); | |
1703 | } | |
1704 | wxResourceBuffer[wxResourceBufferCount] = 0; | |
1705 | if (ch == EOF) | |
1706 | return false; | |
1707 | } | |
1708 | return true; | |
1709 | } | |
1710 | ||
1711 | bool wxGetResourceToken(wxInputStream *is) | |
1712 | { | |
1713 | if (!wxResourceBuffer) | |
1714 | wxReallocateResourceBuffer(); | |
1715 | wxResourceBuffer[0] = 0; | |
1716 | wxEatWhiteSpace(is); | |
1717 | ||
1718 | int ch = is->GetC() ; | |
1719 | if (ch == '"') | |
1720 | { | |
1721 | // Get string | |
1722 | wxResourceBufferCount = 0; | |
1723 | ch = is->GetC(); | |
1724 | while (ch != '"') | |
1725 | { | |
1726 | int actualCh = ch; | |
1727 | if (ch == EOF) | |
1728 | { | |
1729 | wxResourceBuffer[wxResourceBufferCount] = 0; | |
1730 | return false; | |
1731 | } | |
1732 | // Escaped characters | |
1733 | else if (ch == '\\') | |
1734 | { | |
1735 | char newCh = is->GetC(); | |
1736 | if (newCh == '"') | |
1737 | actualCh = '"'; | |
1738 | else if (newCh == 10) | |
1739 | actualCh = 10; | |
1740 | else if (newCh == 13) // mac | |
1741 | actualCh = 10; | |
1742 | else | |
1743 | { | |
1744 | is->Ungetch(newCh); | |
1745 | } | |
1746 | } | |
1747 | ||
1748 | if (wxResourceBufferCount >= wxResourceBufferSize-1) | |
1749 | wxReallocateResourceBuffer(); | |
1750 | wxResourceBuffer[wxResourceBufferCount] = (char)actualCh; | |
1751 | wxResourceBufferCount ++; | |
1752 | ch = is->GetC(); | |
1753 | } | |
1754 | wxResourceBuffer[wxResourceBufferCount] = 0; | |
1755 | } | |
1756 | else | |
1757 | { | |
1758 | wxResourceBufferCount = 0; | |
1759 | // Any other token | |
1760 | while (ch != ' ' && ch != EOF && ch != ' ' && ch != 13 && ch != 9 && ch != 10) | |
1761 | { | |
1762 | if (wxResourceBufferCount >= wxResourceBufferSize-1) | |
1763 | wxReallocateResourceBuffer(); | |
1764 | wxResourceBuffer[wxResourceBufferCount] = (char)ch; | |
1765 | wxResourceBufferCount ++; | |
1766 | ||
1767 | ch = is->GetC(); | |
1768 | } | |
1769 | wxResourceBuffer[wxResourceBufferCount] = 0; | |
1770 | if (ch == EOF) | |
1771 | return false; | |
1772 | } | |
1773 | return true; | |
1774 | } | |
1775 | ||
1776 | /* | |
1777 | * Files are in form: | |
1778 | static char *name = "...."; | |
1779 | with possible comments. | |
1780 | */ | |
1781 | ||
1782 | bool wxResourceReadOneResource(FILE *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table) | |
1783 | { | |
1784 | if (!table) | |
1785 | table = wxDefaultResourceTable; | |
1786 | ||
1787 | // static or #define | |
1788 | if (!wxGetResourceToken(fd)) | |
1789 | { | |
1790 | *eof = true; | |
1791 | return false; | |
1792 | } | |
1793 | ||
1794 | if (strcmp(wxResourceBuffer, "#define") == 0) | |
1795 | { | |
1796 | wxGetResourceToken(fd); | |
1797 | wxChar *name = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer)); | |
1798 | wxGetResourceToken(fd); | |
1799 | wxChar *value = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer)); | |
1800 | if (wxIsdigit(value[0])) | |
1801 | { | |
1802 | int val = (int)wxAtol(value); | |
1803 | wxResourceAddIdentifier(name, val, table); | |
1804 | } | |
1805 | else | |
1806 | { | |
1807 | wxLogWarning(_("#define %s must be an integer."), name); | |
1808 | delete[] name; | |
1809 | delete[] value; | |
1810 | return false; | |
1811 | } | |
1812 | delete[] name; | |
1813 | delete[] value; | |
1814 | ||
1815 | return true; | |
1816 | } | |
1817 | else if (strcmp(wxResourceBuffer, "#include") == 0) | |
1818 | { | |
1819 | wxGetResourceToken(fd); | |
1820 | wxChar *name = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer)); | |
1821 | wxChar *actualName = name; | |
1822 | if (name[0] == wxT('"')) | |
1823 | actualName = name + 1; | |
1824 | int len = wxStrlen(name); | |
1825 | if ((len > 0) && (name[len-1] == wxT('"'))) | |
1826 | name[len-1] = 0; | |
1827 | if (!wxResourceParseIncludeFile(actualName, table)) | |
1828 | { | |
1829 | wxLogWarning(_("Could not find resource include file %s."), actualName); | |
1830 | } | |
1831 | delete[] name; | |
1832 | return true; | |
1833 | } | |
1834 | else if (strcmp(wxResourceBuffer, "static") != 0) | |
1835 | { | |
1836 | wxChar buf[300]; | |
1837 | wxStrcpy(buf, _("Found ")); | |
1838 | wxStrncat(buf, wxConvCurrent->cMB2WX(wxResourceBuffer), 30); | |
1839 | wxStrcat(buf, _(", expected static, #include or #define\nwhile parsing resource.")); | |
1840 | wxLogWarning(buf); | |
1841 | return false; | |
1842 | } | |
1843 | ||
1844 | // char | |
1845 | if (!wxGetResourceToken(fd)) | |
1846 | { | |
1847 | wxLogWarning(_("Unexpected end of file while parsing resource.")); | |
1848 | *eof = true; | |
1849 | return false; | |
1850 | } | |
1851 | ||
1852 | if (strcmp(wxResourceBuffer, "char") != 0) | |
1853 | { | |
1854 | wxLogWarning(_("Expected 'char' while parsing resource.")); | |
1855 | return false; | |
1856 | } | |
1857 | ||
1858 | // *name | |
1859 | if (!wxGetResourceToken(fd)) | |
1860 | { | |
1861 | wxLogWarning(_("Unexpected end of file while parsing resource.")); | |
1862 | *eof = true; | |
1863 | return false; | |
1864 | } | |
1865 | ||
1866 | if (wxResourceBuffer[0] != '*') | |
1867 | { | |
1868 | wxLogWarning(_("Expected '*' while parsing resource.")); | |
1869 | return false; | |
1870 | } | |
1871 | wxChar nameBuf[100]; | |
1872 | wxMB2WX(nameBuf, wxResourceBuffer+1, 99); | |
1873 | nameBuf[99] = 0; | |
1874 | ||
1875 | // = | |
1876 | if (!wxGetResourceToken(fd)) | |
1877 | { | |
1878 | wxLogWarning(_("Unexpected end of file while parsing resource.")); | |
1879 | *eof = true; | |
1880 | return false; | |
1881 | } | |
1882 | ||
1883 | if (strcmp(wxResourceBuffer, "=") != 0) | |
1884 | { | |
1885 | wxLogWarning(_("Expected '=' while parsing resource.")); | |
1886 | return false; | |
1887 | } | |
1888 | ||
1889 | // String | |
1890 | if (!wxGetResourceToken(fd)) | |
1891 | { | |
1892 | wxLogWarning(_("Unexpected end of file while parsing resource.")); | |
1893 | *eof = true; | |
1894 | return false; | |
1895 | } | |
1896 | else | |
1897 | { | |
1898 | if (!db.ReadPrologFromString(wxResourceBuffer)) | |
1899 | { | |
1900 | wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf); | |
1901 | return false; | |
1902 | } | |
1903 | } | |
1904 | // Semicolon | |
1905 | if (!wxGetResourceToken(fd)) | |
1906 | { | |
1907 | *eof = true; | |
1908 | } | |
1909 | return true; | |
1910 | } | |
1911 | ||
1912 | bool wxResourceReadOneResource(wxInputStream *fd, wxExprDatabase& db, bool *eof, wxResourceTable *table) | |
1913 | { | |
1914 | if (!table) | |
1915 | table = wxDefaultResourceTable; | |
1916 | ||
1917 | // static or #define | |
1918 | if (!wxGetResourceToken(fd)) | |
1919 | { | |
1920 | *eof = true; | |
1921 | return false; | |
1922 | } | |
1923 | ||
1924 | if (strcmp(wxResourceBuffer, "#define") == 0) | |
1925 | { | |
1926 | wxGetResourceToken(fd); | |
1927 | wxChar *name = copystring(wxConvLibc.cMB2WX(wxResourceBuffer)); | |
1928 | wxGetResourceToken(fd); | |
1929 | wxChar *value = copystring(wxConvLibc.cMB2WX(wxResourceBuffer)); | |
1930 | if (wxIsalpha(value[0])) | |
1931 | { | |
1932 | int val = (int)wxAtol(value); | |
1933 | wxResourceAddIdentifier(name, val, table); | |
1934 | } | |
1935 | else | |
1936 | { | |
1937 | wxLogWarning(_("#define %s must be an integer."), name); | |
1938 | delete[] name; | |
1939 | delete[] value; | |
1940 | return false; | |
1941 | } | |
1942 | delete[] name; | |
1943 | delete[] value; | |
1944 | ||
1945 | return true; | |
1946 | } | |
1947 | else if (strcmp(wxResourceBuffer, "#include") == 0) | |
1948 | { | |
1949 | wxGetResourceToken(fd); | |
1950 | wxChar *name = copystring(wxConvLibc.cMB2WX(wxResourceBuffer)); | |
1951 | wxChar *actualName = name; | |
1952 | if (name[0] == wxT('"')) | |
1953 | actualName = name + 1; | |
1954 | int len = wxStrlen(name); | |
1955 | if ((len > 0) && (name[len-1] == wxT('"'))) | |
1956 | name[len-1] = 0; | |
1957 | if (!wxResourceParseIncludeFile(actualName, table)) | |
1958 | { | |
1959 | wxLogWarning(_("Could not find resource include file %s."), actualName); | |
1960 | } | |
1961 | delete[] name; | |
1962 | return true; | |
1963 | } | |
1964 | else if (strcmp(wxResourceBuffer, "static") != 0) | |
1965 | { | |
1966 | wxChar buf[300]; | |
1967 | wxStrcpy(buf, _("Found ")); | |
1968 | wxStrncat(buf, wxConvLibc.cMB2WX(wxResourceBuffer), 30); | |
1969 | wxStrcat(buf, _(", expected static, #include or #define\nwhile parsing resource.")); | |
1970 | wxLogWarning(buf); | |
1971 | return false; | |
1972 | } | |
1973 | ||
1974 | // char | |
1975 | if (!wxGetResourceToken(fd)) | |
1976 | { | |
1977 | wxLogWarning(_("Unexpected end of file while parsing resource.")); | |
1978 | *eof = true; | |
1979 | return false; | |
1980 | } | |
1981 | ||
1982 | if (strcmp(wxResourceBuffer, "char") != 0) | |
1983 | { | |
1984 | wxLogWarning(_("Expected 'char' while parsing resource.")); | |
1985 | return false; | |
1986 | } | |
1987 | ||
1988 | // *name | |
1989 | if (!wxGetResourceToken(fd)) | |
1990 | { | |
1991 | wxLogWarning(_("Unexpected end of file while parsing resource.")); | |
1992 | *eof = true; | |
1993 | return false; | |
1994 | } | |
1995 | ||
1996 | if (wxResourceBuffer[0] != '*') | |
1997 | { | |
1998 | wxLogWarning(_("Expected '*' while parsing resource.")); | |
1999 | return false; | |
2000 | } | |
2001 | char nameBuf[100]; | |
2002 | strncpy(nameBuf, wxResourceBuffer+1, 99); | |
2003 | ||
2004 | // = | |
2005 | if (!wxGetResourceToken(fd)) | |
2006 | { | |
2007 | wxLogWarning(_("Unexpected end of file while parsing resource.")); | |
2008 | *eof = true; | |
2009 | return false; | |
2010 | } | |
2011 | ||
2012 | if (strcmp(wxResourceBuffer, "=") != 0) | |
2013 | { | |
2014 | wxLogWarning(_("Expected '=' while parsing resource.")); | |
2015 | return false; | |
2016 | } | |
2017 | ||
2018 | // String | |
2019 | if (!wxGetResourceToken(fd)) | |
2020 | { | |
2021 | wxLogWarning(_("Unexpected end of file while parsing resource.")); | |
2022 | *eof = true; | |
2023 | return false; | |
2024 | } | |
2025 | else | |
2026 | { | |
2027 | if (!db.ReadPrologFromString(wxResourceBuffer)) | |
2028 | { | |
2029 | wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf); | |
2030 | return false; | |
2031 | } | |
2032 | } | |
2033 | // Semicolon | |
2034 | if (!wxGetResourceToken(fd)) | |
2035 | { | |
2036 | *eof = true; | |
2037 | } | |
2038 | return true; | |
2039 | } | |
2040 | ||
2041 | /* | |
2042 | * Parses string window style into integer window style | |
2043 | */ | |
2044 | ||
2045 | /* | |
2046 | * Style flag parsing, e.g. | |
2047 | * "wxSYSTEM_MENU | wxBORDER" -> integer | |
2048 | */ | |
2049 | ||
2050 | wxChar* wxResourceParseWord(wxChar*s, int *i) | |
2051 | { | |
2052 | if (!s) | |
2053 | return (wxChar*) NULL; | |
2054 | ||
2055 | static wxChar buf[150]; | |
2056 | int len = wxStrlen(s); | |
2057 | int j = 0; | |
2058 | int ii = *i; | |
2059 | while ((ii < len) && (wxIsalpha(s[ii]) || (s[ii] == wxT('_')))) | |
2060 | { | |
2061 | buf[j] = s[ii]; | |
2062 | j ++; | |
2063 | ii ++; | |
2064 | } | |
2065 | buf[j] = 0; | |
2066 | ||
2067 | // Eat whitespace and conjunction characters | |
2068 | while ((ii < len) && | |
2069 | ((s[ii] == wxT(' ')) || (s[ii] == wxT('|')) || (s[ii] == wxT(',')))) | |
2070 | { | |
2071 | ii ++; | |
2072 | } | |
2073 | *i = ii; | |
2074 | if (j == 0) | |
2075 | return (wxChar*) NULL; | |
2076 | else | |
2077 | return buf; | |
2078 | } | |
2079 | ||
2080 | struct wxResourceBitListStruct | |
2081 | { | |
2082 | const wxChar *word; | |
2083 | long bits; | |
2084 | }; | |
2085 | ||
2086 | static wxResourceBitListStruct wxResourceBitListTable[] = | |
2087 | { | |
2088 | /* wxListBox */ | |
2089 | { wxT("wxSINGLE"), wxLB_SINGLE }, | |
2090 | { wxT("wxMULTIPLE"), wxLB_MULTIPLE }, | |
2091 | { wxT("wxEXTENDED"), wxLB_EXTENDED }, | |
2092 | { wxT("wxLB_SINGLE"), wxLB_SINGLE }, | |
2093 | { wxT("wxLB_MULTIPLE"), wxLB_MULTIPLE }, | |
2094 | { wxT("wxLB_EXTENDED"), wxLB_EXTENDED }, | |
2095 | { wxT("wxLB_NEEDED_SB"), wxLB_NEEDED_SB }, | |
2096 | { wxT("wxLB_ALWAYS_SB"), wxLB_ALWAYS_SB }, | |
2097 | { wxT("wxLB_SORT"), wxLB_SORT }, | |
2098 | { wxT("wxLB_OWNERDRAW"), wxLB_OWNERDRAW }, | |
2099 | { wxT("wxLB_HSCROLL"), wxLB_HSCROLL }, | |
2100 | ||
2101 | /* wxComboxBox */ | |
2102 | { wxT("wxCB_SIMPLE"), wxCB_SIMPLE }, | |
2103 | { wxT("wxCB_DROPDOWN"), wxCB_DROPDOWN }, | |
2104 | { wxT("wxCB_READONLY"), wxCB_READONLY }, | |
2105 | { wxT("wxCB_SORT"), wxCB_SORT }, | |
2106 | ||
2107 | /* wxGauge */ | |
2108 | #if WXWIN_COMPATIBILITY_2_6 | |
2109 | { wxT("wxGA_PROGRESSBAR"), wxGA_PROGRESSBAR }, | |
2110 | #endif // WXWIN_COMPATIBILITY_2_6 | |
2111 | { wxT("wxGA_HORIZONTAL"), wxGA_HORIZONTAL }, | |
2112 | { wxT("wxGA_VERTICAL"), wxGA_VERTICAL }, | |
2113 | ||
2114 | /* wxTextCtrl */ | |
2115 | #if WXWIN_COMPATIBILITY_2_6 | |
2116 | { wxT("wxPASSWORD"), wxTE_PASSWORD}, | |
2117 | { wxT("wxPROCESS_ENTER"), wxTE_PROCESS_ENTER}, | |
2118 | #endif | |
2119 | { wxT("wxTE_PASSWORD"), wxTE_PASSWORD}, | |
2120 | { wxT("wxTE_READONLY"), wxTE_READONLY}, | |
2121 | { wxT("wxTE_PROCESS_ENTER"), wxTE_PROCESS_ENTER}, | |
2122 | { wxT("wxTE_MULTILINE"), wxTE_MULTILINE}, | |
2123 | { wxT("wxTE_NO_VSCROLL"), wxTE_NO_VSCROLL}, | |
2124 | ||
2125 | /* wxRadioBox/wxRadioButton */ | |
2126 | { wxT("wxRB_GROUP"), wxRB_GROUP }, | |
2127 | { wxT("wxRA_SPECIFY_COLS"), wxRA_SPECIFY_COLS }, | |
2128 | { wxT("wxRA_SPECIFY_ROWS"), wxRA_SPECIFY_ROWS }, | |
2129 | { wxT("wxRA_HORIZONTAL"), wxRA_HORIZONTAL }, | |
2130 | { wxT("wxRA_VERTICAL"), wxRA_VERTICAL }, | |
2131 | ||
2132 | /* wxSlider */ | |
2133 | { wxT("wxSL_HORIZONTAL"), wxSL_HORIZONTAL }, | |
2134 | { wxT("wxSL_VERTICAL"), wxSL_VERTICAL }, | |
2135 | { wxT("wxSL_AUTOTICKS"), wxSL_AUTOTICKS }, | |
2136 | { wxT("wxSL_LABELS"), wxSL_LABELS }, | |
2137 | { wxT("wxSL_LEFT"), wxSL_LEFT }, | |
2138 | { wxT("wxSL_TOP"), wxSL_TOP }, | |
2139 | { wxT("wxSL_RIGHT"), wxSL_RIGHT }, | |
2140 | { wxT("wxSL_BOTTOM"), wxSL_BOTTOM }, | |
2141 | { wxT("wxSL_BOTH"), wxSL_BOTH }, | |
2142 | { wxT("wxSL_SELRANGE"), wxSL_SELRANGE }, | |
2143 | ||
2144 | /* wxScrollBar */ | |
2145 | { wxT("wxSB_HORIZONTAL"), wxSB_HORIZONTAL }, | |
2146 | { wxT("wxSB_VERTICAL"), wxSB_VERTICAL }, | |
2147 | ||
2148 | /* wxButton */ | |
2149 | { wxT("wxBU_AUTODRAW"), wxBU_AUTODRAW }, | |
2150 | { wxT("wxBU_NOAUTODRAW"), wxBU_NOAUTODRAW }, | |
2151 | ||
2152 | /* wxTreeCtrl */ | |
2153 | { wxT("wxTR_HAS_BUTTONS"), wxTR_HAS_BUTTONS }, | |
2154 | { wxT("wxTR_EDIT_LABELS"), wxTR_EDIT_LABELS }, | |
2155 | { wxT("wxTR_LINES_AT_ROOT"), wxTR_LINES_AT_ROOT }, | |
2156 | ||
2157 | /* wxListCtrl */ | |
2158 | { wxT("wxLC_ICON"), wxLC_ICON }, | |
2159 | { wxT("wxLC_SMALL_ICON"), wxLC_SMALL_ICON }, | |
2160 | { wxT("wxLC_LIST"), wxLC_LIST }, | |
2161 | { wxT("wxLC_REPORT"), wxLC_REPORT }, | |
2162 | { wxT("wxLC_ALIGN_TOP"), wxLC_ALIGN_TOP }, | |
2163 | { wxT("wxLC_ALIGN_LEFT"), wxLC_ALIGN_LEFT }, | |
2164 | { wxT("wxLC_AUTOARRANGE"), wxLC_AUTOARRANGE }, | |
2165 | { wxT("wxLC_USER_TEXT"), wxLC_USER_TEXT }, | |
2166 | { wxT("wxLC_EDIT_LABELS"), wxLC_EDIT_LABELS }, | |
2167 | { wxT("wxLC_NO_HEADER"), wxLC_NO_HEADER }, | |
2168 | { wxT("wxLC_NO_SORT_HEADER"), wxLC_NO_SORT_HEADER }, | |
2169 | { wxT("wxLC_SINGLE_SEL"), wxLC_SINGLE_SEL }, | |
2170 | { wxT("wxLC_SORT_ASCENDING"), wxLC_SORT_ASCENDING }, | |
2171 | { wxT("wxLC_SORT_DESCENDING"), wxLC_SORT_DESCENDING }, | |
2172 | ||
2173 | /* wxSpinButton */ | |
2174 | { wxT("wxSP_VERTICAL"), wxSP_VERTICAL}, | |
2175 | { wxT("wxSP_HORIZONTAL"), wxSP_HORIZONTAL}, | |
2176 | { wxT("wxSP_ARROW_KEYS"), wxSP_ARROW_KEYS}, | |
2177 | { wxT("wxSP_WRAP"), wxSP_WRAP}, | |
2178 | ||
2179 | /* wxSplitterWnd */ | |
2180 | { wxT("wxSP_NOBORDER"), wxSP_NOBORDER}, | |
2181 | { wxT("wxSP_3D"), wxSP_3D}, | |
2182 | { wxT("wxSP_BORDER"), wxSP_BORDER}, | |
2183 | ||
2184 | /* wxTabCtrl */ | |
2185 | { wxT("wxTC_MULTILINE"), wxTC_MULTILINE}, | |
2186 | { wxT("wxTC_RIGHTJUSTIFY"), wxTC_RIGHTJUSTIFY}, | |
2187 | { wxT("wxTC_FIXEDWIDTH"), wxTC_FIXEDWIDTH}, | |
2188 | { wxT("wxTC_OWNERDRAW"), wxTC_OWNERDRAW}, | |
2189 | ||
2190 | /* wxStatusBar95 */ | |
2191 | { wxT("wxST_SIZEGRIP"), wxST_SIZEGRIP}, | |
2192 | ||
2193 | /* wxControl */ | |
2194 | { wxT("wxFIXED_LENGTH"), wxFIXED_LENGTH}, | |
2195 | { wxT("wxALIGN_LEFT"), wxALIGN_LEFT}, | |
2196 | { wxT("wxALIGN_CENTER"), wxALIGN_CENTER}, | |
2197 | { wxT("wxALIGN_CENTRE"), wxALIGN_CENTRE}, | |
2198 | { wxT("wxALIGN_RIGHT"), wxALIGN_RIGHT}, | |
2199 | { wxT("wxCOLOURED"), wxCOLOURED}, | |
2200 | ||
2201 | /* wxToolBar */ | |
2202 | { wxT("wxTB_3DBUTTONS"), wxTB_3DBUTTONS}, | |
2203 | { wxT("wxTB_HORIZONTAL"), wxTB_HORIZONTAL}, | |
2204 | { wxT("wxTB_VERTICAL"), wxTB_VERTICAL}, | |
2205 | { wxT("wxTB_FLAT"), wxTB_FLAT}, | |
2206 | ||
2207 | #if WXWIN_COMPATIBILITY_2_6 | |
2208 | /* wxDialog */ | |
2209 | { wxT("wxDIALOG_MODAL"), wxDIALOG_MODAL }, | |
2210 | #endif // WXWIN_COMPATIBILITY_2_6 | |
2211 | ||
2212 | /* Generic */ | |
2213 | { wxT("wxVSCROLL"), wxVSCROLL }, | |
2214 | { wxT("wxHSCROLL"), wxHSCROLL }, | |
2215 | { wxT("wxCAPTION"), wxCAPTION }, | |
2216 | { wxT("wxSTAY_ON_TOP"), wxSTAY_ON_TOP}, | |
2217 | { wxT("wxICONIZE"), wxICONIZE}, | |
2218 | { wxT("wxMINIMIZE"), wxICONIZE}, | |
2219 | { wxT("wxMAXIMIZE"), wxMAXIMIZE}, | |
2220 | { wxT("wxSDI"), 0}, | |
2221 | { wxT("wxMDI_PARENT"), 0}, | |
2222 | { wxT("wxMDI_CHILD"), 0}, | |
2223 | { wxT("wxTHICK_FRAME"), wxRESIZE_BORDER}, | |
2224 | { wxT("wxRESIZE_BORDER"), wxRESIZE_BORDER}, | |
2225 | { wxT("wxSYSTEM_MENU"), wxSYSTEM_MENU}, | |
2226 | { wxT("wxMINIMIZE_BOX"), wxMINIMIZE_BOX}, | |
2227 | { wxT("wxMAXIMIZE_BOX"), wxMAXIMIZE_BOX}, | |
2228 | #if WXWIN_COMPATIBILITY_2_6 | |
2229 | { wxT("wxRESIZE_BOX"), wxRESIZE_BOX}, | |
2230 | #endif // WXWIN_COMPATIBILITY_2_6 | |
2231 | { wxT("wxDEFAULT_FRAME_STYLE"), wxDEFAULT_FRAME_STYLE}, | |
2232 | { wxT("wxDEFAULT_FRAME"), wxDEFAULT_FRAME_STYLE}, | |
2233 | { wxT("wxDEFAULT_DIALOG_STYLE"), wxDEFAULT_DIALOG_STYLE}, | |
2234 | { wxT("wxBORDER"), wxBORDER}, | |
2235 | { wxT("wxRETAINED"), wxRETAINED}, | |
2236 | { wxT("wxNATIVE_IMPL"), 0}, | |
2237 | { wxT("wxEXTENDED_IMPL"), 0}, | |
2238 | { wxT("wxBACKINGSTORE"), wxBACKINGSTORE}, | |
2239 | // { wxT("wxFLAT"), wxFLAT}, | |
2240 | // { wxT("wxMOTIF_RESIZE"), wxMOTIF_RESIZE}, | |
2241 | { wxT("wxFIXED_LENGTH"), 0}, | |
2242 | { wxT("wxDOUBLE_BORDER"), wxDOUBLE_BORDER}, | |
2243 | { wxT("wxSUNKEN_BORDER"), wxSUNKEN_BORDER}, | |
2244 | { wxT("wxRAISED_BORDER"), wxRAISED_BORDER}, | |
2245 | { wxT("wxSIMPLE_BORDER"), wxSIMPLE_BORDER}, | |
2246 | { wxT("wxSTATIC_BORDER"), wxSTATIC_BORDER}, | |
2247 | { wxT("wxTRANSPARENT_WINDOW"), wxTRANSPARENT_WINDOW}, | |
2248 | { wxT("wxNO_BORDER"), wxNO_BORDER}, | |
2249 | { wxT("wxCLIP_CHILDREN"), wxCLIP_CHILDREN}, | |
2250 | { wxT("wxCLIP_SIBLINGS"), wxCLIP_SIBLINGS}, | |
2251 | { wxT("wxTAB_TRAVERSAL"), 0}, // Compatibility only | |
2252 | ||
2253 | { wxT("wxTINY_CAPTION_HORIZ"), wxTINY_CAPTION_HORIZ}, | |
2254 | { wxT("wxTINY_CAPTION_VERT"), wxTINY_CAPTION_VERT}, | |
2255 | ||
2256 | // Text font families | |
2257 | { wxT("wxDEFAULT"), wxDEFAULT}, | |
2258 | { wxT("wxDECORATIVE"), wxDECORATIVE}, | |
2259 | { wxT("wxROMAN"), wxROMAN}, | |
2260 | { wxT("wxSCRIPT"), wxSCRIPT}, | |
2261 | { wxT("wxSWISS"), wxSWISS}, | |
2262 | { wxT("wxMODERN"), wxMODERN}, | |
2263 | { wxT("wxTELETYPE"), wxTELETYPE}, | |
2264 | { wxT("wxVARIABLE"), wxVARIABLE}, | |
2265 | { wxT("wxFIXED"), wxFIXED}, | |
2266 | { wxT("wxNORMAL"), wxNORMAL}, | |
2267 | { wxT("wxLIGHT"), wxLIGHT}, | |
2268 | { wxT("wxBOLD"), wxBOLD}, | |
2269 | { wxT("wxITALIC"), wxITALIC}, | |
2270 | { wxT("wxSLANT"), wxSLANT}, | |
2271 | { wxT("wxSOLID"), wxSOLID}, | |
2272 | { wxT("wxDOT"), wxDOT}, | |
2273 | { wxT("wxLONG_DASH"), wxLONG_DASH}, | |
2274 | { wxT("wxSHORT_DASH"), wxSHORT_DASH}, | |
2275 | { wxT("wxDOT_DASH"), wxDOT_DASH}, | |
2276 | { wxT("wxUSER_DASH"), wxUSER_DASH}, | |
2277 | { wxT("wxTRANSPARENT"), wxTRANSPARENT}, | |
2278 | { wxT("wxSTIPPLE"), wxSTIPPLE}, | |
2279 | { wxT("wxBDIAGONAL_HATCH"), wxBDIAGONAL_HATCH}, | |
2280 | { wxT("wxCROSSDIAG_HATCH"), wxCROSSDIAG_HATCH}, | |
2281 | { wxT("wxFDIAGONAL_HATCH"), wxFDIAGONAL_HATCH}, | |
2282 | { wxT("wxCROSS_HATCH"), wxCROSS_HATCH}, | |
2283 | { wxT("wxHORIZONTAL_HATCH"), wxHORIZONTAL_HATCH}, | |
2284 | { wxT("wxVERTICAL_HATCH"), wxVERTICAL_HATCH}, | |
2285 | { wxT("wxJOIN_BEVEL"), wxJOIN_BEVEL}, | |
2286 | { wxT("wxJOIN_MITER"), wxJOIN_MITER}, | |
2287 | { wxT("wxJOIN_ROUND"), wxJOIN_ROUND}, | |
2288 | { wxT("wxCAP_ROUND"), wxCAP_ROUND}, | |
2289 | { wxT("wxCAP_PROJECTING"), wxCAP_PROJECTING}, | |
2290 | { wxT("wxCAP_BUTT"), wxCAP_BUTT}, | |
2291 | ||
2292 | // Logical ops | |
2293 | { wxT("wxCLEAR"), wxCLEAR}, | |
2294 | { wxT("wxXOR"), wxXOR}, | |
2295 | { wxT("wxINVERT"), wxINVERT}, | |
2296 | { wxT("wxOR_REVERSE"), wxOR_REVERSE}, | |
2297 | { wxT("wxAND_REVERSE"), wxAND_REVERSE}, | |
2298 | { wxT("wxCOPY"), wxCOPY}, | |
2299 | { wxT("wxAND"), wxAND}, | |
2300 | { wxT("wxAND_INVERT"), wxAND_INVERT}, | |
2301 | { wxT("wxNO_OP"), wxNO_OP}, | |
2302 | { wxT("wxNOR"), wxNOR}, | |
2303 | { wxT("wxEQUIV"), wxEQUIV}, | |
2304 | { wxT("wxSRC_INVERT"), wxSRC_INVERT}, | |
2305 | { wxT("wxOR_INVERT"), wxOR_INVERT}, | |
2306 | { wxT("wxNAND"), wxNAND}, | |
2307 | { wxT("wxOR"), wxOR}, | |
2308 | { wxT("wxSET"), wxSET}, | |
2309 | ||
2310 | { wxT("wxFLOOD_SURFACE"), wxFLOOD_SURFACE}, | |
2311 | { wxT("wxFLOOD_BORDER"), wxFLOOD_BORDER}, | |
2312 | { wxT("wxODDEVEN_RULE"), wxODDEVEN_RULE}, | |
2313 | { wxT("wxWINDING_RULE"), wxWINDING_RULE}, | |
2314 | { wxT("wxHORIZONTAL"), wxHORIZONTAL}, | |
2315 | { wxT("wxVERTICAL"), wxVERTICAL}, | |
2316 | { wxT("wxBOTH"), wxBOTH}, | |
2317 | { wxT("wxCENTER_FRAME"), wxCENTER_FRAME}, | |
2318 | { wxT("wxOK"), wxOK}, | |
2319 | { wxT("wxYES_NO"), wxYES_NO}, | |
2320 | { wxT("wxCANCEL"), wxCANCEL}, | |
2321 | { wxT("wxYES"), wxYES}, | |
2322 | { wxT("wxNO"), wxNO}, | |
2323 | { wxT("wxICON_EXCLAMATION"), wxICON_EXCLAMATION}, | |
2324 | { wxT("wxICON_HAND"), wxICON_HAND}, | |
2325 | { wxT("wxICON_QUESTION"), wxICON_QUESTION}, | |
2326 | { wxT("wxICON_INFORMATION"), wxICON_INFORMATION}, | |
2327 | { wxT("wxICON_STOP"), wxICON_STOP}, | |
2328 | { wxT("wxICON_ASTERISK"), wxICON_ASTERISK}, | |
2329 | { wxT("wxICON_MASK"), wxICON_MASK}, | |
2330 | { wxT("wxCENTRE"), wxCENTRE}, | |
2331 | { wxT("wxCENTER"), wxCENTRE}, | |
2332 | #if WXWIN_COMPATIBILITY_2_6 | |
2333 | { wxT("wxUSER_COLOURS"), wxUSER_COLOURS}, | |
2334 | #endif // WXWIN_COMPATIBILITY_2_6 | |
2335 | { wxT("wxVERTICAL_LABEL"), 0}, | |
2336 | { wxT("wxHORIZONTAL_LABEL"), 0}, | |
2337 | ||
2338 | // Bitmap types (not strictly styles) | |
2339 | { wxT("wxBITMAP_TYPE_XPM"), wxBITMAP_TYPE_XPM}, | |
2340 | { wxT("wxBITMAP_TYPE_XBM"), wxBITMAP_TYPE_XBM}, | |
2341 | { wxT("wxBITMAP_TYPE_BMP"), wxBITMAP_TYPE_BMP}, | |
2342 | { wxT("wxBITMAP_TYPE_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE}, | |
2343 | { wxT("wxBITMAP_TYPE_BMP_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE}, | |
2344 | { wxT("wxBITMAP_TYPE_GIF"), wxBITMAP_TYPE_GIF}, | |
2345 | { wxT("wxBITMAP_TYPE_TIF"), wxBITMAP_TYPE_TIF}, | |
2346 | { wxT("wxBITMAP_TYPE_ICO"), wxBITMAP_TYPE_ICO}, | |
2347 | { wxT("wxBITMAP_TYPE_ICO_RESOURCE"), wxBITMAP_TYPE_ICO_RESOURCE}, | |
2348 | { wxT("wxBITMAP_TYPE_CUR"), wxBITMAP_TYPE_CUR}, | |
2349 | { wxT("wxBITMAP_TYPE_CUR_RESOURCE"), wxBITMAP_TYPE_CUR_RESOURCE}, | |
2350 | { wxT("wxBITMAP_TYPE_XBM_DATA"), wxBITMAP_TYPE_XBM_DATA}, | |
2351 | { wxT("wxBITMAP_TYPE_XPM_DATA"), wxBITMAP_TYPE_XPM_DATA}, | |
2352 | { wxT("wxBITMAP_TYPE_ANY"), wxBITMAP_TYPE_ANY} | |
2353 | }; | |
2354 | ||
2355 | static int wxResourceBitListCount = (sizeof(wxResourceBitListTable)/sizeof(wxResourceBitListStruct)); | |
2356 | ||
2357 | long wxParseWindowStyle(const wxString& bitListString) | |
2358 | { | |
2359 | int i = 0; | |
2360 | wxChar *word; | |
2361 | long bitList = 0; | |
2362 | word = wxResourceParseWord(WXSTRINGCAST bitListString, &i); | |
2363 | while (word != NULL) | |
2364 | { | |
2365 | bool found = false; | |
2366 | int j; | |
2367 | for (j = 0; j < wxResourceBitListCount; j++) | |
2368 | if (wxStrcmp(wxResourceBitListTable[j].word, word) == 0) | |
2369 | { | |
2370 | bitList |= wxResourceBitListTable[j].bits; | |
2371 | found = true; | |
2372 | break; | |
2373 | } | |
2374 | if (!found) | |
2375 | { | |
2376 | wxLogWarning(_("Unrecognized style %s while parsing resource."), word); | |
2377 | return 0; | |
2378 | } | |
2379 | word = wxResourceParseWord(WXSTRINGCAST bitListString, &i); | |
2380 | } | |
2381 | return bitList; | |
2382 | } | |
2383 | ||
2384 | /* | |
2385 | * Load a bitmap from a wxWidgets resource, choosing an optimum | |
2386 | * depth and appropriate type. | |
2387 | */ | |
2388 | ||
2389 | wxBitmap wxResourceCreateBitmap(const wxString& resource, wxResourceTable *table) | |
2390 | { | |
2391 | if (!table) | |
2392 | table = wxDefaultResourceTable; | |
2393 | ||
2394 | wxItemResource *item = table->FindResource(resource); | |
2395 | if (item) | |
2396 | { | |
2397 | if ((item->GetType().empty()) || (item->GetType() != wxT("wxBitmap"))) | |
2398 | { | |
2399 | wxLogWarning(_("%s not a bitmap resource specification."), (const wxChar*) resource); | |
2400 | return wxNullBitmap; | |
2401 | } | |
2402 | int thisDepth = wxDisplayDepth(); | |
2403 | long thisNoColours = (long)pow(2.0, (double)thisDepth); | |
2404 | ||
2405 | wxItemResource *optResource = (wxItemResource *) NULL; | |
2406 | ||
2407 | // Try to find optimum bitmap for this platform/colour depth | |
2408 | wxNode *node = item->GetChildren().GetFirst(); | |
2409 | while (node) | |
2410 | { | |
2411 | wxItemResource *child = (wxItemResource *)node->GetData(); | |
2412 | int platform = (int)child->GetValue2(); | |
2413 | int noColours = (int)child->GetValue3(); | |
2414 | /* | |
2415 | char *name = child->GetName(); | |
2416 | int bitmapType = (int)child->GetValue1(); | |
2417 | int xRes = child->GetWidth(); | |
2418 | int yRes = child->GetHeight(); | |
2419 | */ | |
2420 | ||
2421 | switch (platform) | |
2422 | { | |
2423 | case RESOURCE_PLATFORM_ANY: | |
2424 | { | |
2425 | if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) | |
2426 | optResource = child; | |
2427 | else | |
2428 | { | |
2429 | // Maximise the number of colours. | |
2430 | // If noColours is zero (unspecified), then assume this | |
2431 | // is the right one. | |
2432 | if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3()))) | |
2433 | optResource = child; | |
2434 | } | |
2435 | break; | |
2436 | } | |
2437 | #ifdef __WXMSW__ | |
2438 | case RESOURCE_PLATFORM_WINDOWS: | |
2439 | { | |
2440 | if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) | |
2441 | optResource = child; | |
2442 | else | |
2443 | { | |
2444 | // Maximise the number of colours | |
2445 | if ((noColours > 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3()))) | |
2446 | optResource = child; | |
2447 | } | |
2448 | break; | |
2449 | } | |
2450 | #endif | |
2451 | #ifdef __WXGTK__ | |
2452 | case RESOURCE_PLATFORM_X: | |
2453 | { | |
2454 | if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) | |
2455 | optResource = child; | |
2456 | else | |
2457 | { | |
2458 | // Maximise the number of colours | |
2459 | if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3()))) | |
2460 | optResource = child; | |
2461 | } | |
2462 | break; | |
2463 | } | |
2464 | #endif | |
2465 | #ifdef wx_max | |
2466 | case RESOURCE_PLATFORM_MAC: | |
2467 | { | |
2468 | if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) | |
2469 | optResource = child; | |
2470 | else | |
2471 | { | |
2472 | // Maximise the number of colours | |
2473 | if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3()))) | |
2474 | optResource = child; | |
2475 | } | |
2476 | break; | |
2477 | } | |
2478 | #endif | |
2479 | default: | |
2480 | break; | |
2481 | } | |
2482 | node = node->GetNext(); | |
2483 | } | |
2484 | // If no matching resource, fail. | |
2485 | if (!optResource) | |
2486 | return wxNullBitmap; | |
2487 | ||
2488 | wxString name = optResource->GetName(); | |
2489 | int bitmapType = (int)optResource->GetValue1(); | |
2490 | switch (bitmapType) | |
2491 | { | |
2492 | case wxBITMAP_TYPE_XBM_DATA: | |
2493 | { | |
2494 | #ifdef __WXGTK__ | |
2495 | wxItemResource *item = table->FindResource(name); | |
2496 | if (!item) | |
2497 | { | |
2498 | wxLogWarning(_("Failed to find XBM resource %s.\n" | |
2499 | "Forgot to use wxResourceLoadBitmapData?"), (const wxChar*) name); | |
2500 | return wxNullBitmap; | |
2501 | } | |
2502 | return wxBitmap(item->GetValue1(), (int)item->GetValue2(), (int)item->GetValue3()) ; | |
2503 | #else | |
2504 | wxLogWarning(_("No XBM facility available!")); | |
2505 | break; | |
2506 | #endif | |
2507 | } | |
2508 | case wxBITMAP_TYPE_XPM_DATA: | |
2509 | { | |
2510 | wxItemResource *item = table->FindResource(name); | |
2511 | if (!item) | |
2512 | { | |
2513 | wxLogWarning(_("Failed to find XPM resource %s.\nForgot to use wxResourceLoadBitmapData?"), (const wxChar*) name); | |
2514 | return wxNullBitmap; | |
2515 | } | |
2516 | return wxBitmap((char **)item->GetValue1()); | |
2517 | } | |
2518 | default: | |
2519 | { | |
2520 | #if defined(__WXPM__) | |
2521 | return wxNullBitmap; | |
2522 | #else | |
2523 | return wxBitmap(name, (wxBitmapType)bitmapType); | |
2524 | #endif | |
2525 | } | |
2526 | } | |
2527 | #ifndef __WXGTK__ | |
2528 | return wxNullBitmap; | |
2529 | #endif | |
2530 | } | |
2531 | else | |
2532 | { | |
2533 | wxLogWarning(_("Bitmap resource specification %s not found."), (const wxChar*) resource); | |
2534 | return wxNullBitmap; | |
2535 | } | |
2536 | } | |
2537 | ||
2538 | /* | |
2539 | * Load an icon from a wxWidgets resource, choosing an optimum | |
2540 | * depth and appropriate type. | |
2541 | */ | |
2542 | ||
2543 | wxIcon wxResourceCreateIcon(const wxString& resource, wxResourceTable *table) | |
2544 | { | |
2545 | if (!table) | |
2546 | table = wxDefaultResourceTable; | |
2547 | ||
2548 | wxItemResource *item = table->FindResource(resource); | |
2549 | if (item) | |
2550 | { | |
2551 | if ((item->GetType().empty()) || wxStrcmp(item->GetType(), wxT("wxIcon")) != 0) | |
2552 | { | |
2553 | wxLogWarning(_("%s not an icon resource specification."), (const wxChar*) resource); | |
2554 | return wxNullIcon; | |
2555 | } | |
2556 | int thisDepth = wxDisplayDepth(); | |
2557 | long thisNoColours = (long)pow(2.0, (double)thisDepth); | |
2558 | ||
2559 | wxItemResource *optResource = (wxItemResource *) NULL; | |
2560 | ||
2561 | // Try to find optimum icon for this platform/colour depth | |
2562 | wxNode *node = item->GetChildren().GetFirst(); | |
2563 | while (node) | |
2564 | { | |
2565 | wxItemResource *child = (wxItemResource *)node->GetData(); | |
2566 | int platform = (int)child->GetValue2(); | |
2567 | int noColours = (int)child->GetValue3(); | |
2568 | /* | |
2569 | char *name = child->GetName(); | |
2570 | int bitmapType = (int)child->GetValue1(); | |
2571 | int xRes = child->GetWidth(); | |
2572 | int yRes = child->GetHeight(); | |
2573 | */ | |
2574 | ||
2575 | switch (platform) | |
2576 | { | |
2577 | case RESOURCE_PLATFORM_ANY: | |
2578 | { | |
2579 | if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) | |
2580 | optResource = child; | |
2581 | else | |
2582 | { | |
2583 | // Maximise the number of colours. | |
2584 | // If noColours is zero (unspecified), then assume this | |
2585 | // is the right one. | |
2586 | if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3()))) | |
2587 | optResource = child; | |
2588 | } | |
2589 | break; | |
2590 | } | |
2591 | #ifdef __WXMSW__ | |
2592 | case RESOURCE_PLATFORM_WINDOWS: | |
2593 | { | |
2594 | if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) | |
2595 | optResource = child; | |
2596 | else | |
2597 | { | |
2598 | // Maximise the number of colours | |
2599 | if ((noColours > 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3()))) | |
2600 | optResource = child; | |
2601 | } | |
2602 | break; | |
2603 | } | |
2604 | #endif | |
2605 | #ifdef __WXGTK__ | |
2606 | case RESOURCE_PLATFORM_X: | |
2607 | { | |
2608 | if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) | |
2609 | optResource = child; | |
2610 | else | |
2611 | { | |
2612 | // Maximise the number of colours | |
2613 | if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3()))) | |
2614 | optResource = child; | |
2615 | } | |
2616 | break; | |
2617 | } | |
2618 | #endif | |
2619 | #ifdef wx_max | |
2620 | case RESOURCE_PLATFORM_MAC: | |
2621 | { | |
2622 | if (!optResource && ((noColours == 0) || (noColours <= thisNoColours))) | |
2623 | optResource = child; | |
2624 | else | |
2625 | { | |
2626 | // Maximise the number of colours | |
2627 | if ((noColours == 0) || ((noColours <= thisNoColours) && (noColours > optResource->GetValue3()))) | |
2628 | optResource = child; | |
2629 | } | |
2630 | break; | |
2631 | } | |
2632 | #endif | |
2633 | default: | |
2634 | break; | |
2635 | } | |
2636 | node = node->GetNext(); | |
2637 | } | |
2638 | // If no matching resource, fail. | |
2639 | if (!optResource) | |
2640 | return wxNullIcon; | |
2641 | ||
2642 | wxString name = optResource->GetName(); | |
2643 | int bitmapType = (int)optResource->GetValue1(); | |
2644 | switch (bitmapType) | |
2645 | { | |
2646 | case wxBITMAP_TYPE_XBM_DATA: | |
2647 | { | |
2648 | #ifdef __WXGTK__ | |
2649 | wxItemResource *item = table->FindResource(name); | |
2650 | if (!item) | |
2651 | { | |
2652 | wxLogWarning(_("Failed to find XBM resource %s.\n" | |
2653 | "Forgot to use wxResourceLoadIconData?"), (const wxChar*) name); | |
2654 | return wxNullIcon; | |
2655 | } | |
2656 | return wxIcon((const char **)item->GetValue1(), (int)item->GetValue2(), (int)item->GetValue3()); | |
2657 | #else | |
2658 | wxLogWarning(_("No XBM facility available!")); | |
2659 | break; | |
2660 | #endif | |
2661 | } | |
2662 | case wxBITMAP_TYPE_XPM_DATA: | |
2663 | { | |
2664 | // *** XPM ICON NOT YET IMPLEMENTED IN wxWidgets *** | |
2665 | /* | |
2666 | wxItemResource *item = table->FindResource(name); | |
2667 | if (!item) | |
2668 | { | |
2669 | char buf[400]; | |
2670 | sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name); | |
2671 | wxLogWarning(buf); | |
2672 | return NULL; | |
2673 | } | |
2674 | return wxIcon((char **)item->GetValue1()); | |
2675 | */ | |
2676 | wxLogWarning(_("No XPM icon facility available!")); | |
2677 | break; | |
2678 | } | |
2679 | default: | |
2680 | { | |
2681 | #if defined( __WXGTK__ ) || defined( __WXMOTIF__ ) | |
2682 | wxLogWarning(_("Icon resource specification %s not found."), (const wxChar*) resource); | |
2683 | break; | |
2684 | #else | |
2685 | return wxIcon(name, (wxBitmapType) bitmapType); | |
2686 | #endif | |
2687 | } | |
2688 | } | |
2689 | return wxNullIcon; | |
2690 | } | |
2691 | else | |
2692 | { | |
2693 | wxLogWarning(_("Icon resource specification %s not found."), (const wxChar*) resource); | |
2694 | return wxNullIcon; | |
2695 | } | |
2696 | } | |
2697 | ||
2698 | #if wxUSE_MENUS | |
2699 | ||
2700 | wxMenu *wxResourceCreateMenu(wxItemResource *item) | |
2701 | { | |
2702 | wxMenu *menu = new wxMenu; | |
2703 | wxNode *node = item->GetChildren().GetFirst(); | |
2704 | while (node) | |
2705 | { | |
2706 | wxItemResource *child = (wxItemResource *)node->GetData(); | |
2707 | if ((!child->GetType().empty()) && (child->GetType() == wxT("wxMenuSeparator"))) | |
2708 | menu->AppendSeparator(); | |
2709 | else if (child->GetChildren().GetCount() > 0) | |
2710 | { | |
2711 | wxMenu *subMenu = wxResourceCreateMenu(child); | |
2712 | if (subMenu) | |
2713 | menu->Append((int)child->GetValue1(), child->GetTitle(), subMenu, child->GetValue4()); | |
2714 | } | |
2715 | else | |
2716 | { | |
2717 | menu->Append((int)child->GetValue1(), child->GetTitle(), child->GetValue4(), (child->GetValue2() != 0)); | |
2718 | } | |
2719 | node = node->GetNext(); | |
2720 | } | |
2721 | return menu; | |
2722 | } | |
2723 | ||
2724 | wxMenuBar *wxResourceCreateMenuBar(const wxString& resource, wxResourceTable *table, wxMenuBar *menuBar) | |
2725 | { | |
2726 | if (!table) | |
2727 | table = wxDefaultResourceTable; | |
2728 | ||
2729 | wxItemResource *menuResource = table->FindResource(resource); | |
2730 | if (menuResource && (!menuResource->GetType().empty()) && (menuResource->GetType() == wxT("wxMenu"))) | |
2731 | { | |
2732 | if (!menuBar) | |
2733 | menuBar = new wxMenuBar; | |
2734 | wxNode *node = menuResource->GetChildren().GetFirst(); | |
2735 | while (node) | |
2736 | { | |
2737 | wxItemResource *child = (wxItemResource *)node->GetData(); | |
2738 | wxMenu *menu = wxResourceCreateMenu(child); | |
2739 | if (menu) | |
2740 | menuBar->Append(menu, child->GetTitle()); | |
2741 | node = node->GetNext(); | |
2742 | } | |
2743 | return menuBar; | |
2744 | } | |
2745 | return (wxMenuBar *) NULL; | |
2746 | } | |
2747 | ||
2748 | wxMenu *wxResourceCreateMenu(const wxString& resource, wxResourceTable *table) | |
2749 | { | |
2750 | if (!table) | |
2751 | table = wxDefaultResourceTable; | |
2752 | ||
2753 | wxItemResource *menuResource = table->FindResource(resource); | |
2754 | if (menuResource && (!menuResource->GetType().empty()) && (menuResource->GetType() == wxT("wxMenu"))) | |
2755 | // if (menuResource && (menuResource->GetType() == wxTYPE_MENU)) | |
2756 | return wxResourceCreateMenu(menuResource); | |
2757 | return (wxMenu *) NULL; | |
2758 | } | |
2759 | ||
2760 | #endif // wxUSE_MENUS | |
2761 | ||
2762 | // Global equivalents (so don't have to refer to default table explicitly) | |
2763 | bool wxResourceParseData(const wxString& resource, wxResourceTable *table) | |
2764 | { | |
2765 | if (!table) | |
2766 | table = wxDefaultResourceTable; | |
2767 | ||
2768 | return table->ParseResourceData(resource); | |
2769 | } | |
2770 | ||
2771 | bool wxResourceParseData(const char* resource, wxResourceTable *table) | |
2772 | { | |
2773 | wxString str(resource, wxConvLibc); | |
2774 | if (!table) | |
2775 | table = wxDefaultResourceTable; | |
2776 | ||
2777 | return table->ParseResourceData(str); | |
2778 | } | |
2779 | ||
2780 | bool wxResourceParseFile(const wxString& filename, wxResourceTable *table) | |
2781 | { | |
2782 | if (!table) | |
2783 | table = wxDefaultResourceTable; | |
2784 | ||
2785 | return table->ParseResourceFile(filename); | |
2786 | } | |
2787 | ||
2788 | // Register XBM/XPM data | |
2789 | bool wxResourceRegisterBitmapData(const wxString& name, char bits[], int width, int height, wxResourceTable *table) | |
2790 | { | |
2791 | if (!table) | |
2792 | table = wxDefaultResourceTable; | |
2793 | ||
2794 | return table->RegisterResourceBitmapData(name, bits, width, height); | |
2795 | } | |
2796 | ||
2797 | bool wxResourceRegisterBitmapData(const wxString& name, char **data, wxResourceTable *table) | |
2798 | { | |
2799 | if (!table) | |
2800 | table = wxDefaultResourceTable; | |
2801 | ||
2802 | return table->RegisterResourceBitmapData(name, data); | |
2803 | } | |
2804 | ||
2805 | void wxResourceClear(wxResourceTable *table) | |
2806 | { | |
2807 | if (!table) | |
2808 | table = wxDefaultResourceTable; | |
2809 | ||
2810 | table->ClearTable(); | |
2811 | } | |
2812 | ||
2813 | /* | |
2814 | * Identifiers | |
2815 | */ | |
2816 | ||
2817 | bool wxResourceAddIdentifier(const wxString& name, int value, wxResourceTable *table) | |
2818 | { | |
2819 | if (!table) | |
2820 | table = wxDefaultResourceTable; | |
2821 | ||
2822 | table->identifiers.Put(name, (wxObject *)(long)value); | |
2823 | return true; | |
2824 | } | |
2825 | ||
2826 | int wxResourceGetIdentifier(const wxString& name, wxResourceTable *table) | |
2827 | { | |
2828 | if (!table) | |
2829 | table = wxDefaultResourceTable; | |
2830 | ||
2831 | return (int)(long)table->identifiers.Get(name); | |
2832 | } | |
2833 | ||
2834 | /* | |
2835 | * Parse #include file for #defines (only) | |
2836 | */ | |
2837 | ||
2838 | bool wxResourceParseIncludeFile(const wxString& f, wxResourceTable *table) | |
2839 | { | |
2840 | if (!table) | |
2841 | table = wxDefaultResourceTable; | |
2842 | ||
2843 | FILE *fd = wxFopen(f, wxT("r")); | |
2844 | if (!fd) | |
2845 | { | |
2846 | return false; | |
2847 | } | |
2848 | while (wxGetResourceToken(fd)) | |
2849 | { | |
2850 | if (strcmp(wxResourceBuffer, "#define") == 0) | |
2851 | { | |
2852 | wxGetResourceToken(fd); | |
2853 | wxChar *name = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer)); | |
2854 | wxGetResourceToken(fd); | |
2855 | wxChar *value = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer)); | |
2856 | if (wxIsdigit(value[0])) | |
2857 | { | |
2858 | int val = (int)wxAtol(value); | |
2859 | wxResourceAddIdentifier(name, val, table); | |
2860 | } | |
2861 | delete[] name; | |
2862 | delete[] value; | |
2863 | } | |
2864 | } | |
2865 | fclose(fd); | |
2866 | return true; | |
2867 | } | |
2868 | ||
2869 | /* | |
2870 | * Reading strings as if they were .wxr files | |
2871 | */ | |
2872 | ||
2873 | static int getc_string(char *s) | |
2874 | { | |
2875 | int ch = s[wxResourceStringPtr]; | |
2876 | if (ch == 0) | |
2877 | return EOF; | |
2878 | else | |
2879 | { | |
2880 | wxResourceStringPtr ++; | |
2881 | return ch; | |
2882 | } | |
2883 | } | |
2884 | ||
2885 | static int ungetc_string() | |
2886 | { | |
2887 | wxResourceStringPtr --; | |
2888 | return 0; | |
2889 | } | |
2890 | ||
2891 | bool wxEatWhiteSpaceString(char *s) | |
2892 | { | |
2893 | int ch; | |
2894 | ||
2895 | while ((ch = getc_string(s)) != EOF) | |
2896 | { | |
2897 | switch (ch) | |
2898 | { | |
2899 | case ' ': | |
2900 | case 0x0a: | |
2901 | case 0x0d: | |
2902 | case 0x09: | |
2903 | break; | |
2904 | case '/': | |
2905 | { | |
2906 | ch = getc_string(s); | |
2907 | if (ch == EOF) | |
2908 | { | |
2909 | ungetc_string(); | |
2910 | return true; | |
2911 | } | |
2912 | ||
2913 | if (ch == '*') | |
2914 | { | |
2915 | // Eat C comment | |
2916 | int prev_ch = 0; | |
2917 | while ((ch = getc_string(s)) != EOF) | |
2918 | { | |
2919 | if (ch == '/' && prev_ch == '*') | |
2920 | break; | |
2921 | prev_ch = ch; | |
2922 | } | |
2923 | } | |
2924 | else | |
2925 | { | |
2926 | ungetc_string(); | |
2927 | ungetc_string(); | |
2928 | return true; | |
2929 | } | |
2930 | } | |
2931 | break; | |
2932 | default: | |
2933 | ungetc_string(); | |
2934 | return true; | |
2935 | ||
2936 | } | |
2937 | } | |
2938 | return false; | |
2939 | } | |
2940 | ||
2941 | bool wxGetResourceTokenString(char *s) | |
2942 | { | |
2943 | if (!wxResourceBuffer) | |
2944 | wxReallocateResourceBuffer(); | |
2945 | wxResourceBuffer[0] = 0; | |
2946 | wxEatWhiteSpaceString(s); | |
2947 | ||
2948 | int ch = getc_string(s); | |
2949 | if (ch == '"') | |
2950 | { | |
2951 | // Get string | |
2952 | wxResourceBufferCount = 0; | |
2953 | ch = getc_string(s); | |
2954 | while (ch != '"') | |
2955 | { | |
2956 | int actualCh = ch; | |
2957 | if (ch == EOF) | |
2958 | { | |
2959 | wxResourceBuffer[wxResourceBufferCount] = 0; | |
2960 | return false; | |
2961 | } | |
2962 | // Escaped characters | |
2963 | else if (ch == '\\') | |
2964 | { | |
2965 | int newCh = getc_string(s); | |
2966 | if (newCh == '"') | |
2967 | actualCh = '"'; | |
2968 | else if (newCh == 10) | |
2969 | actualCh = 10; | |
2970 | else | |
2971 | { | |
2972 | ungetc_string(); | |
2973 | } | |
2974 | } | |
2975 | ||
2976 | if (wxResourceBufferCount >= wxResourceBufferSize-1) | |
2977 | wxReallocateResourceBuffer(); | |
2978 | wxResourceBuffer[wxResourceBufferCount] = (char)actualCh; | |
2979 | wxResourceBufferCount ++; | |
2980 | ch = getc_string(s); | |
2981 | } | |
2982 | wxResourceBuffer[wxResourceBufferCount] = 0; | |
2983 | } | |
2984 | else | |
2985 | { | |
2986 | wxResourceBufferCount = 0; | |
2987 | // Any other token | |
2988 | while (ch != ' ' && ch != EOF && ch != ' ' && ch != 13 && ch != 9 && ch != 10) | |
2989 | { | |
2990 | if (wxResourceBufferCount >= wxResourceBufferSize-1) | |
2991 | wxReallocateResourceBuffer(); | |
2992 | wxResourceBuffer[wxResourceBufferCount] = (char)ch; | |
2993 | wxResourceBufferCount ++; | |
2994 | ||
2995 | ch = getc_string(s); | |
2996 | } | |
2997 | wxResourceBuffer[wxResourceBufferCount] = 0; | |
2998 | if (ch == EOF) | |
2999 | return false; | |
3000 | } | |
3001 | return true; | |
3002 | } | |
3003 | ||
3004 | /* | |
3005 | * Files are in form: | |
3006 | static char *name = "...."; | |
3007 | with possible comments. | |
3008 | */ | |
3009 | ||
3010 | bool wxResourceReadOneResourceString(char *s, wxExprDatabase& db, bool *eof, wxResourceTable *table) | |
3011 | { | |
3012 | if (!table) | |
3013 | table = wxDefaultResourceTable; | |
3014 | ||
3015 | // static or #define | |
3016 | if (!wxGetResourceTokenString(s)) | |
3017 | { | |
3018 | *eof = true; | |
3019 | return false; | |
3020 | } | |
3021 | ||
3022 | if (strcmp(wxResourceBuffer, "#define") == 0) | |
3023 | { | |
3024 | wxGetResourceTokenString(s); | |
3025 | wxChar *name = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer)); | |
3026 | wxGetResourceTokenString(s); | |
3027 | wxChar *value = copystring(wxConvCurrent->cMB2WX(wxResourceBuffer)); | |
3028 | if (wxIsdigit(value[0])) | |
3029 | { | |
3030 | int val = (int)wxAtol(value); | |
3031 | wxResourceAddIdentifier(name, val, table); | |
3032 | } | |
3033 | else | |
3034 | { | |
3035 | wxLogWarning(_("#define %s must be an integer."), name); | |
3036 | delete[] name; | |
3037 | delete[] value; | |
3038 | return false; | |
3039 | } | |
3040 | delete[] name; | |
3041 | delete[] value; | |
3042 | ||
3043 | return true; | |
3044 | } | |
3045 | /* | |
3046 | else if (strcmp(wxResourceBuffer, "#include") == 0) | |
3047 | { | |
3048 | wxGetResourceTokenString(s); | |
3049 | char *name = copystring(wxResourceBuffer); | |
3050 | char *actualName = name; | |
3051 | if (name[0] == '"') | |
3052 | actualName = name + 1; | |
3053 | int len = strlen(name); | |
3054 | if ((len > 0) && (name[len-1] == '"')) | |
3055 | name[len-1] = 0; | |
3056 | if (!wxResourceParseIncludeFile(actualName, table)) | |
3057 | { | |
3058 | char buf[400]; | |
3059 | sprintf(buf, _("Could not find resource include file %s."), actualName); | |
3060 | wxLogWarning(buf); | |
3061 | } | |
3062 | delete[] name; | |
3063 | return true; | |
3064 | } | |
3065 | */ | |
3066 | else if (strcmp(wxResourceBuffer, "static") != 0) | |
3067 | { | |
3068 | wxChar buf[300]; | |
3069 | wxStrcpy(buf, _("Found ")); | |
3070 | wxStrncat(buf, wxConvCurrent->cMB2WX(wxResourceBuffer), 30); | |
3071 | wxStrcat(buf, _(", expected static, #include or #define\nwhile parsing resource.")); | |
3072 | wxLogWarning(buf); | |
3073 | return false; | |
3074 | } | |
3075 | ||
3076 | // char | |
3077 | if (!wxGetResourceTokenString(s)) | |
3078 | { | |
3079 | wxLogWarning(_("Unexpected end of file while parsing resource.")); | |
3080 | *eof = true; | |
3081 | return false; | |
3082 | } | |
3083 | ||
3084 | if (strcmp(wxResourceBuffer, "char") != 0) | |
3085 | { | |
3086 | wxLogWarning(_("Expected 'char' while parsing resource.")); | |
3087 | return false; | |
3088 | } | |
3089 | ||
3090 | // *name | |
3091 | if (!wxGetResourceTokenString(s)) | |
3092 | { | |
3093 | wxLogWarning(_("Unexpected end of file while parsing resource.")); | |
3094 | *eof = true; | |
3095 | return false; | |
3096 | } | |
3097 | ||
3098 | if (wxResourceBuffer[0] != '*') | |
3099 | { | |
3100 | wxLogWarning(_("Expected '*' while parsing resource.")); | |
3101 | return false; | |
3102 | } | |
3103 | wxChar nameBuf[100]; | |
3104 | wxMB2WX(nameBuf, wxResourceBuffer+1, 99); | |
3105 | nameBuf[99] = 0; | |
3106 | ||
3107 | // = | |
3108 | if (!wxGetResourceTokenString(s)) | |
3109 | { | |
3110 | wxLogWarning(_("Unexpected end of file while parsing resource.")); | |
3111 | *eof = true; | |
3112 | return false; | |
3113 | } | |
3114 | ||
3115 | if (strcmp(wxResourceBuffer, "=") != 0) | |
3116 | { | |
3117 | wxLogWarning(_("Expected '=' while parsing resource.")); | |
3118 | return false; | |
3119 | } | |
3120 | ||
3121 | // String | |
3122 | if (!wxGetResourceTokenString(s)) | |
3123 | { | |
3124 | wxLogWarning(_("Unexpected end of file while parsing resource.")); | |
3125 | *eof = true; | |
3126 | return false; | |
3127 | } | |
3128 | else | |
3129 | { | |
3130 | if (!db.ReadPrologFromString(wxResourceBuffer)) | |
3131 | { | |
3132 | wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf); | |
3133 | return false; | |
3134 | } | |
3135 | } | |
3136 | // Semicolon | |
3137 | if (!wxGetResourceTokenString(s)) | |
3138 | { | |
3139 | *eof = true; | |
3140 | } | |
3141 | return true; | |
3142 | } | |
3143 | ||
3144 | bool wxResourceParseString(const wxString& s, wxResourceTable *WXUNUSED(table)) | |
3145 | { | |
3146 | #if wxUSE_UNICODE | |
3147 | return wxResourceParseString( (char*)s.mb_str().data() ); | |
3148 | #else | |
3149 | return wxResourceParseString( (char*)s.c_str() ); | |
3150 | #endif | |
3151 | } | |
3152 | ||
3153 | bool wxResourceParseString(char *s, wxResourceTable *table) | |
3154 | { | |
3155 | if (!table) | |
3156 | table = wxDefaultResourceTable; | |
3157 | ||
3158 | if (!s) | |
3159 | return false; | |
3160 | ||
3161 | // Turn backslashes into spaces | |
3162 | if (s) | |
3163 | { | |
3164 | int len = strlen(s); | |
3165 | int i; | |
3166 | for (i = 0; i < len; i++) | |
3167 | if (s[i] == 92 && s[i+1] == 13) | |
3168 | { | |
3169 | s[i] = ' '; | |
3170 | s[i+1] = ' '; | |
3171 | } | |
3172 | } | |
3173 | ||
3174 | wxExprDatabase db; | |
3175 | wxResourceStringPtr = 0; | |
3176 | ||
3177 | bool eof = false; | |
3178 | while (wxResourceReadOneResourceString(s, db, &eof, table) && !eof) | |
3179 | { | |
3180 | // Loop | |
3181 | } | |
3182 | return wxResourceInterpretResources(*table, db); | |
3183 | } | |
3184 | ||
3185 | /* | |
3186 | * resource loading facility | |
3187 | */ | |
3188 | ||
3189 | bool wxLoadFromResource(wxWindow* thisWindow, wxWindow *parent, const wxString& resourceName, const wxResourceTable *table) | |
3190 | { | |
3191 | if (!table) | |
3192 | table = wxDefaultResourceTable; | |
3193 | ||
3194 | wxItemResource *resource = table->FindResource((const wxChar *)resourceName); | |
3195 | // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX)) | |
3196 | if (!resource || (resource->GetType().empty()) || | |
3197 | ! ((resource->GetType() == wxT("wxDialog")) || (resource->GetType() == wxT("wxPanel")))) | |
3198 | return false; | |
3199 | ||
3200 | wxString title(resource->GetTitle()); | |
3201 | long theWindowStyle = resource->GetStyle(); | |
3202 | bool isModal = (resource->GetValue1() != 0) ; | |
3203 | int x = resource->GetX(); | |
3204 | int y = resource->GetY(); | |
3205 | int width = resource->GetWidth(); | |
3206 | int height = resource->GetHeight(); | |
3207 | wxString name = resource->GetName(); | |
3208 | ||
3209 | // this is used for loading wxWizard pages from WXR | |
3210 | if ( parent != thisWindow ) | |
3211 | { | |
3212 | if (thisWindow->IsKindOf(CLASSINFO(wxDialog))) | |
3213 | { | |
3214 | wxDialog *dialogBox = (wxDialog *)thisWindow; | |
3215 | long modalStyle = isModal ? | |
3216 | #if WXWIN_COMPATIBILITY_2_6 | |
3217 | wxDIALOG_MODAL | |
3218 | #else | |
3219 | 0 | |
3220 | #endif // WXWIN_COMPATIBILITY_2_6 | |
3221 | : 0; | |
3222 | if (!dialogBox->Create(parent, wxID_ANY, title, wxPoint(x, y), wxSize(width, height), theWindowStyle|modalStyle, name)) | |
3223 | return false; | |
3224 | ||
3225 | // Only reset the client size if we know we're not going to do it again below. | |
3226 | if ((resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) == 0) | |
3227 | dialogBox->SetClientSize(width, height); | |
3228 | } | |
3229 | else if (thisWindow->IsKindOf(CLASSINFO(wxPanel))) | |
3230 | { | |
3231 | wxPanel* panel = (wxPanel *)thisWindow; | |
3232 | if (!panel->Create(parent, wxID_ANY, wxPoint(x, y), wxSize(width, height), theWindowStyle | wxTAB_TRAVERSAL, name)) | |
3233 | return false; | |
3234 | } | |
3235 | else | |
3236 | { | |
3237 | if (!((wxWindow *)thisWindow)->Create(parent, wxID_ANY, wxPoint(x, y), wxSize(width, height), theWindowStyle, name)) | |
3238 | return false; | |
3239 | } | |
3240 | } | |
3241 | ||
3242 | if ((resource->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS) != 0) | |
3243 | { | |
3244 | // No need to do this since it's done in wxPanel or wxDialog constructor. | |
3245 | // SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); | |
3246 | } | |
3247 | else | |
3248 | { | |
3249 | if (resource->GetFont().Ok()) | |
3250 | thisWindow->SetFont(resource->GetFont()); | |
3251 | if (resource->GetBackgroundColour().Ok()) | |
3252 | thisWindow->SetBackgroundColour(resource->GetBackgroundColour()); | |
3253 | } | |
3254 | ||
3255 | // Should have some kind of font at this point | |
3256 | if (!thisWindow->GetFont().Ok()) | |
3257 | thisWindow->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); | |
3258 | if (!thisWindow->GetBackgroundColour().Ok()) | |
3259 | thisWindow->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); | |
3260 | ||
3261 | // Only when we've created the window and set the font can we set the correct size, | |
3262 | // if based on dialog units. | |
3263 | if ((resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) != 0) | |
3264 | { | |
3265 | wxSize sz = thisWindow->ConvertDialogToPixels(wxSize(width, height)); | |
3266 | thisWindow->SetClientSize(sz.x, sz.y); | |
3267 | ||
3268 | wxPoint pt = thisWindow->ConvertDialogToPixels(wxPoint(x, y)); | |
3269 | thisWindow->Move(pt.x, pt.y); | |
3270 | } | |
3271 | ||
3272 | // Now create children | |
3273 | wxNode *node = resource->GetChildren().GetFirst(); | |
3274 | while (node) | |
3275 | { | |
3276 | wxItemResource *childResource = (wxItemResource *)node->GetData(); | |
3277 | ||
3278 | (void) wxCreateItem(thisWindow, childResource, resource, table); | |
3279 | ||
3280 | node = node->GetNext(); | |
3281 | } | |
3282 | return true; | |
3283 | } | |
3284 | ||
3285 | wxControl *wxCreateItem(wxWindow* thisWindow, const wxItemResource *resource, const wxItemResource* parentResource, const wxResourceTable *table) | |
3286 | { | |
3287 | if (!table) | |
3288 | table = wxDefaultResourceTable; | |
3289 | return table->CreateItem(thisWindow, resource, parentResource); | |
3290 | } | |
3291 | ||
3292 | #ifdef __VISUALC__ | |
3293 | #pragma warning(default:4706) // assignment within conditional expression | |
3294 | #endif // VC++ | |
3295 | ||
3296 | #endif // wxUSE_WX_RESOURCES |