]> git.saurik.com Git - wxWidgets.git/commitdiff
Use Connect() of Bind() in the new part of xrc sample.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 7 Nov 2010 19:33:30 +0000 (19:33 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 7 Nov 2010 19:33:30 +0000 (19:33 +0000)
Use Connect() for compatibility (notably with VC6 which doesn't support
Bind()). Also connect the event handlers on loading the dialog instead of
waiting until the relevant page is selected, this makes the code slightly
simpler as we don't need to remember whether we connected them or not any
longer.

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

samples/xrc/objrefdlg.cpp
samples/xrc/objrefdlg.h

index 8fbb22acd3513b6ede1d347b9f2c32ae95235431..ef2c827ba42f63c7c2a5212a7ffd14ad48dfe052 100644 (file)
@@ -47,9 +47,41 @@ ObjrefDialog::ObjrefDialog(wxWindow* parent)
 
     nb = XRCCTRL(*this, "objref_notebook", wxNotebook);
     wxCHECK_RET(nb, "failed to find objref_notebook");
 
     nb = XRCCTRL(*this, "objref_notebook", wxNotebook);
     wxCHECK_RET(nb, "failed to find objref_notebook");
-    nb->Bind(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, &ObjrefDialog::OnNotebookPageChanged, this);
-    iconspage_bound = false;
-    calcpage_bound = false;
+
+    // Connect different event handlers.
+    nb->Connect(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,
+                wxNotebookEventHandler(ObjrefDialog::OnNotebookPageChanged),
+                NULL, this);
+
+    // We want to direct UpdateUI events for the ID range 'first_row' to
+    // OnUpdateUIFirst(). We could achieve this using first_row[0] and
+    // first_row[2], but what if a fourth column were added? It's safer to use
+    // the 'typedefs' for the two ends of the range:
+    wxNotebookPage *page = nb->GetPage(icons_page);
+    page->Connect(XRCID("first_row[start]"), XRCID("first_row[end]"),
+                  wxEVT_UPDATE_UI,
+                  wxUpdateUIEventHandler(ObjrefDialog::OnUpdateUIFirst),
+                  NULL, this);
+    page->Connect(XRCID("second_row[start]"), XRCID("second_row[end]"),
+                  wxEVT_UPDATE_UI,
+                  wxUpdateUIEventHandler(ObjrefDialog::OnUpdateUISecond),
+                  NULL, this);
+    page->Connect(XRCID("third_row[start]"), XRCID("third_row[end]"),
+                  wxEVT_UPDATE_UI,
+                  wxUpdateUIEventHandler(ObjrefDialog::OnUpdateUIThird),
+                  NULL, this);
+
+    // Connect the id ranges, using the [start] and [end] 'typedefs'
+    page = nb->GetPage(calc_page);
+    page->Connect(XRCID("digits[start]"), XRCID("digits[end]"),
+                  wxEVT_COMMAND_BUTTON_CLICKED,
+                  wxCommandEventHandler(ObjrefDialog::OnNumeralClick),
+                  NULL, this);
+    page->Connect(XRCID("operators[start]"), XRCID("operators[end]"),
+                  wxEVT_COMMAND_BUTTON_CLICKED,
+                  wxCommandEventHandler(ObjrefDialog::OnOperatorClick),
+                  NULL, this);
+
 }
 
 ObjrefDialog::~ObjrefDialog()
 }
 
 ObjrefDialog::~ObjrefDialog()
@@ -87,22 +119,6 @@ void ObjrefDialog::OnNotebookPageChanged( wxNotebookEvent &event )
         case icons_page:
             {
                 wxNotebookPage *page = nb->GetPage(icons_page);
         case icons_page:
             {
                 wxNotebookPage *page = nb->GetPage(icons_page);
-                if (!iconspage_bound)
-                {
-                    iconspage_bound = true;
-                    // We want to direct UpdateUI events for the ID range 'first_row' to OnUpdateUIFirst().
-                    // We could achieve this using first_row[0] and first_row[2], but what if a fourth
-                    // column were added? It's safer to use the 'typedefs' for the two ends of the range:
-                    page->Bind(wxEVT_UPDATE_UI, &ObjrefDialog::OnUpdateUIFirst,
-                        this, XRCID("first_row[start]"), XRCID("first_row[end]"));
-                    // Similarly for the other two rows
-                    page->Bind(wxEVT_UPDATE_UI, &ObjrefDialog::OnUpdateUISecond,
-                        this, XRCID("second_row[start]"), XRCID("second_row[end]"));
-                    page->Bind(wxEVT_UPDATE_UI, &ObjrefDialog::OnUpdateUIThird,
-                        this, XRCID("third_row[start]"), XRCID("third_row[end]"));
-
-                }
-
                 text = XRCCTRL(*page, "log_text", wxTextCtrl);
                 if (text)
                     delete wxLog::SetActiveTarget(new wxLogTextCtrl(text));
                 text = XRCCTRL(*page, "log_text", wxTextCtrl);
                 if (text)
                     delete wxLog::SetActiveTarget(new wxLogTextCtrl(text));
@@ -112,16 +128,6 @@ void ObjrefDialog::OnNotebookPageChanged( wxNotebookEvent &event )
         case calc_page:
             {
                 wxNotebookPage *page = nb->GetPage(calc_page);
         case calc_page:
             {
                 wxNotebookPage *page = nb->GetPage(calc_page);
-                if (!calcpage_bound)
-                {
-                    calcpage_bound = true;
-                    // Bind the id ranges, using the [start] and [end] 'typedefs'
-                    page->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &ObjrefDialog::OnNumeralClick,
-                        this, XRCID("digits[start]"), XRCID("digits[end]"));
-                    page->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &ObjrefDialog::OnOperatorClick,
-                        this, XRCID("operators[start]"), XRCID("operators[end]"));
-                }
-
                 result_txt = XRCCTRL(*page, "result", wxTextCtrl);
                 text = XRCCTRL(*page, "log_text", wxTextCtrl);
                 if (text)
                 result_txt = XRCCTRL(*page, "result", wxTextCtrl);
                 text = XRCCTRL(*page, "log_text", wxTextCtrl);
                 if (text)
index da97d664f956339cf51e76c80d6d33ca448e4137..2bddaef27529feb79dd66caac05043b2f9481bcd 100644 (file)
@@ -52,8 +52,6 @@ private:
     wxNotebook *nb;
     wxTextCtrl *text;
     wxTextCtrl *result_txt;
     wxNotebook *nb;
     wxTextCtrl *text;
     wxTextCtrl *result_txt;
-    bool iconspage_bound;
-    bool calcpage_bound;
     int current;
     int previous;
     bool operator_expected;
     int current;
     int previous;
     bool operator_expected;