LCOV - code coverage report
Current view: top level - sw/source/core/undo - unspnd.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 18 95 18.9 %
Date: 2015-06-13 12:38:46 Functions: 5 8 62.5 %
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 <UndoSplitMove.hxx>
      21             : #include "doc.hxx"
      22             : #include <IDocumentRedlineAccess.hxx>
      23             : #include "pam.hxx"
      24             : #include "swtable.hxx"
      25             : #include "ndtxt.hxx"
      26             : #include "swundo.hxx"
      27             : #include <editeng/formatbreakitem.hxx>
      28             : #include <fmtpdsc.hxx>
      29             : #include <frmfmt.hxx>
      30             : #include <UndoCore.hxx>
      31             : #include "rolbck.hxx"
      32             : #include "redline.hxx"
      33             : #include "docary.hxx"
      34             : #include <IShellCursorSupplier.hxx>
      35             : 
      36             : // SPLITNODE
      37             : 
      38         316 : SwUndoSplitNode::SwUndoSplitNode( SwDoc* pDoc, const SwPosition& rPos,
      39             :                                     bool bChkTable )
      40         316 :     : SwUndo( UNDO_SPLITNODE ), pHistory( 0 ), pRedlData( 0 ), nNode( rPos.nNode.GetIndex() ),
      41         316 :         nContent( rPos.nContent.GetIndex() ),
      42         948 :         bTableFlag( false ), bChkTableStt( bChkTable )
      43             : {
      44         316 :     SwTextNode *const pTextNd = rPos.nNode.GetNode().GetTextNode();
      45             :     OSL_ENSURE( pTextNd, "only for TextNode" );
      46         316 :     if( pTextNd->GetpSwpHints() )
      47             :     {
      48           4 :         pHistory = new SwHistory;
      49             :         pHistory->CopyAttr( pTextNd->GetpSwpHints(), nNode, 0,
      50           4 :                             pTextNd->GetText().getLength(), false );
      51           4 :         if( !pHistory->Count() )
      52           4 :             DELETEZ( pHistory );
      53             :     }
      54             :     // consider Redline
      55         316 :     if( pDoc->getIDocumentRedlineAccess().IsRedlineOn() )
      56             :     {
      57           0 :         pRedlData = new SwRedlineData( nsRedlineType_t::REDLINE_INSERT, pDoc->getIDocumentRedlineAccess().GetRedlineAuthor() );
      58           0 :         SetRedlineMode( pDoc->getIDocumentRedlineAccess().GetRedlineMode() );
      59             :     }
      60             : 
      61         316 :     nParRsid = pTextNd->GetParRsid();
      62         316 : }
      63             : 
      64         945 : SwUndoSplitNode::~SwUndoSplitNode()
      65             : {
      66         315 :     delete pHistory;
      67         315 :     delete pRedlData;
      68         630 : }
      69             : 
      70           0 : void SwUndoSplitNode::UndoImpl(::sw::UndoRedoContext & rContext)
      71             : {
      72           0 :     SwDoc *const pDoc = & rContext.GetDoc();
      73           0 :     SwPaM & rPam( rContext.GetCursorSupplier().CreateNewShellCursor() );
      74           0 :     rPam.DeleteMark();
      75           0 :     if( bTableFlag )
      76             :     {
      77             :         // than a TextNode was added directly before the current table
      78           0 :         SwNodeIndex& rIdx = rPam.GetPoint()->nNode;
      79           0 :         rIdx = nNode;
      80             :         SwTextNode* pTNd;
      81           0 :         SwNode* pCurrNd = pDoc->GetNodes()[ nNode + 1 ];
      82           0 :         SwTableNode* pTableNd = pCurrNd->FindTableNode();
      83           0 :         if( pCurrNd->IsContentNode() && pTableNd &&
      84           0 :             0 != ( pTNd = pDoc->GetNodes()[ pTableNd->GetIndex()-1 ]->GetTextNode() ))
      85             :         {
      86             :             // move break attributes
      87           0 :             SwFrameFormat* pTableFormat = pTableNd->GetTable().GetFrameFormat();
      88           0 :             const SfxItemSet* pNdSet = pTNd->GetpSwAttrSet();
      89           0 :             if( pNdSet )
      90             :             {
      91             :                 const SfxPoolItem *pItem;
      92           0 :                 if( SfxItemState::SET == pNdSet->GetItemState( RES_PAGEDESC, false,
      93           0 :                     &pItem ) )
      94           0 :                     pTableFormat->SetFormatAttr( *pItem );
      95             : 
      96           0 :                 if( SfxItemState::SET == pNdSet->GetItemState( RES_BREAK, false,
      97           0 :                      &pItem ) )
      98           0 :                     pTableFormat->SetFormatAttr( *pItem );
      99             :             }
     100             : 
     101             :             // than delete it again
     102           0 :             SwNodeIndex aDelNd( *pTableNd, -1 );
     103           0 :             rPam.GetPoint()->nContent.Assign( static_cast<SwContentNode*>(pCurrNd), 0 );
     104           0 :             RemoveIdxRel( aDelNd.GetIndex(), *rPam.GetPoint() );
     105           0 :             pDoc->GetNodes().Delete( aDelNd );
     106             :         }
     107             :     }
     108             :     else
     109             :     {
     110           0 :         SwTextNode * pTNd = pDoc->GetNodes()[ nNode ]->GetTextNode();
     111           0 :         if( pTNd )
     112             :         {
     113           0 :             rPam.GetPoint()->nNode = *pTNd;
     114           0 :             rPam.GetPoint()->nContent.Assign(pTNd, pTNd->GetText().getLength());
     115             : 
     116           0 :             if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
     117             :             {
     118           0 :                 rPam.SetMark();
     119           0 :                 ++rPam.GetMark()->nNode;
     120           0 :                 rPam.GetMark()->nContent.Assign( rPam.GetMark()->
     121           0 :                                     nNode.GetNode().GetContentNode(), 0 );
     122           0 :                 pDoc->getIDocumentRedlineAccess().DeleteRedline( rPam, true, USHRT_MAX );
     123           0 :                 rPam.DeleteMark();
     124             :             }
     125             : 
     126           0 :             RemoveIdxRel( nNode+1, *rPam.GetPoint() );
     127             : 
     128           0 :             pTNd->JoinNext();
     129           0 :             if( pHistory )
     130             :             {
     131           0 :                 rPam.GetPoint()->nContent = 0;
     132           0 :                 rPam.SetMark();
     133           0 :                 rPam.GetPoint()->nContent = pTNd->GetText().getLength();
     134             : 
     135           0 :                 pDoc->RstTextAttrs( rPam, true );
     136           0 :                 pHistory->TmpRollback( pDoc, 0, false );
     137             :             }
     138             : 
     139           0 :             pDoc->UpdateParRsid( pTNd, nParRsid );
     140             :         }
     141             :     }
     142             : 
     143             :     // also set the cursor onto undo section
     144           0 :     rPam.DeleteMark();
     145           0 :     rPam.GetPoint()->nNode = nNode;
     146           0 :     rPam.GetPoint()->nContent.Assign( rPam.GetContentNode(), nContent );
     147           0 : }
     148             : 
     149           0 : void SwUndoSplitNode::RedoImpl(::sw::UndoRedoContext & rContext)
     150             : {
     151           0 :     SwPaM & rPam( rContext.GetCursorSupplier().CreateNewShellCursor() );
     152           0 :     rPam.GetPoint()->nNode = nNode;
     153           0 :     SwTextNode * pTNd = rPam.GetNode().GetTextNode();
     154             :     OSL_ENSURE(pTNd, "SwUndoSplitNode::RedoImpl(): SwTextNode expected");
     155           0 :     if (pTNd)
     156             :     {
     157           0 :         rPam.GetPoint()->nContent.Assign( pTNd, nContent );
     158             : 
     159           0 :         SwDoc* pDoc = rPam.GetDoc();
     160           0 :         pDoc->getIDocumentContentOperations().SplitNode( *rPam.GetPoint(), bChkTableStt );
     161             : 
     162           0 :         if( pHistory )
     163           0 :             pHistory->SetTmpEnd( pHistory->Count() );
     164             : 
     165           0 :         if( ( pRedlData && IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() )) ||
     166           0 :             ( !( nsRedlineMode_t::REDLINE_IGNORE & GetRedlineMode() ) &&
     167           0 :                 !pDoc->getIDocumentRedlineAccess().GetRedlineTable().empty() ))
     168             :         {
     169           0 :             rPam.SetMark();
     170           0 :             if( rPam.Move( fnMoveBackward ))
     171             :             {
     172           0 :                 if( pRedlData && IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
     173             :                 {
     174           0 :                     RedlineMode_t eOld = pDoc->getIDocumentRedlineAccess().GetRedlineMode();
     175           0 :                     pDoc->getIDocumentRedlineAccess().SetRedlineMode_intern((RedlineMode_t)(eOld & ~nsRedlineMode_t::REDLINE_IGNORE));
     176           0 :                     pDoc->getIDocumentRedlineAccess().AppendRedline( new SwRangeRedline( *pRedlData, rPam ), true);
     177           0 :                     pDoc->getIDocumentRedlineAccess().SetRedlineMode_intern( eOld );
     178             :                 }
     179             :                 else
     180           0 :                     pDoc->getIDocumentRedlineAccess().SplitRedline( rPam );
     181           0 :                 rPam.Exchange();
     182             :             }
     183           0 :             rPam.DeleteMark();
     184             :         }
     185             :     }
     186           0 : }
     187             : 
     188           0 : void SwUndoSplitNode::RepeatImpl(::sw::RepeatContext & rContext)
     189             : {
     190           0 :     rContext.GetDoc().getIDocumentContentOperations().SplitNode(
     191           0 :         *rContext.GetRepeatPaM().GetPoint(), bChkTableStt );
     192         177 : }
     193             : 
     194             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11