]> git.saurik.com Git - wxWidgets.git/blobdiff - contrib/src/xml/xh_sizer.cpp
added 'name' to wxEditableListBox ctor
[wxWidgets.git] / contrib / src / xml / xh_sizer.cpp
index 5b9bd3d4364cff180f904b4c9b219ed83dd722d9..cd38979085b968bcdf9abedecc835ad8d6269bb6 100644 (file)
 #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")));
+    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,55 +74,55 @@ wxSizerXmlHandler::wxSizerXmlHandler()
 
 wxObject *wxSizerXmlHandler::DoCreateResource()
 { 
-    if (m_Class == _T("sizeritem"))
+    if (m_class == wxT("sizeritem"))
     {
-        wxXmlNode *n = GetParamNode(_T("object"));
+        wxXmlNode *n = GetParamNode(wxT("object"));
 
         if (n)
         {
-            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;
+            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"));
+            wxSize minsize = GetSize(wxT("minsize"));
 
             if (sizer)
             {
-                m_ParentSizer->Add(sizer, GetLong(_T("option")), 
-                                   GetStyle(_T("flag")), GetDimension(_T("border")));
+                m_parentSizer->Add(sizer, GetLong(wxT("option")), 
+                                   GetStyle(wxT("flag")), GetDimension(wxT("border")));
                 if (!(minsize == wxDefaultSize))
-                    m_ParentSizer->SetItemMinSize(sizer, minsize.x, minsize.y);
+                    m_parentSizer->SetItemMinSize(sizer, minsize.x, minsize.y);
             }
             else if (wnd)
             {
-                m_ParentSizer->Add(wnd, GetLong(_T("option")), 
-                                   GetStyle(_T("flag")), GetDimension(_T("border")));
+                m_parentSizer->Add(wnd, GetLong(wxT("option")), 
+                                   GetStyle(wxT("flag")), GetDimension(wxT("border")));
                 if (!(minsize == wxDefaultSize))
-                    m_ParentSizer->SetItemMinSize(wnd, minsize.x, minsize.y);
+                    m_parentSizer->SetItemMinSize(wnd, minsize.x, minsize.y);
             }
             else 
-                wxLogError(_T("Error in resource."));
+                wxLogError(wxT("Error in resource."));
 
             return item;
         }
         else /*n == NULL*/
         {
-            wxLogError(_T("Error in resource: no control/sizer within sizer's <item> tag."));
+            wxLogError(wxT("Error in resource: no control/sizer within sizer's <item> tag."));
             return NULL;
         }
     }
     
-    else if (m_Class == _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;
     }
     
@@ -129,58 +130,79 @@ wxObject *wxSizerXmlHandler::DoCreateResource()
     else {
         wxSizer *sizer = NULL;
         
-        wxXmlNode *parentNode = m_Node->GetParent();
+        wxXmlNode *parentNode = m_node->GetParent();
 
-        wxCHECK_MSG(m_ParentSizer != NULL ||
-                ((IsOfClass(parentNode, _T("wxPanel")) ||
-                  IsOfClass(parentNode, _T("wxDialog"))) &&
+        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 'wxDialog' or 'wxPanel'."));
+                wxT("Incorrect use of sizer: parent is not 'wxDialog' or 'wxPanel'."));
 
-        if (m_Class == _T("wxBoxSizer"))
-            sizer = new wxBoxSizer(GetStyle(_T("orient"), wxHORIZONTAL));
+        if (m_class == wxT("wxBoxSizer"))
+            sizer = new wxBoxSizer(GetStyle(wxT("orient"), wxHORIZONTAL));
 
-        else if (m_Class == _T("wxStaticBoxSizer"))
+        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_Class == _T("wxGridSizer"))
-            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_Class == _T("wxFlexGridSizer"))
-            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;
@@ -191,7 +213,7 @@ wxObject *wxSizerXmlHandler::DoCreateResource()
 
 bool wxSizerXmlHandler::CanHandle(wxXmlNode *node)
 {
-    return ((!m_IsInside && IsSizerNode(node)) ||
-            (m_IsInside && IsOfClass(node, _T("sizeritem"))) ||
-            (m_IsInside && IsOfClass(node, _T("spacer"))));
+    return ((!m_isInside && IsSizerNode(node)) ||
+            (m_isInside && IsOfClass(node, wxT("sizeritem"))) ||
+            (m_isInside && IsOfClass(node, wxT("spacer"))));
 }