LCOV - code coverage report
Current view: top level - libreoffice/sw/source/core/edit - eddel.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 150 0.0 %
Date: 2012-12-27 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>       // fuer die UndoIds
      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             : /************************************************************
      37             :  * Loeschen
      38             :  ************************************************************/
      39             : 
      40           0 : void SwEditShell::DeleteSel( SwPaM& rPam, sal_Bool* pUndo )
      41             : {
      42             :     // nur bei Selektion
      43           0 :     if( !rPam.HasMark() || *rPam.GetPoint() == *rPam.GetMark())
      44           0 :         return;
      45             : 
      46             :     // besteht eine Selection in einer Tabelle ?
      47             :     // dann nur den Inhalt der selektierten Boxen loeschen
      48             :     // jetzt gibt es 2 Faelle die beachtet werden muessen:
      49             :     //  1. Point und Mark stehen in einer Box, Selection normal loeschen
      50             :     //  2. Point und Mark stehen in unterschiedlichen Boxen, alle
      51             :     // selektierten Boxen suchen in den Inhalt loeschen
      52           0 :     if( rPam.GetNode()->FindTableNode() &&
      53           0 :         rPam.GetNode()->StartOfSectionNode() !=
      54           0 :         rPam.GetNode(sal_False)->StartOfSectionNode() )
      55             :     {
      56             :         // in Tabellen das Undo gruppieren
      57           0 :         if( pUndo && !*pUndo )
      58             :         {
      59           0 :             GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
      60           0 :             *pUndo = sal_True;
      61             :         }
      62           0 :         SwPaM aDelPam( *rPam.Start() );
      63           0 :         const SwPosition* pEndSelPos = rPam.End();
      64           0 :         do {
      65           0 :             aDelPam.SetMark();
      66           0 :             SwNode* pNd = aDelPam.GetNode();
      67           0 :             const SwNode& rEndNd = *pNd->EndOfSectionNode();
      68           0 :             if( pEndSelPos->nNode.GetIndex() <= rEndNd.GetIndex() )
      69             :             {
      70           0 :                 *aDelPam.GetPoint() = *pEndSelPos;
      71           0 :                 pEndSelPos = 0;     // Pointer als Flag missbrauchen
      72             :             }
      73             :             else
      74             :             {
      75             :                 // dann ans Ende der Section
      76           0 :                 aDelPam.GetPoint()->nNode = rEndNd;
      77           0 :                 aDelPam.Move( fnMoveBackward, fnGoCntnt );
      78             :             }
      79             :                 // geschuetze Boxen ueberspringen !
      80           0 :             if( !pNd->IsCntntNode() ||
      81           0 :                 !pNd->IsInProtectSect() )
      82             :             {
      83             :                 // alles loeschen
      84           0 :                 GetDoc()->DeleteAndJoin( aDelPam );
      85           0 :                 SaveTblBoxCntnt( aDelPam.GetPoint() );
      86             :             }
      87             : 
      88           0 :             if( !pEndSelPos )               // am Ende der Selection
      89           0 :                 break;
      90           0 :             aDelPam.DeleteMark();
      91           0 :             aDelPam.Move( fnMoveForward, fnGoCntnt );   // naechste Box
      92           0 :         } while( pEndSelPos );
      93             :     }
      94             :     else
      95             :     {
      96             :             // alles loeschen
      97           0 :         GetDoc()->DeleteAndJoin( rPam );
      98           0 :         SaveTblBoxCntnt( rPam.GetPoint() );
      99             :     }
     100             : 
     101             :     // Selection wird nicht mehr benoetigt.
     102           0 :     rPam.DeleteMark();
     103             : }
     104             : 
     105             : 
     106           0 : long SwEditShell::Delete()
     107             : {
     108           0 :     SET_CURR_SHELL( this );
     109           0 :     long nRet = 0;
     110           0 :     if( !HasReadonlySel() )
     111             :     {
     112           0 :         StartAllAction();
     113             : 
     114           0 :         sal_Bool bUndo = GetCrsr()->GetNext() != GetCrsr();
     115           0 :         if( bUndo )     // mehr als eine 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(this)
     124           0 :             DeleteSel( *PCURCRSR, &bUndo );
     125           0 :         FOREACHPAM_END()
     126             : 
     127             :         // falls eine Undo-Klammerung, dann hier beenden
     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(this)
     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( sal_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 :     xub_StrLen 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(this)
     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             :         // nur bei Selektion (nicht Textnodes haben Selection,
     227             :         // aber Point/GetMark sind gleich
     228           0 :         if( !PCURCRSR->HasMark() || *PCURCRSR->GetPoint() == *PCURCRSR->GetMark() )
     229           0 :             continue;
     230             : 
     231           0 :         if( bFirstMove )
     232             :         {
     233             :             // Anfangs-Position vom neuen Bereich merken
     234           0 :             aSttNdIdx = pPos->nNode.GetIndex()-1;
     235           0 :             nSttCntIdx = pPos->nContent.GetIndex();
     236           0 :             bFirstMove = false;
     237             :         }
     238             : 
     239           0 :         const bool bSuccess( GetDoc()->CopyRange( *PCURCRSR, *pPos, false ) );
     240           0 :         if (!bSuccess)
     241           0 :             continue;
     242             : 
     243           0 :         SwPaM aInsertPaM(*pPos, SwPosition(aSttNdIdx));
     244           0 :         pDestShell->GetDoc()->MakeUniqueNumRules(aInsertPaM);
     245             : 
     246           0 :         bRet = sal_True;
     247           0 :     FOREACHPAM_END()
     248             : 
     249             : 
     250             :     // Maybe nothing has been moved?
     251           0 :     if( !bFirstMove )
     252             :     {
     253           0 :         SwPaM* pCrsr = pDestShell->GetCrsr();
     254           0 :         pCrsr->SetMark();
     255           0 :         pCrsr->GetPoint()->nNode = aSttNdIdx.GetIndex()+1;
     256           0 :         pCrsr->GetPoint()->nContent.Assign( pCrsr->GetCntntNode(),nSttCntIdx);
     257           0 :         pCrsr->Exchange();
     258             :     }
     259             :     else
     260             :     {
     261             :         // falls beim Move der Cursor "gewandert" ist, so setze hier auch
     262             :         // seinen GetMark um, damit dieser nie in den Wald zeigt.
     263           0 :         pDestShell->GetCrsr()->SetMark();
     264           0 :         pDestShell->GetCrsr()->DeleteMark();
     265             :     }
     266             : #if OSL_DEBUG_LEVEL > 0
     267             : // pruefe ob die Indizies auch in den richtigen Nodes angemeldet sind
     268             : {
     269             :     SwPaM* pCmp = (SwPaM*)pDestShell->GetCrsr();        // sicher den Pointer auf Cursor
     270             :     do {
     271             :         OSL_ENSURE( pCmp->GetPoint()->nContent.GetIdxReg()
     272             :                     == pCmp->GetCntntNode(), "Point im falschen Node" );
     273             :         OSL_ENSURE( pCmp->GetMark()->nContent.GetIdxReg()
     274             :                     == pCmp->GetCntntNode(sal_False), "Mark im falschen Node" );
     275             :         bool bTst = *pCmp->GetPoint() == *pCmp->GetMark();
     276             :         (void) bTst;
     277             :     } while( pDestShell->GetCrsr() != ( pCmp = (SwPaM*)pCmp->GetNext() ) );
     278             : }
     279             : #endif
     280             : 
     281             :     // Undo-Klammerung hier beenden
     282           0 :     pDestShell->GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
     283           0 :     pDestShell->EndAllAction();
     284             : 
     285           0 :     pDestShell->SaveTblBoxCntnt( pDestShell->GetCrsr()->GetPoint() );
     286             : 
     287           0 :     return (long)bRet;
     288             : }
     289             : 
     290             : 
     291             :     // Ersetz einen selektierten Bereich in einem TextNode mit dem
     292             :     // String. Ist fuers Suchen&Ersetzen gedacht.
     293             :     // bRegExpRplc - ersetze Tabs (\\t) und setze den gefundenen String
     294             :     //               ein ( nicht \& )
     295             :     //              z.B.: Fnd: "zzz", Repl: "xx\t\\t..&..\&"
     296             :     //                      --> "xx\t<Tab>..zzz..&"
     297           0 : sal_Bool SwEditShell::Replace( const String& rNewStr, sal_Bool bRegExpRplc )
     298             : {
     299           0 :     SET_CURR_SHELL( this );
     300             : 
     301           0 :     sal_Bool bRet = sal_False;
     302           0 :     if( !HasReadonlySel() )
     303             :     {
     304           0 :         StartAllAction();
     305           0 :         GetDoc()->GetIDocumentUndoRedo().StartUndo(UNDO_EMPTY, NULL);
     306             : 
     307           0 :         FOREACHPAM_START(this)
     308           0 :             if( PCURCRSR->HasMark() && *PCURCRSR->GetMark() != *PCURCRSR->GetPoint() )
     309             :             {
     310           0 :                 bRet = GetDoc()->ReplaceRange( *PCURCRSR, rNewStr, bRegExpRplc )
     311           0 :                     || bRet;
     312           0 :                 SaveTblBoxCntnt( PCURCRSR->GetPoint() );
     313             :             }
     314           0 :         FOREACHPAM_END()
     315             : 
     316             :         // Undo-Klammerung hier beenden
     317           0 :         GetDoc()->GetIDocumentUndoRedo().EndUndo(UNDO_EMPTY, NULL);
     318           0 :         EndAllAction();
     319             :     }
     320           0 :     return bRet;
     321             : }
     322             : 
     323             : 
     324             :     // Special-Methode fuer JOE's- Wizzards
     325           0 : sal_Bool SwEditShell::DelFullPara()
     326             : {
     327           0 :     sal_Bool bRet = sal_False;
     328           0 :     if( !IsTableMode() )
     329             :     {
     330           0 :         SwPaM* pCrsr = GetCrsr();
     331             :         // keine Mehrfach-Selection
     332           0 :         if( pCrsr->GetNext() == pCrsr && !HasReadonlySel() )
     333             :         {
     334           0 :             SET_CURR_SHELL( this );
     335           0 :             StartAllAction();
     336           0 :             bRet = GetDoc()->DelFullPara( *pCrsr );
     337           0 :             EndAllAction();
     338             :         }
     339             :     }
     340           0 :     return bRet;
     341             : }
     342             : 
     343             : 
     344             : 
     345             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10