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/dochdl/swdtflvr.cxx | 3 +- sw/source/uibase/uno/unotxdoc.cxx | 42 ++++++++++++++++++++++++++++++ 7 files changed, 86 insertions(+), 1 deletion(-)
New commits: commit 1a1d15b422bc9bb787f939c28e520ca23debe28b Author: Miklos Vajna <vmik...@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 4f6eea0e6f85a0b90843734aa6f288b8fa92d887 Author: Miklos Vajna <vmik...@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 70dbd74..8dc91dd1 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) ); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits