Kaydet (Commit) 9bda4a67 authored tarafından Michael Stahl's avatar Michael Stahl

sw_redlinehide_2: adapt SwEditShell::GetCurWord()

Move SwTextNode::GetCurWord() to SwTextFrame, this was the only caller.

Change-Id: Id26cea92e1ca507fd82c5c75bc5a6eedb531d78d
üst 6410a654
......@@ -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 & );
......
......@@ -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( )
......
......@@ -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;
};
......
......@@ -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);
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment