LCOV - code coverage report
Current view: top level - sw/source/core/undo - unsect.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 53 195 27.2 %
Date: 2012-08-25 Functions: 13 21 61.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 57 358 15.9 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <UndoSection.hxx>
      31                 :            : 
      32                 :            : #include <sfx2/linkmgr.hxx>
      33                 :            : #include <fmtcntnt.hxx>
      34                 :            : #include <doc.hxx>
      35                 :            : #include <docary.hxx>
      36                 :            : #include <swundo.hxx>
      37                 :            : #include <pam.hxx>
      38                 :            : #include <ndtxt.hxx>
      39                 :            : #include <UndoCore.hxx>
      40                 :            : #include <section.hxx>
      41                 :            : #include <rolbck.hxx>
      42                 :            : #include <redline.hxx>
      43                 :            : #include <doctxm.hxx>
      44                 :            : #include <ftnidx.hxx>
      45                 :            : #include <editsh.hxx>
      46                 :            : /// OD 04.10.2002 #102894#
      47                 :            : /// class Calc needed for calculation of the hidden condition of a section.
      48                 :            : #include <calc.hxx>
      49                 :            : 
      50                 :            : 
      51                 :        140 : SfxItemSet* lcl_GetAttrSet( const SwSection& rSect )
      52                 :            : {
      53                 :            :     // save attributes of the format (columns, color, ...)
      54                 :            :     // Cntnt and Protect items are not interesting since they are already
      55                 :            :     // stored in Section, thus delete them.
      56                 :        140 :     SfxItemSet* pAttr = 0;
      57         [ +  - ]:        140 :     if( rSect.GetFmt() )
      58                 :            :     {
      59                 :        140 :         sal_uInt16 nCnt = 1;
      60         [ +  + ]:        140 :         if( rSect.IsProtect() )
      61                 :         54 :             ++nCnt;
      62                 :            : 
      63         [ +  - ]:        140 :         if( nCnt < rSect.GetFmt()->GetAttrSet().Count() )
      64                 :            :         {
      65         [ +  - ]:        140 :             pAttr = new SfxItemSet( rSect.GetFmt()->GetAttrSet() );
      66                 :        140 :             pAttr->ClearItem( RES_PROTECT );
      67                 :        140 :             pAttr->ClearItem( RES_CNTNT );
      68         [ -  + ]:        140 :             if( !pAttr->Count() )
      69         [ #  # ]:          0 :                 delete pAttr, pAttr = 0;
      70                 :            :         }
      71                 :            :     }
      72                 :        140 :     return pAttr;
      73                 :            : }
      74                 :            : 
      75                 :            : 
      76                 :            : ////////////////////////////////////////////////////////////////////////////
      77                 :            : 
      78                 :         44 : SwUndoInsSection::SwUndoInsSection(
      79                 :            :         SwPaM const& rPam, SwSectionData const& rNewData,
      80                 :            :         SfxItemSet const*const pSet, SwTOXBase const*const pTOXBase)
      81                 :            :     : SwUndo( UNDO_INSSECTION ), SwUndRng( rPam )
      82         [ +  - ]:         44 :     , m_pSectionData(new SwSectionData(rNewData))
      83         [ +  - ]:         10 :     , m_pTOXBase( (pTOXBase) ? new SwTOXBase(*pTOXBase) : 0 )
      84         [ #  # ]:          0 :     , m_pAttrSet( (pSet && pSet->Count()) ? new SfxItemSet( *pSet ) : 0 )
      85                 :            :     , m_pHistory(0)
      86                 :            :     , m_pRedlData(0)
      87                 :            :     , m_nSectionNodePos(0)
      88                 :            :     , m_bSplitAtStart(false)
      89                 :            :     , m_bSplitAtEnd(false)
      90 [ +  - ][ +  - ]:         98 :     , m_bUpdateFtn(false)
         [ +  + ][ +  - ]
           [ -  +  #  # ]
                 [ #  # ]
      91                 :            : {
      92                 :         44 :     SwDoc& rDoc = *(SwDoc*)rPam.GetDoc();
      93 [ -  + ][ +  - ]:         44 :     if( rDoc.IsRedlineOn() )
      94                 :            :     {
      95                 :            :         m_pRedlData.reset(new SwRedlineData( nsRedlineType_t::REDLINE_INSERT,
      96 [ #  # ][ #  # ]:          0 :                                         rDoc.GetRedlineAuthor() ));
                 [ #  # ]
      97         [ #  # ]:          0 :         SetRedlineMode( rDoc.GetRedlineMode() );
      98                 :            :     }
      99                 :            : 
     100                 :            : 
     101         [ +  - ]:         44 :     if( !rPam.HasMark() )
     102                 :            :     {
     103                 :         44 :         const SwCntntNode* pCNd = rPam.GetPoint()->nNode.GetNode().GetCntntNode();
     104         [ +  - ]:         58 :         if( pCNd && pCNd->HasSwAttrSet() && (
           [ +  +  -  + ]
         [ #  # ][ +  + ]
                 [ +  - ]
     105                 :         14 :             !rPam.GetPoint()->nContent.GetIndex() ||
     106         [ #  # ]:          0 :             rPam.GetPoint()->nContent.GetIndex() == pCNd->Len() ))
     107                 :            :         {
     108         [ +  - ]:         14 :             SfxItemSet aBrkSet( rDoc.GetAttrPool(), aBreakSetRange );
     109 [ +  - ][ +  - ]:         14 :             aBrkSet.Put( *pCNd->GetpSwAttrSet() );
     110         [ -  + ]:         14 :             if( aBrkSet.Count() )
     111                 :            :             {
     112 [ #  # ][ #  # ]:          0 :                 m_pHistory.reset( new SwHistory );
     113         [ #  # ]:          0 :                 m_pHistory->CopyFmtAttr( aBrkSet, pCNd->GetIndex() );
     114         [ +  - ]:         14 :             }
     115                 :            :         }
     116                 :            :     }
     117                 :         44 : }
     118                 :            : 
     119 [ +  - ][ +  - ]:         44 : SwUndoInsSection::~SwUndoInsSection()
         [ +  - ][ +  - ]
                 [ +  - ]
     120                 :            : {
     121         [ -  + ]:         88 : }
     122                 :            : 
     123                 :          0 : void SwUndoInsSection::UndoImpl(::sw::UndoRedoContext & rContext)
     124                 :            : {
     125                 :          0 :     SwDoc & rDoc = rContext.GetDoc();
     126                 :            : 
     127         [ #  # ]:          0 :     RemoveIdxFromSection( rDoc, m_nSectionNodePos );
     128                 :            : 
     129                 :            :     SwSectionNode *const pNd =
     130 [ #  # ][ #  # ]:          0 :         rDoc.GetNodes()[ m_nSectionNodePos ]->GetSectionNode();
     131                 :            :     OSL_ENSURE( pNd, "wo ist mein SectionNode?" );
     132                 :            : 
     133         [ #  # ]:          0 :     if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
     134         [ #  # ]:          0 :         rDoc.DeleteRedline( *pNd, true, USHRT_MAX );
     135                 :            : 
     136                 :            :     // no selection?
     137         [ #  # ]:          0 :     SwNodeIndex aIdx( *pNd );
     138 [ #  # ][ #  # ]:          0 :     if( ( !nEndNode && STRING_MAXLEN == nEndCntnt ) ||
         [ #  # ][ #  # ]
     139                 :            :         ( nSttNode == nEndNode && nSttCntnt == nEndCntnt ))
     140                 :            :         // delete simply all nodes
     141         [ #  # ]:          0 :         rDoc.GetNodes().Delete( aIdx, pNd->EndOfSectionIndex() -
     142         [ #  # ]:          0 :                                         aIdx.GetIndex() );
     143                 :            :     else
     144                 :            :         // just delete format, rest happens automatically
     145         [ #  # ]:          0 :         rDoc.DelSectionFmt( pNd->GetSection().GetFmt() );
     146                 :            : 
     147                 :            :     // do we need to consolidate?
     148         [ #  # ]:          0 :     if (m_bSplitAtStart)
     149                 :            :     {
     150         [ #  # ]:          0 :         Join( rDoc, nSttNode );
     151                 :            :     }
     152                 :            : 
     153         [ #  # ]:          0 :     if (m_bSplitAtEnd)
     154                 :            :     {
     155         [ #  # ]:          0 :         Join( rDoc, nEndNode );
     156                 :            :     }
     157                 :            : 
     158         [ #  # ]:          0 :     if (m_pHistory.get())
     159                 :            :     {
     160         [ #  # ]:          0 :         m_pHistory->TmpRollback( &rDoc, 0, false );
     161                 :            :     }
     162                 :            : 
     163         [ #  # ]:          0 :     if (m_bUpdateFtn)
     164                 :            :     {
     165         [ #  # ]:          0 :         rDoc.GetFtnIdxs().UpdateFtn( aIdx );
     166                 :            :     }
     167                 :            : 
     168 [ #  # ][ #  # ]:          0 :     AddUndoRedoPaM(rContext);
     169                 :          0 : }
     170                 :            : 
     171                 :          0 : void SwUndoInsSection::RedoImpl(::sw::UndoRedoContext & rContext)
     172                 :            : {
     173                 :          0 :     SwDoc & rDoc = rContext.GetDoc();
     174                 :          0 :     SwPaM & rPam( AddUndoRedoPaM(rContext) );
     175                 :            : 
     176                 :          0 :     const SwTOXBaseSection* pUpdateTOX = 0;
     177         [ #  # ]:          0 :     if (m_pTOXBase.get())
     178                 :            :     {
     179                 :          0 :         pUpdateTOX = rDoc.InsertTableOf( *rPam.GetPoint(),
     180                 :          0 :                                         *m_pTOXBase, m_pAttrSet.get(), true);
     181                 :            :     }
     182                 :            :     else
     183                 :            :     {
     184                 :          0 :         rDoc.InsertSwSection(rPam, *m_pSectionData, 0, m_pAttrSet.get(), true);
     185                 :            :     }
     186                 :            : 
     187         [ #  # ]:          0 :     if (m_pHistory.get())
     188                 :            :     {
     189                 :          0 :         m_pHistory->SetTmpEnd( m_pHistory->Count() );
     190                 :            :     }
     191                 :            : 
     192                 :            :     SwSectionNode *const pSectNd =
     193                 :          0 :         rDoc.GetNodes()[ m_nSectionNodePos ]->GetSectionNode();
     194         [ #  # ]:          0 :     if (m_pRedlData.get() &&
           [ #  #  #  # ]
     195                 :          0 :         IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode()))
     196                 :            :     {
     197         [ #  # ]:          0 :         RedlineMode_t eOld = rDoc.GetRedlineMode();
     198         [ #  # ]:          0 :         rDoc.SetRedlineMode_intern((RedlineMode_t)(eOld & ~nsRedlineMode_t::REDLINE_IGNORE));
     199                 :            : 
     200         [ #  # ]:          0 :         SwPaM aPam( *pSectNd->EndOfSectionNode(), *pSectNd, 1 );
     201 [ #  # ][ #  # ]:          0 :         rDoc.AppendRedline( new SwRedline( *m_pRedlData, aPam ), true);
                 [ #  # ]
     202 [ #  # ][ #  # ]:          0 :         rDoc.SetRedlineMode_intern( eOld );
     203                 :            :     }
     204   [ #  #  #  # ]:          0 :     else if( !( nsRedlineMode_t::REDLINE_IGNORE & GetRedlineMode() ) &&
                 [ #  # ]
     205                 :          0 :             !rDoc.GetRedlineTbl().empty() )
     206                 :            :     {
     207         [ #  # ]:          0 :         SwPaM aPam( *pSectNd->EndOfSectionNode(), *pSectNd, 1 );
     208 [ #  # ][ #  # ]:          0 :         rDoc.SplitRedline( aPam );
     209                 :            :     }
     210                 :            : 
     211         [ #  # ]:          0 :     if( pUpdateTOX )
     212                 :            :     {
     213                 :            :         // initiate formatting
     214                 :          0 :         SwEditShell* pESh = rDoc.GetEditShell();
     215         [ #  # ]:          0 :         if( pESh )
     216                 :          0 :             pESh->CalcLayout();
     217                 :            : 
     218                 :            :         // insert page numbers
     219                 :          0 :         ((SwTOXBaseSection*)pUpdateTOX)->UpdatePageNum();
     220                 :            :     }
     221                 :          0 : }
     222                 :            : 
     223                 :          0 : void SwUndoInsSection::RepeatImpl(::sw::RepeatContext & rContext)
     224                 :            : {
     225                 :          0 :     SwDoc & rDoc = rContext.GetDoc();
     226         [ #  # ]:          0 :     if (m_pTOXBase.get())
     227                 :            :     {
     228                 :          0 :         rDoc.InsertTableOf(*rContext.GetRepeatPaM().GetPoint(),
     229                 :          0 :                                         *m_pTOXBase, m_pAttrSet.get(), true);
     230                 :            :     }
     231                 :            :     else
     232                 :            :     {
     233                 :          0 :         rDoc.InsertSwSection(rContext.GetRepeatPaM(),
     234                 :          0 :             *m_pSectionData, 0, m_pAttrSet.get());
     235                 :            :     }
     236                 :          0 : }
     237                 :            : 
     238                 :          0 : void SwUndoInsSection::Join( SwDoc& rDoc, sal_uLong nNode )
     239                 :            : {
     240 [ #  # ][ #  # ]:          0 :     SwNodeIndex aIdx( rDoc.GetNodes(), nNode );
     241                 :          0 :     SwTxtNode* pTxtNd = aIdx.GetNode().GetTxtNode();
     242                 :            :     OSL_ENSURE( pTxtNd, "Where is my TextNode?" );
     243                 :            : 
     244                 :            :     {
     245                 :            :         RemoveIdxRel( nNode + 1, SwPosition( aIdx,
     246 [ #  # ][ #  # ]:          0 :                             SwIndex( pTxtNd, pTxtNd->GetTxt().Len() )));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     247                 :            :     }
     248         [ #  # ]:          0 :     pTxtNd->JoinNext();
     249                 :            : 
     250         [ #  # ]:          0 :     if (m_pHistory.get())
     251                 :            :     {
     252 [ #  # ][ #  # ]:          0 :         SwIndex aCntIdx( pTxtNd, 0 );
     253 [ #  # ][ #  # ]:          0 :         pTxtNd->RstAttr( aCntIdx, pTxtNd->Len(), 0, 0, true );
                 [ #  # ]
     254         [ #  # ]:          0 :     }
     255                 :          0 : }
     256                 :            : 
     257                 :            : 
     258                 :            : void
     259                 :         10 : SwUndoInsSection::SaveSplitNode(SwTxtNode *const pTxtNd, bool const bAtStart)
     260                 :            : {
     261         [ -  + ]:         10 :     if( pTxtNd->GetpSwpHints() )
     262                 :            :     {
     263         [ #  # ]:          0 :         if (!m_pHistory.get())
     264                 :            :         {
     265         [ #  # ]:          0 :             m_pHistory.reset( new SwHistory );
     266                 :            :         }
     267                 :            :         m_pHistory->CopyAttr( pTxtNd->GetpSwpHints(), pTxtNd->GetIndex(), 0,
     268                 :          0 :                             pTxtNd->GetTxt().Len(), false );
     269                 :            :     }
     270                 :            : 
     271         [ +  - ]:         10 :     if (bAtStart)
     272                 :            :     {
     273                 :         10 :         m_bSplitAtStart = true;
     274                 :            :     }
     275                 :            :     else
     276                 :            :     {
     277                 :          0 :         m_bSplitAtEnd = true;
     278                 :            :     }
     279                 :         10 : }
     280                 :            : 
     281                 :            : 
     282                 :            : ////////////////////////////////////////////////////////////////////////////
     283                 :            : 
     284                 :            : class SwUndoDelSection
     285                 :            :     : public SwUndo
     286                 :            : {
     287                 :            : private:
     288                 :            :     SAL_WNODEPRECATED_DECLARATIONS_PUSH
     289                 :            :     ::std::auto_ptr<SwSectionData> const m_pSectionData; /// section not TOX
     290                 :            :     ::std::auto_ptr<SwTOXBase> const m_pTOXBase; /// set iff section is TOX
     291                 :            :     ::std::auto_ptr<SfxItemSet> const m_pAttrSet;
     292                 :            :     SAL_WNODEPRECATED_DECLARATIONS_POP
     293                 :            :     ::boost::shared_ptr< ::sfx2::MetadatableUndo > const m_pMetadataUndo;
     294                 :            :     sal_uLong const m_nStartNode;
     295                 :            :     sal_uLong const m_nEndNode;
     296                 :            : 
     297                 :            : public:
     298                 :            :     SwUndoDelSection(
     299                 :            :         SwSectionFmt const&, SwSection const&, SwNodeIndex const*const);
     300                 :            : 
     301                 :            :     virtual ~SwUndoDelSection();
     302                 :            : 
     303                 :            :     virtual void UndoImpl( ::sw::UndoRedoContext & );
     304                 :            :     virtual void RedoImpl( ::sw::UndoRedoContext & );
     305                 :            : };
     306                 :            : 
     307                 :          6 : SW_DLLPRIVATE SwUndo * MakeUndoDelSection(SwSectionFmt const& rFormat)
     308                 :            : {
     309                 :            :     return new SwUndoDelSection(rFormat, *rFormat.GetSection(),
     310         [ +  - ]:          6 :                 rFormat.GetCntnt().GetCntntIdx());
     311                 :            : }
     312                 :            : 
     313                 :          6 : SwUndoDelSection::SwUndoDelSection(
     314                 :            :             SwSectionFmt const& rSectionFmt, SwSection const& rSection,
     315                 :            :             SwNodeIndex const*const pIndex)
     316                 :            :     : SwUndo( UNDO_DELSECTION )
     317         [ +  - ]:          6 :     , m_pSectionData( new SwSectionData(rSection) )
     318 [ +  - ][ +  - ]:          6 :     , m_pTOXBase( rSection.ISA( SwTOXBaseSection )
     319         [ #  # ]:          0 :             ? new SwTOXBase(static_cast<SwTOXBaseSection const&>(rSection))
     320                 :            :             : 0 )
     321                 :            :     , m_pAttrSet( ::lcl_GetAttrSet(rSection) )
     322                 :            :     , m_pMetadataUndo( rSectionFmt.CreateUndo() )
     323                 :          6 :     , m_nStartNode( pIndex->GetIndex() )
     324 [ +  - ][ -  + ]:         24 :     , m_nEndNode( pIndex->GetNode().EndOfSectionIndex() )
         [ #  # ][ +  - ]
                 [ +  - ]
     325                 :            : {
     326                 :          6 : }
     327                 :            : 
     328 [ +  - ][ +  - ]:          6 : SwUndoDelSection::~SwUndoDelSection()
         [ +  - ][ +  - ]
     329                 :            : {
     330         [ -  + ]:         12 : }
     331                 :            : 
     332                 :          0 : void SwUndoDelSection::UndoImpl(::sw::UndoRedoContext & rContext)
     333                 :            : {
     334                 :          0 :     SwDoc & rDoc = rContext.GetDoc();
     335                 :            : 
     336         [ #  # ]:          0 :     if (m_pTOXBase.get())
     337                 :            :     {
     338                 :          0 :         rDoc.InsertTableOf(m_nStartNode, m_nEndNode-2, *m_pTOXBase,
     339                 :          0 :                 m_pAttrSet.get());
     340                 :            :     }
     341                 :            :     else
     342                 :            :     {
     343 [ #  # ][ #  # ]:          0 :         SwNodeIndex aStt( rDoc.GetNodes(), m_nStartNode );
     344 [ #  # ][ #  # ]:          0 :         SwNodeIndex aEnd( rDoc.GetNodes(), m_nEndNode-2 );
     345         [ #  # ]:          0 :         SwSectionFmt* pFmt = rDoc.MakeSectionFmt( 0 );
     346         [ #  # ]:          0 :         if (m_pAttrSet.get())
     347                 :            :         {
     348         [ #  # ]:          0 :             pFmt->SetFmtAttr( *m_pAttrSet );
     349                 :            :         }
     350                 :            : 
     351                 :            :         /// OD 04.10.2002 #102894#
     352                 :            :         /// remember inserted section node for further calculations
     353         [ #  # ]:          0 :         SwSectionNode* pInsertedSectNd = rDoc.GetNodes().InsertTextSection(
     354         [ #  # ]:          0 :                 aStt, *pFmt, *m_pSectionData, 0, & aEnd);
     355                 :            : 
     356 [ #  # ][ #  # ]:          0 :         if( SFX_ITEM_SET == pFmt->GetItemState( RES_FTN_AT_TXTEND ) ||
         [ #  # ][ #  # ]
     357         [ #  # ]:          0 :             SFX_ITEM_SET == pFmt->GetItemState( RES_END_AT_TXTEND ))
     358                 :            :         {
     359         [ #  # ]:          0 :             rDoc.GetFtnIdxs().UpdateFtn( aStt );
     360                 :            :         }
     361                 :            : 
     362                 :            :         /// OD 04.10.2002 #102894#
     363                 :            :         /// consider that section is hidden by condition.
     364                 :            :         /// If section is hidden by condition,
     365                 :            :         /// recalculate condition and update hidden condition flag.
     366                 :            :         /// Recalculation is necessary, because fields, on which the hide
     367                 :            :         /// condition depends, can be changed - fields changes aren't undoable.
     368                 :            :         /// NOTE: setting hidden condition flag also creates/deletes corresponding
     369                 :            :         ///     frames, if the hidden condition flag changes.
     370                 :          0 :         SwSection& aInsertedSect = pInsertedSectNd->GetSection();
     371         [ #  # ]:          0 :         if ( aInsertedSect.IsHidden() &&
           [ #  #  #  # ]
     372                 :          0 :              aInsertedSect.GetCondition().Len() > 0 )
     373                 :            :         {
     374         [ #  # ]:          0 :             SwCalc aCalc( rDoc );
     375         [ #  # ]:          0 :             rDoc.FldsToCalc(aCalc, pInsertedSectNd->GetIndex(), USHRT_MAX);
     376                 :            :             bool bRecalcCondHidden =
     377 [ #  # ][ #  # ]:          0 :                     aCalc.Calculate( aInsertedSect.GetCondition() ).GetBool() ? true : false;
                 [ #  # ]
     378 [ #  # ][ #  # ]:          0 :             aInsertedSect.SetCondHidden( bRecalcCondHidden );
     379                 :            :         }
     380                 :            : 
     381 [ #  # ][ #  # ]:          0 :         pFmt->RestoreMetadata(m_pMetadataUndo);
                 [ #  # ]
     382                 :            :     }
     383                 :          0 : }
     384                 :            : 
     385                 :          0 : void SwUndoDelSection::RedoImpl(::sw::UndoRedoContext & rContext)
     386                 :            : {
     387                 :          0 :     SwDoc & rDoc = rContext.GetDoc();
     388                 :            : 
     389                 :            :     SwSectionNode *const pNd =
     390                 :          0 :         rDoc.GetNodes()[ m_nStartNode ]->GetSectionNode();
     391                 :            :     OSL_ENSURE( pNd, "Where is my SectionNode?" );
     392                 :            :     // just delete format, rest happens automatically
     393                 :          0 :     rDoc.DelSectionFmt( pNd->GetSection().GetFmt() );
     394                 :          0 : }
     395                 :            : 
     396                 :            : 
     397                 :            : ////////////////////////////////////////////////////////////////////////////
     398                 :            : 
     399                 :            : class SwUndoUpdateSection
     400                 :            :     : public SwUndo
     401                 :            : {
     402                 :            : private:
     403                 :            :     SAL_WNODEPRECATED_DECLARATIONS_PUSH
     404                 :            :     ::std::auto_ptr<SwSectionData> m_pSectionData;
     405                 :            :     ::std::auto_ptr<SfxItemSet> m_pAttrSet;
     406                 :            :     SAL_WNODEPRECATED_DECLARATIONS_POP
     407                 :            :     sal_uLong const m_nStartNode;
     408                 :            :     bool const m_bOnlyAttrChanged;
     409                 :            : 
     410                 :            : public:
     411                 :            :     SwUndoUpdateSection(
     412                 :            :         SwSection const&, SwNodeIndex const*const, bool const bOnlyAttr);
     413                 :            : 
     414                 :            :     virtual ~SwUndoUpdateSection();
     415                 :            : 
     416                 :            :     virtual void UndoImpl( ::sw::UndoRedoContext & );
     417                 :            :     virtual void RedoImpl( ::sw::UndoRedoContext & );
     418                 :            : };
     419                 :            : 
     420                 :            : SW_DLLPRIVATE SwUndo *
     421                 :        134 : MakeUndoUpdateSection(SwSectionFmt const& rFormat, bool const bOnlyAttr)
     422                 :            : {
     423                 :            :     return new SwUndoUpdateSection(*rFormat.GetSection(),
     424         [ +  - ]:        134 :                 rFormat.GetCntnt().GetCntntIdx(), bOnlyAttr);
     425                 :            : }
     426                 :            : 
     427                 :        134 : SwUndoUpdateSection::SwUndoUpdateSection(
     428                 :            :         SwSection const& rSection, SwNodeIndex const*const pIndex,
     429                 :            :         bool const bOnlyAttr)
     430                 :            :     : SwUndo( UNDO_CHGSECTION )
     431         [ +  - ]:        134 :     , m_pSectionData( new SwSectionData(rSection) )
     432                 :            :     , m_pAttrSet( ::lcl_GetAttrSet(rSection) )
     433                 :        134 :     , m_nStartNode( pIndex->GetIndex() )
     434 [ +  - ][ +  - ]:        268 :     , m_bOnlyAttrChanged( bOnlyAttr )
     435                 :            : {
     436                 :        134 : }
     437                 :            : 
     438 [ +  - ][ +  - ]:        134 : SwUndoUpdateSection::~SwUndoUpdateSection()
     439                 :            : {
     440         [ -  + ]:        268 : }
     441                 :            : 
     442                 :          0 : void SwUndoUpdateSection::UndoImpl(::sw::UndoRedoContext & rContext)
     443                 :            : {
     444                 :          0 :     SwDoc & rDoc = rContext.GetDoc();
     445                 :            :     SwSectionNode *const pSectNd =
     446                 :          0 :         rDoc.GetNodes()[ m_nStartNode ]->GetSectionNode();
     447                 :            :     OSL_ENSURE( pSectNd, "Where is my SectionNode?" );
     448                 :            : 
     449                 :          0 :     SwSection& rNdSect = pSectNd->GetSection();
     450                 :          0 :     SwFmt* pFmt = rNdSect.GetFmt();
     451                 :            : 
     452                 :          0 :     SfxItemSet* pCur = ::lcl_GetAttrSet( rNdSect );
     453         [ #  # ]:          0 :     if (m_pAttrSet.get())
     454                 :            :     {
     455                 :            :         // The Content and Protect items must persist
     456                 :            :         const SfxPoolItem* pItem;
     457 [ #  # ][ #  # ]:          0 :         m_pAttrSet->Put( pFmt->GetFmtAttr( RES_CNTNT ));
     458 [ #  # ][ #  # ]:          0 :         if( SFX_ITEM_SET == pFmt->GetItemState( RES_PROTECT, sal_True, &pItem ))
     459                 :            :         {
     460         [ #  # ]:          0 :             m_pAttrSet->Put( *pItem );
     461                 :            :         }
     462         [ #  # ]:          0 :         pFmt->DelDiffs( *m_pAttrSet );
     463         [ #  # ]:          0 :         m_pAttrSet->ClearItem( RES_CNTNT );
     464         [ #  # ]:          0 :         pFmt->SetFmtAttr( *m_pAttrSet );
     465                 :            :     }
     466                 :            :     else
     467                 :            :     {
     468                 :            :         // than the old ones need to be deleted
     469                 :          0 :         pFmt->ResetFmtAttr( RES_FRMATR_BEGIN, RES_BREAK );
     470                 :          0 :         pFmt->ResetFmtAttr( RES_HEADER, RES_OPAQUE );
     471                 :          0 :         pFmt->ResetFmtAttr( RES_SURROUND, RES_FRMATR_END-1 );
     472                 :            :     }
     473                 :          0 :     m_pAttrSet.reset(pCur);
     474                 :            : 
     475         [ #  # ]:          0 :     if (!m_bOnlyAttrChanged)
     476                 :            :     {
     477                 :            :         const bool bUpdate =
     478                 :          0 :                (!rNdSect.IsLinkType() && m_pSectionData->IsLinkType())
     479                 :          0 :             || (    m_pSectionData->GetLinkFileName().Len()
     480                 :          0 :                 &&  (m_pSectionData->GetLinkFileName() !=
     481 [ #  # ][ #  #  :          0 :                         rNdSect.GetLinkFileName()));
             #  #  #  # ]
     482                 :            : 
     483                 :            :         // swap stored section data with live section data
     484         [ #  # ]:          0 :         SwSectionData *const pOld( new SwSectionData(rNdSect) );
     485                 :          0 :         rNdSect.SetSectionData(*m_pSectionData);
     486                 :          0 :         m_pSectionData.reset(pOld);
     487                 :            : 
     488         [ #  # ]:          0 :         if( bUpdate )
     489                 :          0 :             rNdSect.CreateLink( CREATE_UPDATE );
     490 [ #  # ][ #  # ]:          0 :         else if( CONTENT_SECTION == rNdSect.GetType() && rNdSect.IsConnected() )
                 [ #  # ]
     491                 :            :         {
     492                 :          0 :             rNdSect.Disconnect();
     493                 :          0 :             rDoc.GetLinkManager().Remove( &rNdSect.GetBaseLink() );
     494                 :            :         }
     495                 :            :     }
     496                 :          0 : }
     497                 :            : 
     498                 :          0 : void SwUndoUpdateSection::RedoImpl(::sw::UndoRedoContext & rContext)
     499                 :            : {
     500                 :          0 :     UndoImpl(rContext);
     501                 :          0 : }
     502                 :            : 
     503                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10