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