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"
47 #include "wx/statbox.h"
51 #include "wx/textctrl.h"
52 #include "wx/msgdlg.h"
57 #include "wx/scrolbar.h"
61 #include "wx/combobox.h"
64 #include "wx/validate.h"
73 #include "wx/resource.h"
74 #include "wx/string.h"
75 #include "wx/wxexpr.h"
77 #include "wx/settings.h"
79 // Forward (private) declarations
80 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
);
81 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
= FALSE
);
82 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
);
83 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
);
84 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
);
85 wxItemResource
*wxResourceInterpretString(wxResourceTable
& table
, wxExpr
*expr
);
86 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& table
, wxExpr
*expr
);
87 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
);
88 // Interpret list expression
89 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
);
91 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
92 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
94 wxResourceTable
*wxDefaultResourceTable
= (wxResourceTable
*) NULL
;
96 static char *wxResourceBuffer
= (char *) NULL
;
97 static long wxResourceBufferSize
= 0;
98 static long wxResourceBufferCount
= 0;
99 static int wxResourceStringPtr
= 0;
101 void wxInitializeResourceSystem()
103 wxDefaultResourceTable
= new wxResourceTable
;
106 void wxCleanUpResourceSystem()
108 delete wxDefaultResourceTable
;
109 if (wxResourceBuffer
)
110 delete[] wxResourceBuffer
;
113 void wxLogWarning(char *msg
)
115 wxMessageBox(msg
, _("Warning"), wxOK
);
118 #if !USE_SHARED_LIBRARY
119 IMPLEMENT_DYNAMIC_CLASS(wxItemResource
, wxObject
)
120 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable
, wxHashTable
)
123 wxItemResource::wxItemResource()
129 m_x
= m_y
= m_width
= m_height
= 0;
130 m_value1
= m_value2
= m_value3
= m_value5
= 0;
136 wxItemResource::~wxItemResource()
138 wxNode
*node
= m_children
.First();
141 wxItemResource
*item
= (wxItemResource
*)node
->Data();
144 node
= m_children
.First();
152 wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
)
156 wxResourceTable::~wxResourceTable()
161 wxItemResource
*wxResourceTable::FindResource(const wxString
& name
) const
163 wxItemResource
*item
= (wxItemResource
*)Get((char *)(const char *)name
);
167 void wxResourceTable::AddResource(wxItemResource
*item
)
169 wxString name
= item
->GetName();
171 name
= item
->GetTitle();
175 // Delete existing resource, if any.
181 bool wxResourceTable::DeleteResource(const wxString
& name
)
183 wxItemResource
*item
= (wxItemResource
*)Delete((char *)(const char *)name
);
186 // See if any resource has this as its child; if so, delete from
187 // parent's child list.
189 wxNode
*node
= (wxNode
*) NULL
;
190 while ((node
= Next()))
192 wxItemResource
*parent
= (wxItemResource
*)node
->Data();
193 if (parent
->GetChildren().Member(item
))
195 parent
->GetChildren().DeleteObject(item
);
207 bool wxResourceTable::ParseResourceFile(const wxString
& filename
)
211 FILE *fd
= fopen((const char*) filename
, "r");
215 while (wxResourceReadOneResource(fd
, db
, &eof
, this) && !eof
)
220 return wxResourceInterpretResources(*this, db
);
223 bool wxResourceTable::ParseResourceData(const wxString
& data
)
226 if (!db
.ReadFromString(data
))
228 wxLogWarning(_("Ill-formed resource file syntax."));
232 return wxResourceInterpretResources(*this, db
);
235 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char bits
[], int width
, int height
)
237 // Register pre-loaded bitmap data
238 wxItemResource
*item
= new wxItemResource
;
239 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
240 item
->SetType("wxXBMData");
242 item
->SetValue1((long)bits
);
243 item
->SetValue2((long)width
);
244 item
->SetValue3((long)height
);
249 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char **data
)
251 // Register pre-loaded bitmap data
252 wxItemResource
*item
= new wxItemResource
;
253 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
254 item
->SetType("wxXPMData");
256 item
->SetValue1((long)data
);
261 bool wxResourceTable::SaveResource(const wxString
& WXUNUSED(filename
))
266 void wxResourceTable::ClearTable()
269 wxNode
*node
= Next();
272 wxNode
*next
= Next();
273 wxItemResource
*item
= (wxItemResource
*)node
->Data();
280 wxControl
*wxResourceTable::CreateItem(wxWindow
*parent
, const wxItemResource
* childResource
, const wxItemResource
* parentResource
) const
282 int id
= childResource
->GetId();
286 bool dlgUnits
= ((parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0);
288 wxControl
*control
= (wxControl
*) NULL
;
289 wxString
itemType(childResource
->GetType());
295 pos
= parent
->ConvertDialogToPixels(wxPoint(childResource
->GetX(), childResource
->GetY()));
296 size
= parent
->ConvertDialogToPixels(wxSize(childResource
->GetWidth(), childResource
->GetHeight()));
300 pos
= wxPoint(childResource
->GetX(), childResource
->GetY());
301 size
= wxSize(childResource
->GetWidth(), childResource
->GetHeight());
304 if (itemType
== wxString("wxButton") || itemType
== wxString("wxBitmapButton"))
306 if (childResource
->GetValue4() != "")
309 wxBitmap bitmap
= childResource
->GetBitmap();
312 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
313 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
316 control
= new wxBitmapButton(parent
, id
, bitmap
, pos
, size
,
317 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
320 // Normal, text button
321 control
= new wxButton(parent
, id
, childResource
->GetTitle(), pos
, size
,
322 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
324 else if (itemType
== wxString("wxMessage") || itemType
== wxString("wxStaticText") ||
325 itemType
== wxString("wxStaticBitmap"))
327 if (childResource
->GetValue4() != "")
330 wxBitmap bitmap
= childResource
->GetBitmap();
333 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
334 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
336 #if wxUSE_BITMAP_MESSAGE
338 control
= new wxStaticBitmap(parent
, id
, bitmap
, pos
, size
,
339 childResource
->GetStyle(), childResource
->GetName());
344 control
= new wxStaticText(parent
, id
, childResource
->GetTitle(), pos
, size
,
345 childResource
->GetStyle(), childResource
->GetName());
348 else if (itemType
== wxString("wxText") || itemType
== wxString("wxTextCtrl") || itemType
== wxString("wxMultiText"))
350 control
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(), pos
, size
,
351 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
353 else if (itemType
== wxString("wxCheckBox"))
355 control
= new wxCheckBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
356 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
358 ((wxCheckBox
*)control
)->SetValue((childResource
->GetValue1() != 0));
361 else if (itemType
== wxString("wxGauge"))
363 control
= new wxGauge(parent
, id
, (int)childResource
->GetValue2(), pos
, size
,
364 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
366 ((wxGauge
*)control
)->SetValue((int)childResource
->GetValue1());
369 #if wxUSE_RADIOBUTTON
370 else if (itemType
== wxString("wxRadioButton"))
372 control
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(),
374 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
378 else if (itemType
== wxString("wxScrollBar"))
380 control
= new wxScrollBar(parent
, id
, pos
, size
,
381 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
383 ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1());
384 ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2());
385 ((wxScrollBar *)control)->SetObjectLength((int)childResource->GetValue3());
386 ((wxScrollBar *)control)->SetViewLength((int)(long)childResource->GetValue5());
388 ((wxScrollBar
*)control
)->SetScrollbar((int)childResource
->GetValue1(),(int)childResource
->GetValue2(),
389 (int)childResource
->GetValue3(),(int)(long)childResource
->GetValue5(),FALSE
);
393 else if (itemType
== wxString("wxSlider"))
395 control
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(),
396 (int)childResource
->GetValue2(), (int)childResource
->GetValue3(), pos
, size
,
397 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
399 else if (itemType
== wxString("wxGroupBox") || itemType
== wxString("wxStaticBox"))
401 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
402 childResource
->GetStyle(), childResource
->GetName());
404 else if (itemType
== wxString("wxListBox"))
406 wxStringList
& stringList
= childResource
->GetStringValues();
407 wxString
*strings
= (wxString
*) NULL
;
409 if (stringList
.Number() > 0)
411 noStrings
= stringList
.Number();
412 strings
= new wxString
[noStrings
];
413 wxNode
*node
= stringList
.First();
417 strings
[i
] = (char *)node
->Data();
422 control
= new wxListBox(parent
, id
, pos
, size
,
423 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
428 else if (itemType
== wxString("wxChoice"))
430 wxStringList
& stringList
= childResource
->GetStringValues();
431 wxString
*strings
= (wxString
*) NULL
;
433 if (stringList
.Number() > 0)
435 noStrings
= stringList
.Number();
436 strings
= new wxString
[noStrings
];
437 wxNode
*node
= stringList
.First();
441 strings
[i
] = (char *)node
->Data();
446 control
= new wxChoice(parent
, id
, pos
, size
,
447 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
453 else if (itemType
== wxString("wxComboBox"))
455 wxStringList
& stringList
= childResource
->GetStringValues();
456 wxString
*strings
= (wxString
*) NULL
;
458 if (stringList
.Number() > 0)
460 noStrings
= stringList
.Number();
461 strings
= new wxString
[noStrings
];
462 wxNode
*node
= stringList
.First();
466 strings
[i
] = (char *)node
->Data();
471 control
= new wxComboBox(parent
, id
, childResource
->GetValue4(), pos
, size
,
472 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
478 else if (itemType
== wxString("wxRadioBox"))
480 wxStringList
& stringList
= childResource
->GetStringValues();
481 wxString
*strings
= (wxString
*) NULL
;
483 if (stringList
.Number() > 0)
485 noStrings
= stringList
.Number();
486 strings
= new wxString
[noStrings
];
487 wxNode
*node
= stringList
.First();
491 strings
[i
] = (char *)node
->Data();
496 control
= new wxRadioBox(parent
, (wxWindowID
) id
, wxString(childResource
->GetTitle()), pos
, size
,
497 noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
,
498 childResource
->GetName());
504 if ((parentResource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
506 // Don't set font; will be inherited from parent.
510 if (control
&& childResource
->GetFont().Ok())
511 control
->SetFont(childResource
->GetFont());
517 * Interpret database as a series of resources
520 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
)
522 wxNode
*node
= db
.First();
525 wxExpr
*clause
= (wxExpr
*)node
->Data();
526 wxString
functor(clause
->Functor());
528 wxItemResource
*item
= (wxItemResource
*) NULL
;
529 if (functor
== "dialog")
530 item
= wxResourceInterpretDialog(table
, clause
);
531 else if (functor
== "panel")
532 item
= wxResourceInterpretDialog(table
, clause
, TRUE
);
533 else if (functor
== "menubar")
534 item
= wxResourceInterpretMenuBar(table
, clause
);
535 else if (functor
== "menu")
536 item
= wxResourceInterpretMenu(table
, clause
);
537 else if (functor
== "string")
538 item
= wxResourceInterpretString(table
, clause
);
539 else if (functor
== "bitmap")
540 item
= wxResourceInterpretBitmap(table
, clause
);
541 else if (functor
== "icon")
542 item
= wxResourceInterpretIcon(table
, clause
);
546 // Remove any existing resource of same name
547 if (item
->GetName() != "")
548 table
.DeleteResource(item
->GetName());
549 table
.AddResource(item
);
556 static char *g_ValidControlClasses
[] = { "wxButton", "wxBitmapButton", "wxMessage",
557 "wxStaticText", "wxStaticBitmap", "wxText", "wxTextCtrl", "wxMultiText",
558 "wxListBox", "wxRadioBox", "wxRadioButton", "wxCheckBox", "wxBitmapCheckBox",
559 "wxGroupBox", "wxStaticBox", "wxSlider", "wxGauge", "wxScrollBar",
560 "wxChoice", "wxComboBox" } ;
561 static int g_ValidControlClassesCount
= sizeof(g_ValidControlClasses
) / sizeof(char *) ;
563 static bool wxIsValidControlClass(const wxString
& c
)
566 for ( i
= 0; i
< g_ValidControlClassesCount
; i
++)
568 if ( c
== g_ValidControlClasses
[i
] )
574 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
)
576 wxItemResource
*dialogItem
= new wxItemResource
;
578 dialogItem
->SetType("wxPanel");
580 dialogItem
->SetType("wxDialog");
584 wxString backColourHex
= "";
585 wxString labelColourHex
= "";
586 wxString buttonColourHex
= "";
588 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
592 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
594 wxExpr
*labelFontExpr
= (wxExpr
*) NULL
;
595 wxExpr
*buttonFontExpr
= (wxExpr
*) NULL
;
596 wxExpr
*fontExpr
= (wxExpr
*) NULL
;
597 expr
->GetAttributeValue("style", style
);
598 expr
->GetAttributeValue("name", name
);
599 expr
->GetAttributeValue("title", title
);
600 expr
->GetAttributeValue("x", x
);
601 expr
->GetAttributeValue("y", y
);
602 expr
->GetAttributeValue("width", width
);
603 expr
->GetAttributeValue("height", height
);
604 expr
->GetAttributeValue("modal", isModal
);
605 expr
->GetAttributeValue("label_font", &labelFontExpr
);
606 expr
->GetAttributeValue("button_font", &buttonFontExpr
);
607 expr
->GetAttributeValue("font", &fontExpr
);
608 expr
->GetAttributeValue("background_colour", backColourHex
);
609 expr
->GetAttributeValue("label_colour", labelColourHex
);
610 expr
->GetAttributeValue("button_colour", buttonColourHex
);
612 int useDialogUnits
= 0;
613 expr
->GetAttributeValue("use_dialog_units", useDialogUnits
);
614 if (useDialogUnits
!= 0)
615 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS
);
618 expr
->GetAttributeValue("use_system_defaults", useDefaults
);
619 if (useDefaults
!= 0)
620 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS
);
623 expr
->GetAttributeValue("id", id
);
624 dialogItem
->SetId(id
);
628 windowStyle
= wxParseWindowStyle(style
);
630 dialogItem
->SetStyle(windowStyle
);
631 dialogItem
->SetValue1(isModal
);
632 dialogItem
->SetName(name
);
633 dialogItem
->SetTitle(title
);
634 dialogItem
->SetSize(x
, y
, width
, height
);
636 if (backColourHex
!= "")
641 r
= wxHexToDec(backColourHex
.Mid(0, 2));
642 g
= wxHexToDec(backColourHex
.Mid(2, 2));
643 b
= wxHexToDec(backColourHex
.Mid(4, 2));
644 dialogItem
->SetBackgroundColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
646 if (labelColourHex
!= "")
651 r
= wxHexToDec(labelColourHex
.Mid(0, 2));
652 g
= wxHexToDec(labelColourHex
.Mid(2, 2));
653 b
= wxHexToDec(labelColourHex
.Mid(4, 2));
654 dialogItem
->SetLabelColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
656 if (buttonColourHex
!= "")
661 r
= wxHexToDec(buttonColourHex
.Mid(0, 2));
662 g
= wxHexToDec(buttonColourHex
.Mid(2, 2));
663 b
= wxHexToDec(buttonColourHex
.Mid(4, 2));
664 dialogItem
->SetButtonColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
668 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
669 else if (buttonFontExpr
)
670 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
671 else if (labelFontExpr
)
672 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
674 // Now parse all controls
675 wxExpr
*controlExpr
= expr
->GetFirst();
678 if (controlExpr
->Number() == 3)
680 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
681 if (controlKeyword
!= "" && controlKeyword
== "control")
683 // The value part: always a list.
684 wxExpr
*listExpr
= controlExpr
->Nth(2);
685 if (listExpr
->Type() == PrologList
)
687 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
690 dialogItem
->GetChildren().Append(controlItem
);
695 controlExpr
= controlExpr
->GetNext();
700 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
)
702 wxItemResource
*controlItem
= new wxItemResource
;
704 // First, find the standard features of a control definition:
705 // [optional integer/string id], control name, title, style, name, x, y, width, height
707 wxString controlType
;
712 long windowStyle
= 0;
713 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
716 wxExpr
*expr1
= expr
->Nth(0);
718 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
720 if ( wxIsValidControlClass(expr1
->StringValue()) )
723 controlType
= expr1
->StringValue();
727 wxString
str(expr1
->StringValue());
728 id
= wxResourceGetIdentifier(str
, &table
);
731 wxLogWarning(_("Could not resolve control class or id '%s'. "
732 "Use (non-zero) integer instead\n or provide #define "
733 "(see manual for caveats)"),
734 (const char*) expr1
->StringValue());
736 return (wxItemResource
*) NULL
;
740 // Success - we have an id, so the 2nd element must be the control class.
741 controlType
= expr
->Nth(1)->StringValue();
746 else if (expr1
->Type() == PrologInteger
)
748 id
= (int)expr1
->IntegerValue();
749 // Success - we have an id, so the 2nd element must be the control class.
750 controlType
= expr
->Nth(1)->StringValue();
754 expr1
= expr
->Nth(count
);
757 title
= expr1
->StringValue();
759 expr1
= expr
->Nth(count
);
763 style
= expr1
->StringValue();
764 windowStyle
= wxParseWindowStyle(style
);
767 expr1
= expr
->Nth(count
);
770 name
= expr1
->StringValue();
772 expr1
= expr
->Nth(count
);
775 x
= (int)expr1
->IntegerValue();
777 expr1
= expr
->Nth(count
);
780 y
= (int)expr1
->IntegerValue();
782 expr1
= expr
->Nth(count
);
785 width
= (int)expr1
->IntegerValue();
787 expr1
= expr
->Nth(count
);
790 height
= (int)expr1
->IntegerValue();
792 controlItem
->SetStyle(windowStyle
);
793 controlItem
->SetName(name
);
794 controlItem
->SetTitle(title
);
795 controlItem
->SetSize(x
, y
, width
, height
);
796 controlItem
->SetType(controlType
);
797 controlItem
->SetId(id
);
799 if (controlType
== "wxButton")
801 // Check for bitmap resource name (in case loading old-style resource file)
802 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
804 wxString
str(expr
->Nth(count
)->StringValue());
805 controlItem
->SetValue4(str
);
807 controlItem
->SetType("wxBitmapButton");
809 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
810 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
812 else if (controlType
== "wxBitmapButton")
814 // Check for bitmap resource name
815 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
817 wxString
str(expr
->Nth(count
)->StringValue());
818 controlItem
->SetValue4(str
);
820 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
821 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
824 else if (controlType
== "wxCheckBox")
826 // Check for default value
827 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
829 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
831 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
832 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
835 #if wxUSE_RADIOBUTTON
836 else if (controlType
== "wxRadioButton")
838 // Check for default value
839 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
841 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
843 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
844 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
848 else if (controlType
== "wxText" || controlType
== "wxTextCtrl" || controlType
== "wxMultiText")
850 // Check for default value
851 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
853 wxString
str(expr
->Nth(count
)->StringValue());
854 controlItem
->SetValue4(str
);
857 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
859 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
860 // Do nothing - no label font any more
862 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
863 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
867 else if (controlType
== "wxMessage" || controlType
== "wxStaticText")
869 // Check for bitmap resource name (in case it's an old-style .wxr file)
870 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
872 wxString
str(expr
->Nth(count
)->StringValue());
873 controlItem
->SetValue4(str
);
875 controlItem
->SetType("wxStaticText");
877 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
878 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
880 else if (controlType
== "wxStaticBitmap")
882 // Check for bitmap resource name
883 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
885 wxString
str(expr
->Nth(count
)->StringValue());
886 controlItem
->SetValue4(str
);
889 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
890 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
892 else if (controlType
== "wxGroupBox" || controlType
== "wxStaticBox")
894 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
895 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
897 else if (controlType
== "wxGauge")
899 // Check for default value
900 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
902 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
906 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
908 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
911 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
913 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
917 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
918 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
923 else if (controlType
== "wxSlider")
925 // Check for default value
926 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
928 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
932 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
934 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
938 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
940 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
943 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
945 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
949 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
950 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
956 else if (controlType
== "wxScrollBar")
959 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
961 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
965 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
967 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
971 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
973 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
977 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
978 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
983 else if (controlType
== "wxListBox")
985 wxExpr
*valueList
= (wxExpr
*) NULL
;
987 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
989 wxStringList stringList
;
990 wxExpr
*stringExpr
= valueList
->GetFirst();
993 stringList
.Add(stringExpr
->StringValue());
994 stringExpr
= stringExpr
->GetNext();
996 controlItem
->SetStringValues(stringList
);
998 // This is now obsolete: it's in the window style.
999 // Check for wxSINGLE/wxMULTIPLE
1000 wxExpr
*mult
= (wxExpr
*) NULL
;
1002 controlItem->SetValue1(wxLB_SINGLE);
1004 if ((mult
= expr
->Nth(count
)) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1007 wxString m(mult->StringValue());
1008 if (m == "wxLB_MULTIPLE")
1009 controlItem->SetValue1(wxLB_MULTIPLE);
1010 else if (m == "wxLB_EXTENDED")
1011 controlItem->SetValue1(wxLB_EXTENDED);
1016 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1018 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1020 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1021 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1025 else if (controlType
== "wxChoice")
1027 wxExpr
*valueList
= (wxExpr
*) NULL
;
1028 // Check for default value list
1029 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1031 wxStringList stringList
;
1032 wxExpr
*stringExpr
= valueList
->GetFirst();
1035 stringList
.Add(stringExpr
->StringValue());
1036 stringExpr
= stringExpr
->GetNext();
1038 controlItem
->SetStringValues(stringList
);
1042 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1044 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1047 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1048 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1053 else if (controlType
== "wxComboBox")
1055 wxExpr
*textValue
= expr
->Nth(count
);
1056 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1058 wxString
str(textValue
->StringValue());
1059 controlItem
->SetValue4(str
);
1063 wxExpr
*valueList
= (wxExpr
*) NULL
;
1064 // Check for default value list
1065 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1067 wxStringList stringList
;
1068 wxExpr
*stringExpr
= valueList
->GetFirst();
1071 stringList
.Add(stringExpr
->StringValue());
1072 stringExpr
= stringExpr
->GetNext();
1074 controlItem
->SetStringValues(stringList
);
1078 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1080 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1083 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1084 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1091 else if (controlType
== "wxRadioBox")
1093 wxExpr
*valueList
= (wxExpr
*) NULL
;
1094 // Check for default value list
1095 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1097 wxStringList stringList
;
1098 wxExpr
*stringExpr
= valueList
->GetFirst();
1101 stringList
.Add(stringExpr
->StringValue());
1102 stringExpr
= stringExpr
->GetNext();
1104 controlItem
->SetStringValues(stringList
);
1107 // majorDim (number of rows or cols)
1108 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1110 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1114 controlItem
->SetValue1(0);
1116 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1118 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1121 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1122 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1130 return (wxItemResource
*) NULL
;
1135 // Forward declaration
1136 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, wxExpr
*expr
);
1139 * Interpet a menu item
1142 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, wxExpr
*expr
)
1144 wxItemResource
*item
= new wxItemResource
;
1146 wxExpr
*labelExpr
= expr
->Nth(0);
1147 wxExpr
*idExpr
= expr
->Nth(1);
1148 wxExpr
*helpExpr
= expr
->Nth(2);
1149 wxExpr
*checkableExpr
= expr
->Nth(3);
1151 // Further keywords/attributes to follow sometime...
1152 if (expr
->Number() == 0)
1154 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1155 item
->SetType("wxMenuSeparator");
1160 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1161 item
->SetType("wxMenu"); // Well, menu item, but doesn't matter.
1164 wxString
str(labelExpr
->StringValue());
1165 item
->SetTitle(str
);
1170 // If a string or word, must look up in identifier table.
1171 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1173 wxString
str(idExpr
->StringValue());
1174 id
= wxResourceGetIdentifier(str
, &table
);
1177 wxLogWarning(_("Could not resolve menu id '%s'. "
1178 "Use (non-zero) integer instead\n"
1179 "or provide #define (see manual for caveats)"),
1180 (const char*) idExpr
->StringValue());
1183 else if (idExpr
->Type() == PrologInteger
)
1184 id
= (int)idExpr
->IntegerValue();
1185 item
->SetValue1(id
);
1189 wxString
str(helpExpr
->StringValue());
1190 item
->SetValue4(str
);
1193 item
->SetValue2(checkableExpr
->IntegerValue());
1195 // Find the first expression that's a list, for submenu
1196 wxExpr
*subMenuExpr
= expr
->GetFirst();
1197 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1198 subMenuExpr
= subMenuExpr
->GetNext();
1202 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1203 item
->GetChildren().Append(child
);
1204 subMenuExpr
= subMenuExpr
->GetNext();
1211 * Interpret a nested list as a menu
1214 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1216 wxItemResource *menu = new wxItemResource;
1217 // menu->SetType(wxTYPE_MENU);
1218 menu->SetType("wxMenu");
1219 wxExpr *element = expr->GetFirst();
1222 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1224 menu->GetChildren().Append(item);
1225 element = element->GetNext();
1231 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
)
1233 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1234 expr
->GetAttributeValue("menu", &listExpr
);
1236 return (wxItemResource
*) NULL
;
1238 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1241 return (wxItemResource
*) NULL
;
1244 if (expr
->GetAttributeValue("name", name
))
1246 menuResource
->SetName(name
);
1249 return menuResource
;
1252 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
)
1254 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1255 expr
->GetAttributeValue("menu", &listExpr
);
1257 return (wxItemResource
*) NULL
;
1259 wxItemResource
*resource
= new wxItemResource
;
1260 resource
->SetType("wxMenu");
1261 // resource->SetType(wxTYPE_MENU);
1263 wxExpr
*element
= listExpr
->GetFirst();
1266 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1267 resource
->GetChildren().Append(menuResource
);
1268 element
= element
->GetNext();
1272 if (expr
->GetAttributeValue("name", name
))
1274 resource
->SetName(name
);
1280 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), wxExpr
*WXUNUSED(expr
))
1282 return (wxItemResource
*) NULL
;
1285 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), wxExpr
*expr
)
1287 wxItemResource
*bitmapItem
= new wxItemResource
;
1288 // bitmapItem->SetType(wxTYPE_BITMAP);
1289 bitmapItem
->SetType("wxBitmap");
1291 if (expr
->GetAttributeValue("name", name
))
1293 bitmapItem
->SetName(name
);
1295 // Now parse all bitmap specifications
1296 wxExpr
*bitmapExpr
= expr
->GetFirst();
1299 if (bitmapExpr
->Number() == 3)
1301 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1302 if (bitmapKeyword
== "bitmap" || bitmapKeyword
== "icon")
1304 // The value part: always a list.
1305 wxExpr
*listExpr
= bitmapExpr
->Nth(2);
1306 if (listExpr
->Type() == PrologList
)
1308 wxItemResource
*bitmapSpec
= new wxItemResource
;
1309 // bitmapSpec->SetType(wxTYPE_BITMAP);
1310 bitmapSpec
->SetType("wxBitmap");
1312 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1313 // where everything after 'filename' is optional.
1314 wxExpr
*nameExpr
= listExpr
->Nth(0);
1315 wxExpr
*typeExpr
= listExpr
->Nth(1);
1316 wxExpr
*platformExpr
= listExpr
->Nth(2);
1317 wxExpr
*coloursExpr
= listExpr
->Nth(3);
1318 wxExpr
*xresExpr
= listExpr
->Nth(4);
1319 wxExpr
*yresExpr
= listExpr
->Nth(5);
1320 if (nameExpr
&& nameExpr
->StringValue())
1322 bitmapSpec
->SetName(nameExpr
->StringValue());
1324 if (typeExpr
&& typeExpr
->StringValue())
1326 bitmapSpec
->SetValue1(wxParseWindowStyle(typeExpr
->StringValue()));
1329 bitmapSpec
->SetValue1(0);
1331 if (platformExpr
&& platformExpr
->StringValue())
1333 wxString
plat(platformExpr
->StringValue());
1334 if (plat
== "windows" || plat
== "WINDOWS")
1335 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1336 else if (plat
== "x" || plat
== "X")
1337 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1338 else if (plat
== "mac" || plat
== "MAC")
1339 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1341 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1344 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1347 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1351 xres
= (int)xresExpr
->IntegerValue();
1353 yres
= (int)yresExpr
->IntegerValue();
1354 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1356 bitmapItem
->GetChildren().Append(bitmapSpec
);
1360 bitmapExpr
= bitmapExpr
->GetNext();
1366 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
)
1368 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1371 // item->SetType(wxTYPE_ICON);
1372 item
->SetType("wxIcon");
1376 return (wxItemResource
*) NULL
;
1379 // Interpret list expression as a font
1380 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
)
1382 if (expr
->Type() != PrologList
)
1386 int family
= wxSWISS
;
1387 int style
= wxNORMAL
;
1388 int weight
= wxNORMAL
;
1390 wxString
faceName("");
1392 wxExpr
*pointExpr
= expr
->Nth(0);
1393 wxExpr
*familyExpr
= expr
->Nth(1);
1394 wxExpr
*styleExpr
= expr
->Nth(2);
1395 wxExpr
*weightExpr
= expr
->Nth(3);
1396 wxExpr
*underlineExpr
= expr
->Nth(4);
1397 wxExpr
*faceNameExpr
= expr
->Nth(5);
1399 point
= (int)pointExpr
->IntegerValue();
1404 str
= familyExpr
->StringValue();
1405 family
= (int)wxParseWindowStyle(str
);
1409 str
= styleExpr
->StringValue();
1410 style
= (int)wxParseWindowStyle(str
);
1414 str
= weightExpr
->StringValue();
1415 weight
= (int)wxParseWindowStyle(str
);
1418 underline
= (int)underlineExpr
->IntegerValue();
1420 faceName
= faceNameExpr
->StringValue();
1422 wxFont
font(point
, family
, style
, weight
, (underline
!= 0), faceName
);
1427 * (Re)allocate buffer for reading in from resource file
1430 bool wxReallocateResourceBuffer()
1432 if (!wxResourceBuffer
)
1434 wxResourceBufferSize
= 1000;
1435 wxResourceBuffer
= new char[wxResourceBufferSize
];
1438 if (wxResourceBuffer
)
1440 long newSize
= wxResourceBufferSize
+ 1000;
1441 char *tmp
= new char[(int)newSize
];
1442 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1443 delete[] wxResourceBuffer
;
1444 wxResourceBuffer
= tmp
;
1445 wxResourceBufferSize
= newSize
;
1450 static bool wxEatWhiteSpace(FILE *fd
)
1453 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
1460 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
1462 // Check for comment
1468 bool finished
= FALSE
;
1476 int newCh
= getc(fd
);
1491 return wxEatWhiteSpace(fd
);
1494 bool wxGetResourceToken(FILE *fd
)
1496 if (!wxResourceBuffer
)
1497 wxReallocateResourceBuffer();
1498 wxResourceBuffer
[0] = 0;
1499 wxEatWhiteSpace(fd
);
1505 wxResourceBufferCount
= 0;
1512 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1515 // Escaped characters
1516 else if (ch
== '\\')
1518 int newCh
= getc(fd
);
1521 else if (newCh
== 10)
1529 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1530 wxReallocateResourceBuffer();
1531 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1532 wxResourceBufferCount
++;
1535 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1539 wxResourceBufferCount
= 0;
1541 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1543 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1544 wxReallocateResourceBuffer();
1545 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1546 wxResourceBufferCount
++;
1550 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1558 * Files are in form:
1559 static char *name = "....";
1560 with possible comments.
1563 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1566 table
= wxDefaultResourceTable
;
1568 // static or #define
1569 if (!wxGetResourceToken(fd
))
1575 if (strcmp(wxResourceBuffer
, "#define") == 0)
1577 wxGetResourceToken(fd
);
1578 char *name
= copystring(wxResourceBuffer
);
1579 wxGetResourceToken(fd
);
1580 char *value
= copystring(wxResourceBuffer
);
1581 if (isalpha(value
[0]))
1583 int val
= (int)atol(value
);
1584 wxResourceAddIdentifier(name
, val
, table
);
1588 wxLogWarning(_("#define %s must be an integer."), name
);
1598 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1600 wxGetResourceToken(fd
);
1601 char *name
= copystring(wxResourceBuffer
);
1602 char *actualName
= name
;
1604 actualName
= name
+ 1;
1605 int len
= strlen(name
);
1606 if ((len
> 0) && (name
[len
-1] == '"'))
1608 if (!wxResourceParseIncludeFile(actualName
, table
))
1610 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1615 else if (strcmp(wxResourceBuffer
, "static") != 0)
1618 strcpy(buf
, _("Found "));
1619 strncat(buf
, wxResourceBuffer
, 30);
1620 strcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1626 if (!wxGetResourceToken(fd
))
1628 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1633 if (strcmp(wxResourceBuffer
, "char") != 0)
1635 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1640 if (!wxGetResourceToken(fd
))
1642 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1647 if (wxResourceBuffer
[0] != '*')
1649 wxLogWarning(_("Expected '*' whilst parsing resource."));
1653 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
1656 if (!wxGetResourceToken(fd
))
1658 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1663 if (strcmp(wxResourceBuffer
, "=") != 0)
1665 wxLogWarning(_("Expected '=' whilst parsing resource."));
1670 if (!wxGetResourceToken(fd
))
1672 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1678 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1680 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1685 if (!wxGetResourceToken(fd
))
1693 * Parses string window style into integer window style
1697 * Style flag parsing, e.g.
1698 * "wxSYSTEM_MENU | wxBORDER" -> integer
1701 char* wxResourceParseWord(char*s
, int *i
)
1704 return (char*) NULL
;
1706 static char buf
[150];
1707 int len
= strlen(s
);
1710 while ((ii
< len
) && (isalpha(s
[ii
]) || (s
[ii
] == '_')))
1718 // Eat whitespace and conjunction characters
1719 while ((ii
< len
) &&
1720 ((s
[ii
] == ' ') || (s
[ii
] == '|') || (s
[ii
] == ',')))
1726 return (char*) NULL
;
1731 struct wxResourceBitListStruct
1737 static wxResourceBitListStruct wxResourceBitListTable
[] =
1740 { "wxSINGLE", wxLB_SINGLE
},
1741 { "wxMULTIPLE", wxLB_MULTIPLE
},
1742 { "wxEXTENDED", wxLB_EXTENDED
},
1743 { "wxLB_SINGLE", wxLB_SINGLE
},
1744 { "wxLB_MULTIPLE", wxLB_MULTIPLE
},
1745 { "wxLB_EXTENDED", wxLB_EXTENDED
},
1746 { "wxLB_NEEDED_SB", wxLB_NEEDED_SB
},
1747 { "wxLB_ALWAYS_SB", wxLB_ALWAYS_SB
},
1748 { "wxLB_SORT", wxLB_SORT
},
1749 { "wxLB_OWNERDRAW", wxLB_OWNERDRAW
},
1750 { "wxLB_HSCROLL", wxLB_HSCROLL
},
1753 { "wxCB_SIMPLE", wxCB_SIMPLE
},
1754 { "wxCB_DROPDOWN", wxCB_DROPDOWN
},
1755 { "wxCB_READONLY", wxCB_READONLY
},
1756 { "wxCB_SORT", wxCB_SORT
},
1759 { "wxGA_PROGRESSBAR", wxGA_PROGRESSBAR
},
1760 { "wxGA_HORIZONTAL", wxGA_HORIZONTAL
},
1761 { "wxGA_VERTICAL", wxGA_VERTICAL
},
1764 { "wxPASSWORD", wxPASSWORD
},
1765 { "wxPROCESS_ENTER", wxPROCESS_ENTER
},
1766 { "wxTE_PASSWORD", wxTE_PASSWORD
},
1767 { "wxTE_READONLY", wxTE_READONLY
},
1768 { "wxTE_PROCESS_ENTER", wxTE_PROCESS_ENTER
},
1769 { "wxTE_MULTILINE", wxTE_MULTILINE
},
1771 /* wxRadioBox/wxRadioButton */
1772 { "wxRB_GROUP", wxRB_GROUP
},
1773 { "wxRA_SPECIFY_COLS", wxRA_SPECIFY_COLS
},
1774 { "wxRA_SPECIFY_ROWS", wxRA_SPECIFY_ROWS
},
1775 { "wxRA_HORIZONTAL", wxRA_HORIZONTAL
},
1776 { "wxRA_VERTICAL", wxRA_VERTICAL
},
1779 { "wxSL_HORIZONTAL", wxSL_HORIZONTAL
},
1780 { "wxSL_VERTICAL", wxSL_VERTICAL
},
1781 { "wxSL_AUTOTICKS", wxSL_AUTOTICKS
},
1782 { "wxSL_LABELS", wxSL_LABELS
},
1783 { "wxSL_LEFT", wxSL_LEFT
},
1784 { "wxSL_TOP", wxSL_TOP
},
1785 { "wxSL_RIGHT", wxSL_RIGHT
},
1786 { "wxSL_BOTTOM", wxSL_BOTTOM
},
1787 { "wxSL_BOTH", wxSL_BOTH
},
1788 { "wxSL_SELRANGE", wxSL_SELRANGE
},
1791 { "wxSB_HORIZONTAL", wxSB_HORIZONTAL
},
1792 { "wxSB_VERTICAL", wxSB_VERTICAL
},
1795 { "wxBU_AUTODRAW", wxBU_AUTODRAW
},
1796 { "wxBU_NOAUTODRAW", wxBU_NOAUTODRAW
},
1799 { "wxTR_HAS_BUTTONS", wxTR_HAS_BUTTONS
},
1800 { "wxTR_EDIT_LABELS", wxTR_EDIT_LABELS
},
1801 { "wxTR_LINES_AT_ROOT", wxTR_LINES_AT_ROOT
},
1804 { "wxLC_ICON", wxLC_ICON
},
1805 { "wxLC_SMALL_ICON", wxLC_SMALL_ICON
},
1806 { "wxLC_LIST", wxLC_LIST
},
1807 { "wxLC_REPORT", wxLC_REPORT
},
1808 { "wxLC_ALIGN_TOP", wxLC_ALIGN_TOP
},
1809 { "wxLC_ALIGN_LEFT", wxLC_ALIGN_LEFT
},
1810 { "wxLC_AUTOARRANGE", wxLC_AUTOARRANGE
},
1811 { "wxLC_USER_TEXT", wxLC_USER_TEXT
},
1812 { "wxLC_EDIT_LABELS", wxLC_EDIT_LABELS
},
1813 { "wxLC_NO_HEADER", wxLC_NO_HEADER
},
1814 { "wxLC_NO_SORT_HEADER", wxLC_NO_SORT_HEADER
},
1815 { "wxLC_SINGLE_SEL", wxLC_SINGLE_SEL
},
1816 { "wxLC_SORT_ASCENDING", wxLC_SORT_ASCENDING
},
1817 { "wxLC_SORT_DESCENDING", wxLC_SORT_DESCENDING
},
1820 { "wxSP_VERTICAL", wxSP_VERTICAL
},
1821 { "wxSP_HORIZONTAL", wxSP_HORIZONTAL
},
1822 { "wxSP_ARROW_KEYS", wxSP_ARROW_KEYS
},
1823 { "wxSP_WRAP", wxSP_WRAP
},
1826 { "wxSP_NOBORDER", wxSP_NOBORDER
},
1827 { "wxSP_3D", wxSP_3D
},
1828 { "wxSP_BORDER", wxSP_BORDER
},
1831 { "wxTC_MULTILINE", wxTC_MULTILINE
},
1832 { "wxTC_RIGHTJUSTIFY", wxTC_RIGHTJUSTIFY
},
1833 { "wxTC_FIXEDWIDTH", wxTC_FIXEDWIDTH
},
1834 { "wxTC_OWNERDRAW", wxTC_OWNERDRAW
},
1837 { "wxST_SIZEGRIP", wxST_SIZEGRIP
},
1840 { "wxFIXED_LENGTH", wxFIXED_LENGTH
},
1841 { "wxALIGN_LEFT", wxALIGN_LEFT
},
1842 { "wxALIGN_CENTER", wxALIGN_CENTER
},
1843 { "wxALIGN_CENTRE", wxALIGN_CENTRE
},
1844 { "wxALIGN_RIGHT", wxALIGN_RIGHT
},
1845 { "wxCOLOURED", wxCOLOURED
},
1848 { "wxTB_3DBUTTONS", wxTB_3DBUTTONS
},
1849 { "wxTB_HORIZONTAL", wxTB_HORIZONTAL
},
1850 { "wxTB_VERTICAL", wxTB_VERTICAL
},
1851 { "wxTB_FLAT", wxTB_FLAT
},
1854 { "wxVSCROLL", wxVSCROLL
},
1855 { "wxHSCROLL", wxHSCROLL
},
1856 { "wxCAPTION", wxCAPTION
},
1857 { "wxSTAY_ON_TOP", wxSTAY_ON_TOP
},
1858 { "wxICONIZE", wxICONIZE
},
1859 { "wxMINIMIZE", wxICONIZE
},
1860 { "wxMAXIMIZE", wxMAXIMIZE
},
1862 { "wxMDI_PARENT", 0},
1863 { "wxMDI_CHILD", 0},
1864 { "wxTHICK_FRAME", wxTHICK_FRAME
},
1865 { "wxRESIZE_BORDER", wxRESIZE_BORDER
},
1866 { "wxSYSTEM_MENU", wxSYSTEM_MENU
},
1867 { "wxMINIMIZE_BOX", wxMINIMIZE_BOX
},
1868 { "wxMAXIMIZE_BOX", wxMAXIMIZE_BOX
},
1869 { "wxRESIZE_BOX", wxRESIZE_BOX
},
1870 { "wxDEFAULT_FRAME_STYLE", wxDEFAULT_FRAME_STYLE
},
1871 { "wxDEFAULT_FRAME", wxDEFAULT_FRAME_STYLE
},
1872 { "wxDEFAULT_DIALOG_STYLE", wxDEFAULT_DIALOG_STYLE
},
1873 { "wxBORDER", wxBORDER
},
1874 { "wxRETAINED", wxRETAINED
},
1875 { "wxNATIVE_IMPL", 0},
1876 { "wxEXTENDED_IMPL", 0},
1877 { "wxBACKINGSTORE", wxBACKINGSTORE
},
1878 // { "wxFLAT", wxFLAT},
1879 // { "wxMOTIF_RESIZE", wxMOTIF_RESIZE},
1880 { "wxFIXED_LENGTH", 0},
1881 { "wxDOUBLE_BORDER", wxDOUBLE_BORDER
},
1882 { "wxSUNKEN_BORDER", wxSUNKEN_BORDER
},
1883 { "wxRAISED_BORDER", wxRAISED_BORDER
},
1884 { "wxSIMPLE_BORDER", wxSIMPLE_BORDER
},
1885 { "wxSTATIC_BORDER", wxSTATIC_BORDER
},
1886 { "wxTRANSPARENT_WINDOW", wxTRANSPARENT_WINDOW
},
1887 { "wxNO_BORDER", wxNO_BORDER
},
1888 { "wxCLIP_CHILDREN", wxCLIP_CHILDREN
},
1890 { "wxTINY_CAPTION_HORIZ", wxTINY_CAPTION_HORIZ
},
1891 { "wxTINY_CAPTION_VERT", wxTINY_CAPTION_VERT
},
1893 // Text font families
1894 { "wxDEFAULT", wxDEFAULT
},
1895 { "wxDECORATIVE", wxDECORATIVE
},
1896 { "wxROMAN", wxROMAN
},
1897 { "wxSCRIPT", wxSCRIPT
},
1898 { "wxSWISS", wxSWISS
},
1899 { "wxMODERN", wxMODERN
},
1900 { "wxTELETYPE", wxTELETYPE
},
1901 { "wxVARIABLE", wxVARIABLE
},
1902 { "wxFIXED", wxFIXED
},
1903 { "wxNORMAL", wxNORMAL
},
1904 { "wxLIGHT", wxLIGHT
},
1905 { "wxBOLD", wxBOLD
},
1906 { "wxITALIC", wxITALIC
},
1907 { "wxSLANT", wxSLANT
},
1908 { "wxSOLID", wxSOLID
},
1910 { "wxLONG_DASH", wxLONG_DASH
},
1911 { "wxSHORT_DASH", wxSHORT_DASH
},
1912 { "wxDOT_DASH", wxDOT_DASH
},
1913 { "wxUSER_DASH", wxUSER_DASH
},
1914 { "wxTRANSPARENT", wxTRANSPARENT
},
1915 { "wxSTIPPLE", wxSTIPPLE
},
1916 { "wxBDIAGONAL_HATCH", wxBDIAGONAL_HATCH
},
1917 { "wxCROSSDIAG_HATCH", wxCROSSDIAG_HATCH
},
1918 { "wxFDIAGONAL_HATCH", wxFDIAGONAL_HATCH
},
1919 { "wxCROSS_HATCH", wxCROSS_HATCH
},
1920 { "wxHORIZONTAL_HATCH", wxHORIZONTAL_HATCH
},
1921 { "wxVERTICAL_HATCH", wxVERTICAL_HATCH
},
1922 { "wxJOIN_BEVEL", wxJOIN_BEVEL
},
1923 { "wxJOIN_MITER", wxJOIN_MITER
},
1924 { "wxJOIN_ROUND", wxJOIN_ROUND
},
1925 { "wxCAP_ROUND", wxCAP_ROUND
},
1926 { "wxCAP_PROJECTING", wxCAP_PROJECTING
},
1927 { "wxCAP_BUTT", wxCAP_BUTT
},
1930 { "wxCLEAR", wxCLEAR
},
1932 { "wxINVERT", wxINVERT
},
1933 { "wxOR_REVERSE", wxOR_REVERSE
},
1934 { "wxAND_REVERSE", wxAND_REVERSE
},
1935 { "wxCOPY", wxCOPY
},
1937 { "wxAND_INVERT", wxAND_INVERT
},
1938 { "wxNO_OP", wxNO_OP
},
1940 { "wxEQUIV", wxEQUIV
},
1941 { "wxSRC_INVERT", wxSRC_INVERT
},
1942 { "wxOR_INVERT", wxOR_INVERT
},
1943 { "wxNAND", wxNAND
},
1947 { "wxFLOOD_SURFACE", wxFLOOD_SURFACE
},
1948 { "wxFLOOD_BORDER", wxFLOOD_BORDER
},
1949 { "wxODDEVEN_RULE", wxODDEVEN_RULE
},
1950 { "wxWINDING_RULE", wxWINDING_RULE
},
1951 { "wxHORIZONTAL", wxHORIZONTAL
},
1952 { "wxVERTICAL", wxVERTICAL
},
1953 { "wxBOTH", wxBOTH
},
1954 { "wxCENTER_FRAME", wxCENTER_FRAME
},
1956 { "wxYES_NO", wxYES_NO
},
1957 { "wxCANCEL", wxCANCEL
},
1960 { "wxICON_EXCLAMATION", wxICON_EXCLAMATION
},
1961 { "wxICON_HAND", wxICON_HAND
},
1962 { "wxICON_QUESTION", wxICON_QUESTION
},
1963 { "wxICON_INFORMATION", wxICON_INFORMATION
},
1964 { "wxICON_STOP", wxICON_STOP
},
1965 { "wxICON_ASTERISK", wxICON_ASTERISK
},
1966 { "wxICON_MASK", wxICON_MASK
},
1967 { "wxCENTRE", wxCENTRE
},
1968 { "wxCENTER", wxCENTRE
},
1969 { "wxUSER_COLOURS", wxUSER_COLOURS
},
1970 { "wxVERTICAL_LABEL", 0},
1971 { "wxHORIZONTAL_LABEL", 0},
1973 // Bitmap types (not strictly styles)
1974 { "wxBITMAP_TYPE_XPM", wxBITMAP_TYPE_XPM
},
1975 { "wxBITMAP_TYPE_XBM", wxBITMAP_TYPE_XBM
},
1976 { "wxBITMAP_TYPE_BMP", wxBITMAP_TYPE_BMP
},
1977 { "wxBITMAP_TYPE_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
},
1978 { "wxBITMAP_TYPE_BMP_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
},
1979 { "wxBITMAP_TYPE_GIF", wxBITMAP_TYPE_GIF
},
1980 { "wxBITMAP_TYPE_TIF", wxBITMAP_TYPE_TIF
},
1981 { "wxBITMAP_TYPE_ICO", wxBITMAP_TYPE_ICO
},
1982 { "wxBITMAP_TYPE_ICO_RESOURCE", wxBITMAP_TYPE_ICO_RESOURCE
},
1983 { "wxBITMAP_TYPE_CUR", wxBITMAP_TYPE_CUR
},
1984 { "wxBITMAP_TYPE_CUR_RESOURCE", wxBITMAP_TYPE_CUR_RESOURCE
},
1985 { "wxBITMAP_TYPE_XBM_DATA", wxBITMAP_TYPE_XBM_DATA
},
1986 { "wxBITMAP_TYPE_XPM_DATA", wxBITMAP_TYPE_XPM_DATA
},
1987 { "wxBITMAP_TYPE_ANY", wxBITMAP_TYPE_ANY
}
1990 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
1992 long wxParseWindowStyle(const wxString
& bitListString
)
1997 while ((word
= wxResourceParseWord((char*) (const char*) bitListString
, &i
)))
2001 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2002 if (strcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2004 bitList
|= wxResourceBitListTable
[j
].bits
;
2010 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word
);
2018 * Load a bitmap from a wxWindows resource, choosing an optimum
2019 * depth and appropriate type.
2022 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
2025 table
= wxDefaultResourceTable
;
2027 wxItemResource
*item
= table
->FindResource(resource
);
2030 if (!item
->GetType() || strcmp(item
->GetType(), "wxBitmap") != 0)
2032 wxLogWarning(_("%s not a bitmap resource specification."), (const char*) resource
);
2033 return wxNullBitmap
;
2035 int thisDepth
= wxDisplayDepth();
2036 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2038 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2040 // Try to find optimum bitmap for this platform/colour depth
2041 wxNode
*node
= item
->GetChildren().First();
2044 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2045 int platform
= (int)child
->GetValue2();
2046 int noColours
= (int)child
->GetValue3();
2048 char *name = child->GetName();
2049 int bitmapType = (int)child->GetValue1();
2050 int xRes = child->GetWidth();
2051 int yRes = child->GetHeight();
2056 case RESOURCE_PLATFORM_ANY
:
2058 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2059 optResource
= child
;
2062 // Maximise the number of colours.
2063 // If noColours is zero (unspecified), then assume this
2064 // is the right one.
2065 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2066 optResource
= child
;
2071 case RESOURCE_PLATFORM_WINDOWS
:
2073 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2074 optResource
= child
;
2077 // Maximise the number of colours
2078 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2079 optResource
= child
;
2085 case RESOURCE_PLATFORM_X
:
2087 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2088 optResource
= child
;
2091 // Maximise the number of colours
2092 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2093 optResource
= child
;
2099 case RESOURCE_PLATFORM_MAC
:
2101 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2102 optResource
= child
;
2105 // Maximise the number of colours
2106 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2107 optResource
= child
;
2115 node
= node
->Next();
2117 // If no matching resource, fail.
2119 return wxNullBitmap
;
2121 wxString name
= optResource
->GetName();
2122 int bitmapType
= (int)optResource
->GetValue1();
2125 case wxBITMAP_TYPE_XBM_DATA
:
2128 wxItemResource
*item
= table
->FindResource(name
);
2131 wxLogWarning(_("Failed to find XBM resource %s.\n"
2132 "Forgot to use wxResourceLoadBitmapData?"), (const char*) name
);
2133 return wxNullBitmap
;
2135 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2137 wxLogWarning(_("No XBM facility available!"));
2141 case wxBITMAP_TYPE_XPM_DATA
:
2143 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2144 wxItemResource
*item
= table
->FindResource(name
);
2147 wxLogWarning(_("Failed to find XPM resource %s.\n"
2148 "Forgot to use wxResourceLoadBitmapData?"), (const char*) name
);
2149 return wxNullBitmap
;
2151 return wxBitmap(item
->GetValue1());
2153 wxLogWarning(_("No XPM facility available!"));
2159 return wxBitmap(name
, bitmapType
);
2163 return wxNullBitmap
;
2167 wxLogWarning(_("Bitmap resource specification %s not found."), (const char*) resource
);
2168 return wxNullBitmap
;
2173 * Load an icon from a wxWindows resource, choosing an optimum
2174 * depth and appropriate type.
2177 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2180 table
= wxDefaultResourceTable
;
2182 wxItemResource
*item
= table
->FindResource(resource
);
2185 if ((item
->GetType() == "") || strcmp(item
->GetType(), "wxIcon") != 0)
2187 wxLogWarning(_("%s not an icon resource specification."), (const char*) resource
);
2190 int thisDepth
= wxDisplayDepth();
2191 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2193 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2195 // Try to find optimum icon for this platform/colour depth
2196 wxNode
*node
= item
->GetChildren().First();
2199 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2200 int platform
= (int)child
->GetValue2();
2201 int noColours
= (int)child
->GetValue3();
2203 char *name = child->GetName();
2204 int bitmapType = (int)child->GetValue1();
2205 int xRes = child->GetWidth();
2206 int yRes = child->GetHeight();
2211 case RESOURCE_PLATFORM_ANY
:
2213 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2214 optResource
= child
;
2217 // Maximise the number of colours.
2218 // If noColours is zero (unspecified), then assume this
2219 // is the right one.
2220 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2221 optResource
= child
;
2226 case RESOURCE_PLATFORM_WINDOWS
:
2228 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2229 optResource
= child
;
2232 // Maximise the number of colours
2233 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2234 optResource
= child
;
2240 case RESOURCE_PLATFORM_X
:
2242 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2243 optResource
= child
;
2246 // Maximise the number of colours
2247 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2248 optResource
= child
;
2254 case RESOURCE_PLATFORM_MAC
:
2256 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2257 optResource
= child
;
2260 // Maximise the number of colours
2261 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2262 optResource
= child
;
2270 node
= node
->Next();
2272 // If no matching resource, fail.
2276 wxString name
= optResource
->GetName();
2277 int bitmapType
= (int)optResource
->GetValue1();
2280 case wxBITMAP_TYPE_XBM_DATA
:
2283 wxItemResource
*item
= table
->FindResource(name
);
2286 wxLogWarning(_("Failed to find XBM resource %s.\n"
2287 "Forgot to use wxResourceLoadIconData?"), (const char*) name
);
2290 return wxIcon((const char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2292 wxLogWarning(_("No XBM facility available!"));
2296 case wxBITMAP_TYPE_XPM_DATA
:
2298 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2300 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2301 wxItemResource *item = table->FindResource(name);
2305 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2309 return wxIcon((char **)item->GetValue1());
2311 wxLogWarning(_("No XPM facility available!"));
2314 wxLogWarning(_("No XPM icon facility available!"));
2320 wxLogWarning(_("Icon resource specification %s not found."), (const char*) resource
);
2322 return wxIcon(name
, bitmapType
);
2331 wxLogWarning(_("Icon resource specification %s not found."), (const char*) resource
);
2336 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2338 wxMenu
*menu
= new wxMenu
;
2339 wxNode
*node
= item
->GetChildren().First();
2342 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2343 if ((child
->GetType() != "") && (child
->GetType() == "wxMenuSeparator"))
2344 menu
->AppendSeparator();
2345 else if (child
->GetChildren().Number() > 0)
2347 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2349 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2353 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2355 node
= node
->Next();
2360 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2363 table
= wxDefaultResourceTable
;
2365 wxItemResource
*menuResource
= table
->FindResource(resource
);
2366 if (menuResource
&& (menuResource
->GetType() != "") && (menuResource
->GetType() == "wxMenu"))
2369 menuBar
= new wxMenuBar
;
2370 wxNode
*node
= menuResource
->GetChildren().First();
2373 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2374 wxMenu
*menu
= wxResourceCreateMenu(child
);
2376 menuBar
->Append(menu
, child
->GetTitle());
2377 node
= node
->Next();
2381 return (wxMenuBar
*) NULL
;
2384 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2387 table
= wxDefaultResourceTable
;
2389 wxItemResource
*menuResource
= table
->FindResource(resource
);
2390 if (menuResource
&& (menuResource
->GetType() != "") && (menuResource
->GetType() == "wxMenu"))
2391 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2392 return wxResourceCreateMenu(menuResource
);
2393 return (wxMenu
*) NULL
;
2396 // Global equivalents (so don't have to refer to default table explicitly)
2397 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2400 table
= wxDefaultResourceTable
;
2402 return table
->ParseResourceData(resource
);
2405 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2408 table
= wxDefaultResourceTable
;
2410 return table
->ParseResourceFile(filename
);
2413 // Register XBM/XPM data
2414 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2417 table
= wxDefaultResourceTable
;
2419 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2422 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2425 table
= wxDefaultResourceTable
;
2427 return table
->RegisterResourceBitmapData(name
, data
);
2430 void wxResourceClear(wxResourceTable
*table
)
2433 table
= wxDefaultResourceTable
;
2435 table
->ClearTable();
2442 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2445 table
= wxDefaultResourceTable
;
2447 table
->identifiers
.Put(name
, (wxObject
*)value
);
2451 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2454 table
= wxDefaultResourceTable
;
2456 return (int)table
->identifiers
.Get(name
);
2460 * Parse #include file for #defines (only)
2463 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2466 table
= wxDefaultResourceTable
;
2468 FILE *fd
= fopen(f
, "r");
2473 while (wxGetResourceToken(fd
))
2475 if (strcmp(wxResourceBuffer
, "#define") == 0)
2477 wxGetResourceToken(fd
);
2478 char *name
= copystring(wxResourceBuffer
);
2479 wxGetResourceToken(fd
);
2480 char *value
= copystring(wxResourceBuffer
);
2481 if (isdigit(value
[0]))
2483 int val
= (int)atol(value
);
2484 wxResourceAddIdentifier(name
, val
, table
);
2495 * Reading strings as if they were .wxr files
2498 static int getc_string(char *s
)
2500 int ch
= s
[wxResourceStringPtr
];
2505 wxResourceStringPtr
++;
2510 static int ungetc_string()
2512 wxResourceStringPtr
--;
2516 bool wxEatWhiteSpaceString(char *s
)
2518 int ch
= getc_string(s
);
2522 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
2529 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
2530 ch
= getc_string(s
);
2531 // Check for comment
2534 ch
= getc_string(s
);
2537 bool finished
= FALSE
;
2540 ch
= getc_string(s
);
2545 int newCh
= getc_string(s
);
2560 return wxEatWhiteSpaceString(s
);
2563 bool wxGetResourceTokenString(char *s
)
2565 if (!wxResourceBuffer
)
2566 wxReallocateResourceBuffer();
2567 wxResourceBuffer
[0] = 0;
2568 wxEatWhiteSpaceString(s
);
2570 int ch
= getc_string(s
);
2574 wxResourceBufferCount
= 0;
2575 ch
= getc_string(s
);
2581 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2584 // Escaped characters
2585 else if (ch
== '\\')
2587 int newCh
= getc_string(s
);
2590 else if (newCh
== 10)
2598 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2599 wxReallocateResourceBuffer();
2600 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2601 wxResourceBufferCount
++;
2602 ch
= getc_string(s
);
2604 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2608 wxResourceBufferCount
= 0;
2610 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2612 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2613 wxReallocateResourceBuffer();
2614 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2615 wxResourceBufferCount
++;
2617 ch
= getc_string(s
);
2619 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2627 * Files are in form:
2628 static char *name = "....";
2629 with possible comments.
2632 bool wxResourceReadOneResourceString(char *s
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2635 table
= wxDefaultResourceTable
;
2637 // static or #define
2638 if (!wxGetResourceTokenString(s
))
2644 if (strcmp(wxResourceBuffer
, "#define") == 0)
2646 wxGetResourceTokenString(s
);
2647 char *name
= copystring(wxResourceBuffer
);
2648 wxGetResourceTokenString(s
);
2649 char *value
= copystring(wxResourceBuffer
);
2650 if (isalpha(value
[0]))
2652 int val
= (int)atol(value
);
2653 wxResourceAddIdentifier(name
, val
, table
);
2657 wxLogWarning(_("#define %s must be an integer."), name
);
2668 else if (strcmp(wxResourceBuffer, "#include") == 0)
2670 wxGetResourceTokenString(s);
2671 char *name = copystring(wxResourceBuffer);
2672 char *actualName = name;
2674 actualName = name + 1;
2675 int len = strlen(name);
2676 if ((len > 0) && (name[len-1] == '"'))
2678 if (!wxResourceParseIncludeFile(actualName, table))
2681 sprintf(buf, _("Could not find resource include file %s."), actualName);
2688 else if (strcmp(wxResourceBuffer
, "static") != 0)
2691 strcpy(buf
, _("Found "));
2692 strncat(buf
, wxResourceBuffer
, 30);
2693 strcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
2699 if (!wxGetResourceTokenString(s
))
2701 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2706 if (strcmp(wxResourceBuffer
, "char") != 0)
2708 wxLogWarning(_("Expected 'char' whilst parsing resource."));
2713 if (!wxGetResourceTokenString(s
))
2715 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2720 if (wxResourceBuffer
[0] != '*')
2722 wxLogWarning(_("Expected '*' whilst parsing resource."));
2726 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
2729 if (!wxGetResourceTokenString(s
))
2731 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2736 if (strcmp(wxResourceBuffer
, "=") != 0)
2738 wxLogWarning(_("Expected '=' whilst parsing resource."));
2743 if (!wxGetResourceTokenString(s
))
2745 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2751 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2753 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2758 if (!wxGetResourceTokenString(s
))
2765 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
2768 table
= wxDefaultResourceTable
;
2773 // Turn backslashes into spaces
2776 int len
= strlen(s
);
2778 for (i
= 0; i
< len
; i
++)
2779 if (s
[i
] == 92 && s
[i
+1] == 13)
2787 wxResourceStringPtr
= 0;
2790 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
2794 return wxResourceInterpretResources(*table
, db
);
2798 * resource loading facility
2801 bool wxWindow::LoadFromResource(wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
2804 table
= wxDefaultResourceTable
;
2806 wxItemResource
*resource
= table
->FindResource((const char *)resourceName
);
2807 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
2808 if (!resource
|| !resource
->GetType() ||
2809 ! ((strcmp(resource
->GetType(), "wxDialog") == 0) || (strcmp(resource
->GetType(), "wxPanel") == 0)))
2812 wxString
title(resource
->GetTitle());
2813 long theWindowStyle
= resource
->GetStyle();
2814 bool isModal
= (resource
->GetValue1() != 0);
2815 int x
= resource
->GetX();
2816 int y
= resource
->GetY();
2817 int width
= resource
->GetWidth();
2818 int height
= resource
->GetHeight();
2819 wxString name
= resource
->GetName();
2821 if (IsKindOf(CLASSINFO(wxDialog
)))
2823 wxDialog
*dialogBox
= (wxDialog
*)this;
2824 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
2825 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
2828 // Only reset the client size if we know we're not going to do it again below.
2829 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == 0)
2830 dialogBox
->SetClientSize(width
, height
);
2832 else if (IsKindOf(CLASSINFO(wxPanel
)))
2834 wxPanel
* panel
= (wxPanel
*)this;
2835 if (!panel
->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2840 if (!this->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2844 if ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
2846 // No need to do this since it's done in wxPanel or wxDialog constructor.
2847 // SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
2851 if (resource
->GetFont().Ok())
2852 SetFont(resource
->GetFont());
2853 if (resource
->GetBackgroundColour().Ok())
2854 SetBackgroundColour(resource
->GetBackgroundColour());
2857 // Should have some kind of font at this point
2858 if (!GetFont().Ok())
2859 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
2860 if (!GetBackgroundColour().Ok())
2861 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
2863 // Only when we've created the window and set the font can we set the correct size,
2864 // if based on dialog units.
2865 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
2867 wxSize sz
= ConvertDialogToPixels(wxSize(width
, height
));
2868 SetClientSize(sz
.x
, sz
.y
);
2870 wxPoint pt
= ConvertDialogToPixels(wxPoint(x
, y
));
2874 // Now create children
2875 wxNode
*node
= resource
->GetChildren().First();
2878 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
2880 (void) CreateItem(childResource
, resource
, table
);
2882 node
= node
->Next();
2887 wxControl
*wxWindow::CreateItem(const wxItemResource
*resource
, const wxItemResource
* parentResource
, const wxResourceTable
*table
)
2890 table
= wxDefaultResourceTable
;
2891 return table
->CreateItem((wxWindow
*)this, resource
, parentResource
);
2895 #pragma warning(default:4706) // assignment within conditional expression
2898 #endif // wxUSE_WX_RESOURCES