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 <tools/datetime.hxx>
23 #include <rtl/ustring.hxx>
27 #include "IDocumentRedlineAccess.hxx"
32 #include <boost/optional.hpp>
37 class SW_DLLPUBLIC SwRedlineExtraData
39 SwRedlineExtraData( const SwRedlineExtraData
& ) = delete;
40 SwRedlineExtraData
& operator=( const SwRedlineExtraData
& ) = delete;
43 SwRedlineExtraData() {}
46 virtual ~SwRedlineExtraData();
47 virtual SwRedlineExtraData
* CreateNew() const = 0;
49 virtual void Reject( SwPaM
& rPam
) const;
50 virtual bool operator == ( const SwRedlineExtraData
& ) const;
53 class SW_DLLPUBLIC SwRedlineExtraData_FormatColl final
: public SwRedlineExtraData
56 std::unique_ptr
<SfxItemSet
> m_pSet
;
58 bool m_bFormatAll
; // don't strip the last paragraph mark
60 SwRedlineExtraData_FormatColl( const OUString
& rColl
, sal_uInt16 nPoolFormatId
,
61 const SfxItemSet
* pSet
= nullptr, bool bFormatAll
= true );
62 virtual ~SwRedlineExtraData_FormatColl() override
;
63 virtual SwRedlineExtraData
* CreateNew() const override
;
64 virtual void Reject( SwPaM
& rPam
) const override
;
65 virtual bool operator == ( const SwRedlineExtraData
& ) const override
;
67 const OUString
& GetFormatName() const { return m_sFormatNm
; }
68 void SetItemSet( const SfxItemSet
& rSet
);
69 SfxItemSet
* GetItemSet( ) const { return m_pSet
.get(); }
70 void SetFormatAll( bool bAll
) { m_bFormatAll
= bAll
; }
73 class SwRedlineExtraData_Format final
: public SwRedlineExtraData
75 std::vector
<sal_uInt16
> m_aWhichIds
;
77 SwRedlineExtraData_Format( const SwRedlineExtraData_Format
& rCpy
);
80 SwRedlineExtraData_Format( const SfxItemSet
& rSet
);
81 virtual ~SwRedlineExtraData_Format() override
;
82 virtual SwRedlineExtraData
* CreateNew() const override
;
83 virtual void Reject( SwPaM
& rPam
) const override
;
84 virtual bool operator == ( const SwRedlineExtraData
& ) const override
;
87 class SW_DLLPUBLIC SwRedlineData
89 friend class SwRangeRedline
;
90 SwRedlineData
* m_pNext
; // Points to other data.
91 SwRedlineExtraData
* m_pExtraData
;
97 std::size_t const 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 const OUString
& rCmnt
, 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_sComment
== rCmp
.m_sComment
&&
116 (( !m_pNext
&& !rCmp
.m_pNext
) ||
117 ( m_pNext
&& rCmp
.m_pNext
&& *m_pNext
== *rCmp
.m_pNext
)) &&
118 (( !m_pExtraData
&& !rCmp
.m_pExtraData
) ||
119 ( m_pExtraData
&& rCmp
.m_pExtraData
&&
120 *m_pExtraData
== *rCmp
.m_pExtraData
));
122 bool operator!=( const SwRedlineData
& rCmp
) const
123 { return !operator==( rCmp
); }
125 RedlineType
GetType() const { return m_eType
; }
127 std::size_t GetAuthor() const { return m_nAuthor
; }
128 const OUString
& GetComment() const { return m_sComment
; }
129 const DateTime
& GetTimeStamp() const { return m_aStamp
; }
130 const SwRedlineData
* Next() const{ return m_pNext
; }
132 void SetComment( const OUString
& rS
) { m_sComment
= rS
; }
133 void SetTimeStamp( const DateTime
& rDT
) { m_aStamp
= rDT
; }
135 void SetAutoFormat() { m_bAutoFormat
= true; }
136 bool IsAutoFormat() const { return m_bAutoFormat
; }
137 bool CanCombine( const SwRedlineData
& rCmp
) const;
139 // ExtraData gets copied, the pointer is therefore not taken over by
141 void SetExtraData( const SwRedlineExtraData
* pData
);
142 const SwRedlineExtraData
* GetExtraData() const { return m_pExtraData
; }
144 // For UI-side pooling of Redline-actions.
145 // At the moment only used for Autoformat with Redline.
146 // Value != 0 means there can be others!
147 sal_uInt16
GetSeqNo() const { return m_nSeqNo
; }
148 void SetSeqNo( sal_uInt16 nNo
) { m_nSeqNo
= nNo
; }
150 OUString
GetDescr() const;
153 class SW_DLLPUBLIC SwRangeRedline
: public SwPaM
155 SwRedlineData
* m_pRedlineData
;
156 SwNodeIndex
* m_pContentSect
;
157 bool m_bDelLastPara
: 1;
158 bool m_bIsVisible
: 1;
159 sal_uInt32
const m_nId
;
161 boost::optional
<long> m_oLOKLastNodeTop
;
163 void MoveToSection();
164 void CopyToSection();
165 void DelCopyOfSection(size_t nMyPos
);
166 void MoveFromSection(size_t nMyPos
);
169 static sal_uInt32 m_nLastId
;
171 SwRangeRedline( RedlineType eType
, const SwPaM
& rPam
);
172 SwRangeRedline( const SwRedlineData
& rData
, const SwPaM
& rPam
);
173 SwRangeRedline( const SwRedlineData
& rData
, const SwPosition
& rPos
);
174 // For sw3io: pData is taken over!
175 SwRangeRedline(SwRedlineData
* pData
, const SwPosition
& rPos
,
177 SwPaM( rPos
), m_pRedlineData( pData
), m_pContentSect( nullptr ),
178 m_bDelLastPara( bDelLP
), m_bIsVisible( true ), m_nId( m_nLastId
++ )
180 SwRangeRedline( const SwRangeRedline
& );
181 virtual ~SwRangeRedline() override
;
183 sal_uInt32
GetId() const { return m_nId
; }
184 SwNodeIndex
* GetContentIdx() const { return m_pContentSect
; }
186 void SetContentIdx( const SwNodeIndex
* );
188 bool IsVisible() const { return m_bIsVisible
; }
189 bool IsDelLastPara() const { return m_bDelLastPara
; }
191 void SetStart( const SwPosition
& rPos
, SwPosition
* pSttPtr
= nullptr );
192 void SetEnd( const SwPosition
& rPos
, SwPosition
* pEndPtr
= nullptr );
194 /// Do we have a valid selection?
195 bool HasValidRange() const;
197 const SwRedlineData
& GetRedlineData(sal_uInt16 nPos
= 0) const;
198 bool operator!=( const SwRedlineData
& rCmp
) const
199 { return *m_pRedlineData
!= rCmp
; }
200 void SetAutoFormat() { m_pRedlineData
->SetAutoFormat(); }
201 bool IsAutoFormat() const { return m_pRedlineData
->IsAutoFormat(); }
203 sal_uInt16
GetStackCount() const;
204 std::size_t GetAuthor( sal_uInt16 nPos
= 0) const;
205 OUString
const & GetAuthorString( sal_uInt16 nPos
= 0 ) const;
206 const DateTime
& GetTimeStamp( sal_uInt16 nPos
= 0) const;
207 RedlineType
GetType( sal_uInt16 nPos
= 0 ) const;
208 const OUString
& GetComment( sal_uInt16 nPos
= 0 ) const;
210 void SetComment( const OUString
& rS
) { m_pRedlineData
->SetComment( rS
); }
212 /** ExtraData gets copied, the pointer is therefore not taken over by
213 * the RedLineObject.*/
214 void SetExtraData( const SwRedlineExtraData
* pData
)
215 { m_pRedlineData
->SetExtraData( pData
); }
216 const SwRedlineExtraData
* GetExtraData() const
217 { return m_pRedlineData
->GetExtraData(); }
219 // For UI-side pooling of Redline-actions.
220 // At the moment only used for Autoformat with Redline.
221 // Value != 0 means there can be others!
222 sal_uInt16
GetSeqNo() const { return m_pRedlineData
->GetSeqNo(); }
223 void SetSeqNo( sal_uInt16 nNo
) { m_pRedlineData
->SetSeqNo( nNo
); }
225 // At Hide/ShowOriginal the list is traversed two times in order to
226 // hide the Del-Redlines via Copy and Delete.
227 // Otherwise at Move the attribution would be handled incorrectly.
228 // All other callers must always give 0.
229 void CallDisplayFunc(size_t nMyPos
);
230 void Show(sal_uInt16 nLoop
, size_t nMyPos
);
231 void Hide(sal_uInt16 nLoop
, size_t nMyPos
);
232 void ShowOriginal(sal_uInt16 nLoop
, size_t nMyPos
);
234 /// Calculates the intersection with text node number nNdIdx.
235 void CalcStartEnd(sal_uLong nNdIdx
, sal_Int32
& rStart
, sal_Int32
& rEnd
) const;
237 enum class Invalidation
{ Add
, Remove
};
238 /// Initiate the layout.
239 void InvalidateRange(Invalidation
);
241 bool IsOwnRedline( const SwRangeRedline
& rRedl
) const
242 { return GetAuthor() == rRedl
.GetAuthor(); }
243 bool CanCombine( const SwRangeRedline
& rRedl
) const;
245 void PushData( const SwRangeRedline
& rRedl
, bool bOwnAsNext
= true );
249 Returns textual description of a redline data element of
252 The textual description of the selected element contains the
253 kind of redline and the possibly shortened text of the redline.
255 @return textual description of the selected redline data element
259 bool operator<( const SwRangeRedline
& ) const;
260 void dumpAsXml(xmlTextWriterPtr pWriter
) const;
262 void MaybeNotifyRedlinePositionModification(long nTop
);
265 void MaybeNotifyRedlineModification(SwRangeRedline
* pRedline
, SwDoc
* pDoc
);
267 /// Base object for 'Redlines' that are not of 'Ranged' type (like table row insert\delete)
268 class SW_DLLPUBLIC SwExtraRedline
271 SwExtraRedline(SwExtraRedline
const&) = delete;
272 SwExtraRedline
& operator=(SwExtraRedline
const&) = delete;
274 SwExtraRedline() = default;
275 virtual ~SwExtraRedline();
278 /// Redline that holds information about a table-row that had some change
279 class SW_DLLPUBLIC SwTableRowRedline
: public SwExtraRedline
282 SwRedlineData m_aRedlineData
;
283 const SwTableLine
& m_rTableLine
;
286 SwTableRowRedline(const SwRedlineData
& rData
, const SwTableLine
& rTableLine
);
287 virtual ~SwTableRowRedline() override
;
289 /** ExtraData gets copied, the pointer is therefore not taken over by
290 * the RedLineObject.*/
291 void SetExtraData( const SwRedlineExtraData
* pData
)
292 { m_aRedlineData
.SetExtraData( pData
); }
293 const SwTableLine
& GetTableLine() const
294 { return m_rTableLine
; }
295 const SwRedlineData
& GetRedlineData() const
296 { return m_aRedlineData
; }
299 /// Redline that holds information about a table-cell that had some change
300 class SW_DLLPUBLIC SwTableCellRedline
: public SwExtraRedline
303 SwRedlineData m_aRedlineData
;
304 const SwTableBox
& m_rTableBox
;
307 SwTableCellRedline(const SwRedlineData
& rData
, const SwTableBox
& rTableBox
);
308 virtual ~SwTableCellRedline() override
;
310 /** ExtraData gets copied, the pointer is therefore not taken over by
311 * the RedLineObject.*/
312 void SetExtraData( const SwRedlineExtraData
* pData
)
313 { m_aRedlineData
.SetExtraData( pData
); }
314 const SwTableBox
& GetTableBox() const
315 { return m_rTableBox
; }
316 const SwRedlineData
& GetRedlineData() const
317 { return m_aRedlineData
; }
320 class SW_DLLPUBLIC SwRedlineHint final
: public SfxHint
327 std::vector
<SwRangeRedline
*> GetAllValidRanges(std::unique_ptr
<SwRangeRedline
> p
);
333 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */