add initial drawinglayer support to UI testing framework
Change-Id: Id0450cdf655accb6bd1a50871e83d5c8ecdaab5f Reviewed-on: https://gerrit.libreoffice.org/29417 Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com> Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
This commit is contained in:
37
include/svx/uiobject.hxx
Normal file
37
include/svx/uiobject.hxx
Normal file
@@ -0,0 +1,37 @@
|
||||
/* -*- 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_SVX_UIOBJECT_HXX
|
||||
#define INCLUDED_SVX_UIOBJECT_HXX
|
||||
|
||||
#include <svx/svxdllapi.h>
|
||||
|
||||
#include <vcl/uitest/uiobject.hxx>
|
||||
|
||||
class SdrObject;
|
||||
|
||||
class SVX_DLLPUBLIC SdrUIObject : public UIObject
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~SdrUIObject() override;
|
||||
|
||||
virtual StringMap get_state() override;
|
||||
|
||||
virtual void execute(const OUString& rAction,
|
||||
const StringMap& rParameters) override;
|
||||
|
||||
virtual OUString get_type() const override;
|
||||
|
||||
virtual SdrObject* get_object() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
@@ -30,6 +30,8 @@ public:
|
||||
virtual void execute(const OUString& rAction,
|
||||
const StringMap& rParameters) override;
|
||||
|
||||
virtual std::unique_ptr<UIObject> get_child(const OUString& rID) override;
|
||||
|
||||
virtual std::set<OUString> get_children() const override;
|
||||
|
||||
static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
|
||||
@@ -42,10 +44,6 @@ private:
|
||||
|
||||
VclPtr<sd::Window> mxWindow;
|
||||
|
||||
sd::DrawViewShell* getViewShell() const;
|
||||
|
||||
SdrObject* getObject(const OUString& rName);
|
||||
|
||||
SdrPageView* getPageView();
|
||||
};
|
||||
|
||||
|
@@ -13,6 +13,71 @@
|
||||
#include "DrawViewShell.hxx"
|
||||
#include "sdpage.hxx"
|
||||
|
||||
#include <svx/uiobject.hxx>
|
||||
|
||||
class ImpressSdrObject : public SdrUIObject
|
||||
{
|
||||
public:
|
||||
ImpressSdrObject(VclPtr<sd::Window> xImpressWin, const OUString& rName);
|
||||
|
||||
SdrObject* get_object() override;
|
||||
|
||||
private:
|
||||
VclPtr<sd::Window> mxWindow;
|
||||
|
||||
OUString maName;
|
||||
};
|
||||
|
||||
namespace {
|
||||
|
||||
sd::DrawViewShell* getViewShell(VclPtr<sd::Window> xWindow)
|
||||
{
|
||||
sd::DrawViewShell* pViewShell = dynamic_cast<sd::DrawViewShell*>(xWindow->GetViewShell());
|
||||
assert(pViewShell);
|
||||
|
||||
return pViewShell;
|
||||
}
|
||||
|
||||
OUString getObjectName(SdrObject* pObject)
|
||||
{
|
||||
if (pObject->GetName().isEmpty())
|
||||
return "Unnamed Drawinglayer object " + OUString::number(pObject->GetOrdNum());
|
||||
else
|
||||
return pObject->GetName();
|
||||
}
|
||||
|
||||
SdrObject* getObject(VclPtr<sd::Window> xWindow, const OUString& rName)
|
||||
{
|
||||
SdrPage* pPage = getViewShell(xWindow)->getCurrentPage();
|
||||
|
||||
if (!pPage)
|
||||
return nullptr;
|
||||
|
||||
size_t nObjs = pPage->GetObjCount();
|
||||
for (size_t i = 0; i < nObjs; ++i)
|
||||
{
|
||||
SdrObject* pObj = pPage->GetObj(i);
|
||||
if (rName == getObjectName(pObj))
|
||||
return pObj;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
ImpressSdrObject::ImpressSdrObject(VclPtr<sd::Window> xImpressWin, const OUString& rName):
|
||||
mxWindow(xImpressWin),
|
||||
maName(rName)
|
||||
{
|
||||
}
|
||||
|
||||
SdrObject* ImpressSdrObject::get_object()
|
||||
{
|
||||
return getObject(mxWindow, maName);
|
||||
}
|
||||
|
||||
ImpressWindowUIObject::ImpressWindowUIObject(VclPtr<sd::Window> xWindow):
|
||||
WindowUIObject(xWindow),
|
||||
mxWindow(xWindow)
|
||||
@@ -23,8 +88,8 @@ StringMap ImpressWindowUIObject::get_state()
|
||||
{
|
||||
StringMap aMap = WindowUIObject::get_state();
|
||||
|
||||
aMap["SelectedText"] = getViewShell()->GetSelectionText(false);
|
||||
aMap["CurrentSlide"] = OUString::number(getViewShell()->GetCurPageId());
|
||||
aMap["SelectedText"] = getViewShell(mxWindow)->GetSelectionText(false);
|
||||
aMap["CurrentSlide"] = OUString::number(getViewShell(mxWindow)->GetCurPageId());
|
||||
|
||||
return aMap;
|
||||
}
|
||||
@@ -39,7 +104,7 @@ void ImpressWindowUIObject::execute(const OUString& rAction,
|
||||
auto itr = rParameters.find("ZOOM");
|
||||
OUString aVal = itr->second;
|
||||
sal_Int32 nVal = aVal.toInt32();
|
||||
getViewShell()->SetZoom(nVal);
|
||||
getViewShell(mxWindow)->SetZoom(nVal);
|
||||
}
|
||||
}
|
||||
else if (rAction == "GOTO")
|
||||
@@ -49,7 +114,7 @@ void ImpressWindowUIObject::execute(const OUString& rAction,
|
||||
auto itr = rParameters.find("PAGE");
|
||||
OUString aVal = itr->second;
|
||||
sal_Int32 nVal = aVal.toInt32();
|
||||
getViewShell()->SwitchPage(nVal);
|
||||
getViewShell(mxWindow)->SwitchPage(nVal);
|
||||
}
|
||||
}
|
||||
else if (rAction == "SELECT")
|
||||
@@ -58,34 +123,27 @@ void ImpressWindowUIObject::execute(const OUString& rAction,
|
||||
{
|
||||
auto itr = rParameters.find("OBJECT");
|
||||
OUString aName = itr->second;
|
||||
SdrObject* pObj = getObject(aName);
|
||||
SdrObject* pObj = getObject(mxWindow, aName);
|
||||
SdrPageView* pPageView = getPageView();
|
||||
getViewShell()->GetView()->MarkObj(pObj, pPageView);
|
||||
getViewShell(mxWindow)->GetView()->MarkObj(pObj, pPageView);
|
||||
}
|
||||
}
|
||||
else if (rAction == "DESELECT")
|
||||
{
|
||||
getViewShell()->GetView()->UnMarkAll();
|
||||
getViewShell(mxWindow)->GetView()->UnMarkAll();
|
||||
}
|
||||
else
|
||||
WindowUIObject::execute(rAction, rParameters);
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
OUString getObjectName(SdrObject* pObject)
|
||||
std::unique_ptr<UIObject> ImpressWindowUIObject::get_child(const OUString& rID)
|
||||
{
|
||||
if (pObject->GetName().isEmpty())
|
||||
return "Unnamed Drawinglayer object " + OUString::number(pObject->GetOrdNum());
|
||||
else
|
||||
return pObject->GetName();
|
||||
}
|
||||
|
||||
return std::unique_ptr<UIObject>(new ImpressSdrObject(mxWindow, rID));
|
||||
}
|
||||
|
||||
std::set<OUString> ImpressWindowUIObject::get_children() const
|
||||
{
|
||||
SdrPage* pPage = getViewShell()->getCurrentPage();
|
||||
SdrPage* pPage = getViewShell(mxWindow)->getCurrentPage();
|
||||
|
||||
std::set<OUString> aRet;
|
||||
if (!pPage)
|
||||
@@ -113,35 +171,9 @@ std::unique_ptr<UIObject> ImpressWindowUIObject::create(vcl::Window* pWindow)
|
||||
return std::unique_ptr<UIObject>(new ImpressWindowUIObject(pWin));
|
||||
}
|
||||
|
||||
sd::DrawViewShell* ImpressWindowUIObject::getViewShell() const
|
||||
{
|
||||
sd::DrawViewShell* pViewShell = dynamic_cast<sd::DrawViewShell*>(mxWindow->GetViewShell());
|
||||
assert(pViewShell);
|
||||
|
||||
return pViewShell;
|
||||
}
|
||||
|
||||
SdrObject* ImpressWindowUIObject::getObject(const OUString& rName)
|
||||
{
|
||||
SdrPage* pPage = getViewShell()->getCurrentPage();
|
||||
|
||||
if (!pPage)
|
||||
return nullptr;
|
||||
|
||||
size_t nObjs = pPage->GetObjCount();
|
||||
for (size_t i = 0; i < nObjs; ++i)
|
||||
{
|
||||
SdrObject* pObj = pPage->GetObj(i);
|
||||
if (rName == getObjectName(pObj))
|
||||
return pObj;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SdrPageView* ImpressWindowUIObject::getPageView()
|
||||
{
|
||||
return getViewShell()->GetView()->GetSdrPageView();
|
||||
return getViewShell(mxWindow)->GetView()->GetSdrPageView();
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
@@ -474,6 +474,7 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\
|
||||
svx/source/form/stringlistresource \
|
||||
svx/source/form/typemap \
|
||||
svx/source/form/xfm_addcondition \
|
||||
svx/source/uitest/sdrobject \
|
||||
))
|
||||
|
||||
$(eval $(call gb_SdiTarget_SdiTarget,svx/sdi/svxslots,svx/sdi/svx))
|
||||
|
113
svx/source/uitest/sdrobject.cxx
Normal file
113
svx/source/uitest/sdrobject.cxx
Normal file
@@ -0,0 +1,113 @@
|
||||
/* -*- 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 <svx/uiobject.hxx>
|
||||
|
||||
#include <svx/svdobj.hxx>
|
||||
|
||||
#include <tools/fract.hxx>
|
||||
|
||||
SdrUIObject::~SdrUIObject()
|
||||
{
|
||||
}
|
||||
|
||||
StringMap SdrUIObject::get_state()
|
||||
{
|
||||
StringMap aMap;
|
||||
SdrObject* pObject = get_object();
|
||||
|
||||
if (!pObject)
|
||||
return aMap;
|
||||
|
||||
aMap["Name"] = pObject->GetName();
|
||||
aMap["Description"] = pObject->GetDescription();
|
||||
aMap["Title"] = pObject->GetTitle();
|
||||
aMap["Z-Order"] = OUString::number(pObject->GetOrdNum());
|
||||
aMap["Layer"] = OUString::number(pObject->GetLayer());
|
||||
aMap["IsGroupObject"] = OUString::boolean(pObject->IsGroupObject());
|
||||
aMap["IsPolyObject"] = OUString::boolean(pObject->IsPolyObj());
|
||||
aMap["PointCount"] = OUString::number(pObject->GetPointCount());
|
||||
aMap["HasTextEdit"] = OUString::boolean(pObject->HasTextEdit());
|
||||
aMap["HasMacro"] = OUString::boolean(pObject->HasMacro());
|
||||
aMap["IsClosed"] = OUString::boolean(pObject->IsClosedObj());
|
||||
aMap["IsEdgeObject"] = OUString::boolean(pObject->IsEdgeObj());
|
||||
aMap["Is3DObject"] = OUString::boolean(pObject->Is3DObj());
|
||||
aMap["IsUNOObject"] = OUString::boolean(pObject->IsUnoObj());
|
||||
aMap["MoveProtected"] = OUString::boolean(pObject->IsMoveProtect());
|
||||
aMap["ResizeProtected"] = OUString::boolean(pObject->IsResizeProtect());
|
||||
aMap["Printable"] = OUString::boolean(pObject->IsPrintable());
|
||||
aMap["Visible"] = OUString::boolean(pObject->IsVisible());
|
||||
aMap["HasText"] = OUString::boolean(pObject->HasText());
|
||||
|
||||
return aMap;
|
||||
}
|
||||
|
||||
void SdrUIObject::execute(const OUString& rAction,
|
||||
const StringMap& rParameters)
|
||||
{
|
||||
SdrObject* pObj = get_object();
|
||||
if (!pObj)
|
||||
return;
|
||||
|
||||
if (rAction == "MOVE")
|
||||
{
|
||||
auto itrNX = rParameters.find("X");
|
||||
if (itrNX == rParameters.end())
|
||||
throw css::uno::RuntimeException("missing parameter X");
|
||||
|
||||
auto itrNY = rParameters.find("Y");
|
||||
if (itrNY == rParameters.end())
|
||||
throw css::uno::RuntimeException("missing parameter Y");
|
||||
|
||||
long nX = itrNX->second.toInt32();
|
||||
long nY = itrNY->second.toInt32();
|
||||
Size aMoveRange(nX, nY);
|
||||
pObj->Move(aMoveRange);
|
||||
}
|
||||
else if (rAction == "RESIZE")
|
||||
{
|
||||
Point aPos;
|
||||
Fraction aFracX;
|
||||
Fraction aFracY;
|
||||
bool bRelative = true;
|
||||
pObj->Resize(aPos, aFracX, aFracY, bRelative);
|
||||
}
|
||||
else if (rAction == "CROP")
|
||||
{
|
||||
Point aPos;
|
||||
Fraction aFracX;
|
||||
Fraction aFracY;
|
||||
pObj->Crop(aPos, aFracX, aFracY);
|
||||
}
|
||||
else if (rAction == "Rotate")
|
||||
{
|
||||
Point aPos;
|
||||
double nAngle = 0;
|
||||
pObj->Rotate(aPos, nAngle, 0, 0);
|
||||
}
|
||||
else if (rAction == "Mirror")
|
||||
{
|
||||
Point aPos;
|
||||
Point aPos2;
|
||||
pObj->Mirror(aPos, aPos2);
|
||||
}
|
||||
else if (rAction == "SHEAR")
|
||||
{
|
||||
Point aPos;
|
||||
double nAngle = 0;
|
||||
pObj->Shear(aPos, nAngle, 0, false);
|
||||
}
|
||||
}
|
||||
|
||||
OUString SdrUIObject::get_type() const
|
||||
{
|
||||
return OUString("SdrUIObject");
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
Reference in New Issue
Block a user