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 #ifndef INCLUDED_SC_SOURCE_UI_INC_UNDOCELL_HXX 21 #define INCLUDED_SC_SOURCE_UI_INC_UNDOCELL_HXX 22 23 #include "undobase.hxx" 24 #include <detdata.hxx> 25 #include <postit.hxx> 26 #include <cellvalue.hxx> 27 #include <cellvalues.hxx> 28 #include <editeng/editobj.hxx> 29 30 #include <memory> 31 32 class ScDocShell; 33 class ScPatternAttr; 34 class ScRangeName; 35 class ScFormulaCell; 36 37 class ScUndoCursorAttr: public ScSimpleUndo 38 { 39 public: 40 ScUndoCursorAttr( ScDocShell* pNewDocShell, 41 SCCOL nNewCol, SCROW nNewRow, SCTAB nNewTab, 42 const ScPatternAttr* pOldPat, const ScPatternAttr* pNewPat, 43 const ScPatternAttr* pApplyPat ); 44 virtual ~ScUndoCursorAttr() override; 45 46 virtual void Undo() override; 47 virtual void Redo() override; 48 virtual void Repeat(SfxRepeatTarget& rTarget) override; 49 virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override; 50 51 virtual OUString GetComment() const override; 52 53 /** once the objects are passed to this class, their life-cycle is 54 managed by this class; the calling function must pass new'ed 55 objects to this method. */ 56 void SetEditData( std::unique_ptr<EditTextObject> pOld, std::unique_ptr<EditTextObject> pNew ); 57 58 private: 59 SCCOL const nCol; 60 SCROW const nRow; 61 SCTAB const nTab; 62 ScPatternAttr* pOldPattern; 63 ScPatternAttr* pNewPattern; 64 ScPatternAttr* pApplyPattern; 65 std::unique_ptr<EditTextObject> pOldEditData; 66 std::unique_ptr<EditTextObject> pNewEditData; 67 68 void DoChange( const ScPatternAttr* pWhichPattern, const std::unique_ptr<EditTextObject>& pEditData ) const; 69 }; 70 71 class ScUndoEnterData: public ScSimpleUndo 72 { 73 public: 74 75 struct Value 76 { 77 SCTAB mnTab; 78 bool mbHasFormat; 79 sal_uInt32 mnFormat; 80 ScCellValue maCell; 81 82 Value(); 83 }; 84 85 typedef std::vector<Value> ValuesType; 86 87 ScUndoEnterData( 88 ScDocShell* pNewDocShell, const ScAddress& rPos, 89 ValuesType& rOldValues, const OUString& rNewStr, std::unique_ptr<EditTextObject> pObj ); 90 91 virtual void Undo() override; 92 virtual void Redo() override; 93 virtual void Repeat(SfxRepeatTarget& rTarget) override; 94 virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override; 95 96 virtual OUString GetComment() const override; 97 98 private: 99 ValuesType maOldValues; 100 101 OUString const maNewString; 102 std::unique_ptr<EditTextObject> mpNewEditData; 103 sal_uLong mnEndChangeAction; 104 ScAddress const maPos; 105 106 void DoChange() const; 107 void SetChangeTrack(); 108 }; 109 110 class ScUndoEnterValue: public ScSimpleUndo 111 { 112 public: 113 ScUndoEnterValue( 114 ScDocShell* pNewDocShell, const ScAddress& rNewPos, 115 const ScCellValue& rUndoCell, double nVal ); 116 117 virtual ~ScUndoEnterValue() override; 118 119 virtual void Undo() override; 120 virtual void Redo() override; 121 virtual void Repeat(SfxRepeatTarget& rTarget) override; 122 virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override; 123 124 virtual OUString GetComment() const override; 125 126 private: 127 ScAddress const aPos; 128 ScCellValue const maOldCell; 129 double const nValue; 130 sal_uLong nEndChangeAction; 131 132 void SetChangeTrack(); 133 }; 134 135 class ScUndoSetCell : public ScSimpleUndo 136 { 137 public: 138 ScUndoSetCell( ScDocShell* pDocSh, const ScAddress& rPos, const ScCellValue& rOldVal, const ScCellValue& rNewVal ); 139 140 virtual ~ScUndoSetCell() override; 141 142 virtual void Undo() override; 143 virtual void Redo() override; 144 virtual void Repeat( SfxRepeatTarget& rTarget ) override; 145 virtual bool CanRepeat( SfxRepeatTarget& rTarget ) const override; 146 virtual OUString GetComment() const override; 147 148 private: 149 void SetChangeTrack(); 150 void SetValue( const ScCellValue& rVal ); 151 void MoveCursorToCell(); 152 153 private: 154 ScAddress const maPos; 155 ScCellValue const maOldValue; 156 ScCellValue const maNewValue; 157 sal_uLong mnEndChangeAction; 158 }; 159 160 class ScUndoPageBreak: public ScSimpleUndo 161 { 162 public: 163 ScUndoPageBreak( ScDocShell* pNewDocShell, 164 SCCOL nNewCol, SCROW nNewRow, SCTAB nNewTab, 165 bool bNewColumn, bool bNewInsert ); 166 virtual ~ScUndoPageBreak() override; 167 168 virtual void Undo() override; 169 virtual void Redo() override; 170 virtual void Repeat(SfxRepeatTarget& rTarget) override; 171 virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override; 172 173 virtual OUString GetComment() const override; 174 175 private: 176 SCCOL const nCol; 177 SCROW const nRow; 178 SCTAB const nTab; 179 bool const bColumn; // Column or row break 180 bool const bInsert; // Insert or Delete 181 182 void DoChange( bool bInsert ) const; 183 }; 184 185 class ScUndoPrintZoom: public ScSimpleUndo 186 { 187 public: 188 ScUndoPrintZoom( ScDocShell* pNewDocShell, SCTAB nT, 189 sal_uInt16 nOS, sal_uInt16 nOP, sal_uInt16 nNS, sal_uInt16 nNP ); 190 virtual ~ScUndoPrintZoom() override; 191 192 virtual void Undo() override; 193 virtual void Redo() override; 194 virtual void Repeat(SfxRepeatTarget& rTarget) override; 195 virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override; 196 197 virtual OUString GetComment() const override; 198 199 private: 200 SCTAB const nTab; 201 sal_uInt16 const nOldScale; 202 sal_uInt16 const nOldPages; 203 sal_uInt16 const nNewScale; 204 sal_uInt16 const nNewPages; 205 206 void DoChange( bool bUndo ); 207 }; 208 209 class ScUndoThesaurus: public ScSimpleUndo 210 { 211 public: 212 ScUndoThesaurus( ScDocShell* pNewDocShell, 213 SCCOL nNewCol, SCROW nNewRow, SCTAB nNewTab, 214 const ScCellValue& rOldText, const ScCellValue& rNewText ); 215 virtual ~ScUndoThesaurus() override; 216 217 virtual void Undo() override; 218 virtual void Redo() override; 219 virtual void Repeat(SfxRepeatTarget& rTarget) override; 220 virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override; 221 222 virtual OUString GetComment() const override; 223 224 private: 225 SCCOL const nCol; 226 SCROW const nRow; 227 SCTAB const nTab; 228 sal_uLong nEndChangeAction; 229 230 ScCellValue const maOldText; 231 ScCellValue const maNewText; 232 233 void DoChange( bool bUndo, const ScCellValue& rText ); 234 void SetChangeTrack( const ScCellValue& rOldCell ); 235 }; 236 237 /** Undo action for inserting, removing, and replacing a cell note. */ 238 class ScUndoReplaceNote : public ScSimpleUndo 239 { 240 public: 241 242 /** Constructs an undo action for inserting or removing a cell note. */ 243 ScUndoReplaceNote( 244 ScDocShell& rDocShell, 245 const ScAddress& rPos, 246 const ScNoteData& rNoteData, 247 bool bInsert, 248 std::unique_ptr<SdrUndoAction> pDrawUndo ); 249 250 /** Constructs an undo action for replacing a cell note with another. */ 251 ScUndoReplaceNote( 252 ScDocShell& rDocShell, 253 const ScAddress& rPos, 254 const ScNoteData& rOldData, 255 const ScNoteData& rNewData, 256 std::unique_ptr<SdrUndoAction> pDrawUndo ); 257 258 virtual ~ScUndoReplaceNote() override; 259 260 virtual void Undo() override; 261 virtual void Redo() override; 262 virtual void Repeat( SfxRepeatTarget& rTarget ) override; 263 virtual bool CanRepeat( SfxRepeatTarget& rTarget ) const override; 264 265 virtual OUString GetComment() const override; 266 267 private: 268 void DoInsertNote( const ScNoteData& rNoteData ); 269 void DoRemoveNote( const ScNoteData& rNoteData ); 270 271 private: 272 ScAddress const maPos; 273 ScNoteData maOldData; 274 ScNoteData maNewData; 275 std::unique_ptr<SdrUndoAction> mpDrawUndo; 276 }; 277 278 /** Undo action for showing or hiding a cell note caption. */ 279 class ScUndoShowHideNote : public ScSimpleUndo 280 { 281 public: 282 ScUndoShowHideNote( ScDocShell& rDocShell, const ScAddress& rPos, bool bShow ); 283 virtual ~ScUndoShowHideNote() override; 284 285 virtual void Undo() override; 286 virtual void Redo() override; 287 virtual void Repeat( SfxRepeatTarget& rTarget ) override; 288 virtual bool CanRepeat( SfxRepeatTarget& rTarget ) const override; 289 290 virtual OUString GetComment() const override; 291 292 private: 293 ScAddress const maPos; 294 bool const mbShown; 295 }; 296 297 class ScUndoDetective: public ScSimpleUndo 298 { 299 public: 300 ScUndoDetective( ScDocShell* pNewDocShell, 301 std::unique_ptr<SdrUndoAction> pDraw, const ScDetOpData* pOperation, 302 std::unique_ptr<ScDetOpList> pUndoList = nullptr ); 303 virtual ~ScUndoDetective() override; 304 305 virtual void Undo() override; 306 virtual void Redo() override; 307 virtual void Repeat(SfxRepeatTarget& rTarget) override; 308 virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override; 309 310 virtual OUString GetComment() const override; 311 312 private: 313 bool bIsDelete; 314 std::unique_ptr<ScDetOpList> pOldList; 315 sal_uInt16 nAction; 316 ScAddress aPos; 317 std::unique_ptr<SdrUndoAction> pDrawUndo; 318 }; 319 320 class ScUndoRangeNames: public ScSimpleUndo 321 { 322 public: 323 //use nTab = -1 for global range names 324 ScUndoRangeNames( ScDocShell* pNewDocShell, 325 std::unique_ptr<ScRangeName> pOld, std::unique_ptr<ScRangeName> pNew , SCTAB nTab); 326 virtual ~ScUndoRangeNames() override; 327 328 virtual void Undo() override; 329 virtual void Redo() override; 330 virtual void Repeat(SfxRepeatTarget& rTarget) override; 331 virtual bool CanRepeat(SfxRepeatTarget& rTarget) const override; 332 333 virtual OUString GetComment() const override; 334 335 private: 336 std::unique_ptr<ScRangeName> pOldRanges; 337 std::unique_ptr<ScRangeName> pNewRanges; 338 SCTAB const mnTab; 339 340 void DoChange( bool bUndo ); 341 }; 342 343 namespace sc { 344 345 class UndoSetCells : public ScSimpleUndo 346 { 347 ScAddress const maTopPos; 348 CellValues maOldValues; 349 CellValues maNewValues; 350 351 void DoChange( const CellValues& rValues ); 352 353 public: 354 UndoSetCells( ScDocShell* pDocSh, const ScAddress& rTopPos ); 355 virtual ~UndoSetCells() override; 356 357 virtual void Undo() override; 358 virtual void Redo() override; 359 360 virtual bool CanRepeat( SfxRepeatTarget& ) const override; 361 virtual OUString GetComment() const override; 362 GetOldValues()363 CellValues& GetOldValues() { return maOldValues;} 364 void SetNewValues( const std::vector<double>& rVals ); 365 void SetNewValues( const std::vector<ScFormulaCell*>& rVals ); 366 }; 367 368 } // namespace sc 369 370 #endif 371 372 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 373