LCOV - code coverage report
Current view: top level - sw/source/core/undo - untblk.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 171 0.0 %
Date: 2014-04-14 Functions: 0 9 0.0 %
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 <IShellCursorSupplier.hxx>
      26             : #include <docary.hxx>
      27             : #include <swundo.hxx>
      28             : #include <pam.hxx>
      29             : #include <ndtxt.hxx>
      30             : #include <UndoCore.hxx>
      31             : #include <rolbck.hxx>
      32             : #include <redline.hxx>
      33             : 
      34           0 : SwUndoInserts::SwUndoInserts( SwUndoId nUndoId, const SwPaM& rPam )
      35             :     : SwUndo( nUndoId ), SwUndRng( rPam ),
      36             :     pTxtFmtColl( 0 ), pLastNdColl(0), pFrmFmts( 0 ), pRedlData( 0 ),
      37           0 :     bSttWasTxtNd( true ), nNdDiff( 0 ), nSetPos( 0 )
      38             : {
      39           0 :     pHistory = new SwHistory;
      40           0 :     SwDoc* pDoc = (SwDoc*)rPam.GetDoc();
      41             : 
      42           0 :     SwTxtNode* pTxtNd = rPam.GetPoint()->nNode.GetNode().GetTxtNode();
      43           0 :     if( pTxtNd )
      44             :     {
      45           0 :         pTxtFmtColl = pTxtNd->GetTxtColl();
      46             :         pHistory->CopyAttr( pTxtNd->GetpSwpHints(), nSttNode,
      47           0 :                             0, pTxtNd->GetTxt().getLength(), false );
      48           0 :         if( pTxtNd->HasSwAttrSet() )
      49           0 :             pHistory->CopyFmtAttr( *pTxtNd->GetpSwAttrSet(), nSttNode );
      50             : 
      51           0 :         if( !nSttCntnt )    // than take the Flys along
      52             :         {
      53           0 :             sal_uInt16 nArrLen = pDoc->GetSpzFrmFmts()->size();
      54           0 :             for( sal_uInt16 n = 0; n < nArrLen; ++n )
      55             :             {
      56           0 :                 SwFrmFmt* pFmt = (*pDoc->GetSpzFrmFmts())[n];
      57           0 :                 SwFmtAnchor const*const  pAnchor = &pFmt->GetAnchor();
      58           0 :                 const SwPosition* pAPos = pAnchor->GetCntntAnchor();
      59           0 :                 if (pAPos &&
      60           0 :                     (pAnchor->GetAnchorId() == FLY_AT_PARA) &&
      61           0 :                      nSttNode == pAPos->nNode.GetIndex() )
      62             :                 {
      63           0 :                     if( !pFrmFmts )
      64           0 :                         pFrmFmts = new std::vector<SwFrmFmt*>;
      65           0 :                     pFrmFmts->push_back( pFmt );
      66             :                 }
      67             :             }
      68             :         }
      69             :     }
      70             :     // consider Redline
      71           0 :     if( pDoc->IsRedlineOn() )
      72             :     {
      73           0 :         pRedlData = new SwRedlineData( nsRedlineType_t::REDLINE_INSERT, pDoc->GetRedlineAuthor() );
      74           0 :         SetRedlineMode( pDoc->GetRedlineMode() );
      75             :     }
      76           0 : }
      77             : 
      78             : // set destination after reading input
      79           0 : void SwUndoInserts::SetInsertRange( const SwPaM& rPam, bool bScanFlys,
      80             :                                     bool bSttIsTxtNd )
      81             : {
      82           0 :     const SwPosition* pTmpPos = rPam.End();
      83           0 :     nEndNode = pTmpPos->nNode.GetIndex();
      84           0 :     nEndCntnt = pTmpPos->nContent.GetIndex();
      85           0 :     if( rPam.HasMark() )
      86             :     {
      87           0 :         if( pTmpPos == rPam.GetPoint() )
      88           0 :             pTmpPos = rPam.GetMark();
      89             :         else
      90           0 :             pTmpPos = rPam.GetPoint();
      91             : 
      92           0 :         nSttNode = pTmpPos->nNode.GetIndex();
      93           0 :         nSttCntnt = pTmpPos->nContent.GetIndex();
      94             : 
      95           0 :         if( !bSttIsTxtNd )      // if a table selection is added ...
      96             :         {
      97           0 :             ++nSttNode;         // ... than the CopyPam is not fully correct
      98           0 :             bSttWasTxtNd = false;
      99             :         }
     100             :     }
     101             : 
     102           0 :     if( bScanFlys && !nSttCntnt )
     103             :     {
     104             :         // than collect all new Flys
     105           0 :         SwDoc* pDoc = (SwDoc*)rPam.GetDoc();
     106           0 :         sal_uInt16 nArrLen = pDoc->GetSpzFrmFmts()->size();
     107           0 :         for( sal_uInt16 n = 0; n < nArrLen; ++n )
     108             :         {
     109           0 :             SwFrmFmt* pFmt = (*pDoc->GetSpzFrmFmts())[n];
     110           0 :             SwFmtAnchor const*const pAnchor = &pFmt->GetAnchor();
     111           0 :             SwPosition const*const pAPos = pAnchor->GetCntntAnchor();
     112           0 :             if (pAPos &&
     113           0 :                 (pAnchor->GetAnchorId() == FLY_AT_PARA) &&
     114           0 :                 nSttNode == pAPos->nNode.GetIndex() )
     115             :             {
     116           0 :                 std::vector<SwFrmFmt*>::iterator it;
     117           0 :                 if( !pFrmFmts ||
     118           0 :                     pFrmFmts->end() == ( it = std::find( pFrmFmts->begin(), pFrmFmts->end(), pFmt ) ) )
     119             :                 {
     120             :                     ::boost::shared_ptr<SwUndoInsLayFmt> const pFlyUndo(
     121           0 :                         new SwUndoInsLayFmt(pFmt, 0, 0));
     122           0 :                     m_FlyUndos.push_back(pFlyUndo);
     123             :                 }
     124             :                 else
     125           0 :                     pFrmFmts->erase( it );
     126             :             }
     127             :         }
     128           0 :         delete pFrmFmts, pFrmFmts = 0;
     129             :     }
     130           0 : }
     131             : 
     132           0 : SwUndoInserts::~SwUndoInserts()
     133             : {
     134           0 :     if (m_pUndoNodeIndex) // delete also the section from UndoNodes array
     135             :     {
     136             :         // Insert saves content in IconSection
     137           0 :         SwNodes& rUNds = m_pUndoNodeIndex->GetNodes();
     138           0 :         rUNds.Delete(*m_pUndoNodeIndex,
     139           0 :             rUNds.GetEndOfExtras().GetIndex() - m_pUndoNodeIndex->GetIndex());
     140           0 :         m_pUndoNodeIndex.reset();
     141             :     }
     142           0 :     delete pFrmFmts;
     143           0 :     delete pRedlData;
     144           0 : }
     145             : 
     146           0 : void SwUndoInserts::UndoImpl(::sw::UndoRedoContext & rContext)
     147             : {
     148           0 :     SwDoc *const pDoc = & rContext.GetDoc();
     149           0 :     SwPaM *const pPam = & AddUndoRedoPaM(rContext);
     150             : 
     151           0 :     if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
     152           0 :         pDoc->DeleteRedline( *pPam, true, USHRT_MAX );
     153             : 
     154             :     // if Point and Mark are different text nodes so a JoinNext has to be done
     155           0 :     bool bJoinNext = nSttNode != nEndNode &&
     156           0 :                 pPam->GetMark()->nNode.GetNode().GetTxtNode() &&
     157           0 :                 pPam->GetPoint()->nNode.GetNode().GetTxtNode();
     158             : 
     159             :     // Is there any content? (loading from template does not have content)
     160           0 :     if( nSttNode != nEndNode || nSttCntnt != nEndCntnt )
     161             :     {
     162           0 :         if( nSttNode != nEndNode )
     163             :         {
     164           0 :             SwTxtNode* pTxtNd = pDoc->GetNodes()[ nEndNode ]->GetTxtNode();
     165           0 :             if (pTxtNd && pTxtNd->GetTxt().getLength() == nEndCntnt)
     166           0 :                 pLastNdColl = pTxtNd->GetTxtColl();
     167             :         }
     168             : 
     169           0 :         RemoveIdxFromRange( *pPam, false );
     170           0 :         SetPaM(*pPam);
     171             : 
     172             :         // are there Footnotes or CntntFlyFrames in text?
     173           0 :         nSetPos = pHistory->Count();
     174           0 :         nNdDiff = pPam->GetMark()->nNode.GetIndex();
     175           0 :         DelCntntIndex( *pPam->GetMark(), *pPam->GetPoint() );
     176           0 :         nNdDiff -= pPam->GetMark()->nNode.GetIndex();
     177             : 
     178           0 :         if( *pPam->GetPoint() != *pPam->GetMark() )
     179             :         {
     180             :             m_pUndoNodeIndex.reset(
     181           0 :                     new SwNodeIndex(pDoc->GetNodes().GetEndOfContent()));
     182           0 :             MoveToUndoNds(*pPam, m_pUndoNodeIndex.get());
     183             : 
     184           0 :             if( !bSttWasTxtNd )
     185           0 :                 pPam->Move( fnMoveBackward, fnGoCntnt );
     186             :         }
     187             :     }
     188             : 
     189           0 :     if (m_FlyUndos.size())
     190             :     {
     191           0 :         sal_uLong nTmp = pPam->GetPoint()->nNode.GetIndex();
     192           0 :         for (size_t n = m_FlyUndos.size(); 0 < n; --n)
     193             :         {
     194           0 :             m_FlyUndos[ n-1 ]->UndoImpl(rContext);
     195             :         }
     196           0 :         nNdDiff += nTmp - pPam->GetPoint()->nNode.GetIndex();
     197             :     }
     198             : 
     199           0 :     SwNodeIndex& rIdx = pPam->GetPoint()->nNode;
     200           0 :     SwTxtNode* pTxtNode = rIdx.GetNode().GetTxtNode();
     201           0 :     if( pTxtNode )
     202             :     {
     203           0 :         if( !pTxtFmtColl ) // if 0 than it's no TextNode -> delete
     204             :         {
     205           0 :             SwNodeIndex aDelIdx( rIdx );
     206           0 :             ++rIdx;
     207           0 :             SwCntntNode* pCNd = rIdx.GetNode().GetCntntNode();
     208           0 :             pPam->GetPoint()->nContent.Assign( pCNd, pCNd ? pCNd->Len() : 0 );
     209           0 :             pPam->SetMark();
     210           0 :             pPam->DeleteMark();
     211             : 
     212           0 :             RemoveIdxRel( aDelIdx.GetIndex(), *pPam->GetPoint() );
     213             : 
     214           0 :             pDoc->GetNodes().Delete( aDelIdx, 1 );
     215             :         }
     216             :         else
     217             :         {
     218           0 :             if( bJoinNext && pTxtNode->CanJoinNext())
     219             :             {
     220             :                 {
     221           0 :                     RemoveIdxRel( rIdx.GetIndex()+1, SwPosition( rIdx,
     222           0 :                         SwIndex( pTxtNode, pTxtNode->GetTxt().getLength() )));
     223             :                 }
     224           0 :                 pTxtNode->JoinNext();
     225             :             }
     226             :             // reset all text attributes in the paragraph!
     227           0 :             pTxtNode->RstTxtAttr( SwIndex(pTxtNode, 0), pTxtNode->Len(), 0, 0, true );
     228             : 
     229           0 :             pTxtNode->ResetAllAttr();
     230             : 
     231           0 :             if( USHRT_MAX != pDoc->GetTxtFmtColls()->GetPos( pTxtFmtColl ))
     232           0 :                 pTxtFmtColl = (SwTxtFmtColl*)pTxtNode->ChgFmtColl( pTxtFmtColl );
     233             : 
     234           0 :             pHistory->SetTmpEnd( nSetPos );
     235           0 :             pHistory->TmpRollback( pDoc, 0, false );
     236             :         }
     237             :     }
     238           0 : }
     239             : 
     240           0 : void SwUndoInserts::RedoImpl(::sw::UndoRedoContext & rContext)
     241             : {
     242             :     // position cursor onto REDO section
     243           0 :     SwPaM *const pPam(& rContext.GetCursorSupplier().CreateNewShellCursor());
     244           0 :     SwDoc* pDoc = pPam->GetDoc();
     245           0 :     pPam->DeleteMark();
     246           0 :     pPam->GetPoint()->nNode = nSttNode - nNdDiff;
     247           0 :     SwCntntNode* pCNd = pPam->GetCntntNode();
     248           0 :     pPam->GetPoint()->nContent.Assign( pCNd, nSttCntnt );
     249             : 
     250           0 :     SwTxtFmtColl* pSavTxtFmtColl = pTxtFmtColl;
     251           0 :     if( pTxtFmtColl && pCNd && pCNd->IsTxtNode() )
     252           0 :         pSavTxtFmtColl = ((SwTxtNode*)pCNd)->GetTxtColl();
     253             : 
     254           0 :     pHistory->SetTmpEnd( nSetPos );
     255             : 
     256             :     // retrieve start position for rollback
     257           0 :     if( ( nSttNode != nEndNode || nSttCntnt != nEndCntnt ) && m_pUndoNodeIndex)
     258             :     {
     259           0 :         const bool bMvBkwrd = MovePtBackward( *pPam );
     260             : 
     261             :         // re-insert content again (first detach m_pUndoNodeIndex!)
     262           0 :         sal_uLong const nMvNd = m_pUndoNodeIndex->GetIndex();
     263           0 :         m_pUndoNodeIndex.reset();
     264           0 :         MoveFromUndoNds(*pDoc, nMvNd, *pPam->GetMark());
     265           0 :         if( bSttWasTxtNd )
     266           0 :             MovePtForward( *pPam, bMvBkwrd );
     267           0 :         pPam->Exchange();
     268             :     }
     269             : 
     270           0 :     if( USHRT_MAX != pDoc->GetTxtFmtColls()->GetPos( pTxtFmtColl ))
     271             :     {
     272           0 :         SwTxtNode* pTxtNd = pPam->GetMark()->nNode.GetNode().GetTxtNode();
     273           0 :         if( pTxtNd )
     274           0 :             pTxtNd->ChgFmtColl( pTxtFmtColl );
     275             :     }
     276           0 :     pTxtFmtColl = pSavTxtFmtColl;
     277             : 
     278           0 :     if( pLastNdColl && USHRT_MAX != pDoc->GetTxtFmtColls()->GetPos( pLastNdColl ) &&
     279           0 :         pPam->GetPoint()->nNode != pPam->GetMark()->nNode )
     280             :     {
     281           0 :         SwTxtNode* pTxtNd = pPam->GetPoint()->nNode.GetNode().GetTxtNode();
     282           0 :         if( pTxtNd )
     283           0 :             pTxtNd->ChgFmtColl( pLastNdColl );
     284             :     }
     285             : 
     286           0 :     for (size_t n = m_FlyUndos.size(); 0 < n; --n)
     287             :     {
     288           0 :         m_FlyUndos[ n-1 ]->RedoImpl(rContext);
     289             :     }
     290             : 
     291           0 :     pHistory->Rollback( pDoc, nSetPos );
     292             : 
     293           0 :     if( pRedlData && IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
     294             :     {
     295           0 :         RedlineMode_t eOld = pDoc->GetRedlineMode();
     296           0 :         pDoc->SetRedlineMode_intern((RedlineMode_t)( eOld & ~nsRedlineMode_t::REDLINE_IGNORE ));
     297           0 :         pDoc->AppendRedline( new SwRangeRedline( *pRedlData, *pPam ), true);
     298           0 :         pDoc->SetRedlineMode_intern( eOld );
     299             :     }
     300           0 :     else if( !( nsRedlineMode_t::REDLINE_IGNORE & GetRedlineMode() ) &&
     301           0 :             !pDoc->GetRedlineTbl().empty() )
     302           0 :         pDoc->SplitRedline( *pPam );
     303           0 : }
     304             : 
     305           0 : void SwUndoInserts::RepeatImpl(::sw::RepeatContext & rContext)
     306             : {
     307           0 :     SwPaM aPam( rContext.GetDoc().GetNodes().GetEndOfContent() );
     308           0 :     SetPaM( aPam );
     309           0 :     SwPaM & rRepeatPaM( rContext.GetRepeatPaM() );
     310           0 :     aPam.GetDoc()->CopyRange( aPam, *rRepeatPaM.GetPoint(), false );
     311           0 : }
     312             : 
     313           0 : SwUndoInsDoc::SwUndoInsDoc( const SwPaM& rPam )
     314           0 :     : SwUndoInserts( UNDO_INSDOKUMENT, rPam )
     315             : {
     316           0 : }
     317             : 
     318           0 : SwUndoCpyDoc::SwUndoCpyDoc( const SwPaM& rPam )
     319           0 :     : SwUndoInserts( UNDO_COPY, rPam )
     320             : {
     321           0 : }
     322             : 
     323             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10