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 "fchrfmt.hxx"
32 #include "tox.hxx"
33 #include "ndhints.hxx"
34 
35 class SfxItemPool;
36 
41 class SAL_DLLPUBLIC_RTTI SwTextAttr
42 {
43 friend class SwpHints;
44 private:
46  sal_Int32 m_nStart;
47  bool m_bDontExpand : 1;
48  bool m_bLockExpandFlag : 1;
49 
50  bool m_bDontMoveAttr : 1; // refmarks, toxmarks
51  bool m_bCharFormatAttr : 1; // charfmt, inet
52  bool m_bOverlapAllowedAttr : 1; // refmarks, toxmarks
53  bool m_bPriorityAttr : 1; // attribute has priority (redlining)
54  bool m_bDontExpandStart : 1; // don't expand start at paragraph start (ruby)
55  bool m_bNesting : 1; // SwTextAttrNesting
56  bool m_bHasDummyChar : 1; // without end + meta
57  bool m_bFormatIgnoreStart : 1;
58  bool m_bFormatIgnoreEnd : 1;
59  bool m_bHasContent : 1; // text attribute with content
60 
61  SwTextAttr(SwTextAttr const&) = delete;
62  SwTextAttr& operator=(SwTextAttr const&) = delete;
63 
64 protected:
65  SwpHints * m_pHints = nullptr; // the SwpHints holds a pointer to this, and needs to be notified if the start/end changes
66 
67  SwTextAttr( SfxPoolItem& rAttr, sal_Int32 nStart );
68  virtual ~SwTextAttr() COVERITY_NOEXCEPT_FALSE;
69 
70  void SetLockExpandFlag( bool bFlag ) { m_bLockExpandFlag = bFlag; }
71  void SetDontMoveAttr( bool bFlag ) { m_bDontMoveAttr = bFlag; }
72  void SetCharFormatAttr( bool bFlag ) { m_bCharFormatAttr = bFlag; }
73  void SetOverlapAllowedAttr( bool bFlag ){ m_bOverlapAllowedAttr = bFlag; }
74  void SetDontExpandStartAttr(bool bFlag) { m_bDontExpandStart = bFlag; }
75  void SetNesting(const bool bFlag) { m_bNesting = bFlag; }
76  void SetHasDummyChar(const bool bFlag) { m_bHasDummyChar = bFlag; }
77  void SetHasContent( const bool bFlag ) { m_bHasContent = bFlag; }
78 
79 public:
80 
82  static void Destroy( SwTextAttr * pToDestroy, SfxItemPool& rPool );
83 
85  void SetStart(sal_Int32 n) { m_nStart = n; if (m_pHints) m_pHints->StartPosChanged(); }
86  sal_Int32 GetStart() const { return m_nStart; }
87 
89  virtual const sal_Int32* GetEnd() const;
90  virtual void SetEnd(sal_Int32);
91  inline const sal_Int32* End() const;
93  inline sal_Int32 GetAnyEnd() const;
94 
95  inline void SetDontExpand( bool bDontExpand );
96  bool DontExpand() const { return m_bDontExpand; }
97  bool IsLockExpandFlag() const { return m_bLockExpandFlag; }
98  bool IsDontMoveAttr() const { return m_bDontMoveAttr; }
99  bool IsCharFormatAttr() const { return m_bCharFormatAttr; }
100  bool IsOverlapAllowedAttr() const { return m_bOverlapAllowedAttr; }
101  bool IsPriorityAttr() const { return m_bPriorityAttr; }
102  void SetPriorityAttr( bool bFlag ) { m_bPriorityAttr = bFlag; }
103  bool IsDontExpandStartAttr() const { return m_bDontExpandStart; }
104  bool IsNesting() const { return m_bNesting; }
105  bool HasDummyChar() const { return m_bHasDummyChar; }
106  bool IsFormatIgnoreStart() const { return m_bFormatIgnoreStart; }
107  bool IsFormatIgnoreEnd () const { return m_bFormatIgnoreEnd ; }
108  void SetFormatIgnoreStart(bool bFlag) { m_bFormatIgnoreStart = bFlag; }
109  void SetFormatIgnoreEnd (bool bFlag) { m_bFormatIgnoreEnd = bFlag; }
110  bool HasContent() const { return m_bHasContent; }
111 
112  inline const SfxPoolItem& GetAttr() const;
113  inline SfxPoolItem& GetAttr();
114  sal_uInt16 Which() const { return GetAttr().Which(); }
115 
116  bool operator==( const SwTextAttr& ) const;
117 
118  inline const SwFormatCharFormat &GetCharFormat() const;
119  inline const SwFormatAutoFormat &GetAutoFormat() const;
120  inline const SwFormatField &GetFormatField() const;
121  inline const SwFormatFootnote &GetFootnote() const;
122  inline const SwFormatFlyCnt &GetFlyCnt() const;
123  inline const SwTOXMark &GetTOXMark() const;
124  inline const SwFormatRefMark &GetRefMark() const;
125  inline const SwFormatINetFormat &GetINetFormat() const;
126  inline const SwFormatRuby &GetRuby() const;
127 
128  virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
129 };
130 
131 class SAL_DLLPUBLIC_RTTI SwTextAttrEnd : public virtual SwTextAttr
132 {
133 protected:
134  sal_Int32 m_nEnd;
135 
136 public:
137  SwTextAttrEnd( SfxPoolItem& rAttr, sal_Int32 nStart, sal_Int32 nEnd );
138 
139  virtual const sal_Int32* GetEnd() const override;
140  virtual void SetEnd(sal_Int32) override;
141 };
142 
143 // attribute that must not overlap others
144 class SAL_DLLPUBLIC_RTTI SwTextAttrNesting : public SwTextAttrEnd
145 {
146 protected:
147  SwTextAttrNesting( SfxPoolItem & i_rAttr,
148  const sal_Int32 i_nStart, const sal_Int32 i_nEnd );
149  virtual ~SwTextAttrNesting() override;
150 };
151 
152 inline const sal_Int32* SwTextAttr::End() const
153 {
154  return GetEnd();
155 }
156 
157 inline sal_Int32 SwTextAttr::GetAnyEnd() const
158 {
159  const sal_Int32* pEnd = End();
160  return pEnd ? *pEnd : m_nStart;
161 }
162 
163 inline const SfxPoolItem& SwTextAttr::GetAttr() const
164 {
165  assert( m_pAttr );
166  return *m_pAttr;
167 }
168 
170 {
171  return const_cast<SfxPoolItem&>(
172  const_cast<const SwTextAttr*>(this)->GetAttr());
173 }
174 
175 inline void SwTextAttr::SetDontExpand( bool bDontExpand )
176 {
177  if ( !m_bLockExpandFlag )
178  {
179  m_bDontExpand = bDontExpand;
180  }
181 }
182 
184 {
186  return static_cast<const SwFormatCharFormat&>(*m_pAttr);
187 }
188 
190 {
192  return static_cast<const SwFormatAutoFormat&>(*m_pAttr);
193 }
194 
196 {
197  assert( m_pAttr
198  && ( m_pAttr->Which() == RES_TXTATR_FIELD
200  || m_pAttr->Which() == RES_TXTATR_INPUTFIELD ));
201  return static_cast<const SwFormatField&>(*m_pAttr);
202 }
203 
205 {
207  return static_cast<const SwFormatFootnote&>(*m_pAttr);
208 }
209 
211 {
213  return static_cast<const SwFormatFlyCnt&>(*m_pAttr);
214 }
215 
216 inline const SwTOXMark& SwTextAttr::GetTOXMark() const
217 {
219  return static_cast<const SwTOXMark&>(*m_pAttr);
220 }
221 
223 {
225  return static_cast<const SwFormatRefMark&>(*m_pAttr);
226 }
227 
229 {
231  return static_cast<const SwFormatINetFormat&>(*m_pAttr);
232 }
233 
234 inline const SwFormatRuby& SwTextAttr::GetRuby() const
235 {
237  return static_cast<const SwFormatRuby&>(*m_pAttr);
238 }
239 
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)
242 {
243  return dynamic_cast<T>(s);
244 }
245 template<typename T, typename S> inline T static_txtattr_cast(S & s)
246 {
247  return dynamic_cast<T>(s);
248 }
249 
250 #endif
251 
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 m_nEnd
Definition: txatbase.hxx:134
bool IsFormatIgnoreEnd() const
Definition: txatbase.hxx:107
void SetDontExpand(bool bDontExpand)
Definition: txatbase.hxx:175
bool IsPriorityAttr() const
Definition: txatbase.hxx:101
bool IsNesting() const
Definition: txatbase.hxx:104
void SetHasDummyChar(const bool bFlag)
Definition: txatbase.hxx:76
void SetPriorityAttr(bool bFlag)
Definition: txatbase.hxx:102
virtual const sal_Int32 * GetEnd() const
end position
Definition: txatbase.cxx:48
void SetStart(sal_Int32 n)
start position
Definition: txatbase.hxx:85
void SetFormatIgnoreStart(bool bFlag)
Definition: txatbase.hxx:108
constexpr TypedWhichId< SwFormatFlyCnt > RES_TXTATR_FLYCNT(57)
bool HasDummyChar() const
Definition: txatbase.hxx:105
bool m_bDontExpand
Definition: txatbase.hxx:47
SfxPoolItem *const m_pAttr
Definition: txatbase.hxx:45
void SetFormatIgnoreEnd(bool bFlag)
Definition: txatbase.hxx:109
sal_uInt16 Which() const
Definition: txatbase.hxx:114
sal_Int32 GetAnyEnd() const
end (if available), else start
Definition: txatbase.hxx:157
constexpr TypedWhichId< SwFormatField > RES_TXTATR_ANNOTATION(59)
const SwFormatRefMark & GetRefMark() const
Definition: txatbase.hxx:222
sal_Int32 m_nStart
Definition: txatbase.hxx:46
void SetNesting(const bool bFlag)
Definition: txatbase.hxx:75
const SwTOXMark & GetTOXMark() const
Definition: txatbase.hxx:216
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
A wrapper around SfxPoolItem to store the start position of (usually) a text portion, with an optional end.
Definition: txatbase.hxx:41
sal_Int32 GetStart() const
Definition: txatbase.hxx:86
bool IsOverlapAllowedAttr() const
Definition: txatbase.hxx:100
constexpr TypedWhichId< SwFormatRuby > RES_TXTATR_CJK_RUBY(53)
constexpr TypedWhichId< SwFormatCharFormat > RES_TXTATR_CHARFMT(52)
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:195
bool IsDontExpandStartAttr() const
Definition: txatbase.hxx:103
constexpr TypedWhichId< SwFormatAutoFormat > RES_TXTATR_AUTOFMT(50)
void SetOverlapAllowedAttr(bool bFlag)
Definition: txatbase.hxx:73
constexpr TypedWhichId< SwFormatFootnote > RES_TXTATR_FTN(58)
constexpr TypedWhichId< SwFormatINetFormat > RES_TXTATR_INETFMT(51)
void SetDontMoveAttr(bool bFlag)
Definition: txatbase.hxx:71
struct _xmlTextWriter * xmlTextWriterPtr
constexpr TypedWhichId< SwFormatField > RES_TXTATR_FIELD(RES_TXTATR_NOEND_BEGIN)
bool IsCharFormatAttr() const
Definition: txatbase.hxx:99
bool HasContent() const
Definition: txatbase.hxx:110
void SetCharFormatAttr(bool bFlag)
Definition: txatbase.hxx:72
T static_txtattr_cast(S *s)
Definition: txatbase.hxx:241
void StartPosChanged() const
Definition: ndhints.hxx:212
const SwFormatFootnote & GetFootnote() const
Definition: txatbase.hxx:204
void SetHasContent(const bool bFlag)
Definition: txatbase.hxx:77
void SetDontExpandStartAttr(bool bFlag)
Definition: txatbase.hxx:74
virtual void SetEnd(sal_Int32)
Definition: txatbase.cxx:53
bool IsLockExpandFlag() const
Definition: txatbase.hxx:97
An SwTextAttr container, stores all directly formatted text portions for a text node.
Definition: ndhints.hxx:67
bool IsDontMoveAttr() const
Definition: txatbase.hxx:98
bool m_bLockExpandFlag
Definition: txatbase.hxx:48
const sal_Int32 * End() const
Definition: txatbase.hxx:152
constexpr TypedWhichId< SwTOXMark > RES_TXTATR_TOXMARK(47)
constexpr TypedWhichId< SwFormatField > RES_TXTATR_INPUTFIELD(55)
Format of a fly content.
Definition: fmtflcnt.hxx:32
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:163
bool DontExpand() const
Definition: txatbase.hxx:96
const SwFormatAutoFormat & GetAutoFormat() const
Definition: txatbase.hxx:189
constexpr TypedWhichId< SwFormatRefMark > RES_TXTATR_REFMARK(RES_TXTATR_WITHEND_BEGIN)
const SwFormatCharFormat & GetCharFormat() const
Definition: txatbase.hxx:183
bool operator==(const ScCsvLayoutData &rData1, const ScCsvLayoutData &rData2)
bool IsFormatIgnoreStart() const
Definition: txatbase.hxx:106
sal_uInt16 Which() const
const SwFormatRuby & GetRuby() const
Definition: txatbase.hxx:234
const SwFormatINetFormat & GetINetFormat() const
Definition: txatbase.hxx:228
const SwFormatFlyCnt & GetFlyCnt() const
Definition: txatbase.hxx:210