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