LCOV - code coverage report
Current view: top level - sw/inc - swcrsr.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 31 36 86.1 %
Date: 2014-11-03 Functions: 24 29 82.8 %
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             : #ifndef INCLUDED_SW_INC_SWCRSR_HXX
      20             : #define INCLUDED_SW_INC_SWCRSR_HXX
      21             : 
      22             : #include <com/sun/star/i18n/WordType.hpp>
      23             : 
      24             : #include <pam.hxx>
      25             : #include <tblsel.hxx>
      26             : #include <cshtyp.hxx>
      27             : 
      28             : struct _SwCursor_SavePos;
      29             : 
      30             : namespace com { namespace sun { namespace star { namespace util {
      31             :     struct SearchOptions;
      32             : } } } }
      33             : 
      34             : // Base structure for parameters of the find-methods.
      35             : // Returns values of found-call.
      36             : const int FIND_NOT_FOUND    = 0;
      37             : const int FIND_FOUND        = 1;
      38             : const int FIND_NO_RING      = 2;
      39             : 
      40          18 : struct SwFindParas
      41             : {
      42             :     virtual int Find( SwPaM*, SwMoveFn, const SwPaM*, bool ) = 0;
      43             :     virtual bool IsReplaceMode() const = 0;
      44             : 
      45             : protected:
      46          18 :     ~SwFindParas() {}
      47             : };
      48             : 
      49             : typedef sal_uInt16 SwCursorSelOverFlags;
      50             : namespace nsSwCursorSelOverFlags
      51             : {
      52             :     const SwCursorSelOverFlags SELOVER_NONE                = 0x00;
      53             :     const SwCursorSelOverFlags SELOVER_CHECKNODESSECTION   = 0x01;
      54             :     const SwCursorSelOverFlags SELOVER_TOGGLE              = 0x02;
      55             :     const SwCursorSelOverFlags SELOVER_ENABLEREVDIREKTION  = 0x04;
      56             :     const SwCursorSelOverFlags SELOVER_CHANGEPOS           = 0x08;
      57             : }
      58             : 
      59           0 : class SW_DLLPUBLIC SwCursor : public SwPaM
      60             : {
      61             :     friend class SwCrsrSaveState;
      62             : 
      63             :     _SwCursor_SavePos* pSavePos;
      64             :     long mnRowSpanOffset;        // required for travelling in tabs with rowspans
      65             :     sal_uInt8 nCursorBidiLevel;       // bidi level of the cursor
      66             :     bool mbColumnSelection;      // true: cursor is aprt of a column selection
      67             : 
      68             :     sal_uLong FindAll( SwFindParas& , SwDocPositions, SwDocPositions, FindRanges, bool& bCancel );
      69             : 
      70             :     using SwPaM::Find;
      71             : 
      72             : protected:
      73             :     virtual _SwCursor_SavePos* CreateNewSavePos() const;
      74             :     void SaveState();
      75             :     void RestoreState();
      76             : 
      77      115218 :     const _SwCursor_SavePos* GetSavePos() const { return pSavePos; }
      78             : 
      79             :     virtual const SwCntntFrm* DoSetBidiLevelLeftRight(
      80             :         bool & io_rbLeft, bool bVisualAllowed, bool bInsertCrsr);
      81             :     virtual void DoSetBidiLevelUpDown();
      82             :     virtual bool IsSelOvrCheck(int eFlags);
      83             : 
      84             : public:
      85             :     // single argument ctors shall be explicit.
      86             :     SwCursor( const SwPosition &rPos, SwPaM* pRing, bool bColumnSel );
      87             :     virtual ~SwCursor();
      88             : 
      89             :     // @@@ semantic: no copy ctor.
      90             :     SwCursor( SwCursor& rCpy);
      91             : 
      92             : public:
      93             : 
      94             :     virtual SwCursor* Create( SwPaM* pRing = 0 ) const;
      95             : 
      96             :     virtual short MaxReplaceArived(); //returns RET_YES/RET_CANCEL/RET_NO
      97             :     virtual void SaveTblBoxCntnt( const SwPosition* pPos = 0 );
      98             : 
      99             :     void FillFindPos( SwDocPositions ePos, SwPosition& rPos ) const;
     100             :     SwMoveFnCollection* MakeFindRange( SwDocPositions, SwDocPositions,
     101             :                                         SwPaM* ) const;
     102             : 
     103             :     sal_uLong Find( const com::sun::star::util::SearchOptions& rSearchOpt,
     104             :                 bool bSearchInNotes,
     105             :                 SwDocPositions nStart, SwDocPositions nEnde,
     106             :                 bool& bCancel,
     107             :                 FindRanges = FND_IN_BODY,
     108             :                 bool bReplace = false );
     109             :     sal_uLong Find( const SwTxtFmtColl& rFmtColl,
     110             :                 SwDocPositions nStart, SwDocPositions nEnde,
     111             :                 bool& bCancel,
     112             :                 FindRanges = FND_IN_BODY,
     113             :                 const SwTxtFmtColl* pReplFmt = 0 );
     114             :     sal_uLong Find( const SfxItemSet& rSet, bool bNoCollections,
     115             :                 SwDocPositions nStart, SwDocPositions nEnde,
     116             :                 bool& bCancel,
     117             :                 FindRanges = FND_IN_BODY,
     118             :                 const com::sun::star::util::SearchOptions* pSearchOpt = 0,
     119             :                 const SfxItemSet* rReplSet = 0 );
     120             : 
     121             :     // UI versions
     122             :     bool IsStartWord( sal_Int16 nWordType = com::sun::star::i18n::WordType::ANYWORD_IGNOREWHITESPACES ) const;
     123             :     bool IsEndWord( sal_Int16 nWordType = com::sun::star::i18n::WordType::ANYWORD_IGNOREWHITESPACES ) const;
     124             :     bool IsInWord( sal_Int16 nWordType = com::sun::star::i18n::WordType::ANYWORD_IGNOREWHITESPACES ) const;
     125             :     bool IsStartEndSentence( bool bEnd ) const;
     126             :     bool GoStartWord();
     127             :     bool GoEndWord();
     128             :     bool GoNextWord();
     129             :     bool GoPrevWord();
     130             :     bool SelectWord( SwViewShell* pViewShell, const Point* pPt = 0 );
     131             : 
     132             :     // API versions of above functions (will be used with a different
     133             :     // WordType for the break iterator)
     134             :     bool IsStartWordWT( sal_Int16 nWordType ) const;
     135             :     bool IsEndWordWT( sal_Int16 nWordType ) const;
     136             :     bool IsInWordWT( sal_Int16 nWordType ) const;
     137             :     bool GoStartWordWT( sal_Int16 nWordType );
     138             :     bool GoEndWordWT( sal_Int16 nWordType );
     139             :     bool GoNextWordWT( sal_Int16 nWordType );
     140             :     bool GoPrevWordWT( sal_Int16 nWordType );
     141             :     bool SelectWordWT( SwViewShell* pViewShell, sal_Int16 nWordType, const Point* pPt = 0 );
     142             : 
     143             :     enum SentenceMoveType
     144             :     {
     145             :         NEXT_SENT,
     146             :         PREV_SENT,
     147             :         START_SENT,
     148             :         END_SENT
     149             :     };
     150             :     bool GoSentence(SentenceMoveType eMoveType);
     151           0 :     bool GoNextSentence(){return GoSentence(NEXT_SENT);}
     152           0 :     bool GoEndSentence(){return GoSentence(END_SENT);}
     153             :     bool GoPrevSentence(){return GoSentence(PREV_SENT);}
     154           0 :     bool GoStartSentence(){return GoSentence(START_SENT);}
     155             :     bool ExpandToSentenceBorders();
     156             : 
     157             :     virtual bool LeftRight( bool bLeft, sal_uInt16 nCnt, sal_uInt16 nMode,
     158             :         bool bAllowVisual, bool bSkipHidden, bool bInsertCrsr );
     159             :     bool UpDown( bool bUp, sal_uInt16 nCnt, Point* pPt, long nUpDownX );
     160             :     bool LeftRightMargin( bool bLeftMargin, bool bAPI = false );
     161             :     bool IsAtLeftRightMargin( bool bLeftMargin, bool bAPI = false ) const;
     162             :     bool SttEndDoc( bool bSttDoc );
     163             :     bool GoPrevNextCell( bool bNext, sal_uInt16 nCnt );
     164             : 
     165       65404 :     bool Left( sal_uInt16 nCnt, sal_uInt16 nMode, bool bAllowVisual, bool bSkipHidden )
     166       65404 :                                     { return LeftRight( true, nCnt, nMode, bAllowVisual, bSkipHidden, false ); }
     167        9288 :     bool Right( sal_uInt16 nCnt, sal_uInt16 nMode, bool bAllowVisual, bool bSkipHidden )
     168        9288 :                                     { return LeftRight( false, nCnt, nMode, bAllowVisual, bSkipHidden, false ); }
     169           4 :     bool GoNextCell( sal_uInt16 nCnt = 1 )  { return GoPrevNextCell( true, nCnt ); }
     170           4 :     bool GoPrevCell( sal_uInt16 nCnt = 1 )  { return GoPrevNextCell( false, nCnt ); }
     171             :     virtual bool GotoTable( const OUString& rName );
     172             :     bool GotoTblBox( const OUString& rName );
     173             :     bool GotoRegion( const OUString& rName );
     174             :     bool GotoFtnAnchor();
     175             :     bool GotoFtnTxt();
     176             :     bool GotoNextFtnAnchor();
     177             :     bool GotoPrevFtnAnchor();
     178             :     bool GotoNextFtnCntnt();
     179             :     bool GotoPrevFtnCntnt();
     180             : 
     181             :     bool MovePara( SwWhichPara, SwPosPara );
     182             :     bool MoveSection( SwWhichSection, SwPosSection );
     183             :     bool MoveTable( SwWhichTable, SwPosTable );
     184             :     bool MoveRegion( SwWhichRegion, SwPosRegion );
     185             : 
     186             :     // Is there a selection of content in table?
     187             :     // Return value indicates if cursor remains at its old position.
     188             :     virtual bool IsSelOvr( int eFlags =
     189             :                                 ( nsSwCursorSelOverFlags::SELOVER_CHECKNODESSECTION |
     190             :                                   nsSwCursorSelOverFlags::SELOVER_TOGGLE |
     191             :                                   nsSwCursorSelOverFlags::SELOVER_CHANGEPOS ));
     192             :     virtual bool IsInProtectTable( bool bMove = false,
     193             :                                    bool bChgCrsr = true );
     194             :     bool IsNoCntnt() const;
     195             : 
     196             :     /** Restore cursor state to the one saved by SwCrsrSaveState **/
     197             :     void RestoreSavePos();
     198             : 
     199             :     // true: cursor can be set at this position.
     200             :     virtual bool IsAtValidPos( bool bPoint = true ) const;
     201             : 
     202             :     // Is cursor allowed in ready only ranges?
     203             :     virtual bool IsReadOnlyAvailable() const;
     204             : 
     205             :     virtual bool IsSkipOverProtectSections() const;
     206             :     virtual bool IsSkipOverHiddenSections() const;
     207             : 
     208      144258 :     sal_uInt8 GetCrsrBidiLevel() const { return nCursorBidiLevel; }
     209          76 :     void SetCrsrBidiLevel( sal_uInt8 nNewLevel ) { nCursorBidiLevel = nNewLevel; }
     210             : 
     211           4 :     bool IsColumnSelection() const { return mbColumnSelection; }
     212           6 :     void SetColumnSelection( bool bNew ) { mbColumnSelection = bNew; }
     213             : 
     214           0 :     long GetCrsrRowSpanOffset() const { return mnRowSpanOffset; }
     215             :     void SetCrsrRowSpanOffset( long nNew ) { mnRowSpanOffset = nNew; }
     216             : 
     217        1012 :     DECL_FIXEDMEMPOOL_NEWDEL( SwCursor )
     218             : };
     219             : 
     220             : /**
     221             :  A helper class to save cursor state (position). Create SwCrsrSaveState
     222             :  object to save current state, use SwCursor::RestoreSavePos() to actually
     223             :  restore cursor state to the saved state (SwCrsrSaveState destructor only
     224             :  removes the saved state from an internal stack). It is possible to stack
     225             :  several SwCrsrSaveState objects.
     226             : **/
     227             : class SwCrsrSaveState
     228             : {
     229             :     SwCursor& rCrsr;
     230             : public:
     231      173400 :     SwCrsrSaveState( SwCursor& rC ) : rCrsr( rC ) { rC.SaveState(); }
     232      173400 :     ~SwCrsrSaveState() { rCrsr.RestoreState(); }
     233             : };
     234             : 
     235             : // internal, used by SwCursor::SaveState() etc.
     236             : struct _SwCursor_SavePos
     237             : {
     238             :     sal_uLong nNode;
     239             :     sal_Int32 nCntnt;
     240             :     _SwCursor_SavePos* pNext;
     241             : 
     242      173400 :     _SwCursor_SavePos( const SwCursor& rCrsr )
     243      173400 :         : nNode( rCrsr.GetPoint()->nNode.GetIndex() ),
     244      173400 :         nCntnt( rCrsr.GetPoint()->nContent.GetIndex() ),
     245      520200 :         pNext( 0 )
     246      173400 :     {}
     247      346800 :     virtual ~_SwCursor_SavePos() {}
     248             : 
     249      346800 :     DECL_FIXEDMEMPOOL_NEWDEL( _SwCursor_SavePos )
     250             : };
     251             : 
     252             : class SwTableCursor : public virtual SwCursor
     253             : {
     254             : 
     255             : protected:
     256             :     sal_uLong nTblPtNd, nTblMkNd;
     257             :     sal_Int32 nTblPtCnt;
     258             :     sal_Int32 nTblMkCnt;
     259             :     SwSelBoxes m_SelectedBoxes;
     260             :     bool bChg : 1;
     261             :     bool bParked : 1;       // Table-cursor was parked.
     262             : 
     263             :     virtual bool IsSelOvrCheck(int eFlags) SAL_OVERRIDE;
     264             : 
     265             : public:
     266             :     SwTableCursor( const SwPosition &rPos, SwPaM* pRing = 0 );
     267             :     SwTableCursor( SwTableCursor& );
     268             :     virtual ~SwTableCursor();
     269             : 
     270             :     virtual bool LeftRight( bool bLeft, sal_uInt16 nCnt, sal_uInt16 nMode,
     271             :         bool bAllowVisual, bool bSkipHidden, bool bInsertCrsr ) SAL_OVERRIDE;
     272             :     virtual bool GotoTable( const OUString& rName ) SAL_OVERRIDE;
     273             : 
     274             :     void InsertBox( const SwTableBox& rTblBox );
     275             :     void DeleteBox(size_t nPos);
     276         116 :     size_t GetSelectedBoxesCount() const { return m_SelectedBoxes.size(); }
     277         100 :     const SwSelBoxes& GetSelectedBoxes() const { return m_SelectedBoxes; }
     278             : 
     279             :     // Creates cursor for all boxes.
     280             :     SwCursor* MakeBoxSels( SwCursor* pAktCrsr );
     281             :     // Any boxes protected?
     282             :     bool HasReadOnlyBoxSel() const;
     283             : 
     284             :     // Has table cursor been changed? If so, save new values immediately.
     285             :     bool IsCrsrMovedUpdt();
     286             :     // Has table cursor been changed?
     287         374 :     bool IsCrsrMoved() const
     288             :     {
     289         736 :         return  nTblMkNd != GetMark()->nNode.GetIndex() ||
     290         720 :                 nTblPtNd != GetPoint()->nNode.GetIndex() ||
     291        1090 :                 nTblMkCnt != GetMark()->nContent.GetIndex() ||
     292         732 :                 nTblPtCnt != GetPoint()->nContent.GetIndex();
     293             :     }
     294             : 
     295        1222 :     bool IsChgd() const { return bChg; }
     296             : 
     297             :     // Park table cursor at start node of boxes.
     298             :     void ParkCrsr();
     299             : 
     300             :     bool NewTableSelection();
     301             :     void ActualizeSelection( const SwSelBoxes &rBoxes );
     302             : };
     303             : 
     304             : #endif
     305             : 
     306             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10