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 #include "wx/xml/xml.h"
31 IMPLEMENT_DYNAMIC_CLASS(wxTreebookXmlHandler
, wxXmlResourceHandler
)
33 wxTreebookXmlHandler::wxTreebookXmlHandler()
34 : wxXmlResourceHandler(),
38 XRC_ADD_STYLE(wxBK_DEFAULT
);
39 XRC_ADD_STYLE(wxBK_TOP
);
40 XRC_ADD_STYLE(wxBK_BOTTOM
);
41 XRC_ADD_STYLE(wxBK_LEFT
);
42 XRC_ADD_STYLE(wxBK_RIGHT
);
47 bool wxTreebookXmlHandler::CanHandle(wxXmlNode
*node
)
49 return ((!m_isInside
&& IsOfClass(node
, wxT("wxTreebook"))) ||
50 (m_isInside
&& IsOfClass(node
, wxT("treebookpage"))));
54 wxObject
*wxTreebookXmlHandler::DoCreateResource()
56 if (m_class
== wxT("wxTreebook"))
58 XRC_MAKE_INSTANCE(tbk
, wxTreebook
)
60 tbk
->Create(m_parentAsWindow
,
62 GetPosition(), GetSize(),
63 GetStyle(wxT("style")),
66 wxImageList
*imagelist
= GetImageList();
68 tbk
->AssignImageList(imagelist
);
70 wxTreebook
* old_par
= m_tbk
;
73 bool old_ins
= m_isInside
;
76 wxArrayTbkPageIndexes old_treeContext
= m_treeContext
;
77 m_treeContext
.Clear();
79 CreateChildren(m_tbk
, true/*only this handler*/);
81 wxXmlNode
*node
= GetParamNode("object");
83 for (unsigned int i
= 0; i
< m_tbk
->GetPageCount(); i
++)
85 if ( m_tbk
->GetPage(i
) )
87 wxXmlNode
*child
= node
->GetChildren();
90 if (child
->GetName() == "expanded" && child
->GetNodeContent() == "1")
91 m_tbk
->ExpandNode(pageIndex
, true);
93 child
= child
->GetNext();
99 m_treeContext
= old_treeContext
;
100 m_isInside
= old_ins
;
106 // else ( m_class == wxT("treebookpage") )
107 wxXmlNode
*n
= GetParamNode(wxT("object"));
108 wxWindow
*wnd
= NULL
;
111 n
= GetParamNode(wxT("object_ref"));
115 bool old_ins
= m_isInside
;
117 wxObject
*item
= CreateResFromNode(n
, m_tbk
, NULL
);
118 m_isInside
= old_ins
;
119 wnd
= wxDynamicCast(item
, wxWindow
);
121 if (wnd
== NULL
&& item
!= NULL
)
123 ReportError(n
, "treebookpage child must be a window");
127 size_t depth
= GetLong( wxT("depth") );
129 if( depth
<= m_treeContext
.GetCount() )
131 // first prepare the icon
132 int imgIndex
= wxNOT_FOUND
;
133 if ( HasParam(wxT("bitmap")) )
135 wxBitmap bmp
= GetBitmap(wxT("bitmap"), wxART_OTHER
);
136 wxImageList
*imgList
= m_tbk
->GetImageList();
137 if ( imgList
== NULL
)
139 imgList
= new wxImageList( bmp
.GetWidth(), bmp
.GetHeight() );
140 m_tbk
->AssignImageList( imgList
);
142 imgIndex
= imgList
->Add(bmp
);
144 else if ( HasParam(wxT("image")) )
146 if ( m_tbk
->GetImageList() )
148 imgIndex
= GetLong(wxT("image"));
150 else // image without image list?
152 ReportError(n
, "image can only be used in conjunction "
157 // then add the page to the corresponding parent
158 if( depth
< m_treeContext
.GetCount() )
159 m_treeContext
.RemoveAt(depth
, m_treeContext
.GetCount() - depth
);
163 GetText(wxT("label")), GetBool(wxT("selected")), imgIndex
);
167 m_tbk
->InsertSubPage(m_treeContext
.Item(depth
- 1), wnd
,
168 GetText(wxT("label")), GetBool(wxT("selected")), imgIndex
);
171 m_treeContext
.Add( m_tbk
->GetPageCount() - 1);
176 ReportParamError("depth", "invalid depth");
182 #endif // wxUSE_XRC && wxUSE_TREEBOOK