LCOV - code coverage report
Current view: top level - libreoffice/sw/inc - txatbase.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 44 50 88.0 %
Date: 2012-12-27 Functions: 32 35 91.4 %
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 _TXATBASE_HXX
      20             : #define _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             : 
      29             : class SfxItemPool;
      30             : class SvXMLAttrContainerItem;
      31             : class SwFmtRuby;
      32             : class SwFmtCharFmt;
      33             : class SwFmtAutoFmt;
      34             : class SwFmtINetFmt;
      35             : class SwFmtFld;
      36             : class SwFmtFtn;
      37             : class SwFmtFlyCnt;
      38             : class SwTOXMark;
      39             : class SwFmtRefMark;
      40             : class SwFmtMeta;
      41             : 
      42             : 
      43             : class SwTxtAttr : private boost::noncopyable
      44             : {
      45             : private:
      46             :     SfxPoolItem * const m_pAttr;
      47             :     xub_StrLen m_nStart;
      48             :     bool m_bDontExpand          : 1;
      49             :     bool m_bLockExpandFlag      : 1;
      50             : 
      51             :     bool m_bDontMoveAttr        : 1;    // refmarks, toxmarks
      52             :     bool m_bCharFmtAttr         : 1;    // charfmt, inet
      53             :     bool m_bOverlapAllowedAttr  : 1;    // refmarks, toxmarks
      54             :     bool m_bPriorityAttr        : 1;    // attribute has priority (redlining)
      55             :     bool m_bDontExpandStart     : 1;    // don't expand start at paragraph start (ruby)
      56             :     bool m_bNesting             : 1;    // SwTxtAttrNesting
      57             :     bool m_bHasDummyChar        : 1;    // without end + meta
      58             : 
      59             : protected:
      60             :     SwTxtAttr( SfxPoolItem& rAttr, xub_StrLen nStart );
      61             :     virtual ~SwTxtAttr();
      62             : 
      63          11 :     void SetLockExpandFlag( bool bFlag )    { m_bLockExpandFlag = bFlag; }
      64           1 :     void SetDontMoveAttr( bool bFlag )      { m_bDontMoveAttr = bFlag; }
      65          23 :     void SetCharFmtAttr( bool bFlag )       { m_bCharFmtAttr = bFlag; }
      66           1 :     void SetOverlapAllowedAttr( bool bFlag ){ m_bOverlapAllowedAttr = bFlag; }
      67          11 :     void SetDontExpandStartAttr(bool bFlag) { m_bDontExpandStart = bFlag; }
      68          11 :     void SetNesting(const bool bFlag)       { m_bNesting = bFlag; }
      69         686 :     void SetHasDummyChar(const bool bFlag)  { m_bHasDummyChar = bFlag; }
      70             : 
      71             : public:
      72             : 
      73             :     /// destroy instance
      74             :     static void Destroy( SwTxtAttr * pToDestroy, SfxItemPool& rPool );
      75             : 
      76             :     /// start position
      77      347098 :                   xub_StrLen* GetStart()        { return & m_nStart; }
      78     2203876 :             const xub_StrLen* GetStart() const  { return & m_nStart; }
      79             : 
      80             :     /// end position
      81             :     virtual      xub_StrLen* GetEnd();
      82             :     inline const xub_StrLen* GetEnd() const;
      83             :     /// end (if available), else start
      84             :     inline const xub_StrLen* GetAnyEnd() const;
      85             : 
      86             :     inline void SetDontExpand( bool bDontExpand );
      87        1812 :     bool DontExpand() const                 { return m_bDontExpand; }
      88         100 :     bool IsLockExpandFlag() const           { return m_bLockExpandFlag; }
      89         270 :     bool IsDontMoveAttr() const             { return m_bDontMoveAttr; }
      90        5014 :     bool IsCharFmtAttr() const              { return m_bCharFmtAttr; }
      91       10045 :     bool IsOverlapAllowedAttr() const       { return m_bOverlapAllowedAttr; }
      92         125 :     bool IsPriorityAttr() const             { return m_bPriorityAttr; }
      93          10 :     void SetPriorityAttr( bool bFlag )      { m_bPriorityAttr = bFlag; }
      94           3 :     bool IsDontExpandStartAttr() const      { return m_bDontExpandStart; }
      95       10963 :     bool IsNesting() const                  { return m_bNesting; }
      96       13030 :     bool HasDummyChar() const               { return m_bHasDummyChar; }
      97             : 
      98             :     inline const SfxPoolItem& GetAttr() const;
      99             :     inline       SfxPoolItem& GetAttr();
     100     1129422 :     inline sal_uInt16 Which() const { return GetAttr().Which(); }
     101             : 
     102             :     virtual int         operator==( const SwTxtAttr& ) const;
     103             : 
     104             :     inline const SwFmtCharFmt           &GetCharFmt() const;
     105             :     inline const SwFmtAutoFmt           &GetAutoFmt() const;
     106             :     inline const SwFmtFld               &GetFld() const;
     107             :     inline const SwFmtFtn               &GetFtn() const;
     108             :     inline const SwFmtFlyCnt            &GetFlyCnt() const;
     109             :     inline const SwTOXMark              &GetTOXMark() const;
     110             :     inline const SwFmtRefMark           &GetRefMark() const;
     111             :     inline const SwFmtINetFmt           &GetINetFmt() const;
     112             :     inline const SwFmtRuby              &GetRuby() const;
     113             :     inline const SwFmtMeta              &GetMeta() const;
     114             : 
     115             : };
     116             : 
     117       38298 : class SwTxtAttrEnd : public SwTxtAttr
     118             : {
     119             : protected:
     120             :     xub_StrLen m_nEnd;
     121             : 
     122             : public:
     123             :     SwTxtAttrEnd( SfxPoolItem& rAttr, sal_uInt16 nStart, sal_uInt16 nEnd );
     124             : 
     125             :     using SwTxtAttr::GetEnd;
     126             :     virtual xub_StrLen* GetEnd();
     127             : };
     128             : 
     129             : 
     130             : // --------------- Inline Implementations ------------------------
     131             : 
     132     1054507 : inline const xub_StrLen* SwTxtAttr::GetEnd() const
     133             : {
     134     1054507 :     return const_cast<SwTxtAttr * >(this)->GetEnd();
     135             : }
     136             : 
     137      820865 : inline const xub_StrLen* SwTxtAttr::GetAnyEnd() const
     138             : {
     139      820865 :     const xub_StrLen* pEnd = GetEnd();
     140      820865 :     return pEnd ? pEnd : GetStart();
     141             : }
     142             : 
     143     1276151 : inline const SfxPoolItem& SwTxtAttr::GetAttr() const
     144             : {
     145             :     OSL_ENSURE( m_pAttr, "SwTxtAttr: where is my attribute?" );
     146     1276151 :     return *m_pAttr;
     147             : }
     148             : 
     149       22512 : inline SfxPoolItem& SwTxtAttr::GetAttr()
     150             : {
     151             :     return const_cast<SfxPoolItem&>(
     152       22512 :             const_cast<const SwTxtAttr*>(this)->GetAttr());
     153             : }
     154             : 
     155         212 : inline void SwTxtAttr::SetDontExpand( bool bDontExpand )
     156             : {
     157         212 :     if ( !m_bLockExpandFlag )
     158             :     {
     159         211 :         m_bDontExpand = bDontExpand;
     160             :     }
     161         212 : }
     162             : 
     163             : //------------------------------------------------------------------------
     164             : 
     165          15 : inline const SwFmtCharFmt& SwTxtAttr::GetCharFmt() const
     166             : {
     167             :     OSL_ENSURE( m_pAttr && m_pAttr->Which() == RES_TXTATR_CHARFMT,
     168             :         "Wrong attribute" );
     169          15 :     return (const SwFmtCharFmt&)(*m_pAttr);
     170             : }
     171             : 
     172             : inline const SwFmtAutoFmt& SwTxtAttr::GetAutoFmt() const
     173             : {
     174             :     OSL_ENSURE( m_pAttr && m_pAttr->Which() == RES_TXTATR_AUTOFMT,
     175             :         "Wrong attribute" );
     176             :     return (const SwFmtAutoFmt&)(*m_pAttr);
     177             : }
     178             : 
     179      124532 : inline const SwFmtFld& SwTxtAttr::GetFld() const
     180             : {
     181             :     OSL_ENSURE( m_pAttr && m_pAttr->Which() == RES_TXTATR_FIELD,
     182             :         "Wrong attribute" );
     183      124532 :     return (const SwFmtFld&)(*m_pAttr);
     184             : }
     185             : 
     186         152 : inline const SwFmtFtn& SwTxtAttr::GetFtn() const
     187             : {
     188             :     OSL_ENSURE( m_pAttr && m_pAttr->Which() == RES_TXTATR_FTN, "Wrong attribute" );
     189         152 :     return (const SwFmtFtn&)(*m_pAttr);
     190             : }
     191             : 
     192        1244 : inline const SwFmtFlyCnt& SwTxtAttr::GetFlyCnt() const
     193             : {
     194             :     OSL_ENSURE( m_pAttr && m_pAttr->Which() == RES_TXTATR_FLYCNT,
     195             :         "Wrong attribute" );
     196        1244 :     return (const SwFmtFlyCnt&)(*m_pAttr);
     197             : }
     198             : 
     199           0 : inline const SwTOXMark& SwTxtAttr::GetTOXMark() const
     200             : {
     201             :     OSL_ENSURE( m_pAttr && m_pAttr->Which() == RES_TXTATR_TOXMARK,
     202             :         "Wrong attribute" );
     203           0 :     return (const SwTOXMark&)(*m_pAttr);
     204             : }
     205             : 
     206           0 : inline const SwFmtRefMark& SwTxtAttr::GetRefMark() const
     207             : {
     208             :     OSL_ENSURE( m_pAttr && m_pAttr->Which() == RES_TXTATR_REFMARK,
     209             :         "Wrong attribute" );
     210           0 :     return (const SwFmtRefMark&)(*m_pAttr);
     211             : }
     212             : 
     213         107 : inline const SwFmtINetFmt& SwTxtAttr::GetINetFmt() const
     214             : {
     215             :     OSL_ENSURE( m_pAttr && m_pAttr->Which() == RES_TXTATR_INETFMT,
     216             :         "Wrong attribute" );
     217         107 :     return (const SwFmtINetFmt&)(*m_pAttr);
     218             : }
     219             : 
     220           0 : inline const SwFmtRuby& SwTxtAttr::GetRuby() const
     221             : {
     222             :     OSL_ENSURE( m_pAttr && m_pAttr->Which() == RES_TXTATR_CJK_RUBY,
     223             :         "Wrong attribute" );
     224           0 :     return (const SwFmtRuby&)(*m_pAttr);
     225             : }
     226             : 
     227             : inline const SwFmtMeta& SwTxtAttr::GetMeta() const
     228             : {
     229             :     OSL_ENSURE( m_pAttr && (m_pAttr->Which() == RES_TXTATR_META ||
     230             :                         m_pAttr->Which() == RES_TXTATR_METAFIELD),
     231             :         "Wrong attribute" );
     232             :     return (const SwFmtMeta&)(*m_pAttr);
     233             : }
     234             : 
     235             : #endif
     236             : 
     237             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10