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-19 18:00:53 +0000 |
commit | af7cbebd8eed82b81e00e6c2e0dc6c2c467ad8e2 (patch) | |
tree | 2172475e22afce046cb1e9b1fb6528574bc16cf4 | |
parent | 69e9c082f07206a1a589c49f679f92c2162e830d (diff) |
LOK: return used format in Document::getTextSelection()
This allows requesting text/html, with falling back to plain text if
necessary.
Change-Id: Ie6d4e0e173311ba018553043b6a869abf193bf6f
Reviewed-on: https://gerrit.libreoffice.org/16377
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
-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-- | libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx | 4 | ||||
-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 |
13 files changed, 44 insertions, 22 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 23c52bc38a3e..c043e04a22a0 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/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx index 9496ba5ea180..7d4960d520d9 100644 --- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx @@ -130,12 +130,14 @@ static void doCopy(GtkWidget* /*pButton*/, gpointer /*pItem*/) { LOKDocView* pLOKDocView = LOK_DOC_VIEW(pDocView); LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(pLOKDocView); - char* pSelection = pDocument->pClass->getTextSelection(pDocument, "text/plain;charset=utf-8"); + char* pUsedFormat = 0; + char* pSelection = pDocument->pClass->getTextSelection(pDocument, "text/plain;charset=utf-8", &pUsedFormat); GtkClipboard* pClipboard = gtk_clipboard_get_for_display(gtk_widget_get_display(pDocView), GDK_SELECTION_CLIPBOARD); gtk_clipboard_set_text(pClipboard, pSelection, -1); free(pSelection); + free(pUsedFormat); } /// Get the visible area of the scrolled window diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx index 55c4426c05fc..a36cfba7324c 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 c74f3b1ffdbb..4940b08ce810 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -2446,7 +2446,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; @@ -2454,7 +2454,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 f8c45b5a912f..396a796e833a 100644 --- a/sd/source/ui/view/viewshel.cxx +++ b/sd/source/ui/view/viewshel.cxx @@ -553,7 +553,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) @@ -585,6 +585,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; @@ -604,6 +607,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 78ec974f7787..21907d4aa483 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 e2008accf93c..1062667992ef 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -3255,7 +3255,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; @@ -3317,6 +3317,7 @@ OString SwXTextDocument::getTextSelection(const char* pMimeType) aRet = OString(reinterpret_cast<sal_Char*>(aSequence.getArray()), aSequence.getLength()); } + rUsedMimeType = pMimeType; return aRet; } |