]> git.saurik.com Git - wxWidgets.git/commitdiff
Use GetWidgets() in the widgets samples instead of GetWidget2().
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 13 May 2010 15:31:30 +0000 (15:31 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 13 May 2010 15:31:30 +0000 (15:31 +0000)
Add a function which can be overridden to return an arbitrary number of
widgets instead of having just GetWidget() and GetWidget2(): spin control page
already uses 3 widgets (and defines GetWidget3() which is never called) and we
could have even more in the future. Just use a generic solution which will
always work.

The practical consequence of this is that the "Enable/Disable" menu item now
also enables and disables the wxSpinCtrlDouble in the spin page, see #12045.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64301 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/widgets/spinbtn.cpp
samples/widgets/widgets.cpp
samples/widgets/widgets.h

index 347b1039c13998ef84e5fe9d420e4e0930c21558..c5b506f504496c3adc3601ed6da9f8d177d27f67 100644 (file)
@@ -86,8 +86,14 @@ public:
     virtual ~SpinBtnWidgetsPage(){};
 
     virtual wxControl *GetWidget() const { return m_spinbtn; }
-    virtual wxControl *GetWidget2() const { return m_spinctrl; }
-    virtual wxControl *GetWidget3() const { return m_spinctrldbl; }
+    virtual Widgets GetWidgets() const
+    {
+        Widgets widgets(WidgetsPage::GetWidgets());
+        widgets.push_back(m_spinctrl);
+        widgets.push_back(m_spinctrldbl);
+        return widgets;
+    }
+
     virtual void RecreateWidget() { CreateSpin(); }
 
     // lazy creation of the content
index 3e3b2b23affe8f6d1b9f9e268b72862a83109c77..53a7b37016fe6fb9a89deb1a23e131506afd9bf3 100644 (file)
@@ -755,11 +755,13 @@ void WidgetsFrame::OnSetTooltip(wxCommandEvent& WXUNUSED(event))
 
     WidgetsPage *page = CurrentPage();
 
-    page->GetWidget()->SetToolTip(s_tip);
-
-    wxControl *ctrl2 = page->GetWidget2();
-    if ( ctrl2 )
-        ctrl2->SetToolTip(s_tip);
+    const Widgets widgets = page->GetWidgets();
+    for ( Widgets::const_iterator it = widgets.begin();
+          it != widgets.end();
+          ++it )
+    {
+        (*it)->SetToolTip(s_tip);
+    }
 }
 
 #endif // wxUSE_TOOLTIPS
@@ -779,14 +781,13 @@ void WidgetsFrame::OnSetFgCol(wxCommandEvent& WXUNUSED(event))
 
     m_colFg = col;
 
-    page->GetWidget()->SetForegroundColour(m_colFg);
-    page->GetWidget()->Refresh();
-
-    wxControl *ctrl2 = page->GetWidget2();
-    if ( ctrl2 )
+    const Widgets widgets = page->GetWidgets();
+    for ( Widgets::const_iterator it = widgets.begin();
+          it != widgets.end();
+          ++it )
     {
-        ctrl2->SetForegroundColour(m_colFg);
-        ctrl2->Refresh();
+        (*it)->SetForegroundColour(m_colFg);
+        (*it)->Refresh();
     }
 #else
     wxLogMessage(wxT("Colour selection dialog not available in current build."));
@@ -807,14 +808,13 @@ void WidgetsFrame::OnSetBgCol(wxCommandEvent& WXUNUSED(event))
 
     m_colBg = col;
 
-    page->GetWidget()->SetBackgroundColour(m_colBg);
-    page->GetWidget()->Refresh();
-
-    wxControl *ctrl2 = page->GetWidget2();
-    if ( ctrl2 )
+    const Widgets widgets = page->GetWidgets();
+    for ( Widgets::const_iterator it = widgets.begin();
+          it != widgets.end();
+          ++it )
     {
-        ctrl2->SetBackgroundColour(m_colFg);
-        ctrl2->Refresh();
+        (*it)->SetBackgroundColour(m_colBg);
+        (*it)->Refresh();
     }
 #else
     wxLogMessage(wxT("Colour selection dialog not available in current build."));
