1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_treebk.cpp
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(wxBK_DEFAULT
);
32 XRC_ADD_STYLE(wxBK_TOP
);
33 XRC_ADD_STYLE(wxBK_BOTTOM
);
34 XRC_ADD_STYLE(wxBK_LEFT
);
35 XRC_ADD_STYLE(wxBK_RIGHT
);
40 bool wxTreebookXmlHandler::CanHandle(wxXmlNode
*node
)
42 return ((!m_isInside
&& IsOfClass(node
, wxT("wxTreebook"))) ||
43 (m_isInside
&& IsOfClass(node
, wxT("treebookpage"))));
47 wxObject
*wxTreebookXmlHandler::DoCreateResource()
49 if (m_class
== wxT("wxTreebook"))
51 XRC_MAKE_INSTANCE(tbk
, wxTreebook
)
53 tbk
->Create(m_parentAsWindow
,
55 GetPosition(), GetSize(),
56 GetStyle(wxT("style")),
59 wxTreebook
* old_par
= m_tbk
;
62 bool old_ins
= m_isInside
;
65 wxArrayTbkPageIndexes old_treeContext
= m_treeContext
;
66 m_treeContext
.Clear();
68 CreateChildren(m_tbk
, true/*only this handler*/);
70 m_treeContext
= old_treeContext
;
77 // else ( m_class == wxT("treebookpage") )
78 wxXmlNode
*n
= GetParamNode(wxT("object"));
82 n
= GetParamNode(wxT("object_ref"));
86 bool old_ins
= m_isInside
;
88 wxObject
*item
= CreateResFromNode(n
, m_tbk
, NULL
);
90 wnd
= wxDynamicCast(item
, wxWindow
);
92 if (wnd
== NULL
&& item
!= NULL
)
93 wxLogError(wxT("Error in resource: control within treebook's <page> tag is not a window."));
96 size_t depth
= GetLong( wxT("depth") );
98 if( depth
<= m_treeContext
.Count() )
100 // first prepare the icon
101 int imgIndex
= wxNOT_FOUND
;
102 if ( HasParam(wxT("bitmap")) )
104 wxBitmap bmp
= GetBitmap(wxT("bitmap"), wxART_OTHER
);
105 wxImageList
*imgList
= m_tbk
->GetImageList();
106 if ( imgList
== NULL
)
108 imgList
= new wxImageList( bmp
.GetWidth(), bmp
.GetHeight() );
109 m_tbk
->AssignImageList( imgList
);
111 imgIndex
= imgList
->Add(bmp
);
114 // then add the page to the corresponding parent
115 if( depth
< m_treeContext
.Count() )
116 m_treeContext
.RemoveAt(depth
, m_treeContext
.Count() - depth
);
120 GetText(wxT("label")), GetBool(wxT("selected")), imgIndex
);
124 m_tbk
->AddSubPage(m_treeContext
.Item(depth
- 1), wnd
,
125 GetText(wxT("label")), GetBool(wxT("selected")), imgIndex
);
128 m_treeContext
.Add( m_tbk
->GetPageCount() - 1);
132 wxLogError(wxT("Error in resource. wxTreebookPage has an invalid depth."));
136 #endif // wxUSE_XRC && wxUSE_TREEBOOK