summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorJustin Luth <jluth@mail.com>2023-05-08 21:29:32 -0400
committerJustin Luth <jluth@mail.com>2023-05-10 20:09:13 +0200
commit24cc6f7e21844c078b8db4c505df5ca3983450b3 (patch)
tree9f0571d365cf0cc49eebc92e389ae48fd89c3d44 /sw
parent21e6aea941d297545b1acd6592e0769af2b4d8a6 (diff)
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 <jluth@mail.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/source/uibase/ribbar/inputwin.cxx20
1 files changed, 19 insertions, 1 deletions
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 )