summaryrefslogtreecommitdiff
path: root/include/LibreOfficeKit
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
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')
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.h7
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.hxx27
-rw-r--r--include/LibreOfficeKit/LibreOfficeKitEnums.h2
3 files changed, 35 insertions, 1 deletions
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 <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.
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;