LCOV - code coverage report
Current view: top level - sw/source/core/edit - eddel.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 154 0.0 %
Date: 2014-04-14 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <hintids.hxx>
      21             : #include <doc.hxx>
      22             : #include <IDocumentUndoRedo.hxx>
      23             : #include <editsh.hxx>
      24             : #include <cntfrm.hxx>
      25             : #include <pam.hxx>
      26             : #include <swundo.hxx>
      27             : #include <edimp.hxx>
      28             : #include <IMark.hxx>
      29             : #include <docary.hxx>
      30             : #include <SwRewriter.hxx>
      31             : #include <globals.hrc>
      32             : 
      33             : #include <comcore.hrc>
      34             : #include <list>
      35             : 
      36           0 : void SwEditShell::DeleteSel( SwPaM& rPam, sal_Bool* pUndo )
      37             : {
      38           0 :     bool bSelectAll = StartsWithTable() && ExtendedSelectedAll(/*bFootnotes =*/ false);
      39             :     // only for selections
      40           0 :     if( !rPam.HasMark() || *rPam.GetPoint() == *rPam.GetMark())
      41           0 :         return;
      42             : 
      43             :     // Is the selection in a table? Then delete only the content of the selected boxes.
      44             :     // Here, there are two cases:
      45             :     // 1. Point and Mark are in one box, delete selection as usual
      46             :     // 2. Point and Mark are in different boxes, search all selected boxes and delete content
      47             :     // 3. Point and Mark are at the document start and end, Point is in a table: delete selection as usual
      48           0 :     if( rPam.GetNode()->FindTableNode() &&
      49           0 :         rPam.GetNode()->StartOfSectionNode() !=
      50           0 :         rPam.GetNode(false)->StartOfSectionNode() && !bSelectAll )
      51             :     {
      52             :         // group the Undo in the table
      53           0 :         if( pUndo && !*pUndo )
      54             :         {
      55           0 :             GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
      56           0 :             *pUndo = sal_True;
      57             :         }
      58           0 :         SwPaM aDelPam( *rPam.Start() );
      59           0 :         const SwPosition* pEndSelPos = rPam.End();
      60           0 :         do {
      61           0 :             aDelPam.SetMark();
      62           0 :             SwNode* pNd = aDelPam.GetNode();
      63           0 :             const SwNode& rEndNd = *pNd->EndOfSectionNode();
      64           0 :             if( pEndSelPos->nNode.GetIndex() <= rEndNd.GetIndex() )
      65             :             {
      66           0 :                 *aDelPam.GetPoint() = *pEndSelPos;
      67           0 :                 pEndSelPos = 0;     // misuse a pointer as a flag
      68             :             }
      69             :             else
      70             :             {
      71             :                 // then go to the end of the selection
      72           0 :                 aDelPam.GetPoint()->nNode = rEndNd;
      73           0 :                 aDelPam.Move( fnMoveBackward, fnGoCntnt );
      74             :             }
      75             :             // skip protected boxes
      76           0 :             if( !pNd->IsCntntNode() ||
      77           0 :                 !pNd->IsInProtectSect() )
      78             :             {
      79             :                 // delete everything
      80           0 :                 GetDoc()->DeleteAndJoin( aDelPam );
      81           0 :                 SaveTblBoxCntnt( aDelPam.GetPoint() );
      82             :             }
      83             : 
      84           0 :             if( !pEndSelPos ) // at the end of a selection
      85           0 :                 break;
      86           0 :             aDelPam.DeleteMark();
      87           0 :             aDelPam.Move( fnMoveForward, fnGoCntnt ); // next box
      88           0 :         } while( pEndSelPos );
      89             :     }
      90             :     else
      91             :     {
      92           0 :         SwPaM aPam(rPam);
      93           0 :         if (bSelectAll)
      94             :             // Selection starts at the first para of the first cell, but we
      95             :             // want to delete the table node before the first cell as well.
      96           0 :             aPam.Start()->nNode = aPam.Start()->nNode.GetNode().FindTableNode()->GetIndex();
      97             :         // delete everything
      98           0 :         GetDoc()->DeleteAndJoin( aPam );
      99           0 :         SaveTblBoxCntnt( aPam.GetPoint() );
     100             :     }
     101             : 
     102             :     // Selection is not needed anymore
     103           0 :     rPam.DeleteMark();
     104             : }
     105             : 
     106           0 : long SwEditShell::Delete()
     107             : {
     108           0 :     SET_CURR_SHELL( this );
     109           0 :     long nRet = 0;
     110           0 :     if ( !HasReadonlySel() || CrsrInsideInputFld() )
     111             :     {
     112           0 :         StartAllAction();
     113             : 
     114           0 :         sal_Bool bUndo = GetCrsr()->GetNext() != GetCrsr();
     115           0 :         if( bUndo ) // more than one selection?
     116             :         {
     117           0 :             SwRewriter aRewriter;
     118           0 :             aRewriter.AddRule(UndoArg1, SW_RESSTR(STR_MULTISEL));
     119             : 
     120           0 :             GetDoc()->GetIDocumentUndoRedo().StartUndo(UNDO_DELETE, &aRewriter);
     121             :         }
     122             : 
     123           0 :         FOREACHPAM_START(GetCrsr())
     124           0 :             DeleteSel( *PCURCRSR, &bUndo );
     125           0 :         FOREACHPAM_END()
     126             : 
     127             :         // If undo container then close here
     128           0 :         if( bUndo )
     129             :         {
     130           0 :             GetDoc()->GetIDocumentUndoRedo().EndUndo(UNDO_END, 0);
     131             :         }
     132           0 :         EndAllAction();
     133           0 :         nRet = 1;
     134             :     }
     135           0 :     return nRet;
     136             : }
     137             : 
     138           0 : long SwEditShell::Copy( SwEditShell* pDestShell )
     139             : {
     140           0 :     if( !pDestShell )
     141           0 :         pDestShell = this;
     142             : 
     143           0 :     SET_CURR_SHELL( pDestShell );
     144             : 
     145             :     // List of insert positions for smart insert of block selections
     146           0 :     std::list< boost::shared_ptr<SwPosition> > aInsertList;
     147             : 
     148             :     // Fill list of insert positions
     149             :     {
     150           0 :         SwPosition * pPos = 0;
     151           0 :         boost::shared_ptr<SwPosition> pInsertPos;
     152           0 :         sal_uInt16 nMove = 0;
     153           0 :         FOREACHPAM_START(GetCrsr())
     154             : 
     155           0 :             if( !pPos )
     156             :             {
     157           0 :                 if( pDestShell == this )
     158             :                 {
     159             :                     // First cursor represents the target position!!
     160           0 :                     PCURCRSR->DeleteMark();
     161           0 :                     pPos = (SwPosition*)PCURCRSR->GetPoint();
     162           0 :                     continue;
     163             :                 }
     164             :                 else
     165           0 :                     pPos = pDestShell->GetCrsr()->GetPoint();
     166             :             }
     167           0 :             if( IsBlockMode() )
     168             :             {   // In block mode different insert positions will be calculated
     169             :                 // by simulated cursor movements from the given first insert position
     170           0 :                 if( nMove )
     171             :                 {
     172           0 :                     SwCursor aCrsr( *pPos, 0, false);
     173           0 :                     if( aCrsr.UpDown( false, nMove, 0, 0 ) )
     174             :                     {
     175           0 :                         pInsertPos.reset( new SwPosition( *aCrsr.GetPoint() ) );
     176           0 :                         aInsertList.push_back( pInsertPos );
     177           0 :                     }
     178             :                 }
     179             :                 else
     180           0 :                     pInsertPos.reset( new SwPosition( *pPos ) );
     181           0 :                 ++nMove;
     182             :             }
     183           0 :             SwPosition *pTmp = IsBlockMode() ? pInsertPos.get() : pPos;
     184             :             // Check if a selection would be copied into itself
     185           0 :             if( pDestShell->GetDoc() == GetDoc() &&
     186           0 :                 *PCURCRSR->Start() <= *pTmp && *pTmp < *PCURCRSR->End() )
     187           0 :                 return sal_False;
     188           0 :         FOREACHPAM_END()
     189             :     }
     190             : 
     191           0 :     pDestShell->StartAllAction();
     192           0 :     SwPosition *pPos = 0;
     193           0 :     sal_Bool bRet = sal_False;
     194           0 :     bool bFirstMove = true;
     195           0 :     SwNodeIndex aSttNdIdx( pDestShell->GetDoc()->GetNodes() );
     196           0 :     sal_Int32 nSttCntIdx = 0;
     197             :     // For block selection this list is filled with the insert positions
     198           0 :     std::list< boost::shared_ptr<SwPosition> >::iterator pNextInsert = aInsertList.begin();
     199             : 
     200           0 :     pDestShell->GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
     201           0 :     FOREACHPAM_START(GetCrsr())
     202             : 
     203           0 :         if( !pPos )
     204             :         {
     205           0 :             if( pDestShell == this )
     206             :             {
     207             :                 // First cursor represents the target position!!
     208           0 :                 PCURCRSR->DeleteMark();
     209           0 :                 pPos = (SwPosition*)PCURCRSR->GetPoint();
     210           0 :                 continue;
     211             :             }
     212             :             else
     213           0 :                 pPos = pDestShell->GetCrsr()->GetPoint();
     214             :         }
     215           0 :         if( !bFirstMove )
     216             :         {
     217           0 :             if( pNextInsert != aInsertList.end() )
     218             :             {
     219           0 :                 pPos = pNextInsert->get();
     220           0 :                 ++pNextInsert;
     221             :             }
     222           0 :             else if( IsBlockMode() )
     223           0 :                 GetDoc()->SplitNode( *pPos, false );
     224             :         }
     225             : 
     226             :         // Only for a selection (non-text nodes have selection but Point/GetMark are equal)
     227           0 :         if( !PCURCRSR->HasMark() || *PCURCRSR->GetPoint() == *PCURCRSR->GetMark() )
     228           0 :             continue;
     229             : 
     230           0 :         if( bFirstMove )
     231             :         {
     232             :             // Store start position of the new area
     233           0 :             aSttNdIdx = pPos->nNode.GetIndex()-1;
     234           0 :             nSttCntIdx = pPos->nContent.GetIndex();
     235           0 :             bFirstMove = false;
     236             :         }
     237             : 
     238           0 :         const bool bSuccess( GetDoc()->CopyRange( *PCURCRSR, *pPos, false ) );
     239           0 :         if (!bSuccess)
     240           0 :             continue;
     241             : 
     242           0 :         SwPaM aInsertPaM(*pPos, SwPosition(aSttNdIdx));
     243           0 :         pDestShell->GetDoc()->MakeUniqueNumRules(aInsertPaM);
     244             : 
     245           0 :         bRet = sal_True;
     246           0 :     FOREACHPAM_END()
     247             : 
     248             :     // Maybe nothing has been moved?
     249           0 :     if( !bFirstMove )
     250             :     {
     251           0 :         SwPaM* pCrsr = pDestShell->GetCrsr();
     252           0 :         pCrsr->SetMark();
     253           0 :         pCrsr->GetPoint()->nNode = aSttNdIdx.GetIndex()+1;
     254           0 :         pCrsr->GetPoint()->nContent.Assign( pCrsr->GetCntntNode(),nSttCntIdx);
     255           0 :         pCrsr->Exchange();
     256             :     }
     257             :     else
     258             :     {
     259             :         // If the cursor moved during move process, move also its GetMark
     260           0 :         pDestShell->GetCrsr()->SetMark();
     261           0 :         pDestShell->GetCrsr()->DeleteMark();
     262             :     }
     263             : #if OSL_DEBUG_LEVEL > 0
     264             : // check if the indices are registered in the correct nodes
     265             : {
     266             :     SwPaM* pCmp = (SwPaM*)pDestShell->GetCrsr();        // store pointer to cursor
     267             :     do {
     268             :         OSL_ENSURE( pCmp->GetPoint()->nContent.GetIdxReg()
     269             :                     == pCmp->GetCntntNode(), "Point in wrong Node" );
     270             :         OSL_ENSURE( pCmp->GetMark()->nContent.GetIdxReg()
     271             :                     == pCmp->GetCntntNode(false), "Mark in wrong Node" );
     272             :         bool bTst = *pCmp->GetPoint() == *pCmp->GetMark();
     273             :         (void) bTst;
     274             :     } while( pDestShell->GetCrsr() != ( pCmp = (SwPaM*)pCmp->GetNext() ) );
     275             : }
     276             : #endif
     277             : 
     278             :     // close Undo container here
     279           0 :     pDestShell->GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
     280           0 :     pDestShell->EndAllAction();
     281             : 
     282           0 :     pDestShell->SaveTblBoxCntnt( pDestShell->GetCrsr()->GetPoint() );
     283             : 
     284           0 :     return (long)bRet;
     285             : }
     286             : 
     287             : /** Replace a selected area in a text node with a given string.
     288             :  *
     289             :  * Intended for "search & replace".
     290             :  *
     291             :  * @param bRegExpRplc if <true> replace tabs (\\t) and replace with found string (not \&).
     292             :  *                    E.g. [Fnd: "zzz", Repl: "xx\t\\t..&..\&"] --> "xx\t<Tab>..zzz..&"
     293             :  */
     294           0 : sal_Bool SwEditShell::Replace( const OUString& rNewStr, sal_Bool bRegExpRplc )
     295             : {
     296           0 :     SET_CURR_SHELL( this );
     297             : 
     298           0 :     sal_Bool bRet = sal_False;
     299           0 :     if( !HasReadonlySel() )
     300             :     {
     301           0 :         StartAllAction();
     302           0 :         GetDoc()->GetIDocumentUndoRedo().StartUndo(UNDO_EMPTY, NULL);
     303             : 
     304           0 :         FOREACHPAM_START(GetCrsr())
     305           0 :             if( PCURCRSR->HasMark() && *PCURCRSR->GetMark() != *PCURCRSR->GetPoint() )
     306             :             {
     307           0 :                 bRet = GetDoc()->ReplaceRange( *PCURCRSR, rNewStr, bRegExpRplc )
     308           0 :                     || bRet;
     309           0 :                 SaveTblBoxCntnt( PCURCRSR->GetPoint() );
     310             :             }
     311           0 :         FOREACHPAM_END()
     312             : 
     313             :         // close Undo container here
     314           0 :         GetDoc()->GetIDocumentUndoRedo().EndUndo(UNDO_EMPTY, NULL);
     315           0 :         EndAllAction();
     316             :     }
     317           0 :     return bRet;
     318             : }
     319             : 
     320             : /// special method for JOE's wizards
     321           0 : sal_Bool SwEditShell::DelFullPara()
     322             : {
     323           0 :     sal_Bool bRet = sal_False;
     324           0 :     if( !IsTableMode() )
     325             :     {
     326           0 :         SwPaM* pCrsr = GetCrsr();
     327             :         // no multi selection
     328           0 :         if( pCrsr->GetNext() == pCrsr && !HasReadonlySel() )
     329             :         {
     330           0 :             SET_CURR_SHELL( this );
     331           0 :             StartAllAction();
     332           0 :             bRet = GetDoc()->DelFullPara( *pCrsr );
     333           0 :             EndAllAction();
     334             :         }
     335             :     }
     336           0 :     return bRet;
     337             : }
     338             : 
     339             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10