sc/inc/spellcheckcontext.hxx            |   27 +++++-
 sc/source/ui/app/inputhdl.cxx           |    8 +
 sc/source/ui/app/uiitems.cxx            |    9 --
 sc/source/ui/inc/gridwin.hxx            |    5 -
 sc/source/ui/inc/output.hxx             |    3 
 sc/source/ui/inc/tabview.hxx            |    2 
 sc/source/ui/inc/uiitems.hxx            |   11 --
 sc/source/ui/view/gridwin.cxx           |   10 +-
 sc/source/ui/view/output2.cxx           |    9 --
 sc/source/ui/view/spellcheckcontext.cxx |  137 +++++++++++++++-----------------
 sc/source/ui/view/tabview.cxx           |    4 
 sc/source/ui/view/viewfun2.cxx          |   51 +++++------
 12 files changed, 149 insertions(+), 127 deletions(-)

New commits:
commit 9a1f131a124cc6620c2423da5867985300962a42
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Thu Mar 6 17:26:03 2025 +0000
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Fri Mar 7 16:25:21 2025 +0100

    cool#11258 move Language into the cache key
    
    setMisspellRanges complicates things somewhat, so return the
    cell language from getMisspellRanges and propogate that along
    with the misspelled range so SetAutoSpellData can transport
    the Language back to setMisspellRanges
    
    Presumably we can assume that the cell language in
    ScInputHandler::EnterHandler2 is that of the EditEngine for
    the case of freshly created MisspellRanges.
    
    https://github.com/CollaboraOnline/online/issues/11258
    
    Change-Id: I93bb869eacbab8ebec875e891d1ed42512cdf9a7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182627
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sc/inc/spellcheckcontext.hxx b/sc/inc/spellcheckcontext.hxx
index f068d91f5181..dc5f09449039 100644
--- a/sc/inc/spellcheckcontext.hxx
+++ b/sc/inc/spellcheckcontext.hxx
@@ -21,6 +21,28 @@ class ScTabEditEngine;
 
 namespace sc
 {
+typedef std::vector<editeng::MisspellRanges> MisspellRangesVec;
+
+struct MisspellRangeResult
+{
+    const MisspellRangesVec* mpRanges;
+    LanguageType meCellLang;
+
+    MisspellRangeResult()
+        : mpRanges(nullptr)
+        , meCellLang(LANGUAGE_DONTKNOW)
+    {
+    }
+
+    MisspellRangeResult(const MisspellRangesVec* pRanges, LanguageType 
eCellLang)
+        : mpRanges(pRanges)
+        , meCellLang(eCellLang)
+    {
+    }
+
+    bool HasRanges() const { return mpRanges != nullptr; }
+};
+
 /**
  * Class shared between grid windows to cache
  * spelling results.
@@ -45,9 +67,8 @@ public:
     void dispose();
 
     bool isMisspelled(SCCOL nCol, SCROW nRow) const;
-    const std::vector<editeng::MisspellRanges>* getMisspellRanges(SCCOL nCol, 
SCROW nRow) const;
-    void setMisspellRanges(SCCOL nCol, SCROW nRow,
-                           const std::vector<editeng::MisspellRanges>* 
pRanges);
+    MisspellRangeResult getMisspellRanges(SCCOL nCol, SCROW nRow) const;
+    void setMisspellRanges(SCCOL nCol, SCROW nRow, const MisspellRangeResult& 
rRangeResult);
 
     void reset();
     void resetForContentChange();
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index edeaca798434..0f3433a0050b 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -3471,8 +3471,14 @@ void ScInputHandler::EnterHandler2(ScEnterMode 
nBlockMode, bool bForget, OUStrin
             ScInputStatusItem aItemCorrected(FID_INPUTLINE_STATUS,
                                              aCursorPos, aCursorPos, 
aCursorPos,
                                              aString, pObject.get());
+
+            sc::MisspellRangeResult aMisspellRangeResult;
             if ( !aMisspellRanges.empty() )
-                aItemCorrected.SetMisspellRanges(&aMisspellRanges);
+            {
+                aMisspellRangeResult.meCellLang = 
mpEditEngine->GetDefaultLanguage();
+                aMisspellRangeResult.mpRanges = &aMisspellRanges;
+                aItemCorrected.SetMisspellRanges(aMisspellRangeResult);
+            }
 
             aArgs[0] = &aItemCorrected;
             rBindings.Execute(nId, aArgs);
diff --git a/sc/source/ui/app/uiitems.cxx b/sc/source/ui/app/uiitems.cxx
index bddd0c689aea..4b6275a59146 100644
--- a/sc/source/ui/app/uiitems.cxx
+++ b/sc/source/ui/app/uiitems.cxx
@@ -38,8 +38,7 @@ ScInputStatusItem::ScInputStatusItem(
     aStartPos   ( rStartPos ),
     aEndPos     ( rEndPos ),
     aString     (std::move( _aString )),
-    pEditData   ( pData ? pData->Clone() : nullptr ),
-    mpMisspellRanges(nullptr)
+    pEditData   ( pData ? pData->Clone() : nullptr )
 {
 }
 
@@ -50,7 +49,7 @@ ScInputStatusItem::ScInputStatusItem( const 
ScInputStatusItem& rItem ) :
     aEndPos     ( rItem.aEndPos ),
     aString     ( rItem.aString ),
     pEditData   ( rItem.pEditData ? rItem.pEditData->Clone() : nullptr ),
-    mpMisspellRanges(rItem.mpMisspellRanges)
+    maMisspellRanges(rItem.maMisspellRanges)
 {
 }
 
@@ -74,9 +73,9 @@ ScInputStatusItem* ScInputStatusItem::Clone( SfxItemPool * ) 
const
     return new ScInputStatusItem( *this );
 }
 
-void ScInputStatusItem::SetMisspellRanges( const 
std::vector<editeng::MisspellRanges>* pRanges )
+void ScInputStatusItem::SetMisspellRanges( const sc::MisspellRangeResult& 
rRanges )
 {
-    mpMisspellRanges = pRanges;
+    maMisspellRanges = rRanges;
 }
 
 // ScPaintHint was moved to hints.cxx
diff --git a/sc/source/ui/inc/gridwin.hxx b/sc/source/ui/inc/gridwin.hxx
index 66f7067081eb..d347c32900c2 100644
--- a/sc/source/ui/inc/gridwin.hxx
+++ b/sc/source/ui/inc/gridwin.hxx
@@ -38,6 +38,7 @@ namespace editeng {
 }
 
 namespace sc {
+    struct MisspellRangeResult;
     class SpellCheckContext;
 }
 
@@ -476,8 +477,8 @@ public:
     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 );
-    const std::vector<editeng::MisspellRanges>* GetAutoSpellData( SCCOL nPosX, 
SCROW nPosY );
+    void SetAutoSpellData( SCCOL nPosX, SCROW nPosY, const 
sc::MisspellRangeResult& rRangeResult );
+    sc::MisspellRangeResult GetAutoSpellData( SCCOL nPosX, SCROW nPosY );
     bool InsideVisibleRange( SCCOL nPosX, SCROW nPosY );
 
     void UpdateSparklineGroupOverlay();
diff --git a/sc/source/ui/inc/output.hxx b/sc/source/ui/inc/output.hxx
index d3d51f52fcc4..3c6ebf6cf765 100644
--- a/sc/source/ui/inc/output.hxx
+++ b/sc/source/ui/inc/output.hxx
@@ -21,6 +21,7 @@
 
 #include <address.hxx>
 #include <cellvalue.hxx>
+#include <spellcheckcontext.hxx>
 #include <tools/color.hxx>
 #include <tools/fract.hxx>
 #include <tools/gen.hxx>
@@ -153,7 +154,7 @@ private:
         const SfxItemSet*       mpOldCondSet;
         const SfxItemSet*       mpOldPreviewFontSet;
         RowInfo*                mpThisRowInfo;
-        const std::vector<editeng::MisspellRanges>* mpMisspellRanges;
+        sc::MisspellRangeResult maMisspellRanges;
 
         explicit DrawEditParam(const ScPatternAttr* pPattern, const 
SfxItemSet* pCondSet, bool bCellIsValue);
 
diff --git a/sc/source/ui/inc/tabview.hxx b/sc/source/ui/inc/tabview.hxx
index 5f6dd33668d1..22fe2655f71a 100644
--- a/sc/source/ui/inc/tabview.hxx
+++ b/sc/source/ui/inc/tabview.hxx
@@ -622,7 +622,7 @@ public:
     void EnableAutoSpell( bool bEnable );
     void ResetAutoSpell();
     void ResetAutoSpellForContentChange();
-    void SetAutoSpellData( SCCOL nPosX, SCROW nPosY, const 
std::vector<editeng::MisspellRanges>* pRanges );
+    void SetAutoSpellData( SCCOL nPosX, SCROW nPosY, const 
sc::MisspellRangeResult& rRangeResult );
     /// @see ScModelObj::getRowColumnHeaders().
     void getRowColumnHeaders(const tools::Rectangle& rRectangle, 
tools::JsonWriter& rJsonWriter);
     /// @see ScModelObj::getSheetGeometryData()
diff --git a/sc/source/ui/inc/uiitems.hxx b/sc/source/ui/inc/uiitems.hxx
index dcab506e64b6..9dfcc713150a 100644
--- a/sc/source/ui/inc/uiitems.hxx
+++ b/sc/source/ui/inc/uiitems.hxx
@@ -21,6 +21,7 @@
 
 #include <scdllapi.h>
 #include <sortparam.hxx>
+#include <spellcheckcontext.hxx>
 #include <subtotalparam.hxx>
 #include <paramisc.hxx>
 #include <svl/poolitem.hxx>
@@ -28,10 +29,6 @@
 #include <memory>
 #include <vector>
 
-namespace editeng {
-    struct MisspellRanges;
-}
-
 class ScEditEngineDefaulter;
 class EditTextObject;
 class ScViewData;
@@ -47,7 +44,7 @@ class ScInputStatusItem : public SfxPoolItem
     ScAddress           aEndPos;
     OUString            aString;
     std::unique_ptr<EditTextObject>             pEditData;
-    const std::vector<editeng::MisspellRanges>* mpMisspellRanges;
+    sc::MisspellRangeResult maMisspellRanges;
 
 public:
 
@@ -69,8 +66,8 @@ public:
     const OUString&         GetString() const   { return aString; }
     const EditTextObject*   GetEditData() const { return pEditData.get(); }
 
-    void SetMisspellRanges( const std::vector<editeng::MisspellRanges>* 
pRanges );
-    const std::vector<editeng::MisspellRanges>* GetMisspellRanges() const { 
return mpMisspellRanges;}
+    void SetMisspellRanges( const sc::MisspellRangeResult& rRanges );
+    const sc::MisspellRangeResult& GetMisspellRanges() const { return 
maMisspellRanges;}
 };
 
 #define SC_TAB_INSERTED     1
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 986a3119caa6..dba7a7165152 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -6103,21 +6103,21 @@ void ScGridWindow::ResetAutoSpellForContentChange()
         mpSpellCheckCxt->resetForContentChange();
 }
 
-void ScGridWindow::SetAutoSpellData( SCCOL nPosX, SCROW nPosY, const 
std::vector<editeng::MisspellRanges>* pRanges )
+void ScGridWindow::SetAutoSpellData( SCCOL nPosX, SCROW nPosY, const 
sc::MisspellRangeResult& rRangeResult )
 {
     if (!mpSpellCheckCxt)
         return;
 
-    mpSpellCheckCxt->setMisspellRanges(nPosX, nPosY, pRanges);
+    mpSpellCheckCxt->setMisspellRanges(nPosX, nPosY, rRangeResult);
 }
 
-const std::vector<editeng::MisspellRanges>* ScGridWindow::GetAutoSpellData( 
SCCOL nPosX, SCROW nPosY )
+sc::MisspellRangeResult ScGridWindow::GetAutoSpellData( SCCOL nPosX, SCROW 
nPosY )
 {
     if (!mpSpellCheckCxt)
-        return nullptr;
+        return {};
 
     if (!maVisibleRange.isInside(nPosX, nPosY))
-        return nullptr;
+        return {};
 
     return mpSpellCheckCxt->getMisspellRanges(nPosX, nPosY);
 }
diff --git a/sc/source/ui/view/output2.cxx b/sc/source/ui/view/output2.cxx
index 4dda4290bc09..6f08e3f2de8d 100644
--- a/sc/source/ui/view/output2.cxx
+++ b/sc/source/ui/view/output2.cxx
@@ -2489,8 +2489,7 @@ ScOutputData::DrawEditParam::DrawEditParam(const 
ScPatternAttr* pPattern, const
     mpOldPattern(nullptr),
     mpOldCondSet(nullptr),
     mpOldPreviewFontSet(nullptr),
-    mpThisRowInfo(nullptr),
-    mpMisspellRanges(nullptr)
+    mpThisRowInfo(nullptr)
 {}
 
 bool ScOutputData::DrawEditParam::readCellContent(
@@ -2534,8 +2533,8 @@ bool ScOutputData::DrawEditParam::readCellContent(
             lcl_SetEditColor( *mpEngine, *pColor );
     }
 
-    if (mpMisspellRanges)
-        mpEngine->SetAllMisspellRanges(*mpMisspellRanges);
+    if (maMisspellRanges.mpRanges)
+        mpEngine->SetAllMisspellRanges(*maMisspellRanges.mpRanges);
 
     return true;
 }
@@ -4600,7 +4599,7 @@ void ScOutputData::DrawEdit(bool bPixelToLogic)
                         aParam.mpOldPreviewFontSet = pOldPreviewFontSet;
                         aParam.mpThisRowInfo = pThisRowInfo;
                         if (mpSpellCheckCxt)
-                            aParam.mpMisspellRanges = 
mpSpellCheckCxt->getMisspellRanges(nCellX, nCellY);
+                            aParam.maMisspellRanges = 
mpSpellCheckCxt->getMisspellRanges(nCellX, nCellY);
 
                         if (aParam.meHorJustAttr == SvxCellHorJustify::Repeat)
                         {
diff --git a/sc/source/ui/view/spellcheckcontext.cxx 
b/sc/source/ui/view/spellcheckcontext.cxx
index 890940531874..f3145855f8b5 100644
--- a/sc/source/ui/view/spellcheckcontext.cxx
+++ b/sc/source/ui/view/spellcheckcontext.cxx
@@ -56,28 +56,53 @@ class SpellCheckContext::SpellCheckCache
 
     };
 
-    typedef std::vector<editeng::MisspellRanges> MisspellType;
-    typedef std::unordered_map<CellPos, std::unique_ptr<MisspellType>, 
CellPos::Hash> CellMapType;
-    typedef std::unordered_map<const rtl_uString*, 
std::unique_ptr<MisspellType>> SharedStringMapType;
-    typedef std::unordered_map<CellPos, LanguageType, CellPos::Hash> 
CellLangMapType;
+    struct LangSharedString
+    {
+        struct Hash
+        {
+            size_t operator() (const LangSharedString& rKey) const
+            {
+                std::size_t seed = 0;
+                o3tl::hash_combine(seed, rKey.meLang.get());
+                o3tl::hash_combine(seed, rKey.mpString);
+                return seed;
+            }
+        };
+
+        LanguageType meLang;
+        const rtl_uString* mpString;
+
+        LangSharedString(LanguageType eLang, const ScRefCellValue& rCell)
+            : meLang(eLang)
+            , mpString(rCell.getSharedString()->getData())
+        {
+        }
+
+        bool operator== (const LangSharedString& r) const
+        {
+            return meLang == r.meLang && mpString == r.mpString;
+        }
+    };
+
+    typedef std::unordered_map<CellPos, std::unique_ptr<MisspellRangesVec>, 
CellPos::Hash> CellMapType;
+    typedef std::unordered_map<LangSharedString, 
std::unique_ptr<MisspellRangesVec>, LangSharedString::Hash> SharedStringMapType;
 
     SharedStringMapType  maStringMisspells;
     CellMapType          maEditTextMisspells;
-    CellLangMapType      maCellLanguages;
-    LanguageType         meDefCellLanguage;
 
 public:
 
-    SpellCheckCache(LanguageType eDefaultCellLanguage) : 
meDefCellLanguage(eDefaultCellLanguage)
+    SpellCheckCache()
     {
     }
 
-    bool query(SCCOL nCol, SCROW nRow, const ScRefCellValue& rCell, 
MisspellType*& rpRanges) const
+    bool query(SCCOL nCol, SCROW nRow, LanguageType eLang,
+               const ScRefCellValue& rCell, MisspellRangesVec*& rpRanges) const
     {
         CellType eType = rCell.getType();
         if (eType == CELLTYPE_STRING)
         {
-            SharedStringMapType::const_iterator it = 
maStringMisspells.find(rCell.getSharedString()->getData());
+            SharedStringMapType::const_iterator it = 
maStringMisspells.find(LangSharedString(eLang, rCell));
             if (it == maStringMisspells.end())
                 return false; // Not available
 
@@ -99,38 +124,22 @@ public:
         return true;
     }
 
-    void set(SCCOL nCol, SCROW nRow, const ScRefCellValue& rCell, 
std::unique_ptr<MisspellType> pRanges)
+    void set(SCCOL nCol, SCROW nRow, LanguageType eLang,
+             const ScRefCellValue& rCell, std::unique_ptr<MisspellRangesVec> 
pRanges)
     {
         CellType eType = rCell.getType();
         if (eType == CELLTYPE_STRING)
-            
maStringMisspells.insert_or_assign(rCell.getSharedString()->getData(), 
std::move(pRanges));
+        {
+            maStringMisspells.insert_or_assign(LangSharedString(eLang, rCell), 
std::move(pRanges));
+        }
         else if (eType == CELLTYPE_EDIT)
             maEditTextMisspells.insert_or_assign(CellPos(nCol, nRow), 
std::move(pRanges));
     }
 
-    LanguageType getLanguage(SCCOL nCol, SCROW nRow) const
-    {
-        CellLangMapType::const_iterator it = 
maCellLanguages.find(CellPos(nCol, nRow));
-        if (it == maCellLanguages.end())
-            return meDefCellLanguage;
-
-        return it->second;
-    }
-
-    void setLanguage(LanguageType eCellLang, SCCOL nCol, SCROW nRow)
-    {
-        if (eCellLang == meDefCellLanguage)
-            maCellLanguages.erase(CellPos(nCol, nRow));
-        else
-            maCellLanguages.insert_or_assign(CellPos(nCol, nRow), eCellLang);
-    }
-
-    void clear(LanguageType eDefaultCellLanguage)
+    void clear()
     {
         maStringMisspells.clear();
         maEditTextMisspells.clear();
-        maCellLanguages.clear();
-        meDefCellLanguage = eDefaultCellLanguage;
     }
 
     void clearEditTextMap()
@@ -159,31 +168,31 @@ struct SpellCheckContext::SpellCheckResult
 {
     SCCOL mnCol;
     SCROW mnRow;
-    const std::vector<editeng::MisspellRanges>* pRanges;
+    MisspellRangeResult maRanges;
 
-    SpellCheckResult() : mnCol(-1), mnRow(-1), pRanges(nullptr) {}
+    SpellCheckResult() : mnCol(-1), mnRow(-1) {}
 
-    void set(SCCOL nCol, SCROW nRow, const 
std::vector<editeng::MisspellRanges>* pMisspells)
+    void set(SCCOL nCol, SCROW nRow, const MisspellRangeResult& rMisspells)
     {
         mnCol = nCol;
         mnRow = nRow;
-        pRanges = pMisspells;
+        maRanges = rMisspells;
     }
 
-    const std::vector<editeng::MisspellRanges>* query(SCCOL nCol, SCROW nRow) 
const
+    MisspellRangeResult query(SCCOL nCol, SCROW nRow) const
     {
         assert(mnCol == nCol);
         assert(mnRow == nRow);
         (void)nCol;
         (void)nRow;
-        return pRanges;
+        return maRanges;
     }
 
     void clear()
     {
         mnCol = -1;
         mnRow = -1;
-        pRanges = nullptr;
+        maRanges = {};
     }
 };
 
@@ -217,10 +226,10 @@ void SpellCheckContext::setTabNo(SCTAB nTab)
 bool SpellCheckContext::isMisspelled(SCCOL nCol, SCROW nRow) const
 {
     const_cast<SpellCheckContext*>(this)->ensureResults(nCol, nRow);
-    return mpResult->query(nCol, nRow);
+    return mpResult->query(nCol, nRow).mpRanges;
 }
 
-const std::vector<editeng::MisspellRanges>* 
SpellCheckContext::getMisspellRanges(
+sc::MisspellRangeResult SpellCheckContext::getMisspellRanges(
     SCCOL nCol, SCROW nRow ) const
 {
     const_cast<SpellCheckContext*>(this)->ensureResults(nCol, nRow);
@@ -228,7 +237,7 @@ const std::vector<editeng::MisspellRanges>* 
SpellCheckContext::getMisspellRanges
 }
 
 void SpellCheckContext::setMisspellRanges(
-    SCCOL nCol, SCROW nRow, const std::vector<editeng::MisspellRanges>* 
pRanges )
+    SCCOL nCol, SCROW nRow, const sc::MisspellRangeResult& rRangeResult )
 {
     if (!mpEngine || !mpCache)
         reset();
@@ -239,9 +248,9 @@ void SpellCheckContext::setMisspellRanges(
     if (eType != CELLTYPE_STRING && eType != CELLTYPE_EDIT)
         return;
 
-    typedef std::vector<editeng::MisspellRanges> MisspellType;
-    std::unique_ptr<MisspellType> pMisspells(pRanges ? new 
MisspellType(*pRanges) : nullptr);
-    mpCache->set(nCol, nRow, aCell, std::move(pMisspells));
+    const MisspellRangesVec* pRanges = rRangeResult.mpRanges;
+    std::unique_ptr<MisspellRangesVec> pMisspells(pRanges ? new 
MisspellRangesVec(*pRanges) : nullptr);
+    mpCache->set(nCol, nRow, rRangeResult.meCellLang, aCell, 
std::move(pMisspells));
 }
 
 void SpellCheckContext::reset()
@@ -274,7 +283,7 @@ void SpellCheckContext::ensureResults(SCCOL nCol, SCROW 
nRow)
             ScRangeList aPivotRanges = pDPs->GetAllTableRanges(mnTab);
             if (aPivotRanges.Contains(ScRange(ScAddress(nCol, nRow, mnTab)))) 
// Don't spell check within pivot tables
             {
-                mpResult->set(nCol, nRow, nullptr);
+                mpResult->set(nCol, nRow, {});
                 return;
             }
         }
@@ -286,7 +295,7 @@ void SpellCheckContext::ensureResults(SCCOL nCol, SCROW 
nRow)
     if (eType != CELLTYPE_STRING && eType != CELLTYPE_EDIT)
     {
         // No spell-check required.
-        mpResult->set(nCol, nRow, nullptr);
+        mpResult->set(nCol, nRow, {});
         return;
     }
 
@@ -303,27 +312,17 @@ void SpellCheckContext::ensureResults(SCCOL nCol, SCROW 
nRow)
 
     if (eCellLang == LANGUAGE_NONE)
     {
-        mpResult->set(nCol, nRow, nullptr); // No need to spell check this 
cell.
+        mpResult->set(nCol, nRow, {}); // No need to spell check this cell.
         return;
     }
 
-    typedef std::vector<editeng::MisspellRanges> MisspellType;
-
-    LanguageType eCachedCellLang = mpCache->getLanguage(nCol, nRow);
-
-    if (eCellLang != eCachedCellLang)
-        mpCache->setLanguage(eCellLang, nCol, nRow);
-
-    else
+    MisspellRangesVec* pCacheRanges = nullptr;
+    bool bFound = mpCache->query(nCol, nRow, eCellLang, aCell, pCacheRanges);
+    if (bFound)
     {
-        MisspellType* pRanges = nullptr;
-        bool bFound = mpCache->query(nCol, nRow, aCell, pRanges);
-        if (bFound)
-        {
-            // Cache hit.
-            mpResult->set(nCol, nRow, pRanges);
-            return;
-        }
+        // Cache hit.
+        mpResult->set(nCol, nRow, MisspellRangeResult(pCacheRanges, 
eCellLang));
+        return;
     }
 
     // Cache miss, the cell needs spell-check..
@@ -337,10 +336,10 @@ void SpellCheckContext::ensureResults(SCCOL nCol, SCROW 
nRow)
 
     mpStatus->mbModified = false;
     mpEngine->CompleteOnlineSpelling();
-    std::unique_ptr<MisspellType> pRanges;
+    std::unique_ptr<MisspellRangesVec> pRanges;
     if (mpStatus->mbModified)
     {
-        pRanges.reset(new MisspellType);
+        pRanges.reset(new MisspellRangesVec);
         mpEngine->GetAllMisspellRanges(*pRanges);
 
         if (pRanges->empty())
@@ -348,8 +347,8 @@ void SpellCheckContext::ensureResults(SCCOL nCol, SCROW 
nRow)
     }
     // else : No change in status for EditStatusFlags::WRONGWORDCHANGED => no 
spell errors (which is the default status).
 
-    mpResult->set(nCol, nRow, pRanges.get());
-    mpCache->set(nCol, nRow, aCell, std::move(pRanges));
+    mpResult->set(nCol, nRow, MisspellRangeResult(pRanges.get(), eCellLang));
+    mpCache->set(nCol, nRow, eCellLang, aCell, std::move(pRanges));
 }
 
 void SpellCheckContext::resetCache(bool bContentChangeOnly)
@@ -360,11 +359,11 @@ void SpellCheckContext::resetCache(bool 
bContentChangeOnly)
         mpResult->clear();
 
     if (!mpCache)
-        mpCache.reset(new SpellCheckCache(meLanguage));
+        mpCache.reset(new SpellCheckCache);
     else if (bContentChangeOnly)
         mpCache->clearEditTextMap();
     else
-        mpCache->clear(meLanguage);
+        mpCache->clear();
 }
 
 void SpellCheckContext::setup()
diff --git a/sc/source/ui/view/tabview.cxx b/sc/source/ui/view/tabview.cxx
index fcb156e60d24..ebe61fa63938 100644
--- a/sc/source/ui/view/tabview.cxx
+++ b/sc/source/ui/view/tabview.cxx
@@ -2543,14 +2543,14 @@ void ScTabView::ResetAutoSpellForContentChange()
     }
 }
 
-void ScTabView::SetAutoSpellData( SCCOL nPosX, SCROW nPosY, const 
std::vector<editeng::MisspellRanges>* pRanges )
+void ScTabView::SetAutoSpellData( SCCOL nPosX, SCROW nPosY, const 
sc::MisspellRangeResult& rRangeResult )
 {
     for (VclPtr<ScGridWindow> & pWin: pGridWin)
     {
         if (!pWin)
             continue;
 
-        pWin->SetAutoSpellData(nPosX, nPosY, pRanges);
+        pWin->SetAutoSpellData(nPosX, nPosY, rRangeResult);
     }
 }
 
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index 1e8a19021c08..3fad2954ca6c 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -1557,11 +1557,11 @@ void ScViewFunc::CopyAutoSpellData( FillDir eDir, SCCOL 
nStartCol, SCROW nStartR
                         if (eCellType != CELLTYPE_EDIT)
                             continue;
 
-                        const std::vector<editeng::MisspellRanges>* pRanges = 
pWin->GetAutoSpellData(nColItr, nStartRow);
-                        if ( !pRanges )
+                        sc::MisspellRangeResult aRangeResult = 
pWin->GetAutoSpellData(nColItr, nStartRow);
+                        if (!aRangeResult.HasRanges())
                             continue;
                         for ( SCROW nRowItr = nStartRow + 1; nRowItr <= 
nEndRow; ++nRowItr )
-                            pWin->SetAutoSpellData(nColItr, nRowItr, pRanges);
+                            pWin->SetAutoSpellData(nColItr, nRowItr, 
aRangeResult);
                     }
                     break;
                 case FILL_TO_TOP:
@@ -1571,11 +1571,11 @@ void ScViewFunc::CopyAutoSpellData( FillDir eDir, SCCOL 
nStartCol, SCROW nStartR
                         if (eCellType != CELLTYPE_EDIT)
                             continue;
 
-                        const std::vector<editeng::MisspellRanges>* pRanges = 
pWin->GetAutoSpellData(nColItr, nEndRow);
-                        if ( !pRanges )
+                        sc::MisspellRangeResult aRangeResult = 
pWin->GetAutoSpellData(nColItr, nEndRow);
+                        if (!aRangeResult.HasRanges())
                             continue;
                         for ( SCROW nRowItr = nEndRow - 1; nRowItr >= 
nStartRow; --nRowItr )
-                            pWin->SetAutoSpellData(nColItr, nRowItr, pRanges);
+                            pWin->SetAutoSpellData(nColItr, nRowItr, 
aRangeResult);
                     }
                     break;
                 case FILL_TO_RIGHT:
@@ -1585,11 +1585,11 @@ void ScViewFunc::CopyAutoSpellData( FillDir eDir, SCCOL 
nStartCol, SCROW nStartR
                         if (eCellType != CELLTYPE_EDIT)
                             continue;
 
-                        const std::vector<editeng::MisspellRanges>* pRanges = 
pWin->GetAutoSpellData(nStartCol, nRowItr);
-                        if ( !pRanges )
+                        sc::MisspellRangeResult aRangeResult = 
pWin->GetAutoSpellData(nStartCol, nRowItr);
+                        if (!aRangeResult.HasRanges())
                             continue;
                         for ( SCCOL nColItr = nStartCol + 1; nColItr <= 
nEndCol; ++nColItr )
-                            pWin->SetAutoSpellData(nColItr, nRowItr, pRanges);
+                            pWin->SetAutoSpellData(nColItr, nRowItr, 
aRangeResult);
                     }
                     break;
                 case FILL_TO_LEFT:
@@ -1599,23 +1599,22 @@ void ScViewFunc::CopyAutoSpellData( FillDir eDir, SCCOL 
nStartCol, SCROW nStartR
                         if (eCellType != CELLTYPE_EDIT)
                             continue;
 
-                        const std::vector<editeng::MisspellRanges>* pRanges = 
pWin->GetAutoSpellData(nEndCol, nRowItr);
-                        if ( !pRanges )
+                        sc::MisspellRangeResult aRangeResult = 
pWin->GetAutoSpellData(nEndCol, nRowItr);
+                        if (!aRangeResult.HasRanges())
                             continue;
                         for ( SCCOL nColItr = nEndCol - 1; nColItr >= 
nStartCol; --nColItr )
-                            pWin->SetAutoSpellData(nColItr, nRowItr, pRanges);
+                            pWin->SetAutoSpellData(nColItr, nRowItr, 
aRangeResult);
                     }
                     break;
             }
             return;
         }
 
-        typedef const std::vector<editeng::MisspellRanges>* MisspellRangesType;
         SCROW nRowRepeatSize = nEndRow - nStartRow + 1;
         SCCOL nColRepeatSize = nEndCol - nStartCol + 1;
         SCROW nTillRow = 0;
         SCCOL nTillCol = 0;
-        std::vector<std::vector<MisspellRangesType>> 
aSourceSpellRanges(nRowRepeatSize, 
std::vector<MisspellRangesType>(nColRepeatSize, nullptr));
+        std::vector<std::vector<sc::MisspellRangeResult>> 
aSourceSpellRanges(nRowRepeatSize, 
std::vector<sc::MisspellRangeResult>(nColRepeatSize));
 
         for ( SCROW nRowIdx = 0; nRowIdx < nRowRepeatSize; ++nRowIdx )
         {
@@ -1638,10 +1637,10 @@ void ScViewFunc::CopyAutoSpellData( FillDir eDir, SCCOL 
nStartCol, SCROW nStartR
                     for ( SCROW nRowItr = nEndRow + 1; nRowItr <= nTillRow; 
++nRowItr )
                     {
                         size_t nSourceRowIdx = ( nRowItr - nEndRow - 1 ) % 
nRowRepeatSize;
-                        MisspellRangesType pRanges = 
aSourceSpellRanges[nSourceRowIdx][nColItr - nStartCol];
-                        if ( !pRanges )
+                        sc::MisspellRangeResult aRangeResult = 
aSourceSpellRanges[nSourceRowIdx][nColItr - nStartCol];
+                        if (!aRangeResult.HasRanges())
                             continue;
-                        pWin->SetAutoSpellData(nColItr, nRowItr, pRanges);
+                        pWin->SetAutoSpellData(nColItr, nRowItr, aRangeResult);
                     }
                 }
                 break;
@@ -1653,10 +1652,10 @@ void ScViewFunc::CopyAutoSpellData( FillDir eDir, SCCOL 
nStartCol, SCROW nStartR
                     for ( SCROW nRowItr = nStartRow - 1; nRowItr >= nTillRow; 
--nRowItr )
                     {
                         size_t nSourceRowIdx = nRowRepeatSize - 1 - ( ( 
nStartRow - 1 - nRowItr ) % nRowRepeatSize );
-                        MisspellRangesType pRanges = 
aSourceSpellRanges[nSourceRowIdx][nColItr - nStartCol];
-                        if ( !pRanges )
+                        sc::MisspellRangeResult aRangeResult = 
aSourceSpellRanges[nSourceRowIdx][nColItr - nStartCol];
+                        if (!aRangeResult.HasRanges())
                             continue;
-                        pWin->SetAutoSpellData(nColItr, nRowItr, pRanges);
+                        pWin->SetAutoSpellData(nColItr, nRowItr, aRangeResult);
                     }
                 }
                 break;
@@ -1668,10 +1667,10 @@ void ScViewFunc::CopyAutoSpellData( FillDir eDir, SCCOL 
nStartCol, SCROW nStartR
                     size_t nSourceColIdx = ( nColItr - nEndCol - 1 ) % 
nColRepeatSize;
                     for ( SCROW nRowItr = nStartRow; nRowItr <= nEndRow; 
++nRowItr )
                     {
-                        MisspellRangesType pRanges = 
aSourceSpellRanges[nRowItr - nStartRow][nSourceColIdx];
-                        if ( !pRanges )
+                        sc::MisspellRangeResult aRangeResult = 
aSourceSpellRanges[nRowItr - nStartRow][nSourceColIdx];
+                        if (!aRangeResult.HasRanges())
                             continue;
-                        pWin->SetAutoSpellData(nColItr, nRowItr, pRanges);
+                        pWin->SetAutoSpellData(nColItr, nRowItr, aRangeResult);
                     }
                 }
                 break;
@@ -1683,10 +1682,10 @@ void ScViewFunc::CopyAutoSpellData( FillDir eDir, SCCOL 
nStartCol, SCROW nStartR
                     size_t nSourceColIdx = nColRepeatSize - 1 - ( ( nStartCol 
- 1 - nColItr ) % nColRepeatSize );
                     for ( SCROW nRowItr = nStartRow; nRowItr <= nEndRow; 
++nRowItr )
                     {
-                        MisspellRangesType pRanges = 
aSourceSpellRanges[nRowItr - nStartRow][nSourceColIdx];
-                        if ( !pRanges )
+                        sc::MisspellRangeResult aRangeResult = 
aSourceSpellRanges[nRowItr - nStartRow][nSourceColIdx];
+                        if (!aRangeResult.HasRanges())
                             continue;
-                        pWin->SetAutoSpellData(nColItr, nRowItr, pRanges);
+                        pWin->SetAutoSpellData(nColItr, nRowItr, aRangeResult);
                     }
                 }
                 break;

Reply via email to