#include "wx/statbox.h"
#include "wx/notebook.h"
+static bool IsSizerNode(wxXmlNode *node)
+{
+ return (node->GetName() == _T("boxsizer")) ||
+ (node->GetName() == _T("staticboxsizer")) ||
+ (node->GetName() == _T("gridsizer")) ||
+ (node->GetName() == _T("flexgridsizer"));
+}
+
+
+
wxSizerXmlHandler::wxSizerXmlHandler()
: wxXmlResourceHandler(), m_IsInside(FALSE), m_ParentSizer(NULL)
{
if (n->GetType() == wxXML_ELEMENT_NODE)
{
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")), GetLong(_T("border")));
+ 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")), GetLong(_T("border")));
+ GetStyle(_T("flag")), GetDimension(_T("border")));
+ if (!(minsize == wxDefaultSize))
+ m_ParentSizer->SetItemMinSize(wnd, minsize.x, minsize.y);
+ }
else
wxLogError(_T("Error in resource."));
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;
new wxStaticBox(m_ParentAsWindow, -1, GetText(_T("label"))),
GetStyle(_T("orient"), wxHORIZONTAL));
}
+
+ else if (m_Node->GetName() == _T("gridsizer"))
+ sizer = new wxGridSizer(GetLong(_T("rows")), GetLong(_T("cols")),
+ GetDimension(_T("vgap")), GetDimension(_T("hgap")));
+
+ else if (m_Node->GetName() == _T("flexgridsizer"))
+ sizer = new wxFlexGridSizer(GetLong(_T("rows")), GetLong(_T("cols")),
+ GetDimension(_T("vgap")), GetDimension(_T("hgap")));
+
+ 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
+ return ((!m_IsInside && IsSizerNode(node)) ||
(m_IsInside && node->GetName() == _T("sizeritem")) ||
(m_IsInside && node->GetName() == _T("spacer")));
}