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
31 #include "wx/gdicmn.h"
35 #include "wx/stattext.h"
36 #include "wx/button.h"
37 #include "wx/bmpbuttn.h"
38 #include "wx/radiobox.h"
39 #include "wx/listbox.h"
40 #include "wx/choice.h"
41 #include "wx/checkbox.h"
42 #include "wx/settings.h"
43 #include "wx/slider.h"
45 #include "wx/statbox.h"
46 #include "wx/statbmp.h"
48 #include "wx/textctrl.h"
49 #include "wx/msgdlg.h"
53 #include "wx/treebase.h"
54 #include "wx/listctrl.h"
57 #include "wx/radiobut.h"
61 #include "wx/scrolbar.h"
65 #include "wx/combobox.h"
68 #include "wx/splitter.h"
69 #include "wx/toolbar.h"
71 #include "wx/validate.h"
73 #include "wx/module.h"
80 #include "wx/string.h"
81 #include "wx/settings.h"
82 #include "wx/stream.h"
84 #include "wx/deprecated/resource.h"
85 #include "wx/deprecated/wxexpr.h"
87 #if !WXWIN_COMPATIBILITY_2_4
88 static inline wxChar
* copystring(const wxChar
* s
)
89 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
92 // Forward (private) declarations
93 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
);
94 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
= false);
95 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
);
96 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
);
97 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
);
98 wxItemResource
*wxResourceInterpretString(wxResourceTable
& table
, wxExpr
*expr
);
99 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& table
, wxExpr
*expr
);
100 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
);
101 // Interpret list expression
102 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
);
104 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
105 bool wxResourceReadOneResource(wxInputStream
*fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
) ;
106 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
108 wxResourceTable
*wxDefaultResourceTable
= (wxResourceTable
*) NULL
;
110 char *wxResourceBuffer
= (char *) NULL
;
111 long wxResourceBufferSize
= 0;
112 long wxResourceBufferCount
= 0;
113 int wxResourceStringPtr
= 0;
115 void wxInitializeResourceSystem()
117 if (!wxDefaultResourceTable
)
118 wxDefaultResourceTable
= new wxResourceTable
;
121 void wxCleanUpResourceSystem()
123 delete wxDefaultResourceTable
;
124 if (wxResourceBuffer
)
125 delete[] wxResourceBuffer
;
128 // Module to ensure the resource system data gets initialized
131 class wxResourceModule
: public wxModule
134 wxResourceModule() : wxModule() {}
135 virtual bool OnInit() { wxInitializeResourceSystem(); return true; }
136 virtual void OnExit() { wxCleanUpResourceSystem(); }
138 DECLARE_DYNAMIC_CLASS(wxResourceModule
)
141 IMPLEMENT_DYNAMIC_CLASS(wxResourceModule
, wxModule
)
144 IMPLEMENT_DYNAMIC_CLASS(wxItemResource
, wxObject
)
145 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable
, wxHashTable
)
147 wxItemResource::wxItemResource()
149 m_itemType
= wxEmptyString
;
150 m_title
= wxEmptyString
;
151 m_name
= wxEmptyString
;
153 m_x
= m_y
= m_width
= m_height
= 0;
154 m_value1
= m_value2
= m_value3
= m_value5
= 0;
155 m_value4
= wxEmptyString
;
160 wxItemResource::~wxItemResource()
162 wxNode
*node
= m_children
.GetFirst();
165 wxItemResource
*item
= (wxItemResource
*)node
->GetData();
168 node
= m_children
.GetFirst();
176 wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
)
180 wxResourceTable::~wxResourceTable()
185 wxItemResource
*wxResourceTable::FindResource(const wxString
& name
) const
187 wxItemResource
*item
= (wxItemResource
*)Get(WXSTRINGCAST name
);
191 void wxResourceTable::AddResource(wxItemResource
*item
)
193 wxString name
= item
->GetName();
195 name
= item
->GetTitle();
197 name
= wxT("no name");
199 // Delete existing resource, if any.
205 bool wxResourceTable::DeleteResource(const wxString
& name
)
207 wxItemResource
*item
= (wxItemResource
*)Delete(WXSTRINGCAST name
);
210 // See if any resource has this as its child; if so, delete from
211 // parent's child list.
213 wxHashTable::Node
*node
= Next();
216 wxItemResource
*parent
= (wxItemResource
*)node
->GetData();
217 if (parent
->GetChildren().Member(item
))
219 parent
->GetChildren().DeleteObject(item
);
232 bool wxResourceTable::ParseResourceFile( wxInputStream
*is
)
235 int len
= is
->GetSize() ;
238 while ( is
->TellI() + 10 < len
) // it's a hack because the streams dont support EOF
240 wxResourceReadOneResource(is
, db
, &eof
, this) ;
242 return wxResourceInterpretResources(*this, db
);
245 bool wxResourceTable::ParseResourceFile(const wxString
& filename
)
249 FILE *fd
= wxFopen(filename
, wxT("r"));
253 while (wxResourceReadOneResource(fd
, db
, &eof
, this) && !eof
)
258 return wxResourceInterpretResources(*this, db
);
261 bool wxResourceTable::ParseResourceData(const wxString
& data
)
264 if (!db
.ReadFromString(data
))
266 wxLogWarning(_("Ill-formed resource file syntax."));
270 return wxResourceInterpretResources(*this, db
);
273 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char bits
[], int width
, int height
)
275 // Register pre-loaded bitmap data
276 wxItemResource
*item
= new wxItemResource
;
277 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
278 item
->SetType(wxT("wxXBMData"));
280 item
->SetValue1((long)bits
);
281 item
->SetValue2((long)width
);
282 item
->SetValue3((long)height
);
287 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char **data
)
289 // Register pre-loaded bitmap data
290 wxItemResource
*item
= new wxItemResource
;
291 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
292 item
->SetType(wxT("wxXPMData"));
294 item
->SetValue1((long)data
);
299 bool wxResourceTable::SaveResource(const wxString
& WXUNUSED(filename
))
304 void wxResourceTable::ClearTable()
307 wxHashTable::Node
*node
= Next();
310 wxHashTable::Node
*next
= Next();
311 wxItemResource
*item
= (wxItemResource
*)node
->GetData();
318 wxControl
*wxResourceTable::CreateItem(wxWindow
*parent
, const wxItemResource
* childResource
, const wxItemResource
* parentResource
) const
320 int id
= childResource
->GetId();
324 bool dlgUnits
= ((parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0);
326 wxControl
*control
= (wxControl
*) NULL
;
327 wxString
itemType(childResource
->GetType());
333 pos
= parent
->ConvertDialogToPixels(wxPoint(childResource
->GetX(), childResource
->GetY()));
334 size
= parent
->ConvertDialogToPixels(wxSize(childResource
->GetWidth(), childResource
->GetHeight()));
338 pos
= wxPoint(childResource
->GetX(), childResource
->GetY());
339 size
= wxSize(childResource
->GetWidth(), childResource
->GetHeight());
342 if (itemType
== wxString(wxT("wxButton")) || itemType
== wxString(wxT("wxBitmapButton")))
344 if (!childResource
->GetValue4().empty())
347 wxBitmap bitmap
= childResource
->GetBitmap();
350 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
351 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
354 #if defined(__WXPM__)
356 // OS/2 uses integer id's to access resources, not file name strings
358 bitmap
.LoadFile(wxCROSS_BITMAP
, wxBITMAP_TYPE_BMP_RESOURCE
);
360 bitmap
.LoadFile(wxT("cross_bmp"), wxBITMAP_TYPE_BMP_RESOURCE
);
362 control
= new wxBitmapButton(parent
, id
, bitmap
, pos
, size
,
363 childResource
->GetStyle() | wxBU_AUTODRAW
, wxDefaultValidator
, childResource
->GetName());
366 // Normal, text button
367 control
= new wxButton(parent
, id
, childResource
->GetTitle(), pos
, size
,
368 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
370 else if (itemType
== wxString(wxT("wxMessage")) || itemType
== wxString(wxT("wxStaticText")) ||
371 itemType
== wxString(wxT("wxStaticBitmap")))
373 if (!childResource
->GetValue4().empty() || itemType
== wxString(wxT("wxStaticBitmap")) )
376 wxBitmap bitmap
= childResource
->GetBitmap();
379 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
380 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
382 #if wxUSE_BITMAP_MESSAGE
384 // Use a default bitmap
386 bitmap
.LoadFile(wxT("cross_bmp"), wxBITMAP_TYPE_BMP_RESOURCE
);
390 control
= new wxStaticBitmap(parent
, id
, bitmap
, pos
, size
,
391 childResource
->GetStyle(), childResource
->GetName());
396 control
= new wxStaticText(parent
, id
, childResource
->GetTitle(), pos
, size
,
397 childResource
->GetStyle(), childResource
->GetName());
400 else if (itemType
== wxString(wxT("wxText")) || itemType
== wxString(wxT("wxTextCtrl")) || itemType
== wxString(wxT("wxMultiText")))
402 control
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(), pos
, size
,
403 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
405 else if (itemType
== wxString(wxT("wxCheckBox")))
407 control
= new wxCheckBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
408 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
410 ((wxCheckBox
*)control
)->SetValue((childResource
->GetValue1() != 0));
413 else if (itemType
== wxString(wxT("wxGauge")))
415 control
= new wxGauge(parent
, id
, (int)childResource
->GetValue2(), pos
, size
,
416 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
418 ((wxGauge
*)control
)->SetValue((int)childResource
->GetValue1());
422 else if (itemType
== wxString(wxT("wxRadioButton")))
424 control
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(),
426 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
430 else if (itemType
== wxString(wxT("wxScrollBar")))
432 control
= new wxScrollBar(parent
, id
, pos
, size
,
433 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
435 ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1());
436 ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2());
437 ((wxScrollBar *)control)->SetObjectLength((int)childResource->GetValue3());
438 ((wxScrollBar *)control)->SetViewLength((int)(long)childResource->GetValue5());
440 ((wxScrollBar
*)control
)->SetScrollbar((int)childResource
->GetValue1(),(int)childResource
->GetValue2(),
441 (int)childResource
->GetValue3(),(int)(long)childResource
->GetValue5(),false);
445 else if (itemType
== wxString(wxT("wxSlider")))
447 control
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(),
448 (int)childResource
->GetValue2(), (int)childResource
->GetValue3(), pos
, size
,
449 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
451 else if (itemType
== wxString(wxT("wxGroupBox")) || itemType
== wxString(wxT("wxStaticBox")))
453 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
454 childResource
->GetStyle(), childResource
->GetName());
456 else if (itemType
== wxString(wxT("wxListBox")))
458 wxStringList
& stringList
= childResource
->GetStringValues();
459 wxString
*strings
= (wxString
*) NULL
;
461 if (stringList
.GetCount() > 0)
463 noStrings
= stringList
.GetCount();
464 strings
= new wxString
[noStrings
];
465 wxStringListNode
*node
= stringList
.GetFirst();
469 strings
[i
] = (wxChar
*)node
->GetData();
471 node
= node
->GetNext();
474 control
= new wxListBox(parent
, id
, pos
, size
,
475 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
480 else if (itemType
== wxString(wxT("wxChoice")))
482 wxStringList
& stringList
= childResource
->GetStringValues();
483 wxString
*strings
= (wxString
*) NULL
;
485 if (stringList
.GetCount() > 0)
487 noStrings
= stringList
.GetCount();
488 strings
= new wxString
[noStrings
];
489 wxStringListNode
*node
= stringList
.GetFirst();
493 strings
[i
] = (wxChar
*)node
->GetData();
495 node
= node
->GetNext();
498 control
= new wxChoice(parent
, id
, pos
, size
,
499 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
505 else if (itemType
== wxString(wxT("wxComboBox")))
507 wxStringList
& stringList
= childResource
->GetStringValues();
508 wxString
*strings
= (wxString
*) NULL
;
510 if (stringList
.GetCount() > 0)
512 noStrings
= stringList
.GetCount();
513 strings
= new wxString
[noStrings
];
514 wxStringListNode
*node
= stringList
.GetFirst();
518 strings
[i
] = (wxChar
*)node
->GetData();
520 node
= node
->GetNext();
523 control
= new wxComboBox(parent
, id
, childResource
->GetValue4(), pos
, size
,
524 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
530 else if (itemType
== wxString(wxT("wxRadioBox")))
532 wxStringList
& stringList
= childResource
->GetStringValues();
533 wxString
*strings
= (wxString
*) NULL
;
535 if (stringList
.GetCount() > 0)
537 noStrings
= stringList
.GetCount();
538 strings
= new wxString
[noStrings
];
539 wxStringListNode
*node
= stringList
.GetFirst();
543 strings
[i
] = (wxChar
*)node
->GetData();
545 node
= node
->GetNext();
548 control
= new wxRadioBox(parent
, (wxWindowID
) id
, wxString(childResource
->GetTitle()), pos
, size
,
549 noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
,
550 childResource
->GetName());
556 if ((parentResource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
558 // Don't set font; will be inherited from parent.
562 if (control
&& childResource
->GetFont().Ok())
564 control
->SetFont(childResource
->GetFont());
567 // Force the layout algorithm since the size changes the layout
568 if (control
->IsKindOf(CLASSINFO(wxRadioBox
)))
570 control
->SetSize(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, wxSIZE_AUTO_WIDTH
|wxSIZE_AUTO_HEIGHT
);
579 * Interpret database as a series of resources
582 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
)
584 wxNode
*node
= db
.GetFirst();
587 wxExpr
*clause
= (wxExpr
*)node
->GetData();
588 wxString
functor(clause
->Functor());
590 wxItemResource
*item
= (wxItemResource
*) NULL
;
591 if (functor
== wxT("dialog"))
592 item
= wxResourceInterpretDialog(table
, clause
);
593 else if (functor
== wxT("panel"))
594 item
= wxResourceInterpretDialog(table
, clause
, true);
595 else if (functor
== wxT("menubar"))
596 item
= wxResourceInterpretMenuBar(table
, clause
);
597 else if (functor
== wxT("menu"))
598 item
= wxResourceInterpretMenu(table
, clause
);
599 else if (functor
== wxT("string"))
600 item
= wxResourceInterpretString(table
, clause
);
601 else if (functor
== wxT("bitmap"))
602 item
= wxResourceInterpretBitmap(table
, clause
);
603 else if (functor
== wxT("icon"))
604 item
= wxResourceInterpretIcon(table
, clause
);
608 // Remove any existing resource of same name
609 if (!item
->GetName().empty())
610 table
.DeleteResource(item
->GetName());
611 table
.AddResource(item
);
613 node
= node
->GetNext();
618 static const wxChar
*g_ValidControlClasses
[] =
621 wxT("wxBitmapButton"),
624 wxT("wxStaticBitmap"),
630 wxT("wxRadioButton"),
632 wxT("wxBitmapCheckBox"),
642 static bool wxIsValidControlClass(const wxString
& c
)
644 for ( size_t i
= 0; i
< WXSIZEOF(g_ValidControlClasses
); i
++ )
646 if ( c
== g_ValidControlClasses
[i
] )
652 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
)
654 wxItemResource
*dialogItem
= new wxItemResource
;
656 dialogItem
->SetType(wxT("wxPanel"));
658 dialogItem
->SetType(wxT("wxDialog"));
659 wxString style
= wxEmptyString
;
660 wxString title
= wxEmptyString
;
661 wxString name
= wxEmptyString
;
662 wxString backColourHex
= wxEmptyString
;
663 wxString labelColourHex
= wxEmptyString
;
664 wxString buttonColourHex
= wxEmptyString
;
666 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
670 int x
= 0; int y
= 0; int width
= wxDefaultCoord
; int height
= wxDefaultCoord
;
672 wxExpr
*labelFontExpr
= (wxExpr
*) NULL
;
673 wxExpr
*buttonFontExpr
= (wxExpr
*) NULL
;
674 wxExpr
*fontExpr
= (wxExpr
*) NULL
;
675 expr
->GetAttributeValue(wxT("style"), style
);
676 expr
->GetAttributeValue(wxT("name"), name
);
677 expr
->GetAttributeValue(wxT("title"), title
);
678 expr
->GetAttributeValue(wxT("x"), x
);
679 expr
->GetAttributeValue(wxT("y"), y
);
680 expr
->GetAttributeValue(wxT("width"), width
);
681 expr
->GetAttributeValue(wxT("height"), height
);
682 expr
->GetAttributeValue(wxT("modal"), isModal
);
683 expr
->GetAttributeValue(wxT("label_font"), &labelFontExpr
);
684 expr
->GetAttributeValue(wxT("button_font"), &buttonFontExpr
);
685 expr
->GetAttributeValue(wxT("font"), &fontExpr
);
686 expr
->GetAttributeValue(wxT("background_colour"), backColourHex
);
687 expr
->GetAttributeValue(wxT("label_colour"), labelColourHex
);
688 expr
->GetAttributeValue(wxT("button_colour"), buttonColourHex
);
690 int useDialogUnits
= 0;
691 expr
->GetAttributeValue(wxT("use_dialog_units"), useDialogUnits
);
692 if (useDialogUnits
!= 0)
693 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS
);
696 expr
->GetAttributeValue(wxT("use_system_defaults"), useDefaults
);
697 if (useDefaults
!= 0)
698 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS
);
701 expr
->GetAttributeValue(wxT("id"), id
);
702 dialogItem
->SetId(id
);
706 windowStyle
= wxParseWindowStyle(style
);
708 dialogItem
->SetStyle(windowStyle
);
709 dialogItem
->SetValue1(isModal
);
711 #if WXWIN_COMPATIBILITY_2_6
714 #pragma message disable CODCAUUNR
716 if (windowStyle
& wxDIALOG_MODAL
) // Uses style in wxWin 2
717 dialogItem
->SetValue1(true);
719 #pragma message enable CODCAUUNR
722 #endif // WXWIN_COMPATIBILITY_2_6
724 dialogItem
->SetName(name
);
725 dialogItem
->SetTitle(title
);
726 dialogItem
->SetSize(x
, y
, width
, height
);
728 // Check for wxWin 1.68-style specifications
729 if (style
.Find(wxT("VERTICAL_LABEL")) != wxNOT_FOUND
)
730 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL
);
731 else if (style
.Find(wxT("HORIZONTAL_LABEL")) != wxNOT_FOUND
)
732 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL
);
734 if (!backColourHex
.empty())
739 r
= wxHexToDec(backColourHex
.Mid(0, 2));
740 g
= wxHexToDec(backColourHex
.Mid(2, 2));
741 b
= wxHexToDec(backColourHex
.Mid(4, 2));
742 dialogItem
->SetBackgroundColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
744 if (!labelColourHex
.empty())
749 r
= wxHexToDec(labelColourHex
.Mid(0, 2));
750 g
= wxHexToDec(labelColourHex
.Mid(2, 2));
751 b
= wxHexToDec(labelColourHex
.Mid(4, 2));
752 dialogItem
->SetLabelColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
754 if (!buttonColourHex
.empty())
759 r
= wxHexToDec(buttonColourHex
.Mid(0, 2));
760 g
= wxHexToDec(buttonColourHex
.Mid(2, 2));
761 b
= wxHexToDec(buttonColourHex
.Mid(4, 2));
762 dialogItem
->SetButtonColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
766 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
767 else if (buttonFontExpr
)
768 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
769 else if (labelFontExpr
)
770 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
772 // Now parse all controls
773 wxExpr
*controlExpr
= expr
->GetFirst();
776 if (controlExpr
->Number() == 3)
778 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
779 if (!controlKeyword
.empty() && controlKeyword
== wxT("control"))
781 // The value part: always a list.
782 wxExpr
*listExpr
= controlExpr
->Nth(2);
783 if (listExpr
->Type() == PrologList
)
785 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
788 dialogItem
->GetChildren().Append(controlItem
);
793 controlExpr
= controlExpr
->GetNext();
798 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
)
800 wxItemResource
*controlItem
= new wxItemResource
;
802 // First, find the standard features of a control definition:
803 // [optional integer/string id], control name, title, style, name, x, y, width, height
805 wxString controlType
;
810 long windowStyle
= 0;
811 int x
= 0; int y
= 0; int width
= wxDefaultCoord
; int height
= wxDefaultCoord
;
814 wxExpr
*expr1
= expr
->Nth(0);
816 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
818 if ( wxIsValidControlClass(expr1
->StringValue()) )
821 controlType
= expr1
->StringValue();
825 wxString
str(expr1
->StringValue());
826 id
= wxResourceGetIdentifier(str
, &table
);
829 wxLogWarning(_("Could not resolve control class or id '%s'. Use (non-zero) integer instead\n or provide #define (see manual for caveats)"),
830 (const wxChar
*) expr1
->StringValue());
832 return (wxItemResource
*) NULL
;
836 // Success - we have an id, so the 2nd element must be the control class.
837 controlType
= expr
->Nth(1)->StringValue();
842 else if (expr1
->Type() == PrologInteger
)
844 id
= (int)expr1
->IntegerValue();
845 // Success - we have an id, so the 2nd element must be the control class.
846 controlType
= expr
->Nth(1)->StringValue();
850 expr1
= expr
->Nth(count
);
853 title
= expr1
->StringValue();
855 expr1
= expr
->Nth(count
);
859 style
= expr1
->StringValue();
860 windowStyle
= wxParseWindowStyle(style
);
863 expr1
= expr
->Nth(count
);
866 name
= expr1
->StringValue();
868 expr1
= expr
->Nth(count
);
871 x
= (int)expr1
->IntegerValue();
873 expr1
= expr
->Nth(count
);
876 y
= (int)expr1
->IntegerValue();
878 expr1
= expr
->Nth(count
);
881 width
= (int)expr1
->IntegerValue();
883 expr1
= expr
->Nth(count
);
886 height
= (int)expr1
->IntegerValue();
888 controlItem
->SetStyle(windowStyle
);
889 controlItem
->SetName(name
);
890 controlItem
->SetTitle(title
);
891 controlItem
->SetSize(x
, y
, width
, height
);
892 controlItem
->SetType(controlType
);
893 controlItem
->SetId(id
);
895 // Check for wxWin 1.68-style specifications
896 if (style
.Find(wxT("VERTICAL_LABEL")) != wxNOT_FOUND
)
897 controlItem
->SetResourceStyle(controlItem
->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL
);
898 else if (style
.Find(wxT("HORIZONTAL_LABEL")) != wxNOT_FOUND
)
899 controlItem
->SetResourceStyle(controlItem
->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL
);
901 if (controlType
== wxT("wxButton"))
903 // Check for bitmap resource name (in case loading old-style resource file)
904 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
906 wxString
str(expr
->Nth(count
)->StringValue());
911 controlItem
->SetValue4(str
);
912 controlItem
->SetType(wxT("wxBitmapButton"));
915 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
916 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
918 else if (controlType
== wxT("wxBitmapButton"))
920 // Check for bitmap resource name
921 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
923 wxString
str(expr
->Nth(count
)->StringValue());
924 controlItem
->SetValue4(str
);
926 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
927 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
930 else if (controlType
== wxT("wxCheckBox"))
932 // Check for default value
933 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
935 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
937 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
938 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
942 else if (controlType
== wxT("wxRadioButton"))
944 // Check for default value
945 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
947 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
949 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
950 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
954 else if (controlType
== wxT("wxText") || controlType
== wxT("wxTextCtrl") || controlType
== wxT("wxMultiText"))
956 // Check for default value
957 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
959 wxString
str(expr
->Nth(count
)->StringValue());
960 controlItem
->SetValue4(str
);
963 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
965 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
966 // Skip past the obsolete label font spec if there are two consecutive specs
967 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
969 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
973 else if (controlType
== wxT("wxMessage") || controlType
== wxT("wxStaticText"))
975 // Check for bitmap resource name (in case it's an old-style .wxr file)
976 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
978 wxString
str(expr
->Nth(count
)->StringValue());
979 controlItem
->SetValue4(str
);
981 controlItem
->SetType(wxT("wxStaticText"));
983 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
984 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
986 else if (controlType
== wxT("wxStaticBitmap"))
988 // Check for bitmap resource name
989 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
991 wxString
str(expr
->Nth(count
)->StringValue());
992 controlItem
->SetValue4(str
);
995 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
996 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
998 else if (controlType
== wxT("wxGroupBox") || controlType
== wxT("wxStaticBox"))
1000 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1001 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1003 else if (controlType
== wxT("wxGauge"))
1005 // Check for default value
1006 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1008 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1012 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1014 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1017 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1019 // Skip past the obsolete label font spec if there are two consecutive specs
1020 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1022 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1027 else if (controlType
== wxT("wxSlider"))
1029 // Check for default value
1030 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1032 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1036 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1038 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1042 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1044 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1047 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1049 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1053 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1054 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1060 else if (controlType
== wxT("wxScrollBar"))
1063 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1065 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1069 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1071 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1075 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1077 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1081 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1082 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
1087 else if (controlType
== wxT("wxListBox"))
1089 wxExpr
*valueList
= (wxExpr
*) NULL
;
1091 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1093 wxStringList stringList
;
1094 wxExpr
*stringExpr
= valueList
->GetFirst();
1097 stringList
.Add(stringExpr
->StringValue());
1098 stringExpr
= stringExpr
->GetNext();
1100 controlItem
->SetStringValues(stringList
);
1102 // This is now obsolete: it's in the window style.
1103 // Check for wxSINGLE/wxMULTIPLE
1104 wxExpr
*mult
= (wxExpr
*) NULL
;
1106 controlItem->SetValue1(wxLB_SINGLE);
1108 if (((mult
= expr
->Nth(count
)) != 0) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1111 wxString m(mult->StringValue());
1112 if (m == "wxLB_MULTIPLE")
1113 controlItem->SetValue1(wxLB_MULTIPLE);
1114 else if (m == "wxLB_EXTENDED")
1115 controlItem->SetValue1(wxLB_EXTENDED);
1120 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1122 // Skip past the obsolete label font spec if there are two consecutive specs
1123 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1125 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1129 else if (controlType
== wxT("wxChoice"))
1131 wxExpr
*valueList
= (wxExpr
*) NULL
;
1132 // Check for default value list
1133 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1135 wxStringList stringList
;
1136 wxExpr
*stringExpr
= valueList
->GetFirst();
1139 stringList
.Add(stringExpr
->StringValue());
1140 stringExpr
= stringExpr
->GetNext();
1142 controlItem
->SetStringValues(stringList
);
1146 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1148 // Skip past the obsolete label font spec if there are two consecutive specs
1149 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1151 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1156 else if (controlType
== wxT("wxComboBox"))
1158 wxExpr
*textValue
= expr
->Nth(count
);
1159 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1161 wxString
str(textValue
->StringValue());
1162 controlItem
->SetValue4(str
);
1166 wxExpr
*valueList
= (wxExpr
*) NULL
;
1167 // Check for default value list
1168 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1170 wxStringList stringList
;
1171 wxExpr
*stringExpr
= valueList
->GetFirst();
1174 stringList
.Add(stringExpr
->StringValue());
1175 stringExpr
= stringExpr
->GetNext();
1177 controlItem
->SetStringValues(stringList
);
1181 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1183 // Skip past the obsolete label font spec if there are two consecutive specs
1184 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1186 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1193 else if (controlType
== wxT("wxRadioBox"))
1195 wxExpr
*valueList
= (wxExpr
*) NULL
;
1196 // Check for default value list
1197 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1199 wxStringList stringList
;
1200 wxExpr
*stringExpr
= valueList
->GetFirst();
1203 stringList
.Add(stringExpr
->StringValue());
1204 stringExpr
= stringExpr
->GetNext();
1206 controlItem
->SetStringValues(stringList
);
1209 // majorDim (number of rows or cols)
1210 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1212 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1216 controlItem
->SetValue1(0);
1218 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1220 // Skip past the obsolete label font spec if there are two consecutive specs
1221 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1223 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1231 return (wxItemResource
*) NULL
;
1236 // Forward declaration
1237 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, wxExpr
*expr
);
1240 * Interpet a menu item
1243 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, wxExpr
*expr
)
1245 wxItemResource
*item
= new wxItemResource
;
1247 wxExpr
*labelExpr
= expr
->Nth(0);
1248 wxExpr
*idExpr
= expr
->Nth(1);
1249 wxExpr
*helpExpr
= expr
->Nth(2);
1250 wxExpr
*checkableExpr
= expr
->Nth(3);
1252 // Further keywords/attributes to follow sometime...
1253 if (expr
->Number() == 0)
1255 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1256 item
->SetType(wxT("wxMenuSeparator"));
1261 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1262 item
->SetType(wxT("wxMenu")); // Well, menu item, but doesn't matter.
1265 wxString
str(labelExpr
->StringValue());
1266 item
->SetTitle(str
);
1271 // If a string or word, must look up in identifier table.
1272 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1274 wxString
str(idExpr
->StringValue());
1275 id
= wxResourceGetIdentifier(str
, &table
);
1278 wxLogWarning(_("Could not resolve menu id '%s'. Use (non-zero) integer instead\nor provide #define (see manual for caveats)"),
1279 (const wxChar
*) idExpr
->StringValue());
1282 else if (idExpr
->Type() == PrologInteger
)
1283 id
= (int)idExpr
->IntegerValue();
1284 item
->SetValue1(id
);
1288 wxString
str(helpExpr
->StringValue());
1289 item
->SetValue4(str
);
1292 item
->SetValue2(checkableExpr
->IntegerValue());
1294 // Find the first expression that's a list, for submenu
1295 wxExpr
*subMenuExpr
= expr
->GetFirst();
1296 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1297 subMenuExpr
= subMenuExpr
->GetNext();
1301 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1302 item
->GetChildren().Append(child
);
1303 subMenuExpr
= subMenuExpr
->GetNext();
1310 * Interpret a nested list as a menu
1313 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1315 wxItemResource *menu = new wxItemResource;
1316 // menu->SetType(wxTYPE_MENU);
1317 menu->SetType("wxMenu");
1318 wxExpr *element = expr->GetFirst();
1321 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1323 menu->GetChildren().Append(item);
1324 element = element->GetNext();
1330 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
)
1332 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1333 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1335 return (wxItemResource
*) NULL
;
1337 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1340 return (wxItemResource
*) NULL
;
1343 if (expr
->GetAttributeValue(wxT("name"), name
))
1345 menuResource
->SetName(name
);
1348 return menuResource
;
1351 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
)
1353 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1354 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1356 return (wxItemResource
*) NULL
;
1358 wxItemResource
*resource
= new wxItemResource
;
1359 resource
->SetType(wxT("wxMenu"));
1360 // resource->SetType(wxTYPE_MENU);
1362 wxExpr
*element
= listExpr
->GetFirst();
1365 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1366 resource
->GetChildren().Append(menuResource
);
1367 element
= element
->GetNext();
1371 if (expr
->GetAttributeValue(wxT("name"), name
))
1373 resource
->SetName(name
);
1379 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), wxExpr
*WXUNUSED(expr
))
1381 return (wxItemResource
*) NULL
;
1384 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), wxExpr
*expr
)
1386 wxItemResource
*bitmapItem
= new wxItemResource
;
1387 // bitmapItem->SetType(wxTYPE_BITMAP);
1388 bitmapItem
->SetType(wxT("wxBitmap"));
1390 if (expr
->GetAttributeValue(wxT("name"), name
))
1392 bitmapItem
->SetName(name
);
1394 // Now parse all bitmap specifications
1395 wxExpr
*bitmapExpr
= expr
->GetFirst();
1398 if (bitmapExpr
->Number() == 3)
1400 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1401 if (bitmapKeyword
== wxT("bitmap") || bitmapKeyword
== wxT("icon"))
1403 // The value part: always a list.
1404 wxExpr
*listExpr
= bitmapExpr
->Nth(2);
1405 if (listExpr
->Type() == PrologList
)
1407 wxItemResource
*bitmapSpec
= new wxItemResource
;
1408 // bitmapSpec->SetType(wxTYPE_BITMAP);
1409 bitmapSpec
->SetType(wxT("wxBitmap"));
1411 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1412 // where everything after 'filename' is optional.
1413 wxExpr
*nameExpr
= listExpr
->Nth(0);
1414 wxExpr
*typeExpr
= listExpr
->Nth(1);
1415 wxExpr
*platformExpr
= listExpr
->Nth(2);
1416 wxExpr
*coloursExpr
= listExpr
->Nth(3);
1417 wxExpr
*xresExpr
= listExpr
->Nth(4);
1418 wxExpr
*yresExpr
= listExpr
->Nth(5);
1419 if (nameExpr
&& !nameExpr
->StringValue().empty())
1421 bitmapSpec
->SetName(nameExpr
->StringValue());
1423 if (typeExpr
&& !typeExpr
->StringValue().empty())
1425 bitmapSpec
->SetValue1(wxParseWindowStyle(typeExpr
->StringValue()));
1428 bitmapSpec
->SetValue1(0);
1430 if (platformExpr
&& !platformExpr
->StringValue().empty())
1432 wxString
plat(platformExpr
->StringValue());
1433 if (plat
== wxT("windows") || plat
== wxT("WINDOWS"))
1434 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1435 else if (plat
== wxT("x") || plat
== wxT("X"))
1436 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1437 else if (plat
== wxT("mac") || plat
== wxT("MAC"))
1438 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1440 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1443 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1446 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1450 xres
= (int)xresExpr
->IntegerValue();
1452 yres
= (int)yresExpr
->IntegerValue();
1453 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1455 bitmapItem
->GetChildren().Append(bitmapSpec
);
1459 bitmapExpr
= bitmapExpr
->GetNext();
1465 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
)
1467 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1470 // item->SetType(wxTYPE_ICON);
1471 item
->SetType(wxT("wxIcon"));
1475 return (wxItemResource
*) NULL
;
1478 // Interpret list expression as a font
1479 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
)
1481 if (expr
->Type() != PrologList
)
1485 int family
= wxSWISS
;
1486 int style
= wxNORMAL
;
1487 int weight
= wxNORMAL
;
1491 wxExpr
*pointExpr
= expr
->Nth(0);
1492 wxExpr
*familyExpr
= expr
->Nth(1);
1493 wxExpr
*styleExpr
= expr
->Nth(2);
1494 wxExpr
*weightExpr
= expr
->Nth(3);
1495 wxExpr
*underlineExpr
= expr
->Nth(4);
1496 wxExpr
*faceNameExpr
= expr
->Nth(5);
1498 point
= (int)pointExpr
->IntegerValue();
1503 str
= familyExpr
->StringValue();
1504 family
= (int)wxParseWindowStyle(str
);
1508 str
= styleExpr
->StringValue();
1509 style
= (int)wxParseWindowStyle(str
);
1513 str
= weightExpr
->StringValue();
1514 weight
= (int)wxParseWindowStyle(str
);
1517 underline
= (int)underlineExpr
->IntegerValue();
1519 faceName
= faceNameExpr
->StringValue();
1521 return *wxTheFontList
->FindOrCreateFont(point
, family
, style
, weight
,
1522 (underline
!= 0), faceName
);
1526 * (Re)allocate buffer for reading in from resource file
1529 bool wxReallocateResourceBuffer()
1531 if (!wxResourceBuffer
)
1533 wxResourceBufferSize
= 1000;
1534 wxResourceBuffer
= new char[wxResourceBufferSize
];
1537 if (wxResourceBuffer
)
1539 long newSize
= wxResourceBufferSize
+ 1000;
1540 char *tmp
= new char[(int)newSize
];
1541 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1542 delete[] wxResourceBuffer
;
1543 wxResourceBuffer
= tmp
;
1544 wxResourceBufferSize
= newSize
;
1549 static bool wxEatWhiteSpace(FILE *fd
)
1553 while ((ch
= getc(fd
)) != EOF
)
1568 ungetc(prev_ch
, fd
);
1576 while ((ch
= getc(fd
)) != EOF
)
1578 if (ch
== '/' && prev_ch
== '*')
1586 static char buffer
[255];
1587 fgets(buffer
, 255, fd
);
1591 ungetc(prev_ch
, fd
);
1605 static bool wxEatWhiteSpace(wxInputStream
*is
)
1607 char ch
= is
->GetC() ;
1608 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
1615 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
1617 // Check for comment
1623 bool finished
= false;
1627 if (is
->LastRead() == 0)
1631 int newCh
= is
->GetC();
1646 return wxEatWhiteSpace(is
);
1649 bool wxGetResourceToken(FILE *fd
)
1651 if (!wxResourceBuffer
)
1652 wxReallocateResourceBuffer();
1653 wxResourceBuffer
[0] = 0;
1654 wxEatWhiteSpace(fd
);
1660 wxResourceBufferCount
= 0;
1667 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1670 // Escaped characters
1671 else if (ch
== '\\')
1673 int newCh
= getc(fd
);
1676 else if (newCh
== 10)
1684 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1685 wxReallocateResourceBuffer();
1686 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1687 wxResourceBufferCount
++;
1690 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1694 wxResourceBufferCount
= 0;
1696 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1698 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1699 wxReallocateResourceBuffer();
1700 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1701 wxResourceBufferCount
++;
1705 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1712 bool wxGetResourceToken(wxInputStream
*is
)
1714 if (!wxResourceBuffer
)
1715 wxReallocateResourceBuffer();
1716 wxResourceBuffer
[0] = 0;
1717 wxEatWhiteSpace(is
);
1719 int ch
= is
->GetC() ;
1723 wxResourceBufferCount
= 0;
1730 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1733 // Escaped characters
1734 else if (ch
== '\\')
1736 char newCh
= is
->GetC();
1739 else if (newCh
== 10)
1741 else if (newCh
== 13) // mac
1749 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1750 wxReallocateResourceBuffer();
1751 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1752 wxResourceBufferCount
++;
1755 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1759 wxResourceBufferCount
= 0;
1761 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1763 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1764 wxReallocateResourceBuffer();
1765 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1766 wxResourceBufferCount
++;
1770 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1778 * Files are in form:
1779 static char *name = "....";
1780 with possible comments.
1783 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1786 table
= wxDefaultResourceTable
;
1788 // static or #define
1789 if (!wxGetResourceToken(fd
))
1795 if (strcmp(wxResourceBuffer
, "#define") == 0)
1797 wxGetResourceToken(fd
);
1798 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1799 wxGetResourceToken(fd
);
1800 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1801 if (wxIsdigit(value
[0]))
1803 int val
= (int)wxAtol(value
);
1804 wxResourceAddIdentifier(name
, val
, table
);
1808 wxLogWarning(_("#define %s must be an integer."), name
);
1818 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1820 wxGetResourceToken(fd
);
1821 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1822 wxChar
*actualName
= name
;
1823 if (name
[0] == wxT('"'))
1824 actualName
= name
+ 1;
1825 int len
= wxStrlen(name
);
1826 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1828 if (!wxResourceParseIncludeFile(actualName
, table
))
1830 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1835 else if (strcmp(wxResourceBuffer
, "static") != 0)
1838 wxStrcpy(buf
, _("Found "));
1839 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
1840 wxStrcat(buf
, _(", expected static, #include or #define\nwhile parsing resource."));
1846 if (!wxGetResourceToken(fd
))
1848 wxLogWarning(_("Unexpected end of file while parsing resource."));
1853 if (strcmp(wxResourceBuffer
, "char") != 0)
1855 wxLogWarning(_("Expected 'char' while parsing resource."));
1860 if (!wxGetResourceToken(fd
))
1862 wxLogWarning(_("Unexpected end of file while parsing resource."));
1867 if (wxResourceBuffer
[0] != '*')
1869 wxLogWarning(_("Expected '*' while parsing resource."));
1872 wxChar nameBuf
[100];
1873 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
1877 if (!wxGetResourceToken(fd
))
1879 wxLogWarning(_("Unexpected end of file while parsing resource."));
1884 if (strcmp(wxResourceBuffer
, "=") != 0)
1886 wxLogWarning(_("Expected '=' while parsing resource."));
1891 if (!wxGetResourceToken(fd
))
1893 wxLogWarning(_("Unexpected end of file while parsing resource."));
1899 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1901 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1906 if (!wxGetResourceToken(fd
))
1913 bool wxResourceReadOneResource(wxInputStream
*fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1916 table
= wxDefaultResourceTable
;
1918 // static or #define
1919 if (!wxGetResourceToken(fd
))
1925 if (strcmp(wxResourceBuffer
, "#define") == 0)
1927 wxGetResourceToken(fd
);
1928 wxChar
*name
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1929 wxGetResourceToken(fd
);
1930 wxChar
*value
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1931 if (wxIsalpha(value
[0]))
1933 int val
= (int)wxAtol(value
);
1934 wxResourceAddIdentifier(name
, val
, table
);
1938 wxLogWarning(_("#define %s must be an integer."), name
);
1948 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1950 wxGetResourceToken(fd
);
1951 wxChar
*name
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1952 wxChar
*actualName
= name
;
1953 if (name
[0] == wxT('"'))
1954 actualName
= name
+ 1;
1955 int len
= wxStrlen(name
);
1956 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1958 if (!wxResourceParseIncludeFile(actualName
, table
))
1960 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1965 else if (strcmp(wxResourceBuffer
, "static") != 0)
1968 wxStrcpy(buf
, _("Found "));
1969 wxStrncat(buf
, wxConvLibc
.cMB2WX(wxResourceBuffer
), 30);
1970 wxStrcat(buf
, _(", expected static, #include or #define\nwhile parsing resource."));
1976 if (!wxGetResourceToken(fd
))
1978 wxLogWarning(_("Unexpected end of file while parsing resource."));
1983 if (strcmp(wxResourceBuffer
, "char") != 0)
1985 wxLogWarning(_("Expected 'char' while parsing resource."));
1990 if (!wxGetResourceToken(fd
))
1992 wxLogWarning(_("Unexpected end of file while parsing resource."));
1997 if (wxResourceBuffer
[0] != '*')
1999 wxLogWarning(_("Expected '*' while parsing resource."));
2003 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
2006 if (!wxGetResourceToken(fd
))
2008 wxLogWarning(_("Unexpected end of file while parsing resource."));
2013 if (strcmp(wxResourceBuffer
, "=") != 0)
2015 wxLogWarning(_("Expected '=' while parsing resource."));
2020 if (!wxGetResourceToken(fd
))
2022 wxLogWarning(_("Unexpected end of file while parsing resource."));
2028 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2030 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2035 if (!wxGetResourceToken(fd
))
2043 * Parses string window style into integer window style
2047 * Style flag parsing, e.g.
2048 * "wxSYSTEM_MENU | wxBORDER" -> integer
2051 wxChar
* wxResourceParseWord(wxChar
*s
, int *i
)
2054 return (wxChar
*) NULL
;
2056 static wxChar buf
[150];
2057 int len
= wxStrlen(s
);
2060 while ((ii
< len
) && (wxIsalpha(s
[ii
]) || (s
[ii
] == wxT('_'))))
2068 // Eat whitespace and conjunction characters
2069 while ((ii
< len
) &&
2070 ((s
[ii
] == wxT(' ')) || (s
[ii
] == wxT('|')) || (s
[ii
] == wxT(','))))
2076 return (wxChar
*) NULL
;
2081 struct wxResourceBitListStruct
2087 static wxResourceBitListStruct wxResourceBitListTable
[] =
2090 { wxT("wxSINGLE"), wxLB_SINGLE
},
2091 { wxT("wxMULTIPLE"), wxLB_MULTIPLE
},
2092 { wxT("wxEXTENDED"), wxLB_EXTENDED
},
2093 { wxT("wxLB_SINGLE"), wxLB_SINGLE
},
2094 { wxT("wxLB_MULTIPLE"), wxLB_MULTIPLE
},
2095 { wxT("wxLB_EXTENDED"), wxLB_EXTENDED
},
2096 { wxT("wxLB_NEEDED_SB"), wxLB_NEEDED_SB
},
2097 { wxT("wxLB_ALWAYS_SB"), wxLB_ALWAYS_SB
},
2098 { wxT("wxLB_SORT"), wxLB_SORT
},
2099 { wxT("wxLB_OWNERDRAW"), wxLB_OWNERDRAW
},
2100 { wxT("wxLB_HSCROLL"), wxLB_HSCROLL
},
2103 { wxT("wxCB_SIMPLE"), wxCB_SIMPLE
},
2104 { wxT("wxCB_DROPDOWN"), wxCB_DROPDOWN
},
2105 { wxT("wxCB_READONLY"), wxCB_READONLY
},
2106 { wxT("wxCB_SORT"), wxCB_SORT
},
2109 #if WXWIN_COMPATIBILITY_2_6
2110 { wxT("wxGA_PROGRESSBAR"), wxGA_PROGRESSBAR
},
2111 #endif // WXWIN_COMPATIBILITY_2_6
2112 { wxT("wxGA_HORIZONTAL"), wxGA_HORIZONTAL
},
2113 { wxT("wxGA_VERTICAL"), wxGA_VERTICAL
},
2116 #if WXWIN_COMPATIBILITY_2_6
2117 { wxT("wxPASSWORD"), wxTE_PASSWORD
},
2118 { wxT("wxPROCESS_ENTER"), wxTE_PROCESS_ENTER
},
2120 { wxT("wxTE_PASSWORD"), wxTE_PASSWORD
},
2121 { wxT("wxTE_READONLY"), wxTE_READONLY
},
2122 { wxT("wxTE_PROCESS_ENTER"), wxTE_PROCESS_ENTER
},
2123 { wxT("wxTE_MULTILINE"), wxTE_MULTILINE
},
2124 { wxT("wxTE_NO_VSCROLL"), wxTE_NO_VSCROLL
},
2126 /* wxRadioBox/wxRadioButton */
2127 { wxT("wxRB_GROUP"), wxRB_GROUP
},
2128 { wxT("wxRA_SPECIFY_COLS"), wxRA_SPECIFY_COLS
},
2129 { wxT("wxRA_SPECIFY_ROWS"), wxRA_SPECIFY_ROWS
},
2130 { wxT("wxRA_HORIZONTAL"), wxRA_HORIZONTAL
},
2131 { wxT("wxRA_VERTICAL"), wxRA_VERTICAL
},
2134 { wxT("wxSL_HORIZONTAL"), wxSL_HORIZONTAL
},
2135 { wxT("wxSL_VERTICAL"), wxSL_VERTICAL
},
2136 { wxT("wxSL_AUTOTICKS"), wxSL_AUTOTICKS
},
2137 { wxT("wxSL_LABELS"), wxSL_LABELS
},
2138 { wxT("wxSL_LEFT"), wxSL_LEFT
},
2139 { wxT("wxSL_TOP"), wxSL_TOP
},
2140 { wxT("wxSL_RIGHT"), wxSL_RIGHT
},
2141 { wxT("wxSL_BOTTOM"), wxSL_BOTTOM
},
2142 { wxT("wxSL_BOTH"), wxSL_BOTH
},
2143 { wxT("wxSL_SELRANGE"), wxSL_SELRANGE
},
2146 { wxT("wxSB_HORIZONTAL"), wxSB_HORIZONTAL
},
2147 { wxT("wxSB_VERTICAL"), wxSB_VERTICAL
},
2150 { wxT("wxBU_AUTODRAW"), wxBU_AUTODRAW
},
2151 { wxT("wxBU_NOAUTODRAW"), wxBU_NOAUTODRAW
},
2154 { wxT("wxTR_HAS_BUTTONS"), wxTR_HAS_BUTTONS
},
2155 { wxT("wxTR_EDIT_LABELS"), wxTR_EDIT_LABELS
},
2156 { wxT("wxTR_LINES_AT_ROOT"), wxTR_LINES_AT_ROOT
},
2159 { wxT("wxLC_ICON"), wxLC_ICON
},
2160 { wxT("wxLC_SMALL_ICON"), wxLC_SMALL_ICON
},
2161 { wxT("wxLC_LIST"), wxLC_LIST
},
2162 { wxT("wxLC_REPORT"), wxLC_REPORT
},
2163 { wxT("wxLC_ALIGN_TOP"), wxLC_ALIGN_TOP
},
2164 { wxT("wxLC_ALIGN_LEFT"), wxLC_ALIGN_LEFT
},
2165 { wxT("wxLC_AUTOARRANGE"), wxLC_AUTOARRANGE
},
2166 { wxT("wxLC_USER_TEXT"), wxLC_USER_TEXT
},
2167 { wxT("wxLC_EDIT_LABELS"), wxLC_EDIT_LABELS
},
2168 { wxT("wxLC_NO_HEADER"), wxLC_NO_HEADER
},
2169 { wxT("wxLC_NO_SORT_HEADER"), wxLC_NO_SORT_HEADER
},
2170 { wxT("wxLC_SINGLE_SEL"), wxLC_SINGLE_SEL
},
2171 { wxT("wxLC_SORT_ASCENDING"), wxLC_SORT_ASCENDING
},
2172 { wxT("wxLC_SORT_DESCENDING"), wxLC_SORT_DESCENDING
},
2175 { wxT("wxSP_VERTICAL"), wxSP_VERTICAL
},
2176 { wxT("wxSP_HORIZONTAL"), wxSP_HORIZONTAL
},
2177 { wxT("wxSP_ARROW_KEYS"), wxSP_ARROW_KEYS
},
2178 { wxT("wxSP_WRAP"), wxSP_WRAP
},
2181 { wxT("wxSP_NOBORDER"), wxSP_NOBORDER
},
2182 { wxT("wxSP_3D"), wxSP_3D
},
2183 { wxT("wxSP_BORDER"), wxSP_BORDER
},
2186 { wxT("wxTC_MULTILINE"), wxTC_MULTILINE
},
2187 { wxT("wxTC_RIGHTJUSTIFY"), wxTC_RIGHTJUSTIFY
},
2188 { wxT("wxTC_FIXEDWIDTH"), wxTC_FIXEDWIDTH
},
2189 { wxT("wxTC_OWNERDRAW"), wxTC_OWNERDRAW
},
2192 { wxT("wxST_SIZEGRIP"), wxST_SIZEGRIP
},
2195 { wxT("wxFIXED_LENGTH"), wxFIXED_LENGTH
},
2196 { wxT("wxALIGN_LEFT"), wxALIGN_LEFT
},
2197 { wxT("wxALIGN_CENTER"), wxALIGN_CENTER
},
2198 { wxT("wxALIGN_CENTRE"), wxALIGN_CENTRE
},
2199 { wxT("wxALIGN_RIGHT"), wxALIGN_RIGHT
},
2200 { wxT("wxCOLOURED"), wxCOLOURED
},
2203 { wxT("wxTB_3DBUTTONS"), wxTB_3DBUTTONS
},
2204 { wxT("wxTB_HORIZONTAL"), wxTB_HORIZONTAL
},
2205 { wxT("wxTB_VERTICAL"), wxTB_VERTICAL
},
2206 { wxT("wxTB_FLAT"), wxTB_FLAT
},
2208 #if WXWIN_COMPATIBILITY_2_6
2210 { wxT("wxDIALOG_MODAL"), wxDIALOG_MODAL
},
2211 #endif // WXWIN_COMPATIBILITY_2_6
2214 { wxT("wxVSCROLL"), wxVSCROLL
},
2215 { wxT("wxHSCROLL"), wxHSCROLL
},
2216 { wxT("wxCAPTION"), wxCAPTION
},
2217 { wxT("wxSTAY_ON_TOP"), wxSTAY_ON_TOP
},
2218 { wxT("wxICONIZE"), wxICONIZE
},
2219 { wxT("wxMINIMIZE"), wxICONIZE
},
2220 { wxT("wxMAXIMIZE"), wxMAXIMIZE
},
2222 { wxT("wxMDI_PARENT"), 0},
2223 { wxT("wxMDI_CHILD"), 0},
2224 { wxT("wxTHICK_FRAME"), wxRESIZE_BORDER
},
2225 { wxT("wxRESIZE_BORDER"), wxRESIZE_BORDER
},
2226 { wxT("wxSYSTEM_MENU"), wxSYSTEM_MENU
},
2227 { wxT("wxMINIMIZE_BOX"), wxMINIMIZE_BOX
},
2228 { wxT("wxMAXIMIZE_BOX"), wxMAXIMIZE_BOX
},
2229 #if WXWIN_COMPATIBILITY_2_6
2230 { wxT("wxRESIZE_BOX"), wxRESIZE_BOX
},
2231 #endif // WXWIN_COMPATIBILITY_2_6
2232 { wxT("wxDEFAULT_FRAME_STYLE"), wxDEFAULT_FRAME_STYLE
},
2233 { wxT("wxDEFAULT_FRAME"), wxDEFAULT_FRAME_STYLE
},
2234 { wxT("wxDEFAULT_DIALOG_STYLE"), wxDEFAULT_DIALOG_STYLE
},
2235 { wxT("wxBORDER"), wxBORDER
},
2236 { wxT("wxRETAINED"), wxRETAINED
},
2237 { wxT("wxNATIVE_IMPL"), 0},
2238 { wxT("wxEXTENDED_IMPL"), 0},
2239 { wxT("wxBACKINGSTORE"), wxBACKINGSTORE
},
2240 // { wxT("wxFLAT"), wxFLAT},
2241 // { wxT("wxMOTIF_RESIZE"), wxMOTIF_RESIZE},
2242 { wxT("wxFIXED_LENGTH"), 0},
2243 { wxT("wxDOUBLE_BORDER"), wxDOUBLE_BORDER
},
2244 { wxT("wxSUNKEN_BORDER"), wxSUNKEN_BORDER
},
2245 { wxT("wxRAISED_BORDER"), wxRAISED_BORDER
},
2246 { wxT("wxSIMPLE_BORDER"), wxSIMPLE_BORDER
},
2247 { wxT("wxSTATIC_BORDER"), wxSTATIC_BORDER
},
2248 { wxT("wxTRANSPARENT_WINDOW"), wxTRANSPARENT_WINDOW
},
2249 { wxT("wxNO_BORDER"), wxNO_BORDER
},
2250 { wxT("wxCLIP_CHILDREN"), wxCLIP_CHILDREN
},
2251 { wxT("wxCLIP_SIBLINGS"), wxCLIP_SIBLINGS
},
2252 { wxT("wxTAB_TRAVERSAL"), 0}, // Compatibility only
2254 { wxT("wxTINY_CAPTION_HORIZ"), wxTINY_CAPTION_HORIZ
},
2255 { wxT("wxTINY_CAPTION_VERT"), wxTINY_CAPTION_VERT
},
2257 // Text font families
2258 { wxT("wxDEFAULT"), wxDEFAULT
},
2259 { wxT("wxDECORATIVE"), wxDECORATIVE
},
2260 { wxT("wxROMAN"), wxROMAN
},
2261 { wxT("wxSCRIPT"), wxSCRIPT
},
2262 { wxT("wxSWISS"), wxSWISS
},
2263 { wxT("wxMODERN"), wxMODERN
},
2264 { wxT("wxTELETYPE"), wxTELETYPE
},
2265 { wxT("wxVARIABLE"), wxVARIABLE
},
2266 { wxT("wxFIXED"), wxFIXED
},
2267 { wxT("wxNORMAL"), wxNORMAL
},
2268 { wxT("wxLIGHT"), wxLIGHT
},
2269 { wxT("wxBOLD"), wxBOLD
},
2270 { wxT("wxITALIC"), wxITALIC
},
2271 { wxT("wxSLANT"), wxSLANT
},
2272 { wxT("wxSOLID"), wxSOLID
},
2273 { wxT("wxDOT"), wxDOT
},
2274 { wxT("wxLONG_DASH"), wxLONG_DASH
},
2275 { wxT("wxSHORT_DASH"), wxSHORT_DASH
},
2276 { wxT("wxDOT_DASH"), wxDOT_DASH
},
2277 { wxT("wxUSER_DASH"), wxUSER_DASH
},
2278 { wxT("wxTRANSPARENT"), wxTRANSPARENT
},
2279 { wxT("wxSTIPPLE"), wxSTIPPLE
},
2280 { wxT("wxBDIAGONAL_HATCH"), wxBDIAGONAL_HATCH
},
2281 { wxT("wxCROSSDIAG_HATCH"), wxCROSSDIAG_HATCH
},
2282 { wxT("wxFDIAGONAL_HATCH"), wxFDIAGONAL_HATCH
},
2283 { wxT("wxCROSS_HATCH"), wxCROSS_HATCH
},
2284 { wxT("wxHORIZONTAL_HATCH"), wxHORIZONTAL_HATCH
},
2285 { wxT("wxVERTICAL_HATCH"), wxVERTICAL_HATCH
},
2286 { wxT("wxJOIN_BEVEL"), wxJOIN_BEVEL
},
2287 { wxT("wxJOIN_MITER"), wxJOIN_MITER
},
2288 { wxT("wxJOIN_ROUND"), wxJOIN_ROUND
},
2289 { wxT("wxCAP_ROUND"), wxCAP_ROUND
},
2290 { wxT("wxCAP_PROJECTING"), wxCAP_PROJECTING
},
2291 { wxT("wxCAP_BUTT"), wxCAP_BUTT
},
2294 { wxT("wxCLEAR"), wxCLEAR
},
2295 { wxT("wxXOR"), wxXOR
},
2296 { wxT("wxINVERT"), wxINVERT
},
2297 { wxT("wxOR_REVERSE"), wxOR_REVERSE
},
2298 { wxT("wxAND_REVERSE"), wxAND_REVERSE
},
2299 { wxT("wxCOPY"), wxCOPY
},
2300 { wxT("wxAND"), wxAND
},
2301 { wxT("wxAND_INVERT"), wxAND_INVERT
},
2302 { wxT("wxNO_OP"), wxNO_OP
},
2303 { wxT("wxNOR"), wxNOR
},
2304 { wxT("wxEQUIV"), wxEQUIV
},
2305 { wxT("wxSRC_INVERT"), wxSRC_INVERT
},
2306 { wxT("wxOR_INVERT"), wxOR_INVERT
},
2307 { wxT("wxNAND"), wxNAND
},
2308 { wxT("wxOR"), wxOR
},
2309 { wxT("wxSET"), wxSET
},
2311 { wxT("wxFLOOD_SURFACE"), wxFLOOD_SURFACE
},
2312 { wxT("wxFLOOD_BORDER"), wxFLOOD_BORDER
},
2313 { wxT("wxODDEVEN_RULE"), wxODDEVEN_RULE
},
2314 { wxT("wxWINDING_RULE"), wxWINDING_RULE
},
2315 { wxT("wxHORIZONTAL"), wxHORIZONTAL
},
2316 { wxT("wxVERTICAL"), wxVERTICAL
},
2317 { wxT("wxBOTH"), wxBOTH
},
2318 { wxT("wxCENTER_FRAME"), wxCENTER_FRAME
},
2319 { wxT("wxOK"), wxOK
},
2320 { wxT("wxYES_NO"), wxYES_NO
},
2321 { wxT("wxCANCEL"), wxCANCEL
},
2322 { wxT("wxYES"), wxYES
},
2323 { wxT("wxNO"), wxNO
},
2324 { wxT("wxICON_EXCLAMATION"), wxICON_EXCLAMATION
},
2325 { wxT("wxICON_HAND"), wxICON_HAND
},
2326 { wxT("wxICON_QUESTION"), wxICON_QUESTION
},
2327 { wxT("wxICON_INFORMATION"), wxICON_INFORMATION
},
2328 { wxT("wxICON_STOP"), wxICON_STOP
},
2329 { wxT("wxICON_ASTERISK"), wxICON_ASTERISK
},
2330 { wxT("wxICON_MASK"), wxICON_MASK
},
2331 { wxT("wxCENTRE"), wxCENTRE
},
2332 { wxT("wxCENTER"), wxCENTRE
},
2333 #if WXWIN_COMPATIBILITY_2_6
2334 { wxT("wxUSER_COLOURS"), wxUSER_COLOURS
},
2335 #endif // WXWIN_COMPATIBILITY_2_6
2336 { wxT("wxVERTICAL_LABEL"), 0},
2337 { wxT("wxHORIZONTAL_LABEL"), 0},
2339 // Bitmap types (not strictly styles)
2340 { wxT("wxBITMAP_TYPE_XPM"), wxBITMAP_TYPE_XPM
},
2341 { wxT("wxBITMAP_TYPE_XBM"), wxBITMAP_TYPE_XBM
},
2342 { wxT("wxBITMAP_TYPE_BMP"), wxBITMAP_TYPE_BMP
},
2343 { wxT("wxBITMAP_TYPE_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2344 { wxT("wxBITMAP_TYPE_BMP_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2345 { wxT("wxBITMAP_TYPE_GIF"), wxBITMAP_TYPE_GIF
},
2346 { wxT("wxBITMAP_TYPE_TIF"), wxBITMAP_TYPE_TIF
},
2347 { wxT("wxBITMAP_TYPE_ICO"), wxBITMAP_TYPE_ICO
},
2348 { wxT("wxBITMAP_TYPE_ICO_RESOURCE"), wxBITMAP_TYPE_ICO_RESOURCE
},
2349 { wxT("wxBITMAP_TYPE_CUR"), wxBITMAP_TYPE_CUR
},
2350 { wxT("wxBITMAP_TYPE_CUR_RESOURCE"), wxBITMAP_TYPE_CUR_RESOURCE
},
2351 { wxT("wxBITMAP_TYPE_XBM_DATA"), wxBITMAP_TYPE_XBM_DATA
},
2352 { wxT("wxBITMAP_TYPE_XPM_DATA"), wxBITMAP_TYPE_XPM_DATA
},
2353 { wxT("wxBITMAP_TYPE_ANY"), wxBITMAP_TYPE_ANY
}
2356 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
2358 long wxParseWindowStyle(const wxString
& bitListString
)
2363 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2364 while (word
!= NULL
)
2368 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2369 if (wxStrcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2371 bitList
|= wxResourceBitListTable
[j
].bits
;
2377 wxLogWarning(_("Unrecognized style %s while parsing resource."), word
);
2380 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2386 * Load a bitmap from a wxWidgets resource, choosing an optimum
2387 * depth and appropriate type.
2390 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
2393 table
= wxDefaultResourceTable
;
2395 wxItemResource
*item
= table
->FindResource(resource
);
2398 if ((item
->GetType().empty()) || (item
->GetType() != wxT("wxBitmap")))
2400 wxLogWarning(_("%s not a bitmap resource specification."), (const wxChar
*) resource
);
2401 return wxNullBitmap
;
2403 int thisDepth
= wxDisplayDepth();
2404 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2406 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2408 // Try to find optimum bitmap for this platform/colour depth
2409 wxNode
*node
= item
->GetChildren().GetFirst();
2412 wxItemResource
*child
= (wxItemResource
*)node
->GetData();
2413 int platform
= (int)child
->GetValue2();
2414 int noColours
= (int)child
->GetValue3();
2416 char *name = child->GetName();
2417 int bitmapType = (int)child->GetValue1();
2418 int xRes = child->GetWidth();
2419 int yRes = child->GetHeight();
2424 case RESOURCE_PLATFORM_ANY
:
2426 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2427 optResource
= child
;
2430 // Maximise the number of colours.
2431 // If noColours is zero (unspecified), then assume this
2432 // is the right one.
2433 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2434 optResource
= child
;
2439 case RESOURCE_PLATFORM_WINDOWS
:
2441 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2442 optResource
= child
;
2445 // Maximise the number of colours
2446 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2447 optResource
= child
;
2453 case RESOURCE_PLATFORM_X
:
2455 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2456 optResource
= child
;
2459 // Maximise the number of colours
2460 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2461 optResource
= child
;
2467 case RESOURCE_PLATFORM_MAC
:
2469 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2470 optResource
= child
;
2473 // Maximise the number of colours
2474 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2475 optResource
= child
;
2483 node
= node
->GetNext();
2485 // If no matching resource, fail.
2487 return wxNullBitmap
;
2489 wxString name
= optResource
->GetName();
2490 int bitmapType
= (int)optResource
->GetValue1();
2493 case wxBITMAP_TYPE_XBM_DATA
:
2496 wxItemResource
*item
= table
->FindResource(name
);
2499 wxLogWarning(_("Failed to find XBM resource %s.\n"
2500 "Forgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2501 return wxNullBitmap
;
2503 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2505 wxLogWarning(_("No XBM facility available!"));
2509 case wxBITMAP_TYPE_XPM_DATA
:
2511 wxItemResource
*item
= table
->FindResource(name
);
2514 wxLogWarning(_("Failed to find XPM resource %s.\nForgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2515 return wxNullBitmap
;
2517 return wxBitmap((char **)item
->GetValue1());
2521 #if defined(__WXPM__)
2522 return wxNullBitmap
;
2524 return wxBitmap(name
, (wxBitmapType
)bitmapType
);
2529 return wxNullBitmap
;
2534 wxLogWarning(_("Bitmap resource specification %s not found."), (const wxChar
*) resource
);
2535 return wxNullBitmap
;
2540 * Load an icon from a wxWidgets resource, choosing an optimum
2541 * depth and appropriate type.
2544 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2547 table
= wxDefaultResourceTable
;
2549 wxItemResource
*item
= table
->FindResource(resource
);
2552 if ((item
->GetType().empty()) || wxStrcmp(item
->GetType(), wxT("wxIcon")) != 0)
2554 wxLogWarning(_("%s not an icon resource specification."), (const wxChar
*) resource
);
2557 int thisDepth
= wxDisplayDepth();
2558 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2560 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2562 // Try to find optimum icon for this platform/colour depth
2563 wxNode
*node
= item
->GetChildren().GetFirst();
2566 wxItemResource
*child
= (wxItemResource
*)node
->GetData();
2567 int platform
= (int)child
->GetValue2();
2568 int noColours
= (int)child
->GetValue3();
2570 char *name = child->GetName();
2571 int bitmapType = (int)child->GetValue1();
2572 int xRes = child->GetWidth();
2573 int yRes = child->GetHeight();
2578 case RESOURCE_PLATFORM_ANY
:
2580 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2581 optResource
= child
;
2584 // Maximise the number of colours.
2585 // If noColours is zero (unspecified), then assume this
2586 // is the right one.
2587 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2588 optResource
= child
;
2593 case RESOURCE_PLATFORM_WINDOWS
:
2595 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2596 optResource
= child
;
2599 // Maximise the number of colours
2600 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2601 optResource
= child
;
2607 case RESOURCE_PLATFORM_X
:
2609 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2610 optResource
= child
;
2613 // Maximise the number of colours
2614 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2615 optResource
= child
;
2621 case RESOURCE_PLATFORM_MAC
:
2623 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2624 optResource
= child
;
2627 // Maximise the number of colours
2628 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2629 optResource
= child
;
2637 node
= node
->GetNext();
2639 // If no matching resource, fail.
2643 wxString name
= optResource
->GetName();
2644 int bitmapType
= (int)optResource
->GetValue1();
2647 case wxBITMAP_TYPE_XBM_DATA
:
2650 wxItemResource
*item
= table
->FindResource(name
);
2653 wxLogWarning(_("Failed to find XBM resource %s.\n"
2654 "Forgot to use wxResourceLoadIconData?"), (const wxChar
*) name
);
2657 return wxIcon((const char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2659 wxLogWarning(_("No XBM facility available!"));
2663 case wxBITMAP_TYPE_XPM_DATA
:
2665 // *** XPM ICON NOT YET IMPLEMENTED IN wxWidgets ***
2667 wxItemResource *item = table->FindResource(name);
2671 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2675 return wxIcon((char **)item->GetValue1());
2677 wxLogWarning(_("No XPM icon facility available!"));
2682 #if defined( __WXGTK__ ) || defined( __WXMOTIF__ )
2683 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2686 return wxIcon(name
, (wxBitmapType
) bitmapType
);
2694 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2701 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2703 wxMenu
*menu
= new wxMenu
;
2704 wxNode
*node
= item
->GetChildren().GetFirst();
2707 wxItemResource
*child
= (wxItemResource
*)node
->GetData();
2708 if ((!child
->GetType().empty()) && (child
->GetType() == wxT("wxMenuSeparator")))
2709 menu
->AppendSeparator();
2710 else if (child
->GetChildren().GetCount() > 0)
2712 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2714 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2718 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2720 node
= node
->GetNext();
2725 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2728 table
= wxDefaultResourceTable
;
2730 wxItemResource
*menuResource
= table
->FindResource(resource
);
2731 if (menuResource
&& (!menuResource
->GetType().empty()) && (menuResource
->GetType() == wxT("wxMenu")))
2734 menuBar
= new wxMenuBar
;
2735 wxNode
*node
= menuResource
->GetChildren().GetFirst();
2738 wxItemResource
*child
= (wxItemResource
*)node
->GetData();
2739 wxMenu
*menu
= wxResourceCreateMenu(child
);
2741 menuBar
->Append(menu
, child
->GetTitle());
2742 node
= node
->GetNext();
2746 return (wxMenuBar
*) NULL
;
2749 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2752 table
= wxDefaultResourceTable
;
2754 wxItemResource
*menuResource
= table
->FindResource(resource
);
2755 if (menuResource
&& (!menuResource
->GetType().empty()) && (menuResource
->GetType() == wxT("wxMenu")))
2756 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2757 return wxResourceCreateMenu(menuResource
);
2758 return (wxMenu
*) NULL
;
2761 #endif // wxUSE_MENUS
2763 // Global equivalents (so don't have to refer to default table explicitly)
2764 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2767 table
= wxDefaultResourceTable
;
2769 return table
->ParseResourceData(resource
);
2772 bool wxResourceParseData(const char* resource
, wxResourceTable
*table
)
2774 wxString
str(resource
, wxConvLibc
);
2776 table
= wxDefaultResourceTable
;
2778 return table
->ParseResourceData(str
);
2781 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2784 table
= wxDefaultResourceTable
;
2786 return table
->ParseResourceFile(filename
);
2789 // Register XBM/XPM data
2790 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2793 table
= wxDefaultResourceTable
;
2795 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2798 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2801 table
= wxDefaultResourceTable
;
2803 return table
->RegisterResourceBitmapData(name
, data
);
2806 void wxResourceClear(wxResourceTable
*table
)
2809 table
= wxDefaultResourceTable
;
2811 table
->ClearTable();
2818 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2821 table
= wxDefaultResourceTable
;
2823 table
->identifiers
.Put(name
, (wxObject
*)(long)value
);
2827 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2830 table
= wxDefaultResourceTable
;
2832 return (int)(long)table
->identifiers
.Get(name
);
2836 * Parse #include file for #defines (only)
2839 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2842 table
= wxDefaultResourceTable
;
2844 FILE *fd
= wxFopen(f
, wxT("r"));
2849 while (wxGetResourceToken(fd
))
2851 if (strcmp(wxResourceBuffer
, "#define") == 0)
2853 wxGetResourceToken(fd
);
2854 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2855 wxGetResourceToken(fd
);
2856 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2857 if (wxIsdigit(value
[0]))
2859 int val
= (int)wxAtol(value
);
2860 wxResourceAddIdentifier(name
, val
, table
);
2871 * Reading strings as if they were .wxr files
2874 static int getc_string(char *s
)
2876 int ch
= s
[wxResourceStringPtr
];
2881 wxResourceStringPtr
++;
2886 static int ungetc_string()
2888 wxResourceStringPtr
--;
2892 bool wxEatWhiteSpaceString(char *s
)
2896 while ((ch
= getc_string(s
)) != EOF
)
2907 ch
= getc_string(s
);
2918 while ((ch
= getc_string(s
)) != EOF
)
2920 if (ch
== '/' && prev_ch
== '*')
2942 bool wxGetResourceTokenString(char *s
)
2944 if (!wxResourceBuffer
)
2945 wxReallocateResourceBuffer();
2946 wxResourceBuffer
[0] = 0;
2947 wxEatWhiteSpaceString(s
);
2949 int ch
= getc_string(s
);
2953 wxResourceBufferCount
= 0;
2954 ch
= getc_string(s
);
2960 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2963 // Escaped characters
2964 else if (ch
== '\\')
2966 int newCh
= getc_string(s
);
2969 else if (newCh
== 10)
2977 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2978 wxReallocateResourceBuffer();
2979 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2980 wxResourceBufferCount
++;
2981 ch
= getc_string(s
);
2983 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2987 wxResourceBufferCount
= 0;
2989 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2991 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2992 wxReallocateResourceBuffer();
2993 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2994 wxResourceBufferCount
++;
2996 ch
= getc_string(s
);
2998 wxResourceBuffer
[wxResourceBufferCount
] = 0;
3006 * Files are in form:
3007 static char *name = "....";
3008 with possible comments.
3011 bool wxResourceReadOneResourceString(char *s
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
3014 table
= wxDefaultResourceTable
;
3016 // static or #define
3017 if (!wxGetResourceTokenString(s
))
3023 if (strcmp(wxResourceBuffer
, "#define") == 0)
3025 wxGetResourceTokenString(s
);
3026 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
3027 wxGetResourceTokenString(s
);
3028 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
3029 if (wxIsdigit(value
[0]))
3031 int val
= (int)wxAtol(value
);
3032 wxResourceAddIdentifier(name
, val
, table
);
3036 wxLogWarning(_("#define %s must be an integer."), name
);
3047 else if (strcmp(wxResourceBuffer, "#include") == 0)
3049 wxGetResourceTokenString(s);
3050 char *name = copystring(wxResourceBuffer);
3051 char *actualName = name;
3053 actualName = name + 1;
3054 int len = strlen(name);
3055 if ((len > 0) && (name[len-1] == '"'))
3057 if (!wxResourceParseIncludeFile(actualName, table))
3060 sprintf(buf, _("Could not find resource include file %s."), actualName);
3067 else if (strcmp(wxResourceBuffer
, "static") != 0)
3070 wxStrcpy(buf
, _("Found "));
3071 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
3072 wxStrcat(buf
, _(", expected static, #include or #define\nwhile parsing resource."));
3078 if (!wxGetResourceTokenString(s
))
3080 wxLogWarning(_("Unexpected end of file while parsing resource."));
3085 if (strcmp(wxResourceBuffer
, "char") != 0)
3087 wxLogWarning(_("Expected 'char' while parsing resource."));
3092 if (!wxGetResourceTokenString(s
))
3094 wxLogWarning(_("Unexpected end of file while parsing resource."));
3099 if (wxResourceBuffer
[0] != '*')
3101 wxLogWarning(_("Expected '*' while parsing resource."));
3104 wxChar nameBuf
[100];
3105 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
3109 if (!wxGetResourceTokenString(s
))
3111 wxLogWarning(_("Unexpected end of file while parsing resource."));
3116 if (strcmp(wxResourceBuffer
, "=") != 0)
3118 wxLogWarning(_("Expected '=' while parsing resource."));
3123 if (!wxGetResourceTokenString(s
))
3125 wxLogWarning(_("Unexpected end of file while parsing resource."));
3131 if (!db
.ReadPrologFromString(wxResourceBuffer
))
3133 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
3138 if (!wxGetResourceTokenString(s
))
3145 bool wxResourceParseString(const wxString
& s
, wxResourceTable
*WXUNUSED(table
))
3148 return wxResourceParseString( (char*)s
.mb_str().data() );
3150 return wxResourceParseString( (char*)s
.c_str() );
3154 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
3157 table
= wxDefaultResourceTable
;
3162 // Turn backslashes into spaces
3165 int len
= strlen(s
);
3167 for (i
= 0; i
< len
; i
++)
3168 if (s
[i
] == 92 && s
[i
+1] == 13)
3176 wxResourceStringPtr
= 0;
3179 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
3183 return wxResourceInterpretResources(*table
, db
);
3187 * resource loading facility
3190 bool wxLoadFromResource(wxWindow
* thisWindow
, wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
3193 table
= wxDefaultResourceTable
;
3195 wxItemResource
*resource
= table
->FindResource((const wxChar
*)resourceName
);
3196 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
3197 if (!resource
|| (resource
->GetType().empty()) ||
3198 ! ((resource
->GetType() == wxT("wxDialog")) || (resource
->GetType() == wxT("wxPanel"))))
3201 wxString
title(resource
->GetTitle());
3202 long theWindowStyle
= resource
->GetStyle();
3203 bool isModal
= (resource
->GetValue1() != 0) ;
3204 int x
= resource
->GetX();
3205 int y
= resource
->GetY();
3206 int width
= resource
->GetWidth();
3207 int height
= resource
->GetHeight();
3208 wxString name
= resource
->GetName();
3210 // this is used for loading wxWizard pages from WXR
3211 if ( parent
!= thisWindow
)
3213 if (thisWindow
->IsKindOf(CLASSINFO(wxDialog
)))
3215 wxDialog
*dialogBox
= (wxDialog
*)thisWindow
;
3216 long modalStyle
= isModal
?
3217 #if WXWIN_COMPATIBILITY_2_6
3221 #endif // WXWIN_COMPATIBILITY_2_6
3223 if (!dialogBox
->Create(parent
, wxID_ANY
, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
3226 // Only reset the client size if we know we're not going to do it again below.
3227 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == 0)
3228 dialogBox
->SetClientSize(width
, height
);
3230 else if (thisWindow
->IsKindOf(CLASSINFO(wxPanel
)))
3232 wxPanel
* panel
= (wxPanel
*)thisWindow
;
3233 if (!panel
->Create(parent
, wxID_ANY
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
| wxTAB_TRAVERSAL
, name
))
3238 if (!((wxWindow
*)thisWindow
)->Create(parent
, wxID_ANY
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
3243 if ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
3245 // No need to do this since it's done in wxPanel or wxDialog constructor.
3246 // SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
3250 if (resource
->GetFont().Ok())
3251 thisWindow
->SetFont(resource
->GetFont());
3252 if (resource
->GetBackgroundColour().Ok())
3253 thisWindow
->SetBackgroundColour(resource
->GetBackgroundColour());
3256 // Should have some kind of font at this point
3257 if (!thisWindow
->GetFont().Ok())
3258 thisWindow
->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
3259 if (!thisWindow
->GetBackgroundColour().Ok())
3260 thisWindow
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
3262 // Only when we've created the window and set the font can we set the correct size,
3263 // if based on dialog units.
3264 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
3266 wxSize sz
= thisWindow
->ConvertDialogToPixels(wxSize(width
, height
));
3267 thisWindow
->SetClientSize(sz
.x
, sz
.y
);
3269 wxPoint pt
= thisWindow
->ConvertDialogToPixels(wxPoint(x
, y
));
3270 thisWindow
->Move(pt
.x
, pt
.y
);
3273 // Now create children
3274 wxNode
*node
= resource
->GetChildren().GetFirst();
3277 wxItemResource
*childResource
= (wxItemResource
*)node
->GetData();
3279 (void) wxCreateItem(thisWindow
, childResource
, resource
, table
);
3281 node
= node
->GetNext();
3286 wxControl
*wxCreateItem(wxWindow
* thisWindow
, const wxItemResource
*resource
, const wxItemResource
* parentResource
, const wxResourceTable
*table
)
3289 table
= wxDefaultResourceTable
;
3290 return table
->CreateItem(thisWindow
, resource
, parentResource
);
3294 #pragma warning(default:4706) // assignment within conditional expression
3297 #endif // wxUSE_WX_RESOURCES