[Libreoffice-commits] core.git: desktop/source include/LibreOfficeKit include/vcl sw/inc sw/source
Miklos Vajna
vmiklos at collabora.co.uk
Wed Jun 17 09:22:15 PDT 2015
desktop/source/lib/init.cxx | 19 +++++++++++++
include/LibreOfficeKit/LibreOfficeKit.h | 4 ++
include/LibreOfficeKit/LibreOfficeKit.hxx | 10 +++++++
include/vcl/ITiledRenderable.hxx | 7 +++++
sw/inc/unotxdoc.hxx | 2 +
sw/source/uibase/uno/unotxdoc.cxx | 42 ++++++++++++++++++++++++++++++
6 files changed, 84 insertions(+)
New commits:
commit cfc4375158ee174e8dcb4df319b82c0bdd6f31cc
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
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 89e85af..23c52bc 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 0f7a446..78ec974 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 20718d2..268148e 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>
@@ -3253,6 +3254,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;
More information about the Libreoffice-commits
mailing list