X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bebb14d53dc0efbf04e57934a70ae39e10819d96..219a5f10c0e5efc3aad7ff3d050a92e7fed88806:/contrib/src/xml/xh_sizer.cpp diff --git a/contrib/src/xml/xh_sizer.cpp b/contrib/src/xml/xh_sizer.cpp index 51b29c80e6..cd38979085 100644 --- a/contrib/src/xml/xh_sizer.cpp +++ b/contrib/src/xml/xh_sizer.cpp @@ -24,19 +24,20 @@ #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); @@ -73,56 +74,55 @@ wxSizerXmlHandler::wxSizerXmlHandler() 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); - 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); - } - 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 tag.")); + return NULL; } - wxLogError(_T("Error in resource: no control/sizer within sizer's 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")), GetDimension(_T("border"))); + m_parentSizer->Add(sz.x, sz.y, + GetLong(wxT("option")), GetStyle(wxT("flag")), GetDimension(wxT("border"))); return NULL; } @@ -130,58 +130,79 @@ wxObject *wxSizerXmlHandler::DoCreateResource() 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")), - GetDimension(_T("vgap")), GetDimension(_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")), - GetDimension(_T("vgap")), GetDimension(_T("hgap"))); + 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(_T("minsize")); + 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; + 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; @@ -192,7 +213,7 @@ wxObject *wxSizerXmlHandler::DoCreateResource() 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")))); }