From be7d3636b83d138f80f4cc1b88a548b79bdb0c54 Mon Sep 17 00:00:00 2001 From: Kamil Marczak Date: Thu, 8 Oct 2026 15:35:11 +0200 Subject: [PATCH] feat(mfcwx): click and list MDI tabs from automation scripts MFCWX_AUTOMATION gains tab and closetab , which send mouse clicks to the n-th MDI tab or its close button, and tabs, which prints the open tabs and marks the active one. --- port/mfcwx/src/snapshot.cpp | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) 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