]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/widgets/notebook.cpp
removed datacmn, not a base file any more
[wxWidgets.git] / samples / widgets / notebook.cpp
index 4491785d2f73c1bf02f9f4ca2d64a8f1d77e210f..8534da6d87032682f1496a9624eded560f794cc0 100644 (file)
@@ -134,6 +134,10 @@ protected:
     // get the numeric value of text ctrl
     int GetTextValue(wxTextCtrl *text) const;
 
     // get the numeric value of text ctrl
     int GetTextValue(wxTextCtrl *text) const;
 
+    // is the value in range?
+    bool IsValidValue(int val) const
+        { return (val >= 0) && (val < m_notebook->GetPageCount()); }
+
     // the controls
     // ------------
 
     // the controls
     // ------------
 
@@ -380,21 +384,20 @@ void NotebookWidgetsPage::CreateNotebook()
 
     if ( notebook )
     {
 
     if ( notebook )
     {
-        int sel = notebook->GetSelection();
+        const int sel = notebook->GetSelection();
+
+        const int count = notebook->GetPageCount();
 
 
-        int count = notebook->GetPageCount();
+        // recreate the pages
         for ( int n = 0; n < count; n++ )
         {
         for ( int n = 0; n < count; n++ )
         {
-            wxNotebookPage *page = notebook->GetPage(0);
-            page->Reparent(m_notebook);
-
-            m_notebook->AddPage(page, notebook->GetPageText(0), FALSE,
-                                notebook->GetPageImage(0));
-
-            notebook->RemovePage(0);
+            m_notebook->AddPage(CreateNewPage(),
+                                notebook->GetPageText(n),
+                                FALSE,
+                                notebook->GetPageImage(n));
         }
 
         }
 
-        m_sizerNotebook->Remove(notebook);
+        m_sizerNotebook->Detach( notebook );
         delete notebook;
 
         // restore selection
         delete notebook;
 
         // restore selection
@@ -459,7 +462,7 @@ void NotebookWidgetsPage::OnButtonDeleteAll(wxCommandEvent& WXUNUSED(event))
 void NotebookWidgetsPage::OnButtonSelectPage(wxCommandEvent& event)
 {
     int pos = GetTextValue(m_textSelect);
 void NotebookWidgetsPage::OnButtonSelectPage(wxCommandEvent& event)
 {
     int pos = GetTextValue(m_textSelect);
-    wxCHECK_RET( pos >= 0, _T("button should be disabled") );
+    wxCHECK_RET( IsValidValue(pos), _T("button should be disabled") );
 
     m_notebook->SetSelection(pos);
 }
 
     m_notebook->SetSelection(pos);
 }
@@ -473,7 +476,7 @@ void NotebookWidgetsPage::OnButtonAddPage(wxCommandEvent& WXUNUSED(event))
 void NotebookWidgetsPage::OnButtonInsertPage(wxCommandEvent& WXUNUSED(event))
 {
     int pos = GetTextValue(m_textInsert);
 void NotebookWidgetsPage::OnButtonInsertPage(wxCommandEvent& WXUNUSED(event))
 {
     int pos = GetTextValue(m_textInsert);
-    wxCHECK_RET( pos >= 0, _T("button should be disabled") );
+    wxCHECK_RET( IsValidValue(pos), _T("button should be disabled") );
 
     m_notebook->InsertPage(pos, CreateNewPage(), _T("Inserted page"), FALSE,
                            GetIconIndex());
 
     m_notebook->InsertPage(pos, CreateNewPage(), _T("Inserted page"), FALSE,
                            GetIconIndex());
@@ -482,24 +485,24 @@ void NotebookWidgetsPage::OnButtonInsertPage(wxCommandEvent& WXUNUSED(event))
 void NotebookWidgetsPage::OnButtonRemovePage(wxCommandEvent& WXUNUSED(event))
 {
     int pos = GetTextValue(m_textRemove);
 void NotebookWidgetsPage::OnButtonRemovePage(wxCommandEvent& WXUNUSED(event))
 {
     int pos = GetTextValue(m_textRemove);
-    wxCHECK_RET( pos >= 0, _T("button should be disabled") );
+    wxCHECK_RET( IsValidValue(pos), _T("button should be disabled") );
 
     m_notebook->DeletePage(pos);
 }
 
 void NotebookWidgetsPage::OnUpdateUISelectButton(wxUpdateUIEvent& event)
 {
 
     m_notebook->DeletePage(pos);
 }
 
 void NotebookWidgetsPage::OnUpdateUISelectButton(wxUpdateUIEvent& event)
 {
-    event.Enable( GetTextValue(m_textSelect) >= 0 );
+    event.Enable( IsValidValue(GetTextValue(m_textSelect)) );
 }
 
 void NotebookWidgetsPage::OnUpdateUIInsertButton(wxUpdateUIEvent& event)
 {
 }
 
 void NotebookWidgetsPage::OnUpdateUIInsertButton(wxUpdateUIEvent& event)
 {
-    event.Enable( GetTextValue(m_textInsert) >= 0 );
+    event.Enable( IsValidValue(GetTextValue(m_textInsert)) );
 }
 
 void NotebookWidgetsPage::OnUpdateUIRemoveButton(wxUpdateUIEvent& event)
 {
 }
 
 void NotebookWidgetsPage::OnUpdateUIRemoveButton(wxUpdateUIEvent& event)
 {
-    event.Enable( GetTextValue(m_textRemove) >= 0 );
+    event.Enable( IsValidValue(GetTextValue(m_textRemove)) );
 }
 
 void NotebookWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
 }
 
 void NotebookWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
@@ -543,4 +546,4 @@ void NotebookWidgetsPage::OnPageChanged(wxNotebookEvent& event)
     event.Skip();
 }
 
     event.Skip();
 }
 
-#endif
\ No newline at end of file
+#endif