LCOV - code coverage report
Current view: top level - sw/inc - txatbase.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 62 62 100.0 %
Date: 2014-11-03 Functions: 56 58 96.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             : #ifndef INCLUDED_SW_INC_TXATBASE_HXX
      20             : #define INCLUDED_SW_INC_TXATBASE_HXX
      21             : 
      22             : #include <tools/solar.h>
      23             : #include <svl/poolitem.hxx>
      24             : #include <hintids.hxx>
      25             : 
      26             : #include <boost/utility.hpp>
      27             : 
      28             : class SfxItemPool;
      29             : class SvXMLAttrContainerItem;
      30             : class SwFmtRuby;
      31             : class SwFmtCharFmt;
      32             : class SwFmtAutoFmt;
      33             : class SwFmtINetFmt;
      34             : class SwFmtFld;
      35             : class SwFmtFtn;
      36             : class SwFmtFlyCnt;
      37             : class SwTOXMark;
      38             : class SwFmtRefMark;
      39             : class SwFmtMeta;
      40             : 
      41             : class SwTxtAttr : private boost::noncopyable
      42             : {
      43             : private:
      44             :     SfxPoolItem * const m_pAttr;
      45             :     sal_Int32 m_nStart;
      46             :     bool m_bDontExpand          : 1;
      47             :     bool m_bLockExpandFlag      : 1;
      48             : 
      49             :     bool m_bDontMoveAttr        : 1;    // refmarks, toxmarks
      50             :     bool m_bCharFmtAttr         : 1;    // charfmt, inet
      51             :     bool m_bOverlapAllowedAttr  : 1;    // refmarks, toxmarks
      52             :     bool m_bPriorityAttr        : 1;    // attribute has priority (redlining)
      53             :     bool m_bDontExpandStart     : 1;    // don't expand start at paragraph start (ruby)
      54             :     bool m_bNesting             : 1;    // SwTxtAttrNesting
      55             :     bool m_bHasDummyChar        : 1;    // without end + meta
      56             :     bool m_bFormatIgnoreStart   : 1;    ///< text formatting should ignore start
      57             :     bool m_bFormatIgnoreEnd     : 1;    ///< text formatting should ignore end
      58             :     bool m_bHasContent          : 1;    // text attribute with content
      59             : 
      60             : protected:
      61             :     SwTxtAttr( SfxPoolItem& rAttr, sal_Int32 nStart );
      62             :     virtual ~SwTxtAttr();
      63             : 
      64        3446 :     void SetLockExpandFlag( bool bFlag )    { m_bLockExpandFlag = bFlag; }
      65         424 :     void SetDontMoveAttr( bool bFlag )      { m_bDontMoveAttr = bFlag; }
      66       15226 :     void SetCharFmtAttr( bool bFlag )       { m_bCharFmtAttr = bFlag; }
      67         424 :     void SetOverlapAllowedAttr( bool bFlag ){ m_bOverlapAllowedAttr = bFlag; }
      68        3446 :     void SetDontExpandStartAttr(bool bFlag) { m_bDontExpandStart = bFlag; }
      69        3446 :     void SetNesting(const bool bFlag)       { m_bNesting = bFlag; }
      70       10686 :     void SetHasDummyChar(const bool bFlag)  { m_bHasDummyChar = bFlag; }
      71          28 :     void SetHasContent( const bool bFlag )  { m_bHasContent = bFlag; }
      72             : 
      73             : public:
      74             : 
      75             :     /// destroy instance
      76             :     static void Destroy( SwTxtAttr * pToDestroy, SfxItemPool& rPool );
      77             : 
      78             :     /// start position
      79     5125269 :                   sal_Int32& GetStart()        { return m_nStart; }
      80    25680904 :             const sal_Int32& GetStart() const  { return m_nStart; }
      81             : 
      82             :     /// end position
      83             :     virtual      sal_Int32* GetEnd(); // also used to change the end position
      84             :     inline const sal_Int32* End() const;
      85             :     /// end (if available), else start
      86             :     inline const sal_Int32* GetAnyEnd() const;
      87             : 
      88             :     inline void SetDontExpand( bool bDontExpand );
      89      158857 :     bool DontExpand() const                 { return m_bDontExpand; }
      90       40272 :     bool IsLockExpandFlag() const           { return m_bLockExpandFlag; }
      91           4 :     bool IsDontMoveAttr() const             { return m_bDontMoveAttr; }
      92      151316 :     bool IsCharFmtAttr() const              { return m_bCharFmtAttr; }
      93      140932 :     bool IsOverlapAllowedAttr() const       { return m_bOverlapAllowedAttr; }
      94        7756 :     bool IsPriorityAttr() const             { return m_bPriorityAttr; }
      95        9850 :     void SetPriorityAttr( bool bFlag )      { m_bPriorityAttr = bFlag; }
      96         172 :     bool IsDontExpandStartAttr() const      { return m_bDontExpandStart; }
      97      165832 :     bool IsNesting() const                  { return m_bNesting; }
      98      465060 :     bool HasDummyChar() const               { return m_bHasDummyChar; }
      99      462009 :     bool IsFormatIgnoreStart() const        { return m_bFormatIgnoreStart; }
     100      515394 :     bool IsFormatIgnoreEnd  () const        { return m_bFormatIgnoreEnd  ; }
     101         124 :     void SetFormatIgnoreStart(bool bFlag)   { m_bFormatIgnoreStart = bFlag; }
     102         124 :     void SetFormatIgnoreEnd  (bool bFlag)   { m_bFormatIgnoreEnd   = bFlag; }
     103      260870 :     bool HasContent() const                 { return m_bHasContent; }
     104             : 
     105             :     inline const SfxPoolItem& GetAttr() const;
     106             :     inline       SfxPoolItem& GetAttr();
     107    17516358 :     inline sal_uInt16 Which() const { return GetAttr().Which(); }
     108             : 
     109             :     virtual bool operator==( const SwTxtAttr& ) const;
     110             : 
     111             :     inline const SwFmtCharFmt           &GetCharFmt() const;
     112             :     inline const SwFmtAutoFmt           &GetAutoFmt() const;
     113             :     inline const SwFmtFld               &GetFmtFld() const;
     114             :     inline const SwFmtFtn               &GetFtn() const;
     115             :     inline const SwFmtFlyCnt            &GetFlyCnt() const;
     116             :     inline const SwTOXMark              &GetTOXMark() const;
     117             :     inline const SwFmtRefMark           &GetRefMark() const;
     118             :     inline const SwFmtINetFmt           &GetINetFmt() const;
     119             :     inline const SwFmtRuby              &GetRuby() const;
     120             :     inline const SwFmtMeta              &GetMeta() const;
     121             : 
     122             : };
     123             : 
     124      396544 : class SwTxtAttrEnd : public virtual SwTxtAttr
     125             : {
     126             : protected:
     127             :     sal_Int32 m_nEnd;
     128             : 
     129             : public:
     130             :     SwTxtAttrEnd( SfxPoolItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
     131             : 
     132             :     virtual sal_Int32* GetEnd() SAL_OVERRIDE;
     133             : };
     134             : 
     135             : // attribute that must not overlap others
     136             : class SwTxtAttrNesting : public SwTxtAttrEnd
     137             : {
     138             : protected:
     139             :     SwTxtAttrNesting( SfxPoolItem & i_rAttr,
     140             :         const sal_Int32 i_nStart, const sal_Int32 i_nEnd );
     141             :     virtual ~SwTxtAttrNesting();
     142             : };
     143             : 
     144    13689006 : inline const sal_Int32* SwTxtAttr::End() const
     145             : {
     146    13689006 :     return const_cast<SwTxtAttr * >(this)->GetEnd();
     147             : }
     148             : 
     149    11892231 : inline const sal_Int32* SwTxtAttr::GetAnyEnd() const
     150             : {
     151    11892231 :     const sal_Int32* pEnd = End();
     152    11892231 :     return pEnd ? pEnd : &GetStart();
     153             : }
     154             : 
     155    19211007 : inline const SfxPoolItem& SwTxtAttr::GetAttr() const
     156             : {
     157             :     assert( m_pAttr );
     158    19211007 :     return *m_pAttr;
     159             : }
     160             : 
     161      210058 : inline SfxPoolItem& SwTxtAttr::GetAttr()
     162             : {
     163             :     return const_cast<SfxPoolItem&>(
     164      210058 :             const_cast<const SwTxtAttr*>(this)->GetAttr());
     165             : }
     166             : 
     167       85382 : inline void SwTxtAttr::SetDontExpand( bool bDontExpand )
     168             : {
     169       85382 :     if ( !m_bLockExpandFlag )
     170             :     {
     171       84426 :         m_bDontExpand = bDontExpand;
     172             :     }
     173       85382 : }
     174             : 
     175       15468 : inline const SwFmtCharFmt& SwTxtAttr::GetCharFmt() const
     176             : {
     177             :     assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_CHARFMT );
     178       15468 :     return (const SwFmtCharFmt&)(*m_pAttr);
     179             : }
     180             : 
     181      909668 : inline const SwFmtAutoFmt& SwTxtAttr::GetAutoFmt() const
     182             : {
     183             :     assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_AUTOFMT );
     184      909668 :     return (const SwFmtAutoFmt&)(*m_pAttr);
     185             : }
     186             : 
     187      274822 : inline const SwFmtFld& SwTxtAttr::GetFmtFld() const
     188             : {
     189             :     assert( m_pAttr
     190             :             && ( m_pAttr->Which() == RES_TXTATR_FIELD
     191             :                  || m_pAttr->Which() == RES_TXTATR_ANNOTATION
     192             :                  || m_pAttr->Which() == RES_TXTATR_INPUTFIELD ));
     193      274822 :     return (const SwFmtFld&)(*m_pAttr);
     194             : }
     195             : 
     196        7570 : inline const SwFmtFtn& SwTxtAttr::GetFtn() const
     197             : {
     198             :     assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_FTN );
     199        7570 :     return (const SwFmtFtn&)(*m_pAttr);
     200             : }
     201             : 
     202       43235 : inline const SwFmtFlyCnt& SwTxtAttr::GetFlyCnt() const
     203             : {
     204             :     assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_FLYCNT );
     205       43235 :     return (const SwFmtFlyCnt&)(*m_pAttr);
     206             : }
     207             : 
     208         376 : inline const SwTOXMark& SwTxtAttr::GetTOXMark() const
     209             : {
     210             :     assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_TOXMARK );
     211         376 :     return (const SwTOXMark&)(*m_pAttr);
     212             : }
     213             : 
     214         104 : inline const SwFmtRefMark& SwTxtAttr::GetRefMark() const
     215             : {
     216             :     assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_REFMARK );
     217         104 :     return (const SwFmtRefMark&)(*m_pAttr);
     218             : }
     219             : 
     220       27453 : inline const SwFmtINetFmt& SwTxtAttr::GetINetFmt() const
     221             : {
     222             :     assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_INETFMT );
     223       27453 :     return (const SwFmtINetFmt&)(*m_pAttr);
     224             : }
     225             : 
     226         672 : inline const SwFmtRuby& SwTxtAttr::GetRuby() const
     227             : {
     228             :     assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_CJK_RUBY );
     229         672 :     return (const SwFmtRuby&)(*m_pAttr);
     230             : }
     231             : 
     232             : inline const SwFmtMeta& SwTxtAttr::GetMeta() const
     233             : {
     234             :     assert( m_pAttr && (m_pAttr->Which() == RES_TXTATR_META ||
     235             :         m_pAttr->Which() == RES_TXTATR_METAFIELD) );
     236             :     return (const SwFmtMeta&)(*m_pAttr);
     237             : }
     238             : 
     239             : // these should be static_casts but with virtual inheritance it's not possible
     240       25300 : template<typename T, typename S> inline T static_txtattr_cast(S * s)
     241             : {
     242       25300 :     return dynamic_cast<T>(s);
     243             : }
     244       30938 : template<typename T, typename S> inline T static_txtattr_cast(S & s)
     245             : {
     246       30938 :     return dynamic_cast<T>(s);
     247             : }
     248             : 
     249             : #endif
     250             : 
     251             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10