sw/source/uibase/ribbar/inputwin.cxx |   20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

New commits:
commit 24cc6f7e21844c078b8db4c505df5ca3983450b3
Author:     Justin Luth <jl...@mail.com>
AuthorDate: Mon May 8 21:29:32 2023 -0400
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Wed May 10 20:09:13 2023 +0200

    related tdf#138925 sw inputwin: get correct cell formula
    
    The problem was that repeatedly pressing F2,
    or any non-mouse movement between cells
    was getting a "random" formula returned.
    
    The only thing that worked was moving the mouse,
    because on every pixel change, it re-loads
    the RequestHelp tooltip that displays the formula,
    thus loading it as the most current formula.
    
    The example bug document easily crashes,
    and everything about this is terribly imprecise,
    so I'm not attempting to make any unit test here.
    
    The code is modeled from GetContentAtPos,
    which also does an unconditional const_cast.
    
    Change-Id: Iecaf2e9a56bccef9a1e05bc0667caad6c3aeb109
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151550
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>

diff --git a/sw/source/uibase/ribbar/inputwin.cxx 
b/sw/source/uibase/ribbar/inputwin.cxx
index 2adddb87cd33..92a9f3fb213c 100644
--- a/sw/source/uibase/ribbar/inputwin.cxx
+++ b/sw/source/uibase/ribbar/inputwin.cxx
@@ -257,7 +257,25 @@ void SwInputWindow::ShowWin()
 
             SfxItemSetFixed<RES_BOXATR_FORMULA, RES_BOXATR_FORMULA> aSet( 
m_pWrtShell->GetAttrPool() );
             if( m_pWrtShell->GetTableBoxFormulaAttrs( aSet ))
-                sEdit += aSet.Get( RES_BOXATR_FORMULA ).GetFormula();
+            {
+                SwTableBoxFormula& rFormula
+                    = 
const_cast<SwTableBoxFormula&>(aSet.Get(RES_BOXATR_FORMULA));
+                // rFormula could be ANY of the table's formulas.
+                // GetFormula returns the "current" formula - which is 
basically undefined,
+                // so do something that encourages the current position's 
formula to become current.
+                if (m_pWrtShell->GetCursor())
+                {
+                    const SwNode* pNd = 
m_pWrtShell->GetCursor()->GetPointNode().FindTableNode();
+                    if (pNd)
+                    {
+                        const SwTable& rTable = static_cast<const 
SwTableNode*>(pNd)->GetTable();
+                        // get cell's external formula (for UI) by waving the 
magic wand.
+                        rFormula.PtrToBoxNm(&rTable);
+                    }
+                }
+
+                sEdit += rFormula.GetFormula();
+            }
         }
 
         if( m_bFirst )

Reply via email to