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/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((char *)(const char *)name
);
171 void wxResourceTable::AddResource(wxItemResource
*item
)
173 wxString name
= item
->GetName();
175 name
= item
->GetTitle();
179 // Delete existing resource, if any.
185 bool wxResourceTable::DeleteResource(const wxString
& name
)
187 wxItemResource
*item
= (wxItemResource
*)Delete((char *)(const char *)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((const char*) filename
, "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("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("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("wxButton") || itemType
== wxString("wxBitmapButton"))
310 if (childResource
->GetValue4() != "")
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("wxMessage") || itemType
== wxString("wxStaticText") ||
329 itemType
== wxString("wxStaticBitmap"))
331 if (childResource
->GetValue4() != "")
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("wxText") || itemType
== wxString("wxTextCtrl") || itemType
== wxString("wxMultiText"))
354 control
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(), pos
, size
,
355 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
357 else if (itemType
== wxString("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("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());
373 #if wxUSE_RADIOBUTTON
374 else if (itemType
== wxString("wxRadioButton"))
376 control
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(),
378 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
382 else if (itemType
== wxString("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("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("wxGroupBox") || itemType
== wxString("wxStaticBox"))
405 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
406 childResource
->GetStyle(), childResource
->GetName());
408 else if (itemType
== wxString("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
] = (char *)node
->Data();
426 control
= new wxListBox(parent
, id
, pos
, size
,
427 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
432 else if (itemType
== wxString("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
] = (char *)node
->Data();
450 control
= new wxChoice(parent
, id
, pos
, size
,
451 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
457 else if (itemType
== wxString("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
] = (char *)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("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
] = (char *)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
== "dialog")
534 item
= wxResourceInterpretDialog(table
, clause
);
535 else if (functor
== "panel")
536 item
= wxResourceInterpretDialog(table
, clause
, TRUE
);
537 else if (functor
== "menubar")
538 item
= wxResourceInterpretMenuBar(table
, clause
);
539 else if (functor
== "menu")
540 item
= wxResourceInterpretMenu(table
, clause
);
541 else if (functor
== "string")
542 item
= wxResourceInterpretString(table
, clause
);
543 else if (functor
== "bitmap")
544 item
= wxResourceInterpretBitmap(table
, clause
);
545 else if (functor
== "icon")
546 item
= wxResourceInterpretIcon(table
, clause
);
550 // Remove any existing resource of same name
551 if (item
->GetName() != "")
552 table
.DeleteResource(item
->GetName());
553 table
.AddResource(item
);
560 static char *g_ValidControlClasses
[] = { "wxButton", "wxBitmapButton", "wxMessage",
561 "wxStaticText", "wxStaticBitmap", "wxText", "wxTextCtrl", "wxMultiText",
562 "wxListBox", "wxRadioBox", "wxRadioButton", "wxCheckBox", "wxBitmapCheckBox",
563 "wxGroupBox", "wxStaticBox", "wxSlider", "wxGauge", "wxScrollBar",
564 "wxChoice", "wxComboBox" } ;
565 static int g_ValidControlClassesCount
= sizeof(g_ValidControlClasses
) / sizeof(char *) ;
567 static bool wxIsValidControlClass(const wxString
& c
)
570 for ( i
= 0; i
< g_ValidControlClassesCount
; i
++)
572 if ( c
== g_ValidControlClasses
[i
] )
578 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
)
580 wxItemResource
*dialogItem
= new wxItemResource
;
582 dialogItem
->SetType("wxPanel");
584 dialogItem
->SetType("wxDialog");
588 wxString backColourHex
= "";
589 wxString labelColourHex
= "";
590 wxString buttonColourHex
= "";
592 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
596 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
598 wxExpr
*labelFontExpr
= (wxExpr
*) NULL
;
599 wxExpr
*buttonFontExpr
= (wxExpr
*) NULL
;
600 wxExpr
*fontExpr
= (wxExpr
*) NULL
;
601 expr
->GetAttributeValue("style", style
);
602 expr
->GetAttributeValue("name", name
);
603 expr
->GetAttributeValue("title", title
);
604 expr
->GetAttributeValue("x", x
);
605 expr
->GetAttributeValue("y", y
);
606 expr
->GetAttributeValue("width", width
);
607 expr
->GetAttributeValue("height", height
);
608 expr
->GetAttributeValue("modal", isModal
);
609 expr
->GetAttributeValue("label_font", &labelFontExpr
);
610 expr
->GetAttributeValue("button_font", &buttonFontExpr
);
611 expr
->GetAttributeValue("font", &fontExpr
);
612 expr
->GetAttributeValue("background_colour", backColourHex
);
613 expr
->GetAttributeValue("label_colour", labelColourHex
);
614 expr
->GetAttributeValue("button_colour", buttonColourHex
);
616 int useDialogUnits
= 0;
617 expr
->GetAttributeValue("use_dialog_units", useDialogUnits
);
618 if (useDialogUnits
!= 0)
619 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS
);
622 expr
->GetAttributeValue("use_system_defaults", useDefaults
);
623 if (useDefaults
!= 0)
624 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS
);
627 expr
->GetAttributeValue("id", id
);
628 dialogItem
->SetId(id
);
632 windowStyle
= wxParseWindowStyle(style
);
634 dialogItem
->SetStyle(windowStyle
);
635 dialogItem
->SetValue1(isModal
);
636 dialogItem
->SetName(name
);
637 dialogItem
->SetTitle(title
);
638 dialogItem
->SetSize(x
, y
, width
, height
);
640 if (backColourHex
!= "")
645 r
= wxHexToDec(backColourHex
.Mid(0, 2));
646 g
= wxHexToDec(backColourHex
.Mid(2, 2));
647 b
= wxHexToDec(backColourHex
.Mid(4, 2));
648 dialogItem
->SetBackgroundColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
650 if (labelColourHex
!= "")
655 r
= wxHexToDec(labelColourHex
.Mid(0, 2));
656 g
= wxHexToDec(labelColourHex
.Mid(2, 2));
657 b
= wxHexToDec(labelColourHex
.Mid(4, 2));
658 dialogItem
->SetLabelColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
660 if (buttonColourHex
!= "")
665 r
= wxHexToDec(buttonColourHex
.Mid(0, 2));
666 g
= wxHexToDec(buttonColourHex
.Mid(2, 2));
667 b
= wxHexToDec(buttonColourHex
.Mid(4, 2));
668 dialogItem
->SetButtonColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
672 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
673 else if (buttonFontExpr
)
674 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
675 else if (labelFontExpr
)
676 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
678 // Now parse all controls
679 wxExpr
*controlExpr
= expr
->GetFirst();
682 if (controlExpr
->Number() == 3)
684 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
685 if (controlKeyword
!= "" && controlKeyword
== "control")
687 // The value part: always a list.
688 wxExpr
*listExpr
= controlExpr
->Nth(2);
689 if (listExpr
->Type() == PrologList
)
691 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
694 dialogItem
->GetChildren().Append(controlItem
);
699 controlExpr
= controlExpr
->GetNext();
704 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
)
706 wxItemResource
*controlItem
= new wxItemResource
;
708 // First, find the standard features of a control definition:
709 // [optional integer/string id], control name, title, style, name, x, y, width, height
711 wxString controlType
;
716 long windowStyle
= 0;
717 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
720 wxExpr
*expr1
= expr
->Nth(0);
722 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
724 if ( wxIsValidControlClass(expr1
->StringValue()) )
727 controlType
= expr1
->StringValue();
731 wxString
str(expr1
->StringValue());
732 id
= wxResourceGetIdentifier(str
, &table
);
735 wxLogWarning(_("Could not resolve control class or id '%s'. "
736 "Use (non-zero) integer instead\n or provide #define "
737 "(see manual for caveats)"),
738 (const char*) expr1
->StringValue());
740 return (wxItemResource
*) NULL
;
744 // Success - we have an id, so the 2nd element must be the control class.
745 controlType
= expr
->Nth(1)->StringValue();
750 else if (expr1
->Type() == PrologInteger
)
752 id
= (int)expr1
->IntegerValue();
753 // Success - we have an id, so the 2nd element must be the control class.
754 controlType
= expr
->Nth(1)->StringValue();
758 expr1
= expr
->Nth(count
);
761 title
= expr1
->StringValue();
763 expr1
= expr
->Nth(count
);
767 style
= expr1
->StringValue();
768 windowStyle
= wxParseWindowStyle(style
);
771 expr1
= expr
->Nth(count
);
774 name
= expr1
->StringValue();
776 expr1
= expr
->Nth(count
);
779 x
= (int)expr1
->IntegerValue();
781 expr1
= expr
->Nth(count
);
784 y
= (int)expr1
->IntegerValue();
786 expr1
= expr
->Nth(count
);
789 width
= (int)expr1
->IntegerValue();
791 expr1
= expr
->Nth(count
);
794 height
= (int)expr1
->IntegerValue();
796 controlItem
->SetStyle(windowStyle
);
797 controlItem
->SetName(name
);
798 controlItem
->SetTitle(title
);
799 controlItem
->SetSize(x
, y
, width
, height
);
800 controlItem
->SetType(controlType
);
801 controlItem
->SetId(id
);
803 if (controlType
== "wxButton")
805 // Check for bitmap resource name (in case loading old-style resource file)
806 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
808 wxString
str(expr
->Nth(count
)->StringValue());
809 controlItem
->SetValue4(str
);
811 controlItem
->SetType("wxBitmapButton");
813 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
814 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
816 else if (controlType
== "wxBitmapButton")
818 // Check for bitmap resource name
819 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
821 wxString
str(expr
->Nth(count
)->StringValue());
822 controlItem
->SetValue4(str
);
824 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
825 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
828 else if (controlType
== "wxCheckBox")
830 // Check for default value
831 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
833 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
835 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
836 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
839 #if wxUSE_RADIOBUTTON
840 else if (controlType
== "wxRadioButton")
842 // Check for default value
843 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
845 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
847 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
848 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
852 else if (controlType
== "wxText" || controlType
== "wxTextCtrl" || controlType
== "wxMultiText")
854 // Check for default value
855 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
857 wxString
str(expr
->Nth(count
)->StringValue());
858 controlItem
->SetValue4(str
);
861 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
863 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
864 // Do nothing - no label font any more
866 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
867 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
871 else if (controlType
== "wxMessage" || controlType
== "wxStaticText")
873 // Check for bitmap resource name (in case it's an old-style .wxr file)
874 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
876 wxString
str(expr
->Nth(count
)->StringValue());
877 controlItem
->SetValue4(str
);
879 controlItem
->SetType("wxStaticText");
881 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
882 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
884 else if (controlType
== "wxStaticBitmap")
886 // Check for bitmap resource name
887 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
889 wxString
str(expr
->Nth(count
)->StringValue());
890 controlItem
->SetValue4(str
);
893 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
894 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
896 else if (controlType
== "wxGroupBox" || controlType
== "wxStaticBox")
898 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
899 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
901 else if (controlType
== "wxGauge")
903 // Check for default value
904 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
906 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
910 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
912 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
915 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
917 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
921 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
922 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
927 else if (controlType
== "wxSlider")
929 // Check for default value
930 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
932 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
936 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
938 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
942 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
944 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
947 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
949 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
953 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
954 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
960 else if (controlType
== "wxScrollBar")
963 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
965 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
969 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
971 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
975 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
977 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
981 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
982 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
987 else if (controlType
== "wxListBox")
989 wxExpr
*valueList
= (wxExpr
*) NULL
;
991 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
993 wxStringList stringList
;
994 wxExpr
*stringExpr
= valueList
->GetFirst();
997 stringList
.Add(stringExpr
->StringValue());
998 stringExpr
= stringExpr
->GetNext();
1000 controlItem
->SetStringValues(stringList
);
1002 // This is now obsolete: it's in the window style.
1003 // Check for wxSINGLE/wxMULTIPLE
1004 wxExpr
*mult
= (wxExpr
*) NULL
;
1006 controlItem->SetValue1(wxLB_SINGLE);
1008 if ((mult
= expr
->Nth(count
)) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1011 wxString m(mult->StringValue());
1012 if (m == "wxLB_MULTIPLE")
1013 controlItem->SetValue1(wxLB_MULTIPLE);
1014 else if (m == "wxLB_EXTENDED")
1015 controlItem->SetValue1(wxLB_EXTENDED);
1020 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1022 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1024 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1025 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1029 else if (controlType
== "wxChoice")
1031 wxExpr
*valueList
= (wxExpr
*) NULL
;
1032 // Check for default value list
1033 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1035 wxStringList stringList
;
1036 wxExpr
*stringExpr
= valueList
->GetFirst();
1039 stringList
.Add(stringExpr
->StringValue());
1040 stringExpr
= stringExpr
->GetNext();
1042 controlItem
->SetStringValues(stringList
);
1046 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1048 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1051 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1052 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1057 else if (controlType
== "wxComboBox")
1059 wxExpr
*textValue
= expr
->Nth(count
);
1060 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1062 wxString
str(textValue
->StringValue());
1063 controlItem
->SetValue4(str
);
1067 wxExpr
*valueList
= (wxExpr
*) NULL
;
1068 // Check for default value list
1069 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1071 wxStringList stringList
;
1072 wxExpr
*stringExpr
= valueList
->GetFirst();
1075 stringList
.Add(stringExpr
->StringValue());
1076 stringExpr
= stringExpr
->GetNext();
1078 controlItem
->SetStringValues(stringList
);
1082 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1084 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1087 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1088 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1095 else if (controlType
== "wxRadioBox")
1097 wxExpr
*valueList
= (wxExpr
*) NULL
;
1098 // Check for default value list
1099 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1101 wxStringList stringList
;
1102 wxExpr
*stringExpr
= valueList
->GetFirst();
1105 stringList
.Add(stringExpr
->StringValue());
1106 stringExpr
= stringExpr
->GetNext();
1108 controlItem
->SetStringValues(stringList
);
1111 // majorDim (number of rows or cols)
1112 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1114 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1118 controlItem
->SetValue1(0);
1120 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1122 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1125 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1126 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1134 return (wxItemResource
*) NULL
;
1139 // Forward declaration
1140 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, wxExpr
*expr
);
1143 * Interpet a menu item
1146 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, wxExpr
*expr
)
1148 wxItemResource
*item
= new wxItemResource
;
1150 wxExpr
*labelExpr
= expr
->Nth(0);
1151 wxExpr
*idExpr
= expr
->Nth(1);
1152 wxExpr
*helpExpr
= expr
->Nth(2);
1153 wxExpr
*checkableExpr
= expr
->Nth(3);
1155 // Further keywords/attributes to follow sometime...
1156 if (expr
->Number() == 0)
1158 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1159 item
->SetType("wxMenuSeparator");
1164 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1165 item
->SetType("wxMenu"); // Well, menu item, but doesn't matter.
1168 wxString
str(labelExpr
->StringValue());
1169 item
->SetTitle(str
);
1174 // If a string or word, must look up in identifier table.
1175 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1177 wxString
str(idExpr
->StringValue());
1178 id
= wxResourceGetIdentifier(str
, &table
);
1181 wxLogWarning(_("Could not resolve menu id '%s'. "
1182 "Use (non-zero) integer instead\n"
1183 "or provide #define (see manual for caveats)"),
1184 (const char*) idExpr
->StringValue());
1187 else if (idExpr
->Type() == PrologInteger
)
1188 id
= (int)idExpr
->IntegerValue();
1189 item
->SetValue1(id
);
1193 wxString
str(helpExpr
->StringValue());
1194 item
->SetValue4(str
);
1197 item
->SetValue2(checkableExpr
->IntegerValue());
1199 // Find the first expression that's a list, for submenu
1200 wxExpr
*subMenuExpr
= expr
->GetFirst();
1201 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1202 subMenuExpr
= subMenuExpr
->GetNext();
1206 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1207 item
->GetChildren().Append(child
);
1208 subMenuExpr
= subMenuExpr
->GetNext();
1215 * Interpret a nested list as a menu
1218 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1220 wxItemResource *menu = new wxItemResource;
1221 // menu->SetType(wxTYPE_MENU);
1222 menu->SetType("wxMenu");
1223 wxExpr *element = expr->GetFirst();
1226 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1228 menu->GetChildren().Append(item);
1229 element = element->GetNext();
1235 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
)
1237 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1238 expr
->GetAttributeValue("menu", &listExpr
);
1240 return (wxItemResource
*) NULL
;
1242 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1245 return (wxItemResource
*) NULL
;
1248 if (expr
->GetAttributeValue("name", name
))
1250 menuResource
->SetName(name
);
1253 return menuResource
;
1256 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
)
1258 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1259 expr
->GetAttributeValue("menu", &listExpr
);
1261 return (wxItemResource
*) NULL
;
1263 wxItemResource
*resource
= new wxItemResource
;
1264 resource
->SetType("wxMenu");
1265 // resource->SetType(wxTYPE_MENU);
1267 wxExpr
*element
= listExpr
->GetFirst();
1270 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1271 resource
->GetChildren().Append(menuResource
);
1272 element
= element
->GetNext();
1276 if (expr
->GetAttributeValue("name", name
))
1278 resource
->SetName(name
);
1284 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), wxExpr
*WXUNUSED(expr
))
1286 return (wxItemResource
*) NULL
;
1289 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), wxExpr
*expr
)
1291 wxItemResource
*bitmapItem
= new wxItemResource
;
1292 // bitmapItem->SetType(wxTYPE_BITMAP);
1293 bitmapItem
->SetType("wxBitmap");
1295 if (expr
->GetAttributeValue("name", name
))
1297 bitmapItem
->SetName(name
);
1299 // Now parse all bitmap specifications
1300 wxExpr
*bitmapExpr
= expr
->GetFirst();
1303 if (bitmapExpr
->Number() == 3)
1305 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1306 if (bitmapKeyword
== "bitmap" || bitmapKeyword
== "icon")
1308 // The value part: always a list.
1309 wxExpr
*listExpr
= bitmapExpr
->Nth(2);
1310 if (listExpr
->Type() == PrologList
)
1312 wxItemResource
*bitmapSpec
= new wxItemResource
;
1313 // bitmapSpec->SetType(wxTYPE_BITMAP);
1314 bitmapSpec
->SetType("wxBitmap");
1316 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1317 // where everything after 'filename' is optional.
1318 wxExpr
*nameExpr
= listExpr
->Nth(0);
1319 wxExpr
*typeExpr
= listExpr
->Nth(1);
1320 wxExpr
*platformExpr
= listExpr
->Nth(2);
1321 wxExpr
*coloursExpr
= listExpr
->Nth(3);
1322 wxExpr
*xresExpr
= listExpr
->Nth(4);
1323 wxExpr
*yresExpr
= listExpr
->Nth(5);
1324 if (nameExpr
&& nameExpr
->StringValue())
1326 bitmapSpec
->SetName(nameExpr
->StringValue());
1328 if (typeExpr
&& typeExpr
->StringValue())
1330 bitmapSpec
->SetValue1(wxParseWindowStyle(typeExpr
->StringValue()));
1333 bitmapSpec
->SetValue1(0);
1335 if (platformExpr
&& platformExpr
->StringValue())
1337 wxString
plat(platformExpr
->StringValue());
1338 if (plat
== "windows" || plat
== "WINDOWS")
1339 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1340 else if (plat
== "x" || plat
== "X")
1341 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1342 else if (plat
== "mac" || plat
== "MAC")
1343 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1345 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1348 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1351 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1355 xres
= (int)xresExpr
->IntegerValue();
1357 yres
= (int)yresExpr
->IntegerValue();
1358 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1360 bitmapItem
->GetChildren().Append(bitmapSpec
);
1364 bitmapExpr
= bitmapExpr
->GetNext();
1370 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
)
1372 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1375 // item->SetType(wxTYPE_ICON);
1376 item
->SetType("wxIcon");
1380 return (wxItemResource
*) NULL
;
1383 // Interpret list expression as a font
1384 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
)
1386 if (expr
->Type() != PrologList
)
1390 int family
= wxSWISS
;
1391 int style
= wxNORMAL
;
1392 int weight
= wxNORMAL
;
1394 wxString
faceName("");
1396 wxExpr
*pointExpr
= expr
->Nth(0);
1397 wxExpr
*familyExpr
= expr
->Nth(1);
1398 wxExpr
*styleExpr
= expr
->Nth(2);
1399 wxExpr
*weightExpr
= expr
->Nth(3);
1400 wxExpr
*underlineExpr
= expr
->Nth(4);
1401 wxExpr
*faceNameExpr
= expr
->Nth(5);
1403 point
= (int)pointExpr
->IntegerValue();
1408 str
= familyExpr
->StringValue();
1409 family
= (int)wxParseWindowStyle(str
);
1413 str
= styleExpr
->StringValue();
1414 style
= (int)wxParseWindowStyle(str
);
1418 str
= weightExpr
->StringValue();
1419 weight
= (int)wxParseWindowStyle(str
);
1422 underline
= (int)underlineExpr
->IntegerValue();
1424 faceName
= faceNameExpr
->StringValue();
1426 wxFont
font(point
, family
, style
, weight
, (underline
!= 0), faceName
);
1430 // Separate file for the remainder of this, for BC++/Win16
1432 #if !(defined(__BORLANDC__) && defined(__WIN16__))
1434 * (Re)allocate buffer for reading in from resource file
1437 bool wxReallocateResourceBuffer()
1439 if (!wxResourceBuffer
)
1441 wxResourceBufferSize
= 1000;
1442 wxResourceBuffer
= new char[wxResourceBufferSize
];
1445 if (wxResourceBuffer
)
1447 long newSize
= wxResourceBufferSize
+ 1000;
1448 char *tmp
= new char[(int)newSize
];
1449 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1450 delete[] wxResourceBuffer
;
1451 wxResourceBuffer
= tmp
;
1452 wxResourceBufferSize
= newSize
;
1457 static bool wxEatWhiteSpace(FILE *fd
)
1460 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
1467 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
1469 // Check for comment
1475 bool finished
= FALSE
;
1483 int newCh
= getc(fd
);
1498 return wxEatWhiteSpace(fd
);
1501 bool wxGetResourceToken(FILE *fd
)
1503 if (!wxResourceBuffer
)
1504 wxReallocateResourceBuffer();
1505 wxResourceBuffer
[0] = 0;
1506 wxEatWhiteSpace(fd
);
1512 wxResourceBufferCount
= 0;
1519 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1522 // Escaped characters
1523 else if (ch
== '\\')
1525 int newCh
= getc(fd
);
1528 else if (newCh
== 10)
1536 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1537 wxReallocateResourceBuffer();
1538 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1539 wxResourceBufferCount
++;
1542 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1546 wxResourceBufferCount
= 0;
1548 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1550 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1551 wxReallocateResourceBuffer();
1552 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1553 wxResourceBufferCount
++;
1557 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1565 * Files are in form:
1566 static char *name = "....";
1567 with possible comments.
1570 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1573 table
= wxDefaultResourceTable
;
1575 // static or #define
1576 if (!wxGetResourceToken(fd
))
1582 if (strcmp(wxResourceBuffer
, "#define") == 0)
1584 wxGetResourceToken(fd
);
1585 char *name
= copystring(wxResourceBuffer
);
1586 wxGetResourceToken(fd
);
1587 char *value
= copystring(wxResourceBuffer
);
1588 if (isalpha(value
[0]))
1590 int val
= (int)atol(value
);
1591 wxResourceAddIdentifier(name
, val
, table
);
1595 wxLogWarning(_("#define %s must be an integer."), name
);
1605 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1607 wxGetResourceToken(fd
);
1608 char *name
= copystring(wxResourceBuffer
);
1609 char *actualName
= name
;
1611 actualName
= name
+ 1;
1612 int len
= strlen(name
);
1613 if ((len
> 0) && (name
[len
-1] == '"'))
1615 if (!wxResourceParseIncludeFile(actualName
, table
))
1617 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1622 else if (strcmp(wxResourceBuffer
, "static") != 0)
1625 strcpy(buf
, _("Found "));
1626 strncat(buf
, wxResourceBuffer
, 30);
1627 strcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1633 if (!wxGetResourceToken(fd
))
1635 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1640 if (strcmp(wxResourceBuffer
, "char") != 0)
1642 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1647 if (!wxGetResourceToken(fd
))
1649 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1654 if (wxResourceBuffer
[0] != '*')
1656 wxLogWarning(_("Expected '*' whilst parsing resource."));
1660 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
1663 if (!wxGetResourceToken(fd
))
1665 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1670 if (strcmp(wxResourceBuffer
, "=") != 0)
1672 wxLogWarning(_("Expected '=' whilst parsing resource."));
1677 if (!wxGetResourceToken(fd
))
1679 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1685 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1687 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1692 if (!wxGetResourceToken(fd
))
1700 * Parses string window style into integer window style
1704 * Style flag parsing, e.g.
1705 * "wxSYSTEM_MENU | wxBORDER" -> integer
1708 char* wxResourceParseWord(char*s
, int *i
)
1711 return (char*) NULL
;
1713 static char buf
[150];
1714 int len
= strlen(s
);
1717 while ((ii
< len
) && (isalpha(s
[ii
]) || (s
[ii
] == '_')))
1725 // Eat whitespace and conjunction characters
1726 while ((ii
< len
) &&
1727 ((s
[ii
] == ' ') || (s
[ii
] == '|') || (s
[ii
] == ',')))
1733 return (char*) NULL
;
1738 struct wxResourceBitListStruct
1744 static wxResourceBitListStruct wxResourceBitListTable
[] =
1747 { "wxSINGLE", wxLB_SINGLE
},
1748 { "wxMULTIPLE", wxLB_MULTIPLE
},
1749 { "wxEXTENDED", wxLB_EXTENDED
},
1750 { "wxLB_SINGLE", wxLB_SINGLE
},
1751 { "wxLB_MULTIPLE", wxLB_MULTIPLE
},
1752 { "wxLB_EXTENDED", wxLB_EXTENDED
},
1753 { "wxLB_NEEDED_SB", wxLB_NEEDED_SB
},
1754 { "wxLB_ALWAYS_SB", wxLB_ALWAYS_SB
},
1755 { "wxLB_SORT", wxLB_SORT
},
1756 { "wxLB_OWNERDRAW", wxLB_OWNERDRAW
},
1757 { "wxLB_HSCROLL", wxLB_HSCROLL
},
1760 { "wxCB_SIMPLE", wxCB_SIMPLE
},
1761 { "wxCB_DROPDOWN", wxCB_DROPDOWN
},
1762 { "wxCB_READONLY", wxCB_READONLY
},
1763 { "wxCB_SORT", wxCB_SORT
},
1766 { "wxGA_PROGRESSBAR", wxGA_PROGRESSBAR
},
1767 { "wxGA_HORIZONTAL", wxGA_HORIZONTAL
},
1768 { "wxGA_VERTICAL", wxGA_VERTICAL
},
1771 { "wxPASSWORD", wxPASSWORD
},
1772 { "wxPROCESS_ENTER", wxPROCESS_ENTER
},
1773 { "wxTE_PASSWORD", wxTE_PASSWORD
},
1774 { "wxTE_READONLY", wxTE_READONLY
},
1775 { "wxTE_PROCESS_ENTER", wxTE_PROCESS_ENTER
},
1776 { "wxTE_MULTILINE", wxTE_MULTILINE
},
1778 /* wxRadioBox/wxRadioButton */
1779 { "wxRB_GROUP", wxRB_GROUP
},
1780 { "wxRA_SPECIFY_COLS", wxRA_SPECIFY_COLS
},
1781 { "wxRA_SPECIFY_ROWS", wxRA_SPECIFY_ROWS
},
1782 { "wxRA_HORIZONTAL", wxRA_HORIZONTAL
},
1783 { "wxRA_VERTICAL", wxRA_VERTICAL
},
1786 { "wxSL_HORIZONTAL", wxSL_HORIZONTAL
},
1787 { "wxSL_VERTICAL", wxSL_VERTICAL
},
1788 { "wxSL_AUTOTICKS", wxSL_AUTOTICKS
},
1789 { "wxSL_LABELS", wxSL_LABELS
},
1790 { "wxSL_LEFT", wxSL_LEFT
},
1791 { "wxSL_TOP", wxSL_TOP
},
1792 { "wxSL_RIGHT", wxSL_RIGHT
},
1793 { "wxSL_BOTTOM", wxSL_BOTTOM
},
1794 { "wxSL_BOTH", wxSL_BOTH
},
1795 { "wxSL_SELRANGE", wxSL_SELRANGE
},
1798 { "wxSB_HORIZONTAL", wxSB_HORIZONTAL
},
1799 { "wxSB_VERTICAL", wxSB_VERTICAL
},
1802 { "wxBU_AUTODRAW", wxBU_AUTODRAW
},
1803 { "wxBU_NOAUTODRAW", wxBU_NOAUTODRAW
},
1806 { "wxTR_HAS_BUTTONS", wxTR_HAS_BUTTONS
},
1807 { "wxTR_EDIT_LABELS", wxTR_EDIT_LABELS
},
1808 { "wxTR_LINES_AT_ROOT", wxTR_LINES_AT_ROOT
},
1811 { "wxLC_ICON", wxLC_ICON
},
1812 { "wxLC_SMALL_ICON", wxLC_SMALL_ICON
},
1813 { "wxLC_LIST", wxLC_LIST
},
1814 { "wxLC_REPORT", wxLC_REPORT
},
1815 { "wxLC_ALIGN_TOP", wxLC_ALIGN_TOP
},
1816 { "wxLC_ALIGN_LEFT", wxLC_ALIGN_LEFT
},
1817 { "wxLC_AUTOARRANGE", wxLC_AUTOARRANGE
},
1818 { "wxLC_USER_TEXT", wxLC_USER_TEXT
},
1819 { "wxLC_EDIT_LABELS", wxLC_EDIT_LABELS
},
1820 { "wxLC_NO_HEADER", wxLC_NO_HEADER
},
1821 { "wxLC_NO_SORT_HEADER", wxLC_NO_SORT_HEADER
},
1822 { "wxLC_SINGLE_SEL", wxLC_SINGLE_SEL
},
1823 { "wxLC_SORT_ASCENDING", wxLC_SORT_ASCENDING
},
1824 { "wxLC_SORT_DESCENDING", wxLC_SORT_DESCENDING
},
1827 { "wxSP_VERTICAL", wxSP_VERTICAL
},
1828 { "wxSP_HORIZONTAL", wxSP_HORIZONTAL
},
1829 { "wxSP_ARROW_KEYS", wxSP_ARROW_KEYS
},
1830 { "wxSP_WRAP", wxSP_WRAP
},
1833 { "wxSP_NOBORDER", wxSP_NOBORDER
},
1834 { "wxSP_3D", wxSP_3D
},
1835 { "wxSP_BORDER", wxSP_BORDER
},
1838 { "wxTC_MULTILINE", wxTC_MULTILINE
},
1839 { "wxTC_RIGHTJUSTIFY", wxTC_RIGHTJUSTIFY
},
1840 { "wxTC_FIXEDWIDTH", wxTC_FIXEDWIDTH
},
1841 { "wxTC_OWNERDRAW", wxTC_OWNERDRAW
},
1844 { "wxST_SIZEGRIP", wxST_SIZEGRIP
},
1847 { "wxFIXED_LENGTH", wxFIXED_LENGTH
},
1848 { "wxALIGN_LEFT", wxALIGN_LEFT
},
1849 { "wxALIGN_CENTER", wxALIGN_CENTER
},
1850 { "wxALIGN_CENTRE", wxALIGN_CENTRE
},
1851 { "wxALIGN_RIGHT", wxALIGN_RIGHT
},
1852 { "wxCOLOURED", wxCOLOURED
},
1855 { "wxTB_3DBUTTONS", wxTB_3DBUTTONS
},
1856 { "wxTB_HORIZONTAL", wxTB_HORIZONTAL
},
1857 { "wxTB_VERTICAL", wxTB_VERTICAL
},
1858 { "wxTB_FLAT", wxTB_FLAT
},
1861 { "wxVSCROLL", wxVSCROLL
},
1862 { "wxHSCROLL", wxHSCROLL
},
1863 { "wxCAPTION", wxCAPTION
},
1864 { "wxSTAY_ON_TOP", wxSTAY_ON_TOP
},
1865 { "wxICONIZE", wxICONIZE
},
1866 { "wxMINIMIZE", wxICONIZE
},
1867 { "wxMAXIMIZE", wxMAXIMIZE
},
1869 { "wxMDI_PARENT", 0},
1870 { "wxMDI_CHILD", 0},
1871 { "wxTHICK_FRAME", wxTHICK_FRAME
},
1872 { "wxRESIZE_BORDER", wxRESIZE_BORDER
},
1873 { "wxSYSTEM_MENU", wxSYSTEM_MENU
},
1874 { "wxMINIMIZE_BOX", wxMINIMIZE_BOX
},
1875 { "wxMAXIMIZE_BOX", wxMAXIMIZE_BOX
},
1876 { "wxRESIZE_BOX", wxRESIZE_BOX
},
1877 { "wxDEFAULT_FRAME_STYLE", wxDEFAULT_FRAME_STYLE
},
1878 { "wxDEFAULT_FRAME", wxDEFAULT_FRAME_STYLE
},
1879 { "wxDEFAULT_DIALOG_STYLE", wxDEFAULT_DIALOG_STYLE
},
1880 { "wxBORDER", wxBORDER
},
1881 { "wxRETAINED", wxRETAINED
},
1882 { "wxNATIVE_IMPL", 0},
1883 { "wxEXTENDED_IMPL", 0},
1884 { "wxBACKINGSTORE", wxBACKINGSTORE
},
1885 // { "wxFLAT", wxFLAT},
1886 // { "wxMOTIF_RESIZE", wxMOTIF_RESIZE},
1887 { "wxFIXED_LENGTH", 0},
1888 { "wxDOUBLE_BORDER", wxDOUBLE_BORDER
},
1889 { "wxSUNKEN_BORDER", wxSUNKEN_BORDER
},
1890 { "wxRAISED_BORDER", wxRAISED_BORDER
},
1891 { "wxSIMPLE_BORDER", wxSIMPLE_BORDER
},
1892 { "wxSTATIC_BORDER", wxSTATIC_BORDER
},
1893 { "wxTRANSPARENT_WINDOW", wxTRANSPARENT_WINDOW
},
1894 { "wxNO_BORDER", wxNO_BORDER
},
1895 { "wxCLIP_CHILDREN", wxCLIP_CHILDREN
},
1897 { "wxTINY_CAPTION_HORIZ", wxTINY_CAPTION_HORIZ
},
1898 { "wxTINY_CAPTION_VERT", wxTINY_CAPTION_VERT
},
1900 // Text font families
1901 { "wxDEFAULT", wxDEFAULT
},
1902 { "wxDECORATIVE", wxDECORATIVE
},
1903 { "wxROMAN", wxROMAN
},
1904 { "wxSCRIPT", wxSCRIPT
},
1905 { "wxSWISS", wxSWISS
},
1906 { "wxMODERN", wxMODERN
},
1907 { "wxTELETYPE", wxTELETYPE
},
1908 { "wxVARIABLE", wxVARIABLE
},
1909 { "wxFIXED", wxFIXED
},
1910 { "wxNORMAL", wxNORMAL
},
1911 { "wxLIGHT", wxLIGHT
},
1912 { "wxBOLD", wxBOLD
},
1913 { "wxITALIC", wxITALIC
},
1914 { "wxSLANT", wxSLANT
},
1915 { "wxSOLID", wxSOLID
},
1917 { "wxLONG_DASH", wxLONG_DASH
},
1918 { "wxSHORT_DASH", wxSHORT_DASH
},
1919 { "wxDOT_DASH", wxDOT_DASH
},
1920 { "wxUSER_DASH", wxUSER_DASH
},
1921 { "wxTRANSPARENT", wxTRANSPARENT
},
1922 { "wxSTIPPLE", wxSTIPPLE
},
1923 { "wxBDIAGONAL_HATCH", wxBDIAGONAL_HATCH
},
1924 { "wxCROSSDIAG_HATCH", wxCROSSDIAG_HATCH
},
1925 { "wxFDIAGONAL_HATCH", wxFDIAGONAL_HATCH
},
1926 { "wxCROSS_HATCH", wxCROSS_HATCH
},
1927 { "wxHORIZONTAL_HATCH", wxHORIZONTAL_HATCH
},
1928 { "wxVERTICAL_HATCH", wxVERTICAL_HATCH
},
1929 { "wxJOIN_BEVEL", wxJOIN_BEVEL
},
1930 { "wxJOIN_MITER", wxJOIN_MITER
},
1931 { "wxJOIN_ROUND", wxJOIN_ROUND
},
1932 { "wxCAP_ROUND", wxCAP_ROUND
},
1933 { "wxCAP_PROJECTING", wxCAP_PROJECTING
},
1934 { "wxCAP_BUTT", wxCAP_BUTT
},
1937 { "wxCLEAR", wxCLEAR
},
1939 { "wxINVERT", wxINVERT
},
1940 { "wxOR_REVERSE", wxOR_REVERSE
},
1941 { "wxAND_REVERSE", wxAND_REVERSE
},
1942 { "wxCOPY", wxCOPY
},
1944 { "wxAND_INVERT", wxAND_INVERT
},
1945 { "wxNO_OP", wxNO_OP
},
1947 { "wxEQUIV", wxEQUIV
},
1948 { "wxSRC_INVERT", wxSRC_INVERT
},
1949 { "wxOR_INVERT", wxOR_INVERT
},
1950 { "wxNAND", wxNAND
},
1954 { "wxFLOOD_SURFACE", wxFLOOD_SURFACE
},
1955 { "wxFLOOD_BORDER", wxFLOOD_BORDER
},
1956 { "wxODDEVEN_RULE", wxODDEVEN_RULE
},
1957 { "wxWINDING_RULE", wxWINDING_RULE
},
1958 { "wxHORIZONTAL", wxHORIZONTAL
},
1959 { "wxVERTICAL", wxVERTICAL
},
1960 { "wxBOTH", wxBOTH
},
1961 { "wxCENTER_FRAME", wxCENTER_FRAME
},
1963 { "wxYES_NO", wxYES_NO
},
1964 { "wxCANCEL", wxCANCEL
},
1967 { "wxICON_EXCLAMATION", wxICON_EXCLAMATION
},
1968 { "wxICON_HAND", wxICON_HAND
},
1969 { "wxICON_QUESTION", wxICON_QUESTION
},
1970 { "wxICON_INFORMATION", wxICON_INFORMATION
},
1971 { "wxICON_STOP", wxICON_STOP
},
1972 { "wxICON_ASTERISK", wxICON_ASTERISK
},
1973 { "wxICON_MASK", wxICON_MASK
},
1974 { "wxCENTRE", wxCENTRE
},
1975 { "wxCENTER", wxCENTRE
},
1976 { "wxUSER_COLOURS", wxUSER_COLOURS
},
1977 { "wxVERTICAL_LABEL", 0},
1978 { "wxHORIZONTAL_LABEL", 0},
1980 // Bitmap types (not strictly styles)
1981 { "wxBITMAP_TYPE_XPM", wxBITMAP_TYPE_XPM
},
1982 { "wxBITMAP_TYPE_XBM", wxBITMAP_TYPE_XBM
},
1983 { "wxBITMAP_TYPE_BMP", wxBITMAP_TYPE_BMP
},
1984 { "wxBITMAP_TYPE_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
},
1985 { "wxBITMAP_TYPE_BMP_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
},
1986 { "wxBITMAP_TYPE_GIF", wxBITMAP_TYPE_GIF
},
1987 { "wxBITMAP_TYPE_TIF", wxBITMAP_TYPE_TIF
},
1988 { "wxBITMAP_TYPE_ICO", wxBITMAP_TYPE_ICO
},
1989 { "wxBITMAP_TYPE_ICO_RESOURCE", wxBITMAP_TYPE_ICO_RESOURCE
},
1990 { "wxBITMAP_TYPE_CUR", wxBITMAP_TYPE_CUR
},
1991 { "wxBITMAP_TYPE_CUR_RESOURCE", wxBITMAP_TYPE_CUR_RESOURCE
},
1992 { "wxBITMAP_TYPE_XBM_DATA", wxBITMAP_TYPE_XBM_DATA
},
1993 { "wxBITMAP_TYPE_XPM_DATA", wxBITMAP_TYPE_XPM_DATA
},
1994 { "wxBITMAP_TYPE_ANY", wxBITMAP_TYPE_ANY
}
1997 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
1999 long wxParseWindowStyle(const wxString
& bitListString
)
2004 while ((word
= wxResourceParseWord((char*) (const char*) bitListString
, &i
)))
2008 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2009 if (strcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2011 bitList
|= wxResourceBitListTable
[j
].bits
;
2017 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word
);
2025 * Load a bitmap from a wxWindows resource, choosing an optimum
2026 * depth and appropriate type.
2029 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
2032 table
= wxDefaultResourceTable
;
2034 wxItemResource
*item
= table
->FindResource(resource
);
2037 if (!item
->GetType() || strcmp(item
->GetType(), "wxBitmap") != 0)
2039 wxLogWarning(_("%s not a bitmap resource specification."), (const char*) resource
);
2040 return wxNullBitmap
;
2042 int thisDepth
= wxDisplayDepth();
2043 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2045 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2047 // Try to find optimum bitmap for this platform/colour depth
2048 wxNode
*node
= item
->GetChildren().First();
2051 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2052 int platform
= (int)child
->GetValue2();
2053 int noColours
= (int)child
->GetValue3();
2055 char *name = child->GetName();
2056 int bitmapType = (int)child->GetValue1();
2057 int xRes = child->GetWidth();
2058 int yRes = child->GetHeight();
2063 case RESOURCE_PLATFORM_ANY
:
2065 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2066 optResource
= child
;
2069 // Maximise the number of colours.
2070 // If noColours is zero (unspecified), then assume this
2071 // is the right one.
2072 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2073 optResource
= child
;
2078 case RESOURCE_PLATFORM_WINDOWS
:
2080 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2081 optResource
= child
;
2084 // Maximise the number of colours
2085 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2086 optResource
= child
;
2092 case RESOURCE_PLATFORM_X
:
2094 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2095 optResource
= child
;
2098 // Maximise the number of colours
2099 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2100 optResource
= child
;
2106 case RESOURCE_PLATFORM_MAC
:
2108 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2109 optResource
= child
;
2112 // Maximise the number of colours
2113 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2114 optResource
= child
;
2122 node
= node
->Next();
2124 // If no matching resource, fail.
2126 return wxNullBitmap
;
2128 wxString name
= optResource
->GetName();
2129 int bitmapType
= (int)optResource
->GetValue1();
2132 case wxBITMAP_TYPE_XBM_DATA
:
2135 wxItemResource
*item
= table
->FindResource(name
);
2138 wxLogWarning(_("Failed to find XBM resource %s.\n"
2139 "Forgot to use wxResourceLoadBitmapData?"), (const char*) name
);
2140 return wxNullBitmap
;
2142 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2144 wxLogWarning(_("No XBM facility available!"));
2148 case wxBITMAP_TYPE_XPM_DATA
:
2150 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2151 wxItemResource
*item
= table
->FindResource(name
);
2154 wxLogWarning(_("Failed to find XPM resource %s.\n"
2155 "Forgot to use wxResourceLoadBitmapData?"), (const char*) name
);
2156 return wxNullBitmap
;
2158 return wxBitmap(item
->GetValue1());
2160 wxLogWarning(_("No XPM facility available!"));
2166 return wxBitmap(name
, bitmapType
);
2170 return wxNullBitmap
;
2174 wxLogWarning(_("Bitmap resource specification %s not found."), (const char*) resource
);
2175 return wxNullBitmap
;
2180 * Load an icon from a wxWindows resource, choosing an optimum
2181 * depth and appropriate type.
2184 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2187 table
= wxDefaultResourceTable
;
2189 wxItemResource
*item
= table
->FindResource(resource
);
2192 if ((item
->GetType() == "") || strcmp(item
->GetType(), "wxIcon") != 0)
2194 wxLogWarning(_("%s not an icon resource specification."), (const char*) resource
);
2197 int thisDepth
= wxDisplayDepth();
2198 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2200 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2202 // Try to find optimum icon for this platform/colour depth
2203 wxNode
*node
= item
->GetChildren().First();
2206 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2207 int platform
= (int)child
->GetValue2();
2208 int noColours
= (int)child
->GetValue3();
2210 char *name = child->GetName();
2211 int bitmapType = (int)child->GetValue1();
2212 int xRes = child->GetWidth();
2213 int yRes = child->GetHeight();
2218 case RESOURCE_PLATFORM_ANY
:
2220 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2221 optResource
= child
;
2224 // Maximise the number of colours.
2225 // If noColours is zero (unspecified), then assume this
2226 // is the right one.
2227 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2228 optResource
= child
;
2233 case RESOURCE_PLATFORM_WINDOWS
:
2235 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2236 optResource
= child
;
2239 // Maximise the number of colours
2240 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2241 optResource
= child
;
2247 case RESOURCE_PLATFORM_X
:
2249 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2250 optResource
= child
;
2253 // Maximise the number of colours
2254 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2255 optResource
= child
;
2261 case RESOURCE_PLATFORM_MAC
:
2263 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2264 optResource
= child
;
2267 // Maximise the number of colours
2268 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2269 optResource
= child
;
2277 node
= node
->Next();
2279 // If no matching resource, fail.
2283 wxString name
= optResource
->GetName();
2284 int bitmapType
= (int)optResource
->GetValue1();
2287 case wxBITMAP_TYPE_XBM_DATA
:
2290 wxItemResource
*item
= table
->FindResource(name
);
2293 wxLogWarning(_("Failed to find XBM resource %s.\n"
2294 "Forgot to use wxResourceLoadIconData?"), (const char*) name
);
2297 return wxIcon((const char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2299 wxLogWarning(_("No XBM facility available!"));
2303 case wxBITMAP_TYPE_XPM_DATA
:
2305 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2307 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2308 wxItemResource *item = table->FindResource(name);
2312 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2316 return wxIcon((char **)item->GetValue1());
2318 wxLogWarning(_("No XPM facility available!"));
2321 wxLogWarning(_("No XPM icon facility available!"));
2327 wxLogWarning(_("Icon resource specification %s not found."), (const char*) resource
);
2329 return wxIcon(name
, bitmapType
);
2338 wxLogWarning(_("Icon resource specification %s not found."), (const char*) resource
);
2343 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2345 wxMenu
*menu
= new wxMenu
;
2346 wxNode
*node
= item
->GetChildren().First();
2349 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2350 if ((child
->GetType() != "") && (child
->GetType() == "wxMenuSeparator"))
2351 menu
->AppendSeparator();
2352 else if (child
->GetChildren().Number() > 0)
2354 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2356 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2360 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2362 node
= node
->Next();
2367 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2370 table
= wxDefaultResourceTable
;
2372 wxItemResource
*menuResource
= table
->FindResource(resource
);
2373 if (menuResource
&& (menuResource
->GetType() != "") && (menuResource
->GetType() == "wxMenu"))
2376 menuBar
= new wxMenuBar
;
2377 wxNode
*node
= menuResource
->GetChildren().First();
2380 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2381 wxMenu
*menu
= wxResourceCreateMenu(child
);
2383 menuBar
->Append(menu
, child
->GetTitle());
2384 node
= node
->Next();
2388 return (wxMenuBar
*) NULL
;
2391 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2394 table
= wxDefaultResourceTable
;
2396 wxItemResource
*menuResource
= table
->FindResource(resource
);
2397 if (menuResource
&& (menuResource
->GetType() != "") && (menuResource
->GetType() == "wxMenu"))
2398 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2399 return wxResourceCreateMenu(menuResource
);
2400 return (wxMenu
*) NULL
;
2403 // Global equivalents (so don't have to refer to default table explicitly)
2404 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2407 table
= wxDefaultResourceTable
;
2409 return table
->ParseResourceData(resource
);
2412 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2415 table
= wxDefaultResourceTable
;
2417 return table
->ParseResourceFile(filename
);
2420 // Register XBM/XPM data
2421 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2424 table
= wxDefaultResourceTable
;
2426 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2429 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2432 table
= wxDefaultResourceTable
;
2434 return table
->RegisterResourceBitmapData(name
, data
);
2437 void wxResourceClear(wxResourceTable
*table
)
2440 table
= wxDefaultResourceTable
;
2442 table
->ClearTable();
2449 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2452 table
= wxDefaultResourceTable
;
2454 table
->identifiers
.Put(name
, (wxObject
*)value
);
2458 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2461 table
= wxDefaultResourceTable
;
2463 return (int)table
->identifiers
.Get(name
);
2467 * Parse #include file for #defines (only)
2470 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2473 table
= wxDefaultResourceTable
;
2475 FILE *fd
= fopen(f
, "r");
2480 while (wxGetResourceToken(fd
))
2482 if (strcmp(wxResourceBuffer
, "#define") == 0)
2484 wxGetResourceToken(fd
);
2485 char *name
= copystring(wxResourceBuffer
);
2486 wxGetResourceToken(fd
);
2487 char *value
= copystring(wxResourceBuffer
);
2488 if (isdigit(value
[0]))
2490 int val
= (int)atol(value
);
2491 wxResourceAddIdentifier(name
, val
, table
);
2502 * Reading strings as if they were .wxr files
2505 static int getc_string(char *s
)
2507 int ch
= s
[wxResourceStringPtr
];
2512 wxResourceStringPtr
++;
2517 static int ungetc_string()
2519 wxResourceStringPtr
--;
2523 bool wxEatWhiteSpaceString(char *s
)
2525 int ch
= getc_string(s
);
2529 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
2536 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
2537 ch
= getc_string(s
);
2538 // Check for comment
2541 ch
= getc_string(s
);
2544 bool finished
= FALSE
;
2547 ch
= getc_string(s
);
2552 int newCh
= getc_string(s
);
2567 return wxEatWhiteSpaceString(s
);
2570 bool wxGetResourceTokenString(char *s
)
2572 if (!wxResourceBuffer
)
2573 wxReallocateResourceBuffer();
2574 wxResourceBuffer
[0] = 0;
2575 wxEatWhiteSpaceString(s
);
2577 int ch
= getc_string(s
);
2581 wxResourceBufferCount
= 0;
2582 ch
= getc_string(s
);
2588 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2591 // Escaped characters
2592 else if (ch
== '\\')
2594 int newCh
= getc_string(s
);
2597 else if (newCh
== 10)
2605 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2606 wxReallocateResourceBuffer();
2607 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2608 wxResourceBufferCount
++;
2609 ch
= getc_string(s
);
2611 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2615 wxResourceBufferCount
= 0;
2617 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2619 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2620 wxReallocateResourceBuffer();
2621 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2622 wxResourceBufferCount
++;
2624 ch
= getc_string(s
);
2626 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2634 * Files are in form:
2635 static char *name = "....";
2636 with possible comments.
2639 bool wxResourceReadOneResourceString(char *s
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2642 table
= wxDefaultResourceTable
;
2644 // static or #define
2645 if (!wxGetResourceTokenString(s
))
2651 if (strcmp(wxResourceBuffer
, "#define") == 0)
2653 wxGetResourceTokenString(s
);
2654 char *name
= copystring(wxResourceBuffer
);
2655 wxGetResourceTokenString(s
);
2656 char *value
= copystring(wxResourceBuffer
);
2657 if (isalpha(value
[0]))
2659 int val
= (int)atol(value
);
2660 wxResourceAddIdentifier(name
, val
, table
);
2664 wxLogWarning(_("#define %s must be an integer."), name
);
2675 else if (strcmp(wxResourceBuffer, "#include") == 0)
2677 wxGetResourceTokenString(s);
2678 char *name = copystring(wxResourceBuffer);
2679 char *actualName = name;
2681 actualName = name + 1;
2682 int len = strlen(name);
2683 if ((len > 0) && (name[len-1] == '"'))
2685 if (!wxResourceParseIncludeFile(actualName, table))
2688 sprintf(buf, _("Could not find resource include file %s."), actualName);
2695 else if (strcmp(wxResourceBuffer
, "static") != 0)
2698 strcpy(buf
, _("Found "));
2699 strncat(buf
, wxResourceBuffer
, 30);
2700 strcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
2706 if (!wxGetResourceTokenString(s
))
2708 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2713 if (strcmp(wxResourceBuffer
, "char") != 0)
2715 wxLogWarning(_("Expected 'char' whilst parsing resource."));
2720 if (!wxGetResourceTokenString(s
))
2722 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2727 if (wxResourceBuffer
[0] != '*')
2729 wxLogWarning(_("Expected '*' whilst parsing resource."));
2733 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
2736 if (!wxGetResourceTokenString(s
))
2738 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2743 if (strcmp(wxResourceBuffer
, "=") != 0)
2745 wxLogWarning(_("Expected '=' whilst parsing resource."));
2750 if (!wxGetResourceTokenString(s
))
2752 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2758 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2760 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2765 if (!wxGetResourceTokenString(s
))
2772 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
2775 table
= wxDefaultResourceTable
;
2780 // Turn backslashes into spaces
2783 int len
= strlen(s
);
2785 for (i
= 0; i
< len
; i
++)
2786 if (s
[i
] == 92 && s
[i
+1] == 13)
2794 wxResourceStringPtr
= 0;
2797 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
2801 return wxResourceInterpretResources(*table
, db
);
2805 * resource loading facility
2808 bool wxWindow::LoadFromResource(wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
2811 table
= wxDefaultResourceTable
;
2813 wxItemResource
*resource
= table
->FindResource((const char *)resourceName
);
2814 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
2815 if (!resource
|| !resource
->GetType() ||
2816 ! ((strcmp(resource
->GetType(), "wxDialog") == 0) || (strcmp(resource
->GetType(), "wxPanel") == 0)))
2819 wxString
title(resource
->GetTitle());
2820 long theWindowStyle
= resource
->GetStyle();
2821 bool isModal
= (resource
->GetValue1() != 0);
2822 int x
= resource
->GetX();
2823 int y
= resource
->GetY();
2824 int width
= resource
->GetWidth();
2825 int height
= resource
->GetHeight();
2826 wxString name
= resource
->GetName();
2828 if (IsKindOf(CLASSINFO(wxDialog
)))
2830 wxDialog
*dialogBox
= (wxDialog
*)this;
2831 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
2832 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
2835 // Only reset the client size if we know we're not going to do it again below.
2836 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == 0)
2837 dialogBox
->SetClientSize(width
, height
);
2839 else if (IsKindOf(CLASSINFO(wxPanel
)))
2841 wxPanel
* panel
= (wxPanel
*)this;
2842 if (!panel
->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2847 if (!this->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2851 if ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
2853 // No need to do this since it's done in wxPanel or wxDialog constructor.
2854 // SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
2858 if (resource
->GetFont().Ok())
2859 SetFont(resource
->GetFont());
2860 if (resource
->GetBackgroundColour().Ok())
2861 SetBackgroundColour(resource
->GetBackgroundColour());
2864 // Should have some kind of font at this point
2865 if (!GetFont().Ok())
2866 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
2867 if (!GetBackgroundColour().Ok())
2868 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
2870 // Only when we've created the window and set the font can we set the correct size,
2871 // if based on dialog units.
2872 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
2874 wxSize sz
= ConvertDialogToPixels(wxSize(width
, height
));
2875 SetClientSize(sz
.x
, sz
.y
);
2877 wxPoint pt
= ConvertDialogToPixels(wxPoint(x
, y
));
2881 // Now create children
2882 wxNode
*node
= resource
->GetChildren().First();
2885 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
2887 (void) CreateItem(childResource
, resource
, table
);
2889 node
= node
->Next();
2894 wxControl
*wxWindow::CreateItem(const wxItemResource
*resource
, const wxItemResource
* parentResource
, const wxResourceTable
*table
)
2897 table
= wxDefaultResourceTable
;
2898 return table
->CreateItem((wxWindow
*)this, resource
, parentResource
);
2902 #pragma warning(default:4706) // assignment within conditional expression
2908 #endif // wxUSE_WX_RESOURCES