[Libreoffice-commits] core.git: Branch 'libreoffice-5-0' - 8 commits - comphelper/source desktop/source include/comphelper include/LibreOfficeKit include/vcl sd/qa sd/source sw/inc sw/qa sw/source

Miklos Vajna vmiklos at collabora.co.uk
Mon Jun 22 02:11:54 PDT 2015


 comphelper/source/misc/lok.cxx                        |    8 +-
 desktop/source/lib/init.cxx                           |   17 ++++-
 include/LibreOfficeKit/LibreOfficeKit.h               |    3 
 include/LibreOfficeKit/LibreOfficeKit.hxx             |    7 +-
 include/comphelper/lok.hxx                            |    2 
 include/vcl/ITiledRenderable.hxx                      |    2 
 sd/qa/unit/tiledrendering/tiledrendering.cxx          |   26 +++++++
 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                        |   59 ++++++++++++++++++
 sw/inc/unotxdoc.hxx                                   |    2 
 sw/qa/extras/tiledrendering/data/shape-with-text.fodt |   17 +++++
 sw/qa/extras/tiledrendering/tiledrendering.cxx        |   40 ++++++++++++
 sw/source/uibase/uno/unotxdoc.cxx                     |   30 ++++++++-
 15 files changed, 212 insertions(+), 16 deletions(-)

