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> pAttr;// Format Attribute
91 
92  bool bOld; // to mark Attributes *before* skipping field results
93  bool bOpen; //Entry open, awaiting being closed
96 
97  sal_Int32 mnStartCP;
98  sal_Int32 mnEndCP;
99  bool bIsParaEnd;
100 
101  SW_DLLPUBLIC SwFltStackEntry(const SwPosition & rStartPos, std::unique_ptr<SfxPoolItem> pHt );
103 
104  enum class RegionMode { NoCheck = 0, CheckNodes = 1<<0, CheckFieldmark = 1<<1 };
105  SW_DLLPUBLIC void SetEndPos( const SwPosition & rEndPos);
106  SW_DLLPUBLIC bool MakeRegion(SwDoc& rDoc, SwPaM& rRegion, RegionMode eCheck) const;
107  SW_DLLPUBLIC static bool MakeRegion(SwDoc& rDoc, SwPaM& rRegion,
108  RegionMode eCheck, const SwFltPosition &rMkPos, const SwFltPosition &rPtPos, bool bIsParaEnd=false,
109  sal_uInt16 nWhich=0);
110 
111  void SetStartCP(sal_Int32 nCP) {mnStartCP = nCP;}
112  void SetEndCP(sal_Int32 nCP) {mnEndCP = nCP;}
113  sal_Int32 GetStartCP() const {return mnStartCP;}
114  sal_Int32 GetEndCP() const {return mnEndCP;}
115  bool IsParaEnd() const { return bIsParaEnd;}
116  void SetIsParaEnd(bool bArg){ bIsParaEnd = bArg;}
117 };
118 
119 template<> struct o3tl::typed_flags<SwFltStackEntry::RegionMode>: o3tl::is_typed_flags<SwFltStackEntry::RegionMode, 0x03> {};
120 
122 {
123 private:
124  SwFltControlStack(SwFltControlStack const&) = delete;
125  SwFltControlStack& operator=(SwFltControlStack const&) = delete;
126 
127  typedef std::vector<std::unique_ptr<SwFltStackEntry>> Entries;
128  Entries m_Entries;
129 
131 
132  bool bHasSdOD;
134 
135 protected:
138 
139  virtual void SetAttrInDoc(const SwPosition& rTmpPos, SwFltStackEntry& rEntry);
140  virtual sal_Int32 GetCurrAttrCP() const {return -1;}
141  virtual bool IsParaEndInCPs(sal_Int32 nStart,sal_Int32 nEnd,bool bSdOD) const;
142 
143  //Clear the para end position recorded in reader intermittently for the least impact on loading performance
144  virtual void ClearParaEndPosition(){};
145  virtual bool CheckSdOD(sal_Int32 nStart,sal_Int32 nEnd);
146  bool HasSdOD();
147 
148 public:
149  enum class MoveAttrsMode { DEFAULT, POSTIT_INSERTED };
150  void MoveAttrs(const SwPosition& rPos, MoveAttrsMode = MoveAttrsMode::DEFAULT);
151  enum Flags
152  {
159  ALLOW_FLD_CR
160  };
161 
162  SwFltControlStack(SwDoc& rDo, sal_uLong nFieldFl);
163  virtual ~SwFltControlStack();
164 
165  bool IsFlagSet(Flags no) const { return ::SwFltGetFlag(nFieldFlags, no);}
166 
167  void NewAttr(const SwPosition& rPos, const SfxPoolItem & rAttr );
168 
169  virtual SwFltStackEntry* SetAttr(const SwPosition& rPos, sal_uInt16 nAttrId, bool bTstEnd=true, tools::Long nHand = LONG_MAX, bool consumedByField=false);
170 
171  void StealAttr(const SwNodeIndex& rNode);
172  void MarkAllAttrsOld();
173  void KillUnlockedAttrs(const SwPosition& pPos);
174  SfxPoolItem* GetFormatStackAttr(sal_uInt16 nWhich, sal_uInt16 * pPos);
175  const SfxPoolItem* GetOpenStackAttr(const SwPosition& rPos, sal_uInt16 nWhich);
176  void Delete(const SwPaM &rPam);
177 
178  bool empty() const { return m_Entries.empty(); }
179  Entries::size_type size() const { return m_Entries.size(); }
180  SwFltStackEntry& operator[](Entries::size_type nIndex)
181  { return *m_Entries[nIndex]; }
182  void DeleteAndDestroy(Entries::size_type nCnt);
183 };
184 
185 class SwFltAnchorListener;
186 
188 {
190  std::unique_ptr<SwFltAnchorListener> pListener;
191 
192 public:
193  SwFltAnchor(SwFrameFormat* pFlyFormat);
194  SwFltAnchor(const SwFltAnchor&);
195  virtual ~SwFltAnchor() override;
196 
197  // "purely virtual methods" of SfxPoolItem
198  virtual bool operator==(const SfxPoolItem&) const override;
199  virtual SwFltAnchor* Clone(SfxItemPool* = nullptr) const override;
200  void SetFrameFormat(SwFrameFormat* _pFrameFormat);
201  const SwFrameFormat* GetFrameFormat() const { return pFrameFormat; }
202  SwFrameFormat* GetFrameFormat() { return pFrameFormat; }
203 };
204 
206 {
208  public:
209  SwFltAnchorListener(SwFltAnchor* pFltAnchor);
210  virtual void Notify(const SfxHint&) override;
211 };
212 
214 {
215 public:
218  std::size_t nAutorNo;
219 
221  std::size_t nAutorNo_,
222  const DateTime& rStamp_)
223  : SfxPoolItem(RES_FLTR_REDLINE), aStamp(rStamp_),
224  eType(eType_),
225  nAutorNo(nAutorNo_)
226  {
227  }
228 
229  // "purely virtual methods" of SfxPoolItem
230  virtual bool operator==(const SfxPoolItem& rItem) const override;
231  virtual SwFltRedline* Clone(SfxItemPool* = nullptr) const override;
232 };
233 
235 {
236 private:
237 
239  OUString maName;
240  OUString maVal;
242 
243 public:
244  SwFltBookmark( const OUString& rNa,
245  const OUString& rVa,
246  tools::Long nHand,
247  const bool bIsTOCBookmark = false );
248 
249  // "purely virtual methods" of SfxPoolItem
250  virtual bool operator==(const SfxPoolItem&) const override;
251  virtual SwFltBookmark* Clone(SfxItemPool* = nullptr) const override;
252 
253  tools::Long GetHandle() const { return mnHandle; }
254  const OUString& GetName() const { return maName; }
255  const OUString& GetValSys() const { return maVal; }
256  bool IsTOCBookmark() const
257  {
258  return mbIsTOCBookmark;
259  }
260 };
261 
264 {
266  std::vector< std::pair<OUString, OUString> > m_aAttributes;
267 
268 public:
269  SwFltRDFMark();
270 
271  virtual bool operator==(const SfxPoolItem&) const override;
272  virtual SwFltRDFMark* Clone(SfxItemPool* = nullptr) const override;
273 
274  void SetHandle(tools::Long nHandle);
275  tools::Long GetHandle() const;
276  void SetAttributes(const std::vector< std::pair<OUString, OUString> >& rAttributes);
277  const std::vector< std::pair<OUString, OUString> >& GetAttributes() const;
278 };
279 
281 {
282  std::shared_ptr<SwTOXBase> m_xTOXBase;
283  bool bHadBreakItem; // there was a break item BEFORE insertion of the TOX
285 public:
286  SwFltTOX(std::shared_ptr<SwTOXBase> xBase);
287  // "purely virtual methods" of SfxPoolItem
288  virtual bool operator==(const SfxPoolItem&) const override;
289  virtual SwFltTOX* Clone(SfxItemPool* = nullptr) const override;
290  const SwTOXBase& GetBase() const { return *m_xTOXBase; }
291  void SetHadBreakItem( bool bVal ) { bHadBreakItem = bVal; }
292  void SetHadPageDescItem( bool bVal ) { bHadPageDescItem = bVal; }
293  bool HadBreakItem() const { return bHadBreakItem; }
294  bool HadPageDescItem() const { return bHadPageDescItem; }
295 };
296 
297 // The WWEndStack behaves like the WWControlStack, except that the attributes
298 // on it are hoarded to the end of the document if they need to be accessed
299 // (e.g., book/RefMarks, index, etc.).
301 {
302 public:
303  SwFltEndStack(SwDoc& rDo, sal_uLong nFieldFl)
304  :SwFltControlStack(rDo, nFieldFl)
305  {
306  bIsEndStack = true;
307  }
308 };
309 
310 SW_DLLPUBLIC void UpdatePageDescs(SwDoc &rDoc, size_t nInPageDescOffset);
311 
313 {
314 private:
316 public:
317  ImportProgress(SwDocShell *pDocShell, tools::Long nStartVal, tools::Long nEndVal)
318  : m_pDocShell(pDocShell)
319  {
320  ::StartProgress(STR_STATSTR_W4WREAD, nStartVal, nEndVal, m_pDocShell);
321  }
322 
323  void Update(sal_uInt16 nProgress)
324  {
325  ::SetProgressState(nProgress, m_pDocShell); // Update
326  }
327 
329  {
330  ::EndProgress(m_pDocShell);
331  }
332 };
333 
334 // detect if the SwFrameFormat it is watching was deleted
336 {
338 public:
340 
341  virtual void Notify(const SfxHint& rHint) override;
342 
344  {
345  return m_pFormat;
346  }
347 
348  bool WasDeleted() const
349  {
350  return !m_pFormat;
351  }
352 
353  virtual ~FrameDeleteWatch() override;
354 };
355 
356 #endif
357 
358 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< std::pair< OUString, OUString > > m_aAttributes
Definition: fltshell.hxx:266
tools::Long mnHandle
Definition: fltshell.hxx:238
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:240
SwFrameFormat * m_pFormat
Definition: fltshell.hxx:337
sal_Int32 mnStartCP
Definition: fltshell.hxx:97
bool bHadPageDescItem
Definition: fltshell.hxx:284
Marks a position in the document model.
Definition: pam.hxx:35
const SwTOXBase & GetBase() const
Definition: fltshell.hxx:290
bool IsTOCBookmark() const
Definition: fltshell.hxx:256
SW_DLLPUBLIC bool MakeRegion(SwDoc &rDoc, SwPaM &rRegion, RegionMode eCheck) const
Definition: fltshell.cxx:169
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:282
sal_uIntPtr sal_uLong
long Long
Base class of all fields.
Definition: fldbas.hxx:289
Definition: doc.hxx:187
SwFrameFormat * GetFrameFormat()
Definition: fltshell.hxx:202
void EndProgress(SwDocShell const *pDocShell)
Definition: mainwn.cxx:92
void Update(sal_uInt16 nProgress)
Definition: fltshell.hxx:323
bool bConsumedByField
Definition: fltshell.hxx:94
bool WasDeleted() const
Definition: fltshell.hxx:348
OUString maName
Definition: fltshell.hxx:239
tools::Long m_nHandle
Definition: fltshell.hxx:265
SwFltAnchor * m_pFltAnchor
Definition: fltshell.hxx:207
Stores RDF statements on a paragraph (key-value pairs where the subject is the paragraph).
Definition: fltshell.hxx:263
RedlineType eType
Definition: fltshell.hxx:217
void StartProgress(const char *pMessResId, tools::Long nStartValue, tools::Long nEndValue, SwDocShell *pDocShell)
Definition: mainwn.cxx:52
SW_DLLPUBLIC ~SwFltStackEntry()
Definition: fltshell.cxx:92
SwFrameFormat * GetFormat()
Definition: fltshell.hxx:343
SwIndex nContent
Definition: pam.hxx:38
sal_Int32 mnEndCP
Definition: fltshell.hxx:98
sal_uLong GetIndex() const
Definition: ndindex.hxx:152
bool bHadBreakItem
Definition: fltshell.hxx:283
void SetIsParaEnd(bool bArg)
Definition: fltshell.hxx:116
SwFltAnchorListener(SwFltAnchor *pFltAnchor)
Definition: fltshell.cxx:956
bool operator==(const SwFltPosition &rOther) const
Definition: fltshell.hxx:53
void SetHadPageDescItem(bool bVal)
Definition: fltshell.hxx:292
void SetHadBreakItem(bool bVal)
Definition: fltshell.hxx:291
std::unique_ptr< SwFltAnchorListener > pListener
Definition: fltshell.hxx:190
bool IsParaEnd() const
Definition: fltshell.hxx:115
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:97
const SwFrameFormat * GetFrameFormat() const
Definition: fltshell.hxx:201
ImportProgress(SwDocShell *pDocShell, tools::Long nStartVal, tools::Long nEndVal)
Definition: fltshell.hxx:317
virtual void Notify(const SfxHint &) override
Definition: fltshell.cxx:960
bool empty() const
Definition: fltshell.hxx:178
Style of a layout element.
Definition: frmfmt.hxx:58
virtual sal_Int32 GetCurrAttrCP() const
Definition: fltshell.hxx:140
tools::Long GetHandle() const
Definition: fltshell.hxx:253
RegionMode
Definition: swcont.hxx:52
void FromSwPosition(const SwPosition &rPos)
Definition: fltshell.hxx:72
SwFltStackEntry & operator=(SwFltStackEntry const &)=delete
sal_uLong nFieldFlags
Definition: fltshell.hxx:130
bool SwFltGetFlag(sal_uLong nFieldFlags, int no)
Definition: fltshell.hxx:42
SwDocShell * m_pDocShell
Definition: fltshell.hxx:315
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:127
std::size_t nAutorNo
Definition: fltshell.hxx:218
bool IsFlagSet(Flags no) const
Definition: fltshell.hxx:165
SwFltPosition m_aMkPos
Definition: fltshell.hxx:87
std::unique_ptr< SfxPoolItem > pAttr
Definition: fltshell.hxx:90
SwFltPosition m_aPtPos
Definition: fltshell.hxx:88
SwFltEndStack(SwDoc &rDo, sal_uLong nFieldFl)
Definition: fltshell.hxx:303
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:240
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:392
sal_Int32 GetStartCP() const
Definition: fltshell.hxx:113
bool HadPageDescItem() const
Definition: fltshell.hxx:294
constexpr TypedWhichId< SwFltRedline > RES_FLTR_REDLINE(194)
bool mbIsTOCBookmark
Definition: fltshell.hxx:241
bool HadBreakItem() const
Definition: fltshell.hxx:293
const OUString & GetName() const
Definition: fltshell.hxx:254
const OUString & GetValSys() const
Definition: fltshell.hxx:255
sal_Int32 GetEndCP() const
Definition: fltshell.hxx:114
void SetStartCP(sal_Int32 nCP)
Definition: fltshell.hxx:111
DateTime aStamp
Definition: fltshell.hxx:216
RedlineType
void SetEndCP(sal_Int32 nCP)
Definition: fltshell.hxx:112
SwFltRedline(RedlineType eType_, std::size_t nAutorNo_, const DateTime &rStamp_)
Definition: fltshell.hxx:220
SwFltStackEntry & operator[](Entries::size_type nIndex)
Definition: fltshell.hxx:180
virtual void ClearParaEndPosition()
Definition: fltshell.hxx:144
void SetPos(SwNodeIndex const &rNode, sal_uInt16 nIdx)
Definition: fltshell.hxx:58
Entries::size_type size() const
Definition: fltshell.hxx:179
SwFrameFormat * pFrameFormat
Definition: fltshell.hxx:189
SW_DLLPUBLIC void UpdatePageDescs(SwDoc &rDoc, size_t nInPageDescOffset)
Definition: fltshell.cxx:1088