update dev300-m58
[ooovba.git] / applied_patches / 0123-sc-string-arg.diff
blobfc9c139ff0dfcd56762239ecd6092e6aa574c971
1 diff --git sc/source/core/inc/interpre.hxx sc/source/core/inc/interpre.hxx
2 index b9b91a8..681766d 100644
3 --- sc/source/core/inc/interpre.hxx
4 +++ sc/source/core/inc/interpre.hxx
5 @@ -178,8 +178,18 @@ void ReplaceCell( ScAddress& ); // for TableOp
6 void ReplaceCell( SCCOL& rCol, SCROW& rRow, SCTAB& rTab ); // for TableOp
7 BOOL IsTableOpInRange( const ScRange& );
8 ULONG GetCellNumberFormat( const ScAddress&, const ScBaseCell* );
9 -double GetCellValue( const ScAddress&, const ScBaseCell* );
10 -double GetCellValueOrZero( const ScAddress&, const ScBaseCell* );
12 +/**
13 + * @param bNoValueAsError when true, cell having no numerical value
14 + * (errCellNoValue) is interpreted as a legitimate
15 + * no-value (errNoValue) error.
16 + * @param bBlankAsZero when true, a cell having a blank text value is
17 + * interpreted as a no-value error.
18 + *
19 + * @return double cell value.
20 + */
21 +double GetCellValue( const ScAddress&, const ScBaseCell*, bool bNoValueAsError = false, bool bBlankAsZero = false );
22 +double GetCellValueOrZero( const ScAddress&, const ScBaseCell*, bool bBlankAsZero );
23 double GetValueCellValue( const ScAddress&, const ScValueCell* );
24 ScBaseCell* GetCell( const ScAddress& rPos )
25 { return pDok->GetCell( rPos ); }
26 @@ -318,7 +328,7 @@ formula::StackVar GetStackType( BYTE nParam );
27 BYTE GetByte() { return cPar; }
28 // generiert aus DoubleRef positionsabhaengige SingleRef
29 BOOL DoubleRefToPosSingleRef( const ScRange& rRange, ScAddress& rAdr );
30 -double GetDouble();
31 +double GetDouble( bool bNoValueAsError = false, bool bBlankAsZero = false );
32 double GetDoubleWithDefault(double nDefault);
33 BOOL IsMissing();
34 BOOL GetBool() { return GetDouble() != 0.0; }
35 diff --git sc/source/core/tool/interpr1.cxx sc/source/core/tool/interpr1.cxx
36 index 5a6eb67..7e5a478 100644
37 --- sc/source/core/tool/interpr1.cxx
38 +++ sc/source/core/tool/interpr1.cxx
39 @@ -3189,12 +3189,13 @@ double ScInterpreter::IterateParameters( ScIterFunc eFunc, BOOL bTextAsZero )
40 nGlobalError = 0;
41 while (nParamCount-- > 0)
43 - switch (GetStackType())
44 + StackVar eStackType = GetStackType();
45 + switch (eStackType)
48 + case svDouble:
49 case svString:
51 - if( eFunc == ifCOUNT )
52 + if( eFunc == ifCOUNT && eStackType == svString )
54 String aStr( PopString() );
55 sal_uInt32 nFIndex = 0; // damit default Land/Spr.
56 @@ -3203,42 +3204,23 @@ double ScInterpreter::IterateParameters( ScIterFunc eFunc, BOOL bTextAsZero )
58 else
60 + if ( bTextAsZero && eStackType == svString )
61 + {
62 + Pop();
63 + nCount++;
64 + if ( eFunc == ifPRODUCT )
65 + fRes = 0.0;
66 + fVal = 0;
67 + }
68 + else
69 + {
70 + fVal = GetDouble();
71 + nCount++;
72 + }
73 switch ( eFunc )
75 case ifAVERAGE:
76 case ifSUM:
77 - case ifSUMSQ:
78 - case ifPRODUCT:
79 - {
80 - if ( bTextAsZero )
81 - {
82 - Pop();
83 - nCount++;
84 - if ( eFunc == ifPRODUCT )
85 - fRes = 0.0;
86 - }
87 - else
88 - {
89 - while (nParamCount-- > 0)
90 - Pop();
91 - SetError( errNoValue );
92 - }
93 - }
94 - break;
95 - default:
96 - Pop();
97 - nCount++;
98 - }
99 - }
101 - break;
102 - case svDouble :
103 - fVal = GetDouble();
104 - nCount++;
105 - switch( eFunc )
107 - case ifAVERAGE:
108 - case ifSUM:
109 if ( bNull && fVal != 0.0 )
111 bNull = FALSE;
112 @@ -3247,12 +3229,15 @@ double ScInterpreter::IterateParameters( ScIterFunc eFunc, BOOL bTextAsZero )
113 else
114 fRes += fVal;
115 break;
116 - case ifSUMSQ: fRes += fVal * fVal; break;
117 - case ifPRODUCT: fRes *= fVal; break;
118 - default: ; // nothing
119 + case ifSUMSQ: fRes += fVal * fVal; break;
120 + case ifPRODUCT: fRes *= fVal; break;
122 + default:;
125 nFuncFmtType = NUMBERFORMAT_NUMBER;
126 - break;
128 + break;
129 case svSingleRef :
131 PopSingleRef( aAdr );
132 diff --git sc/source/core/tool/interpr4.cxx sc/source/core/tool/interpr4.cxx
133 index cd2fccc..ef0d533 100644
134 --- sc/source/core/tool/interpr4.cxx
135 +++ sc/source/core/tool/interpr4.cxx
136 @@ -207,19 +207,27 @@ double ScInterpreter::GetValueCellValue( const ScAddress& rPos, const ScValueCel
140 -double ScInterpreter::GetCellValue( const ScAddress& rPos, const ScBaseCell* pCell )
141 +double ScInterpreter::GetCellValue( const ScAddress& rPos, const ScBaseCell* pCell,
142 + bool bNoValueAsError, bool bBlankAsZero )
144 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "Eike.Rathke@sun.com", "ScInterpreter::GetCellValue" );
145 USHORT nErr = nGlobalError;
146 nGlobalError = 0;
147 - double nVal = GetCellValueOrZero( rPos, pCell );
148 - if ( !nGlobalError || nGlobalError == errCellNoValue )
149 + double nVal = GetCellValueOrZero( rPos, pCell, bBlankAsZero );
150 + if (!nGlobalError)
151 + // no global error. good.
152 nGlobalError = nErr;
153 + else if (nGlobalError == errCellNoValue)
154 + // Internal cell-no-value error. If the caller wants to treat no
155 + // value as error, then we need to translate this to a legitimate
156 + // error number (#VALUE!). If not, we should re-assign the prior error
157 + // number.
158 + nGlobalError = bNoValueAsError ? errNoValue : nErr;
159 return nVal;
163 -double ScInterpreter::GetCellValueOrZero( const ScAddress& rPos, const ScBaseCell* pCell )
164 +double ScInterpreter::GetCellValueOrZero( const ScAddress& rPos, const ScBaseCell* pCell, bool bBlankAsZero )
166 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "Eike.Rathke@sun.com", "ScInterpreter::GetCellValueOrZero" );
167 double fValue;
168 @@ -264,7 +272,7 @@ double ScInterpreter::GetCellValueOrZero( const ScAddress& rPos, const ScBaseCel
169 break;
170 case CELLTYPE_STRING:
171 case CELLTYPE_EDIT:
172 -#if 0
173 +#if 1 /* JEG : re-enable because compatibility is more important than consistency for this */
174 // Xcl does it, but SUM(A1:A2) differs from A1+A2. No good.
176 String aStr;
177 @@ -275,14 +283,15 @@ double ScInterpreter::GetCellValueOrZero( const ScAddress& rPos, const ScBaseCel
178 sal_uInt32 nFIndex = 0; // damit default Land/Spr.
179 if ( !pFormatter->IsNumberFormat( aStr, nFIndex, fValue ) )
181 - SetError(errNoValue);
182 + SetError(errCellNoValue); /* CellNoValue is not really an error */
183 fValue = 0.0;
186 break;
187 #endif
188 default:
189 - SetError(errCellNoValue);
190 + if (!bBlankAsZero)
191 + SetError(errCellNoValue);
192 fValue = 0.0;
195 @@ -1621,7 +1630,7 @@ BOOL ScInterpreter::DoubleRefToPosSingleRef( const ScRange& rRange, ScAddress& r
199 -double ScInterpreter::GetDouble()
200 +double ScInterpreter::GetDouble( bool bNoValueAsError, bool bBlankAsZero )
202 RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "Eike.Rathke@sun.com", "ScInterpreter::GetDouble" );
203 double nVal;
204 @@ -1646,7 +1655,7 @@ double ScInterpreter::GetDouble()
205 ScAddress aAdr;
206 PopSingleRef( aAdr );
207 ScBaseCell* pCell = GetCell( aAdr );
208 - nVal = GetCellValue( aAdr, pCell );
209 + nVal = GetCellValue( aAdr, pCell, bNoValueAsError, bBlankAsZero );
211 break;
212 case svDoubleRef:
213 diff --git sc/source/core/tool/interpr5.cxx sc/source/core/tool/interpr5.cxx
214 index 5b05f0c..c5b4770 100644
215 --- sc/source/core/tool/interpr5.cxx
216 +++ sc/source/core/tool/interpr5.cxx
217 @@ -1184,7 +1184,12 @@ void ScInterpreter::CalculateAddSub(BOOL _bSub)
218 pMat2 = GetMatrix();
219 else
221 - fVal2 = GetDouble();
222 + fVal2 = GetDouble(true, true);
223 + if (nGlobalError)
225 + PushError(nGlobalError);
226 + return;
228 switch ( nCurFmtType )
230 case NUMBERFORMAT_DATE :
231 @@ -1205,7 +1210,12 @@ void ScInterpreter::CalculateAddSub(BOOL _bSub)
232 pMat1 = GetMatrix();
233 else
235 - fVal1 = GetDouble();
236 + fVal1 = GetDouble(true, true);
237 + if (nGlobalError)
239 + PushError(nGlobalError);
240 + return;
242 switch ( nCurFmtType )
244 case NUMBERFORMAT_DATE :
245 @@ -1414,7 +1424,12 @@ void ScInterpreter::ScMul()
246 pMat2 = GetMatrix();
247 else
249 - fVal2 = GetDouble();
250 + fVal2 = GetDouble(true, true);
251 + if (nGlobalError)
253 + PushError(nGlobalError);
254 + return;
256 switch ( nCurFmtType )
258 case NUMBERFORMAT_CURRENCY :
259 @@ -1427,7 +1442,12 @@ void ScInterpreter::ScMul()
260 pMat1 = GetMatrix();
261 else
263 - fVal1 = GetDouble();
264 + fVal1 = GetDouble(true, true);
265 + if (nGlobalError)
267 + PushError(nGlobalError);
268 + return;
270 switch ( nCurFmtType )
272 case NUMBERFORMAT_CURRENCY :
273 @@ -1494,7 +1514,12 @@ void ScInterpreter::ScDiv()
274 pMat2 = GetMatrix();
275 else
277 - fVal2 = GetDouble();
278 + fVal2 = GetDouble(true, true);
279 + if (nGlobalError)
281 + PushError(nGlobalError);
282 + return;
284 // hier kein Currency uebernehmen, 123kg/456DM sind nicht DM
285 nFmtCurrencyType2 = nCurFmtType;
287 @@ -1502,7 +1527,12 @@ void ScInterpreter::ScDiv()
288 pMat1 = GetMatrix();
289 else
291 - fVal1 = GetDouble();
292 + fVal1 = GetDouble(true, true);
293 + if (nGlobalError)
295 + PushError(nGlobalError);
296 + return;
298 switch ( nCurFmtType )
300 case NUMBERFORMAT_CURRENCY :