LCOV - code coverage report
Current view: top level - sw/source/core/crsr - crbm.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 39 109 35.8 %
Date: 2014-11-03 Functions: 10 18 55.6 %
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 "crsrsh.hxx"
      21             : #include "ndtxt.hxx"
      22             : #include <docary.hxx>
      23             : #include "IMark.hxx"
      24             : #include "callnk.hxx"
      25             : #include "swcrsr.hxx"
      26             : #include <IDocumentMarkAccess.hxx>
      27             : #include <IDocumentSettingAccess.hxx>
      28             : 
      29             : using namespace std;
      30             : 
      31             : namespace
      32             : {
      33           2 :     struct CrsrStateHelper
      34             :     {
      35           2 :         CrsrStateHelper(SwCrsrShell& rShell)
      36             :             : m_aLink(rShell)
      37           2 :             , m_pCrsr(rShell.GetSwCrsr())
      38           4 :             , m_aSaveState(*m_pCrsr)
      39           2 :         { }
      40             : 
      41           2 :         void SetCrsrToMark(::sw::mark::IMark const * const pMark)
      42             :         {
      43           2 :             *(m_pCrsr->GetPoint()) = pMark->GetMarkStart();
      44           2 :             if(pMark->IsExpanded())
      45             :             {
      46           2 :                 m_pCrsr->SetMark();
      47           2 :                 *(m_pCrsr->GetMark()) = pMark->GetMarkEnd();
      48             :             }
      49           2 :         }
      50             : 
      51             :         /// returns true if the Cursor had been rolled back
      52           2 :         bool RollbackIfIllegal()
      53             :         {
      54           2 :             if(m_pCrsr->IsSelOvr(nsSwCursorSelOverFlags::SELOVER_CHECKNODESSECTION
      55           2 :                 | nsSwCursorSelOverFlags::SELOVER_TOGGLE))
      56             :             {
      57           0 :                 m_pCrsr->DeleteMark();
      58           0 :                 m_pCrsr->RestoreSavePos();
      59           0 :                 return true;
      60             :             }
      61           2 :             return false;
      62             :         }
      63             : 
      64             :         SwCallLink m_aLink;
      65             :         SwCursor* m_pCrsr;
      66             :         SwCrsrSaveState m_aSaveState;
      67             :     };
      68             : 
      69           0 :     static bool lcl_ReverseMarkOrderingByEnd(const IDocumentMarkAccess::pMark_t& rpFirst,
      70             :         const IDocumentMarkAccess::pMark_t& rpSecond)
      71             :     {
      72           0 :         return rpFirst->GetMarkEnd() > rpSecond->GetMarkEnd();
      73             :     }
      74             : 
      75           0 :     static bool lcl_IsInvisibleBookmark(IDocumentMarkAccess::pMark_t pMark)
      76             :     {
      77           0 :         return IDocumentMarkAccess::GetType(*pMark) != IDocumentMarkAccess::BOOKMARK;
      78             :     }
      79             : }
      80             : 
      81             : // at CurCrsr.SPoint
      82           2 : ::sw::mark::IMark* SwCrsrShell::SetBookmark(
      83             :     const vcl::KeyCode& rCode,
      84             :     const OUString& rName,
      85             :     const OUString& rShortName,
      86             :     IDocumentMarkAccess::MarkType eMark)
      87             : {
      88           2 :     StartAction();
      89           2 :     ::sw::mark::IMark* pMark = getIDocumentMarkAccess()->makeMark(
      90           2 :         *GetCrsr(),
      91             :         rName,
      92           4 :         eMark);
      93           2 :     ::sw::mark::IBookmark* pBookmark = dynamic_cast< ::sw::mark::IBookmark* >(pMark);
      94           2 :     if(pBookmark)
      95             :     {
      96           0 :         pBookmark->SetKeyCode(rCode);
      97           0 :         pBookmark->SetShortName(rShortName);
      98             :     }
      99           2 :     EndAction();
     100           2 :     return pMark;
     101             : }
     102             : // set CurCrsr.SPoint
     103             : 
     104           0 : bool SwCrsrShell::GotoMark(const ::sw::mark::IMark* const pMark, bool bAtStart)
     105             : {
     106             :     // watch Crsr-Moves
     107           0 :     CrsrStateHelper aCrsrSt(*this);
     108           0 :     if ( bAtStart )
     109           0 :         *(aCrsrSt.m_pCrsr)->GetPoint() = pMark->GetMarkStart();
     110             :     else
     111           0 :         *(aCrsrSt.m_pCrsr)->GetPoint() = pMark->GetMarkEnd();
     112             : 
     113           0 :     if(aCrsrSt.RollbackIfIllegal()) return false;
     114             : 
     115           0 :     UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
     116           0 :     return true;
     117             : }
     118             : 
     119           0 : bool SwCrsrShell::GotoMark(const ::sw::mark::IMark* const pMark)
     120             : {
     121             :     // watch Crsr-Moves
     122           0 :     CrsrStateHelper aCrsrSt(*this);
     123           0 :     aCrsrSt.SetCrsrToMark(pMark);
     124             : 
     125           0 :     if(aCrsrSt.RollbackIfIllegal()) return false;
     126             : 
     127           0 :     UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
     128           0 :     return true;
     129             : }
     130             : 
     131           0 : bool SwCrsrShell::GoNextBookmark()
     132             : {
     133           0 :     IDocumentMarkAccess* const pMarkAccess = getIDocumentMarkAccess();
     134           0 :     IDocumentMarkAccess::container_t vCandidates;
     135             :     remove_copy_if(
     136             :         upper_bound( // finds the first that is starting after
     137           0 :             pMarkAccess->getBookmarksBegin(),
     138           0 :             pMarkAccess->getBookmarksEnd(),
     139           0 :             *GetCrsr()->GetPoint(),
     140             :             sw::mark::CompareIMarkStartsAfter()),
     141           0 :         pMarkAccess->getBookmarksEnd(),
     142             :         back_inserter(vCandidates),
     143           0 :         &lcl_IsInvisibleBookmark);
     144             : 
     145             :     // watch Crsr-Moves
     146           0 :     CrsrStateHelper aCrsrSt(*this);
     147           0 :     IDocumentMarkAccess::const_iterator_t ppMark = vCandidates.begin();
     148           0 :     for(; ppMark!=vCandidates.end(); ++ppMark)
     149             :     {
     150           0 :         aCrsrSt.SetCrsrToMark(ppMark->get());
     151           0 :         if(!aCrsrSt.RollbackIfIllegal())
     152           0 :             break; // found legal move
     153             :     }
     154           0 :     if(ppMark==vCandidates.end())
     155             :     {
     156           0 :         SttEndDoc(false);
     157           0 :         return false;
     158             :     }
     159             : 
     160           0 :     UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
     161           0 :     return true;
     162             : }
     163             : 
     164           0 : bool SwCrsrShell::GoPrevBookmark()
     165             : {
     166           0 :     IDocumentMarkAccess* const pMarkAccess = getIDocumentMarkAccess();
     167             :     // candidates from which to choose the mark before
     168             :     // no need to consider marks starting after rPos
     169           0 :     IDocumentMarkAccess::container_t vCandidates;
     170             :     remove_copy_if(
     171           0 :         pMarkAccess->getBookmarksBegin(),
     172             :         upper_bound(
     173           0 :             pMarkAccess->getBookmarksBegin(),
     174           0 :             pMarkAccess->getBookmarksEnd(),
     175           0 :             *GetCrsr()->GetPoint(),
     176             :             sw::mark::CompareIMarkStartsAfter()),
     177             :         back_inserter(vCandidates),
     178           0 :         &lcl_IsInvisibleBookmark);
     179             :     sort(
     180             :         vCandidates.begin(),
     181             :         vCandidates.end(),
     182           0 :         &lcl_ReverseMarkOrderingByEnd);
     183             : 
     184             :     // watch Crsr-Moves
     185           0 :     CrsrStateHelper aCrsrSt(*this);
     186           0 :     IDocumentMarkAccess::const_iterator_t ppMark = vCandidates.begin();
     187           0 :     for(; ppMark!=vCandidates.end(); ++ppMark)
     188             :     {
     189             :         // ignoring those not ending before the Crsr
     190             :         // (we were only able to eliminate those starting
     191             :         // behind the Crsr by the upper_bound(..)
     192             :         // above)
     193           0 :         if(!(**ppMark).EndsBefore(*GetCrsr()->GetPoint()))
     194           0 :             continue;
     195           0 :         aCrsrSt.SetCrsrToMark(ppMark->get());
     196           0 :         if(!aCrsrSt.RollbackIfIllegal())
     197           0 :             break; // found legal move
     198             :     }
     199           0 :     if(ppMark==vCandidates.end())
     200             :     {
     201           0 :         SttEndDoc(true);
     202           0 :         return false;
     203             :     }
     204             : 
     205           0 :     UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
     206           0 :     return true;
     207             : }
     208             : 
     209        4708 : bool SwCrsrShell::IsFormProtected()
     210             : {
     211        4708 :     return getIDocumentSettingAccess()->get(IDocumentSettingAccess::PROTECT_FORM);
     212             : }
     213             : 
     214           0 : ::sw::mark::IFieldmark* SwCrsrShell::GetCurrentFieldmark()
     215             : {
     216             :     // TODO: Refactor
     217           0 :     SwPosition pos(*GetCrsr()->GetPoint());
     218           0 :     return getIDocumentMarkAccess()->getFieldmarkFor(pos);
     219             : }
     220             : 
     221           2 : ::sw::mark::IFieldmark* SwCrsrShell::GetFieldmarkAfter()
     222             : {
     223           2 :     SwPosition pos(*GetCrsr()->GetPoint());
     224           2 :     return getIDocumentMarkAccess()->getFieldmarkAfter(pos);
     225             : }
     226             : 
     227           0 : ::sw::mark::IFieldmark* SwCrsrShell::GetFieldmarkBefore()
     228             : {
     229           0 :     SwPosition pos(*GetCrsr()->GetPoint());
     230           0 :     return getIDocumentMarkAccess()->getFieldmarkBefore(pos);
     231             : }
     232             : 
     233           2 : bool SwCrsrShell::GotoFieldmark(::sw::mark::IFieldmark const * const pMark)
     234             : {
     235           2 :     if(pMark==NULL) return false;
     236             : 
     237             :     // watch Crsr-Moves
     238           2 :     CrsrStateHelper aCrsrSt(*this);
     239           2 :     aCrsrSt.SetCrsrToMark(pMark);
     240           2 :     aCrsrSt.m_pCrsr->GetPoint()->nContent++;
     241           2 :     aCrsrSt.m_pCrsr->GetMark()->nContent--;
     242             : 
     243           2 :     if(aCrsrSt.RollbackIfIllegal()) return false;
     244             : 
     245           2 :     UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
     246           2 :     return true;
     247         270 : }
     248             : 
     249             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10