1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Resource system
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "resource.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #if wxUSE_WX_RESOURCES
26 #pragma warning(disable:4706) // assignment within conditional expression
34 #include "wx/gdicmn.h"
38 #include "wx/stattext.h"
39 #include "wx/button.h"
40 #include "wx/bmpbuttn.h"
41 #include "wx/radiobox.h"
42 #include "wx/radiobut.h"
43 #include "wx/listbox.h"
44 #include "wx/choice.h"
45 #include "wx/checkbox.h"
46 #include "wx/settings.h"
47 #include "wx/slider.h"
48 #include "wx/statbox.h"
49 #include "wx/statbmp.h"
53 #include "wx/textctrl.h"
54 #include "wx/msgdlg.h"
59 #include "wx/radiobut.h"
63 #include "wx/scrolbar.h"
67 #include "wx/combobox.h"
70 #include "wx/validate.h"
79 #include "wx/resource.h"
80 #include "wx/string.h"
81 #include "wx/wxexpr.h"
83 #include "wx/settings.h"
85 // Forward (private) declarations
86 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
);
87 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
= FALSE
);
88 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
);
89 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
);
90 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
);
91 wxItemResource
*wxResourceInterpretString(wxResourceTable
& table
, wxExpr
*expr
);
92 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& table
, wxExpr
*expr
);
93 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
);
94 // Interpret list expression
95 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
);
97 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
98 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
100 wxResourceTable
*wxDefaultResourceTable
= (wxResourceTable
*) NULL
;
102 char *wxResourceBuffer
= (char *) NULL
;
103 long wxResourceBufferSize
= 0;
104 long wxResourceBufferCount
= 0;
105 int wxResourceStringPtr
= 0;
107 void wxInitializeResourceSystem()
109 wxDefaultResourceTable
= new wxResourceTable
;
112 void wxCleanUpResourceSystem()
114 delete wxDefaultResourceTable
;
115 if (wxResourceBuffer
)
116 delete[] wxResourceBuffer
;
119 void wxLogWarning(char *msg
)
121 wxMessageBox(msg
, _("Warning"), wxOK
);
124 #if !USE_SHARED_LIBRARY
125 IMPLEMENT_DYNAMIC_CLASS(wxItemResource
, wxObject
)
126 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable
, wxHashTable
)
129 wxItemResource::wxItemResource()
135 m_x
= m_y
= m_width
= m_height
= 0;
136 m_value1
= m_value2
= m_value3
= m_value5
= 0;
142 wxItemResource::~wxItemResource()
144 wxNode
*node
= m_children
.First();
147 wxItemResource
*item
= (wxItemResource
*)node
->Data();
150 node
= m_children
.First();
158 wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
)
162 wxResourceTable::~wxResourceTable()
167 wxItemResource
*wxResourceTable::FindResource(const wxString
& name
) const
169 wxItemResource
*item
= (wxItemResource
*)Get(WXSTRINGCAST name
);
173 void wxResourceTable::AddResource(wxItemResource
*item
)
175 wxString name
= item
->GetName();
177 name
= item
->GetTitle();
179 name
= _T("no name");
181 // Delete existing resource, if any.
187 bool wxResourceTable::DeleteResource(const wxString
& name
)
189 wxItemResource
*item
= (wxItemResource
*)Delete(WXSTRINGCAST name
);
192 // See if any resource has this as its child; if so, delete from
193 // parent's child list.
195 wxNode
*node
= (wxNode
*) NULL
;
196 while ((node
= Next()))
198 wxItemResource
*parent
= (wxItemResource
*)node
->Data();
199 if (parent
->GetChildren().Member(item
))
201 parent
->GetChildren().DeleteObject(item
);
213 bool wxResourceTable::ParseResourceFile(const wxString
& filename
)
217 FILE *fd
= fopen(filename
.fn_str(), "r");
221 while (wxResourceReadOneResource(fd
, db
, &eof
, this) && !eof
)
226 return wxResourceInterpretResources(*this, db
);
229 bool wxResourceTable::ParseResourceData(const wxString
& data
)
232 if (!db
.ReadFromString(data
))
234 wxLogWarning(_("Ill-formed resource file syntax."));
238 return wxResourceInterpretResources(*this, db
);
241 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char bits
[], int width
, int height
)
243 // Register pre-loaded bitmap data
244 wxItemResource
*item
= new wxItemResource
;
245 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
246 item
->SetType(_T("wxXBMData"));
248 item
->SetValue1((long)bits
);
249 item
->SetValue2((long)width
);
250 item
->SetValue3((long)height
);
255 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char **data
)
257 // Register pre-loaded bitmap data
258 wxItemResource
*item
= new wxItemResource
;
259 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
260 item
->SetType(_T("wxXPMData"));
262 item
->SetValue1((long)data
);
267 bool wxResourceTable::SaveResource(const wxString
& WXUNUSED(filename
))
272 void wxResourceTable::ClearTable()
275 wxNode
*node
= Next();
278 wxNode
*next
= Next();
279 wxItemResource
*item
= (wxItemResource
*)node
->Data();
286 wxControl
*wxResourceTable::CreateItem(wxWindow
*parent
, const wxItemResource
* childResource
, const wxItemResource
* parentResource
) const
288 int id
= childResource
->GetId();
292 bool dlgUnits
= ((parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0);
294 wxControl
*control
= (wxControl
*) NULL
;
295 wxString
itemType(childResource
->GetType());
301 pos
= parent
->ConvertDialogToPixels(wxPoint(childResource
->GetX(), childResource
->GetY()));
302 size
= parent
->ConvertDialogToPixels(wxSize(childResource
->GetWidth(), childResource
->GetHeight()));
306 pos
= wxPoint(childResource
->GetX(), childResource
->GetY());
307 size
= wxSize(childResource
->GetWidth(), childResource
->GetHeight());
310 if (itemType
== wxString(_T("wxButton")) || itemType
== wxString(_T("wxBitmapButton")))
312 if (childResource
->GetValue4() != _T(""))
315 wxBitmap bitmap
= childResource
->GetBitmap();
318 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
319 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
322 control
= new wxBitmapButton(parent
, id
, bitmap
, pos
, size
,
323 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
326 // Normal, text button
327 control
= new wxButton(parent
, id
, childResource
->GetTitle(), pos
, size
,
328 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
330 else if (itemType
== wxString(_T("wxMessage")) || itemType
== wxString(_T("wxStaticText")) ||
331 itemType
== wxString(_T("wxStaticBitmap")))
333 if (childResource
->GetValue4() != _T(""))
336 wxBitmap bitmap
= childResource
->GetBitmap();
339 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
340 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
342 #if wxUSE_BITMAP_MESSAGE
344 control
= new wxStaticBitmap(parent
, id
, bitmap
, pos
, size
,
345 childResource
->GetStyle(), childResource
->GetName());
350 control
= new wxStaticText(parent
, id
, childResource
->GetTitle(), pos
, size
,
351 childResource
->GetStyle(), childResource
->GetName());
354 else if (itemType
== wxString(_T("wxText")) || itemType
== wxString(_T("wxTextCtrl")) || itemType
== wxString(_T("wxMultiText")))
356 control
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(), pos
, size
,
357 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
359 else if (itemType
== wxString(_T("wxCheckBox")))
361 control
= new wxCheckBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
362 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
364 ((wxCheckBox
*)control
)->SetValue((childResource
->GetValue1() != 0));
367 else if (itemType
== wxString(_T("wxGauge")))
369 control
= new wxGauge(parent
, id
, (int)childResource
->GetValue2(), pos
, size
,
370 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
372 ((wxGauge
*)control
)->SetValue((int)childResource
->GetValue1());
375 #if wxUSE_RADIOBUTTON
376 else if (itemType
== wxString(_T("wxRadioButton")))
378 control
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(),
380 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
384 else if (itemType
== wxString(_T("wxScrollBar")))
386 control
= new wxScrollBar(parent
, id
, pos
, size
,
387 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
389 ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1());
390 ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2());
391 ((wxScrollBar *)control)->SetObjectLength((int)childResource->GetValue3());
392 ((wxScrollBar *)control)->SetViewLength((int)(long)childResource->GetValue5());
394 ((wxScrollBar
*)control
)->SetScrollbar((int)childResource
->GetValue1(),(int)childResource
->GetValue2(),
395 (int)childResource
->GetValue3(),(int)(long)childResource
->GetValue5(),FALSE
);
399 else if (itemType
== wxString(_T("wxSlider")))
401 control
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(),
402 (int)childResource
->GetValue2(), (int)childResource
->GetValue3(), pos
, size
,
403 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
405 else if (itemType
== wxString(_T("wxGroupBox")) || itemType
== wxString(_T("wxStaticBox")))
407 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
408 childResource
->GetStyle(), childResource
->GetName());
410 else if (itemType
== wxString(_T("wxListBox")))
412 wxStringList
& stringList
= childResource
->GetStringValues();
413 wxString
*strings
= (wxString
*) NULL
;
415 if (stringList
.Number() > 0)
417 noStrings
= stringList
.Number();
418 strings
= new wxString
[noStrings
];
419 wxNode
*node
= stringList
.First();
423 strings
[i
] = (wxChar
*)node
->Data();
428 control
= new wxListBox(parent
, id
, pos
, size
,
429 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
434 else if (itemType
== wxString(_T("wxChoice")))
436 wxStringList
& stringList
= childResource
->GetStringValues();
437 wxString
*strings
= (wxString
*) NULL
;
439 if (stringList
.Number() > 0)
441 noStrings
= stringList
.Number();
442 strings
= new wxString
[noStrings
];
443 wxNode
*node
= stringList
.First();
447 strings
[i
] = (wxChar
*)node
->Data();
452 control
= new wxChoice(parent
, id
, pos
, size
,
453 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
459 else if (itemType
== wxString(_T("wxComboBox")))
461 wxStringList
& stringList
= childResource
->GetStringValues();
462 wxString
*strings
= (wxString
*) NULL
;
464 if (stringList
.Number() > 0)
466 noStrings
= stringList
.Number();
467 strings
= new wxString
[noStrings
];
468 wxNode
*node
= stringList
.First();
472 strings
[i
] = (wxChar
*)node
->Data();
477 control
= new wxComboBox(parent
, id
, childResource
->GetValue4(), pos
, size
,
478 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
484 else if (itemType
== wxString(_T("wxRadioBox")))
486 wxStringList
& stringList
= childResource
->GetStringValues();
487 wxString
*strings
= (wxString
*) NULL
;
489 if (stringList
.Number() > 0)
491 noStrings
= stringList
.Number();
492 strings
= new wxString
[noStrings
];
493 wxNode
*node
= stringList
.First();
497 strings
[i
] = (wxChar
*)node
->Data();
502 control
= new wxRadioBox(parent
, (wxWindowID
) id
, wxString(childResource
->GetTitle()), pos
, size
,
503 noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
,
504 childResource
->GetName());
510 if ((parentResource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
512 // Don't set font; will be inherited from parent.
516 if (control
&& childResource
->GetFont().Ok())
517 control
->SetFont(childResource
->GetFont());
523 * Interpret database as a series of resources
526 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
)
528 wxNode
*node
= db
.First();
531 wxExpr
*clause
= (wxExpr
*)node
->Data();
532 wxString
functor(clause
->Functor());
534 wxItemResource
*item
= (wxItemResource
*) NULL
;
535 if (functor
== _T("dialog"))
536 item
= wxResourceInterpretDialog(table
, clause
);
537 else if (functor
== _T("panel"))
538 item
= wxResourceInterpretDialog(table
, clause
, TRUE
);
539 else if (functor
== _T("menubar"))
540 item
= wxResourceInterpretMenuBar(table
, clause
);
541 else if (functor
== _T("menu"))
542 item
= wxResourceInterpretMenu(table
, clause
);
543 else if (functor
== _T("string"))
544 item
= wxResourceInterpretString(table
, clause
);
545 else if (functor
== _T("bitmap"))
546 item
= wxResourceInterpretBitmap(table
, clause
);
547 else if (functor
== _T("icon"))
548 item
= wxResourceInterpretIcon(table
, clause
);
552 // Remove any existing resource of same name
553 if (item
->GetName() != _T(""))
554 table
.DeleteResource(item
->GetName());
555 table
.AddResource(item
);
562 static const wxChar
*g_ValidControlClasses
[] =
565 _T("wxBitmapButton"),
568 _T("wxStaticBitmap"),
576 _T("wxBitmapCheckBox"),
586 static bool wxIsValidControlClass(const wxString
& c
)
588 for ( size_t i
= 0; i
< WXSIZEOF(g_ValidControlClasses
); i
++ )
590 if ( c
== g_ValidControlClasses
[i
] )
596 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
)
598 wxItemResource
*dialogItem
= new wxItemResource
;
600 dialogItem
->SetType(_T("wxPanel"));
602 dialogItem
->SetType(_T("wxDialog"));
603 wxString style
= _T("");
604 wxString title
= _T("");
605 wxString name
= _T("");
606 wxString backColourHex
= _T("");
607 wxString labelColourHex
= _T("");
608 wxString buttonColourHex
= _T("");
610 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
614 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
616 wxExpr
*labelFontExpr
= (wxExpr
*) NULL
;
617 wxExpr
*buttonFontExpr
= (wxExpr
*) NULL
;
618 wxExpr
*fontExpr
= (wxExpr
*) NULL
;
619 expr
->GetAttributeValue(_T("style"), style
);
620 expr
->GetAttributeValue(_T("name"), name
);
621 expr
->GetAttributeValue(_T("title"), title
);
622 expr
->GetAttributeValue(_T("x"), x
);
623 expr
->GetAttributeValue(_T("y"), y
);
624 expr
->GetAttributeValue(_T("width"), width
);
625 expr
->GetAttributeValue(_T("height"), height
);
626 expr
->GetAttributeValue(_T("modal"), isModal
);
627 expr
->GetAttributeValue(_T("label_font"), &labelFontExpr
);
628 expr
->GetAttributeValue(_T("button_font"), &buttonFontExpr
);
629 expr
->GetAttributeValue(_T("font"), &fontExpr
);
630 expr
->GetAttributeValue(_T("background_colour"), backColourHex
);
631 expr
->GetAttributeValue(_T("label_colour"), labelColourHex
);
632 expr
->GetAttributeValue(_T("button_colour"), buttonColourHex
);
634 int useDialogUnits
= 0;
635 expr
->GetAttributeValue(_T("use_dialog_units"), useDialogUnits
);
636 if (useDialogUnits
!= 0)
637 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS
);
640 expr
->GetAttributeValue(_T("use_system_defaults"), useDefaults
);
641 if (useDefaults
!= 0)
642 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS
);
645 expr
->GetAttributeValue(_T("id"), id
);
646 dialogItem
->SetId(id
);
650 windowStyle
= wxParseWindowStyle(style
);
652 dialogItem
->SetStyle(windowStyle
);
653 dialogItem
->SetValue1(isModal
);
654 dialogItem
->SetName(name
);
655 dialogItem
->SetTitle(title
);
656 dialogItem
->SetSize(x
, y
, width
, height
);
658 if (backColourHex
!= _T(""))
663 r
= wxHexToDec(backColourHex
.Mid(0, 2));
664 g
= wxHexToDec(backColourHex
.Mid(2, 2));
665 b
= wxHexToDec(backColourHex
.Mid(4, 2));
666 dialogItem
->SetBackgroundColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
668 if (labelColourHex
!= _T(""))
673 r
= wxHexToDec(labelColourHex
.Mid(0, 2));
674 g
= wxHexToDec(labelColourHex
.Mid(2, 2));
675 b
= wxHexToDec(labelColourHex
.Mid(4, 2));
676 dialogItem
->SetLabelColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
678 if (buttonColourHex
!= _T(""))
683 r
= wxHexToDec(buttonColourHex
.Mid(0, 2));
684 g
= wxHexToDec(buttonColourHex
.Mid(2, 2));
685 b
= wxHexToDec(buttonColourHex
.Mid(4, 2));
686 dialogItem
->SetButtonColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
690 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
691 else if (buttonFontExpr
)
692 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
693 else if (labelFontExpr
)
694 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
696 // Now parse all controls
697 wxExpr
*controlExpr
= expr
->GetFirst();
700 if (controlExpr
->Number() == 3)
702 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
703 if (controlKeyword
!= _T("") && controlKeyword
== _T("control"))
705 // The value part: always a list.
706 wxExpr
*listExpr
= controlExpr
->Nth(2);
707 if (listExpr
->Type() == PrologList
)
709 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
712 dialogItem
->GetChildren().Append(controlItem
);
717 controlExpr
= controlExpr
->GetNext();
722 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
)
724 wxItemResource
*controlItem
= new wxItemResource
;
726 // First, find the standard features of a control definition:
727 // [optional integer/string id], control name, title, style, name, x, y, width, height
729 wxString controlType
;
734 long windowStyle
= 0;
735 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
738 wxExpr
*expr1
= expr
->Nth(0);
740 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
742 if ( wxIsValidControlClass(expr1
->StringValue()) )
745 controlType
= expr1
->StringValue();
749 wxString
str(expr1
->StringValue());
750 id
= wxResourceGetIdentifier(str
, &table
);
753 wxLogWarning(_("Could not resolve control class or id '%s'. "
754 "Use (non-zero) integer instead\n or provide #define "
755 "(see manual for caveats)"),
756 (const wxChar
*) expr1
->StringValue());
758 return (wxItemResource
*) NULL
;
762 // Success - we have an id, so the 2nd element must be the control class.
763 controlType
= expr
->Nth(1)->StringValue();
768 else if (expr1
->Type() == PrologInteger
)
770 id
= (int)expr1
->IntegerValue();
771 // Success - we have an id, so the 2nd element must be the control class.
772 controlType
= expr
->Nth(1)->StringValue();
776 expr1
= expr
->Nth(count
);
779 title
= expr1
->StringValue();
781 expr1
= expr
->Nth(count
);
785 style
= expr1
->StringValue();
786 windowStyle
= wxParseWindowStyle(style
);
789 expr1
= expr
->Nth(count
);
792 name
= expr1
->StringValue();
794 expr1
= expr
->Nth(count
);
797 x
= (int)expr1
->IntegerValue();
799 expr1
= expr
->Nth(count
);
802 y
= (int)expr1
->IntegerValue();
804 expr1
= expr
->Nth(count
);
807 width
= (int)expr1
->IntegerValue();
809 expr1
= expr
->Nth(count
);
812 height
= (int)expr1
->IntegerValue();
814 controlItem
->SetStyle(windowStyle
);
815 controlItem
->SetName(name
);
816 controlItem
->SetTitle(title
);
817 controlItem
->SetSize(x
, y
, width
, height
);
818 controlItem
->SetType(controlType
);
819 controlItem
->SetId(id
);
821 if (controlType
== _T("wxButton"))
823 // Check for bitmap resource name (in case loading old-style resource file)
824 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
826 wxString
str(expr
->Nth(count
)->StringValue());
831 controlItem
->SetValue4(str
);
832 controlItem
->SetType(_T("wxBitmapButton"));
835 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
836 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
838 else if (controlType
== _T("wxBitmapButton"))
840 // Check for bitmap resource name
841 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
843 wxString
str(expr
->Nth(count
)->StringValue());
844 controlItem
->SetValue4(str
);
846 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
847 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
850 else if (controlType
== _T("wxCheckBox"))
852 // Check for default value
853 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
855 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
857 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
858 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
861 #if wxUSE_RADIOBUTTON
862 else if (controlType
== _T("wxRadioButton"))
864 // Check for default value
865 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
867 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
869 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
870 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
874 else if (controlType
== _T("wxText") || controlType
== _T("wxTextCtrl") || controlType
== _T("wxMultiText"))
876 // Check for default value
877 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
879 wxString
str(expr
->Nth(count
)->StringValue());
880 controlItem
->SetValue4(str
);
883 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
885 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
886 // Do nothing - no label font any more
888 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
889 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
893 else if (controlType
== _T("wxMessage") || controlType
== _T("wxStaticText"))
895 // Check for bitmap resource name (in case it's an old-style .wxr file)
896 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
898 wxString
str(expr
->Nth(count
)->StringValue());
899 controlItem
->SetValue4(str
);
901 controlItem
->SetType(_T("wxStaticText"));
903 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
904 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
906 else if (controlType
== _T("wxStaticBitmap"))
908 // Check for bitmap resource name
909 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
911 wxString
str(expr
->Nth(count
)->StringValue());
912 controlItem
->SetValue4(str
);
915 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
916 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
918 else if (controlType
== _T("wxGroupBox") || controlType
== _T("wxStaticBox"))
920 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
921 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
923 else if (controlType
== _T("wxGauge"))
925 // Check for default value
926 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
928 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
932 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
934 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
937 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
939 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
943 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
944 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
949 else if (controlType
== _T("wxSlider"))
951 // Check for default value
952 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
954 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
958 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
960 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
964 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
966 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
969 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
971 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
975 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
976 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
982 else if (controlType
== _T("wxScrollBar"))
985 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
987 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
991 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
993 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
997 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
999 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1003 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1004 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
1009 else if (controlType
== _T("wxListBox"))
1011 wxExpr
*valueList
= (wxExpr
*) NULL
;
1013 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1015 wxStringList stringList
;
1016 wxExpr
*stringExpr
= valueList
->GetFirst();
1019 stringList
.Add(stringExpr
->StringValue());
1020 stringExpr
= stringExpr
->GetNext();
1022 controlItem
->SetStringValues(stringList
);
1024 // This is now obsolete: it's in the window style.
1025 // Check for wxSINGLE/wxMULTIPLE
1026 wxExpr
*mult
= (wxExpr
*) NULL
;
1028 controlItem->SetValue1(wxLB_SINGLE);
1030 if ((mult
= expr
->Nth(count
)) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1033 wxString m(mult->StringValue());
1034 if (m == "wxLB_MULTIPLE")
1035 controlItem->SetValue1(wxLB_MULTIPLE);
1036 else if (m == "wxLB_EXTENDED")
1037 controlItem->SetValue1(wxLB_EXTENDED);
1042 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1044 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1046 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1047 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1051 else if (controlType
== _T("wxChoice"))
1053 wxExpr
*valueList
= (wxExpr
*) NULL
;
1054 // Check for default value list
1055 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1057 wxStringList stringList
;
1058 wxExpr
*stringExpr
= valueList
->GetFirst();
1061 stringList
.Add(stringExpr
->StringValue());
1062 stringExpr
= stringExpr
->GetNext();
1064 controlItem
->SetStringValues(stringList
);
1068 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1070 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1073 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1074 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1079 else if (controlType
== _T("wxComboBox"))
1081 wxExpr
*textValue
= expr
->Nth(count
);
1082 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1084 wxString
str(textValue
->StringValue());
1085 controlItem
->SetValue4(str
);
1089 wxExpr
*valueList
= (wxExpr
*) NULL
;
1090 // Check for default value list
1091 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1093 wxStringList stringList
;
1094 wxExpr
*stringExpr
= valueList
->GetFirst();
1097 stringList
.Add(stringExpr
->StringValue());
1098 stringExpr
= stringExpr
->GetNext();
1100 controlItem
->SetStringValues(stringList
);
1104 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1106 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1109 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1110 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1117 else if (controlType
== _T("wxRadioBox"))
1119 wxExpr
*valueList
= (wxExpr
*) NULL
;
1120 // Check for default value list
1121 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1123 wxStringList stringList
;
1124 wxExpr
*stringExpr
= valueList
->GetFirst();
1127 stringList
.Add(stringExpr
->StringValue());
1128 stringExpr
= stringExpr
->GetNext();
1130 controlItem
->SetStringValues(stringList
);
1133 // majorDim (number of rows or cols)
1134 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1136 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1140 controlItem
->SetValue1(0);
1142 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1144 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1147 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1148 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1156 return (wxItemResource
*) NULL
;
1161 // Forward declaration
1162 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, wxExpr
*expr
);
1165 * Interpet a menu item
1168 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, wxExpr
*expr
)
1170 wxItemResource
*item
= new wxItemResource
;
1172 wxExpr
*labelExpr
= expr
->Nth(0);
1173 wxExpr
*idExpr
= expr
->Nth(1);
1174 wxExpr
*helpExpr
= expr
->Nth(2);
1175 wxExpr
*checkableExpr
= expr
->Nth(3);
1177 // Further keywords/attributes to follow sometime...
1178 if (expr
->Number() == 0)
1180 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1181 item
->SetType(_T("wxMenuSeparator"));
1186 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1187 item
->SetType(_T("wxMenu")); // Well, menu item, but doesn't matter.
1190 wxString
str(labelExpr
->StringValue());
1191 item
->SetTitle(str
);
1196 // If a string or word, must look up in identifier table.
1197 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1199 wxString
str(idExpr
->StringValue());
1200 id
= wxResourceGetIdentifier(str
, &table
);
1203 wxLogWarning(_("Could not resolve menu id '%s'. "
1204 "Use (non-zero) integer instead\n"
1205 "or provide #define (see manual for caveats)"),
1206 (const wxChar
*) idExpr
->StringValue());
1209 else if (idExpr
->Type() == PrologInteger
)
1210 id
= (int)idExpr
->IntegerValue();
1211 item
->SetValue1(id
);
1215 wxString
str(helpExpr
->StringValue());
1216 item
->SetValue4(str
);
1219 item
->SetValue2(checkableExpr
->IntegerValue());
1221 // Find the first expression that's a list, for submenu
1222 wxExpr
*subMenuExpr
= expr
->GetFirst();
1223 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1224 subMenuExpr
= subMenuExpr
->GetNext();
1228 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1229 item
->GetChildren().Append(child
);
1230 subMenuExpr
= subMenuExpr
->GetNext();
1237 * Interpret a nested list as a menu
1240 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1242 wxItemResource *menu = new wxItemResource;
1243 // menu->SetType(wxTYPE_MENU);
1244 menu->SetType("wxMenu");
1245 wxExpr *element = expr->GetFirst();
1248 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1250 menu->GetChildren().Append(item);
1251 element = element->GetNext();
1257 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
)
1259 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1260 expr
->GetAttributeValue(_T("menu"), &listExpr
);
1262 return (wxItemResource
*) NULL
;
1264 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1267 return (wxItemResource
*) NULL
;
1270 if (expr
->GetAttributeValue(_T("name"), name
))
1272 menuResource
->SetName(name
);
1275 return menuResource
;
1278 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
)
1280 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1281 expr
->GetAttributeValue(_T("menu"), &listExpr
);
1283 return (wxItemResource
*) NULL
;
1285 wxItemResource
*resource
= new wxItemResource
;
1286 resource
->SetType(_T("wxMenu"));
1287 // resource->SetType(wxTYPE_MENU);
1289 wxExpr
*element
= listExpr
->GetFirst();
1292 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1293 resource
->GetChildren().Append(menuResource
);
1294 element
= element
->GetNext();
1298 if (expr
->GetAttributeValue(_T("name"), name
))
1300 resource
->SetName(name
);
1306 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), wxExpr
*WXUNUSED(expr
))
1308 return (wxItemResource
*) NULL
;
1311 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), wxExpr
*expr
)
1313 wxItemResource
*bitmapItem
= new wxItemResource
;
1314 // bitmapItem->SetType(wxTYPE_BITMAP);
1315 bitmapItem
->SetType(_T("wxBitmap"));
1317 if (expr
->GetAttributeValue(_T("name"), name
))
1319 bitmapItem
->SetName(name
);
1321 // Now parse all bitmap specifications
1322 wxExpr
*bitmapExpr
= expr
->GetFirst();
1325 if (bitmapExpr
->Number() == 3)
1327 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1328 if (bitmapKeyword
== _T("bitmap") || bitmapKeyword
== _T("icon"))
1330 // The value part: always a list.
1331 wxExpr
*listExpr
= bitmapExpr
->Nth(2);
1332 if (listExpr
->Type() == PrologList
)
1334 wxItemResource
*bitmapSpec
= new wxItemResource
;
1335 // bitmapSpec->SetType(wxTYPE_BITMAP);
1336 bitmapSpec
->SetType(_T("wxBitmap"));
1338 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1339 // where everything after 'filename' is optional.
1340 wxExpr
*nameExpr
= listExpr
->Nth(0);
1341 wxExpr
*typeExpr
= listExpr
->Nth(1);
1342 wxExpr
*platformExpr
= listExpr
->Nth(2);
1343 wxExpr
*coloursExpr
= listExpr
->Nth(3);
1344 wxExpr
*xresExpr
= listExpr
->Nth(4);
1345 wxExpr
*yresExpr
= listExpr
->Nth(5);
1346 if (nameExpr
&& nameExpr
->StringValue() != _T(""))
1348 bitmapSpec
->SetName(nameExpr
->StringValue());
1350 if (typeExpr
&& typeExpr
->StringValue() != _T(""))
1352 bitmapSpec
->SetValue1(wxParseWindowStyle(typeExpr
->StringValue()));
1355 bitmapSpec
->SetValue1(0);
1357 if (platformExpr
&& platformExpr
->StringValue() != _T(""))
1359 wxString
plat(platformExpr
->StringValue());
1360 if (plat
== _T("windows") || plat
== _T("WINDOWS"))
1361 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1362 else if (plat
== _T("x") || plat
== _T("X"))
1363 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1364 else if (plat
== _T("mac") || plat
== _T("MAC"))
1365 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1367 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1370 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1373 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1377 xres
= (int)xresExpr
->IntegerValue();
1379 yres
= (int)yresExpr
->IntegerValue();
1380 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1382 bitmapItem
->GetChildren().Append(bitmapSpec
);
1386 bitmapExpr
= bitmapExpr
->GetNext();
1392 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
)
1394 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1397 // item->SetType(wxTYPE_ICON);
1398 item
->SetType(_T("wxIcon"));
1402 return (wxItemResource
*) NULL
;
1405 // Interpret list expression as a font
1406 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
)
1408 if (expr
->Type() != PrologList
)
1412 int family
= wxSWISS
;
1413 int style
= wxNORMAL
;
1414 int weight
= wxNORMAL
;
1416 wxString
faceName(_T(""));
1418 wxExpr
*pointExpr
= expr
->Nth(0);
1419 wxExpr
*familyExpr
= expr
->Nth(1);
1420 wxExpr
*styleExpr
= expr
->Nth(2);
1421 wxExpr
*weightExpr
= expr
->Nth(3);
1422 wxExpr
*underlineExpr
= expr
->Nth(4);
1423 wxExpr
*faceNameExpr
= expr
->Nth(5);
1425 point
= (int)pointExpr
->IntegerValue();
1430 str
= familyExpr
->StringValue();
1431 family
= (int)wxParseWindowStyle(str
);
1435 str
= styleExpr
->StringValue();
1436 style
= (int)wxParseWindowStyle(str
);
1440 str
= weightExpr
->StringValue();
1441 weight
= (int)wxParseWindowStyle(str
);
1444 underline
= (int)underlineExpr
->IntegerValue();
1446 faceName
= faceNameExpr
->StringValue();
1448 wxFont
font(point
, family
, style
, weight
, (underline
!= 0), faceName
);
1452 // Separate file for the remainder of this, for BC++/Win16
1454 #if !((defined(__BORLANDC__) || defined(__SC__)) && defined(__WIN16__))
1456 * (Re)allocate buffer for reading in from resource file
1459 bool wxReallocateResourceBuffer()
1461 if (!wxResourceBuffer
)
1463 wxResourceBufferSize
= 1000;
1464 wxResourceBuffer
= new char[wxResourceBufferSize
];
1467 if (wxResourceBuffer
)
1469 long newSize
= wxResourceBufferSize
+ 1000;
1470 char *tmp
= new char[(int)newSize
];
1471 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1472 delete[] wxResourceBuffer
;
1473 wxResourceBuffer
= tmp
;
1474 wxResourceBufferSize
= newSize
;
1479 static bool wxEatWhiteSpace(FILE *fd
)
1483 while ((ch
= getc(fd
)) != EOF
)
1498 ungetc(prev_ch
, fd
);
1506 while ((ch
= getc(fd
)) != EOF
)
1508 if (ch
== '/' && prev_ch
== '*')
1516 static char buffer
[255];
1517 fgets(buffer
, 255, fd
);
1521 ungetc(prev_ch
, fd
);
1536 bool wxGetResourceToken(FILE *fd
)
1538 if (!wxResourceBuffer
)
1539 wxReallocateResourceBuffer();
1540 wxResourceBuffer
[0] = 0;
1541 wxEatWhiteSpace(fd
);
1547 wxResourceBufferCount
= 0;
1554 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1557 // Escaped characters
1558 else if (ch
== '\\')
1560 int newCh
= getc(fd
);
1563 else if (newCh
== 10)
1571 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1572 wxReallocateResourceBuffer();
1573 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1574 wxResourceBufferCount
++;
1577 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1581 wxResourceBufferCount
= 0;
1583 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1585 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1586 wxReallocateResourceBuffer();
1587 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1588 wxResourceBufferCount
++;
1592 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1600 * Files are in form:
1601 static char *name = "....";
1602 with possible comments.
1605 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1608 table
= wxDefaultResourceTable
;
1610 // static or #define
1611 if (!wxGetResourceToken(fd
))
1617 if (strcmp(wxResourceBuffer
, "#define") == 0)
1619 wxGetResourceToken(fd
);
1620 wxChar
*name
= copystring(wxConv_libc
.cMB2WX(wxResourceBuffer
));
1621 wxGetResourceToken(fd
);
1622 wxChar
*value
= copystring(wxConv_libc
.cMB2WX(wxResourceBuffer
));
1623 if (wxIsalpha(value
[0]))
1625 int val
= (int)wxAtol(value
);
1626 wxResourceAddIdentifier(name
, val
, table
);
1630 wxLogWarning(_("#define %s must be an integer."), name
);
1640 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1642 wxGetResourceToken(fd
);
1643 wxChar
*name
= copystring(wxConv_libc
.cMB2WX(wxResourceBuffer
));
1644 wxChar
*actualName
= name
;
1645 if (name
[0] == _T('"'))
1646 actualName
= name
+ 1;
1647 int len
= wxStrlen(name
);
1648 if ((len
> 0) && (name
[len
-1] == _T('"')))
1650 if (!wxResourceParseIncludeFile(actualName
, table
))
1652 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1657 else if (strcmp(wxResourceBuffer
, "static") != 0)
1660 wxStrcpy(buf
, _("Found "));
1661 wxStrncat(buf
, wxConv_libc
.cMB2WX(wxResourceBuffer
), 30);
1662 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1668 if (!wxGetResourceToken(fd
))
1670 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1675 if (strcmp(wxResourceBuffer
, "char") != 0)
1677 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1682 if (!wxGetResourceToken(fd
))
1684 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1689 if (wxResourceBuffer
[0] != '*')
1691 wxLogWarning(_("Expected '*' whilst parsing resource."));
1694 wxChar nameBuf
[100];
1695 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
1699 if (!wxGetResourceToken(fd
))
1701 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1706 if (strcmp(wxResourceBuffer
, "=") != 0)
1708 wxLogWarning(_("Expected '=' whilst parsing resource."));
1713 if (!wxGetResourceToken(fd
))
1715 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1721 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1723 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1728 if (!wxGetResourceToken(fd
))
1736 * Parses string window style into integer window style
1740 * Style flag parsing, e.g.
1741 * "wxSYSTEM_MENU | wxBORDER" -> integer
1744 wxChar
* wxResourceParseWord(wxChar
*s
, int *i
)
1747 return (wxChar
*) NULL
;
1749 static wxChar buf
[150];
1750 int len
= wxStrlen(s
);
1753 while ((ii
< len
) && (wxIsalpha(s
[ii
]) || (s
[ii
] == _T('_'))))
1761 // Eat whitespace and conjunction characters
1762 while ((ii
< len
) &&
1763 ((s
[ii
] == _T(' ')) || (s
[ii
] == _T('|')) || (s
[ii
] == _T(','))))
1769 return (wxChar
*) NULL
;
1774 struct wxResourceBitListStruct
1780 static wxResourceBitListStruct wxResourceBitListTable
[] =
1783 { _T("wxSINGLE"), wxLB_SINGLE
},
1784 { _T("wxMULTIPLE"), wxLB_MULTIPLE
},
1785 { _T("wxEXTENDED"), wxLB_EXTENDED
},
1786 { _T("wxLB_SINGLE"), wxLB_SINGLE
},
1787 { _T("wxLB_MULTIPLE"), wxLB_MULTIPLE
},
1788 { _T("wxLB_EXTENDED"), wxLB_EXTENDED
},
1789 { _T("wxLB_NEEDED_SB"), wxLB_NEEDED_SB
},
1790 { _T("wxLB_ALWAYS_SB"), wxLB_ALWAYS_SB
},
1791 { _T("wxLB_SORT"), wxLB_SORT
},
1792 { _T("wxLB_OWNERDRAW"), wxLB_OWNERDRAW
},
1793 { _T("wxLB_HSCROLL"), wxLB_HSCROLL
},
1796 { _T("wxCB_SIMPLE"), wxCB_SIMPLE
},
1797 { _T("wxCB_DROPDOWN"), wxCB_DROPDOWN
},
1798 { _T("wxCB_READONLY"), wxCB_READONLY
},
1799 { _T("wxCB_SORT"), wxCB_SORT
},
1802 { _T("wxGA_PROGRESSBAR"), wxGA_PROGRESSBAR
},
1803 { _T("wxGA_HORIZONTAL"), wxGA_HORIZONTAL
},
1804 { _T("wxGA_VERTICAL"), wxGA_VERTICAL
},
1807 { _T("wxPASSWORD"), wxPASSWORD
},
1808 { _T("wxPROCESS_ENTER"), wxPROCESS_ENTER
},
1809 { _T("wxTE_PASSWORD"), wxTE_PASSWORD
},
1810 { _T("wxTE_READONLY"), wxTE_READONLY
},
1811 { _T("wxTE_PROCESS_ENTER"), wxTE_PROCESS_ENTER
},
1812 { _T("wxTE_MULTILINE"), wxTE_MULTILINE
},
1814 /* wxRadioBox/wxRadioButton */
1815 { _T("wxRB_GROUP"), wxRB_GROUP
},
1816 { _T("wxRA_SPECIFY_COLS"), wxRA_SPECIFY_COLS
},
1817 { _T("wxRA_SPECIFY_ROWS"), wxRA_SPECIFY_ROWS
},
1818 { _T("wxRA_HORIZONTAL"), wxRA_HORIZONTAL
},
1819 { _T("wxRA_VERTICAL"), wxRA_VERTICAL
},
1822 { _T("wxSL_HORIZONTAL"), wxSL_HORIZONTAL
},
1823 { _T("wxSL_VERTICAL"), wxSL_VERTICAL
},
1824 { _T("wxSL_AUTOTICKS"), wxSL_AUTOTICKS
},
1825 { _T("wxSL_LABELS"), wxSL_LABELS
},
1826 { _T("wxSL_LEFT"), wxSL_LEFT
},
1827 { _T("wxSL_TOP"), wxSL_TOP
},
1828 { _T("wxSL_RIGHT"), wxSL_RIGHT
},
1829 { _T("wxSL_BOTTOM"), wxSL_BOTTOM
},
1830 { _T("wxSL_BOTH"), wxSL_BOTH
},
1831 { _T("wxSL_SELRANGE"), wxSL_SELRANGE
},
1834 { _T("wxSB_HORIZONTAL"), wxSB_HORIZONTAL
},
1835 { _T("wxSB_VERTICAL"), wxSB_VERTICAL
},
1838 { _T("wxBU_AUTODRAW"), wxBU_AUTODRAW
},
1839 { _T("wxBU_NOAUTODRAW"), wxBU_NOAUTODRAW
},
1842 { _T("wxTR_HAS_BUTTONS"), wxTR_HAS_BUTTONS
},
1843 { _T("wxTR_EDIT_LABELS"), wxTR_EDIT_LABELS
},
1844 { _T("wxTR_LINES_AT_ROOT"), wxTR_LINES_AT_ROOT
},
1847 { _T("wxLC_ICON"), wxLC_ICON
},
1848 { _T("wxLC_SMALL_ICON"), wxLC_SMALL_ICON
},
1849 { _T("wxLC_LIST"), wxLC_LIST
},
1850 { _T("wxLC_REPORT"), wxLC_REPORT
},
1851 { _T("wxLC_ALIGN_TOP"), wxLC_ALIGN_TOP
},
1852 { _T("wxLC_ALIGN_LEFT"), wxLC_ALIGN_LEFT
},
1853 { _T("wxLC_AUTOARRANGE"), wxLC_AUTOARRANGE
},
1854 { _T("wxLC_USER_TEXT"), wxLC_USER_TEXT
},
1855 { _T("wxLC_EDIT_LABELS"), wxLC_EDIT_LABELS
},
1856 { _T("wxLC_NO_HEADER"), wxLC_NO_HEADER
},
1857 { _T("wxLC_NO_SORT_HEADER"), wxLC_NO_SORT_HEADER
},
1858 { _T("wxLC_SINGLE_SEL"), wxLC_SINGLE_SEL
},
1859 { _T("wxLC_SORT_ASCENDING"), wxLC_SORT_ASCENDING
},
1860 { _T("wxLC_SORT_DESCENDING"), wxLC_SORT_DESCENDING
},
1863 { _T("wxSP_VERTICAL"), wxSP_VERTICAL
},
1864 { _T("wxSP_HORIZONTAL"), wxSP_HORIZONTAL
},
1865 { _T("wxSP_ARROW_KEYS"), wxSP_ARROW_KEYS
},
1866 { _T("wxSP_WRAP"), wxSP_WRAP
},
1869 { _T("wxSP_NOBORDER"), wxSP_NOBORDER
},
1870 { _T("wxSP_3D"), wxSP_3D
},
1871 { _T("wxSP_BORDER"), wxSP_BORDER
},
1874 { _T("wxTC_MULTILINE"), wxTC_MULTILINE
},
1875 { _T("wxTC_RIGHTJUSTIFY"), wxTC_RIGHTJUSTIFY
},
1876 { _T("wxTC_FIXEDWIDTH"), wxTC_FIXEDWIDTH
},
1877 { _T("wxTC_OWNERDRAW"), wxTC_OWNERDRAW
},
1880 { _T("wxST_SIZEGRIP"), wxST_SIZEGRIP
},
1883 { _T("wxFIXED_LENGTH"), wxFIXED_LENGTH
},
1884 { _T("wxALIGN_LEFT"), wxALIGN_LEFT
},
1885 { _T("wxALIGN_CENTER"), wxALIGN_CENTER
},
1886 { _T("wxALIGN_CENTRE"), wxALIGN_CENTRE
},
1887 { _T("wxALIGN_RIGHT"), wxALIGN_RIGHT
},
1888 { _T("wxCOLOURED"), wxCOLOURED
},
1891 { _T("wxTB_3DBUTTONS"), wxTB_3DBUTTONS
},
1892 { _T("wxTB_HORIZONTAL"), wxTB_HORIZONTAL
},
1893 { _T("wxTB_VERTICAL"), wxTB_VERTICAL
},
1894 { _T("wxTB_FLAT"), wxTB_FLAT
},
1897 { _T("wxVSCROLL"), wxVSCROLL
},
1898 { _T("wxHSCROLL"), wxHSCROLL
},
1899 { _T("wxCAPTION"), wxCAPTION
},
1900 { _T("wxSTAY_ON_TOP"), wxSTAY_ON_TOP
},
1901 { _T("wxICONIZE"), wxICONIZE
},
1902 { _T("wxMINIMIZE"), wxICONIZE
},
1903 { _T("wxMAXIMIZE"), wxMAXIMIZE
},
1905 { _T("wxMDI_PARENT"), 0},
1906 { _T("wxMDI_CHILD"), 0},
1907 { _T("wxTHICK_FRAME"), wxTHICK_FRAME
},
1908 { _T("wxRESIZE_BORDER"), wxRESIZE_BORDER
},
1909 { _T("wxSYSTEM_MENU"), wxSYSTEM_MENU
},
1910 { _T("wxMINIMIZE_BOX"), wxMINIMIZE_BOX
},
1911 { _T("wxMAXIMIZE_BOX"), wxMAXIMIZE_BOX
},
1912 { _T("wxRESIZE_BOX"), wxRESIZE_BOX
},
1913 { _T("wxDEFAULT_FRAME_STYLE"), wxDEFAULT_FRAME_STYLE
},
1914 { _T("wxDEFAULT_FRAME"), wxDEFAULT_FRAME_STYLE
},
1915 { _T("wxDEFAULT_DIALOG_STYLE"), wxDEFAULT_DIALOG_STYLE
},
1916 { _T("wxBORDER"), wxBORDER
},
1917 { _T("wxRETAINED"), wxRETAINED
},
1918 { _T("wxNATIVE_IMPL"), 0},
1919 { _T("wxEXTENDED_IMPL"), 0},
1920 { _T("wxBACKINGSTORE"), wxBACKINGSTORE
},
1921 // { _T("wxFLAT"), wxFLAT},
1922 // { _T("wxMOTIF_RESIZE"), wxMOTIF_RESIZE},
1923 { _T("wxFIXED_LENGTH"), 0},
1924 { _T("wxDOUBLE_BORDER"), wxDOUBLE_BORDER
},
1925 { _T("wxSUNKEN_BORDER"), wxSUNKEN_BORDER
},
1926 { _T("wxRAISED_BORDER"), wxRAISED_BORDER
},
1927 { _T("wxSIMPLE_BORDER"), wxSIMPLE_BORDER
},
1928 { _T("wxSTATIC_BORDER"), wxSTATIC_BORDER
},
1929 { _T("wxTRANSPARENT_WINDOW"), wxTRANSPARENT_WINDOW
},
1930 { _T("wxNO_BORDER"), wxNO_BORDER
},
1931 { _T("wxCLIP_CHILDREN"), wxCLIP_CHILDREN
},
1933 { _T("wxTINY_CAPTION_HORIZ"), wxTINY_CAPTION_HORIZ
},
1934 { _T("wxTINY_CAPTION_VERT"), wxTINY_CAPTION_VERT
},
1936 // Text font families
1937 { _T("wxDEFAULT"), wxDEFAULT
},
1938 { _T("wxDECORATIVE"), wxDECORATIVE
},
1939 { _T("wxROMAN"), wxROMAN
},
1940 { _T("wxSCRIPT"), wxSCRIPT
},
1941 { _T("wxSWISS"), wxSWISS
},
1942 { _T("wxMODERN"), wxMODERN
},
1943 { _T("wxTELETYPE"), wxTELETYPE
},
1944 { _T("wxVARIABLE"), wxVARIABLE
},
1945 { _T("wxFIXED"), wxFIXED
},
1946 { _T("wxNORMAL"), wxNORMAL
},
1947 { _T("wxLIGHT"), wxLIGHT
},
1948 { _T("wxBOLD"), wxBOLD
},
1949 { _T("wxITALIC"), wxITALIC
},
1950 { _T("wxSLANT"), wxSLANT
},
1951 { _T("wxSOLID"), wxSOLID
},
1952 { _T("wxDOT"), wxDOT
},
1953 { _T("wxLONG_DASH"), wxLONG_DASH
},
1954 { _T("wxSHORT_DASH"), wxSHORT_DASH
},
1955 { _T("wxDOT_DASH"), wxDOT_DASH
},
1956 { _T("wxUSER_DASH"), wxUSER_DASH
},
1957 { _T("wxTRANSPARENT"), wxTRANSPARENT
},
1958 { _T("wxSTIPPLE"), wxSTIPPLE
},
1959 { _T("wxBDIAGONAL_HATCH"), wxBDIAGONAL_HATCH
},
1960 { _T("wxCROSSDIAG_HATCH"), wxCROSSDIAG_HATCH
},
1961 { _T("wxFDIAGONAL_HATCH"), wxFDIAGONAL_HATCH
},
1962 { _T("wxCROSS_HATCH"), wxCROSS_HATCH
},
1963 { _T("wxHORIZONTAL_HATCH"), wxHORIZONTAL_HATCH
},
1964 { _T("wxVERTICAL_HATCH"), wxVERTICAL_HATCH
},
1965 { _T("wxJOIN_BEVEL"), wxJOIN_BEVEL
},
1966 { _T("wxJOIN_MITER"), wxJOIN_MITER
},
1967 { _T("wxJOIN_ROUND"), wxJOIN_ROUND
},
1968 { _T("wxCAP_ROUND"), wxCAP_ROUND
},
1969 { _T("wxCAP_PROJECTING"), wxCAP_PROJECTING
},
1970 { _T("wxCAP_BUTT"), wxCAP_BUTT
},
1973 { _T("wxCLEAR"), wxCLEAR
},
1974 { _T("wxXOR"), wxXOR
},
1975 { _T("wxINVERT"), wxINVERT
},
1976 { _T("wxOR_REVERSE"), wxOR_REVERSE
},
1977 { _T("wxAND_REVERSE"), wxAND_REVERSE
},
1978 { _T("wxCOPY"), wxCOPY
},
1979 { _T("wxAND"), wxAND
},
1980 { _T("wxAND_INVERT"), wxAND_INVERT
},
1981 { _T("wxNO_OP"), wxNO_OP
},
1982 { _T("wxNOR"), wxNOR
},
1983 { _T("wxEQUIV"), wxEQUIV
},
1984 { _T("wxSRC_INVERT"), wxSRC_INVERT
},
1985 { _T("wxOR_INVERT"), wxOR_INVERT
},
1986 { _T("wxNAND"), wxNAND
},
1987 { _T("wxOR"), wxOR
},
1988 { _T("wxSET"), wxSET
},
1990 { _T("wxFLOOD_SURFACE"), wxFLOOD_SURFACE
},
1991 { _T("wxFLOOD_BORDER"), wxFLOOD_BORDER
},
1992 { _T("wxODDEVEN_RULE"), wxODDEVEN_RULE
},
1993 { _T("wxWINDING_RULE"), wxWINDING_RULE
},
1994 { _T("wxHORIZONTAL"), wxHORIZONTAL
},
1995 { _T("wxVERTICAL"), wxVERTICAL
},
1996 { _T("wxBOTH"), wxBOTH
},
1997 { _T("wxCENTER_FRAME"), wxCENTER_FRAME
},
1998 { _T("wxOK"), wxOK
},
1999 { _T("wxYES_NO"), wxYES_NO
},
2000 { _T("wxCANCEL"), wxCANCEL
},
2001 { _T("wxYES"), wxYES
},
2002 { _T("wxNO"), wxNO
},
2003 { _T("wxICON_EXCLAMATION"), wxICON_EXCLAMATION
},
2004 { _T("wxICON_HAND"), wxICON_HAND
},
2005 { _T("wxICON_QUESTION"), wxICON_QUESTION
},
2006 { _T("wxICON_INFORMATION"), wxICON_INFORMATION
},
2007 { _T("wxICON_STOP"), wxICON_STOP
},
2008 { _T("wxICON_ASTERISK"), wxICON_ASTERISK
},
2009 { _T("wxICON_MASK"), wxICON_MASK
},
2010 { _T("wxCENTRE"), wxCENTRE
},
2011 { _T("wxCENTER"), wxCENTRE
},
2012 { _T("wxUSER_COLOURS"), wxUSER_COLOURS
},
2013 { _T("wxVERTICAL_LABEL"), 0},
2014 { _T("wxHORIZONTAL_LABEL"), 0},
2016 // Bitmap types (not strictly styles)
2017 { _T("wxBITMAP_TYPE_XPM"), wxBITMAP_TYPE_XPM
},
2018 { _T("wxBITMAP_TYPE_XBM"), wxBITMAP_TYPE_XBM
},
2019 { _T("wxBITMAP_TYPE_BMP"), wxBITMAP_TYPE_BMP
},
2020 { _T("wxBITMAP_TYPE_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2021 { _T("wxBITMAP_TYPE_BMP_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2022 { _T("wxBITMAP_TYPE_GIF"), wxBITMAP_TYPE_GIF
},
2023 { _T("wxBITMAP_TYPE_TIF"), wxBITMAP_TYPE_TIF
},
2024 { _T("wxBITMAP_TYPE_ICO"), wxBITMAP_TYPE_ICO
},
2025 { _T("wxBITMAP_TYPE_ICO_RESOURCE"), wxBITMAP_TYPE_ICO_RESOURCE
},
2026 { _T("wxBITMAP_TYPE_CUR"), wxBITMAP_TYPE_CUR
},
2027 { _T("wxBITMAP_TYPE_CUR_RESOURCE"), wxBITMAP_TYPE_CUR_RESOURCE
},
2028 { _T("wxBITMAP_TYPE_XBM_DATA"), wxBITMAP_TYPE_XBM_DATA
},
2029 { _T("wxBITMAP_TYPE_XPM_DATA"), wxBITMAP_TYPE_XPM_DATA
},
2030 { _T("wxBITMAP_TYPE_ANY"), wxBITMAP_TYPE_ANY
}
2033 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
2035 long wxParseWindowStyle(const wxString
& bitListString
)
2040 while ((word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
)))
2044 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2045 if (wxStrcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2047 bitList
|= wxResourceBitListTable
[j
].bits
;
2053 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word
);
2061 * Load a bitmap from a wxWindows resource, choosing an optimum
2062 * depth and appropriate type.
2065 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
2068 table
= wxDefaultResourceTable
;
2070 wxItemResource
*item
= table
->FindResource(resource
);
2073 if ((item
->GetType() == _T("")) || (item
->GetType() != _T("wxBitmap")))
2075 wxLogWarning(_("%s not a bitmap resource specification."), (const wxChar
*) resource
);
2076 return wxNullBitmap
;
2078 int thisDepth
= wxDisplayDepth();
2079 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2081 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2083 // Try to find optimum bitmap for this platform/colour depth
2084 wxNode
*node
= item
->GetChildren().First();
2087 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2088 int platform
= (int)child
->GetValue2();
2089 int noColours
= (int)child
->GetValue3();
2091 char *name = child->GetName();
2092 int bitmapType = (int)child->GetValue1();
2093 int xRes = child->GetWidth();
2094 int yRes = child->GetHeight();
2099 case RESOURCE_PLATFORM_ANY
:
2101 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2102 optResource
= child
;
2105 // Maximise the number of colours.
2106 // If noColours is zero (unspecified), then assume this
2107 // is the right one.
2108 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2109 optResource
= child
;
2114 case RESOURCE_PLATFORM_WINDOWS
:
2116 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2117 optResource
= child
;
2120 // Maximise the number of colours
2121 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2122 optResource
= child
;
2128 case RESOURCE_PLATFORM_X
:
2130 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2131 optResource
= child
;
2134 // Maximise the number of colours
2135 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2136 optResource
= child
;
2142 case RESOURCE_PLATFORM_MAC
:
2144 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2145 optResource
= child
;
2148 // Maximise the number of colours
2149 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2150 optResource
= child
;
2158 node
= node
->Next();
2160 // If no matching resource, fail.
2162 return wxNullBitmap
;
2164 wxString name
= optResource
->GetName();
2165 int bitmapType
= (int)optResource
->GetValue1();
2168 case wxBITMAP_TYPE_XBM_DATA
:
2171 wxItemResource
*item
= table
->FindResource(name
);
2174 wxLogWarning(_("Failed to find XBM resource %s.\n"
2175 "Forgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2176 return wxNullBitmap
;
2178 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2180 wxLogWarning(_("No XBM facility available!"));
2184 case wxBITMAP_TYPE_XPM_DATA
:
2186 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2187 wxItemResource
*item
= table
->FindResource(name
);
2190 wxLogWarning(_("Failed to find XPM resource %s.\n"
2191 "Forgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2192 return wxNullBitmap
;
2194 return wxBitmap((char **)item
->GetValue1());
2196 wxLogWarning(_("No XPM facility available!"));
2202 return wxBitmap(name
, bitmapType
);
2206 return wxNullBitmap
;
2210 wxLogWarning(_("Bitmap resource specification %s not found."), (const wxChar
*) resource
);
2211 return wxNullBitmap
;
2216 * Load an icon from a wxWindows resource, choosing an optimum
2217 * depth and appropriate type.
2220 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2223 table
= wxDefaultResourceTable
;
2225 wxItemResource
*item
= table
->FindResource(resource
);
2228 if ((item
->GetType() == _T("")) || wxStrcmp(item
->GetType(), _T("wxIcon")) != 0)
2230 wxLogWarning(_("%s not an icon resource specification."), (const wxChar
*) resource
);
2233 int thisDepth
= wxDisplayDepth();
2234 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2236 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2238 // Try to find optimum icon for this platform/colour depth
2239 wxNode
*node
= item
->GetChildren().First();
2242 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2243 int platform
= (int)child
->GetValue2();
2244 int noColours
= (int)child
->GetValue3();
2246 char *name = child->GetName();
2247 int bitmapType = (int)child->GetValue1();
2248 int xRes = child->GetWidth();
2249 int yRes = child->GetHeight();
2254 case RESOURCE_PLATFORM_ANY
:
2256 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2257 optResource
= child
;
2260 // Maximise the number of colours.
2261 // If noColours is zero (unspecified), then assume this
2262 // is the right one.
2263 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2264 optResource
= child
;
2269 case RESOURCE_PLATFORM_WINDOWS
:
2271 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2272 optResource
= child
;
2275 // Maximise the number of colours
2276 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2277 optResource
= child
;
2283 case RESOURCE_PLATFORM_X
:
2285 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2286 optResource
= child
;
2289 // Maximise the number of colours
2290 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2291 optResource
= child
;
2297 case RESOURCE_PLATFORM_MAC
:
2299 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2300 optResource
= child
;
2303 // Maximise the number of colours
2304 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2305 optResource
= child
;
2313 node
= node
->Next();
2315 // If no matching resource, fail.
2319 wxString name
= optResource
->GetName();
2320 int bitmapType
= (int)optResource
->GetValue1();
2323 case wxBITMAP_TYPE_XBM_DATA
:
2326 wxItemResource
*item
= table
->FindResource(name
);
2329 wxLogWarning(_("Failed to find XBM resource %s.\n"
2330 "Forgot to use wxResourceLoadIconData?"), (const wxChar
*) name
);
2333 return wxIcon((const char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2335 wxLogWarning(_("No XBM facility available!"));
2339 case wxBITMAP_TYPE_XPM_DATA
:
2341 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2343 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2344 wxItemResource *item = table->FindResource(name);
2348 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2352 return wxIcon((char **)item->GetValue1());
2354 wxLogWarning(_("No XPM facility available!"));
2357 wxLogWarning(_("No XPM icon facility available!"));
2363 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2365 return wxIcon(name
, bitmapType
);
2374 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2379 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2381 wxMenu
*menu
= new wxMenu
;
2382 wxNode
*node
= item
->GetChildren().First();
2385 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2386 if ((child
->GetType() != _T("")) && (child
->GetType() == _T("wxMenuSeparator")))
2387 menu
->AppendSeparator();
2388 else if (child
->GetChildren().Number() > 0)
2390 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2392 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2396 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2398 node
= node
->Next();
2403 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2406 table
= wxDefaultResourceTable
;
2408 wxItemResource
*menuResource
= table
->FindResource(resource
);
2409 if (menuResource
&& (menuResource
->GetType() != _T("")) && (menuResource
->GetType() == _T("wxMenu")))
2412 menuBar
= new wxMenuBar
;
2413 wxNode
*node
= menuResource
->GetChildren().First();
2416 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2417 wxMenu
*menu
= wxResourceCreateMenu(child
);
2419 menuBar
->Append(menu
, child
->GetTitle());
2420 node
= node
->Next();
2424 return (wxMenuBar
*) NULL
;
2427 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2430 table
= wxDefaultResourceTable
;
2432 wxItemResource
*menuResource
= table
->FindResource(resource
);
2433 if (menuResource
&& (menuResource
->GetType() != _T("")) && (menuResource
->GetType() == _T("wxMenu")))
2434 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2435 return wxResourceCreateMenu(menuResource
);
2436 return (wxMenu
*) NULL
;
2439 // Global equivalents (so don't have to refer to default table explicitly)
2440 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2443 table
= wxDefaultResourceTable
;
2445 return table
->ParseResourceData(resource
);
2448 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2451 table
= wxDefaultResourceTable
;
2453 return table
->ParseResourceFile(filename
);
2456 // Register XBM/XPM data
2457 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2460 table
= wxDefaultResourceTable
;
2462 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2465 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2468 table
= wxDefaultResourceTable
;
2470 return table
->RegisterResourceBitmapData(name
, data
);
2473 void wxResourceClear(wxResourceTable
*table
)
2476 table
= wxDefaultResourceTable
;
2478 table
->ClearTable();
2485 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2488 table
= wxDefaultResourceTable
;
2490 table
->identifiers
.Put(name
, (wxObject
*)value
);
2494 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2497 table
= wxDefaultResourceTable
;
2499 return (int)table
->identifiers
.Get(name
);
2503 * Parse #include file for #defines (only)
2506 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2509 table
= wxDefaultResourceTable
;
2511 FILE *fd
= fopen(f
.fn_str(), "r");
2516 while (wxGetResourceToken(fd
))
2518 if (strcmp(wxResourceBuffer
, "#define") == 0)
2520 wxGetResourceToken(fd
);
2521 wxChar
*name
= copystring(wxConv_libc
.cMB2WX(wxResourceBuffer
));
2522 wxGetResourceToken(fd
);
2523 wxChar
*value
= copystring(wxConv_libc
.cMB2WX(wxResourceBuffer
));
2524 if (wxIsdigit(value
[0]))
2526 int val
= (int)wxAtol(value
);
2527 wxResourceAddIdentifier(name
, val
, table
);
2538 * Reading strings as if they were .wxr files
2541 static int getc_string(char *s
)
2543 int ch
= s
[wxResourceStringPtr
];
2548 wxResourceStringPtr
++;
2553 static int ungetc_string()
2555 wxResourceStringPtr
--;
2559 bool wxEatWhiteSpaceString(char *s
)
2563 while ((ch
= getc_string(s
)) != EOF
)
2575 ch
= getc_string(s
);
2586 while ((ch
= getc_string(s
)) != EOF
)
2588 if (ch
== '/' && prev_ch
== '*')
2610 bool wxGetResourceTokenString(char *s
)
2612 if (!wxResourceBuffer
)
2613 wxReallocateResourceBuffer();
2614 wxResourceBuffer
[0] = 0;
2615 wxEatWhiteSpaceString(s
);
2617 int ch
= getc_string(s
);
2621 wxResourceBufferCount
= 0;
2622 ch
= getc_string(s
);
2628 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2631 // Escaped characters
2632 else if (ch
== '\\')
2634 int newCh
= getc_string(s
);
2637 else if (newCh
== 10)
2645 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2646 wxReallocateResourceBuffer();
2647 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2648 wxResourceBufferCount
++;
2649 ch
= getc_string(s
);
2651 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2655 wxResourceBufferCount
= 0;
2657 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2659 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2660 wxReallocateResourceBuffer();
2661 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2662 wxResourceBufferCount
++;
2664 ch
= getc_string(s
);
2666 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2674 * Files are in form:
2675 static char *name = "....";
2676 with possible comments.
2679 bool wxResourceReadOneResourceString(char *s
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2682 table
= wxDefaultResourceTable
;
2684 // static or #define
2685 if (!wxGetResourceTokenString(s
))
2691 if (strcmp(wxResourceBuffer
, "#define") == 0)
2693 wxGetResourceTokenString(s
);
2694 wxChar
*name
= copystring(wxConv_libc
.cMB2WX(wxResourceBuffer
));
2695 wxGetResourceTokenString(s
);
2696 wxChar
*value
= copystring(wxConv_libc
.cMB2WX(wxResourceBuffer
));
2697 if (wxIsalpha(value
[0]))
2699 int val
= (int)wxAtol(value
);
2700 wxResourceAddIdentifier(name
, val
, table
);
2704 wxLogWarning(_("#define %s must be an integer."), name
);
2715 else if (strcmp(wxResourceBuffer, "#include") == 0)
2717 wxGetResourceTokenString(s);
2718 char *name = copystring(wxResourceBuffer);
2719 char *actualName = name;
2721 actualName = name + 1;
2722 int len = strlen(name);
2723 if ((len > 0) && (name[len-1] == '"'))
2725 if (!wxResourceParseIncludeFile(actualName, table))
2728 sprintf(buf, _("Could not find resource include file %s."), actualName);
2735 else if (strcmp(wxResourceBuffer
, "static") != 0)
2738 wxStrcpy(buf
, _("Found "));
2739 wxStrncat(buf
, wxConv_libc
.cMB2WX(wxResourceBuffer
), 30);
2740 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
2746 if (!wxGetResourceTokenString(s
))
2748 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2753 if (strcmp(wxResourceBuffer
, "char") != 0)
2755 wxLogWarning(_("Expected 'char' whilst parsing resource."));
2760 if (!wxGetResourceTokenString(s
))
2762 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2767 if (wxResourceBuffer
[0] != '*')
2769 wxLogWarning(_("Expected '*' whilst parsing resource."));
2772 wxChar nameBuf
[100];
2773 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
2777 if (!wxGetResourceTokenString(s
))
2779 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2784 if (strcmp(wxResourceBuffer
, "=") != 0)
2786 wxLogWarning(_("Expected '=' whilst parsing resource."));
2791 if (!wxGetResourceTokenString(s
))
2793 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2799 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2801 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2806 if (!wxGetResourceTokenString(s
))
2813 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
2816 table
= wxDefaultResourceTable
;
2821 // Turn backslashes into spaces
2824 int len
= strlen(s
);
2826 for (i
= 0; i
< len
; i
++)
2827 if (s
[i
] == 92 && s
[i
+1] == 13)
2835 wxResourceStringPtr
= 0;
2838 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
2842 return wxResourceInterpretResources(*table
, db
);
2846 * resource loading facility
2849 bool wxWindowBase::LoadFromResource(wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
2852 table
= wxDefaultResourceTable
;
2854 wxItemResource
*resource
= table
->FindResource((const wxChar
*)resourceName
);
2855 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
2856 if (!resource
|| (resource
->GetType() == _T("")) ||
2857 ! ((resource
->GetType() == _T("wxDialog")) || (resource
->GetType() == _T("wxPanel"))))
2860 wxString
title(resource
->GetTitle());
2861 long theWindowStyle
= resource
->GetStyle();
2862 bool isModal
= (resource
->GetValue1() != 0);
2863 int x
= resource
->GetX();
2864 int y
= resource
->GetY();
2865 int width
= resource
->GetWidth();
2866 int height
= resource
->GetHeight();
2867 wxString name
= resource
->GetName();
2869 if (IsKindOf(CLASSINFO(wxDialog
)))
2871 wxDialog
*dialogBox
= (wxDialog
*)this;
2872 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
2873 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
2876 // Only reset the client size if we know we're not going to do it again below.
2877 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == 0)
2878 dialogBox
->SetClientSize(width
, height
);
2880 else if (IsKindOf(CLASSINFO(wxPanel
)))
2882 wxPanel
* panel
= (wxPanel
*)this;
2883 if (!panel
->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2888 if (!((wxWindow
*)this)->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2892 if ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
2894 // No need to do this since it's done in wxPanel or wxDialog constructor.
2895 // SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
2899 if (resource
->GetFont().Ok())
2900 SetFont(resource
->GetFont());
2901 if (resource
->GetBackgroundColour().Ok())
2902 SetBackgroundColour(resource
->GetBackgroundColour());
2905 // Should have some kind of font at this point
2906 if (!GetFont().Ok())
2907 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
2908 if (!GetBackgroundColour().Ok())
2909 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
2911 // Only when we've created the window and set the font can we set the correct size,
2912 // if based on dialog units.
2913 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
2915 wxSize sz
= ConvertDialogToPixels(wxSize(width
, height
));
2916 SetClientSize(sz
.x
, sz
.y
);
2918 wxPoint pt
= ConvertDialogToPixels(wxPoint(x
, y
));
2922 // Now create children
2923 wxNode
*node
= resource
->GetChildren().First();
2926 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
2928 (void) CreateItem(childResource
, resource
, table
);
2930 node
= node
->Next();
2935 wxControl
*wxWindowBase::CreateItem(const wxItemResource
*resource
, const wxItemResource
* parentResource
, const wxResourceTable
*table
)
2938 table
= wxDefaultResourceTable
;
2939 return table
->CreateItem((wxWindow
*)this, resource
, parentResource
);
2943 #pragma warning(default:4706) // assignment within conditional expression
2949 #endif // wxUSE_WX_RESOURCES