/[pcsx2_0.9.7]/branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/generic/choicbkg.cpp
ViewVC logotype

Annotation of /branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/generic/choicbkg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (hide annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (10 years ago) by william
Original Path: trunk/3rdparty/wxWidgets/src/generic/choicbkg.cpp
File size: 9665 byte(s)
committing r3113 initial commit again...
1 william 31 ///////////////////////////////////////////////////////////////////////////////
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
6     // Created: 15.09.04
7     // RCS-ID: $Id: choicbkg.cpp 58355 2009-01-24 14:12:59Z VZ $
8     // Copyright: (c) Vadim Zeitlin, Wlodzimierz Skiba
9     // Licence: wxWindows licence
10     ///////////////////////////////////////////////////////////////////////////////
11    
12     // ============================================================================
13     // declarations
14     // ============================================================================
15    
16     // ----------------------------------------------------------------------------
17     // headers
18     // ----------------------------------------------------------------------------
19    
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    
29     #include "wx/choicebk.h"
30    
31     #ifndef WX_PRECOMP
32     #include "wx/settings.h"
33     #include "wx/choice.h"
34     #include "wx/sizer.h"
35     #endif
36    
37     #include "wx/imaglist.h"
38    
39     // ----------------------------------------------------------------------------
40     // various wxWidgets macros
41     // ----------------------------------------------------------------------------
42    
43     // check that the page index is valid
44     #define IS_VALID_PAGE(nPage) ((nPage) < GetPageCount())
45    
46     // ----------------------------------------------------------------------------
47     // event table
48     // ----------------------------------------------------------------------------
49    
50     IMPLEMENT_DYNAMIC_CLASS(wxChoicebook, wxBookCtrlBase)
51     IMPLEMENT_DYNAMIC_CLASS(wxChoicebookEvent, wxNotifyEvent)
52    
53     #if !WXWIN_COMPATIBILITY_EVENT_TYPES
54     const wxEventType wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING = wxNewEventType();
55     const wxEventType wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED = wxNewEventType();
56     #endif
57    
58     BEGIN_EVENT_TABLE(wxChoicebook, wxBookCtrlBase)
59     EVT_CHOICE(wxID_ANY, wxChoicebook::OnChoiceSelected)
60     END_EVENT_TABLE()
61    
62     // ============================================================================
63     // wxChoicebook implementation
64     // ============================================================================
65    
66     // ----------------------------------------------------------------------------
67     // wxChoicebook creation
68     // ----------------------------------------------------------------------------
69    
70     void wxChoicebook::Init()
71     {
72     m_selection = wxNOT_FOUND;
73     }
74    
75     bool
76     wxChoicebook::Create(wxWindow *parent,
77     wxWindowID id,
78     const wxPoint& pos,
79     const wxSize& size,
80     long style,
81     const wxString& name)
82     {
83     if ( (style & wxBK_ALIGN_MASK) == wxBK_DEFAULT )
84     {
85     style |= wxBK_TOP;
86     }
87    
88     // no border for this control, it doesn't look nice together with
89     // wxChoice border
90     style &= ~wxBORDER_MASK;
91     style |= wxBORDER_NONE;
92    
93     if ( !wxControl::Create(parent, id, pos, size, style,
94     wxDefaultValidator, name) )
95     return false;
96    
97     m_bookctrl = new wxChoice
98     (
99     this,
100     wxID_ANY,
101     wxDefaultPosition,
102     wxDefaultSize
103     );
104    
105     wxSizer* mainSizer = new wxBoxSizer(IsVertical() ? wxVERTICAL : wxHORIZONTAL);
106    
107     if (style & wxBK_RIGHT || style & wxBK_BOTTOM)
108     mainSizer->Add(0, 0, 1, wxEXPAND, 0);
109    
110     m_controlSizer = new wxBoxSizer(IsVertical() ? wxHORIZONTAL : wxVERTICAL);
111     m_controlSizer->Add(m_bookctrl, 1, (IsVertical() ? wxALIGN_CENTRE_VERTICAL : wxALIGN_CENTRE) |wxGROW, 0);
112     mainSizer->Add(m_controlSizer, 0, (IsVertical() ? (int) wxGROW : (int) wxALIGN_CENTRE_VERTICAL)|wxALL, m_controlMargin);
113     SetSizer(mainSizer);
114     return true;
115     }
116    
117     // ----------------------------------------------------------------------------
118     // wxChoicebook geometry management
119     // ----------------------------------------------------------------------------
120    
121     wxSize wxChoicebook::GetControllerSize() const
122     {
123     const wxSize sizeClient = GetClientSize(),
124     sizeChoice = m_controlSizer->CalcMin();
125    
126     wxSize size;
127     if ( IsVertical() )
128     {
129     size.x = sizeClient.x;
130     size.y = sizeChoice.y;
131     }
132     else // left/right aligned
133     {
134     size.x = sizeChoice.x;
135     size.y = sizeClient.y;
136     }
137    
138     return size;
139     }
140    
141     wxSize wxChoicebook::CalcSizeFromPage(const wxSize& sizePage) const
142     {
143     // we need to add the size of the choice control and the border between
144     const wxSize sizeChoice = GetControllerSize();
145    
146     wxSize size = sizePage;
147     if ( IsVertical() )
148     {
149     if ( sizeChoice.x > sizePage.x )
150     size.x = sizeChoice.x;
151     size.y += sizeChoice.y + GetInternalBorder();
152     }
153     else // left/right aligned
154     {
155     size.x += sizeChoice.x + GetInternalBorder();
156     if ( sizeChoice.y > sizePage.y )
157     size.y = sizeChoice.y;
158     }
159    
160     return size;
161     }
162    
163    
164     // ----------------------------------------------------------------------------
165     // accessing the pages
166     // ----------------------------------------------------------------------------
167    
168     bool wxChoicebook::SetPageText(size_t n, const wxString& strText)
169     {
170     GetChoiceCtrl()->SetString(n, strText);
171    
172     return true;
173     }
174    
175     wxString wxChoicebook::GetPageText(size_t n) const
176     {
177     return GetChoiceCtrl()->GetString(n);
178     }
179    
180     int wxChoicebook::GetPageImage(size_t WXUNUSED(n)) const
181     {
182     wxFAIL_MSG( _T("wxChoicebook::GetPageImage() not implemented") );
183    
184     return wxNOT_FOUND;
185     }
186    
187     bool wxChoicebook::SetPageImage(size_t WXUNUSED(n), int WXUNUSED(imageId))
188     {
189     wxFAIL_MSG( _T("wxChoicebook::SetPageImage() not implemented") );
190    
191     return false;
192     }
193    
194     // ----------------------------------------------------------------------------
195     // image list stuff
196     // ----------------------------------------------------------------------------
197    
198     void wxChoicebook::SetImageList(wxImageList *imageList)
199     {
200     // TODO: can be implemented in form of static bitmap near choice control
201    
202     wxBookCtrlBase::SetImageList(imageList);
203     }
204    
205     // ----------------------------------------------------------------------------
206     // selection
207     // ----------------------------------------------------------------------------
208    
209     int wxChoicebook::GetSelection() const
210     {
211     return m_selection;
212     }
213    
214     wxBookCtrlBaseEvent* wxChoicebook::CreatePageChangingEvent() const
215     {
216     return new wxChoicebookEvent(wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING, m_windowId);
217     }
218    
219     void wxChoicebook::MakeChangedEvent(wxBookCtrlBaseEvent &event)
220     {
221     event.SetEventType(wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED);
222     }
223    
224     // ----------------------------------------------------------------------------
225     // adding/removing the pages
226     // ----------------------------------------------------------------------------
227    
228     bool
229     wxChoicebook::InsertPage(size_t n,
230     wxWindow *page,
231     const wxString& text,
232     bool bSelect,
233     int imageId)
234     {
235     if ( !wxBookCtrlBase::InsertPage(n, page, text, bSelect, imageId) )
236     return false;
237    
238     GetChoiceCtrl()->Insert(text, n);
239    
240     // if the inserted page is before the selected one, we must update the
241     // index of the selected page
242     if ( int(n) <= m_selection )
243     {
244     // one extra page added
245     m_selection++;
246     GetChoiceCtrl()->Select(m_selection);
247     }
248    
249     // some page should be selected: either this one or the first one if there
250     // is still no selection
251     int selNew = wxNOT_FOUND;
252     if ( bSelect )
253     selNew = n;
254     else if ( m_selection == wxNOT_FOUND )
255     selNew = 0;
256    
257     if ( selNew != m_selection )
258     page->Hide();
259    
260     if ( selNew != wxNOT_FOUND )
261     SetSelection(selNew);
262    
263     return true;
264     }
265    
266     wxWindow *wxChoicebook::DoRemovePage(size_t page)
267     {
268     const size_t page_count = GetPageCount();
269     wxWindow *win = wxBookCtrlBase::DoRemovePage(page);
270    
271     if ( win )
272     {
273     GetChoiceCtrl()->Delete(page);
274    
275     if (m_selection >= (int)page)
276     {
277     // force new sel valid if possible
278     int sel = m_selection - 1;
279     if (page_count == 1)
280     sel = wxNOT_FOUND;
281     else if ((page_count == 2) || (sel == -1))
282     sel = 0;
283    
284     // force sel invalid if deleting current page - don't try to hide it
285     m_selection = (m_selection == (int)page) ? wxNOT_FOUND : m_selection - 1;
286    
287     if ((sel != wxNOT_FOUND) && (sel != m_selection))
288     SetSelection(sel);
289     }
290     }
291    
292     return win;
293     }
294    
295    
296     bool wxChoicebook::DeleteAllPages()
297     {
298     m_selection = wxNOT_FOUND;
299     GetChoiceCtrl()->Clear();
300     return wxBookCtrlBase::DeleteAllPages();
301     }
302    
303     // ----------------------------------------------------------------------------
304     // wxChoicebook events
305     // ----------------------------------------------------------------------------
306    
307     void wxChoicebook::OnChoiceSelected(wxCommandEvent& eventChoice)
308     {
309     if ( eventChoice.GetEventObject() != m_bookctrl )
310     {
311     eventChoice.Skip();
312     return;
313     }
314    
315     const int selNew = eventChoice.GetSelection();
316    
317     if ( selNew == m_selection )
318     {
319     // this event can only come from our own Select(m_selection) below
320     // which we call when the page change is vetoed, so we should simply
321     // ignore it
322     return;
323     }
324    
325     SetSelection(selNew);
326    
327     // change wasn't allowed, return to previous state
328     if (m_selection != selNew)
329     GetChoiceCtrl()->Select(m_selection);
330     }
331    
332     #endif // wxUSE_CHOICEBOOK

  ViewVC Help
Powered by ViewVC 1.1.22