LCOV - code coverage report
Current view: top level - sw/source/core/crsr - unocrsr.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 94 118 79.7 %
Date: 2014-04-11 Functions: 17 21 81.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 <unocrsr.hxx>
      21             : #include <doc.hxx>
      22             : #include <swtable.hxx>
      23             : #include <docary.hxx>
      24             : #include <rootfrm.hxx>
      25             : 
      26          37 : IMPL_FIXEDMEMPOOL_NEWDEL( SwUnoCrsr )
      27             : 
      28      130974 : SwUnoCrsr::SwUnoCrsr( const SwPosition &rPos, SwPaM* pRing )
      29             :     : SwCursor( rPos, pRing, false ), SwModify( 0 ),
      30             :     bRemainInSection( sal_True ),
      31             :     bSkipOverHiddenSections( sal_False ),
      32      130974 :     bSkipOverProtectSections( sal_False )
      33      130974 : {}
      34             : 
      35      523828 : SwUnoCrsr::~SwUnoCrsr()
      36             : {
      37      130974 :     SwDoc* pDoc = GetDoc();
      38      130974 :     if( !pDoc->IsInDtor() )
      39             :     {
      40             :         // then remove cursor from array
      41      127864 :         SwUnoCrsrTbl& rTbl = (SwUnoCrsrTbl&)pDoc->GetUnoCrsrTbl();
      42      127864 :         if( !rTbl.erase( this ) )
      43             :         {
      44             :             OSL_ENSURE( !this, "UNO Cursor nicht mehr im Array" );
      45             :         }
      46             :     }
      47             : 
      48             :     // delete the whole ring
      49      262018 :     while( GetNext() != this )
      50             :     {
      51          70 :         Ring* pNxt = GetNext();
      52          70 :         pNxt->MoveTo( 0 ); // remove from chain
      53          70 :         delete pNxt;       // and delete
      54             :     }
      55      392854 : }
      56             : 
      57           0 : SwUnoCrsr * SwUnoCrsr::Clone() const
      58             : {
      59           0 :     SwUnoCrsr * pNewCrsr = GetDoc()->CreateUnoCrsr( *GetPoint() );
      60           0 :     if (HasMark())
      61             :     {
      62           0 :         pNewCrsr->SetMark();
      63           0 :         *pNewCrsr->GetMark() = *GetMark();
      64             :     }
      65           0 :     return pNewCrsr;
      66             : }
      67             : 
      68           0 : SwUnoTableCrsr * SwUnoTableCrsr::Clone() const
      69             : {
      70             :     SwUnoTableCrsr * pNewCrsr = dynamic_cast<SwUnoTableCrsr*>(
      71             :         GetDoc()->CreateUnoCrsr(
      72           0 :             *GetPoint(), true /* create SwUnoTableCrsr */ ) );
      73             :     OSL_ENSURE(pNewCrsr, "Clone: cannot create SwUnoTableCrsr?");
      74           0 :     if (pNewCrsr && HasMark())
      75             :     {
      76           0 :         pNewCrsr->SetMark();
      77           0 :         *pNewCrsr->GetMark() = *GetMark();
      78             :     }
      79           0 :     return pNewCrsr;
      80             : }
      81             : 
      82          23 : bool SwUnoCrsr::IsReadOnlyAvailable() const
      83             : {
      84          23 :     return true;
      85             : }
      86             : 
      87             : const SwCntntFrm*
      88       30139 : SwUnoCrsr::DoSetBidiLevelLeftRight( sal_Bool &, sal_Bool, sal_Bool )
      89             : {
      90       30139 :     return 0; // not for uno cursor
      91             : }
      92             : 
      93           3 : void SwUnoCrsr::DoSetBidiLevelUpDown()
      94             : {
      95           3 :     return; // not for uno cursor
      96             : }
      97             : 
      98       43912 : sal_Bool SwUnoCrsr::IsSelOvr( int eFlags )
      99             : {
     100       43912 :     if( bRemainInSection )
     101             :     {
     102       40784 :         SwDoc* pDoc = GetDoc();
     103       40784 :         SwNodeIndex aOldIdx( *pDoc->GetNodes()[ GetSavePos()->nNode ] );
     104       40784 :         SwNodeIndex& rPtIdx = GetPoint()->nNode;
     105       40784 :         SwStartNode *pOldSttNd = aOldIdx.GetNode().StartOfSectionNode(),
     106       40784 :                     *pNewSttNd = rPtIdx.GetNode().StartOfSectionNode();
     107       40784 :         if( pOldSttNd != pNewSttNd )
     108             :         {
     109         662 :             bool bMoveDown = GetSavePos()->nNode < rPtIdx.GetIndex();
     110         662 :             bool bValidPos = false;
     111             : 
     112             :             // search the correct surrounded start node - which the index
     113             :             // can't leave.
     114        1443 :             while( pOldSttNd->IsSectionNode() )
     115         119 :                 pOldSttNd = pOldSttNd->StartOfSectionNode();
     116             : 
     117             :             // is the new index inside this surrounded section?
     118        1324 :             if( rPtIdx > *pOldSttNd &&
     119         662 :                 rPtIdx < pOldSttNd->EndOfSectionIndex() )
     120             :             {
     121             :                 // check if it a valid move inside this section
     122             :                 // (only over SwSection's !)
     123             :                 const SwStartNode* pInvalidNode;
     124         318 :                 do {
     125         328 :                     pInvalidNode = 0;
     126         328 :                     pNewSttNd = rPtIdx.GetNode().StartOfSectionNode();
     127             : 
     128         328 :                     const SwStartNode *pSttNd = pNewSttNd, *pEndNd = pOldSttNd;
     129         656 :                     if( pSttNd->EndOfSectionIndex() >
     130         328 :                         pEndNd->EndOfSectionIndex() )
     131             :                     {
     132           0 :                         pEndNd = pNewSttNd;
     133           0 :                         pSttNd = pOldSttNd;
     134             :                     }
     135             : 
     136         963 :                     while( pSttNd->GetIndex() > pEndNd->GetIndex() )
     137             :                     {
     138         307 :                         if( !pSttNd->IsSectionNode() )
     139          32 :                             pInvalidNode = pSttNd;
     140         307 :                         pSttNd = pSttNd->StartOfSectionNode();
     141             :                     }
     142         328 :                     if( pInvalidNode )
     143             :                     {
     144          16 :                         if( bMoveDown )
     145             :                         {
     146           2 :                             rPtIdx.Assign( *pInvalidNode->EndOfSectionNode(), 1 );
     147             : 
     148           2 :                             if( !rPtIdx.GetNode().IsCntntNode() &&
     149           0 :                                 ( !pDoc->GetNodes().GoNextSection( &rPtIdx ) ||
     150           0 :                                   rPtIdx > pOldSttNd->EndOfSectionIndex() ) )
     151           0 :                                 break;
     152             :                         }
     153             :                         else
     154             :                         {
     155          14 :                             rPtIdx.Assign( *pInvalidNode, -1 );
     156             : 
     157          59 :                             if( !rPtIdx.GetNode().IsCntntNode() &&
     158          16 :                                 ( !pDoc->GetNodes().GoPrevSection( &rPtIdx ) ||
     159          23 :                                   rPtIdx < *pOldSttNd ) )
     160          10 :                                 break;
     161             :                         }
     162             :                     }
     163             :                     else
     164         312 :                         bValidPos = true;
     165             :                 } while ( pInvalidNode );
     166             :             }
     167             : 
     168         662 :             if( bValidPos )
     169             :             {
     170         312 :                 SwCntntNode* pCNd = GetCntntNode();
     171         312 :                 GetPoint()->nContent.Assign( pCNd, (pCNd && !bMoveDown) ? pCNd->Len() : 0);
     172             :             }
     173             :             else
     174             :             {
     175         350 :                 rPtIdx = GetSavePos()->nNode;
     176         350 :                 GetPoint()->nContent.Assign( GetCntntNode(), GetSavePos()->nCntnt );
     177         350 :                 return sal_True;
     178             :             }
     179       40434 :         }
     180             :     }
     181       43562 :     return SwCursor::IsSelOvr( eFlags );
     182             : }
     183             : 
     184          34 : SwUnoTableCrsr::SwUnoTableCrsr(const SwPosition& rPos)
     185          34 :     : SwCursor(rPos,0,false), SwUnoCrsr(rPos), SwTableCursor(rPos), aTblSel(rPos,0,false)
     186             : {
     187          34 :     SetRemainInSection(sal_False);
     188          34 : }
     189             : 
     190         136 : SwUnoTableCrsr::~SwUnoTableCrsr()
     191             : {
     192         273 :     while( aTblSel.GetNext() != &aTblSel )
     193         205 :         delete aTblSel.GetNext();
     194         102 : }
     195             : 
     196          20 : sal_Bool SwUnoTableCrsr::IsSelOvr( int eFlags )
     197             : {
     198          20 :     sal_Bool bRet = SwUnoCrsr::IsSelOvr( eFlags );
     199          20 :     if( !bRet )
     200             :     {
     201          20 :         const SwTableNode* pTNd = GetPoint()->nNode.GetNode().FindTableNode();
     202          40 :         bRet = !(pTNd == GetDoc()->GetNodes()[ GetSavePos()->nNode ]->
     203          65 :                 FindTableNode() && (!HasMark() ||
     204          40 :                 pTNd == GetMark()->nNode.GetNode().FindTableNode() ));
     205             :     }
     206          20 :     return bRet;
     207             : }
     208             : 
     209         411 : void SwUnoTableCrsr::MakeBoxSels()
     210             : {
     211             :     const SwCntntNode* pCNd;
     212         411 :     bool bMakeTblCrsrs = true;
     213        1644 :     if( GetPoint()->nNode.GetIndex() && GetMark()->nNode.GetIndex() &&
     214        1227 :             0 != ( pCNd = GetCntntNode() ) && pCNd->getLayoutFrm( pCNd->GetDoc()->GetCurrentLayout() ) &&
     215        1221 :             0 != ( pCNd = GetCntntNode(false) ) && pCNd->getLayoutFrm( pCNd->GetDoc()->GetCurrentLayout() ) )
     216         405 :         bMakeTblCrsrs = GetDoc()->GetCurrentLayout()->MakeTblCrsrs( *this );
     217             : 
     218         411 :     if ( !bMakeTblCrsrs )
     219             :     {
     220           0 :         SwSelBoxes const& rTmpBoxes = GetSelectedBoxes();
     221           0 :         while (!rTmpBoxes.empty())
     222             :         {
     223           0 :             DeleteBox(0);
     224             :         }
     225             :     }
     226             : 
     227         411 :     if( IsChgd() )
     228             :     {
     229          39 :         SwTableCursor::MakeBoxSels( &aTblSel );
     230          39 :         if (!GetSelectedBoxesCount())
     231             :         {
     232             :             const SwTableBox* pBox;
     233           0 :             const SwNode* pBoxNd = GetPoint()->nNode.GetNode().FindTableBoxStartNode();
     234           0 :             const SwTableNode* pTblNd = pBoxNd ? pBoxNd->FindTableNode() : 0;
     235           0 :             if( pTblNd && 0 != ( pBox = pTblNd->GetTable().GetTblBox( pBoxNd->GetIndex() )) )
     236           0 :                 InsertBox( *pBox );
     237             :         }
     238             :     }
     239         411 : }
     240             : 
     241        3696 : SwUnoCrsrTbl::~SwUnoCrsrTbl()
     242             : {
     243        6806 :     while (!empty())
     244             :     {
     245        3110 :         delete *begin();
     246        3110 :         erase( begin() );
     247             :     }
     248        1959 : }
     249             : 
     250             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10