]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_treebk.cpp
Committed forgotten files
[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
22#include "wx/treebook.h"
23#include "wx/imaglist.h"
24#include "wx/log.h"
25
26IMPLEMENT_DYNAMIC_CLASS(wxTreebookXmlHandler, wxXmlResourceHandler)
27
28wxTreebookXmlHandler::wxTreebookXmlHandler()
1f00af0e
VZ
29 : wxXmlResourceHandler(),
30 m_tbk(NULL),
31 m_isInside(false)
eca15c0d 32{
2ddb4d13
WS
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);
eca15c0d
VZ
38
39 AddWindowStyles();
40}
41
42bool wxTreebookXmlHandler::CanHandle(wxXmlNode *node)
43{
44 return ((!m_isInside && IsOfClass(node, wxT("wxTreebook"))) ||
45 (m_isInside && IsOfClass(node, wxT("treebookpage"))));
46}
47
48
49wxObject *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") );
2ddb4d13 99
eca15c0d
VZ
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->AddSubPage(m_treeContext.Item(depth - 1), wnd,
127 GetText(wxT("label")), GetBool(wxT("selected")), imgIndex);
128 }
2ddb4d13 129
eca15c0d 130 m_treeContext.Add( m_tbk->GetPageCount() - 1);
2ddb4d13 131
eca15c0d
VZ
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