[Libreoffice-commits] core.git: formula/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Tue Apr 14 11:37:35 UTC 2020


 formula/source/core/api/FormulaCompiler.cxx |  102 +++---
 formula/source/ui/dlg/formula.cxx           |  450 ++++++++++++++--------------
 formula/source/ui/dlg/parawin.cxx           |  114 +++----
 formula/source/ui/dlg/structpg.cxx          |   24 -
 4 files changed, 345 insertions(+), 345 deletions(-)

New commits:
commit bf207a0ed79c4b606ad1a6e2d5ca0fb00a6feeb8
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue Apr 14 12:08:06 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Apr 14 13:37:01 2020 +0200

    loplugin:flatten in formula
    
    Change-Id: I90054df6949cf966b9edc706b2e29c2a57553be9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92161
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx
index fedd6b36fcf4..e8c92c990509 100644
--- a/formula/source/core/api/FormulaCompiler.cxx
+++ b/formula/source/core/api/FormulaCompiler.cxx
@@ -932,19 +932,19 @@ void FormulaCompiler::InitSymbolsOOXML() const
 void FormulaCompiler::loadSymbols(const std::pair<const char*, int>* pSymbols, FormulaGrammar::Grammar eGrammar,
         NonConstOpCodeMapPtr& rxMap, SeparatorType eSepType) const
 {
-    if ( !rxMap.get() )
-    {
-        // not Core
-        rxMap = std::make_shared<OpCodeMap>( SC_OPCODE_LAST_OPCODE_ID + 1, eGrammar != FormulaGrammar::GRAM_ODFF, eGrammar );
-        OpCodeList aOpCodeList(false, pSymbols, rxMap, eSepType);
+    if ( rxMap.get() )
+        return;
 
-        fillFromAddInMap( rxMap, eGrammar);
-        // Fill from collection for AddIns not already present.
-        if ( FormulaGrammar::GRAM_ENGLISH != eGrammar )
-            fillFromAddInCollectionUpperName( rxMap);
-        else
-            fillFromAddInCollectionEnglishName( rxMap);
-    }
+    // not Core
+    rxMap = std::make_shared<OpCodeMap>( SC_OPCODE_LAST_OPCODE_ID + 1, eGrammar != FormulaGrammar::GRAM_ODFF, eGrammar );
+    OpCodeList aOpCodeList(false, pSymbols, rxMap, eSepType);
+
+    fillFromAddInMap( rxMap, eGrammar);
+    // Fill from collection for AddIns not already present.
+    if ( FormulaGrammar::GRAM_ENGLISH != eGrammar )
+        fillFromAddInCollectionUpperName( rxMap);
+    else
+        fillFromAddInCollectionEnglishName( rxMap);
 }
 
 void FormulaCompiler::fillFromAddInCollectionUpperName( const NonConstOpCodeMapPtr& /*xMap */) const
@@ -2142,26 +2142,26 @@ bool FormulaCompiler::CompileTokenArray()
 
 void FormulaCompiler::PopTokenArray()
 {
-    if( pStack )
-    {
-        FormulaArrayStack* p = pStack;
-        pStack = p->pNext;
-        // obtain special RecalcMode from SharedFormula
-        if ( pArr->IsRecalcModeAlways() )
-            p->pArr->SetExclusiveRecalcModeAlways();
-        else if ( !pArr->IsRecalcModeNormal() && p->pArr->IsRecalcModeNormal() )
-            p->pArr->SetMaskedRecalcMode( pArr->GetRecalcMode() );
-        p->pArr->SetCombinedBitsRecalcMode( pArr->GetRecalcMode() );
-        if ( pArr->IsHyperLink() )  // fdo 87534
-            p->pArr->SetHyperLink( true );
-        if( p->bTemp )
-            delete pArr;
-        pArr = p->pArr;
-        maArrIterator = FormulaTokenArrayPlainIterator(*pArr);
-        maArrIterator.Jump(p->nIndex);
-        mpLastToken = p->mpLastToken;
-        delete p;
-    }
+    if( !pStack )
+        return;
+
+    FormulaArrayStack* p = pStack;
+    pStack = p->pNext;
+    // obtain special RecalcMode from SharedFormula
+    if ( pArr->IsRecalcModeAlways() )
+        p->pArr->SetExclusiveRecalcModeAlways();
+    else if ( !pArr->IsRecalcModeNormal() && p->pArr->IsRecalcModeNormal() )
+        p->pArr->SetMaskedRecalcMode( pArr->GetRecalcMode() );
+    p->pArr->SetCombinedBitsRecalcMode( pArr->GetRecalcMode() );
+    if ( pArr->IsHyperLink() )  // fdo 87534
+        p->pArr->SetHyperLink( true );
+    if( p->bTemp )
+        delete pArr;
+    pArr = p->pArr;
+    maArrIterator = FormulaTokenArrayPlainIterator(*pArr);
+    maArrIterator.Jump(p->nIndex);
+    mpLastToken = p->mpLastToken;
+    delete p;
 }
 
 void FormulaCompiler::CreateStringFromTokenArray( OUString& rFormula )
@@ -2738,28 +2738,28 @@ void FormulaCompiler::ForceArrayOperator( FormulaTokenRef const & rCurr )
         return;
     }
 
-    if (nCurrentFactorParam > 0)
+    if (nCurrentFactorParam <= 0)
+        return;
+
+    // Actual current parameter's class.
+    const formula::ParamClass eType = GetForceArrayParameter(
+            pCurrentFactorToken.get(), static_cast<sal_uInt16>(nCurrentFactorParam - 1));
+    if (eType == ParamClass::ForceArray)
+        rCurr->SetInForceArray( eType);
+    else if (eType == ParamClass::ReferenceOrForceArray)
     {
-        // Actual current parameter's class.
-        const formula::ParamClass eType = GetForceArrayParameter(
-                pCurrentFactorToken.get(), static_cast<sal_uInt16>(nCurrentFactorParam - 1));
-        if (eType == ParamClass::ForceArray)
+        if (GetForceArrayParameter( rCurr.get(), SAL_MAX_UINT16) != ParamClass::Reference)
             rCurr->SetInForceArray( eType);
-        else if (eType == ParamClass::ReferenceOrForceArray)
-        {
-            if (GetForceArrayParameter( rCurr.get(), SAL_MAX_UINT16) != ParamClass::Reference)
-                rCurr->SetInForceArray( eType);
-            else
-                rCurr->SetInForceArray( formula::ParamClass::SuppressedReferenceOrForceArray);
-        }
-
-        // Propagate a ForceArrayReturn to caller if the called function
-        // returns one and the caller so far does not have a stronger array
-        // mode set.
-        if (pCurrentFactorToken->GetInForceArray() == ParamClass::Unknown
-                && GetForceArrayParameter( rCurr.get(), SAL_MAX_UINT16) == ParamClass::ForceArrayReturn)
-            pCurrentFactorToken->SetInForceArray( ParamClass::ForceArrayReturn);
+        else
+            rCurr->SetInForceArray( formula::ParamClass::SuppressedReferenceOrForceArray);
     }
+
+    // Propagate a ForceArrayReturn to caller if the called function
+    // returns one and the caller so far does not have a stronger array
+    // mode set.
+    if (pCurrentFactorToken->GetInForceArray() == ParamClass::Unknown
+            && GetForceArrayParameter( rCurr.get(), SAL_MAX_UINT16) == ParamClass::ForceArrayReturn)
+        pCurrentFactorToken->SetInForceArray( ParamClass::ForceArrayReturn);
 }
 
 void FormulaCompiler::CheckSetForceArrayParameter( FormulaTokenRef const & rCurr, sal_uInt8 nParam )
diff --git a/formula/source/ui/dlg/formula.cxx b/formula/source/ui/dlg/formula.cxx
index 2229377b3089..d84e4caea559 100644
--- a/formula/source/ui/dlg/formula.cxx
+++ b/formula/source/ui/dlg/formula.cxx
@@ -327,23 +327,23 @@ FormulaDlg_Impl::~FormulaDlg_Impl()
 
 void FormulaDlg_Impl::StoreFormEditData(FormEditData* pData)
 {
-    if (pData) // it won't be destroyed via Close
-    {
-        int nStartPos, nEndPos;
-        m_xMEdit->get_selection_bounds(nStartPos, nEndPos);
-        if (nStartPos > nEndPos)
-            std::swap(nStartPos, nEndPos);
+    if (!pData) // it won't be destroyed via Close
+        return;
+
+    int nStartPos, nEndPos;
+    m_xMEdit->get_selection_bounds(nStartPos, nEndPos);
+    if (nStartPos > nEndPos)
+        std::swap(nStartPos, nEndPos);
 
-        pData->SetFStart(nStartPos);
-        pData->SetSelection(Selection(nStartPos, nEndPos));
+    pData->SetFStart(nStartPos);
+    pData->SetSelection(Selection(nStartPos, nEndPos));
 
-        if (m_xTabCtrl->get_current_page_ident() == "function")
-            pData->SetMode( FormulaDlgMode::Formula );
-        else
-            pData->SetMode( FormulaDlgMode::Edit );
-        pData->SetUndoStr(m_xMEdit->get_text());
-        pData->SetMatrixFlag(m_xBtnMatrix->get_active());
-    }
+    if (m_xTabCtrl->get_current_page_ident() == "function")
+        pData->SetMode( FormulaDlgMode::Formula );
+    else
+        pData->SetMode( FormulaDlgMode::Edit );
+    pData->SetUndoStr(m_xMEdit->get_text());
+    pData->SetMatrixFlag(m_xBtnMatrix->get_active());
 }
 
 void FormulaDlg_Impl::InitFormulaOpCodeMapper()