New commits:
commit e0400fdde45f432057091833cfd5b4daba7553ae
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Jun 19 18:13:27 2015 +0200

    LOK: return used format in Document::getTextSelection()
    
    This allows requesting text/html, with falling back to plain text if
    necessary.
    
    Conflicts:
    	libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
    
    Reviewed-on: https://gerrit.libreoffice.org/16377
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit af7cbebd8eed82b81e00e6c2e0dc6c2c467ad8e2)
    
    Change-Id: Ie6d4e0e173311ba018553043b6a869abf193bf6f

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 89fe2db..0299431 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -216,7 +216,8 @@ static void doc_setTextSelection (LibreOfficeKitDocument* pThis,
                                   int nX,
                                   int nY);
 static char* doc_getTextSelection(LibreOfficeKitDocument* pThis,
-                                        const char* pMimeType);
+                                  const char* pMimeType,
+                                  char** pUsedMimeType);
 static void doc_setGraphicSelection (LibreOfficeKitDocument* pThis,
                                   int nType,
                                   int nX,
@@ -791,7 +792,7 @@ static void doc_setTextSelection(LibreOfficeKitDocument* pThis, int nType, int n
     pDoc->setTextSelection(nType, nX, nY);
 }
 
-static char* doc_getTextSelection(LibreOfficeKitDocument* pThis, const char* pMimeType)
+static char* doc_getTextSelection(LibreOfficeKitDocument* pThis, const char* pMimeType, char** pUsedMimeType)
 {
     ITiledRenderable* pDoc = getTiledRenderable(pThis);
     if (!pDoc)
@@ -800,10 +801,20 @@ static char* doc_getTextSelection(LibreOfficeKitDocument* pThis, const char* pMi
         return 0;
     }
 
-    OString aRet = pDoc->getTextSelection(pMimeType);
+    OString aUsedMimeType;
+    OString aRet = pDoc->getTextSelection(pMimeType, aUsedMimeType);
+    if (aUsedMimeType.isEmpty())
+        aRet = pDoc->getTextSelection("text/plain;charset=utf-8", aUsedMimeType);
 
     char* pMemory = static_cast<char*>(malloc(aRet.getLength() + 1));
     strcpy(pMemory, aRet.getStr());
+
+    if (pUsedMimeType)
+    {
+        *pUsedMimeType = static_cast<char*>(malloc(aUsedMimeType.getLength() + 1));
+        strcpy(*pUsedMimeType, aUsedMimeType.getStr());
+    }
+
     return pMemory;
 }
 
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 7fbf71b..e3b4850 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -148,7 +148,8 @@ struct _LibreOfficeKitDocumentClass
 
     /// @see lok::Document::getTextSelection
     char* (*getTextSelection) (LibreOfficeKitDocument* pThis,
-                               const char* pMimeType);
+                               const char* pMimeType,
+                               char** pUsedMimeType);
 
     /// @see lok::Document::setGraphicSelection
     void (*setGraphicSelection) (LibreOfficeKitDocument* pThis,
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 2b562b2..816ade5 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -219,11 +219,12 @@ public:
     /**
      * Gets the currently selected text.
      *
-     * @param pMimeType determines the return format, for example text/plain;charset=utf-8.
+     * @param pMimeType suggests the return format, for example text/plain;charset=utf-8.
+     * @param pUsedMimeType output parameter to inform about the determined format (suggested one or plain text).
      */
-    inline char* getTextSelection(const char* pMimeType)
+    inline char* getTextSelection(const char* pMimeType, char** pUsedMimeType = 0)
     {
-        return mpDoc->pClass->getTextSelection(mpDoc, pMimeType);
+        return mpDoc->pClass->getTextSelection(mpDoc, pMimeType, pUsedMimeType);
     }
 
     /**
diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
index 7de3c32..d212519 100644
--- a/include/vcl/ITiledRenderable.hxx
+++ b/include/vcl/ITiledRenderable.hxx
@@ -126,7 +126,7 @@ public:
      *
      * @see lok::Document::getTextSelection().
      */
-    virtual OString getTextSelection(const char* /*pMimeType*/) { return OString(); }
+    virtual OString getTextSelection(const char* /*pMimeType*/, OString& /*rUsedMimeType*/) { return OString(); }
 
     /**
      * Adjusts the graphic selection.
diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx
index dad7c3e..8ed0919 100644
--- a/sd/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx
@@ -302,10 +302,11 @@ void SdTiledRenderingTest::testGetTextSelection()
     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"));
+    OString aUsedFormat;
+    CPPUNIT_ASSERT_EQUAL(OString("Shape"), pXImpressDocument->getTextSelection("text/plain;charset=utf-8", aUsedFormat));
 
     // Make sure returned RTF is not empty.
-    CPPUNIT_ASSERT(!OString(pXImpressDocument->getTextSelection("text/richtext")).isEmpty());
+    CPPUNIT_ASSERT(!OString(pXImpressDocument->getTextSelection("text/richtext", aUsedFormat)).isEmpty());
 }
 
 void SdTiledRenderingTest::testSetGraphicSelection()
diff --git a/sd/source/ui/inc/ViewShell.hxx b/sd/source/ui/inc/ViewShell.hxx
index b0a8682..bc962ca 100644
--- a/sd/source/ui/inc/ViewShell.hxx
+++ b/sd/source/ui/inc/ViewShell.hxx
@@ -452,7 +452,7 @@ 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 GetTextSelection(const OString& aMimeType, OString& rUsedMimeType);
     /// 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 2793ca0..009fb67 100644
--- a/sd/source/ui/inc/unomodel.hxx
+++ b/sd/source/ui/inc/unomodel.hxx
@@ -252,7 +252,7 @@ public:
     /// @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;
+    virtual OString getTextSelection(const char* pMimeType, OString& rUsedMimeType) 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 5bc7101..3b460bf 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2465,7 +2465,7 @@ void SdXImpressDocument::setTextSelection(int nType, int nX, int nY)
     }
 }
 
-OString SdXImpressDocument::getTextSelection(const char* pMimeType)
+OString SdXImpressDocument::getTextSelection(const char* pMimeType, OString& rUsedMimeType)
 {
     SolarMutexGuard aGuard;
 
@@ -2473,7 +2473,7 @@ OString SdXImpressDocument::getTextSelection(const char* pMimeType)
     if (!pViewShell)
         return OString();
 
-    return pViewShell->GetTextSelection(pMimeType);
+    return pViewShell->GetTextSelection(pMimeType, rUsedMimeType);
 }
 
 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 96407dc..51a049e 100644
--- a/sd/source/ui/view/viewshel.cxx
+++ b/sd/source/ui/view/viewshel.cxx
@@ -568,7 +568,7 @@ void ViewShell::SetCursorMm100Position(const Point& rPosition, bool bPoint, bool
     }
 }
 
-OString ViewShell::GetTextSelection(const OString& _aMimeType)
+OString ViewShell::GetTextSelection(const OString& _aMimeType, OString& rUsedMimeType)
 {
     SdrView* pSdrView = GetView();
     if (!pSdrView)
@@ -600,6 +600,9 @@ OString ViewShell::GetTextSelection(const OString& _aMimeType)
     else
         aFlavor.DataType = cppu::UnoType< uno::Sequence<sal_Int8> >::get();
 
+    if (!xTransferable->isDataFlavorSupported(aFlavor))
+        return OString();
+
     uno::Any aAny(xTransferable->getTransferData(aFlavor));
 
     OString aRet;
@@ -619,6 +622,7 @@ OString ViewShell::GetTextSelection(const OString& _aMimeType)
         aRet = OString(reinterpret_cast<sal_Char*>(aSequence.getArray()), aSequence.getLength());
     }
 
+    rUsedMimeType = _aMimeType;
     return aRet;
 }
 
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index a90272a..c90a852 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -418,7 +418,7 @@ public:
     /// @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;
+    virtual OString getTextSelection(const char* pMimeType, OString& rUsedMimeType) SAL_OVERRIDE;
     /// @see vcl::ITiledRenderable::setGraphicSelection().
     virtual void setGraphicSelection(int nType, int nX, int nY) SAL_OVERRIDE;
     /// @see vcl::ITiledRenderable::resetSelection().
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 8d9d6ae..07dd7e3 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -222,7 +222,8 @@ void SwTiledRenderingTest::testGetTextSelection()
 
     SwXTextDocument* pXTextDocument = createDoc("shape-with-text.fodt");
     // No crash, just empty output for unexpected mime type.
-    CPPUNIT_ASSERT_EQUAL(OString(), pXTextDocument->getTextSelection("foo/bar"));
+    OString aUsedFormat;
+    CPPUNIT_ASSERT_EQUAL(OString(), pXTextDocument->getTextSelection("foo/bar", aUsedFormat));
 
     SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
     // Move the cursor into the first word.
@@ -231,10 +232,10 @@ void SwTiledRenderingTest::testGetTextSelection()
     pWrtShell->SelWrd();
 
     // Make sure that we selected text from the body text.
-    CPPUNIT_ASSERT_EQUAL(OString("Hello"), pXTextDocument->getTextSelection("text/plain;charset=utf-8"));
+    CPPUNIT_ASSERT_EQUAL(OString("Hello"), pXTextDocument->getTextSelection("text/plain;charset=utf-8", aUsedFormat));
 
     // Make sure we produce something for HTML.
-    CPPUNIT_ASSERT(!OString(pXTextDocument->getTextSelection("text/html")).isEmpty());
+    CPPUNIT_ASSERT(!OString(pXTextDocument->getTextSelection("text/html", aUsedFormat)).isEmpty());
 
     // Now select some shape text and check again.
     SdrPage* pPage = pWrtShell->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
@@ -245,7 +246,7 @@ void SwTiledRenderingTest::testGetTextSelection()
     EditView& rEditView = pView->GetTextEditOutlinerView()->GetEditView();
     ESelection aWordSelection(0, 0, 0, 5);
     rEditView.SetSelection(aWordSelection);
-    CPPUNIT_ASSERT_EQUAL(OString("Shape"), pXTextDocument->getTextSelection("text/plain;charset=utf-8"));
+    CPPUNIT_ASSERT_EQUAL(OString("Shape"), pXTextDocument->getTextSelection("text/plain;charset=utf-8", aUsedFormat));
 
     comphelper::LibreOfficeKit::setActive(false);
 }
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index b17b234..b7cdf1d 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3257,7 +3257,7 @@ void SwXTextDocument::setTextSelection(int nType, int nX, int nY)
     }
 }
 
-OString SwXTextDocument::getTextSelection(const char* pMimeType)
+OString SwXTextDocument::getTextSelection(const char* pMimeType, OString& rUsedMimeType)
 {
     SolarMutexGuard aGuard;
 
@@ -3319,6 +3319,7 @@ OString SwXTextDocument::getTextSelection(const char* pMimeType)
         aRet = OString(reinterpret_cast<sal_Char*>(aSequence.getArray()), aSequence.getLength());
     }
 
+    rUsedMimeType = pMimeType;
     return aRet;
 }
 
commit 71b768b4f64d469a2e440403206eaeedd851a1cc
Author: Noel Grandin <noel at peralex.com>
Date:   Fri Jun 19 12:51:57 2015 +0200

    loplugin:passstuffbyref
    
    Change-Id: Ic889efaca00ad9600b1b5c8452aa7ee819e63c89
    (cherry picked from commit a61e55a2c8b1c555de905986834462f3ce31621c)

diff --git a/sd/source/ui/inc/ViewShell.hxx b/sd/source/ui/inc/ViewShell.hxx
index d3dfadb..b0a8682 100644
--- a/sd/source/ui/inc/ViewShell.hxx
+++ b/sd/source/ui/inc/ViewShell.hxx
@@ -452,7 +452,7 @@ 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(OString aMimeType);
+    OString GetTextSelection(const 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/view/viewshel.cxx b/sd/source/ui/view/viewshel.cxx
index 7b840f3..96407dc 100644
--- a/sd/source/ui/view/viewshel.cxx
+++ b/sd/source/ui/view/viewshel.cxx
@@ -568,7 +568,7 @@ void ViewShell::SetCursorMm100Position(const Point& rPosition, bool bPoint, bool
     }
 }
 
-OString ViewShell::GetTextSelection(OString aMimeType)
+OString ViewShell::GetTextSelection(const OString& _aMimeType)
 {
     SdrView* pSdrView = GetView();
     if (!pSdrView)
@@ -583,6 +583,7 @@ OString ViewShell::GetTextSelection(OString aMimeType)
     // 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")
commit 9f7b508e934f4bcfac62129b169ff11288e1c4cd
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Jun 19 16:14:59 2015 +0200

    sd::ViewShell::GetTextSelection: fix text/richtext handling
    
    Change-Id: If7d75d48667cd48d9426b02a38d2cf539b248d26
    (cherry picked from commit abd92f37ee5840cc46bf26c4bfabc22ef5457ebe)

diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx
index c643b0b..dad7c3e 100644
--- a/sd/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx
@@ -303,6 +303,9 @@ void SdTiledRenderingTest::testGetTextSelection()
     rEditView.SetSelection(aWordSelection);
     // Did we indeed manage to copy the selected text?
     CPPUNIT_ASSERT_EQUAL(OString("Shape"), pXImpressDocument->getTextSelection("text/plain;charset=utf-8"));
+
+    // Make sure returned RTF is not empty.
+    CPPUNIT_ASSERT(!OString(pXImpressDocument->getTextSelection("text/richtext")).isEmpty());
 }
 
 void SdTiledRenderingTest::testSetGraphicSelection()
diff --git a/sd/source/ui/view/viewshel.cxx b/sd/source/ui/view/viewshel.cxx
index b83fc35..7b840f3 100644
--- a/sd/source/ui/view/viewshel.cxx
+++ b/sd/source/ui/view/viewshel.cxx
@@ -611,6 +611,12 @@ OString ViewShell::GetTextSelection(OString aMimeType)
         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());
+    }
 
     return aRet;
 }
commit 52a02a3980a0b5a55e922301d1b196fcbb3440f9
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Jun 19 15:12:54 2015 +0200

    SwXTextDocument::getTextSelection: fix missing non-string content handling
    
    text/html works with this.
    
    Change-Id: I749e0c987a87dbc6700956f564f6846617c393e8
    (cherry picked from commit e72e79dfa3342482214b37435550e534cfdfc08e)

diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 1006ef9..8d9d6ae 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -233,6 +233,9 @@ void SwTiledRenderingTest::testGetTextSelection()
     // Make sure that we selected text from the body text.
     CPPUNIT_ASSERT_EQUAL(OString("Hello"), pXTextDocument->getTextSelection("text/plain;charset=utf-8"));
 
+    // Make sure we produce something for HTML.
+    CPPUNIT_ASSERT(!OString(pXTextDocument->getTextSelection("text/html")).isEmpty());
+
     // Now select some shape text and check again.
     SdrPage* pPage = pWrtShell->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
     SdrObject* pObject = pPage->GetObj(0);
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 3311526..b17b234 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3312,6 +3312,12 @@ OString SwXTextDocument::getTextSelection(const char* pMimeType)
         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());
+    }
 
     return aRet;
 }
commit 91aa1d81cd0017951afc2470345e039595a08141
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Jun 19 11:16:21 2015 +0200

    SwXTextDocument::getTextSelection: fix crash on unsupported mime type
    
    SdXImpressDocument didn't have this problem, FWIW.
    
    Change-Id: Ic88311596b7b92a8e972f366b9e82cca850244f8
    (cherry picked from commit 0b532178a4936cb6014eba10aa6d5e1f33682e6e)

diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 989e1c7..1006ef9 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -221,6 +221,9 @@ void SwTiledRenderingTest::testGetTextSelection()
     comphelper::LibreOfficeKit::setActive();
 
     SwXTextDocument* pXTextDocument = createDoc("shape-with-text.fodt");
+    // No crash, just empty output for unexpected mime type.
+    CPPUNIT_ASSERT_EQUAL(OString(), pXTextDocument->getTextSelection("foo/bar"));
+
     SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
     // Move the cursor into the first word.
     pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 2, /*bBasicCall=*/false);
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 0e17be4..3311526 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3297,6 +3297,9 @@ OString SwXTextDocument::getTextSelection(const char* pMimeType)
     else
         aFlavor.DataType = cppu::UnoType< uno::Sequence<sal_Int8> >::get();
 
