]> git.saurik.com Git - wxWidgets.git/commitdiff
added SetSelectionToPage/Window() to simplify code and fix more problems with passing...
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 30 Mar 2007 16:48:43 +0000 (16:48 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 30 Mar 2007 16:48:43 +0000 (16:48 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45163 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/aui/auibook.h
src/aui/auibook.cpp

index 05ebfdacf25ac11afe49f9882c6d22dd455834e7..28358f7d0c508de457a594dc46928107926dad83 100644 (file)
@@ -562,6 +562,14 @@ protected:
     void OnTabEndDrag(wxCommandEvent& evt);
     void OnTabButton(wxCommandEvent& evt);
 
     void OnTabEndDrag(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:
 
     wxAuiManager m_mgr;
 protected:
 
     wxAuiManager m_mgr;
index f0763f94f1e0b33a9ee0b0f453c0f47845ad89f5..dc73becd50f7cf5464e5cd993edb18a54008592b 100644 (file)
@@ -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();
-    for (i = 0; i < page_count; ++i)
+    const size_t page_count = m_pages.GetCount();
+    for ( size_t i = 0; i < page_count; ++i )
     {
         wxAuiNotebookPage& page = m_pages.Item(i);
         if (page.window == wnd)
             return i;
     }
     {
         wxAuiNotebookPage& page = m_pages.Item(i);
         if (page.window == wnd)
             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);
-        wxASSERT_MSG(idx != -1, wxT("Invalid Page index returned on wxAuiNotebook::InsertPage()"));
-
-        SetSelection(idx);
+        SetSelectionToWindow(page);
     }
 
     return true;
     }
 
     return true;
@@ -2703,7 +2700,7 @@ bool wxAuiNotebook::RemovePage(size_t page_idx)
     if (new_active)
     {
         m_curpage = -1;
     if (new_active)
     {
         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
 // pages managed by the multi-notebook
 size_t wxAuiNotebook::GetPageCount() const
 // GetPageCount() returns the total number of
 // pages managed by the multi-notebook
 size_t wxAuiNotebook::GetPageCount() const
@@ -3070,15 +3075,7 @@ void wxAuiNotebook::Split(size_t page, int direction)
     m_curpage = -1;
 
     // set the active page to the one we just split off
     m_curpage = -1;
 
     // set the active page to the one we just split off
-    int idx = m_tabs.GetIdxFromWindow(page_info.window);
-    if ( idx != wxNOT_FOUND )
-    {
-        SetSelection(idx);
-    }
-    else
-    {
-        wxFAIL_MSG( _T("just inserted window not found") );
-    }
+    SetSelectionToPage(page_info);
 
     UpdateHintWindowSize();
 }
 
     UpdateHintWindowSize();
 }
@@ -3101,10 +3098,7 @@ void wxAuiNotebook::OnTabClicked(wxCommandEvent& command_evt)
     wxWindow* wnd = ctrl->GetWindowFromIdx(evt.GetSelection());
     wxASSERT(wnd != NULL);
 
     wxWindow* wnd = ctrl->GetWindowFromIdx(evt.GetSelection());
     wxASSERT(wnd != NULL);
 
-    int idx = m_tabs.GetIdxFromWindow(wnd);
-    wxASSERT(idx != -1);
-
-    SetSelection(idx);
+    SetSelectionToWindow(wnd);
 }
 
 void wxAuiNotebook::OnTabBeginDrag(wxCommandEvent&)
 }
 
 void wxAuiNotebook::OnTabBeginDrag(wxCommandEvent&)
@@ -3303,9 +3297,11 @@ void wxAuiNotebook::OnTabEndDrag(wxCommandEvent& command_evt)
 
                 // get main index of the page
                 int main_idx = m_tabs.GetIdxFromWindow(src_page);
 
                 // get main index of the 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
                 RemovePage(main_idx);
 
                 // remove the page from the source notebook
                 RemovePage(main_idx);
@@ -3338,7 +3334,7 @@ void wxAuiNotebook::OnTabEndDrag(wxCommandEvent& command_evt)
                 dest_tabs->Refresh();
 
                 // set the selection in the destination tab control
                 dest_tabs->Refresh();
 
                 // 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;
 
         // set the active page to the one we just split off
         m_curpage = -1;
 
         // set the active page to the one we just split off
-        SetSelection(m_tabs.GetIdxFromWindow(page_info.window));
+        SetSelectionToPage(page_info);
 
         UpdateHintWindowSize();
     }
 
         UpdateHintWindowSize();
     }