added SetSelectionToPage/Window() to simplify code and fix more problems with passing possibly negative indices to SetSelection()
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45163 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -562,6 +562,14 @@ protected:
|
|||||||
void OnTabEndDrag(wxCommandEvent& evt);
|
void OnTabEndDrag(wxCommandEvent& evt);
|
||||||
void OnTabButton(wxCommandEvent& evt);
|
void OnTabButton(wxCommandEvent& evt);
|
||||||
|
|
||||||
|
// set selection to the given window (which must be non-NULL and be one of
|
||||||
|
// our pages, otherwise an assert is raised)
|
||||||
|
void SetSelectionToWindow(wxWindow *win);
|
||||||
|
void SetSelectionToPage(const wxAuiNotebookPage& page)
|
||||||
|
{
|
||||||
|
SetSelectionToWindow(page.window);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
wxAuiManager m_mgr;
|
wxAuiManager m_mgr;
|
||||||
|
@@ -1437,14 +1437,14 @@ wxWindow* wxAuiTabContainer::GetWindowFromIdx(size_t idx) const
|
|||||||
|
|
||||||
int wxAuiTabContainer::GetIdxFromWindow(wxWindow* wnd) const
|
int wxAuiTabContainer::GetIdxFromWindow(wxWindow* wnd) const
|
||||||
{
|
{
|
||||||
size_t i, page_count = m_pages.GetCount();
|
const size_t page_count = m_pages.GetCount();
|
||||||
for (i = 0; i < page_count; ++i)
|
for ( size_t i = 0; i < page_count; ++i )
|
||||||
{
|
{
|
||||||
wxAuiNotebookPage& page = m_pages.Item(i);
|
wxAuiNotebookPage& page = m_pages.Item(i);
|
||||||
if (page.window == wnd)
|
if (page.window == wnd)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
return -1;
|
return wxNOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxAuiNotebookPage& wxAuiTabContainer::GetPage(size_t idx)
|
wxAuiNotebookPage& wxAuiTabContainer::GetPage(size_t idx)
|
||||||
@@ -2614,10 +2614,7 @@ bool wxAuiNotebook::InsertPage(size_t page_idx,
|
|||||||
|
|
||||||
if (select)
|
if (select)
|
||||||
{
|
{
|
||||||
int idx = m_tabs.GetIdxFromWindow(page);
|
SetSelectionToWindow(page);
|
||||||
wxASSERT_MSG(idx != -1, wxT("Invalid Page index returned on wxAuiNotebook::InsertPage()"));
|
|
||||||
|
|
||||||
SetSelection(idx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -2703,7 +2700,7 @@ bool wxAuiNotebook::RemovePage(size_t page_idx)
|
|||||||
if (new_active)
|
if (new_active)
|
||||||
{
|
{
|
||||||
m_curpage = -1;
|
m_curpage = -1;
|
||||||
SetSelection(m_tabs.GetIdxFromWindow(new_active));
|
SetSelectionToWindow(new_active);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -2858,6 +2855,14 @@ size_t wxAuiNotebook::SetSelection(size_t new_page)
|
|||||||
return m_curpage;
|
return m_curpage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxAuiNotebook::SetSelectionToWindow(wxWindow *win)
|
||||||
|
{
|
||||||
|
const int idx = m_tabs.GetIdxFromWindow(win);
|
||||||
|
wxCHECK_RET( idx != wxNOT_FOUND, _T("invalid notebook page") );
|
||||||
|
|
||||||
|
SetSelection(idx);
|
||||||
|
}
|
||||||
|
|
||||||
// GetPageCount() returns the total number of
|
// GetPageCount() returns the total number of
|
||||||
// pages managed by the multi-notebook
|
// pages managed by the multi-notebook
|
||||||
size_t wxAuiNotebook::GetPageCount() const
|
size_t wxAuiNotebook::GetPageCount() const
|
||||||
@@ -3070,15 +3075,7 @@ void wxAuiNotebook::Split(size_t page, int direction)
|
|||||||
m_curpage = -1;
|
m_curpage = -1;
|
||||||
|
|
||||||
// set the active page to the one we just split off
|
// set the active page to the one we just split off
|
||||||
int idx = m_tabs.GetIdxFromWindow(page_info.window);
|
SetSelectionToPage(page_info);
|
||||||
if ( idx != wxNOT_FOUND )
|
|
||||||
{
|
|
||||||
SetSelection(idx);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wxFAIL_MSG( _T("just inserted window not found") );
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateHintWindowSize();
|
UpdateHintWindowSize();
|
||||||
}
|
}
|
||||||
@@ -3101,10 +3098,7 @@ void wxAuiNotebook::OnTabClicked(wxCommandEvent& command_evt)
|
|||||||
wxWindow* wnd = ctrl->GetWindowFromIdx(evt.GetSelection());
|
wxWindow* wnd = ctrl->GetWindowFromIdx(evt.GetSelection());
|
||||||
wxASSERT(wnd != NULL);
|
wxASSERT(wnd != NULL);
|
||||||
|
|
||||||
int idx = m_tabs.GetIdxFromWindow(wnd);
|
SetSelectionToWindow(wnd);
|
||||||
wxASSERT(idx != -1);
|
|
||||||
|
|
||||||
SetSelection(idx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxAuiNotebook::OnTabBeginDrag(wxCommandEvent&)
|
void wxAuiNotebook::OnTabBeginDrag(wxCommandEvent&)
|
||||||
@@ -3303,9 +3297,11 @@ void wxAuiNotebook::OnTabEndDrag(wxCommandEvent& command_evt)
|
|||||||
|
|
||||||
// get main index of the page
|
// get main index of the page
|
||||||
int main_idx = m_tabs.GetIdxFromWindow(src_page);
|
int main_idx = m_tabs.GetIdxFromWindow(src_page);
|
||||||
|
wxCHECK_RET( main_idx != wxNOT_FOUND, _T("no source page?") );
|
||||||
|
|
||||||
|
|
||||||
// make a copy of the page info
|
// make a copy of the page info
|
||||||
wxAuiNotebookPage page_info = m_tabs.GetPage((size_t)main_idx);
|
wxAuiNotebookPage page_info = m_tabs.GetPage(main_idx);
|
||||||
|
|
||||||
// remove the page from the source notebook
|
// remove the page from the source notebook
|
||||||
RemovePage(main_idx);
|
RemovePage(main_idx);
|
||||||
@@ -3338,7 +3334,7 @@ void wxAuiNotebook::OnTabEndDrag(wxCommandEvent& command_evt)
|
|||||||
dest_tabs->Refresh();
|
dest_tabs->Refresh();
|
||||||
|
|
||||||
// set the selection in the destination tab control
|
// set the selection in the destination tab control
|
||||||
nb->SetSelection(nb->m_tabs.GetIdxFromWindow(page_info.window));
|
nb->SetSelectionToPage(page_info);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -3437,7 +3433,7 @@ void wxAuiNotebook::OnTabEndDrag(wxCommandEvent& command_evt)
|
|||||||
m_curpage = -1;
|
m_curpage = -1;
|
||||||
|
|
||||||
// set the active page to the one we just split off
|
// set the active page to the one we just split off
|
||||||
SetSelection(m_tabs.GetIdxFromWindow(page_info.window));
|
SetSelectionToPage(page_info);
|
||||||
|
|
||||||
UpdateHintWindowSize();
|
UpdateHintWindowSize();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user