+int wxBookCtrlBase::FindPage(const wxWindow* page) const
+{
+ const size_t nCount = m_pages.size();
+ for ( size_t nPage = 0; nPage < nCount; nPage++ )
+ {
+ if ( m_pages[nPage] == page )
+ return (int)nPage;
+ }
+
+ return wxNOT_FOUND;
+}
+
+bool wxBookCtrlBase::DoSetSelectionAfterInsertion(size_t n, bool bSelect)
+{
+ if ( bSelect )
+ SetSelection(n);
+ else if ( m_selection == wxNOT_FOUND )
+ ChangeSelection(0);
+ else // We're not going to select this page.
+ return false;
+
+ // Return true to indicate that we selected this page.
+ return true;
+}
+
+void wxBookCtrlBase::DoSetSelectionAfterRemoval(size_t n)
+{
+ if ( m_selection >= (int)n )
+ {
+ // ensure that the selection is valid
+ int sel;
+ if ( GetPageCount() == 0 )
+ sel = wxNOT_FOUND;
+ else
+ sel = m_selection ? m_selection - 1 : 0;
+
+ // if deleting current page we shouldn't try to hide it
+ m_selection = m_selection == (int)n ? wxNOT_FOUND
+ : m_selection - 1;
+
+ if ( sel != wxNOT_FOUND && sel != m_selection )
+ SetSelection(sel);
+ }
+}
+
+int wxBookCtrlBase::DoSetSelection(size_t n, int flags)
+{
+ wxCHECK_MSG( n < GetPageCount(), wxNOT_FOUND,
+ wxT("invalid page index in wxBookCtrlBase::DoSetSelection()") );
+
+ const int oldSel = GetSelection();
+
+ if ( n != (size_t)oldSel )
+ {
+ wxBookCtrlEvent *event = CreatePageChangingEvent();
+ bool allowed = false;
+
+ if ( flags & SetSelection_SendEvent )
+ {
+ event->SetSelection(n);
+ event->SetOldSelection(oldSel);
+ event->SetEventObject(this);
+
+ allowed = !GetEventHandler()->ProcessEvent(*event) || event->IsAllowed();
+ }
+
+ if ( !(flags & SetSelection_SendEvent) || allowed)
+ {
+ if ( oldSel != wxNOT_FOUND )
+ DoShowPage(m_pages[oldSel], false);
+
+ wxWindow *page = m_pages[n];
+ page->SetSize(GetPageRect());
+ DoShowPage(page, true);
+
+ // change selection now to ignore the selection change event
+ UpdateSelectedPage(n);
+
+ if ( flags & SetSelection_SendEvent )
+ {
+ // program allows the page change
+ MakeChangedEvent(*event);
+ (void)GetEventHandler()->ProcessEvent(*event);
+ }
+ }
+
+ delete event;
+ }
+
+ return oldSel;
+}
+
+IMPLEMENT_DYNAMIC_CLASS(wxBookCtrlEvent, wxNotifyEvent)
+