Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/sc/source/ui/inc/undobase.hxx
Line
Count
Source (jump to first uncovered line)
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
20
#pragma once
21
22
#include <svl/undo.hxx>
23
#include <address.hxx>
24
#include "docsh.hxx"
25
26
#include <memory>
27
#include <map>
28
#include <optional>
29
30
class SdrUndoAction;
31
class ScRefUndoData;
32
class ScDBData;
33
34
class SAL_DLLPUBLIC_RTTI ScSimpleUndo: public SfxUndoAction
35
{
36
    ScSimpleUndo(const ScSimpleUndo&) = delete;
37
38
public:
39
    typedef std::map<SCTAB, std::unique_ptr<sc::ColumnSpanSet>> DataSpansType;
40
41
                    ScSimpleUndo( ScDocShell& rDocSh );
42
43
    virtual bool    Merge( SfxUndoAction *pNextAction ) override;
44
    /// See SfxUndoAction::GetViewShellId().
45
    ViewShellId GetViewShellId() const override;
46
47
0
    virtual std::optional<ScRange> getAffectedRange() const { return std::nullopt; }
48
49
protected:
50
    ScDocShell&     rDocShell;
51
    std::unique_ptr<SfxUndoAction>
52
                    pDetectiveUndo;
53
    ViewShellId     mnViewShellId;
54
55
0
    bool            IsPaintLocked() const { return rDocShell.IsPaintLocked(); }
56
57
    bool            SetViewMarkData( const ScMarkData& rMarkData );
58
59
    void            BeginUndo();
60
    void            EndUndo();
61
    void            BeginRedo();
62
    void            EndRedo();
63
64
    void BroadcastChanges( const ScRange& rRange );
65
66
    /**
67
     * Broadcast changes on specified spans.
68
     *
69
     * @param rSpans container that specifies all spans whose changes need to
70
     *               be broadcasted.
71
     */
72
    void BroadcastChanges( const DataSpansType& rSpans );
73
74
    static void     ShowTable( SCTAB nTab );
75
    static void     ShowTable( const ScRange& rRange );
76
};
77
78
enum ScBlockUndoMode { SC_UNDO_SIMPLE, SC_UNDO_MANUALHEIGHT, SC_UNDO_AUTOHEIGHT };
79
80
class ScBlockUndo: public ScSimpleUndo
81
{
82
public:
83
                    ScBlockUndo( ScDocShell& rDocSh, const ScRange& rRange,
84
                                 ScBlockUndoMode eBlockMode );
85
    virtual         ~ScBlockUndo() override;
86
87
0
    virtual std::optional<ScRange> getAffectedRange() const override { return aBlockRange; }
88
89
protected:
90
    ScRange         aBlockRange;
91
    std::unique_ptr<SdrUndoAction> pDrawUndo;
92
    ScBlockUndoMode eMode;
93
94
    void            BeginUndo();
95
    void            EndUndo();
96
//  void            BeginRedo();
97
    void            EndRedo();
98
99
    bool            AdjustHeight();
100
    void            ShowBlock();
101
};
102
103
class SC_DLLPUBLIC ScMultiBlockUndo: public ScSimpleUndo
104
{
105
public:
106
    ScMultiBlockUndo(ScDocShell& rDocSh, ScRangeList aRanges);
107
    virtual ~ScMultiBlockUndo() override;
108
109
protected:
110
    ScRangeList     maBlockRanges;
111
    std::unique_ptr<SdrUndoAction> mpDrawUndo;
112
113
    void BeginUndo();
114
    void EndUndo();
115
    void EndRedo();
116
117
    void ShowBlock();
118
};
119
120
// for functions that act on a database range - takes care of the unnamed database range
121
// (collected separately, before the undo action, for showing dialogs etc.)
122
123
class ScDBFuncUndo: public ScSimpleUndo
124
{
125
protected:
126
    std::unique_ptr<ScDBData> pAutoDBRange;
127
    ScRange         aOriginalRange;
128
129
public:
130
                    ScDBFuncUndo( ScDocShell& rDocSh, const ScRange& rOriginal );
131
    virtual         ~ScDBFuncUndo() override;
132
133
    void            BeginUndo();
134
    void            EndUndo();
135
    void            BeginRedo();
136
    void            EndRedo();
137
};
138
139
class ScMoveUndo: public ScSimpleUndo               // with references
140
{
141
public:
142
                    ScMoveUndo( ScDocShell& rDocSh,
143
                                ScDocumentUniquePtr pRefDoc, std::unique_ptr<ScRefUndoData> pRefData );
144
    virtual         ~ScMoveUndo() override;
145
146
protected:
147
    std::unique_ptr<SdrUndoAction>  pDrawUndo;
148
    ScDocumentUniquePtr             pRefUndoDoc;
149
    std::unique_ptr<ScRefUndoData>  pRefUndoData;
150
151
    void            BeginUndo();
152
    void            EndUndo();
153
//  void            BeginRedo();
154
//  void            EndRedo();
155
156
private:
157
    void            UndoRef();
158
};
159
160
class ScUndoWrapper: public SfxUndoAction           // for manual merging of actions
161
{
162
    std::unique_ptr<SfxUndoAction>  pWrappedUndo;
163
    ViewShellId                     mnViewShellId;
164
165
public:
166
                            ScUndoWrapper( std::unique_ptr<SfxUndoAction> pUndo );
167
    virtual                 ~ScUndoWrapper() override;
168
169
0
    SfxUndoAction*          GetWrappedUndo()        { return pWrappedUndo.get(); }
170
0
    std::unique_ptr<SfxUndoAction> ReleaseWrappedUndo() { return std::move(pWrappedUndo); }
171
172
    virtual void            Undo() override;
173
    virtual void            Redo() override;
174
    virtual void            Repeat(SfxRepeatTarget& rTarget) override;
175
    virtual bool            CanRepeat(SfxRepeatTarget& rTarget) const override;
176
    virtual bool            Merge( SfxUndoAction *pNextAction ) override;
177
    virtual OUString        GetComment() const override;
178
    virtual OUString        GetRepeatComment(SfxRepeatTarget&) const override;
179
    /// See SfxUndoAction::GetViewShellId().
180
    ViewShellId GetViewShellId() const override;
181
};
182
183
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */