kspread Library API Documentation

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