| 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: xh_treebk.cpp 68318 2011-07-21 13:50:03Z VZ $ |
| 7 |
// Copyright: (c) 2005 TT-Solutions <[email protected]> |
| 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 "myxh_treebk.h" |
| 21 |
|
| 22 |
#ifndef WX_PRECOMP |
| 23 |
#include "wx/log.h" |
| 24 |
#endif |
| 25 |
|
| 26 |
#include <wx/imaglist.h> |
| 27 |
#include <wx/treebook.h> |
| 28 |
#include <wx/xml/xml.h> |
| 29 |
|
| 30 |
MYwxTreebookXmlHandler::MYwxTreebookXmlHandler() |
| 31 |
: wxXmlResourceHandler() |
| 32 |
, m_tbk(NULL) |
| 33 |
, m_isInside(false) |
| 34 |
{ |
| 35 |
XRC_ADD_STYLE(wxBK_DEFAULT); |
| 36 |
XRC_ADD_STYLE(wxBK_TOP); |
| 37 |
XRC_ADD_STYLE(wxBK_BOTTOM); |
| 38 |
XRC_ADD_STYLE(wxBK_LEFT); |
| 39 |
XRC_ADD_STYLE(wxBK_RIGHT); |
| 40 |
|
| 41 |
AddWindowStyles(); |
| 42 |
} |
| 43 |
|
| 44 |
bool MYwxTreebookXmlHandler::CanHandle(wxXmlNode* node) |
| 45 |
{ |
| 46 |
return ((!m_isInside && IsOfClass(node, wxT("wxTreebook"))) || |
| 47 |
(m_isInside && IsOfClass(node, wxT("treebookpage")))); |
| 48 |
} |
| 49 |
|
| 50 |
wxObject* MYwxTreebookXmlHandler::DoCreateResource() |
| 51 |
{ |
| 52 |
if(m_class == wxT("wxTreebook")) { |
| 53 |
XRC_MAKE_INSTANCE(tbk, wxTreebook) |
| 54 |
|
| 55 |
tbk->Create(m_parentAsWindow, GetID(), GetPosition(), GetSize(), GetStyle(wxT("style")), GetName()); |
| 56 |
|
| 57 |
wxTreebook* old_par = m_tbk; |
| 58 |
m_tbk = tbk; |
| 59 |
|
| 60 |
bool old_ins = m_isInside; |
| 61 |
m_isInside = true; |
| 62 |
|
| 63 |
wxArrayTbkPageIndexes old_treeContext = m_treeContext; |
| 64 |
m_treeContext.Clear(); |
| 65 |
|
| 66 |
CreateChildren(m_tbk, true /*only this handler*/); |
| 67 |
|
| 68 |
wxXmlNode* node = GetParamNode(wxT("object")); |
| 69 |
int pageIndex = 0; |
| 70 |
for(unsigned int i = 0; i < m_tbk->GetPageCount(); i++) { |
| 71 |
if(m_tbk->GetPage(i)) { |
| 72 |
wxXmlNode* child = node->GetChildren(); |
| 73 |
while(child) { |
| 74 |
if(child->GetName() == wxT("expanded") && child->GetNodeContent() == wxT("1")) |
| 75 |
m_tbk->ExpandNode(pageIndex, true); |
| 76 |
|
| 77 |
child = child->GetNext(); |
| 78 |
} |
| 79 |
pageIndex++; |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
m_treeContext = old_treeContext; |
| 84 |
m_isInside = old_ins; |
| 85 |
m_tbk = old_par; |
| 86 |
|
| 87 |
return tbk; |
| 88 |
} |
| 89 |
|
| 90 |
// else ( m_class == wxT("treebookpage") ) |
| 91 |
wxXmlNode* n = GetParamNode(wxT("object")); |
| 92 |
wxWindow* wnd = NULL; |
| 93 |
|
| 94 |
if(!n) n = GetParamNode(wxT("object_ref")); |
| 95 |
|
| 96 |
if(n) { |
| 97 |
bool old_ins = m_isInside; |
| 98 |
m_isInside = false; |
| 99 |
wxObject* item = CreateResFromNode(n, m_tbk, NULL); |
| 100 |
m_isInside = old_ins; |
| 101 |
wnd = wxDynamicCast(item, wxWindow); |
| 102 |
} |
| 103 |
|
| 104 |
size_t depth = GetLong(wxT("depth")); |
| 105 |
|
| 106 |
if(depth <= m_treeContext.GetCount()) { |
| 107 |
// first prepare the icon |
| 108 |
int imgIndex = wxNOT_FOUND; |
| 109 |
if(HasParam(wxT("bitmap"))) { |
| 110 |
wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER); |
| 111 |
wxImageList* imgList = m_tbk->GetImageList(); |
| 112 |
if(imgList == NULL) { |
| 113 |
imgList = new wxImageList(bmp.GetWidth(), bmp.GetHeight()); |
| 114 |
m_tbk->AssignImageList(imgList); |
| 115 |
} |
| 116 |
imgIndex = imgList->Add(bmp); |
| 117 |
} else if(HasParam(wxT("image"))) { |
| 118 |
if(m_tbk->GetImageList()) { |
| 119 |
imgIndex = GetLong(wxT("image")); |
| 120 |
} else // image without image list? |
| 121 |
{ |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
// then add the page to the corresponding parent |
| 126 |
if(depth < m_treeContext.GetCount()) m_treeContext.RemoveAt(depth, m_treeContext.GetCount() - depth); |
| 127 |
if(depth == 0) { |
| 128 |
m_tbk->AddPage(wnd, GetText(wxT("label")), GetBool(wxT("selected")), imgIndex); |
| 129 |
} else { |
| 130 |
m_tbk->InsertSubPage(m_treeContext.Item(depth - 1), wnd, GetText(wxT("label")), GetBool(wxT("selected")), |
| 131 |
imgIndex); |
| 132 |
} |
| 133 |
|
| 134 |
m_treeContext.Add(m_tbk->GetPageCount() - 1); |
| 135 |
|
| 136 |
} else { |
| 137 |
// ReportParamError("depth", "invalid depth"); |
| 138 |
} |
| 139 |
|
| 140 |
return wnd; |
| 141 |
} |
| 142 |
|
| 143 |
#endif // wxUSE_XRC && wxUSE_TREEBOOK |