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>
30 #include <unofldmid.h>
32 using namespace ::com::sun::star
;
34 SwTableFieldType::SwTableFieldType(SwDoc
* pDocPtr
)
35 : SwValueFieldType( pDocPtr
, SwFieldIds::Table
)
38 std::unique_ptr
<SwFieldType
> SwTableFieldType::Copy() const
40 return std::make_unique
<SwTableFieldType
>(GetDoc());
43 void SwTableField::CalcField( SwTableCalcPara
& rCalcPara
)
45 if( rCalcPara
.m_rCalc
.IsCalcError() ) // stop if there is already an error set
48 // create pointers from box name
49 BoxNmToPtr( rCalcPara
.m_pTable
);
50 OUString
sFormula( MakeFormula( rCalcPara
));
51 SetValue( rCalcPara
.m_rCalc
.Calculate( sFormula
).GetDouble() );
52 ChgValid( !rCalcPara
.IsStackOverflow() ); // is the value again valid?
55 SwTableField::SwTableField( SwTableFieldType
* pInitType
, const OUString
& rFormel
,
56 sal_uInt16 nType
, sal_uLong nFormat
)
57 : SwValueField( pInitType
, nFormat
), SwTableFormula( rFormel
),
63 std::unique_ptr
<SwField
> SwTableField::Copy() const
65 std::unique_ptr
<SwTableField
> pTmp(new SwTableField( static_cast<SwTableFieldType
*>(GetTyp()),
66 SwTableFormula::GetFormula(), m_nSubType
, GetFormat() ));
67 pTmp
->m_sExpand
= m_sExpand
;
68 pTmp
->SwValueField::SetValue(GetValue());
69 pTmp
->SwTableFormula::operator=( *this );
70 pTmp
->SetAutomaticLanguage(IsAutomaticLanguage());
71 return std::unique_ptr
<SwField
>(pTmp
.release());
74 OUString
SwTableField::GetFieldName() const
76 return GetTyp()->GetName() + " " + const_cast<SwTableField
*>(this)->GetCommand();
79 /// search TextNode containing this field
80 const SwNode
* SwTableField::GetNodeOfFormula() const
82 auto pFormat
= GetTyp()->FindFormatForField(this);
83 return pFormat
? &pFormat
->GetTextField()->GetTextNode() : nullptr;
86 OUString
SwTableField::GetCommand()
88 if (EXTRNL_NAME
!= GetNameType())
90 SwNode
const*const pNd
= GetNodeOfFormula();
91 SwTableNode
const*const pTableNd
= pNd
? pNd
->FindTableNode() : nullptr;
94 PtrToBoxNm( &pTableNd
->GetTable() );
97 return (EXTRNL_NAME
== GetNameType())
98 ? SwTableFormula::GetFormula()
102 OUString
SwTableField::ExpandImpl(SwRootFrame
const*const) const
104 if (m_nSubType
& nsSwExtendedSubType::SUB_CMD
)
106 return const_cast<SwTableField
*>(this)->GetCommand();
109 if(m_nSubType
& nsSwGetSetExpType::GSE_STRING
)
112 return m_sExpand
.copy(1, m_sExpand
.getLength()-2);
118 sal_uInt16
SwTableField::GetSubType() const
123 void SwTableField::SetSubType(sal_uInt16 nType
)
128 void SwTableField::SetValue( const double& rVal
)
130 SwValueField::SetValue(rVal
);
131 m_sExpand
= static_cast<SwValueFieldType
*>(GetTyp())->ExpandValue(rVal
, GetFormat(), GetLanguage());
134 OUString
SwTableField::GetPar2() const
136 return SwTableFormula::GetFormula();
139 void SwTableField::SetPar2(const OUString
& rStr
)
144 bool SwTableField::QueryValue( uno::Any
& rAny
, sal_uInt16 nWhichId
) const
149 case FIELD_PROP_PAR2
:
151 sal_uInt16 nOldSubType
= m_nSubType
;
152 SwTableField
* pThis
= const_cast<SwTableField
*>(this);
153 pThis
->m_nSubType
|= nsSwExtendedSubType::SUB_CMD
;
154 rAny
<<= ExpandImpl(nullptr);
155 pThis
->m_nSubType
= nOldSubType
;
158 case FIELD_PROP_BOOL1
:
159 rAny
<<= 0 != (nsSwExtendedSubType::SUB_CMD
& m_nSubType
);
161 case FIELD_PROP_PAR1
:
164 case FIELD_PROP_FORMAT
:
165 rAny
<<= static_cast<sal_Int32
>(GetFormat());
173 bool SwTableField::PutValue( const uno::Any
& rAny
, sal_uInt16 nWhichId
)
178 case FIELD_PROP_PAR2
:
185 case FIELD_PROP_BOOL1
:
186 if(*o3tl::doAccess
<bool>(rAny
))
187 m_nSubType
= nsSwGetSetExpType::GSE_FORMULA
|nsSwExtendedSubType::SUB_CMD
;
189 m_nSubType
= nsSwGetSetExpType::GSE_FORMULA
;
191 case FIELD_PROP_PAR1
:
198 case FIELD_PROP_FORMAT
:
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */