Document domain parameter of wxTranslations::GetTranslatedString().
[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 // 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_LISTBOOK
18
19 #include "wx/xrc/xh_listbk.h"
20
21 #ifndef WX_PRECOMP
22 #include "wx/log.h"
23 #include "wx/sizer.h"
24 #endif
25
26 #include "wx/listbook.h"
27 #include "wx/imaglist.h"
28
29 IMPLEMENT_DYNAMIC_CLASS(wxListbookXmlHandler, wxXmlResourceHandler)
30
31 wxListbookXmlHandler::wxListbookXmlHandler()
32 :wxXmlResourceHandler(),
33 m_isInside(false),
34 m_listbook(NULL)
35 {
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);
41
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
48 AddWindowStyles();
49 }
50
51 wxObject *wxListbookXmlHandler::DoCreateResource()
52 {
53 if (m_class == wxT("listbookpage"))
54 {
55 wxXmlNode *n = GetParamNode(wxT("object"));
56
57 if ( !n )
58 n = GetParamNode(wxT("object_ref"));
59
60 if (n)
61 {
62 bool old_ins = m_isInside;
63 m_isInside = false;
64 wxObject *item = CreateResFromNode(n, m_listbook, NULL);
65 m_isInside = old_ins;
66 wxWindow *wnd = wxDynamicCast(item, wxWindow);
67
68 if (wnd)
69 {
70 m_listbook->AddPage(wnd, GetText(wxT("label")),
71 GetBool(wxT("selected")));
72 if ( HasParam(wxT("bitmap")) )
73 {
74 wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER);
75 wxImageList *imgList = m_listbook->GetImageList();
76 if ( imgList == NULL )
77 {
78 imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() );
79 m_listbook->AssignImageList( imgList );
80 }
81 int imgIndex = imgList->Add(bmp);
82 m_listbook->SetPageImage(m_listbook->GetPageCount()-1, imgIndex );
83 }
84 else if ( HasParam(wxT("image")) )
85 {
86 if ( m_listbook->GetImageList() )
87 {
88 m_listbook->SetPageImage(m_listbook->GetPageCount()-1,
89 GetLong(wxT("image")) );
90 }
91 else // image without image list?
92 {
93 ReportError(n, "image can only be used in conjunction "
94 "with imagelist");
95 }
96 }
97 }
98 else
99 {
100 ReportError(n, "listbookpage child must be a window");
101 }
102 return wnd;
103 }
104 else
105 {
106 ReportError("listbookpage must have a window child");
107 return NULL;
108 }
109 }
110
111 else
112 {
113 XRC_MAKE_INSTANCE(nb, wxListbook)
114
115 nb->Create(m_parentAsWindow,
116 GetID(),
117 GetPosition(), GetSize(),
118 GetStyle(wxT("style")),
119 GetName());
120
121 wxImageList *imagelist = GetImageList();
122 if ( imagelist )
123 nb->AssignImageList(imagelist);
124
125 wxListbook *old_par = m_listbook;
126 m_listbook = nb;
127 bool old_ins = m_isInside;
128 m_isInside = true;
129 CreateChildren(m_listbook, true/*only this handler*/);
130 m_isInside = old_ins;
131 m_listbook = old_par;
132
133 return nb;
134 }
135 }
136
137 bool wxListbookXmlHandler::CanHandle(wxXmlNode *node)
138 {
139 return ((!m_isInside && IsOfClass(node, wxT("wxListbook"))) ||
140 (m_isInside && IsOfClass(node, wxT("listbookpage"))));
141 }
142
143 #endif // wxUSE_XRC && wxUSE_LISTBOOK