summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2015-06-19 09:53:56 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-06-22 10:27:15 +0200
commitd28da3c486c1fac9d4341b7740960bf683b395db (patch)
tree45914a756e3ff93679799ab3cc0ed3c9fcd6a255 /sd
parentfb61289c0bf6f3f2a6805cead902bbc4ecdb0651 (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> (cherry picked from commit d299041e8cdd0318f79115061e0ab25359c2e396)
Diffstat (limited to 'sd')
-rw-r--r--sd/qa/unit/tiledrendering/tiledrendering.cxx22
-rw-r--r--sd/source/ui/inc/ViewShell.hxx2
-rw-r--r--sd/source/ui/inc/unomodel.hxx2
-rw-r--r--sd/source/ui/unoidl/unomodel.cxx11
-rw-r--r--sd/source/ui/view/viewshel.cxx48
5 files changed, 85 insertions, 0 deletions
diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx
index b41c427d2a7a..c643b0be51c4 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 dc4091709bc9..5bc7101743a3 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2465,6 +2465,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 66c28b462f89..b83fc35485e8 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"
@@ -567,6 +568,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)