sd/qa/unit/tiledrendering/tiledrendering.cxx |   22 ++++++++++++
 sd/source/ui/inc/ViewShell.hxx               |    2 +
 sd/source/ui/inc/unomodel.hxx                |    2 +
 sd/source/ui/unoidl/unomodel.cxx             |   11 ++++++
 sd/source/ui/view/viewshel.cxx               |   48 +++++++++++++++++++++++++++
 sw/source/uibase/uno/unotxdoc.cxx            |    2 +
 6 files changed, 87 insertions(+)

New commits:
commit d299041e8cdd0318f79115061e0ab25359c2e396
Author: Miklos Vajna <vmik...@collabora.co.uk>
Date:   Fri Jun 19 09:53:56 2015 +0200

    sd: implement getTextSelection() in SdXImpressDocument
    
    Change-Id: I29df1873b3954aa64a613e06c53c8e9acfa6a79d
    Reviewed-on: https://gerrit.libreoffice.org/16369
    Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk>
    Tested-by: Jenkins <c...@libreoffice.org>

diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx 
b/sd/qa/unit/tiledrendering/tiledrendering.cxx
index 0523773..6ec2219 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 97ed710..d3dfadb 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 43444b8..2793ca0 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 1029f19..c74f3b1 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 d35cd02..c66405b 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)
diff --git a/sw/source/uibase/uno/unotxdoc.cxx 
b/sw/source/uibase/uno/unotxdoc.cxx
index 6b81c637..b2e6adb 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3257,6 +3257,8 @@ void SwXTextDocument::setTextSelection(int nType, int nX, 
int nY)
 
 OString SwXTextDocument::getTextSelection(const char* pMimeType)
 {
+    SolarMutexGuard aGuard;
+
     uno::Reference<datatransfer::XTransferable> xTransferable;
 
     SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to