[Libreoffice-commits] core.git: Branch 'private/mst/sw_redlinehide_3' - 5 commits - sw/inc sw/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Mon Oct 8 15:23:45 UTC 2018
sw/inc/fmtinfmt.hxx | 5
sw/source/core/access/acchyperlink.cxx | 92 +++++-----
sw/source/core/access/acchyperlink.hxx | 19 +-
sw/source/core/access/accpara.cxx | 290 ++++++++++-----------------------
sw/source/core/txtnode/fmtatr2.cxx | 1
5 files changed, 153 insertions(+), 254 deletions(-)
New commits:
commit 44cb02bf24748a5737bc37aa109eb29cd3142672
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: Mon Oct 8 15:46:55 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 )
commit 96f59652b4838e6ca27f7f8f0ffe70b8230559a7
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Mon Oct 8 15:31:02 2018 +0200
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Mon Oct 8 15:31:02 2018 +0200
sw_redlinehide_3: convert selection functions of SwAccessibleParagraph
Do i smell copypasta?
Change-Id: I5450118b58540eee5ac8ff2e941d005fda4572c3
diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx
index 79545c2fce9c..73ae937e4c88 100644
--- a/sw/source/core/access/accpara.cxx
+++ b/sw/source/core/access/accpara.cxx
@@ -207,8 +207,17 @@ bool SwAccessibleParagraph::GetSelection(
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())
@@ -216,19 +225,18 @@ bool SwAccessibleParagraph::GetSelection(
// 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))
{
// translate start and end positions
// start position
sal_Int32 nLocalStart = -1;
- if( nHere > nStartIndex )
+ if (nStartIndex < nFirstNode)
{
// selection starts in previous node:
// then our local selection starts with the paragraph
@@ -236,13 +244,13 @@ bool SwAccessibleParagraph::GetSelection(
}
else
{
- OSL_ENSURE( nHere == nStartIndex,
- "miscalculated index" );
+ 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 sal_Int32 nCoreStart = pStart->nContent.GetIndex();
+ const TextFrameIndex nCoreStart =
+ pFrame->MapModelToViewPos(*pStart);
if( nCoreStart <
GetPortionData().GetFirstValidCorePosition() )
{
@@ -264,7 +272,7 @@ bool SwAccessibleParagraph::GetSelection(
// end position
sal_Int32 nLocalEnd = -1;
- if( nHere < nEndIndex )
+ if (nLastNode < nEndIndex)
{
// selection ends in following node:
// then our local selection extends to the end
@@ -273,12 +281,12 @@ bool SwAccessibleParagraph::GetSelection(
}
else
{
- OSL_ENSURE( nHere == nEndIndex,
- "miscalculated index" );
+ assert(FrameContainsNode(*pFrame, nEndIndex));
// selection ends in this node: then select everything
// before our part of the node
- const sal_Int32 nCoreEnd = pEnd->nContent.GetIndex();
+ const TextFrameIndex nCoreEnd =
+ pFrame->MapModelToViewPos(*pEnd);
if( nCoreEnd >
GetPortionData().GetLastValidCorePosition() )
{
@@ -2473,13 +2481,12 @@ sal_Bool SwAccessibleParagraph::setSelection( sal_Int32 nStartIndex, sal_Int32 n
if( pCursorShell != nullptr )
{
// create pam for selection
- SwTextNode* pNode = const_cast<SwTextNode*>( GetTextNode() );
- SwIndex aIndex(pNode, GetPortionData().GetCoreViewPosition(nStartIndex));
- SwPosition aStartPos( *pNode, aIndex );
- SwPaM aPaM( aStartPos );
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame()));
+ TextFrameIndex const nStart(GetPortionData().GetCoreViewPosition(nStartIndex));
+ TextFrameIndex const nEnd(GetPortionData().GetCoreViewPosition(nEndIndex));
+ SwPaM aPaM(pFrame->MapViewToModelPos(nStart));
aPaM.SetMark();
- aPaM.GetPoint()->nContent =
- GetPortionData().GetCoreViewPosition(nEndIndex);
+ *aPaM.GetPoint() = pFrame->MapViewToModelPos(nEnd);
// set PaM at cursor shell
bRet = Select( aPaM );
@@ -3340,10 +3347,11 @@ sal_Int32 SAL_CALL SwAccessibleParagraph::addSelection( sal_Int32, sal_Int32 sta
{
// create pam for selection
pCursorShell->StartAction();
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(GetFrame()));
SwPaM* aPaM = pCursorShell->CreateCursor();
aPaM->SetMark();
- aPaM->GetPoint()->nContent = GetPortionData().GetCoreViewPosition(startOffset);
- aPaM->GetMark()->nContent = GetPortionData().GetCoreViewPosition(endOffset);
+ *aPaM->GetPoint() = pFrame->MapViewToModelPos(GetPortionData().GetCoreViewPosition(startOffset));
+ *aPaM->GetMark() = pFrame->MapViewToModelPos(GetPortionData().GetCoreViewPosition(endOffset));
pCursorShell->EndAction();
}
@@ -3545,8 +3553,17 @@ bool SwAccessibleParagraph::GetSelectionAtIndex(
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())
@@ -3554,13 +3571,12 @@ bool SwAccessibleParagraph::GetSelectionAtIndex(
// 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))
{
if( nSelected == 0 )
{
@@ -3568,7 +3584,7 @@ bool SwAccessibleParagraph::GetSelectionAtIndex(
// start position
sal_Int32 nLocalStart = -1;
- if( nHere > nStartIndex )
+ if (nStartIndex < nFirstNode)
{
// selection starts in previous node:
// then our local selection starts with the paragraph
@@ -3576,12 +3592,13 @@ bool SwAccessibleParagraph::GetSelectionAtIndex(
}
else
{
- assert(nHere == nStartIndex);
+ 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 sal_Int32 nCoreStart = pStart->nContent.GetIndex();
+ const TextFrameIndex nCoreStart =
+ pFrame->MapModelToViewPos(*pStart);
if( nCoreStart <
GetPortionData().GetFirstValidCorePosition() )
{
@@ -3604,7 +3621,7 @@ bool SwAccessibleParagraph::GetSelectionAtIndex(
// end position
sal_Int32 nLocalEnd = -1;
- if( nHere < nEndIndex )
+ if (nLastNode < nEndIndex)
{
// selection ends in following node:
// then our local selection extends to the end
@@ -3613,11 +3630,12 @@ bool SwAccessibleParagraph::GetSelectionAtIndex(
}
else
{
- assert(nHere == nEndIndex);
+ assert(FrameContainsNode(*pFrame, nEndIndex));
// selection ends in this node: then select everything
// before our part of the node
- const sal_Int32 nCoreEnd = pEnd->nContent.GetIndex();
+ const TextFrameIndex nCoreEnd =
+ pFrame->MapModelToViewPos(*pEnd);
if( nCoreEnd >
GetPortionData().GetLastValidCorePosition() )
{
commit 85f4d89e1040c952f61034004a22117c845ade85
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Mon Oct 8 14:47:07 2018 +0200
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Mon Oct 8 14:47:07 2018 +0200
sw: fix 2 inverted SAL_WARN_IFs
(regression from 1397e7dd3061c8995c9c042c59c4f2982bdf5e63)
Change-Id: I9daa478092209b2e7c168f45280bd5f873f674f2
diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx
index 0a5ce04d0b88..79545c2fce9c 100644
--- a/sw/source/core/access/accpara.cxx
+++ b/sw/source/core/access/accpara.cxx
@@ -3591,7 +3591,7 @@ bool SwAccessibleParagraph::GetSelectionAtIndex(
GetPortionData().GetLastValidCorePosition() )
{
SAL_WARN_IF(
- GetPortionData().IsValidCorePosition(
+ !GetPortionData().IsValidCorePosition(
nCoreStart),
"sw.a11y",
"problem determining valid core position");
@@ -3630,7 +3630,7 @@ bool SwAccessibleParagraph::GetSelectionAtIndex(
{
// selection is inside our part of this para
SAL_WARN_IF(
- GetPortionData().IsValidCorePosition(
+ !GetPortionData().IsValidCorePosition(
nCoreEnd),
"sw.a11y",
"problem determining valid core position");
commit f05e295f99481f994f735d7455afa56c87b3228b
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Mon Oct 8 14:19:17 2018 +0200
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Mon Oct 8 14:20:52 2018 +0200
sw_redlinehide_3: convert the hyperlink code in SwAccessibleParagraph
Use MergedAttrIter for the iteration. Fortunately all use of the
iterator is transient, i.e. it doesn't live past a UNO method return.
Change-Id: I4292a4ecafe94396a9d4cc64c2a26c5f28429ef3
diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx
index 6a5e32aa22ab..0a5ce04d0b88 100644
--- a/sw/source/core/access/accpara.cxx
+++ b/sw/source/core/access/accpara.cxx
@@ -2942,52 +2942,57 @@ void SwAccessibleParagraph::deselectAccessibleChild(
class SwHyperlinkIter_Impl
{
- const SwpHints *m_pHints;
- sal_Int32 const m_nStt;
- sal_Int32 m_nEnd;
- size_t m_nPos;
+ SwTextFrame const& m_rFrame;
+ sw::MergedAttrIter m_Iter;
+ TextFrameIndex const m_nStt;
+ TextFrameIndex m_nEnd;
public:
- explicit SwHyperlinkIter_Impl( const SwTextFrame *pTextFrame );
- const SwTextAttr *next();
- size_t getCurrHintPos() const { return m_nPos-1; }
+ explicit SwHyperlinkIter_Impl(const SwTextFrame & rTextFrame);
+ const SwTextAttr *next(SwTextNode const** ppNode = nullptr);
- sal_Int32 startIdx() const { return m_nStt; }
- sal_Int32 endIdx() const { return m_nEnd; }
+ TextFrameIndex startIdx() const { return m_nStt; }
+ TextFrameIndex endIdx() const { return m_nEnd; }
};
-SwHyperlinkIter_Impl::SwHyperlinkIter_Impl( const SwTextFrame *pTextFrame ) :
- m_pHints( pTextFrame->GetTextNode()->GetpSwpHints() ),
- m_nStt( pTextFrame->GetOfst() ),
- m_nPos( 0 )
+SwHyperlinkIter_Impl::SwHyperlinkIter_Impl(const SwTextFrame & rTextFrame)
+ : m_rFrame(rTextFrame)
+ , m_Iter(rTextFrame)
+ , m_nStt(rTextFrame.GetOfst())
{
- const SwTextFrame *pFollFrame = pTextFrame->GetFollow();
- m_nEnd = pFollFrame ? pFollFrame->GetOfst() : TextFrameIndex(pTextFrame->GetText().getLength());
+ const SwTextFrame *const pFollFrame = rTextFrame.GetFollow();
+ m_nEnd = pFollFrame ? pFollFrame->GetOfst() : TextFrameIndex(rTextFrame.GetText().getLength());
}
-const SwTextAttr *SwHyperlinkIter_Impl::next()
+const SwTextAttr *SwHyperlinkIter_Impl::next(SwTextNode const** ppNode)
{
const SwTextAttr *pAttr = nullptr;
- if( m_pHints )
+
+ SwTextNode const* pNode(nullptr);
+ while (SwTextAttr const*const pHt = m_Iter.NextAttr(&pNode))
{
- while( !pAttr && m_nPos < m_pHints->Count() )
+ if (RES_TXTATR_INETFMT == pHt->Which())
{
- const SwTextAttr *pHt = m_pHints->Get(m_nPos);
- if( RES_TXTATR_INETFMT == pHt->Which() )
+ const TextFrameIndex nHtStt(m_rFrame.MapModelToView(pNode, pHt->GetStart()));
+ const TextFrameIndex nHtEnd(m_rFrame.MapModelToView(pNode, *pHt->GetAnyEnd()));
+ if (nHtEnd > nHtStt &&
+ ((nHtStt >= m_nStt && nHtStt < m_nEnd) ||
+ (nHtEnd > m_nStt && nHtEnd <= m_nEnd)))
{
- const sal_Int32 nHtStt = pHt->GetStart();
- const sal_Int32 nHtEnd = *pHt->GetAnyEnd();
- if( nHtEnd > nHtStt &&
- ( (nHtStt >= m_nStt && nHtStt < m_nEnd) ||
- (nHtEnd > m_nStt && nHtEnd <= m_nEnd) ) )
+ pAttr = pHt;
+ if (ppNode)
{
- pAttr = pHt;
+ *ppNode = pNode;
}
+ break;
}
- ++m_nPos;
}
}
+ if (ppNode)
+ {
+ *ppNode = nullptr;
+ }
return pAttr;
};
@@ -3001,7 +3006,7 @@ sal_Int32 SAL_CALL SwAccessibleParagraph::getHyperLinkCount()
// #i77108# - provide hyperlinks also in editable documents.
const SwTextFrame *pTextFrame = static_cast<const SwTextFrame*>( GetFrame() );
- SwHyperlinkIter_Impl aIter( pTextFrame );
+ SwHyperlinkIter_Impl aIter(*pTextFrame);
while( aIter.next() )
nCount++;
@@ -3018,10 +3023,11 @@ uno::Reference< XAccessibleHyperlink > SAL_CALL
uno::Reference< XAccessibleHyperlink > xRet;
const SwTextFrame *pTextFrame = static_cast<const SwTextFrame*>( GetFrame() );
- SwHyperlinkIter_Impl aHIter( pTextFrame );
+ SwHyperlinkIter_Impl aHIter(*pTextFrame);
sal_Int32 nTIndex = -1;
SwTOXSortTabBase* pTBase = GetTOXSortTabBase();
- SwTextAttr* pHt = const_cast<SwTextAttr*>(aHIter.next());
+ SwTextNode const* pNode(nullptr);
+ SwTextAttr* pHt = const_cast<SwTextAttr*>(aHIter.next(&pNode));
while( (nLinkIndex < getHyperLinkCount()) && nTIndex < nLinkIndex)
{
sal_Int32 nHStt = -1;
@@ -3059,14 +3065,14 @@ uno::Reference< XAccessibleHyperlink > SAL_CALL
}
if( !xRet.is() )
{
- {
- const sal_Int32 nTmpHStt= GetPortionData().GetAccessiblePosition(
- max( aHIter.startIdx(), pHt->GetStart() ) );
- const sal_Int32 nTmpHEnd= GetPortionData().GetAccessiblePosition(
- min( aHIter.endIdx(), *pHt->GetAnyEnd() ) );
- xRet = new SwAccessibleHyperlink(*pHt,
- *this, nTmpHStt, nTmpHEnd );
- }
+ TextFrameIndex const nHintStart(pTextFrame->MapModelToView(pNode, pHt->GetStart()));
+ TextFrameIndex const nHintEnd(pTextFrame->MapModelToView(pNode, *pHt->GetAnyEnd()));
+ const sal_Int32 nTmpHStt= GetPortionData().GetAccessiblePosition(
+ max(aHIter.startIdx(), nHintStart));
+ const sal_Int32 nTmpHEnd= GetPortionData().GetAccessiblePosition(
+ min( aHIter.endIdx(), nHintEnd));
+ xRet = new SwAccessibleHyperlink(*pHt,
+ *this, nTmpHStt, nTmpHEnd );
if( aIter != m_pHyperTextData->end() )
{
(*aIter).second = xRet;
@@ -3084,7 +3090,7 @@ uno::Reference< XAccessibleHyperlink > SAL_CALL
// iterate next
if( bH )
// iterate next hyperlink
- pHt = const_cast<SwTextAttr*>(aHIter.next());
+ pHt = const_cast<SwTextAttr*>(aHIter.next(&pNode));
else if(bTOC)
continue;
else
@@ -3114,14 +3120,16 @@ sal_Int32 SAL_CALL SwAccessibleParagraph::getHyperLinkIndex( sal_Int32 nCharInde
// #i77108#
{
const SwTextFrame *pTextFrame = static_cast<const SwTextFrame*>( GetFrame() );
- SwHyperlinkIter_Impl aHIter( pTextFrame );
+ SwHyperlinkIter_Impl aHIter(*pTextFrame);
- const sal_Int32 nIdx = GetPortionData().GetCoreViewPosition(nCharIndex);
+ const TextFrameIndex nIdx = GetPortionData().GetCoreViewPosition(nCharIndex);
sal_Int32 nPos = 0;
- const SwTextAttr *pHt = aHIter.next();
- while( pHt && !(nIdx >= pHt->GetStart() && nIdx < *pHt->GetAnyEnd()) )
+ SwTextNode const* pNode(nullptr);
+ const SwTextAttr *pHt = aHIter.next(&pNode);
+ while (pHt && !(nIdx >= pTextFrame->MapModelToView(pNode, pHt->GetStart())
+ && nIdx < pTextFrame->MapModelToView(pNode, *pHt->GetAnyEnd())))
{
- pHt = aHIter.next();
+ pHt = aHIter.next(&pNode);
nPos++;
}
commit 85fc5b42216083f2b5f5bc3360fe7c987b6df7cd
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Mon Oct 8 12:57:44 2018 +0200
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Mon Oct 8 13:14:41 2018 +0200
sw_redlinehide_3: SwAccessibleHyperlink listen at SwFormatINetFormat
There is an annoying problem here: how does a SwAccessibleHyperlink
check whether its corresponding model hint still exists or not?
The existing check via the hint-position appears not ideal, and with the
MergedPara the obvious extension is to add a SwTextNode pointer (or
node index?) which would make it even less ideal...
Instead, do as a lot of classes in unocore do, and register as a
listener on the pool item.
There is another aspect there in how the SwAccessibleHyperTextData
map gets disposed quite eagerly when anything changes, but the
SwAccessibleHyperlink can live longer than this map.
Change-Id: I7d0780cf28794b4ef68cff5d640190694f67530e
diff --git a/sw/inc/fmtinfmt.hxx b/sw/inc/fmtinfmt.hxx
index 1b2d150c1049..1787d69bb66b 100644
--- a/sw/inc/fmtinfmt.hxx
+++ b/sw/inc/fmtinfmt.hxx
@@ -22,6 +22,7 @@
#include <svl/poolitem.hxx>
#include "swdllapi.h"
#include <memory>
+#include <calbck.hxx>
class SvxMacro;
class SvxMacroTableDtor;
@@ -31,7 +32,9 @@ enum class SvMacroItemId : sal_uInt16;
// ATT_INETFMT
-class SW_DLLPUBLIC SwFormatINetFormat: public SfxPoolItem
+class SW_DLLPUBLIC SwFormatINetFormat
+ : public SfxPoolItem
+ , public sw::BroadcasterMixin
{
friend class SwTextINetFormat;
diff --git a/sw/source/core/access/acchyperlink.cxx b/sw/source/core/access/acchyperlink.cxx
index 45dc339c7e8a..eb98a9f8752a 100644
--- a/sw/source/core/access/acchyperlink.cxx
+++ b/sw/source/core/access/acchyperlink.cxx
@@ -33,31 +33,37 @@ using namespace ::com::sun::star;
using namespace ::com::sun::star::accessibility;
using ::com::sun::star::lang::IndexOutOfBoundsException;
-SwAccessibleHyperlink::SwAccessibleHyperlink( size_t nHPos,
- SwAccessibleParagraph *p, sal_Int32 nStt, sal_Int32 nEnd ) :
- m_nHintPosition( nHPos ),
- m_xParagraph( p ),
- m_nStartIndex( nStt ),
- m_nEndIndex( nEnd )
+SwAccessibleHyperlink::SwAccessibleHyperlink(SwTextAttr & rTextAttr,
+ SwAccessibleParagraph & rAccPara,
+ sal_Int32 const nStt, sal_Int32 const nEnd)
+ : m_pHyperlink(const_cast<SwFormatINetFormat*>(&rTextAttr.GetINetFormat()))
+ , m_xParagraph(&rAccPara)
+ , m_nStartIndex( nStt )
+ , m_nEndIndex( nEnd )
{
+ StartListening(m_pHyperlink->GetNotifier());
}
-const SwTextAttr *SwAccessibleHyperlink::GetTextAttr() const
+SwAccessibleHyperlink::~SwAccessibleHyperlink()
{
- const SwTextAttr *pTextAttr = nullptr;
- if( m_xParagraph.is() && m_xParagraph->GetMap() )
+ Invalidate(); // with SolarMutex!
+}
+
+// when the pool item dies, invalidate! this is the only reason for Listener...
+void SwAccessibleHyperlink::Notify(SfxHint const& rHint)
+{
+ if (rHint.GetId() == SfxHintId::Dying)
{
- const SwTextNode *pTextNd = m_xParagraph->GetTextNode();
- const SwpHints *pHints = pTextNd->GetpSwpHints();
- if( pHints && m_nHintPosition < pHints->Count() )
- {
- const SwTextAttr *pHt = pHints->Get(m_nHintPosition);
- if( RES_TXTATR_INETFMT == pHt->Which() )
- pTextAttr = pHt;
- }
+ Invalidate();
}
+}
- return pTextAttr;
+// both the parent SwAccessibleParagraph and the pool-item must be valid
+const SwFormatINetFormat *SwAccessibleHyperlink::GetTextAttr() const
+{
+ return (m_xParagraph.is() && m_xParagraph->GetMap())
+ ? m_pHyperlink
+ : nullptr;
}
// XAccessibleAction
@@ -74,27 +80,21 @@ sal_Bool SAL_CALL SwAccessibleHyperlink::doAccessibleAction( sal_Int32 nIndex )
if(nIndex != 0)
throw lang::IndexOutOfBoundsException();
- const SwTextAttr *pTextAttr = GetTextAttr();
- if( pTextAttr )
+ SwFormatINetFormat const*const pINetFormat = GetTextAttr();
+ if (pINetFormat && !pINetFormat->GetValue().isEmpty())
{
- const SwFormatINetFormat& rINetFormat = pTextAttr->GetINetFormat();
- if( !rINetFormat.GetValue().isEmpty() )
+ SwViewShell *pVSh = m_xParagraph->GetShell();
+ if (pVSh)
{
- SwViewShell *pVSh = m_xParagraph->GetShell();
- if( pVSh )
+ LoadURL(*pVSh, pINetFormat->GetValue(), LoadUrlFlags::NONE,
+ pINetFormat->GetTargetFrame());
+ const SwTextINetFormat *const pTextAttr = pINetFormat->GetTextINetFormat();
+ if (pTextAttr)
{
- LoadURL(*pVSh, rINetFormat.GetValue(), LoadUrlFlags::NONE,
- rINetFormat.GetTargetFrame());
- OSL_ENSURE( pTextAttr == rINetFormat.GetTextINetFormat(),
- "lost my txt attr" );
- const SwTextINetFormat* pTextAttr2 = rINetFormat.GetTextINetFormat();
- if( pTextAttr2 )
- {
- const_cast<SwTextINetFormat*>(pTextAttr2)->SetVisited(true);
- const_cast<SwTextINetFormat*>(pTextAttr2)->SetVisitedValid(true);
- }
- bRet = true;
+ const_cast<SwTextINetFormat*>(pTextAttr)->SetVisited(true);
+ const_cast<SwTextINetFormat*>(pTextAttr)->SetVisitedValid(true);
}
+ bRet = true;
}
}
@@ -107,11 +107,10 @@ OUString SAL_CALL SwAccessibleHyperlink::getAccessibleActionDescription(
if(nIndex != 0)
throw lang::IndexOutOfBoundsException();
- const SwTextAttr *pTextAttr = GetTextAttr();
- if( pTextAttr )
+ SolarMutexGuard g;
+ if (SwFormatINetFormat const*const pINetFormat = GetTextAttr())
{
- const SwFormatINetFormat& rINetFormat = pTextAttr->GetINetFormat();
- return rINetFormat.GetValue();
+ return pINetFormat->GetValue();
}
return OUString();
@@ -161,12 +160,10 @@ uno::Any SAL_CALL SwAccessibleHyperlink::getAccessibleActionObject(
if(nIndex != 0)
throw lang::IndexOutOfBoundsException();
- const SwTextAttr *pTextAttr = GetTextAttr();
OUString retText;
- if( pTextAttr )
+ if (SwFormatINetFormat const*const pINetFormat = GetTextAttr())
{
- const SwFormatINetFormat& rINetFormat = pTextAttr->GetINetFormat();
- retText = rINetFormat.GetValue();
+ retText = pINetFormat->GetValue();
}
uno::Any aRet;
aRet <<= retText;
@@ -188,12 +185,9 @@ sal_Bool SAL_CALL SwAccessibleHyperlink::isValid( )
SolarMutexGuard aGuard;
if (m_xParagraph.is())
{
- const SwTextAttr *pTextAttr = GetTextAttr();
- OUString sText;
- if( pTextAttr )
+ if (SwFormatINetFormat const*const pINetFormat = GetTextAttr())
{
- const SwFormatINetFormat& rINetFormat = pTextAttr->GetINetFormat();
- sText = rINetFormat.GetValue();
+ OUString const sText(pINetFormat->GetValue());
OUString sToken = "#";
sal_Int32 nPos = sText.indexOf(sToken);
if (nPos==0)//document link
@@ -240,6 +234,8 @@ void SwAccessibleHyperlink::Invalidate()
{
SolarMutexGuard aGuard;
m_xParagraph = nullptr;
+ m_pHyperlink = nullptr;
+ EndListeningAll();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/access/acchyperlink.hxx b/sw/source/core/access/acchyperlink.hxx
index 4c8f450e3e80..e2ff327256cf 100644
--- a/sw/source/core/access/acchyperlink.hxx
+++ b/sw/source/core/access/acchyperlink.hxx
@@ -23,29 +23,34 @@
#include <com/sun/star/accessibility/XAccessibleHyperlink.hpp>
#include <rtl/ref.hxx>
#include <cppuhelper/implbase.hxx>
+#include <svl/listener.hxx>
+
#include <fmtinfmt.hxx>
class SwAccessibleParagraph;
class SwTextAttr;
-class SwAccessibleHyperlink :
- public ::cppu::WeakImplHelper<
- css::accessibility::XAccessibleHyperlink >
+class SwAccessibleHyperlink
+ : public ::cppu::WeakImplHelper<css::accessibility::XAccessibleHyperlink>
+ , public SvtListener
{
friend class SwAccessibleParagraph;
friend class SwAccessibleHyperTextData;
- size_t const m_nHintPosition;
+ SwFormatINetFormat * m_pHyperlink;
::rtl::Reference< SwAccessibleParagraph > m_xParagraph;
sal_Int32 const m_nStartIndex;
sal_Int32 const m_nEndIndex;
- SwAccessibleHyperlink( size_t nHintPos,
- SwAccessibleParagraph *p,
+ SwAccessibleHyperlink(SwTextAttr &,
+ SwAccessibleParagraph &,
sal_Int32 nStt, sal_Int32 nEnd );
+ ~SwAccessibleHyperlink();
- const SwTextAttr *GetTextAttr() const;
+ const SwFormatINetFormat* GetTextAttr() const;
void Invalidate();
+ virtual void Notify(SfxHint const& rHint) override;
+
public:
// XAccessibleAction
virtual sal_Int32 SAL_CALL getAccessibleActionCount() override;
diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx
index c3fde94a1b3a..6a5e32aa22ab 100644
--- a/sw/source/core/access/accpara.cxx
+++ b/sw/source/core/access/accpara.cxx
@@ -3064,8 +3064,8 @@ uno::Reference< XAccessibleHyperlink > SAL_CALL
max( aHIter.startIdx(), pHt->GetStart() ) );
const sal_Int32 nTmpHEnd= GetPortionData().GetAccessiblePosition(
min( aHIter.endIdx(), *pHt->GetAnyEnd() ) );
- xRet = new SwAccessibleHyperlink( aHIter.getCurrHintPos(),
- this, nTmpHStt, nTmpHEnd );
+ xRet = new SwAccessibleHyperlink(*pHt,
+ *this, nTmpHStt, nTmpHEnd );
}
if( aIter != m_pHyperTextData->end() )
{
diff --git a/sw/source/core/txtnode/fmtatr2.cxx b/sw/source/core/txtnode/fmtatr2.cxx
index 826119d84ccd..534425993cdc 100644
--- a/sw/source/core/txtnode/fmtatr2.cxx
+++ b/sw/source/core/txtnode/fmtatr2.cxx
@@ -178,6 +178,7 @@ SwFormatINetFormat::SwFormatINetFormat( const OUString& rURL, const OUString& rT
SwFormatINetFormat::SwFormatINetFormat( const SwFormatINetFormat& rAttr )
: SfxPoolItem( RES_TXTATR_INETFMT )
+ , sw::BroadcasterMixin()
, msURL( rAttr.GetValue() )
, msTargetFrame( rAttr.msTargetFrame )
, msINetFormatName( rAttr.msINetFormatName )
More information about the Libreoffice-commits
mailing list