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