1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_treebk.cpp
3 // Purpose: XRC resource handler for wxTreebook
4 // Author: Evgeniy Tarassov
6 // Copyright: (c) 2005 TT-Solutions <vadim@tt-solutions.com>
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
17 #if wxUSE_XRC && wxUSE_TREEBOOK
19 #include "wx/xrc/xh_treebk.h"
25 #include "wx/treebook.h"
26 #include "wx/imaglist.h"
28 #include "wx/xml/xml.h"
30 IMPLEMENT_DYNAMIC_CLASS(wxTreebookXmlHandler
, wxXmlResourceHandler
)
32 wxTreebookXmlHandler::wxTreebookXmlHandler()
33 : wxXmlResourceHandler(),
37 XRC_ADD_STYLE(wxBK_DEFAULT
);
38 XRC_ADD_STYLE(wxBK_TOP
);
39 XRC_ADD_STYLE(wxBK_BOTTOM
);
40 XRC_ADD_STYLE(wxBK_LEFT
);
41 XRC_ADD_STYLE(wxBK_RIGHT
);
46 bool wxTreebookXmlHandler::CanHandle(wxXmlNode
*node
)
48 return ((!m_isInside
&& IsOfClass(node
, wxT("wxTreebook"))) ||
49 (m_isInside
&& IsOfClass(node
, wxT("treebookpage"))));
53 wxObject
*wxTreebookXmlHandler::DoCreateResource()
55 if (m_class
== wxT("wxTreebook"))
57 XRC_MAKE_INSTANCE(tbk
, wxTreebook
)
59 tbk
->Create(m_parentAsWindow
,
61 GetPosition(), GetSize(),
62 GetStyle(wxT("style")),
65 wxImageList
*imagelist
= GetImageList();
67 tbk
->AssignImageList(imagelist
);
69 wxTreebook
* old_par
= m_tbk
;
72 bool old_ins
= m_isInside
;
75 wxArrayTbkPageIndexes old_treeContext
= m_treeContext
;
76 m_treeContext
.Clear();
78 CreateChildren(m_tbk
, true/*only this handler*/);
80 wxXmlNode
*node
= GetParamNode("object");
82 for (unsigned int i
= 0; i
< m_tbk
->GetPageCount(); i
++)
84 if ( m_tbk
->GetPage(i
) )
86 wxXmlNode
*child
= node
->GetChildren();
89 if (child
->GetName() == "expanded" && child
->GetNodeContent() == "1")
90 m_tbk
->ExpandNode(pageIndex
, true);
92 child
= child
->GetNext();
98 m_treeContext
= old_treeContext
;
105 // else ( m_class == wxT("treebookpage") )
106 wxXmlNode
*n
= GetParamNode(wxT("object"));
107 wxWindow
*wnd
= NULL
;
110 n
= GetParamNode(wxT("object_ref"));
114 bool old_ins
= m_isInside
;
116 wxObject
*item
= CreateResFromNode(n
, m_tbk
, NULL
);
117 m_isInside
= old_ins
;
118 wnd
= wxDynamicCast(item
, wxWindow
);
120 if (wnd
== NULL
&& item
!= NULL
)
122 ReportError(n
, "treebookpage child must be a window");
126 size_t depth
= GetLong( wxT("depth") );
128 if( depth
<= m_treeContext
.GetCount() )
130 // first prepare the icon
131 int imgIndex
= wxNOT_FOUND
;
132 if ( HasParam(wxT("bitmap")) )
134 wxBitmap bmp
= GetBitmap(wxT("bitmap"), wxART_OTHER
);
135 wxImageList
*imgList
= m_tbk
->GetImageList();
136 if ( imgList
== NULL
)
138 imgList
= new wxImageList( bmp
.GetWidth(), bmp
.GetHeight() );
139 m_tbk
->AssignImageList( imgList
);
141 imgIndex
= imgList
->Add(bmp
);
143 else if ( HasParam(wxT("image")) )
145 if ( m_tbk
->GetImageList() )
147 imgIndex
= GetLong(wxT("image"));
149 else // image without image list?
151 ReportError(n
, "image can only be used in conjunction "
156 // then add the page to the corresponding parent
157 if( depth
< m_treeContext
.GetCount() )
158 m_treeContext
.RemoveAt(depth
, m_treeContext
.GetCount() - depth
);
162 GetText(wxT("label")), GetBool(wxT("selected")), imgIndex
);
166 m_tbk
->InsertSubPage(m_treeContext
.Item(depth
- 1), wnd
,
167 GetText(wxT("label")), GetBool(wxT("selected")), imgIndex
);
170 m_treeContext
.Add( m_tbk
->GetPageCount() - 1);
175 ReportParamError("depth", "invalid depth");
181 #endif // wxUSE_XRC && wxUSE_TREEBOOK