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

Generated by: LCOV version 1.10