]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_treebk.cpp
Remove SashHitTest() "tolerance" parameter
[wxWidgets.git] / src / xrc / xh_treebk.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_treebk.cpp
3 // Purpose: XRC resource handler for wxTreebook
4 // Author: Evgeniy Tarassov
5 // Created: 2005/09/28
6 // RCS-ID: $Id$
7 // Copyright: (c) 2005 TT-Solutions <vadim@tt-solutions.com>
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #if wxUSE_XRC && wxUSE_TREEBOOK
19
20 #include "wx/xrc/xh_treebk.h"
21
22 #ifndef WX_PRECOMP
23 #include "wx/log.h"
24 #endif
25
26 #include "wx/treebook.h"
27 #include "wx/imaglist.h"
28
29 #include "wx/xml/xml.h"
30
31 IMPLEMENT_DYNAMIC_CLASS(wxTreebookXmlHandler, wxXmlResourceHandler)
32
33 wxTreebookXmlHandler::wxTreebookXmlHandler()
34 : wxXmlResourceHandler(),
35 m_tbk(NULL),
36 m_isInside(false)
37 {
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);
43
44 AddWindowStyles();
45 }
46
47 bool wxTreebookXmlHandler::CanHandle(wxXmlNode *node)
48 {
49 return ((!m_isInside && IsOfClass(node, wxT("wxTreebook"))) ||
50 (m_isInside && IsOfClass(node, wxT("treebookpage"))));
51 }
52
53
54 wxObject *wxTreebookXmlHandler::DoCreateResource()
55 {
56 if (m_class == wxT("wxTreebook"))
57 {
58 XRC_MAKE_INSTANCE(tbk, wxTreebook)
59
60 tbk->Create(m_parentAsWindow,
61 GetID(),
62 GetPosition(), GetSize(),
63 GetStyle(wxT("style")),
64 GetName());
65
66 wxImageList *imagelist = GetImageList();
67 if ( imagelist )
68 tbk->AssignImageList(imagelist);
69
70 wxTreebook * old_par = m_tbk;
71 m_tbk = tbk;
72
73 bool old_ins = m_isInside;
74 m_isInside = true;
75
76 wxArrayTbkPageIndexes old_treeContext = m_treeContext;
77 m_treeContext.Clear();
78
79 CreateChildren(m_tbk, true/*only this handler*/);
80
81 wxXmlNode *node = GetParamNode("object");
82 int pageIndex = 0;
83 for (unsigned int i = 0; i < m_tbk->GetPageCount(); i++)
84 {
85 if ( m_tbk->GetPage(i) )
86 {
87 wxXmlNode *child = node->GetChildren();
88 while (child)
89 {
90 if (child->GetName() == "expanded" && child->GetNodeContent() == "1")
91 m_tbk->ExpandNode(pageIndex, true);
92
93 child = child->GetNext();
94 }
95 pageIndex++;
96 }
97 }
98
99 m_treeContext = old_treeContext;
100 m_isInside = old_ins;
101 m_tbk = old_par;
102
103 return tbk;
104 }
105
106 // else ( m_class == wxT("treebookpage") )
107 wxXmlNode *n = GetParamNode(wxT("object"));
108 wxWindow *wnd = NULL;
109
110 if ( !n )
111 n = GetParamNode(wxT("object_ref"));
112
113 if (n)
114 {
115 bool old_ins = m_isInside;
116 m_isInside = false;
117 wxObject *item = CreateResFromNode(n, m_tbk, NULL);
118 m_isInside = old_ins;
119 wnd = wxDynamicCast(item, wxWindow);
120
121 if (wnd == NULL && item != NULL)
122 {
123 ReportError(n, "treebookpage child must be a window");
124 }
125 }
126
127 size_t depth = GetLong( wxT("depth") );
128
129 if( depth <= m_treeContext.GetCount() )
130 {
131 // first prepare the icon
132 int imgIndex = wxNOT_FOUND;
133 if ( HasParam(wxT("bitmap")) )
134 {
135 wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER);
136 wxImageList *imgList = m_tbk->GetImageList();
137 if ( imgList == NULL )
138 {
139 imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() );
140 m_tbk->AssignImageList( imgList );
141 }
142 imgIndex = imgList->Add(bmp);
143 }
144 else if ( HasParam(wxT("image")) )
145 {
146 if ( m_tbk->GetImageList() )
147 {
148 imgIndex = GetLong(wxT("image"));
149 }
150 else // image without image list?
151 {
152 ReportError(n, "image can only be used in conjunction "
153 "with imagelist");
154 }
155 }
156
157 // then add the page to the corresponding parent
158 if( depth < m_treeContext.GetCount() )
159 m_treeContext.RemoveAt(depth, m_treeContext.GetCount() - depth );
160 if( depth == 0)
161 {
162 m_tbk->AddPage(wnd,
163 GetText(wxT("label")), GetBool(wxT("selected")), imgIndex);
164 }
165 else
166 {
167 m_tbk->InsertSubPage(m_treeContext.Item(depth - 1), wnd,
168 GetText(wxT("label")), GetBool(wxT("selected")), imgIndex);
169 }
170
171 m_treeContext.Add( m_tbk->GetPageCount() - 1);
172
173 }
174 else
175 {
176 ReportParamError("depth", "invalid depth");
177 }
178
179 return wnd;
180 }
181
182 #endif // wxUSE_XRC && wxUSE_TREEBOOK