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