[Libreoffice-commits] core.git: Branch 'private/mst/sw_redlinehide_3' - 10 commits - sw/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Tue Oct 9 15:25:18 UTC 2018
Rebased ref, commits from common ancestor:
commit 2ea5807648b0aa0dbe209a338e1205a60db79930
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Tue Oct 9 16:32:33 2018 +0200
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Tue Oct 9 16:34:42 2018 +0200
sw_redlinehide_3: trivial conversions in new code in fntcache.cxx
Change-Id: Id625ee27e69800780c04ea80d888f606cde0f308
diff --git a/sw/source/core/txtnode/fntcache.cxx b/sw/source/core/txtnode/fntcache.cxx
index dd377d0c1090..5288649caaa2 100644
--- a/sw/source/core/txtnode/fntcache.cxx
+++ b/sw/source/core/txtnode/fntcache.cxx
@@ -1450,7 +1450,7 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf )
// get screen array
std::unique_ptr<long[]> pScrArray(new long[sal_Int32(rInf.GetLen())]);
- SwTextGlyphsKey aGlyphsKey{ &rInf.GetOut(), rInf.GetText(), rInf.GetIdx(), rInf.GetLen() };
+ SwTextGlyphsKey aGlyphsKey{ &rInf.GetOut(), rInf.GetText(), sal_Int32(rInf.GetIdx()), sal_Int32(rInf.GetLen()) };
SalLayoutGlyphs* pGlyphs = lcl_CreateLayout(aGlyphsKey, m_aTextGlyphs[aGlyphsKey]);
rInf.GetOut().GetTextArray( rInf.GetText(), pScrArray.get(),
sal_Int32(rInf.GetIdx()), sal_Int32(rInf.GetLen()), nullptr, pGlyphs);
@@ -1465,7 +1465,7 @@ void SwFntObj::DrawText( SwDrawTextInfo &rInf )
if( !m_pPrtFont->IsSameInstance( m_pPrinter->GetFont() ) )
m_pPrinter->SetFont( *m_pPrtFont );
}
- aGlyphsKey = SwTextGlyphsKey{ m_pPrinter, rInf.GetText(), rInf.GetIdx(), rInf.GetLen() };
+ aGlyphsKey = SwTextGlyphsKey{ m_pPrinter, rInf.GetText(), sal_Int32(rInf.GetIdx()), sal_Int32(rInf.GetLen()) };
pGlyphs = lcl_CreateLayout(aGlyphsKey, m_aTextGlyphs[aGlyphsKey]);
m_pPrinter->GetTextArray(rInf.GetText(), pKernArray.get(),
sal_Int32(rInf.GetIdx()), sal_Int32(rInf.GetLen()), nullptr, pGlyphs);
@@ -2039,7 +2039,7 @@ Size SwFntObj::GetTextSize( SwDrawTextInfo& rInf )
}
else
{
- SwTextGlyphsKey aGlyphsKey{ &rInf.GetOut(), rInf.GetText(), rInf.GetIdx(), nLn };
+ SwTextGlyphsKey aGlyphsKey{ &rInf.GetOut(), rInf.GetText(), sal_Int32(rInf.GetIdx()), sal_Int32(nLn) };
SalLayoutGlyphs* pGlyphs = lcl_CreateLayout(aGlyphsKey, m_aTextGlyphs[aGlyphsKey]);
aTextSize.setWidth( rInf.GetOut().GetTextWidth( rInf.GetText(),
sal_Int32(rInf.GetIdx()), sal_Int32(nLn),
@@ -2076,7 +2076,7 @@ TextFrameIndex SwFntObj::GetCursorOfst(SwDrawTextInfo &rInf)
{
m_pPrinter->SetLayoutMode( rInf.GetOut().GetLayoutMode() );
m_pPrinter->SetDigitLanguage( rInf.GetOut().GetDigitLanguage() );
- SwTextGlyphsKey aGlyphsKey{ m_pPrinter, rInf.GetText(), rInf.GetIdx(), rInf.GetLen() };
+ SwTextGlyphsKey aGlyphsKey{ m_pPrinter, rInf.GetText(), sal_Int32(rInf.GetIdx()), sal_Int32(rInf.GetLen()) };
SalLayoutGlyphs* pGlyphs = lcl_CreateLayout(aGlyphsKey, m_aTextGlyphs[aGlyphsKey]);
m_pPrinter->GetTextArray( rInf.GetText(), pKernArray.get(),
sal_Int32(rInf.GetIdx()), sal_Int32(rInf.GetLen()), nullptr, pGlyphs);
@@ -2491,7 +2491,7 @@ TextFrameIndex SwFont::GetTextBreak(SwDrawTextInfo const & rInf, long nTextWidth
{
SwFntAccess aFntAccess(m_aSub[m_nActual].m_nFontCacheId, m_aSub[m_nActual].m_nFontIndex,
&m_aSub[m_nActual], rInf.GetShell());
- SwTextGlyphsKey aGlyphsKey{ &rInf.GetOut(), *pTmpText, nTmpIdx, nTmpLen };
+ SwTextGlyphsKey aGlyphsKey{ &rInf.GetOut(), *pTmpText, sal_Int32(nTmpIdx), sal_Int32(nTmpLen) };
SalLayoutGlyphs* pGlyphs
= lcl_CreateLayout(aGlyphsKey, aFntAccess.Get()->GetTextGlyphs()[aGlyphsKey]);
nTextBreak = TextFrameIndex(rInf.GetOut().GetTextBreak(
commit fc9f27d33b592776c014bea491ca0fe5e362b723
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Tue Oct 9 16:32:02 2018 +0200
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Tue Oct 9 16:34:42 2018 +0200
sw_redlinehide_3: trivial conversions in new code in xmldump.cxx
Change-Id: I37624c92549b4b3cd4d9616a4952163bf51526ef
diff --git a/sw/source/core/text/xmldump.cxx b/sw/source/core/text/xmldump.cxx
index 6dc0eb71971d..90d73c75dab5 100644
--- a/sw/source/core/text/xmldump.cxx
+++ b/sw/source/core/text/xmldump.cxx
@@ -133,12 +133,12 @@ class XmlPortionDumper:public SwPortionHandler
xmlTextWriterWriteFormatAttribute(writer, BAD_CAST("nHeight"), "%i", static_cast<int>(nHeight));
if (nWidth > 0)
xmlTextWriterWriteFormatAttribute(writer, BAD_CAST("nWidth"), "%i", static_cast<int>(nWidth));
- if (nLength > 0)
+ if (nLength > TextFrameIndex(0))
xmlTextWriterWriteAttribute(writer, BAD_CAST("Portion"),
- BAD_CAST(m_rText.copy(ofs, nLength).toUtf8().getStr()));
+ BAD_CAST(m_rText.copy(sal_Int32(ofs), sal_Int32(nLength)).toUtf8().getStr()));
xmlTextWriterEndElement( writer );
- m_aLine += m_rText.copy(ofs, nLength);
+ m_aLine += m_rText.copy(sal_Int32(ofs), sal_Int32(nLength));
ofs += nLength;
}
commit 8f5fe3e08d708677d93b67cf98a0de384550f929
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Tue Oct 9 16:17:03 2018 +0200
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Tue Oct 9 16:34:42 2018 +0200
sw_redlinehide_3: bug in UpdateMergedParaForMove
lcl_SetWrong works on model positions.
Change-Id: I34353a09260e336c15696a7bc48a5922bfd92e4a
diff --git a/sw/source/core/text/txtfrm.cxx b/sw/source/core/text/txtfrm.cxx
index af0422aa09ea..5603d7800914 100644
--- a/sw/source/core/text/txtfrm.cxx
+++ b/sw/source/core/text/txtfrm.cxx
@@ -1724,7 +1724,7 @@ void UpdateMergedParaForMove(sw::MergedPara & rMerged,
if(nDeleted)
{
// InvalidateRange/lcl_SetScriptInval was called sufficiently for SwInsText
- lcl_SetWrong(rTextFrame, rDestNode, nStart, -nDeleted, false);
+ lcl_SetWrong(rTextFrame, rDestNode, nStart, it.first - it.second, false);
if (rTextFrame.HasFollow())
{
TextFrameIndex const nIndex(sw::MapModelToView(rMerged, &rDestNode, nStart));
commit 9b2fcab6b5375e39484430aa238f5ce1a6613c82
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Tue Oct 9 14:49:23 2018 +0200
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Tue Oct 9 16:34:42 2018 +0200
sw_redlinehide_3: convert even more SwAccessibleParagraph functions
... and finally remove GetTextNode().
Change-Id: I7ad91bf709b705afcf7ada79fd2a97335329e8b7
diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx
index 02e20ce9e1aa..85cea101d9c3 100644
--- a/sw/source/core/access/accpara.cxx
+++ b/sw/source/core/access/accpara.cxx
@@ -118,17 +118,6 @@ namespace com { namespace sun { namespace star {
const sal_Char sServiceName[] = "com.sun.star.text.AccessibleParagraphView";
const sal_Char sImplementationName[] = "com.sun.star.comp.Writer.SwAccessibleParagraphView";
-const SwTextNode* SwAccessibleParagraph::GetTextNode() const
-{
- const SwFrame* pFrame = GetFrame();
- OSL_ENSURE( pFrame->IsTextFrame(), "The text frame has mutated!" );
-
- const SwTextNode* pNode = static_cast<const SwTextFrame*>(pFrame)->GetTextNode();
- OSL_ENSURE( pNode != nullptr, "A text frame without a text node." );
-
- return pNode;
-}
-
OUString const & SwAccessibleParagraph::GetString()
{
return GetPortionData().GetAccessibleString();
@@ -223,7 +212,8 @@ SwPaM* SwAccessibleParagraph::GetCursor( const bool _bForSelection )
bool SwAccessibleParagraph::IsHeading() const
{
- const SwTextNode *pTextNd = GetTextNode();
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame()));
+ const SwTextNode *pTextNd = pFrame->GetTextNodeForParaProps();
return pTextNd->IsOutline();
}
@@ -246,9 +236,10 @@ void SwAccessibleParagraph::GetStates(
// FOCUSED (simulates node index of cursor)
SwPaM* pCaret = GetCursor( false ); // #i27301# - consider adjusted method signature
- const SwTextNode* pTextNd = GetTextNode();
- if( pCaret != nullptr && pTextNd != nullptr &&
- pTextNd->GetIndex() == pCaret->GetPoint()->nNode.GetIndex() &&
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame()));
+ assert(pFrame);
+ if (pCaret != nullptr &&
+ sw::FrameContainsNode(*pFrame, pCaret->GetPoint()->nNode.GetIndex()) &&
m_nOldCaretPos != -1)
{
vcl::Window *pWin = GetWindow();
@@ -544,7 +535,9 @@ bool SwAccessibleParagraph::IsValidRange(
SwTOXSortTabBase* SwAccessibleParagraph::GetTOXSortTabBase()
{
- const SwTextNode* pTextNd = GetTextNode();
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame()));
+ assert(pFrame);
+ const SwTextNode *const pTextNd = pFrame->GetTextNodeFirst();
if( pTextNd )
{
const SwSectionNode * pSectNd = pTextNd->FindSectionNode();
@@ -582,15 +575,7 @@ const SwRangeRedline* SwAccessibleParagraph::GetRedlineAtIndex()
if ( pCrSr )
{
SwPosition* pStart = pCrSr->Start();
- const SwTextNode* pNode = GetTextNode();
- if ( pNode )
- {
- const SwDoc* pDoc = pNode->GetDoc();
- if ( pDoc )
- {
- pRedline = pDoc->getIDocumentRedlineAccess().GetRedline( *pStart, nullptr );
- }
- }
+ pRedline = pStart->GetDoc()->getIDocumentRedlineAccess().GetRedline(*pStart, nullptr);
}
return pRedline;
@@ -1253,13 +1238,11 @@ OUString SwAccessibleParagraph::GetFieldTypeNameAtIndex(sal_Int32 nIndex)
sal_Int32 nFieldIndex = GetPortionData().GetFieldIndex(nIndex);
if (nFieldIndex >= 0)
{
- const SwpHints* pSwpHints = GetTextNode()->GetpSwpHints();
- if (pSwpHints)
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame()));
+ sw::MergedAttrIter iter(*pFrame);
+ while (SwTextAttr const*const pHt = iter.NextAttr())
{
- const size_t nSize = pSwpHints->Count();
- for( size_t i = 0; i < nSize; ++i )
{
- const SwTextAttr* pHt = pSwpHints->Get(i);
if ( ( pHt->Which() == RES_TXTATR_FIELD
|| pHt->Which() == RES_TXTATR_ANNOTATION
|| pHt->Which() == RES_TXTATR_INPUTFIELD )
@@ -1539,7 +1522,8 @@ void SwAccessibleParagraph::_getDefaultAttributesImpl(
const bool bOnlyCharAttrs )
{
// retrieve default attributes
- const SwTextNode* pTextNode( GetTextNode() );
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame()));
+ const SwTextNode *const pTextNode(pFrame->GetTextNodeForParaProps());
std::unique_ptr<SfxItemSet> pSet;
if ( !bOnlyCharAttrs )
{
@@ -1876,7 +1860,8 @@ void SwAccessibleParagraph::_getSupplementalAttributesImpl(
const uno::Sequence< OUString >& aRequestedAttributes,
tAccParaPropValMap& rSupplementalAttrSeq )
{
- const SwTextNode* pTextNode( GetTextNode() );
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame()));
+ const SwTextNode *const pTextNode(pFrame->GetTextNodeForParaProps());
std::unique_ptr<SfxItemSet> pSet;
pSet.reset(
new SfxItemSet(
@@ -3062,13 +3047,22 @@ sal_Int32 SAL_CALL SwAccessibleParagraph::getSelectedPortionCount( )
{
SolarMutexGuard g;
- sal_Int32 nSeleted = 0;
+ sal_Int32 nSelected = 0;
SwPaM* pCursor = GetCursor( true );
if( pCursor != nullptr )
{
// get SwPosition for my node
- const SwTextNode* pNode = GetTextNode();
- sal_uLong nHere = pNode->GetIndex();
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame()));
+ sal_uLong nFirstNode(pFrame->GetTextNodeFirst()->GetIndex());
+ sal_uLong nLastNode;
+ if (sw::MergedPara const*const pMerged = pFrame->GetMergedPara())
+ {
+ nLastNode = pMerged->pLastNode->GetIndex();
+ }
+ else
+ {
+ nLastNode = nFirstNode;
+ }
// iterate over ring
for(SwPaM& rTmpCursor : pCursor->GetRingContainer())
@@ -3076,22 +3070,21 @@ sal_Int32 SAL_CALL SwAccessibleParagraph::getSelectedPortionCount( )
// ignore, if no mark
if( rTmpCursor.HasMark() )
{
- // check whether nHere is 'inside' pCursor
+ // check whether frame's node(s) are 'inside' pCursor
SwPosition* pStart = rTmpCursor.Start();
sal_uLong nStartIndex = pStart->nNode.GetIndex();
SwPosition* pEnd = rTmpCursor.End();
sal_uLong nEndIndex = pEnd->nNode.GetIndex();
- if( ( nHere >= nStartIndex ) &&
- ( nHere <= nEndIndex ) )
+ if ((nStartIndex <= nLastNode) && (nFirstNode <= nEndIndex))
{
- nSeleted++;
+ nSelected++;
}
// else: this PaM doesn't point to this paragraph
}
// else: this PaM is collapsed and doesn't select anything
}
}
- return nSeleted;
+ return nSelected;
}
@@ -3133,8 +3126,17 @@ sal_Bool SAL_CALL SwAccessibleParagraph::removeSelection( sal_Int32 selectionInd
bool bRet = false;
// get SwPosition for my node
- const SwTextNode* pNode = GetTextNode();
- sal_uLong nHere = pNode->GetIndex();
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame()));
+ sal_uLong nFirstNode(pFrame->GetTextNodeFirst()->GetIndex());
+ sal_uLong nLastNode;
+ if (sw::MergedPara const*const pMerged = pFrame->GetMergedPara())
+ {
+ nLastNode = pMerged->pLastNode->GetIndex();
+ }
+ else
+ {
+ nLastNode = nFirstNode;
+ }
// iterate over ring
SwPaM* pRingStart = pCursor;
@@ -3143,13 +3145,12 @@ sal_Bool SAL_CALL SwAccessibleParagraph::removeSelection( sal_Int32 selectionInd
// ignore, if no mark
if( pCursor->HasMark() )
{
- // check whether nHere is 'inside' pCursor
+ // check whether frame's node(s) are 'inside' pCursor
SwPosition* pStart = pCursor->Start();
sal_uLong nStartIndex = pStart->nNode.GetIndex();
SwPosition* pEnd = pCursor->End();
sal_uLong nEndIndex = pEnd->nNode.GetIndex();
- if( ( nHere >= nStartIndex ) &&
- ( nHere <= nEndIndex ) )
+ if ((nStartIndex <= nLastNode) && (nFirstNode <= nEndIndex))
{
if( nSelected == 0 )
{
diff --git a/sw/source/core/access/accpara.hxx b/sw/source/core/access/accpara.hxx
index 676e99a9023b..26afc0df73eb 100644
--- a/sw/source/core/access/accpara.hxx
+++ b/sw/source/core/access/accpara.hxx
@@ -88,9 +88,6 @@ class SwAccessibleParagraph :
std::unique_ptr<SwParaChangeTrackingInfo> mpParaChangeTrackInfo; // #i108125#
- /// get the SwTextNode (requires frame; check before)
- const SwTextNode* GetTextNode() const;
-
/// get the (accessible) text string (requires frame; check before)
OUString const & GetString();
commit 95c69f976497417c95e0830b65d3bea90ae7d63e
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Tue Oct 9 15:53:17 2018 +0200
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Tue Oct 9 16:34:42 2018 +0200
sw_redlinehide_3: convert SwAccessibleParagraph::_correctValues()
Tricky usage of SwWrongList here, let's hope this works...
Also, there is a similar bug here, the nIndex is in a11y coordinates
but it was used directly as input to SwWrongList; better to convert
first.
Change-Id: I9b49b4dc84089c03df0e1302512d13d289d16161
diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx
index 238202896aab..02e20ce9e1aa 100644
--- a/sw/source/core/access/accpara.cxx
+++ b/sw/source/core/access/accpara.cxx
@@ -2000,7 +2000,20 @@ void SwAccessibleParagraph::_correctValues( const sal_Int32 nIndex,
}
}
- const SwTextNode* pTextNode( GetTextNode() );
+ // sw_redlinehide: this function only needs SwWrongList for 1 character,
+ // and the end is excluded by InWrongWord(),
+ // so it ought to work to just pick the wrong-list/node that contains
+ // the character following the given nIndex
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame()));
+ TextFrameIndex const nCorePos(GetPortionData().GetCoreViewPosition(nIndex));
+ std::pair<SwTextNode*, sal_Int32> pos(pFrame->MapViewToModel(nCorePos));
+ if (pos.first->Len() == pos.second
+ && nCorePos != TextFrameIndex(pFrame->GetText().getLength()))
+ {
+ pos = pFrame->MapViewToModel(nCorePos + TextFrameIndex(1)); // try this one instead
+ assert(pos.first->Len() != pos.second);
+ }
+ const SwTextNode *const pTextNode(pos.first);
sal_Int32 nValues = rValues.size();
for (sal_Int32 i = 0; i < nValues; ++i)
@@ -2067,7 +2080,7 @@ void SwAccessibleParagraph::_correctValues( const sal_Int32 nIndex,
const SwWrongList* pWrongList = pTextNode->GetWrong();
if( nullptr != pWrongList )
{
- sal_Int32 nBegin = nIndex;
+ sal_Int32 nBegin = pos.second;
sal_Int32 nLen = 1;
if (pWrongList->InWrongWord(nBegin, nLen) && !pTextNode->IsSymbolAt(nBegin))
{
@@ -2088,7 +2101,7 @@ void SwAccessibleParagraph::_correctValues( const sal_Int32 nIndex,
const SwWrongList* pWrongList = pTextNode->GetWrong();
if( nullptr != pWrongList )
{
- sal_Int32 nBegin = nIndex;
+ sal_Int32 nBegin = pos.second;
sal_Int32 nLen = 1;
if (pWrongList->InWrongWord(nBegin, nLen) && !pTextNode->IsSymbolAt(nBegin))
{
commit d9f816b574ec4b8ea85bd763291bfb328a105094
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Tue Oct 9 13:59:24 2018 +0200
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Tue Oct 9 16:33:06 2018 +0200
sw_redlinehide_3: convert SwAccessibleParagraph::_getRunAttributesImpl
There appears to be a bug here, in that the nIndex is an index into
the accessiblity string, but it was used without conversion as a
model position in SwPosition; let's try to fix that.
Change-Id: I7a43ceacfe59102577f39ab4b8fec3b495db345d
diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx
index b7bd65c065a2..238202896aab 100644
--- a/sw/source/core/access/accpara.cxx
+++ b/sw/source/core/access/accpara.cxx
@@ -1751,14 +1751,16 @@ void SwAccessibleParagraph::_getRunAttributesImpl(
{
// create PaM for character at position <nIndex>
std::unique_ptr<SwPaM> pPaM;
+ const TextFrameIndex nCorePos(GetPortionData().GetCoreViewPosition(nIndex));
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame()));
+ SwPosition const aModelPos(pFrame->MapViewToModelPos(nCorePos));
+ SwTextNode *const pTextNode(aModelPos.nNode.GetNode().GetTextNode());
{
- const SwTextNode* pTextNode( GetTextNode() );
- std::unique_ptr<SwPosition> pStartPos( new SwPosition( *pTextNode ) );
- pStartPos->nContent.Assign( const_cast<SwTextNode*>(pTextNode), nIndex );
- std::unique_ptr<SwPosition> pEndPos( new SwPosition( *pTextNode ) );
- pEndPos->nContent.Assign( const_cast<SwTextNode*>(pTextNode), nIndex+1 );
-
- pPaM.reset(new SwPaM( *pStartPos, *pEndPos ));
+ SwPosition const aEndPos(*pTextNode,
+ aModelPos.nContent.GetIndex() == pTextNode->Len()
+ ? pTextNode->Len() // ???
+ : aModelPos.nContent.GetIndex() + 1);
+ pPaM.reset(new SwPaM(aModelPos, aEndPos));
}
// retrieve character attributes for the created PaM <pPaM>
@@ -1771,7 +1773,6 @@ void SwAccessibleParagraph::_getRunAttributesImpl(
// SwXTextCursor::GetCursorAttr( *pPaM, aSet, sal_True, sal_True );
// get character attributes from automatic paragraph style and merge these into <aSet>
{
- const SwTextNode* pTextNode( GetTextNode() );
if ( pTextNode->HasSwAttrSet() )
{
SfxItemSet aAutomaticParaStyleCharAttrs( pPaM->GetDoc()->GetAttrPool(),
commit 458fa203e0fa9761dc368344268dda8ed125df9f
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Tue Oct 9 12:59:01 2018 +0200
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Tue Oct 9 16:33:06 2018 +0200
sw_redlinehide_3: convert more SwAccessibleParagraph functions
Change-Id: I33079154b4775b1df55693bf6046adbf27b0c1e3
diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx
index 1466bc4fd44e..b7bd65c065a2 100644
--- a/sw/source/core/access/accpara.cxx
+++ b/sw/source/core/access/accpara.cxx
@@ -149,20 +149,21 @@ sal_Int32 SwAccessibleParagraph::GetCaretPos()
if( pCaret != nullptr )
{
- const SwTextNode* pNode = GetTextNode();
+ SwTextFrame const*const pTextFrame(static_cast<SwTextFrame const*>(GetFrame()));
+ assert(pTextFrame);
// check whether the point points into 'our' node
SwPosition* pPoint = pCaret->GetPoint();
- if( pNode->GetIndex() == pPoint->nNode.GetIndex() )
+ if (sw::FrameContainsNode(*pTextFrame, pPoint->nNode.GetIndex()))
{
// same node? Then check whether it's also within 'our' part
// of the paragraph
- const sal_Int32 nIndex = pPoint->nContent.GetIndex();
+ const TextFrameIndex nIndex = pTextFrame->MapModelToViewPos(*pPoint);
if(!GetPortionData().IsValidCorePosition( nIndex ) ||
- ( GetPortionData().IsZeroCorePositionData() && nIndex== 0) )
+ (GetPortionData().IsZeroCorePositionData()
+ && nIndex == TextFrameIndex(0)))
{
- const SwTextFrame *pTextFrame = dynamic_cast<const SwTextFrame*>( GetFrame() );
- bool bFormat = (pTextFrame && pTextFrame->HasPara());
+ bool bFormat = pTextFrame->HasPara();
if(bFormat)
{
ClearPortionData();
@@ -501,17 +502,17 @@ SwXTextPortion* SwAccessibleParagraph::CreateUnoPortion(
IsValidRange(nStartIndex, nEndIndex, GetString().getLength()),
"please check parameters before calling this method" );
- const sal_Int32 nStart = GetPortionData().GetCoreViewPosition(nStartIndex);
- const sal_Int32 nEnd = (nEndIndex == -1) ? (nStart + 1) :
- GetPortionData().GetCoreViewPosition(nEndIndex);
+ const TextFrameIndex nStart = GetPortionData().GetCoreViewPosition(nStartIndex);
+ const TextFrameIndex nEnd = (nEndIndex == -1)
+ ? (nStart + TextFrameIndex(1))
+ : GetPortionData().GetCoreViewPosition(nEndIndex);
// create UNO cursor
- SwTextNode* pTextNode = const_cast<SwTextNode*>( GetTextNode() );
- SwIndex aIndex( pTextNode, nStart );
- SwPosition aStartPos( *pTextNode, aIndex );
- auto pUnoCursor(pTextNode->GetDoc()->CreateUnoCursor( aStartPos ));
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame()));
+ SwPosition aStartPos(pFrame->MapViewToModelPos(nStart));
+ auto pUnoCursor(const_cast<SwDoc&>(pFrame->GetDoc()).CreateUnoCursor(aStartPos));
pUnoCursor->SetMark();
- pUnoCursor->GetMark()->nContent = nEnd;
+ *pUnoCursor->GetMark() = pFrame->MapViewToModelPos(nEnd);
// create a (dummy) text portion to be returned
uno::Reference<text::XText> aEmpty;
@@ -618,9 +619,9 @@ bool SwAccessibleParagraph::GetWordBoundary(
assert(g_pBreakIt && g_pBreakIt->GetBreakIter().is());
// get locale for this position
- const sal_Int32 nModelPos = GetPortionData().GetCoreViewPosition(nPos);
- lang::Locale aLocale = g_pBreakIt->GetLocale(
- GetTextNode()->GetLang( nModelPos ) );
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame()));
+ const TextFrameIndex nCorePos = GetPortionData().GetCoreViewPosition(nPos);
+ lang::Locale aLocale = g_pBreakIt->GetLocale(pFrame->GetLangOfChar(nCorePos, 0, true));
// which type of word are we interested in?
// (DICTIONARY_WORD includes punctuation, ANY_WORD doesn't.)
@@ -685,9 +686,9 @@ bool SwAccessibleParagraph::GetGlyphBoundary(
assert(g_pBreakIt && g_pBreakIt->GetBreakIter().is());
// get locale for this position
- const sal_Int32 nModelPos = GetPortionData().GetCoreViewPosition(nPos);
- lang::Locale aLocale = g_pBreakIt->GetLocale(
- GetTextNode()->GetLang( nModelPos ) );
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame()));
+ const TextFrameIndex nCorePos = GetPortionData().GetCoreViewPosition(nPos);
+ lang::Locale aLocale = g_pBreakIt->GetLocale(pFrame->GetLangOfChar(nCorePos, 0, true));
// get word boundary, as the Break-Iterator sees fit.
const sal_Int16 nIterMode = i18n::CharacterIteratorMode::SKIPCELL;
@@ -781,8 +782,7 @@ lang::Locale SAL_CALL SwAccessibleParagraph::getLocale()
throw uno::RuntimeException("no SwTextFrame", static_cast<cppu::OWeakObject*>(this));
}
- const SwTextNode *pTextNd = pTextFrame->GetTextNode();
- lang::Locale aLoc( g_pBreakIt->GetLocale( pTextNd->GetLang( 0 ) ) );
+ lang::Locale aLoc(g_pBreakIt->GetLocale(pTextFrame->GetLangOfChar(TextFrameIndex(0), 0, true)));
return aLoc;
}
@@ -833,11 +833,10 @@ void SAL_CALL SwAccessibleParagraph::grabFocus()
SwCursorShell *pCursorSh = GetCursorShell();
SwPaM *pCursor = GetCursor( false ); // #i27301# - consider new method signature
const SwTextFrame *pTextFrame = static_cast<const SwTextFrame*>( GetFrame() );
- const SwTextNode* pTextNd = pTextFrame->GetTextNode();
- if( pCursorSh != nullptr && pTextNd != nullptr &&
+ if (pCursorSh != nullptr &&
( pCursor == nullptr ||
- pCursor->GetPoint()->nNode.GetIndex() != pTextNd->GetIndex() ||
+ !sw::FrameContainsNode(*pTextFrame, pCursor->GetPoint()->nNode.GetIndex()) ||
!pTextFrame->IsInside(pTextFrame->MapModelToViewPos(*pCursor->GetPoint()))))
{
// create pam for selection
@@ -1139,9 +1138,9 @@ sal_Bool SAL_CALL SwAccessibleParagraph::setCaretPosition( sal_Int32 nIndex )
if( pCursorShell != nullptr )
{
// create pam for selection
- SwTextNode* pNode = const_cast<SwTextNode*>( GetTextNode() );
- SwIndex aIndex(pNode, GetPortionData().GetCoreViewPosition(nIndex));
- SwPosition aStartPos( *pNode, aIndex );
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame()));
+ TextFrameIndex const nFrameIndex(GetPortionData().GetCoreViewPosition(nIndex));
+ SwPosition aStartPos(pFrame->MapViewToModelPos(nFrameIndex));
SwPaM aPaM( aStartPos );
// set PaM at cursor shell
@@ -1188,26 +1187,25 @@ css::uno::Sequence< css::style::TabStop > SwAccessibleParagraph::GetCurrentTabSt
aMoveState.m_bRealHeight = true;
aMoveState.m_bRealWidth = true;
SwSpecialPos aSpecialPos;
- SwTextNode* pNode = const_cast<SwTextNode*>( GetTextNode() );
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame()));
/* #i12332# FillSpecialPos does not accept nIndex ==
GetString().getLength(). In that case nPos is set to the
length of the string in the core. This way GetCharRect
returns the rectangle for a cursor at the end of the
paragraph. */
- const sal_Int32 nPos = bBehindText
- ? pNode->GetText().getLength()
+ const TextFrameIndex nPos = bBehindText
+ ? TextFrameIndex(pFrame->GetText().getLength())
: GetPortionData().FillSpecialPos(nIndex, aSpecialPos, aMoveState.m_pSpecialPos );
// call GetCharRect
SwRect aCoreRect;
- SwIndex aIndex( pNode, nPos );
- SwPosition aPosition( *pNode, aIndex );
+ SwPosition aPosition(pFrame->MapViewToModelPos(nPos));
GetFrame()->GetCharRect( aCoreRect, aPosition, &aMoveState );
// already get the caret position
css::uno::Sequence< css::style::TabStop > tabs;
- const sal_Int32 nStrLen = GetTextNode()->GetText().getLength();
+ const sal_Int32 nStrLen = pFrame->GetText().getLength();
if( nStrLen > 0 )
{
SwFrame* pTFrame = const_cast<SwFrame*>(GetFrame());
@@ -2172,21 +2170,20 @@ awt::Rectangle SwAccessibleParagraph::getCharacterBounds(
aMoveState.m_bRealHeight = true;
aMoveState.m_bRealWidth = true;
SwSpecialPos aSpecialPos;
- SwTextNode* pNode = const_cast<SwTextNode*>( GetTextNode() );
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame()));
/** #i12332# FillSpecialPos does not accept nIndex ==
GetString().getLength(). In that case nPos is set to the
length of the string in the core. This way GetCharRect
returns the rectangle for a cursor at the end of the
paragraph. */
- const sal_Int32 nPos = bBehindText
- ? pNode->GetText().getLength()
+ const TextFrameIndex nPos = bBehindText
+ ? TextFrameIndex(pFrame->GetText().getLength())
: GetPortionData().FillSpecialPos(nIndex, aSpecialPos, aMoveState.m_pSpecialPos );
// call GetCharRect
SwRect aCoreRect;
- SwIndex aIndex( pNode, nPos );
- SwPosition aPosition( *pNode, aIndex );
+ SwPosition aPosition(pFrame->MapViewToModelPos(nPos));
GetFrame()->GetCharRect( aCoreRect, aPosition, &aMoveState );
// translate core coordinates into accessibility coordinates
@@ -2223,11 +2220,6 @@ sal_Int32 SwAccessibleParagraph::getIndexAtPoint( const awt::Point& rPoint )
ThrowIfDisposed();
- // construct SwPosition (where GetCursorOfst() will put the result into)
- SwTextNode* pNode = const_cast<SwTextNode*>( GetTextNode() );
- SwIndex aIndex( pNode, 0);
- SwPosition aPos( *pNode, aIndex );
-
// construct Point (translate into layout coordinates)
vcl::Window *pWin = GetWindow();
if (!pWin)
@@ -2262,14 +2254,17 @@ sal_Int32 SwAccessibleParagraph::getIndexAtPoint( const awt::Point& rPoint )
OSL_ENSURE( GetFrame() != nullptr, "The text frame has vanished!" );
OSL_ENSURE( GetFrame()->IsTextFrame(), "The text frame has mutated!" );
const SwTextFrame* pFrame = static_cast<const SwTextFrame*>( GetFrame() );
+ // construct SwPosition (where GetCursorOfst() will put the result into)
+ SwTextNode* pNode = const_cast<SwTextNode*>(pFrame->GetTextNodeFirst());
+ SwPosition aPos(*pNode, 0);
SwCursorMoveState aMoveState;
aMoveState.m_bPosMatchesBounds = true;
const bool bSuccess = pFrame->GetCursorOfst( &aPos, aCorePoint, &aMoveState );
- SwIndex aContentIdx = aPos.nContent;
- const sal_Int32 nIndex = aContentIdx.GetIndex();
- if ( nIndex > 0 )
+ TextFrameIndex nIndex = pFrame->MapModelToViewPos(aPos);
+ if (TextFrameIndex(0) < nIndex)
{
+ assert(bSuccess);
SwRect aResultRect;
pFrame->GetCharRect( aResultRect, aPos );
bool bVert = pFrame->IsVertical();
@@ -2279,19 +2274,20 @@ sal_Int32 SwAccessibleParagraph::getIndexAtPoint( const awt::Point& rPoint )
( bVert && aResultRect.Pos().getY() > aCorePoint.getY()) ||
( bR2L && aResultRect.Right() < aCorePoint.getX()) )
{
- SwIndex aIdxPrev( pNode, nIndex - 1);
- SwPosition aPosPrev( *pNode, aIdxPrev );
+ SwPosition aPosPrev(pFrame->MapViewToModelPos(nIndex - TextFrameIndex(1)));
SwRect aResultRectPrev;
pFrame->GetCharRect( aResultRectPrev, aPosPrev );
if ( (!bVert && aResultRectPrev.Pos().getX() < aCorePoint.getX() && aResultRect.Pos().getY() == aResultRectPrev.Pos().getY()) ||
( bVert && aResultRectPrev.Pos().getY() < aCorePoint.getY() && aResultRect.Pos().getX() == aResultRectPrev.Pos().getX()) ||
( bR2L && aResultRectPrev.Right() > aCorePoint.getX() && aResultRect.Pos().getY() == aResultRectPrev.Pos().getY()) )
- aPos = aPosPrev;
+ {
+ --nIndex;
+ }
}
}
- return bSuccess ?
- GetPortionData().GetAccessiblePosition( aPos.nContent.GetIndex() )
+ return bSuccess
+ ? GetPortionData().GetAccessiblePosition(nIndex)
: -1;
}
@@ -2663,29 +2659,26 @@ sal_Bool SwAccessibleParagraph::replaceText(
if( !IsEditableState() )
return false;
- SwTextNode* pNode = const_cast<SwTextNode*>( GetTextNode() );
-
// translate positions
- sal_Int32 nStart;
- sal_Int32 nEnd;
+ TextFrameIndex nStart;
+ TextFrameIndex nEnd;
bool bSuccess = GetPortionData().GetEditableRange(
nStartIndex, nEndIndex, nStart, nEnd );
// edit only if the range is editable
if( bSuccess )
{
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame()));
// create SwPosition for nStartIndex
- SwIndex aIndex( pNode, nStart );
- SwPosition aStartPos( *pNode, aIndex );
+ SwPosition aStartPos(pFrame->MapViewToModelPos(nStart));
// create SwPosition for nEndIndex
- SwPosition aEndPos( aStartPos );
- aEndPos.nContent = nEnd;
+ SwPosition aEndPos(pFrame->MapViewToModelPos(nEnd));
// now create XTextRange as helper and set string
const uno::Reference<text::XTextRange> xRange(
SwXTextRange::CreateXTextRange(
- *pNode->GetDoc(), aStartPos, &aEndPos));
+ const_cast<SwDoc&>(pFrame->GetDoc()), aStartPos, &aEndPos));
xRange->setString(sReplacement);
// delete portion data
commit a44ea626244d42cfc135ba5d3704fb28610bc8da
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Tue Oct 9 11:14:05 2018 +0200
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Tue Oct 9 16:33:06 2018 +0200
sw_redlinehide_3: convert SwTextMarkupHelper and related ...
... functions in SwAccessibleParagraph, with the new WrongListIterator.
Change-Id: Ie401dd867a06a1963e49fa54afa978ad1f1346f5
diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx
index 57a596742571..1466bc4fd44e 100644
--- a/sw/source/core/access/accpara.cxx
+++ b/sw/source/core/access/accpara.cxx
@@ -3037,7 +3037,8 @@ sal_Int32 SAL_CALL SwAccessibleParagraph::getTextMarkupCount( sal_Int32 nTextMar
break;
default:
{
- pTextMarkupHelper.reset( new SwTextMarkupHelper( GetPortionData(), *GetTextNode() ) );
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame()));
+ pTextMarkupHelper.reset(new SwTextMarkupHelper(GetPortionData(), *pFrame));
}
}
@@ -3247,7 +3248,8 @@ sal_Int32 SAL_CALL SwAccessibleParagraph::addSelection( sal_Int32, sal_Int32 sta
break;
default:
{
- pTextMarkupHelper.reset( new SwTextMarkupHelper( GetPortionData(), *GetTextNode() ) );
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame()));
+ pTextMarkupHelper.reset(new SwTextMarkupHelper(GetPortionData(), *pFrame));
}
}
@@ -3281,7 +3283,8 @@ uno::Sequence< /*accessibility::*/TextSegment > SAL_CALL
break;
default:
{
- pTextMarkupHelper.reset( new SwTextMarkupHelper( GetPortionData(), *GetTextNode() ) );
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame()));
+ pTextMarkupHelper.reset(new SwTextMarkupHelper(GetPortionData(), *pFrame));
}
}
diff --git a/sw/source/core/access/textmarkuphelper.cxx b/sw/source/core/access/textmarkuphelper.cxx
index 2bbc8ab81984..8633789af140 100644
--- a/sw/source/core/access/textmarkuphelper.cxx
+++ b/sw/source/core/access/textmarkuphelper.cxx
@@ -36,27 +36,26 @@ using namespace com::sun::star;
namespace {
/// @throws css::lang::IllegalArgumentException
/// @throws css::uno::RuntimeException
- const SwWrongList* getTextMarkupList( const SwTextNode& rTextNode,
- const sal_Int32 nTextMarkupType )
+ SwWrongList const* (SwTextNode::*
+ getTextMarkupFunc(const sal_Int32 nTextMarkupType))() const
{
- const SwWrongList* pTextMarkupList( nullptr );
switch ( nTextMarkupType )
{
case text::TextMarkupType::SPELLCHECK:
{
- pTextMarkupList = rTextNode.GetWrong();
+ return &SwTextNode::GetWrong;
}
break;
case text::TextMarkupType::PROOFREADING:
{
// support not implemented yet
- pTextMarkupList = nullptr;
+ return nullptr;
}
break;
case text::TextMarkupType::SMARTTAG:
{
// support not implemented yet
- pTextMarkupList = nullptr;
+ return nullptr;
}
break;
default:
@@ -64,17 +63,14 @@ namespace {
throw lang::IllegalArgumentException();
}
}
-
- return pTextMarkupList;
}
}
// implementation of class <SwTextMarkupoHelper>
SwTextMarkupHelper::SwTextMarkupHelper( const SwAccessiblePortionData& rPortionData,
- const SwTextNode& rTextNode )
+ const SwTextFrame& rTextFrame)
: mrPortionData( rPortionData )
- // #i108125#
- , mpTextNode( &rTextNode )
+ , m_pTextFrame(&rTextFrame)
, mpTextMarkupList( nullptr )
{
}
@@ -83,7 +79,7 @@ SwTextMarkupHelper::SwTextMarkupHelper( const SwAccessiblePortionData& rPortionD
SwTextMarkupHelper::SwTextMarkupHelper( const SwAccessiblePortionData& rPortionData,
const SwWrongList& rTextMarkupList )
: mrPortionData( rPortionData )
- , mpTextNode( nullptr )
+ , m_pTextFrame( nullptr )
, mpTextMarkupList( &rTextMarkupList )
{
}
@@ -92,14 +88,19 @@ sal_Int32 SwTextMarkupHelper::getTextMarkupCount( const sal_Int32 nTextMarkupTyp
{
sal_Int32 nTextMarkupCount( 0 );
- // #i108125#
- const SwWrongList* pTextMarkupList =
- mpTextMarkupList
- ? mpTextMarkupList
- : getTextMarkupList( *mpTextNode, nTextMarkupType );
- if ( pTextMarkupList )
+ if (mpTextMarkupList)
+ {
+ nTextMarkupCount = mpTextMarkupList->Count();
+ }
+ else
{
- nTextMarkupCount = pTextMarkupList->Count();
+ assert(m_pTextFrame);
+ SwWrongList const* (SwTextNode::*const pGetWrongList)() const = getTextMarkupFunc(nTextMarkupType);
+ if (pGetWrongList)
+ {
+ sw::WrongListIteratorCounter iter(*m_pTextFrame, pGetWrongList);
+ nTextMarkupCount = iter.GetElementCount();
+ }
}
return nTextMarkupCount;
@@ -119,22 +120,31 @@ css::accessibility::TextSegment
aTextMarkupSegment.SegmentStart = -1;
aTextMarkupSegment.SegmentEnd = -1;
- // #i108125#
- const SwWrongList* pTextMarkupList =
- mpTextMarkupList
- ? mpTextMarkupList
- : getTextMarkupList( *mpTextNode, nTextMarkupType );
- if ( pTextMarkupList )
+ std::unique_ptr<sw::WrongListIteratorCounter> pIter;
+ if (mpTextMarkupList)
+ {
+ pIter.reset(new sw::WrongListIteratorCounter(*mpTextMarkupList));
+ }
+ else
+ {
+ assert(m_pTextFrame);
+ SwWrongList const* (SwTextNode::*const pGetWrongList)() const = getTextMarkupFunc(nTextMarkupType);
+ if (pGetWrongList)
+ {
+ pIter.reset(new sw::WrongListIteratorCounter(*m_pTextFrame, pGetWrongList));
+ }
+ }
+
+ if (pIter)
{
- const SwWrongArea* pTextMarkup =
- pTextMarkupList->GetElement( static_cast<sal_uInt16>(nTextMarkupIndex) );
- if ( pTextMarkup )
+ auto const oElement(pIter->GetElementAt(nTextMarkupIndex));
+ if (oElement)
{
- const OUString rText = mrPortionData.GetAccessibleString();
+ const OUString& rText = mrPortionData.GetAccessibleString();
const sal_Int32 nStartPos =
- mrPortionData.GetAccessiblePosition( pTextMarkup->mnPos );
+ mrPortionData.GetAccessiblePosition(oElement->first);
const sal_Int32 nEndPos =
- mrPortionData.GetAccessiblePosition( pTextMarkup->mnPos + pTextMarkup->mnLen );
+ mrPortionData.GetAccessiblePosition(oElement->second);
aTextMarkupSegment.SegmentText = rText.copy( nStartPos, nEndPos - nStartPos );
aTextMarkupSegment.SegmentStart = nStartPos;
aTextMarkupSegment.SegmentEnd = nEndPos;
@@ -155,7 +165,7 @@ css::uno::Sequence< css::accessibility::TextSegment >
// assumption:
// value of <nCharIndex> is in range [0..length of accessible text)
- const sal_Int32 nCoreCharIndex = mrPortionData.GetCoreViewPosition(nCharIndex);
+ const TextFrameIndex nCoreCharIndex = mrPortionData.GetCoreViewPosition(nCharIndex);
// Handling of portions with core length == 0 at the beginning of the
// paragraph - e.g. numbering portion.
if ( mrPortionData.GetAccessiblePosition( nCoreCharIndex ) > nCharIndex )
@@ -163,30 +173,37 @@ css::uno::Sequence< css::accessibility::TextSegment >
return uno::Sequence< css::accessibility::TextSegment >();
}
- // #i108125#
- const SwWrongList* pTextMarkupList =
- mpTextMarkupList
- ? mpTextMarkupList
- : getTextMarkupList( *mpTextNode, nTextMarkupType );
- std::vector< css::accessibility::TextSegment > aTmpTextMarkups;
- if ( pTextMarkupList )
+ std::unique_ptr<sw::WrongListIteratorCounter> pIter;
+ if (mpTextMarkupList)
+ {
+ pIter.reset(new sw::WrongListIteratorCounter(*mpTextMarkupList));
+ }
+ else
{
- const OUString rText = mrPortionData.GetAccessibleString();
+ assert(m_pTextFrame);
+ SwWrongList const* (SwTextNode::*const pGetWrongList)() const = getTextMarkupFunc(nTextMarkupType);
+ if (pGetWrongList)
+ {
+ pIter.reset(new sw::WrongListIteratorCounter(*m_pTextFrame, pGetWrongList));
+ }
+ }
- const sal_uInt16 nTextMarkupCount = pTextMarkupList->Count();
- for ( sal_uInt16 nTextMarkupIdx = 0; nTextMarkupIdx < nTextMarkupCount; ++nTextMarkupIdx )
+ std::vector< css::accessibility::TextSegment > aTmpTextMarkups;
+ if (pIter)
+ {
+ const OUString& rText = mrPortionData.GetAccessibleString();
+ sal_uInt16 count(pIter->GetElementCount());
+ for (sal_uInt16 i = 0; i < count; ++i)
{
- const SwWrongArea* pTextMarkup = pTextMarkupList->GetElement( nTextMarkupIdx );
- OSL_ENSURE( pTextMarkup,
- "<SwTextMarkupHelper::getTextMarkup(..)> - missing <SwWrongArea> instance" );
- if ( pTextMarkup &&
- pTextMarkup->mnPos <= nCoreCharIndex &&
- nCoreCharIndex < ( pTextMarkup->mnPos + pTextMarkup->mnLen ) )
+ auto const oElement(pIter->GetElementAt(i));
+ if (oElement &&
+ oElement->first <= nCoreCharIndex &&
+ nCoreCharIndex < oElement->second)
{
const sal_Int32 nStartPos =
- mrPortionData.GetAccessiblePosition( pTextMarkup->mnPos );
+ mrPortionData.GetAccessiblePosition(oElement->first);
const sal_Int32 nEndPos =
- mrPortionData.GetAccessiblePosition( pTextMarkup->mnPos + pTextMarkup->mnLen );
+ mrPortionData.GetAccessiblePosition(oElement->second);
css::accessibility::TextSegment aTextMarkupSegment;
aTextMarkupSegment.SegmentText = rText.copy( nStartPos, nEndPos - nStartPos );
aTextMarkupSegment.SegmentStart = nStartPos;
diff --git a/sw/source/core/access/textmarkuphelper.hxx b/sw/source/core/access/textmarkuphelper.hxx
index de3af6013dc6..56a1cac5f9c4 100644
--- a/sw/source/core/access/textmarkuphelper.hxx
+++ b/sw/source/core/access/textmarkuphelper.hxx
@@ -30,13 +30,14 @@ struct TextSegment;
} } } }
class SwAccessiblePortionData;
-class SwTextNode;
+class SwTextFrame;
class SwWrongList; // #i108125#
+
class SwTextMarkupHelper
{
public:
SwTextMarkupHelper( const SwAccessiblePortionData& rPortionData,
- const SwTextNode& rTextNode );
+ const SwTextFrame& rTextFrame);
SwTextMarkupHelper( const SwAccessiblePortionData& rPortionData,
const SwWrongList& rTextMarkupList ); // #i108125#
@@ -64,8 +65,7 @@ class SwTextMarkupHelper
const SwAccessiblePortionData& mrPortionData;
- // #i108125#
- const SwTextNode* mpTextNode;
+ SwTextFrame const* m_pTextFrame;
const SwWrongList* mpTextMarkupList;
};
#endif
commit 64e8cc32dac6649f8fd794d827feb964dab41308
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Tue Oct 9 11:11:07 2018 +0200
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Tue Oct 9 16:33:06 2018 +0200
sw_redlinehide_3: add another kind of WrongListIterator
This is not very efficient but should be good enough for a11y use.
Change-Id: Ibb00cf4ae18effb09673f3f7d9b9b2e1d72413b1
diff --git a/sw/source/core/inc/wrong.hxx b/sw/source/core/inc/wrong.hxx
index 13f1f50507cf..8340d3337ca4 100644
--- a/sw/source/core/inc/wrong.hxx
+++ b/sw/source/core/inc/wrong.hxx
@@ -29,6 +29,8 @@
#include <vector>
+#include <boost/optional.hpp>
+
#include <tools/color.hxx>
#include <swtypes.hxx>
#include <viewopt.hxx>
@@ -346,9 +348,9 @@ namespace sw {
struct MergedPara;
-class WrongListIterator
+class WrongListIteratorBase
{
-private:
+protected:
SwWrongList const* (SwTextNode::*const m_pGetWrongList)() const;
sw::MergedPara const*const m_pMergedPara;
size_t m_CurrentExtent;
@@ -357,6 +359,17 @@ private:
public:
/// for the text frame
+ WrongListIteratorBase(SwTextFrame const& rFrame,
+ SwWrongList const* (SwTextNode::*pGetWrongList)() const);
+ /// for SwTextSlot
+ WrongListIteratorBase(SwWrongList const& rWrongList);
+};
+
+class WrongListIterator
+ : public WrongListIteratorBase
+{
+public:
+ /// for the text frame
WrongListIterator(SwTextFrame const& rFrame,
SwWrongList const* (SwTextNode::*pGetWrongList)() const);
/// for SwTextSlot
@@ -371,6 +384,18 @@ public:
}
};
+class WrongListIteratorCounter
+ : public WrongListIteratorBase
+{
+public:
+ WrongListIteratorCounter(SwTextFrame const& rFrame,
+ SwWrongList const* (SwTextNode::*pGetWrongList)() const);
+ WrongListIteratorCounter(SwWrongList const& rWrongList);
+
+ sal_uInt16 GetElementCount();
+ boost::optional<std::pair<TextFrameIndex, TextFrameIndex>> GetElementAt(sal_uInt16 nIndex);
+};
+
} // namespace sw
#endif
diff --git a/sw/source/core/text/wrong.cxx b/sw/source/core/text/wrong.cxx
index d85cf9a99bdf..476c3df5f9a3 100644
--- a/sw/source/core/text/wrong.cxx
+++ b/sw/source/core/text/wrong.cxx
@@ -664,7 +664,7 @@ void SwWrongList::Insert( const OUString& rType,
namespace sw {
-WrongListIterator::WrongListIterator(SwTextFrame const& rFrame,
+WrongListIteratorBase::WrongListIteratorBase(SwTextFrame const& rFrame,
SwWrongList const* (SwTextNode::*pGetWrongList)() const)
: m_pGetWrongList(pGetWrongList)
, m_pMergedPara(rFrame.GetMergedPara())
@@ -676,7 +676,7 @@ WrongListIterator::WrongListIterator(SwTextFrame const& rFrame,
{
}
-WrongListIterator::WrongListIterator(SwWrongList const& rWrongList)
+WrongListIteratorBase::WrongListIteratorBase(SwWrongList const& rWrongList)
: m_pGetWrongList(nullptr)
, m_pMergedPara(nullptr)
, m_CurrentExtent(0)
@@ -685,6 +685,17 @@ WrongListIterator::WrongListIterator(SwWrongList const& rWrongList)
{
}
+WrongListIterator::WrongListIterator(SwTextFrame const& rFrame,
+ SwWrongList const* (SwTextNode::*pGetWrongList)() const)
+ : WrongListIteratorBase(rFrame, pGetWrongList)
+{
+}
+
+WrongListIterator::WrongListIterator(SwWrongList const& rWrongList)
+ : WrongListIteratorBase(rWrongList)
+{
+}
+
bool WrongListIterator::Check(TextFrameIndex & rStart, TextFrameIndex & rLen)
{
if (m_pMergedPara)
@@ -838,6 +849,118 @@ WrongListIterator::GetWrongElement(TextFrameIndex const nStart)
return nullptr;
}
+WrongListIteratorCounter::WrongListIteratorCounter(SwTextFrame const& rFrame,
+ SwWrongList const* (SwTextNode::*pGetWrongList)() const)
+ : WrongListIteratorBase(rFrame, pGetWrongList)
+{
+}
+
+WrongListIteratorCounter::WrongListIteratorCounter(SwWrongList const& rWrongList)
+ : WrongListIteratorBase(rWrongList)
+{
+}
+
+sal_uInt16 WrongListIteratorCounter::GetElementCount()
+{
+ if (m_pMergedPara)
+ {
+ sal_uInt16 nRet(0);
+ m_CurrentExtent = 0;
+ m_CurrentIndex = TextFrameIndex(0);
+ SwNode const* pNode(nullptr);
+ sal_uInt16 InCurrentNode(0);
+ while (m_CurrentExtent < m_pMergedPara->extents.size())
+ {
+ sw::Extent const& rExtent(m_pMergedPara->extents[m_CurrentExtent]);
+ if (rExtent.pNode != pNode)
+ {
+ InCurrentNode = 0;
+ pNode = rExtent.pNode;
+ }
+ SwWrongList const*const pWrongList((rExtent.pNode->*m_pGetWrongList)());
+ for (; InCurrentNode < pWrongList->Count(); ++InCurrentNode)
+ {
+ SwWrongArea const*const pWrong(pWrongList->GetElement(InCurrentNode));
+ TextFrameIndex const nExtentEnd(
+ m_CurrentIndex + TextFrameIndex(rExtent.nEnd - rExtent.nStart));
+ if (nExtentEnd <= TextFrameIndex(pWrong->mnPos))
+ {
+ break; // continue outer loop
+ }
+ if (m_CurrentIndex < TextFrameIndex(pWrong->mnPos + pWrong->mnLen))
+ {
+ ++nRet;
+ }
+ }
+ m_CurrentIndex += TextFrameIndex(rExtent.nEnd - rExtent.nStart);
+ ++m_CurrentExtent;
+ }
+ return nRet;
+ }
+ else if (m_pWrongList)
+ {
+ return m_pWrongList->Count();
+ }
+ return 0;
+}
+
+boost::optional<std::pair<TextFrameIndex, TextFrameIndex>>
+WrongListIteratorCounter::GetElementAt(sal_uInt16 nIndex)
+{
+ if (m_pMergedPara)
+ {
+ m_CurrentExtent = 0;
+ m_CurrentIndex = TextFrameIndex(0);
+ SwNode const* pNode(nullptr);
+ sal_uInt16 InCurrentNode(0);
+ while (m_CurrentExtent < m_pMergedPara->extents.size())
+ {
+ sw::Extent const& rExtent(m_pMergedPara->extents[m_CurrentExtent]);
+ if (rExtent.pNode != pNode)
+ {
+ InCurrentNode = 0;
+ pNode = rExtent.pNode;
+ }
+ SwWrongList const*const pWrongList((rExtent.pNode->*m_pGetWrongList)());
+ for (; InCurrentNode < pWrongList->Count(); ++InCurrentNode)
+ {
+ SwWrongArea const*const pWrong(pWrongList->GetElement(InCurrentNode));
+ TextFrameIndex const nExtentEnd(
+ m_CurrentIndex + TextFrameIndex(rExtent.nEnd - rExtent.nStart));
+ if (nExtentEnd <= TextFrameIndex(pWrong->mnPos))
+ {
+ break; // continue outer loop
+ }
+ if (m_CurrentIndex < TextFrameIndex(pWrong->mnPos + pWrong->mnLen))
+ {
+ if (nIndex == 0)
+ {
+ return boost::optional<std::pair<TextFrameIndex, TextFrameIndex>>(
+ std::pair<TextFrameIndex, TextFrameIndex>(
+ m_CurrentIndex - TextFrameIndex(rExtent.nStart -
+ std::min(rExtent.nStart, pWrong->mnPos)),
+ m_CurrentIndex - TextFrameIndex(rExtent.nStart -
+ std::min(pWrong->mnPos + pWrong->mnLen, rExtent.nEnd))));
+ }
+ --nIndex;
+ }
+ }
+ m_CurrentIndex += TextFrameIndex(rExtent.nEnd - rExtent.nStart);
+ ++m_CurrentExtent;
+ }
+ return boost::optional<std::pair<TextFrameIndex, TextFrameIndex>>();
+ }
+ else if (m_pWrongList)
+ {
+ SwWrongArea const*const pWrong(m_pWrongList->GetElement(nIndex));
+ return boost::optional<std::pair<TextFrameIndex, TextFrameIndex>>(
+ std::pair<TextFrameIndex, TextFrameIndex>(
+ TextFrameIndex(pWrong->mnPos),
+ TextFrameIndex(pWrong->mnPos + pWrong->mnLen)));
+ }
+ return boost::optional<std::pair<TextFrameIndex, TextFrameIndex>>();
+}
+
} // namespace sw
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 72be8aa9e277eee7a56668b220a60fd48c871b10
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Mon Oct 8 15:46:55 2018 +0200
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Tue Oct 9 11:16:22 2018 +0200
sw_redlinehide_3: remove GetSelection/GetSelectionAtIndex duplication
Delicious copypasta!
Change-Id: I95ab5a1ef58b01f775065a970a0d7eb2b6bf6394
diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx
index 73ae937e4c88..57a596742571 100644
--- a/sw/source/core/access/accpara.cxx
+++ b/sw/source/core/access/accpara.cxx
@@ -195,137 +195,6 @@ sal_Int32 SwAccessibleParagraph::GetCaretPos()
return nRet;
}
-bool SwAccessibleParagraph::GetSelection(
- sal_Int32& nStart, sal_Int32& nEnd)
-{
- bool bRet = false;
- nStart = -1;
- nEnd = -1;
-
- // get the selection, and test whether it affects our text node
- SwPaM* pCursor = GetCursor( true ); // #i27301# - consider adjusted method signature
- if( pCursor != nullptr )
- {
- // get SwPosition for my node
- SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame()));
- sal_uLong nFirstNode(pFrame->GetTextNodeFirst()->GetIndex());
- sal_uLong nLastNode;
- if (sw::MergedPara const*const pMerged = pFrame->GetMergedPara())
- {
- nLastNode = pMerged->pLastNode->GetIndex();
- }
- else
- {
- nLastNode = nFirstNode;
- }
-
- // iterate over ring
- for(SwPaM& rTmpCursor : pCursor->GetRingContainer())
- {
- // ignore, if no mark
- if( rTmpCursor.HasMark() )
- {
- // check whether frame's node(s) are 'inside' pCursor
- SwPosition* pStart = rTmpCursor.Start();
- sal_uLong nStartIndex = pStart->nNode.GetIndex();
- SwPosition* pEnd = rTmpCursor.End();
- sal_uLong nEndIndex = pEnd->nNode.GetIndex();
- if ((nStartIndex <= nLastNode) && (nFirstNode <= nEndIndex))
- {
- // translate start and end positions
-
- // start position
- sal_Int32 nLocalStart = -1;
- if (nStartIndex < nFirstNode)
- {
- // selection starts in previous node:
- // then our local selection starts with the paragraph
- nLocalStart = 0;
- }
- else
- {
- assert(FrameContainsNode(*pFrame, nStartIndex));
-
- // selection starts in this node:
- // then check whether it's before or inside our part of
- // the paragraph, and if so, get the proper position
- const TextFrameIndex nCoreStart =
- pFrame->MapModelToViewPos(*pStart);
- if( nCoreStart <
- GetPortionData().GetFirstValidCorePosition() )
- {
- nLocalStart = 0;
- }
- else if( nCoreStart <=
- GetPortionData().GetLastValidCorePosition() )
- {
- OSL_ENSURE(
- GetPortionData().IsValidCorePosition(
- nCoreStart ),
- "problem determining valid core position" );
-
- nLocalStart =
- GetPortionData().GetAccessiblePosition(
- nCoreStart );
- }
- }
-
- // end position
- sal_Int32 nLocalEnd = -1;
- if (nLastNode < nEndIndex)
- {
- // selection ends in following node:
- // then our local selection extends to the end
- nLocalEnd = GetPortionData().GetAccessibleString().
- getLength();
- }
- else
- {
- assert(FrameContainsNode(*pFrame, nEndIndex));
-
- // selection ends in this node: then select everything
- // before our part of the node
- const TextFrameIndex nCoreEnd =
- pFrame->MapModelToViewPos(*pEnd);
- if( nCoreEnd >
- GetPortionData().GetLastValidCorePosition() )
- {
- // selection extends beyond out part of this para
- nLocalEnd = GetPortionData().GetAccessibleString().
- getLength();
- }
- else if( nCoreEnd >=
- GetPortionData().GetFirstValidCorePosition() )
- {
- // selection is inside our part of this para
- OSL_ENSURE(
- GetPortionData().IsValidCorePosition(
- nCoreEnd ),
- "problem determining valid core position" );
-
- nLocalEnd = GetPortionData().GetAccessiblePosition(
- nCoreEnd );
- }
- }
-
- if( ( nLocalStart != -1 ) && ( nLocalEnd != -1 ) )
- {
- nStart = nLocalStart;
- nEnd = nLocalEnd;
- bRet = true;
- }
- }
- // else: this PaM doesn't point to this paragraph
- }
- // else: this PaM is collapsed and doesn't select anything
- if(bRet)
- break;
- }
- // else: nocursor -> no selection
- }
- return bRet;
-}
-
// #i27301# - new parameter <_bForSelection>
SwPaM* SwAccessibleParagraph::GetCursor( const bool _bForSelection )
{
@@ -509,7 +378,7 @@ void SwAccessibleParagraph::InvalidateCursorPos_()
//To send TEXT_SELECTION_CHANGED event
sal_Int32 nStart=0;
sal_Int32 nEnd =0;
- bool bCurSelection=GetSelection(nStart,nEnd);
+ bool bCurSelection = GetSelection(nStart,nEnd);
if(m_bLastHasSelection || bCurSelection )
{
aEvent.EventId = AccessibleEventId::TEXT_SELECTION_CHANGED;
@@ -3225,7 +3094,7 @@ sal_Int32 SAL_CALL SwAccessibleParagraph::getSeletedPositionStart( sal_Int32 nSe
ThrowIfDisposed();
sal_Int32 nStart, nEnd;
- /*sal_Bool bSelected = */GetSelectionAtIndex(nSelectedPortionIndex, nStart, nEnd );
+ /*sal_Bool bSelected = */GetSelectionAtIndex(&nSelectedPortionIndex, nStart, nEnd );
return nStart;
}
@@ -3236,7 +3105,7 @@ sal_Int32 SAL_CALL SwAccessibleParagraph::getSeletedPositionEnd( sal_Int32 nSele
ThrowIfDisposed();
sal_Int32 nStart, nEnd;
- /*sal_Bool bSelected = */GetSelectionAtIndex(nSelectedPortionIndex, nStart, nEnd );
+ /*sal_Bool bSelected = */GetSelectionAtIndex(&nSelectedPortionIndex, nStart, nEnd );
return nEnd;
}
@@ -3312,7 +3181,7 @@ sal_Int32 SAL_CALL SwAccessibleParagraph::addSelection( sal_Int32, sal_Int32 sta
for ( sal_Int32 i = nSelectedCount ; i >= 0 ; i--)
{
sal_Int32 nStart, nEnd;
- bool bSelected = GetSelectionAtIndex(i, nStart, nEnd );
+ bool bSelected = GetSelectionAtIndex(&i, nStart, nEnd );
if(bSelected)
{
if(nStart <= nEnd )
@@ -3539,14 +3408,13 @@ void SwAccessibleParagraph::Notify(SfxBroadcaster&, const SfxHint&)
}
bool SwAccessibleParagraph::GetSelectionAtIndex(
- sal_Int32 nIndex, sal_Int32& nStart, sal_Int32& nEnd)
+ sal_Int32 * pSelection, sal_Int32& nStart, sal_Int32& nEnd)
{
- if(nIndex < 0) return false;
+ if (pSelection && *pSelection < 0) return false;
bool bRet = false;
nStart = -1;
nEnd = -1;
- sal_Int32 nSelected = nIndex;
// get the selection, and test whether it affects our text node
SwPaM* pCursor = GetCursor( true );
@@ -3578,7 +3446,7 @@ bool SwAccessibleParagraph::GetSelectionAtIndex(
sal_uLong nEndIndex = pEnd->nNode.GetIndex();
if ((nStartIndex <= nLastNode) && (nFirstNode <= nEndIndex))
{
- if( nSelected == 0 )
+ if (!pSelection || *pSelection == 0)
{
// translate start and end positions
@@ -3667,7 +3535,7 @@ bool SwAccessibleParagraph::GetSelectionAtIndex(
} // if hit the index
else
{
- nSelected--;
+ --*pSelection;
}
}
// else: this PaM doesn't point to this paragraph
@@ -3679,7 +3547,7 @@ bool SwAccessibleParagraph::GetSelectionAtIndex(
}
// else: nocursor -> no selection
- if( bRet )
+ if (pSelection && bRet)
{
sal_Int32 nCaretPos = GetCaretPos();
if( nStart == nCaretPos )
diff --git a/sw/source/core/access/accpara.hxx b/sw/source/core/access/accpara.hxx
index ef5234f46ae8..676e99a9023b 100644
--- a/sw/source/core/access/accpara.hxx
+++ b/sw/source/core/access/accpara.hxx
@@ -101,7 +101,11 @@ class SwAccessibleParagraph :
// determine the current selection. Fill the values with
// -1 if there is no selection in the this paragraph
- bool GetSelection(sal_Int32& nStart, sal_Int32& nEnd);
+ // @param pSelection (optional) check only Nth selection in ring
+ bool GetSelectionAtIndex(sal_Int32 * pSelection, sal_Int32& nStart, sal_Int32& nEnd);
+ bool GetSelection(sal_Int32& nStart, sal_Int32& nEnd) {
+ return GetSelectionAtIndex(nullptr, nStart, nEnd);
+ }
// helper for GetSelection and getCaretPosition
// #i27301# - add parameter <_bForSelection>, which indicates,
@@ -368,7 +372,6 @@ public:
virtual sal_Int32 SAL_CALL addSelection( sal_Int32 selectionIndex, sal_Int32 startOffset, sal_Int32 endOffset) override;
// XAccessibleExtendedAttributes
virtual css::uno::Any SAL_CALL getExtendedAttributes() override ;
- bool GetSelectionAtIndex(sal_Int32 nIndex, sal_Int32& nStart, sal_Int32& nEnd);
sal_Int32 GetRealHeadingLevel();
// XAccessibleComponent
bool m_bLastHasSelection;
More information about the Libreoffice-commits
mailing list