[Libreoffice-commits] .: sw/source

Miklos Vajna vmiklos at kemper.freedesktop.org
Mon Feb 20 01:33:56 PST 2012


 sw/source/core/unocore/unotext.cxx |   27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

New commits:
commit 9592f56323de27f9e1d890ee6259a5f4f328cbd3
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Mon Feb 20 10:12:01 2012 +0100

    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.

diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx
index 00c7e09..2c25700 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);


More information about the Libreoffice-commits mailing list