summaryrefslogtreecommitdiff
path: root/include/LibreOfficeKit/LibreOfficeKit.hxx
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2022-05-19 09:15:46 +0200
committerLuboš Luňák <l.lunak@collabora.com>2022-05-31 17:03:02 +0200
commite4842a4c520c68813f0567d34ad321de11c4f1c3 (patch)
treee7754f576ee9fc75c55ade0516f3116fb546ff7a /include/LibreOfficeKit/LibreOfficeKit.hxx
parentf90239263fcabec30f04098e17dc1be9f9a928d1 (diff)
lok: add more efficient getSelectionType() replacement
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 <l.lunak@collabora.com>
Diffstat (limited to 'include/LibreOfficeKit/LibreOfficeKit.hxx')
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.hxx27
1 files changed, 27 insertions, 0 deletions
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 <LibreOfficeKit/LibreOfficeKit.h>
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <LibreOfficeKit/LibreOfficeKitInit.h>
/*
@@ -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()
@@ -371,6 +374,30 @@ public:
}
/**
+ * 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.
*
* NB. returns a complete set of possible selection types if nullptr is passed for pMimeTypes.