]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/widgets/notebook.cpp
Rebaked makefiles after htmllistbox and collapsable panel additions.
[wxWidgets.git] / samples / widgets / notebook.cpp
index 21cdf14029e6595360574c4a45bd217da43311aa..74ef9c3e69e5113ece148297b18e1ec013da7950 100644 (file)
@@ -92,6 +92,9 @@ public:
     virtual wxControl *GetWidget() const { return m_book; }
     virtual void RecreateWidget() { RecreateBook(); }
 
     virtual wxControl *GetWidget() const { return m_book; }
     virtual void RecreateWidget() { RecreateBook(); }
 
+    // lazy creation of the content
+    virtual void CreateContent();
+
 protected:
     // event handlers
     void OnButtonReset(wxCommandEvent& event);
 protected:
     // event handlers
     void OnButtonReset(wxCommandEvent& event);
@@ -199,8 +202,12 @@ BookWidgetsPage::BookWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist, c
 #endif // USE_ICONS_IN_BOOK
 
     m_book = NULL;
 #endif // USE_ICONS_IN_BOOK
 
     m_book = NULL;
+    m_radioOrient = NULL;
     m_sizerBook = (wxSizer *)NULL;
     m_sizerBook = (wxSizer *)NULL;
+}
 
 
+void BookWidgetsPage::CreateContent()
+{
     wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
 
     // left pane
     wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
 
     // left pane
@@ -279,6 +286,8 @@ BookWidgetsPage::BookWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist, c
     sizerTop->Add(sizerMiddle, 0, wxGROW | wxALL, 10);
     sizerTop->Add(m_sizerBook, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
 
     sizerTop->Add(sizerMiddle, 0, wxGROW | wxALL, 10);
     sizerTop->Add(m_sizerBook, 1, wxGROW | (wxALL & ~wxRIGHT), 10);
 
+    RecreateBook();
+
     // final initializations
     Reset();
 #if USE_ICONS_IN_BOOK
     // final initializations
     Reset();
 #if USE_ICONS_IN_BOOK
@@ -343,7 +352,12 @@ void BookWidgetsPage::CreateImageList()
 
 void BookWidgetsPage::RecreateBook()
 {
 
 void BookWidgetsPage::RecreateBook()
 {
+    // do not recreate anything in case page content was not prepared yet
+    if(!m_radioOrient)
+        return;
+
     int flags = ms_defaultFlags;
     int flags = ms_defaultFlags;
+
     switch ( m_radioOrient->GetSelection() )
     {
         default:
     switch ( m_radioOrient->GetSelection() )
     {
         default:
@@ -412,8 +426,9 @@ void BookWidgetsPage::RecreateBook()
 
 int BookWidgetsPage::GetTextValue(wxTextCtrl *text) const
 {
 
 int BookWidgetsPage::GetTextValue(wxTextCtrl *text) const
 {
-    long pos;
-    if ( !text->GetValue().ToLong(&pos) )
+    long pos = -1;
+
+    if ( !text || !text->GetValue().ToLong(&pos) )
         pos = -1;
 
     return (int)pos;
         pos = -1;
 
     return (int)pos;
@@ -504,18 +519,21 @@ void BookWidgetsPage::OnUpdateUIRemoveButton(wxUpdateUIEvent& event)
 
 void BookWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
 {
 
 void BookWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event)
 {
-    event.Enable( !m_chkImages->GetValue() ||
-                  m_radioOrient->GetSelection() != wxBK_TOP );
+    if(m_chkImages && m_radioOrient)
+        event.Enable( !m_chkImages->GetValue() ||
+                      m_radioOrient->GetSelection() != wxBK_TOP );
 }
 
 void BookWidgetsPage::OnUpdateUINumPagesText(wxUpdateUIEvent& event)
 {
 }
 
 void BookWidgetsPage::OnUpdateUINumPagesText(wxUpdateUIEvent& event)
 {
-    event.SetText( wxString::Format(_T("%d"), m_book->GetPageCount()) );
+    if(m_book)
+        event.SetText( wxString::Format(_T("%u"), unsigned(m_book->GetPageCount())) );
 }
 
 void BookWidgetsPage::OnUpdateUICurSelectText(wxUpdateUIEvent& event)
 {
 }
 
 void BookWidgetsPage::OnUpdateUICurSelectText(wxUpdateUIEvent& event)
 {
-    event.SetText( wxString::Format(_T("%d"), m_book->GetSelection()) );
+    if(m_book)
+        event.SetText( wxString::Format(_T("%d"), m_book->GetSelection()) );
 }
 
 void BookWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
 }
 
 void BookWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& WXUNUSED(event))
@@ -554,7 +572,6 @@ protected:
         return new wxNotebook(this, BookPage_Book,
                               wxDefaultPosition, wxDefaultSize,
                               flags);
         return new wxNotebook(this, BookPage_Book,
                               wxDefaultPosition, wxDefaultSize,
                               flags);
-
     }
 
 private:
     }
 
 private:
@@ -636,7 +653,6 @@ protected:
         return new wxListbook(this, BookPage_Book,
                               wxDefaultPosition, wxDefaultSize,
                               flags);
         return new wxListbook(this, BookPage_Book,
                               wxDefaultPosition, wxDefaultSize,
                               flags);
-
     }
 
 private:
     }
 
 private:
@@ -710,7 +726,6 @@ protected:
         return new wxChoicebook(this, BookPage_Book,
                                 wxDefaultPosition, wxDefaultSize,
                                 flags);
         return new wxChoicebook(this, BookPage_Book,
                                 wxDefaultPosition, wxDefaultSize,
                                 flags);
-
     }
 
 private:
     }
 
 private: