[Libreoffice-commits] core.git: Branch 'private/mmeeks/copypaste' - desktop/source include/LibreOfficeKit

Michael Meeks (via logerrit) logerrit at kemper.freedesktop.org
Tue May 28 07:03:47 UTC 2019


Rebased ref, commits from common ancestor:
commit ff2560cbc078b851b8e1e8d776be2a8e77a24019
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Tue May 28 07:05:36 2019 +0100
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Tue May 28 08:02:56 2019 +0100

    lok: add getBinarySelection API - to go beyond text.
    
    Change-Id: I7d77d3113151856eeae36c9d98cd90fa51f4aae9

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 3d30f5d637ea..d3ddf174e9d2 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -778,6 +778,10 @@ static void doc_setTextSelection (LibreOfficeKitDocument* pThis,
 static char* doc_getTextSelection(LibreOfficeKitDocument* pThis,
                                   const char* pMimeType,
                                   char** pUsedMimeType);
+static char* doc_getBinarySelection(LibreOfficeKitDocument* pThis,
+                                    const char* pMimeType,
+                                    size_t *pBytesSent,
+                                    char** pUsedMimeType);
 static bool doc_paste(LibreOfficeKitDocument* pThis,
                       const char* pMimeType,
                       const char* pData,
@@ -874,6 +878,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone
         m_pDocumentClass->postUnoCommand = doc_postUnoCommand;
         m_pDocumentClass->setTextSelection = doc_setTextSelection;
         m_pDocumentClass->getTextSelection = doc_getTextSelection;
+        m_pDocumentClass->getBinarySelection = doc_getBinarySelection;
         m_pDocumentClass->paste = doc_paste;
         m_pDocumentClass->setGraphicSelection = doc_setGraphicSelection;
         m_pDocumentClass->resetSelection = doc_resetSelection;
@@ -3333,9 +3338,12 @@ static void doc_setTextSelection(LibreOfficeKitDocument* pThis, int nType, int n
     pDoc->setTextSelection(nType, nX, nY);
 }
 
-static char* doc_getTextSelection(LibreOfficeKitDocument* pThis, const char* pMimeType, char** pUsedMimeType)
+static char* doc_getBinarySelection(LibreOfficeKitDocument* pThis,
+                                    const char* pMimeType,
+                                    size_t *pBytesSent,
+                                    char** pUsedMimeType)
 {
-    comphelper::ProfileZone aZone("doc_getTextSelection");
+    comphelper::ProfileZone aZone("doc_getBinarySelection");
 
     SolarMutexGuard aGuard;
     SetLastExceptionMsg();
@@ -3347,13 +3355,22 @@ static char* doc_getTextSelection(LibreOfficeKitDocument* pThis, const char* pMi
         return nullptr;
     }
 
+    const char *pRealType = pMimeType;
+    if (pMimeType && !strncmp(pMimeType, "application/x-openoffice-embed-source-xml",
+                              sizeof ("application/x-openoffice-embed-source-xml") - 1))
+        pRealType = "application/x-openoffice-embed-source-xml;windows_formatname=\"Star Embed Source (XML)\"";
+
     OString aUsedMimeType;
-    OString aRet = pDoc->getTextSelection(pMimeType, aUsedMimeType);
+    OString aRet = pDoc->getTextSelection(pRealType, 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());
+    std::memcpy(pMemory, aRet.getStr(), aRet.getLength());
+    pMemory[aRet.getLength()] = '\0';
+
+    if (pBytesSent)
+        *pBytesSent = aRet.getLength();
 
     if (pUsedMimeType)
     {
@@ -3364,6 +3381,13 @@ static char* doc_getTextSelection(LibreOfficeKitDocument* pThis, const char* pMi
     return pMemory;
 }
 
+static char* doc_getTextSelection(LibreOfficeKitDocument* pThis,
+                                  const char* pMimeType,
+                                  char** pUsedMimeType)
+{
+    return doc_getBinarySelection(pThis, pMimeType, nullptr, pUsedMimeType);
+}
+
 static bool doc_paste(LibreOfficeKitDocument* pThis, const char* pMimeType, const char* pData, size_t nSize)
 {
     comphelper::ProfileZone aZone("doc_paste");
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 9fa134b56388..ab4de46a4521 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -377,6 +377,12 @@ struct _LibreOfficeKitDocumentClass
     void (*resizeWindow) (LibreOfficeKitDocument* pThis, unsigned nWindowId,
                           const int width, const int height);
 
+    /// @see lok::Document::getBinarySelection
+    char* (*getBinarySelection) (LibreOfficeKitDocument* pThis,
+                                 const char* pMimeType,
+                                 size_t *pBytesSent,
+                                 char** pUsedMimeType);
+
 #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
 };
 
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 235053fa0adb..e15a71486bd8 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -352,6 +352,18 @@ public:
     }
 
     /**
+     * Gets the currently selected content as a binary stream.
+     *
+     * @param pMimeType suggests the return format, for example text/plain;charset=utf-8.
+     * @param pBytesSent returns the size of data in the allocated return block
+     * @param pUsedMimeType output parameter to inform about the determined format (suggested one or plain text).
+     */
+    char* getBinarySelection(const char* pMimeType, size_t *pBytesSent, char** pUsedMimeType = NULL)
+    {
+        return mpDoc->pClass->getBinarySelection(mpDoc, pMimeType, pBytesSent, pUsedMimeType);
+    }
+
+    /**
      * Pastes content at the current cursor position.
      *
      * @param pMimeType format of pData, for example text/plain;charset=utf-8.


More information about the Libreoffice-commits mailing list