]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_choicbk.cpp
re-renamed DoCreate() to XmDoCreateTLW() to avoid virtual function hiding in other...
[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 // 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_CHOICEBOOK
18
19 #include "wx/xrc/xh_choicbk.h"
20
21 #include "wx/log.h"
22 #include "wx/choicebk.h"
23 #include "wx/imaglist.h"
24 #include "wx/sizer.h"
25
26 IMPLEMENT_DYNAMIC_CLASS(wxChoicebookXmlHandler, wxXmlResourceHandler)
27
28 wxChoicebookXmlHandler::wxChoicebookXmlHandler()
29 : wxXmlResourceHandler(), m_isInside(false), m_choicebook(NULL)
30 {
31 XRC_ADD_STYLE(wxCHB_DEFAULT);
32 XRC_ADD_STYLE(wxCHB_LEFT);
33 XRC_ADD_STYLE(wxCHB_RIGHT);
34 XRC_ADD_STYLE(wxCHB_TOP);
35 XRC_ADD_STYLE(wxCHB_BOTTOM);
36
37 AddWindowStyles();
38 }
39
40 wxObject *wxChoicebookXmlHandler::DoCreateResource()
41 {
42 if (m_class == wxT("choicebookpage"))
43 {
44 wxXmlNode *n = GetParamNode(wxT("object"));
45
46 if ( !n )
47 n = GetParamNode(wxT("object_ref"));
48
49 if (n)
50 {
51 bool old_ins = m_isInside;
52 m_isInside = false;
53 wxObject *item = CreateResFromNode(n, m_choicebook, NULL);
54 m_isInside = old_ins;
55 wxWindow *wnd = wxDynamicCast(item, wxWindow);
56
57 if (wnd)
58 {
59 m_choicebook->AddPage(wnd, GetText(wxT("label")),
60 GetBool(wxT("selected")));
61 if ( HasParam(wxT("bitmap")) )
62 {
63 wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER);
64 wxImageList *imgList = m_choicebook->GetImageList();
65 if ( imgList == NULL )
66 {
67 imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() );
68 m_choicebook->AssignImageList( imgList );
69 }
70 int imgIndex = imgList->Add(bmp);
71 m_choicebook->SetPageImage(m_choicebook->GetPageCount()-1, imgIndex );
72 }
73 }
74 else
75 wxLogError(wxT("Error in resource."));
76 return wnd;
77 }
78 else
79 {
80 wxLogError(wxT("Error in resource: no control within choicebook's <page> tag."));
81 return NULL;
82 }
83 }
84
85 else
86 {
87 XRC_MAKE_INSTANCE(nb, wxChoicebook)
88
89 nb->Create(m_parentAsWindow,
90 GetID(),
91 GetPosition(), GetSize(),
92 GetStyle(wxT("style")),
93 GetName());
94
95 wxChoicebook *old_par = m_choicebook;
96 m_choicebook = nb;
97 bool old_ins = m_isInside;
98 m_isInside = true;
99 CreateChildren(m_choicebook, true/*only this handler*/);
100 m_isInside = old_ins;
101 m_choicebook = old_par;
102
103 return nb;
104 }
105 }
106
107 bool wxChoicebookXmlHandler::CanHandle(wxXmlNode *node)
108 {
109 return ((!m_isInside && IsOfClass(node, wxT("wxChoicebook"))) ||
110 (m_isInside && IsOfClass(node, wxT("choicebookpage"))));
111 }
112
113 #endif // wxUSE_XRC && wxUSE_CHOICEBOOK