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

Generated by: LCOV version 1.11