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