LCOV - code coverage report
Current view: top level - editeng/source/editeng - editundo.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 127 340 37.4 %
Date: 2014-04-11 Functions: 38 73 52.1 %
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 <vcl/wrkwin.hxx>
      21             : #include <vcl/dialog.hxx>
      22             : #include <vcl/msgbox.hxx>
      23             : #include <vcl/svapp.hxx>
      24             : #include <impedit.hxx>
      25             : #include <editundo.hxx>
      26             : #include <editeng/editview.hxx>
      27             : #include <editeng/editeng.hxx>
      28             : 
      29             : 
      30           0 : static void lcl_DoSetSelection( EditView* pView, sal_uInt16 nPara )
      31             : {
      32           0 :     EPaM aEPaM( nPara, 0 );
      33           0 :     EditPaM aPaM( pView->GetImpEditEngine()->CreateEditPaM( aEPaM ) );
      34           0 :     aPaM.SetIndex( aPaM.GetNode()->Len() );
      35           0 :     EditSelection aSel( aPaM, aPaM );
      36           0 :     pView->GetImpEditView()->SetEditSelection( aSel );
      37           0 : }
      38             : 
      39       21852 : EditUndoManager::EditUndoManager(sal_uInt16 nMaxUndoActionCount )
      40             : :   SfxUndoManager(nMaxUndoActionCount),
      41       21852 :     mpEditEngine(0)
      42             : {
      43       21852 : }
      44             : 
      45       19452 : void EditUndoManager::SetEditEngine(EditEngine* pNew)
      46             : {
      47       19452 :     mpEditEngine = pNew;
      48       19452 : }
      49             : 
      50           2 : bool EditUndoManager::Undo()
      51             : {
      52           2 :     if ( !mpEditEngine || GetUndoActionCount() == 0 )
      53           0 :         return false;
      54             : 
      55             :     DBG_ASSERT( mpEditEngine->GetActiveView(), "Active View?" );
      56             : 
      57           2 :     if ( !mpEditEngine->GetActiveView() )
      58             :     {
      59           0 :         if (!mpEditEngine->GetEditViews().empty())
      60           0 :             mpEditEngine->SetActiveView(mpEditEngine->GetEditViews()[0]);
      61             :         else
      62             :         {
      63             :             OSL_FAIL("Undo in engine is not possible without a View! ");
      64           0 :             return false;
      65             :         }
      66             :     }
      67             : 
      68           2 :     mpEditEngine->GetActiveView()->GetImpEditView()->DrawSelection(); // Remove the old selection
      69             : 
      70           2 :     mpEditEngine->SetUndoMode( true );
      71           2 :     bool bDone = SfxUndoManager::Undo();
      72           2 :     mpEditEngine->SetUndoMode( false );
      73             : 
      74           2 :     EditSelection aNewSel( mpEditEngine->GetActiveView()->GetImpEditView()->GetEditSelection() );
      75             :     DBG_ASSERT( !aNewSel.IsInvalid(), "Invalid selection after Undo () ");
      76             :     DBG_ASSERT( !aNewSel.DbgIsBuggy( mpEditEngine->GetEditDoc() ), "Broken selection afte Undo () ");
      77             : 
      78           2 :     aNewSel.Min() = aNewSel.Max();
      79           2 :     mpEditEngine->GetActiveView()->GetImpEditView()->SetEditSelection( aNewSel );
      80           2 :     mpEditEngine->FormatAndUpdate( mpEditEngine->GetActiveView() );
      81             : 
      82           2 :     return bDone;
      83             : }
      84             : 
      85           1 : bool EditUndoManager::Redo()
      86             : {
      87           1 :     if ( !mpEditEngine || GetRedoActionCount() == 0 )
      88           0 :         return false;
      89             : 
      90             :     DBG_ASSERT( mpEditEngine->GetActiveView(), "Active View?" );
      91             : 
      92           1 :     if ( !mpEditEngine->GetActiveView() )
      93             :     {
      94           0 :         if (!mpEditEngine->GetEditViews().empty())
      95           0 :             mpEditEngine->SetActiveView(mpEditEngine->GetEditViews()[0]);
      96             :         else
      97             :         {
      98             :             OSL_FAIL( "Redo in Engine ohne View nicht moeglich!" );
      99           0 :             return false;
     100             :         }
     101             :     }
     102             : 
     103           1 :     mpEditEngine->GetActiveView()->GetImpEditView()->DrawSelection(); // Remove the old selection
     104             : 
     105           1 :     mpEditEngine->SetUndoMode( true );
     106           1 :     bool bDone = SfxUndoManager::Redo();
     107           1 :     mpEditEngine->SetUndoMode( false );
     108             : 
     109           1 :     EditSelection aNewSel( mpEditEngine->GetActiveView()->GetImpEditView()->GetEditSelection() );
     110             :     DBG_ASSERT( !aNewSel.IsInvalid(), "Invalid selection after Undo () ");
     111             :     DBG_ASSERT( !aNewSel.DbgIsBuggy( mpEditEngine->GetEditDoc() ), "Broken selection afte Undo () ");
     112             : 
     113           1 :     aNewSel.Min() = aNewSel.Max();
     114           1 :     mpEditEngine->GetActiveView()->GetImpEditView()->SetEditSelection( aNewSel );
     115           1 :     mpEditEngine->FormatAndUpdate( mpEditEngine->GetActiveView() );
     116             : 
     117           1 :     return bDone;
     118             : }
     119             : 
     120       49385 : EditUndo::EditUndo(sal_uInt16 nI, EditEngine* pEE) :
     121       49385 :     nId(nI), mpEditEngine(pEE)
     122             : {
     123       49385 : }
     124             : 
     125       47818 : EditUndo::~EditUndo()
     126             : {
     127       47818 : }
     128             : 
     129          12 : EditEngine* EditUndo::GetEditEngine()
     130             : {
     131          12 :     return mpEditEngine;
     132             : }
     133             : 
     134       49281 : sal_uInt16 EditUndo::GetId() const
     135             : {
     136       49281 :     return nId;
     137             : }
     138             : 
     139           0 : bool EditUndo::CanRepeat(SfxRepeatTarget&) const
     140             : {
     141           0 :     return false;
     142             : }
     143             : 
     144       49385 : OUString EditUndo::GetComment() const
     145             : {
     146       49385 :     OUString aComment;
     147             : 
     148       49385 :     if (mpEditEngine)
     149       49281 :         aComment = mpEditEngine->GetUndoComment( GetId() );
     150             : 
     151       49385 :     return aComment;
     152             : }
     153             : 
     154          10 : EditUndoDelContent::EditUndoDelContent(
     155             :     EditEngine* pEE, ContentNode* pNode, sal_Int32 nPortion) :
     156             :     EditUndo(EDITUNDO_DELCONTENT, pEE),
     157             :     bDelObject(true),
     158             :     nNode(nPortion),
     159          10 :     pContentNode(pNode) {}
     160             : 
     161          30 : EditUndoDelContent::~EditUndoDelContent()
     162             : {
     163          10 :     if ( bDelObject )
     164          10 :         delete pContentNode;
     165          20 : }
     166             : 
     167           0 : void EditUndoDelContent::Undo()
     168             : {
     169             :     DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
     170           0 :     GetEditEngine()->InsertContent( pContentNode, nNode );
     171           0 :     bDelObject = false; // belongs to the Engine again
     172           0 :     EditSelection aSel( EditPaM( pContentNode, 0 ), EditPaM( pContentNode, pContentNode->Len() ) );
     173           0 :     GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection(aSel);
     174           0 : }
     175             : 
     176           0 : void EditUndoDelContent::Redo()
     177             : {
     178             :     DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
     179             : 
     180           0 :     EditEngine* pEE = GetEditEngine();
     181             : 
     182             :     // pNode is no longer correct, if the paragraphs where merged
     183             :     // in between Undos
     184           0 :     pContentNode = pEE->GetEditDoc().GetObject( nNode );
     185             :     DBG_ASSERT( pContentNode, "EditUndoDelContent::Redo(): Node?!" );
     186             : 
     187           0 :     pEE->RemoveParaPortion(nNode);
     188             : 
     189             :     // Do not delete node, depends on the undo!
     190           0 :     pEE->GetEditDoc().Remove( nNode );
     191           0 :     if (pEE->IsCallParaInsertedOrDeleted())
     192           0 :         pEE->ParagraphDeleted( nNode );
     193             : 
     194           0 :     DeletedNodeInfo* pInf = new DeletedNodeInfo( (sal_uLong)pContentNode, nNode );
     195           0 :     pEE->AppendDeletedNodeInfo(pInf);
     196           0 :     pEE->UpdateSelections();
     197             : 
     198           0 :     ContentNode* pN = ( nNode < pEE->GetEditDoc().Count() )
     199           0 :         ? pEE->GetEditDoc().GetObject( nNode )
     200           0 :         : pEE->GetEditDoc().GetObject( nNode-1 );
     201             :     DBG_ASSERT( pN && ( pN != pContentNode ), "?! RemoveContent !? " );
     202           0 :     EditPaM aPaM( pN, pN->Len() );
     203             : 
     204           0 :     bDelObject = true;  // belongs to the Engine again
     205             : 
     206           0 :     pEE->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aPaM, aPaM ) );
     207           0 : }
     208             : 
     209         220 : EditUndoConnectParas::EditUndoConnectParas(
     210             :     EditEngine* pEE, sal_Int32 nN, sal_uInt16 nSP,
     211             :     const SfxItemSet& rLeftParaAttribs, const SfxItemSet& rRightParaAttribs,
     212             :     const SfxStyleSheet* pLeftStyle, const SfxStyleSheet* pRightStyle, bool bBkwrd) :
     213             :     EditUndo(EDITUNDO_CONNECTPARAS, pEE),
     214             :     aLeftParaAttribs(rLeftParaAttribs),
     215             :     aRightParaAttribs(rRightParaAttribs),
     216         220 :     bBackward(bBkwrd)
     217             : {
     218         220 :     nNode   = nN;
     219         220 :     nSepPos = nSP;
     220             : 
     221         220 :     if ( pLeftStyle )
     222             :     {
     223           2 :         aLeftStyleName = pLeftStyle->GetName();
     224           2 :         eLeftStyleFamily = pLeftStyle->GetFamily();
     225             :     }
     226         220 :     if ( pRightStyle )
     227             :     {
     228           2 :         aRightStyleName = pRightStyle->GetName();
     229           2 :         eRightStyleFamily = pRightStyle->GetFamily();
     230             :     }
     231         220 : }
     232             : 
     233         440 : EditUndoConnectParas::~EditUndoConnectParas()
     234             : {
     235         440 : }
     236             : 
     237           0 : void EditUndoConnectParas::Undo()
     238             : {
     239             :     DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
     240             : 
     241             :     // For SplitContent ParagraphInserted can not be called yet because the
     242             :     // Outliner relies on the attributes to initialize the depth
     243             : 
     244           0 :     sal_Bool bCall = GetEditEngine()->IsCallParaInsertedOrDeleted();
     245           0 :     GetEditEngine()->SetCallParaInsertedOrDeleted(false);
     246             : 
     247           0 :     EditPaM aPaM = GetEditEngine()->SplitContent(nNode, nSepPos);
     248           0 :     GetEditEngine()->SetParaAttribs( nNode, aLeftParaAttribs );
     249           0 :     GetEditEngine()->SetParaAttribs( nNode+1, aRightParaAttribs );
     250             : 
     251           0 :     GetEditEngine()->SetCallParaInsertedOrDeleted( bCall );
     252           0 :     if (GetEditEngine()->IsCallParaInsertedOrDeleted())
     253           0 :         GetEditEngine()->ParagraphInserted( nNode+1 );
     254             : 
     255           0 :     if (GetEditEngine()->GetStyleSheetPool())
     256             :     {
     257           0 :         if ( !aLeftStyleName.isEmpty() )
     258           0 :             GetEditEngine()->SetStyleSheet( nNode, (SfxStyleSheet*)GetEditEngine()->GetStyleSheetPool()->Find( aLeftStyleName, eLeftStyleFamily ) );
     259           0 :         if ( !aRightStyleName.isEmpty() )
     260           0 :             GetEditEngine()->SetStyleSheet( nNode+1, (SfxStyleSheet*)GetEditEngine()->GetStyleSheetPool()->Find( aRightStyleName, eRightStyleFamily ) );
     261             :     }
     262             : 
     263           0 :     GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aPaM, aPaM ) );
     264           0 : }
     265             : 
     266           0 : void EditUndoConnectParas::Redo()
     267             : {
     268             :     DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: Np Active View!" );
     269           0 :     EditPaM aPaM = GetEditEngine()->ConnectContents( nNode, bBackward );
     270             : 
     271           0 :     GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aPaM, aPaM ) );
     272           0 : }
     273             : 
     274         643 : EditUndoSplitPara::EditUndoSplitPara(
     275             :     EditEngine* pEE, sal_Int32 nN, sal_uInt16 nSP) :
     276             :     EditUndo(EDITUNDO_SPLITPARA, pEE),
     277         643 :     nNode(nN), nSepPos(nSP) {}
     278             : 
     279        1286 : EditUndoSplitPara::~EditUndoSplitPara() {}
     280             : 
     281           0 : void EditUndoSplitPara::Undo()
     282             : {
     283             :     DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
     284           0 :     EditPaM aPaM = GetEditEngine()->ConnectContents(nNode, false);
     285           0 :     GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aPaM, aPaM ) );
     286           0 : }
     287             : 
     288           0 : void EditUndoSplitPara::Redo()
     289             : {
     290             :     DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
     291           0 :     EditPaM aPaM = GetEditEngine()->SplitContent(nNode, nSepPos);
     292           0 :     GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aPaM, aPaM ) );
     293           0 : }
     294             : 
     295       15187 : EditUndoInsertChars::EditUndoInsertChars(
     296             :     EditEngine* pEE, const EPaM& rEPaM, const OUString& rStr) :
     297             :     EditUndo(EDITUNDO_INSERTCHARS, pEE),
     298             :     aEPaM(rEPaM),
     299       15187 :     aText(rStr) {}
     300             : 
     301           2 : void EditUndoInsertChars::Undo()
     302             : {
     303             :     DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
     304           2 :     EditPaM aPaM = GetEditEngine()->CreateEditPaM(aEPaM);
     305           2 :     EditSelection aSel( aPaM, aPaM );
     306           2 :     aSel.Max().SetIndex( aSel.Max().GetIndex() + aText.getLength() );
     307           2 :     EditPaM aNewPaM( GetEditEngine()->DeleteSelection(aSel) );
     308           2 :     GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aNewPaM, aNewPaM ) );
     309           2 : }
     310             : 
     311           1 : void EditUndoInsertChars::Redo()
     312             : {
     313             :     DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
     314           1 :     EditPaM aPaM = GetEditEngine()->CreateEditPaM(aEPaM);
     315           1 :     GetEditEngine()->InsertText(EditSelection(aPaM, aPaM), aText);
     316           1 :     EditPaM aNewPaM( aPaM );
     317           1 :     aNewPaM.SetIndex( aNewPaM.GetIndex() + aText.getLength() );
     318           1 :     GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( EditSelection( aPaM, aNewPaM ) );
     319           1 : }
     320             : 
     321           0 : bool EditUndoInsertChars::Merge( SfxUndoAction* pNextAction )
     322             : {
     323           0 :     EditUndoInsertChars* pNext = dynamic_cast<EditUndoInsertChars*>(pNextAction);
     324           0 :     if (!pNext)
     325           0 :         return false;
     326             : 
     327           0 :     if ( aEPaM.nPara != pNext->aEPaM.nPara )
     328           0 :         return false;
     329             : 
     330           0 :     if ( ( aEPaM.nIndex + aText.getLength() ) == pNext->aEPaM.nIndex )
     331             :     {
     332           0 :         aText += pNext->aText;
     333           0 :         return true;
     334             :     }
     335           0 :     return false;
     336             : }
     337             : 
     338         553 : EditUndoRemoveChars::EditUndoRemoveChars(
     339             :     EditEngine* pEE, const EPaM& rEPaM, const OUString& rStr) :
     340             :     EditUndo(EDITUNDO_REMOVECHARS, pEE),
     341         553 :     aEPaM(rEPaM), aText(rStr) {}
     342             : 
     343           1 : void EditUndoRemoveChars::Undo()
     344             : {
     345             :     DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: Keine Active View!" );
     346           1 :     EditPaM aPaM = GetEditEngine()->CreateEditPaM(aEPaM);
     347           1 :     EditSelection aSel( aPaM, aPaM );
     348           1 :     GetEditEngine()->InsertText(aSel, aText);
     349           1 :     aSel.Max().SetIndex( aSel.Max().GetIndex() + aText.getLength() );
     350           1 :     GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection(aSel);
     351           1 : }
     352             : 
     353           0 : void EditUndoRemoveChars::Redo()
     354             : {
     355             :     DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
     356           0 :     EditPaM aPaM = GetEditEngine()->CreateEditPaM(aEPaM);
     357           0 :     EditSelection aSel( aPaM, aPaM );
     358           0 :     aSel.Max().SetIndex( aSel.Max().GetIndex() + aText.getLength() );
     359           0 :     EditPaM aNewPaM = GetEditEngine()->DeleteSelection(aSel);
     360           0 :     GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection(aNewPaM);
     361           0 : }
     362             : 
     363        3160 : EditUndoInsertFeature::EditUndoInsertFeature(
     364             :     EditEngine* pEE, const EPaM& rEPaM, const SfxPoolItem& rFeature) :
     365        3160 :     EditUndo(EDITUNDO_INSERTFEATURE, pEE), aEPaM(rEPaM)
     366             : {
     367        3160 :     pFeature = rFeature.Clone();
     368             :     DBG_ASSERT( pFeature, "Feature could not be duplicated: EditUndoInsertFeature" );
     369        3160 : }
     370             : 
     371        9480 : EditUndoInsertFeature::~EditUndoInsertFeature()
     372             : {
     373        3160 :     delete pFeature;
     374        6320 : }
     375             : 
     376           0 : void EditUndoInsertFeature::Undo()
     377             : {
     378             :     DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
     379           0 :     EditPaM aPaM = GetEditEngine()->CreateEditPaM(aEPaM);
     380           0 :     EditSelection aSel( aPaM, aPaM );
     381             :     // Attributes are then corrected implicitly by the document ...
     382           0 :     aSel.Max().SetIndex( aSel.Max().GetIndex()+1 );
     383           0 :     GetEditEngine()->DeleteSelection(aSel);
     384           0 :     aSel.Max().SetIndex( aSel.Max().GetIndex()-1 ); // For Selection
     385           0 :     GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection(aSel);
     386           0 : }
     387             : 
     388           0 : void EditUndoInsertFeature::Redo()
     389             : {
     390             :     DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
     391           0 :     EditPaM aPaM = GetEditEngine()->CreateEditPaM(aEPaM);
     392           0 :     EditSelection aSel( aPaM, aPaM );
     393           0 :     GetEditEngine()->InsertFeature(aSel, *pFeature);
     394           0 :     if ( pFeature->Which() == EE_FEATURE_FIELD )
     395           0 :         GetEditEngine()->UpdateFieldsOnly();
     396           0 :     aSel.Max().SetIndex( aSel.Max().GetIndex()+1 );
     397           0 :     GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection(aSel);
     398           0 : }
     399             : 
     400           0 : EditUndoMoveParagraphs::EditUndoMoveParagraphs(
     401             :     EditEngine* pEE, const Range& rParas, sal_Int32 n) :
     402           0 :     EditUndo(EDITUNDO_MOVEPARAGRAPHS, pEE), nParagraphs(rParas), nDest(n) {}
     403             : 
     404           0 : EditUndoMoveParagraphs::~EditUndoMoveParagraphs() {}
     405             : 
     406           0 : void EditUndoMoveParagraphs::Undo()
     407             : {
     408             :     DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
     409           0 :     Range aTmpRange( nParagraphs );
     410           0 :     long nTmpDest = aTmpRange.Min();
     411             : 
     412           0 :     long nDiff = ( nDest - aTmpRange.Min() );
     413           0 :     aTmpRange.Min() += nDiff;
     414           0 :     aTmpRange.Max() += nDiff;
     415             : 
     416           0 :     if ( nParagraphs.Min() < (long)nDest )
     417             :     {
     418           0 :         long nLen = aTmpRange.Len();
     419           0 :         aTmpRange.Min() -= nLen;
     420           0 :         aTmpRange.Max() -= nLen;
     421             :     }
     422             :     else
     423           0 :         nTmpDest += aTmpRange.Len();
     424             : 
     425           0 :     EditSelection aNewSel = GetEditEngine()->MoveParagraphs(aTmpRange, nTmpDest, 0);
     426           0 :     GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( aNewSel );
     427           0 : }
     428             : 
     429           0 : void EditUndoMoveParagraphs::Redo()
     430             : {
     431             :     DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
     432           0 :     EditSelection aNewSel = GetEditEngine()->MoveParagraphs(nParagraphs, nDest, 0);
     433           0 :     GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( aNewSel );
     434           0 : }
     435             : 
     436        3056 : EditUndoSetStyleSheet::EditUndoSetStyleSheet(
     437             :     EditEngine* pEE, sal_Int32 nP, const OUString& rPrevName, SfxStyleFamily ePrevFam,
     438             :     const OUString& rNewName, SfxStyleFamily eNewFam, const SfxItemSet& rPrevParaAttribs) :
     439             :     EditUndo(EDITUNDO_STYLESHEET, pEE),
     440             :     aPrevName(rPrevName),
     441             :     aNewName(rNewName),
     442        3056 :     aPrevParaAttribs(rPrevParaAttribs)
     443             : {
     444        3056 :     ePrevFamily = ePrevFam;
     445        3056 :     eNewFamily = eNewFam;
     446        3056 :     nPara = nP;
     447        3056 : }
     448             : 
     449        6112 : EditUndoSetStyleSheet::~EditUndoSetStyleSheet()
     450             : {
     451        6112 : }
     452             : 
     453           0 : void EditUndoSetStyleSheet::Undo()
     454             : {
     455             :     DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
     456           0 :     GetEditEngine()->SetStyleSheet( nPara, (SfxStyleSheet*)GetEditEngine()->GetStyleSheetPool()->Find( aPrevName, ePrevFamily ) );
     457           0 :     GetEditEngine()->SetParaAttribsOnly( nPara, aPrevParaAttribs );
     458           0 :     lcl_DoSetSelection( GetEditEngine()->GetActiveView(), nPara );
     459           0 : }
     460             : 
     461           0 : void EditUndoSetStyleSheet::Redo()
     462             : {
     463             :     DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
     464           0 :     GetEditEngine()->SetStyleSheet( nPara, (SfxStyleSheet*)GetEditEngine()->GetStyleSheetPool()->Find( aNewName, eNewFamily ) );
     465           0 :     lcl_DoSetSelection( GetEditEngine()->GetActiveView(), nPara );
     466           0 : }
     467             : 
     468       22003 : EditUndoSetParaAttribs::EditUndoSetParaAttribs(
     469             :     EditEngine* pEE, sal_Int32 nP, const SfxItemSet& rPrevItems, const SfxItemSet& rNewItems) :
     470             :     EditUndo(EDITUNDO_PARAATTRIBS, pEE),
     471             :     nPara(nP),
     472             :     aPrevItems(rPrevItems),
     473       22003 :     aNewItems(rNewItems) {}
     474             : 
     475       43578 : EditUndoSetParaAttribs::~EditUndoSetParaAttribs() {}
     476             : 
     477           0 : void EditUndoSetParaAttribs::Undo()
     478             : {
     479             :     DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
     480           0 :     GetEditEngine()->SetParaAttribsOnly( nPara, aPrevItems );
     481           0 :     lcl_DoSetSelection( GetEditEngine()->GetActiveView(), nPara );
     482           0 : }
     483             : 
     484           0 : void EditUndoSetParaAttribs::Redo()
     485             : {
     486             :     DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
     487           0 :     GetEditEngine()->SetParaAttribsOnly( nPara, aNewItems );
     488           0 :     lcl_DoSetSelection( GetEditEngine()->GetActiveView(), nPara );
     489           0 : }
     490             : 
     491        4449 : EditUndoSetAttribs::EditUndoSetAttribs(EditEngine* pEE, const ESelection& rESel, const SfxItemSet& rNewItems) :
     492             :     EditUndo(EDITUNDO_ATTRIBS, pEE),
     493        4449 :     aESel(rESel), aNewAttribs(rNewItems)
     494             : {
     495             :     // When EditUndoSetAttribs actually is a RemoveAttribs this could be
     496             :     // /recognize by the empty itemset, but then it would have to be caught in
     497             :     // its own place, which possible a setAttribs does with an empty itemset.
     498        4449 :     bSetIsRemove = sal_False;
     499        4449 :     bRemoveParaAttribs = sal_False;
     500        4449 :     nRemoveWhich = 0;
     501        4449 :     nSpecial = 0;
     502        4449 : }
     503             : 
     504             : namespace {
     505             : 
     506             : struct RemoveAttribsFromPool : std::unary_function<ContentAttribsInfo, void>
     507             : {
     508             :     SfxItemPool& mrPool;
     509             : public:
     510        4449 :     RemoveAttribsFromPool(SfxItemPool& rPool) : mrPool(rPool) {}
     511        4818 :     void operator() (ContentAttribsInfo& rInfo)
     512             :     {
     513        4818 :         rInfo.RemoveAllCharAttribsFromPool(mrPool);
     514        4818 :     }
     515             : };
     516             : 
     517             : }
     518             : 
     519       13347 : EditUndoSetAttribs::~EditUndoSetAttribs()
     520             : {
     521             :     // Get Items from Pool...
     522        4449 :     SfxItemPool* pPool = aNewAttribs.GetPool();
     523        4449 :     std::for_each(aPrevAttribs.begin(), aPrevAttribs.end(), RemoveAttribsFromPool(*pPool));
     524        8898 : }
     525             : 
     526           0 : void EditUndoSetAttribs::Undo()
     527             : {
     528             :     DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
     529           0 :     EditEngine* pEE = GetEditEngine();
     530           0 :     bool bFields = false;
     531           0 :     for ( sal_Int32 nPara = aESel.nStartPara; nPara <= aESel.nEndPara; nPara++ )
     532             :     {
     533           0 :         const ContentAttribsInfo& rInf = aPrevAttribs[nPara-aESel.nStartPara];
     534             : 
     535             :         // first the paragraph attributes ...
     536           0 :         pEE->SetParaAttribsOnly(nPara, rInf.GetPrevParaAttribs());
     537             : 
     538             :         // Then the character attributes ...
     539             :         // Remove all attributes including features, are later re-established.
     540           0 :         pEE->RemoveCharAttribs(nPara, 0, true);
     541             :         DBG_ASSERT( pEE->GetEditDoc().GetObject( nPara ), "Undo (SetAttribs): pNode = NULL!" );
     542           0 :         ContentNode* pNode = pEE->GetEditDoc().GetObject( nPara );
     543           0 :         for (size_t nAttr = 0; nAttr < rInf.GetPrevCharAttribs().size(); ++nAttr)
     544             :         {
     545           0 :             const EditCharAttrib& rX = rInf.GetPrevCharAttribs()[nAttr];
     546             :             // is automatically "poolsized"
     547           0 :             pEE->GetEditDoc().InsertAttrib(pNode, rX.GetStart(), rX.GetEnd(), *rX.GetItem());
     548           0 :             if (rX.Which() == EE_FEATURE_FIELD)
     549           0 :                 bFields = true;
     550             :         }
     551             :     }
     552           0 :     if ( bFields )
     553           0 :         pEE->UpdateFieldsOnly();
     554           0 :     ImpSetSelection(pEE->GetActiveView());
     555           0 : }
     556             : 
     557           0 : void EditUndoSetAttribs::Redo()
     558             : {
     559             :     DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
     560           0 :     EditEngine* pEE = GetEditEngine();
     561             : 
     562           0 :     EditSelection aSel = pEE->CreateSelection(aESel);
     563           0 :     if ( !bSetIsRemove )
     564           0 :         pEE->SetAttribs( aSel, aNewAttribs, nSpecial );
     565             :     else
     566           0 :         pEE->RemoveCharAttribs( aSel, bRemoveParaAttribs, nRemoveWhich );
     567             : 
     568           0 :     ImpSetSelection( GetEditEngine()->GetActiveView() );
     569           0 : }
     570             : 
     571        4818 : void EditUndoSetAttribs::AppendContentInfo(ContentAttribsInfo* pNew)
     572             : {
     573        4818 :     aPrevAttribs.push_back(pNew);
     574        4818 : }
     575             : 
     576           0 : void EditUndoSetAttribs::ImpSetSelection( EditView* /*pView*/ )
     577             : {
     578           0 :     EditEngine* pEE = GetEditEngine();
     579           0 :     EditSelection aSel = pEE->CreateSelection(aESel);
     580           0 :     pEE->GetActiveView()->GetImpEditView()->SetEditSelection(aSel);
     581           0 : }
     582             : 
     583           0 : EditUndoTransliteration::EditUndoTransliteration(EditEngine* pEE, const ESelection& rESel, sal_Int32 nM) :
     584             :     EditUndo(EDITUNDO_TRANSLITERATE, pEE),
     585           0 :     aOldESel(rESel), nMode(nM), pTxtObj(NULL) {}
     586             : 
     587           0 : EditUndoTransliteration::~EditUndoTransliteration()
     588             : {
     589           0 :     delete pTxtObj;
     590           0 : }
     591             : 
     592           0 : void EditUndoTransliteration::Undo()
     593             : {
     594             :     DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
     595             : 
     596           0 :     EditEngine* pEE = GetEditEngine();
     597             : 
     598           0 :     EditSelection aSel = pEE->CreateSelection(aNewESel);
     599             : 
     600             :     // Insert text, but don't expand Atribs at the current position:
     601           0 :     aSel = pEE->DeleteSelected( aSel );
     602           0 :     EditSelection aDelSel( aSel );
     603           0 :     aSel = pEE->InsertParaBreak( aSel );
     604           0 :     aDelSel.Max() = aSel.Min();
     605           0 :     aDelSel.Max().GetNode()->GetCharAttribs().DeleteEmptyAttribs( pEE->GetEditDoc().GetItemPool() );
     606           0 :     EditSelection aNewSel;
     607           0 :     if ( pTxtObj )
     608             :     {
     609           0 :         aNewSel = pEE->InsertText( *pTxtObj, aSel );
     610             :     }
     611             :     else
     612             :     {
     613           0 :         aNewSel = pEE->InsertText( aSel, aText );
     614             :     }
     615           0 :     if ( aNewSel.Min().GetNode() == aDelSel.Max().GetNode() )
     616             :     {
     617           0 :         aNewSel.Min().SetNode( aDelSel.Min().GetNode() );
     618           0 :         aNewSel.Min().SetIndex( aNewSel.Min().GetIndex() + aDelSel.Min().GetIndex() );
     619             :     }
     620           0 :     if ( aNewSel.Max().GetNode() == aDelSel.Max().GetNode() )
     621             :     {
     622           0 :         aNewSel.Max().SetNode( aDelSel.Min().GetNode() );
     623           0 :         aNewSel.Max().SetIndex( aNewSel.Max().GetIndex() + aDelSel.Min().GetIndex() );
     624             :     }
     625           0 :     pEE->DeleteSelected( aDelSel );
     626           0 :     pEE->GetActiveView()->GetImpEditView()->SetEditSelection( aNewSel );
     627           0 : }
     628             : 
     629           0 : void EditUndoTransliteration::Redo()
     630             : {
     631             :     DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
     632           0 :     EditEngine* pEE = GetEditEngine();
     633             : 
     634           0 :     EditSelection aSel = pEE->CreateSelection(aOldESel);
     635           0 :     EditSelection aNewSel = pEE->TransliterateText( aSel, nMode );
     636           0 :     pEE->GetActiveView()->GetImpEditView()->SetEditSelection( aNewSel );
     637           0 : }
     638             : 
     639           0 : EditUndoMarkSelection::EditUndoMarkSelection(EditEngine* pEE, const ESelection& rSel) :
     640           0 :     EditUndo(EDITUNDO_MARKSELECTION, pEE), aSelection(rSel) {}
     641             : 
     642           0 : EditUndoMarkSelection::~EditUndoMarkSelection() {}
     643             : 
     644           0 : void EditUndoMarkSelection::Undo()
     645             : {
     646             :     DBG_ASSERT( GetEditEngine()->GetActiveView(), "Undo/Redo: No Active View!" );
     647           0 :     if ( GetEditEngine()->GetActiveView() )
     648             :     {
     649           0 :         if ( GetEditEngine()->IsFormatted() )
     650           0 :             GetEditEngine()->GetActiveView()->SetSelection( aSelection );
     651             :         else
     652           0 :             GetEditEngine()->GetActiveView()->GetImpEditView()->SetEditSelection( GetEditEngine()->CreateSelection(aSelection) );
     653             :     }
     654           0 : }
     655             : 
     656           0 : void EditUndoMarkSelection::Redo()
     657             : {
     658             :     // For redo unimportant, because at the beginning of the undo parentheses
     659           0 : }
     660             : 
     661             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10