From c1bfdddb51bf2fe22a7c935a797bf7f7221b0202 Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Sun, 17 Jul 2016 16:43:40 +0200 Subject: uitest: add wrapper for element selector Change-Id: I641a290b3a9cf46ba484a9a851a27456cc68678c --- starmath/Library_sm.mk | 1 + starmath/inc/ElementsDockingWindow.hxx | 6 ++ starmath/source/ElementsDockingWindow.cxx | 7 ++ starmath/source/uiobject.cxx | 115 ++++++++++++++++++++++++++++++ starmath/source/uiobject.hxx | 65 +++++++++++++++++ 5 files changed, 194 insertions(+) create mode 100644 starmath/source/uiobject.cxx create mode 100644 starmath/source/uiobject.hxx (limited to 'starmath') diff --git a/starmath/Library_sm.mk b/starmath/Library_sm.mk index 0b05af9bd264..08a4b50d102a 100644 --- a/starmath/Library_sm.mk +++ b/starmath/Library_sm.mk @@ -88,6 +88,7 @@ $(eval $(call gb_Library_add_exception_objects,sm,\ starmath/source/symbol \ starmath/source/tmpdevice \ starmath/source/typemap \ + starmath/source/uiobject \ starmath/source/unodoc \ starmath/source/unofilter \ starmath/source/unomodel \ diff --git a/starmath/inc/ElementsDockingWindow.hxx b/starmath/inc/ElementsDockingWindow.hxx index 5c0f22895d7a..cbc4bed734f2 100644 --- a/starmath/inc/ElementsDockingWindow.hxx +++ b/starmath/inc/ElementsDockingWindow.hxx @@ -29,6 +29,7 @@ class SmDocShell; class SmNode; +class ElementSelectorUIObject; class SmElement { @@ -72,6 +73,9 @@ public: class SmElementsControl : public Control { + friend class ElementSelectorUIObject; + friend class ElementUIObject; + static const sal_uInt16 aUnaryBinaryOperatorsList[][2]; static const sal_uInt16 aRelationsList[][2]; static const sal_uInt16 aSetOperations[][2]; @@ -125,6 +129,8 @@ public: void DoScroll(long nDelta); void SetSelectHdl(const Link& rLink) { maSelectHdlLink = rLink; } + + virtual FactoryFunction GetUITestFactory() const override; }; class SmElementsDockingWindow : public SfxDockingWindow diff --git a/starmath/source/ElementsDockingWindow.cxx b/starmath/source/ElementsDockingWindow.cxx index b66c37d05922..adba7e19fbcb 100644 --- a/starmath/source/ElementsDockingWindow.cxx +++ b/starmath/source/ElementsDockingWindow.cxx @@ -25,6 +25,7 @@ #include #include "document.hxx" #include "node.hxx" +#include "uiobject.hxx" #include #include @@ -227,6 +228,7 @@ SmElementsControl::SmElementsControl(vcl::Window *pParent) , mbVerticalMode(true) , mxScroll(VclPtr::Create(this, WB_VERT)) { + set_id("element_selector"); SetMapMode( MapMode(MAP_100TH_MM) ); SetDrawMode( DrawModeFlags::Default ); SetLayoutMode( ComplexTextLayoutFlags::Default ); @@ -683,6 +685,11 @@ Size SmElementsControl::GetOptimalSize() const return LogicToPixel(Size(100, 100), MapMode(MAP_APPFONT)); } +FactoryFunction SmElementsControl::GetUITestFactory() const +{ + return ElementSelectorUIObject::create; +} + const sal_uInt16 SmElementsDockingWindow::aCategories[] = { RID_CATEGORY_UNARY_BINARY_OPERATORS, RID_CATEGORY_RELATIONS, diff --git a/starmath/source/uiobject.cxx b/starmath/source/uiobject.cxx new file mode 100644 index 000000000000..63509756ef61 --- /dev/null +++ b/starmath/source/uiobject.cxx @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 "uiobject.hxx" + +#include "ElementsDockingWindow.hxx" + +ElementUIObject::ElementUIObject(VclPtr xElementSelector, + const OUString& rID): + mxElementsSelector(xElementSelector), + maID(rID) +{ +} + +SmElement* ElementUIObject::get_element() +{ + sal_uInt32 nID = maID.toUInt32(); + size_t n = mxElementsSelector->maElementList.size(); + if (nID >= n) + return nullptr; + + return mxElementsSelector->maElementList[nID].get(); +} + +StringMap ElementUIObject::get_state() +{ + StringMap aMap; + aMap["ID"] = maID; + + SmElement* pElement = get_element(); + if (pElement) + aMap["Text"] = pElement->getText(); + + return aMap; +} + +void ElementUIObject::execute(const OUString& rAction, + const StringMap& /*rParameters*/) +{ + if (rAction == "SELECT") + { + SmElement* pElement = get_element(); + if (pElement) + mxElementsSelector->maSelectHdlLink.Call(*pElement); + } +} + +ElementSelectorUIObject::ElementSelectorUIObject(VclPtr xElementSelector): + WindowUIObject(xElementSelector), + mxElementsSelector(xElementSelector) +{ +} + +StringMap ElementSelectorUIObject::get_state() +{ + StringMap aMap = WindowUIObject::get_state(); + + SmElement* pElement = mxElementsSelector->mpCurrentElement; + if (pElement) + aMap["CurrentEntry"] = pElement->getText(); + + aMap["CurrentSelection"] = OUString::number(mxElementsSelector->maCurrentSetId); + + return aMap; +} + +void ElementSelectorUIObject::execute(const OUString& rAction, + const StringMap& rParameters) +{ + WindowUIObject::execute(rAction, rParameters); +} + +std::unique_ptr ElementSelectorUIObject::get_child(const OUString& rID) +{ + size_t nID = rID.toInt32(); + size_t n = mxElementsSelector->maElementList.size(); + if (nID >= n) + throw css::uno::RuntimeException("invalid id"); + + return std::unique_ptr(new ElementUIObject(mxElementsSelector, rID)); +} + +std::set ElementSelectorUIObject::get_children() const +{ + std::set aChildren; + + size_t n = mxElementsSelector->maElementList.size(); + for (size_t i = 0; i < n; ++i) + { + aChildren.insert(OUString::number(i)); + } + + return aChildren; +} + +std::unique_ptr ElementSelectorUIObject::create(vcl::Window* pWindow) +{ + SmElementsControl* pElementsControl = dynamic_cast(pWindow); + assert(pElementsControl); + + return std::unique_ptr(new ElementSelectorUIObject(pElementsControl)); +} + +OUString ElementSelectorUIObject::get_name() const +{ + return OUString("SmElementSelector"); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/starmath/source/uiobject.hxx b/starmath/source/uiobject.hxx new file mode 100644 index 000000000000..1ecdf48596b6 --- /dev/null +++ b/starmath/source/uiobject.hxx @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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/. + */ + +#ifndef INCLUDED_STARMATH_SOURCE_UIOBJECT_HXX +#define INCLUDED_STARMATH_SOURCE_UIOBJECT_HXX + +#include + +class SmElementsControl; +class SmElement; + +class ElementUIObject : public UIObject +{ +private: + VclPtr mxElementsSelector; + OUString maID; + +public: + + ElementUIObject(VclPtr xElementSelector, + const OUString& rID); + + virtual StringMap get_state() override; + + virtual void execute(const OUString& rAction, + const StringMap& rParameters); + +private: + SmElement* get_element(); +}; + +class ElementSelectorUIObject : public WindowUIObject +{ +private: + VclPtr mxElementsSelector; + +public: + + ElementSelectorUIObject(VclPtr xElementSelector); + + virtual StringMap get_state() override; + + virtual void execute(const OUString& rAction, + const StringMap& rParameters) override; + + static std::unique_ptr create(vcl::Window* pWindow); + + virtual std::unique_ptr get_child(const OUString& rID) override; + + virtual std::set get_children() const override; + +protected: + + virtual OUString get_name() const; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit