sc/inc/spellcheckcontext.hxx            |    1 +
 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/spellcheckcontext.cxx |    7 +++++++
 sc/source/ui/view/tabview.cxx           |   10 +++++++++-
 sc/source/ui/view/tabview5.cxx          |    7 ++++++-
 7 files changed, 29 insertions(+), 9 deletions(-)

New commits:
commit 65f42a4540d495a11d255af63c7ee15397b57bfa
Author:     Michael Meeks <michael.me...@collabora.com>
AuthorDate: Thu Oct 22 19:45:16 2020 +0100
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Oct 28 13:08:15 2020 +0100

    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/+/104706
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/inc/spellcheckcontext.hxx b/sc/inc/spellcheckcontext.hxx
index 684b2ceb9edc..ac2b19141360 100644
--- a/sc/inc/spellcheckcontext.hxx
+++ b/sc/inc/spellcheckcontext.hxx
@@ -43,6 +43,7 @@ class SpellCheckContext
 public:
     SpellCheckContext(ScDocument* pDocument, SCTAB nTab);
     ~SpellCheckContext();
+    void dispose();
 
     bool isMisspelled(SCCOL nCol, SCROW nRow) const;
     const std::vector<editeng::MisspellRanges>* getMisspellRanges(SCCOL nCol, 
SCROW nRow) const;
diff --git a/sc/source/ui/inc/gridwin.hxx b/sc/source/ui/inc/gridwin.hxx
index d9c0606b2dd2..448c33ba6b10 100644
--- a/sc/source/ui/inc/gridwin.hxx
+++ b/sc/source/ui/inc/gridwin.hxx
@@ -145,7 +145,7 @@ class SAL_DLLPUBLIC_RTTI ScGridWindow : public vcl::Window, 
public DropTargetHel
     // zoom levels demanded from a ScGridWindow instance.
     std::vector<LOKCursorEntry> maLOKLastCursor;
 
-    std::unique_ptr<sc::SpellCheckContext> mpSpellCheckCxt;
+    std::shared_ptr<sc::SpellCheckContext> mpSpellCheckCxt;
 
     ScViewData&             mrViewData;
     ScSplitPos              eWhich;
@@ -433,7 +433,7 @@ public:
 
     void CursorChanged();
     void DrawLayerCreated();
-    void EnableAutoSpell( bool bEnable );
+    void SetAutoSpellContext( const std::shared_ptr<sc::SpellCheckContext> 
&ctx );
     void ResetAutoSpell();
     void ResetAutoSpellForContentChange();
     void SetAutoSpellData( SCCOL nPosX, SCROW nPosY, const 
std::vector<editeng::MisspellRanges>* pRanges );
diff --git a/sc/source/ui/inc/tabview.hxx b/sc/source/ui/inc/tabview.hxx
index a716763f1d73..17809c51fdc8 100644
--- a/sc/source/ui/inc/tabview.hxx
+++ b/sc/source/ui/inc/tabview.hxx
@@ -156,6 +156,8 @@ private:
     VclPtr<ScCornerButton>      aTopButton;
     VclPtr<ScrollBarBox>        aScrollBarBox;
 
+    std::shared_ptr<sc::SpellCheckContext> mpSpellCheckCxt;
+
     std::unique_ptr<sdr::overlay::OverlayObjectList> mxInputHintOO; // help 
hint for data validation
 
     std::unique_ptr<ScPageBreakData>  pPageBreakData;
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 07a4a8317bac..67b815bfc1c1 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -5501,12 +5501,9 @@ void ScGridWindow::DrawLayerCreated()
     ImpCreateOverlayObjects();
 }
 
-void ScGridWindow::EnableAutoSpell( bool bEnable )
+void ScGridWindow::SetAutoSpellContext( const 
std::shared_ptr<sc::SpellCheckContext> &ctx )
 {
-    if (bEnable)
-        mpSpellCheckCxt.reset(new 
sc::SpellCheckContext(&mrViewData.GetDocument(), mrViewData.GetTabNo()));
-    else
-        mpSpellCheckCxt.reset();
+    mpSpellCheckCxt = ctx;
 }
 
 void ScGridWindow::ResetAutoSpell()
diff --git a/sc/source/ui/view/spellcheckcontext.cxx 
b/sc/source/ui/view/spellcheckcontext.cxx
index 6ff81468c5b1..026c0c5a7968 100644
--- a/sc/source/ui/view/spellcheckcontext.cxx
+++ b/sc/source/ui/view/spellcheckcontext.cxx
@@ -202,6 +202,13 @@ SpellCheckContext::~SpellCheckContext()
 {
 }
 
+void SpellCheckContext::dispose()
+{
+    mpEngine.reset();
+    mpCache.reset();
+    pDoc = nullptr;
+}
+
 bool SpellCheckContext::isMisspelled(SCCOL nCol, SCROW nRow) const
 {
     const_cast<SpellCheckContext*>(this)->ensureResults(nCol, nRow);
diff --git a/sc/source/ui/view/tabview.cxx b/sc/source/ui/view/tabview.cxx
index 2f4a407aca5c..dd7e152f0e93 100644
--- a/sc/source/ui/view/tabview.cxx
+++ b/sc/source/ui/view/tabview.cxx
@@ -46,6 +46,7 @@
 #include <viewuno.hxx>
 #include <appoptio.hxx>
 #include <attrib.hxx>
+#include <spellcheckcontext.hxx>
 #include <comphelper/lok.hxx>
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <sfx2/lokhelper.hxx>
@@ -2234,12 +2235,19 @@ void ScTabView::EnableRefInput(bool bFlag)
 
 void ScTabView::EnableAutoSpell( bool bEnable )
 {
+    if (bEnable)
+        mpSpellCheckCxt =
+            std::make_shared<sc::SpellCheckContext>(&aViewData.GetDocument(),
+                                      aViewData.GetTabNo());
+    else
+        mpSpellCheckCxt.reset();
+
     for (VclPtr<ScGridWindow> & 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 73727a0f13d4..c41f08b0aca1 100644
--- a/sc/source/ui/view/tabview5.cxx
+++ b/sc/source/ui/view/tabview5.cxx
@@ -46,6 +46,7 @@
 #include <docsh.hxx>
 #include <viewuno.hxx>
 #include <postit.hxx>
+#include <spellcheckcontext.hxx>
 
 #include <vcl/settings.hxx>
 
@@ -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();
@@ -268,9 +273,9 @@ void ScTabView::DoAddWin( ScGridWindow* pWin )
     if (pDrawView)
     {
         pDrawView->AddWindowToPaintView(pWin, nullptr);
-
         pWin->DrawLayerCreated();
     }
+    pWin->SetAutoSpellContext(mpSpellCheckCxt);
 }
 
 void ScTabView::TabChanged( bool bSameTabButMoved )
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to