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
10b3f79822SAndrew Rist *
11b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12b3f79822SAndrew Rist *
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.
19b3f79822SAndrew Rist *
20b3f79822SAndrew Rist *************************************************************/
21b3f79822SAndrew Rist
22b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir // System - Includes -----------------------------------------------------
28cdf0e10cSrcweir
29cdf0e10cSrcweir
30cdf0e10cSrcweir
31cdf0e10cSrcweir #ifdef _MSC_VER
32cdf0e10cSrcweir #pragma optimize("",off)
33cdf0e10cSrcweir // sonst Absturz Win beim Fuellen
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir
36cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
37cdf0e10cSrcweir
38cdf0e10cSrcweir #include "scitems.hxx"
39cdf0e10cSrcweir #include <svx/algitem.hxx>
40cdf0e10cSrcweir #include <editeng/boxitem.hxx>
41cdf0e10cSrcweir #include <editeng/brshitem.hxx>
42cdf0e10cSrcweir #include <editeng/cntritem.hxx>
43cdf0e10cSrcweir #include <editeng/colritem.hxx>
44cdf0e10cSrcweir #include <editeng/crsditem.hxx>
45cdf0e10cSrcweir #include <editeng/fhgtitem.hxx>
46cdf0e10cSrcweir #include <editeng/fontitem.hxx>
47cdf0e10cSrcweir #include <editeng/langitem.hxx>
48cdf0e10cSrcweir #include <editeng/postitem.hxx>
49cdf0e10cSrcweir #include <editeng/shdditem.hxx>
50cdf0e10cSrcweir #include <editeng/udlnitem.hxx>
51cdf0e10cSrcweir #include <editeng/wghtitem.hxx>
52cdf0e10cSrcweir #include <svx/rotmodit.hxx>
53cdf0e10cSrcweir #include <editeng/editobj.hxx>
54cdf0e10cSrcweir #include <editeng/editeng.hxx>
55cdf0e10cSrcweir #include <editeng/eeitem.hxx>
56cdf0e10cSrcweir #include <editeng/escpitem.hxx>
57cdf0e10cSrcweir #include <svl/zforlist.hxx>
58cdf0e10cSrcweir #include <vcl/keycodes.hxx>
59cdf0e10cSrcweir #include <rtl/math.hxx>
60cdf0e10cSrcweir #include <unotools/charclass.hxx>
61cdf0e10cSrcweir
62cdf0e10cSrcweir #include "attrib.hxx"
63cdf0e10cSrcweir #include "patattr.hxx"
64cdf0e10cSrcweir #include "cell.hxx"
65cdf0e10cSrcweir #include "table.hxx"
66cdf0e10cSrcweir #include "globstr.hrc"
67cdf0e10cSrcweir #include "global.hxx"
68cdf0e10cSrcweir #include "document.hxx"
69cdf0e10cSrcweir #include "autoform.hxx"
70cdf0e10cSrcweir #include "userlist.hxx"
71cdf0e10cSrcweir #include "zforauto.hxx"
72cdf0e10cSrcweir #include "subtotal.hxx"
73cdf0e10cSrcweir #include "formula/errorcodes.hxx"
74cdf0e10cSrcweir #include "rangenam.hxx"
75cdf0e10cSrcweir #include "docpool.hxx"
76cdf0e10cSrcweir #include "progress.hxx"
77cdf0e10cSrcweir #include "segmenttree.hxx"
78cdf0e10cSrcweir
79cdf0e10cSrcweir #include <math.h>
80cdf0e10cSrcweir
81cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
82cdf0e10cSrcweir
83cdf0e10cSrcweir #define _D_MAX_LONG_ (double) 0x7fffffff
84cdf0e10cSrcweir
85cdf0e10cSrcweir extern sal_uInt16 nScFillModeMouseModifier; // global.cxx
86cdf0e10cSrcweir
87cdf0e10cSrcweir // -----------------------------------------------------------------------
88cdf0e10cSrcweir
lcl_DecompValueString(String & aValue,sal_Int32 & nVal,sal_uInt16 * pMinDigits=NULL)89cdf0e10cSrcweir short lcl_DecompValueString( String& aValue, sal_Int32& nVal, sal_uInt16* pMinDigits = NULL )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir if ( !aValue.Len() )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir nVal = 0;
94cdf0e10cSrcweir return 0;
95cdf0e10cSrcweir }
96cdf0e10cSrcweir const sal_Unicode* p = aValue.GetBuffer();
97cdf0e10cSrcweir xub_StrLen nNeg = 0;
98cdf0e10cSrcweir xub_StrLen nNum = 0;
99cdf0e10cSrcweir if ( p[nNum] == '-' )
100cdf0e10cSrcweir nNum = nNeg = 1;
101cdf0e10cSrcweir while ( p[nNum] && CharClass::isAsciiNumeric( p[nNum] ) )
102cdf0e10cSrcweir nNum++;
103cdf0e10cSrcweir
104cdf0e10cSrcweir sal_Unicode cNext = p[nNum]; // 0 if at the end
105cdf0e10cSrcweir sal_Unicode cLast = p[aValue.Len()-1];
106cdf0e10cSrcweir
107cdf0e10cSrcweir // #i5550# If there are numbers at the beginning and the end,
108cdf0e10cSrcweir // prefer the one at the beginning only if it's followed by a space.
109cdf0e10cSrcweir // Otherwise, use the number at the end, to enable things like IP addresses.
110cdf0e10cSrcweir if ( nNum > nNeg && ( cNext == 0 || cNext == ' ' || !CharClass::isAsciiNumeric(cLast) ) )
111cdf0e10cSrcweir { // number at the beginning
112cdf0e10cSrcweir nVal = aValue.Copy( 0, nNum ).ToInt32();
113cdf0e10cSrcweir // #60893# any number with a leading zero sets the minimum number of digits
114cdf0e10cSrcweir if ( p[nNeg] == '0' && pMinDigits && ( nNum - nNeg > *pMinDigits ) )
115cdf0e10cSrcweir *pMinDigits = nNum - nNeg;
116cdf0e10cSrcweir aValue.Erase( 0, nNum );
117cdf0e10cSrcweir return -1;
118cdf0e10cSrcweir }
119cdf0e10cSrcweir else
120cdf0e10cSrcweir {
121cdf0e10cSrcweir nNeg = 0;
122cdf0e10cSrcweir xub_StrLen nEnd = nNum = aValue.Len() - 1;
123cdf0e10cSrcweir while ( nNum && CharClass::isAsciiNumeric( p[nNum] ) )
124cdf0e10cSrcweir nNum--;
125cdf0e10cSrcweir if ( p[nNum] == '-' )
126cdf0e10cSrcweir {
127cdf0e10cSrcweir nNum--;
128cdf0e10cSrcweir nNeg = 1;
129cdf0e10cSrcweir }
130cdf0e10cSrcweir if ( nNum < nEnd - nNeg )
131cdf0e10cSrcweir { // number at the end
132cdf0e10cSrcweir nVal = aValue.Copy( nNum + 1 ).ToInt32();
133cdf0e10cSrcweir // #60893# any number with a leading zero sets the minimum number of digits
134cdf0e10cSrcweir if ( p[nNum+1+nNeg] == '0' && pMinDigits && ( nEnd - nNum - nNeg > *pMinDigits ) )
135cdf0e10cSrcweir *pMinDigits = nEnd - nNum - nNeg;
136cdf0e10cSrcweir aValue.Erase( nNum + 1 );
137cdf0e10cSrcweir return 1;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir }
140cdf0e10cSrcweir nVal = 0;
141cdf0e10cSrcweir return 0;
142cdf0e10cSrcweir }
143cdf0e10cSrcweir
lcl_ValueString(sal_Int32 nValue,sal_uInt16 nMinDigits)144cdf0e10cSrcweir String lcl_ValueString( sal_Int32 nValue, sal_uInt16 nMinDigits )
145cdf0e10cSrcweir {
146cdf0e10cSrcweir if ( nMinDigits <= 1 )
147cdf0e10cSrcweir return String::CreateFromInt32( nValue ); // simple case...
148cdf0e10cSrcweir else
149cdf0e10cSrcweir {
150cdf0e10cSrcweir String aStr = String::CreateFromInt32( Abs( nValue ) );
151cdf0e10cSrcweir if ( aStr.Len() < nMinDigits )
152cdf0e10cSrcweir {
153cdf0e10cSrcweir String aZero;
154cdf0e10cSrcweir aZero.Fill( nMinDigits - aStr.Len(), '0' );
155cdf0e10cSrcweir aStr.Insert( aZero, 0 );
156cdf0e10cSrcweir }
157cdf0e10cSrcweir // nMinDigits doesn't include the '-' sign -> add after inserting zeros
158cdf0e10cSrcweir if ( nValue < 0 )
159cdf0e10cSrcweir aStr.Insert( '-', 0 );
160cdf0e10cSrcweir return aStr;
161cdf0e10cSrcweir }
162cdf0e10cSrcweir }
163cdf0e10cSrcweir
lcl_getSuffixCell(ScDocument * pDocument,sal_Int32 nValue,sal_uInt16 nDigits,const String & rSuffix,CellType eCellType,sal_Bool bIsOrdinalSuffix)164cdf0e10cSrcweir static ScBaseCell * lcl_getSuffixCell( ScDocument* pDocument, sal_Int32 nValue,
165cdf0e10cSrcweir sal_uInt16 nDigits, const String& rSuffix, CellType eCellType,
166cdf0e10cSrcweir sal_Bool bIsOrdinalSuffix )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir String aValue( lcl_ValueString( nValue, nDigits ));
169cdf0e10cSrcweir if (!bIsOrdinalSuffix)
170cdf0e10cSrcweir return new ScStringCell( aValue += rSuffix);
171cdf0e10cSrcweir
172cdf0e10cSrcweir String aOrdinalSuffix( ScGlobal::GetOrdinalSuffix( nValue));
173cdf0e10cSrcweir if (eCellType != CELLTYPE_EDIT)
174cdf0e10cSrcweir return new ScStringCell( aValue += aOrdinalSuffix);
175cdf0e10cSrcweir
176cdf0e10cSrcweir EditEngine aEngine( pDocument->GetEnginePool() );
177cdf0e10cSrcweir SfxItemSet aAttr = aEngine.GetEmptyItemSet();
178cdf0e10cSrcweir aAttr.Put( SvxEscapementItem( SVX_ESCAPEMENT_SUPERSCRIPT, EE_CHAR_ESCAPEMENT));
179cdf0e10cSrcweir aEngine.SetText( aValue );
180cdf0e10cSrcweir aEngine.QuickInsertText( aOrdinalSuffix, ESelection( 0, aValue.Len(), 0,
181cdf0e10cSrcweir aValue.Len() + aOrdinalSuffix.Len()));
182cdf0e10cSrcweir aEngine.QuickSetAttribs( aAttr, ESelection( 0, aValue.Len(), 0, aValue.Len() +
183cdf0e10cSrcweir aOrdinalSuffix.Len()));
184cdf0e10cSrcweir return new ScEditCell( aEngine.CreateTextObject(), pDocument, NULL );
185cdf0e10cSrcweir }
186cdf0e10cSrcweir
FillAnalyse(SCCOL nCol1,SCROW nRow1,SCCOL nCol2,SCROW nRow2,FillCmd & rCmd,FillDateCmd & rDateCmd,double & rInc,sal_uInt16 & rMinDigits,ScUserListData * & rListData,sal_uInt16 & rListIndex)187cdf0e10cSrcweir void ScTable::FillAnalyse( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
188cdf0e10cSrcweir FillCmd& rCmd, FillDateCmd& rDateCmd,
189cdf0e10cSrcweir double& rInc, sal_uInt16& rMinDigits,
190cdf0e10cSrcweir ScUserListData*& rListData, sal_uInt16& rListIndex)
191cdf0e10cSrcweir {
192cdf0e10cSrcweir DBG_ASSERT( nCol1==nCol2 || nRow1==nRow2, "FillAnalyse: falscher Bereich" );
193cdf0e10cSrcweir
194cdf0e10cSrcweir rInc = 0.0;
195cdf0e10cSrcweir rMinDigits = 0;
196cdf0e10cSrcweir rListData = NULL;
197cdf0e10cSrcweir rCmd = FILL_SIMPLE;
198cdf0e10cSrcweir if (( nScFillModeMouseModifier & KEY_MOD1 )||IsDataFiltered()) //i89232
199cdf0e10cSrcweir return ; // Ctrl-Taste: Copy
200cdf0e10cSrcweir
201cdf0e10cSrcweir SCCOL nAddX;
202cdf0e10cSrcweir SCROW nAddY;
203cdf0e10cSrcweir SCSIZE nCount;
204cdf0e10cSrcweir if (nCol1 == nCol2)
205cdf0e10cSrcweir {
206cdf0e10cSrcweir nAddX = 0;
207cdf0e10cSrcweir nAddY = 1;
208cdf0e10cSrcweir nCount = static_cast<SCSIZE>(nRow2 - nRow1 + 1);
209cdf0e10cSrcweir }
210cdf0e10cSrcweir else
211cdf0e10cSrcweir {
212cdf0e10cSrcweir nAddX = 1;
213cdf0e10cSrcweir nAddY = 0;
214cdf0e10cSrcweir nCount = static_cast<SCSIZE>(nCol2 - nCol1 + 1);
215cdf0e10cSrcweir }
216cdf0e10cSrcweir
217cdf0e10cSrcweir SCCOL nCol = nCol1;
218cdf0e10cSrcweir SCROW nRow = nRow1;
219cdf0e10cSrcweir
220cdf0e10cSrcweir ScBaseCell* pFirstCell = GetCell( nCol, nRow );
221cdf0e10cSrcweir CellType eCellType = pFirstCell ? pFirstCell->GetCellType() : CELLTYPE_NONE;
222cdf0e10cSrcweir
223cdf0e10cSrcweir if (eCellType == CELLTYPE_VALUE)
224cdf0e10cSrcweir {
225cdf0e10cSrcweir sal_uInt32 nFormat = ((const SfxUInt32Item*)GetAttr(nCol,nRow,ATTR_VALUE_FORMAT))->GetValue();
226cdf0e10cSrcweir sal_Bool bDate = ( pDocument->GetFormatTable()->GetType(nFormat) == NUMBERFORMAT_DATE );
227cdf0e10cSrcweir if (bDate)
228cdf0e10cSrcweir {
229cdf0e10cSrcweir if (nCount > 1)
230cdf0e10cSrcweir {
231cdf0e10cSrcweir long nCmpInc = 0;
232cdf0e10cSrcweir double nVal;
233cdf0e10cSrcweir Date aNullDate = *pDocument->GetFormatTable()->GetNullDate();
234cdf0e10cSrcweir Date aDate1 = aNullDate;
235cdf0e10cSrcweir nVal = ((ScValueCell*)pFirstCell)->GetValue();
236cdf0e10cSrcweir aDate1 += (long)nVal;
237cdf0e10cSrcweir Date aDate2 = aNullDate;
238cdf0e10cSrcweir nVal = GetValue(nCol+nAddX, nRow+nAddY);
239cdf0e10cSrcweir aDate2 += (long)nVal;
240cdf0e10cSrcweir if ( aDate1 != aDate2 )
241cdf0e10cSrcweir {
242cdf0e10cSrcweir FillDateCmd eType;
243cdf0e10cSrcweir long nDDiff = aDate2.GetDay() - (long) aDate1.GetDay();
244cdf0e10cSrcweir long nMDiff = aDate2.GetMonth() - (long) aDate1.GetMonth();
245cdf0e10cSrcweir long nYDiff = aDate2.GetYear() - (long) aDate1.GetYear();
246cdf0e10cSrcweir if ( nDDiff )
247cdf0e10cSrcweir {
248cdf0e10cSrcweir eType = FILL_DAY;
249cdf0e10cSrcweir nCmpInc = aDate2 - aDate1;
250cdf0e10cSrcweir }
251cdf0e10cSrcweir else
252cdf0e10cSrcweir {
253cdf0e10cSrcweir eType = FILL_MONTH;
254cdf0e10cSrcweir nCmpInc = nMDiff + 12 * nYDiff;
255cdf0e10cSrcweir }
256cdf0e10cSrcweir
257cdf0e10cSrcweir nCol = sal::static_int_cast<SCCOL>( nCol + nAddX );
258cdf0e10cSrcweir nRow = sal::static_int_cast<SCROW>( nRow + nAddY );
259cdf0e10cSrcweir sal_Bool bVal = sal_True;
260cdf0e10cSrcweir for (sal_uInt16 i=1; i<nCount && bVal; i++)
261cdf0e10cSrcweir {
262cdf0e10cSrcweir ScBaseCell* pCell = GetCell(nCol,nRow);
263cdf0e10cSrcweir if (pCell && pCell->GetCellType() == CELLTYPE_VALUE)
264cdf0e10cSrcweir {
265cdf0e10cSrcweir nVal = ((ScValueCell*)pCell)->GetValue();
266cdf0e10cSrcweir aDate2 = aNullDate + (long) nVal;
267cdf0e10cSrcweir if ( eType == FILL_DAY )
268cdf0e10cSrcweir {
269cdf0e10cSrcweir if ( aDate2-aDate1 != nCmpInc )
270cdf0e10cSrcweir bVal = sal_False;
271cdf0e10cSrcweir }
272cdf0e10cSrcweir else
273cdf0e10cSrcweir {
274cdf0e10cSrcweir nDDiff = aDate2.GetDay() - (long) aDate1.GetDay();
275cdf0e10cSrcweir nMDiff = aDate2.GetMonth() - (long) aDate1.GetMonth();
276cdf0e10cSrcweir nYDiff = aDate2.GetYear() - (long) aDate1.GetYear();
277cdf0e10cSrcweir if (nDDiff || ( nMDiff + 12 * nYDiff != nCmpInc ))
278cdf0e10cSrcweir bVal = sal_False;
279cdf0e10cSrcweir }
280cdf0e10cSrcweir aDate1 = aDate2;
281cdf0e10cSrcweir nCol = sal::static_int_cast<SCCOL>( nCol + nAddX );
282cdf0e10cSrcweir nRow = sal::static_int_cast<SCROW>( nRow + nAddY );
283cdf0e10cSrcweir }
284cdf0e10cSrcweir else
285cdf0e10cSrcweir bVal = sal_False; // #50965# kein Datum passt auch nicht
286cdf0e10cSrcweir }
287cdf0e10cSrcweir if (bVal)
288cdf0e10cSrcweir {
289cdf0e10cSrcweir if ( eType == FILL_MONTH && ( nCmpInc % 12 == 0 ) )
290cdf0e10cSrcweir {
291cdf0e10cSrcweir eType = FILL_YEAR;
292cdf0e10cSrcweir nCmpInc /= 12;
293cdf0e10cSrcweir }
294cdf0e10cSrcweir rCmd = FILL_DATE;
295cdf0e10cSrcweir rDateCmd = eType;
296cdf0e10cSrcweir rInc = nCmpInc;
297cdf0e10cSrcweir }
298cdf0e10cSrcweir }
299cdf0e10cSrcweir }
300cdf0e10cSrcweir else // einzelnes Datum -> Tage hochzaehlen
301cdf0e10cSrcweir {
302cdf0e10cSrcweir rCmd = FILL_DATE;
303cdf0e10cSrcweir rDateCmd = FILL_DAY;
304cdf0e10cSrcweir rInc = 1.0;
305cdf0e10cSrcweir }
306cdf0e10cSrcweir }
307cdf0e10cSrcweir else
308cdf0e10cSrcweir {
309cdf0e10cSrcweir if (nCount > 1)
310cdf0e10cSrcweir {
311cdf0e10cSrcweir double nVal1 = ((ScValueCell*)pFirstCell)->GetValue();
312cdf0e10cSrcweir double nVal2 = GetValue(nCol+nAddX, nRow+nAddY);
313cdf0e10cSrcweir rInc = nVal2 - nVal1;
314cdf0e10cSrcweir nCol = sal::static_int_cast<SCCOL>( nCol + nAddX );
315cdf0e10cSrcweir nRow = sal::static_int_cast<SCROW>( nRow + nAddY );
316cdf0e10cSrcweir sal_Bool bVal = sal_True;
317cdf0e10cSrcweir for (sal_uInt16 i=1; i<nCount && bVal; i++)
318cdf0e10cSrcweir {
319cdf0e10cSrcweir ScBaseCell* pCell = GetCell(nCol,nRow);
320cdf0e10cSrcweir if (pCell && pCell->GetCellType() == CELLTYPE_VALUE)
321cdf0e10cSrcweir {
322cdf0e10cSrcweir nVal2 = ((ScValueCell*)pCell)->GetValue();
323cdf0e10cSrcweir double nDiff = nVal2 - nVal1;
324cdf0e10cSrcweir if ( !::rtl::math::approxEqual( nDiff, rInc ) )
325cdf0e10cSrcweir bVal = sal_False;
326cdf0e10cSrcweir nVal1 = nVal2;
327cdf0e10cSrcweir }
328cdf0e10cSrcweir else
329cdf0e10cSrcweir bVal = sal_False;
330cdf0e10cSrcweir nCol = sal::static_int_cast<SCCOL>( nCol + nAddX );
331cdf0e10cSrcweir nRow = sal::static_int_cast<SCROW>( nRow + nAddY );
332cdf0e10cSrcweir }
333cdf0e10cSrcweir if (bVal)
334cdf0e10cSrcweir rCmd = FILL_LINEAR;
335cdf0e10cSrcweir }
336cdf0e10cSrcweir }
337cdf0e10cSrcweir }
338cdf0e10cSrcweir else if (eCellType == CELLTYPE_STRING || eCellType == CELLTYPE_EDIT)
339cdf0e10cSrcweir {
340cdf0e10cSrcweir String aStr;
341cdf0e10cSrcweir GetString(nCol, nRow, aStr);
342cdf0e10cSrcweir rListData = (ScUserListData*)(ScGlobal::GetUserList()->GetData(aStr));
343cdf0e10cSrcweir if (rListData)
344cdf0e10cSrcweir {
345cdf0e10cSrcweir rListData->GetSubIndex(aStr, rListIndex);
346cdf0e10cSrcweir nCol = sal::static_int_cast<SCCOL>( nCol + nAddX );
347cdf0e10cSrcweir nRow = sal::static_int_cast<SCROW>( nRow + nAddY );
348cdf0e10cSrcweir for (sal_uInt16 i=1; i<nCount && rListData; i++)
349cdf0e10cSrcweir {
350cdf0e10cSrcweir GetString(nCol, nRow, aStr);
351cdf0e10cSrcweir if (!rListData->GetSubIndex(aStr, rListIndex))
352cdf0e10cSrcweir rListData = NULL;
353cdf0e10cSrcweir nCol = sal::static_int_cast<SCCOL>( nCol + nAddX );
354cdf0e10cSrcweir nRow = sal::static_int_cast<SCROW>( nRow + nAddY );
355cdf0e10cSrcweir }
356cdf0e10cSrcweir }
357cdf0e10cSrcweir else if ( nCount > 1 )
358cdf0e10cSrcweir {
359cdf0e10cSrcweir // pass rMinDigits to all DecompValueString calls
360cdf0e10cSrcweir // -> longest number defines rMinDigits
361cdf0e10cSrcweir
362cdf0e10cSrcweir sal_Int32 nVal1;
363cdf0e10cSrcweir short nFlag1 = lcl_DecompValueString( aStr, nVal1, &rMinDigits );
364cdf0e10cSrcweir if ( nFlag1 )
365cdf0e10cSrcweir {
366cdf0e10cSrcweir sal_Int32 nVal2;
367cdf0e10cSrcweir GetString( nCol+nAddX, nRow+nAddY, aStr );
368cdf0e10cSrcweir short nFlag2 = lcl_DecompValueString( aStr, nVal2, &rMinDigits );
369cdf0e10cSrcweir if ( nFlag1 == nFlag2 )
370cdf0e10cSrcweir {
371cdf0e10cSrcweir rInc = (double)nVal2 - (double)nVal1;
372cdf0e10cSrcweir nCol = sal::static_int_cast<SCCOL>( nCol + nAddX );
373cdf0e10cSrcweir nRow = sal::static_int_cast<SCROW>( nRow + nAddY );
374cdf0e10cSrcweir sal_Bool bVal = sal_True;
375cdf0e10cSrcweir for (sal_uInt16 i=1; i<nCount && bVal; i++)
376cdf0e10cSrcweir {
377cdf0e10cSrcweir ScBaseCell* pCell = GetCell(nCol,nRow);
378cdf0e10cSrcweir CellType eType = pCell ? pCell->GetCellType() : CELLTYPE_NONE;
379cdf0e10cSrcweir if ( eType == CELLTYPE_STRING || eType == CELLTYPE_EDIT )
380cdf0e10cSrcweir {
381cdf0e10cSrcweir if ( eType == CELLTYPE_STRING )
382cdf0e10cSrcweir ((ScStringCell*)pCell)->GetString( aStr );
383cdf0e10cSrcweir else
384cdf0e10cSrcweir ((ScEditCell*)pCell)->GetString( aStr );
385cdf0e10cSrcweir nFlag2 = lcl_DecompValueString( aStr, nVal2, &rMinDigits );
386cdf0e10cSrcweir if ( nFlag1 == nFlag2 )
387cdf0e10cSrcweir {
388cdf0e10cSrcweir double nDiff = (double)nVal2 - (double)nVal1;
389cdf0e10cSrcweir if ( !::rtl::math::approxEqual( nDiff, rInc ) )
390cdf0e10cSrcweir bVal = sal_False;
391cdf0e10cSrcweir nVal1 = nVal2;
392cdf0e10cSrcweir }
393cdf0e10cSrcweir else
394cdf0e10cSrcweir bVal = sal_False;
395cdf0e10cSrcweir }
396cdf0e10cSrcweir else
397cdf0e10cSrcweir bVal = sal_False;
398cdf0e10cSrcweir nCol = sal::static_int_cast<SCCOL>( nCol + nAddX );
399cdf0e10cSrcweir nRow = sal::static_int_cast<SCROW>( nRow + nAddY );
400cdf0e10cSrcweir }
401cdf0e10cSrcweir if (bVal)
402cdf0e10cSrcweir rCmd = FILL_LINEAR;
403cdf0e10cSrcweir }
404cdf0e10cSrcweir }
405cdf0e10cSrcweir }
406cdf0e10cSrcweir else
407cdf0e10cSrcweir {
408cdf0e10cSrcweir // call DecompValueString to set rMinDigits
409cdf0e10cSrcweir sal_Int32 nDummy;
410cdf0e10cSrcweir lcl_DecompValueString( aStr, nDummy, &rMinDigits );
411cdf0e10cSrcweir }
412cdf0e10cSrcweir }
413cdf0e10cSrcweir }
414cdf0e10cSrcweir
FillFormula(sal_uLong &,sal_Bool,ScFormulaCell * pSrcCell,SCCOL nDestCol,SCROW nDestRow,sal_Bool bLast)415cdf0e10cSrcweir void ScTable::FillFormula(sal_uLong& /* nFormulaCounter */, sal_Bool /* bFirst */, ScFormulaCell* pSrcCell,
416cdf0e10cSrcweir SCCOL nDestCol, SCROW nDestRow, sal_Bool bLast )
417cdf0e10cSrcweir {
418cdf0e10cSrcweir /* sal_uInt16 nTokArrLen = pSrcCell->GetTokenArrayLen();
419cdf0e10cSrcweir if ( nTokArrLen > 15 ) // mehr als =A1 oder =67
420cdf0e10cSrcweir {
421cdf0e10cSrcweir ScRangeName* pRangeName = pDocument->GetRangeName();
422cdf0e10cSrcweir String aName("___SC_"); // Wird dieser String veraendert,
423cdf0e10cSrcweir // auch in document2 EraseNonUsed...
424cdf0e10cSrcweir // mitaendern!!
425cdf0e10cSrcweir aName += pRangeName->GetSharedMaxIndex() + 1;
426cdf0e10cSrcweir aName += '_';
427cdf0e10cSrcweir aName += nFormulaCounter;
428cdf0e10cSrcweir nFormulaCounter++;
429cdf0e10cSrcweir if (bFirst)
430cdf0e10cSrcweir {
431cdf0e10cSrcweir ScRangeData *pAktRange = new ScRangeData(
432cdf0e10cSrcweir pDocument, aName, pSrcCell->GetTokenArray(), nTokArrLen,
433cdf0e10cSrcweir pSrcCell->GetCol(), pSrcCell->GetRow(), nTab ,RT_SHARED);
434cdf0e10cSrcweir if (!pRangeName->Insert( pAktRange ))
435cdf0e10cSrcweir delete pAktRange;
436cdf0e10cSrcweir else
437cdf0e10cSrcweir bSharedNameInserted = sal_True;
438cdf0e10cSrcweir }
439cdf0e10cSrcweir sal_uInt16 nIndex;
440cdf0e10cSrcweir pRangeName->SearchName(aName, nIndex);
441cdf0e10cSrcweir if (!pRangeName)
442cdf0e10cSrcweir {
443cdf0e10cSrcweir DBG_ERROR("ScTable::FillFormula: Falscher Name");
444cdf0e10cSrcweir return;
445cdf0e10cSrcweir }
446cdf0e10cSrcweir nIndex = ((ScRangeData*) ((*pRangeName)[nIndex]))->GetIndex();
447cdf0e10cSrcweir ScTokenArray aArr;
448cdf0e10cSrcweir aArr.AddName(nIndex);
449cdf0e10cSrcweir aArr.AddOpCode(ocStop);
450cdf0e10cSrcweir ScFormulaCell* pDestCell = new ScFormulaCell
451cdf0e10cSrcweir (pDocument, ScAddress( nDestCol, nDestRow, nTab ), aArr );
452cdf0e10cSrcweir aCol[nDestCol].Insert(nDestRow, pDestCell);
453cdf0e10cSrcweir }
454cdf0e10cSrcweir else
455cdf0e10cSrcweir */ {
456cdf0e10cSrcweir pDocument->SetNoListening( sal_True ); // noch falsche Referenzen
457cdf0e10cSrcweir ScAddress aAddr( nDestCol, nDestRow, nTab );
458cdf0e10cSrcweir ScFormulaCell* pDestCell = new ScFormulaCell( *pSrcCell, *pDocument, aAddr );
459cdf0e10cSrcweir aCol[nDestCol].Insert(nDestRow, pDestCell);
460cdf0e10cSrcweir #if 0
461cdf0e10cSrcweir // mit RelRefs unnoetig
462cdf0e10cSrcweir pDestCell->UpdateReference(URM_COPY,
463cdf0e10cSrcweir ScRange( aAddr, aAddr ),
464cdf0e10cSrcweir nDestCol - pSrcCell->aPos.Col(),
465cdf0e10cSrcweir nDestRow - pSrcCell->aPos.Row(), 0);
466cdf0e10cSrcweir #endif
467cdf0e10cSrcweir if ( bLast && pDestCell->GetMatrixFlag() )
468cdf0e10cSrcweir {
469cdf0e10cSrcweir ScAddress aOrg;
470cdf0e10cSrcweir if ( pDestCell->GetMatrixOrigin( aOrg ) )
471cdf0e10cSrcweir {
472cdf0e10cSrcweir if ( nDestCol >= aOrg.Col() && nDestRow >= aOrg.Row() )
473cdf0e10cSrcweir {
474cdf0e10cSrcweir ScBaseCell* pOrgCell = pDocument->GetCell( aOrg );
475cdf0e10cSrcweir if ( pOrgCell && pOrgCell->GetCellType() == CELLTYPE_FORMULA
476cdf0e10cSrcweir && ((ScFormulaCell*)pOrgCell)->GetMatrixFlag() == MM_FORMULA )
477cdf0e10cSrcweir {
478cdf0e10cSrcweir ((ScFormulaCell*)pOrgCell)->SetMatColsRows(
479cdf0e10cSrcweir nDestCol - aOrg.Col() + 1,
480cdf0e10cSrcweir nDestRow - aOrg.Row() + 1 );
481cdf0e10cSrcweir }
482cdf0e10cSrcweir else
483cdf0e10cSrcweir {
484cdf0e10cSrcweir DBG_ERRORFILE( "FillFormula: MatrixOrigin keine Formelzelle mit MM_FORMULA" );
485cdf0e10cSrcweir }
486cdf0e10cSrcweir }
487cdf0e10cSrcweir else
488cdf0e10cSrcweir {
489cdf0e10cSrcweir DBG_ERRORFILE( "FillFormula: MatrixOrigin rechts unten" );
490cdf0e10cSrcweir }
491cdf0e10cSrcweir }
492cdf0e10cSrcweir else
493cdf0e10cSrcweir {
494cdf0e10cSrcweir DBG_ERRORFILE( "FillFormula: kein MatrixOrigin" );
495cdf0e10cSrcweir }
496cdf0e10cSrcweir }
497cdf0e10cSrcweir pDocument->SetNoListening( sal_False );
498cdf0e10cSrcweir pDestCell->StartListeningTo( pDocument );
499cdf0e10cSrcweir }
500cdf0e10cSrcweir }
501cdf0e10cSrcweir
FillAuto(SCCOL nCol1,SCROW nRow1,SCCOL nCol2,SCROW nRow2,sal_uLong nFillCount,FillDir eFillDir,ScProgress & rProgress)502cdf0e10cSrcweir void ScTable::FillAuto( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
503cdf0e10cSrcweir sal_uLong nFillCount, FillDir eFillDir, ScProgress& rProgress )
504cdf0e10cSrcweir {
505cdf0e10cSrcweir if ( (nFillCount == 0) || !ValidColRow(nCol1, nRow1) || !ValidColRow(nCol2, nRow2) )
506cdf0e10cSrcweir return;
507cdf0e10cSrcweir
508cdf0e10cSrcweir //
509cdf0e10cSrcweir // Richtung auswerten
510cdf0e10cSrcweir //
511cdf0e10cSrcweir
512cdf0e10cSrcweir sal_Bool bVertical = (eFillDir == FILL_TO_BOTTOM || eFillDir == FILL_TO_TOP);
513cdf0e10cSrcweir sal_Bool bPositive = (eFillDir == FILL_TO_BOTTOM || eFillDir == FILL_TO_RIGHT);
514cdf0e10cSrcweir
515cdf0e10cSrcweir sal_uLong nCol = 0;
516cdf0e10cSrcweir sal_uLong nRow = 0;
517cdf0e10cSrcweir sal_uLong& rInner = bVertical ? nRow : nCol; // Schleifenvariablen
518cdf0e10cSrcweir sal_uLong& rOuter = bVertical ? nCol : nRow;
519cdf0e10cSrcweir sal_uLong nOStart;
520cdf0e10cSrcweir sal_uLong nOEnd;
521cdf0e10cSrcweir sal_uLong nIStart;
522cdf0e10cSrcweir sal_uLong nIEnd;
523cdf0e10cSrcweir sal_uLong nISrcStart;
524cdf0e10cSrcweir sal_uLong nISrcEnd;
525cdf0e10cSrcweir
526cdf0e10cSrcweir if (bVertical)
527cdf0e10cSrcweir {
528cdf0e10cSrcweir nOStart = nCol1;
529cdf0e10cSrcweir nOEnd = nCol2;
530cdf0e10cSrcweir if (bPositive)
531cdf0e10cSrcweir {
532cdf0e10cSrcweir nISrcStart = nRow1;
533cdf0e10cSrcweir nISrcEnd = nRow2;
534cdf0e10cSrcweir nIStart = nRow2 + 1;
535cdf0e10cSrcweir nIEnd = nRow2 + nFillCount;
536cdf0e10cSrcweir }
537cdf0e10cSrcweir else
538cdf0e10cSrcweir {
539cdf0e10cSrcweir nISrcStart = nRow2;
540cdf0e10cSrcweir nISrcEnd = nRow1;
541cdf0e10cSrcweir nIStart = nRow1 - 1;
542cdf0e10cSrcweir nIEnd = nRow1 - nFillCount;
543cdf0e10cSrcweir }
544cdf0e10cSrcweir }
545cdf0e10cSrcweir else
546cdf0e10cSrcweir {
547cdf0e10cSrcweir nOStart = nRow1;
548cdf0e10cSrcweir nOEnd = nRow2;
549cdf0e10cSrcweir if (bPositive)
550cdf0e10cSrcweir {
551cdf0e10cSrcweir nISrcStart = nCol1;
552cdf0e10cSrcweir nISrcEnd = nCol2;
553cdf0e10cSrcweir nIStart = nCol2 + 1;
554cdf0e10cSrcweir nIEnd = nCol2 + nFillCount;
555cdf0e10cSrcweir }
556cdf0e10cSrcweir else
557cdf0e10cSrcweir {
558cdf0e10cSrcweir nISrcStart = nCol2;
559cdf0e10cSrcweir nISrcEnd = nCol1;
560cdf0e10cSrcweir nIStart = nCol1 - 1;
561cdf0e10cSrcweir nIEnd = nCol1 - nFillCount;
562cdf0e10cSrcweir }
563cdf0e10cSrcweir }
564cdf0e10cSrcweir sal_uLong nIMin = nIStart;
565cdf0e10cSrcweir sal_uLong nIMax = nIEnd;
566cdf0e10cSrcweir PutInOrder(nIMin,nIMax);
567cdf0e10cSrcweir sal_Bool bHasFiltered = IsDataFiltered();
568cdf0e10cSrcweir if (!bHasFiltered) //modify for i89232
569cdf0e10cSrcweir {
570cdf0e10cSrcweir if (bVertical)
571cdf0e10cSrcweir DeleteArea(nCol1, static_cast<SCROW>(nIMin), nCol2, static_cast<SCROW>(nIMax), IDF_AUTOFILL);
572cdf0e10cSrcweir else
573cdf0e10cSrcweir DeleteArea(static_cast<SCCOL>(nIMin), nRow1, static_cast<SCCOL>(nIMax), nRow2, IDF_AUTOFILL);
574cdf0e10cSrcweir }
575cdf0e10cSrcweir sal_uLong nProgress = rProgress.GetState();
576cdf0e10cSrcweir
577cdf0e10cSrcweir //
578cdf0e10cSrcweir // ausfuehren
579cdf0e10cSrcweir //
580cdf0e10cSrcweir
581cdf0e10cSrcweir sal_uLong nActFormCnt = 0;
582cdf0e10cSrcweir for (rOuter = nOStart; rOuter <= nOEnd; rOuter++)
583cdf0e10cSrcweir {
584cdf0e10cSrcweir sal_uLong nMaxFormCnt = 0; // fuer Formeln
585cdf0e10cSrcweir
586cdf0e10cSrcweir // Attributierung uebertragen
587cdf0e10cSrcweir
588cdf0e10cSrcweir const ScPatternAttr* pSrcPattern = NULL;
589cdf0e10cSrcweir const ScStyleSheet* pStyleSheet = NULL;
590cdf0e10cSrcweir sal_uLong nAtSrc = nISrcStart;
591cdf0e10cSrcweir ScPatternAttr* pNewPattern = NULL;
592cdf0e10cSrcweir sal_Bool bGetPattern = sal_True;
593cdf0e10cSrcweir rInner = nIStart;
594cdf0e10cSrcweir while (true) // #i53728# with "for (;;)" old solaris/x86 compiler mis-optimizes
595cdf0e10cSrcweir {
596cdf0e10cSrcweir if ( bGetPattern )
597cdf0e10cSrcweir {
598cdf0e10cSrcweir if ( pNewPattern )
599cdf0e10cSrcweir delete pNewPattern;
600cdf0e10cSrcweir if (bVertical) // rInner&:=nRow, rOuter&:=nCol
601cdf0e10cSrcweir pSrcPattern = aCol[nCol].GetPattern(static_cast<SCROW>(nAtSrc));
602cdf0e10cSrcweir else // rInner&:=nCol, rOuter&:=nRow
603cdf0e10cSrcweir pSrcPattern = aCol[nAtSrc].GetPattern(static_cast<SCROW>(nRow));
604cdf0e10cSrcweir bGetPattern = sal_False;
605cdf0e10cSrcweir pStyleSheet = pSrcPattern->GetStyleSheet();
606cdf0e10cSrcweir // Merge/Mergeflag nicht uebernehmen,
607cdf0e10cSrcweir const SfxItemSet& rSet = pSrcPattern->GetItemSet();
608cdf0e10cSrcweir if ( rSet.GetItemState(ATTR_MERGE, sal_False) == SFX_ITEM_SET
609cdf0e10cSrcweir || rSet.GetItemState(ATTR_MERGE_FLAG, sal_False) == SFX_ITEM_SET )
610cdf0e10cSrcweir {
611cdf0e10cSrcweir pNewPattern = new ScPatternAttr( *pSrcPattern );
612cdf0e10cSrcweir SfxItemSet& rNewSet = pNewPattern->GetItemSet();
613cdf0e10cSrcweir rNewSet.ClearItem(ATTR_MERGE);
614cdf0e10cSrcweir rNewSet.ClearItem(ATTR_MERGE_FLAG);
615cdf0e10cSrcweir }
616cdf0e10cSrcweir else
617cdf0e10cSrcweir pNewPattern = NULL;
618cdf0e10cSrcweir }
619cdf0e10cSrcweir
620cdf0e10cSrcweir if ( bVertical && nISrcStart == nISrcEnd && !bHasFiltered )
621cdf0e10cSrcweir {
622cdf0e10cSrcweir // Attribute komplett am Stueck setzen
623cdf0e10cSrcweir if (pNewPattern || pSrcPattern != pDocument->GetDefPattern())
624cdf0e10cSrcweir {
625cdf0e10cSrcweir // Default steht schon da (DeleteArea)
626cdf0e10cSrcweir SCROW nY1 = static_cast<SCROW>(Min( nIStart, nIEnd ));
627cdf0e10cSrcweir SCROW nY2 = static_cast<SCROW>(Max( nIStart, nIEnd ));
628cdf0e10cSrcweir if ( pStyleSheet )
629cdf0e10cSrcweir aCol[nCol].ApplyStyleArea( nY1, nY2, *pStyleSheet );
630cdf0e10cSrcweir if ( pNewPattern )
631cdf0e10cSrcweir aCol[nCol].ApplyPatternArea( nY1, nY2, *pNewPattern );
632cdf0e10cSrcweir else
633cdf0e10cSrcweir aCol[nCol].ApplyPatternArea( nY1, nY2, *pSrcPattern );
634cdf0e10cSrcweir }
635cdf0e10cSrcweir break; // Schleife abbrechen
636cdf0e10cSrcweir }
637cdf0e10cSrcweir
638cdf0e10cSrcweir if ( !RowFiltered(nRow) )
639cdf0e10cSrcweir {
640cdf0e10cSrcweir if ( bHasFiltered )
641cdf0e10cSrcweir DeleteArea(static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow),
642cdf0e10cSrcweir static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), IDF_AUTOFILL);
643cdf0e10cSrcweir
644cdf0e10cSrcweir if ( pSrcPattern != aCol[nCol].GetPattern( static_cast<SCROW>(nRow) ) )
645cdf0e10cSrcweir {
646cdf0e10cSrcweir // Vorlage auch uebernehmen
647cdf0e10cSrcweir //! am AttrArray mit ApplyPattern zusammenfassen ??
648cdf0e10cSrcweir if ( pStyleSheet )
649cdf0e10cSrcweir aCol[nCol].ApplyStyle( static_cast<SCROW>(nRow), *pStyleSheet );
650cdf0e10cSrcweir
651cdf0e10cSrcweir // ApplyPattern statt SetPattern um alte MergeFlags stehenzulassen
652cdf0e10cSrcweir if ( pNewPattern )
653cdf0e10cSrcweir aCol[nCol].ApplyPattern( static_cast<SCROW>(nRow), *pNewPattern );
654cdf0e10cSrcweir else
655cdf0e10cSrcweir aCol[nCol].ApplyPattern( static_cast<SCROW>(nRow), *pSrcPattern );
656cdf0e10cSrcweir }
657cdf0e10cSrcweir
658cdf0e10cSrcweir if (nAtSrc==nISrcEnd)
659cdf0e10cSrcweir {
660cdf0e10cSrcweir if ( nAtSrc != nISrcStart )
661cdf0e10cSrcweir { // mehr als eine Source-Zelle
662cdf0e10cSrcweir nAtSrc = nISrcStart;
663cdf0e10cSrcweir bGetPattern = sal_True;
664cdf0e10cSrcweir }
665cdf0e10cSrcweir }
666cdf0e10cSrcweir else if (bPositive)
667cdf0e10cSrcweir {
668cdf0e10cSrcweir ++nAtSrc;
669cdf0e10cSrcweir bGetPattern = sal_True;
670cdf0e10cSrcweir }
671cdf0e10cSrcweir else
672cdf0e10cSrcweir {
673cdf0e10cSrcweir --nAtSrc;
674cdf0e10cSrcweir bGetPattern = sal_True;
675cdf0e10cSrcweir }
676cdf0e10cSrcweir }
677cdf0e10cSrcweir
678cdf0e10cSrcweir if (rInner == nIEnd) break;
679cdf0e10cSrcweir if (bPositive) ++rInner; else --rInner;
680cdf0e10cSrcweir }
681cdf0e10cSrcweir if ( pNewPattern )
682cdf0e10cSrcweir delete pNewPattern;
683cdf0e10cSrcweir
684cdf0e10cSrcweir // Analyse
685cdf0e10cSrcweir
686cdf0e10cSrcweir FillCmd eFillCmd;
687cdf0e10cSrcweir FillDateCmd eDateCmd;
688cdf0e10cSrcweir double nInc;
689cdf0e10cSrcweir sal_uInt16 nMinDigits;
690cdf0e10cSrcweir ScUserListData* pListData = NULL;
691cdf0e10cSrcweir sal_uInt16 nListIndex;
692cdf0e10cSrcweir if (bVertical)
693cdf0e10cSrcweir FillAnalyse(static_cast<SCCOL>(nCol),nRow1,
694cdf0e10cSrcweir static_cast<SCCOL>(nCol),nRow2, eFillCmd,eDateCmd,
695cdf0e10cSrcweir nInc,nMinDigits, pListData,nListIndex);
696cdf0e10cSrcweir else
697cdf0e10cSrcweir FillAnalyse(nCol1,static_cast<SCROW>(nRow),
698cdf0e10cSrcweir nCol2,static_cast<SCROW>(nRow), eFillCmd,eDateCmd,
699cdf0e10cSrcweir nInc,nMinDigits, pListData,nListIndex);
700cdf0e10cSrcweir
701cdf0e10cSrcweir if (bVertical)
702cdf0e10cSrcweir aCol[nCol].Resize( aCol[nCol].GetCellCount() + nFillCount );
703cdf0e10cSrcweir
704cdf0e10cSrcweir if (pListData)
705cdf0e10cSrcweir {
706cdf0e10cSrcweir sal_uInt16 nListCount = pListData->GetSubCount();
707cdf0e10cSrcweir if ( !bPositive )
708cdf0e10cSrcweir {
709cdf0e10cSrcweir // nListIndex auf FillAnalyse zeigt auf den letzten Eintrag -> anpassen
710cdf0e10cSrcweir sal_uLong nSub = nISrcStart - nISrcEnd;
711cdf0e10cSrcweir for (sal_uLong i=0; i<nSub; i++)
712cdf0e10cSrcweir {
713cdf0e10cSrcweir if (nListIndex == 0) nListIndex = nListCount;
714cdf0e10cSrcweir --nListIndex;
715cdf0e10cSrcweir }
716cdf0e10cSrcweir }
717cdf0e10cSrcweir
718cdf0e10cSrcweir rInner = nIStart;
719cdf0e10cSrcweir while (true) // #i53728# with "for (;;)" old solaris/x86 compiler mis-optimizes
720cdf0e10cSrcweir {
721cdf0e10cSrcweir if (bPositive)
722cdf0e10cSrcweir {
723cdf0e10cSrcweir ++nListIndex;
724cdf0e10cSrcweir if (nListIndex >= nListCount) nListIndex = 0;
725cdf0e10cSrcweir }
726cdf0e10cSrcweir else
727cdf0e10cSrcweir {
728cdf0e10cSrcweir if (nListIndex == 0) nListIndex = nListCount;
729cdf0e10cSrcweir --nListIndex;
730cdf0e10cSrcweir }
731cdf0e10cSrcweir aCol[nCol].Insert(static_cast<SCROW>(nRow), new ScStringCell(pListData->GetSubStr(nListIndex)));
732cdf0e10cSrcweir
733cdf0e10cSrcweir if (rInner == nIEnd) break;
734cdf0e10cSrcweir if (bPositive) ++rInner; else --rInner;
735cdf0e10cSrcweir }
736cdf0e10cSrcweir nProgress += nIMax - nIMin + 1;
737cdf0e10cSrcweir rProgress.SetStateOnPercent( nProgress );
738cdf0e10cSrcweir }
739cdf0e10cSrcweir else if (eFillCmd == FILL_SIMPLE) // Auffuellen mit Muster
740cdf0e10cSrcweir {
741cdf0e10cSrcweir sal_uLong nSource = nISrcStart;
742cdf0e10cSrcweir double nDelta;
743cdf0e10cSrcweir if (( nScFillModeMouseModifier & KEY_MOD1 )||bHasFiltered) //i89232
744cdf0e10cSrcweir nDelta = 0.0;
745cdf0e10cSrcweir else if ( bPositive )
746cdf0e10cSrcweir nDelta = 1.0;
747cdf0e10cSrcweir else
748cdf0e10cSrcweir nDelta = -1.0;
749cdf0e10cSrcweir double nVal = 0.0;
750cdf0e10cSrcweir sal_uLong nFormulaCounter = nActFormCnt;
751cdf0e10cSrcweir sal_Bool bFirst = sal_True;
752cdf0e10cSrcweir sal_Bool bGetCell = sal_True;
753cdf0e10cSrcweir sal_uInt16 nCellDigits = 0;
754cdf0e10cSrcweir short nHeadNoneTail = 0;
755cdf0e10cSrcweir sal_Int32 nStringValue = 0;
756cdf0e10cSrcweir String aValue;
757cdf0e10cSrcweir ScBaseCell* pSrcCell = NULL;
758cdf0e10cSrcweir CellType eCellType = CELLTYPE_NONE;
759cdf0e10cSrcweir sal_Bool bIsOrdinalSuffix = sal_False;
760cdf0e10cSrcweir sal_Bool bRowFiltered = sal_False; //i89232
761cdf0e10cSrcweir
762cdf0e10cSrcweir rInner = nIStart;
763cdf0e10cSrcweir while (true) // #i53728# with "for (;;)" old solaris/x86 compiler mis-optimizes
764cdf0e10cSrcweir {
765cdf0e10cSrcweir if ( bGetCell )
766cdf0e10cSrcweir {
767cdf0e10cSrcweir if (bVertical) // rInner&:=nRow, rOuter&:=nCol
768cdf0e10cSrcweir pSrcCell = aCol[nCol].GetCell( static_cast<SCROW>(nSource) );
769cdf0e10cSrcweir else // rInner&:=nCol, rOuter&:=nRow
770cdf0e10cSrcweir pSrcCell = aCol[nSource].GetCell( static_cast<SCROW>(nRow) );
771cdf0e10cSrcweir bGetCell = sal_False;
772cdf0e10cSrcweir if ( pSrcCell )
773cdf0e10cSrcweir {
774cdf0e10cSrcweir eCellType = pSrcCell->GetCellType();
775cdf0e10cSrcweir switch ( eCellType )
776cdf0e10cSrcweir {
777cdf0e10cSrcweir case CELLTYPE_VALUE:
778cdf0e10cSrcweir nVal = ((ScValueCell*)pSrcCell)->GetValue();
779cdf0e10cSrcweir break;
780cdf0e10cSrcweir case CELLTYPE_STRING:
781cdf0e10cSrcweir case CELLTYPE_EDIT:
782cdf0e10cSrcweir if ( eCellType == CELLTYPE_STRING )
783cdf0e10cSrcweir ((ScStringCell*)pSrcCell)->GetString( aValue );
784cdf0e10cSrcweir else
785cdf0e10cSrcweir ((ScEditCell*)pSrcCell)->GetString( aValue );
786cdf0e10cSrcweir if ( !(nScFillModeMouseModifier & KEY_MOD1) && !bHasFiltered) //i89232
787cdf0e10cSrcweir {
788cdf0e10cSrcweir nCellDigits = 0; // look at each source cell individually
789cdf0e10cSrcweir nHeadNoneTail = lcl_DecompValueString(
790cdf0e10cSrcweir aValue, nStringValue, &nCellDigits );
791cdf0e10cSrcweir
792cdf0e10cSrcweir bIsOrdinalSuffix = aValue.Equals(
793cdf0e10cSrcweir ScGlobal::GetOrdinalSuffix( nStringValue));
794cdf0e10cSrcweir }
795cdf0e10cSrcweir break;
796cdf0e10cSrcweir default:
797cdf0e10cSrcweir {
798cdf0e10cSrcweir // added to avoid warnings
799cdf0e10cSrcweir }
800cdf0e10cSrcweir }
801cdf0e10cSrcweir }
802cdf0e10cSrcweir else
803cdf0e10cSrcweir eCellType = CELLTYPE_NONE;
804cdf0e10cSrcweir }
805cdf0e10cSrcweir
806cdf0e10cSrcweir //Modify for i89232
807cdf0e10cSrcweir bRowFiltered = mpFilteredRows->getValue(nRow);
808cdf0e10cSrcweir
809cdf0e10cSrcweir if (!bRowFiltered)
810cdf0e10cSrcweir {
811cdf0e10cSrcweir //End of i89232
812cdf0e10cSrcweir
813cdf0e10cSrcweir switch (eCellType)
814cdf0e10cSrcweir {
815cdf0e10cSrcweir case CELLTYPE_VALUE:
816cdf0e10cSrcweir aCol[nCol].Insert(static_cast<SCROW>(nRow), new ScValueCell(nVal + nDelta));
817cdf0e10cSrcweir break;
818cdf0e10cSrcweir case CELLTYPE_STRING:
819cdf0e10cSrcweir case CELLTYPE_EDIT:
820cdf0e10cSrcweir if ( nHeadNoneTail )
821cdf0e10cSrcweir {
822cdf0e10cSrcweir // #i48009# with the "nStringValue+(long)nDelta" expression within the
823cdf0e10cSrcweir // lcl_ValueString calls, gcc 3.4.1 makes wrong optimizations (ok in 3.4.3),
824cdf0e10cSrcweir // so nNextValue is now calculated ahead.
825cdf0e10cSrcweir sal_Int32 nNextValue = nStringValue+(sal_Int32)nDelta;
826cdf0e10cSrcweir
827cdf0e10cSrcweir String aStr;
828cdf0e10cSrcweir if ( nHeadNoneTail < 0 )
829cdf0e10cSrcweir {
830cdf0e10cSrcweir aCol[nCol].Insert( static_cast<SCROW>(nRow),
831cdf0e10cSrcweir lcl_getSuffixCell( pDocument,
832cdf0e10cSrcweir nNextValue, nCellDigits, aValue,
833cdf0e10cSrcweir eCellType, bIsOrdinalSuffix));
834cdf0e10cSrcweir }
835cdf0e10cSrcweir else
836cdf0e10cSrcweir {
837cdf0e10cSrcweir aStr = aValue;
838cdf0e10cSrcweir aStr += lcl_ValueString( nNextValue, nCellDigits );
839cdf0e10cSrcweir aCol[nCol].Insert( static_cast<SCROW>(nRow),
840cdf0e10cSrcweir new ScStringCell( aStr));
841cdf0e10cSrcweir }
842cdf0e10cSrcweir }
843cdf0e10cSrcweir else
844cdf0e10cSrcweir {
845cdf0e10cSrcweir ScAddress aDestPos( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), nTab );
846cdf0e10cSrcweir switch ( eCellType )
847cdf0e10cSrcweir {
848cdf0e10cSrcweir case CELLTYPE_STRING:
849cdf0e10cSrcweir case CELLTYPE_EDIT:
850cdf0e10cSrcweir aCol[nCol].Insert( aDestPos.Row(), pSrcCell->CloneWithoutNote( *pDocument ) );
851cdf0e10cSrcweir break;
852cdf0e10cSrcweir default:
853cdf0e10cSrcweir {
854cdf0e10cSrcweir // added to avoid warnings
855cdf0e10cSrcweir }
856cdf0e10cSrcweir }
857cdf0e10cSrcweir }
858cdf0e10cSrcweir break;
859cdf0e10cSrcweir case CELLTYPE_FORMULA :
860cdf0e10cSrcweir FillFormula( nFormulaCounter, bFirst,
861cdf0e10cSrcweir (ScFormulaCell*) pSrcCell,
862cdf0e10cSrcweir static_cast<SCCOL>(nCol),
863cdf0e10cSrcweir static_cast<SCROW>(nRow), (rInner == nIEnd) );
864cdf0e10cSrcweir if (nFormulaCounter - nActFormCnt > nMaxFormCnt)
865cdf0e10cSrcweir nMaxFormCnt = nFormulaCounter - nActFormCnt;
866cdf0e10cSrcweir break;
867cdf0e10cSrcweir default:
868cdf0e10cSrcweir {
869cdf0e10cSrcweir // added to avoid warnings
870cdf0e10cSrcweir }
871cdf0e10cSrcweir }
872cdf0e10cSrcweir
873cdf0e10cSrcweir if (nSource==nISrcEnd)
874cdf0e10cSrcweir {
875cdf0e10cSrcweir if ( nSource != nISrcStart )
876cdf0e10cSrcweir { // mehr als eine Source-Zelle
877cdf0e10cSrcweir nSource = nISrcStart;
878cdf0e10cSrcweir bGetCell = sal_True;
879cdf0e10cSrcweir }
880cdf0e10cSrcweir if ( !(nScFillModeMouseModifier & KEY_MOD1) && !bHasFiltered ) //i89232
881cdf0e10cSrcweir {
882cdf0e10cSrcweir if ( bPositive )
883cdf0e10cSrcweir nDelta += 1.0;
884cdf0e10cSrcweir else
885cdf0e10cSrcweir nDelta -= 1.0;
886cdf0e10cSrcweir }
887cdf0e10cSrcweir nFormulaCounter = nActFormCnt;
888cdf0e10cSrcweir bFirst = sal_False;
889cdf0e10cSrcweir }
890cdf0e10cSrcweir else if (bPositive)
891cdf0e10cSrcweir {
892cdf0e10cSrcweir ++nSource;
893cdf0e10cSrcweir bGetCell = sal_True;
894cdf0e10cSrcweir }
895cdf0e10cSrcweir else
896cdf0e10cSrcweir {
897cdf0e10cSrcweir --nSource;
898cdf0e10cSrcweir bGetCell = sal_True;
899cdf0e10cSrcweir }
900cdf0e10cSrcweir }
901cdf0e10cSrcweir
902cdf0e10cSrcweir // Progress in der inneren Schleife nur bei teuren Zellen,
903cdf0e10cSrcweir // und auch dann nicht fuer jede einzelne
904cdf0e10cSrcweir
905cdf0e10cSrcweir ++nProgress;
906cdf0e10cSrcweir if ( eCellType == CELLTYPE_FORMULA || eCellType == CELLTYPE_EDIT )
907cdf0e10cSrcweir rProgress.SetStateOnPercent( nProgress );
908cdf0e10cSrcweir
909cdf0e10cSrcweir if (rInner == nIEnd) break;
910cdf0e10cSrcweir if (bPositive) ++rInner; else --rInner;
911cdf0e10cSrcweir }
912cdf0e10cSrcweir rProgress.SetStateOnPercent( nProgress );
913cdf0e10cSrcweir }
914cdf0e10cSrcweir else
915cdf0e10cSrcweir {
916cdf0e10cSrcweir if (!bPositive)
917cdf0e10cSrcweir nInc = -nInc;
918cdf0e10cSrcweir double nEndVal = (nInc>=0.0) ? MAXDOUBLE : -MAXDOUBLE;
919cdf0e10cSrcweir if (bVertical)
920cdf0e10cSrcweir FillSeries( static_cast<SCCOL>(nCol), nRow1,
921cdf0e10cSrcweir static_cast<SCCOL>(nCol), nRow2, nFillCount, eFillDir,
922cdf0e10cSrcweir eFillCmd, eDateCmd, nInc, nEndVal, nMinDigits, sal_False,
923cdf0e10cSrcweir rProgress );
924cdf0e10cSrcweir else
925cdf0e10cSrcweir FillSeries( nCol1, static_cast<SCROW>(nRow), nCol2,
926cdf0e10cSrcweir static_cast<SCROW>(nRow), nFillCount, eFillDir,
927cdf0e10cSrcweir eFillCmd, eDateCmd, nInc, nEndVal, nMinDigits, sal_False,
928cdf0e10cSrcweir rProgress );
929cdf0e10cSrcweir nProgress = rProgress.GetState();
930cdf0e10cSrcweir }
931cdf0e10cSrcweir
932cdf0e10cSrcweir nActFormCnt += nMaxFormCnt;
933cdf0e10cSrcweir }
934cdf0e10cSrcweir }
935cdf0e10cSrcweir
GetAutoFillPreview(const ScRange & rSource,SCCOL nEndX,SCROW nEndY)936cdf0e10cSrcweir String ScTable::GetAutoFillPreview( const ScRange& rSource, SCCOL nEndX, SCROW nEndY )
937cdf0e10cSrcweir {
938cdf0e10cSrcweir String aValue;
939cdf0e10cSrcweir
940cdf0e10cSrcweir SCCOL nCol1 = rSource.aStart.Col();
941cdf0e10cSrcweir SCROW nRow1 = rSource.aStart.Row();
942cdf0e10cSrcweir SCCOL nCol2 = rSource.aEnd.Col();
943cdf0e10cSrcweir SCROW nRow2 = rSource.aEnd.Row();
944cdf0e10cSrcweir sal_Bool bOk = sal_True;
945cdf0e10cSrcweir long nIndex = 0;
946cdf0e10cSrcweir sal_uLong nSrcCount = 0;
947cdf0e10cSrcweir FillDir eFillDir = FILL_TO_BOTTOM;
948cdf0e10cSrcweir if ( nEndX == nCol2 && nEndY == nRow2 ) // leer
949cdf0e10cSrcweir bOk = sal_False;
950cdf0e10cSrcweir else if ( nEndX == nCol2 ) // nach oben/unten
951cdf0e10cSrcweir {
952cdf0e10cSrcweir nEndX = nCol2 = nCol1; // nur erste Spalte ansehen
953cdf0e10cSrcweir nSrcCount = nRow2 - nRow1 + 1;
954cdf0e10cSrcweir nIndex = ((long)nEndY) - nRow1; // kann negativ werden
955cdf0e10cSrcweir if ( nEndY >= nRow1 )
956cdf0e10cSrcweir eFillDir = FILL_TO_BOTTOM;
957cdf0e10cSrcweir else
958cdf0e10cSrcweir eFillDir = FILL_TO_TOP;
959cdf0e10cSrcweir }
960cdf0e10cSrcweir else if ( nEndY == nRow2 ) // nach links/rechts
961cdf0e10cSrcweir {
962cdf0e10cSrcweir nEndY = nRow2 = nRow1; // nur erste Zeile ansehen
963cdf0e10cSrcweir nSrcCount = nCol2 - nCol1 + 1;
964cdf0e10cSrcweir nIndex = ((long)nEndX) - nCol1; // kann negativ werden
965cdf0e10cSrcweir if ( nEndX >= nCol1 )
966cdf0e10cSrcweir eFillDir = FILL_TO_RIGHT;
967cdf0e10cSrcweir else
968cdf0e10cSrcweir eFillDir = FILL_TO_LEFT;
969cdf0e10cSrcweir }
970cdf0e10cSrcweir else // Richtung nicht eindeutig
971cdf0e10cSrcweir bOk = sal_False;
972cdf0e10cSrcweir
973cdf0e10cSrcweir if ( bOk )
974cdf0e10cSrcweir {
975cdf0e10cSrcweir FillCmd eFillCmd;
976cdf0e10cSrcweir FillDateCmd eDateCmd;
977cdf0e10cSrcweir double nInc;
978cdf0e10cSrcweir sal_uInt16 nMinDigits;
979cdf0e10cSrcweir ScUserListData* pListData = NULL;
980cdf0e10cSrcweir sal_uInt16 nListIndex;
981cdf0e10cSrcweir
982cdf0e10cSrcweir FillAnalyse(nCol1,nRow1, nCol2,nRow2, eFillCmd,eDateCmd, nInc,nMinDigits, pListData,nListIndex);
983cdf0e10cSrcweir
984cdf0e10cSrcweir if ( pListData ) // benutzerdefinierte Liste
985cdf0e10cSrcweir {
986cdf0e10cSrcweir sal_uInt16 nListCount = pListData->GetSubCount();
987cdf0e10cSrcweir if ( nListCount )
988cdf0e10cSrcweir {
989cdf0e10cSrcweir sal_uLong nSub = nSrcCount - 1; // nListIndex ist vom letzten Source-Eintrag
990cdf0e10cSrcweir while ( nIndex < sal::static_int_cast<long>(nSub) )
991cdf0e10cSrcweir nIndex += nListCount;
992cdf0e10cSrcweir sal_uLong nPos = ( nListIndex + nIndex - nSub ) % nListCount;
993cdf0e10cSrcweir aValue = pListData->GetSubStr(sal::static_int_cast<sal_uInt16>(nPos));
994cdf0e10cSrcweir }
995cdf0e10cSrcweir }
996cdf0e10cSrcweir else if ( eFillCmd == FILL_SIMPLE ) // Auffuellen mit Muster
997cdf0e10cSrcweir {
998cdf0e10cSrcweir //Add for i89232
999cdf0e10cSrcweir if ((eFillDir == FILL_TO_BOTTOM)||(eFillDir == FILL_TO_TOP))
1000cdf0e10cSrcweir {
1001cdf0e10cSrcweir long nBegin = 0;
1002cdf0e10cSrcweir long nEnd = 0;
1003cdf0e10cSrcweir if (nEndY > nRow1)
1004cdf0e10cSrcweir {
1005cdf0e10cSrcweir nBegin = nRow2+1;
1006cdf0e10cSrcweir nEnd = nEndY;
1007cdf0e10cSrcweir }
1008cdf0e10cSrcweir else
1009cdf0e10cSrcweir {
1010cdf0e10cSrcweir nBegin = nEndY;
1011cdf0e10cSrcweir nEnd = nRow1 -1;
1012cdf0e10cSrcweir }
1013cdf0e10cSrcweir long nNonFiltered = CountNonFilteredRows(nBegin, nEnd);
1014cdf0e10cSrcweir long nFiltered = nEnd + 1 - nBegin - nNonFiltered;
1015cdf0e10cSrcweir if (nIndex >0)
1016cdf0e10cSrcweir nIndex = nIndex - nFiltered;
1017cdf0e10cSrcweir else
1018cdf0e10cSrcweir nIndex = nIndex + nFiltered;
1019cdf0e10cSrcweir }
1020cdf0e10cSrcweir //End of i89232
1021cdf0e10cSrcweir
1022cdf0e10cSrcweir long nPosIndex = nIndex;
1023cdf0e10cSrcweir while ( nPosIndex < 0 )
1024cdf0e10cSrcweir nPosIndex += nSrcCount;
1025cdf0e10cSrcweir sal_uLong nPos = nPosIndex % nSrcCount;
1026cdf0e10cSrcweir SCCOL nSrcX = nCol1;
1027cdf0e10cSrcweir SCROW nSrcY = nRow1;
1028cdf0e10cSrcweir if ( eFillDir == FILL_TO_TOP || eFillDir == FILL_TO_BOTTOM )
1029cdf0e10cSrcweir nSrcY = sal::static_int_cast<SCROW>( nSrcY + static_cast<SCROW>(nPos) );
1030cdf0e10cSrcweir else
1031cdf0e10cSrcweir nSrcX = sal::static_int_cast<SCCOL>( nSrcX + static_cast<SCCOL>(nPos) );
1032cdf0e10cSrcweir
1033cdf0e10cSrcweir ScBaseCell* pCell = GetCell( nSrcX, nSrcY );
1034cdf0e10cSrcweir if ( pCell )
1035cdf0e10cSrcweir {
1036cdf0e10cSrcweir sal_Int32 nDelta;
1037cdf0e10cSrcweir if (nIndex >= 0)
1038cdf0e10cSrcweir nDelta = nIndex / nSrcCount;
1039cdf0e10cSrcweir else
1040cdf0e10cSrcweir nDelta = ( nIndex - nSrcCount + 1 ) / nSrcCount; // -1 -> -1
1041cdf0e10cSrcweir
1042cdf0e10cSrcweir CellType eType = pCell->GetCellType();
1043cdf0e10cSrcweir switch ( eType )
1044cdf0e10cSrcweir {
1045cdf0e10cSrcweir case CELLTYPE_STRING:
1046cdf0e10cSrcweir case CELLTYPE_EDIT:
1047cdf0e10cSrcweir {
1048cdf0e10cSrcweir if ( eType == CELLTYPE_STRING )
1049cdf0e10cSrcweir ((ScStringCell*)pCell)->GetString( aValue );
1050cdf0e10cSrcweir else
1051cdf0e10cSrcweir ((ScEditCell*)pCell)->GetString( aValue );
1052cdf0e10cSrcweir if ( !(nScFillModeMouseModifier & KEY_MOD1) && !IsDataFiltered() ) //i89232
1053cdf0e10cSrcweir {
1054cdf0e10cSrcweir sal_Int32 nVal;
1055cdf0e10cSrcweir sal_uInt16 nCellDigits = 0; // look at each source cell individually
1056cdf0e10cSrcweir short nFlag = lcl_DecompValueString( aValue, nVal, &nCellDigits );
1057cdf0e10cSrcweir if ( nFlag < 0 )
1058cdf0e10cSrcweir {
1059cdf0e10cSrcweir if (aValue.Equals( ScGlobal::GetOrdinalSuffix( nVal)))
1060cdf0e10cSrcweir aValue = ScGlobal::GetOrdinalSuffix( nVal + nDelta);
1061cdf0e10cSrcweir
1062cdf0e10cSrcweir aValue.Insert( lcl_ValueString( nVal + nDelta, nCellDigits ), 0 );
1063cdf0e10cSrcweir }
1064cdf0e10cSrcweir else if ( nFlag > 0 )
1065cdf0e10cSrcweir aValue += lcl_ValueString( nVal + nDelta, nCellDigits );
1066cdf0e10cSrcweir }
1067cdf0e10cSrcweir }
1068cdf0e10cSrcweir break;
1069cdf0e10cSrcweir case CELLTYPE_VALUE:
1070cdf0e10cSrcweir {
1071cdf0e10cSrcweir // dabei kann's keinen Ueberlauf geben...
1072cdf0e10cSrcweir double nVal = ((ScValueCell*)pCell)->GetValue();
1073cdf0e10cSrcweir if ( !(nScFillModeMouseModifier & KEY_MOD1) && !IsDataFiltered() ) //i89232
1074cdf0e10cSrcweir nVal += (double) nDelta;
1075cdf0e10cSrcweir
1076cdf0e10cSrcweir Color* pColor;
1077cdf0e10cSrcweir sal_uLong nNumFmt = GetNumberFormat( nSrcX, nSrcY );
1078cdf0e10cSrcweir pDocument->GetFormatTable()->
1079cdf0e10cSrcweir GetOutputString( nVal, nNumFmt, aValue, &pColor );
1080cdf0e10cSrcweir }
1081cdf0e10cSrcweir break;
1082cdf0e10cSrcweir // Formeln nicht
1083cdf0e10cSrcweir default:
1084cdf0e10cSrcweir {
1085cdf0e10cSrcweir // added to avoid warnings
1086cdf0e10cSrcweir }
1087cdf0e10cSrcweir }
1088cdf0e10cSrcweir }
1089cdf0e10cSrcweir }
1090cdf0e10cSrcweir else if ( eFillCmd == FILL_LINEAR || eFillCmd == FILL_DATE ) // Werte
1091cdf0e10cSrcweir {
1092cdf0e10cSrcweir sal_Bool bValueOk;
1093cdf0e10cSrcweir double nStart;
1094cdf0e10cSrcweir sal_Int32 nVal = 0;
1095cdf0e10cSrcweir short nHeadNoneTail = 0;
1096cdf0e10cSrcweir ScBaseCell* pCell = GetCell( nCol1, nRow1 );
1097cdf0e10cSrcweir if ( pCell )
1098cdf0e10cSrcweir {
1099cdf0e10cSrcweir CellType eType = pCell->GetCellType();
1100cdf0e10cSrcweir switch ( eType )
1101cdf0e10cSrcweir {
1102cdf0e10cSrcweir case CELLTYPE_STRING:
1103cdf0e10cSrcweir case CELLTYPE_EDIT:
1104cdf0e10cSrcweir {
1105cdf0e10cSrcweir if ( eType == CELLTYPE_STRING )
1106cdf0e10cSrcweir ((ScStringCell*)pCell)->GetString( aValue );
1107cdf0e10cSrcweir else
1108cdf0e10cSrcweir ((ScEditCell*)pCell)->GetString( aValue );
1109cdf0e10cSrcweir nHeadNoneTail = lcl_DecompValueString( aValue, nVal );
1110cdf0e10cSrcweir if ( nHeadNoneTail )
1111cdf0e10cSrcweir nStart = (double)nVal;
1112cdf0e10cSrcweir else
1113cdf0e10cSrcweir nStart = 0.0;
1114cdf0e10cSrcweir }
1115cdf0e10cSrcweir break;
1116cdf0e10cSrcweir case CELLTYPE_VALUE:
1117cdf0e10cSrcweir nStart = ((ScValueCell*)pCell)->GetValue();
1118cdf0e10cSrcweir break;
1119cdf0e10cSrcweir case CELLTYPE_FORMULA:
1120cdf0e10cSrcweir nStart = ((ScFormulaCell*)pCell)->GetValue();
1121cdf0e10cSrcweir break;
1122cdf0e10cSrcweir default:
1123cdf0e10cSrcweir nStart = 0.0;
1124cdf0e10cSrcweir }
1125cdf0e10cSrcweir }
1126cdf0e10cSrcweir else
1127cdf0e10cSrcweir nStart = 0.0;
1128cdf0e10cSrcweir if ( eFillCmd == FILL_LINEAR )
1129cdf0e10cSrcweir {
1130cdf0e10cSrcweir double nAdd = nInc;
1131cdf0e10cSrcweir bValueOk = ( SubTotal::SafeMult( nAdd, (double) nIndex ) &&
1132cdf0e10cSrcweir SubTotal::SafePlus( nStart, nAdd ) );
1133cdf0e10cSrcweir }
1134cdf0e10cSrcweir else // Datum
1135cdf0e10cSrcweir {
1136cdf0e10cSrcweir bValueOk = sal_True;
1137cdf0e10cSrcweir sal_uInt16 nDayOfMonth = 0;
1138cdf0e10cSrcweir if ( nIndex < 0 )
1139cdf0e10cSrcweir {
1140cdf0e10cSrcweir nIndex = -nIndex;
1141cdf0e10cSrcweir nInc = -nInc;
1142cdf0e10cSrcweir }
1143cdf0e10cSrcweir for (long i=0; i<nIndex; i++)
1144cdf0e10cSrcweir IncDate( nStart, nDayOfMonth, nInc, eDateCmd );
1145cdf0e10cSrcweir }
1146cdf0e10cSrcweir
1147cdf0e10cSrcweir if (bValueOk)
1148cdf0e10cSrcweir {
1149cdf0e10cSrcweir if ( nHeadNoneTail )
1150cdf0e10cSrcweir {
1151cdf0e10cSrcweir if ( nHeadNoneTail < 0 )
1152cdf0e10cSrcweir {
1153cdf0e10cSrcweir if (aValue.Equals( ScGlobal::GetOrdinalSuffix( nVal)))
1154cdf0e10cSrcweir aValue = ScGlobal::GetOrdinalSuffix( (sal_Int32)nStart );
1155cdf0e10cSrcweir
1156cdf0e10cSrcweir aValue.Insert( lcl_ValueString( (sal_Int32)nStart, nMinDigits ), 0 );
1157cdf0e10cSrcweir }
1158cdf0e10cSrcweir else
1159cdf0e10cSrcweir aValue += lcl_ValueString( (sal_Int32)nStart, nMinDigits );
1160cdf0e10cSrcweir }
1161cdf0e10cSrcweir else
1162cdf0e10cSrcweir {
1163cdf0e10cSrcweir //! Zahlformat je nach Index holen?
1164cdf0e10cSrcweir Color* pColor;
1165cdf0e10cSrcweir sal_uLong nNumFmt = GetNumberFormat( nCol1, nRow1 );
1166cdf0e10cSrcweir pDocument->GetFormatTable()->
1167cdf0e10cSrcweir GetOutputString( nStart, nNumFmt, aValue, &pColor );
1168cdf0e10cSrcweir }
1169cdf0e10cSrcweir }
1170cdf0e10cSrcweir }
1171cdf0e10cSrcweir else
1172cdf0e10cSrcweir {
1173cdf0e10cSrcweir DBG_ERROR("GetAutoFillPreview: falscher Modus");
1174cdf0e10cSrcweir }
1175cdf0e10cSrcweir }
1176cdf0e10cSrcweir
1177cdf0e10cSrcweir return aValue;
1178cdf0e10cSrcweir }
1179cdf0e10cSrcweir
IncDate(double & rVal,sal_uInt16 & nDayOfMonth,double nStep,FillDateCmd eCmd)1180cdf0e10cSrcweir void ScTable::IncDate(double& rVal, sal_uInt16& nDayOfMonth, double nStep, FillDateCmd eCmd)
1181cdf0e10cSrcweir {
1182cdf0e10cSrcweir if (eCmd == FILL_DAY)
1183cdf0e10cSrcweir {
1184cdf0e10cSrcweir rVal += nStep;
1185cdf0e10cSrcweir return;
1186cdf0e10cSrcweir }
1187cdf0e10cSrcweir
1188cdf0e10cSrcweir // class Date Grenzen
1189cdf0e10cSrcweir const sal_uInt16 nMinYear = 1583;
1190cdf0e10cSrcweir const sal_uInt16 nMaxYear = 9956;
1191cdf0e10cSrcweir
1192cdf0e10cSrcweir long nInc = (long) nStep; // nach oben/unten begrenzen ?
1193cdf0e10cSrcweir Date aNullDate = *pDocument->GetFormatTable()->GetNullDate();
1194cdf0e10cSrcweir Date aDate = aNullDate;
1195cdf0e10cSrcweir aDate += (long)rVal;
1196cdf0e10cSrcweir switch (eCmd)
1197cdf0e10cSrcweir {
1198cdf0e10cSrcweir case FILL_WEEKDAY:
1199cdf0e10cSrcweir {
1200cdf0e10cSrcweir aDate += nInc;
1201cdf0e10cSrcweir DayOfWeek eWeekDay = aDate.GetDayOfWeek();
1202cdf0e10cSrcweir if (nInc >= 0)
1203cdf0e10cSrcweir {
1204cdf0e10cSrcweir if (eWeekDay == SATURDAY)
1205cdf0e10cSrcweir aDate += 2;
1206cdf0e10cSrcweir else if (eWeekDay == SUNDAY)
1207cdf0e10cSrcweir aDate += 1;
1208cdf0e10cSrcweir }
1209cdf0e10cSrcweir else
1210cdf0e10cSrcweir {
1211cdf0e10cSrcweir if (eWeekDay == SATURDAY)
1212cdf0e10cSrcweir aDate -= 1;
1213cdf0e10cSrcweir else if (eWeekDay == SUNDAY)
1214cdf0e10cSrcweir aDate -= 2;
1215cdf0e10cSrcweir }
1216cdf0e10cSrcweir }
1217cdf0e10cSrcweir break;
1218cdf0e10cSrcweir case FILL_MONTH:
1219cdf0e10cSrcweir {
1220cdf0e10cSrcweir if ( nDayOfMonth == 0 )
1221cdf0e10cSrcweir nDayOfMonth = aDate.GetDay(); // init
1222cdf0e10cSrcweir long nMonth = aDate.GetMonth();
1223cdf0e10cSrcweir long nYear = aDate.GetYear();
1224cdf0e10cSrcweir
1225cdf0e10cSrcweir nMonth += nInc;
1226cdf0e10cSrcweir
1227cdf0e10cSrcweir if (nInc >= 0)
1228cdf0e10cSrcweir {
1229cdf0e10cSrcweir if (nMonth > 12)
1230cdf0e10cSrcweir {
1231cdf0e10cSrcweir long nYAdd = (nMonth-1) / 12;
1232cdf0e10cSrcweir nMonth -= nYAdd * 12;
1233cdf0e10cSrcweir nYear += nYAdd;
1234cdf0e10cSrcweir }
1235cdf0e10cSrcweir }
1236cdf0e10cSrcweir else
1237cdf0e10cSrcweir {
1238cdf0e10cSrcweir if (nMonth < 1)
1239cdf0e10cSrcweir {
1240cdf0e10cSrcweir long nYAdd = 1 - nMonth / 12; // positiv
1241cdf0e10cSrcweir nMonth += nYAdd * 12;
1242cdf0e10cSrcweir nYear -= nYAdd;
1243cdf0e10cSrcweir }
1244cdf0e10cSrcweir }
1245cdf0e10cSrcweir
1246cdf0e10cSrcweir if ( nYear < nMinYear )
1247cdf0e10cSrcweir aDate = Date( 1,1, nMinYear );
1248cdf0e10cSrcweir else if ( nYear > nMaxYear )
1249cdf0e10cSrcweir aDate = Date( 31,12, nMaxYear );
1250cdf0e10cSrcweir else
1251cdf0e10cSrcweir {
1252cdf0e10cSrcweir aDate.SetMonth((sal_uInt16) nMonth);
1253cdf0e10cSrcweir aDate.SetYear((sal_uInt16) nYear);
1254cdf0e10cSrcweir if ( nDayOfMonth > 28 )
1255cdf0e10cSrcweir aDate.SetDay( Min( aDate.GetDaysInMonth(), nDayOfMonth ) );
1256cdf0e10cSrcweir }
1257cdf0e10cSrcweir }
1258cdf0e10cSrcweir break;
1259cdf0e10cSrcweir case FILL_YEAR:
1260cdf0e10cSrcweir {
1261cdf0e10cSrcweir long nYear = aDate.GetYear();
1262cdf0e10cSrcweir nYear += nInc;
1263cdf0e10cSrcweir if ( nYear < nMinYear )
1264cdf0e10cSrcweir aDate = Date( 1,1, nMinYear );
1265cdf0e10cSrcweir else if ( nYear > nMaxYear )
1266cdf0e10cSrcweir aDate = Date( 31,12, nMaxYear );
1267cdf0e10cSrcweir else
1268cdf0e10cSrcweir aDate.SetYear((sal_uInt16) nYear);
1269cdf0e10cSrcweir }
1270cdf0e10cSrcweir break;
1271cdf0e10cSrcweir default:
1272cdf0e10cSrcweir {
1273cdf0e10cSrcweir // added to avoid warnings
1274cdf0e10cSrcweir }
1275cdf0e10cSrcweir }
1276cdf0e10cSrcweir
1277cdf0e10cSrcweir rVal = aDate - aNullDate;
1278cdf0e10cSrcweir }
1279cdf0e10cSrcweir
FillSeries(SCCOL nCol1,SCROW nRow1,SCCOL nCol2,SCROW nRow2,sal_uLong nFillCount,FillDir eFillDir,FillCmd eFillCmd,FillDateCmd eFillDateCmd,double nStepValue,double nMaxValue,sal_uInt16 nArgMinDigits,sal_Bool bAttribs,ScProgress & rProgress)1280cdf0e10cSrcweir void ScTable::FillSeries( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
1281cdf0e10cSrcweir sal_uLong nFillCount, FillDir eFillDir, FillCmd eFillCmd, FillDateCmd eFillDateCmd,
1282cdf0e10cSrcweir double nStepValue, double nMaxValue, sal_uInt16 nArgMinDigits,
1283cdf0e10cSrcweir sal_Bool bAttribs, ScProgress& rProgress )
1284cdf0e10cSrcweir {
1285cdf0e10cSrcweir //
1286cdf0e10cSrcweir // Richtung auswerten
1287cdf0e10cSrcweir //
1288cdf0e10cSrcweir
1289cdf0e10cSrcweir sal_Bool bVertical = (eFillDir == FILL_TO_BOTTOM || eFillDir == FILL_TO_TOP);
1290cdf0e10cSrcweir sal_Bool bPositive = (eFillDir == FILL_TO_BOTTOM || eFillDir == FILL_TO_RIGHT);
1291cdf0e10cSrcweir
1292cdf0e10cSrcweir sal_uLong nCol = 0;
1293cdf0e10cSrcweir sal_uLong nRow = 0;
1294cdf0e10cSrcweir sal_uLong& rInner = bVertical ? nRow : nCol; // Schleifenvariablen
1295cdf0e10cSrcweir sal_uLong& rOuter = bVertical ? nCol : nRow;
1296cdf0e10cSrcweir sal_uLong nOStart;
1297cdf0e10cSrcweir sal_uLong nOEnd;
1298cdf0e10cSrcweir sal_uLong nIStart;
1299cdf0e10cSrcweir sal_uLong nIEnd;
1300cdf0e10cSrcweir sal_uLong nISource;
1301cdf0e10cSrcweir
1302cdf0e10cSrcweir if (bVertical)
1303cdf0e10cSrcweir {
1304cdf0e10cSrcweir nFillCount += (nRow2 - nRow1);
1305cdf0e10cSrcweir if (nFillCount == 0)
1306cdf0e10cSrcweir return;
1307cdf0e10cSrcweir nOStart = nCol1;
1308cdf0e10cSrcweir nOEnd = nCol2;
1309cdf0e10cSrcweir if (bPositive)
1310cdf0e10cSrcweir {
1311cdf0e10cSrcweir nISource = nRow1;
1312cdf0e10cSrcweir nIStart = nRow1 + 1;
1313cdf0e10cSrcweir nIEnd = nRow1 + nFillCount;
1314cdf0e10cSrcweir }
1315cdf0e10cSrcweir else
1316cdf0e10cSrcweir {
1317cdf0e10cSrcweir nISource = nRow2;
1318cdf0e10cSrcweir nIStart = nRow2 - 1;
1319cdf0e10cSrcweir nIEnd = nRow2 - nFillCount;
1320cdf0e10cSrcweir }
1321cdf0e10cSrcweir }
1322cdf0e10cSrcweir else
1323cdf0e10cSrcweir {
1324cdf0e10cSrcweir nFillCount += (nCol2 - nCol1);
1325cdf0e10cSrcweir if (nFillCount == 0)
1326cdf0e10cSrcweir return;
1327cdf0e10cSrcweir nOStart = nRow1;
1328cdf0e10cSrcweir nOEnd = nRow2;
1329cdf0e10cSrcweir if (bPositive)
1330cdf0e10cSrcweir {
1331cdf0e10cSrcweir nISource = nCol1;
1332cdf0e10cSrcweir nIStart = nCol1 + 1;
1333cdf0e10cSrcweir nIEnd = nCol1 + nFillCount;
1334cdf0e10cSrcweir }
1335cdf0e10cSrcweir else
1336cdf0e10cSrcweir {
1337cdf0e10cSrcweir nISource = nCol2;
1338cdf0e10cSrcweir nIStart = nCol2 - 1;
1339cdf0e10cSrcweir nIEnd = nCol2 - nFillCount;
1340cdf0e10cSrcweir }
1341cdf0e10cSrcweir }
1342cdf0e10cSrcweir
1343cdf0e10cSrcweir sal_uLong nIMin = nIStart;
1344cdf0e10cSrcweir sal_uLong nIMax = nIEnd;
1345cdf0e10cSrcweir PutInOrder(nIMin,nIMax);
1346cdf0e10cSrcweir sal_uInt16 nDel = bAttribs ? IDF_AUTOFILL : (IDF_AUTOFILL & IDF_CONTENTS);
1347cdf0e10cSrcweir if (bVertical)
1348cdf0e10cSrcweir DeleteArea(nCol1, static_cast<SCROW>(nIMin), nCol2, static_cast<SCROW>(nIMax), nDel);
1349cdf0e10cSrcweir else
1350cdf0e10cSrcweir DeleteArea(static_cast<SCCOL>(nIMin), nRow1, static_cast<SCCOL>(nIMax), nRow2, nDel);
1351cdf0e10cSrcweir
1352cdf0e10cSrcweir sal_uLong nProgress = rProgress.GetState();
1353cdf0e10cSrcweir
1354cdf0e10cSrcweir //
1355cdf0e10cSrcweir // ausfuehren
1356cdf0e10cSrcweir //
1357cdf0e10cSrcweir
1358cdf0e10cSrcweir sal_uLong nActFormCnt = 0;
1359cdf0e10cSrcweir for (rOuter = nOStart; rOuter <= nOEnd; rOuter++)
1360cdf0e10cSrcweir {
1361cdf0e10cSrcweir sal_Bool bFirst = sal_True;
1362cdf0e10cSrcweir rInner = nISource;
1363cdf0e10cSrcweir ScBaseCell* pSrcCell = aCol[nCol].GetCell(static_cast<SCROW>(nRow));
1364cdf0e10cSrcweir
1365cdf0e10cSrcweir if (bVertical && bAttribs)
1366cdf0e10cSrcweir aCol[nCol].Resize( aCol[nCol].GetCellCount() + nFillCount );
1367cdf0e10cSrcweir
1368cdf0e10cSrcweir if (bAttribs)
1369cdf0e10cSrcweir {
1370cdf0e10cSrcweir const ScPatternAttr* pSrcPattern = aCol[nCol].GetPattern(static_cast<SCROW>(nRow));
1371cdf0e10cSrcweir if (bVertical)
1372cdf0e10cSrcweir aCol[nCol].SetPatternArea( static_cast<SCROW>(nIMin),
1373cdf0e10cSrcweir static_cast<SCROW>(nIMax), *pSrcPattern, sal_True );
1374cdf0e10cSrcweir else
1375cdf0e10cSrcweir for (SCCOL nAtCol = static_cast<SCCOL>(nIMin); nAtCol <= sal::static_int_cast<SCCOL>(nIMax); nAtCol++)
1376cdf0e10cSrcweir aCol[nAtCol].SetPattern(static_cast<SCROW>(nRow), *pSrcPattern, sal_True);
1377cdf0e10cSrcweir }
1378cdf0e10cSrcweir
1379cdf0e10cSrcweir if (pSrcCell)
1380cdf0e10cSrcweir {
1381cdf0e10cSrcweir CellType eCellType = pSrcCell->GetCellType();
1382cdf0e10cSrcweir
1383cdf0e10cSrcweir if (eFillCmd == FILL_SIMPLE) // kopieren
1384cdf0e10cSrcweir {
1385cdf0e10cSrcweir if (eCellType == CELLTYPE_FORMULA)
1386cdf0e10cSrcweir {
1387cdf0e10cSrcweir for (rInner = nIMin; rInner <= nIMax; rInner++)
1388cdf0e10cSrcweir {
1389cdf0e10cSrcweir sal_uLong nInd = nActFormCnt;
1390cdf0e10cSrcweir FillFormula(nInd, bFirst, (ScFormulaCell*)pSrcCell,
1391cdf0e10cSrcweir static_cast<SCCOL>(nCol), nRow, (rInner == nIEnd) );
1392cdf0e10cSrcweir bFirst = sal_False;
1393cdf0e10cSrcweir rProgress.SetStateOnPercent( ++nProgress );
1394cdf0e10cSrcweir }
1395cdf0e10cSrcweir }
1396cdf0e10cSrcweir else if (eCellType != CELLTYPE_NOTE)
1397cdf0e10cSrcweir {
1398cdf0e10cSrcweir for (rInner = nIMin; rInner <= nIMax; rInner++)
1399cdf0e10cSrcweir {
1400cdf0e10cSrcweir ScAddress aDestPos( static_cast<SCCOL>(nCol), static_cast<SCROW>(nRow), nTab );
1401cdf0e10cSrcweir aCol[nCol].Insert( aDestPos.Row(), pSrcCell->CloneWithoutNote( *pDocument ) );
1402cdf0e10cSrcweir }
1403cdf0e10cSrcweir nProgress += nIMax - nIMin + 1;
1404cdf0e10cSrcweir rProgress.SetStateOnPercent( nProgress );
1405cdf0e10cSrcweir }
1406cdf0e10cSrcweir }
1407cdf0e10cSrcweir else if (eCellType == CELLTYPE_VALUE || eCellType == CELLTYPE_FORMULA)
1408cdf0e10cSrcweir {
1409cdf0e10cSrcweir double nStartVal;
1410cdf0e10cSrcweir if (eCellType == CELLTYPE_VALUE)
1411cdf0e10cSrcweir nStartVal = ((ScValueCell*)pSrcCell)->GetValue();
1412cdf0e10cSrcweir else
1413cdf0e10cSrcweir nStartVal = ((ScFormulaCell*)pSrcCell)->GetValue();
1414cdf0e10cSrcweir double nVal = nStartVal;
1415cdf0e10cSrcweir long nIndex = 0;
1416cdf0e10cSrcweir
1417cdf0e10cSrcweir sal_Bool bError = sal_False;
1418cdf0e10cSrcweir sal_Bool bOverflow = sal_False;
1419cdf0e10cSrcweir
1420cdf0e10cSrcweir sal_uInt16 nDayOfMonth = 0;
1421cdf0e10cSrcweir rInner = nIStart;
1422cdf0e10cSrcweir while (true) // #i53728# with "for (;;)" old solaris/x86 compiler mis-optimizes
1423cdf0e10cSrcweir {
1424cdf0e10cSrcweir if (!bError && !bOverflow)
1425cdf0e10cSrcweir {
1426cdf0e10cSrcweir switch (eFillCmd)
1427cdf0e10cSrcweir {
1428cdf0e10cSrcweir case FILL_LINEAR:
1429cdf0e10cSrcweir {
1430cdf0e10cSrcweir // #86365# use multiplication instead of repeated addition
1431cdf0e10cSrcweir // to avoid accumulating rounding errors
1432cdf0e10cSrcweir nVal = nStartVal;
1433cdf0e10cSrcweir double nAdd = nStepValue;
1434cdf0e10cSrcweir if ( !SubTotal::SafeMult( nAdd, (double) ++nIndex ) ||
1435cdf0e10cSrcweir !SubTotal::SafePlus( nVal, nAdd ) )
1436cdf0e10cSrcweir bError = sal_True;
1437cdf0e10cSrcweir }
1438cdf0e10cSrcweir break;
1439cdf0e10cSrcweir case FILL_GROWTH:
1440cdf0e10cSrcweir if (!SubTotal::SafeMult(nVal, nStepValue))
1441cdf0e10cSrcweir bError = sal_True;
1442cdf0e10cSrcweir break;
1443cdf0e10cSrcweir case FILL_DATE:
1444cdf0e10cSrcweir if (fabs(nVal) > _D_MAX_LONG_)
1445cdf0e10cSrcweir bError = sal_True;
1446cdf0e10cSrcweir else
1447cdf0e10cSrcweir IncDate(nVal, nDayOfMonth, nStepValue, eFillDateCmd);
1448cdf0e10cSrcweir break;
1449cdf0e10cSrcweir default:
1450cdf0e10cSrcweir {
1451cdf0e10cSrcweir // added to avoid warnings
1452cdf0e10cSrcweir }
1453cdf0e10cSrcweir }
1454cdf0e10cSrcweir
1455cdf0e10cSrcweir if (nStepValue >= 0)
1456cdf0e10cSrcweir {
1457cdf0e10cSrcweir if (nVal > nMaxValue) // Zielwert erreicht?
1458cdf0e10cSrcweir {
1459cdf0e10cSrcweir nVal = nMaxValue;
1460cdf0e10cSrcweir bOverflow = sal_True;
1461cdf0e10cSrcweir }
1462cdf0e10cSrcweir }
1463cdf0e10cSrcweir else
1464cdf0e10cSrcweir {
1465cdf0e10cSrcweir if (nVal < nMaxValue)
1466cdf0e10cSrcweir {
1467cdf0e10cSrcweir nVal = nMaxValue;
1468cdf0e10cSrcweir bOverflow = sal_True;
1469cdf0e10cSrcweir }
1470cdf0e10cSrcweir }
1471cdf0e10cSrcweir }
1472cdf0e10cSrcweir
1473cdf0e10cSrcweir if (bError)
1474cdf0e10cSrcweir aCol[nCol].SetError(static_cast<SCROW>(nRow), errNoValue);
1475cdf0e10cSrcweir else if (!bOverflow)
1476cdf0e10cSrcweir aCol[nCol].SetValue(static_cast<SCROW>(nRow), nVal);
1477cdf0e10cSrcweir
1478cdf0e10cSrcweir if (rInner == nIEnd) break;
1479cdf0e10cSrcweir if (bPositive) ++rInner; else --rInner;
1480cdf0e10cSrcweir }
1481cdf0e10cSrcweir nProgress += nIMax - nIMin + 1;
1482cdf0e10cSrcweir rProgress.SetStateOnPercent( nProgress );
1483cdf0e10cSrcweir }
1484cdf0e10cSrcweir else if (eCellType == CELLTYPE_STRING || eCellType == CELLTYPE_EDIT)
1485cdf0e10cSrcweir {
1486cdf0e10cSrcweir if ( nStepValue >= 0 )
1487cdf0e10cSrcweir {
1488cdf0e10cSrcweir if ( nMaxValue >= (double)LONG_MAX )
1489cdf0e10cSrcweir nMaxValue = (double)LONG_MAX - 1;
1490cdf0e10cSrcweir }
1491cdf0e10cSrcweir else
1492cdf0e10cSrcweir {
1493cdf0e10cSrcweir if ( nMaxValue <= (double)LONG_MIN )
1494cdf0e10cSrcweir nMaxValue = (double)LONG_MIN + 1;
1495cdf0e10cSrcweir }
1496cdf0e10cSrcweir String aValue;
1497cdf0e10cSrcweir if (eCellType == CELLTYPE_STRING)
1498cdf0e10cSrcweir ((ScStringCell*)pSrcCell)->GetString( aValue );
1499cdf0e10cSrcweir else
1500cdf0e10cSrcweir ((ScEditCell*)pSrcCell)->GetString( aValue );
1501cdf0e10cSrcweir sal_Int32 nStringValue;
1502cdf0e10cSrcweir sal_uInt16 nMinDigits = nArgMinDigits;
1503cdf0e10cSrcweir short nHeadNoneTail = lcl_DecompValueString( aValue, nStringValue, &nMinDigits );
1504cdf0e10cSrcweir if ( nHeadNoneTail )
1505cdf0e10cSrcweir {
1506cdf0e10cSrcweir double nStartVal = (double)nStringValue;
1507cdf0e10cSrcweir double nVal = nStartVal;
1508cdf0e10cSrcweir long nIndex = 0;
1509cdf0e10cSrcweir sal_Bool bError = sal_False;
1510cdf0e10cSrcweir sal_Bool bOverflow = sal_False;
1511cdf0e10cSrcweir
1512cdf0e10cSrcweir sal_Bool bIsOrdinalSuffix = aValue.Equals( ScGlobal::GetOrdinalSuffix(
1513cdf0e10cSrcweir (sal_Int32)nStartVal));
1514cdf0e10cSrcweir
1515cdf0e10cSrcweir rInner = nIStart;
1516cdf0e10cSrcweir while (true) // #i53728# with "for (;;)" old solaris/x86 compiler mis-optimizes
1517cdf0e10cSrcweir {
1518cdf0e10cSrcweir if (!bError && !bOverflow)
1519cdf0e10cSrcweir {
1520cdf0e10cSrcweir switch (eFillCmd)
1521cdf0e10cSrcweir {
1522cdf0e10cSrcweir case FILL_LINEAR:
1523cdf0e10cSrcweir {
1524cdf0e10cSrcweir // #86365# use multiplication instead of repeated addition
1525cdf0e10cSrcweir // to avoid accumulating rounding errors
1526cdf0e10cSrcweir nVal = nStartVal;
1527cdf0e10cSrcweir double nAdd = nStepValue;
1528cdf0e10cSrcweir if ( !SubTotal::SafeMult( nAdd, (double) ++nIndex ) ||
1529cdf0e10cSrcweir !SubTotal::SafePlus( nVal, nAdd ) )
1530cdf0e10cSrcweir bError = sal_True;
1531cdf0e10cSrcweir }
1532cdf0e10cSrcweir break;
1533cdf0e10cSrcweir case FILL_GROWTH:
1534cdf0e10cSrcweir if (!SubTotal::SafeMult(nVal, nStepValue))
1535cdf0e10cSrcweir bError = sal_True;
1536cdf0e10cSrcweir break;
1537cdf0e10cSrcweir default:
1538cdf0e10cSrcweir {
1539cdf0e10cSrcweir // added to avoid warnings
1540cdf0e10cSrcweir }
1541cdf0e10cSrcweir }
1542cdf0e10cSrcweir
1543cdf0e10cSrcweir if (nStepValue >= 0)
1544cdf0e10cSrcweir {
1545cdf0e10cSrcweir if (nVal > nMaxValue) // Zielwert erreicht?
1546cdf0e10cSrcweir {
1547cdf0e10cSrcweir nVal = nMaxValue;
1548cdf0e10cSrcweir bOverflow = sal_True;
1549cdf0e10cSrcweir }
1550cdf0e10cSrcweir }
1551cdf0e10cSrcweir else
1552cdf0e10cSrcweir {
1553cdf0e10cSrcweir if (nVal < nMaxValue)
1554cdf0e10cSrcweir {
1555cdf0e10cSrcweir nVal = nMaxValue;
1556cdf0e10cSrcweir bOverflow = sal_True;
1557cdf0e10cSrcweir }
1558cdf0e10cSrcweir }
1559cdf0e10cSrcweir }
1560cdf0e10cSrcweir
1561cdf0e10cSrcweir if (bError)
1562cdf0e10cSrcweir aCol[nCol].SetError(static_cast<SCROW>(nRow), errNoValue);
1563cdf0e10cSrcweir else if (!bOverflow)
1564cdf0e10cSrcweir {
1565cdf0e10cSrcweir nStringValue = (sal_Int32)nVal;
1566cdf0e10cSrcweir String aStr;
1567cdf0e10cSrcweir if ( nHeadNoneTail < 0 )
1568cdf0e10cSrcweir {
1569cdf0e10cSrcweir aCol[nCol].Insert( static_cast<SCROW>(nRow),
1570cdf0e10cSrcweir lcl_getSuffixCell( pDocument,
1571cdf0e10cSrcweir nStringValue, nMinDigits, aValue,
1572cdf0e10cSrcweir eCellType, bIsOrdinalSuffix ));
1573cdf0e10cSrcweir }
1574cdf0e10cSrcweir else
1575cdf0e10cSrcweir {
1576cdf0e10cSrcweir aStr = aValue;
1577cdf0e10cSrcweir aStr += lcl_ValueString( nStringValue, nMinDigits );
1578cdf0e10cSrcweir ScStringCell* pCell = new ScStringCell( aStr );
1579cdf0e10cSrcweir aCol[nCol].Insert( static_cast<SCROW>(nRow), pCell );
1580cdf0e10cSrcweir }
1581cdf0e10cSrcweir }
1582cdf0e10cSrcweir
1583cdf0e10cSrcweir if (rInner == nIEnd) break;
1584cdf0e10cSrcweir if (bPositive) ++rInner; else --rInner;
1585cdf0e10cSrcweir }
1586cdf0e10cSrcweir }
1587cdf0e10cSrcweir nProgress += nIMax - nIMin + 1;
1588cdf0e10cSrcweir rProgress.SetStateOnPercent( nProgress );
1589cdf0e10cSrcweir }
1590cdf0e10cSrcweir }
1591cdf0e10cSrcweir else
1592cdf0e10cSrcweir {
1593cdf0e10cSrcweir nProgress += nIMax - nIMin + 1;
1594cdf0e10cSrcweir rProgress.SetStateOnPercent( nProgress );
1595cdf0e10cSrcweir }
1596cdf0e10cSrcweir ++nActFormCnt;
1597cdf0e10cSrcweir }
1598cdf0e10cSrcweir }
1599cdf0e10cSrcweir
Fill(SCCOL nCol1,SCROW nRow1,SCCOL nCol2,SCROW nRow2,sal_uLong nFillCount,FillDir eFillDir,FillCmd eFillCmd,FillDateCmd eFillDateCmd,double nStepValue,double nMaxValue)1600cdf0e10cSrcweir void ScTable::Fill( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
1601cdf0e10cSrcweir sal_uLong nFillCount, FillDir eFillDir, FillCmd eFillCmd, FillDateCmd eFillDateCmd,
1602cdf0e10cSrcweir double nStepValue, double nMaxValue)
1603cdf0e10cSrcweir {
1604cdf0e10cSrcweir sal_uLong nProgCount;
1605cdf0e10cSrcweir if (eFillDir == FILL_TO_BOTTOM || eFillDir == FILL_TO_TOP)
1606cdf0e10cSrcweir nProgCount = nCol2 - nCol1 + 1;
1607cdf0e10cSrcweir else
1608cdf0e10cSrcweir nProgCount = nRow2 - nRow1 + 1;
1609cdf0e10cSrcweir nProgCount *= nFillCount;
1610cdf0e10cSrcweir ScProgress aProgress( pDocument->GetDocumentShell(),
1611cdf0e10cSrcweir ScGlobal::GetRscString(STR_FILL_SERIES_PROGRESS), nProgCount );
1612cdf0e10cSrcweir
1613cdf0e10cSrcweir bSharedNameInserted = sal_False;
1614cdf0e10cSrcweir
1615cdf0e10cSrcweir if (eFillCmd == FILL_AUTO)
1616cdf0e10cSrcweir FillAuto(nCol1, nRow1, nCol2, nRow2, nFillCount, eFillDir, aProgress);
1617cdf0e10cSrcweir else
1618cdf0e10cSrcweir FillSeries(nCol1, nRow1, nCol2, nRow2, nFillCount, eFillDir,
1619cdf0e10cSrcweir eFillCmd, eFillDateCmd, nStepValue, nMaxValue, 0, sal_True, aProgress);
1620cdf0e10cSrcweir
1621cdf0e10cSrcweir if (bSharedNameInserted) // Wurde Shared-Name eingefuegt?
1622cdf0e10cSrcweir pDocument->GetRangeName()->SetSharedMaxIndex(
1623cdf0e10cSrcweir pDocument->GetRangeName()->GetSharedMaxIndex()+1); // dann hochzaehlen
1624cdf0e10cSrcweir }
1625cdf0e10cSrcweir
1626cdf0e10cSrcweir
AutoFormatArea(SCCOL nStartCol,SCROW nStartRow,SCCOL nEndCol,SCROW nEndRow,const ScPatternAttr & rAttr,sal_uInt16 nFormatNo)1627cdf0e10cSrcweir void ScTable::AutoFormatArea(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
1628cdf0e10cSrcweir const ScPatternAttr& rAttr, sal_uInt16 nFormatNo)
1629cdf0e10cSrcweir {
1630cdf0e10cSrcweir ScAutoFormat* pAutoFormat = ScGlobal::GetAutoFormat();
1631cdf0e10cSrcweir if (pAutoFormat)
1632cdf0e10cSrcweir {
1633cdf0e10cSrcweir ScAutoFormatData* pData = (*pAutoFormat)[nFormatNo];
1634cdf0e10cSrcweir if (pData)
1635cdf0e10cSrcweir {
1636cdf0e10cSrcweir // ScPatternAttr aPattern(pDocument->GetPool());
1637cdf0e10cSrcweir // pData->FillToItemSet(nIndex, aPattern.GetItemSet(), *pDocument);
1638cdf0e10cSrcweir ApplyPatternArea(nStartCol, nStartRow, nEndCol, nEndRow, rAttr);
1639cdf0e10cSrcweir }
1640cdf0e10cSrcweir }
1641cdf0e10cSrcweir }
1642cdf0e10cSrcweir
AutoFormat(SCCOL nStartCol,SCROW nStartRow,SCCOL nEndCol,SCROW nEndRow,sal_uInt16 nFormatNo)1643cdf0e10cSrcweir void ScTable::AutoFormat( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
1644cdf0e10cSrcweir sal_uInt16 nFormatNo )
1645cdf0e10cSrcweir {
1646cdf0e10cSrcweir if (ValidColRow(nStartCol, nStartRow) && ValidColRow(nEndCol, nEndRow))
1647cdf0e10cSrcweir {
1648cdf0e10cSrcweir ScAutoFormat* pAutoFormat = ScGlobal::GetAutoFormat();
1649cdf0e10cSrcweir if (pAutoFormat)
1650cdf0e10cSrcweir {
1651cdf0e10cSrcweir ScAutoFormatData* pData = (*pAutoFormat)[nFormatNo];
1652cdf0e10cSrcweir if (pData)
1653cdf0e10cSrcweir {
1654cdf0e10cSrcweir ScPatternAttr* pPatternAttrs[16];
1655cdf0e10cSrcweir for (sal_uInt8 i = 0; i < 16; ++i)
1656cdf0e10cSrcweir {
1657cdf0e10cSrcweir pPatternAttrs[i] = new ScPatternAttr(pDocument->GetPool());
1658cdf0e10cSrcweir pData->FillToItemSet(i, pPatternAttrs[i]->GetItemSet(), *pDocument);
1659cdf0e10cSrcweir }
1660cdf0e10cSrcweir
1661cdf0e10cSrcweir SCCOL nCol = nStartCol;
1662cdf0e10cSrcweir SCROW nRow = nStartRow;
1663cdf0e10cSrcweir sal_uInt16 nIndex = 0;
1664cdf0e10cSrcweir // Linke obere Ecke
1665cdf0e10cSrcweir AutoFormatArea(nCol, nRow, nCol, nRow, *pPatternAttrs[nIndex], nFormatNo);
1666cdf0e10cSrcweir // Linke Spalte
1667cdf0e10cSrcweir if (pData->IsEqualData(4, 8))
1668cdf0e10cSrcweir AutoFormatArea(nStartCol, nStartRow + 1, nStartCol, nEndRow - 1, *pPatternAttrs[4], nFormatNo);
1669cdf0e10cSrcweir else
1670cdf0e10cSrcweir {
1671cdf0e10cSrcweir nIndex = 4;
1672cdf0e10cSrcweir for (nRow = nStartRow + 1; nRow < nEndRow; nRow++)
1673cdf0e10cSrcweir {
1674cdf0e10cSrcweir AutoFormatArea(nCol, nRow, nCol, nRow, *pPatternAttrs[nIndex], nFormatNo);
1675cdf0e10cSrcweir if (nIndex == 4)
1676cdf0e10cSrcweir nIndex = 8;
1677cdf0e10cSrcweir else
1678cdf0e10cSrcweir nIndex = 4;
1679cdf0e10cSrcweir }
1680cdf0e10cSrcweir }
1681cdf0e10cSrcweir // Linke untere Ecke
1682cdf0e10cSrcweir nRow = nEndRow;
1683cdf0e10cSrcweir nIndex = 12;
1684cdf0e10cSrcweir AutoFormatArea(nCol, nRow, nCol, nRow, *pPatternAttrs[nIndex], nFormatNo);
1685cdf0e10cSrcweir // Rechte obere Ecke
1686cdf0e10cSrcweir nCol = nEndCol;
1687cdf0e10cSrcweir nRow = nStartRow;
1688cdf0e10cSrcweir nIndex = 3;
1689cdf0e10cSrcweir AutoFormatArea(nCol, nRow, nCol, nRow, *pPatternAttrs[nIndex], nFormatNo);
1690cdf0e10cSrcweir // Rechte Spalte
1691cdf0e10cSrcweir if (pData->IsEqualData(7, 11))
1692cdf0e10cSrcweir AutoFormatArea(nEndCol, nStartRow + 1, nEndCol, nEndRow - 1, *pPatternAttrs[7], nFormatNo);
1693cdf0e10cSrcweir else
1694cdf0e10cSrcweir {
1695cdf0e10cSrcweir nIndex = 7;
1696cdf0e10cSrcweir for (nRow = nStartRow + 1; nRow < nEndRow; nRow++)
1697cdf0e10cSrcweir {
1698cdf0e10cSrcweir AutoFormatArea(nCol, nRow, nCol, nRow, *pPatternAttrs[nIndex], nFormatNo);
1699cdf0e10cSrcweir if (nIndex == 7)
1700cdf0e10cSrcweir nIndex = 11;
1701cdf0e10cSrcweir else
1702cdf0e10cSrcweir nIndex = 7;
1703cdf0e10cSrcweir }
1704cdf0e10cSrcweir }
1705cdf0e10cSrcweir // Rechte untere Ecke
1706cdf0e10cSrcweir nRow = nEndRow;
1707cdf0e10cSrcweir nIndex = 15;
1708cdf0e10cSrcweir AutoFormatArea(nCol, nRow, nCol, nRow, *pPatternAttrs[nIndex], nFormatNo);
1709cdf0e10cSrcweir nRow = nStartRow;
1710cdf0e10cSrcweir nIndex = 1;
1711cdf0e10cSrcweir for (nCol = nStartCol + 1; nCol < nEndCol; nCol++)
1712cdf0e10cSrcweir {
1713cdf0e10cSrcweir AutoFormatArea(nCol, nRow, nCol, nRow, *pPatternAttrs[nIndex], nFormatNo);
1714cdf0e10cSrcweir if (nIndex == 1)
1715cdf0e10cSrcweir nIndex = 2;
1716cdf0e10cSrcweir else
1717cdf0e10cSrcweir nIndex = 1;
1718cdf0e10cSrcweir }
1719cdf0e10cSrcweir // Untere Zeile
1720cdf0e10cSrcweir nRow = nEndRow;
1721cdf0e10cSrcweir nIndex = 13;
1722cdf0e10cSrcweir for (nCol = nStartCol + 1; nCol < nEndCol; nCol++)
1723cdf0e10cSrcweir {
1724cdf0e10cSrcweir AutoFormatArea(nCol, nRow, nCol, nRow, *pPatternAttrs[nIndex], nFormatNo);
1725cdf0e10cSrcweir if (nIndex == 13)
1726cdf0e10cSrcweir nIndex = 14;
1727cdf0e10cSrcweir else
1728cdf0e10cSrcweir nIndex = 13;
1729cdf0e10cSrcweir }
1730cdf0e10cSrcweir // Boddy
1731cdf0e10cSrcweir if ((pData->IsEqualData(5, 6)) && (pData->IsEqualData(9, 10)) && (pData->IsEqualData(5, 9)))
1732cdf0e10cSrcweir AutoFormatArea(nStartCol + 1, nStartRow + 1, nEndCol-1, nEndRow - 1, *pPatternAttrs[5], nFormatNo);
1733cdf0e10cSrcweir else
1734cdf0e10cSrcweir {
1735cdf0e10cSrcweir if ((pData->IsEqualData(5, 9)) && (pData->IsEqualData(6, 10)))
1736cdf0e10cSrcweir {
1737cdf0e10cSrcweir nIndex = 5;
1738cdf0e10cSrcweir for (nCol = nStartCol + 1; nCol < nEndCol; nCol++)
1739cdf0e10cSrcweir {
1740cdf0e10cSrcweir AutoFormatArea(nCol, nStartRow + 1, nCol, nEndRow - 1, *pPatternAttrs[nIndex], nFormatNo);
1741cdf0e10cSrcweir if (nIndex == 5)
1742cdf0e10cSrcweir nIndex = 6;
1743cdf0e10cSrcweir else
1744cdf0e10cSrcweir nIndex = 5;
1745cdf0e10cSrcweir }
1746cdf0e10cSrcweir }
1747cdf0e10cSrcweir else
1748cdf0e10cSrcweir {
1749cdf0e10cSrcweir nIndex = 5;
1750cdf0e10cSrcweir for (nCol = nStartCol + 1; nCol < nEndCol; nCol++)
1751cdf0e10cSrcweir {
1752cdf0e10cSrcweir for (nRow = nStartRow + 1; nRow < nEndRow; nRow++)
1753cdf0e10cSrcweir {
1754cdf0e10cSrcweir AutoFormatArea(nCol, nRow, nCol, nRow, *pPatternAttrs[nIndex], nFormatNo);
1755cdf0e10cSrcweir if ((nIndex == 5) || (nIndex == 9))
1756cdf0e10cSrcweir {
1757cdf0e10cSrcweir if (nIndex == 5)
1758cdf0e10cSrcweir nIndex = 9;
1759cdf0e10cSrcweir else
1760cdf0e10cSrcweir nIndex = 5;
1761cdf0e10cSrcweir }
1762cdf0e10cSrcweir else
1763cdf0e10cSrcweir {
1764cdf0e10cSrcweir if (nIndex == 6)
1765cdf0e10cSrcweir nIndex = 10;
1766cdf0e10cSrcweir else
1767cdf0e10cSrcweir nIndex = 6;
1768cdf0e10cSrcweir }
1769cdf0e10cSrcweir } // for nRow
1770cdf0e10cSrcweir if ((nIndex == 5) || (nIndex == 9))
1771cdf0e10cSrcweir nIndex = 6;
1772cdf0e10cSrcweir else
1773cdf0e10cSrcweir nIndex = 5;
1774cdf0e10cSrcweir } // for nCol
1775cdf0e10cSrcweir } // if not equal Column
1776cdf0e10cSrcweir } // if not all equal
1777cdf0e10cSrcweir
1778cdf0e10cSrcweir for (sal_uInt8 j = 0; j < 16; ++j)
1779cdf0e10cSrcweir delete pPatternAttrs[j];
1780cdf0e10cSrcweir } // if AutoFormatData != NULL
1781cdf0e10cSrcweir } // if AutoFormat != NULL
1782cdf0e10cSrcweir } // if ValidColRow
1783cdf0e10cSrcweir }
1784cdf0e10cSrcweir
GetAutoFormatAttr(SCCOL nCol,SCROW nRow,sal_uInt16 nIndex,ScAutoFormatData & rData)1785cdf0e10cSrcweir void ScTable::GetAutoFormatAttr(SCCOL nCol, SCROW nRow, sal_uInt16 nIndex, ScAutoFormatData& rData)
1786cdf0e10cSrcweir {
1787cdf0e10cSrcweir sal_uInt32 nFormatIndex = GetNumberFormat( nCol, nRow );
1788cdf0e10cSrcweir ScNumFormatAbbrev aNumFormat( nFormatIndex, *pDocument->GetFormatTable() );
1789cdf0e10cSrcweir rData.GetFromItemSet( nIndex, GetPattern( nCol, nRow )->GetItemSet(), aNumFormat );
1790cdf0e10cSrcweir }
1791cdf0e10cSrcweir
1792cdf0e10cSrcweir #define LF_LEFT 1
1793cdf0e10cSrcweir #define LF_TOP 2
1794cdf0e10cSrcweir #define LF_RIGHT 4
1795cdf0e10cSrcweir #define LF_BOTTOM 8
1796cdf0e10cSrcweir #define LF_ALL (LF_LEFT | LF_TOP | LF_RIGHT | LF_BOTTOM)
1797cdf0e10cSrcweir
GetAutoFormatFrame(SCCOL nCol,SCROW nRow,sal_uInt16 nFlags,sal_uInt16 nIndex,ScAutoFormatData & rData)1798cdf0e10cSrcweir void ScTable::GetAutoFormatFrame(SCCOL nCol, SCROW nRow, sal_uInt16 nFlags, sal_uInt16 nIndex, ScAutoFormatData& rData)
1799cdf0e10cSrcweir {
1800cdf0e10cSrcweir const SvxBoxItem* pTheBox = (SvxBoxItem*)GetAttr(nCol, nRow, ATTR_BORDER);
1801cdf0e10cSrcweir const SvxBoxItem* pLeftBox = (SvxBoxItem*)GetAttr(nCol - 1, nRow, ATTR_BORDER);
1802cdf0e10cSrcweir const SvxBoxItem* pTopBox = (SvxBoxItem*)GetAttr(nCol, nRow - 1, ATTR_BORDER);
1803cdf0e10cSrcweir const SvxBoxItem* pRightBox = (SvxBoxItem*)GetAttr(nCol + 1, nRow, ATTR_BORDER);
1804cdf0e10cSrcweir const SvxBoxItem* pBottomBox = (SvxBoxItem*)GetAttr(nCol, nRow + 1, ATTR_BORDER);
1805cdf0e10cSrcweir
1806cdf0e10cSrcweir SvxBoxItem aBox( ATTR_BORDER );
1807cdf0e10cSrcweir if (nFlags & LF_LEFT)
1808cdf0e10cSrcweir {
1809cdf0e10cSrcweir if (pLeftBox)
1810cdf0e10cSrcweir {
1811cdf0e10cSrcweir if (ScHasPriority(pTheBox->GetLeft(), pLeftBox->GetRight()))
1812cdf0e10cSrcweir aBox.SetLine(pTheBox->GetLeft(), BOX_LINE_LEFT);
1813cdf0e10cSrcweir else
1814cdf0e10cSrcweir aBox.SetLine(pLeftBox->GetRight(), BOX_LINE_LEFT);
1815cdf0e10cSrcweir }
1816cdf0e10cSrcweir else
1817cdf0e10cSrcweir aBox.SetLine(pTheBox->GetLeft(), BOX_LINE_LEFT);
1818cdf0e10cSrcweir }
1819cdf0e10cSrcweir if (nFlags & LF_TOP)
1820cdf0e10cSrcweir {
1821cdf0e10cSrcweir if (pTopBox)
1822cdf0e10cSrcweir {
1823cdf0e10cSrcweir if (ScHasPriority(pTheBox->GetTop(), pTopBox->GetBottom()))
1824cdf0e10cSrcweir aBox.SetLine(pTheBox->GetTop(), BOX_LINE_TOP);
1825cdf0e10cSrcweir else
1826cdf0e10cSrcweir aBox.SetLine(pTopBox->GetBottom(), BOX_LINE_TOP);
1827cdf0e10cSrcweir }
1828cdf0e10cSrcweir else
1829cdf0e10cSrcweir aBox.SetLine(pTheBox->GetTop(), BOX_LINE_TOP);
1830cdf0e10cSrcweir }
1831cdf0e10cSrcweir if (nFlags & LF_RIGHT)
1832cdf0e10cSrcweir {
1833cdf0e10cSrcweir if (pRightBox)
1834cdf0e10cSrcweir {
1835cdf0e10cSrcweir if (ScHasPriority(pTheBox->GetRight(), pRightBox->GetLeft()))
1836cdf0e10cSrcweir aBox.SetLine(pTheBox->GetRight(), BOX_LINE_RIGHT);
1837cdf0e10cSrcweir else
1838cdf0e10cSrcweir aBox.SetLine(pRightBox->GetLeft(), BOX_LINE_RIGHT);
1839cdf0e10cSrcweir }
1840cdf0e10cSrcweir else
1841cdf0e10cSrcweir aBox.SetLine(pTheBox->GetRight(), BOX_LINE_RIGHT);
1842cdf0e10cSrcweir }
1843cdf0e10cSrcweir if (nFlags & LF_BOTTOM)
1844cdf0e10cSrcweir {
1845cdf0e10cSrcweir if (pBottomBox)
1846cdf0e10cSrcweir {
1847cdf0e10cSrcweir if (ScHasPriority(pTheBox->GetBottom(), pBottomBox->GetTop()))
1848cdf0e10cSrcweir aBox.SetLine(pTheBox->GetBottom(), BOX_LINE_BOTTOM);
1849cdf0e10cSrcweir else
1850cdf0e10cSrcweir aBox.SetLine(pBottomBox->GetTop(), BOX_LINE_BOTTOM);
1851cdf0e10cSrcweir }
1852cdf0e10cSrcweir else
1853cdf0e10cSrcweir aBox.SetLine(pTheBox->GetBottom(), BOX_LINE_BOTTOM);
1854cdf0e10cSrcweir }
1855cdf0e10cSrcweir rData.PutItem( nIndex, aBox );
1856cdf0e10cSrcweir }
1857cdf0e10cSrcweir
GetAutoFormatData(SCCOL nStartCol,SCROW nStartRow,SCCOL nEndCol,SCROW nEndRow,ScAutoFormatData & rData)1858cdf0e10cSrcweir void ScTable::GetAutoFormatData(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, ScAutoFormatData& rData)
1859cdf0e10cSrcweir {
1860cdf0e10cSrcweir if (ValidColRow(nStartCol, nStartRow) && ValidColRow(nEndCol, nEndRow))
1861cdf0e10cSrcweir {
1862cdf0e10cSrcweir if ((nEndCol - nStartCol >= 3) && (nEndRow - nStartRow >= 3))
1863cdf0e10cSrcweir {
1864cdf0e10cSrcweir // Linke obere Ecke
1865cdf0e10cSrcweir GetAutoFormatAttr(nStartCol, nStartRow, 0, rData);
1866cdf0e10cSrcweir GetAutoFormatFrame(nStartCol, nStartRow, LF_ALL, 0, rData);
1867cdf0e10cSrcweir // Linke Spalte
1868cdf0e10cSrcweir GetAutoFormatAttr(nStartCol, nStartRow + 1, 4, rData);
1869cdf0e10cSrcweir GetAutoFormatAttr(nStartCol, nStartRow + 2, 8, rData);
1870cdf0e10cSrcweir GetAutoFormatFrame(nStartCol, nStartRow + 1, LF_LEFT | LF_RIGHT | LF_BOTTOM, 4, rData);
1871cdf0e10cSrcweir if (nEndRow - nStartRow >= 4)
1872cdf0e10cSrcweir GetAutoFormatFrame(nStartCol, nStartRow + 2, LF_LEFT | LF_RIGHT | LF_BOTTOM, 8, rData);
1873cdf0e10cSrcweir else
1874cdf0e10cSrcweir rData.CopyItem( 8, 4, ATTR_BORDER );
1875cdf0e10cSrcweir // Linke untere Ecke
1876cdf0e10cSrcweir GetAutoFormatAttr(nStartCol, nEndRow, 12, rData);
1877cdf0e10cSrcweir GetAutoFormatFrame(nStartCol, nEndRow, LF_ALL, 12, rData);
1878cdf0e10cSrcweir // Rechte obere Ecke
1879cdf0e10cSrcweir GetAutoFormatAttr(nEndCol, nStartRow, 3, rData);
1880cdf0e10cSrcweir GetAutoFormatFrame(nEndCol, nStartRow, LF_ALL, 3, rData);
1881cdf0e10cSrcweir // Rechte Spalte
1882cdf0e10cSrcweir GetAutoFormatAttr(nEndCol, nStartRow + 1, 7, rData);
1883cdf0e10cSrcweir GetAutoFormatAttr(nEndCol, nStartRow + 2, 11, rData);
1884cdf0e10cSrcweir GetAutoFormatFrame(nEndCol, nStartRow + 1, LF_LEFT | LF_RIGHT | LF_BOTTOM, 7, rData);
1885cdf0e10cSrcweir if (nEndRow - nStartRow >= 4)
1886cdf0e10cSrcweir GetAutoFormatFrame(nEndCol, nStartRow + 2, LF_LEFT | LF_RIGHT | LF_BOTTOM, 11, rData);
1887cdf0e10cSrcweir else
1888cdf0e10cSrcweir rData.CopyItem( 11, 7, ATTR_BORDER );
1889cdf0e10cSrcweir // Rechte untere Ecke
1890cdf0e10cSrcweir GetAutoFormatAttr(nEndCol, nEndRow, 15, rData);
1891cdf0e10cSrcweir GetAutoFormatFrame(nEndCol, nEndRow, LF_ALL, 15, rData);
1892cdf0e10cSrcweir // Ober Zeile
1893cdf0e10cSrcweir GetAutoFormatAttr(nStartCol + 1, nStartRow, 1, rData);
1894cdf0e10cSrcweir GetAutoFormatAttr(nStartCol + 2, nStartRow, 2, rData);
1895cdf0e10cSrcweir GetAutoFormatFrame(nStartCol + 1, nStartRow, LF_TOP | LF_BOTTOM | LF_RIGHT, 1, rData);
1896cdf0e10cSrcweir if (nEndCol - nStartCol >= 4)
1897cdf0e10cSrcweir GetAutoFormatFrame(nStartCol + 2, nStartRow, LF_TOP | LF_BOTTOM | LF_RIGHT, 2, rData);
1898cdf0e10cSrcweir else
1899cdf0e10cSrcweir rData.CopyItem( 2, 1, ATTR_BORDER );
1900cdf0e10cSrcweir // Untere Zeile
1901cdf0e10cSrcweir GetAutoFormatAttr(nStartCol + 1, nEndRow, 13, rData);
1902cdf0e10cSrcweir GetAutoFormatAttr(nStartCol + 2, nEndRow, 14, rData);
1903cdf0e10cSrcweir GetAutoFormatFrame(nStartCol + 1, nEndRow, LF_TOP | LF_BOTTOM | LF_RIGHT, 13, rData);
1904cdf0e10cSrcweir if (nEndCol - nStartCol >= 4)
1905cdf0e10cSrcweir GetAutoFormatFrame(nStartCol + 2, nEndRow, LF_TOP | LF_BOTTOM | LF_RIGHT, 14, rData);
1906cdf0e10cSrcweir else
1907cdf0e10cSrcweir rData.CopyItem( 14, 13, ATTR_BORDER );
1908cdf0e10cSrcweir // Body
1909cdf0e10cSrcweir GetAutoFormatAttr(nStartCol + 1, nStartRow + 1, 5, rData);
1910cdf0e10cSrcweir GetAutoFormatAttr(nStartCol + 2, nStartRow + 1, 6, rData);
1911cdf0e10cSrcweir GetAutoFormatAttr(nStartCol + 1, nStartRow + 2, 9, rData);
1912cdf0e10cSrcweir GetAutoFormatAttr(nStartCol + 2, nStartRow + 2, 10, rData);
1913cdf0e10cSrcweir GetAutoFormatFrame(nStartCol + 1, nStartRow + 1, LF_RIGHT | LF_BOTTOM, 5, rData);
1914cdf0e10cSrcweir if ((nEndCol - nStartCol >= 4) && (nEndRow - nStartRow >= 4))
1915cdf0e10cSrcweir {
1916cdf0e10cSrcweir GetAutoFormatFrame(nStartCol + 2, nStartRow + 1, LF_RIGHT | LF_BOTTOM, 6, rData);
1917cdf0e10cSrcweir GetAutoFormatFrame(nStartCol + 1, nStartRow + 2, LF_RIGHT | LF_BOTTOM, 9, rData);
1918cdf0e10cSrcweir GetAutoFormatFrame(nStartCol + 2, nStartRow + 2, LF_RIGHT | LF_BOTTOM, 10, rData);
1919cdf0e10cSrcweir }
1920cdf0e10cSrcweir else
1921cdf0e10cSrcweir {
1922cdf0e10cSrcweir rData.CopyItem( 6, 5, ATTR_BORDER );
1923cdf0e10cSrcweir rData.CopyItem( 9, 5, ATTR_BORDER );
1924cdf0e10cSrcweir rData.CopyItem( 10, 5, ATTR_BORDER );
1925cdf0e10cSrcweir }
1926cdf0e10cSrcweir }
1927cdf0e10cSrcweir }
1928cdf0e10cSrcweir }
1929cdf0e10cSrcweir
SetError(SCCOL nCol,SCROW nRow,sal_uInt16 nError)1930cdf0e10cSrcweir void ScTable::SetError( SCCOL nCol, SCROW nRow, sal_uInt16 nError)
1931cdf0e10cSrcweir {
1932cdf0e10cSrcweir if (ValidColRow(nCol, nRow))
1933cdf0e10cSrcweir aCol[nCol].SetError( nRow, nError );
1934cdf0e10cSrcweir }
1935cdf0e10cSrcweir
UpdateInsertTabAbs(SCTAB nTable)1936cdf0e10cSrcweir void ScTable::UpdateInsertTabAbs(SCTAB nTable)
1937cdf0e10cSrcweir {
1938cdf0e10cSrcweir for (SCCOL i=0; i <= MAXCOL; i++)
1939cdf0e10cSrcweir aCol[i].UpdateInsertTabAbs(nTable);
1940cdf0e10cSrcweir }
1941cdf0e10cSrcweir
1942cdf0e10cSrcweir //UNUSED2008-05 sal_uInt16 ScTable::GetErrorData( SCCOL nCol, SCROW nRow ) const
1943cdf0e10cSrcweir //UNUSED2008-05 {
1944cdf0e10cSrcweir //UNUSED2008-05 if (ValidColRow(nCol,nRow))
1945cdf0e10cSrcweir //UNUSED2008-05 return aCol[nCol].GetErrorData( nRow );
1946cdf0e10cSrcweir //UNUSED2008-05 else
1947cdf0e10cSrcweir //UNUSED2008-05 return 0;
1948cdf0e10cSrcweir //UNUSED2008-05 }
1949cdf0e10cSrcweir
GetNextSpellingCell(SCCOL & rCol,SCROW & rRow,sal_Bool bInSel,const ScMarkData & rMark) const1950cdf0e10cSrcweir sal_Bool ScTable::GetNextSpellingCell(SCCOL& rCol, SCROW& rRow, sal_Bool bInSel,
1951cdf0e10cSrcweir const ScMarkData& rMark) const
1952cdf0e10cSrcweir {
1953cdf0e10cSrcweir if (rRow == MAXROW+2) // Tabellenende
1954cdf0e10cSrcweir {
1955cdf0e10cSrcweir rRow = 0;
1956cdf0e10cSrcweir rCol = 0;
1957cdf0e10cSrcweir }
1958cdf0e10cSrcweir else
1959cdf0e10cSrcweir {
1960cdf0e10cSrcweir rRow++;
1961cdf0e10cSrcweir if (rRow == MAXROW+1)
1962cdf0e10cSrcweir {
1963cdf0e10cSrcweir rCol++;
1964cdf0e10cSrcweir rRow = 0;
1965cdf0e10cSrcweir }
1966cdf0e10cSrcweir }
1967cdf0e10cSrcweir if (rCol == MAXCOL+1)
1968cdf0e10cSrcweir return sal_True;
1969cdf0e10cSrcweir else
1970cdf0e10cSrcweir {
1971cdf0e10cSrcweir sal_Bool bStop = sal_False;
1972cdf0e10cSrcweir while (!bStop)
1973cdf0e10cSrcweir {
1974cdf0e10cSrcweir if (ValidCol(rCol))
1975cdf0e10cSrcweir {
1976cdf0e10cSrcweir bStop = aCol[rCol].GetNextSpellingCell(rRow, bInSel, rMark);
1977cdf0e10cSrcweir if (bStop)
1978cdf0e10cSrcweir return sal_True;
1979cdf0e10cSrcweir else /*if (rRow == MAXROW+1) */
1980cdf0e10cSrcweir {
1981cdf0e10cSrcweir rCol++;
1982cdf0e10cSrcweir rRow = 0;
1983cdf0e10cSrcweir }
1984cdf0e10cSrcweir }
1985cdf0e10cSrcweir else
1986cdf0e10cSrcweir return sal_True;
1987cdf0e10cSrcweir }
1988cdf0e10cSrcweir }
1989cdf0e10cSrcweir return sal_False;
1990cdf0e10cSrcweir }
1991cdf0e10cSrcweir
RemoveAutoSpellObj()1992cdf0e10cSrcweir void ScTable::RemoveAutoSpellObj()
1993cdf0e10cSrcweir {
1994cdf0e10cSrcweir for (SCCOL i=0; i <= MAXCOL; i++)
1995cdf0e10cSrcweir aCol[i].RemoveAutoSpellObj();
1996cdf0e10cSrcweir }
1997cdf0e10cSrcweir
TestTabRefAbs(SCTAB nTable)1998cdf0e10cSrcweir sal_Bool ScTable::TestTabRefAbs(SCTAB nTable)
1999cdf0e10cSrcweir {
2000cdf0e10cSrcweir sal_Bool bRet = sal_False;
2001cdf0e10cSrcweir for (SCCOL i=0; i <= MAXCOL; i++)
2002cdf0e10cSrcweir if (aCol[i].TestTabRefAbs(nTable))
2003cdf0e10cSrcweir bRet = sal_True;
2004cdf0e10cSrcweir return bRet;
2005cdf0e10cSrcweir }
2006cdf0e10cSrcweir
CompileDBFormula()2007cdf0e10cSrcweir void ScTable::CompileDBFormula()
2008cdf0e10cSrcweir {
2009cdf0e10cSrcweir for (SCCOL i=0; i<=MAXCOL; i++) aCol[i].CompileDBFormula();
2010cdf0e10cSrcweir }
2011cdf0e10cSrcweir
CompileDBFormula(sal_Bool bCreateFormulaString)2012cdf0e10cSrcweir void ScTable::CompileDBFormula( sal_Bool bCreateFormulaString )
2013cdf0e10cSrcweir {
2014cdf0e10cSrcweir for (SCCOL i=0; i<=MAXCOL; i++) aCol[i].CompileDBFormula( bCreateFormulaString );
2015cdf0e10cSrcweir }
2016cdf0e10cSrcweir
CompileNameFormula(sal_Bool bCreateFormulaString)2017cdf0e10cSrcweir void ScTable::CompileNameFormula( sal_Bool bCreateFormulaString )
2018cdf0e10cSrcweir {
2019cdf0e10cSrcweir for (SCCOL i=0; i<=MAXCOL; i++) aCol[i].CompileNameFormula( bCreateFormulaString );
2020cdf0e10cSrcweir }
2021cdf0e10cSrcweir
CompileColRowNameFormula()2022cdf0e10cSrcweir void ScTable::CompileColRowNameFormula()
2023cdf0e10cSrcweir {
2024cdf0e10cSrcweir for (SCCOL i=0; i<=MAXCOL; i++) aCol[i].CompileColRowNameFormula();
2025cdf0e10cSrcweir }
2026cdf0e10cSrcweir
GetPatternCount(SCCOL nCol)2027*8f4c7c28SSteve Yin SCSIZE ScTable::GetPatternCount( SCCOL nCol )
2028*8f4c7c28SSteve Yin {
2029*8f4c7c28SSteve Yin if( ValidCol( nCol ) )
2030*8f4c7c28SSteve Yin return aCol[nCol].GetPatternCount();
2031*8f4c7c28SSteve Yin else
2032*8f4c7c28SSteve Yin return 0;
2033*8f4c7c28SSteve Yin }
2034cdf0e10cSrcweir
GetPatternCount(SCCOL nCol,SCROW nRw1,SCROW nRw2)2035*8f4c7c28SSteve Yin SCSIZE ScTable::GetPatternCount( SCCOL nCol, SCROW nRw1, SCROW nRw2 )
2036*8f4c7c28SSteve Yin {
2037*8f4c7c28SSteve Yin if( ValidCol( nCol ) && ValidRow( nRw1 ) && ValidRow( nRw2 ) )
2038*8f4c7c28SSteve Yin return aCol[nCol].GetPatternCount( nRw1, nRw2 );
2039*8f4c7c28SSteve Yin else
2040*8f4c7c28SSteve Yin return 0;
2041*8f4c7c28SSteve Yin }
2042cdf0e10cSrcweir
ReservedPatternCount(SCCOL nCol,SCSIZE nReserved)2043*8f4c7c28SSteve Yin bool ScTable::ReservedPatternCount( SCCOL nCol, SCSIZE nReserved )
2044*8f4c7c28SSteve Yin {
2045*8f4c7c28SSteve Yin if( ValidCol( nCol ) )
2046*8f4c7c28SSteve Yin return aCol[nCol].ReservedPatternCount( nReserved );
2047*8f4c7c28SSteve Yin else
2048*8f4c7c28SSteve Yin return false;
2049*8f4c7c28SSteve Yin }
2050