diff options
author | Eike Rathke <erack@redhat.com> | 2015-12-17 15:12:06 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2015-12-17 15:14:43 +0100 |
commit | 4eea9f214682008052424479a4b1f8cf90a79132 (patch) | |
tree | dc22d6d9e765da9072cb60ed01f8a9b9ec4b8064 | |
parent | db1e34aecd4290623a74b9bbeb602e072b1a49ec (diff) |
handle varargs with first required and subsequent optional, tdf#71459 related
Change-Id: I56c66f516ba2a2e12cab4848c8c352315f27b3bb
-rw-r--r-- | formula/source/ui/dlg/FormulaHelper.cxx | 1 | ||||
-rw-r--r-- | formula/source/ui/dlg/parawin.cxx | 20 | ||||
-rw-r--r-- | include/formula/IFunctionDescription.hxx | 1 | ||||
-rw-r--r-- | reportdesign/source/ui/inc/FunctionHelper.hxx | 1 | ||||
-rw-r--r-- | reportdesign/source/ui/misc/FunctionHelper.cxx | 18 | ||||
-rw-r--r-- | sc/inc/funcdesc.hxx | 10 | ||||
-rw-r--r-- | sc/source/core/data/funcdesc.cxx | 56 | ||||
-rw-r--r-- | sc/source/ui/src/scfuncs.src | 14 |
8 files changed, 97 insertions, 24 deletions
diff --git a/formula/source/ui/dlg/FormulaHelper.cxx b/formula/source/ui/dlg/FormulaHelper.cxx index 1e296f710709..b2ff0c4eb90a 100644 --- a/formula/source/ui/dlg/FormulaHelper.cxx +++ b/formula/source/ui/dlg/FormulaHelper.cxx @@ -45,6 +45,7 @@ namespace formula virtual OUString getSignature() const override { return OUString(); } virtual OString getHelpId() const override { return ""; } virtual sal_uInt32 getParameterCount() const override { return 0; } + virtual sal_uInt32 getVarArgsStart() const override { return 0; } virtual OUString getParameterName(sal_uInt32 ) const override { return OUString(); } virtual OUString getParameterDescription(sal_uInt32 ) const override { return OUString(); } virtual bool isParameterOptional(sal_uInt32 ) const override { return false; } diff --git a/formula/source/ui/dlg/parawin.cxx b/formula/source/ui/dlg/parawin.cxx index e32d257fdd8c..ee094724321b 100644 --- a/formula/source/ui/dlg/parawin.cxx +++ b/formula/source/ui/dlg/parawin.cxx @@ -136,8 +136,9 @@ void ParaWin::UpdateArgDesc( sal_uInt16 nArg ) aVisibleArgMapping[nPos] : aVisibleArgMapping.back()); aArgDesc = pFuncDesc->getParameterDescription(nRealArg); aArgName = pFuncDesc->getParameterName(nRealArg); - if ( nArg >= nFix ) - aArgName += OUString::number( nArg-nFix+1 ); + sal_uInt16 nVarArgsStart = pFuncDesc->getVarArgsStart(); + if ( nArg >= nVarArgsStart ) + aArgName += OUString::number( nArg-nVarArgsStart+1 ); aArgName += " "; aArgName += (nArg > nFix || pFuncDesc->isParameterOptional(nRealArg)) ? m_sOptional : m_sRequired ; @@ -154,8 +155,9 @@ void ParaWin::UpdateArgDesc( sal_uInt16 nArg ) aVisibleArgMapping[nPos] : aVisibleArgMapping.back()); aArgDesc = pFuncDesc->getParameterDescription(nRealArg); aArgName = pFuncDesc->getParameterName(nRealArg); - if ( nArg >= nFix ) - aArgName += OUString::number( (nArg-nFix)/2 + 1 ); + sal_uInt16 nVarArgsStart = pFuncDesc->getVarArgsStart(); + if ( nArg >= nVarArgsStart ) + aArgName += OUString::number( (nArg-nVarArgsStart)/2 + 1 ); aArgName += " "; aArgName += (nArg > (nFix+1) || pFuncDesc->isParameterOptional(nRealArg)) ? m_sOptional : m_sRequired ; @@ -188,10 +190,11 @@ void ParaWin::UpdateArgInput( sal_uInt16 nOffset, sal_uInt16 i ) SetArgNameFont( i, (nArg > nFix || pFuncDesc->isParameterOptional(nRealArg)) ? aFntLight : aFntBold ); - if ( nArg >= nFix ) + sal_uInt16 nVarArgsStart = pFuncDesc->getVarArgsStart(); + if ( nArg >= nVarArgsStart ) { OUString aArgName( pFuncDesc->getParameterName(nRealArg) ); - aArgName += OUString::number(nArg-nFix+1); + aArgName += OUString::number(nArg-nVarArgsStart+1); SetArgName( i, aArgName ); } else @@ -210,10 +213,11 @@ void ParaWin::UpdateArgInput( sal_uInt16 nOffset, sal_uInt16 i ) SetArgNameFont( i, (nArg > (nFix+1) || pFuncDesc->isParameterOptional(nRealArg)) ? aFntLight : aFntBold ); - if ( nArg >= nFix ) + sal_uInt16 nVarArgsStart = pFuncDesc->getVarArgsStart(); + if ( nArg >= nVarArgsStart ) { OUString aArgName( pFuncDesc->getParameterName(nRealArg) ); - aArgName += OUString::number( (nArg-nFix)/2 + 1 ); + aArgName += OUString::number( (nArg-nVarArgsStart)/2 + 1 ); SetArgName( i, aArgName ); } else diff --git a/include/formula/IFunctionDescription.hxx b/include/formula/IFunctionDescription.hxx index 0d93429fd867..1c7ccb96753f 100644 --- a/include/formula/IFunctionDescription.hxx +++ b/include/formula/IFunctionDescription.hxx @@ -91,6 +91,7 @@ namespace formula // parameter virtual sal_uInt32 getParameterCount() const = 0; + virtual sal_uInt32 getVarArgsStart() const = 0; virtual OUString getParameterName(sal_uInt32 _nPos) const = 0; virtual OUString getParameterDescription(sal_uInt32 _nPos) const = 0; virtual bool isParameterOptional(sal_uInt32 _nPos) const = 0; diff --git a/reportdesign/source/ui/inc/FunctionHelper.hxx b/reportdesign/source/ui/inc/FunctionHelper.hxx index 73142dd8f48f..2302d757779b 100644 --- a/reportdesign/source/ui/inc/FunctionHelper.hxx +++ b/reportdesign/source/ui/inc/FunctionHelper.hxx @@ -72,6 +72,7 @@ public: virtual OUString getSignature() const override ; virtual OString getHelpId() const override ; virtual sal_uInt32 getParameterCount() const override ; + virtual sal_uInt32 getVarArgsStart() const override; virtual OUString getParameterName(sal_uInt32 _nPos) const override ; virtual OUString getParameterDescription(sal_uInt32 _nPos) const override ; virtual bool isParameterOptional(sal_uInt32 _nPos) const override ; diff --git a/reportdesign/source/ui/misc/FunctionHelper.cxx b/reportdesign/source/ui/misc/FunctionHelper.cxx index d14ee0aa43ba..a92fc499928c 100644 --- a/reportdesign/source/ui/misc/FunctionHelper.cxx +++ b/reportdesign/source/ui/misc/FunctionHelper.cxx @@ -198,6 +198,24 @@ sal_uInt32 FunctionDescription::getParameterCount() const return m_aParameter.getLength(); } +sal_uInt32 FunctionDescription::getVarArgsStart() const +{ + /* XXX there are no variable number of arguments, are there? Nevertheless + * consider the varargs handling of the Function Wizard and return a value + * within the bounds of parameters. */ + // Don't use defines/constants that could change in future, parameter count + // could be part of an implicit stable API. + // offapi/com/sun/star/report/meta/XFunctionDescription.idl doesn't tell. + const sal_uInt32 nVarArgs = 30; // ugly hard coded VAR_ARGS of formula::ParaWin + const sal_uInt32 nPairedVarArgs = 60; // ugly hard coded PAIRED_VAR_ARGS of formula::ParaWin + sal_uInt32 nLen = m_aParameter.getLength(); + if (nLen >= nPairedVarArgs) + nLen -= nPairedVarArgs; + else if (nLen >= nVarArgs) + nLen -= nVarArgs; + return nLen ? nLen - 1 : 0; +} + OUString FunctionDescription::getParameterName(sal_uInt32 _nPos) const { if ( _nPos < static_cast<sal_uInt32>(m_aParameter.getLength()) ) diff --git a/sc/inc/funcdesc.hxx b/sc/inc/funcdesc.hxx index cda94fac37b3..1c2bccda5bc6 100644 --- a/sc/inc/funcdesc.hxx +++ b/sc/inc/funcdesc.hxx @@ -105,11 +105,18 @@ public: /** Returns number of arguments - @return help id of the function + @return number of arguments */ virtual sal_uInt32 getParameterCount() const override ; /** + Returns start of variable arguments + + @return start of variable arguments + */ + virtual sal_uInt32 getVarArgsStart() const override ; + + /** Returns description of parameter at given position @param _nPos @@ -205,6 +212,7 @@ public: sal_uInt16 nFIndex; /**< Unique function index */ sal_uInt16 nCategory; /**< Function category */ sal_uInt16 nArgCount; /**< All parameter count, suppressed and unsuppressed */ + sal_uInt16 nVarArgsStart; /**< Start of variable arguments, for numbering */ OString sHelpId; /**< HelpId of function */ bool bIncomplete :1; /**< Incomplete argument info (set for add-in info from configuration) */ bool bHasSuppressedArgs :1; /**< Whether there is any suppressed parameter. */ diff --git a/sc/source/core/data/funcdesc.cxx b/sc/source/core/data/funcdesc.cxx index b9c6e30b6f0a..729590b07694 100644 --- a/sc/source/core/data/funcdesc.cxx +++ b/sc/source/core/data/funcdesc.cxx @@ -67,6 +67,7 @@ ScFuncDesc::ScFuncDesc() : nFIndex (0), nCategory (0), nArgCount (0), + nVarArgsStart (0), bIncomplete (false), bHasSuppressedArgs(false) {} @@ -88,6 +89,7 @@ void ScFuncDesc::Clear() delete [] pDefArgFlags; } nArgCount = 0; + nVarArgsStart = 0; maDefArgNames.clear(); maDefArgDescs.clear(); pDefArgFlags = nullptr; @@ -140,8 +142,7 @@ OUString ScFuncDesc::GetParamList() const } else if ( nArgCount < PAIRED_VAR_ARGS) { - sal_uInt16 nFix = nArgCount - VAR_ARGS; - for ( sal_uInt16 nArg = 0; nArg < nFix; nArg++ ) + for ( sal_uInt16 nArg = 0; nArg < nVarArgsStart; nArg++ ) { if (!pDefArgFlags[nArg].bSuppress) { @@ -154,19 +155,18 @@ OUString ScFuncDesc::GetParamList() const * there were, we'd have to cope with it here and above for the fix * parameters. For now parameters are always added, so no special * treatment of a trailing "; " necessary. */ - aSig.append(maDefArgNames[nFix]); + aSig.append(maDefArgNames[nVarArgsStart]); aSig.append('1'); aSig.append(sep); aSig.append(' '); - aSig.append(maDefArgNames[nFix]); + aSig.append(maDefArgNames[nVarArgsStart]); aSig.append('2'); aSig.append(sep); aSig.append(" ... "); } else { - sal_uInt16 nFix = nArgCount - PAIRED_VAR_ARGS; - for ( sal_uInt16 nArg = 0; nArg < nFix; nArg++ ) + for ( sal_uInt16 nArg = 0; nArg < nVarArgsStart; nArg++ ) { if (!pDefArgFlags[nArg].bSuppress) { @@ -176,17 +176,17 @@ OUString ScFuncDesc::GetParamList() const } } - aSig.append(maDefArgNames[nFix]); + aSig.append(maDefArgNames[nVarArgsStart]); aSig.append('1'); aSig.append(sep); - aSig.append(maDefArgNames[nFix+1]); + aSig.append(maDefArgNames[nVarArgsStart+1]); aSig.append('1'); aSig.append(sep); aSig.append( " " ); - aSig.append(maDefArgNames[nFix]); + aSig.append(maDefArgNames[nVarArgsStart]); aSig.append('2'); aSig.append(sep); - aSig.append(maDefArgNames[nFix+1]); + aSig.append(maDefArgNames[nVarArgsStart+1]); aSig.append('2'); aSig.append(sep); aSig.append( " ... " ); @@ -359,6 +359,11 @@ sal_uInt32 ScFuncDesc::getParameterCount() const return nArgCount; } +sal_uInt32 ScFuncDesc::getVarArgsStart() const +{ + return nVarArgsStart; +} + OUString ScFuncDesc::getParameterName(sal_uInt32 _nPos) const { return maDefArgNames[_nPos]; @@ -799,12 +804,20 @@ ScFuncRes::ScFuncRes( ResId &aRes, ScFuncDesc* pDesc, bool & rbSuppressed ) pDesc->sHelpId = ReadByteStringRes(); pDesc->nArgCount = GetNum(); sal_uInt16 nArgs = pDesc->nArgCount; + sal_uInt16 nVarArgsSet = 0; if (nArgs >= PAIRED_VAR_ARGS) - nArgs -= PAIRED_VAR_ARGS - 2; + { + nVarArgsSet = 2; + nArgs -= PAIRED_VAR_ARGS - nVarArgsSet; + } else if (nArgs >= VAR_ARGS) - nArgs -= VAR_ARGS - 1; + { + nVarArgsSet = 1; + nArgs -= VAR_ARGS - nVarArgsSet; + } if (nArgs) { + pDesc->nVarArgsStart = nArgs - nVarArgsSet; pDesc->pDefArgFlags = new ScFuncDesc::ParameterFlags[nArgs]; for (sal_uInt16 i = 0; i < nArgs; ++i) { @@ -864,6 +877,25 @@ ScFuncRes::ScFuncRes( ResId &aRes, ScFuncDesc* pDesc, bool & rbSuppressed ) { pDesc->maDefArgNames[i] = SC_RESSTR(2*(i+1) ); pDesc->maDefArgDescs[i] = SC_RESSTR(2*(i+1)+1); + // If empty and variable number of arguments and last parameter and + // parameter is optional and the previous is not optional, repeat + // previous parameter name and description. + if ((pDesc->maDefArgNames[i].isEmpty() || pDesc->maDefArgDescs[i].isEmpty()) && + nVarArgsSet > 0 && i > nVarArgsSet && (i == nArgs-1 || i == nArgs-2) && + pDesc->pDefArgFlags[i].bOptional) + { + sal_uInt16 nPrev = i - nVarArgsSet; + if (!pDesc->pDefArgFlags[nPrev].bOptional) + { + if (pDesc->maDefArgNames[i].isEmpty()) + pDesc->maDefArgNames[i] = pDesc->maDefArgNames[nPrev]; + if (pDesc->maDefArgDescs[i].isEmpty()) + pDesc->maDefArgDescs[i] = pDesc->maDefArgDescs[nPrev]; + // This also means that variable arguments start one + // parameter set earlier. + pDesc->nVarArgsStart -= nVarArgsSet; + } + } } } diff --git a/sc/source/ui/src/scfuncs.src b/sc/source/ui/src/scfuncs.src index 7a8d30f521b2..e8f67e4de2f5 100644 --- a/sc/source/ui/src/scfuncs.src +++ b/sc/source/ui/src/scfuncs.src @@ -12392,7 +12392,7 @@ Resource RID_SC_FUNCTION_DESCRIPTIONS2 }; String 2 // Name of Parameter 1 { - Text [ en-US ] = "number" ; + Text [ en-US ] = "minuend" ; }; String 3 // Description of Parameter 1 { @@ -12400,11 +12400,19 @@ Resource RID_SC_FUNCTION_DESCRIPTIONS2 }; String 4 // Name of Parameter 2 { - Text [ en-US ] = "number " ; + Text [ en-US ] = "subtrahend " ; }; String 5 // Description of Parameter 2 { - Text [ en-US ] = "Number 2, number 3, ... are arguments subtracted from first number." ; + Text [ en-US ] = "Subtrahend 1, subtrahend 2, ... are numerical arguments subtracted from the minuend." ; + }; + String 6 // Name of Parameter 3, empty dummy to repeat Parameter 2, now optional + { + Text = "" ; + }; + String 7 // Description of Parameter 3, empty dummy to repeat Parameter 2, now optional + { + Text = "" ; }; }; }; |