LibreOffice Module sw (master) 1
txatbase.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#ifndef INCLUDED_SW_INC_TXATBASE_HXX
20#define INCLUDED_SW_INC_TXATBASE_HXX
21
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"
33#include "fchrfmt.hxx"
34#include "tox.hxx"
35#include "ndhints.hxx"
36
37class SfxItemPool;
38
44{
45friend class SwpHints;
46private:
48 sal_Int32 m_nStart;
49 bool m_bDontExpand : 1;
51
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
61 bool m_bHasContent : 1; // text attribute with content
62
63 SwTextAttr(SwTextAttr const&) = delete;
64 SwTextAttr& operator=(SwTextAttr const&) = delete;
65
66protected:
67 SwpHints * m_pHints = nullptr; // the SwpHints holds a pointer to this, and needs to be notified if the start/end changes
68
69 SwTextAttr( SfxPoolItem& rAttr, sal_Int32 nStart );
70 virtual ~SwTextAttr() COVERITY_NOEXCEPT_FALSE;
71
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; }
80
81public:
82
84 static void Destroy( SwTextAttr * pToDestroy, SfxItemPool& rPool );
85
87 void SetStart(sal_Int32 n) { m_nStart = n; if (m_pHints) m_pHints->StartPosChanged(); }
88 sal_Int32 GetStart() const { return m_nStart; }
89
91 virtual const sal_Int32* GetEnd() const;
92 virtual void SetEnd(sal_Int32);
93 inline const sal_Int32* End() const;
95 inline sal_Int32 GetAnyEnd() const;
96
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; }
113
114 inline const SfxPoolItem& GetAttr() const;
115 inline SfxPoolItem& GetAttr();
116 sal_uInt16 Which() const { return GetAttr().Which(); }
117
118 bool operator==( const SwTextAttr& ) const;
119
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;
131
132 virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
133};
134
136{
137protected:
138 sal_Int32 m_nEnd;
139
140public:
141 SwTextAttrEnd( SfxPoolItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
142
143 virtual const sal_Int32* GetEnd() const override;
144 virtual void SetEnd(sal_Int32) override;
145};
146
147// attribute that must not overlap others
148class SAL_DLLPUBLIC_RTTI SwTextAttrNesting : public SwTextAttrEnd
149{
150protected:
152 const sal_Int32 i_nStart, const sal_Int32 i_nEnd );
153 virtual ~SwTextAttrNesting() override;
154};
155
156inline const sal_Int32* SwTextAttr::End() const
157{
158 return GetEnd();
159}
160
161inline sal_Int32 SwTextAttr::GetAnyEnd() const
162{
163 const sal_Int32* pEnd = End();
164 return pEnd ? *pEnd : m_nStart;
165}
166
167inline const SfxPoolItem& SwTextAttr::GetAttr() const
168{
169 assert( m_pAttr );
170 return *m_pAttr;
171}
172
174{
175 return const_cast<SfxPoolItem&>(
176 const_cast<const SwTextAttr*>(this)->GetAttr());
177}
178
179inline void SwTextAttr::SetDontExpand( bool bDontExpand )
180{
181 if ( !m_bLockExpandFlag )
182 {
183 m_bDontExpand = bDontExpand;
184 }
185}
186
188{
189 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_CHARFMT );
190 return static_cast<const SwFormatCharFormat&>(*m_pAttr);
191}
192
194{
195 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_AUTOFMT );
196 return static_cast<const SwFormatAutoFormat&>(*m_pAttr);
197}
198
200{
201 assert( m_pAttr
205 return static_cast<const SwFormatField&>(*m_pAttr);
206}
207
209{
210 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_FTN );
211 return static_cast<const SwFormatFootnote&>(*m_pAttr);
212}
213
215{
216 assert(m_pAttr && m_pAttr->Which() == RES_TXTATR_LINEBREAK);
217 return static_cast<const SwFormatLineBreak&>(*m_pAttr);
218}
219
221{
223 return static_cast<const SwFormatContentControl&>(*m_pAttr);
224}
225
227{
228 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_FLYCNT );
229 return static_cast<const SwFormatFlyCnt&>(*m_pAttr);
230}
231
233{
234 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_TOXMARK );
235 return static_cast<const SwTOXMark&>(*m_pAttr);
236}
237
239{
240 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_REFMARK );
241 return static_cast<const SwFormatRefMark&>(*m_pAttr);
242}
243
245{
246 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_INETFMT );
247 return static_cast<const SwFormatINetFormat&>(*m_pAttr);
248}
249
251{
252 assert( m_pAttr && m_pAttr->Which() == RES_TXTATR_CJK_RUBY );
253 return static_cast<const SwFormatRuby&>(*m_pAttr);
254}
255
256// these should be static_casts but with virtual inheritance it's not possible
257template<typename T, typename S> inline T static_txtattr_cast(S * s)
258{
259 return dynamic_cast<T>(s);
260}
261template<typename T, typename S> inline T static_txtattr_cast(S & s)
262{
263 return dynamic_cast<T>(s);
264}
265
266#endif
267
268/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 Which() const
SfxPoolItem subclass that wraps an SwContentControl.
Format of a fly content.
Definition: fmtflcnt.hxx:33
SfxPoolItem subclass for footnotes and endnotes, stored in the anchor text node.
Definition: fmtftn.hxx:47
SfxPoolItem subclass that wraps an SwLineBreakClear.
sal_Int32 m_nEnd
Definition: txatbase.hxx:138
A wrapper around SfxPoolItem to store the start position of (usually) a text portion,...
Definition: txatbase.hxx:44
bool m_bPriorityAttr
Definition: txatbase.hxx:55
sal_Int32 m_nStart
Definition: txatbase.hxx:48
void SetDontExpandStartAttr(bool bFlag)
Definition: txatbase.hxx:76
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:167
void SetFormatIgnoreStart(bool bFlag)
Definition: txatbase.hxx:110
bool IsOverlapAllowedAttr() const
Definition: txatbase.hxx:102
void SetDontMoveAttr(bool bFlag)
Definition: txatbase.hxx:73
sal_Int32 GetAnyEnd() const
end (if available), else start
Definition: txatbase.hxx:161
virtual const sal_Int32 * GetEnd() const
end position
Definition: txatbase.cxx:48
const SwFormatRefMark & GetRefMark() const
Definition: txatbase.hxx:238
bool IsFormatIgnoreStart() const
Definition: txatbase.hxx:108
SfxPoolItem *const m_pAttr
Definition: txatbase.hxx:47
bool IsNesting() const
Definition: txatbase.hxx:106
const sal_Int32 * End() const
Definition: txatbase.hxx:156
void SetCharFormatAttr(bool bFlag)
Definition: txatbase.hxx:74
const SwFormatFlyCnt & GetFlyCnt() const
Definition: txatbase.hxx:226
void SetOverlapAllowedAttr(bool bFlag)
Definition: txatbase.hxx:75
const SwFormatLineBreak & GetLineBreak() const
Definition: txatbase.hxx:214
const SwFormatFootnote & GetFootnote() const
Definition: txatbase.hxx:208
sal_Int32 GetStart() const
Definition: txatbase.hxx:88
bool m_bDontMoveAttr
Definition: txatbase.hxx:52
const SwFormatINetFormat & GetINetFormat() const
Definition: txatbase.hxx:244
const SwFormatCharFormat & GetCharFormat() const
Definition: txatbase.hxx:187
const SwFormatRuby & GetRuby() const
Definition: txatbase.hxx:250
bool m_bHasDummyChar
Definition: txatbase.hxx:58
bool m_bOverlapAllowedAttr
Definition: txatbase.hxx:54
bool m_bDontExpandStart
Definition: txatbase.hxx:56
void SetFormatIgnoreEnd(bool bFlag)
Definition: txatbase.hxx:111
void SetStart(sal_Int32 n)
start position
Definition: txatbase.hxx:87
void SetHasContent(const bool bFlag)
Definition: txatbase.hxx:79
bool IsDontMoveAttr() const
Definition: txatbase.hxx:100
bool m_bNesting
Definition: txatbase.hxx:57
bool IsCharFormatAttr() const
Definition: txatbase.hxx:101
bool DontExpand() const
Definition: txatbase.hxx:98
bool m_bFormatIgnoreStart
text formatting should ignore start
Definition: txatbase.hxx:59
bool IsPriorityAttr() const
Definition: txatbase.hxx:103
void SetHasDummyChar(const bool bFlag)
Definition: txatbase.hxx:78
SwTextAttr(SwTextAttr const &)=delete
bool m_bLockExpandFlag
Definition: txatbase.hxx:50
bool m_bCharFormatAttr
Definition: txatbase.hxx:53
bool m_bDontExpand
Definition: txatbase.hxx:49
SwTextAttr & operator=(SwTextAttr const &)=delete
const SwFormatAutoFormat & GetAutoFormat() const
Definition: txatbase.hxx:193
const SwFormatContentControl & GetContentControl() const
Definition: txatbase.hxx:220
bool HasContent() const
Definition: txatbase.hxx:112
void SetDontExpand(bool bDontExpand)
Definition: txatbase.hxx:179
bool HasDummyChar() const
Definition: txatbase.hxx:107
bool IsDontExpandStartAttr() const
Definition: txatbase.hxx:105
bool m_bHasContent
Definition: txatbase.hxx:61
sal_uInt16 Which() const
Definition: txatbase.hxx:116
bool IsLockExpandFlag() const
Definition: txatbase.hxx:99
void SetPriorityAttr(bool bFlag)
Definition: txatbase.hxx:104
void SetNesting(const bool bFlag)
Definition: txatbase.hxx:77
bool IsFormatIgnoreEnd() const
Definition: txatbase.hxx:109
bool m_bFormatIgnoreEnd
text formatting should ignore end
Definition: txatbase.hxx:60
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:199
const SwTOXMark & GetTOXMark() const
Definition: txatbase.hxx:232
An SwTextAttr container, stores all directly formatted text portions for a text node.
Definition: ndhints.hxx:68
void StartPosChanged() const
Definition: ndhints.hxx:212
struct _xmlTextWriter * xmlTextWriterPtr
constexpr TypedWhichId< SwFormatFootnote > RES_TXTATR_FTN(59)
constexpr TypedWhichId< SwFormatAutoFormat > RES_TXTATR_AUTOFMT(50)
constexpr TypedWhichId< SwFormatINetFormat > RES_TXTATR_INETFMT(51)
constexpr TypedWhichId< SwFormatField > RES_TXTATR_ANNOTATION(60)
constexpr TypedWhichId< SwFormatContentControl > RES_TXTATR_CONTENTCONTROL(56)
constexpr TypedWhichId< SwFormatField > RES_TXTATR_FIELD(RES_TXTATR_NOEND_BEGIN)
constexpr TypedWhichId< SwFormatCharFormat > RES_TXTATR_CHARFMT(52)
constexpr TypedWhichId< SwFormatFlyCnt > RES_TXTATR_FLYCNT(58)
constexpr TypedWhichId< SwFormatLineBreak > RES_TXTATR_LINEBREAK(61)
constexpr TypedWhichId< SwFormatRefMark > RES_TXTATR_REFMARK(RES_TXTATR_WITHEND_BEGIN)
constexpr TypedWhichId< SwTOXMark > RES_TXTATR_TOXMARK(47)
constexpr TypedWhichId< SwFormatRuby > RES_TXTATR_CJK_RUBY(53)
constexpr TypedWhichId< SwFormatField > RES_TXTATR_INPUTFIELD(55)
sal_Int64 n
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
T static_txtattr_cast(S *s)
Definition: txatbase.hxx:257
bool operator==(const XclFontData &rLeft, const XclFontData &rRight)