From e4842a4c520c68813f0567d34ad321de11c4f1c3 Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Thu, 19 May 2022 09:15:46 +0200 Subject: lok: add more efficient getSelectionType() replacement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The getSelectionType() function usually needs to be followed by a call to getTextSelection(), which means having them as two functions leads to duplicating to a number of calls, some of which may be somewhat expensive (pDoc->getSelection() e.g. for Calc builds another ScDocument for the selection, and then getFromTransferrable() converts that to the given format). Change-Id: Ib0a8844701d80eaaff4834dcd3633c09d6b921b1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134603 Tested-by: Jenkins Reviewed-by: Luboš Luňák --- include/LibreOfficeKit/LibreOfficeKit.h | 7 +++++++ include/LibreOfficeKit/LibreOfficeKit.hxx | 27 +++++++++++++++++++++++++++ include/LibreOfficeKit/LibreOfficeKitEnums.h | 2 +- 3 files changed, 35 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h index 6ebf81aacaa4..aff71dcc1f5d 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -472,6 +472,13 @@ struct _LibreOfficeKitDocumentClass /// @see lok::Document::sendContentControlEvent(). void (*sendContentControlEvent)(LibreOfficeKitDocument* pThis, const char* pArguments); + /// @see lok::Document::getSelectionTypeAndText + /// @since LibreOffice 7.4 + int (*getSelectionTypeAndText) (LibreOfficeKitDocument* pThis, + const char* pMimeType, + char** pText, + 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 827856c3ebeb..993654c88345 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -10,6 +10,7 @@ #pragma once #include +#include #include /* @@ -363,6 +364,8 @@ public: /** * Gets the type of the selected content. * + * In most cases it is more efficient to use getSelectionTypeAndText(). + * * @return an element of the LibreOfficeKitSelectionType enum. */ int getSelectionType() @@ -370,6 +373,30 @@ public: return mpDoc->pClass->getSelectionType(mpDoc); } + /** + * Gets the type of the selected content and possibly its text. + * + * This function is a more efficient combination of getSelectionType() and getTextSelection(). + * It returns the same as getSelectionType(), and additionally if the return value is + * LOK_SELTYPE_TEXT then it also returns the same as getTextSelection(), otherwise + * pText and pUsedMimeType are unchanged. + * + * @param pMimeType suggests the return format, for example text/plain;charset=utf-8. + * @param pText the currently selected text + * @param pUsedMimeType output parameter to inform about the determined format (suggested one or plain text). + * @return an element of the LibreOfficeKitSelectionType enum. + * @since LibreOffice 7.4 + */ + int getSelectionTypeAndText(const char* pMimeType, char** pText, char** pUsedMimeType = NULL) + { + if (LIBREOFFICEKIT_DOCUMENT_HAS(mpDoc, getSelectionTypeAndText)) + return mpDoc->pClass->getSelectionTypeAndText(mpDoc, pMimeType, pText, pUsedMimeType); + int type = mpDoc->pClass->getSelectionType(mpDoc); + if(type == LOK_SELTYPE_TEXT && pText) + *pText = mpDoc->pClass->getTextSelection(mpDoc, pMimeType, pUsedMimeType); + return type; + } + /** * Gets the content on the clipboard for the current view as a series of binary streams. * diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h index 339b0183f153..63ddec957be0 100644 --- a/include/LibreOfficeKit/LibreOfficeKitEnums.h +++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h @@ -53,7 +53,7 @@ typedef enum { LOK_SELTYPE_NONE, LOK_SELTYPE_TEXT, - LOK_SELTYPE_LARGE_TEXT, + LOK_SELTYPE_LARGE_TEXT, // unused (same as LOK_SELTYPE_COMPLEX) LOK_SELTYPE_COMPLEX } LibreOfficeKitSelectionType; -- cgit