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