[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - desktop/source include/vcl vcl/source

Szymon KÅ‚os (via logerrit) logerrit at kemper.freedesktop.org
Wed Apr 14 09:06:40 UTC 2021


 desktop/source/lib/init.cxx     |   14 +++++++++++
 include/vcl/layout.hxx          |    7 -----
 include/vcl/uitest/uiobject.hxx |   12 +++++++++
 vcl/source/uitest/uiobject.cxx  |   50 ++++++++++++++++++++++++++++++++++++++++
 vcl/source/window/layout.cxx    |    8 ++++++
 5 files changed, 85 insertions(+), 6 deletions(-)

New commits:
commit 5f18922496ec60255097048d9b00b70fc6ccbba5
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Fri Apr 2 20:13:32 2021 +0200
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Wed Apr 14 11:06:08 2021 +0200

    jsdialog: uitest: handle click for drawing area
    
    Change-Id: I5ea78697b87f4b2a468f8507470b62031bee4aa0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113524
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index dca49bd79014..8d641cd1383f 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -3818,6 +3818,20 @@ static void lcl_sendDialogEvent(unsigned long long int nWindowId, const char* pA
                         aMap["VALUE"] = aMap["data"];
                         pUIWindow->execute(sValue, aMap);
                     }
+                    else if (sAction == "click" && sControlType == "drawingarea")
+                    {
+                        int separatorPos = aMap["data"].indexOf(';');
+                        if (separatorPos > 0)
+                        {
+                            // x;y
+                            aMap["POSX"] = aMap["data"].copy(0, separatorPos);
+                            aMap["POSY"] = aMap["data"].copy(separatorPos + 1);
+
+                            pUIWindow->execute(sClickAction, aMap);
+                        }
+                        else
+                            bIsClickAction = true;
+                    }
                     else
                         bIsClickAction = true;
 
diff --git a/include/vcl/layout.hxx b/include/vcl/layout.hxx
index 63d789d28a7e..b2f340942a20 100644
--- a/include/vcl/layout.hxx
+++ b/include/vcl/layout.hxx
@@ -723,12 +723,7 @@ private:
             Help::ShowQuickHelp(this, aHelpArea, sHelpTip, eHelpWinStyle);
         }
     }
-    virtual FactoryFunction GetUITestFactory() const override
-    {
-        if (m_pFactoryFunction)
-            return m_pFactoryFunction;
-        return Control::GetUITestFactory();
-    }
+    virtual FactoryFunction GetUITestFactory() const override;
 
 public:
     VclDrawingArea(vcl::Window *pParent, WinBits nStyle)
diff --git a/include/vcl/uitest/uiobject.hxx b/include/vcl/uitest/uiobject.hxx
index 60d84dedbe24..b5713587ccf3 100644
--- a/include/vcl/uitest/uiobject.hxx
+++ b/include/vcl/uitest/uiobject.hxx
@@ -29,6 +29,7 @@
 class Edit;
 class SpinButton;
 class SpinField;
+class VclDrawingArea;
 class MetricField;
 
 typedef std::map<const OUString, OUString> StringMap;
@@ -495,6 +496,17 @@ private:
     SvTreeListEntry* const mpEntry;
 };
 
+class UITEST_DLLPUBLIC DrawingAreaUIObject : public WindowUIObject
+{
+private:
+    VclPtr<VclDrawingArea> mxDrawingArea;
+public:
+    DrawingAreaUIObject(const VclPtr<VclDrawingArea>& rDrawingArea);
+    virtual ~DrawingAreaUIObject() override;
+    virtual void execute(const OUString& rAction, const StringMap& rParameters) override;
+    static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
+};
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/uitest/uiobject.cxx b/vcl/source/uitest/uiobject.cxx
index 2c6010dc205d..c10cc5f21d9d 100644
--- a/vcl/source/uitest/uiobject.cxx
+++ b/vcl/source/uitest/uiobject.cxx
@@ -11,6 +11,7 @@
 
 #include <vcl/event.hxx>
 #include <vcl/tabpage.hxx>
+#include <vcl/layout.hxx>
 #include <vcl/lstbox.hxx>
 #include <vcl/combobox.hxx>
 #include <vcl/toolkit/spin.hxx>
@@ -1485,6 +1486,55 @@ std::unique_ptr<UIObject> TabControlUIObject::create(vcl::Window* pWindow)
     return std::unique_ptr<UIObject>(new TabControlUIObject(pTabControl));
 }
 
+DrawingAreaUIObject::DrawingAreaUIObject(const VclPtr<VclDrawingArea>& rDrawingArea)
+    : WindowUIObject(rDrawingArea)
+    , mxDrawingArea(rDrawingArea.get())
+{
+    assert(mxDrawingArea);
+}
+
+DrawingAreaUIObject::~DrawingAreaUIObject()
+{
+}
+
+void DrawingAreaUIObject::execute(const OUString& rAction, const StringMap& rParameters)
+{
+    if (rAction == "CLICK")
+    {
+        // POSX and POSY are percentage of width/height dimensions
+        if (rParameters.find("POSX") != rParameters.end() &&
+            rParameters.find("POSY") != rParameters.end())
+        {
+            auto aPosX = rParameters.find("POSX");
+            auto aPosY = rParameters.find("POSY");
+
+            OString sPosX2 = OUStringToOString(aPosX->second, RTL_TEXTENCODING_ASCII_US);
+            OString sPoxY2 = OUStringToOString(aPosY->second, RTL_TEXTENCODING_ASCII_US);
+
+            if (!sPosX2.isEmpty() && !sPoxY2.isEmpty())
+            {
+                double fPosX = std::atof(sPosX2.getStr());
+                double fPosY = std::atof(sPoxY2.getStr());
+
+                fPosX = fPosX * mxDrawingArea->GetOutputWidthPixel();
+                fPosY = fPosY * mxDrawingArea->GetOutputHeightPixel();
+
+                MouseEvent aEvent(Point(fPosX, fPosY), 1, MouseEventModifiers::NONE, MOUSE_LEFT, 0);
+                mxDrawingArea->MouseButtonDown(aEvent);
+                mxDrawingArea->MouseButtonUp(aEvent);
+            }
+        }
+    }
+    else
+        WindowUIObject::execute(rAction, rParameters);
+}
+
+std::unique_ptr<UIObject> DrawingAreaUIObject::create(vcl::Window* pWindow)
+{
+    VclDrawingArea* pVclDrawingArea = dynamic_cast<VclDrawingArea*>(pWindow);
+    assert(pVclDrawingArea);
+    return std::unique_ptr<UIObject>(new DrawingAreaUIObject(pVclDrawingArea));
+}
 
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/window/layout.cxx b/vcl/source/window/layout.cxx
index 4e2efa065439..110ffa6b4f87 100644
--- a/vcl/source/window/layout.cxx
+++ b/vcl/source/window/layout.cxx
@@ -17,6 +17,7 @@
 #include <vcl/svapp.hxx>
 #include <vcl/settings.hxx>
 #include <vcl/messagedialog.hxx>
+#include <vcl/uitest/uiobject.hxx>
 #include <window.h>
 #include <boost/multi_array.hpp>
 #include <boost/property_tree/ptree.hpp>
@@ -2721,4 +2722,11 @@ bool isLayoutEnabled(const vcl::Window *pWindow)
     return pChild && isContainerWindow(*pChild) && !pChild->GetWindow(GetWindowType::Next);
 }
 
+FactoryFunction VclDrawingArea::GetUITestFactory() const
+{
+    if (m_pFactoryFunction)
+        return m_pFactoryFunction;
+    return DrawingAreaUIObject::create;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list