1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Resource system
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "resource.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #include "wx/deprecated/setup.h"
25 #if wxUSE_WX_RESOURCES
28 #pragma warning(disable:4706) // assignment within conditional expression
36 #include "wx/gdicmn.h"
40 #include "wx/stattext.h"
41 #include "wx/button.h"
42 #include "wx/bmpbuttn.h"
43 #include "wx/radiobox.h"
44 #include "wx/listbox.h"
45 #include "wx/choice.h"
46 #include "wx/checkbox.h"
47 #include "wx/settings.h"
48 #include "wx/slider.h"
50 #include "wx/statbox.h"
51 #include "wx/statbmp.h"
53 #include "wx/textctrl.h"
54 #include "wx/msgdlg.h"
58 #include "wx/treebase.h"
59 #include "wx/listctrl.h"
62 #include "wx/radiobut.h"
66 #include "wx/scrolbar.h"
70 #include "wx/combobox.h"
73 #include "wx/validate.h"
75 #include "wx/module.h"
82 #include "wx/string.h"
83 #include "wx/settings.h"
84 #include "wx/stream.h"
86 #include "wx/deprecated/resource.h"
87 #include "wx/deprecated/wxexpr.h"
89 // Forward (private) declarations
90 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
);
91 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
= FALSE
);
92 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
);
93 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
);
94 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
);
95 wxItemResource
*wxResourceInterpretString(wxResourceTable
& table
, wxExpr
*expr
);
96 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& table
, wxExpr
*expr
);
97 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
);
98 // Interpret list expression
99 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
);
101 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
102 bool wxResourceReadOneResource(wxInputStream
*fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
) ;
103 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
105 wxResourceTable
*wxDefaultResourceTable
= (wxResourceTable
*) NULL
;
107 char *wxResourceBuffer
= (char *) NULL
;
108 long wxResourceBufferSize
= 0;
109 long wxResourceBufferCount
= 0;
110 int wxResourceStringPtr
= 0;
112 void wxInitializeResourceSystem()
114 if (!wxDefaultResourceTable
)
115 wxDefaultResourceTable
= new wxResourceTable
;
118 void wxCleanUpResourceSystem()
120 delete wxDefaultResourceTable
;
121 if (wxResourceBuffer
)
122 delete[] wxResourceBuffer
;
125 // Module to ensure the resource system data gets initialized
128 class wxResourceModule
: public wxModule
131 wxResourceModule() : wxModule() {}
132 virtual bool OnInit() { wxInitializeResourceSystem(); return TRUE
; }
133 virtual void OnExit() { wxCleanUpResourceSystem(); }
135 DECLARE_DYNAMIC_CLASS(wxResourceModule
)
138 IMPLEMENT_DYNAMIC_CLASS(wxResourceModule
, wxModule
)
141 IMPLEMENT_DYNAMIC_CLASS(wxItemResource
, wxObject
)
142 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable
, wxHashTable
)
144 wxItemResource::wxItemResource()
146 m_itemType
= wxT("");
150 m_x
= m_y
= m_width
= m_height
= 0;
151 m_value1
= m_value2
= m_value3
= m_value5
= 0;
157 wxItemResource::~wxItemResource()
159 wxNode
*node
= m_children
.First();
162 wxItemResource
*item
= (wxItemResource
*)node
->Data();
165 node
= m_children
.First();
173 wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
)
177 wxResourceTable::~wxResourceTable()
182 wxItemResource
*wxResourceTable::FindResource(const wxString
& name
) const
184 wxItemResource
*item
= (wxItemResource
*)Get(WXSTRINGCAST name
);
188 void wxResourceTable::AddResource(wxItemResource
*item
)
190 wxString name
= item
->GetName();
192 name
= item
->GetTitle();
194 name
= wxT("no name");
196 // Delete existing resource, if any.
202 bool wxResourceTable::DeleteResource(const wxString
& name
)
204 wxItemResource
*item
= (wxItemResource
*)Delete(WXSTRINGCAST name
);
207 // See if any resource has this as its child; if so, delete from
208 // parent's child list.
210 wxNode
*node
= (wxNode
*) NULL
;
214 wxItemResource
*parent
= (wxItemResource
*)node
->Data();
215 if (parent
->GetChildren().Member(item
))
217 parent
->GetChildren().DeleteObject(item
);
230 bool wxResourceTable::ParseResourceFile( wxInputStream
*is
)
233 int len
= is
->GetSize() ;
236 while ( is
->TellI() + 10 < len
) // it's a hack because the streams dont support EOF
238 wxResourceReadOneResource(is
, db
, &eof
, this) ;
240 return wxResourceInterpretResources(*this, db
);
243 bool wxResourceTable::ParseResourceFile(const wxString
& filename
)
247 FILE *fd
= wxFopen(filename
, wxT("r"));
251 while (wxResourceReadOneResource(fd
, db
, &eof
, this) && !eof
)
256 return wxResourceInterpretResources(*this, db
);
259 bool wxResourceTable::ParseResourceData(const wxString
& data
)
262 if (!db
.ReadFromString(data
))
264 wxLogWarning(_("Ill-formed resource file syntax."));
268 return wxResourceInterpretResources(*this, db
);
271 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char bits
[], int width
, int height
)
273 // Register pre-loaded bitmap data
274 wxItemResource
*item
= new wxItemResource
;
275 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
276 item
->SetType(wxT("wxXBMData"));
278 item
->SetValue1((long)bits
);
279 item
->SetValue2((long)width
);
280 item
->SetValue3((long)height
);
285 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char **data
)
287 // Register pre-loaded bitmap data
288 wxItemResource
*item
= new wxItemResource
;
289 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
290 item
->SetType(wxT("wxXPMData"));
292 item
->SetValue1((long)data
);
297 bool wxResourceTable::SaveResource(const wxString
& WXUNUSED(filename
))
302 void wxResourceTable::ClearTable()
305 wxNode
*node
= Next();
308 wxNode
*next
= Next();
309 wxItemResource
*item
= (wxItemResource
*)node
->Data();
316 wxControl
*wxResourceTable::CreateItem(wxWindow
*parent
, const wxItemResource
* childResource
, const wxItemResource
* parentResource
) const
318 int id
= childResource
->GetId();
322 bool dlgUnits
= ((parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0);
324 wxControl
*control
= (wxControl
*) NULL
;
325 wxString
itemType(childResource
->GetType());
331 pos
= parent
->ConvertDialogToPixels(wxPoint(childResource
->GetX(), childResource
->GetY()));
332 size
= parent
->ConvertDialogToPixels(wxSize(childResource
->GetWidth(), childResource
->GetHeight()));
336 pos
= wxPoint(childResource
->GetX(), childResource
->GetY());
337 size
= wxSize(childResource
->GetWidth(), childResource
->GetHeight());
340 if (itemType
== wxString(wxT("wxButton")) || itemType
== wxString(wxT("wxBitmapButton")))
342 if (childResource
->GetValue4() != wxT(""))
345 wxBitmap bitmap
= childResource
->GetBitmap();
348 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
349 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
352 #if defined(__WXPM__)
354 // OS/2 uses integer id's to access resources, not file name strings
356 bitmap
.LoadFile(wxCROSS_BITMAP
, wxBITMAP_TYPE_BMP_RESOURCE
);
358 bitmap
.LoadFile(wxT("cross_bmp"), wxBITMAP_TYPE_BMP_RESOURCE
);
360 control
= new wxBitmapButton(parent
, id
, bitmap
, pos
, size
,
361 childResource
->GetStyle() | wxBU_AUTODRAW
, wxDefaultValidator
, childResource
->GetName());
364 // Normal, text button
365 control
= new wxButton(parent
, id
, childResource
->GetTitle(), pos
, size
,
366 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
368 else if (itemType
== wxString(wxT("wxMessage")) || itemType
== wxString(wxT("wxStaticText")) ||
369 itemType
== wxString(wxT("wxStaticBitmap")))
371 if (childResource
->GetValue4() != wxT("") || itemType
== wxString(wxT("wxStaticBitmap")) )
374 wxBitmap bitmap
= childResource
->GetBitmap();
377 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
378 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
380 #if wxUSE_BITMAP_MESSAGE
382 // Use a default bitmap
384 bitmap
.LoadFile(wxT("cross_bmp"), wxBITMAP_TYPE_BMP_RESOURCE
);
388 control
= new wxStaticBitmap(parent
, id
, bitmap
, pos
, size
,
389 childResource
->GetStyle(), childResource
->GetName());
394 control
= new wxStaticText(parent
, id
, childResource
->GetTitle(), pos
, size
,
395 childResource
->GetStyle(), childResource
->GetName());
398 else if (itemType
== wxString(wxT("wxText")) || itemType
== wxString(wxT("wxTextCtrl")) || itemType
== wxString(wxT("wxMultiText")))
400 control
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(), pos
, size
,
401 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
403 else if (itemType
== wxString(wxT("wxCheckBox")))
405 control
= new wxCheckBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
406 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
408 ((wxCheckBox
*)control
)->SetValue((childResource
->GetValue1() != 0));
411 else if (itemType
== wxString(wxT("wxGauge")))
413 control
= new wxGauge(parent
, id
, (int)childResource
->GetValue2(), pos
, size
,
414 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
416 ((wxGauge
*)control
)->SetValue((int)childResource
->GetValue1());
420 else if (itemType
== wxString(wxT("wxRadioButton")))
422 control
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(),
424 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
428 else if (itemType
== wxString(wxT("wxScrollBar")))
430 control
= new wxScrollBar(parent
, id
, pos
, size
,
431 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
433 ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1());
434 ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2());
435 ((wxScrollBar *)control)->SetObjectLength((int)childResource->GetValue3());
436 ((wxScrollBar *)control)->SetViewLength((int)(long)childResource->GetValue5());
438 ((wxScrollBar
*)control
)->SetScrollbar((int)childResource
->GetValue1(),(int)childResource
->GetValue2(),
439 (int)childResource
->GetValue3(),(int)(long)childResource
->GetValue5(),FALSE
);
443 else if (itemType
== wxString(wxT("wxSlider")))
445 control
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(),
446 (int)childResource
->GetValue2(), (int)childResource
->GetValue3(), pos
, size
,
447 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
449 else if (itemType
== wxString(wxT("wxGroupBox")) || itemType
== wxString(wxT("wxStaticBox")))
451 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
452 childResource
->GetStyle(), childResource
->GetName());
454 else if (itemType
== wxString(wxT("wxListBox")))
456 wxStringList
& stringList
= childResource
->GetStringValues();
457 wxString
*strings
= (wxString
*) NULL
;
459 if (stringList
.Number() > 0)
461 noStrings
= stringList
.Number();
462 strings
= new wxString
[noStrings
];
463 wxNode
*node
= stringList
.First();
467 strings
[i
] = (wxChar
*)node
->Data();
472 control
= new wxListBox(parent
, id
, pos
, size
,
473 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
478 else if (itemType
== wxString(wxT("wxChoice")))
480 wxStringList
& stringList
= childResource
->GetStringValues();
481 wxString
*strings
= (wxString
*) NULL
;
483 if (stringList
.Number() > 0)
485 noStrings
= stringList
.Number();
486 strings
= new wxString
[noStrings
];
487 wxNode
*node
= stringList
.First();
491 strings
[i
] = (wxChar
*)node
->Data();
496 control
= new wxChoice(parent
, id
, pos
, size
,
497 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
503 else if (itemType
== wxString(wxT("wxComboBox")))
505 wxStringList
& stringList
= childResource
->GetStringValues();
506 wxString
*strings
= (wxString
*) NULL
;
508 if (stringList
.Number() > 0)
510 noStrings
= stringList
.Number();
511 strings
= new wxString
[noStrings
];
512 wxNode
*node
= stringList
.First();
516 strings
[i
] = (wxChar
*)node
->Data();
521 control
= new wxComboBox(parent
, id
, childResource
->GetValue4(), pos
, size
,
522 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
528 else if (itemType
== wxString(wxT("wxRadioBox")))
530 wxStringList
& stringList
= childResource
->GetStringValues();
531 wxString
*strings
= (wxString
*) NULL
;
533 if (stringList
.Number() > 0)
535 noStrings
= stringList
.Number();
536 strings
= new wxString
[noStrings
];
537 wxNode
*node
= stringList
.First();
541 strings
[i
] = (wxChar
*)node
->Data();
546 control
= new wxRadioBox(parent
, (wxWindowID
) id
, wxString(childResource
->GetTitle()), pos
, size
,
547 noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
,
548 childResource
->GetName());
554 if ((parentResource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
556 // Don't set font; will be inherited from parent.
560 if (control
&& childResource
->GetFont().Ok())
562 control
->SetFont(childResource
->GetFont());
565 // Force the layout algorithm since the size changes the layout
566 if (control
->IsKindOf(CLASSINFO(wxRadioBox
)))
568 control
->SetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
|wxSIZE_AUTO_HEIGHT
);
577 * Interpret database as a series of resources
580 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
)
582 wxNode
*node
= db
.First();
585 wxExpr
*clause
= (wxExpr
*)node
->Data();
586 wxString
functor(clause
->Functor());
588 wxItemResource
*item
= (wxItemResource
*) NULL
;
589 if (functor
== wxT("dialog"))
590 item
= wxResourceInterpretDialog(table
, clause
);
591 else if (functor
== wxT("panel"))
592 item
= wxResourceInterpretDialog(table
, clause
, TRUE
);
593 else if (functor
== wxT("menubar"))
594 item
= wxResourceInterpretMenuBar(table
, clause
);
595 else if (functor
== wxT("menu"))
596 item
= wxResourceInterpretMenu(table
, clause
);
597 else if (functor
== wxT("string"))
598 item
= wxResourceInterpretString(table
, clause
);
599 else if (functor
== wxT("bitmap"))
600 item
= wxResourceInterpretBitmap(table
, clause
);
601 else if (functor
== wxT("icon"))
602 item
= wxResourceInterpretIcon(table
, clause
);
606 // Remove any existing resource of same name
607 if (item
->GetName() != wxT(""))
608 table
.DeleteResource(item
->GetName());
609 table
.AddResource(item
);
616 static const wxChar
*g_ValidControlClasses
[] =
619 wxT("wxBitmapButton"),
622 wxT("wxStaticBitmap"),
628 wxT("wxRadioButton"),
630 wxT("wxBitmapCheckBox"),
640 static bool wxIsValidControlClass(const wxString
& c
)
642 for ( size_t i
= 0; i
< WXSIZEOF(g_ValidControlClasses
); i
++ )
644 if ( c
== g_ValidControlClasses
[i
] )
650 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
)
652 wxItemResource
*dialogItem
= new wxItemResource
;
654 dialogItem
->SetType(wxT("wxPanel"));
656 dialogItem
->SetType(wxT("wxDialog"));
657 wxString style
= wxT("");
658 wxString title
= wxT("");
659 wxString name
= wxT("");
660 wxString backColourHex
= wxT("");
661 wxString labelColourHex
= wxT("");
662 wxString buttonColourHex
= wxT("");
664 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
668 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
670 wxExpr
*labelFontExpr
= (wxExpr
*) NULL
;
671 wxExpr
*buttonFontExpr
= (wxExpr
*) NULL
;
672 wxExpr
*fontExpr
= (wxExpr
*) NULL
;
673 expr
->GetAttributeValue(wxT("style"), style
);
674 expr
->GetAttributeValue(wxT("name"), name
);
675 expr
->GetAttributeValue(wxT("title"), title
);
676 expr
->GetAttributeValue(wxT("x"), x
);
677 expr
->GetAttributeValue(wxT("y"), y
);
678 expr
->GetAttributeValue(wxT("width"), width
);
679 expr
->GetAttributeValue(wxT("height"), height
);
680 expr
->GetAttributeValue(wxT("modal"), isModal
);
681 expr
->GetAttributeValue(wxT("label_font"), &labelFontExpr
);
682 expr
->GetAttributeValue(wxT("button_font"), &buttonFontExpr
);
683 expr
->GetAttributeValue(wxT("font"), &fontExpr
);
684 expr
->GetAttributeValue(wxT("background_colour"), backColourHex
);
685 expr
->GetAttributeValue(wxT("label_colour"), labelColourHex
);
686 expr
->GetAttributeValue(wxT("button_colour"), buttonColourHex
);
688 int useDialogUnits
= 0;
689 expr
->GetAttributeValue(wxT("use_dialog_units"), useDialogUnits
);
690 if (useDialogUnits
!= 0)
691 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS
);
694 expr
->GetAttributeValue(wxT("use_system_defaults"), useDefaults
);
695 if (useDefaults
!= 0)
696 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS
);
699 expr
->GetAttributeValue(wxT("id"), id
);
700 dialogItem
->SetId(id
);
702 if (style
!= wxT(""))
704 windowStyle
= wxParseWindowStyle(style
);
706 dialogItem
->SetStyle(windowStyle
);
707 dialogItem
->SetValue1(isModal
);
708 if (windowStyle
& wxDIALOG_MODAL
) // Uses style in wxWin 2
709 dialogItem
->SetValue1(TRUE
);
711 dialogItem
->SetName(name
);
712 dialogItem
->SetTitle(title
);
713 dialogItem
->SetSize(x
, y
, width
, height
);
715 // Check for wxWin 1.68-style specifications
716 if (style
.Find(wxT("VERTICAL_LABEL")) != -1)
717 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL
);
718 else if (style
.Find(wxT("HORIZONTAL_LABEL")) != -1)
719 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL
);
721 if (backColourHex
!= wxT(""))
726 r
= wxHexToDec(backColourHex
.Mid(0, 2));
727 g
= wxHexToDec(backColourHex
.Mid(2, 2));
728 b
= wxHexToDec(backColourHex
.Mid(4, 2));
729 dialogItem
->SetBackgroundColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
731 if (labelColourHex
!= wxT(""))
736 r
= wxHexToDec(labelColourHex
.Mid(0, 2));
737 g
= wxHexToDec(labelColourHex
.Mid(2, 2));
738 b
= wxHexToDec(labelColourHex
.Mid(4, 2));
739 dialogItem
->SetLabelColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
741 if (buttonColourHex
!= wxT(""))
746 r
= wxHexToDec(buttonColourHex
.Mid(0, 2));
747 g
= wxHexToDec(buttonColourHex
.Mid(2, 2));
748 b
= wxHexToDec(buttonColourHex
.Mid(4, 2));
749 dialogItem
->SetButtonColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
753 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
754 else if (buttonFontExpr
)
755 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
756 else if (labelFontExpr
)
757 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
759 // Now parse all controls
760 wxExpr
*controlExpr
= expr
->GetFirst();
763 if (controlExpr
->Number() == 3)
765 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
766 if (controlKeyword
!= wxT("") && controlKeyword
== wxT("control"))
768 // The value part: always a list.
769 wxExpr
*listExpr
= controlExpr
->Nth(2);
770 if (listExpr
->Type() == PrologList
)
772 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
775 dialogItem
->GetChildren().Append(controlItem
);
780 controlExpr
= controlExpr
->GetNext();
785 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
)
787 wxItemResource
*controlItem
= new wxItemResource
;
789 // First, find the standard features of a control definition:
790 // [optional integer/string id], control name, title, style, name, x, y, width, height
792 wxString controlType
;
797 long windowStyle
= 0;
798 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
801 wxExpr
*expr1
= expr
->Nth(0);
803 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
805 if ( wxIsValidControlClass(expr1
->StringValue()) )
808 controlType
= expr1
->StringValue();
812 wxString
str(expr1
->StringValue());
813 id
= wxResourceGetIdentifier(str
, &table
);
816 wxLogWarning(_("Could not resolve control class or id '%s'. Use (non-zero) integer instead\n or provide #define (see manual for caveats)"),
817 (const wxChar
*) expr1
->StringValue());
819 return (wxItemResource
*) NULL
;
823 // Success - we have an id, so the 2nd element must be the control class.
824 controlType
= expr
->Nth(1)->StringValue();
829 else if (expr1
->Type() == PrologInteger
)
831 id
= (int)expr1
->IntegerValue();
832 // Success - we have an id, so the 2nd element must be the control class.
833 controlType
= expr
->Nth(1)->StringValue();
837 expr1
= expr
->Nth(count
);
840 title
= expr1
->StringValue();
842 expr1
= expr
->Nth(count
);
846 style
= expr1
->StringValue();
847 windowStyle
= wxParseWindowStyle(style
);
850 expr1
= expr
->Nth(count
);
853 name
= expr1
->StringValue();
855 expr1
= expr
->Nth(count
);
858 x
= (int)expr1
->IntegerValue();
860 expr1
= expr
->Nth(count
);
863 y
= (int)expr1
->IntegerValue();
865 expr1
= expr
->Nth(count
);
868 width
= (int)expr1
->IntegerValue();
870 expr1
= expr
->Nth(count
);
873 height
= (int)expr1
->IntegerValue();
875 controlItem
->SetStyle(windowStyle
);
876 controlItem
->SetName(name
);
877 controlItem
->SetTitle(title
);
878 controlItem
->SetSize(x
, y
, width
, height
);
879 controlItem
->SetType(controlType
);
880 controlItem
->SetId(id
);
882 // Check for wxWin 1.68-style specifications
883 if (style
.Find(wxT("VERTICAL_LABEL")) != -1)
884 controlItem
->SetResourceStyle(controlItem
->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL
);
885 else if (style
.Find(wxT("HORIZONTAL_LABEL")) != -1)
886 controlItem
->SetResourceStyle(controlItem
->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL
);
888 if (controlType
== wxT("wxButton"))
890 // Check for bitmap resource name (in case loading old-style resource file)
891 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
893 wxString
str(expr
->Nth(count
)->StringValue());
898 controlItem
->SetValue4(str
);
899 controlItem
->SetType(wxT("wxBitmapButton"));
902 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
903 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
905 else if (controlType
== wxT("wxBitmapButton"))
907 // Check for bitmap resource name
908 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
910 wxString
str(expr
->Nth(count
)->StringValue());
911 controlItem
->SetValue4(str
);
913 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
914 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
917 else if (controlType
== wxT("wxCheckBox"))
919 // Check for default value
920 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
922 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
924 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
925 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
929 else if (controlType
== wxT("wxRadioButton"))
931 // Check for default value
932 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
934 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
936 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
937 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
941 else if (controlType
== wxT("wxText") || controlType
== wxT("wxTextCtrl") || controlType
== wxT("wxMultiText"))
943 // Check for default value
944 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
946 wxString
str(expr
->Nth(count
)->StringValue());
947 controlItem
->SetValue4(str
);
950 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
952 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
953 // Skip past the obsolete label font spec if there are two consecutive specs
954 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
956 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
960 else if (controlType
== wxT("wxMessage") || controlType
== wxT("wxStaticText"))
962 // Check for bitmap resource name (in case it's an old-style .wxr file)
963 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
965 wxString
str(expr
->Nth(count
)->StringValue());
966 controlItem
->SetValue4(str
);
968 controlItem
->SetType(wxT("wxStaticText"));
970 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
971 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
973 else if (controlType
== wxT("wxStaticBitmap"))
975 // Check for bitmap resource name
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
);
982 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
983 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
985 else if (controlType
== wxT("wxGroupBox") || controlType
== wxT("wxStaticBox"))
987 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
988 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
990 else if (controlType
== wxT("wxGauge"))
992 // Check for default value
993 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
995 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
999 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1001 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1004 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1006 // Skip past the obsolete label font spec if there are two consecutive specs
1007 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1009 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1014 else if (controlType
== wxT("wxSlider"))
1016 // Check for default value
1017 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1019 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1023 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1025 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1029 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1031 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1034 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1036 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1040 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1041 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1047 else if (controlType
== wxT("wxScrollBar"))
1050 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1052 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1056 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1058 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1062 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1064 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1068 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1069 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
1074 else if (controlType
== wxT("wxListBox"))
1076 wxExpr
*valueList
= (wxExpr
*) NULL
;
1078 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1080 wxStringList stringList
;
1081 wxExpr
*stringExpr
= valueList
->GetFirst();
1084 stringList
.Add(stringExpr
->StringValue());
1085 stringExpr
= stringExpr
->GetNext();
1087 controlItem
->SetStringValues(stringList
);
1089 // This is now obsolete: it's in the window style.
1090 // Check for wxSINGLE/wxMULTIPLE
1091 wxExpr
*mult
= (wxExpr
*) NULL
;
1093 controlItem->SetValue1(wxLB_SINGLE);
1095 if (((mult
= expr
->Nth(count
)) != 0) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1098 wxString m(mult->StringValue());
1099 if (m == "wxLB_MULTIPLE")
1100 controlItem->SetValue1(wxLB_MULTIPLE);
1101 else if (m == "wxLB_EXTENDED")
1102 controlItem->SetValue1(wxLB_EXTENDED);
1107 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1109 // Skip past the obsolete label font spec if there are two consecutive specs
1110 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1112 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1116 else if (controlType
== wxT("wxChoice"))
1118 wxExpr
*valueList
= (wxExpr
*) NULL
;
1119 // Check for default value list
1120 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1122 wxStringList stringList
;
1123 wxExpr
*stringExpr
= valueList
->GetFirst();
1126 stringList
.Add(stringExpr
->StringValue());
1127 stringExpr
= stringExpr
->GetNext();
1129 controlItem
->SetStringValues(stringList
);
1133 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1135 // Skip past the obsolete label font spec if there are two consecutive specs
1136 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1138 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1143 else if (controlType
== wxT("wxComboBox"))
1145 wxExpr
*textValue
= expr
->Nth(count
);
1146 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1148 wxString
str(textValue
->StringValue());
1149 controlItem
->SetValue4(str
);
1153 wxExpr
*valueList
= (wxExpr
*) NULL
;
1154 // Check for default value list
1155 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1157 wxStringList stringList
;
1158 wxExpr
*stringExpr
= valueList
->GetFirst();
1161 stringList
.Add(stringExpr
->StringValue());
1162 stringExpr
= stringExpr
->GetNext();
1164 controlItem
->SetStringValues(stringList
);
1168 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1170 // Skip past the obsolete label font spec if there are two consecutive specs
1171 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1173 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1180 else if (controlType
== wxT("wxRadioBox"))
1182 wxExpr
*valueList
= (wxExpr
*) NULL
;
1183 // Check for default value list
1184 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1186 wxStringList stringList
;
1187 wxExpr
*stringExpr
= valueList
->GetFirst();
1190 stringList
.Add(stringExpr
->StringValue());
1191 stringExpr
= stringExpr
->GetNext();
1193 controlItem
->SetStringValues(stringList
);
1196 // majorDim (number of rows or cols)
1197 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1199 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1203 controlItem
->SetValue1(0);
1205 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1207 // Skip past the obsolete label font spec if there are two consecutive specs
1208 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1210 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1218 return (wxItemResource
*) NULL
;
1223 // Forward declaration
1224 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, wxExpr
*expr
);
1227 * Interpet a menu item
1230 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, wxExpr
*expr
)
1232 wxItemResource
*item
= new wxItemResource
;
1234 wxExpr
*labelExpr
= expr
->Nth(0);
1235 wxExpr
*idExpr
= expr
->Nth(1);
1236 wxExpr
*helpExpr
= expr
->Nth(2);
1237 wxExpr
*checkableExpr
= expr
->Nth(3);
1239 // Further keywords/attributes to follow sometime...
1240 if (expr
->Number() == 0)
1242 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1243 item
->SetType(wxT("wxMenuSeparator"));
1248 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1249 item
->SetType(wxT("wxMenu")); // Well, menu item, but doesn't matter.
1252 wxString
str(labelExpr
->StringValue());
1253 item
->SetTitle(str
);
1258 // If a string or word, must look up in identifier table.
1259 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1261 wxString
str(idExpr
->StringValue());
1262 id
= wxResourceGetIdentifier(str
, &table
);
1265 wxLogWarning(_("Could not resolve menu id '%s'. Use (non-zero) integer instead\nor provide #define (see manual for caveats)"),
1266 (const wxChar
*) idExpr
->StringValue());
1269 else if (idExpr
->Type() == PrologInteger
)
1270 id
= (int)idExpr
->IntegerValue();
1271 item
->SetValue1(id
);
1275 wxString
str(helpExpr
->StringValue());
1276 item
->SetValue4(str
);
1279 item
->SetValue2(checkableExpr
->IntegerValue());
1281 // Find the first expression that's a list, for submenu
1282 wxExpr
*subMenuExpr
= expr
->GetFirst();
1283 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1284 subMenuExpr
= subMenuExpr
->GetNext();
1288 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1289 item
->GetChildren().Append(child
);
1290 subMenuExpr
= subMenuExpr
->GetNext();
1297 * Interpret a nested list as a menu
1300 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1302 wxItemResource *menu = new wxItemResource;
1303 // menu->SetType(wxTYPE_MENU);
1304 menu->SetType("wxMenu");
1305 wxExpr *element = expr->GetFirst();
1308 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1310 menu->GetChildren().Append(item);
1311 element = element->GetNext();
1317 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
)
1319 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1320 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1322 return (wxItemResource
*) NULL
;
1324 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1327 return (wxItemResource
*) NULL
;
1330 if (expr
->GetAttributeValue(wxT("name"), name
))
1332 menuResource
->SetName(name
);
1335 return menuResource
;
1338 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
)
1340 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1341 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1343 return (wxItemResource
*) NULL
;
1345 wxItemResource
*resource
= new wxItemResource
;
1346 resource
->SetType(wxT("wxMenu"));
1347 // resource->SetType(wxTYPE_MENU);
1349 wxExpr
*element
= listExpr
->GetFirst();
1352 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1353 resource
->GetChildren().Append(menuResource
);
1354 element
= element
->GetNext();
1358 if (expr
->GetAttributeValue(wxT("name"), name
))
1360 resource
->SetName(name
);
1366 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), wxExpr
*WXUNUSED(expr
))
1368 return (wxItemResource
*) NULL
;
1371 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), wxExpr
*expr
)
1373 wxItemResource
*bitmapItem
= new wxItemResource
;
1374 // bitmapItem->SetType(wxTYPE_BITMAP);
1375 bitmapItem
->SetType(wxT("wxBitmap"));
1377 if (expr
->GetAttributeValue(wxT("name"), name
))
1379 bitmapItem
->SetName(name
);
1381 // Now parse all bitmap specifications
1382 wxExpr
*bitmapExpr
= expr
->GetFirst();
1385 if (bitmapExpr
->Number() == 3)
1387 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1388 if (bitmapKeyword
== wxT("bitmap") || bitmapKeyword
== wxT("icon"))
1390 // The value part: always a list.
1391 wxExpr
*listExpr
= bitmapExpr
->Nth(2);
1392 if (listExpr
->Type() == PrologList
)
1394 wxItemResource
*bitmapSpec
= new wxItemResource
;
1395 // bitmapSpec->SetType(wxTYPE_BITMAP);
1396 bitmapSpec
->SetType(wxT("wxBitmap"));
1398 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1399 // where everything after 'filename' is optional.
1400 wxExpr
*nameExpr
= listExpr
->Nth(0);
1401 wxExpr
*typeExpr
= listExpr
->Nth(1);
1402 wxExpr
*platformExpr
= listExpr
->Nth(2);
1403 wxExpr
*coloursExpr
= listExpr
->Nth(3);
1404 wxExpr
*xresExpr
= listExpr
->Nth(4);
1405 wxExpr
*yresExpr
= listExpr
->Nth(5);
1406 if (nameExpr
&& nameExpr
->StringValue() != wxT(""))
1408 bitmapSpec
->SetName(nameExpr
->StringValue());
1410 if (typeExpr
&& typeExpr
->StringValue() != wxT(""))
1412 bitmapSpec
->SetValue1(wxParseWindowStyle(typeExpr
->StringValue()));
1415 bitmapSpec
->SetValue1(0);
1417 if (platformExpr
&& platformExpr
->StringValue() != wxT(""))
1419 wxString
plat(platformExpr
->StringValue());
1420 if (plat
== wxT("windows") || plat
== wxT("WINDOWS"))
1421 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1422 else if (plat
== wxT("x") || plat
== wxT("X"))
1423 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1424 else if (plat
== wxT("mac") || plat
== wxT("MAC"))
1425 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1427 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1430 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1433 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1437 xres
= (int)xresExpr
->IntegerValue();
1439 yres
= (int)yresExpr
->IntegerValue();
1440 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1442 bitmapItem
->GetChildren().Append(bitmapSpec
);
1446 bitmapExpr
= bitmapExpr
->GetNext();
1452 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
)
1454 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1457 // item->SetType(wxTYPE_ICON);
1458 item
->SetType(wxT("wxIcon"));
1462 return (wxItemResource
*) NULL
;
1465 // Interpret list expression as a font
1466 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
)
1468 if (expr
->Type() != PrologList
)
1472 int family
= wxSWISS
;
1473 int style
= wxNORMAL
;
1474 int weight
= wxNORMAL
;
1476 wxString
faceName(wxT(""));
1478 wxExpr
*pointExpr
= expr
->Nth(0);
1479 wxExpr
*familyExpr
= expr
->Nth(1);
1480 wxExpr
*styleExpr
= expr
->Nth(2);
1481 wxExpr
*weightExpr
= expr
->Nth(3);
1482 wxExpr
*underlineExpr
= expr
->Nth(4);
1483 wxExpr
*faceNameExpr
= expr
->Nth(5);
1485 point
= (int)pointExpr
->IntegerValue();
1490 str
= familyExpr
->StringValue();
1491 family
= (int)wxParseWindowStyle(str
);
1495 str
= styleExpr
->StringValue();
1496 style
= (int)wxParseWindowStyle(str
);
1500 str
= weightExpr
->StringValue();
1501 weight
= (int)wxParseWindowStyle(str
);
1504 underline
= (int)underlineExpr
->IntegerValue();
1506 faceName
= faceNameExpr
->StringValue();
1508 return *wxTheFontList
->FindOrCreateFont(point
, family
, style
, weight
,
1509 (underline
!= 0), faceName
);
1513 * (Re)allocate buffer for reading in from resource file
1516 bool wxReallocateResourceBuffer()
1518 if (!wxResourceBuffer
)
1520 wxResourceBufferSize
= 1000;
1521 wxResourceBuffer
= new char[wxResourceBufferSize
];
1524 if (wxResourceBuffer
)
1526 long newSize
= wxResourceBufferSize
+ 1000;
1527 char *tmp
= new char[(int)newSize
];
1528 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1529 delete[] wxResourceBuffer
;
1530 wxResourceBuffer
= tmp
;
1531 wxResourceBufferSize
= newSize
;
1536 static bool wxEatWhiteSpace(FILE *fd
)
1540 while ((ch
= getc(fd
)) != EOF
)
1555 ungetc(prev_ch
, fd
);
1563 while ((ch
= getc(fd
)) != EOF
)
1565 if (ch
== '/' && prev_ch
== '*')
1573 static char buffer
[255];
1574 fgets(buffer
, 255, fd
);
1578 ungetc(prev_ch
, fd
);
1592 static bool wxEatWhiteSpace(wxInputStream
*is
)
1594 int ch
= is
->GetC() ;
1595 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
1602 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
1604 // Check for comment
1610 bool finished
= FALSE
;
1618 int newCh
= is
->GetC();
1633 return wxEatWhiteSpace(is
);
1636 bool wxGetResourceToken(FILE *fd
)
1638 if (!wxResourceBuffer
)
1639 wxReallocateResourceBuffer();
1640 wxResourceBuffer
[0] = 0;
1641 wxEatWhiteSpace(fd
);
1647 wxResourceBufferCount
= 0;
1654 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1657 // Escaped characters
1658 else if (ch
== '\\')
1660 int newCh
= getc(fd
);
1663 else if (newCh
== 10)
1671 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1672 wxReallocateResourceBuffer();
1673 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1674 wxResourceBufferCount
++;
1677 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1681 wxResourceBufferCount
= 0;
1683 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1685 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1686 wxReallocateResourceBuffer();
1687 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1688 wxResourceBufferCount
++;
1692 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1699 bool wxGetResourceToken(wxInputStream
*is
)
1701 if (!wxResourceBuffer
)
1702 wxReallocateResourceBuffer();
1703 wxResourceBuffer
[0] = 0;
1704 wxEatWhiteSpace(is
);
1706 int ch
= is
->GetC() ;
1710 wxResourceBufferCount
= 0;
1717 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1720 // Escaped characters
1721 else if (ch
== '\\')
1723 int newCh
= is
->GetC();
1726 else if (newCh
== 10)
1728 else if (newCh
== 13) // mac
1736 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1737 wxReallocateResourceBuffer();
1738 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1739 wxResourceBufferCount
++;
1742 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1746 wxResourceBufferCount
= 0;
1748 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1750 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1751 wxReallocateResourceBuffer();
1752 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1753 wxResourceBufferCount
++;
1757 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1765 * Files are in form:
1766 static char *name = "....";
1767 with possible comments.
1770 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1773 table
= wxDefaultResourceTable
;
1775 // static or #define
1776 if (!wxGetResourceToken(fd
))
1782 if (strcmp(wxResourceBuffer
, "#define") == 0)
1784 wxGetResourceToken(fd
);
1785 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1786 wxGetResourceToken(fd
);
1787 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1788 if (wxIsdigit(value
[0]))
1790 int val
= (int)wxAtol(value
);
1791 wxResourceAddIdentifier(name
, val
, table
);
1795 wxLogWarning(_("#define %s must be an integer."), name
);
1805 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1807 wxGetResourceToken(fd
);
1808 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1809 wxChar
*actualName
= name
;
1810 if (name
[0] == wxT('"'))
1811 actualName
= name
+ 1;
1812 int len
= wxStrlen(name
);
1813 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1815 if (!wxResourceParseIncludeFile(actualName
, table
))
1817 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1822 else if (strcmp(wxResourceBuffer
, "static") != 0)
1825 wxStrcpy(buf
, _("Found "));
1826 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
1827 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1833 if (!wxGetResourceToken(fd
))
1835 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1840 if (strcmp(wxResourceBuffer
, "char") != 0)
1842 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1847 if (!wxGetResourceToken(fd
))
1849 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1854 if (wxResourceBuffer
[0] != '*')
1856 wxLogWarning(_("Expected '*' whilst parsing resource."));
1859 wxChar nameBuf
[100];
1860 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
1864 if (!wxGetResourceToken(fd
))
1866 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1871 if (strcmp(wxResourceBuffer
, "=") != 0)
1873 wxLogWarning(_("Expected '=' whilst parsing resource."));
1878 if (!wxGetResourceToken(fd
))
1880 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1886 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1888 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1893 if (!wxGetResourceToken(fd
))
1900 bool wxResourceReadOneResource(wxInputStream
*fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1903 table
= wxDefaultResourceTable
;
1905 // static or #define
1906 if (!wxGetResourceToken(fd
))
1912 if (strcmp(wxResourceBuffer
, "#define") == 0)
1914 wxGetResourceToken(fd
);
1915 wxChar
*name
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1916 wxGetResourceToken(fd
);
1917 wxChar
*value
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1918 if (wxIsalpha(value
[0]))
1920 int val
= (int)wxAtol(value
);
1921 wxResourceAddIdentifier(name
, val
, table
);
1925 wxLogWarning(_("#define %s must be an integer."), name
);
1935 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1937 wxGetResourceToken(fd
);
1938 wxChar
*name
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1939 wxChar
*actualName
= name
;
1940 if (name
[0] == wxT('"'))
1941 actualName
= name
+ 1;
1942 int len
= wxStrlen(name
);
1943 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1945 if (!wxResourceParseIncludeFile(actualName
, table
))
1947 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1952 else if (strcmp(wxResourceBuffer
, "static") != 0)
1955 wxStrcpy(buf
, _("Found "));
1956 wxStrncat(buf
, wxConvLibc
.cMB2WX(wxResourceBuffer
), 30);
1957 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1963 if (!wxGetResourceToken(fd
))
1965 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1970 if (strcmp(wxResourceBuffer
, "char") != 0)
1972 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1977 if (!wxGetResourceToken(fd
))
1979 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1984 if (wxResourceBuffer
[0] != '*')
1986 wxLogWarning(_("Expected '*' whilst parsing resource."));
1990 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
1993 if (!wxGetResourceToken(fd
))
1995 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2000 if (strcmp(wxResourceBuffer
, "=") != 0)
2002 wxLogWarning(_("Expected '=' whilst parsing resource."));
2007 if (!wxGetResourceToken(fd
))
2009 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2015 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2017 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2022 if (!wxGetResourceToken(fd
))
2030 * Parses string window style into integer window style
2034 * Style flag parsing, e.g.
2035 * "wxSYSTEM_MENU | wxBORDER" -> integer
2038 wxChar
* wxResourceParseWord(wxChar
*s
, int *i
)
2041 return (wxChar
*) NULL
;
2043 static wxChar buf
[150];
2044 int len
= wxStrlen(s
);
2047 while ((ii
< len
) && (wxIsalpha(s
[ii
]) || (s
[ii
] == wxT('_'))))
2055 // Eat whitespace and conjunction characters
2056 while ((ii
< len
) &&
2057 ((s
[ii
] == wxT(' ')) || (s
[ii
] == wxT('|')) || (s
[ii
] == wxT(','))))
2063 return (wxChar
*) NULL
;
2068 struct wxResourceBitListStruct
2074 static wxResourceBitListStruct wxResourceBitListTable
[] =
2077 { wxT("wxSINGLE"), wxLB_SINGLE
},
2078 { wxT("wxMULTIPLE"), wxLB_MULTIPLE
},
2079 { wxT("wxEXTENDED"), wxLB_EXTENDED
},
2080 { wxT("wxLB_SINGLE"), wxLB_SINGLE
},
2081 { wxT("wxLB_MULTIPLE"), wxLB_MULTIPLE
},
2082 { wxT("wxLB_EXTENDED"), wxLB_EXTENDED
},
2083 { wxT("wxLB_NEEDED_SB"), wxLB_NEEDED_SB
},
2084 { wxT("wxLB_ALWAYS_SB"), wxLB_ALWAYS_SB
},
2085 { wxT("wxLB_SORT"), wxLB_SORT
},
2086 { wxT("wxLB_OWNERDRAW"), wxLB_OWNERDRAW
},
2087 { wxT("wxLB_HSCROLL"), wxLB_HSCROLL
},
2090 { wxT("wxCB_SIMPLE"), wxCB_SIMPLE
},
2091 { wxT("wxCB_DROPDOWN"), wxCB_DROPDOWN
},
2092 { wxT("wxCB_READONLY"), wxCB_READONLY
},
2093 { wxT("wxCB_SORT"), wxCB_SORT
},
2096 { wxT("wxGA_PROGRESSBAR"), wxGA_PROGRESSBAR
},
2097 { wxT("wxGA_HORIZONTAL"), wxGA_HORIZONTAL
},
2098 { wxT("wxGA_VERTICAL"), wxGA_VERTICAL
},
2101 { wxT("wxPASSWORD"), wxPASSWORD
},
2102 { wxT("wxPROCESS_ENTER"), wxPROCESS_ENTER
},
2103 { wxT("wxTE_PASSWORD"), wxTE_PASSWORD
},
2104 { wxT("wxTE_READONLY"), wxTE_READONLY
},
2105 { wxT("wxTE_PROCESS_ENTER"), wxTE_PROCESS_ENTER
},
2106 { wxT("wxTE_MULTILINE"), wxTE_MULTILINE
},
2107 { wxT("wxTE_NO_VSCROLL"), wxTE_NO_VSCROLL
},
2109 /* wxRadioBox/wxRadioButton */
2110 { wxT("wxRB_GROUP"), wxRB_GROUP
},
2111 { wxT("wxRA_SPECIFY_COLS"), wxRA_SPECIFY_COLS
},
2112 { wxT("wxRA_SPECIFY_ROWS"), wxRA_SPECIFY_ROWS
},
2113 { wxT("wxRA_HORIZONTAL"), wxRA_HORIZONTAL
},
2114 { wxT("wxRA_VERTICAL"), wxRA_VERTICAL
},
2117 { wxT("wxSL_HORIZONTAL"), wxSL_HORIZONTAL
},
2118 { wxT("wxSL_VERTICAL"), wxSL_VERTICAL
},
2119 { wxT("wxSL_AUTOTICKS"), wxSL_AUTOTICKS
},
2120 { wxT("wxSL_LABELS"), wxSL_LABELS
},
2121 { wxT("wxSL_LEFT"), wxSL_LEFT
},
2122 { wxT("wxSL_TOP"), wxSL_TOP
},
2123 { wxT("wxSL_RIGHT"), wxSL_RIGHT
},
2124 { wxT("wxSL_BOTTOM"), wxSL_BOTTOM
},
2125 { wxT("wxSL_BOTH"), wxSL_BOTH
},
2126 { wxT("wxSL_SELRANGE"), wxSL_SELRANGE
},
2129 { wxT("wxSB_HORIZONTAL"), wxSB_HORIZONTAL
},
2130 { wxT("wxSB_VERTICAL"), wxSB_VERTICAL
},
2133 { wxT("wxBU_AUTODRAW"), wxBU_AUTODRAW
},
2134 { wxT("wxBU_NOAUTODRAW"), wxBU_NOAUTODRAW
},
2137 { wxT("wxTR_HAS_BUTTONS"), wxTR_HAS_BUTTONS
},
2138 { wxT("wxTR_EDIT_LABELS"), wxTR_EDIT_LABELS
},
2139 { wxT("wxTR_LINES_AT_ROOT"), wxTR_LINES_AT_ROOT
},
2142 { wxT("wxLC_ICON"), wxLC_ICON
},
2143 { wxT("wxLC_SMALL_ICON"), wxLC_SMALL_ICON
},
2144 { wxT("wxLC_LIST"), wxLC_LIST
},
2145 { wxT("wxLC_REPORT"), wxLC_REPORT
},
2146 { wxT("wxLC_ALIGN_TOP"), wxLC_ALIGN_TOP
},
2147 { wxT("wxLC_ALIGN_LEFT"), wxLC_ALIGN_LEFT
},
2148 { wxT("wxLC_AUTOARRANGE"), wxLC_AUTOARRANGE
},
2149 { wxT("wxLC_USER_TEXT"), wxLC_USER_TEXT
},
2150 { wxT("wxLC_EDIT_LABELS"), wxLC_EDIT_LABELS
},
2151 { wxT("wxLC_NO_HEADER"), wxLC_NO_HEADER
},
2152 { wxT("wxLC_NO_SORT_HEADER"), wxLC_NO_SORT_HEADER
},
2153 { wxT("wxLC_SINGLE_SEL"), wxLC_SINGLE_SEL
},
2154 { wxT("wxLC_SORT_ASCENDING"), wxLC_SORT_ASCENDING
},
2155 { wxT("wxLC_SORT_DESCENDING"), wxLC_SORT_DESCENDING
},
2158 { wxT("wxSP_VERTICAL"), wxSP_VERTICAL
},
2159 { wxT("wxSP_HORIZONTAL"), wxSP_HORIZONTAL
},
2160 { wxT("wxSP_ARROW_KEYS"), wxSP_ARROW_KEYS
},
2161 { wxT("wxSP_WRAP"), wxSP_WRAP
},
2164 { wxT("wxSP_NOBORDER"), wxSP_NOBORDER
},
2165 { wxT("wxSP_3D"), wxSP_3D
},
2166 { wxT("wxSP_BORDER"), wxSP_BORDER
},
2169 { wxT("wxTC_MULTILINE"), wxTC_MULTILINE
},
2170 { wxT("wxTC_RIGHTJUSTIFY"), wxTC_RIGHTJUSTIFY
},
2171 { wxT("wxTC_FIXEDWIDTH"), wxTC_FIXEDWIDTH
},
2172 { wxT("wxTC_OWNERDRAW"), wxTC_OWNERDRAW
},
2175 { wxT("wxST_SIZEGRIP"), wxST_SIZEGRIP
},
2178 { wxT("wxFIXED_LENGTH"), wxFIXED_LENGTH
},
2179 { wxT("wxALIGN_LEFT"), wxALIGN_LEFT
},
2180 { wxT("wxALIGN_CENTER"), wxALIGN_CENTER
},
2181 { wxT("wxALIGN_CENTRE"), wxALIGN_CENTRE
},
2182 { wxT("wxALIGN_RIGHT"), wxALIGN_RIGHT
},
2183 { wxT("wxCOLOURED"), wxCOLOURED
},
2186 { wxT("wxTB_3DBUTTONS"), wxTB_3DBUTTONS
},
2187 { wxT("wxTB_HORIZONTAL"), wxTB_HORIZONTAL
},
2188 { wxT("wxTB_VERTICAL"), wxTB_VERTICAL
},
2189 { wxT("wxTB_FLAT"), wxTB_FLAT
},
2192 { wxT("wxDIALOG_MODAL"), wxDIALOG_MODAL
},
2195 { wxT("wxVSCROLL"), wxVSCROLL
},
2196 { wxT("wxHSCROLL"), wxHSCROLL
},
2197 { wxT("wxCAPTION"), wxCAPTION
},
2198 { wxT("wxSTAY_ON_TOP"), wxSTAY_ON_TOP
},
2199 { wxT("wxICONIZE"), wxICONIZE
},
2200 { wxT("wxMINIMIZE"), wxICONIZE
},
2201 { wxT("wxMAXIMIZE"), wxMAXIMIZE
},
2203 { wxT("wxMDI_PARENT"), 0},
2204 { wxT("wxMDI_CHILD"), 0},
2205 { wxT("wxTHICK_FRAME"), wxTHICK_FRAME
},
2206 { wxT("wxRESIZE_BORDER"), wxRESIZE_BORDER
},
2207 { wxT("wxSYSTEM_MENU"), wxSYSTEM_MENU
},
2208 { wxT("wxMINIMIZE_BOX"), wxMINIMIZE_BOX
},
2209 { wxT("wxMAXIMIZE_BOX"), wxMAXIMIZE_BOX
},
2210 { wxT("wxRESIZE_BOX"), wxRESIZE_BOX
},
2211 { wxT("wxDEFAULT_FRAME_STYLE"), wxDEFAULT_FRAME_STYLE
},
2212 { wxT("wxDEFAULT_FRAME"), wxDEFAULT_FRAME_STYLE
},
2213 { wxT("wxDEFAULT_DIALOG_STYLE"), wxDEFAULT_DIALOG_STYLE
},
2214 { wxT("wxBORDER"), wxBORDER
},
2215 { wxT("wxRETAINED"), wxRETAINED
},
2216 { wxT("wxNATIVE_IMPL"), 0},
2217 { wxT("wxEXTENDED_IMPL"), 0},
2218 { wxT("wxBACKINGSTORE"), wxBACKINGSTORE
},
2219 // { wxT("wxFLAT"), wxFLAT},
2220 // { wxT("wxMOTIF_RESIZE"), wxMOTIF_RESIZE},
2221 { wxT("wxFIXED_LENGTH"), 0},
2222 { wxT("wxDOUBLE_BORDER"), wxDOUBLE_BORDER
},
2223 { wxT("wxSUNKEN_BORDER"), wxSUNKEN_BORDER
},
2224 { wxT("wxRAISED_BORDER"), wxRAISED_BORDER
},
2225 { wxT("wxSIMPLE_BORDER"), wxSIMPLE_BORDER
},
2226 { wxT("wxSTATIC_BORDER"), wxSTATIC_BORDER
},
2227 { wxT("wxTRANSPARENT_WINDOW"), wxTRANSPARENT_WINDOW
},
2228 { wxT("wxNO_BORDER"), wxNO_BORDER
},
2229 { wxT("wxCLIP_CHILDREN"), wxCLIP_CHILDREN
},
2230 { wxT("wxCLIP_SIBLINGS"), wxCLIP_SIBLINGS
},
2231 { wxT("wxTAB_TRAVERSAL"), 0}, // Compatibility only
2233 { wxT("wxTINY_CAPTION_HORIZ"), wxTINY_CAPTION_HORIZ
},
2234 { wxT("wxTINY_CAPTION_VERT"), wxTINY_CAPTION_VERT
},
2236 // Text font families
2237 { wxT("wxDEFAULT"), wxDEFAULT
},
2238 { wxT("wxDECORATIVE"), wxDECORATIVE
},
2239 { wxT("wxROMAN"), wxROMAN
},
2240 { wxT("wxSCRIPT"), wxSCRIPT
},
2241 { wxT("wxSWISS"), wxSWISS
},
2242 { wxT("wxMODERN"), wxMODERN
},
2243 { wxT("wxTELETYPE"), wxTELETYPE
},
2244 { wxT("wxVARIABLE"), wxVARIABLE
},
2245 { wxT("wxFIXED"), wxFIXED
},
2246 { wxT("wxNORMAL"), wxNORMAL
},
2247 { wxT("wxLIGHT"), wxLIGHT
},
2248 { wxT("wxBOLD"), wxBOLD
},
2249 { wxT("wxITALIC"), wxITALIC
},
2250 { wxT("wxSLANT"), wxSLANT
},
2251 { wxT("wxSOLID"), wxSOLID
},
2252 { wxT("wxDOT"), wxDOT
},
2253 { wxT("wxLONG_DASH"), wxLONG_DASH
},
2254 { wxT("wxSHORT_DASH"), wxSHORT_DASH
},
2255 { wxT("wxDOT_DASH"), wxDOT_DASH
},
2256 { wxT("wxUSER_DASH"), wxUSER_DASH
},
2257 { wxT("wxTRANSPARENT"), wxTRANSPARENT
},
2258 { wxT("wxSTIPPLE"), wxSTIPPLE
},
2259 { wxT("wxBDIAGONAL_HATCH"), wxBDIAGONAL_HATCH
},
2260 { wxT("wxCROSSDIAG_HATCH"), wxCROSSDIAG_HATCH
},
2261 { wxT("wxFDIAGONAL_HATCH"), wxFDIAGONAL_HATCH
},
2262 { wxT("wxCROSS_HATCH"), wxCROSS_HATCH
},
2263 { wxT("wxHORIZONTAL_HATCH"), wxHORIZONTAL_HATCH
},
2264 { wxT("wxVERTICAL_HATCH"), wxVERTICAL_HATCH
},
2265 { wxT("wxJOIN_BEVEL"), wxJOIN_BEVEL
},
2266 { wxT("wxJOIN_MITER"), wxJOIN_MITER
},
2267 { wxT("wxJOIN_ROUND"), wxJOIN_ROUND
},
2268 { wxT("wxCAP_ROUND"), wxCAP_ROUND
},
2269 { wxT("wxCAP_PROJECTING"), wxCAP_PROJECTING
},
2270 { wxT("wxCAP_BUTT"), wxCAP_BUTT
},
2273 { wxT("wxCLEAR"), wxCLEAR
},
2274 { wxT("wxXOR"), wxXOR
},
2275 { wxT("wxINVERT"), wxINVERT
},
2276 { wxT("wxOR_REVERSE"), wxOR_REVERSE
},
2277 { wxT("wxAND_REVERSE"), wxAND_REVERSE
},
2278 { wxT("wxCOPY"), wxCOPY
},
2279 { wxT("wxAND"), wxAND
},
2280 { wxT("wxAND_INVERT"), wxAND_INVERT
},
2281 { wxT("wxNO_OP"), wxNO_OP
},
2282 { wxT("wxNOR"), wxNOR
},
2283 { wxT("wxEQUIV"), wxEQUIV
},
2284 { wxT("wxSRC_INVERT"), wxSRC_INVERT
},
2285 { wxT("wxOR_INVERT"), wxOR_INVERT
},
2286 { wxT("wxNAND"), wxNAND
},
2287 { wxT("wxOR"), wxOR
},
2288 { wxT("wxSET"), wxSET
},
2290 { wxT("wxFLOOD_SURFACE"), wxFLOOD_SURFACE
},
2291 { wxT("wxFLOOD_BORDER"), wxFLOOD_BORDER
},
2292 { wxT("wxODDEVEN_RULE"), wxODDEVEN_RULE
},
2293 { wxT("wxWINDING_RULE"), wxWINDING_RULE
},
2294 { wxT("wxHORIZONTAL"), wxHORIZONTAL
},
2295 { wxT("wxVERTICAL"), wxVERTICAL
},
2296 { wxT("wxBOTH"), wxBOTH
},
2297 { wxT("wxCENTER_FRAME"), wxCENTER_FRAME
},
2298 { wxT("wxOK"), wxOK
},
2299 { wxT("wxYES_NO"), wxYES_NO
},
2300 { wxT("wxCANCEL"), wxCANCEL
},
2301 { wxT("wxYES"), wxYES
},
2302 { wxT("wxNO"), wxNO
},
2303 { wxT("wxICON_EXCLAMATION"), wxICON_EXCLAMATION
},
2304 { wxT("wxICON_HAND"), wxICON_HAND
},
2305 { wxT("wxICON_QUESTION"), wxICON_QUESTION
},
2306 { wxT("wxICON_INFORMATION"), wxICON_INFORMATION
},
2307 { wxT("wxICON_STOP"), wxICON_STOP
},
2308 { wxT("wxICON_ASTERISK"), wxICON_ASTERISK
},
2309 { wxT("wxICON_MASK"), wxICON_MASK
},
2310 { wxT("wxCENTRE"), wxCENTRE
},
2311 { wxT("wxCENTER"), wxCENTRE
},
2312 { wxT("wxUSER_COLOURS"), wxUSER_COLOURS
},
2313 { wxT("wxVERTICAL_LABEL"), 0},
2314 { wxT("wxHORIZONTAL_LABEL"), 0},
2316 // Bitmap types (not strictly styles)
2317 { wxT("wxBITMAP_TYPE_XPM"), wxBITMAP_TYPE_XPM
},
2318 { wxT("wxBITMAP_TYPE_XBM"), wxBITMAP_TYPE_XBM
},
2319 { wxT("wxBITMAP_TYPE_BMP"), wxBITMAP_TYPE_BMP
},
2320 { wxT("wxBITMAP_TYPE_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2321 { wxT("wxBITMAP_TYPE_BMP_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2322 { wxT("wxBITMAP_TYPE_GIF"), wxBITMAP_TYPE_GIF
},
2323 { wxT("wxBITMAP_TYPE_TIF"), wxBITMAP_TYPE_TIF
},
2324 { wxT("wxBITMAP_TYPE_ICO"), wxBITMAP_TYPE_ICO
},
2325 { wxT("wxBITMAP_TYPE_ICO_RESOURCE"), wxBITMAP_TYPE_ICO_RESOURCE
},
2326 { wxT("wxBITMAP_TYPE_CUR"), wxBITMAP_TYPE_CUR
},
2327 { wxT("wxBITMAP_TYPE_CUR_RESOURCE"), wxBITMAP_TYPE_CUR_RESOURCE
},
2328 { wxT("wxBITMAP_TYPE_XBM_DATA"), wxBITMAP_TYPE_XBM_DATA
},
2329 { wxT("wxBITMAP_TYPE_XPM_DATA"), wxBITMAP_TYPE_XPM_DATA
},
2330 { wxT("wxBITMAP_TYPE_ANY"), wxBITMAP_TYPE_ANY
}
2333 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
2335 long wxParseWindowStyle(const wxString
& bitListString
)
2340 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2341 while (word
!= NULL
)
2345 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2346 if (wxStrcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2348 bitList
|= wxResourceBitListTable
[j
].bits
;
2354 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word
);
2357 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2363 * Load a bitmap from a wxWindows resource, choosing an optimum
2364 * depth and appropriate type.
2367 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
2370 table
= wxDefaultResourceTable
;
2372 wxItemResource
*item
= table
->FindResource(resource
);
2375 if ((item
->GetType() == wxT("")) || (item
->GetType() != wxT("wxBitmap")))
2377 wxLogWarning(_("%s not a bitmap resource specification."), (const wxChar
*) resource
);
2378 return wxNullBitmap
;
2380 int thisDepth
= wxDisplayDepth();
2381 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2383 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2385 // Try to find optimum bitmap for this platform/colour depth
2386 wxNode
*node
= item
->GetChildren().First();
2389 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2390 int platform
= (int)child
->GetValue2();
2391 int noColours
= (int)child
->GetValue3();
2393 char *name = child->GetName();
2394 int bitmapType = (int)child->GetValue1();
2395 int xRes = child->GetWidth();
2396 int yRes = child->GetHeight();
2401 case RESOURCE_PLATFORM_ANY
:
2403 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2404 optResource
= child
;
2407 // Maximise the number of colours.
2408 // If noColours is zero (unspecified), then assume this
2409 // is the right one.
2410 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2411 optResource
= child
;
2416 case RESOURCE_PLATFORM_WINDOWS
:
2418 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2419 optResource
= child
;
2422 // Maximise the number of colours
2423 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2424 optResource
= child
;
2430 case RESOURCE_PLATFORM_X
:
2432 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2433 optResource
= child
;
2436 // Maximise the number of colours
2437 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2438 optResource
= child
;
2444 case RESOURCE_PLATFORM_MAC
:
2446 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2447 optResource
= child
;
2450 // Maximise the number of colours
2451 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2452 optResource
= child
;
2460 node
= node
->Next();
2462 // If no matching resource, fail.
2464 return wxNullBitmap
;
2466 wxString name
= optResource
->GetName();
2467 int bitmapType
= (int)optResource
->GetValue1();
2470 case wxBITMAP_TYPE_XBM_DATA
:
2473 wxItemResource
*item
= table
->FindResource(name
);
2476 wxLogWarning(_("Failed to find XBM resource %s.\n"
2477 "Forgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2478 return wxNullBitmap
;
2480 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2482 wxLogWarning(_("No XBM facility available!"));
2486 case wxBITMAP_TYPE_XPM_DATA
:
2488 wxItemResource
*item
= table
->FindResource(name
);
2491 wxLogWarning(_("Failed to find XPM resource %s.\nForgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2492 return wxNullBitmap
;
2494 return wxBitmap((char **)item
->GetValue1());
2498 #if defined(__WXPM__)
2499 return wxNullBitmap
;
2501 return wxBitmap(name
, (wxBitmapType
)bitmapType
);
2506 return wxNullBitmap
;
2511 wxLogWarning(_("Bitmap resource specification %s not found."), (const wxChar
*) resource
);
2512 return wxNullBitmap
;
2517 * Load an icon from a wxWindows resource, choosing an optimum
2518 * depth and appropriate type.
2521 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2524 table
= wxDefaultResourceTable
;
2526 wxItemResource
*item
= table
->FindResource(resource
);
2529 if ((item
->GetType() == wxT("")) || wxStrcmp(item
->GetType(), wxT("wxIcon")) != 0)
2531 wxLogWarning(_("%s not an icon resource specification."), (const wxChar
*) resource
);
2534 int thisDepth
= wxDisplayDepth();
2535 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2537 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2539 // Try to find optimum icon for this platform/colour depth
2540 wxNode
*node
= item
->GetChildren().First();
2543 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2544 int platform
= (int)child
->GetValue2();
2545 int noColours
= (int)child
->GetValue3();
2547 char *name = child->GetName();
2548 int bitmapType = (int)child->GetValue1();
2549 int xRes = child->GetWidth();
2550 int yRes = child->GetHeight();
2555 case RESOURCE_PLATFORM_ANY
:
2557 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2558 optResource
= child
;
2561 // Maximise the number of colours.
2562 // If noColours is zero (unspecified), then assume this
2563 // is the right one.
2564 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2565 optResource
= child
;
2570 case RESOURCE_PLATFORM_WINDOWS
:
2572 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2573 optResource
= child
;
2576 // Maximise the number of colours
2577 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2578 optResource
= child
;
2584 case RESOURCE_PLATFORM_X
:
2586 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2587 optResource
= child
;
2590 // Maximise the number of colours
2591 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2592 optResource
= child
;
2598 case RESOURCE_PLATFORM_MAC
:
2600 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2601 optResource
= child
;
2604 // Maximise the number of colours
2605 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2606 optResource
= child
;
2614 node
= node
->Next();
2616 // If no matching resource, fail.
2620 wxString name
= optResource
->GetName();
2621 int bitmapType
= (int)optResource
->GetValue1();
2624 case wxBITMAP_TYPE_XBM_DATA
:
2627 wxItemResource
*item
= table
->FindResource(name
);
2630 wxLogWarning(_("Failed to find XBM resource %s.\n"
2631 "Forgot to use wxResourceLoadIconData?"), (const wxChar
*) name
);
2634 return wxIcon((const char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2636 wxLogWarning(_("No XBM facility available!"));
2640 case wxBITMAP_TYPE_XPM_DATA
:
2642 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2644 wxItemResource *item = table->FindResource(name);
2648 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2652 return wxIcon((char **)item->GetValue1());
2654 wxLogWarning(_("No XPM icon facility available!"));
2659 #if defined( __WXGTK__ ) || defined( __WXMOTIF__ )
2660 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2663 return wxIcon(name
, bitmapType
);
2671 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2678 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2680 wxMenu
*menu
= new wxMenu
;
2681 wxNode
*node
= item
->GetChildren().First();
2684 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2685 if ((child
->GetType() != wxT("")) && (child
->GetType() == wxT("wxMenuSeparator")))
2686 menu
->AppendSeparator();
2687 else if (child
->GetChildren().Number() > 0)
2689 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2691 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2695 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2697 node
= node
->Next();
2702 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2705 table
= wxDefaultResourceTable
;
2707 wxItemResource
*menuResource
= table
->FindResource(resource
);
2708 if (menuResource
&& (menuResource
->GetType() != wxT("")) && (menuResource
->GetType() == wxT("wxMenu")))
2711 menuBar
= new wxMenuBar
;
2712 wxNode
*node
= menuResource
->GetChildren().First();
2715 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2716 wxMenu
*menu
= wxResourceCreateMenu(child
);
2718 menuBar
->Append(menu
, child
->GetTitle());
2719 node
= node
->Next();
2723 return (wxMenuBar
*) NULL
;
2726 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2729 table
= wxDefaultResourceTable
;
2731 wxItemResource
*menuResource
= table
->FindResource(resource
);
2732 if (menuResource
&& (menuResource
->GetType() != wxT("")) && (menuResource
->GetType() == wxT("wxMenu")))
2733 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2734 return wxResourceCreateMenu(menuResource
);
2735 return (wxMenu
*) NULL
;
2738 #endif // wxUSE_MENUS
2740 // Global equivalents (so don't have to refer to default table explicitly)
2741 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2744 table
= wxDefaultResourceTable
;
2746 return table
->ParseResourceData(resource
);
2749 bool wxResourceParseData(const char* resource
, wxResourceTable
*table
)
2751 wxString
str(resource
, wxConvLibc
);
2753 table
= wxDefaultResourceTable
;
2755 return table
->ParseResourceData(str
);
2758 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2761 table
= wxDefaultResourceTable
;
2763 return table
->ParseResourceFile(filename
);
2766 // Register XBM/XPM data
2767 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2770 table
= wxDefaultResourceTable
;
2772 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2775 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2778 table
= wxDefaultResourceTable
;
2780 return table
->RegisterResourceBitmapData(name
, data
);
2783 void wxResourceClear(wxResourceTable
*table
)
2786 table
= wxDefaultResourceTable
;
2788 table
->ClearTable();
2795 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2798 table
= wxDefaultResourceTable
;
2800 table
->identifiers
.Put(name
, (wxObject
*)(long)value
);
2804 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2807 table
= wxDefaultResourceTable
;
2809 return (int)(long)table
->identifiers
.Get(name
);
2813 * Parse #include file for #defines (only)
2816 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2819 table
= wxDefaultResourceTable
;
2821 FILE *fd
= wxFopen(f
, wxT("r"));
2826 while (wxGetResourceToken(fd
))
2828 if (strcmp(wxResourceBuffer
, "#define") == 0)
2830 wxGetResourceToken(fd
);
2831 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2832 wxGetResourceToken(fd
);
2833 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2834 if (wxIsdigit(value
[0]))
2836 int val
= (int)wxAtol(value
);
2837 wxResourceAddIdentifier(name
, val
, table
);
2848 * Reading strings as if they were .wxr files
2851 static int getc_string(char *s
)
2853 int ch
= s
[wxResourceStringPtr
];
2858 wxResourceStringPtr
++;
2863 static int ungetc_string()
2865 wxResourceStringPtr
--;
2869 bool wxEatWhiteSpaceString(char *s
)
2873 while ((ch
= getc_string(s
)) != EOF
)
2885 ch
= getc_string(s
);
2896 while ((ch
= getc_string(s
)) != EOF
)
2898 if (ch
== '/' && prev_ch
== '*')
2920 bool wxGetResourceTokenString(char *s
)
2922 if (!wxResourceBuffer
)
2923 wxReallocateResourceBuffer();
2924 wxResourceBuffer
[0] = 0;
2925 wxEatWhiteSpaceString(s
);
2927 int ch
= getc_string(s
);
2931 wxResourceBufferCount
= 0;
2932 ch
= getc_string(s
);
2938 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2941 // Escaped characters
2942 else if (ch
== '\\')
2944 int newCh
= getc_string(s
);
2947 else if (newCh
== 10)
2955 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2956 wxReallocateResourceBuffer();
2957 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2958 wxResourceBufferCount
++;
2959 ch
= getc_string(s
);
2961 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2965 wxResourceBufferCount
= 0;
2967 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2969 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2970 wxReallocateResourceBuffer();
2971 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2972 wxResourceBufferCount
++;
2974 ch
= getc_string(s
);
2976 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2984 * Files are in form:
2985 static char *name = "....";
2986 with possible comments.
2989 bool wxResourceReadOneResourceString(char *s
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2992 table
= wxDefaultResourceTable
;
2994 // static or #define
2995 if (!wxGetResourceTokenString(s
))
3001 if (strcmp(wxResourceBuffer
, "#define") == 0)
3003 wxGetResourceTokenString(s
);
3004 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
3005 wxGetResourceTokenString(s
);
3006 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
3007 if (wxIsdigit(value
[0]))
3009 int val
= (int)wxAtol(value
);
3010 wxResourceAddIdentifier(name
, val
, table
);
3014 wxLogWarning(_("#define %s must be an integer."), name
);
3025 else if (strcmp(wxResourceBuffer, "#include") == 0)
3027 wxGetResourceTokenString(s);
3028 char *name = copystring(wxResourceBuffer);
3029 char *actualName = name;
3031 actualName = name + 1;
3032 int len = strlen(name);
3033 if ((len > 0) && (name[len-1] == '"'))
3035 if (!wxResourceParseIncludeFile(actualName, table))
3038 sprintf(buf, _("Could not find resource include file %s."), actualName);
3045 else if (strcmp(wxResourceBuffer
, "static") != 0)
3048 wxStrcpy(buf
, _("Found "));
3049 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
3050 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
3056 if (!wxGetResourceTokenString(s
))
3058 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3063 if (strcmp(wxResourceBuffer
, "char") != 0)
3065 wxLogWarning(_("Expected 'char' whilst parsing resource."));
3070 if (!wxGetResourceTokenString(s
))
3072 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3077 if (wxResourceBuffer
[0] != '*')
3079 wxLogWarning(_("Expected '*' whilst parsing resource."));
3082 wxChar nameBuf
[100];
3083 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
3087 if (!wxGetResourceTokenString(s
))
3089 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3094 if (strcmp(wxResourceBuffer
, "=") != 0)
3096 wxLogWarning(_("Expected '=' whilst parsing resource."));
3101 if (!wxGetResourceTokenString(s
))
3103 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3109 if (!db
.ReadPrologFromString(wxResourceBuffer
))
3111 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
3116 if (!wxGetResourceTokenString(s
))
3123 bool wxResourceParseString(const wxString
& s
, wxResourceTable
*table
)
3126 return wxResourceParseString( (char*)s
.mb_str().data() );
3128 return wxResourceParseString( (char*)s
.c_str() );
3132 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
3135 table
= wxDefaultResourceTable
;
3140 // Turn backslashes into spaces
3143 int len
= strlen(s
);
3145 for (i
= 0; i
< len
; i
++)
3146 if (s
[i
] == 92 && s
[i
+1] == 13)
3154 wxResourceStringPtr
= 0;
3157 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
3161 return wxResourceInterpretResources(*table
, db
);
3165 * resource loading facility
3168 bool wxLoadFromResource(wxWindow
* thisWindow
, wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
3171 table
= wxDefaultResourceTable
;
3173 wxItemResource
*resource
= table
->FindResource((const wxChar
*)resourceName
);
3174 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
3175 if (!resource
|| (resource
->GetType() == wxT("")) ||
3176 ! ((resource
->GetType() == wxT("wxDialog")) || (resource
->GetType() == wxT("wxPanel"))))
3179 wxString
title(resource
->GetTitle());
3180 long theWindowStyle
= resource
->GetStyle();
3181 bool isModal
= (resource
->GetValue1() != 0) ;
3182 int x
= resource
->GetX();
3183 int y
= resource
->GetY();
3184 int width
= resource
->GetWidth();
3185 int height
= resource
->GetHeight();
3186 wxString name
= resource
->GetName();
3188 // this is used for loading wxWizard pages from WXR
3189 if ( parent
!= thisWindow
)
3191 if (thisWindow
->IsKindOf(CLASSINFO(wxDialog
)))
3193 wxDialog
*dialogBox
= (wxDialog
*)thisWindow
;
3194 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
3195 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
3198 // Only reset the client size if we know we're not going to do it again below.
3199 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == 0)
3200 dialogBox
->SetClientSize(width
, height
);
3202 else if (thisWindow
->IsKindOf(CLASSINFO(wxPanel
)))
3204 wxPanel
* panel
= (wxPanel
*)thisWindow
;
3205 if (!panel
->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
| wxTAB_TRAVERSAL
, name
))
3210 if (!((wxWindow
*)thisWindow
)->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
3215 if ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
3217 // No need to do this since it's done in wxPanel or wxDialog constructor.
3218 // SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
3222 if (resource
->GetFont().Ok())
3223 thisWindow
->SetFont(resource
->GetFont());
3224 if (resource
->GetBackgroundColour().Ok())
3225 thisWindow
->SetBackgroundColour(resource
->GetBackgroundColour());
3228 // Should have some kind of font at this point
3229 if (!thisWindow
->GetFont().Ok())
3230 thisWindow
->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
3231 if (!thisWindow
->GetBackgroundColour().Ok())
3232 thisWindow
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
3234 // Only when we've created the window and set the font can we set the correct size,
3235 // if based on dialog units.
3236 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
3238 wxSize sz
= thisWindow
->ConvertDialogToPixels(wxSize(width
, height
));
3239 thisWindow
->SetClientSize(sz
.x
, sz
.y
);
3241 wxPoint pt
= thisWindow
->ConvertDialogToPixels(wxPoint(x
, y
));
3242 thisWindow
->Move(pt
.x
, pt
.y
);
3245 // Now create children
3246 wxNode
*node
= resource
->GetChildren().First();
3249 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
3251 (void) wxCreateItem(thisWindow
, childResource
, resource
, table
);
3253 node
= node
->Next();
3258 wxControl
*wxCreateItem(wxWindow
* thisWindow
, const wxItemResource
*resource
, const wxItemResource
* parentResource
, const wxResourceTable
*table
)
3261 table
= wxDefaultResourceTable
;
3262 return table
->CreateItem(thisWindow
, resource
, parentResource
);
3266 #pragma warning(default:4706) // assignment within conditional expression
3269 #endif // wxUSE_WX_RESOURCES