LCOV - code coverage report
Current view: top level - libreoffice/sw/source/core/undo - unnum.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 200 0.0 %
Date: 2012-12-27 Functions: 0 36 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 <UndoNumbering.hxx>
      21             : #include <hintids.hxx>
      22             : #include <editeng/lrspitem.hxx>
      23             : #include <doc.hxx>
      24             : #include <IDocumentUndoRedo.hxx>
      25             : #include <swundo.hxx>
      26             : #include <pam.hxx>
      27             : #include <ndtxt.hxx>
      28             : #include <UndoCore.hxx>
      29             : #include <rolbck.hxx>
      30             : 
      31           0 : SwUndoInsNum::SwUndoInsNum( const SwNumRule& rOldRule,
      32             :                             const SwNumRule& rNewRule,
      33             :                             SwUndoId nUndoId )
      34             :     : SwUndo( nUndoId ),
      35             :     aNumRule( rNewRule ), pHistory( 0 ), nSttSet( ULONG_MAX ),
      36           0 :     pOldNumRule( new SwNumRule( rOldRule )), nLRSavePos( 0 )
      37             : {
      38           0 : }
      39             : 
      40           0 : SwUndoInsNum::SwUndoInsNum( const SwPaM& rPam, const SwNumRule& rRule )
      41             :     : SwUndo( UNDO_INSNUM ), SwUndRng( rPam ),
      42             :     aNumRule( rRule ), pHistory( 0 ),
      43           0 :     nSttSet( ULONG_MAX ), pOldNumRule( 0 ), nLRSavePos( 0 )
      44             : {
      45           0 : }
      46             : 
      47           0 : SwUndoInsNum::SwUndoInsNum( const SwPosition& rPos, const SwNumRule& rRule,
      48             :                             const String& rReplaceRule )
      49             :     : SwUndo( UNDO_INSNUM ),
      50             :     aNumRule( rRule ), pHistory( 0 ),
      51             :     nSttSet( ULONG_MAX ), pOldNumRule( 0 ),
      52           0 :     sReplaceRule( rReplaceRule ), nLRSavePos( 0 )
      53             : {
      54             :     // No selection!
      55           0 :     nEndNode = 0, nEndCntnt = USHRT_MAX;
      56           0 :     nSttNode = rPos.nNode.GetIndex();
      57           0 :     nSttCntnt = rPos.nContent.GetIndex();
      58           0 : }
      59             : 
      60           0 : SwUndoInsNum::~SwUndoInsNum()
      61             : {
      62           0 :     delete pHistory;
      63           0 :     delete pOldNumRule;
      64           0 : }
      65             : 
      66           0 : SwRewriter SwUndoInsNum::GetRewriter() const
      67             : {
      68           0 :     SwRewriter aResult;
      69           0 :     if( UNDO_INSFMTATTR == GetId() )
      70           0 :         aResult.AddRule(UndoArg1, aNumRule.GetName());
      71           0 :     return aResult;
      72             : }
      73             : 
      74           0 : void SwUndoInsNum::UndoImpl(::sw::UndoRedoContext & rContext)
      75             : {
      76           0 :     SwDoc & rDoc = rContext.GetDoc();
      77             : 
      78           0 :     if( pOldNumRule )
      79           0 :         rDoc.ChgNumRuleFmts( *pOldNumRule );
      80             : 
      81           0 :     if( pHistory )
      82             :     {
      83             :         SwTxtNode* pNd;
      84           0 :         if( ULONG_MAX != nSttSet &&
      85           0 :             0 != ( pNd = rDoc.GetNodes()[ nSttSet ]->GetTxtNode() ))
      86           0 :                 pNd->SetListRestart( sal_True );
      87             :         else
      88           0 :             pNd = 0;
      89             : 
      90             : 
      91           0 :         if( nLRSavePos )
      92             :         {
      93             :             // Update immediately so that potential "old" LRSpaces will be valid again.
      94             :             // For that search firstly the correct NumRule names!
      95           0 :             if( !pNd && nSttNode )
      96           0 :                 pNd = rDoc.GetNodes()[ nSttNode ]->GetTxtNode();
      97             : 
      98           0 :             pHistory->TmpRollback( &rDoc, nLRSavePos );
      99             : 
     100             :         }
     101           0 :         pHistory->TmpRollback( &rDoc, 0 );
     102           0 :         pHistory->SetTmpEnd( pHistory->Count() );
     103             :     }
     104             : 
     105           0 :     if (nSttNode)
     106             :     {
     107           0 :         AddUndoRedoPaM(rContext);
     108             :     }
     109           0 : }
     110             : 
     111           0 : void SwUndoInsNum::RedoImpl(::sw::UndoRedoContext & rContext)
     112             : {
     113           0 :     SwDoc & rDoc = rContext.GetDoc();
     114             : 
     115           0 :     if( pOldNumRule )
     116           0 :         rDoc.ChgNumRuleFmts( aNumRule );
     117           0 :     else if( pHistory )
     118             :     {
     119           0 :         SwPaM & rPam( AddUndoRedoPaM(rContext) );
     120           0 :         if( sReplaceRule.Len() )
     121             :         {
     122           0 :             rDoc.ReplaceNumRule(*rPam.GetPoint(),
     123           0 :                                 sReplaceRule, aNumRule.GetName() );
     124             :         }
     125             :         else
     126             :         {
     127             :             // #i42921# - adapt to changed signature
     128           0 :             rDoc.SetNumRule(rPam, aNumRule, false);
     129             :         }
     130             :     }
     131           0 : }
     132             : 
     133           0 : void SwUndoInsNum::SetLRSpaceEndPos()
     134             : {
     135           0 :     if( pHistory )
     136           0 :         nLRSavePos = pHistory->Count();
     137           0 : }
     138             : 
     139           0 : void SwUndoInsNum::RepeatImpl(::sw::RepeatContext & rContext)
     140             : {
     141           0 :     SwDoc & rDoc(rContext.GetDoc());
     142           0 :     if( nSttNode )
     143             :     {
     144           0 :         if( !sReplaceRule.Len() )
     145             :         {
     146             :             // #i42921# - adapt to changed signature
     147           0 :             rDoc.SetNumRule(rContext.GetRepeatPaM(), aNumRule, false);
     148             :         }
     149             :     }
     150             :     else
     151             :     {
     152           0 :         rDoc.ChgNumRuleFmts( aNumRule );
     153             :     }
     154           0 : }
     155             : 
     156           0 : SwHistory* SwUndoInsNum::GetHistory()
     157             : {
     158           0 :     if( !pHistory )
     159           0 :         pHistory = new SwHistory;
     160           0 :     return pHistory;
     161             : }
     162             : 
     163           0 : void SwUndoInsNum::SaveOldNumRule( const SwNumRule& rOld )
     164             : {
     165           0 :     if( !pOldNumRule )
     166           0 :         pOldNumRule = new SwNumRule( rOld );
     167           0 : }
     168             : 
     169           0 : SwUndoDelNum::SwUndoDelNum( const SwPaM& rPam )
     170           0 :     : SwUndo( UNDO_DELNUM ), SwUndRng( rPam )
     171             : {
     172           0 :     aNodes.reserve( nEndNode - nSttNode > 255 ? 255 : nEndNode - nSttNode );
     173           0 :     pHistory = new SwHistory;
     174           0 : }
     175             : 
     176           0 : SwUndoDelNum::~SwUndoDelNum()
     177             : {
     178           0 :     delete pHistory;
     179           0 : }
     180             : 
     181           0 : void SwUndoDelNum::UndoImpl(::sw::UndoRedoContext & rContext)
     182             : {
     183           0 :     SwDoc & rDoc = rContext.GetDoc();
     184             : 
     185           0 :     pHistory->TmpRollback( &rDoc, 0 );
     186           0 :     pHistory->SetTmpEnd( pHistory->Count() );
     187             : 
     188           0 :     for( std::vector<NodeLevel>::const_iterator i = aNodes.begin(); i != aNodes.end(); ++i )
     189             :     {
     190           0 :         SwTxtNode* pNd = rDoc.GetNodes()[ i->index ]->GetTxtNode();
     191             :         OSL_ENSURE( pNd, "Where has the TextNode gone?" );
     192           0 :         pNd->SetAttrListLevel( i->level );
     193             : 
     194           0 :         if( pNd->GetCondFmtColl() )
     195           0 :             pNd->ChkCondColl();
     196             :     }
     197             : 
     198           0 :     AddUndoRedoPaM(rContext);
     199           0 : }
     200             : 
     201           0 : void SwUndoDelNum::RedoImpl(::sw::UndoRedoContext & rContext)
     202             : {
     203           0 :     SwPaM & rPam( AddUndoRedoPaM(rContext) );
     204           0 :     rContext.GetDoc().DelNumRules(rPam);
     205           0 : }
     206             : 
     207           0 : void SwUndoDelNum::RepeatImpl(::sw::RepeatContext & rContext)
     208             : {
     209           0 :     rContext.GetDoc().DelNumRules(rContext.GetRepeatPaM());
     210           0 : }
     211             : 
     212           0 : void SwUndoDelNum::AddNode( const SwTxtNode& rNd, sal_Bool )
     213             : {
     214           0 :     if( rNd.GetNumRule() )
     215             :     {
     216           0 :         aNodes.push_back( NodeLevel( rNd.GetIndex(), rNd.GetActualListLevel() ) );
     217             :     }
     218           0 : }
     219             : 
     220           0 : SwUndoMoveNum::SwUndoMoveNum( const SwPaM& rPam, long nOff, bool bIsOutlMv )
     221             :     : SwUndo( bIsOutlMv ? UNDO_OUTLINE_UD : UNDO_MOVENUM ),
     222             :     SwUndRng( rPam ),
     223           0 :     nNewStt( 0 ), nOffset( nOff )
     224             : {
     225             :     // nOffset: Down    =>  1
     226             :     //          Up      => -1
     227           0 : }
     228             : 
     229           0 : void SwUndoMoveNum::UndoImpl(::sw::UndoRedoContext & rContext)
     230             : {
     231           0 :     sal_uLong nTmpStt = nSttNode, nTmpEnd = nEndNode;
     232             : 
     233           0 :     if( nEndNode || USHRT_MAX != nEndCntnt )        // section?
     234             :     {
     235           0 :         if( nNewStt < nSttNode )        // moved forwards
     236           0 :             nEndNode = nEndNode - ( nSttNode - nNewStt );
     237             :         else
     238           0 :             nEndNode = nEndNode + ( nNewStt - nSttNode );
     239             :     }
     240           0 :     nSttNode = nNewStt;
     241             : 
     242           0 :     SwPaM & rPam( AddUndoRedoPaM(rContext) );
     243           0 :     rContext.GetDoc().MoveParagraph( rPam, -nOffset,
     244           0 :                                         UNDO_OUTLINE_UD == GetId() );
     245           0 :     nSttNode = nTmpStt;
     246           0 :     nEndNode = nTmpEnd;
     247           0 : }
     248             : 
     249           0 : void SwUndoMoveNum::RedoImpl(::sw::UndoRedoContext & rContext)
     250             : {
     251           0 :     SwPaM & rPam( AddUndoRedoPaM(rContext) );
     252           0 :     rContext.GetDoc().MoveParagraph(rPam, nOffset, UNDO_OUTLINE_UD == GetId());
     253           0 : }
     254             : 
     255           0 : void SwUndoMoveNum::RepeatImpl(::sw::RepeatContext & rContext)
     256             : {
     257           0 :     SwDoc & rDoc = rContext.GetDoc();
     258           0 :     if( UNDO_OUTLINE_UD == GetId() )
     259             :     {
     260           0 :         rDoc.MoveOutlinePara(rContext.GetRepeatPaM(),
     261           0 :                                             0 < nOffset ? 1 : -1 );
     262             :     }
     263             :     else
     264             :     {
     265           0 :         rDoc.MoveParagraph(rContext.GetRepeatPaM(), nOffset, false);
     266             :     }
     267           0 : }
     268             : 
     269           0 : SwUndoNumUpDown::SwUndoNumUpDown( const SwPaM& rPam, short nOff )
     270             :     : SwUndo( nOff > 0 ? UNDO_NUMUP : UNDO_NUMDOWN ), SwUndRng( rPam ),
     271           0 :       nOffset( nOff )
     272             : {
     273             :     // nOffset: Down    =>  1
     274             :     //          Up      => -1
     275           0 : }
     276             : 
     277           0 : void SwUndoNumUpDown::UndoImpl(::sw::UndoRedoContext & rContext)
     278             : {
     279           0 :     SwPaM & rPam( AddUndoRedoPaM(rContext) );
     280           0 :     rContext.GetDoc().NumUpDown(rPam, 1 != nOffset );
     281           0 : }
     282             : 
     283           0 : void SwUndoNumUpDown::RedoImpl(::sw::UndoRedoContext & rContext)
     284             : {
     285           0 :     SwPaM & rPam( AddUndoRedoPaM(rContext) );
     286           0 :     rContext.GetDoc().NumUpDown(rPam, 1 == nOffset);
     287           0 : }
     288             : 
     289           0 : void SwUndoNumUpDown::RepeatImpl(::sw::RepeatContext & rContext)
     290             : {
     291           0 :     rContext.GetDoc().NumUpDown(rContext.GetRepeatPaM(), 1 == nOffset);
     292           0 : }
     293             : 
     294             : // #115901#
     295           0 : SwUndoNumOrNoNum::SwUndoNumOrNoNum( const SwNodeIndex& rIdx, sal_Bool bOldNum,
     296             :                                     sal_Bool bNewNum)
     297           0 :     : SwUndo( UNDO_NUMORNONUM ), nIdx( rIdx.GetIndex() ), mbNewNum(bNewNum),
     298           0 :       mbOldNum(bOldNum)
     299             : {
     300           0 : }
     301             : 
     302             : // #115901#, #i40034#
     303           0 : void SwUndoNumOrNoNum::UndoImpl(::sw::UndoRedoContext & rContext)
     304             : {
     305           0 :     SwNodeIndex aIdx( rContext.GetDoc().GetNodes(), nIdx );
     306           0 :     SwTxtNode * pTxtNd = aIdx.GetNode().GetTxtNode();
     307             : 
     308           0 :     if (NULL != pTxtNd)
     309             :     {
     310           0 :         pTxtNd->SetCountedInList(mbOldNum);
     311           0 :     }
     312           0 : }
     313             : 
     314             : // #115901#, #i40034#
     315           0 : void SwUndoNumOrNoNum::RedoImpl(::sw::UndoRedoContext & rContext)
     316             : {
     317           0 :     SwNodeIndex aIdx( rContext.GetDoc().GetNodes(), nIdx );
     318           0 :     SwTxtNode * pTxtNd = aIdx.GetNode().GetTxtNode();
     319             : 
     320           0 :     if (NULL != pTxtNd)
     321             :     {
     322           0 :         pTxtNd->SetCountedInList(mbNewNum);
     323           0 :     }
     324           0 : }
     325             : 
     326             : // #115901#
     327           0 : void SwUndoNumOrNoNum::RepeatImpl(::sw::RepeatContext & rContext)
     328             : {
     329           0 :     SwDoc & rDoc = rContext.GetDoc();
     330           0 :     if (mbOldNum && ! mbNewNum)
     331             :     {
     332           0 :         rDoc.NumOrNoNum(rContext.GetRepeatPaM().GetPoint()->nNode, false);
     333             :     }
     334           0 :     else if ( ! mbOldNum && mbNewNum )
     335             :     {
     336           0 :         rDoc.NumOrNoNum(rContext.GetRepeatPaM().GetPoint()->nNode, true);
     337             :     }
     338           0 : }
     339             : 
     340           0 : SwUndoNumRuleStart::SwUndoNumRuleStart( const SwPosition& rPos, sal_Bool bFlg )
     341             :     : SwUndo( UNDO_SETNUMRULESTART ),
     342           0 :     nIdx( rPos.nNode.GetIndex() ), nOldStt( USHRT_MAX ),
     343           0 :     nNewStt( USHRT_MAX ), bSetSttValue( sal_False ), bFlag( bFlg )
     344             : {
     345           0 : }
     346             : 
     347           0 : SwUndoNumRuleStart::SwUndoNumRuleStart( const SwPosition& rPos, sal_uInt16 nStt )
     348             :     : SwUndo( UNDO_SETNUMRULESTART ),
     349           0 :     nIdx( rPos.nNode.GetIndex() ),
     350           0 :     nOldStt( USHRT_MAX ), nNewStt( nStt ), bSetSttValue( sal_True )
     351             : {
     352           0 :     SwTxtNode* pTxtNd = rPos.nNode.GetNode().GetTxtNode();
     353           0 :     if ( pTxtNd )
     354             :     {
     355           0 :         if ( pTxtNd->HasAttrListRestartValue() )
     356             :         {
     357           0 :             nOldStt = static_cast<sal_uInt16>(pTxtNd->GetAttrListRestartValue());
     358             :         }
     359             :         else
     360             :         {
     361           0 :             nOldStt = USHRT_MAX; // indicating, that the list restart value is not set
     362             :         }
     363             :     }
     364           0 : }
     365             : 
     366           0 : void SwUndoNumRuleStart::UndoImpl(::sw::UndoRedoContext & rContext)
     367             : {
     368           0 :     SwDoc & rDoc = rContext.GetDoc();
     369           0 :     SwPosition const aPos( *rDoc.GetNodes()[ nIdx ] );
     370           0 :     if( bSetSttValue )
     371             :     {
     372           0 :         rDoc.SetNodeNumStart( aPos, nOldStt );
     373             :     }
     374             :     else
     375             :     {
     376           0 :         rDoc.SetNumRuleStart( aPos, !bFlag );
     377           0 :     }
     378           0 : }
     379             : 
     380           0 : void SwUndoNumRuleStart::RedoImpl(::sw::UndoRedoContext & rContext)
     381             : {
     382           0 :     SwDoc & rDoc = rContext.GetDoc();
     383           0 :     SwPosition const aPos( *rDoc.GetNodes()[ nIdx ] );
     384           0 :     if( bSetSttValue )
     385             :     {
     386           0 :         rDoc.SetNodeNumStart( aPos, nNewStt );
     387             :     }
     388             :     else
     389             :     {
     390           0 :         rDoc.SetNumRuleStart( aPos, bFlag );
     391           0 :     }
     392           0 : }
     393             : 
     394           0 : void SwUndoNumRuleStart::RepeatImpl(::sw::RepeatContext & rContext)
     395             : {
     396           0 :     SwDoc & rDoc = rContext.GetDoc();
     397           0 :     if( bSetSttValue )
     398             :     {
     399           0 :         rDoc.SetNodeNumStart(*rContext.GetRepeatPaM().GetPoint(), nNewStt);
     400             :     }
     401             :     else
     402             :     {
     403           0 :         rDoc.SetNumRuleStart(*rContext.GetRepeatPaM().GetPoint(), bFlag);
     404             :     }
     405           0 : }
     406             : 
     407             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10