From 1e3c5948c35cd0b2178b1cf204709ed36c6123c7 Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Wed, 28 Aug 2013 15:55:56 -0400 Subject: Expose misspelled range container outside edit engine. Change-Id: I04c87c5299559932733c88a317808241fd1755d4 --- editeng/Library_editeng.mk | 1 + editeng/source/editeng/edtspell.cxx | 190 +++++++++++++++---------------- editeng/source/editeng/edtspell.hxx | 57 +++++----- editeng/source/editeng/impedit2.cxx | 18 +-- editeng/source/editeng/impedit3.cxx | 11 +- editeng/source/editeng/misspellrange.cxx | 19 ++++ 6 files changed, 155 insertions(+), 141 deletions(-) create mode 100644 editeng/source/editeng/misspellrange.cxx (limited to 'editeng') diff --git a/editeng/Library_editeng.mk b/editeng/Library_editeng.mk index 94e841bca389..9a1ca715d1c8 100644 --- a/editeng/Library_editeng.mk +++ b/editeng/Library_editeng.mk @@ -60,6 +60,7 @@ $(eval $(call gb_Library_add_exception_objects,editeng,\ editeng/source/editeng/impedit3 \ editeng/source/editeng/impedit4 \ editeng/source/editeng/impedit5 \ + editeng/source/editeng/misspellrange \ editeng/source/editeng/section \ editeng/source/editeng/textconv \ editeng/source/items/borderline \ diff --git a/editeng/source/editeng/edtspell.cxx b/editeng/source/editeng/edtspell.cxx index 3331ab36c749..6d7bcd188aa6 100644 --- a/editeng/source/editeng/edtspell.cxx +++ b/editeng/source/editeng/edtspell.cxx @@ -196,89 +196,89 @@ void EditSpellWrapper::CheckSpellTo() } } -sal_uInt16 WrongList::Valid = std::numeric_limits::max(); +size_t WrongList::Valid = std::numeric_limits::max(); -WrongList::WrongList() : nInvalidStart(0), nInvalidEnd(Valid) {} +WrongList::WrongList() : mnInvalidStart(0), mnInvalidEnd(Valid) {} WrongList::WrongList(const WrongList& r) : maRanges(r.maRanges), - nInvalidStart(r.nInvalidStart), - nInvalidEnd(r.nInvalidEnd) {} + mnInvalidStart(r.mnInvalidStart), + mnInvalidEnd(r.mnInvalidEnd) {} WrongList::~WrongList() {} bool WrongList::IsValid() const { - return nInvalidStart == Valid; + return mnInvalidStart == Valid; } void WrongList::SetValid() { - nInvalidStart = Valid; - nInvalidEnd = 0; + mnInvalidStart = Valid; + mnInvalidEnd = 0; } -void WrongList::SetInvalidRange( sal_uInt16 nStart, sal_uInt16 nEnd ) +void WrongList::SetInvalidRange( size_t nStart, size_t nEnd ) { - if (nInvalidStart == Valid || nStart < nInvalidStart) - nInvalidStart = nStart; + if (mnInvalidStart == Valid || nStart < mnInvalidStart) + mnInvalidStart = nStart; - if (nInvalidEnd < nEnd) - nInvalidEnd = nEnd; + if (mnInvalidEnd < nEnd) + mnInvalidEnd = nEnd; } -void WrongList::ResetInvalidRange( sal_uInt16 nStart, sal_uInt16 nEnd ) +void WrongList::ResetInvalidRange( size_t nStart, size_t nEnd ) { - nInvalidStart = nStart; - nInvalidEnd = nEnd; + mnInvalidStart = nStart; + mnInvalidEnd = nEnd; } -void WrongList::TextInserted( sal_uInt16 nPos, sal_uInt16 nLength, bool bPosIsSep ) +void WrongList::TextInserted( size_t nPos, size_t nLength, bool bPosIsSep ) { if (IsValid()) { - nInvalidStart = nPos; - nInvalidEnd = nPos + nLength; + mnInvalidStart = nPos; + mnInvalidEnd = nPos + nLength; } else { - if ( nInvalidStart > nPos ) - nInvalidStart = nPos; - if ( nInvalidEnd >= nPos ) - nInvalidEnd = nInvalidEnd + nLength; + if ( mnInvalidStart > nPos ) + mnInvalidStart = nPos; + if ( mnInvalidEnd >= nPos ) + mnInvalidEnd = mnInvalidEnd + nLength; else - nInvalidEnd = nPos + nLength; + mnInvalidEnd = nPos + nLength; } for (size_t i = 0, n = maRanges.size(); i < n; ++i) { - WrongRange& rWrong = maRanges[i]; + editeng::MisspellRange& rWrong = maRanges[i]; bool bRefIsValid = true; - if (rWrong.nEnd >= nPos) + if (rWrong.mnEnd >= nPos) { // Move all Wrongs after the insert position... - if (rWrong.nStart > nPos) + if (rWrong.mnStart > nPos) { - rWrong.nStart += nLength; - rWrong.nEnd += nLength; + rWrong.mnStart += nLength; + rWrong.mnEnd += nLength; } // 1: Starts before and goes until nPos... - else if (rWrong.nEnd == nPos) + else if (rWrong.mnEnd == nPos) { // Should be halted at a blank! if ( !bPosIsSep ) - rWrong.nEnd += nLength; + rWrong.mnEnd += nLength; } // 2: Starts before and goes until after nPos... - else if ((rWrong.nStart < nPos) && (rWrong.nEnd > nPos)) + else if ((rWrong.mnStart < nPos) && (rWrong.mnEnd > nPos)) { - rWrong.nEnd += nLength; + rWrong.mnEnd += nLength; // When a separator remove and re-examine the Wrong if ( bPosIsSep ) { // Split Wrong... - WrongRange aNewWrong(rWrong.nStart, nPos); - rWrong.nStart = nPos + 1; + editeng::MisspellRange aNewWrong(rWrong.mnStart, nPos); + rWrong.mnStart = nPos + 1; maRanges.insert(maRanges.begin() + i, aNewWrong); // Reference no longer valid after Insert, the other // was inserted in front of this position @@ -287,76 +287,76 @@ void WrongList::TextInserted( sal_uInt16 nPos, sal_uInt16 nLength, bool bPosIsSe } } // 3: Attribute starts at position .. - else if (rWrong.nStart == nPos) + else if (rWrong.mnStart == nPos) { - rWrong.nEnd += nLength; + rWrong.mnEnd += nLength; if ( bPosIsSep ) - ++(rWrong.nStart); + ++(rWrong.mnStart); } } - SAL_WARN_IF(bRefIsValid && rWrong.nStart >= rWrong.nEnd, "editeng", - "TextInserted, WrongRange: Start >= End?!"); + SAL_WARN_IF(bRefIsValid && rWrong.mnStart >= rWrong.mnEnd, "editeng", + "TextInserted, editeng::MisspellRange: Start >= End?!"); (void)bRefIsValid; } SAL_WARN_IF(DbgIsBuggy(), "editeng", "InsertWrong: WrongList broken!"); } -void WrongList::TextDeleted( sal_uInt16 nPos, sal_uInt16 nLength ) +void WrongList::TextDeleted( size_t nPos, size_t nLength ) { - sal_uInt16 nEndPos = nPos + nLength; + size_t nEndPos = nPos + nLength; if (IsValid()) { sal_uInt16 nNewInvalidStart = nPos ? nPos - 1 : 0; - nInvalidStart = nNewInvalidStart; - nInvalidEnd = nNewInvalidStart + 1; + mnInvalidStart = nNewInvalidStart; + mnInvalidEnd = nNewInvalidStart + 1; } else { - if ( nInvalidStart > nPos ) - nInvalidStart = nPos; - if ( nInvalidEnd > nPos ) + if ( mnInvalidStart > nPos ) + mnInvalidStart = nPos; + if ( mnInvalidEnd > nPos ) { - if (nInvalidEnd > nEndPos) - nInvalidEnd = nInvalidEnd - nLength; + if (mnInvalidEnd > nEndPos) + mnInvalidEnd = mnInvalidEnd - nLength; else - nInvalidEnd = nPos+1; + mnInvalidEnd = nPos+1; } } for (WrongList::iterator i = begin(); i != end(); ) { bool bDelWrong = false; - if (i->nEnd >= nPos) + if (i->mnEnd >= nPos) { // Move all Wrongs after the insert position... - if (i->nStart >= nEndPos) + if (i->mnStart >= nEndPos) { - i->nStart -= nLength; - i->nEnd -= nLength; + i->mnStart -= nLength; + i->mnEnd -= nLength; } // 1. Delete Internal Wrongs ... - else if (i->nStart >= nPos && i->nEnd <= nEndPos) + else if (i->mnStart >= nPos && i->mnEnd <= nEndPos) { bDelWrong = true; } // 2. Wrong begins before, ends inside or behind it ... - else if (i->nStart <= nPos && i->nEnd > nPos) + else if (i->mnStart <= nPos && i->mnEnd > nPos) { - if (i->nEnd <= nEndPos) // ends inside - i->nEnd = nPos; + if (i->mnEnd <= nEndPos) // ends inside + i->mnEnd = nPos; else - i->nEnd -= nLength; // ends after + i->mnEnd -= nLength; // ends after } // 3. Wrong begins inside, ending after ... - else if (i->nStart >= nPos && i->nEnd > nEndPos) + else if (i->mnStart >= nPos && i->mnEnd > nEndPos) { - i->nStart = nEndPos - nLength; - i->nEnd -= nLength; + i->mnStart = nEndPos - nLength; + i->mnEnd -= nLength; } } - SAL_WARN_IF(i->nStart >= i->nEnd, "editeng", - "TextDeleted, WrongRange: Start >= End?!"); + SAL_WARN_IF(i->mnStart >= i->mnEnd, "editeng", + "TextDeleted, editeng::MisspellRange: Start >= End?!"); if ( bDelWrong ) { i = maRanges.erase(i); @@ -370,7 +370,7 @@ void WrongList::TextDeleted( sal_uInt16 nPos, sal_uInt16 nLength ) SAL_WARN_IF(DbgIsBuggy(), "editeng", "TextDeleted: WrongList broken!"); } -bool WrongList::NextWrong( sal_uInt16& rnStart, sal_uInt16& rnEnd ) const +bool WrongList::NextWrong( size_t& rnStart, size_t& rnEnd ) const { /* rnStart get the start position, is possibly adjusted wrt. Wrong start @@ -378,56 +378,56 @@ bool WrongList::NextWrong( sal_uInt16& rnStart, sal_uInt16& rnEnd ) const */ for (WrongList::const_iterator i = begin(); i != end(); ++i) { - if ( i->nEnd > rnStart ) + if (i->mnEnd > rnStart) { - rnStart = i->nStart; - rnEnd = i->nEnd; + rnStart = i->mnStart; + rnEnd = i->mnEnd; return true; } } return false; } -bool WrongList::HasWrong( sal_uInt16 nStart, sal_uInt16 nEnd ) const +bool WrongList::HasWrong( size_t nStart, size_t nEnd ) const { for (WrongList::const_iterator i = begin(); i != end(); ++i) { - if (i->nStart == nStart && i->nEnd == nEnd) + if (i->mnStart == nStart && i->mnEnd == nEnd) return true; - else if ( i->nStart >= nStart ) + else if (i->mnStart >= nStart) break; } return false; } -bool WrongList::HasAnyWrong( sal_uInt16 nStart, sal_uInt16 nEnd ) const +bool WrongList::HasAnyWrong( size_t nStart, size_t nEnd ) const { for (WrongList::const_iterator i = begin(); i != end(); ++i) { - if (i->nEnd >= nStart && i->nStart < nEnd) + if (i->mnEnd >= nStart && i->mnStart < nEnd) return true; - else if (i->nStart >= nEnd) + else if (i->mnStart >= nEnd) break; } return false; } -void WrongList::ClearWrongs( sal_uInt16 nStart, sal_uInt16 nEnd, +void WrongList::ClearWrongs( size_t nStart, size_t nEnd, const ContentNode* pNode ) { for (WrongList::iterator i = begin(); i != end(); ) { - if (i->nEnd > nStart && i->nStart < nEnd) + if (i->mnEnd > nStart && i->mnStart < nEnd) { - if (i->nEnd > nEnd) // Runs out + if (i->mnEnd > nEnd) // Runs out { - i->nStart = nEnd; + i->mnStart = nEnd; // Blanks? - while (i->nStart < pNode->Len() && - (pNode->GetChar(i->nStart) == ' ' || - pNode->IsFeature(i->nStart))) + while (i->mnStart < pNode->Len() && + (pNode->GetChar(i->mnStart) == ' ' || + pNode->IsFeature(i->mnStart))) { - ++(i->nStart); + ++i->mnStart; } ++i; } @@ -446,12 +446,12 @@ void WrongList::ClearWrongs( sal_uInt16 nStart, sal_uInt16 nEnd, SAL_WARN_IF(DbgIsBuggy(), "editeng", "ClearWrongs: WrongList broken!"); } -void WrongList::InsertWrong( sal_uInt16 nStart, sal_uInt16 nEnd ) +void WrongList::InsertWrong( size_t nStart, size_t nEnd ) { WrongList::iterator nPos = end(); for (WrongList::iterator i = begin(); i != end(); ++i) { - if (i->nStart >= nStart ) + if (i->mnStart >= nStart) { nPos = i; { @@ -459,18 +459,18 @@ void WrongList::InsertWrong( sal_uInt16 nStart, sal_uInt16 nEnd ) // and runs along, but not that there are several ranges ... // Exactly in the range is no one allowed to be, otherwise this // Method can not be called! - SAL_WARN_IF((i->nStart != nStart || i->nEnd <= nEnd) && i->nStart <= nEnd, "editeng", "InsertWrong: RangeMismatch!"); - if (i->nStart == nStart && i->nEnd > nEnd) - i->nStart = nEnd + 1; + SAL_WARN_IF((i->mnStart != nStart || i->mnEnd <= nEnd) && i->mnStart <= nEnd, "editeng", "InsertWrong: RangeMismatch!"); + if (i->mnStart == nStart && i->mnEnd > nEnd) + i->mnStart = nEnd + 1; } break; } } if (nPos != maRanges.end()) - maRanges.insert(nPos, WrongRange(nStart, nEnd)); + maRanges.insert(nPos, editeng::MisspellRange(nStart, nEnd)); else - maRanges.push_back(WrongRange(nStart, nEnd)); + maRanges.push_back(editeng::MisspellRange(nStart, nEnd)); SAL_WARN_IF(DbgIsBuggy(), "editeng", "InsertWrong: WrongList broken!"); } @@ -478,7 +478,7 @@ void WrongList::InsertWrong( sal_uInt16 nStart, sal_uInt16 nEnd ) void WrongList::MarkWrongsInvalid() { if (!maRanges.empty()) - SetInvalidRange(maRanges.front().nStart, maRanges.back().nEnd); + SetInvalidRange(maRanges.front().mnStart, maRanges.back().mnEnd); } WrongList* WrongList::Clone() const @@ -500,7 +500,7 @@ bool WrongList::operator==(const WrongList& rCompare) const for (; rCA != maRanges.end(); ++rCA, ++rCB) { - if(rCA->nStart != rCB->nStart || rCA->nEnd != rCB->nEnd) + if(rCA->mnStart != rCB->mnStart || rCA->mnEnd != rCB->mnEnd) return false; } @@ -512,17 +512,17 @@ bool WrongList::empty() const return maRanges.empty(); } -void WrongList::push_back(const WrongRange& rRange) +void WrongList::push_back(const editeng::MisspellRange& rRange) { maRanges.push_back(rRange); } -WrongRange& WrongList::back() +editeng::MisspellRange& WrongList::back() { return maRanges.back(); } -const WrongRange& WrongList::back() const +const editeng::MisspellRange& WrongList::back() const { return maRanges.back(); } @@ -556,10 +556,10 @@ bool WrongList::DbgIsBuggy() const for (WrongList::const_iterator j = i + 1; !bError && (j != end()); ++j) { // 1) Start before, End after the second Start - if (i->nStart <= j->nStart && i->nEnd >= j->nStart) + if (i->mnStart <= j->mnStart && i->mnEnd >= j->mnStart) bError = true; // 2) Start after the second Start, but still before the second End - else if (i->nStart >= j->nStart && i->nStart <= j->nEnd) + else if (i->mnStart >= j->mnStart && i->mnStart <= j->mnEnd) bError = true; } } diff --git a/editeng/source/editeng/edtspell.hxx b/editeng/source/editeng/edtspell.hxx index 642bcfa94469..c79c2ac7dc87 100644 --- a/editeng/source/editeng/edtspell.hxx +++ b/editeng/source/editeng/edtspell.hxx @@ -25,6 +25,7 @@ #include #include #include +#include "editeng/misspellrange.hxx" #include #include @@ -64,50 +65,44 @@ public: }; - -struct WrongRange -{ - sal_uInt16 nStart; - sal_uInt16 nEnd; - - WrongRange( sal_uInt16 nS, sal_uInt16 nE ) { nStart = nS; nEnd = nE; } -}; - +/** + * Keeps track of misspelled ranges in paragraph. + */ class WrongList { - static sal_uInt16 Valid; + static size_t Valid; - std::vector maRanges; - sal_uInt16 nInvalidStart; - sal_uInt16 nInvalidEnd; + std::vector maRanges; + size_t mnInvalidStart; + size_t mnInvalidEnd; bool DbgIsBuggy() const; public: - typedef std::vector::iterator iterator; - typedef std::vector::const_iterator const_iterator; + typedef std::vector::iterator iterator; + typedef std::vector::const_iterator const_iterator; WrongList(); WrongList(const WrongList& r); ~WrongList(); bool IsValid() const; - void SetValid(); - void SetInvalidRange( sal_uInt16 nStart, sal_uInt16 nEnd ); - void ResetInvalidRange( sal_uInt16 nStart, sal_uInt16 nEnd ); + void SetValid(); + void SetInvalidRange( size_t nStart, size_t nEnd ); + void ResetInvalidRange( size_t nStart, size_t nEnd ); - sal_uInt16 GetInvalidStart() const { return nInvalidStart; } - sal_uInt16 GetInvalidEnd() const { return nInvalidEnd; } + size_t GetInvalidStart() const { return mnInvalidStart; } + size_t GetInvalidEnd() const { return mnInvalidEnd; } - void TextInserted( sal_uInt16 nPos, sal_uInt16 nLength, bool bPosIsSep ); - void TextDeleted( sal_uInt16 nPos, sal_uInt16 nLength ); + void TextInserted( size_t nPos, size_t nLength, bool bPosIsSep ); + void TextDeleted( size_t nPos, size_t nLength ); - void InsertWrong( sal_uInt16 nStart, sal_uInt16 nEnd ); - bool NextWrong( sal_uInt16& rnStart, sal_uInt16& rnEnd ) const; - bool HasWrong( sal_uInt16 nStart, sal_uInt16 nEnd ) const; - bool HasAnyWrong( sal_uInt16 nStart, sal_uInt16 nEnd ) const; - void ClearWrongs( sal_uInt16 nStart, sal_uInt16 nEnd, const ContentNode* pNode ); - void MarkWrongsInvalid(); + void InsertWrong( size_t nStart, size_t nEnd ); + bool NextWrong( size_t& rnStart, size_t& rnEnd ) const; + bool HasWrong( size_t nStart, size_t nEnd ) const; + bool HasAnyWrong( size_t nStart, size_t nEnd ) const; + void ClearWrongs( size_t nStart, size_t nEnd, const ContentNode* pNode ); + void MarkWrongsInvalid(); WrongList* Clone() const; @@ -115,9 +110,9 @@ public: bool operator==(const WrongList& rCompare) const; bool empty() const; - void push_back(const WrongRange& rRange); - WrongRange& back(); - const WrongRange& back() const; + void push_back(const editeng::MisspellRange& rRange); + editeng::MisspellRange& back(); + const editeng::MisspellRange& back() const; iterator begin(); iterator end(); diff --git a/editeng/source/editeng/impedit2.cxx b/editeng/source/editeng/impedit2.cxx index c8b56f195b9d..3a5fb7e78faa 100644 --- a/editeng/source/editeng/impedit2.cxx +++ b/editeng/source/editeng/impedit2.cxx @@ -2235,10 +2235,10 @@ EditPaM ImpEditEngine::ImpConnectParagraphs( ContentNode* pLeft, ContentNode* pR WrongList* pRWrongs = pRight->GetWrongList(); for (WrongList::iterator i = pRWrongs->begin(); i < pRWrongs->end(); ++i) { - if (i->nStart != 0) // Not a subsequent + if (i->mnStart != 0) // Not a subsequent { - i->nStart = i->nStart + nEnd; - i->nEnd = i->nEnd + nEnd; + i->mnStart = i->mnStart + nEnd; + i->mnEnd = i->mnEnd + nEnd; pLeft->GetWrongList()->push_back(*i); } } @@ -2821,15 +2821,15 @@ EditPaM ImpEditEngine::ImpInsertParaBreak( EditPaM& rPaM, bool bKeepEndingAttrib { // Correct only if really a word gets overlapped in the process of // Spell checking - if (i->nStart > nEnd) + if (i->mnStart > nEnd) { pRWrongs->push_back(*i); - WrongRange& rRWrong = pRWrongs->back(); - rRWrong.nStart = rRWrong.nStart - nEnd; - rRWrong.nEnd = rRWrong.nEnd - nEnd; + editeng::MisspellRange& rRWrong = pRWrongs->back(); + rRWrong.mnStart = rRWrong.mnStart - nEnd; + rRWrong.mnEnd = rRWrong.mnEnd - nEnd; } - else if (i->nStart < nEnd && i->nEnd > nEnd) - i->nEnd = nEnd; + else if (i->mnStart < nEnd && i->mnEnd > nEnd) + i->mnEnd = nEnd; } sal_uInt16 nInv = nEnd ? nEnd-1 : nEnd; if ( nEnd ) diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx index f2579f8c123a..a3c68f548cce 100644 --- a/editeng/source/editeng/impedit3.cxx +++ b/editeng/source/editeng/impedit3.cxx @@ -169,8 +169,8 @@ static void lcl_DrawRedLines( else nStyle = WAVE_FLAT; - sal_uInt16 nEnd, nStart = nIndex; - sal_Bool bWrong = pWrongs->NextWrong( nStart, nEnd ); + size_t nEnd, nStart = nIndex; + bool bWrong = pWrongs->NextWrong( nStart, nEnd ); while ( bWrong ) { if ( nStart >= nMaxEnd ) @@ -225,7 +225,7 @@ static void lcl_DrawRedLines( if ( nEnd < nMaxEnd ) bWrong = pWrongs->NextWrong( nStart, nEnd ); else - bWrong = sal_False; + bWrong = false; } } } @@ -3232,9 +3232,8 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, Rectangle aClipRect, Point aSt if(pWrongs && !pWrongs->empty()) { - sal_uInt16 nStart(nIndex); - sal_uInt16 nEnd(0); - sal_Bool bWrong(pWrongs->NextWrong(nStart, nEnd)); + size_t nStart = nIndex, nEnd = 0; + bool bWrong = pWrongs->NextWrong(nStart, nEnd); const sal_uInt16 nMaxEnd(nIndex + pTextPortion->GetLen()); while(bWrong) diff --git a/editeng/source/editeng/misspellrange.cxx b/editeng/source/editeng/misspellrange.cxx new file mode 100644 index 000000000000..0136705248d6 --- /dev/null +++ b/editeng/source/editeng/misspellrange.cxx @@ -0,0 +1,19 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "editeng/misspellrange.hxx" + +namespace editeng { + +MisspellRange::MisspellRange() : mnStart(0), mnEnd(0) {} +MisspellRange::MisspellRange(size_t nStart, size_t nEnd) : mnStart(nStart), mnEnd(nEnd) {} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3