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