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(),
33 XRC_ADD_STYLE(wxBK_DEFAULT
);
34 XRC_ADD_STYLE(wxBK_TOP
);
35 XRC_ADD_STYLE(wxBK_BOTTOM
);
36 XRC_ADD_STYLE(wxBK_LEFT
);
37 XRC_ADD_STYLE(wxBK_RIGHT
);
42 bool wxTreebookXmlHandler::CanHandle(wxXmlNode
*node
)
44 return ((!m_isInside
&& IsOfClass(node
, wxT("wxTreebook"))) ||
45 (m_isInside
&& IsOfClass(node
, wxT("treebookpage"))));
49 wxObject
*wxTreebookXmlHandler::DoCreateResource()
51 if (m_class
== wxT("wxTreebook"))
53 XRC_MAKE_INSTANCE(tbk
, wxTreebook
)
55 tbk
->Create(m_parentAsWindow
,
57 GetPosition(), GetSize(),
58 GetStyle(wxT("style")),
61 wxTreebook
* old_par
= m_tbk
;
64 bool old_ins
= m_isInside
;
67 wxArrayTbkPageIndexes old_treeContext
= m_treeContext
;
68 m_treeContext
.Clear();
70 CreateChildren(m_tbk
, true/*only this handler*/);
72 m_treeContext
= old_treeContext
;
79 // else ( m_class == wxT("treebookpage") )
80 wxXmlNode
*n
= GetParamNode(wxT("object"));
84 n
= GetParamNode(wxT("object_ref"));
88 bool old_ins
= m_isInside
;
90 wxObject
*item
= CreateResFromNode(n
, m_tbk
, NULL
);
92 wnd
= wxDynamicCast(item
, wxWindow
);
94 if (wnd
== NULL
&& item
!= NULL
)
95 wxLogError(wxT("Error in resource: control within treebook's <page> tag is not a window."));
98 size_t depth
= GetLong( wxT("depth") );
100 if( depth
<= m_treeContext
.Count() )
102 // first prepare the icon
103 int imgIndex
= wxNOT_FOUND
;
104 if ( HasParam(wxT("bitmap")) )
106 wxBitmap bmp
= GetBitmap(wxT("bitmap"), wxART_OTHER
);
107 wxImageList
*imgList
= m_tbk
->GetImageList();
108 if ( imgList
== NULL
)
110 imgList
= new wxImageList( bmp
.GetWidth(), bmp
.GetHeight() );
111 m_tbk
->AssignImageList( imgList
);
113 imgIndex
= imgList
->Add(bmp
);
116 // then add the page to the corresponding parent
117 if( depth
< m_treeContext
.Count() )
118 m_treeContext
.RemoveAt(depth
, m_treeContext
.Count() - depth
);
122 GetText(wxT("label")), GetBool(wxT("selected")), imgIndex
);
126 m_tbk
->AddSubPage(m_treeContext
.Item(depth
- 1), wnd
,
127 GetText(wxT("label")), GetBool(wxT("selected")), imgIndex
);
130 m_treeContext
.Add( m_tbk
->GetPageCount() - 1);
134 wxLogError(wxT("Error in resource. wxTreebookPage has an invalid depth."));
138 #endif // wxUSE_XRC && wxUSE_TREEBOOK