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