]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_listbk.cpp
Minor source cleaning.
[wxWidgets.git] / src / xrc / xh_listbk.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_listbk.cpp
3 // Purpose: XRC resource for wxListbook
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_LISTBOOK
19
20 #include "wx/xrc/xh_listbk.h"
21
22 #ifndef WX_PRECOMP
23 #include "wx/log.h"
24 #endif
25
26 #include "wx/listbook.h"
27 #include "wx/imaglist.h"
28 #include "wx/sizer.h"
29
30 IMPLEMENT_DYNAMIC_CLASS(wxListbookXmlHandler, wxXmlResourceHandler)
31
32 wxListbookXmlHandler::wxListbookXmlHandler()
33 : wxXmlResourceHandler(), m_isInside(false), m_listbook(NULL)
34 {
35 XRC_ADD_STYLE(wxBK_DEFAULT);
36 XRC_ADD_STYLE(wxBK_LEFT);
37 XRC_ADD_STYLE(wxBK_RIGHT);
38 XRC_ADD_STYLE(wxBK_TOP);
39 XRC_ADD_STYLE(wxBK_BOTTOM);
40
41 #if WXWIN_COMPATIBILITY_2_6
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);
47 #endif
48
49 AddWindowStyles();
50 }
51
52 wxObject *wxListbookXmlHandler::DoCreateResource()
53 {
54 if (m_class == wxT("listbookpage"))
55 {
56 wxXmlNode *n = GetParamNode(wxT("object"));
57
58 if ( !n )
59 n = GetParamNode(wxT("object_ref"));
60
61 if (n)
62 {
63 bool old_ins = m_isInside;
64 m_isInside = false;
65 wxObject *item = CreateResFromNode(n, m_listbook, NULL);
66 m_isInside = old_ins;
67 wxWindow *wnd = wxDynamicCast(item, wxWindow);
68
69 if (wnd)
70 {
71 m_listbook->AddPage(wnd, GetText(wxT("label")),
72 GetBool(wxT("selected")));
73 if ( HasParam(wxT("bitmap")) )
74 {
75 wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER);
76 wxImageList *imgList = m_listbook->GetImageList();
77 if ( imgList == NULL )
78 {
79 imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() );
80 m_listbook->AssignImageList( imgList );
81 }
82 int imgIndex = imgList->Add(bmp);
83 m_listbook->SetPageImage(m_listbook->GetPageCount()-1, imgIndex );
84 }
85 }
86 else
87 wxLogError(wxT("Error in resource."));
88 return wnd;
89 }
90 else
91 {
92 wxLogError(wxT("Error in resource: no control within listbook's <page> tag."));
93 return NULL;
94 }
95 }
96
97 else
98 {
99 XRC_MAKE_INSTANCE(nb, wxListbook)
100
101 nb->Create(m_parentAsWindow,
102 GetID(),
103 GetPosition(), GetSize(),
104 GetStyle(wxT("style")),
105 GetName());
106
107 wxListbook *old_par = m_listbook;
108 m_listbook = nb;
109 bool old_ins = m_isInside;
110 m_isInside = true;
111 CreateChildren(m_listbook, true/*only this handler*/);
112 m_isInside = old_ins;
113 m_listbook = old_par;
114
115 return nb;
116 }
117 }
118
119 bool wxListbookXmlHandler::CanHandle(wxXmlNode *node)
120 {
121 return ((!m_isInside && IsOfClass(node, wxT("wxListbook"))) ||
122 (m_isInside && IsOfClass(node, wxT("listbookpage"))));
123 }
124
125 #endif // wxUSE_XRC && wxUSE_LISTBOOK