Refactor: use wxBookCtrlBase::m_selection in all derived classes.

All book control classes with the exception of wxGTK wxNotebook stored the
currently selected page in m_selection or m_nSelection (or, in wxUniv
wxNotebook case, m_sel) variable. Remove all of them and add m_selection
directly to the base class itself so that it can be reused everywhere.

Closes #12622.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65931 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-10-27 16:54:36 +00:00
parent 7e837615b9
commit 681be2ef80
22 changed files with 139 additions and 246 deletions

View File

@@ -106,7 +106,7 @@ public:
} }
// get the currently selected page or wxNOT_FOUND if none // get the currently selected page or wxNOT_FOUND if none
virtual int GetSelection() const = 0; int GetSelection() const { return m_selection; }
// set/get the title of a page // set/get the title of a page
virtual bool SetPageText(size_t n, const wxString& strText) = 0; virtual bool SetPageText(size_t n, const wxString& strText) = 0;
@@ -181,6 +181,7 @@ public:
// remove all pages and delete them // remove all pages and delete them
virtual bool DeleteAllPages() virtual bool DeleteAllPages()
{ {
m_selection = wxNOT_FOUND;
DoInvalidateBestSize(); DoInvalidateBestSize();
WX_CLEAR_ARRAY(m_pages); WX_CLEAR_ARRAY(m_pages);
return true; return true;
@@ -332,6 +333,11 @@ protected:
// the margin around the choice control // the margin around the choice control
int m_controlMargin; int m_controlMargin;
// The currently selected page (in range 0..m_pages.size()-1 inclusive) or
// wxNOT_FOUND if none (this can normally only be the case for an empty
// control without any pages).
int m_selection;
private: private:
// common part of all ctors // common part of all ctors
@@ -342,6 +348,7 @@ private:
DECLARE_ABSTRACT_CLASS(wxBookCtrlBase) DECLARE_ABSTRACT_CLASS(wxBookCtrlBase)
wxDECLARE_NO_COPY_CLASS(wxBookCtrlBase); wxDECLARE_NO_COPY_CLASS(wxBookCtrlBase);
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };

View File

@@ -39,10 +39,7 @@ wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGI
class WXDLLIMPEXP_CORE wxChoicebook : public wxBookCtrlBase class WXDLLIMPEXP_CORE wxChoicebook : public wxBookCtrlBase
{ {
public: public:
wxChoicebook() wxChoicebook() { }
{
Init();
}
wxChoicebook(wxWindow *parent, wxChoicebook(wxWindow *parent,
wxWindowID id, wxWindowID id,
@@ -51,8 +48,6 @@ public:
long style = 0, long style = 0,
const wxString& name = wxEmptyString) const wxString& name = wxEmptyString)
{ {
Init();
(void)Create(parent, id, pos, size, style, name); (void)Create(parent, id, pos, size, style, name);
} }
@@ -65,7 +60,6 @@ public:
const wxString& name = wxEmptyString); const wxString& name = wxEmptyString);
virtual int GetSelection() const;
virtual bool SetPageText(size_t n, const wxString& strText); virtual bool SetPageText(size_t n, const wxString& strText);
virtual wxString GetPageText(size_t n) const; virtual wxString GetPageText(size_t n) const;
virtual int GetPageImage(size_t n) const; virtual int GetPageImage(size_t n) const;
@@ -102,13 +96,7 @@ protected:
// event handlers // event handlers
void OnChoiceSelected(wxCommandEvent& event); void OnChoiceSelected(wxCommandEvent& event);
// the currently selected page or wxNOT_FOUND if none
int m_selection;
private: private:
// common part of all constructors
void Init();
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS_NO_COPY(wxChoicebook) DECLARE_DYNAMIC_CLASS_NO_COPY(wxChoicebook)
}; };

View File

@@ -65,8 +65,6 @@ public:
int SetSelection(size_t nPage); int SetSelection(size_t nPage);
// cycle thru the tabs // cycle thru the tabs
// void AdvanceSelection(bool bForward = true); // void AdvanceSelection(bool bForward = true);
// get the currently selected page
int GetSelection() const { return m_nSelection; }
// changes selected page without sending events // changes selected page without sending events
int ChangeSelection(size_t nPage); int ChangeSelection(size_t nPage);
@@ -149,8 +147,6 @@ protected:
// helper functions // helper functions
void ChangePage(int nOldSel, int nSel); // change pages void ChangePage(int nOldSel, int nSel); // change pages
int m_nSelection; // the current selection (-1 if none)
wxTabView* m_tabView; wxTabView* m_tabView;
DECLARE_DYNAMIC_CLASS(wxNotebook) DECLARE_DYNAMIC_CLASS(wxNotebook)

View File

@@ -110,6 +110,9 @@ public:
// common part of all ctors // common part of all ctors
void Init(); void Init();
// Called by GTK event handler when the current page is definitely changed.
void GTKOnPageChanged();
// helper function // helper function
wxGtkNotebookPage* GetNotebookPage(int page) const; wxGtkNotebookPage* GetNotebookPage(int page) const;

View File

