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
;
194 while ((node
= Next()))
196 wxItemResource
*parent
= (wxItemResource
*)node
->Data();
197 if (parent
->GetChildren().Member(item
))
199 parent
->GetChildren().DeleteObject(item
);
211 bool wxResourceTable::ParseResourceFile(const wxString
& filename
)
215 FILE *fd
= fopen(filename
.fn_str(), "r");
219 while (wxResourceReadOneResource(fd
, db
, &eof
, this) && !eof
)
224 return wxResourceInterpretResources(*this, db
);
227 bool wxResourceTable::ParseResourceData(const wxString
& data
)
230 if (!db
.ReadFromString(data
))
232 wxLogWarning(_("Ill-formed resource file syntax."));
236 return wxResourceInterpretResources(*this, db
);
239 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char bits
[], int width
, int height
)
241 // Register pre-loaded bitmap data
242 wxItemResource
*item
= new wxItemResource
;
243 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
244 item
->SetType(_T("wxXBMData"));
246 item
->SetValue1((long)bits
);
247 item
->SetValue2((long)width
);
248 item
->SetValue3((long)height
);
253 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char **data
)
255 // Register pre-loaded bitmap data
256 wxItemResource
*item
= new wxItemResource
;
257 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
258 item
->SetType(_T("wxXPMData"));
260 item
->SetValue1((long)data
);
265 bool wxResourceTable::SaveResource(const wxString
& WXUNUSED(filename
))
270 void wxResourceTable::ClearTable()
273 wxNode
*node
= Next();
276 wxNode
*next
= Next();
277 wxItemResource
*item
= (wxItemResource
*)node
->Data();
284 wxControl
*wxResourceTable::CreateItem(wxWindow
*parent
, const wxItemResource
* childResource
, const wxItemResource
* parentResource
) const
286 int id
= childResource
->GetId();
290 bool dlgUnits
= ((parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0);
292 wxControl
*control
= (wxControl
*) NULL
;
293 wxString
itemType(childResource
->GetType());
299 pos
= parent
->ConvertDialogToPixels(wxPoint(childResource
->GetX(), childResource
->GetY()));
300 size
= parent
->ConvertDialogToPixels(wxSize(childResource
->GetWidth(), childResource
->GetHeight()));
304 pos
= wxPoint(childResource
->GetX(), childResource
->GetY());
305 size
= wxSize(childResource
->GetWidth(), childResource
->GetHeight());
308 if (itemType
== wxString(_T("wxButton")) || itemType
== wxString(_T("wxBitmapButton")))
310 if (childResource
->GetValue4() != _T(""))
313 wxBitmap bitmap
= childResource
->GetBitmap();
316 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
317 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
320 control
= new wxBitmapButton(parent
, id
, bitmap
, pos
, size
,
321 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
324 // Normal, text button
325 control
= new wxButton(parent
, id
, childResource
->GetTitle(), pos
, size
,
326 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
328 else if (itemType
== wxString(_T("wxMessage")) || itemType
== wxString(_T("wxStaticText")) ||
329 itemType
== wxString(_T("wxStaticBitmap")))
331 if (childResource
->GetValue4() != _T(""))
334 wxBitmap bitmap
= childResource
->GetBitmap();
337 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
338 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
340 #if wxUSE_BITMAP_MESSAGE
342 control
= new wxStaticBitmap(parent
, id
, bitmap
, pos
, size
,
343 childResource
->GetStyle(), childResource
->GetName());
348 control
= new wxStaticText(parent
, id
, childResource
->GetTitle(), pos
, size
,
349 childResource
->GetStyle(), childResource
->GetName());
352 else if (itemType
== wxString(_T("wxText")) || itemType
== wxString(_T("wxTextCtrl")) || itemType
== wxString(_T("wxMultiText")))
354 control
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(), pos
, size
,
355 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
357 else if (itemType
== wxString(_T("wxCheckBox")))
359 control
= new wxCheckBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
360 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
362 ((wxCheckBox
*)control
)->SetValue((childResource
->GetValue1() != 0));
365 else if (itemType
== wxString(_T("wxGauge")))
367 control
= new wxGauge(parent
, id
, (int)childResource
->GetValue2(), pos
, size
,
368 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
370 ((wxGauge
*)control
)->SetValue((int)childResource
->GetValue1());
374 else if (itemType
== wxString(_T("wxRadioButton")))
376 control
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(),
378 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
382 else if (itemType
== wxString(_T("wxScrollBar")))
384 control
= new wxScrollBar(parent
, id
, pos
, size
,
385 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
387 ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1());
388 ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2());
389 ((wxScrollBar *)control)->SetObjectLength((int)childResource->GetValue3());
390 ((wxScrollBar *)control)->SetViewLength((int)(long)childResource->GetValue5());
392 ((wxScrollBar
*)control
)->SetScrollbar((int)childResource
->GetValue1(),(int)childResource
->GetValue2(),
393 (int)childResource
->GetValue3(),(int)(long)childResource
->GetValue5(),FALSE
);
397 else if (itemType
== wxString(_T("wxSlider")))
399 control
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(),
400 (int)childResource
->GetValue2(), (int)childResource
->GetValue3(), pos
, size
,
401 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
403 else if (itemType
== wxString(_T("wxGroupBox")) || itemType
== wxString(_T("wxStaticBox")))
405 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
406 childResource
->GetStyle(), childResource
->GetName());
408 else if (itemType
== wxString(_T("wxListBox")))
410 wxStringList
& stringList
= childResource
->GetStringValues();
411 wxString
*strings
= (wxString
*) NULL
;
413 if (stringList
.Number() > 0)
415 noStrings
= stringList
.Number();
416 strings
= new wxString
[noStrings
];
417 wxNode
*node
= stringList
.First();
421 strings
[i
] = (wxChar
*)node
->Data();
426 control
= new wxListBox(parent
, id
, pos
, size
,
427 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
432 else if (itemType
== wxString(_T("wxChoice")))
434 wxStringList
& stringList
= childResource
->GetStringValues();
435 wxString
*strings
= (wxString
*) NULL
;
437 if (stringList
.Number() > 0)
439 noStrings
= stringList
.Number();
440 strings
= new wxString
[noStrings
];
441 wxNode
*node
= stringList
.First();
445 strings
[i
] = (wxChar
*)node
->Data();
450 control
= new wxChoice(parent
, id
, pos
, size
,
451 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
457 else if (itemType
== wxString(_T("wxComboBox")))
459 wxStringList
& stringList
= childResource
->GetStringValues();
460 wxString
*strings
= (wxString
*) NULL
;
462 if (stringList
.Number() > 0)
464 noStrings
= stringList
.Number();
465 strings
= new wxString
[noStrings
];
466 wxNode
*node
= stringList
.First();
470 strings
[i
] = (wxChar
*)node
->Data();
475 control
= new wxComboBox(parent
, id
, childResource
->GetValue4(), pos
, size
,
476 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
482 else if (itemType
== wxString(_T("wxRadioBox")))
484 wxStringList
& stringList
= childResource
->GetStringValues();
485 wxString
*strings
= (wxString
*) NULL
;
487 if (stringList
.Number() > 0)
489 noStrings
= stringList
.Number();
490 strings
= new wxString
[noStrings
];
491 wxNode
*node
= stringList
.First();
495 strings
[i
] = (wxChar
*)node
->Data();
500 control
= new wxRadioBox(parent
, (wxWindowID
) id
, wxString(childResource
->GetTitle()), pos
, size
,
501 noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
,
502 childResource
->GetName());
508 if ((parentResource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
510 // Don't set font; will be inherited from parent.
514 if (control
&& childResource
->GetFont().Ok())
515 control
->SetFont(childResource
->GetFont());
521 * Interpret database as a series of resources
524 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
)
526 wxNode
*node
= db
.First();
529 wxExpr
*clause
= (wxExpr
*)node
->Data();
530 wxString
functor(clause
->Functor());
532 wxItemResource
*item
= (wxItemResource
*) NULL
;
533 if (functor
== _T("dialog"))
534 item
= wxResourceInterpretDialog(table
, clause
);
535 else if (functor
== _T("panel"))
536 item
= wxResourceInterpretDialog(table
, clause
, TRUE
);
537 else if (functor
== _T("menubar"))
538 item
= wxResourceInterpretMenuBar(table
, clause
);
539 else if (functor
== _T("menu"))
540 item
= wxResourceInterpretMenu(table
, clause
);
541 else if (functor
== _T("string"))
542 item
= wxResourceInterpretString(table
, clause
);
543 else if (functor
== _T("bitmap"))
544 item
= wxResourceInterpretBitmap(table
, clause
);
545 else if (functor
== _T("icon"))
546 item
= wxResourceInterpretIcon(table
, clause
);
550 // Remove any existing resource of same name
551 if (item
->GetName() != _T(""))
552 table
.DeleteResource(item
->GetName());
553 table
.AddResource(item
);
560 static const wxChar
*g_ValidControlClasses
[] =
563 _T("wxBitmapButton"),
566 _T("wxStaticBitmap"),
574 _T("wxBitmapCheckBox"),
584 static bool wxIsValidControlClass(const wxString
& c
)
586 for ( size_t i
= 0; i
< WXSIZEOF(g_ValidControlClasses
); i
++ )
588 if ( c
== g_ValidControlClasses
[i
] )
594 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
)
596 wxItemResource
*dialogItem
= new wxItemResource
;
598 dialogItem
->SetType(_T("wxPanel"));
600 dialogItem
->SetType(_T("wxDialog"));
601 wxString style
= _T("");
602 wxString title
= _T("");
603 wxString name
= _T("");
604 wxString backColourHex
= _T("");
605 wxString labelColourHex
= _T("");
606 wxString buttonColourHex
= _T("");
608 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
612 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
614 wxExpr
*labelFontExpr
= (wxExpr
*) NULL
;
615 wxExpr
*buttonFontExpr
= (wxExpr
*) NULL
;
616 wxExpr
*fontExpr
= (wxExpr
*) NULL
;
617 expr
->GetAttributeValue(_T("style"), style
);
618 expr
->GetAttributeValue(_T("name"), name
);
619 expr
->GetAttributeValue(_T("title"), title
);
620 expr
->GetAttributeValue(_T("x"), x
);
621 expr
->GetAttributeValue(_T("y"), y
);
622 expr
->GetAttributeValue(_T("width"), width
);
623 expr
->GetAttributeValue(_T("height"), height
);
624 expr
->GetAttributeValue(_T("modal"), isModal
);
625 expr
->GetAttributeValue(_T("label_font"), &labelFontExpr
);
626 expr
->GetAttributeValue(_T("button_font"), &buttonFontExpr
);
627 expr
->GetAttributeValue(_T("font"), &fontExpr
);
628 expr
->GetAttributeValue(_T("background_colour"), backColourHex
);
629 expr
->GetAttributeValue(_T("label_colour"), labelColourHex
);
630 expr
->GetAttributeValue(_T("button_colour"), buttonColourHex
);
632 int useDialogUnits
= 0;
633 expr
->GetAttributeValue(_T("use_dialog_units"), useDialogUnits
);
634 if (useDialogUnits
!= 0)
635 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS
);
638 expr
->GetAttributeValue(_T("use_system_defaults"), useDefaults
);
639 if (useDefaults
!= 0)
640 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS
);
643 expr
->GetAttributeValue(_T("id"), id
);
644 dialogItem
->SetId(id
);
648 windowStyle
= wxParseWindowStyle(style
);
650 dialogItem
->SetStyle(windowStyle
);
651 dialogItem
->SetValue1(isModal
);
652 if (windowStyle
& wxDIALOG_MODAL
) // Uses style in wxWin 2
653 dialogItem
->SetValue1(TRUE
);
655 dialogItem
->SetName(name
);
656 dialogItem
->SetTitle(title
);
657 dialogItem
->SetSize(x
, y
, width
, height
);
659 if (backColourHex
!= _T(""))
664 r
= wxHexToDec(backColourHex
.Mid(0, 2));
665 g
= wxHexToDec(backColourHex
.Mid(2, 2));
666 b
= wxHexToDec(backColourHex
.Mid(4, 2));
667 dialogItem
->SetBackgroundColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
669 if (labelColourHex
!= _T(""))
674 r
= wxHexToDec(labelColourHex
.Mid(0, 2));
675 g
= wxHexToDec(labelColourHex
.Mid(2, 2));
676 b
= wxHexToDec(labelColourHex
.Mid(4, 2));
677 dialogItem
->SetLabelColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
679 if (buttonColourHex
!= _T(""))
684 r
= wxHexToDec(buttonColourHex
.Mid(0, 2));
685 g
= wxHexToDec(buttonColourHex
.Mid(2, 2));
686 b
= wxHexToDec(buttonColourHex
.Mid(4, 2));
687 dialogItem
->SetButtonColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
691 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
692 else if (buttonFontExpr
)
693 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
694 else if (labelFontExpr
)
695 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
697 // Now parse all controls
698 wxExpr
*controlExpr
= expr
->GetFirst();
701 if (controlExpr
->Number() == 3)
703 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
704 if (controlKeyword
!= _T("") && controlKeyword
== _T("control"))
706 // The value part: always a list.
707 wxExpr
*listExpr
= controlExpr
->Nth(2);
708 if (listExpr
->Type() == PrologList
)
710 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
713 dialogItem
->GetChildren().Append(controlItem
);
718 controlExpr
= controlExpr
->GetNext();
723 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
)
725 wxItemResource
*controlItem
= new wxItemResource
;
727 // First, find the standard features of a control definition:
728 // [optional integer/string id], control name, title, style, name, x, y, width, height
730 wxString controlType
;
735 long windowStyle
= 0;
736 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
739 wxExpr
*expr1
= expr
->Nth(0);
741 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
743 if ( wxIsValidControlClass(expr1
->StringValue()) )
746 controlType
= expr1
->StringValue();
750 wxString
str(expr1
->StringValue());
751 id
= wxResourceGetIdentifier(str
, &table
);
754 wxLogWarning(_("Could not resolve control class or id '%s'. "
755 "Use (non-zero) integer instead\n or provide #define "
756 "(see manual for caveats)"),
757 (const wxChar
*) expr1
->StringValue());
759 return (wxItemResource
*) NULL
;
763 // Success - we have an id, so the 2nd element must be the control class.
764 controlType
= expr
->Nth(1)->StringValue();
769 else if (expr1
->Type() == PrologInteger
)
771 id
= (int)expr1
->IntegerValue();
772 // Success - we have an id, so the 2nd element must be the control class.
773 controlType
= expr
->Nth(1)->StringValue();
777 expr1
= expr
->Nth(count
);
780 title
= expr1
->StringValue();
782 expr1
= expr
->Nth(count
);
786 style
= expr1
->StringValue();
787 windowStyle
= wxParseWindowStyle(style
);
790 expr1
= expr
->Nth(count
);
793 name
= expr1
->StringValue();
795 expr1
= expr
->Nth(count
);
798 x
= (int)expr1
->IntegerValue();
800 expr1
= expr
->Nth(count
);
803 y
= (int)expr1
->IntegerValue();
805 expr1
= expr
->Nth(count
);
808 width
= (int)expr1
->IntegerValue();
810 expr1
= expr
->Nth(count
);
813 height
= (int)expr1
->IntegerValue();
815 controlItem
->SetStyle(windowStyle
);
816 controlItem
->SetName(name
);
817 controlItem
->SetTitle(title
);
818 controlItem
->SetSize(x
, y
, width
, height
);
819 controlItem
->SetType(controlType
);
820 controlItem
->SetId(id
);
822 if (controlType
== _T("wxButton"))
824 // Check for bitmap resource name (in case loading old-style resource file)
825 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
827 wxString
str(expr
->Nth(count
)->StringValue());
832 controlItem
->SetValue4(str
);
833 controlItem
->SetType(_T("wxBitmapButton"));
836 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
837 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
839 else if (controlType
== _T("wxBitmapButton"))
841 // Check for bitmap resource name
842 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
844 wxString
str(expr
->Nth(count
)->StringValue());
845 controlItem
->SetValue4(str
);
847 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
848 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
851 else if (controlType
== _T("wxCheckBox"))
853 // Check for default value
854 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
856 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
858 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
859 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
863 else if (controlType
== _T("wxRadioButton"))
865 // Check for default value
866 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
868 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
870 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
871 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
875 else if (controlType
== _T("wxText") || controlType
== _T("wxTextCtrl") || controlType
== _T("wxMultiText"))
877 // Check for default value
878 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
880 wxString
str(expr
->Nth(count
)->StringValue());
881 controlItem
->SetValue4(str
);
884 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
886 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
887 // Do nothing - no label font any more
889 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
890 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
894 else if (controlType
== _T("wxMessage") || controlType
== _T("wxStaticText"))
896 // Check for bitmap resource name (in case it's an old-style .wxr file)
897 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
899 wxString
str(expr
->Nth(count
)->StringValue());
900 controlItem
->SetValue4(str
);
902 controlItem
->SetType(_T("wxStaticText"));
904 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
905 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
907 else if (controlType
== _T("wxStaticBitmap"))
909 // Check for bitmap resource name
910 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
912 wxString
str(expr
->Nth(count
)->StringValue());
913 controlItem
->SetValue4(str
);
916 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
917 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
919 else if (controlType
== _T("wxGroupBox") || controlType
== _T("wxStaticBox"))
921 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
922 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
924 else if (controlType
== _T("wxGauge"))
926 // Check for default value
927 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
929 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
933 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
935 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
938 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
940 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
944 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
945 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
950 else if (controlType
== _T("wxSlider"))
952 // Check for default value
953 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
955 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
959 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
961 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
965 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
967 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
970 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
972 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
976 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
977 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
983 else if (controlType
== _T("wxScrollBar"))
986 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
988 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
992 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
994 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
998 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1000 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1004 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1005 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
1010 else if (controlType
== _T("wxListBox"))
1012 wxExpr
*valueList
= (wxExpr
*) NULL
;
1014 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1016 wxStringList stringList
;
1017 wxExpr
*stringExpr
= valueList
->GetFirst();
1020 stringList
.Add(stringExpr
->StringValue());
1021 stringExpr
= stringExpr
->GetNext();
1023 controlItem
->SetStringValues(stringList
);
1025 // This is now obsolete: it's in the window style.
1026 // Check for wxSINGLE/wxMULTIPLE
1027 wxExpr
*mult
= (wxExpr
*) NULL
;
1029 controlItem->SetValue1(wxLB_SINGLE);
1031 if ((mult
= expr
->Nth(count
)) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1034 wxString m(mult->StringValue());
1035 if (m == "wxLB_MULTIPLE")
1036 controlItem->SetValue1(wxLB_MULTIPLE);
1037 else if (m == "wxLB_EXTENDED")
1038 controlItem->SetValue1(wxLB_EXTENDED);
1043 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1045 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1047 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1048 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1052 else if (controlType
== _T("wxChoice"))
1054 wxExpr
*valueList
= (wxExpr
*) NULL
;
1055 // Check for default value list
1056 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1058 wxStringList stringList
;
1059 wxExpr
*stringExpr
= valueList
->GetFirst();
1062 stringList
.Add(stringExpr
->StringValue());
1063 stringExpr
= stringExpr
->GetNext();
1065 controlItem
->SetStringValues(stringList
);
1069 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1071 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1074 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1075 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1080 else if (controlType
== _T("wxComboBox"))
1082 wxExpr
*textValue
= expr
->Nth(count
);
1083 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1085 wxString
str(textValue
->StringValue());
1086 controlItem
->SetValue4(str
);
1090 wxExpr
*valueList
= (wxExpr
*) NULL
;
1091 // Check for default value list
1092 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1094 wxStringList stringList
;
1095 wxExpr
*stringExpr
= valueList
->GetFirst();
1098 stringList
.Add(stringExpr
->StringValue());
1099 stringExpr
= stringExpr
->GetNext();
1101 controlItem
->SetStringValues(stringList
);
1105 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1107 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1110 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1111 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1118 else if (controlType
== _T("wxRadioBox"))
1120 wxExpr
*valueList
= (wxExpr
*) NULL
;
1121 // Check for default value list
1122 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1124 wxStringList stringList
;
1125 wxExpr
*stringExpr
= valueList
->GetFirst();
1128 stringList
.Add(stringExpr
->StringValue());
1129 stringExpr
= stringExpr
->GetNext();
1131 controlItem
->SetStringValues(stringList
);
1134 // majorDim (number of rows or cols)
1135 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1137 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1141 controlItem
->SetValue1(0);
1143 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1145 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1148 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1149 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1157 return (wxItemResource
*) NULL
;
1162 // Forward declaration
1163 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, wxExpr
*expr
);
1166 * Interpet a menu item
1169 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, wxExpr
*expr
)
1171 wxItemResource
*item
= new wxItemResource
;
1173 wxExpr
*labelExpr
= expr
->Nth(0);
1174 wxExpr
*idExpr
= expr
->Nth(1);
1175 wxExpr
*helpExpr
= expr
->Nth(2);
1176 wxExpr
*checkableExpr
= expr
->Nth(3);
1178 // Further keywords/attributes to follow sometime...
1179 if (expr
->Number() == 0)
1181 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1182 item
->SetType(_T("wxMenuSeparator"));
1187 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1188 item
->SetType(_T("wxMenu")); // Well, menu item, but doesn't matter.
1191 wxString
str(labelExpr
->StringValue());
1192 item
->SetTitle(str
);
1197 // If a string or word, must look up in identifier table.
1198 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1200 wxString
str(idExpr
->StringValue());
1201 id
= wxResourceGetIdentifier(str
, &table
);
1204 wxLogWarning(_("Could not resolve menu id '%s'. "
1205 "Use (non-zero) integer instead\n"
1206 "or provide #define (see manual for caveats)"),
1207 (const wxChar
*) idExpr
->StringValue());
1210 else if (idExpr
->Type() == PrologInteger
)
1211 id
= (int)idExpr
->IntegerValue();
1212 item
->SetValue1(id
);
1216 wxString
str(helpExpr
->StringValue());
1217 item
->SetValue4(str
);
1220 item
->SetValue2(checkableExpr
->IntegerValue());
1222 // Find the first expression that's a list, for submenu
1223 wxExpr
*subMenuExpr
= expr
->GetFirst();
1224 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1225 subMenuExpr
= subMenuExpr
->GetNext();
1229 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1230 item
->GetChildren().Append(child
);
1231 subMenuExpr
= subMenuExpr
->GetNext();
1238 * Interpret a nested list as a menu
1241 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1243 wxItemResource *menu = new wxItemResource;
1244 // menu->SetType(wxTYPE_MENU);
1245 menu->SetType("wxMenu");
1246 wxExpr *element = expr->GetFirst();
1249 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1251 menu->GetChildren().Append(item);
1252 element = element->GetNext();
1258 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
)
1260 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1261 expr
->GetAttributeValue(_T("menu"), &listExpr
);
1263 return (wxItemResource
*) NULL
;
1265 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1268 return (wxItemResource
*) NULL
;
1271 if (expr
->GetAttributeValue(_T("name"), name
))
1273 menuResource
->SetName(name
);
1276 return menuResource
;
1279 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
)
1281 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1282 expr
->GetAttributeValue(_T("menu"), &listExpr
);
1284 return (wxItemResource
*) NULL
;
1286 wxItemResource
*resource
= new wxItemResource
;
1287 resource
->SetType(_T("wxMenu"));
1288 // resource->SetType(wxTYPE_MENU);
1290 wxExpr
*element
= listExpr
->GetFirst();
1293 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1294 resource
->GetChildren().Append(menuResource
);
1295 element
= element
->GetNext();
1299 if (expr
->GetAttributeValue(_T("name"), name
))
1301 resource
->SetName(name
);
1307 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), wxExpr
*WXUNUSED(expr
))
1309 return (wxItemResource
*) NULL
;
1312 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), wxExpr
*expr
)
1314 wxItemResource
*bitmapItem
= new wxItemResource
;
1315 // bitmapItem->SetType(wxTYPE_BITMAP);
1316 bitmapItem
->SetType(_T("wxBitmap"));
1318 if (expr
->GetAttributeValue(_T("name"), name
))
1320 bitmapItem
->SetName(name
);
1322 // Now parse all bitmap specifications
1323 wxExpr
*bitmapExpr
= expr
->GetFirst();
1326 if (bitmapExpr
->Number() == 3)
1328 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1329 if (bitmapKeyword
== _T("bitmap") || bitmapKeyword
== _T("icon"))
1331 // The value part: always a list.
1332 wxExpr
*listExpr
= bitmapExpr
->Nth(2);
1333 if (listExpr
->Type() == PrologList
)
1335 wxItemResource
*bitmapSpec
= new wxItemResource
;
1336 // bitmapSpec->SetType(wxTYPE_BITMAP);
1337 bitmapSpec
->SetType(_T("wxBitmap"));
1339 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1340 // where everything after 'filename' is optional.
1341 wxExpr
*nameExpr
= listExpr
->Nth(0);
1342 wxExpr
*typeExpr
= listExpr
->Nth(1);
1343 wxExpr
*platformExpr
= listExpr
->Nth(2);
1344 wxExpr
*coloursExpr
= listExpr
->Nth(3);
1345 wxExpr
*xresExpr
= listExpr
->Nth(4);
1346 wxExpr
*yresExpr
= listExpr
->Nth(5);
1347 if (nameExpr
&& nameExpr
->StringValue() != _T(""))
1349 bitmapSpec
->SetName(nameExpr
->StringValue());
1351 if (typeExpr
&& typeExpr
->StringValue() != _T(""))
1353 bitmapSpec
->SetValue1(wxParseWindowStyle(typeExpr
->StringValue()));
1356 bitmapSpec
->SetValue1(0);
1358 if (platformExpr
&& platformExpr
->StringValue() != _T(""))
1360 wxString
plat(platformExpr
->StringValue());
1361 if (plat
== _T("windows") || plat
== _T("WINDOWS"))
1362 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1363 else if (plat
== _T("x") || plat
== _T("X"))
1364 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1365 else if (plat
== _T("mac") || plat
== _T("MAC"))
1366 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1368 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1371 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1374 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1378 xres
= (int)xresExpr
->IntegerValue();
1380 yres
= (int)yresExpr
->IntegerValue();
1381 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1383 bitmapItem
->GetChildren().Append(bitmapSpec
);
1387 bitmapExpr
= bitmapExpr
->GetNext();
1393 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
)
1395 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1398 // item->SetType(wxTYPE_ICON);
1399 item
->SetType(_T("wxIcon"));
1403 return (wxItemResource
*) NULL
;
1406 // Interpret list expression as a font
1407 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
)
1409 if (expr
->Type() != PrologList
)
1413 int family
= wxSWISS
;
1414 int style
= wxNORMAL
;
1415 int weight
= wxNORMAL
;
1417 wxString
faceName(_T(""));
1419 wxExpr
*pointExpr
= expr
->Nth(0);
1420 wxExpr
*familyExpr
= expr
->Nth(1);
1421 wxExpr
*styleExpr
= expr
->Nth(2);
1422 wxExpr
*weightExpr
= expr
->Nth(3);
1423 wxExpr
*underlineExpr
= expr
->Nth(4);
1424 wxExpr
*faceNameExpr
= expr
->Nth(5);
1426 point
= (int)pointExpr
->IntegerValue();
1431 str
= familyExpr
->StringValue();
1432 family
= (int)wxParseWindowStyle(str
);
1436 str
= styleExpr
->StringValue();
1437 style
= (int)wxParseWindowStyle(str
);
1441 str
= weightExpr
->StringValue();
1442 weight
= (int)wxParseWindowStyle(str
);
1445 underline
= (int)underlineExpr
->IntegerValue();
1447 faceName
= faceNameExpr
->StringValue();
1449 wxFont
font(point
, family
, style
, weight
, (underline
!= 0), faceName
);
1453 // Separate file for the remainder of this, for BC++/Win16
1455 #if !((defined(__BORLANDC__) || defined(__SC__)) && defined(__WIN16__))
1457 * (Re)allocate buffer for reading in from resource file
1460 bool wxReallocateResourceBuffer()
1462 if (!wxResourceBuffer
)
1464 wxResourceBufferSize
= 1000;
1465 wxResourceBuffer
= new char[wxResourceBufferSize
];
1468 if (wxResourceBuffer
)
1470 long newSize
= wxResourceBufferSize
+ 1000;
1471 char *tmp
= new char[(int)newSize
];
1472 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1473 delete[] wxResourceBuffer
;
1474 wxResourceBuffer
= tmp
;
1475 wxResourceBufferSize
= newSize
;
1480 static bool wxEatWhiteSpace(FILE *fd
)
1484 while ((ch
= getc(fd
)) != EOF
)
1499 ungetc(prev_ch
, fd
);
1507 while ((ch
= getc(fd
)) != EOF
)
1509 if (ch
== '/' && prev_ch
== '*')
1517 static char buffer
[255];
1518 fgets(buffer
, 255, fd
);
1522 ungetc(prev_ch
, fd
);
1537 bool wxGetResourceToken(FILE *fd
)
1539 if (!wxResourceBuffer
)
1540 wxReallocateResourceBuffer();
1541 wxResourceBuffer
[0] = 0;
1542 wxEatWhiteSpace(fd
);
1548 wxResourceBufferCount
= 0;
1555 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1558 // Escaped characters
1559 else if (ch
== '\\')
1561 int newCh
= getc(fd
);
1564 else if (newCh
== 10)
1572 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1573 wxReallocateResourceBuffer();
1574 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1575 wxResourceBufferCount
++;
1578 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1582 wxResourceBufferCount
= 0;
1584 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1586 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1587 wxReallocateResourceBuffer();
1588 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1589 wxResourceBufferCount
++;
1593 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1601 * Files are in form:
1602 static char *name = "....";
1603 with possible comments.
1606 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1609 table
= wxDefaultResourceTable
;
1611 // static or #define
1612 if (!wxGetResourceToken(fd
))
1618 if (strcmp(wxResourceBuffer
, "#define") == 0)
1620 wxGetResourceToken(fd
);
1621 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1622 wxGetResourceToken(fd
);
1623 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1624 if (wxIsalpha(value
[0]))
1626 int val
= (int)wxAtol(value
);
1627 wxResourceAddIdentifier(name
, val
, table
);
1631 wxLogWarning(_("#define %s must be an integer."), name
);
1641 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1643 wxGetResourceToken(fd
);
1644 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1645 wxChar
*actualName
= name
;
1646 if (name
[0] == _T('"'))
1647 actualName
= name
+ 1;
1648 int len
= wxStrlen(name
);
1649 if ((len
> 0) && (name
[len
-1] == _T('"')))
1651 if (!wxResourceParseIncludeFile(actualName
, table
))
1653 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1658 else if (strcmp(wxResourceBuffer
, "static") != 0)
1661 wxStrcpy(buf
, _("Found "));
1662 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
1663 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1669 if (!wxGetResourceToken(fd
))
1671 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1676 if (strcmp(wxResourceBuffer
, "char") != 0)
1678 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1683 if (!wxGetResourceToken(fd
))
1685 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1690 if (wxResourceBuffer
[0] != '*')
1692 wxLogWarning(_("Expected '*' whilst parsing resource."));
1695 wxChar nameBuf
[100];
1696 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
1700 if (!wxGetResourceToken(fd
))
1702 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1707 if (strcmp(wxResourceBuffer
, "=") != 0)
1709 wxLogWarning(_("Expected '=' whilst parsing resource."));
1714 if (!wxGetResourceToken(fd
))
1716 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1722 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1724 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1729 if (!wxGetResourceToken(fd
))
1737 * Parses string window style into integer window style
1741 * Style flag parsing, e.g.
1742 * "wxSYSTEM_MENU | wxBORDER" -> integer
1745 wxChar
* wxResourceParseWord(wxChar
*s
, int *i
)
1748 return (wxChar
*) NULL
;
1750 static wxChar buf
[150];
1751 int len
= wxStrlen(s
);
1754 while ((ii
< len
) && (wxIsalpha(s
[ii
]) || (s
[ii
] == _T('_'))))
1762 // Eat whitespace and conjunction characters
1763 while ((ii
< len
) &&
1764 ((s
[ii
] == _T(' ')) || (s
[ii
] == _T('|')) || (s
[ii
] == _T(','))))
1770 return (wxChar
*) NULL
;
1775 struct wxResourceBitListStruct
1781 static wxResourceBitListStruct wxResourceBitListTable
[] =
1784 { _T("wxSINGLE"), wxLB_SINGLE
},
1785 { _T("wxMULTIPLE"), wxLB_MULTIPLE
},
1786 { _T("wxEXTENDED"), wxLB_EXTENDED
},
1787 { _T("wxLB_SINGLE"), wxLB_SINGLE
},
1788 { _T("wxLB_MULTIPLE"), wxLB_MULTIPLE
},
1789 { _T("wxLB_EXTENDED"), wxLB_EXTENDED
},
1790 { _T("wxLB_NEEDED_SB"), wxLB_NEEDED_SB
},
1791 { _T("wxLB_ALWAYS_SB"), wxLB_ALWAYS_SB
},
1792 { _T("wxLB_SORT"), wxLB_SORT
},
1793 { _T("wxLB_OWNERDRAW"), wxLB_OWNERDRAW
},
1794 { _T("wxLB_HSCROLL"), wxLB_HSCROLL
},
1797 { _T("wxCB_SIMPLE"), wxCB_SIMPLE
},
1798 { _T("wxCB_DROPDOWN"), wxCB_DROPDOWN
},
1799 { _T("wxCB_READONLY"), wxCB_READONLY
},
1800 { _T("wxCB_SORT"), wxCB_SORT
},
1803 { _T("wxGA_PROGRESSBAR"), wxGA_PROGRESSBAR
},
1804 { _T("wxGA_HORIZONTAL"), wxGA_HORIZONTAL
},
1805 { _T("wxGA_VERTICAL"), wxGA_VERTICAL
},
1808 { _T("wxPASSWORD"), wxPASSWORD
},
1809 { _T("wxPROCESS_ENTER"), wxPROCESS_ENTER
},
1810 { _T("wxTE_PASSWORD"), wxTE_PASSWORD
},
1811 { _T("wxTE_READONLY"), wxTE_READONLY
},
1812 { _T("wxTE_PROCESS_ENTER"), wxTE_PROCESS_ENTER
},
1813 { _T("wxTE_MULTILINE"), wxTE_MULTILINE
},
1815 /* wxRadioBox/wxRadioButton */
1816 { _T("wxRB_GROUP"), wxRB_GROUP
},
1817 { _T("wxRA_SPECIFY_COLS"), wxRA_SPECIFY_COLS
},
1818 { _T("wxRA_SPECIFY_ROWS"), wxRA_SPECIFY_ROWS
},
1819 { _T("wxRA_HORIZONTAL"), wxRA_HORIZONTAL
},
1820 { _T("wxRA_VERTICAL"), wxRA_VERTICAL
},
1823 { _T("wxSL_HORIZONTAL"), wxSL_HORIZONTAL
},
1824 { _T("wxSL_VERTICAL"), wxSL_VERTICAL
},
1825 { _T("wxSL_AUTOTICKS"), wxSL_AUTOTICKS
},
1826 { _T("wxSL_LABELS"), wxSL_LABELS
},
1827 { _T("wxSL_LEFT"), wxSL_LEFT
},
1828 { _T("wxSL_TOP"), wxSL_TOP
},
1829 { _T("wxSL_RIGHT"), wxSL_RIGHT
},
1830 { _T("wxSL_BOTTOM"), wxSL_BOTTOM
},
1831 { _T("wxSL_BOTH"), wxSL_BOTH
},
1832 { _T("wxSL_SELRANGE"), wxSL_SELRANGE
},
1835 { _T("wxSB_HORIZONTAL"), wxSB_HORIZONTAL
},
1836 { _T("wxSB_VERTICAL"), wxSB_VERTICAL
},
1839 { _T("wxBU_AUTODRAW"), wxBU_AUTODRAW
},
1840 { _T("wxBU_NOAUTODRAW"), wxBU_NOAUTODRAW
},
1843 { _T("wxTR_HAS_BUTTONS"), wxTR_HAS_BUTTONS
},
1844 { _T("wxTR_EDIT_LABELS"), wxTR_EDIT_LABELS
},
1845 { _T("wxTR_LINES_AT_ROOT"), wxTR_LINES_AT_ROOT
},
1848 { _T("wxLC_ICON"), wxLC_ICON
},
1849 { _T("wxLC_SMALL_ICON"), wxLC_SMALL_ICON
},
1850 { _T("wxLC_LIST"), wxLC_LIST
},
1851 { _T("wxLC_REPORT"), wxLC_REPORT
},
1852 { _T("wxLC_ALIGN_TOP"), wxLC_ALIGN_TOP
},
1853 { _T("wxLC_ALIGN_LEFT"), wxLC_ALIGN_LEFT
},
1854 { _T("wxLC_AUTOARRANGE"), wxLC_AUTOARRANGE
},
1855 { _T("wxLC_USER_TEXT"), wxLC_USER_TEXT
},
1856 { _T("wxLC_EDIT_LABELS"), wxLC_EDIT_LABELS
},
1857 { _T("wxLC_NO_HEADER"), wxLC_NO_HEADER
},
1858 { _T("wxLC_NO_SORT_HEADER"), wxLC_NO_SORT_HEADER
},
1859 { _T("wxLC_SINGLE_SEL"), wxLC_SINGLE_SEL
},
1860 { _T("wxLC_SORT_ASCENDING"), wxLC_SORT_ASCENDING
},
1861 { _T("wxLC_SORT_DESCENDING"), wxLC_SORT_DESCENDING
},
1864 { _T("wxSP_VERTICAL"), wxSP_VERTICAL
},
1865 { _T("wxSP_HORIZONTAL"), wxSP_HORIZONTAL
},
1866 { _T("wxSP_ARROW_KEYS"), wxSP_ARROW_KEYS
},
1867 { _T("wxSP_WRAP"), wxSP_WRAP
},
1870 { _T("wxSP_NOBORDER"), wxSP_NOBORDER
},
1871 { _T("wxSP_3D"), wxSP_3D
},
1872 { _T("wxSP_BORDER"), wxSP_BORDER
},
1875 { _T("wxTC_MULTILINE"), wxTC_MULTILINE
},
1876 { _T("wxTC_RIGHTJUSTIFY"), wxTC_RIGHTJUSTIFY
},
1877 { _T("wxTC_FIXEDWIDTH"), wxTC_FIXEDWIDTH
},
1878 { _T("wxTC_OWNERDRAW"), wxTC_OWNERDRAW
},
1881 { _T("wxST_SIZEGRIP"), wxST_SIZEGRIP
},
1884 { _T("wxFIXED_LENGTH"), wxFIXED_LENGTH
},
1885 { _T("wxALIGN_LEFT"), wxALIGN_LEFT
},
1886 { _T("wxALIGN_CENTER"), wxALIGN_CENTER
},
1887 { _T("wxALIGN_CENTRE"), wxALIGN_CENTRE
},
1888 { _T("wxALIGN_RIGHT"), wxALIGN_RIGHT
},
1889 { _T("wxCOLOURED"), wxCOLOURED
},
1892 { _T("wxTB_3DBUTTONS"), wxTB_3DBUTTONS
},
1893 { _T("wxTB_HORIZONTAL"), wxTB_HORIZONTAL
},
1894 { _T("wxTB_VERTICAL"), wxTB_VERTICAL
},
1895 { _T("wxTB_FLAT"), wxTB_FLAT
},
1898 { _T("wxDIALOG_MODAL"), wxDIALOG_MODAL
},
1901 { _T("wxVSCROLL"), wxVSCROLL
},
1902 { _T("wxHSCROLL"), wxHSCROLL
},
1903 { _T("wxCAPTION"), wxCAPTION
},
1904 { _T("wxSTAY_ON_TOP"), wxSTAY_ON_TOP
},
1905 { _T("wxICONIZE"), wxICONIZE
},
1906 { _T("wxMINIMIZE"), wxICONIZE
},
1907 { _T("wxMAXIMIZE"), wxMAXIMIZE
},
1909 { _T("wxMDI_PARENT"), 0},
1910 { _T("wxMDI_CHILD"), 0},
1911 { _T("wxTHICK_FRAME"), wxTHICK_FRAME
},
1912 { _T("wxRESIZE_BORDER"), wxRESIZE_BORDER
},
1913 { _T("wxSYSTEM_MENU"), wxSYSTEM_MENU
},
1914 { _T("wxMINIMIZE_BOX"), wxMINIMIZE_BOX
},
1915 { _T("wxMAXIMIZE_BOX"), wxMAXIMIZE_BOX
},
1916 { _T("wxRESIZE_BOX"), wxRESIZE_BOX
},
1917 { _T("wxDEFAULT_FRAME_STYLE"), wxDEFAULT_FRAME_STYLE
},
1918 { _T("wxDEFAULT_FRAME"), wxDEFAULT_FRAME_STYLE
},
1919 { _T("wxDEFAULT_DIALOG_STYLE"), wxDEFAULT_DIALOG_STYLE
},
1920 { _T("wxBORDER"), wxBORDER
},
1921 { _T("wxRETAINED"), wxRETAINED
},
1922 { _T("wxNATIVE_IMPL"), 0},
1923 { _T("wxEXTENDED_IMPL"), 0},
1924 { _T("wxBACKINGSTORE"), wxBACKINGSTORE
},
1925 // { _T("wxFLAT"), wxFLAT},
1926 // { _T("wxMOTIF_RESIZE"), wxMOTIF_RESIZE},
1927 { _T("wxFIXED_LENGTH"), 0},
1928 { _T("wxDOUBLE_BORDER"), wxDOUBLE_BORDER
},
1929 { _T("wxSUNKEN_BORDER"), wxSUNKEN_BORDER
},
1930 { _T("wxRAISED_BORDER"), wxRAISED_BORDER
},
1931 { _T("wxSIMPLE_BORDER"), wxSIMPLE_BORDER
},
1932 { _T("wxSTATIC_BORDER"), wxSTATIC_BORDER
},
1933 { _T("wxTRANSPARENT_WINDOW"), wxTRANSPARENT_WINDOW
},
1934 { _T("wxNO_BORDER"), wxNO_BORDER
},
1935 { _T("wxCLIP_CHILDREN"), wxCLIP_CHILDREN
},
1937 { _T("wxTINY_CAPTION_HORIZ"), wxTINY_CAPTION_HORIZ
},
1938 { _T("wxTINY_CAPTION_VERT"), wxTINY_CAPTION_VERT
},
1940 // Text font families
1941 { _T("wxDEFAULT"), wxDEFAULT
},
1942 { _T("wxDECORATIVE"), wxDECORATIVE
},
1943 { _T("wxROMAN"), wxROMAN
},
1944 { _T("wxSCRIPT"), wxSCRIPT
},
1945 { _T("wxSWISS"), wxSWISS
},
1946 { _T("wxMODERN"), wxMODERN
},
1947 { _T("wxTELETYPE"), wxTELETYPE
},
1948 { _T("wxVARIABLE"), wxVARIABLE
},
1949 { _T("wxFIXED"), wxFIXED
},
1950 { _T("wxNORMAL"), wxNORMAL
},
1951 { _T("wxLIGHT"), wxLIGHT
},
1952 { _T("wxBOLD"), wxBOLD
},
1953 { _T("wxITALIC"), wxITALIC
},
1954 { _T("wxSLANT"), wxSLANT
},
1955 { _T("wxSOLID"), wxSOLID
},
1956 { _T("wxDOT"), wxDOT
},
1957 { _T("wxLONG_DASH"), wxLONG_DASH
},
1958 { _T("wxSHORT_DASH"), wxSHORT_DASH
},
1959 { _T("wxDOT_DASH"), wxDOT_DASH
},
1960 { _T("wxUSER_DASH"), wxUSER_DASH
},
1961 { _T("wxTRANSPARENT"), wxTRANSPARENT
},
1962 { _T("wxSTIPPLE"), wxSTIPPLE
},
1963 { _T("wxBDIAGONAL_HATCH"), wxBDIAGONAL_HATCH
},
1964 { _T("wxCROSSDIAG_HATCH"), wxCROSSDIAG_HATCH
},
1965 { _T("wxFDIAGONAL_HATCH"), wxFDIAGONAL_HATCH
},
1966 { _T("wxCROSS_HATCH"), wxCROSS_HATCH
},
1967 { _T("wxHORIZONTAL_HATCH"), wxHORIZONTAL_HATCH
},
1968 { _T("wxVERTICAL_HATCH"), wxVERTICAL_HATCH
},
1969 { _T("wxJOIN_BEVEL"), wxJOIN_BEVEL
},
1970 { _T("wxJOIN_MITER"), wxJOIN_MITER
},
1971 { _T("wxJOIN_ROUND"), wxJOIN_ROUND
},
1972 { _T("wxCAP_ROUND"), wxCAP_ROUND
},
1973 { _T("wxCAP_PROJECTING"), wxCAP_PROJECTING
},
1974 { _T("wxCAP_BUTT"), wxCAP_BUTT
},
1977 { _T("wxCLEAR"), wxCLEAR
},
1978 { _T("wxXOR"), wxXOR
},
1979 { _T("wxINVERT"), wxINVERT
},
1980 { _T("wxOR_REVERSE"), wxOR_REVERSE
},
1981 { _T("wxAND_REVERSE"), wxAND_REVERSE
},
1982 { _T("wxCOPY"), wxCOPY
},
1983 { _T("wxAND"), wxAND
},
1984 { _T("wxAND_INVERT"), wxAND_INVERT
},
1985 { _T("wxNO_OP"), wxNO_OP
},
1986 { _T("wxNOR"), wxNOR
},
1987 { _T("wxEQUIV"), wxEQUIV
},
1988 { _T("wxSRC_INVERT"), wxSRC_INVERT
},
1989 { _T("wxOR_INVERT"), wxOR_INVERT
},
1990 { _T("wxNAND"), wxNAND
},
1991 { _T("wxOR"), wxOR
},
1992 { _T("wxSET"), wxSET
},
1994 { _T("wxFLOOD_SURFACE"), wxFLOOD_SURFACE
},
1995 { _T("wxFLOOD_BORDER"), wxFLOOD_BORDER
},
1996 { _T("wxODDEVEN_RULE"), wxODDEVEN_RULE
},
1997 { _T("wxWINDING_RULE"), wxWINDING_RULE
},
1998 { _T("wxHORIZONTAL"), wxHORIZONTAL
},
1999 { _T("wxVERTICAL"), wxVERTICAL
},
2000 { _T("wxBOTH"), wxBOTH
},
2001 { _T("wxCENTER_FRAME"), wxCENTER_FRAME
},
2002 { _T("wxOK"), wxOK
},
2003 { _T("wxYES_NO"), wxYES_NO
},
2004 { _T("wxCANCEL"), wxCANCEL
},
2005 { _T("wxYES"), wxYES
},
2006 { _T("wxNO"), wxNO
},
2007 { _T("wxICON_EXCLAMATION"), wxICON_EXCLAMATION
},
2008 { _T("wxICON_HAND"), wxICON_HAND
},
2009 { _T("wxICON_QUESTION"), wxICON_QUESTION
},
2010 { _T("wxICON_INFORMATION"), wxICON_INFORMATION
},
2011 { _T("wxICON_STOP"), wxICON_STOP
},
2012 { _T("wxICON_ASTERISK"), wxICON_ASTERISK
},
2013 { _T("wxICON_MASK"), wxICON_MASK
},
2014 { _T("wxCENTRE"), wxCENTRE
},
2015 { _T("wxCENTER"), wxCENTRE
},
2016 { _T("wxUSER_COLOURS"), wxUSER_COLOURS
},
2017 { _T("wxVERTICAL_LABEL"), 0},
2018 { _T("wxHORIZONTAL_LABEL"), 0},
2020 // Bitmap types (not strictly styles)
2021 { _T("wxBITMAP_TYPE_XPM"), wxBITMAP_TYPE_XPM
},
2022 { _T("wxBITMAP_TYPE_XBM"), wxBITMAP_TYPE_XBM
},
2023 { _T("wxBITMAP_TYPE_BMP"), wxBITMAP_TYPE_BMP
},
2024 { _T("wxBITMAP_TYPE_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2025 { _T("wxBITMAP_TYPE_BMP_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2026 { _T("wxBITMAP_TYPE_GIF"), wxBITMAP_TYPE_GIF
},
2027 { _T("wxBITMAP_TYPE_TIF"), wxBITMAP_TYPE_TIF
},
2028 { _T("wxBITMAP_TYPE_ICO"), wxBITMAP_TYPE_ICO
},
2029 { _T("wxBITMAP_TYPE_ICO_RESOURCE"), wxBITMAP_TYPE_ICO_RESOURCE
},
2030 { _T("wxBITMAP_TYPE_CUR"), wxBITMAP_TYPE_CUR
},
2031 { _T("wxBITMAP_TYPE_CUR_RESOURCE"), wxBITMAP_TYPE_CUR_RESOURCE
},
2032 { _T("wxBITMAP_TYPE_XBM_DATA"), wxBITMAP_TYPE_XBM_DATA
},
2033 { _T("wxBITMAP_TYPE_XPM_DATA"), wxBITMAP_TYPE_XPM_DATA
},
2034 { _T("wxBITMAP_TYPE_ANY"), wxBITMAP_TYPE_ANY
}
2037 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
2039 long wxParseWindowStyle(const wxString
& bitListString
)
2044 while ((word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
)))
2048 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2049 if (wxStrcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2051 bitList
|= wxResourceBitListTable
[j
].bits
;
2057 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word
);
2065 * Load a bitmap from a wxWindows resource, choosing an optimum
2066 * depth and appropriate type.
2069 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
2072 table
= wxDefaultResourceTable
;
2074 wxItemResource
*item
= table
->FindResource(resource
);
2077 if ((item
->GetType() == _T("")) || (item
->GetType() != _T("wxBitmap")))
2079 wxLogWarning(_("%s not a bitmap resource specification."), (const wxChar
*) resource
);
2080 return wxNullBitmap
;
2082 int thisDepth
= wxDisplayDepth();
2083 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2085 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2087 // Try to find optimum bitmap for this platform/colour depth
2088 wxNode
*node
= item
->GetChildren().First();
2091 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2092 int platform
= (int)child
->GetValue2();
2093 int noColours
= (int)child
->GetValue3();
2095 char *name = child->GetName();
2096 int bitmapType = (int)child->GetValue1();
2097 int xRes = child->GetWidth();
2098 int yRes = child->GetHeight();
2103 case RESOURCE_PLATFORM_ANY
:
2105 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2106 optResource
= child
;
2109 // Maximise the number of colours.
2110 // If noColours is zero (unspecified), then assume this
2111 // is the right one.
2112 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2113 optResource
= child
;
2118 case RESOURCE_PLATFORM_WINDOWS
:
2120 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2121 optResource
= child
;
2124 // Maximise the number of colours
2125 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2126 optResource
= child
;
2132 case RESOURCE_PLATFORM_X
:
2134 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2135 optResource
= child
;
2138 // Maximise the number of colours
2139 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2140 optResource
= child
;
2146 case RESOURCE_PLATFORM_MAC
:
2148 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2149 optResource
= child
;
2152 // Maximise the number of colours
2153 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2154 optResource
= child
;
2162 node
= node
->Next();
2164 // If no matching resource, fail.
2166 return wxNullBitmap
;
2168 wxString name
= optResource
->GetName();
2169 int bitmapType
= (int)optResource
->GetValue1();
2172 case wxBITMAP_TYPE_XBM_DATA
:
2175 wxItemResource
*item
= table
->FindResource(name
);
2178 wxLogWarning(_("Failed to find XBM resource %s.\n"
2179 "Forgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2180 return wxNullBitmap
;
2182 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2184 wxLogWarning(_("No XBM facility available!"));
2188 case wxBITMAP_TYPE_XPM_DATA
:
2190 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2191 wxItemResource
*item
= table
->FindResource(name
);
2194 wxLogWarning(_("Failed to find XPM resource %s.\n"
2195 "Forgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2196 return wxNullBitmap
;
2198 return wxBitmap((char **)item
->GetValue1());
2200 wxLogWarning(_("No XPM facility available!"));
2206 return wxBitmap(name
, bitmapType
);
2210 return wxNullBitmap
;
2214 wxLogWarning(_("Bitmap resource specification %s not found."), (const wxChar
*) resource
);
2215 return wxNullBitmap
;
2220 * Load an icon from a wxWindows resource, choosing an optimum
2221 * depth and appropriate type.
2224 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2227 table
= wxDefaultResourceTable
;
2229 wxItemResource
*item
= table
->FindResource(resource
);
2232 if ((item
->GetType() == _T("")) || wxStrcmp(item
->GetType(), _T("wxIcon")) != 0)
2234 wxLogWarning(_("%s not an icon resource specification."), (const wxChar
*) resource
);
2237 int thisDepth
= wxDisplayDepth();
2238 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2240 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2242 // Try to find optimum icon for this platform/colour depth
2243 wxNode
*node
= item
->GetChildren().First();
2246 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2247 int platform
= (int)child
->GetValue2();
2248 int noColours
= (int)child
->GetValue3();
2250 char *name = child->GetName();
2251 int bitmapType = (int)child->GetValue1();
2252 int xRes = child->GetWidth();
2253 int yRes = child->GetHeight();
2258 case RESOURCE_PLATFORM_ANY
:
2260 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2261 optResource
= child
;
2264 // Maximise the number of colours.
2265 // If noColours is zero (unspecified), then assume this
2266 // is the right one.
2267 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2268 optResource
= child
;
2273 case RESOURCE_PLATFORM_WINDOWS
:
2275 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2276 optResource
= child
;
2279 // Maximise the number of colours
2280 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2281 optResource
= child
;
2287 case RESOURCE_PLATFORM_X
:
2289 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2290 optResource
= child
;
2293 // Maximise the number of colours
2294 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2295 optResource
= child
;
2301 case RESOURCE_PLATFORM_MAC
:
2303 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2304 optResource
= child
;
2307 // Maximise the number of colours
2308 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2309 optResource
= child
;
2317 node
= node
->Next();
2319 // If no matching resource, fail.
2323 wxString name
= optResource
->GetName();
2324 int bitmapType
= (int)optResource
->GetValue1();
2327 case wxBITMAP_TYPE_XBM_DATA
:
2330 wxItemResource
*item
= table
->FindResource(name
);
2333 wxLogWarning(_("Failed to find XBM resource %s.\n"
2334 "Forgot to use wxResourceLoadIconData?"), (const wxChar
*) name
);
2337 return wxIcon((const char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2339 wxLogWarning(_("No XBM facility available!"));
2343 case wxBITMAP_TYPE_XPM_DATA
:
2345 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2347 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2348 wxItemResource *item = table->FindResource(name);
2352 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2356 return wxIcon((char **)item->GetValue1());
2358 wxLogWarning(_("No XPM facility available!"));
2361 wxLogWarning(_("No XPM icon facility available!"));
2367 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2369 return wxIcon(name
, bitmapType
);
2378 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2383 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2385 wxMenu
*menu
= new wxMenu
;
2386 wxNode
*node
= item
->GetChildren().First();
2389 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2390 if ((child
->GetType() != _T("")) && (child
->GetType() == _T("wxMenuSeparator")))
2391 menu
->AppendSeparator();
2392 else if (child
->GetChildren().Number() > 0)
2394 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2396 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2400 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2402 node
= node
->Next();
2407 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2410 table
= wxDefaultResourceTable
;
2412 wxItemResource
*menuResource
= table
->FindResource(resource
);
2413 if (menuResource
&& (menuResource
->GetType() != _T("")) && (menuResource
->GetType() == _T("wxMenu")))
2416 menuBar
= new wxMenuBar
;
2417 wxNode
*node
= menuResource
->GetChildren().First();
2420 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2421 wxMenu
*menu
= wxResourceCreateMenu(child
);
2423 menuBar
->Append(menu
, child
->GetTitle());
2424 node
= node
->Next();
2428 return (wxMenuBar
*) NULL
;
2431 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2434 table
= wxDefaultResourceTable
;
2436 wxItemResource
*menuResource
= table
->FindResource(resource
);
2437 if (menuResource
&& (menuResource
->GetType() != _T("")) && (menuResource
->GetType() == _T("wxMenu")))
2438 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2439 return wxResourceCreateMenu(menuResource
);
2440 return (wxMenu
*) NULL
;
2443 // Global equivalents (so don't have to refer to default table explicitly)
2444 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2447 table
= wxDefaultResourceTable
;
2449 return table
->ParseResourceData(resource
);
2452 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2455 table
= wxDefaultResourceTable
;
2457 return table
->ParseResourceFile(filename
);
2460 // Register XBM/XPM data
2461 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2464 table
= wxDefaultResourceTable
;
2466 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2469 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2472 table
= wxDefaultResourceTable
;
2474 return table
->RegisterResourceBitmapData(name
, data
);
2477 void wxResourceClear(wxResourceTable
*table
)
2480 table
= wxDefaultResourceTable
;
2482 table
->ClearTable();
2489 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2492 table
= wxDefaultResourceTable
;
2494 table
->identifiers
.Put(name
, (wxObject
*)value
);
2498 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2501 table
= wxDefaultResourceTable
;
2503 return (int)table
->identifiers
.Get(name
);
2507 * Parse #include file for #defines (only)
2510 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2513 table
= wxDefaultResourceTable
;
2515 FILE *fd
= fopen(f
.fn_str(), "r");
2520 while (wxGetResourceToken(fd
))
2522 if (strcmp(wxResourceBuffer
, "#define") == 0)
2524 wxGetResourceToken(fd
);
2525 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2526 wxGetResourceToken(fd
);
2527 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2528 if (wxIsdigit(value
[0]))
2530 int val
= (int)wxAtol(value
);
2531 wxResourceAddIdentifier(name
, val
, table
);
2542 * Reading strings as if they were .wxr files
2545 static int getc_string(char *s
)
2547 int ch
= s
[wxResourceStringPtr
];
2552 wxResourceStringPtr
++;
2557 static int ungetc_string()
2559 wxResourceStringPtr
--;
2563 bool wxEatWhiteSpaceString(char *s
)
2567 while ((ch
= getc_string(s
)) != EOF
)
2579 ch
= getc_string(s
);
2590 while ((ch
= getc_string(s
)) != EOF
)
2592 if (ch
== '/' && prev_ch
== '*')
2614 bool wxGetResourceTokenString(char *s
)
2616 if (!wxResourceBuffer
)
2617 wxReallocateResourceBuffer();
2618 wxResourceBuffer
[0] = 0;
2619 wxEatWhiteSpaceString(s
);
2621 int ch
= getc_string(s
);
2625 wxResourceBufferCount
= 0;
2626 ch
= getc_string(s
);
2632 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2635 // Escaped characters
2636 else if (ch
== '\\')
2638 int newCh
= getc_string(s
);
2641 else if (newCh
== 10)
2649 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2650 wxReallocateResourceBuffer();
2651 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2652 wxResourceBufferCount
++;
2653 ch
= getc_string(s
);
2655 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2659 wxResourceBufferCount
= 0;
2661 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2663 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2664 wxReallocateResourceBuffer();
2665 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2666 wxResourceBufferCount
++;
2668 ch
= getc_string(s
);
2670 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2678 * Files are in form:
2679 static char *name = "....";
2680 with possible comments.
2683 bool wxResourceReadOneResourceString(char *s
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2686 table
= wxDefaultResourceTable
;
2688 // static or #define
2689 if (!wxGetResourceTokenString(s
))
2695 if (strcmp(wxResourceBuffer
, "#define") == 0)
2697 wxGetResourceTokenString(s
);
2698 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2699 wxGetResourceTokenString(s
);
2700 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2701 if (wxIsalpha(value
[0]))
2703 int val
= (int)wxAtol(value
);
2704 wxResourceAddIdentifier(name
, val
, table
);
2708 wxLogWarning(_("#define %s must be an integer."), name
);
2719 else if (strcmp(wxResourceBuffer, "#include") == 0)
2721 wxGetResourceTokenString(s);
2722 char *name = copystring(wxResourceBuffer);
2723 char *actualName = name;
2725 actualName = name + 1;
2726 int len = strlen(name);
2727 if ((len > 0) && (name[len-1] == '"'))
2729 if (!wxResourceParseIncludeFile(actualName, table))
2732 sprintf(buf, _("Could not find resource include file %s."), actualName);
2739 else if (strcmp(wxResourceBuffer
, "static") != 0)
2742 wxStrcpy(buf
, _("Found "));
2743 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
2744 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
2750 if (!wxGetResourceTokenString(s
))
2752 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2757 if (strcmp(wxResourceBuffer
, "char") != 0)
2759 wxLogWarning(_("Expected 'char' whilst parsing resource."));
2764 if (!wxGetResourceTokenString(s
))
2766 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2771 if (wxResourceBuffer
[0] != '*')
2773 wxLogWarning(_("Expected '*' whilst parsing resource."));
2776 wxChar nameBuf
[100];
2777 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
2781 if (!wxGetResourceTokenString(s
))
2783 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2788 if (strcmp(wxResourceBuffer
, "=") != 0)
2790 wxLogWarning(_("Expected '=' whilst parsing resource."));
2795 if (!wxGetResourceTokenString(s
))
2797 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2803 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2805 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2810 if (!wxGetResourceTokenString(s
))
2817 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
2820 table
= wxDefaultResourceTable
;
2825 // Turn backslashes into spaces
2828 int len
= strlen(s
);
2830 for (i
= 0; i
< len
; i
++)
2831 if (s
[i
] == 92 && s
[i
+1] == 13)
2839 wxResourceStringPtr
= 0;
2842 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
2846 return wxResourceInterpretResources(*table
, db
);
2850 * resource loading facility
2853 bool wxWindowBase::LoadFromResource(wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
2856 table
= wxDefaultResourceTable
;
2858 wxItemResource
*resource
= table
->FindResource((const wxChar
*)resourceName
);
2859 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
2860 if (!resource
|| (resource
->GetType() == _T("")) ||
2861 ! ((resource
->GetType() == _T("wxDialog")) || (resource
->GetType() == _T("wxPanel"))))
2864 wxString
title(resource
->GetTitle());
2865 long theWindowStyle
= resource
->GetStyle();
2866 bool isModal
= (resource
->GetValue1() != 0);
2867 int x
= resource
->GetX();
2868 int y
= resource
->GetY();
2869 int width
= resource
->GetWidth();
2870 int height
= resource
->GetHeight();
2871 wxString name
= resource
->GetName();
2873 if (IsKindOf(CLASSINFO(wxDialog
)))
2875 wxDialog
*dialogBox
= (wxDialog
*)this;
2876 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
2877 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
2880 // Only reset the client size if we know we're not going to do it again below.
2881 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == 0)
2882 dialogBox
->SetClientSize(width
, height
);
2884 else if (IsKindOf(CLASSINFO(wxPanel
)))
2886 wxPanel
* panel
= (wxPanel
*)this;
2887 if (!panel
->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2892 if (!((wxWindow
*)this)->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2896 if ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
2898 // No need to do this since it's done in wxPanel or wxDialog constructor.
2899 // SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
2903 if (resource
->GetFont().Ok())
2904 SetFont(resource
->GetFont());
2905 if (resource
->GetBackgroundColour().Ok())
2906 SetBackgroundColour(resource
->GetBackgroundColour());
2909 // Should have some kind of font at this point
2910 if (!GetFont().Ok())
2911 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
2912 if (!GetBackgroundColour().Ok())
2913 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
2915 // Only when we've created the window and set the font can we set the correct size,
2916 // if based on dialog units.
2917 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
2919 wxSize sz
= ConvertDialogToPixels(wxSize(width
, height
));
2920 SetClientSize(sz
.x
, sz
.y
);
2922 wxPoint pt
= ConvertDialogToPixels(wxPoint(x
, y
));
2926 // Now create children
2927 wxNode
*node
= resource
->GetChildren().First();
2930 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
2932 (void) CreateItem(childResource
, resource
, table
);
2934 node
= node
->Next();
2939 wxControl
*wxWindowBase::CreateItem(const wxItemResource
*resource
, const wxItemResource
* parentResource
, const wxResourceTable
*table
)
2942 table
= wxDefaultResourceTable
;
2943 return table
->CreateItem((wxWindow
*)this, resource
, parentResource
);
2947 #pragma warning(default:4706) // assignment within conditional expression
2953 #endif // wxUSE_WX_RESOURCES