LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter/xfilter - xfnumberstyle.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 61 179 34.1 %
Date: 2012-08-25 Functions: 6 9 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 38 236 16.1 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  *  The Contents of this file are made available subject to the terms of
       5                 :            :  *  either of the following licenses
       6                 :            :  *
       7                 :            :  *         - GNU Lesser General Public License Version 2.1
       8                 :            :  *         - Sun Industry Standards Source License Version 1.1
       9                 :            :  *
      10                 :            :  *  Sun Microsystems Inc., October, 2000
      11                 :            :  *
      12                 :            :  *  GNU Lesser General Public License Version 2.1
      13                 :            :  *  =============================================
      14                 :            :  *  Copyright 2000 by Sun Microsystems, Inc.
      15                 :            :  *  901 San Antonio Road, Palo Alto, CA 94303, USA
      16                 :            :  *
      17                 :            :  *  This library is free software; you can redistribute it and/or
      18                 :            :  *  modify it under the terms of the GNU Lesser General Public
      19                 :            :  *  License version 2.1, as published by the Free Software Foundation.
      20                 :            :  *
      21                 :            :  *  This library is distributed in the hope that it will be useful,
      22                 :            :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      23                 :            :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      24                 :            :  *  Lesser General Public License for more details.
      25                 :            :  *
      26                 :            :  *  You should have received a copy of the GNU Lesser General Public
      27                 :            :  *  License along with this library; if not, write to the Free Software
      28                 :            :  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      29                 :            :  *  MA  02111-1307  USA
      30                 :            :  *
      31                 :            :  *
      32                 :            :  *  Sun Industry Standards Source License Version 1.1
      33                 :            :  *  =================================================
      34                 :            :  *  The contents of this file are subject to the Sun Industry Standards
      35                 :            :  *  Source License Version 1.1 (the "License"); You may not use this file
      36                 :            :  *  except in compliance with the License. You may obtain a copy of the
      37                 :            :  *  License at http://www.openoffice.org/license.html.
      38                 :            :  *
      39                 :            :  *  Software provided under this License is provided on an "AS IS" basis,
      40                 :            :  *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
      41                 :            :  *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
      42                 :            :  *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
      43                 :            :  *  See the License for the specific provisions governing your rights and
      44                 :            :  *  obligations concerning the Software.
      45                 :            :  *
      46                 :            :  *  The Initial Developer of the Original Code is: IBM Corporation
      47                 :            :  *
      48                 :            :  *  Copyright: 2008 by IBM Corporation
      49                 :            :  *
      50                 :            :  *  All Rights Reserved.
      51                 :            :  *
      52                 :            :  *  Contributor(s): _______________________________________
      53                 :            :  *
      54                 :            :  *
      55                 :            :  ************************************************************************/
      56                 :            : /*************************************************************************
      57                 :            :  * @file
      58                 :            :  * Number style for table cell.
      59                 :            :  ************************************************************************/
      60                 :            : #include    "xfnumberstyle.hxx"
      61                 :            : 
      62                 :        135 : XFNumberStyle::XFNumberStyle():m_aColor(0,0,0),m_aNegativeColor(255,0,0)
      63                 :            : {
      64                 :        135 :     m_eType = enumXFNumberNumber;
      65                 :        135 :     m_nDecimalDigits = 0;
      66                 :        135 :     m_nMinInteger = 1;
      67                 :        135 :     m_nMinExponent = 2;
      68                 :        135 :     m_bGroup = sal_False;
      69                 :        135 :     m_bRedIfNegative = sal_False;
      70                 :        135 :     m_bCurrencySymbolPost = sal_False;
      71                 :        135 : }
      72                 :            : 
      73                 :       1735 : enumXFStyle XFNumberStyle::GetStyleFamily()
      74                 :            : {
      75                 :       1735 :     return enumXFStyleNumber;
      76                 :            : }
      77                 :            : 
      78                 :        130 : sal_Bool XFNumberStyle::Equal(IXFStyle *pStyle)
      79                 :            : {
      80 [ +  - ][ +  + ]:        130 :     if( !pStyle || pStyle->GetStyleFamily() != enumXFStyleNumber )
                 [ +  + ]
      81                 :         15 :         return sal_False;
      82                 :        115 :     XFNumberStyle *pOther = (XFNumberStyle*)pStyle;
      83         [ -  + ]:        115 :     if( !pOther )
      84                 :          0 :         return sal_False;
      85                 :            : 
      86         [ -  + ]:        115 :     if( m_eType != pOther->m_eType )
      87                 :          0 :         return sal_False;
      88         [ -  + ]:        115 :     if( m_nDecimalDigits != pOther->m_nDecimalDigits )
      89                 :          0 :         return sal_False;
      90         [ -  + ]:        115 :     if( m_nMinInteger != pOther->m_nMinInteger )
      91                 :          0 :         return sal_False;
      92         [ -  + ]:        115 :     if( m_bRedIfNegative != pOther->m_bRedIfNegative )
      93                 :          0 :         return sal_False;
      94         [ -  + ]:        115 :     if( m_bGroup != pOther->m_bGroup )
      95                 :          0 :         return sal_False;
      96         [ -  + ]:        115 :     if( m_aColor != pOther->m_aColor )
      97                 :          0 :         return sal_False;
      98         [ -  + ]:        115 :     if( m_strPrefix != pOther->m_strPrefix )
      99                 :          0 :         return sal_False;
     100         [ -  + ]:        115 :     if( m_strSuffix != pOther->m_strSuffix )
     101                 :          0 :         return sal_False;
     102                 :            : 
     103                 :            :     //When category of number format is scientific, the number can not be displayed normally in table.
     104         [ -  + ]:        115 :     if ( m_nMinExponent != pOther->m_nMinExponent )
     105                 :          0 :         return sal_False;
     106                 :            : 
     107         [ +  - ]:        115 :     if( m_bRedIfNegative )
     108                 :            :     {
     109         [ -  + ]:        115 :         if( m_aNegativeColor != pOther->m_aNegativeColor )
     110                 :          0 :             return sal_False;
     111         [ -  + ]:        115 :         if( m_strNegativePrefix != pOther->m_strNegativePrefix )
     112                 :          0 :             return sal_False;
     113         [ -  + ]:        115 :         if( m_strNegativeSuffix != pOther->m_strNegativeSuffix )
     114                 :          0 :             return sal_False;
     115                 :            :     }
     116                 :            : 
     117         [ -  + ]:        115 :     if( m_eType == enuMXFNumberCurrency )
     118                 :            :     {
     119         [ #  # ]:          0 :         if( m_bCurrencySymbolPost != pOther->m_bCurrencySymbolPost )
     120                 :          0 :             return sal_False;
     121         [ #  # ]:          0 :         if( m_strCurrencySymbol != pOther->m_strCurrencySymbol )
     122                 :          0 :             return sal_False;
     123                 :            :     }
     124                 :            : 
     125                 :        130 :     return sal_True;
     126                 :            : }
     127                 :            : 
     128                 :         15 : void XFNumberStyle::ToXml(IXFStream *pStrm)
     129                 :            : {
     130                 :            :     // for Text content number format
     131         [ +  - ]:         15 :     if (m_eType == enumXFText)
     132                 :            :     {
     133                 :         15 :         ToXml_StartElement(pStrm);
     134                 :         15 :         ToXml_EndElement(pStrm);
     135                 :         15 :         return;
     136                 :            :     }
     137                 :            :     // END for Text content number format
     138                 :            : 
     139         [ #  # ]:          0 :     if( !m_bRedIfNegative )
     140                 :            :     {
     141                 :          0 :         ToXml_Normal(pStrm);
     142                 :            :     }
     143                 :            :     else
     144                 :            :     {
     145                 :          0 :         ToXml_Negative(pStrm);
     146                 :            :     }
     147                 :            : }
     148                 :            : 
     149                 :         15 : void XFNumberStyle::ToXml_StartElement(IXFStream *pStrm)
     150                 :            : {
     151                 :         15 :     IXFAttrList *pAttrList = pStrm->GetAttrList();
     152                 :         15 :     pAttrList->Clear();
     153                 :            : 
     154         [ +  - ]:         15 :     pAttrList->AddAttribute( A2OUSTR("style:name"), GetStyleName() );
     155         [ -  + ]:         15 :     if( !GetParentStyleName().isEmpty() )
     156         [ #  # ]:          0 :         pAttrList->AddAttribute(A2OUSTR("style:parent-style-name"),GetParentStyleName());
     157                 :            : 
     158         [ +  - ]:         15 :     pAttrList->AddAttribute( A2OUSTR("style:family"), A2OUSTR("data-style") );
     159                 :            : 
     160         [ -  + ]:         15 :     if( m_eType == enumXFNumberNumber )
     161                 :            :     {
     162         [ #  # ]:          0 :         pStrm->StartElement( A2OUSTR("number:number-style") );
     163                 :            :     }
     164         [ -  + ]:         15 :     else if( m_eType == enumXFNumberPercent )
     165                 :            :     {
     166         [ #  # ]:          0 :         pStrm->StartElement( A2OUSTR("number:percentage-style") );
     167                 :            :     }
     168         [ -  + ]:         15 :     else if( m_eType == enuMXFNumberCurrency )
     169                 :            :     {
     170         [ #  # ]:          0 :         pStrm->StartElement( A2OUSTR("number:currency-style") );
     171                 :            :     }
     172         [ -  + ]:         15 :     else if( m_eType == enumXFNumberScientific )
     173                 :            :     {
     174         [ #  # ]:          0 :         pStrm->StartElement( A2OUSTR("number:number-style") );
     175                 :            :     }
     176                 :            :     // for Text content number format
     177         [ +  - ]:         15 :     else if (m_eType == enumXFText)
     178                 :            :     {
     179         [ +  - ]:         15 :         pStrm->StartElement( A2OUSTR("number:text-content"));
     180                 :            :     }
     181                 :            :     // END for Text content number format
     182                 :            : 
     183                 :         15 : }
     184                 :            : 
     185                 :         15 : void XFNumberStyle::ToXml_EndElement(IXFStream *pStrm)
     186                 :            : {
     187                 :         15 :     IXFAttrList *pAttrList = pStrm->GetAttrList();
     188                 :         15 :     pAttrList->Clear();
     189                 :            : 
     190         [ +  - ]:         15 :     pAttrList->AddAttribute( A2OUSTR("style:name"), GetStyleName() );
     191         [ +  - ]:         15 :     pAttrList->AddAttribute( A2OUSTR("style:family"), A2OUSTR("data-style") );
     192                 :            : 
     193         [ -  + ]:         15 :     if( m_eType == enumXFNumberNumber )
     194                 :            :     {
     195         [ #  # ]:          0 :         pStrm->EndElement( A2OUSTR("number:number-style") );
     196                 :            :     }
     197         [ -  + ]:         15 :     else if( m_eType == enumXFNumberPercent )
     198                 :            :     {
     199         [ #  # ]:          0 :         pStrm->EndElement( A2OUSTR("number:percentage-style") );
     200                 :            :     }
     201         [ -  + ]:         15 :     else if( m_eType == enuMXFNumberCurrency )
     202                 :            :     {
     203         [ #  # ]:          0 :         pStrm->EndElement( A2OUSTR("number:currency-style") );
     204                 :            :     }
     205         [ -  + ]:         15 :     else if( m_eType == enumXFNumberScientific )
     206                 :            :     {
     207         [ #  # ]:          0 :         pStrm->EndElement( A2OUSTR("number:number-style") );
     208                 :            :     }
     209                 :            :     // for Text content number format
     210         [ +  - ]:         15 :     else if (m_eType == enumXFText)
     211                 :            :     {
     212         [ +  - ]:         15 :         pStrm->EndElement( A2OUSTR("number:text-content"));
     213                 :            :     }
     214                 :            :     // END for Text content number format
     215                 :            : 
     216                 :         15 : }
     217                 :          0 : void XFNumberStyle::ToXml_Normal(IXFStream *pStrm)
     218                 :            : {
     219                 :          0 :     ToXml_StartElement(pStrm);
     220                 :            : 
     221                 :          0 :     ToXml_Content(pStrm,sal_False);
     222                 :            : 
     223                 :          0 :     ToXml_EndElement(pStrm);
     224                 :          0 : }
     225                 :            : 
     226                 :          0 : void XFNumberStyle::ToXml_Negative(IXFStream *pStrm)
     227                 :            : {
     228         [ #  # ]:          0 :     IXFAttrList *pAttrList = pStrm->GetAttrList();
     229         [ #  # ]:          0 :     pAttrList->Clear();
     230                 :            : 
     231         [ #  # ]:          0 :     rtl::OUString strStyleName = GetStyleName();
     232                 :          0 :     rtl::OUString strGEStyle = strStyleName + A2OUSTR("PO");
     233                 :            : 
     234         [ #  # ]:          0 :     SetStyleName(strGEStyle);
     235         [ #  # ]:          0 :     ToXml_Normal(pStrm);
     236         [ #  # ]:          0 :     SetStyleName(strStyleName);
     237                 :            : 
     238         [ #  # ]:          0 :     ToXml_StartElement(pStrm);
     239                 :            : 
     240         [ #  # ]:          0 :     ToXml_Content(pStrm,sal_True);
     241                 :            : 
     242         [ #  # ]:          0 :     pAttrList->Clear();
     243         [ #  # ]:          0 :     pAttrList->AddAttribute( A2OUSTR("style:condition"), A2OUSTR("value()>=0") );
     244         [ #  # ]:          0 :     pAttrList->AddAttribute( A2OUSTR("style:apply-style-name"), strGEStyle );
     245         [ #  # ]:          0 :     pStrm->StartElement( A2OUSTR("style:map") );
     246         [ #  # ]:          0 :     pStrm->EndElement( A2OUSTR("style:map") );
     247                 :            : 
     248         [ #  # ]:          0 :     ToXml_EndElement(pStrm);
     249                 :          0 : }
     250                 :            : 
     251                 :          0 : void XFNumberStyle::ToXml_Content(IXFStream *pStrm, sal_Bool nagetive)
     252                 :            : {
     253                 :          0 :     IXFAttrList *pAttrList = pStrm->GetAttrList();
     254                 :          0 :     pAttrList->Clear();
     255                 :            :     //color:
     256         [ #  # ]:          0 :     if( !nagetive )
     257         [ #  # ]:          0 :         pAttrList->AddAttribute( A2OUSTR("fo:color"), m_aColor.ToString() );
     258                 :            :     else
     259         [ #  # ]:          0 :         pAttrList->AddAttribute( A2OUSTR("fo:color"), m_aNegativeColor.ToString() );
     260                 :            : 
     261         [ #  # ]:          0 :     pStrm->StartElement( A2OUSTR("style:properties") );
     262         [ #  # ]:          0 :     pStrm->EndElement( A2OUSTR("style:properties") );
     263                 :            : 
     264         [ #  # ]:          0 :     if( !nagetive )
     265                 :            :     {
     266         [ #  # ]:          0 :         if( !m_strPrefix.isEmpty() )
     267                 :            :         {
     268         [ #  # ]:          0 :             pStrm->StartElement( A2OUSTR("number:text") );
     269                 :          0 :             pStrm->Characters(m_strPrefix);
     270         [ #  # ]:          0 :             pStrm->EndElement( A2OUSTR("number:text") );
     271                 :            :         }
     272                 :            :     }
     273                 :            :     else
     274                 :            :     {
     275         [ #  # ]:          0 :         if( m_strNegativePrefix.isEmpty() )
     276                 :          0 :             m_strNegativePrefix = m_strPrefix;
     277         [ #  # ]:          0 :         if( !m_strNegativePrefix.isEmpty() )
     278                 :            :         {
     279         [ #  # ]:          0 :             pStrm->StartElement( A2OUSTR("number:text") );
     280                 :            :             // pStrm->Characters(m_strNegativePrefix);
     281         [ #  # ]:          0 :             pStrm->Characters(m_strNegativePrefix + A2OUSTR("-"));
     282         [ #  # ]:          0 :             pStrm->EndElement( A2OUSTR("number:text") );
     283                 :            :         }
     284                 :            :         else
     285                 :            :         {
     286         [ #  # ]:          0 :             pStrm->StartElement( A2OUSTR("number:text") );
     287         [ #  # ]:          0 :             pStrm->Characters(A2OUSTR("-"));
     288         [ #  # ]:          0 :             pStrm->EndElement( A2OUSTR("number:text") );
     289                 :            :         }
     290                 :            :     }
     291                 :            : 
     292 [ #  # ][ #  # ]:          0 :     if( m_eType == enuMXFNumberCurrency && !m_bCurrencySymbolPost )
     293                 :            :     {
     294         [ #  # ]:          0 :         if( !m_strCurrencySymbol.isEmpty() )
     295                 :            :         {
     296         [ #  # ]:          0 :             pStrm->StartElement( A2OUSTR("number:currency-symbol") );
     297                 :          0 :             pStrm->Characters(m_strCurrencySymbol);
     298         [ #  # ]:          0 :             pStrm->EndElement( A2OUSTR("number:currency-symbol") );
     299                 :            :         }
     300                 :            :     }
     301                 :            : 
     302                 :            :     //When category of number format is scientific, the number can not be displayed normally in table.
     303         [ #  # ]:          0 :     if ( m_eType == enumXFNumberScientific )
     304                 :            :     {
     305                 :          0 :         pAttrList->Clear();
     306         [ #  # ]:          0 :         pAttrList->AddAttribute(A2OUSTR("number:decimal-places"), Int32ToOUString(m_nDecimalDigits));
     307         [ #  # ]:          0 :         pAttrList->AddAttribute(A2OUSTR("number:min-integer-digits"), Int32ToOUString(m_nMinInteger));
     308         [ #  # ]:          0 :         pAttrList->AddAttribute(A2OUSTR("number:min-exponent-digits"), Int32ToOUString(m_nMinExponent));
     309         [ #  # ]:          0 :         pStrm->StartElement( A2OUSTR("number:scientific-number") );
     310         [ #  # ]:          0 :         pStrm->EndElement( A2OUSTR("number:scientific-number") );
     311                 :            :     }
     312                 :            :     else
     313                 :            :     {
     314                 :          0 :         pAttrList->Clear();
     315         [ #  # ]:          0 :         pAttrList->AddAttribute(A2OUSTR("number:decimal-places"),Int32ToOUString(m_nDecimalDigits));
     316         [ #  # ]:          0 :         pAttrList->AddAttribute(A2OUSTR("number:min-integer-digits"),Int32ToOUString(m_nMinInteger));
     317                 :            : 
     318         [ #  # ]:          0 :         if( m_bGroup )
     319         [ #  # ]:          0 :             pAttrList->AddAttribute(A2OUSTR("number:grouping"),A2OUSTR("true"));
     320                 :            :         else
     321         [ #  # ]:          0 :             pAttrList->AddAttribute(A2OUSTR("number:grouping"),A2OUSTR("false"));
     322                 :            : 
     323         [ #  # ]:          0 :         pStrm->StartElement( A2OUSTR("number:number") );
     324         [ #  # ]:          0 :         pStrm->EndElement( A2OUSTR("number:number") );
     325                 :            :     }
     326                 :            : 
     327 [ #  # ][ #  # ]:          0 :     if( m_eType == enuMXFNumberCurrency && m_bCurrencySymbolPost )
     328                 :            :     {
     329         [ #  # ]:          0 :         if( !m_strCurrencySymbol.isEmpty() )
     330                 :            :         {
     331         [ #  # ]:          0 :             pStrm->StartElement( A2OUSTR("number:currency-symbol") );
     332                 :          0 :             pStrm->Characters(m_strCurrencySymbol);
     333         [ #  # ]:          0 :             pStrm->EndElement( A2OUSTR("number:currency-symbol") );
     334                 :            :         }
     335                 :            :     }
     336                 :            : 
     337         [ #  # ]:          0 :     if( !nagetive )
     338                 :            :     {
     339         [ #  # ]:          0 :         if( !m_strSuffix.isEmpty() )
     340                 :            :         {
     341         [ #  # ]:          0 :             pStrm->StartElement( A2OUSTR("number:text") );
     342                 :          0 :             pStrm->Characters(m_strSuffix);
     343         [ #  # ]:          0 :             pStrm->EndElement( A2OUSTR("number:text") );
     344                 :            :         }
     345                 :            :         else
     346                 :            :         {
     347         [ #  # ]:          0 :             if( m_eType == enumXFNumberPercent )
     348                 :            :             {
     349         [ #  # ]:          0 :                 pStrm->StartElement( A2OUSTR("number:text") );
     350         [ #  # ]:          0 :                 pStrm->Characters(A2OUSTR("%"));
     351         [ #  # ]:          0 :                 pStrm->EndElement( A2OUSTR("number:text") );
     352                 :            :             }
     353                 :            :         }
     354                 :            :     }
     355                 :            :     else
     356                 :            :     {
     357         [ #  # ]:          0 :         if( m_strNegativeSuffix.isEmpty() )
     358                 :          0 :             m_strNegativeSuffix = m_strSuffix;
     359         [ #  # ]:          0 :         if( !m_strNegativeSuffix.isEmpty() )
     360                 :            :         {
     361         [ #  # ]:          0 :             pStrm->StartElement( A2OUSTR("number:text") );
     362                 :          0 :             pStrm->Characters(m_strNegativeSuffix);
     363         [ #  # ]:          0 :             pStrm->EndElement( A2OUSTR("number:text") );
     364                 :            :         }
     365                 :            :         else
     366                 :            :         {
     367         [ #  # ]:          0 :             if( m_eType == enumXFNumberPercent )
     368                 :            :             {
     369         [ #  # ]:          0 :                 pStrm->StartElement( A2OUSTR("number:text") );
     370         [ #  # ]:          0 :                 pStrm->Characters(A2OUSTR("%"));
     371         [ #  # ]:          0 :                 pStrm->EndElement( A2OUSTR("number:text") );
     372                 :            :             }
     373                 :            :         }
     374                 :            :     }
     375                 :          0 : }
     376                 :            : 
     377                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10