@@ -39,10 +39,7 @@ wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_CORE, wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING
class WXDLLIMPEXP_CORE wxListbook : public wxBookCtrlBase class WXDLLIMPEXP_CORE wxListbook : public wxBookCtrlBase
{ {
public: public:
wxListbook() wxListbook() { }
{
Init();
}
wxListbook(wxWindow *parent, wxListbook(wxWindow *parent,
wxWindowID id, wxWindowID id,
@@ -51,8 +48,6 @@ public:
long style = 0, long style = 0,
const wxString& name = wxEmptyString) const wxString& name = wxEmptyString)
{ {
Init();
(void)Create(parent, id, pos, size, style, name); (void)Create(parent, id, pos, size, style, name);
} }
@@ -66,7 +61,6 @@ public:
// overridden base class methods // overridden base class methods
virtual int GetSelection() const;
virtual bool SetPageText(size_t n, const wxString& strText); virtual bool SetPageText(size_t n, const wxString& strText);
virtual wxString GetPageText(size_t n) const; virtual wxString GetPageText(size_t n) const;
virtual int GetPageImage(size_t n) const; virtual int GetPageImage(size_t n) const;
@@ -101,13 +95,7 @@ protected:
void OnListSelected(wxListEvent& event); void OnListSelected(wxListEvent& event);
void OnSize(wxSizeEvent& event); void OnSize(wxSizeEvent& event);
// the currently selected page or wxNOT_FOUND if none
int m_selection;
private: private:
// common part of all constructors
void Init();
// this should be called when we need to be relaid out // this should be called when we need to be relaid out
void UpdateSize(); void UpdateSize();

View File

@@ -89,8 +89,6 @@ public:
// selected one (or wxNOT_FOUND on error) // selected one (or wxNOT_FOUND on error)
// NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events // NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events
int SetSelection(size_t nPage); int SetSelection(size_t nPage);
// get the currently selected page
int GetSelection() const { return m_nSelection; }
// changes selected page without sending events // changes selected page without sending events
int ChangeSelection(size_t nPage); int ChangeSelection(size_t nPage);
@@ -199,7 +197,7 @@ protected:
void Init(); void Init();
// hides the currently shown page and shows the given one (if not -1) and // hides the currently shown page and shows the given one (if not -1) and
// updates m_nSelection accordingly // updates m_selection accordingly
void UpdateSelection(int selNew); void UpdateSelection(int selNew);
// remove one page from the notebook, without deleting // remove one page from the notebook, without deleting
@@ -236,8 +234,6 @@ protected:
bool m_hasSubclassedUpdown; bool m_hasSubclassedUpdown;
#endif // __WXWINCE__ #endif // __WXWINCE__
// the current selection (-1 if none)
int m_nSelection;
wxNotebookPageInfoList m_pageInfos; wxNotebookPageInfoList m_pageInfos;

View File

@@ -69,11 +69,6 @@ public:
// changes selected page without sending events // changes selected page without sending events
int ChangeSelection(size_t nPage); int ChangeSelection(size_t nPage);
//
// Get the currently selected page
//
inline int GetSelection(void) const { return m_nSelection; }
// //
// Set/Get the title of a page // Set/Get the title of a page
// //
@@ -193,8 +188,6 @@ protected:
// Helper functions // Helper functions
// //
int m_nSelection; // The current selection (-1 if none)
private: private:
wxArrayLong m_alPageId; wxArrayLong m_alPageId;
int m_nTabSize; // holds the largest tab size int m_nTabSize; // holds the largest tab size

View File

@@ -34,7 +34,7 @@ public:
// ctors // ctors
// ----- // -----
// default for dynamic class // default for dynamic class
wxNotebook(); wxNotebook() { }
// the same arguments as for wxControl (@@@ any special styles?) // the same arguments as for wxControl (@@@ any special styles?)
wxNotebook(wxWindow *parent, wxNotebook(wxWindow *parent,
wxWindowID id, wxWindowID id,
@@ -42,6 +42,7 @@ public:
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = 0, long style = 0,
const wxString& name = wxNotebookNameStr); const wxString& name = wxNotebookNameStr);
{ Create( parent, id, pos, size, style, name ); }
// Create() function // Create() function
bool Create(wxWindow *parent, bool Create(wxWindow *parent,
wxWindowID id, wxWindowID id,
@@ -58,8 +59,6 @@ public:
// selected one (or wxNOT_FOUND on error) // selected one (or wxNOT_FOUND on error)
// NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events // NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events
int SetSelection(size_t nPage) { return DoSetSelection(nPage, SetSelection_SendEvent); } int SetSelection(size_t nPage) { return DoSetSelection(nPage, SetSelection_SendEvent); }
// get the currently selected page
int GetSelection() const { return m_nSelection; }
// changes selected page without sending events // changes selected page without sending events
int ChangeSelection(size_t nPage) { return DoSetSelection(nPage); } int ChangeSelection(size_t nPage) { return DoSetSelection(nPage); }
@@ -135,8 +134,6 @@ protected:
// the icon indices // the icon indices
wxArrayInt m_images; wxArrayInt m_images;
int m_nSelection; // the current selection (-1 if none)
DECLARE_DYNAMIC_CLASS(wxNotebook) DECLARE_DYNAMIC_CLASS(wxNotebook)
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };

View File

@@ -70,7 +70,6 @@ public:
// implement base class virtuals // implement base class virtuals
virtual int GetSelection() const;
virtual bool SetPageText(size_t n, const wxString& strText); virtual bool SetPageText(size_t n, const wxString& strText);
virtual wxString GetPageText(size_t n) const; virtual wxString GetPageText(size_t n) const;
virtual int GetPageImage(size_t n) const; virtual int GetPageImage(size_t n) const;
@@ -110,9 +109,6 @@ protected:
wxBookCtrlEvent* CreatePageChangingEvent() const; wxBookCtrlEvent* CreatePageChangingEvent() const;
void MakeChangedEvent(wxBookCtrlEvent &event); void MakeChangedEvent(wxBookCtrlEvent &event);
// the currently selected page or wxNOT_FOUND if none
int m_selection;
// whether the toolbar needs to be realized // whether the toolbar needs to be realized
bool m_needsRealizing; bool m_needsRealizing;

View File

@@ -126,7 +126,6 @@ public:
// Standard operations inherited from wxBookCtrlBase // Standard operations inherited from wxBookCtrlBase
// ------------------------------------------------- // -------------------------------------------------
virtual int GetSelection() const;
virtual bool SetPageText(size_t n, const wxString& strText); virtual bool SetPageText(size_t n, const wxString& strText);
virtual wxString GetPageText(size_t n) const; virtual wxString GetPageText(size_t n) const;
virtual int GetPageImage(size_t n) const; virtual int GetPageImage(size_t n) const;
@@ -152,9 +151,6 @@ protected:
// array of page ids and page windows // array of page ids and page windows
wxArrayTreeItemIds m_treeIds; wxArrayTreeItemIds m_treeIds;
// the currently selected page or wxNOT_FOUND if none
int m_selection;
// in the situation when m_selection page is not wxNOT_FOUND but page is // in the situation when m_selection page is not wxNOT_FOUND but page is
// NULL this is the first (sub)child that has a non-NULL page // NULL this is the first (sub)child that has a non-NULL page
int m_actualSelection; int m_actualSelection;

View File

@@ -64,7 +64,6 @@ public:
// -------------------------------------- // --------------------------------------
virtual int SetSelection(size_t nPage) { return DoSetSelection(nPage, SetSelection_SendEvent); } virtual int SetSelection(size_t nPage) { return DoSetSelection(nPage, SetSelection_SendEvent); }
virtual int GetSelection() const { return (int) m_sel; }
// changes selected page without sending events // changes selected page without sending events
int ChangeSelection(size_t nPage) { return DoSetSelection(nPage); } int ChangeSelection(size_t nPage) { return DoSetSelection(nPage); }
@@ -210,9 +209,6 @@ protected:
// the pages titles // the pages titles
wxArrayString m_titles; wxArrayString m_titles;
// the current selection
size_t m_sel;
// the spin button to change the pages // the spin button to change the pages
wxSpinButton *m_spinbtn; wxSpinButton *m_spinbtn;

View File

@@ -53,6 +53,7 @@ END_EVENT_TABLE()
void wxBookCtrlBase::Init() void wxBookCtrlBase::Init()
{ {
m_selection = wxNOT_FOUND;
m_bookctrl = NULL; m_bookctrl = NULL;
m_imageList = NULL; m_imageList = NULL;
m_ownsImageList = false; m_ownsImageList = false;

View File

@@ -64,11 +64,6 @@ END_EVENT_TABLE()
// wxChoicebook creation // wxChoicebook creation
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void wxChoicebook::Init()
{
m_selection = wxNOT_FOUND;
}
bool bool
wxChoicebook::Create(wxWindow *parent, wxChoicebook::Create(wxWindow *parent,
wxWindowID id, wxWindowID id,
@@ -165,11 +160,6 @@ void wxChoicebook::SetImageList(wxImageList *imageList)
// selection // selection
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
int wxChoicebook::GetSelection() const
{
return m_selection;
}
wxBookCtrlEvent* wxChoicebook::CreatePageChangingEvent() const wxBookCtrlEvent* wxChoicebook::CreatePageChangingEvent() const
{ {
return new wxBookCtrlEvent(wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING, m_windowId); return new wxBookCtrlEvent(wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING, m_windowId);
@@ -254,7 +244,6 @@ wxWindow *wxChoicebook::DoRemovePage(size_t page)
bool wxChoicebook::DeleteAllPages() bool wxChoicebook::DeleteAllPages()
{ {
m_selection = wxNOT_FOUND;
GetChoiceCtrl()->Clear(); GetChoiceCtrl()->Clear();
return wxBookCtrlBase::DeleteAllPages(); return wxBookCtrlBase::DeleteAllPages();
} }

View File

@@ -85,11 +85,6 @@ END_EVENT_TABLE()
// wxListbook creation // wxListbook creation
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void wxListbook::Init()
{
m_selection = wxNOT_FOUND;
}
bool bool
wxListbook::Create(wxWindow *parent, wxListbook::Create(wxWindow *parent,
wxWindowID id, wxWindowID id,
@@ -311,11 +306,6 @@ void wxListbook::UpdateSelectedPage(size_t newsel)
GetListView()->Focus(newsel); GetListView()->Focus(newsel);
} }
int wxListbook::GetSelection() const
{
return m_selection;
}
wxBookCtrlEvent* wxListbook::CreatePageChangingEvent() const wxBookCtrlEvent* wxListbook::CreatePageChangingEvent() const
{ {
return new wxBookCtrlEvent(wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING, m_windowId); return new wxBookCtrlEvent(wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING, m_windowId);
@@ -411,8 +401,6 @@ bool wxListbook::DeleteAllPages()
if (!wxBookCtrlBase::DeleteAllPages()) if (!wxBookCtrlBase::DeleteAllPages())
return false; return false;
m_selection = -1;
UpdateSize(); UpdateSize();
return true; return true;

View File

@@ -64,7 +64,6 @@ END_EVENT_TABLE()
void wxToolbook::Init() void wxToolbook::Init()
{ {
m_selection = wxNOT_FOUND;
m_needsRealizing = false; m_needsRealizing = false;
} }
@@ -201,11 +200,6 @@ void wxToolbook::SetImageList(wxImageList *imageList)
// selection // selection
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
int wxToolbook::GetSelection() const
{
return m_selection;
}
wxBookCtrlEvent* wxToolbook::CreatePageChangingEvent() const wxBookCtrlEvent* wxToolbook::CreatePageChangingEvent() const
{ {
return new wxBookCtrlEvent(wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGING, m_windowId); return new wxBookCtrlEvent(wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGING, m_windowId);

View File

@@ -556,11 +556,6 @@ bool wxTreebook::SetPageImage(size_t n, int imageId)
return true; return true;
} }
int wxTreebook::GetSelection() const
{
return m_selection;
}
int wxTreebook::DoSetSelection(size_t pagePos, int flags) int wxTreebook::DoSetSelection(size_t pagePos, int flags)
{ {
wxCHECK_MSG( IS_VALID_PAGE(pagePos), wxNOT_FOUND, wxCHECK_MSG( IS_VALID_PAGE(pagePos), wxNOT_FOUND,

View File

@@ -61,10 +61,11 @@ static void event_after(GtkNotebook*, GdkEvent*, wxNotebook*);
extern "C" { extern "C" {
static void static void
switch_page_after(GtkWidget* widget, GtkNotebookPage*, guint, wxNotebook* win) switch_page_after(GtkNotebook* widget, GtkNotebookPage*, guint, wxNotebook* win)
{ {
g_signal_handlers_block_by_func(widget, (void*)switch_page_after, win); g_signal_handlers_block_by_func(widget, (void*)switch_page_after, win);
win->SendPageChangedEvent(win->m_oldSelection);
win->GTKOnPageChanged();
} }
} }
@@ -245,6 +246,8 @@ int wxNotebook::DoSetSelection( size_t page, int flags )
g_signal_handlers_unblock_by_func(m_widget, (void*)switch_page, this); g_signal_handlers_unblock_by_func(m_widget, (void*)switch_page, this);
} }
m_selection = page;
wxNotebookPage *client = GetPage(page); wxNotebookPage *client = GetPage(page);
if ( client ) if ( client )
client->SetFocus(); client->SetFocus();
@@ -252,6 +255,13 @@ int wxNotebook::DoSetSelection( size_t page, int flags )
return selOld; return selOld;
} }
void wxNotebook::GTKOnPageChanged()
{
m_selection = gtk_notebook_get_current_page(GTK_NOTEBOOK(m_widget));
SendPageChangedEvent(m_oldSelection);
}
bool wxNotebook::SetPageText( size_t page, const wxString &text ) bool wxNotebook::SetPageText( size_t page, const wxString &text )
{ {
wxCHECK_MSG(page < GetPageCount(), false, "invalid notebook index"); wxCHECK_MSG(page < GetPageCount(), false, "invalid notebook index");

View File

@@ -107,7 +107,7 @@ static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget),
// make wxNotebook::GetSelection() return the correct (i.e. consistent // make wxNotebook::GetSelection() return the correct (i.e. consistent
// with wxBookCtrlEvent::GetSelection()) value even though the page is // with wxBookCtrlEvent::GetSelection()) value even though the page is
// not really changed in GTK+ // not really changed in GTK+
notebook->m_selection = page; notebook->SetSelection(page);
} }
else else
{ {
@@ -121,7 +121,7 @@ static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget),
// make wxNotebook::GetSelection() return the correct (i.e. consistent // make wxNotebook::GetSelection() return the correct (i.e. consistent
// with wxBookCtrlEvent::GetSelection()) value even though the page is // with wxBookCtrlEvent::GetSelection()) value even though the page is
// not really changed in GTK+ // not really changed in GTK+
notebook->m_selection = page; notebook->SetSelection(page);
notebook->SendPageChangedEvent(old); notebook->SendPageChangedEvent(old);
} }
@@ -292,7 +292,6 @@ void wxNotebook::Init()
m_inSwitchPage = false; m_inSwitchPage = false;
m_imageList = NULL; m_imageList = NULL;
m_selection = -1;
m_themeEnabled = true; m_themeEnabled = true;
} }
@@ -375,8 +374,8 @@ int wxNotebook::GetSelection() const
gpointer cur = notebook->cur_page; gpointer cur = notebook->cur_page;
if ( cur != NULL ) if ( cur != NULL )
{ {
wxConstCast(this, wxNotebook)->m_selection = const_cast<wxNotebook *>(this)->
g_list_index( nb_pages, cur ); SetSelection(g_list_index( nb_pages, cur ));
} }
} }
} }

View File

@@ -240,7 +240,6 @@ const wxNotebookPageInfoList& wxNotebook::GetPageInfos() const
void wxNotebook::Init() void wxNotebook::Init()
{ {
m_imageList = NULL; m_imageList = NULL;
m_nSelection = wxNOT_FOUND;
#if wxUSE_UXTHEME #if wxUSE_UXTHEME
m_hbrBackground = NULL; m_hbrBackground = NULL;
@@ -451,24 +450,24 @@ int wxNotebook::SetSelection(size_t nPage)
{ {
wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") ); wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") );
if ( m_nSelection == wxNOT_FOUND || nPage != (size_t)m_nSelection ) if ( m_selection == wxNOT_FOUND || nPage != (size_t)m_selection )
{ {
if ( SendPageChangingEvent(nPage) ) if ( SendPageChangingEvent(nPage) )
{ {
// program allows the page change // program allows the page change
SendPageChangedEvent(m_nSelection, nPage); SendPageChangedEvent(m_selection, nPage);
TabCtrl_SetCurSel(GetHwnd(), nPage); TabCtrl_SetCurSel(GetHwnd(), nPage);
} }
} }
return m_nSelection; return m_selection;
} }
void wxNotebook::UpdateSelection(int selNew) void wxNotebook::UpdateSelection(int selNew)
{ {
if ( m_nSelection != wxNOT_FOUND ) if ( m_selection != wxNOT_FOUND )
m_pages[m_nSelection]->Show(false); m_pages[m_selection]->Show(false);
if ( selNew != wxNOT_FOUND ) if ( selNew != wxNOT_FOUND )
{ {
@@ -486,16 +485,16 @@ void wxNotebook::UpdateSelection(int selNew)
if ( ::IsWindowVisible(GetHwnd()) ) if ( ::IsWindowVisible(GetHwnd()) )
SetFocus(); SetFocus();
m_nSelection = selNew; m_selection = selNew;
} }
int wxNotebook::ChangeSelection(size_t nPage) int wxNotebook::ChangeSelection(size_t nPage)
{ {
wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") ); wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") );
const int selOld = m_nSelection; const int selOld = m_selection;
if ( m_nSelection == wxNOT_FOUND || nPage != (size_t)m_nSelection ) if ( m_selection == wxNOT_FOUND || nPage != (size_t)m_selection )
{ {
TabCtrl_SetCurSel(GetHwnd(), nPage); TabCtrl_SetCurSel(GetHwnd(), nPage);
@@ -697,7 +696,7 @@ wxNotebookPage *wxNotebook::DoRemovePage(size_t nPage)
if ( m_pages.IsEmpty() ) if ( m_pages.IsEmpty() )
{ {
// no selection any more, the notebook becamse empty // no selection any more, the notebook becamse empty
m_nSelection = wxNOT_FOUND; m_selection = wxNOT_FOUND;
} }
else // notebook still not empty else // notebook still not empty
{ {
@@ -708,22 +707,22 @@ wxNotebookPage *wxNotebook::DoRemovePage(size_t nPage)
// Because it could be that the slection index changed // Because it could be that the slection index changed
// we need to update it. // we need to update it.
// Note: this does not mean the selection it self changed. // Note: this does not mean the selection it self changed.
m_nSelection = selNew; m_selection = selNew;
m_pages[m_nSelection]->Refresh(); m_pages[m_selection]->Refresh();
} }
else if (int(nPage) == m_nSelection) else if (int(nPage) == m_selection)
{ {
// The selection was deleted. // The selection was deleted.
// Determine new selection. // Determine new selection.
if (m_nSelection == int(GetPageCount())) if (m_selection == int(GetPageCount()))
selNew = m_nSelection - 1; selNew = m_selection - 1;
else else
selNew = m_nSelection; selNew = m_selection;
// m_nSelection must be always valid so reset it before calling // m_selection must be always valid so reset it before calling
// SetSelection() // SetSelection()
m_nSelection = wxNOT_FOUND; m_selection = wxNOT_FOUND;
SetSelection(selNew); SetSelection(selNew);
} }
else else
@@ -747,7 +746,7 @@ bool wxNotebook::DeleteAllPages()
TabCtrl_DeleteAllItems(GetHwnd()); TabCtrl_DeleteAllItems(GetHwnd());
m_nSelection = wxNOT_FOUND; m_selection = wxNOT_FOUND;
InvalidateBestSize(); InvalidateBestSize();
return true; return true;
@@ -837,10 +836,10 @@ bool wxNotebook::InsertPage(size_t nPage,
// if the inserted page is before the selected one, we must update the // if the inserted page is before the selected one, we must update the
// index of the selected page // index of the selected page
if ( int(nPage) <= m_nSelection ) if ( int(nPage) <= m_selection )
{ {
// one extra page added // one extra page added
m_nSelection++; m_selection++;
} }
// some page should be selected: either this one or the first one if there // some page should be selected: either this one or the first one if there
@@ -848,7 +847,7 @@ bool wxNotebook::InsertPage(size_t nPage,
int selNew = wxNOT_FOUND; int selNew = wxNOT_FOUND;
if ( bSelect ) if ( bSelect )
selNew = nPage; selNew = nPage;
else if ( m_nSelection == wxNOT_FOUND ) else if ( m_selection == wxNOT_FOUND )
selNew = 0; selNew = 0;
if ( selNew != wxNOT_FOUND ) if ( selNew != wxNOT_FOUND )
@@ -1149,14 +1148,14 @@ void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
// page but only if entering notebook page (i.e. direction is // page but only if entering notebook page (i.e. direction is
// backwards (Shift-TAB) comething from out-of-notebook, or // backwards (Shift-TAB) comething from out-of-notebook, or
// direction is forward (TAB) from ourselves), // direction is forward (TAB) from ourselves),
if ( m_nSelection != wxNOT_FOUND && if ( m_selection != wxNOT_FOUND &&
(!event.GetDirection() || isFromSelf) ) (!event.GetDirection() || isFromSelf) )
{ {
// so that the page knows that the event comes from it's parent // so that the page knows that the event comes from it's parent
// and is being propagated downwards // and is being propagated downwards
event.SetEventObject(this); event.SetEventObject(this);
wxWindow *page = m_pages[m_nSelection]; wxWindow *page = m_pages[m_selection];
if ( !page->HandleWindowEvent(event) ) if ( !page->HandleWindowEvent(event) )
{ {
page->SetFocus(); page->SetFocus();
@@ -1451,7 +1450,7 @@ bool wxNotebook::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM* result)
} }
event.SetSelection(TabCtrl_GetCurSel(GetHwnd())); event.SetSelection(TabCtrl_GetCurSel(GetHwnd()));
event.SetOldSelection(m_nSelection); event.SetOldSelection(m_selection);
event.SetEventObject(this); event.SetEventObject(this);
event.SetInt(idCtrl); event.SetInt(idCtrl);

View File

@@ -76,7 +76,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxBookCtrlBase)
void wxNotebook::Init() void wxNotebook::Init()
{ {
m_imageList = NULL; m_imageList = NULL;
m_nSelection = -1;
m_nTabSize = 0; m_nTabSize = 0;
} // end of wxNotebook::Init } // end of wxNotebook::Init
@@ -210,14 +209,14 @@ int wxNotebook::SetSelection( size_t nPage )
{ {
wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") ); wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") );
if (nPage != (size_t)m_nSelection) if (nPage != (size_t)m_selection)
{ {
wxBookCtrlEvent vEvent( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING wxBookCtrlEvent vEvent( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
,m_windowId ,m_windowId
); );
vEvent.SetSelection(nPage); vEvent.SetSelection(nPage);
vEvent.SetOldSelection(m_nSelection); vEvent.SetOldSelection(m_selection);
vEvent.SetEventObject(this); vEvent.SetEventObject(this);
if (!HandleWindowEvent(vEvent) || vEvent.IsAllowed()) if (!HandleWindowEvent(vEvent) || vEvent.IsAllowed())
{ {
@@ -235,7 +234,7 @@ int wxNotebook::SetSelection( size_t nPage )
); );
} }
} }
m_nSelection = nPage; m_selection = nPage;
return nPage; return nPage;
} // end of wxNotebook::SetSelection } // end of wxNotebook::SetSelection
@@ -243,7 +242,7 @@ int wxNotebook::ChangeSelection( size_t nPage )
{ {
wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") ); wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") );
if (nPage != (size_t)m_nSelection) if (nPage != (size_t)m_selection)
{ {
::WinSendMsg( GetHWND() ::WinSendMsg( GetHWND()
,BKM_TURNTOPAGE ,BKM_TURNTOPAGE
@@ -251,7 +250,7 @@ int wxNotebook::ChangeSelection( size_t nPage )
,(MPARAM)0 ,(MPARAM)0
); );
} }
m_nSelection = nPage; m_selection = nPage;
return nPage; return nPage;
} }
@@ -404,7 +403,7 @@ wxNotebookPage* wxNotebook::DoRemovePage ( size_t nPage )
// //
// No selection any more, the notebook becamse empty // No selection any more, the notebook becamse empty
// //
m_nSelection = -1; m_selection = wxNOT_FOUND;
} }
else // notebook still not empty else // notebook still not empty
{ {
@@ -413,19 +412,19 @@ wxNotebookPage* wxNotebook::DoRemovePage ( size_t nPage )
// //
int nSelNew; int nSelNew;
if (m_nSelection == (int)GetPageCount()) if (m_selection == (int)GetPageCount())
{ {
// //
// Last page deleted, make the new last page the new selection // Last page deleted, make the new last page the new selection
// //
nSelNew = m_nSelection - 1; nSelNew = m_selection - 1;
} }
else if (nPage <= (size_t)m_nSelection) else if (nPage <= (size_t)m_selection)
{ {
// //
// We must show another page, even if it has the same index // We must show another page, even if it has the same index
// //
nSelNew = m_nSelection; nSelNew = m_selection;
} }
else // nothing changes for the currently selected page else // nothing changes for the currently selected page
{ {
@@ -437,16 +436,16 @@ wxNotebookPage* wxNotebook::DoRemovePage ( size_t nPage )
// control (i.e. when there are too many pages) -- otherwise after // control (i.e. when there are too many pages) -- otherwise after
// deleting a page nothing at all is shown // deleting a page nothing at all is shown
// //
m_pages[m_nSelection]->Refresh(); m_pages[m_selection]->Refresh();
} }
if (nSelNew != wxNOT_FOUND) if (nSelNew != wxNOT_FOUND)
{ {
// //
// m_nSelection must be always valid so reset it before calling // m_selection must be always valid so reset it before calling
// SetSelection() // SetSelection()
// //
m_nSelection = -1; m_selection = wxNOT_FOUND;
SetSelection(nSelNew); SetSelection(nSelNew);
} }
} }
@@ -469,7 +468,7 @@ bool wxNotebook::DeleteAllPages()
,(MPARAM)0 ,(MPARAM)0
,(MPARAM)BKA_ALL ,(MPARAM)BKA_ALL
); );
m_nSelection = -1; m_selection = wxNOT_FOUND;
return true; return true;
} // end of wxNotebook::DeleteAllPages } // end of wxNotebook::DeleteAllPages
@@ -569,12 +568,12 @@ bool wxNotebook::InsertPage ( size_t nPage,
// If the inserted page is before the selected one, we must update the // If the inserted page is before the selected one, we must update the
// index of the selected page // index of the selected page
// //
if (nPage <= (size_t)m_nSelection) if (nPage <= (size_t)m_selection)
{ {
// //
// One extra page added // One extra page added
// //
m_nSelection++; m_selection++;
} }
if (pPage) if (pPage)
@@ -657,7 +656,7 @@ bool wxNotebook::InsertPage ( size_t nPage,
if (bSelect) if (bSelect)
nSelNew = nPage; nSelNew = nPage;
else if ( m_nSelection == -1 ) else if ( m_selection == wxNOT_FOUND )
nSelNew = 0; nSelNew = 0;
if (nSelNew != wxNOT_FOUND) if (nSelNew != wxNOT_FOUND)
@@ -725,7 +724,7 @@ void wxNotebook::OnSelChange (
wxNotebookPage* pPage = m_pages[nSel]; wxNotebookPage* pPage = m_pages[nSel];
pPage->Show(true); pPage->Show(true);
m_nSelection = nSel; m_selection = nSel;
} }
// //
@@ -746,8 +745,8 @@ void wxNotebook::OnSetFocus (
// //
// set focus to the currently selected page if any // set focus to the currently selected page if any
// //
if (m_nSelection != -1) if (m_selection != wxNOT_FOUND)
m_pages[m_nSelection]->SetFocus(); m_pages[m_selection]->SetFocus();
rEvent.Skip(); rEvent.Skip();
} // end of wxNotebook::OnSetFocus } // end of wxNotebook::OnSetFocus
@@ -786,7 +785,7 @@ void wxNotebook::OnNavigationKey (
// //
// No, it doesn't come from child, case (b): forward to a page // No, it doesn't come from child, case (b): forward to a page
// //
if (m_nSelection != -1) if (m_selection != wxNOT_FOUND)
{ {
// //
// So that the page knows that the event comes from it's parent // So that the page knows that the event comes from it's parent
@@ -794,7 +793,7 @@ void wxNotebook::OnNavigationKey (
// //
rEvent.SetEventObject(this); rEvent.SetEventObject(this);
wxWindow* pPage = m_pages[m_nSelection]; wxWindow* pPage = m_pages[m_selection];
if (!pPage->HandleWindowEvent(rEvent)) if (!pPage->HandleWindowEvent(rEvent))
{ {

View File

@@ -40,32 +40,6 @@ END_EVENT_TABLE()
IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxBookCtrlBase) IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxBookCtrlBase)
// common part of all ctors
void wxNotebook::Init()
{
m_nSelection = -1;
}
// default for dynamic class
wxNotebook::wxNotebook()
{
Init();
}
// the same arguments as for wxControl
wxNotebook::wxNotebook( wxWindow *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name )
{
Init();
Create( parent, id, pos, size, style, name );
}
bool wxNotebook::Create( wxWindow *parent, bool wxNotebook::Create( wxWindow *parent,
wxWindowID id, wxWindowID id,
const wxPoint& pos, const wxPoint& pos,
@@ -121,25 +95,25 @@ int wxNotebook::DoSetSelection(size_t nPage, int flags)
{ {
wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("DoSetSelection: invalid notebook page") ); wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("DoSetSelection: invalid notebook page") );
if ( m_nSelection == wxNOT_FOUND || nPage != (size_t)m_nSelection ) if ( m_selection == wxNOT_FOUND || nPage != (size_t)m_selection )
{ {
if ( flags & SetSelection_SendEvent ) if ( flags & SetSelection_SendEvent )
{ {
if ( !SendPageChangingEvent(nPage) ) if ( !SendPageChangingEvent(nPage) )
{ {
// vetoed by program // vetoed by program
return m_nSelection; return m_selection;
} }
//else: program allows the page change //else: program allows the page change
SendPageChangedEvent(m_nSelection, nPage); SendPageChangedEvent(m_selection, nPage);
} }
ChangePage(m_nSelection, nPage); ChangePage(m_selection, nPage);
} }
//else: no change //else: no change
return m_nSelection; return m_selection;
} }
bool wxNotebook::SetPageText(size_t nPage, const wxString& strText) bool wxNotebook::SetPageText(size_t nPage, const wxString& strText)
@@ -204,11 +178,11 @@ wxNotebookPage* wxNotebook::DoRemovePage(size_t nPage)
MacSetupTabs(); MacSetupTabs();
if (m_nSelection >= (int)GetPageCount()) if (m_selection >= (int)GetPageCount())
m_nSelection = GetPageCount() - 1; m_selection = GetPageCount() - 1;
if (m_nSelection >= 0) if (m_selection >= 0)
m_pages[m_nSelection]->Show(true); m_pages[m_selection]->Show(true);
InvalidateBestSize(); InvalidateBestSize();
@@ -220,7 +194,7 @@ bool wxNotebook::DeleteAllPages()
{ {
WX_CLEAR_ARRAY(m_pages) ; WX_CLEAR_ARRAY(m_pages) ;
MacSetupTabs(); MacSetupTabs();
m_nSelection = -1 ; m_selection = wxNOT_FOUND ;
InvalidateBestSize(); InvalidateBestSize();
return true; return true;
@@ -258,12 +232,12 @@ bool wxNotebook::InsertPage(size_t nPage,
// if the inserted page is before the selected one, we must update the // if the inserted page is before the selected one, we must update the
// index of the selected page // index of the selected page
if ( int(nPage) <= m_nSelection ) if ( int(nPage) <= m_selection )
{ {
m_nSelection++; m_selection++;
// while this still is the same page showing, we need to update the tabs // while this still is the same page showing, we need to update the tabs
m_peer->SetValue( m_nSelection + 1 ) ; m_peer->SetValue( m_selection + 1 ) ;
} }
// some page should be selected: either this one or the first one if there // some page should be selected: either this one or the first one if there
@@ -271,7 +245,7 @@ bool wxNotebook::InsertPage(size_t nPage,
int selNew = wxNOT_FOUND; int selNew = wxNOT_FOUND;
if ( bSelect ) if ( bSelect )
selNew = nPage; selNew = nPage;
else if ( m_nSelection == -1 ) else if ( m_selection == wxNOT_FOUND )
selNew = 0; selNew = 0;
if ( selNew != wxNOT_FOUND ) if ( selNew != wxNOT_FOUND )
@@ -380,9 +354,9 @@ void wxNotebook::OnSize(wxSizeEvent& event)
// has become visible for the first time after creation, and // has become visible for the first time after creation, and
// we postponed showing the page in ChangePage(). // we postponed showing the page in ChangePage().
// So show the selected page now. // So show the selected page now.
if ( m_nSelection != -1 ) if ( m_selection != wxNOT_FOUND )
{ {
wxNotebookPage *pPage = m_pages[m_nSelection]; wxNotebookPage *pPage = m_pages[m_selection];
if ( !pPage->IsShown() ) if ( !pPage->IsShown() )
{ {
pPage->Show( true ); pPage->Show( true );
@@ -407,8 +381,8 @@ void wxNotebook::OnSelChange(wxBookCtrlEvent& event)
void wxNotebook::OnSetFocus(wxFocusEvent& event) void wxNotebook::OnSetFocus(wxFocusEvent& event)
{ {
// set focus to the currently selected page if any // set focus to the currently selected page if any
if ( m_nSelection != -1 ) if ( m_selection != wxNOT_FOUND )
m_pages[m_nSelection]->SetFocus(); m_pages[m_selection]->SetFocus();
event.Skip(); event.Skip();
} }
@@ -441,13 +415,13 @@ void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
if ( ((wxWindow*)event.GetEventObject()) == parent ) if ( ((wxWindow*)event.GetEventObject()) == parent )
{ {
// no, it doesn't come from child, case (b): forward to a page // no, it doesn't come from child, case (b): forward to a page
if ( m_nSelection != -1 ) if ( m_selection != wxNOT_FOUND )
{ {
// so that the page knows that the event comes from it's parent // so that the page knows that the event comes from it's parent
// and is being propagated downwards // and is being propagated downwards
event.SetEventObject( this ); event.SetEventObject( this );
wxWindow *page = m_pages[m_nSelection]; wxWindow *page = m_pages[m_selection];
if ( !page->HandleWindowEvent( event ) ) if ( !page->HandleWindowEvent( event ) )
{ {
page->SetFocus(); page->SetFocus();
@@ -530,8 +504,8 @@ void wxNotebook::ChangePage(int nOldSel, int nSel)
} }
} }
m_nSelection = nSel; m_selection = nSel;
m_peer->SetValue( m_nSelection + 1 ) ; m_peer->SetValue( m_selection + 1 ) ;
} }
bool wxNotebook::OSXHandleClicked( double WXUNUSED(timestampsec) ) bool wxNotebook::OSXHandleClicked( double WXUNUSED(timestampsec) )
@@ -539,11 +513,11 @@ bool wxNotebook::OSXHandleClicked( double WXUNUSED(timestampsec) )
bool status = false ; bool status = false ;
SInt32 newSel = m_peer->GetValue() - 1 ; SInt32 newSel = m_peer->GetValue() - 1 ;
if ( newSel != m_nSelection ) if ( newSel != m_selection )
{ {
wxBookCtrlEvent changing( wxBookCtrlEvent changing(
wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId,
newSel , m_nSelection ); newSel , m_selection );
changing.SetEventObject( this ); changing.SetEventObject( this );
HandleWindowEvent( changing ); HandleWindowEvent( changing );
@@ -551,13 +525,13 @@ bool wxNotebook::OSXHandleClicked( double WXUNUSED(timestampsec) )
{ {
wxBookCtrlEvent event( wxBookCtrlEvent event(
wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId, wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_windowId,
newSel, m_nSelection ); newSel, m_selection );
event.SetEventObject( this ); event.SetEventObject( this );
HandleWindowEvent( event ); HandleWindowEvent( event );
} }
else else
{ {
m_peer->SetValue( m_nSelection + 1 ) ; m_peer->SetValue( m_selection + 1 ) ;
} }
status = true ; status = true ;

View File

@@ -70,12 +70,6 @@ protected:
#define IS_VALID_PAGE(nPage) (((size_t)nPage) < GetPageCount()) #define IS_VALID_PAGE(nPage) (((size_t)nPage) < GetPageCount())
#endif #endif
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
static const size_t INVALID_PAGE = (size_t)-1;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// private classes // private classes
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -119,8 +113,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxBookCtrlBase)
void wxNotebook::Init() void wxNotebook::Init()
{ {
m_sel = INVALID_PAGE;
m_heightTab = m_heightTab =
m_widthMax = 0; m_widthMax = 0;
@@ -233,10 +225,10 @@ int wxNotebook::DoSetSelection(size_t nPage, int flags)
{ {
wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("invalid notebook page") ); wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("invalid notebook page") );
if ( (size_t)nPage == m_sel ) if ( (size_t)nPage == m_selection )
{ {
// don't do anything if there is nothing to do // don't do anything if there is nothing to do
return m_sel; return m_selection;
} }
if ( flags & SetSelection_SendEvent ) if ( flags & SetSelection_SendEvent )
@@ -244,51 +236,51 @@ int wxNotebook::DoSetSelection(size_t nPage, int flags)
if ( !SendPageChangingEvent(nPage) ) if ( !SendPageChangingEvent(nPage) )
{ {
// program doesn't allow the page change // program doesn't allow the page change
return m_sel; return m_selection;
} }
} }
// we need to change m_sel first, before calling RefreshTab() below as // we need to change m_selection first, before calling RefreshTab() below as
// otherwise the previously selected tab wouldn't be redrawn properly under // otherwise the previously selected tab wouldn't be redrawn properly under
// wxGTK which calls Refresh() immediately and not during the next event // wxGTK which calls Refresh() immediately and not during the next event
// loop iteration as wxMSW does and as it should // loop iteration as wxMSW does and as it should
size_t selOld = m_sel; size_t selOld = m_selection;
m_sel = nPage; m_selection = nPage;
if ( selOld != INVALID_PAGE ) if ( selOld != wxNOT_FOUND )
{ {
RefreshTab(selOld, true /* this tab was selected */); RefreshTab(selOld, true /* this tab was selected */);
m_pages[selOld]->Hide(); m_pages[selOld]->Hide();
} }
if ( m_sel != INVALID_PAGE ) // this is impossible - but test nevertheless if ( m_selection != wxNOT_FOUND ) // this is impossible - but test nevertheless
{ {
if ( HasSpinBtn() ) if ( HasSpinBtn() )
{ {
// keep it in sync // keep it in sync
m_spinbtn->SetValue(m_sel); m_spinbtn->SetValue(m_selection);
} }
if ( m_sel < m_firstVisible ) if ( m_selection < m_firstVisible )
{ {
// selection is to the left of visible part of tabs // selection is to the left of visible part of tabs
ScrollTo(m_sel); ScrollTo(m_selection);
} }
else if ( m_sel > m_lastFullyVisible ) else if ( m_selection > m_lastFullyVisible )
{ {
// selection is to the right of visible part of tabs // selection is to the right of visible part of tabs
ScrollLastTo(m_sel); ScrollLastTo(m_selection);
} }
else // we already see this tab else // we already see this tab
{ {
// no need to scroll // no need to scroll
RefreshTab(m_sel); RefreshTab(m_selection);
} }
m_pages[m_sel]->SetSize(GetPageRect()); m_pages[m_selection]->SetSize(GetPageRect());
m_pages[m_sel]->Show(); m_pages[m_selection]->Show();
} }
if ( flags & SetSelection_SendEvent ) if ( flags & SetSelection_SendEvent )
@@ -376,9 +368,6 @@ bool wxNotebook::DeleteAllPages()
m_accels.Clear(); m_accels.Clear();
m_widths.Clear(); m_widths.Clear();
// it is not valid any longer
m_sel = INVALID_PAGE;
// spin button is not needed any more // spin button is not needed any more
UpdateSpinBtn(); UpdateSpinBtn();
@@ -411,23 +400,23 @@ wxNotebookPage *wxNotebook::DoRemovePage(size_t nPage)
size_t count = GetPageCount(); size_t count = GetPageCount();
if ( count ) if ( count )
{ {
if ( m_sel == (size_t)nPage ) if ( m_selection == (size_t)nPage )
{ {
// avoid sending event to this page which doesn't exist in the // avoid sending event to this page which doesn't exist in the
// notebook any more // notebook any more
m_sel = INVALID_PAGE; m_selection = wxNOT_FOUND;
SetSelection(nPage == count ? nPage - 1 : nPage); SetSelection(nPage == count ? nPage - 1 : nPage);
} }
else if ( m_sel > (size_t)nPage ) else if ( m_selection > (size_t)nPage )
{ {
// no need to change selection, just adjust the index // no need to change selection, just adjust the index
m_sel--; m_selection--;
} }
} }
else // no more tabs left else // no more tabs left
{ {
m_sel = INVALID_PAGE; m_selection = wxNOT_FOUND;
} }
// have to refresh everything // have to refresh everything
@@ -442,9 +431,9 @@ wxNotebookPage *wxNotebook::DoRemovePage(size_t nPage)
void wxNotebook::RefreshCurrent() void wxNotebook::RefreshCurrent()
{ {
if ( m_sel != INVALID_PAGE ) if ( m_selection != wxNOT_FOUND )
{ {
RefreshTab(m_sel); RefreshTab(m_selection);
} }
} }
@@ -453,7 +442,7 @@ void wxNotebook::RefreshTab(int page, bool forceSelected)
wxCHECK_RET( IS_VALID_PAGE(page), wxT("invalid notebook page") ); wxCHECK_RET( IS_VALID_PAGE(page), wxT("invalid notebook page") );
wxRect rect = GetTabRect(page); wxRect rect = GetTabRect(page);
if ( forceSelected || ((size_t)page == m_sel) ) if ( forceSelected || ((size_t)page == m_selection) )
{ {
const wxSize indent = GetRenderer()->GetTabIndent(); const wxSize indent = GetRenderer()->GetTabIndent();
rect.Inflate(indent.x, indent.y); rect.Inflate(indent.x, indent.y);
@@ -496,7 +485,7 @@ void wxNotebook::DoDrawTab(wxDC& dc, const wxRect& rect, size_t n)
} }
int flags = 0; int flags = 0;
if ( n == m_sel ) if ( n == m_selection )
{ {
flags |= wxCONTROL_SELECTED; flags |= wxCONTROL_SELECTED;
@@ -560,7 +549,7 @@ void wxNotebook::DoDraw(wxControlRenderer *renderer)
{ {
GetTabSize(n, &rect.width, &rect.height); GetTabSize(n, &rect.width, &rect.height);
if ( n == m_sel ) if ( n == m_selection )
{ {
// don't redraw it now as this tab has to be drawn over the other // don't redraw it now as this tab has to be drawn over the other
// ones as it takes more place and spills over to them // ones as it takes more place and spills over to them
@@ -591,7 +580,7 @@ void wxNotebook::DoDraw(wxControlRenderer *renderer)
// now redraw the selected tab // now redraw the selected tab
if ( rectSel.width ) if ( rectSel.width )
{ {
DoDrawTab(dc, rectSel, m_sel); DoDrawTab(dc, rectSel, m_selection);
} }
dc.DestroyClippingRegion(); dc.DestroyClippingRegion();
@@ -908,27 +897,27 @@ void wxNotebook::Relayout()
UpdateSpinBtn(); UpdateSpinBtn();
if ( m_sel != INVALID_PAGE ) if ( m_selection != wxNOT_FOUND )
{ {
// resize the currently shown page // resize the currently shown page
wxRect rectPage = GetPageRect(); wxRect rectPage = GetPageRect();
m_pages[m_sel]->SetSize(rectPage); m_pages[m_selection]->SetSize(rectPage);
// also scroll it into view if needed (note that m_lastVisible // also scroll it into view if needed (note that m_lastVisible
// was updated by the call to UpdateSpinBtn() above, this is why it // was updated by the call to UpdateSpinBtn() above, this is why it
// is needed here) // is needed here)
if ( HasSpinBtn() ) if ( HasSpinBtn() )
{ {
if ( m_sel < m_firstVisible ) if ( m_selection < m_firstVisible )
{ {
// selection is to the left of visible part of tabs // selection is to the left of visible part of tabs
ScrollTo(m_sel); ScrollTo(m_selection);
} }
else if ( m_sel > m_lastFullyVisible ) else if ( m_selection > m_lastFullyVisible )
{ {
// selection is to the right of visible part of tabs // selection is to the right of visible part of tabs
ScrollLastTo(m_sel); ScrollLastTo(m_selection);
} }
} }
} }
@@ -1133,7 +1122,7 @@ void wxNotebook::UpdateSpinBtn()
m_spinbtn = new wxNotebookSpinBtn(this); m_spinbtn = new wxNotebookSpinBtn(this);
// set the correct value to keep it in sync // set the correct value to keep it in sync
m_spinbtn->SetValue(m_sel); m_spinbtn->SetValue(m_selection);
} }
// position it correctly // position it correctly