]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_treebk.cpp
Recognize VC12 (a.k.a. MSVS 2013) and define __VISUALC12__ for it.
[wxWidgets.git] / src / xrc / xh_treebk.cpp
CommitLineData
eca15c0d 1/////////////////////////////////////////////////////////////////////////////
2ddb4d13 2// Name: src/xrc/xh_treebk.cpp
eca15c0d
VZ
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
e4db172a
WS
22#ifndef WX_PRECOMP
23 #include "wx/log.h"
24#endif
25
eca15c0d
VZ
26#include "wx/treebook.h"
27#include "wx/imaglist.h"
eca15c0d 28
df27f1dc
VZ
29#include "wx/xml/xml.h"
30
eca15c0d
VZ
31IMPLEMENT_DYNAMIC_CLASS(wxTreebookXmlHandler, wxXmlResourceHandler)
32
33wxTreebookXmlHandler::wxTreebookXmlHandler()
1f00af0e
VZ
34 : wxXmlResourceHandler(),
35 m_tbk(NULL),
36 m_isInside(false)
eca15c0d 37{
2ddb4d13
WS
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);
eca15c0d
VZ
43
44 AddWindowStyles();
45}
46
47bool wxTreebookXmlHandler::CanHandle(wxXmlNode *node)
48{
49 return ((!m_isInside && IsOfClass(node, wxT("wxTreebook"))) ||
50 (m_isInside && IsOfClass(node, wxT("treebookpage"))));
51}
52
53
54wxObject *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
326462ae
VZ
66 wxImageList *imagelist = GetImageList();
67 if ( imagelist )
68 tbk->AssignImageList(imagelist);
69
eca15c0d
VZ
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
2b232dec
VZ
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
eca15c0d
VZ
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)
819559b2
VS
122 {
123 ReportError(n, "treebookpage child must be a window");
124 }
eca15c0d
VZ
125 }
126
127 size_t depth = GetLong( wxT("depth") );
2ddb4d13 128
b4a980f4 129 if( depth <= m_treeContext.GetCount() )
eca15c0d
VZ
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 }
326462ae
VZ
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 }
eca15c0d
VZ
156
157 // then add the page to the corresponding parent
b4a980f4
VZ
158 if( depth < m_treeContext.GetCount() )
159 m_treeContext.RemoveAt(depth, m_treeContext.GetCount() - depth );
eca15c0d
VZ
160 if( depth == 0)
161 {
162 m_tbk->AddPage(wnd,
163 GetText(wxT("label")), GetBool(wxT("selected")), imgIndex);
164 }
165 else
166 {
b7c542d5 167 m_tbk->InsertSubPage(m_treeContext.Item(depth - 1), wnd,
eca15c0d
VZ
168 GetText(wxT("label")), GetBool(wxT("selected")), imgIndex);
169 }
2ddb4d13 170
eca15c0d 171 m_treeContext.Add( m_tbk->GetPageCount() - 1);
2ddb4d13 172
eca15c0d
VZ
173 }
174 else
819559b2
VS
175 {
176 ReportParamError("depth", "invalid depth");
177 }
178
eca15c0d
VZ
179 return wnd;
180}
181
182#endif // wxUSE_XRC && wxUSE_TREEBOOK