LibreOffice Module sw (master) 1
tblcalc.cxx
Go to the documentation of this file.
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 <sal/config.h>
21
22#include <o3tl/any.hxx>
23
24#include <calc.hxx>
25#include <doc.hxx>
26#include <ndtxt.hxx>
27#include <fmtfld.hxx>
28#include <txtfld.hxx>
29#include <expfld.hxx>
30#include <unofldmid.h>
31
32using namespace ::com::sun::star;
33
35 : SwValueFieldType( pDocPtr, SwFieldIds::Table )
36{}
37
38std::unique_ptr<SwFieldType> SwTableFieldType::Copy() const
39{
40 return std::make_unique<SwTableFieldType>(GetDoc());
41}
42
44{
45 if( rCalcPara.m_rCalc.IsCalcError() ) // stop if there is already an error set
46 return;
47
48 // create pointers from box name
49 BoxNmToPtr( rCalcPara.m_pTable );
50 OUString sFormula( MakeFormula( rCalcPara ));
52 ChgValid( !rCalcPara.IsStackOverflow() ); // is the value again valid?
53}
54
55SwTableField::SwTableField( SwTableFieldType* pInitType, const OUString& rFormel,
56 sal_uInt16 nType, sal_uLong nFormat )
57 : SwValueField( pInitType, nFormat ), SwTableFormula( rFormel ),
58 m_nSubType(nType)
59{
60 m_sExpand = "0";
61}
62
63std::unique_ptr<SwField> SwTableField::Copy() const
64{
65 std::unique_ptr<SwTableField> pTmp(new SwTableField( static_cast<SwTableFieldType*>(GetTyp()),
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());
72}
73
75{
76 return GetTyp()->GetName() + " " + const_cast<SwTableField *>(this)->GetCommand();
77}
78
81{
82 auto pFormat = GetTyp()->FindFormatForField(this);
83 return pFormat ? &pFormat->GetTextField()->GetTextNode() : nullptr;
84}
85
87{
88 if (EXTRNL_NAME != GetNameType())
89 {
90 SwNode const*const pNd = GetNodeOfFormula();
91 SwTableNode const*const pTableNd = pNd ? pNd->FindTableNode() : nullptr;
92 if (pTableNd)
93 {
94 PtrToBoxNm( &pTableNd->GetTable() );
95 }
96 }
97 return (EXTRNL_NAME == GetNameType())
99 : OUString();
100}
101
102OUString SwTableField::ExpandImpl(SwRootFrame const*const) const
103{
105 {
106 return const_cast<SwTableField *>(this)->GetCommand();
107 }
108
110 {
111 // it is a string
112 return m_sExpand.copy(1, m_sExpand.getLength()-2);
113 }
114
115 return m_sExpand;
116}
117
118sal_uInt16 SwTableField::GetSubType() const
119{
120 return m_nSubType;
121}
122
123void SwTableField::SetSubType(sal_uInt16 nType)
124{
126}
127
128void SwTableField::SetValue( const double& rVal )
129{
131 m_sExpand = static_cast<SwValueFieldType*>(GetTyp())->ExpandValue(rVal, GetFormat(), GetLanguage());
132}
133
134OUString SwTableField::GetPar2() const
135{
137}
138
139void SwTableField::SetPar2(const OUString& rStr)
140{
141 SetFormula( rStr );
142}
143
144bool SwTableField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
145{
146 bool bRet = true;
147 switch ( nWhichId )
148 {
149 case FIELD_PROP_PAR2:
150 {
151 sal_uInt16 nOldSubType = m_nSubType;
152 SwTableField* pThis = const_cast<SwTableField*>(this);
154 rAny <<= ExpandImpl(nullptr);
155 pThis->m_nSubType = nOldSubType;
156 }
157 break;
158 case FIELD_PROP_BOOL1:
160 break;
161 case FIELD_PROP_PAR1:
162 rAny <<= m_sExpand;
163 break;
165 rAny <<= static_cast<sal_Int32>(GetFormat());
166 break;
167 default:
168 bRet = false;
169 }
170 return bRet;
171}
172
173bool SwTableField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
174{
175 bool bRet = true;
176 switch ( nWhichId )
177 {
178 case FIELD_PROP_PAR2:
179 {
180 OUString sTmp;
181 rAny >>= sTmp;
182 SetFormula( sTmp );
183 }
184 break;
185 case FIELD_PROP_BOOL1:
186 if(*o3tl::doAccess<bool>(rAny))
188 else
190 break;
191 case FIELD_PROP_PAR1:
192 {
193 OUString sTmp;
194 rAny >>= sTmp;
195 ChgExpStr( sTmp );
196 }
197 break;
199 {
200 sal_Int32 nTmp = 0;
201 rAny >>= nTmp;
202 SetFormat(nTmp);
203 }
204 break;
205 default:
206 bRet = false;
207 }
208 return bRet;
209}
210
211/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwSbxValue Calculate(const OUString &rStr)
Definition: calc.cxx:363
bool IsCalcError() const
Definition: calc.hxx:256
Definition: doc.hxx:197
virtual OUString GetName() const
Only in derived classes.
Definition: fldbas.cxx:139
SwFormatField * FindFormatForField(const SwField *) const
Definition: fldbas.cxx:171
bool IsAutomaticLanguage() const
Definition: fldbas.hxx:387
void SetFormat(sal_uInt32 const nSet)
Definition: fldbas.hxx:311
sal_uInt32 GetFormat() const
Query parameters for dialog and for BASIC.
Definition: fldbas.hxx:407
SwFieldType * GetTyp() const
Definition: fldbas.hxx:402
LanguageType GetLanguage() const
Language at field position.
Definition: fldbas.hxx:412
const SwTextField * GetTextField() const
Definition: fmtfld.hxx:149
Base class of the Writer document model elements.
Definition: node.hxx:98
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:380
The root element of a Writer document layout.
Definition: rootfrm.hxx:85
double GetDouble() const
Definition: calc.cxx:1468
SwCalc & m_rCalc
current Calculator
Definition: cellfml.hxx:47
const SwTable * m_pTable
current table
Definition: cellfml.hxx:48
bool IsStackOverflow() const
Definition: cellfml.hxx:54
Implementation in tblcalc.cxx.
Definition: expfld.hxx:374
virtual std::unique_ptr< SwFieldType > Copy() const override
Definition: tblcalc.cxx:38
SwTableFieldType(SwDoc *pDocPtr)
Definition: tblcalc.cxx:34
void CalcField(SwTableCalcPara &rCalcPara)
Definition: tblcalc.cxx:43
virtual std::unique_ptr< SwField > Copy() const override
Definition: tblcalc.cxx:63
void ChgExpStr(const OUString &rStr)
Definition: expfld.hxx:402
virtual void SetSubType(sal_uInt16 nType) override
Definition: tblcalc.cxx:123
virtual const SwNode * GetNodeOfFormula() const override
Search TextNode containing the field.
Definition: tblcalc.cxx:80
virtual OUString GetFieldName() const override
get name or content
Definition: tblcalc.cxx:74
OUString GetCommand()
Definition: tblcalc.cxx:86
SwTableField(SwTableFieldType *, const OUString &rFormel, sal_uInt16 nSubType, sal_uLong nFormat)
Definition: tblcalc.cxx:55
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhich) override
Definition: tblcalc.cxx:173
virtual void SetPar2(const OUString &rStr) override
Definition: tblcalc.cxx:139
virtual void SetValue(const double &rVal) override
Definition: tblcalc.cxx:128
virtual OUString ExpandImpl(SwRootFrame const *pLayout) const override
Definition: tblcalc.cxx:102
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const override
Definition: tblcalc.cxx:144
OUString m_sExpand
Definition: expfld.hxx:383
virtual OUString GetPar2() const override
The formula.
Definition: tblcalc.cxx:134
virtual sal_uInt16 GetSubType() const override
Definition: tblcalc.cxx:118
sal_uInt16 m_nSubType
Definition: expfld.hxx:384
void ChgValid(bool bNew)
Definition: cellfml.hxx:135
OUString MakeFormula(SwTableCalcPara &rCalcPara) const
Definition: cellfml.hxx:106
const OUString & GetFormula() const
Definition: cellfml.hxx:137
void BoxNmToPtr(const SwTable *pTable)
create from the external formula the internal
Definition: cellfml.cxx:605
NameType GetNameType() const
Definition: cellfml.hxx:132
void PtrToBoxNm(const SwTable *pTable)
create from the internal formula (for CORE) the external formula (for UI)
Definition: cellfml.cxx:580
void SetFormula(const OUString &rNew)
Definition: cellfml.hxx:138
const SwTable & GetTable() const
Definition: node.hxx:542
SwTextNode & GetTextNode() const
Definition: txtfld.hxx:53
Fields containing values that have to be formatted via number formatter.
Definition: fldbas.hxx:419
SwDoc * GetDoc() const
Definition: fldbas.hxx:429
OUString ExpandValue(const double &rVal, sal_uInt32 nFormat, LanguageType nLng) const
Definition: fldbas.hxx:472
virtual double GetValue() const
Definition: fldbas.cxx:799
virtual void SetValue(const double &rVal)
Definition: fldbas.cxx:804
OString sFormula
SwFieldIds
Definition: fldbas.hxx:49
const SwExtendedSubType SUB_CMD
Show command.
Definition: fldbas.hxx:216
const SwGetSetExpType GSE_FORMULA
Formula.
Definition: fldbas.hxx:210
const SwGetSetExpType GSE_STRING
String.
Definition: fldbas.hxx:207
QPRO_FUNC_TYPE nType
sal_uIntPtr sal_uLong
#define FIELD_PROP_BOOL1
Definition: unofldmid.h:28
#define FIELD_PROP_FORMAT
Definition: unofldmid.h:26
#define FIELD_PROP_PAR1
Definition: unofldmid.h:23
#define FIELD_PROP_PAR2
Definition: unofldmid.h:24