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/listbox.h"
43 #include "wx/choice.h"
44 #include "wx/checkbox.h"
45 #include "wx/settings.h"
46 #include "wx/slider.h"
48 #include "wx/statbox.h"
49 #include "wx/statbmp.h"
51 #include "wx/textctrl.h"
52 #include "wx/msgdlg.h"
57 #include "wx/radiobut.h"
61 #include "wx/scrolbar.h"
65 #include "wx/combobox.h"
68 #include "wx/validate.h"
77 #include "wx/resource.h"
78 #include "wx/string.h"
79 #include "wx/wxexpr.h"
81 #include "wx/settings.h"
83 // Forward (private) declarations
84 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
);
85 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
= FALSE
);
86 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
);
87 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
);
88 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
);
89 wxItemResource
*wxResourceInterpretString(wxResourceTable
& table
, wxExpr
*expr
);
90 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& table
, wxExpr
*expr
);
91 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
);
92 // Interpret list expression
93 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
);
95 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
96 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
98 wxResourceTable
*wxDefaultResourceTable
= (wxResourceTable
*) NULL
;
100 char *wxResourceBuffer
= (char *) NULL
;
101 long wxResourceBufferSize
= 0;
102 long wxResourceBufferCount
= 0;
103 int wxResourceStringPtr
= 0;
105 void wxInitializeResourceSystem()
107 wxDefaultResourceTable
= new wxResourceTable
;
110 void wxCleanUpResourceSystem()
112 delete wxDefaultResourceTable
;
113 if (wxResourceBuffer
)
114 delete[] wxResourceBuffer
;
117 void wxLogWarning(char *msg
)
119 wxMessageBox(msg
, _("Warning"), wxOK
);
122 #if !USE_SHARED_LIBRARY
123 IMPLEMENT_DYNAMIC_CLASS(wxItemResource
, wxObject
)
124 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable
, wxHashTable
)
127 wxItemResource::wxItemResource()
133 m_x
= m_y
= m_width
= m_height
= 0;
134 m_value1
= m_value2
= m_value3
= m_value5
= 0;
140 wxItemResource::~wxItemResource()
142 wxNode
*node
= m_children
.First();
145 wxItemResource
*item
= (wxItemResource
*)node
->Data();
148 node
= m_children
.First();
156 wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
)
160 wxResourceTable::~wxResourceTable()
165 wxItemResource
*wxResourceTable::FindResource(const wxString
& name
) const
167 wxItemResource
*item
= (wxItemResource
*)Get(WXSTRINGCAST name
);
171 void wxResourceTable::AddResource(wxItemResource
*item
)
173 wxString name
= item
->GetName();
175 name
= item
->GetTitle();
177 name
= _T("no name");
179 // Delete existing resource, if any.
185 bool wxResourceTable::DeleteResource(const wxString
& name
)
187 wxItemResource
*item
= (wxItemResource
*)Delete(WXSTRINGCAST name
);
190 // See if any resource has this as its child; if so, delete from
191 // parent's child list.
193 wxNode
*node
= (wxNode
*) NULL
;
197 wxItemResource
*parent
= (wxItemResource
*)node
->Data();
198 if (parent
->GetChildren().Member(item
))
200 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());
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 if (windowStyle
& wxDIALOG_MODAL
) // Uses style in wxWin 2
655 dialogItem
->SetValue1(TRUE
);
657 dialogItem
->SetName(name
);
658 dialogItem
->SetTitle(title
);
659 dialogItem
->SetSize(x
, y
, width
, height
);
661 if (backColourHex
!= _T(""))
666 r
= wxHexToDec(backColourHex
.Mid(0, 2));
667 g
= wxHexToDec(backColourHex
.Mid(2, 2));
668 b
= wxHexToDec(backColourHex
.Mid(4, 2));
669 dialogItem
->SetBackgroundColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
671 if (labelColourHex
!= _T(""))
676 r
= wxHexToDec(labelColourHex
.Mid(0, 2));
677 g
= wxHexToDec(labelColourHex
.Mid(2, 2));
678 b
= wxHexToDec(labelColourHex
.Mid(4, 2));
679 dialogItem
->SetLabelColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
681 if (buttonColourHex
!= _T(""))
686 r
= wxHexToDec(buttonColourHex
.Mid(0, 2));
687 g
= wxHexToDec(buttonColourHex
.Mid(2, 2));
688 b
= wxHexToDec(buttonColourHex
.Mid(4, 2));
689 dialogItem
->SetButtonColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
693 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
694 else if (buttonFontExpr
)
695 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
696 else if (labelFontExpr
)
697 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
699 // Now parse all controls
700 wxExpr
*controlExpr
= expr
->GetFirst();
703 if (controlExpr
->Number() == 3)
705 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
706 if (controlKeyword
!= _T("") && controlKeyword
== _T("control"))
708 // The value part: always a list.
709 wxExpr
*listExpr
= controlExpr
->Nth(2);
710 if (listExpr
->Type() == PrologList
)
712 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
715 dialogItem
->GetChildren().Append(controlItem
);
720 controlExpr
= controlExpr
->GetNext();
725 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
)
727 wxItemResource
*controlItem
= new wxItemResource
;
729 // First, find the standard features of a control definition:
730 // [optional integer/string id], control name, title, style, name, x, y, width, height
732 wxString controlType
;
737 long windowStyle
= 0;
738 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
741 wxExpr
*expr1
= expr
->Nth(0);
743 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
745 if ( wxIsValidControlClass(expr1
->StringValue()) )
748 controlType
= expr1
->StringValue();
752 wxString
str(expr1
->StringValue());
753 id
= wxResourceGetIdentifier(str
, &table
);
756 wxLogWarning(_("Could not resolve control class or id '%s'. "
757 "Use (non-zero) integer instead\n or provide #define "
758 "(see manual for caveats)"),
759 (const wxChar
*) expr1
->StringValue());
761 return (wxItemResource
*) NULL
;
765 // Success - we have an id, so the 2nd element must be the control class.
766 controlType
= expr
->Nth(1)->StringValue();
771 else if (expr1
->Type() == PrologInteger
)
773 id
= (int)expr1
->IntegerValue();
774 // Success - we have an id, so the 2nd element must be the control class.
775 controlType
= expr
->Nth(1)->StringValue();
779 expr1
= expr
->Nth(count
);
782 title
= expr1
->StringValue();
784 expr1
= expr
->Nth(count
);
788 style
= expr1
->StringValue();
789 windowStyle
= wxParseWindowStyle(style
);
792 expr1
= expr
->Nth(count
);
795 name
= expr1
->StringValue();
797 expr1
= expr
->Nth(count
);
800 x
= (int)expr1
->IntegerValue();
802 expr1
= expr
->Nth(count
);
805 y
= (int)expr1
->IntegerValue();
807 expr1
= expr
->Nth(count
);
810 width
= (int)expr1
->IntegerValue();
812 expr1
= expr
->Nth(count
);
815 height
= (int)expr1
->IntegerValue();
817 controlItem
->SetStyle(windowStyle
);
818 controlItem
->SetName(name
);
819 controlItem
->SetTitle(title
);
820 controlItem
->SetSize(x
, y
, width
, height
);
821 controlItem
->SetType(controlType
);
822 controlItem
->SetId(id
);
824 if (controlType
== _T("wxButton"))
826 // Check for bitmap resource name (in case loading old-style resource file)
827 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
829 wxString
str(expr
->Nth(count
)->StringValue());
834 controlItem
->SetValue4(str
);
835 controlItem
->SetType(_T("wxBitmapButton"));
838 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
839 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
841 else if (controlType
== _T("wxBitmapButton"))
843 // Check for bitmap resource name
844 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
846 wxString
str(expr
->Nth(count
)->StringValue());
847 controlItem
->SetValue4(str
);
849 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
850 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
853 else if (controlType
== _T("wxCheckBox"))
855 // Check for default value
856 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
858 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
860 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
861 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
865 else if (controlType
== _T("wxRadioButton"))
867 // Check for default value
868 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
870 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
872 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
873 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
877 else if (controlType
== _T("wxText") || controlType
== _T("wxTextCtrl") || controlType
== _T("wxMultiText"))
879 // Check for default value
880 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
882 wxString
str(expr
->Nth(count
)->StringValue());
883 controlItem
->SetValue4(str
);
886 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
888 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
889 // Do nothing - no label font any more
891 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
892 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
896 else if (controlType
== _T("wxMessage") || controlType
== _T("wxStaticText"))
898 // Check for bitmap resource name (in case it's an old-style .wxr file)
899 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
901 wxString
str(expr
->Nth(count
)->StringValue());
902 controlItem
->SetValue4(str
);
904 controlItem
->SetType(_T("wxStaticText"));
906 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
907 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
909 else if (controlType
== _T("wxStaticBitmap"))
911 // Check for bitmap resource name
912 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
914 wxString
str(expr
->Nth(count
)->StringValue());
915 controlItem
->SetValue4(str
);
918 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
919 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
921 else if (controlType
== _T("wxGroupBox") || controlType
== _T("wxStaticBox"))
923 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
924 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
926 else if (controlType
== _T("wxGauge"))
928 // Check for default value
929 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
931 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
935 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
937 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
940 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
942 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
946 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
947 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
952 else if (controlType
== _T("wxSlider"))
954 // Check for default value
955 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
957 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
961 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
963 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
967 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
969 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
972 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
974 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
978 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
979 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
985 else if (controlType
== _T("wxScrollBar"))
988 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
990 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
994 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
996 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1000 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1002 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1006 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1007 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
1012 else if (controlType
== _T("wxListBox"))
1014 wxExpr
*valueList
= (wxExpr
*) NULL
;
1016 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1018 wxStringList stringList
;
1019 wxExpr
*stringExpr
= valueList
->GetFirst();
1022 stringList
.Add(stringExpr
->StringValue());
1023 stringExpr
= stringExpr
->GetNext();
1025 controlItem
->SetStringValues(stringList
);
1027 // This is now obsolete: it's in the window style.
1028 // Check for wxSINGLE/wxMULTIPLE
1029 wxExpr
*mult
= (wxExpr
*) NULL
;
1031 controlItem->SetValue1(wxLB_SINGLE);
1033 if ((mult
= expr
->Nth(count
)) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1036 wxString m(mult->StringValue());
1037 if (m == "wxLB_MULTIPLE")
1038 controlItem->SetValue1(wxLB_MULTIPLE);
1039 else if (m == "wxLB_EXTENDED")
1040 controlItem->SetValue1(wxLB_EXTENDED);
1045 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1047 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1049 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1050 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1054 else if (controlType
== _T("wxChoice"))
1056 wxExpr
*valueList
= (wxExpr
*) NULL
;
1057 // Check for default value list
1058 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1060 wxStringList stringList
;
1061 wxExpr
*stringExpr
= valueList
->GetFirst();
1064 stringList
.Add(stringExpr
->StringValue());
1065 stringExpr
= stringExpr
->GetNext();
1067 controlItem
->SetStringValues(stringList
);
1071 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1073 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1076 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1077 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1082 else if (controlType
== _T("wxComboBox"))
1084 wxExpr
*textValue
= expr
->Nth(count
);
1085 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1087 wxString
str(textValue
->StringValue());
1088 controlItem
->SetValue4(str
);
1092 wxExpr
*valueList
= (wxExpr
*) NULL
;
1093 // Check for default value list
1094 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1096 wxStringList stringList
;
1097 wxExpr
*stringExpr
= valueList
->GetFirst();
1100 stringList
.Add(stringExpr
->StringValue());
1101 stringExpr
= stringExpr
->GetNext();
1103 controlItem
->SetStringValues(stringList
);
1107 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1109 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1112 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1113 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1120 else if (controlType
== _T("wxRadioBox"))
1122 wxExpr
*valueList
= (wxExpr
*) NULL
;
1123 // Check for default value list
1124 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1126 wxStringList stringList
;
1127 wxExpr
*stringExpr
= valueList
->GetFirst();
1130 stringList
.Add(stringExpr
->StringValue());
1131 stringExpr
= stringExpr
->GetNext();
1133 controlItem
->SetStringValues(stringList
);
1136 // majorDim (number of rows or cols)
1137 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1139 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1143 controlItem
->SetValue1(0);
1145 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1147 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1150 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1151 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1159 return (wxItemResource
*) NULL
;
1164 // Forward declaration
1165 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, wxExpr
*expr
);
1168 * Interpet a menu item
1171 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, wxExpr
*expr
)
1173 wxItemResource
*item
= new wxItemResource
;
1175 wxExpr
*labelExpr
= expr
->Nth(0);
1176 wxExpr
*idExpr
= expr
->Nth(1);
1177 wxExpr
*helpExpr
= expr
->Nth(2);
1178 wxExpr
*checkableExpr
= expr
->Nth(3);
1180 // Further keywords/attributes to follow sometime...
1181 if (expr
->Number() == 0)
1183 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1184 item
->SetType(_T("wxMenuSeparator"));
1189 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1190 item
->SetType(_T("wxMenu")); // Well, menu item, but doesn't matter.
1193 wxString
str(labelExpr
->StringValue());
1194 item
->SetTitle(str
);
1199 // If a string or word, must look up in identifier table.
1200 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1202 wxString
str(idExpr
->StringValue());
1203 id
= wxResourceGetIdentifier(str
, &table
);
1206 wxLogWarning(_("Could not resolve menu id '%s'. "
1207 "Use (non-zero) integer instead\n"
1208 "or provide #define (see manual for caveats)"),
1209 (const wxChar
*) idExpr
->StringValue());
1212 else if (idExpr
->Type() == PrologInteger
)
1213 id
= (int)idExpr
->IntegerValue();
1214 item
->SetValue1(id
);
1218 wxString
str(helpExpr
->StringValue());
1219 item
->SetValue4(str
);
1222 item
->SetValue2(checkableExpr
->IntegerValue());
1224 // Find the first expression that's a list, for submenu
1225 wxExpr
*subMenuExpr
= expr
->GetFirst();
1226 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1227 subMenuExpr
= subMenuExpr
->GetNext();
1231 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1232 item
->GetChildren().Append(child
);
1233 subMenuExpr
= subMenuExpr
->GetNext();
1240 * Interpret a nested list as a menu
1243 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1245 wxItemResource *menu = new wxItemResource;
1246 // menu->SetType(wxTYPE_MENU);
1247 menu->SetType("wxMenu");
1248 wxExpr *element = expr->GetFirst();
1251 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1253 menu->GetChildren().Append(item);
1254 element = element->GetNext();
1260 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
)
1262 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1263 expr
->GetAttributeValue(_T("menu"), &listExpr
);
1265 return (wxItemResource
*) NULL
;
1267 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1270 return (wxItemResource
*) NULL
;
1273 if (expr
->GetAttributeValue(_T("name"), name
))
1275 menuResource
->SetName(name
);
1278 return menuResource
;
1281 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
)
1283 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1284 expr
->GetAttributeValue(_T("menu"), &listExpr
);
1286 return (wxItemResource
*) NULL
;
1288 wxItemResource
*resource
= new wxItemResource
;
1289 resource
->SetType(_T("wxMenu"));
1290 // resource->SetType(wxTYPE_MENU);
1292 wxExpr
*element
= listExpr
->GetFirst();
1295 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1296 resource
->GetChildren().Append(menuResource
);
1297 element
= element
->GetNext();
1301 if (expr
->GetAttributeValue(_T("name"), name
))
1303 resource
->SetName(name
);
1309 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), wxExpr
*WXUNUSED(expr
))
1311 return (wxItemResource
*) NULL
;
1314 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), wxExpr
*expr
)
1316 wxItemResource
*bitmapItem
= new wxItemResource
;
1317 // bitmapItem->SetType(wxTYPE_BITMAP);
1318 bitmapItem
->SetType(_T("wxBitmap"));
1320 if (expr
->GetAttributeValue(_T("name"), name
))
1322 bitmapItem
->SetName(name
);
1324 // Now parse all bitmap specifications
1325 wxExpr
*bitmapExpr
= expr
->GetFirst();
1328 if (bitmapExpr
->Number() == 3)
1330 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1331 if (bitmapKeyword
== _T("bitmap") || bitmapKeyword
== _T("icon"))
1333 // The value part: always a list.
1334 wxExpr
*listExpr
= bitmapExpr
->Nth(2);
1335 if (listExpr
->Type() == PrologList
)
1337 wxItemResource
*bitmapSpec
= new wxItemResource
;
1338 // bitmapSpec->SetType(wxTYPE_BITMAP);
1339 bitmapSpec
->SetType(_T("wxBitmap"));
1341 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1342 // where everything after 'filename' is optional.
1343 wxExpr
*nameExpr
= listExpr
->Nth(0);
1344 wxExpr
*typeExpr
= listExpr
->Nth(1);
1345 wxExpr
*platformExpr
= listExpr
->Nth(2);
1346 wxExpr
*coloursExpr
= listExpr
->Nth(3);
1347 wxExpr
*xresExpr
= listExpr
->Nth(4);
1348 wxExpr
*yresExpr
= listExpr
->Nth(5);
1349 if (nameExpr
&& nameExpr
->StringValue() != _T(""))
1351 bitmapSpec
->SetName(nameExpr
->StringValue());
1353 if (typeExpr
&& typeExpr
->StringValue() != _T(""))
1355 bitmapSpec
->SetValue1(wxParseWindowStyle(typeExpr
->StringValue()));
1358 bitmapSpec
->SetValue1(0);
1360 if (platformExpr
&& platformExpr
->StringValue() != _T(""))
1362 wxString
plat(platformExpr
->StringValue());
1363 if (plat
== _T("windows") || plat
== _T("WINDOWS"))
1364 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1365 else if (plat
== _T("x") || plat
== _T("X"))
1366 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1367 else if (plat
== _T("mac") || plat
== _T("MAC"))
1368 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1370 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1373 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1376 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1380 xres
= (int)xresExpr
->IntegerValue();
1382 yres
= (int)yresExpr
->IntegerValue();
1383 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1385 bitmapItem
->GetChildren().Append(bitmapSpec
);
1389 bitmapExpr
= bitmapExpr
->GetNext();
1395 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
)
1397 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1400 // item->SetType(wxTYPE_ICON);
1401 item
->SetType(_T("wxIcon"));
1405 return (wxItemResource
*) NULL
;
1408 // Interpret list expression as a font
1409 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
)
1411 if (expr
->Type() != PrologList
)
1415 int family
= wxSWISS
;
1416 int style
= wxNORMAL
;
1417 int weight
= wxNORMAL
;
1419 wxString
faceName(_T(""));
1421 wxExpr
*pointExpr
= expr
->Nth(0);
1422 wxExpr
*familyExpr
= expr
->Nth(1);
1423 wxExpr
*styleExpr
= expr
->Nth(2);
1424 wxExpr
*weightExpr
= expr
->Nth(3);
1425 wxExpr
*underlineExpr
= expr
->Nth(4);
1426 wxExpr
*faceNameExpr
= expr
->Nth(5);
1428 point
= (int)pointExpr
->IntegerValue();
1433 str
= familyExpr
->StringValue();
1434 family
= (int)wxParseWindowStyle(str
);
1438 str
= styleExpr
->StringValue();
1439 style
= (int)wxParseWindowStyle(str
);
1443 str
= weightExpr
->StringValue();
1444 weight
= (int)wxParseWindowStyle(str
);
1447 underline
= (int)underlineExpr
->IntegerValue();
1449 faceName
= faceNameExpr
->StringValue();
1451 wxFont
font(point
, family
, style
, weight
, (underline
!= 0), faceName
);
1455 // Separate file for the remainder of this, for BC++/Win16
1457 #if !((defined(__BORLANDC__) || defined(__SC__)) && defined(__WIN16__))
1459 * (Re)allocate buffer for reading in from resource file
1462 bool wxReallocateResourceBuffer()
1464 if (!wxResourceBuffer
)
1466 wxResourceBufferSize
= 1000;
1467 wxResourceBuffer
= new char[wxResourceBufferSize
];
1470 if (wxResourceBuffer
)
1472 long newSize
= wxResourceBufferSize
+ 1000;
1473 char *tmp
= new char[(int)newSize
];
1474 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1475 delete[] wxResourceBuffer
;
1476 wxResourceBuffer
= tmp
;
1477 wxResourceBufferSize
= newSize
;
1482 static bool wxEatWhiteSpace(FILE *fd
)
1486 while ((ch
= getc(fd
)) != EOF
)
1501 ungetc(prev_ch
, fd
);
1509 while ((ch
= getc(fd
)) != EOF
)
1511 if (ch
== '/' && prev_ch
== '*')
1519 static char buffer
[255];
1520 fgets(buffer
, 255, fd
);
1524 ungetc(prev_ch
, fd
);
1539 bool wxGetResourceToken(FILE *fd
)
1541 if (!wxResourceBuffer
)
1542 wxReallocateResourceBuffer();
1543 wxResourceBuffer
[0] = 0;
1544 wxEatWhiteSpace(fd
);
1550 wxResourceBufferCount
= 0;
1557 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1560 // Escaped characters
1561 else if (ch
== '\\')
1563 int newCh
= getc(fd
);
1566 else if (newCh
== 10)
1574 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1575 wxReallocateResourceBuffer();
1576 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1577 wxResourceBufferCount
++;
1580 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1584 wxResourceBufferCount
= 0;
1586 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1588 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1589 wxReallocateResourceBuffer();
1590 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1591 wxResourceBufferCount
++;
1595 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1603 * Files are in form:
1604 static char *name = "....";
1605 with possible comments.
1608 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1611 table
= wxDefaultResourceTable
;
1613 // static or #define
1614 if (!wxGetResourceToken(fd
))
1620 if (strcmp(wxResourceBuffer
, "#define") == 0)
1622 wxGetResourceToken(fd
);
1623 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1624 wxGetResourceToken(fd
);
1625 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1626 if (wxIsalpha(value
[0]))
1628 int val
= (int)wxAtol(value
);
1629 wxResourceAddIdentifier(name
, val
, table
);
1633 wxLogWarning(_("#define %s must be an integer."), name
);
1643 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1645 wxGetResourceToken(fd
);
1646 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1647 wxChar
*actualName
= name
;
1648 if (name
[0] == _T('"'))
1649 actualName
= name
+ 1;
1650 int len
= wxStrlen(name
);
1651 if ((len
> 0) && (name
[len
-1] == _T('"')))
1653 if (!wxResourceParseIncludeFile(actualName
, table
))
1655 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1660 else if (strcmp(wxResourceBuffer
, "static") != 0)
1663 wxStrcpy(buf
, _("Found "));
1664 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
1665 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1671 if (!wxGetResourceToken(fd
))
1673 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1678 if (strcmp(wxResourceBuffer
, "char") != 0)
1680 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1685 if (!wxGetResourceToken(fd
))
1687 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1692 if (wxResourceBuffer
[0] != '*')
1694 wxLogWarning(_("Expected '*' whilst parsing resource."));
1697 wxChar nameBuf
[100];
1698 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
1702 if (!wxGetResourceToken(fd
))
1704 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1709 if (strcmp(wxResourceBuffer
, "=") != 0)
1711 wxLogWarning(_("Expected '=' whilst parsing resource."));
1716 if (!wxGetResourceToken(fd
))
1718 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1724 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1726 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1731 if (!wxGetResourceToken(fd
))
1739 * Parses string window style into integer window style
1743 * Style flag parsing, e.g.
1744 * "wxSYSTEM_MENU | wxBORDER" -> integer
1747 wxChar
* wxResourceParseWord(wxChar
*s
, int *i
)
1750 return (wxChar
*) NULL
;
1752 static wxChar buf
[150];
1753 int len
= wxStrlen(s
);
1756 while ((ii
< len
) && (wxIsalpha(s
[ii
]) || (s
[ii
] == _T('_'))))
1764 // Eat whitespace and conjunction characters
1765 while ((ii
< len
) &&
1766 ((s
[ii
] == _T(' ')) || (s
[ii
] == _T('|')) || (s
[ii
] == _T(','))))
1772 return (wxChar
*) NULL
;
1777 struct wxResourceBitListStruct
1783 static wxResourceBitListStruct wxResourceBitListTable
[] =
1786 { _T("wxSINGLE"), wxLB_SINGLE
},
1787 { _T("wxMULTIPLE"), wxLB_MULTIPLE
},
1788 { _T("wxEXTENDED"), wxLB_EXTENDED
},
1789 { _T("wxLB_SINGLE"), wxLB_SINGLE
},
1790 { _T("wxLB_MULTIPLE"), wxLB_MULTIPLE
},
1791 { _T("wxLB_EXTENDED"), wxLB_EXTENDED
},
1792 { _T("wxLB_NEEDED_SB"), wxLB_NEEDED_SB
},
1793 { _T("wxLB_ALWAYS_SB"), wxLB_ALWAYS_SB
},
1794 { _T("wxLB_SORT"), wxLB_SORT
},
1795 { _T("wxLB_OWNERDRAW"), wxLB_OWNERDRAW
},
1796 { _T("wxLB_HSCROLL"), wxLB_HSCROLL
},
1799 { _T("wxCB_SIMPLE"), wxCB_SIMPLE
},
1800 { _T("wxCB_DROPDOWN"), wxCB_DROPDOWN
},
1801 { _T("wxCB_READONLY"), wxCB_READONLY
},
1802 { _T("wxCB_SORT"), wxCB_SORT
},
1805 { _T("wxGA_PROGRESSBAR"), wxGA_PROGRESSBAR
},
1806 { _T("wxGA_HORIZONTAL"), wxGA_HORIZONTAL
},
1807 { _T("wxGA_VERTICAL"), wxGA_VERTICAL
},
1810 { _T("wxPASSWORD"), wxPASSWORD
},
1811 { _T("wxPROCESS_ENTER"), wxPROCESS_ENTER
},
1812 { _T("wxTE_PASSWORD"), wxTE_PASSWORD
},
1813 { _T("wxTE_READONLY"), wxTE_READONLY
},
1814 { _T("wxTE_PROCESS_ENTER"), wxTE_PROCESS_ENTER
},
1815 { _T("wxTE_MULTILINE"), wxTE_MULTILINE
},
1817 /* wxRadioBox/wxRadioButton */
1818 { _T("wxRB_GROUP"), wxRB_GROUP
},
1819 { _T("wxRA_SPECIFY_COLS"), wxRA_SPECIFY_COLS
},
1820 { _T("wxRA_SPECIFY_ROWS"), wxRA_SPECIFY_ROWS
},
1821 { _T("wxRA_HORIZONTAL"), wxRA_HORIZONTAL
},
1822 { _T("wxRA_VERTICAL"), wxRA_VERTICAL
},
1825 { _T("wxSL_HORIZONTAL"), wxSL_HORIZONTAL
},
1826 { _T("wxSL_VERTICAL"), wxSL_VERTICAL
},
1827 { _T("wxSL_AUTOTICKS"), wxSL_AUTOTICKS
},
1828 { _T("wxSL_LABELS"), wxSL_LABELS
},
1829 { _T("wxSL_LEFT"), wxSL_LEFT
},
1830 { _T("wxSL_TOP"), wxSL_TOP
},
1831 { _T("wxSL_RIGHT"), wxSL_RIGHT
},
1832 { _T("wxSL_BOTTOM"), wxSL_BOTTOM
},
1833 { _T("wxSL_BOTH"), wxSL_BOTH
},
1834 { _T("wxSL_SELRANGE"), wxSL_SELRANGE
},
1837 { _T("wxSB_HORIZONTAL"), wxSB_HORIZONTAL
},
1838 { _T("wxSB_VERTICAL"), wxSB_VERTICAL
},
1841 { _T("wxBU_AUTODRAW"), wxBU_AUTODRAW
},
1842 { _T("wxBU_NOAUTODRAW"), wxBU_NOAUTODRAW
},
1845 { _T("wxTR_HAS_BUTTONS"), wxTR_HAS_BUTTONS
},
1846 { _T("wxTR_EDIT_LABELS"), wxTR_EDIT_LABELS
},
1847 { _T("wxTR_LINES_AT_ROOT"), wxTR_LINES_AT_ROOT
},
1850 { _T("wxLC_ICON"), wxLC_ICON
},
1851 { _T("wxLC_SMALL_ICON"), wxLC_SMALL_ICON
},
1852 { _T("wxLC_LIST"), wxLC_LIST
},
1853 { _T("wxLC_REPORT"), wxLC_REPORT
},
1854 { _T("wxLC_ALIGN_TOP"), wxLC_ALIGN_TOP
},
1855 { _T("wxLC_ALIGN_LEFT"), wxLC_ALIGN_LEFT
},
1856 { _T("wxLC_AUTOARRANGE"), wxLC_AUTOARRANGE
},
1857 { _T("wxLC_USER_TEXT"), wxLC_USER_TEXT
},
1858 { _T("wxLC_EDIT_LABELS"), wxLC_EDIT_LABELS
},
1859 { _T("wxLC_NO_HEADER"), wxLC_NO_HEADER
},
1860 { _T("wxLC_NO_SORT_HEADER"), wxLC_NO_SORT_HEADER
},
1861 { _T("wxLC_SINGLE_SEL"), wxLC_SINGLE_SEL
},
1862 { _T("wxLC_SORT_ASCENDING"), wxLC_SORT_ASCENDING
},
1863 { _T("wxLC_SORT_DESCENDING"), wxLC_SORT_DESCENDING
},
1866 { _T("wxSP_VERTICAL"), wxSP_VERTICAL
},
1867 { _T("wxSP_HORIZONTAL"), wxSP_HORIZONTAL
},
1868 { _T("wxSP_ARROW_KEYS"), wxSP_ARROW_KEYS
},
1869 { _T("wxSP_WRAP"), wxSP_WRAP
},
1872 { _T("wxSP_NOBORDER"), wxSP_NOBORDER
},
1873 { _T("wxSP_3D"), wxSP_3D
},
1874 { _T("wxSP_BORDER"), wxSP_BORDER
},
1877 { _T("wxTC_MULTILINE"), wxTC_MULTILINE
},
1878 { _T("wxTC_RIGHTJUSTIFY"), wxTC_RIGHTJUSTIFY
},
1879 { _T("wxTC_FIXEDWIDTH"), wxTC_FIXEDWIDTH
},
1880 { _T("wxTC_OWNERDRAW"), wxTC_OWNERDRAW
},
1883 { _T("wxST_SIZEGRIP"), wxST_SIZEGRIP
},
1886 { _T("wxFIXED_LENGTH"), wxFIXED_LENGTH
},
1887 { _T("wxALIGN_LEFT"), wxALIGN_LEFT
},
1888 { _T("wxALIGN_CENTER"), wxALIGN_CENTER
},
1889 { _T("wxALIGN_CENTRE"), wxALIGN_CENTRE
},
1890 { _T("wxALIGN_RIGHT"), wxALIGN_RIGHT
},
1891 { _T("wxCOLOURED"), wxCOLOURED
},
1894 { _T("wxTB_3DBUTTONS"), wxTB_3DBUTTONS
},
1895 { _T("wxTB_HORIZONTAL"), wxTB_HORIZONTAL
},
1896 { _T("wxTB_VERTICAL"), wxTB_VERTICAL
},
1897 { _T("wxTB_FLAT"), wxTB_FLAT
},
1900 { _T("wxDIALOG_MODAL"), wxDIALOG_MODAL
},
1903 { _T("wxVSCROLL"), wxVSCROLL
},
1904 { _T("wxHSCROLL"), wxHSCROLL
},
1905 { _T("wxCAPTION"), wxCAPTION
},
1906 { _T("wxSTAY_ON_TOP"), wxSTAY_ON_TOP
},
1907 { _T("wxICONIZE"), wxICONIZE
},
1908 { _T("wxMINIMIZE"), wxICONIZE
},
1909 { _T("wxMAXIMIZE"), wxMAXIMIZE
},
1911 { _T("wxMDI_PARENT"), 0},
1912 { _T("wxMDI_CHILD"), 0},
1913 { _T("wxTHICK_FRAME"), wxTHICK_FRAME
},
1914 { _T("wxRESIZE_BORDER"), wxRESIZE_BORDER
},
1915 { _T("wxSYSTEM_MENU"), wxSYSTEM_MENU
},
1916 { _T("wxMINIMIZE_BOX"), wxMINIMIZE_BOX
},
1917 { _T("wxMAXIMIZE_BOX"), wxMAXIMIZE_BOX
},
1918 { _T("wxRESIZE_BOX"), wxRESIZE_BOX
},
1919 { _T("wxDEFAULT_FRAME_STYLE"), wxDEFAULT_FRAME_STYLE
},
1920 { _T("wxDEFAULT_FRAME"), wxDEFAULT_FRAME_STYLE
},
1921 { _T("wxDEFAULT_DIALOG_STYLE"), wxDEFAULT_DIALOG_STYLE
},
1922 { _T("wxBORDER"), wxBORDER
},
1923 { _T("wxRETAINED"), wxRETAINED
},
1924 { _T("wxNATIVE_IMPL"), 0},
1925 { _T("wxEXTENDED_IMPL"), 0},
1926 { _T("wxBACKINGSTORE"), wxBACKINGSTORE
},
1927 // { _T("wxFLAT"), wxFLAT},
1928 // { _T("wxMOTIF_RESIZE"), wxMOTIF_RESIZE},
1929 { _T("wxFIXED_LENGTH"), 0},
1930 { _T("wxDOUBLE_BORDER"), wxDOUBLE_BORDER
},
1931 { _T("wxSUNKEN_BORDER"), wxSUNKEN_BORDER
},
1932 { _T("wxRAISED_BORDER"), wxRAISED_BORDER
},
1933 { _T("wxSIMPLE_BORDER"), wxSIMPLE_BORDER
},
1934 { _T("wxSTATIC_BORDER"), wxSTATIC_BORDER
},
1935 { _T("wxTRANSPARENT_WINDOW"), wxTRANSPARENT_WINDOW
},
1936 { _T("wxNO_BORDER"), wxNO_BORDER
},
1937 { _T("wxCLIP_CHILDREN"), wxCLIP_CHILDREN
},
1939 { _T("wxTINY_CAPTION_HORIZ"), wxTINY_CAPTION_HORIZ
},
1940 { _T("wxTINY_CAPTION_VERT"), wxTINY_CAPTION_VERT
},
1942 // Text font families
1943 { _T("wxDEFAULT"), wxDEFAULT
},
1944 { _T("wxDECORATIVE"), wxDECORATIVE
},
1945 { _T("wxROMAN"), wxROMAN
},
1946 { _T("wxSCRIPT"), wxSCRIPT
},
1947 { _T("wxSWISS"), wxSWISS
},
1948 { _T("wxMODERN"), wxMODERN
},
1949 { _T("wxTELETYPE"), wxTELETYPE
},
1950 { _T("wxVARIABLE"), wxVARIABLE
},
1951 { _T("wxFIXED"), wxFIXED
},
1952 { _T("wxNORMAL"), wxNORMAL
},
1953 { _T("wxLIGHT"), wxLIGHT
},
1954 { _T("wxBOLD"), wxBOLD
},
1955 { _T("wxITALIC"), wxITALIC
},
1956 { _T("wxSLANT"), wxSLANT
},
1957 { _T("wxSOLID"), wxSOLID
},
1958 { _T("wxDOT"), wxDOT
},
1959 { _T("wxLONG_DASH"), wxLONG_DASH
},
1960 { _T("wxSHORT_DASH"), wxSHORT_DASH
},
1961 { _T("wxDOT_DASH"), wxDOT_DASH
},
1962 { _T("wxUSER_DASH"), wxUSER_DASH
},
1963 { _T("wxTRANSPARENT"), wxTRANSPARENT
},
1964 { _T("wxSTIPPLE"), wxSTIPPLE
},
1965 { _T("wxBDIAGONAL_HATCH"), wxBDIAGONAL_HATCH
},
1966 { _T("wxCROSSDIAG_HATCH"), wxCROSSDIAG_HATCH
},
1967 { _T("wxFDIAGONAL_HATCH"), wxFDIAGONAL_HATCH
},
1968 { _T("wxCROSS_HATCH"), wxCROSS_HATCH
},
1969 { _T("wxHORIZONTAL_HATCH"), wxHORIZONTAL_HATCH
},
1970 { _T("wxVERTICAL_HATCH"), wxVERTICAL_HATCH
},
1971 { _T("wxJOIN_BEVEL"), wxJOIN_BEVEL
},
1972 { _T("wxJOIN_MITER"), wxJOIN_MITER
},
1973 { _T("wxJOIN_ROUND"), wxJOIN_ROUND
},
1974 { _T("wxCAP_ROUND"), wxCAP_ROUND
},
1975 { _T("wxCAP_PROJECTING"), wxCAP_PROJECTING
},
1976 { _T("wxCAP_BUTT"), wxCAP_BUTT
},
1979 { _T("wxCLEAR"), wxCLEAR
},
1980 { _T("wxXOR"), wxXOR
},
1981 { _T("wxINVERT"), wxINVERT
},
1982 { _T("wxOR_REVERSE"), wxOR_REVERSE
},
1983 { _T("wxAND_REVERSE"), wxAND_REVERSE
},
1984 { _T("wxCOPY"), wxCOPY
},
1985 { _T("wxAND"), wxAND
},
1986 { _T("wxAND_INVERT"), wxAND_INVERT
},
1987 { _T("wxNO_OP"), wxNO_OP
},
1988 { _T("wxNOR"), wxNOR
},
1989 { _T("wxEQUIV"), wxEQUIV
},
1990 { _T("wxSRC_INVERT"), wxSRC_INVERT
},
1991 { _T("wxOR_INVERT"), wxOR_INVERT
},
1992 { _T("wxNAND"), wxNAND
},
1993 { _T("wxOR"), wxOR
},
1994 { _T("wxSET"), wxSET
},
1996 { _T("wxFLOOD_SURFACE"), wxFLOOD_SURFACE
},
1997 { _T("wxFLOOD_BORDER"), wxFLOOD_BORDER
},
1998 { _T("wxODDEVEN_RULE"), wxODDEVEN_RULE
},
1999 { _T("wxWINDING_RULE"), wxWINDING_RULE
},
2000 { _T("wxHORIZONTAL"), wxHORIZONTAL
},
2001 { _T("wxVERTICAL"), wxVERTICAL
},
2002 { _T("wxBOTH"), wxBOTH
},
2003 { _T("wxCENTER_FRAME"), wxCENTER_FRAME
},
2004 { _T("wxOK"), wxOK
},
2005 { _T("wxYES_NO"), wxYES_NO
},
2006 { _T("wxCANCEL"), wxCANCEL
},
2007 { _T("wxYES"), wxYES
},
2008 { _T("wxNO"), wxNO
},
2009 { _T("wxICON_EXCLAMATION"), wxICON_EXCLAMATION
},
2010 { _T("wxICON_HAND"), wxICON_HAND
},
2011 { _T("wxICON_QUESTION"), wxICON_QUESTION
},
2012 { _T("wxICON_INFORMATION"), wxICON_INFORMATION
},
2013 { _T("wxICON_STOP"), wxICON_STOP
},
2014 { _T("wxICON_ASTERISK"), wxICON_ASTERISK
},
2015 { _T("wxICON_MASK"), wxICON_MASK
},
2016 { _T("wxCENTRE"), wxCENTRE
},
2017 { _T("wxCENTER"), wxCENTRE
},
2018 { _T("wxUSER_COLOURS"), wxUSER_COLOURS
},
2019 { _T("wxVERTICAL_LABEL"), 0},
2020 { _T("wxHORIZONTAL_LABEL"), 0},
2022 // Bitmap types (not strictly styles)
2023 { _T("wxBITMAP_TYPE_XPM"), wxBITMAP_TYPE_XPM
},
2024 { _T("wxBITMAP_TYPE_XBM"), wxBITMAP_TYPE_XBM
},
2025 { _T("wxBITMAP_TYPE_BMP"), wxBITMAP_TYPE_BMP
},
2026 { _T("wxBITMAP_TYPE_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2027 { _T("wxBITMAP_TYPE_BMP_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2028 { _T("wxBITMAP_TYPE_GIF"), wxBITMAP_TYPE_GIF
},
2029 { _T("wxBITMAP_TYPE_TIF"), wxBITMAP_TYPE_TIF
},
2030 { _T("wxBITMAP_TYPE_ICO"), wxBITMAP_TYPE_ICO
},
2031 { _T("wxBITMAP_TYPE_ICO_RESOURCE"), wxBITMAP_TYPE_ICO_RESOURCE
},
2032 { _T("wxBITMAP_TYPE_CUR"), wxBITMAP_TYPE_CUR
},
2033 { _T("wxBITMAP_TYPE_CUR_RESOURCE"), wxBITMAP_TYPE_CUR_RESOURCE
},
2034 { _T("wxBITMAP_TYPE_XBM_DATA"), wxBITMAP_TYPE_XBM_DATA
},
2035 { _T("wxBITMAP_TYPE_XPM_DATA"), wxBITMAP_TYPE_XPM_DATA
},
2036 { _T("wxBITMAP_TYPE_ANY"), wxBITMAP_TYPE_ANY
}
2039 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
2041 long wxParseWindowStyle(const wxString
& bitListString
)
2046 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2047 while (word
!= NULL
)
2051 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2052 if (wxStrcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2054 bitList
|= wxResourceBitListTable
[j
].bits
;
2060 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word
);
2063 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2069 * Load a bitmap from a wxWindows resource, choosing an optimum
2070 * depth and appropriate type.
2073 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
2076 table
= wxDefaultResourceTable
;
2078 wxItemResource
*item
= table
->FindResource(resource
);
2081 if ((item
->GetType() == _T("")) || (item
->GetType() != _T("wxBitmap")))
2083 wxLogWarning(_("%s not a bitmap resource specification."), (const wxChar
*) resource
);
2084 return wxNullBitmap
;
2086 int thisDepth
= wxDisplayDepth();
2087 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2089 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2091 // Try to find optimum bitmap for this platform/colour depth
2092 wxNode
*node
= item
->GetChildren().First();
2095 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2096 int platform
= (int)child
->GetValue2();
2097 int noColours
= (int)child
->GetValue3();
2099 char *name = child->GetName();
2100 int bitmapType = (int)child->GetValue1();
2101 int xRes = child->GetWidth();
2102 int yRes = child->GetHeight();
2107 case RESOURCE_PLATFORM_ANY
:
2109 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2110 optResource
= child
;
2113 // Maximise the number of colours.
2114 // If noColours is zero (unspecified), then assume this
2115 // is the right one.
2116 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2117 optResource
= child
;
2122 case RESOURCE_PLATFORM_WINDOWS
:
2124 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2125 optResource
= child
;
2128 // Maximise the number of colours
2129 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2130 optResource
= child
;
2136 case RESOURCE_PLATFORM_X
:
2138 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2139 optResource
= child
;
2142 // Maximise the number of colours
2143 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2144 optResource
= child
;
2150 case RESOURCE_PLATFORM_MAC
:
2152 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2153 optResource
= child
;
2156 // Maximise the number of colours
2157 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2158 optResource
= child
;
2166 node
= node
->Next();
2168 // If no matching resource, fail.
2170 return wxNullBitmap
;
2172 wxString name
= optResource
->GetName();
2173 int bitmapType
= (int)optResource
->GetValue1();
2176 case wxBITMAP_TYPE_XBM_DATA
:
2179 wxItemResource
*item
= table
->FindResource(name
);
2182 wxLogWarning(_("Failed to find XBM resource %s.\n"
2183 "Forgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2184 return wxNullBitmap
;
2186 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2188 wxLogWarning(_("No XBM facility available!"));
2192 case wxBITMAP_TYPE_XPM_DATA
:
2194 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2195 wxItemResource
*item
= table
->FindResource(name
);
2198 wxLogWarning(_("Failed to find XPM resource %s.\n"
2199 "Forgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2200 return wxNullBitmap
;
2202 return wxBitmap((char **)item
->GetValue1());
2204 wxLogWarning(_("No XPM facility available!"));
2210 return wxBitmap(name
, bitmapType
);
2214 return wxNullBitmap
;
2218 wxLogWarning(_("Bitmap resource specification %s not found."), (const wxChar
*) resource
);
2219 return wxNullBitmap
;
2224 * Load an icon from a wxWindows resource, choosing an optimum
2225 * depth and appropriate type.
2228 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2231 table
= wxDefaultResourceTable
;
2233 wxItemResource
*item
= table
->FindResource(resource
);
2236 if ((item
->GetType() == _T("")) || wxStrcmp(item
->GetType(), _T("wxIcon")) != 0)
2238 wxLogWarning(_("%s not an icon resource specification."), (const wxChar
*) resource
);
2241 int thisDepth
= wxDisplayDepth();
2242 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2244 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2246 // Try to find optimum icon for this platform/colour depth
2247 wxNode
*node
= item
->GetChildren().First();
2250 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2251 int platform
= (int)child
->GetValue2();
2252 int noColours
= (int)child
->GetValue3();
2254 char *name = child->GetName();
2255 int bitmapType = (int)child->GetValue1();
2256 int xRes = child->GetWidth();
2257 int yRes = child->GetHeight();
2262 case RESOURCE_PLATFORM_ANY
:
2264 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2265 optResource
= child
;
2268 // Maximise the number of colours.
2269 // If noColours is zero (unspecified), then assume this
2270 // is the right one.
2271 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2272 optResource
= child
;
2277 case RESOURCE_PLATFORM_WINDOWS
:
2279 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2280 optResource
= child
;
2283 // Maximise the number of colours
2284 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2285 optResource
= child
;
2291 case RESOURCE_PLATFORM_X
:
2293 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2294 optResource
= child
;
2297 // Maximise the number of colours
2298 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2299 optResource
= child
;
2305 case RESOURCE_PLATFORM_MAC
:
2307 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2308 optResource
= child
;
2311 // Maximise the number of colours
2312 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2313 optResource
= child
;
2321 node
= node
->Next();
2323 // If no matching resource, fail.
2327 wxString name
= optResource
->GetName();
2328 int bitmapType
= (int)optResource
->GetValue1();
2331 case wxBITMAP_TYPE_XBM_DATA
:
2334 wxItemResource
*item
= table
->FindResource(name
);
2337 wxLogWarning(_("Failed to find XBM resource %s.\n"
2338 "Forgot to use wxResourceLoadIconData?"), (const wxChar
*) name
);
2341 return wxIcon((const char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2343 wxLogWarning(_("No XBM facility available!"));
2347 case wxBITMAP_TYPE_XPM_DATA
:
2349 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2351 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2352 wxItemResource *item = table->FindResource(name);
2356 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2360 return wxIcon((char **)item->GetValue1());
2362 wxLogWarning(_("No XPM facility available!"));
2365 wxLogWarning(_("No XPM icon facility available!"));
2371 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2373 return wxIcon(name
, bitmapType
);
2382 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2387 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2389 wxMenu
*menu
= new wxMenu
;
2390 wxNode
*node
= item
->GetChildren().First();
2393 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2394 if ((child
->GetType() != _T("")) && (child
->GetType() == _T("wxMenuSeparator")))
2395 menu
->AppendSeparator();
2396 else if (child
->GetChildren().Number() > 0)
2398 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2400 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2404 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2406 node
= node
->Next();
2411 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2414 table
= wxDefaultResourceTable
;
2416 wxItemResource
*menuResource
= table
->FindResource(resource
);
2417 if (menuResource
&& (menuResource
->GetType() != _T("")) && (menuResource
->GetType() == _T("wxMenu")))
2420 menuBar
= new wxMenuBar
;
2421 wxNode
*node
= menuResource
->GetChildren().First();
2424 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2425 wxMenu
*menu
= wxResourceCreateMenu(child
);
2427 menuBar
->Append(menu
, child
->GetTitle());
2428 node
= node
->Next();
2432 return (wxMenuBar
*) NULL
;
2435 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2438 table
= wxDefaultResourceTable
;
2440 wxItemResource
*menuResource
= table
->FindResource(resource
);
2441 if (menuResource
&& (menuResource
->GetType() != _T("")) && (menuResource
->GetType() == _T("wxMenu")))
2442 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2443 return wxResourceCreateMenu(menuResource
);
2444 return (wxMenu
*) NULL
;
2447 // Global equivalents (so don't have to refer to default table explicitly)
2448 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2451 table
= wxDefaultResourceTable
;
2453 return table
->ParseResourceData(resource
);
2456 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2459 table
= wxDefaultResourceTable
;
2461 return table
->ParseResourceFile(filename
);
2464 // Register XBM/XPM data
2465 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2468 table
= wxDefaultResourceTable
;
2470 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2473 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2476 table
= wxDefaultResourceTable
;
2478 return table
->RegisterResourceBitmapData(name
, data
);
2481 void wxResourceClear(wxResourceTable
*table
)
2484 table
= wxDefaultResourceTable
;
2486 table
->ClearTable();
2493 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2496 table
= wxDefaultResourceTable
;
2498 table
->identifiers
.Put(name
, (wxObject
*)value
);
2502 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2505 table
= wxDefaultResourceTable
;
2507 return (int)table
->identifiers
.Get(name
);
2511 * Parse #include file for #defines (only)
2514 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2517 table
= wxDefaultResourceTable
;
2519 FILE *fd
= fopen(f
.fn_str(), "r");
2524 while (wxGetResourceToken(fd
))
2526 if (strcmp(wxResourceBuffer
, "#define") == 0)
2528 wxGetResourceToken(fd
);
2529 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2530 wxGetResourceToken(fd
);
2531 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2532 if (wxIsdigit(value
[0]))
2534 int val
= (int)wxAtol(value
);
2535 wxResourceAddIdentifier(name
, val
, table
);
2546 * Reading strings as if they were .wxr files
2549 static int getc_string(char *s
)
2551 int ch
= s
[wxResourceStringPtr
];
2556 wxResourceStringPtr
++;
2561 static int ungetc_string()
2563 wxResourceStringPtr
--;
2567 bool wxEatWhiteSpaceString(char *s
)
2571 while ((ch
= getc_string(s
)) != EOF
)
2583 ch
= getc_string(s
);
2594 while ((ch
= getc_string(s
)) != EOF
)
2596 if (ch
== '/' && prev_ch
== '*')
2618 bool wxGetResourceTokenString(char *s
)
2620 if (!wxResourceBuffer
)
2621 wxReallocateResourceBuffer();
2622 wxResourceBuffer
[0] = 0;
2623 wxEatWhiteSpaceString(s
);
2625 int ch
= getc_string(s
);
2629 wxResourceBufferCount
= 0;
2630 ch
= getc_string(s
);
2636 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2639 // Escaped characters
2640 else if (ch
== '\\')
2642 int newCh
= getc_string(s
);
2645 else if (newCh
== 10)
2653 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2654 wxReallocateResourceBuffer();
2655 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2656 wxResourceBufferCount
++;
2657 ch
= getc_string(s
);
2659 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2663 wxResourceBufferCount
= 0;
2665 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2667 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2668 wxReallocateResourceBuffer();
2669 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2670 wxResourceBufferCount
++;
2672 ch
= getc_string(s
);
2674 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2682 * Files are in form:
2683 static char *name = "....";
2684 with possible comments.
2687 bool wxResourceReadOneResourceString(char *s
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2690 table
= wxDefaultResourceTable
;
2692 // static or #define
2693 if (!wxGetResourceTokenString(s
))
2699 if (strcmp(wxResourceBuffer
, "#define") == 0)
2701 wxGetResourceTokenString(s
);
2702 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2703 wxGetResourceTokenString(s
);
2704 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2705 if (wxIsalpha(value
[0]))
2707 int val
= (int)wxAtol(value
);
2708 wxResourceAddIdentifier(name
, val
, table
);
2712 wxLogWarning(_("#define %s must be an integer."), name
);
2723 else if (strcmp(wxResourceBuffer, "#include") == 0)
2725 wxGetResourceTokenString(s);
2726 char *name = copystring(wxResourceBuffer);
2727 char *actualName = name;
2729 actualName = name + 1;
2730 int len = strlen(name);
2731 if ((len > 0) && (name[len-1] == '"'))
2733 if (!wxResourceParseIncludeFile(actualName, table))
2736 sprintf(buf, _("Could not find resource include file %s."), actualName);
2743 else if (strcmp(wxResourceBuffer
, "static") != 0)
2746 wxStrcpy(buf
, _("Found "));
2747 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
2748 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
2754 if (!wxGetResourceTokenString(s
))
2756 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2761 if (strcmp(wxResourceBuffer
, "char") != 0)
2763 wxLogWarning(_("Expected 'char' whilst parsing resource."));
2768 if (!wxGetResourceTokenString(s
))
2770 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2775 if (wxResourceBuffer
[0] != '*')
2777 wxLogWarning(_("Expected '*' whilst parsing resource."));
2780 wxChar nameBuf
[100];
2781 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
2785 if (!wxGetResourceTokenString(s
))
2787 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2792 if (strcmp(wxResourceBuffer
, "=") != 0)
2794 wxLogWarning(_("Expected '=' whilst parsing resource."));
2799 if (!wxGetResourceTokenString(s
))
2801 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2807 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2809 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2814 if (!wxGetResourceTokenString(s
))
2821 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
2824 table
= wxDefaultResourceTable
;
2829 // Turn backslashes into spaces
2832 int len
= strlen(s
);
2834 for (i
= 0; i
< len
; i
++)
2835 if (s
[i
] == 92 && s
[i
+1] == 13)
2843 wxResourceStringPtr
= 0;
2846 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
2850 return wxResourceInterpretResources(*table
, db
);
2854 * resource loading facility
2857 bool wxWindowBase::LoadFromResource(wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
2860 table
= wxDefaultResourceTable
;
2862 wxItemResource
*resource
= table
->FindResource((const wxChar
*)resourceName
);
2863 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
2864 if (!resource
|| (resource
->GetType() == _T("")) ||
2865 ! ((resource
->GetType() == _T("wxDialog")) || (resource
->GetType() == _T("wxPanel"))))
2868 wxString
title(resource
->GetTitle());
2869 long theWindowStyle
= resource
->GetStyle();
2870 bool isModal
= (resource
->GetValue1() != 0);
2871 int x
= resource
->GetX();
2872 int y
= resource
->GetY();
2873 int width
= resource
->GetWidth();
2874 int height
= resource
->GetHeight();
2875 wxString name
= resource
->GetName();
2877 if (IsKindOf(CLASSINFO(wxDialog
)))
2879 wxDialog
*dialogBox
= (wxDialog
*)this;
2880 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
2881 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
2884 // Only reset the client size if we know we're not going to do it again below.
2885 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == 0)
2886 dialogBox
->SetClientSize(width
, height
);
2888 else if (IsKindOf(CLASSINFO(wxPanel
)))
2890 wxPanel
* panel
= (wxPanel
*)this;
2891 if (!panel
->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2896 if (!((wxWindow
*)this)->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2900 if ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
2902 // No need to do this since it's done in wxPanel or wxDialog constructor.
2903 // SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
2907 if (resource
->GetFont().Ok())
2908 SetFont(resource
->GetFont());
2909 if (resource
->GetBackgroundColour().Ok())
2910 SetBackgroundColour(resource
->GetBackgroundColour());
2913 // Should have some kind of font at this point
2914 if (!GetFont().Ok())
2915 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
2916 if (!GetBackgroundColour().Ok())
2917 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
2919 // Only when we've created the window and set the font can we set the correct size,
2920 // if based on dialog units.
2921 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
2923 wxSize sz
= ConvertDialogToPixels(wxSize(width
, height
));
2924 SetClientSize(sz
.x
, sz
.y
);
2926 wxPoint pt
= ConvertDialogToPixels(wxPoint(x
, y
));
2930 // Now create children
2931 wxNode
*node
= resource
->GetChildren().First();
2934 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
2936 (void) CreateItem(childResource
, resource
, table
);
2938 node
= node
->Next();
2943 wxControl
*wxWindowBase::CreateItem(const wxItemResource
*resource
, const wxItemResource
* parentResource
, const wxResourceTable
*table
)
2946 table
= wxDefaultResourceTable
;
2947 return table
->CreateItem((wxWindow
*)this, resource
, parentResource
);
2951 #pragma warning(default:4706) // assignment within conditional expression
2957 #endif // wxUSE_WX_RESOURCES