]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_choicbk.cpp
supporting full style mask
[wxWidgets.git] / src / xrc / xh_choicbk.cpp
CommitLineData
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
30IMPLEMENT_DYNAMIC_CLASS(wxChoicebookXmlHandler, wxXmlResourceHandler)
31
32wxChoicebookXmlHandler::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
72f48155
WS
43 XRC_ADD_STYLE(wxCHB_DEFAULT);
44 XRC_ADD_STYLE(wxCHB_LEFT);
45 XRC_ADD_STYLE(wxCHB_RIGHT);
46 XRC_ADD_STYLE(wxCHB_TOP);
47 XRC_ADD_STYLE(wxCHB_BOTTOM);
5a439c1a 48
9aaf1192
WS
49 AddWindowStyles();
50}
51
52wxObject *wxChoicebookXmlHandler::DoCreateResource()
53{
54 if (m_class == wxT("choicebookpage"))
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_choicebook, NULL);
66 m_isInside = old_ins;
67 wxWindow *wnd = wxDynamicCast(item, wxWindow);
68
69 if (wnd)
70 {
71 m_choicebook->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_choicebook->GetImageList();
77 if ( imgList == NULL )
78 {
79 imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() );
80 m_choicebook->AssignImageList( imgList );
81 }
82 int imgIndex = imgList->Add(bmp);
83 m_choicebook->SetPageImage(m_choicebook->GetPageCount()-1, imgIndex );
84 }
326462ae
VZ
85 else if ( HasParam(wxT("image")) )
86 {
87 if ( m_choicebook->GetImageList() )
88 {
89 m_choicebook->SetPageImage(m_choicebook->GetPageCount()-1,
90 GetLong(wxT("image")) );
91 }
92 else // image without image list?
93 {
94 ReportError(n, "image can only be used in conjunction "
95 "with imagelist");
96 }
97 }
9aaf1192
WS
98 }
99 else
819559b2
VS
100 {
101 ReportError(n, "choicebookpage child must be a window");
102 }
9aaf1192
WS
103 return wnd;
104 }
105 else
106 {
819559b2 107 ReportError("choicebookpage must have a window child");
9aaf1192
WS
108 return NULL;
109 }
110 }
111
112 else
113 {
114 XRC_MAKE_INSTANCE(nb, wxChoicebook)
115
116 nb->Create(m_parentAsWindow,
117 GetID(),
118 GetPosition(), GetSize(),
119 GetStyle(wxT("style")),
120 GetName());
121
326462ae
VZ
122 wxImageList *imagelist = GetImageList();
123 if ( imagelist )
124 nb->AssignImageList(imagelist);
125
9aaf1192
WS
126 wxChoicebook *old_par = m_choicebook;
127 m_choicebook = nb;
128 bool old_ins = m_isInside;
129 m_isInside = true;
130 CreateChildren(m_choicebook, true/*only this handler*/);
131 m_isInside = old_ins;
132 m_choicebook = old_par;
133
134 return nb;
135 }
136}
137
138bool wxChoicebookXmlHandler::CanHandle(wxXmlNode *node)
139{
140 return ((!m_isInside && IsOfClass(node, wxT("wxChoicebook"))) ||
141 (m_isInside && IsOfClass(node, wxT("choicebookpage"))));
142}
143
144#endif // wxUSE_XRC && wxUSE_CHOICEBOOK