LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/core/attr - cellatr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 25 88 28.4 %
Date: 2013-07-09 Functions: 10 16 62.5 %
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 <calc.hxx>
      21             : #include <cellatr.hxx>
      22             : #include <doc.hxx>
      23             : #include <float.h>
      24             : #include <format.hxx>
      25             : #include <hintids.hxx>
      26             : #include <hints.hxx>
      27             : #include <node.hxx>
      28             : #include <rolbck.hxx>
      29             : #include <rtl/math.hxx>
      30             : #include <switerator.hxx>
      31             : #include <swtable.hxx>
      32             : 
      33             : // -----------------
      34             : // SwTblBoxNumFormat
      35             : // -----------------
      36             : 
      37         166 : SwTblBoxNumFormat::SwTblBoxNumFormat( sal_uInt32 nFormat, sal_Bool bFlag )
      38         166 :     : SfxUInt32Item( RES_BOXATR_FORMAT, nFormat ), bAuto( bFlag )
      39             : {
      40         166 : }
      41             : 
      42         201 : int SwTblBoxNumFormat::operator==( const SfxPoolItem& rAttr ) const
      43             : {
      44             :     OSL_ENSURE( SfxPoolItem::operator==( rAttr ), "no matching attributes" );
      45         305 :     return GetValue() == ( (SwTblBoxNumFormat&) rAttr ).GetValue() &&
      46         305 :            bAuto == ( (SwTblBoxNumFormat&) rAttr ).bAuto;
      47             : }
      48             : 
      49          15 : SfxPoolItem* SwTblBoxNumFormat::Clone( SfxItemPool* ) const
      50             : {
      51          15 :     return new SwTblBoxNumFormat( GetValue(), bAuto );
      52             : }
      53             : 
      54             : // -----------------
      55             : // SwTblBoxFormula
      56             : // -----------------
      57             : 
      58          33 : SwTblBoxFormula::SwTblBoxFormula( const String& rFormula )
      59             :     : SfxPoolItem( RES_BOXATR_FORMULA ),
      60             :     SwTableFormula( rFormula ),
      61          33 :     pDefinedIn( 0 )
      62             : {
      63          33 : }
      64             : 
      65           0 : int SwTblBoxFormula::operator==( const SfxPoolItem& rAttr ) const
      66             : {
      67             :     OSL_ENSURE( SfxPoolItem::operator==( rAttr ), "keine gleichen Attribute" );
      68           0 :     return GetFormula() == ( (SwTblBoxFormula&) rAttr ).GetFormula() &&
      69           0 :            pDefinedIn == ( (SwTblBoxFormula&) rAttr ).pDefinedIn;
      70             : }
      71             : 
      72           0 : SfxPoolItem* SwTblBoxFormula::Clone( SfxItemPool* ) const
      73             : {
      74             :     // switch to external rendering
      75           0 :     SwTblBoxFormula* pNew = new SwTblBoxFormula( GetFormula() );
      76           0 :     pNew->SwTableFormula::operator=( *this );
      77           0 :     return pNew;
      78             : }
      79             : 
      80             : /** Get node type of the node containing this formula
      81             : 
      82             :     E.g. TextFeld -> TextNode, or
      83             :      BoxAttribute -> BoxStartNode
      84             : 
      85             :     Caution: Has to be overloaded when inheriting.
      86             : */
      87           0 : const SwNode* SwTblBoxFormula::GetNodeOfFormula() const
      88             : {
      89           0 :     const SwNode* pRet = 0;
      90           0 :     if( pDefinedIn )
      91             :     {
      92           0 :         SwTableBox* pBox = SwIterator<SwTableBox,SwModify>::FirstElement( *pDefinedIn );
      93           0 :         if( pBox )
      94           0 :             pRet = pBox->GetSttNd();
      95             :     }
      96           0 :     return pRet;
      97             : }
      98             : 
      99           0 : SwTableBox* SwTblBoxFormula::GetTableBox()
     100             : {
     101           0 :     SwTableBox* pBox = 0;
     102           0 :     if( pDefinedIn )
     103           0 :         pBox = SwIterator<SwTableBox,SwModify>::FirstElement( *pDefinedIn );
     104           0 :     return pBox;
     105             : }
     106             : 
     107           0 : void SwTblBoxFormula::ChangeState( const SfxPoolItem* pItem )
     108             : {
     109           0 :     if( !pDefinedIn )
     110           0 :         return ;
     111             : 
     112             :     SwTableFmlUpdate* pUpdtFld;
     113           0 :     if( !pItem || RES_TABLEFML_UPDATE != pItem->Which() )
     114             :     {
     115             :         // reset value flag
     116           0 :         ChgValid( sal_False );
     117           0 :         return ;
     118             :     }
     119             : 
     120           0 :     pUpdtFld = (SwTableFmlUpdate*)pItem;
     121             : 
     122             :     // detect table that contains this attribute
     123             :     const SwTableNode* pTblNd;
     124           0 :     const SwNode* pNd = GetNodeOfFormula();
     125           0 :     if( pNd && &pNd->GetNodes() == &pNd->GetDoc()->GetNodes() &&
     126             :         0 != ( pTblNd = pNd->FindTableNode() ))
     127             :     {
     128           0 :         switch( pUpdtFld->eFlags )
     129             :         {
     130             :         case TBL_CALC:
     131             :             // reset value flag
     132           0 :             ChgValid( sal_False );
     133           0 :             break;
     134             :         case TBL_BOXNAME:
     135           0 :             if( &pTblNd->GetTable() == pUpdtFld->pTbl )
     136             :                 // use external rendering
     137           0 :                 PtrToBoxNm( pUpdtFld->pTbl );
     138           0 :             break;
     139             :         case TBL_BOXPTR:
     140             :             // internal rendering
     141           0 :             BoxNmToPtr( &pTblNd->GetTable() );
     142           0 :             break;
     143             :         case TBL_RELBOXNAME:
     144           0 :             if( &pTblNd->GetTable() == pUpdtFld->pTbl )
     145             :                 // relative rendering
     146           0 :                 ToRelBoxNm( pUpdtFld->pTbl );
     147           0 :             break;
     148             : 
     149             :         case TBL_SPLITTBL:
     150           0 :             if( &pTblNd->GetTable() == pUpdtFld->pTbl )
     151             :             {
     152             :                 sal_uInt16 nLnPos = SwTableFormula::GetLnPosInTbl(
     153           0 :                                         pTblNd->GetTable(), GetTableBox() );
     154           0 :                 pUpdtFld->bBehindSplitLine = USHRT_MAX != nLnPos &&
     155           0 :                                             pUpdtFld->nSplitLine <= nLnPos;
     156             :             }
     157             :             else
     158           0 :                 pUpdtFld->bBehindSplitLine = sal_False;
     159             :             // no break
     160             :         case TBL_MERGETBL:
     161           0 :             if( pUpdtFld->pHistory )
     162             :             {
     163             :                 // for a history record the unchanged formula is needed
     164           0 :                 SwTblBoxFormula aCopy( *this );
     165           0 :                 pUpdtFld->bModified = sal_False;
     166           0 :                 ToSplitMergeBoxNm( *pUpdtFld );
     167             : 
     168           0 :                 if( pUpdtFld->bModified )
     169             :                 {
     170             :                     // external rendering
     171           0 :                     aCopy.PtrToBoxNm( &pTblNd->GetTable() );
     172             :                     pUpdtFld->pHistory->Add( &aCopy, &aCopy,
     173           0 :                                 pNd->FindTableBoxStartNode()->GetIndex() );
     174           0 :                 }
     175             :             }
     176             :             else
     177           0 :                 ToSplitMergeBoxNm( *pUpdtFld );
     178           0 :             break;
     179             :         }
     180             :     }
     181             : }
     182             : 
     183           0 : void SwTblBoxFormula::Calc( SwTblCalcPara& rCalcPara, double& rValue )
     184             : {
     185           0 :     if( !rCalcPara.rCalc.IsCalcError() )
     186             :     {
     187             :         // create pointers from box names
     188           0 :         BoxNmToPtr( rCalcPara.pTbl );
     189           0 :         String sFml( MakeFormula( rCalcPara ));
     190           0 :         if( !rCalcPara.rCalc.IsCalcError() )
     191           0 :             rValue = rCalcPara.rCalc.Calculate( sFml ).GetDouble();
     192             :         else
     193           0 :             rValue = DBL_MAX;
     194           0 :         ChgValid( !rCalcPara.IsStackOverFlow() ); // value is now valid again
     195             :     }
     196           0 : }
     197             : 
     198             : // -------------
     199             : // SwTblBoxValue
     200             : // -------------
     201             : 
     202          33 : SwTblBoxValue::SwTblBoxValue()
     203          33 :     : SfxPoolItem( RES_BOXATR_VALUE ), nValue( 0 )
     204             : {
     205          33 : }
     206             : 
     207         120 : SwTblBoxValue::SwTblBoxValue( const double nVal )
     208         120 :     : SfxPoolItem( RES_BOXATR_VALUE ), nValue( nVal )
     209             : {
     210         120 : }
     211             : 
     212         181 : int SwTblBoxValue::operator==( const SfxPoolItem& rAttr ) const
     213             : {
     214             :     OSL_ENSURE( SfxPoolItem::operator==(rAttr), "SwTblBoxValue: item not equal" );
     215         181 :     SwTblBoxValue const& rOther( static_cast<SwTblBoxValue const&>(rAttr) );
     216             :     // items with NaN should be equal to enable pooling
     217         181 :     return ::rtl::math::isNan( nValue )
     218           9 :         ?   ::rtl::math::isNan( rOther.nValue )
     219         190 :         :   ( nValue == rOther.nValue );
     220             : }
     221             : 
     222          37 : SfxPoolItem* SwTblBoxValue::Clone( SfxItemPool* ) const
     223             : {
     224          37 :     return new SwTblBoxValue( nValue );
     225          99 : }
     226             : 
     227             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10