xh_treebk.cpp

Go to the documentation of this file.
00001 // $Id: xh_treebook.cpp 1089 2006-05-16 17:57:54Z alex $
00002 /* @@tag:xara-cn-tp@@ THIRD PARTY COPYRIGHT */
00003 // The following line makes normalize.pl skip type fixing
00004 /* SKIPFIXTYPES: START */
00005 
00007 // Name:        src/xrc/xh_treebk.cpp
00008 // Purpose:     XRC resource handler for wxTreebook
00009 // Author:      Evgeniy Tarassov
00010 // Created:     2005/09/28
00011 // RCS-ID:      $Id: xh_treebk.cpp,v 1.5 2006/04/26 08:21:31 ABX Exp $
00012 // Copyright:   (c) 2005 TT-Solutions <vadim@tt-solutions.com>
00013 // Licence:     wxWindows licence
00015 
00016 // For compilers that support precompilation, includes "wx.h".
00017 
00018 #include "treebook.h"
00019 
00020 #if wxUSE_XRC && wxXTRA_TREEBOOK
00021 
00022 #include "xh_treebk.h"
00023 
00024 #include <wx/log.h>
00025 
00026 #include <wx/imaglist.h>
00027 
00028 IMPLEMENT_DYNAMIC_CLASS(wxTreebookXmlHandler, wxXmlResourceHandler)
00029 
00030 wxTreebookXmlHandler::wxTreebookXmlHandler()
00031                     : wxXmlResourceHandler(),
00032                       m_tbk(NULL),
00033                       m_isInside(false)
00034 {
00035     XRC_ADD_STYLE(wxBK_DEFAULT);
00036     XRC_ADD_STYLE(wxBK_TOP);
00037     XRC_ADD_STYLE(wxBK_BOTTOM);
00038     XRC_ADD_STYLE(wxBK_LEFT);
00039     XRC_ADD_STYLE(wxBK_RIGHT);
00040 
00041     AddWindowStyles();
00042 }
00043 
00044 bool wxTreebookXmlHandler::CanHandle(wxXmlNode *node)
00045 {
00046     return ((!m_isInside && IsOfClass(node, wxT("wxTreebook"))) ||
00047             (m_isInside && IsOfClass(node, wxT("treebookpage"))));
00048 }
00049 
00050 
00051 wxObject *wxTreebookXmlHandler::DoCreateResource()
00052 {
00053     if (m_class == wxT("wxTreebook"))
00054     {
00055         XRC_MAKE_INSTANCE(tbk, wxTreebook)
00056 
00057         tbk->Create(m_parentAsWindow,
00058                     GetID(),
00059                     GetPosition(), GetSize(),
00060                     GetStyle(wxT("style")),
00061                     GetName());
00062 
00063         wxTreebook * old_par = m_tbk;
00064         m_tbk = tbk;
00065 
00066         bool old_ins = m_isInside;
00067         m_isInside = true;
00068 
00069         wxArrayTbkPageIndexes old_treeContext = m_treeContext;
00070         m_treeContext.Clear();
00071 
00072         CreateChildren(m_tbk, true/*only this handler*/);
00073 
00074         m_treeContext = old_treeContext;
00075         m_isInside = old_ins;
00076         m_tbk = old_par;
00077 
00078         return tbk;
00079     }
00080 
00081 //    else ( m_class == wxT("treebookpage") )
00082     wxXmlNode *n = GetParamNode(wxT("object"));
00083     wxWindow *wnd = NULL;
00084 
00085     if ( !n )
00086         n = GetParamNode(wxT("object_ref"));
00087 
00088     if (n)
00089     {
00090         bool old_ins = m_isInside;
00091         m_isInside = false;
00092         wxObject *item = CreateResFromNode(n, m_tbk, NULL);
00093         m_isInside = old_ins;
00094         wnd = wxDynamicCast(item, wxWindow);
00095 
00096         if (wnd == NULL && item != NULL)
00097             wxLogError(wxT("Error in resource: control within treebook's <page> tag is not a window."));
00098     }
00099 
00100     size_t depth = GetLong( wxT("depth") );
00101 
00102     if( depth <= m_treeContext.Count() )
00103     {
00104         // first prepare the icon
00105         int imgIndex = wxNOT_FOUND;
00106         if ( HasParam(wxT("bitmap")) )
00107         {
00108             wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER);
00109             wxImageList *imgList = m_tbk->GetImageList();
00110             if ( imgList == NULL )
00111             {
00112                 imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() );
00113                 m_tbk->AssignImageList( imgList );
00114             }
00115             imgIndex = imgList->Add(bmp);
00116         }
00117 
00118         // then add the page to the corresponding parent
00119         if( depth < m_treeContext.Count() )
00120             m_treeContext.RemoveAt(depth, m_treeContext.Count() - depth );
00121         if( depth == 0)
00122         {
00123             m_tbk->AddPage(wnd,
00124                 GetText(wxT("label")), GetBool(wxT("selected")), imgIndex);
00125         }
00126         else
00127         {
00128             m_tbk->InsertSubPage(m_treeContext.Item(depth - 1), wnd,
00129                 GetText(wxT("label")), GetBool(wxT("selected")), imgIndex);
00130         }
00131 
00132         m_treeContext.Add( m_tbk->GetPageCount() - 1);
00133 
00134     }
00135     else
00136         wxLogError(wxT("Error in resource. wxTreebookPage has an invalid depth."));
00137     return wnd;
00138 }
00139 
00140 #endif // wxUSE_XRC && wxUSE_TREEBOOK

Generated on Sat Nov 10 03:49:02 2007 for Camelot by  doxygen 1.4.4