]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_treebk.cpp
Improve wxCollapsiblePane appearance under OS X.
[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
VZ
28
29IMPLEMENT_DYNAMIC_CLASS(wxTreebookXmlHandler, wxXmlResourceHandler)
30
31wxTreebookXmlHandler::wxTreebookXmlHandler()
1f00af0e
VZ
32 : wxXmlResourceHandler(),
33 m_tbk(NULL),
34 m_isInside(false)
eca15c0d 35{
2ddb4d13
WS
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);
eca15c0d
VZ
41
42 AddWindowStyles();
43}
44
45bool wxTreebookXmlHandler::CanHandle(wxXmlNode *node)
46{
47 return ((!m_isInside && IsOfClass(node, wxT("wxTreebook"))) ||
48 (m_isInside && IsOfClass(node, wxT("treebookpage"))));
49}
50
51
52wxObject *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
326462ae
VZ
64 wxImageList *imagelist = GetImageList();
65 if ( imagelist )
66 tbk->AssignImageList(imagelist);
67
eca15c0d
VZ
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 m_treeContext = old_treeContext;
80 m_isInside = old_ins;
81 m_tbk = old_par;
82
83 return tbk;
84 }
85
86// else ( m_class == wxT("treebookpage") )
87 wxXmlNode *n = GetParamNode(wxT("object"));
88 wxWindow *wnd = NULL;
89
90 if ( !n )
91 n = GetParamNode(wxT("object_ref"));
92
93 if (n)
94 {
95 bool old_ins = m_isInside;
96 m_isInside = false;
97 wxObject *item = CreateResFromNode(n, m_tbk, NULL);
98 m_isInside = old_ins;
99 wnd = wxDynamicCast(item, wxWindow);
100
101 if (wnd == NULL && item != NULL)
819559b2
VS
102 {
103 ReportError(n, "treebookpage child must be a window");
104 }
eca15c0d
VZ
105 }
106
107 size_t depth = GetLong( wxT("depth") );
2ddb4d13 108
b4a980f4 109 if( depth <= m_treeContext.GetCount() )
eca15c0d
VZ
110 {
111 // first prepare the icon
112 int imgIndex = wxNOT_FOUND;
113 if ( HasParam(wxT("bitmap")) )
114 {
115 wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER);
116 wxImageList *imgList = m_tbk->GetImageList();
117 if ( imgList == NULL )
118 {
119 imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() );
120 m_tbk->AssignImageList( imgList );
121 }
122 imgIndex = imgList->Add(bmp);
123 }
326462ae
VZ
124 else if ( HasParam(wxT("image")) )
125 {
126 if ( m_tbk->GetImageList() )
127 {
128 imgIndex = GetLong(wxT("image"));
129 }
130 else // image without image list?
131 {
132 ReportError(n, "image can only be used in conjunction "
133 "with imagelist");
134 }
135 }
eca15c0d
VZ
136
137 // then add the page to the corresponding parent
b4a980f4
VZ
138 if( depth < m_treeContext.GetCount() )
139 m_treeContext.RemoveAt(depth, m_treeContext.GetCount() - depth );
eca15c0d
VZ
140 if( depth == 0)
141 {
142 m_tbk->AddPage(wnd,
143 GetText(wxT("label")), GetBool(wxT("selected")), imgIndex);
144 }
145 else
146 {
b7c542d5 147 m_tbk->InsertSubPage(m_treeContext.Item(depth - 1), wnd,
eca15c0d
VZ
148 GetText(wxT("label")), GetBool(wxT("selected")), imgIndex);
149 }
2ddb4d13 150
eca15c0d 151 m_treeContext.Add( m_tbk->GetPageCount() - 1);
2ddb4d13 152
eca15c0d
VZ
153 }
154 else
819559b2
VS
155 {
156 ReportParamError("depth", "invalid depth");
157 }
158
eca15c0d
VZ
159 return wnd;
160}
161
162#endif // wxUSE_XRC && wxUSE_TREEBOOK