summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWinfried Donkers <winfrieddonkers@libreoffice.org>2014-02-25 08:14:55 +0100
committerEike Rathke <erack@redhat.com>2014-05-12 16:44:20 +0000
commit5b0b7553241bb5150b12bbf7625b4b0b36970272 (patch)
tree50a856bc65558183be49a04610b14532d2242354
parent6e225b41f1ab3e6cac395b0c0c6db73414658625 (diff)
fdo#75264 fix incorrect/missing function tips in Calc
Change-Id: Ibaed735ed1c8dd2dcaf69b82a4c089f1cb35b8cf Reviewed-on: https://gerrit.libreoffice.org/8218 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Eike Rathke <erack@redhat.com>
-rw-r--r--sc/source/ui/app/inputhdl.cxx76
-rw-r--r--sc/source/ui/inc/inputhdl.hxx2
2 files changed, 48 insertions, 30 deletions
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index fd513708a5ec..22a0e05db039 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -530,7 +530,8 @@ ScInputHandler::ScInputHandler()
pEditDefaults( NULL ),
pLastState( NULL ),
pDelayTimer( NULL ),
- pRangeFindList( NULL )
+ pRangeFindList( NULL ),
+ maFormulaChar()
{
// The InputHandler is constructed with the view, so SfxViewShell::Current
// doesn't have the right view yet. pActiveViewSh is updated in NotifyChange.
@@ -719,36 +720,20 @@ void ScInputHandler::GetFormulaData()
else
pFormulaDataPara = new ScTypedCaseStrSet;
- // MRU functions from the functions autopilot
- // Just like in ScPosWnd::FillFunctions (inputwin.cxx)
- const ScAppOptions& rOpt = SC_MOD()->GetAppOptions();
- sal_uInt16 nMRUCount = rOpt.GetLRUFuncListCount();
- const sal_uInt16* pMRUList = rOpt.GetLRUFuncList();
const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
sal_uLong nListCount = pFuncList->GetCount();
- if (pMRUList)
- {
- for (sal_uInt16 i=0; i<nMRUCount; i++)
- {
- sal_uInt16 nId = pMRUList[i];
- for (sal_uLong j=0; j<nListCount; j++)
- {
- const ScFuncDesc* pDesc = pFuncList->GetFunction( j );
- if ( pDesc->nFIndex == nId && pDesc->pFuncName )
- {
- OUString aEntry = *pDesc->pFuncName;
- aEntry += "()";
- pFormulaData->insert(ScTypedStrData(aEntry, 0.0, ScTypedStrData::Standard));
- break; // Stop searching
- }
- }
- }
- }
for(sal_uLong i=0;i<nListCount;i++)
{
const ScFuncDesc* pDesc = pFuncList->GetFunction( i );
if ( pDesc->pFuncName )
{
+ pFormulaData->insert(ScTypedStrData(*pDesc->pFuncName, 0.0, ScTypedStrData::Standard));
+ // fdo75264 fill maFormulaChar with all characters used in formula names
+ for ( sal_Int32 j = 0; j < pDesc->pFuncName->getLength(); j++ )
+ {
+ sal_Unicode c = pDesc->pFuncName->getStr()[ j ];
+ maFormulaChar.insert( c );
+ }
pDesc->initArgumentInfo();
OUString aEntry = pDesc->getSignature();
pFormulaDataPara->insert(ScTypedStrData(aEntry, 0.0, ScTypedStrData::Standard));
@@ -1025,6 +1010,35 @@ void ScInputHandler::ShowTipBelow( const OUString& rText )
}
}
+bool ScInputHandler::GetFuncName( OUString& aStart, OUString& aResult )
+{
+ if ( aStart.isEmpty() )
+ return false;
+
+ aStart = ScGlobal::pCharClass->uppercase( aStart );
+ sal_Int32 nPos = aStart.getLength() - 1;
+ sal_Unicode c = aStart[ nPos ];
+ // fdo75264 use maFormulaChar to check if characters are used in function names
+ ::std::set< sal_Unicode >::const_iterator p = maFormulaChar.find( c );
+ if ( p == maFormulaChar.end() )
+ return false; // last character is not part of any function name, quit
+
+ ::std::vector<sal_Unicode> aTemp;
+ while ( nPos >= 0 && p != maFormulaChar.end() )
+ {
+ aTemp.push_back( c );
+ c = aStart[ --nPos ];
+ p = maFormulaChar.find( c );
+ }
+
+ ::std::vector<sal_Unicode>::reverse_iterator rIt = aTemp.rbegin();
+ aResult = OUString( *rIt++ );
+ while ( rIt != aTemp.rend() )
+ aResult += OUString( *rIt++ );
+
+ return true;
+}
+
void ScInputHandler::UseFormulaData()
{
EditView* pActiveView = pTopView ? pTopView : pTableView;
@@ -1058,20 +1072,26 @@ void ScInputHandler::UseFormulaData()
sal_uInt16 nArgs;
bool bFound = false;
- OUString aText = pEngine->GetWord( 0, aSel.nEndPos-1 );
- if (!aText.isEmpty())
+ OUString aText;
+ if ( GetFuncName( aFormula, aText ) )
{
+ // function name is incomplete:
+ // show first matching function name as tip above cell
OUString aNew;
miAutoPosFormula = pFormulaData->end();
miAutoPosFormula = findText(*pFormulaData, miAutoPosFormula, aText, aNew, false);
if (miAutoPosFormula != pFormulaData->end())
{
+ aNew += "()";
ShowTip( aNew );
aAutoSearch = aText;
}
+ return;
}
FormulaHelper aHelper(ScGlobal::GetStarCalcFunctionMgr());
+ // function name is complete:
+ // show tip below the cell with function name and arguments of function
while( !bFound )
{
aFormula += ")";
@@ -1079,10 +1099,6 @@ void ScInputHandler::UseFormulaData()
if( nLeftParentPos == -1 )
break;
- // nLeftParentPos can be 0 if a parenthesis is inserted before the formula
- sal_Unicode c = ( nLeftParentPos > 0 ) ? aFormula[ nLeftParentPos-1 ] : 0;
- if( !(comphelper::string::isalphaAscii(c)) )
- continue;
nNextFStart = aHelper.GetFunctionStart( aFormula, nLeftParentPos, true);
if( aHelper.GetNextFunc( aFormula, false, nNextFStart, NULL, &ppFDesc, &aArgs ) )
{
diff --git a/sc/source/ui/inc/inputhdl.hxx b/sc/source/ui/inc/inputhdl.hxx
index 0d57a2ee64f3..2f0021846a8c 100644
--- a/sc/source/ui/inc/inputhdl.hxx
+++ b/sc/source/ui/inc/inputhdl.hxx
@@ -120,6 +120,7 @@ private:
static bool bAutoComplete; // from app options
static bool bOptLoaded;
+ ::std::set< sal_Unicode > maFormulaChar; //fdo 75264
private:
void UpdateActiveView();
@@ -156,6 +157,7 @@ private:
void AutoParAdded();
bool CursorAtClosingPar();
void SkipClosingPar();
+ bool GetFuncName( OUString& aStart, OUString& aResult ); // fdo75264
DECL_LINK( ModifyHdl, void* );
DECL_LINK( ShowHideTipVisibleParentListener, VclWindowEvent* );
DECL_LINK( ShowHideTipVisibleSecParentListener, VclWindowEvent* );