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/splitter.h"
74 #include "wx/toolbar.h"
76 #include "wx/validate.h"
78 #include "wx/module.h"
85 #include "wx/string.h"
86 #include "wx/settings.h"
87 #include "wx/stream.h"
89 #include "wx/deprecated/resource.h"
90 #include "wx/deprecated/wxexpr.h"
92 // Forward (private) declarations
93 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
);
94 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
= FALSE
);
95 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
);
96 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
);
97 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
);
98 wxItemResource
*wxResourceInterpretString(wxResourceTable
& table
, wxExpr
*expr
);
99 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& table
, wxExpr
*expr
);
100 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
);
101 // Interpret list expression
102 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
);
104 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
105 bool wxResourceReadOneResource(wxInputStream
*fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
) ;
106 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
108 wxResourceTable
*wxDefaultResourceTable
= (wxResourceTable
*) NULL
;
110 char *wxResourceBuffer
= (char *) NULL
;
111 long wxResourceBufferSize
= 0;
112 long wxResourceBufferCount
= 0;
113 int wxResourceStringPtr
= 0;
115 void wxInitializeResourceSystem()
117 if (!wxDefaultResourceTable
)
118 wxDefaultResourceTable
= new wxResourceTable
;
121 void wxCleanUpResourceSystem()
123 delete wxDefaultResourceTable
;
124 if (wxResourceBuffer
)
125 delete[] wxResourceBuffer
;
128 // Module to ensure the resource system data gets initialized
131 class wxResourceModule
: public wxModule
134 wxResourceModule() : wxModule() {}
135 virtual bool OnInit() { wxInitializeResourceSystem(); return TRUE
; }
136 virtual void OnExit() { wxCleanUpResourceSystem(); }
138 DECLARE_DYNAMIC_CLASS(wxResourceModule
)
141 IMPLEMENT_DYNAMIC_CLASS(wxResourceModule
, wxModule
)
144 IMPLEMENT_DYNAMIC_CLASS(wxItemResource
, wxObject
)
145 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable
, wxHashTable
)
147 wxItemResource::wxItemResource()
149 m_itemType
= wxT("");
153 m_x
= m_y
= m_width
= m_height
= 0;
154 m_value1
= m_value2
= m_value3
= m_value5
= 0;
160 wxItemResource::~wxItemResource()
162 wxNode
*node
= m_children
.First();
165 wxItemResource
*item
= (wxItemResource
*)node
->Data();
168 node
= m_children
.First();
176 wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
)
180 wxResourceTable::~wxResourceTable()
185 wxItemResource
*wxResourceTable::FindResource(const wxString
& name
) const
187 wxItemResource
*item
= (wxItemResource
*)Get(WXSTRINGCAST name
);
191 void wxResourceTable::AddResource(wxItemResource
*item
)
193 wxString name
= item
->GetName();
195 name
= item
->GetTitle();
197 name
= wxT("no name");
199 // Delete existing resource, if any.
205 bool wxResourceTable::DeleteResource(const wxString
& name
)
207 wxItemResource
*item
= (wxItemResource
*)Delete(WXSTRINGCAST name
);
210 // See if any resource has this as its child; if so, delete from
211 // parent's child list.
213 wxNode
*node
= (wxNode
*) NULL
;
217 wxItemResource
*parent
= (wxItemResource
*)node
->Data();
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 wxNode
*node
= Next();
311 wxNode
*next
= Next();
312 wxItemResource
*item
= (wxItemResource
*)node
->Data();
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() != wxT(""))
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() != wxT("") || 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
.Number() > 0)
464 noStrings
= stringList
.Number();
465 strings
= new wxString
[noStrings
];
466 wxNode
*node
= stringList
.First();
470 strings
[i
] = (wxChar
*)node
->Data();
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
.Number() > 0)
488 noStrings
= stringList
.Number();
489 strings
= new wxString
[noStrings
];
490 wxNode
*node
= stringList
.First();
494 strings
[i
] = (wxChar
*)node
->Data();
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
.Number() > 0)
513 noStrings
= stringList
.Number();
514 strings
= new wxString
[noStrings
];
515 wxNode
*node
= stringList
.First();
519 strings
[i
] = (wxChar
*)node
->Data();
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
.Number() > 0)
538 noStrings
= stringList
.Number();
539 strings
= new wxString
[noStrings
];
540 wxNode
*node
= stringList
.First();
544 strings
[i
] = (wxChar
*)node
->Data();
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(-1, -1, -1, -1, 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
.First();
588 wxExpr
*clause
= (wxExpr
*)node
->Data();
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() != wxT(""))
611 table
.DeleteResource(item
->GetName());
612 table
.AddResource(item
);
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
= wxT("");
661 wxString title
= wxT("");
662 wxString name
= wxT("");
663 wxString backColourHex
= wxT("");
664 wxString labelColourHex
= wxT("");
665 wxString buttonColourHex
= wxT("");
667 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
671 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
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
);
705 if (style
!= wxT(""))
707 windowStyle
= wxParseWindowStyle(style
);
709 dialogItem
->SetStyle(windowStyle
);
710 dialogItem
->SetValue1(isModal
);
711 if (windowStyle
& wxDIALOG_MODAL
) // Uses style in wxWin 2
712 dialogItem
->SetValue1(TRUE
);
714 dialogItem
->SetName(name
);
715 dialogItem
->SetTitle(title
);
716 dialogItem
->SetSize(x
, y
, width
, height
);
718 // Check for wxWin 1.68-style specifications
719 if (style
.Find(wxT("VERTICAL_LABEL")) != -1)
720 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL
);
721 else if (style
.Find(wxT("HORIZONTAL_LABEL")) != -1)
722 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL
);
724 if (backColourHex
!= wxT(""))
729 r
= wxHexToDec(backColourHex
.Mid(0, 2));
730 g
= wxHexToDec(backColourHex
.Mid(2, 2));
731 b
= wxHexToDec(backColourHex
.Mid(4, 2));
732 dialogItem
->SetBackgroundColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
734 if (labelColourHex
!= wxT(""))
739 r
= wxHexToDec(labelColourHex
.Mid(0, 2));
740 g
= wxHexToDec(labelColourHex
.Mid(2, 2));
741 b
= wxHexToDec(labelColourHex
.Mid(4, 2));
742 dialogItem
->SetLabelColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
744 if (buttonColourHex
!= wxT(""))
749 r
= wxHexToDec(buttonColourHex
.Mid(0, 2));
750 g
= wxHexToDec(buttonColourHex
.Mid(2, 2));
751 b
= wxHexToDec(buttonColourHex
.Mid(4, 2));
752 dialogItem
->SetButtonColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
756 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
757 else if (buttonFontExpr
)
758 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
759 else if (labelFontExpr
)
760 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
762 // Now parse all controls
763 wxExpr
*controlExpr
= expr
->GetFirst();
766 if (controlExpr
->Number() == 3)
768 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
769 if (controlKeyword
!= wxT("") && controlKeyword
== wxT("control"))
771 // The value part: always a list.
772 wxExpr
*listExpr
= controlExpr
->Nth(2);
773 if (listExpr
->Type() == PrologList
)
775 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
778 dialogItem
->GetChildren().Append(controlItem
);
783 controlExpr
= controlExpr
->GetNext();
788 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
)
790 wxItemResource
*controlItem
= new wxItemResource
;
792 // First, find the standard features of a control definition:
793 // [optional integer/string id], control name, title, style, name, x, y, width, height
795 wxString controlType
;
800 long windowStyle
= 0;
801 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
804 wxExpr
*expr1
= expr
->Nth(0);
806 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
808 if ( wxIsValidControlClass(expr1
->StringValue()) )
811 controlType
= expr1
->StringValue();
815 wxString
str(expr1
->StringValue());
816 id
= wxResourceGetIdentifier(str
, &table
);
819 wxLogWarning(_("Could not resolve control class or id '%s'. Use (non-zero) integer instead\n or provide #define (see manual for caveats)"),
820 (const wxChar
*) expr1
->StringValue());
822 return (wxItemResource
*) NULL
;
826 // Success - we have an id, so the 2nd element must be the control class.
827 controlType
= expr
->Nth(1)->StringValue();
832 else if (expr1
->Type() == PrologInteger
)
834 id
= (int)expr1
->IntegerValue();
835 // Success - we have an id, so the 2nd element must be the control class.
836 controlType
= expr
->Nth(1)->StringValue();
840 expr1
= expr
->Nth(count
);
843 title
= expr1
->StringValue();
845 expr1
= expr
->Nth(count
);
849 style
= expr1
->StringValue();
850 windowStyle
= wxParseWindowStyle(style
);
853 expr1
= expr
->Nth(count
);
856 name
= expr1
->StringValue();
858 expr1
= expr
->Nth(count
);
861 x
= (int)expr1
->IntegerValue();
863 expr1
= expr
->Nth(count
);
866 y
= (int)expr1
->IntegerValue();
868 expr1
= expr
->Nth(count
);
871 width
= (int)expr1
->IntegerValue();
873 expr1
= expr
->Nth(count
);
876 height
= (int)expr1
->IntegerValue();
878 controlItem
->SetStyle(windowStyle
);
879 controlItem
->SetName(name
);
880 controlItem
->SetTitle(title
);
881 controlItem
->SetSize(x
, y
, width
, height
);
882 controlItem
->SetType(controlType
);
883 controlItem
->SetId(id
);
885 // Check for wxWin 1.68-style specifications
886 if (style
.Find(wxT("VERTICAL_LABEL")) != -1)
887 controlItem
->SetResourceStyle(controlItem
->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL
);
888 else if (style
.Find(wxT("HORIZONTAL_LABEL")) != -1)
889 controlItem
->SetResourceStyle(controlItem
->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL
);
891 if (controlType
== wxT("wxButton"))
893 // Check for bitmap resource name (in case loading old-style resource file)
894 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
896 wxString
str(expr
->Nth(count
)->StringValue());
901 controlItem
->SetValue4(str
);
902 controlItem
->SetType(wxT("wxBitmapButton"));
905 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
906 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
908 else if (controlType
== wxT("wxBitmapButton"))
910 // Check for bitmap resource name
911 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
913 wxString
str(expr
->Nth(count
)->StringValue());
914 controlItem
->SetValue4(str
);
916 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
917 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
920 else if (controlType
== wxT("wxCheckBox"))
922 // Check for default value
923 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
925 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
927 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
928 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
932 else if (controlType
== wxT("wxRadioButton"))
934 // Check for default value
935 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
937 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
939 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
940 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
944 else if (controlType
== wxT("wxText") || controlType
== wxT("wxTextCtrl") || controlType
== wxT("wxMultiText"))
946 // Check for default value
947 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
949 wxString
str(expr
->Nth(count
)->StringValue());
950 controlItem
->SetValue4(str
);
953 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
955 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
956 // Skip past the obsolete label font spec if there are two consecutive specs
957 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
959 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
963 else if (controlType
== wxT("wxMessage") || controlType
== wxT("wxStaticText"))
965 // Check for bitmap resource name (in case it's an old-style .wxr file)
966 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
968 wxString
str(expr
->Nth(count
)->StringValue());
969 controlItem
->SetValue4(str
);
971 controlItem
->SetType(wxT("wxStaticText"));
973 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
974 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
976 else if (controlType
== wxT("wxStaticBitmap"))
978 // Check for bitmap resource name
979 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
981 wxString
str(expr
->Nth(count
)->StringValue());
982 controlItem
->SetValue4(str
);
985 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
986 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
988 else if (controlType
== wxT("wxGroupBox") || controlType
== wxT("wxStaticBox"))
990 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
991 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
993 else if (controlType
== wxT("wxGauge"))
995 // Check for default value
996 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
998 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1002 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1004 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1007 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1009 // Skip past the obsolete label font spec if there are two consecutive specs
1010 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1012 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1017 else if (controlType
== wxT("wxSlider"))
1019 // Check for default value
1020 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1022 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1026 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1028 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1032 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1034 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1037 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1039 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1043 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1044 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1050 else if (controlType
== wxT("wxScrollBar"))
1053 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1055 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1059 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1061 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1065 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1067 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1071 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1072 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
1077 else if (controlType
== wxT("wxListBox"))
1079 wxExpr
*valueList
= (wxExpr
*) NULL
;
1081 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1083 wxStringList stringList
;
1084 wxExpr
*stringExpr
= valueList
->GetFirst();
1087 stringList
.Add(stringExpr
->StringValue());
1088 stringExpr
= stringExpr
->GetNext();
1090 controlItem
->SetStringValues(stringList
);
1092 // This is now obsolete: it's in the window style.
1093 // Check for wxSINGLE/wxMULTIPLE
1094 wxExpr
*mult
= (wxExpr
*) NULL
;
1096 controlItem->SetValue1(wxLB_SINGLE);
1098 if (((mult
= expr
->Nth(count
)) != 0) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1101 wxString m(mult->StringValue());
1102 if (m == "wxLB_MULTIPLE")
1103 controlItem->SetValue1(wxLB_MULTIPLE);
1104 else if (m == "wxLB_EXTENDED")
1105 controlItem->SetValue1(wxLB_EXTENDED);
1110 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1112 // Skip past the obsolete label font spec if there are two consecutive specs
1113 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1115 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1119 else if (controlType
== wxT("wxChoice"))
1121 wxExpr
*valueList
= (wxExpr
*) NULL
;
1122 // Check for default value list
1123 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1125 wxStringList stringList
;
1126 wxExpr
*stringExpr
= valueList
->GetFirst();
1129 stringList
.Add(stringExpr
->StringValue());
1130 stringExpr
= stringExpr
->GetNext();
1132 controlItem
->SetStringValues(stringList
);
1136 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1138 // Skip past the obsolete label font spec if there are two consecutive specs
1139 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1141 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1146 else if (controlType
== wxT("wxComboBox"))
1148 wxExpr
*textValue
= expr
->Nth(count
);
1149 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1151 wxString
str(textValue
->StringValue());
1152 controlItem
->SetValue4(str
);
1156 wxExpr
*valueList
= (wxExpr
*) NULL
;
1157 // Check for default value list
1158 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1160 wxStringList stringList
;
1161 wxExpr
*stringExpr
= valueList
->GetFirst();
1164 stringList
.Add(stringExpr
->StringValue());
1165 stringExpr
= stringExpr
->GetNext();
1167 controlItem
->SetStringValues(stringList
);
1171 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1173 // Skip past the obsolete label font spec if there are two consecutive specs
1174 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1176 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1183 else if (controlType
== wxT("wxRadioBox"))
1185 wxExpr
*valueList
= (wxExpr
*) NULL
;
1186 // Check for default value list
1187 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1189 wxStringList stringList
;
1190 wxExpr
*stringExpr
= valueList
->GetFirst();
1193 stringList
.Add(stringExpr
->StringValue());
1194 stringExpr
= stringExpr
->GetNext();
1196 controlItem
->SetStringValues(stringList
);
1199 // majorDim (number of rows or cols)
1200 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1202 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1206 controlItem
->SetValue1(0);
1208 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1210 // Skip past the obsolete label font spec if there are two consecutive specs
1211 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1213 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1221 return (wxItemResource
*) NULL
;
1226 // Forward declaration
1227 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, wxExpr
*expr
);
1230 * Interpet a menu item
1233 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, wxExpr
*expr
)
1235 wxItemResource
*item
= new wxItemResource
;
1237 wxExpr
*labelExpr
= expr
->Nth(0);
1238 wxExpr
*idExpr
= expr
->Nth(1);
1239 wxExpr
*helpExpr
= expr
->Nth(2);
1240 wxExpr
*checkableExpr
= expr
->Nth(3);
1242 // Further keywords/attributes to follow sometime...
1243 if (expr
->Number() == 0)
1245 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1246 item
->SetType(wxT("wxMenuSeparator"));
1251 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1252 item
->SetType(wxT("wxMenu")); // Well, menu item, but doesn't matter.
1255 wxString
str(labelExpr
->StringValue());
1256 item
->SetTitle(str
);
1261 // If a string or word, must look up in identifier table.
1262 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1264 wxString
str(idExpr
->StringValue());
1265 id
= wxResourceGetIdentifier(str
, &table
);
1268 wxLogWarning(_("Could not resolve menu id '%s'. Use (non-zero) integer instead\nor provide #define (see manual for caveats)"),
1269 (const wxChar
*) idExpr
->StringValue());
1272 else if (idExpr
->Type() == PrologInteger
)
1273 id
= (int)idExpr
->IntegerValue();
1274 item
->SetValue1(id
);
1278 wxString
str(helpExpr
->StringValue());
1279 item
->SetValue4(str
);
1282 item
->SetValue2(checkableExpr
->IntegerValue());
1284 // Find the first expression that's a list, for submenu
1285 wxExpr
*subMenuExpr
= expr
->GetFirst();
1286 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1287 subMenuExpr
= subMenuExpr
->GetNext();
1291 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1292 item
->GetChildren().Append(child
);
1293 subMenuExpr
= subMenuExpr
->GetNext();
1300 * Interpret a nested list as a menu
1303 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1305 wxItemResource *menu = new wxItemResource;
1306 // menu->SetType(wxTYPE_MENU);
1307 menu->SetType("wxMenu");
1308 wxExpr *element = expr->GetFirst();
1311 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1313 menu->GetChildren().Append(item);
1314 element = element->GetNext();
1320 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
)
1322 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1323 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1325 return (wxItemResource
*) NULL
;
1327 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1330 return (wxItemResource
*) NULL
;
1333 if (expr
->GetAttributeValue(wxT("name"), name
))
1335 menuResource
->SetName(name
);
1338 return menuResource
;
1341 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
)
1343 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1344 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1346 return (wxItemResource
*) NULL
;
1348 wxItemResource
*resource
= new wxItemResource
;
1349 resource
->SetType(wxT("wxMenu"));
1350 // resource->SetType(wxTYPE_MENU);
1352 wxExpr
*element
= listExpr
->GetFirst();
1355 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1356 resource
->GetChildren().Append(menuResource
);
1357 element
= element
->GetNext();
1361 if (expr
->GetAttributeValue(wxT("name"), name
))
1363 resource
->SetName(name
);
1369 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), wxExpr
*WXUNUSED(expr
))
1371 return (wxItemResource
*) NULL
;
1374 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), wxExpr
*expr
)
1376 wxItemResource
*bitmapItem
= new wxItemResource
;
1377 // bitmapItem->SetType(wxTYPE_BITMAP);
1378 bitmapItem
->SetType(wxT("wxBitmap"));
1380 if (expr
->GetAttributeValue(wxT("name"), name
))
1382 bitmapItem
->SetName(name
);
1384 // Now parse all bitmap specifications
1385 wxExpr
*bitmapExpr
= expr
->GetFirst();
1388 if (bitmapExpr
->Number() == 3)
1390 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1391 if (bitmapKeyword
== wxT("bitmap") || bitmapKeyword
== wxT("icon"))
1393 // The value part: always a list.
1394 wxExpr
*listExpr
= bitmapExpr
->Nth(2);
1395 if (listExpr
->Type() == PrologList
)
1397 wxItemResource
*bitmapSpec
= new wxItemResource
;
1398 // bitmapSpec->SetType(wxTYPE_BITMAP);
1399 bitmapSpec
->SetType(wxT("wxBitmap"));
1401 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1402 // where everything after 'filename' is optional.
1403 wxExpr
*nameExpr
= listExpr
->Nth(0);
1404 wxExpr
*typeExpr
= listExpr
->Nth(1);
1405 wxExpr
*platformExpr
= listExpr
->Nth(2);
1406 wxExpr
*coloursExpr
= listExpr
->Nth(3);
1407 wxExpr
*xresExpr
= listExpr
->Nth(4);
1408 wxExpr
*yresExpr
= listExpr
->Nth(5);
1409 if (nameExpr
&& nameExpr
->StringValue() != wxT(""))
1411 bitmapSpec
->SetName(nameExpr
->StringValue());
1413 if (typeExpr
&& typeExpr
->StringValue() != wxT(""))
1415 bitmapSpec
->SetValue1(wxParseWindowStyle(typeExpr
->StringValue()));
1418 bitmapSpec
->SetValue1(0);
1420 if (platformExpr
&& platformExpr
->StringValue() != wxT(""))
1422 wxString
plat(platformExpr
->StringValue());
1423 if (plat
== wxT("windows") || plat
== wxT("WINDOWS"))
1424 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1425 else if (plat
== wxT("x") || plat
== wxT("X"))
1426 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1427 else if (plat
== wxT("mac") || plat
== wxT("MAC"))
1428 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1430 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1433 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1436 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1440 xres
= (int)xresExpr
->IntegerValue();
1442 yres
= (int)yresExpr
->IntegerValue();
1443 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1445 bitmapItem
->GetChildren().Append(bitmapSpec
);
1449 bitmapExpr
= bitmapExpr
->GetNext();
1455 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
)
1457 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1460 // item->SetType(wxTYPE_ICON);
1461 item
->SetType(wxT("wxIcon"));
1465 return (wxItemResource
*) NULL
;
1468 // Interpret list expression as a font
1469 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
)
1471 if (expr
->Type() != PrologList
)
1475 int family
= wxSWISS
;
1476 int style
= wxNORMAL
;
1477 int weight
= wxNORMAL
;
1479 wxString
faceName(wxT(""));
1481 wxExpr
*pointExpr
= expr
->Nth(0);
1482 wxExpr
*familyExpr
= expr
->Nth(1);
1483 wxExpr
*styleExpr
= expr
->Nth(2);
1484 wxExpr
*weightExpr
= expr
->Nth(3);
1485 wxExpr
*underlineExpr
= expr
->Nth(4);
1486 wxExpr
*faceNameExpr
= expr
->Nth(5);
1488 point
= (int)pointExpr
->IntegerValue();
1493 str
= familyExpr
->StringValue();
1494 family
= (int)wxParseWindowStyle(str
);
1498 str
= styleExpr
->StringValue();
1499 style
= (int)wxParseWindowStyle(str
);
1503 str
= weightExpr
->StringValue();
1504 weight
= (int)wxParseWindowStyle(str
);
1507 underline
= (int)underlineExpr
->IntegerValue();
1509 faceName
= faceNameExpr
->StringValue();
1511 return *wxTheFontList
->FindOrCreateFont(point
, family
, style
, weight
,
1512 (underline
!= 0), faceName
);
1516 * (Re)allocate buffer for reading in from resource file
1519 bool wxReallocateResourceBuffer()
1521 if (!wxResourceBuffer
)
1523 wxResourceBufferSize
= 1000;
1524 wxResourceBuffer
= new char[wxResourceBufferSize
];
1527 if (wxResourceBuffer
)
1529 long newSize
= wxResourceBufferSize
+ 1000;
1530 char *tmp
= new char[(int)newSize
];
1531 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1532 delete[] wxResourceBuffer
;
1533 wxResourceBuffer
= tmp
;
1534 wxResourceBufferSize
= newSize
;
1539 static bool wxEatWhiteSpace(FILE *fd
)
1543 while ((ch
= getc(fd
)) != EOF
)
1558 ungetc(prev_ch
, fd
);
1566 while ((ch
= getc(fd
)) != EOF
)
1568 if (ch
== '/' && prev_ch
== '*')
1576 static char buffer
[255];
1577 fgets(buffer
, 255, fd
);
1581 ungetc(prev_ch
, fd
);
1595 static bool wxEatWhiteSpace(wxInputStream
*is
)
1597 int ch
= is
->GetC() ;
1598 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
1605 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
1607 // Check for comment
1613 bool finished
= FALSE
;
1621 int newCh
= is
->GetC();
1636 return wxEatWhiteSpace(is
);
1639 bool wxGetResourceToken(FILE *fd
)
1641 if (!wxResourceBuffer
)
1642 wxReallocateResourceBuffer();
1643 wxResourceBuffer
[0] = 0;
1644 wxEatWhiteSpace(fd
);
1650 wxResourceBufferCount
= 0;
1657 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1660 // Escaped characters
1661 else if (ch
== '\\')
1663 int newCh
= getc(fd
);
1666 else if (newCh
== 10)
1674 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1675 wxReallocateResourceBuffer();
1676 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1677 wxResourceBufferCount
++;
1680 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1684 wxResourceBufferCount
= 0;
1686 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1688 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1689 wxReallocateResourceBuffer();
1690 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1691 wxResourceBufferCount
++;
1695 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1702 bool wxGetResourceToken(wxInputStream
*is
)
1704 if (!wxResourceBuffer
)
1705 wxReallocateResourceBuffer();
1706 wxResourceBuffer
[0] = 0;
1707 wxEatWhiteSpace(is
);
1709 int ch
= is
->GetC() ;
1713 wxResourceBufferCount
= 0;
1720 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1723 // Escaped characters
1724 else if (ch
== '\\')
1726 int newCh
= is
->GetC();
1729 else if (newCh
== 10)
1731 else if (newCh
== 13) // mac
1739 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1740 wxReallocateResourceBuffer();
1741 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1742 wxResourceBufferCount
++;
1745 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1749 wxResourceBufferCount
= 0;
1751 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1753 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1754 wxReallocateResourceBuffer();
1755 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1756 wxResourceBufferCount
++;
1760 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1768 * Files are in form:
1769 static char *name = "....";
1770 with possible comments.
1773 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1776 table
= wxDefaultResourceTable
;
1778 // static or #define
1779 if (!wxGetResourceToken(fd
))
1785 if (strcmp(wxResourceBuffer
, "#define") == 0)
1787 wxGetResourceToken(fd
);
1788 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1789 wxGetResourceToken(fd
);
1790 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1791 if (wxIsdigit(value
[0]))
1793 int val
= (int)wxAtol(value
);
1794 wxResourceAddIdentifier(name
, val
, table
);
1798 wxLogWarning(_("#define %s must be an integer."), name
);
1808 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1810 wxGetResourceToken(fd
);
1811 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1812 wxChar
*actualName
= name
;
1813 if (name
[0] == wxT('"'))
1814 actualName
= name
+ 1;
1815 int len
= wxStrlen(name
);
1816 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1818 if (!wxResourceParseIncludeFile(actualName
, table
))
1820 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1825 else if (strcmp(wxResourceBuffer
, "static") != 0)
1828 wxStrcpy(buf
, _("Found "));
1829 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
1830 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1836 if (!wxGetResourceToken(fd
))
1838 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1843 if (strcmp(wxResourceBuffer
, "char") != 0)
1845 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1850 if (!wxGetResourceToken(fd
))
1852 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1857 if (wxResourceBuffer
[0] != '*')
1859 wxLogWarning(_("Expected '*' whilst parsing resource."));
1862 wxChar nameBuf
[100];
1863 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
1867 if (!wxGetResourceToken(fd
))
1869 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1874 if (strcmp(wxResourceBuffer
, "=") != 0)
1876 wxLogWarning(_("Expected '=' whilst parsing resource."));
1881 if (!wxGetResourceToken(fd
))
1883 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1889 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1891 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1896 if (!wxGetResourceToken(fd
))
1903 bool wxResourceReadOneResource(wxInputStream
*fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1906 table
= wxDefaultResourceTable
;
1908 // static or #define
1909 if (!wxGetResourceToken(fd
))
1915 if (strcmp(wxResourceBuffer
, "#define") == 0)
1917 wxGetResourceToken(fd
);
1918 wxChar
*name
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1919 wxGetResourceToken(fd
);
1920 wxChar
*value
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1921 if (wxIsalpha(value
[0]))
1923 int val
= (int)wxAtol(value
);
1924 wxResourceAddIdentifier(name
, val
, table
);
1928 wxLogWarning(_("#define %s must be an integer."), name
);
1938 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1940 wxGetResourceToken(fd
);
1941 wxChar
*name
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1942 wxChar
*actualName
= name
;
1943 if (name
[0] == wxT('"'))
1944 actualName
= name
+ 1;
1945 int len
= wxStrlen(name
);
1946 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1948 if (!wxResourceParseIncludeFile(actualName
, table
))
1950 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1955 else if (strcmp(wxResourceBuffer
, "static") != 0)
1958 wxStrcpy(buf
, _("Found "));
1959 wxStrncat(buf
, wxConvLibc
.cMB2WX(wxResourceBuffer
), 30);
1960 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1966 if (!wxGetResourceToken(fd
))
1968 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1973 if (strcmp(wxResourceBuffer
, "char") != 0)
1975 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1980 if (!wxGetResourceToken(fd
))
1982 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1987 if (wxResourceBuffer
[0] != '*')
1989 wxLogWarning(_("Expected '*' whilst parsing resource."));
1993 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
1996 if (!wxGetResourceToken(fd
))
1998 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2003 if (strcmp(wxResourceBuffer
, "=") != 0)
2005 wxLogWarning(_("Expected '=' whilst parsing resource."));
2010 if (!wxGetResourceToken(fd
))
2012 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2018 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2020 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2025 if (!wxGetResourceToken(fd
))
2033 * Parses string window style into integer window style
2037 * Style flag parsing, e.g.
2038 * "wxSYSTEM_MENU | wxBORDER" -> integer
2041 wxChar
* wxResourceParseWord(wxChar
*s
, int *i
)
2044 return (wxChar
*) NULL
;
2046 static wxChar buf
[150];
2047 int len
= wxStrlen(s
);
2050 while ((ii
< len
) && (wxIsalpha(s
[ii
]) || (s
[ii
] == wxT('_'))))
2058 // Eat whitespace and conjunction characters
2059 while ((ii
< len
) &&
2060 ((s
[ii
] == wxT(' ')) || (s
[ii
] == wxT('|')) || (s
[ii
] == wxT(','))))
2066 return (wxChar
*) NULL
;
2071 struct wxResourceBitListStruct
2077 static wxResourceBitListStruct wxResourceBitListTable
[] =
2080 { wxT("wxSINGLE"), wxLB_SINGLE
},
2081 { wxT("wxMULTIPLE"), wxLB_MULTIPLE
},
2082 { wxT("wxEXTENDED"), wxLB_EXTENDED
},
2083 { wxT("wxLB_SINGLE"), wxLB_SINGLE
},
2084 { wxT("wxLB_MULTIPLE"), wxLB_MULTIPLE
},
2085 { wxT("wxLB_EXTENDED"), wxLB_EXTENDED
},
2086 { wxT("wxLB_NEEDED_SB"), wxLB_NEEDED_SB
},
2087 { wxT("wxLB_ALWAYS_SB"), wxLB_ALWAYS_SB
},
2088 { wxT("wxLB_SORT"), wxLB_SORT
},
2089 { wxT("wxLB_OWNERDRAW"), wxLB_OWNERDRAW
},
2090 { wxT("wxLB_HSCROLL"), wxLB_HSCROLL
},
2093 { wxT("wxCB_SIMPLE"), wxCB_SIMPLE
},
2094 { wxT("wxCB_DROPDOWN"), wxCB_DROPDOWN
},
2095 { wxT("wxCB_READONLY"), wxCB_READONLY
},
2096 { wxT("wxCB_SORT"), wxCB_SORT
},
2099 { wxT("wxGA_PROGRESSBAR"), wxGA_PROGRESSBAR
},
2100 { wxT("wxGA_HORIZONTAL"), wxGA_HORIZONTAL
},
2101 { wxT("wxGA_VERTICAL"), wxGA_VERTICAL
},
2104 { wxT("wxPASSWORD"), wxPASSWORD
},
2105 { wxT("wxPROCESS_ENTER"), wxPROCESS_ENTER
},
2106 { wxT("wxTE_PASSWORD"), wxTE_PASSWORD
},
2107 { wxT("wxTE_READONLY"), wxTE_READONLY
},
2108 { wxT("wxTE_PROCESS_ENTER"), wxTE_PROCESS_ENTER
},
2109 { wxT("wxTE_MULTILINE"), wxTE_MULTILINE
},
2110 { wxT("wxTE_NO_VSCROLL"), wxTE_NO_VSCROLL
},
2112 /* wxRadioBox/wxRadioButton */
2113 { wxT("wxRB_GROUP"), wxRB_GROUP
},
2114 { wxT("wxRA_SPECIFY_COLS"), wxRA_SPECIFY_COLS
},
2115 { wxT("wxRA_SPECIFY_ROWS"), wxRA_SPECIFY_ROWS
},
2116 { wxT("wxRA_HORIZONTAL"), wxRA_HORIZONTAL
},
2117 { wxT("wxRA_VERTICAL"), wxRA_VERTICAL
},
2120 { wxT("wxSL_HORIZONTAL"), wxSL_HORIZONTAL
},
2121 { wxT("wxSL_VERTICAL"), wxSL_VERTICAL
},
2122 { wxT("wxSL_AUTOTICKS"), wxSL_AUTOTICKS
},
2123 { wxT("wxSL_LABELS"), wxSL_LABELS
},
2124 { wxT("wxSL_LEFT"), wxSL_LEFT
},
2125 { wxT("wxSL_TOP"), wxSL_TOP
},
2126 { wxT("wxSL_RIGHT"), wxSL_RIGHT
},
2127 { wxT("wxSL_BOTTOM"), wxSL_BOTTOM
},
2128 { wxT("wxSL_BOTH"), wxSL_BOTH
},
2129 { wxT("wxSL_SELRANGE"), wxSL_SELRANGE
},
2132 { wxT("wxSB_HORIZONTAL"), wxSB_HORIZONTAL
},
2133 { wxT("wxSB_VERTICAL"), wxSB_VERTICAL
},
2136 { wxT("wxBU_AUTODRAW"), wxBU_AUTODRAW
},
2137 { wxT("wxBU_NOAUTODRAW"), wxBU_NOAUTODRAW
},
2140 { wxT("wxTR_HAS_BUTTONS"), wxTR_HAS_BUTTONS
},
2141 { wxT("wxTR_EDIT_LABELS"), wxTR_EDIT_LABELS
},
2142 { wxT("wxTR_LINES_AT_ROOT"), wxTR_LINES_AT_ROOT
},
2145 { wxT("wxLC_ICON"), wxLC_ICON
},
2146 { wxT("wxLC_SMALL_ICON"), wxLC_SMALL_ICON
},
2147 { wxT("wxLC_LIST"), wxLC_LIST
},
2148 { wxT("wxLC_REPORT"), wxLC_REPORT
},
2149 { wxT("wxLC_ALIGN_TOP"), wxLC_ALIGN_TOP
},
2150 { wxT("wxLC_ALIGN_LEFT"), wxLC_ALIGN_LEFT
},
2151 { wxT("wxLC_AUTOARRANGE"), wxLC_AUTOARRANGE
},
2152 { wxT("wxLC_USER_TEXT"), wxLC_USER_TEXT
},
2153 { wxT("wxLC_EDIT_LABELS"), wxLC_EDIT_LABELS
},
2154 { wxT("wxLC_NO_HEADER"), wxLC_NO_HEADER
},
2155 { wxT("wxLC_NO_SORT_HEADER"), wxLC_NO_SORT_HEADER
},
2156 { wxT("wxLC_SINGLE_SEL"), wxLC_SINGLE_SEL
},
2157 { wxT("wxLC_SORT_ASCENDING"), wxLC_SORT_ASCENDING
},
2158 { wxT("wxLC_SORT_DESCENDING"), wxLC_SORT_DESCENDING
},
2161 { wxT("wxSP_VERTICAL"), wxSP_VERTICAL
},
2162 { wxT("wxSP_HORIZONTAL"), wxSP_HORIZONTAL
},
2163 { wxT("wxSP_ARROW_KEYS"), wxSP_ARROW_KEYS
},
2164 { wxT("wxSP_WRAP"), wxSP_WRAP
},
2167 { wxT("wxSP_NOBORDER"), wxSP_NOBORDER
},
2168 { wxT("wxSP_3D"), wxSP_3D
},
2169 { wxT("wxSP_BORDER"), wxSP_BORDER
},
2172 { wxT("wxTC_MULTILINE"), wxTC_MULTILINE
},
2173 { wxT("wxTC_RIGHTJUSTIFY"), wxTC_RIGHTJUSTIFY
},
2174 { wxT("wxTC_FIXEDWIDTH"), wxTC_FIXEDWIDTH
},
2175 { wxT("wxTC_OWNERDRAW"), wxTC_OWNERDRAW
},
2178 { wxT("wxST_SIZEGRIP"), wxST_SIZEGRIP
},
2181 { wxT("wxFIXED_LENGTH"), wxFIXED_LENGTH
},
2182 { wxT("wxALIGN_LEFT"), wxALIGN_LEFT
},
2183 { wxT("wxALIGN_CENTER"), wxALIGN_CENTER
},
2184 { wxT("wxALIGN_CENTRE"), wxALIGN_CENTRE
},
2185 { wxT("wxALIGN_RIGHT"), wxALIGN_RIGHT
},
2186 { wxT("wxCOLOURED"), wxCOLOURED
},
2189 { wxT("wxTB_3DBUTTONS"), wxTB_3DBUTTONS
},
2190 { wxT("wxTB_HORIZONTAL"), wxTB_HORIZONTAL
},
2191 { wxT("wxTB_VERTICAL"), wxTB_VERTICAL
},
2192 { wxT("wxTB_FLAT"), wxTB_FLAT
},
2195 { wxT("wxDIALOG_MODAL"), wxDIALOG_MODAL
},
2198 { wxT("wxVSCROLL"), wxVSCROLL
},
2199 { wxT("wxHSCROLL"), wxHSCROLL
},
2200 { wxT("wxCAPTION"), wxCAPTION
},
2201 { wxT("wxSTAY_ON_TOP"), wxSTAY_ON_TOP
},
2202 { wxT("wxICONIZE"), wxICONIZE
},
2203 { wxT("wxMINIMIZE"), wxICONIZE
},
2204 { wxT("wxMAXIMIZE"), wxMAXIMIZE
},
2206 { wxT("wxMDI_PARENT"), 0},
2207 { wxT("wxMDI_CHILD"), 0},
2208 { wxT("wxTHICK_FRAME"), wxTHICK_FRAME
},
2209 { wxT("wxRESIZE_BORDER"), wxRESIZE_BORDER
},
2210 { wxT("wxSYSTEM_MENU"), wxSYSTEM_MENU
},
2211 { wxT("wxMINIMIZE_BOX"), wxMINIMIZE_BOX
},
2212 { wxT("wxMAXIMIZE_BOX"), wxMAXIMIZE_BOX
},
2213 { wxT("wxRESIZE_BOX"), wxRESIZE_BOX
},
2214 { wxT("wxDEFAULT_FRAME_STYLE"), wxDEFAULT_FRAME_STYLE
},
2215 { wxT("wxDEFAULT_FRAME"), wxDEFAULT_FRAME_STYLE
},
2216 { wxT("wxDEFAULT_DIALOG_STYLE"), wxDEFAULT_DIALOG_STYLE
},
2217 { wxT("wxBORDER"), wxBORDER
},
2218 { wxT("wxRETAINED"), wxRETAINED
},
2219 { wxT("wxNATIVE_IMPL"), 0},
2220 { wxT("wxEXTENDED_IMPL"), 0},
2221 { wxT("wxBACKINGSTORE"), wxBACKINGSTORE
},
2222 // { wxT("wxFLAT"), wxFLAT},
2223 // { wxT("wxMOTIF_RESIZE"), wxMOTIF_RESIZE},
2224 { wxT("wxFIXED_LENGTH"), 0},
2225 { wxT("wxDOUBLE_BORDER"), wxDOUBLE_BORDER
},
2226 { wxT("wxSUNKEN_BORDER"), wxSUNKEN_BORDER
},
2227 { wxT("wxRAISED_BORDER"), wxRAISED_BORDER
},
2228 { wxT("wxSIMPLE_BORDER"), wxSIMPLE_BORDER
},
2229 { wxT("wxSTATIC_BORDER"), wxSTATIC_BORDER
},
2230 { wxT("wxTRANSPARENT_WINDOW"), wxTRANSPARENT_WINDOW
},
2231 { wxT("wxNO_BORDER"), wxNO_BORDER
},
2232 { wxT("wxCLIP_CHILDREN"), wxCLIP_CHILDREN
},
2233 { wxT("wxCLIP_SIBLINGS"), wxCLIP_SIBLINGS
},
2234 { wxT("wxTAB_TRAVERSAL"), 0}, // Compatibility only
2236 { wxT("wxTINY_CAPTION_HORIZ"), wxTINY_CAPTION_HORIZ
},
2237 { wxT("wxTINY_CAPTION_VERT"), wxTINY_CAPTION_VERT
},
2239 // Text font families
2240 { wxT("wxDEFAULT"), wxDEFAULT
},
2241 { wxT("wxDECORATIVE"), wxDECORATIVE
},
2242 { wxT("wxROMAN"), wxROMAN
},
2243 { wxT("wxSCRIPT"), wxSCRIPT
},
2244 { wxT("wxSWISS"), wxSWISS
},
2245 { wxT("wxMODERN"), wxMODERN
},
2246 { wxT("wxTELETYPE"), wxTELETYPE
},
2247 { wxT("wxVARIABLE"), wxVARIABLE
},
2248 { wxT("wxFIXED"), wxFIXED
},
2249 { wxT("wxNORMAL"), wxNORMAL
},
2250 { wxT("wxLIGHT"), wxLIGHT
},
2251 { wxT("wxBOLD"), wxBOLD
},
2252 { wxT("wxITALIC"), wxITALIC
},
2253 { wxT("wxSLANT"), wxSLANT
},
2254 { wxT("wxSOLID"), wxSOLID
},
2255 { wxT("wxDOT"), wxDOT
},
2256 { wxT("wxLONG_DASH"), wxLONG_DASH
},
2257 { wxT("wxSHORT_DASH"), wxSHORT_DASH
},
2258 { wxT("wxDOT_DASH"), wxDOT_DASH
},
2259 { wxT("wxUSER_DASH"), wxUSER_DASH
},
2260 { wxT("wxTRANSPARENT"), wxTRANSPARENT
},
2261 { wxT("wxSTIPPLE"), wxSTIPPLE
},
2262 { wxT("wxBDIAGONAL_HATCH"), wxBDIAGONAL_HATCH
},
2263 { wxT("wxCROSSDIAG_HATCH"), wxCROSSDIAG_HATCH
},
2264 { wxT("wxFDIAGONAL_HATCH"), wxFDIAGONAL_HATCH
},
2265 { wxT("wxCROSS_HATCH"), wxCROSS_HATCH
},
2266 { wxT("wxHORIZONTAL_HATCH"), wxHORIZONTAL_HATCH
},
2267 { wxT("wxVERTICAL_HATCH"), wxVERTICAL_HATCH
},
2268 { wxT("wxJOIN_BEVEL"), wxJOIN_BEVEL
},
2269 { wxT("wxJOIN_MITER"), wxJOIN_MITER
},
2270 { wxT("wxJOIN_ROUND"), wxJOIN_ROUND
},
2271 { wxT("wxCAP_ROUND"), wxCAP_ROUND
},
2272 { wxT("wxCAP_PROJECTING"), wxCAP_PROJECTING
},
2273 { wxT("wxCAP_BUTT"), wxCAP_BUTT
},
2276 { wxT("wxCLEAR"), wxCLEAR
},
2277 { wxT("wxXOR"), wxXOR
},
2278 { wxT("wxINVERT"), wxINVERT
},
2279 { wxT("wxOR_REVERSE"), wxOR_REVERSE
},
2280 { wxT("wxAND_REVERSE"), wxAND_REVERSE
},
2281 { wxT("wxCOPY"), wxCOPY
},
2282 { wxT("wxAND"), wxAND
},
2283 { wxT("wxAND_INVERT"), wxAND_INVERT
},
2284 { wxT("wxNO_OP"), wxNO_OP
},
2285 { wxT("wxNOR"), wxNOR
},
2286 { wxT("wxEQUIV"), wxEQUIV
},
2287 { wxT("wxSRC_INVERT"), wxSRC_INVERT
},
2288 { wxT("wxOR_INVERT"), wxOR_INVERT
},
2289 { wxT("wxNAND"), wxNAND
},
2290 { wxT("wxOR"), wxOR
},
2291 { wxT("wxSET"), wxSET
},
2293 { wxT("wxFLOOD_SURFACE"), wxFLOOD_SURFACE
},
2294 { wxT("wxFLOOD_BORDER"), wxFLOOD_BORDER
},
2295 { wxT("wxODDEVEN_RULE"), wxODDEVEN_RULE
},
2296 { wxT("wxWINDING_RULE"), wxWINDING_RULE
},
2297 { wxT("wxHORIZONTAL"), wxHORIZONTAL
},
2298 { wxT("wxVERTICAL"), wxVERTICAL
},
2299 { wxT("wxBOTH"), wxBOTH
},
2300 { wxT("wxCENTER_FRAME"), wxCENTER_FRAME
},
2301 { wxT("wxOK"), wxOK
},
2302 { wxT("wxYES_NO"), wxYES_NO
},
2303 { wxT("wxCANCEL"), wxCANCEL
},
2304 { wxT("wxYES"), wxYES
},
2305 { wxT("wxNO"), wxNO
},
2306 { wxT("wxICON_EXCLAMATION"), wxICON_EXCLAMATION
},
2307 { wxT("wxICON_HAND"), wxICON_HAND
},
2308 { wxT("wxICON_QUESTION"), wxICON_QUESTION
},
2309 { wxT("wxICON_INFORMATION"), wxICON_INFORMATION
},
2310 { wxT("wxICON_STOP"), wxICON_STOP
},
2311 { wxT("wxICON_ASTERISK"), wxICON_ASTERISK
},
2312 { wxT("wxICON_MASK"), wxICON_MASK
},
2313 { wxT("wxCENTRE"), wxCENTRE
},
2314 { wxT("wxCENTER"), wxCENTRE
},
2315 { wxT("wxUSER_COLOURS"), wxUSER_COLOURS
},
2316 { wxT("wxVERTICAL_LABEL"), 0},
2317 { wxT("wxHORIZONTAL_LABEL"), 0},
2319 // Bitmap types (not strictly styles)
2320 { wxT("wxBITMAP_TYPE_XPM"), wxBITMAP_TYPE_XPM
},
2321 { wxT("wxBITMAP_TYPE_XBM"), wxBITMAP_TYPE_XBM
},
2322 { wxT("wxBITMAP_TYPE_BMP"), wxBITMAP_TYPE_BMP
},
2323 { wxT("wxBITMAP_TYPE_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2324 { wxT("wxBITMAP_TYPE_BMP_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2325 { wxT("wxBITMAP_TYPE_GIF"), wxBITMAP_TYPE_GIF
},
2326 { wxT("wxBITMAP_TYPE_TIF"), wxBITMAP_TYPE_TIF
},
2327 { wxT("wxBITMAP_TYPE_ICO"), wxBITMAP_TYPE_ICO
},
2328 { wxT("wxBITMAP_TYPE_ICO_RESOURCE"), wxBITMAP_TYPE_ICO_RESOURCE
},
2329 { wxT("wxBITMAP_TYPE_CUR"), wxBITMAP_TYPE_CUR
},
2330 { wxT("wxBITMAP_TYPE_CUR_RESOURCE"), wxBITMAP_TYPE_CUR_RESOURCE
},
2331 { wxT("wxBITMAP_TYPE_XBM_DATA"), wxBITMAP_TYPE_XBM_DATA
},
2332 { wxT("wxBITMAP_TYPE_XPM_DATA"), wxBITMAP_TYPE_XPM_DATA
},
2333 { wxT("wxBITMAP_TYPE_ANY"), wxBITMAP_TYPE_ANY
}
2336 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
2338 long wxParseWindowStyle(const wxString
& bitListString
)
2343 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2344 while (word
!= NULL
)
2348 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2349 if (wxStrcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2351 bitList
|= wxResourceBitListTable
[j
].bits
;
2357 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word
);
2360 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2366 * Load a bitmap from a wxWindows resource, choosing an optimum
2367 * depth and appropriate type.
2370 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
2373 table
= wxDefaultResourceTable
;
2375 wxItemResource
*item
= table
->FindResource(resource
);
2378 if ((item
->GetType() == wxT("")) || (item
->GetType() != wxT("wxBitmap")))
2380 wxLogWarning(_("%s not a bitmap resource specification."), (const wxChar
*) resource
);
2381 return wxNullBitmap
;
2383 int thisDepth
= wxDisplayDepth();
2384 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2386 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2388 // Try to find optimum bitmap for this platform/colour depth
2389 wxNode
*node
= item
->GetChildren().First();
2392 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2393 int platform
= (int)child
->GetValue2();
2394 int noColours
= (int)child
->GetValue3();
2396 char *name = child->GetName();
2397 int bitmapType = (int)child->GetValue1();
2398 int xRes = child->GetWidth();
2399 int yRes = child->GetHeight();
2404 case RESOURCE_PLATFORM_ANY
:
2406 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2407 optResource
= child
;
2410 // Maximise the number of colours.
2411 // If noColours is zero (unspecified), then assume this
2412 // is the right one.
2413 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2414 optResource
= child
;
2419 case RESOURCE_PLATFORM_WINDOWS
:
2421 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2422 optResource
= child
;
2425 // Maximise the number of colours
2426 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2427 optResource
= child
;
2433 case RESOURCE_PLATFORM_X
:
2435 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2436 optResource
= child
;
2439 // Maximise the number of colours
2440 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2441 optResource
= child
;
2447 case RESOURCE_PLATFORM_MAC
:
2449 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2450 optResource
= child
;
2453 // Maximise the number of colours
2454 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2455 optResource
= child
;
2463 node
= node
->Next();
2465 // If no matching resource, fail.
2467 return wxNullBitmap
;
2469 wxString name
= optResource
->GetName();
2470 int bitmapType
= (int)optResource
->GetValue1();
2473 case wxBITMAP_TYPE_XBM_DATA
:
2476 wxItemResource
*item
= table
->FindResource(name
);
2479 wxLogWarning(_("Failed to find XBM resource %s.\n"
2480 "Forgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2481 return wxNullBitmap
;
2483 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2485 wxLogWarning(_("No XBM facility available!"));
2489 case wxBITMAP_TYPE_XPM_DATA
:
2491 wxItemResource
*item
= table
->FindResource(name
);
2494 wxLogWarning(_("Failed to find XPM resource %s.\nForgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2495 return wxNullBitmap
;
2497 return wxBitmap((char **)item
->GetValue1());
2501 #if defined(__WXPM__)
2502 return wxNullBitmap
;
2504 return wxBitmap(name
, (wxBitmapType
)bitmapType
);
2509 return wxNullBitmap
;
2514 wxLogWarning(_("Bitmap resource specification %s not found."), (const wxChar
*) resource
);
2515 return wxNullBitmap
;
2520 * Load an icon from a wxWindows resource, choosing an optimum
2521 * depth and appropriate type.
2524 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2527 table
= wxDefaultResourceTable
;
2529 wxItemResource
*item
= table
->FindResource(resource
);
2532 if ((item
->GetType() == wxT("")) || wxStrcmp(item
->GetType(), wxT("wxIcon")) != 0)
2534 wxLogWarning(_("%s not an icon resource specification."), (const wxChar
*) resource
);
2537 int thisDepth
= wxDisplayDepth();
2538 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2540 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2542 // Try to find optimum icon for this platform/colour depth
2543 wxNode
*node
= item
->GetChildren().First();
2546 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2547 int platform
= (int)child
->GetValue2();
2548 int noColours
= (int)child
->GetValue3();
2550 char *name = child->GetName();
2551 int bitmapType = (int)child->GetValue1();
2552 int xRes = child->GetWidth();
2553 int yRes = child->GetHeight();
2558 case RESOURCE_PLATFORM_ANY
:
2560 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2561 optResource
= child
;
2564 // Maximise the number of colours.
2565 // If noColours is zero (unspecified), then assume this
2566 // is the right one.
2567 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2568 optResource
= child
;
2573 case RESOURCE_PLATFORM_WINDOWS
:
2575 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2576 optResource
= child
;
2579 // Maximise the number of colours
2580 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2581 optResource
= child
;
2587 case RESOURCE_PLATFORM_X
:
2589 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2590 optResource
= child
;
2593 // Maximise the number of colours
2594 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2595 optResource
= child
;
2601 case RESOURCE_PLATFORM_MAC
:
2603 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2604 optResource
= child
;
2607 // Maximise the number of colours
2608 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2609 optResource
= child
;
2617 node
= node
->Next();
2619 // If no matching resource, fail.
2623 wxString name
= optResource
->GetName();
2624 int bitmapType
= (int)optResource
->GetValue1();
2627 case wxBITMAP_TYPE_XBM_DATA
:
2630 wxItemResource
*item
= table
->FindResource(name
);
2633 wxLogWarning(_("Failed to find XBM resource %s.\n"
2634 "Forgot to use wxResourceLoadIconData?"), (const wxChar
*) name
);
2637 return wxIcon((const char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2639 wxLogWarning(_("No XBM facility available!"));
2643 case wxBITMAP_TYPE_XPM_DATA
:
2645 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2647 wxItemResource *item = table->FindResource(name);
2651 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2655 return wxIcon((char **)item->GetValue1());
2657 wxLogWarning(_("No XPM icon facility available!"));
2662 #if defined( __WXGTK__ ) || defined( __WXMOTIF__ )
2663 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2666 return wxIcon(name
, (wxBitmapType
) bitmapType
);
2674 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2681 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2683 wxMenu
*menu
= new wxMenu
;
2684 wxNode
*node
= item
->GetChildren().First();
2687 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2688 if ((child
->GetType() != wxT("")) && (child
->GetType() == wxT("wxMenuSeparator")))
2689 menu
->AppendSeparator();
2690 else if (child
->GetChildren().Number() > 0)
2692 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2694 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2698 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2700 node
= node
->Next();
2705 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2708 table
= wxDefaultResourceTable
;
2710 wxItemResource
*menuResource
= table
->FindResource(resource
);
2711 if (menuResource
&& (menuResource
->GetType() != wxT("")) && (menuResource
->GetType() == wxT("wxMenu")))
2714 menuBar
= new wxMenuBar
;
2715 wxNode
*node
= menuResource
->GetChildren().First();
2718 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2719 wxMenu
*menu
= wxResourceCreateMenu(child
);
2721 menuBar
->Append(menu
, child
->GetTitle());
2722 node
= node
->Next();
2726 return (wxMenuBar
*) NULL
;
2729 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2732 table
= wxDefaultResourceTable
;
2734 wxItemResource
*menuResource
= table
->FindResource(resource
);
2735 if (menuResource
&& (menuResource
->GetType() != wxT("")) && (menuResource
->GetType() == wxT("wxMenu")))
2736 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2737 return wxResourceCreateMenu(menuResource
);
2738 return (wxMenu
*) NULL
;
2741 #endif // wxUSE_MENUS
2743 // Global equivalents (so don't have to refer to default table explicitly)
2744 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2747 table
= wxDefaultResourceTable
;
2749 return table
->ParseResourceData(resource
);
2752 bool wxResourceParseData(const char* resource
, wxResourceTable
*table
)
2754 wxString
str(resource
, wxConvLibc
);
2756 table
= wxDefaultResourceTable
;
2758 return table
->ParseResourceData(str
);
2761 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2764 table
= wxDefaultResourceTable
;
2766 return table
->ParseResourceFile(filename
);
2769 // Register XBM/XPM data
2770 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2773 table
= wxDefaultResourceTable
;
2775 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2778 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2781 table
= wxDefaultResourceTable
;
2783 return table
->RegisterResourceBitmapData(name
, data
);
2786 void wxResourceClear(wxResourceTable
*table
)
2789 table
= wxDefaultResourceTable
;
2791 table
->ClearTable();
2798 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2801 table
= wxDefaultResourceTable
;
2803 table
->identifiers
.Put(name
, (wxObject
*)(long)value
);
2807 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2810 table
= wxDefaultResourceTable
;
2812 return (int)(long)table
->identifiers
.Get(name
);
2816 * Parse #include file for #defines (only)
2819 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2822 table
= wxDefaultResourceTable
;
2824 FILE *fd
= wxFopen(f
, wxT("r"));
2829 while (wxGetResourceToken(fd
))
2831 if (strcmp(wxResourceBuffer
, "#define") == 0)
2833 wxGetResourceToken(fd
);
2834 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2835 wxGetResourceToken(fd
);
2836 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2837 if (wxIsdigit(value
[0]))
2839 int val
= (int)wxAtol(value
);
2840 wxResourceAddIdentifier(name
, val
, table
);
2851 * Reading strings as if they were .wxr files
2854 static int getc_string(char *s
)
2856 int ch
= s
[wxResourceStringPtr
];
2861 wxResourceStringPtr
++;
2866 static int ungetc_string()
2868 wxResourceStringPtr
--;
2872 bool wxEatWhiteSpaceString(char *s
)
2876 while ((ch
= getc_string(s
)) != EOF
)
2888 ch
= getc_string(s
);
2899 while ((ch
= getc_string(s
)) != EOF
)
2901 if (ch
== '/' && prev_ch
== '*')
2923 bool wxGetResourceTokenString(char *s
)
2925 if (!wxResourceBuffer
)
2926 wxReallocateResourceBuffer();
2927 wxResourceBuffer
[0] = 0;
2928 wxEatWhiteSpaceString(s
);
2930 int ch
= getc_string(s
);
2934 wxResourceBufferCount
= 0;
2935 ch
= getc_string(s
);
2941 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2944 // Escaped characters
2945 else if (ch
== '\\')
2947 int newCh
= getc_string(s
);
2950 else if (newCh
== 10)
2958 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2959 wxReallocateResourceBuffer();
2960 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2961 wxResourceBufferCount
++;
2962 ch
= getc_string(s
);
2964 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2968 wxResourceBufferCount
= 0;
2970 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2972 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2973 wxReallocateResourceBuffer();
2974 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2975 wxResourceBufferCount
++;
2977 ch
= getc_string(s
);
2979 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2987 * Files are in form:
2988 static char *name = "....";
2989 with possible comments.
2992 bool wxResourceReadOneResourceString(char *s
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2995 table
= wxDefaultResourceTable
;
2997 // static or #define
2998 if (!wxGetResourceTokenString(s
))
3004 if (strcmp(wxResourceBuffer
, "#define") == 0)
3006 wxGetResourceTokenString(s
);
3007 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
3008 wxGetResourceTokenString(s
);
3009 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
3010 if (wxIsdigit(value
[0]))
3012 int val
= (int)wxAtol(value
);
3013 wxResourceAddIdentifier(name
, val
, table
);
3017 wxLogWarning(_("#define %s must be an integer."), name
);
3028 else if (strcmp(wxResourceBuffer, "#include") == 0)
3030 wxGetResourceTokenString(s);
3031 char *name = copystring(wxResourceBuffer);
3032 char *actualName = name;
3034 actualName = name + 1;
3035 int len = strlen(name);
3036 if ((len > 0) && (name[len-1] == '"'))
3038 if (!wxResourceParseIncludeFile(actualName, table))
3041 sprintf(buf, _("Could not find resource include file %s."), actualName);
3048 else if (strcmp(wxResourceBuffer
, "static") != 0)
3051 wxStrcpy(buf
, _("Found "));
3052 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
3053 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
3059 if (!wxGetResourceTokenString(s
))
3061 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3066 if (strcmp(wxResourceBuffer
, "char") != 0)
3068 wxLogWarning(_("Expected 'char' whilst parsing resource."));
3073 if (!wxGetResourceTokenString(s
))
3075 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3080 if (wxResourceBuffer
[0] != '*')
3082 wxLogWarning(_("Expected '*' whilst parsing resource."));
3085 wxChar nameBuf
[100];
3086 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
3090 if (!wxGetResourceTokenString(s
))
3092 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3097 if (strcmp(wxResourceBuffer
, "=") != 0)
3099 wxLogWarning(_("Expected '=' whilst parsing resource."));
3104 if (!wxGetResourceTokenString(s
))
3106 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3112 if (!db
.ReadPrologFromString(wxResourceBuffer
))
3114 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
3119 if (!wxGetResourceTokenString(s
))
3126 bool wxResourceParseString(const wxString
& s
, wxResourceTable
*table
)
3129 return wxResourceParseString( (char*)s
.mb_str().data() );
3131 return wxResourceParseString( (char*)s
.c_str() );
3135 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
3138 table
= wxDefaultResourceTable
;
3143 // Turn backslashes into spaces
3146 int len
= strlen(s
);
3148 for (i
= 0; i
< len
; i
++)
3149 if (s
[i
] == 92 && s
[i
+1] == 13)
3157 wxResourceStringPtr
= 0;
3160 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
3164 return wxResourceInterpretResources(*table
, db
);
3168 * resource loading facility
3171 bool wxLoadFromResource(wxWindow
* thisWindow
, wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
3174 table
= wxDefaultResourceTable
;
3176 wxItemResource
*resource
= table
->FindResource((const wxChar
*)resourceName
);
3177 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
3178 if (!resource
|| (resource
->GetType() == wxT("")) ||
3179 ! ((resource
->GetType() == wxT("wxDialog")) || (resource
->GetType() == wxT("wxPanel"))))
3182 wxString
title(resource
->GetTitle());
3183 long theWindowStyle
= resource
->GetStyle();
3184 bool isModal
= (resource
->GetValue1() != 0) ;
3185 int x
= resource
->GetX();
3186 int y
= resource
->GetY();
3187 int width
= resource
->GetWidth();
3188 int height
= resource
->GetHeight();
3189 wxString name
= resource
->GetName();
3191 // this is used for loading wxWizard pages from WXR
3192 if ( parent
!= thisWindow
)
3194 if (thisWindow
->IsKindOf(CLASSINFO(wxDialog
)))
3196 wxDialog
*dialogBox
= (wxDialog
*)thisWindow
;
3197 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
3198 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
3201 // Only reset the client size if we know we're not going to do it again below.
3202 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == 0)
3203 dialogBox
->SetClientSize(width
, height
);
3205 else if (thisWindow
->IsKindOf(CLASSINFO(wxPanel
)))
3207 wxPanel
* panel
= (wxPanel
*)thisWindow
;
3208 if (!panel
->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
| wxTAB_TRAVERSAL
, name
))
3213 if (!((wxWindow
*)thisWindow
)->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
3218 if ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
3220 // No need to do this since it's done in wxPanel or wxDialog constructor.
3221 // SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
3225 if (resource
->GetFont().Ok())
3226 thisWindow
->SetFont(resource
->GetFont());
3227 if (resource
->GetBackgroundColour().Ok())
3228 thisWindow
->SetBackgroundColour(resource
->GetBackgroundColour());
3231 // Should have some kind of font at this point
3232 if (!thisWindow
->GetFont().Ok())
3233 thisWindow
->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
3234 if (!thisWindow
->GetBackgroundColour().Ok())
3235 thisWindow
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
3237 // Only when we've created the window and set the font can we set the correct size,
3238 // if based on dialog units.
3239 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
3241 wxSize sz
= thisWindow
->ConvertDialogToPixels(wxSize(width
, height
));
3242 thisWindow
->SetClientSize(sz
.x
, sz
.y
);
3244 wxPoint pt
= thisWindow
->ConvertDialogToPixels(wxPoint(x
, y
));
3245 thisWindow
->Move(pt
.x
, pt
.y
);
3248 // Now create children
3249 wxNode
*node
= resource
->GetChildren().First();
3252 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
3254 (void) wxCreateItem(thisWindow
, childResource
, resource
, table
);
3256 node
= node
->Next();
3261 wxControl
*wxCreateItem(wxWindow
* thisWindow
, const wxItemResource
*resource
, const wxItemResource
* parentResource
, const wxResourceTable
*table
)
3264 table
= wxDefaultResourceTable
;
3265 return table
->CreateItem(thisWindow
, resource
, parentResource
);
3269 #pragma warning(default:4706) // assignment within conditional expression
3272 #endif // wxUSE_WX_RESOURCES