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

Generated by: LCOV version 1.10