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.

1104 lines
36KB

  1. /* This file is part of the KDE project
  2. Copyright 2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
  3. Copyright 2004 Tomas Mecir <mecirt@gmail.com>
  4. Copyright 1999-2002,2004 Laurent Montel <montel@kde.org>
  5. Copyright 2002,2004 Ariya Hidayat <ariya@kde.org>
  6. Copyright 2002-2003 Norbert Andres <nandres@web.de>
  7. Copyright 2003 Stefan Hetzl <shetzl@chello.at>
  8. Copyright 2001-2002 Philipp Mueller <philipp.mueller@gmx.de>
  9. Copyright 2002 Harri Porten <porten@kde.org>
  10. Copyright 2002 John Dailey <dailey@vt.edu>
  11. Copyright 1999-2001 David Faure <faure@kde.org>
  12. Copyright 2000-2001 Werner Trobin <trobin@kde.org>
  13. Copyright 2000 Simon Hausmann <hausmann@kde.org
  14. Copyright 1998-1999 Torben Weis <weis@kde.org>
  15. Copyright 1999 Michael Reiher <michael.reiher.gmx.de>
  16. Copyright 1999 Reginald Stadlbauer <reggie@kde.org>
  17. This library is free software; you can redistribute it and/or
  18. modify it under the terms of the GNU Library General Public
  19. License as published by the Free Software Foundation; either
  20. version 2 of the License, or (at your option) any later version.
  21. This library is distributed in the hope that it will be useful,
  22. but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  24. Library General Public License for more details.
  25. You should have received a copy of the GNU Library General Public License
  26. along with this library; see the file COPYING.LIB. If not, write to
  27. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  28. * Boston, MA 02110-1301, USA.
  29. */
  30. #ifndef KSPREAD_CELL
  31. #define KSPREAD_CELL
  32. #include <tqpainter.h>
  33. #include <tqptrlist.h>
  34. #include <tqdatetime.h>
  35. #include "kspread_condition.h"
  36. class KLocale;
  37. class TQDomElement;
  38. class TQDomDocument;
  39. class KoXmlWriter;
  40. class KoGenStyles;
  41. class KoGenStyle;
  42. class KSParseNode;
  43. class KoRect;
  44. class KoPoint;
  45. class KoOasisStyles;
  46. class KoOasisLoadingContext;
  47. namespace KSpread
  48. {
  49. class Canvas;
  50. class Format;
  51. class GenValidationStyles;
  52. class Sheet;
  53. class Value;
  54. class View;
  55. class ConditionalDialog;
  56. struct Validity
  57. {
  58. Validity()
  59. {
  60. valMin = 0.0;
  61. valMax = 0.0;
  62. m_cond = Conditional::None;
  63. m_action = Action::Stop;
  64. m_restriction = Restriction::None;
  65. displayMessage = true;
  66. allowEmptyCell = false;
  67. displayValidationInformation = false;
  68. };
  69. bool operator==( const Validity& other ) const
  70. {
  71. if ( message == other.message &&
  72. title == other.title &&
  73. titleInfo == other.titleInfo &&
  74. messageInfo == other.messageInfo &&
  75. valMin == other.valMin &&
  76. valMax == other.valMax &&
  77. m_cond == other.m_cond &&
  78. m_action == other.m_action &&
  79. m_restriction == other.m_restriction &&
  80. timeMin == other.timeMin &&
  81. timeMax == other.timeMax &&
  82. dateMin == other.dateMin &&
  83. dateMax == other.dateMax &&
  84. displayMessage == other.displayMessage &&
  85. allowEmptyCell == other.allowEmptyCell &&
  86. displayValidationInformation == other.displayValidationInformation &&
  87. listValidity == other.listValidity )
  88. {
  89. return true;
  90. }
  91. return false;
  92. }
  93. inline bool operator!=( const Validity& other ) const { return !operator==( other ); }
  94. TQString message;
  95. TQString title;
  96. TQString titleInfo;
  97. TQString messageInfo;
  98. double valMin;
  99. double valMax;
  100. Conditional::Type m_cond;
  101. Action::Type m_action;
  102. Restriction::Type m_restriction;
  103. TQTime timeMin;
  104. TQTime timeMax;
  105. TQDate dateMin;
  106. TQDate dateMax;
  107. bool displayMessage;
  108. bool allowEmptyCell;
  109. bool displayValidationInformation;
  110. TQStringList listValidity;
  111. };
  112. class Formula;
  113. /**
  114. * For every cell in the spread sheet there is a Cell object.
  115. *
  116. * Cell contains format information and algorithm and it
  117. * contains the calculation algorithm.
  118. *
  119. * However, all empty cells are represented by one instace, called the
  120. * default cell. @ref #isDefault can be used to determine whether or not a Cell object represents
  121. * the default one.
  122. */
  123. class KSPREAD_EXPORT Cell
  124. {
  125. friend class Conditions;
  126. public:
  127. Cell (Sheet *_sheet, int _column, int _row);
  128. Cell (Sheet *_sheet, Style * _style, int _column, int _row);
  129. /**
  130. * @see #sheetDies
  131. */
  132. ~Cell();
  133. /**
  134. * Returns the worksheet which owns this cell.
  135. */
  136. Sheet* sheet() const;
  137. /**
  138. * Returns true if this is a default cell (with row and column equal to zero).
  139. * Normally, cell constructed within a sheet can't be a default cell.
  140. */
  141. bool isDefault() const;
  142. /**
  143. * Returns true if this cell has no content, i.e no text and no formula.
  144. */
  145. bool isEmpty() const;
  146. /**
  147. * Returns the cell's column. This could be 0 if the cell is the default cell.
  148. */
  149. int column() const;
  150. /**
  151. * Returns the cell's row. This could be 0 if the cell is the default cell.
  152. */
  153. int row() const;
  154. /**
  155. * Returns the name of the cell. For example, the cell in first column and
  156. * first row is "A1".
  157. */
  158. TQString name() const;
  159. /**
  160. * Returns the full name of the cell, i.e. including the worksheet name.
  161. * Example: "Sheet1!A1"
  162. */
  163. TQString fullName() const;
  164. /**
  165. * Returns the column name of the cell.
  166. */
  167. TQString columnName() const;
  168. /**
  169. * Given the cell position, this static function returns the name of the cell.
  170. * Example: name(5,4) will return "E4".
  171. */
  172. static TQString name( int col, int row );
  173. /**
  174. * Given the sheet and cell position, this static function returns the full name
  175. * of the cell, i.e. with the name of the sheet.
  176. */
  177. static TQString fullName( const Sheet *s, int col, int row );
  178. /**
  179. * Given the column number, this static function returns the corresponding
  180. * column name, i.e. the first column is "A", the second is "B", and so on.
  181. */
  182. static TQString columnName( uint column );
  183. /**
  184. * Returns the locale setting of this cell.
  185. */
  186. KLocale* locale() const;
  187. /**
  188. * Returns true if this cell holds a formula.
  189. */
  190. bool isFormula() const;
  191. /**
  192. * Return the text the user entered. This could be a value (e.g. "14.03")
  193. * or a formula (e.g. "=SUM(A1:A10)")
  194. */
  195. TQString text() const;
  196. TQString strOutText() const;
  197. Formula *formula () const;
  198. /** Returns the format object of this cell */
  199. Format* format() const;
  200. /**
  201. * Returns the value that this cell holds. It could be from the user
  202. * (i.e. when s/he enters a value) or a result of formula.
  203. */
  204. const Value value() const;
  205. /**
  206. * Sets the value for this cell.
  207. */
  208. void setValue( const Value& value );
  209. /**
  210. * Sets the value for this cell and its formatting and input text, if
  211. * appropriate. Can therefore be used as a replacement for setCellText,
  212. * if we don't need to parse.
  213. *
  214. * If \p inputText is empty and the cell has NO formula, the input text
  215. * is created from \p value .
  216. *
  217. * \param value the new cell value
  218. * \param fmtType the formatting type
  219. * \param inputText the new input text
  220. *
  221. * \note Calls setValue() after setting the formatting and input text.
  222. */
  223. void setCellValue (const Value& value, FormatType fmtType = No_format,
  224. const TQString& inputText = TQString());
  225. Cell* previousCell() const;
  226. Cell* nextCell() const;
  227. void setPreviousCell( Cell* c );
  228. void setNextCell( Cell* c );
  229. /**
  230. * Moves around the cell. It cares about obscured and obscuring cells and
  231. * forces, retqlayout, calculation and redrawing of the cell.
  232. */
  233. void move( int column, int row );
  234. /**
  235. * This method notifies the cell that the parent sheet is being deleted.
  236. */
  237. // Note: This used to remove any links from this cell to other cells. However, this caused a problem
  238. // in other parts of the code which relied upon walking from one cell to the next using
  239. // nextCell().
  240. void sheetDies();
  241. /**
  242. * Save this cell.
  243. * @param doc document to save cell in
  244. * @param _x_offset x offset
  245. * @param _y_offset y offset
  246. * @param force if set to true, all the properties of the format are stored (used for "Copy"),
  247. * otherwise only the non-default properties will be stored.
  248. * Set this to false if you want smaller files.
  249. * @param copy if set to true, all cell formats will be copied instead of referencing the format (style name),
  250. * thus resulting in larger output (files).
  251. * Set this to false if you want smaller files.
  252. * @param era set this to true if you want to encode relative references as absolutely (they will be switched
  253. * back to relative references during decoding) - is used for cutting to clipboard
  254. * Usually this is false, to only store the properties explicitely set.
  255. */
  256. TQDomElement save( TQDomDocument& doc, int _x_offset = 0, int _y_offset = 0, bool force = false, bool copy = false, bool era = false );
  257. bool saveOasis( KoXmlWriter& xmlwriter, KoGenStyles& mainStyles,
  258. int row, int column, int &repeated,
  259. GenValidationStyles &valStyle );
  260. void saveOasisValue (KoXmlWriter &xmlWriter);
  261. /**
  262. * @return the OASIS style's name
  263. */
  264. TQString saveOasisCellStyle( KoGenStyle &currentCellStyle,KoGenStyles &mainStyles );
  265. bool load( const TQDomElement& cell, int _xshift, int _yshift, Paste::Mode pm = Paste::Normal,
  266. Paste::Operation op = Paste::OverWrite, bool paste = false );
  267. /**
  268. * Loads a cell from an OASIS XML element.
  269. * @param element An OASIS XML element
  270. * @param oasisContext The loading context assoiated with the XML element
  271. */
  272. bool loadOasis( const TQDomElement & element, KoOasisLoadingContext &oasisContext , Style* style);
  273. TQTime toTime(const TQDomElement &element);
  274. TQDate toDate(const TQDomElement &element);
  275. /**
  276. * Copyies the format from the cell at the position (_column|_row).
  277. *
  278. * @see #copyAll
  279. */
  280. void copyFormat( const int column, const int row );
  281. /**
  282. * A convenience function.
  283. *
  284. * @see #copyAll
  285. */
  286. void copyFormat( const Cell* cell );
  287. void copyContent( const Cell* cell );
  288. /**
  289. * Copies the format and the content. It does not copy the #m_row and #m_column attributes.
  290. * Besides that all persistent attributes are copied. @ref #setCellText is called to set the real
  291. * content.
  292. *
  293. * @see #copyFormat
  294. */
  295. void copyAll( Cell *cell);
  296. enum BorderSides
  297. {
  298. Border_None =0x00,
  299. Border_Left =0x01,
  300. Border_Right =0x02,
  301. Border_Top =0x04,
  302. Border_Bottom =0x08,
  303. Border_SizeGrip =0x10 //the size grip is the little square on the bottom right-hand corner of a highlighted range of cells
  304. //which the user can click and drag to resize the range and change which cells are included.
  305. //this is not used with normal borders
  306. };
  307. /**
  308. * Paints the cell.
  309. *
  310. * @param rect the portion of the canvas that is actually in view
  311. * @param painter the painter object to paint on
  312. * @param view the view of this data. This may be NULL, but no selection
  313. * will be included with the painting.
  314. * @param coordinate coordinates on the painter where the top left corner
  315. * of the cell should be painted plus width and height
  316. * @param cellRef the column/row coordinates of the cell.
  317. * @param paintBorder a combination of flags from the Cell::BorderSides enum which specifies which cell borders to paint
  318. * @param rightPen pen to use to draw the right border if @p paintBorder includes the Border_Right flag
  319. * @param bottomPen pen to use to draw the bottom border if @p paintBorderBottom includes the Border_Bottom flag
  320. * @param leftPen pen to use to draw the left border if @p paintBorderLeft includes the Border_Left flag
  321. * @param topPen pen to use to draw the top border if @p paintBorderTop includes the Border_Top flag
  322. * @param mergedCellsPainted list of merged cells being painted
  323. * @param drawCursor whether to draw the cursor and selection or not
  324. */
  325. void paintCell( const KoRect & rect, TQPainter & painter,
  326. View * view, const KoPoint & coordinate,
  327. const TQPoint & cellRef,
  328. int paintBorder,
  329. TQPen & rightPen,
  330. TQPen & bottomPen,
  331. TQPen & leftPen,
  332. TQPen & topPen,
  333. TQValueList<TQPoint> &mergedCellsPainted,
  334. bool drawCursor = true );
  335. /**
  336. * @param _col the column this cell is assumed to be in.
  337. * This parameter defaults to the return value of @ref #column.
  338. * @param _canvas the canvas this cell is assumed to be in.
  339. *
  340. * @return the width of this cell as int
  341. */
  342. int width( int _col = -1, const Canvas *_canvas = 0L ) const;
  343. /**
  344. * @param _row the row this cell is assumed to be in.
  345. * @param _canvas the canvas this cell is assumed to be in.
  346. *
  347. * @return the height of this cell as int
  348. */
  349. int height( int _row = -1, const Canvas *_canvas = 0L ) const;
  350. /**
  351. * @param _canvas the canvas this cell is assumed to be in.
  352. * @param _col the column this cell is assumed to be in.
  353. * This parameter defaults to the return value of @ref #column.
  354. *
  355. * @return the width of this cell as double
  356. */
  357. double dblWidth( int _col = -1, const Canvas *_canvas = 0L ) const;
  358. /**
  359. * @param _row the row this cell is assumed to be in.
  360. * @param _canvas the canvas this cell is assumed to be in.
  361. *
  362. * @return the height of this cell as double
  363. */
  364. double dblHeight( int _row = -1, const Canvas *_canvas = 0L ) const;
  365. /**
  366. * @return a TQRect for this cell (i.e., a 1x1 rect). @see zoomedCellRect
  367. */
  368. TQRect cellRect();
  369. /**
  370. * @return true if the cell should be printed in a print out.
  371. * That si the case if it has any content, border, backgroundcolor,
  372. * or background brush.
  373. *
  374. * @see Sheet::print
  375. */
  376. bool needsPrinting() const;
  377. /**
  378. * Increases the precison of the
  379. * value displayed. Precision means here the amount of
  380. * digits behind the dot. If the current precision is the
  381. * default of -1, then it is set to the number of digits
  382. * behind the dot plus 1.
  383. */
  384. void incPrecision();
  385. /**
  386. * Decreases the precison of the
  387. * value displayed. Precision means here the amount of
  388. * digits behind the dot. If the current precision is the
  389. * default of -1, then it is set to the number of digits
  390. * behind the dot minus 1.
  391. */
  392. void decPrecision();
  393. /**
  394. * The high-level method for setting text, when the user inputs it.
  395. * It will revert back to the old text if testValidity() returns action==stop.
  396. */
  397. void setCellText( const TQString& _text, bool asString = false );
  398. /**
  399. * Sets the text in the cell when the user inputs it.
  400. * Will determine the type of contents automatically.
  401. * Called by setCellText.
  402. */
  403. void setDisplayText( const TQString& _text );
  404. /**
  405. * Sets a link for this cell. For example, setLink( "mailto:joe@somewhere.com" )
  406. * will open a new e-mail if this cell is clicked.
  407. * Possible choices for link are URL (web, ftp), e-mail address, local file,
  408. * or another cell.
  409. */
  410. void setLink( const TQString& link );
  411. /**
  412. * Returns the link associated with cell. It is empty if this cell
  413. * contains no link.
  414. */
  415. TQString link() const;
  416. ////////////////////////////////
  417. //
  418. // Methods for querying format stuff.
  419. //
  420. ////////////////////////////////
  421. /**
  422. * @return effective pen for the left border
  423. * If this cell is merged by another cell, the other cell's
  424. * left border pen. If this cell's conditional formatting contains
  425. * a left border pen and the condition is matched, the conditional
  426. * formatting's pen. Otherwise, its own left border pen.
  427. */
  428. const TQPen & effLeftBorderPen( int col, int row ) const;
  429. /**
  430. * @return effective pen for the top border
  431. * @see effLeftBorderPen
  432. */
  433. const TQPen & effTopBorderPen( int col, int row ) const;
  434. /**
  435. * @return effective pen for the right border
  436. * @see effLeftBorderPen
  437. */
  438. const TQPen & effRightBorderPen( int col, int row ) const;
  439. /**
  440. * @return effective pen for the bottom border
  441. * @see effLeftBorderPen
  442. */
  443. const TQPen & effBottomBorderPen( int col, int row ) const;
  444. /**
  445. * @return effective pen for the go up diagonal border
  446. * If this cell's conditional formatting contains a go up diagonal pen and
  447. * the condition is matched, the conditional formatting's pen. Otherwise,
  448. * its own go up diagonal pen.
  449. */
  450. const TQPen & effGoUpDiagonalPen( int col, int row ) const;
  451. /**
  452. * @return effective pen for the go up diagonal border
  453. * @see effGoUpDiagonalPen
  454. */
  455. const TQPen & effFallDiagonalPen( int col, int row ) const;
  456. const TQColor & effTextColor( int col, int row ) const;
  457. /**
  458. * @return "worth" of the effective bottom border pen
  459. * @see Style::calculateValue
  460. * @see effLeftBorderPen
  461. */
  462. uint effBottomBorderValue( int col, int row ) const;
  463. /**
  464. * @return "worth" of the effective right border pen
  465. * @see Style::calculateValue
  466. * @see effLeftBorderPen
  467. */
  468. uint effRightBorderValue( int col, int row ) const;
  469. /**
  470. * @return "worth" of the effective left border pen
  471. * @see Style::calculateValue
  472. * @see effLeftBorderPen
  473. */
  474. uint effLeftBorderValue( int col, int row ) const;
  475. /**
  476. * @return "worth" of the effective top border pen
  477. * @see Style::calculateValue
  478. * @see effLeftBorderPen
  479. */
  480. uint effTopBorderValue( int col, int row ) const;
  481. /**
  482. * @see Format::leftBorderPen
  483. */
  484. const TQPen& leftBorderPen( int col, int row ) const;
  485. /**
  486. * @see Format::topBorderPen
  487. */
  488. const TQPen& topBorderPen( int col, int row ) const;
  489. /**
  490. * @see Format::rightBorderPen
  491. */
  492. const TQPen& rightBorderPen( int col, int row ) const;
  493. /**
  494. * @see Format::bottomBorderPen
  495. */
  496. const TQPen& bottomBorderPen( int col, int row ) const;
  497. /**
  498. * @see Format::bgColor
  499. */
  500. const TQColor& bgColor( int col, int row ) const;
  501. /**
  502. * @see Format::backGroundBrush
  503. */
  504. const TQBrush& backGroundBrush( int col, int row ) const;
  505. ////////////////////////////////
  506. //
  507. // Methods for setting format stuff.
  508. //
  509. ////////////////////////////////
  510. /**
  511. * @see Format::setLeftBorderPen
  512. */
  513. void setLeftBorderPen( const TQPen& p );
  514. /**
  515. * @see Format::setTopBorderPen
  516. */
  517. void setTopBorderPen( const TQPen& p );
  518. /**
  519. * @see Format::setRightBorderPen
  520. */
  521. void setRightBorderPen( const TQPen& p );
  522. /**
  523. * @see Format::setBottomBorderPen
  524. */
  525. void setBottomBorderPen( const TQPen& p );
  526. //////////////////////
  527. //
  528. // Other stuff
  529. //
  530. //////////////////////
  531. /**
  532. * Return the format of this cell.
  533. * Convenience method for Format::getFormatType
  534. * Note that this is "how the user would like the data to be displayed if possible".
  535. * If he selects a date format, and the cell contains a string, we won't apply that format.
  536. */
  537. FormatType formatType() const;
  538. /** returns true, if cell format is of date type or content is a date */
  539. bool isDate() const;
  540. /** returns true, if cell format is of time type or content is a time */
  541. bool isTime() const;
  542. void setNumber( double number );
  543. /** return the cell's value as a double */
  544. double getDouble ();
  545. /** converts content to double format */
  546. void convertToDouble ();
  547. /** converts content to percentageformat */
  548. void convertToPercent ();
  549. /** converts content to money format */
  550. void convertToMoney ();
  551. /** converts content to time format */
  552. void convertToTime ();
  553. /** converts content to date format */
  554. void convertToDate ();
  555. /** return width of the text */
  556. double textWidth() const;
  557. /** return height of the text */
  558. double textHeight() const;
  559. /**
  560. * Refreshing chart
  561. * @param refresh is default true
  562. * when it's false it's just for test
  563. * it's used when you paste cell
  564. */
  565. bool updateChart(bool refresh=true);
  566. TQString testAnchor( int _x, int _y ) const;
  567. /**
  568. * Starts calculating.
  569. * @param delay true if you want to check for delay condition in doc()
  570. * false if you really have to calculate the value right now
  571. * e.g. if you sort with formula as key
  572. *
  573. * @return true on success and false on error.
  574. */
  575. bool calc(bool delay = true);
  576. /** Set the calcDirtyFlag */
  577. void setCalcDirtyFlag();
  578. /** Checks the calcDirtyFlag */
  579. bool calcDirtyFlag();
  580. /**
  581. * Notify this cell that another cell is depending, or no longer depending on this cell's value
  582. *
  583. * @param col the column of the cell
  584. * @param row the row of the cell
  585. * @param sheet the sheet that the cell is on
  586. * @param isDepending true if the cell is now depending on this one, false if it is not any longer
  587. * depending on it.
  588. */
  589. void NotifyDepending( int col, int row, Sheet* sheet, bool isDepending );
  590. /**
  591. * Causes the format to be recalculated when the cell is drawn next time.
  592. * This flag is for example set if the width of the column changes or if
  593. * some cell specific format value like font or text change.
  594. */
  595. void setLayoutDirtyFlag( bool format = false );
  596. bool layoutDirtyFlag() const;
  597. void clearDisplayDirtyFlag();
  598. void setDisplayDirtyFlag();
  599. /**
  600. * Tells this cell that the @ref Cell 'cell' obscures this one.
  601. * If this cell has to be redrawn, then the obscuring cell is redrawn instead.
  602. *
  603. * @param cell the obscuring cell
  604. * @param isForcing whether this is a forced obscuring (merged cells) or
  605. * just a temporary obscure (text overlap).
  606. */
  607. void obscure( Cell *cell, bool isForcing = false);
  608. /**
  609. * Tells this cell that it is no longer obscured.
  610. *
  611. * @param cell the cell that is no longer obscuring this one.
  612. */
  613. void unobscure(Cell* cell);
  614. /**
  615. * @return true if this cell is obscured by another.
  616. */
  617. bool isObscured() const;
  618. /**
  619. * If this cell is part of a merged cell, then the marker may
  620. * never reside on this cell.
  621. *
  622. * @return true if another cell has this one merged into itself.
  623. */
  624. bool isPartOfMerged() const;
  625. /**
  626. * Return the cell that is obscuring this one (merged cells only).
  627. * If no obscuring, return the cell itself.
  628. *
  629. * @return the cell that decides the format for the cell in question.
  630. */
  631. Cell *ultimateObscuringCell() const;
  632. /**
  633. * @return the obscuring cell list (might be empty)
  634. */
  635. TQValueList<Cell*> obscuringCells() const;
  636. void clearObscuringCells();
  637. /**
  638. * Merge a number of cells, i.e. force the cell to occupy other
  639. * cells space. If '_x' and '_y' are 0 then the merging is
  640. * disabled.
  641. *
  642. * @param _col is the column this cell is assumed to be in.
  643. * @param _row is the row this cell is assumed to be in.
  644. * @param _x tells to occupy _x additional cells in the horizontal
  645. * @param _y tells to occupy _y additional cells in the vertical
  646. *
  647. */
  648. void mergeCells( int _col, int _row, int _x, int _y );
  649. /**
  650. * @return true if the cell is forced to obscure other cells.
  651. */
  652. bool doesMergeCells() const;
  653. /**
  654. * @return the number of obscured cells in the horizontal direction as a
  655. * result of cell merging (forced obscuring)
  656. */
  657. int mergedXCells() const;
  658. /**
  659. * @return the number of obscured cells in the vertical direction as a
  660. * result of cell merging (forced obscuring)
  661. */
  662. int mergedYCells() const;
  663. /**
  664. * @return the amount of obscured cells in the horizontal direction
  665. */
  666. int extraXCells() const;
  667. /**
  668. * @return the amount of obscured cells in the vertical direction
  669. */
  670. int extraYCells() const;
  671. double extraWidth() const;
  672. double extraHeight() const;
  673. /**
  674. * encode a formula into a text representation
  675. *
  676. * @param _era encode relative references absolutely (this is used for copying
  677. * a cell to make the paste operation create a formula that points
  678. * to the original cells, not the cells at the same relative position)
  679. * @param _col row the formula is in
  680. * @param _row column the formula is in
  681. */
  682. TQString encodeFormula( bool _era = false, int _col = -1, int _row = -1 ) const;
  683. TQString decodeFormula( const TQString &_text, int _col = -1, int _row = -1 ) const;
  684. /**
  685. * Merges the @p new_text with @p old_text during a paste operation.
  686. * If both texts represent doubles, then the operation is performed on both
  687. * values and the result is returned. If both texts represents a formula or
  688. * one a formula and the other a double value, then a formula is returned.
  689. * In all other cases @p new_text is returned.
  690. *
  691. * @return the merged text.
  692. */
  693. TQString pasteOperation( const TQString &new_text, const TQString &old_text, Paste::Operation op );
  694. /**
  695. * @return true if the cell contains a formula that could not
  696. * be evaluated. These cells usually appear with "####" on the screen.
  697. */
  698. bool hasError() const;
  699. /**
  700. * Clear all error flags from the cell.
  701. */
  702. void clearAllErrors();
  703. /**
  704. * Calculates the tqlayout of the cell, i,e, determines what should be shown
  705. * for this cell, m_strOutText.
  706. */
  707. void makeLayout( TQPainter &_painter, int _col, int _row );
  708. /**
  709. * Parses the formula.
  710. * Fills #dependList and #formula.
  711. * @return false on error.
  712. */
  713. bool makeFormula();
  714. void defaultStyle();
  715. /**
  716. * Gets a copy of the list of current conditions
  717. */
  718. TQValueList<Conditional> conditionList() const;
  719. /**
  720. * Replace the old set of conditions with a new one
  721. */
  722. void setConditionList(const TQValueList<Conditional> &newList);
  723. Validity * getValidity( int newStruct = -1 );
  724. void removeValidity();
  725. /**
  726. * return true if value is good
  727. * else show a messagebox
  728. */
  729. bool testValidity() const;
  730. /**
  731. * Calculates the text parameters stored in cell
  732. * Applies font to use to @p painter
  733. */
  734. void calculateTextParameters( TQPainter &painter, int _col, int _row );
  735. /**
  736. * return align X when align is undefined
  737. */
  738. int defineAlignX();
  739. /**
  740. * Used for comparing cells (when sorting)
  741. */
  742. bool operator > ( const Cell & ) const;
  743. bool operator < ( const Cell & ) const;
  744. bool operator==( const Cell& other ) const;
  745. inline bool operator!=( const Cell& other ) const { return !operator==( other ); }
  746. void freeAllObscuredCells();
  747. /* descriptions of the flags are just below */
  748. enum CellFlags{
  749. /* this uses the same flags variable as Format. The least significant
  750. 16 bits are reserved for the base class, and the most significant 16
  751. have been left for this subclass to use. */
  752. Flag_LayoutDirty = 0x00010000,
  753. Flag_CalcDirty = 0x00020000,
  754. Flag_Progress = 0x00040000,
  755. Flag_UpdatingDeps = 0x00080000,
  756. Flag_DisplayDirty = 0x00100000,
  757. Flag_Merged = 0x00200000,
  758. Flag_CellTooShortX = 0x00400000,
  759. Flag_CellTooShortY = 0x00800000,
  760. Flag_ParseError = 0x01000000,
  761. Flag_CircularCalculation = 0x02000000,
  762. Flag_DependancyError = 0x04000000,
  763. Flag_PaintingCell = 0x08000000, // On during painting
  764. Flag_TextFormatDirty = 0x10000000
  765. // Flag_Highlight = 0x20000000
  766. };
  767. void clearFlag( CellFlags flag );
  768. void setFlag( CellFlags flag );
  769. bool testFlag( CellFlags flag ) const;
  770. /* descriptions of the flags are as follows: */
  771. /*
  772. * Error
  773. * True if the cell is calculated and there was an error during calculation
  774. * In that case the cell usually displays "#####"
  775. *
  776. * LayoutDirty
  777. * Flag showing whether the current tqlayout is OK.
  778. * If you change for example the fonts point size, set this flag. When the
  779. * cell must draw itself on the screen it will first recalculate its tqlayout.
  780. *
  781. * CalcDirty
  782. * Shows whether recalculation is necessary.
  783. * If this cell must be recalculated for some reason, for example the user
  784. * entered a new formula, then this flag is set. If @ref #bFormula is false
  785. * nothing will happen at all.
  786. *
  787. * Progress
  788. * Tells whether this cell it currently under calculation.
  789. * If a cell thats 'progressFlag' is set is told to calculate we
  790. * have detected a circular reference and we must stop calulating.
  791. *
  792. * UpdatingDeps
  793. * Tells whether we've already calculated the reverse dependancies for this
  794. * cell. Similar to the Progress flag but it's for when we are calculating
  795. * in the reverse direction.
  796. * @see updateDependancies()
  797. *
  798. * DisplayDirty - TODO - is this unused now??
  799. * If this flag is set, then it is known that this cell has to be updated
  800. * on the display. This means that somewhere in the calling stack there is a
  801. * function which will call @ref Sheet::updateCell once it retains
  802. * the control. If a function changes the contents/tqlayout of this cell and this
  803. * flag is not set, then the function must set it at once. After the changes
  804. * are done the function must call <tt>m_pSheet->updateCell(...).
  805. * The flag is cleared by the function format()->sheet()->updateCell.
  806. *
  807. * Merged
  808. * Tells whether the cell is merged with other cells. Cells may
  809. * occupy other cells space on demand. You may force a cell to
  810. * do so by setting this flag. Merging the cell with 0 in both
  811. * directions, will disable this flag!
  812. *
  813. * CellTooShortX
  814. * When it's True displays ** and/or the red triangle and when the
  815. * mouse is over it, the tooltip displays the full value
  816. * it's true when text size is bigger that cell size
  817. * and when Align is center or left
  818. *
  819. * CellTooShortY
  820. * When it's True when mouseover it, the tooltip displays the full value
  821. * it's true when text size is bigger that cell height
  822. */
  823. protected:
  824. /**
  825. * Applies the font to use to @p painter
  826. */
  827. void applyZoomedFont( TQPainter &painter, int _col, int _row );
  828. /**
  829. * Called from makeFormat() to determine the space
  830. * needed for the text.
  831. */
  832. void textSize( TQPainter &_paint );
  833. /**
  834. * Called from @ref #paintCell to determine the text
  835. * wich can be displaying.
  836. */
  837. TQString textDisplaying( TQPainter &painter);
  838. /**
  839. * Cleans up formula stuff.
  840. * Call this before you store a new formula or to delete the
  841. * formula.
  842. */
  843. void clearFormula();
  844. /**
  845. * Check the input from the user, and determine the contents of the cell accordingly
  846. * (in particular the data type).
  847. * This is to be called only when m_content == Text.
  848. *
  849. * Input: m_strText
  850. * Output: m_dataType
  851. */
  852. void checkTextInput();
  853. /**
  854. * Automatically chooses between a number format and
  855. * a scientific format (if the number is too big)
  856. */
  857. void checkNumberFormat();
  858. /**
  859. * Load the text paragraphs from an OASIS XML cell description.
  860. * @param parent The DOM element representing the cell.
  861. */
  862. void loadOasisCellText( const TQDomElement& parent );
  863. void loadOasisObjects( const TQDomElement& e, KoOasisLoadingContext& oasisContext );
  864. void loadOasisValidation( const TQString& validationName );
  865. void loadOasisValidationCondition( TQString &valExpression );
  866. void saveOasisAnnotation( KoXmlWriter &xmlwriter );
  867. void loadOasisConditional( TQDomElement * style );
  868. private:
  869. class Extra;
  870. class Private;
  871. Private *d;
  872. // static const char* s_dataTypeToString[];
  873. /* helper functions to the paintCell(...) function */
  874. /* void paintCellHighlight(TQPainter& painter,
  875. const KoRect& cellRect,
  876. const TQPoint& cellRef,
  877. const int highlightBorder,
  878. const TQPen& rightPen,
  879. const TQPen& bottomPen,
  880. const TQPen& leftPen,
  881. const TQPen& topPen
  882. );*/
  883. void paintCellBorders( TQPainter& painter, const KoRect &rect,
  884. const KoRect &cellRect,
  885. const TQPoint &cellRef,
  886. bool paintBorderRight, bool paintBorderBottom,
  887. bool paintBorderLeft, bool paintBorderTop,
  888. TQPen & rightPen, TQPen & bottomPen,
  889. TQPen & leftPen, TQPen & topPen );
  890. void paintPageBorders( TQPainter& painter, const KoRect &cellRect,
  891. const TQPoint &cellRef,
  892. bool paintBorderRight, bool paintBorderBottom );
  893. void paintText( TQPainter& painter, const KoRect &cellRect,
  894. const TQPoint &cellRef );
  895. void paintMoreTextIndicator( TQPainter& painter, const KoRect &cellRect,
  896. TQColor &backgroundColor );
  897. void paintCommentIndicator( TQPainter& painter, const KoRect &cellRect,
  898. const TQPoint &cellRef, TQColor &backgroundColor );
  899. void paintFormulaIndicator( TQPainter& painter, const KoRect &cellRect,
  900. TQColor &backgroundColor );
  901. void paintDefaultBorders( TQPainter& painter, const KoRect &rect,
  902. const KoRect &cellRect, const TQPoint &cellRef,
  903. bool paintBorderRight, bool paintBorderBottom,
  904. bool paintBorderLeft, bool paintBorderTop,
  905. TQPen const & rightPen, TQPen const & bottomPen,
  906. TQPen const & leftPen, TQPen const & topPen );
  907. void paintBackground( TQPainter& painter, const KoRect &cellRect,
  908. const TQPoint &cellRef, bool selected,
  909. TQColor &backgroundColor );
  910. void paintObscuredCells( const KoRect& rect, TQPainter& painter,
  911. View* view, const KoRect &cellRect,
  912. const TQPoint &cellRef,
  913. bool paintBorderRight, bool paintBorderBottom,
  914. bool paintBorderLeft, bool paintBorderTop,
  915. TQPen & rightPen, TQPen & bottomPen,
  916. TQPen & leftPen, TQPen & topPen,
  917. TQValueList<TQPoint> &mergedCellsPainted );
  918. void paintCellDiagonalLines( TQPainter& painter, const KoRect &cellRect,
  919. const TQPoint &cellRef );
  920. /** handle the fact that a cell has been updated - calls cellUpdated()
  921. in the parent Sheet object */
  922. void valueChanged ();
  923. /* helper functions to the makeLayout(...) function */
  924. /* (more to come) */
  925. void setOutputText();
  926. /* helper functions to the load/save routines */
  927. bool loadCellData(const TQDomElement &text, Paste::Operation op);
  928. bool saveCellResult( TQDomDocument& doc, TQDomElement& result,
  929. TQString str );
  930. void update();
  931. int effAlignX();
  932. /**
  933. * When you insert a cell at bottom or right
  934. * and the size is not the same so text offset
  935. * will not good => recalc offset
  936. */
  937. void offsetAlign( int _col, int _row );
  938. void checkForNamedAreas( TQString & formula ) const;
  939. /**
  940. * replacements:
  941. * 1. "==" -> "="
  942. * 2. "Sheet1!A1" -> "[Sheet1.A1]"
  943. * "A1" -> "[.A1]"
  944. * 3. "," -> "."
  945. */
  946. TQString convertFormulaToOasisFormat( const TQString & formula ) const;
  947. void loadOasisValidationValue( const TQStringList &listVal );
  948. };
  949. } // namespace KSpread
  950. #endif // KSPREAD_CELL