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"
26 #include "wx/treebook.h"
27 #include "wx/imaglist.h"
29 IMPLEMENT_DYNAMIC_CLASS(wxTreebookXmlHandler
, wxXmlResourceHandler
)
31 wxTreebookXmlHandler::wxTreebookXmlHandler()
32 : wxXmlResourceHandler(),
36 XRC_ADD_STYLE(wxBK_DEFAULT
);
37 XRC_ADD_STYLE(wxBK_TOP
);
38 XRC_ADD_STYLE(wxBK_BOTTOM
);
39 XRC_ADD_STYLE(wxBK_LEFT
);
40 XRC_ADD_STYLE(wxBK_RIGHT
);
45 bool wxTreebookXmlHandler::CanHandle(wxXmlNode
*node
)
47 return ((!m_isInside
&& IsOfClass(node
, wxT("wxTreebook"))) ||
48 (m_isInside
&& IsOfClass(node
, wxT("treebookpage"))));
52 wxObject
*wxTreebookXmlHandler::DoCreateResource()
54 if (m_class
== wxT("wxTreebook"))
56 XRC_MAKE_INSTANCE(tbk
, wxTreebook
)
58 tbk
->Create(m_parentAsWindow
,
60 GetPosition(), GetSize(),
61 GetStyle(wxT("style")),
64 wxImageList
*imagelist
= GetImageList();
66 tbk
->AssignImageList(imagelist
);
68 wxTreebook
* old_par
= m_tbk
;
71 bool old_ins
= m_isInside
;
74 wxArrayTbkPageIndexes old_treeContext
= m_treeContext
;
75 m_treeContext
.Clear();
77 CreateChildren(m_tbk
, true/*only this handler*/);
79 wxXmlNode
*node
= GetParamNode("object");
81 for (unsigned int i
= 0; i
< m_tbk
->GetPageCount(); i
++)
83 if ( m_tbk
->GetPage(i
) )
85 wxXmlNode
*child
= node
->GetChildren();
88 if (child
->GetName() == "expanded" && child
->GetNodeContent() == "1")
89 m_tbk
->ExpandNode(pageIndex
, true);
91 child
= child
->GetNext();
97 m_treeContext
= old_treeContext
;
104 // else ( m_class == wxT("treebookpage") )
105 wxXmlNode
*n
= GetParamNode(wxT("object"));
106 wxWindow
*wnd
= NULL
;
109 n
= GetParamNode(wxT("object_ref"));
113 bool old_ins
= m_isInside
;
115 wxObject
*item
= CreateResFromNode(n
, m_tbk
, NULL
);
116 m_isInside
= old_ins
;
117 wnd
= wxDynamicCast(item
, wxWindow
);
119 if (wnd
== NULL
&& item
!= NULL
)
121 ReportError(n
, "treebookpage child must be a window");
125 size_t depth
= GetLong( wxT("depth") );
127 if( depth
<= m_treeContext
.GetCount() )
129 // first prepare the icon
130 int imgIndex
= wxNOT_FOUND
;
131 if ( HasParam(wxT("bitmap")) )
133 wxBitmap bmp
= GetBitmap(wxT("bitmap"), wxART_OTHER
);
134 wxImageList
*imgList
= m_tbk
->GetImageList();
135 if ( imgList
== NULL
)
137 imgList
= new wxImageList( bmp
.GetWidth(), bmp
.GetHeight() );
138 m_tbk
->AssignImageList( imgList
);
140 imgIndex
= imgList
->Add(bmp
);
142 else if ( HasParam(wxT("image")) )
144 if ( m_tbk
->GetImageList() )
146 imgIndex
= GetLong(wxT("image"));
148 else // image without image list?
150 ReportError(n
, "image can only be used in conjunction "
155 // then add the page to the corresponding parent
156 if( depth
< m_treeContext
.GetCount() )
157 m_treeContext
.RemoveAt(depth
, m_treeContext
.GetCount() - depth
);
161 GetText(wxT("label")), GetBool(wxT("selected")), imgIndex
);
165 m_tbk
->InsertSubPage(m_treeContext
.Item(depth
- 1), wnd
,
166 GetText(wxT("label")), GetBool(wxT("selected")), imgIndex
);
169 m_treeContext
.Add( m_tbk
->GetPageCount() - 1);
174 ReportParamError("depth", "invalid depth");
180 #endif // wxUSE_XRC && wxUSE_TREEBOOK