LCOV - code coverage report
Current view: top level - sw/source/core/crsr - trvlfnfl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 170 0.6 %
Date: 2015-06-13 12:38:46 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::GotoFootnoteText()
      50             : {
      51             :     // jump from content to footnote
      52           0 :     bool bRet = false;
      53           0 :     SwTextNode* pTextNd = GetPoint()->nNode.GetNode().GetTextNode();
      54             : 
      55             :     SwTextAttr *const pFootnote( (pTextNd)
      56             :         ? pTextNd->GetTextAttrForCharAt(
      57           0 :             GetPoint()->nContent.GetIndex(), RES_TXTATR_FTN)
      58           0 :         : 0);
      59           0 :     if (pFootnote)
      60             :     {
      61           0 :         SwCrsrSaveState aSaveState( *this );
      62           0 :         GetPoint()->nNode = *static_cast<SwTextFootnote*>(pFootnote)->GetStartNode();
      63             : 
      64           0 :         SwContentNode* 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::GotoFootnoteText()
      78             : {
      79           0 :     bool bRet = CallCrsrFN( &SwCursor::GotoFootnoteText );
      80           0 :     if( !bRet )
      81             :     {
      82           0 :         SwTextNode* pTextNd = _GetCrsr() ?
      83           0 :                    _GetCrsr()->GetPoint()->nNode.GetNode().GetTextNode() : NULL;
      84           0 :         if( pTextNd )
      85             :         {
      86           0 :             const SwFrm *pFrm = pTextNd->getLayoutFrm( GetLayout(), &_GetCrsr()->GetSttPos(),
      87           0 :                                                  _GetCrsr()->Start() );
      88             :             const SwFootnoteBossFrm* pFootnoteBoss;
      89           0 :             bool bSkip = pFrm && pFrm->IsInFootnote();
      90           0 :             while( pFrm && 0 != ( pFootnoteBoss = pFrm->FindFootnoteBossFrm() ) )
      91             :             {
      92           0 :                 if( 0 != ( pFrm = pFootnoteBoss->FindFootnoteCont() ) )
      93             :                 {
      94           0 :                     if( bSkip )
      95           0 :                         bSkip = false;
      96             :                     else
      97             :                     {
      98             :                         const SwContentFrm* pCnt = static_cast<const SwLayoutFrm*>
      99           0 :                                                         (pFrm)->ContainsContent();
     100           0 :                         if( pCnt )
     101             :                         {
     102           0 :                             const SwContentNode* pNode = pCnt->GetNode();
     103           0 :                             _GetCrsr()->GetPoint()->nNode = *pNode;
     104           0 :                             _GetCrsr()->GetPoint()->nContent.Assign(
     105             :                                 const_cast<SwContentNode*>(pNode),
     106           0 :                                 static_cast<const SwTextFrm*>(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( pFootnoteBoss->GetNext() && !pFootnoteBoss->IsPageFrm() )
     115           0 :                     pFrm = pFootnoteBoss->GetNext();
     116             :                 else
     117           0 :                     pFrm = pFootnoteBoss->GetUpper();
     118             :             }
     119             :         }
     120             :     }
     121           0 :     return bRet;
     122             : }
     123             : 
     124           0 : bool SwCursor::GotoFootnoteAnchor()
     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 SwTextFootnote* pTextFootnote;
     132           0 :         const SwFootnoteIdxs& rFootnoteArr = pSttNd->GetDoc()->GetFootnoteIdxs();
     133           0 :         for( size_t n = 0; n < rFootnoteArr.size(); ++n )
     134           0 :             if( 0 != ( pTextFootnote = rFootnoteArr[ n ])->GetStartNode() &&
     135           0 :                 pSttNd == &pTextFootnote->GetStartNode()->GetNode() )
     136             :             {
     137           0 :                 SwCrsrSaveState aSaveState( *this );
     138             : 
     139           0 :                 SwTextNode& rTNd = (SwTextNode&)pTextFootnote->GetTextNode();
     140           0 :                 GetPoint()->nNode = rTNd;
     141           0 :                 GetPoint()->nContent.Assign( &rTNd, pTextFootnote->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::GotoFootnoteAnchor()
     151             : {
     152             :     // jump from footnote to anchor
     153           0 :     SwCallLink aLk( *this ); // watch Crsr-Moves
     154           0 :     bool bRet = m_pCurCrsr->GotoFootnoteAnchor();
     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 SwTextFootnote& rFootnote, sal_uLong nNd, sal_Int32 nCnt )
     166             : {
     167           0 :     const sal_uLong nTNd = rFootnote.GetTextNode().GetIndex();
     168           0 :     return nTNd < nNd || ( nTNd == nNd && rFootnote.GetStart() <= nCnt );
     169             : }
     170             : 
     171           0 : inline bool CmpL( const SwTextFootnote& rFootnote, sal_uLong nNd, sal_Int32 nCnt )
     172             : {
     173           0 :     const sal_uLong nTNd = rFootnote.GetTextNode().GetIndex();
     174           0 :     return nTNd < nNd || ( nTNd == nNd && rFootnote.GetStart() < nCnt );
     175             : }
     176             : 
     177           0 : bool SwCursor::GotoNextFootnoteAnchor()
     178             : {
     179           0 :     const SwFootnoteIdxs& rFootnoteArr = GetDoc()->GetFootnoteIdxs();
     180           0 :     const SwTextFootnote* pTextFootnote = 0;
     181           0 :     size_t nPos = 0;
     182             : 
     183           0 :     if( rFootnoteArr.SeekEntry( GetPoint()->nNode, &nPos ))
     184             :     {
     185             :         // there is a footnote with this index, so search also for the next one
     186           0 :         if( nPos < rFootnoteArr.size() )
     187             :         {
     188           0 :             sal_uLong nNdPos = GetPoint()->nNode.GetIndex();
     189           0 :             const sal_Int32 nCntPos = GetPoint()->nContent.GetIndex();
     190             : 
     191           0 :             pTextFootnote = rFootnoteArr[ nPos ];
     192             :             // search forwards
     193           0 :             if( CmpLE( *pTextFootnote, nNdPos, nCntPos ) )
     194             :             {
     195           0 :                 pTextFootnote = 0;
     196           0 :                 for( ++nPos; nPos < rFootnoteArr.size(); ++nPos )
     197             :                 {
     198           0 :                     pTextFootnote = rFootnoteArr[ nPos ];
     199           0 :                     if( !CmpLE( *pTextFootnote, nNdPos, nCntPos ) )
     200           0 :                         break; // found
     201           0 :                     pTextFootnote = 0;
     202             :                 }
     203             :             }
     204           0 :             else if( nPos )
     205             :             {
     206             :                 // search backwards
     207           0 :                 pTextFootnote = 0;
     208           0 :                 while( nPos )
     209             :                 {
     210           0 :                     pTextFootnote = rFootnoteArr[ --nPos ];
     211           0 :                     if( CmpLE( *pTextFootnote, nNdPos, nCntPos ) )
     212             :                     {
     213           0 :                         pTextFootnote = rFootnoteArr[ ++nPos ];
     214           0 :                         break; // found
     215             :                     }
     216             :                 }
     217             :             }
     218             :         }
     219             :     }
     220           0 :     else if( nPos < rFootnoteArr.size() )
     221           0 :         pTextFootnote = rFootnoteArr[ nPos ];
     222             : 
     223           0 :     bool bRet = 0 != pTextFootnote;
     224           0 :     if( bRet )
     225             :     {
     226           0 :         SwCrsrSaveState aSaveState( *this );
     227             : 
     228           0 :         SwTextNode& rTNd = (SwTextNode&)pTextFootnote->GetTextNode();
     229           0 :         GetPoint()->nNode = rTNd;
     230           0 :         GetPoint()->nContent.Assign( &rTNd, pTextFootnote->GetStart() );
     231           0 :         bRet = !IsSelOvr();
     232             :     }
     233           0 :     return bRet;
     234             : }
     235             : 
     236           0 : bool SwCursor::GotoPrevFootnoteAnchor()
     237             : {
     238           0 :     const SwFootnoteIdxs& rFootnoteArr = GetDoc()->GetFootnoteIdxs();
     239           0 :     const SwTextFootnote* pTextFootnote = 0;
     240           0 :     size_t nPos = 0;
     241             : 
     242           0 :     if( rFootnoteArr.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 :         pTextFootnote = rFootnoteArr[ nPos ];
     249             :         // search forwards
     250           0 :         if( CmpL( *pTextFootnote, nNdPos, nCntPos ))
     251             :         {
     252           0 :             for( ++nPos; nPos < rFootnoteArr.size(); ++nPos )
     253             :             {
     254           0 :                 pTextFootnote = rFootnoteArr[ nPos ];
     255           0 :                 if( !CmpL( *pTextFootnote, nNdPos, nCntPos ) )
     256             :                 {
     257           0 :                     pTextFootnote = rFootnoteArr[ nPos-1 ];
     258           0 :                     break;
     259             :                 }
     260             :             }
     261             :         }
     262           0 :         else if( nPos )
     263             :         {
     264             :             // search backwards
     265           0 :             pTextFootnote = 0;
     266           0 :             while( nPos )
     267             :             {
     268           0 :                 pTextFootnote = rFootnoteArr[ --nPos ];
     269           0 :                 if( CmpL( *pTextFootnote, nNdPos, nCntPos ))
     270           0 :                     break; // found
     271           0 :                 pTextFootnote = 0;
     272             :             }
     273             :         }
     274             :         else
     275           0 :             pTextFootnote = 0;
     276             :     }
     277           0 :     else if( nPos )
     278           0 :         pTextFootnote = rFootnoteArr[ nPos-1 ];
     279             : 
     280           0 :     bool bRet = 0 != pTextFootnote;
     281           0 :     if( bRet )
     282             :     {
     283           0 :         SwCrsrSaveState aSaveState( *this );
     284             : 
     285           0 :         SwTextNode& rTNd = (SwTextNode&)pTextFootnote->GetTextNode();
     286           0 :         GetPoint()->nNode = rTNd;
     287           0 :         GetPoint()->nContent.Assign( &rTNd, pTextFootnote->GetStart() );
     288           0 :         bRet = !IsSelOvr();
     289             :     }
     290           0 :     return bRet;
     291             : }
     292             : 
     293           0 : bool SwCrsrShell::GotoNextFootnoteAnchor()
     294             : {
     295           0 :     return CallCrsrFN( &SwCursor::GotoNextFootnoteAnchor );
     296             : }
     297             : 
     298           0 : bool SwCrsrShell::GotoPrevFootnoteAnchor()
     299             : {
     300           0 :     return CallCrsrFN( &SwCursor::GotoPrevFootnoteAnchor );
     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 SwContentFrm* pFndFrm = pPageFrm->GetContentPos( 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         177 : }
     338             : 
     339             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11