summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Cecchetti <marco.cecchetti@collabora.com>2019-11-27 22:53:38 +0100
committerMiklos Vajna <vmiklos@collabora.com>2019-12-03 07:28:36 +0100
commite5367efbd15e1d97f8d4de232df1c325d8fff2b8 (patch)
treeff58530755848954e76b4b16eb30b8d261fc2c29
parent9bbdf2273394f7b9d619973cb8a73e7f846c334f (diff)
lok: formula bar: function completion
lok clients can request to complete a function name partially typed in the formula input box. Change-Id: I8771fd4d2a7f79c20138d9183162da23a92f2ba4 Reviewed-on: https://gerrit.libreoffice.org/83984 Reviewed-by: Marco Cecchetti <marco.cecchetti@collabora.com> Tested-by: Marco Cecchetti <marco.cecchetti@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/84258 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
-rw-r--r--desktop/qa/desktop_lib/test_desktop_lib.cxx3
-rw-r--r--desktop/source/lib/init.cxx17
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.h3
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.hxx10
-rw-r--r--include/vcl/ITiledRenderable.hxx5
-rw-r--r--sc/inc/docuno.hxx3
-rw-r--r--sc/source/ui/app/inputhdl.cxx16
-rw-r--r--sc/source/ui/inc/inputhdl.hxx2
-rw-r--r--sc/source/ui/unoobj/docuno.cxx10
9 files changed, 68 insertions, 1 deletions
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 08fa6a54ab62..1effbc2669b8 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -2751,10 +2751,11 @@ void DesktopLOKTest::testABI()
CPPUNIT_ASSERT_EQUAL(documentClassOffset(56), offsetof(struct _LibreOfficeKitDocumentClass, sendDialogEvent));
CPPUNIT_ASSERT_EQUAL(documentClassOffset(57), offsetof(struct _LibreOfficeKitDocumentClass, renderFontOrientation));
CPPUNIT_ASSERT_EQUAL(documentClassOffset(58), offsetof(struct _LibreOfficeKitDocumentClass, paintWindowForView));
+ CPPUNIT_ASSERT_EQUAL(documentClassOffset(59), offsetof(struct _LibreOfficeKitDocumentClass, completeFunction));
// Extending is fine, update this, and add new assert for the offsetof the
// new method
- CPPUNIT_ASSERT_EQUAL(documentClassOffset(59), sizeof(struct _LibreOfficeKitDocumentClass));
+ CPPUNIT_ASSERT_EQUAL(documentClassOffset(60), sizeof(struct _LibreOfficeKitDocumentClass));
}
CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 7fb08f0bec15..7ecc9fcdf78b 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -933,6 +933,7 @@ static size_t doc_renderShapeSelection(LibreOfficeKitDocument* pThis, char** pOu
static void doc_resizeWindow(LibreOfficeKitDocument* pThis, unsigned nLOKWindowId,
const int nWidth, const int nHeight);
+static void doc_completeFunction(LibreOfficeKitDocument* pThis, int nIndex);
} // extern "C"
namespace {
@@ -1044,6 +1045,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone
m_pDocumentClass->postWindowGestureEvent = doc_postWindowGestureEvent;
m_pDocumentClass->createViewWithOptions = doc_createViewWithOptions;
+ m_pDocumentClass->completeFunction = doc_completeFunction;
gDocumentClass = m_pDocumentClass;
}
@@ -5144,6 +5146,21 @@ static void doc_resizeWindow(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKWin
pWindow->SetSizePixel(Size(nWidth, nHeight));
}
+static void doc_completeFunction(LibreOfficeKitDocument* pThis, int nIndex)
+{
+ SolarMutexGuard aGuard;
+ SetLastExceptionMsg();
+
+ ITiledRenderable* pDoc = getTiledRenderable(pThis);
+ if (!pDoc)
+ {
+ SetLastExceptionMsg("Document doesn't support tiled rendering");
+ return;
+ }
+
+ pDoc->completeFunction(nIndex);
+}
+
static char* lo_getError (LibreOfficeKit *pThis)
{
comphelper::ProfileZone aZone("lo_getError");
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index a486886c15de..b4278625ccb0 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -436,6 +436,9 @@ struct _LibreOfficeKitDocumentClass
const double dpiscale,
int viewId);
+ /// @see lok::Document::completeFunction().
+ void (*completeFunction) (LibreOfficeKitDocument* pThis, int nIndex);
+
#endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
};
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 318bf943cca9..19f0b2663552 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -757,6 +757,16 @@ public:
mpDoc->pClass->removeTextContext(mpDoc, nWindowId, nBefore, nAfter);
}
+ /**
+ * Select the Calc function to be pasted into the formula input box
+ *
+ * @param nIndex is the index of the selected function
+ */
+ void completeFunction(int nIndex)
+ {
+ mpDoc->pClass->completeFunction(mpDoc, nIndex);
+ }
+
#endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
};
diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
index 905a3262b1a6..e5407e805e5c 100644
--- a/include/vcl/ITiledRenderable.hxx
+++ b/include/vcl/ITiledRenderable.hxx
@@ -288,6 +288,11 @@ public:
* bDuplicate: to copy (true), or to move (false).
*/
virtual void moveSelectedParts(int /*nPosition*/, bool /*bDuplicate*/) {}
+
+ /// @see lok::Document::completeFunction().
+ virtual void completeFunction(int /*nIndex*/)
+ {
+ }
};
} // namespace vcl
diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx
index e7cf7f1d3263..207940f731b8 100644
--- a/sc/inc/docuno.hxx
+++ b/sc/inc/docuno.hxx
@@ -386,6 +386,9 @@ public:
/// @see vcl::ITiledRenderable::getPostItsPos().
OUString getPostItsPos() override;
+
+ /// @see vcl::ITiledRenderable::completeFunction().
+ virtual void completeFunction(int nIndex) override;
};
class ScDrawPagesObj final : public cppu::WeakImplHelper<
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index 2d03cdecb5df..e8c8ebd0c669 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -17,6 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <iterator>
#include <memory>
#include <string_view>
@@ -1574,6 +1575,21 @@ void ScInputHandler::PasteFunctionData()
pActiveView->ShowCursor();
}
+void ScInputHandler::LOKPasteFunctionData( sal_uInt32 nIndex )
+{
+ if (pFormulaData && miAutoPosFormula != pFormulaData->end() && nIndex < pFormulaData->size())
+ {
+ auto aPos = pFormulaData->begin();
+ sal_uInt32 nCurIndex = std::distance(aPos, miAutoPosFormula);
+ nIndex += nCurIndex;
+ if (nIndex >= pFormulaData->size())
+ nIndex -= pFormulaData->size();
+ std::advance(aPos, nIndex);
+ miAutoPosFormula = aPos;
+ PasteFunctionData();
+ }
+}
+
// Calculate selection and display as tip help
static OUString lcl_Calculate( const OUString& rFormula, ScDocument* pDoc, const ScAddress &rPos )
{
diff --git a/sc/source/ui/inc/inputhdl.hxx b/sc/source/ui/inc/inputhdl.hxx
index 7180ab6efac2..c6d681e70e05 100644
--- a/sc/source/ui/inc/inputhdl.hxx
+++ b/sc/source/ui/inc/inputhdl.hxx
@@ -287,6 +287,8 @@ public:
static ReferenceMark GetReferenceMark( ScViewData& rViewData, ScDocShell* pDocSh,
long nX1, long nX2, long nY1, long nY2,
long nTab, const Color& rColor );
+
+ void LOKPasteFunctionData( sal_uInt32 nIndex );
};
// ScInputHdlState
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index ccfc91071769..aec2102f2d63 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -1081,6 +1081,16 @@ OUString ScModelObj::getPostItsPos()
return OUString::fromUtf8(aStream.str().c_str());
}
+void ScModelObj::completeFunction(int nIndex)
+{
+ ScInputHandler* pHdl = SC_MOD()->GetInputHdl();
+ if (pHdl)
+ {
+ assert(nIndex >= 0);
+ pHdl->LOKPasteFunctionData(nIndex);
+ }
+}
+
void ScModelObj::initializeForTiledRendering(const css::uno::Sequence<css::beans::PropertyValue>& /*rArguments*/)
{
SolarMutexGuard aGuard;