lok: Hide file linking in section
[LibreOffice.git] / sw / inc / txatbase.hxx
blob90509a929309ae98ff9cf5267a86557f777e6e5a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SW_INC_TXATBASE_HXX
20 #define INCLUDED_SW_INC_TXATBASE_HXX
22 #include <svl/poolitem.hxx>
23 #include "hintids.hxx"
24 #include "fmtautofmt.hxx"
25 #include "fmtinfmt.hxx"
26 #include "fmtrfmrk.hxx"
27 #include "fmtruby.hxx"
28 #include "fmtfld.hxx"
29 #include "fmtflcnt.hxx"
30 #include "fmtftn.hxx"
31 #include "fchrfmt.hxx"
32 #include "tox.hxx"
33 #include "ndhints.hxx"
35 class SfxItemPool;
37 class SAL_DLLPUBLIC_RTTI SwTextAttr
39 friend class SwpHints;
40 private:
41 SfxPoolItem * const m_pAttr;
42 sal_Int32 m_nStart;
43 bool m_bDontExpand : 1;
44 bool m_bLockExpandFlag : 1;
46 bool m_bDontMoveAttr : 1; // refmarks, toxmarks
47 bool m_bCharFormatAttr : 1; // charfmt, inet
48 bool m_bOverlapAllowedAttr : 1; // refmarks, toxmarks
49 bool m_bPriorityAttr : 1; // attribute has priority (redlining)
50 bool m_bDontExpandStart : 1; // don't expand start at paragraph start (ruby)
51 bool m_bNesting : 1; // SwTextAttrNesting
52 bool m_bHasDummyChar : 1; // without end + meta
53 bool m_bFormatIgnoreStart : 1; ///< text formatting should ignore start
54 bool m_bFormatIgnoreEnd : 1; ///< text formatting should ignore end
55 bool m_bHasContent : 1; // text attribute with content
57 SwTextAttr(SwTextAttr const&) = delete;
58 SwTextAttr& operator=(SwTextAttr const&) = delete;
60 protected:
61 SwpHints * m_pHints = nullptr; // the SwpHints holds a pointer to this, and needs to be notified if the start/end changes
63 SwTextAttr( SfxPoolItem& rAttr, sal_Int32 nStart );
64 virtual ~SwTextAttr() COVERITY_NOEXCEPT_FALSE;
66 void SetLockExpandFlag( bool bFlag ) { m_bLockExpandFlag = bFlag; }
67 void SetDontMoveAttr( bool bFlag ) { m_bDontMoveAttr = bFlag; }
68 void SetCharFormatAttr( bool bFlag ) { m_bCharFormatAttr = bFlag; }
69 void SetOverlapAllowedAttr( bool bFlag ){ m_bOverlapAllowedAttr = bFlag; }
70 void SetDontExpandStartAttr(bool bFlag) { m_bDontExpandStart = bFlag; }
71 void SetNesting(const bool bFlag) { m_bNesting = bFlag; }
72 void SetHasDummyChar(const bool bFlag) { m_bHasDummyChar = bFlag; }
73 void SetHasContent( const bool bFlag ) { m_bHasContent = bFlag; }
75 public:
77 /// destroy instance
78 static void Destroy( SwTextAttr * pToDestroy, SfxItemPool& rPool );
80 /// start position
81 void SetStart(sal_Int32 n) { m_nStart = n; if (m_pHints) m_pHints->StartPosChanged(); }
82 sal_Int32 GetStart() const { return m_nStart; }
84 /// end position
85 virtual const sal_Int32* GetEnd() const;
86 virtual void SetEnd(sal_Int32);
87 inline const sal_Int32* End() const;
88 /// end (if available), else start
89 inline sal_Int32 GetAnyEnd() const;
91 inline void SetDontExpand( bool bDontExpand );
92 bool DontExpand() const { return m_bDontExpand; }
93 bool IsLockExpandFlag() const { return m_bLockExpandFlag; }
94 bool IsDontMoveAttr() const { return m_bDontMoveAttr; }
95 bool IsCharFormatAttr() const { return m_bCharFormatAttr; }
96 bool IsOverlapAllowedAttr() const { return m_bOverlapAllowedAttr; }
97 bool IsPriorityAttr() const { return m_bPriorityAttr; }
98 void SetPriorityAttr( bool bFlag ) { m_bPriorityAttr = bFlag; }
99 bool IsDontExpandStartAttr() const { return m_bDontExpandStart; }
100 bool IsNesting() const { return m_bNesting; }
101 bool HasDummyChar() const { return m_bHasDummyChar; }
102 bool IsFormatIgnoreStart() const { return m_bFormatIgnoreStart; }
103 bool IsFormatIgnoreEnd () const { return m_bFormatIgnoreEnd ; }
104 void SetFormatIgnoreStart(bool bFlag) { m_bFormatIgnoreStart = bFlag; }
105 void SetFormatIgnoreEnd (bool bFlag) { m_bFormatIgnoreEnd = bFlag; }
106 bool HasContent() const { return m_bHasContent; }
108 inline const SfxPoolItem& GetAttr() const;
109 inline SfxPoolItem& GetAttr();
110 sal_uInt16 Which() const { return GetAttr().Which(); }
112 bool operator==( const SwTextAttr& ) const;
114 inline const SwFormatCharFormat &GetCharFormat() const;
115 inline const SwFormatAutoFormat &GetAutoFormat() const;
116 inline const SwFormatField &GetFormatField() const;
117 inline const SwFormatFootnote &GetFootnote() const;
118 inline const SwFormatFlyCnt &GetFlyCnt() const;
119 inline const SwTOXMark &GetTOXMark() const;
120 inline const SwFormatRefMark &GetRefMark() const;
121 inline const SwFormatINetFormat &GetINetFormat() const;
122 inline const SwFormatRuby &GetRuby() const;
124 void dumpAsXml(xmlTextWriterPtr pWriter) const;
127 class SAL_DLLPUBLIC_RTTI SwTextAttrEnd : public virtual SwTextAttr
129 protected:
130 sal_Int32 m_nEnd;
132 public:
133 SwTextAttrEnd( SfxPoolItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
135 virtual const sal_Int32* GetEnd() const override;
136 virtual void SetEnd(sal_Int32) override;
139 // attribute that must not overlap others
140 class SAL_DLLPUBLIC_RTTI SwTextAttrNesting : public SwTextAttrEnd
142 protected:
143 SwTextAttrNesting( SfxPoolItem & i_rAttr,
144 const sal_Int32 i_nStart, const sal_Int32 i_nEnd );
145 virtual ~SwTextAttrNesting() override;
148 inline const sal_Int32* SwTextAttr::End() const
150 return GetEnd();
153 inline sal_Int32 SwTextAttr::GetAnyEnd() const
155 const sal_Int32* pEnd = End();
156 return pEnd ? *pEnd : m_nStart;
159 inline const SfxPoolItem& SwTextAttr::GetAttr() const
161 assert( m_pAttr );
162 return *m_pAttr;
165 inline SfxPoolItem& SwTextAttr::GetAttr()
167 return const_cast<SfxPoolItem&>(
168 const_cast<const SwTextAttr*>(this)->GetAttr());
171 inline void SwTextAttr::SetDontExpand( bool bDontExpand )
173 if ( !m_bLockExpandFlag )
175 m_bDontExpand = bDontExpand;
179 inline const SwFormatCharFormat& SwTextAttr::GetCharFormat() const
181 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_CHARFMT );
182 return static_cast<const SwFormatCharFormat&>(*m_pAttr);
185 inline const SwFormatAutoFormat& SwTextAttr::GetAutoFormat() const
187 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_AUTOFMT );
188 return static_cast<const SwFormatAutoFormat&>(*m_pAttr);
191 inline const SwFormatField& SwTextAttr::GetFormatField() const
193 assert( m_pAttr
194 && ( m_pAttr->Which() == RES_TXTATR_FIELD
195 || m_pAttr->Which() == RES_TXTATR_ANNOTATION
196 || m_pAttr->Which() == RES_TXTATR_INPUTFIELD ));
197 return static_cast<const SwFormatField&>(*m_pAttr);
200 inline const SwFormatFootnote& SwTextAttr::GetFootnote() const
202 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_FTN );
203 return static_cast<const SwFormatFootnote&>(*m_pAttr);
206 inline const SwFormatFlyCnt& SwTextAttr::GetFlyCnt() const
208 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_FLYCNT );
209 return static_cast<const SwFormatFlyCnt&>(*m_pAttr);
212 inline const SwTOXMark& SwTextAttr::GetTOXMark() const
214 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_TOXMARK );
215 return static_cast<const SwTOXMark&>(*m_pAttr);
218 inline const SwFormatRefMark& SwTextAttr::GetRefMark() const
220 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_REFMARK );
221 return static_cast<const SwFormatRefMark&>(*m_pAttr);
224 inline const SwFormatINetFormat& SwTextAttr::GetINetFormat() const
226 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_INETFMT );
227 return static_cast<const SwFormatINetFormat&>(*m_pAttr);
230 inline const SwFormatRuby& SwTextAttr::GetRuby() const
232 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_CJK_RUBY );
233 return static_cast<const SwFormatRuby&>(*m_pAttr);
236 // these should be static_casts but with virtual inheritance it's not possible
237 template<typename T, typename S> inline T static_txtattr_cast(S * s)
239 return dynamic_cast<T>(s);
241 template<typename T, typename S> inline T static_txtattr_cast(S & s)
243 return dynamic_cast<T>(s);
246 #endif
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */