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

Generated by: LCOV version 1.10