Kaydet (Commit) c1bfdddb authored tarafından Markus Mohrhard's avatar Markus Mohrhard

uitest: add wrapper for element selector

Change-Id: I641a290b3a9cf46ba484a9a851a27456cc68678c
üst d03d7a79
......@@ -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 \
......
......@@ -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<SmElement&,void>& rLink) { maSelectHdlLink = rLink; }
virtual FactoryFunction GetUITestFactory() const override;
};
class SmElementsDockingWindow : public SfxDockingWindow
......
......@@ -25,6 +25,7 @@
#include <visitors.hxx>
#include "document.hxx"
#include "node.hxx"
#include "uiobject.hxx"
#include <o3tl/make_unique.hxx>
#include <svl/stritem.hxx>
......@@ -227,6 +228,7 @@ SmElementsControl::SmElementsControl(vcl::Window *pParent)
, mbVerticalMode(true)
, mxScroll(VclPtr<ScrollBar>::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,
......
/* -*- 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<SmElementsControl> 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<SmElementsControl> 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<UIObject> 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<UIObject>(new ElementUIObject(mxElementsSelector, rID));
}
std::set<OUString> ElementSelectorUIObject::get_children() const
{
std::set<OUString> 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<UIObject> ElementSelectorUIObject::create(vcl::Window* pWindow)
{
SmElementsControl* pElementsControl = dynamic_cast<SmElementsControl*>(pWindow);
assert(pElementsControl);
return std::unique_ptr<UIObject>(new ElementSelectorUIObject(pElementsControl));
}
OUString ElementSelectorUIObject::get_name() const
{
return OUString("SmElementSelector");
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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 <vcl/uitest/uiobject.hxx>
class SmElementsControl;
class SmElement;
class ElementUIObject : public UIObject
{
private:
VclPtr<SmElementsControl> mxElementsSelector;
OUString maID;
public:
ElementUIObject(VclPtr<SmElementsControl> 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<SmElementsControl> mxElementsSelector;
public:
ElementSelectorUIObject(VclPtr<SmElementsControl> xElementSelector);
virtual StringMap get_state() override;
virtual void execute(const OUString& rAction,
const StringMap& rParameters) override;
static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
virtual std::unique_ptr<UIObject> get_child(const OUString& rID) override;
virtual std::set<OUString> get_children() const override;
protected:
virtual OUString get_name() const;
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment