LCOV - code coverage report
Current view: top level - sw/source/core/crsr - trvlfnfl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 170 0.6 %
Date: 2014-11-03 Functions: 2 14 14.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 <svx/svdmodel.hxx>
      21             : #include <svx/svdpage.hxx>
      22             : #include <crsrsh.hxx>
      23             : #include <doc.hxx>
      24             : #include <pagefrm.hxx>
      25             : #include <cntfrm.hxx>
      26             : #include <ftnfrm.hxx>
      27             : #include <viewimp.hxx>
      28             : #include <swcrsr.hxx>
      29             : #include <dflyobj.hxx>
      30             : #include <ndtxt.hxx>
      31             : #include <flyfrm.hxx>
      32             : #include <txtfrm.hxx>
      33             : #include <txtftn.hxx>
      34             : #include <ftnidx.hxx>
      35             : #include <viscrs.hxx>
      36             : #include <callnk.hxx>
      37             : 
      38           0 : bool SwCrsrShell::CallCrsrFN( FNCrsr fnCrsr )
      39             : {
      40           0 :     SwCallLink aLk( *this ); // watch Crsr-Moves
      41           0 :     SwCursor* pCrsr = getShellCrsr( true );
      42           0 :     bool bRet = (pCrsr->*fnCrsr)();
      43           0 :     if( bRet )
      44             :         UpdateCrsr( SwCrsrShell::SCROLLWIN | SwCrsrShell::CHKRANGE |
      45           0 :                     SwCrsrShell::READONLY );
      46           0 :     return bRet;
      47             : }
      48             : 
      49           0 : bool SwCursor::GotoFtnTxt()
      50             : {
      51             :     // jump from content to footnote
      52           0 :     bool bRet = false;
      53           0 :     SwTxtNode* pTxtNd = GetPoint()->nNode.GetNode().GetTxtNode();
      54             : 
      55             :     SwTxtAttr *const pFtn( (pTxtNd)
      56             :         ? pTxtNd->GetTxtAttrForCharAt(
      57           0 :             GetPoint()->nContent.GetIndex(), RES_TXTATR_FTN)
      58           0 :         : 0);
      59           0 :     if (pFtn)
      60             :     {
      61           0 :         SwCrsrSaveState aSaveState( *this );
      62           0 :         GetPoint()->nNode = *((SwTxtFtn*)pFtn)->GetStartNode();
      63             : 
      64           0 :         SwCntntNode* pCNd = GetDoc()->GetNodes().GoNextSection(
      65           0 :                                             &GetPoint()->nNode,
      66           0 :                                             true, !IsReadOnlyAvailable() );
      67           0 :         if( pCNd )
      68             :         {
      69           0 :             GetPoint()->nContent.Assign( pCNd, 0 );
      70             :             bRet = !IsSelOvr( nsSwCursorSelOverFlags::SELOVER_CHECKNODESSECTION |
      71           0 :                               nsSwCursorSelOverFlags::SELOVER_TOGGLE );
      72           0 :         }
      73             :     }
      74           0 :     return bRet;
      75             : }
      76             : 
      77           0 : bool SwCrsrShell::GotoFtnTxt()
      78             : {
      79           0 :     bool bRet = CallCrsrFN( &SwCursor::GotoFtnTxt );
      80           0 :     if( !bRet )
      81             :     {
      82           0 :         SwTxtNode* pTxtNd = _GetCrsr() ?
      83           0 :                    _GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode() : NULL;
      84           0 :         if( pTxtNd )
      85             :         {
      86           0 :             const SwFrm *pFrm = pTxtNd->getLayoutFrm( GetLayout(), &_GetCrsr()->GetSttPos(),
      87           0 :                                                  _GetCrsr()->Start() );
      88             :             const SwFtnBossFrm* pFtnBoss;
      89           0 :             bool bSkip = pFrm && pFrm->IsInFtn();
      90           0 :             while( pFrm && 0 != ( pFtnBoss = pFrm->FindFtnBossFrm() ) )
      91             :             {
      92           0 :                 if( 0 != ( pFrm = pFtnBoss->FindFtnCont() ) )
      93             :                 {
      94           0 :                     if( bSkip )
      95           0 :                         bSkip = false;
      96             :                     else
      97             :                     {
      98             :                         const SwCntntFrm* pCnt = static_cast<const SwLayoutFrm*>
      99           0 :                                                         (pFrm)->ContainsCntnt();
     100           0 :                         if( pCnt )
     101             :                         {
     102           0 :                             const SwCntntNode* pNode = pCnt->GetNode();
     103           0 :                             _GetCrsr()->GetPoint()->nNode = *pNode;
     104           0 :                             _GetCrsr()->GetPoint()->nContent.Assign(
     105             :                                 const_cast<SwCntntNode*>(pNode),
     106           0 :                                 static_cast<const SwTxtFrm*>(pCnt)->GetOfst() );
     107             :                             UpdateCrsr( SwCrsrShell::SCROLLWIN |
     108           0 :                                 SwCrsrShell::CHKRANGE | SwCrsrShell::READONLY );
     109           0 :                             bRet = true;
     110           0 :                             break;
     111             :                         }
     112             :                     }
     113             :                 }
     114           0 :                 if( pFtnBoss->GetNext() && !pFtnBoss->IsPageFrm() )
     115           0 :                     pFrm = pFtnBoss->GetNext();
     116             :                 else
     117           0 :                     pFrm = pFtnBoss->GetUpper();
     118             :             }
     119             :         }
     120             :     }
     121           0 :     return bRet;
     122             : }
     123             : 
     124           0 : bool SwCursor::GotoFtnAnchor()
     125             : {
     126             :     // jump from footnote to anchor
     127           0 :     const SwNode* pSttNd = GetNode().FindFootnoteStartNode();
     128           0 :     if( pSttNd )
     129             :     {
     130             :         // search in all footnotes in document for this StartIndex
     131             :         const SwTxtFtn* pTxtFtn;
     132           0 :         const SwFtnIdxs& rFtnArr = pSttNd->GetDoc()->GetFtnIdxs();
     133           0 :         for( size_t n = 0; n < rFtnArr.size(); ++n )
     134           0 :             if( 0 != ( pTxtFtn = rFtnArr[ n ])->GetStartNode() &&
     135           0 :                 pSttNd == &pTxtFtn->GetStartNode()->GetNode() )
     136             :             {
     137           0 :                 SwCrsrSaveState aSaveState( *this );
     138             : 
     139           0 :                 SwTxtNode& rTNd = (SwTxtNode&)pTxtFtn->GetTxtNode();
     140           0 :                 GetPoint()->nNode = rTNd;
     141           0 :                 GetPoint()->nContent.Assign( &rTNd, pTxtFtn->GetStart() );
     142             : 
     143             :                 return !IsSelOvr( nsSwCursorSelOverFlags::SELOVER_CHECKNODESSECTION |
     144           0 :                                   nsSwCursorSelOverFlags::SELOVER_TOGGLE );
     145             :             }
     146             :     }
     147           0 :     return false;
     148             : }
     149             : 
     150           0 : bool SwCrsrShell::GotoFtnAnchor()
     151             : {
     152             :     // jump from footnote to anchor
     153           0 :     SwCallLink aLk( *this ); // watch Crsr-Moves
     154           0 :     bool bRet = m_pCurCrsr->GotoFtnAnchor();
     155           0 :     if( bRet )
     156             :     {
     157             :         // special treatment for table header row
     158           0 :         m_pCurCrsr->GetPtPos() = Point();
     159             :         UpdateCrsr( SwCrsrShell::SCROLLWIN | SwCrsrShell::CHKRANGE |
     160           0 :                     SwCrsrShell::READONLY );
     161             :     }
     162           0 :     return bRet;
     163             : }
     164             : 
     165           0 : inline bool CmpLE( const SwTxtFtn& rFtn, sal_uLong nNd, sal_Int32 nCnt )
     166             : {
     167           0 :     const sal_uLong nTNd = rFtn.GetTxtNode().GetIndex();
     168           0 :     return nTNd < nNd || ( nTNd == nNd && rFtn.GetStart() <= nCnt );
     169             : }
     170             : 
     171           0 : inline bool CmpL( const SwTxtFtn& rFtn, sal_uLong nNd, sal_Int32 nCnt )
     172             : {
     173           0 :     const sal_uLong nTNd = rFtn.GetTxtNode().GetIndex();
     174           0 :     return nTNd < nNd || ( nTNd == nNd && rFtn.GetStart() < nCnt );
     175             : }
     176             : 
     177           0 : bool SwCursor::GotoNextFtnAnchor()
     178             : {
     179           0 :     const SwFtnIdxs& rFtnArr = GetDoc()->GetFtnIdxs();
     180           0 :     const SwTxtFtn* pTxtFtn = 0;
     181           0 :     size_t nPos = 0;
     182             : 
     183           0 :     if( rFtnArr.SeekEntry( GetPoint()->nNode, &nPos ))
     184             :     {
     185             :         // there is a footnote with this index, so search also for the next one
     186           0 :         if( nPos < rFtnArr.size() )
     187             :         {
     188           0 :             sal_uLong nNdPos = GetPoint()->nNode.GetIndex();
     189           0 :             const sal_Int32 nCntPos = GetPoint()->nContent.GetIndex();
     190             : 
     191           0 :             pTxtFtn = rFtnArr[ nPos ];
     192             :             // search forwards
     193           0 :             if( CmpLE( *pTxtFtn, nNdPos, nCntPos ) )
     194             :             {
     195           0 :                 pTxtFtn = 0;
     196           0 :                 for( ++nPos; nPos < rFtnArr.size(); ++nPos )
     197             :                 {
     198           0 :                     pTxtFtn = rFtnArr[ nPos ];
     199           0 :                     if( !CmpLE( *pTxtFtn, nNdPos, nCntPos ) )
     200           0 :                         break; // found
     201           0 :                     pTxtFtn = 0;
     202             :                 }
     203             :             }
     204           0 :             else if( nPos )
     205             :             {
     206             :                 // search backwards
     207           0 :                 pTxtFtn = 0;
     208           0 :                 while( nPos )
     209             :                 {
     210           0 :                     pTxtFtn = rFtnArr[ --nPos ];
     211           0 :                     if( CmpLE( *pTxtFtn, nNdPos, nCntPos ) )
     212             :                     {
     213           0 :                         pTxtFtn = rFtnArr[ ++nPos ];
     214           0 :                         break; // found
     215             :                     }
     216             :                 }
     217             :             }
     218             :         }
     219             :     }
     220           0 :     else if( nPos < rFtnArr.size() )
     221           0 :         pTxtFtn = rFtnArr[ nPos ];
     222             : 
     223           0 :     bool bRet = 0 != pTxtFtn;
     224           0 :     if( bRet )
     225             :     {
     226           0 :         SwCrsrSaveState aSaveState( *this );
     227             : 
     228           0 :         SwTxtNode& rTNd = (SwTxtNode&)pTxtFtn->GetTxtNode();
     229           0 :         GetPoint()->nNode = rTNd;
     230           0 :         GetPoint()->nContent.Assign( &rTNd, pTxtFtn->GetStart() );
     231           0 :         bRet = !IsSelOvr();
     232             :     }
     233           0 :     return bRet;
     234             : }
     235             : 
     236           0 : bool SwCursor::GotoPrevFtnAnchor()
     237             : {
     238           0 :     const SwFtnIdxs& rFtnArr = GetDoc()->GetFtnIdxs();
     239           0 :     const SwTxtFtn* pTxtFtn = 0;
     240           0 :     size_t nPos = 0;
     241             : 
     242           0 :     if( rFtnArr.SeekEntry( GetPoint()->nNode, &nPos ) )
     243             :     {
     244             :         // there is a footnote with this index, so search also for the next one
     245           0 :         sal_uLong nNdPos = GetPoint()->nNode.GetIndex();
     246           0 :         const sal_Int32 nCntPos = GetPoint()->nContent.GetIndex();
     247             : 
     248           0 :         pTxtFtn = rFtnArr[ nPos ];
     249             :         // search forwards
     250           0 :         if( CmpL( *pTxtFtn, nNdPos, nCntPos ))
     251             :         {
     252           0 :             for( ++nPos; nPos < rFtnArr.size(); ++nPos )
     253             :             {
     254           0 :                 pTxtFtn = rFtnArr[ nPos ];
     255           0 :                 if( !CmpL( *pTxtFtn, nNdPos, nCntPos ) )
     256             :                 {
     257           0 :                     pTxtFtn = rFtnArr[ nPos-1 ];
     258           0 :                     break;
     259             :                 }
     260             :             }
     261             :         }
     262           0 :         else if( nPos )
     263             :         {
     264             :             // search backwards
     265           0 :             pTxtFtn = 0;
     266           0 :             while( nPos )
     267             :             {
     268           0 :                 pTxtFtn = rFtnArr[ --nPos ];
     269           0 :                 if( CmpL( *pTxtFtn, nNdPos, nCntPos ))
     270           0 :                     break; // found
     271           0 :                 pTxtFtn = 0;
     272             :             }
     273             :         }
     274             :         else
     275           0 :             pTxtFtn = 0;
     276             :     }
     277           0 :     else if( nPos )
     278           0 :         pTxtFtn = rFtnArr[ nPos-1 ];
     279             : 
     280           0 :     bool bRet = 0 != pTxtFtn;
     281           0 :     if( bRet )
     282             :     {
     283           0 :         SwCrsrSaveState aSaveState( *this );
     284             : 
     285           0 :         SwTxtNode& rTNd = (SwTxtNode&)pTxtFtn->GetTxtNode();
     286           0 :         GetPoint()->nNode = rTNd;
     287           0 :         GetPoint()->nContent.Assign( &rTNd, pTxtFtn->GetStart() );
     288           0 :         bRet = !IsSelOvr();
     289             :     }
     290           0 :     return bRet;
     291             : }
     292             : 
     293           0 : bool SwCrsrShell::GotoNextFtnAnchor()
     294             : {
     295           0 :     return CallCrsrFN( &SwCursor::GotoNextFtnAnchor );
     296             : }
     297             : 
     298           0 : bool SwCrsrShell::GotoPrevFtnAnchor()
     299             : {
     300           0 :     return CallCrsrFN( &SwCursor::GotoPrevFtnAnchor );
     301             : }
     302             : 
     303             : /// jump from border to anchor
     304           0 : bool SwCrsrShell::GotoFlyAnchor()
     305             : {
     306           0 :     SET_CURR_SHELL( this );
     307           0 :     const SwFrm* pFrm = GetCurrFrm();
     308           0 :     do {
     309           0 :         pFrm = pFrm->GetUpper();
     310           0 :     } while( pFrm && !pFrm->IsFlyFrm() );
     311             : 
     312           0 :     if( !pFrm ) // no FlyFrame
     313           0 :         return false;
     314             : 
     315           0 :     SwCallLink aLk( *this ); // watch Crsr-Moves
     316           0 :     SwCrsrSaveState aSaveState( *m_pCurCrsr );
     317             : 
     318             :     // jump in BodyFrame closest to FlyFrame
     319           0 :     SwRect aTmpRect( m_aCharRect );
     320           0 :     if( !pFrm->Frm().IsInside( aTmpRect ))
     321           0 :         aTmpRect = pFrm->Frm();
     322           0 :     Point aPt( aTmpRect.Left(), aTmpRect.Top() +
     323           0 :                 ( aTmpRect.Bottom() - aTmpRect.Top() ) / 2 );
     324           0 :     aPt.setX(aPt.getX() > (pFrm->Frm().Left() + (pFrm->Frm().SSize().Width() / 2 ))
     325           0 :                 ? pFrm->Frm().Right()
     326           0 :                 : pFrm->Frm().Left());
     327             : 
     328           0 :     const SwPageFrm* pPageFrm = pFrm->FindPageFrm();
     329           0 :     const SwCntntFrm* pFndFrm = pPageFrm->GetCntntPos( aPt, false, true );
     330           0 :     pFndFrm->GetCrsrOfst( m_pCurCrsr->GetPoint(), aPt );
     331             : 
     332           0 :     bool bRet = !m_pCurCrsr->IsInProtectTable() && !m_pCurCrsr->IsSelOvr();
     333           0 :     if( bRet )
     334             :         UpdateCrsr( SwCrsrShell::SCROLLWIN | SwCrsrShell::CHKRANGE |
     335           0 :                     SwCrsrShell::READONLY );
     336           0 :     return bRet;
     337         270 : }
     338             : 
     339             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10