android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / inc / txatbase.hxx
blob00e2f9b514703433ed585d431fb6ab41db06b414
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 "formatlinebreak.hxx"
32 #include "formatcontentcontrol.hxx"
33 #include "fchrfmt.hxx"
34 #include "tox.hxx"
35 #include "ndhints.hxx"
37 class SfxItemPool;
39 /**
40 * A wrapper around SfxPoolItem to store the start position of (usually) a text portion, with an
41 * optional end.
43 class SW_DLLPUBLIC SwTextAttr
45 friend class SwpHints;
46 private:
47 SfxPoolItem * const m_pAttr;
48 sal_Int32 m_nStart;
49 bool m_bDontExpand : 1;
50 bool m_bLockExpandFlag : 1;
52 bool m_bDontMoveAttr : 1; // refmarks, toxmarks
53 bool m_bCharFormatAttr : 1; // charfmt, inet
54 bool m_bOverlapAllowedAttr : 1; // refmarks, toxmarks
55 bool m_bPriorityAttr : 1; // attribute has priority (redlining)
56 bool m_bDontExpandStart : 1; // don't expand start at paragraph start (ruby)
57 bool m_bNesting : 1; // SwTextAttrNesting
58 bool m_bHasDummyChar : 1; // without end + meta
59 bool m_bFormatIgnoreStart : 1; ///< text formatting should ignore start
60 bool m_bFormatIgnoreEnd : 1; ///< text formatting should ignore end
61 bool m_bHasContent : 1; // text attribute with content
63 SwTextAttr(SwTextAttr const&) = delete;
64 SwTextAttr& operator=(SwTextAttr const&) = delete;
66 protected:
67 SwpHints * m_pHints = nullptr; // the SwpHints holds a pointer to this, and needs to be notified if the start/end changes
69 SwTextAttr( SfxPoolItem& rAttr, sal_Int32 nStart );
70 virtual ~SwTextAttr() COVERITY_NOEXCEPT_FALSE;
72 void SetLockExpandFlag( bool bFlag ) { m_bLockExpandFlag = bFlag; }
73 void SetDontMoveAttr( bool bFlag ) { m_bDontMoveAttr = bFlag; }
74 void SetCharFormatAttr( bool bFlag ) { m_bCharFormatAttr = 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 void SetHasContent( const bool bFlag ) { m_bHasContent = bFlag; }
81 public:
83 /// destroy instance
84 static void Destroy( SwTextAttr * pToDestroy, SfxItemPool& rPool );
86 /// start position
87 void SetStart(sal_Int32 n) { m_nStart = n; if (m_pHints) m_pHints->StartPosChanged(); }
88 sal_Int32 GetStart() const { return m_nStart; }
90 /// end position
91 virtual const sal_Int32* GetEnd() const;
92 virtual void SetEnd(sal_Int32);
93 inline const sal_Int32* End() const;
94 /// end (if available), else start
95 inline sal_Int32 GetAnyEnd() const;
97 inline void SetDontExpand( bool bDontExpand );
98 bool DontExpand() const { return m_bDontExpand; }
99 bool IsLockExpandFlag() const { return m_bLockExpandFlag; }
100 bool IsDontMoveAttr() const { return m_bDontMoveAttr; }
101 bool IsCharFormatAttr() const { return m_bCharFormatAttr; }
102 bool IsOverlapAllowedAttr() const { return m_bOverlapAllowedAttr; }
103 bool IsPriorityAttr() const { return m_bPriorityAttr; }
104 void SetPriorityAttr( bool bFlag ) { m_bPriorityAttr = bFlag; }
105 bool IsDontExpandStartAttr() const { return m_bDontExpandStart; }
106 bool IsNesting() const { return m_bNesting; }
107 bool HasDummyChar() const { return m_bHasDummyChar; }
108 bool IsFormatIgnoreStart() const { return m_bFormatIgnoreStart; }
109 bool IsFormatIgnoreEnd () const { return m_bFormatIgnoreEnd ; }
110 void SetFormatIgnoreStart(bool bFlag) { m_bFormatIgnoreStart = bFlag; }
111 void SetFormatIgnoreEnd (bool bFlag) { m_bFormatIgnoreEnd = bFlag; }
112 bool HasContent() const { return m_bHasContent; }
114 inline const SfxPoolItem& GetAttr() const;
115 inline SfxPoolItem& GetAttr();
116 sal_uInt16 Which() const { return GetAttr().Which(); }
118 bool operator==( const SwTextAttr& ) const;
120 inline const SwFormatCharFormat &GetCharFormat() const;
121 inline const SwFormatAutoFormat &GetAutoFormat() const;
122 inline const SwFormatField &GetFormatField() const;
123 inline const SwFormatFootnote &GetFootnote() const;
124 inline const SwFormatLineBreak& GetLineBreak() const;
125 inline const SwFormatContentControl& GetContentControl() const;
126 inline const SwFormatFlyCnt &GetFlyCnt() const;
127 inline const SwTOXMark &GetTOXMark() const;
128 inline const SwFormatRefMark &GetRefMark() const;
129 inline const SwFormatINetFormat &GetINetFormat() const;
130 inline const SwFormatRuby &GetRuby() const;
132 virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
135 class SW_DLLPUBLIC SwTextAttrEnd : public virtual SwTextAttr
137 protected:
138 sal_Int32 m_nEnd;
140 public:
141 SwTextAttrEnd( SfxPoolItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
143 virtual const sal_Int32* GetEnd() const override;
144 virtual void SetEnd(sal_Int32) override;
147 // attribute that must not overlap others
148 class SAL_DLLPUBLIC_RTTI SwTextAttrNesting : public SwTextAttrEnd
150 protected:
151 SwTextAttrNesting( SfxPoolItem & i_rAttr,
152 const sal_Int32 i_nStart, const sal_Int32 i_nEnd );
153 virtual ~SwTextAttrNesting() override;
156 inline const sal_Int32* SwTextAttr::End() const
158 return GetEnd();
161 inline sal_Int32 SwTextAttr::GetAnyEnd() const
163 const sal_Int32* pEnd = End();
164 return pEnd ? *pEnd : m_nStart;
167 inline const SfxPoolItem& SwTextAttr::GetAttr() const
169 assert( m_pAttr );
170 return *m_pAttr;
173 inline SfxPoolItem& SwTextAttr::GetAttr()
175 return const_cast<SfxPoolItem&>(
176 const_cast<const SwTextAttr*>(this)->GetAttr());
179 inline void SwTextAttr::SetDontExpand( bool bDontExpand )
181 if ( !m_bLockExpandFlag )
183 m_bDontExpand = bDontExpand;
187 inline const SwFormatCharFormat& SwTextAttr::GetCharFormat() const
189 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_CHARFMT );
190 return static_cast<const SwFormatCharFormat&>(*m_pAttr);
193 inline const SwFormatAutoFormat& SwTextAttr::GetAutoFormat() const
195 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_AUTOFMT );
196 return static_cast<const SwFormatAutoFormat&>(*m_pAttr);
199 inline const SwFormatField& SwTextAttr::GetFormatField() const
201 assert( m_pAttr
202 && ( m_pAttr->Which() == RES_TXTATR_FIELD
203 || m_pAttr->Which() == RES_TXTATR_ANNOTATION
204 || m_pAttr->Which() == RES_TXTATR_INPUTFIELD ));
205 return static_cast<const SwFormatField&>(*m_pAttr);
208 inline const SwFormatFootnote& SwTextAttr::GetFootnote() const
210 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_FTN );
211 return static_cast<const SwFormatFootnote&>(*m_pAttr);
214 inline const SwFormatLineBreak& SwTextAttr::GetLineBreak() const
216 assert(m_pAttr && m_pAttr->Which() == RES_TXTATR_LINEBREAK);
217 return static_cast<const SwFormatLineBreak&>(*m_pAttr);
220 inline const SwFormatContentControl& SwTextAttr::GetContentControl() const
222 assert(m_pAttr && m_pAttr->Which() == RES_TXTATR_CONTENTCONTROL);
223 return static_cast<const SwFormatContentControl&>(*m_pAttr);
226 inline const SwFormatFlyCnt& SwTextAttr::GetFlyCnt() const
228 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_FLYCNT );
229 return static_cast<const SwFormatFlyCnt&>(*m_pAttr);
232 inline const SwTOXMark& SwTextAttr::GetTOXMark() const
234 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_TOXMARK );
235 return static_cast<const SwTOXMark&>(*m_pAttr);
238 inline const SwFormatRefMark& SwTextAttr::GetRefMark() const
240 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_REFMARK );
241 return static_cast<const SwFormatRefMark&>(*m_pAttr);
244 inline const SwFormatINetFormat& SwTextAttr::GetINetFormat() const
246 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_INETFMT );
247 return static_cast<const SwFormatINetFormat&>(*m_pAttr);
250 inline const SwFormatRuby& SwTextAttr::GetRuby() const
252 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_CJK_RUBY );
253 return static_cast<const SwFormatRuby&>(*m_pAttr);
256 // these should be static_casts but with virtual inheritance it's not possible
257 template<typename T, typename S> inline T static_txtattr_cast(S * s)
259 return dynamic_cast<T>(s);
261 template<typename T, typename S> inline T static_txtattr_cast(S & s)
263 return dynamic_cast<T>(s);
266 #endif
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */