[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.0' - 10 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:37:54 PDT 2015
comphelper/source/misc/lok.cxx | 8 +-
desktop/source/lib/init.cxx | 30 +++++++
include/LibreOfficeKit/LibreOfficeKit.h | 5 +
include/LibreOfficeKit/LibreOfficeKit.hxx | 11 ++
include/comphelper/lok.hxx | 2
include/vcl/ITiledRenderable.hxx | 7 +
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/dochdl/swdtflvr.cxx | 3
sw/source/uibase/uno/unotxdoc.cxx | 68 ++++++++++++++++++
16 files changed, 287 insertions(+), 6 deletions(-)
New commits:
commit 801f24f0b87c3d159cc68e1cbb2d4a7ebc34b5ea
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 7b534de..3436515 100644
--- a/sd/source/ui/inc/ViewShell.hxx
+++ b/sd/source/ui/inc/ViewShell.hxx
@@ -450,7 +450,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 5885cbd..a50f95e 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2462,7 +2462,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;
@@ -2470,7 +2470,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 2552090..6978288 100644
--- a/sd/source/ui/view/viewshel.cxx
+++ b/sd/source/ui/view/viewshel.cxx
@@ -555,7 +555,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)
@@ -587,6 +587,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;
@@ -606,6 +609,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 5095443d20dc8f474372fb217939526b11156917
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 97c4474..7b534de 100644
--- a/sd/source/ui/inc/ViewShell.hxx
+++ b/sd/source/ui/inc/ViewShell.hxx
@@ -450,7 +450,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 9c2cf02..2552090 100644
--- a/sd/source/ui/view/viewshel.cxx
+++ b/sd/source/ui/view/viewshel.cxx
@@ -555,7 +555,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)
@@ -570,6 +570,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 cf51ec84b0531f021be5514f6da8313219ee858e
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 1954f42..9c2cf02 100644
--- a/sd/source/ui/view/viewshel.cxx
+++ b/sd/source/ui/view/viewshel.cxx
@@ -598,6 +598,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 df3ccb24c561de5a8ab59c62e5ddd1a59199eaf7
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 d70c86c7eee13232fd612814baf9076cc0b67479
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 9dc677fd466c430dd412847e625b1ad1ca736283
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 49417b6..97c4474 100644
--- a/sd/source/ui/inc/ViewShell.hxx
+++ b/sd/source/ui/inc/ViewShell.hxx
@@ -449,6 +449,8 @@ public:
void LogicMouseButtonUp(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 5190351..5885cbd 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2462,6 +2462,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 402c9a0..1954f42 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"
@@ -554,6 +555,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 3f0d2a1cd5508c2e0c10b4a280c88ad703853548
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 4de6d972ee747a49221d26522924ff6051f8f721
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);
commit 7160685d541605bda21fbb434e975c4452799abd
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Wed Jun 17 18:00:01 2015 +0200
LOK: add lok::Document::getTextSelection()
I.e. the copy part of copy&paste. Only the Writer bits for now.
Change-Id: Ia003e76e3b234735f472cdef125514f9771d8640
(cherry picked from commit cfc4375158ee174e8dcb4df319b82c0bdd6f31cc)
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 71e9431..89fe2db 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -215,6 +215,8 @@ static void doc_setTextSelection (LibreOfficeKitDocument* pThis,
int nType,
int nX,
int nY);
+static char* doc_getTextSelection(LibreOfficeKitDocument* pThis,
+ const char* pMimeType);
static void doc_setGraphicSelection (LibreOfficeKitDocument* pThis,
int nType,
int nX,
@@ -251,6 +253,7 @@ struct LibLODocument_Impl : public _LibreOfficeKitDocument
m_pDocumentClass->postMouseEvent = doc_postMouseEvent;
m_pDocumentClass->postUnoCommand = doc_postUnoCommand;
m_pDocumentClass->setTextSelection = doc_setTextSelection;
+ m_pDocumentClass->getTextSelection = doc_getTextSelection;
m_pDocumentClass->setGraphicSelection = doc_setGraphicSelection;
m_pDocumentClass->resetSelection = doc_resetSelection;
@@ -788,6 +791,22 @@ static void doc_setTextSelection(LibreOfficeKitDocument* pThis, int nType, int n
pDoc->setTextSelection(nType, nX, nY);
}
+static char* doc_getTextSelection(LibreOfficeKitDocument* pThis, const char* pMimeType)
+{
+ ITiledRenderable* pDoc = getTiledRenderable(pThis);
+ if (!pDoc)
+ {
+ gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
+ return 0;
+ }
+
+ OString aRet = pDoc->getTextSelection(pMimeType);
+
+ char* pMemory = static_cast<char*>(malloc(aRet.getLength() + 1));
+ strcpy(pMemory, aRet.getStr());
+ return pMemory;
+}
+
static void doc_setGraphicSelection(LibreOfficeKitDocument* pThis, int nType, int nX, int nY)
{
ITiledRenderable* pDoc = getTiledRenderable(pThis);
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 7eb42e8..7fbf71b 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -146,6 +146,10 @@ struct _LibreOfficeKitDocumentClass
int nX,
int nY);
+ /// @see lok::Document::getTextSelection
+ char* (*getTextSelection) (LibreOfficeKitDocument* pThis,
+ const char* pMimeType);
+
/// @see lok::Document::setGraphicSelection
void (*setGraphicSelection) (LibreOfficeKitDocument* pThis,
int nType,
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index bd8832a..2b562b2 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -217,6 +217,16 @@ public:
}
/**
+ * Gets the currently selected text.
+ *
+ * @param pMimeType determines the return format, for example text/plain;charset=utf-8.
+ */
+ inline char* getTextSelection(const char* pMimeType)
+ {
+ return mpDoc->pClass->getTextSelection(mpDoc, pMimeType);
+ }
+
+ /**
* Adjusts the graphic selection.
*
* @param nType @see LibreOfficeKitSetGraphicSelectionType
diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
index 5cac9b6..7de3c32 100644
--- a/include/vcl/ITiledRenderable.hxx
+++ b/include/vcl/ITiledRenderable.hxx
@@ -122,6 +122,13 @@ public:
virtual void setTextSelection(int nType, int nX, int nY) = 0;
/**
+ * Gets the text selection.
+ *
+ * @see lok::Document::getTextSelection().
+ */
+ virtual OString getTextSelection(const char* /*pMimeType*/) { return OString(); }
+
+ /**
* Adjusts the graphic selection.
*
* @see lok::Document::setGraphicSelection().
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index 90e7f02..a90272a 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -417,6 +417,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 vcl::ITiledRenderable::resetSelection().
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index b2cdfac..4e96b6c 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -133,6 +133,7 @@
#include <view.hxx>
#include <srcview.hxx>
#include <edtwin.hxx>
+#include <swdtflvr.hxx>
#include <svtools/langtab.hxx>
#include <map>
@@ -3255,6 +3256,47 @@ void SwXTextDocument::setTextSelection(int nType, int nX, int nY)
}
}
+OString SwXTextDocument::getTextSelection(const char* pMimeType)
+{
+ SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+ uno::Reference<datatransfer::XTransferable> xTransferable(new SwTransferable(*pWrtShell));
+
+ // Take care of UTF-8 text here.
+ OString aMimeType(pMimeType);
+ 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 SwXTextDocument::setGraphicSelection(int nType, int nX, int nY)
{
SolarMutexGuard aGuard;
commit 161e39a6d2eb7038e0d7a40b13f5e290680be6f8
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Wed Jun 17 16:17:24 2015 +0200
sw tiled rendering: fix always empty copy&paste format list
Change-Id: I0c6390b54d0e9bb1cad7c30ff24ddb109d88e03b
(cherry picked from commit c4e5a14b1c8d2d85476791c519ac7df8b13f02df)
diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx
index 765ab0f..1d20eb2 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -126,6 +126,7 @@
#include <vcl/GraphicNativeTransform.hxx>
#include <vcl/GraphicNativeMetadata.hxx>
+#include <comphelper/lok.hxx>
#include <boost/scoped_array.hpp>
#include <boost/scoped_ptr.hpp>
@@ -305,7 +306,7 @@ void SwTransferable::AddSupportedFormats()
{
// only need if we are the current XSelection Object
SwModule *pMod = SW_MOD();
- if( this == pMod->pXSelection )
+ if( this == pMod->pXSelection || comphelper::LibreOfficeKit::isActive())
{
SetDataForDragAndDrop( Point( 0,0) );
}
More information about the Libreoffice-commits
mailing list