LibreOffice Module sw (master)  1
fltshell.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_SOURCE_FILTER_INC_FLTSHELL_HXX
20 #define INCLUDED_SW_SOURCE_FILTER_INC_FLTSHELL_HXX
21 
22 #include <hintids.hxx>
23 #include <svl/listener.hxx>
24 #include <svx/ctredlin.hxx>
25 #include <tools/datetime.hxx>
26 #include <mdiexp.hxx>
27 #include <ndindex.hxx>
28 #include <pam.hxx>
29 #include <strings.hrc>
30 
31 #include <cstddef>
32 #include <memory>
33 
34 class SwTOXBase;
35 class SwField;
36 class SwFieldType;
37 class Graphic;
38 class SwTableBox;
39 class SwDoc;
40 class SwPaM;
41 
42 inline bool SwFltGetFlag(sal_uLong nFieldFlags, int no)
43  { return (nFieldFlags & (sal_uLong(1) << no)) != 0; }
44 
45 //Subvert the Node/Content system to get positions which don't update as
46 //content is appended to them
48 {
49 public:
51  sal_Int32 m_nContent;
52 public:
53  bool operator==(const SwFltPosition &rOther) const
54  {
55  return (m_nContent == rOther.m_nContent &&
56  m_nNode == rOther.m_nNode);
57  }
58  void SetPos(SwNodeIndex const &rNode, sal_uInt16 nIdx)
59  {
60  m_nNode = rNode;
61  m_nContent = nIdx;
62  }
63 
64  //operators with SwPosition, where the node is hacked to the previous one,
65  //and the offset to content is de-dynamic-ified
67  : m_nNode(rPos.nNode, -1)
68  , m_nContent(rPos.nContent.GetIndex())
69  {
70  }
71 
72  void FromSwPosition(const SwPosition &rPos)
73  {
74  m_nNode = rPos.nNode.GetIndex()-1;
75  m_nContent = rPos.nContent.GetIndex();
76  }
77 };
78 
79 // Stack entry for the attributes. It is always pointers to new attributes that are passed.
81 {
82 private:
83  SwFltStackEntry(SwFltStackEntry const&) = delete;
84  SwFltStackEntry& operator=(SwFltStackEntry const&) = delete;
85 
86 public:
89 
90  std::unique_ptr<SfxPoolItem> m_pAttr;// Format Attribute
91 
92  bool m_bOld; // to mark Attributes *before* skipping field results
93  bool m_bOpen; //Entry open, awaiting being closed
96 
97  SW_DLLPUBLIC SwFltStackEntry(const SwPosition & rStartPos, std::unique_ptr<SfxPoolItem> pHt );
99 
100  enum class RegionMode { NoCheck = 0, CheckNodes = 1<<0, CheckFieldmark = 1<<1 };
101  SW_DLLPUBLIC void SetEndPos( const SwPosition & rEndPos);
102  SW_DLLPUBLIC bool MakeRegion(SwDoc& rDoc, SwPaM& rRegion, RegionMode eCheck) const;
103  SW_DLLPUBLIC static bool MakeRegion(SwDoc& rDoc, SwPaM& rRegion,
104  RegionMode eCheck, const SwFltPosition &rMkPos, const SwFltPosition &rPtPos,
105  sal_uInt16 nWhich=0);
106 };
107 
108 template<> struct o3tl::typed_flags<SwFltStackEntry::RegionMode>: o3tl::is_typed_flags<SwFltStackEntry::RegionMode, 0x03> {};
109 
111 {
112 private:
113  SwFltControlStack(SwFltControlStack const&) = delete;
114  SwFltControlStack& operator=(SwFltControlStack const&) = delete;
115 
116  typedef std::vector<std::unique_ptr<SwFltStackEntry>> Entries;
117  Entries m_Entries;
118 
120 
121 protected:
124 
125  virtual void SetAttrInDoc(const SwPosition& rTmpPos, SwFltStackEntry& rEntry);
126 
127 public:
128  enum class MoveAttrsMode { DEFAULT, POSTIT_INSERTED };
129  void MoveAttrs(const SwPosition& rPos, MoveAttrsMode = MoveAttrsMode::DEFAULT);
130  enum Flags
131  {
138  ALLOW_FLD_CR
139  };
140 
141  SwFltControlStack(SwDoc& rDo, sal_uLong nFieldFl);
142  virtual ~SwFltControlStack();
143 
144  bool IsFlagSet(Flags no) const { return ::SwFltGetFlag(m_nFieldFlags, no);}
145 
146  void NewAttr(const SwPosition& rPos, const SfxPoolItem & rAttr );
147 
148  virtual SwFltStackEntry* SetAttr(const SwPosition& rPos, sal_uInt16 nAttrId, bool bTstEnd=true, tools::Long nHand = LONG_MAX, bool consumedByField=false);
149 
150  void StealAttr(const SwNodeIndex& rNode);
151  void MarkAllAttrsOld();
152  void KillUnlockedAttrs(const SwPosition& pPos);
153  SfxPoolItem* GetFormatStackAttr(sal_uInt16 nWhich, sal_uInt16 * pPos);
154  const SfxPoolItem* GetOpenStackAttr(const SwPosition& rPos, sal_uInt16 nWhich);
155  void Delete(const SwPaM &rPam);
156 
157  bool empty() const { return m_Entries.empty(); }
158  Entries::size_type size() const { return m_Entries.size(); }
159  SwFltStackEntry& operator[](Entries::size_type nIndex)
160  { return *m_Entries[nIndex]; }
161  void DeleteAndDestroy(Entries::size_type nCnt);
162 };
163 
164 class SwFltAnchorListener;
165 
167 {
169  std::unique_ptr<SwFltAnchorListener> m_pListener;
170 
171 public:
172  SwFltAnchor(SwFrameFormat* pFlyFormat);
173  SwFltAnchor(const SwFltAnchor&);
174  virtual ~SwFltAnchor() override;
175 
176  // "purely virtual methods" of SfxPoolItem
177  virtual bool operator==(const SfxPoolItem&) const override;
178  virtual SwFltAnchor* Clone(SfxItemPool* = nullptr) const override;
179  void SetFrameFormat(SwFrameFormat* _pFrameFormat);
180  const SwFrameFormat* GetFrameFormat() const { return m_pFrameFormat; }
181  SwFrameFormat* GetFrameFormat() { return m_pFrameFormat; }
182 };
183 
184 class SwFltAnchorListener final : public SvtListener
185 {
187  public:
188  SwFltAnchorListener(SwFltAnchor* pFltAnchor);
189  virtual void Notify(const SfxHint&) override;
190 };
191 
193 {
194 public:
197  std::size_t m_nAutorNo;
198 
200  std::size_t nAutorNo_,
201  const DateTime& rStamp_)
202  : SfxPoolItem(RES_FLTR_REDLINE), m_aStamp(rStamp_),
203  m_eType(eType_),
204  m_nAutorNo(nAutorNo_)
205  {
206  }
207 
208  // "purely virtual methods" of SfxPoolItem
209  virtual bool operator==(const SfxPoolItem& rItem) const override;
210  virtual SwFltRedline* Clone(SfxItemPool* = nullptr) const override;
211 };
212 
214 {
215 private:
216 
218  OUString maName;
219  OUString maVal;
221 
222 public:
223  SwFltBookmark( const OUString& rNa,
224  const OUString& rVa,
225  tools::Long nHand,
226  const bool bIsTOCBookmark = false );
227 
228  // "purely virtual methods" of SfxPoolItem
229  virtual bool operator==(const SfxPoolItem&) const override;
230  virtual SwFltBookmark* Clone(SfxItemPool* = nullptr) const override;
231 
232  tools::Long GetHandle() const { return mnHandle; }
233  const OUString& GetName() const { return maName; }
234  const OUString& GetValSys() const { return maVal; }
235  bool IsTOCBookmark() const
236  {
237  return mbIsTOCBookmark;
238  }
239 };
240 
243 {
245  std::vector< std::pair<OUString, OUString> > m_aAttributes;
246 
247 public:
248  SwFltRDFMark();
249 
250  virtual bool operator==(const SfxPoolItem&) const override;
251  virtual SwFltRDFMark* Clone(SfxItemPool* = nullptr) const override;
252 
253  void SetHandle(tools::Long nHandle);
254  tools::Long GetHandle() const;
255  void SetAttributes(const std::vector< std::pair<OUString, OUString> >& rAttributes);
256  const std::vector< std::pair<OUString, OUString> >& GetAttributes() const;
257 };
258 
259 class SW_DLLPUBLIC SwFltTOX final : public SfxPoolItem
260 {
261  std::shared_ptr<SwTOXBase> m_xTOXBase;
262  bool m_bHadBreakItem; // there was a break item BEFORE insertion of the TOX
264 public:
265  SwFltTOX(std::shared_ptr<SwTOXBase> xBase);
266  // "purely virtual methods" of SfxPoolItem
267  virtual bool operator==(const SfxPoolItem&) const override;
268  virtual SwFltTOX* Clone(SfxItemPool* = nullptr) const override;
269  const SwTOXBase& GetBase() const { return *m_xTOXBase; }
270  void SetHadBreakItem( bool bVal ) { m_bHadBreakItem = bVal; }
271  void SetHadPageDescItem( bool bVal ) { m_bHadPageDescItem = bVal; }
272  bool HadBreakItem() const { return m_bHadBreakItem; }
273  bool HadPageDescItem() const { return m_bHadPageDescItem; }
274 };
275 
276 // The WWEndStack behaves like the WWControlStack, except that the attributes
277 // on it are hoarded to the end of the document if they need to be accessed
278 // (e.g., book/RefMarks, index, etc.).
280 {
281 public:
282  SwFltEndStack(SwDoc& rDo, sal_uLong nFieldFl)
283  :SwFltControlStack(rDo, nFieldFl)
284  {
285  m_bIsEndStack = true;
286  }
287 };
288 
289 SW_DLLPUBLIC void UpdatePageDescs(SwDoc &rDoc, size_t nInPageDescOffset);
290 
292 {
293 private:
295 public:
296  ImportProgress(SwDocShell *pDocShell, tools::Long nStartVal, tools::Long nEndVal)
297  : m_pDocShell(pDocShell)
298  {
299  ::StartProgress(STR_STATSTR_W4WREAD, nStartVal, nEndVal, m_pDocShell);
300  }
301 
302  void Update(sal_uInt16 nProgress)
303  {
304  ::SetProgressState(nProgress, m_pDocShell); // Update
305  }
306 
308  {
309  ::EndProgress(m_pDocShell);
310  }
311 };
312 
313 // detect if the SwFrameFormat it is watching was deleted
315 {
317 public:
319 
320  virtual void Notify(const SfxHint& rHint) override;
321 
323  {
324  return m_pFormat;
325  }
326 
327  bool WasDeleted() const
328  {
329  return !m_pFormat;
330  }
331 
332  virtual ~FrameDeleteWatch() override;
333 };
334 
335 #endif
336 
337 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< std::pair< OUString, OUString > > m_aAttributes
Definition: fltshell.hxx:245
tools::Long mnHandle
Definition: fltshell.hxx:217
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:240
SwFrameFormat * m_pFormat
Definition: fltshell.hxx:316
Marks a position in the document model.
Definition: pam.hxx:35
const SwTOXBase & GetBase() const
Definition: fltshell.hxx:269
bool IsTOCBookmark() const
Definition: fltshell.hxx:235
SW_DLLPUBLIC bool MakeRegion(SwDoc &rDoc, SwPaM &rRegion, RegionMode eCheck) const
Definition: fltshell.cxx:162
virtual bool operator==(const SfxPoolItem &) const =0
SwNodeIndex m_nNode
Definition: fltshell.hxx:50
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const =0
SwNodeIndex nNode
Definition: pam.hxx:37
std::shared_ptr< SwTOXBase > m_xTOXBase
Definition: fltshell.hxx:261
DateTime m_aStamp
Definition: fltshell.hxx:195
sal_uIntPtr sal_uLong
long Long
std::size_t m_nAutorNo
Definition: fltshell.hxx:197
Base class of all fields.
Definition: fldbas.hxx:289
Definition: doc.hxx:188
SwFrameFormat * GetFrameFormat()
Definition: fltshell.hxx:181
void EndProgress(SwDocShell const *pDocShell)
Definition: mainwn.cxx:92
void Update(sal_uInt16 nProgress)
Definition: fltshell.hxx:302
bool WasDeleted() const
Definition: fltshell.hxx:327
OUString maName
Definition: fltshell.hxx:218
tools::Long m_nHandle
Definition: fltshell.hxx:244
SwFltAnchor * m_pFltAnchor
Definition: fltshell.hxx:186
Stores RDF statements on a paragraph (key-value pairs where the subject is the paragraph).
Definition: fltshell.hxx:242
void StartProgress(const char *pMessResId, tools::Long nStartValue, tools::Long nEndValue, SwDocShell *pDocShell)
Definition: mainwn.cxx:52
SW_DLLPUBLIC ~SwFltStackEntry()
Definition: fltshell.cxx:89
SwFrameFormat * GetFormat()
Definition: fltshell.hxx:322
sal_uLong m_nFieldFlags
Definition: fltshell.hxx:119
SwIndex nContent
Definition: pam.hxx:38
sal_uLong GetIndex() const
Definition: ndindex.hxx:152
SwFltAnchorListener(SwFltAnchor *pFltAnchor)
Definition: fltshell.cxx:887
bool operator==(const SwFltPosition &rOther) const
Definition: fltshell.hxx:53
void SetHadPageDescItem(bool bVal)
Definition: fltshell.hxx:271
RedlineType m_eType
Definition: fltshell.hxx:196
void SetHadBreakItem(bool bVal)
Definition: fltshell.hxx:270
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
SW_DLLPUBLIC void SetEndPos(const SwPosition &rEndPos)
Definition: fltshell.cxx:94
const SwFrameFormat * GetFrameFormat() const
Definition: fltshell.hxx:180
ImportProgress(SwDocShell *pDocShell, tools::Long nStartVal, tools::Long nEndVal)
Definition: fltshell.hxx:296
virtual void Notify(const SfxHint &) override
Definition: fltshell.cxx:891
bool empty() const
Definition: fltshell.hxx:157
Style of a layout element.
Definition: frmfmt.hxx:58
tools::Long GetHandle() const
Definition: fltshell.hxx:232
SwFrameFormat * m_pFrameFormat
Definition: fltshell.hxx:168
RegionMode
Definition: swcont.hxx:53
void FromSwPosition(const SwPosition &rPos)
Definition: fltshell.hxx:72
SwFltStackEntry & operator=(SwFltStackEntry const &)=delete
bool SwFltGetFlag(sal_uLong nFieldFlags, int no)
Definition: fltshell.hxx:42
SwDocShell * m_pDocShell
Definition: fltshell.hxx:294
SwFltStackEntry(SwFltStackEntry const &)=delete
Marks a node in the document model.
Definition: ndindex.hxx:31
SwFltPosition(const SwPosition &rPos)
Definition: fltshell.hxx:66
sal_Int32 m_nContent
Definition: fltshell.hxx:51
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
std::vector< std::unique_ptr< SwFltStackEntry > > Entries
Definition: fltshell.hxx:116
bool IsFlagSet(Flags no) const
Definition: fltshell.hxx:144
std::unique_ptr< SfxPoolItem > m_pAttr
Definition: fltshell.hxx:90
SwFltPosition m_aMkPos
Definition: fltshell.hxx:87
SwFltPosition m_aPtPos
Definition: fltshell.hxx:88
std::unique_ptr< SwFltAnchorListener > m_pListener
Definition: fltshell.hxx:169
bool m_bHadPageDescItem
Definition: fltshell.hxx:263
SwFltEndStack(SwDoc &rDo, sal_uLong nFieldFl)
Definition: fltshell.hxx:282
bool m_bConsumedByField
Definition: fltshell.hxx:94
virtual void Notify(const SfxHint &rHint)
bool m_isAnnotationOnEnd
annotation already moved onto its end pos.
Definition: fltshell.hxx:95
OUString maVal
Definition: fltshell.hxx:219
sal_Int32 GetIndex() const
Definition: index.hxx:91
void SetProgressState(tools::Long nPosition, SwDocShell const *pDocShell)
Definition: mainwn.cxx:82
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:395
bool m_bHadBreakItem
Definition: fltshell.hxx:262
bool HadPageDescItem() const
Definition: fltshell.hxx:273
constexpr TypedWhichId< SwFltRedline > RES_FLTR_REDLINE(194)
bool mbIsTOCBookmark
Definition: fltshell.hxx:220
bool HadBreakItem() const
Definition: fltshell.hxx:272
const OUString & GetName() const
Definition: fltshell.hxx:233
const OUString & GetValSys() const
Definition: fltshell.hxx:234
RedlineType
SwFltRedline(RedlineType eType_, std::size_t nAutorNo_, const DateTime &rStamp_)
Definition: fltshell.hxx:199
SwFltStackEntry & operator[](Entries::size_type nIndex)
Definition: fltshell.hxx:159
void SetPos(SwNodeIndex const &rNode, sal_uInt16 nIdx)
Definition: fltshell.hxx:58
Entries::size_type size() const
Definition: fltshell.hxx:158
SW_DLLPUBLIC void UpdatePageDescs(SwDoc &rDoc, size_t nInPageDescOffset)
Definition: fltshell.cxx:1020