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