kspread

kspread_format.cpp
1/* This file is part of the KDE project Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
2 Copyright (C) 2000 - 2005 The KSpread Team
3 www.koffice.org/kspread
4
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
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include <float.h>
22#include <iostream>
23#include <stdlib.h>
24#include <stdio.h>
25
26#include <dcopobject.h>
27#include <kdebug.h>
28#include <tdelocale.h>
29
30#include <KoXmlNS.h>
31#include <KoGenStyles.h>
32#include <KoGlobal.h>
33#include <KoStyleStack.h>
34#include <KoOasisLoadingContext.h>
35#include <KoOasisStyles.h>
36
37#include "kspread_canvas.h"
38#include "kspread_doc.h"
39#include "kspread_global.h"
40#include "kspread_sheet.h"
41#include "kspread_sheetprint.h"
42#include "kspread_style.h"
43#include "kspread_style_manager.h"
44#include "KSpreadColumnIface.h"
45#include "KSpreadLayoutIface.h"
46#include "KSpreadRowIface.h"
47
48#include "kspread_format.h"
49
50using namespace std;
51using namespace KSpread;
52
53/*****************************************************************************
54 *
55 * Format
56 *
57 *****************************************************************************/
58
59// static variable construction
60// NOTE Stefan: These values are always overridden by the Doc c'tor.
61double Format::s_columnWidth = 100.0;
62double Format::s_rowHeight = 20.0;
63
64Format::Format( Sheet * _sheet, Style * _style )
65 : m_pSheet( _sheet ),
66 m_pStyle( _style ),
67 m_mask( 0 ),
68 m_bNoFallBack( 0 ),
69 m_flagsMask( 0 ),
70 m_strComment( 0 ),
71 m_pCell( 0 )
72{
73}
74
75Format::~Format()
76{
77 if ( m_pStyle->release() )
78 delete m_pStyle;
79}
80
81void Format::defaultStyleFormat()
82{
83 if ( m_pStyle->release() )
84 delete m_pStyle;
85
86 if ( m_pSheet )
87 m_pStyle = m_pSheet->doc()->styleManager()->defaultStyle();
88
89 delete m_strComment;
90}
91
92
93void Format::setGlobalColWidth( double width )
94{
95 s_columnWidth = width;
96}
97
98void Format::setGlobalRowHeight( double height )
99{
100 s_rowHeight = height;
101}
102
103double Format::globalRowHeight()
104{
105 return s_rowHeight;
106}
107
108double Format::globalColWidth()
109{
110 return s_columnWidth;
111}
112
113void Format::copy( const Format & _l )
114{
115 // TODO why is the sheet not copied?
116
117 setStyle( _l.m_pStyle );
118
119 m_mask = _l.m_mask;
120 m_flagsMask = _l.m_flagsMask;
121 m_bNoFallBack = _l.m_bNoFallBack;
122
123 if ( _l.m_strComment )
124 {
125 if (m_strComment)
126 delete m_strComment;
127 m_strComment = new TQString( *_l.m_strComment );
128 }
129}
130
131void Format::setStyle( Style * style )
132{
133 if ( style == m_pStyle )
134 return;
135
136 if ( m_pStyle && m_pStyle->release() )
137 delete m_pStyle;
138
139 m_bNoFallBack = 0;
140 m_pStyle = style;
141 m_pStyle->addRef();
142 formatChanged();
143 // kdDebug() << "Newly assigned style: " << m_pStyle << ", type: " << m_pStyle->type() << endl;
144 if ( style->type() == Style::BUILTIN || style->type() == Style::CUSTOM )
145 kdDebug() << "Style name: " << ((CustomStyle *) m_pStyle)->name() << endl;
146}
147
148void Format::clearFlag( FormatFlags flag )
149{
150 m_flagsMask &= ~(TQ_UINT32)flag;
151}
152
153void Format::setFlag( FormatFlags flag )
154{
155 m_flagsMask |= (TQ_UINT32)flag;
156}
157
158bool Format::testFlag( FormatFlags flag ) const
159{
160 return ( m_flagsMask & (TQ_UINT32)flag );
161}
162
163void Format::clearProperties()
164{
165 m_mask = 0;
166 m_pStyle->clearFeature( (Style::FlagsSet) ~(uint)0 );
167 formatChanged();
168}
169
170void Format::clearProperty( Properties p )
171{
172 m_mask &= ~(uint)p;
173 m_pStyle->clearFeature( (Style::FlagsSet) p );
174 formatChanged();
175}
176
177// FIXME according to Valgrind, this function consumes too much time
178// find a way to optimize it !
179bool Format::hasProperty( Properties p, bool withoutParent ) const
180{
181 if ( m_pStyle->hasFeature( (Style::FlagsSet) p, withoutParent ) )
182 return true;
183
184 return ( m_mask & (uint)p );
185}
186
187void Format::setProperty( Properties p )
188{
189 m_mask |= (uint)p;
190}
191
192void Format::clearNoFallBackProperties()
193{
194 m_bNoFallBack = 0;
195
196 formatChanged();
197}
198
199void Format::clearNoFallBackProperties( Properties p )
200{
201 m_bNoFallBack &= ~(uint)p;
202
203 formatChanged();
204}
205
206bool Format::hasNoFallBackProperties( Properties p ) const
207{
208 return ( m_bNoFallBack & (uint)p );
209}
210
211void Format::setNoFallBackProperties( Properties p )
212{
213 m_bNoFallBack |= (uint)p;
214}
215
216
218//
219// Loading and saving
220//
222
223
224TQString Format::saveOasisCellStyle( KoGenStyle &currentCellStyle, KoGenStyles &mainStyles )
225{
226 TQString styleName;
227 styleName = m_pStyle->saveOasis( currentCellStyle, mainStyles );
228
229 // user styles are already stored
230 if ( currentCellStyle.type() == Doc::STYLE_CELL_AUTO )
231 {
232 styleName = mainStyles.lookup( currentCellStyle, "ce" );
233 }
234
235 return styleName;
236}
237
238TQDomElement Format::saveFormat( TQDomDocument & doc, int _col, int _row, bool force, bool copy ) const
239{
240 TQDomElement format( doc.createElement( "format" ) );
241
242 if ( m_pStyle->type() == Style::BUILTIN || m_pStyle->type() == Style::CUSTOM )
243 {
244 format.setAttribute( "style-name", ((CustomStyle *) m_pStyle)->name() );
245
246 if ( !copy )
247 return format;
248 }
249 else
250 {
251 if ( m_pStyle->parent() && m_pStyle->parent()->name().length() > 0 )
252 format.setAttribute( "parent", m_pStyle->parent()->name() );
253 }
254
255 if ( hasProperty( PAlign, true ) || hasNoFallBackProperties( PAlign ) || force )
256 format.setAttribute( "align", (int) align( _col, _row ) );
257 if ( hasProperty( PAlignY, true ) || hasNoFallBackProperties( PAlignY ) || force )
258 format.setAttribute( "alignY", (int)alignY( _col, _row ) );
259 if ( ( hasProperty( PBackgroundColor, false ) || hasNoFallBackProperties( PBackgroundColor)
260 || force ) && bgColor( _col, _row ).isValid() )
261 format.setAttribute( "bgcolor", bgColor( _col, _row ).name() );
262 if ( ( hasProperty( PMultiRow, true ) || hasNoFallBackProperties( PMultiRow )
263 || force ) && multiRow( _col, _row ) )
264 format.setAttribute( "multirow", "yes" );
265 if ( ( hasProperty( PVerticalText, true ) || hasNoFallBackProperties( PVerticalText )
266 || force ) && verticalText( _col, _row ) )
267 format.setAttribute( "verticaltext", "yes" );
268 if ( hasProperty( PPrecision, true ) || hasNoFallBackProperties( PPrecision ) || force )
269 format.setAttribute( "precision", precision( _col, _row ) );
270 if ( ( hasProperty( PPrefix, true ) || hasNoFallBackProperties( PPrefix ) || force )
271 && !prefix( _col, _row ).isEmpty() )
272 format.setAttribute( "prefix", prefix( _col, _row ) );
273 if ( ( hasProperty( PPostfix, true ) || hasNoFallBackProperties( PPostfix ) || force )
274 && !postfix( _col, _row ).isEmpty() )
275 format.setAttribute( "postfix", postfix( _col, _row ) );
276 if ( hasProperty( PFloatFormat, true ) || hasNoFallBackProperties( PFloatFormat ) || force )
277 format.setAttribute( "float", (int) floatFormat( _col, _row ) );
278 if ( hasProperty( PFloatColor, true ) || hasNoFallBackProperties( PFloatColor ) || force )
279 format.setAttribute( "floatcolor", (int) floatColor( _col, _row ) );
280 if ( hasProperty( PFormatType, true ) || hasNoFallBackProperties( PFormatType ) || force )
281 format.setAttribute( "format", (int)getFormatType( _col, _row ));
282 if ( hasProperty( PCustomFormat, true ) || hasNoFallBackProperties( PCustomFormat ) || force )
283 {
284 TQString s( getFormatString( _col, _row ) );
285 if ( s.length() > 0 )
286 format.setAttribute( "custom", s );
287 }
288 if ( getFormatType( _col, _row ) == Money_format )
289 {
290 format.setAttribute( "type", (int) m_pStyle->currency().type ); // TODO: fallback?
291 format.setAttribute( "symbol", m_pStyle->currency().symbol );
292 }
293 if ( hasProperty( PAngle, true ) || hasNoFallBackProperties( PAngle ) || force )
294 format.setAttribute( "angle", getAngle( _col, _row ) );
295 if ( hasProperty( PIndent, true ) || hasNoFallBackProperties( PIndent ) || force )
296 format.setAttribute( "indent", getIndent( _col, _row ) );
297 if( ( hasProperty( PDontPrintText, true ) || hasNoFallBackProperties( PDontPrintText )
298 || force ) && getDontprintText( _col, _row ) )
299 format.setAttribute( "dontprinttext", "yes" );
300 if( ( hasProperty( PNotProtected, true ) || hasNoFallBackProperties( PNotProtected )
301 || force ) && notProtected( _col, _row ) )
302 format.setAttribute( "noprotection", "yes" );
303 if( ( hasProperty( PHideAll, true ) || hasNoFallBackProperties( PHideAll )
304 || force ) && isHideAll( _col, _row ) )
305 format.setAttribute( "hideall", "yes" );
306 if( ( hasProperty( PHideFormula, true ) || hasNoFallBackProperties( PHideFormula )
307 || force ) && isHideFormula( _col, _row ) )
308 format.setAttribute( "hideformula", "yes" );
309 if ( hasProperty( PFont, true ) || hasNoFallBackProperties( PFont ) || force )
310 format.appendChild( util_createElement( "font", textFont( _col, _row ), doc ) );
311 if ( ( hasProperty( PTextPen, true ) || hasNoFallBackProperties( PTextPen ) || force )
312 && textPen( _col, _row ).color().isValid() )
313 format.appendChild( util_createElement( "pen", textPen( _col, _row ), doc ) );
314 if ( hasProperty( PBackgroundBrush, true ) || hasNoFallBackProperties( PBackgroundBrush ) || force )
315 {
316 format.setAttribute( "brushcolor", backGroundBrushColor( _col, _row ).name() );
317 format.setAttribute( "brushstyle", (int)backGroundBrushStyle( _col, _row ) );
318 }
319 if ( hasProperty( PLeftBorder, true ) || hasNoFallBackProperties( PLeftBorder ) || force )
320 {
321 TQDomElement left = doc.createElement( "left-border" );
322 left.appendChild( util_createElement( "pen", leftBorderPen( _col, _row ), doc ) );
323 format.appendChild( left );
324 }
325 if ( hasProperty( PTopBorder, true ) || hasNoFallBackProperties( PTopBorder ) || force )
326 {
327 TQDomElement top = doc.createElement( "top-border" );
328 top.appendChild( util_createElement( "pen", topBorderPen( _col, _row ), doc ) );
329 format.appendChild( top );
330 }
331 if ( hasProperty( PRightBorder, true ) || hasNoFallBackProperties( PRightBorder ) || force )
332 {
333 TQDomElement right = doc.createElement( "right-border" );
334 right.appendChild( util_createElement( "pen", rightBorderPen( _col, _row ), doc ) );
335 format.appendChild( right );
336 }
337 if ( hasProperty( PBottomBorder, true ) || hasNoFallBackProperties( PBottomBorder ) || force )
338 {
339 TQDomElement bottom = doc.createElement( "bottom-border" );
340 bottom.appendChild( util_createElement( "pen", bottomBorderPen( _col, _row ), doc ) );
341 format.appendChild( bottom );
342 }
343 if ( hasProperty( PFallDiagonal, true ) || hasNoFallBackProperties( PFallDiagonal ) || force )
344 {
345 TQDomElement fallDiagonal = doc.createElement( "fall-diagonal" );
346 fallDiagonal.appendChild( util_createElement( "pen", fallDiagonalPen( _col, _row ), doc ) );
347 format.appendChild( fallDiagonal );
348 }
349 if ( hasProperty( PGoUpDiagonal, true ) || hasNoFallBackProperties( PGoUpDiagonal ) || force )
350 {
351 TQDomElement goUpDiagonal = doc.createElement( "up-diagonal" );
352 goUpDiagonal.appendChild( util_createElement( "pen", goUpDiagonalPen( _col, _row ), doc ) );
353 format.appendChild( goUpDiagonal );
354 }
355 return format;
356}
357
358
359TQDomElement Format::saveFormat( TQDomDocument& doc, bool force, bool copy ) const
360{
361 TQDomElement format( doc.createElement( "format" ) );
362
363 if ( m_pStyle->type() == Style::BUILTIN || m_pStyle->type() == Style::CUSTOM )
364 {
365 format.setAttribute( "style-name", ((CustomStyle *) m_pStyle)->name() );
366
367 if ( !copy )
368 return format;
369 }
370 else
371 {
372 if ( m_pStyle->parent() && m_pStyle->parentName().length() > 0 )
373 format.setAttribute( "parent", m_pStyle->parentName() );
374 }
375
376 if ( hasProperty( PAlign, true ) || hasNoFallBackProperties( PAlign ) || force )
377 format.setAttribute( "align", (int)m_pStyle->alignX() );
378 if ( hasProperty( PAlignY, true ) || hasNoFallBackProperties( PAlignY ) || force )
379 format.setAttribute( "alignY", (int)m_pStyle->alignY() );
380 if ( ( hasProperty( PBackgroundColor, true ) || hasNoFallBackProperties( PBackgroundColor )
381 || force ) && m_pStyle->bgColor().isValid() )
382 format.setAttribute( "bgcolor", m_pStyle->bgColor().name() );
383
384 if ( ( hasProperty( PMultiRow, true ) || hasNoFallBackProperties( PMultiRow ) || force )
385 && m_pStyle->hasProperty( Style::PMultiRow ) )
386 format.setAttribute( "multirow", "yes" );
387 if ( ( hasProperty( PVerticalText, true ) || hasNoFallBackProperties( PVerticalText ) || force )
388 && m_pStyle->hasProperty( Style::PVerticalText ) )
389 format.setAttribute( "verticaltext", "yes" );
390
391 if ( hasProperty( PPrecision, true ) || hasNoFallBackProperties( PPrecision ) || force )
392 format.setAttribute( "precision", m_pStyle->precision() );
393 if ( ( hasProperty( PPrefix, true ) || hasNoFallBackProperties( PPrefix ) || force )
394 && !m_pStyle->prefix().isEmpty() )
395 format.setAttribute( "prefix", m_pStyle->prefix() );
396 if ( ( hasProperty( PPostfix, true ) || hasNoFallBackProperties( PPostfix ) || force )
397 && !m_pStyle->postfix().isEmpty() )
398 format.setAttribute( "postfix", m_pStyle->postfix() );
399
400 if ( hasProperty( PFloatFormat, true ) || hasNoFallBackProperties( PFloatFormat ) || force )
401 format.setAttribute( "float", (int) m_pStyle->floatFormat() );
402 if ( hasProperty( PFloatColor, true ) || hasNoFallBackProperties( PFloatColor ) || force )
403 format.setAttribute( "floatcolor", (int) m_pStyle->floatColor() );
404 if ( hasProperty( PFormatType, true ) || hasNoFallBackProperties( PFormatType ) || force )
405 format.setAttribute( "format", (int) m_pStyle->formatType() );
406 if ( hasProperty( PCustomFormat, true ) || hasNoFallBackProperties( PCustomFormat ) || force )
407 if ( m_pStyle->strFormat().length() > 0 )
408 format.setAttribute( "custom", m_pStyle->strFormat() );
409 if ( m_pStyle->formatType() == Money_format )
410 {
411 format.setAttribute( "type", (int) m_pStyle->currency().type );
412 format.setAttribute( "symbol", m_pStyle->currency().symbol );
413 }
414 if ( hasProperty( PAngle, true ) || hasNoFallBackProperties( PAngle ) || force )
415 format.setAttribute( "angle", m_pStyle->rotateAngle() );
416 if ( hasProperty( PIndent, true ) || hasNoFallBackProperties( PIndent ) || force )
417 format.setAttribute( "indent", m_pStyle->indent() );
418 if ( ( hasProperty( PDontPrintText, true ) || hasNoFallBackProperties( PDontPrintText ) || force )
419 && m_pStyle->hasProperty( Style::PDontPrintText ) )
420 format.setAttribute( "dontprinttext", "yes" );
421 if ( ( hasProperty( PNotProtected, true ) || hasNoFallBackProperties( PNotProtected )
422 || force ) && m_pStyle->hasProperty( Style::PNotProtected ) )
423 format.setAttribute( "noprotection", "yes" );
424 if( ( hasProperty( PHideAll, true ) || hasNoFallBackProperties( PHideAll )
425 || force ) && m_pStyle->hasProperty( Style::PHideAll ) )
426 format.setAttribute( "hideall", "yes" );
427 if( ( hasProperty( PHideFormula, true ) || hasNoFallBackProperties( PHideFormula )
428 || force ) && m_pStyle->hasProperty( Style::PHideFormula ) )
429 format.setAttribute( "hideformula", "yes" );
430 if ( hasProperty( PFont, true ) || hasNoFallBackProperties( PFont ) || force )
431 format.appendChild( util_createElement( "font", m_pStyle->font(), doc ) );
432 if ( ( hasProperty( PTextPen, true ) || hasNoFallBackProperties( PTextPen ) || force )
433 && m_pStyle->pen().color().isValid() )
434 format.appendChild( util_createElement( "pen", m_pStyle->pen(), doc ) );
435 if ( hasProperty( PBackgroundBrush, true ) || hasNoFallBackProperties( PBackgroundBrush ) || force )
436 {
437 format.setAttribute( "brushcolor", m_pStyle->backGroundBrush().color().name() );
438 format.setAttribute( "brushstyle", (int) m_pStyle->backGroundBrush().style() );
439 }
440 if ( hasProperty( PLeftBorder, true ) || hasNoFallBackProperties( PLeftBorder ) || force )
441 {
442 TQDomElement left = doc.createElement( "left-border" );
443 left.appendChild( util_createElement( "pen", m_pStyle->leftBorderPen(), doc ) );
444 format.appendChild( left );
445 }
446 if ( hasProperty( PTopBorder, true ) || hasNoFallBackProperties( PTopBorder ) || force )
447 {
448 TQDomElement top = doc.createElement( "top-border" );
449 top.appendChild( util_createElement( "pen", m_pStyle->topBorderPen(), doc ) );
450 format.appendChild( top );
451 }
452 if ( hasProperty( PRightBorder, true ) || hasNoFallBackProperties( PRightBorder ) || force )
453 {
454 TQDomElement right = doc.createElement( "right-border" );
455 right.appendChild( util_createElement( "pen", m_pStyle->rightBorderPen(), doc ) );
456 format.appendChild( right );
457 }
458 if ( hasProperty( PBottomBorder, true ) || hasNoFallBackProperties( PBottomBorder ) || force )
459 {
460 TQDomElement bottom = doc.createElement( "bottom-border" );
461 bottom.appendChild( util_createElement( "pen", m_pStyle->bottomBorderPen(), doc ) );
462 format.appendChild( bottom );
463 }
464 if ( hasProperty( PFallDiagonal, true ) || hasNoFallBackProperties( PFallDiagonal ) || force )
465 {
466 TQDomElement fallDiagonal = doc.createElement( "fall-diagonal" );
467 fallDiagonal.appendChild( util_createElement( "pen", m_pStyle->fallDiagonalPen(), doc ) );
468 format.appendChild( fallDiagonal );
469 }
470 if ( hasProperty( PGoUpDiagonal, true ) || hasNoFallBackProperties( PGoUpDiagonal ) || force )
471 {
472 TQDomElement goUpDiagonal = doc.createElement( "up-diagonal" );
473 goUpDiagonal.appendChild( util_createElement( "pen", m_pStyle->goUpDiagonalPen(), doc ) );
474 format.appendChild( goUpDiagonal );
475 }
476 return format;
477}
478
479TQDomElement Format::save( TQDomDocument & doc, int _col, int _row, bool force, bool copy ) const
480{
481 TQDomElement format = saveFormat( doc, _col, _row, force, copy );
482 return format;
483}
484
485bool Format::loadFormat( const TQDomElement & f, Paste::Mode pm, bool paste )
486{
487 if ( f.hasAttribute( "style-name" ) )
488 {
489 Style * s = m_pSheet->doc()->styleManager()->style( f.attribute( "style-name" ) );
490
491 //kdDebug() << "Using style: " << f.attribute( "style-name" ) << ", s: " << s << endl;
492 if ( s )
493 {
494 setStyle( s );
495
496 return true;
497 }
498 else if ( !paste )
499 return false;
500 }
501 else
502 if ( f.hasAttribute( "parent" ) )
503 {
504 CustomStyle* s = static_cast<CustomStyle*>( m_pSheet->doc()->styleManager()->style( f.attribute( "parent" ) ) );
505 //kdDebug() << "Loading Style, parent: " << s->name() << ": " << s << endl;
506
507 if ( s )
508 {
509 if ( m_pStyle && m_pStyle->release() )
510 delete m_pStyle;
511
512 m_pStyle = new Style();
513 m_pStyle->setParent( s );
514 }
515 }
516
517 bool ok;
518 if ( f.hasAttribute( "align" ) )
519 {
520 Align a = (Align) f.attribute( "align" ).toInt( &ok );
521 if ( !ok )
522 return false;
523 // Validation
524 if ( (unsigned int) a >= 1 || (unsigned int) a <= 4 )
525 {
526 setAlign( a );
527 }
528 }
529 if ( f.hasAttribute( "alignY" ) )
530 {
531 AlignY a = (AlignY) f.attribute( "alignY" ).toInt( &ok );
532 if ( !ok )
533 return false;
534 // Validation
535 if ( (unsigned int) a >= 1 || (unsigned int) a <= 4 )
536 {
537 setAlignY( a );
538 }
539 }
540
541 if ( f.hasAttribute( "bgcolor" ) ) {
542 TQColor col( f.attribute( "bgcolor" ) );
543 if ( col != TQt::white )
544 setBgColor( col );
545 }
546
547 if ( f.hasAttribute( "multirow" ) )
548 setMultiRow( true );
549
550 if ( f.hasAttribute( "verticaltext" ) )
551 setVerticalText( true );
552
553 if ( f.hasAttribute( "precision" ) )
554 {
555 int i = f.attribute( "precision" ).toInt( &ok );
556 if ( i < -1 )
557 {
558 kdDebug(36001) << "Value out of range Cell::precision=" << i << endl;
559 return false;
560 }
561 // Assignment
562 setPrecision( i );
563 }
564
565 if ( f.hasAttribute( "float" ) )
566 {
567 FloatFormat a = (FloatFormat) f.attribute( "float" ).toInt( &ok );
568 if ( !ok ) return false;
569 if ( (unsigned int) a >= 1 && (unsigned int) a <= 3 )
570 {
571 setFloatFormat( a );
572 }
573 }
574
575 if ( f.hasAttribute( "floatcolor" ) )
576 {
577 FloatColor a = (FloatColor) f.attribute( "floatcolor" ).toInt( &ok );
578 if ( !ok ) return false;
579 if ( (unsigned int) a >= 1 && (unsigned int) a <= 4 )
580 {
581 setFloatColor( a );
582 }
583 }
584
585 if ( f.hasAttribute( "format" ) )
586 {
587 int fo = f.attribute( "format" ).toInt( &ok );
588 if ( ! ok )
589 return false;
590 setFormatType( ( FormatType ) fo );
591 }
592 if ( f.hasAttribute( "custom" ) )
593 {
594 setFormatString( f.attribute( "custom" ) );
595 }
596 if ( m_pStyle->formatType() == Money_format )
597 {
598 Currency c;
599 c.type = -1;
600 if ( f.hasAttribute( "type" ) )
601 {
602 c.type = f.attribute( "type" ).toInt( &ok );
603 if ( !ok )
604 c.type = 1;
605 }
606 if ( f.hasAttribute( "symbol" ) )
607 {
608 c.symbol = f.attribute( "symbol" );
609 }
610 if ( c.type != -1 )
611 setCurrency( c );
612 }
613 if ( f.hasAttribute( "angle" ) )
614 {
615 setAngle( f.attribute( "angle" ).toInt( &ok ) );
616 if ( !ok )
617 return false;
618 }
619 if ( f.hasAttribute( "indent" ) )
620 {
621 setIndent( f.attribute( "indent" ).toDouble( &ok ) );
622 if ( !ok )
623 return false;
624 }
625 if ( f.hasAttribute( "dontprinttext" ) )
626 setDontPrintText( true );
627
628 if ( f.hasAttribute( "noprotection" ) )
629 setNotProtected( true );
630
631 if ( f.hasAttribute( "hideall" ) )
632 setHideAll( true );
633
634 if ( f.hasAttribute( "hideformula" ) )
635 setHideFormula( true );
636
637 if ( f.hasAttribute( "brushstyle" ) )
638 {
639 setBackGroundBrushStyle( (TQt::BrushStyle) f.attribute( "brushstyle" ).toInt( &ok ) );
640 if ( !ok )
641 return false;
642 }
643
644 if ( f.hasAttribute( "brushcolor" ) )
645 setBackGroundBrushColor( TQColor( f.attribute( "brushcolor" ) ) );
646
647 TQDomElement pen( f.namedItem( "pen" ).toElement() );
648 if ( !pen.isNull() )
649 setTextPen( util_toPen( pen ) );
650
651 TQDomElement font( f.namedItem( "font" ).toElement() );
652 if ( !font.isNull() )
653 setTextFont( util_toFont( font ) );
654
655 if ( ( pm != Paste::NoBorder ) && ( pm != Paste::Text ) && ( pm != Paste::Comment ) )
656 {
657 TQDomElement left( f.namedItem( "left-border" ).toElement() );
658 if ( !left.isNull() )
659 {
660 TQDomElement pen( left.namedItem( "pen" ).toElement() );
661 if ( !pen.isNull() )
662 setLeftBorderPen( util_toPen( pen ) );
663 }
664
665 TQDomElement top( f.namedItem( "top-border" ).toElement() );
666 if ( !top.isNull() )
667 {
668 TQDomElement pen( top.namedItem( "pen" ).toElement() );
669 if ( !pen.isNull() )
670 setTopBorderPen( util_toPen( pen ) );
671 }
672
673 TQDomElement right( f.namedItem( "right-border" ).toElement() );
674 if ( !right.isNull() )
675 {
676 TQDomElement pen( right.namedItem( "pen" ).toElement() );
677 if ( !pen.isNull() )
678 setRightBorderPen( util_toPen( pen ) );
679 }
680
681 TQDomElement bottom( f.namedItem( "bottom-border" ).toElement() );
682 if ( !bottom.isNull() )
683 {
684 TQDomElement pen( bottom.namedItem( "pen" ).toElement() );
685 if ( !pen.isNull() )
686 setBottomBorderPen( util_toPen( pen ) );
687 }
688
689 TQDomElement fallDiagonal( f.namedItem( "fall-diagonal" ).toElement() );
690 if ( !fallDiagonal.isNull() )
691 {
692 TQDomElement pen( fallDiagonal.namedItem( "pen" ).toElement() );
693 if ( !pen.isNull() )
694 setFallDiagonalPen( util_toPen( pen ) );
695 }
696
697 TQDomElement goUpDiagonal( f.namedItem( "up-diagonal" ).toElement() );
698 if ( !goUpDiagonal.isNull() )
699 {
700 TQDomElement pen( goUpDiagonal.namedItem( "pen" ).toElement() );
701 if ( !pen.isNull() )
702 setGoUpDiagonalPen( util_toPen( pen ) );
703 }
704 }
705
706 if ( f.hasAttribute( "prefix" ) )
707 setPrefix( f.attribute( "prefix" ) );
708 if ( f.hasAttribute( "postfix" ) )
709 setPostfix( f.attribute( "postfix" ) );
710
711 return true;
712}
713
714bool Format::load( const TQDomElement & f, Paste::Mode pm, bool paste )
715{
716 if ( !loadFormat( f, pm, paste ) )
717 return false;
718 return true;
719}
720
721
722#if 0
723bool Format::loadFontOasisStyle( KoStyleStack & font )
724{
725 font.setTypeProperties( "text" ); // load all style attributes from "style:text-properties"
726 //TODO remember to change type properties
727
728 if ( font.hasAttributeNS( KoXmlNS::fo, "font-family" ) )
729 setTextFontFamily( font.attributeNS( KoXmlNS::fo, "font-family" ) );
730
731 if ( font.hasAttributeNS( KoXmlNS::fo, "color" ) )
732 setTextColor( TQColor( font.attributeNS( KoXmlNS::fo, "color" ) ) );
733
734 if ( font.hasAttributeNS( KoXmlNS::fo, "font-size" ) )
735 setTextFontSize( (int) KoUnit::parseValue( font.attributeNS( KoXmlNS::fo, "font-size" ), 10.0 ) );
736
737 if ( font.hasAttributeNS( KoXmlNS::fo, "font-style" ) && ( font.attributeNS( KoXmlNS::fo,"font-style" )== "italic" ))
738 {
739 kdDebug(30518) << "italic" << endl;
740 setTextFontItalic( true ); // only thing we support
741 }
742 if ( font.hasAttributeNS( KoXmlNS::fo, "font-weight" )
743 && ( font.attributeNS( KoXmlNS::fo, "font-weight" ) == "bold") )
744 setTextFontBold( true ); // only thing we support
745
746 //TODO add "style:text-underline-width" "style:text-underline-color"
747 if ( ( font.hasAttributeNS( KoXmlNS::fo, "text-underline-style" ) && font.attributeNS( KoXmlNS::fo, "text-underline-style" ) != "none" )
748 || ( font.hasAttributeNS( KoXmlNS::style, "text-underline-style" ) && font.attributeNS( KoXmlNS::style, "text-underline-style" )!="none" ) )
749 setTextFontUnderline( true ); // only thing we support
750
751 if ( font.hasAttributeNS( KoXmlNS::style, "text-line-through-style" )
752 && font.attributeNS( KoXmlNS::style, "text-line-through-style" ) != "none"
753 /*&& ( font.attributeNS( KoXmlNS::style, "text-crossing-out" ) == "single-line" )*/)
754 setTextFontStrike( true ); // only thing we support
755
756 if ( font.hasAttributeNS( KoXmlNS::style, "font-pitch" ) )
757 {
758 // TODO: possible values: fixed, variable
759 }
760
761 // TODO: for the future when we will use kotext
762 // text-underline-color
763 return true;
764}
765
766void Format::loadOasisStyle( /*const TQDomElement& style,*/ KoOasisLoadingContext& context )
767{
768 TQString str; // multi purpose string
769 KoOasisStyles& oasisStyles = context.oasisStyles();
770
771/* context.styleStack().save();
772 context.addStyles( &style );*/
773/* KoStyleStack styleStack;
774 styleStack.push( style );
775 styleStack.setTypeProperties( "table-cell" );*/
776
777 KoStyleStack& styleStack = context.styleStack();
778 loadOasisStyleProperties( styleStack, context.oasisStyles() );
779/* loadOasisStyleProperties( context.styleStack(), context.oasisStyles() );
780 context.styleStack().restore();*/
781
782 kdDebug() << "*** Loading style attributes *****" << endl;
783
784 if ( styleStack.hasAttributeNS( KoXmlNS::style, "data-style-name" ) )
785 {
786 str = styleStack.attributeNS( KoXmlNS::style, "data-style-name" );
787 kdDebug() << " style:data-style-name: " << str << endl << endl;
788
789 if ( !str.isEmpty() )
790 {
791 TQString tmp = oasisStyles.dataFormats()[str].prefix;
792 if ( !tmp.isEmpty() )
793 {
794 setPrefix( tmp );
795 }
796 tmp = oasisStyles.dataFormats()[str].suffix;
797 if ( !tmp.isEmpty() )
798 {
799 setPostfix( tmp );
800 }
801 tmp = oasisStyles.dataFormats()[str].formatStr;
802 if ( !tmp.isEmpty() )
803 {
804 setFormatType( Style::formatType( tmp ) );
805 }
806 }
807 }
808
809 if ( styleStack.hasAttributeNS( KoXmlNS::style, "decimal-places" ) )
810 {
811 bool ok = false;
812 int p = styleStack.attributeNS( KoXmlNS::style, "decimal-places" ).toInt( &ok );
813 kdDebug() << " style:decimal-places: " << p << endl;
814 if (ok )
815 setPrecision( p );
816 }
817}
818
819bool Format::loadOasisStyleProperties( KoStyleStack & styleStack, const KoOasisStyles& oasisStyles )
820{
821 kdDebug() << "*** Loading style properties *****" << endl;
822#if 0
823 if ( f.hasAttribute( "style-name" ) )
824 {
825 Style * s = m_pSheet->doc()->styleManager()->style( f.attribute( "style-name" ) );
826
827 //kdDebug() << "Using style: " << f.attribute( "style-name" ) << ", s: " << s << endl;
828 if ( s )
829 {
830 setStyle( s );
831
832 return true;
833 }
834 else if ( !paste )
835 return false;
836 }
837 else
838 if ( f.hasAttribute( "parent" ) )
839 {
840 CustomStyle * s = (CustomStyle *) m_pSheet->doc()->styleManager()->style( f.attribute( "parent" ) );
841 //kdDebug() << "Loading Style, parent: " << s->name() << ": " << s << endl;
842
843 if ( s )
844 {
845 if ( m_pStyle && m_pStyle->release() )
846 delete m_pStyle;
847
848 m_pStyle = new Style();
849 m_pStyle->setParent( s );
850 }
851 }
852#endif
853 if ( styleStack.hasAttributeNS( KoXmlNS::style, "parent-style-name" ) )
854 {
855 Style * s = m_pSheet->doc()->styleManager()->style( styleStack.attributeNS( KoXmlNS::style, "parent-style-name" ) );
856
857 //kdDebug() << "Using style: " << f.attribute( "style-name" ) << ", s: " << s << endl;
858 if ( s )
859 {
860 setStyle( s );
861 }
862 }
863 else
864 {
865 setStyle( m_pSheet->doc()->styleManager()->defaultStyle() );
866 }
867
868
869 if ( styleStack.hasAttributeNS( KoXmlNS::style, "font-name" ) )
870 {
871 const TQDomElement * font = oasisStyles.findStyle( styleStack.attributeNS( KoXmlNS::style, "font-name" ) );
872 if ( font )
873 {
874 styleStack.save();
875 styleStack.push( *font );
876 loadFontOasisStyle( styleStack ); // general font style
877 styleStack.restore();
878 }
879 }
880
881 kdDebug() << " [text properties]" << endl;
882 //Text properties
883 loadFontOasisStyle( styleStack ); // specific font style
884 //End Text properties
885
886 kdDebug() << " [paragraph properties]" << endl;
887 //Paragraph properties
888 styleStack.setTypeProperties( "paragraph" ); // load all style attributes from "style:paragraph-properties"
889 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "margin-left" ) )
890 {
891 kdDebug()<<" margin-left:"<<KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::fo, "margin-left" ),0.0 )<<endl;
892 setIndent( KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::fo, "margin-left" ),0.0 ) );
893 }
894 //kdDebug()<<"property.hasAttribute( fo:text-align ) :"<<styleStack.hasAttributeNS( KoXmlNS::fo, "text-align" )<<endl;
895 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "text-align" ) )
896 {
897 TQString s = styleStack.attributeNS( KoXmlNS::fo, "text-align" );
898 if ( s == "center" )
899 setAlign( Format::Center );
900 else if ( s == "end" )
901 setAlign( Format::Right );
902 else if ( s == "start" )
903 setAlign( Format::Left );
904 else if ( s == "justify" ) // TODO in KSpread!
905 setAlign( Format::Center );
906 }
907 //end paragraph properties
908
909 kdDebug() << " [cell properties]" << endl;
910 styleStack.setTypeProperties( "table-cell" ); // Default
911
912 // TODO:
913 // diagonal: fall + goup
914 // fo:direction="ltr"
915 // style:text-align-source ("fix")
916 // style:shadow
917 // style:text-outline
918 // indents from right, top, bottom
919 // style:condition="cell-content()=15"
920 // => style:apply-style-name="Result" style:base-cell-address="Sheet6.A5"/>
921
922 if ( styleStack.hasAttributeNS( KoXmlNS::style, "rotation-angle" ) )
923 {
924 bool ok = false;
925 int a = styleStack.attributeNS( KoXmlNS::style, "rotation-angle" ).toInt( &ok );
926 if ( ok && ( a != 0 ))
927 setAngle( -a );
928 }
929 if ( styleStack.hasAttributeNS( KoXmlNS::style, "direction" ) )
930 {
931 TQString dir = styleStack.attributeNS( KoXmlNS::fo, "direction" );
932 if ( dir == "ttb" )
933 setVerticalText( true );
934 else if ( dir == "ltr" )
935 setVerticalText( false );
936 }
937
938 kdDebug()<<"property.hasAttribute( fo:background-color ) :"<<styleStack.hasAttributeNS( KoXmlNS::fo, "background-color" )<<endl;
939
940 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "background-color" ) )
941 setBgColor( TQColor( styleStack.attributeNS( KoXmlNS::fo, "background-color" ) ) );
942
943 if ( styleStack.hasAttributeNS( KoXmlNS::style, "print-content" ) )
944 {
945 if ( styleStack.attributeNS( KoXmlNS::style, "print-content" ) == "false" )
946 setDontPrintText( false );
947 }
948 if ( styleStack.hasAttributeNS( KoXmlNS::style, "cell-protect" ) )
949 {
950 TQString prot( styleStack.attributeNS( KoXmlNS::style, "cell-protect" ) );
951 if ( prot == "none" )
952 {
953 setNotProtected( true );
954 setHideFormula( false );
955 setHideAll( false );
956 }
957 else if ( prot == "formula-hidden" )
958 {
959 setNotProtected( true );
960 setHideFormula( true );
961 setHideAll( false );
962 }
963 else if ( prot == "protected formula-hidden" )
964 {
965 setNotProtected( false );
966 setHideFormula( true );
967 setHideAll( false );
968 }
969 else if ( prot == "hidden-and-protected" )
970 {
971 setNotProtected( false );
972 setHideFormula( false );
973 setHideAll( true );
974 }
975 else if ( prot == "protected" )
976 {
977 setNotProtected( false );
978 setHideFormula( false );
979 setHideAll( false );
980 }
981 else
982 kdDebug()<<" Protected cell not supported :"<<prot<<endl;
983 kdDebug() << " cell-protect: " << prot << endl;
984 }
985
986 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "padding-left" ) )
987 setIndent( KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::fo, "padding-left" ) ) );
988
989 if ( styleStack.hasAttributeNS( KoXmlNS::style, "vertical-align" ) )
990 {
991 TQString s = styleStack.attributeNS( KoXmlNS::style, "vertical-align" );
992 if ( s == "middle" )
993 setAlignY( Format::Middle );
994 else if ( s == "bottom" )
995 setAlignY( Format::Bottom );
996 else if ( s == "top" )
997 setAlignY( Format::Top );
998 }
999
1000 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "wrap-option" ) )
1001 {
1002 // we do not support anything else yet
1003 TQString wrapOpt = styleStack.attributeNS( KoXmlNS::fo, "wrap-option" );
1004 if ( wrapOpt == "wrap" )
1005 setMultiRow( true );
1006 else if ( wrapOpt == "no-wrap" )
1007 setMultiRow( false );
1008 }
1009 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "border-bottom" ) )
1010 {
1011 setBottomBorderPen( convertOasisStringToPen( styleStack.attributeNS( KoXmlNS::fo, "border-bottom" ) ) );
1012 // TODO: style:border-line-width-bottom if double!
1013 }
1014
1015 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "border-right" ) )
1016 {
1017 setRightBorderPen( convertOasisStringToPen( styleStack.attributeNS( KoXmlNS::fo, "border-right" ) ) );
1018 // TODO: style:border-line-width-right
1019 }
1020
1021 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "border-top" ) )
1022 {
1023 setTopBorderPen( convertOasisStringToPen( styleStack.attributeNS( KoXmlNS::fo, "border-top" ) ) );
1024 // TODO: style:border-line-width-top
1025 }
1026
1027 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "border-left" ) )
1028 {
1029 setLeftBorderPen( convertOasisStringToPen( styleStack.attributeNS( KoXmlNS::fo, "border-left" ) ) );
1030 // TODO: style:border-line-width-left
1031 }
1032
1033 if ( styleStack.hasAttributeNS( KoXmlNS::fo, "border" ) )
1034 {
1035 TQPen pen = convertOasisStringToPen( styleStack.attributeNS( KoXmlNS::fo, "border" ) );
1036 setLeftBorderPen( pen );
1037 setRightBorderPen( pen );
1038 setTopBorderPen( pen );
1039 setBottomBorderPen( pen );
1040
1041 // TODO: style:border-line-width-left
1042 }
1043 if ( styleStack.hasAttributeNS( KoXmlNS::style, "diagonal-tl-br" ) )
1044 {
1045 setFallDiagonalPen( convertOasisStringToPen( styleStack.attributeNS( KoXmlNS::style, "diagonal-tl-br" ) ) );
1046 }
1047 if ( styleStack.hasAttributeNS( KoXmlNS::style, "diagonal-bl-tr" ) )
1048 {
1049 setGoUpDiagonalPen( convertOasisStringToPen( styleStack.attributeNS( KoXmlNS::style, "diagonal-bl-tr" ) ) );
1050 }
1051
1052 if ( styleStack.hasAttributeNS( KoXmlNS::draw, "style-name" ) )
1053 {
1054 //kdDebug()<<" style name :"<<styleStack.attributeNS( KoXmlNS::draw, "style-name" )<<endl;
1055
1056 const TQDomElement * style = oasisStyles.findStyle( styleStack.attributeNS( KoXmlNS::draw, "style-name" ), "graphic" );
1057 if ( style )
1058 {
1059 //kdDebug()<<" style :"<<style<<endl;
1060 KoStyleStack drawStyleStack;
1061 drawStyleStack.push( *style );
1062 drawStyleStack.setTypeProperties( "graphic" );
1063 if ( drawStyleStack.hasAttributeNS( KoXmlNS::draw, "fill" ) )
1064 {
1065 const TQString fill = drawStyleStack.attributeNS( KoXmlNS::draw, "fill" );
1066 kdDebug()<<" load object gradient fill type :"<<fill<<endl;
1067
1068 if ( fill == "solid" || fill == "hatch" )
1069 {
1070 TQBrush brush=KoOasisStyles::loadOasisFillStyle( drawStyleStack, fill, oasisStyles );
1071 setBackGroundBrushStyle( brush.style() );
1072 setBackGroundBrushColor( brush.color() );
1073 }
1074 else
1075 kdDebug()<<" fill style not supported by kspread : "<<fill<<endl;
1076 }
1077 }
1078 }
1079
1080 return true;
1081}
1082#endif
1083
1084
1086//
1087// Set methods
1088//
1090
1091void Format::setFormatString( TQString const & format )
1092{
1093 if ( format.isEmpty() )
1094 {
1095 clearProperty( PCustomFormat );
1096 setNoFallBackProperties( PCustomFormat );
1097 }
1098 else
1099 {
1100 setProperty( PCustomFormat );
1101 clearNoFallBackProperties( PCustomFormat );
1102
1103 // now have a custom format...
1104 clearProperty( PPrefix );
1105 clearProperty( PPostfix );
1106 clearProperty( PPrecision );
1107 clearProperty( PFloatColor );
1108 clearProperty( PFloatFormat );
1109
1110 setNoFallBackProperties( PPrecision );
1111 setNoFallBackProperties( PPrefix );
1112 setNoFallBackProperties( PPostfix );
1113 }
1114
1115 m_pStyle = m_pStyle->setStrFormat( format );
1116 formatChanged();
1117}
1118
1119void Format::setAlign( Align _align )
1120{
1121 if ( _align == Format::Undefined )
1122 {
1123 clearProperty( PAlign );
1124 setNoFallBackProperties(PAlign );
1125 }
1126 else
1127 {
1128 setProperty( PAlign );
1129 clearNoFallBackProperties(PAlign );
1130 }
1131
1132 m_pStyle = m_pStyle->setAlignX( _align );
1133 formatChanged();
1134}
1135
1136void Format::setAlignY( AlignY _alignY)
1137{
1138 //kdDebug() << "Format: AlignY: " << _alignY << endl;
1139 if ( _alignY == Format::Middle )
1140 {
1141 //kdDebug() << "Middle" << endl;
1142 clearProperty( PAlignY );
1143 setNoFallBackProperties(PAlignY );
1144 }
1145 else
1146 {
1147 //kdDebug() << "Not middle: " << _alignY << endl;
1148 setProperty( PAlignY );
1149 clearNoFallBackProperties( PAlignY );
1150 }
1151
1152 m_pStyle = m_pStyle->setAlignY( _alignY );
1153 formatChanged();
1154}
1155
1156void Format::setPrefix( const TQString& _prefix )
1157{
1158 if ( _prefix.isEmpty() )
1159 {
1160 clearProperty( PPrefix );
1161 setNoFallBackProperties( PPrefix );
1162 }
1163 else
1164 {
1165 setProperty( PPrefix );
1166 clearNoFallBackProperties( PPrefix );
1167 }
1168
1169 m_pStyle = m_pStyle->setPrefix( _prefix );
1170 formatChanged();
1171}
1172
1173void Format::setPostfix( const TQString& _postfix )
1174{
1175 if ( _postfix.isEmpty() )
1176 {
1177 clearProperty( PPostfix );
1178 setNoFallBackProperties( PPostfix );
1179 }
1180 else
1181 {
1182 setProperty( PPostfix );
1183 clearNoFallBackProperties( PPostfix );
1184 }
1185
1186 m_pStyle = m_pStyle->setPostfix( _postfix );
1187 formatChanged();
1188}
1189
1190void Format::setPrecision( int _p )
1191{
1192 if ( _p == -1 )
1193 {
1194 clearProperty( PPrecision );
1195 setNoFallBackProperties( PPrecision );
1196 }
1197 else
1198 {
1199 setProperty( PPrecision );
1200 clearNoFallBackProperties( PPrecision );
1201 }
1202
1203 m_pStyle = m_pStyle->setPrecision( _p );
1204 formatChanged();
1205}
1206
1207void Format::setLeftBorderPen( const TQPen & _p )
1208{
1209 if ( _p.style() == TQt::NoPen )
1210 {
1211 clearProperty( PLeftBorder );
1212 setNoFallBackProperties( PLeftBorder );
1213 }
1214 else
1215 {
1216 setProperty( PLeftBorder );
1217 clearNoFallBackProperties( PLeftBorder );
1218 }
1219
1220 m_pStyle = m_pStyle->setLeftBorderPen( _p );
1221 formatChanged();
1222}
1223
1224void Format::setLeftBorderStyle( TQt::PenStyle s )
1225{
1226 TQPen p( m_pStyle->leftBorderPen() );
1227 p.setStyle( s );
1228 setLeftBorderPen( p );
1229}
1230
1231void Format::setLeftBorderColor( const TQColor & c )
1232{
1233 TQPen p( m_pStyle->leftBorderPen() );
1234 p.setColor( c );
1235 setLeftBorderPen( p );
1236}
1237
1238void Format::setLeftBorderWidth( int _w )
1239{
1240 TQPen p( m_pStyle->leftBorderPen() );
1241 p.setWidth( _w );
1242 setLeftBorderPen( p );
1243}
1244
1245void Format::setTopBorderPen( const TQPen & _p )
1246{
1247 if ( _p.style() == TQt::NoPen )
1248 {
1249 clearProperty( PTopBorder );
1250 setNoFallBackProperties( PTopBorder );
1251 }
1252 else
1253 {
1254 setProperty( PTopBorder );
1255 clearNoFallBackProperties( PTopBorder );
1256 }
1257
1258 m_pStyle = m_pStyle->setTopBorderPen( _p );
1259 formatChanged();
1260}
1261
1262void Format::setTopBorderStyle( TQt::PenStyle s )
1263{
1264 TQPen p( m_pStyle->topBorderPen() );
1265 p.setStyle( s );
1266 setTopBorderPen( p );
1267}
1268
1269void Format::setTopBorderColor( const TQColor& c )
1270{
1271 TQPen p( m_pStyle->topBorderPen() );
1272 p.setColor( c );
1273 setTopBorderPen( p );
1274}
1275
1276void Format::setTopBorderWidth( int _w )
1277{
1278 TQPen p( m_pStyle->topBorderPen() );
1279 p.setWidth( _w );
1280 setTopBorderPen( p );
1281}
1282
1283void Format::setRightBorderPen( const TQPen& p )
1284{
1285 if ( p.style() == TQt::NoPen )
1286 {
1287 clearProperty( PRightBorder );
1288 setNoFallBackProperties( PRightBorder );
1289 }
1290 else
1291 {
1292 setProperty( PRightBorder );
1293 clearNoFallBackProperties( PRightBorder );
1294 }
1295
1296 m_pStyle = m_pStyle->setRightBorderPen( p );
1297 formatChanged();
1298}
1299
1300void Format::setRightBorderStyle( TQt::PenStyle _s )
1301{
1302 TQPen p( m_pStyle->rightBorderPen() );
1303 p.setStyle( _s );
1304 setRightBorderPen( p );
1305}
1306
1307void Format::setRightBorderColor( const TQColor & _c )
1308{
1309 TQPen p( m_pStyle->rightBorderPen() );
1310 p.setColor( _c );
1311 setRightBorderPen( p );
1312}
1313
1314void Format::setRightBorderWidth( int _w )
1315{
1316 TQPen p( m_pStyle->rightBorderPen() );
1317 p.setWidth( _w );
1318 setRightBorderPen( p );
1319}
1320
1321void Format::setBottomBorderPen( const TQPen& p )
1322{
1323 if ( p.style() == TQt::NoPen )
1324 {
1325 clearProperty( PBottomBorder );
1326 setNoFallBackProperties( PBottomBorder );
1327 }
1328 else
1329 {
1330 setProperty( PBottomBorder );
1331 clearNoFallBackProperties( PBottomBorder );
1332 }
1333
1334 m_pStyle = m_pStyle->setBottomBorderPen( p );
1335 formatChanged();
1336}
1337
1338void Format::setBottomBorderStyle( TQt::PenStyle _s )
1339{
1340 TQPen p( m_pStyle->bottomBorderPen() );
1341 p.setStyle( _s );
1342 setBottomBorderPen( p );
1343}
1344
1345void Format::setBottomBorderColor( const TQColor & _c )
1346{
1347 TQPen p( m_pStyle->bottomBorderPen() );
1348 p.setColor( _c );
1349 setBottomBorderPen( p );
1350}
1351
1352void Format::setBottomBorderWidth( int _w )
1353{
1354 TQPen p( m_pStyle->bottomBorderPen() );
1355 p.setWidth( _w );
1356 setBottomBorderPen( p );
1357}
1358
1359void Format::setFallDiagonalPen( const TQPen & _p )
1360{
1361 if ( _p.style() == TQt::NoPen )
1362 {
1363 clearProperty( PFallDiagonal );
1364 setNoFallBackProperties( PFallDiagonal );
1365 }
1366 else
1367 {
1368 setProperty( PFallDiagonal );
1369 clearNoFallBackProperties( PFallDiagonal );
1370 }
1371
1372 m_pStyle = m_pStyle->setFallDiagonalPen( _p );
1373 formatChanged();
1374}
1375
1376void Format::setFallDiagonalStyle( TQt::PenStyle s )
1377{
1378 TQPen p( m_pStyle->fallDiagonalPen() );
1379 p.setStyle( s );
1380 setFallDiagonalPen( p );
1381}
1382
1383void Format::setFallDiagonalColor( const TQColor& c )
1384{
1385 TQPen p( m_pStyle->fallDiagonalPen() );
1386 p.setColor( c );
1387 setFallDiagonalPen( p );
1388}
1389
1390void Format::setFallDiagonalWidth( int _w )
1391{
1392 TQPen p( m_pStyle->fallDiagonalPen() );
1393 p.setWidth( _w );
1394 setFallDiagonalPen( p );
1395}
1396
1397void Format::setGoUpDiagonalPen( const TQPen & _p )
1398{
1399 if ( _p.style() == TQt::NoPen )
1400 {
1401 clearProperty( PGoUpDiagonal );
1402 setNoFallBackProperties( PGoUpDiagonal );
1403 }
1404 else
1405 {
1406 setProperty( PGoUpDiagonal );
1407 clearNoFallBackProperties( PGoUpDiagonal );
1408 }
1409
1410 m_pStyle = m_pStyle->setGoUpDiagonalPen( _p );
1411 formatChanged();
1412}
1413
1414void Format::setGoUpDiagonalStyle( TQt::PenStyle s )
1415{
1416 TQPen p( m_pStyle->goUpDiagonalPen() );
1417 p.setStyle( s );
1418 setGoUpDiagonalPen( p );
1419}
1420
1421void Format::setGoUpDiagonalColor( const TQColor& c )
1422{
1423 TQPen p( m_pStyle->goUpDiagonalPen() );
1424 p.setColor( c );
1425 setGoUpDiagonalPen( p );
1426}
1427
1428void Format::setGoUpDiagonalWidth( int _w )
1429{
1430 TQPen p( m_pStyle->goUpDiagonalPen() );
1431 p.setWidth( _w );
1432 setGoUpDiagonalPen( p );
1433}
1434
1435void Format::setBackGroundBrush( const TQBrush & _p)
1436{
1437 if ( _p.style() == TQt::NoBrush )
1438 {
1439 clearProperty( PBackgroundBrush );
1440 setNoFallBackProperties( PBackgroundBrush );
1441 }
1442 else
1443 {
1444 setProperty( PBackgroundBrush );
1445 clearNoFallBackProperties( PBackgroundBrush );
1446 }
1447
1448 m_pStyle = m_pStyle->setBackGroundBrush( _p );
1449 formatChanged();
1450}
1451
1452void Format::setBackGroundBrushStyle( TQt::BrushStyle s )
1453{
1454 TQBrush b( m_pStyle->backGroundBrush() );
1455 b.setStyle( s );
1456 setBackGroundBrush( b );
1457}
1458
1459void Format::setBackGroundBrushColor( const TQColor & c )
1460{
1461 TQBrush b( m_pStyle->backGroundBrush() );
1462 b.setColor( c );
1463 setBackGroundBrush( b );
1464}
1465
1466void Format::setTextFont( const TQFont & _f )
1467{
1468 if( m_pStyle->parent() && _f == m_pStyle->parent()->font())
1469 {
1470 clearProperty( PFont );
1471 setNoFallBackProperties( PFont );
1472 }
1473 else if( !m_pStyle->parent() && _f == KoGlobal::defaultFont() )
1474 {
1475 clearProperty( PFont );
1476 setNoFallBackProperties( PFont );
1477 }
1478 else
1479 {
1480 setProperty( PFont );
1481 clearNoFallBackProperties( PFont );
1482 }
1483
1484
1485 m_pStyle = m_pStyle->setFont( _f );
1486 formatChanged();
1487}
1488
1489void Format::setTextFontSize( int _s )
1490{
1491 TQFont f( m_pStyle->font() );
1492 f.setPointSize( _s );
1493 setTextFont( f );
1494}
1495
1496void Format::setTextFontFamily( const TQString & _f )
1497{
1498 TQFont f( m_pStyle->font() );
1499 f.setFamily( _f );
1500 setTextFont( f );
1501}
1502
1503void Format::setTextFontBold( bool _b )
1504{
1505 TQFont f( m_pStyle->font() );
1506 f.setBold( _b );
1507 setTextFont( f );
1508}
1509
1510void Format::setTextFontItalic( bool _i )
1511{
1512 TQFont f( m_pStyle->font() );
1513 f.setItalic( _i );
1514 setTextFont( f );
1515}
1516
1517void Format::setTextFontUnderline( bool _i )
1518{
1519 TQFont f( m_pStyle->font() );
1520 f.setUnderline( _i );
1521 setTextFont( f );
1522}
1523
1524void Format::setTextFontStrike( bool _i )
1525{
1526 TQFont f( m_pStyle->font() );
1527 f.setStrikeOut( _i );
1528 setTextFont( f );
1529}
1530
1531void Format::setTextPen( const TQPen & _p )
1532{
1533 // An invalid color means "the default text color, from the color scheme"
1534 // It doesn't mean "no setting here, look at fallback"
1535 // Maybe we should look at the fallback color, in fact.
1536 /*if(!_p.color().isValid())
1537 {
1538 clearProperty( PTextPen );
1539 setNoFallBackProperties( PTextPen );
1540 }
1541 else*/
1542 {
1543 setProperty( PTextPen );
1544 clearNoFallBackProperties( PTextPen );
1545 }
1546
1547 //setProperty( PTextPen );
1548 m_pStyle = m_pStyle->setPen( _p );
1549 //kdDebug(36001) << "setTextPen: this=" << this << " pen=" << m_textPen.color().name() << " valid:" << m_textPen.color().isValid() << endl;
1550 formatChanged();
1551}
1552
1553void Format::setTextColor( const TQColor & _c )
1554{
1555 TQPen p( m_pStyle->pen() );
1556 p.setColor( _c );
1557 setTextPen( p );
1558}
1559
1560void Format::setBgColor( const TQColor & _c )
1561{
1562 if ( !_c.isValid() )
1563 {
1564 clearProperty( PBackgroundColor );
1565 setNoFallBackProperties( PBackgroundColor );
1566 }
1567 else
1568 {
1569 setProperty( PBackgroundColor );
1570 clearNoFallBackProperties( PBackgroundColor );
1571 }
1572
1573 m_pStyle = m_pStyle->setBgColor( _c );
1574 formatChanged();
1575}
1576
1577void Format::setFloatFormat( FloatFormat _f )
1578{
1579 setProperty( PFloatFormat );
1580
1581 m_pStyle = m_pStyle->setFloatFormat( _f );
1582 formatChanged();
1583}
1584
1585void Format::setFloatColor( FloatColor _c )
1586{
1587 setProperty( PFloatColor );
1588
1589 m_pStyle = m_pStyle->setFloatColor( _c );
1590 formatChanged();
1591}
1592
1593void Format::setMultiRow( bool _b )
1594{
1595 if ( _b == false )
1596 {
1597 m_pStyle = m_pStyle->clearProperty( Style::PMultiRow );
1598 clearProperty( PMultiRow );
1599 setNoFallBackProperties( PMultiRow );
1600 }
1601 else
1602 {
1603 m_pStyle = m_pStyle->setProperty( Style::PMultiRow );
1604 setProperty( PMultiRow );
1605 clearNoFallBackProperties( PMultiRow );
1606 }
1607 formatChanged();
1608}
1609
1610void Format::setVerticalText( bool _b )
1611{
1612 if ( _b == false )
1613 {
1614 m_pStyle = m_pStyle->clearProperty( Style::PVerticalText );
1615 setNoFallBackProperties( PVerticalText);
1616 clearFlag( Flag_VerticalText );
1617 }
1618 else
1619 {
1620 m_pStyle = m_pStyle->setProperty( Style::PVerticalText );
1621 clearNoFallBackProperties( PVerticalText);
1622 setFlag( Flag_VerticalText );
1623 }
1624 formatChanged();
1625}
1626
1627void Format::setFormatType( FormatType _format )
1628{
1629 if ( _format == Number_format )
1630 {
1631 clearProperty( PFormatType );
1632 setNoFallBackProperties( PFormatType);
1633 }
1634 else
1635 {
1636 setProperty( PFormatType );
1637 clearNoFallBackProperties( PFormatType);
1638 }
1639
1640 m_pStyle = m_pStyle->setFormatType( _format );
1641 formatChanged();
1642}
1643
1644void Format::setAngle( int _angle )
1645{
1646 if ( _angle == 0 )
1647 {
1648 clearProperty( PAngle );
1649 setNoFallBackProperties( PAngle);
1650 }
1651 else
1652 {
1653 setProperty( PAngle );
1654 clearNoFallBackProperties( PAngle);
1655 }
1656
1657 m_pStyle = m_pStyle->setRotateAngle( _angle );
1658 formatChanged();
1659}
1660
1661void Format::setIndent( double _indent )
1662{
1663 if ( _indent == 0.0 )
1664 {
1665 clearProperty( PIndent );
1666 setNoFallBackProperties( PIndent );
1667 }
1668 else
1669 {
1670 setProperty( PIndent );
1671 clearNoFallBackProperties( PIndent );
1672 }
1673
1674 m_pStyle = m_pStyle->setIndent( _indent );
1675 formatChanged();
1676}
1677
1678void Format::setComment( const TQString & _comment )
1679{
1680 if ( _comment.isEmpty() )
1681 {
1682 clearProperty( PComment );
1683 setNoFallBackProperties( PComment );
1684 }
1685 else
1686 {
1687 setProperty( PComment );
1688 clearNoFallBackProperties( PComment );
1689 }
1690
1691 // not part of the style
1692 delete m_strComment;
1693 if ( !_comment.isEmpty() )
1694 m_strComment = new TQString( _comment );
1695 else
1696 m_strComment = 0;
1697 formatChanged();
1698}
1699
1700void Format::setNotProtected( bool _b)
1701{
1702 if ( _b == false )
1703 {
1704 m_pStyle = m_pStyle->clearProperty( Style::PNotProtected );
1705 setNoFallBackProperties( PNotProtected );
1706 clearFlag( Flag_NotProtected );
1707 }
1708 else
1709 {
1710 m_pStyle = m_pStyle->setProperty( Style::PNotProtected );
1711 clearNoFallBackProperties( PNotProtected );
1712 setFlag( Flag_NotProtected );
1713 }
1714 formatChanged();
1715}
1716
1717void Format::setDontPrintText( bool _b )
1718{
1719 if ( _b == false )
1720 {
1721 m_pStyle = m_pStyle->clearProperty( Style::PDontPrintText );
1722 setNoFallBackProperties(PDontPrintText);
1723 clearFlag( Flag_DontPrintText );
1724 }
1725 else
1726 {
1727 m_pStyle = m_pStyle->setProperty( Style::PDontPrintText );
1728 clearNoFallBackProperties( PDontPrintText);
1729 setFlag( Flag_DontPrintText );
1730 }
1731 formatChanged();
1732}
1733
1734void Format::setHideAll( bool _b )
1735{
1736 if ( _b == false )
1737 {
1738 m_pStyle = m_pStyle->clearProperty( Style::PHideAll );
1739 setNoFallBackProperties(PHideAll);
1740 clearFlag( Flag_HideAll );
1741 }
1742 else
1743 {
1744 m_pStyle = m_pStyle->setProperty( Style::PHideAll );
1745 clearNoFallBackProperties( PHideAll);
1746 setFlag( Flag_HideAll );
1747 }
1748 formatChanged();
1749}
1750
1751void Format::setHideFormula( bool _b )
1752{
1753 if ( _b == false )
1754 {
1755 m_pStyle = m_pStyle->clearProperty( Style::PHideFormula );
1756 setNoFallBackProperties( PHideFormula );
1757 clearFlag( Flag_HideFormula );
1758 }
1759 else
1760 {
1761 m_pStyle = m_pStyle->setProperty( Style::PHideFormula );
1762 clearNoFallBackProperties( PHideFormula );
1763 setFlag( Flag_HideFormula );
1764 }
1765 formatChanged();
1766}
1767
1768void Format::setCurrency( Currency const & c )
1769{
1770 m_pStyle = m_pStyle->setCurrency( c );
1771}
1772
1773void Format::setCurrency( int type, TQString const & symbol )
1774{
1775 Currency c;
1776
1777 c.symbol = symbol.simplifyWhiteSpace();
1778 c.type = type;
1779
1780 if (c.symbol.length() == 0)
1781 {
1782 c.type = 0;
1783 c.symbol = sheet()->doc()->locale()->currencySymbol();
1784 }
1785
1786 m_pStyle = m_pStyle->setCurrency( c );
1787}
1788
1790//
1791// Get methods
1792//
1794
1795TQString const & Format::getFormatString( int col, int row ) const
1796{
1797 if ( !hasProperty( PCustomFormat, false ) && !hasNoFallBackProperties( PCustomFormat ))
1798 {
1799 const Format * l = fallbackFormat( col, row );
1800 if ( l )
1801 return l->getFormatString( col, row );
1802 }
1803 return m_pStyle->strFormat();
1804}
1805
1806TQString Format::prefix( int col, int row ) const
1807{
1808 if ( !hasProperty( PPrefix, false ) && !hasNoFallBackProperties(PPrefix ))
1809 {
1810 const Format * l = fallbackFormat( col, row );
1811 if ( l )
1812 return l->prefix( col, row );
1813 }
1814 return m_pStyle->prefix();
1815}
1816
1817TQString Format::postfix( int col, int row ) const
1818{
1819 if ( !hasProperty( PPostfix, false ) && !hasNoFallBackProperties(PPostfix ))
1820 {
1821 const Format * l = fallbackFormat( col, row );
1822 if ( l )
1823 return l->postfix( col, row );
1824 }
1825 return m_pStyle->postfix();
1826}
1827
1828const TQPen& Format::fallDiagonalPen( int col, int row ) const
1829{
1830 if ( !hasProperty( PFallDiagonal, false ) && !hasNoFallBackProperties(PFallDiagonal ))
1831 {
1832 const Format* l = fallbackFormat( col, row );
1833 if ( l )
1834 return l->fallDiagonalPen( col, row );
1835 }
1836 return m_pStyle->fallDiagonalPen();
1837}
1838
1839int Format::fallDiagonalWidth( int col, int row ) const
1840{
1841 return fallDiagonalPen( col, row ).width();
1842}
1843
1844TQt::PenStyle Format::fallDiagonalStyle( int col, int row ) const
1845{
1846 return fallDiagonalPen( col, row ).style();
1847}
1848
1849const TQColor & Format::fallDiagonalColor( int col, int row ) const
1850{
1851 return fallDiagonalPen( col, row ).color();
1852}
1853
1854const TQPen & Format::goUpDiagonalPen( int col, int row ) const
1855{
1856 if ( !hasProperty( PGoUpDiagonal, false ) && !hasNoFallBackProperties( PGoUpDiagonal ) )
1857 {
1858 const Format* l = fallbackFormat( col, row );
1859 if ( l )
1860 return l->goUpDiagonalPen( col, row );
1861 }
1862 return m_pStyle->goUpDiagonalPen();
1863}
1864
1865int Format::goUpDiagonalWidth( int col, int row ) const
1866{
1867 return goUpDiagonalPen( col, row ).width();
1868}
1869
1870TQt::PenStyle Format::goUpDiagonalStyle( int col, int row ) const
1871{
1872 return goUpDiagonalPen( col, row ).style();
1873}
1874
1875const TQColor& Format::goUpDiagonalColor( int col, int row ) const
1876{
1877 return goUpDiagonalPen( col, row ).color();
1878}
1879
1880uint Format::bottomBorderValue( int col, int row ) const
1881{
1882 if ( !hasProperty( PBottomBorder, false ) && !hasNoFallBackProperties( PBottomBorder ) )
1883 {
1884 const Format * l = fallbackFormat( col, row );
1885 if ( l )
1886 return l->bottomBorderValue( col, row );
1887
1888 return 0;
1889 }
1890
1891 return m_pStyle->bottomPenValue();
1892}
1893
1894uint Format::rightBorderValue( int col, int row ) const
1895{
1896 if ( !hasProperty( PRightBorder, false ) && !hasNoFallBackProperties( PRightBorder ) )
1897 {
1898 const Format * l = fallbackFormat( col, row );
1899 if ( l )
1900 return l->rightBorderValue( col, row );
1901
1902 return 0;
1903 }
1904
1905 return m_pStyle->rightPenValue();
1906}
1907
1908uint Format::leftBorderValue( int col, int row ) const
1909{
1910 if ( !hasProperty( PLeftBorder, false ) && !hasNoFallBackProperties( PLeftBorder ) )
1911 {
1912 const Format * l = fallbackFormat( col, row );
1913 if ( l )
1914 return l->leftBorderValue( col, row );
1915
1916 return 0;
1917 }
1918
1919 return m_pStyle->leftPenValue();
1920}
1921
1922uint Format::topBorderValue( int col, int row ) const
1923{
1924 if ( !hasProperty( PTopBorder, false ) && !hasNoFallBackProperties( PTopBorder ) )
1925 {
1926 const Format * l = fallbackFormat( col, row );
1927 if ( l )
1928 return l->topBorderValue( col, row );
1929
1930 return 0;
1931 }
1932
1933 return m_pStyle->topPenValue();
1934}
1935
1936const TQPen& Format::leftBorderPen( int col, int row ) const
1937{
1938 if ( !hasProperty( PLeftBorder, false ) && !hasNoFallBackProperties( PLeftBorder ) )
1939 {
1940 const Format * l = fallbackFormat( col, row );
1941 if ( l )
1942 return l->leftBorderPen( col, row );
1943 return sheet()->emptyPen();
1944 }
1945
1946 return m_pStyle->leftBorderPen();
1947}
1948
1949TQt::PenStyle Format::leftBorderStyle( int col, int row ) const
1950{
1951 return leftBorderPen( col, row ).style();
1952}
1953
1954const TQColor& Format::leftBorderColor( int col, int row ) const
1955{
1956 return leftBorderPen( col, row ).color();
1957}
1958
1959int Format::leftBorderWidth( int col, int row ) const
1960{
1961 return leftBorderPen( col, row ).width();
1962}
1963
1964const TQPen& Format::topBorderPen( int col, int row ) const
1965{
1966 if ( !hasProperty( PTopBorder, false ) && !hasNoFallBackProperties( PTopBorder ) )
1967 {
1968 const Format* l = fallbackFormat( col, row );
1969 if ( l )
1970 return l->topBorderPen( col, row );
1971 return sheet()->emptyPen();
1972 }
1973
1974 return m_pStyle->topBorderPen();
1975}
1976
1977const TQColor& Format::topBorderColor( int col, int row ) const
1978{
1979 return topBorderPen( col, row ).color();
1980}
1981
1982TQt::PenStyle Format::topBorderStyle( int col, int row ) const
1983{
1984 return topBorderPen( col, row ).style();
1985}
1986
1987int Format::topBorderWidth( int col, int row ) const
1988{
1989 return topBorderPen( col, row ).width();
1990}
1991
1992const TQPen& Format::rightBorderPen( int col, int row ) const
1993{
1994 if ( !hasProperty( PRightBorder, false ) && !hasNoFallBackProperties( PRightBorder ) )
1995 {
1996 const Format * l = fallbackFormat( col, row );
1997 if ( l )
1998 return l->rightBorderPen( col, row );
1999 return sheet()->emptyPen();
2000 }
2001
2002 return m_pStyle->rightBorderPen();
2003}
2004
2005int Format::rightBorderWidth( int col, int row ) const
2006{
2007 return rightBorderPen( col, row ).width();
2008}
2009
2010TQt::PenStyle Format::rightBorderStyle( int col, int row ) const
2011{
2012 return rightBorderPen( col, row ).style();
2013}
2014
2015const TQColor& Format::rightBorderColor( int col, int row ) const
2016{
2017 return rightBorderPen( col, row ).color();
2018}
2019
2020const TQPen& Format::bottomBorderPen( int col, int row ) const
2021{
2022 if ( !hasProperty( PBottomBorder, false )&& !hasNoFallBackProperties( PBottomBorder ) )
2023 {
2024 const Format * l = fallbackFormat( col, row );
2025 if ( l )
2026 return l->bottomBorderPen( col, row );
2027 return sheet()->emptyPen();
2028 }
2029
2030 return m_pStyle->bottomBorderPen();
2031}
2032
2033int Format::bottomBorderWidth( int col, int row ) const
2034{
2035 return bottomBorderPen( col, row ).width();
2036}
2037
2038TQt::PenStyle Format::bottomBorderStyle( int col, int row ) const
2039{
2040 return bottomBorderPen( col, row ).style();
2041}
2042
2043const TQColor& Format::bottomBorderColor( int col, int row ) const
2044{
2045 return bottomBorderPen( col, row ).color();
2046}
2047
2048const TQBrush& Format::backGroundBrush( int col, int row ) const
2049{
2050 if ( !hasProperty( PBackgroundBrush, false ) && !hasNoFallBackProperties(PBackgroundBrush ))
2051 {
2052 const Format* l = fallbackFormat( col, row );
2053 if ( l )
2054 return l->backGroundBrush( col, row );
2055 }
2056 return m_pStyle->backGroundBrush();
2057}
2058
2059TQt::BrushStyle Format::backGroundBrushStyle( int col, int row ) const
2060{
2061 return backGroundBrush( col, row ).style();
2062}
2063
2064const TQColor& Format::backGroundBrushColor( int col, int row ) const
2065{
2066 return backGroundBrush( col, row ).color();
2067}
2068
2069int Format::precision( int col, int row ) const
2070{
2071 if ( !hasProperty( PPrecision, false )&& !hasNoFallBackProperties( PPrecision ) )
2072 {
2073 const Format * l = fallbackFormat( col, row );
2074 if ( l )
2075 return l->precision( col, row );
2076 }
2077 return m_pStyle->precision();
2078}
2079
2080Format::FloatFormat Format::floatFormat( int col, int row ) const
2081{
2082 if ( !hasProperty( PFloatFormat, false ) && !hasNoFallBackProperties( PFloatFormat ) )
2083 {
2084 const Format * l = fallbackFormat( col, row );
2085 if ( l )
2086 return l->floatFormat( col, row );
2087 }
2088 return m_pStyle->floatFormat();
2089}
2090
2091Format::FloatColor Format::floatColor( int col, int row ) const
2092{
2093 if ( !hasProperty( PFloatColor, false ) && !hasNoFallBackProperties( PFloatColor ) )
2094 {
2095 const Format * l = fallbackFormat( col, row );
2096 if ( l )
2097 return l->floatColor( col, row );
2098 }
2099 return m_pStyle->floatColor();
2100}
2101
2102const TQColor& Format::bgColor( int col, int row ) const
2103{
2104 if ( !hasProperty( PBackgroundColor, false ) && !hasNoFallBackProperties( PBackgroundColor ) )
2105 {
2106 const Format * l = fallbackFormat( col, row );
2107 if ( l )
2108 return l->bgColor( col, row );
2109 }
2110
2111 return m_pStyle->bgColor();
2112}
2113
2114const TQPen& Format::textPen( int col, int row ) const
2115{
2116 if ( !hasProperty( PTextPen, false ) && !hasNoFallBackProperties( PTextPen ) )
2117 {
2118 const Format * l = fallbackFormat( col, row );
2119 if ( l )
2120 return l->textPen( col, row );
2121 }
2122 return m_pStyle->pen();
2123}
2124
2125const TQColor& Format::textColor( int col, int row ) const
2126{
2127 return textPen( col, row ).color();
2128}
2129
2130const TQFont Format::textFont( int col, int row ) const
2131{
2132 if ( !hasProperty( PFont, false ) && !hasNoFallBackProperties( PFont ) )
2133 {
2134 const Format * l = fallbackFormat( col, row );
2135 if ( l )
2136 return l->textFont( col, row );
2137 }
2138
2139 return m_pStyle->font();
2140}
2141
2142int Format::textFontSize( int col, int row ) const
2143{
2144 if ( !hasProperty( PFont, false ) && !hasNoFallBackProperties( PFont ) )
2145 {
2146 const Format * l = fallbackFormat( col, row );
2147 if ( l )
2148 return l->textFontSize( col, row );
2149 }
2150
2151 return m_pStyle->fontSize();
2152}
2153
2154TQString const & Format::textFontFamily( int col, int row ) const
2155{
2156 if ( !hasProperty( PFont, false ) && !hasNoFallBackProperties( PFont ) )
2157 {
2158 const Format * l = fallbackFormat( col, row );
2159 if ( l )
2160 return l->textFontFamily( col, row );
2161 }
2162
2163 return m_pStyle->fontFamily();
2164}
2165
2166bool Format::textFontBold( int col, int row ) const
2167{
2168 if ( !hasProperty( PFont, false ) && !hasNoFallBackProperties( PFont ) )
2169 {
2170 const Format * l = fallbackFormat( col, row );
2171 if ( l )
2172 return l->textFontBold( col, row );
2173 }
2174
2175 return ( m_pStyle->fontFlags() & Style::FBold );
2176}
2177
2178bool Format::textFontItalic( int col, int row ) const
2179{
2180 if ( !hasProperty( PFont, false ) && !hasNoFallBackProperties( PFont ) )
2181 {
2182 const Format * l = fallbackFormat( col, row );
2183 if ( l )
2184 return l->textFontItalic( col, row );
2185 }
2186
2187 return ( m_pStyle->fontFlags() & Style::FItalic );
2188}
2189
2190bool Format::textFontUnderline( int col, int row ) const
2191{
2192 if ( !hasProperty( PFont, false ) && !hasNoFallBackProperties( PFont ) )
2193 {
2194 const Format * l = fallbackFormat( col, row );
2195 if ( l )
2196 return l->textFontUnderline( col, row );
2197 }
2198
2199 return ( m_pStyle->fontFlags() & Style::FUnderline );
2200}
2201
2202bool Format::textFontStrike( int col, int row ) const
2203{
2204 if ( !hasProperty( PFont, false ) && !hasNoFallBackProperties( PFont ) )
2205 {
2206 const Format * l = fallbackFormat( col, row );
2207 if ( l )
2208 return l->textFontStrike( col, row );
2209 }
2210
2211 return ( m_pStyle->fontFlags() & Style::FStrike );
2212}
2213
2214Format::Align Format::align( int col, int row ) const
2215{
2216 if ( !hasProperty( PAlign, false ) && !hasNoFallBackProperties( PAlign ) )
2217 {
2218 const Format * l = fallbackFormat( col, row );
2219 if ( l )
2220 return l->align( col, row );
2221 }
2222
2223 return m_pStyle->alignX();
2224}
2225
2226Format::AlignY Format::alignY( int col, int row ) const
2227{
2228 if ( !hasProperty( PAlignY, false )&& !hasNoFallBackProperties( PAlignY ) )
2229 {
2230 const Format * l = fallbackFormat( col, row );
2231 if ( l )
2232 return l->alignY( col, row );
2233 }
2234
2235 return m_pStyle->alignY();
2236}
2237
2238bool Format::multiRow( int col, int row ) const
2239{
2240 if ( !hasProperty( PMultiRow, false ) && !hasNoFallBackProperties( PMultiRow ) )
2241 {
2242 const Format * l = fallbackFormat( col, row );
2243 if ( l )
2244 return l->multiRow( col, row );
2245 }
2246
2247 return m_pStyle->hasProperty( Style::PMultiRow );
2248}
2249
2250bool Format::verticalText( int col, int row ) const
2251{
2252 if ( !hasProperty( PVerticalText, false )&& !hasNoFallBackProperties( PVerticalText ) )
2253 {
2254 const Format * l = fallbackFormat( col, row );
2255 if ( l )
2256 return l->verticalText( col, row );
2257 }
2258
2259 return m_pStyle->hasProperty( Style::PVerticalText );
2260}
2261
2262FormatType Format::getFormatType( int col, int row ) const
2263{
2264 if ( !hasProperty( PFormatType, false ) && !hasNoFallBackProperties( PFormatType ) )
2265 {
2266 const Format* l = fallbackFormat( col, row );
2267 if ( l )
2268 return l->getFormatType( col, row );
2269 }
2270
2271 return m_pStyle->formatType();
2272}
2273
2274int Format::getAngle( int col, int row ) const
2275{
2276 if ( !hasProperty( PAngle, false ) && !hasNoFallBackProperties( PAngle ) )
2277 {
2278 const Format* l = fallbackFormat( col, row );
2279 if ( l )
2280 return l->getAngle( col, row );
2281 }
2282
2283 return m_pStyle->rotateAngle();
2284}
2285
2286TQString Format::comment( int col, int row ) const
2287{
2288 if ( !hasProperty( PComment, false ) && !hasNoFallBackProperties( PComment ))
2289 {
2290 const Format* l = fallbackFormat( col, row );
2291 if ( l )
2292 return l->comment( col, row );
2293 }
2294
2295 if ( !m_strComment )
2296 return TQString();
2297
2298 // not part of the style
2299 return *m_strComment;
2300}
2301
2302TQString * Format::commentP( int col, int row ) const
2303{
2304 if ( !hasProperty( PComment, false ) && !hasNoFallBackProperties( PComment ))
2305 {
2306 const Format* l = fallbackFormat( col, row );
2307 if ( l )
2308 return l->commentP( col, row );
2309 }
2310
2311 return m_strComment;
2312}
2313
2314double Format::getIndent( int col, int row ) const
2315{
2316 if ( !hasProperty( PIndent, false ) && !hasNoFallBackProperties( PIndent ) )
2317 {
2318 const Format* l = fallbackFormat( col, row );
2319 if ( l )
2320 return l->getIndent( col, row );
2321 }
2322
2323 return m_pStyle->indent();
2324}
2325
2326bool Format::getDontprintText( int col, int row ) const
2327{
2328 if ( !hasProperty( PDontPrintText, false )&& !hasNoFallBackProperties( PDontPrintText ) )
2329 {
2330 const Format* l = fallbackFormat( col, row );
2331 if ( l )
2332 return l->getDontprintText( col, row );
2333 }
2334
2335 return m_pStyle->hasProperty( Style::PDontPrintText );
2336}
2337
2338bool Format::isProtected( int col, int row ) const
2339{
2340 return ( m_pSheet->isProtected() && !notProtected( col, row ) );
2341}
2342
2343
2344bool Format::notProtected( int col, int row) const
2345{
2346 if ( !hasProperty( PNotProtected, false )&& !hasNoFallBackProperties( PNotProtected ) )
2347 {
2348 const Format * l = fallbackFormat( col, row );
2349 if ( l )
2350 return l->notProtected( col, row );
2351 }
2352
2353 return m_pStyle->hasProperty( Style::PNotProtected );
2354}
2355
2356bool Format::isHideAll( int col, int row) const
2357{
2358 if ( !hasProperty( PHideAll, false )&& !hasNoFallBackProperties( PHideAll ) )
2359 {
2360 const Format * l = fallbackFormat( col, row );
2361 if ( l )
2362 return l->isHideAll( col, row );
2363 }
2364
2365 return m_pStyle->hasProperty( Style::PHideAll );
2366}
2367
2368bool Format::isHideFormula( int col, int row) const
2369{
2370 if ( !hasProperty( PHideFormula, false )&& !hasNoFallBackProperties( PHideFormula ) )
2371 {
2372 const Format * l = fallbackFormat( col, row );
2373 if ( l )
2374 return l->isHideFormula( col, row );
2375 }
2376
2377 return m_pStyle->hasProperty( Style::PHideFormula );
2378}
2379
2380bool Format::currencyInfo( Currency & currency) const
2381{
2382 // TODO: fallback ?
2383 if ( m_pStyle->formatType() != Money_format )
2384 return false;
2385
2386 currency.symbol = m_pStyle->currency().symbol;
2387 currency.type = m_pStyle->currency().type;
2388
2389 return true;
2390}
2391
2392TQString Format::getCurrencySymbol() const
2393{
2394 // TODO: fallback ?
2395 return m_pStyle->currency().symbol;
2396}
2397
2398TQFont Format::font() const
2399{
2400 return m_pStyle->font();
2401}
2402
2403
2405//
2406// Get methods
2407//
2409
2410const TQPen & Format::leftBorderPen() const
2411{
2412 return m_pStyle->leftBorderPen();
2413}
2414
2415const TQPen & Format::topBorderPen() const
2416{
2417 return m_pStyle->topBorderPen();
2418}
2419
2420const TQPen & Format::rightBorderPen() const
2421{
2422 return m_pStyle->rightBorderPen();
2423}
2424
2425const TQPen & Format::bottomBorderPen() const
2426{
2427 return m_pStyle->bottomBorderPen();
2428}
2429
2430const TQPen & Format::fallDiagonalPen() const
2431{
2432 return m_pStyle->fallDiagonalPen();
2433}
2434
2435const TQPen & Format::goUpDiagonalPen() const
2436{
2437 return m_pStyle->goUpDiagonalPen();
2438}
2439
2440const TQBrush & Format::backGroundBrush() const
2441{
2442 return m_pStyle->backGroundBrush();
2443}
2444
2445const TQFont Format::textFont() const
2446{
2447 return m_pStyle->font();
2448}
2449
2450const TQPen & Format::textPen() const
2451{
2452 return m_pStyle->pen();
2453}
2454
2456//
2457// Misc
2458//
2460
2461void Format::formatChanged()
2462{
2463 if (m_pCell)
2464 {
2465 m_pCell->setFlag(Cell::Flag_LayoutDirty);
2466 m_pCell->setFlag(Cell::Flag_TextFormatDirty);
2467 }
2468}
2469
2470Format* Format::fallbackFormat( int, int row )
2471{
2472 return m_pCell ? m_pSheet->rowFormat( row ) : 0;
2473}
2474
2475const Format* Format::fallbackFormat( int, int row ) const
2476{
2477 return m_pCell ? m_pSheet->rowFormat( row ) : 0;
2478}
2479
2480bool Format::isDefault() const
2481{
2482 // NOTE Stefan: Don't compare sheet and cell.
2483 // Because of the comment we have to check m_mask.
2484 if ( ( m_mask & PComment ) && m_strComment != 0 )
2485 return false;
2486#if 0 // These are copied in Style.
2487 if ( m_mask ) // Properties
2488 return false;
2489 if ( m_flagsMask != 0 ) // FormatFlags
2490 return false;
2491#endif
2492 if ( m_bNoFallBack != 0 )
2493 return false;
2494 return ( *m_pStyle == *m_pSheet->doc()->styleManager()->defaultStyle() );
2495}
2496
2497bool Format::operator==( const Format& other ) const
2498{
2499 // NOTE Stefan: Don't compare sheet and cell.
2500 // Because of the comment we have to check m_mask.
2501 if ( ( m_mask & other.m_mask & PComment ) && m_strComment != other.m_strComment )
2502 return false;
2503#if 0 // These are copied in Style.
2504 if ( m_mask != other.m_mask ) // Properties
2505 return false;
2506 if ( m_flagsMask != other.m_flagsMask ) // FormatFlags
2507 return false;
2508#endif
2509 if ( m_bNoFallBack != other.m_bNoFallBack )
2510 return false;
2511 return ( *m_pStyle == *other.m_pStyle );
2512}
2513
2514/*****************************************************************************
2515 *
2516 * RowFormat
2517 *
2518 *****************************************************************************/
2519
2520//#define UPDATE_BEGIN bool b_update_begin = m_bDisplayDirtyFlag; m_bDisplayDirtyFlag = true;
2521//#define UPDATE_END if ( !b_update_begin && m_bDisplayDirtyFlag ) m_pSheet->emit_updateRow( this, m_iRow );
2522
2523RowFormat::RowFormat( Sheet * _sheet, int _row )
2524 : Format( _sheet, _sheet->doc()->styleManager()->defaultStyle() )
2525{
2526 m_next = 0;
2527 m_prev = 0;
2528
2529 m_bDisplayDirtyFlag = false;
2530 m_fHeight = s_rowHeight;
2531 m_iRow = _row;
2532 m_bDefault = false;
2533 m_bHide = false;
2534 m_dcop = 0L;
2535}
2536
2537RowFormat::~RowFormat()
2538{
2539 if ( m_next )
2540 m_next->setPrevious( m_prev );
2541 if ( m_prev )
2542 m_prev->setNext( m_next );
2543 delete m_dcop;
2544}
2545
2546DCOPObject * RowFormat::dcopObject()
2547{
2548 if ( !m_dcop )
2549 m_dcop = new RowIface( this );
2550 return m_dcop;
2551}
2552
2553
2554void RowFormat::setMMHeight( double _h )
2555{
2556 setDblHeight( MM_TO_POINT ( _h ) );
2557}
2558
2559void RowFormat::setHeight( int _h, const Canvas * _canvas )
2560{
2561 setDblHeight( (double) _h, _canvas );
2562}
2563
2564void RowFormat::setDblHeight( double _h, const Canvas * _canvas )
2565{
2566 Sheet *_sheet = _canvas ? _canvas->activeSheet() : m_pSheet;
2567
2568 // avoid unnecessary updates
2569 if ( kAbs( _h - dblHeight( _canvas ) ) < DBL_EPSILON )
2570 return;
2571
2572// UPDATE_BEGIN;
2573
2574 // Lower maximum size by old height
2575 _sheet->adjustSizeMaxY ( - dblHeight() );
2576
2577 if ( _canvas )
2578 m_fHeight = ( _h / _canvas->zoom() );
2579 else
2580 m_fHeight = _h;
2581
2582 // Rise maximum size by new height
2583 _sheet->adjustSizeMaxY ( dblHeight() );
2584 _sheet->print()->updatePrintRepeatRowsHeight();
2585 _sheet->print()->updateNewPageListY ( row() );
2586
2587 _sheet->emit_updateRow(this,m_iRow);
2588// UPDATE_END;
2589}
2590
2591int RowFormat::height( const Canvas *_canvas ) const
2592{
2593 return (int) dblHeight( _canvas );
2594}
2595
2596double RowFormat::dblHeight( const Canvas *_canvas ) const
2597{
2598 if( m_bHide )
2599 return 0.0;
2600
2601 if ( _canvas )
2602 return _canvas->zoom() * (m_iRow == 0) ? s_rowHeight : m_fHeight;
2603 else
2604 return (m_iRow == 0) ? s_rowHeight : m_fHeight;
2605}
2606
2607double RowFormat::mmHeight() const
2608{
2609 return POINT_TO_MM ( dblHeight() );
2610}
2611
2612TQDomElement RowFormat::save( TQDomDocument& doc, int yshift, bool copy ) const
2613{
2614 TQDomElement row = doc.createElement( "row" );
2615 row.setAttribute( "height", m_fHeight );
2616 row.setAttribute( "row", m_iRow - yshift );
2617 if( m_bHide )
2618 row.setAttribute( "hide", (int) m_bHide );
2619
2620 TQDomElement format( saveFormat( doc, false, copy ) );
2621 row.appendChild( format );
2622 return row;
2623}
2624
2625#if 0
2626bool RowFormat::loadOasis( const TQDomElement& /*row*/, TQDomElement * /*rowStyle*/ )
2627{
2628 return true;
2629}
2630#endif
2631
2632bool RowFormat::load( const TQDomElement & row, int yshift, Paste::Mode sp, bool paste )
2633{
2634 bool ok;
2635
2636 m_iRow = row.attribute( "row" ).toInt( &ok ) + yshift;
2637 if ( !ok )
2638 return false;
2639
2640 if ( row.hasAttribute( "height" ) )
2641 {
2642 if ( m_pSheet->doc()->syntaxVersion() < 1 ) //compatibility with old format - was in millimeter
2643 m_fHeight = tqRound( MM_TO_POINT( row.attribute( "height" ).toDouble( &ok ) ) );
2644 else
2645 m_fHeight = row.attribute( "height" ).toDouble( &ok );
2646
2647 if ( !ok ) return false;
2648 }
2649
2650 // Validation
2651 if ( m_fHeight < 0 )
2652 {
2653 kdDebug(36001) << "Value height=" << m_fHeight << " out of range" << endl;
2654 return false;
2655 }
2656 if ( m_iRow < 1 || m_iRow > KS_rowMax )
2657 {
2658 kdDebug(36001) << "Value row=" << m_iRow << " out of range" << endl;
2659 return false;
2660 }
2661
2662 if ( row.hasAttribute( "hide" ) )
2663 {
2664 setHide( (int) row.attribute( "hide" ).toInt( &ok ) );
2665 if ( !ok )
2666 return false;
2667 }
2668
2669 TQDomElement f( row.namedItem( "format" ).toElement() );
2670
2671 if ( !f.isNull() && ( sp == Paste::Normal || sp == Paste::Format || sp == Paste::NoBorder ) )
2672 {
2673 if ( !loadFormat( f, sp, paste ) )
2674 return false;
2675 return true;
2676 }
2677
2678 return true;
2679}
2680
2681const TQPen & RowFormat::topBorderPen( int _col, int _row ) const
2682{
2683 // First look at the row above us
2684 if ( !hasProperty( PTopBorder, false ) )
2685 {
2686 const RowFormat * rl = sheet()->rowFormat( _row - 1 );
2687 if ( rl->hasProperty( PBottomBorder ) )
2688 return rl->bottomBorderPen( _col, _row - 1 );
2689 }
2690
2691 return Format::topBorderPen( _col, _row );
2692}
2693
2694void RowFormat::setTopBorderPen( const TQPen & p )
2695{
2696 RowFormat * cl = sheet()->nonDefaultRowFormat( row() - 1, false );
2697 if ( cl )
2698 cl->clearProperty( PBottomBorder );
2699
2700 Format::setTopBorderPen( p );
2701}
2702
2703const TQPen & RowFormat::bottomBorderPen( int _col, int _row ) const
2704{
2705 // First look at the row below of us
2706 if ( !hasProperty( PBottomBorder, false ) && ( _row < KS_rowMax ) )
2707 {
2708 const RowFormat * rl = sheet()->rowFormat( _row + 1 );
2709 if ( rl->hasProperty( PTopBorder ) )
2710 return rl->topBorderPen( _col, _row + 1 );
2711 }
2712
2713 return Format::bottomBorderPen( _col, _row );
2714}
2715
2716void RowFormat::setBottomBorderPen( const TQPen & p )
2717{
2718 if ( row() < KS_rowMax )
2719 {
2720 RowFormat * cl = sheet()->nonDefaultRowFormat( row() + 1, false );
2721 if ( cl )
2722 cl->clearProperty( PTopBorder );
2723 }
2724
2725 Format::setBottomBorderPen( p );
2726}
2727
2728void RowFormat::setHide( bool _hide, bool repaint )
2729{
2730 if ( _hide != m_bHide ) // only if we change the status
2731 {
2732 if ( _hide )
2733 {
2734 // Lower maximum size by height of row
2735 m_pSheet->adjustSizeMaxY ( - dblHeight() );
2736 m_bHide = _hide; //hide must be set after we requested the height
2737 m_pSheet->emit_updateRow( this, m_iRow, repaint );
2738 }
2739 else
2740 {
2741 // Rise maximum size by height of row
2742 m_bHide = _hide; //unhide must be set before we request the height
2743 m_pSheet->adjustSizeMaxY ( dblHeight() );
2744 m_pSheet->emit_updateRow( this, m_iRow, repaint );
2745 }
2746 }
2747}
2748
2749Format* RowFormat::fallbackFormat( int col, int )
2750{
2751 return sheet()->columnFormat( col );
2752}
2753
2754const Format* RowFormat::fallbackFormat( int col, int ) const
2755{
2756 return sheet()->columnFormat( col );
2757}
2758
2759bool RowFormat::isDefault() const
2760{
2761 if ( m_fHeight != s_rowHeight )
2762 return false;
2763 if ( m_bHide == true )
2764 return false;
2765 return Format::isDefault();
2766}
2767
2768bool RowFormat::operator==( const RowFormat& other ) const
2769{
2770 // NOTE Stefan: Don't compare sheet and cell.
2771 if ( m_fHeight != other.m_fHeight )
2772 return false;
2773 if ( m_bHide != other.m_bHide )
2774 return false;
2775 return Format::operator==( other );
2776}
2777
2778/*****************************************************************************
2779 *
2780 * ColumnFormat
2781 *
2782 *****************************************************************************/
2783
2784#undef UPDATE_BEGIN
2785#undef UPDATE_END
2786
2787#define UPDATE_BEGIN bool b_update_begin = m_bDisplayDirtyFlag; m_bDisplayDirtyFlag = true;
2788#define UPDATE_END if ( !b_update_begin && m_bDisplayDirtyFlag ) m_pSheet->emit_updateColumn( this, m_iColumn );
2789
2790ColumnFormat::ColumnFormat( Sheet * _sheet, int _column )
2791 : Format( _sheet, _sheet->doc()->styleManager()->defaultStyle() )
2792{
2793 m_bDisplayDirtyFlag = false;
2794 m_fWidth = s_columnWidth;
2795 m_iColumn = _column;
2796 m_bDefault=false;
2797 m_bHide=false;
2798 m_prev = 0;
2799 m_next = 0;
2800 m_dcop = 0;
2801}
2802
2803ColumnFormat::~ColumnFormat()
2804{
2805 if ( m_next )
2806 m_next->setPrevious( m_prev );
2807 if ( m_prev )
2808 m_prev->setNext( m_next );
2809 delete m_dcop;
2810}
2811
2812DCOPObject * ColumnFormat::dcopObject()
2813{
2814 if ( !m_dcop )
2815 m_dcop = new ColumnIface( this );
2816 return m_dcop;
2817}
2818
2819void ColumnFormat::setMMWidth( double _w )
2820{
2821 setDblWidth( MM_TO_POINT ( _w ) );
2822}
2823
2824void ColumnFormat::setWidth( int _w, const Canvas * _canvas )
2825{
2826 setDblWidth( (double)_w, _canvas );
2827}
2828
2829void ColumnFormat::setDblWidth( double _w, const Canvas * _canvas )
2830{
2831 Sheet *_sheet = _canvas ? _canvas->activeSheet() : m_pSheet;
2832
2833 // avoid unnecessary updates
2834 if ( kAbs( _w - dblWidth( _canvas ) ) < DBL_EPSILON )
2835 return;
2836
2837 // UPDATE_BEGIN;
2838
2839 // Lower maximum size by old width
2840 _sheet->adjustSizeMaxX ( - dblWidth() );
2841
2842 if ( _canvas )
2843 m_fWidth = ( _w / _canvas->zoom() );
2844 else
2845 m_fWidth = _w;
2846
2847 // Rise maximum size by new width
2848 _sheet->adjustSizeMaxX ( dblWidth() );
2849 _sheet->print()->updatePrintRepeatColumnsWidth();
2850 _sheet->print()->updateNewPageListX ( column() );
2851
2852 _sheet->emit_updateColumn(this,m_iColumn);
2853 // UPDATE_END;
2854}
2855
2856int ColumnFormat::width( const Canvas * _canvas ) const
2857{
2858 return (int) dblWidth( _canvas );
2859}
2860
2861double ColumnFormat::dblWidth( const Canvas * _canvas ) const
2862{
2863 if ( m_bHide )
2864 return 0.0;
2865
2866 if ( _canvas )
2867 return _canvas->zoom() * (m_iColumn == 0) ? s_columnWidth : m_fWidth;
2868 else
2869 return (m_iColumn == 0) ? s_columnWidth : m_fWidth;
2870}
2871
2872double ColumnFormat::mmWidth() const
2873{
2874 return POINT_TO_MM( dblWidth() );
2875}
2876
2877
2878TQDomElement ColumnFormat::save( TQDomDocument& doc, int xshift, bool copy ) const
2879{
2880 TQDomElement col( doc.createElement( "column" ) );
2881 col.setAttribute( "width", m_fWidth );
2882 col.setAttribute( "column", m_iColumn - xshift );
2883
2884 if ( m_bHide )
2885 col.setAttribute( "hide", (int) m_bHide );
2886
2887 TQDomElement format( saveFormat( doc, false, copy ) );
2888 col.appendChild( format );
2889
2890 return col;
2891}
2892
2893bool ColumnFormat::load( const TQDomElement & col, int xshift, Paste::Mode sp, bool paste )
2894{
2895 bool ok;
2896 if ( col.hasAttribute( "width" ) )
2897 {
2898 if ( m_pSheet->doc()->syntaxVersion() < 1 ) //combatibility to old format - was in millimeter
2899 m_fWidth = tqRound( MM_TO_POINT ( col.attribute( "width" ).toDouble( &ok ) ) );
2900 else
2901 m_fWidth = col.attribute( "width" ).toDouble( &ok );
2902
2903 if ( !ok )
2904 return false;
2905 }
2906
2907 m_iColumn = col.attribute( "column" ).toInt( &ok ) + xshift;
2908
2909 if ( !ok )
2910 return false;
2911
2912 // Validation
2913 if ( m_fWidth < 0 )
2914 {
2915 kdDebug(36001) << "Value width=" << m_fWidth << " out of range" << endl;
2916 return false;
2917 }
2918 if ( m_iColumn < 1 || m_iColumn > KS_colMax )
2919 {
2920 kdDebug(36001) << "Value col=" << m_iColumn << " out of range" << endl;
2921 return false;
2922 }
2923 if ( col.hasAttribute( "hide" ) )
2924 {
2925 setHide( (int) col.attribute( "hide" ).toInt( &ok ) );
2926 if ( !ok )
2927 return false;
2928 }
2929
2930 TQDomElement f( col.namedItem( "format" ).toElement() );
2931
2932 if ( !f.isNull() && ( sp == Paste::Normal || sp == Paste::Format || sp == Paste::NoBorder ))
2933 {
2934 if ( !loadFormat( f, sp, paste ) )
2935 return false;
2936 return true;
2937 }
2938
2939 return true;
2940}
2941
2942const TQPen & ColumnFormat::leftBorderPen( int _col, int _row ) const
2943{
2944 // First look ar the right column at the right
2945 if ( !hasProperty( PLeftBorder, false ) )
2946 {
2947 const ColumnFormat * cl = sheet()->columnFormat( _col - 1 );
2948 if ( cl->hasProperty( PRightBorder ) )
2949 return cl->rightBorderPen( _col - 1, _row );
2950 }
2951
2952 return Format::leftBorderPen( _col, _row );
2953}
2954
2955void ColumnFormat::setLeftBorderPen( const TQPen & p )
2956{
2957 ColumnFormat * cl = sheet()->nonDefaultColumnFormat( column() - 1, false );
2958 if ( cl )
2959 cl->clearProperty( PRightBorder );
2960
2961 Format::setLeftBorderPen( p );
2962}
2963
2964const TQPen & ColumnFormat::rightBorderPen( int _col, int _row ) const
2965{
2966 // First look ar the right column at the right
2967 if ( !hasProperty( PRightBorder, false ) && ( _col < KS_colMax ) )
2968 {
2969 const ColumnFormat * cl = sheet()->columnFormat( _col + 1 );
2970 if ( cl->hasProperty( PLeftBorder ) )
2971 return cl->leftBorderPen( _col + 1, _row );
2972 }
2973
2974 return Format::rightBorderPen( _col, _row );
2975}
2976
2977void ColumnFormat::setRightBorderPen( const TQPen & p )
2978{
2979 if ( column() < KS_colMax )
2980 {
2981 ColumnFormat * cl = sheet()->nonDefaultColumnFormat( column() + 1, false );
2982 if ( cl )
2983 cl->clearProperty( PLeftBorder );
2984 }
2985
2986 Format::setRightBorderPen( p );
2987}
2988
2989Format * ColumnFormat::fallbackFormat( int, int )
2990{
2991 return sheet()->defaultFormat();
2992}
2993
2994void ColumnFormat::setHide( bool _hide )
2995{
2996 if ( _hide != m_bHide ) // only if we change the status
2997 {
2998 if ( _hide )
2999 {
3000 // Lower maximum size by width of column
3001 m_pSheet->adjustSizeMaxX ( - dblWidth() );
3002 m_bHide = _hide; //hide must be set after we requested the width
3003 // m_pSheet->emit_updateColumn( this, m_iColumn );
3004 }
3005 else
3006 {
3007 // Rise maximum size by width of column
3008 m_bHide = _hide; //unhide must be set before we request the width
3009 m_pSheet->adjustSizeMaxX ( dblWidth() );
3010 // m_pSheet->emit_updateColumn( this, m_iColumn );
3011 }
3012 }
3013}
3014
3015const Format * ColumnFormat::fallbackFormat( int, int ) const
3016{
3017 return sheet()->defaultFormat();
3018}
3019
3020bool ColumnFormat::isDefault() const
3021{
3022 if ( m_fWidth != s_columnWidth )
3023 return false;
3024 if ( m_bHide == true )
3025 return false;
3026 return Format::isDefault();
3027}
3028
3029bool ColumnFormat::operator==( const ColumnFormat& other ) const
3030{
3031 // NOTE Stefan: Don't compare sheet and cell.
3032 if ( m_fWidth != other.m_fWidth )
3033 return false;
3034 if ( m_bHide != other.m_bHide )
3035 return false;
3036 return Format::operator==( other );
3037}
3038
3039
3040
3041namespace Currency_LNS
3042{
3043 typedef struct
3044 {
3045 char const * code;
3046 char const * country;
3047 char const * name;
3048 char const * display;
3049 } Money;
3050
3051 // codes and names as defined in ISO 3166-1
3052 // first column: saved code
3053 // second column: country name (localized)
3054 // third column: currency name (localized)
3055 // fourth column: displayed currency code (localized but maybe only in
3056 // the country language it belongs to)
3057 // WARNING: change the "24" in getChooseString if you change this array
3058 static const Money lMoney[] = {
3059 { "", "", "", ""}, // auto
3060 { "", "", "", ""}, // extension (codes imported)
3061 { "$", "", "Dollar", "$" }, // unspecified
3062 { "$", I18N_NOOP("Australia"), I18N_NOOP("Dollar"), "$" },
3063 { "$", I18N_NOOP("Canada"), I18N_NOOP("Dollar"), "$" },
3064 { "$", I18N_NOOP("Caribbea"), I18N_NOOP("Dollar"), "$" },
3065 { "$", I18N_NOOP("New Zealand"), I18N_NOOP("Dollar"), "$" },
3066 { "$", I18N_NOOP("United States"), I18N_NOOP("Dollar"), "$" },
3067
3068 // € == Euro sign in utf8
3069 { "€", "", "€", "€" }, // unspecified
3070 { "€", I18N_NOOP("Austria"), I18N_NOOP("Euro"), "€" },
3071 { "€", I18N_NOOP("Belgium"), I18N_NOOP("Euro"), "€" },
3072 { "€", I18N_NOOP("Finland"), I18N_NOOP("Euro"), "€" },
3073 { "€", I18N_NOOP("France"), I18N_NOOP("Euro"), "€" },
3074 { "€", I18N_NOOP("Germany"), I18N_NOOP("Euro"), "€" },
3075 { "€", I18N_NOOP("Greece"), I18N_NOOP("Euro"), "€" },
3076 { "€", I18N_NOOP("Ireland"), I18N_NOOP("Euro"), "€" },
3077 { "€", I18N_NOOP("Italy"), I18N_NOOP("Euro"), "€" },
3078 { "€", I18N_NOOP("Luxembourg"), I18N_NOOP("Euro"), "€" },
3079 { "€", I18N_NOOP("Monaco"), I18N_NOOP("Euro"), "€" },
3080 { "€", I18N_NOOP("Netherlands"), I18N_NOOP("Euro"), "€" },
3081 { "€", I18N_NOOP("Portugal"), I18N_NOOP("Euro"), "€" },
3082 { "€", I18N_NOOP("Spain"), I18N_NOOP("Euro"), "€" },
3083
3084 { "£", I18N_NOOP("United Kingdom"), I18N_NOOP("Pound"), "£" },
3085
3086 { "Â¥", I18N_NOOP("Japan"), I18N_NOOP("Yen"), "Â¥" },
3087
3088 { "AFA", I18N_NOOP("Afghanistan"), I18N_NOOP("Afghani"), I18N_NOOP("AFA") },
3089 { "ALL", I18N_NOOP("Albania"), I18N_NOOP("Lek"), I18N_NOOP("Lek") },
3090 { "DZD", I18N_NOOP("Algeria"), I18N_NOOP("Algerian Dinar"), I18N_NOOP("DZD") },
3091 { "USD", I18N_NOOP("American Samoa"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
3092 { "EUR", I18N_NOOP("Andorra"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
3093 { "ADP", I18N_NOOP("Andorra"), I18N_NOOP("Andorran Peseta"), I18N_NOOP("ADP") },
3094 { "AOA", I18N_NOOP("Angola"), I18N_NOOP("Kwanza"), I18N_NOOP("AOA") },
3095 { "XCD", I18N_NOOP("Anguilla"), I18N_NOOP("East Caribbean Dollar"), I18N_NOOP("XCD") },
3096 { "XCD", I18N_NOOP("Antigua And Barbuda"), I18N_NOOP("East Carribean Dollar"), I18N_NOOP("XCD") },
3097 { "ARS", I18N_NOOP("Argentina"), I18N_NOOP("Argentine Peso"), I18N_NOOP("ARS") },
3098 { "AMD", I18N_NOOP("Armenia"), I18N_NOOP("Armenian Dram"), I18N_NOOP("AMD") },
3099 { "AWG", I18N_NOOP("Aruba"), I18N_NOOP("Aruban Guilder"), I18N_NOOP("AWG") },
3100 { "AUD", I18N_NOOP("Australia"), I18N_NOOP("Australian Dollar"), I18N_NOOP("AUD") },
3101 { "EUR", I18N_NOOP("Austria"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
3102 { "ATS", I18N_NOOP("Austria"), I18N_NOOP("Schilling"), I18N_NOOP("S") },
3103 { "AZM", I18N_NOOP("Azerbaijan"), I18N_NOOP("Azerbaijanian Manat"), I18N_NOOP("AZM") },
3104 { "BSD", I18N_NOOP("Bahamas"), I18N_NOOP("Bahamian Dollar"), I18N_NOOP("BSD") },
3105 { "BHD", I18N_NOOP("Bahrain"), I18N_NOOP("Bahraini Dinar"), I18N_NOOP("BHD") },
3106 { "BDT", I18N_NOOP("Bangladesh"), I18N_NOOP("Taka"), I18N_NOOP("BDT") },
3107 { "BBD", I18N_NOOP("Barbados"), I18N_NOOP("Barbados Dollar"), I18N_NOOP("BBD") },
3108 { "BYR", I18N_NOOP("Belarus"), I18N_NOOP("Belarussian Ruble"), I18N_NOOP("p.") },
3109 { "EUR", I18N_NOOP("Belgium"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
3110 { "BEF", I18N_NOOP("Belgium"), I18N_NOOP("Franc"), I18N_NOOP("BF") },
3111 { "BZD", I18N_NOOP("Belize"), I18N_NOOP("Belize Dollar"), I18N_NOOP("BZ$") },
3112 { "XOF", I18N_NOOP("Benin"), I18N_NOOP("CFA Franc BCEAO"), I18N_NOOP("XOF") },
3113 { "BMD", I18N_NOOP("Bermuda"), I18N_NOOP("Bermudian Dollar"), I18N_NOOP("BMD") },
3114 { "INR", I18N_NOOP("Bhutan"), I18N_NOOP("Indian Rupee"), I18N_NOOP("INR") },
3115 { "BTN", I18N_NOOP("Bhutan"), I18N_NOOP("Ngultrum"), I18N_NOOP("BTN") },
3116 { "BOB", I18N_NOOP("Bolivia"), I18N_NOOP("Boliviano"), I18N_NOOP("Bs") },
3117 { "BOV", I18N_NOOP("Bolivia"), I18N_NOOP("Mvdol"), I18N_NOOP("BOV") },
3118 { "BAM", I18N_NOOP("Bosnia And Herzegovina"), I18N_NOOP("Convertible Marks"), I18N_NOOP("BAM") },
3119 { "BWP", I18N_NOOP("Botswana"), I18N_NOOP("Pula"), I18N_NOOP("BWP") },
3120 { "NOK", I18N_NOOP("Bouvet Island"), I18N_NOOP("Norvegian Krone"), I18N_NOOP("NOK") },
3121 { "BRL", I18N_NOOP("Brazil"), I18N_NOOP("Brazilian Real"), I18N_NOOP("R$") },
3122 { "USD", I18N_NOOP("British Indian Ocean Territory"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
3123 { "BND", I18N_NOOP("Brunei Darussalam"), I18N_NOOP("Brunei Dollar"), I18N_NOOP("BND") },
3124 { "BGL", I18N_NOOP("Bulgaria"), I18N_NOOP("Lev"), I18N_NOOP("BGL") },
3125 { "BGN", I18N_NOOP("Bulgaria"), I18N_NOOP("Bulgarian Lev"), I18N_NOOP("BGN") },
3126 { "XOF", I18N_NOOP("Burkina Faso"), I18N_NOOP("CFA Franc BCEAO"), I18N_NOOP("XOF") },
3127 { "BIF", I18N_NOOP("Burundi"), I18N_NOOP("Burundi Franc"), I18N_NOOP("BIF") },
3128 { "KHR", I18N_NOOP("Cambodia"), I18N_NOOP("Riel"), I18N_NOOP("KHR") },
3129 { "XAF", I18N_NOOP("Cameroon"), I18N_NOOP("CFA Franc BEAC"), I18N_NOOP("XAF") },
3130 { "CAD", I18N_NOOP("Canada"), I18N_NOOP("Canadian Dollar"), I18N_NOOP("CAD") },
3131 { "CVE", I18N_NOOP("Cape Verde"), I18N_NOOP("Cape Verde Escudo"), I18N_NOOP("CVE") },
3132 { "KYD", I18N_NOOP("Cayman Islands"), I18N_NOOP("Cayman Islands Dollar"), I18N_NOOP("KYD") },
3133 { "XAF", I18N_NOOP("Central African Republic"), I18N_NOOP("CFA Franc BEAC"), I18N_NOOP("XAF") },
3134 { "XAF", I18N_NOOP("Chad"), I18N_NOOP("CFA Franc BEAC"), I18N_NOOP("XAF") },
3135 { "CLP", I18N_NOOP("Chile"), I18N_NOOP("Chilean Peso"), I18N_NOOP("Ch$") },
3136 { "CLF", I18N_NOOP("Chile"), I18N_NOOP("Unidades de fomento"), I18N_NOOP("CLF") },
3137 { "CNY", I18N_NOOP("China"), I18N_NOOP("Yuan Renminbi"), I18N_NOOP("CNY") },
3138 { "AUD", I18N_NOOP("Christmas Island"), I18N_NOOP("Australian Dollar"), I18N_NOOP("AUD") },
3139 { "AUD", I18N_NOOP("Cocos (Keeling) Islands"), I18N_NOOP("Australian Dollar"), I18N_NOOP("AUD") },
3140 { "COP", I18N_NOOP("Colombia"), I18N_NOOP("Colombian Peso"), I18N_NOOP("C$") },
3141 { "KMF", I18N_NOOP("Comoros"), I18N_NOOP("Comoro Franc"), I18N_NOOP("KMF") },
3142 { "XAF", I18N_NOOP("Congo"), I18N_NOOP("CFA Franc BEAC"), I18N_NOOP("XAF") },
3143 { "CDF", I18N_NOOP("Congo, The Democratic Republic Of"), I18N_NOOP("Franc Congolais"), I18N_NOOP("CDF") },
3144 { "NZD", I18N_NOOP("Cook Islands"), I18N_NOOP("New Zealand Dollar"), I18N_NOOP("NZD") },
3145 { "CRC", I18N_NOOP("Costa Rica"), I18N_NOOP("Costa Rican Colon"), I18N_NOOP("C") },
3146 { "XOF", I18N_NOOP("Cote D'Ivoire"), I18N_NOOP("CFA Franc BCEAO"), I18N_NOOP("XOF") },
3147 { "HRK", I18N_NOOP("Croatia"), I18N_NOOP("Croatian kuna"), I18N_NOOP("kn") },
3148 { "CUP", I18N_NOOP("Cuba"), I18N_NOOP("Cuban Peso"), I18N_NOOP("CUP") },
3149 { "CYP", I18N_NOOP("Cyprus"), I18N_NOOP("Cyprus Pound"), I18N_NOOP("CYP") },
3150 { "CZK", I18N_NOOP("Czech Republic"), I18N_NOOP("Czech Koruna"), I18N_NOOP("Kc") },
3151 { "DKK", I18N_NOOP("Denmark"), I18N_NOOP("Danish Krone"), I18N_NOOP("kr") },
3152 { "DJF", I18N_NOOP("Djibouti"), I18N_NOOP("Djibouti Franc"), I18N_NOOP("DJF") },
3153 { "XCD", I18N_NOOP("Dominica"), I18N_NOOP("East Caribbean Dollar"), I18N_NOOP("RD$") },
3154 { "DOP", I18N_NOOP("Dominican Republic"), I18N_NOOP("Dominican Peso"), I18N_NOOP("DOP") },
3155 { "TPE", I18N_NOOP("East Timor"), I18N_NOOP("Timor Escudo"), I18N_NOOP("TPE") },
3156 { "USD", I18N_NOOP("East Timor"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
3157 { "USD", I18N_NOOP("Ecuador"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
3158 { "EGP", I18N_NOOP("Egypt"), I18N_NOOP("Egyptian Pound"), I18N_NOOP("EGP") },
3159 { "SVC", I18N_NOOP("El Salvador"), I18N_NOOP("El Salvador Colon"), I18N_NOOP("C") },
3160 { "USD", I18N_NOOP("El Salvador"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
3161 { "XAF", I18N_NOOP("Equatorial Guinea"), I18N_NOOP("CFA Franc BEAC"), I18N_NOOP("XAF") },
3162 { "ERN", I18N_NOOP("Eritrea"), I18N_NOOP("Nakfa"), I18N_NOOP("ERN") },
3163 { "EEK", I18N_NOOP("Estonia"), I18N_NOOP("Kroon"), I18N_NOOP("kr") },
3164 { "ETB", I18N_NOOP("Ethiopia"), I18N_NOOP("Ethiopian Birr"), I18N_NOOP("ETB") },
3165 { "FKP", I18N_NOOP("Falkland Island (Malvinas)"), I18N_NOOP("Falkland Islands Pound"), I18N_NOOP("FKP") },
3166 { "DKK", I18N_NOOP("Faeroe Islands"), I18N_NOOP("Danish Krone"), I18N_NOOP("kr") },
3167 { "FJD", I18N_NOOP("Fiji"), I18N_NOOP("Fiji Dollar"), I18N_NOOP("FJD") },
3168 { "EUR", I18N_NOOP("Finland"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
3169 { "FIM", I18N_NOOP("Finland"), I18N_NOOP("Markka"), I18N_NOOP("mk") },
3170 { "EUR", I18N_NOOP("France"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
3171 { "FRF", I18N_NOOP("France"), I18N_NOOP("Franc"), I18N_NOOP("F") },
3172 { "EUR", I18N_NOOP("French Guiana"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
3173 { "XPF", I18N_NOOP("French Polynesia"), I18N_NOOP("CFP Franc"), I18N_NOOP("XPF") },
3174 { "EUR", I18N_NOOP("Franc Southern Territories"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
3175 { "XAF", I18N_NOOP("Gabon"), I18N_NOOP("CFA Franc BEAC"), I18N_NOOP("XAF") },
3176 { "GMD", I18N_NOOP("Gambia"), I18N_NOOP("Dalasi"), I18N_NOOP("GMD") },
3177 { "GEL", I18N_NOOP("Georgia"), I18N_NOOP("Lari"), I18N_NOOP("GEL") },
3178 { "EUR", I18N_NOOP("Germany"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
3179 { "DEM", I18N_NOOP("Germany"), I18N_NOOP("German Mark"), I18N_NOOP("DM") },
3180 { "GHC", I18N_NOOP("Ghana"), I18N_NOOP("Cedi"), I18N_NOOP("GHC") },
3181 { "GIP", I18N_NOOP("Gibraltar"), I18N_NOOP("Gibraltar Pound"), I18N_NOOP("GIP") },
3182 { "EUR", I18N_NOOP("Greece"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
3183 { "GRD", I18N_NOOP("Greece"), I18N_NOOP("Drachma"), I18N_NOOP("GRD") },
3184 { "DKK", I18N_NOOP("Greenland"), I18N_NOOP("Danish Krone"), I18N_NOOP("DKK") },
3185 { "XCD", I18N_NOOP("Grenada"), I18N_NOOP("East Caribbean Dollar"), I18N_NOOP("XCD") },
3186 { "EUR", I18N_NOOP("Guadeloupe"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
3187 { "USD", I18N_NOOP("Guam"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
3188 { "GTQ", I18N_NOOP("Guatemala"), I18N_NOOP("Quetzal"), I18N_NOOP("Q") },
3189 { "GNF", I18N_NOOP("Guinea"), I18N_NOOP("Guinea Franc"), I18N_NOOP("GNF") },
3190 { "GWP", I18N_NOOP("Guinea-Bissau"), I18N_NOOP("Guinea-Bissau Peso"), I18N_NOOP("GWP") },
3191 { "XOF", I18N_NOOP("Guinea-Bissau"), I18N_NOOP("CFA Franc BCEAO"), I18N_NOOP("XOF") },
3192 { "GYD", I18N_NOOP("Guyana"), I18N_NOOP("Guyana Dollar"), I18N_NOOP("GYD") },
3193 { "HTG", I18N_NOOP("Haiti"), I18N_NOOP("Gourde"), I18N_NOOP("HTG") },
3194 { "USD", I18N_NOOP("Haiti"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
3195 { "AUD", I18N_NOOP("Heard Island And McDonald Islands"), I18N_NOOP("Australian Dollar"), I18N_NOOP("AUD") },
3196 { "EUR", I18N_NOOP("Holy See (Vatican City State)"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
3197 { "HNL", I18N_NOOP("Honduras"), I18N_NOOP("Lempira"), I18N_NOOP("L") },
3198 { "HKD", I18N_NOOP("Hong Kong"), I18N_NOOP("Hong Kong Dollar"), I18N_NOOP("HKD") },
3199 { "HUF", I18N_NOOP("Hungary"), I18N_NOOP("Forint"), I18N_NOOP("Ft") },
3200 { "ISK", I18N_NOOP("Iceland"), I18N_NOOP("Iceland Krona"), I18N_NOOP("kr.") },
3201 { "INR", I18N_NOOP("India"), I18N_NOOP("Indian Rupee"), I18N_NOOP("INR") },
3202 { "IDR", I18N_NOOP("Indonesia"), I18N_NOOP("Rupiah"), I18N_NOOP("Rp") },
3203 { "IRR", I18N_NOOP("Iran, Islamic Republic Of"), I18N_NOOP("Iranian Rial"), I18N_NOOP("IRR") },
3204 { "IQD", I18N_NOOP("Iraq"), I18N_NOOP("Iraqi Dinar"), I18N_NOOP("IQD") },
3205 { "EUR", I18N_NOOP("Ireland"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
3206 { "IEP", I18N_NOOP("Ireland"), I18N_NOOP("Punt"), I18N_NOOP("IR----") },
3207 { "IEX", I18N_NOOP("Ireland"), I18N_NOOP("Pence"), I18N_NOOP("IEX") },
3208 { "ILS", I18N_NOOP("Israel"), I18N_NOOP("New Israeli Sheqel"), I18N_NOOP("ILS") },
3209 { "EUR", I18N_NOOP("Italy"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
3210 { "ITL", I18N_NOOP("Italy"), I18N_NOOP("Lira"), I18N_NOOP("L.") },
3211 { "JMD", I18N_NOOP("Jamaica"), I18N_NOOP("Jamaican Dollar"), I18N_NOOP("J$") },
3212 { "JPY", I18N_NOOP("Japan"), I18N_NOOP("Yen"), I18N_NOOP("JPY") },
3213 { "JOD", I18N_NOOP("Jordan"), I18N_NOOP("Jordanian Dinar"), I18N_NOOP("JOD") },
3214 { "KZT", I18N_NOOP("Kazakhstan"), I18N_NOOP("Tenge"), I18N_NOOP("KZT") },
3215 { "KES", I18N_NOOP("Kenya"), I18N_NOOP("Kenyan Shilling"), I18N_NOOP("KES") },
3216 { "AUD", I18N_NOOP("Kiribati"), I18N_NOOP("Australian Dollar"), I18N_NOOP("AUD") },
3217 { "KPW", I18N_NOOP("Korea, Democratic People's Republic Of"), I18N_NOOP("North Korean Won"), I18N_NOOP("KPW") },
3218 { "KRW", I18N_NOOP("Korea, Republic Of"), I18N_NOOP("Won"), I18N_NOOP("KRW") },
3219 { "KWD", I18N_NOOP("Kuwait"), I18N_NOOP("Kuwaiti Dinar"), I18N_NOOP("KWD") },
3220 { "KGS", I18N_NOOP("Kyrgyzstan"), I18N_NOOP("Som"), I18N_NOOP("KGS") },
3221 { "LAK", I18N_NOOP("Lao People's Democratic Republic"), I18N_NOOP("Kip"), I18N_NOOP("LAK") },
3222 { "LVL", I18N_NOOP("Latvia"), I18N_NOOP("Latvian Lats"), I18N_NOOP("Ls") },
3223 { "LBP", I18N_NOOP("Lebanon"), I18N_NOOP("Lebanese Pound"), I18N_NOOP("LBP") },
3224 { "ZAR", I18N_NOOP("Lesotho"), I18N_NOOP("Rand"), I18N_NOOP("ZAR") },
3225 { "LSL", I18N_NOOP("Lesotho"), I18N_NOOP("Loti"), I18N_NOOP("LSL") },
3226 { "LRD", I18N_NOOP("Liberia"), I18N_NOOP("Liberian Dollar"), I18N_NOOP("LRD") },
3227 { "LYD", I18N_NOOP("Libyan Arab Jamahiriya"), I18N_NOOP("Lybian Dinar"), I18N_NOOP("LYD") },
3228 { "CHF", I18N_NOOP("Liechtenstein"), I18N_NOOP("Swiss Franc"), I18N_NOOP("CHF") },
3229 { "LTL", I18N_NOOP("Lithuania"), I18N_NOOP("Lithuanian Litus"), I18N_NOOP("Lt") },
3230 { "EUR", I18N_NOOP("Luxembourg"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
3231 { "LUF", I18N_NOOP("Luxembourg"), I18N_NOOP("Franc"), I18N_NOOP("F") },
3232 { "MOP", I18N_NOOP("Macao"), I18N_NOOP("Pataca"), I18N_NOOP("MOP") },
3233 { "MKD", I18N_NOOP("Macedonia, The Former Yugoslav Republic Of"), I18N_NOOP("Denar"), I18N_NOOP("MKD") },
3234 { "MGF", I18N_NOOP("Madagascar"), I18N_NOOP("Malagasy Franc"), I18N_NOOP("MGF") },
3235 { "MWK", I18N_NOOP("Malawi"), I18N_NOOP("Kwacha"), I18N_NOOP("MWK") },
3236 { "MYR", I18N_NOOP("Malaysia"), I18N_NOOP("Malaysian Ringgit"), I18N_NOOP("MYR") },
3237 { "MVR", I18N_NOOP("Maldives"), I18N_NOOP("Rufiyaa"), I18N_NOOP("MVR") },
3238 { "XOF", I18N_NOOP("Mali"), I18N_NOOP("CFA Franc BCEAO"), I18N_NOOP("XOF") },
3239 { "MTL", I18N_NOOP("Malta"), I18N_NOOP("Maltese Lira"), I18N_NOOP("MTL") },
3240 { "USD", I18N_NOOP("Marshall Islands"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
3241 { "EUR", I18N_NOOP("Martinique"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
3242 { "MRO", I18N_NOOP("Mauritania"), I18N_NOOP("Ouguiya"), I18N_NOOP("MRO") },
3243 { "MUR", I18N_NOOP("Mauritius"), I18N_NOOP("Mauritius Rupee"), I18N_NOOP("MUR") },
3244 { "EUR", I18N_NOOP("Mayotte"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
3245 { "MXN", I18N_NOOP("Mexico"), I18N_NOOP("Mexican Peso"), I18N_NOOP("MXN") },
3246 { "MXV", I18N_NOOP("Mexico"), I18N_NOOP("Mexican Unidad de Inversion (UDI)"), I18N_NOOP("MXV") },
3247 { "USD", I18N_NOOP("Micronesia, Federated States Of"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
3248 { "MDL", I18N_NOOP("Moldova, Republic Of"), I18N_NOOP("Moldovan Leu"), I18N_NOOP("MDL") },
3249 { "EUR", I18N_NOOP("Monaco"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
3250 { "MNT", I18N_NOOP("Mongolia"), I18N_NOOP("Tugrik"), I18N_NOOP("MNT") },
3251 { "XCD", I18N_NOOP("Montserrat"), I18N_NOOP("East Caribbean Dollar"), I18N_NOOP("XCD") },
3252 { "MAD", I18N_NOOP("Morocco"), I18N_NOOP("Moroccan Dirham"), I18N_NOOP("MAD") },
3253 { "MZM", I18N_NOOP("Mozambique"), I18N_NOOP("Metical"), I18N_NOOP("MZM") },
3254 { "MMK", I18N_NOOP("Myanmar"), I18N_NOOP("Kyat"), I18N_NOOP("MMK") },
3255 { "ZAR", I18N_NOOP("Namibia"), I18N_NOOP("Rand"), I18N_NOOP("ZAR") },
3256 { "NAD", I18N_NOOP("Namibia"), I18N_NOOP("Namibia Dollar"), I18N_NOOP("NAD") },
3257 { "AUD", I18N_NOOP("Nauru"), I18N_NOOP("Australian Dollar"), I18N_NOOP("AUD") },
3258 { "NPR", I18N_NOOP("Nepal"), I18N_NOOP("Nepalese Rupee"), I18N_NOOP("NPR") },
3259 { "EUR", I18N_NOOP("Netherlands"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
3260 { "NLG", I18N_NOOP("Netherlands"), I18N_NOOP("Guilder"), I18N_NOOP("fl") },
3261 { "ANG", I18N_NOOP("Netherlands Antilles"), I18N_NOOP("Netherlands Antillan Guilder"), I18N_NOOP("ANG") },
3262 { "XPF", I18N_NOOP("New Caledonia"), I18N_NOOP("CFP Franc"), I18N_NOOP("XPF") },
3263 { "NZD", I18N_NOOP("New Zealand"), I18N_NOOP("New Zealand Dollar"), I18N_NOOP("NZD") },
3264 { "NIO", I18N_NOOP("Nicaragua"), I18N_NOOP("Cordoba Oro"), I18N_NOOP("NIO") },
3265 { "XOF", I18N_NOOP("Niger"), I18N_NOOP("CFA Franc BCEAO"), I18N_NOOP("XOF") },
3266 { "NGN", I18N_NOOP("Nigeria"), I18N_NOOP("Naira"), I18N_NOOP("NGN") },
3267 { "NZD", I18N_NOOP("Niue"), I18N_NOOP("New Zealand Dollar"), I18N_NOOP("NZD") },
3268 { "AUD", I18N_NOOP("Norfolk Islands"), I18N_NOOP("Australian Dollar"), I18N_NOOP("AUD") },
3269 { "USD", I18N_NOOP("Northern Mariana Islands"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
3270 { "NOK", I18N_NOOP("Norway"), I18N_NOOP("Norwegian Krone"), I18N_NOOP("kr") },
3271 { "OMR", I18N_NOOP("Oman"), I18N_NOOP("Rial Omani"), I18N_NOOP("OMR") },
3272 { "PKR", I18N_NOOP("Pakistan"), I18N_NOOP("Pakistan Rupee"), I18N_NOOP("PKR") },
3273 { "USD", I18N_NOOP("Palau"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
3274 { "PAB", I18N_NOOP("Panama"), I18N_NOOP("Balboa"), I18N_NOOP("PAB") },
3275 { "USD", I18N_NOOP("Panama"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
3276 { "PGK", I18N_NOOP("Papua New Guinea"), I18N_NOOP("Kina"), I18N_NOOP("PGK") },
3277 { "PYG", I18N_NOOP("Paraguay"), I18N_NOOP("Guarani"), I18N_NOOP("G") },
3278 { "PEN", I18N_NOOP("Peru"), I18N_NOOP("Nuevo Sol"), I18N_NOOP("PEN") },
3279 { "PHP", I18N_NOOP("Philippines"), I18N_NOOP("Philippine Peso"), I18N_NOOP("PHP") },
3280 { "NZD", I18N_NOOP("Pitcairn"), I18N_NOOP("New Zealand Dollar"), I18N_NOOP("NZD") },
3281 { "PLN", I18N_NOOP("Poland"), I18N_NOOP("Zloty"), I18N_NOOP("zt") },
3282 { "EUR", I18N_NOOP("Portugal"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
3283 { "PTE", I18N_NOOP("Portugal"), I18N_NOOP("Escudo"), I18N_NOOP("Esc.") },
3284 { "USD", I18N_NOOP("Puerto Rico"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
3285 { "QAR", I18N_NOOP("Qatar"), I18N_NOOP("Qatari Rial"), I18N_NOOP("QAR") },
3286 { "ROL", I18N_NOOP("Romania"), I18N_NOOP("Leu"), I18N_NOOP("LEI") },
3287 { "RUR", I18N_NOOP("Russian Federation"), I18N_NOOP("Russian Ruble"), I18N_NOOP("RUR") },
3288 { "RUB", I18N_NOOP("Russian Federation"), I18N_NOOP("Russian Ruble"), I18N_NOOP("RUB") },
3289 { "RWF", I18N_NOOP("Rwanda"), I18N_NOOP("Rwanda Franc"), I18N_NOOP("RWF") },
3290 { "SHP", I18N_NOOP("Saint Helena"), I18N_NOOP("Saint Helena Pound"), I18N_NOOP("SHP") },
3291 { "XCD", I18N_NOOP("Saint Kitts And Nevis"), I18N_NOOP("East Caribbean Dollar"), I18N_NOOP("XCD") },
3292 { "XCD", I18N_NOOP("Saint Lucia"), I18N_NOOP("East Caribbean Dollar"), I18N_NOOP("XCD") },
3293 { "EUR", I18N_NOOP("Saint Pierre And Miquelon"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
3294 { "XCD", I18N_NOOP("Saint Vincent And The Grenadines"), I18N_NOOP("East Caribbean Dollar"), I18N_NOOP("XCD") },
3295 { "WST", I18N_NOOP("Samoa"), I18N_NOOP("Tala"), I18N_NOOP("WST") },
3296 { "EUR", I18N_NOOP("San Marino"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
3297 { "STD", I18N_NOOP("Sao Tome And Principe"), I18N_NOOP("Dobra"), I18N_NOOP("STD") },
3298 { "SAR", I18N_NOOP("Saudi Arabia"), I18N_NOOP("Saudi Riyal"), I18N_NOOP("SAR") },
3299 { "XOF", I18N_NOOP("Senegal"), I18N_NOOP("CFA Franc BCEAO"), I18N_NOOP("XOF") },
3300 { "SCR", I18N_NOOP("Seychelles"), I18N_NOOP("Seychelles Rupee"), I18N_NOOP("SCR") },
3301 { "SLL", I18N_NOOP("Sierra Leone"), I18N_NOOP("Leone"), I18N_NOOP("SLL") },
3302 { "SGD", I18N_NOOP("Singapore"), I18N_NOOP("Singapore Dollar"), I18N_NOOP("SGD") },
3303 { "SKK", I18N_NOOP("Slovakia"), I18N_NOOP("Slovak Koruna"), I18N_NOOP("Sk") },
3304 { "EUR", I18N_NOOP("Slovenia"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
3305 { "SBD", I18N_NOOP("Solomon Islands"), I18N_NOOP("Solomon Islands Dollar"), I18N_NOOP("SBD") },
3306 { "SOS", I18N_NOOP("Somalia"), I18N_NOOP("Somali Shilling"), I18N_NOOP("SOS") },
3307 { "ZAR", I18N_NOOP("South Africa"), I18N_NOOP("Rand"), I18N_NOOP("R") },
3308 { "EUR", I18N_NOOP("Spain"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
3309 { "ESP", I18N_NOOP("Spain"), I18N_NOOP("Peseta"), I18N_NOOP("Pts") },
3310 { "LKR", I18N_NOOP("Sri Lanka"), I18N_NOOP("Sri Lanka Rupee"), I18N_NOOP("LKR") },
3311 { "SDD", I18N_NOOP("Sudan"), I18N_NOOP("Sudanese Dinar"), I18N_NOOP("SDD") },
3312 { "SRG", I18N_NOOP("Suriname"), I18N_NOOP("Suriname Guilder"), I18N_NOOP("SRG") },
3313 { "NOK", I18N_NOOP("Svalbard And Jan Mayen"), I18N_NOOP("Norwegian Krone"), I18N_NOOP("NOK") },
3314 { "SZL", I18N_NOOP("Swaziland"), I18N_NOOP("Lilangeni"), I18N_NOOP("SZL") },
3315 { "SEK", I18N_NOOP("Sweden"), I18N_NOOP("Swedish Krona"), I18N_NOOP("kr") },
3316 { "CHF", I18N_NOOP("Switzerland"), I18N_NOOP("Swiss Franc"), I18N_NOOP("SFr.") },
3317 { "SYP", I18N_NOOP("Syrian Arab Republic"), I18N_NOOP("Syrian Pound"), I18N_NOOP("SYP") },
3318 { "TWD", I18N_NOOP("Taiwan, Province Of China"), I18N_NOOP("New Taiwan Dollar"), I18N_NOOP("TWD") },
3319 { "TJS", I18N_NOOP("Tajikistan"), I18N_NOOP("Somoni"), I18N_NOOP("TJS") },
3320 { "TZS", I18N_NOOP("Tanzania, United Republic Of"), I18N_NOOP("Tanzanian Shilling"), I18N_NOOP("TZS") },
3321 { "THB", I18N_NOOP("Thailand"), I18N_NOOP("Baht"), I18N_NOOP("THB") },
3322 { "XOF", I18N_NOOP("Togo"), I18N_NOOP("CFA Franc BCEAO"), I18N_NOOP("XOF") },
3323 { "NZD", I18N_NOOP("Tokelau"), I18N_NOOP("New Zealand Dollar"), I18N_NOOP("NZD") },
3324 { "TOP", I18N_NOOP("Tonga"), I18N_NOOP("Pa'anga"), I18N_NOOP("TOP") },
3325 { "TTD", I18N_NOOP("Trinidad And Tobago"), I18N_NOOP("Trinidad and Tobago Dollar"), I18N_NOOP("TT$") },
3326 { "TND", I18N_NOOP("Tunisia"), I18N_NOOP("Tunisian Dinar"), I18N_NOOP("TND") },
3327 { "TRL", I18N_NOOP("Turkey"), I18N_NOOP("Turkish Lira"), I18N_NOOP("TL") },
3328 { "TMM", I18N_NOOP("Turkmenistan"), I18N_NOOP("Manat"), I18N_NOOP("TMM") },
3329 { "USD", I18N_NOOP("Turks And Caicos Islands"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
3330 { "AUD", I18N_NOOP("Tuvalu"), I18N_NOOP("Australian Dollar"), I18N_NOOP("AUD") },
3331 { "UGX", I18N_NOOP("Uganda"), I18N_NOOP("Uganda Shilling"), I18N_NOOP("UGX") },
3332 { "UAH", I18N_NOOP("Ukraine"), I18N_NOOP("Hryvnia"), I18N_NOOP("UAH") },
3333 { "AED", I18N_NOOP("United Arab Emirates"), I18N_NOOP("UAE Dirham"), I18N_NOOP("AED") },
3334 { "GBP", I18N_NOOP("United Kingdom"), I18N_NOOP("Pound Sterling"), I18N_NOOP("GBP") },
3335 { "USD", I18N_NOOP("United States"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
3336 { "USN", I18N_NOOP("United States"), I18N_NOOP("US Dollar (Next day)"), I18N_NOOP("USN") },
3337 { "USS", I18N_NOOP("United States"), I18N_NOOP("US Dollar (Same day)"), I18N_NOOP("USS") },
3338 { "UYU", I18N_NOOP("Uruguay"), I18N_NOOP("Peso Uruguayo"), I18N_NOOP("NU$") },
3339 { "UZS", I18N_NOOP("Uzbekistan"), I18N_NOOP("Uzbekistan Sum"), I18N_NOOP("UZS") },
3340 { "VUV", I18N_NOOP("Vanuatu"), I18N_NOOP("Vatu"), I18N_NOOP("VUV") },
3341 { "VEB", I18N_NOOP("Venezuela"), I18N_NOOP("Bolivar"), I18N_NOOP("Bs") },
3342 { "VND", I18N_NOOP("Viet Nam"), I18N_NOOP("Dong"), I18N_NOOP("VND") },
3343 { "USD", I18N_NOOP("Virgin Islands"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
3344 { "XPF", I18N_NOOP("Wallis And Futuna"), I18N_NOOP("CFP Franc"), I18N_NOOP("XPF") },
3345 { "MAD", I18N_NOOP("Western Sahara"), I18N_NOOP("Moroccan Dirham"), I18N_NOOP("MAD") },
3346 { "YER", I18N_NOOP("Yemen"), I18N_NOOP("Yemeni Rial"), I18N_NOOP("YER") },
3347 { "YUM", I18N_NOOP("Yugoslavia"), I18N_NOOP("Yugoslavian Dinar"), I18N_NOOP("YUM") },
3348 { "ZMK", I18N_NOOP("Zambia"), I18N_NOOP("Kwacha"), I18N_NOOP("ZMK") },
3349 { "ZWD", I18N_NOOP("Zimbabwe"), I18N_NOOP("Zimbabwe Dollar"), I18N_NOOP("ZWD") },
3350 { 0, 0, 0, 0}, // Last must be empty!
3351 };
3352
3353
3354 class CurrencyMap
3355 {
3356 public:
3357 CurrencyMap()
3358 : m_List(lMoney)
3359 {
3360 }
3361
3362 // Those return the _untranslated_ strings from the above array
3363 TQString getCode(int t) const
3364 {
3365 return TQString::fromUtf8( m_List[t].code );
3366 }
3367
3368 TQString getCountry(int t) const
3369 {
3370 return TQString::fromUtf8( m_List[t].country );
3371 }
3372
3373 TQString getName(int t) const
3374 {
3375 return TQString::fromUtf8( m_List[t].name );
3376 }
3377
3378 TQString getDisplayCode(int t) const
3379 {
3380 return TQString::fromUtf8( m_List[t].display );
3381 }
3382
3383 int getIndex(const TQString& code) const
3384 {
3385 int index = 0;
3386 while (m_List[index].code != 0 && m_List[index].code != code)
3387 ++index;
3388 return (m_List[index].code != 0) ? index : 1 /*undef*/;
3389 }
3390
3391 private:
3392 const Money * m_List;
3393 };
3394
3395 const CurrencyMap gCurrencyMap;
3396 const Money * gMoneyList(lMoney);
3397}
3398
3399
3400using namespace Currency_LNS;
3401
3402Currency::Currency()
3403 : m_type( 0 )
3404{
3405}
3406
3407Currency::~Currency()
3408{
3409}
3410
3411Currency::Currency(int index)
3412 : m_type( index ),
3413 m_code( gCurrencyMap.getCode( index ) )
3414{
3415}
3416
3417Currency::Currency(int index, TQString const & code)
3418 : m_type ( 1 ), // unspec
3419 m_code( code )
3420{
3421 if ( gCurrencyMap.getCode( index ) == code )
3422 m_type = index;
3423}
3424
3425Currency::Currency(TQString const & code, currencyFormat format)
3426 : m_type( 1 ), // unspec
3427 m_code( code )
3428{
3429 if ( format == Gnumeric )
3430 {
3431 // I use TQChar(c,r) here so that this file can be opened in any encoding...
3432 if ( code.find( TQChar( 172, 32 ) ) != -1 ) // Euro sign
3433 m_code = TQChar( 172, 32 );
3434 else if ( code.find( TQChar( 163, 0 ) ) != -1 ) // Pound sign
3435 m_code = TQChar( 163, 0 );
3436 else if ( code.find( TQChar( 165, 0 ) ) != -1 ) // Yen sign
3437 m_code = TQChar( 165, 0 );
3438 else if ( code[0] == '[' && code[1] == '$' )
3439 {
3440 int n = code.find(']');
3441 if (n != -1)
3442 {
3443 m_code = code.mid( 2, n - 2 );
3444 }
3445 else
3446 {
3447 m_type = 0;
3448 }
3449 }
3450 else if ( code.find( '$' ) != -1 )
3451 m_code = "$";
3452 } // end gnumeric
3453 m_type = gCurrencyMap.getIndex( m_code );
3454}
3455
3456Currency & Currency::operator=(int type)
3457{
3458 m_type = type;
3459 m_code = gCurrencyMap.getCode( m_type );
3460
3461 return *this;
3462}
3463
3464Currency & Currency::operator=(char const * code)
3465{
3466 m_type = 1;
3467 m_code = code;
3468
3469 return *this;
3470}
3471
3472bool Currency::operator==(Currency const & cur) const
3473{
3474 if ( m_type == cur.m_type )
3475 return true;
3476
3477 if ( m_code == cur.m_code )
3478 return true;
3479
3480 return false;
3481}
3482
3483bool Currency::operator==(int type) const
3484{
3485 if ( m_type == type )
3486 return true;
3487
3488 return false;
3489}
3490
3491Currency::operator int() const
3492{
3493 return m_type;
3494}
3495
3496TQString Currency::getCode() const
3497{
3498 return m_code;
3499}
3500
3501TQString Currency::getCountry() const
3502{
3503 return gCurrencyMap.getCountry( m_type );
3504}
3505
3506TQString Currency::getName() const
3507{
3508 return gCurrencyMap.getName( m_type );
3509}
3510
3511TQString Currency::getDisplayCode() const
3512{
3513 return gMoneyList[m_type].display;
3514}
3515
3516int Currency::getIndex() const
3517{
3518 return m_type;
3519}
3520
3521TQString Currency::getExportCode( currencyFormat format ) const
3522{
3523 if ( format == Gnumeric )
3524 {
3525 if ( m_code.length() == 1 ) // symbol
3526 return m_code;
3527
3528 TQString ret( "[$");
3529 ret += m_code;
3530 ret += "]";
3531
3532 return ret;
3533 }
3534
3535 return m_code;
3536}
3537
3538TQString Currency::getChooseString( int type, bool & ok )
3539{
3540 if ( !gMoneyList[type].country )
3541 {
3542 ok = false;
3543 return TQString();
3544 }
3545 if ( type < 24 )
3546 {
3547 TQString ret( i18n( gMoneyList[type].name ) );
3548 if ( gMoneyList[type].country[0] )
3549 {
3550 ret += " (";
3551 ret += i18n( gMoneyList[type].country );
3552 ret += ")";
3553 }
3554 return ret;
3555 }
3556 else
3557 {
3558 TQString ret( i18n( gMoneyList[type].country ) );
3559 if ( gMoneyList[type].name[0] )
3560 {
3561 ret += " (";
3562 ret += i18n( gMoneyList[type].name );
3563 ret += ")";
3564 }
3565 return ret;
3566 }
3567}
3568
3569TQString Currency::getDisplaySymbol( int type )
3570{
3571 return i18n( gMoneyList[type].display );
3572}
3573
3574// Currently unused
3575TQString Currency::getCurrencyCode( int type )
3576{
3577 return TQString::fromUtf8( gMoneyList[type].code );
3578}
3579
3580#undef UPDATE_BEGIN
3581#undef UPDATE_END
The canvas builds a part of the GUI of KSpread.
double zoom() const
convenience function
Sheet * activeSheet() const
The Style class represents a cell style.
@ BUILTIN
built-in style (the default style)
@ CUSTOM
custom style (defined in the StyleManager dialog)
Mode
The pasted content.
@ Format
Format only.
@ Comment
Comment only.
@ Text
Text only.
@ NoBorder
not the borders
@ Normal
Everything.
The KSpread namespace.
Definition commands.h:39