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 { wxT("wxGA_PROGRESSBAR"), wxGA_PROGRESSBAR
},
2109 { wxT("wxGA_HORIZONTAL"), wxGA_HORIZONTAL
},
2110 { wxT("wxGA_VERTICAL"), wxGA_VERTICAL
},
2113 #if WXWIN_COMPATIBILITY_2_6
2114 { wxT("wxPASSWORD"), wxTE_PASSWORD
},
2115 { wxT("wxPROCESS_ENTER"), wxTE_PROCESS_ENTER
},
2117 { wxT("wxTE_PASSWORD"), wxTE_PASSWORD
},
2118 { wxT("wxTE_READONLY"), wxTE_READONLY
},
2119 { wxT("wxTE_PROCESS_ENTER"), wxTE_PROCESS_ENTER
},
2120 { wxT("wxTE_MULTILINE"), wxTE_MULTILINE
},
2121 { wxT("wxTE_NO_VSCROLL"), wxTE_NO_VSCROLL
},
2123 /* wxRadioBox/wxRadioButton */
2124 { wxT("wxRB_GROUP"), wxRB_GROUP
},
2125 { wxT("wxRA_SPECIFY_COLS"), wxRA_SPECIFY_COLS
},
2126 { wxT("wxRA_SPECIFY_ROWS"), wxRA_SPECIFY_ROWS
},
2127 { wxT("wxRA_HORIZONTAL"), wxRA_HORIZONTAL
},
2128 { wxT("wxRA_VERTICAL"), wxRA_VERTICAL
},
2131 { wxT("wxSL_HORIZONTAL"), wxSL_HORIZONTAL
},
2132 { wxT("wxSL_VERTICAL"), wxSL_VERTICAL
},
2133 { wxT("wxSL_AUTOTICKS"), wxSL_AUTOTICKS
},
2134 { wxT("wxSL_LABELS"), wxSL_LABELS
},
2135 { wxT("wxSL_LEFT"), wxSL_LEFT
},
2136 { wxT("wxSL_TOP"), wxSL_TOP
},
2137 { wxT("wxSL_RIGHT"), wxSL_RIGHT
},
2138 { wxT("wxSL_BOTTOM"), wxSL_BOTTOM
},
2139 { wxT("wxSL_BOTH"), wxSL_BOTH
},
2140 { wxT("wxSL_SELRANGE"), wxSL_SELRANGE
},
2143 { wxT("wxSB_HORIZONTAL"), wxSB_HORIZONTAL
},
2144 { wxT("wxSB_VERTICAL"), wxSB_VERTICAL
},
2147 { wxT("wxBU_AUTODRAW"), wxBU_AUTODRAW
},
2148 { wxT("wxBU_NOAUTODRAW"), wxBU_NOAUTODRAW
},
2151 { wxT("wxTR_HAS_BUTTONS"), wxTR_HAS_BUTTONS
},
2152 { wxT("wxTR_EDIT_LABELS"), wxTR_EDIT_LABELS
},
2153 { wxT("wxTR_LINES_AT_ROOT"), wxTR_LINES_AT_ROOT
},
2156 { wxT("wxLC_ICON"), wxLC_ICON
},
2157 { wxT("wxLC_SMALL_ICON"), wxLC_SMALL_ICON
},
2158 { wxT("wxLC_LIST"), wxLC_LIST
},
2159 { wxT("wxLC_REPORT"), wxLC_REPORT
},
2160 { wxT("wxLC_ALIGN_TOP"), wxLC_ALIGN_TOP
},
2161 { wxT("wxLC_ALIGN_LEFT"), wxLC_ALIGN_LEFT
},
2162 { wxT("wxLC_AUTOARRANGE"), wxLC_AUTOARRANGE
},
2163 { wxT("wxLC_USER_TEXT"), wxLC_USER_TEXT
},
2164 { wxT("wxLC_EDIT_LABELS"), wxLC_EDIT_LABELS
},
2165 { wxT("wxLC_NO_HEADER"), wxLC_NO_HEADER
},
2166 { wxT("wxLC_NO_SORT_HEADER"), wxLC_NO_SORT_HEADER
},
2167 { wxT("wxLC_SINGLE_SEL"), wxLC_SINGLE_SEL
},
2168 { wxT("wxLC_SORT_ASCENDING"), wxLC_SORT_ASCENDING
},
2169 { wxT("wxLC_SORT_DESCENDING"), wxLC_SORT_DESCENDING
},
2172 { wxT("wxSP_VERTICAL"), wxSP_VERTICAL
},
2173 { wxT("wxSP_HORIZONTAL"), wxSP_HORIZONTAL
},
2174 { wxT("wxSP_ARROW_KEYS"), wxSP_ARROW_KEYS
},
2175 { wxT("wxSP_WRAP"), wxSP_WRAP
},
2178 { wxT("wxSP_NOBORDER"), wxSP_NOBORDER
},
2179 { wxT("wxSP_3D"), wxSP_3D
},
2180 { wxT("wxSP_BORDER"), wxSP_BORDER
},
2183 { wxT("wxTC_MULTILINE"), wxTC_MULTILINE
},
2184 { wxT("wxTC_RIGHTJUSTIFY"), wxTC_RIGHTJUSTIFY
},
2185 { wxT("wxTC_FIXEDWIDTH"), wxTC_FIXEDWIDTH
},
2186 { wxT("wxTC_OWNERDRAW"), wxTC_OWNERDRAW
},
2189 { wxT("wxST_SIZEGRIP"), wxST_SIZEGRIP
},
2192 { wxT("wxFIXED_LENGTH"), wxFIXED_LENGTH
},
2193 { wxT("wxALIGN_LEFT"), wxALIGN_LEFT
},
2194 { wxT("wxALIGN_CENTER"), wxALIGN_CENTER
},
2195 { wxT("wxALIGN_CENTRE"), wxALIGN_CENTRE
},
2196 { wxT("wxALIGN_RIGHT"), wxALIGN_RIGHT
},
2197 { wxT("wxCOLOURED"), wxCOLOURED
},
2200 { wxT("wxTB_3DBUTTONS"), wxTB_3DBUTTONS
},
2201 { wxT("wxTB_HORIZONTAL"), wxTB_HORIZONTAL
},
2202 { wxT("wxTB_VERTICAL"), wxTB_VERTICAL
},
2203 { wxT("wxTB_FLAT"), wxTB_FLAT
},
2205 #if WXWIN_COMPATIBILITY_2_6
2207 { wxT("wxDIALOG_MODAL"), wxDIALOG_MODAL
},
2208 #endif // WXWIN_COMPATIBILITY_2_6
2211 { wxT("wxVSCROLL"), wxVSCROLL
},
2212 { wxT("wxHSCROLL"), wxHSCROLL
},
2213 { wxT("wxCAPTION"), wxCAPTION
},
2214 { wxT("wxSTAY_ON_TOP"), wxSTAY_ON_TOP
},
2215 { wxT("wxICONIZE"), wxICONIZE
},
2216 { wxT("wxMINIMIZE"), wxICONIZE
},
2217 { wxT("wxMAXIMIZE"), wxMAXIMIZE
},
2219 { wxT("wxMDI_PARENT"), 0},
2220 { wxT("wxMDI_CHILD"), 0},
2221 { wxT("wxTHICK_FRAME"), wxRESIZE_BORDER
},
2222 { wxT("wxRESIZE_BORDER"), wxRESIZE_BORDER
},
2223 { wxT("wxSYSTEM_MENU"), wxSYSTEM_MENU
},
2224 { wxT("wxMINIMIZE_BOX"), wxMINIMIZE_BOX
},
2225 { wxT("wxMAXIMIZE_BOX"), wxMAXIMIZE_BOX
},
2226 { wxT("wxRESIZE_BOX"), wxRESIZE_BOX
},
2227 { wxT("wxDEFAULT_FRAME_STYLE"), wxDEFAULT_FRAME_STYLE
},
2228 { wxT("wxDEFAULT_FRAME"), wxDEFAULT_FRAME_STYLE
},
2229 { wxT("wxDEFAULT_DIALOG_STYLE"), wxDEFAULT_DIALOG_STYLE
},
2230 { wxT("wxBORDER"), wxBORDER
},
2231 { wxT("wxRETAINED"), wxRETAINED
},
2232 { wxT("wxNATIVE_IMPL"), 0},
2233 { wxT("wxEXTENDED_IMPL"), 0},
2234 { wxT("wxBACKINGSTORE"), wxBACKINGSTORE
},
2235 // { wxT("wxFLAT"), wxFLAT},
2236 // { wxT("wxMOTIF_RESIZE"), wxMOTIF_RESIZE},
2237 { wxT("wxFIXED_LENGTH"), 0},
2238 { wxT("wxDOUBLE_BORDER"), wxDOUBLE_BORDER
},
2239 { wxT("wxSUNKEN_BORDER"), wxSUNKEN_BORDER
},
2240 { wxT("wxRAISED_BORDER"), wxRAISED_BORDER
},
2241 { wxT("wxSIMPLE_BORDER"), wxSIMPLE_BORDER
},
2242 { wxT("wxSTATIC_BORDER"), wxSTATIC_BORDER
},
2243 { wxT("wxTRANSPARENT_WINDOW"), wxTRANSPARENT_WINDOW
},
2244 { wxT("wxNO_BORDER"), wxNO_BORDER
},
2245 { wxT("wxCLIP_CHILDREN"), wxCLIP_CHILDREN
},
2246 { wxT("wxCLIP_SIBLINGS"), wxCLIP_SIBLINGS
},
2247 { wxT("wxTAB_TRAVERSAL"), 0}, // Compatibility only
2249 { wxT("wxTINY_CAPTION_HORIZ"), wxTINY_CAPTION_HORIZ
},
2250 { wxT("wxTINY_CAPTION_VERT"), wxTINY_CAPTION_VERT
},
2252 // Text font families
2253 { wxT("wxDEFAULT"), wxDEFAULT
},
2254 { wxT("wxDECORATIVE"), wxDECORATIVE
},
2255 { wxT("wxROMAN"), wxROMAN
},
2256 { wxT("wxSCRIPT"), wxSCRIPT
},
2257 { wxT("wxSWISS"), wxSWISS
},
2258 { wxT("wxMODERN"), wxMODERN
},
2259 { wxT("wxTELETYPE"), wxTELETYPE
},
2260 { wxT("wxVARIABLE"), wxVARIABLE
},
2261 { wxT("wxFIXED"), wxFIXED
},
2262 { wxT("wxNORMAL"), wxNORMAL
},
2263 { wxT("wxLIGHT"), wxLIGHT
},
2264 { wxT("wxBOLD"), wxBOLD
},
2265 { wxT("wxITALIC"), wxITALIC
},
2266 { wxT("wxSLANT"), wxSLANT
},
2267 { wxT("wxSOLID"), wxSOLID
},
2268 { wxT("wxDOT"), wxDOT
},
2269 { wxT("wxLONG_DASH"), wxLONG_DASH
},
2270 { wxT("wxSHORT_DASH"), wxSHORT_DASH
},
2271 { wxT("wxDOT_DASH"), wxDOT_DASH
},
2272 { wxT("wxUSER_DASH"), wxUSER_DASH
},
2273 { wxT("wxTRANSPARENT"), wxTRANSPARENT
},
2274 { wxT("wxSTIPPLE"), wxSTIPPLE
},
2275 { wxT("wxBDIAGONAL_HATCH"), wxBDIAGONAL_HATCH
},
2276 { wxT("wxCROSSDIAG_HATCH"), wxCROSSDIAG_HATCH
},
2277 { wxT("wxFDIAGONAL_HATCH"), wxFDIAGONAL_HATCH
},
2278 { wxT("wxCROSS_HATCH"), wxCROSS_HATCH
},
2279 { wxT("wxHORIZONTAL_HATCH"), wxHORIZONTAL_HATCH
},
2280 { wxT("wxVERTICAL_HATCH"), wxVERTICAL_HATCH
},
2281 { wxT("wxJOIN_BEVEL"), wxJOIN_BEVEL
},
2282 { wxT("wxJOIN_MITER"), wxJOIN_MITER
},
2283 { wxT("wxJOIN_ROUND"), wxJOIN_ROUND
},
2284 { wxT("wxCAP_ROUND"), wxCAP_ROUND
},
2285 { wxT("wxCAP_PROJECTING"), wxCAP_PROJECTING
},
2286 { wxT("wxCAP_BUTT"), wxCAP_BUTT
},
2289 { wxT("wxCLEAR"), wxCLEAR
},
2290 { wxT("wxXOR"), wxXOR
},
2291 { wxT("wxINVERT"), wxINVERT
},
2292 { wxT("wxOR_REVERSE"), wxOR_REVERSE
},
2293 { wxT("wxAND_REVERSE"), wxAND_REVERSE
},
2294 { wxT("wxCOPY"), wxCOPY
},
2295 { wxT("wxAND"), wxAND
},
2296 { wxT("wxAND_INVERT"), wxAND_INVERT
},
2297 { wxT("wxNO_OP"), wxNO_OP
},
2298 { wxT("wxNOR"), wxNOR
},
2299 { wxT("wxEQUIV"), wxEQUIV
},
2300 { wxT("wxSRC_INVERT"), wxSRC_INVERT
},
2301 { wxT("wxOR_INVERT"), wxOR_INVERT
},
2302 { wxT("wxNAND"), wxNAND
},
2303 { wxT("wxOR"), wxOR
},
2304 { wxT("wxSET"), wxSET
},
2306 { wxT("wxFLOOD_SURFACE"), wxFLOOD_SURFACE
},
2307 { wxT("wxFLOOD_BORDER"), wxFLOOD_BORDER
},
2308 { wxT("wxODDEVEN_RULE"), wxODDEVEN_RULE
},
2309 { wxT("wxWINDING_RULE"), wxWINDING_RULE
},
2310 { wxT("wxHORIZONTAL"), wxHORIZONTAL
},
2311 { wxT("wxVERTICAL"), wxVERTICAL
},
2312 { wxT("wxBOTH"), wxBOTH
},
2313 { wxT("wxCENTER_FRAME"), wxCENTER_FRAME
},
2314 { wxT("wxOK"), wxOK
},
2315 { wxT("wxYES_NO"), wxYES_NO
},
2316 { wxT("wxCANCEL"), wxCANCEL
},
2317 { wxT("wxYES"), wxYES
},
2318 { wxT("wxNO"), wxNO
},
2319 { wxT("wxICON_EXCLAMATION"), wxICON_EXCLAMATION
},
2320 { wxT("wxICON_HAND"), wxICON_HAND
},
2321 { wxT("wxICON_QUESTION"), wxICON_QUESTION
},
2322 { wxT("wxICON_INFORMATION"), wxICON_INFORMATION
},
2323 { wxT("wxICON_STOP"), wxICON_STOP
},
2324 { wxT("wxICON_ASTERISK"), wxICON_ASTERISK
},
2325 { wxT("wxICON_MASK"), wxICON_MASK
},
2326 { wxT("wxCENTRE"), wxCENTRE
},
2327 { wxT("wxCENTER"), wxCENTRE
},
2328 #if WXWIN_COMPATIBILITY_2_6
2329 { wxT("wxUSER_COLOURS"), wxUSER_COLOURS
},
2330 #endif // WXWIN_COMPATIBILITY_2_6
2331 { wxT("wxVERTICAL_LABEL"), 0},
2332 { wxT("wxHORIZONTAL_LABEL"), 0},
2334 // Bitmap types (not strictly styles)
2335 { wxT("wxBITMAP_TYPE_XPM"), wxBITMAP_TYPE_XPM
},
2336 { wxT("wxBITMAP_TYPE_XBM"), wxBITMAP_TYPE_XBM
},
2337 { wxT("wxBITMAP_TYPE_BMP"), wxBITMAP_TYPE_BMP
},
2338 { wxT("wxBITMAP_TYPE_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2339 { wxT("wxBITMAP_TYPE_BMP_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2340 { wxT("wxBITMAP_TYPE_GIF"), wxBITMAP_TYPE_GIF
},
2341 { wxT("wxBITMAP_TYPE_TIF"), wxBITMAP_TYPE_TIF
},
2342 { wxT("wxBITMAP_TYPE_ICO"), wxBITMAP_TYPE_ICO
},
2343 { wxT("wxBITMAP_TYPE_ICO_RESOURCE"), wxBITMAP_TYPE_ICO_RESOURCE
},
2344 { wxT("wxBITMAP_TYPE_CUR"), wxBITMAP_TYPE_CUR
},
2345 { wxT("wxBITMAP_TYPE_CUR_RESOURCE"), wxBITMAP_TYPE_CUR_RESOURCE
},
2346 { wxT("wxBITMAP_TYPE_XBM_DATA"), wxBITMAP_TYPE_XBM_DATA
},
2347 { wxT("wxBITMAP_TYPE_XPM_DATA"), wxBITMAP_TYPE_XPM_DATA
},
2348 { wxT("wxBITMAP_TYPE_ANY"), wxBITMAP_TYPE_ANY
}
2351 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
2353 long wxParseWindowStyle(const wxString
& bitListString
)
2358 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2359 while (word
!= NULL
)
2363 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2364 if (wxStrcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2366 bitList
|= wxResourceBitListTable
[j
].bits
;
2372 wxLogWarning(_("Unrecognized style %s while parsing resource."), word
);
2375 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2381 * Load a bitmap from a wxWidgets resource, choosing an optimum
2382 * depth and appropriate type.
2385 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
2388 table
= wxDefaultResourceTable
;
2390 wxItemResource
*item
= table
->FindResource(resource
);
2393 if ((item
->GetType().empty()) || (item
->GetType() != wxT("wxBitmap")))
2395 wxLogWarning(_("%s not a bitmap resource specification."), (const wxChar
*) resource
);
2396 return wxNullBitmap
;
2398 int thisDepth
= wxDisplayDepth();
2399 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2401 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2403 // Try to find optimum bitmap for this platform/colour depth
2404 wxNode
*node
= item
->GetChildren().GetFirst();
2407 wxItemResource
*child
= (wxItemResource
*)node
->GetData();
2408 int platform
= (int)child
->GetValue2();
2409 int noColours
= (int)child
->GetValue3();
2411 char *name = child->GetName();
2412 int bitmapType = (int)child->GetValue1();
2413 int xRes = child->GetWidth();
2414 int yRes = child->GetHeight();
2419 case RESOURCE_PLATFORM_ANY
:
2421 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2422 optResource
= child
;
2425 // Maximise the number of colours.
2426 // If noColours is zero (unspecified), then assume this
2427 // is the right one.
2428 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2429 optResource
= child
;
2434 case RESOURCE_PLATFORM_WINDOWS
:
2436 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2437 optResource
= child
;
2440 // Maximise the number of colours
2441 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2442 optResource
= child
;
2448 case RESOURCE_PLATFORM_X
:
2450 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2451 optResource
= child
;
2454 // Maximise the number of colours
2455 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2456 optResource
= child
;
2462 case RESOURCE_PLATFORM_MAC
:
2464 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2465 optResource
= child
;
2468 // Maximise the number of colours
2469 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2470 optResource
= child
;
2478 node
= node
->GetNext();
2480 // If no matching resource, fail.
2482 return wxNullBitmap
;
2484 wxString name
= optResource
->GetName();
2485 int bitmapType
= (int)optResource
->GetValue1();
2488 case wxBITMAP_TYPE_XBM_DATA
:
2491 wxItemResource
*item
= table
->FindResource(name
);
2494 wxLogWarning(_("Failed to find XBM resource %s.\n"
2495 "Forgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2496 return wxNullBitmap
;
2498 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2500 wxLogWarning(_("No XBM facility available!"));
2504 case wxBITMAP_TYPE_XPM_DATA
:
2506 wxItemResource
*item
= table
->FindResource(name
);
2509 wxLogWarning(_("Failed to find XPM resource %s.\nForgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2510 return wxNullBitmap
;
2512 return wxBitmap((char **)item
->GetValue1());
2516 #if defined(__WXPM__)
2517 return wxNullBitmap
;
2519 return wxBitmap(name
, (wxBitmapType
)bitmapType
);
2524 return wxNullBitmap
;
2529 wxLogWarning(_("Bitmap resource specification %s not found."), (const wxChar
*) resource
);
2530 return wxNullBitmap
;
2535 * Load an icon from a wxWidgets resource, choosing an optimum
2536 * depth and appropriate type.
2539 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2542 table
= wxDefaultResourceTable
;
2544 wxItemResource
*item
= table
->FindResource(resource
);
2547 if ((item
->GetType().empty()) || wxStrcmp(item
->GetType(), wxT("wxIcon")) != 0)
2549 wxLogWarning(_("%s not an icon resource specification."), (const wxChar
*) resource
);
2552 int thisDepth
= wxDisplayDepth();
2553 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2555 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2557 // Try to find optimum icon for this platform/colour depth
2558 wxNode
*node
= item
->GetChildren().GetFirst();
2561 wxItemResource
*child
= (wxItemResource
*)node
->GetData();
2562 int platform
= (int)child
->GetValue2();
2563 int noColours
= (int)child
->GetValue3();
2565 char *name = child->GetName();
2566 int bitmapType = (int)child->GetValue1();
2567 int xRes = child->GetWidth();
2568 int yRes = child->GetHeight();
2573 case RESOURCE_PLATFORM_ANY
:
2575 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2576 optResource
= child
;
2579 // Maximise the number of colours.
2580 // If noColours is zero (unspecified), then assume this
2581 // is the right one.
2582 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2583 optResource
= child
;
2588 case RESOURCE_PLATFORM_WINDOWS
:
2590 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2591 optResource
= child
;
2594 // Maximise the number of colours
2595 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2596 optResource
= child
;
2602 case RESOURCE_PLATFORM_X
:
2604 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2605 optResource
= child
;
2608 // Maximise the number of colours
2609 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2610 optResource
= child
;
2616 case RESOURCE_PLATFORM_MAC
:
2618 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2619 optResource
= child
;
2622 // Maximise the number of colours
2623 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2624 optResource
= child
;
2632 node
= node
->GetNext();
2634 // If no matching resource, fail.
2638 wxString name
= optResource
->GetName();
2639 int bitmapType
= (int)optResource
->GetValue1();
2642 case wxBITMAP_TYPE_XBM_DATA
:
2645 wxItemResource
*item
= table
->FindResource(name
);
2648 wxLogWarning(_("Failed to find XBM resource %s.\n"
2649 "Forgot to use wxResourceLoadIconData?"), (const wxChar
*) name
);
2652 return wxIcon((const char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2654 wxLogWarning(_("No XBM facility available!"));
2658 case wxBITMAP_TYPE_XPM_DATA
:
2660 // *** XPM ICON NOT YET IMPLEMENTED IN wxWidgets ***
2662 wxItemResource *item = table->FindResource(name);
2666 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2670 return wxIcon((char **)item->GetValue1());
2672 wxLogWarning(_("No XPM icon facility available!"));
2677 #if defined( __WXGTK__ ) || defined( __WXMOTIF__ )
2678 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2681 return wxIcon(name
, (wxBitmapType
) bitmapType
);
2689 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2696 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2698 wxMenu
*menu
= new wxMenu
;
2699 wxNode
*node
= item
->GetChildren().GetFirst();
2702 wxItemResource
*child
= (wxItemResource
*)node
->GetData();
2703 if ((!child
->GetType().empty()) && (child
->GetType() == wxT("wxMenuSeparator")))
2704 menu
->AppendSeparator();
2705 else if (child
->GetChildren().GetCount() > 0)
2707 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2709 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2713 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2715 node
= node
->GetNext();
2720 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2723 table
= wxDefaultResourceTable
;
2725 wxItemResource
*menuResource
= table
->FindResource(resource
);
2726 if (menuResource
&& (!menuResource
->GetType().empty()) && (menuResource
->GetType() == wxT("wxMenu")))
2729 menuBar
= new wxMenuBar
;
2730 wxNode
*node
= menuResource
->GetChildren().GetFirst();
2733 wxItemResource
*child
= (wxItemResource
*)node
->GetData();
2734 wxMenu
*menu
= wxResourceCreateMenu(child
);
2736 menuBar
->Append(menu
, child
->GetTitle());
2737 node
= node
->GetNext();
2741 return (wxMenuBar
*) NULL
;
2744 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2747 table
= wxDefaultResourceTable
;
2749 wxItemResource
*menuResource
= table
->FindResource(resource
);
2750 if (menuResource
&& (!menuResource
->GetType().empty()) && (menuResource
->GetType() == wxT("wxMenu")))
2751 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2752 return wxResourceCreateMenu(menuResource
);
2753 return (wxMenu
*) NULL
;
2756 #endif // wxUSE_MENUS
2758 // Global equivalents (so don't have to refer to default table explicitly)
2759 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2762 table
= wxDefaultResourceTable
;
2764 return table
->ParseResourceData(resource
);
2767 bool wxResourceParseData(const char* resource
, wxResourceTable
*table
)
2769 wxString
str(resource
, wxConvLibc
);
2771 table
= wxDefaultResourceTable
;
2773 return table
->ParseResourceData(str
);
2776 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2779 table
= wxDefaultResourceTable
;
2781 return table
->ParseResourceFile(filename
);
2784 // Register XBM/XPM data
2785 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2788 table
= wxDefaultResourceTable
;
2790 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2793 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2796 table
= wxDefaultResourceTable
;
2798 return table
->RegisterResourceBitmapData(name
, data
);
2801 void wxResourceClear(wxResourceTable
*table
)
2804 table
= wxDefaultResourceTable
;
2806 table
->ClearTable();
2813 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2816 table
= wxDefaultResourceTable
;
2818 table
->identifiers
.Put(name
, (wxObject
*)(long)value
);
2822 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2825 table
= wxDefaultResourceTable
;
2827 return (int)(long)table
->identifiers
.Get(name
);
2831 * Parse #include file for #defines (only)
2834 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2837 table
= wxDefaultResourceTable
;
2839 FILE *fd
= wxFopen(f
, wxT("r"));
2844 while (wxGetResourceToken(fd
))
2846 if (strcmp(wxResourceBuffer
, "#define") == 0)
2848 wxGetResourceToken(fd
);
2849 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2850 wxGetResourceToken(fd
);
2851 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2852 if (wxIsdigit(value
[0]))
2854 int val
= (int)wxAtol(value
);
2855 wxResourceAddIdentifier(name
, val
, table
);
2866 * Reading strings as if they were .wxr files
2869 static int getc_string(char *s
)
2871 int ch
= s
[wxResourceStringPtr
];
2876 wxResourceStringPtr
++;
2881 static int ungetc_string()
2883 wxResourceStringPtr
--;
2887 bool wxEatWhiteSpaceString(char *s
)
2891 while ((ch
= getc_string(s
)) != EOF
)
2902 ch
= getc_string(s
);
2913 while ((ch
= getc_string(s
)) != EOF
)
2915 if (ch
== '/' && prev_ch
== '*')
2937 bool wxGetResourceTokenString(char *s
)
2939 if (!wxResourceBuffer
)
2940 wxReallocateResourceBuffer();
2941 wxResourceBuffer
[0] = 0;
2942 wxEatWhiteSpaceString(s
);
2944 int ch
= getc_string(s
);
2948 wxResourceBufferCount
= 0;
2949 ch
= getc_string(s
);
2955 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2958 // Escaped characters
2959 else if (ch
== '\\')
2961 int newCh
= getc_string(s
);
2964 else if (newCh
== 10)
2972 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2973 wxReallocateResourceBuffer();
2974 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2975 wxResourceBufferCount
++;
2976 ch
= getc_string(s
);
2978 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2982 wxResourceBufferCount
= 0;
2984 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2986 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2987 wxReallocateResourceBuffer();
2988 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2989 wxResourceBufferCount
++;
2991 ch
= getc_string(s
);
2993 wxResourceBuffer
[wxResourceBufferCount
] = 0;
3001 * Files are in form:
3002 static char *name = "....";
3003 with possible comments.
3006 bool wxResourceReadOneResourceString(char *s
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
3009 table
= wxDefaultResourceTable
;
3011 // static or #define
3012 if (!wxGetResourceTokenString(s
))
3018 if (strcmp(wxResourceBuffer
, "#define") == 0)
3020 wxGetResourceTokenString(s
);
3021 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
3022 wxGetResourceTokenString(s
);
3023 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
3024 if (wxIsdigit(value
[0]))
3026 int val
= (int)wxAtol(value
);
3027 wxResourceAddIdentifier(name
, val
, table
);
3031 wxLogWarning(_("#define %s must be an integer."), name
);
3042 else if (strcmp(wxResourceBuffer, "#include") == 0)
3044 wxGetResourceTokenString(s);
3045 char *name = copystring(wxResourceBuffer);
3046 char *actualName = name;
3048 actualName = name + 1;
3049 int len = strlen(name);
3050 if ((len > 0) && (name[len-1] == '"'))
3052 if (!wxResourceParseIncludeFile(actualName, table))
3055 sprintf(buf, _("Could not find resource include file %s."), actualName);
3062 else if (strcmp(wxResourceBuffer
, "static") != 0)
3065 wxStrcpy(buf
, _("Found "));
3066 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
3067 wxStrcat(buf
, _(", expected static, #include or #define\nwhile parsing resource."));
3073 if (!wxGetResourceTokenString(s
))
3075 wxLogWarning(_("Unexpected end of file while parsing resource."));
3080 if (strcmp(wxResourceBuffer
, "char") != 0)
3082 wxLogWarning(_("Expected 'char' while parsing resource."));
3087 if (!wxGetResourceTokenString(s
))
3089 wxLogWarning(_("Unexpected end of file while parsing resource."));
3094 if (wxResourceBuffer
[0] != '*')
3096 wxLogWarning(_("Expected '*' while parsing resource."));
3099 wxChar nameBuf
[100];
3100 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
3104 if (!wxGetResourceTokenString(s
))
3106 wxLogWarning(_("Unexpected end of file while parsing resource."));
3111 if (strcmp(wxResourceBuffer
, "=") != 0)
3113 wxLogWarning(_("Expected '=' while parsing resource."));
3118 if (!wxGetResourceTokenString(s
))
3120 wxLogWarning(_("Unexpected end of file while parsing resource."));
3126 if (!db
.ReadPrologFromString(wxResourceBuffer
))
3128 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
3133 if (!wxGetResourceTokenString(s
))
3140 bool wxResourceParseString(const wxString
& s
, wxResourceTable
*WXUNUSED(table
))
3143 return wxResourceParseString( (char*)s
.mb_str().data() );
3145 return wxResourceParseString( (char*)s
.c_str() );
3149 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
3152 table
= wxDefaultResourceTable
;
3157 // Turn backslashes into spaces
3160 int len
= strlen(s
);
3162 for (i
= 0; i
< len
; i
++)
3163 if (s
[i
] == 92 && s
[i
+1] == 13)
3171 wxResourceStringPtr
= 0;
3174 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
3178 return wxResourceInterpretResources(*table
, db
);
3182 * resource loading facility
3185 bool wxLoadFromResource(wxWindow
* thisWindow
, wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
3188 table
= wxDefaultResourceTable
;
3190 wxItemResource
*resource
= table
->FindResource((const wxChar
*)resourceName
);
3191 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
3192 if (!resource
|| (resource
->GetType().empty()) ||
3193 ! ((resource
->GetType() == wxT("wxDialog")) || (resource
->GetType() == wxT("wxPanel"))))
3196 wxString
title(resource
->GetTitle());
3197 long theWindowStyle
= resource
->GetStyle();
3198 bool isModal
= (resource
->GetValue1() != 0) ;
3199 int x
= resource
->GetX();
3200 int y
= resource
->GetY();
3201 int width
= resource
->GetWidth();
3202 int height
= resource
->GetHeight();
3203 wxString name
= resource
->GetName();
3205 // this is used for loading wxWizard pages from WXR
3206 if ( parent
!= thisWindow
)
3208 if (thisWindow
->IsKindOf(CLASSINFO(wxDialog
)))
3210 wxDialog
*dialogBox
= (wxDialog
*)thisWindow
;
3211 long modalStyle
= isModal
?
3212 #if WXWIN_COMPATIBILITY_2_6
3216 #endif // WXWIN_COMPATIBILITY_2_6
3218 if (!dialogBox
->Create(parent
, wxID_ANY
, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
3221 // Only reset the client size if we know we're not going to do it again below.
3222 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == 0)
3223 dialogBox
->SetClientSize(width
, height
);
3225 else if (thisWindow
->IsKindOf(CLASSINFO(wxPanel
)))
3227 wxPanel
* panel
= (wxPanel
*)thisWindow
;
3228 if (!panel
->Create(parent
, wxID_ANY
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
| wxTAB_TRAVERSAL
, name
))
3233 if (!((wxWindow
*)thisWindow
)->Create(parent
, wxID_ANY
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
3238 if ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
3240 // No need to do this since it's done in wxPanel or wxDialog constructor.
3241 // SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
3245 if (resource
->GetFont().Ok())
3246 thisWindow
->SetFont(resource
->GetFont());
3247 if (resource
->GetBackgroundColour().Ok())
3248 thisWindow
->SetBackgroundColour(resource
->GetBackgroundColour());
3251 // Should have some kind of font at this point
3252 if (!thisWindow
->GetFont().Ok())
3253 thisWindow
->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
3254 if (!thisWindow
->GetBackgroundColour().Ok())
3255 thisWindow
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
3257 // Only when we've created the window and set the font can we set the correct size,
3258 // if based on dialog units.
3259 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
3261 wxSize sz
= thisWindow
->ConvertDialogToPixels(wxSize(width
, height
));
3262 thisWindow
->SetClientSize(sz
.x
, sz
.y
);
3264 wxPoint pt
= thisWindow
->ConvertDialogToPixels(wxPoint(x
, y
));
3265 thisWindow
->Move(pt
.x
, pt
.y
);
3268 // Now create children
3269 wxNode
*node
= resource
->GetChildren().GetFirst();
3272 wxItemResource
*childResource
= (wxItemResource
*)node
->GetData();
3274 (void) wxCreateItem(thisWindow
, childResource
, resource
, table
);
3276 node
= node
->GetNext();
3281 wxControl
*wxCreateItem(wxWindow
* thisWindow
, const wxItemResource
*resource
, const wxItemResource
* parentResource
, const wxResourceTable
*table
)
3284 table
= wxDefaultResourceTable
;
3285 return table
->CreateItem(thisWindow
, resource
, parentResource
);
3289 #pragma warning(default:4706) // assignment within conditional expression
3292 #endif // wxUSE_WX_RESOURCES