LCOV - code coverage report
Current view: top level - libreoffice/sw/inc - pam.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 53 60 88.3 %
Date: 2012-12-27 Functions: 22 24 91.7 %
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 _PAM_HXX
      20             : #define _PAM_HXX
      21             : 
      22             : #include <stddef.h>         ///< For MemPool.
      23             : #include <tools/gen.hxx>
      24             : #include <tools/mempool.hxx>
      25             : #include <cshtyp.hxx>       ///< For function definitions.
      26             : #include <ring.hxx>         ///< Super class.
      27             : #include <index.hxx>        ///< For SwIndex.
      28             : #include <ndindex.hxx>      ///< For SwNodeIndex.
      29             : #include "swdllapi.h"
      30             : 
      31             : class SwFmt;
      32             : class SfxPoolItem;
      33             : class SfxItemSet;
      34             : class SwDoc;
      35             : class SwNode;
      36             : class SwCntntNode;
      37             : class SwPaM;
      38             : 
      39             : namespace com { namespace sun { namespace star { namespace util {
      40             :     struct SearchOptions;
      41             : } } } }
      42             : 
      43             : namespace utl {
      44             :     class TextSearch;
      45             : }
      46             : 
      47             : /// Marks a position in the document model.
      48      271801 : struct SW_DLLPUBLIC SwPosition
      49             : {
      50             :     SwNodeIndex nNode;
      51             :     SwIndex nContent;
      52             : 
      53             :     SwPosition( const SwNodeIndex &rNode, const SwIndex &rCntnt );
      54             :     explicit SwPosition( const SwNodeIndex &rNode );
      55             :     explicit SwPosition( const SwNode& rNode );
      56             :     explicit SwPosition( SwCntntNode& rNode, const xub_StrLen nOffset = 0 );
      57             : 
      58             :     SwPosition( const SwPosition & );
      59             :     SwPosition &operator=(const SwPosition &);
      60             : 
      61             :     /**
      62             :        Returns the document this position is in.
      63             : 
      64             :        @return the document this position is in.
      65             :     */
      66             :     SwDoc * GetDoc() const;
      67             : 
      68             :     bool operator < (const SwPosition &) const;
      69             :     bool operator > (const SwPosition &) const;
      70             :     bool operator <=(const SwPosition &) const;
      71             :     bool operator >=(const SwPosition &) const;
      72             :     bool operator ==(const SwPosition &) const;
      73             :     bool operator !=(const SwPosition &) const;
      74             : };
      75             : 
      76             : 
      77             : // Result of comparing positions.
      78             : enum SwComparePosition {
      79             :     POS_BEFORE,             ///< Pos1 before Pos2.
      80             :     POS_BEHIND,             ///< Pos1 behind Pos2.
      81             :     POS_INSIDE,             ///< Pos1 completely contained in Pos2.
      82             :     POS_OUTSIDE,            ///< Pos2 completely contained in Pos1.
      83             :     POS_EQUAL,              ///< Pos1 is as large as Pos2.
      84             :     POS_OVERLAP_BEFORE,     ///< Pos1 overlaps Pos2 at the beginning.
      85             :     POS_OVERLAP_BEHIND,     ///< Pos1 overlaps Pos2 at the end.
      86             :     POS_COLLIDE_START,      ///< Pos1 start touches at Pos2 end.
      87             :     POS_COLLIDE_END         ///< Pos1 end touches at Pos2 start.
      88             : };
      89             : 
      90             : template<typename T>
      91         698 : SwComparePosition ComparePosition(
      92             :             const T& rStt1, const T& rEnd1,
      93             :             const T& rStt2, const T& rEnd2 )
      94             : {
      95             :     SwComparePosition nRet;
      96         698 :     if( rStt1 < rStt2 )
      97             :     {
      98         252 :         if( rEnd1 > rStt2 )
      99             :         {
     100         250 :             if( rEnd1 >= rEnd2 )
     101         250 :                 nRet = POS_OUTSIDE;
     102             :             else
     103           0 :                 nRet = POS_OVERLAP_BEFORE;
     104             : 
     105             :         }
     106           2 :         else if( rEnd1 == rStt2 )
     107           2 :             nRet = POS_COLLIDE_END;
     108             :         else
     109           0 :             nRet = POS_BEFORE;
     110             :     }
     111         446 :     else if( rEnd2 > rStt1 )
     112             :     {
     113           3 :         if( rEnd2 >= rEnd1 )
     114             :         {
     115           0 :             if( rEnd2 == rEnd1 && rStt2 == rStt1 )
     116           0 :                 nRet = POS_EQUAL;
     117             :             else
     118           0 :                 nRet = POS_INSIDE;
     119             :         }
     120             :         else
     121             :         {
     122           3 :             if (rStt1 == rStt2)
     123           3 :                 nRet = POS_OUTSIDE;
     124             :             else
     125           0 :                 nRet = POS_OVERLAP_BEHIND;
     126             :         }
     127             :     }
     128         443 :     else if( rEnd2 == rStt1 )
     129         300 :         nRet = POS_COLLIDE_START;
     130             :     else
     131         143 :         nRet = POS_BEHIND;
     132         698 :     return nRet;
     133             : }
     134             : 
     135             : /// SwPointAndMark / SwPaM
     136             : struct SwMoveFnCollection;
     137             : typedef SwMoveFnCollection* SwMoveFn;
     138             : SW_DLLPUBLIC extern SwMoveFn fnMoveForward; ///< SwPam::Move()/Find() default argument.
     139             : SW_DLLPUBLIC extern SwMoveFn fnMoveBackward;
     140             : 
     141             : typedef sal_Bool (*SwGoInDoc)( SwPaM& rPam, SwMoveFn fnMove );
     142             : SW_DLLPUBLIC extern SwGoInDoc fnGoDoc;
     143             : extern SwGoInDoc fnGoSection;
     144             : SW_DLLPUBLIC extern SwGoInDoc fnGoNode;
     145             : SW_DLLPUBLIC extern SwGoInDoc fnGoCntnt; ///< SwPam::Move() default argument.
     146             : extern SwGoInDoc fnGoCntntCells;
     147             : extern SwGoInDoc fnGoCntntSkipHidden;
     148             : extern SwGoInDoc fnGoCntntCellsSkipHidden;
     149             : 
     150             : void _InitPam();
     151             : 
     152             : /// PaM is Point and Mark: a selection of the document model.
     153             : class SW_DLLPUBLIC SwPaM : public Ring
     154             : {
     155             :     SwPosition   m_Bound1;
     156             :     SwPosition   m_Bound2;
     157             :     SwPosition * m_pPoint; ///< points at either m_Bound1 or m_Bound2
     158             :     SwPosition * m_pMark;  ///< points at either m_Bound1 or m_Bound2
     159             :     bool m_bIsInFrontOfLabel;
     160             : 
     161             :     SwPaM* MakeRegion( SwMoveFn fnMove, const SwPaM * pOrigRg = 0 );
     162             : 
     163             : public:
     164             :     SwPaM( const SwPosition& rPos, SwPaM* pRing = 0 );
     165             :     SwPaM( const SwPosition& rMk, const SwPosition& rPt, SwPaM* pRing = 0 );
     166             :     SwPaM( const SwNodeIndex& rMk, const SwNodeIndex& rPt,
     167             :            long nMkOffset = 0, long nPtOffset = 0, SwPaM* pRing = 0 );
     168             :     SwPaM( const SwNode& rMk, const SwNode& rPt,
     169             :            long nMkOffset = 0, long nPtOffset = 0, SwPaM* pRing = 0 );
     170             :     SwPaM(  const SwNodeIndex& rMk, xub_StrLen nMkCntnt,
     171             :             const SwNodeIndex& rPt, xub_StrLen nPtCntnt, SwPaM* pRing = 0 );
     172             :     SwPaM(  const SwNode& rMk, xub_StrLen nMkCntnt,
     173             :             const SwNode& rPt, xub_StrLen nPtCntnt, SwPaM* pRing = 0 );
     174             :     SwPaM( const SwNode& rNd, xub_StrLen nCntnt = 0, SwPaM* pRing = 0 );
     175             :     SwPaM( const SwNodeIndex& rNd, xub_StrLen nCntnt = 0, SwPaM* pRing = 0 );
     176             :     virtual ~SwPaM();
     177             : 
     178             :     /// @@@ semantic: no copy ctor.
     179             :     SwPaM( SwPaM & );
     180             :     /// @@@ semantic: no copy assignment for super class Ring.
     181             :     SwPaM& operator=( const SwPaM & );
     182             : 
     183             :     /// Movement of cursor.
     184             :     sal_Bool Move( SwMoveFn fnMove = fnMoveForward,
     185             :                     SwGoInDoc fnGo = fnGoCntnt );
     186             : 
     187             :     /// Search.
     188             :     sal_uInt8 Find( const com::sun::star::util::SearchOptions& rSearchOpt,
     189             :                 sal_Bool bSearchInNotes,
     190             :                 utl::TextSearch& rSTxt,
     191             :                 SwMoveFn fnMove = fnMoveForward,
     192             :                 const SwPaM *pPam =0, sal_Bool bInReadOnly = sal_False);
     193             :     sal_Bool Find(  const SwFmt& rFmt,
     194             :                 SwMoveFn fnMove = fnMoveForward,
     195             :                 const SwPaM *pPam =0, sal_Bool bInReadOnly = sal_False);
     196             :     sal_Bool Find(  const SfxPoolItem& rAttr, sal_Bool bValue = sal_True,
     197             :                 SwMoveFn fnMove = fnMoveForward,
     198             :                 const SwPaM *pPam =0, sal_Bool bInReadOnly = sal_False );
     199             :     sal_Bool Find(  const SfxItemSet& rAttr, sal_Bool bNoColls,
     200             :                 SwMoveFn fnMove,
     201             :                 const SwPaM *pPam, sal_Bool bInReadOnly, sal_Bool bMoveFirst );
     202             : 
     203             :     bool DoSearch( const com::sun::star::util::SearchOptions& rSearchOpt, utl::TextSearch& rSTxt,
     204             :                     SwMoveFn fnMove, sal_Bool bSrchForward, sal_Bool bRegSearch, sal_Bool bChkEmptyPara, sal_Bool bChkParaEnd,
     205             :                     xub_StrLen &nStart, xub_StrLen &nEnde,xub_StrLen nTxtLen,SwNode* pNode, SwPaM* pPam);
     206             : 
     207       17266 :     inline bool IsInFrontOfLabel() const        { return m_bIsInFrontOfLabel; }
     208           0 :     inline void _SetInFrontOfLabel( bool bNew ) { m_bIsInFrontOfLabel = bNew; }
     209             : 
     210             :     virtual void SetMark();
     211             : 
     212        4696 :     void DeleteMark()
     213             :     {
     214        4696 :         if (m_pMark != m_pPoint)
     215             :         {
     216             :             /** clear the mark position; this helps if mark's SwIndex is
     217             :                registered at some node, and that node is then deleted */
     218        1521 :             *m_pMark = SwPosition( SwNodeIndex( GetNode()->GetNodes() ) );
     219        1521 :             m_pMark = m_pPoint;
     220             :         }
     221        4696 :     }
     222             : #ifdef DBG_UTIL
     223             :     void Exchange();
     224             : 
     225             : #else
     226        1014 :     void Exchange()
     227             :     {
     228        1014 :         if (m_pPoint != m_pMark)
     229             :         {
     230         966 :             SwPosition *pTmp = m_pPoint;
     231         966 :             m_pPoint = m_pMark;
     232         966 :             m_pMark = pTmp;
     233             :         }
     234        1014 :     }
     235             : #endif
     236             : 
     237             :     /** A PaM marks a selection if Point and Mark are distinct positions.
     238             :         @return     true iff the PaM spans a selection
     239             :      */
     240       67027 :     bool HasMark() const { return m_pPoint == m_pMark ? false : true; }
     241             : 
     242      200523 :     const SwPosition *GetPoint() const { return m_pPoint; }
     243      242402 :           SwPosition *GetPoint()       { return m_pPoint; }
     244        5957 :     const SwPosition *GetMark()  const { return m_pMark; }
     245       33398 :           SwPosition *GetMark()        { return m_pMark; }
     246             : 
     247       27360 :     const SwPosition *Start() const
     248       27360 :                 { return (*m_pPoint) <= (*m_pMark) ? m_pPoint : m_pMark; }
     249       36753 :           SwPosition *Start()
     250       36753 :                 { return (*m_pPoint) <= (*m_pMark) ? m_pPoint : m_pMark; }
     251             : 
     252       24282 :     const SwPosition *End()   const
     253       24282 :                 { return (*m_pPoint) >  (*m_pMark) ? m_pPoint : m_pMark; }
     254       45076 :           SwPosition *End()
     255       45076 :                 { return (*m_pPoint) >  (*m_pMark) ? m_pPoint : m_pMark; }
     256             : 
     257             :     /// @return current Node at Point/Mark
     258       80664 :     SwNode    * GetNode      ( bool bPoint = true ) const
     259             :     {
     260       80664 :         return &( bPoint ? m_pPoint->nNode : m_pMark->nNode ).GetNode();
     261             :     }
     262             : 
     263             :     /// @return current ContentNode at Point/Mark
     264       55780 :     SwCntntNode* GetCntntNode( bool bPoint = true ) const
     265             :     {
     266       55780 :         return GetNode(bPoint)->GetCntntNode();
     267             :     }
     268             : 
     269             :     /**
     270             :        Normalizes PaM, i.e. sort point and mark.
     271             : 
     272             :        @param bPointFirst sal_True: If the point is behind the mark then swap.
     273             :                           sal_False: If the mark is behind the point then swap.
     274             :     */
     275             :     SwPaM & Normalize(sal_Bool bPointFirst = sal_True);
     276             : 
     277             :     /// @return the document (SwDoc) at which the PaM is registered
     278      102139 :     SwDoc* GetDoc() const   { return m_pPoint->nNode.GetNode().GetDoc(); }
     279             : 
     280        6347 :           SwPosition& GetBound( bool bOne = true )
     281        6347 :                             { return bOne ? m_Bound1 : m_Bound2; }
     282        1066 :     const SwPosition& GetBound( bool bOne = true ) const
     283        1066 :                             { return bOne ? m_Bound1 : m_Bound2; }
     284             : 
     285             :     /// Get number of page which contains cursor.
     286             :     sal_uInt16 GetPageNum( sal_Bool bAtPoint = sal_True, const Point* pLayPos = 0 );
     287             : 
     288             :     /** Is in something protected (readonly) or selection contains
     289             :        something protected. */
     290             :     sal_Bool HasReadonlySel( bool bFormView ) const;
     291             : 
     292        4262 :     sal_Bool ContainsPosition(const SwPosition & rPos)
     293        4262 :     { return *Start() <= rPos && rPos <= *End(); }
     294             : 
     295        8539 :     DECL_FIXEDMEMPOOL_NEWDEL(SwPaM);
     296             : 
     297             :     String GetTxt() const;
     298             :     void InvalidatePaM();
     299             : };
     300             : 
     301             : 
     302             : sal_Bool CheckNodesRange( const SwNodeIndex&, const SwNodeIndex&, sal_Bool );
     303             : sal_Bool GoInCntnt( SwPaM & rPam, SwMoveFn fnMove );
     304             : 
     305             : 
     306             : #endif  // _PAM_HXX
     307             : 
     308             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10