]> git.saurik.com Git - wxWidgets.git/blobdiff - src/xrc/xh_treebk.cpp
Add missing WXK constants for the control keys
[wxWidgets.git] / src / xrc / xh_treebk.cpp
index a79a01b9a34e818e785fb533520603bc97f44f82..9780ce24eaa61aebe270f139cb86d71d7089e23f 100644 (file)
 
 #include "wx/xrc/xh_treebk.h"
 
+#ifndef WX_PRECOMP
+    #include "wx/log.h"
+#endif
+
 #include "wx/treebook.h"
 #include "wx/imaglist.h"
-#include "wx/log.h"
+
+#include "wx/xml/xml.h"
 
 IMPLEMENT_DYNAMIC_CLASS(wxTreebookXmlHandler, wxXmlResourceHandler)
 
 wxTreebookXmlHandler::wxTreebookXmlHandler()
-: wxXmlResourceHandler(), m_isInside(false), m_tbk(NULL), m_treeContext()
+                    : wxXmlResourceHandler(),
+                      m_tbk(NULL),
+                      m_isInside(false)
 {
     XRC_ADD_STYLE(wxBK_DEFAULT);
     XRC_ADD_STYLE(wxBK_TOP);
@@ -56,6 +63,10 @@ wxObject *wxTreebookXmlHandler::DoCreateResource()
                     GetStyle(wxT("style")),
                     GetName());
 
+        wxImageList *imagelist = GetImageList();
+        if ( imagelist )
+            tbk->AssignImageList(imagelist);
+
         wxTreebook * old_par = m_tbk;
         m_tbk = tbk;
 
@@ -67,6 +78,24 @@ wxObject *wxTreebookXmlHandler::DoCreateResource()
 
         CreateChildren(m_tbk, true/*only this handler*/);
 
+        wxXmlNode *node = GetParamNode("object");
+        int pageIndex = 0;
+        for (unsigned int i = 0; i < m_tbk->GetPageCount(); i++)
+        {
+            if ( m_tbk->GetPage(i) )
+            {
+                wxXmlNode *child = node->GetChildren();
+                while (child)
+                {
+                    if (child->GetName() == "expanded" && child->GetNodeContent() == "1")
+                        m_tbk->ExpandNode(pageIndex, true);
+
+                    child = child->GetNext();
+                }
+                pageIndex++;
+            }
+        }
+
         m_treeContext = old_treeContext;
         m_isInside = old_ins;
         m_tbk = old_par;
@@ -90,12 +119,14 @@ wxObject *wxTreebookXmlHandler::DoCreateResource()
         wnd = wxDynamicCast(item, wxWindow);
 
         if (wnd == NULL && item != NULL)
-            wxLogError(wxT("Error in resource: control within treebook's <page> tag is not a window."));
+        {
+            ReportError(n, "treebookpage child must be a window");
+        }
     }
 
     size_t depth = GetLong( wxT("depth") );
 
-    if( depth <= m_treeContext.Count() )
+    if( depth <= m_treeContext.GetCount() )
     {
         // first prepare the icon
         int imgIndex = wxNOT_FOUND;
@@ -110,10 +141,22 @@ wxObject *wxTreebookXmlHandler::DoCreateResource()
             }
             imgIndex = imgList->Add(bmp);
         }
+        else if ( HasParam(wxT("image")) )
+        {
+            if ( m_tbk->GetImageList() )
+            {
+                imgIndex = GetLong(wxT("image"));
+            }
+            else // image without image list?
+            {
+                ReportError(n, "image can only be used in conjunction "
+                               "with imagelist");
+            }
+        }
 
         // then add the page to the corresponding parent
-        if( depth < m_treeContext.Count() )
-            m_treeContext.RemoveAt(depth, m_treeContext.Count() - depth );
+        if( depth < m_treeContext.GetCount() )
+            m_treeContext.RemoveAt(depth, m_treeContext.GetCount() - depth );
         if( depth == 0)
         {
             m_tbk->AddPage(wnd,
@@ -121,7 +164,7 @@ wxObject *wxTreebookXmlHandler::DoCreateResource()
         }
         else
         {
-            m_tbk->AddSubPage(m_treeContext.Item(depth - 1), wnd,
+            m_tbk->InsertSubPage(m_treeContext.Item(depth - 1), wnd,
                 GetText(wxT("label")), GetBool(wxT("selected")), imgIndex);
         }
 
@@ -129,7 +172,10 @@ wxObject *wxTreebookXmlHandler::DoCreateResource()
 
     }
     else
-        wxLogError(wxT("Error in resource. wxTreebookPage has an invalid depth."));
+    {
+        ReportParamError("depth", "invalid depth");
+    }
+
     return wnd;
 }