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.

1390 lines
46KB

  1. /* This file is part of the KDE project
  2. Copyright 1998, 1999 Torben Weis <weis@kde.org>
  3. Copyright 1999- 2006 The KSpread Team
  4. www.koffice.org/kspread
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  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. You should have received a copy of the GNU Library General Public License
  14. along with this library; see the file COPYING.LIB. If not, write to
  15. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16. * Boston, MA 02110-1301, USA.
  17. */
  18. #ifndef KSPREAD_SHEET
  19. #define KSPREAD_SHEET
  20. #include <tqclipboard.h>
  21. #include <tqdragobject.h>
  22. #include <tqintdict.h>
  23. #include <tqmemarray.h>
  24. #include <tqpen.h>
  25. #include <tqptrlist.h>
  26. #include <tqrect.h>
  27. #include <tqwidget.h>
  28. #include <KoDocument.h>
  29. #include <KoDocumentChild.h>
  30. #include <KoOasisSettings.h> // for KoOasisSettings::NamedMap
  31. #include "kspread_autofill.h"
  32. #include "kspread_cell.h"
  33. #include "kspread_format.h"
  34. #include "kspread_global.h"
  35. #include "kspread_object.h"
  36. class TQWidget;
  37. class TQPainter;
  38. class TQDomElement;
  39. class DCOPObject;
  40. class KPrinter;
  41. class KoDocumentEntry;
  42. class KoStyleStack;
  43. class KoGenStyles;
  44. class KoOasisLoadingContext;
  45. class KoOasisSettings;
  46. class KoOasisStyles;
  47. class KCommand;
  48. class KoPicture;
  49. class KoXmlWriter;
  50. namespace KoChart
  51. {
  52. class Part;
  53. }
  54. namespace KSpread
  55. {
  56. class Canvas;
  57. class Cell;
  58. class EmbeddedChart;
  59. class DependencyManager;
  60. class Doc;
  61. class GenValidationStyles;
  62. class Map;
  63. class Point;
  64. class Region;
  65. class Selection;
  66. class Sheet;
  67. class SheetPrint;
  68. class Style;
  69. class UndoInsertRemoveAction;
  70. class View;
  71. class EmbeddedKOfficeObject;
  72. class EmbeddedObject;
  73. /********************************************************************
  74. *
  75. * CellBinding
  76. *
  77. ********************************************************************/
  78. /**
  79. * @short This is an abstract base class only.
  80. */
  81. class CellBinding : public TQObject
  82. {
  83. Q_OBJECT
  84. public:
  85. CellBinding( Sheet *_sheet, const TQRect& _area );
  86. virtual ~CellBinding();
  87. bool contains( int _x, int _y );
  88. /**
  89. * Call this function if one of the cells covered by this binding ( @see #rect )
  90. * has changed. This will in turn force for example a chart to update.
  91. *
  92. * @param _obj may by 0L. In this case all cells may have changed.
  93. */
  94. virtual void cellChanged( Cell *_obj );
  95. virtual void setIgnoreChanges( bool _ignore ) { m_bIgnoreChanges = _ignore; }
  96. virtual TQRect& dataArea() { return m_rctDataArea; }
  97. virtual void setDataArea( const TQRect _rect ) { m_rctDataArea = _rect; }
  98. Sheet* sheet()const { return m_pSheet; }
  99. signals:
  100. void changed( Cell *_obj );
  101. protected:
  102. TQRect m_rctDataArea;
  103. Sheet *m_pSheet;
  104. bool m_bIgnoreChanges;
  105. };
  106. class ChartBinding : public CellBinding
  107. {
  108. Q_OBJECT
  109. public:
  110. ChartBinding( Sheet *_sheet, const TQRect& _area, EmbeddedChart *_child );
  111. virtual ~ChartBinding();
  112. virtual void cellChanged( Cell *_obj );
  113. private:
  114. EmbeddedChart* m_child;
  115. };
  116. /********************************************************************
  117. *
  118. * TextDrag
  119. *
  120. ********************************************************************/
  121. /**
  122. * @short This is a class for handling clipboard data
  123. */
  124. class TextDrag : public TQTextDrag
  125. {
  126. Q_OBJECT
  127. public:
  128. TextDrag( TQWidget * dragSource = 0L, const char * name = 0L );
  129. virtual ~TextDrag();
  130. void setPlain( TQString const & _plain ) { setText( _plain ); }
  131. void setKSpread( TQByteArray const & _kspread ) { m_kspread = _kspread; }
  132. virtual TQByteArray encodedData( const char * mime ) const;
  133. virtual const char* format( int i ) const;
  134. static bool canDecode( TQMimeSource * e );
  135. static const char * selectionMimeType();
  136. protected:
  137. TQByteArray m_kspread;
  138. };
  139. /********************************************************************
  140. *
  141. * Sheet
  142. *
  143. ********************************************************************/
  144. /**
  145. */
  146. class KSPREAD_EXPORT Sheet : public TQObject
  147. {
  148. friend class Cell;
  149. Q_OBJECT
  150. TQ_PROPERTY( TQString sheetName READ sheetName )
  151. TQ_PROPERTY( bool autoCalc READ getAutoCalc WRITE setAutoCalc )
  152. TQ_PROPERTY( bool showGrid READ getShowGrid WRITE setShowGrid )
  153. public:
  154. enum Direction { Right, Left, Up, Down };
  155. enum SortingOrder{ Increase, Decrease };
  156. enum ChangeRef { ColumnInsert, ColumnRemove, RowInsert, RowRemove };
  157. enum TestType { Text, Validity, Comment, ConditionalCellAttribute };
  158. enum LayoutDirection { LeftToRight, RightToLeft };
  159. Sheet ( Map* map, const TQString &sheetName, const char *_name=0L );
  160. ~Sheet();
  161. virtual bool isEmpty( unsigned long int x, unsigned long int y ) const;
  162. /**
  163. * Return the name of this sheet.
  164. */
  165. TQString sheetName() const;
  166. /**
  167. * \deprecated Use sheetName().
  168. */
  169. TQString tableName() const { return sheetName(); }
  170. /**
  171. * Renames a sheet. This will automatically adapt all formulas
  172. * in all sheets and all cells to reflect the new name.
  173. *
  174. * If the name really changed then @ref #sig_nameChanged is emitted
  175. * and the GUI will reflect the change.
  176. *
  177. * @param init If set to true then no formula will be changed and no signal
  178. * will be emitted and no undo action created. Usually you dont
  179. * want to do that.
  180. *
  181. *
  182. * @return false if the sheet could not be renamed. Usually the reason is
  183. * that this name is already used.
  184. *
  185. * @see #changeCellTabName
  186. * @see TabBar::renameTab
  187. * @see #sheetName
  188. */
  189. bool setSheetName( const TQString& name, bool init = false, bool makeUndo=true );
  190. Map* workbook() const;
  191. Doc* doc() const;
  192. /**
  193. * Saves the sheet and all it's children in XML format
  194. */
  195. virtual TQDomElement saveXML( TQDomDocument& );
  196. /**
  197. * Loads the sheet and all it's children in XML format
  198. */
  199. virtual bool loadXML( const TQDomElement& );
  200. virtual bool loadOasis( const TQDomElement& sheet, KoOasisLoadingContext& oasisContext, TQDict<Style>& styleMap );
  201. virtual bool saveOasis( KoXmlWriter & xmlWriter, KoGenStyles &mainStyles, GenValidationStyles &valStyle, KoStore *store, KoXmlWriter* manifestWriter, int & indexObj, int &partIndexObj );
  202. void saveOasisHeaderFooter( KoXmlWriter &xmlWriter ) const;
  203. void loadOasisObjects( const TQDomElement& e, KoOasisLoadingContext& oasisContext );
  204. void loadOasisSettings( const KoOasisSettings::NamedMap &settings );
  205. void saveOasisSettings( KoXmlWriter &settingsWriter ) const;
  206. void saveOasisPrintStyleLayout( KoGenStyle &style ) const;
  207. /**
  208. * Saves a children
  209. */
  210. virtual bool saveChildren( KoStore* _store, const TQString &_path );
  211. bool saveOasisObjects( KoStore *store, KoXmlWriter &xmlWriter, KoGenStyles& mainStyles, int & indexObj, int &partIndexObj );
  212. /**
  213. * Loads a children
  214. */
  215. virtual bool loadChildren( KoStore* _store );
  216. bool isLoading();
  217. /**
  218. * @brief Get a list of all selected objects
  219. *
  220. * @return list of selected objets.
  221. */
  222. TQPtrList<EmbeddedObject> getSelectedObjects();
  223. /**
  224. * @brief get the rect for the objects
  225. *
  226. * @param all true if the rect for all objects shoud be returned
  227. * false if only the rect for selected objects sould be returned
  228. *
  229. * @return rect of the objects
  230. */
  231. KoRect getRealRect( bool all );
  232. //return command when we move object
  233. KCommand *moveObject(View *_view, double diffx, double diffy);
  234. KCommand *moveObject(View *m_view,const KoPoint &_move,bool key);
  235. /**
  236. * @brief Create a uniq name for an object.
  237. *
  238. * Create a uniq name for the object. If no name is set for the object
  239. * a name according to its type is created. If the name already exists
  240. * append ' (x)'. // FIXME: not allowed by I18N
  241. *
  242. * @param object to work on
  243. */
  244. void unifyObjectName( EmbeddedObject *object );
  245. /**
  246. * Returns the layout direction of the sheet.
  247. */
  248. LayoutDirection layoutDirection() const;
  249. /**
  250. * Sets the layout direction of the sheet. For example, for Arabic or Hebrew
  251. * documents, it is possibly to layout the sheet from right to left.
  252. */
  253. void setLayoutDirection( LayoutDirection dir );
  254. /**
  255. * \deprecated Use direction().
  256. */
  257. bool isRightToLeft() const;
  258. void password( TQCString & passwd ) const ;
  259. bool isProtected() const;
  260. void setProtected( TQCString const & passwd );
  261. bool checkPassword( TQCString const & passwd ) const;
  262. void setDefaultHeight( double height );
  263. void setDefaultWidth( double width );
  264. const ColumnFormat* columnFormat( int _column ) const;
  265. ColumnFormat* columnFormat( int _column );
  266. /**
  267. * If no special @ref ColumnFormat exists for this column, then a new one is created.
  268. *
  269. * @return a non default ColumnFormat for this column.
  270. */
  271. ColumnFormat* nonDefaultColumnFormat( int _column, bool force_creation = true );
  272. const RowFormat* rowFormat( int _row ) const;
  273. RowFormat* rowFormat( int _row );
  274. /**
  275. * If no special @ref RowFormat exists for this row, then a new one is created.
  276. *
  277. * @return a non default RowFormat for this row.
  278. */
  279. RowFormat* nonDefaultRowFormat( int _row, bool force_creation = true );
  280. /**
  281. * @return the first cell of this sheet. Next cells can
  282. * be retrieved by calling @ref Cell::nextCell.
  283. */
  284. Cell* firstCell() const;
  285. RowFormat* firstRow() const;
  286. ColumnFormat* firstCol() const;
  287. Cell* cellAt( int _column, int _row ) const;
  288. /**
  289. * @param _scrollbar_update will change the scrollbar if set to true disregarding
  290. * whether _column/_row are bigger than
  291. * m_iMaxRow/m_iMaxColumn. May be overruled by
  292. * @ref #m_bScrollbarUpdates.
  293. */
  294. Cell* cellAt( int _column, int _row, bool _scrollbar_update = false );
  295. /**
  296. * A convenience function.
  297. */
  298. Cell* cellAt( const TQPoint& _point, bool _scrollbar_update = false )
  299. { return cellAt( _point.x(), _point.y(), _scrollbar_update ); }
  300. /**
  301. * @returns the pointer to the cell that is visible at a certain position. That means If the cell
  302. * at this position is obscured then the obscuring cell is returned.
  303. *
  304. * @param _scrollbar_update will change the scrollbar if set to true disregarding
  305. * whether _column/_row are bigger than
  306. * m_iMaxRow/m_iMaxColumn. May be overruled by
  307. * @ref #m_bScrollbarUpdates.
  308. */
  309. Cell* visibleCellAt( int _column, int _row, bool _scrollbar_update = false );
  310. /**
  311. * If no special Cell exists for this position then a new one is created.
  312. *
  313. * @param _scrollbar_update will change the scrollbar if set to true disregarding
  314. * whether _column/_row are bigger than
  315. * m_iMaxRow/m_iMaxColumn. May be overruled by
  316. * @ref #m_bScrollbarUpdates.
  317. *
  318. * @return a non default Cell for the position.
  319. */
  320. Cell* nonDefaultCell( int _column, int _row, bool _scrollbar_update = false, Style * _style = 0 );
  321. Cell* nonDefaultCell( TQPoint const & cellRef, bool scroll = false )
  322. { return nonDefaultCell( cellRef.x(), cellRef.y(), scroll ); }
  323. Cell* defaultCell() const;
  324. Format* defaultFormat();
  325. const Format* defaultFormat() const;
  326. /** retrieve a value */
  327. Value value (int col, int row) const;
  328. /** retrieve a range of values */
  329. Value valueRange (int col1, int row1, int col2, int row2) const;
  330. TQRect visibleRect( Canvas const * const _canvas ) const;
  331. int topRow( double _ypos, double &_top, const Canvas *_canvas = 0L ) const;
  332. int bottomRow( double _ypos, const Canvas *_canvas = 0L ) const;
  333. int leftColumn( double _xpos, double &_left, const Canvas *_canvas = 0L ) const;
  334. int rightColumn( double _xpos, const Canvas *_canvas = 0L ) const;
  335. /**
  336. * @return the left corner of the column as int.
  337. *
  338. * @param _canvas If not 0 then the returned position is in screen
  339. * coordinates. Otherwise the point (0|0) is in the upper
  340. * left corner of the sheet.
  341. */
  342. int columnPos( int _col, const Canvas *_canvas = 0L ) const;
  343. /**
  344. * @return the left corner of the column as double.
  345. * Use this method, when you later calculate other positions depending on this one
  346. * to avoid rounding problems
  347. *
  348. * @param _canvas If not 0 then the returned position is in screen
  349. * coordinates. Otherwise the point (0|0) is in the upper
  350. * left corner of the sheet.
  351. */
  352. double dblColumnPos( int _col, const Canvas *_canvas = 0L ) const;
  353. /**
  354. * @return the top corner of the row as int.
  355. *
  356. * @param _canvas If not 0 then the returned position is in screen
  357. * coordinates. Otherwise the point (0|0) is in the upper
  358. * top corner of the sheet.
  359. */
  360. int rowPos( int _row, const Canvas *_canvas = 0L ) const;
  361. /**
  362. * @return the top corner of the row as double.
  363. * Use this method, when you later calculate other positions depending on this one
  364. * to avoid rounding problems
  365. *
  366. * @param _canvas If not 0 then the returned position is in screen
  367. * coordinates. Otherwise the point (0|0) is in the upper
  368. * top corner of the sheet.
  369. */
  370. double dblRowPos( int _row, const Canvas *_canvas = 0L ) const;
  371. /**
  372. * @return the maximum size of the column range
  373. */
  374. double sizeMaxX() const ;
  375. /**
  376. * @return the maximum size of the row range
  377. */
  378. double sizeMaxY() const;
  379. /**
  380. * Adjusts the internal reference of the sum of the widths of all columns.
  381. * Used in resizing of columns.
  382. */
  383. void adjustSizeMaxX ( double _x );
  384. /**
  385. * Adjusts the internal reference of the sum of the heights of all rows.
  386. * Used in resizing of rows.
  387. */
  388. void adjustSizeMaxY ( double _y );
  389. /**
  390. * Sets the @ref Cell::layoutDirtyFlag in all cells.
  391. */
  392. void setLayoutDirtyFlag();
  393. /**
  394. * Sets the @ref Cell::calcDirtyFlag in all cells.
  395. * That means that the cells are marked dirty and will recalculate
  396. * if requested. This function does only MARK, it does NOT actually calculate.
  397. * Use @ref #recalc to recaculate dirty values.
  398. */
  399. void setCalcDirtyFlag();
  400. /**
  401. * Calculates all cells in the sheet with the CalcDirtyFlag.
  402. */
  403. //why on earth would we want to do this?
  404. // void calc();
  405. /**
  406. * Recalculates the current sheet. If you want to recalculate EVERYTHING, then
  407. * call @ref Sheet::setCalcDirtyFlag for all sheets in the @ref #m_pMap to make
  408. * sure that no invalid values in other sheets make you trouble.
  409. *
  410. * Recalc will do nothing if automatic calculation is disabled (via @ref Sheet::setAutoCalc ).
  411. * unless the force flag is set to true. Automatic recalculation is enabled by default.
  412. *
  413. * @param force If false, the sheet will be recalculated if automatic calculation is enabled.
  414. * If true, the sheet will be recalculated regardless of the automatic calculation setting.
  415. */
  416. void recalc( bool force );
  417. /**
  418. * Recalculates the current sheet, if automatic recalculation is enabled.
  419. */
  420. void recalc();
  421. /** handles the fact that a cell has been changed - updates
  422. things that need to be updated */
  423. void valueChanged (Cell *cell);
  424. /**
  425. * Attempts to guess the title (or 'header') of a column, within a given area of the sheet
  426. * This is used, for example, by the Data Sort dialog, to guess the names of columns
  427. * within the selected area. An empty string may be returned if guessColumnTitle does not think
  428. * that column @p col has a title.
  429. * @param area The area within the sheet to guess from
  430. * @param col The column to find the title (or 'header') for.
  431. */
  432. TQString guessColumnTitle(TQRect& area, int col);
  433. /**
  434. * Attempts to guess the title (or 'header') of a row, within a given area of the sheet
  435. * This is used, for example, by the Data Sort dialog, to guess the names of rows within the selected area.
  436. * An empty string may be returned if guessRowTitle does not think that row @p row has a title.
  437. * @param area The area within the sheet to guess from
  438. * @param row The row to find the title (or 'header') for.
  439. */
  440. TQString guessRowTitle(TQRect& area, int row);
  441. /**
  442. * Sets the contents of the cell at row,column to text
  443. */
  444. void setText( int row, int column, const TQString& text,
  445. bool asString = false );
  446. void setArrayFormula (Selection *selectionInfo, const TQString &_text);
  447. void setSelectionFont( Selection* selectionInfo,
  448. const char *_font = 0L, int _size = -1,
  449. signed char _bold = -1, signed char _italic = -1,
  450. signed char _underline = -1,
  451. signed char _strike = -1 );
  452. void setSelectionMoneyFormat( Selection* selectionInfo, bool b );
  453. void setSelectionAlign( Selection* selectionInfo,
  454. Format::Align _align );
  455. void setSelectionAlignY( Selection* selectionInfo,
  456. Format::AlignY _alignY );
  457. void setSelectionPrecision( Selection* selectionInfo, int _delta );
  458. void setSelectionPercent( Selection* selectionInfo, bool b );
  459. void setSelectionMultiRow( Selection* selectionInfo, bool enable );
  460. void setSelectionStyle( Selection* selectionInfo, Style * style );
  461. /**
  462. * setSelectionSize increase or decrease font size
  463. */
  464. void setSelectionSize( Selection* selectionInfo, int _size );
  465. /**
  466. *change string to upper case if _type equals 1
  467. * or change string to lower if _type equals -1
  468. */
  469. void setSelectionUpperLower( Selection* selectionInfo, int _type );
  470. void setSelectionfirstLetterUpper( Selection* selectionInfo);
  471. void setSelectionVerticalText( Selection* selectionInfo, bool _b);
  472. void setSelectionComment( Selection* selectionInfo,
  473. const TQString &_comment);
  474. void setSelectionRemoveComment(Selection* selectionInfo);
  475. void setSelectionAngle(Selection* selectionInfo, int _value );
  476. void setSelectionTextColor( Selection* selectionInfo,
  477. const TQColor &tbColor );
  478. void setSelectionbgColor( Selection* selectionInfo,
  479. const TQColor &bg_Color );
  480. void setSelectionBorderColor( Selection* selectionInfo,
  481. const TQColor &bd_Color );
  482. /**
  483. * @param _marker is used if there is no selection currently.
  484. * In this case the cell on which the marker is will
  485. * be deleted.
  486. *
  487. */
  488. void deleteSelection( Selection* selectionInfo, bool undo = true );
  489. /**
  490. * @param _marker is used if there is no selection currently.
  491. * In this case the cell on which the marker is will
  492. * be copied.
  493. */
  494. void copySelection( Selection* selectionInfo );
  495. /**
  496. * @param _marker is used if there is no selection currently.
  497. * In this case the cell on which the marker is will
  498. * be cut.
  499. */
  500. void cutSelection( Selection* selectionInfo );
  501. /**
  502. * @param _marker is used if there is no selection currently.
  503. * In this case the cell on which the marker is will
  504. * be cleared.
  505. */
  506. void clearTextSelection( Selection* selectionInfo );
  507. void clearValiditySelection(Selection* selectionInfo );
  508. void clearConditionalSelection(Selection* selectionInfo );
  509. void fillSelection( Selection * selectionInfo, int direction );
  510. void setWordSpelling(Selection* selectionInfo,const TQString _listWord );
  511. TQString getWordSpelling(Selection* selectionInfo );
  512. /**
  513. * A convenience function which retrieves the data to be pasted
  514. * from the clipboard.
  515. */
  516. void paste( const TQRect & pasteArea, bool makeUndo = true,
  517. Paste::Mode = Paste::Normal, Paste::Operation = Paste::OverWrite,
  518. bool insert = false, int insertTo = 0, bool pasteFC = false,
  519. TQClipboard::Mode clipboardMode = TQClipboard::Clipboard );
  520. void paste( const TQByteArray & data, const TQRect & pasteArea,
  521. bool makeUndo = false, Paste::Mode= Paste::Normal, Paste::Operation = Paste::OverWrite,
  522. bool insert = false, int insertTo = 0, bool pasteFC = false );
  523. void defaultSelection( Selection* selectionInfo );
  524. /**
  525. * A function which allows to paste a text plain from the clipboard
  526. */
  527. void pasteTextPlain( TQString &_text, TQRect pasteArea);
  528. void sortByRow( const TQRect &area, int ref_row, SortingOrder );
  529. void sortByRow( const TQRect &area, int key1, int key2, int key3,
  530. SortingOrder order1, SortingOrder order2, SortingOrder order3,
  531. TQStringList const * firstKey, bool copyFormat, bool headerRow,
  532. Point const & outputPoint, bool respectCase );
  533. void sortByColumn( const TQRect &area, int ref_column, SortingOrder );
  534. void sortByColumn( const TQRect &area, int key1, int key2, int key3,
  535. SortingOrder order1, SortingOrder order2, SortingOrder order3,
  536. TQStringList const * firstKey, bool copyFormat, bool headerCol,
  537. Point const & outputPoint, bool respectCase );
  538. void swapCells( int x1, int y1, int x2, int y2, bool cpFormat );
  539. /**
  540. * @param x1, y1: values from source cell,
  541. * @param x2, y2: values from target cell
  542. * @param cpFormat: if true: cell format gets copied, too
  543. */
  544. void copyCells( int x1, int y1, int x2, int y2, bool cpFormat );
  545. void setSeries( const TQPoint &_marker, double start, double end, double step, Series mode, Series type );
  546. /**
  547. * Moves all cells of the row _marker.y() which are in
  548. * the column _marker.x() or right hand of that one position
  549. * to the right.
  550. *
  551. * @return true if the shift was possible, or false otherwise.
  552. * A reason for returning false is that there was a cell
  553. * in the right most position.
  554. */
  555. bool shiftRow( const TQRect &_rect, bool makeUndo=true );
  556. bool shiftColumn( const TQRect& rect, bool makeUndo=true );
  557. void unshiftColumn( const TQRect& rect, bool makeUndo=true );
  558. void unshiftRow( const TQRect& rect, bool makeUndo=true );
  559. /**
  560. * Moves all columns which are >= @p col one position to the right and
  561. * inserts a new and empty column. After this the sheet is redrawn.
  562. * nbCol is the number of column which are installing
  563. */
  564. bool insertColumn( int col, int nbCol=0, bool makeUndo=true );
  565. /**
  566. * Moves all rows which are >= @p row one position down and
  567. * inserts a new and empty row. After this the sheet is redrawn.
  568. */
  569. bool insertRow( int row, int nbRow=0, bool makeUndo=true );
  570. /**
  571. * Deletes the column @p col and redraws the sheet.
  572. */
  573. void removeColumn( int col, int nbCol=0, bool makeUndo=true );
  574. /**
  575. * Deletes the row @p row and redraws the sheet.
  576. */
  577. void removeRow( int row, int nbRow=0, bool makeUndo=true );
  578. /**
  579. * hide row
  580. */
  581. void hideRow(const Region&);
  582. void emitHideRow();
  583. void showRow(const Region&);
  584. /**
  585. * hide column
  586. */
  587. void hideColumn(const Region&);
  588. void emitHideColumn();
  589. void showColumn(const Region&);
  590. /**
  591. * Adjust columns and rows of a region
  592. */
  593. void adjustArea(const Region&);
  594. /**
  595. * Adjust columns of a region
  596. */
  597. void adjustColumn(const Region&);
  598. /**
  599. * Adjust rows of a region
  600. */
  601. void adjustRow(const Region&);
  602. /**
  603. * Install borders
  604. */
  605. void borderLeft( Selection* selectionInfo, const TQColor &_color );
  606. void borderTop( Selection* selectionInfo, const TQColor &_color );
  607. void borderOutline( Selection* selectionInfo, const TQColor &_color );
  608. void borderAll( Selection* selectionInfo, const TQColor &_color );
  609. void borderRemove( Selection* selectionInfo );
  610. void borderBottom( Selection* selectionInfo, const TQColor &_color );
  611. void borderRight( Selection* selectionInfo, const TQColor &_color );
  612. void setConditional( Selection* selectionInfo,
  613. TQValueList<Conditional> const & newConditions );
  614. void setValidity( Selection* selectionInfo, KSpread::Validity tmp );
  615. /**
  616. * Returns, if the grid shall be shown on the screen
  617. */
  618. bool getShowGrid() const;
  619. /**
  620. * Sets, if the grid shall be shown on the screen
  621. */
  622. void setShowGrid( bool _showGrid );
  623. /**
  624. * Sets, if formula shall be shown instead of the result
  625. */
  626. bool getShowFormula() const;
  627. void setShowFormula(bool _showFormula);
  628. /**
  629. * Sets, if indicator must be shown when the cell holds a formula
  630. */
  631. bool getShowFormulaIndicator() const;
  632. void setShowFormulaIndicator(bool _showFormulaIndicator);
  633. /**
  634. * Returns true if comment indicator is visible.
  635. */
  636. bool getShowCommentIndicator() const;
  637. /**
  638. * If b is true, comment indicator is visible, otherwise
  639. * it will be hidden.
  640. */
  641. void setShowCommentIndicator( bool b );
  642. bool getLcMode() const;
  643. void setLcMode(bool _lcMode);
  644. bool getAutoCalc() const;
  645. void setAutoCalc(bool _AutoCalc);
  646. bool getShowColumnNumber() const;
  647. void setShowColumnNumber(bool _showColumnNumber);
  648. bool getHideZero() const;
  649. void setHideZero(bool _hideZero);
  650. bool getFirstLetterUpper() const;
  651. void setFirstLetterUpper(bool _firstUpper);
  652. // TODO Stefan: remove after kspread_undo.cc|h and commands.cc|h are obsolete
  653. void changeMergedCell( int /*m_iCol*/, int /*m_iRow*/, int /*m_iExtraX*/, int /*m_iExtraY*/) {}
  654. /**
  655. * @param region the region to merge
  656. * @param hor merge horizontally
  657. * @param ver merge vertically
  658. */
  659. void mergeCells( const Region& region, bool hor = false, bool ver = false );
  660. void dissociateCells( const Region &region );
  661. void increaseIndent( Selection* selectionInfo );
  662. void decreaseIndent( Selection* selectionInfo );
  663. bool areaIsEmpty(const Region& area, TestType _type = Text) ;
  664. void refreshPreference() ;
  665. void hideSheet(bool _hide);
  666. void removeSheet();
  667. TQRect selectionCellMerged(const TQRect &_sel);
  668. /**
  669. * Change name of reference when the user inserts or removes a column,
  670. * a row or a cell (= insertion of a row [or column] on a single column [or row]).
  671. * For example the formula =Sheet1!A1 is changed into =Sheet1!B1 if a Column
  672. * is inserted before A.
  673. *
  674. * @param pos the point of insertion (only one coordinate may be used, depending
  675. * on the other parameters).
  676. * @param fullRowOrColumn if true, a whole row or column has been inserted/removed.
  677. * if false, we inserted or removed a cell
  678. * @param ref see ChangeRef
  679. * @param tabname completes the pos specification by giving the sheet name
  680. * @param undo is the handler of the undo class in case of lost cell references
  681. */
  682. void changeNameCellRef( const TQPoint & pos, bool fullRowOrColumn,
  683. ChangeRef ref, TQString tabname, int NbCol = 1,
  684. UndoInsertRemoveAction * undo = 0 );
  685. void refreshRemoveAreaName(const TQString &_areaName);
  686. void refreshChangeAreaName(const TQString &_areaName);
  687. /**
  688. * Update chart when you insert or remove row or column
  689. *
  690. * @param pos the point of insertion (only one coordinate may be used, depending
  691. * on the other parameters).
  692. * @param fullRowOrColumn if true, a whole row or column has been inserted/removed.
  693. * if false, we inserted or removed a cell
  694. * @param ref see ChangeRef
  695. * @param tabname completes the pos specification by giving the sheet name
  696. */
  697. void refreshChart(const TQPoint & pos, bool fullRowOrColumn, ChangeRef ref);
  698. /**
  699. * Refresh merged cell when you insert or remove row or column
  700. */
  701. void refreshMergedCell();
  702. /**
  703. * @return true if this sheet is hidden
  704. */
  705. bool isHidden()const;
  706. /**
  707. * Hides or shows this sheets
  708. */
  709. void setHidden( bool hidden );
  710. /**
  711. * @return a painter for the hidden widget ( @ref #widget ).
  712. *
  713. * This function is useful while making formats where you
  714. * need some TQPainter related functions.
  715. */
  716. TQPainter& painter();
  717. /**
  718. * @return a hidden widget.
  719. *
  720. * @see #painter
  721. */
  722. TQWidget* widget()const;
  723. /**
  724. * @return a flag that indicates whether the sheet should paint the page breaks.
  725. *
  726. * @see #setShowPageBorders
  727. * @see #bShowPageBorders
  728. */
  729. bool isShowPageBorders() const;
  730. /**
  731. * Turns the page break lines on or off.
  732. *
  733. * @see #isShowPageBorders
  734. * @see #bShowPageBorders
  735. */
  736. void setShowPageBorders( bool _b );
  737. void addCellBinding( CellBinding *_bind );
  738. void removeCellBinding( CellBinding *_bind );
  739. CellBinding* firstCellBinding();
  740. CellBinding* nextCellBinding();
  741. /**
  742. * Used by the 'chart' to get the sheet on which the chart is build.
  743. * The cells we are interested in are in the rectangle '_range'.
  744. * The cells are stored row after row in '_list'.
  745. */
  746. bool getCellRectangle( const TQRect &_range, TQPtrList<Cell> &_list );
  747. /**
  748. * A convenience function that finds a sheet by its name.
  749. */
  750. Sheet *findSheet( const TQString & _name );
  751. /**
  752. * Inserts the @p _cell into the sheet.
  753. * All cells depending on this cell will be actualized.
  754. * The border range will be actualized, when the cell is out of current range.
  755. */
  756. void insertCell( Cell *_cell );
  757. /**
  758. * Used by Undo.
  759. *
  760. * @see UndoDeleteColumn
  761. */
  762. void insertColumnFormat( ColumnFormat *_l );
  763. /**
  764. * Used by Undo.
  765. *
  766. * @see UndoDeleteRow
  767. */
  768. void insertRowFormat( RowFormat *_l );
  769. /**
  770. * @see #copy
  771. *
  772. * @param era set this to true if you want to encode relative references absolutely (they will
  773. * be switched back to relative references during decoding) - used for cut to clipboard
  774. */
  775. TQDomDocument saveCellRegion(const Region&, bool copy = false, bool era = false);
  776. /**
  777. * insertTo defined if you insert to the bottom or right
  778. * insert to bottom if insertTo==1
  779. * insert to right if insertTo ==-1
  780. * insertTo used just for insert/paste an area
  781. * @see #paste
  782. */
  783. bool loadSelection( const TQDomDocument& doc, const TQRect &pasteArea,
  784. int _xshift, int _yshift, bool makeUndo,
  785. Paste::Mode = Paste::Normal, Paste::Operation = Paste::OverWrite,
  786. bool insert = false, int insertTo = 0, bool paste = false );
  787. void loadSelectionUndo( const TQDomDocument & doc, const TQRect &loadArea,
  788. int _xshift, int _yshift,bool insert,int insertTo);
  789. /**
  790. * Used when you insert and paste cell
  791. * return true if it's a area
  792. * false if it's a column/row
  793. * it's used to select if you want to insert at the bottom or right
  794. * @see #paste
  795. */
  796. bool testAreaPasteInsert()const;
  797. /**
  798. * Deletes all cells in the given rectangle.
  799. * The display is NOT updated by this function.
  800. * This function can be used to clear an area before you paste something from the clipboard
  801. * in this area.
  802. *
  803. * @param region The region that contains the cells that should be deleted
  804. *
  805. * @see #loadCells
  806. */
  807. void deleteCells(const Region& region);
  808. /**
  809. * Return true if there are text value in cell
  810. * so you can create list selection
  811. */
  812. bool testListChoose(Selection* selectionInfo);
  813. /**
  814. * returns the text to be copied to the clipboard
  815. */
  816. TQString copyAsText(Selection* selection);
  817. /**
  818. * Assume that the retangle 'src' was already selected. Then the user clicked on the
  819. * lower right corner of the marker and resized the area ( left mouse button ).
  820. * Once he releases the mouse we have to autofill the region 'dest'. Mention that
  821. * src.left() == dest.left() and src.top() == dest.top().
  822. *
  823. * @see #mouseReleaseEvent
  824. */
  825. void autofill( TQRect &src, TQRect &dest );
  826. bool insertChild( const KoRect& _geometry, KoDocumentEntry& );
  827. bool insertChart( const KoRect& _geometry, KoDocumentEntry&, const TQRect& _data );
  828. /**
  829. * Creates a new embedded picture object and inserts it into the sheet next to the currently
  830. * selected cell.
  831. *
  832. * TODO: Remove this method in future and provide a better way of opening pictures and inserting
  833. * them into the sheet.
  834. *
  835. * @param file The URL of the file to insert.
  836. * @param point The the top-left point in the sheet where the picture should be inserted.
  837. */
  838. bool insertPicture( const KoPoint& point , const KURL& file );
  839. /**
  840. * Creates a new embedded picture object and inserts it into the sheet at the specified position.
  841. *
  842. * @param point The top-left position for the new picture object in the sheet
  843. * @param pixmap The source pixmap for the new picture
  844. */
  845. bool insertPicture( const KoPoint& point, const TQPixmap& pixmap );
  846. void changeChildGeometry( EmbeddedKOfficeObject *_child, const KoRect& _geometry );
  847. const TQColorGroup& colorGroup() { return widget()->colorGroup(); }
  848. int id() const;
  849. /**
  850. * Return the currently maximum defined column of the horizontal scrollbar.
  851. * It's always 10 times higher than the maximum access column.
  852. * In an empty sheet it starts with 256.
  853. */
  854. int maxColumn() const ;
  855. /**
  856. * Checks if the argument _column is out of the current maximum range of the vertical border
  857. * If this is the case, the current maximum value m_iMaxColumn is adjusted and the vertical border
  858. * is resized.
  859. * Use this function with care, as it involves a repaint of the border, when it is out of range.
  860. */
  861. void checkRangeHBorder ( int _column );
  862. /**
  863. * Return the currently maximum defined row of the vertical scrollbar.
  864. * It's always 10 times higher than the maximum access row.
  865. * In an empty sheet it starts with 256.
  866. */
  867. int maxRow() const ;
  868. /**
  869. * Checks if the argument _row is out of the current maximum range of the horizontal border
  870. * If this is the case, the current maximum value m_iMaxRow is adjusted and the horizontal border
  871. * is resized.
  872. * Use this function with care, as it involves a repaint of the border, when it is out of range.
  873. */
  874. void checkRangeVBorder ( int _row );
  875. void enableScrollBarUpdates( bool _enable );
  876. virtual DCOPObject* dcopObject();
  877. static Sheet* find( int _id );
  878. #ifndef NDEBUG
  879. void printDebug();
  880. #endif
  881. /**
  882. * Calculates the cell if necessary, makes its layout if necessary,
  883. * and force redraw.
  884. * Then it sets the cell's @ref Cell::m_bDisplayDirtyFlag to false.
  885. */
  886. void updateCell( Cell* _cell, int _col, int _row );
  887. /**
  888. * Like updateCell except it works on a range of cells. Use this function
  889. * rather than calling updateCell(..) on several adjacent cells so there
  890. * will be one paint event instead of several
  891. */
  892. void updateCellArea(const Region& cellArea);
  893. /**
  894. * Updates every cell on the sheet
  895. */
  896. void update();
  897. /**
  898. * repaints all visible cells
  899. */
  900. void updateView();
  901. /**
  902. * repaints all visible cells in the given rect
  903. */
  904. void updateView( TQRect const & rect );
  905. /**
  906. * repaints all visible cells in the given rect
  907. */
  908. void updateView(Region*);
  909. /**
  910. * used to refresh cells when you make redodelete
  911. */
  912. void refreshView(const Region& region);
  913. void emit_updateRow( RowFormat *_format, int _row, bool repaint = true );
  914. void emit_updateColumn( ColumnFormat *_format, int _column );
  915. /**
  916. * Needed for @ref Cell::leftBorderPen and friends, since we can not
  917. * have a static pen object.
  918. *
  919. * The returned pen has pen style NoPen set.
  920. */
  921. const TQPen& emptyPen() const ;
  922. const TQBrush& emptyBrush() const;
  923. const TQColor& emptyColor() const;
  924. void updateLocale();
  925. /**
  926. * set a region of the spreadsheet to be 'paint dirty' meaning it
  927. * needs repainted. This is not a flag on the cell itself since quite
  928. * often this needs set on a default cell
  929. */
  930. void setRegionPaintDirty(TQRect const & range);
  931. void setRegionPaintDirty(Region const & region);
  932. /**
  933. * Remove all records of 'paint dirty' cells
  934. */
  935. void clearPaintDirtyData();
  936. /**
  937. * Test whether a cell needs repainted
  938. */
  939. bool cellIsPaintDirty(TQPoint const & cell) const;
  940. /**
  941. * Retrieve the first used cell in a given column. Can be used in conjunction
  942. * with getNextCellDown to loop through a column.
  943. *
  944. * @param col The column to get the first cell from
  945. *
  946. * @return Returns a pointer to the cell, or NULL if there are no used cells
  947. * in this column
  948. */
  949. Cell* getFirstCellColumn(int col) const;
  950. /**
  951. * Retrieve the last used cell in a given column. Can be used in conjunction
  952. * with getNextCellUp to loop through a column.
  953. *
  954. * @param col The column to get the cell from
  955. *
  956. * @return Returns a pointer to the cell, or NULL if there are no used cells
  957. * in this column
  958. */
  959. Cell* getLastCellColumn(int col) const;
  960. /**
  961. * Retrieve the first used cell in a given row. Can be used in conjunction
  962. * with getNextCellRight to loop through a row.
  963. *
  964. * @param row The row to get the first cell from
  965. *
  966. * @return Returns a pointer to the cell, or NULL if there are no used cells
  967. * in this row
  968. */
  969. Cell* getFirstCellRow(int row) const;
  970. /**
  971. * Retrieve the last used cell in a given row. Can be used in conjunction
  972. * with getNextCellLeft to loop through a row.
  973. *
  974. * @param row The row to get the last cell from
  975. *
  976. * @return Returns a pointer to the cell, or NULL if there are no used cells
  977. * in this row
  978. */
  979. Cell* getLastCellRow(int row) const;
  980. /**
  981. * Retrieves the next used cell above the given col/row pair. The given
  982. * col/row pair does not need to reference a used cell.
  983. *
  984. * @param col column to start looking through
  985. * @param row the row above which to start looking.
  986. *
  987. * @return Returns the next used cell above this one, or NULL if there are none
  988. */
  989. Cell* getNextCellUp(int col, int row) const;
  990. /**
  991. * Retrieves the next used cell below the given col/row pair. The given
  992. * col/row pair does not need to reference a used cell.
  993. *
  994. * @param col column to start looking through
  995. * @param row the row below which to start looking.
  996. *
  997. * @return Returns the next used cell below this one, or NULL if there are none
  998. */
  999. Cell* getNextCellDown(int col, int row) const;
  1000. /**
  1001. * Retrieves the next used cell to the right of the given col/row pair.
  1002. * The given col/row pair does not need to reference a used cell.
  1003. *
  1004. * @param col the column after which should be searched
  1005. * @param row the row to search through
  1006. *
  1007. * @return Returns the next used cell to the right of this one, or NULL if
  1008. * there are none
  1009. */
  1010. Cell* getNextCellLeft(int col, int row) const;
  1011. /**
  1012. * Retrieves the next used cell to the left of the given col/row pair.
  1013. * The given col/row pair does not need to reference a used cell.
  1014. *
  1015. * @param col the column before which should be searched
  1016. * @param row the row to search through
  1017. *
  1018. * @return Returns the next used cell to the left of this one, or NULL if
  1019. * there are none
  1020. */
  1021. Cell* getNextCellRight(int col, int row) const;
  1022. SheetPrint * print() const;
  1023. /** returns a pointer to the dependency manager */
  1024. KSpread::DependencyManager *dependencies ();
  1025. /**
  1026. * @brief Get the amount of selected objects that belong to this sheet
  1027. *
  1028. * @return the amount of select objects in this sheet
  1029. */
  1030. int numSelected() const;
  1031. //return command when we move object
  1032. // KCommand *moveObject(KSpreadView *_view, double diffx, double diffy);
  1033. // KCommand *moveObject(KSpreadView *m_view,const KoPoint &_move,bool key);
  1034. signals:
  1035. void sig_refreshView();
  1036. void sig_updateView( Sheet *_sheet );
  1037. void sig_updateView( Sheet *_sheet, const Region& );
  1038. void sig_updateView( EmbeddedObject *obj );
  1039. void sig_updateHBorder( Sheet *_sheet );
  1040. void sig_updateVBorder( Sheet *_sheet );
  1041. void sig_updateChildGeometry( EmbeddedKOfficeObject *_child );
  1042. void sig_maxColumn( int _max_column );
  1043. void sig_maxRow( int _max_row );
  1044. /**
  1045. * @see #setSheetName
  1046. */
  1047. void sig_nameChanged( Sheet* sheet, const TQString& old_name );
  1048. /**
  1049. * Emitted if a certain area of some sheet has to be redrawn.
  1050. * That is for example the case when a new child is inserted.
  1051. */
  1052. void sig_polygonInvalidated( const TQPointArray& );
  1053. void sig_SheetHidden( Sheet* sheet);
  1054. void sig_SheetShown( Sheet* sheet);
  1055. void sig_SheetRemoved( Sheet* sheet);
  1056. void sig_SheetActivated( Sheet* );
  1057. void sig_RefreshView( Sheet* );
  1058. protected slots:
  1059. /** react on modification (add/remove) of a named area */
  1060. void slotAreaModified (const TQString &name);
  1061. protected:
  1062. /** Updates dependencies for all cells on this sheet */
  1063. void updateAllDependencies();
  1064. /**
  1065. * Change the name of a sheet in all formulas.
  1066. * When you change name sheet Sheet1 -> Price
  1067. * for all cell which refere to Sheet1, this function changes the name.
  1068. */
  1069. void changeCellTabName( TQString const & old_name,TQString const & new_name );
  1070. bool loadRowFormat( const TQDomElement& row, int &rowIndex, KoOasisLoadingContext& oasisContext, TQDict<Style>& styleMap );
  1071. /**
  1072. * Loads the properties of a column from a table:table-column element in an OASIS XML file
  1073. * defaultColumnCellStyles is a map from column indicies to the default cell style for that column
  1074. */
  1075. bool loadColumnFormat(const TQDomElement& row, const KoOasisStyles& oasisStyles, int & indexCol, const TQDict<Style>& styleMap);
  1076. bool loadSheetStyleFormat( TQDomElement *style );
  1077. void loadOasisMasterLayoutPage( KoStyleStack &styleStack );
  1078. TQString saveOasisSheetStyleName( KoGenStyles &mainStyles );
  1079. void saveOasisColRowCell( KoXmlWriter& xmlWriter, KoGenStyles &mainStyles, int maxCols, int maxRows, GenValidationStyles &valStyle );
  1080. void saveOasisCells( KoXmlWriter& xmlWriter, KoGenStyles &mainStyles, int row, int maxCols, GenValidationStyles &valStyle );
  1081. void convertPart( const TQString & part, KoXmlWriter & writer ) const;
  1082. void addText( const TQString & text, KoXmlWriter & writer ) const;
  1083. void maxRowCols( int & maxCols, int & maxRows );
  1084. bool compareRows( int row1, int row2, int & maxCols ) const;
  1085. TQString getPart( const TQDomNode & part );
  1086. void replaceMacro( TQString & text, const TQString & old, const TQString & newS );
  1087. void insertObject( EmbeddedObject *_obj );
  1088. /**
  1089. * @see #autofill
  1090. */
  1091. void fillSequence( TQPtrList<Cell>& _srcList, TQPtrList<Cell>& _destList, TQPtrList<AutoFillSequence>& _seqList, bool down = true );
  1092. static int s_id;
  1093. static TQIntDict<Sheet>* s_mapSheets;
  1094. public:
  1095. // see kspread_sheet.cc for an explanation of this
  1096. // this is for type B and also for type A (better use CellWorkerTypeA for that)
  1097. struct CellWorker
  1098. {
  1099. const bool create_if_default;
  1100. const bool emit_signal;
  1101. const bool type_B;
  1102. CellWorker( bool cid=true, bool es=true, bool tb=true ) : create_if_default( cid ), emit_signal( es ), type_B( tb ) { }
  1103. virtual ~CellWorker() { }
  1104. virtual class UndoAction* createUndoAction( Doc* doc, Sheet* sheet, const Region& region ) =0;
  1105. // these are only needed for type A
  1106. virtual bool testCondition( RowFormat* ) { return false; }
  1107. virtual void doWork( RowFormat* ) { }
  1108. virtual void doWork( ColumnFormat* ) { }
  1109. virtual void prepareCell( Cell* ) { }
  1110. // these are needed in all CellWorkers
  1111. virtual bool testCondition( Cell* cell ) =0;
  1112. virtual void doWork( Cell* cell, bool cellRegion, int x, int y ) =0;
  1113. };
  1114. // this is for type A (surprise :))
  1115. struct CellWorkerTypeA : public CellWorker
  1116. {
  1117. CellWorkerTypeA( ) : CellWorker( true, true, false ) { }
  1118. virtual TQString getUndoTitle( ) =0;
  1119. class UndoAction* createUndoAction( Doc* doc, Sheet* sheet, const Region& region );
  1120. };
  1121. protected:
  1122. typedef enum { CompleteRows, CompleteColumns, CellRegion } SelectionType;
  1123. SelectionType workOnCells( Selection* selectionInfo,
  1124. CellWorker& worker );
  1125. private:
  1126. /**
  1127. * Inserts a picture into the sheet and the given position. The picture should be added to the
  1128. * document's picture collection before calling this method.
  1129. */
  1130. bool insertPicture( const KoPoint& point, KoPicture& picture );
  1131. bool FillSequenceWithInterval (TQPtrList<Cell>& _srcList,
  1132. TQPtrList<Cell>& _destList,
  1133. TQPtrList<AutoFillSequence>& _seqList,
  1134. bool down);
  1135. void FillSequenceWithCopy (TQPtrList<Cell>& _srcList,
  1136. TQPtrList<Cell>& _destList,
  1137. bool down);
  1138. void convertObscuringBorders();
  1139. void checkCellContent(Cell * cell1, Cell * cell2, int & ret);
  1140. int adjustColumnHelper(Cell * c, int _col, int _row);
  1141. void checkContentDirection( TQString const & name );
  1142. bool objectNameExists( EmbeddedObject *object, TQPtrList<EmbeddedObject> &list );
  1143. class Private;
  1144. Private* d;
  1145. // don't allow copy or assignment
  1146. Sheet( const Sheet& );
  1147. Sheet& operator=( const Sheet& );
  1148. };
  1149. } // namespace KSpread
  1150. #endif // KSPREAD_SHEET