LCOV - code coverage report
Current view: top level - libreoffice/sw/source/core/doc - doccorr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 104 152 68.4 %
Date: 2012-12-17 Functions: 10 12 83.3 %
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 <doc.hxx>
      21             : #include <node.hxx>
      22             : #include <rootfrm.hxx>
      23             : #include <editsh.hxx>
      24             : #include <viscrs.hxx>
      25             : #include <IMark.hxx>
      26             : #include <bookmrk.hxx>
      27             : #include <redline.hxx>
      28             : #include <mvsave.hxx>
      29             : #include <docary.hxx>
      30             : #include <unocrsr.hxx>
      31             : #include <swundo.hxx>
      32             : #include <hints.hxx>
      33             : 
      34             : /*
      35             :  * Macros to iterate over all CrsrShells
      36             :  */
      37             : #define PCURSH ((SwCrsrShell*)_pStartShell)
      38             : #define FOREACHSHELL_START( pEShell ) \
      39             :     {\
      40             :         ViewShell *_pStartShell = pEShell; \
      41             :         do { \
      42             :             if( _pStartShell->IsA( TYPE( SwCrsrShell )) ) \
      43             :             {
      44             : 
      45             : #define FOREACHSHELL_END( pEShell ) \
      46             :             } \
      47             :         } while((_pStartShell=(ViewShell*)_pStartShell->GetNext())!= pEShell ); \
      48             :     }
      49             : 
      50             : #define PCURCRSR (_pCurrCrsr)
      51             : #define FOREACHPAM_START(pSttCrsr) \
      52             :     {\
      53             :         SwPaM *_pStartCrsr = pSttCrsr, *_pCurrCrsr = pSttCrsr; \
      54             :         do {
      55             : 
      56             : #define FOREACHPAM_END() \
      57             :         } while( (_pCurrCrsr=(SwPaM *)_pCurrCrsr->GetNext()) != _pStartCrsr ); \
      58             :     }
      59             : 
      60             : namespace
      61             : {
      62             :     // find the relevant section in which the SwUnoCrsr may wander.
      63             :     // returns NULL if no restrictions apply
      64        4812 :     static const SwStartNode* lcl_FindUnoCrsrSection( const SwNode& rNode )
      65             :     {
      66        4812 :         const SwStartNode* pStartNode = rNode.StartOfSectionNode();
      67       27266 :         while( ( pStartNode != NULL ) &&
      68        8774 :                ( pStartNode->StartOfSectionNode() != pStartNode ) &&
      69        4906 :                ( pStartNode->GetStartNodeType() == SwNormalStartNode ) )
      70        3962 :             pStartNode = pStartNode->StartOfSectionNode();
      71             : 
      72        4812 :         return pStartNode;
      73             :     }
      74             : 
      75        5412 :     static inline bool lcl_PosCorrAbs(SwPosition & rPos,
      76             :         const SwPosition& rStart,
      77             :         const SwPosition& rEnd,
      78             :         const SwPosition& rNewPos)
      79             :     {
      80        5412 :         if ((rStart <= rPos) && (rPos <= rEnd))
      81             :         {
      82        1906 :             rPos = rNewPos;
      83        1906 :             return true;
      84             :         }
      85        3506 :         return false;
      86             :     };
      87             : 
      88        2706 :     static inline bool lcl_PaMCorrAbs(SwPaM & rPam,
      89             :         const SwPosition& rStart,
      90             :         const SwPosition& rEnd,
      91             :         const SwPosition& rNewPos)
      92             :     {
      93        2706 :         bool bRet = false;
      94        2706 :         bRet |= lcl_PosCorrAbs(rPam.GetBound(true ), rStart, rEnd, rNewPos);
      95        2706 :         bRet |= lcl_PosCorrAbs(rPam.GetBound(false), rStart, rEnd, rNewPos);
      96        2706 :         return bRet;
      97             :     };
      98             : 
      99        1046 :     static inline void lcl_PaMCorrRel1(SwPaM * pPam,
     100             :         SwNode const * const pOldNode,
     101             :         const SwPosition& rNewPos,
     102             :         const xub_StrLen nCntIdx)
     103             :     {
     104        3138 :         for(int nb = 0; nb < 2; ++nb)
     105        2092 :             if(&((pPam)->GetBound(sal_Bool(nb)).nNode.GetNode()) == pOldNode)
     106             :             {
     107         788 :                 (pPam)->GetBound(sal_Bool(nb)).nNode = rNewPos.nNode;
     108         788 :                 (pPam)->GetBound(sal_Bool(nb)).nContent.Assign(
     109         788 :                     const_cast<SwIndexReg*>(rNewPos.nContent.GetIdxReg()),
     110        1576 :                     nCntIdx + (pPam)->GetBound(sal_Bool(nb)).nContent.GetIndex());
     111             :             }
     112        1046 :     }
     113             : }
     114             : 
     115             : 
     116        2731 : void PaMCorrAbs( const SwPaM& rRange,
     117             :                 const SwPosition& rNewPos )
     118             : {
     119        2731 :     SwPosition const aStart( *rRange.Start() );
     120        2731 :     SwPosition const aEnd( *rRange.End() );
     121        2731 :     SwPosition const aNewPos( rNewPos );
     122        2731 :     SwDoc *const pDoc = aStart.nNode.GetNode().GetDoc();
     123        2731 :     SwCrsrShell *const pShell = pDoc->GetEditShell();
     124             : 
     125        2731 :     if( pShell )
     126             :     {
     127           0 :         FOREACHSHELL_START( pShell )
     128           0 :             SwPaM *_pStkCrsr = PCURSH->GetStkCrsr();
     129           0 :             if( _pStkCrsr )
     130           0 :             do {
     131           0 :                 lcl_PaMCorrAbs( *_pStkCrsr, aStart, aEnd, aNewPos );
     132             :             } while ( (_pStkCrsr != 0 ) &&
     133           0 :                 ((_pStkCrsr=(SwPaM *)_pStkCrsr->GetNext()) != PCURSH->GetStkCrsr()) );
     134             : 
     135           0 :             FOREACHPAM_START( PCURSH->_GetCrsr() )
     136           0 :                 lcl_PaMCorrAbs( *PCURCRSR, aStart, aEnd, aNewPos );
     137           0 :             FOREACHPAM_END()
     138             : 
     139           0 :             if( PCURSH->IsTableMode() )
     140           0 :                 lcl_PaMCorrAbs( *PCURSH->GetTblCrs(), aStart, aEnd, aNewPos );
     141             : 
     142           0 :         FOREACHSHELL_END( pShell )
     143             :     }
     144             :     {
     145        2731 :         SwUnoCrsrTbl& rTbl = const_cast<SwUnoCrsrTbl&>(pDoc->GetUnoCrsrTbl());
     146             : 
     147        5437 :         for( SwUnoCrsrTbl::iterator it = rTbl.begin(); it != rTbl.end(); ++it )
     148             :         {
     149        2706 :             SwUnoCrsr *const pUnoCursor = *it;
     150             : 
     151        2706 :             bool bChange = false; // has the UNO cursor been corrected?
     152             : 
     153             :             // determine whether the UNO cursor will leave it's designated
     154             :             // section
     155             :             bool const bLeaveSection =
     156        2706 :                 pUnoCursor->IsRemainInSection() &&
     157        2406 :                 ( lcl_FindUnoCrsrSection( aNewPos.nNode.GetNode() ) !=
     158             :                   lcl_FindUnoCrsrSection(
     159        5112 :                       pUnoCursor->GetPoint()->nNode.GetNode() ) );
     160             : 
     161        5412 :             FOREACHPAM_START( pUnoCursor )
     162        2706 :                 bChange |= lcl_PaMCorrAbs( *PCURCRSR, aStart, aEnd, aNewPos );
     163        2706 :             FOREACHPAM_END()
     164             : 
     165             :             SwUnoTableCrsr *const pUnoTblCrsr =
     166        2706 :                 dynamic_cast<SwUnoTableCrsr *>(*it);
     167        2706 :             if( pUnoTblCrsr )
     168             :             {
     169           0 :                 FOREACHPAM_START( &pUnoTblCrsr->GetSelRing() )
     170             :                     bChange |=
     171           0 :                         lcl_PaMCorrAbs( *PCURCRSR, aStart, aEnd, aNewPos );
     172           0 :                 FOREACHPAM_END()
     173             :             }
     174             : 
     175             :             // if a UNO cursor leaves its designated section, we must inform
     176             :             // (and invalidate) said cursor
     177        2706 :             if (bChange && bLeaveSection)
     178             :             {
     179             :                 // the UNO cursor has left its section. We need to notify it!
     180         234 :                 SwMsgPoolItem aHint( RES_UNOCURSOR_LEAVES_SECTION );
     181         234 :                 pUnoCursor->ModifyNotification( &aHint, NULL );
     182             :             }
     183             :         }
     184        2731 :     }
     185        2731 : }
     186             : 
     187         356 : void SwDoc::CorrAbs(const SwNodeIndex& rOldNode,
     188             :     const SwPosition& rNewPos,
     189             :     const xub_StrLen nOffset,
     190             :     sal_Bool bMoveCrsr)
     191             : {
     192         356 :     SwCntntNode *const pCntntNode( rOldNode.GetNode().GetCntntNode() );
     193             :     SwPaM const aPam(rOldNode, 0,
     194         356 :                      rOldNode, (pCntntNode) ? pCntntNode->Len() : 0);
     195         356 :     SwPosition aNewPos(rNewPos);
     196         356 :     aNewPos.nContent += nOffset;
     197             : 
     198         356 :     getIDocumentMarkAccess()->correctMarksAbsolute(rOldNode, rNewPos, nOffset);
     199             :     {   // fix redlines
     200         356 :         SwRedlineTbl& rTbl = *pRedlineTbl;
     201         712 :         for (sal_uInt16 n = 0; n < rTbl.size(); )
     202             :         {
     203             :             // is on position ??
     204           0 :             SwRedline *const pRedline( rTbl[ n ] );
     205             :             bool const bChanged =
     206           0 :                 lcl_PaMCorrAbs(*pRedline, *aPam.Start(), *aPam.End(), aNewPos);
     207             :             // clean up empty redlines: docredln.cxx asserts these as invalid
     208           0 :             if (bChanged && (*pRedline->GetPoint() == *pRedline->GetMark())
     209           0 :                          && (pRedline->GetContentIdx() == NULL))
     210             :             {
     211           0 :                 rTbl.DeleteAndDestroy(n);
     212             :             }
     213             :             else
     214             :             {
     215           0 :                 ++n;
     216             :             }
     217             :         }
     218             :     }
     219             : 
     220         356 :     if(bMoveCrsr)
     221             :     {
     222         356 :         ::PaMCorrAbs(aPam, aNewPos);
     223         356 :     }
     224         356 : }
     225             : 
     226           0 : void SwDoc::CorrAbs(const SwPaM& rRange,
     227             :     const SwPosition& rNewPos,
     228             :     sal_Bool bMoveCrsr)
     229             : {
     230           0 :     SwPosition aStart(*rRange.Start());
     231           0 :     SwPosition aEnd(*rRange.End());
     232           0 :     SwPosition aNewPos(rNewPos);
     233             : 
     234             :     _DelBookmarks(aStart.nNode, aEnd.nNode, NULL,
     235           0 :         &aStart.nContent, &aEnd.nContent);
     236           0 :     if(bMoveCrsr)
     237           0 :         ::PaMCorrAbs(rRange, rNewPos);
     238           0 : }
     239             : 
     240         362 : void SwDoc::CorrAbs(const SwNodeIndex& rStartNode,
     241             :      const SwNodeIndex& rEndNode,
     242             :      const SwPosition& rNewPos,
     243             :      sal_Bool bMoveCrsr)
     244             : {
     245         362 :     _DelBookmarks(rStartNode, rEndNode);
     246             : 
     247         362 :     if(bMoveCrsr)
     248             :     {
     249         362 :         SwCntntNode *const pCntntNode( rEndNode.GetNode().GetCntntNode() );
     250             :         SwPaM const aPam(rStartNode, 0,
     251         362 :                          rEndNode, (pCntntNode) ? pCntntNode->Len() : 0);
     252         362 :         ::PaMCorrAbs(aPam, rNewPos);
     253             :     }
     254         362 : }
     255             : 
     256             : 
     257             : 
     258             : 
     259             : 
     260         524 : void PaMCorrRel( const SwNodeIndex &rOldNode,
     261             :                  const SwPosition &rNewPos,
     262             :                  const xub_StrLen nOffset )
     263             : {
     264         524 :     const SwNode* pOldNode = &rOldNode.GetNode();
     265         524 :     SwPosition aNewPos( rNewPos );
     266         524 :     const SwDoc* pDoc = pOldNode->GetDoc();
     267             : 
     268         524 :     xub_StrLen nCntIdx = rNewPos.nContent.GetIndex() + nOffset;
     269             : 
     270         524 :     SwCrsrShell* pShell = pDoc->GetEditShell();
     271         524 :     if( pShell )
     272             :     {
     273           0 :         FOREACHSHELL_START( pShell )
     274           0 :             SwPaM *_pStkCrsr = PCURSH->GetStkCrsr();
     275           0 :             if( _pStkCrsr )
     276           0 :             do {
     277           0 :                 lcl_PaMCorrRel1( _pStkCrsr, pOldNode, aNewPos, nCntIdx );
     278             :             } while ( (_pStkCrsr != 0 ) &&
     279           0 :                 ((_pStkCrsr=(SwPaM *)_pStkCrsr->GetNext()) != PCURSH->GetStkCrsr()) );
     280             : 
     281           0 :             FOREACHPAM_START( PCURSH->_GetCrsr() )
     282           0 :                 lcl_PaMCorrRel1( PCURCRSR, pOldNode, aNewPos, nCntIdx);
     283           0 :             FOREACHPAM_END()
     284             : 
     285           0 :             if( PCURSH->IsTableMode() )
     286           0 :                 lcl_PaMCorrRel1( PCURSH->GetTblCrs(), pOldNode, aNewPos, nCntIdx );
     287             : 
     288           0 :         FOREACHSHELL_END( pShell )
     289             :     }
     290             :     {
     291         524 :         SwUnoCrsrTbl& rTbl = (SwUnoCrsrTbl&)pDoc->GetUnoCrsrTbl();
     292        1566 :         for( SwUnoCrsrTbl::iterator it = rTbl.begin(); it != rTbl.end(); ++it )
     293             :         {
     294        2084 :             FOREACHPAM_START( *it )
     295        1042 :                 lcl_PaMCorrRel1( PCURCRSR, pOldNode, aNewPos, nCntIdx );
     296        1042 :             FOREACHPAM_END()
     297             : 
     298             :             SwUnoTableCrsr* pUnoTblCrsr =
     299        1042 :                 dynamic_cast<SwUnoTableCrsr*>(*it);
     300        1042 :             if( pUnoTblCrsr )
     301             :             {
     302           0 :                 FOREACHPAM_START( &pUnoTblCrsr->GetSelRing() )
     303           0 :                     lcl_PaMCorrRel1( PCURCRSR, pOldNode, aNewPos, nCntIdx );
     304           0 :                 FOREACHPAM_END()
     305             :             }
     306             :         }
     307         524 :     }
     308         524 : }
     309             : 
     310         524 : void SwDoc::CorrRel(const SwNodeIndex& rOldNode,
     311             :     const SwPosition& rNewPos,
     312             :     const xub_StrLen nOffset,
     313             :     sal_Bool bMoveCrsr)
     314             : {
     315         524 :     getIDocumentMarkAccess()->correctMarksRelative(rOldNode, rNewPos, nOffset);
     316             : 
     317             :     { // fix the Redlines
     318         524 :         SwRedlineTbl& rTbl = *pRedlineTbl;
     319         524 :         SwPosition aNewPos(rNewPos);
     320         528 :         for( sal_uInt16 n = 0; n < rTbl.size(); ++n )
     321             :         {
     322             :             // liegt auf der Position ??
     323           4 :             lcl_PaMCorrRel1( rTbl[ n ], &rOldNode.GetNode(), aNewPos, aNewPos.nContent.GetIndex() + nOffset );
     324         524 :         }
     325             :     }
     326             : 
     327         524 :     if(bMoveCrsr)
     328         524 :         ::PaMCorrRel(rOldNode, rNewPos, nOffset);
     329         524 : }
     330             : 
     331             : 
     332        6133 : SwEditShell* SwDoc::GetEditShell( ViewShell** ppSh ) const
     333             : {
     334             :     // Layout and OLE shells should be available
     335        6133 :     if( pCurrentView )
     336             :     {
     337         585 :         ViewShell *pSh = pCurrentView, *pVSh = pSh;
     338         585 :         if( ppSh )
     339         406 :             *ppSh = pSh;
     340             : 
     341             :         // look for an EditShell (if it exists)
     342           0 :         do {
     343         585 :             if( pSh->IsA( TYPE( SwEditShell ) ) )
     344         585 :                 return (SwEditShell*)pSh;
     345             : 
     346           0 :         } while( pVSh != ( pSh = (ViewShell*)pSh->GetNext() ));
     347             :     }
     348        5548 :     else if( ppSh )
     349          14 :         *ppSh = 0;  //swmod 071029//swmod 071225
     350             : 
     351        5548 :     return 0;
     352             : }
     353             : 
     354           0 : ::sw::IShellCursorSupplier * SwDoc::GetIShellCursorSupplier()
     355             : {
     356           0 :     return GetEditShell(0);
     357             : }
     358             : 
     359             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10