1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5b3f79822SAndrew Rist * distributed with this work for additional information
6b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist * software distributed under the License is distributed on an
15b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17b3f79822SAndrew Rist * specific language governing permissions and limitations
18b3f79822SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20b3f79822SAndrew Rist *************************************************************/
21b3f79822SAndrew Rist
22b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include <sfx2/objsh.hxx>
29cdf0e10cSrcweir #include <svl/smplhint.hxx>
30cdf0e10cSrcweir #include <svl/zforlist.hxx>
31*fe481f06SOliver-Rainer Wittmann #include <svl/zformat.hxx>
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include "cellform.hxx"
34cdf0e10cSrcweir #include "cell.hxx"
35cdf0e10cSrcweir #include "document.hxx"
36cdf0e10cSrcweir #include "formula/errorcodes.hxx"
37cdf0e10cSrcweir #include "sc.hrc"
38cdf0e10cSrcweir
39cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
40cdf0e10cSrcweir
41cdf0e10cSrcweir // Err527 Workaround
42cdf0e10cSrcweir const ScFormulaCell* pLastFormulaTreeTop = 0;
43cdf0e10cSrcweir
44cdf0e10cSrcweir // -----------------------------------------------------------------------
45cdf0e10cSrcweir
GetString(ScBaseCell * pCell,sal_uLong nFormat,String & rString,Color ** ppColor,SvNumberFormatter & rFormatter,sal_Bool bNullVals,sal_Bool bFormula,ScForceTextFmt eForceTextFmt)46cdf0e10cSrcweir void ScCellFormat::GetString( ScBaseCell* pCell, sal_uLong nFormat, String& rString,
47cdf0e10cSrcweir Color** ppColor, SvNumberFormatter& rFormatter,
48cdf0e10cSrcweir sal_Bool bNullVals,
49cdf0e10cSrcweir sal_Bool bFormula,
50cdf0e10cSrcweir ScForceTextFmt eForceTextFmt )
51cdf0e10cSrcweir {
52cdf0e10cSrcweir *ppColor = NULL;
53cdf0e10cSrcweir if (&rFormatter==NULL)
54cdf0e10cSrcweir {
55cdf0e10cSrcweir rString.Erase();
56cdf0e10cSrcweir return;
57cdf0e10cSrcweir }
58cdf0e10cSrcweir
59cdf0e10cSrcweir CellType eType = pCell->GetCellType();
60cdf0e10cSrcweir switch(eType)
61cdf0e10cSrcweir {
62cdf0e10cSrcweir case CELLTYPE_STRING:
63cdf0e10cSrcweir {
64cdf0e10cSrcweir String aCellString;
65cdf0e10cSrcweir ((ScStringCell*)pCell)->GetString( aCellString );
66cdf0e10cSrcweir rFormatter.GetOutputString( aCellString, nFormat, rString, ppColor );
67cdf0e10cSrcweir }
68cdf0e10cSrcweir break;
69cdf0e10cSrcweir case CELLTYPE_EDIT:
70cdf0e10cSrcweir {
71cdf0e10cSrcweir String aCellString;
72cdf0e10cSrcweir ((ScEditCell*)pCell)->GetString( aCellString );
73cdf0e10cSrcweir rFormatter.GetOutputString( aCellString, nFormat, rString, ppColor );
74cdf0e10cSrcweir }
75cdf0e10cSrcweir break;
76cdf0e10cSrcweir case CELLTYPE_VALUE:
77cdf0e10cSrcweir {
78cdf0e10cSrcweir double nValue = ((ScValueCell*)pCell)->GetValue();
79cdf0e10cSrcweir if ( !bNullVals && nValue == 0.0 )
80cdf0e10cSrcweir rString.Erase();
81cdf0e10cSrcweir else
82cdf0e10cSrcweir {
83cdf0e10cSrcweir if( eForceTextFmt == ftCheck )
84cdf0e10cSrcweir {
85cdf0e10cSrcweir if( nFormat && rFormatter.IsTextFormat( nFormat ) )
86cdf0e10cSrcweir eForceTextFmt = ftForce;
87cdf0e10cSrcweir }
88cdf0e10cSrcweir if( eForceTextFmt == ftForce )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir String aTemp;
91cdf0e10cSrcweir rFormatter.GetOutputString( nValue, 0, aTemp, ppColor );
92cdf0e10cSrcweir rFormatter.GetOutputString( aTemp, nFormat, rString, ppColor );
93cdf0e10cSrcweir }
94cdf0e10cSrcweir else
95cdf0e10cSrcweir rFormatter.GetOutputString( nValue, nFormat, rString, ppColor );
96cdf0e10cSrcweir }
97cdf0e10cSrcweir }
98cdf0e10cSrcweir break;
99cdf0e10cSrcweir case CELLTYPE_FORMULA:
100cdf0e10cSrcweir {
101cdf0e10cSrcweir ScFormulaCell* pFCell = (ScFormulaCell*)pCell;
102cdf0e10cSrcweir if ( bFormula )
103cdf0e10cSrcweir pFCell->GetFormula( rString );
104cdf0e10cSrcweir else
105cdf0e10cSrcweir {
106cdf0e10cSrcweir // #62160# Ein via Interpreter gestartetes Makro, das hart
107cdf0e10cSrcweir // auf Formelzellen zugreift, bekommt einen CellText, auch
108cdf0e10cSrcweir // wenn dadurch ein weiterer Interpreter gestartet wird,
109cdf0e10cSrcweir // aber nicht wenn diese Zelle gerade interpretiert wird.
110cdf0e10cSrcweir // IdleCalc startet generell keine weiteren Interpreter,
111cdf0e10cSrcweir // um keine Err522 (zirkulaer) zu bekommen.
112cdf0e10cSrcweir if ( pFCell->GetDocument()->IsInInterpreter() &&
113cdf0e10cSrcweir (!pFCell->GetDocument()->GetMacroInterpretLevel()
114cdf0e10cSrcweir || pFCell->IsRunning()) )
115cdf0e10cSrcweir {
116cdf0e10cSrcweir rString.AssignAscii( RTL_CONSTASCII_STRINGPARAM("...") );
117cdf0e10cSrcweir }
118cdf0e10cSrcweir else
119cdf0e10cSrcweir {
120cdf0e10cSrcweir sal_uInt16 nErrCode = pFCell->GetErrCode();
121cdf0e10cSrcweir
122cdf0e10cSrcweir // erst nach dem Interpretieren (GetErrCode) das Zahlformat holen:
123cdf0e10cSrcweir if ( (nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 )
124cdf0e10cSrcweir nFormat = pFCell->GetStandardFormat( rFormatter,
125cdf0e10cSrcweir nFormat );
126cdf0e10cSrcweir
127cdf0e10cSrcweir if (nErrCode != 0)
128cdf0e10cSrcweir rString = ScGlobal::GetErrorString(nErrCode);
129cdf0e10cSrcweir else if ( pFCell->IsEmptyDisplayedAsString() )
130cdf0e10cSrcweir rString.Erase();
131cdf0e10cSrcweir else if ( pFCell->IsValue() )
132cdf0e10cSrcweir {
133*fe481f06SOliver-Rainer Wittmann const SvNumberformat* pNumFmt = rFormatter.GetEntry( nFormat );
134*fe481f06SOliver-Rainer Wittmann const bool bHasTextFormatCode = pNumFmt != NULL && pNumFmt->HasTextFormatCode();
135*fe481f06SOliver-Rainer Wittmann if( pFCell->GetFormatType() == NUMBERFORMAT_LOGICAL && bHasTextFormatCode )
136056bc390SWang Lei {
137056bc390SWang Lei String aCellString;
138056bc390SWang Lei double fValue = pFCell->GetValue();
139056bc390SWang Lei if(fValue)
140056bc390SWang Lei aCellString = rFormatter.GetTrueString();
141056bc390SWang Lei else
142056bc390SWang Lei aCellString = rFormatter.GetFalseString();
143056bc390SWang Lei rFormatter.GetOutputString( aCellString, nFormat, rString, ppColor );
144056bc390SWang Lei
145056bc390SWang Lei }
146056bc390SWang Lei else
147056bc390SWang Lei {
148cdf0e10cSrcweir double fValue = pFCell->GetValue();
149cdf0e10cSrcweir if ( !bNullVals && fValue == 0.0 )
150cdf0e10cSrcweir rString.Erase();
151cdf0e10cSrcweir else
152cdf0e10cSrcweir rFormatter.GetOutputString( fValue, nFormat, rString, ppColor );
153cdf0e10cSrcweir }
154056bc390SWang Lei }
155cdf0e10cSrcweir else
156cdf0e10cSrcweir {
157cdf0e10cSrcweir String aCellString;
158cdf0e10cSrcweir pFCell->GetString( aCellString );
159cdf0e10cSrcweir rFormatter.GetOutputString( aCellString, nFormat, rString, ppColor );
160cdf0e10cSrcweir }
161cdf0e10cSrcweir }
162cdf0e10cSrcweir }
163cdf0e10cSrcweir }
164cdf0e10cSrcweir break;
165cdf0e10cSrcweir default:
166cdf0e10cSrcweir rString.Erase();
167cdf0e10cSrcweir break;
168cdf0e10cSrcweir }
169cdf0e10cSrcweir }
170cdf0e10cSrcweir
GetInputString(ScBaseCell * pCell,sal_uLong nFormat,String & rString,SvNumberFormatter & rFormatter)171cdf0e10cSrcweir void ScCellFormat::GetInputString( ScBaseCell* pCell, sal_uLong nFormat, String& rString,
172cdf0e10cSrcweir SvNumberFormatter& rFormatter )
173cdf0e10cSrcweir {
174cdf0e10cSrcweir if (&rFormatter==NULL)
175cdf0e10cSrcweir {
176cdf0e10cSrcweir rString.Erase();
177cdf0e10cSrcweir return;
178cdf0e10cSrcweir }
179cdf0e10cSrcweir
180cdf0e10cSrcweir CellType eType = pCell->GetCellType();
181cdf0e10cSrcweir switch(eType)
182cdf0e10cSrcweir {
183cdf0e10cSrcweir case CELLTYPE_STRING:
184cdf0e10cSrcweir {
185cdf0e10cSrcweir ((ScStringCell*)pCell)->GetString( rString );
186cdf0e10cSrcweir }
187cdf0e10cSrcweir break;
188cdf0e10cSrcweir case CELLTYPE_EDIT:
189cdf0e10cSrcweir {
190cdf0e10cSrcweir ((ScEditCell*)pCell)->GetString( rString );
191cdf0e10cSrcweir }
192cdf0e10cSrcweir break;
193cdf0e10cSrcweir case CELLTYPE_VALUE:
194cdf0e10cSrcweir {
195cdf0e10cSrcweir double nValue = ((ScValueCell*)pCell)->GetValue();
196cdf0e10cSrcweir rFormatter.GetInputLineString( nValue, nFormat, rString );
197cdf0e10cSrcweir }
198cdf0e10cSrcweir break;
199cdf0e10cSrcweir case CELLTYPE_FORMULA:
200cdf0e10cSrcweir {
201cdf0e10cSrcweir if (((ScFormulaCell*)pCell)->IsEmptyDisplayedAsString())
202cdf0e10cSrcweir {
203cdf0e10cSrcweir rString.Erase();
204cdf0e10cSrcweir }
205cdf0e10cSrcweir else if (((ScFormulaCell*)pCell)->IsValue())
206cdf0e10cSrcweir {
207cdf0e10cSrcweir double nValue = ((ScFormulaCell*)pCell)->GetValue();
208cdf0e10cSrcweir rFormatter.GetInputLineString( nValue, nFormat, rString );
209cdf0e10cSrcweir }
210cdf0e10cSrcweir else
211cdf0e10cSrcweir {
212cdf0e10cSrcweir ((ScFormulaCell*)pCell)->GetString( rString );
213cdf0e10cSrcweir }
214cdf0e10cSrcweir
215cdf0e10cSrcweir sal_uInt16 nErrCode = ((ScFormulaCell*)pCell)->GetErrCode();
216cdf0e10cSrcweir if (nErrCode != 0)
217cdf0e10cSrcweir {
218cdf0e10cSrcweir rString.Erase();
219cdf0e10cSrcweir }
220cdf0e10cSrcweir }
221cdf0e10cSrcweir break;
222cdf0e10cSrcweir default:
223cdf0e10cSrcweir rString.Erase();
224cdf0e10cSrcweir break;
225cdf0e10cSrcweir }
226cdf0e10cSrcweir }
227cdf0e10cSrcweir
228cdf0e10cSrcweir
229cdf0e10cSrcweir
230