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.

472 lines
11KB

  1. /* This file is part of the KDE project
  2. Copyright 2004 Ariya Hidayat <ariya@kde.org>
  3. Copyright 2004 Laurent Montel <montel@kde.org>
  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. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. * Boston, MA 02110-1301, USA.
  16. */
  17. #ifndef KSPREAD_COMMANDS
  18. #define KSPREAD_COMMANDS
  19. #include <KoPageLayout.h>
  20. #include <KoQueryTrader.h>
  21. #include <KoUnit.h>
  22. #include <tqrect.h>
  23. #include <tqstring.h>
  24. #include <kcommand.h>
  25. #include "kspread_object.h"
  26. #include "kspread_sheet.h" // for Sheet::LayoutDirection
  27. /**
  28. * The KSpread namespace.
  29. */
  30. namespace KSpread
  31. {
  32. class Cell;
  33. class Doc;
  34. class UndoAction;
  35. /** \page commands Commands
  36. To implement undo and redo functionality, every possible action
  37. by the user for editing and manipulating the document is encapsulated
  38. in a command (based on KCommand).
  39. There is one command class (which will be instantiated) for every unique
  40. action. You need to reimplement the execute() and unexecute() methods
  41. of KCommand.
  42. Each command is created from the user interface, and then added
  43. to the command history (see Doc::commandHistory) using
  44. Doc::addCommand method. Because the command is not immediately
  45. executed, you also need to call the execute() method of that command.
  46. This is an example of typical use of command:
  47. \code
  48. KCommand* command = new RenameSheetCommand( sheet, name );
  49. doc->addCommand( command );
  50. command->execute();
  51. \endcode
  52. Then whenever the user triggers an "undo", the corresponding
  53. unexecute() method of the command is called by the undo action,
  54. thereby reverting the previously executed command. Similar thing
  55. happens for the "redo".
  56. Alphabetical list of commands:
  57. \li AddSheetCommand
  58. \li DissociateCellCommand
  59. \li MergeCellCommand
  60. \li RemoveSheetCommand
  61. \li RenameSheetCommand
  62. \sa Doc::addCommand
  63. \sa KoCommandHistory
  64. */
  65. /**
  66. * Class UndoWrapperCommand is used to help migration from custom
  67. * UndoAction to KCommand-based system.
  68. * See Doc::addCommand for more information.
  69. */
  70. class UndoWrapperCommand : public KCommand
  71. {
  72. public:
  73. UndoWrapperCommand( UndoAction* undoAction );
  74. virtual void execute();
  75. virtual void unexecute();
  76. virtual TQString name() const;
  77. protected:
  78. UndoAction* undoAction;
  79. };
  80. /**
  81. * Class MergeCellCommand implements a command for merging two or more cells
  82. * into one cell.
  83. */
  84. class MergeCellCommand : public KCommand
  85. {
  86. public:
  87. MergeCellCommand( Cell* cell, int colSpan, int rowSpan );
  88. virtual void execute();
  89. virtual void unexecute();
  90. virtual TQString name() const;
  91. protected:
  92. Cell* cell;
  93. int colSpan;
  94. int rowSpan;
  95. int oldColSpan;
  96. int oldRowSpan;
  97. TQString rangeName;
  98. };
  99. /**
  100. * Class DissociateCellCommand implements a command for breaking merged cells.
  101. */
  102. class DissociateCellCommand : public KCommand
  103. {
  104. public:
  105. DissociateCellCommand( Cell* cell );
  106. virtual void execute();
  107. virtual void unexecute();
  108. virtual TQString name() const;
  109. protected:
  110. Cell* cell;
  111. int oldColSpan;
  112. int oldRowSpan;
  113. };
  114. /**
  115. * Class RenameSheetCommand implements a command for renaming a sheet.
  116. *
  117. * \sa Sheet::setSheetName
  118. */
  119. class RenameSheetCommand : public KCommand
  120. {
  121. public:
  122. RenameSheetCommand( Sheet* sheet, const TQString &name );
  123. virtual void execute();
  124. virtual void unexecute();
  125. virtual TQString name() const;
  126. protected:
  127. Sheet* sheet;
  128. TQString oldName;
  129. TQString newName;
  130. };
  131. class HideSheetCommand : public KCommand
  132. {
  133. public:
  134. HideSheetCommand( Sheet* sheet );
  135. virtual void execute();
  136. virtual void unexecute();
  137. virtual TQString name() const;
  138. protected:
  139. Doc* doc;
  140. TQString sheetName;
  141. };
  142. class ShowSheetCommand : public KCommand
  143. {
  144. public:
  145. ShowSheetCommand( Sheet* sheet );
  146. virtual void execute();
  147. virtual void unexecute();
  148. virtual TQString name() const;
  149. protected:
  150. Doc* doc;
  151. TQString sheetName;
  152. };
  153. class AddSheetCommand : public KCommand
  154. {
  155. public:
  156. AddSheetCommand( Sheet* sheet );
  157. virtual void execute();
  158. virtual void unexecute();
  159. virtual TQString name() const;
  160. protected:
  161. Sheet* sheet;
  162. Doc* doc;
  163. };
  164. class RemoveSheetCommand : public KCommand
  165. {
  166. public:
  167. RemoveSheetCommand( Sheet* sheet );
  168. virtual void execute();
  169. virtual void unexecute();
  170. virtual TQString name() const;
  171. protected:
  172. Sheet* sheet;
  173. Doc* doc;
  174. };
  175. /**
  176. * Class SheetPropertiesCommand implements a command for changing sheet properties.
  177. */
  178. class SheetPropertiesCommand : public KCommand
  179. {
  180. public:
  181. SheetPropertiesCommand( Doc* doc, Sheet* sheet );
  182. void setLayoutDirection( Sheet::LayoutDirection direction );
  183. void setAutoCalc( bool b );
  184. void setShowGrid( bool b );
  185. void setShowPageBorders( bool b );
  186. void setShowFormula( bool b );
  187. void setHideZero( bool b );
  188. void setShowFormulaIndicator( bool b );
  189. void setShowCommentIndicator( bool b );
  190. void setColumnAsNumber( bool b );
  191. void setLcMode( bool b );
  192. void setCapitalizeFirstLetter( bool b );
  193. virtual void execute();
  194. virtual void unexecute();
  195. virtual TQString name() const;
  196. protected:
  197. Sheet* sheet;
  198. Doc* doc;
  199. Sheet::LayoutDirection oldDirection, newDirection;
  200. bool oldAutoCalc, newAutoCalc;
  201. bool oldShowGrid, newShowGrid;
  202. bool oldShowPageBorders, newShowPageBorders;
  203. bool oldShowFormula, newShowFormula;
  204. bool oldHideZero, newHideZero;
  205. bool oldShowFormulaIndicator, newShowFormulaIndicator;
  206. bool oldShowCommentIndicator, newShowCommentIndicator;
  207. bool oldColumnAsNumber, newColumnAsNumber;
  208. bool oldLcMode, newLcMode;
  209. bool oldCapitalizeFirstLetter, newCapitalizeFirstLetter;
  210. };
  211. class InsertColumnCommand : public KCommand
  212. {
  213. public:
  214. InsertColumnCommand( Sheet* s , unsigned int _column, unsigned int _nbCol );
  215. virtual void execute();
  216. virtual void unexecute();
  217. virtual TQString name() const;
  218. protected:
  219. Doc* doc;
  220. TQString sheetName;
  221. unsigned int insertPosColumn;
  222. unsigned int nbColumnInserted;
  223. };
  224. class DefinePrintRangeCommand : public KCommand
  225. {
  226. public:
  227. DefinePrintRangeCommand( Sheet* sheet );
  228. virtual void execute();
  229. virtual void unexecute();
  230. virtual TQString name() const;
  231. protected:
  232. Doc* doc;
  233. TQString sheetName;
  234. TQRect printRangeRedo, printRange;
  235. };
  236. class PaperLayoutCommand : public KCommand
  237. {
  238. public:
  239. PaperLayoutCommand( Sheet* sheet );
  240. virtual void execute();
  241. virtual void unexecute();
  242. virtual TQString name() const;
  243. protected:
  244. Doc* doc;
  245. TQString sheetName;
  246. KoPageLayout pl;
  247. KoPageLayout plRedo;
  248. KoHeadFoot hf;
  249. KoHeadFoot hfRedo;
  250. KoUnit::Unit unit;
  251. KoUnit::Unit unitRedo;
  252. bool printGrid;
  253. bool printGridRedo;
  254. bool printCommentIndicator;
  255. bool printCommentIndicatorRedo;
  256. bool printFormulaIndicator;
  257. bool printFormulaIndicatorRedo;
  258. TQRect printRange;
  259. TQRect printRangeRedo;
  260. TQPair<int, int> printRepeatColumns;
  261. TQPair<int, int> printRepeatColumnsRedo;
  262. TQPair<int, int> printRepeatRows;
  263. TQPair<int, int> printRepeatRowsRedo;
  264. double zoom;
  265. double zoomRedo;
  266. int pageLimitX;
  267. int pageLimitXRedo;
  268. int pageLimitY;
  269. int pageLimitYRedo;
  270. };
  271. class LinkCommand : public KCommand
  272. {
  273. public:
  274. LinkCommand( Cell* cell, const TQString& text, const TQString& link );
  275. virtual void execute();
  276. virtual void unexecute();
  277. virtual TQString name() const;
  278. protected:
  279. Cell* cell;
  280. Doc* doc;
  281. TQString oldText;
  282. TQString oldLink;
  283. TQString newText;
  284. TQString newLink;
  285. };
  286. class ChangeObjectGeometryCommand : public KCommand
  287. {
  288. public:
  289. ChangeObjectGeometryCommand( EmbeddedObject *_obj, const KoPoint &_m_diff, const KoSize &_r_diff );
  290. ~ChangeObjectGeometryCommand();
  291. virtual void execute();
  292. virtual void unexecute();
  293. virtual TQString name() const;
  294. protected:
  295. KoPoint m_diff;
  296. KoSize r_diff;
  297. EmbeddedObject *obj;
  298. Doc *doc;
  299. };
  300. class RemoveObjectCommand : public KCommand
  301. {
  302. public:
  303. RemoveObjectCommand( EmbeddedObject *_obj, bool _cut = false );
  304. ~RemoveObjectCommand();
  305. virtual void execute();
  306. virtual void unexecute();
  307. virtual TQString name() const;
  308. protected:
  309. EmbeddedObject *obj;
  310. Doc* doc;
  311. bool executed;
  312. bool cut;
  313. };
  314. class InsertObjectCommand : public KCommand
  315. {
  316. public:
  317. InsertObjectCommand( const KoRect& _tqgeometry, KoDocumentEntry&, Canvas *_canvas ); //child
  318. InsertObjectCommand( const KoRect& _tqgeometry, KoDocumentEntry&, const TQRect& _data, Canvas *_canvas ); //chart
  319. InsertObjectCommand( const KoRect& _tqgeometry, KURL& _file, Canvas *_canvas ); //picture
  320. ~InsertObjectCommand();
  321. virtual void execute();
  322. virtual void unexecute();
  323. virtual TQString name() const;
  324. protected:
  325. KoRect tqgeometry;
  326. Canvas *canvas;
  327. bool executed;
  328. KoDocumentEntry entry;
  329. TQRect data;
  330. ObjType type;
  331. KURL file;
  332. EmbeddedObject *obj;
  333. };
  334. class RenameNameObjectCommand : public KNamedCommand
  335. {
  336. public:
  337. RenameNameObjectCommand( const TQString &_name, const TQString &_objectName, EmbeddedObject *_obj, Doc *_doc );
  338. ~RenameNameObjectCommand();
  339. void execute();
  340. void unexecute();
  341. protected:
  342. TQString oldObjectName, newObjectName;
  343. EmbeddedObject *object;
  344. Doc *doc;
  345. Sheet *m_page;
  346. };
  347. class GeometryPropertiesCommand : public KNamedCommand
  348. {
  349. public:
  350. enum KgpType { ProtectSize, KeepRatio};
  351. GeometryPropertiesCommand( const TQString &name, TQPtrList<EmbeddedObject> &objects,
  352. bool newValue, KgpType type, Doc *_doc );
  353. GeometryPropertiesCommand( const TQString &name, TQValueList<bool> &lst, TQPtrList<EmbeddedObject> &objects,
  354. bool newValue, KgpType type, Doc *_doc );
  355. ~GeometryPropertiesCommand();
  356. virtual void execute();
  357. virtual void unexecute();
  358. protected:
  359. TQValueList<bool> m_oldValue;
  360. TQPtrList<EmbeddedObject> m_objects;
  361. bool m_newValue;
  362. KgpType m_type;
  363. Doc *m_doc;
  364. };
  365. class MoveObjectByCmd : public KNamedCommand
  366. {
  367. public:
  368. MoveObjectByCmd( const TQString &_name, const KoPoint &_diff, TQPtrList<EmbeddedObject> &_objects,
  369. Doc *_doc, Sheet *m_page );
  370. ~MoveObjectByCmd();
  371. virtual void execute();
  372. virtual void unexecute();
  373. protected:
  374. KoPoint diff;
  375. TQPtrList<EmbeddedObject> objects;
  376. Doc *doc;
  377. Sheet *m_page;
  378. };
  379. } // namespace KSpread
  380. #endif /* KSPREAD_COMMANDS */