update dev300-m57
[ooovba.git] / sc / source / core / tool / cellform.cxx
blobe6177b01def6a8755a09432f3492e212c81bbf8a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cellform.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
33 // INCLUDE ---------------------------------------------------------------
35 #include <sfx2/objsh.hxx>
36 #include <svtools/smplhint.hxx>
37 #include <svtools/zforlist.hxx>
39 #include "cellform.hxx"
40 #include "cell.hxx"
41 #include "document.hxx"
42 #include "formula/errorcodes.hxx"
43 #include "sc.hrc"
45 // STATIC DATA -----------------------------------------------------------
47 // Err527 Workaround
48 const ScFormulaCell* pLastFormulaTreeTop = 0;
50 // -----------------------------------------------------------------------
52 void ScCellFormat::GetString( ScBaseCell* pCell, ULONG nFormat, String& rString,
53 Color** ppColor, SvNumberFormatter& rFormatter,
54 BOOL bNullVals,
55 BOOL bFormula,
56 ScForceTextFmt eForceTextFmt )
58 *ppColor = NULL;
59 if (&rFormatter==NULL)
61 rString.Erase();
62 return;
65 CellType eType = pCell->GetCellType();
66 switch(eType)
68 case CELLTYPE_STRING:
70 String aCellString;
71 ((ScStringCell*)pCell)->GetString( aCellString );
72 rFormatter.GetOutputString( aCellString, nFormat, rString, ppColor );
74 break;
75 case CELLTYPE_EDIT:
77 String aCellString;
78 ((ScEditCell*)pCell)->GetString( aCellString );
79 rFormatter.GetOutputString( aCellString, nFormat, rString, ppColor );
81 break;
82 case CELLTYPE_VALUE:
84 double nValue = ((ScValueCell*)pCell)->GetValue();
85 if ( !bNullVals && nValue == 0.0 )
86 rString.Erase();
87 else
89 if( eForceTextFmt == ftCheck )
91 if( nFormat && rFormatter.IsTextFormat( nFormat ) )
92 eForceTextFmt = ftForce;
94 if( eForceTextFmt == ftForce )
96 String aTemp;
97 rFormatter.GetOutputString( nValue, 0, aTemp, ppColor );
98 rFormatter.GetOutputString( aTemp, nFormat, rString, ppColor );
100 else
101 rFormatter.GetOutputString( nValue, nFormat, rString, ppColor );
104 break;
105 case CELLTYPE_FORMULA:
107 ScFormulaCell* pFCell = (ScFormulaCell*)pCell;
108 if ( bFormula )
109 pFCell->GetFormula( rString );
110 else
112 // #62160# Ein via Interpreter gestartetes Makro, das hart
113 // auf Formelzellen zugreift, bekommt einen CellText, auch
114 // wenn dadurch ein weiterer Interpreter gestartet wird,
115 // aber nicht wenn diese Zelle gerade interpretiert wird.
116 // IdleCalc startet generell keine weiteren Interpreter,
117 // um keine Err522 (zirkulaer) zu bekommen.
118 if ( pFCell->GetDocument()->IsInInterpreter() &&
119 (!pFCell->GetDocument()->GetMacroInterpretLevel()
120 || pFCell->IsRunning()) )
122 rString.AssignAscii( RTL_CONSTASCII_STRINGPARAM("...") );
124 else
126 USHORT nErrCode = pFCell->GetErrCode();
128 // erst nach dem Interpretieren (GetErrCode) das Zahlformat holen:
129 if ( (nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 )
130 nFormat = pFCell->GetStandardFormat( rFormatter,
131 nFormat );
133 if (nErrCode != 0)
134 rString = ScGlobal::GetErrorString(nErrCode);
135 else if ( pFCell->IsEmptyDisplayedAsString() )
136 rString.Erase();
137 else if ( pFCell->IsValue() )
139 double fValue = pFCell->GetValue();
140 if ( !bNullVals && fValue == 0.0 )
141 rString.Erase();
142 else
143 rFormatter.GetOutputString( fValue, nFormat, rString, ppColor );
145 else
147 String aCellString;
148 pFCell->GetString( aCellString );
149 rFormatter.GetOutputString( aCellString, nFormat, rString, ppColor );
154 break;
155 default:
156 rString.Erase();
157 break;
161 void ScCellFormat::GetInputString( ScBaseCell* pCell, ULONG nFormat, String& rString,
162 SvNumberFormatter& rFormatter )
164 if (&rFormatter==NULL)
166 rString.Erase();
167 return;
170 CellType eType = pCell->GetCellType();
171 switch(eType)
173 case CELLTYPE_STRING:
175 ((ScStringCell*)pCell)->GetString( rString );
177 break;
178 case CELLTYPE_EDIT:
180 ((ScEditCell*)pCell)->GetString( rString );
182 break;
183 case CELLTYPE_VALUE:
185 double nValue = ((ScValueCell*)pCell)->GetValue();
186 rFormatter.GetInputLineString( nValue, nFormat, rString );
188 break;
189 case CELLTYPE_FORMULA:
191 if (((ScFormulaCell*)pCell)->IsEmptyDisplayedAsString())
193 rString.Erase();
195 else if (((ScFormulaCell*)pCell)->IsValue())
197 double nValue = ((ScFormulaCell*)pCell)->GetValue();
198 rFormatter.GetInputLineString( nValue, nFormat, rString );
200 else
202 ((ScFormulaCell*)pCell)->GetString( rString );
205 USHORT nErrCode = ((ScFormulaCell*)pCell)->GetErrCode();
206 if (nErrCode != 0)
208 rString.Erase();
211 break;
212 default:
213 rString.Erase();
214 break;