offapi/com/sun/star/ui/test/XUITest.idl   |    6 ++++
 vcl/Library_vcl.mk                        |    1 
 vcl/inc/uitest/toolboxitemuiobject.hxx    |   30 ++++++++++++++++++++++++
 vcl/inc/uitest/toolboxuiobject.hxx        |    4 +++
 vcl/source/uitest/toolboxitemuiobject.cxx |   37 ++++++++++++++++++++++++++++++
 vcl/source/uitest/toolboxuiobject.cxx     |   31 +++++++++++++++++++++++++
 vcl/source/uitest/uno/uitest_uno.cxx      |   18 ++++++++++++++
 7 files changed, 127 insertions(+)

New commits:
commit b95f8892a1b87fe2130397b749a23d48e13a9e62
Author:     Michael Weghorn <[email protected]>
AuthorDate: Mon May 26 08:57:32 2025 +0200
Commit:     Michael Weghorn <[email protected]>
CommitDate: Wed May 28 09:19:43 2025 +0200

    vcl uitest: Add support for toolbar items
    
    Add new class ToolBoxItemUIObject that provides
    access to information about ToolBox (toolbar)
    items in UI tests.
    Initially, report the item's text and enabled
    state. (This can be extended as needed if there
    is a need in the future.)
    
    Extend ToolBoxUIObject to report the ToolBox
    items as children in addition to those children
    retrieved via the WindowUIObject base class logic.
    
    This will be used in an upcoming commit in
    sw/qa/uitest/table/tdf146145.py to port
    that test away from depending on a11y implementation
    details that are about to change.
    
    Change-Id: I6064ad3481e1cef694762c321e244097d8c3029b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185774
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <[email protected]>

diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 1ca6bcac969e..07537ccdfc71 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -570,6 +570,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
     vcl/source/pdf/Matrix3 \
     vcl/source/pdf/XmpMetadata \
     vcl/source/uitest/logger \
+    vcl/source/uitest/toolboxitemuiobject \
     vcl/source/uitest/toolboxuiobject \
     vcl/source/uitest/uiobject \
     vcl/source/uitest/uitest \
diff --git a/vcl/inc/uitest/toolboxitemuiobject.hxx 
b/vcl/inc/uitest/toolboxitemuiobject.hxx
new file mode 100644
index 000000000000..d6e7ecf0f1a4
--- /dev/null
+++ b/vcl/inc/uitest/toolboxitemuiobject.hxx
@@ -0,0 +1,30 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include <vcl/toolbox.hxx>
+#include <vcl/uitest/uiobject.hxx>
+
+class ToolBoxItemUIObject final : public UIObject
+{
+private:
+    VclPtr<ToolBox> m_pToolBox;
+    ToolBoxItemId m_nId;
+
+public:
+    ToolBoxItemUIObject(const VclPtr<ToolBox>& pToolBox, ToolBoxItemId nId);
+    virtual ~ToolBoxItemUIObject() override;
+
+    virtual StringMap get_state() override;
+
+    virtual bool equals(const UIObject& rOther) const override;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/vcl/inc/uitest/toolboxuiobject.hxx 
b/vcl/inc/uitest/toolboxuiobject.hxx
index 7ab595be1278..65184e2d7171 100644
--- a/vcl/inc/uitest/toolboxuiobject.hxx
+++ b/vcl/inc/uitest/toolboxuiobject.hxx
@@ -30,6 +30,10 @@ public:
 
     virtual OUString get_action(VclEventId nEvent) const override;
 
+    std::set<OUString> get_children() const override;
+
+    std::unique_ptr<UIObject> get_child(const OUString& rID) override;
+
 private:
     virtual OUString get_name() const override;
 };
diff --git a/vcl/source/uitest/toolboxitemuiobject.cxx 
b/vcl/source/uitest/toolboxitemuiobject.cxx
new file mode 100644
index 000000000000..e976050cb85d
--- /dev/null
+++ b/vcl/source/uitest/toolboxitemuiobject.cxx
@@ -0,0 +1,37 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <uitest/toolboxitemuiobject.hxx>
+
+ToolBoxItemUIObject::ToolBoxItemUIObject(const VclPtr<ToolBox>& pToolBox, 
ToolBoxItemId nId)
+    : m_pToolBox(pToolBox)
+    , m_nId(nId)
+{
+}
+
+ToolBoxItemUIObject::~ToolBoxItemUIObject() {}
+
+StringMap ToolBoxItemUIObject::get_state()
+{
+    StringMap aMap{ { u"Enabled"_ustr, 
OUString::boolean(m_pToolBox->IsItemEnabled(m_nId)) },
+                    { u"Text"_ustr, m_pToolBox->GetItemText(m_nId) } };
+
+    return aMap;
+}
+
+bool ToolBoxItemUIObject::equals(const UIObject& rOther) const
+{
+    const ToolBoxItemUIObject* pOther = dynamic_cast<const 
ToolBoxItemUIObject*>(&rOther);
+    if (!pOther)
+        return false;
+
+    return m_pToolBox == pOther->m_pToolBox && m_nId == pOther->m_nId;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/vcl/source/uitest/toolboxuiobject.cxx 
b/vcl/source/uitest/toolboxuiobject.cxx
index fd7de25727ac..a9c599970025 100644
--- a/vcl/source/uitest/toolboxuiobject.cxx
+++ b/vcl/source/uitest/toolboxuiobject.cxx
@@ -7,10 +7,14 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
+#include <uitest/toolboxitemuiobject.hxx>
 #include <uitest/toolboxuiobject.hxx>
 
+#include <o3tl/string_view.hxx>
 #include <vcl/toolbox.hxx>
 
+constexpr OUString TOOLBOX_ITEM_ID_PREFIX = u"toolboxitem-"_ustr;
+
 ToolBoxUIObject::ToolBoxUIObject(const VclPtr<ToolBox>& xToolBox)
     : WindowUIObject(xToolBox)
     , mxToolBox(xToolBox)
@@ -59,6 +63,33 @@ StringMap ToolBoxUIObject::get_state()
     return aMap;
 }
 
