LibreOffice Module sw (master) 1
cellatr.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 <calc.hxx>
21#include <cellatr.hxx>
22#include <doc.hxx>
23#include <float.h>
24#include <hintids.hxx>
25#include <hints.hxx>
26#include <node.hxx>
27#include <rolbck.hxx>
28#include <rtl/ustring.hxx>
29#include <calbck.hxx>
30#include <swtable.hxx>
31
32// The % SV_COUNTRY_LANGUAGE_OFFSET result checks if nFormat is a mere built-in
33// @ Text format of *any* locale and if so uses the default text format. Text
34// is text, the locale doesn't matter for Writer's number formatting purposes.
35// The advantage is that this is the pool's default item value and some places
36// benefit from this special treatment in that they don't have to handle/store
37// attribute specifics, especially when writing a document.
41 getSwDefaultTextFormat() : nFormat))
42{
43}
44
46{
47 assert(SfxPoolItem::operator==(rAttr));
48 return GetValue() == static_cast<const SwTableBoxNumFormat&>(rAttr).GetValue();
49}
50
52{
53 return new SwTableBoxNumFormat( GetValue() );
54}
55
56SwTableBoxFormula::SwTableBoxFormula( const OUString& rFormula )
58 SwTableFormula( rFormula ),
59 m_pDefinedIn( nullptr )
60{
61}
62
64{
65 assert(SfxPoolItem::operator==(rAttr));
66 return GetFormula() == static_cast<const SwTableBoxFormula&>(rAttr).GetFormula() &&
67 m_pDefinedIn == static_cast<const SwTableBoxFormula&>(rAttr).m_pDefinedIn;
68}
69
71{
72 // switch to external rendering
74 pNew->SwTableFormula::operator=( *this );
75 return pNew;
76}
77
86{
87 auto pTableBox = GetTableBox();
88 return pTableBox ? pTableBox->GetSttNd() : nullptr;
89}
90
92{
93 assert(!m_pDefinedIn || dynamic_cast<SwTableBoxFormat*>(m_pDefinedIn));
94 return m_pDefinedIn ? static_cast<SwTableBoxFormat*>(m_pDefinedIn)->GetTableBox() : nullptr;
95}
96
98{
99 const SwNode* pNd = GetNodeOfFormula();
100 if (!pNd || &pNd->GetNodes() != &pNd->GetDoc().GetNodes())
101 return;
102 if(const SwTableNode* pTableNd = pNd->FindTableNode())
103 {
104 BoxNmToPtr(&pTableNd->GetTable());
105 }
106}
108{
109 if(!pHistory)
110 {
111 ToSplitMergeBoxNm(rUpdate);
112 return;
113 }
114 auto pNd = GetNodeOfFormula();
115 // for a history record the unchanged formula is needed
116 SwTableBoxFormula aCopy(*this);
117 rUpdate.m_bModified = false;
118 ToSplitMergeBoxNm(rUpdate);
119 if(rUpdate.m_bModified)
120 {
121 // external rendering
122 aCopy.PtrToBoxNm(&pNd->FindTableNode()->GetTable());
123 pHistory->Add(
124 &aCopy,
125 &aCopy,
126 pNd->FindTableBoxStartNode()->GetIndex());
127 }
128}
129
130void SwTableBoxFormula::Calc( SwTableCalcPara& rCalcPara, double& rValue )
131{
132 if( !rCalcPara.m_rCalc.IsCalcError() )
133 {
134 // create pointers from box names
135 BoxNmToPtr( rCalcPara.m_pTable );
136 const OUString sFormula( MakeFormula( rCalcPara ));
137 if( !rCalcPara.m_rCalc.IsCalcError() )
138 rValue = rCalcPara.m_rCalc.Calculate( sFormula ).GetDouble();
139 else
140 rValue = DBL_MAX;
141 ChgValid( !rCalcPara.IsStackOverflow() ); // value is now valid again
142 }
143}
144
146 : SfxPoolItem( RES_BOXATR_VALUE ), m_nValue( 0 )
147{
148}
149
151 : SfxPoolItem( RES_BOXATR_VALUE ), m_nValue( nVal )
152{
153}
154
155bool SwTableBoxValue::operator==( const SfxPoolItem& rAttr ) const
156{
157 assert(SfxPoolItem::operator==(rAttr));
158 SwTableBoxValue const& rOther( static_cast<SwTableBoxValue const&>(rAttr) );
159 // items with NaN should be equal to enable pooling
160 return std::isnan( m_nValue )
161 ? std::isnan( rOther.m_nValue )
162 : ( m_nValue == rOther.m_nValue );
163}
164
166{
167 return new SwTableBoxValue( m_nValue );
168}
169
170/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr sal_uInt32 getSwDefaultTextFormat()
The number formatter's default locale's @ Text format.
Definition: cellatr.hxx:37
sal_uInt32 GetValue() const
SwSbxValue Calculate(const OUString &rStr)
Definition: calc.cxx:363
bool IsCalcError() const
Definition: calc.hxx:256
SwNodes & GetNodes()
Definition: doc.hxx:422
void Add(const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue, SwNodeOffset nNodeIdx)
Definition: rolbck.cxx:1029
Base class of the Writer document model elements.
Definition: node.hxx:98
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:706
SwDoc & GetDoc()
Definition: node.hxx:233
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:380
double GetDouble() const
Definition: calc.cxx:1468
virtual const SwNode * GetNodeOfFormula() const override
Get node type of the node containing this formula.
Definition: cellatr.cxx:85
SwTableBoxFormula(const OUString &rFormula)
Definition: cellatr.cxx:56
void ToSplitMergeBoxNmWithHistory(SwTableFormulaUpdate &rUpdate, SwHistory *pHistory)
Definition: cellatr.cxx:107
virtual bool operator==(const SfxPoolItem &) const override
Definition: cellatr.cxx:63
sw::BroadcastingModify * m_pDefinedIn
Definition: cellatr.hxx:57
SwTableBox * GetTableBox()
Definition: cellatr.cxx:91
void TryBoxNmToPtr()
Definition: cellatr.cxx:97
virtual SwTableBoxFormula * Clone(SfxItemPool *pPool=nullptr) const override
Definition: cellatr.cxx:70
void Calc(SwTableCalcPara &rCalcPara, double &rValue)
Definition: cellatr.cxx:130
virtual bool operator==(const SfxPoolItem &) const override
Definition: cellatr.cxx:45
virtual SwTableBoxNumFormat * Clone(SfxItemPool *pPool=nullptr) const override
Definition: cellatr.cxx:51
SwTableBoxNumFormat(sal_uInt32 nFormat=getSwDefaultTextFormat())
Definition: cellatr.cxx:38
double m_nValue
Definition: cellatr.hxx:97
virtual bool operator==(const SfxPoolItem &) const override
Definition: cellatr.cxx:155
virtual SwTableBoxValue * Clone(SfxItemPool *pPool=nullptr) const override
Definition: cellatr.cxx:165
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:443
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
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
void ToSplitMergeBoxNm(SwTableFormulaUpdate &rTableUpd)
gets called before/after merging/splitting of tables
Definition: cellfml.cxx:1241
void PtrToBoxNm(const SwTable *pTable)
create from the internal formula (for CORE) the external formula (for UI)
Definition: cellfml.cxx:580
OString sFormula
constexpr TypedWhichId< SwTableBoxValue > RES_BOXATR_VALUE(158)
constexpr TypedWhichId< SwTableBoxFormula > RES_BOXATR_FORMULA(157)
constexpr TypedWhichId< SwTableBoxNumFormat > RES_BOXATR_FORMAT(RES_BOXATR_BEGIN)
#define SV_COUNTRY_LANGUAGE_OFFSET