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 "cellform.hxx"
22 #include <sfx2/objsh.hxx>
23 #include <svl/smplhint.hxx>
24 #include <svl/zforlist.hxx>
25 #include "svl/sharedstring.hxx"
27 #include "formulacell.hxx"
28 #include "document.hxx"
29 #include "cellvalue.hxx"
30 #include "formula/errorcodes.hxx"
35 const ScFormulaCell
* pLastFormulaTreeTop
= 0;
37 void ScCellFormat::GetString( ScRefCellValue
& rCell
, sal_uLong nFormat
, OUString
& rString
,
38 Color
** ppColor
, SvNumberFormatter
& rFormatter
, const ScDocument
* pDoc
,
39 bool bNullVals
, bool bFormula
, ScForceTextFmt eForceTextFmt
,
43 if (&rFormatter
==NULL
)
45 rString
= EMPTY_OUSTRING
;
52 rFormatter
.GetOutputString(rCell
.mpString
->getString(), nFormat
, rString
, ppColor
, bUseStarFormat
);
55 rFormatter
.GetOutputString(rCell
.getString(pDoc
), nFormat
, rString
, ppColor
);
59 double nValue
= rCell
.mfValue
;
60 if (!bNullVals
&& nValue
== 0.0)
64 if( eForceTextFmt
== ftCheck
)
66 if( nFormat
&& rFormatter
.IsTextFormat( nFormat
) )
67 eForceTextFmt
= ftForce
;
69 if( eForceTextFmt
== ftForce
)
72 rFormatter
.GetOutputString( nValue
, 0, aTemp
, ppColor
);
73 rFormatter
.GetOutputString( aTemp
, nFormat
, rString
, ppColor
);
76 rFormatter
.GetOutputString( nValue
, nFormat
, rString
, ppColor
, bUseStarFormat
);
80 case CELLTYPE_FORMULA
:
82 ScFormulaCell
* pFCell
= rCell
.mpFormula
;
85 pFCell
->GetFormula( rString
);
89 // A macro started from the interpreter, which has
90 // access to Formular Cells, becomes a CellText, even if
91 // that triggers further interpretation, except if those
92 // cells are already being interpreted.
93 // IdleCalc generally doesn't trigger futher interpretation,
94 // as not to get Err522 (circular).
95 if ( pFCell
->GetDocument()->IsInInterpreter() &&
96 (!pFCell
->GetDocument()->GetMacroInterpretLevel()
97 || pFCell
->IsRunning()) )
103 sal_uInt16 nErrCode
= pFCell
->GetErrCode();
106 rString
= ScGlobal::GetErrorString(nErrCode
);
107 else if ( pFCell
->IsEmptyDisplayedAsString() )
109 else if ( pFCell
->IsValue() )
111 double fValue
= pFCell
->GetValue();
112 if ( !bNullVals
&& fValue
== 0.0 )
114 else if ( pFCell
->IsHybridValueCell() )
115 rString
= pFCell
->GetString().getString();
117 rFormatter
.GetOutputString( fValue
, nFormat
, rString
, ppColor
, bUseStarFormat
);
121 OUString aCellString
= pFCell
->GetString().getString();
122 rFormatter
.GetOutputString( aCellString
, nFormat
, rString
, ppColor
, bUseStarFormat
);
134 OUString
ScCellFormat::GetString(
135 ScDocument
& rDoc
, const ScAddress
& rPos
, sal_uLong nFormat
, Color
** ppColor
,
136 SvNumberFormatter
& rFormatter
, bool bNullVals
, bool bFormula
, ScForceTextFmt eForceTextFmt
,
137 bool bUseStarFormat
)
142 CellType eType
= rDoc
.GetCellType(rPos
);
145 case CELLTYPE_STRING
:
147 ScRefCellValue aCell
;
148 aCell
.assign(rDoc
, rPos
);
149 rFormatter
.GetOutputString(aCell
.mpString
->getString(), nFormat
, aString
, ppColor
, bUseStarFormat
);
154 ScRefCellValue aCell
;
155 aCell
.assign(rDoc
, rPos
);
156 rFormatter
.GetOutputString(aCell
.getString(&rDoc
), nFormat
, aString
, ppColor
);
161 double nValue
= rDoc
.GetValue(rPos
);
162 if (!bNullVals
&& nValue
== 0.0) aString
= "";
165 if (eForceTextFmt
== ftCheck
)
167 if (nFormat
&& rFormatter
.IsTextFormat(nFormat
)) eForceTextFmt
= ftForce
;
169 if (eForceTextFmt
== ftForce
)
172 rFormatter
.GetOutputString(nValue
, 0, aTemp
, ppColor
);
173 rFormatter
.GetOutputString(aTemp
, nFormat
, aString
, ppColor
);
175 else rFormatter
.GetOutputString(nValue
, nFormat
, aString
, ppColor
, bUseStarFormat
);
179 case CELLTYPE_FORMULA
:
181 ScFormulaCell
* pFCell
= rDoc
.GetFormulaCell(rPos
);
184 pFCell
->GetFormula(aString
);
188 // A macro started from the interpreter, which has
189 // access to Formular Cells, becomes a CellText, even if
190 // that triggers further interpretation, except if those
191 // cells are already being interpreted.
192 // IdleCalc generally doesn't trigger futher interpretation,
193 // as not to get Err522 (circular).
194 if (pFCell
->GetDocument()->IsInInterpreter() &&
195 (!pFCell
->GetDocument()->GetMacroInterpretLevel()
196 || pFCell
->IsRunning()))
202 sal_uInt16 nErrCode
= pFCell
->GetErrCode();
204 if (nErrCode
!= 0) aString
= ScGlobal::GetErrorString(nErrCode
);
205 else if (pFCell
->IsEmptyDisplayedAsString()) aString
= "";
206 else if (pFCell
->IsValue())
208 double fValue
= pFCell
->GetValue();
209 if (!bNullVals
&& fValue
== 0.0) aString
= "";
210 else if (pFCell
->IsHybridValueCell()) aString
= pFCell
->GetString().getString();
211 else rFormatter
.GetOutputString(fValue
, nFormat
, aString
, ppColor
, bUseStarFormat
);
215 OUString aCellString
= pFCell
->GetString().getString();
216 rFormatter
.GetOutputString(aCellString
, nFormat
, aString
, ppColor
, bUseStarFormat
);
228 void ScCellFormat::GetInputString(
229 ScRefCellValue
& rCell
, sal_uLong nFormat
, OUString
& rString
, SvNumberFormatter
& rFormatter
, const ScDocument
* pDoc
)
231 if (&rFormatter
== NULL
)
233 rString
= EMPTY_OUSTRING
;
237 OUString aString
= rString
;
238 switch (rCell
.meType
)
240 case CELLTYPE_STRING
:
242 aString
= rCell
.getString(pDoc
);
245 rFormatter
.GetInputLineString(rCell
.mfValue
, nFormat
, aString
);
247 case CELLTYPE_FORMULA
:
249 ScFormulaCell
* pFC
= rCell
.mpFormula
;
250 if (pFC
->IsEmptyDisplayedAsString())
251 aString
= EMPTY_OUSTRING
;
252 else if (pFC
->IsValue())
253 rFormatter
.GetInputLineString(pFC
->GetValue(), nFormat
, aString
);
255 aString
= pFC
->GetString().getString();
257 sal_uInt16 nErrCode
= pFC
->GetErrCode();
259 aString
= EMPTY_OUSTRING
;
263 aString
= EMPTY_OUSTRING
;
269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */