KOffice – TDE office suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

695 lines
15KB

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