X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/261357eb0ad855b642fe68a84c9ad2b727a926cb..55b43eaa025408453e90a6c01f64215a9203da9a:/samples/widgets/notebook.cpp diff --git a/samples/widgets/notebook.cpp b/samples/widgets/notebook.cpp index add4b52b3d..0bfc12be5c 100644 --- a/samples/widgets/notebook.cpp +++ b/samples/widgets/notebook.cpp @@ -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); @@ -119,8 +122,10 @@ protected: void RecreateBook(); virtual wxBookCtrlBase *CreateBook(long flags) = 0; +#if USE_ICONS_IN_BOOK // create or destroy the image list void CreateImageList(); +#endif // USE_ICONS_IN_BOOK // create a new page wxWindow *CreateNewPage(); @@ -151,8 +156,10 @@ protected: wxBookCtrlBase *m_book; wxSizer *m_sizerBook; - // thei mage list for our book +#if USE_ICONS_IN_BOOK + // the image list for our book wxImageList *m_imageList; +#endif // USE_ICONS_IN_BOOK private: DECLARE_EVENT_TABLE() @@ -190,11 +197,17 @@ BookWidgetsPage::BookWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist, c { // init everything m_chkImages = NULL; +#if USE_ICONS_IN_BOOK m_imageList = NULL; +#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 @@ -273,9 +286,13 @@ 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 CreateImageList(); +#endif // USE_ICONS_IN_BOOK SetSizer(sizerTop); @@ -284,7 +301,9 @@ BookWidgetsPage::BookWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist, c BookWidgetsPage::~BookWidgetsPage() { +#if USE_ICONS_IN_BOOK delete m_imageList; +#endif // USE_ICONS_IN_BOOK } // ---------------------------------------------------------------------------- @@ -297,6 +316,7 @@ void BookWidgetsPage::Reset() m_radioOrient->SetSelection(Orient_Top); } +#if USE_ICONS_IN_BOOK void BookWidgetsPage::CreateImageList() { if ( m_chkImages->GetValue() ) @@ -328,10 +348,16 @@ void BookWidgetsPage::CreateImageList() // it would be logical if this removed the image list from book, under // MSW it crashes instead - FIXME } +#endif // USE_ICONS_IN_BOOK 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: @@ -359,7 +385,9 @@ void BookWidgetsPage::RecreateBook() m_book = CreateBook(flags); +#if USE_ICONS_IN_BOOK CreateImageList(); +#endif // USE_ICONS_IN_BOOK if ( oldBook ) { @@ -398,8 +426,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; @@ -407,6 +436,7 @@ int BookWidgetsPage::GetTextValue(wxTextCtrl *text) const int BookWidgetsPage::GetIconIndex() const { +#if USE_ICONS_IN_BOOK if ( m_imageList ) { int nImages = m_imageList->GetImageCount(); @@ -415,6 +445,7 @@ int BookWidgetsPage::GetIconIndex() const return m_book->GetPageCount() % nImages; } } +#endif // USE_ICONS_IN_BOOK return -1; } @@ -488,18 +519,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("%d"), 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)) @@ -538,7 +572,6 @@ protected: return new wxNotebook(this, BookPage_Book, wxDefaultPosition, wxDefaultSize, flags); - } private: @@ -620,7 +653,6 @@ protected: return new wxListbook(this, BookPage_Book, wxDefaultPosition, wxDefaultSize, flags); - } private: @@ -694,7 +726,6 @@ protected: return new wxChoicebook(this, BookPage_Book, wxDefaultPosition, wxDefaultSize, flags); - } private: