24#include <osl/diagnose.h>
29#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
30#include <com/sun/star/text/TextMarkupType.hpp>
31#include <com/sun/star/text/TextMarkupDescriptor.hpp>
32#include <com/sun/star/container/ElementExistException.hpp>
33#include <com/sun/star/container/XStringKeyMap.hpp>
39#include <com/sun/star/lang/XUnoTunnel.hpp>
40#include <com/sun/star/text/XTextRange.hpp>
89 return m_pImpl->m_ConversionMap;
98 const uno::Reference< container::XStringKeyMap > & xMarkupInfoContainer)
102 if (
auto pRange =
dynamic_cast<SwXTextRange*
>(xRange.get()))
104 SwDoc& rDoc = pRange->GetDoc();
110 auto [startPos, endPos] = aPam.
StartEnd();
112 commitStringMarkup (
nType, aIdentifier, startPos->GetContentIndex(), endPos->GetContentIndex() - startPos->GetContentIndex(), xMarkupInfoContainer);
114 else if (
auto pCursor =
dynamic_cast<OTextCursorHelper*
>(xRange.get()))
116 SwPaM & rPam(*pCursor->GetPaM());
118 auto [startPos, endPos] = rPam.
StartEnd();
120 commitStringMarkup (
nType, aIdentifier, startPos->GetContentIndex(), endPos->GetContentIndex() - startPos->GetContentIndex(), xMarkupInfoContainer);
126 const OUString & rIdentifier,
129 const uno::Reference< container::XStringKeyMap > & xMarkupInfoContainer)
137 if (
nType == text::TextMarkupType::SMARTTAG &&
143 bool bRepaint =
false;
144 if (
nType == text::TextMarkupType::SPELLCHECK )
146 pWList =
m_pImpl->m_pTextNode->GetWrong();
150 m_pImpl->m_pTextNode->SetWrong( std::unique_ptr<SwWrongList>(pWList) );
153 else if (
nType == text::TextMarkupType::PROOFREADING ||
nType == text::TextMarkupType::SENTENCE )
156 if( pGrammarContact )
159 OSL_ENSURE( pWList,
"GrammarContact _has_ to deliver a wrong list" );
163 pWList =
m_pImpl->m_pTextNode->GetGrammarCheck();
166 m_pImpl->m_pTextNode->SetGrammarCheck( std::make_unique<SwGrammarMarkUp>() );
167 pWList =
m_pImpl->m_pTextNode->GetGrammarCheck();
170 bRepaint = pWList ==
m_pImpl->m_pTextNode->GetGrammarCheck();
174 else if (
nType == text::TextMarkupType::SMARTTAG )
176 pWList =
m_pImpl->m_pTextNode->GetSmartTags();
180 m_pImpl->m_pTextNode->SetSmartTags( std::unique_ptr<SwWrongList>(pWList) );
185 OSL_FAIL(
"Unknown mark-up type" );
190 m_pImpl->m_ConversionMap.ConvertToModelPosition( nStart );
192 m_pImpl->m_ConversionMap.ConvertToModelPosition( nStart +
nLength - 1);
194 const bool bStartInField = aStartPos.
mbIsField;
195 const bool bEndInField = aEndPos.
mbIsField;
196 bool bCommit =
false;
198 if ( bStartInField && bEndInField && aStartPos.
mnPos == aEndPos.
mnPos )
201 const sal_Int32 nFieldPosModel = aStartPos.
mnPos;
202 const sal_uInt16 nInsertPos = pWList->
GetWrongPos( nFieldPosModel );
207 if(
nType == text::TextMarkupType::PROOFREADING ||
nType == text::TextMarkupType::SENTENCE )
211 pWList->
InsertSubList( nFieldPosModel, 1, nInsertPos, pSubList );
217 else if ( !bStartInField && !bEndInField )
219 nStart = aStartPos.
mnPos;
223 else if(
nType == text::TextMarkupType::PROOFREADING ||
nType == text::TextMarkupType::SENTENCE )
226 nStart = aStartPos.
mnPos;
227 sal_Int32 nEnd = aEndPos.
mnPos;
228 if( bStartInField &&
nType != text::TextMarkupType::SENTENCE )
230 const sal_Int32 nFieldPosModel = aStartPos.
mnPos;
231 const sal_uInt16 nInsertPos = pWList->
GetWrongPos( nFieldPosModel );
236 pWList->
InsertSubList( nFieldPosModel, 1, nInsertPos, pSubList );
238 const sal_Int32 nTmpStart =
239 m_pImpl->m_ConversionMap.ConvertToViewPosition(aStartPos.
mnPos);
240 const sal_Int32 nTmpLen =
241 m_pImpl->m_ConversionMap.ConvertToViewPosition(aStartPos.
mnPos + 1)
245 pSubList->
Insert( rIdentifier, xMarkupInfoContainer, aStartPos.
mnSubPos, nTmpLen );
249 if( bEndInField &&
nType != text::TextMarkupType::SENTENCE )
251 const sal_Int32 nFieldPosModel = aEndPos.
mnPos;
252 const sal_uInt16 nInsertPos = pWList->
GetWrongPos( nFieldPosModel );
257 pWList->
InsertSubList( nFieldPosModel, 1, nInsertPos, pSubList );
259 const sal_Int32 nTmpLen = aEndPos.
mnSubPos + 1;
260 pSubList->
Insert( rIdentifier, xMarkupInfoContainer, 0, nTmpLen );
272 if(
nType == text::TextMarkupType::SENTENCE )
275 pWList->
Insert( rIdentifier, xMarkupInfoContainer, nStart,
nLength );
286 const OUString & rIdentifier,
289 const uno::Reference< container::XStringKeyMap > & xMarkupInfoContainer)
291 OSL_ENSURE(
nType == text::TextMarkupType::PROOFREADING ||
nType == text::TextMarkupType::SENTENCE,
"Wrong mark-up type" );
297 const bool bStartInField = aStartPos.
mbIsField;
298 const bool bEndInField = aEndPos.
mbIsField;
299 bool bCommit =
false;
301 if ( bStartInField && bEndInField && aStartPos.
mnPos == aEndPos.
mnPos )
304 const sal_Int32 nFieldPosModel = aStartPos.
mnPos;
305 const sal_uInt16 nInsertPos = pWList->
GetWrongPos( nFieldPosModel );
311 pWList->
InsertSubList( nFieldPosModel, 1, nInsertPos, pSubList );
317 else if ( !bStartInField && !bEndInField )
319 nStart = aStartPos.
mnPos;
326 nStart = aStartPos.
mnPos;
327 sal_Int32 nEnd = aEndPos.
mnPos;
328 if( bStartInField &&
nType != text::TextMarkupType::SENTENCE )
330 const sal_Int32 nFieldPosModel = aStartPos.
mnPos;
331 const sal_uInt16 nInsertPos = pWList->
GetWrongPos( nFieldPosModel );
336 pWList->
InsertSubList( nFieldPosModel, 1, nInsertPos, pSubList );
342 pSubList->
Insert( rIdentifier, xMarkupInfoContainer, aStartPos.
mnSubPos, nTmpLen );
345 if( bEndInField &&
nType != text::TextMarkupType::SENTENCE )
347 const sal_Int32 nFieldPosModel = aEndPos.
mnPos;
348 const sal_uInt16 nInsertPos = pWList->
GetWrongPos( nFieldPosModel );
353 pWList->
InsertSubList( nFieldPosModel, 1, nInsertPos, pSubList );
355 const sal_Int32 nTmpLen = aEndPos.
mnSubPos + 1;
356 pSubList->
Insert( rIdentifier, xMarkupInfoContainer, 0, nTmpLen );
368 if(
nType == text::TextMarkupType::SENTENCE )
371 pWList->
Insert( rIdentifier, xMarkupInfoContainer, nStart,
nLength );
376 const uno::Sequence< text::TextMarkupDescriptor > &rMarkups )
390 const text::TextMarkupDescriptor *pSentenceMarkUp =
nullptr;
391 for(
const text::TextMarkupDescriptor &rDesc : rMarkups )
393 if (rDesc.nType == text::TextMarkupType::SENTENCE)
395 if (pSentenceMarkUp !=
nullptr)
396 throw lang::IllegalArgumentException();
397 pSentenceMarkUp = &rDesc;
399 else if( rDesc.nType != text::TextMarkupType::PROOFREADING )
403 if( pSentenceMarkUp ==
nullptr )
408 bool bRepaint =
false;
410 if( pGrammarContact )
413 OSL_ENSURE( pWList,
"GrammarContact _has_ to deliver a wrong list" );
417 pWList =
m_pImpl->m_pTextNode->GetGrammarCheck();
420 m_pImpl->m_pTextNode->SetGrammarCheck( std::make_unique<SwGrammarMarkUp>() );
421 pWList =
m_pImpl->m_pTextNode->GetGrammarCheck();
425 bRepaint = pWList ==
m_pImpl->m_pTextNode->GetGrammarCheck();
427 bool bAcceptGrammarError =
false;
431 m_pImpl->m_ConversionMap.ConvertToModelPosition(
432 pSentenceMarkUp->nOffset + pSentenceMarkUp->nLength );
437 if( bAcceptGrammarError )
439 for(
const text::TextMarkupDescriptor &rDesc : rMarkups )
442 rDesc.aIdentifier, rDesc.nOffset, rDesc.nLength, rDesc.xMarkupInfoContainer );
448 const text::TextMarkupDescriptor &rDesc = *pSentenceMarkUp;
450 rDesc.aIdentifier, rDesc.nOffset, rDesc.nLength, rDesc.xMarkupInfoContainer );
460 if(rHint.
GetId() == SfxHintId::Dying)
472 std::map< OUString, uno::Any >::const_iterator aIter = maMap.find( aKey );
473 if ( aIter == maMap.end() )
474 throw container::NoSuchElementException();
476 return (*aIter).second;
481 return maMap.find( aKey ) != maMap.end();
486 std::map< OUString, uno::Any >::const_iterator aIter = maMap.find( aKey );
487 if ( aIter != maMap.end() )
488 throw container::ElementExistException();
490 maMap[ aKey ] = aValue;
501 throw lang::IndexOutOfBoundsException();
509 throw lang::IndexOutOfBoundsException();
ModelPosition ConvertToModelPosition(sal_Int32 nViewPos) const
Converts a view position into a model position.
sal_Int32 ConvertToViewPosition(sal_Int32 nModelPos) const
Converts a model position into a view position.
bool StartListening(SvtBroadcaster &rBroadcaster)
void ClearGrammarList(sal_Int32 nSentenceEnd=COMPLETE_STRING)
void setSentence(sal_Int32 nStart)
PaM is Point and Mark: a selection of the document model.
std::pair< const SwPosition *, const SwPosition * > StartEnd() const
Because sometimes the cost of the operator<= can add up.
static SwSmartTagMgr & Get()
SwTextNode is a paragraph in the document model.
WrongListType GetWrongListType() const
void InsertSubList(sal_Int32 nNewPos, sal_Int32 nNewLen, sal_uInt16 nWhere, SwWrongList *pSubList)
sal_uInt16 GetWrongPos(sal_Int32 nValue) const
Find the first position that is greater or equal to the given value.
void SetInvalid(sal_Int32 nBegin, sal_Int32 nEnd)
SwWrongList * SubList(sal_uInt16 nIdx) const
void Insert(sal_uInt16 nWhere, std::vector< SwWrongArea >::iterator startPos, std::vector< SwWrongArea >::iterator const &endPos)
sal_Int32 GetBeginInv() const
Implementation of the css::container::XStringKeyMap interface.
virtual sal_Bool SAL_CALL hasValue(const OUString &aKey) override
virtual css::uno::Any SAL_CALL getValue(const OUString &aKey) override
virtual ::sal_Int32 SAL_CALL getCount() override
virtual css::uno::Any SAL_CALL getValueByIndex(::sal_Int32 nIndex) override
virtual OUString SAL_CALL getKeyByIndex(::sal_Int32 nIndex) override
virtual void SAL_CALL insertValue(const OUString &aKey, const css::uno::Any &aValue) override
virtual void SAL_CALL commitStringMarkup(::sal_Int32 nType, const OUString &aIdentifier, ::sal_Int32 nStart, ::sal_Int32 nLength, const css::uno::Reference< css::container::XStringKeyMap > &xMarkupInfoContainer) override
::sw::UnoImplPtr< Impl > m_pImpl
virtual css::uno::Reference< css::container::XStringKeyMap > SAL_CALL getMarkupInfoContainer() override
const ModelToViewHelper & GetConversionMap() const
virtual void SAL_CALL commitMultiTextMarkup(const css::uno::Sequence< css::text::TextMarkupDescriptor > &aMarkups) override
SwXTextMarkup(SwTextNode *const rTextNode, const ModelToViewHelper &rConversionMap)
virtual ~SwXTextMarkup() override
virtual void SAL_CALL commitTextRangeMarkup(::sal_Int32 nType, const OUString &aIdentifier, const css::uno::Reference< css::text::XTextRange > &xRange, const css::uno::Reference< css::container::XStringKeyMap > &xMarkupInfoContainer) override
SwTextNode * GetTextNode()
#define DBG_TESTSOLARMUTEX()
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
sw::GrammarContact * getGrammarContactFor(const SwTextNode &rTextNode)
getGrammarContact() delivers the grammar contact of the document (for a given textnode)
bool XTextRangeToSwPaM(SwUnoInternalPaM &rToFill, const uno::Reference< text::XTextRange > &xTextRange, ::sw::TextRangeMode const eMode)
void finishGrammarCheckFor(SwTextNode &rTextNode)
finishGrammarCheck() calls the same function of the grammar contact of the document (for a given text...
HashMap_OWString_Interface aMap
This struct defines a position in the model string.
virtual void Notify(const SfxHint &rHint) override
Impl(SwTextNode *const pTextNode, ModelToViewHelper aMap)
ModelToViewHelper const m_ConversionMap
constexpr sal_Int32 COMPLETE_STRING
static void lcl_commitGrammarMarkUp(const ModelToViewHelper &rConversionMap, SwGrammarMarkUp *pWList, ::sal_Int32 nType, const OUString &rIdentifier, ::sal_Int32 nStart, ::sal_Int32 nLength, const uno::Reference< container::XStringKeyMap > &xMarkupInfoContainer)