kspread

kspread_undo.h
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef __kspread_undo_h__
21#define __kspread_undo_h__
22
23#include <tqptrstack.h>
24#include <tqstring.h>
25#include <tqrect.h>
26#include <tqptrlist.h>
27#include <tqvaluelist.h>
28#include <tqmap.h>
29
30#include <KoUnit.h>
31#include <KoPageLayout.h>
32
33#include "kspread_doc.h"
34#include "region.h"
35
36namespace KSpread
37{
38class ColumnFormat;
39class Doc;
40class Format;
41class Region;
42class RowFormat;
43class Sheet;
44class Undo;
45class UndoResizeColRow;
46
47struct rowSize {
48int rowNumber;
49double rowHeight;
50};
51
52struct columnSize {
53int columnNumber;
54double columnWidth;
55};
56
57struct textOfCell {
58int row;
59int col;
60TQString text;
61};
62
63struct layoutTextCell {
64int row;
65int col;
66Format * l;
67TQString text;
68};
69
70struct layoutCell {
71int row;
72int col;
73Format *l;
74};
75
76struct layoutColumn {
77int col;
78ColumnFormat *l;
79};
80
81struct layoutRow {
82int row;
83RowFormat *l;
84};
85
86struct styleCell {
87 int row;
88 int col;
89 TQString action;
90};
91
92class FormulaOfCell
93{
94public:
95 FormulaOfCell(): m_sheetName(0) {}
96 FormulaOfCell( TQString & sheetName, int col, int row, TQString & formula )
97 : m_sheetName( sheetName ), m_col( col ), m_row( row ), m_formula( formula )
98 {}
99
100 TQString sheetName() const { return m_sheetName; }
101 TQString formula() const { return m_formula; }
102 int col() const { return m_col; }
103 int row() const { return m_row; }
104
105private:
106 TQString m_sheetName;
107 int m_col;
108 int m_row;
109 TQString m_formula;
110};
111
116class UndoAction
117{
118public:
119 UndoAction( Doc *_doc ) { m_pDoc = _doc; m_pDoc->setModified(true); }
120 virtual ~UndoAction() { }
121
122 virtual void undo() = 0;
123 virtual void redo() = 0;
124
125 Doc* doc()const { return m_pDoc; }
126
127 TQString getName()const {return name ;}
128
129protected:
130 Doc *m_pDoc;
131 TQString name;
132};
133
134class MacroUndoAction : public UndoAction
135{
136public:
137 MacroUndoAction( Doc * _doc, const TQString & _name );
138 virtual ~MacroUndoAction();
139
140 void addCommand(UndoAction *command);
141
142 virtual void undo();
143 virtual void redo();
144
145protected:
146 TQPtrList<UndoAction> m_commands;
147};
148
149class UndoInsertRemoveAction : public UndoAction
150{
151public:
152 UndoInsertRemoveAction( Doc *_doc );
153 virtual ~UndoInsertRemoveAction();
154
155 void saveFormulaReference( Sheet *_sheet, int col, int row, TQString & formula );
156
157protected:
158 void undoFormulaReference();
159 TQValueList<FormulaOfCell> m_lstFormulaCells;
160};
161
162class UndoRemoveColumn : public UndoInsertRemoveAction
163{
164public:
165 UndoRemoveColumn( Doc *_doc, Sheet *_sheet, int _column,int _nbCol=0 );
166 virtual ~UndoRemoveColumn();
167
168 virtual void undo();
169 virtual void redo();
170
171protected:
172 TQString m_sheetName;
173 TQCString m_data;
174 int m_iColumn;
175 int m_iNbCol;
176 TQRect m_printRange;
177 TQPair<int, int> m_printRepeatColumns;
178};
179
180class UndoInsertColumn : public UndoInsertRemoveAction
181{
182public:
183 UndoInsertColumn( Doc *_doc, Sheet *_sheet, int _column,int _nbCol=0 );
184 virtual ~UndoInsertColumn();
185
186 virtual void undo();
187 virtual void redo();
188
189protected:
190 TQString m_sheetName;
191 int m_iColumn;
192 int m_iNbCol;
193};
194
195class UndoRemoveRow : public UndoInsertRemoveAction
196{
197public:
198 UndoRemoveRow( Doc *_doc, Sheet *_sheet, int _row,int _nbRow=0 );
199 virtual ~UndoRemoveRow();
200
201 virtual void undo();
202 virtual void redo();
203
204protected:
205 TQString m_sheetName;
206 TQCString m_data;
207 int m_iRow;
208 int m_iNbRow;
209 TQRect m_printRange;
210 TQPair<int, int> m_printRepeatRows;
211};
212
213class UndoInsertRow : public UndoInsertRemoveAction
214{
215public:
216 UndoInsertRow( Doc *_doc, Sheet *_sheet, int _row,int _nbRow=0 );
217 virtual ~UndoInsertRow();
218
219 virtual void undo();
220 virtual void redo();
221
222protected:
223 TQString m_sheetName;
224 int m_iRow;
225 int m_iNbRow;
226};
227
228
229class UndoHideColumn : public UndoAction
230{
231public:
232 UndoHideColumn( Doc *_doc, Sheet *_sheet, int _column,int _nbCol=0, TQValueList<int>listCol=TQValueList<int>() );
233 virtual ~UndoHideColumn();
234
235 virtual void undo();
236 virtual void redo();
237 void createList( TQValueList<int>&list,Sheet *_tab );
238
239protected:
240 TQString m_sheetName;
241 int m_iColumn;
242 int m_iNbCol;
243 TQValueList<int> listCol;
244};
245
246class UndoHideRow : public UndoAction
247{
248public:
249 UndoHideRow( Doc *_doc, Sheet *_sheet, int _column,int _nbCol=0, TQValueList<int>_listRow=TQValueList<int>() );
250 virtual ~UndoHideRow();
251
252 virtual void undo();
253 virtual void redo();
254protected:
255 void createList( TQValueList<int>&list,Sheet *_tab );
256
257 TQString m_sheetName;
258 int m_iRow;
259 int m_iNbRow;
260 TQValueList<int> listRow;
261};
262
263class UndoShowColumn : public UndoAction
264{
265public:
266 UndoShowColumn( Doc *_doc, Sheet *_sheet, int _column,int _nbCol=0, TQValueList<int>_list=TQValueList<int>() );
267 virtual ~UndoShowColumn();
268
269 virtual void undo();
270 virtual void redo();
271protected:
272 void createList( TQValueList<int>&list,Sheet *_tab );
273
274 TQString m_sheetName;
275 int m_iColumn;
276 int m_iNbCol;
277 TQValueList<int> listCol;
278};
279
280class UndoShowRow : public UndoAction
281{
282public:
283 UndoShowRow( Doc *_doc, Sheet *_sheet, int _column,int _nbCol=0, TQValueList<int>list=TQValueList<int>() );
284 virtual ~UndoShowRow();
285
286 virtual void undo();
287 virtual void redo();
288
289protected:
290 void createList( TQValueList<int>&list,Sheet *_tab );
291 TQString m_sheetName;
292 int m_iRow;
293 int m_iNbRow;
294 TQValueList<int> listRow;
295};
296
297
298class UndoPaperLayout : public UndoAction
299{
300public:
301 UndoPaperLayout( Doc *_doc, Sheet *_sheet );
302 virtual ~UndoPaperLayout();
303
304 virtual void undo();
305 virtual void redo();
306
307protected:
308 TQString m_sheetName;
309 KoPageLayout m_pl;
310 KoPageLayout m_plRedo;
311 KoHeadFoot m_hf;
312 KoHeadFoot m_hfRedo;
313 KoUnit::Unit m_unit;
314 KoUnit::Unit m_unitRedo;
315 bool m_printGrid;
316 bool m_printGridRedo;
317 bool m_printCommentIndicator;
318 bool m_printCommentIndicatorRedo;
319 bool m_printFormulaIndicator;
320 bool m_printFormulaIndicatorRedo;
321 TQRect m_printRange;
322 TQRect m_printRangeRedo;
323 TQPair<int, int> m_printRepeatColumns;
324 TQPair<int, int> m_printRepeatColumnsRedo;
325 TQPair<int, int> m_printRepeatRows;
326 TQPair<int, int> m_printRepeatRowsRedo;
327 double m_dZoom;
328 double m_dZoomRedo;
329 int m_iPageLimitX;
330 int m_iPageLimitXRedo;
331 int m_iPageLimitY;
332 int m_iPageLimitYRedo;
333};
334
335
336class UndoSetText : public UndoAction
337{
338public:
339 UndoSetText( Doc *_doc, Sheet *_sheet, const TQString& _text, int _column, int _row, FormatType _formatType );
340 virtual ~UndoSetText();
341
342 virtual void undo();
343 virtual void redo();
344
345protected:
346 TQString m_sheetName;
347 int m_iRow;
348 int m_iColumn;
349 TQString m_strText;
350 TQString m_strRedoText;
351 FormatType m_eFormatType;
352 FormatType m_eFormatTypeRedo;
353};
354
355class UndoCellFormat : public UndoAction
356{
357public:
358 UndoCellFormat( Doc *_doc, Sheet *_sheet, const Region &_selection, const TQString &_title );
359 virtual ~UndoCellFormat();
360
361 virtual void undo();
362 virtual void redo();
363
364protected:
365 void copyFormat( TQValueList<layoutCell> &list,TQValueList<layoutColumn> &listCol,TQValueList<layoutRow> &listRow, Sheet* sheet );
366
367 Region m_region;
368 TQValueList<layoutCell> m_lstFormats;
369 TQValueList<layoutCell> m_lstRedoFormats;
370 TQValueList<layoutColumn> m_lstColFormats;
371 TQValueList<layoutColumn> m_lstRedoColFormats;
372 TQValueList<layoutRow> m_lstRowFormats;
373 TQValueList<layoutRow> m_lstRedoRowFormats;
374
375 TQString m_sheetName;
376};
377
378class UndoChangeAngle : public UndoAction
379{
380public:
381 UndoChangeAngle( Doc *_doc, Sheet *_sheet, const Region &_selection );
382 virtual ~UndoChangeAngle();
383
384 virtual void undo();
385 virtual void redo();
386
387protected:
388
389 UndoCellFormat* m_layoutUndo;
390 UndoResizeColRow* m_resizeUndo;
391
392};
393
394class UndoDelete : public UndoAction
395{
396public:
397 UndoDelete(Doc *_doc, Sheet *_sheet, const Region& region);
398 virtual ~UndoDelete();
399
400 virtual void undo();
401 virtual void redo();
402
403protected:
404 void createListCell( TQCString &listCell,TQValueList<columnSize> &listCol,TQValueList<rowSize> &listRow, Sheet* sheet );
405
406 Region m_region;
407 TQCString m_data;
408 TQCString m_dataRedo;
409 TQValueList<columnSize> m_lstColumn;
410 TQValueList<columnSize> m_lstRedoColumn;
411 TQValueList<rowSize> m_lstRow;
412 TQValueList<rowSize> m_lstRedoRow;
413 TQString m_sheetName;
414};
415
416class UndoDragDrop : public UndoAction
417{
418public:
419 UndoDragDrop( Doc * _doc, Sheet * _sheet, const Region& _source, const Region& _target );
420 virtual ~UndoDragDrop();
421
422 virtual void undo();
423 virtual void redo();
424
425protected:
426 Region m_selectionSource;
427 Region m_selectionTarget;
428 TQCString m_dataSource;
429 TQCString m_dataTarget;
430 TQCString m_dataRedoSource;
431 TQCString m_dataRedoTarget;
432 TQString m_sheetName;
433
434 void saveCellRect( TQCString & cells, Sheet * sheet,
435 const Region& region );
436};
437
438class UndoResizeColRow : public UndoAction
439{
440public:
441 UndoResizeColRow( Doc *_doc, Sheet *_sheet, const Region &_selection );
442 virtual ~UndoResizeColRow();
443
444 virtual void undo();
445 virtual void redo();
446
447protected:
448 void createList( TQValueList<columnSize> &listCol,TQValueList<rowSize> &listRow, Sheet* sheet );
449
450 Region m_region;
451 TQValueList<columnSize> m_lstColumn;
452 TQValueList<columnSize> m_lstRedoColumn;
453 TQValueList<rowSize> m_lstRow;
454 TQValueList<rowSize> m_lstRedoRow;
455 TQString m_sheetName;
456};
457
458class UndoChangeAreaTextCell : public UndoAction
459{
460public:
461 UndoChangeAreaTextCell( Doc *_doc, Sheet *_sheet, const Region &_selection );
462 virtual ~UndoChangeAreaTextCell();
463
464 virtual void undo();
465 virtual void redo();
466
467protected:
468 void createList( TQMap<TQPoint,TQString> &list, Sheet* sheet );
469
470 Region m_region;
471 TQMap<TQPoint,TQString> m_lstTextCell;
472 TQMap<TQPoint,TQString> m_lstRedoTextCell;
473 TQString m_sheetName;
474};
475
476class UndoSort : public UndoAction
477{
478public:
479 UndoSort( Doc *_doc, Sheet *_sheet, const TQRect &_selection);
480 virtual ~UndoSort();
481
482 virtual void undo();
483 virtual void redo();
484
485protected:
486 void copyAll( TQValueList<layoutTextCell> & list, TQValueList<layoutColumn> & listCol,
487 TQValueList<layoutRow> & listRow, Sheet * sheet );
488
489 TQRect m_rctRect;
490 TQValueList<layoutTextCell> m_lstFormats;
491 TQValueList<layoutTextCell> m_lstRedoFormats;
492 TQValueList<layoutColumn> m_lstColFormats;
493 TQValueList<layoutColumn> m_lstRedoColFormats;
494 TQValueList<layoutRow> m_lstRowFormats;
495 TQValueList<layoutRow> m_lstRedoRowFormats;
496
497 TQString m_sheetName;
498};
499
500class UndoMergedCell : public UndoAction
501{
502public:
503 UndoMergedCell( Doc *_doc, Sheet *_sheet, int _column, int _row, int _extraX,int _extraY);
504 virtual ~UndoMergedCell();
505
506 virtual void undo();
507 virtual void redo();
508
509protected:
510 int m_iRow;
511 int m_iCol;
512 int m_iExtraX;
513 int m_iExtraY;
514 int m_iExtraRedoX;
515 int m_iExtraRedoY;
516 TQString m_sheetName;
517};
518
519
520class UndoAutofill : public UndoAction
521{
522public:
523 UndoAutofill( Doc *_doc, Sheet *_sheet, const TQRect &_rect );
524 virtual ~UndoAutofill();
525
526 virtual void undo();
527 virtual void redo();
528protected:
529 void createListCell( TQCString &list, Sheet* sheet );
530 TQRect m_selection;
531 TQCString m_data;
532 TQCString m_dataRedo;
533 TQString m_sheetName;
534};
535
536class UndoInsertCellCol : public UndoInsertRemoveAction
537{
538public:
539 UndoInsertCellCol( Doc *_doc, Sheet *_sheet, const TQRect &_rect );
540 virtual ~UndoInsertCellCol();
541
542 virtual void undo();
543 virtual void redo();
544
545protected:
546 TQString m_sheetName;
547 TQRect m_rect;
548};
549
550class UndoInsertCellRow : public UndoInsertRemoveAction
551{
552public:
553 UndoInsertCellRow( Doc *_doc, Sheet *_sheet,const TQRect &_rect );
554 virtual ~UndoInsertCellRow();
555
556 virtual void undo();
557 virtual void redo();
558
559protected:
560 TQString m_sheetName;
561 TQRect m_rect;
562};
563
564class UndoRemoveCellCol : public UndoInsertRemoveAction
565{
566public:
567 UndoRemoveCellCol( Doc *_doc, Sheet *_sheet, const TQRect &_rect );
568 virtual ~UndoRemoveCellCol();
569
570 virtual void undo();
571 virtual void redo();
572
573protected:
574 TQString m_sheetName;
575 TQRect m_rect;
576 TQCString m_data;
577};
578
579class UndoRemoveCellRow : public UndoInsertRemoveAction
580{
581public:
582 UndoRemoveCellRow( Doc *_doc, Sheet *_sheet, const TQRect &_rect );
583 virtual ~UndoRemoveCellRow();
584
585 virtual void undo();
586 virtual void redo();
587
588protected:
589 TQString m_sheetName;
590 TQRect m_rect;
591 TQCString m_data;
592};
593
594class UndoConditional : public UndoAction
595{
596public:
597 UndoConditional( Doc *_doc, Sheet *_sheet, const Region & _selection );
598 virtual ~UndoConditional();
599
600 virtual void undo();
601 virtual void redo();
602protected:
603 void createListCell( TQCString &list, Sheet* sheet );
604 Region m_region;
605 TQCString m_data;
606 TQCString m_dataRedo;
607 TQString m_sheetName;
608};
609
610class UndoCellPaste : public UndoAction
611{
612public:
613 UndoCellPaste(Doc *_doc, Sheet *_sheet,
614 int _xshift, int _yshift,
615 const Region& _selection, bool insert, int insertTo = 0);
616 virtual ~UndoCellPaste();
617
618 virtual void undo();
619 virtual void redo();
620
621protected:
622 void createListCell( TQCString &listCell,TQValueList<columnSize> &listCol,TQValueList<rowSize> &listRow, Sheet* sheet );
623
624 Region m_region;
625 TQCString m_data;
626 TQCString m_dataRedo;
627 TQValueList<columnSize> m_lstColumn;
628 TQValueList<columnSize> m_lstRedoColumn;
629 TQValueList<rowSize> m_lstRow;
630 TQValueList<rowSize> m_lstRedoRow;
631 int xshift;
632 int yshift;
633 bool b_insert;
634 int m_iInsertTo;
635 TQString m_sheetName;
636};
637
638
639class UndoStyleCell : public UndoAction
640{
641public:
642 UndoStyleCell( Doc *_doc, Sheet *_sheet, const TQRect &_rect );
643 virtual ~UndoStyleCell();
644
645 virtual void undo();
646 virtual void redo();
647
648protected:
649 void createListCell( TQValueList<styleCell> &listCell, Sheet* sheet );
650 TQRect m_selection;
651 TQValueList<styleCell> m_lstStyleCell;
652 TQValueList<styleCell> m_lstRedoStyleCell;
653 TQString m_sheetName;
654};
655
656class UndoInsertData : public UndoChangeAreaTextCell
657{
658 public:
659 UndoInsertData( Doc * _doc, Sheet * _sheet, TQRect & _selection );
660};
661
662
663class Undo
664{
665public:
666 Undo( Doc *_doc );
667 ~Undo();
668
669 void undo();
670 void redo();
671 void clear();
672
673 void lock();
674 void unlock();
675 bool isLocked() const ;
676
677 bool hasUndoActions()const { return !m_stckUndo.isEmpty(); }
678 bool hasRedoActions()const { return !m_stckRedo.isEmpty(); }
679
680 void appendUndo( UndoAction *_action );
681
682 TQString getUndoName();
683 TQString getRedoName();
684
685protected:
686 TQPtrStack<UndoAction> m_stckUndo;
687 TQPtrStack<UndoAction> m_stckRedo;
688
689 Doc *m_pDoc;
690};
691
692} // namespace KSpread
693
694#endif
This class holds the data that makes up a spreadsheet.
Definition kspread_doc.h:98
The one for all class for points and ranges.
Definition region.h:44
Abstract base class.
@ Format
Format only.
The KSpread namespace.
Definition commands.h:39