1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_listbk.cpp
3 // Purpose: XRC resource for wxListbook
4 // Author: Vaclav Slavik
6 // Copyright: (c) 2000 Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
17 #if wxUSE_XRC && wxUSE_LISTBOOK
19 #include "wx/xrc/xh_listbk.h"
26 #include "wx/listbook.h"
27 #include "wx/imaglist.h"
29 IMPLEMENT_DYNAMIC_CLASS(wxListbookXmlHandler
, wxXmlResourceHandler
)
31 wxListbookXmlHandler::wxListbookXmlHandler()
32 :wxXmlResourceHandler(),
36 XRC_ADD_STYLE(wxBK_DEFAULT
);
37 XRC_ADD_STYLE(wxBK_LEFT
);
38 XRC_ADD_STYLE(wxBK_RIGHT
);
39 XRC_ADD_STYLE(wxBK_TOP
);
40 XRC_ADD_STYLE(wxBK_BOTTOM
);
42 XRC_ADD_STYLE(wxLB_DEFAULT
);
43 XRC_ADD_STYLE(wxLB_LEFT
);
44 XRC_ADD_STYLE(wxLB_RIGHT
);
45 XRC_ADD_STYLE(wxLB_TOP
);
46 XRC_ADD_STYLE(wxLB_BOTTOM
);
51 wxObject
*wxListbookXmlHandler::DoCreateResource()
53 if (m_class
== wxT("listbookpage"))
55 wxXmlNode
*n
= GetParamNode(wxT("object"));
58 n
= GetParamNode(wxT("object_ref"));
62 bool old_ins
= m_isInside
;
64 wxObject
*item
= CreateResFromNode(n
, m_listbook
, NULL
);
66 wxWindow
*wnd
= wxDynamicCast(item
, wxWindow
);
70 m_listbook
->AddPage(wnd
, GetText(wxT("label")),
71 GetBool(wxT("selected")));
72 if ( HasParam(wxT("bitmap")) )
74 wxBitmap bmp
= GetBitmap(wxT("bitmap"), wxART_OTHER
);
75 wxImageList
*imgList
= m_listbook
->GetImageList();
76 if ( imgList
== NULL
)
78 imgList
= new wxImageList( bmp
.GetWidth(), bmp
.GetHeight() );
79 m_listbook
->AssignImageList( imgList
);
81 int imgIndex
= imgList
->Add(bmp
);
82 m_listbook
->SetPageImage(m_listbook
->GetPageCount()-1, imgIndex
);
84 else if ( HasParam(wxT("image")) )
86 if ( m_listbook
->GetImageList() )
88 m_listbook
->SetPageImage(m_listbook
->GetPageCount()-1,
89 GetLong(wxT("image")) );
91 else // image without image list?
93 ReportError(n
, "image can only be used in conjunction "
100 ReportError(n
, "listbookpage child must be a window");
106 ReportError("listbookpage must have a window child");
113 XRC_MAKE_INSTANCE(nb
, wxListbook
)
115 nb
->Create(m_parentAsWindow
,
117 GetPosition(), GetSize(),
118 GetStyle(wxT("style")),
121 wxImageList
*imagelist
= GetImageList();
123 nb
->AssignImageList(imagelist
);
125 wxListbook
*old_par
= m_listbook
;
127 bool old_ins
= m_isInside
;
129 CreateChildren(m_listbook
, true/*only this handler*/);
130 m_isInside
= old_ins
;
131 m_listbook
= old_par
;
137 bool wxListbookXmlHandler::CanHandle(wxXmlNode
*node
)
139 return ((!m_isInside
&& IsOfClass(node
, wxT("wxListbook"))) ||
140 (m_isInside
&& IsOfClass(node
, wxT("listbookpage"))));
143 #endif // wxUSE_XRC && wxUSE_LISTBOOK