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

Generated by: LCOV version 1.11