1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tblcalc.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
37 #include <pam.hxx> // fuer GetBodyTxtNode
42 #include <docfld.hxx> // fuer _SetGetExpFld
44 #include <unofldmid.h>
47 using namespace ::com::sun::star
;
48 using ::rtl::OUString
;
51 SwTblFieldType::SwTblFieldType(SwDoc
* pDocPtr
)
52 : SwValueFieldType( pDocPtr
, RES_TABLEFLD
)
56 SwFieldType
* SwTblFieldType::Copy() const
58 return new SwTblFieldType(GetDoc());
63 void SwTblField::CalcField( SwTblCalcPara
& rCalcPara
)
65 if( rCalcPara
.rCalc
.IsCalcError() ) // ist schon Fehler gesetzt ?
68 // erzeuge aus den BoxNamen die Pointer
69 BoxNmToPtr( rCalcPara
.pTbl
);
70 String
sFml( MakeFormel( rCalcPara
));
71 SetValue( rCalcPara
.rCalc
.Calculate( sFml
).GetDouble() );
72 ChgValid( !rCalcPara
.IsStackOverFlow() ); // ist der Wert wieder gueltig?
77 SwTblField::SwTblField( SwTblFieldType
* pInitType
, const String
& rFormel
,
78 USHORT nType
, ULONG nFmt
)
79 : SwValueField( pInitType
, nFmt
), SwTableFormula( rFormel
),
80 sExpand( '0' ), nSubType(nType
)
85 SwField
* SwTblField::Copy() const
87 SwTblField
* pTmp
= new SwTblField( (SwTblFieldType
*)GetTyp(),
88 SwTableFormula::GetFormula(), nSubType
, GetFormat() );
89 pTmp
->sExpand
= sExpand
;
90 pTmp
->SwValueField::SetValue(GetValue());
91 pTmp
->SwTableFormula::operator=( *this );
92 pTmp
->SetAutomaticLanguage(IsAutomaticLanguage());
97 String
SwTblField::GetCntnt(BOOL bName
) const
101 String
aStr(GetTyp()->GetName());
104 USHORT nOldSubType
= nSubType
;
105 SwTblField
* pThis
= (SwTblField
*)this;
106 pThis
->nSubType
|= nsSwExtendedSubType::SUB_CMD
;
108 pThis
->nSubType
= nOldSubType
;
115 // suche den TextNode, in dem das Feld steht
116 const SwNode
* SwTblField::GetNodeOfFormula() const
118 if( !GetTyp()->GetDepends() )
121 SwClientIter
aIter( *GetTyp() );
122 SwClient
* pLast
= aIter
.GoStart();
123 if( pLast
) // konnte zum Anfang gesprungen werden ??
125 const SwFmtFld
* pFmtFld
= (SwFmtFld
*)pLast
;
126 if( this == pFmtFld
->GetFld() )
127 return (SwTxtNode
*)&pFmtFld
->GetTxtFld()->GetTxtNode();
129 } while( 0 != ( pLast
= aIter
++ ));
134 String
SwTblField::Expand() const
137 if (nSubType
& nsSwExtendedSubType::SUB_CMD
)
139 if( EXTRNL_NAME
!= GetNameType() )
141 const SwNode
* pNd
= GetNodeOfFormula();
142 const SwTableNode
* pTblNd
= pNd
? pNd
->FindTableNode() : 0;
144 ((SwTblField
*)this)->PtrToBoxNm( &pTblNd
->GetTable() );
146 if( EXTRNL_NAME
== GetNameType() )
147 aStr
= SwTableFormula::GetFormula();
152 if(nSubType
& nsSwGetSetExpType::GSE_STRING
)
157 aStr
.Erase( aStr
.Len()-1, 1 );
163 USHORT
SwTblField::GetSubType() const
168 void SwTblField::SetSubType(USHORT nType
)
174 void SwTblField::SetValue( const double& rVal
)
176 SwValueField::SetValue(rVal
);
177 sExpand
= ((SwValueFieldType
*)GetTyp())->ExpandValue(rVal
, GetFormat(), GetLanguage());
180 /*--------------------------------------------------------------------
181 Beschreibung: Parameter setzen
182 --------------------------------------------------------------------*/
185 String
SwTblField::GetPar2() const
187 return SwTableFormula::GetFormula();
191 void SwTblField::SetPar2(const String
& rStr
)
197 /*-----------------04.03.98 10:33-------------------
199 --------------------------------------------------*/
200 BOOL
SwTblField::QueryValue( uno::Any
& rAny
, USHORT nWhichId
) const
205 case FIELD_PROP_PAR2
:
207 USHORT nOldSubType
= nSubType
;
208 SwTblField
* pThis
= (SwTblField
*)this;
209 pThis
->nSubType
|= nsSwExtendedSubType::SUB_CMD
;
210 rAny
<<= rtl::OUString( Expand() );
211 pThis
->nSubType
= nOldSubType
;
214 case FIELD_PROP_BOOL1
:
216 BOOL bFormula
= 0 != (nsSwExtendedSubType::SUB_CMD
& nSubType
);
217 rAny
.setValue(&bFormula
, ::getBooleanCppuType());
220 case FIELD_PROP_PAR1
:
221 rAny
<<= rtl::OUString(GetExpStr());
223 case FIELD_PROP_FORMAT
:
224 rAny
<<= (sal_Int32
)GetFormat();
231 /*-----------------04.03.98 10:33-------------------
233 --------------------------------------------------*/
234 BOOL
SwTblField::PutValue( const uno::Any
& rAny
, USHORT nWhichId
)
240 case FIELD_PROP_PAR2
:
241 SetFormula( ::GetString( rAny
, sTmp
));
243 case FIELD_PROP_BOOL1
:
244 if(*(sal_Bool
*)rAny
.getValue())
245 nSubType
= nsSwGetSetExpType::GSE_FORMULA
|nsSwExtendedSubType::SUB_CMD
;
247 nSubType
= nsSwGetSetExpType::GSE_FORMULA
;
249 case FIELD_PROP_PAR1
:
250 ChgExpStr( ::GetString( rAny
, sTmp
));
252 case FIELD_PROP_FORMAT
: