kspread

kspread_cell.h
1/* This file is part of the KDE project
2
3 Copyright 2006 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
4 Copyright 2004 Tomas Mecir <mecirt@gmail.com>
5 Copyright 1999-2002,2004 Laurent Montel <montel@kde.org>
6 Copyright 2002,2004 Ariya Hidayat <ariya@kde.org>
7 Copyright 2002-2003 Norbert Andres <nandres@web.de>
8 Copyright 2003 Stefan Hetzl <shetzl@chello.at>
9 Copyright 2001-2002 Philipp Mueller <philipp.mueller@gmx.de>
10 Copyright 2002 Harri Porten <porten@kde.org>
11 Copyright 2002 John Dailey <dailey@vt.edu>
12 Copyright 1999-2001 David Faure <faure@kde.org>
13 Copyright 2000-2001 Werner Trobin <trobin@kde.org>
14 Copyright 2000 Simon Hausmann <hausmann@kde.org
15 Copyright 1998-1999 Torben Weis <weis@kde.org>
16 Copyright 1999 Michael Reiher <michael.reiher.gmx.de>
17 Copyright 1999 Reginald Stadlbauer <reggie@kde.org>
18
19 This library is free software; you can redistribute it and/or
20 modify it under the terms of the GNU Library General Public
21 License as published by the Free Software Foundation; either
22 version 2 of the License, or (at your option) any later version.
23
24 This library is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 Library General Public License for more details.
28
29 You should have received a copy of the GNU Library General Public License
30 along with this library; see the file COPYING.LIB. If not, write to
31 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
32 * Boston, MA 02110-1301, USA.
33*/
34
35#ifndef KSPREAD_CELL
36#define KSPREAD_CELL
37
38#include <tqpainter.h>
39#include <tqptrlist.h>
40#include <tqdatetime.h>
41
42#include "kspread_condition.h"
43
44class TDELocale;
45class TQDomElement;
46class TQDomDocument;
47class KoXmlWriter;
48class KoGenStyles;
49class KoGenStyle;
50class KSParseNode;
51class KoRect;
52class KoPoint;
53class KoOasisStyles;
54class KoOasisLoadingContext;
55
56namespace KSpread
57{
58class Canvas;
59class Format;
60class GenValidationStyles;
61class Sheet;
62class Value;
63class View;
64class ConditionalDialog;
65
66struct Validity
67{
68 Validity()
69 {
70 valMin = 0.0;
71 valMax = 0.0;
72 m_cond = Conditional::None;
73 m_action = Action::Stop;
74 m_restriction = Restriction::None;
75 displayMessage = true;
76 allowEmptyCell = false;
77 displayValidationInformation = false;
78 };
79
80 bool operator==( const Validity& other ) const
81 {
82 if ( message == other.message &&
83 title == other.title &&
84 titleInfo == other.titleInfo &&
85 messageInfo == other.messageInfo &&
86 valMin == other.valMin &&
87 valMax == other.valMax &&
88 m_cond == other.m_cond &&
89 m_action == other.m_action &&
90 m_restriction == other.m_restriction &&
91 timeMin == other.timeMin &&
92 timeMax == other.timeMax &&
93 dateMin == other.dateMin &&
94 dateMax == other.dateMax &&
95 displayMessage == other.displayMessage &&
96 allowEmptyCell == other.allowEmptyCell &&
97 displayValidationInformation == other.displayValidationInformation &&
98 listValidity == other.listValidity )
99 {
100 return true;
101 }
102 return false;
103 }
104 inline bool operator!=( const Validity& other ) const { return !operator==( other ); }
105
106 TQString message;
107 TQString title;
108 TQString titleInfo;
109 TQString messageInfo;
110 double valMin;
111 double valMax;
112 Conditional::Type m_cond;
113 Action::Type m_action;
114 Restriction::Type m_restriction;
115 TQTime timeMin;
116 TQTime timeMax;
117 TQDate dateMin;
118 TQDate dateMax;
119 bool displayMessage;
120 bool allowEmptyCell;
121 bool displayValidationInformation;
122 TQStringList listValidity;
123};
124
125class Formula;
126
137class KSPREAD_EXPORT Cell
138{
139 friend class Conditions;
140public:
141
142 Cell (Sheet *_sheet, int _column, int _row);
143 Cell (Sheet *_sheet, Style * _style, int _column, int _row);
144
148 ~Cell();
149
153 Sheet* sheet() const;
154
159 bool isDefault() const;
160
164 bool isEmpty() const;
165
169 int column() const;
170
174 int row() const;
175
180 TQString name() const;
181
186 TQString fullName() const;
187
191 TQString columnName() const;
192
197 static TQString name( int col, int row );
198
203 static TQString fullName( const Sheet *s, int col, int row );
204
209 static TQString columnName( uint column );
210
214 TDELocale* locale() const;
218 bool isFormula() const;
219
224 TQString text() const;
225
226 TQString strOutText() const;
227
228 Formula *formula () const;
229
231 Format* format() const;
232
237 const Value value() const;
238
242 void setValue( const Value& value );
243
258 void setCellValue (const Value& value, FormatType fmtType = No_format,
259 const TQString& inputText = TQString());
260
261 Cell* previousCell() const;
262 Cell* nextCell() const;
263 void setPreviousCell( Cell* c );
264 void setNextCell( Cell* c );
265
270 void move( int column, int row );
271
275 // Note: This used to remove any links from this cell to other cells. However, this caused a problem
276 // in other parts of the code which relied upon walking from one cell to the next using
277 // nextCell().
278 void sheetDies();
279
295 TQDomElement save( TQDomDocument& doc, int _x_offset = 0, int _y_offset = 0, bool force = false, bool copy = false, bool era = false );
296
297 bool saveOasis( KoXmlWriter& xmlwriter, KoGenStyles& mainStyles,
298 int row, int column, int &repeated,
299 GenValidationStyles &valStyle );
300
301 void saveOasisValue (KoXmlWriter &xmlWriter);
302
306 TQString saveOasisCellStyle( KoGenStyle &currentCellStyle,KoGenStyles &mainStyles );
307
308 bool load( const TQDomElement& cell, int _xshift, int _yshift, Paste::Mode pm = Paste::Normal,
309 Paste::Operation op = Paste::OverWrite, bool paste = false );
310
316 bool loadOasis( const TQDomElement & element, KoOasisLoadingContext &oasisContext , Style* style);
317
318 TQTime toTime(const TQDomElement &element);
319 TQDate toDate(const TQDomElement &element);
320
326 void copyFormat( const int column, const int row );
332 void copyFormat( const Cell* cell );
333 void copyContent( const Cell* cell );
341 void copyAll( Cell *cell);
342
343 enum BorderSides
344 {
345 Border_None =0x00,
346 Border_Left =0x01,
347 Border_Right =0x02,
348 Border_Top =0x04,
349 Border_Bottom =0x08,
350 Border_SizeGrip =0x10 //the size grip is the little square on the bottom right-hand corner of a highlighted range of cells
351 //which the user can click and drag to resize the range and change which cells are included.
352 //this is not used with normal borders
353 };
354
373 void paintCell( const KoRect & rect, TQPainter & painter,
374 View * view, const KoPoint & coordinate,
375 const TQPoint & cellRef,
376 int paintBorder,
377 TQPen & rightPen,
378 TQPen & bottomPen,
379 TQPen & leftPen,
380 TQPen & topPen,
381 TQValueList<TQPoint> &mergedCellsPainted,
382 bool drawCursor = true );
383
384
392 int width( int _col = -1, const Canvas *_canvas = 0L ) const;
393
400 int height( int _row = -1, const Canvas *_canvas = 0L ) const;
401
409 double dblWidth( int _col = -1, const Canvas *_canvas = 0L ) const;
410
417 double dblHeight( int _row = -1, const Canvas *_canvas = 0L ) const;
418
422 TQRect cellRect();
423
431 bool needsPrinting() const;
432
440 void incPrecision();
448 void decPrecision();
449
454 void setCellText( const TQString& _text, bool asString = false );
455
461 void setDisplayText( const TQString& _text );
462
469 void setLink( const TQString& link );
470
475 TQString link() const;
476
478 //
479 // Methods for querying format stuff.
480 //
482
490 const TQPen & effLeftBorderPen( int col, int row ) const;
495 const TQPen & effTopBorderPen( int col, int row ) const;
500 const TQPen & effRightBorderPen( int col, int row ) const;
505 const TQPen & effBottomBorderPen( int col, int row ) const;
512 const TQPen & effGoUpDiagonalPen( int col, int row ) const;
517 const TQPen & effFallDiagonalPen( int col, int row ) const;
518 const TQColor & effTextColor( int col, int row ) const;
519
525 uint effBottomBorderValue( int col, int row ) const;
531 uint effRightBorderValue( int col, int row ) const;
537 uint effLeftBorderValue( int col, int row ) const;
543 uint effTopBorderValue( int col, int row ) const;
544
548 const TQPen& leftBorderPen( int col, int row ) const;
549
553 const TQPen& topBorderPen( int col, int row ) const;
554
558 const TQPen& rightBorderPen( int col, int row ) const;
559
563 const TQPen& bottomBorderPen( int col, int row ) const;
564
568 const TQColor& bgColor( int col, int row ) const;
569
573 const TQBrush& backGroundBrush( int col, int row ) const;
574
576 //
577 // Methods for setting format stuff.
578 //
580
584 void setLeftBorderPen( const TQPen& p );
585
589 void setTopBorderPen( const TQPen& p );
590
594 void setRightBorderPen( const TQPen& p );
595
599 void setBottomBorderPen( const TQPen& p );
600
602 //
603 // Other stuff
604 //
606
613 FormatType formatType() const;
614
616 bool isDate() const;
618 bool isTime() const;
619
620 void setNumber( double number );
621
623 double getDouble ();
624
626 void convertToDouble ();
628 void convertToPercent ();
630 void convertToMoney ();
632 void convertToTime ();
634 void convertToDate ();
635
637 double textWidth() const;
639 double textHeight() const;
640
641
648 bool updateChart(bool refresh=true);
649
650 TQString testAnchor( int _x, int _y ) const;
651
660 bool calc(bool delay = true);
661
663 void setCalcDirtyFlag();
665 bool calcDirtyFlag();
666
676 void NotifyDepending( int col, int row, Sheet* sheet, bool isDepending );
677
683 void setLayoutDirtyFlag( bool format = false );
684 bool layoutDirtyFlag() const;
685
686 void clearDisplayDirtyFlag();
687 void setDisplayDirtyFlag();
688
697 void obscure( Cell *cell, bool isForcing = false);
703 void unobscure(Cell* cell);
707 bool isObscured() const;
714 bool isPartOfMerged() const;
715
722 Cell *ultimateObscuringCell() const;
723
727 TQValueList<Cell*> obscuringCells() const;
728
729 void clearObscuringCells();
730
731
743 void mergeCells( int _col, int _row, int _x, int _y );
744
748 bool doesMergeCells() const;
749
754 int mergedXCells() const;
755
760 int mergedYCells() const;
761
765 int extraXCells() const;
766
770 int extraYCells() const;
771
772 double extraWidth() const;
773 double extraHeight() const;
774
784 TQString encodeFormula( bool _era = false, int _col = -1, int _row = -1 ) const;
785 TQString decodeFormula( const TQString &_text, int _col = -1, int _row = -1 ) const;
786
796 TQString pasteOperation( const TQString &new_text, const TQString &old_text, Paste::Operation op );
797
802 bool hasError() const;
803
807 void clearAllErrors();
808
813 void makeLayout( TQPainter &_painter, int _col, int _row );
814
820 bool makeFormula();
821
822
823 void defaultStyle();
824
828 TQValueList<Conditional> conditionList() const;
829
833 void setConditionList(const TQValueList<Conditional> &newList);
834
835 Validity * getValidity( int newStruct = -1 );
836
837 void removeValidity();
838
843 bool testValidity() const;
844
849 void calculateTextParameters( TQPainter &painter, int _col, int _row );
850
854 int defineAlignX();
855
856
857
858
862 bool operator > ( const Cell & ) const;
863 bool operator < ( const Cell & ) const;
864
865 bool operator==( const Cell& other ) const;
866 inline bool operator!=( const Cell& other ) const { return !operator==( other ); }
867
868 void freeAllObscuredCells();
869
870 /* descriptions of the flags are just below */
871 enum CellFlags{
872 /* this uses the same flags variable as Format. The least significant
873 16 bits are reserved for the base class, and the most significant 16
874 have been left for this subclass to use. */
875 Flag_LayoutDirty = 0x00010000,
876 Flag_CalcDirty = 0x00020000,
877 Flag_Progress = 0x00040000,
878 Flag_UpdatingDeps = 0x00080000,
879 Flag_DisplayDirty = 0x00100000,
880 Flag_Merged = 0x00200000,
881 Flag_CellTooShortX = 0x00400000,
882 Flag_CellTooShortY = 0x00800000,
883 Flag_ParseError = 0x01000000,
884 Flag_CircularCalculation = 0x02000000,
885 Flag_DependancyError = 0x04000000,
886 Flag_PaintingCell = 0x08000000, // On during painting
887 Flag_TextFormatDirty = 0x10000000
888 // Flag_Highlight = 0x20000000
889 };
890
891 void clearFlag( CellFlags flag );
892 void setFlag( CellFlags flag );
893 bool testFlag( CellFlags flag ) const;
894
895 /* descriptions of the flags are as follows: */
896
897 /*
898 * Error
899 * True if the cell is calculated and there was an error during calculation
900 * In that case the cell usually displays "#####"
901 *
902 * LayoutDirty
903 * Flag showing whether the current layout is OK.
904 * If you change for example the fonts point size, set this flag. When the
905 * cell must draw itself on the screen it will first recalculate its layout.
906 *
907 * CalcDirty
908 * Shows whether recalculation is necessary.
909 * If this cell must be recalculated for some reason, for example the user
910 * entered a new formula, then this flag is set. If @ref #bFormula is false
911 * nothing will happen at all.
912 *
913 * Progress
914 * Tells whether this cell it currently under calculation.
915 * If a cell thats 'progressFlag' is set is told to calculate we
916 * have detected a circular reference and we must stop calulating.
917 *
918 * UpdatingDeps
919 * Tells whether we've already calculated the reverse dependancies for this
920 * cell. Similar to the Progress flag but it's for when we are calculating
921 * in the reverse direction.
922 * @see updateDependancies()
923 *
924 * DisplayDirty - TODO - is this unused now??
925 * If this flag is set, then it is known that this cell has to be updated
926 * on the display. This means that somewhere in the calling stack there is a
927 * function which will call @ref Sheet::updateCell once it retains
928 * the control. If a function changes the contents/layout of this cell and this
929 * flag is not set, then the function must set it at once. After the changes
930 * are done the function must call <tt>m_pSheet->updateCell(...).
931 * The flag is cleared by the function format()->sheet()->updateCell.
932 *
933 * Merged
934 * Tells whether the cell is merged with other cells. Cells may
935 * occupy other cells space on demand. You may force a cell to
936 * do so by setting this flag. Merging the cell with 0 in both
937 * directions, will disable this flag!
938 *
939 * CellTooShortX
940 * When it's True displays ** and/or the red triangle and when the
941 * mouse is over it, the tooltip displays the full value
942 * it's true when text size is bigger that cell size
943 * and when Align is center or left
944 *
945 * CellTooShortY
946 * When it's True when mouseover it, the tooltip displays the full value
947 * it's true when text size is bigger that cell height
948 */
949
950protected:
954 void applyZoomedFont( TQPainter &painter, int _col, int _row );
955
960 void textSize( TQPainter &_paint );
961
966 TQString textDisplaying( TQPainter &painter);
967
973 void clearFormula();
974
983 void checkTextInput();
984
989 void checkNumberFormat();
990
995 void loadOasisCellText( const TQDomElement& parent );
996 void loadOasisObjects( const TQDomElement& e, KoOasisLoadingContext& oasisContext );
997 void loadOasisValidation( const TQString& validationName );
998
999 void loadOasisValidationCondition( TQString &valExpression );
1000 void saveOasisAnnotation( KoXmlWriter &xmlwriter );
1001 void loadOasisConditional( TQDomElement * style );
1002
1003
1004
1005private:
1006
1007 class Extra;
1008 class Private;
1009 Private *d;
1010 // static const char* s_dataTypeToString[];
1011
1012 /* helper functions to the paintCell(...) function */
1013 /* void paintCellHighlight(TQPainter& painter,
1014 const KoRect& cellRect,
1015 const TQPoint& cellRef,
1016 const int highlightBorder,
1017 const TQPen& rightPen,
1018 const TQPen& bottomPen,
1019 const TQPen& leftPen,
1020 const TQPen& topPen
1021 );*/
1022
1023
1024 void paintCellBorders( TQPainter& painter, const KoRect &rect,
1025 const KoRect &cellRect,
1026 const TQPoint &cellRef,
1027 bool paintBorderRight, bool paintBorderBottom,
1028 bool paintBorderLeft, bool paintBorderTop,
1029 TQPen & rightPen, TQPen & bottomPen,
1030 TQPen & leftPen, TQPen & topPen );
1031 void paintPageBorders( TQPainter& painter, const KoRect &cellRect,
1032 const TQPoint &cellRef,
1033 bool paintBorderRight, bool paintBorderBottom );
1034 void paintText( TQPainter& painter, const KoRect &cellRect,
1035 const TQPoint &cellRef );
1036 void paintMoreTextIndicator( TQPainter& painter, const KoRect &cellRect,
1037 TQColor &backgroundColor );
1038 void paintCommentIndicator( TQPainter& painter, const KoRect &cellRect,
1039 const TQPoint &cellRef, TQColor &backgroundColor );
1040 void paintFormulaIndicator( TQPainter& painter, const KoRect &cellRect,
1041 TQColor &backgroundColor );
1042 void paintDefaultBorders( TQPainter& painter, const KoRect &rect,
1043 const KoRect &cellRect, const TQPoint &cellRef,
1044 bool paintBorderRight, bool paintBorderBottom,
1045 bool paintBorderLeft, bool paintBorderTop,
1046 TQPen const & rightPen, TQPen const & bottomPen,
1047 TQPen const & leftPen, TQPen const & topPen );
1048 void paintBackground( TQPainter& painter, const KoRect &cellRect,
1049 const TQPoint &cellRef, bool selected,
1050 TQColor &backgroundColor );
1051 void paintObscuredCells( const KoRect& rect, TQPainter& painter,
1052 View* view, const KoRect &cellRect,
1053 const TQPoint &cellRef,
1054 bool paintBorderRight, bool paintBorderBottom,
1055 bool paintBorderLeft, bool paintBorderTop,
1056 TQPen & rightPen, TQPen & bottomPen,
1057 TQPen & leftPen, TQPen & topPen,
1058 TQValueList<TQPoint> &mergedCellsPainted );
1059 void paintCellDiagonalLines( TQPainter& painter, const KoRect &cellRect,
1060 const TQPoint &cellRef );
1061
1062
1063
1064
1067 void valueChanged ();
1068
1069 /* helper functions to the makeLayout(...) function */
1070 /* (more to come) */
1071 void setOutputText();
1072
1073
1074 /* helper functions to the load/save routines */
1075 bool loadCellData(const TQDomElement &text, Paste::Operation op);
1076 bool saveCellResult( TQDomDocument& doc, TQDomElement& result,
1077 TQString str );
1078 void update();
1079 int effAlignX();
1080
1086 void offsetAlign( int _col, int _row );
1087
1088 void checkForNamedAreas( TQString & formula ) const;
1096 TQString convertFormulaToOasisFormat( const TQString & formula ) const;
1097 void loadOasisValidationValue( const TQStringList &listVal );
1098
1099};
1100
1101} // namespace KSpread
1102
1103#endif // KSPREAD_CELL
The canvas builds a part of the GUI of KSpread.
For every cell in the spread sheet there is a Cell object.
void NotifyDepending(int col, int row, Sheet *sheet, bool isDepending)
Notify this cell that another cell is depending, or no longer depending on this cell's value.
Manages a set of conditions for a cell.
Class Formula encapsulates a formula for a cell.
Definition formula.h:239
The Style class represents a cell style.
Provides a wrapper for cell value.
The View class displays a KSpread document.
Operation
The current cell value treatment.
Mode
The pasted content.
@ Format
Format only.
Type
The type of the restriction.
@ None
No restriction.
The KSpread namespace.
Definition commands.h:39