LCOV - code coverage report
Current view: top level - sw/source/core/edit - eddel.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 150 0.0 %
Date: 2012-08-25 Functions: 0 5 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 320 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                 :            : #include <hintids.hxx>
      30                 :            : #include <doc.hxx>
      31                 :            : #include <IDocumentUndoRedo.hxx>
      32                 :            : #include <editsh.hxx>
      33                 :            : #include <cntfrm.hxx>
      34                 :            : #include <pam.hxx>
      35                 :            : #include <swundo.hxx>       // fuer die UndoIds
      36                 :            : #include <edimp.hxx>
      37                 :            : #include <IMark.hxx>
      38                 :            : #include <docary.hxx>
      39                 :            : #include <SwRewriter.hxx>
      40                 :            : #include <globals.hrc>
      41                 :            : 
      42                 :            : #include <comcore.hrc>
      43                 :            : #include <list>
      44                 :            : 
      45                 :            : /************************************************************
      46                 :            :  * Loeschen
      47                 :            :  ************************************************************/
      48                 :            : 
      49                 :          0 : void SwEditShell::DeleteSel( SwPaM& rPam, sal_Bool* pUndo )
      50                 :            : {
      51                 :            :     // nur bei Selektion
      52 [ #  # ][ #  # ]:          0 :     if( !rPam.HasMark() || *rPam.GetPoint() == *rPam.GetMark())
                 [ #  # ]
      53                 :          0 :         return;
      54                 :            : 
      55                 :            :     // besteht eine Selection in einer Tabelle ?
      56                 :            :     // dann nur den Inhalt der selektierten Boxen loeschen
      57                 :            :     // jetzt gibt es 2 Faelle die beachtet werden muessen:
      58                 :            :     //  1. Point und Mark stehen in einer Box, Selection normal loeschen
      59                 :            :     //  2. Point und Mark stehen in unterschiedlichen Boxen, alle
      60                 :            :     // selektierten Boxen suchen in den Inhalt loeschen
      61   [ #  #  #  # ]:          0 :     if( rPam.GetNode()->FindTableNode() &&
                 [ #  # ]
      62                 :          0 :         rPam.GetNode()->StartOfSectionNode() !=
      63                 :          0 :         rPam.GetNode(sal_False)->StartOfSectionNode() )
      64                 :            :     {
      65                 :            :         // in Tabellen das Undo gruppieren
      66 [ #  # ][ #  # ]:          0 :         if( pUndo && !*pUndo )
      67                 :            :         {
      68 [ #  # ][ #  # ]:          0 :             GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
      69                 :          0 :             *pUndo = sal_True;
      70                 :            :         }
      71 [ #  # ][ #  # ]:          0 :         SwPaM aDelPam( *rPam.Start() );
      72         [ #  # ]:          0 :         const SwPosition* pEndSelPos = rPam.End();
      73         [ #  # ]:          0 :         do {
      74         [ #  # ]:          0 :             aDelPam.SetMark();
      75                 :          0 :             SwNode* pNd = aDelPam.GetNode();
      76                 :          0 :             const SwNode& rEndNd = *pNd->EndOfSectionNode();
      77         [ #  # ]:          0 :             if( pEndSelPos->nNode.GetIndex() <= rEndNd.GetIndex() )
      78                 :            :             {
      79         [ #  # ]:          0 :                 *aDelPam.GetPoint() = *pEndSelPos;
      80                 :          0 :                 pEndSelPos = 0;     // Pointer als Flag missbrauchen
      81                 :            :             }
      82                 :            :             else
      83                 :            :             {
      84                 :            :                 // dann ans Ende der Section
      85         [ #  # ]:          0 :                 aDelPam.GetPoint()->nNode = rEndNd;
      86         [ #  # ]:          0 :                 aDelPam.Move( fnMoveBackward, fnGoCntnt );
      87                 :            :             }
      88                 :            :                 // geschuetze Boxen ueberspringen !
      89 [ #  # ][ #  # ]:          0 :             if( !pNd->IsCntntNode() ||
                 [ #  # ]
      90         [ #  # ]:          0 :                 !pNd->IsInProtectSect() )
      91                 :            :             {
      92                 :            :                 // alles loeschen
      93         [ #  # ]:          0 :                 GetDoc()->DeleteAndJoin( aDelPam );
      94         [ #  # ]:          0 :                 SaveTblBoxCntnt( aDelPam.GetPoint() );
      95                 :            :             }
      96                 :            : 
      97         [ #  # ]:          0 :             if( !pEndSelPos )               // am Ende der Selection
      98                 :          0 :                 break;
      99         [ #  # ]:          0 :             aDelPam.DeleteMark();
     100         [ #  # ]:          0 :             aDelPam.Move( fnMoveForward, fnGoCntnt );   // naechste Box
     101         [ #  # ]:          0 :         } while( pEndSelPos );
     102                 :            :     }
     103                 :            :     else
     104                 :            :     {
     105                 :            :             // alles loeschen
     106                 :          0 :         GetDoc()->DeleteAndJoin( rPam );
     107                 :          0 :         SaveTblBoxCntnt( rPam.GetPoint() );
     108                 :            :     }
     109                 :            : 
     110                 :            :     // Selection wird nicht mehr benoetigt.
     111                 :          0 :     rPam.DeleteMark();
     112                 :            : }
     113                 :            : 
     114                 :            : 
     115                 :          0 : long SwEditShell::Delete()
     116                 :            : {
     117         [ #  # ]:          0 :     SET_CURR_SHELL( this );
     118                 :          0 :     long nRet = 0;
     119 [ #  # ][ #  # ]:          0 :     if( !HasReadonlySel() )
     120                 :            :     {
     121         [ #  # ]:          0 :         StartAllAction();
     122                 :            : 
     123 [ #  # ][ #  # ]:          0 :         sal_Bool bUndo = GetCrsr()->GetNext() != GetCrsr();
     124         [ #  # ]:          0 :         if( bUndo )     // mehr als eine Selection ?
     125                 :            :         {
     126         [ #  # ]:          0 :             SwRewriter aRewriter;
     127 [ #  # ][ #  # ]:          0 :             aRewriter.AddRule(UndoArg1, SW_RESSTR(STR_MULTISEL));
         [ #  # ][ #  # ]
     128                 :            : 
     129 [ #  # ][ #  # ]:          0 :             GetDoc()->GetIDocumentUndoRedo().StartUndo(UNDO_DELETE, &aRewriter);
                 [ #  # ]
     130                 :            :         }
     131                 :            : 
     132 [ #  # ][ #  # ]:          0 :         FOREACHPAM_START(this)
     133         [ #  # ]:          0 :             DeleteSel( *PCURCRSR, &bUndo );
     134                 :          0 :         FOREACHPAM_END()
     135                 :            : 
     136                 :            :         // falls eine Undo-Klammerung, dann hier beenden
     137         [ #  # ]:          0 :         if( bUndo )
     138                 :            :         {
     139 [ #  # ][ #  # ]:          0 :             GetDoc()->GetIDocumentUndoRedo().EndUndo(UNDO_END, 0);
     140                 :            :         }
     141         [ #  # ]:          0 :         EndAllAction();
     142                 :          0 :         nRet = 1;
     143                 :            :     }
     144         [ #  # ]:          0 :     return nRet;
     145                 :            : }
     146                 :            : 
     147                 :          0 : long SwEditShell::Copy( SwEditShell* pDestShell )
     148                 :            : {
     149         [ #  # ]:          0 :     if( !pDestShell )
     150                 :          0 :         pDestShell = this;
     151                 :            : 
     152         [ #  # ]:          0 :     SET_CURR_SHELL( pDestShell );
     153                 :            : 
     154                 :            :     // List of insert positions for smart insert of block selections
     155         [ #  # ]:          0 :     std::list< boost::shared_ptr<SwPosition> > aInsertList;
     156                 :            : 
     157                 :            :     // Fill list of insert positions
     158                 :            :     {
     159                 :          0 :         SwPosition * pPos = 0;
     160         [ #  # ]:          0 :         boost::shared_ptr<SwPosition> pInsertPos;
     161                 :          0 :         sal_uInt16 nMove = 0;
     162 [ #  # ][ #  # ]:          0 :         FOREACHPAM_START(this)
     163                 :            : 
     164         [ #  # ]:          0 :             if( !pPos )
     165                 :            :             {
     166         [ #  # ]:          0 :                 if( pDestShell == this )
     167                 :            :                 {
     168                 :            :                     // First cursor represents the target position!!
     169         [ #  # ]:          0 :                     PCURCRSR->DeleteMark();
     170                 :          0 :                     pPos = (SwPosition*)PCURCRSR->GetPoint();
     171                 :          0 :                     continue;
     172                 :            :                 }
     173                 :            :                 else
     174         [ #  # ]:          0 :                     pPos = pDestShell->GetCrsr()->GetPoint();
     175                 :            :             }
     176         [ #  # ]:          0 :             if( IsBlockMode() )
     177                 :            :             {   // In block mode different insert positions will be calculated
     178                 :            :                 // by simulated cursor movements from the given first insert position
     179         [ #  # ]:          0 :                 if( nMove )
     180                 :            :                 {
     181         [ #  # ]:          0 :                     SwCursor aCrsr( *pPos, 0, false);
     182 [ #  # ][ #  # ]:          0 :                     if( aCrsr.UpDown( sal_False, nMove, 0, 0 ) )
     183                 :            :                     {
     184 [ #  # ][ #  # ]:          0 :                         pInsertPos.reset( new SwPosition( *aCrsr.GetPoint() ) );
                 [ #  # ]
     185         [ #  # ]:          0 :                         aInsertList.push_back( pInsertPos );
     186         [ #  # ]:          0 :                     }
     187                 :            :                 }
     188                 :            :                 else
     189 [ #  # ][ #  # ]:          0 :                     pInsertPos.reset( new SwPosition( *pPos ) );
                 [ #  # ]
     190                 :          0 :                 ++nMove;
     191                 :            :             }
     192         [ #  # ]:          0 :             SwPosition *pTmp = IsBlockMode() ? pInsertPos.get() : pPos;
     193                 :            :             // Check if a selection would be copied into itself
     194 [ #  # ][ #  # ]:          0 :             if( pDestShell->GetDoc() == GetDoc() &&
         [ #  # ][ #  # ]
     195 [ #  # ][ #  # ]:          0 :                 *PCURCRSR->Start() <= *pTmp && *pTmp < *PCURCRSR->End() )
         [ #  # ][ #  # ]
     196                 :          0 :                 return sal_False;
     197 [ #  # ][ #  # ]:          0 :         FOREACHPAM_END()
     198                 :            :     }
     199                 :            : 
     200         [ #  # ]:          0 :     pDestShell->StartAllAction();
     201                 :          0 :     SwPosition *pPos = 0;
     202                 :          0 :     sal_Bool bRet = sal_False;
     203                 :          0 :     sal_Bool bFirstMove = sal_True;
     204 [ #  # ][ #  # ]:          0 :     SwNodeIndex aSttNdIdx( pDestShell->GetDoc()->GetNodes() );
     205                 :          0 :     xub_StrLen nSttCntIdx = 0;
     206                 :            :     // For block selection this list is filled with the insert positions
     207                 :          0 :     std::list< boost::shared_ptr<SwPosition> >::iterator pNextInsert = aInsertList.begin();
     208                 :            : 
     209 [ #  # ][ #  # ]:          0 :     pDestShell->GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
     210 [ #  # ][ #  # ]:          0 :     FOREACHPAM_START(this)
     211                 :            : 
     212         [ #  # ]:          0 :         if( !pPos )
     213                 :            :         {
     214         [ #  # ]:          0 :             if( pDestShell == this )
     215                 :            :             {
     216                 :            :                 // First cursor represents the target position!!
     217         [ #  # ]:          0 :                 PCURCRSR->DeleteMark();
     218                 :          0 :                 pPos = (SwPosition*)PCURCRSR->GetPoint();
     219                 :          0 :                 continue;
     220                 :            :             }
     221                 :            :             else
     222         [ #  # ]:          0 :                 pPos = pDestShell->GetCrsr()->GetPoint();
     223                 :            :         }
     224         [ #  # ]:          0 :         if( !bFirstMove )
     225                 :            :         {
     226         [ #  # ]:          0 :             if( pNextInsert != aInsertList.end() )
     227                 :            :             {
     228                 :          0 :                 pPos = pNextInsert->get();
     229                 :          0 :                 ++pNextInsert;
     230                 :            :             }
     231         [ #  # ]:          0 :             else if( IsBlockMode() )
     232         [ #  # ]:          0 :                 GetDoc()->SplitNode( *pPos, false );
     233                 :            :         }
     234                 :            : 
     235                 :            :         // nur bei Selektion (nicht Textnodes haben Selection,
     236                 :            :         // aber Point/GetMark sind gleich
     237 [ #  # ][ #  # ]:          0 :         if( !PCURCRSR->HasMark() || *PCURCRSR->GetPoint() == *PCURCRSR->GetMark() )
         [ #  # ][ #  # ]
     238                 :          0 :             continue;
     239                 :            : 
     240         [ #  # ]:          0 :         if( bFirstMove )
     241                 :            :         {
     242                 :            :             // Anfangs-Position vom neuen Bereich merken
     243         [ #  # ]:          0 :             aSttNdIdx = pPos->nNode.GetIndex()-1;
     244                 :          0 :             nSttCntIdx = pPos->nContent.GetIndex();
     245                 :          0 :             bFirstMove = sal_False;
     246                 :            :         }
     247                 :            : 
     248         [ #  # ]:          0 :         const bool bSuccess( GetDoc()->CopyRange( *PCURCRSR, *pPos, false ) );
     249         [ #  # ]:          0 :         if (!bSuccess)
     250                 :          0 :             continue;
     251                 :            : 
     252 [ #  # ][ #  # ]:          0 :         SwPaM aInsertPaM(*pPos, SwPosition(aSttNdIdx));
                 [ #  # ]
     253         [ #  # ]:          0 :         pDestShell->GetDoc()->MakeUniqueNumRules(aInsertPaM);
     254                 :            : 
     255         [ #  # ]:          0 :         bRet = sal_True;
     256                 :          0 :     FOREACHPAM_END()
     257                 :            : 
     258                 :            : 
     259                 :            :     // Maybe nothing has been moved?
     260         [ #  # ]:          0 :     if( !bFirstMove )
     261                 :            :     {
     262         [ #  # ]:          0 :         SwPaM* pCrsr = pDestShell->GetCrsr();
     263         [ #  # ]:          0 :         pCrsr->SetMark();
     264         [ #  # ]:          0 :         pCrsr->GetPoint()->nNode = aSttNdIdx.GetIndex()+1;
     265 [ #  # ][ #  # ]:          0 :         pCrsr->GetPoint()->nContent.Assign( pCrsr->GetCntntNode(),nSttCntIdx);
     266                 :          0 :         pCrsr->Exchange();
     267                 :            :     }
     268                 :            :     else
     269                 :            :     {
     270                 :            :         // falls beim Move der Cursor "gewandert" ist, so setze hier auch
     271                 :            :         // seinen GetMark um, damit dieser nie in den Wald zeigt.
     272 [ #  # ][ #  # ]:          0 :         pDestShell->GetCrsr()->SetMark();
     273 [ #  # ][ #  # ]:          0 :         pDestShell->GetCrsr()->DeleteMark();
     274                 :            :     }
     275                 :            : #if OSL_DEBUG_LEVEL > 0
     276                 :            : // pruefe ob die Indizies auch in den richtigen Nodes angemeldet sind
     277                 :            : {
     278                 :            :     SwPaM* pCmp = (SwPaM*)pDestShell->GetCrsr();        // sicher den Pointer auf Cursor
     279                 :            :     do {
     280                 :            :         OSL_ENSURE( pCmp->GetPoint()->nContent.GetIdxReg()
     281                 :            :                     == pCmp->GetCntntNode(), "Point im falschen Node" );
     282                 :            :         OSL_ENSURE( pCmp->GetMark()->nContent.GetIdxReg()
     283                 :            :                     == pCmp->GetCntntNode(sal_False), "Mark im falschen Node" );
     284                 :            :         sal_Bool bTst = *pCmp->GetPoint() == *pCmp->GetMark();
     285                 :            :         (void) bTst;
     286                 :            :     } while( pDestShell->GetCrsr() != ( pCmp = (SwPaM*)pCmp->GetNext() ) );
     287                 :            : }
     288                 :            : #endif
     289                 :            : 
     290                 :            :     // Undo-Klammerung hier beenden
     291 [ #  # ][ #  # ]:          0 :     pDestShell->GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
     292         [ #  # ]:          0 :     pDestShell->EndAllAction();
     293                 :            : 
     294 [ #  # ][ #  # ]:          0 :     pDestShell->SaveTblBoxCntnt( pDestShell->GetCrsr()->GetPoint() );
     295                 :            : 
     296 [ #  # ][ #  # ]:          0 :     return (long)bRet;
     297                 :            : }
     298                 :            : 
     299                 :            : 
     300                 :            :     // Ersetz einen selektierten Bereich in einem TextNode mit dem
     301                 :            :     // String. Ist fuers Suchen&Ersetzen gedacht.
     302                 :            :     // bRegExpRplc - ersetze Tabs (\\t) und setze den gefundenen String
     303                 :            :     //               ein ( nicht \& )
     304                 :            :     //              z.B.: Fnd: "zzz", Repl: "xx\t\\t..&..\&"
     305                 :            :     //                      --> "xx\t<Tab>..zzz..&"
     306                 :          0 : sal_Bool SwEditShell::Replace( const String& rNewStr, sal_Bool bRegExpRplc )
     307                 :            : {
     308         [ #  # ]:          0 :     SET_CURR_SHELL( this );
     309                 :            : 
     310                 :          0 :     sal_Bool bRet = sal_False;
     311 [ #  # ][ #  # ]:          0 :     if( !HasReadonlySel() )
     312                 :            :     {
     313         [ #  # ]:          0 :         StartAllAction();
     314 [ #  # ][ #  # ]:          0 :         GetDoc()->GetIDocumentUndoRedo().StartUndo(UNDO_EMPTY, NULL);
     315                 :            : 
     316 [ #  # ][ #  # ]:          0 :         FOREACHPAM_START(this)
     317 [ #  # ][ #  # ]:          0 :             if( PCURCRSR->HasMark() && *PCURCRSR->GetMark() != *PCURCRSR->GetPoint() )
         [ #  # ][ #  # ]
     318                 :            :             {
     319         [ #  # ]:          0 :                 bRet = GetDoc()->ReplaceRange( *PCURCRSR, rNewStr, bRegExpRplc )
     320 [ #  # ][ #  # ]:          0 :                     || bRet;
     321         [ #  # ]:          0 :                 SaveTblBoxCntnt( PCURCRSR->GetPoint() );
     322                 :            :             }
     323                 :          0 :         FOREACHPAM_END()
     324                 :            : 
     325                 :            :         // Undo-Klammerung hier beenden
     326 [ #  # ][ #  # ]:          0 :         GetDoc()->GetIDocumentUndoRedo().EndUndo(UNDO_EMPTY, NULL);
     327         [ #  # ]:          0 :         EndAllAction();
     328                 :            :     }
     329         [ #  # ]:          0 :     return bRet;
     330                 :            : }
     331                 :            : 
     332                 :            : 
     333                 :            :     // Special-Methode fuer JOE's- Wizzards
     334                 :          0 : sal_Bool SwEditShell::DelFullPara()
     335                 :            : {
     336                 :          0 :     sal_Bool bRet = sal_False;
     337         [ #  # ]:          0 :     if( !IsTableMode() )
     338                 :            :     {
     339                 :          0 :         SwPaM* pCrsr = GetCrsr();
     340                 :            :         // keine Mehrfach-Selection
     341 [ #  # ][ #  # ]:          0 :         if( pCrsr->GetNext() == pCrsr && !HasReadonlySel() )
                 [ #  # ]
     342                 :            :         {
     343         [ #  # ]:          0 :             SET_CURR_SHELL( this );
     344         [ #  # ]:          0 :             StartAllAction();
     345         [ #  # ]:          0 :             bRet = GetDoc()->DelFullPara( *pCrsr );
     346 [ #  # ][ #  # ]:          0 :             EndAllAction();
     347                 :            :         }
     348                 :            :     }
     349                 :          0 :     return bRet;
     350                 :            : }
     351                 :            : 
     352                 :            : 
     353                 :            : 
     354                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10