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.

738 lines
20KB

  1. /* This file is part of the KDE project
  2. Copyright (C) 2004 Ariya Hidayat <ariya@kde.org>
  3. (C) 2002-2003 Norbert Andres <nandres@web.de>
  4. (C) 2000-2005 Laurent Montel <montel@kde.org>
  5. (C) 2002 John Dailey <dailey@vt.edu>
  6. (C) 2002 Phillip Mueller <philipp.mueller@gmx.de>
  7. (C) 2000 Werner Trobin <trobin@kde.org>
  8. (C) 1999-2000 Simon Hausmann <hausmann@kde.org>
  9. (C) 1999 David Faure <faure@kde.org>
  10. (C) 1998-2000 Torben Weis <weis@kde.org>
  11. This library is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU Library General Public
  13. License as published by the Free Software Foundation; either
  14. version 2 of the License, or (at your option) any later version.
  15. This library is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. Library General Public License for more details.
  19. You should have received a copy of the GNU Library General Public License
  20. along with this library; see the file COPYING.LIB. If not, write to
  21. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  22. * Boston, MA 02110-1301, USA.
  23. */
  24. #ifndef KSPREAD_DOC
  25. #define KSPREAD_DOC
  26. #include <tqmap.h>
  27. #include <tqobject.h>
  28. #include <tqpainter.h>
  29. #include <tqrect.h>
  30. #include <tqstring.h>
  31. #include <tqvaluelist.h>
  32. #include <kcompletion.h>
  33. #include <KoDocument.h>
  34. #include <KoZoomHandler.h>
  35. #include "kspread_global.h"
  36. class KCommand;
  37. class KoCommandHistory;
  38. class KoGenStyles;
  39. class KoOasisSettings;
  40. class KoPicture;
  41. class KoPictureCollection;
  42. class KoPictureKey;
  43. class KoStore;
  44. class KoXmlWriter;
  45. class DCOPObject;
  46. class TQDomDocument;
  47. class KSpellConfig;
  48. #define MIME_TYPE "application/x-kspread"
  49. namespace KSpread
  50. {
  51. class Damage;
  52. class ValueParser;
  53. class ValueConverter;
  54. class ValueFormatter;
  55. class ValueCalc;
  56. class Sheet;
  57. class Doc;
  58. class View;
  59. class Map;
  60. class Region;
  61. class StyleManager;
  62. class UndoAction;
  63. class KSPLoadingInfo;
  64. class EmbeddedObject;
  65. struct Reference
  66. {
  67. TQString sheet_name;
  68. TQString ref_name;
  69. TQRect rect;
  70. };
  71. class Plugin
  72. {
  73. public:
  74. Plugin() {}
  75. virtual ~Plugin() {}
  76. virtual TQDomElement saveXML( TQDomDocument & doc ) const = 0;
  77. };
  78. /**
  79. * This class holds the data that makes up a spreadsheet.
  80. */
  81. class KSPREAD_EXPORT Doc : public KoDocument, public KoZoomHandler
  82. {
  83. Q_OBJECT
  84. TQ_PROPERTY( bool getShowRowHeader READ getShowRowHeader )
  85. TQ_PROPERTY( bool getShowColHeader READ getShowColHeader )
  86. TQ_PROPERTY( double getIndentValue READ getIndentValue WRITE setIndentValue )
  87. TQ_PROPERTY( bool getShowMessageError READ getShowMessageError WRITE setShowMessageError)
  88. TQ_PROPERTY( bool dontCheckUpperWord READ dontCheckUpperWord WRITE setDontCheckUpperWord)
  89. TQ_PROPERTY( bool dontCheckTitleCase READ dontCheckTitleCase WRITE setDontCheckTitleCase)
  90. TQ_PROPERTY( int syntaxVersion READ syntaxVersion )
  91. TQ_PROPERTY( bool showVerticalScrollBar READ showVerticalScrollBar WRITE setShowVerticalScrollBar )
  92. TQ_PROPERTY( bool showHorizontalScrollBar READ showHorizontalScrollBar WRITE setShowHorizontalScrollBar )
  93. TQ_PROPERTY( bool showColumnHeader READ showColumnHeader WRITE setShowColumnHeader )
  94. TQ_PROPERTY( bool showRowHeader READ showRowHeader WRITE setShowRowHeader )
  95. TQ_PROPERTY( bool showStatusBar READ showStatusBar WRITE setShowStatusBar )
  96. TQ_PROPERTY( bool showFormulaBar READ showFormulaBar WRITE setShowFormulaBar )
  97. TQ_PROPERTY( bool showTabBar READ showTabBar WRITE setShowTabBar )
  98. TQ_PROPERTY( int undoRedoLimit READ undoRedoLimit WRITE setUndoRedoLimit )
  99. public:
  100. /**
  101. * Creates a new document.
  102. */
  103. Doc( TQWidget *parentWidget = 0, const char *widgetName = 0, TQObject* parent = 0,
  104. const char* name = 0, bool singleViewMode = false );
  105. /**
  106. * Destroys the document.
  107. */
  108. ~Doc();
  109. /**
  110. * Possible values for the "type" argument of the KoGenStyle constructor.
  111. */
  112. enum { STYLE_PAGE = 20,
  113. STYLE_COLUMN_USER, /**< commmon column styles */
  114. STYLE_COLUMN_AUTO, /**< auto column styles */
  115. STYLE_ROW_USER, /**< common row styles */
  116. STYLE_ROW_AUTO, /**< auto row styles */
  117. STYLE_CELL_USER,
  118. STYLE_CELL_AUTO,
  119. STYLE_PAGEMASTER,
  120. STYLE_NUMERIC_NUMBER };
  121. /**
  122. * Returns list of all documents.
  123. */
  124. static TQValueList<Doc*> documents();
  125. /**
  126. * Returns the MIME type of KSpread document.
  127. */
  128. virtual TQCString mimeType() const { return MIME_TYPE; }
  129. TDELocale *locale () const;
  130. Map *map () const;
  131. StyleManager *styleManager () const;
  132. ValueParser *parser () const;
  133. ValueFormatter *formatter () const;
  134. ValueConverter *converter () const;
  135. ValueCalc *calc () const;
  136. /**
  137. * Adds a command to the command history. The command itself
  138. * would not be executed.
  139. */
  140. void addCommand( KCommand* command );
  141. /*
  142. * Adds an undo object. This is the same as addCommand, except
  143. * that it accepts Undo instance. Once every undo object
  144. * is converted to KCommand, this function will be obsoleted.
  145. */
  146. void addCommand( UndoAction* command );
  147. /**
  148. * Undoes the last operation.
  149. */
  150. void undo();
  151. /**
  152. * Redoes the last undo.
  153. */
  154. void redo();
  155. /**
  156. * Locks the undo buffer.
  157. */
  158. void undoLock();
  159. /**
  160. * Releases lock of undo buffer.
  161. */
  162. void undoUnlock();
  163. /**
  164. * Returns true if undo buffer is locked.
  165. */
  166. bool undoLocked() const;
  167. /**
  168. * Returns the command history for the document. This is used
  169. * in View for updating the actions (i.e through
  170. * signal KoCommandHistory::commandExecuted)
  171. */
  172. KoCommandHistory* commandHistory();
  173. /**
  174. * Returns the name of the unit used to display margins.
  175. * For example, if unit() returns KoUnit::U_MM, then
  176. * this functions return "mm".
  177. */
  178. TQString unitName() const;
  179. /**
  180. * Returns the syntax version of the currently opened file
  181. */
  182. int syntaxVersion( ) const;
  183. /**
  184. * If b is true, vertical scrollbar is visible, otherwise
  185. * it will be hidden.
  186. */
  187. void setShowVerticalScrollBar( bool b );
  188. /**
  189. * Returns true if vertical scroll bar is visible.
  190. */
  191. bool showVerticalScrollBar() const;
  192. /**
  193. * \deprecated Use showVerticalScrollBar().
  194. */
  195. bool getShowVerticalScrollBar() const { return showVerticalScrollBar(); }
  196. /**
  197. * If b is true, horizontal scrollbar is visible, otherwise
  198. * it will be hidden.
  199. */
  200. void setShowHorizontalScrollBar( bool b );
  201. /**
  202. * Returns true if horizontal scroll bar is visible.
  203. */
  204. bool showHorizontalScrollBar() const;
  205. /**
  206. * \deprecated Use showHorizontalScrollBar().
  207. */
  208. bool getShowHorizontalScrollBar() const { return showHorizontalScrollBar(); }
  209. /**
  210. * If b is true, column header is visible, otherwise
  211. * it will be hidden.
  212. */
  213. void setShowColumnHeader( bool b );
  214. /**
  215. * Returns true if column header is visible.
  216. */
  217. bool showColumnHeader() const;
  218. /**
  219. * \deprecated Use setShowColumnHeader().
  220. */
  221. void setShowColHeader( bool b ){ setShowColumnHeader( b ) ; }
  222. /**
  223. * \deprecated Use showColumnHeader().
  224. */
  225. bool getShowColHeader() const { return showColumnHeader(); }
  226. /**
  227. * If b is true, row header is visible, otherwise
  228. * it will be hidden.
  229. */
  230. void setShowRowHeader( bool b );
  231. /**
  232. * Returns true if row header is visible.
  233. */
  234. bool showRowHeader() const;
  235. /**
  236. * \deprecated Use showRowHeader().
  237. */
  238. bool getShowRowHeader() const { return showRowHeader(); }
  239. /**
  240. * Sets the color of the grid.
  241. */
  242. void setGridColor( const TQColor& color );
  243. /**
  244. * Returns the color of the grid.
  245. */
  246. TQColor gridColor() const;
  247. /**
  248. * Sets the indentation value.
  249. */
  250. void setIndentValue( double val );
  251. /**
  252. * Returns the indentation value.
  253. */
  254. double indentValue() const;
  255. /**
  256. * \deprecated Use indentValue().
  257. */
  258. double getIndentValue() const { return indentValue(); }
  259. /**
  260. * If b is true, status bar is visible, otherwise
  261. * it will be hidden.
  262. */
  263. void setShowStatusBar( bool b );
  264. /**
  265. * Returns true if status bar is visible.
  266. */
  267. bool showStatusBar() const;
  268. /**
  269. * \deprecated Use showStatusBar().
  270. */
  271. bool getShowStatusBar() const { return showStatusBar(); }
  272. /**
  273. * If b is true, tab bar is visible, otherwise
  274. * it will be hidden.
  275. */
  276. void setShowTabBar( bool b );
  277. /**
  278. * Returns true if tab bar is visible.
  279. */
  280. bool showTabBar() const;
  281. /**
  282. * \deprecated Use showTabBar().
  283. */
  284. bool getShowTabBar() const { return showTabBar(); }
  285. /**
  286. * If b is true, formula bar is visible, otherwise
  287. * it will be hidden.
  288. */
  289. void setShowFormulaBar( bool b );
  290. /**
  291. * Returns true if formula bar is visible.
  292. */
  293. bool showFormulaBar() const;
  294. /**
  295. * \deprecated Use showFormulaBar().
  296. */
  297. bool getShowFormulaBar() const { return showFormulaBar(); }
  298. /**
  299. * If b is true, an error message will pop up whenever error occurs.
  300. */
  301. void setShowMessageError( bool b );
  302. /**
  303. * Returns true if error message should pop up whenever error occurs.
  304. */
  305. bool showMessageError() const;
  306. /**
  307. * \deprecated Use showMessageError().
  308. */
  309. bool getShowMessageError() const{ return showMessageError(); }
  310. /**
  311. * completion mode
  312. */
  313. TDEGlobalSettings::Completion completionMode( )const ;
  314. void setCompletionMode( TDEGlobalSettings::Completion _complMode);
  315. KSpread::MoveTo getMoveToValue()const;
  316. void setMoveToValue(KSpread::MoveTo _moveTo) ;
  317. /**
  318. * Method of calc
  319. */
  320. void setTypeOfCalc( MethodOfCalc _calc);
  321. MethodOfCalc getTypeOfCalc() const;
  322. /**
  323. * get custom tdespell config
  324. */
  325. void setKSpellConfig(KSpellConfig _tdespell);
  326. KSpellConfig * getKSpellConfig();
  327. bool dontCheckUpperWord() const;
  328. void setDontCheckUpperWord(bool _b);
  329. bool dontCheckTitleCase() const;
  330. void setDontCheckTitleCase(bool _b);
  331. TQColor pageBorderColor() const;
  332. void changePageBorderColor( const TQColor & _color);
  333. virtual bool completeSaving( KoStore* _store );
  334. virtual TQDomDocument saveXML();
  335. enum SaveFlag { SaveAll, SaveSelected }; // kpresenter and kword have have SavePage too
  336. bool savingWholeDocument();
  337. /**
  338. * Save the whole document, or just the selection, into OASIS format
  339. * When saving the selection, also return the data as plain text and/or plain picture,
  340. * which are used to insert into the KMultipleDrag drag object.
  341. *
  342. * @param store the KoStore to save into
  343. * @param manifestWriter pointer to a koxmlwriter to add entries to the manifest
  344. * @param saveFlag either the whole document, or only the selected text/objects.
  345. * @param plainText must be set when saveFlag==SaveSelected.
  346. * It returns the plain text format of the saved data, when available.
  347. * @param picture must be set when saveFlag==SaveSelected.
  348. * It returns the selected picture, when exactly one picture was selected.
  349. */
  350. bool saveOasisHelper( KoStore* store, KoXmlWriter* manifestWriter, SaveFlag saveFlag,
  351. TQString* plainText = 0, KoPicture* picture = 0 );
  352. virtual bool saveOasis( KoStore* store, KoXmlWriter* manifestWriter );
  353. void saveOasisDocumentStyles( KoStore* store, KoGenStyles& mainStyles ) const;
  354. virtual int supportedSpecialFormats() const;
  355. virtual bool loadXML( TQIODevice *, const TQDomDocument& doc );
  356. virtual bool loadOasis( const TQDomDocument& doc, KoOasisStyles& oasisStyles, const TQDomDocument& settings, KoStore* );
  357. virtual bool loadChildren( KoStore* _store );
  358. TQDomElement saveAreaName( TQDomDocument& doc ) ;
  359. void saveOasisAreaName( KoXmlWriter & xmlWriter );
  360. void loadAreaName( const TQDomElement& element );
  361. void loadOasisAreaName( const TQDomElement& element );
  362. void loadOasisCellValidation( const TQDomElement&body );
  363. virtual void addView( KoView *_view );
  364. virtual bool initDoc(InitDocFlags flags, TQWidget* parentWidget=0);
  365. /**
  366. * Change the zoom factor to @p z (e.g. 150 for 150%)
  367. * and/or change the resolution, given in DPI.
  368. * This is done on startup and when printing.
  369. * The same call combines both so that all the updating done behind
  370. * the scenes is done only once, even if both zoom and DPI must be changed.
  371. */
  372. virtual void setZoomAndResolution( int zoom, int dpiX, int dpiY );
  373. /**
  374. * updates all properties after zoom changed
  375. */
  376. void newZoomAndResolution( bool updateViews, bool forPrint );
  377. // virtual void printMap( TQPainter & _painter );
  378. void enableUndo( bool _b );
  379. void enableRedo( bool _b );
  380. /**
  381. * @return true if the document is currently loading.
  382. */
  383. bool isLoading() const;
  384. /**
  385. Prevents painting. Useful when importing data.
  386. * @param status switch the painting on/off
  387. */
  388. void doNotPaint(bool status);
  389. virtual void paintContent( TQPainter & painter, const TQRect & rect, bool transparent = false,
  390. double zoomX = 1.0, double zoomY = 1.0 );
  391. void paintContent( TQPainter & painter, const TQRect & rect, bool transparent,
  392. Sheet * sheet, bool drawCursor = true );
  393. bool docData( TQString const & xmlTag, TQDomElement & data );
  394. void deregisterPlugin( Plugin * plugin );
  395. void registerPlugin( Plugin * plugin );
  396. /**
  397. * Primary entry point for painting. Use this function to paint groups of cells
  398. *
  399. * @param painter the painter object to use. This should already be
  400. * initialized with the world matrix. The begin and end calls
  401. * should surround this function.
  402. *
  403. * @param viewRect the document coordinates showing what is actually visible in
  404. * the screen
  405. *
  406. * @param view the view of the region -- may be NULL but no selection markers
  407. * can be passed in that case.
  408. *
  409. * @param cellRegions a list of rectangles indicating the cell ranges needing
  410. * painted.
  411. *
  412. * @param sheet the sheet which the cells in cellRegions come from
  413. *
  414. * @param drawCursor whether or not to draw the selection rectangle and the choose
  415. * marker
  416. */
  417. void paintCellRegions(TQPainter& painter, const TQRect &viewRect,
  418. View* view,
  419. TQValueList<TQRect> cellRegions,
  420. const Sheet* sheet, bool drawCursor);
  421. virtual DCOPObject* dcopObject();
  422. void addAreaName(const TQRect &_rect,const TQString & name,const TQString & sheetName);
  423. const TQValueList<Reference> & listArea();
  424. void removeArea( const TQString &name);
  425. TDECompletion & completion();
  426. void addStringCompletion(const TQString & stringCompletion);
  427. void changeAreaSheetName(const TQString & oldName,const TQString &sheetName);
  428. TQRect getRectArea(const TQString & _sheetName);
  429. /**
  430. * Inserts an object to the object list.
  431. */
  432. void insertObject( EmbeddedObject * obj );
  433. /**
  434. * @return the list of all embedded objects (charts, pictures and koffice objects) Use insertObject to add an object to the list.
  435. */
  436. TQPtrList<EmbeddedObject>& embeddedObjects();
  437. KoPictureCollection *pictureCollection();
  438. void initConfig();
  439. void saveConfig();
  440. void refreshLocale();
  441. /**
  442. * Functions to begin a kspread 'operation'. Calls to emitBeginOperation
  443. * and emitEndOperation should surround each logical user operation.
  444. * During the operation, the following should hold true:
  445. * - No painting will be done to the screen
  446. * - No cell calculation will be done (maybe there are exceptions, such
  447. * as the goalseek operation needs to calculate values)
  448. * During an operation, calls to Sheet::setRegionPaintDirty mark
  449. * regions as needing repainted. Once the emitEndOperation function is
  450. * called, those regions will be painted all at once, values being calculated
  451. * as necessary.
  452. * Calls to begin/endOperation may be nested. Calcualation/painting will
  453. * be delayed until the outer begin/end pair has finished.
  454. *
  455. * The waitCursor parameter specifies whether to put the hourglass
  456. * up during the operation.
  457. *
  458. */
  459. void emitBeginOperation(bool waitCursor);
  460. /** default override of koDocument version. Changes the cursor to an
  461. * hourglass
  462. */
  463. virtual void emitBeginOperation();
  464. /**
  465. * Mark the end of an operation and triggers a repaint of any cells or regions of cells which
  466. * have been marked as 'dirty' via calls to Sheet::setRegionPaintDirty
  467. * See above comment to emitBeginOperation(bool).
  468. */
  469. virtual void emitEndOperation();
  470. /**
  471. * s.a. difference does only specified tasks and thats why it improves performance
  472. * significantly. rect normally are the visible cells/the cells that need to be updated.
  473. *
  474. * TODO: This is essentially redundant now since emitEndOperation behaviour has been fixed to
  475. * only update cells that were already in the paint dirty list.
  476. */
  477. void emitEndOperation( const Region& region );
  478. bool delayCalculation() const;
  479. void updateBorderButton();
  480. void insertSheet( Sheet * sheet );
  481. void takeSheet( Sheet * sheet );
  482. // The user-chosen global unit
  483. static TQString getAttribute(const TQDomElement &element, const char *attributeName, const TQString &defaultValue)
  484. {
  485. return element.attribute( attributeName, defaultValue );
  486. }
  487. static int getAttribute(const TQDomElement &element, const char *attributeName, int defaultValue)
  488. {
  489. TQString value;
  490. if ( ( value = element.attribute( attributeName ) ) != TQString() )
  491. return value.toInt();
  492. else
  493. return defaultValue;
  494. }
  495. static double getAttribute(const TQDomElement &element, const char *attributeName, double defaultValue)
  496. {
  497. TQString value;
  498. if ( ( value = element.attribute( attributeName ) ) != TQString() )
  499. return value.toDouble();
  500. else
  501. return defaultValue;
  502. }
  503. void addIgnoreWordAll( const TQString & word);
  504. void clearIgnoreWordAll( );
  505. void addIgnoreWordAllList( const TQStringList & _lst);
  506. TQStringList spellListIgnoreAll() const ;
  507. void setDisplaySheet(Sheet *_Sheet );
  508. Sheet * displaySheet() const;
  509. /**
  510. * @return the loading info
  511. */
  512. KSPLoadingInfo* loadingInfo() const;
  513. /**
  514. * deletes the loading info after loading is complete
  515. */
  516. void deleteLoadingInfo();
  517. void increaseNumOperation();
  518. void decreaseNumOperation();
  519. void addDamage( Damage* damage );
  520. /* Function specific when we load config from file */
  521. void loadConfigFromFile();
  522. bool configLoadFromFile() const;
  523. // repaint (update) all views
  524. void repaint( const TQRect& );
  525. void repaint( EmbeddedObject* );
  526. void repaint( const KoRect& );
  527. virtual void addShell( KoMainWindow *shell );
  528. int undoRedoLimit() const;
  529. void setUndoRedoLimit(int _val);
  530. public slots:
  531. //void newView(); obsloete (Werner)
  532. void refreshInterface();
  533. void flushDamages();
  534. signals:
  535. // Document signals
  536. /**
  537. * Emitted if all views have to be updated.
  538. */
  539. void sig_updateView();
  540. /**
  541. * Emitted if all interfaces have to be updated.
  542. */
  543. void sig_refreshView();
  544. /**
  545. * Emitted if we update to locale system
  546. */
  547. void sig_refreshLocale();
  548. void sig_addAreaName( const TQString & );
  549. void sig_removeAreaName( const TQString & );
  550. void damagesFlushed( const TQValueList<Damage*>& damages );
  551. protected slots:
  552. void commandExecuted();
  553. void documentRestored();
  554. virtual void openTemplate( const TQString& file );
  555. virtual void initEmpty();
  556. protected:
  557. KoView* createViewInstance( TQWidget* parent, const char* name );
  558. void makeUsedPixmapList();
  559. void insertPixmapKey( KoPictureKey key );
  560. /**
  561. * Overloaded function of @ref KoDocument.
  562. */
  563. virtual bool completeLoading( KoStore* );
  564. /**
  565. * Overloaded function of @ref KoDocument.
  566. */
  567. virtual bool saveChildren( KoStore* _store );
  568. class SavedDocParts : public TQMap<TQString, TQDomElement> {};
  569. SavedDocParts m_savedDocParts;
  570. private:
  571. class Private;
  572. Private* d;
  573. // don't allow copy or assignment
  574. Doc( const Doc& );
  575. Doc& operator=( const Doc& );
  576. /* helper functions for painting */
  577. /**
  578. * This function is called at the end of an operation and is responsible
  579. * for painting any changes that have occurred in the meantime
  580. */
  581. void paintUpdates();
  582. void PaintRegion(TQPainter& painter, const KoRect &viewRegion,
  583. View* view, const TQRect &paintRegion,
  584. const Sheet* sheet);
  585. void loadPaper( TQDomElement const & paper );
  586. void saveOasisSettings( KoXmlWriter &settingsWriter );
  587. void loadOasisSettings( const TQDomDocument&settingsDoc );
  588. void loadOasisIgnoreList( const KoOasisSettings& settings );
  589. KSPLoadingInfo *m_loadingInfo;
  590. };
  591. } // namespace KSpread
  592. #endif /* KSPREAD_DOC */