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