1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sc.hxx" 30 // INCLUDE --------------------------------------------------------------- 31 32 #include <sfx2/objsh.hxx> 33 #include <svl/smplhint.hxx> 34 #include <svl/zforlist.hxx> 35 36 #include "cellform.hxx" 37 #include "cell.hxx" 38 #include "document.hxx" 39 #include "formula/errorcodes.hxx" 40 #include "sc.hrc" 41 42 // STATIC DATA ----------------------------------------------------------- 43 44 // Err527 Workaround 45 const ScFormulaCell* pLastFormulaTreeTop = 0; 46 47 // ----------------------------------------------------------------------- 48 49 void ScCellFormat::GetString( ScBaseCell* pCell, sal_uLong nFormat, String& rString, 50 Color** ppColor, SvNumberFormatter& rFormatter, 51 sal_Bool bNullVals, 52 sal_Bool bFormula, 53 ScForceTextFmt eForceTextFmt ) 54 { 55 *ppColor = NULL; 56 if (&rFormatter==NULL) 57 { 58 rString.Erase(); 59 return; 60 } 61 62 CellType eType = pCell->GetCellType(); 63 switch(eType) 64 { 65 case CELLTYPE_STRING: 66 { 67 String aCellString; 68 ((ScStringCell*)pCell)->GetString( aCellString ); 69 rFormatter.GetOutputString( aCellString, nFormat, rString, ppColor ); 70 } 71 break; 72 case CELLTYPE_EDIT: 73 { 74 String aCellString; 75 ((ScEditCell*)pCell)->GetString( aCellString ); 76 rFormatter.GetOutputString( aCellString, nFormat, rString, ppColor ); 77 } 78 break; 79 case CELLTYPE_VALUE: 80 { 81 double nValue = ((ScValueCell*)pCell)->GetValue(); 82 if ( !bNullVals && nValue == 0.0 ) 83 rString.Erase(); 84 else 85 { 86 if( eForceTextFmt == ftCheck ) 87 { 88 if( nFormat && rFormatter.IsTextFormat( nFormat ) ) 89 eForceTextFmt = ftForce; 90 } 91 if( eForceTextFmt == ftForce ) 92 { 93 String aTemp; 94 rFormatter.GetOutputString( nValue, 0, aTemp, ppColor ); 95 rFormatter.GetOutputString( aTemp, nFormat, rString, ppColor ); 96 } 97 else 98 rFormatter.GetOutputString( nValue, nFormat, rString, ppColor ); 99 } 100 } 101 break; 102 case CELLTYPE_FORMULA: 103 { 104 ScFormulaCell* pFCell = (ScFormulaCell*)pCell; 105 if ( bFormula ) 106 pFCell->GetFormula( rString ); 107 else 108 { 109 // #62160# Ein via Interpreter gestartetes Makro, das hart 110 // auf Formelzellen zugreift, bekommt einen CellText, auch 111 // wenn dadurch ein weiterer Interpreter gestartet wird, 112 // aber nicht wenn diese Zelle gerade interpretiert wird. 113 // IdleCalc startet generell keine weiteren Interpreter, 114 // um keine Err522 (zirkulaer) zu bekommen. 115 if ( pFCell->GetDocument()->IsInInterpreter() && 116 (!pFCell->GetDocument()->GetMacroInterpretLevel() 117 || pFCell->IsRunning()) ) 118 { 119 rString.AssignAscii( RTL_CONSTASCII_STRINGPARAM("...") ); 120 } 121 else 122 { 123 sal_uInt16 nErrCode = pFCell->GetErrCode(); 124 125 // erst nach dem Interpretieren (GetErrCode) das Zahlformat holen: 126 if ( (nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 ) 127 nFormat = pFCell->GetStandardFormat( rFormatter, 128 nFormat ); 129 130 if (nErrCode != 0) 131 rString = ScGlobal::GetErrorString(nErrCode); 132 else if ( pFCell->IsEmptyDisplayedAsString() ) 133 rString.Erase(); 134 else if ( pFCell->IsValue() ) 135 { 136 double fValue = pFCell->GetValue(); 137 if ( !bNullVals && fValue == 0.0 ) 138 rString.Erase(); 139 else 140 rFormatter.GetOutputString( fValue, nFormat, rString, ppColor ); 141 } 142 else 143 { 144 String aCellString; 145 pFCell->GetString( aCellString ); 146 rFormatter.GetOutputString( aCellString, nFormat, rString, ppColor ); 147 } 148 } 149 } 150 } 151 break; 152 default: 153 rString.Erase(); 154 break; 155 } 156 } 157 158 void ScCellFormat::GetInputString( ScBaseCell* pCell, sal_uLong nFormat, String& rString, 159 SvNumberFormatter& rFormatter ) 160 { 161 if (&rFormatter==NULL) 162 { 163 rString.Erase(); 164 return; 165 } 166 167 CellType eType = pCell->GetCellType(); 168 switch(eType) 169 { 170 case CELLTYPE_STRING: 171 { 172 ((ScStringCell*)pCell)->GetString( rString ); 173 } 174 break; 175 case CELLTYPE_EDIT: 176 { 177 ((ScEditCell*)pCell)->GetString( rString ); 178 } 179 break; 180 case CELLTYPE_VALUE: 181 { 182 double nValue = ((ScValueCell*)pCell)->GetValue(); 183 rFormatter.GetInputLineString( nValue, nFormat, rString ); 184 } 185 break; 186 case CELLTYPE_FORMULA: 187 { 188 if (((ScFormulaCell*)pCell)->IsEmptyDisplayedAsString()) 189 { 190 rString.Erase(); 191 } 192 else if (((ScFormulaCell*)pCell)->IsValue()) 193 { 194 double nValue = ((ScFormulaCell*)pCell)->GetValue(); 195 rFormatter.GetInputLineString( nValue, nFormat, rString ); 196 } 197 else 198 { 199 ((ScFormulaCell*)pCell)->GetString( rString ); 200 } 201 202 sal_uInt16 nErrCode = ((ScFormulaCell*)pCell)->GetErrCode(); 203 if (nErrCode != 0) 204 { 205 rString.Erase(); 206 } 207 } 208 break; 209 default: 210 rString.Erase(); 211 break; 212 } 213 } 214 215 216 217