Debian Codegraph @

wxcrafter/xrc_handlers/myxh_toolbk.cpp

raw
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_toolbk.cpp
3 // Purpose: XRC resource for wxToolbook
4 // Author: Andrea Zanellato
5 // Created: 2009/12/12
6 // Copyright: (c) 2010 wxWidgets development team
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 // For compilers that support precompilation, includes "wx.h".
11 #include "myxh_toolbk.h"
12 #include "wx/wxprec.h"
13
14 #if wxUSE_XRC && wxUSE_TOOLBOOK
15
16 #include "wx/log.h"
17 #include "wx/sizer.h"
18
19 #include <wx/imaglist.h>
20 #include <wx/toolbook.h>
21
22 MYwxToolbookXmlHandler::MYwxToolbookXmlHandler()
23 : wxXmlResourceHandler()
24 , m_isInside(false)
25 , m_toolbook(NULL)
26 {
27 XRC_ADD_STYLE(wxBK_DEFAULT);
28 XRC_ADD_STYLE(wxBK_TOP);
29 XRC_ADD_STYLE(wxBK_BOTTOM);
30 XRC_ADD_STYLE(wxBK_LEFT);
31 XRC_ADD_STYLE(wxBK_RIGHT);
32
33 #if wxVERSION_NUMBER > 2900
34 XRC_ADD_STYLE(wxTBK_BUTTONBAR);
35 XRC_ADD_STYLE(wxTBK_HORZ_LAYOUT);
36 #endif
37
38 AddWindowStyles();
39 }
40
41 wxObject* MYwxToolbookXmlHandler::DoCreateResource()
42 {
43 if(m_class == wxT("toolbookpage")) {
44 wxXmlNode* n = GetParamNode(wxT("object"));
45
46 if(!n) n = GetParamNode(wxT("object_ref"));
47
48 if(n) {
49 bool old_ins = m_isInside;
50 m_isInside = false;
51 wxObject* item = CreateResFromNode(n, m_toolbook, NULL);
52 m_isInside = old_ins;
53 wxWindow* wnd = wxDynamicCast(item, wxWindow);
54
55 if(wnd) {
56 int imgId = -1;
57
58 if(HasParam(wxT("bitmap"))) {
59 wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER);
60 wxImageList* imgList = m_toolbook->GetImageList();
61 if(imgList == NULL) {
62 imgList = new wxImageList(bmp.GetWidth(), bmp.GetHeight());
63 m_toolbook->AssignImageList(imgList);
64 }
65 imgId = imgList->Add(bmp);
66 } else if(HasParam(wxT("image"))) {
67 if(m_toolbook->GetImageList()) { imgId = (int)GetLong(wxT("image")); }
68 }
69
70 m_toolbook->AddPage(wnd, GetText(wxT("label")), GetBool(wxT("selected")), imgId);
71 }
72 return wnd;
73 } else {
74 return NULL;
75 }
76 }
77
78 else {
79 XRC_MAKE_INSTANCE(nb, wxToolbook)
80
81 nb->Create(m_parentAsWindow, GetID(), GetPosition(), GetSize(), GetStyle(wxT("style")), GetName());
82
83 wxToolbook* old_par = m_toolbook;
84 m_toolbook = nb;
85 bool old_ins = m_isInside;
86 m_isInside = true;
87 CreateChildren(m_toolbook, true /*only this handler*/);
88 m_isInside = old_ins;
89 m_toolbook = old_par;
90
91 return nb;
92 }
93 }
94
95 bool MYwxToolbookXmlHandler::CanHandle(wxXmlNode* node)
96 {
97 return ((!m_isInside && IsOfClass(node, wxT("wxToolbook"))) ||
98 (m_isInside && IsOfClass(node, wxT("toolbookpage"))));
99 }
100
101 #endif // wxUSE_XRC && wxUSE_TOOLBOOK