]>
Commit | Line | Data |
---|---|---|
9aaf1192 | 1 | ///////////////////////////////////////////////////////////////////////////// |
2ddb4d13 | 2 | // Name: src/xrc/xh_choicbk.cpp |
9aaf1192 WS |
3 | // Purpose: XRC resource for wxChoicebook |
4 | // Author: Vaclav Slavik | |
5 | // Created: 2000/03/21 | |
2ddb4d13 | 6 | // RCS-ID: $Id$ |
9aaf1192 WS |
7 | // Copyright: (c) 2000 Vaclav Slavik |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
9aaf1192 WS |
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 | ||
e4db172a WS |
22 | #ifndef WX_PRECOMP |
23 | #include "wx/log.h" | |
ed2fbeb8 | 24 | #include "wx/sizer.h" |
e4db172a WS |
25 | #endif |
26 | ||
9aaf1192 WS |
27 | #include "wx/choicebk.h" |
28 | #include "wx/imaglist.h" | |
9aaf1192 WS |
29 | |
30 | IMPLEMENT_DYNAMIC_CLASS(wxChoicebookXmlHandler, wxXmlResourceHandler) | |
31 | ||
32 | wxChoicebookXmlHandler::wxChoicebookXmlHandler() | |
ed2fbeb8 WS |
33 | :wxXmlResourceHandler(), |
34 | m_isInside(false), | |
35 | m_choicebook(NULL) | |
9aaf1192 | 36 | { |
2ddb4d13 WS |
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 | |
72f48155 WS |
44 | XRC_ADD_STYLE(wxCHB_DEFAULT); |
45 | XRC_ADD_STYLE(wxCHB_LEFT); | |
46 | XRC_ADD_STYLE(wxCHB_RIGHT); | |
47 | XRC_ADD_STYLE(wxCHB_TOP); | |
48 | XRC_ADD_STYLE(wxCHB_BOTTOM); | |
2ddb4d13 | 49 | #endif |
5a439c1a | 50 | |
9aaf1192 WS |
51 | AddWindowStyles(); |
52 | } | |
53 | ||
54 | wxObject *wxChoicebookXmlHandler::DoCreateResource() | |
55 | { | |
56 | if (m_class == wxT("choicebookpage")) | |
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_choicebook, NULL); | |
68 | m_isInside = old_ins; | |
69 | wxWindow *wnd = wxDynamicCast(item, wxWindow); | |
70 | ||
71 | if (wnd) | |
72 | { | |
73 | m_choicebook->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_choicebook->GetImageList(); | |
79 | if ( imgList == NULL ) | |
80 | { | |
81 | imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() ); | |
82 | m_choicebook->AssignImageList( imgList ); | |
83 | } | |
84 | int imgIndex = imgList->Add(bmp); | |
85 | m_choicebook->SetPageImage(m_choicebook->GetPageCount()-1, imgIndex ); | |
86 | } | |
87 | } | |
88 | else | |
819559b2 VS |
89 | { |
90 | ReportError(n, "choicebookpage child must be a window"); | |
91 | } | |
9aaf1192 WS |
92 | return wnd; |
93 | } | |
94 | else | |
95 | { | |
819559b2 | 96 | ReportError("choicebookpage must have a window child"); |
9aaf1192 WS |
97 | return NULL; |
98 | } | |
99 | } | |
100 | ||
101 | else | |
102 | { | |
103 | XRC_MAKE_INSTANCE(nb, wxChoicebook) | |
104 | ||
105 | nb->Create(m_parentAsWindow, | |
106 | GetID(), | |
107 | GetPosition(), GetSize(), | |
108 | GetStyle(wxT("style")), | |
109 | GetName()); | |
110 | ||
111 | wxChoicebook *old_par = m_choicebook; | |
112 | m_choicebook = nb; | |
113 | bool old_ins = m_isInside; | |
114 | m_isInside = true; | |
115 | CreateChildren(m_choicebook, true/*only this handler*/); | |
116 | m_isInside = old_ins; | |
117 | m_choicebook = old_par; | |
118 | ||
119 | return nb; | |
120 | } | |
121 | } | |
122 | ||
123 | bool wxChoicebookXmlHandler::CanHandle(wxXmlNode *node) | |
124 | { | |
125 | return ((!m_isInside && IsOfClass(node, wxT("wxChoicebook"))) || | |
126 | (m_isInside && IsOfClass(node, wxT("choicebookpage")))); | |
127 | } | |
128 | ||
129 | #endif // wxUSE_XRC && wxUSE_CHOICEBOOK |