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