]> git.saurik.com Git - wxWidgets.git/blobdiff - contrib/src/xml/xh_sizer.cpp
documented EVT_LIST_ITEM_RIGHT_CLICK
[wxWidgets.git] / contrib / src / xml / xh_sizer.cpp
index 8932fc65576dc1f7fcc071c53779d5d5860afc95..51b29c80e6431ed214facbf000095c3efc7f6c43 100644 (file)
 #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)
 {
@@ -72,18 +82,30 @@ wxObject *wxSizerXmlHandler::DoCreateResource()
             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."));
                 
@@ -100,39 +122,11 @@ wxObject *wxSizerXmlHandler::DoCreateResource()
         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;
         
@@ -153,6 +147,19 @@ wxObject *wxSizerXmlHandler::DoCreateResource()
                          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;
@@ -185,11 +192,7 @@ wxObject *wxSizerXmlHandler::DoCreateResource()
 
 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")));
 }