]> git.saurik.com Git - wxWidgets.git/commitdiff
On-demand creation of the pages for speedup of sample launch.
authorWłodzimierz Skiba <abx@abx.art.pl>
Tue, 6 Jun 2006 14:10:06 +0000 (14:10 +0000)
committerWłodzimierz Skiba <abx@abx.art.pl>
Tue, 6 Jun 2006 14:10:06 +0000 (14:10 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39593 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

17 files changed:
samples/widgets/button.cpp
samples/widgets/checkbox.cpp
samples/widgets/combobox.cpp
samples/widgets/datepick.cpp
samples/widgets/gauge.cpp
samples/widgets/hyperlnk.cpp
samples/widgets/listbox.cpp
samples/widgets/notebook.cpp
samples/widgets/picker.cpp
samples/widgets/radiobox.cpp
samples/widgets/slider.cpp
samples/widgets/spinbtn.cpp
samples/widgets/static.cpp
samples/widgets/textctrl.cpp
samples/widgets/toggle.cpp
samples/widgets/widgets.cpp
samples/widgets/widgets.h

index 7c4dd08266772b523ebb9e58cb85ec108d818678..c06a28bf6929a29a8423549ee6922fd5de410c45 100644 (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
index 384d4156e810c25dc5e8078a4c4f253ca66d97a4..65a5c1ea4ead0b4967ed3d6420c7db913ae6c358 100644 (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);
 
index 77e8962012ff2fe1cb6886760a94b5a0b05ba844..2ac76337af76d209f2b99a49c6627040a3dc7e33 100644 (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)
index 65c5f84b8732b8689ec52743b02741e7873c0e0a..f72112cf8b7a78bc71972fa034ea2361b39f1028 100644 (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);
 
index f7cd1bb582c17749ff2f5ae9cc7469f7684b6456..7093f874c40e6a06e1e9190f8229479540cfa585 100644 (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
index 4e4dfef1984ab138a2da6362a73c4846a1ab2d53..3c2295b539e951564645d9525e8c2389cff5df95 100644 (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);
 
index 1bbd3faa46257f0f1327b31d575b32d23cb412b9..b189d3b22b55ba4915f9defc7542b6b26814c602 100644 (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
index 21cdf14029e6595360574c4a45bd217da43311aa..4d6902cb3ec2bd8e1600067ea7852ae9d576d280 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
@@ -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))
index 74eab9c1c8a5a525394fbc3f6ca8bdef8599d0ac..8ed727ab7f32cda0c53ef00bbaba0535102d532d 100644 (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);
index 9f647fd92eb0eb6f14b8a2851093232370a97c1a..a4e73f24cca788a58eeb43da0988c08e0c05a1f0 100644 (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
index 4502d6c87148532835d9472670bbe48310091a51..ec7b0bf6045a1018369e383e98a6a3b76e5b39e1 100644 (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
index 125d533bf3dd43f446d282e1eff40af4737cdb6f..e5c7fc444cadf34e02369ee7285759c75c19f282 100644 (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
index 05c13669092853523c59821707015315528d1710..e9360497b0c2ca0315dfc24218616196d2e70939 100644 (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
index 87bf0c0cfa1b6120b3a75f0122a4399b75c891b2..0d2e8e293c966b098b2a8e8e08193f0d74d9e64d 100644 (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[] =
     {
index 214474f7ade23e565e24397ee4e3b6764f905119..6c4734d7ab15c0e6c1da25041194d2ed2941d048 100644 (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);
 
index 8287db11ae9477f4fd231528b1fd263457111b78..3e7ab3663bd9902338263b48ec0de2aae928e345 100644 (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();
 }
 
index ca2a8e7cca83e89bd529bc22102d3cd0f18c84c4..0aca377a0b9acb10a525de55d6bfa6bcf646546b 100644 (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; }