Resolves tdf#142513 - Order of ZoomIn and ZoomOut at Print Preview
[LibreOffice.git] / sw / inc / redline.hxx
blob8d352b2b423c786650616c577afb622d4311d0eb
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( const OUString& rColl, 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;
99 public:
100 SwRedlineData( RedlineType eT, std::size_t nAut );
101 SwRedlineData( const SwRedlineData& rCpy, bool bCpyNext = true );
103 // For sw3io: pNext/pExtraData are taken over.
104 SwRedlineData( RedlineType eT, std::size_t nAut, const DateTime& rDT,
105 const OUString& rCmnt, SwRedlineData* pNxt );
107 ~SwRedlineData();
109 bool operator==( const SwRedlineData& rCmp ) const
111 return m_nAuthor == rCmp.m_nAuthor &&
112 m_eType == rCmp.m_eType &&
113 m_bAutoFormat == rCmp.m_bAutoFormat &&
114 m_sComment == rCmp.m_sComment &&
115 (( !m_pNext && !rCmp.m_pNext ) ||
116 ( m_pNext && rCmp.m_pNext && *m_pNext == *rCmp.m_pNext )) &&
117 (( !m_pExtraData && !rCmp.m_pExtraData ) ||
118 ( m_pExtraData && rCmp.m_pExtraData &&
119 *m_pExtraData == *rCmp.m_pExtraData ));
121 bool operator!=( const SwRedlineData& rCmp ) const
122 { return !operator==( rCmp ); }
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 const SwRedlineData* Next() const{ return m_pNext; }
131 void SetComment( const OUString& rS ) { m_sComment = rS; }
132 void SetTimeStamp( const DateTime& rDT ) { m_aStamp = rDT; }
134 void SetAutoFormat() { m_bAutoFormat = true; }
135 bool IsAutoFormat() const { return m_bAutoFormat; }
136 bool CanCombine( const SwRedlineData& rCmp ) const;
138 // ExtraData gets copied, the pointer is therefore not taken over by
139 // the RedlineObject
140 void SetExtraData( const SwRedlineExtraData* pData );
141 const SwRedlineExtraData* GetExtraData() const { return m_pExtraData; }
143 // For UI-side pooling of Redline-actions.
144 // At the moment only used for Autoformat with Redline.
145 // Value != 0 means there can be others!
146 sal_uInt16 GetSeqNo() const { return m_nSeqNo; }
147 void SetSeqNo( sal_uInt16 nNo ) { m_nSeqNo = nNo; }
149 OUString GetDescr() const;
152 class SW_DLLPUBLIC SwRangeRedline : public SwPaM
154 SwRedlineData* m_pRedlineData;
155 SwNodeIndex* m_pContentSect;
156 bool m_bDelLastPara : 1;
157 bool m_bIsVisible : 1;
158 sal_uInt32 m_nId;
160 std::optional<tools::Long> m_oLOKLastNodeTop;
162 void MoveToSection();
163 void CopyToSection();
164 void DelCopyOfSection(size_t nMyPos);
165 void MoveFromSection(size_t nMyPos);
167 public:
168 static sal_uInt32 s_nLastId;
170 SwRangeRedline( RedlineType eType, const SwPaM& rPam );
171 SwRangeRedline( const SwRedlineData& rData, const SwPaM& rPam );
172 SwRangeRedline( const SwRedlineData& rData, const SwPosition& rPos );
173 // For sw3io: pData is taken over!
174 SwRangeRedline(SwRedlineData* pData, const SwPosition& rPos,
175 bool bDelLP) :
176 SwPaM( rPos ), m_pRedlineData( pData ), m_pContentSect( nullptr ),
177 m_bDelLastPara( bDelLP ), m_bIsVisible( true ), m_nId( s_nLastId++ )
179 SwRangeRedline( const SwRangeRedline& );
180 virtual ~SwRangeRedline() override;
182 sal_uInt32 GetId() const { return m_nId; }
183 SwNodeIndex* GetContentIdx() const { return m_pContentSect; }
184 // For Undo.
185 void SetContentIdx( const SwNodeIndex* );
187 bool IsVisible() const { return m_bIsVisible; }
188 bool IsDelLastPara() const { return m_bDelLastPara; }
190 void SetStart( const SwPosition& rPos, SwPosition* pSttPtr = nullptr );
191 void SetEnd( const SwPosition& rPos, SwPosition* pEndPtr = nullptr );
193 /// Do we have a valid selection?
194 bool HasValidRange() const;
196 const SwRedlineData& GetRedlineData(sal_uInt16 nPos = 0) const;
197 bool operator!=( const SwRedlineData& rCmp ) const
198 { return *m_pRedlineData != rCmp; }
199 void SetAutoFormat() { m_pRedlineData->SetAutoFormat(); }
200 bool IsAutoFormat() const { return m_pRedlineData->IsAutoFormat(); }
202 sal_uInt16 GetStackCount() const;
203 std::size_t GetAuthor( sal_uInt16 nPos = 0) const;
204 OUString const & GetAuthorString( sal_uInt16 nPos = 0 ) const;
205 const DateTime& GetTimeStamp( sal_uInt16 nPos = 0) const;
206 RedlineType GetType( sal_uInt16 nPos = 0 ) const;
207 const OUString& GetComment( sal_uInt16 nPos = 0 ) const;
209 void SetComment( const OUString& rS ) { m_pRedlineData->SetComment( rS ); }
211 /** ExtraData gets copied, the pointer is therefore not taken over by
212 * the RedLineObject.*/
213 void SetExtraData( const SwRedlineExtraData* pData )
214 { m_pRedlineData->SetExtraData( pData ); }
215 const SwRedlineExtraData* GetExtraData() const
216 { return m_pRedlineData->GetExtraData(); }
218 // For UI-side pooling of Redline-actions.
219 // At the moment only used for Autoformat with Redline.
220 // Value != 0 means there can be others!
221 sal_uInt16 GetSeqNo() const { return m_pRedlineData->GetSeqNo(); }
222 void SetSeqNo( sal_uInt16 nNo ) { m_pRedlineData->SetSeqNo( nNo ); }
224 // At Hide/ShowOriginal the list is traversed two times in order to
225 // hide the Del-Redlines via Copy and Delete.
226 // Otherwise at Move the attribution would be handled incorrectly.
227 // All other callers must always give 0.
228 void CallDisplayFunc(size_t nMyPos);
229 void Show(sal_uInt16 nLoop , size_t nMyPos, bool bForced = false);
230 void Hide(sal_uInt16 nLoop , size_t nMyPos, bool bForced = false);
231 void ShowOriginal(sal_uInt16 nLoop, size_t nMyPos, bool bForced = false);
233 /// Calculates the intersection with text node number nNdIdx.
234 void CalcStartEnd(sal_uLong nNdIdx, sal_Int32& rStart, sal_Int32& rEnd) const;
236 enum class Invalidation { Add, Remove };
237 /// Initiate the layout.
238 void InvalidateRange(Invalidation);
240 bool IsOwnRedline( const SwRangeRedline& rRedl ) const
241 { return GetAuthor() == rRedl.GetAuthor(); }
242 bool CanCombine( const SwRangeRedline& rRedl ) const;
244 void PushData( const SwRangeRedline& rRedl, bool bOwnAsNext = true );
245 bool PopData();
248 Returns textual description of a redline data element of
249 this redline.
251 The textual description of the selected element contains the
252 kind of redline and the possibly shortened text of the redline.
254 @return textual description of the selected redline data element
256 bSimplified = simplified shortened text to show deletions on margin
258 OUString GetDescr(bool bSimplified = false);
260 bool operator<( const SwRangeRedline& ) const;
261 void dumpAsXml(xmlTextWriterPtr pWriter) const;
263 void MaybeNotifyRedlinePositionModification(tools::Long nTop);
266 void MaybeNotifyRedlineModification(SwRangeRedline& rRedline, SwDoc& rDoc);
268 /// Base object for 'Redlines' that are not of 'Ranged' type (like table row insert\delete)
269 class SW_DLLPUBLIC SwExtraRedline
271 private:
272 SwExtraRedline(SwExtraRedline const&) = delete;
273 SwExtraRedline& operator=(SwExtraRedline const&) = delete;
274 public:
275 SwExtraRedline() = default;
276 virtual ~SwExtraRedline();
279 /// Redline that holds information about a table-row that had some change
280 class SW_DLLPUBLIC SwTableRowRedline : public SwExtraRedline
282 private:
283 SwRedlineData m_aRedlineData;
284 const SwTableLine& m_rTableLine;
286 public:
287 SwTableRowRedline(const SwRedlineData& rData, const SwTableLine& rTableLine);
288 virtual ~SwTableRowRedline() override;
290 /** ExtraData gets copied, the pointer is therefore not taken over by
291 * the RedLineObject.*/
292 void SetExtraData( const SwRedlineExtraData* pData )
293 { m_aRedlineData.SetExtraData( pData ); }
294 const SwTableLine& GetTableLine() const
295 { return m_rTableLine; }
296 const SwRedlineData& GetRedlineData() const
297 { return m_aRedlineData; }
300 /// Redline that holds information about a table-cell that had some change
301 class SW_DLLPUBLIC SwTableCellRedline : public SwExtraRedline
303 private:
304 SwRedlineData m_aRedlineData;
305 const SwTableBox& m_rTableBox;
307 public:
308 SwTableCellRedline(const SwRedlineData& rData, const SwTableBox& rTableBox);
309 virtual ~SwTableCellRedline() override;
311 /** ExtraData gets copied, the pointer is therefore not taken over by
312 * the RedLineObject.*/
313 void SetExtraData( const SwRedlineExtraData* pData )
314 { m_aRedlineData.SetExtraData( pData ); }
315 const SwTableBox& GetTableBox() const
316 { return m_rTableBox; }
317 const SwRedlineData& GetRedlineData() const
318 { return m_aRedlineData; }
321 class SW_DLLPUBLIC SwRedlineHint final : public SfxHint
326 namespace sw {
328 std::vector<SwRangeRedline*> GetAllValidRanges(std::unique_ptr<SwRangeRedline> p);
330 } // namespace sw
332 #endif
334 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */