diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2016-05-05 00:50:08 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2016-06-18 17:01:59 +0200 |
commit | 755a7b74b44a8dadc403f94dda0e3450df1daa17 (patch) | |
tree | 5e0193be671c7da49e9a0c88f31b3dda54ddf1b8 /sc/source/ui | |
parent | a86405470fafd86132b8452746a86b54f2396fff (diff) |
uitest: add wrapper for calc's gridwindow
It already supports selecting cell ranges.
Change-Id: I8c3e4a42dea8956e2429b82b50ff8506c1774bbb
Diffstat (limited to 'sc/source/ui')
-rw-r--r-- | sc/source/ui/inc/gridwin.hxx | 3 | ||||
-rw-r--r-- | sc/source/ui/inc/uiobject.hxx | 41 | ||||
-rw-r--r-- | sc/source/ui/uitest/uiobject.cxx | 108 | ||||
-rw-r--r-- | sc/source/ui/view/gridwin.cxx | 11 |
4 files changed, 163 insertions, 0 deletions
diff --git a/sc/source/ui/inc/gridwin.hxx b/sc/source/ui/inc/gridwin.hxx index eb1c1220116a..53c03b51093f 100644 --- a/sc/source/ui/inc/gridwin.hxx +++ b/sc/source/ui/inc/gridwin.hxx @@ -434,6 +434,9 @@ public: long nTileWidth, long nTileHeight); + ScViewData* getViewData(); + virtual FactoryFunction GetUITestFactory() const override; + protected: void ImpCreateOverlayObjects(); void ImpDestroyOverlayObjects(); diff --git a/sc/source/ui/inc/uiobject.hxx b/sc/source/ui/inc/uiobject.hxx new file mode 100644 index 000000000000..df14dafa8e98 --- /dev/null +++ b/sc/source/ui/inc/uiobject.hxx @@ -0,0 +1,41 @@ +/* -*- 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 <vcl/uitest/uiobject.hxx> + +class ScGridWindow; +class ScDBFunc; + +class ScGridWinUIObject : public WindowUIObject +{ + VclPtr<ScGridWindow> mxGridWindow; + +public: + + ScGridWinUIObject(VclPtr<ScGridWindow> xGridWin); + + virtual StringMap get_state() override; + + virtual void execute(const OUString& rAction, + const StringMap& rParameters) override; + + virtual std::unique_ptr<UIObject> get_child(const OUString& rID) override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); + +protected: + + virtual OUString get_name() const override; + +private: + + ScDBFunc* getDBFunc(); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/uitest/uiobject.cxx b/sc/source/ui/uitest/uiobject.cxx new file mode 100644 index 000000000000..f9b8127b12fb --- /dev/null +++ b/sc/source/ui/uitest/uiobject.cxx @@ -0,0 +1,108 @@ +/* -*- 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 "rangeutl.hxx" +#include "gridwin.hxx" + +#include "viewdata.hxx" +#include "dbfunc.hxx" + +namespace { + +ScAddress get_address_from_string(const OUString& rStr) +{ + ScAddress aAddr; + sal_Int32 nOffset = 0; + ScRangeStringConverter::GetAddressFromString(aAddr, rStr, nullptr, formula::FormulaGrammar::CONV_OOO, nOffset); + return aAddr; +} + +ScRange get_range_from_string(const OUString& rStr) +{ + ScRange aRange; + sal_Int32 nOffset = 0; + ScRangeStringConverter::GetRangeFromString(aRange, rStr, nullptr, formula::FormulaGrammar::CONV_OOO, nOffset); + + return aRange; +} + +} + +ScGridWinUIObject::ScGridWinUIObject(VclPtr<ScGridWindow> xGridWin): + WindowUIObject(xGridWin), + mxGridWindow(xGridWin) +{ +} + +StringMap ScGridWinUIObject::get_state() +{ + StringMap aMap = WindowUIObject::get_state(); + + aMap["SelectedTable"] = OUString::number(0); + return aMap; +} + +ScDBFunc* ScGridWinUIObject::getDBFunc() +{ + ScViewData* pViewData = mxGridWindow->getViewData(); + ScDBFunc* pFunc = pViewData->GetView(); + + return pFunc; +} + +void ScGridWinUIObject::execute(const OUString& rAction, + const StringMap& rParameters) +{ + if (rAction == "SELECT") + { + if (rParameters.find("CELL") != rParameters.end()) + { + auto itr = rParameters.find("CELL"); + const OUString& rStr = itr->second; + ScAddress aAddr = get_address_from_string(rStr); + ScDBFunc* pFunc = getDBFunc(); + pFunc->MarkRange(ScRange(aAddr)); + mxGridWindow->CursorChanged(); + } + else if (rParameters.find("RANGE") != rParameters.end()) + { + auto itr = rParameters.find("RANGE"); + const OUString rStr = itr->second; + ScRange aRange = get_range_from_string(rStr); + ScDBFunc* pFunc = getDBFunc(); + pFunc->MarkRange(aRange); + mxGridWindow->CursorChanged(); + } + } + else + { + WindowUIObject::execute(rAction, rParameters); + } +} + +std::unique_ptr<UIObject> ScGridWinUIObject::get_child(const OUString& /*rID*/) +{ + return nullptr; +} + +std::unique_ptr<UIObject> ScGridWinUIObject::create(vcl::Window* pWindow) +{ + ScGridWindow* pGridWin = dynamic_cast<ScGridWindow*>(pWindow); + assert(pGridWin); + return std::unique_ptr<UIObject>(new ScGridWinUIObject(pGridWin)); +} + +OUString ScGridWinUIObject::get_name() const +{ + return OUString("ScGridWinUIObject"); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index 32dddd39c2a7..1bb7ec7e6fce 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -129,6 +129,7 @@ #include "dociter.hxx" #include "hints.hxx" #include "spellcheckcontext.hxx" +#include "uiobject.hxx" #include <svx/sdrpagewindow.hxx> #include <svx/sdr/overlay/overlaymanager.hxx> @@ -6486,4 +6487,14 @@ void ScGridWindow::flushOverlayManager() xOverlayManager->flush(); } +ScViewData* ScGridWindow::getViewData() +{ + return pViewData; +} + +FactoryFunction ScGridWindow::GetUITestFactory() const +{ + return ScGridWinUIObject::create; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |