]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/widgets/notebook.cpp
compilation fix for previous commit
[wxWidgets.git] / samples / widgets / notebook.cpp
index 21cdf14029e6595360574c4a45bd217da43311aa..116ee5d91b6e88e8545f77c95f5d5bdb37aebb79 100644 (file)
@@ -92,6 +92,9 @@ public:
     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);
@@ -199,8 +202,12 @@ BookWidgetsPage::BookWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist, c
 #endif // USE_ICONS_IN_BOOK
 
     m_book = NULL;
+    m_radioOrient = NULL;
     m_sizerBook = (wxSizer *)NULL;
+}
 
+void BookWidgetsPage::CreateContent()
+{
     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);
 
+    RecreateBook();
+
     // final initializations
     Reset();
 #if USE_ICONS_IN_BOOK
@@ -286,8 +295,6 @@ BookWidgetsPage::BookWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist, c
 #endif // USE_ICONS_IN_BOOK
 
     SetSizer(sizerTop);
-
-    sizerTop->Fit(this);
 }
 
 BookWidgetsPage::~BookWidgetsPage()
@@ -343,7 +350,12 @@ void BookWidgetsPage::CreateImageList()
 
 void BookWidgetsPage::RecreateBook()
 {
+    // do not recreate anything in case page content was not prepared yet
+    if(!m_radioOrient)
+        return;
+
     int flags = ms_defaultFlags;
+
     switch ( m_radioOrient->GetSelection() )
     {
         default:
@@ -412,8 +424,9 @@ void BookWidgetsPage::RecreateBook()
 
 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;
@@ -504,18 +517,21 @@ void BookWidgetsPage::OnUpdateUIRemoveButton(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)
 {
-    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)
 {
-    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))
@@ -554,7 +570,6 @@ protected:
         return new wxNotebook(this, BookPage_Book,
                               wxDefaultPosition, wxDefaultSize,
                               flags);
-
     }
 
 private:
@@ -636,7 +651,6 @@ protected:
         return new wxListbook(this, BookPage_Book,
                               wxDefaultPosition, wxDefaultSize,
                               flags);
-
     }
 
 private:
@@ -710,7 +724,6 @@ protected:
         return new wxChoicebook(this, BookPage_Book,
                                 wxDefaultPosition, wxDefaultSize,
                                 flags);
-
     }
 
 private: