LCOV - code coverage report
Current view: top level - sw/source/core/undo - untblk.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 48 171 28.1 %
Date: 2015-06-13 12:38:46 Functions: 7 11 63.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <hintids.hxx>
      21             : #include <fmtanchr.hxx>
      22             : #include <frmfmt.hxx>
      23             : #include <doc.hxx>
      24             : #include <IDocumentUndoRedo.hxx>
      25             : #include <IDocumentRedlineAccess.hxx>
      26             : #include <IShellCursorSupplier.hxx>
      27             : #include <docary.hxx>
      28             : #include <swundo.hxx>
      29             : #include <pam.hxx>
      30             : #include <ndtxt.hxx>
      31             : #include <UndoCore.hxx>
      32             : #include <rolbck.hxx>
      33             : #include <redline.hxx>
      34             : 
      35          51 : SwUndoInserts::SwUndoInserts( SwUndoId nUndoId, const SwPaM& rPam )
      36             :     : SwUndo( nUndoId ), SwUndRng( rPam ),
      37             :     pTextFormatColl( 0 ), pLastNdColl(0), pFrameFormats( 0 ), pRedlData( 0 ),
      38          51 :     bSttWasTextNd( true ), nNdDiff( 0 ), nSetPos( 0 )
      39             : {
      40          51 :     pHistory = new SwHistory;
      41          51 :     SwDoc* pDoc = rPam.GetDoc();
      42             : 
      43          51 :     SwTextNode* pTextNd = rPam.GetPoint()->nNode.GetNode().GetTextNode();
      44          51 :     if( pTextNd )
      45             :     {
      46           7 :         pTextFormatColl = pTextNd->GetTextColl();
      47             :         pHistory->CopyAttr( pTextNd->GetpSwpHints(), nSttNode,
      48           7 :                             0, pTextNd->GetText().getLength(), false );
      49           7 :         if( pTextNd->HasSwAttrSet() )
      50           4 :             pHistory->CopyFormatAttr( *pTextNd->GetpSwAttrSet(), nSttNode );
      51             : 
      52           7 :         if( !nSttContent )    // than take the Flys along
      53             :         {
      54           3 :             const size_t nArrLen = pDoc->GetSpzFrameFormats()->size();
      55           3 :             for( size_t n = 0; n < nArrLen; ++n )
      56             :             {
      57           0 :                 SwFrameFormat* pFormat = (*pDoc->GetSpzFrameFormats())[n];
      58           0 :                 SwFormatAnchor const*const  pAnchor = &pFormat->GetAnchor();
      59           0 :                 const SwPosition* pAPos = pAnchor->GetContentAnchor();
      60           0 :                 if (pAPos &&
      61           0 :                     (pAnchor->GetAnchorId() == FLY_AT_PARA) &&
      62           0 :                      nSttNode == pAPos->nNode.GetIndex() )
      63             :                 {
      64           0 :                     if( !pFrameFormats )
      65           0 :                         pFrameFormats = new std::vector<SwFrameFormat*>;
      66           0 :                     pFrameFormats->push_back( pFormat );
      67             :                 }
      68             :             }
      69             :         }
      70             :     }
      71             :     // consider Redline
      72          51 :     if( pDoc->getIDocumentRedlineAccess().IsRedlineOn() )
      73             :     {
      74           0 :         pRedlData = new SwRedlineData( nsRedlineType_t::REDLINE_INSERT, pDoc->getIDocumentRedlineAccess().GetRedlineAuthor() );
      75           0 :         SetRedlineMode( pDoc->getIDocumentRedlineAccess().GetRedlineMode() );
      76             :     }
      77          51 : }
      78             : 
      79             : // set destination after reading input
      80          51 : void SwUndoInserts::SetInsertRange( const SwPaM& rPam, bool bScanFlys,
      81             :                                     bool bSttIsTextNd )
      82             : {
      83          51 :     const SwPosition* pTmpPos = rPam.End();
      84          51 :     nEndNode = pTmpPos->nNode.GetIndex();
      85          51 :     nEndContent = pTmpPos->nContent.GetIndex();
      86          51 :     if( rPam.HasMark() )
      87             :     {
      88          51 :         if( pTmpPos == rPam.GetPoint() )
      89          40 :             pTmpPos = rPam.GetMark();
      90             :         else
      91          11 :             pTmpPos = rPam.GetPoint();
      92             : 
      93          51 :         nSttNode = pTmpPos->nNode.GetIndex();
      94          51 :         nSttContent = pTmpPos->nContent.GetIndex();
      95             : 
      96          51 :         if( !bSttIsTextNd )      // if a table selection is added ...
      97             :         {
      98           0 :             ++nSttNode;         // ... than the CopyPam is not fully correct
      99           0 :             bSttWasTextNd = false;
     100             :         }
     101             :     }
     102             : 
     103          51 :     if( bScanFlys && !nSttContent )
     104             :     {
     105             :         // than collect all new Flys
     106          47 :         SwDoc* pDoc = rPam.GetDoc();
     107          47 :         const size_t nArrLen = pDoc->GetSpzFrameFormats()->size();
     108          59 :         for( size_t n = 0; n < nArrLen; ++n )
     109             :         {
     110          12 :             SwFrameFormat* pFormat = (*pDoc->GetSpzFrameFormats())[n];
     111          12 :             SwFormatAnchor const*const pAnchor = &pFormat->GetAnchor();
     112          12 :             SwPosition const*const pAPos = pAnchor->GetContentAnchor();
     113          12 :             if (pAPos &&
     114          12 :                 (pAnchor->GetAnchorId() == FLY_AT_PARA) &&
     115           0 :                 nSttNode == pAPos->nNode.GetIndex() )
     116             :             {
     117           0 :                 std::vector<SwFrameFormat*>::iterator it;
     118           0 :                 if( !pFrameFormats ||
     119           0 :                     pFrameFormats->end() == ( it = std::find( pFrameFormats->begin(), pFrameFormats->end(), pFormat ) ) )
     120             :                 {
     121             :                     ::boost::shared_ptr<SwUndoInsLayFormat> const pFlyUndo(
     122           0 :                         new SwUndoInsLayFormat(pFormat, 0, 0));
     123           0 :                     m_FlyUndos.push_back(pFlyUndo);
     124             :                 }
     125             :                 else
     126           0 :                     pFrameFormats->erase( it );
     127             :             }
     128             :         }
     129          47 :         delete pFrameFormats, pFrameFormats = 0;
     130             :     }
     131          51 : }
     132             : 
     133         102 : SwUndoInserts::~SwUndoInserts()
     134             : {
     135          51 :     if (m_pUndoNodeIndex) // delete also the section from UndoNodes array
     136             :     {
     137             :         // Insert saves content in IconSection
     138           0 :         SwNodes& rUNds = m_pUndoNodeIndex->GetNodes();
     139           0 :         rUNds.Delete(*m_pUndoNodeIndex,
     140           0 :             rUNds.GetEndOfExtras().GetIndex() - m_pUndoNodeIndex->GetIndex());
     141           0 :         m_pUndoNodeIndex.reset();
     142             :     }
     143          51 :     delete pFrameFormats;
     144          51 :     delete pRedlData;
     145          51 : }
     146             : 
     147           0 : void SwUndoInserts::UndoImpl(::sw::UndoRedoContext & rContext)
     148             : {
     149           0 :     SwDoc *const pDoc = & rContext.GetDoc();
     150           0 :     SwPaM *const pPam = & AddUndoRedoPaM(rContext);
     151             : 
     152           0 :     if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
     153           0 :         pDoc->getIDocumentRedlineAccess().DeleteRedline( *pPam, true, USHRT_MAX );
     154             : 
     155             :     // if Point and Mark are different text nodes so a JoinNext has to be done
     156           0 :     bool bJoinNext = nSttNode != nEndNode &&
     157           0 :                 pPam->GetMark()->nNode.GetNode().GetTextNode() &&
     158           0 :                 pPam->GetPoint()->nNode.GetNode().GetTextNode();
     159             : 
     160             :     // Is there any content? (loading from template does not have content)
     161           0 :     if( nSttNode != nEndNode || nSttContent != nEndContent )
     162             :     {
     163           0 :         if( nSttNode != nEndNode )
     164             :         {
     165           0 :             SwTextNode* pTextNd = pDoc->GetNodes()[ nEndNode ]->GetTextNode();
     166           0 :             if (pTextNd && pTextNd->GetText().getLength() == nEndContent)
     167           0 :                 pLastNdColl = pTextNd->GetTextColl();
     168             :         }
     169             : 
     170           0 :         RemoveIdxFromRange( *pPam, false );
     171           0 :         SetPaM(*pPam);
     172             : 
     173             :         // are there Footnotes or ContentFlyFrames in text?
     174           0 :         nSetPos = pHistory->Count();
     175           0 :         nNdDiff = pPam->GetMark()->nNode.GetIndex();
     176           0 :         DelContentIndex( *pPam->GetMark(), *pPam->GetPoint() );
     177           0 :         nNdDiff -= pPam->GetMark()->nNode.GetIndex();
     178             : 
     179           0 :         if( *pPam->GetPoint() != *pPam->GetMark() )
     180             :         {
     181             :             m_pUndoNodeIndex.reset(
     182           0 :                     new SwNodeIndex(pDoc->GetNodes().GetEndOfContent()));
     183           0 :             MoveToUndoNds(*pPam, m_pUndoNodeIndex.get());
     184             : 
     185           0 :             if( !bSttWasTextNd )
     186           0 :                 pPam->Move( fnMoveBackward, fnGoContent );
     187             :         }
     188             :     }
     189             : 
     190           0 :     if (m_FlyUndos.size())
     191             :     {
     192           0 :         sal_uLong nTmp = pPam->GetPoint()->nNode.GetIndex();
     193           0 :         for (size_t n = m_FlyUndos.size(); 0 < n; --n)
     194             :         {
     195           0 :             m_FlyUndos[ n-1 ]->UndoImpl(rContext);
     196             :         }
     197           0 :         nNdDiff += nTmp - pPam->GetPoint()->nNode.GetIndex();
     198             :     }
     199             : 
     200           0 :     SwNodeIndex& rIdx = pPam->GetPoint()->nNode;
     201           0 :     SwTextNode* pTextNode = rIdx.GetNode().GetTextNode();
     202           0 :     if( pTextNode )
     203             :     {
     204           0 :         if( !pTextFormatColl ) // if 0 than it's no TextNode -> delete
     205             :         {
     206           0 :             SwNodeIndex aDelIdx( rIdx );
     207           0 :             ++rIdx;
     208           0 :             SwContentNode* pCNd = rIdx.GetNode().GetContentNode();
     209           0 :             pPam->GetPoint()->nContent.Assign( pCNd, pCNd ? pCNd->Len() : 0 );
     210           0 :             pPam->SetMark();
     211           0 :             pPam->DeleteMark();
     212             : 
     213           0 :             RemoveIdxRel( aDelIdx.GetIndex(), *pPam->GetPoint() );
     214             : 
     215           0 :             pDoc->GetNodes().Delete( aDelIdx, 1 );
     216             :         }
     217             :         else
     218             :         {
     219           0 :             if( bJoinNext && pTextNode->CanJoinNext())
     220             :             {
     221             :                 {
     222           0 :                     RemoveIdxRel( rIdx.GetIndex()+1, SwPosition( rIdx,
     223           0 :                         SwIndex( pTextNode, pTextNode->GetText().getLength() )));
     224             :                 }
     225           0 :                 pTextNode->JoinNext();
     226             :             }
     227             :             // reset all text attributes in the paragraph!
     228           0 :             pTextNode->RstTextAttr( SwIndex(pTextNode, 0), pTextNode->Len(), 0, 0, true );
     229             : 
     230           0 :             pTextNode->ResetAllAttr();
     231             : 
     232           0 :             if( pDoc->GetTextFormatColls()->Contains( pTextFormatColl ))
     233           0 :                 pTextFormatColl = static_cast<SwTextFormatColl*>(pTextNode->ChgFormatColl( pTextFormatColl )) ;
     234             : 
     235           0 :             pHistory->SetTmpEnd( nSetPos );
     236           0 :             pHistory->TmpRollback( pDoc, 0, false );
     237             :         }
     238             :     }
     239           0 : }
     240             : 
     241           0 : void SwUndoInserts::RedoImpl(::sw::UndoRedoContext & rContext)
     242             : {
     243             :     // position cursor onto REDO section
     244           0 :     SwPaM *const pPam(& rContext.GetCursorSupplier().CreateNewShellCursor());
     245           0 :     SwDoc* pDoc = pPam->GetDoc();
     246           0 :     pPam->DeleteMark();
     247           0 :     pPam->GetPoint()->nNode = nSttNode - nNdDiff;
     248           0 :     SwContentNode* pCNd = pPam->GetContentNode();
     249           0 :     pPam->GetPoint()->nContent.Assign( pCNd, nSttContent );
     250             : 
     251           0 :     SwTextFormatColl* pSavTextFormatColl = pTextFormatColl;
     252           0 :     if( pTextFormatColl && pCNd && pCNd->IsTextNode() )
     253           0 :         pSavTextFormatColl = static_cast<SwTextNode*>(pCNd)->GetTextColl();
     254             : 
     255           0 :     pHistory->SetTmpEnd( nSetPos );
     256             : 
     257             :     // retrieve start position for rollback
     258           0 :     if( ( nSttNode != nEndNode || nSttContent != nEndContent ) && m_pUndoNodeIndex)
     259             :     {
     260           0 :         const bool bMvBkwrd = MovePtBackward( *pPam );
     261             : 
     262             :         // re-insert content again (first detach m_pUndoNodeIndex!)
     263           0 :         sal_uLong const nMvNd = m_pUndoNodeIndex->GetIndex();
     264           0 :         m_pUndoNodeIndex.reset();
     265           0 :         MoveFromUndoNds(*pDoc, nMvNd, *pPam->GetMark());
     266           0 :         if( bSttWasTextNd )
     267           0 :             MovePtForward( *pPam, bMvBkwrd );
     268           0 :         pPam->Exchange();
     269             :     }
     270             : 
     271           0 :     if( pDoc->GetTextFormatColls()->Contains( pTextFormatColl ))
     272             :     {
     273           0 :         SwTextNode* pTextNd = pPam->GetMark()->nNode.GetNode().GetTextNode();
     274           0 :         if( pTextNd )
     275           0 :             pTextNd->ChgFormatColl( pTextFormatColl );
     276             :     }
     277           0 :     pTextFormatColl = pSavTextFormatColl;
     278             : 
     279           0 :     if( pLastNdColl && pDoc->GetTextFormatColls()->Contains( pLastNdColl ) &&
     280           0 :         pPam->GetPoint()->nNode != pPam->GetMark()->nNode )
     281             :     {
     282           0 :         SwTextNode* pTextNd = pPam->GetPoint()->nNode.GetNode().GetTextNode();
     283           0 :         if( pTextNd )
     284           0 :             pTextNd->ChgFormatColl( pLastNdColl );
     285             :     }
     286             : 
     287           0 :     for (size_t n = m_FlyUndos.size(); 0 < n; --n)
     288             :     {
     289           0 :         m_FlyUndos[ n-1 ]->RedoImpl(rContext);
     290             :     }
     291             : 
     292           0 :     pHistory->Rollback( pDoc, nSetPos );
     293             : 
     294           0 :     if( pRedlData && IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
     295             :     {
     296           0 :         RedlineMode_t eOld = pDoc->getIDocumentRedlineAccess().GetRedlineMode();
     297           0 :         pDoc->getIDocumentRedlineAccess().SetRedlineMode_intern((RedlineMode_t)( eOld & ~nsRedlineMode_t::REDLINE_IGNORE ));
     298           0 :         pDoc->getIDocumentRedlineAccess().AppendRedline( new SwRangeRedline( *pRedlData, *pPam ), true);
     299           0 :         pDoc->getIDocumentRedlineAccess().SetRedlineMode_intern( eOld );
     300             :     }
     301           0 :     else if( !( nsRedlineMode_t::REDLINE_IGNORE & GetRedlineMode() ) &&
     302           0 :             !pDoc->getIDocumentRedlineAccess().GetRedlineTable().empty() )
     303           0 :         pDoc->getIDocumentRedlineAccess().SplitRedline( *pPam );
     304           0 : }
     305             : 
     306           0 : void SwUndoInserts::RepeatImpl(::sw::RepeatContext & rContext)
     307             : {
     308           0 :     SwPaM aPam( rContext.GetDoc().GetNodes().GetEndOfContent() );
     309           0 :     SetPaM( aPam );
     310           0 :     SwPaM & rRepeatPaM( rContext.GetRepeatPaM() );
     311           0 :     aPam.GetDoc()->getIDocumentContentOperations().CopyRange( aPam, *rRepeatPaM.GetPoint(), /*bCopyAll=*/false, /*bCheckPos=*/true );
     312           0 : }
     313             : 
     314           1 : SwUndoInsDoc::SwUndoInsDoc( const SwPaM& rPam )
     315           1 :     : SwUndoInserts( UNDO_INSDOKUMENT, rPam )
     316             : {
     317           1 : }
     318             : 
     319          50 : SwUndoCpyDoc::SwUndoCpyDoc( const SwPaM& rPam )
     320          50 :     : SwUndoInserts( UNDO_COPY, rPam )
     321             : {
     322         227 : }
     323             : 
     324             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11