LCOV - code coverage report
Current view: top level - vcl/source/edit - textundo.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 151 0.0 %
Date: 2012-08-25 Functions: 0 64 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 148 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <vcl/texteng.hxx>
      31                 :            : #include <vcl/textview.hxx>
      32                 :            : #include <textundo.hxx>
      33                 :            : #include <textund2.hxx>
      34                 :            : #include <vcl/textdata.hxx>
      35                 :            : #include <textdoc.hxx>
      36                 :            : #include <textdat2.hxx>
      37                 :            : 
      38 [ #  # ][ #  # ]:          0 : TYPEINIT1( TextUndo, SfxUndoAction );
      39 [ #  # ][ #  # ]:          0 : TYPEINIT1( TextUndoDelPara, TextUndo );
      40 [ #  # ][ #  # ]:          0 : TYPEINIT1( TextUndoConnectParas, TextUndo );
      41 [ #  # ][ #  # ]:          0 : TYPEINIT1( TextUndoSplitPara, TextUndo );
      42 [ #  # ][ #  # ]:          0 : TYPEINIT1( TextUndoInsertChars, TextUndo );
      43 [ #  # ][ #  # ]:          0 : TYPEINIT1( TextUndoRemoveChars, TextUndo );
      44                 :            : 
      45                 :            : 
      46                 :          0 : TextUndoManager::TextUndoManager( TextEngine* p )
      47                 :            : {
      48                 :          0 :     mpTextEngine = p;
      49                 :          0 : }
      50                 :            : 
      51                 :          0 : TextUndoManager::~TextUndoManager()
      52                 :            : {
      53         [ #  # ]:          0 : }
      54                 :            : 
      55                 :          0 : sal_Bool TextUndoManager::Undo()
      56                 :            : {
      57         [ #  # ]:          0 :     if ( GetUndoActionCount() == 0 )
      58                 :          0 :         return sal_False;
      59                 :            : 
      60                 :          0 :     UndoRedoStart();
      61                 :            : 
      62                 :          0 :     mpTextEngine->SetIsInUndo( sal_True );
      63                 :          0 :     sal_Bool bDone = SfxUndoManager::Undo();
      64                 :          0 :     mpTextEngine->SetIsInUndo( sal_False );
      65                 :            : 
      66                 :          0 :     UndoRedoEnd();
      67                 :            : 
      68                 :          0 :     return bDone;
      69                 :            : }
      70                 :            : 
      71                 :          0 : sal_Bool TextUndoManager::Redo()
      72                 :            : {
      73         [ #  # ]:          0 :     if ( GetRedoActionCount() == 0 )
      74                 :          0 :         return sal_False;
      75                 :            : 
      76                 :            : 
      77                 :          0 :     UndoRedoStart();
      78                 :            : 
      79                 :          0 :     mpTextEngine->SetIsInUndo( sal_True );
      80                 :          0 :     sal_Bool bDone = SfxUndoManager::Redo();
      81                 :          0 :     mpTextEngine->SetIsInUndo( sal_False );
      82                 :            : 
      83                 :          0 :     UndoRedoEnd();
      84                 :            : 
      85                 :          0 :     return bDone;
      86                 :            : }
      87                 :            : 
      88                 :          0 : void TextUndoManager::UndoRedoStart()
      89                 :            : {
      90                 :            :     DBG_ASSERT( GetView(), "Undo/Redo: Active View?" );
      91                 :            : 
      92                 :            : //  if ( GetView() )
      93                 :            : //      GetView()->HideSelection();
      94                 :          0 : }
      95                 :            : 
      96                 :          0 : void TextUndoManager::UndoRedoEnd()
      97                 :            : {
      98         [ #  # ]:          0 :     if ( GetView() )
      99                 :            :     {
     100 [ #  # ][ #  # ]:          0 :         TextSelection aNewSel( GetView()->GetSelection() );
     101                 :          0 :         aNewSel.GetStart() = aNewSel.GetEnd();
     102 [ #  # ][ #  # ]:          0 :         GetView()->ImpSetSelection( aNewSel );
     103                 :            :     }
     104                 :            : 
     105                 :          0 :     mpTextEngine->UpdateSelections();
     106                 :            : 
     107                 :          0 :     mpTextEngine->FormatAndUpdate( GetView() );
     108                 :          0 : }
     109                 :            : 
     110                 :            : 
     111                 :          0 : TextUndo::TextUndo( TextEngine* p )
     112                 :            : {
     113                 :          0 :     mpTextEngine = p;
     114                 :          0 : }
     115                 :            : 
     116                 :          0 : TextUndo::~TextUndo()
     117                 :            : {
     118         [ #  # ]:          0 : }
     119                 :            : 
     120                 :          0 : rtl::OUString TextUndo::GetComment() const
     121                 :            : {
     122                 :          0 :     return rtl::OUString();
     123                 :            : }
     124                 :            : 
     125                 :          0 : void TextUndo::SetSelection( const TextSelection& rSel )
     126                 :            : {
     127         [ #  # ]:          0 :     if ( GetView() )
     128                 :          0 :         GetView()->ImpSetSelection( rSel );
     129                 :          0 : }
     130                 :            : 
     131                 :            : 
     132                 :          0 : TextUndoDelPara::TextUndoDelPara( TextEngine* pTextEngine, TextNode* pNode, sal_uLong nPara )
     133                 :          0 :                     : TextUndo( pTextEngine )
     134                 :            : {
     135                 :          0 :     mpNode = pNode;
     136                 :          0 :     mnPara = nPara;
     137                 :          0 :     mbDelObject = sal_True;
     138                 :          0 : }
     139                 :            : 
     140                 :          0 : TextUndoDelPara::~TextUndoDelPara()
     141                 :            : {
     142         [ #  # ]:          0 :     if ( mbDelObject )
     143 [ #  # ][ #  # ]:          0 :         delete mpNode;
     144         [ #  # ]:          0 : }
     145                 :            : 
     146                 :          0 : void TextUndoDelPara::Undo()
     147                 :            : {
     148                 :          0 :     GetTextEngine()->InsertContent( mpNode, mnPara );
     149                 :          0 :     mbDelObject = sal_False;    // gehoert wieder der Engine
     150                 :            : 
     151         [ #  # ]:          0 :     if ( GetView() )
     152                 :            :     {
     153         [ #  # ]:          0 :         TextSelection aSel( TextPaM( mnPara, 0 ), TextPaM( mnPara, mpNode->GetText().Len() ) );
     154         [ #  # ]:          0 :         SetSelection( aSel );
     155                 :            :     }
     156                 :          0 : }
     157                 :            : 
     158                 :          0 : void TextUndoDelPara::Redo()
     159                 :            : {
     160                 :            :     // pNode stimmt nicht mehr, falls zwischendurch Undos, in denen
     161                 :            :     // Absaetze verschmolzen sind.
     162         [ #  # ]:          0 :     mpNode = GetDoc()->GetNodes().GetObject( mnPara );
     163                 :            : 
     164 [ #  # ][ #  # ]:          0 :     delete GetTEParaPortions()->GetObject( mnPara );
                 [ #  # ]
     165         [ #  # ]:          0 :     GetTEParaPortions()->Remove( mnPara );
     166                 :            : 
     167                 :            :     // Node nicht loeschen, haengt im Undo!
     168         [ #  # ]:          0 :     GetDoc()->GetNodes().Remove( mnPara );
     169         [ #  # ]:          0 :     GetTextEngine()->ImpParagraphRemoved( mnPara );
     170                 :            : 
     171                 :          0 :     mbDelObject = sal_True; // gehoert wieder dem Undo
     172                 :            : 
     173                 :          0 :     sal_uLong nParas = GetDoc()->GetNodes().Count();
     174         [ #  # ]:          0 :     sal_uLong n = mnPara < nParas ? mnPara : (nParas-1);
     175         [ #  # ]:          0 :     TextNode* pN = GetDoc()->GetNodes().GetObject( n );
     176                 :          0 :     TextPaM aPaM( n, pN->GetText().Len() );
     177 [ #  # ][ #  # ]:          0 :     SetSelection( aPaM );
     178                 :          0 : }
     179                 :            : 
     180                 :            : // -----------------------------------------------------------------------
     181                 :            : // TextUndoConnectParas
     182                 :            : // ------------------------------------------------------------------------
     183                 :          0 : TextUndoConnectParas::TextUndoConnectParas( TextEngine* pTextEngine, sal_uLong nPara, sal_uInt16 nPos )
     184                 :          0 :                     :   TextUndo( pTextEngine )
     185                 :            : {
     186                 :          0 :     mnPara = nPara;
     187                 :          0 :     mnSepPos = nPos;
     188                 :          0 : }
     189                 :            : 
     190                 :          0 : TextUndoConnectParas::~TextUndoConnectParas()
     191                 :            : {
     192         [ #  # ]:          0 : }
     193                 :            : 
     194                 :          0 : void TextUndoConnectParas::Undo()
     195                 :            : {
     196         [ #  # ]:          0 :     TextPaM aPaM = GetTextEngine()->SplitContent( mnPara, mnSepPos );
     197 [ #  # ][ #  # ]:          0 :     SetSelection( aPaM );
     198                 :          0 : }
     199                 :            : 
     200                 :          0 : void TextUndoConnectParas::Redo()
     201                 :            : {
     202         [ #  # ]:          0 :     TextPaM aPaM = GetTextEngine()->ConnectContents( mnPara );
     203 [ #  # ][ #  # ]:          0 :     SetSelection( aPaM );
     204                 :          0 : }
     205                 :            : 
     206                 :            : 
     207                 :          0 : TextUndoSplitPara::TextUndoSplitPara( TextEngine* pTextEngine, sal_uLong nPara, sal_uInt16 nPos )
     208                 :          0 :                     : TextUndo( pTextEngine )
     209                 :            : {
     210                 :          0 :     mnPara = nPara;
     211                 :          0 :     mnSepPos = nPos;
     212                 :          0 : }
     213                 :            : 
     214                 :          0 : TextUndoSplitPara::~TextUndoSplitPara()
     215                 :            : {
     216         [ #  # ]:          0 : }
     217                 :            : 
     218                 :          0 : void TextUndoSplitPara::Undo()
     219                 :            : {
     220         [ #  # ]:          0 :     TextPaM aPaM = GetTextEngine()->ConnectContents( mnPara );
     221 [ #  # ][ #  # ]:          0 :     SetSelection( aPaM );
     222                 :          0 : }
     223                 :            : 
     224                 :          0 : void TextUndoSplitPara::Redo()
     225                 :            : {
     226         [ #  # ]:          0 :     TextPaM aPaM = GetTextEngine()->SplitContent( mnPara, mnSepPos );
     227 [ #  # ][ #  # ]:          0 :     SetSelection( aPaM );
     228                 :          0 : }
     229                 :            : 
     230                 :            : 
     231                 :          0 : TextUndoInsertChars::TextUndoInsertChars( TextEngine* pTextEngine, const TextPaM& rTextPaM, const XubString& rStr )
     232                 :            :                     : TextUndo( pTextEngine ),
     233         [ #  # ]:          0 :                         maTextPaM( rTextPaM ), maText( rStr )
     234                 :            : {
     235                 :          0 : }
     236                 :            : 
     237                 :          0 : void TextUndoInsertChars::Undo()
     238                 :            : {
     239         [ #  # ]:          0 :     TextSelection aSel( maTextPaM, maTextPaM );
     240                 :          0 :     aSel.GetEnd().GetIndex() = aSel.GetEnd().GetIndex() + maText.Len();
     241         [ #  # ]:          0 :     TextPaM aPaM = GetTextEngine()->ImpDeleteText( aSel );
     242 [ #  # ][ #  # ]:          0 :     SetSelection( aPaM );
     243                 :          0 : }
     244                 :            : 
     245                 :          0 : void TextUndoInsertChars::Redo()
     246                 :            : {
     247         [ #  # ]:          0 :     TextSelection aSel( maTextPaM, maTextPaM );
     248         [ #  # ]:          0 :     GetTextEngine()->ImpInsertText( aSel, maText );
     249                 :          0 :     TextPaM aNewPaM( maTextPaM );
     250                 :          0 :     aNewPaM.GetIndex() = aNewPaM.GetIndex() + maText.Len();
     251 [ #  # ][ #  # ]:          0 :     SetSelection( TextSelection( aSel.GetStart(), aNewPaM ) );
     252                 :          0 : }
     253                 :            : 
     254                 :          0 : sal_Bool TextUndoInsertChars::Merge( SfxUndoAction* pNextAction )
     255                 :            : {
     256         [ #  # ]:          0 :     if ( !pNextAction->ISA( TextUndoInsertChars ) )
     257                 :          0 :         return sal_False;
     258                 :            : 
     259                 :          0 :     TextUndoInsertChars* pNext = (TextUndoInsertChars*)pNextAction;
     260                 :            : 
     261         [ #  # ]:          0 :     if ( maTextPaM.GetPara() != pNext->maTextPaM.GetPara() )
     262                 :          0 :         return sal_False;
     263                 :            : 
     264         [ #  # ]:          0 :     if ( ( maTextPaM.GetIndex() + maText.Len() ) == pNext->maTextPaM.GetIndex() )
     265                 :            :     {
     266                 :          0 :         maText += pNext->maText;
     267                 :          0 :         return sal_True;
     268                 :            :     }
     269                 :          0 :     return sal_False;
     270                 :            : }
     271                 :            : 
     272                 :            : 
     273                 :          0 : TextUndoRemoveChars::TextUndoRemoveChars( TextEngine* pTextEngine, const TextPaM& rTextPaM, const XubString& rStr )
     274                 :            :                     : TextUndo( pTextEngine ),
     275         [ #  # ]:          0 :                         maTextPaM( rTextPaM ), maText( rStr )
     276                 :            : {
     277                 :          0 : }
     278                 :            : 
     279                 :          0 : void TextUndoRemoveChars::Undo()
     280                 :            : {
     281         [ #  # ]:          0 :     TextSelection aSel( maTextPaM, maTextPaM );
     282         [ #  # ]:          0 :     GetTextEngine()->ImpInsertText( aSel, maText );
     283                 :          0 :     aSel.GetEnd().GetIndex() = aSel.GetEnd().GetIndex() + maText.Len();
     284         [ #  # ]:          0 :     SetSelection( aSel );
     285                 :          0 : }
     286                 :            : 
     287                 :          0 : void TextUndoRemoveChars::Redo()
     288                 :            : {
     289         [ #  # ]:          0 :     TextSelection aSel( maTextPaM, maTextPaM );
     290                 :          0 :     aSel.GetEnd().GetIndex() = aSel.GetEnd().GetIndex() + maText.Len();
     291         [ #  # ]:          0 :     TextPaM aPaM = GetTextEngine()->ImpDeleteText( aSel );
     292 [ #  # ][ #  # ]:          0 :     SetSelection( aPaM );
     293                 :          0 : }
     294                 :            : 
     295                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10