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