]>
git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_choicbk.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_choicbk.cpp
3 // Purpose: XRC resource for wxChoicebook
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_CHOICEBOOK
19 #include "wx/xrc/xh_choicbk.h"
26 #include "wx/choicebk.h"
27 #include "wx/imaglist.h"
29 IMPLEMENT_DYNAMIC_CLASS(wxChoicebookXmlHandler
, wxXmlResourceHandler
)
31 wxChoicebookXmlHandler::wxChoicebookXmlHandler()
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(wxCHB_DEFAULT
);
43 XRC_ADD_STYLE(wxCHB_LEFT
);
44 XRC_ADD_STYLE(wxCHB_RIGHT
);
45 XRC_ADD_STYLE(wxCHB_TOP
);
46 XRC_ADD_STYLE(wxCHB_BOTTOM
);
51 wxObject
*wxChoicebookXmlHandler::DoCreateResource()
53 if (m_class
== wxT("choicebookpage"))
55 wxXmlNode
*n
= GetParamNode(wxT("object"));
58 n
= GetParamNode(wxT("object_ref"));
62 bool old_ins
= m_isInside
;
64 wxObject
*item
= CreateResFromNode(n
, m_choicebook
, NULL
);
66 wxWindow
*wnd
= wxDynamicCast(item
, wxWindow
);
70 m_choicebook
->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_choicebook
->GetImageList();
76 if ( imgList
== NULL
)
78 imgList
= new wxImageList( bmp
.GetWidth(), bmp
.GetHeight() );
79 m_choicebook
->AssignImageList( imgList
);
81 int imgIndex
= imgList
->Add(bmp
);
82 m_choicebook
->SetPageImage(m_choicebook
->GetPageCount()-1, imgIndex
);
84 else if ( HasParam(wxT("image")) )
86 if ( m_choicebook
->GetImageList() )
88 m_choicebook
->SetPageImage(m_choicebook
->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
, "choicebookpage child must be a window");
106 ReportError("choicebookpage must have a window child");
113 XRC_MAKE_INSTANCE(nb
, wxChoicebook
)
115 nb
->Create(m_parentAsWindow
,
117 GetPosition(), GetSize(),
118 GetStyle(wxT("style")),
121 wxImageList
*imagelist
= GetImageList();
123 nb
->AssignImageList(imagelist
);
125 wxChoicebook
*old_par
= m_choicebook
;
127 bool old_ins
= m_isInside
;
129 CreateChildren(m_choicebook
, true/*only this handler*/);
130 m_isInside
= old_ins
;
131 m_choicebook
= old_par
;
137 bool wxChoicebookXmlHandler::CanHandle(wxXmlNode
*node
)
139 return ((!m_isInside
&& IsOfClass(node
, wxT("wxChoicebook"))) ||
140 (m_isInside
&& IsOfClass(node
, wxT("choicebookpage"))));
143 #endif // wxUSE_XRC && wxUSE_CHOICEBOOK