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