@@ -557,187 +557,187 @@ void FormulaDlg_Impl::CalcStruct( const OUString& rStrExp, bool bForceRecalcStru
 {
     sal_Int32 nLength = rStrExp.getLength();
 
-    if ( !rStrExp.isEmpty() && (bForceRecalcStruct || m_aOldFormula != rStrExp) && m_bStructUpdate)
-    {
-        m_xStructPage->ClearStruct();
+    if ( !(!rStrExp.isEmpty() && (bForceRecalcStruct || m_aOldFormula != rStrExp) && m_bStructUpdate))
+        return;
 
-        OUString aString = rStrExp;
-        if (rStrExp[nLength-1] == '(')
-        {
-            aString = aString.copy( 0, nLength-1);
-        }
+    m_xStructPage->ClearStruct();
+
+    OUString aString = rStrExp;
+    if (rStrExp[nLength-1] == '(')
+    {
+        aString = aString.copy( 0, nLength-1);
+    }
 
-        aString = aString.replaceAll( "\n", "");
-        OUString aStrResult;
+    aString = aString.replaceAll( "\n", "");
+    OUString aStrResult;
 
-        if ( CalcValue( aString, aStrResult ) )
-            m_xWndFormResult->set_text(aStrResult);
+    if ( CalcValue( aString, aStrResult ) )
+        m_xWndFormResult->set_text(aStrResult);
 
-        UpdateTokenArray(aString);
-        fillTree(m_xStructPage.get());
+    UpdateTokenArray(aString);
+    fillTree(m_xStructPage.get());
 
-        m_aOldFormula = rStrExp;
-        if (rStrExp[nLength-1] == '(')
-            UpdateTokenArray(rStrExp);
-    }
+    m_aOldFormula = rStrExp;
+    if (rStrExp[nLength-1] == '(')
+        UpdateTokenArray(rStrExp);
 }
 
 void FormulaDlg_Impl::MakeTree(StructPage* _pTree, weld::TreeIter* pParent, const FormulaToken* pFuncToken,
                                const FormulaToken* _pToken, long Count)
 {
-    if ( _pToken != nullptr && Count > 0 )
+    if ( !(_pToken != nullptr && Count > 0) )
+        return;
+
+    long nParas = _pToken->GetParamCount();
+    OpCode eOp = _pToken->GetOpCode();
+
+    // #i101512# for output, the original token is needed
+    const FormulaToken* pOrigToken = (_pToken->GetType() == svFAP) ? _pToken->GetFAPOrigToken() : _pToken;
+    uno::Sequence<sheet::FormulaToken> aArgs(1);
+    ::std::map<const FormulaToken*, sheet::FormulaToken>::const_iterator itr = m_aTokenMap.find(pOrigToken);
+    if (itr == m_aTokenMap.end())
+        return;
+
+    aArgs[0] = itr->second;
+    try
     {
-        long nParas = _pToken->GetParamCount();
-        OpCode eOp = _pToken->GetOpCode();
-
-        // #i101512# for output, the original token is needed
-        const FormulaToken* pOrigToken = (_pToken->GetType() == svFAP) ? _pToken->GetFAPOrigToken() : _pToken;
-        uno::Sequence<sheet::FormulaToken> aArgs(1);
-        ::std::map<const FormulaToken*, sheet::FormulaToken>::const_iterator itr = m_aTokenMap.find(pOrigToken);
-        if (itr == m_aTokenMap.end())
-            return;
-
-        aArgs[0] = itr->second;
-        try
+        const table::CellAddress aRefPos(m_pHelper->getReferencePosition());
+        const OUString aResult = m_pHelper->getFormulaParser()->printFormula( aArgs, aRefPos);
+
+        if ( nParas > 0 || (nParas == 0 && _pToken->IsFunction()) )
         {
-            const table::CellAddress aRefPos(m_pHelper->getReferencePosition());
-            const OUString aResult = m_pHelper->getFormulaParser()->printFormula( aArgs, aRefPos);
+            std::unique_ptr<weld::TreeIter> xEntry;
+            weld::TreeIter* pEntry;
 
-            if ( nParas > 0 || (nParas == 0 && _pToken->IsFunction()) )
-            {
-                std::unique_ptr<weld::TreeIter> xEntry;
-                weld::TreeIter* pEntry;
+            bool bCalcSubformula = false;
+            OUString aTest = _pTree->GetEntryText(pParent);
 
-                bool bCalcSubformula = false;
-                OUString aTest = _pTree->GetEntryText(pParent);
+            if (aTest == aResult && (eOp == ocAdd || eOp == ocMul || eOp == ocAmpersand))
+            {
+                pEntry = pParent;
+            }
+            else
+            {
+                xEntry = m_xStructPage->GetTlbStruct().make_iterator();
 
-                if (aTest == aResult && (eOp == ocAdd || eOp == ocMul || eOp == ocAmpersand))
+                if (eOp == ocBad)
+                {
+                    _pTree->InsertEntry(aResult, pParent, STRUCT_ERROR, 0, _pToken, *xEntry);
+                }
+                else if (!((SC_OPCODE_START_BIN_OP <= eOp && eOp < SC_OPCODE_STOP_BIN_OP) ||
+                            (SC_OPCODE_START_UN_OP <= eOp && eOp < SC_OPCODE_STOP_UN_OP)))
                 {
-                    pEntry = pParent;
+                    // Not a binary or unary operator.
+                    bCalcSubformula = true;
+                    _pTree->InsertEntry(aResult, pParent, STRUCT_FOLDER, 0, _pToken, *xEntry);
                 }
                 else
                 {
-                    xEntry = m_xStructPage->GetTlbStruct().make_iterator();
-
-                    if (eOp == ocBad)
-                    {
-                        _pTree->InsertEntry(aResult, pParent, STRUCT_ERROR, 0, _pToken, *xEntry);
-                    }
-                    else if (!((SC_OPCODE_START_BIN_OP <= eOp && eOp < SC_OPCODE_STOP_BIN_OP) ||
-                                (SC_OPCODE_START_UN_OP <= eOp && eOp < SC_OPCODE_STOP_UN_OP)))
-                    {
-                        // Not a binary or unary operator.
-                        bCalcSubformula = true;
-                        _pTree->InsertEntry(aResult, pParent, STRUCT_FOLDER, 0, _pToken, *xEntry);
-                    }
-                    else
-                    {
-                        /* TODO: question remains, why not sub calculate operators? */
-                        _pTree->InsertEntry(aResult, pParent, STRUCT_FOLDER, 0, _pToken, *xEntry);
-                    }
-
-                    pEntry = xEntry.get();
+                    /* TODO: question remains, why not sub calculate operators? */
+                    _pTree->InsertEntry(aResult, pParent, STRUCT_FOLDER, 0, _pToken, *xEntry);
                 }
 
-                MakeTree(_pTree, pEntry, _pToken, m_pTokenArrayIterator->PrevRPN(), nParas);
+                pEntry = xEntry.get();
+            }
 
-                if (bCalcSubformula)
-                {
-                    OUString aFormula;
+            MakeTree(_pTree, pEntry, _pToken, m_pTokenArrayIterator->PrevRPN(), nParas);
 
-                    if (!m_bMakingTree)
-                    {
-                        // gets the last subformula result
-                        m_bMakingTree = true;
-                        aFormula = GetPrevFuncExpression( true);
-                    }
-                    else
-                    {
-                        // gets subsequent subformula results (from the back)
-                        aFormula = GetPrevFuncExpression( false);
-                    }
+            if (bCalcSubformula)
+            {
+                OUString aFormula;
 
-                    OUString aStr;
-                    if (CalcValue( aFormula, aStr, _pToken->IsInForceArray()))
-                        m_xWndResult->set_text( aStr );
-                    aStr = m_xWndResult->get_text();
-                    m_xStructPage->GetTlbStruct().set_text(*pEntry, aResult + " = " + aStr);
+                if (!m_bMakingTree)
+                {
+                    // gets the last subformula result
+                    m_bMakingTree = true;
+                    aFormula = GetPrevFuncExpression( true);
+                }
+                else
+                {
+                    // gets subsequent subformula results (from the back)
+                    aFormula = GetPrevFuncExpression( false);
                 }
 
-                --Count;
-                m_pTokenArrayIterator->NextRPN();   /* TODO: what's this to be? ThisRPN()? */
-                MakeTree( _pTree, pParent, _pToken, m_pTokenArrayIterator->PrevRPN(), Count);
+                OUString aStr;
+                if (CalcValue( aFormula, aStr, _pToken->IsInForceArray()))
+                    m_xWndResult->set_text( aStr );
+                aStr = m_xWndResult->get_text();
+                m_xStructPage->GetTlbStruct().set_text(*pEntry, aResult + " = " + aStr);
             }
-            else
+
+            --Count;
+            m_pTokenArrayIterator->NextRPN();   /* TODO: what's this to be? ThisRPN()? */
+            MakeTree( _pTree, pParent, _pToken, m_pTokenArrayIterator->PrevRPN(), Count);
+        }
+        else
+        {
+            std::unique_ptr<weld::TreeIter> xEntry(m_xStructPage->GetTlbStruct().make_iterator());
+            if (eOp == ocBad)
             {
-                std::unique_ptr<weld::TreeIter> xEntry(m_xStructPage->GetTlbStruct().make_iterator());
-                if (eOp == ocBad)
-                {
-                    _pTree->InsertEntry( aResult, pParent, STRUCT_ERROR, 0, _pToken, *xEntry);
-                }
-                else if (eOp == ocPush)
+                _pTree->InsertEntry( aResult, pParent, STRUCT_ERROR, 0, _pToken, *xEntry);
+            }
+            else if (eOp == ocPush)
+            {
+                // Interpret range reference in matrix context to resolve
+                // as array elements. Depending on parameter classification
+                // a scalar value (non-array context) is calculated first.
+                OUString aUnforcedResult;
+                bool bForceMatrix = (!m_xBtnMatrix->get_active() &&
+                        (_pToken->GetType() == svDoubleRef || _pToken->GetType() == svExternalDoubleRef));
+                if (bForceMatrix && pFuncToken)
                 {
-                    // Interpret range reference in matrix context to resolve
-                    // as array elements. Depending on parameter classification
-                    // a scalar value (non-array context) is calculated first.
-                    OUString aUnforcedResult;
-                    bool bForceMatrix = (!m_xBtnMatrix->get_active() &&
-                            (_pToken->GetType() == svDoubleRef || _pToken->GetType() == svExternalDoubleRef));
-                    if (bForceMatrix && pFuncToken)
+                    formula::ParamClass eParamClass = ParamClass::Reference;
+                    if (pFuncToken->IsInForceArray())
+                        eParamClass = ParamClass::ForceArray;
+                    else
                     {
-                        formula::ParamClass eParamClass = ParamClass::Reference;
-                        if (pFuncToken->IsInForceArray())
-                            eParamClass = ParamClass::ForceArray;
-                        else
-                        {
-                            std::shared_ptr<FormulaCompiler> pCompiler = m_pHelper->getCompiler();
-                            if (pCompiler)
-                                eParamClass = pCompiler->GetForceArrayParameter( pFuncToken, Count - 1);
-                        }
-                        switch (eParamClass)
-                        {
-                            case ParamClass::Unknown:
-                            case ParamClass::Bounds:
-                            case ParamClass::Value:
-                                if (CalcValue( "=" + aResult, aUnforcedResult, false) && aUnforcedResult != aResult)
-                                    aUnforcedResult += "  ";
-                                else
-                                    aUnforcedResult.clear();
-                            break;
-                            case ParamClass::Reference:
-                            case ParamClass::ReferenceOrRefArray:
-                            case ParamClass::Array:
-                            case ParamClass::ForceArray:
-                            case ParamClass::ReferenceOrForceArray:
-                            case ParamClass::SuppressedReferenceOrForceArray:
-                            case ParamClass::ForceArrayReturn:
-                                ;   // nothing, only as array/matrix
-                            // no default to get compiler warning
-                        }
+                        std::shared_ptr<FormulaCompiler> pCompiler = m_pHelper->getCompiler();
+                        if (pCompiler)
+                            eParamClass = pCompiler->GetForceArrayParameter( pFuncToken, Count - 1);
                     }
-                    OUString aCellResult;
-                    if (CalcValue( "=" + aResult, aCellResult, bForceMatrix) && aCellResult != aResult)
+                    switch (eParamClass)
                     {
-                        // Cell is a formula, print subformula.
-                        // With scalar values prints "A1:A3 = 2 {1;2;3}"
-                        _pTree->InsertEntry( aResult + " = " + aUnforcedResult + aCellResult,
-                                pParent, STRUCT_END, 0, _pToken, *xEntry);
+                        case ParamClass::Unknown:
+                        case ParamClass::Bounds:
+                        case ParamClass::Value:
+                            if (CalcValue( "=" + aResult, aUnforcedResult, false) && aUnforcedResult != aResult)
+                                aUnforcedResult += "  ";
+                            else
+                                aUnforcedResult.clear();
+                        break;
+                        case ParamClass::Reference:
+                        case ParamClass::ReferenceOrRefArray:
+                        case ParamClass::Array:
+                        case ParamClass::ForceArray:
+                        case ParamClass::ReferenceOrForceArray:
+                        case ParamClass::SuppressedReferenceOrForceArray:
+                        case ParamClass::ForceArrayReturn:
+                            ;   // nothing, only as array/matrix
+                        // no default to get compiler warning
                     }
-                    else
-                        _pTree->InsertEntry(aResult, pParent, STRUCT_END, 0, _pToken, *xEntry);
                 }
-                else
+                OUString aCellResult;
+                if (CalcValue( "=" + aResult, aCellResult, bForceMatrix) && aCellResult != aResult)
                 {
-                    _pTree->InsertEntry(aResult, pParent, STRUCT_END, 0, _pToken, *xEntry);
+                    // Cell is a formula, print subformula.
+                    // With scalar values prints "A1:A3 = 2 {1;2;3}"
+                    _pTree->InsertEntry( aResult + " = " + aUnforcedResult + aCellResult,
+                            pParent, STRUCT_END, 0, _pToken, *xEntry);
                 }
-                --Count;
-                MakeTree( _pTree, pParent, _pToken, m_pTokenArrayIterator->PrevRPN(), Count);
+                else
+                    _pTree->InsertEntry(aResult, pParent, STRUCT_END, 0, _pToken, *xEntry);
             }
+            else
+            {
+                _pTree->InsertEntry(aResult, pParent, STRUCT_END, 0, _pToken, *xEntry);
+            }
+            --Count;
+            MakeTree( _pTree, pParent, _pToken, m_pTokenArrayIterator->PrevRPN(), Count);
         }
-        catch (const uno::Exception&)
-        {
-            DBG_UNHANDLED_EXCEPTION("formula.ui");
-        }
+    }
+    catch (const uno::Exception&)
+    {
+        DBG_UNHANDLED_EXCEPTION("formula.ui");
     }
 }
 
@@ -1222,64 +1222,64 @@ OUString FormulaDlg_Impl::GetPrevFuncExpression( bool bStartFromEnd )
 
 void FormulaDlg_Impl::SaveArg( sal_uInt16 nEd )
 {
-    if (nEd < m_nArgs)
+    if (nEd >= m_nArgs)
+        return;
+
+    for (sal_uInt16 i = 0; i <= nEd; i++)
     {
-        for (sal_uInt16 i = 0; i <= nEd; i++)
-        {
-            if ( m_aArguments[i].isEmpty() )
-                m_aArguments[i] = " ";
-        }
-        if (!m_xParaWin->GetArgument(nEd).isEmpty())
-            m_aArguments[nEd] = m_xParaWin->GetArgument(nEd);
+        if ( m_aArguments[i].isEmpty() )
+            m_aArguments[i] = " ";
+    }
+    if (!m_xParaWin->GetArgument(nEd).isEmpty())
+        m_aArguments[nEd] = m_xParaWin->GetArgument(nEd);
 
-        sal_uInt16 nClearPos = nEd+1;
-        for (sal_Int32 i = nEd+1; i < m_nArgs; i++)
+    sal_uInt16 nClearPos = nEd+1;
+    for (sal_Int32 i = nEd+1; i < m_nArgs; i++)
+    {
+        if ( !m_xParaWin->GetArgument(i).isEmpty() )
         {
-            if ( !m_xParaWin->GetArgument(i).isEmpty() )
-            {
-                nClearPos = i+1;
-            }
+            nClearPos = i+1;
         }
+    }
 
-        for (sal_Int32 i = nClearPos; i < m_nArgs; i++)
-        {
-            m_aArguments[i].clear();
-        }
+    for (sal_Int32 i = nClearPos; i < m_nArgs; i++)
+    {
+        m_aArguments[i].clear();
     }
 }
 
 IMPL_LINK( FormulaDlg_Impl, FxHdl, ParaWin&, rPtr, void )
 {
-    if (&rPtr == m_xParaWin.get())
-    {
-        m_xBtnForward->set_sensitive(true); //@ In order to be able to input another function.
-        m_xTabCtrl->set_current_page("function");
+    if (&rPtr != m_xParaWin.get())
+        return;
 
-        OUString aUndoStr = m_pHelper->getCurrentFormula();       // it will be added before a ";"
-        FormEditData* pData = m_pHelper->getFormEditData();
-        if (!pData)
-            return;
+    m_xBtnForward->set_sensitive(true); //@ In order to be able to input another function.
+    m_xTabCtrl->set_current_page("function");
 
-        sal_uInt16 nArgNo = m_xParaWin->GetActiveLine();
-        sal_uInt16 nEdFocus = nArgNo;
+    OUString aUndoStr = m_pHelper->getCurrentFormula();       // it will be added before a ";"
+    FormEditData* pData = m_pHelper->getFormEditData();
+    if (!pData)
+        return;
 
-        SaveArg(nArgNo);
-        UpdateSelection();
+    sal_uInt16 nArgNo = m_xParaWin->GetActiveLine();
+    sal_uInt16 nEdFocus = nArgNo;
 
-        sal_Int32 nFormulaStrPos = pData->GetFStart();
+    SaveArg(nArgNo);
+    UpdateSelection();
 
-        OUString aFormula = m_pHelper->getCurrentFormula();
-        sal_Int32 n1 = m_aFormulaHelper.GetArgStart( aFormula, nFormulaStrPos, nEdFocus + pData->GetOffset() );
+    sal_Int32 nFormulaStrPos = pData->GetFStart();
 
-        pData->SaveValues();
-        pData->SetMode( FormulaDlgMode::Formula );
-        pData->SetFStart( n1 );
-        pData->SetUndoStr( aUndoStr );
-        ClearAllParas();
+    OUString aFormula = m_pHelper->getCurrentFormula();
+    sal_Int32 n1 = m_aFormulaHelper.GetArgStart( aFormula, nFormulaStrPos, nEdFocus + pData->GetOffset() );
 
-        FillDialog(false);
-        m_xFuncPage->SetFocus(); //There Parawin is not visible anymore
-    }
+    pData->SaveValues();
+    pData->SetMode( FormulaDlgMode::Formula );
+    pData->SetFStart( n1 );
+    pData->SetUndoStr( aUndoStr );
+    ClearAllParas();
+
+    FillDialog(false);
+    m_xFuncPage->SetFocus(); //There Parawin is not visible anymore
 }
 
 IMPL_LINK( FormulaDlg_Impl, ModifyHdl, ParaWin&, rPtr, void )
@@ -1528,43 +1528,43 @@ void FormulaDlg_Impl::RefInputStartAfter()
 {
     m_xRefBtn->SetEndImage();
 
-    if (m_pTheRefEdit)
-    {
-        OUString aStr = m_aTitle2 + " " + m_xFtEditName->get_label() + "( ";
+    if (!m_pTheRefEdit)
+        return;
 
-        if ( m_xParaWin->GetActiveLine() > 0 )
-            aStr += "...; ";
-        aStr += m_xParaWin->GetActiveArgName();
-        if ( m_xParaWin->GetActiveLine() + 1 < m_nArgs )
-            aStr += "; ...";
-        aStr += " )";
+    OUString aStr = m_aTitle2 + " " + m_xFtEditName->get_label() + "( ";
 
-        m_rDialog.set_title(m_rDialog.strip_mnemonic(aStr));
-    }
+    if ( m_xParaWin->GetActiveLine() > 0 )
+        aStr += "...; ";
+    aStr += m_xParaWin->GetActiveArgName();
+    if ( m_xParaWin->GetActiveLine() + 1 < m_nArgs )
+        aStr += "; ...";
+    aStr += " )";
+
+    m_rDialog.set_title(m_rDialog.strip_mnemonic(aStr));
 }
 
 void FormulaDlg_Impl::RefInputDoneAfter( bool bForced )
 {
     m_xRefBtn->SetStartImage();
-    if (bForced || !m_xRefBtn->GetWidget()->get_visible())
+    if (!(bForced || !m_xRefBtn->GetWidget()->get_visible()))
+        return;
+
+    m_xEdRef->GetWidget()->hide();
+    m_xRefBtn->GetWidget()->hide();
+    if ( m_pTheRefEdit )
     {
-        m_xEdRef->GetWidget()->hide();
-        m_xRefBtn->GetWidget()->hide();
-        if ( m_pTheRefEdit )
-        {
-            m_pTheRefEdit->SetRefString( m_xEdRef->GetText() );
-            m_pTheRefEdit->GrabFocus();
+        m_pTheRefEdit->SetRefString( m_xEdRef->GetText() );
+        m_pTheRefEdit->GrabFocus();
 
-            if ( m_pTheRefButton )
-                m_pTheRefButton->SetStartImage();
+        if ( m_pTheRefButton )
+            m_pTheRefButton->SetStartImage();
 
-            sal_uInt16 nPrivActiv = m_xParaWin->GetActiveLine();
-            m_xParaWin->SetArgument( nPrivActiv, m_xEdRef->GetText() );
-            ModifyHdl( *m_xParaWin );
-            m_pTheRefEdit = nullptr;
-        }
-        m_rDialog.set_title(m_aTitle1);
+        sal_uInt16 nPrivActiv = m_xParaWin->GetActiveLine();
+        m_xParaWin->SetArgument( nPrivActiv, m_xEdRef->GetText() );
+        ModifyHdl( *m_xParaWin );
+        m_pTheRefEdit = nullptr;
     }
+    m_rDialog.set_title(m_aTitle1);
 }
 
 RefEdit* FormulaDlg_Impl::GetCurrRefEdit()
diff --git a/formula/source/ui/dlg/parawin.cxx b/formula/source/ui/dlg/parawin.cxx
index d3c4de1b7554..ceb50d8d7e6d 100644
--- a/formula/source/ui/dlg/parawin.cxx
+++ b/formula/source/ui/dlg/parawin.cxx
@@ -108,55 +108,55 @@ void ParaWin::UpdateArgDesc( sal_uInt16 nArg )
     if (nMaxArgs > 4)
         nArg = sal::static_int_cast<sal_uInt16>( nArg + GetSliderPos() );
 
-    if ((nMaxArgs > 0) && (nArg<nMaxArgs))
-    {
-        OUString  aArgDesc;
-        OUString  aArgName;
+    if (!((nMaxArgs > 0) && (nArg<nMaxArgs)))
+        return;
 
-        SetArgumentDesc( OUString() );
-        SetArgumentText( OUString() );
+    OUString  aArgDesc;
+    OUString  aArgName;
 
-        if ( nArgs < VAR_ARGS )
-        {
-            sal_uInt16 nRealArg = (nArg < aVisibleArgMapping.size()) ? aVisibleArgMapping[nArg] : nArg;
-            aArgDesc  = pFuncDesc->getParameterDescription(nRealArg);
-            aArgName  = pFuncDesc->getParameterName(nRealArg) + " " +
-                ((pFuncDesc->isParameterOptional(nRealArg)) ? m_sOptional : m_sRequired);
-        }
-        else if ( nArgs < PAIRED_VAR_ARGS )
-        {
-            sal_uInt16 nFix = nArgs - VAR_ARGS;
-            sal_uInt16 nPos = std::min( nArg, nFix );
-            sal_uInt16 nRealArg = (nPos < aVisibleArgMapping.size() ?
-                    aVisibleArgMapping[nPos] : aVisibleArgMapping.back());
-            aArgDesc  = pFuncDesc->getParameterDescription(nRealArg);
-            aArgName  = pFuncDesc->getParameterName(nRealArg);
-            sal_uInt16 nVarArgsStart = pFuncDesc->getVarArgsStart();
-            if ( nArg >= nVarArgsStart )
-                aArgName += OUString::number( nArg-nVarArgsStart+1 );
-            aArgName += " " + ((nArg > nFix || pFuncDesc->isParameterOptional(nRealArg)) ? m_sOptional : m_sRequired) ;
-        }
-        else
-        {
-            sal_uInt16 nFix = nArgs - PAIRED_VAR_ARGS;
-            sal_uInt16 nPos;
-            if ( nArg < nFix )
-                nPos = nArg;
-            else
-                nPos = nFix + ( (nArg-nFix) % 2);
-            sal_uInt16 nRealArg = (nPos < aVisibleArgMapping.size() ?
-                    aVisibleArgMapping[nPos] : aVisibleArgMapping.back());
-            aArgDesc  = pFuncDesc->getParameterDescription(nRealArg);
-            aArgName  = pFuncDesc->getParameterName(nRealArg);
-            sal_uInt16 nVarArgsStart = pFuncDesc->getVarArgsStart();
-            if ( nArg >= nVarArgsStart )
-                aArgName += OUString::number( (nArg-nVarArgsStart)/2 + 1 );
-            aArgName += " " + ((nArg > (nFix+1) || pFuncDesc->isParameterOptional(nRealArg)) ? m_sOptional : m_sRequired) ;
-        }
+    SetArgumentDesc( OUString() );
+    SetArgumentText( OUString() );
 
-        SetArgumentDesc(aArgDesc);
-        SetArgumentText(aArgName);
+    if ( nArgs < VAR_ARGS )
+    {
+        sal_uInt16 nRealArg = (nArg < aVisibleArgMapping.size()) ? aVisibleArgMapping[nArg] : nArg;
+        aArgDesc  = pFuncDesc->getParameterDescription(nRealArg);
+        aArgName  = pFuncDesc->getParameterName(nRealArg) + " " +
+            ((pFuncDesc->isParameterOptional(nRealArg)) ? m_sOptional : m_sRequired);
+    }
+    else if ( nArgs < PAIRED_VAR_ARGS )
+    {
+        sal_uInt16 nFix = nArgs - VAR_ARGS;
+        sal_uInt16 nPos = std::min( nArg, nFix );
+        sal_uInt16 nRealArg = (nPos < aVisibleArgMapping.size() ?
+                aVisibleArgMapping[nPos] : aVisibleArgMapping.back());
+        aArgDesc  = pFuncDesc->getParameterDescription(nRealArg);
+        aArgName  = pFuncDesc->getParameterName(nRealArg);
+        sal_uInt16 nVarArgsStart = pFuncDesc->getVarArgsStart();
+        if ( nArg >= nVarArgsStart )
+            aArgName += OUString::number( nArg-nVarArgsStart+1 );
+        aArgName += " " + ((nArg > nFix || pFuncDesc->isParameterOptional(nRealArg)) ? m_sOptional : m_sRequired) ;
     }
+    else
+    {
+        sal_uInt16 nFix = nArgs - PAIRED_VAR_ARGS;
+        sal_uInt16 nPos;
+        if ( nArg < nFix )
+            nPos = nArg;
+        else
+            nPos = nFix + ( (nArg-nFix) % 2);
+        sal_uInt16 nRealArg = (nPos < aVisibleArgMapping.size() ?
+                aVisibleArgMapping[nPos] : aVisibleArgMapping.back());
+        aArgDesc  = pFuncDesc->getParameterDescription(nRealArg);
+        aArgName  = pFuncDesc->getParameterName(nRealArg);
+        sal_uInt16 nVarArgsStart = pFuncDesc->getVarArgsStart();
+        if ( nArg >= nVarArgsStart )
+            aArgName += OUString::number( (nArg-nVarArgsStart)/2 + 1 );
+        aArgName += " " + ((nArg > (nFix+1) || pFuncDesc->isParameterOptional(nRealArg)) ? m_sOptional : m_sRequired) ;
+    }
+
+    SetArgumentDesc(aArgDesc);
+    SetArgumentText(aArgName);
 }
 
 void ParaWin::UpdateArgInput( sal_uInt16 nOffset, sal_uInt16 i )
@@ -234,20 +234,20 @@ ParaWin::~ParaWin()
 
 void ParaWin::SetActiveLine(sal_uInt16 no)
 {
-    if (no < nMaxArgs)
+    if (no >= nMaxArgs)
+        return;
+
+    long nOffset = GetSliderPos();
+    nActiveLine=no;
+    long nNewEdPos=static_cast<long>(nActiveLine)-nOffset;
+    if(nNewEdPos<0 || nNewEdPos>3)
     {
-        long nOffset = GetSliderPos();
-        nActiveLine=no;
-        long nNewEdPos=static_cast<long>(nActiveLine)-nOffset;
-        if(nNewEdPos<0 || nNewEdPos>3)
-        {
-            nOffset+=nNewEdPos;
-            SetSliderPos(static_cast<sal_uInt16>(nOffset));
-            nOffset=GetSliderPos();
-        }
-        nEdFocus=no-static_cast<sal_uInt16>(nOffset);
-        UpdateArgDesc( nEdFocus );
+        nOffset+=nNewEdPos;
+        SetSliderPos(static_cast<sal_uInt16>(nOffset));
+        nOffset=GetSliderPos();
     }
+    nEdFocus=no-static_cast<sal_uInt16>(nOffset);
+    UpdateArgDesc( nEdFocus );
 }
 
 RefEdit* ParaWin::GetActiveEdit()
diff --git a/formula/source/ui/dlg/structpg.cxx b/formula/source/ui/dlg/structpg.cxx
index 432f2a9bdd5b..0f5fd9417732 100644
--- a/formula/source/ui/dlg/structpg.cxx
+++ b/formula/source/ui/dlg/structpg.cxx
@@ -127,26 +127,26 @@ const FormulaToken* StructPage::GetFunctionEntry(const weld::TreeIter* pEntry)
 
 IMPL_LINK(StructPage, SelectHdl, weld::TreeView&, rTlb, void)
 {
-    if (GetActiveFlag())
+    if (!GetActiveFlag())
+        return;
+
+    if (&rTlb == m_xTlbStruct.get())
     {
-        if (&rTlb == m_xTlbStruct.get())
+        std::unique_ptr<weld::TreeIter> xCurEntry(m_xTlbStruct->make_iterator());
+        if (m_xTlbStruct->get_cursor(xCurEntry.get()))
         {
-            std::unique_ptr<weld::TreeIter> xCurEntry(m_xTlbStruct->make_iterator());
-            if (m_xTlbStruct->get_cursor(xCurEntry.get()))
+            pSelectedToken = reinterpret_cast<const FormulaToken *>(m_xTlbStruct->get_id(*xCurEntry).toInt64());
+            if (pSelectedToken)
             {
-                pSelectedToken = reinterpret_cast<const FormulaToken *>(m_xTlbStruct->get_id(*xCurEntry).toInt64());
-                if (pSelectedToken)
+                if ( !(pSelectedToken->IsFunction() || pSelectedToken->GetParamCount() > 1) )
                 {
-                    if ( !(pSelectedToken->IsFunction() || pSelectedToken->GetParamCount() > 1) )
-                    {
-                        pSelectedToken = GetFunctionEntry(xCurEntry.get());
-                    }
+                    pSelectedToken = GetFunctionEntry(xCurEntry.get());
                 }
             }
         }
-
-        aSelLink.Call(*this);
     }
+
+    aSelLink.Call(*this);
 }
 
 } // formula


More information about the Libreoffice-commits mailing list