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
This commit is contained in:
Włodzimierz Skiba 2006-06-06 14:10:06 +00:00
parent 3f60522a05
commit 453535a739
17 changed files with 151 additions and 15 deletions

View File

@ -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

View File

@ -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);

View File

@ -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)

View File

@ -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);

View File

@ -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

View File

@ -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);

View File

@ -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

View 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
@ -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))

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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[] =
{

View File

@ -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);

View File

@ -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();
}

View File

@ -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; }