]> git.saurik.com Git - wxWidgets.git/blame - src/generic/choicbkg.cpp
wxRTC: fixed guidelines overwriting adjacent cell borders; corrected capitalisation...
[wxWidgets.git] / src / generic / choicbkg.cpp
CommitLineData
f5e0b4bc 1///////////////////////////////////////////////////////////////////////////////
2ddb4d13 2// Name: src/generic/choicbkg.cpp
f5e0b4bc
WS
3// Purpose: generic implementation of wxChoicebook
4// Author: Vadim Zeitlin
5// Modified by: Wlodzimierz ABX Skiba from generic/listbkg.cpp
6// Created: 15.09.04
f5e0b4bc
WS
7// Copyright: (c) Vadim Zeitlin, Wlodzimierz Skiba
8// Licence: wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
f5e0b4bc
WS
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
26#if wxUSE_CHOICEBOOK
27
f5e0b4bc 28#include "wx/choicebk.h"
9eddec69
WS
29
30#ifndef WX_PRECOMP
31 #include "wx/settings.h"
b36e08d0 32 #include "wx/choice.h"
ed2fbeb8 33 #include "wx/sizer.h"
9eddec69
WS
34#endif
35
f5e0b4bc 36#include "wx/imaglist.h"
f5e0b4bc 37
f5e0b4bc
WS
38// ----------------------------------------------------------------------------
39// various wxWidgets macros
40// ----------------------------------------------------------------------------
41
1f30c176
WS
42// check that the page index is valid
43#define IS_VALID_PAGE(nPage) ((nPage) < GetPageCount())
44
45// ----------------------------------------------------------------------------
46// event table
47// ----------------------------------------------------------------------------
48
2ddb4d13 49IMPLEMENT_DYNAMIC_CLASS(wxChoicebook, wxBookCtrlBase)
f5e0b4bc 50
ce7fe42e
VZ
51wxDEFINE_EVENT( wxEVT_CHOICEBOOK_PAGE_CHANGING, wxBookCtrlEvent );
52wxDEFINE_EVENT( wxEVT_CHOICEBOOK_PAGE_CHANGED, wxBookCtrlEvent );
f5e0b4bc 53
61c083e7 54BEGIN_EVENT_TABLE(wxChoicebook, wxBookCtrlBase)
447325a4 55 EVT_CHOICE(wxID_ANY, wxChoicebook::OnChoiceSelected)
f5e0b4bc
WS
56END_EVENT_TABLE()
57
58// ============================================================================
59// wxChoicebook implementation
60// ============================================================================
61
62// ----------------------------------------------------------------------------
63// wxChoicebook creation
64// ----------------------------------------------------------------------------
65
f5e0b4bc
WS
66bool
67wxChoicebook::Create(wxWindow *parent,
68 wxWindowID id,
69 const wxPoint& pos,
70 const wxSize& size,
71 long style,
72 const wxString& name)
73{
2ddb4d13 74 if ( (style & wxBK_ALIGN_MASK) == wxBK_DEFAULT )
f5e0b4bc 75 {
2ddb4d13 76 style |= wxBK_TOP;
f5e0b4bc
WS
77 }
78
79 // no border for this control, it doesn't look nice together with
80 // wxChoice border
81 style &= ~wxBORDER_MASK;
82 style |= wxBORDER_NONE;
83
84 if ( !wxControl::Create(parent, id, pos, size, style,
85 wxDefaultValidator, name) )
86 return false;
87
2ddb4d13 88 m_bookctrl = new wxChoice
f5e0b4bc
WS
89 (
90 this,
447325a4 91 wxID_ANY,
f5e0b4bc
WS
92 wxDefaultPosition,
93 wxDefaultSize
94 );
95
87cf52d8 96 wxSizer* mainSizer = new wxBoxSizer(IsVertical() ? wxVERTICAL : wxHORIZONTAL);
e0d5d9af
WS
97
98 if (style & wxBK_RIGHT || style & wxBK_BOTTOM)
87cf52d8 99 mainSizer->Add(0, 0, 1, wxEXPAND, 0);
e0d5d9af 100
87cf52d8
JS
101 m_controlSizer = new wxBoxSizer(IsVertical() ? wxHORIZONTAL : wxVERTICAL);
102 m_controlSizer->Add(m_bookctrl, 1, (IsVertical() ? wxALIGN_CENTRE_VERTICAL : wxALIGN_CENTRE) |wxGROW, 0);
f2b29c64 103 mainSizer->Add(m_controlSizer, 0, (IsVertical() ? (int) wxGROW : (int) wxALIGN_CENTRE_VERTICAL)|wxALL, m_controlMargin);
87cf52d8 104 SetSizer(mainSizer);
f5e0b4bc
WS
105 return true;
106}
107
f5e0b4bc
WS
108// ----------------------------------------------------------------------------
109// accessing the pages
110// ----------------------------------------------------------------------------
111
112bool wxChoicebook::SetPageText(size_t n, const wxString& strText)
113{
2ddb4d13 114 GetChoiceCtrl()->SetString(n, strText);
f5e0b4bc
WS
115
116 return true;
117}
118
119wxString wxChoicebook::GetPageText(size_t n) const
120{
2ddb4d13 121 return GetChoiceCtrl()->GetString(n);
f5e0b4bc
WS
122}
123
124int wxChoicebook::GetPageImage(size_t WXUNUSED(n)) const
125{
9f29226d 126 return wxNOT_FOUND;
f5e0b4bc
WS
127}
128
129bool wxChoicebook::SetPageImage(size_t WXUNUSED(n), int WXUNUSED(imageId))
130{
c15cc7fa
VZ
131 // fail silently, the code may be written to use one of several book
132 // classes and call SetPageImage() unconditionally, it's better to just
133 // ignore it (which is the best we can do short of rewriting this class to
134 // use wxBitmapComboBox anyhow) than complain loudly about a rather
135 // harmless problem
f5e0b4bc
WS
136
137 return false;
138}
139
140// ----------------------------------------------------------------------------
64c38b4b 141// miscellaneous other stuff
f5e0b4bc
WS
142// ----------------------------------------------------------------------------
143
64c38b4b
VZ
144void wxChoicebook::DoSetWindowVariant(wxWindowVariant variant)
145{
b725fa9a
KO
146 wxBookCtrlBase::DoSetWindowVariant(variant);
147 if (m_bookctrl)
148 m_bookctrl->SetWindowVariant(variant);
64c38b4b
VZ
149}
150
f5e0b4bc
WS
151void wxChoicebook::SetImageList(wxImageList *imageList)
152{
153 // TODO: can be implemented in form of static bitmap near choice control
154
61c083e7 155 wxBookCtrlBase::SetImageList(imageList);
f5e0b4bc
WS
156}
157
158// ----------------------------------------------------------------------------
159// selection
160// ----------------------------------------------------------------------------
161
3e97a905 162wxBookCtrlEvent* wxChoicebook::CreatePageChangingEvent() const
f5e0b4bc 163{
ce7fe42e 164 return new wxBookCtrlEvent(wxEVT_CHOICEBOOK_PAGE_CHANGING, m_windowId);
deb325e3
VZ
165}
166
3e97a905 167void wxChoicebook::MakeChangedEvent(wxBookCtrlEvent &event)
deb325e3 168{
ce7fe42e 169 event.SetEventType(wxEVT_CHOICEBOOK_PAGE_CHANGED);
f5e0b4bc
WS
170}
171
f5e0b4bc
WS
172// ----------------------------------------------------------------------------
173// adding/removing the pages
174// ----------------------------------------------------------------------------
175
176bool
177wxChoicebook::InsertPage(size_t n,
178 wxWindow *page,
179 const wxString& text,
180 bool bSelect,
181 int imageId)
182{
61c083e7 183 if ( !wxBookCtrlBase::InsertPage(n, page, text, bSelect, imageId) )
f5e0b4bc
WS
184 return false;
185
2ddb4d13 186 GetChoiceCtrl()->Insert(text, n);
f5e0b4bc 187
716dc245
WS
188 // if the inserted page is before the selected one, we must update the
189 // index of the selected page
190 if ( int(n) <= m_selection )
f5e0b4bc 191 {
716dc245
WS
192 // one extra page added
193 m_selection++;
2ddb4d13 194 GetChoiceCtrl()->Select(m_selection);
f5e0b4bc 195 }
716dc245 196
60d5c563 197 if ( !DoSetSelectionAfterInsertion(n, bSelect) )
f5e0b4bc 198 page->Hide();
716dc245 199
f5e0b4bc
WS
200 return true;
201}
202
203wxWindow *wxChoicebook::DoRemovePage(size_t page)
204{
61c083e7 205 wxWindow *win = wxBookCtrlBase::DoRemovePage(page);
bb08a4a1 206
f5e0b4bc
WS
207 if ( win )
208 {
2ddb4d13 209 GetChoiceCtrl()->Delete(page);
bb08a4a1 210
4f9ccec5 211 DoSetSelectionAfterRemoval(page);
f5e0b4bc
WS
212 }
213
214 return win;
215}
216
217
218bool wxChoicebook::DeleteAllPages()
219{
2ddb4d13 220 GetChoiceCtrl()->Clear();
61c083e7 221 return wxBookCtrlBase::DeleteAllPages();
f5e0b4bc
WS
222}
223
224// ----------------------------------------------------------------------------
225// wxChoicebook events
226// ----------------------------------------------------------------------------
227
228void wxChoicebook::OnChoiceSelected(wxCommandEvent& eventChoice)
229{
447325a4
VZ
230 if ( eventChoice.GetEventObject() != m_bookctrl )
231 {
232 eventChoice.Skip();
233 return;
234 }
235
f5e0b4bc
WS
236 const int selNew = eventChoice.GetSelection();
237
238 if ( selNew == m_selection )
239 {
240 // this event can only come from our own Select(m_selection) below
241 // which we call when the page change is vetoed, so we should simply
242 // ignore it
243 return;
244 }
245
bb08a4a1 246 SetSelection(selNew);
f5e0b4bc 247
716dc245
WS
248 // change wasn't allowed, return to previous state
249 if (m_selection != selNew)
2ddb4d13 250 GetChoiceCtrl()->Select(m_selection);
f5e0b4bc
WS
251}
252
253#endif // wxUSE_CHOICEBOOK