Branch libreoffice-5-0-4
[LibreOffice.git] / sw / inc / txatbase.hxx
blobf1f70b431555e9275370eabe46f0f8e6a3718b14
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 <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>
36 #include <boost/utility.hpp>
38 class SfxItemPool;
39 class SvXMLAttrContainerItem;
41 class SwTextAttr : private boost::noncopyable
43 private:
44 SfxPoolItem * const m_pAttr;
45 sal_Int32 m_nStart;
46 bool m_bDontExpand : 1;
47 bool m_bLockExpandFlag : 1;
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
60 protected:
61 SwTextAttr( SfxPoolItem& rAttr, sal_Int32 nStart );
62 virtual ~SwTextAttr();
64 void SetLockExpandFlag( bool bFlag ) { m_bLockExpandFlag = bFlag; }
65 void SetDontMoveAttr( bool bFlag ) { m_bDontMoveAttr = bFlag; }
66 void SetCharFormatAttr( bool bFlag ) { m_bCharFormatAttr = bFlag; }
67 void SetOverlapAllowedAttr( bool bFlag ){ m_bOverlapAllowedAttr = bFlag; }
68 void SetDontExpandStartAttr(bool bFlag) { m_bDontExpandStart = bFlag; }
69 void SetNesting(const bool bFlag) { m_bNesting = bFlag; }
70 void SetHasDummyChar(const bool bFlag) { m_bHasDummyChar = bFlag; }
71 void SetHasContent( const bool bFlag ) { m_bHasContent = bFlag; }
73 public:
75 /// destroy instance
76 static void Destroy( SwTextAttr * pToDestroy, SfxItemPool& rPool );
78 /// start position
79 sal_Int32& GetStart() { return m_nStart; }
80 const sal_Int32& GetStart() const { return m_nStart; }
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;
88 inline void SetDontExpand( bool bDontExpand );
89 bool DontExpand() const { return m_bDontExpand; }
90 bool IsLockExpandFlag() const { return m_bLockExpandFlag; }
91 bool IsDontMoveAttr() const { return m_bDontMoveAttr; }
92 bool IsCharFormatAttr() const { return m_bCharFormatAttr; }
93 bool IsOverlapAllowedAttr() const { return m_bOverlapAllowedAttr; }
94 bool IsPriorityAttr() const { return m_bPriorityAttr; }
95 void SetPriorityAttr( bool bFlag ) { m_bPriorityAttr = bFlag; }
96 bool IsDontExpandStartAttr() const { return m_bDontExpandStart; }
97 bool IsNesting() const { return m_bNesting; }
98 bool HasDummyChar() const { return m_bHasDummyChar; }
99 bool IsFormatIgnoreStart() const { return m_bFormatIgnoreStart; }
100 bool IsFormatIgnoreEnd () const { return m_bFormatIgnoreEnd ; }
101 void SetFormatIgnoreStart(bool bFlag) { m_bFormatIgnoreStart = bFlag; }
102 void SetFormatIgnoreEnd (bool bFlag) { m_bFormatIgnoreEnd = bFlag; }
103 bool HasContent() const { return m_bHasContent; }
105 inline const SfxPoolItem& GetAttr() const;
106 inline SfxPoolItem& GetAttr();
107 inline sal_uInt16 Which() const { return GetAttr().Which(); }
109 bool operator==( const SwTextAttr& ) const;
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;
122 void dumpAsXml(struct _xmlTextWriter* pWriter) const;
125 class SwTextAttrEnd : public virtual SwTextAttr
127 protected:
128 sal_Int32 m_nEnd;
130 public:
131 SwTextAttrEnd( SfxPoolItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
133 virtual sal_Int32* GetEnd() SAL_OVERRIDE;
136 // attribute that must not overlap others
137 class SwTextAttrNesting : public SwTextAttrEnd
139 protected:
140 SwTextAttrNesting( SfxPoolItem & i_rAttr,
141 const sal_Int32 i_nStart, const sal_Int32 i_nEnd );
142 virtual ~SwTextAttrNesting();
145 inline const sal_Int32* SwTextAttr::End() const
147 return const_cast<SwTextAttr * >(this)->GetEnd();
150 inline const sal_Int32* SwTextAttr::GetAnyEnd() const
152 const sal_Int32* pEnd = End();
153 return pEnd ? pEnd : &GetStart();
156 inline const SfxPoolItem& SwTextAttr::GetAttr() const
158 assert( m_pAttr );
159 return *m_pAttr;
162 inline SfxPoolItem& SwTextAttr::GetAttr()
164 return const_cast<SfxPoolItem&>(
165 const_cast<const SwTextAttr*>(this)->GetAttr());
168 inline void SwTextAttr::SetDontExpand( bool bDontExpand )
170 if ( !m_bLockExpandFlag )
172 m_bDontExpand = bDontExpand;
176 inline const SwFormatCharFormat& SwTextAttr::GetCharFormat() const
178 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_CHARFMT );
179 return static_cast<const SwFormatCharFormat&>(*m_pAttr);
182 inline const SwFormatAutoFormat& SwTextAttr::GetAutoFormat() const
184 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_AUTOFMT );
185 return static_cast<const SwFormatAutoFormat&>(*m_pAttr);
188 inline const SwFormatField& SwTextAttr::GetFormatField() const
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 return static_cast<const SwFormatField&>(*m_pAttr);
197 inline const SwFormatFootnote& SwTextAttr::GetFootnote() const
199 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_FTN );
200 return static_cast<const SwFormatFootnote&>(*m_pAttr);
203 inline const SwFormatFlyCnt& SwTextAttr::GetFlyCnt() const
205 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_FLYCNT );
206 return static_cast<const SwFormatFlyCnt&>(*m_pAttr);
209 inline const SwTOXMark& SwTextAttr::GetTOXMark() const
211 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_TOXMARK );
212 return static_cast<const SwTOXMark&>(*m_pAttr);
215 inline const SwFormatRefMark& SwTextAttr::GetRefMark() const
217 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_REFMARK );
218 return static_cast<const SwFormatRefMark&>(*m_pAttr);
221 inline const SwFormatINetFormat& SwTextAttr::GetINetFormat() const
223 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_INETFMT );
224 return static_cast<const SwFormatINetFormat&>(*m_pAttr);
227 inline const SwFormatRuby& SwTextAttr::GetRuby() const
229 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_CJK_RUBY );
230 return static_cast<const SwFormatRuby&>(*m_pAttr);
233 inline const SwFormatMeta& SwTextAttr::GetMeta() const
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);
240 // these should be static_casts but with virtual inheritance it's not possible
241 template<typename T, typename S> inline T static_txtattr_cast(S * s)
243 return dynamic_cast<T>(s);
245 template<typename T, typename S> inline T static_txtattr_cast(S & s)
247 return dynamic_cast<T>(s);
250 #endif
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */