]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/xrc/objrefdlg.cpp
Skip EVT_RIGHT_UP event in wxHtmlWindow if it wasn't handled.
[wxWidgets.git] / samples / xrc / objrefdlg.cpp
index 8fbb22acd3513b6ede1d347b9f2c32ae95235431..3421f2dc8f8fad3dbcfba29324ef1975f3ce2aa8 100644 (file)
@@ -31,7 +31,7 @@
 #include "objrefdlg.h"
 
 //-----------------------------------------------------------------------------
-// Remaining headers: Needed wx headers, then wx/contrib headers, then application headers
+// Needed wx headers,
 //-----------------------------------------------------------------------------
 
 #include "wx/xrc/xmlres.h"              // XRC XML resouces
@@ -47,15 +47,48 @@ ObjrefDialog::ObjrefDialog(wxWindow* parent)
 
     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()
 {
-    // Select page 0. Otherwise if the Calc page were selected, when it's removed the Icons page is selected
-    // and sets the log target again in idle time, *after* myframe restores the old one!
+    // Select page 0. Otherwise if the Calc page were selected, when it's
+    // removed the Icons page is selected and sets the log target again in idle
+    // time, *after* myframe restores the old one!
     nb->ChangeSelection(0);
 }
 
@@ -73,13 +106,14 @@ void ObjrefDialog::OnNotebookPageChanged( wxNotebookEvent &event )
                 nb->SetPageText(copy_page, "Page 1 copy");
 
                 wxNotebookPage *page = nb->GetPage(copy_page);
-                wxTextCtrl *text = XRCCTRL(*page, "description_text", wxTextCtrl);
+                wxTextCtrl *
+                    text = XRCCTRL(*page, "description_text", wxTextCtrl);
                 text->ChangeValue(
-                    wxString("This is a duplicate of page 1, using an object reference. ")
-                    + wxString("It was created by this very simple xml:\n\n")
-                    + wxString("<object class=\"notebookpage\">\n\t<object_ref ref=\"page1\"/>\n")
-                    + wxString("\t<label>Page 1 copy</label>\n</object>")
-                    + wxString("\n\n(Then I'm cheating by inserting this text programmatically.)")
+                    "This is a duplicate of page 1, using an object reference. "
+                    "It was created by this very simple xml:\n\n"
+                    "<object class=\"notebookpage\">\n\t<object_ref ref=\"page1\"/>\n"
+                    "\t<label>Page 1 copy</label>\n</object>"
+                    "\n\n(Then I'm cheating by inserting this text programmatically.)"
                                 );
                 break;
             }
@@ -87,22 +121,6 @@ void ObjrefDialog::OnNotebookPageChanged( wxNotebookEvent &event )
         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));
@@ -112,16 +130,6 @@ void ObjrefDialog::OnNotebookPageChanged( wxNotebookEvent &event )
         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)
@@ -130,16 +138,16 @@ void ObjrefDialog::OnNotebookPageChanged( wxNotebookEvent &event )
                 ClearCalculator();
                 break;
             }
-
-         default: return;
     }
 }
 
