Kaydet (Commit) 9592f563 authored tarafından Miklos Vajna's avatar Miklos Vajna

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.
üst 31826318
......@@ -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);
......
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