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

Eike Rathke erack at redhat.com
Mon May 12 16:18:03 PDT 2014


 sc/source/ui/app/inputhdl.cxx |  418 ++++++++++++++----------------------------
 sc/source/ui/inc/inputhdl.hxx |    2 
 2 files changed, 146 insertions(+), 274 deletions(-)

New commits:
commit 5a14766061f75e88791dc3134c9ec56e198144e2
Author: Eike Rathke <erack at redhat.com>
Date:   Tue May 13 01:16:24 2014 +0200

    distill copypasta
    
    Change-Id: Ibb6e9e6f98041ddc81b3743f57c3335458be2cb0

diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index f35ab6a..ec22405 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -792,186 +792,186 @@ void ScInputHandler::HideTipBelow()
     aManualTip = OUString();
 }
 
-void ScInputHandler::ShowTipCursor()
+void ScInputHandler::ShowArgumentsTip( const OUString& rParagraph, OUString& rSelText, const ESelection& rSel,
+        bool bTryFirstSel )
 {
-    HideTip();
-    HideTipBelow();
-    EditView* pActiveView = pTopView ? pTopView : pTableView;
     ScDocShell* pDocSh = pActiveViewSh->GetViewData()->GetDocShell();
     const sal_Unicode cSep = ScCompiler::GetNativeSymbolChar(ocSep);
     const sal_Unicode cSheetSep = lcl_getSheetSeparator(pDocSh->GetDocument());
-
-    if ( bFormulaMode && pActiveView && pFormulaDataPara && pEngine->GetParagraphCount() == 1 )
+    FormulaHelper aHelper(ScGlobal::GetStarCalcFunctionMgr());
+    bool bFound = false;
+    while( !bFound )
     {
-        OUString aFormula = pEngine->GetText( 0 );
-        ESelection aSel = pActiveView->GetSelection();
-        aSel.Adjust();
-        if( aSel.nEndPos )
+        rSelText += ")";
+        sal_Int32 nLeftParentPos = lcl_MatchParenthesis( rSelText, rSelText.getLength()-1 );
+        if( nLeftParentPos != -1 )
         {
-            if ( aFormula.getLength() < aSel.nEndPos )
-                return;
-            sal_Int32 nPos = aSel.nEndPos;
-            OUString  aSelText = aFormula.copy( 0, nPos );
-            sal_Int32   nNextFStart = 0;
-            sal_Int32  nArgPos = 0;
+            sal_Int32 nNextFStart = aHelper.GetFunctionStart( rSelText, nLeftParentPos, true);
             const IFunctionDescription* ppFDesc;
             ::std::vector< OUString> aArgs;
-            sal_uInt16      nArgs;
-            bool bFound = false;
-            FormulaHelper aHelper(ScGlobal::GetStarCalcFunctionMgr());
-
-            while( !bFound )
+            if( aHelper.GetNextFunc( rSelText, false, nNextFStart, NULL, &ppFDesc, &aArgs ) )
             {
-                aSelText += ")";
-                sal_Int32 nLeftParentPos = lcl_MatchParenthesis( aSelText, aSelText.getLength()-1 );
-                if( nLeftParentPos != -1 )
+                if( !ppFDesc->getFunctionName().isEmpty() )
                 {
-                    sal_Unicode c = ( nLeftParentPos > 0 ) ? aSelText[ nLeftParentPos-1 ] : 0;
-                    if( !(comphelper::string::isalphaAscii(c)) )
-                        continue;
-                    nNextFStart = aHelper.GetFunctionStart( aSelText, nLeftParentPos, true);
-                    if( aHelper.GetNextFunc( aSelText, false, nNextFStart, NULL, &ppFDesc, &aArgs ) )
+                    sal_Int32 nArgPos = aHelper.GetArgStart( rSelText, nNextFStart, 0 );
+                    sal_uInt16 nArgs = static_cast<sal_uInt16>(ppFDesc->getParameterCount());
+                    OUString aFuncName( ppFDesc->getFunctionName() + "(");
+                    OUString aNew;
+                    ScTypedCaseStrSet::const_iterator it =
+                        findText(*pFormulaDataPara, pFormulaDataPara->end(), aFuncName, aNew, false);
+                    if (it != pFormulaDataPara->end())
                     {
-                        if( !ppFDesc->getFunctionName().isEmpty() )
+                        bool bFlag = false;
+                        sal_uInt16 nActive = 0;
+                        for( sal_uInt16 i=0; i < nArgs; i++ )
+                        {
+                            sal_Int32 nLength = aArgs[i].getLength();
+                            if( nArgPos <= rSelText.getLength()-1 )
+                            {
+                                nActive = i+1;
+                                bFlag = true;
+                            }
+                            nArgPos+=nLength+1;
+                        }
+                        if( bFlag )
                         {
-                            nArgPos = aHelper.GetArgStart( aSelText, nNextFStart, 0 );
-                            nArgs = static_cast<sal_uInt16>(ppFDesc->getParameterCount());
-
-                            OUString aFuncName = ppFDesc->getFunctionName() + "(";
-                            OUString aNew;
-                            ScTypedCaseStrSet::const_iterator it =
-                                findText(*pFormulaDataPara, pFormulaDataPara->end(), aFuncName, aNew, false);
-                            if (it != pFormulaDataPara->end())
+                            sal_Int32 nCountSemicolon = comphelper::string::getTokenCount(aNew, cSep) - 1;
+                            sal_Int32 nCountDot = comphelper::string::getTokenCount(aNew, cSheetSep) - 1;
+                            sal_Int32 nStartPosition = 0;
+                            sal_Int32 nEndPosition = 0;
+
+                            if( !nCountSemicolon )
                             {
-                                bool bFlag = false;
-                                sal_uInt16 nActive = 0;
-                                for( sal_uInt16 i=0; i < nArgs; i++ )
+                                for (sal_Int32 i = 0; i < aNew.getLength(); ++i)
                                 {
-                                    sal_Int32 nLength = aArgs[i].getLength();
-                                    if( nArgPos <= aSelText.getLength()-1 )
+                                    sal_Unicode cNext = aNew[i];
+                                    if( cNext == '(' )
                                     {
-                                        nActive = i+1;
-                                        bFlag = true;
+                                        nStartPosition = i+1;
                                     }
-                                    nArgPos+=nLength+1;
                                 }
-                                if( bFlag )
+                            }
+                            else if( !nCountDot )
+                            {
+                                sal_uInt16 nCount = 0;
+                                for (sal_Int32 i = 0; i < aNew.getLength(); ++i)
                                 {
-                                    sal_Int32 nCountSemicolon = comphelper::string::getTokenCount(aNew, cSep) - 1;
-                                    sal_Int32 nCountDot = comphelper::string::getTokenCount(aNew, cSheetSep) - 1;
-                                    sal_Int32 nStartPosition = 0;
-                                    sal_Int32 nEndPosition = 0;
-
-                                    if( !nCountSemicolon )
+                                    sal_Unicode cNext = aNew[i];
+                                    if( cNext == '(' )
                                     {
-                                        for (sal_Int32 i = 0; i < aNew.getLength(); ++i)
-                                        {
-                                            sal_Unicode cNext = aNew[i];
-                                            if( cNext == '(' )
-                                            {
-                                                nStartPosition = i+1;
-                                            }
-                                        }
+                                        nStartPosition = i+1;
                                     }
-                                    else if( !nCountDot )
+                                    else if( cNext == cSep )
                                     {
-                                        sal_uInt16 nCount = 0;
-                                        for (sal_Int32 i = 0; i < aNew.getLength(); ++i)
+                                        nCount ++;
+                                        nEndPosition = i;
+                                        if( nCount == nActive )
                                         {
-                                            sal_Unicode cNext = aNew[i];
-                                            if( cNext == '(' )
-                                            {
-                                                nStartPosition = i+1;
-                                            }
-                                            else if( cNext == cSep )
-                                            {
-                                                nCount ++;
-                                                nEndPosition = i;
-                                                if( nCount == nActive )
-                                                {
-                                                    break;
-                                                }
-                                                nStartPosition = nEndPosition+1;
-                                            }
+                                            break;
                                         }
+                                        nStartPosition = nEndPosition+1;
+                                    }
+                                }
+                            }
+                            else
+                            {
+                                sal_uInt16 nCount = 0;
+                                for (sal_Int32 i = 0; i < aNew.getLength(); ++i)
+                                {
+                                    sal_Unicode cNext = aNew[i];
+                                    if( cNext == '(' )
+                                    {
+                                        nStartPosition = i+1;
                                     }
-                                    else
+                                    else if( cNext == cSep )
                                     {
-                                        sal_uInt16 nCount = 0;
-                                        for (sal_Int32 i = 0; i < aNew.getLength(); ++i)
+                                        nCount ++;
+                                        nEndPosition = i;
+                                        if( nCount == nActive )
                                         {
-                                            sal_Unicode cNext = aNew[i];
-                                            if( cNext == '(' )
-                                            {
-                                                nStartPosition = i+1;
-                                            }
-                                            else if( cNext == cSep )
-                                            {
-                                                nCount ++;
-                                                nEndPosition = i;
-                                                if( nCount == nActive )
-                                                {
-                                                    break;
-                                                }
-                                                nStartPosition = nEndPosition+1;
-                                            }
-                                            else if( cNext == cSheetSep )
-                                            {
-                                                continue;
-                                            }
+                                            break;
                                         }
+                                        nStartPosition = nEndPosition+1;
                                     }
-
-                                    if (nStartPosition > 0)
+                                    else if( cNext == cSheetSep )
                                     {
-                                        OUStringBuffer aBuf;
-                                        aBuf.append(aNew.copy(0, nStartPosition));
-                                        aBuf.append(static_cast<sal_Unicode>(0x25BA));
-                                        aBuf.append(aNew.copy(nStartPosition));
-                                        aNew = aBuf.makeStringAndClear();
-                                        ShowTipBelow( aNew );
-                                        bFound = true;
+                                        continue;
                                     }
                                 }
-                                else
-                                {
-                                    ShowTipBelow( aNew );
-                                    bFound = true;
-                                }
+                            }
+
+                            if (nStartPosition > 0)
+                            {
+                                OUStringBuffer aBuf;
+                                aBuf.append(aNew.copy(0, nStartPosition));
+                                aBuf.append(static_cast<sal_Unicode>(0x25BA));
+                                aBuf.append(aNew.copy(nStartPosition));
+                                aNew = aBuf.makeStringAndClear();
+                                ShowTipBelow( aNew );
+                                bFound = true;
                             }
                         }
-                    }
-                }
-                else
-                {
-                    sal_Int32 nPosition = 0;
-                    OUString aText = pEngine->GetWord( 0, aSel.nEndPos-1 );
-                    /* XXX: dubious, what is this condition supposed to exactly match? */
-                    if (aSel.nEndPos <= aText.getLength() && aText[ aSel.nEndPos-1 ] == '=')
-                    {
-                        break;
-                    }
-                    OUString aNew;
-                    nPosition = aText.getLength()+1;
-                    ScTypedCaseStrSet::const_iterator it =
-                        findText(*pFormulaDataPara, pFormulaDataPara->end(), aText, aNew, false);
-                    if (it != pFormulaDataPara->end())
-                    {
-                        if( nPosition < aFormula.getLength() && aFormula[ nPosition ] =='(' )
+                        else
                         {
                             ShowTipBelow( aNew );
                             bFound = true;
                         }
-                        else
-                            break;
-                    }
-                    else
-                    {
-                        break;
                     }
                 }
             }
         }
+        else if (bTryFirstSel)
+        {
+            sal_Int32 nPosition = 0;
+            OUString aText = pEngine->GetWord( 0, rSel.nEndPos-1 );
+            /* XXX: dubious, what is this condition supposed to exactly match? */
+            if (rSel.nEndPos <= aText.getLength() && aText[ rSel.nEndPos-1 ] == '=')
+            {
+                break;
+            }
+            OUString aNew;
+            nPosition = aText.getLength()+1;
+            ScTypedCaseStrSet::const_iterator it =
+                findText(*pFormulaDataPara, pFormulaDataPara->end(), aText, aNew, false);
+            if (it != pFormulaDataPara->end())
+            {
+                if( nPosition < rParagraph.getLength() && rParagraph[ nPosition ] =='(' )
+                {
+                    ShowTipBelow( aNew );
+                    bFound = true;
+                }
+                else
+                    break;
+            }
+            else
+            {
+                break;
+            }
+        }
+    }
+}
+
+void ScInputHandler::ShowTipCursor()
+{
+    HideTip();
+    HideTipBelow();
+    EditView* pActiveView = pTopView ? pTopView : pTableView;
+
+    if ( bFormulaMode && pActiveView && pFormulaDataPara && pEngine->GetParagraphCount() == 1 )
+    {
+        OUString aParagraph = pEngine->GetText( 0 );
+        ESelection aSel = pActiveView->GetSelection();
+        aSel.Adjust();
+
+        if ( aParagraph.getLength() < aSel.nEndPos )
+            return;
+
+        if ( aSel.nEndPos > 0 )
+        {
+            OUString aSelText( aParagraph.copy( 0, aSel.nEndPos ));
+
+            ShowArgumentsTip( aParagraph, aSelText, aSel, true);
+        }
     }
 }
 
@@ -1052,38 +1052,27 @@ bool ScInputHandler::GetFuncName( OUString& aStart, OUString& aResult )
 void ScInputHandler::UseFormulaData()
 {
     EditView* pActiveView = pTopView ? pTopView : pTableView;
-    ScDocShell* pDocSh = pActiveViewSh->GetViewData()->GetDocShell();
-    const sal_Unicode cSep = ScCompiler::GetNativeSymbolChar(ocSep);
-    const sal_Unicode cSheetSep = lcl_getSheetSeparator(pDocSh->GetDocument());
 
     // Formulas may only have 1 paragraph
     if ( pActiveView && pFormulaData && pEngine->GetParagraphCount() == 1 )
     {
-        OUString aTotal = pEngine->GetText( 0 );
+        OUString aParagraph = pEngine->GetText( 0 );
         ESelection aSel = pActiveView->GetSelection();
         aSel.Adjust();
 
         // Due to differences between table and input cell (e.g clipboard with line breaks),
         // the selection may not be in line with the EditEngine anymore.
         // Just return without any indication as to why.
-        if ( aSel.nEndPos > aTotal.getLength() )
+        if ( aSel.nEndPos > aParagraph.getLength() )
             return;
 
         //  Is the cursor at the end of a word?
         if ( aSel.nEndPos > 0 )
         {
-            sal_Int32 nPos = aSel.nEndPos;
-            OUString  aFormula = aTotal.copy( 0, nPos );;
-            sal_Int32   nLeftParentPos = 0;
-            sal_Int32   nNextFStart = 0;
-            sal_Int32  nArgPos = 0;
-            const IFunctionDescription* ppFDesc;
-            ::std::vector< OUString> aArgs;
-            sal_uInt16      nArgs;
-            bool bFound = false;
+            OUString aSelText( aParagraph.copy( 0, aSel.nEndPos ));
 
             OUString aText;
-            if ( GetFuncName( aFormula, aText ) )
+            if ( GetFuncName( aSelText, aText ) )
             {
                 // function name is incomplete:
                 // show first matching function name as tip above cell
@@ -1099,129 +1088,10 @@ void ScInputHandler::UseFormulaData()
                 }
                 return;
             }
-            FormulaHelper aHelper(ScGlobal::GetStarCalcFunctionMgr());
 
             // function name is complete:
             // show tip below the cell with function name and arguments of function
-            while( !bFound )
-            {
-                aFormula += ")";
-                nLeftParentPos = lcl_MatchParenthesis( aFormula, aFormula.getLength()-1 );
-                if( nLeftParentPos == -1 )
-                    break;
-
-                nNextFStart = aHelper.GetFunctionStart( aFormula, nLeftParentPos, true);
-                if( aHelper.GetNextFunc( aFormula, false, nNextFStart, NULL, &ppFDesc, &aArgs ) )
-                {
-                    if( !ppFDesc->getFunctionName().isEmpty() )
-                    {
-                        nArgPos = aHelper.GetArgStart( aFormula, nNextFStart, 0 );
-                        nArgs = static_cast<sal_uInt16>(ppFDesc->getParameterCount());
-                        OUString aFuncName = ppFDesc->getFunctionName() + "(";
-                        OUString aNew;
-                        ScTypedCaseStrSet::const_iterator it =
-                            findText(*pFormulaDataPara, pFormulaDataPara->end(), aFuncName, aNew, false);
-                        if (it != pFormulaDataPara->end())
-                        {
-                            bool bFlag = false;
-                            sal_uInt16 nActive = 0;
-                            for( sal_uInt16 i=0; i < nArgs; i++ )
-                            {
-                                sal_Int32 nLength = aArgs[i].getLength();
-                                if( nArgPos <= aFormula.getLength()-1 )
-                                {
-                                    nActive = i+1;
-                                    bFlag = true;
-                                }
-                                nArgPos+=nLength+1;
-                            }
-                            if( bFlag )
-                            {
-                                sal_Int32 nCountSemicolon = comphelper::string::getTokenCount(aNew, cSep) - 1;
-                                sal_Int32 nCountDot = comphelper::string::getTokenCount(aNew, cSheetSep) - 1;
-                                sal_Int32 nStartPosition = 0;
-                                sal_Int32 nEndPosition = 0;
-
-                               if( !nCountSemicolon )
-                               {
-                                    for (sal_Int32 i = 0; i < aNew.getLength(); ++i)
-                                    {
-                                        sal_Unicode cNext = aNew[i];
-                                        if( cNext == '(' )
-                                        {
-                                            nStartPosition = i+1;
-                                        }
-                                    }
-                                }
-                                else if( !nCountDot )
-                                {
-                                    sal_uInt16 nCount = 0;
-                                    for (sal_Int32 i = 0; i < aNew.getLength(); ++i)
-                                    {
-                                        sal_Unicode cNext = aNew[i];
-                                        if( cNext == '(' )
-                                        {
-                                            nStartPosition = i+1;
-                                        }
-                                        else if( cNext == cSep )
-                                        {
-                                            nCount ++;
-                                            nEndPosition = i;
-                                            if( nCount == nActive )
-                                            {
-                                                break;
-                                            }
-                                            nStartPosition = nEndPosition+1;
-                                        }
-                                    }
-                                }
-                                else
-                                {
-                                    sal_uInt16 nCount = 0;
-                                    for (sal_Int32 i = 0; i < aNew.getLength(); ++i)
-                                    {
-                                        sal_Unicode cNext = aNew[i];
-                                        if( cNext == '(' )
-                                        {
-                                            nStartPosition = i+1;
-                                        }
-                                        else if( cNext == cSep )
-                                        {
-                                            nCount ++;
-                                            nEndPosition = i;
-                                            if( nCount == nActive )
-                                            {
-                                                break;
-                                            }
-                                            nStartPosition = nEndPosition+1;
-                                        }
-                                        else if( cNext == cSheetSep )
-                                        {
-                                            continue;
-                                        }
-                                    }
-                                }
-
-                                if (nStartPosition > 0)
-                                {
-                                    OUStringBuffer aBuf;
-                                    aBuf.append(aNew.copy(0, nStartPosition));
-                                    aBuf.append(static_cast<sal_Unicode>(0x25BA));
-                                    aBuf.append(aNew.copy(nStartPosition));
-                                    aNew = aBuf.makeStringAndClear();
-                                    ShowTipBelow( aNew );
-                                    bFound = true;
-                                }
-                            }
-                            else
-                            {
-                                ShowTipBelow( aNew );
-                                bFound = true;
-                            }
-                        }
-                    }
-                }
-            }
+            ShowArgumentsTip( aParagraph, aSelText, aSel, false);
         }
     }
 }
diff --git a/sc/source/ui/inc/inputhdl.hxx b/sc/source/ui/inc/inputhdl.hxx
index 2f00218..70e4554 100644
--- a/sc/source/ui/inc/inputhdl.hxx
+++ b/sc/source/ui/inc/inputhdl.hxx
@@ -158,6 +158,8 @@ private:
     bool            CursorAtClosingPar();
     void            SkipClosingPar();
     bool            GetFuncName( OUString& aStart, OUString& aResult );  // fdo75264
+    void            ShowArgumentsTip( const OUString& rParagraph, OUString& rSelText, const ESelection& rSel,
+                                      bool bTryFirstSel );
     DECL_LINK( ModifyHdl, void* );
     DECL_LINK( ShowHideTipVisibleParentListener, VclWindowEvent* );
     DECL_LINK( ShowHideTipVisibleSecParentListener, VclWindowEvent* );


More information about the Libreoffice-commits mailing list