LCOV - code coverage report
Current view: top level - libreoffice/sw/source/core/fields - tblcalc.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 3 106 2.8 %
Date: 2012-12-27 Functions: 1 16 6.2 %
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             : 
      21             : #include <switerator.hxx>
      22             : #include <cntfrm.hxx>
      23             : #include <doc.hxx>
      24             : #include <pam.hxx>      // fuer GetBodyTxtNode
      25             : #include <ndtxt.hxx>
      26             : #include <fmtfld.hxx>
      27             : #include <txtfld.hxx>
      28             : #include <expfld.hxx>
      29             : #include <docfld.hxx>   // fuer _SetGetExpFld
      30             : #include <unofldmid.h>
      31             : 
      32             : using namespace ::com::sun::star;
      33             : using ::rtl::OUString;
      34             : 
      35             : 
      36         276 : SwTblFieldType::SwTblFieldType(SwDoc* pDocPtr)
      37         276 :     : SwValueFieldType( pDocPtr, RES_TABLEFLD )
      38         276 : {}
      39             : 
      40             : 
      41           0 : SwFieldType* SwTblFieldType::Copy() const
      42             : {
      43           0 :     return new SwTblFieldType(GetDoc());
      44             : }
      45             : 
      46             : 
      47             : 
      48           0 : void SwTblField::CalcField( SwTblCalcPara& rCalcPara )
      49             : {
      50           0 :     if( rCalcPara.rCalc.IsCalcError() )     // ist schon Fehler gesetzt ?
      51           0 :         return;
      52             : 
      53             :     // erzeuge aus den BoxNamen die Pointer
      54           0 :     BoxNmToPtr( rCalcPara.pTbl );
      55           0 :     String sFml( MakeFormula( rCalcPara ));
      56           0 :     SetValue( rCalcPara.rCalc.Calculate( sFml ).GetDouble() );
      57           0 :     ChgValid( !rCalcPara.IsStackOverFlow() );       // ist der Wert wieder gueltig?
      58             : }
      59             : 
      60             : 
      61             : 
      62           0 : SwTblField::SwTblField( SwTblFieldType* pInitType, const String& rFormel,
      63             :                         sal_uInt16 nType, sal_uLong nFmt )
      64             :     : SwValueField( pInitType, nFmt ), SwTableFormula( rFormel ),
      65           0 :     nSubType(nType)
      66             : {
      67           0 :     sExpand = rtl::OUString('0');
      68           0 : }
      69             : 
      70             : 
      71           0 : SwField* SwTblField::Copy() const
      72             : {
      73           0 :     SwTblField* pTmp = new SwTblField( (SwTblFieldType*)GetTyp(),
      74           0 :                                         SwTableFormula::GetFormula(), nSubType, GetFormat() );
      75           0 :     pTmp->sExpand     = sExpand;
      76           0 :     pTmp->SwValueField::SetValue(GetValue());
      77           0 :     pTmp->SwTableFormula::operator=( *this );
      78           0 :     pTmp->SetAutomaticLanguage(IsAutomaticLanguage());
      79           0 :     return pTmp;
      80             : }
      81             : 
      82             : 
      83           0 : String SwTblField::GetFieldName() const
      84             : {
      85           0 :     String aStr(GetTyp()->GetName());
      86           0 :     aStr += ' ';
      87           0 :     aStr += const_cast<SwTblField *>(this)->GetCommand();
      88           0 :     return aStr;
      89             : }
      90             : 
      91             : // suche den TextNode, in dem das Feld steht
      92           0 : const SwNode* SwTblField::GetNodeOfFormula() const
      93             : {
      94           0 :     if( !GetTyp()->GetDepends() )
      95           0 :         return 0;
      96             : 
      97           0 :     SwIterator<SwFmtFld,SwFieldType> aIter( *GetTyp() );
      98           0 :     for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
      99           0 :             if( this == pFmtFld->GetFld() )
     100           0 :                 return (SwTxtNode*)&pFmtFld->GetTxtFld()->GetTxtNode();
     101           0 :     return 0;
     102             : }
     103             : 
     104           0 : String SwTblField::GetCommand()
     105             : {
     106           0 :     if (EXTRNL_NAME != GetNameType())
     107             :     {
     108           0 :         SwNode const*const pNd = GetNodeOfFormula();
     109           0 :         SwTableNode const*const pTblNd = (pNd) ? pNd->FindTableNode() : 0;
     110           0 :         if (pTblNd)
     111             :         {
     112           0 :             PtrToBoxNm( &pTblNd->GetTable() );
     113             :         }
     114             :     }
     115           0 :     return (EXTRNL_NAME == GetNameType())
     116           0 :         ? SwTableFormula::GetFormula()
     117           0 :         : String();
     118             : }
     119             : 
     120           0 : String SwTblField::Expand() const
     121             : {
     122           0 :     String aStr;
     123           0 :     if (nSubType & nsSwExtendedSubType::SUB_CMD)
     124             :     {
     125           0 :         aStr = const_cast<SwTblField *>(this)->GetCommand();
     126             :     }
     127             :     else
     128             :     {
     129           0 :         aStr = sExpand;
     130           0 :         if(nSubType & nsSwGetSetExpType::GSE_STRING)
     131             :         {
     132             :             // es ist ein String
     133           0 :             aStr = sExpand;
     134           0 :             aStr.Erase( 0,1 );
     135           0 :             aStr.Erase( aStr.Len()-1, 1 );
     136             :         }
     137             :     }
     138           0 :     return aStr;
     139             : }
     140             : 
     141           0 : sal_uInt16 SwTblField::GetSubType() const
     142             : {
     143           0 :     return nSubType;
     144             : }
     145             : 
     146           0 : void SwTblField::SetSubType(sal_uInt16 nType)
     147             : {
     148           0 :     nSubType = nType;
     149           0 : }
     150             : 
     151             : 
     152           0 : void SwTblField::SetValue( const double& rVal )
     153             : {
     154           0 :     SwValueField::SetValue(rVal);
     155           0 :     sExpand = ((SwValueFieldType*)GetTyp())->ExpandValue(rVal, GetFormat(), GetLanguage());
     156           0 : }
     157             : 
     158             : /*--------------------------------------------------------------------
     159             :     Beschreibung: Parameter setzen
     160             :  --------------------------------------------------------------------*/
     161             : 
     162             : 
     163           0 : rtl::OUString SwTblField::GetPar2() const
     164             : {
     165           0 :     return SwTableFormula::GetFormula();
     166             : }
     167             : 
     168             : 
     169           0 : void SwTblField::SetPar2(const rtl::OUString& rStr)
     170             : {
     171           0 :     SetFormula( rStr );
     172           0 : }
     173             : 
     174           0 : bool SwTblField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
     175             : {
     176           0 :     bool bRet = true;
     177           0 :     switch ( nWhichId )
     178             :     {
     179             :     case FIELD_PROP_PAR2:
     180             :         {
     181           0 :             sal_uInt16 nOldSubType = nSubType;
     182           0 :             SwTblField* pThis = (SwTblField*)this;
     183           0 :             pThis->nSubType |= nsSwExtendedSubType::SUB_CMD;
     184           0 :             rAny <<= rtl::OUString( Expand() );
     185           0 :             pThis->nSubType = nOldSubType;
     186             :         }
     187           0 :         break;
     188             :     case FIELD_PROP_BOOL1:
     189             :         {
     190           0 :             sal_Bool bFormula = 0 != (nsSwExtendedSubType::SUB_CMD & nSubType);
     191           0 :             rAny.setValue(&bFormula, ::getBooleanCppuType());
     192             :         }
     193           0 :         break;
     194             :     case FIELD_PROP_PAR1:
     195           0 :         rAny <<= rtl::OUString(GetExpStr());
     196           0 :         break;
     197             :     case FIELD_PROP_FORMAT:
     198           0 :         rAny <<= (sal_Int32)GetFormat();
     199           0 :         break;
     200             :     default:
     201           0 :         bRet = false;
     202             :     }
     203           0 :     return bRet;
     204             : }
     205             : 
     206           0 : bool SwTblField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     207             : {
     208           0 :     bool bRet = true;
     209           0 :     String sTmp;
     210           0 :     switch ( nWhichId )
     211             :     {
     212             :     case FIELD_PROP_PAR2:
     213           0 :         SetFormula( ::GetString( rAny, sTmp ));
     214           0 :         break;
     215             :     case FIELD_PROP_BOOL1:
     216           0 :         if(*(sal_Bool*)rAny.getValue())
     217           0 :             nSubType = nsSwGetSetExpType::GSE_FORMULA|nsSwExtendedSubType::SUB_CMD;
     218             :         else
     219           0 :             nSubType = nsSwGetSetExpType::GSE_FORMULA;
     220           0 :         break;
     221             :     case FIELD_PROP_PAR1:
     222           0 :         ChgExpStr( ::GetString( rAny, sTmp ));
     223           0 :         break;
     224             :     case FIELD_PROP_FORMAT:
     225             :         {
     226           0 :             sal_Int32 nTmp = 0;
     227           0 :             rAny >>= nTmp;
     228           0 :             SetFormat(nTmp);
     229             :         }
     230           0 :         break;
     231             :     default:
     232           0 :         bRet = false;
     233             :     }
     234           0 :     return bRet;
     235             : }
     236             : 
     237             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10