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