LCOV - code coverage report
Current view: top level - sw/inc - txatbase.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 62 62 100.0 %
Date: 2015-06-13 12:38:46 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             : #include <fmtautofmt.hxx>
      26             : #include <fmtinfmt.hxx>
      27             : #include <fmtrfmrk.hxx>
      28             : #include <fmtruby.hxx>
      29             : #include <fmtfld.hxx>
      30             : #include <fmtflcnt.hxx>
      31             : #include <fmtftn.hxx>
      32             : #include <fmtmeta.hxx>
      33             : #include <fchrfmt.hxx>
      34             : #include <tox.hxx>
      35             : 
      36             : #include <boost/utility.hpp>
      37             : 
      38             : class SfxItemPool;
      39             : class SvXMLAttrContainerItem;
      40             : 
      41             : class SwTextAttr : 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_bCharFormatAttr         : 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;    // SwTextAttrNesting
      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             :     SwTextAttr( SfxPoolItem& rAttr, sal_Int32 nStart );
      62             :     virtual ~SwTextAttr();
      63             : 
      64        2095 :     void SetLockExpandFlag( bool bFlag )    { m_bLockExpandFlag = bFlag; }
      65         212 :     void SetDontMoveAttr( bool bFlag )      { m_bDontMoveAttr = bFlag; }
      66        8122 :     void SetCharFormatAttr( bool bFlag )       { m_bCharFormatAttr = bFlag; }
      67         212 :     void SetOverlapAllowedAttr( bool bFlag ){ m_bOverlapAllowedAttr = bFlag; }
      68        2095 :     void SetDontExpandStartAttr(bool bFlag) { m_bDontExpandStart = bFlag; }
      69        2095 :     void SetNesting(const bool bFlag)       { m_bNesting = bFlag; }
      70        6125 :     void SetHasDummyChar(const bool bFlag)  { m_bHasDummyChar = bFlag; }
      71          18 :     void SetHasContent( const bool bFlag )  { m_bHasContent = bFlag; }
      72             : 
      73             : public:
      74             : 
      75             :     /// destroy instance
      76             :     static void Destroy( SwTextAttr * pToDestroy, SfxItemPool& rPool );
      77             : 
      78             :     /// start position
      79     2781617 :                   sal_Int32& GetStart()        { return m_nStart; }
      80    45574265 :             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       83120 :     bool DontExpand() const                 { return m_bDontExpand; }
      90       20420 :     bool IsLockExpandFlag() const           { return m_bLockExpandFlag; }
      91           4 :     bool IsDontMoveAttr() const             { return m_bDontMoveAttr; }
      92    21143400 :     bool IsCharFormatAttr() const              { return m_bCharFormatAttr; }
      93       72945 :     bool IsOverlapAllowedAttr() const       { return m_bOverlapAllowedAttr; }
      94        4344 :     bool IsPriorityAttr() const             { return m_bPriorityAttr; }
      95        5301 :     void SetPriorityAttr( bool bFlag )      { m_bPriorityAttr = bFlag; }
      96         103 :     bool IsDontExpandStartAttr() const      { return m_bDontExpandStart; }
      97       86731 :     bool IsNesting() const                  { return m_bNesting; }
      98      257153 :     bool HasDummyChar() const               { return m_bHasDummyChar; }
      99      238687 :     bool IsFormatIgnoreStart() const        { return m_bFormatIgnoreStart; }
     100      266351 :     bool IsFormatIgnoreEnd  () const        { return m_bFormatIgnoreEnd  ; }
     101         104 :     void SetFormatIgnoreStart(bool bFlag)   { m_bFormatIgnoreStart = bFlag; }
     102         104 :     void SetFormatIgnoreEnd  (bool bFlag)   { m_bFormatIgnoreEnd   = bFlag; }
     103      135692 :     bool HasContent() const                 { return m_bHasContent; }
     104             : 
     105             :     inline const SfxPoolItem& GetAttr() const;
     106             :     inline       SfxPoolItem& GetAttr();
     107    30279962 :     inline sal_uInt16 Which() const { return GetAttr().Which(); }
     108             : 
     109             :     bool operator==( const SwTextAttr& ) const;
     110             : 
     111             :     inline const SwFormatCharFormat           &GetCharFormat() const;
     112             :     inline const SwFormatAutoFormat           &GetAutoFormat() const;
     113             :     inline const SwFormatField               &GetFormatField() const;
     114             :     inline const SwFormatFootnote               &GetFootnote() const;
     115             :     inline const SwFormatFlyCnt            &GetFlyCnt() const;
     116             :     inline const SwTOXMark              &GetTOXMark() const;
     117             :     inline const SwFormatRefMark           &GetRefMark() const;
     118             :     inline const SwFormatINetFormat           &GetINetFormat() const;
     119             :     inline const SwFormatRuby              &GetRuby() const;
     120             :     inline const SwFormatMeta              &GetMeta() const;
     121             : 
     122             :     void dumpAsXml(struct _xmlTextWriter* pWriter) const;
     123             : };
     124             : 
     125      204853 : class SwTextAttrEnd : public virtual SwTextAttr
     126             : {
     127             : protected:
     128             :     sal_Int32 m_nEnd;
     129             : 
     130             : public:
     131             :     SwTextAttrEnd( SfxPoolItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
     132             : 
     133             :     virtual sal_Int32* GetEnd() SAL_OVERRIDE;
     134             : };
     135             : 
     136             : // attribute that must not overlap others
     137             : class SwTextAttrNesting : public SwTextAttrEnd
     138             : {
     139             : protected:
     140             :     SwTextAttrNesting( SfxPoolItem & i_rAttr,
     141             :         const sal_Int32 i_nStart, const sal_Int32 i_nEnd );
     142             :     virtual ~SwTextAttrNesting();
     143             : };
     144             : 
     145     7039156 : inline const sal_Int32* SwTextAttr::End() const
     146             : {
     147     7039156 :     return const_cast<SwTextAttr * >(this)->GetEnd();
     148             : }
     149             : 
     150     6092156 : inline const sal_Int32* SwTextAttr::GetAnyEnd() const
     151             : {
     152     6092156 :     const sal_Int32* pEnd = End();
     153     6092156 :     return pEnd ? pEnd : &GetStart();
     154             : }
     155             : 
     156    31170872 : inline const SfxPoolItem& SwTextAttr::GetAttr() const
     157             : {
     158             :     assert( m_pAttr );
     159    31170872 :     return *m_pAttr;
     160             : }
     161             : 
     162      106649 : inline SfxPoolItem& SwTextAttr::GetAttr()
     163             : {
     164             :     return const_cast<SfxPoolItem&>(
     165      106649 :             const_cast<const SwTextAttr*>(this)->GetAttr());
     166             : }
     167             : 
     168       43638 : inline void SwTextAttr::SetDontExpand( bool bDontExpand )
     169             : {
     170       43638 :     if ( !m_bLockExpandFlag )
     171             :     {
     172       43155 :         m_bDontExpand = bDontExpand;
     173             :     }
     174       43638 : }
     175             : 
     176        8133 : inline const SwFormatCharFormat& SwTextAttr::GetCharFormat() const
     177             : {
     178             :     assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_CHARFMT );
     179        8133 :     return static_cast<const SwFormatCharFormat&>(*m_pAttr);
     180             : }
     181             : 
     182      473874 : inline const SwFormatAutoFormat& SwTextAttr::GetAutoFormat() const
     183             : {
     184             :     assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_AUTOFMT );
     185      473874 :     return static_cast<const SwFormatAutoFormat&>(*m_pAttr);
     186             : }
     187             : 
     188      145535 : inline const SwFormatField& SwTextAttr::GetFormatField() const
     189             : {
     190             :     assert( m_pAttr
     191             :             && ( m_pAttr->Which() == RES_TXTATR_FIELD
     192             :                  || m_pAttr->Which() == RES_TXTATR_ANNOTATION
     193             :                  || m_pAttr->Which() == RES_TXTATR_INPUTFIELD ));
     194      145535 :     return static_cast<const SwFormatField&>(*m_pAttr);
     195             : }
     196             : 
     197        4626 : inline const SwFormatFootnote& SwTextAttr::GetFootnote() const
     198             : {
     199             :     assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_FTN );
     200        4626 :     return static_cast<const SwFormatFootnote&>(*m_pAttr);
     201             : }
     202             : 
     203       22976 : inline const SwFormatFlyCnt& SwTextAttr::GetFlyCnt() const
     204             : {
     205             :     assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_FLYCNT );
     206       22976 :     return static_cast<const SwFormatFlyCnt&>(*m_pAttr);
     207             : }
     208             : 
     209         190 : inline const SwTOXMark& SwTextAttr::GetTOXMark() const
     210             : {
     211             :     assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_TOXMARK );
     212         190 :     return static_cast<const SwTOXMark&>(*m_pAttr);
     213             : }
     214             : 
     215          50 : inline const SwFormatRefMark& SwTextAttr::GetRefMark() const
     216             : {
     217             :     assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_REFMARK );
     218          50 :     return static_cast<const SwFormatRefMark&>(*m_pAttr);
     219             : }
     220             : 
     221       16056 : inline const SwFormatINetFormat& SwTextAttr::GetINetFormat() const
     222             : {
     223             :     assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_INETFMT );
     224       16056 :     return static_cast<const SwFormatINetFormat&>(*m_pAttr);
     225             : }
     226             : 
     227         314 : inline const SwFormatRuby& SwTextAttr::GetRuby() const
     228             : {
     229             :     assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_CJK_RUBY );
     230         314 :     return static_cast<const SwFormatRuby&>(*m_pAttr);
     231             : }
     232             : 
     233             : inline const SwFormatMeta& SwTextAttr::GetMeta() const
     234             : {
     235             :     assert( m_pAttr && (m_pAttr->Which() == RES_TXTATR_META ||
     236             :         m_pAttr->Which() == RES_TXTATR_METAFIELD) );
     237             :     return static_cast<const SwFormatMeta&>(*m_pAttr);
     238             : }
     239             : 
     240             : // these should be static_casts but with virtual inheritance it's not possible
     241       14992 : template<typename T, typename S> inline T static_txtattr_cast(S * s)
     242             : {
     243       14992 :     return dynamic_cast<T>(s);
     244             : }
     245       15120 : template<typename T, typename S> inline T static_txtattr_cast(S & s)
     246             : {
     247       15120 :     return dynamic_cast<T>(s);
     248             : }
     249             : 
     250             : #endif
     251             : 
     252             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11