1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SW_SOURCE_FILTER_INC_FLTSHELL_HXX
20 #define INCLUDED_SW_SOURCE_FILTER_INC_FLTSHELL_HXX
22 #include <hintids.hxx>
23 #include <svl/listener.hxx>
24 #include <svx/ctredlin.hxx>
25 #include <tools/datetime.hxx>
27 #include <ndindex.hxx>
29 #include <strings.hrc>
42 inline bool SwFltGetFlag(sal_uLong nFieldFlags
, int no
)
43 { return (nFieldFlags
& (sal_uLong(1) << no
)) != 0; }
45 //Subvert the Node/Content system to get positions which don't update as
46 //content is appended to them
47 struct SW_DLLPUBLIC SwFltPosition
53 bool operator==(const SwFltPosition
&rOther
) const
55 return (m_nContent
== rOther
.m_nContent
&&
56 m_nNode
== rOther
.m_nNode
);
58 void SetPos(SwNodeIndex
const &rNode
, sal_uInt16 nIdx
)
64 //operators with SwPosition, where the node is hacked to the previous one,
65 //and the offset to content is de-dynamic-ified
66 SwFltPosition(const SwPosition
&rPos
)
67 : m_nNode(rPos
.GetNode(), -1)
68 , m_nContent(rPos
.GetContentIndex())
72 void FromSwPosition(const SwPosition
&rPos
)
74 m_nNode
= rPos
.GetNodeIndex()-1;
75 m_nContent
= rPos
.GetContentIndex();
79 // Stack entry for the attributes. It is always pointers to new attributes that are passed.
83 SwFltStackEntry(SwFltStackEntry
const&) = delete;
84 SwFltStackEntry
& operator=(SwFltStackEntry
const&) = delete;
87 SwFltPosition m_aMkPos
;
88 SwFltPosition m_aPtPos
;
90 std::unique_ptr
<SfxPoolItem
> m_pAttr
;// Format Attribute
92 bool m_bOld
; // to mark Attributes *before* skipping field results
93 bool m_bOpen
; //Entry open, awaiting being closed
94 bool m_bConsumedByField
;
95 bool m_isAnnotationOnEnd
; ///< annotation already moved onto its end pos.
97 SW_DLLPUBLIC
SwFltStackEntry(const SwPosition
& rStartPos
, std::unique_ptr
<SfxPoolItem
> pHt
);
98 SW_DLLPUBLIC
~SwFltStackEntry();
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);
108 template<> struct o3tl::typed_flags
<SwFltStackEntry::RegionMode
>: o3tl::is_typed_flags
<SwFltStackEntry::RegionMode
, 0x03> {};
110 class SW_DLLPUBLIC SwFltControlStack
113 SwFltControlStack(SwFltControlStack
const&) = delete;
114 SwFltControlStack
& operator=(SwFltControlStack
const&) = delete;
116 typedef std::vector
<std::unique_ptr
<SwFltStackEntry
>> Entries
;
119 sal_uLong m_nFieldFlags
;
125 virtual void SetAttrInDoc(const SwPosition
& rTmpPos
, SwFltStackEntry
& rEntry
);
128 enum class MoveAttrsMode
{ DEFAULT
, POSTIT_INSERTED
};
129 void MoveAttrs(const SwPosition
& rPos
, MoveAttrsMode
= MoveAttrsMode::DEFAULT
);
141 SwFltControlStack(SwDoc
& rDo
, sal_uLong nFieldFl
);
142 virtual ~SwFltControlStack();
144 bool IsFlagSet(Flags no
) const { return ::SwFltGetFlag(m_nFieldFlags
, no
);}
146 void NewAttr(const SwPosition
& rPos
, const SfxPoolItem
& rAttr
);
148 virtual SwFltStackEntry
* SetAttr(const SwPosition
& rPos
, sal_uInt16 nAttrId
, bool bTstEnd
=true, tools::Long nHand
= LONG_MAX
, bool consumedByField
=false);
150 void StealAttr(const SwNode
& 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
);
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
);
164 class SwFltAnchorListener
;
166 class SW_DLLPUBLIC SwFltAnchor final
: public SfxPoolItem
168 SwFrameFormat
* m_pFrameFormat
;
169 std::unique_ptr
<SwFltAnchorListener
> m_pListener
;
172 SwFltAnchor(SwFrameFormat
* pFlyFormat
);
173 SwFltAnchor(const SwFltAnchor
&);
174 virtual ~SwFltAnchor() override
;
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
; }
184 /// Used by SwFltAnchor, to listen to an SwFrameFormat (to be aware when it is replaced or deleted).
185 class SwFltAnchorListener final
: public SvtListener
187 SwFltAnchor
* m_pFltAnchor
;
189 SwFltAnchorListener(SwFltAnchor
* pFltAnchor
);
190 virtual void Notify(const SfxHint
&) override
;
193 class SW_DLLPUBLIC SwFltRedline final
: public SfxPoolItem
198 std::size_t m_nAutorNo
;
200 SwFltRedline(RedlineType eType_
,
201 std::size_t nAutorNo_
,
202 const DateTime
& rStamp_
)
203 : SfxPoolItem(RES_FLTR_REDLINE
), m_aStamp(rStamp_
),
205 m_nAutorNo(nAutorNo_
)
209 // "purely virtual methods" of SfxPoolItem
210 virtual bool operator==(const SfxPoolItem
& rItem
) const override
;
211 virtual SwFltRedline
* Clone(SfxItemPool
* = nullptr) const override
;
214 class SW_DLLPUBLIC SwFltBookmark final
: public SfxPoolItem
218 tools::Long mnHandle
;
221 bool mbIsTOCBookmark
;
224 SwFltBookmark( const OUString
& rNa
,
227 const bool bIsTOCBookmark
= false );
229 // "purely virtual methods" of SfxPoolItem
230 virtual bool operator==(const SfxPoolItem
&) const override
;
231 virtual SwFltBookmark
* Clone(SfxItemPool
* = nullptr) const override
;
233 tools::Long
GetHandle() const { return mnHandle
; }
234 const OUString
& GetName() const { return maName
; }
235 const OUString
& GetValSys() const { return maVal
; }
236 bool IsTOCBookmark() const
238 return mbIsTOCBookmark
;
242 /// Stores RDF statements on a paragraph (key-value pairs where the subject is the paragraph).
243 class SW_DLLPUBLIC SwFltRDFMark final
: public SfxPoolItem
245 tools::Long m_nHandle
;
246 std::vector
< std::pair
<OUString
, OUString
> > m_aAttributes
;
251 virtual bool operator==(const SfxPoolItem
&) const override
;
252 virtual SwFltRDFMark
* Clone(SfxItemPool
* = nullptr) const override
;
254 void SetHandle(tools::Long nHandle
);
255 tools::Long
GetHandle() const;
256 void SetAttributes(std::vector
< std::pair
<OUString
, OUString
> >&& rAttributes
);
257 const std::vector
< std::pair
<OUString
, OUString
> >& GetAttributes() const;
260 class SW_DLLPUBLIC SwFltTOX final
: public SfxPoolItem
262 std::shared_ptr
<SwTOXBase
> m_xTOXBase
;
263 bool m_bHadBreakItem
; // there was a break item BEFORE insertion of the TOX
264 bool m_bHadPageDescItem
;
266 SwFltTOX(std::shared_ptr
<SwTOXBase
> xBase
);
267 // "purely virtual methods" of SfxPoolItem
268 virtual bool operator==(const SfxPoolItem
&) const override
;
269 virtual SwFltTOX
* Clone(SfxItemPool
* = nullptr) const override
;
270 const SwTOXBase
& GetBase() const { return *m_xTOXBase
; }
271 void SetHadBreakItem( bool bVal
) { m_bHadBreakItem
= bVal
; }
272 void SetHadPageDescItem( bool bVal
) { m_bHadPageDescItem
= bVal
; }
273 bool HadBreakItem() const { return m_bHadBreakItem
; }
274 bool HadPageDescItem() const { return m_bHadPageDescItem
; }
277 // The WWEndStack behaves like the WWControlStack, except that the attributes
278 // on it are hoarded to the end of the document if they need to be accessed
279 // (e.g., book/RefMarks, index, etc.).
280 class SwFltEndStack
: public SwFltControlStack
283 SwFltEndStack(SwDoc
& rDo
, sal_uLong nFieldFl
)
284 :SwFltControlStack(rDo
, nFieldFl
)
286 m_bIsEndStack
= true;
290 SW_DLLPUBLIC
void UpdatePageDescs(SwDoc
&rDoc
, size_t nInPageDescOffset
);
295 SwDocShell
*m_pDocShell
;
297 ImportProgress(SwDocShell
*pDocShell
, tools::Long nStartVal
, tools::Long nEndVal
)
298 : m_pDocShell(pDocShell
)
300 ::StartProgress(STR_STATSTR_W4WREAD
, nStartVal
, nEndVal
, m_pDocShell
);
303 void Update(sal_uInt16 nProgress
)
305 ::SetProgressState(nProgress
, m_pDocShell
); // Update
310 ::EndProgress(m_pDocShell
);
314 // detect if the SwFrameFormat it is watching was deleted
315 class SW_DLLPUBLIC FrameDeleteWatch final
: public SvtListener
317 SwFrameFormat
* m_pFormat
;
319 FrameDeleteWatch(SwFrameFormat
* pFormat
);
321 virtual void Notify(const SfxHint
& rHint
) override
;
323 SwFrameFormat
* GetFormat()
328 bool WasDeleted() const
333 virtual ~FrameDeleteWatch() override
;
338 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */