Replace workaround of resize to invalidate with an explicit SfxHint
[LibreOffice.git] / sw / inc / redline.hxx
blob20befbaa43d7cf9382e0e2fdc3d808fb4c1fff51
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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_INC_REDLINE_HXX
20 #define INCLUDED_SW_INC_REDLINE_HXX
22 #include <svx/ctredlin.hxx>
23 #include <tools/datetime.hxx>
24 #include <rtl/ustring.hxx>
26 #include "pam.hxx"
28 #include <cstddef>
29 #include <memory>
30 #include <vector>
31 #include <optional>
34 class SfxItemSet;
36 class SW_DLLPUBLIC SwRedlineExtraData
38 SwRedlineExtraData( const SwRedlineExtraData& ) = delete;
39 SwRedlineExtraData& operator=( const SwRedlineExtraData& ) = delete;
41 protected:
42 SwRedlineExtraData() {}
44 public:
45 virtual ~SwRedlineExtraData();
46 virtual SwRedlineExtraData* CreateNew() const = 0;
48 virtual void Reject( SwPaM& rPam ) const;
49 virtual bool operator == ( const SwRedlineExtraData& ) const;
52 class SW_DLLPUBLIC SwRedlineExtraData_FormatColl final : public SwRedlineExtraData
54 OUString m_sFormatNm;
55 std::unique_ptr<SfxItemSet> m_pSet;
56 sal_uInt16 m_nPoolId;
57 bool m_bFormatAll; // don't strip the last paragraph mark
58 public:
59 SwRedlineExtraData_FormatColl( OUString aColl, sal_uInt16 nPoolFormatId,
60 const SfxItemSet* pSet = nullptr, bool bFormatAll = true );
61 virtual ~SwRedlineExtraData_FormatColl() override;
62 virtual SwRedlineExtraData* CreateNew() const override;
63 virtual void Reject( SwPaM& rPam ) const override;
64 virtual bool operator == ( const SwRedlineExtraData& ) const override;
66 const OUString& GetFormatName() const { return m_sFormatNm; }
67 void SetItemSet( const SfxItemSet& rSet );
68 SfxItemSet* GetItemSet( ) const { return m_pSet.get(); }
69 void SetFormatAll( bool bAll ) { m_bFormatAll = bAll; }
72 class SwRedlineExtraData_Format final : public SwRedlineExtraData
74 std::vector<sal_uInt16> m_aWhichIds;
76 SwRedlineExtraData_Format( const SwRedlineExtraData_Format& rCpy );
78 public:
79 SwRedlineExtraData_Format( const SfxItemSet& rSet );
80 virtual ~SwRedlineExtraData_Format() override;
81 virtual SwRedlineExtraData* CreateNew() const override;
82 virtual void Reject( SwPaM& rPam ) const override;
83 virtual bool operator == ( const SwRedlineExtraData& ) const override;
86 class SW_DLLPUBLIC SwRedlineData
88 friend class SwRangeRedline;
89 SwRedlineData* m_pNext; // Points to other data.
90 SwRedlineExtraData* m_pExtraData;
92 OUString m_sComment;
93 DateTime m_aStamp;
94 std::size_t m_nAuthor;
95 RedlineType m_eType;
96 sal_uInt16 m_nSeqNo;
97 bool m_bAutoFormat;
98 sal_uInt32 m_nMovedID; // 0 == not moved, 1 == moved, but don't have its pair, 2+ == unique ID
100 public:
101 SwRedlineData( RedlineType eT, std::size_t nAut, sal_uInt32 nMoveID = 0 );
102 SwRedlineData( const SwRedlineData& rCpy, bool bCpyNext = true );
104 // For sw3io: pNext/pExtraData are taken over.
105 SwRedlineData( RedlineType eT, std::size_t nAut, const DateTime& rDT, sal_uInt32 nMovedID,
106 OUString aCmnt, SwRedlineData* pNxt );
108 ~SwRedlineData();
110 bool operator==( const SwRedlineData& rCmp ) const
112 return m_nAuthor == rCmp.m_nAuthor &&
113 m_eType == rCmp.m_eType &&
114 m_bAutoFormat == rCmp.m_bAutoFormat &&
115 m_nMovedID == rCmp.m_nMovedID &&
116 m_sComment == rCmp.m_sComment &&
117 (( !m_pNext && !rCmp.m_pNext ) ||
118 ( m_pNext && rCmp.m_pNext && *m_pNext == *rCmp.m_pNext )) &&
119 (( !m_pExtraData && !rCmp.m_pExtraData ) ||
120 ( m_pExtraData && rCmp.m_pExtraData &&
121 *m_pExtraData == *rCmp.m_pExtraData ));
124 RedlineType GetType() const { return m_eType; }
126 std::size_t GetAuthor() const { return m_nAuthor; }
127 const OUString& GetComment() const { return m_sComment; }
128 const DateTime& GetTimeStamp() const { return m_aStamp; }
129 bool IsAnonymized() const
131 return m_aStamp.GetYear() == 1970 &&
132 m_aStamp.GetMonth() == 1 && m_aStamp.GetDay() == 1;
135 const SwRedlineData* Next() const{ return m_pNext; }
137 void SetComment( const OUString& rS ) { m_sComment = rS; }
138 void SetTimeStamp( const DateTime& rDT ) { m_aStamp = rDT; }
140 void SetAutoFormat() { m_bAutoFormat = true; }
141 bool IsAutoFormat() const { return m_bAutoFormat; }
142 void SetMoved( sal_uInt32 nMoveID ) { m_nMovedID = nMoveID; }
143 sal_uInt32 GetMoved() const { return m_nMovedID; }
144 bool IsMoved() const { return m_nMovedID != 0; }
145 bool CanCombine( const SwRedlineData& rCmp ) const;
146 bool CanCombineForAcceptReject( const SwRedlineData& rCmp ) const;
148 // ExtraData gets copied, the pointer is therefore not taken over by
149 // the RedlineObject
150 void SetExtraData( const SwRedlineExtraData* pData );
151 const SwRedlineExtraData* GetExtraData() const { return m_pExtraData; }
153 // For UI-side pooling of Redline-actions.
154 // At the moment only used for Autoformat with Redline.
155 // Value != 0 means there can be others!
156 sal_uInt16 GetSeqNo() const { return m_nSeqNo; }
157 void SetSeqNo( sal_uInt16 nNo ) { m_nSeqNo = nNo; }
159 OUString GetDescr() const;
161 void dumpAsXml(xmlTextWriterPtr pWriter) const;
164 class SAL_DLLPUBLIC_RTTI SwRangeRedline final : public SwPaM, public ISwContentIndexOwner
166 SwRedlineData* m_pRedlineData;
167 std::optional<SwNodeIndex> m_oContentSect;
168 std::optional<tools::Long> m_oLOKLastNodeTop;
169 sal_uInt32 m_nId;
170 bool m_bDelLastPara : 1;
171 bool m_bIsVisible : 1;
173 void MoveToSection();
174 void CopyToSection();
175 void DelCopyOfSection(size_t nMyPos);
176 void MoveFromSection(size_t nMyPos);
178 public:
179 static sal_uInt32 s_nLastId;
181 SW_DLLPUBLIC SwRangeRedline( RedlineType eType, const SwPaM& rPam, sal_uInt32 nMoveID = 0 );
182 SW_DLLPUBLIC SwRangeRedline( const SwRedlineData& rData, const SwPaM& rPam );
183 SwRangeRedline( const SwRedlineData& rData, const SwPosition& rPos );
184 // For sw3io: pData is taken over!
185 SwRangeRedline(SwRedlineData* pData, const SwPosition& rPos,
186 bool bDelLP) :
187 SwPaM( rPos ), m_pRedlineData( pData ),
188 m_nId( s_nLastId++ ), m_bDelLastPara( bDelLP ), m_bIsVisible( true )
190 GetBound().SetOwner(this);
191 GetBound(false).SetOwner(this);
193 SwRangeRedline( const SwRangeRedline& );
194 virtual ~SwRangeRedline() override;
196 virtual SwContentIndexOwnerType GetOwnerType() const override final { return SwContentIndexOwnerType::Redline; }
198 sal_uInt32 GetId() const { return m_nId; }
199 const SwNodeIndex* GetContentIdx() const { return m_oContentSect ? &*m_oContentSect : nullptr; }
200 // For Undo.
201 void SetContentIdx( const SwNodeIndex& );
202 void ClearContentIdx();
204 bool IsVisible() const { return m_bIsVisible; }
205 bool IsDelLastPara() const { return m_bDelLastPara; }
207 void SetStart( const SwPosition& rPos, SwPosition* pSttPtr = nullptr );
208 void SetEnd( const SwPosition& rPos, SwPosition* pEndPtr = nullptr );
210 /// Do we have a valid selection?
211 bool HasValidRange() const;
213 SW_DLLPUBLIC const SwRedlineData& GetRedlineData(sal_uInt16 nPos = 0) const;
214 bool operator!=( const SwRedlineData& rCmp ) const
215 { return *m_pRedlineData != rCmp; }
216 void SetAutoFormat() { m_pRedlineData->SetAutoFormat(); }
217 bool IsAutoFormat() const { return m_pRedlineData->IsAutoFormat(); }
219 sal_uInt16 GetStackCount() const;
220 SW_DLLPUBLIC std::size_t GetAuthor( sal_uInt16 nPos = 0) const;
221 SW_DLLPUBLIC OUString const & GetAuthorString( sal_uInt16 nPos = 0 ) const;
222 sal_uInt32 GetMovedID(sal_uInt16 nPos = 0) const;
223 const DateTime& GetTimeStamp(sal_uInt16 nPos = 0) const;
224 SW_DLLPUBLIC RedlineType GetType( sal_uInt16 nPos = 0 ) const;
225 // text content of the redline is only an annotation placeholder
226 // (i.e. a comment, but don't confuse it with comment of the redline)
227 bool IsAnnotation() const;
228 const OUString& GetComment( sal_uInt16 nPos = 0 ) const;
230 void SetComment( const OUString& rS ) { m_pRedlineData->SetComment( rS ); }
232 /** ExtraData gets copied, the pointer is therefore not taken over by
233 * the RedLineObject.*/
234 void SetExtraData( const SwRedlineExtraData* pData )
235 { m_pRedlineData->SetExtraData( pData ); }
236 const SwRedlineExtraData* GetExtraData() const
237 { return m_pRedlineData->GetExtraData(); }
239 // For UI-side pooling of Redline-actions.
240 // At the moment only used for Autoformat with Redline.
241 // Value != 0 means there can be others!
242 sal_uInt16 GetSeqNo() const { return m_pRedlineData->GetSeqNo(); }
243 void SetSeqNo( sal_uInt16 nNo ) { m_pRedlineData->SetSeqNo( nNo ); }
245 // At Hide/ShowOriginal the list is traversed two times in order to
246 // hide the Del-Redlines via Copy and Delete.
247 // Otherwise at Move the attribution would be handled incorrectly.
248 // All other callers must always give 0.
249 void CallDisplayFunc(size_t nMyPos);
250 void Show(sal_uInt16 nLoop , size_t nMyPos, bool bForced = false);
251 void Hide(sal_uInt16 nLoop , size_t nMyPos, bool bForced = false);
252 void ShowOriginal(sal_uInt16 nLoop, size_t nMyPos, bool bForced = false);
254 /// Calculates the intersection with text node number nNdIdx.
255 void CalcStartEnd(SwNodeOffset nNdIdx, sal_Int32& rStart, sal_Int32& rEnd) const;
257 enum class Invalidation { Add, Remove };
258 /// Initiate the layout.
259 void InvalidateRange(Invalidation);
261 bool IsOwnRedline( const SwRangeRedline& rRedl ) const
262 { return GetAuthor() == rRedl.GetAuthor(); }
263 bool CanCombine( const SwRangeRedline& rRedl ) const;
265 void PushData( const SwRangeRedline& rRedl, bool bOwnAsNext = true );
266 bool PopData();
267 bool PopAllDataAfter(int depth);
270 Returns textual description of a redline data element of
271 this redline.
273 The textual description of the selected element contains the
274 kind of redline and the possibly shortened text of the redline.
276 @return textual description of the selected redline data element
278 bSimplified = simplified shortened text to show deletions on margin
280 SW_DLLPUBLIC OUString GetDescr(bool bSimplified = false);
282 bool operator<( const SwRangeRedline& ) const;
283 void dumpAsXml(xmlTextWriterPtr pWriter) const;
285 void MaybeNotifyRedlinePositionModification(tools::Long nTop);
287 void SetMoved(sal_uInt32 nMoveID = 1) { m_pRedlineData->SetMoved(nMoveID); }
288 bool IsMoved() const { return m_pRedlineData->IsMoved(); }
289 sal_uInt32 GetMoved(sal_uInt16 nPos = 0) const { return GetRedlineData(nPos).GetMoved(); }
292 void MaybeNotifyRedlineModification(SwRangeRedline& rRedline, SwDoc& rDoc);
294 /// Base object for 'Redlines' that are not of 'Ranged' type (like table row insert\delete)
295 class SW_DLLPUBLIC SwExtraRedline
297 private:
298 SwExtraRedline(SwExtraRedline const&) = delete;
299 SwExtraRedline& operator=(SwExtraRedline const&) = delete;
300 public:
301 SwExtraRedline() = default;
302 virtual ~SwExtraRedline();
305 /// Redline that holds information about a table-row that had some change
306 class SW_DLLPUBLIC SwTableRowRedline final : public SwExtraRedline
308 private:
309 SwRedlineData m_aRedlineData;
310 const SwTableLine& m_rTableLine;
312 public:
313 SwTableRowRedline(const SwRedlineData& rData, const SwTableLine& rTableLine);
314 virtual ~SwTableRowRedline() override;
316 /** ExtraData gets copied, the pointer is therefore not taken over by
317 * the RedLineObject.*/
318 void SetExtraData( const SwRedlineExtraData* pData )
319 { m_aRedlineData.SetExtraData( pData ); }
320 const SwTableLine& GetTableLine() const
321 { return m_rTableLine; }
322 const SwRedlineData& GetRedlineData() const
323 { return m_aRedlineData; }
326 /// Redline that holds information about a table-cell that had some change
327 class SW_DLLPUBLIC SwTableCellRedline final : public SwExtraRedline
329 private:
330 SwRedlineData m_aRedlineData;
331 const SwTableBox& m_rTableBox;
333 public:
334 SwTableCellRedline(const SwRedlineData& rData, const SwTableBox& rTableBox);
335 virtual ~SwTableCellRedline() override;
337 /** ExtraData gets copied, the pointer is therefore not taken over by
338 * the RedLineObject.*/
339 void SetExtraData( const SwRedlineExtraData* pData )
340 { m_aRedlineData.SetExtraData( pData ); }
341 const SwTableBox& GetTableBox() const
342 { return m_rTableBox; }
343 const SwRedlineData& GetRedlineData() const
344 { return m_aRedlineData; }
347 namespace sw {
349 std::vector<std::unique_ptr<SwRangeRedline>> GetAllValidRanges(std::unique_ptr<SwRangeRedline> p);
351 } // namespace sw
353 #endif
355 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */