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

Eike Rathke erack at redhat.com
Fri Dec 18 06:44:40 PST 2015


 formula/source/ui/dlg/formula.cxx |   55 ++++++++++++++++++++++++++------------
 1 file changed, 38 insertions(+), 17 deletions(-)

New commits:
commit 9d1ee5a5b4730a6d3da4e8a02a08d1d27e9d27e4
Author: Eike Rathke <erack at redhat.com>
Date:   Fri Dec 18 15:40:31 2015 +0100

    Resolves: tdf#96366 replace Edit...() calls with actually working code
    
    ... and way less overhead, geez..
    
    Change-Id: Id9277301fbe69bc9a83ca39a907032b0b86b1c81

diff --git a/formula/source/ui/dlg/formula.cxx b/formula/source/ui/dlg/formula.cxx
index 3c1523c..bb4f46d 100644
--- a/formula/source/ui/dlg/formula.cxx
+++ b/formula/source/ui/dlg/formula.cxx
@@ -92,6 +92,8 @@ public:
     bool            EditNextFunc( bool bForward, sal_Int32 nFStart=NOT_FOUND );
     void            EditThisFunc(sal_Int32 nFStart);
 
+    OUString        GetPrevFuncExpression( bool bStartFromEnd );
+
     void            StoreFormEditData(FormEditData* pEditData);
 
     void            Update();
@@ -206,6 +208,8 @@ public:
     ::std::vector< OUString > m_aArguments;
     Selection       aFuncSel;
 
+    sal_Int32       mnFuncExpStart;     ///< current formula position for treeview results
+
     FormulaDlg_Impl(Dialog* pParent
             , bool _bSupportFunctionResult
             , bool _bSupportResult
@@ -242,7 +246,8 @@ FormulaDlg_Impl::FormulaDlg_Impl(Dialog* pParent
     bMakingTree     (false),
     nEdFocus        (0),
     pFuncDesc       (nullptr),
-    nArgs           (0)
+    nArgs           (0),
+    mnFuncExpStart  (0)
 {
     pParent->get(m_pParaWinBox, "BOX");
     pParent->get(m_pTabCtrl, "tabs");
@@ -695,31 +700,25 @@ void FormulaDlg_Impl::MakeTree(StructPage* _pTree,SvTreeListEntry* pParent,Formu
 
                 if (bCalcSubformula)
                 {
-/* FIXME: tdf#96366 this simply does not work, disable until solved. */
-#if 0
-                    OUString aStr;
-                    OUString aEquals(" = ");
+                    OUString aFormula;
 
                     if (!bMakingTree)
-                    { // gets the last subformula result
+                    {
+                        // gets the last subformula result
                         bMakingTree = true;
-                        EditThisFunc(0);
-                        while ( EditNextFunc(true) ) {}
+                        aFormula = GetPrevFuncExpression( true);
                     }
                     else
-                    { // gets subsequent subformula results (from the back)
-                        const IFunctionDescription* pDesc =pFuncPage->GetFuncDesc( pFuncPage->GetFunction() );
-                        if(pDesc==pFuncDesc || !pFuncPage->IsVisible())
-                        {
-                            EditNextFunc(false);
-                        }
+                    {
+                        // gets subsequent subformula results (from the back)
+                        aFormula = GetPrevFuncExpression( false);
                     }
 
-                    if ( CalcValue( pFuncDesc->getFormula( m_aArguments ), aStr ) )
+                    OUString aStr;
+                    if (CalcValue( aFormula, aStr))
                         m_pWndResult->SetText( aStr );
                     aStr = m_pWndResult->GetText();
-                    pStructPage->GetTlbStruct()->SetEntryText(pEntry,aResult + aEquals + aStr);
-#endif
+                    pStructPage->GetTlbStruct()->SetEntryText( pEntry, aResult + " = " + aStr);
                 }
 
                 --Count;
@@ -1200,6 +1199,28 @@ bool FormulaDlg_Impl::EditNextFunc( bool bForward, sal_Int32 nFStart )
     return bFound;
 }
 
+OUString FormulaDlg_Impl::GetPrevFuncExpression( bool bStartFromEnd )
+{
+    OUString aExpression;
+
+    OUString aFormula( m_pHelper->getCurrentFormula());
+    if (aFormula.isEmpty())
+        return aExpression;
+
+    if (bStartFromEnd || mnFuncExpStart >= aFormula.getLength())
+        mnFuncExpStart = aFormula.getLength() - 1;
+
+    sal_Int32 nFStart = mnFuncExpStart;
+    sal_Int32 nFEnd   = 0;
+    if (m_aFormulaHelper.GetNextFunc( aFormula, true, nFStart, &nFEnd))
+    {
+        aExpression = aFormula.copy( nFStart, nFEnd - nFStart); // nFEnd is exclusive
+        mnFuncExpStart = nFStart;
+    }
+
+    return aExpression;
+}
+
 void FormulaDlg_Impl::SaveArg( sal_uInt16 nEd )
 {
     if (nEd<nArgs)


More information about the Libreoffice-commits mailing list