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 static inline wxChar
* copystring(const wxChar
* s
)
93 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
95 // Forward (private) declarations
96 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
);
97 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
= FALSE
);
98 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
);
99 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
);
100 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
);
101 wxItemResource
*wxResourceInterpretString(wxResourceTable
& table
, wxExpr
*expr
);
102 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& table
, wxExpr
*expr
);
103 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
);
104 // Interpret list expression
105 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
);
107 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
108 bool wxResourceReadOneResource(wxInputStream
*fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
) ;
109 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
111 wxResourceTable
*wxDefaultResourceTable
= (wxResourceTable
*) NULL
;
113 char *wxResourceBuffer
= (char *) NULL
;
114 long wxResourceBufferSize
= 0;
115 long wxResourceBufferCount
= 0;
116 int wxResourceStringPtr
= 0;
118 void wxInitializeResourceSystem()
120 if (!wxDefaultResourceTable
)
121 wxDefaultResourceTable
= new wxResourceTable
;
124 void wxCleanUpResourceSystem()
126 delete wxDefaultResourceTable
;
127 if (wxResourceBuffer
)
128 delete[] wxResourceBuffer
;
131 // Module to ensure the resource system data gets initialized
134 class wxResourceModule
: public wxModule
137 wxResourceModule() : wxModule() {}
138 virtual bool OnInit() { wxInitializeResourceSystem(); return TRUE
; }
139 virtual void OnExit() { wxCleanUpResourceSystem(); }
141 DECLARE_DYNAMIC_CLASS(wxResourceModule
)
144 IMPLEMENT_DYNAMIC_CLASS(wxResourceModule
, wxModule
)
147 IMPLEMENT_DYNAMIC_CLASS(wxItemResource
, wxObject
)
148 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable
, wxHashTable
)
150 wxItemResource::wxItemResource()
152 m_itemType
= wxT("");
156 m_x
= m_y
= m_width
= m_height
= 0;
157 m_value1
= m_value2
= m_value3
= m_value5
= 0;
163 wxItemResource::~wxItemResource()
165 wxNode
*node
= m_children
.First();
168 wxItemResource
*item
= (wxItemResource
*)node
->Data();
171 node
= m_children
.First();
179 wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
)
183 wxResourceTable::~wxResourceTable()
188 wxItemResource
*wxResourceTable::FindResource(const wxString
& name
) const
190 wxItemResource
*item
= (wxItemResource
*)Get(WXSTRINGCAST name
);
194 void wxResourceTable::AddResource(wxItemResource
*item
)
196 wxString name
= item
->GetName();
198 name
= item
->GetTitle();
200 name
= wxT("no name");
202 // Delete existing resource, if any.
208 bool wxResourceTable::DeleteResource(const wxString
& name
)
210 wxItemResource
*item
= (wxItemResource
*)Delete(WXSTRINGCAST name
);
213 // See if any resource has this as its child; if so, delete from
214 // parent's child list.
216 wxNode
*node
= (wxNode
*) NULL
;
220 wxItemResource
*parent
= (wxItemResource
*)node
->Data();
221 if (parent
->GetChildren().Member(item
))
223 parent
->GetChildren().DeleteObject(item
);
236 bool wxResourceTable::ParseResourceFile( wxInputStream
*is
)
239 int len
= is
->GetSize() ;
242 while ( is
->TellI() + 10 < len
) // it's a hack because the streams dont support EOF
244 wxResourceReadOneResource(is
, db
, &eof
, this) ;
246 return wxResourceInterpretResources(*this, db
);
249 bool wxResourceTable::ParseResourceFile(const wxString
& filename
)
253 FILE *fd
= wxFopen(filename
, wxT("r"));
257 while (wxResourceReadOneResource(fd
, db
, &eof
, this) && !eof
)
262 return wxResourceInterpretResources(*this, db
);
265 bool wxResourceTable::ParseResourceData(const wxString
& data
)
268 if (!db
.ReadFromString(data
))
270 wxLogWarning(_("Ill-formed resource file syntax."));
274 return wxResourceInterpretResources(*this, db
);
277 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char bits
[], int width
, int height
)
279 // Register pre-loaded bitmap data
280 wxItemResource
*item
= new wxItemResource
;
281 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
282 item
->SetType(wxT("wxXBMData"));
284 item
->SetValue1((long)bits
);
285 item
->SetValue2((long)width
);
286 item
->SetValue3((long)height
);
291 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char **data
)
293 // Register pre-loaded bitmap data
294 wxItemResource
*item
= new wxItemResource
;
295 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
296 item
->SetType(wxT("wxXPMData"));
298 item
->SetValue1((long)data
);
303 bool wxResourceTable::SaveResource(const wxString
& WXUNUSED(filename
))
308 void wxResourceTable::ClearTable()
311 wxNode
*node
= Next();
314 wxNode
*next
= Next();
315 wxItemResource
*item
= (wxItemResource
*)node
->Data();
322 wxControl
*wxResourceTable::CreateItem(wxWindow
*parent
, const wxItemResource
* childResource
, const wxItemResource
* parentResource
) const
324 int id
= childResource
->GetId();
328 bool dlgUnits
= ((parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0);
330 wxControl
*control
= (wxControl
*) NULL
;
331 wxString
itemType(childResource
->GetType());
337 pos
= parent
->ConvertDialogToPixels(wxPoint(childResource
->GetX(), childResource
->GetY()));
338 size
= parent
->ConvertDialogToPixels(wxSize(childResource
->GetWidth(), childResource
->GetHeight()));
342 pos
= wxPoint(childResource
->GetX(), childResource
->GetY());
343 size
= wxSize(childResource
->GetWidth(), childResource
->GetHeight());
346 if (itemType
== wxString(wxT("wxButton")) || itemType
== wxString(wxT("wxBitmapButton")))
348 if (childResource
->GetValue4() != wxT(""))
351 wxBitmap bitmap
= childResource
->GetBitmap();
354 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
355 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
358 #if defined(__WXPM__)
360 // OS/2 uses integer id's to access resources, not file name strings
362 bitmap
.LoadFile(wxCROSS_BITMAP
, wxBITMAP_TYPE_BMP_RESOURCE
);
364 bitmap
.LoadFile(wxT("cross_bmp"), wxBITMAP_TYPE_BMP_RESOURCE
);
366 control
= new wxBitmapButton(parent
, id
, bitmap
, pos
, size
,
367 childResource
->GetStyle() | wxBU_AUTODRAW
, wxDefaultValidator
, childResource
->GetName());
370 // Normal, text button
371 control
= new wxButton(parent
, id
, childResource
->GetTitle(), pos
, size
,
372 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
374 else if (itemType
== wxString(wxT("wxMessage")) || itemType
== wxString(wxT("wxStaticText")) ||
375 itemType
== wxString(wxT("wxStaticBitmap")))
377 if (childResource
->GetValue4() != wxT("") || itemType
== wxString(wxT("wxStaticBitmap")) )
380 wxBitmap bitmap
= childResource
->GetBitmap();
383 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
384 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
386 #if wxUSE_BITMAP_MESSAGE
388 // Use a default bitmap
390 bitmap
.LoadFile(wxT("cross_bmp"), wxBITMAP_TYPE_BMP_RESOURCE
);
394 control
= new wxStaticBitmap(parent
, id
, bitmap
, pos
, size
,
395 childResource
->GetStyle(), childResource
->GetName());
400 control
= new wxStaticText(parent
, id
, childResource
->GetTitle(), pos
, size
,
401 childResource
->GetStyle(), childResource
->GetName());
404 else if (itemType
== wxString(wxT("wxText")) || itemType
== wxString(wxT("wxTextCtrl")) || itemType
== wxString(wxT("wxMultiText")))
406 control
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(), pos
, size
,
407 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
409 else if (itemType
== wxString(wxT("wxCheckBox")))
411 control
= new wxCheckBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
412 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
414 ((wxCheckBox
*)control
)->SetValue((childResource
->GetValue1() != 0));
417 else if (itemType
== wxString(wxT("wxGauge")))
419 control
= new wxGauge(parent
, id
, (int)childResource
->GetValue2(), pos
, size
,
420 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
422 ((wxGauge
*)control
)->SetValue((int)childResource
->GetValue1());
426 else if (itemType
== wxString(wxT("wxRadioButton")))
428 control
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(),
430 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
434 else if (itemType
== wxString(wxT("wxScrollBar")))
436 control
= new wxScrollBar(parent
, id
, pos
, size
,
437 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
439 ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1());
440 ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2());
441 ((wxScrollBar *)control)->SetObjectLength((int)childResource->GetValue3());
442 ((wxScrollBar *)control)->SetViewLength((int)(long)childResource->GetValue5());
444 ((wxScrollBar
*)control
)->SetScrollbar((int)childResource
->GetValue1(),(int)childResource
->GetValue2(),
445 (int)childResource
->GetValue3(),(int)(long)childResource
->GetValue5(),FALSE
);
449 else if (itemType
== wxString(wxT("wxSlider")))
451 control
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(),
452 (int)childResource
->GetValue2(), (int)childResource
->GetValue3(), pos
, size
,
453 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
455 else if (itemType
== wxString(wxT("wxGroupBox")) || itemType
== wxString(wxT("wxStaticBox")))
457 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
458 childResource
->GetStyle(), childResource
->GetName());
460 else if (itemType
== wxString(wxT("wxListBox")))
462 wxStringList
& stringList
= childResource
->GetStringValues();
463 wxString
*strings
= (wxString
*) NULL
;
465 if (stringList
.Number() > 0)
467 noStrings
= stringList
.Number();
468 strings
= new wxString
[noStrings
];
469 wxNode
*node
= stringList
.First();
473 strings
[i
] = (wxChar
*)node
->Data();
478 control
= new wxListBox(parent
, id
, pos
, size
,
479 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
484 else if (itemType
== wxString(wxT("wxChoice")))
486 wxStringList
& stringList
= childResource
->GetStringValues();
487 wxString
*strings
= (wxString
*) NULL
;
489 if (stringList
.Number() > 0)
491 noStrings
= stringList
.Number();
492 strings
= new wxString
[noStrings
];
493 wxNode
*node
= stringList
.First();
497 strings
[i
] = (wxChar
*)node
->Data();
502 control
= new wxChoice(parent
, id
, pos
, size
,
503 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
509 else if (itemType
== wxString(wxT("wxComboBox")))
511 wxStringList
& stringList
= childResource
->GetStringValues();
512 wxString
*strings
= (wxString
*) NULL
;
514 if (stringList
.Number() > 0)
516 noStrings
= stringList
.Number();
517 strings
= new wxString
[noStrings
];
518 wxNode
*node
= stringList
.First();
522 strings
[i
] = (wxChar
*)node
->Data();
527 control
= new wxComboBox(parent
, id
, childResource
->GetValue4(), pos
, size
,
528 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
534 else if (itemType
== wxString(wxT("wxRadioBox")))
536 wxStringList
& stringList
= childResource
->GetStringValues();
537 wxString
*strings
= (wxString
*) NULL
;
539 if (stringList
.Number() > 0)
541 noStrings
= stringList
.Number();
542 strings
= new wxString
[noStrings
];
543 wxNode
*node
= stringList
.First();
547 strings
[i
] = (wxChar
*)node
->Data();
552 control
= new wxRadioBox(parent
, (wxWindowID
) id
, wxString(childResource
->GetTitle()), pos
, size
,
553 noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
,
554 childResource
->GetName());
560 if ((parentResource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
562 // Don't set font; will be inherited from parent.
566 if (control
&& childResource
->GetFont().Ok())
568 control
->SetFont(childResource
->GetFont());
571 // Force the layout algorithm since the size changes the layout
572 if (control
->IsKindOf(CLASSINFO(wxRadioBox
)))
574 control
->SetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
|wxSIZE_AUTO_HEIGHT
);
583 * Interpret database as a series of resources
586 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
)
588 wxNode
*node
= db
.First();
591 wxExpr
*clause
= (wxExpr
*)node
->Data();
592 wxString
functor(clause
->Functor());
594 wxItemResource
*item
= (wxItemResource
*) NULL
;
595 if (functor
== wxT("dialog"))
596 item
= wxResourceInterpretDialog(table
, clause
);
597 else if (functor
== wxT("panel"))
598 item
= wxResourceInterpretDialog(table
, clause
, TRUE
);
599 else if (functor
== wxT("menubar"))
600 item
= wxResourceInterpretMenuBar(table
, clause
);
601 else if (functor
== wxT("menu"))
602 item
= wxResourceInterpretMenu(table
, clause
);
603 else if (functor
== wxT("string"))
604 item
= wxResourceInterpretString(table
, clause
);
605 else if (functor
== wxT("bitmap"))
606 item
= wxResourceInterpretBitmap(table
, clause
);
607 else if (functor
== wxT("icon"))
608 item
= wxResourceInterpretIcon(table
, clause
);
612 // Remove any existing resource of same name
613 if (item
->GetName() != wxT(""))
614 table
.DeleteResource(item
->GetName());
615 table
.AddResource(item
);
622 static const wxChar
*g_ValidControlClasses
[] =
625 wxT("wxBitmapButton"),
628 wxT("wxStaticBitmap"),
634 wxT("wxRadioButton"),
636 wxT("wxBitmapCheckBox"),
646 static bool wxIsValidControlClass(const wxString
& c
)
648 for ( size_t i
= 0; i
< WXSIZEOF(g_ValidControlClasses
); i
++ )
650 if ( c
== g_ValidControlClasses
[i
] )
656 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
)
658 wxItemResource
*dialogItem
= new wxItemResource
;
660 dialogItem
->SetType(wxT("wxPanel"));
662 dialogItem
->SetType(wxT("wxDialog"));
663 wxString style
= wxT("");
664 wxString title
= wxT("");
665 wxString name
= wxT("");
666 wxString backColourHex
= wxT("");
667 wxString labelColourHex
= wxT("");
668 wxString buttonColourHex
= wxT("");
670 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
674 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
676 wxExpr
*labelFontExpr
= (wxExpr
*) NULL
;
677 wxExpr
*buttonFontExpr
= (wxExpr
*) NULL
;
678 wxExpr
*fontExpr
= (wxExpr
*) NULL
;
679 expr
->GetAttributeValue(wxT("style"), style
);
680 expr
->GetAttributeValue(wxT("name"), name
);
681 expr
->GetAttributeValue(wxT("title"), title
);
682 expr
->GetAttributeValue(wxT("x"), x
);
683 expr
->GetAttributeValue(wxT("y"), y
);
684 expr
->GetAttributeValue(wxT("width"), width
);
685 expr
->GetAttributeValue(wxT("height"), height
);
686 expr
->GetAttributeValue(wxT("modal"), isModal
);
687 expr
->GetAttributeValue(wxT("label_font"), &labelFontExpr
);
688 expr
->GetAttributeValue(wxT("button_font"), &buttonFontExpr
);
689 expr
->GetAttributeValue(wxT("font"), &fontExpr
);
690 expr
->GetAttributeValue(wxT("background_colour"), backColourHex
);
691 expr
->GetAttributeValue(wxT("label_colour"), labelColourHex
);
692 expr
->GetAttributeValue(wxT("button_colour"), buttonColourHex
);
694 int useDialogUnits
= 0;
695 expr
->GetAttributeValue(wxT("use_dialog_units"), useDialogUnits
);
696 if (useDialogUnits
!= 0)
697 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS
);
700 expr
->GetAttributeValue(wxT("use_system_defaults"), useDefaults
);
701 if (useDefaults
!= 0)
702 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS
);
705 expr
->GetAttributeValue(wxT("id"), id
);
706 dialogItem
->SetId(id
);
708 if (style
!= wxT(""))
710 windowStyle
= wxParseWindowStyle(style
);
712 dialogItem
->SetStyle(windowStyle
);
713 dialogItem
->SetValue1(isModal
);
714 if (windowStyle
& wxDIALOG_MODAL
) // Uses style in wxWin 2
715 dialogItem
->SetValue1(TRUE
);
717 dialogItem
->SetName(name
);
718 dialogItem
->SetTitle(title
);
719 dialogItem
->SetSize(x
, y
, width
, height
);
721 // Check for wxWin 1.68-style specifications
722 if (style
.Find(wxT("VERTICAL_LABEL")) != -1)
723 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL
);
724 else if (style
.Find(wxT("HORIZONTAL_LABEL")) != -1)
725 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL
);
727 if (backColourHex
!= wxT(""))
732 r
= wxHexToDec(backColourHex
.Mid(0, 2));
733 g
= wxHexToDec(backColourHex
.Mid(2, 2));
734 b
= wxHexToDec(backColourHex
.Mid(4, 2));
735 dialogItem
->SetBackgroundColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
737 if (labelColourHex
!= wxT(""))
742 r
= wxHexToDec(labelColourHex
.Mid(0, 2));
743 g
= wxHexToDec(labelColourHex
.Mid(2, 2));
744 b
= wxHexToDec(labelColourHex
.Mid(4, 2));
745 dialogItem
->SetLabelColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
747 if (buttonColourHex
!= wxT(""))
752 r
= wxHexToDec(buttonColourHex
.Mid(0, 2));
753 g
= wxHexToDec(buttonColourHex
.Mid(2, 2));
754 b
= wxHexToDec(buttonColourHex
.Mid(4, 2));
755 dialogItem
->SetButtonColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
759 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
760 else if (buttonFontExpr
)
761 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
762 else if (labelFontExpr
)
763 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
765 // Now parse all controls
766 wxExpr
*controlExpr
= expr
->GetFirst();
769 if (controlExpr
->Number() == 3)
771 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
772 if (controlKeyword
!= wxT("") && controlKeyword
== wxT("control"))
774 // The value part: always a list.
775 wxExpr
*listExpr
= controlExpr
->Nth(2);
776 if (listExpr
->Type() == PrologList
)
778 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
781 dialogItem
->GetChildren().Append(controlItem
);
786 controlExpr
= controlExpr
->GetNext();
791 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
)
793 wxItemResource
*controlItem
= new wxItemResource
;
795 // First, find the standard features of a control definition:
796 // [optional integer/string id], control name, title, style, name, x, y, width, height
798 wxString controlType
;
803 long windowStyle
= 0;
804 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
807 wxExpr
*expr1
= expr
->Nth(0);
809 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
811 if ( wxIsValidControlClass(expr1
->StringValue()) )
814 controlType
= expr1
->StringValue();
818 wxString
str(expr1
->StringValue());
819 id
= wxResourceGetIdentifier(str
, &table
);
822 wxLogWarning(_("Could not resolve control class or id '%s'. Use (non-zero) integer instead\n or provide #define (see manual for caveats)"),
823 (const wxChar
*) expr1
->StringValue());
825 return (wxItemResource
*) NULL
;
829 // Success - we have an id, so the 2nd element must be the control class.
830 controlType
= expr
->Nth(1)->StringValue();
835 else if (expr1
->Type() == PrologInteger
)
837 id
= (int)expr1
->IntegerValue();
838 // Success - we have an id, so the 2nd element must be the control class.
839 controlType
= expr
->Nth(1)->StringValue();
843 expr1
= expr
->Nth(count
);
846 title
= expr1
->StringValue();
848 expr1
= expr
->Nth(count
);
852 style
= expr1
->StringValue();
853 windowStyle
= wxParseWindowStyle(style
);
856 expr1
= expr
->Nth(count
);
859 name
= expr1
->StringValue();
861 expr1
= expr
->Nth(count
);
864 x
= (int)expr1
->IntegerValue();
866 expr1
= expr
->Nth(count
);
869 y
= (int)expr1
->IntegerValue();
871 expr1
= expr
->Nth(count
);
874 width
= (int)expr1
->IntegerValue();
876 expr1
= expr
->Nth(count
);
879 height
= (int)expr1
->IntegerValue();
881 controlItem
->SetStyle(windowStyle
);
882 controlItem
->SetName(name
);
883 controlItem
->SetTitle(title
);
884 controlItem
->SetSize(x
, y
, width
, height
);
885 controlItem
->SetType(controlType
);
886 controlItem
->SetId(id
);
888 // Check for wxWin 1.68-style specifications
889 if (style
.Find(wxT("VERTICAL_LABEL")) != -1)
890 controlItem
->SetResourceStyle(controlItem
->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL
);
891 else if (style
.Find(wxT("HORIZONTAL_LABEL")) != -1)
892 controlItem
->SetResourceStyle(controlItem
->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL
);
894 if (controlType
== wxT("wxButton"))
896 // Check for bitmap resource name (in case loading old-style resource file)
897 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
899 wxString
str(expr
->Nth(count
)->StringValue());
904 controlItem
->SetValue4(str
);
905 controlItem
->SetType(wxT("wxBitmapButton"));
908 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
909 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
911 else if (controlType
== wxT("wxBitmapButton"))
913 // Check for bitmap resource name
914 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
916 wxString
str(expr
->Nth(count
)->StringValue());
917 controlItem
->SetValue4(str
);
919 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
920 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
923 else if (controlType
== wxT("wxCheckBox"))
925 // Check for default value
926 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
928 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
930 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
931 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
935 else if (controlType
== wxT("wxRadioButton"))
937 // Check for default value
938 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
940 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
942 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
943 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
947 else if (controlType
== wxT("wxText") || controlType
== wxT("wxTextCtrl") || controlType
== wxT("wxMultiText"))
949 // Check for default value
950 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
952 wxString
str(expr
->Nth(count
)->StringValue());
953 controlItem
->SetValue4(str
);
956 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
958 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
959 // Skip past the obsolete label font spec if there are two consecutive specs
960 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
962 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
966 else if (controlType
== wxT("wxMessage") || controlType
== wxT("wxStaticText"))
968 // Check for bitmap resource name (in case it's an old-style .wxr file)
969 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
971 wxString
str(expr
->Nth(count
)->StringValue());
972 controlItem
->SetValue4(str
);
974 controlItem
->SetType(wxT("wxStaticText"));
976 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
977 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
979 else if (controlType
== wxT("wxStaticBitmap"))
981 // Check for bitmap resource name
982 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
984 wxString
str(expr
->Nth(count
)->StringValue());
985 controlItem
->SetValue4(str
);
988 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
989 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
991 else if (controlType
== wxT("wxGroupBox") || controlType
== wxT("wxStaticBox"))
993 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
994 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
996 else if (controlType
== wxT("wxGauge"))
998 // Check for default value
999 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1001 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1005 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1007 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1010 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1012 // Skip past the obsolete label font spec if there are two consecutive specs
1013 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1015 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1020 else if (controlType
== wxT("wxSlider"))
1022 // Check for default value
1023 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1025 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1029 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1031 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1035 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1037 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1040 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1042 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1046 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1047 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1053 else if (controlType
== wxT("wxScrollBar"))
1056 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1058 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1062 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1064 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1068 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1070 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1074 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1075 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
1080 else if (controlType
== wxT("wxListBox"))
1082 wxExpr
*valueList
= (wxExpr
*) NULL
;
1084 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1086 wxStringList stringList
;
1087 wxExpr
*stringExpr
= valueList
->GetFirst();
1090 stringList
.Add(stringExpr
->StringValue());
1091 stringExpr
= stringExpr
->GetNext();
1093 controlItem
->SetStringValues(stringList
);
1095 // This is now obsolete: it's in the window style.
1096 // Check for wxSINGLE/wxMULTIPLE
1097 wxExpr
*mult
= (wxExpr
*) NULL
;
1099 controlItem->SetValue1(wxLB_SINGLE);
1101 if (((mult
= expr
->Nth(count
)) != 0) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1104 wxString m(mult->StringValue());
1105 if (m == "wxLB_MULTIPLE")
1106 controlItem->SetValue1(wxLB_MULTIPLE);
1107 else if (m == "wxLB_EXTENDED")
1108 controlItem->SetValue1(wxLB_EXTENDED);
1113 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1115 // Skip past the obsolete label font spec if there are two consecutive specs
1116 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1118 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1122 else if (controlType
== wxT("wxChoice"))
1124 wxExpr
*valueList
= (wxExpr
*) NULL
;
1125 // Check for default value list
1126 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1128 wxStringList stringList
;
1129 wxExpr
*stringExpr
= valueList
->GetFirst();
1132 stringList
.Add(stringExpr
->StringValue());
1133 stringExpr
= stringExpr
->GetNext();
1135 controlItem
->SetStringValues(stringList
);
1139 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1141 // Skip past the obsolete label font spec if there are two consecutive specs
1142 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1144 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1149 else if (controlType
== wxT("wxComboBox"))
1151 wxExpr
*textValue
= expr
->Nth(count
);
1152 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1154 wxString
str(textValue
->StringValue());
1155 controlItem
->SetValue4(str
);
1159 wxExpr
*valueList
= (wxExpr
*) NULL
;
1160 // Check for default value list
1161 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1163 wxStringList stringList
;
1164 wxExpr
*stringExpr
= valueList
->GetFirst();
1167 stringList
.Add(stringExpr
->StringValue());
1168 stringExpr
= stringExpr
->GetNext();
1170 controlItem
->SetStringValues(stringList
);
1174 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1176 // Skip past the obsolete label font spec if there are two consecutive specs
1177 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1179 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1186 else if (controlType
== wxT("wxRadioBox"))
1188 wxExpr
*valueList
= (wxExpr
*) NULL
;
1189 // Check for default value list
1190 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1192 wxStringList stringList
;
1193 wxExpr
*stringExpr
= valueList
->GetFirst();
1196 stringList
.Add(stringExpr
->StringValue());
1197 stringExpr
= stringExpr
->GetNext();
1199 controlItem
->SetStringValues(stringList
);
1202 // majorDim (number of rows or cols)
1203 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1205 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1209 controlItem
->SetValue1(0);
1211 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1213 // Skip past the obsolete label font spec if there are two consecutive specs
1214 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1216 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1224 return (wxItemResource
*) NULL
;
1229 // Forward declaration
1230 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, wxExpr
*expr
);
1233 * Interpet a menu item
1236 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, wxExpr
*expr
)
1238 wxItemResource
*item
= new wxItemResource
;
1240 wxExpr
*labelExpr
= expr
->Nth(0);
1241 wxExpr
*idExpr
= expr
->Nth(1);
1242 wxExpr
*helpExpr
= expr
->Nth(2);
1243 wxExpr
*checkableExpr
= expr
->Nth(3);
1245 // Further keywords/attributes to follow sometime...
1246 if (expr
->Number() == 0)
1248 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1249 item
->SetType(wxT("wxMenuSeparator"));
1254 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1255 item
->SetType(wxT("wxMenu")); // Well, menu item, but doesn't matter.
1258 wxString
str(labelExpr
->StringValue());
1259 item
->SetTitle(str
);
1264 // If a string or word, must look up in identifier table.
1265 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1267 wxString
str(idExpr
->StringValue());
1268 id
= wxResourceGetIdentifier(str
, &table
);
1271 wxLogWarning(_("Could not resolve menu id '%s'. Use (non-zero) integer instead\nor provide #define (see manual for caveats)"),
1272 (const wxChar
*) idExpr
->StringValue());
1275 else if (idExpr
->Type() == PrologInteger
)
1276 id
= (int)idExpr
->IntegerValue();
1277 item
->SetValue1(id
);
1281 wxString
str(helpExpr
->StringValue());
1282 item
->SetValue4(str
);
1285 item
->SetValue2(checkableExpr
->IntegerValue());
1287 // Find the first expression that's a list, for submenu
1288 wxExpr
*subMenuExpr
= expr
->GetFirst();
1289 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1290 subMenuExpr
= subMenuExpr
->GetNext();
1294 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1295 item
->GetChildren().Append(child
);
1296 subMenuExpr
= subMenuExpr
->GetNext();
1303 * Interpret a nested list as a menu
1306 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1308 wxItemResource *menu = new wxItemResource;
1309 // menu->SetType(wxTYPE_MENU);
1310 menu->SetType("wxMenu");
1311 wxExpr *element = expr->GetFirst();
1314 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1316 menu->GetChildren().Append(item);
1317 element = element->GetNext();
1323 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
)
1325 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1326 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1328 return (wxItemResource
*) NULL
;
1330 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1333 return (wxItemResource
*) NULL
;
1336 if (expr
->GetAttributeValue(wxT("name"), name
))
1338 menuResource
->SetName(name
);
1341 return menuResource
;
1344 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
)
1346 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1347 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1349 return (wxItemResource
*) NULL
;
1351 wxItemResource
*resource
= new wxItemResource
;
1352 resource
->SetType(wxT("wxMenu"));
1353 // resource->SetType(wxTYPE_MENU);
1355 wxExpr
*element
= listExpr
->GetFirst();
1358 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1359 resource
->GetChildren().Append(menuResource
);
1360 element
= element
->GetNext();
1364 if (expr
->GetAttributeValue(wxT("name"), name
))
1366 resource
->SetName(name
);
1372 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), wxExpr
*WXUNUSED(expr
))
1374 return (wxItemResource
*) NULL
;
1377 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), wxExpr
*expr
)
1379 wxItemResource
*bitmapItem
= new wxItemResource
;
1380 // bitmapItem->SetType(wxTYPE_BITMAP);
1381 bitmapItem
->SetType(wxT("wxBitmap"));
1383 if (expr
->GetAttributeValue(wxT("name"), name
))
1385 bitmapItem
->SetName(name
);
1387 // Now parse all bitmap specifications
1388 wxExpr
*bitmapExpr
= expr
->GetFirst();
1391 if (bitmapExpr
->Number() == 3)
1393 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1394 if (bitmapKeyword
== wxT("bitmap") || bitmapKeyword
== wxT("icon"))
1396 // The value part: always a list.
1397 wxExpr
*listExpr
= bitmapExpr
->Nth(2);
1398 if (listExpr
->Type() == PrologList
)
1400 wxItemResource
*bitmapSpec
= new wxItemResource
;
1401 // bitmapSpec->SetType(wxTYPE_BITMAP);
1402 bitmapSpec
->SetType(wxT("wxBitmap"));
1404 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1405 // where everything after 'filename' is optional.
1406 wxExpr
*nameExpr
= listExpr
->Nth(0);
1407 wxExpr
*typeExpr
= listExpr
->Nth(1);
1408 wxExpr
*platformExpr
= listExpr
->Nth(2);
1409 wxExpr
*coloursExpr
= listExpr
->Nth(3);
1410 wxExpr
*xresExpr
= listExpr
->Nth(4);
1411 wxExpr
*yresExpr
= listExpr
->Nth(5);
1412 if (nameExpr
&& nameExpr
->StringValue() != wxT(""))
1414 bitmapSpec
->SetName(nameExpr
->StringValue());
1416 if (typeExpr
&& typeExpr
->StringValue() != wxT(""))
1418 bitmapSpec
->SetValue1(wxParseWindowStyle(typeExpr
->StringValue()));
1421 bitmapSpec
->SetValue1(0);
1423 if (platformExpr
&& platformExpr
->StringValue() != wxT(""))
1425 wxString
plat(platformExpr
->StringValue());
1426 if (plat
== wxT("windows") || plat
== wxT("WINDOWS"))
1427 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1428 else if (plat
== wxT("x") || plat
== wxT("X"))
1429 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1430 else if (plat
== wxT("mac") || plat
== wxT("MAC"))
1431 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1433 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1436 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1439 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1443 xres
= (int)xresExpr
->IntegerValue();
1445 yres
= (int)yresExpr
->IntegerValue();
1446 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1448 bitmapItem
->GetChildren().Append(bitmapSpec
);
1452 bitmapExpr
= bitmapExpr
->GetNext();
1458 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
)
1460 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1463 // item->SetType(wxTYPE_ICON);
1464 item
->SetType(wxT("wxIcon"));
1468 return (wxItemResource
*) NULL
;
1471 // Interpret list expression as a font
1472 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
)
1474 if (expr
->Type() != PrologList
)
1478 int family
= wxSWISS
;
1479 int style
= wxNORMAL
;
1480 int weight
= wxNORMAL
;
1482 wxString
faceName(wxT(""));
1484 wxExpr
*pointExpr
= expr
->Nth(0);
1485 wxExpr
*familyExpr
= expr
->Nth(1);
1486 wxExpr
*styleExpr
= expr
->Nth(2);
1487 wxExpr
*weightExpr
= expr
->Nth(3);
1488 wxExpr
*underlineExpr
= expr
->Nth(4);
1489 wxExpr
*faceNameExpr
= expr
->Nth(5);
1491 point
= (int)pointExpr
->IntegerValue();
1496 str
= familyExpr
->StringValue();
1497 family
= (int)wxParseWindowStyle(str
);
1501 str
= styleExpr
->StringValue();
1502 style
= (int)wxParseWindowStyle(str
);
1506 str
= weightExpr
->StringValue();
1507 weight
= (int)wxParseWindowStyle(str
);
1510 underline
= (int)underlineExpr
->IntegerValue();
1512 faceName
= faceNameExpr
->StringValue();
1514 return *wxTheFontList
->FindOrCreateFont(point
, family
, style
, weight
,
1515 (underline
!= 0), faceName
);
1519 * (Re)allocate buffer for reading in from resource file
1522 bool wxReallocateResourceBuffer()
1524 if (!wxResourceBuffer
)
1526 wxResourceBufferSize
= 1000;
1527 wxResourceBuffer
= new char[wxResourceBufferSize
];
1530 if (wxResourceBuffer
)
1532 long newSize
= wxResourceBufferSize
+ 1000;
1533 char *tmp
= new char[(int)newSize
];
1534 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1535 delete[] wxResourceBuffer
;
1536 wxResourceBuffer
= tmp
;
1537 wxResourceBufferSize
= newSize
;
1542 static bool wxEatWhiteSpace(FILE *fd
)
1546 while ((ch
= getc(fd
)) != EOF
)
1561 ungetc(prev_ch
, fd
);
1569 while ((ch
= getc(fd
)) != EOF
)
1571 if (ch
== '/' && prev_ch
== '*')
1579 static char buffer
[255];
1580 fgets(buffer
, 255, fd
);
1584 ungetc(prev_ch
, fd
);
1598 static bool wxEatWhiteSpace(wxInputStream
*is
)
1600 int ch
= is
->GetC() ;
1601 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
1608 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
1610 // Check for comment
1616 bool finished
= FALSE
;
1624 int newCh
= is
->GetC();
1639 return wxEatWhiteSpace(is
);
1642 bool wxGetResourceToken(FILE *fd
)
1644 if (!wxResourceBuffer
)
1645 wxReallocateResourceBuffer();
1646 wxResourceBuffer
[0] = 0;
1647 wxEatWhiteSpace(fd
);
1653 wxResourceBufferCount
= 0;
1660 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1663 // Escaped characters
1664 else if (ch
== '\\')
1666 int newCh
= getc(fd
);
1669 else if (newCh
== 10)
1677 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1678 wxReallocateResourceBuffer();
1679 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1680 wxResourceBufferCount
++;
1683 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1687 wxResourceBufferCount
= 0;
1689 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1691 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1692 wxReallocateResourceBuffer();
1693 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1694 wxResourceBufferCount
++;
1698 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1705 bool wxGetResourceToken(wxInputStream
*is
)
1707 if (!wxResourceBuffer
)
1708 wxReallocateResourceBuffer();
1709 wxResourceBuffer
[0] = 0;
1710 wxEatWhiteSpace(is
);
1712 int ch
= is
->GetC() ;
1716 wxResourceBufferCount
= 0;
1723 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1726 // Escaped characters
1727 else if (ch
== '\\')
1729 int newCh
= is
->GetC();
1732 else if (newCh
== 10)
1734 else if (newCh
== 13) // mac
1742 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1743 wxReallocateResourceBuffer();
1744 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1745 wxResourceBufferCount
++;
1748 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1752 wxResourceBufferCount
= 0;
1754 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1756 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1757 wxReallocateResourceBuffer();
1758 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1759 wxResourceBufferCount
++;
1763 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1771 * Files are in form:
1772 static char *name = "....";
1773 with possible comments.
1776 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1779 table
= wxDefaultResourceTable
;
1781 // static or #define
1782 if (!wxGetResourceToken(fd
))
1788 if (strcmp(wxResourceBuffer
, "#define") == 0)
1790 wxGetResourceToken(fd
);
1791 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1792 wxGetResourceToken(fd
);
1793 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1794 if (wxIsdigit(value
[0]))
1796 int val
= (int)wxAtol(value
);
1797 wxResourceAddIdentifier(name
, val
, table
);
1801 wxLogWarning(_("#define %s must be an integer."), name
);
1811 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1813 wxGetResourceToken(fd
);
1814 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1815 wxChar
*actualName
= name
;
1816 if (name
[0] == wxT('"'))
1817 actualName
= name
+ 1;
1818 int len
= wxStrlen(name
);
1819 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1821 if (!wxResourceParseIncludeFile(actualName
, table
))
1823 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1828 else if (strcmp(wxResourceBuffer
, "static") != 0)
1831 wxStrcpy(buf
, _("Found "));
1832 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
1833 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1839 if (!wxGetResourceToken(fd
))
1841 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1846 if (strcmp(wxResourceBuffer
, "char") != 0)
1848 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1853 if (!wxGetResourceToken(fd
))
1855 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1860 if (wxResourceBuffer
[0] != '*')
1862 wxLogWarning(_("Expected '*' whilst parsing resource."));
1865 wxChar nameBuf
[100];
1866 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
1870 if (!wxGetResourceToken(fd
))
1872 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1877 if (strcmp(wxResourceBuffer
, "=") != 0)
1879 wxLogWarning(_("Expected '=' whilst parsing resource."));
1884 if (!wxGetResourceToken(fd
))
1886 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1892 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1894 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1899 if (!wxGetResourceToken(fd
))
1906 bool wxResourceReadOneResource(wxInputStream
*fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1909 table
= wxDefaultResourceTable
;
1911 // static or #define
1912 if (!wxGetResourceToken(fd
))
1918 if (strcmp(wxResourceBuffer
, "#define") == 0)
1920 wxGetResourceToken(fd
);
1921 wxChar
*name
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1922 wxGetResourceToken(fd
);
1923 wxChar
*value
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1924 if (wxIsalpha(value
[0]))
1926 int val
= (int)wxAtol(value
);
1927 wxResourceAddIdentifier(name
, val
, table
);
1931 wxLogWarning(_("#define %s must be an integer."), name
);
1941 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1943 wxGetResourceToken(fd
);
1944 wxChar
*name
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1945 wxChar
*actualName
= name
;
1946 if (name
[0] == wxT('"'))
1947 actualName
= name
+ 1;
1948 int len
= wxStrlen(name
);
1949 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1951 if (!wxResourceParseIncludeFile(actualName
, table
))
1953 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1958 else if (strcmp(wxResourceBuffer
, "static") != 0)
1961 wxStrcpy(buf
, _("Found "));
1962 wxStrncat(buf
, wxConvLibc
.cMB2WX(wxResourceBuffer
), 30);
1963 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1969 if (!wxGetResourceToken(fd
))
1971 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1976 if (strcmp(wxResourceBuffer
, "char") != 0)
1978 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1983 if (!wxGetResourceToken(fd
))
1985 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1990 if (wxResourceBuffer
[0] != '*')
1992 wxLogWarning(_("Expected '*' whilst parsing resource."));
1996 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
1999 if (!wxGetResourceToken(fd
))
2001 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2006 if (strcmp(wxResourceBuffer
, "=") != 0)
2008 wxLogWarning(_("Expected '=' whilst parsing resource."));
2013 if (!wxGetResourceToken(fd
))
2015 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2021 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2023 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2028 if (!wxGetResourceToken(fd
))
2036 * Parses string window style into integer window style
2040 * Style flag parsing, e.g.
2041 * "wxSYSTEM_MENU | wxBORDER" -> integer
2044 wxChar
* wxResourceParseWord(wxChar
*s
, int *i
)
2047 return (wxChar
*) NULL
;
2049 static wxChar buf
[150];
2050 int len
= wxStrlen(s
);
2053 while ((ii
< len
) && (wxIsalpha(s
[ii
]) || (s
[ii
] == wxT('_'))))
2061 // Eat whitespace and conjunction characters
2062 while ((ii
< len
) &&
2063 ((s
[ii
] == wxT(' ')) || (s
[ii
] == wxT('|')) || (s
[ii
] == wxT(','))))
2069 return (wxChar
*) NULL
;
2074 struct wxResourceBitListStruct
2080 static wxResourceBitListStruct wxResourceBitListTable
[] =
2083 { wxT("wxSINGLE"), wxLB_SINGLE
},
2084 { wxT("wxMULTIPLE"), wxLB_MULTIPLE
},
2085 { wxT("wxEXTENDED"), wxLB_EXTENDED
},
2086 { wxT("wxLB_SINGLE"), wxLB_SINGLE
},
2087 { wxT("wxLB_MULTIPLE"), wxLB_MULTIPLE
},
2088 { wxT("wxLB_EXTENDED"), wxLB_EXTENDED
},
2089 { wxT("wxLB_NEEDED_SB"), wxLB_NEEDED_SB
},
2090 { wxT("wxLB_ALWAYS_SB"), wxLB_ALWAYS_SB
},
2091 { wxT("wxLB_SORT"), wxLB_SORT
},
2092 { wxT("wxLB_OWNERDRAW"), wxLB_OWNERDRAW
},
2093 { wxT("wxLB_HSCROLL"), wxLB_HSCROLL
},
2096 { wxT("wxCB_SIMPLE"), wxCB_SIMPLE
},
2097 { wxT("wxCB_DROPDOWN"), wxCB_DROPDOWN
},
2098 { wxT("wxCB_READONLY"), wxCB_READONLY
},
2099 { wxT("wxCB_SORT"), wxCB_SORT
},
2102 { wxT("wxGA_PROGRESSBAR"), wxGA_PROGRESSBAR
},
2103 { wxT("wxGA_HORIZONTAL"), wxGA_HORIZONTAL
},
2104 { wxT("wxGA_VERTICAL"), wxGA_VERTICAL
},
2107 { wxT("wxPASSWORD"), wxPASSWORD
},
2108 { wxT("wxPROCESS_ENTER"), wxPROCESS_ENTER
},
2109 { wxT("wxTE_PASSWORD"), wxTE_PASSWORD
},
2110 { wxT("wxTE_READONLY"), wxTE_READONLY
},
2111 { wxT("wxTE_PROCESS_ENTER"), wxTE_PROCESS_ENTER
},
2112 { wxT("wxTE_MULTILINE"), wxTE_MULTILINE
},
2113 { wxT("wxTE_NO_VSCROLL"), wxTE_NO_VSCROLL
},
2115 /* wxRadioBox/wxRadioButton */
2116 { wxT("wxRB_GROUP"), wxRB_GROUP
},
2117 { wxT("wxRA_SPECIFY_COLS"), wxRA_SPECIFY_COLS
},
2118 { wxT("wxRA_SPECIFY_ROWS"), wxRA_SPECIFY_ROWS
},
2119 { wxT("wxRA_HORIZONTAL"), wxRA_HORIZONTAL
},
2120 { wxT("wxRA_VERTICAL"), wxRA_VERTICAL
},
2123 { wxT("wxSL_HORIZONTAL"), wxSL_HORIZONTAL
},
2124 { wxT("wxSL_VERTICAL"), wxSL_VERTICAL
},
2125 { wxT("wxSL_AUTOTICKS"), wxSL_AUTOTICKS
},
2126 { wxT("wxSL_LABELS"), wxSL_LABELS
},
2127 { wxT("wxSL_LEFT"), wxSL_LEFT
},
2128 { wxT("wxSL_TOP"), wxSL_TOP
},
2129 { wxT("wxSL_RIGHT"), wxSL_RIGHT
},
2130 { wxT("wxSL_BOTTOM"), wxSL_BOTTOM
},
2131 { wxT("wxSL_BOTH"), wxSL_BOTH
},
2132 { wxT("wxSL_SELRANGE"), wxSL_SELRANGE
},
2135 { wxT("wxSB_HORIZONTAL"), wxSB_HORIZONTAL
},
2136 { wxT("wxSB_VERTICAL"), wxSB_VERTICAL
},
2139 { wxT("wxBU_AUTODRAW"), wxBU_AUTODRAW
},
2140 { wxT("wxBU_NOAUTODRAW"), wxBU_NOAUTODRAW
},
2143 { wxT("wxTR_HAS_BUTTONS"), wxTR_HAS_BUTTONS
},
2144 { wxT("wxTR_EDIT_LABELS"), wxTR_EDIT_LABELS
},
2145 { wxT("wxTR_LINES_AT_ROOT"), wxTR_LINES_AT_ROOT
},
2148 { wxT("wxLC_ICON"), wxLC_ICON
},
2149 { wxT("wxLC_SMALL_ICON"), wxLC_SMALL_ICON
},
2150 { wxT("wxLC_LIST"), wxLC_LIST
},
2151 { wxT("wxLC_REPORT"), wxLC_REPORT
},
2152 { wxT("wxLC_ALIGN_TOP"), wxLC_ALIGN_TOP
},
2153 { wxT("wxLC_ALIGN_LEFT"), wxLC_ALIGN_LEFT
},
2154 { wxT("wxLC_AUTOARRANGE"), wxLC_AUTOARRANGE
},
2155 { wxT("wxLC_USER_TEXT"), wxLC_USER_TEXT
},
2156 { wxT("wxLC_EDIT_LABELS"), wxLC_EDIT_LABELS
},
2157 { wxT("wxLC_NO_HEADER"), wxLC_NO_HEADER
},
2158 { wxT("wxLC_NO_SORT_HEADER"), wxLC_NO_SORT_HEADER
},
2159 { wxT("wxLC_SINGLE_SEL"), wxLC_SINGLE_SEL
},
2160 { wxT("wxLC_SORT_ASCENDING"), wxLC_SORT_ASCENDING
},
2161 { wxT("wxLC_SORT_DESCENDING"), wxLC_SORT_DESCENDING
},
2164 { wxT("wxSP_VERTICAL"), wxSP_VERTICAL
},
2165 { wxT("wxSP_HORIZONTAL"), wxSP_HORIZONTAL
},
2166 { wxT("wxSP_ARROW_KEYS"), wxSP_ARROW_KEYS
},
2167 { wxT("wxSP_WRAP"), wxSP_WRAP
},
2170 { wxT("wxSP_NOBORDER"), wxSP_NOBORDER
},
2171 { wxT("wxSP_3D"), wxSP_3D
},
2172 { wxT("wxSP_BORDER"), wxSP_BORDER
},
2175 { wxT("wxTC_MULTILINE"), wxTC_MULTILINE
},
2176 { wxT("wxTC_RIGHTJUSTIFY"), wxTC_RIGHTJUSTIFY
},
2177 { wxT("wxTC_FIXEDWIDTH"), wxTC_FIXEDWIDTH
},
2178 { wxT("wxTC_OWNERDRAW"), wxTC_OWNERDRAW
},
2181 { wxT("wxST_SIZEGRIP"), wxST_SIZEGRIP
},
2184 { wxT("wxFIXED_LENGTH"), wxFIXED_LENGTH
},
2185 { wxT("wxALIGN_LEFT"), wxALIGN_LEFT
},
2186 { wxT("wxALIGN_CENTER"), wxALIGN_CENTER
},
2187 { wxT("wxALIGN_CENTRE"), wxALIGN_CENTRE
},
2188 { wxT("wxALIGN_RIGHT"), wxALIGN_RIGHT
},
2189 { wxT("wxCOLOURED"), wxCOLOURED
},
2192 { wxT("wxTB_3DBUTTONS"), wxTB_3DBUTTONS
},
2193 { wxT("wxTB_HORIZONTAL"), wxTB_HORIZONTAL
},
2194 { wxT("wxTB_VERTICAL"), wxTB_VERTICAL
},
2195 { wxT("wxTB_FLAT"), wxTB_FLAT
},
2198 { wxT("wxDIALOG_MODAL"), wxDIALOG_MODAL
},
2201 { wxT("wxVSCROLL"), wxVSCROLL
},
2202 { wxT("wxHSCROLL"), wxHSCROLL
},
2203 { wxT("wxCAPTION"), wxCAPTION
},
2204 { wxT("wxSTAY_ON_TOP"), wxSTAY_ON_TOP
},
2205 { wxT("wxICONIZE"), wxICONIZE
},
2206 { wxT("wxMINIMIZE"), wxICONIZE
},
2207 { wxT("wxMAXIMIZE"), wxMAXIMIZE
},
2209 { wxT("wxMDI_PARENT"), 0},
2210 { wxT("wxMDI_CHILD"), 0},
2211 { wxT("wxTHICK_FRAME"), wxTHICK_FRAME
},
2212 { wxT("wxRESIZE_BORDER"), wxRESIZE_BORDER
},
2213 { wxT("wxSYSTEM_MENU"), wxSYSTEM_MENU
},
2214 { wxT("wxMINIMIZE_BOX"), wxMINIMIZE_BOX
},
2215 { wxT("wxMAXIMIZE_BOX"), wxMAXIMIZE_BOX
},
2216 { wxT("wxRESIZE_BOX"), wxRESIZE_BOX
},
2217 { wxT("wxDEFAULT_FRAME_STYLE"), wxDEFAULT_FRAME_STYLE
},
2218 { wxT("wxDEFAULT_FRAME"), wxDEFAULT_FRAME_STYLE
},
2219 { wxT("wxDEFAULT_DIALOG_STYLE"), wxDEFAULT_DIALOG_STYLE
},
2220 { wxT("wxBORDER"), wxBORDER
},
2221 { wxT("wxRETAINED"), wxRETAINED
},
2222 { wxT("wxNATIVE_IMPL"), 0},
2223 { wxT("wxEXTENDED_IMPL"), 0},
2224 { wxT("wxBACKINGSTORE"), wxBACKINGSTORE
},
2225 // { wxT("wxFLAT"), wxFLAT},
2226 // { wxT("wxMOTIF_RESIZE"), wxMOTIF_RESIZE},
2227 { wxT("wxFIXED_LENGTH"), 0},
2228 { wxT("wxDOUBLE_BORDER"), wxDOUBLE_BORDER
},
2229 { wxT("wxSUNKEN_BORDER"), wxSUNKEN_BORDER
},
2230 { wxT("wxRAISED_BORDER"), wxRAISED_BORDER
},
2231 { wxT("wxSIMPLE_BORDER"), wxSIMPLE_BORDER
},
2232 { wxT("wxSTATIC_BORDER"), wxSTATIC_BORDER
},
2233 { wxT("wxTRANSPARENT_WINDOW"), wxTRANSPARENT_WINDOW
},
2234 { wxT("wxNO_BORDER"), wxNO_BORDER
},
2235 { wxT("wxCLIP_CHILDREN"), wxCLIP_CHILDREN
},
2236 { wxT("wxCLIP_SIBLINGS"), wxCLIP_SIBLINGS
},
2237 { wxT("wxTAB_TRAVERSAL"), 0}, // Compatibility only
2239 { wxT("wxTINY_CAPTION_HORIZ"), wxTINY_CAPTION_HORIZ
},
2240 { wxT("wxTINY_CAPTION_VERT"), wxTINY_CAPTION_VERT
},
2242 // Text font families
2243 { wxT("wxDEFAULT"), wxDEFAULT
},
2244 { wxT("wxDECORATIVE"), wxDECORATIVE
},
2245 { wxT("wxROMAN"), wxROMAN
},
2246 { wxT("wxSCRIPT"), wxSCRIPT
},
2247 { wxT("wxSWISS"), wxSWISS
},
2248 { wxT("wxMODERN"), wxMODERN
},
2249 { wxT("wxTELETYPE"), wxTELETYPE
},
2250 { wxT("wxVARIABLE"), wxVARIABLE
},
2251 { wxT("wxFIXED"), wxFIXED
},
2252 { wxT("wxNORMAL"), wxNORMAL
},
2253 { wxT("wxLIGHT"), wxLIGHT
},
2254 { wxT("wxBOLD"), wxBOLD
},
2255 { wxT("wxITALIC"), wxITALIC
},
2256 { wxT("wxSLANT"), wxSLANT
},
2257 { wxT("wxSOLID"), wxSOLID
},
2258 { wxT("wxDOT"), wxDOT
},
2259 { wxT("wxLONG_DASH"), wxLONG_DASH
},
2260 { wxT("wxSHORT_DASH"), wxSHORT_DASH
},
2261 { wxT("wxDOT_DASH"), wxDOT_DASH
},
2262 { wxT("wxUSER_DASH"), wxUSER_DASH
},
2263 { wxT("wxTRANSPARENT"), wxTRANSPARENT
},
2264 { wxT("wxSTIPPLE"), wxSTIPPLE
},
2265 { wxT("wxBDIAGONAL_HATCH"), wxBDIAGONAL_HATCH
},
2266 { wxT("wxCROSSDIAG_HATCH"), wxCROSSDIAG_HATCH
},
2267 { wxT("wxFDIAGONAL_HATCH"), wxFDIAGONAL_HATCH
},
2268 { wxT("wxCROSS_HATCH"), wxCROSS_HATCH
},
2269 { wxT("wxHORIZONTAL_HATCH"), wxHORIZONTAL_HATCH
},
2270 { wxT("wxVERTICAL_HATCH"), wxVERTICAL_HATCH
},
2271 { wxT("wxJOIN_BEVEL"), wxJOIN_BEVEL
},
2272 { wxT("wxJOIN_MITER"), wxJOIN_MITER
},
2273 { wxT("wxJOIN_ROUND"), wxJOIN_ROUND
},
2274 { wxT("wxCAP_ROUND"), wxCAP_ROUND
},
2275 { wxT("wxCAP_PROJECTING"), wxCAP_PROJECTING
},
2276 { wxT("wxCAP_BUTT"), wxCAP_BUTT
},
2279 { wxT("wxCLEAR"), wxCLEAR
},
2280 { wxT("wxXOR"), wxXOR
},
2281 { wxT("wxINVERT"), wxINVERT
},
2282 { wxT("wxOR_REVERSE"), wxOR_REVERSE
},
2283 { wxT("wxAND_REVERSE"), wxAND_REVERSE
},
2284 { wxT("wxCOPY"), wxCOPY
},
2285 { wxT("wxAND"), wxAND
},
2286 { wxT("wxAND_INVERT"), wxAND_INVERT
},
2287 { wxT("wxNO_OP"), wxNO_OP
},
2288 { wxT("wxNOR"), wxNOR
},
2289 { wxT("wxEQUIV"), wxEQUIV
},
2290 { wxT("wxSRC_INVERT"), wxSRC_INVERT
},
2291 { wxT("wxOR_INVERT"), wxOR_INVERT
},
2292 { wxT("wxNAND"), wxNAND
},
2293 { wxT("wxOR"), wxOR
},
2294 { wxT("wxSET"), wxSET
},
2296 { wxT("wxFLOOD_SURFACE"), wxFLOOD_SURFACE
},
2297 { wxT("wxFLOOD_BORDER"), wxFLOOD_BORDER
},
2298 { wxT("wxODDEVEN_RULE"), wxODDEVEN_RULE
},
2299 { wxT("wxWINDING_RULE"), wxWINDING_RULE
},
2300 { wxT("wxHORIZONTAL"), wxHORIZONTAL
},
2301 { wxT("wxVERTICAL"), wxVERTICAL
},
2302 { wxT("wxBOTH"), wxBOTH
},
2303 { wxT("wxCENTER_FRAME"), wxCENTER_FRAME
},
2304 { wxT("wxOK"), wxOK
},
2305 { wxT("wxYES_NO"), wxYES_NO
},
2306 { wxT("wxCANCEL"), wxCANCEL
},
2307 { wxT("wxYES"), wxYES
},
2308 { wxT("wxNO"), wxNO
},
2309 { wxT("wxICON_EXCLAMATION"), wxICON_EXCLAMATION
},
2310 { wxT("wxICON_HAND"), wxICON_HAND
},
2311 { wxT("wxICON_QUESTION"), wxICON_QUESTION
},
2312 { wxT("wxICON_INFORMATION"), wxICON_INFORMATION
},
2313 { wxT("wxICON_STOP"), wxICON_STOP
},
2314 { wxT("wxICON_ASTERISK"), wxICON_ASTERISK
},
2315 { wxT("wxICON_MASK"), wxICON_MASK
},
2316 { wxT("wxCENTRE"), wxCENTRE
},
2317 { wxT("wxCENTER"), wxCENTRE
},
2318 { wxT("wxUSER_COLOURS"), wxUSER_COLOURS
},
2319 { wxT("wxVERTICAL_LABEL"), 0},
2320 { wxT("wxHORIZONTAL_LABEL"), 0},
2322 // Bitmap types (not strictly styles)
2323 { wxT("wxBITMAP_TYPE_XPM"), wxBITMAP_TYPE_XPM
},
2324 { wxT("wxBITMAP_TYPE_XBM"), wxBITMAP_TYPE_XBM
},
2325 { wxT("wxBITMAP_TYPE_BMP"), wxBITMAP_TYPE_BMP
},
2326 { wxT("wxBITMAP_TYPE_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2327 { wxT("wxBITMAP_TYPE_BMP_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2328 { wxT("wxBITMAP_TYPE_GIF"), wxBITMAP_TYPE_GIF
},
2329 { wxT("wxBITMAP_TYPE_TIF"), wxBITMAP_TYPE_TIF
},
2330 { wxT("wxBITMAP_TYPE_ICO"), wxBITMAP_TYPE_ICO
},
2331 { wxT("wxBITMAP_TYPE_ICO_RESOURCE"), wxBITMAP_TYPE_ICO_RESOURCE
},
2332 { wxT("wxBITMAP_TYPE_CUR"), wxBITMAP_TYPE_CUR
},
2333 { wxT("wxBITMAP_TYPE_CUR_RESOURCE"), wxBITMAP_TYPE_CUR_RESOURCE
},
2334 { wxT("wxBITMAP_TYPE_XBM_DATA"), wxBITMAP_TYPE_XBM_DATA
},
2335 { wxT("wxBITMAP_TYPE_XPM_DATA"), wxBITMAP_TYPE_XPM_DATA
},
2336 { wxT("wxBITMAP_TYPE_ANY"), wxBITMAP_TYPE_ANY
}
2339 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
2341 long wxParseWindowStyle(const wxString
& bitListString
)
2346 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2347 while (word
!= NULL
)
2351 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2352 if (wxStrcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2354 bitList
|= wxResourceBitListTable
[j
].bits
;
2360 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word
);
2363 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2369 * Load a bitmap from a wxWindows resource, choosing an optimum
2370 * depth and appropriate type.
2373 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
2376 table
= wxDefaultResourceTable
;
2378 wxItemResource
*item
= table
->FindResource(resource
);
2381 if ((item
->GetType() == wxT("")) || (item
->GetType() != wxT("wxBitmap")))
2383 wxLogWarning(_("%s not a bitmap resource specification."), (const wxChar
*) resource
);
2384 return wxNullBitmap
;
2386 int thisDepth
= wxDisplayDepth();
2387 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2389 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2391 // Try to find optimum bitmap for this platform/colour depth
2392 wxNode
*node
= item
->GetChildren().First();
2395 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2396 int platform
= (int)child
->GetValue2();
2397 int noColours
= (int)child
->GetValue3();
2399 char *name = child->GetName();
2400 int bitmapType = (int)child->GetValue1();
2401 int xRes = child->GetWidth();
2402 int yRes = child->GetHeight();
2407 case RESOURCE_PLATFORM_ANY
:
2409 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2410 optResource
= child
;
2413 // Maximise the number of colours.
2414 // If noColours is zero (unspecified), then assume this
2415 // is the right one.
2416 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2417 optResource
= child
;
2422 case RESOURCE_PLATFORM_WINDOWS
:
2424 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2425 optResource
= child
;
2428 // Maximise the number of colours
2429 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2430 optResource
= child
;
2436 case RESOURCE_PLATFORM_X
:
2438 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2439 optResource
= child
;
2442 // Maximise the number of colours
2443 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2444 optResource
= child
;
2450 case RESOURCE_PLATFORM_MAC
:
2452 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2453 optResource
= child
;
2456 // Maximise the number of colours
2457 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2458 optResource
= child
;
2466 node
= node
->Next();
2468 // If no matching resource, fail.
2470 return wxNullBitmap
;
2472 wxString name
= optResource
->GetName();
2473 int bitmapType
= (int)optResource
->GetValue1();
2476 case wxBITMAP_TYPE_XBM_DATA
:
2479 wxItemResource
*item
= table
->FindResource(name
);
2482 wxLogWarning(_("Failed to find XBM resource %s.\n"
2483 "Forgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2484 return wxNullBitmap
;
2486 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2488 wxLogWarning(_("No XBM facility available!"));
2492 case wxBITMAP_TYPE_XPM_DATA
:
2494 wxItemResource
*item
= table
->FindResource(name
);
2497 wxLogWarning(_("Failed to find XPM resource %s.\nForgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2498 return wxNullBitmap
;
2500 return wxBitmap((char **)item
->GetValue1());
2504 #if defined(__WXPM__)
2505 return wxNullBitmap
;
2507 return wxBitmap(name
, (wxBitmapType
)bitmapType
);
2512 return wxNullBitmap
;
2517 wxLogWarning(_("Bitmap resource specification %s not found."), (const wxChar
*) resource
);
2518 return wxNullBitmap
;
2523 * Load an icon from a wxWindows resource, choosing an optimum
2524 * depth and appropriate type.
2527 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2530 table
= wxDefaultResourceTable
;
2532 wxItemResource
*item
= table
->FindResource(resource
);
2535 if ((item
->GetType() == wxT("")) || wxStrcmp(item
->GetType(), wxT("wxIcon")) != 0)
2537 wxLogWarning(_("%s not an icon resource specification."), (const wxChar
*) resource
);
2540 int thisDepth
= wxDisplayDepth();
2541 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2543 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2545 // Try to find optimum icon for this platform/colour depth
2546 wxNode
*node
= item
->GetChildren().First();
2549 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2550 int platform
= (int)child
->GetValue2();
2551 int noColours
= (int)child
->GetValue3();
2553 char *name = child->GetName();
2554 int bitmapType = (int)child->GetValue1();
2555 int xRes = child->GetWidth();
2556 int yRes = child->GetHeight();
2561 case RESOURCE_PLATFORM_ANY
:
2563 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2564 optResource
= child
;
2567 // Maximise the number of colours.
2568 // If noColours is zero (unspecified), then assume this
2569 // is the right one.
2570 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2571 optResource
= child
;
2576 case RESOURCE_PLATFORM_WINDOWS
:
2578 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2579 optResource
= child
;
2582 // Maximise the number of colours
2583 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2584 optResource
= child
;
2590 case RESOURCE_PLATFORM_X
:
2592 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2593 optResource
= child
;
2596 // Maximise the number of colours
2597 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2598 optResource
= child
;
2604 case RESOURCE_PLATFORM_MAC
:
2606 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2607 optResource
= child
;
2610 // Maximise the number of colours
2611 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2612 optResource
= child
;
2620 node
= node
->Next();
2622 // If no matching resource, fail.
2626 wxString name
= optResource
->GetName();
2627 int bitmapType
= (int)optResource
->GetValue1();
2630 case wxBITMAP_TYPE_XBM_DATA
:
2633 wxItemResource
*item
= table
->FindResource(name
);
2636 wxLogWarning(_("Failed to find XBM resource %s.\n"
2637 "Forgot to use wxResourceLoadIconData?"), (const wxChar
*) name
);
2640 return wxIcon((const char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2642 wxLogWarning(_("No XBM facility available!"));
2646 case wxBITMAP_TYPE_XPM_DATA
:
2648 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2650 wxItemResource *item = table->FindResource(name);
2654 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2658 return wxIcon((char **)item->GetValue1());
2660 wxLogWarning(_("No XPM icon facility available!"));
2665 #if defined( __WXGTK__ ) || defined( __WXMOTIF__ )
2666 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2669 return wxIcon(name
, (wxBitmapType
) bitmapType
);
2677 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2684 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2686 wxMenu
*menu
= new wxMenu
;
2687 wxNode
*node
= item
->GetChildren().First();
2690 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2691 if ((child
->GetType() != wxT("")) && (child
->GetType() == wxT("wxMenuSeparator")))
2692 menu
->AppendSeparator();
2693 else if (child
->GetChildren().Number() > 0)
2695 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2697 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2701 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2703 node
= node
->Next();
2708 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2711 table
= wxDefaultResourceTable
;
2713 wxItemResource
*menuResource
= table
->FindResource(resource
);
2714 if (menuResource
&& (menuResource
->GetType() != wxT("")) && (menuResource
->GetType() == wxT("wxMenu")))
2717 menuBar
= new wxMenuBar
;
2718 wxNode
*node
= menuResource
->GetChildren().First();
2721 wxItemResource
*child
= (wxItemResource
*)node
->Data();
2722 wxMenu
*menu
= wxResourceCreateMenu(child
);
2724 menuBar
->Append(menu
, child
->GetTitle());
2725 node
= node
->Next();
2729 return (wxMenuBar
*) NULL
;
2732 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2735 table
= wxDefaultResourceTable
;
2737 wxItemResource
*menuResource
= table
->FindResource(resource
);
2738 if (menuResource
&& (menuResource
->GetType() != wxT("")) && (menuResource
->GetType() == wxT("wxMenu")))
2739 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2740 return wxResourceCreateMenu(menuResource
);
2741 return (wxMenu
*) NULL
;
2744 #endif // wxUSE_MENUS
2746 // Global equivalents (so don't have to refer to default table explicitly)
2747 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2750 table
= wxDefaultResourceTable
;
2752 return table
->ParseResourceData(resource
);
2755 bool wxResourceParseData(const char* resource
, wxResourceTable
*table
)
2757 wxString
str(resource
, wxConvLibc
);
2759 table
= wxDefaultResourceTable
;
2761 return table
->ParseResourceData(str
);
2764 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2767 table
= wxDefaultResourceTable
;
2769 return table
->ParseResourceFile(filename
);
2772 // Register XBM/XPM data
2773 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2776 table
= wxDefaultResourceTable
;
2778 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2781 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2784 table
= wxDefaultResourceTable
;
2786 return table
->RegisterResourceBitmapData(name
, data
);
2789 void wxResourceClear(wxResourceTable
*table
)
2792 table
= wxDefaultResourceTable
;
2794 table
->ClearTable();
2801 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2804 table
= wxDefaultResourceTable
;
2806 table
->identifiers
.Put(name
, (wxObject
*)(long)value
);
2810 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2813 table
= wxDefaultResourceTable
;
2815 return (int)(long)table
->identifiers
.Get(name
);
2819 * Parse #include file for #defines (only)
2822 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2825 table
= wxDefaultResourceTable
;
2827 FILE *fd
= wxFopen(f
, wxT("r"));
2832 while (wxGetResourceToken(fd
))
2834 if (strcmp(wxResourceBuffer
, "#define") == 0)
2836 wxGetResourceToken(fd
);
2837 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2838 wxGetResourceToken(fd
);
2839 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2840 if (wxIsdigit(value
[0]))
2842 int val
= (int)wxAtol(value
);
2843 wxResourceAddIdentifier(name
, val
, table
);
2854 * Reading strings as if they were .wxr files
2857 static int getc_string(char *s
)
2859 int ch
= s
[wxResourceStringPtr
];
2864 wxResourceStringPtr
++;
2869 static int ungetc_string()
2871 wxResourceStringPtr
--;
2875 bool wxEatWhiteSpaceString(char *s
)
2879 while ((ch
= getc_string(s
)) != EOF
)
2891 ch
= getc_string(s
);
2902 while ((ch
= getc_string(s
)) != EOF
)
2904 if (ch
== '/' && prev_ch
== '*')
2926 bool wxGetResourceTokenString(char *s
)
2928 if (!wxResourceBuffer
)
2929 wxReallocateResourceBuffer();
2930 wxResourceBuffer
[0] = 0;
2931 wxEatWhiteSpaceString(s
);
2933 int ch
= getc_string(s
);
2937 wxResourceBufferCount
= 0;
2938 ch
= getc_string(s
);
2944 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2947 // Escaped characters
2948 else if (ch
== '\\')
2950 int newCh
= getc_string(s
);
2953 else if (newCh
== 10)
2961 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2962 wxReallocateResourceBuffer();
2963 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2964 wxResourceBufferCount
++;
2965 ch
= getc_string(s
);
2967 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2971 wxResourceBufferCount
= 0;
2973 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2975 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2976 wxReallocateResourceBuffer();
2977 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2978 wxResourceBufferCount
++;
2980 ch
= getc_string(s
);
2982 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2990 * Files are in form:
2991 static char *name = "....";
2992 with possible comments.
2995 bool wxResourceReadOneResourceString(char *s
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
2998 table
= wxDefaultResourceTable
;
3000 // static or #define
3001 if (!wxGetResourceTokenString(s
))
3007 if (strcmp(wxResourceBuffer
, "#define") == 0)
3009 wxGetResourceTokenString(s
);
3010 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
3011 wxGetResourceTokenString(s
);
3012 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
3013 if (wxIsdigit(value
[0]))
3015 int val
= (int)wxAtol(value
);
3016 wxResourceAddIdentifier(name
, val
, table
);
3020 wxLogWarning(_("#define %s must be an integer."), name
);
3031 else if (strcmp(wxResourceBuffer, "#include") == 0)
3033 wxGetResourceTokenString(s);
3034 char *name = copystring(wxResourceBuffer);
3035 char *actualName = name;
3037 actualName = name + 1;
3038 int len = strlen(name);
3039 if ((len > 0) && (name[len-1] == '"'))
3041 if (!wxResourceParseIncludeFile(actualName, table))
3044 sprintf(buf, _("Could not find resource include file %s."), actualName);
3051 else if (strcmp(wxResourceBuffer
, "static") != 0)
3054 wxStrcpy(buf
, _("Found "));
3055 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
3056 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
3062 if (!wxGetResourceTokenString(s
))
3064 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3069 if (strcmp(wxResourceBuffer
, "char") != 0)
3071 wxLogWarning(_("Expected 'char' whilst parsing resource."));
3076 if (!wxGetResourceTokenString(s
))
3078 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3083 if (wxResourceBuffer
[0] != '*')
3085 wxLogWarning(_("Expected '*' whilst parsing resource."));
3088 wxChar nameBuf
[100];
3089 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
3093 if (!wxGetResourceTokenString(s
))
3095 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3100 if (strcmp(wxResourceBuffer
, "=") != 0)
3102 wxLogWarning(_("Expected '=' whilst parsing resource."));
3107 if (!wxGetResourceTokenString(s
))
3109 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
3115 if (!db
.ReadPrologFromString(wxResourceBuffer
))
3117 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
3122 if (!wxGetResourceTokenString(s
))
3129 bool wxResourceParseString(const wxString
& s
, wxResourceTable
*WXUNUSED(table
))
3132 return wxResourceParseString( (char*)s
.mb_str().data() );
3134 return wxResourceParseString( (char*)s
.c_str() );
3138 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
3141 table
= wxDefaultResourceTable
;
3146 // Turn backslashes into spaces
3149 int len
= strlen(s
);
3151 for (i
= 0; i
< len
; i
++)
3152 if (s
[i
] == 92 && s
[i
+1] == 13)
3160 wxResourceStringPtr
= 0;
3163 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
3167 return wxResourceInterpretResources(*table
, db
);
3171 * resource loading facility
3174 bool wxLoadFromResource(wxWindow
* thisWindow
, wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
3177 table
= wxDefaultResourceTable
;
3179 wxItemResource
*resource
= table
->FindResource((const wxChar
*)resourceName
);
3180 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
3181 if (!resource
|| (resource
->GetType() == wxT("")) ||
3182 ! ((resource
->GetType() == wxT("wxDialog")) || (resource
->GetType() == wxT("wxPanel"))))
3185 wxString
title(resource
->GetTitle());
3186 long theWindowStyle
= resource
->GetStyle();
3187 bool isModal
= (resource
->GetValue1() != 0) ;
3188 int x
= resource
->GetX();
3189 int y
= resource
->GetY();
3190 int width
= resource
->GetWidth();
3191 int height
= resource
->GetHeight();
3192 wxString name
= resource
->GetName();
3194 // this is used for loading wxWizard pages from WXR
3195 if ( parent
!= thisWindow
)
3197 if (thisWindow
->IsKindOf(CLASSINFO(wxDialog
)))
3199 wxDialog
*dialogBox
= (wxDialog
*)thisWindow
;
3200 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
3201 if (!dialogBox
->Create(parent
, -1, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
3204 // Only reset the client size if we know we're not going to do it again below.
3205 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == 0)
3206 dialogBox
->SetClientSize(width
, height
);
3208 else if (thisWindow
->IsKindOf(CLASSINFO(wxPanel
)))
3210 wxPanel
* panel
= (wxPanel
*)thisWindow
;
3211 if (!panel
->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
| wxTAB_TRAVERSAL
, name
))
3216 if (!((wxWindow
*)thisWindow
)->Create(parent
, -1, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
3221 if ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
3223 // No need to do this since it's done in wxPanel or wxDialog constructor.
3224 // SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
3228 if (resource
->GetFont().Ok())
3229 thisWindow
->SetFont(resource
->GetFont());
3230 if (resource
->GetBackgroundColour().Ok())
3231 thisWindow
->SetBackgroundColour(resource
->GetBackgroundColour());
3234 // Should have some kind of font at this point
3235 if (!thisWindow
->GetFont().Ok())
3236 thisWindow
->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
3237 if (!thisWindow
->GetBackgroundColour().Ok())
3238 thisWindow
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
3240 // Only when we've created the window and set the font can we set the correct size,
3241 // if based on dialog units.
3242 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
3244 wxSize sz
= thisWindow
->ConvertDialogToPixels(wxSize(width
, height
));
3245 thisWindow
->SetClientSize(sz
.x
, sz
.y
);
3247 wxPoint pt
= thisWindow
->ConvertDialogToPixels(wxPoint(x
, y
));
3248 thisWindow
->Move(pt
.x
, pt
.y
);
3251 // Now create children
3252 wxNode
*node
= resource
->GetChildren().First();
3255 wxItemResource
*childResource
= (wxItemResource
*)node
->Data();
3257 (void) wxCreateItem(thisWindow
, childResource
, resource
, table
);
3259 node
= node
->Next();
3264 wxControl
*wxCreateItem(wxWindow
* thisWindow
, const wxItemResource
*resource
, const wxItemResource
* parentResource
, const wxResourceTable
*table
)
3267 table
= wxDefaultResourceTable
;
3268 return table
->CreateItem(thisWindow
, resource
, parentResource
);
3272 #pragma warning(default:4706) // assignment within conditional expression
3275 #endif // wxUSE_WX_RESOURCES