Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / sw / inc / redline.hxx
blob6092b665005662bb2a2a4340b43dd6d9af624cf4
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 <tools/datetime.hxx>
23 #include <rtl/ustring.hxx>
25 #include <pam.hxx>
26 #include <swtable.hxx>
28 #include <IDocumentRedlineAccess.hxx>
30 #include <cstddef>
31 #include <memory>
32 #include <vector>
34 class SfxItemSet;
35 class SwView;
37 class SW_DLLPUBLIC SwRedlineExtraData
39 SwRedlineExtraData( const SwRedlineExtraData& ) = delete;
40 SwRedlineExtraData& operator=( const SwRedlineExtraData& ) = delete;
42 protected:
43 SwRedlineExtraData() {}
45 public:
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 SwRedlineExtraData_FormatColl : public SwRedlineExtraData
55 OUString sFormatNm;
56 std::unique_ptr<SfxItemSet> pSet;
57 sal_uInt16 nPoolId;
58 public:
59 SwRedlineExtraData_FormatColl( const OUString& rColl, sal_uInt16 nPoolFormatId,
60 const SfxItemSet* pSet = nullptr );
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 void SetItemSet( const SfxItemSet& rSet );
69 class SwRedlineExtraData_Format : public SwRedlineExtraData
71 std::vector<sal_uInt16> aWhichIds;
73 SwRedlineExtraData_Format( const SwRedlineExtraData_Format& rCpy );
75 public:
76 SwRedlineExtraData_Format( const SfxItemSet& rSet );
77 virtual ~SwRedlineExtraData_Format() override;
78 virtual SwRedlineExtraData* CreateNew() const override;
79 virtual void Reject( SwPaM& rPam ) const override;
80 virtual bool operator == ( const SwRedlineExtraData& ) const override;
84 * This class is used to store 'redline' data regarding formatting changes,
85 * e.g. - a text portion *was* italic and now is not italic,
86 * e.g. - a text portion got a hightlight to it
88 * The way the information is stored is in an 'SfxItemSet' that holds all
89 * the WhichIds with their values.
91 class SW_DLLPUBLIC SwRedlineExtraData_FormattingChanges : public SwRedlineExtraData
93 std::unique_ptr<SfxItemSet> pSet;
95 SwRedlineExtraData_FormattingChanges( const SwRedlineExtraData_FormattingChanges& rCpy );
97 public:
98 SwRedlineExtraData_FormattingChanges( const SfxItemSet* pItemSet );
99 virtual ~SwRedlineExtraData_FormattingChanges() override;
100 virtual SwRedlineExtraData* CreateNew() const override;
101 virtual void Reject( SwPaM& rPam ) const override;
102 virtual bool operator == ( const SwRedlineExtraData& ) const override;
103 SfxItemSet* GetItemSet( ) const { return pSet.get(); }
106 class SW_DLLPUBLIC SwRedlineData
108 friend class SwRangeRedline;
109 SwRedlineData* pNext; // Points to other data.
110 SwRedlineExtraData* pExtraData;
112 OUString sComment;
113 DateTime aStamp;
114 RedlineType_t eType;
115 std::size_t nAuthor;
116 sal_uInt16 nSeqNo;
118 public:
119 SwRedlineData( RedlineType_t eT, std::size_t nAut );
120 SwRedlineData( const SwRedlineData& rCpy, bool bCpyNext = true );
122 // For sw3io: pNext/pExtraData are taken over.
123 SwRedlineData( RedlineType_t eT, std::size_t nAut, const DateTime& rDT,
124 const OUString& rCmnt, SwRedlineData* pNxt );
126 ~SwRedlineData();
128 bool operator==( const SwRedlineData& rCmp ) const
130 return nAuthor == rCmp.nAuthor &&
131 eType == rCmp.eType &&
132 sComment == rCmp.sComment &&
133 (( !pNext && !rCmp.pNext ) ||
134 ( pNext && rCmp.pNext && *pNext == *rCmp.pNext )) &&
135 (( !pExtraData && !rCmp.pExtraData ) ||
136 ( pExtraData && rCmp.pExtraData &&
137 *pExtraData == *rCmp.pExtraData ));
139 bool operator!=( const SwRedlineData& rCmp ) const
140 { return !operator==( rCmp ); }
142 RedlineType_t GetType() const
143 { return ((RedlineType_t)(eType & nsRedlineType_t::REDLINE_NO_FLAG_MASK)); }
145 std::size_t GetAuthor() const { return nAuthor; }
146 const OUString& GetComment() const { return sComment; }
147 const DateTime& GetTimeStamp() const { return aStamp; }
148 const SwRedlineData* Next() const{ return pNext; }
150 void SetComment( const OUString& rS ) { sComment = rS; }
151 void SetTimeStamp( const DateTime& rDT ) { aStamp = rDT; }
153 void SetAutoFormatFlag()
154 { eType = (RedlineType_t)(eType | nsRedlineType_t::REDLINE_FORM_AUTOFMT); }
155 bool CanCombine( const SwRedlineData& rCmp ) const;
157 // ExtraData gets copied, the pointer is therefore not taken over by
158 // the RedlineObject
159 void SetExtraData( const SwRedlineExtraData* pData );
160 const SwRedlineExtraData* GetExtraData() const { return pExtraData; }
162 // For UI-side pooling of Redline-actions.
163 // At the moment only used for Autoformat with Redline.
164 // Value != 0 means there can be others!
165 sal_uInt16 GetSeqNo() const { return nSeqNo; }
166 void SetSeqNo( sal_uInt16 nNo ) { nSeqNo = nNo; }
168 OUString GetDescr() const;
171 class SW_DLLPUBLIC SwRangeRedline : public SwPaM
173 SwRedlineData* pRedlineData;
174 SwNodeIndex* pContentSect;
175 bool bDelLastPara : 1;
176 bool bIsVisible : 1;
177 sal_uInt32 m_nId;
179 void MoveToSection();
180 void CopyToSection();
181 void DelCopyOfSection(size_t nMyPos);
182 void MoveFromSection(size_t nMyPos);
184 public:
185 static sal_uInt32 m_nLastId;
187 SwRangeRedline( RedlineType_t eType, const SwPaM& rPam );
188 SwRangeRedline( const SwRedlineData& rData, const SwPaM& rPam );
189 SwRangeRedline( const SwRedlineData& rData, const SwPosition& rPos );
190 // For sw3io: pData is taken over!
191 SwRangeRedline(SwRedlineData* pData, const SwPosition& rPos,
192 bool bDelLP) :
193 SwPaM( rPos ), pRedlineData( pData ), pContentSect( nullptr ),
194 bDelLastPara( bDelLP ), bIsVisible( true ), m_nId( m_nLastId++ )
196 SwRangeRedline( const SwRangeRedline& );
197 virtual ~SwRangeRedline() override;
199 sal_uInt32 GetId() const { return m_nId; }
200 SwNodeIndex* GetContentIdx() const { return pContentSect; }
201 // For Undo.
202 void SetContentIdx( const SwNodeIndex* );
204 bool IsVisible() const { return bIsVisible; }
205 bool IsDelLastPara() const { return 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 const SwRedlineData& GetRedlineData(sal_uInt16 nPos = 0) const;
214 bool operator!=( const SwRedlineData& rCmp ) const
215 { return *pRedlineData != rCmp; }
216 void SetAutoFormatFlag() { pRedlineData->SetAutoFormatFlag(); }
218 sal_uInt16 GetStackCount() const;
219 std::size_t GetAuthor( sal_uInt16 nPos = 0) const;
220 OUString GetAuthorString( sal_uInt16 nPos = 0 ) const;
221 const DateTime& GetTimeStamp( sal_uInt16 nPos = 0) const;
222 RedlineType_t GetRealType( sal_uInt16 nPos = 0 ) const;
223 RedlineType_t GetType( sal_uInt16 nPos = 0) const
224 { return ( (RedlineType_t)(GetRealType( nPos ) & nsRedlineType_t::REDLINE_NO_FLAG_MASK)); }
225 const OUString& GetComment( sal_uInt16 nPos = 0 ) const;
227 void SetComment( const OUString& rS ) { pRedlineData->SetComment( rS ); }
229 /** ExtraData gets copied, the pointer is therefore not taken over by
230 * the RedLineObject.*/
231 void SetExtraData( const SwRedlineExtraData* pData )
232 { pRedlineData->SetExtraData( pData ); }
233 const SwRedlineExtraData* GetExtraData() const
234 { return pRedlineData->GetExtraData(); }
236 // For UI-side pooling of Redline-actions.
237 // At the moment only used for Autoformat with Redline.
238 // Value != 0 means there can be others!
239 sal_uInt16 GetSeqNo() const { return pRedlineData->GetSeqNo(); }
240 void SetSeqNo( sal_uInt16 nNo ) { pRedlineData->SetSeqNo( nNo ); }
242 // At Hide/ShowOriginal the list is traversed two times in order to
243 // hide the Del-Redlines via Copy and Delete.
244 // Otherwise at Move the attribution would be handled incorrectly.
245 // All other callers must always give 0.
246 void CallDisplayFunc(size_t nMyPos);
247 void Show(sal_uInt16 nLoop , size_t nMyPos);
248 void Hide(sal_uInt16 nLoop , size_t nMyPos);
249 void ShowOriginal(sal_uInt16 nLoop, size_t nMyPos);
251 /// Calculates the intersection with text node number nNdIdx.
252 void CalcStartEnd(sal_uLong nNdIdx, sal_Int32& rStart, sal_Int32& rEnd) const;
254 /// Initiate the layout.
255 void InvalidateRange();
257 bool IsOwnRedline( const SwRangeRedline& rRedl ) const
258 { return GetAuthor() == rRedl.GetAuthor(); }
259 bool CanCombine( const SwRangeRedline& rRedl ) const;
261 void PushData( const SwRangeRedline& rRedl, bool bOwnAsNext = true );
262 bool PopData();
265 Returns textual description of a redline data element of
266 this redline.
268 The textual description of the selected element contains the
269 kind of redline and the possibly shortened text of the redline.
271 @return textual description of the selected redline data element
273 OUString GetDescr();
275 bool operator<( const SwRangeRedline& ) const;
276 void dumpAsXml(struct _xmlTextWriter* pWriter) const;
277 void MaybeNotifyModification();
280 /// Base object for 'Redlines' that are not of 'Ranged' type (like table row insert\delete)
281 class SW_DLLPUBLIC SwExtraRedline
283 private:
284 SwExtraRedline(SwExtraRedline const&) = delete;
285 SwExtraRedline& operator=(SwExtraRedline const&) = delete;
286 public:
287 SwExtraRedline() = default;
288 virtual ~SwExtraRedline();
291 /// Redline that holds information about a table-row that had some change
292 class SW_DLLPUBLIC SwTableRowRedline : public SwExtraRedline
294 private:
295 SwRedlineData m_aRedlineData;
296 const SwTableLine& m_rTableLine;
298 public:
299 SwTableRowRedline(const SwRedlineData& rData, const SwTableLine& rTableLine);
300 virtual ~SwTableRowRedline() override;
302 /** ExtraData gets copied, the pointer is therefore not taken over by
303 * the RedLineObject.*/
304 void SetExtraData( const SwRedlineExtraData* pData )
305 { m_aRedlineData.SetExtraData( pData ); }
306 const SwTableLine& GetTableLine() const
307 { return m_rTableLine; }
308 const SwRedlineData& GetRedlineData() const
309 { return m_aRedlineData; }
312 /// Redline that holds information about a table-cell that had some change
313 class SW_DLLPUBLIC SwTableCellRedline : public SwExtraRedline
315 private:
316 SwRedlineData m_aRedlineData;
317 const SwTableBox& m_rTableBox;
319 public:
320 SwTableCellRedline(const SwRedlineData& rData, const SwTableBox& rTableBox);
321 virtual ~SwTableCellRedline() override;
323 /** ExtraData gets copied, the pointer is therefore not taken over by
324 * the RedLineObject.*/
325 void SetExtraData( const SwRedlineExtraData* pData )
326 { m_aRedlineData.SetExtraData( pData ); }
327 const SwTableBox& GetTableBox() const
328 { return m_rTableBox; }
329 const SwRedlineData& GetRedlineData() const
330 { return m_aRedlineData; }
333 class SW_DLLPUBLIC SwRedlineHint : public SfxHint
337 #endif
339 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */