1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #ifndef _TXATBASE_HXX 28 #define _TXATBASE_HXX 29 30 #include <tools/solar.h> 31 #include <svl/poolitem.hxx> 32 #include <hintids.hxx> 33 #include <errhdl.hxx> 34 35 #include <boost/utility.hpp> 36 37 38 class SfxItemPool; 39 class SvXMLAttrContainerItem; 40 class SwFmtRuby; 41 class SwFmtCharFmt; 42 class SwFmtAutoFmt; 43 class SwFmtINetFmt; 44 class SwFmtFld; 45 class SwFmtFtn; 46 class SwFmtFlyCnt; 47 class SwTOXMark; 48 class SwFmtRefMark; 49 class SwFmtMeta; 50 51 52 class SwTxtAttr : private boost::noncopyable 53 { 54 private: 55 SfxPoolItem * const m_pAttr; 56 xub_StrLen m_nStart; 57 bool m_bDontExpand : 1; 58 bool m_bLockExpandFlag : 1; 59 60 bool m_bDontMoveAttr : 1; // refmarks, toxmarks 61 bool m_bCharFmtAttr : 1; // charfmt, inet 62 bool m_bOverlapAllowedAttr : 1; // refmarks, toxmarks 63 bool m_bPriorityAttr : 1; // attribute has priority (redlining) 64 bool m_bDontExpandStart : 1; // don't expand start at paragraph start (ruby) 65 bool m_bNesting : 1; // SwTxtAttrNesting 66 bool m_bHasDummyChar : 1; // without end + meta 67 68 protected: 69 SwTxtAttr( SfxPoolItem& rAttr, xub_StrLen nStart ); 70 virtual ~SwTxtAttr(); 71 72 void SetLockExpandFlag( bool bFlag ) { m_bLockExpandFlag = bFlag; } 73 void SetDontMoveAttr( bool bFlag ) { m_bDontMoveAttr = bFlag; } 74 void SetCharFmtAttr( bool bFlag ) { m_bCharFmtAttr = bFlag; } 75 void SetOverlapAllowedAttr( bool bFlag ){ m_bOverlapAllowedAttr = bFlag; } 76 void SetDontExpandStartAttr(bool bFlag) { m_bDontExpandStart = bFlag; } 77 void SetNesting(const bool bFlag) { m_bNesting = bFlag; } 78 void SetHasDummyChar(const bool bFlag) { m_bHasDummyChar = bFlag; } 79 80 public: 81 82 /// destroy instance 83 static void Destroy( SwTxtAttr * pToDestroy, SfxItemPool& rPool ); 84 85 /// start position 86 xub_StrLen* GetStart() { return & m_nStart; } 87 const xub_StrLen* GetStart() const { return & m_nStart; } 88 89 /// end position 90 virtual xub_StrLen* GetEnd(); 91 inline const xub_StrLen* GetEnd() const; 92 /// end (if available), else start 93 inline const xub_StrLen* GetAnyEnd() const; 94 95 inline void SetDontExpand( bool bDontExpand ); 96 bool DontExpand() const { return m_bDontExpand; } 97 bool IsLockExpandFlag() const { return m_bLockExpandFlag; } 98 bool IsDontMoveAttr() const { return m_bDontMoveAttr; } 99 bool IsCharFmtAttr() const { return m_bCharFmtAttr; } 100 bool IsOverlapAllowedAttr() const { return m_bOverlapAllowedAttr; } 101 bool IsPriorityAttr() const { return m_bPriorityAttr; } 102 void SetPriorityAttr( bool bFlag ) { m_bPriorityAttr = bFlag; } 103 bool IsDontExpandStartAttr() const { return m_bDontExpandStart; } 104 bool IsNesting() const { return m_bNesting; } 105 bool HasDummyChar() const { return m_bHasDummyChar; } 106 107 inline const SfxPoolItem& GetAttr() const; 108 inline SfxPoolItem& GetAttr(); 109 inline sal_uInt16 Which() const { return GetAttr().Which(); } 110 111 virtual int operator==( const SwTxtAttr& ) const; 112 113 inline const SwFmtCharFmt &GetCharFmt() const; 114 inline const SwFmtAutoFmt &GetAutoFmt() const; 115 inline const SwFmtFld &GetFld() const; 116 inline const SwFmtFtn &GetFtn() const; 117 inline const SwFmtFlyCnt &GetFlyCnt() const; 118 inline const SwTOXMark &GetTOXMark() const; 119 inline const SwFmtRefMark &GetRefMark() const; 120 inline const SwFmtINetFmt &GetINetFmt() const; 121 inline const SwFmtRuby &GetRuby() const; 122 inline const SwFmtMeta &GetMeta() const; 123 124 }; 125 126 class SwTxtAttrEnd : public SwTxtAttr 127 { 128 protected: 129 xub_StrLen m_nEnd; 130 131 public: 132 SwTxtAttrEnd( SfxPoolItem& rAttr, sal_uInt16 nStart, sal_uInt16 nEnd ); 133 134 using SwTxtAttr::GetEnd; 135 virtual xub_StrLen* GetEnd(); 136 }; 137 138 139 // --------------- Inline Implementierungen ------------------------ 140 141 inline const xub_StrLen* SwTxtAttr::GetEnd() const 142 { 143 return const_cast<SwTxtAttr * >(this)->GetEnd(); 144 } 145 146 inline const xub_StrLen* SwTxtAttr::GetAnyEnd() const 147 { 148 const xub_StrLen* pEnd = GetEnd(); 149 return pEnd ? pEnd : GetStart(); 150 } 151 152 inline const SfxPoolItem& SwTxtAttr::GetAttr() const 153 { 154 ASSERT( m_pAttr, "SwTxtAttr: where is my attribute?" ); 155 return *m_pAttr; 156 } 157 158 inline SfxPoolItem& SwTxtAttr::GetAttr() 159 { 160 return const_cast<SfxPoolItem&>( 161 const_cast<const SwTxtAttr*>(this)->GetAttr()); 162 } 163 164 inline void SwTxtAttr::SetDontExpand( bool bDontExpand ) 165 { 166 if ( !m_bLockExpandFlag ) 167 { 168 m_bDontExpand = bDontExpand; 169 } 170 } 171 172 //------------------------------------------------------------------------ 173 174 inline const SwFmtCharFmt& SwTxtAttr::GetCharFmt() const 175 { 176 ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_CHARFMT, 177 "Wrong attribute" ); 178 return (const SwFmtCharFmt&)(*m_pAttr); 179 } 180 181 inline const SwFmtAutoFmt& SwTxtAttr::GetAutoFmt() const 182 { 183 ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_AUTOFMT, 184 "Wrong attribute" ); 185 return (const SwFmtAutoFmt&)(*m_pAttr); 186 } 187 188 inline const SwFmtFld& SwTxtAttr::GetFld() const 189 { 190 ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_FIELD, 191 "Wrong attribute" ); 192 return (const SwFmtFld&)(*m_pAttr); 193 } 194 195 inline const SwFmtFtn& SwTxtAttr::GetFtn() const 196 { 197 ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_FTN, "Wrong attribute" ); 198 return (const SwFmtFtn&)(*m_pAttr); 199 } 200 201 inline const SwFmtFlyCnt& SwTxtAttr::GetFlyCnt() const 202 { 203 ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_FLYCNT, 204 "Wrong attribute" ); 205 return (const SwFmtFlyCnt&)(*m_pAttr); 206 } 207 208 inline const SwTOXMark& SwTxtAttr::GetTOXMark() const 209 { 210 ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_TOXMARK, 211 "Wrong attribute" ); 212 return (const SwTOXMark&)(*m_pAttr); 213 } 214 215 inline const SwFmtRefMark& SwTxtAttr::GetRefMark() const 216 { 217 ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_REFMARK, 218 "Wrong attribute" ); 219 return (const SwFmtRefMark&)(*m_pAttr); 220 } 221 222 inline const SwFmtINetFmt& SwTxtAttr::GetINetFmt() const 223 { 224 ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_INETFMT, 225 "Wrong attribute" ); 226 return (const SwFmtINetFmt&)(*m_pAttr); 227 } 228 229 inline const SwFmtRuby& SwTxtAttr::GetRuby() const 230 { 231 ASSERT( m_pAttr && m_pAttr->Which() == RES_TXTATR_CJK_RUBY, 232 "Wrong attribute" ); 233 return (const SwFmtRuby&)(*m_pAttr); 234 } 235 236 inline const SwFmtMeta& SwTxtAttr::GetMeta() const 237 { 238 ASSERT( m_pAttr && (m_pAttr->Which() == RES_TXTATR_META || 239 m_pAttr->Which() == RES_TXTATR_METAFIELD), 240 "Wrong attribute" ); 241 return (const SwFmtMeta&)(*m_pAttr); 242 } 243 244 #endif 245