[Libreoffice-commits] core.git: 8 commits - sw/inc sw/source

Luboš Luňák l.lunak at collabora.com
Sun Nov 9 10:46:04 PST 2014


 sw/inc/doc.hxx                                          |    5 
 sw/inc/docary.hxx                                       |   28 +++--
 sw/inc/frmfmt.hxx                                       |   27 +++++
 sw/inc/node.hxx                                         |    2 
 sw/source/core/attr/swatrset.cxx                        |   27 ++++-
 sw/source/core/doc/DocumentContentOperationsManager.cxx |   18 +--
 sw/source/core/doc/DocumentStylePoolManager.cxx         |    2 
 sw/source/core/doc/docbm.cxx                            |   21 ++--
 sw/source/core/doc/docchart.cxx                         |    4 
 sw/source/core/doc/docedt.cxx                           |    2 
 sw/source/core/doc/doclay.cxx                           |    9 +
 sw/source/core/doc/docnew.cxx                           |    2 
 sw/source/core/doc/docnum.cxx                           |   11 ++
 sw/source/core/doc/docsort.cxx                          |    2 
 sw/source/core/doc/doctxm.cxx                           |   11 ++
 sw/source/core/doc/textboxhelper.cxx                    |    3 
 sw/source/core/docnode/ndsect.cxx                       |   13 ++
 sw/source/core/docnode/ndtbl.cxx                        |    9 +
 sw/source/core/docnode/node.cxx                         |    2 
 sw/source/core/docnode/nodedump.cxx                     |    8 -
 sw/source/core/draw/dcontact.cxx                        |    2 
 sw/source/core/frmedt/fefly1.cxx                        |   18 +--
 sw/source/core/frmedt/feshview.cxx                      |   17 +--
 sw/source/core/inc/MarkManager.hxx                      |    2 
 sw/source/core/inc/flyfrm.hxx                           |    2 
 sw/source/core/inc/frmtool.hxx                          |    2 
 sw/source/core/layout/atrfrm.cxx                        |   83 ++++++++++++++++
 sw/source/core/layout/flycnt.cxx                        |   19 +--
 sw/source/core/layout/frmtool.cxx                       |   39 ++++++-
 sw/source/core/layout/pagechg.cxx                       |    1 
 sw/source/core/layout/tabfrm.cxx                        |    3 
 sw/source/core/txtnode/atrflyin.cxx                     |    9 -
 sw/source/core/txtnode/ndtxt.cxx                        |   54 +++++++++-
 sw/source/core/undo/undobj1.cxx                         |    2 
 sw/source/core/unocore/unochart.cxx                     |    2 
 sw/source/core/unocore/unostyle.cxx                     |    2 
 sw/source/core/unocore/unotbl.cxx                       |    2 
 sw/source/core/unocore/unotext.cxx                      |    2 
 sw/source/filter/ascii/wrtasc.cxx                       |    2 
 sw/source/filter/html/swhtml.cxx                        |    2 
 sw/source/filter/ww8/rtfexport.cxx                      |    1 
 sw/source/filter/ww8/ww8glsy.cxx                        |    2 
 sw/source/uibase/app/docstyle.cxx                       |    2 
 sw/source/uibase/uiview/view2.cxx                       |    4 
 44 files changed, 375 insertions(+), 105 deletions(-)

New commits:
commit c8867b4c360f808386030ef6c87802403b42b70a
Author: Luboš Luňák <l.lunak at collabora.com>
Date:   Sun Nov 9 16:58:34 2014 +0100

    do not display missing data source always as "SOURCE"
    
    Broken by cc6f43275a00b0aff2e60e70ee8032222a2c9610.
    
    Change-Id: Ie870dea874327639460349b239525e4ce77dd8fe

diff --git a/sw/source/uibase/uiview/view2.cxx b/sw/source/uibase/uiview/view2.cxx
index 894e2a0..159941f 100644
--- a/sw/source/uibase/uiview/view2.cxx
+++ b/sw/source/uibase/uiview/view2.cxx
@@ -2384,7 +2384,7 @@ void SwView::GenerateFormLetter(bool bUseCurrentDocument)
                     "WarnDataSourceDialog",
                     "modules/swriter/ui/warndatasourcedialog.ui");
                 OUString sTmp(aWarning.get_primary_text());
-                aWarning.set_primary_text(sTmp.replaceFirst("%1", "SOURCE"));
+                aWarning.set_primary_text(sTmp.replaceFirst("%1", sSource));
                 if (RET_OK == aWarning.Execute())
                 {
                     SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
commit 738fb2ad77e5a1a4d6e2dc540886a17f4527e4db
Author: Luboš Luňák <l.lunak at collabora.com>
Date:   Sun Nov 9 15:30:08 2014 +0100

    faster mapping from nodes to SwFrmFmt's anchored at them
    
    The SwFrmFmtAnchorMap class provides reverse mapping
    to SwFrmFmt::GetAnchor().GetCntntAnchor(), so that when code somewhere needs
    to update SwFrmFmt's anchored at a position, it's not necessary to iterate
    over all of them (which can be a large number e.g. with mail merge).
    
    One special catch with the multimap of SwNodeIndex keys is that
    the values of those keys change (whenever the node structure of the document
    changes, indexes of nodes change as a result). This makes it impossible to use
    any hashing container, as the hashes would change without the container
    noticing, but multimap should work fine, as it just requires that the keys
    remain sorted, and that is the case. Nevertheless, the old code in the two
    converted places is intentionally left there in debug mode to verify the reverse
    mapping is updated correctly.
    
    I intentionally went with SwNodeIndex rather than SwPosition, as SwIndex
    (the other component of SwPosition) was causing some trouble (see e.g. the
    SwPosition comparison operator< , where two same positions are different if one
    is registered and the other not) and it doesn't appear to be actually necessary.
    
    Change-Id: I7f1768558f60155d4ba83c84aa7f9e34dc65ebf9

diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index c8b88c2..76a7713 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -99,6 +99,7 @@ class SwFmt;
 class SwFmtINetFmt;
 class SwFmtRefMark;
 class SwFrmFmt;
+class SwFrmFmtAnchorMap;
 class SwFrmFmts;
 class SwFtnIdxs;
 class SwFtnInfo;
@@ -302,6 +303,7 @@ class SW_DLLPUBLIC SwDoc :
     SwGrfFmtColl    *mpDfltGrfFmtColl;
 
     SwFrmFmts       *mpFrmFmtTbl;        //< Format table
+    SwFrmFmtAnchorMap *mpFrmFmtAnchorMap;
     SwCharFmts      *mpCharFmtTbl;
     SwFrmFmts       *mpSpzFrmFmtTbl;
     SwSectionFmts   *mpSectionFmtTbl;
@@ -811,6 +813,9 @@ public:
     const SwCharFmt *GetDfltCharFmt() const { return mpDfltCharFmt;}
           SwCharFmt *GetDfltCharFmt()       { return mpDfltCharFmt;}
 
+    const SwFrmFmtAnchorMap* GetFrmFmtAnchorMap() const { return mpFrmFmtAnchorMap; }
+    SwFrmFmtAnchorMap* GetFrmFmtAnchorMap() { return mpFrmFmtAnchorMap; }
+
     // @return the interface of the management of (auto)styles
     IStyleAccess& GetIStyleAccess() { return *mpStyleAccess; }
 
diff --git a/sw/inc/frmfmt.hxx b/sw/inc/frmfmt.hxx
index 8b33ec2..ca2c2dc 100644
--- a/sw/inc/frmfmt.hxx
+++ b/sw/inc/frmfmt.hxx
@@ -23,6 +23,8 @@
 #include <cppuhelper/weakref.hxx>
 #include <tools/gen.hxx>
 #include <format.hxx>
+#include <map>
+#include <ndindex.hxx>
 #include "swdllapi.h"
 
 class SwFlyFrm;
@@ -67,6 +69,7 @@ protected:
 
 public:
     TYPEINFO_OVERRIDE();     ///< Already in base class Client.
+    virtual ~SwFrmFmt();
 
     /// Destroys all Frms in aDepend (Frms are identified via PTR_CAST).
     virtual void DelFrms();
@@ -300,6 +303,30 @@ public:
 
 SW_DLLPUBLIC bool IsFlyFrmFmtInHeader(const SwFrmFmt& rFmt);
 
+/**
+ Fast mapping from node positions to SwFrmFmt objects anchored at them.
+
+ SwFrmFmt::GetAnchor().GetCntntAnchor() provides the position where the object is anchored.
+ This class provides the reverse mapping. It intentionally uses SwNodeIndex instead of SwPosition
+ to allow simpler implementation, do SwIndex checking explicitly if needed.
+*/
+class SwFrmFmtAnchorMap
+{
+public:
+    SwFrmFmtAnchorMap( const SwDoc* doc );
+    void Add( SwFrmFmt* fmt, const SwNodeIndex& index );
+    void Remove( SwFrmFmt* fmt, const SwNodeIndex& index );
+    typedef std::multimap< SwNodeIndex, SwFrmFmt* >::const_iterator const_iterator;
+    typedef std::pair< const_iterator, const_iterator > const_iterator_pair;
+    const_iterator_pair equal_range( const SwNodeIndex& pos ) const;
+    const_iterator lower_bound( const SwNodeIndex& pos ) const;
+    const_iterator upper_bound( const SwNodeIndex& pos ) const;
+    const_iterator end() const;
+private:
+    std::multimap< SwNodeIndex, SwFrmFmt* > items;
+    const SwDoc* doc;
+};
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/attr/swatrset.cxx b/sw/source/core/attr/swatrset.cxx
index 383abcf..62b30cc 100644
--- a/sw/source/core/attr/swatrset.cxx
+++ b/sw/source/core/attr/swatrset.cxx
@@ -27,6 +27,7 @@
 #include <editeng/lineitem.hxx>
 #include <editeng/boxitem.hxx>
 #include <editeng/editeng.hxx>
+#include <fmtanchr.hxx>
 #include <fmtpdsc.hxx>
 #include <hintids.hxx>
 #include <istyleaccess.hxx>
@@ -380,12 +381,15 @@ void SwAttrSet::CopyToModify( SwModify& rMod ) const
                 }
             }
 
+            boost::scoped_ptr< SfxItemSet > tmpSet;
+
             const SwPageDesc* pPgDesc;
             if( pSrcDoc != pDstDoc && SfxItemState::SET == GetItemState(
                                             RES_PAGEDESC, false, &pItem ) &&
                 0 != ( pPgDesc = ((SwFmtPageDesc*)pItem)->GetPageDesc()) )
             {
-                SfxItemSet aTmpSet( *this );
+                if( !tmpSet )
+                    tmpSet.reset( new SfxItemSet( *this ));
 
                 SwPageDesc* pDstPgDesc = pDstDoc->FindPageDesc(pPgDesc->GetName());
                 if( !pDstPgDesc )
@@ -395,20 +399,33 @@ void SwAttrSet::CopyToModify( SwModify& rMod ) const
                 }
                 SwFmtPageDesc aDesc( pDstPgDesc );
                 aDesc.SetNumOffset( ((SwFmtPageDesc*)pItem)->GetNumOffset() );
-                aTmpSet.Put( aDesc );
+                tmpSet->Put( aDesc );
+            }
 
+            if( pSrcDoc != pDstDoc && SfxItemState::SET == GetItemState( RES_ANCHOR, false, &pItem )
+                && static_cast< const SwFmtAnchor* >( pItem )->GetCntntAnchor() != NULL )
+            {
+                if( !tmpSet )
+                    tmpSet.reset( new SfxItemSet( *this ));
+                // Anchors at any node position cannot be copied to another document, because the SwPosition
+                // would still point to the old document. It needs to be fixed up explicitly.
+                tmpSet->ClearItem( RES_ANCHOR );
+            }
+
+            if( tmpSet )
+            {
                 if( pCNd )
                 {
                     // #i92811#
                     if ( pNewListIdItem != 0 )
                     {
-                        aTmpSet.Put( *pNewListIdItem );
+                        tmpSet->Put( *pNewListIdItem );
                     }
-                    pCNd->SetAttr( aTmpSet );
+                    pCNd->SetAttr( *tmpSet );
                 }
                 else
                 {
-                    pFmt->SetFmtAttr( aTmpSet );
+                    pFmt->SetFmtAttr( *tmpSet );
                 }
             }
             else if( pCNd )
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index 70bda8c..c6d353b 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -231,6 +231,7 @@ SwDoc::SwDoc()
     mpDfltTxtFmtColl( new SwTxtFmtColl( GetAttrPool(), sTxtCollStr ) ),
     mpDfltGrfFmtColl( new SwGrfFmtColl( GetAttrPool(), sGrfCollStr ) ),
     mpFrmFmtTbl( new SwFrmFmts() ),
+    mpFrmFmtAnchorMap( new SwFrmFmtAnchorMap( this ) ),
     mpCharFmtTbl( new SwCharFmts() ),
     mpSpzFrmFmtTbl( new SwFrmFmts() ),
     mpSectionFmtTbl( new SwSectionFmts() ),
@@ -609,6 +610,7 @@ SwDoc::~SwDoc()
     delete mpDfltCharFmt;
     delete mpDfltFrmFmt;
     delete mpLayoutCache;
+    delete mpFrmFmtAnchorMap;
 
     SfxItemPool::Free(mpAttrPool);
 }
diff --git a/sw/source/core/inc/flyfrm.hxx b/sw/source/core/inc/flyfrm.hxx
index 33f0aa7..3208259 100644
--- a/sw/source/core/inc/flyfrm.hxx
+++ b/sw/source/core/inc/flyfrm.hxx
@@ -57,7 +57,7 @@ bool CalcClipRect( const SdrObject *pSdrObj, SwRect &rRect, bool bMove = true );
 class SwFlyFrm : public SwLayoutFrm, public SwAnchoredObject
 {
     // is allowed to lock, implemented in frmtool.cxx
-    friend void AppendObjs   ( const SwFrmFmts *, sal_uLong, SwFrm *, SwPageFrm * );
+    friend void AppendObjs   ( const SwFrmFmts *, sal_uLong, SwFrm *, SwPageFrm *, SwDoc* );
     friend void Notify( SwFlyFrm *, SwPageFrm *pOld, const SwRect &rOld,
                         const SwRect* pOldPrt );
 
diff --git a/sw/source/core/inc/frmtool.hxx b/sw/source/core/inc/frmtool.hxx
index 8df9df1..8003042 100644
--- a/sw/source/core/inc/frmtool.hxx
+++ b/sw/source/core/inc/frmtool.hxx
@@ -52,7 +52,7 @@ class SwFrmFmts;
 #define GRFNUM_REPLACE 2
 
 void AppendObjs( const SwFrmFmts *pTbl, sal_uLong nIndex,
-                       SwFrm *pFrm, SwPageFrm *pPage );
+                       SwFrm *pFrm, SwPageFrm *pPage, SwDoc* doc );
 
 // draw background with brush or graphics
 // The 6th parameter indicates that the method should consider background
diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx
index d9ffa19..f3304f5 100644
--- a/sw/source/core/layout/atrfrm.cxx
+++ b/sw/source/core/layout/atrfrm.cxx
@@ -2423,6 +2423,16 @@ SwFrmFmt::SwFrmFmt(
 {
 }
 
+SwFrmFmt::~SwFrmFmt()
+{
+    if( !GetDoc()->IsInDtor())
+    {
+        const SwFmtAnchor& anchor = GetAnchor();
+        if( anchor.GetCntntAnchor() != NULL )
+            GetDoc()->GetFrmFmtAnchorMap()->Remove( this, anchor.GetCntntAnchor()->nNode );
+    }
+}
+
 bool SwFrmFmt::supportsFullDrawingLayerFillAttributeSet() const
 {
     return true;
@@ -2490,6 +2500,31 @@ void SwFrmFmt::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
     {   // invalidate cached uno object
         SetXObject(uno::Reference<uno::XInterface>(0));
     }
+
+    const SwPosition* oldAnchorPosition = NULL;
+    const SwPosition* newAnchorPosition = NULL;
+    if( pNew && pNew->Which() == RES_ATTRSET_CHG )
+    {
+        const SfxPoolItem* tmp = NULL;
+        static_cast< const SwAttrSetChg* >(pNew)->GetChgSet()->GetItemState( RES_ANCHOR, false, &tmp );
+        if( tmp )
+            newAnchorPosition = static_cast< const SwFmtAnchor* >( tmp )->GetCntntAnchor();
+    }
+    if( pNew && pNew->Which() == RES_ANCHOR )
+        newAnchorPosition = static_cast< const SwFmtAnchor* >( pNew )->GetCntntAnchor();
+    if( pOld && pOld->Which() == RES_ATTRSET_CHG )
+    {
+        const SfxPoolItem* tmp = NULL;
+        static_cast< const SwAttrSetChg* >(pOld)->GetChgSet()->GetItemState( RES_ANCHOR, false, &tmp );
+        if( tmp )
+            oldAnchorPosition = static_cast< const SwFmtAnchor* >( tmp )->GetCntntAnchor();
+    }
+    if( pOld && pOld->Which() == RES_ANCHOR )
+        oldAnchorPosition = static_cast< const SwFmtAnchor* >( pOld )->GetCntntAnchor();
+    if( oldAnchorPosition != NULL && ( newAnchorPosition == NULL || oldAnchorPosition->nNode.GetIndex() != newAnchorPosition->nNode.GetIndex()))
+        GetDoc()->GetFrmFmtAnchorMap()->Remove( this, oldAnchorPosition->nNode );
+    if( newAnchorPosition != NULL && ( oldAnchorPosition == NULL || oldAnchorPosition->nNode.GetIndex() != newAnchorPosition->nNode.GetIndex()))
+        GetDoc()->GetFrmFmtAnchorMap()->Add( this, newAnchorPosition->nNode );
 }
 
 void SwFrmFmt::RegisterToFormat( SwFmt& rFmt )
@@ -3299,4 +3334,52 @@ bool IsFlyFrmFmtInHeader(const SwFrmFmt& rFmt)
     return false;
 }
 
+
+SwFrmFmtAnchorMap::SwFrmFmtAnchorMap( const SwDoc* _doc )
+: doc( _doc )
+{
+}
+
+void SwFrmFmtAnchorMap::Add( SwFrmFmt* fmt, const SwNodeIndex& pos )
+{
+    assert( pos.GetNode().GetDoc() == doc );
+    items.insert( std::make_pair( pos, fmt ));
+}
+
+void SwFrmFmtAnchorMap::Remove( SwFrmFmt* fmt, const SwNodeIndex& pos )
+{
+    assert( pos.GetNode().GetDoc() == doc );
+    typedef std::multimap< SwNodeIndex, SwFrmFmt* >::iterator iterator;
+    std::pair< iterator, iterator > range = items.equal_range( pos );
+    for( iterator it = range.first; it != range.second; ++it )
+    {
+        if( it->second == fmt )
+        {
+            items.erase( it );
+            return;
+        }
+    }
+    assert( false );
+}
+
+SwFrmFmtAnchorMap::const_iterator_pair SwFrmFmtAnchorMap::equal_range( const SwNodeIndex& pos ) const
+{
+    return items.equal_range( pos );
+}
+
+SwFrmFmtAnchorMap::const_iterator SwFrmFmtAnchorMap::lower_bound( const SwNodeIndex& pos ) const
+{
+    return items.lower_bound( pos );
+}
+
+SwFrmFmtAnchorMap::const_iterator SwFrmFmtAnchorMap::upper_bound( const SwNodeIndex& pos ) const
+{
+    return items.upper_bound( pos );
+}
+
+SwFrmFmtAnchorMap::const_iterator SwFrmFmtAnchorMap::end() const
+{
+    return items.end();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/layout/frmtool.cxx b/sw/source/core/layout/frmtool.cxx
index 8d92e4f..5132eec 100644
--- a/sw/source/core/layout/frmtool.cxx
+++ b/sw/source/core/layout/frmtool.cxx
@@ -999,15 +999,36 @@ SwCntntNotify::~SwCntntNotify()
 }
 
 void AppendObjs( const SwFrmFmts *pTbl, sal_uLong nIndex,
-                        SwFrm *pFrm, SwPageFrm *pPage )
+                        SwFrm *pFrm, SwPageFrm *pPage, SwDoc* doc )
 {
+#if OSL_DEBUG_LEVEL > 0
+    std::list<SwFrmFmt*> checkFmts;
     for ( sal_uInt16 i = 0; i < pTbl->size(); ++i )
     {
-        SwFrmFmt *pFmt = (SwFrmFmt*)(*pTbl)[i];
+        SwFrmFmt *pFmt = (*pTbl)[i];
         const SwFmtAnchor &rAnch = pFmt->GetAnchor();
         if ( rAnch.GetCntntAnchor() &&
              (rAnch.GetCntntAnchor()->nNode.GetIndex() == nIndex) )
         {
+            checkFmts.push_back( pFmt );
+        }
+    }
+#endif
+    SwFrmFmtAnchorMap::const_iterator_pair range = doc->GetFrmFmtAnchorMap()->equal_range( SwNodeIndex( doc->GetNodes(), nIndex ));
+    for( std::multimap< SwNodeIndex, SwFrmFmt* >::const_iterator it = range.first;
+         it != range.second;
+         )
+    {
+        SwFrmFmt *pFmt = it->second;
+        const SwFmtAnchor &rAnch = pFmt->GetAnchor();
+        if ( rAnch.GetCntntAnchor() &&
+             (rAnch.GetCntntAnchor()->nNode.GetIndex() == nIndex) )
+        {
+#if OSL_DEBUG_LEVEL > 0
+            std::list<SwFrmFmt*>::iterator checkPos = std::find( checkFmts.begin(), checkFmts.end(), pFmt );
+            assert( checkPos != checkFmts.end());
+            checkFmts.erase( checkPos );
+#endif
             const bool bFlyAtFly = rAnch.GetAnchorId() == FLY_AT_FLY; // LAYER_IMPL
             //Is a frame or a SdrObject described?
             const bool bSdrObj = RES_DRAWFRMFMT == pFmt->Which();
@@ -1025,8 +1046,8 @@ void AppendObjs( const SwFrmFmts *pTbl, sal_uLong nIndex,
                 if ( bSdrObj && 0 == (pSdrObj = pFmt->FindSdrObject()) )
                 {
                     OSL_ENSURE( !bSdrObj, "DrawObject not found." );
+                    ++it;
                     pFmt->GetDoc()->DelFrmFmt( pFmt );
-                    --i;
                     continue;
                 }
                 if ( pSdrObj )
@@ -1071,7 +1092,11 @@ void AppendObjs( const SwFrmFmts *pTbl, sal_uLong nIndex,
                 }
             }
         }
+        ++it;
     }
+#if OSL_DEBUG_LEVEL > 0
+    assert( checkFmts.empty());
+#endif
 }
 
 static bool lcl_ObjConnected( const SwFrmFmt *pFmt, const SwFrm* pSib )
@@ -1311,7 +1336,7 @@ void _InsertCnt( SwLayoutFrm *pLay, SwDoc *pDoc,
             pPrv = pFrm;
 
             if ( !pTbl->empty() && bObjsDirect && !bDontCreateObjects )
-                AppendObjs( pTbl, nIndex, pFrm, pPage );
+                AppendObjs( pTbl, nIndex, pFrm, pPage, pDoc );
         }
         else if ( pNd->IsTableNode() )
         {   //Should we have encountered a table?
@@ -1531,7 +1556,7 @@ void _InsertCnt( SwLayoutFrm *pLay, SwDoc *pDoc,
             {
                 SwFlyFrm* pFly = pLay->FindFlyFrm();
                 if( pFly )
-                    AppendObjs( pTbl, nIndex, pFly, pPage );
+                    AppendObjs( pTbl, nIndex, pFly, pPage, pDoc );
             }
         }
         else
diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index cbf90520..bdc39aa 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -1093,7 +1093,7 @@ bool SwTabFrm::Split( const SwTwips nCutPos, bool bTryToSplit, bool bTableRowKee
                 while( pFrm )
                 {
                     nIndex = pFrm->GetNode()->GetIndex();
-                    AppendObjs( pTbl, nIndex, pFrm, pPage );
+                    AppendObjs( pTbl, nIndex, pFrm, pPage, GetFmt()->GetDoc());
                     pFrm = pFrm->GetNextCntntFrm();
                     if( !pHeadline->IsAnLower( pFrm ) )
                         break;
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index bf15ea2..0146d4f 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -1106,6 +1106,8 @@ void SwTxtNode::Update(
         }
 
         // at-char anchored flys shouldn't be moved, either.
+#if OSL_DEBUG_LEVEL > 0
+        std::list<SwFrmFmt*> checkFmts;
         const SwFrmFmts& rFmts = *GetDoc()->GetSpzFrmFmts();
         for (SwFrmFmts::const_iterator pFmt = rFmts.begin(); pFmt != rFmts.end(); ++pFmt)
         {
@@ -1116,10 +1118,43 @@ void SwTxtNode::Update(
                 // The fly is at-char anchored and has an anchor position.
                 SwIndex& rEndIdx = const_cast<SwIndex&>(pCntntAnchor->nContent);
                 if (&pCntntAnchor->nNode.GetNode() == this && rEndIdx.GetIndex() == rPos.GetIndex())
+                {
                     // The anchor position is exactly our insert position.
+                    #if 0
                     rEndIdx.Assign(&aTmpIdxReg, rEndIdx.GetIndex());
+                    #endif
+                    checkFmts.push_back( *pFmt );
+                }
             }
         }
+#endif
+        SwFrmFmtAnchorMap::const_iterator_pair range = GetDoc()->GetFrmFmtAnchorMap()->equal_range( SwNodeIndex( *this ));
+        for( SwFrmFmtAnchorMap::const_iterator it = range.first;
+             it != range.second;
+             ++it )
+        {
+            SwFrmFmt *pFmt = it->second;
+            const SwFmtAnchor& rAnchor = pFmt->GetAnchor();
+            const SwPosition* pCntntAnchor = rAnchor.GetCntntAnchor();
+            if (rAnchor.GetAnchorId() == FLY_AT_CHAR && pCntntAnchor)
+            {
+                // The fly is at-char anchored and has an anchor position.
+                SwIndex& rEndIdx = const_cast<SwIndex&>(pCntntAnchor->nContent);
+                if (&pCntntAnchor->nNode.GetNode() == this && rEndIdx.GetIndex() == rPos.GetIndex())
+                {
+                    // The anchor position is exactly our insert position.
+                    rEndIdx.Assign(&aTmpIdxReg, rEndIdx.GetIndex());
+#if OSL_DEBUG_LEVEL > 0
+                    std::list<SwFrmFmt*>::iterator checkPos = std::find( checkFmts.begin(), checkFmts.end(), pFmt );
+                    assert( checkPos != checkFmts.end());
+                    checkFmts.erase( checkPos );
+#endif
+                }
+            }
+        }
+#if OSL_DEBUG_LEVEL > 0
+        assert( checkFmts.empty());
+#endif
     }
 
     // base class
commit b21df5a993a3815cf736fe3d2eab73eee646b38e
Author: Luboš Luňák <l.lunak at collabora.com>
Date:   Sun Nov 9 10:33:00 2014 +0100

    do not break encapsulation of SwFmtAnchor::GetCntntAnchor()
    
    Change-Id: I0a320eb990f9a3b6800447a97a84c118239bae96

diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index 7a6319b..8b53daf 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -3275,7 +3275,8 @@ void DocumentContentOperationsManager::CopyFlyInFlyImpl(
         // #i59964#
         // correct determination of new anchor position
         SwFmtAnchor aAnchor( *(*it).GetAnchor() );
-        SwPosition* pNewPos = (SwPosition*)aAnchor.GetCntntAnchor();
+        assert( aAnchor.GetCntntAnchor() != NULL );
+        SwPosition newPos = *aAnchor.GetCntntAnchor();
         // for at-paragraph and at-character anchored objects the new anchor
         // position can *not* be determined by the difference of the current
         // anchor position to the start of the copied range, because not
@@ -3341,25 +3342,26 @@ void DocumentContentOperationsManager::CopyFlyInFlyImpl(
                 }
             }
             // apply found anchor text node as new anchor position
-            pNewPos->nNode = aAnchorNdIdx;
+            newPos.nNode = aAnchorNdIdx;
         }
         else
         {
-            long nOffset = pNewPos->nNode.GetIndex() - rRg.aStart.GetIndex();
+            long nOffset = newPos.nNode.GetIndex() - rRg.aStart.GetIndex();
             SwNodeIndex aIdx( rStartIdx, nOffset );
-            pNewPos->nNode = aIdx;
+            newPos.nNode = aIdx;
         }
         // Set the character bound Flys back at the original character
         if ((FLY_AT_CHAR == aAnchor.GetAnchorId()) &&
-             pNewPos->nNode.GetNode().IsTxtNode() )
+             newPos.nNode.GetNode().IsTxtNode() )
         {
-            pNewPos->nContent.Assign( (SwTxtNode*)&pNewPos->nNode.GetNode(),
-                                        pNewPos->nContent.GetIndex() );
+            newPos.nContent.Assign( (SwTxtNode*)&newPos.nNode.GetNode(),
+                                        newPos.nContent.GetIndex() );
         }
         else
         {
-            pNewPos->nContent.Assign( 0, 0 );
+            newPos.nContent.Assign( 0, 0 );
         }
+        aAnchor.SetAnchor( &newPos );
 
         // Check recursion: copy content in its own frame, then don't copy it.
         bool bMakeCpy = true;
diff --git a/sw/source/core/frmedt/fefly1.cxx b/sw/source/core/frmedt/fefly1.cxx
index 8c104cb..43ca2ea 100644
--- a/sw/source/core/frmedt/fefly1.cxx
+++ b/sw/source/core/frmedt/fefly1.cxx
@@ -479,9 +479,10 @@ Point SwFEShell::FindAnchorPos( const Point& rAbsPos, bool bMoveIt )
                 {
                     case FLY_AT_PARA:
                     {
-                        SwPosition *pPos = (SwPosition*)aAnch.GetCntntAnchor();
-                        pPos->nNode = *pTxtFrm->GetNode();
-                        pPos->nContent.Assign(0,0);
+                        SwPosition pos = *aAnch.GetCntntAnchor();
+                        pos.nNode = *pTxtFrm->GetNode();
+                        pos.nContent.Assign(0,0);
+                        aAnch.SetAnchor( &pos );
                         break;
                     }
                     case FLY_AT_PAGE:
@@ -501,19 +502,20 @@ Point SwFEShell::FindAnchorPos( const Point& rAbsPos, bool bMoveIt )
 
                     case FLY_AT_CHAR:
                         {
-                            SwPosition *pPos = (SwPosition*)aAnch.GetCntntAnchor();
+                            SwPosition pos = *aAnch.GetCntntAnchor();
                             Point aTmpPnt( rAbsPos );
-                            if( pTxtFrm->GetCrsrOfst( pPos, aTmpPnt, NULL ) )
+                            if( pTxtFrm->GetCrsrOfst( &pos, aTmpPnt, NULL ) )
                             {
                                 SwRect aTmpRect;
-                                pTxtFrm->GetCharRect( aTmpRect, *pPos );
+                                pTxtFrm->GetCharRect( aTmpRect, pos );
                                 aRet = aTmpRect.Pos();
                             }
                             else
                             {
-                                pPos->nNode = *pTxtFrm->GetNode();
-                                pPos->nContent.Assign(0,0);
+                                pos.nNode = *pTxtFrm->GetNode();
+                                pos.nContent.Assign(0,0);
                             }
+                            aAnch.SetAnchor( &pos );
                             break;
                         }
                     default:
diff --git a/sw/source/core/frmedt/feshview.cxx b/sw/source/core/frmedt/feshview.cxx
index 8fe4b7c..18bcf01 100644
--- a/sw/source/core/frmedt/feshview.cxx
+++ b/sw/source/core/frmedt/feshview.cxx
@@ -352,15 +352,15 @@ bool SwFEShell::MoveAnchor( SwMove nDir )
                 OSL_ENSURE( pOld->IsCntntFrm(), "Wrong anchor, page expected." );
                 if( SwMove::LEFT == nDir || SwMove::RIGHT == nDir )
                 {
-                    SwPosition *pPos = (SwPosition*)aAnch.GetCntntAnchor();
+                    SwPosition pos = *aAnch.GetCntntAnchor();
                     SwTxtNode* pTxtNd = ((SwTxtFrm*)pOld)->GetTxtNode();
-                    const sal_Int32 nAct = pPos->nContent.GetIndex();
+                    const sal_Int32 nAct = pos.nContent.GetIndex();
                     if( SwMove::LEFT == nDir )
                     {
                         bRet = true;
                         if( nAct )
                         {
-                            pPos->nContent.Assign( pTxtNd, nAct-1 );
+                            pos.nContent.Assign( pTxtNd, nAct-1 );
                         }
                         else
                             nDir = SwMove::UP;
@@ -372,11 +372,13 @@ bool SwFEShell::MoveAnchor( SwMove nDir )
                         if( nAct < nMax )
                         {
                             bRet = true;
-                            pPos->nContent.Assign( pTxtNd, nAct+1 );
+                            pos.nContent.Assign( pTxtNd, nAct+1 );
                         }
                         else
                             nDir = SwMove::DOWN;
                     }
+                    if( pos != *aAnch.GetCntntAnchor())
+                        aAnch.SetAnchor( &pos );
                 }
             } // no break!
             case FLY_AT_PARA:
@@ -388,9 +390,9 @@ bool SwFEShell::MoveAnchor( SwMove nDir )
                     pNew = pOld->FindNext();
                 if( pNew && pNew != pOld && pNew->IsCntntFrm() )
                 {
-                    SwPosition *pPos = (SwPosition*)aAnch.GetCntntAnchor();
+                    SwPosition pos = *aAnch.GetCntntAnchor();
                     SwTxtNode* pTxtNd = ((SwTxtFrm*)pNew)->GetTxtNode();
-                    pPos->nNode = *pTxtNd;
+                    pos.nNode = *pTxtNd;
                     sal_Int32 nTmp = 0;
                     if( bRet )
                     {
@@ -398,7 +400,8 @@ bool SwFEShell::MoveAnchor( SwMove nDir )
                         if( nTmp )
                             --nTmp;
                     }
-                    pPos->nContent.Assign( pTxtNd, nTmp );
+                    pos.nContent.Assign( pTxtNd, nTmp );
+                    aAnch.SetAnchor( &pos );
                     bRet = true;
                 }
                 else if( SwMove::UP == nDir || SwMove::DOWN == nDir )
diff --git a/sw/source/core/layout/flycnt.cxx b/sw/source/core/layout/flycnt.cxx
index 0626338..b391363 100644
--- a/sw/source/core/layout/flycnt.cxx
+++ b/sw/source/core/layout/flycnt.cxx
@@ -1327,21 +1327,21 @@ void SwFlyAtCntFrm::SetAbsPos( const Point &rNew )
     {
         //Set the anchor attribute according to the new Cnt.
         SwFmtAnchor aAnch( pFmt->GetAnchor() );
-        SwPosition *pPos = (SwPosition*)aAnch.GetCntntAnchor();
+        SwPosition pos = *aAnch.GetCntntAnchor();
         if( IsAutoPos() && pCnt->IsTxtFrm() )
         {
             SwCrsrMoveState eTmpState( MV_SETONLYTEXT );
             Point aPt( rNew );
-            if( pCnt->GetCrsrOfst( pPos, aPt, &eTmpState )
-                && pPos->nNode == *pCnt->GetNode() )
+            if( pCnt->GetCrsrOfst( &pos, aPt, &eTmpState )
+                && pos.nNode == *pCnt->GetNode() )
             {
                 if ( pCnt->GetNode()->GetTxtNode() != NULL )
                 {
                     const SwTxtAttr* pTxtInputFld =
-                        pCnt->GetNode()->GetTxtNode()->GetTxtAttrAt( pPos->nContent.GetIndex(), RES_TXTATR_INPUTFIELD, SwTxtNode::PARENT );
+                        pCnt->GetNode()->GetTxtNode()->GetTxtAttrAt( pos.nContent.GetIndex(), RES_TXTATR_INPUTFIELD, SwTxtNode::PARENT );
                     if ( pTxtInputFld != NULL )
                     {
-                        pPos->nContent = pTxtInputFld->GetStart();
+                        pos.nContent = pTxtInputFld->GetStart();
                     }
                 }
                 ResetLastCharRectHeight();
@@ -1352,15 +1352,16 @@ void SwFlyAtCntFrm::SetAbsPos( const Point &rNew )
             }
             else
             {
-                pPos->nNode = *pCnt->GetNode();
-                pPos->nContent.Assign( pCnt->GetNode(), 0 );
+                pos.nNode = *pCnt->GetNode();
+                pos.nContent.Assign( pCnt->GetNode(), 0 );
             }
         }
         else
         {
-            pPos->nNode = *pCnt->GetNode();
-            pPos->nContent.Assign( pCnt->GetNode(), 0 );
+            pos.nNode = *pCnt->GetNode();
+            pos.nContent.Assign( pCnt->GetNode(), 0 );
         }
+        aAnch.SetAnchor( &pos );
 
         // handle change of anchor node:
         // if count of the anchor frame also change, the fly frames have to be
diff --git a/sw/source/core/txtnode/atrflyin.cxx b/sw/source/core/txtnode/atrflyin.cxx
index a961b64..7dc780e 100644
--- a/sw/source/core/txtnode/atrflyin.cxx
+++ b/sw/source/core/txtnode/atrflyin.cxx
@@ -115,17 +115,18 @@ void SwTxtFlyCnt::CopyFlyFmt( SwDoc* pDoc )
         if( !pCNd )
             pCNd = pDoc->GetNodes().GoNext( &aIdx );
 
-        SwPosition* pPos = (SwPosition*)aAnchor.GetCntntAnchor();
-        pPos->nNode = aIdx;
+        SwPosition pos = *aAnchor.GetCntntAnchor();
+        pos.nNode = aIdx;
         if (FLY_AS_CHAR == aAnchor.GetAnchorId())
         {
-            pPos->nContent.Assign( pCNd, 0 );
+            pos.nContent.Assign( pCNd, 0 );
         }
         else
         {
-            pPos->nContent.Assign( 0, 0 );
+            pos.nContent.Assign( 0, 0 );
             OSL_ENSURE( false, "CopyFlyFmt: Was fuer ein Anker?" );
         }
+        aAnchor.SetAnchor( &pos );
     }
 
     SwFrmFmt* pNew = pDoc->getIDocumentLayoutAccess().CopyLayoutFmt( *pFmt, aAnchor, false, false );
diff --git a/sw/source/core/undo/undobj1.cxx b/sw/source/core/undo/undobj1.cxx
index 572cd16..13a0c12 100644
--- a/sw/source/core/undo/undobj1.cxx
+++ b/sw/source/core/undo/undobj1.cxx
@@ -593,7 +593,7 @@ void SwUndoSetFlyFmt::UndoImpl(::sw::UndoRedoContext & rContext)
 
             if (FLY_AS_CHAR == aNewAnchor.GetAnchorId())
             {
-                SwPosition* pPos = (SwPosition*)aNewAnchor.GetCntntAnchor();
+                const SwPosition* pPos = aNewAnchor.GetCntntAnchor();
                 SwFmtFlyCnt aFmt( pFrmFmt );
                 pPos->nNode.GetNode().GetTxtNode()->InsertItem( aFmt,
                     nOldCntnt, 0 );
commit 92e00493aed5a9d82d306bbd9a9e76276d1abcea
Author: Luboš Luňák <l.lunak at collabora.com>
Date:   Sat Nov 8 20:57:45 2014 +0100

    const
    
    Change-Id: Ie2f4c5059a4160287690cf7a4e99472d9a575102

diff --git a/sw/source/core/doc/docchart.cxx b/sw/source/core/doc/docchart.cxx
index 196fda1..1b48a92 100644
--- a/sw/source/core/doc/docchart.cxx
+++ b/sw/source/core/doc/docchart.cxx
@@ -95,7 +95,7 @@ void SwDoc::DoUpdateAllCharts()
         {
             SwTable* pTmpTbl;
             const SwTableNode* pTblNd;
-            SwFrmFmt* pFmt = rTblFmts[ n ];
+            const SwFrmFmt* pFmt = rTblFmts[ n ];
 
             if( 0 != ( pTmpTbl = SwTable::FindTable( pFmt ) ) &&
                 0 != ( pTblNd = pTmpTbl->GetTableNode() ) &&
@@ -149,7 +149,7 @@ void SwDoc::SetTableName( SwFrmFmt& rTblFmt, const OUString &rNewName )
     bool bNameFound = rNewName.isEmpty();
     if( !bNameFound )
     {
-        SwFrmFmt* pFmt;
+        const SwFrmFmt* pFmt;
         const SwFrmFmts& rTbl = *GetTblFrmFmts();
         for( sal_uInt16 i = rTbl.size(); i; )
             if( !( pFmt = rTbl[ --i ] )->IsDefault() &&
diff --git a/sw/source/core/doc/docedt.cxx b/sw/source/core/doc/docedt.cxx
index 456740a..50e8e2f 100644
--- a/sw/source/core/doc/docedt.cxx
+++ b/sw/source/core/doc/docedt.cxx
@@ -88,7 +88,7 @@ void _SaveFlyInRange( const SwNodeRange& rRg, _SaveFlyArr& rArr )
     SwFrmFmts& rFmts = *rRg.aStart.GetNode().GetDoc()->GetSpzFrmFmts();
     for( sal_uInt16 n = 0; n < rFmts.size(); ++n )
     {
-        SwFrmFmt *const pFmt = static_cast<SwFrmFmt*>(rFmts[n]);
+        SwFrmFmt *const pFmt = rFmts[n];
         SwFmtAnchor const*const pAnchor = &pFmt->GetAnchor();
         SwPosition const*const pAPos = pAnchor->GetCntntAnchor();
         if (pAPos &&
diff --git a/sw/source/core/doc/docsort.cxx b/sw/source/core/doc/docsort.cxx
index a335a29..6475c34 100644
--- a/sw/source/core/doc/docsort.cxx
+++ b/sw/source/core/doc/docsort.cxx
@@ -298,7 +298,7 @@ bool SwDoc::SortText(const SwPaM& rPaM, const SwSortOptions& rOpt)
     // Set index to the Selection's start
     for ( sal_uInt16 n = 0; n < GetSpzFrmFmts()->size(); ++n )
     {
-        SwFrmFmt *const pFmt = static_cast<SwFrmFmt*>((*GetSpzFrmFmts())[n]);
+        const SwFrmFmt *const pFmt = (*GetSpzFrmFmts())[n];
         SwFmtAnchor const*const pAnchor = &pFmt->GetAnchor();
         SwPosition const*const pAPos = pAnchor->GetCntntAnchor();
 
diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx
index e106ddb..e48160f 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -527,7 +527,7 @@ void SwTextBoxHelper::saveLinks(const SwFrmFmts& rFormats, std::map<const SwFrmF
 {
     for (size_t i = 0; i < rFormats.size(); ++i)
     {
-        SwFrmFmt* pFmt = rFormats[i];
+        const SwFrmFmt* pFmt = rFormats[i];
         if (pFmt->Which() != RES_DRAWFRMFMT)
             continue;
         if (SwFrmFmt* pTextBox = findTextBox(pFmt))
diff --git a/sw/source/core/docnode/node.cxx b/sw/source/core/docnode/node.cxx
index ee5a621..ee2c7be 100644
--- a/sw/source/core/docnode/node.cxx
+++ b/sw/source/core/docnode/node.cxx
@@ -515,7 +515,7 @@ const SwPageDesc* SwNode::FindPageDesc( bool bCalcLay,
 
             for( n = 0; n < rFmts.size(); ++n )
             {
-                SwFrmFmt* pFrmFmt = rFmts[ n ];
+                const SwFrmFmt* pFrmFmt = rFmts[ n ];
                 const SwFmtCntnt& rCntnt = pFrmFmt->GetCntnt();
                 if( rCntnt.GetCntntIdx() &&
                     &rCntnt.GetCntntIdx()->GetNode() == (SwNode*)pSttNd )
diff --git a/sw/source/core/draw/dcontact.cxx b/sw/source/core/draw/dcontact.cxx
index fc85ef5..aa99a18 100644
--- a/sw/source/core/draw/dcontact.cxx
+++ b/sw/source/core/draw/dcontact.cxx
@@ -636,7 +636,7 @@ void SwDrawContact::GetTextObjectsFromFmt( std::list<SdrTextObj*>& rTextObjects,
 {
     for( sal_Int32 n=0; n<(sal_Int32)pDoc->GetSpzFrmFmts()->size(); n++ )
     {
-        SwFrmFmt* pFly = (*pDoc->GetSpzFrmFmts())[n];
+        const SwFrmFmt* pFly = (*pDoc->GetSpzFrmFmts())[n];
         if( pFly->IsA( TYPE(SwDrawFrmFmt) ) )
         {
             SwDrawContact* pContact = SwIterator<SwDrawContact,SwFrmFmt>::FirstElement(*pFly);
diff --git a/sw/source/core/layout/frmtool.cxx b/sw/source/core/layout/frmtool.cxx
index a2cda52..8d92e4f 100644
--- a/sw/source/core/layout/frmtool.cxx
+++ b/sw/source/core/layout/frmtool.cxx
@@ -1074,7 +1074,7 @@ void AppendObjs( const SwFrmFmts *pTbl, sal_uLong nIndex,
     }
 }
 
-static bool lcl_ObjConnected( SwFrmFmt *pFmt, const SwFrm* pSib )
+static bool lcl_ObjConnected( const SwFrmFmt *pFmt, const SwFrm* pSib )
 {
     if ( RES_FLYFRMFMT == pFmt->Which() )
     {
@@ -1101,7 +1101,7 @@ static bool lcl_ObjConnected( SwFrmFmt *pFmt, const SwFrm* pSib )
 
     OD 23.06.2003 #108784#
 */
-static bool lcl_InHeaderOrFooter( SwFrmFmt& _rFmt )
+static bool lcl_InHeaderOrFooter( const SwFrmFmt& _rFmt )
 {
     bool bRetVal = false;
 
diff --git a/sw/source/core/unocore/unochart.cxx b/sw/source/core/unocore/unochart.cxx
index 2434798..cec7d22 100644
--- a/sw/source/core/unocore/unochart.cxx
+++ b/sw/source/core/unocore/unochart.cxx
@@ -123,7 +123,7 @@ void SwChartLockController_Helper::LockUnlockAllCharts( bool bLock )
     {
         SwTable* pTmpTbl;
         const SwTableNode* pTblNd;
-        SwFrmFmt* pFmt = rTblFmts[ n ];
+        const SwFrmFmt* pFmt = rTblFmts[ n ];
 
         if( 0 != ( pTmpTbl = SwTable::FindTable( pFmt ) ) &&
             0 != ( pTblNd = pTmpTbl->GetTableNode() ) &&
diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index 7101506..cb9417c 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -512,7 +512,7 @@ static sal_Int32 lcl_GetCountOrName(const SwDoc &rDoc,
             const size_t nArrLen = rDoc.GetFrmFmts()->size();
             for( size_t i = 0; i < nArrLen; ++i )
             {
-                SwFrmFmt* pFmt = (*rDoc.GetFrmFmts())[ i ];
+                const SwFrmFmt* pFmt = (*rDoc.GetFrmFmts())[ i ];
                 if(pFmt->IsDefault() || pFmt->IsAuto())
                     continue;
                 if ( IsPoolUserFmt ( pFmt->GetPoolFmtId() ) )
diff --git a/sw/source/core/unocore/unotbl.cxx b/sw/source/core/unocore/unotbl.cxx
index 73ac3ee..87f0b63 100644
--- a/sw/source/core/unocore/unotbl.cxx
+++ b/sw/source/core/unocore/unotbl.cxx
@@ -3626,7 +3626,7 @@ void SwXTextTable::setName(const OUString& rName) throw( uno::RuntimeException,
     if(pFmt)
     {
         const OUString aOldName( pFmt->GetName() );
-        SwFrmFmt* pTmpFmt;
+        const SwFrmFmt* pTmpFmt;
         const SwFrmFmts* pTbl = pFmt->GetDoc()->GetTblFrmFmts();
         for( size_t i = pTbl->size(); i; )
             if( !( pTmpFmt = (*pTbl)[ --i ] )->IsDefault() &&
diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx
index f0c5f44..ae73060 100644
--- a/sw/source/core/unocore/unotext.cxx
+++ b/sw/source/core/unocore/unotext.cxx
@@ -1665,7 +1665,7 @@ SwXText::convertToTextFrame(
     std::set<OUString> aAnchoredFrames;
     for (size_t i = 0; i < m_pImpl->m_pDoc->GetSpzFrmFmts()->size(); ++i)
     {
-        SwFrmFmt* pFrmFmt = (*m_pImpl->m_pDoc->GetSpzFrmFmts())[i];
+        const SwFrmFmt* pFrmFmt = (*m_pImpl->m_pDoc->GetSpzFrmFmts())[i];
         const SwFmtAnchor& rAnchor = pFrmFmt->GetAnchor();
         if (FLY_AT_PARA == rAnchor.GetAnchorId() &&
                 aStartPam.Start()->nNode.GetIndex() <= rAnchor.GetCntntAnchor()->nNode.GetIndex() &&
diff --git a/sw/source/filter/ascii/wrtasc.cxx b/sw/source/filter/ascii/wrtasc.cxx
index 015a156..e8cae74 100644
--- a/sw/source/filter/ascii/wrtasc.cxx
+++ b/sw/source/filter/ascii/wrtasc.cxx
@@ -136,7 +136,7 @@ sal_uLong SwASCWriter::WriteStream()
                 {
                     // Print the frame's content.
                     // It is always at position 0!
-                    SwFrmFmt* pFmt = (*pDoc->GetSpzFrmFmts())[ 0 ];
+                    const SwFrmFmt* pFmt = (*pDoc->GetSpzFrmFmts())[ 0 ];
                     const SwNodeIndex* pIdx = pFmt->GetCntnt().GetCntntIdx();
                     if( pIdx )
                     {
diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx
index 3b3bfdf..6be2662 100644
--- a/sw/source/filter/html/swhtml.cxx
+++ b/sw/source/filter/html/swhtml.cxx
@@ -4481,7 +4481,7 @@ bool SwHTMLParser::HasCurrentParaFlys( bool bNoSurroundOnly,
     bool bFound = false;
     for ( sal_uInt16 i=0; i<rFrmFmtTbl.size(); i++ )
     {
-        SwFrmFmt *const pFmt = rFrmFmtTbl[i];
+        const SwFrmFmt *const pFmt = rFrmFmtTbl[i];
         SwFmtAnchor const*const pAnchor = &pFmt->GetAnchor();
         // Ein Rahmen wurde gefunden, wenn
         // - er absatzgebunden ist, und
diff --git a/sw/source/filter/ww8/ww8glsy.cxx b/sw/source/filter/ww8/ww8glsy.cxx
index 5312c89..ff27a37 100644
--- a/sw/source/filter/ww8/ww8glsy.cxx
+++ b/sw/source/filter/ww8/ww8glsy.cxx
@@ -59,7 +59,7 @@ bool WW8Glossary::HasBareGraphicEnd(SwDoc *pDoc,SwNodeIndex &rIdx)
     bool bRet=false;
     for( sal_uInt16 nCnt = pDoc->GetSpzFrmFmts()->size(); nCnt; )
     {
-        SwFrmFmt* pFrmFmt = (*pDoc->GetSpzFrmFmts())[ --nCnt ];
+        const SwFrmFmt* pFrmFmt = (*pDoc->GetSpzFrmFmts())[ --nCnt ];
         if ( RES_FLYFRMFMT != pFrmFmt->Which() &&
             RES_DRAWFRMFMT != pFrmFmt->Which() )
                 continue;
diff --git a/sw/source/uibase/app/docstyle.cxx b/sw/source/uibase/app/docstyle.cxx
index 520bba8..cbccde4 100644
--- a/sw/source/uibase/app/docstyle.cxx
+++ b/sw/source/uibase/app/docstyle.cxx
@@ -2825,7 +2825,7 @@ SfxStyleSheetBase*  SwStyleSheetIterator::First()
         const sal_uInt16 nArrLen = rDoc.GetFrmFmts()->size();
         for( sal_uInt16 i = 0; i < nArrLen; i++ )
         {
-            SwFrmFmt* pFmt = (*rDoc.GetFrmFmts())[ i ];
+            const SwFrmFmt* pFmt = (*rDoc.GetFrmFmts())[ i ];
 
             bool bUsed = bIsSearchUsed && ( bOrganizer || rDoc.IsUsed(*pFmt));
             if( ( !bSearchHidden && pFmt->IsHidden( ) && !bUsed ) || pFmt->IsDefault() || pFmt->IsAuto() )
diff --git a/sw/source/uibase/uiview/view2.cxx b/sw/source/uibase/uiview/view2.cxx
index be0c94b..894e2a0 100644
--- a/sw/source/uibase/uiview/view2.cxx
+++ b/sw/source/uibase/uiview/view2.cxx
@@ -318,7 +318,7 @@ bool SwView::InsertGraphicDlg( SfxRequest& rReq )
     const size_t nArrLen = pDoc->GetFrmFmts()->size();
     for( size_t i = 0; i < nArrLen; ++i )
     {
-        SwFrmFmt* pFmt = (*pDoc->GetFrmFmts())[ i ];
+        const SwFrmFmt* pFmt = (*pDoc->GetFrmFmts())[ i ];
         if(pFmt->IsDefault() || pFmt->IsAuto())
             continue;
         aFormats.push_back(pFmt->GetName());
commit c41346f96f201c4e8b6c15d5b3fe65aa2590e86a
Author: Luboš Luňák <l.lunak at collabora.com>
Date:   Sat Nov 8 18:19:04 2014 +0100

    fix constness of SwFmtsBase::GetFmt()
    
    And covariant return type while I'm at it.
    
    Change-Id: Iab8459e73fa6743eae17094d9826c83b0f53c3f5

diff --git a/sw/inc/docary.hxx b/sw/inc/docary.hxx
index 097a1b2..2f388b1 100644
--- a/sw/inc/docary.hxx
+++ b/sw/inc/docary.hxx
@@ -26,19 +26,13 @@
 #include <o3tl/sorted_vector.hxx>
 
 class SwFieldType;
-class SwFmt;
-class SwFrmFmt;
-class SwCharFmt;
 class SwTOXType;
 class SwUndo;
-class SwSectionFmt;
 class SwNumRule;
 class SwRangeRedline;
 class SwExtraRedline;
 class SwUnoCrsr;
 class SwOLENode;
-class SwTxtFmtColl;
-class SwGrfFmtColl;
 class SwTable;
 class SwTableLine;
 class SwTableBox;
@@ -49,6 +43,10 @@ namespace com { namespace sun { namespace star { namespace i18n {
 
 #include <swtypes.hxx>
 #include <ndarr.hxx>
+#include <charfmt.hxx>
+#include <fmtcol.hxx>
+#include <frmfmt.hxx>
+#include <section.hxx>
 
 /** provides some methods for generic operations on lists that contain
 SwFmt* subclasses. */
@@ -56,7 +54,8 @@ class SwFmtsBase
 {
 public:
     virtual size_t GetFmtCount() const = 0;
-    virtual SwFmt* GetFmt(size_t idx) const = 0;
+    virtual const SwFmt* GetFmt(size_t idx) const = 0;
+    virtual SwFmt* GetFmt(size_t idx) = 0;
     virtual ~SwFmtsBase() = 0;
 };
 
@@ -67,7 +66,8 @@ private:
 
 public:
     virtual size_t GetFmtCount() const SAL_OVERRIDE { return size(); }
-    virtual SwFmt* GetFmt(size_t idx) const SAL_OVERRIDE { return (SwFmt*)operator[](idx); }
+    virtual const SwGrfFmtColl* GetFmt(size_t idx) const SAL_OVERRIDE { return operator[](idx); }
+    virtual SwGrfFmtColl* GetFmt(size_t idx) SAL_OVERRIDE { return operator[](idx); }
     size_t size() const { return mvColls.size(); }
     SwGrfFmtColl *operator[](size_t idx) const { return mvColls[idx]; }
     void push_back(SwGrfFmtColl* pColl) { mvColls.push_back(pColl); }
@@ -85,7 +85,8 @@ class SW_DLLPUBLIC SwFrmFmts : public SwFrmFmts_Base, public SwFmtsBase
 {
 public:
     virtual size_t GetFmtCount() const SAL_OVERRIDE { return size(); }
-    virtual SwFmt* GetFmt(size_t idx) const SAL_OVERRIDE { return (SwFmt*)operator[](idx); }
+    virtual const SwFrmFmt* GetFmt(size_t idx) const SAL_OVERRIDE { return operator[](idx); }
+    virtual SwFrmFmt* GetFmt(size_t idx) SAL_OVERRIDE { return operator[](idx); }
     sal_uInt16 GetPos(const SwFrmFmt* pFmt) const;
     bool Contains(const SwFrmFmt* pFmt) const;
     void dumpAsXml(xmlTextWriterPtr w, const char* pName) const;
@@ -97,7 +98,8 @@ class SwCharFmts : public std::vector<SwCharFmt*>, public SwFmtsBase
 {
 public:
     virtual size_t GetFmtCount() const SAL_OVERRIDE { return size(); }
-    virtual SwFmt* GetFmt(size_t idx) const SAL_OVERRIDE { return (SwFmt*)operator[](idx); }
+    virtual const SwCharFmt* GetFmt(size_t idx) const SAL_OVERRIDE { return operator[](idx); }
+    virtual SwCharFmt* GetFmt(size_t idx) SAL_OVERRIDE { return operator[](idx); }
     sal_uInt16 GetPos(const SwCharFmt* pFmt) const;
     bool Contains(const SwCharFmt* pFmt) const;
     void dumpAsXml(xmlTextWriterPtr w) const;
@@ -109,7 +111,8 @@ class SwTxtFmtColls : public std::vector<SwTxtFmtColl*>, public SwFmtsBase
 {
 public:
     virtual size_t GetFmtCount() const SAL_OVERRIDE { return size(); }
-    virtual SwFmt* GetFmt(size_t idx) const SAL_OVERRIDE { return (SwFmt*)operator[](idx); }
+    virtual const SwTxtFmtColl* GetFmt(size_t idx) const SAL_OVERRIDE { return operator[](idx); }
+    virtual SwTxtFmtColl* GetFmt(size_t idx) SAL_OVERRIDE { return operator[](idx); }
     sal_uInt16 GetPos(const SwTxtFmtColl* pFmt) const;
     void dumpAsXml(xmlTextWriterPtr w) const;
     virtual ~SwTxtFmtColls() {}
@@ -120,7 +123,8 @@ class SW_DLLPUBLIC SwSectionFmts : public std::vector<SwSectionFmt*>, public SwF
 {
 public:
     virtual size_t GetFmtCount() const SAL_OVERRIDE { return size(); }
-    virtual SwFmt* GetFmt(size_t idx) const SAL_OVERRIDE { return (SwFmt*)operator[](idx); }
+    virtual const SwSectionFmt* GetFmt(size_t idx) const SAL_OVERRIDE { return operator[](idx); }
+    virtual SwSectionFmt* GetFmt(size_t idx) SAL_OVERRIDE { return operator[](idx); }
     sal_uInt16 GetPos(const SwSectionFmt* pFmt) const;
     bool Contains(const SwSectionFmt* pFmt) const;
     void dumpAsXml(xmlTextWriterPtr w) const;
diff --git a/sw/inc/node.hxx b/sw/inc/node.hxx
index f3ec9f0..64a7e5c 100644
--- a/sw/inc/node.hxx
+++ b/sw/inc/node.hxx
@@ -33,7 +33,6 @@
 #include <ndtyp.hxx>
 #include <index.hxx>
 #include <fmtcol.hxx>
-#include "docary.hxx"
 
 // forward declarations
 
@@ -73,6 +72,7 @@ class IDocumentFieldsAccess;
 class IDocumentContentOperations;
 class IDocumentListItems;
 class Point;
+typedef std::vector<SwOLENode*> SwOLENodes; // docary.hxx
 
 //UUUU
 namespace drawinglayer { namespace attribute {
diff --git a/sw/source/core/doc/DocumentStylePoolManager.cxx b/sw/source/core/doc/DocumentStylePoolManager.cxx
index abc1149..de9496d 100644
--- a/sw/source/core/doc/DocumentStylePoolManager.cxx
+++ b/sw/source/core/doc/DocumentStylePoolManager.cxx
@@ -2118,7 +2118,7 @@ bool DocumentStylePoolManager::IsPoolTxtCollUsed( sal_uInt16 nId ) const
 /// Check if this AutoCollection is already/still in use
 bool DocumentStylePoolManager::IsPoolFmtUsed( sal_uInt16 nId ) const
 {
-    SwFmt *pNewFmt = 0;
+    const SwFmt *pNewFmt = 0;
     const SwFmtsBase* pArray[ 2 ];
     sal_uInt16 nArrCnt = 1;
     bool bFnd = true;
diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx
index 6a49724..e106ddb 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -28,6 +28,7 @@
 #include <sortedobjs.hxx>
 #include <anchoredobject.hxx>
 #include <cntfrm.hxx>
+#include <docary.hxx>
 
 #include <editeng/unoprnms.hxx>
 #include <editeng/charrotateitem.hxx>
diff --git a/sw/source/core/docnode/nodedump.cxx b/sw/source/core/docnode/nodedump.cxx
index 5ccf26b..812c881 100644
--- a/sw/source/core/docnode/nodedump.cxx
+++ b/sw/source/core/docnode/nodedump.cxx
@@ -674,7 +674,7 @@ void SwFrmFmts::dumpAsXml(xmlTextWriterPtr w, const char* pName) const
         writer.startElement(pName);
         for (size_t i = 0; i < size(); ++i)
         {
-            SwFrmFmt* pFmt = static_cast<SwFrmFmt*>(GetFmt(i));
+            const SwFrmFmt* pFmt = GetFmt(i);
             writer.startElement("swfrmfmt");
             OString aName = OUStringToOString(pFmt->GetName(), RTL_TEXTENCODING_UTF8);
             writer.writeFormatAttribute("ptr", "%p", pFmt);
@@ -709,7 +709,7 @@ void SwCharFmts::dumpAsXml(xmlTextWriterPtr w) const
         writer.startElement("swcharfmts");
         for (size_t i = 0; i < size(); ++i)
         {
-            SwCharFmt* pFmt = static_cast<SwCharFmt*>(GetFmt(i));
+            const SwCharFmt* pFmt = GetFmt(i);
             writer.startElement("swcharfmt");
             OString aName = OUStringToOString(pFmt->GetName(), RTL_TEXTENCODING_UTF8);
             writer.writeFormatAttribute("name", "%s", BAD_CAST(aName.getStr()));
@@ -729,7 +729,7 @@ void SwSectionFmts::dumpAsXml(xmlTextWriterPtr w) const
         writer.startElement("swsectionfmts");
         for (size_t i = 0; i < size(); ++i)
         {
-            SwSectionFmt* pFmt = static_cast<SwSectionFmt*>(GetFmt(i));
+            const SwSectionFmt* pFmt = GetFmt(i);
             writer.startElement("swsectionfmt");
             lcl_dumpSfxItemSet(writer, &pFmt->GetAttrSet());
             writer.endElement();
@@ -746,7 +746,7 @@ void SwTxtFmtColls::dumpAsXml(xmlTextWriterPtr w) const
         writer.startElement("swtxtfmtcolls");
         for (size_t i = 0; i < size(); ++i)
         {
-            SwTxtFmtColl* pColl = static_cast<SwTxtFmtColl*>(GetFmt(i));
+            const SwTxtFmtColl* pColl = GetFmt(i);
             writer.startElement("swtxtfmtcoll");
             OString aName = OUStringToOString(pColl->GetName(), RTL_TEXTENCODING_UTF8);
             writer.writeFormatAttribute("name", "%s", BAD_CAST(aName.getStr()));
diff --git a/sw/source/core/layout/pagechg.cxx b/sw/source/core/layout/pagechg.cxx
index 2ebfe73..aa57f73 100644
--- a/sw/source/core/layout/pagechg.cxx
+++ b/sw/source/core/layout/pagechg.cxx
@@ -32,6 +32,7 @@
 #include <wrtsh.hxx>
 #include <view.hxx>
 #include <edtwin.hxx>
+#include <docary.hxx>
 
 #include "viewimp.hxx"
 #include "pagefrm.hxx"
diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index 628ba09..cbf90520 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -54,6 +54,7 @@
 #include <layouter.hxx>
 #include <switerator.hxx>
 #include <DocumentSettingManager.hxx>
+#include <docary.hxx>
 
 using namespace ::com::sun::star;
 
diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx
index 42ab1e0..c95fd50 100644
--- a/sw/source/filter/ww8/rtfexport.cxx
+++ b/sw/source/filter/ww8/rtfexport.cxx
@@ -48,6 +48,7 @@
 #include <svtools/rtfkeywd.hxx>
 #include <filter/msfilter/rtfutil.hxx>
 #include <unotools/docinfohelper.hxx>
+#include <docary.hxx>
 #if OSL_DEBUG_LEVEL > 1
 #include <iostream>
 #endif
commit bb00a0097900ae054401f7758a915047cfde4065
Author: Luboš Luňák <l.lunak at collabora.com>
Date:   Sat Nov 8 09:41:02 2014 +0100

    do not bother with nice unique names during mailmerge
    
    When using a single document for all the generating MM documents, there can
    be a significant number of sections/etc. , enough to make searching them
    all in order to find a next nice unique name take a noticeable time. Since
    it's very unlikely anybody will ever care about nice names after mailmerge,
    just get some unique name in a fast way.
    
    Change-Id: Id6b8d39a67529984cb93bb369f2c6eab401f1799

diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index 6c877dc..22cef6b 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -52,6 +52,7 @@
 #include <viscrs.hxx>
 #include <edimp.hxx>
 #include <stdio.h>
+#include <tools/datetimeutils.hxx>
 
 using namespace ::boost;
 using namespace ::sw::mark;
@@ -1069,6 +1070,14 @@ namespace sw { namespace mark
     {
         OSL_ENSURE(rName.getLength(),
             "<MarkManager::getUniqueMarkName(..)> - a name should be proposed");
+        if( m_pDoc->IsInMailMerge())
+        {
+            OUString newName = rName + "MailMergeMark"
+                    + OStringToOUString( DateTimeToOString( DateTime( DateTime::SYSTEM )), RTL_TEXTENCODING_ASCII_US )
+                    + OUString::number( m_vAllMarks.size() + 1 );
+            return newName;
+        }
+
         if ( findMark(rName) == getAllMarksEnd() )
         {
             return rName;
@@ -1076,13 +1085,9 @@ namespace sw { namespace mark
         OUStringBuffer sBuf;
         OUString sTmp;
 
-        // try the name "<rName>XXX" (where XXX is a number starting from 1) unless there is
-        // a unused name. Due to performance-reasons (especially in mailmerge-Szenarios) there
-        // is a map m_aMarkBasenameMapUniqueOffset which holds the next possible offset (XXX) for
-        // rName (so there is no need to test for nCnt-values smaller than the offset).
-        sal_Int32 nCnt = 1;
-        MarkBasenameMapUniqueOffset_t::const_iterator aIter = m_aMarkBasenameMapUniqueOffset.find(rName);
-        if(aIter != m_aMarkBasenameMapUniqueOffset.end()) nCnt = aIter->second;
+        // Try the name "<rName>XXX", where XXX is a number. Start the number at the existing count rather than 1
+        // in order to increase the chance that already the first one will not exist.
+        sal_Int32 nCnt = m_vAllMarks.size() + 1;
         while(nCnt < SAL_MAX_INT32)
         {
             sTmp = sBuf.append(rName).append(nCnt).makeStringAndClear();
@@ -1092,8 +1097,6 @@ namespace sw { namespace mark
                 break;
             }
         }
-        m_aMarkBasenameMapUniqueOffset[rName] = nCnt;
-
         return sTmp;
     }
 
diff --git a/sw/source/core/doc/doclay.cxx b/sw/source/core/doc/doclay.cxx
index 288ba1f..8f12b98 100644
--- a/sw/source/core/doc/doclay.cxx
+++ b/sw/source/core/doc/doclay.cxx
@@ -94,6 +94,7 @@
 #include <pagedesc.hxx>
 #include <PostItMgr.hxx>
 #include <comcore.hrc>
+#include <tools/datetimeutils.hxx>
 
 #include <unoframe.hxx>
 
@@ -1287,6 +1288,14 @@ IMPL_STATIC_LINK( SwDoc, BackgroundDone, SvxBrushItem*, EMPTYARG )
 
 static OUString lcl_GetUniqueFlyName( const SwDoc* pDoc, sal_uInt16 nDefStrId )
 {
+    if( pDoc->IsInMailMerge())
+    {
+        OUString newName = "MailMergeFly"
+            + OStringToOUString( DateTimeToOString( DateTime( DateTime::SYSTEM )), RTL_TEXTENCODING_ASCII_US )
+            + OUString::number( pDoc->GetSpzFrmFmts()->size() + 1 );
+        return newName;
+    }
+
     ResId aId( nDefStrId, *pSwResMgr );
     OUString aName( aId );
     sal_Int32 nNmLen = aName.getLength();
diff --git a/sw/source/core/doc/docnum.cxx b/sw/source/core/doc/docnum.cxx
index 1b078e2..4cf931b 100644
--- a/sw/source/core/doc/docnum.cxx
+++ b/sw/source/core/doc/docnum.cxx
@@ -55,6 +55,7 @@
 #include <list.hxx>
 #include <switerator.hxx>
 #include <comphelper/string.hxx>
+#include <tools/datetimeutils.hxx>
 
 #include <cstdlib>
 #include <map>
@@ -2185,6 +2186,16 @@ sal_uInt16 SwDoc::MakeNumRule( const OUString &rName,
 
 OUString SwDoc::GetUniqueNumRuleName( const OUString* pChkStr, bool bAutoNum ) const
 {
+    if( IsInMailMerge())
+    {
+        OUString newName = "MailMergeNumRule"
+            + OStringToOUString( DateTimeToOString( DateTime( DateTime::SYSTEM )), RTL_TEXTENCODING_ASCII_US )
+            + OUString::number( mpNumRuleTbl->size() + 1 );
+        if( pChkStr )
+            newName += *pChkStr;
+        return newName;
+    }
+
     OUString aName;
     if( bAutoNum )
     {
diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx
index 5d89632..d0c1441 100644
--- a/sw/source/core/doc/doctxm.cxx
+++ b/sw/source/core/doc/doctxm.cxx
@@ -71,6 +71,7 @@
 #include <switerator.hxx>
 #include <ToxTextGenerator.hxx>
 #include <ToxTabStopTokenHandler.hxx>
+#include <tools/datetimeutils.hxx>
 
 #include <boost/make_shared.hpp>
 
@@ -609,6 +610,16 @@ const SwTOXType* SwDoc::InsertTOXType( const SwTOXType& rTyp )
 OUString SwDoc::GetUniqueTOXBaseName( const SwTOXType& rType,
                                       const OUString& sChkStr ) const
 {
+    if( IsInMailMerge())
+    {
+        OUString newName = "MailMergeTOX"
+            + OStringToOUString( DateTimeToOString( DateTime( DateTime::SYSTEM )), RTL_TEXTENCODING_ASCII_US )
+            + OUString::number( mpSectionFmtTbl->size() + 1 );
+        if( !sChkStr.isEmpty())
+            newName += sChkStr;
+        return newName;
+    }
+
     bool bUseChkStr = !sChkStr.isEmpty();
     const OUString aName( rType.GetTypeName() );
     const sal_Int32 nNmLen = aName.getLength();
diff --git a/sw/source/core/docnode/ndsect.cxx b/sw/source/core/docnode/ndsect.cxx
index 993cd8e..1178ef9 100644
--- a/sw/source/core/docnode/ndsect.cxx
+++ b/sw/source/core/docnode/ndsect.cxx
@@ -58,6 +58,7 @@
 #include <txtfrm.hxx>
 #include <boost/scoped_ptr.hpp>
 #include <ndsect.hxx>
+#include <tools/datetimeutils.hxx>
 
 // #i21457# - new implementation of local method <lcl_IsInSameTblBox(..)>.
 // Method now determines the previous/next on its own. Thus, it can be controlled,
@@ -1380,6 +1381,16 @@ void SwSectionNode::NodesArrChgd()
 
 OUString SwDoc::GetUniqueSectionName( const OUString* pChkStr ) const
 {
+    if( IsInMailMerge())
+    {
+        OUString newName = "MailMergeSection"
+            + OStringToOUString( DateTimeToOString( DateTime( DateTime::SYSTEM )), RTL_TEXTENCODING_ASCII_US )
+            + OUString::number( mpSectionFmtTbl->size() + 1 );
+        if( pChkStr )
+            newName += *pChkStr;
+        return newName;
+    }
+
     const OUString aName( ResId( STR_REGION_DEFNAME, *pSwResMgr ) );
 
     sal_uInt16 nNum = 0;
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index 568493b..8e5d2fd 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -94,6 +94,7 @@
 #include <switerator.hxx>
 #include <o3tl/numeric.hxx>
 #include <boost/foreach.hpp>
+#include <tools/datetimeutils.hxx>
 
 #ifdef DBG_UTIL
 #define CHECK_TABLE(t) (t).CheckConsistency();
@@ -3861,6 +3862,14 @@ bool SwDoc::GetTableAutoFmt( const SwSelBoxes& rBoxes, SwTableAutoFmt& rGet )
 
 OUString SwDoc::GetUniqueTblName() const
 {
+    if( IsInMailMerge())
+    {
+        OUString newName = "MailMergeTable"
+            + OStringToOUString( DateTimeToOString( DateTime( DateTime::SYSTEM )), RTL_TEXTENCODING_ASCII_US )
+            + OUString::number( mpTblFrmFmtTbl->size() + 1 );
+        return newName;
+    }
+
     ResId aId( STR_TABLE_DEFNAME, *pSwResMgr );
     const OUString aName( aId );
 
diff --git a/sw/source/core/inc/MarkManager.hxx b/sw/source/core/inc/MarkManager.hxx
index ccd614e..52fea0a 100644
--- a/sw/source/core/inc/MarkManager.hxx
+++ b/sw/source/core/inc/MarkManager.hxx
@@ -27,7 +27,6 @@
 
 namespace sw {
     namespace mark {
-    typedef boost::unordered_map<OUString, sal_Int32, OUStringHash> MarkBasenameMapUniqueOffset_t;
 
     class MarkManager
         : private ::boost::noncopyable
@@ -111,7 +110,6 @@ namespace sw {
             container_t m_vFieldmarks;
 
             boost::unordered_set<OUString, OUStringHash> m_aMarkNamesSet;
-            mutable MarkBasenameMapUniqueOffset_t m_aMarkBasenameMapUniqueOffset;
 
             // container for annotation marks
             container_t m_vAnnotationMarks;
commit f1fb3fae21d8e157978da4666eab15364ebb0660
Author: Luboš Luňák <l.lunak at collabora.com>
Date:   Sat Nov 8 09:15:49 2014 +0100

    actually use return value of GetUniqueSectionName() in SwDoc::UpdateSection()
    
    Change-Id: I6d9ae98e900e5e42c5253ee9b2f71bec351b54d1

diff --git a/sw/source/core/docnode/ndsect.cxx b/sw/source/core/docnode/ndsect.cxx
index 7e26598..993cd8e 100644
--- a/sw/source/core/docnode/ndsect.cxx
+++ b/sw/source/core/docnode/ndsect.cxx
@@ -691,7 +691,7 @@ void SwDoc::UpdateSection(sal_uInt16 const nPos, SwSectionData & rNewData,
 
     OUString sSectName( rNewData.GetSectionName() );
     if (sSectName != pSection->GetSectionName())
-        GetUniqueSectionName( &sSectName );
+        sSectName = GetUniqueSectionName( &sSectName );
     else
         sSectName = OUString();
 
commit 6a5dbe73537642b06bcde782118a34b4593d17eb
Author: Luboš Luňák <l.lunak at collabora.com>
Date:   Fri Nov 7 16:14:21 2014 +0100

    do not iterate over all bookmarks in SwTxtNode::Update()
    
    3f9872185e introduced new API for fast finding of marks to a specific text node,
    so use that (code itself based on cb46aaf2d7).
    This makes mailmerge faster (since it can create a huge document, and especially
    with the change to use UNO bookmarks to mark starts of MM documents inside
    the larger single document there can be a large number of marks).
    
    Change-Id: I30ec69acf423e9a62fae5f5492ed8744cb727a56

diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index 5979305..bf15ea2 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -1067,12 +1067,19 @@ void SwTxtNode::Update(
         {
             bool bAtLeastOneBookmarkMoved = false;
             bool bAtLeastOneExpandedBookmarkAtInsertionPosition = false;
-            const IDocumentMarkAccess* const pMarkAccess = getIDocumentMarkAccess();
-            for ( IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->getAllMarksBegin();
-                ppMark != pMarkAccess->getAllMarksEnd();
-                ++ppMark )
-            {
-                const ::sw::mark::IMark* const pMark = ppMark->get();
+            // A text node already knows its marks via its SwIndexes.
+            std::set<const sw::mark::IMark*> aSeenMarks;
+            const SwIndex* next;
+            for (const SwIndex* pIndex = GetFirstIndex(); pIndex; pIndex = next )
+            {
+                next = pIndex->GetNext();
+                const sw::mark::IMark* pMark = pIndex->GetMark();
+                if (!pMark)
+                    continue;
+                // Only handle bookmarks once, if they start and end at this node as well.
+                if (aSeenMarks.find(pMark) != aSeenMarks.end())
+                    continue;
+                aSeenMarks.insert(pMark);
                 const SwPosition* pEnd = &pMark->GetMarkEnd();
                 SwIndex & rEndIdx = const_cast<SwIndex&>(pEnd->nContent);
                 if( this == &pEnd->nNode.GetNode() &&


More information about the Libreoffice-commits mailing list