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