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_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>
36 class SW_DLLPUBLIC SwRedlineExtraData
38 SwRedlineExtraData( const SwRedlineExtraData
& ) = delete;
39 SwRedlineExtraData
& operator=( const SwRedlineExtraData
& ) = delete;
42 SwRedlineExtraData() {}
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
55 std::unique_ptr
<SfxItemSet
> m_pSet
;
57 bool m_bFormatAll
; // don't strip the last paragraph mark
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
);
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
;
94 std::size_t m_nAuthor
;
101 SwRedlineData( RedlineType eT
, std::size_t nAut
);
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
,
106 OUString aCmnt
, SwRedlineData
* pNxt
);
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_bMoved
== rCmp
.m_bMoved
&&
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
));
123 bool operator!=( const SwRedlineData
& rCmp
) const
124 { return !operator==( rCmp
); }
126 RedlineType
GetType() const { return m_eType
; }
128 std::size_t GetAuthor() const { return m_nAuthor
; }
129 const OUString
& GetComment() const { return m_sComment
; }
130 const DateTime
& GetTimeStamp() const { return m_aStamp
; }
131 bool IsAnonymized() const
133 return m_aStamp
.GetYear() == 1970 &&
134 m_aStamp
.GetMonth() == 1 && m_aStamp
.GetDay() == 1;
137 const SwRedlineData
* Next() const{ return m_pNext
; }
139 void SetComment( const OUString
& rS
) { m_sComment
= rS
; }
140 void SetTimeStamp( const DateTime
& rDT
) { m_aStamp
= rDT
; }
142 void SetAutoFormat() { m_bAutoFormat
= true; }
143 bool IsAutoFormat() const { return m_bAutoFormat
; }
144 void SetMoved() { m_bMoved
= true; }
145 bool IsMoved() const { return m_bMoved
; }
146 bool CanCombine( const SwRedlineData
& rCmp
) const;
148 // ExtraData gets copied, the pointer is therefore not taken over by
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;
162 class SW_DLLPUBLIC SwRangeRedline final
: public SwPaM
164 SwRedlineData
* m_pRedlineData
;
165 std::optional
<SwNodeIndex
> m_oContentSect
;
166 std::optional
<tools::Long
> m_oLOKLastNodeTop
;
168 bool m_bDelLastPara
: 1;
169 bool m_bIsVisible
: 1;
171 void MoveToSection();
172 void CopyToSection();
173 void DelCopyOfSection(size_t nMyPos
);
174 void MoveFromSection(size_t nMyPos
);
177 static sal_uInt32 s_nLastId
;
179 SwRangeRedline( RedlineType eType
, const SwPaM
& rPam
);
180 SwRangeRedline( const SwRedlineData
& rData
, const SwPaM
& rPam
);
181 SwRangeRedline( const SwRedlineData
& rData
, const SwPosition
& rPos
);
182 // For sw3io: pData is taken over!
183 SwRangeRedline(SwRedlineData
* pData
, const SwPosition
& rPos
,
185 SwPaM( rPos
), m_pRedlineData( pData
),
186 m_nId( s_nLastId
++ ), m_bDelLastPara( bDelLP
), m_bIsVisible( true )
188 GetBound().SetRedline(this);
189 GetBound(false).SetRedline(this);
191 SwRangeRedline( const SwRangeRedline
& );
192 virtual ~SwRangeRedline() override
;
194 sal_uInt32
GetId() const { return m_nId
; }
195 const SwNodeIndex
* GetContentIdx() const { return m_oContentSect
? &*m_oContentSect
: nullptr; }
197 void SetContentIdx( const SwNodeIndex
& );
198 void ClearContentIdx();
200 bool IsVisible() const { return m_bIsVisible
; }
201 bool IsDelLastPara() const { return m_bDelLastPara
; }
203 void SetStart( const SwPosition
& rPos
, SwPosition
* pSttPtr
= nullptr );
204 void SetEnd( const SwPosition
& rPos
, SwPosition
* pEndPtr
= nullptr );
206 /// Do we have a valid selection?
207 bool HasValidRange() const;
209 const SwRedlineData
& GetRedlineData(sal_uInt16 nPos
= 0) const;
210 bool operator!=( const SwRedlineData
& rCmp
) const
211 { return *m_pRedlineData
!= rCmp
; }
212 void SetAutoFormat() { m_pRedlineData
->SetAutoFormat(); }
213 bool IsAutoFormat() const { return m_pRedlineData
->IsAutoFormat(); }
215 sal_uInt16
GetStackCount() const;
216 std::size_t GetAuthor( sal_uInt16 nPos
= 0) const;
217 OUString
const & GetAuthorString( sal_uInt16 nPos
= 0 ) const;
218 const DateTime
& GetTimeStamp( sal_uInt16 nPos
= 0) const;
219 RedlineType
GetType( sal_uInt16 nPos
= 0 ) const;
220 // text content of the redline is only an annotation placeholder
221 // (i.e. a comment, but don't confuse it with comment of the redline)
222 bool IsAnnotation() const;
223 const OUString
& GetComment( sal_uInt16 nPos
= 0 ) const;
225 void SetComment( const OUString
& rS
) { m_pRedlineData
->SetComment( rS
); }
227 /** ExtraData gets copied, the pointer is therefore not taken over by
228 * the RedLineObject.*/
229 void SetExtraData( const SwRedlineExtraData
* pData
)
230 { m_pRedlineData
->SetExtraData( pData
); }
231 const SwRedlineExtraData
* GetExtraData() const
232 { return m_pRedlineData
->GetExtraData(); }
234 // For UI-side pooling of Redline-actions.
235 // At the moment only used for Autoformat with Redline.
236 // Value != 0 means there can be others!
237 sal_uInt16
GetSeqNo() const { return m_pRedlineData
->GetSeqNo(); }
238 void SetSeqNo( sal_uInt16 nNo
) { m_pRedlineData
->SetSeqNo( nNo
); }
240 // At Hide/ShowOriginal the list is traversed two times in order to
241 // hide the Del-Redlines via Copy and Delete.
242 // Otherwise at Move the attribution would be handled incorrectly.
243 // All other callers must always give 0.
244 void CallDisplayFunc(size_t nMyPos
);
245 void Show(sal_uInt16 nLoop
, size_t nMyPos
, bool bForced
= false);
246 void Hide(sal_uInt16 nLoop
, size_t nMyPos
, bool bForced
= false);
247 void ShowOriginal(sal_uInt16 nLoop
, size_t nMyPos
, bool bForced
= false);
249 /// Calculates the intersection with text node number nNdIdx.
250 void CalcStartEnd(SwNodeOffset nNdIdx
, sal_Int32
& rStart
, sal_Int32
& rEnd
) const;
252 enum class Invalidation
{ Add
, Remove
};
253 /// Initiate the layout.
254 void InvalidateRange(Invalidation
);
256 bool IsOwnRedline( const SwRangeRedline
& rRedl
) const
257 { return GetAuthor() == rRedl
.GetAuthor(); }
258 bool CanCombine( const SwRangeRedline
& rRedl
) const;
260 void PushData( const SwRangeRedline
& rRedl
, bool bOwnAsNext
= true );
264 Returns textual description of a redline data element of
267 The textual description of the selected element contains the
268 kind of redline and the possibly shortened text of the redline.
270 @return textual description of the selected redline data element
272 bSimplified = simplified shortened text to show deletions on margin
274 OUString
GetDescr(bool bSimplified
= false);
276 bool operator<( const SwRangeRedline
& ) const;
277 void dumpAsXml(xmlTextWriterPtr pWriter
) const;
279 void MaybeNotifyRedlinePositionModification(tools::Long nTop
);
281 void SetMoved() { m_pRedlineData
->SetMoved(); }
282 bool IsMoved() const { return m_pRedlineData
->IsMoved(); }
285 void MaybeNotifyRedlineModification(SwRangeRedline
& rRedline
, SwDoc
& rDoc
);
287 /// Base object for 'Redlines' that are not of 'Ranged' type (like table row insert\delete)
288 class SW_DLLPUBLIC SwExtraRedline
291 SwExtraRedline(SwExtraRedline
const&) = delete;
292 SwExtraRedline
& operator=(SwExtraRedline
const&) = delete;
294 SwExtraRedline() = default;
295 virtual ~SwExtraRedline();
298 /// Redline that holds information about a table-row that had some change
299 class SW_DLLPUBLIC SwTableRowRedline final
: public SwExtraRedline
302 SwRedlineData m_aRedlineData
;
303 const SwTableLine
& m_rTableLine
;
306 SwTableRowRedline(const SwRedlineData
& rData
, const SwTableLine
& rTableLine
);
307 virtual ~SwTableRowRedline() override
;
309 /** ExtraData gets copied, the pointer is therefore not taken over by
310 * the RedLineObject.*/
311 void SetExtraData( const SwRedlineExtraData
* pData
)
312 { m_aRedlineData
.SetExtraData( pData
); }
313 const SwTableLine
& GetTableLine() const
314 { return m_rTableLine
; }
315 const SwRedlineData
& GetRedlineData() const
316 { return m_aRedlineData
; }
319 /// Redline that holds information about a table-cell that had some change
320 class SW_DLLPUBLIC SwTableCellRedline final
: public SwExtraRedline
323 SwRedlineData m_aRedlineData
;
324 const SwTableBox
& m_rTableBox
;
327 SwTableCellRedline(const SwRedlineData
& rData
, const SwTableBox
& rTableBox
);
328 virtual ~SwTableCellRedline() override
;
330 /** ExtraData gets copied, the pointer is therefore not taken over by
331 * the RedLineObject.*/
332 void SetExtraData( const SwRedlineExtraData
* pData
)
333 { m_aRedlineData
.SetExtraData( pData
); }
334 const SwTableBox
& GetTableBox() const
335 { return m_rTableBox
; }
336 const SwRedlineData
& GetRedlineData() const
337 { return m_aRedlineData
; }
340 class SW_DLLPUBLIC SwRedlineHint final
: public SfxHint
347 std::vector
<std::unique_ptr
<SwRangeRedline
>> GetAllValidRanges(std::unique_ptr
<SwRangeRedline
> p
);
353 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */