1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <o3tl/any.hxx>
31 #include <unofldmid.h>
33 using namespace ::com::sun::star
;
35 SwTableFieldType::SwTableFieldType(SwDoc
* pDocPtr
)
36 : SwValueFieldType( pDocPtr
, SwFieldIds::Table
)
39 std::unique_ptr
<SwFieldType
> SwTableFieldType::Copy() const
41 return std::make_unique
<SwTableFieldType
>(GetDoc());
44 void SwTableField::CalcField( SwTableCalcPara
& rCalcPara
)
46 if( rCalcPara
.m_rCalc
.IsCalcError() ) // stop if there is already an error set
49 // create pointers from box name
50 BoxNmToPtr( rCalcPara
.m_pTable
);
51 OUString
sFormula( MakeFormula( rCalcPara
));
52 SetValue( rCalcPara
.m_rCalc
.Calculate( sFormula
).GetDouble() );
53 ChgValid( !rCalcPara
.IsStackOverflow() ); // is the value again valid?
56 SwTableField::SwTableField( SwTableFieldType
* pInitType
, const OUString
& rFormel
,
57 sal_uInt16 nType
, sal_uLong nFormat
)
58 : SwValueField( pInitType
, nFormat
), SwTableFormula( rFormel
),
64 std::unique_ptr
<SwField
> SwTableField::Copy() const
66 std::unique_ptr
<SwTableField
> pTmp(new SwTableField( static_cast<SwTableFieldType
*>(GetTyp()),
67 SwTableFormula::GetFormula(), m_nSubType
, GetFormat() ));
68 pTmp
->m_sExpand
= m_sExpand
;
69 pTmp
->SwValueField::SetValue(GetValue());
70 pTmp
->SwTableFormula::operator=( *this );
71 pTmp
->SetAutomaticLanguage(IsAutomaticLanguage());
72 return std::unique_ptr
<SwField
>(pTmp
.release());
75 OUString
SwTableField::GetFieldName() const
77 return GetTyp()->GetName() + " " + const_cast<SwTableField
*>(this)->GetCommand();
80 /// search TextNode containing this field
81 const SwNode
* SwTableField::GetNodeOfFormula() const
83 auto pFormat
= GetTyp()->FindFormatForField(this);
84 return pFormat
? &pFormat
->GetTextField()->GetTextNode() : nullptr;
87 OUString
SwTableField::GetCommand()
89 if (EXTRNL_NAME
!= GetNameType())
91 SwNode
const*const pNd
= GetNodeOfFormula();
92 SwTableNode
const*const pTableNd
= pNd
? pNd
->FindTableNode() : nullptr;
95 PtrToBoxNm( &pTableNd
->GetTable() );
98 return (EXTRNL_NAME
== GetNameType())
99 ? SwTableFormula::GetFormula()
103 OUString
SwTableField::ExpandImpl(SwRootFrame
const*const) const
105 if (m_nSubType
& nsSwExtendedSubType::SUB_CMD
)
107 return const_cast<SwTableField
*>(this)->GetCommand();
110 if(m_nSubType
& nsSwGetSetExpType::GSE_STRING
)
113 return m_sExpand
.copy(1, m_sExpand
.getLength()-2);
119 sal_uInt16
SwTableField::GetSubType() const
124 void SwTableField::SetSubType(sal_uInt16 nType
)
129 void SwTableField::SetValue( const double& rVal
)
131 SwValueField::SetValue(rVal
);
132 m_sExpand
= static_cast<SwValueFieldType
*>(GetTyp())->ExpandValue(rVal
, GetFormat(), GetLanguage());
135 OUString
SwTableField::GetPar2() const
137 return SwTableFormula::GetFormula();
140 void SwTableField::SetPar2(const OUString
& rStr
)
145 bool SwTableField::QueryValue( uno::Any
& rAny
, sal_uInt16 nWhichId
) const
150 case FIELD_PROP_PAR2
:
152 sal_uInt16 nOldSubType
= m_nSubType
;
153 SwTableField
* pThis
= const_cast<SwTableField
*>(this);
154 pThis
->m_nSubType
|= nsSwExtendedSubType::SUB_CMD
;
155 rAny
<<= ExpandImpl(nullptr);
156 pThis
->m_nSubType
= nOldSubType
;
159 case FIELD_PROP_BOOL1
:
160 rAny
<<= 0 != (nsSwExtendedSubType::SUB_CMD
& m_nSubType
);
162 case FIELD_PROP_PAR1
:
165 case FIELD_PROP_FORMAT
:
166 rAny
<<= static_cast<sal_Int32
>(GetFormat());
174 bool SwTableField::PutValue( const uno::Any
& rAny
, sal_uInt16 nWhichId
)
179 case FIELD_PROP_PAR2
:
186 case FIELD_PROP_BOOL1
:
187 if(*o3tl::doAccess
<bool>(rAny
))
188 m_nSubType
= nsSwGetSetExpType::GSE_FORMULA
|nsSwExtendedSubType::SUB_CMD
;
190 m_nSubType
= nsSwGetSetExpType::GSE_FORMULA
;
192 case FIELD_PROP_PAR1
:
199 case FIELD_PROP_FORMAT
:
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */