diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-06-19 18:13:27 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-06-22 10:32:01 +0200 |
commit | e0400fdde45f432057091833cfd5b4daba7553ae (patch) | |
tree | 2620184fc8c54a81c4a418f64455293ef69007e8 | |
parent | 71b768b4f64d469a2e440403206eaeedd851a1cc (diff) |
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@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
(cherry picked from commit af7cbebd8eed82b81e00e6c2e0dc6c2c467ad8e2)
Change-Id: Ie6d4e0e173311ba018553043b6a869abf193bf6f
-rw-r--r-- | desktop/source/lib/init.cxx | 17 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.h | 3 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.hxx | 7 | ||||
-rw-r--r-- | include/vcl/ITiledRenderable.hxx | 2 | ||||
-rw-r--r-- | sd/qa/unit/tiledrendering/tiledrendering.cxx | 5 | ||||
-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 | 4 | ||||
-rw-r--r-- | sd/source/ui/view/viewshel.cxx | 6 | ||||
-rw-r--r-- | sw/inc/unotxdoc.hxx | 2 | ||||
-rw-r--r-- | sw/qa/extras/tiledrendering/tiledrendering.cxx | 9 | ||||
-rw-r--r-- | sw/source/uibase/uno/unotxdoc.cxx | 3 |
12 files changed, 41 insertions, 21 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 89fe2dbd366e..02994319c079 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 7fbf71b8667a..e3b485052444 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 2b562b261743..816ade5649b2 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 7de3c3219e4a..d212519bc9be 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 dad7c3e3c8cc..8ed091998ef1 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 b0a868282453..bc962ca59810 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 2793ca09617b..009fb672cf27 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 5bc7101743a3..3b460bfb6cf2 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 96407dcf3626..51a049e4d66d 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 a90272aa2a6b..c90a852ac8ee 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 8d9d6ae44443..07dd7e34b29c 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 b17b2344b49c..b7cdf1d300fe 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; } |