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