[Libreoffice-commits] core.git: desktop/source include/LibreOfficeKit include/vcl libreofficekit/qa sd/qa sd/source sw/inc sw/qa sw/source
Miklos Vajna
vmiklos at collabora.co.uk
Fri Jun 19 11:01:15 PDT 2015
desktop/source/lib/init.cxx | 17 ++++++++++++++---
include/LibreOfficeKit/LibreOfficeKit.h | 3 ++-
include/LibreOfficeKit/LibreOfficeKit.hxx | 7 ++++---
include/vcl/ITiledRenderable.hxx | 2 +-
libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx | 4 +++-
sd/qa/unit/tiledrendering/tiledrendering.cxx | 5 +++--
sd/source/ui/inc/ViewShell.hxx | 2 +-
sd/source/ui/inc/unomodel.hxx | 2 +-
sd/source/ui/unoidl/unomodel.cxx | 4 ++--
sd/source/ui/view/viewshel.cxx | 6 +++++-
sw/inc/unotxdoc.hxx | 2 +-
sw/qa/extras/tiledrendering/tiledrendering.cxx | 9 +++++----
sw/source/uibase/uno/unotxdoc.cxx | 3 ++-
13 files changed, 44 insertions(+), 22 deletions(-)
New commits:
commit af7cbebd8eed82b81e00e6c2e0dc6c2c467ad8e2
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.
Change-Id: Ie6d4e0e173311ba018553043b6a869abf193bf6f
Reviewed-on: https://gerrit.libreoffice.org/16377
Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
Tested-by: Jenkins <ci at libreoffice.org>
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 23c52bc..c043e04 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/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 9496ba5..7d4960d 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 55c4426..a36cfba 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 c74f3b1..4940b08 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 f8c45b5..396a796 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 78ec974..21907d4 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 e2008ac..1062667 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;
}
More information about the Libreoffice-commits
mailing list