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