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