1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Resource system
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "resource.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #if wxUSE_WX_RESOURCES
26 #pragma warning(disable:4706) // assignment within conditional expression
34 #include "wx/gdicmn.h"
38 #include "wx/stattext.h"
39 #include "wx/button.h"
40 #include "wx/bmpbuttn.h"
41 #include "wx/radiobox.h"
42 #include "wx/radiobut.h"
43 #include "wx/listbox.h"
44 #include "wx/choice.h"
45 #include "wx/checkbox.h"
46 #include "wx/settings.h"
47 #include "wx/slider.h"
48 #include "wx/statbox.h"
49 #include "wx/statbmp.h"
53 #include "wx/textctrl.h"
54 #include "wx/msgdlg.h"
59 #include "wx/radiobut.h"
63 #include "wx/scrolbar.h"
67 #include "wx/combobox.h"
70 #include "wx/validate.h"
79 #include "wx/resource.h"
80 #include "wx/string.h"
81 #include "wx/wxexpr.h"
83 #include "wx/settings.h"
85 // Forward (private) declarations
86 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
);
87 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
= FALSE
);
88 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
);
89 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
);
90 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
);
91 wxItemResource
*wxResourceInterpretString(wxResourceTable
& table
, wxExpr
*expr
);
92 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& table
, wxExpr
*expr
);
93 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
);
94 // Interpret list expression
95 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
);
97 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
98 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
100 wxResourceTable
*wxDefaultResourceTable
= (wxResourceTable
*) NULL
;
102 char *wxResourceBuffer
= (char *) NULL
;
103 long wxResourceBufferSize
= 0;
104 long wxResourceBufferCount
= 0;
105 int wxResourceStringPtr
= 0;
107 void wxInitializeResourceSystem()
109 wxDefaultResourceTable
= new wxResourceTable
;
112 void wxCleanUpResourceSystem()
114 delete wxDefaultResourceTable
;
115 if (wxResourceBuffer
)
116 delete[] wxResourceBuffer
;
119 void wxLogWarning(char *msg
)
121 wxMessageBox(msg
, _("Warning"), wxOK
);
124 #if !USE_SHARED_LIBRARY
125 IMPLEMENT_DYNAMIC_CLASS(wxItemResource
, wxObject
)
126 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable
, wxHashTable
)
129 wxItemResource::wxItemResource()
135 m_x
= m_y
= m_width
= m_height
= 0;
136 m_value1
= m_value2
= m_value3
= m_value5
= 0;
142 wxItemResource::~wxItemResource()
144 wxNode
*node
= m_children
.First();
147 wxItemResource
*item
= (wxItemResource
*)node
->Data();
150 node
= m_children
.First();
158 wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
)
162 wxResourceTable::~wxResourceTable()
167 wxItemResource
*wxResourceTable::FindResource(const wxString
& name
) const
169 wxItemResource
*item
= (wxItemResource
*)Get((char *)(const char *)name
);
173 void wxResourceTable::AddResource(wxItemResource
*item
)
175 wxString name
= item
->GetName();
177 name
= item
->GetTitle();
181 // Delete existing resource, if any.
187 bool wxResourceTable::DeleteResource(const wxString
& name
)
189 wxItemResource
*item
= (wxItemResource
*)Delete((char *)(const char *)name
);
192 // See if any resource has this as its child; if so, delete from
193 // parent's child list.
195 wxNode
*node
= (wxNode
*) NULL
;
196 while ((node
= Next()))
198 wxItemResource
*parent
= (wxItemResource
*)node
->Data();
199 if (parent
->GetChildren().Member(item
))
201 parent
->GetChildren().DeleteObject(item
);
213 bool wxResourceTable::ParseResourceFile(const wxString
& filename
)
217 FILE *fd
= fopen((const char*) filename
, "r");
221 while (wxResourceReadOneResource(fd
, db
, &eof
, this) && !eof
)
226 return wxResourceInterpretResources(*this, db
);
229 bool wxResourceTable::ParseResourceData(const wxString
& data
)
232 if (!db
.ReadFromString(data
))
234 wxLogWarning(_("Ill-formed resource file syntax."));
238 return wxResourceInterpretResources(*this, db
);
241 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char bits
[], int width
, int height
)
243 // Register pre-loaded bitmap data
244 wxItemResource
*item
= new wxItemResource
;
245 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
246 item
->SetType("wxXBMData");
248 item
->SetValue1((long)bits
);
249 item
->SetValue2((long)width
);
250 item
->SetValue3((long)height
);
255 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char **data
)
257 // Register pre-loaded bitmap data
258 wxItemResource
*item
= new wxItemResource
;
259 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
260 item
->SetType("wxXPMData");
262 item
->SetValue1((long)data
);
267 bool wxResourceTable::SaveResource(const wxString
& WXUNUSED(filename
))
272 void wxResourceTable::ClearTable()
275 wxNode
*node
= Next();
278 wxNode
*next
= Next();
279 wxItemResource
*item
= (wxItemResource
*)node
->Data();
286 wxControl
*wxResourceTable::CreateItem(wxWindow
*parent
, const wxItemResource
* childResource
, const wxItemResource
* parentResource
) const
288 int id
= childResource
->GetId();
292 bool dlgUnits
= ((parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0);
294 wxControl
*control
= (wxControl
*) NULL
;
295 wxString
itemType(childResource
->GetType());
301 pos
= parent
->ConvertDialogToPixels(wxPoint(childResource
->GetX(), childResource
->GetY()));
302 size
= parent
->ConvertDialogToPixels(wxSize(childResource
->GetWidth(), childResource
->GetHeight()));
306 pos
= wxPoint(childResource
->GetX(), childResource
->GetY());
307 size
= wxSize(childResource
->GetWidth(), childResource
->GetHeight());
310 if (itemType
== wxString("wxButton") || itemType
== wxString("wxBitmapButton"))
312 if (childResource
->GetValue4() != "")
315 wxBitmap bitmap
= childResource
->GetBitmap();
318 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
319 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
322 control
= new wxBitmapButton(parent
, id
, bitmap
, pos
, size
,
323 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
326 // Normal, text button
327 control
= new wxButton(parent
, id
, childResource
->GetTitle(), pos
, size
,
328 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
330 else if (itemType
== wxString("wxMessage") || itemType
== wxString("wxStaticText") ||
331 itemType
== wxString("wxStaticBitmap"))
333 if (childResource
->GetValue4() != "")
336 wxBitmap bitmap
= childResource
->GetBitmap();
339 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
340 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
342 #if wxUSE_BITMAP_MESSAGE
344 control
= new wxStaticBitmap(parent
, id
, bitmap
, pos
, size
,
345 childResource
->GetStyle(), childResource
->GetName());
350 control
= new wxStaticText(parent
, id
, childResource
->GetTitle(), pos
, size
,
351 childResource
->GetStyle(), childResource
->GetName());
354 else if (itemType
== wxString("wxText") || itemType
== wxString("wxTextCtrl") || itemType
== wxString("wxMultiText"))
356 control
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(), pos
, size
,
357 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
359 else if (itemType
== wxString("wxCheckBox"))
361 control
= new wxCheckBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
362 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
364 ((wxCheckBox
*)control
)->SetValue((childResource
->GetValue1() != 0));
367 else if (itemType
== wxString("wxGauge"))
369 control
= new wxGauge(parent
, id
, (int)childResource
->GetValue2(), pos
, size
,
370 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
372 ((wxGauge
*)control
)->SetValue((int)childResource
->GetValue1());
375 #if wxUSE_RADIOBUTTON
376 else if (itemType
== wxString("wxRadioButton"))
378 control
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(),
380 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
384 else if (itemType
== wxString("wxScrollBar"))
386 control
= new wxScrollBar(parent
, id
, pos
, size
,
387 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
389 ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1());
390 ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2());
391 ((wxScrollBar *)control)->SetObjectLength((int)childResource->GetValue3());
392 ((wxScrollBar *)control)->SetViewLength((int)(long)childResource->GetValue5());
394 ((wxScrollBar
*)control
)->SetScrollbar((int)childResource
->GetValue1(),(int)childResource
->GetValue2(),
395 (int)childResource
->GetValue3(),(int)(long)childResource
->GetValue5(),FALSE
);
399 else if (itemType
== wxString("wxSlider"))
401 control
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(),
402 (int)childResource
->GetValue2(), (int)childResource
->GetValue3(), pos
, size
,
403 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
405 else if (itemType
== wxString("wxGroupBox") || itemType
== wxString("wxStaticBox"))
407 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
408 childResource
->GetStyle(), childResource
->GetName());
410 else if (itemType
== wxString("wxListBox"))
412 wxStringList
& stringList
= childResource
->GetStringValues();
413 wxString
*strings
= (wxString
*) NULL
;
415 if (stringList
.Number() > 0)
417 noStrings
= stringList
.Number();
418 strings
= new wxString
[noStrings
];
419 wxNode
*node
= stringList
.First();
423 strings
[i
] = (char *)node
->Data();
428 control
= new wxListBox(parent
, id
, pos
, size
,
429 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
434 else if (itemType
== wxString("wxChoice"))
436 wxStringList
& stringList
= childResource
->GetStringValues();
437 wxString
*strings
= (wxString
*) NULL
;
439 if (stringList
.Number() > 0)
441 noStrings
= stringList
.Number();
442 strings
= new wxString
[noStrings
];
443 wxNode
*node
= stringList
.First();
447 strings
[i
] = (char *)node
->Data();
452 control
= new wxChoice(parent
, id
, pos
, size
,
453 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
459 else if (itemType
== wxString("wxComboBox"))
461 wxStringList
& stringList
= childResource
->GetStringValues();
462 wxString
*strings
= (wxString
*) NULL
;
464 if (stringList
.Number() > 0)
466 noStrings
= stringList
.Number();
467 strings
= new wxString
[noStrings
];
468 wxNode
*node
= stringList
.First();
472 strings
[i
] = (char *)node
->Data();
477 control
= new wxComboBox(parent
, id
, childResource
->GetValue4(), pos
, size
,
478 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
484 else if (itemType
== wxString("wxRadioBox"))
486 wxStringList
& stringList
= childResource
->GetStringValues();
487 wxString
*strings
= (wxString
*) NULL
;
489 if (stringList
.Number() > 0)
491 noStrings
= stringList
.Number();
492 strings
= new wxString
[noStrings
];
493 wxNode
*node
= stringList
.First();
497 strings
[i
] = (char *)node
->Data();
502 control
= new wxRadioBox(parent
, (wxWindowID
) id
, wxString(childResource
->GetTitle()), pos
, size
,
503 noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
,
504 childResource
->GetName());
510 if ((parentResource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
512 // Don't set font; will be inherited from parent.
516 if (control
&& childResource
->GetFont().Ok())
517 control
->SetFont(childResource
->GetFont());
523 * Interpret database as a series of resources
526 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
)
528 wxNode
*node
= db
.First();
531 wxExpr
*clause
= (wxExpr
*)node
->Data();
532 wxString
functor(clause
->Functor());
534 wxItemResource
*item
= (wxItemResource
*) NULL
;
535 if (functor
== "dialog")
536 item
= wxResourceInterpretDialog(table
, clause
);
537 else if (functor
== "panel")
538 item
= wxResourceInterpretDialog(table
, clause
, TRUE
);
539 else if (functor
== "menubar")
540 item
= wxResourceInterpretMenuBar(table
, clause
);
541 else if (functor
== "menu")
542 item
= wxResourceInterpretMenu(table
, clause
);
543 else if (functor
== "string")
544 item
= wxResourceInterpretString(table
, clause
);
545 else if (functor
== "bitmap")
546 item
= wxResourceInterpretBitmap(table
, clause
);
547 else if (functor
== "icon")
548 item
= wxResourceInterpretIcon(table
, clause
);
552 // Remove any existing resource of same name
553 if (item
->GetName() != "")
554 table
.DeleteResource(item
->GetName());
555 table
.AddResource(item
);
562 static char *g_ValidControlClasses
[] = { "wxButton", "wxBitmapButton", "wxMessage",
563 "wxStaticText", "wxStaticBitmap", "wxText", "wxTextCtrl", "wxMultiText",
564 "wxListBox", "wxRadioBox", "wxRadioButton", "wxCheckBox", "wxBitmapCheckBox",
565 "wxGroupBox", "wxStaticBox", "wxSlider", "wxGauge", "wxScrollBar",
566 "wxChoice", "wxComboBox" } ;
567 static int g_ValidControlClassesCount
= sizeof(g_ValidControlClasses
) / sizeof(char *) ;
569 static bool wxIsValidControlClass(const wxString
& c
)
572 for ( i
= 0; i
< g_ValidControlClassesCount
; i
++)
574 if ( c
== g_ValidControlClasses
[i
] )
580 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
)
582 wxItemResource
*dialogItem
= new wxItemResource
;
584 dialogItem
->SetType("wxPanel");
586 dialogItem
->SetType("wxDialog");
590 wxString backColourHex
= "";
591 wxString labelColourHex
= "";
592 wxString buttonColourHex
= "";
594 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
598 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
600 wxExpr
*labelFontExpr
= (wxExpr
*) NULL
;
601 wxExpr
*buttonFontExpr
= (wxExpr
*) NULL
;
602 wxExpr
*fontExpr
= (wxExpr
*) NULL
;
603 expr
->GetAttributeValue("style", style
);
604 expr
->GetAttributeValue("name", name
);
605 expr
->GetAttributeValue("title", title
);
606 expr
->GetAttributeValue("x", x
);
607 expr
->GetAttributeValue("y", y
);
608 expr
->GetAttributeValue("width", width
);
609 expr
->GetAttributeValue("height", height
);
610 expr
->GetAttributeValue("modal", isModal
);
611 expr
->GetAttributeValue("label_font", &labelFontExpr
);
612 expr
->GetAttributeValue("button_font", &buttonFontExpr
);
613 expr
->GetAttributeValue("font", &fontExpr
);
614 expr
->GetAttributeValue("background_colour", backColourHex
);
615 expr
->GetAttributeValue("label_colour", labelColourHex
);
616 expr
->GetAttributeValue("button_colour", buttonColourHex
);
618 int useDialogUnits
= 0;
619 expr
->GetAttributeValue("use_dialog_units", useDialogUnits
);
620 if (useDialogUnits
!= 0)
621 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS
);
624 expr
->GetAttributeValue("use_system_defaults", useDefaults
);
625 if (useDefaults
!= 0)
626 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS
);
629 expr
->GetAttributeValue("id", id
);
630 dialogItem
->SetId(id
);
634 windowStyle
= wxParseWindowStyle(style
);
636 dialogItem
->SetStyle(windowStyle
);
637 dialogItem
->SetValue1(isModal
);
638 dialogItem
->SetName(name
);
639 dialogItem
->SetTitle(title
);
640 dialogItem
->SetSize(x
, y
, width
, height
);
642 if (backColourHex
!= "")
647 r
= wxHexToDec(backColourHex
.Mid(0, 2));
648 g
= wxHexToDec(backColourHex
.Mid(2, 2));
649 b
= wxHexToDec(backColourHex
.Mid(4, 2));
650 dialogItem
->SetBackgroundColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
652 if (labelColourHex
!= "")
657 r
= wxHexToDec(labelColourHex
.Mid(0, 2));
658 g
= wxHexToDec(labelColourHex
.Mid(2, 2));
659 b
= wxHexToDec(labelColourHex
.Mid(4, 2));
660 dialogItem
->SetLabelColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
662 if (buttonColourHex
!= "")
667 r
= wxHexToDec(buttonColourHex
.Mid(0, 2));
668 g
= wxHexToDec(buttonColourHex
.Mid(2, 2));
669 b
= wxHexToDec(buttonColourHex
.Mid(4, 2));
670 dialogItem
->SetButtonColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
674 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
675 else if (buttonFontExpr
)
676 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
677 else if (labelFontExpr
)
678 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
680 // Now parse all controls
681 wxExpr
*controlExpr
= expr
->GetFirst();
684 if (controlExpr
->Number() == 3)
686 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
687 if (controlKeyword
!= "" && controlKeyword
== "control")
689 // The value part: always a list.
690 wxExpr
*listExpr
= controlExpr
->Nth(2);
691 if (listExpr
->Type() == PrologList
)
693 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
696 dialogItem
->GetChildren().Append(controlItem
);
701 controlExpr
= controlExpr
->GetNext();
706 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
)
708 wxItemResource
*controlItem
= new wxItemResource
;
710 // First, find the standard features of a control definition:
711 // [optional integer/string id], control name, title, style, name, x, y, width, height
713 wxString controlType
;
718 long windowStyle
= 0;
719 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
722 wxExpr
*expr1
= expr
->Nth(0);
724 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
726 if ( wxIsValidControlClass(expr1
->StringValue()) )
729 controlType
= expr1
->StringValue();
733 wxString
str(expr1
->StringValue());
734 id
= wxResourceGetIdentifier(str
, &table
);
737 wxLogWarning(_("Could not resolve control class or id '%s'. "
738 "Use (non-zero) integer instead\n or provide #define "
739 "(see manual for caveats)"),
740 (const char*) expr1
->StringValue());
742 return (wxItemResource
*) NULL
;
746 // Success - we have an id, so the 2nd element must be the control class.
747 controlType
= expr
->Nth(1)->StringValue();
752 else if (expr1
->Type() == PrologInteger
)
754 id
= (int)expr1
->IntegerValue();
755 // Success - we have an id, so the 2nd element must be the control class.
756 controlType
= expr
->Nth(1)->StringValue();
760 expr1
= expr
->Nth(count
);
763 title
= expr1
->StringValue();
765 expr1
= expr
->Nth(count
);
769 style
= expr1
->StringValue();
770 windowStyle
= wxParseWindowStyle(style
);
773 expr1
= expr
->Nth(count
);
776 name
= expr1
->StringValue();
778 expr1
= expr
->Nth(count
);
781 x
= (int)expr1
->IntegerValue();
783 expr1
= expr
->Nth(count
);
786 y
= (int)expr1
->IntegerValue();
788 expr1
= expr
->Nth(count
);
791 width
= (int)expr1
->IntegerValue();
793 expr1
= expr
->Nth(count
);
796 height
= (int)expr1
->IntegerValue();
798 controlItem
->SetStyle(windowStyle
);
799 controlItem
->SetName(name
);
800 controlItem
->SetTitle(title
);
801 controlItem
->SetSize(x
, y
, width
, height
);
802 controlItem
->SetType(controlType
);
803 controlItem
->SetId(id
);
805 if (controlType
== "wxButton")
807 // Check for bitmap resource name (in case loading old-style resource file)
808 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
810 wxString
str(expr
->Nth(count
)->StringValue());
811 controlItem
->SetValue4(str
);
813 controlItem
->SetType("wxBitmapButton");
815 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
816 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
818 else if (controlType
== "wxBitmapButton")
820 // Check for bitmap resource name
821 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
823 wxString
str(expr
->Nth(count
)->StringValue());
824 controlItem
->SetValue4(str
);
826 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
827 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
830 else if (controlType
== "wxCheckBox")
832 // Check for default value
833 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
835 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
837 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
838 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
841 #if wxUSE_RADIOBUTTON
842 else if (controlType
== "wxRadioButton")
844 // Check for default value
845 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
847 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
849 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
850 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
854 else if (controlType
== "wxText" || controlType
== "wxTextCtrl" || controlType
== "wxMultiText")
856 // Check for default value
857 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
859 wxString
str(expr
->Nth(count
)->StringValue());
860 controlItem
->SetValue4(str
);
863 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
865 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
866 // Do nothing - no label font any more
868 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
869 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
873 else if (controlType
== "wxMessage" || controlType
== "wxStaticText")
875 // Check for bitmap resource name (in case it's an old-style .wxr file)
876 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
878 wxString
str(expr
->Nth(count
)->StringValue());
879 controlItem
->SetValue4(str
);
881 controlItem
->SetType("wxStaticText");
883 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
884 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
886 else if (controlType
== "wxStaticBitmap")
888 // Check for bitmap resource name
889 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
891 wxString
str(expr
->Nth(count
)->StringValue());
892 controlItem
->SetValue4(str
);
895 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
896 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
898 else if (controlType
== "wxGroupBox" || controlType
== "wxStaticBox")
900 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
901 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
903 else if (controlType
== "wxGauge")
905 // Check for default value
906 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
908 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
912 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
914 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
917 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
919 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
923 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
924 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
929 else if (controlType
== "wxSlider")
931 // Check for default value
932 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
934 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
938 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
940 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
944 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
946 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
949 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
951 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
955 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
956 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
962 else if (controlType
== "wxScrollBar")
965 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
967 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
971 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
973 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
977 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
979 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
983 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
984 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
989 else if (controlType
== "wxListBox")
991 wxExpr
*valueList
= (wxExpr
*) NULL
;
993 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
995 wxStringList stringList
;
996 wxExpr
*stringExpr
= valueList
->GetFirst();
999 stringList
.Add(stringExpr
->StringValue());
1000 stringExpr
= stringExpr
->GetNext();
1002 controlItem
->SetStringValues(stringList
);
1004 // This is now obsolete: it's in the window style.
1005 // Check for wxSINGLE/wxMULTIPLE
1006 wxExpr
*mult
= (wxExpr
*) NULL
;
1008 controlItem->SetValue1(wxLB_SINGLE);
1010 if ((mult
= expr
->Nth(count
)) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1013 wxString m(mult->StringValue());
1014 if (m == "wxLB_MULTIPLE")
1015 controlItem->SetValue1(wxLB_MULTIPLE);
1016 else if (m == "wxLB_EXTENDED")
1017 controlItem->SetValue1(wxLB_EXTENDED);
1022 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1024 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1026 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1027 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1031 else if (controlType
== "wxChoice")
1033 wxExpr
*valueList
= (wxExpr
*) NULL
;
1034 // Check for default value list
1035 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1037 wxStringList stringList
;
1038 wxExpr
*stringExpr
= valueList
->GetFirst();
1041 stringList
.Add(stringExpr
->StringValue());
1042 stringExpr
= stringExpr
->GetNext();
1044 controlItem
->SetStringValues(stringList
);
1048 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1050 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1053 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1054 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1059 else if (controlType
== "wxComboBox")
1061 wxExpr
*textValue
= expr
->Nth(count
);
1062 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1064 wxString
str(textValue
->StringValue());
1065 controlItem
->SetValue4(str
);
1069 wxExpr
*valueList
= (wxExpr
*) NULL
;
1070 // Check for default value list
1071 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1073 wxStringList stringList
;
1074 wxExpr
*stringExpr
= valueList
->GetFirst();
1077 stringList
.Add(stringExpr
->StringValue());
1078 stringExpr
= stringExpr
->GetNext();
1080 controlItem
->SetStringValues(stringList
);
1084 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1086 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1089 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1090 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1097 else if (controlType
== "wxRadioBox")
1099 wxExpr
*valueList
= (wxExpr
*) NULL
;
1100 // Check for default value list
1101 if ((valueList
= expr
->Nth(count
)) && (valueList
->Type() == PrologList
))
1103 wxStringList stringList
;
1104 wxExpr
*stringExpr
= valueList
->GetFirst();
1107 stringList
.Add(stringExpr
->StringValue());
1108 stringExpr
= stringExpr
->GetNext();
1110 controlItem
->SetStringValues(stringList
);
1113 // majorDim (number of rows or cols)
1114 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1116 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1120 controlItem
->SetValue1(0);
1122 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1124 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1127 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1128 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1136 return (wxItemResource
*) NULL
;
1141 // Forward declaration
1142 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, wxExpr
*expr
);
1145 * Interpet a menu item
1148 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, wxExpr
*expr
)
1150 wxItemResource
*item
= new wxItemResource
;
1152 wxExpr
*labelExpr
= expr
->Nth(0);
1153 wxExpr
*idExpr
= expr
->Nth(1);
1154 wxExpr
*helpExpr
= expr
->Nth(2);
1155 wxExpr
*checkableExpr
= expr
->Nth(3);
1157 // Further keywords/attributes to follow sometime...
1158 if (expr
->Number() == 0)
1160 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1161 item
->SetType("wxMenuSeparator");
1166 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1167 item
->SetType("wxMenu"); // Well, menu item, but doesn't matter.
1170 wxString
str(labelExpr
->StringValue());
1171 item
->SetTitle(str
);
1176 // If a string or word, must look up in identifier table.
1177 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1179 wxString
str(idExpr
->StringValue());
1180 id
= wxResourceGetIdentifier(str
, &table
);
1183 wxLogWarning(_("Could not resolve menu id '%s'. "
1184 "Use (non-zero) integer instead\n"
1185 "or provide #define (see manual for caveats)"),
1186 (const char*) idExpr
->StringValue());
1189 else if (idExpr
->Type() == PrologInteger
)
1190 id
= (int)idExpr
->IntegerValue();
1191 item
->SetValue1(id
);
1195 wxString
str(helpExpr
->StringValue());
1196 item
->SetValue4(str
);
1199 item
->SetValue2(checkableExpr
->IntegerValue());
1201 // Find the first expression that's a list, for submenu
1202 wxExpr
*subMenuExpr
= expr
->GetFirst();
1203 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1204 subMenuExpr
= subMenuExpr
->GetNext();
1208 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1209 item
->GetChildren().Append(child
);
1210 subMenuExpr
= subMenuExpr
->GetNext();
1217 * Interpret a nested list as a menu
1220 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1222 wxItemResource *menu = new wxItemResource;
1223 // menu->SetType(wxTYPE_MENU);
1224 menu->SetType("wxMenu");
1225 wxExpr *element = expr->GetFirst();
1228 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1230 menu->GetChildren().Append(item);
1231 element = element->GetNext();
1237 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
)
1239 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1240 expr
->GetAttributeValue("menu", &listExpr
);
1242 return (wxItemResource
*) NULL
;
1244 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1247 return (wxItemResource
*) NULL
;
1250 if (expr
->GetAttributeValue("name", name
))
1252 menuResource
->SetName(name
);
1255 return menuResource
;
1258 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
)
1260 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1261 expr
->GetAttributeValue("menu", &listExpr
);
1263 return (wxItemResource
*) NULL
;
1265 wxItemResource
*resource
= new wxItemResource
;
1266 resource
->SetType("wxMenu");
1267 // resource->SetType(wxTYPE_MENU);
1269 wxExpr
*element
= listExpr
->GetFirst();
1272 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1273 resource
->GetChildren().Append(menuResource
);
1274 element
= element
->GetNext();
1278 if (expr
->GetAttributeValue("name", name
))
1280 resource
->SetName(name
);
1286 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), wxExpr
*WXUNUSED(expr
))
1288 return (wxItemResource
*) NULL
;
1291 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), wxExpr
*expr
)
1293 wxItemResource
*bitmapItem
= new wxItemResource
;
1294 // bitmapItem->SetType(wxTYPE_BITMAP);
1295 bitmapItem
->SetType("wxBitmap");
1297 if (expr
->GetAttributeValue("name", name
))
1299 bitmapItem
->SetName(name
);
1301 // Now parse all bitmap specifications
1302 wxExpr
*bitmapExpr
= expr
->GetFirst();
1305 if (bitmapExpr
->Number() == 3)
1307 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1308 if (bitmapKeyword
== "bitmap" || bitmapKeyword
== "icon")
1310 // The value part: always a list.
1311 wxExpr
*listExpr
= bitmapExpr
->Nth(2);
1312 if (listExpr
->Type() == PrologList
)
1314 wxItemResource
*bitmapSpec
= new wxItemResource
;
1315 // bitmapSpec->SetType(wxTYPE_BITMAP);
1316 bitmapSpec
->SetType("wxBitmap");
1318 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1319 // where everything after 'filename' is optional.
1320 wxExpr
*nameExpr
= listExpr
->Nth(0);
1321 wxExpr
*typeExpr
= listExpr
->Nth(1);
1322 wxExpr
*platformExpr
= listExpr
->Nth(2);
1323 wxExpr
*coloursExpr
= listExpr
->Nth(3);
1324 wxExpr
*xresExpr
= listExpr
->Nth(4);
1325 wxExpr
*yresExpr
= listExpr
->Nth(5);
1326 if (nameExpr
&& nameExpr
->StringValue() != "")
1328 bitmapSpec
->SetName(nameExpr
->StringValue());
1330 if (typeExpr
&& typeExpr
->StringValue() != "")
1332 bitmapSpec
->SetValue1(wxParseWindowStyle(typeExpr
->StringValue()));
1335 bitmapSpec
->SetValue1(0);
1337 if (platformExpr
&& platformExpr
->StringValue() != "")
1339 wxString
plat(platformExpr
->StringValue());
1340 if (plat
== "windows" || plat
== "WINDOWS")
1341 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1342 else if (plat
== "x" || plat
== "X")
1343 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1344 else if (plat
== "mac" || plat
== "MAC")
1345 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1347 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1350 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1353 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1357 xres
= (int)xresExpr
->IntegerValue();
1359 yres
= (int)yresExpr
->IntegerValue();
1360 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1362 bitmapItem
->GetChildren().Append(bitmapSpec
);
1366 bitmapExpr
= bitmapExpr
->GetNext();
1372 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
)
1374 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1377 // item->SetType(wxTYPE_ICON);
1378 item
->SetType("wxIcon");
1382 return (wxItemResource
*) NULL
;
1385 // Interpret list expression as a font
1386 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
)
1388 if (expr
->Type() != PrologList
)
1392 int family
= wxSWISS
;
1393 int style
= wxNORMAL
;
1394 int weight
= wxNORMAL
;
1396 wxString
faceName("");
1398 wxExpr
*pointExpr
= expr
->Nth(0);
1399 wxExpr
*familyExpr
= expr
->Nth(1);
1400 wxExpr
*styleExpr
= expr
->Nth(2);
1401 wxExpr
*weightExpr
= expr
->Nth(3);
1402 wxExpr
*underlineExpr
= expr
->Nth(4);
1403 wxExpr
*faceNameExpr
= expr
->Nth(5);
1405 point
= (int)pointExpr
->IntegerValue();
1410 str
= familyExpr
->StringValue();
1411 family
= (int)wxParseWindowStyle(str
);
1415 str
= styleExpr
->StringValue();
1416 style
= (int)wxParseWindowStyle(str
);
1420 str
= weightExpr
->StringValue();
1421 weight
= (int)wxParseWindowStyle(str
);
1424 underline
= (int)underlineExpr
->IntegerValue();
1426 faceName
= faceNameExpr
->StringValue();
1428 wxFont
font(point
, family
, style
, weight
, (underline
!= 0), faceName
);
1432 // Separate file for the remainder of this, for BC++/Win16
1434 #if !((defined(__BORLANDC__) || defined(__SC__)) && defined(__WIN16__))
1436 * (Re)allocate buffer for reading in from resource file
1439 bool wxReallocateResourceBuffer()
1441 if (!wxResourceBuffer
)
1443 wxResourceBufferSize
= 1000;
1444 wxResourceBuffer
= new char[wxResourceBufferSize
];
1447 if (wxResourceBuffer
)
1449 long newSize
= wxResourceBufferSize
+ 1000;
1450 char *tmp
= new char[(int)newSize
];
1451 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1452 delete[] wxResourceBuffer
;
1453 wxResourceBuffer
= tmp
;
1454 wxResourceBufferSize
= newSize
;
1459 static bool wxEatWhiteSpace(FILE *fd
)
1462 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
1469 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
1471 // Check for comment
1477 bool finished
= FALSE
;
1485 int newCh
= getc(fd
);
1500 return wxEatWhiteSpace(fd
);
1503 bool wxGetResourceToken(FILE *fd
)
1505 if (!wxResourceBuffer
)
1506 wxReallocateResourceBuffer();
1507 wxResourceBuffer
[0] = 0;
1508 wxEatWhiteSpace(fd
);
1514 wxResourceBufferCount
= 0;
1521 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1524 // Escaped characters
1525 else if (ch
== '\\')
1527 int newCh
= getc(fd
);
1530 else if (newCh
== 10)
1538 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1539 wxReallocateResourceBuffer();
1540 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1541 wxResourceBufferCount
++;
1544 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1548 wxResourceBufferCount
= 0;
1550 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1552 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1553 wxReallocateResourceBuffer();
1554 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1555 wxResourceBufferCount
++;
1559 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1567 * Files are in form:
1568 static char *name = "....";
1569 with possible comments.
1572 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1575 table
= wxDefaultResourceTable
;
1577 // static or #define
1578 if (!wxGetResourceToken(fd
))
1584 if (strcmp(wxResourceBuffer
, "#define") == 0)
1586 wxGetResourceToken(fd
);
1587 char *name
= copystring(wxResourceBuffer
);
1588 wxGetResourceToken(fd
);
1589 char *value
= copystring(wxResourceBuffer
);
1590 if (isalpha(value
[0]))
1592 int val
= (int)atol(value
);
1593 wxResourceAddIdentifier(name
, val
, table
);
1597 wxLogWarning(_("#define %s must be an integer."), name
);
1607 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1609 wxGetResourceToken(fd
);
1610 char *name
= copystring(wxResourceBuffer
);
1611 char *actualName
= name
;
1613 actualName
= name
+ 1;
1614 int len
= strlen(name
);
1615 if ((len
> 0) && (name
[len
-1] == '"'))
1617 if (!wxResourceParseIncludeFile(actualName
, table
))
1619 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1624 else if (strcmp(wxResourceBuffer
, "static") != 0)
1627 strcpy(buf
, _("Found "));
1628 strncat(buf
, wxResourceBuffer
, 30);
1629 strcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1635 if (!wxGetResourceToken(fd
))
1637 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1642 if (strcmp(wxResourceBuffer
, "char") != 0)
1644 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1649 if (!wxGetResourceToken(fd
))
1651 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1656 if (wxResourceBuffer
[0] != '*')
1658 wxLogWarning(_("Expected '*' whilst parsing resource."));
1662 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
1665 if (!wxGetResourceToken(fd
))
1667 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1672 if (strcmp(wxResourceBuffer
, "=") != 0)
1674 wxLogWarning(_("Expected '=' whilst parsing resource."));
1679 if (!wxGetResourceToken(fd
))
1681 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1687 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1689 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1694 if (!wxGetResourceToken(fd
))
1702 * Parses string window style into integer window style
1706 * Style flag parsing, e.g.
1707 * "wxSYSTEM_MENU | wxBORDER" -> integer
1710 char* wxResourceParseWord(char*s
, int *i
)
1713 return (char*) NULL
;
1715 static char buf
[150];
1716 int len
= strlen(s
);
1719 while ((ii
< len
) && (isalpha(s
[ii
]) || (s
[ii
] == '_')))
1727 // Eat whitespace and conjunction characters
1728 while ((ii
< len
) &&
1729 ((s
[ii
] == ' ') || (s
[ii
] == '|') || (s
[ii
] == ',')))
1735 return (char*) NULL
;
1740 struct wxResourceBitListStruct
1746 static wxResourceBitListStruct wxResourceBitListTable
[] =
1749 { "wxSINGLE", wxLB_SINGLE
},
1750 { "wxMULTIPLE", wxLB_MULTIPLE
},
1751 { "wxEXTENDED", wxLB_EXTENDED
},
1752 { "wxLB_SINGLE", wxLB_SINGLE
},
1753 { "wxLB_MULTIPLE", wxLB_MULTIPLE
},
1754 { "wxLB_EXTENDED", wxLB_EXTENDED
},
1755 { "wxLB_NEEDED_SB", wxLB_NEEDED_SB
},
1756 { "wxLB_ALWAYS_SB", wxLB_ALWAYS_SB
},
1757 { "wxLB_SORT", wxLB_SORT
},
1758 { "wxLB_OWNERDRAW", wxLB_OWNERDRAW
},
1759 { "wxLB_HSCROLL", wxLB_HSCROLL
},
1762 { "wxCB_SIMPLE", wxCB_SIMPLE
},
1763 { "wxCB_DROPDOWN", wxCB_DROPDOWN
},
1764 { "wxCB_READONLY", wxCB_READONLY
},
1765 { "wxCB_SORT", wxCB_SORT
},
1768 { "wxGA_PROGRESSBAR", wxGA_PROGRESSBAR
},
1769 { "wxGA_HORIZONTAL", wxGA_HORIZONTAL
},
1770 { "wxGA_VERTICAL", wxGA_VERTICAL
},
1773 { "wxPASSWORD", wxPASSWORD
},
1774 { "wxPROCESS_ENTER", wxPROCESS_ENTER
},
1775 { "wxTE_PASSWORD", wxTE_PASSWORD
},
1776 { "wxTE_READONLY", wxTE_READONLY
},
1777 { "wxTE_PROCESS_ENTER", wxTE_PROCESS_ENTER
},
1778 { "wxTE_MULTILINE", wxTE_MULTILINE
},
1780 /* wxRadioBox/wxRadioButton */
1781 { "wxRB_GROUP", wxRB_GROUP
},
1782 { "wxRA_SPECIFY_COLS", wxRA_SPECIFY_COLS
},
1783 { "wxRA_SPECIFY_ROWS", wxRA_SPECIFY_ROWS
},
1784 { "wxRA_HORIZONTAL", wxRA_HORIZONTAL
},
1785 { "wxRA_VERTICAL", wxRA_VERTICAL
},
1788 { "wxSL_HORIZONTAL", wxSL_HORIZONTAL
},
1789 { "wxSL_VERTICAL", wxSL_VERTICAL
},
1790 { "wxSL_AUTOTICKS", wxSL_AUTOTICKS
},
1791 { "wxSL_LABELS", wxSL_LABELS
},
1792 { "wxSL_LEFT", wxSL_LEFT
},
1793 { "wxSL_TOP", wxSL_TOP
},
1794 { "wxSL_RIGHT", wxSL_RIGHT
},
1795 { "wxSL_BOTTOM", wxSL_BOTTOM
},
1796 { "wxSL_BOTH", wxSL_BOTH
},
1797 { "wxSL_SELRANGE", wxSL_SELRANGE
},
1800 { "wxSB_HORIZONTAL", wxSB_HORIZONTAL
},
1801 { "wxSB_VERTICAL", wxSB_VERTICAL
},
1804 { "wxBU_AUTODRAW", wxBU_AUTODRAW
},
1805 { "wxBU_NOAUTODRAW", wxBU_NOAUTODRAW
},
1808 { "wxTR_HAS_BUTTONS", wxTR_HAS_BUTTONS
},
1809 { "wxTR_EDIT_LABELS", wxTR_EDIT_LABELS
},
1810 { "wxTR_LINES_AT_ROOT", wxTR_LINES_AT_ROOT
},
1813 { "wxLC_ICON", wxLC_ICON
},
1814 { "wxLC_SMALL_ICON", wxLC_SMALL_ICON
},
1815 { "wxLC_LIST", wxLC_LIST
},
1816 { "wxLC_REPORT", wxLC_REPORT
},
1817 { "wxLC_ALIGN_TOP", wxLC_ALIGN_TOP
},
1818 { "wxLC_ALIGN_LEFT", wxLC_ALIGN_LEFT
},
1819 { "wxLC_AUTOARRANGE", wxLC_AUTOARRANGE
},
1820 { "wxLC_USER_TEXT", wxLC_USER_TEXT
},
1821 { "wxLC_EDIT_LABELS", wxLC_EDIT_LABELS
},
1822 { "wxLC_NO_HEADER", wxLC_NO_HEADER
},
1823 { "wxLC_NO_SORT_HEADER", wxLC_NO_SORT_HEADER
},
1824 { "wxLC_SINGLE_SEL", wxLC_SINGLE_SEL
},
1825 { "wxLC_SORT_ASCENDING", wxLC_SORT_ASCENDING
},
1826 { "wxLC_SORT_DESCENDING", wxLC_SORT_DESCENDING
},
1829 { "wxSP_VERTICAL", wxSP_VERTICAL
},
1830 { "wxSP_HORIZONTAL", wxSP_HORIZONTAL
},
1831 { "wxSP_ARROW_KEYS", wxSP_ARROW_KEYS
},
1832 { "wxSP_WRAP", wxSP_WRAP
},
1835 { "wxSP_NOBORDER", wxSP_NOBORDER
},
1836 { "wxSP_3D", wxSP_3D
},
1837 { "wxSP_BORDER", wxSP_BORDER
},
1840 { "wxTC_MULTILINE", wxTC_MULTILINE
},
1841 { "wxTC_RIGHTJUSTIFY", wxTC_RIGHTJUSTIFY
},
1842 { "wxTC_FIXEDWIDTH", wxTC_FIXEDWIDTH
},
1843 { "wxTC_OWNERDRAW", wxTC_OWNERDRAW
},
1846 { "wxST_SIZEGRIP", wxST_SIZEGRIP
},
1849 { "wxFIXED_LENGTH", wxFIXED_LENGTH
},
1850 { "wxALIGN_LEFT", wxALIGN_LEFT
},
1851 { "wxALIGN_CENTER", wxALIGN_CENTER
},
1852 { "wxALIGN_CENTRE", wxALIGN_CENTRE
},
1853 { "wxALIGN_RIGHT", wxALIGN_RIGHT
},
1854 { "wxCOLOURED", wxCOLOURED
},
1857 { "wxTB_3DBUTTONS", wxTB_3DBUTTONS
},
1858 { "wxTB_HORIZONTAL", wxTB_HORIZONTAL
},
1859 { "wxTB_VERTICAL", wxTB_VERTICAL
},
1860 { "wxTB_FLAT", wxTB_FLAT
},
1863 { "wxVSCROLL", wxVSCROLL
},
1864 { "wxHSCROLL", wxHSCROLL
},
1865 { "wxCAPTION", wxCAPTION
},
1866 { "wxSTAY_ON_TOP", wxSTAY_ON_TOP
},
1867 { "wxICONIZE", wxICONIZE
},
1868 { "wxMINIMIZE", wxICONIZE
},
1869 { "wxMAXIMIZE", wxMAXIMIZE
},
1871 { "wxMDI_PARENT", 0},
1872 { "wxMDI_CHILD", 0},
1873 { "wxTHICK_FRAME", wxTHICK_FRAME
},
1874 { "wxRESIZE_BORDER", wxRESIZE_BORDER
},
1875 { "wxSYSTEM_MENU", wxSYSTEM_MENU
},
1876 { "wxMINIMIZE_BOX", wxMINIMIZE_BOX
},
1877 { "wxMAXIMIZE_BOX", wxMAXIMIZE_BOX
},
1878 { "wxRESIZE_BOX", wxRESIZE_BOX
},
1879 { "wxDEFAULT_FRAME_STYLE", wxDEFAULT_FRAME_STYLE
},
1880 { "wxDEFAULT_FRAME", wxDEFAULT_FRAME_STYLE
},
1881 { "wxDEFAULT_DIALOG_STYLE", wxDEFAULT_DIALOG_STYLE
},
1882 { "wxBORDER", wxBORDER
},
1883 { "wxRETAINED", wxRETAINED
},
1884 { "wxNATIVE_IMPL", 0},
1885 { "wxEXTENDED_IMPL", 0},
1886 { "wxBACKINGSTORE", wxBACKINGSTORE
},
1887 // { "wxFLAT", wxFLAT},
1888 // { "wxMOTIF_RESIZE", wxMOTIF_RESIZE},
1889 { "wxFIXED_LENGTH", 0},
1890 { "wxDOUBLE_BORDER", wxDOUBLE_BORDER
},
1891 { "wxSUNKEN_BORDER", wxSUNKEN_BORDER
},
1892 { "wxRAISED_BORDER", wxRAISED_BORDER
},
1893 { "wxSIMPLE_BORDER", wxSIMPLE_BORDER
},
1894 { "wxSTATIC_BORDER", wxSTATIC_BORDER
},
1895 { "wxTRANSPARENT_WINDOW", wxTRANSPARENT_WINDOW
},
1896 { "wxNO_BORDER", wxNO_BORDER
},
1897 { "wxCLIP_CHILDREN", wxCLIP_CHILDREN
},
1899 { "wxTINY_CAPTION_HORIZ", wxTINY_CAPTION_HORIZ
},
1900 { "wxTINY_CAPTION_VERT", wxTINY_CAPTION_VERT
},
1902 // Text font families
1903 { "wxDEFAULT", wxDEFAULT
},
1904 { "wxDECORATIVE", wxDECORATIVE
},
1905 { "wxROMAN", wxROMAN
},
1906 { "wxSCRIPT", wxSCRIPT
},
1907 { "wxSWISS", wxSWISS
},
1908 { "wxMODERN", wxMODERN
},
1909 { "wxTELETYPE", wxTELETYPE
},
1910 { "wxVARIABLE", wxVARIABLE
},
1911 { "wxFIXED", wxFIXED
},
1912 { "wxNORMAL", wxNORMAL
},
1913 { "wxLIGHT", wxLIGHT
},
1914 { "wxBOLD", wxBOLD
},
1915 { "wxITALIC", wxITALIC
},
1916 { "wxSLANT", wxSLANT
},
1917 { "wxSOLID", wxSOLID
},
1919 { "wxLONG_DASH", wxLONG_DASH
},
1920 { "wxSHORT_DASH", wxSHORT_DASH
},
1921 { "wxDOT_DASH", wxDOT_DASH
},
1922 { "wxUSER_DASH", wxUSER_DASH
},
1923 { "wxTRANSPARENT", wxTRANSPARENT
},
1924 { "wxSTIPPLE", wxSTIPPLE
},
1925 { "wxBDIAGONAL_HATCH", wxBDIAGONAL_HATCH
},
1926 { "wxCROSSDIAG_HATCH", wxCROSSDIAG_HATCH
},
1927 { "wxFDIAGONAL_HATCH", wxFDIAGONAL_HATCH
},
1928 { "wxCROSS_HATCH", wxCROSS_HATCH
},
1929 { "wxHORIZONTAL_HATCH", wxHORIZONTAL_HATCH
},
1930 { "wxVERTICAL_HATCH", wxVERTICAL_HATCH
},
1931 { "wxJOIN_BEVEL", wxJOIN_BEVEL
},
1932 { "wxJOIN_MITER", wxJOIN_MITER
},
1933 { "wxJOIN_ROUND", wxJOIN_ROUND
},
1934 { "wxCAP_ROUND", wxCAP_ROUND
},
1935 { "wxCAP_PROJECTING", wxCAP_PROJECTING
},
1936 { "wxCAP_BUTT", wxCAP_BUTT
},
1939 { "wxCLEAR", wxCLEAR
},
1941 { "wxINVERT", wxINVERT
},
1942 { "wxOR_REVERSE", wxOR_REVERSE
},
1943 { "wxAND_REVERSE", wxAND_REVERSE
},
1944 { "wxCOPY", wxCOPY
},
1946 { "wxAND_INVERT", wxAND_INVERT
},
1947 { "wxNO_OP", wxNO_OP
},
1949 { "wxEQUIV", wxEQUIV
},
1950 { "wxSRC_INVERT", wxSRC_INVERT
},
1951 { "wxOR_INVERT", wxOR_INVERT
},
1952 { "wxNAND", wxNAND
},
1956 { "wxFLOOD_SURFACE", wxFLOOD_SURFACE
},
1957 { "wxFLOOD_BORDER", wxFLOOD_BORDER
},
1958 { "wxODDEVEN_RULE", wxODDEVEN_RULE
},
1959 { "wxWINDING_RULE", wxWINDING_RULE
},
1960 { "wxHORIZONTAL", wxHORIZONTAL
},
1961 { "wxVERTICAL", wxVERTICAL
},
1962 { "wxBOTH", wxBOTH
},
1963 { "wxCENTER_FRAME", wxCENTER_FRAME
},
1965 { "wxYES_NO", wxYES_NO
},
1966 { "wxCANCEL", wxCANCEL
},
1969 { "wxICON_EXCLAMATION", wxICON_EXCLAMATION
},
1970 { "wxICON_HAND", wxICON_HAND
},
1971 { "wxICON_QUESTION", wxICON_QUESTION
},
1972 { "wxICON_INFORMATION", wxICON_INFORMATION
},
1973 { "wxICON_STOP", wxICON_STOP
},
1974 { "wxICON_ASTERISK", wxICON_ASTERISK
},
1975 { "wxICON_MASK", wxICON_MASK
},
1976 { "wxCENTRE", wxCENTRE
},
1977 { "wxCENTER", wxCENTRE
},
1978 { "wxUSER_COLOURS", wxUSER_COLOURS
},
1979 { "wxVERTICAL_LABEL", 0},
1980 { "wxHORIZONTAL_LABEL", 0},
1982 // Bitmap types (not strictly styles)
1983 { "wxBITMAP_TYPE_XPM", wxBITMAP_TYPE_XPM
},
1984 { "wxBITMAP_TYPE_XBM", wxBITMAP_TYPE_XBM
},
1985 { "wxBITMAP_TYPE_BMP", wxBITMAP_TYPE_BMP
},
1986 { "wxBITMAP_TYPE_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
},
1987 { "wxBITMAP_TYPE_BMP_RESOURCE", wxBITMAP_TYPE_BMP_RESOURCE
},
1988 { "wxBITMAP_TYPE_GIF", wxBITMAP_TYPE_GIF
},
1989 { "wxBITMAP_TYPE_TIF", wxBITMAP_TYPE_TIF
},
1990 { "wxBITMAP_TYPE_ICO", wxBITMAP_TYPE_ICO
},
1991 { "wxBITMAP_TYPE_ICO_RESOURCE", wxBITMAP_TYPE_ICO_RESOURCE
},
1992 { "wxBITMAP_TYPE_CUR", wxBITMAP_TYPE_CUR
},
1993 { "wxBITMAP_TYPE_CUR_RESOURCE", wxBITMAP_TYPE_CUR_RESOURCE
},
1994 { "wxBITMAP_TYPE_XBM_DATA", wxBITMAP_TYPE_XBM_DATA
},
1995 { "wxBITMAP_TYPE_XPM_DATA", wxBITMAP_TYPE_XPM_DATA
},
1996 { "wxBITMAP_TYPE_ANY", wxBITMAP_TYPE_ANY
}
1999 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
2001 long wxParseWindowStyle(const wxString
& bitListString
)
2006 while ((word
= wxResourceParseWord((char*) (const char*) bitListString
, &i
)))
2010 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2011 if (strcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2013 bitList
|= wxResourceBitListTable
[j
].bits
;
2019 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word
);
2027 * Load a bitmap from a wxWindows resource, choosing an optimum
2028 * depth and appropriate type.
2031 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
2034 table
= wxDefaultResourceTable
;
2036 wxItemResource
*item
= table
->FindResource(resource
);
2039 if ((item
->GetType() == "") || (item
->GetType() != "wxBitmap"))
2041 wxLogWarning(_("%s not a bitmap resource specification."), (const char*) resource
);
2042 return wxNullBitmap
;
2044 int thisDepth
= wxDisplayDepth();
2045 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2047 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2049 // Try to find optimum bitmap for this platform/colour depth
2050 wxNode
*node
= item
->GetChildren().First();
2053 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2054 int platform
= (int)child
->GetValue2();
2055 int noColours
= (int)child
->GetValue3();
2057 char *name = child->GetName();
2058 int bitmapType = (int)child->GetValue1();
2059 int xRes = child->GetWidth();
2060 int yRes = child->GetHeight();
2065 case RESOURCE_PLATFORM_ANY
:
2067 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2068 optResource
= child
;
2071 // Maximise the number of colours.
2072 // If noColours is zero (unspecified), then assume this
2073 // is the right one.
2074 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2075 optResource
= child
;
2080 case RESOURCE_PLATFORM_WINDOWS
:
2082 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2083 optResource
= child
;
2086 // Maximise the number of colours
2087 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2088 optResource
= child
;
2094 case RESOURCE_PLATFORM_X
:
2096 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2097 optResource
= child
;
2100 // Maximise the number of colours
2101 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2102 optResource
= child
;
2108 case RESOURCE_PLATFORM_MAC
:
2110 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2111 optResource
= child
;
2114 // Maximise the number of colours
2115 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2116 optResource
= child
;
2124 node
= node
->Next();
2126 // If no matching resource, fail.
2128 return wxNullBitmap
;
2130 wxString name
= optResource
->GetName();
2131 int bitmapType
= (int)optResource
->GetValue1();
2134 case wxBITMAP_TYPE_XBM_DATA
:
2137 wxItemResource
*item
= table
->FindResource(name
);
2140 wxLogWarning(_("Failed to find XBM resource %s.\n"
2141 "Forgot to use wxResourceLoadBitmapData?"), (const char*) name
);
2142 return wxNullBitmap
;
2144 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2146 wxLogWarning(_("No XBM facility available!"));
2150 case wxBITMAP_TYPE_XPM_DATA
:
2152 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2153 wxItemResource
*item
= table
->FindResource(name
);
2156 wxLogWarning(_("Failed to find XPM resource %s.\n"
2157 "Forgot to use wxResourceLoadBitmapData?"), (const char*) name
);
2158 return wxNullBitmap
;
2160 return wxBitmap(item
->GetValue1());
2162 wxLogWarning(_("No XPM facility available!"));
2168 return wxBitmap(name
, bitmapType
);
2172 return wxNullBitmap
;
2176 wxLogWarning(_("Bitmap resource specification %s not found."), (const char*) resource
);
2177 return wxNullBitmap
;
2182 * Load an icon from a wxWindows resource, choosing an optimum
2183 * depth and appropriate type.
2186 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2189 table
= wxDefaultResourceTable
;
2191 wxItemResource
*item
= table
->FindResource(resource
);
2194 if ((item
->GetType() == "") || strcmp(item
->GetType(), "wxIcon") != 0)
2196 wxLogWarning(_("%s not an icon resource specification."), (const char*) resource
);
2199 int thisDepth
= wxDisplayDepth();
2200 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2202 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2204 // Try to find optimum icon for this platform/colour depth
2205 wxNode
*node
= item
->GetChildren().First();
2208 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2209 int platform
= (int)child
->GetValue2();
2210 int noColours
= (int)child
->GetValue3();
2212 char *name = child->GetName();
2213 int bitmapType = (int)child->GetValue1();
2214 int xRes = child->GetWidth();
2215 int yRes = child->GetHeight();
2220 case RESOURCE_PLATFORM_ANY
:
2222 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2223 optResource
= child
;
2226 // Maximise the number of colours.
2227 // If noColours is zero (unspecified), then assume this
2228 // is the right one.
2229 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2230 optResource
= child
;
2235 case RESOURCE_PLATFORM_WINDOWS
:
2237 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2238 optResource
= child
;
2241 // Maximise the number of colours
2242 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2243 optResource
= child
;
2249 case RESOURCE_PLATFORM_X
:
2251 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2252 optResource
= child
;
2255 // Maximise the number of colours
2256 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2257 optResource
= child
;
2263 case RESOURCE_PLATFORM_MAC
:
2265 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2266 optResource
= child
;
2269 // Maximise the number of colours
2270 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2271 optResource
= child
;
2279 node
= node
->Next();
2281 // If no matching resource, fail.
2285 wxString name
= optResource
->GetName();
2286 int bitmapType
= (int)optResource
->GetValue1();
2289 case wxBITMAP_TYPE_XBM_DATA
:
2292 wxItemResource
*item
= table
->FindResource(name
);
2295 wxLogWarning(_("Failed to find XBM resource %s.\n"
2296 "Forgot to use wxResourceLoadIconData?"), (const char*) name
);
2299 return wxIcon((const char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2301 wxLogWarning(_("No XBM facility available!"));
2305 case wxBITMAP_TYPE_XPM_DATA
:
2307 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2309 #if (defined(__WXGTK__)) || (defined(__WXMSW__) && wxUSE_XPM_IN_MSW)
2310 wxItemResource *item = table->FindResource(name);
2314 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2318 return wxIcon((char **)item->GetValue1());
2320 wxLogWarning(_("No XPM facility available!"));
2323 wxLogWarning(_("No XPM icon facility available!"));
2329 wxLogWarning(_("Icon resource specification %s not found."), (const char*) resource
);
2331 return wxIcon(name
, bitmapType
);
2340 wxLogWarning(_("Icon resource specification %s not found."), (const char*) resource
);
2345 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2347 wxMenu
*menu
= new wxMenu
;
2348 wxNode
*node
= item
->GetChildren().First();
2351 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2352 if ((child
->GetType() != "") && (child
->GetType() == "wxMenuSeparator"))
2353 menu
->AppendSeparator();
2354 else if (child
->GetChildren().Number() > 0)
2356 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2358 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2362 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2364 node
= node
->Next();
2369 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2372 table
= wxDefaultResourceTable
;
2374 wxItemResource
*menuResource
= table
->FindResource(resource
);
2375 if (menuResource
&& (menuResource
->GetType() != "") && (menuResource
->GetType() == "wxMenu"))
2378 menuBar
= new wxMenuBar
;
2379 wxNode
*node
= menuResource
->GetChildren().First();
2382 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2383 wxMenu
*menu
= wxResourceCreateMenu(child
);
2385 menuBar
->Append(menu
, child
->GetTitle());
2386 node
= node
->Next();
2390 return (wxMenuBar
*) NULL
;
2393 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2396 table
= wxDefaultResourceTable
;
2398 wxItemResource
*menuResource
= table
->FindResource(resource
);
2399 if (menuResource
&& (menuResource
->GetType() != "") && (menuResource
->GetType() == "wxMenu"))
2400 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2401 return wxResourceCreateMenu(menuResource
);
2402 return (wxMenu
*) NULL
;
2405 // Global equivalents (so don't have to refer to default table explicitly)
2406 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2409 table
= wxDefaultResourceTable
;
2411 return table
->ParseResourceData(resource
);
2414 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2417 table
= wxDefaultResourceTable
;
2419 return table
->ParseResourceFile(filename
);
2422 // Register XBM/XPM data
2423 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2426 table
= wxDefaultResourceTable
;
2428 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2431 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2434 table
= wxDefaultResourceTable
;
2436 return table
->RegisterResourceBitmapData(name
, data
);
2439 void wxResourceClear(wxResourceTable
*table
)
2442 table
= wxDefaultResourceTable
;
2444 table
->ClearTable();
2451 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2454 table
= wxDefaultResourceTable
;
2456 table
->identifiers
.Put(name
, (wxObject
*)value
);
2460 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2463 table
= wxDefaultResourceTable
;
2465 return (int)table
->identifiers
.Get(name
);
2469 * Parse #include file for #defines (only)
2472 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2475 table
= wxDefaultResourceTable
;
2477 FILE *fd
= fopen(f
, "r");
2482 while (wxGetResourceToken(fd
))
2484 if (strcmp(wxResourceBuffer
, "#define") == 0)
2486 wxGetResourceToken(fd
);
2487 char *name
= copystring(wxResourceBuffer
);
2488 wxGetResourceToken(fd
);
2489 char *value
= copystring(wxResourceBuffer
);
2490 if (isdigit(value
[0]))
2492 int val
= (int)atol(value
);
2493 wxResourceAddIdentifier(name
, val
, table
);
2504 * Reading strings as if they were .wxr files
2507 static int getc_string(char *s
)
2509 int ch
= s
[wxResourceStringPtr
];
2514 wxResourceStringPtr
++;
2519 static int ungetc_string()
2521 wxResourceStringPtr
--;
2525 bool wxEatWhiteSpaceString(char *s
)
2527 int ch
= getc_string(s
);
2531 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
2538 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
2539 ch
= getc_string(s
);
2540 // Check for comment
2543 ch
= getc_string(s
);
2546 bool finished
= FALSE
;
2549 ch
= getc_string(s
);
2554 int newCh
= getc_string(s
);
2569 return wxEatWhiteSpaceString(s
);
2572 bool wxGetResourceTokenString(char *s
)
2574 if (!wxResourceBuffer
)
2575 wxReallocateResourceBuffer();
2576 wxResourceBuffer
[0] = 0;
2577 wxEatWhiteSpaceString(s
);
2579 int ch
= getc_string(s
);
2583 wxResourceBufferCount
= 0;
2584 ch
= getc_string(s
);
2590 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2593 // Escaped characters
2594 else if (ch
== '\\')
2596 int newCh
= getc_string(s
);
2599 else if (newCh
== 10)
2607 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2608 wxReallocateResourceBuffer();
2609 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2610 wxResourceBufferCount
++;
2611 ch
= getc_string(s
);
2613 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2617 wxResourceBufferCount
= 0;
2619 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2621 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2622 wxReallocateResourceBuffer();
2623 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2624 wxResourceBufferCount
++;
2626 ch
= getc_string(s
);
2628 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2636 * Files are in form:
2637 static char *name = "....";
2638 with possible comments.
2641 bool wxResourceReadOneResourceString(char *s
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2644 table
= wxDefaultResourceTable
;
2646 // static or #define
2647 if (!wxGetResourceTokenString(s
))
2653 if (strcmp(wxResourceBuffer
, "#define") == 0)
2655 wxGetResourceTokenString(s
);
2656 char *name
= copystring(wxResourceBuffer
);
2657 wxGetResourceTokenString(s
);
2658 char *value
= copystring(wxResourceBuffer
);
2659 if (isalpha(value
[0]))
2661 int val
= (int)atol(value
);
2662 wxResourceAddIdentifier(name
, val
, table
);
2666 wxLogWarning(_("#define %s must be an integer."), name
);
2677 else if (strcmp(wxResourceBuffer, "#include") == 0)
2679 wxGetResourceTokenString(s);
2680 char *name = copystring(wxResourceBuffer);
2681 char *actualName = name;
2683 actualName = name + 1;
2684 int len = strlen(name);
2685 if ((len > 0) && (name[len-1] == '"'))
2687 if (!wxResourceParseIncludeFile(actualName, table))
2690 sprintf(buf, _("Could not find resource include file %s."), actualName);
2697 else if (strcmp(wxResourceBuffer
, "static") != 0)
2700 strcpy(buf
, _("Found "));
2701 strncat(buf
, wxResourceBuffer
, 30);
2702 strcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
2708 if (!wxGetResourceTokenString(s
))
2710 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2715 if (strcmp(wxResourceBuffer
, "char") != 0)
2717 wxLogWarning(_("Expected 'char' whilst parsing resource."));
2722 if (!wxGetResourceTokenString(s
))
2724 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2729 if (wxResourceBuffer
[0] != '*')
2731 wxLogWarning(_("Expected '*' whilst parsing resource."));
2735 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
2738 if (!wxGetResourceTokenString(s
))
2740 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2745 if (strcmp(wxResourceBuffer
, "=") != 0)
2747 wxLogWarning(_("Expected '=' whilst parsing resource."));
2752 if (!wxGetResourceTokenString(s
))
2754 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2760 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2762 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2767 if (!wxGetResourceTokenString(s
))
2774 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
2777 table
= wxDefaultResourceTable
;
2782 // Turn backslashes into spaces
2785 int len
= strlen(s
);
2787 for (i
= 0; i
< len
; i
++)
2788 if (s
[i
] == 92 && s
[i
+1] == 13)
2796 wxResourceStringPtr
= 0;
2799 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
2803 return wxResourceInterpretResources(*table
, db
);
2807 * resource loading facility
2810 bool wxWindow::LoadFromResource(wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
2813 table
= wxDefaultResourceTable
;
2815 wxItemResource
*resource
= table
->FindResource((const char *)resourceName
);
2816 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
2817 if (!resource
|| (resource
->GetType() == "") ||
2818 ! ((resource
->GetType() == "wxDialog") || (resource
->GetType() == "wxPanel")))
2821 wxString
title(resource
->GetTitle());
2822 long theWindowStyle
= resource
->GetStyle();
2823 bool isModal
= (resource
->GetValue1() != 0);
2824 int x
= resource
->GetX();
2825 int y
= resource
->GetY();
2826 int width
= resource
->GetWidth();
2827 int height
= resource
->GetHeight();
2828 wxString name
= resource
->GetName();
2830 if (IsKindOf(CLASSINFO(wxDialog
)))
2832 wxDialog
*dialogBox
= (wxDialog
*)this;
2833 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
2834 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
2837 // Only reset the client size if we know we're not going to do it again below.
2838 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == 0)
2839 dialogBox
->SetClientSize(width
, height
);
2841 else if (IsKindOf(CLASSINFO(wxPanel
)))
2843 wxPanel
* panel
= (wxPanel
*)this;
2844 if (!panel
->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2849 if (!this->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
2853 if ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
2855 // No need to do this since it's done in wxPanel or wxDialog constructor.
2856 // SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
2860 if (resource
->GetFont().Ok())
2861 SetFont(resource
->GetFont());
2862 if (resource
->GetBackgroundColour().Ok())
2863 SetBackgroundColour(resource
->GetBackgroundColour());
2866 // Should have some kind of font at this point
2867 if (!GetFont().Ok())
2868 SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT
));
2869 if (!GetBackgroundColour().Ok())
2870 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE
));
2872 // Only when we've created the window and set the font can we set the correct size,
2873 // if based on dialog units.
2874 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
2876 wxSize sz
= ConvertDialogToPixels(wxSize(width
, height
));
2877 SetClientSize(sz
.x
, sz
.y
);
2879 wxPoint pt
= ConvertDialogToPixels(wxPoint(x
, y
));
2883 // Now create children
2884 wxNode
*node
= resource
->GetChildren().First();
2887 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
2889 (void) CreateItem(childResource
, resource
, table
);
2891 node
= node
->Next();
2896 wxControl
*wxWindow::CreateItem(const wxItemResource
*resource
, const wxItemResource
* parentResource
, const wxResourceTable
*table
)
2899 table
= wxDefaultResourceTable
;
2900 return table
->CreateItem((wxWindow
*)this, resource
, parentResource
);
2904 #pragma warning(default:4706) // assignment within conditional expression
2910 #endif // wxUSE_WX_RESOURCES