summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2019-06-06 17:45:24 +0100
committerMichael Meeks <michael.meeks@collabora.com>2019-08-05 21:06:40 -0400
commit02a93a04393e71db36b3891c1dc0718dff3aa4b6 (patch)
tree6b6114d400fe4c7b096379831fffef02c4d82f45 /sd
parent656e941b95222d601daba6a5a2ea72dd534183a8 (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 'sd')
-rw-r--r--sd/qa/unit/tiledrendering/tiledrendering.cxx12
-rw-r--r--sd/source/ui/inc/ViewShell.hxx4
-rw-r--r--sd/source/ui/inc/unomodel.hxx4
-rw-r--r--sd/source/ui/unoidl/unomodel.cxx6
-rw-r--r--sd/source/ui/view/viewshel.cxx53
5 files changed, 16 insertions, 63 deletions
diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx
index 4accff83b9c2..5409bc048e5c 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);
}
@@ -623,9 +623,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;
@@ -675,10 +674,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 ba6412524751..57c2d1df78c6 100644
--- a/sd/source/ui/inc/ViewShell.hxx
+++ b/sd/source/ui/inc/ViewShell.hxx
@@ -412,8 +412,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 f271d7b37b69..9282d0aeef80 100644
--- a/sd/source/ui/inc/unomodel.hxx
+++ b/sd/source/ui/inc/unomodel.hxx
@@ -248,8 +248,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 fbefc1c7e0bf..a1f8dac5ab1c 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2609,15 +2609,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 5b4bc878393a..6a5afbc3d366 100644
--- a/sd/source/ui/view/viewshel.cxx
+++ b/sd/source/ui/view/viewshel.cxx
@@ -521,62 +521,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)