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
virtual int GetSelection() const = 0;
int GetSelection() const { return m_selection; }
// set/get the title of a page
virtual bool SetPageText(size_t n, const wxString& strText) = 0;
@@ -181,6 +181,7 @@ public:
// remove all pages and delete them
virtual bool DeleteAllPages()
{
m_selection = wxNOT_FOUND;
DoInvalidateBestSize();
WX_CLEAR_ARRAY(m_pages);
return true;
@@ -332,6 +333,11 @@ protected:
// the margin around the choice control
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:
// common part of all ctors
@@ -342,6 +348,7 @@ private:
DECLARE_ABSTRACT_CLASS(wxBookCtrlBase)
wxDECLARE_NO_COPY_CLASS(wxBookCtrlBase);
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
{
public:
wxChoicebook()
{
Init();
}
wxChoicebook() { }
wxChoicebook(wxWindow *parent,
wxWindowID id,
@@ -51,8 +48,6 @@ public:
long style = 0,
const wxString& name = wxEmptyString)
{
Init();
(void)Create(parent, id, pos, size, style, name);
}
@@ -65,7 +60,6 @@ public:
const wxString& name = wxEmptyString);
virtual int GetSelection() const;
virtual bool SetPageText(size_t n, const wxString& strText);
virtual wxString GetPageText(size_t n) const;
virtual int GetPageImage(size_t n) const;
@@ -102,13 +96,7 @@ protected:
// event handlers
void OnChoiceSelected(wxCommandEvent& event);
// the currently selected page or wxNOT_FOUND if none
int m_selection;
private:
// common part of all constructors
void Init();
DECLARE_EVENT_TABLE()
DECLARE_DYNAMIC_CLASS_NO_COPY(wxChoicebook)
};

View File

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

View File

@@ -110,6 +110,9 @@ public:
// common part of all ctors
void Init();
// Called by GTK event handler when the current page is definitely changed.
void GTKOnPageChanged();
// helper function
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
{
public:
wxListbook()
{
Init();
}
wxListbook() { }
wxListbook(wxWindow *parent,
wxWindowID id,
@@ -51,8 +48,6 @@ public:
long style = 0,
const wxString& name = wxEmptyString)
{
Init();
(void)Create(parent, id, pos, size, style, name);
}
@@ -66,7 +61,6 @@ public:
// overridden base class methods
virtual int GetSelection() const;
virtual bool SetPageText(size_t n, const wxString& strText);
virtual wxString GetPageText(size_t n) const;
virtual int GetPageImage(size_t n) const;
@@ -101,13 +95,7 @@ protected:
void OnListSelected(wxListEvent& event);
void OnSize(wxSizeEvent& event);
// the currently selected page or wxNOT_FOUND if none
int m_selection;
private:
// common part of all constructors
void Init();
// this should be called when we need to be relaid out
void UpdateSize();

View File

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

View File

@@ -69,11 +69,6 @@ public:
// changes selected page without sending events
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
//
@@ -193,8 +188,6 @@ protected:
// Helper functions
//
int m_nSelection; // The current selection (-1 if none)
private:
wxArrayLong m_alPageId;
int m_nTabSize; // holds the largest tab size

View File

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

View File

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

View File

@@ -126,7 +126,6 @@ public:
// Standard operations inherited from wxBookCtrlBase
// -------------------------------------------------
virtual int GetSelection() const;
virtual bool SetPageText(size_t n, const wxString& strText);
virtual wxString GetPageText(size_t n) const;
virtual int GetPageImage(size_t n) const;
@@ -152,9 +151,6 @@ protected:
// array of page ids and page windows
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
// NULL this is the first (sub)child that has a non-NULL page
int m_actualSelection;

View File

@@ -64,7 +64,6 @@ public:
// --------------------------------------
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
int ChangeSelection(size_t nPage) { return DoSetSelection(nPage); }
@@ -210,9 +209,6 @@ protected:
// the pages titles
wxArrayString m_titles;
// the current selection
size_t m_sel;
// the spin button to change the pages
wxSpinButton *m_spinbtn;