summaryrefslogtreecommitdiff
path: root/include
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:02:47 +0200
commitd236341c6aab90d7d4097d6ff535e1bbeb656f3a (patch)
tree0bb7dc50017e927ac6a1c041b1b67c670e705148 /include
parent7aeff80c565837cbcd46c649cefe11462cb6948e (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/+/134615 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Ashod Nakashian <ash@collabora.com>
Diffstat (limited to 'include')
-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 c578582d2726..aeb36690f9d4 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;