kspread

kspread_format.h
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
3 Copyright (C) 2000 - 2003 The KSpread Team
4 www.koffice.org/kspread
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20*/
21
22#ifndef __kspread_format_h__
23#define __kspread_format_h__
24
25#include <tqbrush.h>
26#include <tqcolor.h>
27#include <tqfont.h>
28#include <tqpen.h>
29
30#include <koffice_export.h>
31
32#include "kspread_global.h"
33
34class TQDomElement;
35class TQDomDocument;
36class DCOPObject;
37class TDELocale;
38class KoGenStyle;
39class KoGenStyles;
40class KoOasisLoadingContext;
41class KoOasisStyles;
42class KoStyleStack;
43
44namespace KSpread
45{
46class Canvas;
47class Cell;
48class Currency;
49class Sheet;
50class Style;
51
54class KSPREAD_EXPORT Format
55{
56public:
57 enum Align { Left = 1, Center = 2, Right = 3, Undefined = 4 };
58 enum AlignY { Top = 1, Middle = 2, Bottom = 3, UndefinedY = 4 };
59 enum FloatFormat { AlwaysSigned = 1, AlwaysUnsigned = 2, OnlyNegSigned = 3 };
60 enum FloatColor { NegRed = 1, AllBlack = 2, NegBrackets = 3, NegRedBrackets = 4 };
61
62 // TODO Stefan: merge with Style::FlagsSet
63 enum Properties{ PAlign = 0x01,
64 PAlignY = 0x02,
65 //PFactor was here
66 PPrefix = 0x08,
67 PPostfix = 0x10,
68 PLeftBorder = 0x20,
69 PRightBorder = 0x40,
70 PTopBorder = 0x80,
71 PBottomBorder = 0x100,
72 PFallDiagonal = 0x200,
73 PGoUpDiagonal = 0x400,
74 PBackgroundBrush = 0x800,
75 PFont = 0x1000,
76 PTextPen = 0x2000,
77 PBackgroundColor = 0x4000,
78 PFloatFormat = 0x8000,
79 PFloatColor = 0x10000,
80 PMultiRow = 0x20000,
81 PVerticalText = 0x40000,
82 PPrecision = 0x80000,
83 PFormatType = 0x100000,
84 PAngle = 0x200000,
85 PComment = 0x400000,
86 PIndent = 0x800000,
87 PDontPrintText = 0x1000000,
88 PCustomFormat = 0x2000000,
89 PNotProtected = 0x4000000,
90 PHideAll = 0x8000000,
91 PHideFormula = 0x10000000 };
92
93 struct Currency
94 {
95 int type;
96 TQString symbol;
97 };
98
108 Format( Sheet* sheet, Style* style );
114 virtual ~Format();
115
116 void copy( const Format& other );
117
118 void defaultStyleFormat();
119
121 //
122 // Loading and saving
123 //
125
126 bool load( const TQDomElement & f, Paste::Mode pm, bool paste = false );
127 bool loadFormat( const TQDomElement & f, Paste::Mode pm = Paste::Normal, bool paste = false );
128 TQDomElement save( TQDomDocument& doc,int _col, int _row,bool force = false, bool copy = false ) const;
129 TQDomElement saveFormat( TQDomDocument& doc, bool force = false, bool copy = false ) const;
130 TQDomElement saveFormat( TQDomDocument& doc, int _col, int _row, bool force = false, bool copy = false ) const;
131
132 void loadOasisStyle(/* const TQDomElement& element,*/ KoOasisLoadingContext& context );
133 bool loadOasisStyleProperties(KoStyleStack & styleStack, const KoOasisStyles& oasisStyles );
134 bool loadFontOasisStyle( KoStyleStack & font );
138 TQString saveOasisCellStyle( KoGenStyle &currentCellStyle, KoGenStyles &mainStyle );
139
141 //
142 // Properties
143 //
145 uint propertiesMask() { return m_mask; } // For the cell inspector only.
146 void clearProperties();
147 void clearProperty( Properties p );
148
149 void clearNoFallBackProperties( ) ;
150 void clearNoFallBackProperties( Properties p ) ;
151 void setNoFallBackProperties(Properties p);
152 bool hasNoFallBackProperties( Properties p ) const ;
153
155 //
156 // Flags
157 //
159 enum FormatFlags{ Flag_MultiRow = 0x00000001,
160 Flag_VerticalText = 0x00000002,
161 Flag_DontPrintText = 0x00000004,
162 Flag_HideAll = 0x00000008,
163 Flag_HideFormula = 0x00000010,
164 Flag_NotProtected = 0x00000020
165 /* reserve the bits 0xFFFF0000 for subclasses to use */
166 };
167 void clearFlag( FormatFlags flag );
168 void setFlag( FormatFlags flag );
169 bool testFlag( FormatFlags flag ) const;
170
171
173 //
174 // Methods for setting format stuff.
175 //
177
178 static void setGlobalColWidth( double width );
179 static void setGlobalRowHeight( double height );
180 static double globalRowHeight();
181 static double globalColWidth();
182
183
184 void setStyle( Style * style );
185 void setCell( Cell* cell ) { m_pCell = cell; }
186
190 void setFormatString( TQString const & format );
191
192 void setAlign( Align _align );
193 void setAlignY( AlignY _alignY );
194 void setPrefix( const TQString& _prefix );
195 void setPostfix( const TQString& _postfix );
196 void setPrecision( int _p );
197
198 virtual void setLeftBorderPen( const TQPen& _p );
199 void setLeftBorderStyle( TQt::PenStyle s );
200 void setLeftBorderColor( const TQColor & _c );
201 void setLeftBorderWidth( int _w );
202
203 virtual void setTopBorderPen( const TQPen& _p );
204 void setTopBorderStyle( TQt::PenStyle s );
205 void setTopBorderColor( const TQColor & _c );
206 void setTopBorderWidth( int _w );
207
208 virtual void setRightBorderPen( const TQPen& p );
209 void setRightBorderStyle( TQt::PenStyle _s );
210 void setRightBorderColor( const TQColor & _c );
211 void setRightBorderWidth( int _w );
212
213 virtual void setBottomBorderPen( const TQPen& p );
214 void setBottomBorderStyle( TQt::PenStyle _s );
215 void setBottomBorderColor( const TQColor & _c );
216 void setBottomBorderWidth( int _w );
217
218 void setFallDiagonalPen( const TQPen& _p );
219 void setFallDiagonalStyle( TQt::PenStyle s );
220 void setFallDiagonalColor( const TQColor & _c );
221 void setFallDiagonalWidth( int _w );
222
223 void setGoUpDiagonalPen( const TQPen& _p );
224 void setGoUpDiagonalStyle( TQt::PenStyle s );
225 void setGoUpDiagonalColor( const TQColor & _c );
226 void setGoUpDiagonalWidth( int _w );
227
228 void setBackGroundBrush( const TQBrush& _p);
229 void setBackGroundBrushStyle( TQt::BrushStyle s);
230 void setBackGroundBrushColor( const TQColor & _c);
231
232 void setTextFont( const TQFont& _f );
233 void setTextFontSize( int _s );
234 void setTextFontFamily( const TQString& _f );
235 void setTextFontBold( bool _b );
236 void setTextFontItalic( bool _i );
237 void setTextFontUnderline( bool _i );
238 void setTextFontStrike( bool _i );
239
240 void setTextPen( const TQPen& _p );
241 void setTextColor( const TQColor & _c );
242
243 void setBgColor( const TQColor & _c );
244
245 void setFloatFormat( FloatFormat _f );
246 void setFloatColor( FloatColor _c );
247
248 void setMultiRow( bool _b );
249
250 void setVerticalText( bool _b );
251
252 void setFormatType(FormatType _format);
253
254 void setAngle(int _angle);
255
256 void setComment( const TQString& c );
257
258 void setIndent( double _indent );
259
260 void setDontPrintText( bool _b );
261 void setNotProtected( bool _b );
262 void setHideAll( bool _b );
263 void setHideFormula( bool _b );
264
265 void setCurrency( Currency const & c );
266 void setCurrency( int type, TQString const & symbol );
267
269 //
270 // Methods for querying format stuff.
271 //
273
274 TQString const & getFormatString( int col, int row ) const;
275
276 virtual const TQPen& leftBorderPen( int col, int row ) const;
277 int leftBorderWidth( int col, int row ) const;
278 TQt::PenStyle leftBorderStyle( int col, int row ) const;
279 const TQColor& leftBorderColor( int col, int row ) const;
280
281 virtual const TQPen& topBorderPen( int col, int row ) const;
282 int topBorderWidth( int col, int row ) const;
283 TQt::PenStyle topBorderStyle( int col, int row ) const;
284 const TQColor& topBorderColor( int col, int row ) const;
285
286 virtual const TQPen& rightBorderPen( int col, int row ) const;
287 int rightBorderWidth( int col, int row ) const;
288 TQt::PenStyle rightBorderStyle( int col, int row ) const;
289 const TQColor& rightBorderColor( int col, int row ) const;
290
291 virtual const TQPen& bottomBorderPen( int col, int row ) const;
292 int bottomBorderWidth( int col, int row ) const;
293 TQt::PenStyle bottomBorderStyle( int col, int row ) const;
294 const TQColor& bottomBorderColor( int col, int row ) const;
295
296 const TQPen& fallDiagonalPen( int col, int row ) const;
297 int fallDiagonalWidth( int col, int row ) const;
298 TQt::PenStyle fallDiagonalStyle( int col, int row ) const;
299 const TQColor& fallDiagonalColor( int col, int row ) const;
300
301 const TQPen& goUpDiagonalPen( int col, int row ) const;
302 int goUpDiagonalWidth( int col, int row ) const;
303 TQt::PenStyle goUpDiagonalStyle( int col, int row ) const;
304 const TQColor& goUpDiagonalColor( int col, int row ) const;
305
306 const TQBrush& backGroundBrush( int col, int row ) const;
307 TQt::BrushStyle backGroundBrushStyle( int col, int row ) const;
308 const TQColor& backGroundBrushColor(int col, int row ) const;
309
310 uint bottomBorderValue( int col, int row ) const;
311 uint rightBorderValue( int col, int row ) const;
312 uint leftBorderValue( int col, int row ) const;
313 uint topBorderValue( int col, int row ) const;
314
318 int precision( int col, int row ) const;
322 TQString prefix( int col, int row ) const;
326 TQString postfix( int col, int row ) const;
330 FloatFormat floatFormat( int col, int row ) const;
334 FloatColor floatColor( int col, int row ) const;
335
336 const TQPen& textPen( int col, int row ) const;
340 const TQColor& textColor( int col, int row ) const;
341
348 const TQColor& bgColor( int col, int row ) const;
349
350 const TQFont textFont( int col, int row ) const;
351 int textFontSize( int col, int row ) const;
352 TQString const & textFontFamily( int col, int row ) const;
353 bool textFontBold( int col, int row ) const;
354 bool textFontItalic( int col, int row ) const;
355 bool textFontUnderline( int col, int row ) const;
356 bool textFontStrike( int col, int row ) const;
357
358 Align align( int col, int row ) const;
359 AlignY alignY( int col, int row ) const;
360
361 bool multiRow( int col, int row ) const;
362
363 bool verticalText( int col, int row ) const;
364
365 FormatType getFormatType(int col, int row )const ;
366
367 int getAngle(int col, int row) const;
368
369 const TQString* comment() const { return m_strComment; };
370 TQString comment(int col, int row) const;
371 TQString * commentP( int col, int row ) const;
372
373 double getIndent(int col, int row) const;
374
375 bool getDontprintText( int col, int row) const;
376 bool notProtected( int col, int row) const;
377 bool isHideAll( int col, int row) const;
378 bool isHideFormula( int col, int row) const;
379 bool isProtected( int col, int row ) const;
380
381 Style* style() const { return m_pStyle; }
382 Sheet* sheet() { return m_pSheet; }
383 const Sheet* sheet() const { return m_pSheet; }
384
385 bool hasProperty( Properties p, bool withoutParent = false ) const;
386
391 bool currencyInfo( Currency & currency) const;
392
393 TQString getCurrencySymbol() const;
394 TQFont font() const;
395
396 bool operator==( const Format& other ) const;
397 inline bool operator!=( const Format& other ) const { return !operator==( other ); }
398
399protected:
400 const TQPen& rightBorderPen() const;
401 const TQPen& bottomBorderPen() const;
402
406 void formatChanged();
407
411 virtual Format* fallbackFormat( int col, int row );
415 virtual const Format* fallbackFormat( int col, int row ) const;
416
420 virtual bool isDefault() const;
421
422 Sheet * m_pSheet;
423 Style * m_pStyle;
424
425 uint m_mask;
426
431 uint m_bNoFallBack;
432
433 TQ_UINT32 m_flagsMask;
434
438 TQString * m_strComment;
439
440 // default column width and row height
441 static double s_columnWidth;
442 static double s_rowHeight;
443
444private:
445 void setProperty( Properties p );
446
450 const TQPen & leftBorderPen() const;
451 const TQPen & topBorderPen() const;
452 const TQPen & fallDiagonalPen() const;
453 const TQPen & goUpDiagonalPen() const;
454 const TQBrush & backGroundBrush() const;
455 const TQFont textFont() const;
456 const TQPen & textPen() const;
457
458 Cell* m_pCell;
459};
460
463class KSPREAD_EXPORT RowFormat : public Format
464{
465public:
466 RowFormat( Sheet * _sheet, int _row );
467 ~RowFormat();
468
469 DCOPObject* dcopObject();
470
471 TQDomElement save( TQDomDocument&, int yshift = 0, bool copy = false ) const;
472 bool load( const TQDomElement& row, int yshift = 0, Paste::Mode sp = Paste::Normal, bool paste = false );
473 bool loadOasis( const TQDomElement& row, TQDomElement * rowStyle );
474
480 int height( const Canvas *_canvas = 0L ) const;
487 double dblHeight( const Canvas *_canvas = 0L ) const;
491 double mmHeight() const;
498 void setHeight( int _h, const Canvas *_canvas = 0L );
506 void setDblHeight( double _h, const Canvas *_canvas = 0L );
512 void setMMHeight( double _h );
513
517 void setDefault() { m_bDefault = true; }
521 virtual bool isDefault() const;
522
528 int row() const { return m_iRow; }
529
530 void setRow( int _r ) { m_iRow = _r; }
531
532 void setDisplayDirtyFlag() { m_bDisplayDirtyFlag = true; }
533 void clearDisplayDirtyFlag() { m_bDisplayDirtyFlag = false; }
534
535 RowFormat* next() const { return m_next; }
536 RowFormat* previous() const { return m_prev; }
537 void setNext( RowFormat* c ) { m_next = c; }
538 void setPrevious( RowFormat* c ) { m_prev = c; }
539
543 const TQPen& bottomBorderPen( int col, int row ) const;
547 void setBottomBorderPen( const TQPen& p );
551 const TQPen& topBorderPen( int col, int row ) const;
555 void setTopBorderPen( const TQPen& p );
556
560 void setHide( bool _hide, bool repaint = true );
561 bool isHide()const { return m_bHide;}
562
563 bool operator==( const RowFormat& other ) const;
564 inline bool operator!=( const RowFormat& other ) const { return !operator==( other ); }
565
566protected:
570 virtual Format* fallbackFormat( int col, int row );
574 virtual const Format* fallbackFormat( int col, int row ) const;
575
579 double m_fHeight;
580
587 bool m_bDefault;
594 int m_iRow;
595
596 bool m_bDisplayDirtyFlag;
597 bool m_bHide;
598 RowFormat* m_next;
599 RowFormat* m_prev;
600 DCOPObject*m_dcop;
601};
602
605class KSPREAD_EXPORT ColumnFormat : public Format
606{
607public:
608 ColumnFormat( Sheet *_sheet, int _column );
609 ~ColumnFormat();
610
611 TQDomElement save( TQDomDocument&, int xshift = 0, bool copy = false ) const;
612 bool load( const TQDomElement& row, int xshift = 0,Paste::Mode sp = Paste::Normal, bool paste = false );
613 DCOPObject* dcopObject();
614
620 int width( const Canvas *_canvas = 0L ) const;
628 double dblWidth( const Canvas *_canvas = 0L ) const;
632 double mmWidth() const;
640 void setWidth( int _w, const Canvas *_canvas = 0L );
649 void setDblWidth( double _w, const Canvas *_canvas = 0L );
655 void setMMWidth( double _w );
656
660 void setDefault() { m_bDefault = true; }
664 virtual bool isDefault() const;
665
671 int column() const { return m_iColumn; }
672
673 void setColumn( int _c ) { m_iColumn = _c; }
674
675 void setDisplayDirtyFlag() { m_bDisplayDirtyFlag = true; }
676 void clearDisplayDirtyFlag() { m_bDisplayDirtyFlag = false; }
677
678 ColumnFormat* next() const { return m_next; }
679 ColumnFormat* previous() const { return m_prev; }
680 void setNext( ColumnFormat* c ) { m_next = c; }
681 void setPrevious( ColumnFormat* c ) { m_prev = c; }
682
686 virtual const TQPen& rightBorderPen( int col, int row ) const;
690 virtual void setRightBorderPen( const TQPen& p );
694 virtual const TQPen& leftBorderPen( int col, int row ) const;
698 virtual void setLeftBorderPen( const TQPen& p );
699
700 void setHide( bool _hide );
701 bool isHide()const { return m_bHide;}
702
703 bool operator==( const ColumnFormat& other ) const;
704 inline bool operator!=( const ColumnFormat& other ) const { return !operator==( other ); }
705
706protected:
710 Format* fallbackFormat( int col, int row );
714 const Format* fallbackFormat( int col, int row ) const;
715
719 double m_fWidth;
720
727 bool m_bDefault;
734 int m_iColumn;
735
736 bool m_bDisplayDirtyFlag;
737
738 bool m_bHide;
739
740 ColumnFormat* m_next;
741 ColumnFormat* m_prev;
742 DCOPObject*m_dcop;
743};
744
745class KSPREAD_EXPORT Currency
746{
747 public:
748
749 enum currencyFormat { Native, Gnumeric, OpenCalc, ApplixSpread,
750 GobeProductiveSpread, HancomSheet };
751
752 Currency();
753 ~Currency();
754
755 Currency(int index);
756
760 Currency(int index, TQString const & code);
761
768 Currency(TQString const & code, currencyFormat format = Native);
769 Currency & operator=(int type);
770 Currency & operator=(char const * code);
771 bool operator==(Currency const & cur) const;
772 bool operator==(int type) const;
773 operator int() const;
774
775 TQString getCode() const;
776 TQString getCountry() const;
777 TQString getName() const;
778 TQString getDisplayCode() const;
779 int getIndex() const;
780
781 static TQString getChooseString(int type, bool & ok);
782 static TQString getDisplaySymbol(int type);
783 static TQString getCurrencyCode( int type);
784
788 TQString getExportCode(currencyFormat format) const;
789
790 private:
791 int m_type;
792 TQString m_code;
793};
794
795} // namespace KSpread
796
797#endif
@ Format
Format only.
The KSpread namespace.
Definition commands.h:39