LCOV - code coverage report
Current view: top level - sw/source/core/fields - tblcalc.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 101 0.0 %
Date: 2014-04-14 Functions: 0 16 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <switerator.hxx>
      21             : #include <cntfrm.hxx>
      22             : #include <doc.hxx>
      23             : #include <pam.hxx>
      24             : #include <ndtxt.hxx>
      25             : #include <fmtfld.hxx>
      26             : #include <txtfld.hxx>
      27             : #include <expfld.hxx>
      28             : #include <docfld.hxx>
      29             : #include <unofldmid.h>
      30             : 
      31             : using namespace ::com::sun::star;
      32             : 
      33           0 : SwTblFieldType::SwTblFieldType(SwDoc* pDocPtr)
      34           0 :     : SwValueFieldType( pDocPtr, RES_TABLEFLD )
      35           0 : {}
      36             : 
      37           0 : SwFieldType* SwTblFieldType::Copy() const
      38             : {
      39           0 :     return new SwTblFieldType(GetDoc());
      40             : }
      41             : 
      42           0 : void SwTblField::CalcField( SwTblCalcPara& rCalcPara )
      43             : {
      44           0 :     if( rCalcPara.rCalc.IsCalcError() ) // stop if there is already an error set
      45           0 :         return;
      46             : 
      47             :     // create pointers from box name
      48           0 :     BoxNmToPtr( rCalcPara.pTbl );
      49           0 :     OUString sFml( MakeFormula( rCalcPara ));
      50           0 :     SetValue( rCalcPara.rCalc.Calculate( sFml ).GetDouble() );
      51           0 :     ChgValid( !rCalcPara.IsStackOverflow() ); // is the value again valid?
      52             : }
      53             : 
      54           0 : SwTblField::SwTblField( SwTblFieldType* pInitType, const OUString& rFormel,
      55             :                         sal_uInt16 nType, sal_uLong nFmt )
      56             :     : SwValueField( pInitType, nFmt ), SwTableFormula( rFormel ),
      57           0 :     nSubType(nType)
      58             : {
      59           0 :     sExpand = OUString('0');
      60           0 : }
      61             : 
      62           0 : SwField* SwTblField::Copy() const
      63             : {
      64           0 :     SwTblField* pTmp = new SwTblField( (SwTblFieldType*)GetTyp(),
      65           0 :                                         SwTableFormula::GetFormula(), nSubType, GetFormat() );
      66           0 :     pTmp->sExpand     = sExpand;
      67           0 :     pTmp->SwValueField::SetValue(GetValue());
      68           0 :     pTmp->SwTableFormula::operator=( *this );
      69           0 :     pTmp->SetAutomaticLanguage(IsAutomaticLanguage());
      70           0 :     return pTmp;
      71             : }
      72             : 
      73           0 : OUString SwTblField::GetFieldName() const
      74             : {
      75           0 :     return GetTyp()->GetName() + " " + const_cast<SwTblField *>(this)->GetCommand();
      76             : }
      77             : 
      78             : /// search TextNode containing this field
      79           0 : const SwNode* SwTblField::GetNodeOfFormula() const
      80             : {
      81           0 :     if( !GetTyp()->GetDepends() )
      82           0 :         return 0;
      83             : 
      84           0 :     SwIterator<SwFmtFld,SwFieldType> aIter( *GetTyp() );
      85           0 :     for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
      86           0 :             if( this == pFmtFld->GetField() )
      87           0 :                 return (SwTxtNode*)&pFmtFld->GetTxtFld()->GetTxtNode();
      88           0 :     return 0;
      89             : }
      90             : 
      91           0 : OUString SwTblField::GetCommand()
      92             : {
      93           0 :     if (EXTRNL_NAME != GetNameType())
      94             :     {
      95           0 :         SwNode const*const pNd = GetNodeOfFormula();
      96           0 :         SwTableNode const*const pTblNd = (pNd) ? pNd->FindTableNode() : 0;
      97           0 :         if (pTblNd)
      98             :         {
      99           0 :             PtrToBoxNm( &pTblNd->GetTable() );
     100             :         }
     101             :     }
     102           0 :     return (EXTRNL_NAME == GetNameType())
     103             :         ? OUString(SwTableFormula::GetFormula())
     104           0 :         : OUString();
     105             : }
     106             : 
     107           0 : OUString SwTblField::Expand() const
     108             : {
     109           0 :     if (nSubType & nsSwExtendedSubType::SUB_CMD)
     110             :     {
     111           0 :         return const_cast<SwTblField *>(this)->GetCommand();
     112             :     }
     113             : 
     114           0 :     if(nSubType & nsSwGetSetExpType::GSE_STRING)
     115             :     {
     116             :         // es ist ein String
     117           0 :         return sExpand.copy(1, sExpand.getLength()-2);
     118             :     }
     119             : 
     120           0 :     return sExpand;
     121             : }
     122             : 
     123           0 : sal_uInt16 SwTblField::GetSubType() const
     124             : {
     125           0 :     return nSubType;
     126             : }
     127             : 
     128           0 : void SwTblField::SetSubType(sal_uInt16 nType)
     129             : {
     130           0 :     nSubType = nType;
     131           0 : }
     132             : 
     133           0 : void SwTblField::SetValue( const double& rVal )
     134             : {
     135           0 :     SwValueField::SetValue(rVal);
     136           0 :     sExpand = ((SwValueFieldType*)GetTyp())->ExpandValue(rVal, GetFormat(), GetLanguage());
     137           0 : }
     138             : 
     139           0 : OUString SwTblField::GetPar2() const
     140             : {
     141           0 :     return SwTableFormula::GetFormula();
     142             : }
     143             : 
     144           0 : void SwTblField::SetPar2(const OUString& rStr)
     145             : {
     146           0 :     SetFormula( rStr );
     147           0 : }
     148             : 
     149           0 : bool SwTblField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
     150             : {
     151           0 :     bool bRet = true;
     152           0 :     switch ( nWhichId )
     153             :     {
     154             :     case FIELD_PROP_PAR2:
     155             :         {
     156           0 :             sal_uInt16 nOldSubType = nSubType;
     157           0 :             SwTblField* pThis = (SwTblField*)this;
     158           0 :             pThis->nSubType |= nsSwExtendedSubType::SUB_CMD;
     159           0 :             rAny <<= Expand();
     160           0 :             pThis->nSubType = nOldSubType;
     161             :         }
     162           0 :         break;
     163             :     case FIELD_PROP_BOOL1:
     164             :         {
     165           0 :             sal_Bool bFormula = 0 != (nsSwExtendedSubType::SUB_CMD & nSubType);
     166           0 :             rAny.setValue(&bFormula, ::getBooleanCppuType());
     167             :         }
     168           0 :         break;
     169             :     case FIELD_PROP_PAR1:
     170           0 :         rAny <<= GetExpStr();
     171           0 :         break;
     172             :     case FIELD_PROP_FORMAT:
     173           0 :         rAny <<= (sal_Int32)GetFormat();
     174           0 :         break;
     175             :     default:
     176           0 :         bRet = false;
     177             :     }
     178           0 :     return bRet;
     179             : }
     180             : 
     181           0 : bool SwTblField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     182             : {
     183           0 :     bool bRet = true;
     184           0 :     switch ( nWhichId )
     185             :     {
     186             :     case FIELD_PROP_PAR2:
     187             :         {
     188           0 :             OUString sTmp;
     189           0 :             rAny >>= sTmp;
     190           0 :             SetFormula( sTmp );
     191             :         }
     192           0 :         break;
     193             :     case FIELD_PROP_BOOL1:
     194           0 :         if(*(sal_Bool*)rAny.getValue())
     195           0 :             nSubType = nsSwGetSetExpType::GSE_FORMULA|nsSwExtendedSubType::SUB_CMD;
     196             :         else
     197           0 :             nSubType = nsSwGetSetExpType::GSE_FORMULA;
     198           0 :         break;
     199             :     case FIELD_PROP_PAR1:
     200             :         {
     201           0 :             OUString sTmp;
     202           0 :             rAny >>= sTmp;
     203           0 :             ChgExpStr( sTmp );
     204             :         }
     205           0 :         break;
     206             :     case FIELD_PROP_FORMAT:
     207             :         {
     208           0 :             sal_Int32 nTmp = 0;
     209           0 :             rAny >>= nTmp;
     210           0 :             SetFormat(nTmp);
     211             :         }
     212           0 :         break;
     213             :     default:
     214           0 :         bRet = false;
     215             :     }
     216           0 :     return bRet;
     217             : }
     218             : 
     219             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10