From 24cc6f7e21844c078b8db4c505df5ca3983450b3 Mon Sep 17 00:00:00 2001 From: Justin Luth Date: Mon, 8 May 2023 21:29:32 -0400 Subject: 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 --- sw/source/uibase/ribbar/inputwin.cxx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'sw') 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 aSet( m_pWrtShell->GetAttrPool() ); if( m_pWrtShell->GetTableBoxFormulaAttrs( aSet )) - sEdit += aSet.Get( RES_BOXATR_FORMULA ).GetFormula(); + { + SwTableBoxFormula& rFormula + = const_cast(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(pNd)->GetTable(); + // get cell's external formula (for UI) by waving the magic wand. + rFormula.PtrToBoxNm(&rTable); + } + } + + sEdit += rFormula.GetFormula(); + } } if( m_bFirst ) -- cgit