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 #if !WXWIN_COMPATIBILITY_2_4
93 static inline wxChar
* copystring(const wxChar
* s
)
94 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
97 // Forward (private) declarations
98 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
);
99 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
= FALSE
);
100 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
);
101 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
);
102 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
);
103 wxItemResource
*wxResourceInterpretString(wxResourceTable
& table
, wxExpr
*expr
);
104 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& table
, wxExpr
*expr
);
105 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
);
106 // Interpret list expression
107 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
);
109 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
110 bool wxResourceReadOneResource(wxInputStream
*fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
) ;
111 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
= (wxResourceTable
*) NULL
);
113 wxResourceTable
*wxDefaultResourceTable
= (wxResourceTable
*) NULL
;
115 char *wxResourceBuffer
= (char *) NULL
;
116 long wxResourceBufferSize
= 0;
117 long wxResourceBufferCount
= 0;
118 int wxResourceStringPtr
= 0;
120 void wxInitializeResourceSystem()
122 if (!wxDefaultResourceTable
)
123 wxDefaultResourceTable
= new wxResourceTable
;
126 void wxCleanUpResourceSystem()
128 delete wxDefaultResourceTable
;
129 if (wxResourceBuffer
)
130 delete[] wxResourceBuffer
;
133 // Module to ensure the resource system data gets initialized
136 class wxResourceModule
: public wxModule
139 wxResourceModule() : wxModule() {}
140 virtual bool OnInit() { wxInitializeResourceSystem(); return TRUE
; }
141 virtual void OnExit() { wxCleanUpResourceSystem(); }
143 DECLARE_DYNAMIC_CLASS(wxResourceModule
)
146 IMPLEMENT_DYNAMIC_CLASS(wxResourceModule
, wxModule
)
149 IMPLEMENT_DYNAMIC_CLASS(wxItemResource
, wxObject
)
150 IMPLEMENT_DYNAMIC_CLASS(wxResourceTable
, wxHashTable
)
152 wxItemResource::wxItemResource()
154 m_itemType
= wxT("");
158 m_x
= m_y
= m_width
= m_height
= 0;
159 m_value1
= m_value2
= m_value3
= m_value5
= 0;
165 wxItemResource::~wxItemResource()
167 wxNode
*node
= m_children
.GetFirst();
170 wxItemResource
*item
= (wxItemResource
*)node
->GetData();
173 node
= m_children
.GetFirst();
181 wxResourceTable::wxResourceTable():wxHashTable(wxKEY_STRING
), identifiers(wxKEY_STRING
)
185 wxResourceTable::~wxResourceTable()
190 wxItemResource
*wxResourceTable::FindResource(const wxString
& name
) const
192 wxItemResource
*item
= (wxItemResource
*)Get(WXSTRINGCAST name
);
196 void wxResourceTable::AddResource(wxItemResource
*item
)
198 wxString name
= item
->GetName();
200 name
= item
->GetTitle();
202 name
= wxT("no name");
204 // Delete existing resource, if any.
210 bool wxResourceTable::DeleteResource(const wxString
& name
)
212 wxItemResource
*item
= (wxItemResource
*)Delete(WXSTRINGCAST name
);
215 // See if any resource has this as its child; if so, delete from
216 // parent's child list.
218 wxNode
*node
= Next();
221 wxItemResource
*parent
= (wxItemResource
*)node
->GetData();
222 if (parent
->GetChildren().Member(item
))
224 parent
->GetChildren().DeleteObject(item
);
237 bool wxResourceTable::ParseResourceFile( wxInputStream
*is
)
240 int len
= is
->GetSize() ;
243 while ( is
->TellI() + 10 < len
) // it's a hack because the streams dont support EOF
245 wxResourceReadOneResource(is
, db
, &eof
, this) ;
247 return wxResourceInterpretResources(*this, db
);
250 bool wxResourceTable::ParseResourceFile(const wxString
& filename
)
254 FILE *fd
= wxFopen(filename
, wxT("r"));
258 while (wxResourceReadOneResource(fd
, db
, &eof
, this) && !eof
)
263 return wxResourceInterpretResources(*this, db
);
266 bool wxResourceTable::ParseResourceData(const wxString
& data
)
269 if (!db
.ReadFromString(data
))
271 wxLogWarning(_("Ill-formed resource file syntax."));
275 return wxResourceInterpretResources(*this, db
);
278 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char bits
[], int width
, int height
)
280 // Register pre-loaded bitmap data
281 wxItemResource
*item
= new wxItemResource
;
282 // item->SetType(wxRESOURCE_TYPE_XBM_DATA);
283 item
->SetType(wxT("wxXBMData"));
285 item
->SetValue1((long)bits
);
286 item
->SetValue2((long)width
);
287 item
->SetValue3((long)height
);
292 bool wxResourceTable::RegisterResourceBitmapData(const wxString
& name
, char **data
)
294 // Register pre-loaded bitmap data
295 wxItemResource
*item
= new wxItemResource
;
296 // item->SetType(wxRESOURCE_TYPE_XPM_DATA);
297 item
->SetType(wxT("wxXPMData"));
299 item
->SetValue1((long)data
);
304 bool wxResourceTable::SaveResource(const wxString
& WXUNUSED(filename
))
309 void wxResourceTable::ClearTable()
312 wxNode
*node
= Next();
315 wxNode
*next
= Next();
316 wxItemResource
*item
= (wxItemResource
*)node
->GetData();
323 wxControl
*wxResourceTable::CreateItem(wxWindow
*parent
, const wxItemResource
* childResource
, const wxItemResource
* parentResource
) const
325 int id
= childResource
->GetId();
329 bool dlgUnits
= ((parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0);
331 wxControl
*control
= (wxControl
*) NULL
;
332 wxString
itemType(childResource
->GetType());
338 pos
= parent
->ConvertDialogToPixels(wxPoint(childResource
->GetX(), childResource
->GetY()));
339 size
= parent
->ConvertDialogToPixels(wxSize(childResource
->GetWidth(), childResource
->GetHeight()));
343 pos
= wxPoint(childResource
->GetX(), childResource
->GetY());
344 size
= wxSize(childResource
->GetWidth(), childResource
->GetHeight());
347 if (itemType
== wxString(wxT("wxButton")) || itemType
== wxString(wxT("wxBitmapButton")))
349 if (childResource
->GetValue4() != wxT(""))
352 wxBitmap bitmap
= childResource
->GetBitmap();
355 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
356 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
359 #if defined(__WXPM__)
361 // OS/2 uses integer id's to access resources, not file name strings
363 bitmap
.LoadFile(wxCROSS_BITMAP
, wxBITMAP_TYPE_BMP_RESOURCE
);
365 bitmap
.LoadFile(wxT("cross_bmp"), wxBITMAP_TYPE_BMP_RESOURCE
);
367 control
= new wxBitmapButton(parent
, id
, bitmap
, pos
, size
,
368 childResource
->GetStyle() | wxBU_AUTODRAW
, wxDefaultValidator
, childResource
->GetName());
371 // Normal, text button
372 control
= new wxButton(parent
, id
, childResource
->GetTitle(), pos
, size
,
373 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
375 else if (itemType
== wxString(wxT("wxMessage")) || itemType
== wxString(wxT("wxStaticText")) ||
376 itemType
== wxString(wxT("wxStaticBitmap")))
378 if (childResource
->GetValue4() != wxT("") || itemType
== wxString(wxT("wxStaticBitmap")) )
381 wxBitmap bitmap
= childResource
->GetBitmap();
384 bitmap
= wxResourceCreateBitmap(childResource
->GetValue4(), (wxResourceTable
*)this);
385 ((wxItemResource
*) childResource
)->SetBitmap(bitmap
);
387 #if wxUSE_BITMAP_MESSAGE
389 // Use a default bitmap
391 bitmap
.LoadFile(wxT("cross_bmp"), wxBITMAP_TYPE_BMP_RESOURCE
);
395 control
= new wxStaticBitmap(parent
, id
, bitmap
, pos
, size
,
396 childResource
->GetStyle(), childResource
->GetName());
401 control
= new wxStaticText(parent
, id
, childResource
->GetTitle(), pos
, size
,
402 childResource
->GetStyle(), childResource
->GetName());
405 else if (itemType
== wxString(wxT("wxText")) || itemType
== wxString(wxT("wxTextCtrl")) || itemType
== wxString(wxT("wxMultiText")))
407 control
= new wxTextCtrl(parent
, id
, childResource
->GetValue4(), pos
, size
,
408 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
410 else if (itemType
== wxString(wxT("wxCheckBox")))
412 control
= new wxCheckBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
413 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
415 ((wxCheckBox
*)control
)->SetValue((childResource
->GetValue1() != 0));
418 else if (itemType
== wxString(wxT("wxGauge")))
420 control
= new wxGauge(parent
, id
, (int)childResource
->GetValue2(), pos
, size
,
421 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
423 ((wxGauge
*)control
)->SetValue((int)childResource
->GetValue1());
427 else if (itemType
== wxString(wxT("wxRadioButton")))
429 control
= new wxRadioButton(parent
, id
, childResource
->GetTitle(), // (int)childResource->GetValue1(),
431 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
435 else if (itemType
== wxString(wxT("wxScrollBar")))
437 control
= new wxScrollBar(parent
, id
, pos
, size
,
438 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
440 ((wxScrollBar *)control)->SetValue((int)childResource->GetValue1());
441 ((wxScrollBar *)control)->SetPageSize((int)childResource->GetValue2());
442 ((wxScrollBar *)control)->SetObjectLength((int)childResource->GetValue3());
443 ((wxScrollBar *)control)->SetViewLength((int)(long)childResource->GetValue5());
445 ((wxScrollBar
*)control
)->SetScrollbar((int)childResource
->GetValue1(),(int)childResource
->GetValue2(),
446 (int)childResource
->GetValue3(),(int)(long)childResource
->GetValue5(),FALSE
);
450 else if (itemType
== wxString(wxT("wxSlider")))
452 control
= new wxSlider(parent
, id
, (int)childResource
->GetValue1(),
453 (int)childResource
->GetValue2(), (int)childResource
->GetValue3(), pos
, size
,
454 childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
456 else if (itemType
== wxString(wxT("wxGroupBox")) || itemType
== wxString(wxT("wxStaticBox")))
458 control
= new wxStaticBox(parent
, id
, childResource
->GetTitle(), pos
, size
,
459 childResource
->GetStyle(), childResource
->GetName());
461 else if (itemType
== wxString(wxT("wxListBox")))
463 wxStringList
& stringList
= childResource
->GetStringValues();
464 wxString
*strings
= (wxString
*) NULL
;
466 if (stringList
.GetCount() > 0)
468 noStrings
= stringList
.GetCount();
469 strings
= new wxString
[noStrings
];
470 wxStringListNode
*node
= stringList
.GetFirst();
474 strings
[i
] = (wxChar
*)node
->GetData();
476 node
= node
->GetNext();
479 control
= new wxListBox(parent
, id
, pos
, size
,
480 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
485 else if (itemType
== wxString(wxT("wxChoice")))
487 wxStringList
& stringList
= childResource
->GetStringValues();
488 wxString
*strings
= (wxString
*) NULL
;
490 if (stringList
.GetCount() > 0)
492 noStrings
= stringList
.GetCount();
493 strings
= new wxString
[noStrings
];
494 wxStringListNode
*node
= stringList
.GetFirst();
498 strings
[i
] = (wxChar
*)node
->GetData();
500 node
= node
->GetNext();
503 control
= new wxChoice(parent
, id
, pos
, size
,
504 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
510 else if (itemType
== wxString(wxT("wxComboBox")))
512 wxStringList
& stringList
= childResource
->GetStringValues();
513 wxString
*strings
= (wxString
*) NULL
;
515 if (stringList
.GetCount() > 0)
517 noStrings
= stringList
.GetCount();
518 strings
= new wxString
[noStrings
];
519 wxStringListNode
*node
= stringList
.GetFirst();
523 strings
[i
] = (wxChar
*)node
->GetData();
525 node
= node
->GetNext();
528 control
= new wxComboBox(parent
, id
, childResource
->GetValue4(), pos
, size
,
529 noStrings
, strings
, childResource
->GetStyle(), wxDefaultValidator
, childResource
->GetName());
535 else if (itemType
== wxString(wxT("wxRadioBox")))
537 wxStringList
& stringList
= childResource
->GetStringValues();
538 wxString
*strings
= (wxString
*) NULL
;
540 if (stringList
.GetCount() > 0)
542 noStrings
= stringList
.GetCount();
543 strings
= new wxString
[noStrings
];
544 wxStringListNode
*node
= stringList
.GetFirst();
548 strings
[i
] = (wxChar
*)node
->GetData();
550 node
= node
->GetNext();
553 control
= new wxRadioBox(parent
, (wxWindowID
) id
, wxString(childResource
->GetTitle()), pos
, size
,
554 noStrings
, strings
, (int)childResource
->GetValue1(), childResource
->GetStyle(), wxDefaultValidator
,
555 childResource
->GetName());
561 if ((parentResource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
563 // Don't set font; will be inherited from parent.
567 if (control
&& childResource
->GetFont().Ok())
569 control
->SetFont(childResource
->GetFont());
572 // Force the layout algorithm since the size changes the layout
573 if (control
->IsKindOf(CLASSINFO(wxRadioBox
)))
575 control
->SetSize(-1, -1, -1, -1, wxSIZE_AUTO_WIDTH
|wxSIZE_AUTO_HEIGHT
);
584 * Interpret database as a series of resources
587 bool wxResourceInterpretResources(wxResourceTable
& table
, wxExprDatabase
& db
)
589 wxNode
*node
= db
.GetFirst();
592 wxExpr
*clause
= (wxExpr
*)node
->GetData();
593 wxString
functor(clause
->Functor());
595 wxItemResource
*item
= (wxItemResource
*) NULL
;
596 if (functor
== wxT("dialog"))
597 item
= wxResourceInterpretDialog(table
, clause
);
598 else if (functor
== wxT("panel"))
599 item
= wxResourceInterpretDialog(table
, clause
, TRUE
);
600 else if (functor
== wxT("menubar"))
601 item
= wxResourceInterpretMenuBar(table
, clause
);
602 else if (functor
== wxT("menu"))
603 item
= wxResourceInterpretMenu(table
, clause
);
604 else if (functor
== wxT("string"))
605 item
= wxResourceInterpretString(table
, clause
);
606 else if (functor
== wxT("bitmap"))
607 item
= wxResourceInterpretBitmap(table
, clause
);
608 else if (functor
== wxT("icon"))
609 item
= wxResourceInterpretIcon(table
, clause
);
613 // Remove any existing resource of same name
614 if (item
->GetName() != wxT(""))
615 table
.DeleteResource(item
->GetName());
616 table
.AddResource(item
);
618 node
= node
->GetNext();
623 static const wxChar
*g_ValidControlClasses
[] =
626 wxT("wxBitmapButton"),
629 wxT("wxStaticBitmap"),
635 wxT("wxRadioButton"),
637 wxT("wxBitmapCheckBox"),
647 static bool wxIsValidControlClass(const wxString
& c
)
649 for ( size_t i
= 0; i
< WXSIZEOF(g_ValidControlClasses
); i
++ )
651 if ( c
== g_ValidControlClasses
[i
] )
657 wxItemResource
*wxResourceInterpretDialog(wxResourceTable
& table
, wxExpr
*expr
, bool isPanel
)
659 wxItemResource
*dialogItem
= new wxItemResource
;
661 dialogItem
->SetType(wxT("wxPanel"));
663 dialogItem
->SetType(wxT("wxDialog"));
664 wxString style
= wxT("");
665 wxString title
= wxT("");
666 wxString name
= wxT("");
667 wxString backColourHex
= wxT("");
668 wxString labelColourHex
= wxT("");
669 wxString buttonColourHex
= wxT("");
671 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
675 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
677 wxExpr
*labelFontExpr
= (wxExpr
*) NULL
;
678 wxExpr
*buttonFontExpr
= (wxExpr
*) NULL
;
679 wxExpr
*fontExpr
= (wxExpr
*) NULL
;
680 expr
->GetAttributeValue(wxT("style"), style
);
681 expr
->GetAttributeValue(wxT("name"), name
);
682 expr
->GetAttributeValue(wxT("title"), title
);
683 expr
->GetAttributeValue(wxT("x"), x
);
684 expr
->GetAttributeValue(wxT("y"), y
);
685 expr
->GetAttributeValue(wxT("width"), width
);
686 expr
->GetAttributeValue(wxT("height"), height
);
687 expr
->GetAttributeValue(wxT("modal"), isModal
);
688 expr
->GetAttributeValue(wxT("label_font"), &labelFontExpr
);
689 expr
->GetAttributeValue(wxT("button_font"), &buttonFontExpr
);
690 expr
->GetAttributeValue(wxT("font"), &fontExpr
);
691 expr
->GetAttributeValue(wxT("background_colour"), backColourHex
);
692 expr
->GetAttributeValue(wxT("label_colour"), labelColourHex
);
693 expr
->GetAttributeValue(wxT("button_colour"), buttonColourHex
);
695 int useDialogUnits
= 0;
696 expr
->GetAttributeValue(wxT("use_dialog_units"), useDialogUnits
);
697 if (useDialogUnits
!= 0)
698 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_DIALOG_UNITS
);
701 expr
->GetAttributeValue(wxT("use_system_defaults"), useDefaults
);
702 if (useDefaults
!= 0)
703 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_USE_DEFAULTS
);
706 expr
->GetAttributeValue(wxT("id"), id
);
707 dialogItem
->SetId(id
);
709 if (style
!= wxT(""))
711 windowStyle
= wxParseWindowStyle(style
);
713 dialogItem
->SetStyle(windowStyle
);
714 dialogItem
->SetValue1(isModal
);
715 if (windowStyle
& wxDIALOG_MODAL
) // Uses style in wxWin 2
716 dialogItem
->SetValue1(TRUE
);
718 dialogItem
->SetName(name
);
719 dialogItem
->SetTitle(title
);
720 dialogItem
->SetSize(x
, y
, width
, height
);
722 // Check for wxWin 1.68-style specifications
723 if (style
.Find(wxT("VERTICAL_LABEL")) != -1)
724 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL
);
725 else if (style
.Find(wxT("HORIZONTAL_LABEL")) != -1)
726 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL
);
728 if (backColourHex
!= wxT(""))
733 r
= wxHexToDec(backColourHex
.Mid(0, 2));
734 g
= wxHexToDec(backColourHex
.Mid(2, 2));
735 b
= wxHexToDec(backColourHex
.Mid(4, 2));
736 dialogItem
->SetBackgroundColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
738 if (labelColourHex
!= wxT(""))
743 r
= wxHexToDec(labelColourHex
.Mid(0, 2));
744 g
= wxHexToDec(labelColourHex
.Mid(2, 2));
745 b
= wxHexToDec(labelColourHex
.Mid(4, 2));
746 dialogItem
->SetLabelColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
748 if (buttonColourHex
!= wxT(""))
753 r
= wxHexToDec(buttonColourHex
.Mid(0, 2));
754 g
= wxHexToDec(buttonColourHex
.Mid(2, 2));
755 b
= wxHexToDec(buttonColourHex
.Mid(4, 2));
756 dialogItem
->SetButtonColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
760 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
761 else if (buttonFontExpr
)
762 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
763 else if (labelFontExpr
)
764 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
766 // Now parse all controls
767 wxExpr
*controlExpr
= expr
->GetFirst();
770 if (controlExpr
->Number() == 3)
772 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
773 if (controlKeyword
!= wxT("") && controlKeyword
== wxT("control"))
775 // The value part: always a list.
776 wxExpr
*listExpr
= controlExpr
->Nth(2);
777 if (listExpr
->Type() == PrologList
)
779 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
782 dialogItem
->GetChildren().Append(controlItem
);
787 controlExpr
= controlExpr
->GetNext();
792 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
)
794 wxItemResource
*controlItem
= new wxItemResource
;
796 // First, find the standard features of a control definition:
797 // [optional integer/string id], control name, title, style, name, x, y, width, height
799 wxString controlType
;
804 long windowStyle
= 0;
805 int x
= 0; int y
= 0; int width
= -1; int height
= -1;
808 wxExpr
*expr1
= expr
->Nth(0);
810 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
812 if ( wxIsValidControlClass(expr1
->StringValue()) )
815 controlType
= expr1
->StringValue();
819 wxString
str(expr1
->StringValue());
820 id
= wxResourceGetIdentifier(str
, &table
);
823 wxLogWarning(_("Could not resolve control class or id '%s'. Use (non-zero) integer instead\n or provide #define (see manual for caveats)"),
824 (const wxChar
*) expr1
->StringValue());
826 return (wxItemResource
*) NULL
;
830 // Success - we have an id, so the 2nd element must be the control class.
831 controlType
= expr
->Nth(1)->StringValue();
836 else if (expr1
->Type() == PrologInteger
)
838 id
= (int)expr1
->IntegerValue();
839 // Success - we have an id, so the 2nd element must be the control class.
840 controlType
= expr
->Nth(1)->StringValue();
844 expr1
= expr
->Nth(count
);
847 title
= expr1
->StringValue();
849 expr1
= expr
->Nth(count
);
853 style
= expr1
->StringValue();
854 windowStyle
= wxParseWindowStyle(style
);
857 expr1
= expr
->Nth(count
);
860 name
= expr1
->StringValue();
862 expr1
= expr
->Nth(count
);
865 x
= (int)expr1
->IntegerValue();
867 expr1
= expr
->Nth(count
);
870 y
= (int)expr1
->IntegerValue();
872 expr1
= expr
->Nth(count
);
875 width
= (int)expr1
->IntegerValue();
877 expr1
= expr
->Nth(count
);
880 height
= (int)expr1
->IntegerValue();
882 controlItem
->SetStyle(windowStyle
);
883 controlItem
->SetName(name
);
884 controlItem
->SetTitle(title
);
885 controlItem
->SetSize(x
, y
, width
, height
);
886 controlItem
->SetType(controlType
);
887 controlItem
->SetId(id
);
889 // Check for wxWin 1.68-style specifications
890 if (style
.Find(wxT("VERTICAL_LABEL")) != -1)
891 controlItem
->SetResourceStyle(controlItem
->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL
);
892 else if (style
.Find(wxT("HORIZONTAL_LABEL")) != -1)
893 controlItem
->SetResourceStyle(controlItem
->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL
);
895 if (controlType
== wxT("wxButton"))
897 // Check for bitmap resource name (in case loading old-style resource file)
898 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
900 wxString
str(expr
->Nth(count
)->StringValue());
905 controlItem
->SetValue4(str
);
906 controlItem
->SetType(wxT("wxBitmapButton"));
909 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
910 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
912 else if (controlType
== wxT("wxBitmapButton"))
914 // Check for bitmap resource name
915 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
917 wxString
str(expr
->Nth(count
)->StringValue());
918 controlItem
->SetValue4(str
);
920 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
921 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
924 else if (controlType
== wxT("wxCheckBox"))
926 // Check for default value
927 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
929 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
931 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
932 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
936 else if (controlType
== wxT("wxRadioButton"))
938 // Check for default value
939 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
941 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
943 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
944 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
948 else if (controlType
== wxT("wxText") || controlType
== wxT("wxTextCtrl") || controlType
== wxT("wxMultiText"))
950 // Check for default value
951 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
953 wxString
str(expr
->Nth(count
)->StringValue());
954 controlItem
->SetValue4(str
);
957 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
959 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
960 // Skip past the obsolete label font spec if there are two consecutive specs
961 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
963 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
967 else if (controlType
== wxT("wxMessage") || controlType
== wxT("wxStaticText"))
969 // Check for bitmap resource name (in case it's an old-style .wxr file)
970 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
972 wxString
str(expr
->Nth(count
)->StringValue());
973 controlItem
->SetValue4(str
);
975 controlItem
->SetType(wxT("wxStaticText"));
977 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
978 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
980 else if (controlType
== wxT("wxStaticBitmap"))
982 // Check for bitmap resource name
983 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
985 wxString
str(expr
->Nth(count
)->StringValue());
986 controlItem
->SetValue4(str
);
989 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
990 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
992 else if (controlType
== wxT("wxGroupBox") || controlType
== wxT("wxStaticBox"))
994 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
995 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
997 else if (controlType
== wxT("wxGauge"))
999 // Check for default value
1000 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1002 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1006 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1008 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1011 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1013 // Skip past the obsolete label font spec if there are two consecutive specs
1014 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1016 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1021 else if (controlType
== wxT("wxSlider"))
1023 // Check for default value
1024 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1026 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1030 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1032 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1036 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1038 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1041 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1043 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1047 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1048 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1054 else if (controlType
== wxT("wxScrollBar"))
1057 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1059 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1063 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1065 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1069 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1071 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1075 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1076 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
1081 else if (controlType
== wxT("wxListBox"))
1083 wxExpr
*valueList
= (wxExpr
*) NULL
;
1085 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1087 wxStringList stringList
;
1088 wxExpr
*stringExpr
= valueList
->GetFirst();
1091 stringList
.Add(stringExpr
->StringValue());
1092 stringExpr
= stringExpr
->GetNext();
1094 controlItem
->SetStringValues(stringList
);
1096 // This is now obsolete: it's in the window style.
1097 // Check for wxSINGLE/wxMULTIPLE
1098 wxExpr
*mult
= (wxExpr
*) NULL
;
1100 controlItem->SetValue1(wxLB_SINGLE);
1102 if (((mult
= expr
->Nth(count
)) != 0) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1105 wxString m(mult->StringValue());
1106 if (m == "wxLB_MULTIPLE")
1107 controlItem->SetValue1(wxLB_MULTIPLE);
1108 else if (m == "wxLB_EXTENDED")
1109 controlItem->SetValue1(wxLB_EXTENDED);
1114 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1116 // Skip past the obsolete label font spec if there are two consecutive specs
1117 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1119 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1123 else if (controlType
== wxT("wxChoice"))
1125 wxExpr
*valueList
= (wxExpr
*) NULL
;
1126 // Check for default value list
1127 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1129 wxStringList stringList
;
1130 wxExpr
*stringExpr
= valueList
->GetFirst();
1133 stringList
.Add(stringExpr
->StringValue());
1134 stringExpr
= stringExpr
->GetNext();
1136 controlItem
->SetStringValues(stringList
);
1140 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1142 // Skip past the obsolete label font spec if there are two consecutive specs
1143 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1145 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1150 else if (controlType
== wxT("wxComboBox"))
1152 wxExpr
*textValue
= expr
->Nth(count
);
1153 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1155 wxString
str(textValue
->StringValue());
1156 controlItem
->SetValue4(str
);
1160 wxExpr
*valueList
= (wxExpr
*) NULL
;
1161 // Check for default value list
1162 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1164 wxStringList stringList
;
1165 wxExpr
*stringExpr
= valueList
->GetFirst();
1168 stringList
.Add(stringExpr
->StringValue());
1169 stringExpr
= stringExpr
->GetNext();
1171 controlItem
->SetStringValues(stringList
);
1175 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1177 // Skip past the obsolete label font spec if there are two consecutive specs
1178 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1180 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1187 else if (controlType
== wxT("wxRadioBox"))
1189 wxExpr
*valueList
= (wxExpr
*) NULL
;
1190 // Check for default value list
1191 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1193 wxStringList stringList
;
1194 wxExpr
*stringExpr
= valueList
->GetFirst();
1197 stringList
.Add(stringExpr
->StringValue());
1198 stringExpr
= stringExpr
->GetNext();
1200 controlItem
->SetStringValues(stringList
);
1203 // majorDim (number of rows or cols)
1204 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1206 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1210 controlItem
->SetValue1(0);
1212 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1214 // Skip past the obsolete label font spec if there are two consecutive specs
1215 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1217 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1225 return (wxItemResource
*) NULL
;
1230 // Forward declaration
1231 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, wxExpr
*expr
);
1234 * Interpet a menu item
1237 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, wxExpr
*expr
)
1239 wxItemResource
*item
= new wxItemResource
;
1241 wxExpr
*labelExpr
= expr
->Nth(0);
1242 wxExpr
*idExpr
= expr
->Nth(1);
1243 wxExpr
*helpExpr
= expr
->Nth(2);
1244 wxExpr
*checkableExpr
= expr
->Nth(3);
1246 // Further keywords/attributes to follow sometime...
1247 if (expr
->Number() == 0)
1249 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1250 item
->SetType(wxT("wxMenuSeparator"));
1255 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1256 item
->SetType(wxT("wxMenu")); // Well, menu item, but doesn't matter.
1259 wxString
str(labelExpr
->StringValue());
1260 item
->SetTitle(str
);
1265 // If a string or word, must look up in identifier table.
1266 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1268 wxString
str(idExpr
->StringValue());
1269 id
= wxResourceGetIdentifier(str
, &table
);
1272 wxLogWarning(_("Could not resolve menu id '%s'. Use (non-zero) integer instead\nor provide #define (see manual for caveats)"),
1273 (const wxChar
*) idExpr
->StringValue());
1276 else if (idExpr
->Type() == PrologInteger
)
1277 id
= (int)idExpr
->IntegerValue();
1278 item
->SetValue1(id
);
1282 wxString
str(helpExpr
->StringValue());
1283 item
->SetValue4(str
);
1286 item
->SetValue2(checkableExpr
->IntegerValue());
1288 // Find the first expression that's a list, for submenu
1289 wxExpr
*subMenuExpr
= expr
->GetFirst();
1290 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1291 subMenuExpr
= subMenuExpr
->GetNext();
1295 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1296 item
->GetChildren().Append(child
);
1297 subMenuExpr
= subMenuExpr
->GetNext();
1304 * Interpret a nested list as a menu
1307 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1309 wxItemResource *menu = new wxItemResource;
1310 // menu->SetType(wxTYPE_MENU);
1311 menu->SetType("wxMenu");
1312 wxExpr *element = expr->GetFirst();
1315 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1317 menu->GetChildren().Append(item);
1318 element = element->GetNext();
1324 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
)
1326 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1327 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1329 return (wxItemResource
*) NULL
;
1331 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1334 return (wxItemResource
*) NULL
;
1337 if (expr
->GetAttributeValue(wxT("name"), name
))
1339 menuResource
->SetName(name
);
1342 return menuResource
;
1345 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
)
1347 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1348 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1350 return (wxItemResource
*) NULL
;
1352 wxItemResource
*resource
= new wxItemResource
;
1353 resource
->SetType(wxT("wxMenu"));
1354 // resource->SetType(wxTYPE_MENU);
1356 wxExpr
*element
= listExpr
->GetFirst();
1359 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1360 resource
->GetChildren().Append(menuResource
);
1361 element
= element
->GetNext();
1365 if (expr
->GetAttributeValue(wxT("name"), name
))
1367 resource
->SetName(name
);
1373 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), wxExpr
*WXUNUSED(expr
))
1375 return (wxItemResource
*) NULL
;
1378 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), wxExpr
*expr
)
1380 wxItemResource
*bitmapItem
= new wxItemResource
;
1381 // bitmapItem->SetType(wxTYPE_BITMAP);
1382 bitmapItem
->SetType(wxT("wxBitmap"));
1384 if (expr
->GetAttributeValue(wxT("name"), name
))
1386 bitmapItem
->SetName(name
);
1388 // Now parse all bitmap specifications
1389 wxExpr
*bitmapExpr
= expr
->GetFirst();
1392 if (bitmapExpr
->Number() == 3)
1394 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1395 if (bitmapKeyword
== wxT("bitmap") || bitmapKeyword
== wxT("icon"))
1397 // The value part: always a list.
1398 wxExpr
*listExpr
= bitmapExpr
->Nth(2);
1399 if (listExpr
->Type() == PrologList
)
1401 wxItemResource
*bitmapSpec
= new wxItemResource
;
1402 // bitmapSpec->SetType(wxTYPE_BITMAP);
1403 bitmapSpec
->SetType(wxT("wxBitmap"));
1405 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1406 // where everything after 'filename' is optional.
1407 wxExpr
*nameExpr
= listExpr
->Nth(0);
1408 wxExpr
*typeExpr
= listExpr
->Nth(1);
1409 wxExpr
*platformExpr
= listExpr
->Nth(2);
1410 wxExpr
*coloursExpr
= listExpr
->Nth(3);
1411 wxExpr
*xresExpr
= listExpr
->Nth(4);
1412 wxExpr
*yresExpr
= listExpr
->Nth(5);
1413 if (nameExpr
&& nameExpr
->StringValue() != wxT(""))
1415 bitmapSpec
->SetName(nameExpr
->StringValue());
1417 if (typeExpr
&& typeExpr
->StringValue() != wxT(""))
1419 bitmapSpec
->SetValue1(wxParseWindowStyle(typeExpr
->StringValue()));
1422 bitmapSpec
->SetValue1(0);
1424 if (platformExpr
&& platformExpr
->StringValue() != wxT(""))
1426 wxString
plat(platformExpr
->StringValue());
1427 if (plat
== wxT("windows") || plat
== wxT("WINDOWS"))
1428 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1429 else if (plat
== wxT("x") || plat
== wxT("X"))
1430 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1431 else if (plat
== wxT("mac") || plat
== wxT("MAC"))
1432 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1434 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1437 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1440 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1444 xres
= (int)xresExpr
->IntegerValue();
1446 yres
= (int)yresExpr
->IntegerValue();
1447 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1449 bitmapItem
->GetChildren().Append(bitmapSpec
);
1453 bitmapExpr
= bitmapExpr
->GetNext();
1459 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
)
1461 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1464 // item->SetType(wxTYPE_ICON);
1465 item
->SetType(wxT("wxIcon"));
1469 return (wxItemResource
*) NULL
;
1472 // Interpret list expression as a font
1473 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
)
1475 if (expr
->Type() != PrologList
)
1479 int family
= wxSWISS
;
1480 int style
= wxNORMAL
;
1481 int weight
= wxNORMAL
;
1483 wxString
faceName(wxT(""));
1485 wxExpr
*pointExpr
= expr
->Nth(0);
1486 wxExpr
*familyExpr
= expr
->Nth(1);
1487 wxExpr
*styleExpr
= expr
->Nth(2);
1488 wxExpr
*weightExpr
= expr
->Nth(3);
1489 wxExpr
*underlineExpr
= expr
->Nth(4);
1490 wxExpr
*faceNameExpr
= expr
->Nth(5);
1492 point
= (int)pointExpr
->IntegerValue();
1497 str
= familyExpr
->StringValue();
1498 family
= (int)wxParseWindowStyle(str
);
1502 str
= styleExpr
->StringValue();
1503 style
= (int)wxParseWindowStyle(str
);
1507 str
= weightExpr
->StringValue();
1508 weight
= (int)wxParseWindowStyle(str
);
1511 underline
= (int)underlineExpr
->IntegerValue();
1513 faceName
= faceNameExpr
->StringValue();
1515 return *wxTheFontList
->FindOrCreateFont(point
, family
, style
, weight
,
1516 (underline
!= 0), faceName
);
1520 * (Re)allocate buffer for reading in from resource file
1523 bool wxReallocateResourceBuffer()
1525 if (!wxResourceBuffer
)
1527 wxResourceBufferSize
= 1000;
1528 wxResourceBuffer
= new char[wxResourceBufferSize
];
1531 if (wxResourceBuffer
)
1533 long newSize
= wxResourceBufferSize
+ 1000;
1534 char *tmp
= new char[(int)newSize
];
1535 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1536 delete[] wxResourceBuffer
;
1537 wxResourceBuffer
= tmp
;
1538 wxResourceBufferSize
= newSize
;
1543 static bool wxEatWhiteSpace(FILE *fd
)
1547 while ((ch
= getc(fd
)) != EOF
)
1562 ungetc(prev_ch
, fd
);
1570 while ((ch
= getc(fd
)) != EOF
)
1572 if (ch
== '/' && prev_ch
== '*')
1580 static char buffer
[255];
1581 fgets(buffer
, 255, fd
);
1585 ungetc(prev_ch
, fd
);
1599 static bool wxEatWhiteSpace(wxInputStream
*is
)
1601 int ch
= is
->GetC() ;
1602 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
1609 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
1611 // Check for comment
1617 bool finished
= FALSE
;
1625 int newCh
= is
->GetC();
1640 return wxEatWhiteSpace(is
);
1643 bool wxGetResourceToken(FILE *fd
)
1645 if (!wxResourceBuffer
)
1646 wxReallocateResourceBuffer();
1647 wxResourceBuffer
[0] = 0;
1648 wxEatWhiteSpace(fd
);
1654 wxResourceBufferCount
= 0;
1661 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1664 // Escaped characters
1665 else if (ch
== '\\')
1667 int newCh
= getc(fd
);
1670 else if (newCh
== 10)
1678 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1679 wxReallocateResourceBuffer();
1680 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1681 wxResourceBufferCount
++;
1684 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1688 wxResourceBufferCount
= 0;
1690 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1692 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1693 wxReallocateResourceBuffer();
1694 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1695 wxResourceBufferCount
++;
1699 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1706 bool wxGetResourceToken(wxInputStream
*is
)
1708 if (!wxResourceBuffer
)
1709 wxReallocateResourceBuffer();
1710 wxResourceBuffer
[0] = 0;
1711 wxEatWhiteSpace(is
);
1713 int ch
= is
->GetC() ;
1717 wxResourceBufferCount
= 0;
1724 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1727 // Escaped characters
1728 else if (ch
== '\\')
1730 int newCh
= is
->GetC();
1733 else if (newCh
== 10)
1735 else if (newCh
== 13) // mac
1743 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1744 wxReallocateResourceBuffer();
1745 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1746 wxResourceBufferCount
++;
1749 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1753 wxResourceBufferCount
= 0;
1755 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1757 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1758 wxReallocateResourceBuffer();
1759 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1760 wxResourceBufferCount
++;
1764 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1772 * Files are in form:
1773 static char *name = "....";
1774 with possible comments.
1777 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1780 table
= wxDefaultResourceTable
;
1782 // static or #define
1783 if (!wxGetResourceToken(fd
))
1789 if (strcmp(wxResourceBuffer
, "#define") == 0)
1791 wxGetResourceToken(fd
);
1792 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1793 wxGetResourceToken(fd
);
1794 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1795 if (wxIsdigit(value
[0]))
1797 int val
= (int)wxAtol(value
);
1798 wxResourceAddIdentifier(name
, val
, table
);
1802 wxLogWarning(_("#define %s must be an integer."), name
);
1812 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1814 wxGetResourceToken(fd
);
1815 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1816 wxChar
*actualName
= name
;
1817 if (name
[0] == wxT('"'))
1818 actualName
= name
+ 1;
1819 int len
= wxStrlen(name
);
1820 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1822 if (!wxResourceParseIncludeFile(actualName
, table
))
1824 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1829 else if (strcmp(wxResourceBuffer
, "static") != 0)
1832 wxStrcpy(buf
, _("Found "));
1833 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
1834 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1840 if (!wxGetResourceToken(fd
))
1842 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1847 if (strcmp(wxResourceBuffer
, "char") != 0)
1849 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1854 if (!wxGetResourceToken(fd
))
1856 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1861 if (wxResourceBuffer
[0] != '*')
1863 wxLogWarning(_("Expected '*' whilst parsing resource."));
1866 wxChar nameBuf
[100];
1867 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
1871 if (!wxGetResourceToken(fd
))
1873 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1878 if (strcmp(wxResourceBuffer
, "=") != 0)
1880 wxLogWarning(_("Expected '=' whilst parsing resource."));
1885 if (!wxGetResourceToken(fd
))
1887 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1893 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1895 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1900 if (!wxGetResourceToken(fd
))
1907 bool wxResourceReadOneResource(wxInputStream
*fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1910 table
= wxDefaultResourceTable
;
1912 // static or #define
1913 if (!wxGetResourceToken(fd
))
1919 if (strcmp(wxResourceBuffer
, "#define") == 0)
1921 wxGetResourceToken(fd
);
1922 wxChar
*name
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1923 wxGetResourceToken(fd
);
1924 wxChar
*value
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1925 if (wxIsalpha(value
[0]))
1927 int val
= (int)wxAtol(value
);
1928 wxResourceAddIdentifier(name
, val
, table
);
1932 wxLogWarning(_("#define %s must be an integer."), name
);
1942 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1944 wxGetResourceToken(fd
);
1945 wxChar
*name
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1946 wxChar
*actualName
= name
;
1947 if (name
[0] == wxT('"'))
1948 actualName
= name
+ 1;
1949 int len
= wxStrlen(name
);
1950 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1952 if (!wxResourceParseIncludeFile(actualName
, table
))
1954 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1959 else if (strcmp(wxResourceBuffer
, "static") != 0)
1962 wxStrcpy(buf
, _("Found "));
1963 wxStrncat(buf
, wxConvLibc
.cMB2WX(wxResourceBuffer
), 30);
1964 wxStrcat(buf
, _(", expected static, #include or #define\nwhilst parsing resource."));
1970 if (!wxGetResourceToken(fd
))
1972 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1977 if (strcmp(wxResourceBuffer
, "char") != 0)
1979 wxLogWarning(_("Expected 'char' whilst parsing resource."));
1984 if (!wxGetResourceToken(fd
))
1986 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
1991 if (wxResourceBuffer
[0] != '*')
1993 wxLogWarning(_("Expected '*' whilst parsing resource."));
1997 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
2000 if (!wxGetResourceToken(fd
))
2002 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2007 if (strcmp(wxResourceBuffer
, "=") != 0)
2009 wxLogWarning(_("Expected '=' whilst parsing resource."));
2014 if (!wxGetResourceToken(fd
))
2016 wxLogWarning(_("Unexpected end of file whilst parsing resource."));
2022 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2024 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2029 if (!wxGetResourceToken(fd
))
2037 * Parses string window style into integer window style
2041 * Style flag parsing, e.g.
2042 * "wxSYSTEM_MENU | wxBORDER" -> integer
2045 wxChar
* wxResourceParseWord(wxChar
*s
, int *i
)
2048 return (wxChar
*) NULL
;
2050 static wxChar buf
[150];
2051 int len
= wxStrlen(s
);
2054 while ((ii
< len
) && (wxIsalpha(s
[ii
]) || (s
[ii
] == wxT('_'))))
2062 // Eat whitespace and conjunction characters
2063 while ((ii
< len
) &&
2064 ((s
[ii
] == wxT(' ')) || (s
[ii
] == wxT('|')) || (s
[ii
] == wxT(','))))
2070 return (wxChar
*) NULL
;
2075 struct wxResourceBitListStruct
2081 static wxResourceBitListStruct wxResourceBitListTable
[] =
2084 { wxT("wxSINGLE"), wxLB_SINGLE
},
2085 { wxT("wxMULTIPLE"), wxLB_MULTIPLE
},
2086 { wxT("wxEXTENDED"), wxLB_EXTENDED
},
2087 { wxT("wxLB_SINGLE"), wxLB_SINGLE
},
2088 { wxT("wxLB_MULTIPLE"), wxLB_MULTIPLE
},
2089 { wxT("wxLB_EXTENDED"), wxLB_EXTENDED
},
2090 { wxT("wxLB_NEEDED_SB"), wxLB_NEEDED_SB
},
2091 { wxT("wxLB_ALWAYS_SB"), wxLB_ALWAYS_SB
},
2092 { wxT("wxLB_SORT"), wxLB_SORT
},
2093 { wxT("wxLB_OWNERDRAW"), wxLB_OWNERDRAW
},
2094 { wxT("wxLB_HSCROLL"), wxLB_HSCROLL
},
2097 { wxT("wxCB_SIMPLE"), wxCB_SIMPLE
},
2098 { wxT("wxCB_DROPDOWN"), wxCB_DROPDOWN
},
2099 { wxT("wxCB_READONLY"), wxCB_READONLY
},
2100 { wxT("wxCB_SORT"), wxCB_SORT
},
2103 { wxT("wxGA_PROGRESSBAR"), wxGA_PROGRESSBAR
},
2104 { wxT("wxGA_HORIZONTAL"), wxGA_HORIZONTAL
},
2105 { wxT("wxGA_VERTICAL"), wxGA_VERTICAL
},
2108 { wxT("wxPASSWORD"), wxPASSWORD
},
2109 { wxT("wxPROCESS_ENTER"), wxPROCESS_ENTER
},
2110 { wxT("wxTE_PASSWORD"), wxTE_PASSWORD
},
2111 { wxT("wxTE_READONLY"), wxTE_READONLY
},
2112 { wxT("wxTE_PROCESS_ENTER"), wxTE_PROCESS_ENTER
},
2113 { wxT("wxTE_MULTILINE"), wxTE_MULTILINE
},
2114 { wxT("wxTE_NO_VSCROLL"), wxTE_NO_VSCROLL
},
2116 /* wxRadioBox/wxRadioButton */
2117 { wxT("wxRB_GROUP"), wxRB_GROUP
},
2118 { wxT("wxRA_SPECIFY_COLS"), wxRA_SPECIFY_COLS
},
2119 { wxT("wxRA_SPECIFY_ROWS"), wxRA_SPECIFY_ROWS
},
2120 { wxT("wxRA_HORIZONTAL"), wxRA_HORIZONTAL
},
2121 { wxT("wxRA_VERTICAL"), wxRA_VERTICAL
},
2124 { wxT("wxSL_HORIZONTAL"), wxSL_HORIZONTAL
},
2125 { wxT("wxSL_VERTICAL"), wxSL_VERTICAL
},
2126 { wxT("wxSL_AUTOTICKS"), wxSL_AUTOTICKS
},
2127 { wxT("wxSL_LABELS"), wxSL_LABELS
},
2128 { wxT("wxSL_LEFT"), wxSL_LEFT
},
2129 { wxT("wxSL_TOP"), wxSL_TOP
},
2130 { wxT("wxSL_RIGHT"), wxSL_RIGHT
},
2131 { wxT("wxSL_BOTTOM"), wxSL_BOTTOM
},
2132 { wxT("wxSL_BOTH"), wxSL_BOTH
},
2133 { wxT("wxSL_SELRANGE"), wxSL_SELRANGE
},
2136 { wxT("wxSB_HORIZONTAL"), wxSB_HORIZONTAL
},
2137 { wxT("wxSB_VERTICAL"), wxSB_VERTICAL
},
2140 { wxT("wxBU_AUTODRAW"), wxBU_AUTODRAW
},
2141 { wxT("wxBU_NOAUTODRAW"), wxBU_NOAUTODRAW
},
2144 { wxT("wxTR_HAS_BUTTONS"), wxTR_HAS_BUTTONS
},
2145 { wxT("wxTR_EDIT_LABELS"), wxTR_EDIT_LABELS
},
2146 { wxT("wxTR_LINES_AT_ROOT"), wxTR_LINES_AT_ROOT
},
2149 { wxT("wxLC_ICON"), wxLC_ICON
},
2150 { wxT("wxLC_SMALL_ICON"), wxLC_SMALL_ICON
},
2151 { wxT("wxLC_LIST"), wxLC_LIST
},
2152 { wxT("wxLC_REPORT"), wxLC_REPORT
},
2153 { wxT("wxLC_ALIGN_TOP"), wxLC_ALIGN_TOP
},
2154 { wxT("wxLC_ALIGN_LEFT"), wxLC_ALIGN_LEFT
},
2155 { wxT("wxLC_AUTOARRANGE"), wxLC_AUTOARRANGE
},
2156 { wxT("wxLC_USER_TEXT"), wxLC_USER_TEXT
},
2157 { wxT("wxLC_EDIT_LABELS"), wxLC_EDIT_LABELS
},
2158 { wxT("wxLC_NO_HEADER"), wxLC_NO_HEADER
},
2159 { wxT("wxLC_NO_SORT_HEADER"), wxLC_NO_SORT_HEADER
},
2160 { wxT("wxLC_SINGLE_SEL"), wxLC_SINGLE_SEL
},
2161 { wxT("wxLC_SORT_ASCENDING"), wxLC_SORT_ASCENDING
},
2162 { wxT("wxLC_SORT_DESCENDING"), wxLC_SORT_DESCENDING
},
2165 { wxT("wxSP_VERTICAL"), wxSP_VERTICAL
},
2166 { wxT("wxSP_HORIZONTAL"), wxSP_HORIZONTAL
},
2167 { wxT("wxSP_ARROW_KEYS"), wxSP_ARROW_KEYS
},
2168 { wxT("wxSP_WRAP"), wxSP_WRAP
},
2171 { wxT("wxSP_NOBORDER"), wxSP_NOBORDER
},
2172 { wxT("wxSP_3D"), wxSP_3D
},
2173 { wxT("wxSP_BORDER"), wxSP_BORDER
},
2176 { wxT("wxTC_MULTILINE"), wxTC_MULTILINE
},
2177 { wxT("wxTC_RIGHTJUSTIFY"), wxTC_RIGHTJUSTIFY
},
2178 { wxT("wxTC_FIXEDWIDTH"), wxTC_FIXEDWIDTH
},
2179 { wxT("wxTC_OWNERDRAW"), wxTC_OWNERDRAW
},
2182 { wxT("wxST_SIZEGRIP"), wxST_SIZEGRIP
},
2185 { wxT("wxFIXED_LENGTH"), wxFIXED_LENGTH
},
2186 { wxT("wxALIGN_LEFT"), wxALIGN_LEFT
},
2187 { wxT("wxALIGN_CENTER"), wxALIGN_CENTER
},
2188 { wxT("wxALIGN_CENTRE"), wxALIGN_CENTRE
},
2189 { wxT("wxALIGN_RIGHT"), wxALIGN_RIGHT
},
2190 { wxT("wxCOLOURED"), wxCOLOURED
},
2193 { wxT("wxTB_3DBUTTONS"), wxTB_3DBUTTONS
},
2194 { wxT("wxTB_HORIZONTAL"), wxTB_HORIZONTAL
},
2195 { wxT("wxTB_VERTICAL"), wxTB_VERTICAL
},
2196 { wxT("wxTB_FLAT"), wxTB_FLAT
},
2199 { wxT("wxDIALOG_MODAL"), wxDIALOG_MODAL
},
2202 { wxT("wxVSCROLL"), wxVSCROLL
},
2203 { wxT("wxHSCROLL"), wxHSCROLL
},
2204 { wxT("wxCAPTION"), wxCAPTION
},
2205 { wxT("wxSTAY_ON_TOP"), wxSTAY_ON_TOP
},
2206 { wxT("wxICONIZE"), wxICONIZE
},
2207 { wxT("wxMINIMIZE"), wxICONIZE
},
2208 { wxT("wxMAXIMIZE"), wxMAXIMIZE
},
2210 { wxT("wxMDI_PARENT"), 0},
2211 { wxT("wxMDI_CHILD"), 0},
2212 { wxT("wxTHICK_FRAME"), wxTHICK_FRAME
},
2213 { wxT("wxRESIZE_BORDER"), wxRESIZE_BORDER
},
2214 { wxT("wxSYSTEM_MENU"), wxSYSTEM_MENU
},
2215 { wxT("wxMINIMIZE_BOX"), wxMINIMIZE_BOX
},
2216 { wxT("wxMAXIMIZE_BOX"), wxMAXIMIZE_BOX
},
2217 { wxT("wxRESIZE_BOX"), wxRESIZE_BOX
},
2218 { wxT("wxDEFAULT_FRAME_STYLE"), wxDEFAULT_FRAME_STYLE
},
2219 { wxT("wxDEFAULT_FRAME"), wxDEFAULT_FRAME_STYLE
},
2220 { wxT("wxDEFAULT_DIALOG_STYLE"), wxDEFAULT_DIALOG_STYLE
},
2221 { wxT("wxBORDER"), wxBORDER
},
2222 { wxT("wxRETAINED"), wxRETAINED
},
2223 { wxT("wxNATIVE_IMPL"), 0},
2224 { wxT("wxEXTENDED_IMPL"), 0},
2225 { wxT("wxBACKINGSTORE"), wxBACKINGSTORE
},
2226 // { wxT("wxFLAT"), wxFLAT},
2227 // { wxT("wxMOTIF_RESIZE"), wxMOTIF_RESIZE},
2228 { wxT("wxFIXED_LENGTH"), 0},
2229 { wxT("wxDOUBLE_BORDER"), wxDOUBLE_BORDER
},
2230 { wxT("wxSUNKEN_BORDER"), wxSUNKEN_BORDER
},
2231 { wxT("wxRAISED_BORDER"), wxRAISED_BORDER
},
2232 { wxT("wxSIMPLE_BORDER"), wxSIMPLE_BORDER
},
2233 { wxT("wxSTATIC_BORDER"), wxSTATIC_BORDER
},
2234 { wxT("wxTRANSPARENT_WINDOW"), wxTRANSPARENT_WINDOW
},
2235 { wxT("wxNO_BORDER"), wxNO_BORDER
},
2236 { wxT("wxCLIP_CHILDREN"), wxCLIP_CHILDREN
},
2237 { wxT("wxCLIP_SIBLINGS"), wxCLIP_SIBLINGS
},
2238 { wxT("wxTAB_TRAVERSAL"), 0}, // Compatibility only
2240 { wxT("wxTINY_CAPTION_HORIZ"), wxTINY_CAPTION_HORIZ
},
2241 { wxT("wxTINY_CAPTION_VERT"), wxTINY_CAPTION_VERT
},
2243 // Text font families
2244 { wxT("wxDEFAULT"), wxDEFAULT
},
2245 { wxT("wxDECORATIVE"), wxDECORATIVE
},
2246 { wxT("wxROMAN"), wxROMAN
},
2247 { wxT("wxSCRIPT"), wxSCRIPT
},
2248 { wxT("wxSWISS"), wxSWISS
},
2249 { wxT("wxMODERN"), wxMODERN
},
2250 { wxT("wxTELETYPE"), wxTELETYPE
},
2251 { wxT("wxVARIABLE"), wxVARIABLE
},
2252 { wxT("wxFIXED"), wxFIXED
},
2253 { wxT("wxNORMAL"), wxNORMAL
},
2254 { wxT("wxLIGHT"), wxLIGHT
},
2255 { wxT("wxBOLD"), wxBOLD
},
2256 { wxT("wxITALIC"), wxITALIC
},
2257 { wxT("wxSLANT"), wxSLANT
},
2258 { wxT("wxSOLID"), wxSOLID
},
2259 { wxT("wxDOT"), wxDOT
},
2260 { wxT("wxLONG_DASH"), wxLONG_DASH
},
2261 { wxT("wxSHORT_DASH"), wxSHORT_DASH
},
2262 { wxT("wxDOT_DASH"), wxDOT_DASH
},
2263 { wxT("wxUSER_DASH"), wxUSER_DASH
},
2264 { wxT("wxTRANSPARENT"), wxTRANSPARENT
},
2265 { wxT("wxSTIPPLE"), wxSTIPPLE
},
2266 { wxT("wxBDIAGONAL_HATCH"), wxBDIAGONAL_HATCH
},
2267 { wxT("wxCROSSDIAG_HATCH"), wxCROSSDIAG_HATCH
},
2268 { wxT("wxFDIAGONAL_HATCH"), wxFDIAGONAL_HATCH
},
2269 { wxT("wxCROSS_HATCH"), wxCROSS_HATCH
},
2270 { wxT("wxHORIZONTAL_HATCH"), wxHORIZONTAL_HATCH
},
2271 { wxT("wxVERTICAL_HATCH"), wxVERTICAL_HATCH
},
2272 { wxT("wxJOIN_BEVEL"), wxJOIN_BEVEL
},
2273 { wxT("wxJOIN_MITER"), wxJOIN_MITER
},
2274 { wxT("wxJOIN_ROUND"), wxJOIN_ROUND
},
2275 { wxT("wxCAP_ROUND"), wxCAP_ROUND
},
2276 { wxT("wxCAP_PROJECTING"), wxCAP_PROJECTING
},
2277 { wxT("wxCAP_BUTT"), wxCAP_BUTT
},
2280 { wxT("wxCLEAR"), wxCLEAR
},
2281 { wxT("wxXOR"), wxXOR
},
2282 { wxT("wxINVERT"), wxINVERT
},
2283 { wxT("wxOR_REVERSE"), wxOR_REVERSE
},
2284 { wxT("wxAND_REVERSE"), wxAND_REVERSE
},
2285 { wxT("wxCOPY"), wxCOPY
},
2286 { wxT("wxAND"), wxAND
},
2287 { wxT("wxAND_INVERT"), wxAND_INVERT
},
2288 { wxT("wxNO_OP"), wxNO_OP
},
2289 { wxT("wxNOR"), wxNOR
},
2290 { wxT("wxEQUIV"), wxEQUIV
},
2291 { wxT("wxSRC_INVERT"), wxSRC_INVERT
},
2292 { wxT("wxOR_INVERT"), wxOR_INVERT
},
2293 { wxT("wxNAND"), wxNAND
},
2294 { wxT("wxOR"), wxOR
},
2295 { wxT("wxSET"), wxSET
},
2297 { wxT("wxFLOOD_SURFACE"), wxFLOOD_SURFACE
},
2298 { wxT("wxFLOOD_BORDER"), wxFLOOD_BORDER
},
2299 { wxT("wxODDEVEN_RULE"), wxODDEVEN_RULE
},
2300 { wxT("wxWINDING_RULE"), wxWINDING_RULE
},
2301 { wxT("wxHORIZONTAL"), wxHORIZONTAL
},
2302 { wxT("wxVERTICAL"), wxVERTICAL
},
2303 { wxT("wxBOTH"), wxBOTH
},
2304 { wxT("wxCENTER_FRAME"), wxCENTER_FRAME
},
2305 { wxT("wxOK"), wxOK
},
2306 { wxT("wxYES_NO"), wxYES_NO
},
2307 { wxT("wxCANCEL"), wxCANCEL
},
2308 { wxT("wxYES"), wxYES
},
2309 { wxT("wxNO"), wxNO
},
2310 { wxT("wxICON_EXCLAMATION"), wxICON_EXCLAMATION
},
2311 { wxT("wxICON_HAND"), wxICON_HAND
},
2312 { wxT("wxICON_QUESTION"), wxICON_QUESTION
},
2313 { wxT("wxICON_INFORMATION"), wxICON_INFORMATION
},
2314 { wxT("wxICON_STOP"), wxICON_STOP
},
2315 { wxT("wxICON_ASTERISK"), wxICON_ASTERISK
},
2316 { wxT("wxICON_MASK"), wxICON_MASK
},
2317 { wxT("wxCENTRE"), wxCENTRE
},
2318 { wxT("wxCENTER"), wxCENTRE
},
2319 { wxT("wxUSER_COLOURS"), wxUSER_COLOURS
},
2320 { wxT("wxVERTICAL_LABEL"), 0},
2321 { wxT("wxHORIZONTAL_LABEL"), 0},
2323 // Bitmap types (not strictly styles)
2324 { wxT("wxBITMAP_TYPE_XPM"), wxBITMAP_TYPE_XPM
},
2325 { wxT("wxBITMAP_TYPE_XBM"), wxBITMAP_TYPE_XBM
},
2326 { wxT("wxBITMAP_TYPE_BMP"), wxBITMAP_TYPE_BMP
},
2327 { wxT("wxBITMAP_TYPE_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2328 { wxT("wxBITMAP_TYPE_BMP_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2329 { wxT("wxBITMAP_TYPE_GIF"), wxBITMAP_TYPE_GIF
},
2330 { wxT("wxBITMAP_TYPE_TIF"), wxBITMAP_TYPE_TIF
},
2331 { wxT("wxBITMAP_TYPE_ICO"), wxBITMAP_TYPE_ICO
},
2332 { wxT("wxBITMAP_TYPE_ICO_RESOURCE"), wxBITMAP_TYPE_ICO_RESOURCE
},
2333 { wxT("wxBITMAP_TYPE_CUR"), wxBITMAP_TYPE_CUR
},
2334 { wxT("wxBITMAP_TYPE_CUR_RESOURCE"), wxBITMAP_TYPE_CUR_RESOURCE
},
2335 { wxT("wxBITMAP_TYPE_XBM_DATA"), wxBITMAP_TYPE_XBM_DATA
},
2336 { wxT("wxBITMAP_TYPE_XPM_DATA"), wxBITMAP_TYPE_XPM_DATA
},
2337 { wxT("wxBITMAP_TYPE_ANY"), wxBITMAP_TYPE_ANY
}
2340 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
2342 long wxParseWindowStyle(const wxString
& bitListString
)
2347 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2348 while (word
!= NULL
)
2352 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2353 if (wxStrcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2355 bitList
|= wxResourceBitListTable
[j
].bits
;
2361 wxLogWarning(_("Unrecognized style %s whilst parsing resource."), word
);
2364 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2370 * Load a bitmap from a wxWindows resource, choosing an optimum
2371 * depth and appropriate type.
2374 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
2377 table
= wxDefaultResourceTable
;
2379 wxItemResource
*item
= table
->FindResource(resource
);
2382 if ((item
->GetType() == wxT("")) || (item
->GetType() != wxT("wxBitmap")))
2384 wxLogWarning(_("%s not a bitmap resource specification."), (const wxChar
*) resource
);
2385 return wxNullBitmap
;
2387 int thisDepth
= wxDisplayDepth();
2388 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2390 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2392 // Try to find optimum bitmap for this platform/colour depth
2393 wxNode
*node
= item
->GetChildren().GetFirst();
2396 wxItemResource
*child
= (wxItemResource
*)node
->GetData();
2397 int platform
= (int)child
->GetValue2();
2398 int noColours
= (int)child
->GetValue3();
2400 char *name = child->GetName();
2401 int bitmapType = (int)child->GetValue1();
2402 int xRes = child->GetWidth();
2403 int yRes = child->GetHeight();
2408 case RESOURCE_PLATFORM_ANY
:
2410 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2411 optResource
= child
;
2414 // Maximise the number of colours.
2415 // If noColours is zero (unspecified), then assume this
2416 // is the right one.
2417 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2418 optResource
= child
;
2423 case RESOURCE_PLATFORM_WINDOWS
:
2425 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2426 optResource
= child
;
2429 // Maximise the number of colours
2430 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2431 optResource
= child
;
2437 case RESOURCE_PLATFORM_X
:
2439 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2440 optResource
= child
;
2443 // Maximise the number of colours
2444 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2445 optResource
= child
;
2451 case RESOURCE_PLATFORM_MAC
:
2453 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2454 optResource
= child
;
2457 // Maximise the number of colours
2458 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2459 optResource
= child
;
2467 node
= node
->GetNext();
2469 // If no matching resource, fail.
2471 return wxNullBitmap
;
2473 wxString name
= optResource
->GetName();
2474 int bitmapType
= (int)optResource
->GetValue1();
2477 case wxBITMAP_TYPE_XBM_DATA
:
2480 wxItemResource
*item
= table
->FindResource(name
);
2483 wxLogWarning(_("Failed to find XBM resource %s.\n"
2484 "Forgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2485 return wxNullBitmap
;
2487 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2489 wxLogWarning(_("No XBM facility available!"));
2493 case wxBITMAP_TYPE_XPM_DATA
:
2495 wxItemResource
*item
= table
->FindResource(name
);
2498 wxLogWarning(_("Failed to find XPM resource %s.\nForgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2499 return wxNullBitmap
;
2501 return wxBitmap((char **)item
->GetValue1());
2505 #if defined(__WXPM__)
2506 return wxNullBitmap
;
2508 return wxBitmap(name
, (wxBitmapType
)bitmapType
);
2513 return wxNullBitmap
;
2518 wxLogWarning(_("Bitmap resource specification %s not found."), (const wxChar
*) resource
);
2519 return wxNullBitmap
;
2524 * Load an icon from a wxWindows resource, choosing an optimum
2525 * depth and appropriate type.
2528 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2531 table
= wxDefaultResourceTable
;
2533 wxItemResource
*item
= table
->FindResource(resource
);
2536 if ((item
->GetType() == wxT("")) || wxStrcmp(item
->GetType(), wxT("wxIcon")) != 0)
2538 wxLogWarning(_("%s not an icon resource specification."), (const wxChar
*) resource
);
2541 int thisDepth
= wxDisplayDepth();
2542 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2544 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2546 // Try to find optimum icon for this platform/colour depth
2547 wxNode
*node
= item
->GetChildren().GetFirst();
2550 wxItemResource
*child
= (wxItemResource
*)node
->GetData();
2551 int platform
= (int)child
->GetValue2();
2552 int noColours
= (int)child
->GetValue3();
2554 char *name = child->GetName();
2555 int bitmapType = (int)child->GetValue1();
2556 int xRes = child->GetWidth();
2557 int yRes = child->GetHeight();
2562 case RESOURCE_PLATFORM_ANY
:
2564 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2565 optResource
= child
;
2568 // Maximise the number of colours.
2569 // If noColours is zero (unspecified), then assume this
2570 // is the right one.
2571 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2572 optResource
= child
;
2577 case RESOURCE_PLATFORM_WINDOWS
:
2579 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2580 optResource
= child
;
2583 // Maximise the number of colours
2584 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2585 optResource
= child
;
2591 case RESOURCE_PLATFORM_X
:
2593 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2594 optResource
= child
;
2597 // Maximise the number of colours
2598 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2599 optResource
= child
;
2605 case RESOURCE_PLATFORM_MAC
:
2607 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2608 optResource
= child
;
2611 // Maximise the number of colours
2612 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2613 optResource
= child
;
2621 node
= node
->GetNext();
2623 // If no matching resource, fail.
2627 wxString name
= optResource
->GetName();
2628 int bitmapType
= (int)optResource
->GetValue1();
2631 case wxBITMAP_TYPE_XBM_DATA
:
2634 wxItemResource
*item
= table
->FindResource(name
);
2637 wxLogWarning(_("Failed to find XBM resource %s.\n"
2638 "Forgot to use wxResourceLoadIconData?"), (const wxChar
*) name
);
2641 return wxIcon((const char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2643 wxLogWarning(_("No XBM facility available!"));
2647 case wxBITMAP_TYPE_XPM_DATA
:
2649 // *** XPM ICON NOT YET IMPLEMENTED IN WXWINDOWS ***
2651 wxItemResource *item = table->FindResource(name);
2655 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2659 return wxIcon((char **)item->GetValue1());
2661 wxLogWarning(_("No XPM icon facility available!"));
2666 #if defined( __WXGTK__ ) || defined( __WXMOTIF__ )
2667 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2670 return wxIcon(name
, (wxBitmapType
) bitmapType
);
2678 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2685 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2687 wxMenu
*menu
= new wxMenu
;
2688 wxNode
*node
= item
->GetChildren().GetFirst();
2691 wxItemResource
*child
= (wxItemResource
*)node
->GetData();
2692 if ((child
->GetType() != wxT("")) && (child
->GetType() == wxT("wxMenuSeparator")))
2693 menu
->AppendSeparator();
2694 else if (child
->GetChildren().GetCount() > 0)
2696 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2698 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2702 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2704 node
= node
->GetNext();
2709 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2712 table
= wxDefaultResourceTable
;
2714 wxItemResource
*menuResource
= table
->FindResource(resource
);
2715 if (menuResource
&& (menuResource
->GetType() != wxT("")) && (menuResource
->GetType() == wxT("wxMenu")))
2718 menuBar
= new wxMenuBar
;
2719 wxNode
*node
= menuResource
->GetChildren().GetFirst();
2722 wxItemResource
*child
= (wxItemResource
*)node
->GetData();
2723 wxMenu
*menu
= wxResourceCreateMenu(child
);
2725 menuBar
->Append(menu
, child
->GetTitle());
2726 node
= node
->GetNext();
2730 return (wxMenuBar
*) NULL
;
2733 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2736 table
= wxDefaultResourceTable
;
2738 wxItemResource
*menuResource
= table
->FindResource(resource
);
2739 if (menuResource
&& (menuResource
->GetType() != wxT("")) && (menuResource
->GetType() == wxT("wxMenu")))
2740 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2741 return wxResourceCreateMenu(menuResource
);
2742 return (wxMenu
*) NULL
;
2745 #endif // wxUSE_MENUS
2747 // Global equivalents (so don't have to refer to default table explicitly)
2748 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2751 table
= wxDefaultResourceTable
;
2753 return table
->ParseResourceData(resource
);
2756 bool wxResourceParseData(const char* resource
, wxResourceTable
*table
)
2758 wxString
str(resource
, wxConvLibc
);
2760 table
= wxDefaultResourceTable
;
2762 return table
->ParseResourceData(str
);
2765 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2768 table
= wxDefaultResourceTable
;
2770 return table
->ParseResourceFile(filename
);
2773 // Register XBM/XPM data
2774 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2777 table
= wxDefaultResourceTable
;
2779 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2782 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2785 table
= wxDefaultResourceTable
;
2787 return table
->RegisterResourceBitmapData(name
, data
);
2790 void wxResourceClear(wxResourceTable
*table
)
2793 table
= wxDefaultResourceTable
;
2795 table
->ClearTable();
2802 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2805 table
= wxDefaultResourceTable
;
2807 table
->identifiers
.Put(name
, (wxObject
*)(long)value
);
2811 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2814 table
= wxDefaultResourceTable
;
2816 return (int)(long)table
->identifiers
.Get(name
);
2820 * Parse #include file for #defines (only)
2823 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2826 table
= wxDefaultResourceTable
;
2828 FILE *fd
= wxFopen(f
, wxT("r"));
2833 while (wxGetResourceToken(fd
))
2835 if (strcmp(wxResourceBuffer
, "#define") == 0)
2837 wxGetResourceToken(fd
);
2838 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2839 wxGetResourceToken(fd
);
2840 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2841 if (wxIsdigit(value
[0]))
2843 int val
= (int)wxAtol(value
);
2844 wxResourceAddIdentifier(name
, val
, table
);
2855 * Reading strings as if they were .wxr files
2858 static int getc_string(char *s
)
2860 int ch
= s
[wxResourceStringPtr
];
2865 wxResourceStringPtr
++;
2870 static int ungetc_string()
2872 wxResourceStringPtr
--;
2876 bool wxEatWhiteSpaceString(char *s
)
2880 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().GetFirst();
3255 wxItemResource
*childResource
= (wxItemResource
*)node
->GetData();
3257 (void) wxCreateItem(thisWindow
, childResource
, resource
, table
);
3259 node
= node
->GetNext();
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