]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_treebk.cpp
uninitialized variable warning fixed (modified patch 1434065)
[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 #include "wx/treebook.h"
23 #include "wx/imaglist.h"
24 #include "wx/log.h"
25
26 IMPLEMENT_DYNAMIC_CLASS(wxTreebookXmlHandler, wxXmlResourceHandler)
27
28 wxTreebookXmlHandler::wxTreebookXmlHandler()
29 : wxXmlResourceHandler(),
30 m_tbk(NULL),
31 m_isInside(false)
32 {
33 XRC_ADD_STYLE(wxBK_DEFAULT);
34 XRC_ADD_STYLE(wxBK_TOP);
35 XRC_ADD_STYLE(wxBK_BOTTOM);
36 XRC_ADD_STYLE(wxBK_LEFT);
37 XRC_ADD_STYLE(wxBK_RIGHT);
38
39 AddWindowStyles();
40 }
41
42 bool wxTreebookXmlHandler::CanHandle(wxXmlNode *node)
43 {
44 return ((!m_isInside && IsOfClass(node, wxT("wxTreebook"))) ||
45 (m_isInside && IsOfClass(node, wxT("treebookpage"))));
46 }
47
48
49 wxObject *wxTreebookXmlHandler::DoCreateResource()
50 {
51 if (m_class == wxT("wxTreebook"))
52 {
53 XRC_MAKE_INSTANCE(tbk, wxTreebook)
54
55 tbk->Create(m_parentAsWindow,
56 GetID(),
57 GetPosition(), GetSize(),
58 GetStyle(wxT("style")),
59 GetName());
60
61 wxTreebook * old_par = m_tbk;
62 m_tbk = tbk;
63
64 bool old_ins = m_isInside;
65 m_isInside = true;
66
67 wxArrayTbkPageIndexes old_treeContext = m_treeContext;
68 m_treeContext.Clear();
69
70 CreateChildren(m_tbk, true/*only this handler*/);
71
72 m_treeContext = old_treeContext;
73 m_isInside = old_ins;
74 m_tbk = old_par;
75
76 return tbk;
77 }
78
79 // else ( m_class == wxT("treebookpage") )
80 wxXmlNode *n = GetParamNode(wxT("object"));
81 wxWindow *wnd = NULL;
82
83 if ( !n )
84 n = GetParamNode(wxT("object_ref"));
85
86 if (n)
87 {
88 bool old_ins = m_isInside;
89 m_isInside = false;
90 wxObject *item = CreateResFromNode(n, m_tbk, NULL);
91 m_isInside = old_ins;
92 wnd = wxDynamicCast(item, wxWindow);
93
94 if (wnd == NULL && item != NULL)
95 wxLogError(wxT("Error in resource: control within treebook's <page> tag is not a window."));
96 }
97
98 size_t depth = GetLong( wxT("depth") );
99
100 if( depth <= m_treeContext.Count() )
101 {
102 // first prepare the icon
103 int imgIndex = wxNOT_FOUND;
104 if ( HasParam(wxT("bitmap")) )
105 {
106 wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER);
107 wxImageList *imgList = m_tbk->GetImageList();
108 if ( imgList == NULL )
109 {
110 imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() );
111 m_tbk->AssignImageList( imgList );
112 }
113 imgIndex = imgList->Add(bmp);
114 }
115
116 // then add the page to the corresponding parent
117 if( depth < m_treeContext.Count() )
118 m_treeContext.RemoveAt(depth, m_treeContext.Count() - depth );
119 if( depth == 0)
120 {
121 m_tbk->AddPage(wnd,
122 GetText(wxT("label")), GetBool(wxT("selected")), imgIndex);
123 }
124 else
125 {
126 m_tbk->InsertSubPage(m_treeContext.Item(depth - 1), wnd,
127 GetText(wxT("label")), GetBool(wxT("selected")), imgIndex);
128 }
129
130 m_treeContext.Add( m_tbk->GetPageCount() - 1);
131
132 }
133 else
134 wxLogError(wxT("Error in resource. wxTreebookPage has an invalid depth."));
135 return wnd;
136 }
137
138 #endif // wxUSE_XRC && wxUSE_TREEBOOK