+    if (!xTransferable->isDataFlavorSupported(aFlavor))
+        return OString();
+
     uno::Any aAny(xTransferable->getTransferData(aFlavor));
 
     OString aRet;
commit d28da3c486c1fac9d4341b7740960bf683b395db
Author: Miklos Vajna <vmiklos at 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 <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit d299041e8cdd0318f79115061e0ab25359c2e396)

diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx
index b41c427..c643b0b 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 dc40917..5bc7101 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 66c28b4..b83fc35 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)
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 82c8116..0e17be4 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3259,6 +3259,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();
commit fb61289c0bf6f3f2a6805cead902bbc4ecdb0651
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Jun 18 14:12:04 2015 +0200

    Add SwTiledRenderingTest::testGetTextSelection() testcase.
    
    Fails without commit 193b907b2bc49b9e48cfab2583e81a24aaa2e666
    (SwXTextDocument::getTextSelection: fix missing editeng forward,
    2015-06-18).
    
    Change-Id: I5fdab128471c12901f930b6b4ab4e2304dd3fe64
    Reviewed-on: https://gerrit.libreoffice.org/16359
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>
    (cherry picked from commit bcace9acafa24d5251e90587af776fdb0a808ed8)

diff --git a/comphelper/source/misc/lok.cxx b/comphelper/source/misc/lok.cxx
index fc8a09d..a6abd2a 100644
--- a/comphelper/source/misc/lok.cxx
+++ b/comphelper/source/misc/lok.cxx
@@ -15,16 +15,16 @@ namespace comphelper
 namespace LibreOfficeKit
 {
 
-static bool bActive(false);
+static bool g_bActive(false);
 
-void setActive()
+void setActive(bool bActive)
 {
-    bActive = true;
+    g_bActive = bActive;
 }
 
 bool isActive()
 {
-    return bActive;
+    return g_bActive;
 }
 
 static void (*pStatusIndicatorCallback)(void *data, statusIndicatorCallbackType type, int percent)(nullptr);
diff --git a/include/comphelper/lok.hxx b/include/comphelper/lok.hxx
index 704fb1f..79fa115 100644
--- a/include/comphelper/lok.hxx
+++ b/include/comphelper/lok.hxx
@@ -24,7 +24,7 @@ namespace LibreOfficeKit
 // Functions to be called only from the LibreOfficeKit implementation in desktop, not from other
 // places in LibreOffice code.
 
-COMPHELPER_DLLPUBLIC void setActive();
+COMPHELPER_DLLPUBLIC void setActive(bool bActive = true);
 
 enum class statusIndicatorCallbackType { Start, SetValue, Finish };
 
diff --git a/sw/qa/extras/tiledrendering/data/shape-with-text.fodt b/sw/qa/extras/tiledrendering/data/shape-with-text.fodt
new file mode 100644
index 0000000..ce76aaf
--- /dev/null
+++ b/sw/qa/extras/tiledrendering/data/shape-with-text.fodt
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:config="urn:oas
 is:names:tc:opendocument:xmlns:config:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:drawooo="http://openoffice.org/2010/draw" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:
 experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:body>
+  <office:text>
+   <text:sequence-decls>
+    <text:sequence-decl text:display-outline-level="0" text:name="Illustration"/>
+    <text:sequence-decl text:display-outline-level="0" text:name="Table"/>
+    <text:sequence-decl text:display-outline-level="0" text:name="Text"/>
+    <text:sequence-decl text:display-outline-level="0" text:name="Drawing"/>
+   </text:sequence-decls>
+   <text:p><draw:custom-shape text:anchor-type="paragraph" draw:z-index="0" svg:width="4.883cm" svg:height="3.225cm" svg:x="2.602cm" svg:y="1.178cm">
+     <text:p>Shape text</text:p>
+     <draw:enhanced-geometry svg:viewBox="0 0 21600 21600" draw:glue-points="10800 0 3163 3163 0 10800 3163 18437 10800 21600 18437 18437 21600 10800 18437 3163" draw:text-areas="3163 3163 18437 18437" draw:type="ellipse" draw:enhanced-path="U 10800 10800 10800 10800 0 360 Z N"/>
+    </draw:custom-shape>Hello.</text:p>
+  </office:text>
+ </office:body>
+</office:document>
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index b139b16..989e1c7 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -12,9 +12,12 @@
 #include <comphelper/dispatchcommand.hxx>
 #include <comphelper/propertysequence.hxx>
 #include <comphelper/string.hxx>
+#include <comphelper/lok.hxx>
 #include <svx/svdpage.hxx>
 #include <svx/svdview.hxx>
 #include <vcl/svapp.hxx>
+#include <editeng/editview.hxx>
+#include <editeng/outliner.hxx>
 #include <crsskip.hxx>
 #include <drawdoc.hxx>
 #include <ndtxt.hxx>
@@ -31,6 +34,7 @@ public:
     void testPostKeyEvent();
     void testPostMouseEvent();
     void testSetTextSelection();
+    void testGetTextSelection();
     void testSetGraphicSelection();
     void testResetSelection();
     void testSearch();
@@ -44,6 +48,7 @@ public:
     CPPUNIT_TEST(testPostKeyEvent);
     CPPUNIT_TEST(testPostMouseEvent);
     CPPUNIT_TEST(testSetTextSelection);
+    CPPUNIT_TEST(testGetTextSelection);
     CPPUNIT_TEST(testSetGraphicSelection);
     CPPUNIT_TEST(testResetSelection);
     CPPUNIT_TEST(testSearch);
@@ -211,6 +216,34 @@ void SwTiledRenderingTest::testSetTextSelection()
     CPPUNIT_ASSERT_EQUAL(OUString("Aaa b"), pShellCrsr->GetText());
 }
 
