]>
Commit | Line | Data |
---|---|---|
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 | IMPLEMENT_DYNAMIC_CLASS(wxTreebookXmlHandler, wxXmlResourceHandler) | |
30 | ||
31 | wxTreebookXmlHandler::wxTreebookXmlHandler() | |
32 | : wxXmlResourceHandler(), | |
33 | m_tbk(NULL), | |
34 | m_isInside(false) | |
35 | { | |
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); | |
41 | ||
42 | AddWindowStyles(); | |
43 | } | |
44 | ||
45 | bool wxTreebookXmlHandler::CanHandle(wxXmlNode *node) | |
46 | { | |
47 | return ((!m_isInside && IsOfClass(node, wxT("wxTreebook"))) || | |
48 | (m_isInside && IsOfClass(node, wxT("treebookpage")))); | |
49 | } | |
50 | ||
51 | ||
52 | wxObject *wxTreebookXmlHandler::DoCreateResource() | |
53 | { | |
54 | if (m_class == wxT("wxTreebook")) | |
55 | { | |
56 | XRC_MAKE_INSTANCE(tbk, wxTreebook) | |
57 | ||
58 | tbk->Create(m_parentAsWindow, | |
59 | GetID(), | |
60 | GetPosition(), GetSize(), | |
61 | GetStyle(wxT("style")), | |
62 | GetName()); | |
63 | ||
64 | wxImageList *imagelist = GetImageList(); | |
65 | if ( imagelist ) | |
66 | tbk->AssignImageList(imagelist); | |
67 | ||
68 | wxTreebook * old_par = m_tbk; | |
69 | m_tbk = tbk; | |
70 | ||
71 | bool old_ins = m_isInside; | |
72 | m_isInside = true; | |
73 | ||
74 | wxArrayTbkPageIndexes old_treeContext = m_treeContext; | |
75 | m_treeContext.Clear(); | |
76 | ||
77 | CreateChildren(m_tbk, true/*only this handler*/); | |
78 | ||
79 | wxXmlNode *node = GetParamNode("object"); | |
80 | int pageIndex = 0; | |
81 | for (unsigned int i = 0; i < m_tbk->GetPageCount(); i++) | |
82 | { | |
83 | if ( m_tbk->GetPage(i) ) | |
84 | { | |
85 | wxXmlNode *child = node->GetChildren(); | |
86 | while (child) | |
87 | { | |
88 | if (child->GetName() == "expanded" && child->GetNodeContent() == "1") | |
89 | m_tbk->ExpandNode(pageIndex, true); | |
90 | ||
91 | child = child->GetNext(); | |
92 | } | |
93 | pageIndex++; | |
94 | } | |
95 | } | |
96 | ||
97 | m_treeContext = old_treeContext; | |
98 | m_isInside = old_ins; | |
99 | m_tbk = old_par; | |
100 | ||
101 | return tbk; | |
102 | } | |
103 | ||
104 | // else ( m_class == wxT("treebookpage") ) | |
105 | wxXmlNode *n = GetParamNode(wxT("object")); | |
106 | wxWindow *wnd = NULL; | |
107 | ||
108 | if ( !n ) | |
109 | n = GetParamNode(wxT("object_ref")); | |
110 | ||
111 | if (n) | |
112 | { | |
113 | bool old_ins = m_isInside; | |
114 | m_isInside = false; | |
115 | wxObject *item = CreateResFromNode(n, m_tbk, NULL); | |
116 | m_isInside = old_ins; | |
117 | wnd = wxDynamicCast(item, wxWindow); | |
118 | ||
119 | if (wnd == NULL && item != NULL) | |
120 | { | |
121 | ReportError(n, "treebookpage child must be a window"); | |
122 | } | |
123 | } | |
124 | ||
125 | size_t depth = GetLong( wxT("depth") ); | |
126 | ||
127 | if( depth <= m_treeContext.GetCount() ) | |
128 | { | |
129 | // first prepare the icon | |
130 | int imgIndex = wxNOT_FOUND; | |
131 | if ( HasParam(wxT("bitmap")) ) | |
132 | { | |
133 | wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER); | |
134 | wxImageList *imgList = m_tbk->GetImageList(); | |
135 | if ( imgList == NULL ) | |
136 | { | |
137 | imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() ); | |
138 | m_tbk->AssignImageList( imgList ); | |
139 | } | |
140 | imgIndex = imgList->Add(bmp); | |
141 | } | |
142 | else if ( HasParam(wxT("image")) ) | |
143 | { | |
144 | if ( m_tbk->GetImageList() ) | |
145 | { | |
146 | imgIndex = GetLong(wxT("image")); | |
147 | } | |
148 | else // image without image list? | |
149 | { | |
150 | ReportError(n, "image can only be used in conjunction " | |
151 | "with imagelist"); | |
152 | } | |
153 | } | |
154 | ||
155 | // then add the page to the corresponding parent | |
156 | if( depth < m_treeContext.GetCount() ) | |
157 | m_treeContext.RemoveAt(depth, m_treeContext.GetCount() - depth ); | |
158 | if( depth == 0) | |
159 | { | |
160 | m_tbk->AddPage(wnd, | |
161 | GetText(wxT("label")), GetBool(wxT("selected")), imgIndex); | |
162 | } | |
163 | else | |
164 | { | |
165 | m_tbk->InsertSubPage(m_treeContext.Item(depth - 1), wnd, | |
166 | GetText(wxT("label")), GetBool(wxT("selected")), imgIndex); | |
167 | } | |
168 | ||
169 | m_treeContext.Add( m_tbk->GetPageCount() - 1); | |
170 | ||
171 | } | |
172 | else | |
173 | { | |
174 | ReportParamError("depth", "invalid depth"); | |
175 | } | |
176 | ||
177 | return wnd; | |
178 | } | |
179 | ||
180 | #endif // wxUSE_XRC && wxUSE_TREEBOOK |