1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
30 #include <fmtflcnt.hxx>
32 #include <fmtmeta.hxx>
33 #include <fchrfmt.hxx>
38 class SvXMLAttrContainerItem
;
43 SfxPoolItem
* const m_pAttr
;
45 bool m_bDontExpand
: 1;
46 bool m_bLockExpandFlag
: 1;
48 bool m_bDontMoveAttr
: 1; // refmarks, toxmarks
49 bool m_bCharFormatAttr
: 1; // charfmt, inet
50 bool m_bOverlapAllowedAttr
: 1; // refmarks, toxmarks
51 bool m_bPriorityAttr
: 1; // attribute has priority (redlining)
52 bool m_bDontExpandStart
: 1; // don't expand start at paragraph start (ruby)
53 bool m_bNesting
: 1; // SwTextAttrNesting
54 bool m_bHasDummyChar
: 1; // without end + meta
55 bool m_bFormatIgnoreStart
: 1; ///< text formatting should ignore start
56 bool m_bFormatIgnoreEnd
: 1; ///< text formatting should ignore end
57 bool m_bHasContent
: 1; // text attribute with content
59 SwTextAttr(SwTextAttr
const&) = delete;
60 SwTextAttr
& operator=(SwTextAttr
const&) = delete;
63 SwTextAttr( SfxPoolItem
& rAttr
, sal_Int32 nStart
);
64 virtual ~SwTextAttr();
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
; }
78 static void Destroy( SwTextAttr
* pToDestroy
, SfxItemPool
& rPool
);
81 sal_Int32
& GetStart() { return m_nStart
; }
82 const sal_Int32
& GetStart() const { return m_nStart
; }
85 virtual sal_Int32
* GetEnd(); // also used to change the end position
86 inline const sal_Int32
* End() const;
87 /// end (if available), else start
88 inline const sal_Int32
* GetAnyEnd() const;
90 inline void SetDontExpand( bool bDontExpand
);
91 bool DontExpand() const { return m_bDontExpand
; }
92 bool IsLockExpandFlag() const { return m_bLockExpandFlag
; }
93 bool IsDontMoveAttr() const { return m_bDontMoveAttr
; }
94 bool IsCharFormatAttr() const { return m_bCharFormatAttr
; }
95 bool IsOverlapAllowedAttr() const { return m_bOverlapAllowedAttr
; }
96 bool IsPriorityAttr() const { return m_bPriorityAttr
; }
97 void SetPriorityAttr( bool bFlag
) { m_bPriorityAttr
= bFlag
; }
98 bool IsDontExpandStartAttr() const { return m_bDontExpandStart
; }
99 bool IsNesting() const { return m_bNesting
; }
100 bool HasDummyChar() const { return m_bHasDummyChar
; }
101 bool IsFormatIgnoreStart() const { return m_bFormatIgnoreStart
; }
102 bool IsFormatIgnoreEnd () const { return m_bFormatIgnoreEnd
; }
103 void SetFormatIgnoreStart(bool bFlag
) { m_bFormatIgnoreStart
= bFlag
; }
104 void SetFormatIgnoreEnd (bool bFlag
) { m_bFormatIgnoreEnd
= bFlag
; }
105 bool HasContent() const { return m_bHasContent
; }
107 inline const SfxPoolItem
& GetAttr() const;
108 inline SfxPoolItem
& GetAttr();
109 sal_uInt16
Which() const { return GetAttr().Which(); }
111 bool operator==( const SwTextAttr
& ) const;
113 inline const SwFormatCharFormat
&GetCharFormat() const;
114 inline const SwFormatAutoFormat
&GetAutoFormat() const;
115 inline const SwFormatField
&GetFormatField() const;
116 inline const SwFormatFootnote
&GetFootnote() const;
117 inline const SwFormatFlyCnt
&GetFlyCnt() const;
118 inline const SwTOXMark
&GetTOXMark() const;
119 inline const SwFormatRefMark
&GetRefMark() const;
120 inline const SwFormatINetFormat
&GetINetFormat() const;
121 inline const SwFormatRuby
&GetRuby() const;
123 void dumpAsXml(struct _xmlTextWriter
* pWriter
) const;
126 class SwTextAttrEnd
: public virtual SwTextAttr
132 SwTextAttrEnd( SfxPoolItem
& rAttr
, sal_Int32 nStart
, sal_Int32 nEnd
);
134 virtual sal_Int32
* GetEnd() override
;
137 // attribute that must not overlap others
138 class SwTextAttrNesting
: public SwTextAttrEnd
141 SwTextAttrNesting( SfxPoolItem
& i_rAttr
,
142 const sal_Int32 i_nStart
, const sal_Int32 i_nEnd
);
143 virtual ~SwTextAttrNesting() override
;
146 inline const sal_Int32
* SwTextAttr::End() const
148 return const_cast<SwTextAttr
* >(this)->GetEnd();
151 inline const sal_Int32
* SwTextAttr::GetAnyEnd() const
153 const sal_Int32
* pEnd
= End();
154 return pEnd
? pEnd
: &GetStart();
157 inline const SfxPoolItem
& SwTextAttr::GetAttr() const
163 inline SfxPoolItem
& SwTextAttr::GetAttr()
165 return const_cast<SfxPoolItem
&>(
166 const_cast<const SwTextAttr
*>(this)->GetAttr());
169 inline void SwTextAttr::SetDontExpand( bool bDontExpand
)
171 if ( !m_bLockExpandFlag
)
173 m_bDontExpand
= bDontExpand
;
177 inline const SwFormatCharFormat
& SwTextAttr::GetCharFormat() const
179 assert( m_pAttr
&& m_pAttr
->Which() == RES_TXTATR_CHARFMT
);
180 return static_cast<const SwFormatCharFormat
&>(*m_pAttr
);
183 inline const SwFormatAutoFormat
& SwTextAttr::GetAutoFormat() const
185 assert( m_pAttr
&& m_pAttr
->Which() == RES_TXTATR_AUTOFMT
);
186 return static_cast<const SwFormatAutoFormat
&>(*m_pAttr
);
189 inline const SwFormatField
& SwTextAttr::GetFormatField() const
192 && ( m_pAttr
->Which() == RES_TXTATR_FIELD
193 || m_pAttr
->Which() == RES_TXTATR_ANNOTATION
194 || m_pAttr
->Which() == RES_TXTATR_INPUTFIELD
));
195 return static_cast<const SwFormatField
&>(*m_pAttr
);
198 inline const SwFormatFootnote
& SwTextAttr::GetFootnote() const
200 assert( m_pAttr
&& m_pAttr
->Which() == RES_TXTATR_FTN
);
201 return static_cast<const SwFormatFootnote
&>(*m_pAttr
);
204 inline const SwFormatFlyCnt
& SwTextAttr::GetFlyCnt() const
206 assert( m_pAttr
&& m_pAttr
->Which() == RES_TXTATR_FLYCNT
);
207 return static_cast<const SwFormatFlyCnt
&>(*m_pAttr
);
210 inline const SwTOXMark
& SwTextAttr::GetTOXMark() const
212 assert( m_pAttr
&& m_pAttr
->Which() == RES_TXTATR_TOXMARK
);
213 return static_cast<const SwTOXMark
&>(*m_pAttr
);
216 inline const SwFormatRefMark
& SwTextAttr::GetRefMark() const
218 assert( m_pAttr
&& m_pAttr
->Which() == RES_TXTATR_REFMARK
);
219 return static_cast<const SwFormatRefMark
&>(*m_pAttr
);
222 inline const SwFormatINetFormat
& SwTextAttr::GetINetFormat() const
224 assert( m_pAttr
&& m_pAttr
->Which() == RES_TXTATR_INETFMT
);
225 return static_cast<const SwFormatINetFormat
&>(*m_pAttr
);
228 inline const SwFormatRuby
& SwTextAttr::GetRuby() const
230 assert( m_pAttr
&& m_pAttr
->Which() == RES_TXTATR_CJK_RUBY
);
231 return static_cast<const SwFormatRuby
&>(*m_pAttr
);
234 // these should be static_casts but with virtual inheritance it's not possible
235 template<typename T
, typename S
> inline T
static_txtattr_cast(S
* s
)
237 return dynamic_cast<T
>(s
);
239 template<typename T
, typename S
> inline T
static_txtattr_cast(S
& s
)
241 return dynamic_cast<T
>(s
);
246 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */