diff options
| author | Michael Stahl <Michael.Stahl@cib.de> | 2018-09-14 14:35:00 +0200 |
|---|---|---|
| committer | Michael Stahl <Michael.Stahl@cib.de> | 2018-09-19 10:18:33 +0200 |
| commit | 9bda4a67565817f0a26f48c4a4b9723894a385f5 (patch) | |
| tree | 316bc5f268763580998321bfdef2510393698a63 | |
| parent | 6410a654058c3dc30461aa25d0197e579147edcc (diff) | |
sw_redlinehide_2: adapt SwEditShell::GetCurWord()
Move SwTextNode::GetCurWord() to SwTextFrame, this was the only caller.
Change-Id: Id26cea92e1ca507fd82c5c75bc5a6eedb531d78d
| -rw-r--r-- | sw/inc/ndtxt.hxx | 1 | ||||
| -rw-r--r-- | sw/source/core/edit/editsh.cxx | 14 | ||||
| -rw-r--r-- | sw/source/core/inc/txtfrm.hxx | 3 | ||||
| -rw-r--r-- | sw/source/core/text/itratr.cxx | 7 | ||||
| -rw-r--r-- | sw/source/core/txtnode/txtedt.cxx | 29 |
5 files changed, 38 insertions, 16 deletions
diff --git a/sw/inc/ndtxt.hxx b/sw/inc/ndtxt.hxx index 64bdaa3a5cc1..dde56486e0a7 100644 --- a/sw/inc/ndtxt.hxx +++ b/sw/inc/ndtxt.hxx @@ -404,7 +404,6 @@ public: const sal_Int32 nIndex, const bool bIncludeInputFieldAtStart = false ) const; - OUString GetCurWord(sal_Int32) const; bool Spell(SwSpellArgs*); bool Convert( SwConversionArgs & ); diff --git a/sw/source/core/edit/editsh.cxx b/sw/source/core/edit/editsh.cxx index f5867ee7fb8a..30ca2e97e427 100644 --- a/sw/source/core/edit/editsh.cxx +++ b/sw/source/core/edit/editsh.cxx @@ -415,10 +415,16 @@ OUString SwEditShell::GetCurWord() { const SwPaM& rPaM = *GetCursor(); const SwTextNode* pNd = rPaM.GetNode().GetTextNode(); - OUString aString = pNd ? - pNd->GetCurWord(rPaM.GetPoint()->nContent.GetIndex()) : - OUString(); - return aString; + if (!pNd) + { + return OUString(); + } + SwTextFrame const*const pFrame(static_cast<SwTextFrame*>(pNd->getLayoutFrame(GetLayout()))); + if (pFrame) + { + return pFrame->GetCurWord(*rPaM.GetPoint()); + } + return OUString(); } void SwEditShell::UpdateDocStat( ) diff --git a/sw/source/core/inc/txtfrm.hxx b/sw/source/core/inc/txtfrm.hxx index a9d3a6dd1fe5..0933a5e328db 100644 --- a/sw/source/core/inc/txtfrm.hxx +++ b/sw/source/core/inc/txtfrm.hxx @@ -742,6 +742,9 @@ public: void RegisterToNode(SwTextNode &, bool isForceNodeAsFirst = false); + bool IsSymbolAt(TextFrameIndex) const; + OUString GetCurWord(SwPosition const&) const; + virtual void dumpAsXmlAttributes(xmlTextWriterPtr writer) const override; }; diff --git a/sw/source/core/text/itratr.cxx b/sw/source/core/text/itratr.cxx index 1b4c46b4eb80..0533fae9be27 100644 --- a/sw/source/core/text/itratr.cxx +++ b/sw/source/core/text/itratr.cxx @@ -188,6 +188,13 @@ bool SwAttrIter::IsSymbol(TextFrameIndex const nNewPos) return m_pFont->IsSymbol( m_pViewShell ); } +bool SwTextFrame::IsSymbolAt(TextFrameIndex const nPos) const +{ + SwTextInfo info(const_cast<SwTextFrame*>(this)); + SwTextIter iter(const_cast<SwTextFrame*>(this), &info); + return iter.IsSymbol(nPos); +} + bool SwAttrIter::SeekStartAndChgAttrIter( OutputDevice* pOut, const bool bParaFont ) { SwTextNode const*const pFirstTextNode(m_pMergedPara ? m_pMergedPara->pFirstNode : m_pTextNode); diff --git a/sw/source/core/txtnode/txtedt.cxx b/sw/source/core/txtnode/txtedt.cxx index ff2d645c83da..bbd4ccc268fd 100644 --- a/sw/source/core/txtnode/txtedt.cxx +++ b/sw/source/core/txtnode/txtedt.cxx @@ -695,36 +695,43 @@ static sal_Int32 clipIndexBounds(const OUString &rStr, sal_Int32 nPos) // Search from left to right, so find the word before nPos. // Except if at the start of the paragraph, then return the first word. // If the first word consists only of whitespace, return an empty string. -OUString SwTextNode::GetCurWord( sal_Int32 nPos ) const +OUString SwTextFrame::GetCurWord(SwPosition const& rPos) const { - assert(nPos <= m_Text.getLength()); // invalid index + TextFrameIndex const nPos(MapModelToViewPos(rPos)); + SwTextNode *const pTextNode(rPos.nNode.GetNode().GetTextNode()); + assert(pTextNode); + OUString const& rText(GetText()); + assert(sal_Int32(nPos) <= rText.getLength()); // invalid index - if (m_Text.isEmpty()) - return m_Text; + if (rText.isEmpty()) + return OUString(); assert(g_pBreakIt && g_pBreakIt->GetBreakIter().is()); const uno::Reference< XBreakIterator > &rxBreak = g_pBreakIt->GetBreakIter(); sal_Int16 nWordType = WordType::DICTIONARY_WORD; - lang::Locale aLocale( g_pBreakIt->GetLocale( GetLang( nPos ) ) ); + lang::Locale aLocale( g_pBreakIt->GetLocale(pTextNode->GetLang(rPos.nContent.GetIndex())) ); Boundary aBndry = - rxBreak->getWordBoundary( m_Text, nPos, aLocale, nWordType, true ); + rxBreak->getWordBoundary(rText, sal_Int32(nPos), aLocale, nWordType, true); // if no word was found use previous word (if any) if (aBndry.startPos == aBndry.endPos) { - aBndry = rxBreak->previousWord( m_Text, nPos, aLocale, nWordType ); + aBndry = rxBreak->previousWord(rText, sal_Int32(nPos), aLocale, nWordType); } // check if word was found and if it uses a symbol font, if so // enforce returning an empty string - if (aBndry.endPos != aBndry.startPos && IsSymbolAt(aBndry.startPos)) + if (aBndry.endPos != aBndry.startPos + && IsSymbolAt(TextFrameIndex(aBndry.startPos))) + { aBndry.endPos = aBndry.startPos; + } // can have -1 as start/end of bounds not found - aBndry.startPos = clipIndexBounds(m_Text, aBndry.startPos); - aBndry.endPos = clipIndexBounds(m_Text, aBndry.endPos); + aBndry.startPos = clipIndexBounds(rText, aBndry.startPos); + aBndry.endPos = clipIndexBounds(rText, aBndry.endPos); - return m_Text.copy(aBndry.startPos, + return rText.copy(aBndry.startPos, aBndry.endPos - aBndry.startPos); } |
