kspread

kspread_format.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999  Torben Weis <weis@kde.org>
00003    Copyright (C) 2000 - 2005 The KSpread Team
00004                               www.koffice.org/kspread
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License as published by the Free Software Foundation; either
00009    version 2 of the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Library General Public License for more details.
00015 
00016    You should have received a copy of the GNU Library General Public License
00017    along with this library; see the file COPYING.LIB.  If not, write to
00018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include <float.h>
00023 #include <iostream>
00024 #include <stdlib.h>
00025 #include <stdio.h>
00026 
00027 #include <dcopobject.h>
00028 #include <kdebug.h>
00029 #include <klocale.h>
00030 
00031 #include <KoXmlNS.h>
00032 #include <KoGenStyles.h>
00033 #include <KoGlobal.h>
00034 #include <KoStyleStack.h>
00035 #include <KoOasisLoadingContext.h>
00036 #include <KoOasisStyles.h>
00037 
00038 #include "kspread_canvas.h"
00039 #include "kspread_doc.h"
00040 #include "kspread_global.h"
00041 #include "kspread_sheet.h"
00042 #include "kspread_sheetprint.h"
00043 #include "kspread_style.h"
00044 #include "kspread_style_manager.h"
00045 #include "KSpreadColumnIface.h"
00046 #include "KSpreadLayoutIface.h"
00047 #include "KSpreadRowIface.h"
00048 
00049 #include "kspread_format.h"
00050 
00051 namespace format_LNS
00052 {
00053   double g_colWidth  = colWidth;
00054   double g_rowHeight = heightOfRow;
00055 }
00056 
00057 using namespace std;
00058 using namespace format_LNS;
00059 using namespace KSpread;
00060 
00061 /*****************************************************************************
00062  *
00063  * Format
00064  *
00065  *****************************************************************************/
00066 
00067 Format::Format( Sheet * _sheet, Style * _style )
00068   : m_pSheet( _sheet ),
00069     m_pStyle( _style ),
00070     m_mask( 0 ),
00071     m_bNoFallBack( 0 ),
00072     m_flagsMask( 0 ),
00073     m_strComment( 0 ),
00074     m_pCell( 0 )
00075 {
00076 }
00077 
00078 Format::~Format()
00079 {
00080     if ( m_pStyle->release() )
00081         delete m_pStyle;
00082 }
00083 
00084 void Format::defaultStyleFormat()
00085 {
00086   if ( m_pStyle->release() )
00087     delete m_pStyle;
00088 
00089   if ( m_pSheet )
00090     m_pStyle = m_pSheet->doc()->styleManager()->defaultStyle();
00091 
00092   delete m_strComment;
00093 }
00094 
00095 
00096 void Format::setGlobalColWidth( double width )
00097 {
00098   g_colWidth = width;
00099 }
00100 
00101 void Format::setGlobalRowHeight( double height )
00102 {
00103   g_rowHeight = height;
00104 }
00105 
00106 double Format::globalRowHeight()
00107 {
00108   return g_rowHeight;
00109 }
00110 
00111 double Format::globalColWidth()
00112 {
00113   return g_colWidth;
00114 }
00115 
00116 void Format::copy( const Format & _l )
00117 {
00118   // TODO why is the sheet not copied?
00119 
00120   setStyle( _l.m_pStyle );
00121 
00122   m_mask        = _l.m_mask;
00123   m_flagsMask   = _l.m_flagsMask;
00124   m_bNoFallBack = _l.m_bNoFallBack;
00125 
00126   if ( _l.m_strComment )
00127   {
00128     if (m_strComment)
00129       delete m_strComment;
00130     m_strComment  = new QString( *_l.m_strComment );
00131   }
00132 }
00133 
00134 void Format::setStyle( Style * style )
00135 {
00136   if ( style == m_pStyle )
00137     return;
00138 
00139   if ( m_pStyle && m_pStyle->release() )
00140     delete m_pStyle;
00141 
00142   m_bNoFallBack = 0;
00143   m_pStyle = style;
00144   m_pStyle->addRef();
00145   formatChanged();
00146  // kdDebug() << "Newly assigned style: " << m_pStyle << ", type: " << m_pStyle->type() << endl;
00147   if ( style->type() == Style::BUILTIN || style->type() == Style::CUSTOM )
00148     kdDebug() << "Style name: " << ((CustomStyle *) m_pStyle)->name() << endl;
00149 }
00150 
00151 void Format::clearFlag( FormatFlags flag )
00152 {
00153   m_flagsMask &= ~(Q_UINT32)flag;
00154 }
00155 
00156 void Format::setFlag( FormatFlags flag )
00157 {
00158   m_flagsMask |= (Q_UINT32)flag;
00159 }
00160 
00161 bool Format::testFlag( FormatFlags flag ) const
00162 {
00163   return ( m_flagsMask & (Q_UINT32)flag );
00164 }
00165 
00166 void Format::clearProperties()
00167 {
00168     m_mask = 0;
00169 
00170     formatChanged();
00171 }
00172 
00173 void Format::clearProperty( Properties p )
00174 {
00175     m_mask &= ~(uint)p;
00176 
00177     formatChanged();
00178 }
00179 
00180 // FIXME according to Valgrind, this function consumes too much time
00181 // find a way to optimize it !
00182 bool Format::hasProperty( Properties p, bool withoutParent ) const
00183 {
00184     if ( m_pStyle->hasFeature( (Style::FlagsSet) p, withoutParent ) )
00185         return true;
00186 
00187     return ( m_mask & (uint)p );
00188 }
00189 
00190 void Format::setProperty( Properties p )
00191 {
00192     m_mask |= (uint)p;
00193 }
00194 
00195 void Format::clearNoFallBackProperties()
00196 {
00197     m_bNoFallBack = 0;
00198 
00199     formatChanged();
00200 }
00201 
00202 void Format::clearNoFallBackProperties( Properties p )
00203 {
00204     m_bNoFallBack &= ~(uint)p;
00205 
00206     formatChanged();
00207 }
00208 
00209 bool Format::hasNoFallBackProperties( Properties p ) const
00210 {
00211     return ( m_bNoFallBack & (uint)p );
00212 }
00213 
00214 void Format::setNoFallBackProperties( Properties p )
00215 {
00216     m_bNoFallBack |= (uint)p;
00217 }
00218 
00219 
00221 //
00222 // Loading and saving
00223 //
00225 
00226 
00227 QString Format::saveOasisCellStyle( KoGenStyle &currentCellStyle, KoGenStyles &mainStyles )
00228 {
00229   QString styleName;
00230   styleName = m_pStyle->saveOasis( currentCellStyle, mainStyles );
00231 
00232     // user styles are already stored
00233   if ( currentCellStyle.type() == Doc::STYLE_CELL_AUTO )
00234   {
00235     styleName = mainStyles.lookup( currentCellStyle, "ce" );
00236   }
00237 
00238   return styleName;
00239 }
00240 
00241 QDomElement Format::saveFormat( QDomDocument & doc, int _col, int _row, bool force, bool copy ) const
00242 {
00243   QDomElement format( doc.createElement( "format" ) );
00244 
00245   if ( m_pStyle->type() == Style::BUILTIN || m_pStyle->type() == Style::CUSTOM )
00246   {
00247     format.setAttribute( "style-name", ((CustomStyle *) m_pStyle)->name() );
00248 
00249     if ( !copy )
00250       return format;
00251   }
00252   else
00253   {
00254     if ( m_pStyle->parent() && m_pStyle->parent()->name().length() > 0 )
00255       format.setAttribute( "parent", m_pStyle->parent()->name() );
00256   }
00257 
00258   if ( hasProperty( PAlign, true ) || hasNoFallBackProperties( PAlign ) || force )
00259     format.setAttribute( "align", (int) align( _col, _row ) );
00260   if ( hasProperty( PAlignY, true ) || hasNoFallBackProperties( PAlignY ) || force  )
00261     format.setAttribute( "alignY", (int)alignY( _col, _row ) );
00262   if ( ( hasProperty( PBackgroundColor, false ) || hasNoFallBackProperties( PBackgroundColor)
00263          || force ) && bgColor( _col, _row ).isValid() )
00264     format.setAttribute( "bgcolor", bgColor( _col, _row ).name() );
00265   if ( ( hasProperty( PMultiRow, true ) || hasNoFallBackProperties( PMultiRow )
00266          || force ) && multiRow( _col, _row )  )
00267     format.setAttribute( "multirow", "yes" );
00268   if ( ( hasProperty( PVerticalText, true ) || hasNoFallBackProperties( PVerticalText )
00269          || force ) && verticalText( _col, _row ) )
00270     format.setAttribute( "verticaltext", "yes" );
00271   if ( hasProperty( PPrecision, true ) || hasNoFallBackProperties( PPrecision ) || force )
00272     format.setAttribute( "precision", precision( _col, _row ) );
00273   if ( ( hasProperty( PPrefix, true ) || hasNoFallBackProperties( PPrefix ) || force )
00274        && !prefix( _col, _row ).isEmpty() )
00275     format.setAttribute( "prefix", prefix( _col, _row ) );
00276   if ( ( hasProperty( PPostfix, true ) || hasNoFallBackProperties( PPostfix ) || force )
00277        && !postfix( _col, _row ).isEmpty() )
00278     format.setAttribute( "postfix", postfix( _col, _row ) );
00279   if ( hasProperty( PFloatFormat, true ) || hasNoFallBackProperties( PFloatFormat ) || force )
00280     format.setAttribute( "float", (int) floatFormat( _col, _row ) );
00281   if ( hasProperty( PFloatColor, true ) || hasNoFallBackProperties( PFloatColor ) || force )
00282     format.setAttribute( "floatcolor", (int) floatColor( _col, _row ) );
00283   if ( hasProperty( PFormatType, true ) || hasNoFallBackProperties( PFormatType ) || force )
00284     format.setAttribute( "format", (int)getFormatType( _col, _row ));
00285   if ( hasProperty( PCustomFormat, true ) || hasNoFallBackProperties( PCustomFormat ) || force )
00286   {
00287     QString s( getFormatString( _col, _row ) );
00288     if ( s.length() > 0 )
00289       format.setAttribute( "custom", s );
00290   }
00291   if ( getFormatType( _col, _row ) == Money_format )
00292   {
00293     format.setAttribute( "type", (int) m_pStyle->currency().type ); // TODO: fallback?
00294     format.setAttribute( "symbol", m_pStyle->currency().symbol );
00295   }
00296   if ( hasProperty( PAngle, true ) || hasNoFallBackProperties( PAngle ) || force )
00297     format.setAttribute( "angle", getAngle( _col, _row ) );
00298   if ( hasProperty( PIndent, true ) || hasNoFallBackProperties( PIndent ) || force )
00299     format.setAttribute( "indent", getIndent( _col, _row ) );
00300   if( ( hasProperty( PDontPrintText, true ) || hasNoFallBackProperties( PDontPrintText )
00301         || force ) && getDontprintText( _col, _row ) )
00302     format.setAttribute( "dontprinttext", "yes" );
00303   if( ( hasProperty( PNotProtected, true ) || hasNoFallBackProperties( PNotProtected )
00304         || force ) && notProtected( _col, _row ) )
00305     format.setAttribute( "noprotection", "yes" );
00306   if( ( hasProperty( PHideAll, true ) || hasNoFallBackProperties( PHideAll )
00307         || force ) && isHideAll( _col, _row ) )
00308     format.setAttribute( "hideall", "yes" );
00309   if( ( hasProperty( PHideFormula, true ) || hasNoFallBackProperties( PHideFormula )
00310         || force ) && isHideFormula( _col, _row ) )
00311     format.setAttribute( "hideformula", "yes" );
00312   if ( hasProperty( PFont, true ) || hasNoFallBackProperties( PFont ) || force )
00313     format.appendChild( util_createElement( "font", textFont( _col, _row ), doc ) );
00314   if ( ( hasProperty( PTextPen, true ) || hasNoFallBackProperties( PTextPen ) || force )
00315        && textPen( _col, _row ).color().isValid() )
00316     format.appendChild( util_createElement( "pen", textPen( _col, _row ), doc ) );
00317   if ( hasProperty( PBackgroundBrush, true ) || hasNoFallBackProperties( PBackgroundBrush ) || force )
00318   {
00319     format.setAttribute( "brushcolor", backGroundBrushColor( _col, _row ).name() );
00320     format.setAttribute( "brushstyle", (int)backGroundBrushStyle( _col, _row ) );
00321   }
00322   if ( hasProperty( PLeftBorder, true ) || hasNoFallBackProperties( PLeftBorder ) || force )
00323   {
00324     QDomElement left = doc.createElement( "left-border" );
00325     left.appendChild( util_createElement( "pen", leftBorderPen( _col, _row ), doc ) );
00326     format.appendChild( left );
00327   }
00328   if ( hasProperty( PTopBorder, true ) || hasNoFallBackProperties( PTopBorder ) || force )
00329   {
00330     QDomElement top = doc.createElement( "top-border" );
00331     top.appendChild( util_createElement( "pen", topBorderPen( _col, _row ), doc ) );
00332     format.appendChild( top );
00333   }
00334   if ( hasProperty( PRightBorder, true ) || hasNoFallBackProperties( PRightBorder ) || force )
00335   {
00336     QDomElement right = doc.createElement( "right-border" );
00337     right.appendChild( util_createElement( "pen", rightBorderPen( _col, _row ), doc ) );
00338     format.appendChild( right );
00339   }
00340   if ( hasProperty( PBottomBorder, true ) || hasNoFallBackProperties( PBottomBorder ) || force )
00341   {
00342     QDomElement bottom = doc.createElement( "bottom-border" );
00343     bottom.appendChild( util_createElement( "pen", bottomBorderPen( _col, _row ), doc ) );
00344     format.appendChild( bottom );
00345   }
00346   if ( hasProperty( PFallDiagonal, true ) || hasNoFallBackProperties( PFallDiagonal ) || force )
00347   {
00348     QDomElement fallDiagonal  = doc.createElement( "fall-diagonal" );
00349     fallDiagonal.appendChild( util_createElement( "pen", fallDiagonalPen( _col, _row ), doc ) );
00350     format.appendChild( fallDiagonal );
00351   }
00352   if ( hasProperty( PGoUpDiagonal, true ) || hasNoFallBackProperties( PGoUpDiagonal ) || force )
00353   {
00354     QDomElement goUpDiagonal = doc.createElement( "up-diagonal" );
00355     goUpDiagonal.appendChild( util_createElement( "pen", goUpDiagonalPen( _col, _row ), doc ) );
00356     format.appendChild( goUpDiagonal );
00357   }
00358   return format;
00359 }
00360 
00361 
00362 QDomElement Format::saveFormat( QDomDocument& doc, bool force, bool copy ) const
00363 {
00364   QDomElement format( doc.createElement( "format" ) );
00365 
00366   if ( m_pStyle->type() == Style::BUILTIN || m_pStyle->type() == Style::CUSTOM )
00367   {
00368     format.setAttribute( "style-name", ((CustomStyle *) m_pStyle)->name() );
00369 
00370     if ( !copy )
00371       return format;
00372   }
00373   else
00374   {
00375     if ( m_pStyle->parent() && m_pStyle->parentName().length() > 0 )
00376       format.setAttribute( "parent", m_pStyle->parentName() );
00377   }
00378 
00379   if ( hasProperty( PAlign, true ) || hasNoFallBackProperties( PAlign ) || force )
00380     format.setAttribute( "align", (int)m_pStyle->alignX() );
00381   if ( hasProperty( PAlignY, true ) || hasNoFallBackProperties( PAlignY ) || force  )
00382     format.setAttribute( "alignY", (int)m_pStyle->alignY() );
00383   if ( ( hasProperty( PBackgroundColor, true ) || hasNoFallBackProperties( PBackgroundColor )
00384          || force ) && m_pStyle->bgColor().isValid() )
00385     format.setAttribute( "bgcolor", m_pStyle->bgColor().name() );
00386 
00387   if ( ( hasProperty( PMultiRow, true ) || hasNoFallBackProperties( PMultiRow ) || force )
00388        && m_pStyle->hasProperty( Style::PMultiRow ) )
00389     format.setAttribute( "multirow", "yes" );
00390   if ( ( hasProperty( PVerticalText, true ) || hasNoFallBackProperties( PVerticalText ) || force )
00391        && m_pStyle->hasProperty( Style::PVerticalText ) )
00392     format.setAttribute( "verticaltext", "yes" );
00393 
00394   if ( hasProperty( PPrecision, true ) || hasNoFallBackProperties( PPrecision ) || force )
00395     format.setAttribute( "precision", m_pStyle->precision() );
00396   if ( ( hasProperty( PPrefix, true ) || hasNoFallBackProperties( PPrefix ) || force )
00397        && !m_pStyle->prefix().isEmpty() )
00398     format.setAttribute( "prefix", m_pStyle->prefix() );
00399   if ( ( hasProperty( PPostfix, true ) || hasNoFallBackProperties( PPostfix ) || force )
00400        && !m_pStyle->postfix().isEmpty() )
00401     format.setAttribute( "postfix", m_pStyle->postfix() );
00402 
00403   if ( hasProperty( PFloatFormat, true ) || hasNoFallBackProperties( PFloatFormat ) || force )
00404     format.setAttribute( "float", (int) m_pStyle->floatFormat() );
00405   if ( hasProperty( PFloatColor, true ) || hasNoFallBackProperties( PFloatColor ) || force )
00406     format.setAttribute( "floatcolor", (int) m_pStyle->floatColor() );
00407   if ( hasProperty( PFormatType, true ) || hasNoFallBackProperties( PFormatType ) || force )
00408     format.setAttribute( "format", (int) m_pStyle->formatType() );
00409   if ( hasProperty( PCustomFormat, true ) || hasNoFallBackProperties( PCustomFormat ) || force )
00410     if ( m_pStyle->strFormat().length() > 0 )
00411       format.setAttribute( "custom", m_pStyle->strFormat() );
00412   if ( m_pStyle->formatType() == Money_format )
00413   {
00414     format.setAttribute( "type", (int) m_pStyle->currency().type );
00415     format.setAttribute( "symbol", m_pStyle->currency().symbol );
00416   }
00417   if ( hasProperty( PAngle, true ) || hasNoFallBackProperties( PAngle ) || force )
00418     format.setAttribute( "angle", m_pStyle->rotateAngle() );
00419   if ( hasProperty( PIndent, true ) || hasNoFallBackProperties( PIndent ) || force )
00420     format.setAttribute( "indent", m_pStyle->indent() );
00421   if ( ( hasProperty( PDontPrintText, true ) || hasNoFallBackProperties( PDontPrintText ) || force )
00422       && m_pStyle->hasProperty( Style::PDontPrintText ) )
00423     format.setAttribute( "dontprinttext", "yes" );
00424   if ( ( hasProperty( PNotProtected, true ) || hasNoFallBackProperties( PNotProtected )
00425          || force ) && m_pStyle->hasProperty( Style::PNotProtected ) )
00426     format.setAttribute( "noprotection", "yes" );
00427   if( ( hasProperty( PHideAll, true ) || hasNoFallBackProperties( PHideAll )
00428         || force ) && m_pStyle->hasProperty( Style::PHideAll ) )
00429     format.setAttribute( "hideall", "yes" );
00430   if( ( hasProperty( PHideFormula, true ) || hasNoFallBackProperties( PHideFormula )
00431         || force ) && m_pStyle->hasProperty( Style::PHideFormula ) )
00432     format.setAttribute( "hideformula", "yes" );
00433   if ( hasProperty( PFont, true ) || hasNoFallBackProperties( PFont ) || force )
00434     format.appendChild( util_createElement( "font", m_pStyle->font(), doc ) );
00435   if ( ( hasProperty( PTextPen, true ) || hasNoFallBackProperties( PTextPen ) || force )
00436        && m_pStyle->pen().color().isValid() )
00437     format.appendChild( util_createElement( "pen", m_pStyle->pen(), doc ) );
00438   if ( hasProperty( PBackgroundBrush, true ) || hasNoFallBackProperties( PBackgroundBrush ) || force )
00439   {
00440     format.setAttribute( "brushcolor", m_pStyle->backGroundBrush().color().name() );
00441     format.setAttribute( "brushstyle", (int) m_pStyle->backGroundBrush().style() );
00442   }
00443   if ( hasProperty( PLeftBorder, true ) || hasNoFallBackProperties( PLeftBorder ) || force )
00444   {
00445     QDomElement left = doc.createElement( "left-border" );
00446     left.appendChild( util_createElement( "pen", m_pStyle->leftBorderPen(), doc ) );
00447     format.appendChild( left );
00448   }
00449   if ( hasProperty( PTopBorder, true ) || hasNoFallBackProperties( PTopBorder ) || force )
00450   {
00451     QDomElement top = doc.createElement( "top-border" );
00452     top.appendChild( util_createElement( "pen", m_pStyle->topBorderPen(), doc ) );
00453     format.appendChild( top );
00454   }
00455   if ( hasProperty( PRightBorder, true ) || hasNoFallBackProperties( PRightBorder ) || force )
00456   {
00457     QDomElement right = doc.createElement( "right-border" );
00458     right.appendChild( util_createElement( "pen", m_pStyle->rightBorderPen(), doc ) );
00459     format.appendChild( right );
00460   }
00461   if ( hasProperty( PBottomBorder, true ) || hasNoFallBackProperties( PBottomBorder ) || force )
00462   {
00463     QDomElement bottom = doc.createElement( "bottom-border" );
00464     bottom.appendChild( util_createElement( "pen", m_pStyle->bottomBorderPen(), doc ) );
00465     format.appendChild( bottom );
00466   }
00467   if ( hasProperty( PFallDiagonal, true ) || hasNoFallBackProperties( PFallDiagonal ) || force )
00468   {
00469     QDomElement fallDiagonal  = doc.createElement( "fall-diagonal" );
00470     fallDiagonal.appendChild( util_createElement( "pen", m_pStyle->fallDiagonalPen(), doc ) );
00471     format.appendChild( fallDiagonal );
00472   }
00473   if ( hasProperty( PGoUpDiagonal, true ) || hasNoFallBackProperties( PGoUpDiagonal ) || force )
00474   {
00475     QDomElement goUpDiagonal = doc.createElement( "up-diagonal" );
00476     goUpDiagonal.appendChild( util_createElement( "pen", m_pStyle->goUpDiagonalPen(), doc ) );
00477     format.appendChild( goUpDiagonal );
00478   }
00479   return format;
00480 }
00481 
00482 QDomElement Format::save( QDomDocument & doc, int _col, int _row, bool force, bool copy ) const
00483 {
00484   QDomElement format = saveFormat( doc, _col, _row, force, copy );
00485   return format;
00486 }
00487 
00488 bool Format::loadFormat( const QDomElement & f, Paste::Mode pm, bool paste )
00489 {
00490     if ( f.hasAttribute( "style-name" ) )
00491     {
00492       Style * s = m_pSheet->doc()->styleManager()->style( f.attribute( "style-name" ) );
00493 
00494       //kdDebug() << "Using style: " << f.attribute( "style-name" ) << ", s: " << s << endl;
00495       if ( s )
00496       {
00497         setStyle( s );
00498 
00499         return true;
00500       }
00501       else if ( !paste )
00502         return false;
00503     }
00504     else
00505     if ( f.hasAttribute( "parent" ) )
00506     {
00507       CustomStyle* s = static_cast<CustomStyle*>( m_pSheet->doc()->styleManager()->style( f.attribute( "parent" ) ) );
00508       //kdDebug() << "Loading Style, parent: " << s->name() << ": " << s << endl;
00509 
00510       if ( s )
00511       {
00512         if ( m_pStyle && m_pStyle->release() )
00513           delete m_pStyle;
00514 
00515         m_pStyle = new Style();
00516         m_pStyle->setParent( s );
00517       }
00518     }
00519 
00520     bool ok;
00521     if ( f.hasAttribute( "align" ) )
00522     {
00523         Align a = (Align) f.attribute( "align" ).toInt( &ok );
00524         if ( !ok )
00525             return false;
00526         // Validation
00527         if ( (unsigned int) a >= 1 || (unsigned int) a <= 4 )
00528         {
00529             setAlign( a );
00530         }
00531     }
00532     if ( f.hasAttribute( "alignY" ) )
00533     {
00534         AlignY a = (AlignY) f.attribute( "alignY" ).toInt( &ok );
00535         if ( !ok )
00536             return false;
00537         // Validation
00538         if ( (unsigned int) a >= 1 || (unsigned int) a <= 4 )
00539         {
00540             setAlignY( a );
00541         }
00542     }
00543 
00544     if ( f.hasAttribute( "bgcolor" ) ) {
00545     QColor  col( f.attribute( "bgcolor" ) );
00546     if ( col != Qt::white )
00547         setBgColor( col );
00548     }
00549 
00550     if ( f.hasAttribute( "multirow" ) )
00551         setMultiRow( true );
00552 
00553     if ( f.hasAttribute( "verticaltext" ) )
00554         setVerticalText( true );
00555 
00556     if ( f.hasAttribute( "precision" ) )
00557     {
00558         int i = f.attribute( "precision" ).toInt( &ok );
00559         if ( i < -1 )
00560         {
00561             kdDebug(36001) << "Value out of range Cell::precision=" << i << endl;
00562             return false;
00563         }
00564         // Assignment
00565         setPrecision( i );
00566     }
00567 
00568     if ( f.hasAttribute( "float" ) )
00569     {
00570         FloatFormat a = (FloatFormat) f.attribute( "float" ).toInt( &ok );
00571         if ( !ok ) return false;
00572         if ( (unsigned int) a >= 1 && (unsigned int) a <= 3 )
00573         {
00574             setFloatFormat( a );
00575         }
00576     }
00577 
00578     if ( f.hasAttribute( "floatcolor" ) )
00579     {
00580         FloatColor a = (FloatColor) f.attribute( "floatcolor" ).toInt( &ok );
00581         if ( !ok ) return false;
00582         if ( (unsigned int) a >= 1 && (unsigned int) a <= 4 )
00583         {
00584             setFloatColor( a );
00585         }
00586     }
00587 
00588     if ( f.hasAttribute( "format" ) )
00589     {
00590         int fo = f.attribute( "format" ).toInt( &ok );
00591         if ( ! ok )
00592           return false;
00593         setFormatType( ( FormatType ) fo );
00594     }
00595     if ( f.hasAttribute( "custom" ) )
00596     {
00597         setFormatString( f.attribute( "custom" ) );
00598     }
00599     if ( m_pStyle->formatType() == Money_format )
00600     {
00601       Currency c;
00602       c.type = -1;
00603       if ( f.hasAttribute( "type" ) )
00604       {
00605         c.type   = f.attribute( "type" ).toInt( &ok );
00606         if ( !ok )
00607           c.type = 1;
00608       }
00609       if ( f.hasAttribute( "symbol" ) )
00610       {
00611         c.symbol = f.attribute( "symbol" );
00612       }
00613       if ( c.type != -1 )
00614         setCurrency( c );
00615     }
00616     if ( f.hasAttribute( "angle" ) )
00617     {
00618         setAngle( f.attribute( "angle" ).toInt( &ok ) );
00619         if ( !ok )
00620             return false;
00621     }
00622     if ( f.hasAttribute( "indent" ) )
00623     {
00624         setIndent( f.attribute( "indent" ).toDouble( &ok ) );
00625         if ( !ok )
00626             return false;
00627     }
00628     if ( f.hasAttribute( "dontprinttext" ) )
00629         setDontPrintText( true );
00630 
00631     if ( f.hasAttribute( "noprotection" ) )
00632         setNotProtected( true );
00633 
00634     if ( f.hasAttribute( "hideall" ) )
00635         setHideAll( true );
00636 
00637     if ( f.hasAttribute( "hideformula" ) )
00638         setHideFormula( true );
00639 
00640     if ( f.hasAttribute( "brushstyle" ) )
00641     {
00642         setBackGroundBrushStyle( (Qt::BrushStyle) f.attribute( "brushstyle" ).toInt( &ok ) );
00643         if ( !ok )
00644           return false;
00645     }
00646 
00647     if ( f.hasAttribute( "brushcolor" ) )
00648         setBackGroundBrushColor( QColor( f.attribute( "brushcolor" ) ) );
00649 
00650     QDomElement pen( f.namedItem( "pen" ).toElement() );
00651     if ( !pen.isNull() )
00652         setTextPen( util_toPen( pen ) );
00653 
00654     QDomElement font( f.namedItem( "font" ).toElement() );
00655     if ( !font.isNull() )
00656         setTextFont( util_toFont( font ) );
00657 
00658     if ( ( pm != Paste::NoBorder ) && ( pm != Paste::Text ) && ( pm != Paste::Comment ) )
00659     {
00660         QDomElement left( f.namedItem( "left-border" ).toElement() );
00661         if ( !left.isNull() )
00662         {
00663             QDomElement pen( left.namedItem( "pen" ).toElement() );
00664             if ( !pen.isNull() )
00665                 setLeftBorderPen( util_toPen( pen ) );
00666         }
00667 
00668         QDomElement top( f.namedItem( "top-border" ).toElement() );
00669         if ( !top.isNull() )
00670         {
00671             QDomElement pen( top.namedItem( "pen" ).toElement() );
00672             if ( !pen.isNull() )
00673                 setTopBorderPen( util_toPen( pen ) );
00674         }
00675 
00676         QDomElement right( f.namedItem( "right-border" ).toElement() );
00677         if ( !right.isNull() )
00678         {
00679             QDomElement pen( right.namedItem( "pen" ).toElement() );
00680             if ( !pen.isNull() )
00681                 setRightBorderPen( util_toPen( pen ) );
00682         }
00683 
00684         QDomElement bottom( f.namedItem( "bottom-border" ).toElement() );
00685         if ( !bottom.isNull() )
00686         {
00687             QDomElement pen( bottom.namedItem( "pen" ).toElement() );
00688             if ( !pen.isNull() )
00689                 setBottomBorderPen( util_toPen( pen ) );
00690         }
00691 
00692         QDomElement fallDiagonal( f.namedItem( "fall-diagonal" ).toElement() );
00693         if ( !fallDiagonal.isNull() )
00694         {
00695             QDomElement pen( fallDiagonal.namedItem( "pen" ).toElement() );
00696             if ( !pen.isNull() )
00697                 setFallDiagonalPen( util_toPen( pen ) );
00698         }
00699 
00700         QDomElement goUpDiagonal( f.namedItem( "up-diagonal" ).toElement() );
00701         if ( !goUpDiagonal.isNull() )
00702         {
00703             QDomElement pen( goUpDiagonal.namedItem( "pen" ).toElement() );
00704             if ( !pen.isNull() )
00705                 setGoUpDiagonalPen( util_toPen( pen ) );
00706         }
00707     }
00708 
00709     if ( f.hasAttribute( "prefix" ) )
00710         setPrefix( f.attribute( "prefix" ) );
00711     if ( f.hasAttribute( "postfix" ) )
00712         setPostfix( f.attribute( "postfix" ) );
00713 
00714     return true;
00715 }
00716 
00717 bool Format::load( const QDomElement & f, Paste::Mode pm, bool paste )
00718 {
00719     if ( !loadFormat( f, pm, paste ) )
00720         return false;
00721     return true;
00722 }
00723 
00724 
00725 bool Format::loadFontOasisStyle( KoStyleStack & font )
00726 {
00727     font.setTypeProperties( "text" ); // load all style attributes from "style:text-properties"
00728     //TODO remember to change type properties
00729 
00730     if ( font.hasAttributeNS( KoXmlNS::fo, "font-family" ) )
00731         setTextFontFamily( font.attributeNS( KoXmlNS::fo, "font-family" ) );
00732 
00733     if ( font.hasAttributeNS( KoXmlNS::fo, "color" ) )
00734         setTextColor( QColor( font.attributeNS( KoXmlNS::fo, "color" ) ) );
00735 
00736     if ( font.hasAttributeNS( KoXmlNS::fo, "font-size" ) )
00737         setTextFontSize( (int) KoUnit::parseValue( font.attributeNS( KoXmlNS::fo, "font-size" ), 10.0 ) );
00738 
00739     if ( font.hasAttributeNS( KoXmlNS::fo, "font-style" ) && ( font.attributeNS( KoXmlNS::fo,"font-style" )== "italic" ))
00740     {
00741         kdDebug(30518) << "italic" << endl;
00742         setTextFontItalic( true ); // only thing we support
00743     }
00744     if ( font.hasAttributeNS( KoXmlNS::fo, "font-weight" )
00745          && ( font.attributeNS( KoXmlNS::fo, "font-weight" ) == "bold") )
00746         setTextFontBold( true ); // only thing we support
00747 
00748     //TODO add "style:text-underline-width" "style:text-underline-color"
00749     if ( ( font.hasAttributeNS( KoXmlNS::fo, "text-underline-style" ) && font.attributeNS( KoXmlNS::fo, "text-underline-style" ) != "none" )
00750          || ( font.hasAttributeNS( KoXmlNS::style, "text-underline-style" ) && font.attributeNS( KoXmlNS::style, "text-underline-style" )!="none" ) )
00751         setTextFontUnderline( true ); // only thing we support
00752 
00753     if ( font.hasAttributeNS( KoXmlNS::style, "text-line-through-style" )
00754          && font.attributeNS( KoXmlNS::style, "text-line-through-style" ) != "none"
00755          /*&& ( font.attributeNS( KoXmlNS::style, "text-crossing-out" ) == "single-line" )*/)
00756         setTextFontStrike( true ); // only thing we support
00757 
00758     if ( font.hasAttributeNS( KoXmlNS::style, "font-pitch" ) )
00759     {
00760         // TODO: possible values: fixed, variable
00761     }
00762 
00763     // TODO: for the future when we will use kotext
00764     // text-underline-color
00765     return true;
00766 }
00767 
00768 void Format::loadOasisStyle( /*const QDomElement& style,*/ KoOasisLoadingContext& context )
00769 {
00770   QString str; // multi purpose string
00771   KoOasisStyles& oasisStyles = context.oasisStyles();
00772 
00773 /*  context.styleStack().save();
00774   context.addStyles( &style );*/
00775 /*  KoStyleStack styleStack;
00776   styleStack.push( style );
00777   styleStack.setTypeProperties( "table-cell" );*/
00778 
00779   KoStyleStack& styleStack = context.styleStack();
00780   loadOasisStyleProperties( styleStack, context.oasisStyles() );
00781 /*  loadOasisStyleProperties( context.styleStack(), context.oasisStyles() );
00782   context.styleStack().restore();*/
00783 
00784   kdDebug() << "*** Loading style attributes *****" << endl;
00785 
00786   if ( styleStack.hasAttributeNS( KoXmlNS::style, "data-style-name" ) )
00787   {
00788     str = styleStack.attributeNS( KoXmlNS::style, "data-style-name" );
00789     kdDebug() << " style:data-style-name: " <<  str << endl << endl;
00790 
00791     if ( !str.isEmpty() )
00792     {
00793       QString tmp = oasisStyles.dataFormats()[str].prefix;
00794       if ( !tmp.isEmpty() )
00795       {
00796         setPrefix( tmp );
00797       }
00798       tmp = oasisStyles.dataFormats()[str].suffix;
00799       if ( !tmp.isEmpty() )
00800       {
00801         setPostfix( tmp );
00802       }
00803       tmp = oasisStyles.dataFormats()[str].formatStr;
00804       if ( !tmp.isEmpty() )
00805       {
00806         setFormatType( Style::formatType( tmp ) );
00807       }
00808     }
00809   }
00810 
00811   if ( styleStack.hasAttributeNS( KoXmlNS::style, "decimal-places" ) )
00812   {
00813     bool ok = false;
00814     int p = styleStack.attributeNS( KoXmlNS::style, "decimal-places" ).toInt( &ok );
00815     kdDebug() << " style:decimal-places: " << p << endl;
00816     if (ok )
00817       setPrecision( p );
00818   }
00819 }
00820 
00821 bool Format::loadOasisStyleProperties( KoStyleStack & styleStack, const KoOasisStyles& oasisStyles )
00822 {
00823     kdDebug() << "*** Loading style properties *****" << endl;
00824 #if 0
00825     if ( f.hasAttribute( "style-name" ) )
00826     {
00827         Style * s = m_pSheet->doc()->styleManager()->style( f.attribute( "style-name" ) );
00828 
00829         //kdDebug() << "Using style: " << f.attribute( "style-name" ) << ", s: " << s << endl;
00830         if ( s )
00831         {
00832             setStyle( s );
00833 
00834             return true;
00835         }
00836         else if ( !paste )
00837             return false;
00838     }
00839     else
00840         if ( f.hasAttribute( "parent" ) )
00841         {
00842             CustomStyle * s = (CustomStyle *) m_pSheet->doc()->styleManager()->style( f.attribute( "parent" ) );
00843             //kdDebug() << "Loading Style, parent: " << s->name() << ": " << s << endl;
00844 
00845             if ( s )
00846             {
00847                 if ( m_pStyle && m_pStyle->release() )
00848                     delete m_pStyle;
00849 
00850                 m_pStyle = new Style();
00851                 m_pStyle->setParent( s );
00852             }
00853         }
00854 #endif
00855     if ( styleStack.hasAttributeNS( KoXmlNS::style, "parent-style-name" ) )
00856     {
00857         Style * s = m_pSheet->doc()->styleManager()->style( styleStack.attributeNS( KoXmlNS::style, "parent-style-name" ) );
00858 
00859         //kdDebug() << "Using style: " << f.attribute( "style-name" ) << ", s: " << s << endl;
00860         if ( s )
00861         {
00862             setStyle( s );
00863         }
00864     }
00865     else
00866     {
00867       setStyle( m_pSheet->doc()->styleManager()->defaultStyle() );
00868     }
00869 
00870 
00871     if ( styleStack.hasAttributeNS( KoXmlNS::style, "font-name" ) )
00872     {
00873         const QDomElement * font = oasisStyles.findStyle( styleStack.attributeNS( KoXmlNS::style, "font-name" ) );
00874         if ( font )
00875         {
00876             styleStack.save();
00877             styleStack.push( *font );
00878             loadFontOasisStyle( styleStack ); // general font style
00879             styleStack.restore();
00880         }
00881     }
00882 
00883     kdDebug() << " [text properties]" << endl;
00884     //Text properties
00885     loadFontOasisStyle( styleStack ); // specific font style
00886     //End Text properties
00887 
00888     kdDebug() << " [paragraph properties]" << endl;
00889     //Paragraph properties
00890     styleStack.setTypeProperties( "paragraph" ); // load all style attributes from "style:paragraph-properties"
00891     if (  styleStack.hasAttributeNS( KoXmlNS::fo, "margin-left" ) )
00892     {
00893         kdDebug()<<"  margin-left:"<<KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::fo, "margin-left" ),0.0 )<<endl;
00894         setIndent( KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::fo, "margin-left" ),0.0 ) );
00895     }
00896     //kdDebug()<<"property.hasAttribute( fo:text-align ) :"<<styleStack.hasAttributeNS( KoXmlNS::fo, "text-align" )<<endl;
00897     if ( styleStack.hasAttributeNS( KoXmlNS::fo, "text-align" ) )
00898     {
00899         QString s = styleStack.attributeNS( KoXmlNS::fo, "text-align" );
00900         if ( s == "center" )
00901             setAlign( Format::Center );
00902         else if ( s == "end" )
00903             setAlign( Format::Right );
00904         else if ( s == "start" )
00905             setAlign( Format::Left );
00906         else if ( s == "justify" ) // TODO in KSpread!
00907             setAlign( Format::Center );
00908     }
00909     //end paragraph properties
00910 
00911     kdDebug() << " [cell properties]" << endl;
00912     styleStack.setTypeProperties( "table-cell" ); // Default
00913 
00914     // TODO:
00915     //   diagonal: fall + goup
00916     //   fo:direction="ltr"
00917     //   style:text-align-source  ("fix")
00918     //   style:shadow
00919     //   style:text-outline
00920     //   indents from right, top, bottom
00921     //   style:condition="cell-content()=15"
00922     //     => style:apply-style-name="Result" style:base-cell-address="Sheet6.A5"/>
00923 
00924     if ( styleStack.hasAttributeNS( KoXmlNS::style, "rotation-angle" ) )
00925     {
00926         bool ok = false;
00927         int a = styleStack.attributeNS( KoXmlNS::style, "rotation-angle" ).toInt( &ok );
00928         if ( ok && ( a != 0 ))
00929             setAngle( -a );
00930     }
00931     if ( styleStack.hasAttributeNS( KoXmlNS::style, "direction" ) )
00932     {
00933         QString dir = styleStack.attributeNS( KoXmlNS::fo, "direction" );
00934         if ( dir == "ttb" )
00935             setVerticalText( true );
00936         else if ( dir == "ltr" )
00937             setVerticalText( false );
00938     }
00939 
00940     kdDebug()<<"property.hasAttribute( fo:background-color ) :"<<styleStack.hasAttributeNS( KoXmlNS::fo, "background-color" )<<endl;
00941 
00942     if ( styleStack.hasAttributeNS( KoXmlNS::fo, "background-color" ) )
00943         setBgColor( QColor( styleStack.attributeNS( KoXmlNS::fo, "background-color" ) ) );
00944 
00945     if ( styleStack.hasAttributeNS( KoXmlNS::style, "print-content" ) )
00946     {
00947         if ( styleStack.attributeNS( KoXmlNS::style, "print-content" ) == "false" )
00948             setDontPrintText( false );
00949     }
00950     if ( styleStack.hasAttributeNS( KoXmlNS::style, "cell-protect" ) )
00951     {
00952         QString prot( styleStack.attributeNS( KoXmlNS::style, "cell-protect" ) );
00953         if ( prot == "none" )
00954         {
00955             setNotProtected( true );
00956             setHideFormula( false );
00957             setHideAll( false );
00958         }
00959         else if ( prot == "formula-hidden" )
00960         {
00961             setNotProtected( true );
00962             setHideFormula( true );
00963             setHideAll( false );
00964         }
00965         else if ( prot == "protected formula-hidden" )
00966         {
00967             setNotProtected( false );
00968             setHideFormula( true );
00969             setHideAll( false );
00970         }
00971         else if ( prot == "hidden-and-protected" )
00972         {
00973             setNotProtected( false );
00974             setHideFormula( false );
00975             setHideAll( true );
00976         }
00977         else if ( prot == "protected" )
00978         {
00979             setNotProtected( false );
00980             setHideFormula( false );
00981             setHideAll( false );
00982         }
00983         else
00984             kdDebug()<<" Protected cell not supported :"<<prot<<endl;
00985         kdDebug() << "  cell-protect: " << prot << endl;
00986     }
00987 
00988     if ( styleStack.hasAttributeNS( KoXmlNS::fo, "padding-left" ) )
00989         setIndent(  KoUnit::parseValue( styleStack.attributeNS( KoXmlNS::fo, "padding-left" ) ) );
00990 
00991     if ( styleStack.hasAttributeNS( KoXmlNS::style, "vertical-align" ) )
00992     {
00993         QString s = styleStack.attributeNS( KoXmlNS::style, "vertical-align" );
00994         if ( s == "middle" )
00995             setAlignY( Format::Middle );
00996         else if ( s == "bottom" )
00997             setAlignY( Format::Bottom );
00998         else if ( s == "top" )
00999             setAlignY( Format::Top );
01000     }
01001 
01002     if ( styleStack.hasAttributeNS( KoXmlNS::fo, "wrap-option" ) )
01003     {
01004         // we do not support anything else yet
01005        QString wrapOpt = styleStack.attributeNS( KoXmlNS::fo, "wrap-option" );
01006         if ( wrapOpt == "wrap" )
01007             setMultiRow( true );
01008         else if ( wrapOpt == "no-wrap" )
01009             setMultiRow( false );
01010     }
01011     if ( styleStack.hasAttributeNS( KoXmlNS::fo, "border-bottom" ) )
01012     {
01013         setBottomBorderPen( convertOasisStringToPen( styleStack.attributeNS( KoXmlNS::fo, "border-bottom" ) ) );
01014         // TODO: style:border-line-width-bottom if double!
01015     }
01016 
01017     if ( styleStack.hasAttributeNS( KoXmlNS::fo, "border-right" ) )
01018     {
01019         setRightBorderPen( convertOasisStringToPen(  styleStack.attributeNS( KoXmlNS::fo, "border-right" ) ) );
01020         // TODO: style:border-line-width-right
01021     }
01022 
01023     if ( styleStack.hasAttributeNS( KoXmlNS::fo, "border-top" ) )
01024     {
01025         setTopBorderPen( convertOasisStringToPen(  styleStack.attributeNS( KoXmlNS::fo, "border-top" ) ) );
01026         // TODO: style:border-line-width-top
01027     }
01028 
01029     if ( styleStack.hasAttributeNS( KoXmlNS::fo, "border-left" ) )
01030     {
01031         setLeftBorderPen( convertOasisStringToPen( styleStack.attributeNS( KoXmlNS::fo, "border-left" ) ) );
01032         // TODO: style:border-line-width-left
01033     }
01034 
01035     if ( styleStack.hasAttributeNS( KoXmlNS::fo, "border" ) )
01036     {
01037         QPen pen = convertOasisStringToPen( styleStack.attributeNS( KoXmlNS::fo, "border" ) );
01038         setLeftBorderPen( pen );
01039         setRightBorderPen( pen );
01040         setTopBorderPen( pen );
01041         setBottomBorderPen( pen );
01042 
01043         // TODO: style:border-line-width-left
01044     }
01045     if ( styleStack.hasAttributeNS( KoXmlNS::style, "diagonal-tl-br" ) )
01046     {
01047         setFallDiagonalPen( convertOasisStringToPen( styleStack.attributeNS( KoXmlNS::style, "diagonal-tl-br" ) ) );
01048     }
01049     if ( styleStack.hasAttributeNS( KoXmlNS::style, "diagonal-bl-tr" ) )
01050     {
01051         setGoUpDiagonalPen( convertOasisStringToPen( styleStack.attributeNS( KoXmlNS::style, "diagonal-bl-tr" ) ) );
01052     }
01053 
01054     if ( styleStack.hasAttributeNS( KoXmlNS::draw, "style-name" ) )
01055     {
01056         //kdDebug()<<" style name :"<<styleStack.attributeNS( KoXmlNS::draw, "style-name" )<<endl;
01057 
01058       const QDomElement * style = oasisStyles.findStyle( styleStack.attributeNS( KoXmlNS::draw, "style-name" ), "graphic" );
01059       if ( style )
01060       {
01061         //kdDebug()<<" style :"<<style<<endl;
01062         KoStyleStack drawStyleStack;
01063         drawStyleStack.push( *style );
01064         drawStyleStack.setTypeProperties( "graphic" );
01065         if ( drawStyleStack.hasAttributeNS( KoXmlNS::draw, "fill" ) )
01066         {
01067             const QString fill = drawStyleStack.attributeNS( KoXmlNS::draw, "fill" );
01068             kdDebug()<<" load object gradient fill type :"<<fill<<endl;
01069 
01070             if ( fill == "solid" || fill == "hatch" )
01071             {
01072                 QBrush brush=KoOasisStyles::loadOasisFillStyle( drawStyleStack, fill, oasisStyles );
01073                 setBackGroundBrushStyle( brush.style() );
01074                 setBackGroundBrushColor( brush.color() );
01075             }
01076             else
01077                 kdDebug()<<" fill style not supported by kspread : "<<fill<<endl;
01078         }
01079       }
01080     }
01081 
01082     return true;
01083 }
01084 
01085 
01087 //
01088 // Set methods
01089 //
01091 
01092 void Format::setFormatString( QString const & format )
01093 {
01094   if ( format.isEmpty() )
01095   {
01096     clearProperty( PCustomFormat );
01097     setNoFallBackProperties( PCustomFormat );
01098   }
01099   else
01100   {
01101     setProperty( PCustomFormat );
01102     clearNoFallBackProperties( PCustomFormat );
01103 
01104     // now have a custom format...
01105     clearProperty( PPrefix  );
01106     clearProperty( PPostfix  );
01107     clearProperty( PPrecision );
01108     clearProperty( PFloatColor );
01109     clearProperty( PFloatFormat );
01110 
01111     setNoFallBackProperties( PPrecision );
01112     setNoFallBackProperties( PPrefix  );
01113     setNoFallBackProperties( PPostfix );
01114   }
01115 
01116   m_pStyle = m_pStyle->setStrFormat( format );
01117   formatChanged();
01118 }
01119 
01120 void Format::setAlign( Align _align )
01121 {
01122   if ( _align == Format::Undefined )
01123   {
01124     clearProperty( PAlign );
01125     setNoFallBackProperties(PAlign );
01126   }
01127   else
01128   {
01129     setProperty( PAlign );
01130     clearNoFallBackProperties(PAlign );
01131   }
01132 
01133   m_pStyle = m_pStyle->setAlignX( _align );
01134   formatChanged();
01135 }
01136 
01137 void Format::setAlignY( AlignY _alignY)
01138 {
01139     //kdDebug() << "Format: AlignY: " << _alignY << endl;
01140   if ( _alignY == Format::Middle )
01141   {
01142       //kdDebug() << "Middle" << endl;
01143     clearProperty( PAlignY );
01144     setNoFallBackProperties(PAlignY );
01145   }
01146   else
01147   {
01148       //kdDebug() << "Not middle: " << _alignY << endl;
01149     setProperty( PAlignY );
01150     clearNoFallBackProperties( PAlignY );
01151   }
01152 
01153   m_pStyle = m_pStyle->setAlignY( _alignY );
01154   formatChanged();
01155 }
01156 
01157 void Format::setPrefix( const QString& _prefix )
01158 {
01159   if ( _prefix.isEmpty() )
01160   {
01161     clearProperty( PPrefix );
01162     setNoFallBackProperties( PPrefix );
01163   }
01164   else
01165   {
01166     setProperty( PPrefix );
01167     clearNoFallBackProperties( PPrefix );
01168   }
01169 
01170   m_pStyle = m_pStyle->setPrefix( _prefix );
01171   formatChanged();
01172 }
01173 
01174 void Format::setPostfix( const QString& _postfix )
01175 {
01176   if ( _postfix.isEmpty() )
01177   {
01178     clearProperty( PPostfix );
01179     setNoFallBackProperties( PPostfix );
01180   }
01181   else
01182   {
01183     setProperty( PPostfix );
01184     clearNoFallBackProperties( PPostfix );
01185   }
01186 
01187   m_pStyle = m_pStyle->setPostfix( _postfix );
01188   formatChanged();
01189 }
01190 
01191 void Format::setPrecision( int _p )
01192 {
01193   if ( _p == -1 )
01194   {
01195     clearProperty( PPrecision );
01196     setNoFallBackProperties( PPrecision );
01197   }
01198   else
01199   {
01200     setProperty( PPrecision );
01201     clearNoFallBackProperties( PPrecision );
01202   }
01203 
01204   m_pStyle = m_pStyle->setPrecision( _p );
01205   formatChanged();
01206 }
01207 
01208 void Format::setLeftBorderPen( const QPen & _p )
01209 {
01210   if ( _p.style() == Qt::NoPen )
01211   {
01212     clearProperty( PLeftBorder );
01213     setNoFallBackProperties( PLeftBorder );
01214   }
01215   else
01216   {
01217     setProperty( PLeftBorder );
01218     clearNoFallBackProperties( PLeftBorder );
01219   }
01220 
01221   m_pStyle = m_pStyle->setLeftBorderPen( _p );
01222   formatChanged();
01223 }
01224 
01225 void Format::setLeftBorderStyle( Qt::PenStyle s )
01226 {
01227   QPen p( m_pStyle->leftBorderPen() );
01228   p.setStyle( s );
01229   setLeftBorderPen( p );
01230 }
01231 
01232 void Format::setLeftBorderColor( const QColor & c )
01233 {
01234   QPen p( m_pStyle->leftBorderPen() );
01235   p.setColor( c );
01236   setLeftBorderPen( p );
01237 }
01238 
01239 void Format::setLeftBorderWidth( int _w )
01240 {
01241   QPen p( m_pStyle->leftBorderPen() );
01242   p.setWidth( _w );
01243   setLeftBorderPen( p );
01244 }
01245 
01246 void Format::setTopBorderPen( const QPen & _p )
01247 {
01248   if ( _p.style() == Qt::NoPen )
01249   {
01250     clearProperty( PTopBorder );
01251     setNoFallBackProperties( PTopBorder );
01252   }
01253   else
01254   {
01255     setProperty( PTopBorder );
01256     clearNoFallBackProperties( PTopBorder );
01257   }
01258 
01259   m_pStyle = m_pStyle->setTopBorderPen( _p );
01260   formatChanged();
01261 }
01262 
01263 void Format::setTopBorderStyle( Qt::PenStyle s )
01264 {
01265   QPen p( m_pStyle->topBorderPen() );
01266   p.setStyle( s );
01267   setTopBorderPen( p );
01268 }
01269 
01270 void Format::setTopBorderColor( const QColor& c )
01271 {
01272   QPen p( m_pStyle->topBorderPen() );
01273   p.setColor( c );
01274   setTopBorderPen( p );
01275 }
01276 
01277 void Format::setTopBorderWidth( int _w )
01278 {
01279   QPen p( m_pStyle->topBorderPen() );
01280   p.setWidth( _w );
01281   setTopBorderPen( p );
01282 }
01283 
01284 void Format::setRightBorderPen( const QPen& p )
01285 {
01286   if ( p.style() == Qt::NoPen )
01287   {
01288     clearProperty( PRightBorder );
01289     setNoFallBackProperties( PRightBorder );
01290   }
01291   else
01292   {
01293     setProperty( PRightBorder );
01294     clearNoFallBackProperties( PRightBorder );
01295   }
01296 
01297   m_pStyle = m_pStyle->setRightBorderPen( p );
01298   formatChanged();
01299 }
01300 
01301 void Format::setRightBorderStyle( Qt::PenStyle _s )
01302 {
01303   QPen p( m_pStyle->rightBorderPen() );
01304   p.setStyle( _s );
01305   setRightBorderPen( p );
01306 }
01307 
01308 void Format::setRightBorderColor( const QColor & _c )
01309 {
01310   QPen p( m_pStyle->rightBorderPen() );
01311   p.setColor( _c );
01312   setRightBorderPen( p );
01313 }
01314 
01315 void Format::setRightBorderWidth( int _w )
01316 {
01317   QPen p( m_pStyle->rightBorderPen() );
01318   p.setWidth( _w );
01319   setRightBorderPen( p );
01320 }
01321 
01322 void Format::setBottomBorderPen( const QPen& p )
01323 {
01324   if ( p.style() == Qt::NoPen )
01325   {
01326     clearProperty( PBottomBorder );
01327     setNoFallBackProperties( PBottomBorder );
01328   }
01329   else
01330   {
01331     setProperty( PBottomBorder );
01332     clearNoFallBackProperties( PBottomBorder );
01333   }
01334 
01335   m_pStyle = m_pStyle->setBottomBorderPen( p );
01336   formatChanged();
01337 }
01338 
01339 void Format::setBottomBorderStyle( Qt::PenStyle _s )
01340 {
01341   QPen p( m_pStyle->bottomBorderPen() );
01342   p.setStyle( _s );
01343   setBottomBorderPen( p );
01344 }
01345 
01346 void Format::setBottomBorderColor( const QColor & _c )
01347 {
01348   QPen p( m_pStyle->bottomBorderPen() );
01349   p.setColor( _c );
01350   setBottomBorderPen( p );
01351 }
01352 
01353 void Format::setBottomBorderWidth( int _w )
01354 {
01355   QPen p( m_pStyle->bottomBorderPen() );
01356   p.setWidth( _w );
01357   setBottomBorderPen( p );
01358 }
01359 
01360 void Format::setFallDiagonalPen( const QPen & _p )
01361 {
01362   if ( _p.style() == Qt::NoPen )
01363   {
01364     clearProperty( PFallDiagonal );
01365     setNoFallBackProperties( PFallDiagonal );
01366   }
01367   else
01368   {
01369     setProperty( PFallDiagonal );
01370     clearNoFallBackProperties( PFallDiagonal );
01371   }
01372 
01373   m_pStyle = m_pStyle->setFallDiagonalPen( _p );
01374   formatChanged();
01375 }
01376 
01377 void Format::setFallDiagonalStyle( Qt::PenStyle s )
01378 {
01379   QPen p( m_pStyle->fallDiagonalPen() );
01380   p.setStyle( s );
01381   setFallDiagonalPen( p );
01382 }
01383 
01384 void Format::setFallDiagonalColor( const QColor& c )
01385 {
01386   QPen p( m_pStyle->fallDiagonalPen() );
01387   p.setColor( c );
01388   setFallDiagonalPen( p );
01389 }
01390 
01391 void Format::setFallDiagonalWidth( int _w )
01392 {
01393   QPen p( m_pStyle->fallDiagonalPen() );
01394   p.setWidth( _w );
01395   setFallDiagonalPen( p );
01396 }
01397 
01398 void Format::setGoUpDiagonalPen( const QPen & _p )
01399 {
01400   if ( _p.style() == Qt::NoPen )
01401   {
01402     clearProperty( PGoUpDiagonal );
01403     setNoFallBackProperties( PGoUpDiagonal );
01404   }
01405   else
01406   {
01407     setProperty( PGoUpDiagonal );
01408     clearNoFallBackProperties( PGoUpDiagonal );
01409   }
01410 
01411   m_pStyle = m_pStyle->setGoUpDiagonalPen( _p );
01412   formatChanged();
01413 }
01414 
01415 void Format::setGoUpDiagonalStyle( Qt::PenStyle s )
01416 {
01417   QPen p( m_pStyle->goUpDiagonalPen() );
01418     p.setStyle( s );
01419     setGoUpDiagonalPen( p );
01420 }
01421 
01422 void Format::setGoUpDiagonalColor( const QColor& c )
01423 {
01424   QPen p( m_pStyle->goUpDiagonalPen() );
01425   p.setColor( c );
01426   setGoUpDiagonalPen( p );
01427 }
01428 
01429 void Format::setGoUpDiagonalWidth( int _w )
01430 {
01431   QPen p( m_pStyle->goUpDiagonalPen() );
01432   p.setWidth( _w );
01433   setGoUpDiagonalPen( p );
01434 }
01435 
01436 void Format::setBackGroundBrush( const QBrush & _p)
01437 {
01438   if ( _p.style() == Qt::NoBrush )
01439   {
01440     clearProperty( PBackgroundBrush );
01441     setNoFallBackProperties( PBackgroundBrush );
01442   }
01443   else
01444   {
01445     setProperty( PBackgroundBrush );
01446     clearNoFallBackProperties( PBackgroundBrush );
01447   }
01448 
01449   m_pStyle = m_pStyle->setBackGroundBrush( _p );
01450   formatChanged();
01451 }
01452 
01453 void Format::setBackGroundBrushStyle( Qt::BrushStyle s )
01454 {
01455   QBrush b( m_pStyle->backGroundBrush() );
01456   b.setStyle( s );
01457   setBackGroundBrush( b );
01458 }
01459 
01460 void Format::setBackGroundBrushColor( const QColor & c )
01461 {
01462   QBrush b( m_pStyle->backGroundBrush() );
01463   b.setColor( c );
01464   setBackGroundBrush( b );
01465 }
01466 
01467 void Format::setTextFont( const QFont & _f )
01468 {
01469   if( m_pStyle->parent() && _f == m_pStyle->parent()->font())
01470   {
01471     clearProperty( PFont );
01472     setNoFallBackProperties( PFont );
01473   }
01474   else if( !m_pStyle->parent() && _f == KoGlobal::defaultFont() )
01475   {
01476     clearProperty( PFont );
01477     setNoFallBackProperties( PFont );
01478   }
01479   else
01480   {
01481     setProperty( PFont );
01482     clearNoFallBackProperties( PFont );
01483   }
01484 
01485 
01486   m_pStyle = m_pStyle->setFont( _f );
01487   formatChanged();
01488 }
01489 
01490 void Format::setTextFontSize( int _s )
01491 {
01492   QFont f( m_pStyle->font() );
01493   f.setPointSize( _s );
01494   setTextFont( f );
01495 }
01496 
01497 void Format::setTextFontFamily( const QString & _f )
01498 {
01499   QFont f( m_pStyle->font() );
01500   f.setFamily( _f );
01501   setTextFont( f );
01502 }
01503 
01504 void Format::setTextFontBold( bool _b )
01505 {
01506   QFont f( m_pStyle->font() );
01507   f.setBold( _b );
01508   setTextFont( f );
01509 }
01510 
01511 void Format::setTextFontItalic( bool _i )
01512 {
01513   QFont f( m_pStyle->font() );
01514   f.setItalic( _i );
01515   setTextFont( f );
01516 }
01517 
01518 void Format::setTextFontUnderline( bool _i )
01519 {
01520   QFont f( m_pStyle->font() );
01521   f.setUnderline( _i );
01522   setTextFont( f );
01523 }
01524 
01525 void Format::setTextFontStrike( bool _i )
01526 {
01527   QFont f( m_pStyle->font() );
01528   f.setStrikeOut( _i );
01529   setTextFont( f );
01530 }
01531 
01532 void Format::setTextPen( const QPen & _p )
01533 {
01534    // An invalid color means "the default text color, from the color scheme"
01535    // It doesn't mean "no setting here, look at fallback"
01536    // Maybe we should look at the fallback color, in fact.
01537    /*if(!_p.color().isValid())
01538      {
01539      clearProperty( PTextPen );
01540      setNoFallBackProperties( PTextPen );
01541      }
01542      else*/
01543   {
01544     setProperty( PTextPen );
01545     clearNoFallBackProperties( PTextPen );
01546   }
01547 
01548   //setProperty( PTextPen );
01549   m_pStyle = m_pStyle->setPen( _p );
01550   //kdDebug(36001) << "setTextPen: this=" << this << " pen=" << m_textPen.color().name() << " valid:" << m_textPen.color().isValid() << endl;
01551   formatChanged();
01552 }
01553 
01554 void Format::setTextColor( const QColor & _c )
01555 {
01556   QPen p( m_pStyle->pen() );
01557   p.setColor( _c );
01558   setTextPen( p );
01559 }
01560 
01561 void Format::setBgColor( const QColor & _c )
01562 {
01563   if ( !_c.isValid() )
01564   {
01565     clearProperty( PBackgroundColor );
01566     setNoFallBackProperties( PBackgroundColor );
01567   }
01568   else
01569   {
01570     setProperty( PBackgroundColor );
01571     clearNoFallBackProperties( PBackgroundColor );
01572   }
01573 
01574   m_pStyle = m_pStyle->setBgColor( _c );
01575   formatChanged();
01576 }
01577 
01578 void Format::setFloatFormat( FloatFormat _f )
01579 {
01580   setProperty( PFloatFormat );
01581 
01582   m_pStyle = m_pStyle->setFloatFormat( _f );
01583   formatChanged();
01584 }
01585 
01586 void Format::setFloatColor( FloatColor _c )
01587 {
01588   setProperty( PFloatColor );
01589 
01590   m_pStyle = m_pStyle->setFloatColor( _c );
01591   formatChanged();
01592 }
01593 
01594 void Format::setMultiRow( bool _b )
01595 {
01596   if ( _b == false )
01597   {
01598     m_pStyle = m_pStyle->clearProperty( Style::PMultiRow );
01599     clearProperty( PMultiRow );
01600     setNoFallBackProperties( PMultiRow );
01601   }
01602   else
01603   {
01604     m_pStyle = m_pStyle->setProperty( Style::PMultiRow );
01605     setProperty( PMultiRow );
01606     clearNoFallBackProperties( PMultiRow );
01607   }
01608   formatChanged();
01609 }
01610 
01611 void Format::setVerticalText( bool _b )
01612 {
01613   if ( _b == false )
01614   {
01615     m_pStyle = m_pStyle->clearProperty( Style::PVerticalText );
01616     setNoFallBackProperties( PVerticalText);
01617     clearFlag( Flag_VerticalText );
01618   }
01619   else
01620   {
01621     m_pStyle = m_pStyle->setProperty( Style::PVerticalText );
01622     clearNoFallBackProperties( PVerticalText);
01623     setFlag( Flag_VerticalText );
01624   }
01625   formatChanged();
01626 }
01627 
01628 void Format::setFormatType( FormatType _format )
01629 {
01630   if ( _format == Number_format )
01631   {
01632     clearProperty( PFormatType );
01633     setNoFallBackProperties( PFormatType);
01634   }
01635   else
01636   {
01637     setProperty( PFormatType );
01638     clearNoFallBackProperties( PFormatType);
01639   }
01640 
01641   m_pStyle = m_pStyle->setFormatType( _format );
01642   formatChanged();
01643 }
01644 
01645 void Format::setAngle( int _angle )
01646 {
01647   if ( _angle == 0 )
01648   {
01649     clearProperty( PAngle );
01650     setNoFallBackProperties( PAngle);
01651   }
01652   else
01653   {
01654     setProperty( PAngle );
01655     clearNoFallBackProperties( PAngle);
01656   }
01657 
01658   m_pStyle = m_pStyle->setRotateAngle( _angle );
01659   formatChanged();
01660 }
01661 
01662 void Format::setIndent( double _indent )
01663 {
01664   if ( _indent == 0.0 )
01665   {
01666     clearProperty( PIndent );
01667     setNoFallBackProperties( PIndent );
01668   }
01669   else
01670   {
01671     setProperty( PIndent );
01672     clearNoFallBackProperties( PIndent );
01673   }
01674 
01675   m_pStyle = m_pStyle->setIndent( _indent );
01676   formatChanged();
01677 }
01678 
01679 void Format::setComment( const QString & _comment )
01680 {
01681   if ( _comment.isEmpty() )
01682   {
01683     clearProperty( PComment );
01684     setNoFallBackProperties( PComment );
01685   }
01686   else
01687   {
01688     setProperty( PComment );
01689     clearNoFallBackProperties( PComment );
01690   }
01691 
01692   // not part of the style
01693   delete m_strComment;
01694   if ( !_comment.isEmpty() )
01695     m_strComment = new QString( _comment );
01696   else
01697     m_strComment = 0;
01698   formatChanged();
01699 }
01700 
01701 void Format::setNotProtected( bool _b)
01702 {
01703   if ( _b == false )
01704   {
01705     m_pStyle = m_pStyle->clearProperty( Style::PNotProtected );
01706     setNoFallBackProperties( PNotProtected );
01707     clearFlag( Flag_NotProtected );
01708   }
01709   else
01710   {
01711     m_pStyle = m_pStyle->setProperty( Style::PNotProtected );
01712     clearNoFallBackProperties( PNotProtected );
01713     setFlag( Flag_NotProtected );
01714   }
01715   formatChanged();
01716 }
01717 
01718 void Format::setDontPrintText( bool _b )
01719 {
01720   if ( _b == false )
01721   {
01722     m_pStyle = m_pStyle->clearProperty( Style::PDontPrintText );
01723     setNoFallBackProperties(PDontPrintText);
01724     clearFlag( Flag_DontPrintText );
01725   }
01726   else
01727   {
01728     m_pStyle = m_pStyle->setProperty( Style::PDontPrintText );
01729     clearNoFallBackProperties( PDontPrintText);
01730     setFlag( Flag_DontPrintText );
01731   }
01732   formatChanged();
01733 }
01734 
01735 void Format::setHideAll( bool _b )
01736 {
01737   if ( _b == false )
01738   {
01739     m_pStyle = m_pStyle->clearProperty( Style::PHideAll );
01740     setNoFallBackProperties(PHideAll);
01741     clearFlag( Flag_HideAll );
01742   }
01743   else
01744   {
01745     m_pStyle = m_pStyle->setProperty( Style::PHideAll );
01746     clearNoFallBackProperties( PHideAll);
01747     setFlag( Flag_HideAll );
01748   }
01749   formatChanged();
01750 }
01751 
01752 void Format::setHideFormula( bool _b )
01753 {
01754   if ( _b == false )
01755   {
01756     m_pStyle = m_pStyle->clearProperty( Style::PHideFormula );
01757     setNoFallBackProperties( PHideFormula );
01758     clearFlag( Flag_HideFormula );
01759   }
01760   else
01761   {
01762     m_pStyle = m_pStyle->setProperty( Style::PHideFormula );
01763     clearNoFallBackProperties( PHideFormula );
01764     setFlag( Flag_HideFormula );
01765   }
01766   formatChanged();
01767 }
01768 
01769 void Format::setCurrency( Currency const & c )
01770 {
01771   m_pStyle = m_pStyle->setCurrency( c );
01772 }
01773 
01774 void Format::setCurrency( int type, QString const & symbol )
01775 {
01776   Currency c;
01777 
01778   c.symbol = symbol.simplifyWhiteSpace();
01779   c.type   = type;
01780 
01781   if (c.symbol.length() == 0)
01782   {
01783     c.type = 0;
01784     c.symbol = sheet()->doc()->locale()->currencySymbol();
01785   }
01786 
01787   m_pStyle = m_pStyle->setCurrency( c );
01788 }
01789 
01791 //
01792 // Get methods
01793 //
01795 
01796 QString const & Format::getFormatString( int col, int row ) const
01797 {
01798   if ( !hasProperty( PCustomFormat, false ) && !hasNoFallBackProperties( PCustomFormat ))
01799   {
01800     const Format * l = fallbackFormat( col, row );
01801     if ( l )
01802       return l->getFormatString( col, row );
01803   }
01804   return m_pStyle->strFormat();
01805 }
01806 
01807 QString Format::prefix( int col, int row ) const
01808 {
01809   if ( !hasProperty( PPrefix, false ) && !hasNoFallBackProperties(PPrefix ))
01810   {
01811     const Format * l = fallbackFormat( col, row );
01812     if ( l )
01813       return l->prefix( col, row );
01814   }
01815   return m_pStyle->prefix();
01816 }
01817 
01818 QString Format::postfix( int col, int row ) const
01819 {
01820   if ( !hasProperty( PPostfix, false ) && !hasNoFallBackProperties(PPostfix ))
01821   {
01822     const Format * l = fallbackFormat( col, row );
01823     if ( l )
01824       return l->postfix( col, row );
01825   }
01826   return m_pStyle->postfix();
01827 }
01828 
01829 const QPen& Format::fallDiagonalPen( int col, int row ) const
01830 {
01831   if ( !hasProperty( PFallDiagonal, false )  && !hasNoFallBackProperties(PFallDiagonal ))
01832   {
01833     const Format* l = fallbackFormat( col, row );
01834     if ( l )
01835       return l->fallDiagonalPen( col, row );
01836   }
01837   return m_pStyle->fallDiagonalPen();
01838 }
01839 
01840 int Format::fallDiagonalWidth( int col, int row ) const
01841 {
01842   return fallDiagonalPen( col, row ).width();
01843 }
01844 
01845 Qt::PenStyle Format::fallDiagonalStyle( int col, int row ) const
01846 {
01847   return fallDiagonalPen( col, row ).style();
01848 }
01849 
01850 const QColor & Format::fallDiagonalColor( int col, int row ) const
01851 {
01852   return fallDiagonalPen( col, row ).color();
01853 }
01854 
01855 const QPen & Format::goUpDiagonalPen( int col, int row ) const
01856 {
01857   if ( !hasProperty( PGoUpDiagonal, false ) && !hasNoFallBackProperties( PGoUpDiagonal ) )
01858   {
01859     const Format* l = fallbackFormat( col, row );
01860     if ( l )
01861       return l->goUpDiagonalPen( col, row );
01862   }
01863   return m_pStyle->goUpDiagonalPen();
01864 }
01865 
01866 int Format::goUpDiagonalWidth( int col, int row ) const
01867 {
01868   return goUpDiagonalPen( col, row ).width();
01869 }
01870 
01871 Qt::PenStyle Format::goUpDiagonalStyle( int col, int row ) const
01872 {
01873   return goUpDiagonalPen( col, row ).style();
01874 }
01875 
01876 const QColor& Format::goUpDiagonalColor( int col, int row ) const
01877 {
01878   return goUpDiagonalPen( col, row ).color();
01879 }
01880 
01881 uint Format::bottomBorderValue( int col, int row ) const
01882 {
01883   if ( !hasProperty( PBottomBorder, false ) && !hasNoFallBackProperties( PBottomBorder ) )
01884   {
01885     const Format * l = fallbackFormat( col, row );
01886     if ( l )
01887       return l->bottomBorderValue( col, row );
01888 
01889     return 0;
01890   }
01891 
01892   return m_pStyle->bottomPenValue();
01893 }
01894 
01895 uint Format::rightBorderValue( int col, int row ) const
01896 {
01897   if ( !hasProperty( PRightBorder, false ) && !hasNoFallBackProperties( PRightBorder ) )
01898   {
01899     const Format * l = fallbackFormat( col, row );
01900     if ( l )
01901       return l->rightBorderValue( col, row );
01902 
01903     return 0;
01904   }
01905 
01906   return m_pStyle->rightPenValue();
01907 }
01908 
01909 uint Format::leftBorderValue( int col, int row ) const
01910 {
01911   if ( !hasProperty( PLeftBorder, false ) && !hasNoFallBackProperties( PLeftBorder ) )
01912   {
01913     const Format * l = fallbackFormat( col, row );
01914     if ( l )
01915       return l->leftBorderValue( col, row );
01916 
01917     return 0;
01918   }
01919 
01920   return m_pStyle->leftPenValue();
01921 }
01922 
01923 uint Format::topBorderValue( int col, int row ) const
01924 {
01925   if ( !hasProperty( PTopBorder, false ) && !hasNoFallBackProperties( PTopBorder ) )
01926   {
01927     const Format * l = fallbackFormat( col, row );
01928     if ( l )
01929       return l->topBorderValue( col, row );
01930 
01931     return 0;
01932   }
01933 
01934   return m_pStyle->topPenValue();
01935 }
01936 
01937 const QPen& Format::leftBorderPen( int col, int row ) const
01938 {
01939   if ( !hasProperty( PLeftBorder, false ) && !hasNoFallBackProperties( PLeftBorder ) )
01940   {
01941     const Format * l = fallbackFormat( col, row );
01942     if ( l )
01943       return l->leftBorderPen( col, row );
01944     return sheet()->emptyPen();
01945   }
01946 
01947   return m_pStyle->leftBorderPen();
01948 }
01949 
01950 Qt::PenStyle Format::leftBorderStyle( int col, int row ) const
01951 {
01952   return leftBorderPen( col, row ).style();
01953 }
01954 
01955 const QColor& Format::leftBorderColor( int col, int row ) const
01956 {
01957   return leftBorderPen( col, row ).color();
01958 }
01959 
01960 int Format::leftBorderWidth( int col, int row ) const
01961 {
01962   return leftBorderPen( col, row ).width();
01963 }
01964 
01965 const QPen& Format::topBorderPen( int col, int row ) const
01966 {
01967   if ( !hasProperty( PTopBorder, false ) && !hasNoFallBackProperties( PTopBorder ) )
01968   {
01969     const Format* l = fallbackFormat( col, row );
01970     if ( l )
01971       return l->topBorderPen( col, row );
01972     return sheet()->emptyPen();
01973   }
01974 
01975   return m_pStyle->topBorderPen();
01976 }
01977 
01978 const QColor& Format::topBorderColor( int col, int row ) const
01979 {
01980   return topBorderPen( col, row ).color();
01981 }
01982 
01983 Qt::PenStyle Format::topBorderStyle( int col, int row ) const
01984 {
01985   return topBorderPen( col, row ).style();
01986 }
01987 
01988 int Format::topBorderWidth( int col, int row ) const
01989 {
01990   return topBorderPen( col, row ).width();
01991 }
01992 
01993 const QPen& Format::rightBorderPen( int col, int row ) const
01994 {
01995   if ( !hasProperty( PRightBorder, false ) && !hasNoFallBackProperties( PRightBorder ) )
01996   {
01997     const Format * l = fallbackFormat( col, row );
01998     if ( l )
01999       return l->rightBorderPen( col, row );
02000     return sheet()->emptyPen();
02001   }
02002 
02003   return m_pStyle->rightBorderPen();
02004 }
02005 
02006 int Format::rightBorderWidth( int col, int row ) const
02007 {
02008   return rightBorderPen( col, row ).width();
02009 }
02010 
02011 Qt::PenStyle Format::rightBorderStyle( int col, int row ) const
02012 {
02013   return rightBorderPen( col, row ).style();
02014 }
02015 
02016 const QColor& Format::rightBorderColor( int col, int row ) const
02017 {
02018   return rightBorderPen( col, row ).color();
02019 }
02020 
02021 const QPen& Format::bottomBorderPen( int col, int row ) const
02022 {
02023   if ( !hasProperty( PBottomBorder, false )&& !hasNoFallBackProperties( PBottomBorder ) )
02024   {
02025     const Format * l = fallbackFormat( col, row );
02026     if ( l )
02027       return l->bottomBorderPen( col, row );
02028     return sheet()->emptyPen();
02029   }
02030 
02031   return m_pStyle->bottomBorderPen();
02032 }
02033 
02034 int Format::bottomBorderWidth( int col, int row ) const
02035 {
02036   return bottomBorderPen( col, row ).width();
02037 }
02038 
02039 Qt::PenStyle Format::bottomBorderStyle( int col, int row ) const
02040 {
02041   return bottomBorderPen( col, row ).style();
02042 }
02043 
02044 const QColor& Format::bottomBorderColor( int col, int row ) const
02045 {
02046   return bottomBorderPen( col, row ).color();
02047 }
02048 
02049 const QBrush& Format::backGroundBrush( int col, int row ) const
02050 {
02051   if ( !hasProperty( PBackgroundBrush, false ) && !hasNoFallBackProperties(PBackgroundBrush ))
02052   {
02053     const Format* l = fallbackFormat( col, row );
02054     if ( l )
02055       return l->backGroundBrush( col, row );
02056   }
02057   return m_pStyle->backGroundBrush();
02058 }
02059 
02060 Qt::BrushStyle Format::backGroundBrushStyle( int col, int row ) const
02061 {
02062   return backGroundBrush( col, row ).style();
02063 }
02064 
02065 const QColor& Format::backGroundBrushColor( int col, int row ) const
02066 {
02067   return backGroundBrush( col, row ).color();
02068 }
02069 
02070 int Format::precision( int col, int row ) const
02071 {
02072   if ( !hasProperty( PPrecision, false )&& !hasNoFallBackProperties( PPrecision ) )
02073   {
02074     const Format * l = fallbackFormat( col, row );
02075     if ( l )
02076       return l->precision( col, row );
02077   }
02078   return m_pStyle->precision();
02079 }
02080 
02081 Format::FloatFormat Format::floatFormat( int col, int row ) const
02082 {
02083   if ( !hasProperty( PFloatFormat, false ) && !hasNoFallBackProperties( PFloatFormat ) )
02084   {
02085     const Format * l = fallbackFormat( col, row );
02086     if ( l )
02087       return l->floatFormat( col, row );
02088   }
02089   return m_pStyle->floatFormat();
02090 }
02091 
02092 Format::FloatColor Format::floatColor( int col, int row ) const
02093 {
02094   if ( !hasProperty( PFloatColor, false ) && !hasNoFallBackProperties( PFloatColor ) )
02095   {
02096     const Format * l = fallbackFormat( col, row );
02097     if ( l )
02098       return l->floatColor( col, row );
02099   }
02100   return m_pStyle->floatColor();
02101 }
02102 
02103 const QColor& Format::bgColor( int col, int row ) const
02104 {
02105   if ( !hasProperty( PBackgroundColor, false ) && !hasNoFallBackProperties( PBackgroundColor ) )
02106   {
02107     const Format * l = fallbackFormat( col, row );
02108     if ( l )
02109       return l->bgColor( col, row );
02110   }
02111 
02112   return m_pStyle->bgColor();
02113 }
02114 
02115 const QPen& Format::textPen( int col, int row ) const
02116 {
02117   if ( !hasProperty( PTextPen, false ) && !hasNoFallBackProperties( PTextPen ) )
02118   {
02119     const Format * l = fallbackFormat( col, row );
02120     if ( l )
02121       return l->textPen( col, row );
02122   }
02123   return m_pStyle->pen();
02124 }
02125 
02126 const QColor& Format::textColor( int col, int row ) const
02127 {
02128   return textPen( col, row ).color();
02129 }
02130 
02131 const QFont Format::textFont( int col, int row ) const
02132 {
02133   if ( !hasProperty( PFont, false ) && !hasNoFallBackProperties( PFont ) )
02134   {
02135     const Format * l = fallbackFormat( col, row );
02136     if ( l )
02137       return l->textFont( col, row );
02138   }
02139 
02140   return m_pStyle->font();
02141 }
02142 
02143 int Format::textFontSize( int col, int row ) const
02144 {
02145   if ( !hasProperty( PFont, false ) && !hasNoFallBackProperties( PFont ) )
02146   {
02147     const Format * l = fallbackFormat( col, row );
02148     if ( l )
02149       return l->textFontSize( col, row );
02150   }
02151 
02152   return m_pStyle->fontSize();
02153 }
02154 
02155 QString const & Format::textFontFamily( int col, int row ) const
02156 {
02157   if ( !hasProperty( PFont, false ) && !hasNoFallBackProperties( PFont ) )
02158   {
02159     const Format * l = fallbackFormat( col, row );
02160     if ( l )
02161       return l->textFontFamily( col, row );
02162   }
02163 
02164   return m_pStyle->fontFamily();
02165 }
02166 
02167 bool Format::textFontBold( int col, int row ) const
02168 {
02169   if ( !hasProperty( PFont, false ) && !hasNoFallBackProperties( PFont ) )
02170   {
02171     const Format * l = fallbackFormat( col, row );
02172     if ( l )
02173       return l->textFontBold( col, row );
02174   }
02175 
02176   return ( m_pStyle->fontFlags() & Style::FBold );
02177 }
02178 
02179 bool Format::textFontItalic( int col, int row ) const
02180 {
02181   if ( !hasProperty( PFont, false ) && !hasNoFallBackProperties( PFont ) )
02182   {
02183     const Format * l = fallbackFormat( col, row );
02184     if ( l )
02185       return l->textFontItalic( col, row );
02186   }
02187 
02188   return ( m_pStyle->fontFlags() & Style::FItalic );
02189 }
02190 
02191 bool Format::textFontUnderline( int col, int row ) const
02192 {
02193   if ( !hasProperty( PFont, false ) && !hasNoFallBackProperties( PFont ) )
02194   {
02195     const Format * l = fallbackFormat( col, row );
02196     if ( l )
02197       return l->textFontUnderline( col, row );
02198   }
02199 
02200   return ( m_pStyle->fontFlags() & Style::FUnderline );
02201 }
02202 
02203 bool Format::textFontStrike( int col, int row ) const
02204 {
02205   if ( !hasProperty( PFont, false ) && !hasNoFallBackProperties( PFont ) )
02206   {
02207     const Format * l = fallbackFormat( col, row );
02208     if ( l )
02209       return l->textFontStrike( col, row );
02210   }
02211 
02212   return ( m_pStyle->fontFlags() & Style::FStrike );
02213 }
02214 
02215 Format::Align Format::align( int col, int row ) const
02216 {
02217   if ( !hasProperty( PAlign, false ) && !hasNoFallBackProperties( PAlign ) )
02218   {
02219     const Format * l = fallbackFormat( col, row );
02220     if ( l )
02221       return l->align( col, row );
02222   }
02223 
02224   return m_pStyle->alignX();
02225 }
02226 
02227 Format::AlignY Format::alignY( int col, int row ) const
02228 {
02229   if ( !hasProperty( PAlignY, false )&& !hasNoFallBackProperties( PAlignY ) )
02230   {
02231     const Format * l = fallbackFormat( col, row );
02232     if ( l )
02233       return l->alignY( col, row );
02234   }
02235 
02236   return m_pStyle->alignY();
02237 }
02238 
02239 bool Format::multiRow( int col, int row ) const
02240 {
02241   if ( !hasProperty( PMultiRow, false ) && !hasNoFallBackProperties( PMultiRow ) )
02242   {
02243     const Format * l = fallbackFormat( col, row );
02244     if ( l )
02245       return l->multiRow( col, row );
02246   }
02247 
02248   return m_pStyle->hasProperty( Style::PMultiRow );
02249 }
02250 
02251 bool Format::verticalText( int col, int row ) const
02252 {
02253   if ( !hasProperty( PVerticalText, false )&& !hasNoFallBackProperties( PVerticalText ) )
02254   {
02255     const Format * l = fallbackFormat( col, row );
02256     if ( l )
02257       return l->verticalText( col, row );
02258   }
02259 
02260   return m_pStyle->hasProperty( Style::PVerticalText );
02261 }
02262 
02263 FormatType Format::getFormatType( int col, int row ) const
02264 {
02265   if ( !hasProperty( PFormatType, false ) && !hasNoFallBackProperties( PFormatType ) )
02266   {
02267     const Format* l = fallbackFormat( col, row );
02268     if ( l )
02269       return l->getFormatType( col, row );
02270   }
02271 
02272   return m_pStyle->formatType();
02273 }
02274 
02275 int Format::getAngle( int col, int row ) const
02276 {
02277   if ( !hasProperty( PAngle, false ) && !hasNoFallBackProperties( PAngle ) )
02278   {
02279     const Format* l = fallbackFormat( col, row );
02280     if ( l )
02281       return l->getAngle( col, row );
02282   }
02283 
02284   return m_pStyle->rotateAngle();
02285 }
02286 
02287 QString Format::comment( int col, int row ) const
02288 {
02289   if ( !hasProperty( PComment, false ) && !hasNoFallBackProperties(  PComment ))
02290   {
02291     const Format* l = fallbackFormat( col, row );
02292     if ( l )
02293       return l->comment( col, row );
02294   }
02295 
02296   if ( !m_strComment )
02297     return QString::null;
02298 
02299   // not part of the style
02300   return *m_strComment;
02301 }
02302 
02303 QString * Format::commentP( int col, int row ) const
02304 {
02305   if ( !hasProperty( PComment, false ) && !hasNoFallBackProperties(  PComment ))
02306   {
02307     const Format* l = fallbackFormat( col, row );
02308     if ( l )
02309       return l->commentP( col, row );
02310   }
02311 
02312   return m_strComment;
02313 }
02314 
02315 double Format::getIndent( int col, int row ) const
02316 {
02317   if ( !hasProperty( PIndent, false ) && !hasNoFallBackProperties( PIndent ) )
02318   {
02319     const Format* l = fallbackFormat( col, row );
02320     if ( l )
02321       return l->getIndent( col, row );
02322   }
02323 
02324   return m_pStyle->indent();
02325 }
02326 
02327 bool Format::getDontprintText( int col, int row ) const
02328 {
02329   if ( !hasProperty( PDontPrintText, false )&& !hasNoFallBackProperties( PDontPrintText ) )
02330   {
02331     const Format* l = fallbackFormat( col, row );
02332     if ( l )
02333       return l->getDontprintText( col, row );
02334   }
02335 
02336   return m_pStyle->hasProperty( Style::PDontPrintText );
02337 }
02338 
02339 bool Format::isProtected( int col, int row ) const
02340 {
02341   return ( m_pSheet->isProtected() && !notProtected( col, row ) );
02342 }
02343 
02344 
02345 bool Format::notProtected( int col, int row) const
02346 {
02347   if ( !hasProperty( PNotProtected, false )&& !hasNoFallBackProperties( PNotProtected ) )
02348   {
02349     const Format * l = fallbackFormat( col, row );
02350     if ( l )
02351       return l->notProtected( col, row );
02352   }
02353 
02354   return m_pStyle->hasProperty( Style::PNotProtected );
02355 }
02356 
02357 bool Format::isHideAll( int col, int row) const
02358 {
02359   if ( !hasProperty( PHideAll, false )&& !hasNoFallBackProperties( PHideAll ) )
02360   {
02361     const Format * l = fallbackFormat( col, row );
02362     if ( l )
02363       return l->isHideAll( col, row );
02364   }
02365 
02366   return m_pStyle->hasProperty( Style::PHideAll );
02367 }
02368 
02369 bool Format::isHideFormula( int col, int row) const
02370 {
02371   if ( !hasProperty( PHideFormula, false )&& !hasNoFallBackProperties( PHideFormula ) )
02372   {
02373     const Format * l = fallbackFormat( col, row );
02374     if ( l )
02375       return l->isHideFormula( col, row );
02376   }
02377 
02378   return m_pStyle->hasProperty( Style::PHideFormula );
02379 }
02380 
02381 bool Format::currencyInfo( Currency & currency) const
02382 {
02383   // TODO: fallback ?
02384   if ( m_pStyle->formatType() != Money_format )
02385     return false;
02386 
02387   currency.symbol = m_pStyle->currency().symbol;
02388   currency.type   = m_pStyle->currency().type;
02389 
02390   return true;
02391 }
02392 
02393 QString Format::getCurrencySymbol() const
02394 {
02395   // TODO: fallback ?
02396   return m_pStyle->currency().symbol;
02397 }
02398 
02399 QFont Format::font() const
02400 {
02401   return m_pStyle->font();
02402 }
02403 
02404 
02406 //
02407 // Get methods
02408 //
02410 
02411 const QPen & Format::leftBorderPen() const
02412 {
02413   return m_pStyle->leftBorderPen();
02414 }
02415 
02416 const QPen & Format::topBorderPen() const
02417 {
02418   return m_pStyle->topBorderPen();
02419 }
02420 
02421 const QPen & Format::rightBorderPen() const
02422 {
02423   return m_pStyle->rightBorderPen();
02424 }
02425 
02426 const QPen & Format::bottomBorderPen() const
02427 {
02428   return m_pStyle->bottomBorderPen();
02429 }
02430 
02431 const QPen & Format::fallDiagonalPen() const
02432 {
02433   return m_pStyle->fallDiagonalPen();
02434 }
02435 
02436 const QPen & Format::goUpDiagonalPen() const
02437 {
02438   return m_pStyle->goUpDiagonalPen();
02439 }
02440 
02441 const QBrush & Format::backGroundBrush() const
02442 {
02443   return m_pStyle->backGroundBrush();
02444 }
02445 
02446 const QFont Format::textFont() const
02447 {
02448   return m_pStyle->font();
02449 }
02450 
02451 const QPen & Format::textPen() const
02452 {
02453   return m_pStyle->pen();
02454 }
02455 
02457 //
02458 // Misc
02459 //
02461 
02462 void Format::formatChanged()
02463 {
02464   if (m_pCell)
02465   {
02466     m_pCell->setFlag(Cell::Flag_LayoutDirty);
02467     m_pCell->setFlag(Cell::Flag_TextFormatDirty);
02468   }
02469 }
02470 
02471 Format* Format::fallbackFormat( int, int row )
02472 {
02473   return m_pCell ? m_pSheet->rowFormat( row ) : 0;
02474 }
02475 
02476 const Format* Format::fallbackFormat( int, int row ) const
02477 {
02478   return m_pCell ? m_pSheet->rowFormat( row ) : 0;
02479 }
02480 
02481 bool Format::isDefault() const
02482 {
02483   return true;
02484 }
02485 
02486 /*****************************************************************************
02487  *
02488  * RowFormat
02489  *
02490  *****************************************************************************/
02491 
02492 //#define UPDATE_BEGIN bool b_update_begin = m_bDisplayDirtyFlag; m_bDisplayDirtyFlag = true;
02493 //#define UPDATE_END if ( !b_update_begin && m_bDisplayDirtyFlag ) m_pSheet->emit_updateRow( this, m_iRow );
02494 
02495 RowFormat::RowFormat( Sheet * _sheet, int _row )
02496   : Format( _sheet, _sheet->doc()->styleManager()->defaultStyle() )
02497 {
02498     m_next = 0;
02499     m_prev = 0;
02500 
02501     m_bDisplayDirtyFlag = false;
02502     m_fHeight  = g_rowHeight;
02503     m_iRow     = _row;
02504     m_bDefault = false;
02505     m_bHide    = false;
02506     m_dcop     = 0L;
02507 }
02508 
02509 RowFormat::~RowFormat()
02510 {
02511     if ( m_next )
02512     m_next->setPrevious( m_prev );
02513     if ( m_prev )
02514     m_prev->setNext( m_next );
02515     delete m_dcop;
02516 }
02517 
02518 DCOPObject * RowFormat::dcopObject()
02519 {
02520     if ( !m_dcop )
02521     m_dcop = new RowIface( this );
02522     return m_dcop;
02523 }
02524 
02525 
02526 void RowFormat::setMMHeight( double _h )
02527 {
02528   setDblHeight( MM_TO_POINT ( _h ) );
02529 }
02530 
02531 void RowFormat::setHeight( int _h, const Canvas * _canvas )
02532 {
02533   setDblHeight( (double) _h, _canvas );
02534 }
02535 
02536 void RowFormat::setDblHeight( double _h, const Canvas * _canvas )
02537 {
02538   Sheet *_sheet = _canvas ? _canvas->activeSheet() : m_pSheet;
02539 
02540   // avoid unnecessary updates
02541   if ( kAbs( _h - dblHeight( _canvas ) ) < DBL_EPSILON )
02542     return;
02543 
02544 //  UPDATE_BEGIN;
02545 
02546   // Lower maximum size by old height
02547   _sheet->adjustSizeMaxY ( - dblHeight() );
02548 
02549   if ( _canvas )
02550     m_fHeight = ( _h / _canvas->zoom() );
02551   else
02552     m_fHeight = _h;
02553 
02554   // Rise maximum size by new height
02555   _sheet->adjustSizeMaxY ( dblHeight() );
02556   _sheet->print()->updatePrintRepeatRowsHeight();
02557   _sheet->print()->updateNewPageListY ( row() );
02558 
02559   _sheet->emit_updateRow(this,m_iRow);
02560 //  UPDATE_END;
02561 }
02562 
02563 int RowFormat::height( const Canvas *_canvas ) const
02564 {
02565   return (int) dblHeight( _canvas );
02566 }
02567 
02568 double RowFormat::dblHeight( const Canvas *_canvas ) const
02569 {
02570     if( m_bHide )
02571         return 0.0;
02572 
02573     if ( _canvas )
02574         return _canvas->zoom() * m_fHeight;
02575     else
02576         return m_fHeight;
02577 }
02578 
02579 double RowFormat::mmHeight() const
02580 {
02581     return POINT_TO_MM ( dblHeight() );
02582 }
02583 
02584 QDomElement RowFormat::save( QDomDocument& doc, int yshift, bool copy ) const
02585 {
02586     QDomElement row = doc.createElement( "row" );
02587     row.setAttribute( "height", m_fHeight );
02588     row.setAttribute( "row", m_iRow - yshift );
02589     if( m_bHide )
02590         row.setAttribute( "hide", (int) m_bHide );
02591 
02592     QDomElement format( saveFormat( doc, false, copy ) );
02593     row.appendChild( format );
02594     return row;
02595 }
02596 
02597 bool RowFormat::loadOasis( const QDomElement& /*row*/, QDomElement * /*rowStyle*/ )
02598 {
02599     return true;
02600 }
02601 
02602 bool RowFormat::load( const QDomElement & row, int yshift, Paste::Mode sp, bool paste )
02603 {
02604     bool ok;
02605 
02606     m_iRow = row.attribute( "row" ).toInt( &ok ) + yshift;
02607     if ( !ok )
02608       return false;
02609 
02610     if ( row.hasAttribute( "height" ) )
02611     {
02612     if ( m_pSheet->doc()->syntaxVersion() < 1 ) //compatibility with old format - was in millimeter
02613         m_fHeight = qRound( MM_TO_POINT( row.attribute( "height" ).toDouble( &ok ) ) );
02614     else
02615         m_fHeight = row.attribute( "height" ).toDouble( &ok );
02616 
02617     if ( !ok ) return false;
02618     }
02619 
02620     // Validation
02621     if ( m_fHeight < 0 )
02622     {
02623     kdDebug(36001) << "Value height=" << m_fHeight << " out of range" << endl;
02624     return false;
02625     }
02626     if ( m_iRow < 1 || m_iRow > KS_rowMax )
02627     {
02628     kdDebug(36001) << "Value row=" << m_iRow << " out of range" << endl;
02629     return false;
02630     }
02631 
02632     if ( row.hasAttribute( "hide" ) )
02633     {
02634         setHide( (int) row.attribute( "hide" ).toInt( &ok ) );
02635         if ( !ok )
02636            return false;
02637     }
02638 
02639     QDomElement f( row.namedItem( "format" ).toElement() );
02640 
02641     if ( !f.isNull() && ( sp == Paste::Normal || sp == Paste::Format || sp == Paste::NoBorder ) )
02642     {
02643         if ( !loadFormat( f, sp, paste ) )
02644             return false;
02645         return true;
02646     }
02647 
02648     return true;
02649 }
02650 
02651 const QPen & RowFormat::topBorderPen( int _col, int _row ) const
02652 {
02653     // First look at the row above us
02654     if ( !hasProperty( PTopBorder, false ) )
02655     {
02656     const RowFormat * rl = sheet()->rowFormat( _row - 1 );
02657     if ( rl->hasProperty( PBottomBorder ) )
02658         return rl->bottomBorderPen( _col, _row - 1 );
02659     }
02660 
02661     return Format::topBorderPen( _col, _row );
02662 }
02663 
02664 void RowFormat::setTopBorderPen( const QPen & p )
02665 {
02666     RowFormat * cl = sheet()->nonDefaultRowFormat( row() - 1, false );
02667     if ( cl )
02668     cl->clearProperty( PBottomBorder );
02669 
02670     Format::setTopBorderPen( p );
02671 }
02672 
02673 const QPen & RowFormat::bottomBorderPen( int _col, int _row ) const
02674 {
02675     // First look at the row below of us
02676     if ( !hasProperty( PBottomBorder, false ) && ( _row < KS_rowMax ) )
02677     {
02678     const RowFormat * rl = sheet()->rowFormat( _row + 1 );
02679     if ( rl->hasProperty( PTopBorder ) )
02680         return rl->topBorderPen( _col, _row + 1 );
02681     }
02682 
02683     return Format::bottomBorderPen( _col, _row );
02684 }
02685 
02686 void RowFormat::setBottomBorderPen( const QPen & p )
02687 {
02688     if ( row() < KS_rowMax )
02689     {
02690         RowFormat * cl = sheet()->nonDefaultRowFormat( row() + 1, false );
02691         if ( cl )
02692         cl->clearProperty( PTopBorder );
02693     }
02694 
02695     Format::setBottomBorderPen( p );
02696 }
02697 
02698 void RowFormat::setHide( bool _hide, bool repaint )
02699 {
02700     if ( _hide != m_bHide ) // only if we change the status
02701     {
02702     if ( _hide )
02703     {
02704         // Lower maximum size by height of row
02705         m_pSheet->adjustSizeMaxY ( - dblHeight() );
02706         m_bHide = _hide; //hide must be set after we requested the height
02707       m_pSheet->emit_updateRow( this, m_iRow, repaint );
02708     }
02709     else
02710     {
02711         // Rise maximum size by height of row
02712         m_bHide = _hide; //unhide must be set before we request the height
02713         m_pSheet->adjustSizeMaxY ( dblHeight() );
02714             m_pSheet->emit_updateRow( this, m_iRow, repaint );
02715     }
02716     }
02717 }
02718 
02719 Format* RowFormat::fallbackFormat( int col, int )
02720 {
02721     return sheet()->columnFormat( col );
02722 }
02723 
02724 const Format* RowFormat::fallbackFormat( int col, int ) const
02725 {
02726     return sheet()->columnFormat( col );
02727 }
02728 
02729 bool RowFormat::isDefault() const
02730 {
02731     return m_bDefault;
02732 }
02733 
02734 /*****************************************************************************
02735  *
02736  * ColumnFormat
02737  *
02738  *****************************************************************************/
02739 
02740 #undef UPDATE_BEGIN
02741 #undef UPDATE_END
02742 
02743 #define UPDATE_BEGIN bool b_update_begin = m_bDisplayDirtyFlag; m_bDisplayDirtyFlag = true;
02744 #define UPDATE_END if ( !b_update_begin && m_bDisplayDirtyFlag ) m_pSheet->emit_updateColumn( this, m_iColumn );
02745 
02746 ColumnFormat::ColumnFormat( Sheet * _sheet, int _column )
02747   : Format( _sheet, _sheet->doc()->styleManager()->defaultStyle() )
02748 {
02749   m_bDisplayDirtyFlag = false;
02750   m_fWidth = g_colWidth;
02751   m_iColumn = _column;
02752   m_bDefault=false;
02753   m_bHide=false;
02754   m_prev = 0;
02755   m_next = 0;
02756   m_dcop = 0;
02757 }
02758 
02759 ColumnFormat::~ColumnFormat()
02760 {
02761     if ( m_next )
02762     m_next->setPrevious( m_prev );
02763     if ( m_prev )
02764     m_prev->setNext( m_next );
02765     delete m_dcop;
02766 }
02767 
02768 DCOPObject * ColumnFormat::dcopObject()
02769 {
02770     if ( !m_dcop )
02771         m_dcop = new ColumnIface( this );
02772     return m_dcop;
02773 }
02774 
02775 void ColumnFormat::setMMWidth( double _w )
02776 {
02777   setDblWidth( MM_TO_POINT ( _w ) );
02778 }
02779 
02780 void ColumnFormat::setWidth( int _w, const Canvas * _canvas )
02781 {
02782   setDblWidth( (double)_w, _canvas );
02783 }
02784 
02785 void ColumnFormat::setDblWidth( double _w, const Canvas * _canvas )
02786 {
02787   Sheet *_sheet = _canvas ? _canvas->activeSheet() : m_pSheet;
02788 
02789   // avoid unnecessary updates
02790   if ( kAbs( _w - dblWidth( _canvas ) ) < DBL_EPSILON )
02791     return;
02792 
02793  // UPDATE_BEGIN;
02794 
02795   // Lower maximum size by old width
02796   _sheet->adjustSizeMaxX ( - dblWidth() );
02797 
02798   if ( _canvas )
02799       m_fWidth = ( _w / _canvas->zoom() );
02800   else
02801       m_fWidth = _w;
02802 
02803   // Rise maximum size by new width
02804   _sheet->adjustSizeMaxX ( dblWidth() );
02805   _sheet->print()->updatePrintRepeatColumnsWidth();
02806   _sheet->print()->updateNewPageListX ( column() );
02807 
02808   _sheet->emit_updateColumn(this,m_iColumn);
02809  // UPDATE_END;
02810 }
02811 
02812 int ColumnFormat::width( const Canvas * _canvas ) const
02813 {
02814   return (int) dblWidth( _canvas );
02815 }
02816 
02817 double ColumnFormat::dblWidth( const Canvas * _canvas ) const
02818 {
02819   if ( m_bHide )
02820     return 0.0;
02821 
02822   if ( _canvas )
02823     return _canvas->zoom() * m_fWidth;
02824   else
02825     return m_fWidth;
02826 }
02827 
02828 double ColumnFormat::mmWidth() const
02829 {
02830   return POINT_TO_MM( dblWidth() );
02831 }
02832 
02833 
02834 QDomElement ColumnFormat::save( QDomDocument& doc, int xshift, bool copy ) const
02835 {
02836   QDomElement col( doc.createElement( "column" ) );
02837   col.setAttribute( "width", m_fWidth );
02838   col.setAttribute( "column", m_iColumn - xshift );
02839 
02840   if ( m_bHide )
02841         col.setAttribute( "hide", (int) m_bHide );
02842 
02843   QDomElement format( saveFormat( doc, false, copy ) );
02844   col.appendChild( format );
02845 
02846   return col;
02847 }
02848 
02849 bool ColumnFormat::load( const QDomElement & col, int xshift, Paste::Mode sp, bool paste )
02850 {
02851     bool ok;
02852     if ( col.hasAttribute( "width" ) )
02853     {
02854     if ( m_pSheet->doc()->syntaxVersion() < 1 ) //combatibility to old format - was in millimeter
02855         m_fWidth = qRound( MM_TO_POINT ( col.attribute( "width" ).toDouble( &ok ) ) );
02856     else
02857         m_fWidth = col.attribute( "width" ).toDouble( &ok );
02858 
02859     if ( !ok )
02860             return false;
02861     }
02862 
02863     m_iColumn = col.attribute( "column" ).toInt( &ok ) + xshift;
02864 
02865     if ( !ok )
02866         return false;
02867 
02868     // Validation
02869     if ( m_fWidth < 0 )
02870     {
02871     kdDebug(36001) << "Value width=" << m_fWidth << " out of range" << endl;
02872     return false;
02873     }
02874     if ( m_iColumn < 1 || m_iColumn > KS_colMax )
02875     {
02876     kdDebug(36001) << "Value col=" << m_iColumn << " out of range" << endl;
02877     return false;
02878     }
02879     if ( col.hasAttribute( "hide" ) )
02880     {
02881         setHide( (int) col.attribute( "hide" ).toInt( &ok ) );
02882         if ( !ok )
02883             return false;
02884     }
02885 
02886     QDomElement f( col.namedItem( "format" ).toElement() );
02887 
02888     if ( !f.isNull() && ( sp == Paste::Normal || sp == Paste::Format || sp == Paste::NoBorder ))
02889     {
02890         if ( !loadFormat( f, sp, paste ) )
02891             return false;
02892         return true;
02893     }
02894 
02895     return true;
02896 }
02897 
02898 const QPen & ColumnFormat::leftBorderPen( int _col, int _row ) const
02899 {
02900     // First look ar the right column at the right
02901     if ( !hasProperty( PLeftBorder, false ) )
02902     {
02903     const ColumnFormat * cl = sheet()->columnFormat( _col - 1 );
02904     if ( cl->hasProperty( PRightBorder ) )
02905         return cl->rightBorderPen( _col - 1, _row );
02906     }
02907 
02908     return Format::leftBorderPen( _col, _row );
02909 }
02910 
02911 void ColumnFormat::setLeftBorderPen( const QPen & p )
02912 {
02913     ColumnFormat * cl = sheet()->nonDefaultColumnFormat( column() - 1, false );
02914     if ( cl )
02915     cl->clearProperty( PRightBorder );
02916 
02917     Format::setLeftBorderPen( p );
02918 }
02919 
02920 const QPen & ColumnFormat::rightBorderPen( int _col, int _row ) const
02921 {
02922     // First look ar the right column at the right
02923     if ( !hasProperty( PRightBorder, false ) && ( _col < KS_colMax ) )
02924     {
02925     const ColumnFormat * cl = sheet()->columnFormat( _col + 1 );
02926     if ( cl->hasProperty( PLeftBorder ) )
02927         return cl->leftBorderPen( _col + 1, _row );
02928     }
02929 
02930     return Format::rightBorderPen( _col, _row );
02931 }
02932 
02933 void ColumnFormat::setRightBorderPen( const QPen & p )
02934 {
02935     if ( column() < KS_colMax )
02936     {
02937         ColumnFormat * cl = sheet()->nonDefaultColumnFormat( column() + 1, false );
02938         if ( cl )
02939             cl->clearProperty( PLeftBorder );
02940     }
02941 
02942     Format::setRightBorderPen( p );
02943 }
02944 
02945 Format * ColumnFormat::fallbackFormat( int, int )
02946 {
02947     return sheet()->defaultFormat();
02948 }
02949 
02950 void ColumnFormat::setHide( bool _hide )
02951 {
02952     if ( _hide != m_bHide ) // only if we change the status
02953     {
02954     if ( _hide )
02955     {
02956         // Lower maximum size by width of column
02957         m_pSheet->adjustSizeMaxX ( - dblWidth() );
02958         m_bHide = _hide; //hide must be set after we requested the width
02959           //  m_pSheet->emit_updateColumn( this, m_iColumn );
02960     }
02961     else
02962         {
02963         // Rise maximum size by width of column
02964         m_bHide = _hide; //unhide must be set before we request the width
02965         m_pSheet->adjustSizeMaxX ( dblWidth() );
02966          //   m_pSheet->emit_updateColumn( this, m_iColumn );
02967         }
02968     }
02969 }
02970 
02971 const Format * ColumnFormat::fallbackFormat( int, int ) const
02972 {
02973     return sheet()->defaultFormat();
02974 }
02975 
02976 bool ColumnFormat::isDefault() const
02977 {
02978     return m_bDefault;
02979 }
02980 
02981 namespace Currency_LNS
02982 {
02983   typedef struct
02984   {
02985     char const * code;
02986     char const * country;
02987     char const * name;
02988     char const * display;
02989   } Money;
02990 
02991   // codes and names as defined in ISO 3166-1
02992   // first  column: saved code
02993   // second column: country name (localized)
02994   // third column:  currency name (localized)
02995   // fourth column: displayed currency code (localized but maybe only in
02996   //                the country language it belongs to)
02997   // WARNING: change the "24" in getChooseString if you change this array
02998   static const Money lMoney[] = {
02999     { "", "", "", ""}, // auto
03000     { "", "", "", ""}, // extension (codes imported)
03001     { "$", "", "Dollar", "$" }, // unspecified
03002     { "$", I18N_NOOP("Australia"), I18N_NOOP("Dollar"), "$" },
03003     { "$", I18N_NOOP("Canada"), I18N_NOOP("Dollar"), "$" },
03004     { "$", I18N_NOOP("Caribbea"), I18N_NOOP("Dollar"), "$" },
03005     { "$", I18N_NOOP("New Zealand"), I18N_NOOP("Dollar"), "$" },
03006     { "$", I18N_NOOP("United States"), I18N_NOOP("Dollar"), "$" },
03007 
03008     // € == Euro sign in utf8
03009     { "€", "", "€", "€" }, // unspecified
03010     { "€", I18N_NOOP("Austria"), I18N_NOOP("Euro"), "€" },
03011     { "€", I18N_NOOP("Belgium"), I18N_NOOP("Euro"), "€" },
03012     { "€", I18N_NOOP("Finland"), I18N_NOOP("Euro"), "€" },
03013     { "€", I18N_NOOP("France"), I18N_NOOP("Euro"), "€" },
03014     { "€", I18N_NOOP("Germany"), I18N_NOOP("Euro"), "€" },
03015     { "€", I18N_NOOP("Greece"), I18N_NOOP("Euro"), "€" },
03016     { "€", I18N_NOOP("Ireland"), I18N_NOOP("Euro"), "€" },
03017     { "€", I18N_NOOP("Italy"), I18N_NOOP("Euro"), "€" },
03018     { "€", I18N_NOOP("Luxembourg"), I18N_NOOP("Euro"), "€" },
03019     { "€", I18N_NOOP("Monaco"), I18N_NOOP("Euro"), "€" },
03020     { "€", I18N_NOOP("Netherlands"), I18N_NOOP("Euro"), "€" },
03021     { "€", I18N_NOOP("Portugal"), I18N_NOOP("Euro"), "€" },
03022     { "€", I18N_NOOP("Spain"), I18N_NOOP("Euro"), "€" },
03023 
03024     { "£", I18N_NOOP("United Kingdom"), I18N_NOOP("Pound"), "£" },
03025 
03026     { "Â¥", I18N_NOOP("Japan"), I18N_NOOP("Yen"), "Â¥" },
03027 
03028     { "AFA", I18N_NOOP("Afghanistan"), I18N_NOOP("Afghani"), I18N_NOOP("AFA") },
03029     { "ALL", I18N_NOOP("Albania"), I18N_NOOP("Lek"), I18N_NOOP("Lek") },
03030     { "DZD", I18N_NOOP("Algeria"), I18N_NOOP("Algerian Dinar"), I18N_NOOP("DZD") },
03031     { "USD", I18N_NOOP("American Samoa"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
03032     { "EUR", I18N_NOOP("Andorra"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
03033     { "ADP", I18N_NOOP("Andorra"), I18N_NOOP("Andorran Peseta"), I18N_NOOP("ADP") },
03034     { "AOA", I18N_NOOP("Angola"), I18N_NOOP("Kwanza"), I18N_NOOP("AOA") },
03035     { "XCD", I18N_NOOP("Anguilla"), I18N_NOOP("East Caribbean Dollar"), I18N_NOOP("XCD") },
03036     { "XCD", I18N_NOOP("Antigua And Barbuda"), I18N_NOOP("East Carribean Dollar"), I18N_NOOP("XCD") },
03037     { "ARS", I18N_NOOP("Argentina"), I18N_NOOP("Argentine Peso"), I18N_NOOP("ARS") },
03038     { "AMD", I18N_NOOP("Armenia"), I18N_NOOP("Armenian Dram"), I18N_NOOP("AMD") },
03039     { "AWG", I18N_NOOP("Aruba"), I18N_NOOP("Aruban Guilder"), I18N_NOOP("AWG") },
03040     { "AUD", I18N_NOOP("Australia"), I18N_NOOP("Australian Dollar"), I18N_NOOP("AUD") },
03041     { "EUR", I18N_NOOP("Austria"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
03042     { "ATS", I18N_NOOP("Austria"), I18N_NOOP("Schilling"), I18N_NOOP("S") },
03043     { "AZM", I18N_NOOP("Azerbaijan"), I18N_NOOP("Azerbaijanian Manat"), I18N_NOOP("AZM") },
03044     { "BSD", I18N_NOOP("Bahamas"), I18N_NOOP("Bahamian Dollar"), I18N_NOOP("BSD") },
03045     { "BHD", I18N_NOOP("Bahrain"), I18N_NOOP("Bahraini Dinar"), I18N_NOOP("BHD") },
03046     { "BDT", I18N_NOOP("Bangladesh"), I18N_NOOP("Taka"), I18N_NOOP("BDT") },
03047     { "BBD", I18N_NOOP("Barbados"), I18N_NOOP("Barbados Dollar"), I18N_NOOP("BBD") },
03048     { "BYR", I18N_NOOP("Belarus"), I18N_NOOP("Belarussian Ruble"), I18N_NOOP("p.") },
03049     { "EUR", I18N_NOOP("Belgium"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
03050     { "BEF", I18N_NOOP("Belgium"), I18N_NOOP("Franc"), I18N_NOOP("BF") },
03051     { "BZD", I18N_NOOP("Belize"), I18N_NOOP("Belize Dollar"), I18N_NOOP("BZ$") },
03052     { "XOF", I18N_NOOP("Benin"), I18N_NOOP("CFA Franc BCEAO"), I18N_NOOP("XOF") },
03053     { "BMD", I18N_NOOP("Bermuda"), I18N_NOOP("Bermudian Dollar"), I18N_NOOP("BMD") },
03054     { "INR", I18N_NOOP("Bhutan"), I18N_NOOP("Indian Rupee"), I18N_NOOP("INR") },
03055     { "BTN", I18N_NOOP("Bhutan"), I18N_NOOP("Ngultrum"), I18N_NOOP("BTN") },
03056     { "BOB", I18N_NOOP("Bolivia"), I18N_NOOP("Boliviano"), I18N_NOOP("Bs") },
03057     { "BOV", I18N_NOOP("Bolivia"), I18N_NOOP("Mvdol"), I18N_NOOP("BOV") },
03058     { "BAM", I18N_NOOP("Bosnia And Herzegovina"), I18N_NOOP("Convertible Marks"), I18N_NOOP("BAM") },
03059     { "BWP", I18N_NOOP("Botswana"), I18N_NOOP("Pula"), I18N_NOOP("BWP") },
03060     { "NOK", I18N_NOOP("Bouvet Island"), I18N_NOOP("Norvegian Krone"), I18N_NOOP("NOK") },
03061     { "BRL", I18N_NOOP("Brazil"), I18N_NOOP("Brazilian Real"), I18N_NOOP("R$") },
03062     { "USD", I18N_NOOP("British Indian Ocean Territory"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
03063     { "BND", I18N_NOOP("Brunei Darussalam"), I18N_NOOP("Brunei Dollar"), I18N_NOOP("BND") },
03064     { "BGL", I18N_NOOP("Bulgaria"), I18N_NOOP("Lev"), I18N_NOOP("BGL") },
03065     { "BGN", I18N_NOOP("Bulgaria"), I18N_NOOP("Bulgarian Lev"), I18N_NOOP("BGN") },
03066     { "XOF", I18N_NOOP("Burkina Faso"), I18N_NOOP("CFA Franc BCEAO"), I18N_NOOP("XOF") },
03067     { "BIF", I18N_NOOP("Burundi"), I18N_NOOP("Burundi Franc"), I18N_NOOP("BIF") },
03068     { "KHR", I18N_NOOP("Cambodia"), I18N_NOOP("Riel"), I18N_NOOP("KHR") },
03069     { "XAF", I18N_NOOP("Cameroon"), I18N_NOOP("CFA Franc BEAC"), I18N_NOOP("XAF") },
03070     { "CAD", I18N_NOOP("Canada"), I18N_NOOP("Canadian Dollar"), I18N_NOOP("CAD") },
03071     { "CVE", I18N_NOOP("Cape Verde"), I18N_NOOP("Cape Verde Escudo"), I18N_NOOP("CVE") },
03072     { "KYD", I18N_NOOP("Cayman Islands"), I18N_NOOP("Cayman Islands Dollar"), I18N_NOOP("KYD") },
03073     { "XAF", I18N_NOOP("Central African Republic"), I18N_NOOP("CFA Franc BEAC"), I18N_NOOP("XAF") },
03074     { "XAF", I18N_NOOP("Chad"), I18N_NOOP("CFA Franc BEAC"), I18N_NOOP("XAF") },
03075     { "CLP", I18N_NOOP("Chile"), I18N_NOOP("Chilean Peso"), I18N_NOOP("Ch$") },
03076     { "CLF", I18N_NOOP("Chile"), I18N_NOOP("Unidades de fomento"), I18N_NOOP("CLF") },
03077     { "CNY", I18N_NOOP("China"), I18N_NOOP("Yuan Renminbi"), I18N_NOOP("CNY") },
03078     { "AUD", I18N_NOOP("Christmas Island"), I18N_NOOP("Australian Dollar"), I18N_NOOP("AUD") },
03079     { "AUD", I18N_NOOP("Cocos (Keeling) Islands"), I18N_NOOP("Australian Dollar"), I18N_NOOP("AUD") },
03080     { "COP", I18N_NOOP("Colombia"), I18N_NOOP("Colombian Peso"), I18N_NOOP("C$") },
03081     { "KMF", I18N_NOOP("Comoros"), I18N_NOOP("Comoro Franc"), I18N_NOOP("KMF") },
03082     { "XAF", I18N_NOOP("Congo"), I18N_NOOP("CFA Franc BEAC"), I18N_NOOP("XAF") },
03083     { "CDF", I18N_NOOP("Congo, The Democratic Republic Of"), I18N_NOOP("Franc Congolais"), I18N_NOOP("CDF") },
03084     { "NZD", I18N_NOOP("Cook Islands"), I18N_NOOP("New Zealand Dollar"), I18N_NOOP("NZD") },
03085     { "CRC", I18N_NOOP("Costa Rica"), I18N_NOOP("Costa Rican Colon"), I18N_NOOP("C") },
03086     { "XOF", I18N_NOOP("Cote D'Ivoire"), I18N_NOOP("CFA Franc BCEAO"), I18N_NOOP("XOF") },
03087     { "HRK", I18N_NOOP("Croatia"), I18N_NOOP("Croatian kuna"), I18N_NOOP("kn") },
03088     { "CUP", I18N_NOOP("Cuba"), I18N_NOOP("Cuban Peso"), I18N_NOOP("CUP") },
03089     { "CYP", I18N_NOOP("Cyprus"), I18N_NOOP("Cyprus Pound"), I18N_NOOP("CYP") },
03090     { "CZK", I18N_NOOP("Czech Republic"), I18N_NOOP("Czech Koruna"), I18N_NOOP("Kc") },
03091     { "DKK", I18N_NOOP("Denmark"), I18N_NOOP("Danish Krone"), I18N_NOOP("kr") },
03092     { "DJF", I18N_NOOP("Djibouti"), I18N_NOOP("Djibouti Franc"), I18N_NOOP("DJF") },
03093     { "XCD", I18N_NOOP("Dominica"), I18N_NOOP("East Caribbean Dollar"), I18N_NOOP("RD$") },
03094     { "DOP", I18N_NOOP("Dominican Republic"), I18N_NOOP("Dominican Peso"), I18N_NOOP("DOP") },
03095     { "TPE", I18N_NOOP("East Timor"), I18N_NOOP("Timor Escudo"), I18N_NOOP("TPE") },
03096     { "USD", I18N_NOOP("East Timor"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
03097     { "USD", I18N_NOOP("Ecuador"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
03098     { "EGP", I18N_NOOP("Egypt"), I18N_NOOP("Egyptian Pound"), I18N_NOOP("EGP") },
03099     { "SVC", I18N_NOOP("El Salvador"), I18N_NOOP("El Salvador Colon"), I18N_NOOP("C") },
03100     { "USD", I18N_NOOP("El Salvador"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
03101     { "XAF", I18N_NOOP("Equatorial Guinea"), I18N_NOOP("CFA Franc BEAC"), I18N_NOOP("XAF") },
03102     { "ERN", I18N_NOOP("Eritrea"), I18N_NOOP("Nakfa"), I18N_NOOP("ERN") },
03103     { "EEK", I18N_NOOP("Estonia"), I18N_NOOP("Kroon"), I18N_NOOP("kr") },
03104     { "ETB", I18N_NOOP("Ethiopia"), I18N_NOOP("Ethiopian Birr"), I18N_NOOP("ETB") },
03105     { "FKP", I18N_NOOP("Falkland Island (Malvinas)"), I18N_NOOP("Falkland Islands Pound"), I18N_NOOP("FKP") },
03106     { "DKK", I18N_NOOP("Faeroe Islands"), I18N_NOOP("Danish Krone"), I18N_NOOP("kr") },
03107     { "FJD", I18N_NOOP("Fiji"), I18N_NOOP("Fiji Dollar"), I18N_NOOP("FJD") },
03108     { "EUR", I18N_NOOP("Finland"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
03109     { "FIM", I18N_NOOP("Finland"), I18N_NOOP("Markka"), I18N_NOOP("mk") },
03110     { "EUR", I18N_NOOP("France"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
03111     { "FRF", I18N_NOOP("France"), I18N_NOOP("Franc"), I18N_NOOP("F") },
03112     { "EUR", I18N_NOOP("French Guiana"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
03113     { "XPF", I18N_NOOP("French Polynesia"), I18N_NOOP("CFP Franc"), I18N_NOOP("XPF") },
03114     { "EUR", I18N_NOOP("Franc Southern Territories"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
03115     { "XAF", I18N_NOOP("Gabon"), I18N_NOOP("CFA Franc BEAC"), I18N_NOOP("XAF") },
03116     { "GMD", I18N_NOOP("Gambia"), I18N_NOOP("Dalasi"), I18N_NOOP("GMD") },
03117     { "GEL", I18N_NOOP("Georgia"), I18N_NOOP("Lari"), I18N_NOOP("GEL") },
03118     { "EUR", I18N_NOOP("Germany"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
03119     { "DEM", I18N_NOOP("Germany"), I18N_NOOP("German Mark"), I18N_NOOP("DM") },
03120     { "GHC", I18N_NOOP("Ghana"), I18N_NOOP("Cedi"), I18N_NOOP("GHC") },
03121     { "GIP", I18N_NOOP("Gibraltar"), I18N_NOOP("Gibraltar Pound"), I18N_NOOP("GIP") },
03122     { "EUR", I18N_NOOP("Greece"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
03123     { "GRD", I18N_NOOP("Greece"), I18N_NOOP("Drachma"), I18N_NOOP("GRD") },
03124     { "DKK", I18N_NOOP("Greenland"), I18N_NOOP("Danish Krone"), I18N_NOOP("DKK") },
03125     { "XCD", I18N_NOOP("Grenada"), I18N_NOOP("East Caribbean Dollar"), I18N_NOOP("XCD") },
03126     { "EUR", I18N_NOOP("Guadeloupe"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
03127     { "USD", I18N_NOOP("Guam"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
03128     { "GTQ", I18N_NOOP("Guatemala"), I18N_NOOP("Quetzal"), I18N_NOOP("Q") },
03129     { "GNF", I18N_NOOP("Guinea"), I18N_NOOP("Guinea Franc"), I18N_NOOP("GNF") },
03130     { "GWP", I18N_NOOP("Guinea-Bissau"), I18N_NOOP("Guinea-Bissau Peso"), I18N_NOOP("GWP") },
03131     { "XOF", I18N_NOOP("Guinea-Bissau"), I18N_NOOP("CFA Franc BCEAO"), I18N_NOOP("XOF") },
03132     { "GYD", I18N_NOOP("Guyana"), I18N_NOOP("Guyana Dollar"), I18N_NOOP("GYD") },
03133     { "HTG", I18N_NOOP("Haiti"), I18N_NOOP("Gourde"), I18N_NOOP("HTG") },
03134     { "USD", I18N_NOOP("Haiti"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
03135     { "AUD", I18N_NOOP("Heard Island And McDonald Islands"), I18N_NOOP("Australian Dollar"), I18N_NOOP("AUD") },
03136     { "EUR", I18N_NOOP("Holy See (Vatican City State)"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
03137     { "HNL", I18N_NOOP("Honduras"), I18N_NOOP("Lempira"), I18N_NOOP("L") },
03138     { "HKD", I18N_NOOP("Hong Kong"), I18N_NOOP("Hong Kong Dollar"), I18N_NOOP("HKD") },
03139     { "HUF", I18N_NOOP("Hungary"), I18N_NOOP("Forint"), I18N_NOOP("Ft") },
03140     { "ISK", I18N_NOOP("Iceland"), I18N_NOOP("Iceland Krona"), I18N_NOOP("kr.") },
03141     { "INR", I18N_NOOP("India"), I18N_NOOP("Indian Rupee"), I18N_NOOP("INR") },
03142     { "IDR", I18N_NOOP("Indonesia"), I18N_NOOP("Rupiah"), I18N_NOOP("Rp") },
03143     { "IRR", I18N_NOOP("Iran, Islamic Republic Of"), I18N_NOOP("Iranian Rial"), I18N_NOOP("IRR") },
03144     { "IQD", I18N_NOOP("Iraq"), I18N_NOOP("Iraqi Dinar"), I18N_NOOP("IQD") },
03145     { "EUR", I18N_NOOP("Ireland"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
03146     { "IEP", I18N_NOOP("Ireland"), I18N_NOOP("Punt"), I18N_NOOP("IR----") },
03147     { "IEX", I18N_NOOP("Ireland"), I18N_NOOP("Pence"), I18N_NOOP("IEX") },
03148     { "ILS", I18N_NOOP("Israel"), I18N_NOOP("New Israeli Sheqel"), I18N_NOOP("ILS") },
03149     { "EUR", I18N_NOOP("Italy"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
03150     { "ITL", I18N_NOOP("Italy"), I18N_NOOP("Lira"), I18N_NOOP("L.") },
03151     { "JMD", I18N_NOOP("Jamaica"), I18N_NOOP("Jamaican Dollar"), I18N_NOOP("J$") },
03152     { "JPY", I18N_NOOP("Japan"), I18N_NOOP("Yen"), I18N_NOOP("JPY") },
03153     { "JOD", I18N_NOOP("Jordan"), I18N_NOOP("Jordanian Dinar"), I18N_NOOP("JOD") },
03154     { "KZT", I18N_NOOP("Kazakhstan"), I18N_NOOP("Tenge"), I18N_NOOP("KZT") },
03155     { "KES", I18N_NOOP("Kenya"), I18N_NOOP("Kenyan Shilling"), I18N_NOOP("KES") },
03156     { "AUD", I18N_NOOP("Kiribati"), I18N_NOOP("Australian Dollar"), I18N_NOOP("AUD") },
03157     { "KPW", I18N_NOOP("Korea, Democratic People's Republic Of"), I18N_NOOP("North Korean Won"), I18N_NOOP("KPW") },
03158     { "KRW", I18N_NOOP("Korea, Republic Of"), I18N_NOOP("Won"), I18N_NOOP("KRW") },
03159     { "KWD", I18N_NOOP("Kuwait"), I18N_NOOP("Kuwaiti Dinar"), I18N_NOOP("KWD") },
03160     { "KGS", I18N_NOOP("Kyrgyzstan"), I18N_NOOP("Som"), I18N_NOOP("KGS") },
03161     { "LAK", I18N_NOOP("Lao People's Democratic Republic"), I18N_NOOP("Kip"), I18N_NOOP("LAK") },
03162     { "LVL", I18N_NOOP("Latvia"), I18N_NOOP("Latvian Lats"), I18N_NOOP("Ls") },
03163     { "LBP", I18N_NOOP("Lebanon"), I18N_NOOP("Lebanese Pound"), I18N_NOOP("LBP") },
03164     { "ZAR", I18N_NOOP("Lesotho"), I18N_NOOP("Rand"), I18N_NOOP("ZAR") },
03165     { "LSL", I18N_NOOP("Lesotho"), I18N_NOOP("Loti"), I18N_NOOP("LSL") },
03166     { "LRD", I18N_NOOP("Liberia"), I18N_NOOP("Liberian Dollar"), I18N_NOOP("LRD") },
03167     { "LYD", I18N_NOOP("Libyan Arab Jamahiriya"), I18N_NOOP("Lybian Dinar"), I18N_NOOP("LYD") },
03168     { "CHF", I18N_NOOP("Liechtenstein"), I18N_NOOP("Swiss Franc"), I18N_NOOP("CHF") },
03169     { "LTL", I18N_NOOP("Lithuania"), I18N_NOOP("Lithuanian Litus"), I18N_NOOP("Lt") },
03170     { "EUR", I18N_NOOP("Luxembourg"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
03171     { "LUF", I18N_NOOP("Luxembourg"), I18N_NOOP("Franc"), I18N_NOOP("F") },
03172     { "MOP", I18N_NOOP("Macao"), I18N_NOOP("Pataca"), I18N_NOOP("MOP") },
03173     { "MKD", I18N_NOOP("Macedonia, The Former Yugoslav Republic Of"), I18N_NOOP("Denar"), I18N_NOOP("MKD") },
03174     { "MGF", I18N_NOOP("Madagascar"), I18N_NOOP("Malagasy Franc"), I18N_NOOP("MGF") },
03175     { "MWK", I18N_NOOP("Malawi"), I18N_NOOP("Kwacha"), I18N_NOOP("MWK") },
03176     { "MYR", I18N_NOOP("Malaysia"), I18N_NOOP("Malaysian Ringgit"), I18N_NOOP("MYR") },
03177     { "MVR", I18N_NOOP("Maldives"), I18N_NOOP("Rufiyaa"), I18N_NOOP("MVR") },
03178     { "XOF", I18N_NOOP("Mali"), I18N_NOOP("CFA Franc BCEAO"), I18N_NOOP("XOF") },
03179     { "MTL", I18N_NOOP("Malta"), I18N_NOOP("Maltese Lira"), I18N_NOOP("MTL") },
03180     { "USD", I18N_NOOP("Marshall Islands"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
03181     { "EUR", I18N_NOOP("Martinique"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
03182     { "MRO", I18N_NOOP("Mauritania"), I18N_NOOP("Ouguiya"), I18N_NOOP("MRO") },
03183     { "MUR", I18N_NOOP("Mauritius"), I18N_NOOP("Mauritius Rupee"), I18N_NOOP("MUR") },
03184     { "EUR", I18N_NOOP("Mayotte"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
03185     { "MXN", I18N_NOOP("Mexico"), I18N_NOOP("Mexican Peso"), I18N_NOOP("MXN") },
03186     { "MXV", I18N_NOOP("Mexico"), I18N_NOOP("Mexican Unidad de Inversion (UDI)"), I18N_NOOP("MXV") },
03187     { "USD", I18N_NOOP("Micronesia, Federated States Of"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
03188     { "MDL", I18N_NOOP("Moldova, Republic Of"), I18N_NOOP("Moldovan Leu"), I18N_NOOP("MDL") },
03189     { "EUR", I18N_NOOP("Monaco"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
03190     { "MNT", I18N_NOOP("Mongolia"), I18N_NOOP("Tugrik"), I18N_NOOP("MNT") },
03191     { "XCD", I18N_NOOP("Montserrat"), I18N_NOOP("East Caribbean Dollar"), I18N_NOOP("XCD") },
03192     { "MAD", I18N_NOOP("Morocco"), I18N_NOOP("Moroccan Dirham"), I18N_NOOP("MAD") },
03193     { "MZM", I18N_NOOP("Mozambique"), I18N_NOOP("Metical"), I18N_NOOP("MZM") },
03194     { "MMK", I18N_NOOP("Myanmar"), I18N_NOOP("Kyat"), I18N_NOOP("MMK") },
03195     { "ZAR", I18N_NOOP("Namibia"), I18N_NOOP("Rand"), I18N_NOOP("ZAR") },
03196     { "NAD", I18N_NOOP("Namibia"), I18N_NOOP("Namibia Dollar"), I18N_NOOP("NAD") },
03197     { "AUD", I18N_NOOP("Nauru"), I18N_NOOP("Australian Dollar"), I18N_NOOP("AUD") },
03198     { "NPR", I18N_NOOP("Nepal"), I18N_NOOP("Nepalese Rupee"), I18N_NOOP("NPR") },
03199     { "EUR", I18N_NOOP("Netherlands"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
03200     { "NLG", I18N_NOOP("Netherlands"), I18N_NOOP("Guilder"), I18N_NOOP("fl") },
03201     { "ANG", I18N_NOOP("Netherlands Antilles"), I18N_NOOP("Netherlands Antillan Guilder"), I18N_NOOP("ANG") },
03202     { "XPF", I18N_NOOP("New Caledonia"), I18N_NOOP("CFP Franc"), I18N_NOOP("XPF") },
03203     { "NZD", I18N_NOOP("New Zealand"), I18N_NOOP("New Zealand Dollar"), I18N_NOOP("NZD") },
03204     { "NIO", I18N_NOOP("Nicaragua"), I18N_NOOP("Cordoba Oro"), I18N_NOOP("NIO") },
03205     { "XOF", I18N_NOOP("Niger"), I18N_NOOP("CFA Franc BCEAO"), I18N_NOOP("XOF") },
03206     { "NGN", I18N_NOOP("Nigeria"), I18N_NOOP("Naira"), I18N_NOOP("NGN") },
03207     { "NZD", I18N_NOOP("Niue"), I18N_NOOP("New Zealand Dollar"), I18N_NOOP("NZD") },
03208     { "AUD", I18N_NOOP("Norfolk Islands"), I18N_NOOP("Australian Dollar"), I18N_NOOP("AUD") },
03209     { "USD", I18N_NOOP("Northern Mariana Islands"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
03210     { "NOK", I18N_NOOP("Norway"), I18N_NOOP("Norwegian Krone"), I18N_NOOP("kr") },
03211     { "OMR", I18N_NOOP("Oman"), I18N_NOOP("Rial Omani"), I18N_NOOP("OMR") },
03212     { "PKR", I18N_NOOP("Pakistan"), I18N_NOOP("Pakistan Rupee"), I18N_NOOP("PKR") },
03213     { "USD", I18N_NOOP("Palau"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
03214     { "PAB", I18N_NOOP("Panama"), I18N_NOOP("Balboa"), I18N_NOOP("PAB") },
03215     { "USD", I18N_NOOP("Panama"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
03216     { "PGK", I18N_NOOP("Papua New Guinea"), I18N_NOOP("Kina"), I18N_NOOP("PGK") },
03217     { "PYG", I18N_NOOP("Paraguay"), I18N_NOOP("Guarani"), I18N_NOOP("G") },
03218     { "PEN", I18N_NOOP("Peru"), I18N_NOOP("Nuevo Sol"), I18N_NOOP("PEN") },
03219     { "PHP", I18N_NOOP("Philippines"), I18N_NOOP("Philippine Peso"), I18N_NOOP("PHP") },
03220     { "NZD", I18N_NOOP("Pitcairn"), I18N_NOOP("New Zealand Dollar"), I18N_NOOP("NZD") },
03221     { "PLN", I18N_NOOP("Poland"), I18N_NOOP("Zloty"), I18N_NOOP("zt") },
03222     { "EUR", I18N_NOOP("Portugal"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
03223     { "PTE", I18N_NOOP("Portugal"), I18N_NOOP("Escudo"), I18N_NOOP("Esc.") },
03224     { "USD", I18N_NOOP("Puerto Rico"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
03225     { "QAR", I18N_NOOP("Qatar"), I18N_NOOP("Qatari Rial"), I18N_NOOP("QAR") },
03226     { "ROL", I18N_NOOP("Romania"), I18N_NOOP("Leu"), I18N_NOOP("LEI") },
03227     { "RUR", I18N_NOOP("Russian Federation"), I18N_NOOP("Russian Ruble"), I18N_NOOP("RUR") },
03228     { "RUB", I18N_NOOP("Russian Federation"), I18N_NOOP("Russian Ruble"), I18N_NOOP("RUB") },
03229     { "RWF", I18N_NOOP("Rwanda"), I18N_NOOP("Rwanda Franc"), I18N_NOOP("RWF") },
03230     { "SHP", I18N_NOOP("Saint Helena"), I18N_NOOP("Saint Helena Pound"), I18N_NOOP("SHP") },
03231     { "XCD", I18N_NOOP("Saint Kitts And Nevis"), I18N_NOOP("East Caribbean Dollar"), I18N_NOOP("XCD") },
03232     { "XCD", I18N_NOOP("Saint Lucia"), I18N_NOOP("East Caribbean Dollar"), I18N_NOOP("XCD") },
03233     { "EUR", I18N_NOOP("Saint Pierre And Miquelon"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
03234     { "XCD", I18N_NOOP("Saint Vincent And The Grenadines"), I18N_NOOP("East Caribbean Dollar"), I18N_NOOP("XCD") },
03235     { "WST", I18N_NOOP("Samoa"), I18N_NOOP("Tala"), I18N_NOOP("WST") },
03236     { "EUR", I18N_NOOP("San Marino"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
03237     { "STD", I18N_NOOP("Sao Tome And Principe"), I18N_NOOP("Dobra"), I18N_NOOP("STD") },
03238     { "SAR", I18N_NOOP("Saudi Arabia"), I18N_NOOP("Saudi Riyal"), I18N_NOOP("SAR") },
03239     { "XOF", I18N_NOOP("Senegal"), I18N_NOOP("CFA Franc BCEAO"), I18N_NOOP("XOF") },
03240     { "SCR", I18N_NOOP("Seychelles"), I18N_NOOP("Seychelles Rupee"), I18N_NOOP("SCR") },
03241     { "SLL", I18N_NOOP("Sierra Leone"), I18N_NOOP("Leone"), I18N_NOOP("SLL") },
03242     { "SGD", I18N_NOOP("Singapore"), I18N_NOOP("Singapore Dollar"), I18N_NOOP("SGD") },
03243     { "SKK", I18N_NOOP("Slovakia"), I18N_NOOP("Slovak Koruna"), I18N_NOOP("Sk") },
03244     { "SIT", I18N_NOOP("Slovenia"), I18N_NOOP("Tolar"), I18N_NOOP("SIT") },
03245     { "SBD", I18N_NOOP("Solomon Islands"), I18N_NOOP("Solomon Islands Dollar"), I18N_NOOP("SBD") },
03246     { "SOS", I18N_NOOP("Somalia"), I18N_NOOP("Somali Shilling"), I18N_NOOP("SOS") },
03247     { "ZAR", I18N_NOOP("South Africa"), I18N_NOOP("Rand"), I18N_NOOP("R") },
03248     { "EUR", I18N_NOOP("Spain"), I18N_NOOP("Euro"), I18N_NOOP("EUR") },
03249     { "ESP", I18N_NOOP("Spain"), I18N_NOOP("Peseta"), I18N_NOOP("Pts") },
03250     { "LKR", I18N_NOOP("Sri Lanka"), I18N_NOOP("Sri Lanka Rupee"), I18N_NOOP("LKR") },
03251     { "SDD", I18N_NOOP("Sudan"), I18N_NOOP("Sudanese Dinar"), I18N_NOOP("SDD") },
03252     { "SRG", I18N_NOOP("Suriname"), I18N_NOOP("Suriname Guilder"), I18N_NOOP("SRG") },
03253     { "NOK", I18N_NOOP("Svalbard And Jan Mayen"), I18N_NOOP("Norwegian Krone"), I18N_NOOP("NOK") },
03254     { "SZL", I18N_NOOP("Swaziland"), I18N_NOOP("Lilangeni"), I18N_NOOP("SZL") },
03255     { "SEK", I18N_NOOP("Sweden"), I18N_NOOP("Swedish Krona"), I18N_NOOP("kr") },
03256     { "CHF", I18N_NOOP("Switzerland"), I18N_NOOP("Swiss Franc"), I18N_NOOP("SFr.") },
03257     { "SYP", I18N_NOOP("Syrian Arab Republic"), I18N_NOOP("Syrian Pound"), I18N_NOOP("SYP") },
03258     { "TWD", I18N_NOOP("Taiwan, Province Of China"), I18N_NOOP("New Taiwan Dollar"), I18N_NOOP("TWD") },
03259     { "TJS", I18N_NOOP("Tajikistan"), I18N_NOOP("Somoni"), I18N_NOOP("TJS") },
03260     { "TZS", I18N_NOOP("Tanzania, United Republic Of"), I18N_NOOP("Tanzanian Shilling"), I18N_NOOP("TZS") },
03261     { "THB", I18N_NOOP("Thailand"), I18N_NOOP("Baht"), I18N_NOOP("THB") },
03262     { "XOF", I18N_NOOP("Togo"), I18N_NOOP("CFA Franc BCEAO"), I18N_NOOP("XOF") },
03263     { "NZD", I18N_NOOP("Tokelau"), I18N_NOOP("New Zealand Dollar"), I18N_NOOP("NZD") },
03264     { "TOP", I18N_NOOP("Tonga"), I18N_NOOP("Pa'anga"), I18N_NOOP("TOP") },
03265     { "TTD", I18N_NOOP("Trinidad And Tobago"), I18N_NOOP("Trinidad and Tobago Dollar"), I18N_NOOP("TT$") },
03266     { "TND", I18N_NOOP("Tunisia"), I18N_NOOP("Tunisian Dinar"), I18N_NOOP("TND") },
03267     { "TRL", I18N_NOOP("Turkey"), I18N_NOOP("Turkish Lira"), I18N_NOOP("TL") },
03268     { "TMM", I18N_NOOP("Turkmenistan"), I18N_NOOP("Manat"), I18N_NOOP("TMM") },
03269     { "USD", I18N_NOOP("Turks And Caicos Islands"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
03270     { "AUD", I18N_NOOP("Tuvalu"), I18N_NOOP("Australian Dollar"), I18N_NOOP("AUD") },
03271     { "UGX", I18N_NOOP("Uganda"), I18N_NOOP("Uganda Shilling"), I18N_NOOP("UGX") },
03272     { "UAH", I18N_NOOP("Ukraine"), I18N_NOOP("Hryvnia"), I18N_NOOP("UAH") },
03273     { "AED", I18N_NOOP("United Arab Emirates"), I18N_NOOP("UAE Dirham"), I18N_NOOP("AED") },
03274     { "GBP", I18N_NOOP("United Kingdom"), I18N_NOOP("Pound Sterling"), I18N_NOOP("GBP") },
03275     { "USD", I18N_NOOP("United States"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
03276     { "USN", I18N_NOOP("United States"), I18N_NOOP("US Dollar (Next day)"), I18N_NOOP("USN") },
03277     { "USS", I18N_NOOP("United States"), I18N_NOOP("US Dollar (Same day)"), I18N_NOOP("USS") },
03278     { "UYU", I18N_NOOP("Uruguay"), I18N_NOOP("Peso Uruguayo"), I18N_NOOP("NU$") },
03279     { "UZS", I18N_NOOP("Uzbekistan"), I18N_NOOP("Uzbekistan Sum"), I18N_NOOP("UZS") },
03280     { "VUV", I18N_NOOP("Vanuatu"), I18N_NOOP("Vatu"), I18N_NOOP("VUV") },
03281     { "VEB", I18N_NOOP("Venezuela"), I18N_NOOP("Bolivar"), I18N_NOOP("Bs") },
03282     { "VND", I18N_NOOP("Viet Nam"), I18N_NOOP("Dong"), I18N_NOOP("VND") },
03283     { "USD", I18N_NOOP("Virgin Islands"), I18N_NOOP("US Dollar"), I18N_NOOP("USD") },
03284     { "XPF", I18N_NOOP("Wallis And Futuna"), I18N_NOOP("CFP Franc"), I18N_NOOP("XPF") },
03285     { "MAD", I18N_NOOP("Western Sahara"), I18N_NOOP("Moroccan Dirham"), I18N_NOOP("MAD") },
03286     { "YER", I18N_NOOP("Yemen"), I18N_NOOP("Yemeni Rial"), I18N_NOOP("YER") },
03287     { "YUM", I18N_NOOP("Yugoslavia"), I18N_NOOP("Yugoslavian Dinar"), I18N_NOOP("YUM") },
03288     { "ZMK", I18N_NOOP("Zambia"), I18N_NOOP("Kwacha"), I18N_NOOP("ZMK") },
03289     { "ZWD", I18N_NOOP("Zimbabwe"), I18N_NOOP("Zimbabwe Dollar"), I18N_NOOP("ZWD") },
03290     { 0, 0, 0, 0}, // Last must be empty!
03291   };
03292 
03293 
03294   class CurrencyMap
03295   {
03296    public:
03297     CurrencyMap()
03298       : m_List(lMoney)
03299     {
03300     }
03301 
03302     // Those return the _untranslated_ strings from the above array
03303     QString getCode(int t) const
03304     {
03305       return QString::fromUtf8( m_List[t].code );
03306     }
03307 
03308     QString getCountry(int t) const
03309     {
03310       return QString::fromUtf8( m_List[t].country );
03311     }
03312 
03313     QString getName(int t) const
03314     {
03315       return QString::fromUtf8( m_List[t].name );
03316     }
03317 
03318     QString getDisplayCode(int t) const
03319     {
03320       return QString::fromUtf8( m_List[t].display );
03321     }
03322 
03323     int getIndex(const QString& code) const
03324     {
03325       int index = 0;
03326       while (m_List[index].code != 0 && m_List[index].code != code)
03327         ++index;
03328       return (m_List[index].code != 0) ? index : 1 /*undef*/;
03329     }
03330 
03331    private:
03332     const Money * m_List;
03333   };
03334 
03335   const CurrencyMap gCurrencyMap;
03336   const Money * gMoneyList(lMoney);
03337 }
03338 
03339 
03340 using namespace Currency_LNS;
03341 
03342 Currency::Currency()
03343   : m_type( 0 )
03344 {
03345 }
03346 
03347 Currency::~Currency()
03348 {
03349 }
03350 
03351 Currency::Currency(int index)
03352   : m_type( index ),
03353     m_code( gCurrencyMap.getCode( index ) )
03354 {
03355 }
03356 
03357 Currency::Currency(int index, QString const & code)
03358   : m_type ( 1 ), // unspec
03359     m_code( code )
03360 {
03361   if ( gCurrencyMap.getCode( index ) == code )
03362     m_type = index;
03363 }
03364 
03365 Currency::Currency(QString const & code, currencyFormat format)
03366   : m_type( 1 ), // unspec
03367     m_code( code )
03368 {
03369   if ( format == Gnumeric )
03370   {
03371     // I use QChar(c,r) here so that this file can be opened in any encoding...
03372     if ( code.find( QChar( 172, 32 ) ) != -1 )      // Euro sign
03373       m_code = QChar( 172, 32 );
03374     else if ( code.find( QChar( 163, 0 ) ) != -1 )  // Pound sign
03375       m_code = QChar( 163, 0 );
03376     else if ( code.find( QChar( 165, 0 ) ) != -1 )  // Yen sign
03377       m_code = QChar( 165, 0 );
03378     else if ( code[0] == '[' && code[1] == '$' )
03379     {
03380       int n = code.find(']');
03381       if (n != -1)
03382       {
03383         m_code = code.mid( 2, n - 2 );
03384       }
03385       else
03386       {
03387         m_type = 0;
03388       }
03389     }
03390     else if ( code.find( '$' ) != -1 )
03391       m_code = "$";
03392   } // end gnumeric
03393   m_type = gCurrencyMap.getIndex( m_code );
03394 }
03395 
03396 Currency & Currency::operator=(int type)
03397 {
03398   m_type = type;
03399   m_code = gCurrencyMap.getCode( m_type );
03400 
03401   return *this;
03402 }
03403 
03404 Currency & Currency::operator=(char const * code)
03405 {
03406   m_type = 1;
03407   m_code = code;
03408 
03409   return *this;
03410 }
03411 
03412 bool Currency::operator==(Currency const & cur) const
03413 {
03414   if ( m_type == cur.m_type )
03415     return true;
03416 
03417   if ( m_code == cur.m_code )
03418     return true;
03419 
03420   return false;
03421 }
03422 
03423 bool Currency::operator==(int type) const
03424 {
03425   if ( m_type == type )
03426     return true;
03427 
03428   return false;
03429 }
03430 
03431 Currency::operator int() const
03432 {
03433   return m_type;
03434 }
03435 
03436 QString Currency::getCode() const
03437 {
03438   return m_code;
03439 }
03440 
03441 QString Currency::getCountry() const
03442 {
03443   return gCurrencyMap.getCountry( m_type );
03444 }
03445 
03446 QString Currency::getName() const
03447 {
03448   return gCurrencyMap.getName( m_type );
03449 }
03450 
03451 QString Currency::getDisplayCode() const
03452 {
03453   return gMoneyList[m_type].display;
03454 }
03455 
03456 int Currency::getIndex() const
03457 {
03458   return m_type;
03459 }
03460 
03461 QString Currency::getExportCode( currencyFormat format ) const
03462 {
03463   if ( format == Gnumeric )
03464   {
03465     if ( m_code.length() == 1 ) // symbol
03466       return m_code;
03467 
03468     QString ret( "[$");
03469     ret += m_code;
03470     ret += "]";
03471 
03472     return ret;
03473   }
03474 
03475   return m_code;
03476 }
03477 
03478 QString Currency::getChooseString( int type, bool & ok )
03479 {
03480   if ( !gMoneyList[type].country )
03481   {
03482     ok = false;
03483     return QString::null;
03484   }
03485   if ( type < 24 )
03486   {
03487     QString ret( i18n( gMoneyList[type].name ) );
03488     if ( gMoneyList[type].country[0] )
03489     {
03490       ret += " (";
03491       ret += i18n( gMoneyList[type].country );
03492       ret += ")";
03493     }
03494     return ret;
03495   }
03496   else
03497   {
03498     QString ret( i18n( gMoneyList[type].country ) );
03499     if ( gMoneyList[type].name[0] )
03500     {
03501       ret += " (";
03502       ret += i18n( gMoneyList[type].name );
03503       ret += ")";
03504     }
03505     return ret;
03506   }
03507 }
03508 
03509 QString Currency::getDisplaySymbol( int type )
03510 {
03511   return i18n( gMoneyList[type].display );
03512 }
03513 
03514 // Currently unused
03515 QString Currency::getCurrencyCode( int type )
03516 {
03517   return QString::fromUtf8( gMoneyList[type].code );
03518 }
03519 
03520 #undef UPDATE_BEGIN
03521 #undef UPDATE_END
KDE Home | KDE Accessibility Home | Description of Access Keys