+std::set<OUString> ToolBoxUIObject::get_children() const
+{
+    std::set<OUString> aChildren = WindowUIObject::get_children();
+
+    const size_t nItemCount = mxToolBox->GetItemCount();
+    for (size_t i = 0; i < nItemCount; ++i)
+    {
+        const OUString sId
+            = TOOLBOX_ITEM_ID_PREFIX + 
OUString::number(sal_uInt16(mxToolBox->GetItemId(i)));
+        aChildren.insert(sId);
+    }
+
+    return aChildren;
+}
+
+std::unique_ptr<UIObject> ToolBoxUIObject::get_child(const OUString& rID)
+{
+    if (rID.startsWith(TOOLBOX_ITEM_ID_PREFIX))
+    {
+        const sal_Int32 nPrefixLength = TOOLBOX_ITEM_ID_PREFIX.getLength();
+        const ToolBoxItemId nItemId(o3tl::toInt32(rID.subView(nPrefixLength)));
+        return std::make_unique<ToolBoxItemUIObject>(mxToolBox, nItemId);
+    }
+
+    return WindowUIObject::get_child(rID);
+}
+
 OUString ToolBoxUIObject::get_name() const { return u"ToolBoxUIObject"_ustr; }
 
 std::unique_ptr<UIObject> ToolBoxUIObject::create(vcl::Window* pWindow)
commit 3cf9ebf5841d363da85e700fe7acc4ebe5be52ca
Author:     Michael Weghorn <[email protected]>
AuthorDate: Mon May 26 08:26:37 2025 +0200
Commit:     Michael Weghorn <[email protected]>
CommitDate: Wed May 28 09:19:34 2025 +0200

    [API CHANGE] uitest: Add API to get XUIObject for specific XWindow
    
    Add a XUITest::getWindow method that allows to get the
    XUIObject for a given XWindow.
    
    The XUITest interface is internal/unpublished API used
    for UI tests.
    
    The newly introduced method will be used in an upcoming
    commit in sw/qa/uitest/table/tdf146145.py to port
    that test away from depending on a11y implementation
    details that are about to change.
    
    Change-Id: I6fcbee3ce894ad82ec42fa034b85544b50408779
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185773
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <[email protected]>

diff --git a/offapi/com/sun/star/ui/test/XUITest.idl 
b/offapi/com/sun/star/ui/test/XUITest.idl
index 201791d88df4..e4fd1d30aa19 100644
--- a/offapi/com/sun/star/ui/test/XUITest.idl
+++ b/offapi/com/sun/star/ui/test/XUITest.idl
@@ -21,6 +21,12 @@ interface XUITest
     XUIObject getTopFocusWindow();
 
     XUIObject getFloatWindow();
+
+    /** Get the XUIObject for the given window.
+
+        @since LibreOffice 25.8
+    */
+    XUIObject getWindow([in] ::com::sun::star::awt::XWindow xWindow);
 };
 
 }; }; }; }; };
diff --git a/vcl/source/uitest/uno/uitest_uno.cxx 
b/vcl/source/uitest/uno/uitest_uno.cxx
index a96371daba38..c49422877e8a 100644
--- a/vcl/source/uitest/uno/uitest_uno.cxx
+++ b/vcl/source/uitest/uno/uitest_uno.cxx
@@ -17,6 +17,7 @@
 
 #include <vcl/uitest/uitest.hxx>
 #include <vcl/svapp.hxx>
+#include <vcl/toolkit/unowrap.hxx>
 #include <vcl/window.hxx>
 
 #include "uiobject_uno.hxx"
@@ -44,6 +45,9 @@ public:
 
     css::uno::Reference<css::ui::test::XUIObject> SAL_CALL getFloatWindow() 
override;
 
+    css::uno::Reference<css::ui::test::XUIObject>
+        SAL_CALL getWindow(const css::uno::Reference<css::awt::XWindow>& 
xWindow) override;
+
     OUString SAL_CALL getImplementationName() override;
 
     sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override;
@@ -94,6 +98,20 @@ css::uno::Reference<css::ui::test::XUIObject> SAL_CALL 
UITestUnoObj::getFloatWin
     return new UIObjectUnoObj(std::move(pObj));
 }
 
+css::uno::Reference<css::ui::test::XUIObject>
+    SAL_CALL UITestUnoObj::getWindow(const 
css::uno::Reference<::css::awt::XWindow>& xWindow)
+{
+    if (!xWindow.is())
+        return {};
+
+    UnoWrapperBase* pWrapper = UnoWrapperBase::GetUnoWrapper();
+    assert(pWrapper);
+    VclPtr<vcl::Window> pWindow = pWrapper->GetWindow(xWindow);
+    assert(pWindow);
+
+    return new UIObjectUnoObj(pWindow->GetUITestFactory()(pWindow));
+}
+
 OUString SAL_CALL UITestUnoObj::getImplementationName()
 {
     return u"org.libreoffice.uitest.UITest"_ustr;

Reply via email to