1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: XRC resource handler for wxTreebook
4 // Author: Evgeniy Tarassov
7 // Copyright: (c) 2005 TT-Solutions <vadim@tt-solutions.com>
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
18 #if wxUSE_XRC && wxUSE_TREEBOOK
20 #include "wx/xrc/xh_treebk.h"
22 #include "wx/treebook.h"
23 #include "wx/imaglist.h"
26 IMPLEMENT_DYNAMIC_CLASS(wxTreebookXmlHandler
, wxXmlResourceHandler
)
28 wxTreebookXmlHandler::wxTreebookXmlHandler()
29 : wxXmlResourceHandler(), m_isInside(false), m_tbk(NULL
), m_treeContext()
31 XRC_ADD_STYLE(wxTBK_DEFAULT
);
32 XRC_ADD_STYLE(wxTBK_LEFT
);
33 XRC_ADD_STYLE(wxTBK_RIGHT
);
38 bool wxTreebookXmlHandler::CanHandle(wxXmlNode
*node
)
40 return ((!m_isInside
&& IsOfClass(node
, wxT("wxTreebook"))) ||
41 (m_isInside
&& IsOfClass(node
, wxT("treebookpage"))));
45 wxObject
*wxTreebookXmlHandler::DoCreateResource()
47 if (m_class
== wxT("wxTreebook"))
49 XRC_MAKE_INSTANCE(tbk
, wxTreebook
)
51 tbk
->Create(m_parentAsWindow
,
53 GetPosition(), GetSize(),
54 GetStyle(wxT("style")),
57 wxTreebook
* old_par
= m_tbk
;
60 bool old_ins
= m_isInside
;
63 wxArrayTbkPageIndexes old_treeContext
= m_treeContext
;
64 m_treeContext
.Clear();
66 CreateChildren(m_tbk
, true/*only this handler*/);
68 m_treeContext
= old_treeContext
;
75 // else ( m_class == wxT("treebookpage") )
76 wxXmlNode
*n
= GetParamNode(wxT("object"));
80 n
= GetParamNode(wxT("object_ref"));
84 bool old_ins
= m_isInside
;
86 wxObject
*item
= CreateResFromNode(n
, m_tbk
, NULL
);
88 wnd
= wxDynamicCast(item
, wxWindow
);
90 if (wnd
== NULL
&& item
!= NULL
)
91 wxLogError(wxT("Error in resource: control within treebook's <page> tag is not a window."));
94 size_t depth
= GetLong( wxT("depth") );
96 if( depth
<= m_treeContext
.Count() )
98 // first prepare the icon
99 int imgIndex
= wxNOT_FOUND
;
100 if ( HasParam(wxT("bitmap")) )
102 wxBitmap bmp
= GetBitmap(wxT("bitmap"), wxART_OTHER
);
103 wxImageList
*imgList
= m_tbk
->GetImageList();
104 if ( imgList
== NULL
)
106 imgList
= new wxImageList( bmp
.GetWidth(), bmp
.GetHeight() );
107 m_tbk
->AssignImageList( imgList
);
109 imgIndex
= imgList
->Add(bmp
);
112 // then add the page to the corresponding parent
113 if( depth
< m_treeContext
.Count() )
114 m_treeContext
.RemoveAt(depth
, m_treeContext
.Count() - depth
);
118 GetText(wxT("label")), GetBool(wxT("selected")), imgIndex
);
122 m_tbk
->AddSubPage(m_treeContext
.Item(depth
- 1), wnd
,
123 GetText(wxT("label")), GetBool(wxT("selected")), imgIndex
);
126 m_treeContext
.Add( m_tbk
->GetPageCount() - 1);
130 wxLogError(wxT("Error in resource. wxTreebookPage has an invalid depth."));
134 #endif // wxUSE_XRC && wxUSE_TREEBOOK