LCOV - code coverage report
Current view: top level - sw/source/core/fields - tblcalc.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 3 106 2.8 %
Date: 2012-08-25 Functions: 1 16 6.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 116 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <switerator.hxx>
      31                 :            : #include <cntfrm.hxx>
      32                 :            : #include <doc.hxx>
      33                 :            : #include <pam.hxx>      // fuer GetBodyTxtNode
      34                 :            : #include <ndtxt.hxx>
      35                 :            : #include <fmtfld.hxx>
      36                 :            : #include <txtfld.hxx>
      37                 :            : #include <expfld.hxx>
      38                 :            : #include <docfld.hxx>   // fuer _SetGetExpFld
      39                 :            : #include <unofldmid.h>
      40                 :            : 
      41                 :            : using namespace ::com::sun::star;
      42                 :            : using ::rtl::OUString;
      43                 :            : 
      44                 :            : 
      45                 :       1549 : SwTblFieldType::SwTblFieldType(SwDoc* pDocPtr)
      46                 :       1549 :     : SwValueFieldType( pDocPtr, RES_TABLEFLD )
      47                 :       1549 : {}
      48                 :            : 
      49                 :            : 
      50                 :          0 : SwFieldType* SwTblFieldType::Copy() const
      51                 :            : {
      52         [ #  # ]:          0 :     return new SwTblFieldType(GetDoc());
      53                 :            : }
      54                 :            : 
      55                 :            : 
      56                 :            : 
      57                 :          0 : void SwTblField::CalcField( SwTblCalcPara& rCalcPara )
      58                 :            : {
      59         [ #  # ]:          0 :     if( rCalcPara.rCalc.IsCalcError() )     // ist schon Fehler gesetzt ?
      60                 :          0 :         return;
      61                 :            : 
      62                 :            :     // erzeuge aus den BoxNamen die Pointer
      63         [ #  # ]:          0 :     BoxNmToPtr( rCalcPara.pTbl );
      64         [ #  # ]:          0 :     String sFml( MakeFormula( rCalcPara ));
      65 [ #  # ][ #  # ]:          0 :     SetValue( rCalcPara.rCalc.Calculate( sFml ).GetDouble() );
         [ #  # ][ #  # ]
      66         [ #  # ]:          0 :     ChgValid( !rCalcPara.IsStackOverFlow() );       // ist der Wert wieder gueltig?
      67                 :            : }
      68                 :            : 
      69                 :            : 
      70                 :            : 
      71                 :          0 : SwTblField::SwTblField( SwTblFieldType* pInitType, const String& rFormel,
      72                 :            :                         sal_uInt16 nType, sal_uLong nFmt )
      73                 :            :     : SwValueField( pInitType, nFmt ), SwTableFormula( rFormel ),
      74 [ #  # ][ #  # ]:          0 :     nSubType(nType)
      75                 :            : {
      76         [ #  # ]:          0 :     sExpand = rtl::OUString('0');
      77                 :          0 : }
      78                 :            : 
      79                 :            : 
      80                 :          0 : SwField* SwTblField::Copy() const
      81                 :            : {
      82                 :          0 :     SwTblField* pTmp = new SwTblField( (SwTblFieldType*)GetTyp(),
      83         [ #  # ]:          0 :                                         SwTableFormula::GetFormula(), nSubType, GetFormat() );
      84                 :          0 :     pTmp->sExpand     = sExpand;
      85         [ #  # ]:          0 :     pTmp->SwValueField::SetValue(GetValue());
      86                 :          0 :     pTmp->SwTableFormula::operator=( *this );
      87                 :          0 :     pTmp->SetAutomaticLanguage(IsAutomaticLanguage());
      88                 :          0 :     return pTmp;
      89                 :            : }
      90                 :            : 
      91                 :            : 
      92                 :          0 : String SwTblField::GetFieldName() const
      93                 :            : {
      94                 :          0 :     String aStr(GetTyp()->GetName());
      95         [ #  # ]:          0 :     aStr += ' ';
      96 [ #  # ][ #  # ]:          0 :     aStr += const_cast<SwTblField *>(this)->GetCommand();
                 [ #  # ]
      97                 :          0 :     return aStr;
      98                 :            : }
      99                 :            : 
     100                 :            : // suche den TextNode, in dem das Feld steht
     101                 :          0 : const SwNode* SwTblField::GetNodeOfFormula() const
     102                 :            : {
     103         [ #  # ]:          0 :     if( !GetTyp()->GetDepends() )
     104                 :          0 :         return 0;
     105                 :            : 
     106         [ #  # ]:          0 :     SwIterator<SwFmtFld,SwFieldType> aIter( *GetTyp() );
     107 [ #  # ][ #  # ]:          0 :     for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
                 [ #  # ]
     108         [ #  # ]:          0 :             if( this == pFmtFld->GetFld() )
     109         [ #  # ]:          0 :                 return (SwTxtNode*)&pFmtFld->GetTxtFld()->GetTxtNode();
     110         [ #  # ]:          0 :     return 0;
     111                 :            : }
     112                 :            : 
     113                 :          0 : String SwTblField::GetCommand()
     114                 :            : {
     115         [ #  # ]:          0 :     if (EXTRNL_NAME != GetNameType())
     116                 :            :     {
     117                 :          0 :         SwNode const*const pNd = GetNodeOfFormula();
     118         [ #  # ]:          0 :         SwTableNode const*const pTblNd = (pNd) ? pNd->FindTableNode() : 0;
     119         [ #  # ]:          0 :         if (pTblNd)
     120                 :            :         {
     121                 :          0 :             PtrToBoxNm( &pTblNd->GetTable() );
     122                 :            :         }
     123                 :            :     }
     124                 :          0 :     return (EXTRNL_NAME == GetNameType())
     125                 :          0 :         ? SwTableFormula::GetFormula()
     126         [ #  # ]:          0 :         : String();
     127                 :            : }
     128                 :            : 
     129                 :          0 : String SwTblField::Expand() const
     130                 :            : {
     131                 :          0 :     String aStr;
     132         [ #  # ]:          0 :     if (nSubType & nsSwExtendedSubType::SUB_CMD)
     133                 :            :     {
     134 [ #  # ][ #  # ]:          0 :         aStr = const_cast<SwTblField *>(this)->GetCommand();
                 [ #  # ]
     135                 :            :     }
     136                 :            :     else
     137                 :            :     {
     138         [ #  # ]:          0 :         aStr = sExpand;
     139         [ #  # ]:          0 :         if(nSubType & nsSwGetSetExpType::GSE_STRING)
     140                 :            :         {
     141                 :            :             // es ist ein String
     142         [ #  # ]:          0 :             aStr = sExpand;
     143         [ #  # ]:          0 :             aStr.Erase( 0,1 );
     144         [ #  # ]:          0 :             aStr.Erase( aStr.Len()-1, 1 );
     145                 :            :         }
     146                 :            :     }
     147                 :          0 :     return aStr;
     148                 :            : }
     149                 :            : 
     150                 :          0 : sal_uInt16 SwTblField::GetSubType() const
     151                 :            : {
     152                 :          0 :     return nSubType;
     153                 :            : }
     154                 :            : 
     155                 :          0 : void SwTblField::SetSubType(sal_uInt16 nType)
     156                 :            : {
     157                 :          0 :     nSubType = nType;
     158                 :          0 : }
     159                 :            : 
     160                 :            : 
     161                 :          0 : void SwTblField::SetValue( const double& rVal )
     162                 :            : {
     163                 :          0 :     SwValueField::SetValue(rVal);
     164         [ #  # ]:          0 :     sExpand = ((SwValueFieldType*)GetTyp())->ExpandValue(rVal, GetFormat(), GetLanguage());
     165                 :          0 : }
     166                 :            : 
     167                 :            : /*--------------------------------------------------------------------
     168                 :            :     Beschreibung: Parameter setzen
     169                 :            :  --------------------------------------------------------------------*/
     170                 :            : 
     171                 :            : 
     172                 :          0 : rtl::OUString SwTblField::GetPar2() const
     173                 :            : {
     174                 :          0 :     return SwTableFormula::GetFormula();
     175                 :            : }
     176                 :            : 
     177                 :            : 
     178                 :          0 : void SwTblField::SetPar2(const rtl::OUString& rStr)
     179                 :            : {
     180         [ #  # ]:          0 :     SetFormula( rStr );
     181                 :          0 : }
     182                 :            : 
     183                 :          0 : bool SwTblField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
     184                 :            : {
     185                 :          0 :     bool bRet = true;
     186   [ #  #  #  #  :          0 :     switch ( nWhichId )
                      # ]
     187                 :            :     {
     188                 :            :     case FIELD_PROP_PAR2:
     189                 :            :         {
     190                 :          0 :             sal_uInt16 nOldSubType = nSubType;
     191                 :          0 :             SwTblField* pThis = (SwTblField*)this;
     192                 :          0 :             pThis->nSubType |= nsSwExtendedSubType::SUB_CMD;
     193 [ #  # ][ #  # ]:          0 :             rAny <<= rtl::OUString( Expand() );
     194                 :          0 :             pThis->nSubType = nOldSubType;
     195                 :            :         }
     196                 :          0 :         break;
     197                 :            :     case FIELD_PROP_BOOL1:
     198                 :            :         {
     199                 :          0 :             sal_Bool bFormula = 0 != (nsSwExtendedSubType::SUB_CMD & nSubType);
     200         [ #  # ]:          0 :             rAny.setValue(&bFormula, ::getBooleanCppuType());
     201                 :            :         }
     202                 :          0 :         break;
     203                 :            :     case FIELD_PROP_PAR1:
     204         [ #  # ]:          0 :         rAny <<= rtl::OUString(GetExpStr());
     205                 :          0 :         break;
     206                 :            :     case FIELD_PROP_FORMAT:
     207         [ #  # ]:          0 :         rAny <<= (sal_Int32)GetFormat();
     208                 :          0 :         break;
     209                 :            :     default:
     210                 :          0 :         bRet = false;
     211                 :            :     }
     212                 :          0 :     return bRet;
     213                 :            : }
     214                 :            : 
     215                 :          0 : bool SwTblField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     216                 :            : {
     217                 :          0 :     bool bRet = true;
     218         [ #  # ]:          0 :     String sTmp;
     219   [ #  #  #  #  :          0 :     switch ( nWhichId )
                      # ]
     220                 :            :     {
     221                 :            :     case FIELD_PROP_PAR2:
     222 [ #  # ][ #  # ]:          0 :         SetFormula( ::GetString( rAny, sTmp ));
     223                 :          0 :         break;
     224                 :            :     case FIELD_PROP_BOOL1:
     225         [ #  # ]:          0 :         if(*(sal_Bool*)rAny.getValue())
     226                 :          0 :             nSubType = nsSwGetSetExpType::GSE_FORMULA|nsSwExtendedSubType::SUB_CMD;
     227                 :            :         else
     228                 :          0 :             nSubType = nsSwGetSetExpType::GSE_FORMULA;
     229                 :          0 :         break;
     230                 :            :     case FIELD_PROP_PAR1:
     231 [ #  # ][ #  # ]:          0 :         ChgExpStr( ::GetString( rAny, sTmp ));
     232                 :          0 :         break;
     233                 :            :     case FIELD_PROP_FORMAT:
     234                 :            :         {
     235                 :          0 :             sal_Int32 nTmp = 0;
     236                 :          0 :             rAny >>= nTmp;
     237                 :          0 :             SetFormat(nTmp);
     238                 :            :         }
     239                 :          0 :         break;
     240                 :            :     default:
     241                 :          0 :         bRet = false;
     242                 :            :     }
     243         [ #  # ]:          0 :     return bRet;
     244                 :            : }
     245                 :            : 
     246                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10