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