X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/954427ba3e6553ba15e04182732f6f15a1a1e14e..30738aae14dfbce0c492d8696c861947228028c2:/samples/widgets/notebook.cpp diff --git a/samples/widgets/notebook.cpp b/samples/widgets/notebook.cpp index 21cdf14029..7c9e94a8a8 100644 --- a/samples/widgets/notebook.cpp +++ b/samples/widgets/notebook.cpp @@ -86,12 +86,15 @@ enum Orient class BookWidgetsPage : public WidgetsPage { public: - BookWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist, char* icon[]); + BookWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist, const char *const icon[]); virtual ~BookWidgetsPage(); 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); @@ -189,7 +192,7 @@ END_EVENT_TABLE() // implementation // ============================================================================ -BookWidgetsPage::BookWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist, char* icon[]) +BookWidgetsPage::BookWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist, const char *const icon[]) :WidgetsPage(book, imaglist, icon) { // init everything @@ -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: