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