17#include <document.hxx>
22#include <com/sun/star/linguistic2/XSpellChecker1.hpp>
26#include <unordered_map>
84 rpRanges = it->second.get();
94 rpRanges = it->second.get();
154 if (nStatus & EditStatusFlags::WRONGWORDCHANGED)
162 const std::vector<editeng::MisspellRanges>*
pRanges;
166 void set(
SCCOL nCol,
SCROW nRow,
const std::vector<editeng::MisspellRanges>* pMisspells)
175 assert(
mnCol == nCol);
176 assert(
mnRow == nRow);
190SpellCheckContext::SpellCheckContext(
ScDocument* pDocument,
SCTAB nTab) :
198SpellCheckContext::~SpellCheckContext()
202void SpellCheckContext::dispose()
209void SpellCheckContext::setTabNo(
SCTAB nTab)
217bool SpellCheckContext::isMisspelled(
SCCOL nCol,
SCROW nRow)
const
220 return mpResult->query(nCol, nRow);
223const std::vector<editeng::MisspellRanges>* SpellCheckContext::getMisspellRanges(
227 return mpResult->query(nCol, nRow);
230void SpellCheckContext::setMisspellRanges(
231 SCCOL nCol,
SCROW nRow,
const std::vector<editeng::MisspellRanges>* pRanges )
233 if (!mpEngine || !mpCache)
242 typedef std::vector<editeng::MisspellRanges> MisspellType;
243 std::unique_ptr<MisspellType> pMisspells(pRanges ?
new MisspellType(*pRanges) :
nullptr);
244 mpCache->set(nCol, nRow, aCell, std::move(pMisspells));
247void SpellCheckContext::reset()
255void SpellCheckContext::resetForContentChange()
260void SpellCheckContext::ensureResults(
SCCOL nCol,
SCROW nRow)
262 if (!mpEngine || !mpCache ||
270 if (pDoc->HasPivotTable())
274 ScRangeList aPivotRanges = pDPs->GetAllTableRanges(mnTab);
277 mpResult->set(nCol, nRow,
nullptr);
289 mpResult->set(nCol, nRow,
nullptr);
298 const ScPatternAttr* pPattern = pDoc->GetPattern(nCol, nRow, mnTab);
301 if (eCellLang == LANGUAGE_SYSTEM)
304 if (eCellLang == LANGUAGE_NONE)
306 mpResult->set(nCol, nRow,
nullptr);
310 typedef std::vector<editeng::MisspellRanges> MisspellType;
312 LanguageType eCachedCellLang = mpCache->getLanguage(nCol, nRow);
314 if (eCellLang != eCachedCellLang)
315 mpCache->setLanguage(eCellLang, nCol, nRow);
319 MisspellType* pRanges =
nullptr;
320 bool bFound = mpCache->query(nCol, nRow, aCell, pRanges);
324 mpResult->set(nCol, nRow, pRanges);
331 mpEngine->SetText(aCell.getSharedString()->getString());
333 mpEngine->SetText(*aCell.getEditText());
336 mpEngine->SetDefaultItem(
SvxLanguageItem(eCellLang, EE_CHAR_LANGUAGE));
338 mpStatus->mbModified =
false;
339 mpEngine->CompleteOnlineSpelling();
340 std::unique_ptr<MisspellType> pRanges;
341 if (mpStatus->mbModified)
343 pRanges.reset(
new MisspellType);
344 mpEngine->GetAllMisspellRanges(*pRanges);
346 if (pRanges->empty())
347 pRanges.reset(
nullptr);
351 mpResult->set(nCol, nRow, pRanges.get());
352 mpCache->set(nCol, nRow, aCell, std::move(pRanges));
355void SpellCheckContext::resetCache(
bool bContentChangeOnly)
358 mpResult.reset(
new SpellCheckResult());
363 mpCache.reset(
new SpellCheckCache(meLanguage));
364 else if (bContentChangeOnly)
365 mpCache->clearEditTextMap();
367 mpCache->clear(meLanguage);
370void SpellCheckContext::setup()
373 mpStatus.reset(
new SpellCheckStatus());
375 mpEngine->SetControlWord(
376 mpEngine->GetControlWord() | (EEControlBits::ONLINESPELLING | EEControlBits::ALLOWBIGOBJS));
377 mpEngine->SetStatusEventHdl(
LINK(mpStatus.get(), SpellCheckStatus, EventHdl));
379 mpEngine->SetWordDelimiters(
383 mpEngine->SetSpeller(xXSpellChecker1);
384 mpEngine->SetDefaultLanguage(meLanguage);
static css::uno::Reference< css::linguistic2::XSpellChecker1 > GetSpellChecker()
static OUString ModifyDelimiters(const OUString &rOld)
static LanguageType GetEditDefaultLanguage()
const SfxPoolItem & GetItem(sal_uInt16 nWhichP) const
bool Contains(const ScRange &) const
CellMapType maEditTextMisspells
std::unordered_map< CellPos, std::unique_ptr< MisspellType >, CellPos::Hash > CellMapType
std::vector< editeng::MisspellRanges > MisspellType
CellLangMapType maCellLanguages
bool query(SCCOL nCol, SCROW nRow, const ScRefCellValue &rCell, MisspellType *&rpRanges) const
void clear(LanguageType eDefaultCellLanguage)
void setLanguage(LanguageType eCellLang, SCCOL nCol, SCROW nRow)
void set(SCCOL nCol, SCROW nRow, const ScRefCellValue &rCell, std::unique_ptr< MisspellType > pRanges)
std::unordered_map< CellPos, LanguageType, CellPos::Hash > CellLangMapType
SharedStringMapType maStringMisspells
std::unordered_map< const rtl_uString *, std::unique_ptr< MisspellType > > SharedStringMapType
LanguageType meDefCellLanguage
SpellCheckCache(LanguageType eDefaultCellLanguage)
LanguageType getLanguage(SCCOL nCol, SCROW nRow) const
Class shared between grid windows to cache spelling results.
#define LINK(Instance, Class, Member)
std::enable_if_t<(sizeof(N)==4)> hash_combine(N &nSeed, T const *pValue, size_t nCount)
constexpr TypedWhichId< SvxLanguageItem > ATTR_FONT_LANGUAGE(110)
IMPL_LINK(SpellCheckContext::SpellCheckStatus, EventHdl, EditStatus &, rStatus, void)
This is very similar to ScCellValue, except that it references the original value instead of copying ...
const svl::SharedString * getSharedString() const
size_t operator()(const CellPos &rPos) const
CellPos(SCCOL nCol, SCROW nRow)
bool operator==(const CellPos &r) const
void set(SCCOL nCol, SCROW nRow, const std::vector< editeng::MisspellRanges > *pMisspells)
const std::vector< editeng::MisspellRanges > * pRanges
const std::vector< editeng::MisspellRanges > * query(SCCOL nCol, SCROW nRow) const
DECL_LINK(EventHdl, EditStatus &, void)