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