From 453535a739f649ce43a65fd7e6b9730363bb1b7c Mon Sep 17 00:00:00 2001 From: =?utf8?q?W=C5=82odzimierz=20Skiba?= Date: Tue, 6 Jun 2006 14:10:06 +0000 Subject: [PATCH] On-demand creation of the pages for speedup of sample launch. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39593 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/widgets/button.cpp | 6 ++++++ samples/widgets/checkbox.cpp | 7 +++++++ samples/widgets/combobox.cpp | 10 ++++++++-- samples/widgets/datepick.cpp | 7 +++++++ samples/widgets/gauge.cpp | 6 ++++++ samples/widgets/hyperlnk.cpp | 11 +++++++++-- samples/widgets/listbox.cpp | 9 ++++++++- samples/widgets/notebook.cpp | 28 ++++++++++++++++++++++------ samples/widgets/picker.cpp | 7 +++++++ samples/widgets/radiobox.cpp | 6 ++++++ samples/widgets/slider.cpp | 6 ++++++ samples/widgets/spinbtn.cpp | 6 ++++++ samples/widgets/static.cpp | 6 ++++++ samples/widgets/textctrl.cpp | 6 ++++++ samples/widgets/toggle.cpp | 7 +++++++ samples/widgets/widgets.cpp | 35 +++++++++++++++++++++++++++++++---- samples/widgets/widgets.h | 3 +++ 17 files changed, 151 insertions(+), 15 deletions(-) diff --git a/samples/widgets/button.cpp b/samples/widgets/button.cpp index 7c4dd08266..c06a28bf69 100644 --- a/samples/widgets/button.cpp +++ b/samples/widgets/button.cpp @@ -85,6 +85,9 @@ public: virtual wxControl *GetWidget() const { return m_button; } virtual void RecreateWidget() { CreateButton(); } + // lazy creation of the content + virtual void CreateContent(); + protected: // event handlers void OnCheckOrRadioBox(wxCommandEvent& event); @@ -183,7 +186,10 @@ ButtonWidgetsPage::ButtonWidgetsPage(WidgetsBookCtrl *book, m_button = (wxButton *)NULL; m_sizerButton = (wxSizer *)NULL; +} +void ButtonWidgetsPage::CreateContent() +{ wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); // left pane diff --git a/samples/widgets/checkbox.cpp b/samples/widgets/checkbox.cpp index 384d4156e8..65a5c1ea4e 100644 --- a/samples/widgets/checkbox.cpp +++ b/samples/widgets/checkbox.cpp @@ -79,6 +79,9 @@ public: virtual wxControl *GetWidget() const { return m_checkbox; } virtual void RecreateWidget() { CreateCheckbox(); } + // lazy creation of the content + virtual void CreateContent(); + protected: // event handlers void OnCheckBox(wxCommandEvent& event); @@ -159,6 +162,10 @@ IMPLEMENT_WIDGETS_PAGE(CheckBoxWidgetsPage, wxT("CheckBox"), FAMILY_CTRLS ); CheckBoxWidgetsPage::CheckBoxWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist) : WidgetsPage(book, imaglist, checkbox_xpm) +{ +} + +void CheckBoxWidgetsPage::CreateContent() { wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); diff --git a/samples/widgets/combobox.cpp b/samples/widgets/combobox.cpp index 77e8962012..2ac76337af 100644 --- a/samples/widgets/combobox.cpp +++ b/samples/widgets/combobox.cpp @@ -90,6 +90,9 @@ public: virtual wxControl *GetWidget() const { return m_combobox; } virtual void RecreateWidget() { CreateCombo(); } + // lazy creation of the content + virtual void CreateContent(); + protected: // event handlers void OnButtonReset(wxCommandEvent& event); @@ -212,7 +215,10 @@ ComboboxWidgetsPage::ComboboxWidgetsPage(WidgetsBookCtrl *book, m_combobox = (wxComboBox *)NULL; m_sizerCombo = (wxSizer *)NULL; +} +void ComboboxWidgetsPage::CreateContent() +{ /* What we create here is a frame having 3 panes: style pane is the leftmost one, in the middle the pane with buttons allowing to perform @@ -408,7 +414,7 @@ void ComboboxWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event)) void ComboboxWidgetsPage::OnButtonChange(wxCommandEvent& WXUNUSED(event)) { int sel = m_combobox->GetSelection(); - if ( sel != -1 ) + if ( sel != wxNOT_FOUND ) { #ifndef __WXGTK__ m_combobox->SetString(sel, m_textChange->GetValue()); @@ -531,7 +537,7 @@ void ComboboxWidgetsPage::OnUpdateUIDeleteButton(wxUpdateUIEvent& event) void ComboboxWidgetsPage::OnUpdateUIDeleteSelButton(wxUpdateUIEvent& event) { if (m_combobox) - event.Enable(m_combobox->GetSelection() != -1); + event.Enable(m_combobox->GetSelection() != wxNOT_FOUND); } void ComboboxWidgetsPage::OnUpdateUIClearButton(wxUpdateUIEvent& event) diff --git a/samples/widgets/datepick.cpp b/samples/widgets/datepick.cpp index 65c5f84b87..f72112cf8b 100644 --- a/samples/widgets/datepick.cpp +++ b/samples/widgets/datepick.cpp @@ -75,6 +75,9 @@ public: virtual wxControl *GetWidget() const { return m_datePicker; } virtual void RecreateWidget() { CreateDatePicker(); } + // lazy creation of the content + virtual void CreateContent(); + protected: // event handlers void OnButtonSet(wxCommandEvent& event); @@ -132,6 +135,10 @@ IMPLEMENT_WIDGETS_PAGE(DatePickerWidgetsPage, wxT("DatePicker"), DatePickerWidgetsPage::DatePickerWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist) :WidgetsPage(book, imaglist, datepick_xpm) +{ +} + +void DatePickerWidgetsPage::CreateContent() { wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); diff --git a/samples/widgets/gauge.cpp b/samples/widgets/gauge.cpp index f7cd1bb582..7093f874c4 100644 --- a/samples/widgets/gauge.cpp +++ b/samples/widgets/gauge.cpp @@ -77,6 +77,9 @@ public: virtual wxControl *GetWidget() const { return m_gauge; } virtual void RecreateWidget() { CreateGauge(); } + // lazy creation of the content + virtual void CreateContent(); + protected: // event handlers void OnButtonReset(wxCommandEvent& event); @@ -179,7 +182,10 @@ GaugeWidgetsPage::GaugeWidgetsPage(WidgetsBookCtrl *book, m_gauge = (wxGauge *)NULL; m_sizerGauge = (wxSizer *)NULL; +} +void GaugeWidgetsPage::CreateContent() +{ wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); // left pane diff --git a/samples/widgets/hyperlnk.cpp b/samples/widgets/hyperlnk.cpp index 4e4dfef198..3c2295b539 100644 --- a/samples/widgets/hyperlnk.cpp +++ b/samples/widgets/hyperlnk.cpp @@ -69,11 +69,14 @@ class HyperlinkWidgetsPage : public WidgetsPage { public: HyperlinkWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist); - virtual ~HyperlinkWidgetsPage(){}; + virtual ~HyperlinkWidgetsPage() {} virtual wxControl *GetWidget() const { return m_hyperlink; } virtual void RecreateWidget() { CreateHyperlink(); } + // lazy creation of the content + virtual void CreateContent(); + protected: // event handlers void OnButtonSetLabel(wxCommandEvent& event); @@ -128,7 +131,11 @@ IMPLEMENT_WIDGETS_PAGE(HyperlinkWidgetsPage, wxT("Hyperlink"), HyperlinkWidgetsPage::HyperlinkWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist) - :WidgetsPage(book, imaglist, hyperlnk_xpm) + :WidgetsPage(book, imaglist, hyperlnk_xpm) +{ +} + +void HyperlinkWidgetsPage::CreateContent() { wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); diff --git a/samples/widgets/listbox.cpp b/samples/widgets/listbox.cpp index 1bbd3faa46..b189d3b22b 100644 --- a/samples/widgets/listbox.cpp +++ b/samples/widgets/listbox.cpp @@ -81,6 +81,9 @@ public: virtual wxControl *GetWidget() const { return m_lbox; } virtual void RecreateWidget() { CreateLbox(); } + // lazy creation of the content + virtual void CreateContent(); + protected: // event handlers void OnButtonReset(wxCommandEvent& event); @@ -145,7 +148,7 @@ protected: #ifdef __WXWINCE__ wxListBoxBase #else - wxListBox + wxListBox #endif *m_lbox; @@ -225,6 +228,10 @@ ListboxWidgetsPage::ListboxWidgetsPage(WidgetsBookCtrl *book, m_lbox = NULL; m_sizerLbox = (wxSizer *)NULL; +} + +void ListboxWidgetsPage::CreateContent() +{ /* What we create here is a frame having 3 panes: style pane is the leftmost one, in the middle the pane with buttons allowing to perform diff --git a/samples/widgets/notebook.cpp b/samples/widgets/notebook.cpp index 21cdf14029..4d6902cb3e 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); @@ -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 @@ -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("%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)) diff --git a/samples/widgets/picker.cpp b/samples/widgets/picker.cpp index 74eab9c1c8..8ed727ab7f 100644 --- a/samples/widgets/picker.cpp +++ b/samples/widgets/picker.cpp @@ -90,6 +90,9 @@ public: virtual wxControl *GetWidget() const { return m_filePicker; } virtual void RecreateWidget() { RecreateAllPickers(); } + // lazy creation of the content + virtual void CreateContent(); + protected: enum PickerKind { @@ -206,6 +209,10 @@ IMPLEMENT_WIDGETS_PAGE(PickerWidgetsPage, _T("Pickers"), PickerWidgetsPage::PickerWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist) : WidgetsPage(book, imaglist, picker_xpm) +{ +} + +void PickerWidgetsPage::CreateContent() { // left pane wxSizer *boxleft = new wxBoxSizer(wxVERTICAL); diff --git a/samples/widgets/radiobox.cpp b/samples/widgets/radiobox.cpp index 9f647fd92e..a4e73f24cc 100644 --- a/samples/widgets/radiobox.cpp +++ b/samples/widgets/radiobox.cpp @@ -89,6 +89,9 @@ public: virtual wxControl *GetWidget() const { return m_radio; } virtual void RecreateWidget() { CreateRadio(); } + // lazy creation of the content + virtual void CreateContent(); + protected: // event handlers void OnCheckOrRadioBox(wxCommandEvent& event); @@ -199,7 +202,10 @@ RadioWidgetsPage::RadioWidgetsPage(WidgetsBookCtrl *book, m_radio = m_radioDir = (wxRadioBox *)NULL; m_sizerRadio = (wxSizer *)NULL; +} +void RadioWidgetsPage::CreateContent() +{ wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); // left pane diff --git a/samples/widgets/slider.cpp b/samples/widgets/slider.cpp index 4502d6c871..ec7b0bf604 100644 --- a/samples/widgets/slider.cpp +++ b/samples/widgets/slider.cpp @@ -95,6 +95,9 @@ public: virtual wxControl *GetWidget() const { return m_slider; } virtual void RecreateWidget() { CreateSlider(); } + // lazy creation of the content + virtual void CreateContent(); + protected: // event handlers void OnButtonReset(wxCommandEvent& event); @@ -223,7 +226,10 @@ SliderWidgetsPage::SliderWidgetsPage(WidgetsBookCtrl *book, m_slider = (wxSlider *)NULL; m_sizerSlider = (wxSizer *)NULL; +} +void SliderWidgetsPage::CreateContent() +{ wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); // left pane diff --git a/samples/widgets/spinbtn.cpp b/samples/widgets/spinbtn.cpp index 125d533bf3..e5c7fc444c 100644 --- a/samples/widgets/spinbtn.cpp +++ b/samples/widgets/spinbtn.cpp @@ -80,6 +80,9 @@ public: virtual wxControl *GetWidget2() const { return m_spinctrl; } virtual void RecreateWidget() { CreateSpin(); } + // lazy creation of the content + virtual void CreateContent(); + protected: // event handlers void OnButtonReset(wxCommandEvent& event); @@ -197,7 +200,10 @@ SpinBtnWidgetsPage::SpinBtnWidgetsPage(WidgetsBookCtrl *book, m_spinbtn = (wxSpinButton *)NULL; m_sizerSpin = (wxSizer *)NULL; +} +void SpinBtnWidgetsPage::CreateContent() +{ wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); // left pane diff --git a/samples/widgets/static.cpp b/samples/widgets/static.cpp index 05c1366909..e9360497b0 100644 --- a/samples/widgets/static.cpp +++ b/samples/widgets/static.cpp @@ -145,6 +145,9 @@ public: virtual wxControl *GetWidget() const { return m_statText; } virtual void RecreateWidget() { CreateStatic(); } + // lazy creation of the content + virtual void CreateContent(); + protected: // event handlers void OnCheckOrRadioBox(wxCommandEvent& event); @@ -227,7 +230,10 @@ StaticWidgetsPage::StaticWidgetsPage(WidgetsBookCtrl *book, m_staticBox = (wxStaticBox *)NULL; m_sizerStatBox = (wxStaticBoxSizer *)NULL; m_sizerStatic = (wxSizer *)NULL; +} +void StaticWidgetsPage::CreateContent() +{ wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); // left pane diff --git a/samples/widgets/textctrl.cpp b/samples/widgets/textctrl.cpp index 87bf0c0cfa..0d2e8e293c 100644 --- a/samples/widgets/textctrl.cpp +++ b/samples/widgets/textctrl.cpp @@ -138,6 +138,9 @@ public: virtual wxControl *GetWidget() const { return m_text; } virtual void RecreateWidget() { CreateText(); } + // lazy creation of the content + virtual void CreateContent(); + protected: // create an info text contorl wxTextCtrl *CreateInfoText(); @@ -374,7 +377,10 @@ TextWidgetsPage::TextWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist) m_posLast = m_selFrom = m_selTo = -2; // not -1 which means "no selection" +} +void TextWidgetsPage::CreateContent() +{ // left pane static const wxString modes[] = { diff --git a/samples/widgets/toggle.cpp b/samples/widgets/toggle.cpp index 214474f7ad..6c4734d7ab 100644 --- a/samples/widgets/toggle.cpp +++ b/samples/widgets/toggle.cpp @@ -64,6 +64,9 @@ public: virtual wxControl *GetWidget() const { return m_toggle; } virtual void RecreateWidget() { CreateToggle(); } + // lazy creation of the content + virtual void CreateContent(); + protected: // event handlers void OnButtonReset(wxCommandEvent& event); @@ -116,6 +119,10 @@ IMPLEMENT_WIDGETS_PAGE(ToggleWidgetsPage, wxT("ToggleButton"), ToggleWidgetsPage::ToggleWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist) :WidgetsPage(book, imaglist, toggle_xpm) +{ +} + +void ToggleWidgetsPage::CreateContent() { wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); diff --git a/samples/widgets/widgets.cpp b/samples/widgets/widgets.cpp index 8287db11ae..3e7ab3663b 100644 --- a/samples/widgets/widgets.cpp +++ b/samples/widgets/widgets.cpp @@ -48,6 +48,7 @@ #include "wx/fontdlg.h" #include "wx/textdlg.h" #include "wx/imaglist.h" +#include "wx/wupdlock.h" #include "widgets.h" @@ -567,12 +568,17 @@ void WidgetsFrame::InitBook() WidgetsPage *WidgetsFrame::CurrentPage() { + wxWindow *page = m_book->GetCurrentPage(); + if(!page) return NULL; + #if USE_TREEBOOK - return wxStaticCast(m_book->GetCurrentPage(), WidgetsPage); + return wxStaticCast(page, WidgetsPage); #else - WidgetsBookCtrl *book = wxStaticCast(m_book->GetCurrentPage(), WidgetsBookCtrl); - if (!book) return NULL; - return wxStaticCast(book->GetCurrentPage(), WidgetsPage); + WidgetsBookCtrl *subBook = wxStaticCast(page, WidgetsBookCtrl); + if (!subBook) return NULL; + page = subBook->GetCurrentPage(); + if(!page) return NULL; + return wxStaticCast(page, WidgetsPage); #endif } @@ -603,8 +609,29 @@ void WidgetsFrame::OnButtonClearLog(wxCommandEvent& WXUNUSED(event)) void WidgetsFrame::OnPageChanged(WidgetsBookCtrlEvent& event) { + // adjust "Page" menu selection wxMenuItem *item = GetMenuBar()->FindItem(Widgets_GoToPage + event.GetSelection()); if (item) item->Check(); + + // lazy creation of the pages + WidgetsPage* page = CurrentPage(); + if (page && (page->GetChildren().GetCount()==0)) + { + wxWindowUpdateLocker noUpdates(page); + page->CreateContent(); + WidgetsBookCtrl *book = wxStaticCast(page->GetParent(), WidgetsBookCtrl); + wxSize size; + for ( size_t i = 0; i < book->GetPageCount(); ++i ) + { + wxWindow *page = book->GetPage(i); + if (page) + { + size.IncTo(page->GetSize()); + } + } + page->SetSize(size); + } + event.Skip(); } diff --git a/samples/widgets/widgets.h b/samples/widgets/widgets.h index ca2a8e7cca..0aca377a0b 100644 --- a/samples/widgets/widgets.h +++ b/samples/widgets/widgets.h @@ -98,6 +98,9 @@ public: // return the control shown by this page virtual wxControl *GetWidget() const = 0; + // lazy creation of the content + virtual void CreateContent() = 0; + // some pages show 2 controls, in this case override this one as well virtual wxControl *GetWidget2() const { return NULL; } -- 2.47.2