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
= wxEmptyString
;
155 m_title
= wxEmptyString
;
156 m_name
= wxEmptyString
;
158 m_x
= m_y
= m_width
= m_height
= 0;
159 m_value1
= m_value2
= m_value3
= m_value5
= 0;
160 m_value4
= wxEmptyString
;
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 wxHashTable::Node
*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 wxHashTable::Node
*node
= Next();
315 wxHashTable::Node
*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().empty())
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().empty() || 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(wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, wxDefaultCoord
, 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().empty())
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
= wxEmptyString
;
665 wxString title
= wxEmptyString
;
666 wxString name
= wxEmptyString
;
667 wxString backColourHex
= wxEmptyString
;
668 wxString labelColourHex
= wxEmptyString
;
669 wxString buttonColourHex
= wxEmptyString
;
671 long windowStyle
= wxDEFAULT_DIALOG_STYLE
;
675 int x
= 0; int y
= 0; int width
= wxDefaultCoord
; int height
= wxDefaultCoord
;
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
);
711 windowStyle
= wxParseWindowStyle(style
);
713 dialogItem
->SetStyle(windowStyle
);
714 dialogItem
->SetValue1(isModal
);
716 #pragma message disable CODCAUUNR
718 if (windowStyle
& wxDIALOG_MODAL
) // Uses style in wxWin 2
719 dialogItem
->SetValue1(true);
721 #pragma message enable CODCAUUNR
724 dialogItem
->SetName(name
);
725 dialogItem
->SetTitle(title
);
726 dialogItem
->SetSize(x
, y
, width
, height
);
728 // Check for wxWin 1.68-style specifications
729 if (style
.Find(wxT("VERTICAL_LABEL")) != wxNOT_FOUND
)
730 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL
);
731 else if (style
.Find(wxT("HORIZONTAL_LABEL")) != wxNOT_FOUND
)
732 dialogItem
->SetResourceStyle(dialogItem
->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL
);
734 if (!backColourHex
.empty())
739 r
= wxHexToDec(backColourHex
.Mid(0, 2));
740 g
= wxHexToDec(backColourHex
.Mid(2, 2));
741 b
= wxHexToDec(backColourHex
.Mid(4, 2));
742 dialogItem
->SetBackgroundColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
744 if (!labelColourHex
.empty())
749 r
= wxHexToDec(labelColourHex
.Mid(0, 2));
750 g
= wxHexToDec(labelColourHex
.Mid(2, 2));
751 b
= wxHexToDec(labelColourHex
.Mid(4, 2));
752 dialogItem
->SetLabelColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
754 if (!buttonColourHex
.empty())
759 r
= wxHexToDec(buttonColourHex
.Mid(0, 2));
760 g
= wxHexToDec(buttonColourHex
.Mid(2, 2));
761 b
= wxHexToDec(buttonColourHex
.Mid(4, 2));
762 dialogItem
->SetButtonColour(wxColour((unsigned char)r
,(unsigned char)g
,(unsigned char)b
));
766 dialogItem
->SetFont(wxResourceInterpretFontSpec(fontExpr
));
767 else if (buttonFontExpr
)
768 dialogItem
->SetFont(wxResourceInterpretFontSpec(buttonFontExpr
));
769 else if (labelFontExpr
)
770 dialogItem
->SetFont(wxResourceInterpretFontSpec(labelFontExpr
));
772 // Now parse all controls
773 wxExpr
*controlExpr
= expr
->GetFirst();
776 if (controlExpr
->Number() == 3)
778 wxString
controlKeyword(controlExpr
->Nth(1)->StringValue());
779 if (!controlKeyword
.empty() && controlKeyword
== wxT("control"))
781 // The value part: always a list.
782 wxExpr
*listExpr
= controlExpr
->Nth(2);
783 if (listExpr
->Type() == PrologList
)
785 wxItemResource
*controlItem
= wxResourceInterpretControl(table
, listExpr
);
788 dialogItem
->GetChildren().Append(controlItem
);
793 controlExpr
= controlExpr
->GetNext();
798 wxItemResource
*wxResourceInterpretControl(wxResourceTable
& table
, wxExpr
*expr
)
800 wxItemResource
*controlItem
= new wxItemResource
;
802 // First, find the standard features of a control definition:
803 // [optional integer/string id], control name, title, style, name, x, y, width, height
805 wxString controlType
;
810 long windowStyle
= 0;
811 int x
= 0; int y
= 0; int width
= wxDefaultCoord
; int height
= wxDefaultCoord
;
814 wxExpr
*expr1
= expr
->Nth(0);
816 if ( expr1
->Type() == PrologString
|| expr1
->Type() == PrologWord
)
818 if ( wxIsValidControlClass(expr1
->StringValue()) )
821 controlType
= expr1
->StringValue();
825 wxString
str(expr1
->StringValue());
826 id
= wxResourceGetIdentifier(str
, &table
);
829 wxLogWarning(_("Could not resolve control class or id '%s'. Use (non-zero) integer instead\n or provide #define (see manual for caveats)"),
830 (const wxChar
*) expr1
->StringValue());
832 return (wxItemResource
*) NULL
;
836 // Success - we have an id, so the 2nd element must be the control class.
837 controlType
= expr
->Nth(1)->StringValue();
842 else if (expr1
->Type() == PrologInteger
)
844 id
= (int)expr1
->IntegerValue();
845 // Success - we have an id, so the 2nd element must be the control class.
846 controlType
= expr
->Nth(1)->StringValue();
850 expr1
= expr
->Nth(count
);
853 title
= expr1
->StringValue();
855 expr1
= expr
->Nth(count
);
859 style
= expr1
->StringValue();
860 windowStyle
= wxParseWindowStyle(style
);
863 expr1
= expr
->Nth(count
);
866 name
= expr1
->StringValue();
868 expr1
= expr
->Nth(count
);
871 x
= (int)expr1
->IntegerValue();
873 expr1
= expr
->Nth(count
);
876 y
= (int)expr1
->IntegerValue();
878 expr1
= expr
->Nth(count
);
881 width
= (int)expr1
->IntegerValue();
883 expr1
= expr
->Nth(count
);
886 height
= (int)expr1
->IntegerValue();
888 controlItem
->SetStyle(windowStyle
);
889 controlItem
->SetName(name
);
890 controlItem
->SetTitle(title
);
891 controlItem
->SetSize(x
, y
, width
, height
);
892 controlItem
->SetType(controlType
);
893 controlItem
->SetId(id
);
895 // Check for wxWin 1.68-style specifications
896 if (style
.Find(wxT("VERTICAL_LABEL")) != wxNOT_FOUND
)
897 controlItem
->SetResourceStyle(controlItem
->GetResourceStyle() | wxRESOURCE_VERTICAL_LABEL
);
898 else if (style
.Find(wxT("HORIZONTAL_LABEL")) != wxNOT_FOUND
)
899 controlItem
->SetResourceStyle(controlItem
->GetResourceStyle() | wxRESOURCE_HORIZONTAL_LABEL
);
901 if (controlType
== wxT("wxButton"))
903 // Check for bitmap resource name (in case loading old-style resource file)
904 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
906 wxString
str(expr
->Nth(count
)->StringValue());
911 controlItem
->SetValue4(str
);
912 controlItem
->SetType(wxT("wxBitmapButton"));
915 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
916 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
918 else if (controlType
== wxT("wxBitmapButton"))
920 // Check for bitmap resource name
921 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
923 wxString
str(expr
->Nth(count
)->StringValue());
924 controlItem
->SetValue4(str
);
926 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
927 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
930 else if (controlType
== wxT("wxCheckBox"))
932 // Check for default value
933 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
935 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
937 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
938 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
942 else if (controlType
== wxT("wxRadioButton"))
944 // Check for default value
945 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
947 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
949 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
950 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
954 else if (controlType
== wxT("wxText") || controlType
== wxT("wxTextCtrl") || controlType
== wxT("wxMultiText"))
956 // Check for default value
957 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
959 wxString
str(expr
->Nth(count
)->StringValue());
960 controlItem
->SetValue4(str
);
963 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
965 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
966 // Skip past the obsolete label font spec if there are two consecutive specs
967 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
969 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
973 else if (controlType
== wxT("wxMessage") || controlType
== wxT("wxStaticText"))
975 // Check for bitmap resource name (in case it's an old-style .wxr file)
976 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
978 wxString
str(expr
->Nth(count
)->StringValue());
979 controlItem
->SetValue4(str
);
981 controlItem
->SetType(wxT("wxStaticText"));
983 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
984 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
986 else if (controlType
== wxT("wxStaticBitmap"))
988 // Check for bitmap resource name
989 if (expr
->Nth(count
) && ((expr
->Nth(count
)->Type() == PrologString
) || (expr
->Nth(count
)->Type() == PrologWord
)))
991 wxString
str(expr
->Nth(count
)->StringValue());
992 controlItem
->SetValue4(str
);
995 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
996 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
998 else if (controlType
== wxT("wxGroupBox") || controlType
== wxT("wxStaticBox"))
1000 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1001 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1003 else if (controlType
== wxT("wxGauge"))
1005 // Check for default value
1006 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1008 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1012 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1014 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1017 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1019 // Skip past the obsolete label font spec if there are two consecutive specs
1020 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1022 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1027 else if (controlType
== wxT("wxSlider"))
1029 // Check for default value
1030 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1032 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1036 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1038 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1042 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1044 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1047 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1049 // controlItem->SetLabelFont(wxResourceInterpretFontSpec(expr->Nth(count)));
1053 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1054 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1060 else if (controlType
== wxT("wxScrollBar"))
1063 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1065 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1069 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1071 controlItem
->SetValue2(expr
->Nth(count
)->IntegerValue());
1075 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1077 controlItem
->SetValue3(expr
->Nth(count
)->IntegerValue());
1081 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1082 controlItem
->SetValue5(expr
->Nth(count
)->IntegerValue());
1087 else if (controlType
== wxT("wxListBox"))
1089 wxExpr
*valueList
= (wxExpr
*) NULL
;
1091 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1093 wxStringList stringList
;
1094 wxExpr
*stringExpr
= valueList
->GetFirst();
1097 stringList
.Add(stringExpr
->StringValue());
1098 stringExpr
= stringExpr
->GetNext();
1100 controlItem
->SetStringValues(stringList
);
1102 // This is now obsolete: it's in the window style.
1103 // Check for wxSINGLE/wxMULTIPLE
1104 wxExpr
*mult
= (wxExpr
*) NULL
;
1106 controlItem->SetValue1(wxLB_SINGLE);
1108 if (((mult
= expr
->Nth(count
)) != 0) && ((mult
->Type() == PrologString
)||(mult
->Type() == PrologWord
)))
1111 wxString m(mult->StringValue());
1112 if (m == "wxLB_MULTIPLE")
1113 controlItem->SetValue1(wxLB_MULTIPLE);
1114 else if (m == "wxLB_EXTENDED")
1115 controlItem->SetValue1(wxLB_EXTENDED);
1120 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1122 // Skip past the obsolete label font spec if there are two consecutive specs
1123 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1125 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1129 else if (controlType
== wxT("wxChoice"))
1131 wxExpr
*valueList
= (wxExpr
*) NULL
;
1132 // Check for default value list
1133 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1135 wxStringList stringList
;
1136 wxExpr
*stringExpr
= valueList
->GetFirst();
1139 stringList
.Add(stringExpr
->StringValue());
1140 stringExpr
= stringExpr
->GetNext();
1142 controlItem
->SetStringValues(stringList
);
1146 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1148 // Skip past the obsolete label font spec if there are two consecutive specs
1149 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1151 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1156 else if (controlType
== wxT("wxComboBox"))
1158 wxExpr
*textValue
= expr
->Nth(count
);
1159 if (textValue
&& (textValue
->Type() == PrologString
|| textValue
->Type() == PrologWord
))
1161 wxString
str(textValue
->StringValue());
1162 controlItem
->SetValue4(str
);
1166 wxExpr
*valueList
= (wxExpr
*) NULL
;
1167 // Check for default value list
1168 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1170 wxStringList stringList
;
1171 wxExpr
*stringExpr
= valueList
->GetFirst();
1174 stringList
.Add(stringExpr
->StringValue());
1175 stringExpr
= stringExpr
->GetNext();
1177 controlItem
->SetStringValues(stringList
);
1181 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1183 // Skip past the obsolete label font spec if there are two consecutive specs
1184 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1186 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1193 else if (controlType
== wxT("wxRadioBox"))
1195 wxExpr
*valueList
= (wxExpr
*) NULL
;
1196 // Check for default value list
1197 if (((valueList
= expr
->Nth(count
)) != 0) && (valueList
->Type() == PrologList
))
1199 wxStringList stringList
;
1200 wxExpr
*stringExpr
= valueList
->GetFirst();
1203 stringList
.Add(stringExpr
->StringValue());
1204 stringExpr
= stringExpr
->GetNext();
1206 controlItem
->SetStringValues(stringList
);
1209 // majorDim (number of rows or cols)
1210 if (expr
->Nth(count
) && (expr
->Nth(count
)->Type() == PrologInteger
))
1212 controlItem
->SetValue1(expr
->Nth(count
)->IntegerValue());
1216 controlItem
->SetValue1(0);
1218 if (expr
->Nth(count
) && expr
->Nth(count
)->Type() == PrologList
)
1220 // Skip past the obsolete label font spec if there are two consecutive specs
1221 if (expr
->Nth(count
+1) && expr
->Nth(count
+1)->Type() == PrologList
)
1223 controlItem
->SetFont(wxResourceInterpretFontSpec(expr
->Nth(count
)));
1231 return (wxItemResource
*) NULL
;
1236 // Forward declaration
1237 wxItemResource
*wxResourceInterpretMenu1(wxResourceTable
& table
, wxExpr
*expr
);
1240 * Interpet a menu item
1243 wxItemResource
*wxResourceInterpretMenuItem(wxResourceTable
& table
, wxExpr
*expr
)
1245 wxItemResource
*item
= new wxItemResource
;
1247 wxExpr
*labelExpr
= expr
->Nth(0);
1248 wxExpr
*idExpr
= expr
->Nth(1);
1249 wxExpr
*helpExpr
= expr
->Nth(2);
1250 wxExpr
*checkableExpr
= expr
->Nth(3);
1252 // Further keywords/attributes to follow sometime...
1253 if (expr
->Number() == 0)
1255 // item->SetType(wxRESOURCE_TYPE_SEPARATOR);
1256 item
->SetType(wxT("wxMenuSeparator"));
1261 // item->SetType(wxTYPE_MENU); // Well, menu item, but doesn't matter.
1262 item
->SetType(wxT("wxMenu")); // Well, menu item, but doesn't matter.
1265 wxString
str(labelExpr
->StringValue());
1266 item
->SetTitle(str
);
1271 // If a string or word, must look up in identifier table.
1272 if ((idExpr
->Type() == PrologString
) || (idExpr
->Type() == PrologWord
))
1274 wxString
str(idExpr
->StringValue());
1275 id
= wxResourceGetIdentifier(str
, &table
);
1278 wxLogWarning(_("Could not resolve menu id '%s'. Use (non-zero) integer instead\nor provide #define (see manual for caveats)"),
1279 (const wxChar
*) idExpr
->StringValue());
1282 else if (idExpr
->Type() == PrologInteger
)
1283 id
= (int)idExpr
->IntegerValue();
1284 item
->SetValue1(id
);
1288 wxString
str(helpExpr
->StringValue());
1289 item
->SetValue4(str
);
1292 item
->SetValue2(checkableExpr
->IntegerValue());
1294 // Find the first expression that's a list, for submenu
1295 wxExpr
*subMenuExpr
= expr
->GetFirst();
1296 while (subMenuExpr
&& (subMenuExpr
->Type() != PrologList
))
1297 subMenuExpr
= subMenuExpr
->GetNext();
1301 wxItemResource
*child
= wxResourceInterpretMenuItem(table
, subMenuExpr
);
1302 item
->GetChildren().Append(child
);
1303 subMenuExpr
= subMenuExpr
->GetNext();
1310 * Interpret a nested list as a menu
1313 wxItemResource *wxResourceInterpretMenu1(wxResourceTable& table, wxExpr *expr)
1315 wxItemResource *menu = new wxItemResource;
1316 // menu->SetType(wxTYPE_MENU);
1317 menu->SetType("wxMenu");
1318 wxExpr *element = expr->GetFirst();
1321 wxItemResource *item = wxResourceInterpretMenuItem(table, element);
1323 menu->GetChildren().Append(item);
1324 element = element->GetNext();
1330 wxItemResource
*wxResourceInterpretMenu(wxResourceTable
& table
, wxExpr
*expr
)
1332 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1333 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1335 return (wxItemResource
*) NULL
;
1337 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1340 return (wxItemResource
*) NULL
;
1343 if (expr
->GetAttributeValue(wxT("name"), name
))
1345 menuResource
->SetName(name
);
1348 return menuResource
;
1351 wxItemResource
*wxResourceInterpretMenuBar(wxResourceTable
& table
, wxExpr
*expr
)
1353 wxExpr
*listExpr
= (wxExpr
*) NULL
;
1354 expr
->GetAttributeValue(wxT("menu"), &listExpr
);
1356 return (wxItemResource
*) NULL
;
1358 wxItemResource
*resource
= new wxItemResource
;
1359 resource
->SetType(wxT("wxMenu"));
1360 // resource->SetType(wxTYPE_MENU);
1362 wxExpr
*element
= listExpr
->GetFirst();
1365 wxItemResource
*menuResource
= wxResourceInterpretMenuItem(table
, listExpr
);
1366 resource
->GetChildren().Append(menuResource
);
1367 element
= element
->GetNext();
1371 if (expr
->GetAttributeValue(wxT("name"), name
))
1373 resource
->SetName(name
);
1379 wxItemResource
*wxResourceInterpretString(wxResourceTable
& WXUNUSED(table
), wxExpr
*WXUNUSED(expr
))
1381 return (wxItemResource
*) NULL
;
1384 wxItemResource
*wxResourceInterpretBitmap(wxResourceTable
& WXUNUSED(table
), wxExpr
*expr
)
1386 wxItemResource
*bitmapItem
= new wxItemResource
;
1387 // bitmapItem->SetType(wxTYPE_BITMAP);
1388 bitmapItem
->SetType(wxT("wxBitmap"));
1390 if (expr
->GetAttributeValue(wxT("name"), name
))
1392 bitmapItem
->SetName(name
);
1394 // Now parse all bitmap specifications
1395 wxExpr
*bitmapExpr
= expr
->GetFirst();
1398 if (bitmapExpr
->Number() == 3)
1400 wxString
bitmapKeyword(bitmapExpr
->Nth(1)->StringValue());
1401 if (bitmapKeyword
== wxT("bitmap") || bitmapKeyword
== wxT("icon"))
1403 // The value part: always a list.
1404 wxExpr
*listExpr
= bitmapExpr
->Nth(2);
1405 if (listExpr
->Type() == PrologList
)
1407 wxItemResource
*bitmapSpec
= new wxItemResource
;
1408 // bitmapSpec->SetType(wxTYPE_BITMAP);
1409 bitmapSpec
->SetType(wxT("wxBitmap"));
1411 // List is of form: [filename, bitmaptype, platform, colours, xresolution, yresolution]
1412 // where everything after 'filename' is optional.
1413 wxExpr
*nameExpr
= listExpr
->Nth(0);
1414 wxExpr
*typeExpr
= listExpr
->Nth(1);
1415 wxExpr
*platformExpr
= listExpr
->Nth(2);
1416 wxExpr
*coloursExpr
= listExpr
->Nth(3);
1417 wxExpr
*xresExpr
= listExpr
->Nth(4);
1418 wxExpr
*yresExpr
= listExpr
->Nth(5);
1419 if (nameExpr
&& !nameExpr
->StringValue().empty())
1421 bitmapSpec
->SetName(nameExpr
->StringValue());
1423 if (typeExpr
&& !typeExpr
->StringValue().empty())
1425 bitmapSpec
->SetValue1(wxParseWindowStyle(typeExpr
->StringValue()));
1428 bitmapSpec
->SetValue1(0);
1430 if (platformExpr
&& !platformExpr
->StringValue().empty())
1432 wxString
plat(platformExpr
->StringValue());
1433 if (plat
== wxT("windows") || plat
== wxT("WINDOWS"))
1434 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_WINDOWS
);
1435 else if (plat
== wxT("x") || plat
== wxT("X"))
1436 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_X
);
1437 else if (plat
== wxT("mac") || plat
== wxT("MAC"))
1438 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_MAC
);
1440 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1443 bitmapSpec
->SetValue2(RESOURCE_PLATFORM_ANY
);
1446 bitmapSpec
->SetValue3(coloursExpr
->IntegerValue());
1450 xres
= (int)xresExpr
->IntegerValue();
1452 yres
= (int)yresExpr
->IntegerValue();
1453 bitmapSpec
->SetSize(0, 0, xres
, yres
);
1455 bitmapItem
->GetChildren().Append(bitmapSpec
);
1459 bitmapExpr
= bitmapExpr
->GetNext();
1465 wxItemResource
*wxResourceInterpretIcon(wxResourceTable
& table
, wxExpr
*expr
)
1467 wxItemResource
*item
= wxResourceInterpretBitmap(table
, expr
);
1470 // item->SetType(wxTYPE_ICON);
1471 item
->SetType(wxT("wxIcon"));
1475 return (wxItemResource
*) NULL
;
1478 // Interpret list expression as a font
1479 wxFont
wxResourceInterpretFontSpec(wxExpr
*expr
)
1481 if (expr
->Type() != PrologList
)
1485 int family
= wxSWISS
;
1486 int style
= wxNORMAL
;
1487 int weight
= wxNORMAL
;
1491 wxExpr
*pointExpr
= expr
->Nth(0);
1492 wxExpr
*familyExpr
= expr
->Nth(1);
1493 wxExpr
*styleExpr
= expr
->Nth(2);
1494 wxExpr
*weightExpr
= expr
->Nth(3);
1495 wxExpr
*underlineExpr
= expr
->Nth(4);
1496 wxExpr
*faceNameExpr
= expr
->Nth(5);
1498 point
= (int)pointExpr
->IntegerValue();
1503 str
= familyExpr
->StringValue();
1504 family
= (int)wxParseWindowStyle(str
);
1508 str
= styleExpr
->StringValue();
1509 style
= (int)wxParseWindowStyle(str
);
1513 str
= weightExpr
->StringValue();
1514 weight
= (int)wxParseWindowStyle(str
);
1517 underline
= (int)underlineExpr
->IntegerValue();
1519 faceName
= faceNameExpr
->StringValue();
1521 return *wxTheFontList
->FindOrCreateFont(point
, family
, style
, weight
,
1522 (underline
!= 0), faceName
);
1526 * (Re)allocate buffer for reading in from resource file
1529 bool wxReallocateResourceBuffer()
1531 if (!wxResourceBuffer
)
1533 wxResourceBufferSize
= 1000;
1534 wxResourceBuffer
= new char[wxResourceBufferSize
];
1537 if (wxResourceBuffer
)
1539 long newSize
= wxResourceBufferSize
+ 1000;
1540 char *tmp
= new char[(int)newSize
];
1541 strncpy(tmp
, wxResourceBuffer
, (int)wxResourceBufferCount
);
1542 delete[] wxResourceBuffer
;
1543 wxResourceBuffer
= tmp
;
1544 wxResourceBufferSize
= newSize
;
1549 static bool wxEatWhiteSpace(FILE *fd
)
1553 while ((ch
= getc(fd
)) != EOF
)
1568 ungetc(prev_ch
, fd
);
1576 while ((ch
= getc(fd
)) != EOF
)
1578 if (ch
== '/' && prev_ch
== '*')
1586 static char buffer
[255];
1587 fgets(buffer
, 255, fd
);
1591 ungetc(prev_ch
, fd
);
1605 static bool wxEatWhiteSpace(wxInputStream
*is
)
1607 char ch
= is
->GetC() ;
1608 if ((ch
!= ' ') && (ch
!= '/') && (ch
!= ' ') && (ch
!= 10) && (ch
!= 13) && (ch
!= 9))
1615 while (ch
== ' ' || ch
== 10 || ch
== 13 || ch
== 9)
1617 // Check for comment
1623 bool finished
= false;
1631 int newCh
= is
->GetC();
1646 return wxEatWhiteSpace(is
);
1649 bool wxGetResourceToken(FILE *fd
)
1651 if (!wxResourceBuffer
)
1652 wxReallocateResourceBuffer();
1653 wxResourceBuffer
[0] = 0;
1654 wxEatWhiteSpace(fd
);
1660 wxResourceBufferCount
= 0;
1667 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1670 // Escaped characters
1671 else if (ch
== '\\')
1673 int newCh
= getc(fd
);
1676 else if (newCh
== 10)
1684 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1685 wxReallocateResourceBuffer();
1686 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1687 wxResourceBufferCount
++;
1690 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1694 wxResourceBufferCount
= 0;
1696 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1698 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1699 wxReallocateResourceBuffer();
1700 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1701 wxResourceBufferCount
++;
1705 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1712 bool wxGetResourceToken(wxInputStream
*is
)
1714 if (!wxResourceBuffer
)
1715 wxReallocateResourceBuffer();
1716 wxResourceBuffer
[0] = 0;
1717 wxEatWhiteSpace(is
);
1719 int ch
= is
->GetC() ;
1723 wxResourceBufferCount
= 0;
1730 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1733 // Escaped characters
1734 else if (ch
== '\\')
1736 int newCh
= is
->GetC();
1739 else if (newCh
== 10)
1741 else if (newCh
== 13) // mac
1749 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1750 wxReallocateResourceBuffer();
1751 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
1752 wxResourceBufferCount
++;
1755 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1759 wxResourceBufferCount
= 0;
1761 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
1763 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
1764 wxReallocateResourceBuffer();
1765 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
1766 wxResourceBufferCount
++;
1770 wxResourceBuffer
[wxResourceBufferCount
] = 0;
1778 * Files are in form:
1779 static char *name = "....";
1780 with possible comments.
1783 bool wxResourceReadOneResource(FILE *fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1786 table
= wxDefaultResourceTable
;
1788 // static or #define
1789 if (!wxGetResourceToken(fd
))
1795 if (strcmp(wxResourceBuffer
, "#define") == 0)
1797 wxGetResourceToken(fd
);
1798 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1799 wxGetResourceToken(fd
);
1800 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1801 if (wxIsdigit(value
[0]))
1803 int val
= (int)wxAtol(value
);
1804 wxResourceAddIdentifier(name
, val
, table
);
1808 wxLogWarning(_("#define %s must be an integer."), name
);
1818 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1820 wxGetResourceToken(fd
);
1821 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
1822 wxChar
*actualName
= name
;
1823 if (name
[0] == wxT('"'))
1824 actualName
= name
+ 1;
1825 int len
= wxStrlen(name
);
1826 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1828 if (!wxResourceParseIncludeFile(actualName
, table
))
1830 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1835 else if (strcmp(wxResourceBuffer
, "static") != 0)
1838 wxStrcpy(buf
, _("Found "));
1839 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
1840 wxStrcat(buf
, _(", expected static, #include or #define\nwhile parsing resource."));
1846 if (!wxGetResourceToken(fd
))
1848 wxLogWarning(_("Unexpected end of file while parsing resource."));
1853 if (strcmp(wxResourceBuffer
, "char") != 0)
1855 wxLogWarning(_("Expected 'char' while parsing resource."));
1860 if (!wxGetResourceToken(fd
))
1862 wxLogWarning(_("Unexpected end of file while parsing resource."));
1867 if (wxResourceBuffer
[0] != '*')
1869 wxLogWarning(_("Expected '*' while parsing resource."));
1872 wxChar nameBuf
[100];
1873 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
1877 if (!wxGetResourceToken(fd
))
1879 wxLogWarning(_("Unexpected end of file while parsing resource."));
1884 if (strcmp(wxResourceBuffer
, "=") != 0)
1886 wxLogWarning(_("Expected '=' while parsing resource."));
1891 if (!wxGetResourceToken(fd
))
1893 wxLogWarning(_("Unexpected end of file while parsing resource."));
1899 if (!db
.ReadPrologFromString(wxResourceBuffer
))
1901 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
1906 if (!wxGetResourceToken(fd
))
1913 bool wxResourceReadOneResource(wxInputStream
*fd
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
1916 table
= wxDefaultResourceTable
;
1918 // static or #define
1919 if (!wxGetResourceToken(fd
))
1925 if (strcmp(wxResourceBuffer
, "#define") == 0)
1927 wxGetResourceToken(fd
);
1928 wxChar
*name
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1929 wxGetResourceToken(fd
);
1930 wxChar
*value
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1931 if (wxIsalpha(value
[0]))
1933 int val
= (int)wxAtol(value
);
1934 wxResourceAddIdentifier(name
, val
, table
);
1938 wxLogWarning(_("#define %s must be an integer."), name
);
1948 else if (strcmp(wxResourceBuffer
, "#include") == 0)
1950 wxGetResourceToken(fd
);
1951 wxChar
*name
= copystring(wxConvLibc
.cMB2WX(wxResourceBuffer
));
1952 wxChar
*actualName
= name
;
1953 if (name
[0] == wxT('"'))
1954 actualName
= name
+ 1;
1955 int len
= wxStrlen(name
);
1956 if ((len
> 0) && (name
[len
-1] == wxT('"')))
1958 if (!wxResourceParseIncludeFile(actualName
, table
))
1960 wxLogWarning(_("Could not find resource include file %s."), actualName
);
1965 else if (strcmp(wxResourceBuffer
, "static") != 0)
1968 wxStrcpy(buf
, _("Found "));
1969 wxStrncat(buf
, wxConvLibc
.cMB2WX(wxResourceBuffer
), 30);
1970 wxStrcat(buf
, _(", expected static, #include or #define\nwhile parsing resource."));
1976 if (!wxGetResourceToken(fd
))
1978 wxLogWarning(_("Unexpected end of file while parsing resource."));
1983 if (strcmp(wxResourceBuffer
, "char") != 0)
1985 wxLogWarning(_("Expected 'char' while parsing resource."));
1990 if (!wxGetResourceToken(fd
))
1992 wxLogWarning(_("Unexpected end of file while parsing resource."));
1997 if (wxResourceBuffer
[0] != '*')
1999 wxLogWarning(_("Expected '*' while parsing resource."));
2003 strncpy(nameBuf
, wxResourceBuffer
+1, 99);
2006 if (!wxGetResourceToken(fd
))
2008 wxLogWarning(_("Unexpected end of file while parsing resource."));
2013 if (strcmp(wxResourceBuffer
, "=") != 0)
2015 wxLogWarning(_("Expected '=' while parsing resource."));
2020 if (!wxGetResourceToken(fd
))
2022 wxLogWarning(_("Unexpected end of file while parsing resource."));
2028 if (!db
.ReadPrologFromString(wxResourceBuffer
))
2030 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
2035 if (!wxGetResourceToken(fd
))
2043 * Parses string window style into integer window style
2047 * Style flag parsing, e.g.
2048 * "wxSYSTEM_MENU | wxBORDER" -> integer
2051 wxChar
* wxResourceParseWord(wxChar
*s
, int *i
)
2054 return (wxChar
*) NULL
;
2056 static wxChar buf
[150];
2057 int len
= wxStrlen(s
);
2060 while ((ii
< len
) && (wxIsalpha(s
[ii
]) || (s
[ii
] == wxT('_'))))
2068 // Eat whitespace and conjunction characters
2069 while ((ii
< len
) &&
2070 ((s
[ii
] == wxT(' ')) || (s
[ii
] == wxT('|')) || (s
[ii
] == wxT(','))))
2076 return (wxChar
*) NULL
;
2081 struct wxResourceBitListStruct
2087 static wxResourceBitListStruct wxResourceBitListTable
[] =
2090 { wxT("wxSINGLE"), wxLB_SINGLE
},
2091 { wxT("wxMULTIPLE"), wxLB_MULTIPLE
},
2092 { wxT("wxEXTENDED"), wxLB_EXTENDED
},
2093 { wxT("wxLB_SINGLE"), wxLB_SINGLE
},
2094 { wxT("wxLB_MULTIPLE"), wxLB_MULTIPLE
},
2095 { wxT("wxLB_EXTENDED"), wxLB_EXTENDED
},
2096 { wxT("wxLB_NEEDED_SB"), wxLB_NEEDED_SB
},
2097 { wxT("wxLB_ALWAYS_SB"), wxLB_ALWAYS_SB
},
2098 { wxT("wxLB_SORT"), wxLB_SORT
},
2099 { wxT("wxLB_OWNERDRAW"), wxLB_OWNERDRAW
},
2100 { wxT("wxLB_HSCROLL"), wxLB_HSCROLL
},
2103 { wxT("wxCB_SIMPLE"), wxCB_SIMPLE
},
2104 { wxT("wxCB_DROPDOWN"), wxCB_DROPDOWN
},
2105 { wxT("wxCB_READONLY"), wxCB_READONLY
},
2106 { wxT("wxCB_SORT"), wxCB_SORT
},
2109 { wxT("wxGA_PROGRESSBAR"), wxGA_PROGRESSBAR
},
2110 { wxT("wxGA_HORIZONTAL"), wxGA_HORIZONTAL
},
2111 { wxT("wxGA_VERTICAL"), wxGA_VERTICAL
},
2114 { wxT("wxPASSWORD"), wxPASSWORD
},
2115 { wxT("wxPROCESS_ENTER"), wxPROCESS_ENTER
},
2116 { wxT("wxTE_PASSWORD"), wxTE_PASSWORD
},
2117 { wxT("wxTE_READONLY"), wxTE_READONLY
},
2118 { wxT("wxTE_PROCESS_ENTER"), wxTE_PROCESS_ENTER
},
2119 { wxT("wxTE_MULTILINE"), wxTE_MULTILINE
},
2120 { wxT("wxTE_NO_VSCROLL"), wxTE_NO_VSCROLL
},
2122 /* wxRadioBox/wxRadioButton */
2123 { wxT("wxRB_GROUP"), wxRB_GROUP
},
2124 { wxT("wxRA_SPECIFY_COLS"), wxRA_SPECIFY_COLS
},
2125 { wxT("wxRA_SPECIFY_ROWS"), wxRA_SPECIFY_ROWS
},
2126 { wxT("wxRA_HORIZONTAL"), wxRA_HORIZONTAL
},
2127 { wxT("wxRA_VERTICAL"), wxRA_VERTICAL
},
2130 { wxT("wxSL_HORIZONTAL"), wxSL_HORIZONTAL
},
2131 { wxT("wxSL_VERTICAL"), wxSL_VERTICAL
},
2132 { wxT("wxSL_AUTOTICKS"), wxSL_AUTOTICKS
},
2133 { wxT("wxSL_LABELS"), wxSL_LABELS
},
2134 { wxT("wxSL_LEFT"), wxSL_LEFT
},
2135 { wxT("wxSL_TOP"), wxSL_TOP
},
2136 { wxT("wxSL_RIGHT"), wxSL_RIGHT
},
2137 { wxT("wxSL_BOTTOM"), wxSL_BOTTOM
},
2138 { wxT("wxSL_BOTH"), wxSL_BOTH
},
2139 { wxT("wxSL_SELRANGE"), wxSL_SELRANGE
},
2142 { wxT("wxSB_HORIZONTAL"), wxSB_HORIZONTAL
},
2143 { wxT("wxSB_VERTICAL"), wxSB_VERTICAL
},
2146 { wxT("wxBU_AUTODRAW"), wxBU_AUTODRAW
},
2147 { wxT("wxBU_NOAUTODRAW"), wxBU_NOAUTODRAW
},
2150 { wxT("wxTR_HAS_BUTTONS"), wxTR_HAS_BUTTONS
},
2151 { wxT("wxTR_EDIT_LABELS"), wxTR_EDIT_LABELS
},
2152 { wxT("wxTR_LINES_AT_ROOT"), wxTR_LINES_AT_ROOT
},
2155 { wxT("wxLC_ICON"), wxLC_ICON
},
2156 { wxT("wxLC_SMALL_ICON"), wxLC_SMALL_ICON
},
2157 { wxT("wxLC_LIST"), wxLC_LIST
},
2158 { wxT("wxLC_REPORT"), wxLC_REPORT
},
2159 { wxT("wxLC_ALIGN_TOP"), wxLC_ALIGN_TOP
},
2160 { wxT("wxLC_ALIGN_LEFT"), wxLC_ALIGN_LEFT
},
2161 { wxT("wxLC_AUTOARRANGE"), wxLC_AUTOARRANGE
},
2162 { wxT("wxLC_USER_TEXT"), wxLC_USER_TEXT
},
2163 { wxT("wxLC_EDIT_LABELS"), wxLC_EDIT_LABELS
},
2164 { wxT("wxLC_NO_HEADER"), wxLC_NO_HEADER
},
2165 { wxT("wxLC_NO_SORT_HEADER"), wxLC_NO_SORT_HEADER
},
2166 { wxT("wxLC_SINGLE_SEL"), wxLC_SINGLE_SEL
},
2167 { wxT("wxLC_SORT_ASCENDING"), wxLC_SORT_ASCENDING
},
2168 { wxT("wxLC_SORT_DESCENDING"), wxLC_SORT_DESCENDING
},
2171 { wxT("wxSP_VERTICAL"), wxSP_VERTICAL
},
2172 { wxT("wxSP_HORIZONTAL"), wxSP_HORIZONTAL
},
2173 { wxT("wxSP_ARROW_KEYS"), wxSP_ARROW_KEYS
},
2174 { wxT("wxSP_WRAP"), wxSP_WRAP
},
2177 { wxT("wxSP_NOBORDER"), wxSP_NOBORDER
},
2178 { wxT("wxSP_3D"), wxSP_3D
},
2179 { wxT("wxSP_BORDER"), wxSP_BORDER
},
2182 { wxT("wxTC_MULTILINE"), wxTC_MULTILINE
},
2183 { wxT("wxTC_RIGHTJUSTIFY"), wxTC_RIGHTJUSTIFY
},
2184 { wxT("wxTC_FIXEDWIDTH"), wxTC_FIXEDWIDTH
},
2185 { wxT("wxTC_OWNERDRAW"), wxTC_OWNERDRAW
},
2188 { wxT("wxST_SIZEGRIP"), wxST_SIZEGRIP
},
2191 { wxT("wxFIXED_LENGTH"), wxFIXED_LENGTH
},
2192 { wxT("wxALIGN_LEFT"), wxALIGN_LEFT
},
2193 { wxT("wxALIGN_CENTER"), wxALIGN_CENTER
},
2194 { wxT("wxALIGN_CENTRE"), wxALIGN_CENTRE
},
2195 { wxT("wxALIGN_RIGHT"), wxALIGN_RIGHT
},
2196 { wxT("wxCOLOURED"), wxCOLOURED
},
2199 { wxT("wxTB_3DBUTTONS"), wxTB_3DBUTTONS
},
2200 { wxT("wxTB_HORIZONTAL"), wxTB_HORIZONTAL
},
2201 { wxT("wxTB_VERTICAL"), wxTB_VERTICAL
},
2202 { wxT("wxTB_FLAT"), wxTB_FLAT
},
2205 { wxT("wxDIALOG_MODAL"), wxDIALOG_MODAL
},
2208 { wxT("wxVSCROLL"), wxVSCROLL
},
2209 { wxT("wxHSCROLL"), wxHSCROLL
},
2210 { wxT("wxCAPTION"), wxCAPTION
},
2211 { wxT("wxSTAY_ON_TOP"), wxSTAY_ON_TOP
},
2212 { wxT("wxICONIZE"), wxICONIZE
},
2213 { wxT("wxMINIMIZE"), wxICONIZE
},
2214 { wxT("wxMAXIMIZE"), wxMAXIMIZE
},
2216 { wxT("wxMDI_PARENT"), 0},
2217 { wxT("wxMDI_CHILD"), 0},
2218 { wxT("wxTHICK_FRAME"), wxTHICK_FRAME
},
2219 { wxT("wxRESIZE_BORDER"), wxRESIZE_BORDER
},
2220 { wxT("wxSYSTEM_MENU"), wxSYSTEM_MENU
},
2221 { wxT("wxMINIMIZE_BOX"), wxMINIMIZE_BOX
},
2222 { wxT("wxMAXIMIZE_BOX"), wxMAXIMIZE_BOX
},
2223 { wxT("wxRESIZE_BOX"), wxRESIZE_BOX
},
2224 { wxT("wxDEFAULT_FRAME_STYLE"), wxDEFAULT_FRAME_STYLE
},
2225 { wxT("wxDEFAULT_FRAME"), wxDEFAULT_FRAME_STYLE
},
2226 { wxT("wxDEFAULT_DIALOG_STYLE"), wxDEFAULT_DIALOG_STYLE
},
2227 { wxT("wxBORDER"), wxBORDER
},
2228 { wxT("wxRETAINED"), wxRETAINED
},
2229 { wxT("wxNATIVE_IMPL"), 0},
2230 { wxT("wxEXTENDED_IMPL"), 0},
2231 { wxT("wxBACKINGSTORE"), wxBACKINGSTORE
},
2232 // { wxT("wxFLAT"), wxFLAT},
2233 // { wxT("wxMOTIF_RESIZE"), wxMOTIF_RESIZE},
2234 { wxT("wxFIXED_LENGTH"), 0},
2235 { wxT("wxDOUBLE_BORDER"), wxDOUBLE_BORDER
},
2236 { wxT("wxSUNKEN_BORDER"), wxSUNKEN_BORDER
},
2237 { wxT("wxRAISED_BORDER"), wxRAISED_BORDER
},
2238 { wxT("wxSIMPLE_BORDER"), wxSIMPLE_BORDER
},
2239 { wxT("wxSTATIC_BORDER"), wxSTATIC_BORDER
},
2240 { wxT("wxTRANSPARENT_WINDOW"), wxTRANSPARENT_WINDOW
},
2241 { wxT("wxNO_BORDER"), wxNO_BORDER
},
2242 { wxT("wxCLIP_CHILDREN"), wxCLIP_CHILDREN
},
2243 { wxT("wxCLIP_SIBLINGS"), wxCLIP_SIBLINGS
},
2244 { wxT("wxTAB_TRAVERSAL"), 0}, // Compatibility only
2246 { wxT("wxTINY_CAPTION_HORIZ"), wxTINY_CAPTION_HORIZ
},
2247 { wxT("wxTINY_CAPTION_VERT"), wxTINY_CAPTION_VERT
},
2249 // Text font families
2250 { wxT("wxDEFAULT"), wxDEFAULT
},
2251 { wxT("wxDECORATIVE"), wxDECORATIVE
},
2252 { wxT("wxROMAN"), wxROMAN
},
2253 { wxT("wxSCRIPT"), wxSCRIPT
},
2254 { wxT("wxSWISS"), wxSWISS
},
2255 { wxT("wxMODERN"), wxMODERN
},
2256 { wxT("wxTELETYPE"), wxTELETYPE
},
2257 { wxT("wxVARIABLE"), wxVARIABLE
},
2258 { wxT("wxFIXED"), wxFIXED
},
2259 { wxT("wxNORMAL"), wxNORMAL
},
2260 { wxT("wxLIGHT"), wxLIGHT
},
2261 { wxT("wxBOLD"), wxBOLD
},
2262 { wxT("wxITALIC"), wxITALIC
},
2263 { wxT("wxSLANT"), wxSLANT
},
2264 { wxT("wxSOLID"), wxSOLID
},
2265 { wxT("wxDOT"), wxDOT
},
2266 { wxT("wxLONG_DASH"), wxLONG_DASH
},
2267 { wxT("wxSHORT_DASH"), wxSHORT_DASH
},
2268 { wxT("wxDOT_DASH"), wxDOT_DASH
},
2269 { wxT("wxUSER_DASH"), wxUSER_DASH
},
2270 { wxT("wxTRANSPARENT"), wxTRANSPARENT
},
2271 { wxT("wxSTIPPLE"), wxSTIPPLE
},
2272 { wxT("wxBDIAGONAL_HATCH"), wxBDIAGONAL_HATCH
},
2273 { wxT("wxCROSSDIAG_HATCH"), wxCROSSDIAG_HATCH
},
2274 { wxT("wxFDIAGONAL_HATCH"), wxFDIAGONAL_HATCH
},
2275 { wxT("wxCROSS_HATCH"), wxCROSS_HATCH
},
2276 { wxT("wxHORIZONTAL_HATCH"), wxHORIZONTAL_HATCH
},
2277 { wxT("wxVERTICAL_HATCH"), wxVERTICAL_HATCH
},
2278 { wxT("wxJOIN_BEVEL"), wxJOIN_BEVEL
},
2279 { wxT("wxJOIN_MITER"), wxJOIN_MITER
},
2280 { wxT("wxJOIN_ROUND"), wxJOIN_ROUND
},
2281 { wxT("wxCAP_ROUND"), wxCAP_ROUND
},
2282 { wxT("wxCAP_PROJECTING"), wxCAP_PROJECTING
},
2283 { wxT("wxCAP_BUTT"), wxCAP_BUTT
},
2286 { wxT("wxCLEAR"), wxCLEAR
},
2287 { wxT("wxXOR"), wxXOR
},
2288 { wxT("wxINVERT"), wxINVERT
},
2289 { wxT("wxOR_REVERSE"), wxOR_REVERSE
},
2290 { wxT("wxAND_REVERSE"), wxAND_REVERSE
},
2291 { wxT("wxCOPY"), wxCOPY
},
2292 { wxT("wxAND"), wxAND
},
2293 { wxT("wxAND_INVERT"), wxAND_INVERT
},
2294 { wxT("wxNO_OP"), wxNO_OP
},
2295 { wxT("wxNOR"), wxNOR
},
2296 { wxT("wxEQUIV"), wxEQUIV
},
2297 { wxT("wxSRC_INVERT"), wxSRC_INVERT
},
2298 { wxT("wxOR_INVERT"), wxOR_INVERT
},
2299 { wxT("wxNAND"), wxNAND
},
2300 { wxT("wxOR"), wxOR
},
2301 { wxT("wxSET"), wxSET
},
2303 { wxT("wxFLOOD_SURFACE"), wxFLOOD_SURFACE
},
2304 { wxT("wxFLOOD_BORDER"), wxFLOOD_BORDER
},
2305 { wxT("wxODDEVEN_RULE"), wxODDEVEN_RULE
},
2306 { wxT("wxWINDING_RULE"), wxWINDING_RULE
},
2307 { wxT("wxHORIZONTAL"), wxHORIZONTAL
},
2308 { wxT("wxVERTICAL"), wxVERTICAL
},
2309 { wxT("wxBOTH"), wxBOTH
},
2310 { wxT("wxCENTER_FRAME"), wxCENTER_FRAME
},
2311 { wxT("wxOK"), wxOK
},
2312 { wxT("wxYES_NO"), wxYES_NO
},
2313 { wxT("wxCANCEL"), wxCANCEL
},
2314 { wxT("wxYES"), wxYES
},
2315 { wxT("wxNO"), wxNO
},
2316 { wxT("wxICON_EXCLAMATION"), wxICON_EXCLAMATION
},
2317 { wxT("wxICON_HAND"), wxICON_HAND
},
2318 { wxT("wxICON_QUESTION"), wxICON_QUESTION
},
2319 { wxT("wxICON_INFORMATION"), wxICON_INFORMATION
},
2320 { wxT("wxICON_STOP"), wxICON_STOP
},
2321 { wxT("wxICON_ASTERISK"), wxICON_ASTERISK
},
2322 { wxT("wxICON_MASK"), wxICON_MASK
},
2323 { wxT("wxCENTRE"), wxCENTRE
},
2324 { wxT("wxCENTER"), wxCENTRE
},
2325 { wxT("wxUSER_COLOURS"), wxUSER_COLOURS
},
2326 { wxT("wxVERTICAL_LABEL"), 0},
2327 { wxT("wxHORIZONTAL_LABEL"), 0},
2329 // Bitmap types (not strictly styles)
2330 { wxT("wxBITMAP_TYPE_XPM"), wxBITMAP_TYPE_XPM
},
2331 { wxT("wxBITMAP_TYPE_XBM"), wxBITMAP_TYPE_XBM
},
2332 { wxT("wxBITMAP_TYPE_BMP"), wxBITMAP_TYPE_BMP
},
2333 { wxT("wxBITMAP_TYPE_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2334 { wxT("wxBITMAP_TYPE_BMP_RESOURCE"), wxBITMAP_TYPE_BMP_RESOURCE
},
2335 { wxT("wxBITMAP_TYPE_GIF"), wxBITMAP_TYPE_GIF
},
2336 { wxT("wxBITMAP_TYPE_TIF"), wxBITMAP_TYPE_TIF
},
2337 { wxT("wxBITMAP_TYPE_ICO"), wxBITMAP_TYPE_ICO
},
2338 { wxT("wxBITMAP_TYPE_ICO_RESOURCE"), wxBITMAP_TYPE_ICO_RESOURCE
},
2339 { wxT("wxBITMAP_TYPE_CUR"), wxBITMAP_TYPE_CUR
},
2340 { wxT("wxBITMAP_TYPE_CUR_RESOURCE"), wxBITMAP_TYPE_CUR_RESOURCE
},
2341 { wxT("wxBITMAP_TYPE_XBM_DATA"), wxBITMAP_TYPE_XBM_DATA
},
2342 { wxT("wxBITMAP_TYPE_XPM_DATA"), wxBITMAP_TYPE_XPM_DATA
},
2343 { wxT("wxBITMAP_TYPE_ANY"), wxBITMAP_TYPE_ANY
}
2346 static int wxResourceBitListCount
= (sizeof(wxResourceBitListTable
)/sizeof(wxResourceBitListStruct
));
2348 long wxParseWindowStyle(const wxString
& bitListString
)
2353 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2354 while (word
!= NULL
)
2358 for (j
= 0; j
< wxResourceBitListCount
; j
++)
2359 if (wxStrcmp(wxResourceBitListTable
[j
].word
, word
) == 0)
2361 bitList
|= wxResourceBitListTable
[j
].bits
;
2367 wxLogWarning(_("Unrecognized style %s while parsing resource."), word
);
2370 word
= wxResourceParseWord(WXSTRINGCAST bitListString
, &i
);
2376 * Load a bitmap from a wxWidgets resource, choosing an optimum
2377 * depth and appropriate type.
2380 wxBitmap
wxResourceCreateBitmap(const wxString
& resource
, wxResourceTable
*table
)
2383 table
= wxDefaultResourceTable
;
2385 wxItemResource
*item
= table
->FindResource(resource
);
2388 if ((item
->GetType().empty()) || (item
->GetType() != wxT("wxBitmap")))
2390 wxLogWarning(_("%s not a bitmap resource specification."), (const wxChar
*) resource
);
2391 return wxNullBitmap
;
2393 int thisDepth
= wxDisplayDepth();
2394 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2396 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2398 // Try to find optimum bitmap for this platform/colour depth
2399 wxNode
*node
= item
->GetChildren().GetFirst();
2402 wxItemResource
*child
= (wxItemResource
*)node
->GetData();
2403 int platform
= (int)child
->GetValue2();
2404 int noColours
= (int)child
->GetValue3();
2406 char *name = child->GetName();
2407 int bitmapType = (int)child->GetValue1();
2408 int xRes = child->GetWidth();
2409 int yRes = child->GetHeight();
2414 case RESOURCE_PLATFORM_ANY
:
2416 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2417 optResource
= child
;
2420 // Maximise the number of colours.
2421 // If noColours is zero (unspecified), then assume this
2422 // is the right one.
2423 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2424 optResource
= child
;
2429 case RESOURCE_PLATFORM_WINDOWS
:
2431 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2432 optResource
= child
;
2435 // Maximise the number of colours
2436 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2437 optResource
= child
;
2443 case RESOURCE_PLATFORM_X
:
2445 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2446 optResource
= child
;
2449 // Maximise the number of colours
2450 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2451 optResource
= child
;
2457 case RESOURCE_PLATFORM_MAC
:
2459 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2460 optResource
= child
;
2463 // Maximise the number of colours
2464 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2465 optResource
= child
;
2473 node
= node
->GetNext();
2475 // If no matching resource, fail.
2477 return wxNullBitmap
;
2479 wxString name
= optResource
->GetName();
2480 int bitmapType
= (int)optResource
->GetValue1();
2483 case wxBITMAP_TYPE_XBM_DATA
:
2486 wxItemResource
*item
= table
->FindResource(name
);
2489 wxLogWarning(_("Failed to find XBM resource %s.\n"
2490 "Forgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2491 return wxNullBitmap
;
2493 return wxBitmap(item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3()) ;
2495 wxLogWarning(_("No XBM facility available!"));
2499 case wxBITMAP_TYPE_XPM_DATA
:
2501 wxItemResource
*item
= table
->FindResource(name
);
2504 wxLogWarning(_("Failed to find XPM resource %s.\nForgot to use wxResourceLoadBitmapData?"), (const wxChar
*) name
);
2505 return wxNullBitmap
;
2507 return wxBitmap((char **)item
->GetValue1());
2511 #if defined(__WXPM__)
2512 return wxNullBitmap
;
2514 return wxBitmap(name
, (wxBitmapType
)bitmapType
);
2519 return wxNullBitmap
;
2524 wxLogWarning(_("Bitmap resource specification %s not found."), (const wxChar
*) resource
);
2525 return wxNullBitmap
;
2530 * Load an icon from a wxWidgets resource, choosing an optimum
2531 * depth and appropriate type.
2534 wxIcon
wxResourceCreateIcon(const wxString
& resource
, wxResourceTable
*table
)
2537 table
= wxDefaultResourceTable
;
2539 wxItemResource
*item
= table
->FindResource(resource
);
2542 if ((item
->GetType().empty()) || wxStrcmp(item
->GetType(), wxT("wxIcon")) != 0)
2544 wxLogWarning(_("%s not an icon resource specification."), (const wxChar
*) resource
);
2547 int thisDepth
= wxDisplayDepth();
2548 long thisNoColours
= (long)pow(2.0, (double)thisDepth
);
2550 wxItemResource
*optResource
= (wxItemResource
*) NULL
;
2552 // Try to find optimum icon for this platform/colour depth
2553 wxNode
*node
= item
->GetChildren().GetFirst();
2556 wxItemResource
*child
= (wxItemResource
*)node
->GetData();
2557 int platform
= (int)child
->GetValue2();
2558 int noColours
= (int)child
->GetValue3();
2560 char *name = child->GetName();
2561 int bitmapType = (int)child->GetValue1();
2562 int xRes = child->GetWidth();
2563 int yRes = child->GetHeight();
2568 case RESOURCE_PLATFORM_ANY
:
2570 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2571 optResource
= child
;
2574 // Maximise the number of colours.
2575 // If noColours is zero (unspecified), then assume this
2576 // is the right one.
2577 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2578 optResource
= child
;
2583 case RESOURCE_PLATFORM_WINDOWS
:
2585 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2586 optResource
= child
;
2589 // Maximise the number of colours
2590 if ((noColours
> 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2591 optResource
= child
;
2597 case RESOURCE_PLATFORM_X
:
2599 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2600 optResource
= child
;
2603 // Maximise the number of colours
2604 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2605 optResource
= child
;
2611 case RESOURCE_PLATFORM_MAC
:
2613 if (!optResource
&& ((noColours
== 0) || (noColours
<= thisNoColours
)))
2614 optResource
= child
;
2617 // Maximise the number of colours
2618 if ((noColours
== 0) || ((noColours
<= thisNoColours
) && (noColours
> optResource
->GetValue3())))
2619 optResource
= child
;
2627 node
= node
->GetNext();
2629 // If no matching resource, fail.
2633 wxString name
= optResource
->GetName();
2634 int bitmapType
= (int)optResource
->GetValue1();
2637 case wxBITMAP_TYPE_XBM_DATA
:
2640 wxItemResource
*item
= table
->FindResource(name
);
2643 wxLogWarning(_("Failed to find XBM resource %s.\n"
2644 "Forgot to use wxResourceLoadIconData?"), (const wxChar
*) name
);
2647 return wxIcon((const char **)item
->GetValue1(), (int)item
->GetValue2(), (int)item
->GetValue3());
2649 wxLogWarning(_("No XBM facility available!"));
2653 case wxBITMAP_TYPE_XPM_DATA
:
2655 // *** XPM ICON NOT YET IMPLEMENTED IN wxWidgets ***
2657 wxItemResource *item = table->FindResource(name);
2661 sprintf(buf, _("Failed to find XPM resource %s.\nForgot to use wxResourceLoadIconData?"), name);
2665 return wxIcon((char **)item->GetValue1());
2667 wxLogWarning(_("No XPM icon facility available!"));
2672 #if defined( __WXGTK__ ) || defined( __WXMOTIF__ )
2673 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2676 return wxIcon(name
, (wxBitmapType
) bitmapType
);
2684 wxLogWarning(_("Icon resource specification %s not found."), (const wxChar
*) resource
);
2691 wxMenu
*wxResourceCreateMenu(wxItemResource
*item
)
2693 wxMenu
*menu
= new wxMenu
;
2694 wxNode
*node
= item
->GetChildren().GetFirst();
2697 wxItemResource
*child
= (wxItemResource
*)node
->GetData();
2698 if ((!child
->GetType().empty()) && (child
->GetType() == wxT("wxMenuSeparator")))
2699 menu
->AppendSeparator();
2700 else if (child
->GetChildren().GetCount() > 0)
2702 wxMenu
*subMenu
= wxResourceCreateMenu(child
);
2704 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), subMenu
, child
->GetValue4());
2708 menu
->Append((int)child
->GetValue1(), child
->GetTitle(), child
->GetValue4(), (child
->GetValue2() != 0));
2710 node
= node
->GetNext();
2715 wxMenuBar
*wxResourceCreateMenuBar(const wxString
& resource
, wxResourceTable
*table
, wxMenuBar
*menuBar
)
2718 table
= wxDefaultResourceTable
;
2720 wxItemResource
*menuResource
= table
->FindResource(resource
);
2721 if (menuResource
&& (!menuResource
->GetType().empty()) && (menuResource
->GetType() == wxT("wxMenu")))
2724 menuBar
= new wxMenuBar
;
2725 wxNode
*node
= menuResource
->GetChildren().GetFirst();
2728 wxItemResource
*child
= (wxItemResource
*)node
->GetData();
2729 wxMenu
*menu
= wxResourceCreateMenu(child
);
2731 menuBar
->Append(menu
, child
->GetTitle());
2732 node
= node
->GetNext();
2736 return (wxMenuBar
*) NULL
;
2739 wxMenu
*wxResourceCreateMenu(const wxString
& resource
, wxResourceTable
*table
)
2742 table
= wxDefaultResourceTable
;
2744 wxItemResource
*menuResource
= table
->FindResource(resource
);
2745 if (menuResource
&& (!menuResource
->GetType().empty()) && (menuResource
->GetType() == wxT("wxMenu")))
2746 // if (menuResource && (menuResource->GetType() == wxTYPE_MENU))
2747 return wxResourceCreateMenu(menuResource
);
2748 return (wxMenu
*) NULL
;
2751 #endif // wxUSE_MENUS
2753 // Global equivalents (so don't have to refer to default table explicitly)
2754 bool wxResourceParseData(const wxString
& resource
, wxResourceTable
*table
)
2757 table
= wxDefaultResourceTable
;
2759 return table
->ParseResourceData(resource
);
2762 bool wxResourceParseData(const char* resource
, wxResourceTable
*table
)
2764 wxString
str(resource
, wxConvLibc
);
2766 table
= wxDefaultResourceTable
;
2768 return table
->ParseResourceData(str
);
2771 bool wxResourceParseFile(const wxString
& filename
, wxResourceTable
*table
)
2774 table
= wxDefaultResourceTable
;
2776 return table
->ParseResourceFile(filename
);
2779 // Register XBM/XPM data
2780 bool wxResourceRegisterBitmapData(const wxString
& name
, char bits
[], int width
, int height
, wxResourceTable
*table
)
2783 table
= wxDefaultResourceTable
;
2785 return table
->RegisterResourceBitmapData(name
, bits
, width
, height
);
2788 bool wxResourceRegisterBitmapData(const wxString
& name
, char **data
, wxResourceTable
*table
)
2791 table
= wxDefaultResourceTable
;
2793 return table
->RegisterResourceBitmapData(name
, data
);
2796 void wxResourceClear(wxResourceTable
*table
)
2799 table
= wxDefaultResourceTable
;
2801 table
->ClearTable();
2808 bool wxResourceAddIdentifier(const wxString
& name
, int value
, wxResourceTable
*table
)
2811 table
= wxDefaultResourceTable
;
2813 table
->identifiers
.Put(name
, (wxObject
*)(long)value
);
2817 int wxResourceGetIdentifier(const wxString
& name
, wxResourceTable
*table
)
2820 table
= wxDefaultResourceTable
;
2822 return (int)(long)table
->identifiers
.Get(name
);
2826 * Parse #include file for #defines (only)
2829 bool wxResourceParseIncludeFile(const wxString
& f
, wxResourceTable
*table
)
2832 table
= wxDefaultResourceTable
;
2834 FILE *fd
= wxFopen(f
, wxT("r"));
2839 while (wxGetResourceToken(fd
))
2841 if (strcmp(wxResourceBuffer
, "#define") == 0)
2843 wxGetResourceToken(fd
);
2844 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2845 wxGetResourceToken(fd
);
2846 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
2847 if (wxIsdigit(value
[0]))
2849 int val
= (int)wxAtol(value
);
2850 wxResourceAddIdentifier(name
, val
, table
);
2861 * Reading strings as if they were .wxr files
2864 static int getc_string(char *s
)
2866 int ch
= s
[wxResourceStringPtr
];
2871 wxResourceStringPtr
++;
2876 static int ungetc_string()
2878 wxResourceStringPtr
--;
2882 bool wxEatWhiteSpaceString(char *s
)
2886 while ((ch
= getc_string(s
)) != EOF
)
2897 ch
= getc_string(s
);
2908 while ((ch
= getc_string(s
)) != EOF
)
2910 if (ch
== '/' && prev_ch
== '*')
2932 bool wxGetResourceTokenString(char *s
)
2934 if (!wxResourceBuffer
)
2935 wxReallocateResourceBuffer();
2936 wxResourceBuffer
[0] = 0;
2937 wxEatWhiteSpaceString(s
);
2939 int ch
= getc_string(s
);
2943 wxResourceBufferCount
= 0;
2944 ch
= getc_string(s
);
2950 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2953 // Escaped characters
2954 else if (ch
== '\\')
2956 int newCh
= getc_string(s
);
2959 else if (newCh
== 10)
2967 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2968 wxReallocateResourceBuffer();
2969 wxResourceBuffer
[wxResourceBufferCount
] = (char)actualCh
;
2970 wxResourceBufferCount
++;
2971 ch
= getc_string(s
);
2973 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2977 wxResourceBufferCount
= 0;
2979 while (ch
!= ' ' && ch
!= EOF
&& ch
!= ' ' && ch
!= 13 && ch
!= 9 && ch
!= 10)
2981 if (wxResourceBufferCount
>= wxResourceBufferSize
-1)
2982 wxReallocateResourceBuffer();
2983 wxResourceBuffer
[wxResourceBufferCount
] = (char)ch
;
2984 wxResourceBufferCount
++;
2986 ch
= getc_string(s
);
2988 wxResourceBuffer
[wxResourceBufferCount
] = 0;
2996 * Files are in form:
2997 static char *name = "....";
2998 with possible comments.
3001 bool wxResourceReadOneResourceString(char *s
, wxExprDatabase
& db
, bool *eof
, wxResourceTable
*table
)
3004 table
= wxDefaultResourceTable
;
3006 // static or #define
3007 if (!wxGetResourceTokenString(s
))
3013 if (strcmp(wxResourceBuffer
, "#define") == 0)
3015 wxGetResourceTokenString(s
);
3016 wxChar
*name
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
3017 wxGetResourceTokenString(s
);
3018 wxChar
*value
= copystring(wxConvCurrent
->cMB2WX(wxResourceBuffer
));
3019 if (wxIsdigit(value
[0]))
3021 int val
= (int)wxAtol(value
);
3022 wxResourceAddIdentifier(name
, val
, table
);
3026 wxLogWarning(_("#define %s must be an integer."), name
);
3037 else if (strcmp(wxResourceBuffer, "#include") == 0)
3039 wxGetResourceTokenString(s);
3040 char *name = copystring(wxResourceBuffer);
3041 char *actualName = name;
3043 actualName = name + 1;
3044 int len = strlen(name);
3045 if ((len > 0) && (name[len-1] == '"'))
3047 if (!wxResourceParseIncludeFile(actualName, table))
3050 sprintf(buf, _("Could not find resource include file %s."), actualName);
3057 else if (strcmp(wxResourceBuffer
, "static") != 0)
3060 wxStrcpy(buf
, _("Found "));
3061 wxStrncat(buf
, wxConvCurrent
->cMB2WX(wxResourceBuffer
), 30);
3062 wxStrcat(buf
, _(", expected static, #include or #define\nwhile parsing resource."));
3068 if (!wxGetResourceTokenString(s
))
3070 wxLogWarning(_("Unexpected end of file while parsing resource."));
3075 if (strcmp(wxResourceBuffer
, "char") != 0)
3077 wxLogWarning(_("Expected 'char' while parsing resource."));
3082 if (!wxGetResourceTokenString(s
))
3084 wxLogWarning(_("Unexpected end of file while parsing resource."));
3089 if (wxResourceBuffer
[0] != '*')
3091 wxLogWarning(_("Expected '*' while parsing resource."));
3094 wxChar nameBuf
[100];
3095 wxMB2WX(nameBuf
, wxResourceBuffer
+1, 99);
3099 if (!wxGetResourceTokenString(s
))
3101 wxLogWarning(_("Unexpected end of file while parsing resource."));
3106 if (strcmp(wxResourceBuffer
, "=") != 0)
3108 wxLogWarning(_("Expected '=' while parsing resource."));
3113 if (!wxGetResourceTokenString(s
))
3115 wxLogWarning(_("Unexpected end of file while parsing resource."));
3121 if (!db
.ReadPrologFromString(wxResourceBuffer
))
3123 wxLogWarning(_("%s: ill-formed resource file syntax."), nameBuf
);
3128 if (!wxGetResourceTokenString(s
))
3135 bool wxResourceParseString(const wxString
& s
, wxResourceTable
*WXUNUSED(table
))
3138 return wxResourceParseString( (char*)s
.mb_str().data() );
3140 return wxResourceParseString( (char*)s
.c_str() );
3144 bool wxResourceParseString(char *s
, wxResourceTable
*table
)
3147 table
= wxDefaultResourceTable
;
3152 // Turn backslashes into spaces
3155 int len
= strlen(s
);
3157 for (i
= 0; i
< len
; i
++)
3158 if (s
[i
] == 92 && s
[i
+1] == 13)
3166 wxResourceStringPtr
= 0;
3169 while (wxResourceReadOneResourceString(s
, db
, &eof
, table
) && !eof
)
3173 return wxResourceInterpretResources(*table
, db
);
3177 * resource loading facility
3180 bool wxLoadFromResource(wxWindow
* thisWindow
, wxWindow
*parent
, const wxString
& resourceName
, const wxResourceTable
*table
)
3183 table
= wxDefaultResourceTable
;
3185 wxItemResource
*resource
= table
->FindResource((const wxChar
*)resourceName
);
3186 // if (!resource || (resource->GetType() != wxTYPE_DIALOG_BOX))
3187 if (!resource
|| (resource
->GetType().empty()) ||
3188 ! ((resource
->GetType() == wxT("wxDialog")) || (resource
->GetType() == wxT("wxPanel"))))
3191 wxString
title(resource
->GetTitle());
3192 long theWindowStyle
= resource
->GetStyle();
3193 bool isModal
= (resource
->GetValue1() != 0) ;
3194 int x
= resource
->GetX();
3195 int y
= resource
->GetY();
3196 int width
= resource
->GetWidth();
3197 int height
= resource
->GetHeight();
3198 wxString name
= resource
->GetName();
3200 // this is used for loading wxWizard pages from WXR
3201 if ( parent
!= thisWindow
)
3203 if (thisWindow
->IsKindOf(CLASSINFO(wxDialog
)))
3205 wxDialog
*dialogBox
= (wxDialog
*)thisWindow
;
3206 long modalStyle
= isModal
? wxDIALOG_MODAL
: 0;
3207 if (!dialogBox
->Create(parent
, wxID_ANY
, title
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
|modalStyle
, name
))
3210 // Only reset the client size if we know we're not going to do it again below.
3211 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == 0)
3212 dialogBox
->SetClientSize(width
, height
);
3214 else if (thisWindow
->IsKindOf(CLASSINFO(wxPanel
)))
3216 wxPanel
* panel
= (wxPanel
*)thisWindow
;
3217 if (!panel
->Create(parent
, wxID_ANY
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
| wxTAB_TRAVERSAL
, name
))
3222 if (!((wxWindow
*)thisWindow
)->Create(parent
, wxID_ANY
, wxPoint(x
, y
), wxSize(width
, height
), theWindowStyle
, name
))
3227 if ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) != 0)
3229 // No need to do this since it's done in wxPanel or wxDialog constructor.
3230 // SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
3234 if (resource
->GetFont().Ok())
3235 thisWindow
->SetFont(resource
->GetFont());
3236 if (resource
->GetBackgroundColour().Ok())
3237 thisWindow
->SetBackgroundColour(resource
->GetBackgroundColour());
3240 // Should have some kind of font at this point
3241 if (!thisWindow
->GetFont().Ok())
3242 thisWindow
->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
));
3243 if (!thisWindow
->GetBackgroundColour().Ok())
3244 thisWindow
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE
));
3246 // Only when we've created the window and set the font can we set the correct size,
3247 // if based on dialog units.
3248 if ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) != 0)
3250 wxSize sz
= thisWindow
->ConvertDialogToPixels(wxSize(width
, height
));
3251 thisWindow
->SetClientSize(sz
.x
, sz
.y
);
3253 wxPoint pt
= thisWindow
->ConvertDialogToPixels(wxPoint(x
, y
));
3254 thisWindow
->Move(pt
.x
, pt
.y
);
3257 // Now create children
3258 wxNode
*node
= resource
->GetChildren().GetFirst();
3261 wxItemResource
*childResource
= (wxItemResource
*)node
->GetData();
3263 (void) wxCreateItem(thisWindow
, childResource
, resource
, table
);
3265 node
= node
->GetNext();
3270 wxControl
*wxCreateItem(wxWindow
* thisWindow
, const wxItemResource
*resource
, const wxItemResource
* parentResource
, const wxResourceTable
*table
)
3273 table
= wxDefaultResourceTable
;
3274 return table
->CreateItem(thisWindow
, resource
, parentResource
);
3278 #pragma warning(default:4706) // assignment within conditional expression
3281 #endif // wxUSE_WX_RESOURCES