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