]> git.saurik.com Git - wxWidgets.git/commitdiff
several notebook bugs fixed:
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 24 Jun 1999 21:27:52 +0000 (21:27 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 24 Jun 1999 21:27:52 +0000 (21:27 +0000)
1. deleting the last page sets selection to -1
2. deleting the selected page unselects it first
3. adding page calls Layout() on it

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2888 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/notebook/test.cpp
samples/notebook/test.h
src/msw/notebook.cpp

index 9a35002ed626895bd3fd3a05d90661137bcddd2e..6413033ed499f82e32551da0efb166e67df0846b 100644 (file)
@@ -162,6 +162,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_BUTTON(ID_DELETE_PAGE, MyFrame::OnDeletePage)
     EVT_BUTTON(ID_ADD_PAGE, MyFrame::OnAddPage)
     EVT_SIZE(MyFrame::OnSize)
+    EVT_IDLE(MyFrame::OnIdle)
 END_EVENT_TABLE()
 
 MyFrame::MyFrame(wxFrame* parent, const wxWindowID id, const wxString& title,
@@ -183,17 +184,17 @@ void MyFrame::OnAddPage(wxCommandEvent& WXUNUSED(event))
 
 void MyFrame::OnDeletePage(wxCommandEvent& WXUNUSED(event))
 {
-  m_notebook->DeletePage( m_notebook->GetPageCount()-1 );
+    m_notebook->DeletePage( m_notebook->GetPageCount()-1 );
 }
 
 void MyFrame::OnOK(wxCommandEvent& WXUNUSED(event) )
 {
-    this->Destroy();
+    Destroy();
 }
 
 void MyFrame::OnCloseWindow(wxCloseEvent& WXUNUSED(event) )
 {
-    this->Destroy();
+    Destroy();
 }
 
 void MyFrame::Init(void)
@@ -229,3 +230,21 @@ void MyFrame::OnSize(wxSizeEvent& event)
     m_panel->Layout();
 }
 
+void MyFrame::OnIdle(wxIdleEvent& WXUNUSED(event))
+{
+    static int s_nPages = -1;
+    static int s_nSel = -1;
+
+    int nPages = m_notebook->GetPageCount();
+    int nSel = m_notebook->GetSelection();
+    if ( nPages != s_nPages || nSel != s_nSel )
+    {
+        s_nPages = nPages;
+        s_nSel = nSel;
+
+        wxString title;
+        title.Printf("Notebook (%d pages, selection: %d)", nPages, nSel);
+
+        SetTitle(title);
+    }
+}
index f9f482ecf8c97554996138b542046bc196d97d8f..70b52a00e49d05ab814366a854cdb2f2ac9edf28 100644 (file)
@@ -52,7 +52,10 @@ public:
     void OnAddPage(wxCommandEvent& event);
     void OnDeletePage(wxCommandEvent& event);
     void OnSize(wxSizeEvent& event);
-    void Init(void);
+    void OnIdle(wxIdleEvent& event);
+
+    void Init();
+
 protected:
     wxNotebook*     m_notebook;
     wxPanel*        m_panel; // Panel containing notebook and OK/Cancel/Help
index d6c5fc5234928a1857e22c93b29aa1ab0cb03071..d94b86b315c4bdcdcf1730434e5f44631476255f 100644 (file)
@@ -274,11 +274,22 @@ bool wxNotebook::DeletePage(int nPage)
 {
   wxCHECK_MSG( IS_VALID_PAGE(nPage), FALSE, _T("notebook page out of range") );
 
+  if ( m_nSelection == nPage ) {
+      // advance selection backwards - the page being deleted shouldn't be left
+      // selected
+      AdvanceSelection(FALSE);
+  }
+
   TabCtrl_DeleteItem(m_hwnd, nPage);
 
   delete m_aPages[nPage];
   m_aPages.Remove(nPage);
 
+  if ( m_aPages.IsEmpty() ) {
+      // no selection if the notebook became empty
+      m_nSelection = -1;
+  }
+
   return TRUE;
 }
 
@@ -370,6 +381,11 @@ bool wxNotebook::InsertPage(int nPage,
   // this updates internal flag too - otherwise it will get out of sync
   pPage->Show(FALSE);
 
+  // FIXME this is ugly, I'm breaking my own rules... but needed to get display
+  //       right (why?)
+  wxSizeEvent event;
+  OnSize(event);
+
   return TRUE;
 }