summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2020-05-07 15:47:49 +0200
committerAndras Timar <andras.timar@collabora.com>2020-05-08 10:46:09 +0200
commitf56ace63f3bae98dc0185043d85157d366fd9311 (patch)
tree56597a9be713febbeeac47cdfd9b33cbb71d6322
parentba552ebf17c44b6951f472cce0b2bb318fd8f952 (diff)
formula bar: Change completeFunction() to accept string instead of index.
The 'index' is unsafe, because the set it tries to index can change in the meantime. Instead, use the function name and search for it in the set, to get the recent index. Change-Id: Id2a021c32f421057c87b6f7f4fffcc1c98009acb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93666 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Andras Timar <andras.timar@collabora.com>
-rw-r--r--desktop/source/lib/init.cxx6
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.h2
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.hxx4
-rw-r--r--include/vcl/ITiledRenderable.hxx2
-rw-r--r--sc/inc/docuno.hxx2
-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.cxx6
8 files changed, 22 insertions, 18 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index e6c2d6630a58..fa04e95e2424 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1090,7 +1090,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);
+static void doc_completeFunction(LibreOfficeKitDocument* pThis, const char*);
} // extern "C"
namespace {
@@ -5411,7 +5411,7 @@ static void doc_resizeWindow(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKWin
pWindow->SetSizePixel(Size(nWidth, nHeight));
}
-static void doc_completeFunction(LibreOfficeKitDocument* pThis, int nIndex)
+static void doc_completeFunction(LibreOfficeKitDocument* pThis, const char* pFunctionName)
{
SolarMutexGuard aGuard;
SetLastExceptionMsg();
@@ -5423,7 +5423,7 @@ static void doc_completeFunction(LibreOfficeKitDocument* pThis, int nIndex)
return;
}
- pDoc->completeFunction(nIndex);
+ pDoc->completeFunction(OUString::fromUtf8(pFunctionName));
}
static char* lo_getError (LibreOfficeKit *pThis)
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 6203c11fb044..f95c8cb7858b 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -437,7 +437,7 @@ struct _LibreOfficeKitDocumentClass
int viewId);
/// @see lok::Document::completeFunction().
- void (*completeFunction) (LibreOfficeKitDocument* pThis, int nIndex);
+ void (*completeFunction) (LibreOfficeKitDocument* pThis, const char* pFunctionName);
/// @see lok::Document::setWindowTextSelection
void (*setWindowTextSelection) (LibreOfficeKitDocument* pThis,
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index b80a35209bc3..ae72a3258357 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -762,9 +762,9 @@ public:
*
* @param nIndex is the index of the selected function
*/
- void completeFunction(int nIndex)
+ void completeFunction(const char* pFunctionName)
{
- mpDoc->pClass->completeFunction(mpDoc, nIndex);
+ mpDoc->pClass->completeFunction(mpDoc, pFunctionName);
}
/**
diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
index a204713dd91b..b68157d32468 100644
--- a/include/vcl/ITiledRenderable.hxx
+++ b/include/vcl/ITiledRenderable.hxx
@@ -337,7 +337,7 @@ public:
virtual void moveSelectedParts(int /*nPosition*/, bool /*bDuplicate*/) {}
/// @see lok::Document::completeFunction().
- virtual void completeFunction(int /*nIndex*/)
+ virtual void completeFunction(const OUString& /*rFunctionName*/)
{
}
diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx
index 5a5cf33bd3e9..3229dd86d720 100644
--- a/sc/inc/docuno.hxx
+++ b/sc/inc/docuno.hxx
@@ -385,7 +385,7 @@ public:
OUString getPostItsPos() override;
/// @see vcl::ITiledRenderable::completeFunction().
- virtual void completeFunction(int nIndex) override;
+ virtual void completeFunction(const OUString& rFunctionName) override;
};
class ScDrawPagesObj : public cppu::WeakImplHelper<
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index 8f422831c6a6..68e2f780fc14 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -1642,7 +1642,7 @@ void ScInputHandler::PasteFunctionData()
pActiveView->ShowCursor();
}
-void ScInputHandler::LOKPasteFunctionData( sal_uInt32 nIndex )
+void ScInputHandler::LOKPasteFunctionData(const OUString& rFunctionName)
{
// in case we have no top view try to create it
if (!pTopView && pInputWin)
@@ -1675,12 +1675,16 @@ void ScInputHandler::LOKPasteFunctionData( sal_uInt32 nIndex )
InputReplaceSelection( aNewFormula );
}
- if (pFormulaData && nIndex < pFormulaData->size())
+ if (pFormulaData)
{
- auto aPos = pFormulaData->begin();
- std::advance(aPos, nIndex);
- miAutoPosFormula = aPos;
- PasteFunctionData();
+ OUString aNew;
+ ScTypedCaseStrSet::const_iterator aPos = findText(*pFormulaData, pFormulaData->begin(), rFunctionName, aNew, /* backward = */false);
+
+ if (aPos != pFormulaData->end())
+ {
+ miAutoPosFormula = aPos;
+ PasteFunctionData();
+ }
}
}
}
diff --git a/sc/source/ui/inc/inputhdl.hxx b/sc/source/ui/inc/inputhdl.hxx
index 70a1cd6e09d0..4d7bfca86cae 100644
--- a/sc/source/ui/inc/inputhdl.hxx
+++ b/sc/source/ui/inc/inputhdl.hxx
@@ -288,7 +288,7 @@ public:
long nX1, long nX2, long nY1, long nY2,
long nTab, const Color& rColor );
- void LOKPasteFunctionData( sal_uInt32 nIndex );
+ void LOKPasteFunctionData(const OUString& rFunctionName);
};
// ScInputHdlState
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 89fa194c4770..4145fd55769c 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -1083,13 +1083,13 @@ OUString ScModelObj::getPostItsPos()
return OUString::fromUtf8(aStream.str().c_str());
}
-void ScModelObj::completeFunction(int nIndex)
+void ScModelObj::completeFunction(const OUString& rFunctionName)
{
ScInputHandler* pHdl = SC_MOD()->GetInputHdl();
if (pHdl)
{
- assert(nIndex >= 0);
- pHdl->LOKPasteFunctionData(nIndex);
+ assert(!rFunctionName.isEmpty());
+ pHdl->LOKPasteFunctionData(rFunctionName);
}
}