diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-06-19 09:53:56 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-06-19 09:22:54 +0000 |
commit | d299041e8cdd0318f79115061e0ab25359c2e396 (patch) | |
tree | bba5424f60a79972aeab4dc81faa4835f4a55a68 /sd | |
parent | c38e0f01ac23dc6b75c8bf23af277940310097d1 (diff) |
sd: implement getTextSelection() in SdXImpressDocument
Change-Id: I29df1873b3954aa64a613e06c53c8e9acfa6a79d
Reviewed-on: https://gerrit.libreoffice.org/16369
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'sd')
-rw-r--r-- | sd/qa/unit/tiledrendering/tiledrendering.cxx | 22 | ||||
-rw-r--r-- | sd/source/ui/inc/ViewShell.hxx | 2 | ||||
-rw-r--r-- | sd/source/ui/inc/unomodel.hxx | 2 | ||||
-rw-r--r-- | sd/source/ui/unoidl/unomodel.cxx | 11 | ||||
-rw-r--r-- | sd/source/ui/view/viewshel.cxx | 48 |
5 files changed, 85 insertions, 0 deletions
diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx index 05237736b4eb..6ec221990884 100644 --- a/sd/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx @@ -46,6 +46,7 @@ public: void testPostKeyEvent(); void testPostMouseEvent(); void testSetTextSelection(); + void testGetTextSelection(); void testSetGraphicSelection(); void testResetSelection(); void testSearch(); @@ -57,6 +58,7 @@ public: CPPUNIT_TEST(testPostKeyEvent); CPPUNIT_TEST(testPostMouseEvent); CPPUNIT_TEST(testSetTextSelection); + CPPUNIT_TEST(testGetTextSelection); CPPUNIT_TEST(testSetGraphicSelection); CPPUNIT_TEST(testResetSelection); CPPUNIT_TEST(testSearch); @@ -283,6 +285,26 @@ void SdTiledRenderingTest::testSetTextSelection() CPPUNIT_ASSERT_EQUAL(OUString("bbb."), rEditView.GetSelected()); } +void SdTiledRenderingTest::testGetTextSelection() +{ + SdXImpressDocument* pXImpressDocument = createDoc("dummy.odp"); + uno::Reference<container::XIndexAccess> xDrawPage(pXImpressDocument->getDrawPages()->getByIndex(0), uno::UNO_QUERY); + uno::Reference<text::XTextRange> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY); + xShape->setString("Shape"); + // Create a selection on the shape text. + sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell(); + SdPage* pActualPage = pViewShell->GetActualPage(); + SdrObject* pObject = pActualPage->GetObj(0); + SdrView* pView = pViewShell->GetView(); + pView->SdrBeginTextEdit(pObject); + CPPUNIT_ASSERT(pView->GetTextEditObject()); + EditView& rEditView = pView->GetTextEditOutlinerView()->GetEditView(); + ESelection aWordSelection(0, 0, 0, 5); + rEditView.SetSelection(aWordSelection); + // Did we indeed manage to copy the selected text? + CPPUNIT_ASSERT_EQUAL(OString("Shape"), pXImpressDocument->getTextSelection("text/plain;charset=utf-8")); +} + void SdTiledRenderingTest::testSetGraphicSelection() { SdXImpressDocument* pXImpressDocument = createDoc("shape.odp"); diff --git a/sd/source/ui/inc/ViewShell.hxx b/sd/source/ui/inc/ViewShell.hxx index 97ed710a68f7..d3dfadb891af 100644 --- a/sd/source/ui/inc/ViewShell.hxx +++ b/sd/source/ui/inc/ViewShell.hxx @@ -451,6 +451,8 @@ public: void LogicMouseMove(const MouseEvent& rMouseEvent); /// 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(OString aMimeType); /// 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 43444b83c1b9..2793ca09617b 100644 --- a/sd/source/ui/inc/unomodel.hxx +++ b/sd/source/ui/inc/unomodel.hxx @@ -251,6 +251,8 @@ public: virtual void postMouseEvent(int nType, int nX, int nY, int nCount) SAL_OVERRIDE; /// @see vcl::ITiledRenderable::setTextSelection(). virtual void setTextSelection(int nType, int nX, int nY) SAL_OVERRIDE; + /// @see vcl::ITiledRenderable::getTextSelection(). + virtual OString getTextSelection(const char* pMimeType) SAL_OVERRIDE; /// @see vcl::ITiledRenderable::setGraphicSelection(). virtual void setGraphicSelection(int nType, int nX, int nY) SAL_OVERRIDE; /// @see lok::Document::resetSelection(). diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index 1029f1908525..c74f3b1ffdbb 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -2446,6 +2446,17 @@ void SdXImpressDocument::setTextSelection(int nType, int nX, int nY) } } +OString SdXImpressDocument::getTextSelection(const char* pMimeType) +{ + SolarMutexGuard aGuard; + + DrawViewShell* pViewShell = GetViewShell(); + if (!pViewShell) + return OString(); + + return pViewShell->GetTextSelection(pMimeType); +} + void SdXImpressDocument::setGraphicSelection(int nType, int nX, int nY) { SolarMutexGuard aGuard; diff --git a/sd/source/ui/view/viewshel.cxx b/sd/source/ui/view/viewshel.cxx index d35cd0213478..c66405b47e2a 100644 --- a/sd/source/ui/view/viewshel.cxx +++ b/sd/source/ui/view/viewshel.cxx @@ -78,6 +78,7 @@ #include <editeng/numitem.hxx> #include <editeng/eeitem.hxx> #include <editeng/editview.hxx> +#include <editeng/editeng.hxx> #include <svl/poolitem.hxx> #include <glob.hrc> #include "AccessibleDocumentViewBase.hxx" @@ -552,6 +553,53 @@ void ViewShell::SetCursorMm100Position(const Point& rPosition, bool bPoint, bool } } +OString ViewShell::GetTextSelection(OString aMimeType) +{ + SdrView* pSdrView = GetView(); + if (!pSdrView) + return OString(); + + if (!pSdrView->GetTextEditObject()) + return OString(); + + 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; + 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(); + + 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)); + } + + return aRet; +} + void ViewShell::SetGraphicMm100Position(bool bStart, const Point& rPosition) { if (bStart) |