+void SwTiledRenderingTest::testGetTextSelection()
+{
+    comphelper::LibreOfficeKit::setActive();
+
+    SwXTextDocument* pXTextDocument = createDoc("shape-with-text.fodt");
+    SwWrtShell* pWrtShell = pXTextDocument->GetDocShell()->GetWrtShell();
+    // Move the cursor into the first word.
+    pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 2, /*bBasicCall=*/false);
+    // Create a selection by on the word.
+    pWrtShell->SelWrd();
+
+    // Make sure that we selected text from the body text.
+    CPPUNIT_ASSERT_EQUAL(OString("Hello"), pXTextDocument->getTextSelection("text/plain;charset=utf-8"));
+
+    // Now select some shape text and check again.
+    SdrPage* pPage = pWrtShell->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
+    SdrObject* pObject = pPage->GetObj(0);
+    SdrView* pView = pWrtShell->GetDrawView();
+    pView->SdrBeginTextEdit(pObject);
+    CPPUNIT_ASSERT(pView->GetTextEditObject());
+    EditView& rEditView = pView->GetTextEditOutlinerView()->GetEditView();
+    ESelection aWordSelection(0, 0, 0, 5);
+    rEditView.SetSelection(aWordSelection);
+    CPPUNIT_ASSERT_EQUAL(OString("Shape"), pXTextDocument->getTextSelection("text/plain;charset=utf-8"));
+
+    comphelper::LibreOfficeKit::setActive(false);
+}
+
 void SwTiledRenderingTest::testSetGraphicSelection()
 {
     SwXTextDocument* pXTextDocument = createDoc("shape.fodt");
commit 55ff31748b7dc337aa0369ac8c7864f01e296d42
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Jun 18 14:03:00 2015 +0200

    SwXTextDocument::getTextSelection: fix missing editeng forward
    
    When editing shape text, the text selection should be provided by
    editeng.
    
    Change-Id: I379f89fc28d2ff8172d0411bba347c959de6ab29
    (cherry picked from commit 193b907b2bc49b9e48cfab2583e81a24aaa2e666)

diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 4e96b6c..82c8116 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -142,6 +142,7 @@
 
 #include <editeng/eeitem.hxx>
 #include <editeng/editeng.hxx>
+#include <editeng/editview.hxx>
 #include <svx/svdoutl.hxx>
 #include <svl/languageoptions.hxx>
 #include <svx/svdview.hxx>
@@ -3258,8 +3259,21 @@ void SwXTextDocument::setTextSelection(int nType, int nX, int nY)
 
 OString SwXTextDocument::getTextSelection(const char* pMimeType)
 {
+    uno::Reference<datatransfer::XTransferable> xTransferable;
+
     SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
-    uno::Reference<datatransfer::XTransferable> xTransferable(new SwTransferable(*pWrtShell));
+    if (SdrView* pSdrView = pWrtShell->GetDrawView())
+    {
+        if (pSdrView->GetTextEditObject())
+        {
+            // Editing shape text
+            EditView& rEditView = pSdrView->GetTextEditOutlinerView()->GetEditView();
+            xTransferable = rEditView.GetEditEngine()->CreateTransferable(rEditView.GetSelection());
+        }
+    }
+
+    if (!xTransferable.is())
+        xTransferable = new SwTransferable(*pWrtShell);
 
     // Take care of UTF-8 text here.
     OString aMimeType(pMimeType);


More information about the Libreoffice-commits mailing list