1 /////////////////////////////////////////////////////////////////////////////
2 // Name: contrib/src/deprecated/resource.cpp
3 // Purpose: Resource system
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 #include "wx/deprecated/setup.h"
21 #if wxUSE_WX_RESOURCES
24 #pragma warning(disable:4706) // assignment within conditional expression
30 #include "wx/gdicmn.h"
34 #include "wx/stattext.h"
35 #include "wx/button.h"
36 #include "wx/bmpbuttn.h"
37 #include "wx/radiobox.h"
38 #include "wx/listbox.h"
39 #include "wx/choice.h"
40 #include "wx/checkbox.h"
41 #include "wx/settings.h"
42 #include "wx/slider.h"
44 #include "wx/statbox.h"
45 #include "wx/statbmp.h"
47 #include "wx/textctrl.h"
48 #include "wx/msgdlg.h"
52 #include "wx/treebase.h"
53 #include "wx/listctrl.h"
56 #include "wx/radiobut.h"
60 #include "wx/scrolbar.h"
64 #include "wx/combobox.h"
67 #include "wx/splitter.h"
68 #include "wx/toolbar.h"
70 #include "wx/validate.h"
72 #include "wx/module.h"
79 #include "wx/string.h"
80 #include "wx/settings.h"
81 #include "wx/stream.h"
83 #include "wx/deprecated/resource.h"
84 #include "wx/deprecated/wxexpr.h"
86 #if !WXWIN_COMPATIBILITY_2_4
87 static inline wxChar
* copystring(const wxChar
* s
)
88 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
91 // Forward (private) declarations
92 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
);
93 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
= false);
94 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
);
95 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
);
96 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
);
97 wxItemResource
*wxResourceInterpretString(wxResourceTable
& table
, wxExpr
*expr
);
98 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& table
, wxExpr
*expr
);
99 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
);
100 // Interpret list expression
101 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
);
103 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
104 bool wxResourceReadOneResource(wxInputStream
*fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
) ;
105 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
107 wxResourceTable
*wxDefaultResourceTable
= (wxResourceTable
*) NULL
;
109 char *wxResourceBuffer
= (char *) NULL
;
110 long wxResourceBufferSize
= 0;
111 long wxResourceBufferCount
= 0;
112 int wxResourceStringPtr
= 0;
114 void wxInitializeResourceSystem()
116 if (!wxDefaultResourceTable
)
117 wxDefaultResourceTable
= new wxResourceTable
;
120 void wxCleanUpResourceSystem()
122 delete wxDefaultResourceTable
;
123 if (wxResourceBuffer
)
124 delete[] wxResourceBuffer
;
127 // Module to ensure the resource system data gets initialized
130 class wxResourceModule
: public wxModule
133 wxResourceModule() : wxModule() {}
134 virtual bool OnInit() { wxInitializeResourceSystem(); return true; }
135 virtual void OnExit() { wxCleanUpResourceSystem(); }
137 DECLARE_DYNAMIC_CLASS(wxResourceModule
)
140 IMPLEMENT_DYNAMIC_CLASS(wxResourceModule
, wxModule
)
143 IMPLEMENT_DYNAMIC_CLASS(wxItemResource
, wxObject
)
144 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable
, wxHashTable
)
146 wxItemResource::wxItemResource()
148 m_itemType
= wxEmptyString
;
149 m_title
= wxEmptyString
;
150 m_name
= wxEmptyString
;
152 m_x
= m_y
= m_width
= m_height
= 0;
153 m_value1
= m_value2
= m_value3
= m_value5
= 0;
154 m_value4
= wxEmptyString
;
159 wxItemResource::~wxItemResource()
161 wxNode
*node
= m_children
.GetFirst();
164 wxItemResource
*item
= (wxItemResource
*)node
->GetData();
167 node
= m_children
.GetFirst();
175 wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
)
179 wxResourceTable::~wxResourceTable()
184 wxItemResource
*wxResourceTable::FindResource(const wxString
& name
) const
186 wxItemResource
*item
= (wxItemResource
*)Get(WXSTRINGCAST name
);
190 void wxResourceTable::AddResource(wxItemResource
*item
)
192 wxString name
= item
->GetName();
194 name
= item
->GetTitle();
196 name
= wxT("no name");
198 // Delete existing resource, if any.
204 bool wxResourceTable::DeleteResource(const wxString
& name
)
206 wxItemResource
*item
= (wxItemResource
*)Delete(WXSTRINGCAST name
);
209 // See if any resource has this as its child; if so, delete from
210 // parent's child list.
212 wxHashTable::Node
*node
= Next();
215 wxItemResource
*parent
= (wxItemResource
*)node
->GetData();
216 if (parent
->GetChildren().Member(item
))
218 parent
->GetChildren().DeleteObject(item
);
231 bool wxResourceTable::ParseResourceFile( wxInputStream
*is
)
234 int len
= is
->GetSize() ;
237 while ( is
->TellI() + 10 < len
) // it's a hack because the streams dont support EOF
239 wxResourceReadOneResource(is
, db
, &eof
, this) ;
241 return wxResourceInterpretResources(*this, db
);
244 bool wxResourceTable::ParseResourceFile(const wxString
& filename
)
248 FILE *fd
= wxFopen(filename
, wxT("r"));
252 while (wxResourceReadOneResource(fd
, db
, &eof
, this) && !eof
)
257 return wxResourceInterpretResources(*this, db
);
260 bool wxResourceTable::ParseResourceData(const wxString
& data
)
263 if (!db
.ReadFromString(data
))
265 wxLogWarning(_("Ill-formed resource file syntax."));
269 return wxResourceInterpretResources(*this, db
);
272 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char bits
[], int width
, int height
)
274 // Register pre-loaded bitmap data
275 wxItemResource
*item
= new wxItemResource
;
276 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
277 item
->SetType(wxT("wxXBMData"));
279 item
->SetValue1((long)bits
);
280 item
->SetValue2((long)width
);
281 item
->SetValue3((long)height
);
286 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char **data
)
288 // Register pre-loaded bitmap data
289 wxItemResource
*item
= new wxItemResource
;
290 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
291 item
->SetType(wxT("wxXPMData"));
293 item
->SetValue1((long)data
);
298 bool wxResourceTable::SaveResource(const wxString
& WXUNUSED(filename
))
303 void wxResourceTable::ClearTable()
306 wxHashTable::Node
*node
= Next();
309 wxHashTable::Node
*next
= Next();
310 wxItemResource
*item
= (wxItemResource
*)node
->GetData();
317 wxControl
*wxResourceTable::CreateItem(wxWindow
*parent
, const wxItemResource
* childResource
, const wxItemResource
* parentResource
) const
319 int id
= childResource
->GetId();
323 bool dlgUnits
= ((parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0);
325 wxControl
*control
= (wxControl
*) NULL
;
326 wxString
itemType(childResource
->GetType());
332 pos
= parent
->ConvertDialogToPixels(wxPoint(childResource
->GetX(), childResource
->GetY()));
333 size
= parent
->ConvertDialogToPixels(wxSize(childResource
->GetWidth(), childResource
->GetHeight()));
337 pos
= wxPoint(childResource
->GetX(), childResource
->GetY());
338 size
= wxSize(childResource
->GetWidth(), childResource
->GetHeight());
341 if (itemType
== wxString(wxT("wxButton")) || itemType
== wxString(wxT("wxBitmapButton")))
343 if (!childResource
->GetValue4().empty())
346 wxBitmap bitmap
= childResource
->GetBitmap();
349 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
350 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
353 #if defined(__WXPM__)
355 // OS/2 uses integer id's to access resources, not file name strings
357 bitmap
.LoadFile(wxCROSS_BITMAP
, wxBITMAP_TYPE_BMP_RESOURCE
);
359 bitmap
.LoadFile(wxT("cross_bmp"), wxBITMAP_TYPE_BMP_RESOURCE
);
361 control
= new wxBitmapButton(parent
, id
, bitmap
, pos
, size
,
362 childResource
->GetStyle() | wxBU_AUTODRAW
, wxDefaultValidator
, childResource
->GetName());
365 // Normal, text button
366 control
= new wxButton(parent
, id
, childResource
->GetTitle(), pos
, size
,
367 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
369 else if (itemType
== wxString(wxT("wxMessage")) || itemType
== wxString(wxT("wxStaticText")) ||
370 itemType
== wxString(wxT("wxStaticBitmap")))
372 if (!childResource
->GetValue4().empty() || itemType
== wxString(wxT("wxStaticBitmap")) )
375 wxBitmap bitmap
= childResource
->GetBitmap();
378 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
379 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
381 #if wxUSE_BITMAP_MESSAGE
383 // Use a default bitmap
385 bitmap
.LoadFile(wxT("cross_bmp"), wxBITMAP_TYPE_BMP_RESOURCE
);
389 control
= new wxStaticBitmap(parent
, id
, bitmap
, pos
, size
,
390 childResource
->GetStyle(), childResource
->GetName());
395 control
= new wxStaticText(parent
, id
, childResource
->GetTitle(), pos
, size
,
396 childResource
->GetStyle(), childResource
->GetName());
399 else if (itemType
== wxString(wxT("wxText")) || itemType
== wxString(wxT("wxTextCtrl")) || itemType
== wxString(wxT("wxMultiText")))
401 control
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(), pos
, size
,
402 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
404 else if (itemType
== wxString(wxT("wxCheckBox")))
406 control
= new wxCheckBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
407 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
409 ((wxCheckBox
*)control
)->SetValue((childResource
->GetValue1() != 0));
412 else if (itemType
== wxString(wxT("wxGauge")))
414 control
= new wxGauge(parent
, id
, (int)childResource
->GetValue2(), pos
, size
,
415 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
417 ((wxGauge
*)control
)->SetValue((int)childResource
->GetValue1());
421 else if (itemType
== wxString(wxT("wxRadioButton")))
423 control
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(),
425 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
429 else if (itemType
== wxString(wxT("wxScrollBar")))
431 control
= new wxScrollBar(parent
, id
, pos
, size
,
432 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
434 ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1());
435 ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2());
436 ((wxScrollBar *)control)->SetObjectLength((int)childResource->GetValue3());
437 ((wxScrollBar *)control)->SetViewLength((int)(long)childResource->GetValue5());
439 ((wxScrollBar
*)control
)->SetScrollbar((int)childResource
->GetValue1(),(int)childResource
->GetValue2(),
440 (int)childResource
->GetValue3(),(int)(long)childResource
->GetValue5(),false);
444 else if (itemType
== wxString(wxT("wxSlider")))
446 control
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(),
447 (int)childResource
->GetValue2(), (int)childResource
->GetValue3(), pos
, size
,
448 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
450 else if (itemType
== wxString(wxT("wxGroupBox")) || itemType
== wxString(wxT("wxStaticBox")))
452 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
453 childResource
->GetStyle(), childResource
->GetName());
455 else if (itemType
== wxString(wxT("wxListBox")))
457 wxStringList
& stringList
= childResource
->GetStringValues();
458 wxString
*strings
= (wxString
*) NULL
;
460 if (stringList
.GetCount() > 0)
462 noStrings
= stringList
.GetCount();
463 strings
= new wxString
[noStrings
];
464 wxStringListNode
*node
= stringList
.GetFirst();
468 strings
[i
] = (wxChar
*)node
->GetData();
470 node
= node
->GetNext();
473 control
= new wxListBox(parent
, id
, pos
, size
,
474 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
479 else if (itemType
== wxString(wxT("wxChoice")))
481 wxStringList
& stringList
= childResource
->GetStringValues();
482 wxString
*strings
= (wxString
*) NULL
;
484 if (stringList
.GetCount() > 0)
486 noStrings
= stringList
.GetCount();
487 strings
= new wxString
[noStrings
];
488 wxStringListNode
*node
= stringList
.GetFirst();
492 strings
[i
] = (wxChar
*)node
->GetData();
494 node
= node
->GetNext();
497 control
= new wxChoice(parent
, id
, pos
, size
,
498 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
504 else if (itemType
== wxString(wxT("wxComboBox")))
506 wxStringList
& stringList
= childResource
->GetStringValues();
507 wxString
*strings
= (wxString
*) NULL
;
509 if (stringList
.GetCount() > 0)
511 noStrings
= stringList
.GetCount();
512 strings
= new wxString
[noStrings
];
513 wxStringListNode
*node
= stringList
.GetFirst();
517 strings
[i
] = (wxChar
*)node
->GetData();
519 node
= node
->GetNext();
522 control
= new wxComboBox(parent
, id
, childResource
->GetValue4(), pos
, size
,
523 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
529 else if (itemType
== wxString(wxT("wxRadioBox")))
531 wxStringList
& stringList
= childResource
->GetStringValues();
532 wxString
*strings
= (wxString
*) NULL
;
534 if (stringList
.GetCount() > 0)
536 noStrings
= stringList
.GetCount();
537 strings
= new wxString
[noStrings
];
538 wxStringListNode
*node
= stringList
.GetFirst();
542 strings
[i
] = (wxChar
*)node
->GetData();
544 node
= node
->GetNext();
547 control
= new wxRadioBox(parent
, (wxWindowID
) id
, wxString(childResource
->GetTitle()), pos
, size
,
548 noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
,
549 childResource
->GetName());
555 if ((parentResource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
557 // Don't set font; will be inherited from parent.
561 if (control
&& childResource
->GetFont().Ok())
563 control
->SetFont(childResource
->GetFont());
566 // Force the layout algorithm since the size changes the layout
567 if (control
->IsKindOf(CLASSINFO(wxRadioBox
)))
569 control
->SetSize(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, wxSIZE_AUTO_WIDTH
|wxSIZE_AUTO_HEIGHT
);
578 * Interpret database as a series of resources
581 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
)
583 wxNode
*node
= db
.GetFirst();
586 wxExpr
*clause
= (wxExpr
*)node
->GetData();
587 wxString
functor(clause
->Functor());
589 wxItemResource
*item
= (wxItemResource
*) NULL
;
590 if (functor
== wxT("dialog"))
591 item
= wxResourceInterpretDialog(table
, clause
);
592 else if (functor
== wxT("panel"))
593 item
= wxResourceInterpretDialog(table
, clause
, true);
594 else if (functor
== wxT("menubar"))
595 item
= wxResourceInterpretMenuBar(table
, clause
);
596 else if (functor
== wxT("menu"))
597 item
= wxResourceInterpretMenu(table
, clause
);
598 else if (functor
== wxT("string"))
599 item
= wxResourceInterpretString(table
, clause
);
600 else if (functor
== wxT("bitmap"))
601 item
= wxResourceInterpretBitmap(table
, clause
);
602 else if (functor
== wxT("icon"))
603 item
= wxResourceInterpretIcon(table
, clause
);
607 // Remove any existing resource of same name
608 if (!item
->GetName().empty())
609 table
.DeleteResource(item
->GetName());
610 table
.AddResource(item
);
612 node
= node
->GetNext();
617 static const wxChar
*g_ValidControlClasses
[] =
620 wxT("wxBitmapButton"),
623 wxT("wxStaticBitmap"),
629 wxT("wxRadioButton"),
631 wxT("wxBitmapCheckBox"),
641 static bool wxIsValidControlClass(const wxString
& c
)
643 for ( size_t i
= 0; i
< WXSIZEOF(g_ValidControlClasses
); i
++ )
645 if ( c
== g_ValidControlClasses
[i
] )
651 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
)
653 wxItemResource
*dialogItem
= new wxItemResource
;
655 dialogItem
->SetType(wxT("wxPanel"));
657 dialogItem
->SetType(wxT("wxDialog"));
658 wxString style
= wxEmptyString
;
659 wxString title
= wxEmptyString
;
660 wxString name
= wxEmptyString
;
661 wxString backColourHex
= wxEmptyString
;
662 wxString labelColourHex
= wxEmptyString
;
663 wxString buttonColourHex
= wxEmptyString
;
665 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
669 int x
= 0; int y
= 0; int width
= wxDefaultCoord
; int height
= wxDefaultCoord
;
671 wxExpr
*labelFontExpr
= (wxExpr
*) NULL
;
672 wxExpr
*buttonFontExpr
= (wxExpr
*) NULL
;
673 wxExpr
*fontExpr
= (wxExpr
*) NULL
;
674 expr
->GetAttributeValue(wxT("style"), style
);
675 expr
->GetAttributeValue(wxT("name"), name
);
676 expr
->GetAttributeValue(wxT("title"), title
);
677 expr
->GetAttributeValue(wxT("x"), x
);
678 expr
->GetAttributeValue(wxT("y"), y
);
679 expr
->GetAttributeValue(wxT("width"), width
);
680 expr
->GetAttributeValue(wxT("height"), height
);
681 expr
->GetAttributeValue(wxT("modal"), isModal
);
682 expr
->GetAttributeValue(wxT("label_font"), &labelFontExpr
);
683 expr
->GetAttributeValue(wxT("button_font"), &buttonFontExpr
);
684 expr
->GetAttributeValue(wxT("font"), &fontExpr
);
685 expr
->GetAttributeValue(wxT("background_colour"), backColourHex
);
686 expr
->GetAttributeValue(wxT("label_colour"), labelColourHex
);
687 expr
->GetAttributeValue(wxT("button_colour"), buttonColourHex
);
689 int useDialogUnits
= 0;
690 expr
->GetAttributeValue(wxT("use_dialog_units"), useDialogUnits
);
691 if (useDialogUnits
!= 0)
692 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS
);
695 expr
->GetAttributeValue(wxT("use_system_defaults"), useDefaults
);
696 if (useDefaults
!= 0)
697 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS
);
700 expr
->GetAttributeValue(wxT("id"), id
);
701 dialogItem
->SetId(id
);
705 windowStyle
= wxParseWindowStyle(style
);
707 dialogItem
->SetStyle(windowStyle
);
708 dialogItem
->SetValue1(isModal
);
710 #if WXWIN_COMPATIBILITY_2_6
713 #pragma message disable CODCAUUNR
715 if (windowStyle
& wxDIALOG_MODAL
) // Uses style in wxWin 2
716 dialogItem
->SetValue1(true);
718 #pragma message enable CODCAUUNR
721 #endif // WXWIN_COMPATIBILITY_2_6
723 dialogItem
->SetName(name
);
724 dialogItem
->SetTitle(title
);
725 dialogItem
->SetSize(x
, y
, width
, height
);
727 // Check for wxWin 1.68-style specifications
728 if (style
.Find(wxT("VERTICAL_LABEL")) != wxNOT_FOUND
)
729 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL
);
730 else if (style
.Find(wxT("HORIZONTAL_LABEL")) != wxNOT_FOUND
)
731 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL
);
733 if (!backColourHex
.empty())
738 r
= wxHexToDec(backColourHex
.Mid(0, 2));
739 g
= wxHexToDec(backColourHex
.Mid(2, 2));
740 b
= wxHexToDec(backColourHex
.Mid(4, 2));
741 dialogItem
->SetBackgroundColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
743 if (!labelColourHex
.empty())
748 r
= wxHexToDec(labelColourHex
.Mid(0, 2));
749 g
= wxHexToDec(labelColourHex
.Mid(2, 2));
750 b
= wxHexToDec(labelColourHex
.Mid(4, 2));
751 dialogItem
->SetLabelColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
753 if (!buttonColourHex
.empty())
758 r
= wxHexToDec(buttonColourHex
.Mid(0, 2));
759 g
= wxHexToDec(buttonColourHex
.Mid(2, 2));
760 b
= wxHexToDec(buttonColourHex
.Mid(4, 2));
761 dialogItem
->SetButtonColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
765 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
766 else if (buttonFontExpr
)
767 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
768 else if (labelFontExpr
)
769 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
771 // Now parse all controls
772 wxExpr
*controlExpr
= expr
->GetFirst();
775 if (controlExpr
->Number() == 3)
777 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
778 if (!controlKeyword
.empty() && controlKeyword
== wxT("control"))
780 // The value part: always a list.
781 wxExpr
*listExpr
= controlExpr
->Nth(2);
782 if (listExpr
->Type() == PrologList
)
784 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
787 dialogItem
->GetChildren().Append(controlItem
);
792 controlExpr
= controlExpr
->GetNext();
797 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
)
799 wxItemResource
*controlItem
= new wxItemResource
;
801 // First, find the standard features of a control definition:
802 // [optional integer/string id], control name, title, style, name, x, y, width, height
804 wxString controlType
;
809 long windowStyle
= 0;
810 int x
= 0; int y
= 0; int width
= wxDefaultCoord
; int height
= wxDefaultCoord
;
813 wxExpr
*expr1
= expr
->Nth(0);
815 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
817 if ( wxIsValidControlClass(expr1
->StringValue()) )
820 controlType
= expr1
->StringValue();
824 wxString
str(expr1
->StringValue());
825 id
= wxResourceGetIdentifier(str
, &table
);
828 wxLogWarning(_("Could not resolve control class or id '%s'. Use (non-zero) integer instead\n or provide #define (see manual for caveats)"),
829 (const wxChar
*) expr1
->StringValue());
831 return (wxItemResource
*) NULL
;
835 // Success - we have an id, so the 2nd element must be the control class.
836 controlType
= expr
->Nth(1)->StringValue();
841 else if (expr1
->Type() == PrologInteger
)
843 id
= (int)expr1
->IntegerValue();
844 // Success - we have an id, so the 2nd element must be the control class.
845 controlType
= expr
->Nth(1)->StringValue();
849 expr1
= expr
->Nth(count
);
852 title
= expr1
->StringValue();
854 expr1
= expr
->Nth(count
);
858 style
= expr1
->StringValue();
859 windowStyle
= wxParseWindowStyle(style
);
862 expr1
= expr
->Nth(count
);
865 name
= expr1
->StringValue();
867 expr1
= expr
->Nth(count
);
870 x
= (int)expr1
->IntegerValue();
872 expr1
= expr
->Nth(count
);
875 y
= (int)expr1
->IntegerValue();
877 expr1
= expr
->Nth(count
);
880 width
= (int)expr1
->IntegerValue();
882 expr1
= expr
->Nth(count
);
885 height
= (int)expr1
->IntegerValue();
887 controlItem
->SetStyle(windowStyle
);
888 controlItem
->SetName(name
);
889 controlItem
->SetTitle(title
);
890 controlItem
->SetSize(x
, y
, width
, height
);
891 controlItem
->SetType(controlType
);
892 controlItem
->SetId(id
);
894 // Check for wxWin 1.68-style specifications
895 if (style
.Find(wxT("VERTICAL_LABEL")) != wxNOT_FOUND
)
896 controlItem
->SetResourceStyle(controlItem
->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL
);
897 else if (style
.Find(wxT("HORIZONTAL_LABEL")) != wxNOT_FOUND
)
898 controlItem
->SetResourceStyle(controlItem
->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL
);
900 if (controlType
== wxT("wxButton"))
902 // Check for bitmap resource name (in case loading old-style resource file)
903 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
905 wxString
str(expr
->Nth(count
)->StringValue());
910 controlItem
->SetValue4(str
);
911 controlItem
->SetType(wxT("wxBitmapButton"));
914 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
915 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
917 else if (controlType
== wxT("wxBitmapButton"))
919 // Check for bitmap resource name
920 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
922 wxString
str(expr
->Nth(count
)->StringValue());
923 controlItem
->SetValue4(str
);
925 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
926 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
929 else if (controlType
== wxT("wxCheckBox"))
931 // Check for default value
932 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
934 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
936 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
937 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
941 else if (controlType
== wxT("wxRadioButton"))
943 // Check for default value
944 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
946 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
948 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
949 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
953 else if (controlType
== wxT("wxText") || controlType
== wxT("wxTextCtrl") || controlType
== wxT("wxMultiText"))
955 // Check for default value
956 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
958 wxString
str(expr
->Nth(count
)->StringValue());
959 controlItem
->SetValue4(str
);
962 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
964 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
965 // Skip past the obsolete label font spec if there are two consecutive specs
966 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
968 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
972 else if (controlType
== wxT("wxMessage") || controlType
== wxT("wxStaticText"))
974 // Check for bitmap resource name (in case it's an old-style .wxr file)
975 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
977 wxString
str(expr
->Nth(count
)->StringValue());
978 controlItem
->SetValue4(str
);
980 controlItem
->SetType(wxT("wxStaticText"));
982 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
983 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
985 else if (controlType
== wxT("wxStaticBitmap"))
987 // Check for bitmap resource name
988 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
990 wxString
str(expr
->Nth(count
)->StringValue());
991 controlItem
->SetValue4(str
);
994 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
995 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
997 else if (controlType
== wxT("wxGroupBox") || controlType
== wxT("wxStaticBox"))
999 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1000 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1002 else if (controlType
== wxT("wxGauge"))
1004 // Check for default value
1005 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1007 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1011 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1013 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1016 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1018 // Skip past the obsolete label font spec if there are two consecutive specs
1019 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1021 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1026 else if (controlType
== wxT("wxSlider"))
1028 // Check for default value
1029 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1031 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1035 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1037 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1041 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1043 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1046 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1048 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1052 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1053 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1059 else if (controlType
== wxT("wxScrollBar"))
1062 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1064 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1068 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1070 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1074 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1076 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1080 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1081 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
1086 else if (controlType
== wxT("wxListBox"))
1088 wxExpr
*valueList
= (wxExpr
*) NULL
;
1090 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1092 wxStringList stringList
;
1093 wxExpr
*stringExpr
= valueList
->GetFirst();
1096 stringList
.Add(stringExpr
->StringValue());
1097 stringExpr
= stringExpr
->GetNext();
1099 controlItem
->SetStringValues(stringList
);
1101 // This is now obsolete: it's in the window style.
1102 // Check for wxSINGLE/wxMULTIPLE
1103 wxExpr
*mult
= (wxExpr
*) NULL
;
1105 controlItem->SetValue1(wxLB_SINGLE);
1107 if (((mult
= expr
->Nth(count
)) != 0) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1110 wxString m(mult->StringValue());
1111 if (m == "wxLB_MULTIPLE")
1112 controlItem->SetValue1(wxLB_MULTIPLE);
1113 else if (m == "wxLB_EXTENDED")
1114 controlItem->SetValue1(wxLB_EXTENDED);
1119 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1121 // Skip past the obsolete label font spec if there are two consecutive specs
1122 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1124 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1128 else if (controlType
== wxT("wxChoice"))
1130 wxExpr
*valueList
= (wxExpr
*) NULL
;
1131 // Check for default value list
1132 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1134 wxStringList stringList
;
1135 wxExpr
*stringExpr
= valueList
->GetFirst();
1138 stringList
.Add(stringExpr
->StringValue());
1139 stringExpr
= stringExpr
->GetNext();
1141 controlItem
->SetStringValues(stringList
);
1145 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1147 // Skip past the obsolete label font spec if there are two consecutive specs
1148 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1150 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1155 else if (controlType
== wxT("wxComboBox"))
1157 wxExpr
*textValue
= expr
->Nth(count
);
1158 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1160 wxString
str(textValue
->StringValue());
1161 controlItem
->SetValue4(str
);
1165 wxExpr
*valueList
= (wxExpr
*) NULL
;
1166 // Check for default value list
1167 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1169 wxStringList stringList
;
1170 wxExpr
*stringExpr
= valueList
->GetFirst();
1173 stringList
.Add(stringExpr
->StringValue());
1174 stringExpr
= stringExpr
->GetNext();
1176 controlItem
->SetStringValues(stringList
);
1180 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1182 // Skip past the obsolete label font spec if there are two consecutive specs
1183 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1185 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1192 else if (controlType
== wxT("wxRadioBox"))
1194 wxExpr
*valueList
= (wxExpr
*) NULL
;
1195 // Check for default value list
1196 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1198 wxStringList stringList
;
1199 wxExpr
*stringExpr
= valueList
->GetFirst();
1202 stringList
.Add(stringExpr
->StringValue());
1203 stringExpr
= stringExpr
->GetNext();
1205 controlItem
->SetStringValues(stringList
);
1208 // majorDim (number of rows or cols)
1209 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1211 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1215 controlItem
->SetValue1(0);
1217 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1219 // Skip past the obsolete label font spec if there are two consecutive specs
1220 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1222 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1230 return (wxItemResource
*) NULL
;
1235 // Forward declaration
1236 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, wxExpr
*expr
);
1239 * Interpet a menu item
1242 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, wxExpr
*expr
)
1244 wxItemResource
*item
= new wxItemResource
;
1246 wxExpr
*labelExpr
= expr
->Nth(0);
1247 wxExpr
*idExpr
= expr
->Nth(1);
1248 wxExpr
*helpExpr
= expr
->Nth(2);
1249 wxExpr
*checkableExpr
= expr
->Nth(3);
1251 // Further keywords/attributes to follow sometime...
1252 if (expr
->Number() == 0)
1254 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1255 item
->SetType(wxT("wxMenuSeparator"));
1260 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1261 item
->SetType(wxT("wxMenu")); // Well, menu item, but doesn't matter.
1264 wxString
str(labelExpr
->StringValue());
1265 item
->SetTitle(str
);
1270 // If a string or word, must look up in identifier table.
1271 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1273 wxString
str(idExpr
->StringValue());
1274 id
= wxResourceGetIdentifier(str
, &table
);
1277 wxLogWarning(_("Could not resolve menu id '%s'. Use (non-zero) integer instead\nor provide #define (see manual for caveats)"),
1278 (const wxChar
*) idExpr
->StringValue());
1281 else if (idExpr
->Type() == PrologInteger
)
1282 id
= (int)idExpr
->IntegerValue();
1283 item
->SetValue1(id
);
1287 wxString
str(helpExpr
->StringValue());
1288 item
->SetValue4(str
);
1291 item
->SetValue2(checkableExpr
->IntegerValue());
1293 // Find the first expression that's a list, for submenu
1294 wxExpr
*subMenuExpr
= expr
->GetFirst();
1295 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1296 subMenuExpr
= subMenuExpr
->GetNext();
1300 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1301 item
->GetChildren().Append(child
);
1302 subMenuExpr
= subMenuExpr
->GetNext();
1309 * Interpret a nested list as a menu
1312 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1314 wxItemResource *menu = new wxItemResource;
1315 // menu->SetType(wxTYPE_MENU);
1316 menu->SetType("wxMenu");
1317 wxExpr *element = expr->GetFirst();
1320 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1322 menu->GetChildren().Append(item);
1323 element = element->GetNext();
1329 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
)
1331 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1332 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1334 return (wxItemResource
*) NULL
;
1336 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1339 return (wxItemResource
*) NULL
;
1342 if (expr
->GetAttributeValue(wxT("name"), name
))
1344 menuResource
->SetName(name
);
1347 return menuResource
;
1350 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
)
1352 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1353 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1355 return (wxItemResource
*) NULL
;
1357 wxItemResource
*resource
= new wxItemResource
;
1358 resource
->SetType(wxT("wxMenu"));
1359 // resource->SetType(wxTYPE_MENU);
1361 wxExpr
*element
= listExpr
->GetFirst();
1364 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1365 resource
->GetChildren().Append(menuResource
);
1366 element
= element
->GetNext();
1370 if (expr
->GetAttributeValue(wxT("name"), name
))
1372 resource
->SetName(name
);
1378 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), wxExpr
*WXUNUSED(expr
))
1380 return (wxItemResource
*) NULL
;
1383 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), wxExpr
*expr
)
1385 wxItemResource
*bitmapItem
= new wxItemResource
;
1386 // bitmapItem->SetType(wxTYPE_BITMAP);
1387 bitmapItem
->SetType(wxT("wxBitmap"));
1389 if (expr
->GetAttributeValue(wxT("name"), name
))
1391 bitmapItem
->SetName(name
);
1393 // Now parse all bitmap specifications
1394 wxExpr
*bitmapExpr
= expr
->GetFirst();
1397 if (bitmapExpr
->Number() == 3)
1399 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1400 if (bitmapKeyword
== wxT("bitmap") || bitmapKeyword
== wxT("icon"))
1402 // The value part: always a list.
1403 wxExpr
*listExpr
= bitmapExpr
->Nth(2);
1404 if (listExpr
->Type() == PrologList
)
1406 wxItemResource
*bitmapSpec
= new wxItemResource
;
1407 // bitmapSpec->SetType(wxTYPE_BITMAP);
1408 bitmapSpec
->SetType(wxT("wxBitmap"));
1410 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1411 // where everything after 'filename' is optional.
1412 wxExpr
*nameExpr
= listExpr
->Nth(0);
1413 wxExpr
*typeExpr
= listExpr
->Nth(1);
1414 wxExpr
*platformExpr
= listExpr
->Nth(2);
1415 wxExpr
*coloursExpr
= listExpr
->Nth(3);
1416 wxExpr
*xresExpr
= listExpr
->Nth(4);
1417 wxExpr
*yresExpr
= listExpr
->Nth(5);
1418 if (nameExpr
&& !nameExpr
->StringValue().empty())
1420 bitmapSpec
->SetName(nameExpr
->StringValue());
1422 if (typeExpr
&& !typeExpr
->StringValue().empty())
1424 bitmapSpec
->SetValue1(wxParseWindowStyle(typeExpr
->StringValue()));
1427 bitmapSpec
->SetValue1(0);
1429 if (platformExpr
&& !platformExpr
->StringValue().empty())
1431 wxString
plat(platformExpr
->StringValue());
1432 if (plat
== wxT("windows") || plat
== wxT("WINDOWS"))
1433 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1434 else if (plat
== wxT("x") || plat
== wxT("X"))
1435 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1436 else if (plat
== wxT("mac") || plat
== wxT("MAC"))
1437 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1439 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1442 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1445 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1449 xres
= (int)xresExpr
->IntegerValue();
1451 yres
= (int)yresExpr
->IntegerValue();
1452 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1454 bitmapItem
->GetChildren().Append(bitmapSpec
);
1458 bitmapExpr
= bitmapExpr
->GetNext();
1464 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
)
1466 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1469 // item->SetType(wxTYPE_ICON);
1470 item
->SetType(wxT("wxIcon"));
1474 return (wxItemResource
*) NULL
;
1477 // Interpret list expression as a font
1478 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
)
1480 if (expr
->Type() != PrologList
)
1484 int family
= wxSWISS
;
1485 int style
= wxNORMAL
;
1486 int weight
= wxNORMAL
;
1490 wxExpr
*pointExpr
= expr
->Nth(0);
1491 wxExpr
*familyExpr
= expr
->Nth(1);
1492 wxExpr
*styleExpr
= expr
->Nth(2);
1493 wxExpr
*weightExpr
= expr
->Nth(3);
1494 wxExpr
*underlineExpr
= expr
->Nth(4);
1495 wxExpr
*faceNameExpr
= expr
->Nth(5);
1497 point
= (int)pointExpr
->IntegerValue();
1502 str
= familyExpr
->StringValue();
1503 family
= (int)wxParseWindowStyle(str
);
1507 str
= styleExpr
->StringValue();
1508 style
= (int)wxParseWindowStyle(str
);
1512 str
= weightExpr
->StringValue();
1513 weight
= (int)wxParseWindowStyle(str
);
1516 underline
= (int)underlineExpr
->IntegerValue();
1518 faceName
= faceNameExpr
->StringValue();
1520 return *wxTheFontList
->FindOrCreateFont(point
, family
, style
, weight
,
1521 (underline
!= 0), faceName
);
1525 * (Re)allocate buffer for reading in from resource file
1528 bool wxReallocateResourceBuffer()
1530 if (!wxResourceBuffer
)
1532 wxResourceBufferSize
= 1000;
1533 wxResourceBuffer
= new char[wxResourceBufferSize
];
1536 if (wxResourceBuffer
)
1538 long newSize
= wxResourceBufferSize
+ 1000;
1539 char *tmp
= new char[(int)newSize
];
1540 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1541 delete[] wxResourceBuffer
;
1542 wxResourceBuffer
= tmp
;
1543 wxResourceBufferSize
= newSize
;
1548 static bool wxEatWhiteSpace(FILE *fd
)
1552 while ((ch
= getc(fd
)) != EOF
)
1567 ungetc(prev_ch
, fd
);
1575 while ((ch
= getc(fd
)) != EOF
)
1577 if (ch
== '/' && prev_ch
== '*')
1585 static char buffer
[255];
1586 fgets(buffer
, 255, fd
);
1590 ungetc(prev_ch
, fd
);
1604 static bool wxEatWhiteSpace(wxInputStream
*is
)
1606 char ch
= is
->GetC() ;
1607 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
1614 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
1616 // Check for comment
1622 bool finished
= false;
1626 if (is
->LastRead() == 0)
1630 int newCh
= is
->GetC();
1645 return wxEatWhiteSpace(is
);
1648 bool wxGetResourceToken(FILE *fd
)
1650 if (!wxResourceBuffer
)
1651 wxReallocateResourceBuffer();
1652 wxResourceBuffer
[0] = 0;
1653 wxEatWhiteSpace(fd
);
1659 wxResourceBufferCount
= 0;
1666 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1669 // Escaped characters
1670 else if (ch
== '\\')
1672 int newCh
= getc(fd
);
1675 else if (newCh
== 10)
1683 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1684 wxReallocateResourceBuffer();
1685 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1686 wxResourceBufferCount
++;
1689 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1693 wxResourceBufferCount
= 0;
1695 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1697 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1698 wxReallocateResourceBuffer();
1699 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1700 wxResourceBufferCount
++;
1704 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1711 bool wxGetResourceToken(wxInputStream
*is
)
1713 if (!wxResourceBuffer
)
1714 wxReallocateResourceBuffer();
1715 wxResourceBuffer
[0] = 0;
1716 wxEatWhiteSpace(is
);
1718 int ch
= is
->GetC() ;
1722 wxResourceBufferCount
= 0;
1729 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1732 // Escaped characters
1733 else if (ch
== '\\')
1735 char newCh
= is
->GetC();
1738 else if (newCh
== 10)
1740 else if (newCh
== 13) // mac
1748 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1749 wxReallocateResourceBuffer();
1750 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1751 wxResourceBufferCount
++;
1754 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1758 wxResourceBufferCount
= 0;
1760 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1762 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1763 wxReallocateResourceBuffer();
1764 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1765 wxResourceBufferCount
++;
1769 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1777 * Files are in form:
1778 static char *name = "....";
1779 with possible comments.
1782 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1785 table
= wxDefaultResourceTable
;
1787 // static or #define
1788 if (!wxGetResourceToken(fd
))
1794 if (strcmp(wxResourceBuffer
, "#define") == 0)
1796 wxGetResourceToken(fd
);
1797 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1798 wxGetResourceToken(fd
);
1799 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1800 if (wxIsdigit(value
[0]))
1802 int val
= (int)wxAtol(value
);
1803 wxResourceAddIdentifier(name
, val
, table
);
1807 wxLogWarning(_("#define %s must be an integer."), name
);
1817 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1819 wxGetResourceToken(fd
);
1820 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1821 wxChar
*actualName
= name
;
1822 if (name
[0] == wxT('"'))
1823 actualName
= name
+ 1;
1824 int len
= wxStrlen(name
);
1825 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1827 if (!wxResourceParseIncludeFile(actualName
, table
))
1829 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1834 else if (strcmp(wxResourceBuffer
, "static") != 0)
1837 wxStrcpy(buf
, _("Found "));
1838 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
1839 wxStrcat(buf
, _(", expected static, #include or #define\nwhile parsing resource."));
1845 if (!wxGetResourceToken(fd
))
1847 wxLogWarning(_("Unexpected end of file while parsing resource."));
1852 if (strcmp(wxResourceBuffer
, "char") != 0)
1854 wxLogWarning(_("Expected 'char' while parsing resource."));
1859 if (!wxGetResourceToken(fd
))
1861 wxLogWarning(_("Unexpected end of file while parsing resource."));
1866 if (wxResourceBuffer
[0] != '*')
1868 wxLogWarning(_("Expected '*' while parsing resource."));
1871 wxChar nameBuf
[100];
1872 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
1876 if (!wxGetResourceToken(fd
))
1878 wxLogWarning(_("Unexpected end of file while parsing resource."));
1883 if (strcmp(wxResourceBuffer
, "=") != 0)
1885 wxLogWarning(_("Expected '=' while parsing resource."));
1890 if (!wxGetResourceToken(fd
))
1892 wxLogWarning(_("Unexpected end of file while parsing resource."));
1898 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1900 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1905 if (!wxGetResourceToken(fd
))
1912 bool wxResourceReadOneResource(wxInputStream
*fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1915 table
= wxDefaultResourceTable
;
1917 // static or #define
1918 if (!wxGetResourceToken(fd
))
1924 if (strcmp(wxResourceBuffer
, "#define") == 0)
1926 wxGetResourceToken(fd
);
1927 wxChar
*name
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1928 wxGetResourceToken(fd
);
1929 wxChar
*value
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1930 if (wxIsalpha(value
[0]))
1932 int val
= (int)wxAtol(value
);
1933 wxResourceAddIdentifier(name
, val
, table
);
1937 wxLogWarning(_("#define %s must be an integer."), name
);
1947 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1949 wxGetResourceToken(fd
);
1950 wxChar
*name
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1951 wxChar
*actualName
= name
;
1952 if (name
[0] == wxT('"'))
1953 actualName
= name
+ 1;
1954 int len
= wxStrlen(name
);
1955 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1957 if (!wxResourceParseIncludeFile(actualName
, table
))
1959 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1964 else if (strcmp(wxResourceBuffer
, "static") != 0)
1967 wxStrcpy(buf
, _("Found "));
1968 wxStrncat(buf
, wxConvLibc
.cMB2WX(wxResourceBuffer
), 30);
1969 wxStrcat(buf
, _(", expected static, #include or #define\nwhile parsing resource."));
1975 if (!wxGetResourceToken(fd
))
1977 wxLogWarning(_("Unexpected end of file while parsing resource."));
1982 if (strcmp(wxResourceBuffer
, "char") != 0)
1984 wxLogWarning(_("Expected 'char' while parsing resource."));
1989 if (!wxGetResourceToken(fd
))
1991 wxLogWarning(_("Unexpected end of file while parsing resource."));
1996 if (wxResourceBuffer
[0] != '*')
1998 wxLogWarning(_("Expected '*' while parsing resource."));
2002 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
2005 if (!wxGetResourceToken(fd
))
2007 wxLogWarning(_("Unexpected end of file while parsing resource."));
2012 if (strcmp(wxResourceBuffer
, "=") != 0)
2014 wxLogWarning(_("Expected '=' while parsing resource."));
2019 if (!wxGetResourceToken(fd
))
2021 wxLogWarning(_("Unexpected end of file while parsing resource."));
2027 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2029 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2034 if (!wxGetResourceToken(fd
))
2042 * Parses string window style into integer window style
2046 * Style flag parsing, e.g.
2047 * "wxSYSTEM_MENU | wxBORDER" -> integer
2050 wxChar
* wxResourceParseWord(wxChar
*s
, int *i
)
2053 return (wxChar
*) NULL
;
2055 static wxChar buf
[150];
2056 int len
= wxStrlen(s
);
2059 while ((ii
< len
) && (wxIsalpha(s
[ii
]) || (s
[ii
] == wxT('_'))))
2067 // Eat whitespace and conjunction characters
2068 while ((ii
< len
) &&
2069 ((s
[ii
] == wxT(' ')) || (s
[ii
] == wxT('|')) || (s
[ii
] == wxT(','))))
2075 return (wxChar
*) NULL
;
2080 struct wxResourceBitListStruct
2086 static wxResourceBitListStruct wxResourceBitListTable
[] =
2089 { wxT("wxSINGLE"), wxLB_SINGLE
},
2090 { wxT("wxMULTIPLE"), wxLB_MULTIPLE
},
2091 { wxT("wxEXTENDED"), wxLB_EXTENDED
},
2092 { wxT("wxLB_SINGLE"), wxLB_SINGLE
},
2093 { wxT("wxLB_MULTIPLE"), wxLB_MULTIPLE
},
2094 { wxT("wxLB_EXTENDED"), wxLB_EXTENDED
},
2095 { wxT("wxLB_NEEDED_SB"), wxLB_NEEDED_SB
},
2096 { wxT("wxLB_ALWAYS_SB"), wxLB_ALWAYS_SB
},
2097 { wxT("wxLB_SORT"), wxLB_SORT
},
2098 { wxT("wxLB_OWNERDRAW"), wxLB_OWNERDRAW
},
2099 { wxT("wxLB_HSCROLL"), wxLB_HSCROLL
},
2102 { wxT("wxCB_SIMPLE"), wxCB_SIMPLE
},
2103 { wxT("wxCB_DROPDOWN"), wxCB_DROPDOWN
},
2104 { wxT("wxCB_READONLY"), wxCB_READONLY
},
2105 { wxT("wxCB_SORT"), wxCB_SORT
},
2108 #if WXWIN_COMPATIBILITY_2_6
2109 { wxT("wxGA_PROGRESSBAR"), wxGA_PROGRESSBAR
},
2110 #endif // WXWIN_COMPATIBILITY_2_6
2111 { wxT("wxGA_HORIZONTAL"), wxGA_HORIZONTAL
},
2112 { wxT("wxGA_VERTICAL"), wxGA_VERTICAL
},
2115 #if WXWIN_COMPATIBILITY_2_6
2116 { wxT("wxPASSWORD"), wxTE_PASSWORD
},
2117 { wxT("wxPROCESS_ENTER"), wxTE_PROCESS_ENTER
},
2119 { wxT("wxTE_PASSWORD"), wxTE_PASSWORD
},
2120 { wxT("wxTE_READONLY"), wxTE_READONLY
},
2121 { wxT("wxTE_PROCESS_ENTER"), wxTE_PROCESS_ENTER
},
2122 { wxT("wxTE_MULTILINE"), wxTE_MULTILINE
},
2123 { wxT("wxTE_NO_VSCROLL"), wxTE_NO_VSCROLL
},
2125 /* wxRadioBox/wxRadioButton */
2126 { wxT("wxRB_GROUP"), wxRB_GROUP
},
2127 { wxT("wxRA_SPECIFY_COLS"), wxRA_SPECIFY_COLS
},
2128 { wxT("wxRA_SPECIFY_ROWS"), wxRA_SPECIFY_ROWS
},
2129 { wxT("wxRA_HORIZONTAL"), wxRA_HORIZONTAL
},
2130 { wxT("wxRA_VERTICAL"), wxRA_VERTICAL
},
2133 { wxT("wxSL_HORIZONTAL"), wxSL_HORIZONTAL
},
2134 { wxT("wxSL_VERTICAL"), wxSL_VERTICAL
},
2135 { wxT("wxSL_AUTOTICKS"), wxSL_AUTOTICKS
},
2136 { wxT("wxSL_LABELS"), wxSL_LABELS
},
2137 { wxT("wxSL_LEFT"), wxSL_LEFT
},
2138 { wxT("wxSL_TOP"), wxSL_TOP
},
2139 { wxT("wxSL_RIGHT"), wxSL_RIGHT
},
2140 { wxT("wxSL_BOTTOM"), wxSL_BOTTOM
},
2141 { wxT("wxSL_BOTH"), wxSL_BOTH
},
2142 { wxT("wxSL_SELRANGE"), wxSL_SELRANGE
},
2145 { wxT("wxSB_HORIZONTAL"), wxSB_HORIZONTAL
},
2146 { wxT("wxSB_VERTICAL"), wxSB_VERTICAL
},
2149 { wxT("wxBU_AUTODRAW"), wxBU_AUTODRAW
},
2150 { wxT("wxBU_NOAUTODRAW"), wxBU_NOAUTODRAW
},
2153 { wxT("wxTR_HAS_BUTTONS"), wxTR_HAS_BUTTONS
},
2154 { wxT("wxTR_EDIT_LABELS"), wxTR_EDIT_LABELS
},
2155 { wxT("wxTR_LINES_AT_ROOT"), wxTR_LINES_AT_ROOT
},
2158 { wxT("wxLC_ICON"), wxLC_ICON
},
2159 { wxT("wxLC_SMALL_ICON"), wxLC_SMALL_ICON
},
2160 { wxT("wxLC_LIST"), wxLC_LIST
},
2161 { wxT("wxLC_REPORT"), wxLC_REPORT
},
2162 { wxT("wxLC_ALIGN_TOP"), wxLC_ALIGN_TOP
},
2163 { wxT("wxLC_ALIGN_LEFT"), wxLC_ALIGN_LEFT
},
2164 { wxT("wxLC_AUTOARRANGE"), wxLC_AUTOARRANGE
},
2165 { wxT("wxLC_USER_TEXT"), wxLC_USER_TEXT
},
2166 { wxT("wxLC_EDIT_LABELS"), wxLC_EDIT_LABELS
},
2167 { wxT("wxLC_NO_HEADER"), wxLC_NO_HEADER
},
2168 { wxT("wxLC_NO_SORT_HEADER"), wxLC_NO_SORT_HEADER
},
2169 { wxT("wxLC_SINGLE_SEL"), wxLC_SINGLE_SEL
},
2170 { wxT("wxLC_SORT_ASCENDING"), wxLC_SORT_ASCENDING
},
2171 { wxT("wxLC_SORT_DESCENDING"), wxLC_SORT_DESCENDING
},
2174 { wxT("wxSP_VERTICAL"), wxSP_VERTICAL
},
2175 { wxT("wxSP_HORIZONTAL"), wxSP_HORIZONTAL
},
2176 { wxT("wxSP_ARROW_KEYS"), wxSP_ARROW_KEYS
},
2177 { wxT("wxSP_WRAP"), wxSP_WRAP
},
2180 { wxT("wxSP_NOBORDER"), wxSP_NOBORDER
},
2181 { wxT("wxSP_3D"), wxSP_3D
},
2182 { wxT("wxSP_BORDER"), wxSP_BORDER
},
2185 { wxT("wxTC_MULTILINE"), wxTC_MULTILINE
},
2186 { wxT("wxTC_RIGHTJUSTIFY"), wxTC_RIGHTJUSTIFY
},
2187 { wxT("wxTC_FIXEDWIDTH"), wxTC_FIXEDWIDTH
},
2188 { wxT("wxTC_OWNERDRAW"), wxTC_OWNERDRAW
},
2191 { wxT("wxST_SIZEGRIP"), wxST_SIZEGRIP
},
2194 { wxT("wxFIXED_LENGTH"), wxFIXED_LENGTH
},
2195 { wxT("wxALIGN_LEFT"), wxALIGN_LEFT
},
2196 { wxT("wxALIGN_CENTER"), wxALIGN_CENTER
},
2197 { wxT("wxALIGN_CENTRE"), wxALIGN_CENTRE
},
2198 { wxT("wxALIGN_RIGHT"), wxALIGN_RIGHT
},
2199 { wxT("wxCOLOURED"), wxCOLOURED
},
2202 { wxT("wxTB_3DBUTTONS"), wxTB_3DBUTTONS
},
2203 { wxT("wxTB_HORIZONTAL"), wxTB_HORIZONTAL
},
2204 { wxT("wxTB_VERTICAL"), wxTB_VERTICAL
},
2205 { wxT("wxTB_FLAT"), wxTB_FLAT
},
2207 #if WXWIN_COMPATIBILITY_2_6
2209 { wxT("wxDIALOG_MODAL"), wxDIALOG_MODAL
},
2210 #endif // WXWIN_COMPATIBILITY_2_6
2213 { wxT("wxVSCROLL"), wxVSCROLL
},
2214 { wxT("wxHSCROLL"), wxHSCROLL
},
2215 { wxT("wxCAPTION"), wxCAPTION
},
2216 { wxT("wxSTAY_ON_TOP"), wxSTAY_ON_TOP
},
2217 { wxT("wxICONIZE"), wxICONIZE
},
2218 { wxT("wxMINIMIZE"), wxICONIZE
},
2219 { wxT("wxMAXIMIZE"), wxMAXIMIZE
},
2221 { wxT("wxMDI_PARENT"), 0},
2222 { wxT("wxMDI_CHILD"), 0},
2223 { wxT("wxTHICK_FRAME"), wxRESIZE_BORDER
},
2224 { wxT("wxRESIZE_BORDER"), wxRESIZE_BORDER
},
2225 { wxT("wxSYSTEM_MENU"), wxSYSTEM_MENU
},
2226 { wxT("wxMINIMIZE_BOX"), wxMINIMIZE_BOX
},
2227 { wxT("wxMAXIMIZE_BOX"), wxMAXIMIZE_BOX
},
2228 #if WXWIN_COMPATIBILITY_2_6
2229 { wxT("wxRESIZE_BOX"), wxRESIZE_BOX
},
2230 #endif // WXWIN_COMPATIBILITY_2_6
2231 { wxT("wxDEFAULT_FRAME_STYLE"), wxDEFAULT_FRAME_STYLE
},
2232 { wxT("wxDEFAULT_FRAME"), wxDEFAULT_FRAME_STYLE
},
2233 { wxT("wxDEFAULT_DIALOG_STYLE"), wxDEFAULT_DIALOG_STYLE
},
2234 { wxT("wxBORDER"), wxBORDER
},
2235 { wxT("wxRETAINED"), wxRETAINED
},
2236 { wxT("wxNATIVE_IMPL"), 0},
2237 { wxT("wxEXTENDED_IMPL"), 0},
2238 { wxT("wxBACKINGSTORE"), wxBACKINGSTORE
},
2239 // { wxT("wxFLAT"), wxFLAT},
2240 // { wxT("wxMOTIF_RESIZE"), wxMOTIF_RESIZE},
2241 { wxT("wxFIXED_LENGTH"), 0},
2242 { wxT("wxDOUBLE_BORDER"), wxDOUBLE_BORDER
},
2243 { wxT("wxSUNKEN_BORDER"), wxSUNKEN_BORDER
},
2244 { wxT("wxRAISED_BORDER"), wxRAISED_BORDER
},
2245 { wxT("wxSIMPLE_BORDER"), wxSIMPLE_BORDER
},
2246 { wxT("wxSTATIC_BORDER"), wxSTATIC_BORDER
},
2247 { wxT("wxTRANSPARENT_WINDOW"), wxTRANSPARENT_WINDOW
},
2248 { wxT("wxNO_BORDER"), wxNO_BORDER
},
2249 { wxT("wxCLIP_CHILDREN"), wxCLIP_CHILDREN
},
2250 { wxT("wxCLIP_SIBLINGS"), wxCLIP_SIBLINGS
},
2251 { wxT("wxTAB_TRAVERSAL"), 0}, // Compatibility only
2253 { wxT("wxTINY_CAPTION_HORIZ"), wxTINY_CAPTION_HORIZ
},
2254 { wxT("wxTINY_CAPTION_VERT"), wxTINY_CAPTION_VERT
},
2256 // Text font families
2257 { wxT("wxDEFAULT"), wxDEFAULT
},
2258 { wxT("wxDECORATIVE"), wxDECORATIVE
},
2259 { wxT("wxROMAN"), wxROMAN
},
2260 { wxT("wxSCRIPT"), wxSCRIPT
},
2261 { wxT("wxSWISS"), wxSWISS
},
2262 { wxT("wxMODERN"), wxMODERN
},
2263 { wxT("wxTELETYPE"), wxTELETYPE
},
2264 { wxT("wxVARIABLE"), wxVARIABLE
},
2265 { wxT("wxFIXED"), wxFIXED
},
2266 { wxT("wxNORMAL"), wxNORMAL
},
2267 { wxT("wxLIGHT"), wxLIGHT
},
2268 { wxT("wxBOLD"), wxBOLD
},
2269 { wxT("wxITALIC"), wxITALIC
},
2270 { wxT("wxSLANT"), wxSLANT
},
2271 { wxT("wxSOLID"), wxSOLID
},
2272 { wxT("wxDOT"), wxDOT
},
2273 { wxT("wxLONG_DASH"), wxLONG_DASH
},
2274 { wxT("wxSHORT_DASH"), wxSHORT_DASH
},
2275 { wxT("wxDOT_DASH"), wxDOT_DASH
},
2276 { wxT("wxUSER_DASH"), wxUSER_DASH
},
2277 { wxT("wxTRANSPARENT"), wxTRANSPARENT
},
2278 { wxT("wxSTIPPLE"), wxSTIPPLE
},
2279 { wxT("wxBDIAGONAL_HATCH"), wxBDIAGONAL_HATCH
},
2280 { wxT("wxCROSSDIAG_HATCH"), wxCROSSDIAG_HATCH
},
2281 { wxT("wxFDIAGONAL_HATCH"), wxFDIAGONAL_HATCH
},
2282 { wxT("wxCROSS_HATCH"), wxCROSS_HATCH
},
2283 { wxT("wxHORIZONTAL_HATCH"), wxHORIZONTAL_HATCH
},
2284 { wxT("wxVERTICAL_HATCH"), wxVERTICAL_HATCH
},
2285 { wxT("wxJOIN_BEVEL"), wxJOIN_BEVEL
},
2286 { wxT("wxJOIN_MITER"), wxJOIN_MITER
},
2287 { wxT("wxJOIN_ROUND"), wxJOIN_ROUND
},
2288 { wxT("wxCAP_ROUND"), wxCAP_ROUND
},
2289 { wxT("wxCAP_PROJECTING"), wxCAP_PROJECTING
},
2290 { wxT("wxCAP_BUTT"), wxCAP_BUTT
},
2293 { wxT("wxCLEAR"), wxCLEAR
},
2294 { wxT("wxXOR"), wxXOR
},
2295 { wxT("wxINVERT"), wxINVERT
},
2296 { wxT("wxOR_REVERSE"), wxOR_REVERSE
},
2297 { wxT("wxAND_REVERSE"), wxAND_REVERSE
},
2298 { wxT("wxCOPY"), wxCOPY
},
2299 { wxT("wxAND"), wxAND
},
2300 { wxT("wxAND_INVERT"), wxAND_INVERT
},
2301 { wxT("wxNO_OP"), wxNO_OP
},
2302 { wxT("wxNOR"), wxNOR
},
2303 { wxT("wxEQUIV"), wxEQUIV
},
2304 { wxT("wxSRC_INVERT"), wxSRC_INVERT
},
2305 { wxT("wxOR_INVERT"), wxOR_INVERT
},
2306 { wxT("wxNAND"), wxNAND
},
2307 { wxT("wxOR"), wxOR
},
2308 { wxT("wxSET"), wxSET
},
2310 { wxT("wxFLOOD_SURFACE"), wxFLOOD_SURFACE
},
2311 { wxT("wxFLOOD_BORDER"), wxFLOOD_BORDER
},
2312 { wxT("wxODDEVEN_RULE"), wxODDEVEN_RULE
},
2313 { wxT("wxWINDING_RULE"), wxWINDING_RULE
},
2314 { wxT("wxHORIZONTAL"), wxHORIZONTAL
},
2315 { wxT("wxVERTICAL"), wxVERTICAL
},
2316 { wxT("wxBOTH"), wxBOTH
},
2317 { wxT("wxCENTER_FRAME"), wxCENTER_FRAME
},
2318 { wxT("wxOK"), wxOK
},
2319 { wxT("wxYES_NO"), wxYES_NO
},
2320 { wxT("wxCANCEL"), wxCANCEL
},
2321 { wxT("wxYES"), wxYES
},
2322 { wxT("wxNO"), wxNO
},
2323 { wxT("wxICON_EXCLAMATION"), wxICON_EXCLAMATION
},
2324 { wxT("wxICON_HAND"), wxICON_HAND
},
2325 { wxT("wxICON_QUESTION"), wxICON_QUESTION
},
2326 { wxT("wxICON_INFORMATION"), wxICON_INFORMATION
},
2327 { wxT("wxICON_STOP"), wxICON_STOP
},
2328 { wxT("wxICON_ASTERISK"), wxICON_ASTERISK
},
2329 { wxT("wxICON_MASK"), wxICON_MASK
},
2330 { wxT("wxCENTRE"), wxCENTRE
},
2331 { wxT("wxCENTER"), wxCENTRE
},
2332 #if WXWIN_COMPATIBILITY_2_6
2333 { wxT("wxUSER_COLOURS"), wxUSER_COLOURS
},
2334 #endif // WXWIN_COMPATIBILITY_2_6
2335 { wxT("wxVERTICAL_LABEL"), 0},
2336 { wxT("wxHORIZONTAL_LABEL"), 0},
2338 // Bitmap types (not strictly styles)
2339 { wxT("wxBITMAP_TYPE_XPM"), wxBITMAP_TYPE_XPM
},
2340 { wxT("wxBITMAP_TYPE_XBM"), wxBITMAP_TYPE_XBM
},
2341 { wxT("wxBITMAP_TYPE_BMP"), wxBITMAP_TYPE_BMP
},
2342 { wxT("wxBITMAP_TYPE_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2343 { wxT("wxBITMAP_TYPE_BMP_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2344 { wxT("wxBITMAP_TYPE_GIF"), wxBITMAP_TYPE_GIF
},
2345 { wxT("wxBITMAP_TYPE_TIF"), wxBITMAP_TYPE_TIF
},
2346 { wxT("wxBITMAP_TYPE_ICO"), wxBITMAP_TYPE_ICO
},
2347 { wxT("wxBITMAP_TYPE_ICO_RESOURCE"), wxBITMAP_TYPE_ICO_RESOURCE
},
2348 { wxT("wxBITMAP_TYPE_CUR"), wxBITMAP_TYPE_CUR
},
2349 { wxT("wxBITMAP_TYPE_CUR_RESOURCE"), wxBITMAP_TYPE_CUR_RESOURCE
},
2350 { wxT("wxBITMAP_TYPE_XBM_DATA"), wxBITMAP_TYPE_XBM_DATA
},
2351 { wxT("wxBITMAP_TYPE_XPM_DATA"), wxBITMAP_TYPE_XPM_DATA
},
2352 { wxT("wxBITMAP_TYPE_ANY"), wxBITMAP_TYPE_ANY
}
2355 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
2357 long wxParseWindowStyle(const wxString
& bitListString
)
2362 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2363 while (word
!= NULL
)
2367 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2368 if (wxStrcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2370 bitList
|= wxResourceBitListTable
[j
].bits
;
2376 wxLogWarning(_("Unrecognized style %s while parsing resource."), word
);
2379 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2385 * Load a bitmap from a wxWidgets resource, choosing an optimum
2386 * depth and appropriate type.
2389 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
2392 table
= wxDefaultResourceTable
;
2394 wxItemResource
*item
= table
->FindResource(resource
);
2397 if ((item
->GetType().empty()) || (item
->GetType() != wxT("wxBitmap")))
2399 wxLogWarning(_("%s not a bitmap resource specification."), (const wxChar
*) resource
);
2400 return wxNullBitmap
;
2402 int thisDepth
= wxDisplayDepth();
2403 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2405 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2407 // Try to find optimum bitmap for this platform/colour depth
2408 wxNode
*node
= item
->GetChildren().GetFirst();
2411 wxItemResource
*child
= (wxItemResource
*)node
->GetData();
2412 int platform
= (int)child
->GetValue2();
2413 int noColours
= (int)child
->GetValue3();
2415 char *name = child->GetName();
2416 int bitmapType = (int)child->GetValue1();
2417 int xRes = child->GetWidth();
2418 int yRes = child->GetHeight();
2423 case RESOURCE_PLATFORM_ANY
:
2425 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2426 optResource
= child
;
2429 // Maximise the number of colours.
2430 // If noColours is zero (unspecified), then assume this
2431 // is the right one.
2432 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2433 optResource
= child
;
2438 case RESOURCE_PLATFORM_WINDOWS
:
2440 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2441 optResource
= child
;
2444 // Maximise the number of colours
2445 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2446 optResource
= child
;
2452 case RESOURCE_PLATFORM_X
:
2454 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2455 optResource
= child
;
2458 // Maximise the number of colours
2459 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2460 optResource
= child
;
2466 case RESOURCE_PLATFORM_MAC
:
2468 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2469 optResource
= child
;
2472 // Maximise the number of colours
2473 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2474 optResource
= child
;
2482 node
= node
->GetNext();
2484 // If no matching resource, fail.
2486 return wxNullBitmap
;
2488 wxString name
= optResource
->GetName();
2489 int bitmapType
= (int)optResource
->GetValue1();
2492 case wxBITMAP_TYPE_XBM_DATA
:
2495 wxItemResource
*item
= table
->FindResource(name
);
2498 wxLogWarning(_("Failed to find XBM resource %s.\n"
2499 "Forgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2500 return wxNullBitmap
;
2502 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2504 wxLogWarning(_("No XBM facility available!"));
2508 case wxBITMAP_TYPE_XPM_DATA
:
2510 wxItemResource
*item
= table
->FindResource(name
);
2513 wxLogWarning(_("Failed to find XPM resource %s.\nForgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2514 return wxNullBitmap
;
2516 return wxBitmap((char **)item
->GetValue1());
2520 #if defined(__WXPM__)
2521 return wxNullBitmap
;
2523 return wxBitmap(name
, (wxBitmapType
)bitmapType
);
2528 return wxNullBitmap
;
2533 wxLogWarning(_("Bitmap resource specification %s not found."), (const wxChar
*) resource
);
2534 return wxNullBitmap
;
2539 * Load an icon from a wxWidgets resource, choosing an optimum
2540 * depth and appropriate type.
2543 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2546 table
= wxDefaultResourceTable
;
2548 wxItemResource
*item
= table
->FindResource(resource
);
2551 if ((item
->GetType().empty()) || wxStrcmp(item
->GetType(), wxT("wxIcon")) != 0)
2553 wxLogWarning(_("%s not an icon resource specification."), (const wxChar
*) resource
);
2556 int thisDepth
= wxDisplayDepth();
2557 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2559 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2561 // Try to find optimum icon for this platform/colour depth
2562 wxNode
*node
= item
->GetChildren().GetFirst();
2565 wxItemResource
*child
= (wxItemResource
*)node
->GetData();
2566 int platform
= (int)child
->GetValue2();
2567 int noColours
= (int)child
->GetValue3();
2569 char *name = child->GetName();
2570 int bitmapType = (int)child->GetValue1();
2571 int xRes = child->GetWidth();
2572 int yRes = child->GetHeight();
2577 case RESOURCE_PLATFORM_ANY
:
2579 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2580 optResource
= child
;
2583 // Maximise the number of colours.
2584 // If noColours is zero (unspecified), then assume this
2585 // is the right one.
2586 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2587 optResource
= child
;
2592 case RESOURCE_PLATFORM_WINDOWS
:
2594 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2595 optResource
= child
;
2598 // Maximise the number of colours
2599 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2600 optResource
= child
;
2606 case RESOURCE_PLATFORM_X
:
2608 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2609 optResource
= child
;
2612 // Maximise the number of colours
2613 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2614 optResource
= child
;
2620 case RESOURCE_PLATFORM_MAC
:
2622 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2623 optResource
= child
;
2626 // Maximise the number of colours
2627 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2628 optResource
= child
;
2636 node
= node
->GetNext();
2638 // If no matching resource, fail.
2642 wxString name
= optResource
->GetName();
2643 int bitmapType
= (int)optResource
->GetValue1();
2646 case wxBITMAP_TYPE_XBM_DATA
:
2649 wxItemResource
*item
= table
->FindResource(name
);
2652 wxLogWarning(_("Failed to find XBM resource %s.\n"
2653 "Forgot to use wxResourceLoadIconData?"), (const wxChar
*) name
);
2656 return wxIcon((const char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2658 wxLogWarning(_("No XBM facility available!"));
2662 case wxBITMAP_TYPE_XPM_DATA
:
2664 // *** XPM ICON NOT YET IMPLEMENTED IN wxWidgets ***
2666 wxItemResource *item = table->FindResource(name);
2670 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2674 return wxIcon((char **)item->GetValue1());
2676 wxLogWarning(_("No XPM icon facility available!"));
2681 #if defined( __WXGTK__ ) || defined( __WXMOTIF__ )
2682 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2685 return wxIcon(name
, (wxBitmapType
) bitmapType
);
2693 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2700 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2702 wxMenu
*menu
= new wxMenu
;
2703 wxNode
*node
= item
->GetChildren().GetFirst();
2706 wxItemResource
*child
= (wxItemResource
*)node
->GetData();
2707 if ((!child
->GetType().empty()) && (child
->GetType() == wxT("wxMenuSeparator")))
2708 menu
->AppendSeparator();
2709 else if (child
->GetChildren().GetCount() > 0)
2711 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2713 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2717 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2719 node
= node
->GetNext();
2724 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2727 table
= wxDefaultResourceTable
;
2729 wxItemResource
*menuResource
= table
->FindResource(resource
);
2730 if (menuResource
&& (!menuResource
->GetType().empty()) && (menuResource
->GetType() == wxT("wxMenu")))
2733 menuBar
= new wxMenuBar
;
2734 wxNode
*node
= menuResource
->GetChildren().GetFirst();
2737 wxItemResource
*child
= (wxItemResource
*)node
->GetData();
2738 wxMenu
*menu
= wxResourceCreateMenu(child
);
2740 menuBar
->Append(menu
, child
->GetTitle());
2741 node
= node
->GetNext();
2745 return (wxMenuBar
*) NULL
;
2748 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2751 table
= wxDefaultResourceTable
;
2753 wxItemResource
*menuResource
= table
->FindResource(resource
);
2754 if (menuResource
&& (!menuResource
->GetType().empty()) && (menuResource
->GetType() == wxT("wxMenu")))
2755 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2756 return wxResourceCreateMenu(menuResource
);
2757 return (wxMenu
*) NULL
;
2760 #endif // wxUSE_MENUS
2762 // Global equivalents (so don't have to refer to default table explicitly)
2763 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2766 table
= wxDefaultResourceTable
;
2768 return table
->ParseResourceData(resource
);
2771 bool wxResourceParseData(const char* resource
, wxResourceTable
*table
)
2773 wxString
str(resource
, wxConvLibc
);
2775 table
= wxDefaultResourceTable
;
2777 return table
->ParseResourceData(str
);
2780 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2783 table
= wxDefaultResourceTable
;
2785 return table
->ParseResourceFile(filename
);
2788 // Register XBM/XPM data
2789 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2792 table
= wxDefaultResourceTable
;
2794 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2797 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2800 table
= wxDefaultResourceTable
;
2802 return table
->RegisterResourceBitmapData(name
, data
);
2805 void wxResourceClear(wxResourceTable
*table
)
2808 table
= wxDefaultResourceTable
;
2810 table
->ClearTable();
2817 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2820 table
= wxDefaultResourceTable
;
2822 table
->identifiers
.Put(name
, (wxObject
*)(long)value
);
2826 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2829 table
= wxDefaultResourceTable
;
2831 return (int)(long)table
->identifiers
.Get(name
);
2835 * Parse #include file for #defines (only)
2838 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2841 table
= wxDefaultResourceTable
;
2843 FILE *fd
= wxFopen(f
, wxT("r"));
2848 while (wxGetResourceToken(fd
))
2850 if (strcmp(wxResourceBuffer
, "#define") == 0)
2852 wxGetResourceToken(fd
);
2853 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2854 wxGetResourceToken(fd
);
2855 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2856 if (wxIsdigit(value
[0]))
2858 int val
= (int)wxAtol(value
);
2859 wxResourceAddIdentifier(name
, val
, table
);
2870 * Reading strings as if they were .wxr files
2873 static int getc_string(char *s
)
2875 int ch
= s
[wxResourceStringPtr
];
2880 wxResourceStringPtr
++;
2885 static int ungetc_string()
2887 wxResourceStringPtr
--;
2891 bool wxEatWhiteSpaceString(char *s
)
2895 while ((ch
= getc_string(s
)) != EOF
)
2906 ch
= getc_string(s
);
2917 while ((ch
= getc_string(s
)) != EOF
)
2919 if (ch
== '/' && prev_ch
== '*')
2941 bool wxGetResourceTokenString(char *s
)
2943 if (!wxResourceBuffer
)
2944 wxReallocateResourceBuffer();
2945 wxResourceBuffer
[0] = 0;
2946 wxEatWhiteSpaceString(s
);
2948 int ch
= getc_string(s
);
2952 wxResourceBufferCount
= 0;
2953 ch
= getc_string(s
);
2959 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2962 // Escaped characters
2963 else if (ch
== '\\')
2965 int newCh
= getc_string(s
);
2968 else if (newCh
== 10)
2976 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2977 wxReallocateResourceBuffer();
2978 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2979 wxResourceBufferCount
++;
2980 ch
= getc_string(s
);
2982 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2986 wxResourceBufferCount
= 0;
2988 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2990 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2991 wxReallocateResourceBuffer();
2992 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2993 wxResourceBufferCount
++;
2995 ch
= getc_string(s
);
2997 wxResourceBuffer
[wxResourceBufferCount
] = 0;
3005 * Files are in form:
3006 static char *name = "....";
3007 with possible comments.
3010 bool wxResourceReadOneResourceString(char *s
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
3013 table
= wxDefaultResourceTable
;
3015 // static or #define
3016 if (!wxGetResourceTokenString(s
))
3022 if (strcmp(wxResourceBuffer
, "#define") == 0)
3024 wxGetResourceTokenString(s
);
3025 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
3026 wxGetResourceTokenString(s
);
3027 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
3028 if (wxIsdigit(value
[0]))
3030 int val
= (int)wxAtol(value
);
3031 wxResourceAddIdentifier(name
, val
, table
);
3035 wxLogWarning(_("#define %s must be an integer."), name
);
3046 else if (strcmp(wxResourceBuffer, "#include") == 0)
3048 wxGetResourceTokenString(s);
3049 char *name = copystring(wxResourceBuffer);
3050 char *actualName = name;
3052 actualName = name + 1;
3053 int len = strlen(name);
3054 if ((len > 0) && (name[len-1] == '"'))
3056 if (!wxResourceParseIncludeFile(actualName, table))
3059 sprintf(buf, _("Could not find resource include file %s."), actualName);
3066 else if (strcmp(wxResourceBuffer
, "static") != 0)
3069 wxStrcpy(buf
, _("Found "));
3070 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
3071 wxStrcat(buf
, _(", expected static, #include or #define\nwhile parsing resource."));
3077 if (!wxGetResourceTokenString(s
))
3079 wxLogWarning(_("Unexpected end of file while parsing resource."));
3084 if (strcmp(wxResourceBuffer
, "char") != 0)
3086 wxLogWarning(_("Expected 'char' while parsing resource."));
3091 if (!wxGetResourceTokenString(s
))
3093 wxLogWarning(_("Unexpected end of file while parsing resource."));
3098 if (wxResourceBuffer
[0] != '*')
3100 wxLogWarning(_("Expected '*' while parsing resource."));
3103 wxChar nameBuf
[100];
3104 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
3108 if (!wxGetResourceTokenString(s
))
3110 wxLogWarning(_("Unexpected end of file while parsing resource."));
3115 if (strcmp(wxResourceBuffer
, "=") != 0)
3117 wxLogWarning(_("Expected '=' while parsing resource."));
3122 if (!wxGetResourceTokenString(s
))
3124 wxLogWarning(_("Unexpected end of file while parsing resource."));
3130 if (!db
.ReadPrologFromString(wxResourceBuffer
))
3132 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
3137 if (!wxGetResourceTokenString(s
))
3144 bool wxResourceParseString(const wxString
& s
, wxResourceTable
*WXUNUSED(table
))
3147 return wxResourceParseString( (char*)s
.mb_str().data() );
3149 return wxResourceParseString( (char*)s
.c_str() );
3153 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
3156 table
= wxDefaultResourceTable
;
3161 // Turn backslashes into spaces
3164 int len
= strlen(s
);
3166 for (i
= 0; i
< len
; i
++)
3167 if (s
[i
] == 92 && s
[i
+1] == 13)
3175 wxResourceStringPtr
= 0;
3178 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
3182 return wxResourceInterpretResources(*table
, db
);
3186 * resource loading facility
3189 bool wxLoadFromResource(wxWindow
* thisWindow
, wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
3192 table
= wxDefaultResourceTable
;
3194 wxItemResource
*resource
= table
->FindResource((const wxChar
*)resourceName
);
3195 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
3196 if (!resource
|| (resource
->GetType().empty()) ||
3197 ! ((resource
->GetType() == wxT("wxDialog")) || (resource
->GetType() == wxT("wxPanel"))))
3200 wxString
title(resource
->GetTitle());
3201 long theWindowStyle
= resource
->GetStyle();
3202 bool isModal
= (resource
->GetValue1() != 0) ;
3203 int x
= resource
->GetX();
3204 int y
= resource
->GetY();
3205 int width
= resource
->GetWidth();
3206 int height
= resource
->GetHeight();
3207 wxString name
= resource
->GetName();
3209 // this is used for loading wxWizard pages from WXR
3210 if ( parent
!= thisWindow
)
3212 if (thisWindow
->IsKindOf(CLASSINFO(wxDialog
)))
3214 wxDialog
*dialogBox
= (wxDialog
*)thisWindow
;
3215 long modalStyle
= isModal
?
3216 #if WXWIN_COMPATIBILITY_2_6
3220 #endif // WXWIN_COMPATIBILITY_2_6
3222 if (!dialogBox
->Create(parent
, wxID_ANY
, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
3225 // Only reset the client size if we know we're not going to do it again below.
3226 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == 0)
3227 dialogBox
->SetClientSize(width
, height
);
3229 else if (thisWindow
->IsKindOf(CLASSINFO(wxPanel
)))
3231 wxPanel
* panel
= (wxPanel
*)thisWindow
;
3232 if (!panel
->Create(parent
, wxID_ANY
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
| wxTAB_TRAVERSAL
, name
))
3237 if (!((wxWindow
*)thisWindow
)->Create(parent
, wxID_ANY
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
3242 if ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
3244 // No need to do this since it's done in wxPanel or wxDialog constructor.
3245 // SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
3249 if (resource
->GetFont().Ok())
3250 thisWindow
->SetFont(resource
->GetFont());
3251 if (resource
->GetBackgroundColour().Ok())
3252 thisWindow
->SetBackgroundColour(resource
->GetBackgroundColour());
3255 // Should have some kind of font at this point
3256 if (!thisWindow
->GetFont().Ok())
3257 thisWindow
->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
3258 if (!thisWindow
->GetBackgroundColour().Ok())
3259 thisWindow
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
3261 // Only when we've created the window and set the font can we set the correct size,
3262 // if based on dialog units.
3263 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
3265 wxSize sz
= thisWindow
->ConvertDialogToPixels(wxSize(width
, height
));
3266 thisWindow
->SetClientSize(sz
.x
, sz
.y
);
3268 wxPoint pt
= thisWindow
->ConvertDialogToPixels(wxPoint(x
, y
));
3269 thisWindow
->Move(pt
.x
, pt
.y
);
3272 // Now create children
3273 wxNode
*node
= resource
->GetChildren().GetFirst();
3276 wxItemResource
*childResource
= (wxItemResource
*)node
->GetData();
3278 (void) wxCreateItem(thisWindow
, childResource
, resource
, table
);
3280 node
= node
->GetNext();
3285 wxControl
*wxCreateItem(wxWindow
* thisWindow
, const wxItemResource
*resource
, const wxItemResource
* parentResource
, const wxResourceTable
*table
)
3288 table
= wxDefaultResourceTable
;
3289 return table
->CreateItem(thisWindow
, resource
, parentResource
);
3293 #pragma warning(default:4706) // assignment within conditional expression
3296 #endif // wxUSE_WX_RESOURCES