summaryrefslogtreecommitdiffstats
path: root/sw/inc/redline.hxx
blob: 0399ad153084d4313971bafd3232777903584013 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */
#ifndef INCLUDED_SW_INC_REDLINE_HXX
#define INCLUDED_SW_INC_REDLINE_HXX

#include <svx/ctredlin.hxx>
#include <tools/datetime.hxx>
#include <rtl/ustring.hxx>

#include "pam.hxx"

#include <cstddef>
#include <memory>
#include <vector>
#include <optional>


class SfxItemSet;

class SW_DLLPUBLIC SwRedlineExtraData
{
    SwRedlineExtraData( const SwRedlineExtraData& ) = delete;
    SwRedlineExtraData& operator=( const SwRedlineExtraData& ) = delete;

protected:
    SwRedlineExtraData() {}

public:
    virtual ~SwRedlineExtraData();
    virtual SwRedlineExtraData* CreateNew() const = 0;

    virtual void Reject( SwPaM& rPam ) const;
    virtual bool operator == ( const SwRedlineExtraData& ) const;
};

class SW_DLLPUBLIC SwRedlineExtraData_FormatColl final : public SwRedlineExtraData
{
    OUString m_sFormatNm;
    std::unique_ptr<SfxItemSet> m_pSet;
    sal_uInt16 m_nPoolId;
    bool m_bFormatAll; // don't strip the last paragraph mark
public:
    SwRedlineExtraData_FormatColl( const OUString& rColl, sal_uInt16 nPoolFormatId,
                                const SfxItemSet* pSet = nullptr, bool bFormatAll = true );
    virtual ~SwRedlineExtraData_FormatColl() override;
    virtual SwRedlineExtraData* CreateNew() const override;
    virtual void Reject( SwPaM& rPam ) const override;
    virtual bool operator == ( const SwRedlineExtraData& ) const override;

    const OUString& GetFormatName() const        { return m_sFormatNm; }
    void SetItemSet( const SfxItemSet& rSet );
    SfxItemSet* GetItemSet( ) const { return m_pSet.get(); }
    void SetFormatAll( bool bAll )               { m_bFormatAll = bAll; }
};

class SwRedlineExtraData_Format final : public SwRedlineExtraData
{
    std::vector<sal_uInt16> m_aWhichIds;

    SwRedlineExtraData_Format( const SwRedlineExtraData_Format& rCpy );

public:
    SwRedlineExtraData_Format( const SfxItemSet& rSet );
    virtual ~SwRedlineExtraData_Format() override;
    virtual SwRedlineExtraData* CreateNew() const override;
    virtual void Reject( SwPaM& rPam ) const override;
    virtual bool operator == ( const SwRedlineExtraData& ) const override;
};

class SW_DLLPUBLIC SwRedlineData
{
    friend class SwRangeRedline;
    SwRedlineData* m_pNext;       // Points to other data.
    SwRedlineExtraData* m_pExtraData;

    OUString m_sComment;
    DateTime m_aStamp;
    std::size_t m_nAuthor;
    RedlineType m_eType;
    sal_uInt16 m_nSeqNo;
    bool m_bAutoFormat;
    bool m_bMoved;

public:
    SwRedlineData( RedlineType eT, std::size_t nAut );
    SwRedlineData( const SwRedlineData& rCpy, bool bCpyNext = true );

    // For sw3io: pNext/pExtraData are taken over.
    SwRedlineData( RedlineType eT, std::size_t nAut, const DateTime& rDT,
                   const OUString& rCmnt, SwRedlineData* pNxt );

    ~SwRedlineData();

    bool operator==( const SwRedlineData& rCmp ) const
        {
            return m_nAuthor == rCmp.m_nAuthor &&
                    m_eType == rCmp.m_eType &&
                    m_bAutoFormat == rCmp.m_bAutoFormat &&
                    m_bMoved == rCmp.m_bMoved &&
                    m_sComment == rCmp.m_sComment &&
                    (( !m_pNext && !rCmp.m_pNext ) ||
                        ( m_pNext && rCmp.m_pNext && *m_pNext == *rCmp.m_pNext )) &&
                    (( !m_pExtraData && !rCmp.m_pExtraData ) ||
                        ( m_pExtraData && rCmp.m_pExtraData &&
                            *m_pExtraData == *rCmp.m_pExtraData ));
        }
    bool operator!=( const SwRedlineData& rCmp ) const
        {   return !operator==( rCmp ); }

    RedlineType GetType() const { return m_eType; }

    std::size_t GetAuthor() const                { return m_nAuthor; }
    const OUString& GetComment() const        { return m_sComment; }
    const DateTime& GetTimeStamp() const    { return m_aStamp; }
    bool IsAnonymized() const
        {
            return m_aStamp.GetYear() == 1970 &&
                    m_aStamp.GetMonth() == 1 && m_aStamp.GetDay() == 1;
        }

    const SwRedlineData* Next() const{ return m_pNext; }

    void SetComment( const OUString& rS )     { m_sComment = rS; }
    void SetTimeStamp( const DateTime& rDT ) { m_aStamp = rDT; }

    void SetAutoFormat() { m_bAutoFormat = true; }
    bool IsAutoFormat() const { return m_bAutoFormat; }
    void SetMoved() { m_bMoved = true; }
    bool IsMoved() const { return m_bMoved; }
    bool CanCombine( const SwRedlineData& rCmp ) const;

    // ExtraData gets copied, the pointer is therefore not taken over by
    // the RedlineObject
    void SetExtraData( const SwRedlineExtraData* pData );
    const SwRedlineExtraData* GetExtraData() const { return m_pExtraData; }

    // For UI-side pooling of Redline-actions.
    // At the moment only used for Autoformat with Redline.
    // Value != 0 means there can be others!
    sal_uInt16 GetSeqNo() const                     { return m_nSeqNo; }
    void SetSeqNo( sal_uInt16 nNo )                 { m_nSeqNo = nNo; }

    OUString GetDescr() const;
};

class SW_DLLPUBLIC SwRangeRedline final : public SwPaM
{
    SwRedlineData* m_pRedlineData;
    SwNodeIndex* m_pContentSect;
    bool m_bDelLastPara : 1;
    bool m_bIsVisible : 1;
    sal_uInt32 m_nId;

    std::optional<tools::Long> m_oLOKLastNodeTop;

    void MoveToSection();
    void CopyToSection();
    void DelCopyOfSection(size_t nMyPos);
    void MoveFromSection(size_t nMyPos);

public:
    static sal_uInt32 s_nLastId;

    SwRangeRedline( RedlineType eType, const SwPaM& rPam );
    SwRangeRedline( const SwRedlineData& rData, const SwPaM& rPam );
    SwRangeRedline( const SwRedlineData& rData, const SwPosition& rPos );
    // For sw3io: pData is taken over!
    SwRangeRedline(SwRedlineData* pData, const SwPosition& rPos,
               bool bDelLP) :
        SwPaM( rPos ), m_pRedlineData( pData ), m_pContentSect( nullptr ),
        m_bDelLastPara( bDelLP ), m_bIsVisible( true ), m_nId( s_nLastId++ )
    {}
    SwRangeRedline( const SwRangeRedline& );
    virtual ~SwRangeRedline() override;

    sal_uInt32 GetId() const { return m_nId; }
    SwNodeIndex* GetContentIdx() const { return m_pContentSect; }
    // For Undo.
    void SetContentIdx( const SwNodeIndex* );

    bool IsVisible() const { return m_bIsVisible; }
    bool IsDelLastPara() const { return m_bDelLastPara; }

    void SetStart( const SwPosition& rPos, SwPosition* pSttPtr = nullptr );
    void SetEnd( const SwPosition& rPos, SwPosition* pEndPtr = nullptr );

    /// Do we have a valid selection?
    bool HasValidRange() const;

    const SwRedlineData& GetRedlineData(sal_uInt16 nPos = 0) const;
    bool operator!=( const SwRedlineData& rCmp ) const
        { return *m_pRedlineData != rCmp; }
    void SetAutoFormat() { m_pRedlineData->SetAutoFormat(); }
    bool IsAutoFormat() const { return m_pRedlineData->IsAutoFormat(); }

    sal_uInt16 GetStackCount() const;
    std::size_t GetAuthor( sal_uInt16 nPos = 0) const;
    OUString const & GetAuthorString( sal_uInt16 nPos = 0 ) const;
    const DateTime& GetTimeStamp( sal_uInt16 nPos = 0) const;
    RedlineType GetType( sal_uInt16 nPos = 0 ) const;
    // text content of the redline is only an annotation placeholder
    // (i.e. a comment, but don't confuse it with comment of the redline)
    bool IsAnnotation() const;
    const OUString& GetComment( sal_uInt16 nPos = 0 ) const;

    void SetComment( const OUString& rS ) { m_pRedlineData->SetComment( rS ); }

    /** ExtraData gets copied, the pointer is therefore not taken over by
     *  the RedLineObject.*/
    void SetExtraData( const SwRedlineExtraData* pData )
        { m_pRedlineData->SetExtraData( pData ); }
    const SwRedlineExtraData* GetExtraData() const
        { return m_pRedlineData->GetExtraData(); }

    // For UI-side pooling of Redline-actions.
    // At the moment only used for Autoformat with Redline.
    // Value != 0 means there can be others!
    sal_uInt16 GetSeqNo() const             { return m_pRedlineData->GetSeqNo(); }
    void SetSeqNo( sal_uInt16 nNo )         { m_pRedlineData->SetSeqNo( nNo ); }

    // At Hide/ShowOriginal the list is traversed two times in order to
    // hide the Del-Redlines via Copy and Delete.
    // Otherwise at Move the attribution would be handled incorrectly.
    // All other callers must always give 0.
    void CallDisplayFunc(size_t nMyPos);
    void Show(sal_uInt16 nLoop , size_t nMyPos, bool bForced = false);
    void Hide(sal_uInt16 nLoop , size_t nMyPos, bool bForced = false);
    void ShowOriginal(sal_uInt16 nLoop, size_t nMyPos, bool bForced = false);

    /// Calculates the intersection with text node number nNdIdx.
    void CalcStartEnd(SwNodeOffset nNdIdx, sal_Int32& rStart, sal_Int32& rEnd) const;

    enum class Invalidation { Add, Remove };
    /// Initiate the layout.
    void InvalidateRange(Invalidation);

    bool IsOwnRedline( const SwRangeRedline& rRedl ) const
        { return GetAuthor() == rRedl.GetAuthor(); }
    bool CanCombine( const SwRangeRedline& rRedl ) const;

    void PushData( const SwRangeRedline& rRedl, bool bOwnAsNext = true );
    bool PopData();

    /**
       Returns textual description of a redline data element of
       this redline.

       The textual description of the selected element contains the
       kind of redline and the possibly shortened text of the redline.

       @return textual description of the selected redline data element

       bSimplified = simplified shortened text to show deletions on margin
     */
    OUString GetDescr(bool bSimplified = false);

    bool operator<( const SwRangeRedline& ) const;
    void dumpAsXml(xmlTextWriterPtr pWriter) const;

    void MaybeNotifyRedlinePositionModification(tools::Long nTop);

    void SetMoved() {  m_pRedlineData->SetMoved(); }
    bool IsMoved() const { return m_pRedlineData->IsMoved(); }
};

void MaybeNotifyRedlineModification(SwRangeRedline& rRedline, SwDoc& rDoc);

/// Base object for 'Redlines' that are not of 'Ranged' type (like table row insert\delete)
class SW_DLLPUBLIC SwExtraRedline
{
private:
    SwExtraRedline(SwExtraRedline const&) = delete;
    SwExtraRedline& operator=(SwExtraRedline const&) = delete;
public:
    SwExtraRedline() = default;
    virtual ~SwExtraRedline();
};

/// Redline that holds information about a table-row that had some change
class SW_DLLPUBLIC SwTableRowRedline final : public SwExtraRedline
{
private:
    SwRedlineData m_aRedlineData;
    const SwTableLine& m_rTableLine;

public:
    SwTableRowRedline(const SwRedlineData& rData, const SwTableLine& rTableLine);
    virtual ~SwTableRowRedline() override;

    /** ExtraData gets copied, the pointer is therefore not taken over by
     *  the RedLineObject.*/
    void SetExtraData( const SwRedlineExtraData* pData )
        { m_aRedlineData.SetExtraData( pData ); }
    const SwTableLine& GetTableLine() const
        { return m_rTableLine; }
    const SwRedlineData& GetRedlineData() const
        { return m_aRedlineData; }
};

/// Redline that holds information about a table-cell that had some change
class SW_DLLPUBLIC SwTableCellRedline final : public SwExtraRedline
{
private:
    SwRedlineData m_aRedlineData;
    const SwTableBox& m_rTableBox;

public:
    SwTableCellRedline(const SwRedlineData& rData, const SwTableBox& rTableBox);
    virtual ~SwTableCellRedline() override;

    /** ExtraData gets copied, the pointer is therefore not taken over by
     *  the RedLineObject.*/
    void SetExtraData( const SwRedlineExtraData* pData )
        { m_aRedlineData.SetExtraData( pData ); }
    const SwTableBox& GetTableBox() const
        { return m_rTableBox; }
    const SwRedlineData& GetRedlineData() const
        { return m_aRedlineData; }
};

class SW_DLLPUBLIC SwRedlineHint final : public SfxHint
{
};


namespace sw {

std::vector<SwRangeRedline*> GetAllValidRanges(std::unique_ptr<SwRangeRedline> p);

} // namespace sw

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */