1
///////////////////////////////////////////////////////////////////////////////
2
// Name: src/generic/choicbkg.cpp
3
// Purpose: generic implementation of wxChoicebook
4
// Author: Vadim Zeitlin
5
// Modified by: Wlodzimierz ABX Skiba from generic/listbkg.cpp
7
// Copyright: (c) Vadim Zeitlin, Wlodzimierz Skiba
8
// Licence: wxWindows licence
9
///////////////////////////////////////////////////////////////////////////////
11
// ============================================================================
13
// ============================================================================
15
// ----------------------------------------------------------------------------
17
// ----------------------------------------------------------------------------
19
// For compilers that support precompilation, includes "wx.h".
20
#include "wx/wxprec.h"
28
#include "wx/choicebk.h"
31
#include "wx/settings.h"
32
#include "wx/choice.h"
36
#include "wx/imaglist.h"
38
// ----------------------------------------------------------------------------
39
// various wxWidgets macros
40
// ----------------------------------------------------------------------------
42
// check that the page index is valid
43
#define IS_VALID_PAGE(nPage) ((nPage) < GetPageCount())
45
// ----------------------------------------------------------------------------
47
// ----------------------------------------------------------------------------
49
IMPLEMENT_DYNAMIC_CLASS(wxChoicebook, wxBookCtrlBase)
51
wxDEFINE_EVENT( wxEVT_CHOICEBOOK_PAGE_CHANGING, wxBookCtrlEvent );
52
wxDEFINE_EVENT( wxEVT_CHOICEBOOK_PAGE_CHANGED, wxBookCtrlEvent );
54
BEGIN_EVENT_TABLE(wxChoicebook, wxBookCtrlBase)
55
EVT_CHOICE(wxID_ANY, wxChoicebook::OnChoiceSelected)
58
// ============================================================================
59
// wxChoicebook implementation
60
// ============================================================================
62
// ----------------------------------------------------------------------------
63
// wxChoicebook creation
64
// ----------------------------------------------------------------------------
67
wxChoicebook::Create(wxWindow *parent,
74
if ( (style & wxBK_ALIGN_MASK) == wxBK_DEFAULT )
79
// no border for this control, it doesn't look nice together with
81
style &= ~wxBORDER_MASK;
82
style |= wxBORDER_NONE;
84
if ( !wxControl::Create(parent, id, pos, size, style,
85
wxDefaultValidator, name) )
88
m_bookctrl = new wxChoice
96
wxSizer* mainSizer = new wxBoxSizer(IsVertical() ? wxVERTICAL : wxHORIZONTAL);
98
if (style & wxBK_RIGHT || style & wxBK_BOTTOM)
99
mainSizer->Add(0, 0, 1, wxEXPAND, 0);
101
m_controlSizer = new wxBoxSizer(IsVertical() ? wxHORIZONTAL : wxVERTICAL);
102
m_controlSizer->Add(m_bookctrl, 1, (IsVertical() ? wxALIGN_CENTRE_VERTICAL : wxALIGN_CENTRE) |wxGROW, 0);
103
mainSizer->Add(m_controlSizer, 0, (IsVertical() ? (int) wxGROW : (int) wxALIGN_CENTRE_VERTICAL)|wxALL, m_controlMargin);
108
// ----------------------------------------------------------------------------
109
// accessing the pages
110
// ----------------------------------------------------------------------------
112
bool wxChoicebook::SetPageText(size_t n, const wxString& strText)
114
GetChoiceCtrl()->SetString(n, strText);
119
wxString wxChoicebook::GetPageText(size_t n) const
121
return GetChoiceCtrl()->GetString(n);
124
int wxChoicebook::GetPageImage(size_t WXUNUSED(n)) const
129
bool wxChoicebook::SetPageImage(size_t WXUNUSED(n), int WXUNUSED(imageId))
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
140
// ----------------------------------------------------------------------------
141
// miscellaneous other stuff
142
// ----------------------------------------------------------------------------
144
void wxChoicebook::DoSetWindowVariant(wxWindowVariant variant)
146
wxBookCtrlBase::DoSetWindowVariant(variant);
148
m_bookctrl->SetWindowVariant(variant);
151
void wxChoicebook::SetImageList(wxImageList *imageList)
153
// TODO: can be implemented in form of static bitmap near choice control
155
wxBookCtrlBase::SetImageList(imageList);
158
// ----------------------------------------------------------------------------
160
// ----------------------------------------------------------------------------
162
wxBookCtrlEvent* wxChoicebook::CreatePageChangingEvent() const
164
return new wxBookCtrlEvent(wxEVT_CHOICEBOOK_PAGE_CHANGING, m_windowId);
167
void wxChoicebook::MakeChangedEvent(wxBookCtrlEvent &event)
169
event.SetEventType(wxEVT_CHOICEBOOK_PAGE_CHANGED);
172
// ----------------------------------------------------------------------------
173
// adding/removing the pages
174
// ----------------------------------------------------------------------------
177
wxChoicebook::InsertPage(size_t n,
179
const wxString& text,
183
if ( !wxBookCtrlBase::InsertPage(n, page, text, bSelect, imageId) )
186
GetChoiceCtrl()->Insert(text, n);
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 )
192
// one extra page added
194
GetChoiceCtrl()->Select(m_selection);
197
if ( !DoSetSelectionAfterInsertion(n, bSelect) )
203
wxWindow *wxChoicebook::DoRemovePage(size_t page)
205
wxWindow *win = wxBookCtrlBase::DoRemovePage(page);
209
GetChoiceCtrl()->Delete(page);
211
DoSetSelectionAfterRemoval(page);
218
bool wxChoicebook::DeleteAllPages()
220
GetChoiceCtrl()->Clear();
221
return wxBookCtrlBase::DeleteAllPages();
224
// ----------------------------------------------------------------------------
225
// wxChoicebook events
226
// ----------------------------------------------------------------------------
228
void wxChoicebook::OnChoiceSelected(wxCommandEvent& eventChoice)
230
if ( eventChoice.GetEventObject() != m_bookctrl )
236
const int selNew = eventChoice.GetSelection();
238
if ( selNew == m_selection )
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
246
SetSelection(selNew);
248
// change wasn't allowed, return to previous state
249
if (m_selection != selNew)
250
GetChoiceCtrl()->Select(m_selection);
253
#endif // wxUSE_CHOICEBOOK