diff --git a/port/mfcwx/src/snapshot.cpp b/port/mfcwx/src/snapshot.cpp index 68559456..3acd640b 100644 --- a/port/mfcwx/src/snapshot.cpp +++ b/port/mfcwx/src/snapshot.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -88,6 +89,33 @@ std::string SafeName(const wxString& title) { return name.substr(0, 40); } +wxAuiTabCtrl* FindTabCtrl(wxWindow* w) { + if (auto* t = wxDynamicCast(w, wxAuiTabCtrl)) + return t; + for (wxWindow* c : w->GetChildren()) + if (wxAuiTabCtrl* t = FindTabCtrl(c)) + return t; + return nullptr; +} + +void ClickTab(int index, bool closeButton) { + wxWindow* main = MainWxWindow(); + wxAuiTabCtrl* tabs = main ? FindTabCtrl(main) : nullptr; + if (!tabs || index < 0 || static_cast(index) >= tabs->GetPageCount()) { + fprintf(stderr, "mfcwx automation: no tab %d\n", index); + return; + } + wxRect r = tabs->GetPage(static_cast(index)).rect; + wxPoint pt = closeButton ? wxPoint(r.GetRight() - 12, r.y + r.height / 2) : wxPoint(r.x + r.width / 3, r.y + r.height / 2); + for (wxEventType type : {wxEVT_MOTION, wxEVT_LEFT_DOWN, wxEVT_LEFT_UP}) { + wxMouseEvent e(type); + e.SetEventObject(tabs); + e.SetPosition(pt); + e.m_leftDown = type == wxEVT_LEFT_DOWN; + tabs->GetEventHandler()->ProcessEvent(e); + } +} + wxWindow* ActiveDialog() { wxWindow* found = nullptr; for (wxWindow* w : wxTopLevelWindows) { @@ -102,6 +130,8 @@ wxWindow* ActiveDialog() { // command WM_COMMAND to the main window // button WM_COMMAND (BN_CLICKED) to the topmost dialog // text sets the text of a control of the topmost dialog +// tab / closetab clicks the n-th MDI tab or its close button +// tabs print the MDI tabs // wait // snapshot