]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_toolbk.cpp
Fix compilation errors under OSX.
[wxWidgets.git] / src / xrc / xh_toolbk.cpp
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 "wx/wxprec.h"
12
13 #ifdef __BORLANDC__
14 #pragma hdrstop
15 #endif
16
17 #if wxUSE_XRC && wxUSE_TOOLBOOK
18
19 #include "wx/xrc/xh_toolbk.h"
20
21 #ifndef WX_PRECOMP
22 #include "wx/log.h"
23 #include "wx/sizer.h"
24 #endif
25
26 #include "wx/toolbook.h"
27 #include "wx/imaglist.h"
28
29 IMPLEMENT_DYNAMIC_CLASS(wxToolbookXmlHandler, wxXmlResourceHandler)
30
31 wxToolbookXmlHandler::wxToolbookXmlHandler()
32 :wxXmlResourceHandler(),
33 m_isInside(false),
34 m_toolbook(NULL)
35 {
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);
41
42 XRC_ADD_STYLE(wxTBK_BUTTONBAR);
43 XRC_ADD_STYLE(wxTBK_HORZ_LAYOUT);
44
45 AddWindowStyles();
46 }
47
48 wxObject *wxToolbookXmlHandler::DoCreateResource()
49 {
50 if (m_class == wxT("toolbookpage"))
51 {
52 wxXmlNode *n = GetParamNode(wxT("object"));
53
54 if ( !n )
55 n = GetParamNode(wxT("object_ref"));
56
57 if (n)
58 {
59 bool old_ins = m_isInside;
60 m_isInside = false;
61 wxObject *item = CreateResFromNode(n, m_toolbook, NULL);
62 m_isInside = old_ins;
63 wxWindow *wnd = wxDynamicCast(item, wxWindow);
64
65 if (wnd)
66 {
67 int imgId = -1;
68
69 if ( HasParam(wxT("bitmap")) )
70 {
71 wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER);
72 wxImageList *imgList = m_toolbook->GetImageList();
73 if ( imgList == NULL )
74 {
75 imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() );
76 m_toolbook->AssignImageList( imgList );
77 }
78 imgId = imgList->Add(bmp);
79 }
80 else if ( HasParam(wxT("image")) )
81 {
82 if ( m_toolbook->GetImageList() )
83 {
84 imgId = (int)GetLong(wxT("image"));
85 }
86 else // image without image list?
87 {
88 ReportError(n, "image can only be used in conjunction "
89 "with imagelist");
90 }
91 }
92
93 m_toolbook->AddPage(wnd, GetText(wxT("label")),
94 GetBool(wxT("selected")), imgId );
95 }
96 else
97 {
98 ReportError(n, "toolbookpage child must be a window");
99 }
100 return wnd;
101 }
102 else
103 {
104 ReportError("toolbookpage must have a window child");
105 return NULL;
106 }
107 }
108
109 else
110 {
111 XRC_MAKE_INSTANCE(nb, wxToolbook)
112
113 nb->Create( m_parentAsWindow,
114 GetID(),
115 GetPosition(), GetSize(),
116 GetStyle(wxT("style")),
117 GetName() );
118
119 wxImageList *imagelist = GetImageList();
120 if ( imagelist )
121 nb->AssignImageList(imagelist);
122
123 wxToolbook *old_par = m_toolbook;
124 m_toolbook = nb;
125 bool old_ins = m_isInside;
126 m_isInside = true;
127 CreateChildren(m_toolbook, true/*only this handler*/);
128 m_isInside = old_ins;
129 m_toolbook = old_par;
130
131 return nb;
132 }
133 }
134
135 bool wxToolbookXmlHandler::CanHandle(wxXmlNode *node)
136 {
137 return ((!m_isInside && IsOfClass(node, wxT("wxToolbook"))) ||
138 (m_isInside && IsOfClass(node, wxT("toolbookpage"))));
139 }
140
141 #endif // wxUSE_XRC && wxUSE_TOOLBOOK