#include "wx/log.h"
#include "wx/statbox.h"
#include "wx/notebook.h"
+#include "wx/tokenzr.h"
+
+bool wxSizerXmlHandler::IsSizerNode(wxXmlNode *node)
+{
+ return (IsOfClass(node, _T("wxBoxSizer"))) ||
+ (IsOfClass(node, _T("wxStaticBoxSizer"))) ||
+ (IsOfClass(node, _T("wxGridSizer"))) ||
+ (IsOfClass(node, _T("wxFlexGridSizer")));
+}
+
+
wxSizerXmlHandler::wxSizerXmlHandler()
: wxXmlResourceHandler(), m_IsInside(FALSE), m_ParentSizer(NULL)
wxObject *wxSizerXmlHandler::DoCreateResource()
{
- if (m_Node->GetName() == _T("sizeritem"))
+ if (m_Class == _T("sizeritem"))
{
- wxXmlNode *n = GetParamNode(_T("window"))->GetChildren();
+ wxXmlNode *n = GetParamNode(_T("object"));
- while (n)
+ if (n)
{
- if (n->GetType() == wxXML_ELEMENT_NODE)
- {
- bool old_ins = m_IsInside;
- m_IsInside = FALSE;
- wxObject *item = CreateResFromNode(n, m_Parent, NULL);
- m_IsInside = old_ins;
- wxSizer *sizer = wxDynamicCast(item, wxSizer);
- wxWindow *wnd = wxDynamicCast(item, wxWindow);
-
- if (sizer)
- m_ParentSizer->Add(sizer, GetLong(_T("option")),
- GetStyle(_T("flag")), GetLong(_T("border")));
- else if (wnd)
- m_ParentSizer->Add(wnd, GetLong(_T("option")),
- GetStyle(_T("flag")), GetLong(_T("border")));
- else
- wxLogError(_T("Error in resource."));
-
- return item;
+ bool old_ins = m_IsInside;
+ wxSizer *old_par = m_ParentSizer;
+ m_IsInside = FALSE;
+ if (!IsSizerNode(n)) m_ParentSizer = NULL;
+ wxObject *item = CreateResFromNode(n, m_Parent, NULL);
+ m_IsInside = old_ins;
+ m_ParentSizer = old_par;
+ wxSizer *sizer = wxDynamicCast(item, wxSizer);
+ wxWindow *wnd = wxDynamicCast(item, wxWindow);
+ wxSize minsize = GetSize(_T("minsize"));
+
+ if (sizer)
+ {
+ m_ParentSizer->Add(sizer, GetLong(_T("option")),
+ GetStyle(_T("flag")), GetDimension(_T("border")));
+ if (!(minsize == wxDefaultSize))
+ m_ParentSizer->SetItemMinSize(sizer, minsize.x, minsize.y);
+ }
+ else if (wnd)
+ {
+ m_ParentSizer->Add(wnd, GetLong(_T("option")),
+ GetStyle(_T("flag")), GetDimension(_T("border")));
+ if (!(minsize == wxDefaultSize))
+ m_ParentSizer->SetItemMinSize(wnd, minsize.x, minsize.y);
}
- n = n->GetNext();
+ else
+ wxLogError(_T("Error in resource."));
+
+ return item;
+ }
+ else /*n == NULL*/
+ {
+ wxLogError(_T("Error in resource: no control/sizer within sizer's <item> tag."));
+ return NULL;
}
- wxLogError(_T("Error in resource: no control/sizer within sizer's <item> tag."));
- return NULL;
}
- else if (m_Node->GetName() == _T("spacer"))
+ else if (m_Class == _T("spacer"))
{
wxCHECK_MSG(m_ParentSizer, NULL, _T("Incorrect syntax of XML resource: spacer not within sizer!"));
wxSize sz = GetSize();
m_ParentSizer->Add(sz.x, sz.y,
- GetLong(_T("option")), GetStyle(_T("flag")), GetLong(_T("border")));
+ GetLong(_T("option")), GetStyle(_T("flag")), GetDimension(_T("border")));
return NULL;
}
-#if wxUSE_NOTEBOOK
- else if (m_Node->GetName() == _T("notebooksizer"))
- {
- wxCHECK_MSG(m_ParentSizer, NULL, _T("Incorrect syntax of XML resource: notebooksizer not within sizer!"));
- wxSizer *old_par = m_ParentSizer;
- m_ParentSizer = NULL;
-
- wxNotebook *nb = NULL;
- wxObject *item;
- wxXmlNode *n = GetParamNode(_T("window"))->GetChildren();
- while (n)
- {
- if (n->GetType() == wxXML_ELEMENT_NODE)
- {
- item = CreateResFromNode(n, m_Parent, NULL);
- nb = wxDynamicCast(item, wxNotebook);
- break;
- }
- n = n->GetNext();
- }
-
- m_ParentSizer = old_par;
-
- wxCHECK_MSG(nb, NULL, _T("Incorrect syntax of XML resource: notebooksizer must contain a notebook!"));
- return new wxNotebookSizer(nb);
- }
-#endif
-
else {
wxSizer *sizer = NULL;
- wxXmlNode *parentNode = m_Node->GetParent()->GetParent();
+ wxXmlNode *parentNode = m_Node->GetParent();
wxCHECK_MSG(m_ParentSizer != NULL ||
- ((parentNode->GetName() == _T("panel") ||
- parentNode->GetName() == _T("dialog")) &&
+ ((IsOfClass(parentNode, _T("wxPanel")) ||
+ IsOfClass(parentNode, _T("wxDialog"))) &&
parentNode->GetType() == wxXML_ELEMENT_NODE), NULL,
- _T("Incorrect use of sizer: parent is not 'dialog' or 'panel'."));
+ _T("Incorrect use of sizer: parent is not 'wxDialog' or 'wxPanel'."));
- if (m_Node->GetName() == _T("boxsizer"))
+ if (m_Class == _T("wxBoxSizer"))
sizer = new wxBoxSizer(GetStyle(_T("orient"), wxHORIZONTAL));
- else if (m_Node->GetName() == _T("staticboxsizer"))
+ else if (m_Class == _T("wxStaticBoxSizer"))
{
sizer = new wxStaticBoxSizer(
new wxStaticBox(m_ParentAsWindow, -1, GetText(_T("label"))),
GetStyle(_T("orient"), wxHORIZONTAL));
}
+
+ else if (m_Class == _T("wxGridSizer"))
+ sizer = new wxGridSizer(GetLong(_T("rows")), GetLong(_T("cols")),
+ GetDimension(_T("vgap")), GetDimension(_T("hgap")));
+
+ else if (m_Class == _T("wxFlexGridSizer"))
+ {
+ wxFlexGridSizer *fsizer =
+ new wxFlexGridSizer(GetLong(_T("rows")), GetLong(_T("cols")),
+ GetDimension(_T("vgap")), GetDimension(_T("hgap")));
+ sizer = fsizer;
+ wxStringTokenizer tkn;
+ unsigned long l;
+ tkn.SetString(GetParamValue(_T("growablerows")), _T(","));
+ while (tkn.HasMoreTokens())
+ {
+ if (!tkn.GetNextToken().ToULong(&l))
+ wxLogError(_T("growablerows must be comma-separated list of row numbers"));
+ else
+ fsizer->AddGrowableRow(l);
+ }
+ tkn.SetString(GetParamValue(_T("growablecols")), _T(","));
+ while (tkn.HasMoreTokens())
+ {
+ if (!tkn.GetNextToken().ToULong(&l))
+ wxLogError(_T("growablecols must be comma-separated list of column numbers"));
+ else
+ fsizer->AddGrowableCol(l);
+ }
+ }
+
+ wxSize minsize = GetSize(_T("minsize"));
+ if (!(minsize == wxDefaultSize))
+ sizer->SetMinSize(minsize);
wxSizer *old_par = m_ParentSizer;
m_ParentSizer = sizer;
bool wxSizerXmlHandler::CanHandle(wxXmlNode *node)
{
- return ((!m_IsInside && node->GetName() == _T("boxsizer")) ||
- (!m_IsInside && node->GetName() == _T("staticboxsizer")) ||
-#if wxUSE_NOTEBOOK
- (!m_IsInside && node->GetName() == _T("notebooksizer")) ||
-#endif
- (m_IsInside && node->GetName() == _T("sizeritem")) ||
- (m_IsInside && node->GetName() == _T("spacer")));
+ return ((!m_IsInside && IsSizerNode(node)) ||
+ (m_IsInside && IsOfClass(node, _T("sizeritem"))) ||
+ (m_IsInside && IsOfClass(node, _T("spacer"))));
}