]>
Commit | Line | Data |
---|---|---|
9aaf1192 WS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: 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 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
11 | #pragma implementation "xh_listbk.h" | |
12 | #endif | |
13 | ||
14 | // For compilers that support precompilation, includes "wx.h". | |
15 | #include "wx/wxprec.h" | |
16 | ||
17 | #ifdef __BORLANDC__ | |
18 | #pragma hdrstop | |
19 | #endif | |
20 | ||
21 | #if wxUSE_XRC && wxUSE_LISTBOOK | |
22 | ||
23 | #include "wx/xrc/xh_listbk.h" | |
24 | ||
25 | #include "wx/log.h" | |
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(wxLB_LEFT); | |
36 | XRC_ADD_STYLE(wxLB_RIGHT); | |
37 | XRC_ADD_STYLE(wxLB_TOP); | |
38 | XRC_ADD_STYLE(wxLB_BOTTOM); | |
39 | AddWindowStyles(); | |
40 | } | |
41 | ||
42 | wxObject *wxListbookXmlHandler::DoCreateResource() | |
43 | { | |
44 | if (m_class == wxT("listbookpage")) | |
45 | { | |
46 | wxXmlNode *n = GetParamNode(wxT("object")); | |
47 | ||
48 | if ( !n ) | |
49 | n = GetParamNode(wxT("object_ref")); | |
50 | ||
51 | if (n) | |
52 | { | |
53 | bool old_ins = m_isInside; | |
54 | m_isInside = false; | |
55 | wxObject *item = CreateResFromNode(n, m_listbook, NULL); | |
56 | m_isInside = old_ins; | |
57 | wxWindow *wnd = wxDynamicCast(item, wxWindow); | |
58 | ||
59 | if (wnd) | |
60 | { | |
61 | m_listbook->AddPage(wnd, GetText(wxT("label")), | |
62 | GetBool(wxT("selected"))); | |
63 | if ( HasParam(wxT("bitmap")) ) | |
64 | { | |
65 | wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER); | |
66 | wxImageList *imgList = m_listbook->GetImageList(); | |
67 | if ( imgList == NULL ) | |
68 | { | |
69 | imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() ); | |
70 | m_listbook->AssignImageList( imgList ); | |
71 | } | |
72 | int imgIndex = imgList->Add(bmp); | |
73 | m_listbook->SetPageImage(m_listbook->GetPageCount()-1, imgIndex ); | |
74 | } | |
75 | } | |
76 | else | |
77 | wxLogError(wxT("Error in resource.")); | |
78 | return wnd; | |
79 | } | |
80 | else | |
81 | { | |
82 | wxLogError(wxT("Error in resource: no control within listbook's <page> tag.")); | |
83 | return NULL; | |
84 | } | |
85 | } | |
86 | ||
87 | else | |
88 | { | |
89 | XRC_MAKE_INSTANCE(nb, wxListbook) | |
90 | ||
91 | nb->Create(m_parentAsWindow, | |
92 | GetID(), | |
93 | GetPosition(), GetSize(), | |
94 | GetStyle(wxT("style")), | |
95 | GetName()); | |
96 | ||
97 | wxListbook *old_par = m_listbook; | |
98 | m_listbook = nb; | |
99 | bool old_ins = m_isInside; | |
100 | m_isInside = true; | |
101 | CreateChildren(m_listbook, true/*only this handler*/); | |
102 | m_isInside = old_ins; | |
103 | m_listbook = old_par; | |
104 | ||
105 | return nb; | |
106 | } | |
107 | } | |
108 | ||
109 | bool wxListbookXmlHandler::CanHandle(wxXmlNode *node) | |
110 | { | |
111 | return ((!m_isInside && IsOfClass(node, wxT("wxListbook"))) || | |
112 | (m_isInside && IsOfClass(node, wxT("listbookpage")))); | |
113 | } | |
114 | ||
115 | #endif // wxUSE_XRC && wxUSE_LISTBOOK |