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