summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@suse.cz>2012-02-20 10:12:01 +0100
committerPetr Mladek <pmladek@suse.cz>2012-02-24 15:20:30 +0100
commitca76395eead22525d9c1a3a3b0863189b911ed1c (patch)
tree387ad9befba0627705801fa6d01bac0cce587f4b
parent9a440f8aa8eacb39eeaec03ffddf3612b3964f32 (diff)
n#695479 fix anchor handling in SwXText::convertToTextFrame()
When two (or more) text frames was imported without a non-frame paragraph in between, the first frame was anchored to the second one, instead of a non-frame paragraph. The fix is modelled after what the old RTF import already did in SwRTFParser::Continue() in swparrtf.cxx:493 and SwRTFParser::SetFlysInDoc() in rtffly.cxx:481. (cherry picked from commit 9592f56323de27f9e1d890ee6259a5f4f328cbd3) Signed-off-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sw/source/core/unocore/unotext.cxx27
1 files changed, 27 insertions, 0 deletions
diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx
index 820239f1afb1..a562a252d264 100644
--- a/sw/source/core/unocore/unotext.cxx
+++ b/sw/source/core/unocore/unotext.cxx
@@ -1665,6 +1665,18 @@ throw (lang::IllegalArgumentException, uno::RuntimeException)
aStartPam.SetMark();
*aStartPam.End() = *pEndPam->End();
pEndPam.reset(0);
+
+ // see if there are frames already anchored to this node
+ std::vector<SwFrmFmt*> aAnchoredFrames;
+ for (int i = 0; i < m_pImpl->m_pDoc->GetSpzFrmFmts()->Count(); ++i)
+ {
+ SwFrmFmt* pFrmFmt = (*m_pImpl->m_pDoc->GetSpzFrmFmts())[i];
+ const SwFmtAnchor& rAnchor = pFrmFmt->GetAnchor();
+ if (FLY_AT_PARA == rAnchor.GetAnchorId() &&
+ aStartPam.GetNode()->GetIndex() == rAnchor.GetCntntAnchor()->nNode.GetIndex())
+ aAnchoredFrames.push_back(pFrmFmt);
+ }
+
SwXTextFrame *const pNewFrame = new SwXTextFrame(m_pImpl->m_pDoc);
const uno::Reference< text::XTextFrame > xNewFrame = pNewFrame;
pNewFrame->SetSelection( aStartPam );
@@ -1700,6 +1712,21 @@ throw (lang::IllegalArgumentException, uno::RuntimeException)
aNewAnchor.SetAnchor( aMovePam.Start() );
m_pImpl->m_pDoc->SetAttr(
aNewAnchor, *pNewFrame->GetFrmFmt() );
+
+ // also move frames anchored to us
+ for (std::vector<SwFrmFmt*>::iterator i = aAnchoredFrames.begin(); i != aAnchoredFrames.end(); ++i)
+ {
+ // copy the anchor to the next paragraph
+ SwFmtAnchor aAnchor((*i)->GetAnchor());
+ aAnchor.SetAnchor(aMovePam.Start());
+ m_pImpl->m_pDoc->SetAttr(aAnchor, *(*i));
+
+ // delete the old anchor
+ SwSpzFrmFmts* pFrmFmts = m_pImpl->m_pDoc->GetSpzFrmFmts();
+ // here we rely on that fact that this is a sorted list, where the last element is the newly created frame
+ SwFrmFmt *pFrmFmt = (*pFrmFmts)[pFrmFmts->Count()-1];
+ m_pImpl->m_pDoc->DelLayoutFmt(pFrmFmt);
+ }
}
}
m_pImpl->m_pDoc->DelFullPara(aStartPam);