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