diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2019-06-06 22:20:33 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2019-06-07 12:44:44 +0100 |
commit | 6804b001d4255a38f680182099c6d23d7e53a976 (patch) | |
tree | ecf7e2c3c2be357737cfe38adced8fdac906fd78 /sd | |
parent | a4ec8b5d3df1d78b0288c06109887490c74801ba (diff) |
lok: re-factor getTextSelection.
Change-Id: I2c27c213ee980e19d6020e9599b2b72115e7f28e
Diffstat (limited to 'sd')
-rw-r--r-- | sd/qa/unit/tiledrendering/tiledrendering.cxx | 12 | ||||
-rw-r--r-- | sd/source/ui/inc/ViewShell.hxx | 4 | ||||
-rw-r--r-- | sd/source/ui/inc/unomodel.hxx | 4 | ||||
-rw-r--r-- | sd/source/ui/unoidl/unomodel.cxx | 6 | ||||
-rw-r--r-- | sd/source/ui/view/viewshel.cxx | 53 |
5 files changed, 16 insertions, 63 deletions
diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx index 6044c1e8c554..44dec150a6ab 100644 --- a/sd/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx @@ -10,6 +10,7 @@ #include "../sdmodeltestbase.hxx" #include <app.hrc> #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> @@ -473,11 +474,10 @@ void SdTiledRenderingTest::testGetTextSelection() ESelection aWordSelection(0, 0, 0, 5); rEditView.SetSelection(aWordSelection); // Did we indeed manage to copy the selected text? - OString aUsedFormat; - CPPUNIT_ASSERT_EQUAL(OString("Shape"), pXImpressDocument->getTextSelection("text/plain;charset=utf-8", aUsedFormat)); + CPPUNIT_ASSERT_EQUAL(OString("Shape"), apitest::helper::transferable::getTextSelection(pXImpressDocument->getSelection(), "text/plain;charset=utf-8")); // Make sure returned RTF is not empty. - CPPUNIT_ASSERT(!pXImpressDocument->getTextSelection("text/rtf", aUsedFormat).isEmpty()); + CPPUNIT_ASSERT(!apitest::helper::transferable::getTextSelection(pXImpressDocument->getSelection(), "text/rtf").isEmpty()); comphelper::LibreOfficeKit::setActive(false); } @@ -621,9 +621,8 @@ void SdTiledRenderingTest::testSearchAll() lcl_search("match", /*bFindAll=*/true); - OString aUsedFormat; // This was empty: find-all did not highlight the first match. - CPPUNIT_ASSERT_EQUAL(OString("match"), pXImpressDocument->getTextSelection("text/plain;charset=utf-8", aUsedFormat)); + CPPUNIT_ASSERT_EQUAL(OString("match"), apitest::helper::transferable::getTextSelection(pXImpressDocument->getSelection(), "text/plain;charset=utf-8")); // We're on the first slide, search for something on the second slide and make sure we get a SET_PART. m_nPart = 0; @@ -673,10 +672,9 @@ void SdTiledRenderingTest::testSearchAllFollowedBySearch() lcl_search("third", /*bFindAll=*/true); lcl_search("match" /*,bFindAll=false*/); - OString aUsedFormat; // This used to give wrong result: 'search' after 'search all' still // returned 'third' - CPPUNIT_ASSERT_EQUAL(OString("match"), pXImpressDocument->getTextSelection("text/plain;charset=utf-8", aUsedFormat)); + CPPUNIT_ASSERT_EQUAL(OString("match"), apitest::helper::transferable::getTextSelection(pXImpressDocument->getSelection(), "text/plain;charset=utf-8")); comphelper::LibreOfficeKit::setActive(false); } diff --git a/sd/source/ui/inc/ViewShell.hxx b/sd/source/ui/inc/ViewShell.hxx index fbbfb5f4919e..2872b4cdb312 100644 --- a/sd/source/ui/inc/ViewShell.hxx +++ b/sd/source/ui/inc/ViewShell.hxx @@ -413,8 +413,8 @@ public: /// Allows adjusting the point or mark of the selection to a document coordinate. void SetCursorMm100Position(const Point& rPosition, bool bPoint, bool bClearMark); - /// Gets the currently selected text. - OString GetTextSelection(const OString& aMimeType, OString& rUsedMimeType); + /// Gets the current selectiion + css::uno::Reference<css::datatransfer::XTransferable> GetSelectionTransferrable(); /// Allows starting or ending a graphic move or resize action. void SetGraphicMm100Position(bool bStart, const Point& rPosition); diff --git a/sd/source/ui/inc/unomodel.hxx b/sd/source/ui/inc/unomodel.hxx index b0345ce2d140..440af532e277 100644 --- a/sd/source/ui/inc/unomodel.hxx +++ b/sd/source/ui/inc/unomodel.hxx @@ -251,8 +251,8 @@ public: virtual void postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons, int nModifier) override; /// @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; /// @see lok::Document::resetSelection(). diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index fe0c82d9309a..b0179a1ce148 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -2581,15 +2581,15 @@ void SdXImpressDocument::setTextSelection(int nType, int nX, int nY) } } -OString SdXImpressDocument::getTextSelection(const char* pMimeType, OString& rUsedMimeType) +uno::Reference<datatransfer::XTransferable> SdXImpressDocument::getSelection() { SolarMutexGuard aGuard; DrawViewShell* pViewShell = GetViewShell(); if (!pViewShell) - return OString(); + return uno::Reference<datatransfer::XTransferable>(); - return pViewShell->GetTextSelection(pMimeType, rUsedMimeType); + return pViewShell->GetSelectionTransferrable(); } void SdXImpressDocument::setGraphicSelection(int nType, int nX, int nY) diff --git a/sd/source/ui/view/viewshel.cxx b/sd/source/ui/view/viewshel.cxx index bc732104f2b1..372dce3a119f 100644 --- a/sd/source/ui/view/viewshel.cxx +++ b/sd/source/ui/view/viewshel.cxx @@ -530,62 +530,17 @@ void ViewShell::SetCursorMm100Position(const Point& rPosition, bool bPoint, bool } } -OString ViewShell::GetTextSelection(const OString& _aMimeType, OString& rUsedMimeType) +uno::Reference<datatransfer::XTransferable> ViewShell::GetSelectionTransferrable() { SdrView* pSdrView = GetView(); if (!pSdrView) - return OString(); + return uno::Reference<datatransfer::XTransferable>(); if (!pSdrView->GetTextEditObject()) - return OString(); + return uno::Reference<datatransfer::XTransferable>(); EditView& rEditView = pSdrView->GetTextEditOutlinerView()->GetEditView(); - uno::Reference<datatransfer::XTransferable> xTransferable = rEditView.GetEditEngine()->CreateTransferable(rEditView.GetSelection()); - - // Take care of UTF-8 text here. - bool bConvert = false; - sal_Int32 nIndex = 0; - OString aMimeType = _aMimeType; - 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->isDataFlavorSupported(aFlavor)) - return OString(); - - uno::Any aAny(xTransferable->getTransferData(aFlavor)); - - 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 = _aMimeType; - return aRet; + return rEditView.GetEditEngine()->CreateTransferable(rEditView.GetSelection()); } void ViewShell::SetGraphicMm100Position(bool bStart, const Point& rPosition) |