XRC for wxListbook [patch 1152306] and wxChoicebook. Regenerated makefiles.
[wxWidgets.git] / src / xrc / xh_choicbk.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: xh_choicbk.cpp
3 // Purpose: XRC resource for wxChoicebook
4 // Author: Vaclav Slavik
5 // Created: 2000/03/21
6 // Copyright: (c) 2000 Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "xh_choicbk.h"
12 #endif
13
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
16
17 #ifdef __BORLANDC__
18 #pragma hdrstop
19 #endif
20
21 #if wxUSE_XRC && wxUSE_CHOICEBOOK
22
23 #include "wx/xrc/xh_choicbk.h"
24
25 #include "wx/log.h"
26 #include "wx/choicebk.h"
27 #include "wx/imaglist.h"
28 #include "wx/sizer.h"
29
30 IMPLEMENT_DYNAMIC_CLASS(wxChoicebookXmlHandler, wxXmlResourceHandler)
31
32 wxChoicebookXmlHandler::wxChoicebookXmlHandler()
33 : wxXmlResourceHandler(), m_isInside(false), m_choicebook(NULL)
34 {
35 XRC_ADD_STYLE(wxLB_LEFT);
36 XRC_ADD_STYLE(wxLB_RIGHT);
37 XRC_ADD_STYLE(wxLB_TOP);
38 XRC_ADD_STYLE(wxLB_BOTTOM);
39 AddWindowStyles();
40 }
41
42 wxObject *wxChoicebookXmlHandler::DoCreateResource()
43 {
44 if (m_class == wxT("choicebookpage"))
45 {
46 wxXmlNode *n = GetParamNode(wxT("object"));
47
48 if ( !n )
49 n = GetParamNode(wxT("object_ref"));
50
51 if (n)
52 {
53 bool old_ins = m_isInside;
54 m_isInside = false;
55 wxObject *item = CreateResFromNode(n, m_choicebook, NULL);
56 m_isInside = old_ins;
57 wxWindow *wnd = wxDynamicCast(item, wxWindow);
58
59 if (wnd)
60 {
61 m_choicebook->AddPage(wnd, GetText(wxT("label")),
62 GetBool(wxT("selected")));
63 if ( HasParam(wxT("bitmap")) )
64 {
65 wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER);
66 wxImageList *imgList = m_choicebook->GetImageList();
67 if ( imgList == NULL )
68 {
69 imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() );
70 m_choicebook->AssignImageList( imgList );
71 }
72 int imgIndex = imgList->Add(bmp);
73 m_choicebook->SetPageImage(m_choicebook->GetPageCount()-1, imgIndex );
74 }
75 }
76 else
77 wxLogError(wxT("Error in resource."));
78 return wnd;
79 }
80 else
81 {
82 wxLogError(wxT("Error in resource: no control within choicebook's <page> tag."));
83 return NULL;
84 }
85 }
86
87 else
88 {
89 XRC_MAKE_INSTANCE(nb, wxChoicebook)
90
91 nb->Create(m_parentAsWindow,
92 GetID(),
93 GetPosition(), GetSize(),
94 GetStyle(wxT("style")),
95 GetName());
96
97 wxChoicebook *old_par = m_choicebook;
98 m_choicebook = nb;
99 bool old_ins = m_isInside;
100 m_isInside = true;
101 CreateChildren(m_choicebook, true/*only this handler*/);
102 m_isInside = old_ins;
103 m_choicebook = old_par;
104
105 return nb;
106 }
107 }
108
109 bool wxChoicebookXmlHandler::CanHandle(wxXmlNode *node)
110 {
111 return ((!m_isInside && IsOfClass(node, wxT("wxChoicebook"))) ||
112 (m_isInside && IsOfClass(node, wxT("choicebookpage"))));
113 }
114
115 #endif // wxUSE_XRC && wxUSE_CHOICEBOOK