From 1a356dc0262022f8c0880d992f628507fdca408e Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Thu, 22 Oct 2020 19:45:16 +0100 Subject: tdf#136694 - share spelling context across all ScGridWindows. Adding new ScGridWindows later (as we do for split panes) didn't call EnableAutoSpell on them; also duplicating the spell-checking cache looks wasteful, so share it. Change-Id: Ieb67bb292590a097bb5a59d369416a094c54c954 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104704 Tested-by: Jenkins CollaboraOffice Reviewed-by: Michael Meeks --- sc/source/ui/inc/gridwin.hxx | 4 ++-- sc/source/ui/inc/tabview.hxx | 2 ++ sc/source/ui/view/gridwin.cxx | 7 ++----- sc/source/ui/view/tabview.cxx | 10 +++++++++- sc/source/ui/view/tabview5.cxx | 7 ++++++- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/sc/source/ui/inc/gridwin.hxx b/sc/source/ui/inc/gridwin.hxx index 5623a0c92d11..a576375283b9 100644 --- a/sc/source/ui/inc/gridwin.hxx +++ b/sc/source/ui/inc/gridwin.hxx @@ -142,7 +142,7 @@ class SAL_DLLPUBLIC_RTTI ScGridWindow : public vcl::Window, public DropTargetHel // zoom levels demanded from a ScGridWindow instance. std::vector maLOKLastCursor; - std::unique_ptr mpSpellCheckCxt; + std::shared_ptr mpSpellCheckCxt; ScViewData* pViewData; ScSplitPos const eWhich; @@ -428,7 +428,7 @@ public: void CursorChanged(); void DrawLayerCreated(); - void EnableAutoSpell( bool bEnable ); + void SetAutoSpellContext( const std::shared_ptr &ctx ); void ResetAutoSpell(); void ResetAutoSpellForContentChange(); void SetAutoSpellData( SCCOL nPosX, SCROW nPosY, const std::vector* pRanges ); diff --git a/sc/source/ui/inc/tabview.hxx b/sc/source/ui/inc/tabview.hxx index 287513af1e00..25185b1ca559 100644 --- a/sc/source/ui/inc/tabview.hxx +++ b/sc/source/ui/inc/tabview.hxx @@ -163,6 +163,8 @@ private: VclPtr aTopButton; VclPtr aScrollBarBox; + std::shared_ptr mpSpellCheckCxt; + std::unique_ptr mxInputHintOO; // help hint for data validation std::unique_ptr pPageBreakData; diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx index 569395c99d6b..9dfca179a4ed 100644 --- a/sc/source/ui/view/gridwin.cxx +++ b/sc/source/ui/view/gridwin.cxx @@ -5528,12 +5528,9 @@ void ScGridWindow::DrawLayerCreated() ImpCreateOverlayObjects(); } -void ScGridWindow::EnableAutoSpell( bool bEnable ) +void ScGridWindow::SetAutoSpellContext( const std::shared_ptr &ctx ) { - if (bEnable) - mpSpellCheckCxt.reset(new sc::SpellCheckContext(pViewData->GetDocument(), pViewData->GetTabNo())); - else - mpSpellCheckCxt.reset(); + mpSpellCheckCxt = ctx; } void ScGridWindow::ResetAutoSpell() diff --git a/sc/source/ui/view/tabview.cxx b/sc/source/ui/view/tabview.cxx index 2c6dd86e368d..1f924ddaf8f9 100644 --- a/sc/source/ui/view/tabview.cxx +++ b/sc/source/ui/view/tabview.cxx @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -2237,12 +2238,19 @@ void ScTabView::EnableRefInput(bool bFlag) void ScTabView::EnableAutoSpell( bool bEnable ) { + if (bEnable) + mpSpellCheckCxt.reset( + new sc::SpellCheckContext(aViewData.GetDocument(), + aViewData.GetTabNo())); + else + mpSpellCheckCxt.reset(); + for (VclPtr & pWin : pGridWin) { if (!pWin) continue; - pWin->EnableAutoSpell(bEnable); + pWin->SetAutoSpellContext(mpSpellCheckCxt); } } diff --git a/sc/source/ui/view/tabview5.cxx b/sc/source/ui/view/tabview5.cxx index e504cf231698..a81772131d12 100644 --- a/sc/source/ui/view/tabview5.cxx +++ b/sc/source/ui/view/tabview5.cxx @@ -46,6 +46,7 @@ #include #include #include +#include #include @@ -193,6 +194,10 @@ ScTabView::~ScTabView() pSelEngine.reset(); + if (mpSpellCheckCxt) + mpSpellCheckCxt->dispose(); + mpSpellCheckCxt.reset(); + mxInputHintOO.reset(); for (i=0; i<4; i++) pGridWin[i].disposeAndClear(); @@ -269,9 +274,9 @@ void ScTabView::DoAddWin( ScGridWindow* pWin ) if (pDrawView) { pDrawView->AddWindowToPaintView(pWin, nullptr); - pWin->DrawLayerCreated(); } + pWin->SetAutoSpellContext(mpSpellCheckCxt); } void ScTabView::TabChanged( bool bSameTabButMoved ) -- cgit