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