lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [6113] Add a helper for finding an MVC window by name


From: Greg Chicares
Subject: [lmi-commits] [6113] Add a helper for finding an MVC window by name
Date: Sun, 01 Mar 2015 17:47:18 +0000

Revision: 6113
          http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=6113
Author:   chicares
Date:     2015-03-01 17:47:17 +0000 (Sun, 01 Mar 2015)
Log Message:
-----------
Add a helper for finding an MVC window by name

Modified Paths:
--------------
    lmi/trunk/ChangeLog
    lmi/trunk/main_wx_test.cpp
    lmi/trunk/wx_test_new.hpp
    lmi/trunk/wx_test_paste_census.cpp
    lmi/trunk/wx_test_validate_output.cpp

Modified: lmi/trunk/ChangeLog
===================================================================
--- lmi/trunk/ChangeLog 2015-03-01 17:29:17 UTC (rev 6112)
+++ lmi/trunk/ChangeLog 2015-03-01 17:47:17 UTC (rev 6113)
@@ -35688,3 +35688,12 @@
 Remove old code to make way for new. See:
   http://lists.nongnu.org/archive/html/lmi/2015-02/msg00012.html
 
+20150301T1747Z <address@hidden> [516]
+
+  main_wx_test.cpp
+  wx_test_new.hpp
+  wx_test_paste_census.cpp
+  wx_test_validate_output.cpp
+Add a helper for finding an MVC window by name. See:
+  http://lists.nongnu.org/archive/html/lmi/2015-02/msg00012.html
+

Modified: lmi/trunk/main_wx_test.cpp
===================================================================
--- lmi/trunk/main_wx_test.cpp  2015-03-01 17:29:17 UTC (rev 6112)
+++ lmi/trunk/main_wx_test.cpp  2015-03-01 17:47:17 UTC (rev 6113)
@@ -27,6 +27,7 @@
 #endif
 
 #include "alert.hpp"
+#include "assert_lmi.hpp"
 #include "docmanager_ex.hpp"
 #include "force_linking.hpp"
 #include "handle_exceptions.hpp"        // stealth_exception
@@ -37,6 +38,7 @@
 #include "skeleton.hpp"
 #include "uncopyable_lmi.hpp"
 #include "wx_test_case.hpp"
+#include "wx_test_new.hpp"
 
 #include <wx/docview.h>
 #include <wx/fileconf.h>
@@ -577,6 +579,56 @@
         }
 }
 
