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