Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <calc.hxx>
30 : : #include <cellatr.hxx>
31 : : #include <doc.hxx>
32 : : #include <float.h>
33 : : #include <format.hxx>
34 : : #include <hintids.hxx>
35 : : #include <hints.hxx>
36 : : #include <node.hxx>
37 : : #include <rolbck.hxx>
38 : : #include <rtl/math.hxx>
39 : : #include <switerator.hxx>
40 : : #include <swtable.hxx>
41 : :
42 : : // -----------------
43 : : // SwTblBoxNumFormat
44 : : // -----------------
45 : :
46 : 325 : SwTblBoxNumFormat::SwTblBoxNumFormat( sal_uInt32 nFormat, sal_Bool bFlag )
47 : 325 : : SfxUInt32Item( RES_BOXATR_FORMAT, nFormat ), bAuto( bFlag )
48 : : {
49 : 325 : }
50 : :
51 : 394 : int SwTblBoxNumFormat::operator==( const SfxPoolItem& rAttr ) const
52 : : {
53 : : OSL_ENSURE( SfxPoolItem::operator==( rAttr ), "no matching attributes" );
54 : 394 : return GetValue() == ( (SwTblBoxNumFormat&) rAttr ).GetValue() &&
55 [ + - ][ + + ]: 394 : bAuto == ( (SwTblBoxNumFormat&) rAttr ).bAuto;
56 : : }
57 : :
58 : 24 : SfxPoolItem* SwTblBoxNumFormat::Clone( SfxItemPool* ) const
59 : : {
60 [ + - ]: 24 : return new SwTblBoxNumFormat( GetValue(), bAuto );
61 : : }
62 : :
63 : : // -----------------
64 : : // SwTblBoxFormula
65 : : // -----------------
66 : :
67 : 73 : SwTblBoxFormula::SwTblBoxFormula( const String& rFormula )
68 : : : SfxPoolItem( RES_BOXATR_FORMULA ),
69 : : SwTableFormula( rFormula ),
70 [ + - ]: 73 : pDefinedIn( 0 )
71 : : {
72 : 73 : }
73 : :
74 : 0 : int SwTblBoxFormula::operator==( const SfxPoolItem& rAttr ) const
75 : : {
76 : : OSL_ENSURE( SfxPoolItem::operator==( rAttr ), "keine gleichen Attribute" );
77 : 0 : return GetFormula() == ( (SwTblBoxFormula&) rAttr ).GetFormula() &&
78 [ # # ][ # # ]: 0 : pDefinedIn == ( (SwTblBoxFormula&) rAttr ).pDefinedIn;
79 : : }
80 : :
81 : 0 : SfxPoolItem* SwTblBoxFormula::Clone( SfxItemPool* ) const
82 : : {
83 : : // switch to external rendering
84 [ # # ]: 0 : SwTblBoxFormula* pNew = new SwTblBoxFormula( GetFormula() );
85 : 0 : pNew->SwTableFormula::operator=( *this );
86 : 0 : return pNew;
87 : : }
88 : :
89 : : /** Get node type of the node containing this formula
90 : :
91 : : E.g. TextFeld -> TextNode, or
92 : : BoxAttribute -> BoxStartNode
93 : :
94 : : Caution: Has to be overloaded when inheriting.
95 : : */
96 : 0 : const SwNode* SwTblBoxFormula::GetNodeOfFormula() const
97 : : {
98 : 0 : const SwNode* pRet = 0;
99 [ # # ]: 0 : if( pDefinedIn )
100 : : {
101 : 0 : SwTableBox* pBox = SwIterator<SwTableBox,SwModify>::FirstElement( *pDefinedIn );
102 [ # # ]: 0 : if( pBox )
103 : 0 : pRet = pBox->GetSttNd();
104 : : }
105 : 0 : return pRet;
106 : : }
107 : :
108 : 0 : SwTableBox* SwTblBoxFormula::GetTableBox()
109 : : {
110 : 0 : SwTableBox* pBox = 0;
111 [ # # ]: 0 : if( pDefinedIn )
112 : 0 : pBox = SwIterator<SwTableBox,SwModify>::FirstElement( *pDefinedIn );
113 : 0 : return pBox;
114 : : }
115 : :
116 : 0 : void SwTblBoxFormula::ChangeState( const SfxPoolItem* pItem )
117 : : {
118 [ # # ]: 0 : if( !pDefinedIn )
119 : 0 : return ;
120 : :
121 : : SwTableFmlUpdate* pUpdtFld;
122 [ # # ][ # # ]: 0 : if( !pItem || RES_TABLEFML_UPDATE != pItem->Which() )
[ # # ]
123 : : {
124 : : // reset value flag
125 : 0 : ChgValid( sal_False );
126 : 0 : return ;
127 : : }
128 : :
129 : 0 : pUpdtFld = (SwTableFmlUpdate*)pItem;
130 : :
131 : : // detect table that contains this attribute
132 : : const SwTableNode* pTblNd;
133 : 0 : const SwNode* pNd = GetNodeOfFormula();
134 [ # # ][ # # ]: 0 : if( pNd && &pNd->GetNodes() == &pNd->GetDoc()->GetNodes() &&
[ # # ][ # # ]
135 : : 0 != ( pTblNd = pNd->FindTableNode() ))
136 : : {
137 [ # # # # : 0 : switch( pUpdtFld->eFlags )
# # # ]
138 : : {
139 : : case TBL_CALC:
140 : : // reset value flag
141 : 0 : ChgValid( sal_False );
142 : 0 : break;
143 : : case TBL_BOXNAME:
144 [ # # ]: 0 : if( &pTblNd->GetTable() == pUpdtFld->pTbl )
145 : : // use external rendering
146 : 0 : PtrToBoxNm( pUpdtFld->pTbl );
147 : 0 : break;
148 : : case TBL_BOXPTR:
149 : : // internal rendering
150 : 0 : BoxNmToPtr( &pTblNd->GetTable() );
151 : 0 : break;
152 : : case TBL_RELBOXNAME:
153 [ # # ]: 0 : if( &pTblNd->GetTable() == pUpdtFld->pTbl )
154 : : // relative rendering
155 : 0 : ToRelBoxNm( pUpdtFld->pTbl );
156 : 0 : break;
157 : :
158 : : case TBL_SPLITTBL:
159 [ # # ]: 0 : if( &pTblNd->GetTable() == pUpdtFld->pTbl )
160 : : {
161 : : sal_uInt16 nLnPos = SwTableFormula::GetLnPosInTbl(
162 : 0 : pTblNd->GetTable(), GetTableBox() );
163 : : pUpdtFld->bBehindSplitLine = USHRT_MAX != nLnPos &&
164 [ # # ][ # # ]: 0 : pUpdtFld->nSplitLine <= nLnPos;
165 : : }
166 : : else
167 : 0 : pUpdtFld->bBehindSplitLine = sal_False;
168 : : // no break
169 : : case TBL_MERGETBL:
170 [ # # ]: 0 : if( pUpdtFld->pHistory )
171 : : {
172 : : // for a history record the unchanged formula is needed
173 [ # # ]: 0 : SwTblBoxFormula aCopy( *this );
174 : 0 : pUpdtFld->bModified = sal_False;
175 [ # # ]: 0 : ToSplitMergeBoxNm( *pUpdtFld );
176 : :
177 [ # # ]: 0 : if( pUpdtFld->bModified )
178 : : {
179 : : // external rendering
180 [ # # ]: 0 : aCopy.PtrToBoxNm( &pTblNd->GetTable() );
181 : : pUpdtFld->pHistory->Add( &aCopy, &aCopy,
182 [ # # ][ # # ]: 0 : pNd->FindTableBoxStartNode()->GetIndex() );
183 [ # # ]: 0 : }
184 : : }
185 : : else
186 : 0 : ToSplitMergeBoxNm( *pUpdtFld );
187 : 0 : break;
188 : : }
189 : : }
190 : : }
191 : :
192 : 0 : void SwTblBoxFormula::Calc( SwTblCalcPara& rCalcPara, double& rValue )
193 : : {
194 [ # # ]: 0 : if( !rCalcPara.rCalc.IsCalcError() )
195 : : {
196 : : // create pointers from box names
197 [ # # ]: 0 : BoxNmToPtr( rCalcPara.pTbl );
198 [ # # ]: 0 : String sFml( MakeFormula( rCalcPara ));
199 [ # # ]: 0 : if( !rCalcPara.rCalc.IsCalcError() )
200 [ # # ][ # # ]: 0 : rValue = rCalcPara.rCalc.Calculate( sFml ).GetDouble();
[ # # ]
201 : : else
202 : 0 : rValue = DBL_MAX;
203 [ # # ]: 0 : ChgValid( !rCalcPara.IsStackOverFlow() ); // value is now valid again
204 : : }
205 : 0 : }
206 : :
207 : : // -------------
208 : : // SwTblBoxValue
209 : : // -------------
210 : :
211 : 73 : SwTblBoxValue::SwTblBoxValue()
212 : 73 : : SfxPoolItem( RES_BOXATR_VALUE ), nValue( 0 )
213 : : {
214 : 73 : }
215 : :
216 : 218 : SwTblBoxValue::SwTblBoxValue( const double nVal )
217 : 218 : : SfxPoolItem( RES_BOXATR_VALUE ), nValue( nVal )
218 : : {
219 : 218 : }
220 : :
221 : 336 : int SwTblBoxValue::operator==( const SfxPoolItem& rAttr ) const
222 : : {
223 : : OSL_ENSURE( SfxPoolItem::operator==(rAttr), "SwTblBoxValue: item not equal" );
224 : 336 : SwTblBoxValue const& rOther( static_cast<SwTblBoxValue const&>(rAttr) );
225 : : // items with NaN should be equal to enable pooling
226 : 336 : return ::rtl::math::isNan( nValue )
227 : 18 : ? ::rtl::math::isNan( rOther.nValue )
228 [ + + ]: 354 : : ( nValue == rOther.nValue );
229 : : }
230 : :
231 : 64 : SfxPoolItem* SwTblBoxValue::Clone( SfxItemPool* ) const
232 : : {
233 [ + - ]: 64 : return new SwTblBoxValue( nValue );
234 : : }
235 : :
236 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|