+wxWindow* wx_test_focus_controller_child(MvcController& dialog, char const* 
name)
+{
+    // First find the window anywhere inside the dialog.
+    wxWindow* const w = wxWindow::FindWindowByName(name, &dialog);
+    LMI_ASSERT_WITH_MSG(w, "window named \"" << name << "\" not found");
+
+    // Then find the book control containing it by walking up the window chain
+    // until we reach it.
+    for (wxWindow* maybe_page = w;;)
+        {
+        wxWindow* const maybe_book = maybe_page->GetParent();
+
+        // As we know that w is a descendant of the dialog, this check ensures
+        // that the loop terminates as sooner or later we must reach the dialog
+        // by walking up the parent chain.
+        LMI_ASSERT_WITH_MSG
+            (maybe_book != &dialog
+            ,"book control containing window \"" << name << "\" not found"
+            );
+
+        if (wxBookCtrlBase* const book = 
dynamic_cast<wxBookCtrlBase*>(maybe_book))
+            {
+            // We found the notebook, now we can use it to make the page
+            // containing the target window current.
+            size_t const num_pages = book->GetPageCount();
+            for (size_t n = 0; n < num_pages; n++)
+                {
+                if (book->GetPage(n) == maybe_page)
+                    {
+                    book->SetSelection(n);
+                    wxYield();
+
+                    break;
+                    }
+                }
+
+            break;
+            }
+
+        maybe_page = maybe_book;
+        }
+
+    // Finally set the focus to the target window and ensure all events
+    // generated because of this are processed.
+    w->SetFocus();
+    wxYield();
+
+    return w;
+}
+
 // Application to drive the tests
 class SkeletonTest : public Skeleton
 {

Modified: lmi/trunk/wx_test_new.hpp
===================================================================
--- lmi/trunk/wx_test_new.hpp   2015-03-01 17:29:17 UTC (rev 6112)
+++ lmi/trunk/wx_test_new.hpp   2015-03-01 17:47:17 UTC (rev 6113)
@@ -35,6 +35,15 @@
 
 #include <exception>
 
+/// Helper function for finding and focusing a control with the specified name
+/// inside MvcController (actually it could be any top level window containing
+/// a book control).
+///
+/// Returns the never null pointer to the window.
+///
+/// Throws if the control couldn't be found.
+wxWindow* wx_test_focus_controller_child(MvcController& dialog, char const* 
name);
+
 /// Helper base class for classes testing creation of specific new documents.
 ///
 /// This class provides methods for closing the current document, optionally

Modified: lmi/trunk/wx_test_paste_census.cpp
===================================================================
--- lmi/trunk/wx_test_paste_census.cpp  2015-03-01 17:29:17 UTC (rev 6112)
+++ lmi/trunk/wx_test_paste_census.cpp  2015-03-01 17:47:17 UTC (rev 6113)
@@ -288,36 +288,19 @@
             dialog->Show();
             wxYield();
 
-            wxUIActionSimulator ui;
-
-            // Go to the third page: as the dialog remembers its last opened
-            // page, ensure that we start from the first one.
-            ui.Char(WXK_HOME);
-            ui.Char(WXK_RIGHT);
-            ui.Char(WXK_RIGHT);
-            wxYield();
-
             // We can't find directly the radio button we're interested in,
             // because it's not a real wxWindow, so we need to find the radio
             // box containing it.
-            wxWindow* const gender_window = wxWindow::FindWindowByName
-                ("Gender"
-                ,dialog
+            wxWindow* const gender_window = wx_test_focus_controller_child
+                (*dialog
+                ,"Gender"
                 );
-            LMI_ASSERT(gender_window);
 
             wxRadioBox* const
                 gender_radiobox = dynamic_cast<wxRadioBox*>(gender_window);
             LMI_ASSERT(gender_radiobox);
 
-            // It's difficult to select the radiobox using just
-            // wxUIActionSimulator as there is no keyboard shortcut to navigate
-            // to it and emulating a mouse click on it is tricky as we don't
-            // want to change its selection by clicking on the item, so do it
-            // programmatically, the effect should be absolutely the same.
-            gender_radiobox->SetFocus();
-            wxYield();
-
+            wxUIActionSimulator ui;
             ui.Char(WXK_DOWN); // Select the last, "Unisex", radio button.
             wxYield();
 
@@ -372,36 +355,19 @@
             dialog->Show();
             wxYield();
 
-            wxUIActionSimulator ui;
-
-            // Go to the third page: as the dialog remembers its last opened
-            // page, ensure that we start from the first one.
-            ui.Char(WXK_HOME);
-            ui.Char(WXK_RIGHT);
-            ui.Char(WXK_RIGHT);
-            wxYield();
-
             // We can't find directly the radio button we're interested in,
             // because it's not a real wxWindow, so we need to find the radio
             // box containing it.
-            wxWindow* const class_window = wxWindow::FindWindowByName
-                ("UnderwritingClass"
-                ,dialog
+            wxWindow* const class_window = wx_test_focus_controller_child
+                (*dialog
+                ,"UnderwritingClass"
                 );
-            LMI_ASSERT(class_window);
 
             wxRadioBox* const
                 class_radiobox = dynamic_cast<wxRadioBox*>(class_window);
             LMI_ASSERT(class_radiobox);
 
-            // It's difficult to select the radiobox using just
-            // wxUIActionSimulator as there is no keyboard shortcut to navigate
-            // to it and emulating a mouse click on it is tricky as we don't
-            // want to change its selection by clicking on the item, so do it
-            // programmatically, the effect should be absolutely the same.
-            class_radiobox->SetFocus();
-            wxYield();
-
+            wxUIActionSimulator ui;
             ui.Char(WXK_UP); // Select the first, "Preferred", radio button.
             wxYield();
 

Modified: lmi/trunk/wx_test_validate_output.cpp
===================================================================
--- lmi/trunk/wx_test_validate_output.cpp       2015-03-01 17:29:17 UTC (rev 
6112)
+++ lmi/trunk/wx_test_validate_output.cpp       2015-03-01 17:47:17 UTC (rev 
6113)
@@ -141,25 +141,9 @@
             dialog->Show();
             wxYield();
 
-            wxUIActionSimulator ui;
+            wx_test_focus_controller_child(*dialog, "Comments");
 
-            // Go to the first page: as the dialog remembers its last opened
-            // page, ensure that we are always on the one we need.
-            ui.Char(WXK_HOME);
-            wxYield();
-
-            // It is difficult to focus the text entry that we're interested
-            // directly from keyboard, so cheat a little and focus it
-            // programmatically.
-            wxWindow* const comments = wxWindow::FindWindowByName
-                ("Comments"
-                ,dialog
-                );
-            LMI_ASSERT(comments);
-
-            comments->SetFocus();
-            wxYield();
-
+            wxUIActionSimulator ui;
             ui.Text("idiosyncrasyZ");
             wxYield();
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]