LCOV - code coverage report
Current view: top level - sw/source/core/fields - tblcalc.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 4 101 4.0 %
Date: 2015-06-13 12:38:46 Functions: 3 18 16.7 %
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 <calbck.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        2958 : SwTableFieldType::SwTableFieldType(SwDoc* pDocPtr)
      34        2958 :     : SwValueFieldType( pDocPtr, RES_TABLEFLD )
      35        2958 : {}
      36             : 
      37           0 : SwFieldType* SwTableFieldType::Copy() const
      38             : {
      39           0 :     return new SwTableFieldType(GetDoc());
      40             : }
      41             : 
      42           0 : void SwTableField::CalcField( SwTableCalcPara& 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.pTable );
      49           0 :     OUString sFormula( MakeFormula( rCalcPara ));
      50           0 :     SetValue( rCalcPara.rCalc.Calculate( sFormula ).GetDouble() );
      51           0 :     ChgValid( !rCalcPara.IsStackOverflow() ); // is the value again valid?
      52             : }
      53             : 
      54           0 : SwTableField::SwTableField( SwTableFieldType* pInitType, const OUString& rFormel,
      55             :                         sal_uInt16 nType, sal_uLong nFormat )
      56             :     : SwValueField( pInitType, nFormat ), SwTableFormula( rFormel ),
      57           0 :     nSubType(nType)
      58             : {
      59           0 :     sExpand = "0";
      60           0 : }
      61             : 
      62           0 : SwField* SwTableField::Copy() const
      63             : {
      64           0 :     SwTableField* pTmp = new SwTableField( static_cast<SwTableFieldType*>(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 SwTableField::GetFieldName() const
      74             : {
      75           0 :     return GetTyp()->GetName() + " " + const_cast<SwTableField *>(this)->GetCommand();
      76             : }
      77             : 
      78             : /// search TextNode containing this field
      79           0 : const SwNode* SwTableField::GetNodeOfFormula() const
      80             : {
      81           0 :     if( !GetTyp()->HasWriterListeners() )
      82           0 :         return 0;
      83             : 
      84           0 :     SwIterator<SwFormatField,SwFieldType> aIter( *GetTyp() );
      85           0 :     for( SwFormatField* pFormatField = aIter.First(); pFormatField; pFormatField = aIter.Next() )
      86           0 :             if( this == pFormatField->GetField() )
      87           0 :                 return &pFormatField->GetTextField()->GetTextNode();
      88           0 :     return 0;
      89             : }
      90             : 
      91           0 : OUString SwTableField::GetCommand()
      92             : {
      93           0 :     if (EXTRNL_NAME != GetNameType())
      94             :     {
      95           0 :         SwNode const*const pNd = GetNodeOfFormula();
      96           0 :         SwTableNode const*const pTableNd = (pNd) ? pNd->FindTableNode() : 0;
      97           0 :         if (pTableNd)
      98             :         {
      99           0 :             PtrToBoxNm( &pTableNd->GetTable() );
     100             :         }
     101             :     }
     102           0 :     return (EXTRNL_NAME == GetNameType())
     103             :         ? OUString(SwTableFormula::GetFormula())
     104           0 :         : OUString();
     105             : }
     106             : 
     107           0 : OUString SwTableField::Expand() const
     108             : {
     109           0 :     if (nSubType & nsSwExtendedSubType::SUB_CMD)
     110             :     {
     111           0 :         return const_cast<SwTableField *>(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 SwTableField::GetSubType() const
     124             : {
     125           0 :     return nSubType;
     126             : }
     127             : 
     128           0 : void SwTableField::SetSubType(sal_uInt16 nType)
     129             : {
     130           0 :     nSubType = nType;
     131           0 : }
     132             : 
     133           0 : void SwTableField::SetValue( const double& rVal )
     134             : {
     135           0 :     SwValueField::SetValue(rVal);
     136           0 :     sExpand = static_cast<SwValueFieldType*>(GetTyp())->ExpandValue(rVal, GetFormat(), GetLanguage());
     137           0 : }
     138             : 
     139           0 : OUString SwTableField::GetPar2() const
     140             : {
     141           0 :     return SwTableFormula::GetFormula();
     142             : }
     143             : 
     144           0 : void SwTableField::SetPar2(const OUString& rStr)
     145             : {
     146           0 :     SetFormula( rStr );
     147           0 : }
     148             : 
     149           0 : bool SwTableField::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 :             SwTableField* pThis = const_cast<SwTableField*>(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           0 :         rAny <<= 0 != (nsSwExtendedSubType::SUB_CMD & nSubType);
     165           0 :         break;
     166             :     case FIELD_PROP_PAR1:
     167           0 :         rAny <<= GetExpStr();
     168           0 :         break;
     169             :     case FIELD_PROP_FORMAT:
     170           0 :         rAny <<= (sal_Int32)GetFormat();
     171           0 :         break;
     172             :     default:
     173           0 :         bRet = false;
     174             :     }
     175           0 :     return bRet;
     176             : }
     177             : 
     178           0 : bool SwTableField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     179             : {
     180           0 :     bool bRet = true;
     181           0 :     switch ( nWhichId )
     182             :     {
     183             :     case FIELD_PROP_PAR2:
     184             :         {
     185           0 :             OUString sTmp;
     186           0 :             rAny >>= sTmp;
     187           0 :             SetFormula( sTmp );
     188             :         }
     189           0 :         break;
     190             :     case FIELD_PROP_BOOL1:
     191           0 :         if(*static_cast<sal_Bool const *>(rAny.getValue()))
     192           0 :             nSubType = nsSwGetSetExpType::GSE_FORMULA|nsSwExtendedSubType::SUB_CMD;
     193             :         else
     194           0 :             nSubType = nsSwGetSetExpType::GSE_FORMULA;
     195           0 :         break;
     196             :     case FIELD_PROP_PAR1:
     197             :         {
     198           0 :             OUString sTmp;
     199           0 :             rAny >>= sTmp;
     200           0 :             ChgExpStr( sTmp );
     201             :         }
     202           0 :         break;
     203             :     case FIELD_PROP_FORMAT:
     204             :         {
     205           0 :             sal_Int32 nTmp = 0;
     206           0 :             rAny >>= nTmp;
     207           0 :             SetFormat(nTmp);
     208             :         }
     209           0 :         break;
     210             :     default:
     211           0 :         bRet = false;
     212             :     }
     213           0 :     return bRet;
     214         177 : }
     215             : 
     216             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11