@@ -835,14 +835,13 @@ void WidgetsFrame::OnSetFont(wxCommandEvent& WXUNUSED(event))
 
     m_font = font;
 
-    page->GetWidget()->SetFont(m_font);
-    page->GetWidget()->Refresh();
-
-    wxControl *ctrl2 = page->GetWidget2();
-    if ( ctrl2 )
+    const Widgets widgets = page->GetWidgets();
+    for ( Widgets::const_iterator it = widgets.begin();
+          it != widgets.end();
+          ++it )
     {
-        ctrl2->SetFont(m_font);
-        ctrl2->Refresh();
+        (*it)->SetFont(m_font);
+        (*it)->Refresh();
     }
 #else
     wxLogMessage(wxT("Font selection dialog not available in current build."));
@@ -851,9 +850,13 @@ void WidgetsFrame::OnSetFont(wxCommandEvent& WXUNUSED(event))
 
 void WidgetsFrame::OnEnable(wxCommandEvent& event)
 {
-    CurrentPage()->GetWidget()->Enable(event.IsChecked());
-    if (CurrentPage()->GetWidget2())
-        CurrentPage()->GetWidget2()->Enable(event.IsChecked());
+    const Widgets widgets = CurrentPage()->GetWidgets();
+    for ( Widgets::const_iterator it = widgets.begin();
+          it != widgets.end();
+          ++it )
+    {
+        (*it)->Enable(event.IsChecked());
+    }
 }
 
 void WidgetsFrame::OnSetBorder(wxCommandEvent& event)
@@ -893,9 +896,16 @@ void WidgetsFrame::OnToggleGlobalBusyCursor(wxCommandEvent& event)
 
 void WidgetsFrame::OnToggleBusyCursor(wxCommandEvent& event)
 {
-    CurrentPage()->GetWidget()->SetCursor(*(event.IsChecked()
-                                                ? wxHOURGLASS_CURSOR
-                                                : wxSTANDARD_CURSOR));
+    wxCursor cursor(*(event.IsChecked() ? wxHOURGLASS_CURSOR
+                                        : wxSTANDARD_CURSOR));
+
+    const Widgets widgets = CurrentPage()->GetWidgets();
+    for ( Widgets::const_iterator it = widgets.begin();
+          it != widgets.end();
+          ++it )
+    {
+        (*it)->SetCursor(cursor);
+    }
 }
 
 void WidgetsFrame::OnDisableAutoComplete(wxCommandEvent& WXUNUSED(event))
index 2420bbe567fd13e3519751d861eb6b42de40215f..d82b03d1bb45b2dc66d03beae7484fc187224d63 100644 (file)
@@ -52,6 +52,7 @@ class WXDLLIMPEXP_FWD_CORE WidgetsBookCtrl;
 class WidgetsPageInfo;
 
 #include "wx/panel.h"
+#include "wx/vector.h"
 
 // INTRODUCING NEW PAGES DON'T FORGET TO ADD ENTRIES TO 'WidgetsCategories'
 enum
@@ -83,6 +84,8 @@ enum
     ALL_CTRLS        = 1 << ALL_PAGE
 };
 
+typedef wxVector<wxControl *> Widgets;
+
 // ----------------------------------------------------------------------------
 // WidgetsPage: a book page demonstrating some widget
 // ----------------------------------------------------------------------------
@@ -103,8 +106,14 @@ public:
     // 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; }
+    // some pages show additional controls, in this case override this one to
+    // return all of them (including the one returned by GetWidget())
+    virtual Widgets GetWidgets() const
+    {
+        Widgets widgets;
+        widgets.push_back(GetWidget());
+        return widgets;
+    }
 
     // recreate the control shown by this page
     //