LCOV - code coverage report
Current view: top level - sw/inc - swcrsr.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 31 36 86.1 %
Date: 2015-06-13 12:38:46 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* m_pSavePos;
      64             :     long m_nRowSpanOffset;        // required for travelling in tabs with rowspans
      65             :     sal_uInt8 m_nCursorBidiLevel; // bidi level of the cursor
      66             :     bool m_bColumnSelection;      // 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             :     SwCursor(SwCursor const& rPaM) SAL_DELETED_FUNCTION;
      73             : 
      74             : protected:
      75             :     _SwCursor_SavePos* CreateNewSavePos() const;
      76             :     void SaveState();
      77             :     void RestoreState();
      78             : 
      79       65592 :     const _SwCursor_SavePos* GetSavePos() const { return m_pSavePos; }
      80             : 
      81             :     virtual const SwContentFrm* DoSetBidiLevelLeftRight(
      82             :         bool & io_rbLeft, bool bVisualAllowed, bool bInsertCrsr);
      83             :     virtual void DoSetBidiLevelUpDown();
      84             :     virtual bool IsSelOvrCheck(int eFlags);
      85             : 
      86             : public:
      87             :     // single argument ctors shall be explicit.
      88             :     SwCursor( const SwPosition &rPos, SwPaM* pRing, bool bColumnSel );
      89             :     virtual ~SwCursor();
      90             : 
      91             :     /// this takes a second parameter, which indicates the Ring that
      92             :     /// the new cursor should be part of (may be null)
      93             :     SwCursor(SwCursor const& rCursor, SwPaM* pRing);
      94             : 
      95             : public:
      96             : 
      97             :     virtual SwCursor* Create( SwPaM* pRing = 0 ) const;
      98             : 
      99             :     virtual short MaxReplaceArived(); //returns RET_YES/RET_CANCEL/RET_NO
     100             :     virtual void SaveTableBoxContent( const SwPosition* pPos = 0 );
     101             : 
     102             :     void FillFindPos( SwDocPositions ePos, SwPosition& rPos ) const;
     103             :     SwMoveFnCollection* MakeFindRange( SwDocPositions, SwDocPositions,
     104             :                                         SwPaM* ) const;
     105             : 
     106             :     sal_uLong Find( const com::sun::star::util::SearchOptions& rSearchOpt,
     107             :                 bool bSearchInNotes,
     108             :                 SwDocPositions nStart, SwDocPositions nEnde,
     109             :                 bool& bCancel,
     110             :                 FindRanges = FND_IN_BODY,
     111             :                 bool bReplace = false );
     112             :     sal_uLong Find( const SwTextFormatColl& rFormatColl,
     113             :                 SwDocPositions nStart, SwDocPositions nEnde,
     114             :                 bool& bCancel,
     115             :                 FindRanges = FND_IN_BODY,
     116             :                 const SwTextFormatColl* pReplFormat = 0 );
     117             :     sal_uLong Find( const SfxItemSet& rSet, bool bNoCollections,
     118             :                 SwDocPositions nStart, SwDocPositions nEnde,
     119             :                 bool& bCancel,
     120             :                 FindRanges = FND_IN_BODY,
     121             :                 const com::sun::star::util::SearchOptions* pSearchOpt = 0,
     122             :                 const SfxItemSet* rReplSet = 0 );
     123             : 
     124             :     // UI versions
     125             :     bool IsStartWord( sal_Int16 nWordType = com::sun::star::i18n::WordType::ANYWORD_IGNOREWHITESPACES ) const;
     126             :     bool IsEndWord( sal_Int16 nWordType = com::sun::star::i18n::WordType::ANYWORD_IGNOREWHITESPACES ) const;
     127             :     bool IsInWord( sal_Int16 nWordType = com::sun::star::i18n::WordType::ANYWORD_IGNOREWHITESPACES ) const;
     128             :     bool IsStartEndSentence( bool bEnd ) const;
     129             :     bool GoStartWord();
     130             :     bool GoEndWord();
     131             :     bool GoNextWord();
     132             :     bool GoPrevWord();
     133             :     bool SelectWord( SwViewShell* pViewShell, const Point* pPt = 0 );
     134             : 
     135             :     // API versions of above functions (will be used with a different
     136             :     // WordType for the break iterator)
     137             :     bool IsStartWordWT( sal_Int16 nWordType ) const;
     138             :     bool IsEndWordWT( sal_Int16 nWordType ) const;
     139             :     bool IsInWordWT( sal_Int16 nWordType ) const;
     140             :     bool GoStartWordWT( sal_Int16 nWordType );
     141             :     bool GoEndWordWT( sal_Int16 nWordType );
     142             :     bool GoNextWordWT( sal_Int16 nWordType );
     143             :     bool GoPrevWordWT( sal_Int16 nWordType );
     144             :     bool SelectWordWT( SwViewShell* pViewShell, sal_Int16 nWordType, const Point* pPt = 0 );
     145             : 
     146             :     enum SentenceMoveType
     147             :     {
     148             :         NEXT_SENT,
     149             :         PREV_SENT,
     150             :         START_SENT,
     151             :         END_SENT
     152             :     };
     153             :     bool GoSentence(SentenceMoveType eMoveType);
     154           0 :     bool GoNextSentence(){return GoSentence(NEXT_SENT);}
     155           0 :     bool GoEndSentence(){return GoSentence(END_SENT);}
     156             :     bool GoPrevSentence(){return GoSentence(PREV_SENT);}
     157           0 :     bool GoStartSentence(){return GoSentence(START_SENT);}
     158             :     bool ExpandToSentenceBorders();
     159             : 
     160             :     virtual bool LeftRight( bool bLeft, sal_uInt16 nCnt, sal_uInt16 nMode,
     161             :         bool bAllowVisual, bool bSkipHidden, bool bInsertCrsr );
     162             :     bool UpDown( bool bUp, sal_uInt16 nCnt, Point* pPt, long nUpDownX );
     163             :     bool LeftRightMargin( bool bLeftMargin, bool bAPI = false );
     164             :     bool IsAtLeftRightMargin( bool bLeftMargin, bool bAPI = false ) const;
     165             :     bool SttEndDoc( bool bSttDoc );
     166             :     bool GoPrevNextCell( bool bNext, sal_uInt16 nCnt );
     167             : 
     168       37195 :     bool Left( sal_uInt16 nCnt, sal_uInt16 nMode, bool bAllowVisual, bool bSkipHidden )
     169       37195 :                                     { return LeftRight( true, nCnt, nMode, bAllowVisual, bSkipHidden, false ); }
     170        5680 :     bool Right( sal_uInt16 nCnt, sal_uInt16 nMode, bool bAllowVisual, bool bSkipHidden )
     171        5680 :                                     { return LeftRight( false, nCnt, nMode, bAllowVisual, bSkipHidden, false ); }
     172           2 :     bool GoNextCell( sal_uInt16 nCnt = 1 )  { return GoPrevNextCell( true, nCnt ); }
     173           2 :     bool GoPrevCell( sal_uInt16 nCnt = 1 )  { return GoPrevNextCell( false, nCnt ); }
     174             :     virtual bool GotoTable( const OUString& rName );
     175             :     bool GotoTableBox( const OUString& rName );
     176             :     bool GotoRegion( const OUString& rName );
     177             :     bool GotoFootnoteAnchor();
     178             :     bool GotoFootnoteText();
     179             :     bool GotoNextFootnoteAnchor();
     180             :     bool GotoPrevFootnoteAnchor();
     181             :     bool GotoNextFootnoteContent();
     182             :     bool GotoPrevFootnoteContent();
     183             : 
     184             :     bool MovePara( SwWhichPara, SwPosPara );
     185             :     bool MoveSection( SwWhichSection, SwPosSection );
     186             :     bool MoveTable( SwWhichTable, SwPosTable );
     187             :     bool MoveRegion( SwWhichRegion, SwPosRegion );
     188             : 
     189             :     // Is there a selection of content in table?
     190             :     // Return value indicates if cursor remains at its old position.
     191             :     virtual bool IsSelOvr( int eFlags =
     192             :                                 ( nsSwCursorSelOverFlags::SELOVER_CHECKNODESSECTION |
     193             :                                   nsSwCursorSelOverFlags::SELOVER_TOGGLE |
     194             :                                   nsSwCursorSelOverFlags::SELOVER_CHANGEPOS ));
     195             :     bool IsInProtectTable( bool bMove = false,
     196             :                                    bool bChgCrsr = true );
     197             :     bool IsNoContent() const;
     198             : 
     199             :     /** Restore cursor state to the one saved by SwCrsrSaveState **/
     200             :     void RestoreSavePos();
     201             : 
     202             :     // true: cursor can be set at this position.
     203             :     virtual bool IsAtValidPos( bool bPoint = true ) const;
     204             : 
     205             :     // Is cursor allowed in ready only ranges?
     206             :     virtual bool IsReadOnlyAvailable() const;
     207             : 
     208             :     virtual bool IsSkipOverProtectSections() const;
     209             :     virtual bool IsSkipOverHiddenSections() const;
     210             : 
     211       81980 :     sal_uInt8 GetCrsrBidiLevel() const { return m_nCursorBidiLevel; }
     212          64 :     void SetCrsrBidiLevel( sal_uInt8 nNewLevel ) { m_nCursorBidiLevel = nNewLevel; }
     213             : 
     214           2 :     bool IsColumnSelection() const { return m_bColumnSelection; }
     215           9 :     void SetColumnSelection( bool bNew ) { m_bColumnSelection = bNew; }
     216             : 
     217           0 :     long GetCrsrRowSpanOffset() const { return m_nRowSpanOffset; }
     218             :     void SetCrsrRowSpanOffset( long nNew ) { m_nRowSpanOffset = nNew; }
     219             : 
     220        1386 :     DECL_FIXEDMEMPOOL_NEWDEL( SwCursor )
     221             : };
     222             : 
     223             : /**
     224             :  A helper class to save cursor state (position). Create SwCrsrSaveState
     225             :  object to save current state, use SwCursor::RestoreSavePos() to actually
     226             :  restore cursor state to the saved state (SwCrsrSaveState destructor only
     227             :  removes the saved state from an internal stack). It is possible to stack
     228             :  several SwCrsrSaveState objects.
     229             : **/
     230             : class SwCrsrSaveState
     231             : {
     232             : private:
     233             :     SwCursor& m_rCrsr;
     234             : public:
     235       95050 :     SwCrsrSaveState( SwCursor& rC ) : m_rCrsr( rC ) { rC.SaveState(); }
     236       95050 :     ~SwCrsrSaveState() { m_rCrsr.RestoreState(); }
     237             : };
     238             : 
     239             : // internal, used by SwCursor::SaveState() etc.
     240             : struct _SwCursor_SavePos
     241             : {
     242             :     sal_uLong nNode;
     243             :     sal_Int32 nContent;
     244             :     _SwCursor_SavePos* pNext;
     245             : 
     246       95050 :     _SwCursor_SavePos( const SwCursor& rCrsr )
     247       95050 :         : nNode( rCrsr.GetPoint()->nNode.GetIndex() ),
     248       95050 :         nContent( rCrsr.GetPoint()->nContent.GetIndex() ),
     249      285150 :         pNext( 0 )
     250       95050 :     {}
     251      190100 :     virtual ~_SwCursor_SavePos() {}
     252             : 
     253      190100 :     DECL_FIXEDMEMPOOL_NEWDEL( _SwCursor_SavePos )
     254             : };
     255             : 
     256             : class SwTableCursor : public virtual SwCursor
     257             : {
     258             : 
     259             : protected:
     260             :     sal_uLong m_nTablePtNd;
     261             :     sal_uLong m_nTableMkNd;
     262             :     sal_Int32 m_nTablePtCnt;
     263             :     sal_Int32 m_nTableMkCnt;
     264             :     SwSelBoxes m_SelectedBoxes;
     265             :     bool m_bChanged : 1;
     266             :     bool m_bParked : 1;       // Table-cursor was parked.
     267             : 
     268             :     virtual bool IsSelOvrCheck(int eFlags) SAL_OVERRIDE;
     269             : 
     270             : public:
     271             :     SwTableCursor( const SwPosition &rPos, SwPaM* pRing = 0 );
     272             :     SwTableCursor( SwTableCursor& );
     273             :     virtual ~SwTableCursor();
     274             : 
     275             :     virtual bool LeftRight( bool bLeft, sal_uInt16 nCnt, sal_uInt16 nMode,
     276             :         bool bAllowVisual, bool bSkipHidden, bool bInsertCrsr ) SAL_OVERRIDE;
     277             :     virtual bool GotoTable( const OUString& rName ) SAL_OVERRIDE;
     278             : 
     279             :     void InsertBox( const SwTableBox& rTableBox );
     280             :     void DeleteBox(size_t nPos);
     281         151 :     size_t GetSelectedBoxesCount() const { return m_SelectedBoxes.size(); }
     282          59 :     const SwSelBoxes& GetSelectedBoxes() const { return m_SelectedBoxes; }
     283             : 
     284             :     // Creates cursor for all boxes.
     285             :     SwCursor* MakeBoxSels( SwCursor* pAktCrsr );
     286             :     // Any boxes protected?
     287             :     bool HasReadOnlyBoxSel() const;
     288             : 
     289             :     // Has table cursor been changed? If so, save new values immediately.
     290             :     bool IsCrsrMovedUpdate();
     291             :     // Has table cursor been changed?
     292         279 :     bool IsCrsrMoved() const
     293             :     {
     294         546 :         return  m_nTableMkNd != GetMark()->nNode.GetIndex() ||
     295         532 :                 m_nTablePtNd != GetPoint()->nNode.GetIndex() ||
     296         809 :                 m_nTableMkCnt != GetMark()->nContent.GetIndex() ||
     297         544 :                 m_nTablePtCnt != GetPoint()->nContent.GetIndex();
     298             :     }
     299             : 
     300         779 :     bool IsChgd() const { return m_bChanged; }
     301             : 
     302             :     // Park table cursor at start node of boxes.
     303             :     void ParkCrsr();
     304             : 
     305             :     bool NewTableSelection();
     306             :     void ActualizeSelection( const SwSelBoxes &rBoxes );
     307             : };
     308             : 
     309             : #endif
     310             : 
     311             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11