#include "wx/log.h"
#include "wx/statbox.h"
#include "wx/notebook.h"
+#include "wx/tokenzr.h"
-static bool IsSizerNode(wxXmlNode *node)
+bool wxSizerXmlHandler::IsSizerNode(wxXmlNode *node)
{
- return (node->GetName() == _T("boxsizer")) ||
- (node->GetName() == _T("staticboxsizer")) ||
- (node->GetName() == _T("gridsizer")) ||
- (node->GetName() == _T("flexgridsizer"));
+ return (IsOfClass(node, wxT("wxBoxSizer"))) ||
+ (IsOfClass(node, wxT("wxStaticBoxSizer"))) ||
+ (IsOfClass(node, wxT("wxGridSizer"))) ||
+ (IsOfClass(node, wxT("wxFlexGridSizer")));
}
wxSizerXmlHandler::wxSizerXmlHandler()
-: wxXmlResourceHandler(), m_IsInside(FALSE), m_ParentSizer(NULL)
+: wxXmlResourceHandler(), m_isInside(FALSE), m_parentSizer(NULL)
{
ADD_STYLE(wxHORIZONTAL);
ADD_STYLE(wxVERTICAL);
wxObject *wxSizerXmlHandler::DoCreateResource()
{
- if (m_Node->GetName() == _T("sizeritem"))
+ if (m_class == wxT("sizeritem"))
{
- wxXmlNode *n = GetParamNode(_T("window"))->GetChildren();
+ wxXmlNode *n = GetParamNode(wxT("object"));
- while (n)
+ if (n)
{
- 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);
-
- 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(wxT("minsize"));
+
+ if (sizer)
+ {
+ m_parentSizer->Add(sizer, GetLong(wxT("option")),
+ GetStyle(wxT("flag")), GetDimension(wxT("border")));
+ if (!(minsize == wxDefaultSize))
+ m_parentSizer->SetItemMinSize(sizer, minsize.x, minsize.y);
}
- n = n->GetNext();
+ else if (wnd)
+ {
+ m_parentSizer->Add(wnd, GetLong(wxT("option")),
+ GetStyle(wxT("flag")), GetDimension(wxT("border")));
+ if (!(minsize == wxDefaultSize))
+ m_parentSizer->SetItemMinSize(wnd, minsize.x, minsize.y);
+ }
+ else
+ wxLogError(wxT("Error in resource."));
+
+ return item;
+ }
+ else /*n == NULL*/
+ {
+ wxLogError(wxT("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 == wxT("spacer"))
{
- wxCHECK_MSG(m_ParentSizer, NULL, _T("Incorrect syntax of XML resource: spacer not within sizer!"));
+ wxCHECK_MSG(m_parentSizer, NULL, wxT("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")));
+ m_parentSizer->Add(sz.x, sz.y,
+ GetLong(wxT("option")), GetStyle(wxT("flag")), GetDimension(wxT("border")));
return NULL;
}
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")) &&
+ wxCHECK_MSG(m_parentSizer != NULL ||
+ ((IsOfClass(parentNode, wxT("wxPanel")) ||
+ IsOfClass(parentNode, wxT("wxDialog"))) &&
parentNode->GetType() == wxXML_ELEMENT_NODE), NULL,
- _T("Incorrect use of sizer: parent is not 'dialog' or 'panel'."));
+ wxT("Incorrect use of sizer: parent is not 'wxDialog' or 'wxPanel'."));
- if (m_Node->GetName() == _T("boxsizer"))
- sizer = new wxBoxSizer(GetStyle(_T("orient"), wxHORIZONTAL));
+ if (m_class == wxT("wxBoxSizer"))
+ sizer = new wxBoxSizer(GetStyle(wxT("orient"), wxHORIZONTAL));
- else if (m_Node->GetName() == _T("staticboxsizer"))
+ else if (m_class == wxT("wxStaticBoxSizer"))
{
sizer = new wxStaticBoxSizer(
- new wxStaticBox(m_ParentAsWindow, -1, GetText(_T("label"))),
- GetStyle(_T("orient"), wxHORIZONTAL));
+ new wxStaticBox(m_parentAsWindow, -1, GetText(wxT("label"))),
+ GetStyle(wxT("orient"), wxHORIZONTAL));
}
- else if (m_Node->GetName() == _T("gridsizer"))
- sizer = new wxGridSizer(GetLong(_T("rows")), GetLong(_T("cols")),
- GetLong(_T("vgap")), GetLong(_T("hgap")));
+ else if (m_class == wxT("wxGridSizer"))
+ sizer = new wxGridSizer(GetLong(wxT("rows")), GetLong(wxT("cols")),
+ GetDimension(wxT("vgap")), GetDimension(wxT("hgap")));
- else if (m_Node->GetName() == _T("flexgridsizer"))
- sizer = new wxFlexGridSizer(GetLong(_T("rows")), GetLong(_T("cols")),
- GetLong(_T("vgap")), GetLong(_T("hgap")));
-
- wxSizer *old_par = m_ParentSizer;
- m_ParentSizer = sizer;
- bool old_ins = m_IsInside;
- m_IsInside = TRUE;
- CreateChildren(m_Parent, TRUE/*only this handler*/);
- m_IsInside = old_ins;
- m_ParentSizer = old_par;
+ else if (m_class == wxT("wxFlexGridSizer"))
+ {
+ wxFlexGridSizer *fsizer =
+ new wxFlexGridSizer(GetLong(wxT("rows")), GetLong(wxT("cols")),
+ GetDimension(wxT("vgap")), GetDimension(wxT("hgap")));
+ sizer = fsizer;
+ wxStringTokenizer tkn;
+ unsigned long l;
+ tkn.SetString(GetParamValue(wxT("growablerows")), wxT(","));
+ while (tkn.HasMoreTokens())
+ {
+ if (!tkn.GetNextToken().ToULong(&l))
+ wxLogError(wxT("growablerows must be comma-separated list of row numbers"));
+ else
+ fsizer->AddGrowableRow(l);
+ }
+ tkn.SetString(GetParamValue(wxT("growablecols")), wxT(","));
+ while (tkn.HasMoreTokens())
+ {
+ if (!tkn.GetNextToken().ToULong(&l))
+ wxLogError(wxT("growablecols must be comma-separated list of column numbers"));
+ else
+ fsizer->AddGrowableCol(l);
+ }
+ }
+
+ wxSize minsize = GetSize(wxT("minsize"));
+ if (!(minsize == wxDefaultSize))
+ sizer->SetMinSize(minsize);
+
+ wxSizer *old_par = m_parentSizer;
+ m_parentSizer = sizer;
+ bool old_ins = m_isInside;
+ m_isInside = TRUE;
+ CreateChildren(m_parent, TRUE/*only this handler*/);
+ m_isInside = old_ins;
+ m_parentSizer = old_par;
- if (m_ParentSizer == NULL) // setup window:
+ if (m_parentSizer == NULL) // setup window:
{
- m_ParentAsWindow->SetAutoLayout(TRUE);
- m_ParentAsWindow->SetSizer(sizer);
+ m_parentAsWindow->SetAutoLayout(TRUE);
+ m_parentAsWindow->SetSizer(sizer);
- wxXmlNode *nd = m_Node;
- m_Node = parentNode;
+ wxXmlNode *nd = m_node;
+ m_node = parentNode;
if (GetSize() == wxDefaultSize)
- sizer->Fit(m_ParentAsWindow);
- m_Node = nd;
+ sizer->Fit(m_parentAsWindow);
+ m_node = nd;
- if (m_ParentAsWindow->GetWindowStyle() & (wxRESIZE_BOX | wxRESIZE_BORDER))
- sizer->SetSizeHints(m_ParentAsWindow);
+ if (m_parentAsWindow->GetWindowStyle() & (wxRESIZE_BOX | wxRESIZE_BORDER))
+ sizer->SetSizeHints(m_parentAsWindow);
}
return sizer;
bool wxSizerXmlHandler::CanHandle(wxXmlNode *node)
{
- return ((!m_IsInside && IsSizerNode(node)) ||
- (m_IsInside && node->GetName() == _T("sizeritem")) ||
- (m_IsInside && node->GetName() == _T("spacer")));
+ return ((!m_isInside && IsSizerNode(node)) ||
+ (m_isInside && IsOfClass(node, wxT("sizeritem"))) ||
+ (m_isInside && IsOfClass(node, wxT("spacer"))));
}