diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2019-06-06 17:45:24 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2019-06-07 15:42:05 +0200 |
commit | 03d33ba9410433d2072364b3afb9dbd6b19c4d0d (patch) | |
tree | a0513e810856ea6a45fc8eb31b086e857b9a17fd /sc | |
parent | 00dfa6dc890dbbc8140fe613599becb5e4c55486 (diff) |
lok: re-factor getTextSelection.
Change-Id: I2c27c213ee980e19d6020e9599b2b72115e7f28e
Reviewed-on: https://gerrit.libreoffice.org/73626
Tested-by: Jenkins
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/docuno.hxx | 4 | ||||
-rw-r--r-- | sc/qa/unit/tiledrendering/tiledrendering.cxx | 19 | ||||
-rw-r--r-- | sc/source/ui/unoobj/docuno.cxx | 61 |
3 files changed, 13 insertions, 71 deletions
diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx index 580379642610..501028b7340a 100644 --- a/sc/inc/docuno.hxx +++ b/sc/inc/docuno.hxx @@ -343,8 +343,8 @@ public: /// @see vcl::ITiledRenderable::setTextSelection(). virtual void setTextSelection(int nType, int nX, int nY) override; - /// @see vcl::ITiledRenderable::getTextSelection(). - virtual OString getTextSelection(const char* pMimeType, OString& rUsedMimeType) override; + /// @see vcl::ITiledRenderable::getSelection(). + virtual css::uno::Reference<css::datatransfer::XTransferable> getSelection() override; /// @see vcl::ITiledRenderable::setGraphicSelection(). virtual void setGraphicSelection(int nType, int nX, int nY) override; diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx index 8bc981982af5..44d090b6ab4e 100644 --- a/sc/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx @@ -8,6 +8,7 @@ */ #include <test/bootstrapfixture.hxx> +#include <test/helper/transferable.hxx> #include <unotest/macros_test.hxx> #include <test/xmltesttools.hxx> #include <boost/property_tree/json_parser.hpp> @@ -16,6 +17,7 @@ #include <com/sun/star/frame/Desktop.hpp> #include <com/sun/star/frame/DispatchHelper.hpp> #include <com/sun/star/datatransfer/clipboard/SystemClipboard.hpp> +#include <com/sun/star/datatransfer/UnsupportedFlavorException.hpp> #include <comphelper/dispatchcommand.hxx> #include <comphelper/processfactory.hxx> #include <comphelper/propertysequence.hxx> @@ -33,6 +35,7 @@ #include <vcl/scheduler.hxx> #include <vcl/vclevent.hxx> #include <vcl/virdev.hxx> +#include <vcl/unohelp2.hxx> #include <sc.hrc> #include <chrono> @@ -253,8 +256,7 @@ void ScTiledRenderingTest::testRowColumnSelections() comphelper::dispatchCommand(".uno:SelectRow", aArgs); // Check if it is selected - OString aUsedMimeType; - OString aResult = pModelObj->getTextSelection("text/plain;charset=utf-8", aUsedMimeType); + OString aResult = apitest::helper::transferable::getTextSelection(pModelObj->getSelection(), "text/plain;charset=utf-8"); OString aExpected("1\t2\t3\t4\t5\t6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t16\t17\t18\t19\t20\t21\n"); CPPUNIT_ASSERT_EQUAL(aExpected, aResult); @@ -266,7 +268,7 @@ void ScTiledRenderingTest::testRowColumnSelections() comphelper::dispatchCommand(".uno:SelectRow", aArgs); // Check if all the rows from 5th to 10th get selected - aResult = pModelObj->getTextSelection("text/plain;charset=utf-8", aUsedMimeType); + aResult = apitest::helper::transferable::getTextSelection(pModelObj->getSelection(), "text/plain;charset=utf-8"); aExpected = "1\t2\t3\t4\t5\t6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t16\t17\t18\t19\t20\t21\n2\t3\t4\t5\t6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t16\t17\t18\t19\t20\t21\t22\n3\t4\t5\t6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t16\t17\t18\t19\t20\t21\t22\t23\n4\t5\t6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t16\t17\t18\t19\t20\t21\t22\t23\t24\n5\t6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t16\t17\t18\t19\t20\t21\t22\t23\t24\t25\n6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t16\t17\t18\t19\t20\t21\t22\t23\t24\t25\t26\n"; CPPUNIT_ASSERT_EQUAL(aExpected, aResult); @@ -279,7 +281,7 @@ void ScTiledRenderingTest::testRowColumnSelections() // When we copy this, we don't get anything useful, but we must not crash // (used to happen) - aResult = pModelObj->getTextSelection("text/plain;charset=utf-8", aUsedMimeType); + aResult = apitest::helper::transferable::getTextSelection(pModelObj->getSelection(), "text/plain;charset=utf-8"); CPPUNIT_ASSERT_EQUAL(OString(), aResult); // TODO check that we really selected what we wanted here @@ -293,7 +295,7 @@ void ScTiledRenderingTest::testRowColumnSelections() // When we copy this, we don't get anything useful, but we must not crash // (used to happen) - aResult = pModelObj->getTextSelection("text/plain;charset=utf-8", aUsedMimeType); + aResult = apitest::helper::transferable::getTextSelection(pModelObj->getSelection(), "text/plain;charset=utf-8"); CPPUNIT_ASSERT_EQUAL(OString(), aResult); // TODO check that we really selected what we wanted here @@ -321,7 +323,7 @@ void ScTiledRenderingTest::testRowColumnSelections() comphelper::dispatchCommand(".uno:SelectRow", aArgs); // only row 5 should remain selected - aResult = pModelObj->getTextSelection("text/plain;charset=utf-8", aUsedMimeType); + aResult = apitest::helper::transferable::getTextSelection(pModelObj->getSelection(), "text/plain;charset=utf-8"); aExpected = "1\t2\t3\t4\t5\t6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t16\t17\t18\t19\t20\t21\n"; CPPUNIT_ASSERT_EQUAL(aExpected, aResult); } @@ -420,11 +422,8 @@ void ScTiledRenderingTest::testEmptyColumnSelection() })); comphelper::dispatchCommand(".uno:SelectColumn", aArgs); - // Get plain selection - OString aUsedMimeType; - OString aResult = pModelObj->getTextSelection("text/plain;charset=utf-8", aUsedMimeType); // should be an empty string - CPPUNIT_ASSERT_EQUAL(OString(), aResult); + CPPUNIT_ASSERT_EQUAL(OString(), apitest::helper::transferable::getTextSelection(pModelObj->getSelection(), "text/plain;charset=utf-8")); } /// A view callback tracks callbacks invoked on one specific view. diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx index 9989eb821c01..3c399a6bc8ec 100644 --- a/sc/source/ui/unoobj/docuno.cxx +++ b/sc/source/ui/unoobj/docuno.cxx @@ -776,7 +776,7 @@ void ScModelObj::setTextSelection(int nType, int nX, int nY) } } -OString ScModelObj::getTextSelection(const char* pMimeType, OString& rUsedMimeType) +uno::Reference<datatransfer::XTransferable> ScModelObj::getSelection() { SolarMutexGuard aGuard; @@ -804,64 +804,7 @@ OString ScModelObj::getTextSelection(const char* pMimeType, OString& rUsedMimeTy if (!xTransferable.is()) xTransferable.set( aDataHelper.GetTransferable() ); - // Take care of UTF-8 text here. - OString aMimeType(pMimeType); - bool bConvert = false; - sal_Int32 nIndex = 0; - if (aMimeType.getToken(0, ';', nIndex) == "text/plain") - { - if (aMimeType.getToken(0, ';', nIndex) == "charset=utf-8") - { - aMimeType = "text/plain;charset=utf-16"; - bConvert = true; - } - } - - datatransfer::DataFlavor aFlavor; - aFlavor.MimeType = OUString::fromUtf8(aMimeType.getStr()); - if (aMimeType == "text/plain;charset=utf-16") - aFlavor.DataType = cppu::UnoType<OUString>::get(); - else - aFlavor.DataType = cppu::UnoType< uno::Sequence<sal_Int8> >::get(); - - if (!xTransferable.is() || !xTransferable->isDataFlavorSupported(aFlavor)) - return OString(); - - uno::Any aAny; - try - { - aAny = xTransferable->getTransferData(aFlavor); - } - catch (const datatransfer::UnsupportedFlavorException& e) - { - SAL_WARN("sc", "Caught " << e); - return OString(); - } - catch (const css::uno::Exception& e) - { - SAL_WARN("sc", "Caught " << e); - return OString(); - } - - OString aRet; - if (aFlavor.DataType == cppu::UnoType<OUString>::get()) - { - OUString aString; - aAny >>= aString; - if (bConvert) - aRet = OUStringToOString(aString, RTL_TEXTENCODING_UTF8); - else - aRet = OString(reinterpret_cast<const sal_Char *>(aString.getStr()), aString.getLength() * sizeof(sal_Unicode)); - } - else - { - uno::Sequence<sal_Int8> aSequence; - aAny >>= aSequence; - aRet = OString(reinterpret_cast<sal_Char*>(aSequence.getArray()), aSequence.getLength()); - } - - rUsedMimeType = pMimeType; - return aRet; + return xTransferable; } void ScModelObj::setGraphicSelection(int nType, int nX, int nY) |