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 <tools/datetime.hxx>
23 #include <rtl/ustring.hxx>
24 
25 #include "pam.hxx"
26 
27 #include "IDocumentRedlineAccess.hxx"
28 
29 #include <cstddef>
30 #include <memory>
31 #include <vector>
32 #include <boost/optional.hpp>
33 
34 
35 class SfxItemSet;
36 
37 class SW_DLLPUBLIC SwRedlineExtraData
38 {
39     SwRedlineExtraData( const SwRedlineExtraData& ) = delete;
40     SwRedlineExtraData& operator=( const SwRedlineExtraData& ) = delete;
41 
42 protected:
SwRedlineExtraData()43     SwRedlineExtraData() {}
44 
45 public:
46     virtual ~SwRedlineExtraData();
47     virtual SwRedlineExtraData* CreateNew() const = 0;
48 
49     virtual void Reject( SwPaM& rPam ) const;
50     virtual bool operator == ( const SwRedlineExtraData& ) const;
51 };
52 
53 class SW_DLLPUBLIC SwRedlineExtraData_FormatColl final : public SwRedlineExtraData
54 {
55     OUString m_sFormatNm;
56     std::unique_ptr<SfxItemSet> m_pSet;
57     sal_uInt16 m_nPoolId;
58     bool m_bFormatAll; // don't strip the last paragraph mark
59 public:
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;
66 
GetFormatName() const67     const OUString& GetFormatName() const        { return m_sFormatNm; }
68     void SetItemSet( const SfxItemSet& rSet );
GetItemSet() const69     SfxItemSet* GetItemSet( ) const { return m_pSet.get(); }
SetFormatAll(bool bAll)70     void SetFormatAll( bool bAll )               { m_bFormatAll = bAll; }
71 };
72 
73 class SwRedlineExtraData_Format final : public SwRedlineExtraData
74 {
75     std::vector<sal_uInt16> m_aWhichIds;
76 
77     SwRedlineExtraData_Format( const SwRedlineExtraData_Format& rCpy );
78 
79 public:
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;
85 };
86 
87 class SW_DLLPUBLIC SwRedlineData
88 {
89     friend class SwRangeRedline;
90     SwRedlineData* m_pNext;       // Points to other data.
91     SwRedlineExtraData* m_pExtraData;
92 
93     OUString m_sComment;
94     DateTime m_aStamp;
95     RedlineType m_eType;
96     bool m_bAutoFormat;
97     std::size_t const m_nAuthor;
98     sal_uInt16 m_nSeqNo;
99 
100 public:
101     SwRedlineData( RedlineType eT, std::size_t nAut );
102     SwRedlineData( const SwRedlineData& rCpy, bool bCpyNext = true );
103 
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 );
107 
108     ~SwRedlineData();
109 
operator ==(const SwRedlineData & rCmp) const110     bool operator==( const SwRedlineData& rCmp ) const
111         {
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 ));
121         }
operator !=(const SwRedlineData & rCmp) const122     bool operator!=( const SwRedlineData& rCmp ) const
123         {   return !operator==( rCmp ); }
124 
GetType() const125     RedlineType GetType() const { return m_eType; }
126 
GetAuthor() const127     std::size_t GetAuthor() const                { return m_nAuthor; }
GetComment() const128     const OUString& GetComment() const        { return m_sComment; }
GetTimeStamp() const129     const DateTime& GetTimeStamp() const    { return m_aStamp; }
Next() const130     const SwRedlineData* Next() const{ return m_pNext; }
131 
SetComment(const OUString & rS)132     void SetComment( const OUString& rS )     { m_sComment = rS; }
SetTimeStamp(const DateTime & rDT)133     void SetTimeStamp( const DateTime& rDT ) { m_aStamp = rDT; }
134 
SetAutoFormat()135     void SetAutoFormat() { m_bAutoFormat = true; }
IsAutoFormat() const136     bool IsAutoFormat() const { return m_bAutoFormat; }
137     bool CanCombine( const SwRedlineData& rCmp ) const;
138 
139     // ExtraData gets copied, the pointer is therefore not taken over by
140     // the RedlineObject
141     void SetExtraData( const SwRedlineExtraData* pData );
GetExtraData() const142     const SwRedlineExtraData* GetExtraData() const { return m_pExtraData; }
143 
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!
GetSeqNo() const147     sal_uInt16 GetSeqNo() const                     { return m_nSeqNo; }
SetSeqNo(sal_uInt16 nNo)148     void SetSeqNo( sal_uInt16 nNo )                 { m_nSeqNo = nNo; }
149 
150     OUString GetDescr() const;
151 };
152 
153 class SW_DLLPUBLIC SwRangeRedline : public SwPaM
154 {
155     SwRedlineData* m_pRedlineData;
156     SwNodeIndex* m_pContentSect;
157     bool m_bDelLastPara : 1;
158     bool m_bIsVisible : 1;
159     sal_uInt32 const m_nId;
160 
161     boost::optional<long> m_oLOKLastNodeTop;
162 
163     void MoveToSection();
164     void CopyToSection();
165     void DelCopyOfSection(size_t nMyPos);
166     void MoveFromSection(size_t nMyPos);
167 
168 public:
169     static sal_uInt32 m_nLastId;
170 
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!
SwRangeRedline(SwRedlineData * pData,const SwPosition & rPos,bool bDelLP)175     SwRangeRedline(SwRedlineData* pData, const SwPosition& rPos,
176                bool bDelLP) :
177         SwPaM( rPos ), m_pRedlineData( pData ), m_pContentSect( nullptr ),
178         m_bDelLastPara( bDelLP ), m_bIsVisible( true ), m_nId( m_nLastId++ )
179     {}
180     SwRangeRedline( const SwRangeRedline& );
181     virtual ~SwRangeRedline() override;
182 
GetId() const183     sal_uInt32 GetId() const { return m_nId; }
GetContentIdx() const184     SwNodeIndex* GetContentIdx() const { return m_pContentSect; }
185     // For Undo.
186     void SetContentIdx( const SwNodeIndex* );
187 
IsVisible() const188     bool IsVisible() const { return m_bIsVisible; }
IsDelLastPara() const189     bool IsDelLastPara() const { return m_bDelLastPara; }
190 
191     void SetStart( const SwPosition& rPos, SwPosition* pSttPtr = nullptr );
192     void SetEnd( const SwPosition& rPos, SwPosition* pEndPtr = nullptr );
193 
194     /// Do we have a valid selection?
195     bool HasValidRange() const;
196 
197     const SwRedlineData& GetRedlineData(sal_uInt16 nPos = 0) const;
operator !=(const SwRedlineData & rCmp) const198     bool operator!=( const SwRedlineData& rCmp ) const
199         { return *m_pRedlineData != rCmp; }
SetAutoFormat()200     void SetAutoFormat() { m_pRedlineData->SetAutoFormat(); }
IsAutoFormat() const201     bool IsAutoFormat() const { return m_pRedlineData->IsAutoFormat(); }
202 
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;
209 
SetComment(const OUString & rS)210     void SetComment( const OUString& rS ) { m_pRedlineData->SetComment( rS ); }
211 
212     /** ExtraData gets copied, the pointer is therefore not taken over by
213      *  the RedLineObject.*/
SetExtraData(const SwRedlineExtraData * pData)214     void SetExtraData( const SwRedlineExtraData* pData )
215         { m_pRedlineData->SetExtraData( pData ); }
GetExtraData() const216     const SwRedlineExtraData* GetExtraData() const
217         { return m_pRedlineData->GetExtraData(); }
218 
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!
GetSeqNo() const222     sal_uInt16 GetSeqNo() const             { return m_pRedlineData->GetSeqNo(); }
SetSeqNo(sal_uInt16 nNo)223     void SetSeqNo( sal_uInt16 nNo )         { m_pRedlineData->SetSeqNo( nNo ); }
224 
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);
233 
234     /// Calculates the intersection with text node number nNdIdx.
235     void CalcStartEnd(sal_uLong nNdIdx, sal_Int32& rStart, sal_Int32& rEnd) const;
236 
237     enum class Invalidation { Add, Remove };
238     /// Initiate the layout.
239     void InvalidateRange(Invalidation);
240 
IsOwnRedline(const SwRangeRedline & rRedl) const241     bool IsOwnRedline( const SwRangeRedline& rRedl ) const
242         { return GetAuthor() == rRedl.GetAuthor(); }
243     bool CanCombine( const SwRangeRedline& rRedl ) const;
244 
245     void PushData( const SwRangeRedline& rRedl, bool bOwnAsNext = true );
246     bool PopData();
247 
248     /**
249        Returns textual description of a redline data element of
250        this redline.
251 
252        The textual description of the selected element contains the
253        kind of redline and the possibly shortened text of the redline.
254 
255        @return textual description of the selected redline data element
256      */
257     OUString GetDescr();
258 
259     bool operator<( const SwRangeRedline& ) const;
260     void dumpAsXml(xmlTextWriterPtr pWriter) const;
261 
262     void MaybeNotifyRedlinePositionModification(long nTop);
263 };
264 
265 void MaybeNotifyRedlineModification(SwRangeRedline* pRedline, SwDoc* pDoc);
266 
267 /// Base object for 'Redlines' that are not of 'Ranged' type (like table row insert\delete)
268 class SW_DLLPUBLIC SwExtraRedline
269 {
270 private:
271     SwExtraRedline(SwExtraRedline const&) = delete;
272     SwExtraRedline& operator=(SwExtraRedline const&) = delete;
273 public:
274     SwExtraRedline() = default;
275     virtual ~SwExtraRedline();
276 };
277 
278 /// Redline that holds information about a table-row that had some change
279 class SW_DLLPUBLIC SwTableRowRedline : public SwExtraRedline
280 {
281 private:
282     SwRedlineData m_aRedlineData;
283     const SwTableLine& m_rTableLine;
284 
285 public:
286     SwTableRowRedline(const SwRedlineData& rData, const SwTableLine& rTableLine);
287     virtual ~SwTableRowRedline() override;
288 
289     /** ExtraData gets copied, the pointer is therefore not taken over by
290      *  the RedLineObject.*/
SetExtraData(const SwRedlineExtraData * pData)291     void SetExtraData( const SwRedlineExtraData* pData )
292         { m_aRedlineData.SetExtraData( pData ); }
GetTableLine() const293     const SwTableLine& GetTableLine() const
294         { return m_rTableLine; }
GetRedlineData() const295     const SwRedlineData& GetRedlineData() const
296         { return m_aRedlineData; }
297 };
298 
299 /// Redline that holds information about a table-cell that had some change
300 class SW_DLLPUBLIC SwTableCellRedline : public SwExtraRedline
301 {
302 private:
303     SwRedlineData m_aRedlineData;
304     const SwTableBox& m_rTableBox;
305 
306 public:
307     SwTableCellRedline(const SwRedlineData& rData, const SwTableBox& rTableBox);
308     virtual ~SwTableCellRedline() override;
309 
310     /** ExtraData gets copied, the pointer is therefore not taken over by
311      *  the RedLineObject.*/
SetExtraData(const SwRedlineExtraData * pData)312     void SetExtraData( const SwRedlineExtraData* pData )
313         { m_aRedlineData.SetExtraData( pData ); }
GetTableBox() const314     const SwTableBox& GetTableBox() const
315         { return m_rTableBox; }
GetRedlineData() const316     const SwRedlineData& GetRedlineData() const
317         { return m_aRedlineData; }
318 };
319 
320 class SW_DLLPUBLIC SwRedlineHint final : public SfxHint
321 {
322 };
323 
324 
325 namespace sw {
326 
327 std::vector<SwRangeRedline*> GetAllValidRanges(std::unique_ptr<SwRangeRedline> p);
328 
329 } // namespace sw
330 
331 #endif
332 
333 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
334