17 #include <document.hxx>
22 #include <com/sun/star/linguistic2/XSpellChecker1.hpp>
24 #include <boost/functional/hash.hpp>
26 #include <unordered_map>
38 size_t operator() (
const CellPos& rPos)
const
41 boost::hash_combine(seed, rPos.
mnCol);
42 boost::hash_combine(seed, rPos.
mnRow);
80 SharedStringMapType::const_iterator it = maStringMisspells.find(rCell.
mpString->
getData());
81 if (it == maStringMisspells.end())
84 rpRanges = it->second.get();
90 CellMapType::const_iterator it = maEditTextMisspells.find(
CellPos(nCol, nRow));
91 if (it == maEditTextMisspells.end())
94 rpRanges = it->second.get();
106 maStringMisspells.insert_or_assign(rCell.
mpString->
getData(), std::move(pRanges));
108 maEditTextMisspells.insert_or_assign(
CellPos(nCol, nRow), std::move(pRanges));
113 CellLangMapType::const_iterator it = maCellLanguages.find(
CellPos(nCol, nRow));
114 if (it == maCellLanguages.end())
115 return meDefCellLanguage;
122 if (eCellLang == meDefCellLanguage)
123 maCellLanguages.erase(
CellPos(nCol, nRow));
125 maCellLanguages.insert_or_assign(
CellPos(nCol, nRow), eCellLang);
130 maStringMisspells.clear();
131 maEditTextMisspells.clear();
132 maCellLanguages.clear();
133 meDefCellLanguage = eDefaultCellLanguage;
138 maEditTextMisspells.clear();
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)
170 pRanges = pMisspells;
190 SpellCheckContext::SpellCheckContext(
ScDocument* pDocument,
SCTAB nTab) :
198 SpellCheckContext::~SpellCheckContext()
202 void SpellCheckContext::dispose()
209 void SpellCheckContext::setTabNo(
SCTAB nTab)
217 bool SpellCheckContext::isMisspelled(
SCCOL nCol,
SCROW nRow)
const
220 return mpResult->query(nCol, nRow);
223 const std::vector<editeng::MisspellRanges>* SpellCheckContext::getMisspellRanges(
227 return mpResult->query(nCol, nRow);
230 void 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));
247 void SpellCheckContext::reset()
255 void SpellCheckContext::resetForContentChange()
260 void 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);
330 mpEngine->SetDefaultItem(
SvxLanguageItem(eCellLang, EE_CHAR_LANGUAGE));
332 mpEngine->SetText(aCell.mpString->getString());
334 mpEngine->SetText(*aCell.mpEditText);
336 mpStatus->mbModified =
false;
337 mpEngine->CompleteOnlineSpelling();
338 std::unique_ptr<MisspellType> pRanges;
339 if (mpStatus->mbModified)
341 pRanges.reset(
new MisspellType);
342 mpEngine->GetAllMisspellRanges(*pRanges);
344 if (pRanges->empty())
345 pRanges.reset(
nullptr);
349 mpResult->set(nCol, nRow, pRanges.get());
350 mpCache->set(nCol, nRow, aCell, std::move(pRanges));
353 void SpellCheckContext::resetCache(
bool bContentChangeOnly)
356 mpResult.reset(
new SpellCheckResult());
361 mpCache.reset(
new SpellCheckCache(meLanguage));
362 else if (bContentChangeOnly)
363 mpCache->clearEditTextMap();
365 mpCache->clear(meLanguage);
368 void SpellCheckContext::setup()
371 mpStatus.reset(
new SpellCheckStatus());
373 mpEngine->SetControlWord(
374 mpEngine->GetControlWord() | (EEControlBits::ONLINESPELLING | EEControlBits::ALLOWBIGOBJS));
375 mpEngine->SetStatusEventHdl(
LINK(mpStatus.get(), SpellCheckStatus, EventHdl));
377 mpEngine->SetWordDelimiters(
381 mpEngine->SetSpeller(xXSpellChecker1);
382 mpEngine->SetDefaultLanguage(meLanguage);
bool operator==(const XclFontData &rLeft, const XclFontData &rRight)
#define LINK(Instance, Class, Member)
void set(SCCOL nCol, SCROW nRow, const std::vector< editeng::MisspellRanges > *pMisspells)
const std::vector< editeng::MisspellRanges > * pRanges
Class shared between grid windows to cache spelling results.
#define DECL_LINK(Member, ArgType, RetType)
constexpr TypedWhichId< SvxLanguageItem > ATTR_FONT_LANGUAGE(110)
bool query(SCCOL nCol, SCROW nRow, const ScRefCellValue &rCell, MisspellType *&rpRanges) const
This is very similar to ScCellValue, except that it references the original value instead of copying ...
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
bool In(const ScRange &) const
SpellCheckCache(LanguageType eDefaultCellLanguage)
CellMapType maEditTextMisspells
const SfxPoolItem & GetItem(sal_uInt16 nWhichP) const
CellPos(SCCOL nCol, SCROW nRow)
static css::uno::Reference< css::linguistic2::XSpellChecker1 > GetSpellChecker()
std::unordered_map< const rtl_uString *, std::unique_ptr< MisspellType > > SharedStringMapType
IMPL_LINK(SpellCheckContext::SpellCheckStatus, EventHdl, EditStatus &, rStatus, void)
const svl::SharedString * mpString
void setLanguage(LanguageType eCellLang, SCCOL nCol, SCROW nRow)
CellLangMapType maCellLanguages
const std::vector< editeng::MisspellRanges > * query(SCCOL nCol, SCROW nRow) const
void clear(LanguageType eDefaultCellLanguage)
static LanguageType GetEditDefaultLanguage()
LanguageType getLanguage(SCCOL nCol, SCROW nRow) const
static OUString ModifyDelimiters(const OUString &rOld)
std::vector< editeng::MisspellRanges > MisspellType
void set(SCCOL nCol, SCROW nRow, const ScRefCellValue &rCell, std::unique_ptr< MisspellType > pRanges)
LanguageType meDefCellLanguage
std::unordered_map< CellPos, std::unique_ptr< MisspellType >, CellPos::Hash > CellMapType
std::unordered_map< CellPos, LanguageType, CellPos::Hash > CellLangMapType
exports com.sun.star. setup
SharedStringMapType maStringMisspells