-// There are undoubtedly simpler ways of doing all this, but we're demonstrating the use of ID ranges
+// There are undoubtedly simpler ways of doing all this, but we're
+// demonstrating the use of ID ranges
 void ObjrefDialog::OnUpdateUIFirst(wxUpdateUIEvent& event)
 {
     // The checkbox with the XRCID 'check[0]' controls this row of icons
-    wxCheckBox *chk = XRCCTRL(*(nb->GetPage(icons_page)), "check[0]", wxCheckBox);
+    wxCheckBox *
+        chk = XRCCTRL(*(nb->GetPage(icons_page)), "check[0]", wxCheckBox);
     if (chk)
         event.Enable(chk->IsChecked());
 
@@ -148,16 +156,22 @@ void ObjrefDialog::OnUpdateUIFirst(wxUpdateUIEvent& event)
     if (chk->IsChecked() != checked)
     {
         checked = chk->IsChecked();
-        wxLogMessage("Row one has been %s by check[0], XRCID = %i", checked ? "enabled" : "disabled", XRCID("check[0]"));
-        wxLogMessage("XRCIDs: first_row[start] = %i, first_row[0] = %i, first_row[1] = %i, first_row[2] = %i, first_row[end] = %i",
-            XRCID("first_row[start]"), XRCID("first_row[0]"), XRCID("first_row[1]"), XRCID("first_row[2]"), XRCID("first_row[end]"));
+        wxLogMessage("Row one has been %s by check[0], XRCID = %i",
+                     checked ? "enabled" : "disabled", XRCID("check[0]"));
+        wxLogMessage("XRCIDs: first_row[start] = %i, first_row[0] = %i, "
+                     "first_row[1] = %i, first_row[2] = %i, "
+                     "first_row[end] = %i",
+                     XRCID("first_row[start]"), XRCID("first_row[0]"),
+                     XRCID("first_row[1]"), XRCID("first_row[2]"),
+                     XRCID("first_row[end]"));
     }
 }
 
 void ObjrefDialog::OnUpdateUISecond(wxUpdateUIEvent& event)
 {
     // The checkbox with the XRCID 'check[1]' controls this row of icons
-    wxCheckBox *chk = XRCCTRL(*(nb->GetPage(icons_page)), "check[1]", wxCheckBox);
+    wxCheckBox *
+        chk = XRCCTRL(*(nb->GetPage(icons_page)), "check[1]", wxCheckBox);
     if (chk)
         event.Enable(chk->IsChecked());
 
@@ -166,16 +180,22 @@ void ObjrefDialog::OnUpdateUISecond(wxUpdateUIEvent& event)
     if (chk->IsChecked() != checked)
     {
         checked = chk->IsChecked();
-        wxLogMessage("Row two has been %s by check[1], XRCID = %i", checked ? "enabled" : "disabled", XRCID("check[1]"));
-        wxLogMessage("XRCIDs: second_row[start] = %i, second_row[0] = %i, second_row[1] = %i, second_row[2] = %i, second_row[end] = %i",
-            XRCID("second_row[start]"), XRCID("second_row[0]"), XRCID("second_row[1]"), XRCID("second_row[2]"), XRCID("second_row[end]"));
+        wxLogMessage("Row two has been %s by check[1], XRCID = %i",
+                     checked ? "enabled" : "disabled", XRCID("check[1]"));
+        wxLogMessage("XRCIDs: second_row[start] = %i, second_row[0] = %i, "
+                     "second_row[1] = %i, second_row[2] = %i, "
+                     "second_row[end] = %i",
+                     XRCID("second_row[start]"), XRCID("second_row[0]"),
+                     XRCID("second_row[1]"), XRCID("second_row[2]"),
+                     XRCID("second_row[end]"));
     }
 }
 
 void ObjrefDialog::OnUpdateUIThird(wxUpdateUIEvent& event)
 {
     // The checkbox with the XRCID 'check[2]' controls this row of icons
-    wxCheckBox *chk = XRCCTRL(*(nb->GetPage(icons_page)), "check[2]", wxCheckBox);
+    wxCheckBox *
+        chk = XRCCTRL(*(nb->GetPage(icons_page)), "check[2]", wxCheckBox);
     if (chk)
         event.Enable(chk->IsChecked());
 
@@ -184,9 +204,14 @@ void ObjrefDialog::OnUpdateUIThird(wxUpdateUIEvent& event)
     if (chk->IsChecked() != checked)
     {
         checked = chk->IsChecked();
-        wxLogMessage("Row three has been %s by check[2], XRCID = %i", checked ? "enabled" : "disabled", XRCID("check[2]"));
-        wxLogMessage("XRCIDs: third_row[start] = %i, third_row[0] = %i, third_row[1] = %i, third_row[2] = %i, third_row[end] = %i",
-            XRCID("third_row[start]"), XRCID("third_row[0]"), XRCID("third_row[1]"), XRCID("third_row[2]"), XRCID("third_row[end]"));
+        wxLogMessage("Row three has been %s by check[2], XRCID = %i",
+                     checked ? "enabled" : "disabled", XRCID("check[2]"));
+        wxLogMessage("XRCIDs: third_row[start] = %i, third_row[0] = %i, "
+                     "third_row[1] = %i, third_row[2] = %i, "
+                     "third_row[end] = %i",
+                     XRCID("third_row[start]"), XRCID("third_row[0]"),
+                     XRCID("third_row[1]"), XRCID("third_row[2]"),
+                     XRCID("third_row[end]"));
     }
 }
 
@@ -203,7 +228,8 @@ void ObjrefDialog::OnNumeralClick(wxCommandEvent& event)
     }
     else if (operator_expected == true)
     {
-        // If we've just finished one calculation, and now a digit is entered, clear
+        // If we've just finished one calculation, and now a digit is entered,
+        // clear
         ClearCalculator();
         result_txt->Clear();
     }
@@ -225,8 +251,10 @@ void ObjrefDialog::OnOperatorClick(wxCommandEvent& event)
     // We carefully used "operators[end]" as the name of the Clear button
     if (event.GetId() == XRCID("operators[end]"))
     {
-        wxLogMessage("You clicked operators[%i], XRCID %i, 'Clear'", ID, event.GetId());
-        return ClearCalculator();
+        wxLogMessage("You clicked operators[%i], XRCID %d, 'Clear'",
+                     ID, event.GetId());
+        ClearCalculator();
+        return;
     }
 
     switch(ID)
@@ -237,7 +265,8 @@ void ObjrefDialog::OnOperatorClick(wxCommandEvent& event)
         case operator_divide:
             if (current!=0 || previous!=0)
             {
-                // We're in the middle of a complex calculation, so do the first bit
+                // We're in the middle of a complex calculation, so do the
+                // first bit
                 Calculate();
             }
             curr_operator = (CalcOperator)ID;
@@ -245,7 +274,8 @@ void ObjrefDialog::OnOperatorClick(wxCommandEvent& event)
 
         case operator_equals:
             Calculate();
-            wxLogMessage("You clicked operators[%i], XRCID %i, giving a '%c'", ID, event.GetId(), symbols[ID]);
+            wxLogMessage("You clicked operators[%i], XRCID %i, giving a '%c'",
+                         ID, event.GetId(), symbols[ID]);
             curr_operator = operator_equals;
             // Flag that the next entry should be an operator, not a digit
             operator_expected = true;
@@ -254,7 +284,8 @@ void ObjrefDialog::OnOperatorClick(wxCommandEvent& event)
 
     (*result_txt) << ' ' << symbols[ID] << ' ';
 
-    wxLogMessage("You clicked operators[%i], XRCID %i, giving a '%c'", ID, event.GetId(), symbols[ID]);
+    wxLogMessage("You clicked operators[%i], XRCID %i, giving a '%c'",
+                 ID, event.GetId(), symbols[ID]);
 }
 
 void ObjrefDialog::Calculate()