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