1 /////////////////////////////////////////////////////////////////////////////
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
32 #include "wx/gdicmn.h"
36 #include "wx/stattext.h"
37 #include "wx/button.h"
38 #include "wx/bmpbuttn.h"
39 #include "wx/radiobox.h"
40 #include "wx/listbox.h"
41 #include "wx/choice.h"
42 #include "wx/checkbox.h"
43 #include "wx/settings.h"
44 #include "wx/slider.h"
46 #include "wx/statbox.h"
47 #include "wx/statbmp.h"
49 #include "wx/textctrl.h"
50 #include "wx/msgdlg.h"
54 #include "wx/treebase.h"
55 #include "wx/listctrl.h"
58 #include "wx/radiobut.h"
62 #include "wx/scrolbar.h"
66 #include "wx/combobox.h"
69 #include "wx/splitter.h"
70 #include "wx/toolbar.h"
72 #include "wx/validate.h"
74 #include "wx/module.h"
81 #include "wx/string.h"
82 #include "wx/settings.h"
83 #include "wx/stream.h"
85 #include "wx/deprecated/resource.h"
86 #include "wx/deprecated/wxexpr.h"
88 #if !WXWIN_COMPATIBILITY_2_4
89 static inline wxChar
* copystring(const wxChar
* s
)
90 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
93 // Forward (private) declarations
94 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
);
95 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
= false);
96 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
);
97 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
);
98 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
);
99 wxItemResource
*wxResourceInterpretString(wxResourceTable
& table
, wxExpr
*expr
);
100 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& table
, wxExpr
*expr
);
101 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
);
102 // Interpret list expression
103 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
);
105 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
106 bool wxResourceReadOneResource(wxInputStream
*fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
) ;
107 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
109 wxResourceTable
*wxDefaultResourceTable
= (wxResourceTable
*) NULL
;
111 char *wxResourceBuffer
= (char *) NULL
;
112 long wxResourceBufferSize
= 0;
113 long wxResourceBufferCount
= 0;
114 int wxResourceStringPtr
= 0;
116 void wxInitializeResourceSystem()
118 if (!wxDefaultResourceTable
)
119 wxDefaultResourceTable
= new wxResourceTable
;
122 void wxCleanUpResourceSystem()
124 delete wxDefaultResourceTable
;
125 if (wxResourceBuffer
)
126 delete[] wxResourceBuffer
;
129 // Module to ensure the resource system data gets initialized
132 class wxResourceModule
: public wxModule
135 wxResourceModule() : wxModule() {}
136 virtual bool OnInit() { wxInitializeResourceSystem(); return true; }
137 virtual void OnExit() { wxCleanUpResourceSystem(); }
139 DECLARE_DYNAMIC_CLASS(wxResourceModule
)
142 IMPLEMENT_DYNAMIC_CLASS(wxResourceModule
, wxModule
)
145 IMPLEMENT_DYNAMIC_CLASS(wxItemResource
, wxObject
)
146 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable
, wxHashTable
)
148 wxItemResource::wxItemResource()
150 m_itemType
= wxEmptyString
;
151 m_title
= wxEmptyString
;
152 m_name
= wxEmptyString
;
154 m_x
= m_y
= m_width
= m_height
= 0;
155 m_value1
= m_value2
= m_value3
= m_value5
= 0;
156 m_value4
= wxEmptyString
;
161 wxItemResource::~wxItemResource()
163 wxNode
*node
= m_children
.GetFirst();
166 wxItemResource
*item
= (wxItemResource
*)node
->GetData();
169 node
= m_children
.GetFirst();
177 wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
)
181 wxResourceTable::~wxResourceTable()
186 wxItemResource
*wxResourceTable::FindResource(const wxString
& name
) const
188 wxItemResource
*item
= (wxItemResource
*)Get(WXSTRINGCAST name
);
192 void wxResourceTable::AddResource(wxItemResource
*item
)
194 wxString name
= item
->GetName();
196 name
= item
->GetTitle();
198 name
= wxT("no name");
200 // Delete existing resource, if any.
206 bool wxResourceTable::DeleteResource(const wxString
& name
)
208 wxItemResource
*item
= (wxItemResource
*)Delete(WXSTRINGCAST name
);
211 // See if any resource has this as its child; if so, delete from
212 // parent's child list.
214 wxHashTable::Node
*node
= Next();
217 wxItemResource
*parent
= (wxItemResource
*)node
->GetData();
218 if (parent
->GetChildren().Member(item
))
220 parent
->GetChildren().DeleteObject(item
);
233 bool wxResourceTable::ParseResourceFile( wxInputStream
*is
)
236 int len
= is
->GetSize() ;
239 while ( is
->TellI() + 10 < len
) // it's a hack because the streams dont support EOF
241 wxResourceReadOneResource(is
, db
, &eof
, this) ;
243 return wxResourceInterpretResources(*this, db
);
246 bool wxResourceTable::ParseResourceFile(const wxString
& filename
)
250 FILE *fd
= wxFopen(filename
, wxT("r"));
254 while (wxResourceReadOneResource(fd
, db
, &eof
, this) && !eof
)
259 return wxResourceInterpretResources(*this, db
);
262 bool wxResourceTable::ParseResourceData(const wxString
& data
)
265 if (!db
.ReadFromString(data
))
267 wxLogWarning(_("Ill-formed resource file syntax."));
271 return wxResourceInterpretResources(*this, db
);
274 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char bits
[], int width
, int height
)
276 // Register pre-loaded bitmap data
277 wxItemResource
*item
= new wxItemResource
;
278 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
279 item
->SetType(wxT("wxXBMData"));
281 item
->SetValue1((long)bits
);
282 item
->SetValue2((long)width
);
283 item
->SetValue3((long)height
);
288 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char **data
)
290 // Register pre-loaded bitmap data
291 wxItemResource
*item
= new wxItemResource
;
292 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
293 item
->SetType(wxT("wxXPMData"));
295 item
->SetValue1((long)data
);
300 bool wxResourceTable::SaveResource(const wxString
& WXUNUSED(filename
))
305 void wxResourceTable::ClearTable()
308 wxHashTable::Node
*node
= Next();
311 wxHashTable::Node
*next
= Next();
312 wxItemResource
*item
= (wxItemResource
*)node
->GetData();
319 wxControl
*wxResourceTable::CreateItem(wxWindow
*parent
, const wxItemResource
* childResource
, const wxItemResource
* parentResource
) const
321 int id
= childResource
->GetId();
325 bool dlgUnits
= ((parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0);
327 wxControl
*control
= (wxControl
*) NULL
;
328 wxString
itemType(childResource
->GetType());
334 pos
= parent
->ConvertDialogToPixels(wxPoint(childResource
->GetX(), childResource
->GetY()));
335 size
= parent
->ConvertDialogToPixels(wxSize(childResource
->GetWidth(), childResource
->GetHeight()));
339 pos
= wxPoint(childResource
->GetX(), childResource
->GetY());
340 size
= wxSize(childResource
->GetWidth(), childResource
->GetHeight());
343 if (itemType
== wxString(wxT("wxButton")) || itemType
== wxString(wxT("wxBitmapButton")))
345 if (!childResource
->GetValue4().empty())
348 wxBitmap bitmap
= childResource
->GetBitmap();
351 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
352 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
355 #if defined(__WXPM__)
357 // OS/2 uses integer id's to access resources, not file name strings
359 bitmap
.LoadFile(wxCROSS_BITMAP
, wxBITMAP_TYPE_BMP_RESOURCE
);
361 bitmap
.LoadFile(wxT("cross_bmp"), wxBITMAP_TYPE_BMP_RESOURCE
);
363 control
= new wxBitmapButton(parent
, id
, bitmap
, pos
, size
,
364 childResource
->GetStyle() | wxBU_AUTODRAW
, wxDefaultValidator
, childResource
->GetName());
367 // Normal, text button
368 control
= new wxButton(parent
, id
, childResource
->GetTitle(), pos
, size
,
369 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
371 else if (itemType
== wxString(wxT("wxMessage")) || itemType
== wxString(wxT("wxStaticText")) ||
372 itemType
== wxString(wxT("wxStaticBitmap")))
374 if (!childResource
->GetValue4().empty() || itemType
== wxString(wxT("wxStaticBitmap")) )
377 wxBitmap bitmap
= childResource
->GetBitmap();
380 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
381 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
383 #if wxUSE_BITMAP_MESSAGE
385 // Use a default bitmap
387 bitmap
.LoadFile(wxT("cross_bmp"), wxBITMAP_TYPE_BMP_RESOURCE
);
391 control
= new wxStaticBitmap(parent
, id
, bitmap
, pos
, size
,
392 childResource
->GetStyle(), childResource
->GetName());
397 control
= new wxStaticText(parent
, id
, childResource
->GetTitle(), pos
, size
,
398 childResource
->GetStyle(), childResource
->GetName());
401 else if (itemType
== wxString(wxT("wxText")) || itemType
== wxString(wxT("wxTextCtrl")) || itemType
== wxString(wxT("wxMultiText")))
403 control
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(), pos
, size
,
404 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
406 else if (itemType
== wxString(wxT("wxCheckBox")))
408 control
= new wxCheckBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
409 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
411 ((wxCheckBox
*)control
)->SetValue((childResource
->GetValue1() != 0));
414 else if (itemType
== wxString(wxT("wxGauge")))
416 control
= new wxGauge(parent
, id
, (int)childResource
->GetValue2(), pos
, size
,
417 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
419 ((wxGauge
*)control
)->SetValue((int)childResource
->GetValue1());
423 else if (itemType
== wxString(wxT("wxRadioButton")))
425 control
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(),
427 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
431 else if (itemType
== wxString(wxT("wxScrollBar")))
433 control
= new wxScrollBar(parent
, id
, pos
, size
,
434 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
436 ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1());
437 ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2());
438 ((wxScrollBar *)control)->SetObjectLength((int)childResource->GetValue3());
439 ((wxScrollBar *)control)->SetViewLength((int)(long)childResource->GetValue5());
441 ((wxScrollBar
*)control
)->SetScrollbar((int)childResource
->GetValue1(),(int)childResource
->GetValue2(),
442 (int)childResource
->GetValue3(),(int)(long)childResource
->GetValue5(),false);
446 else if (itemType
== wxString(wxT("wxSlider")))
448 control
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(),
449 (int)childResource
->GetValue2(), (int)childResource
->GetValue3(), pos
, size
,
450 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
452 else if (itemType
== wxString(wxT("wxGroupBox")) || itemType
== wxString(wxT("wxStaticBox")))
454 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
455 childResource
->GetStyle(), childResource
->GetName());
457 else if (itemType
== wxString(wxT("wxListBox")))
459 wxStringList
& stringList
= childResource
->GetStringValues();
460 wxString
*strings
= (wxString
*) NULL
;
462 if (stringList
.GetCount() > 0)
464 noStrings
= stringList
.GetCount();
465 strings
= new wxString
[noStrings
];
466 wxStringListNode
*node
= stringList
.GetFirst();
470 strings
[i
] = (wxChar
*)node
->GetData();
472 node
= node
->GetNext();
475 control
= new wxListBox(parent
, id
, pos
, size
,
476 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
481 else if (itemType
== wxString(wxT("wxChoice")))
483 wxStringList
& stringList
= childResource
->GetStringValues();
484 wxString
*strings
= (wxString
*) NULL
;
486 if (stringList
.GetCount() > 0)
488 noStrings
= stringList
.GetCount();
489 strings
= new wxString
[noStrings
];
490 wxStringListNode
*node
= stringList
.GetFirst();
494 strings
[i
] = (wxChar
*)node
->GetData();
496 node
= node
->GetNext();
499 control
= new wxChoice(parent
, id
, pos
, size
,
500 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
506 else if (itemType
== wxString(wxT("wxComboBox")))
508 wxStringList
& stringList
= childResource
->GetStringValues();
509 wxString
*strings
= (wxString
*) NULL
;
511 if (stringList
.GetCount() > 0)
513 noStrings
= stringList
.GetCount();
514 strings
= new wxString
[noStrings
];
515 wxStringListNode
*node
= stringList
.GetFirst();
519 strings
[i
] = (wxChar
*)node
->GetData();
521 node
= node
->GetNext();
524 control
= new wxComboBox(parent
, id
, childResource
->GetValue4(), pos
, size
,
525 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
531 else if (itemType
== wxString(wxT("wxRadioBox")))
533 wxStringList
& stringList
= childResource
->GetStringValues();
534 wxString
*strings
= (wxString
*) NULL
;
536 if (stringList
.GetCount() > 0)
538 noStrings
= stringList
.GetCount();
539 strings
= new wxString
[noStrings
];
540 wxStringListNode
*node
= stringList
.GetFirst();
544 strings
[i
] = (wxChar
*)node
->GetData();
546 node
= node
->GetNext();
549 control
= new wxRadioBox(parent
, (wxWindowID
) id
, wxString(childResource
->GetTitle()), pos
, size
,
550 noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
,
551 childResource
->GetName());
557 if ((parentResource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
559 // Don't set font; will be inherited from parent.
563 if (control
&& childResource
->GetFont().Ok())
565 control
->SetFont(childResource
->GetFont());
568 // Force the layout algorithm since the size changes the layout
569 if (control
->IsKindOf(CLASSINFO(wxRadioBox
)))
571 control
->SetSize(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, wxSIZE_AUTO_WIDTH
|wxSIZE_AUTO_HEIGHT
);
580 * Interpret database as a series of resources
583 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
)
585 wxNode
*node
= db
.GetFirst();
588 wxExpr
*clause
= (wxExpr
*)node
->GetData();
589 wxString
functor(clause
->Functor());
591 wxItemResource
*item
= (wxItemResource
*) NULL
;
592 if (functor
== wxT("dialog"))
593 item
= wxResourceInterpretDialog(table
, clause
);
594 else if (functor
== wxT("panel"))
595 item
= wxResourceInterpretDialog(table
, clause
, true);
596 else if (functor
== wxT("menubar"))
597 item
= wxResourceInterpretMenuBar(table
, clause
);
598 else if (functor
== wxT("menu"))
599 item
= wxResourceInterpretMenu(table
, clause
);
600 else if (functor
== wxT("string"))
601 item
= wxResourceInterpretString(table
, clause
);
602 else if (functor
== wxT("bitmap"))
603 item
= wxResourceInterpretBitmap(table
, clause
);
604 else if (functor
== wxT("icon"))
605 item
= wxResourceInterpretIcon(table
, clause
);
609 // Remove any existing resource of same name
610 if (!item
->GetName().empty())
611 table
.DeleteResource(item
->GetName());
612 table
.AddResource(item
);
614 node
= node
->GetNext();
619 static const wxChar
*g_ValidControlClasses
[] =
622 wxT("wxBitmapButton"),
625 wxT("wxStaticBitmap"),
631 wxT("wxRadioButton"),
633 wxT("wxBitmapCheckBox"),
643 static bool wxIsValidControlClass(const wxString
& c
)
645 for ( size_t i
= 0; i
< WXSIZEOF(g_ValidControlClasses
); i
++ )
647 if ( c
== g_ValidControlClasses
[i
] )
653 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
)
655 wxItemResource
*dialogItem
= new wxItemResource
;
657 dialogItem
->SetType(wxT("wxPanel"));
659 dialogItem
->SetType(wxT("wxDialog"));
660 wxString style
= wxEmptyString
;
661 wxString title
= wxEmptyString
;
662 wxString name
= wxEmptyString
;
663 wxString backColourHex
= wxEmptyString
;
664 wxString labelColourHex
= wxEmptyString
;
665 wxString buttonColourHex
= wxEmptyString
;
667 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
671 int x
= 0; int y
= 0; int width
= wxDefaultCoord
; int height
= wxDefaultCoord
;
673 wxExpr
*labelFontExpr
= (wxExpr
*) NULL
;
674 wxExpr
*buttonFontExpr
= (wxExpr
*) NULL
;
675 wxExpr
*fontExpr
= (wxExpr
*) NULL
;
676 expr
->GetAttributeValue(wxT("style"), style
);
677 expr
->GetAttributeValue(wxT("name"), name
);
678 expr
->GetAttributeValue(wxT("title"), title
);
679 expr
->GetAttributeValue(wxT("x"), x
);
680 expr
->GetAttributeValue(wxT("y"), y
);
681 expr
->GetAttributeValue(wxT("width"), width
);
682 expr
->GetAttributeValue(wxT("height"), height
);
683 expr
->GetAttributeValue(wxT("modal"), isModal
);
684 expr
->GetAttributeValue(wxT("label_font"), &labelFontExpr
);
685 expr
->GetAttributeValue(wxT("button_font"), &buttonFontExpr
);
686 expr
->GetAttributeValue(wxT("font"), &fontExpr
);
687 expr
->GetAttributeValue(wxT("background_colour"), backColourHex
);
688 expr
->GetAttributeValue(wxT("label_colour"), labelColourHex
);
689 expr
->GetAttributeValue(wxT("button_colour"), buttonColourHex
);
691 int useDialogUnits
= 0;
692 expr
->GetAttributeValue(wxT("use_dialog_units"), useDialogUnits
);
693 if (useDialogUnits
!= 0)
694 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS
);
697 expr
->GetAttributeValue(wxT("use_system_defaults"), useDefaults
);
698 if (useDefaults
!= 0)
699 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS
);
702 expr
->GetAttributeValue(wxT("id"), id
);
703 dialogItem
->SetId(id
);
707 windowStyle
= wxParseWindowStyle(style
);
709 dialogItem
->SetStyle(windowStyle
);
710 dialogItem
->SetValue1(isModal
);
712 #pragma message disable CODCAUUNR
714 if (windowStyle
& wxDIALOG_MODAL
) // Uses style in wxWin 2
715 dialogItem
->SetValue1(true);
717 #pragma message enable CODCAUUNR
720 dialogItem
->SetName(name
);
721 dialogItem
->SetTitle(title
);
722 dialogItem
->SetSize(x
, y
, width
, height
);
724 // Check for wxWin 1.68-style specifications
725 if (style
.Find(wxT("VERTICAL_LABEL")) != wxNOT_FOUND
)
726 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL
);
727 else if (style
.Find(wxT("HORIZONTAL_LABEL")) != wxNOT_FOUND
)
728 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL
);
730 if (!backColourHex
.empty())
735 r
= wxHexToDec(backColourHex
.Mid(0, 2));
736 g
= wxHexToDec(backColourHex
.Mid(2, 2));
737 b
= wxHexToDec(backColourHex
.Mid(4, 2));
738 dialogItem
->SetBackgroundColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
740 if (!labelColourHex
.empty())
745 r
= wxHexToDec(labelColourHex
.Mid(0, 2));
746 g
= wxHexToDec(labelColourHex
.Mid(2, 2));
747 b
= wxHexToDec(labelColourHex
.Mid(4, 2));
748 dialogItem
->SetLabelColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
750 if (!buttonColourHex
.empty())
755 r
= wxHexToDec(buttonColourHex
.Mid(0, 2));
756 g
= wxHexToDec(buttonColourHex
.Mid(2, 2));
757 b
= wxHexToDec(buttonColourHex
.Mid(4, 2));
758 dialogItem
->SetButtonColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
762 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
763 else if (buttonFontExpr
)
764 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
765 else if (labelFontExpr
)
766 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
768 // Now parse all controls
769 wxExpr
*controlExpr
= expr
->GetFirst();
772 if (controlExpr
->Number() == 3)
774 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
775 if (!controlKeyword
.empty() && controlKeyword
== wxT("control"))
777 // The value part: always a list.
778 wxExpr
*listExpr
= controlExpr
->Nth(2);
779 if (listExpr
->Type() == PrologList
)
781 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
784 dialogItem
->GetChildren().Append(controlItem
);
789 controlExpr
= controlExpr
->GetNext();
794 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
)
796 wxItemResource
*controlItem
= new wxItemResource
;
798 // First, find the standard features of a control definition:
799 // [optional integer/string id], control name, title, style, name, x, y, width, height
801 wxString controlType
;
806 long windowStyle
= 0;
807 int x
= 0; int y
= 0; int width
= wxDefaultCoord
; int height
= wxDefaultCoord
;
810 wxExpr
*expr1
= expr
->Nth(0);
812 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
814 if ( wxIsValidControlClass(expr1
->StringValue()) )
817 controlType
= expr1
->StringValue();
821 wxString
str(expr1
->StringValue());
822 id
= wxResourceGetIdentifier(str
, &table
);
825 wxLogWarning(_("Could not resolve control class or id '%s'. Use (non-zero) integer instead\n or provide #define (see manual for caveats)"),
826 (const wxChar
*) expr1
->StringValue());
828 return (wxItemResource
*) NULL
;
832 // Success - we have an id, so the 2nd element must be the control class.
833 controlType
= expr
->Nth(1)->StringValue();
838 else if (expr1
->Type() == PrologInteger
)
840 id
= (int)expr1
->IntegerValue();
841 // Success - we have an id, so the 2nd element must be the control class.
842 controlType
= expr
->Nth(1)->StringValue();
846 expr1
= expr
->Nth(count
);
849 title
= expr1
->StringValue();
851 expr1
= expr
->Nth(count
);
855 style
= expr1
->StringValue();
856 windowStyle
= wxParseWindowStyle(style
);
859 expr1
= expr
->Nth(count
);
862 name
= expr1
->StringValue();
864 expr1
= expr
->Nth(count
);
867 x
= (int)expr1
->IntegerValue();
869 expr1
= expr
->Nth(count
);
872 y
= (int)expr1
->IntegerValue();
874 expr1
= expr
->Nth(count
);
877 width
= (int)expr1
->IntegerValue();
879 expr1
= expr
->Nth(count
);
882 height
= (int)expr1
->IntegerValue();
884 controlItem
->SetStyle(windowStyle
);
885 controlItem
->SetName(name
);
886 controlItem
->SetTitle(title
);
887 controlItem
->SetSize(x
, y
, width
, height
);
888 controlItem
->SetType(controlType
);
889 controlItem
->SetId(id
);
891 // Check for wxWin 1.68-style specifications
892 if (style
.Find(wxT("VERTICAL_LABEL")) != wxNOT_FOUND
)
893 controlItem
->SetResourceStyle(controlItem
->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL
);
894 else if (style
.Find(wxT("HORIZONTAL_LABEL")) != wxNOT_FOUND
)
895 controlItem
->SetResourceStyle(controlItem
->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL
);
897 if (controlType
== wxT("wxButton"))
899 // Check for bitmap resource name (in case loading old-style resource file)
900 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
902 wxString
str(expr
->Nth(count
)->StringValue());
907 controlItem
->SetValue4(str
);
908 controlItem
->SetType(wxT("wxBitmapButton"));
911 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
912 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
914 else if (controlType
== wxT("wxBitmapButton"))
916 // Check for bitmap resource name
917 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
919 wxString
str(expr
->Nth(count
)->StringValue());
920 controlItem
->SetValue4(str
);
922 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
923 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
926 else if (controlType
== wxT("wxCheckBox"))
928 // Check for default value
929 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
931 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
933 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
934 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
938 else if (controlType
== wxT("wxRadioButton"))
940 // Check for default value
941 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
943 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
945 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
946 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
950 else if (controlType
== wxT("wxText") || controlType
== wxT("wxTextCtrl") || controlType
== wxT("wxMultiText"))
952 // Check for default value
953 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
955 wxString
str(expr
->Nth(count
)->StringValue());
956 controlItem
->SetValue4(str
);
959 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
961 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
962 // Skip past the obsolete label font spec if there are two consecutive specs
963 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
965 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
969 else if (controlType
== wxT("wxMessage") || controlType
== wxT("wxStaticText"))
971 // Check for bitmap resource name (in case it's an old-style .wxr file)
972 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
974 wxString
str(expr
->Nth(count
)->StringValue());
975 controlItem
->SetValue4(str
);
977 controlItem
->SetType(wxT("wxStaticText"));
979 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
980 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
982 else if (controlType
== wxT("wxStaticBitmap"))
984 // Check for bitmap resource name
985 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
987 wxString
str(expr
->Nth(count
)->StringValue());
988 controlItem
->SetValue4(str
);
991 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
992 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
994 else if (controlType
== wxT("wxGroupBox") || controlType
== wxT("wxStaticBox"))
996 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
997 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
999 else if (controlType
== wxT("wxGauge"))
1001 // Check for default value
1002 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1004 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1008 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1010 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1013 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1015 // Skip past the obsolete label font spec if there are two consecutive specs
1016 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1018 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1023 else if (controlType
== wxT("wxSlider"))
1025 // Check for default value
1026 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1028 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1032 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1034 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1038 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1040 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1043 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1045 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1049 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1050 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1056 else if (controlType
== wxT("wxScrollBar"))
1059 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1061 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1065 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1067 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1071 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1073 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1077 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1078 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
1083 else if (controlType
== wxT("wxListBox"))
1085 wxExpr
*valueList
= (wxExpr
*) NULL
;
1087 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1089 wxStringList stringList
;
1090 wxExpr
*stringExpr
= valueList
->GetFirst();
1093 stringList
.Add(stringExpr
->StringValue());
1094 stringExpr
= stringExpr
->GetNext();
1096 controlItem
->SetStringValues(stringList
);
1098 // This is now obsolete: it's in the window style.
1099 // Check for wxSINGLE/wxMULTIPLE
1100 wxExpr
*mult
= (wxExpr
*) NULL
;
1102 controlItem->SetValue1(wxLB_SINGLE);
1104 if (((mult
= expr
->Nth(count
)) != 0) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1107 wxString m(mult->StringValue());
1108 if (m == "wxLB_MULTIPLE")
1109 controlItem->SetValue1(wxLB_MULTIPLE);
1110 else if (m == "wxLB_EXTENDED")
1111 controlItem->SetValue1(wxLB_EXTENDED);
1116 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1118 // Skip past the obsolete label font spec if there are two consecutive specs
1119 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1121 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1125 else if (controlType
== wxT("wxChoice"))
1127 wxExpr
*valueList
= (wxExpr
*) NULL
;
1128 // Check for default value list
1129 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1131 wxStringList stringList
;
1132 wxExpr
*stringExpr
= valueList
->GetFirst();
1135 stringList
.Add(stringExpr
->StringValue());
1136 stringExpr
= stringExpr
->GetNext();
1138 controlItem
->SetStringValues(stringList
);
1142 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1144 // Skip past the obsolete label font spec if there are two consecutive specs
1145 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1147 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1152 else if (controlType
== wxT("wxComboBox"))
1154 wxExpr
*textValue
= expr
->Nth(count
);
1155 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1157 wxString
str(textValue
->StringValue());
1158 controlItem
->SetValue4(str
);
1162 wxExpr
*valueList
= (wxExpr
*) NULL
;
1163 // Check for default value list
1164 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1166 wxStringList stringList
;
1167 wxExpr
*stringExpr
= valueList
->GetFirst();
1170 stringList
.Add(stringExpr
->StringValue());
1171 stringExpr
= stringExpr
->GetNext();
1173 controlItem
->SetStringValues(stringList
);
1177 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1179 // Skip past the obsolete label font spec if there are two consecutive specs
1180 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1182 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1189 else if (controlType
== wxT("wxRadioBox"))
1191 wxExpr
*valueList
= (wxExpr
*) NULL
;
1192 // Check for default value list
1193 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1195 wxStringList stringList
;
1196 wxExpr
*stringExpr
= valueList
->GetFirst();
1199 stringList
.Add(stringExpr
->StringValue());
1200 stringExpr
= stringExpr
->GetNext();
1202 controlItem
->SetStringValues(stringList
);
1205 // majorDim (number of rows or cols)
1206 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1208 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1212 controlItem
->SetValue1(0);
1214 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1216 // Skip past the obsolete label font spec if there are two consecutive specs
1217 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1219 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1227 return (wxItemResource
*) NULL
;
1232 // Forward declaration
1233 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, wxExpr
*expr
);
1236 * Interpet a menu item
1239 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, wxExpr
*expr
)
1241 wxItemResource
*item
= new wxItemResource
;
1243 wxExpr
*labelExpr
= expr
->Nth(0);
1244 wxExpr
*idExpr
= expr
->Nth(1);
1245 wxExpr
*helpExpr
= expr
->Nth(2);
1246 wxExpr
*checkableExpr
= expr
->Nth(3);
1248 // Further keywords/attributes to follow sometime...
1249 if (expr
->Number() == 0)
1251 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1252 item
->SetType(wxT("wxMenuSeparator"));
1257 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1258 item
->SetType(wxT("wxMenu")); // Well, menu item, but doesn't matter.
1261 wxString
str(labelExpr
->StringValue());
1262 item
->SetTitle(str
);
1267 // If a string or word, must look up in identifier table.
1268 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1270 wxString
str(idExpr
->StringValue());
1271 id
= wxResourceGetIdentifier(str
, &table
);
1274 wxLogWarning(_("Could not resolve menu id '%s'. Use (non-zero) integer instead\nor provide #define (see manual for caveats)"),
1275 (const wxChar
*) idExpr
->StringValue());
1278 else if (idExpr
->Type() == PrologInteger
)
1279 id
= (int)idExpr
->IntegerValue();
1280 item
->SetValue1(id
);
1284 wxString
str(helpExpr
->StringValue());
1285 item
->SetValue4(str
);
1288 item
->SetValue2(checkableExpr
->IntegerValue());
1290 // Find the first expression that's a list, for submenu
1291 wxExpr
*subMenuExpr
= expr
->GetFirst();
1292 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1293 subMenuExpr
= subMenuExpr
->GetNext();
1297 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1298 item
->GetChildren().Append(child
);
1299 subMenuExpr
= subMenuExpr
->GetNext();
1306 * Interpret a nested list as a menu
1309 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1311 wxItemResource *menu = new wxItemResource;
1312 // menu->SetType(wxTYPE_MENU);
1313 menu->SetType("wxMenu");
1314 wxExpr *element = expr->GetFirst();
1317 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1319 menu->GetChildren().Append(item);
1320 element = element->GetNext();
1326 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
)
1328 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1329 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1331 return (wxItemResource
*) NULL
;
1333 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1336 return (wxItemResource
*) NULL
;
1339 if (expr
->GetAttributeValue(wxT("name"), name
))
1341 menuResource
->SetName(name
);
1344 return menuResource
;
1347 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
)
1349 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1350 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1352 return (wxItemResource
*) NULL
;
1354 wxItemResource
*resource
= new wxItemResource
;
1355 resource
->SetType(wxT("wxMenu"));
1356 // resource->SetType(wxTYPE_MENU);
1358 wxExpr
*element
= listExpr
->GetFirst();
1361 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1362 resource
->GetChildren().Append(menuResource
);
1363 element
= element
->GetNext();
1367 if (expr
->GetAttributeValue(wxT("name"), name
))
1369 resource
->SetName(name
);
1375 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), wxExpr
*WXUNUSED(expr
))
1377 return (wxItemResource
*) NULL
;
1380 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), wxExpr
*expr
)
1382 wxItemResource
*bitmapItem
= new wxItemResource
;
1383 // bitmapItem->SetType(wxTYPE_BITMAP);
1384 bitmapItem
->SetType(wxT("wxBitmap"));
1386 if (expr
->GetAttributeValue(wxT("name"), name
))
1388 bitmapItem
->SetName(name
);
1390 // Now parse all bitmap specifications
1391 wxExpr
*bitmapExpr
= expr
->GetFirst();
1394 if (bitmapExpr
->Number() == 3)
1396 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1397 if (bitmapKeyword
== wxT("bitmap") || bitmapKeyword
== wxT("icon"))
1399 // The value part: always a list.
1400 wxExpr
*listExpr
= bitmapExpr
->Nth(2);
1401 if (listExpr
->Type() == PrologList
)
1403 wxItemResource
*bitmapSpec
= new wxItemResource
;
1404 // bitmapSpec->SetType(wxTYPE_BITMAP);
1405 bitmapSpec
->SetType(wxT("wxBitmap"));
1407 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1408 // where everything after 'filename' is optional.
1409 wxExpr
*nameExpr
= listExpr
->Nth(0);
1410 wxExpr
*typeExpr
= listExpr
->Nth(1);
1411 wxExpr
*platformExpr
= listExpr
->Nth(2);
1412 wxExpr
*coloursExpr
= listExpr
->Nth(3);
1413 wxExpr
*xresExpr
= listExpr
->Nth(4);
1414 wxExpr
*yresExpr
= listExpr
->Nth(5);
1415 if (nameExpr
&& !nameExpr
->StringValue().empty())
1417 bitmapSpec
->SetName(nameExpr
->StringValue());
1419 if (typeExpr
&& !typeExpr
->StringValue().empty())
1421 bitmapSpec
->SetValue1(wxParseWindowStyle(typeExpr
->StringValue()));
1424 bitmapSpec
->SetValue1(0);
1426 if (platformExpr
&& !platformExpr
->StringValue().empty())
1428 wxString
plat(platformExpr
->StringValue());
1429 if (plat
== wxT("windows") || plat
== wxT("WINDOWS"))
1430 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1431 else if (plat
== wxT("x") || plat
== wxT("X"))
1432 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1433 else if (plat
== wxT("mac") || plat
== wxT("MAC"))
1434 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1436 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1439 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1442 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1446 xres
= (int)xresExpr
->IntegerValue();
1448 yres
= (int)yresExpr
->IntegerValue();
1449 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1451 bitmapItem
->GetChildren().Append(bitmapSpec
);
1455 bitmapExpr
= bitmapExpr
->GetNext();
1461 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
)
1463 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1466 // item->SetType(wxTYPE_ICON);
1467 item
->SetType(wxT("wxIcon"));
1471 return (wxItemResource
*) NULL
;
1474 // Interpret list expression as a font
1475 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
)
1477 if (expr
->Type() != PrologList
)
1481 int family
= wxSWISS
;
1482 int style
= wxNORMAL
;
1483 int weight
= wxNORMAL
;
1487 wxExpr
*pointExpr
= expr
->Nth(0);
1488 wxExpr
*familyExpr
= expr
->Nth(1);
1489 wxExpr
*styleExpr
= expr
->Nth(2);
1490 wxExpr
*weightExpr
= expr
->Nth(3);
1491 wxExpr
*underlineExpr
= expr
->Nth(4);
1492 wxExpr
*faceNameExpr
= expr
->Nth(5);
1494 point
= (int)pointExpr
->IntegerValue();
1499 str
= familyExpr
->StringValue();
1500 family
= (int)wxParseWindowStyle(str
);
1504 str
= styleExpr
->StringValue();
1505 style
= (int)wxParseWindowStyle(str
);
1509 str
= weightExpr
->StringValue();
1510 weight
= (int)wxParseWindowStyle(str
);
1513 underline
= (int)underlineExpr
->IntegerValue();
1515 faceName
= faceNameExpr
->StringValue();
1517 return *wxTheFontList
->FindOrCreateFont(point
, family
, style
, weight
,
1518 (underline
!= 0), faceName
);
1522 * (Re)allocate buffer for reading in from resource file
1525 bool wxReallocateResourceBuffer()
1527 if (!wxResourceBuffer
)
1529 wxResourceBufferSize
= 1000;
1530 wxResourceBuffer
= new char[wxResourceBufferSize
];
1533 if (wxResourceBuffer
)
1535 long newSize
= wxResourceBufferSize
+ 1000;
1536 char *tmp
= new char[(int)newSize
];
1537 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1538 delete[] wxResourceBuffer
;
1539 wxResourceBuffer
= tmp
;
1540 wxResourceBufferSize
= newSize
;
1545 static bool wxEatWhiteSpace(FILE *fd
)
1549 while ((ch
= getc(fd
)) != EOF
)
1564 ungetc(prev_ch
, fd
);
1572 while ((ch
= getc(fd
)) != EOF
)
1574 if (ch
== '/' && prev_ch
== '*')
1582 static char buffer
[255];
1583 fgets(buffer
, 255, fd
);
1587 ungetc(prev_ch
, fd
);
1601 static bool wxEatWhiteSpace(wxInputStream
*is
)
1603 char ch
= is
->GetC() ;
1604 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
1611 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
1613 // Check for comment
1619 bool finished
= false;
1623 if (is
->LastRead() == 0)
1627 int newCh
= is
->GetC();
1642 return wxEatWhiteSpace(is
);
1645 bool wxGetResourceToken(FILE *fd
)
1647 if (!wxResourceBuffer
)
1648 wxReallocateResourceBuffer();
1649 wxResourceBuffer
[0] = 0;
1650 wxEatWhiteSpace(fd
);
1656 wxResourceBufferCount
= 0;
1663 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1666 // Escaped characters
1667 else if (ch
== '\\')
1669 int newCh
= getc(fd
);
1672 else if (newCh
== 10)
1680 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1681 wxReallocateResourceBuffer();
1682 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1683 wxResourceBufferCount
++;
1686 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1690 wxResourceBufferCount
= 0;
1692 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1694 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1695 wxReallocateResourceBuffer();
1696 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1697 wxResourceBufferCount
++;
1701 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1708 bool wxGetResourceToken(wxInputStream
*is
)
1710 if (!wxResourceBuffer
)
1711 wxReallocateResourceBuffer();
1712 wxResourceBuffer
[0] = 0;
1713 wxEatWhiteSpace(is
);
1715 int ch
= is
->GetC() ;
1719 wxResourceBufferCount
= 0;
1726 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1729 // Escaped characters
1730 else if (ch
== '\\')
1732 char newCh
= is
->GetC();
1735 else if (newCh
== 10)
1737 else if (newCh
== 13) // mac
1745 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1746 wxReallocateResourceBuffer();
1747 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1748 wxResourceBufferCount
++;
1751 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1755 wxResourceBufferCount
= 0;
1757 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1759 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1760 wxReallocateResourceBuffer();
1761 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1762 wxResourceBufferCount
++;
1766 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1774 * Files are in form:
1775 static char *name = "....";
1776 with possible comments.
1779 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1782 table
= wxDefaultResourceTable
;
1784 // static or #define
1785 if (!wxGetResourceToken(fd
))
1791 if (strcmp(wxResourceBuffer
, "#define") == 0)
1793 wxGetResourceToken(fd
);
1794 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1795 wxGetResourceToken(fd
);
1796 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1797 if (wxIsdigit(value
[0]))
1799 int val
= (int)wxAtol(value
);
1800 wxResourceAddIdentifier(name
, val
, table
);
1804 wxLogWarning(_("#define %s must be an integer."), name
);
1814 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1816 wxGetResourceToken(fd
);
1817 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1818 wxChar
*actualName
= name
;
1819 if (name
[0] == wxT('"'))
1820 actualName
= name
+ 1;
1821 int len
= wxStrlen(name
);
1822 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1824 if (!wxResourceParseIncludeFile(actualName
, table
))
1826 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1831 else if (strcmp(wxResourceBuffer
, "static") != 0)
1834 wxStrcpy(buf
, _("Found "));
1835 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
1836 wxStrcat(buf
, _(", expected static, #include or #define\nwhile parsing resource."));
1842 if (!wxGetResourceToken(fd
))
1844 wxLogWarning(_("Unexpected end of file while parsing resource."));
1849 if (strcmp(wxResourceBuffer
, "char") != 0)
1851 wxLogWarning(_("Expected 'char' while parsing resource."));
1856 if (!wxGetResourceToken(fd
))
1858 wxLogWarning(_("Unexpected end of file while parsing resource."));
1863 if (wxResourceBuffer
[0] != '*')
1865 wxLogWarning(_("Expected '*' while parsing resource."));
1868 wxChar nameBuf
[100];
1869 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
1873 if (!wxGetResourceToken(fd
))
1875 wxLogWarning(_("Unexpected end of file while parsing resource."));
1880 if (strcmp(wxResourceBuffer
, "=") != 0)
1882 wxLogWarning(_("Expected '=' while parsing resource."));
1887 if (!wxGetResourceToken(fd
))
1889 wxLogWarning(_("Unexpected end of file while parsing resource."));
1895 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1897 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1902 if (!wxGetResourceToken(fd
))
1909 bool wxResourceReadOneResource(wxInputStream
*fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1912 table
= wxDefaultResourceTable
;
1914 // static or #define
1915 if (!wxGetResourceToken(fd
))
1921 if (strcmp(wxResourceBuffer
, "#define") == 0)
1923 wxGetResourceToken(fd
);
1924 wxChar
*name
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1925 wxGetResourceToken(fd
);
1926 wxChar
*value
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1927 if (wxIsalpha(value
[0]))
1929 int val
= (int)wxAtol(value
);
1930 wxResourceAddIdentifier(name
, val
, table
);
1934 wxLogWarning(_("#define %s must be an integer."), name
);
1944 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1946 wxGetResourceToken(fd
);
1947 wxChar
*name
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1948 wxChar
*actualName
= name
;
1949 if (name
[0] == wxT('"'))
1950 actualName
= name
+ 1;
1951 int len
= wxStrlen(name
);
1952 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1954 if (!wxResourceParseIncludeFile(actualName
, table
))
1956 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1961 else if (strcmp(wxResourceBuffer
, "static") != 0)
1964 wxStrcpy(buf
, _("Found "));
1965 wxStrncat(buf
, wxConvLibc
.cMB2WX(wxResourceBuffer
), 30);
1966 wxStrcat(buf
, _(", expected static, #include or #define\nwhile parsing resource."));
1972 if (!wxGetResourceToken(fd
))
1974 wxLogWarning(_("Unexpected end of file while parsing resource."));
1979 if (strcmp(wxResourceBuffer
, "char") != 0)
1981 wxLogWarning(_("Expected 'char' while parsing resource."));
1986 if (!wxGetResourceToken(fd
))
1988 wxLogWarning(_("Unexpected end of file while parsing resource."));
1993 if (wxResourceBuffer
[0] != '*')
1995 wxLogWarning(_("Expected '*' while parsing resource."));
1999 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
2002 if (!wxGetResourceToken(fd
))
2004 wxLogWarning(_("Unexpected end of file while parsing resource."));
2009 if (strcmp(wxResourceBuffer
, "=") != 0)
2011 wxLogWarning(_("Expected '=' while parsing resource."));
2016 if (!wxGetResourceToken(fd
))
2018 wxLogWarning(_("Unexpected end of file while parsing resource."));
2024 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2026 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2031 if (!wxGetResourceToken(fd
))
2039 * Parses string window style into integer window style
2043 * Style flag parsing, e.g.
2044 * "wxSYSTEM_MENU | wxBORDER" -> integer
2047 wxChar
* wxResourceParseWord(wxChar
*s
, int *i
)
2050 return (wxChar
*) NULL
;
2052 static wxChar buf
[150];
2053 int len
= wxStrlen(s
);
2056 while ((ii
< len
) && (wxIsalpha(s
[ii
]) || (s
[ii
] == wxT('_'))))
2064 // Eat whitespace and conjunction characters
2065 while ((ii
< len
) &&
2066 ((s
[ii
] == wxT(' ')) || (s
[ii
] == wxT('|')) || (s
[ii
] == wxT(','))))
2072 return (wxChar
*) NULL
;
2077 struct wxResourceBitListStruct
2083 static wxResourceBitListStruct wxResourceBitListTable
[] =
2086 { wxT("wxSINGLE"), wxLB_SINGLE
},
2087 { wxT("wxMULTIPLE"), wxLB_MULTIPLE
},
2088 { wxT("wxEXTENDED"), wxLB_EXTENDED
},
2089 { wxT("wxLB_SINGLE"), wxLB_SINGLE
},
2090 { wxT("wxLB_MULTIPLE"), wxLB_MULTIPLE
},
2091 { wxT("wxLB_EXTENDED"), wxLB_EXTENDED
},
2092 { wxT("wxLB_NEEDED_SB"), wxLB_NEEDED_SB
},
2093 { wxT("wxLB_ALWAYS_SB"), wxLB_ALWAYS_SB
},
2094 { wxT("wxLB_SORT"), wxLB_SORT
},
2095 { wxT("wxLB_OWNERDRAW"), wxLB_OWNERDRAW
},
2096 { wxT("wxLB_HSCROLL"), wxLB_HSCROLL
},
2099 { wxT("wxCB_SIMPLE"), wxCB_SIMPLE
},
2100 { wxT("wxCB_DROPDOWN"), wxCB_DROPDOWN
},
2101 { wxT("wxCB_READONLY"), wxCB_READONLY
},
2102 { wxT("wxCB_SORT"), wxCB_SORT
},
2105 { wxT("wxGA_PROGRESSBAR"), wxGA_PROGRESSBAR
},
2106 { wxT("wxGA_HORIZONTAL"), wxGA_HORIZONTAL
},
2107 { wxT("wxGA_VERTICAL"), wxGA_VERTICAL
},
2110 { wxT("wxPASSWORD"), wxPASSWORD
},
2111 { wxT("wxPROCESS_ENTER"), wxPROCESS_ENTER
},
2112 { wxT("wxTE_PASSWORD"), wxTE_PASSWORD
},
2113 { wxT("wxTE_READONLY"), wxTE_READONLY
},
2114 { wxT("wxTE_PROCESS_ENTER"), wxTE_PROCESS_ENTER
},
2115 { wxT("wxTE_MULTILINE"), wxTE_MULTILINE
},
2116 { wxT("wxTE_NO_VSCROLL"), wxTE_NO_VSCROLL
},
2118 /* wxRadioBox/wxRadioButton */
2119 { wxT("wxRB_GROUP"), wxRB_GROUP
},
2120 { wxT("wxRA_SPECIFY_COLS"), wxRA_SPECIFY_COLS
},
2121 { wxT("wxRA_SPECIFY_ROWS"), wxRA_SPECIFY_ROWS
},
2122 { wxT("wxRA_HORIZONTAL"), wxRA_HORIZONTAL
},
2123 { wxT("wxRA_VERTICAL"), wxRA_VERTICAL
},
2126 { wxT("wxSL_HORIZONTAL"), wxSL_HORIZONTAL
},
2127 { wxT("wxSL_VERTICAL"), wxSL_VERTICAL
},
2128 { wxT("wxSL_AUTOTICKS"), wxSL_AUTOTICKS
},
2129 { wxT("wxSL_LABELS"), wxSL_LABELS
},
2130 { wxT("wxSL_LEFT"), wxSL_LEFT
},
2131 { wxT("wxSL_TOP"), wxSL_TOP
},
2132 { wxT("wxSL_RIGHT"), wxSL_RIGHT
},
2133 { wxT("wxSL_BOTTOM"), wxSL_BOTTOM
},
2134 { wxT("wxSL_BOTH"), wxSL_BOTH
},
2135 { wxT("wxSL_SELRANGE"), wxSL_SELRANGE
},
2138 { wxT("wxSB_HORIZONTAL"), wxSB_HORIZONTAL
},
2139 { wxT("wxSB_VERTICAL"), wxSB_VERTICAL
},
2142 { wxT("wxBU_AUTODRAW"), wxBU_AUTODRAW
},
2143 { wxT("wxBU_NOAUTODRAW"), wxBU_NOAUTODRAW
},
2146 { wxT("wxTR_HAS_BUTTONS"), wxTR_HAS_BUTTONS
},
2147 { wxT("wxTR_EDIT_LABELS"), wxTR_EDIT_LABELS
},
2148 { wxT("wxTR_LINES_AT_ROOT"), wxTR_LINES_AT_ROOT
},
2151 { wxT("wxLC_ICON"), wxLC_ICON
},
2152 { wxT("wxLC_SMALL_ICON"), wxLC_SMALL_ICON
},
2153 { wxT("wxLC_LIST"), wxLC_LIST
},
2154 { wxT("wxLC_REPORT"), wxLC_REPORT
},
2155 { wxT("wxLC_ALIGN_TOP"), wxLC_ALIGN_TOP
},
2156 { wxT("wxLC_ALIGN_LEFT"), wxLC_ALIGN_LEFT
},
2157 { wxT("wxLC_AUTOARRANGE"), wxLC_AUTOARRANGE
},
2158 { wxT("wxLC_USER_TEXT"), wxLC_USER_TEXT
},
2159 { wxT("wxLC_EDIT_LABELS"), wxLC_EDIT_LABELS
},
2160 { wxT("wxLC_NO_HEADER"), wxLC_NO_HEADER
},
2161 { wxT("wxLC_NO_SORT_HEADER"), wxLC_NO_SORT_HEADER
},
2162 { wxT("wxLC_SINGLE_SEL"), wxLC_SINGLE_SEL
},
2163 { wxT("wxLC_SORT_ASCENDING"), wxLC_SORT_ASCENDING
},
2164 { wxT("wxLC_SORT_DESCENDING"), wxLC_SORT_DESCENDING
},
2167 { wxT("wxSP_VERTICAL"), wxSP_VERTICAL
},
2168 { wxT("wxSP_HORIZONTAL"), wxSP_HORIZONTAL
},
2169 { wxT("wxSP_ARROW_KEYS"), wxSP_ARROW_KEYS
},
2170 { wxT("wxSP_WRAP"), wxSP_WRAP
},
2173 { wxT("wxSP_NOBORDER"), wxSP_NOBORDER
},
2174 { wxT("wxSP_3D"), wxSP_3D
},
2175 { wxT("wxSP_BORDER"), wxSP_BORDER
},
2178 { wxT("wxTC_MULTILINE"), wxTC_MULTILINE
},
2179 { wxT("wxTC_RIGHTJUSTIFY"), wxTC_RIGHTJUSTIFY
},
2180 { wxT("wxTC_FIXEDWIDTH"), wxTC_FIXEDWIDTH
},
2181 { wxT("wxTC_OWNERDRAW"), wxTC_OWNERDRAW
},
2184 { wxT("wxST_SIZEGRIP"), wxST_SIZEGRIP
},
2187 { wxT("wxFIXED_LENGTH"), wxFIXED_LENGTH
},
2188 { wxT("wxALIGN_LEFT"), wxALIGN_LEFT
},
2189 { wxT("wxALIGN_CENTER"), wxALIGN_CENTER
},
2190 { wxT("wxALIGN_CENTRE"), wxALIGN_CENTRE
},
2191 { wxT("wxALIGN_RIGHT"), wxALIGN_RIGHT
},
2192 { wxT("wxCOLOURED"), wxCOLOURED
},
2195 { wxT("wxTB_3DBUTTONS"), wxTB_3DBUTTONS
},
2196 { wxT("wxTB_HORIZONTAL"), wxTB_HORIZONTAL
},
2197 { wxT("wxTB_VERTICAL"), wxTB_VERTICAL
},
2198 { wxT("wxTB_FLAT"), wxTB_FLAT
},
2201 { wxT("wxDIALOG_MODAL"), wxDIALOG_MODAL
},
2204 { wxT("wxVSCROLL"), wxVSCROLL
},
2205 { wxT("wxHSCROLL"), wxHSCROLL
},
2206 { wxT("wxCAPTION"), wxCAPTION
},
2207 { wxT("wxSTAY_ON_TOP"), wxSTAY_ON_TOP
},
2208 { wxT("wxICONIZE"), wxICONIZE
},
2209 { wxT("wxMINIMIZE"), wxICONIZE
},
2210 { wxT("wxMAXIMIZE"), wxMAXIMIZE
},
2212 { wxT("wxMDI_PARENT"), 0},
2213 { wxT("wxMDI_CHILD"), 0},
2214 { wxT("wxTHICK_FRAME"), wxTHICK_FRAME
},
2215 { wxT("wxRESIZE_BORDER"), wxRESIZE_BORDER
},
2216 { wxT("wxSYSTEM_MENU"), wxSYSTEM_MENU
},
2217 { wxT("wxMINIMIZE_BOX"), wxMINIMIZE_BOX
},
2218 { wxT("wxMAXIMIZE_BOX"), wxMAXIMIZE_BOX
},
2219 { wxT("wxRESIZE_BOX"), wxRESIZE_BOX
},
2220 { wxT("wxDEFAULT_FRAME_STYLE"), wxDEFAULT_FRAME_STYLE
},
2221 { wxT("wxDEFAULT_FRAME"), wxDEFAULT_FRAME_STYLE
},
2222 { wxT("wxDEFAULT_DIALOG_STYLE"), wxDEFAULT_DIALOG_STYLE
},
2223 { wxT("wxBORDER"), wxBORDER
},
2224 { wxT("wxRETAINED"), wxRETAINED
},
2225 { wxT("wxNATIVE_IMPL"), 0},
2226 { wxT("wxEXTENDED_IMPL"), 0},
2227 { wxT("wxBACKINGSTORE"), wxBACKINGSTORE
},
2228 // { wxT("wxFLAT"), wxFLAT},
2229 // { wxT("wxMOTIF_RESIZE"), wxMOTIF_RESIZE},
2230 { wxT("wxFIXED_LENGTH"), 0},
2231 { wxT("wxDOUBLE_BORDER"), wxDOUBLE_BORDER
},
2232 { wxT("wxSUNKEN_BORDER"), wxSUNKEN_BORDER
},
2233 { wxT("wxRAISED_BORDER"), wxRAISED_BORDER
},
2234 { wxT("wxSIMPLE_BORDER"), wxSIMPLE_BORDER
},
2235 { wxT("wxSTATIC_BORDER"), wxSTATIC_BORDER
},
2236 { wxT("wxTRANSPARENT_WINDOW"), wxTRANSPARENT_WINDOW
},
2237 { wxT("wxNO_BORDER"), wxNO_BORDER
},
2238 { wxT("wxCLIP_CHILDREN"), wxCLIP_CHILDREN
},
2239 { wxT("wxCLIP_SIBLINGS"), wxCLIP_SIBLINGS
},
2240 { wxT("wxTAB_TRAVERSAL"), 0}, // Compatibility only
2242 { wxT("wxTINY_CAPTION_HORIZ"), wxTINY_CAPTION_HORIZ
},
2243 { wxT("wxTINY_CAPTION_VERT"), wxTINY_CAPTION_VERT
},
2245 // Text font families
2246 { wxT("wxDEFAULT"), wxDEFAULT
},
2247 { wxT("wxDECORATIVE"), wxDECORATIVE
},
2248 { wxT("wxROMAN"), wxROMAN
},
2249 { wxT("wxSCRIPT"), wxSCRIPT
},
2250 { wxT("wxSWISS"), wxSWISS
},
2251 { wxT("wxMODERN"), wxMODERN
},
2252 { wxT("wxTELETYPE"), wxTELETYPE
},
2253 { wxT("wxVARIABLE"), wxVARIABLE
},
2254 { wxT("wxFIXED"), wxFIXED
},
2255 { wxT("wxNORMAL"), wxNORMAL
},
2256 { wxT("wxLIGHT"), wxLIGHT
},
2257 { wxT("wxBOLD"), wxBOLD
},
2258 { wxT("wxITALIC"), wxITALIC
},
2259 { wxT("wxSLANT"), wxSLANT
},
2260 { wxT("wxSOLID"), wxSOLID
},
2261 { wxT("wxDOT"), wxDOT
},
2262 { wxT("wxLONG_DASH"), wxLONG_DASH
},
2263 { wxT("wxSHORT_DASH"), wxSHORT_DASH
},
2264 { wxT("wxDOT_DASH"), wxDOT_DASH
},
2265 { wxT("wxUSER_DASH"), wxUSER_DASH
},
2266 { wxT("wxTRANSPARENT"), wxTRANSPARENT
},
2267 { wxT("wxSTIPPLE"), wxSTIPPLE
},
2268 { wxT("wxBDIAGONAL_HATCH"), wxBDIAGONAL_HATCH
},
2269 { wxT("wxCROSSDIAG_HATCH"), wxCROSSDIAG_HATCH
},
2270 { wxT("wxFDIAGONAL_HATCH"), wxFDIAGONAL_HATCH
},
2271 { wxT("wxCROSS_HATCH"), wxCROSS_HATCH
},
2272 { wxT("wxHORIZONTAL_HATCH"), wxHORIZONTAL_HATCH
},
2273 { wxT("wxVERTICAL_HATCH"), wxVERTICAL_HATCH
},
2274 { wxT("wxJOIN_BEVEL"), wxJOIN_BEVEL
},
2275 { wxT("wxJOIN_MITER"), wxJOIN_MITER
},
2276 { wxT("wxJOIN_ROUND"), wxJOIN_ROUND
},
2277 { wxT("wxCAP_ROUND"), wxCAP_ROUND
},
2278 { wxT("wxCAP_PROJECTING"), wxCAP_PROJECTING
},
2279 { wxT("wxCAP_BUTT"), wxCAP_BUTT
},
2282 { wxT("wxCLEAR"), wxCLEAR
},
2283 { wxT("wxXOR"), wxXOR
},
2284 { wxT("wxINVERT"), wxINVERT
},
2285 { wxT("wxOR_REVERSE"), wxOR_REVERSE
},
2286 { wxT("wxAND_REVERSE"), wxAND_REVERSE
},
2287 { wxT("wxCOPY"), wxCOPY
},
2288 { wxT("wxAND"), wxAND
},
2289 { wxT("wxAND_INVERT"), wxAND_INVERT
},
2290 { wxT("wxNO_OP"), wxNO_OP
},
2291 { wxT("wxNOR"), wxNOR
},
2292 { wxT("wxEQUIV"), wxEQUIV
},
2293 { wxT("wxSRC_INVERT"), wxSRC_INVERT
},
2294 { wxT("wxOR_INVERT"), wxOR_INVERT
},
2295 { wxT("wxNAND"), wxNAND
},
2296 { wxT("wxOR"), wxOR
},
2297 { wxT("wxSET"), wxSET
},
2299 { wxT("wxFLOOD_SURFACE"), wxFLOOD_SURFACE
},
2300 { wxT("wxFLOOD_BORDER"), wxFLOOD_BORDER
},
2301 { wxT("wxODDEVEN_RULE"), wxODDEVEN_RULE
},
2302 { wxT("wxWINDING_RULE"), wxWINDING_RULE
},
2303 { wxT("wxHORIZONTAL"), wxHORIZONTAL
},
2304 { wxT("wxVERTICAL"), wxVERTICAL
},
2305 { wxT("wxBOTH"), wxBOTH
},
2306 { wxT("wxCENTER_FRAME"), wxCENTER_FRAME
},
2307 { wxT("wxOK"), wxOK
},
2308 { wxT("wxYES_NO"), wxYES_NO
},
2309 { wxT("wxCANCEL"), wxCANCEL
},
2310 { wxT("wxYES"), wxYES
},
2311 { wxT("wxNO"), wxNO
},
2312 { wxT("wxICON_EXCLAMATION"), wxICON_EXCLAMATION
},
2313 { wxT("wxICON_HAND"), wxICON_HAND
},
2314 { wxT("wxICON_QUESTION"), wxICON_QUESTION
},
2315 { wxT("wxICON_INFORMATION"), wxICON_INFORMATION
},
2316 { wxT("wxICON_STOP"), wxICON_STOP
},
2317 { wxT("wxICON_ASTERISK"), wxICON_ASTERISK
},
2318 { wxT("wxICON_MASK"), wxICON_MASK
},
2319 { wxT("wxCENTRE"), wxCENTRE
},
2320 { wxT("wxCENTER"), wxCENTRE
},
2321 { wxT("wxUSER_COLOURS"), wxUSER_COLOURS
},
2322 { wxT("wxVERTICAL_LABEL"), 0},
2323 { wxT("wxHORIZONTAL_LABEL"), 0},
2325 // Bitmap types (not strictly styles)
2326 { wxT("wxBITMAP_TYPE_XPM"), wxBITMAP_TYPE_XPM
},
2327 { wxT("wxBITMAP_TYPE_XBM"), wxBITMAP_TYPE_XBM
},
2328 { wxT("wxBITMAP_TYPE_BMP"), wxBITMAP_TYPE_BMP
},
2329 { wxT("wxBITMAP_TYPE_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2330 { wxT("wxBITMAP_TYPE_BMP_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2331 { wxT("wxBITMAP_TYPE_GIF"), wxBITMAP_TYPE_GIF
},
2332 { wxT("wxBITMAP_TYPE_TIF"), wxBITMAP_TYPE_TIF
},
2333 { wxT("wxBITMAP_TYPE_ICO"), wxBITMAP_TYPE_ICO
},
2334 { wxT("wxBITMAP_TYPE_ICO_RESOURCE"), wxBITMAP_TYPE_ICO_RESOURCE
},
2335 { wxT("wxBITMAP_TYPE_CUR"), wxBITMAP_TYPE_CUR
},
2336 { wxT("wxBITMAP_TYPE_CUR_RESOURCE"), wxBITMAP_TYPE_CUR_RESOURCE
},
2337 { wxT("wxBITMAP_TYPE_XBM_DATA"), wxBITMAP_TYPE_XBM_DATA
},
2338 { wxT("wxBITMAP_TYPE_XPM_DATA"), wxBITMAP_TYPE_XPM_DATA
},
2339 { wxT("wxBITMAP_TYPE_ANY"), wxBITMAP_TYPE_ANY
}
2342 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
2344 long wxParseWindowStyle(const wxString
& bitListString
)
2349 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2350 while (word
!= NULL
)
2354 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2355 if (wxStrcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2357 bitList
|= wxResourceBitListTable
[j
].bits
;
2363 wxLogWarning(_("Unrecognized style %s while parsing resource."), word
);
2366 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2372 * Load a bitmap from a wxWidgets resource, choosing an optimum
2373 * depth and appropriate type.
2376 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
2379 table
= wxDefaultResourceTable
;
2381 wxItemResource
*item
= table
->FindResource(resource
);
2384 if ((item
->GetType().empty()) || (item
->GetType() != wxT("wxBitmap")))
2386 wxLogWarning(_("%s not a bitmap resource specification."), (const wxChar
*) resource
);
2387 return wxNullBitmap
;
2389 int thisDepth
= wxDisplayDepth();
2390 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2392 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2394 // Try to find optimum bitmap for this platform/colour depth
2395 wxNode
*node
= item
->GetChildren().GetFirst();
2398 wxItemResource
*child
= (wxItemResource
*)node
->GetData();
2399 int platform
= (int)child
->GetValue2();
2400 int noColours
= (int)child
->GetValue3();
2402 char *name = child->GetName();
2403 int bitmapType = (int)child->GetValue1();
2404 int xRes = child->GetWidth();
2405 int yRes = child->GetHeight();
2410 case RESOURCE_PLATFORM_ANY
:
2412 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2413 optResource
= child
;
2416 // Maximise the number of colours.
2417 // If noColours is zero (unspecified), then assume this
2418 // is the right one.
2419 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2420 optResource
= child
;
2425 case RESOURCE_PLATFORM_WINDOWS
:
2427 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2428 optResource
= child
;
2431 // Maximise the number of colours
2432 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2433 optResource
= child
;
2439 case RESOURCE_PLATFORM_X
:
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_MAC
:
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
;
2469 node
= node
->GetNext();
2471 // If no matching resource, fail.
2473 return wxNullBitmap
;
2475 wxString name
= optResource
->GetName();
2476 int bitmapType
= (int)optResource
->GetValue1();
2479 case wxBITMAP_TYPE_XBM_DATA
:
2482 wxItemResource
*item
= table
->FindResource(name
);
2485 wxLogWarning(_("Failed to find XBM resource %s.\n"
2486 "Forgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2487 return wxNullBitmap
;
2489 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2491 wxLogWarning(_("No XBM facility available!"));
2495 case wxBITMAP_TYPE_XPM_DATA
:
2497 wxItemResource
*item
= table
->FindResource(name
);
2500 wxLogWarning(_("Failed to find XPM resource %s.\nForgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2501 return wxNullBitmap
;
2503 return wxBitmap((char **)item
->GetValue1());
2507 #if defined(__WXPM__)
2508 return wxNullBitmap
;
2510 return wxBitmap(name
, (wxBitmapType
)bitmapType
);
2515 return wxNullBitmap
;
2520 wxLogWarning(_("Bitmap resource specification %s not found."), (const wxChar
*) resource
);
2521 return wxNullBitmap
;
2526 * Load an icon from a wxWidgets resource, choosing an optimum
2527 * depth and appropriate type.
2530 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2533 table
= wxDefaultResourceTable
;
2535 wxItemResource
*item
= table
->FindResource(resource
);
2538 if ((item
->GetType().empty()) || wxStrcmp(item
->GetType(), wxT("wxIcon")) != 0)
2540 wxLogWarning(_("%s not an icon resource specification."), (const wxChar
*) resource
);
2543 int thisDepth
= wxDisplayDepth();
2544 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2546 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2548 // Try to find optimum icon for this platform/colour depth
2549 wxNode
*node
= item
->GetChildren().GetFirst();
2552 wxItemResource
*child
= (wxItemResource
*)node
->GetData();
2553 int platform
= (int)child
->GetValue2();
2554 int noColours
= (int)child
->GetValue3();
2556 char *name = child->GetName();
2557 int bitmapType = (int)child->GetValue1();
2558 int xRes = child->GetWidth();
2559 int yRes = child->GetHeight();
2564 case RESOURCE_PLATFORM_ANY
:
2566 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2567 optResource
= child
;
2570 // Maximise the number of colours.
2571 // If noColours is zero (unspecified), then assume this
2572 // is the right one.
2573 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2574 optResource
= child
;
2579 case RESOURCE_PLATFORM_WINDOWS
:
2581 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2582 optResource
= child
;
2585 // Maximise the number of colours
2586 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2587 optResource
= child
;
2593 case RESOURCE_PLATFORM_X
:
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_MAC
:
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
;
2623 node
= node
->GetNext();
2625 // If no matching resource, fail.
2629 wxString name
= optResource
->GetName();
2630 int bitmapType
= (int)optResource
->GetValue1();
2633 case wxBITMAP_TYPE_XBM_DATA
:
2636 wxItemResource
*item
= table
->FindResource(name
);
2639 wxLogWarning(_("Failed to find XBM resource %s.\n"
2640 "Forgot to use wxResourceLoadIconData?"), (const wxChar
*) name
);
2643 return wxIcon((const char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2645 wxLogWarning(_("No XBM facility available!"));
2649 case wxBITMAP_TYPE_XPM_DATA
:
2651 // *** XPM ICON NOT YET IMPLEMENTED IN wxWidgets ***
2653 wxItemResource *item = table->FindResource(name);
2657 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2661 return wxIcon((char **)item->GetValue1());
2663 wxLogWarning(_("No XPM icon facility available!"));
2668 #if defined( __WXGTK__ ) || defined( __WXMOTIF__ )
2669 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2672 return wxIcon(name
, (wxBitmapType
) bitmapType
);
2680 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2687 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2689 wxMenu
*menu
= new wxMenu
;
2690 wxNode
*node
= item
->GetChildren().GetFirst();
2693 wxItemResource
*child
= (wxItemResource
*)node
->GetData();
2694 if ((!child
->GetType().empty()) && (child
->GetType() == wxT("wxMenuSeparator")))
2695 menu
->AppendSeparator();
2696 else if (child
->GetChildren().GetCount() > 0)
2698 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2700 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2704 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2706 node
= node
->GetNext();
2711 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2714 table
= wxDefaultResourceTable
;
2716 wxItemResource
*menuResource
= table
->FindResource(resource
);
2717 if (menuResource
&& (!menuResource
->GetType().empty()) && (menuResource
->GetType() == wxT("wxMenu")))
2720 menuBar
= new wxMenuBar
;
2721 wxNode
*node
= menuResource
->GetChildren().GetFirst();
2724 wxItemResource
*child
= (wxItemResource
*)node
->GetData();
2725 wxMenu
*menu
= wxResourceCreateMenu(child
);
2727 menuBar
->Append(menu
, child
->GetTitle());
2728 node
= node
->GetNext();
2732 return (wxMenuBar
*) NULL
;
2735 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2738 table
= wxDefaultResourceTable
;
2740 wxItemResource
*menuResource
= table
->FindResource(resource
);
2741 if (menuResource
&& (!menuResource
->GetType().empty()) && (menuResource
->GetType() == wxT("wxMenu")))
2742 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2743 return wxResourceCreateMenu(menuResource
);
2744 return (wxMenu
*) NULL
;
2747 #endif // wxUSE_MENUS
2749 // Global equivalents (so don't have to refer to default table explicitly)
2750 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2753 table
= wxDefaultResourceTable
;
2755 return table
->ParseResourceData(resource
);
2758 bool wxResourceParseData(const char* resource
, wxResourceTable
*table
)
2760 wxString
str(resource
, wxConvLibc
);
2762 table
= wxDefaultResourceTable
;
2764 return table
->ParseResourceData(str
);
2767 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2770 table
= wxDefaultResourceTable
;
2772 return table
->ParseResourceFile(filename
);
2775 // Register XBM/XPM data
2776 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2779 table
= wxDefaultResourceTable
;
2781 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2784 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2787 table
= wxDefaultResourceTable
;
2789 return table
->RegisterResourceBitmapData(name
, data
);
2792 void wxResourceClear(wxResourceTable
*table
)
2795 table
= wxDefaultResourceTable
;
2797 table
->ClearTable();
2804 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2807 table
= wxDefaultResourceTable
;
2809 table
->identifiers
.Put(name
, (wxObject
*)(long)value
);
2813 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2816 table
= wxDefaultResourceTable
;
2818 return (int)(long)table
->identifiers
.Get(name
);
2822 * Parse #include file for #defines (only)
2825 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2828 table
= wxDefaultResourceTable
;
2830 FILE *fd
= wxFopen(f
, wxT("r"));
2835 while (wxGetResourceToken(fd
))
2837 if (strcmp(wxResourceBuffer
, "#define") == 0)
2839 wxGetResourceToken(fd
);
2840 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2841 wxGetResourceToken(fd
);
2842 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2843 if (wxIsdigit(value
[0]))
2845 int val
= (int)wxAtol(value
);
2846 wxResourceAddIdentifier(name
, val
, table
);
2857 * Reading strings as if they were .wxr files
2860 static int getc_string(char *s
)
2862 int ch
= s
[wxResourceStringPtr
];
2867 wxResourceStringPtr
++;
2872 static int ungetc_string()
2874 wxResourceStringPtr
--;
2878 bool wxEatWhiteSpaceString(char *s
)
2882 while ((ch
= getc_string(s
)) != EOF
)
2893 ch
= getc_string(s
);
2904 while ((ch
= getc_string(s
)) != EOF
)
2906 if (ch
== '/' && prev_ch
== '*')
2928 bool wxGetResourceTokenString(char *s
)
2930 if (!wxResourceBuffer
)
2931 wxReallocateResourceBuffer();
2932 wxResourceBuffer
[0] = 0;
2933 wxEatWhiteSpaceString(s
);
2935 int ch
= getc_string(s
);
2939 wxResourceBufferCount
= 0;
2940 ch
= getc_string(s
);
2946 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2949 // Escaped characters
2950 else if (ch
== '\\')
2952 int newCh
= getc_string(s
);
2955 else if (newCh
== 10)
2963 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2964 wxReallocateResourceBuffer();
2965 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2966 wxResourceBufferCount
++;
2967 ch
= getc_string(s
);
2969 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2973 wxResourceBufferCount
= 0;
2975 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2977 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2978 wxReallocateResourceBuffer();
2979 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2980 wxResourceBufferCount
++;
2982 ch
= getc_string(s
);
2984 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2992 * Files are in form:
2993 static char *name = "....";
2994 with possible comments.
2997 bool wxResourceReadOneResourceString(char *s
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
3000 table
= wxDefaultResourceTable
;
3002 // static or #define
3003 if (!wxGetResourceTokenString(s
))
3009 if (strcmp(wxResourceBuffer
, "#define") == 0)
3011 wxGetResourceTokenString(s
);
3012 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
3013 wxGetResourceTokenString(s
);
3014 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
3015 if (wxIsdigit(value
[0]))
3017 int val
= (int)wxAtol(value
);
3018 wxResourceAddIdentifier(name
, val
, table
);
3022 wxLogWarning(_("#define %s must be an integer."), name
);
3033 else if (strcmp(wxResourceBuffer, "#include") == 0)
3035 wxGetResourceTokenString(s);
3036 char *name = copystring(wxResourceBuffer);
3037 char *actualName = name;
3039 actualName = name + 1;
3040 int len = strlen(name);
3041 if ((len > 0) && (name[len-1] == '"'))
3043 if (!wxResourceParseIncludeFile(actualName, table))
3046 sprintf(buf, _("Could not find resource include file %s."), actualName);
3053 else if (strcmp(wxResourceBuffer
, "static") != 0)
3056 wxStrcpy(buf
, _("Found "));
3057 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
3058 wxStrcat(buf
, _(", expected static, #include or #define\nwhile parsing resource."));
3064 if (!wxGetResourceTokenString(s
))
3066 wxLogWarning(_("Unexpected end of file while parsing resource."));
3071 if (strcmp(wxResourceBuffer
, "char") != 0)
3073 wxLogWarning(_("Expected 'char' while parsing resource."));
3078 if (!wxGetResourceTokenString(s
))
3080 wxLogWarning(_("Unexpected end of file while parsing resource."));
3085 if (wxResourceBuffer
[0] != '*')
3087 wxLogWarning(_("Expected '*' while parsing resource."));
3090 wxChar nameBuf
[100];
3091 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
3095 if (!wxGetResourceTokenString(s
))
3097 wxLogWarning(_("Unexpected end of file while parsing resource."));
3102 if (strcmp(wxResourceBuffer
, "=") != 0)
3104 wxLogWarning(_("Expected '=' while parsing resource."));
3109 if (!wxGetResourceTokenString(s
))
3111 wxLogWarning(_("Unexpected end of file while parsing resource."));
3117 if (!db
.ReadPrologFromString(wxResourceBuffer
))
3119 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
3124 if (!wxGetResourceTokenString(s
))
3131 bool wxResourceParseString(const wxString
& s
, wxResourceTable
*WXUNUSED(table
))
3134 return wxResourceParseString( (char*)s
.mb_str().data() );
3136 return wxResourceParseString( (char*)s
.c_str() );
3140 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
3143 table
= wxDefaultResourceTable
;
3148 // Turn backslashes into spaces
3151 int len
= strlen(s
);
3153 for (i
= 0; i
< len
; i
++)
3154 if (s
[i
] == 92 && s
[i
+1] == 13)
3162 wxResourceStringPtr
= 0;
3165 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
3169 return wxResourceInterpretResources(*table
, db
);
3173 * resource loading facility
3176 bool wxLoadFromResource(wxWindow
* thisWindow
, wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
3179 table
= wxDefaultResourceTable
;
3181 wxItemResource
*resource
= table
->FindResource((const wxChar
*)resourceName
);
3182 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
3183 if (!resource
|| (resource
->GetType().empty()) ||
3184 ! ((resource
->GetType() == wxT("wxDialog")) || (resource
->GetType() == wxT("wxPanel"))))
3187 wxString
title(resource
->GetTitle());
3188 long theWindowStyle
= resource
->GetStyle();
3189 bool isModal
= (resource
->GetValue1() != 0) ;
3190 int x
= resource
->GetX();
3191 int y
= resource
->GetY();
3192 int width
= resource
->GetWidth();
3193 int height
= resource
->GetHeight();
3194 wxString name
= resource
->GetName();
3196 // this is used for loading wxWizard pages from WXR
3197 if ( parent
!= thisWindow
)
3199 if (thisWindow
->IsKindOf(CLASSINFO(wxDialog
)))
3201 wxDialog
*dialogBox
= (wxDialog
*)thisWindow
;
3202 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
3203 if (!dialogBox
->Create(parent
, wxID_ANY
, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
3206 // Only reset the client size if we know we're not going to do it again below.
3207 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == 0)
3208 dialogBox
->SetClientSize(width
, height
);
3210 else if (thisWindow
->IsKindOf(CLASSINFO(wxPanel
)))
3212 wxPanel
* panel
= (wxPanel
*)thisWindow
;
3213 if (!panel
->Create(parent
, wxID_ANY
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
| wxTAB_TRAVERSAL
, name
))
3218 if (!((wxWindow
*)thisWindow
)->Create(parent
, wxID_ANY
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
3223 if ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
3225 // No need to do this since it's done in wxPanel or wxDialog constructor.
3226 // SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
3230 if (resource
->GetFont().Ok())
3231 thisWindow
->SetFont(resource
->GetFont());
3232 if (resource
->GetBackgroundColour().Ok())
3233 thisWindow
->SetBackgroundColour(resource
->GetBackgroundColour());
3236 // Should have some kind of font at this point
3237 if (!thisWindow
->GetFont().Ok())
3238 thisWindow
->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
3239 if (!thisWindow
->GetBackgroundColour().Ok())
3240 thisWindow
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
3242 // Only when we've created the window and set the font can we set the correct size,
3243 // if based on dialog units.
3244 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
3246 wxSize sz
= thisWindow
->ConvertDialogToPixels(wxSize(width
, height
));
3247 thisWindow
->SetClientSize(sz
.x
, sz
.y
);
3249 wxPoint pt
= thisWindow
->ConvertDialogToPixels(wxPoint(x
, y
));
3250 thisWindow
->Move(pt
.x
, pt
.y
);
3253 // Now create children
3254 wxNode
*node
= resource
->GetChildren().GetFirst();
3257 wxItemResource
*childResource
= (wxItemResource
*)node
->GetData();
3259 (void) wxCreateItem(thisWindow
, childResource
, resource
, table
);
3261 node
= node
->GetNext();
3266 wxControl
*wxCreateItem(wxWindow
* thisWindow
, const wxItemResource
*resource
, const wxItemResource
* parentResource
, const wxResourceTable
*table
)
3269 table
= wxDefaultResourceTable
;
3270 return table
->CreateItem(thisWindow
, resource
, parentResource
);
3274 #pragma warning(default:4706) // assignment within conditional expression
3277 #endif // wxUSE_WX_RESOURCES