xref: /AOO41X/main/sc/source/core/data/column3.cxx (revision 7a6646f1d5507b1bc5c2e48501f001d2d1aeed7d)
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
10cdf0e10cSrcweir  *
11b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
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.
19cdf0e10cSrcweir  *
20b3f79822SAndrew Rist  *************************************************************/
21b3f79822SAndrew Rist 
22b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <sfx2/objsh.hxx>
31cdf0e10cSrcweir #include <svl/zforlist.hxx>
32cdf0e10cSrcweir #include <svl/zformat.hxx>
33cdf0e10cSrcweir 
34b4df81e3SWang Lei #include "boost/tuple/tuple.hpp"
35b4df81e3SWang Lei #include <boost/function.hpp>
36b4df81e3SWang Lei #include "boost/lambda/bind.hpp"
37b4df81e3SWang Lei #include "boost/bind.hpp"
38b4df81e3SWang Lei #include "boost/lambda/lambda.hpp"
39cdf0e10cSrcweir #include "scitems.hxx"
40cdf0e10cSrcweir #include "column.hxx"
41cdf0e10cSrcweir #include "cell.hxx"
42cdf0e10cSrcweir #include "document.hxx"
43cdf0e10cSrcweir #include "attarray.hxx"
44cdf0e10cSrcweir #include "patattr.hxx"
45cdf0e10cSrcweir #include "cellform.hxx"
46cdf0e10cSrcweir #include "collect.hxx"
47cdf0e10cSrcweir #include "formula/errorcodes.hxx"
48cdf0e10cSrcweir #include "formula/token.hxx"
49cdf0e10cSrcweir #include "brdcst.hxx"
50cdf0e10cSrcweir #include "docoptio.hxx"			// GetStdPrecision fuer GetMaxNumberStringLen
51cdf0e10cSrcweir #include "subtotal.hxx"
52cdf0e10cSrcweir #include "markdata.hxx"
53cdf0e10cSrcweir #include "detfunc.hxx"			// fuer Notizen bei DeleteRange
54cdf0e10cSrcweir #include "postit.hxx"
55cdf0e10cSrcweir #include "stringutil.hxx"
56b4df81e3SWang Lei #include "dpglobal.hxx"
57b4df81e3SWang Lei #include <dptablecache.hxx>
58cdf0e10cSrcweir #include <com/sun/star/i18n/LocaleDataItem.hpp>
59cdf0e10cSrcweir using ::com::sun::star::i18n::LocaleDataItem;
60cdf0e10cSrcweir using ::rtl::OUString;
61cdf0e10cSrcweir using ::rtl::OUStringBuffer;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir // Err527 Workaround
64cdf0e10cSrcweir extern const ScFormulaCell* pLastFormulaTreeTop;	// in cellform.cxx
65cdf0e10cSrcweir using namespace formula;
66cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
67cdf0e10cSrcweir 
68cdf0e10cSrcweir sal_Bool ScColumn::bDoubleAlloc = sal_False;	// fuer Import: Groesse beim Allozieren verdoppeln
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 
Insert(SCROW nRow,ScBaseCell * pNewCell)71cdf0e10cSrcweir void ScColumn::Insert( SCROW nRow, ScBaseCell* pNewCell )
72cdf0e10cSrcweir {
73cdf0e10cSrcweir 	sal_Bool bIsAppended = sal_False;
74cdf0e10cSrcweir 	if (pItems && nCount>0)
75cdf0e10cSrcweir 	{
76cdf0e10cSrcweir 		if (pItems[nCount-1].nRow < nRow)
77cdf0e10cSrcweir 		{
78cdf0e10cSrcweir 			Append(nRow, pNewCell );
79cdf0e10cSrcweir 			bIsAppended = sal_True;
80cdf0e10cSrcweir 		}
81cdf0e10cSrcweir 	}
82cdf0e10cSrcweir 	if ( !bIsAppended )
83cdf0e10cSrcweir 	{
84cdf0e10cSrcweir 		SCSIZE	nIndex;
85cdf0e10cSrcweir 		if (Search(nRow, nIndex))
86cdf0e10cSrcweir 		{
87cdf0e10cSrcweir 			ScBaseCell* pOldCell = pItems[nIndex].pCell;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir             // move broadcaster and note to new cell, if not existing in new cell
90cdf0e10cSrcweir             if (pOldCell->HasBroadcaster() && !pNewCell->HasBroadcaster())
91cdf0e10cSrcweir                 pNewCell->TakeBroadcaster( pOldCell->ReleaseBroadcaster() );
92cdf0e10cSrcweir             if (pOldCell->HasNote() && !pNewCell->HasNote())
93cdf0e10cSrcweir 				pNewCell->TakeNote( pOldCell->ReleaseNote() );
94cdf0e10cSrcweir 
95cdf0e10cSrcweir             if ( pOldCell->GetCellType() == CELLTYPE_FORMULA && !pDocument->IsClipOrUndo() )
96cdf0e10cSrcweir 			{
97cdf0e10cSrcweir 				pOldCell->EndListeningTo( pDocument );
98cdf0e10cSrcweir 				// falls in EndListening NoteCell in gleicher Col zerstoert
99cdf0e10cSrcweir 				if ( nIndex >= nCount || pItems[nIndex].nRow != nRow )
100cdf0e10cSrcweir 					Search(nRow, nIndex);
101cdf0e10cSrcweir 			}
102cdf0e10cSrcweir 			pOldCell->Delete();
103cdf0e10cSrcweir 			pItems[nIndex].pCell = pNewCell;
104cdf0e10cSrcweir 		}
105cdf0e10cSrcweir 		else
106cdf0e10cSrcweir 		{
107cdf0e10cSrcweir 			if (nCount + 1 > nLimit)
108cdf0e10cSrcweir 			{
109cdf0e10cSrcweir 				if (bDoubleAlloc)
110cdf0e10cSrcweir 				{
111cdf0e10cSrcweir 					if (nLimit < COLUMN_DELTA)
112cdf0e10cSrcweir 						nLimit = COLUMN_DELTA;
113cdf0e10cSrcweir 					else
114cdf0e10cSrcweir 					{
115cdf0e10cSrcweir 						nLimit *= 2;
116cdf0e10cSrcweir                         if ( nLimit > sal::static_int_cast<SCSIZE>(MAXROWCOUNT) )
117cdf0e10cSrcweir 							nLimit = MAXROWCOUNT;
118cdf0e10cSrcweir 					}
119cdf0e10cSrcweir 				}
120cdf0e10cSrcweir 				else
121cdf0e10cSrcweir 					nLimit += COLUMN_DELTA;
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 				ColEntry* pNewItems = new ColEntry[nLimit];
124cdf0e10cSrcweir 				if (pItems)
125cdf0e10cSrcweir 				{
126cdf0e10cSrcweir 					memmove( pNewItems, pItems, nCount * sizeof(ColEntry) );
127cdf0e10cSrcweir 					delete[] pItems;
128cdf0e10cSrcweir 				}
129cdf0e10cSrcweir 				pItems = pNewItems;
130cdf0e10cSrcweir 			}
131cdf0e10cSrcweir 			memmove( &pItems[nIndex + 1], &pItems[nIndex], (nCount - nIndex) * sizeof(ColEntry) );
132cdf0e10cSrcweir 			pItems[nIndex].pCell = pNewCell;
133cdf0e10cSrcweir 			pItems[nIndex].nRow  = nRow;
134cdf0e10cSrcweir 			++nCount;
135cdf0e10cSrcweir 		}
136cdf0e10cSrcweir 	}
137cdf0e10cSrcweir 	// Bei aus Clipboard sind hier noch falsche (alte) Referenzen!
138cdf0e10cSrcweir 	// Werden in CopyBlockFromClip per UpdateReference umgesetzt,
139cdf0e10cSrcweir 	// danach StartListeningFromClip und BroadcastFromClip gerufen.
140cdf0e10cSrcweir 	// Wird ins Clipboard/UndoDoc gestellt, wird kein Broadcast gebraucht.
141cdf0e10cSrcweir 	// Nach Import wird CalcAfterLoad gerufen, dort Listening.
142cdf0e10cSrcweir 	if ( !(pDocument->IsClipOrUndo() || pDocument->IsInsertingFromOtherDoc()) )
143cdf0e10cSrcweir 	{
144cdf0e10cSrcweir 		pNewCell->StartListeningTo( pDocument );
145cdf0e10cSrcweir 		CellType eCellType = pNewCell->GetCellType();
146cdf0e10cSrcweir 		// Notizzelle entsteht beim Laden nur durch StartListeningCell,
147cdf0e10cSrcweir 		// ausloesende Formelzelle muss sowieso dirty sein.
148cdf0e10cSrcweir 		if ( !(pDocument->IsCalcingAfterLoad() && eCellType == CELLTYPE_NOTE) )
149cdf0e10cSrcweir 		{
150cdf0e10cSrcweir 			if ( eCellType == CELLTYPE_FORMULA )
151cdf0e10cSrcweir 				((ScFormulaCell*)pNewCell)->SetDirty();
152cdf0e10cSrcweir 			else
153cdf0e10cSrcweir 				pDocument->Broadcast( ScHint( SC_HINT_DATACHANGED,
154cdf0e10cSrcweir 					ScAddress( nCol, nRow, nTab ), pNewCell ) );
155cdf0e10cSrcweir 		}
156cdf0e10cSrcweir 	}
157cdf0e10cSrcweir }
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 
Insert(SCROW nRow,sal_uLong nNumberFormat,ScBaseCell * pCell)160cdf0e10cSrcweir void ScColumn::Insert( SCROW nRow, sal_uLong nNumberFormat, ScBaseCell* pCell )
161cdf0e10cSrcweir {
162cdf0e10cSrcweir 	Insert(nRow, pCell);
163cdf0e10cSrcweir 	short eOldType = pDocument->GetFormatTable()->
164cdf0e10cSrcweir 						GetType( (sal_uLong)
165cdf0e10cSrcweir 							((SfxUInt32Item*)GetAttr( nRow, ATTR_VALUE_FORMAT ))->
166cdf0e10cSrcweir 								GetValue() );
167cdf0e10cSrcweir 	short eNewType = pDocument->GetFormatTable()->GetType(nNumberFormat);
168cdf0e10cSrcweir 	if (!pDocument->GetFormatTable()->IsCompatible(eOldType, eNewType))
169cdf0e10cSrcweir 		ApplyAttr( nRow, SfxUInt32Item( ATTR_VALUE_FORMAT, (sal_uInt32) nNumberFormat) );
170cdf0e10cSrcweir }
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 
Append(SCROW nRow,ScBaseCell * pCell)173cdf0e10cSrcweir void ScColumn::Append( SCROW nRow, ScBaseCell* pCell )
174cdf0e10cSrcweir {
175cdf0e10cSrcweir 	if (nCount + 1 > nLimit)
176cdf0e10cSrcweir 	{
177cdf0e10cSrcweir 		if (bDoubleAlloc)
178cdf0e10cSrcweir 		{
179cdf0e10cSrcweir 			if (nLimit < COLUMN_DELTA)
180cdf0e10cSrcweir 				nLimit = COLUMN_DELTA;
181cdf0e10cSrcweir 			else
182cdf0e10cSrcweir 			{
183cdf0e10cSrcweir 				nLimit *= 2;
184cdf0e10cSrcweir                 if ( nLimit > sal::static_int_cast<SCSIZE>(MAXROWCOUNT) )
185cdf0e10cSrcweir 					nLimit = MAXROWCOUNT;
186cdf0e10cSrcweir 			}
187cdf0e10cSrcweir 		}
188cdf0e10cSrcweir 		else
189cdf0e10cSrcweir 			nLimit += COLUMN_DELTA;
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 		ColEntry* pNewItems = new ColEntry[nLimit];
192cdf0e10cSrcweir 		if (pItems)
193cdf0e10cSrcweir 		{
194cdf0e10cSrcweir 			memmove( pNewItems, pItems, nCount * sizeof(ColEntry) );
195cdf0e10cSrcweir 			delete[] pItems;
196cdf0e10cSrcweir 		}
197cdf0e10cSrcweir 		pItems = pNewItems;
198cdf0e10cSrcweir 	}
199cdf0e10cSrcweir 	pItems[nCount].pCell = pCell;
200cdf0e10cSrcweir 	pItems[nCount].nRow  = nRow;
201cdf0e10cSrcweir 	++nCount;
202cdf0e10cSrcweir }
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 
Delete(SCROW nRow)205cdf0e10cSrcweir void ScColumn::Delete( SCROW nRow )
206cdf0e10cSrcweir {
207cdf0e10cSrcweir 	SCSIZE	nIndex;
208cdf0e10cSrcweir 
209cdf0e10cSrcweir 	if (Search(nRow, nIndex))
210cdf0e10cSrcweir 	{
211cdf0e10cSrcweir 		ScBaseCell* pCell = pItems[nIndex].pCell;
212cdf0e10cSrcweir 		ScNoteCell* pNoteCell = new ScNoteCell;
213cdf0e10cSrcweir 		pItems[nIndex].pCell = pNoteCell;		// Dummy fuer Interpret
214cdf0e10cSrcweir 		pDocument->Broadcast( ScHint( SC_HINT_DYING,
215cdf0e10cSrcweir 			ScAddress( nCol, nRow, nTab ), pCell ) );
216cdf0e10cSrcweir         if ( SvtBroadcaster* pBC = pCell->ReleaseBroadcaster() )
217cdf0e10cSrcweir 		{
218cdf0e10cSrcweir             pNoteCell->TakeBroadcaster( pBC );
219cdf0e10cSrcweir 		}
220cdf0e10cSrcweir 		else
221cdf0e10cSrcweir 		{
222cdf0e10cSrcweir 			delete pNoteCell;
223cdf0e10cSrcweir 			--nCount;
224cdf0e10cSrcweir 			memmove( &pItems[nIndex], &pItems[nIndex + 1], (nCount - nIndex) * sizeof(ColEntry) );
225cdf0e10cSrcweir 			pItems[nCount].nRow = 0;
226cdf0e10cSrcweir 			pItems[nCount].pCell = NULL;
227cdf0e10cSrcweir 			//	Soll man hier den Speicher freigeben (delta)? Wird dann langsamer!
228cdf0e10cSrcweir 		}
229cdf0e10cSrcweir 		pCell->EndListeningTo( pDocument );
230cdf0e10cSrcweir 		pCell->Delete();
231cdf0e10cSrcweir 	}
232cdf0e10cSrcweir }
233cdf0e10cSrcweir 
234cdf0e10cSrcweir 
DeleteAtIndex(SCSIZE nIndex)235cdf0e10cSrcweir void ScColumn::DeleteAtIndex( SCSIZE nIndex )
236cdf0e10cSrcweir {
237cdf0e10cSrcweir 	ScBaseCell* pCell = pItems[nIndex].pCell;
238cdf0e10cSrcweir 	ScNoteCell* pNoteCell = new ScNoteCell;
239cdf0e10cSrcweir 	pItems[nIndex].pCell = pNoteCell;		// Dummy fuer Interpret
240cdf0e10cSrcweir 	pDocument->Broadcast( ScHint( SC_HINT_DYING,
241cdf0e10cSrcweir 		ScAddress( nCol, pItems[nIndex].nRow, nTab ), pCell ) );
242cdf0e10cSrcweir 	delete pNoteCell;
243cdf0e10cSrcweir 	--nCount;
244cdf0e10cSrcweir 	memmove( &pItems[nIndex], &pItems[nIndex + 1], (nCount - nIndex) * sizeof(ColEntry) );
245cdf0e10cSrcweir 	pItems[nCount].nRow = 0;
246cdf0e10cSrcweir 	pItems[nCount].pCell = NULL;
247cdf0e10cSrcweir 	pCell->EndListeningTo( pDocument );
248cdf0e10cSrcweir 	pCell->Delete();
249cdf0e10cSrcweir }
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 
FreeAll()252cdf0e10cSrcweir void ScColumn::FreeAll()
253cdf0e10cSrcweir {
254cdf0e10cSrcweir 	if (pItems)
255cdf0e10cSrcweir 	{
256cdf0e10cSrcweir 		for (SCSIZE i = 0; i < nCount; i++)
257cdf0e10cSrcweir 			pItems[i].pCell->Delete();
258cdf0e10cSrcweir 		delete[] pItems;
259cdf0e10cSrcweir 		pItems = NULL;
260cdf0e10cSrcweir 	}
261cdf0e10cSrcweir 	nCount = 0;
262cdf0e10cSrcweir 	nLimit = 0;
263cdf0e10cSrcweir }
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 
DeleteRow(SCROW nStartRow,SCSIZE nSize)266cdf0e10cSrcweir void ScColumn::DeleteRow( SCROW nStartRow, SCSIZE nSize )
267cdf0e10cSrcweir {
268cdf0e10cSrcweir 	pAttrArray->DeleteRow( nStartRow, nSize );
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 	if ( !pItems || !nCount )
271cdf0e10cSrcweir 		return ;
272cdf0e10cSrcweir 
273cdf0e10cSrcweir 	SCSIZE nFirstIndex;
274cdf0e10cSrcweir 	Search( nStartRow, nFirstIndex );
275cdf0e10cSrcweir 	if ( nFirstIndex >= nCount )
276cdf0e10cSrcweir 		return ;
277cdf0e10cSrcweir 
278cdf0e10cSrcweir 	sal_Bool bOldAutoCalc = pDocument->GetAutoCalc();
279cdf0e10cSrcweir 	pDocument->SetAutoCalc( sal_False );	// Mehrfachberechnungen vermeiden
280cdf0e10cSrcweir 
281cdf0e10cSrcweir 	sal_Bool bFound=sal_False;
282cdf0e10cSrcweir 	SCROW nEndRow = nStartRow + nSize - 1;
283cdf0e10cSrcweir     SCSIZE nStartIndex = 0;
284cdf0e10cSrcweir     SCSIZE nEndIndex = 0;
285cdf0e10cSrcweir 	SCSIZE i;
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 	for ( i = nFirstIndex; i < nCount && pItems[i].nRow <= nEndRow; i++ )
288cdf0e10cSrcweir 	{
289cdf0e10cSrcweir 		if (!bFound)
290cdf0e10cSrcweir 		{
291cdf0e10cSrcweir 			nStartIndex = i;
292cdf0e10cSrcweir 			bFound = sal_True;
293cdf0e10cSrcweir 		}
294cdf0e10cSrcweir 		nEndIndex = i;
295cdf0e10cSrcweir 
296cdf0e10cSrcweir 		ScBaseCell* pCell = pItems[i].pCell;
297cdf0e10cSrcweir 		SvtBroadcaster* pBC = pCell->GetBroadcaster();
298cdf0e10cSrcweir 		if (pBC)
299cdf0e10cSrcweir 		{
300cdf0e10cSrcweir // gibt jetzt invalid reference, kein Aufruecken der direkten Referenzen
301cdf0e10cSrcweir //			MoveListeners( *pBC, nRow+nSize );
302cdf0e10cSrcweir             pCell->DeleteBroadcaster();
303cdf0e10cSrcweir 			//	in DeleteRange werden leere Broadcaster geloescht
304cdf0e10cSrcweir 		}
305cdf0e10cSrcweir 	}
306cdf0e10cSrcweir 	if (bFound)
307cdf0e10cSrcweir 	{
308cdf0e10cSrcweir 		DeleteRange( nStartIndex, nEndIndex, IDF_CONTENTS );
309cdf0e10cSrcweir 		Search( nStartRow, i );
310cdf0e10cSrcweir 		if ( i >= nCount )
311cdf0e10cSrcweir 		{
312cdf0e10cSrcweir 			pDocument->SetAutoCalc( bOldAutoCalc );
313cdf0e10cSrcweir 			return ;
314cdf0e10cSrcweir 		}
315cdf0e10cSrcweir 	}
316cdf0e10cSrcweir 	else
317cdf0e10cSrcweir 		i = nFirstIndex;
318cdf0e10cSrcweir 
319cdf0e10cSrcweir 	ScAddress aAdr( nCol, 0, nTab );
320cdf0e10cSrcweir     ScHint aHint( SC_HINT_DATACHANGED, aAdr, NULL );    // only areas (ScBaseCell* == NULL)
321cdf0e10cSrcweir     ScAddress& rAddress = aHint.GetAddress();
322cdf0e10cSrcweir     // for sparse occupation use single broadcasts, not ranges
323cdf0e10cSrcweir     sal_Bool bSingleBroadcasts = (((pItems[nCount-1].nRow - pItems[i].nRow) /
324cdf0e10cSrcweir                 (nCount - i)) > 1);
325cdf0e10cSrcweir     if ( bSingleBroadcasts )
326cdf0e10cSrcweir     {
327cdf0e10cSrcweir         SCROW nLastBroadcast = MAXROW+1;
328cdf0e10cSrcweir         for ( ; i < nCount; i++ )
329cdf0e10cSrcweir         {
330cdf0e10cSrcweir             SCROW nOldRow = pItems[i].nRow;
331cdf0e10cSrcweir             // #43940# Aenderung Quelle broadcasten
332cdf0e10cSrcweir             rAddress.SetRow( nOldRow );
333cdf0e10cSrcweir             pDocument->AreaBroadcast( aHint );
334cdf0e10cSrcweir             SCROW nNewRow = (pItems[i].nRow -= nSize);
335cdf0e10cSrcweir             // #43940# Aenderung Ziel broadcasten
336cdf0e10cSrcweir             if ( nLastBroadcast != nNewRow )
337cdf0e10cSrcweir             {   // direkt aufeinanderfolgende nicht doppelt broadcasten
338cdf0e10cSrcweir                 rAddress.SetRow( nNewRow );
339cdf0e10cSrcweir                 pDocument->AreaBroadcast( aHint );
340cdf0e10cSrcweir             }
341cdf0e10cSrcweir             nLastBroadcast = nOldRow;
342cdf0e10cSrcweir             ScBaseCell* pCell = pItems[i].pCell;
343cdf0e10cSrcweir             if ( pCell->GetCellType() == CELLTYPE_FORMULA )
344cdf0e10cSrcweir                 ((ScFormulaCell*)pCell)->aPos.SetRow( nNewRow );
345cdf0e10cSrcweir         }
346cdf0e10cSrcweir     }
347cdf0e10cSrcweir     else
348cdf0e10cSrcweir     {
349cdf0e10cSrcweir         rAddress.SetRow( pItems[i].nRow );
350cdf0e10cSrcweir         ScRange aRange( rAddress );
351cdf0e10cSrcweir         aRange.aEnd.SetRow( pItems[nCount-1].nRow );
352cdf0e10cSrcweir         for ( ; i < nCount; i++ )
353cdf0e10cSrcweir         {
354cdf0e10cSrcweir             SCROW nNewRow = (pItems[i].nRow -= nSize);
355cdf0e10cSrcweir             ScBaseCell* pCell = pItems[i].pCell;
356cdf0e10cSrcweir             if ( pCell->GetCellType() == CELLTYPE_FORMULA )
357cdf0e10cSrcweir                 ((ScFormulaCell*)pCell)->aPos.SetRow( nNewRow );
358cdf0e10cSrcweir         }
359cdf0e10cSrcweir         pDocument->AreaBroadcastInRange( aRange, aHint );
360cdf0e10cSrcweir     }
361cdf0e10cSrcweir 
362cdf0e10cSrcweir 	pDocument->SetAutoCalc( bOldAutoCalc );
363cdf0e10cSrcweir }
364cdf0e10cSrcweir 
365cdf0e10cSrcweir 
DeleteRange(SCSIZE nStartIndex,SCSIZE nEndIndex,sal_uInt16 nDelFlag)366cdf0e10cSrcweir void ScColumn::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDelFlag )
367cdf0e10cSrcweir {
368cdf0e10cSrcweir     /*  If caller specifies to not remove the note caption objects, all cells
369cdf0e10cSrcweir         have to forget the pointers to them. This is used e.g. while undoing a
370cdf0e10cSrcweir         "paste cells" operation, which removes the caption objects later in
371cdf0e10cSrcweir         drawing undo. */
372cdf0e10cSrcweir     bool bDeleteNote = (nDelFlag & IDF_NOTE) != 0;
373cdf0e10cSrcweir     bool bNoCaptions = (nDelFlag & IDF_NOCAPTIONS) != 0;
374cdf0e10cSrcweir     if (bDeleteNote && bNoCaptions)
375cdf0e10cSrcweir 		for ( SCSIZE nIdx = nStartIndex; nIdx <= nEndIndex; ++nIdx )
376cdf0e10cSrcweir 			if ( ScPostIt* pNote = pItems[ nIdx ].pCell->GetNote() )
377cdf0e10cSrcweir 				pNote->ForgetCaption();
378cdf0e10cSrcweir 
379cdf0e10cSrcweir     // special simple mode if all contents are deleted and cells do not contain broadcasters
380cdf0e10cSrcweir 	bool bSimple = ((nDelFlag & IDF_CONTENTS) == IDF_CONTENTS);
381cdf0e10cSrcweir 	if (bSimple)
382cdf0e10cSrcweir 		for ( SCSIZE nIdx = nStartIndex; bSimple && (nIdx <= nEndIndex); ++nIdx )
383cdf0e10cSrcweir 			if (pItems[ nIdx ].pCell->GetBroadcaster())
384cdf0e10cSrcweir 				bSimple = false;
385cdf0e10cSrcweir 
386cdf0e10cSrcweir     ScHint aHint( SC_HINT_DYING, ScAddress( nCol, 0, nTab ), 0 );
387cdf0e10cSrcweir 
388cdf0e10cSrcweir     // cache all formula cells, they will be deleted at end of this function
389cdf0e10cSrcweir 	typedef ::std::vector< ScFormulaCell* > FormulaCellVector;
390cdf0e10cSrcweir 	FormulaCellVector aDelCells;
391cdf0e10cSrcweir     aDelCells.reserve( nEndIndex - nStartIndex + 1 );
392cdf0e10cSrcweir 
393cdf0e10cSrcweir     // simple deletion of the cell objects
394cdf0e10cSrcweir 	if (bSimple)
395cdf0e10cSrcweir 	{
396cdf0e10cSrcweir         // pNoteCell: dummy replacement for old cells, to prevent that interpreter uses old cell
397cdf0e10cSrcweir 		ScNoteCell* pNoteCell = new ScNoteCell;
398cdf0e10cSrcweir 		for ( SCSIZE nIdx = nStartIndex; nIdx <= nEndIndex; ++nIdx )
399cdf0e10cSrcweir 		{
400cdf0e10cSrcweir 			ScBaseCell* pOldCell = pItems[ nIdx ].pCell;
401cdf0e10cSrcweir 			if (pOldCell->GetCellType() == CELLTYPE_FORMULA)
402cdf0e10cSrcweir             {
403cdf0e10cSrcweir                 // cache formula cell, will be deleted below
404cdf0e10cSrcweir 				aDelCells.push_back( static_cast< ScFormulaCell* >( pOldCell ) );
405cdf0e10cSrcweir             }
406cdf0e10cSrcweir 			else
407cdf0e10cSrcweir 			{
408cdf0e10cSrcweir 				// interpret in broadcast must not use the old cell
409cdf0e10cSrcweir 				pItems[ nIdx ].pCell = pNoteCell;
410cdf0e10cSrcweir                 aHint.GetAddress().SetRow( pItems[ nIdx ].nRow );
411cdf0e10cSrcweir                 aHint.SetCell( pOldCell );
412cdf0e10cSrcweir 				pDocument->Broadcast( aHint );
413cdf0e10cSrcweir 				pOldCell->Delete();
414cdf0e10cSrcweir 			}
415cdf0e10cSrcweir 		}
416cdf0e10cSrcweir 		delete pNoteCell;
417cdf0e10cSrcweir 		memmove( &pItems[nStartIndex], &pItems[nEndIndex + 1], (nCount - nEndIndex - 1) * sizeof(ColEntry) );
418cdf0e10cSrcweir 		nCount -= nEndIndex-nStartIndex+1;
419cdf0e10cSrcweir 	}
420cdf0e10cSrcweir 
421cdf0e10cSrcweir     // else: delete some contents of the cells
422cdf0e10cSrcweir 	else
423cdf0e10cSrcweir 	{
424cdf0e10cSrcweir 		SCSIZE j = nStartIndex;
425cdf0e10cSrcweir         for ( SCSIZE nIdx = nStartIndex; nIdx <= nEndIndex; ++nIdx )
426cdf0e10cSrcweir 		{
427cdf0e10cSrcweir             // decide whether to delete the cell object according to passed flags
428cdf0e10cSrcweir 			bool bDelete = false;
429cdf0e10cSrcweir 			ScBaseCell* pOldCell = pItems[j].pCell;
430cdf0e10cSrcweir 			CellType eCellType = pOldCell->GetCellType();
431cdf0e10cSrcweir 			switch ( eCellType )
432cdf0e10cSrcweir 			{
433cdf0e10cSrcweir 				case CELLTYPE_VALUE:
434cdf0e10cSrcweir                 {
435cdf0e10cSrcweir                     sal_uInt16 nValFlags = nDelFlag & (IDF_DATETIME|IDF_VALUE);
436cdf0e10cSrcweir                     // delete values and dates?
437cdf0e10cSrcweir 					bDelete = nValFlags == (IDF_DATETIME|IDF_VALUE);
438cdf0e10cSrcweir                     // if not, decide according to cell number format
439cdf0e10cSrcweir 					if( !bDelete && (nValFlags != 0) )
440cdf0e10cSrcweir 					{
441cdf0e10cSrcweir 						sal_uLong nIndex = (sal_uLong)((SfxUInt32Item*)GetAttr( pItems[j].nRow, ATTR_VALUE_FORMAT ))->GetValue();
442cdf0e10cSrcweir 						short nType = pDocument->GetFormatTable()->GetType(nIndex);
443cdf0e10cSrcweir 						bool bIsDate = (nType == NUMBERFORMAT_DATE) || (nType == NUMBERFORMAT_TIME) || (nType == NUMBERFORMAT_DATETIME);
444cdf0e10cSrcweir                         bDelete = nValFlags == (bIsDate ? IDF_DATETIME : IDF_VALUE);
445cdf0e10cSrcweir 					}
446cdf0e10cSrcweir                 }
447cdf0e10cSrcweir                 break;
448cdf0e10cSrcweir 
449cdf0e10cSrcweir 				case CELLTYPE_STRING:
450cdf0e10cSrcweir 				case CELLTYPE_EDIT:
451cdf0e10cSrcweir                     bDelete = (nDelFlag & IDF_STRING) != 0;
452cdf0e10cSrcweir                 break;
453cdf0e10cSrcweir 
454cdf0e10cSrcweir 				case CELLTYPE_FORMULA:
455cdf0e10cSrcweir                     bDelete = (nDelFlag & IDF_FORMULA) != 0;
456cdf0e10cSrcweir                 break;
457cdf0e10cSrcweir 
458cdf0e10cSrcweir 				case CELLTYPE_NOTE:
459cdf0e10cSrcweir                     // do note delete note cell with broadcaster
460cdf0e10cSrcweir 					bDelete = bDeleteNote && !pOldCell->GetBroadcaster();
461cdf0e10cSrcweir                 break;
462cdf0e10cSrcweir 
463cdf0e10cSrcweir                 default:;   // added to avoid warnings
464cdf0e10cSrcweir 			}
465cdf0e10cSrcweir 
466cdf0e10cSrcweir 			if (bDelete)
467cdf0e10cSrcweir 			{
468cdf0e10cSrcweir                 // try to create a replacement note cell, if note or broadcaster exists
469cdf0e10cSrcweir 				ScNoteCell* pNoteCell = 0;
470cdf0e10cSrcweir 				if (eCellType != CELLTYPE_NOTE)
471cdf0e10cSrcweir 				{
472cdf0e10cSrcweir                     // do not rescue note if it has to be deleted according to passed flags
473cdf0e10cSrcweir 					ScPostIt* pNote = bDeleteNote ? 0 : pOldCell->ReleaseNote();
474cdf0e10cSrcweir                     // #i99844# do not release broadcaster from old cell, it still has to notify deleted content
475cdf0e10cSrcweir                     SvtBroadcaster* pBC = pOldCell->GetBroadcaster();
476cdf0e10cSrcweir                     if( pNote || pBC )
477cdf0e10cSrcweir                         pNoteCell = new ScNoteCell( pNote, pBC );
478cdf0e10cSrcweir 				}
479cdf0e10cSrcweir 
480cdf0e10cSrcweir                 // remove cell entry in cell item list
481cdf0e10cSrcweir 				SCROW nOldRow = pItems[j].nRow;
482cdf0e10cSrcweir 				if (pNoteCell)
483cdf0e10cSrcweir 				{
484cdf0e10cSrcweir                     // replace old cell with the replacement note cell
485cdf0e10cSrcweir 					pItems[j].pCell = pNoteCell;
486cdf0e10cSrcweir 					++j;
487cdf0e10cSrcweir 				}
488cdf0e10cSrcweir 				else
489cdf0e10cSrcweir 				{
490cdf0e10cSrcweir                     // remove the old cell from the cell item list
491cdf0e10cSrcweir 					--nCount;
492cdf0e10cSrcweir 					memmove( &pItems[j], &pItems[j + 1], (nCount - j) * sizeof(ColEntry) );
493cdf0e10cSrcweir 					pItems[nCount].nRow = 0;
494cdf0e10cSrcweir 					pItems[nCount].pCell = 0;
495cdf0e10cSrcweir 				}
496cdf0e10cSrcweir 
497cdf0e10cSrcweir                 // cache formula cells (will be deleted later), delete cell of other type
498cdf0e10cSrcweir 				if (eCellType == CELLTYPE_FORMULA)
499cdf0e10cSrcweir 				{
500cdf0e10cSrcweir 					aDelCells.push_back( static_cast< ScFormulaCell* >( pOldCell ) );
501cdf0e10cSrcweir 				}
502cdf0e10cSrcweir 				else
503cdf0e10cSrcweir 				{
504cdf0e10cSrcweir                     aHint.GetAddress().SetRow( nOldRow );
505cdf0e10cSrcweir                     aHint.SetCell( pOldCell );
506cdf0e10cSrcweir 					pDocument->Broadcast( aHint );
507cdf0e10cSrcweir                     // #i99844# after broadcasting, old cell has to forget the broadcaster (owned by pNoteCell)
508cdf0e10cSrcweir                     pOldCell->ReleaseBroadcaster();
509cdf0e10cSrcweir 					pOldCell->Delete();
510cdf0e10cSrcweir 				}
511cdf0e10cSrcweir 			}
512cdf0e10cSrcweir 			else
513cdf0e10cSrcweir 			{
514cdf0e10cSrcweir                 // delete cell note
515cdf0e10cSrcweir 				if (bDeleteNote)
516cdf0e10cSrcweir 					pItems[j].pCell->DeleteNote();
517cdf0e10cSrcweir                 // cell not deleted, move index to next cell
518cdf0e10cSrcweir 				++j;
519cdf0e10cSrcweir 			}
520cdf0e10cSrcweir 		}
521cdf0e10cSrcweir 	}
522cdf0e10cSrcweir 
523cdf0e10cSrcweir     // *** delete all formula cells ***
524cdf0e10cSrcweir 
525cdf0e10cSrcweir 	// first, all cells stop listening, may save unneeded recalcualtions
526cdf0e10cSrcweir 	for ( FormulaCellVector::iterator aIt = aDelCells.begin(), aEnd = aDelCells.end(); aIt != aEnd; ++aIt )
527cdf0e10cSrcweir 		(*aIt)->EndListeningTo( pDocument );
528cdf0e10cSrcweir 
529cdf0e10cSrcweir     // #i101869# if the note cell with the broadcaster was deleted in EndListening,
530cdf0e10cSrcweir     // forget the pointer to the broadcaster
531cdf0e10cSrcweir     for ( FormulaCellVector::iterator aIt = aDelCells.begin(), aEnd = aDelCells.end(); aIt != aEnd; ++aIt )
532cdf0e10cSrcweir     {
533cdf0e10cSrcweir         SCSIZE nIndex;
534cdf0e10cSrcweir         if ( !Search( (*aIt)->aPos.Row(), nIndex ) )
535cdf0e10cSrcweir             (*aIt)->ReleaseBroadcaster();
536cdf0e10cSrcweir     }
537cdf0e10cSrcweir 
538cdf0e10cSrcweir     // broadcast SC_HINT_DYING for all cells and delete them
539cdf0e10cSrcweir 	for ( FormulaCellVector::iterator aIt = aDelCells.begin(), aEnd = aDelCells.end(); aIt != aEnd; ++aIt )
540cdf0e10cSrcweir 	{
541cdf0e10cSrcweir         aHint.SetAddress( (*aIt)->aPos );
542cdf0e10cSrcweir         aHint.SetCell( *aIt );
543cdf0e10cSrcweir 		pDocument->Broadcast( aHint );
544cdf0e10cSrcweir         // #i99844# after broadcasting, old cell has to forget the broadcaster (owned by replacement note cell)
545cdf0e10cSrcweir         (*aIt)->ReleaseBroadcaster();
546cdf0e10cSrcweir 		(*aIt)->Delete();
547cdf0e10cSrcweir 	}
548cdf0e10cSrcweir }
549cdf0e10cSrcweir 
550cdf0e10cSrcweir 
DeleteArea(SCROW nStartRow,SCROW nEndRow,sal_uInt16 nDelFlag)551cdf0e10cSrcweir void ScColumn::DeleteArea(SCROW nStartRow, SCROW nEndRow, sal_uInt16 nDelFlag)
552cdf0e10cSrcweir {
553cdf0e10cSrcweir 	//	FreeAll darf hier nicht gerufen werden wegen Broadcastern
554cdf0e10cSrcweir 
555cdf0e10cSrcweir 	//	Attribute erst am Ende, damit vorher noch zwischen Zahlen und Datum
556cdf0e10cSrcweir 	//	unterschieden werden kann (#47901#)
557cdf0e10cSrcweir 
558cdf0e10cSrcweir     sal_uInt16 nContMask = IDF_CONTENTS;
559cdf0e10cSrcweir     //  IDF_NOCAPTIONS needs to be passed too, if IDF_NOTE is set
560cdf0e10cSrcweir     if( nDelFlag & IDF_NOTE )
561cdf0e10cSrcweir         nContMask |= IDF_NOCAPTIONS;
562cdf0e10cSrcweir     sal_uInt16 nContFlag = nDelFlag & nContMask;
563cdf0e10cSrcweir 
564cdf0e10cSrcweir 	if (pItems && nCount>0 && nContFlag)
565cdf0e10cSrcweir 	{
566cdf0e10cSrcweir 		if (nStartRow==0 && nEndRow==MAXROW)
567cdf0e10cSrcweir             DeleteRange( 0, nCount-1, nContFlag );
568cdf0e10cSrcweir 		else
569cdf0e10cSrcweir 		{
570cdf0e10cSrcweir 			sal_Bool bFound=sal_False;
571cdf0e10cSrcweir             SCSIZE nStartIndex = 0;
572cdf0e10cSrcweir             SCSIZE nEndIndex = 0;
573cdf0e10cSrcweir 			for (SCSIZE i = 0; i < nCount; i++)
574cdf0e10cSrcweir 				if ((pItems[i].nRow >= nStartRow) && (pItems[i].nRow <= nEndRow))
575cdf0e10cSrcweir 				{
576cdf0e10cSrcweir 					if (!bFound)
577cdf0e10cSrcweir 					{
578cdf0e10cSrcweir 						nStartIndex = i;
579cdf0e10cSrcweir 						bFound = sal_True;
580cdf0e10cSrcweir 					}
581cdf0e10cSrcweir 					nEndIndex = i;
582cdf0e10cSrcweir 				}
583cdf0e10cSrcweir 			if (bFound)
584cdf0e10cSrcweir                 DeleteRange( nStartIndex, nEndIndex, nContFlag );
585cdf0e10cSrcweir 		}
586cdf0e10cSrcweir 	}
587cdf0e10cSrcweir 
588cdf0e10cSrcweir 	if ( nDelFlag & IDF_EDITATTR )
589cdf0e10cSrcweir 	{
590cdf0e10cSrcweir 		DBG_ASSERT( nContFlag == 0, "DeleteArea: falsche Flags" );
591cdf0e10cSrcweir 		RemoveEditAttribs( nStartRow, nEndRow );
592cdf0e10cSrcweir 	}
593cdf0e10cSrcweir 
594cdf0e10cSrcweir 	//	Attribute erst hier
595cdf0e10cSrcweir 	if ((nDelFlag & IDF_ATTRIB) == IDF_ATTRIB) pAttrArray->DeleteArea( nStartRow, nEndRow );
596cdf0e10cSrcweir 	else if ((nDelFlag & IDF_ATTRIB) != 0) pAttrArray->DeleteHardAttr( nStartRow, nEndRow );
597cdf0e10cSrcweir }
598cdf0e10cSrcweir 
599cdf0e10cSrcweir 
CreateRefCell(ScDocument * pDestDoc,const ScAddress & rDestPos,SCSIZE nIndex,sal_uInt16 nFlags) const600cdf0e10cSrcweir ScFormulaCell* ScColumn::CreateRefCell( ScDocument* pDestDoc, const ScAddress& rDestPos,
601cdf0e10cSrcweir 											SCSIZE nIndex, sal_uInt16 nFlags ) const
602cdf0e10cSrcweir {
603cdf0e10cSrcweir 	sal_uInt16 nContFlags = nFlags & IDF_CONTENTS;
604cdf0e10cSrcweir 	if (!nContFlags)
605cdf0e10cSrcweir 		return NULL;
606cdf0e10cSrcweir 
607cdf0e10cSrcweir 	//	Testen, ob Zelle kopiert werden soll
608cdf0e10cSrcweir 	//	auch bei IDF_CONTENTS komplett, wegen Notes / Broadcastern
609cdf0e10cSrcweir 
610cdf0e10cSrcweir 	sal_Bool bMatch = sal_False;
611cdf0e10cSrcweir 	ScBaseCell* pCell = pItems[nIndex].pCell;
612cdf0e10cSrcweir 	CellType eCellType = pCell->GetCellType();
613cdf0e10cSrcweir 	switch ( eCellType )
614cdf0e10cSrcweir 	{
615cdf0e10cSrcweir 		case CELLTYPE_VALUE:
616cdf0e10cSrcweir 			{
617cdf0e10cSrcweir 				sal_uInt16 nValFlags = nFlags & (IDF_DATETIME|IDF_VALUE);
618cdf0e10cSrcweir 
619cdf0e10cSrcweir 				if ( nValFlags == (IDF_DATETIME|IDF_VALUE) )
620cdf0e10cSrcweir 					bMatch = sal_True;
621cdf0e10cSrcweir 				else if ( nValFlags )
622cdf0e10cSrcweir 				{
623cdf0e10cSrcweir 					sal_uLong nNumIndex = (sal_uLong)((SfxUInt32Item*)GetAttr(
624cdf0e10cSrcweir 									pItems[nIndex].nRow, ATTR_VALUE_FORMAT ))->GetValue();
625cdf0e10cSrcweir 					short nTyp = pDocument->GetFormatTable()->GetType(nNumIndex);
626cdf0e10cSrcweir 					if ((nTyp == NUMBERFORMAT_DATE) || (nTyp == NUMBERFORMAT_TIME) || (nTyp == NUMBERFORMAT_DATETIME))
627cdf0e10cSrcweir 						bMatch = ((nFlags & IDF_DATETIME) != 0);
628cdf0e10cSrcweir 					else
629cdf0e10cSrcweir 						bMatch = ((nFlags & IDF_VALUE) != 0);
630cdf0e10cSrcweir 				}
631cdf0e10cSrcweir 			}
632cdf0e10cSrcweir 			break;
633cdf0e10cSrcweir 		case CELLTYPE_STRING:
634cdf0e10cSrcweir 		case CELLTYPE_EDIT:		bMatch = ((nFlags & IDF_STRING) != 0); break;
635cdf0e10cSrcweir 		case CELLTYPE_FORMULA:	bMatch = ((nFlags & IDF_FORMULA) != 0); break;
636cdf0e10cSrcweir         default:
637cdf0e10cSrcweir         {
638cdf0e10cSrcweir             // added to avoid warnings
639cdf0e10cSrcweir         }
640cdf0e10cSrcweir 	}
641cdf0e10cSrcweir 	if (!bMatch)
642cdf0e10cSrcweir 		return NULL;
643cdf0e10cSrcweir 
644cdf0e10cSrcweir 
645cdf0e10cSrcweir 	//	Referenz einsetzen
646cdf0e10cSrcweir 	ScSingleRefData aRef;
647cdf0e10cSrcweir 	aRef.nCol = nCol;
648cdf0e10cSrcweir 	aRef.nRow = pItems[nIndex].nRow;
649cdf0e10cSrcweir 	aRef.nTab = nTab;
650cdf0e10cSrcweir 	aRef.InitFlags();							// -> alles absolut
651cdf0e10cSrcweir 	aRef.SetFlag3D(sal_True);
652cdf0e10cSrcweir 
653cdf0e10cSrcweir 	//!	3D(sal_False) und TabRel(sal_True), wenn die endgueltige Position auf der selben Tabelle ist?
654cdf0e10cSrcweir 	//!	(bei TransposeClip ist die Zielposition noch nicht bekannt)
655cdf0e10cSrcweir 
656cdf0e10cSrcweir 	aRef.CalcRelFromAbs( rDestPos );
657cdf0e10cSrcweir 
658cdf0e10cSrcweir 	ScTokenArray aArr;
659cdf0e10cSrcweir 	aArr.AddSingleReference( aRef );
660cdf0e10cSrcweir 
661cdf0e10cSrcweir 	return new ScFormulaCell( pDestDoc, rDestPos, &aArr );
662cdf0e10cSrcweir }
663cdf0e10cSrcweir 
664cdf0e10cSrcweir 
665cdf0e10cSrcweir //	rColumn = Quelle
666cdf0e10cSrcweir //	nRow1, nRow2 = Zielposition
667cdf0e10cSrcweir 
CopyFromClip(SCROW nRow1,SCROW nRow2,long nDy,sal_uInt16 nInsFlag,sal_Bool bAsLink,sal_Bool bSkipAttrForEmpty,ScColumn & rColumn)668cdf0e10cSrcweir void ScColumn::CopyFromClip(SCROW nRow1, SCROW nRow2, long nDy,
669cdf0e10cSrcweir 								sal_uInt16 nInsFlag, sal_Bool bAsLink, sal_Bool bSkipAttrForEmpty,
670cdf0e10cSrcweir 								ScColumn& rColumn)
671cdf0e10cSrcweir {
672cdf0e10cSrcweir 	if ((nInsFlag & IDF_ATTRIB) != 0)
673cdf0e10cSrcweir 	{
674cdf0e10cSrcweir 		if ( bSkipAttrForEmpty )
675cdf0e10cSrcweir 		{
676cdf0e10cSrcweir 			//	copy only attributes for non-empty cells
677cdf0e10cSrcweir 			//	(notes are not counted as non-empty here, to match the content behavior)
678cdf0e10cSrcweir 
679cdf0e10cSrcweir 			SCSIZE nStartIndex;
680cdf0e10cSrcweir 			rColumn.Search( nRow1-nDy, nStartIndex );
681cdf0e10cSrcweir 			while ( nStartIndex < rColumn.nCount && rColumn.pItems[nStartIndex].nRow <= nRow2-nDy )
682cdf0e10cSrcweir 			{
683cdf0e10cSrcweir 				SCSIZE nEndIndex = nStartIndex;
684cdf0e10cSrcweir 				if ( rColumn.pItems[nStartIndex].pCell->GetCellType() != CELLTYPE_NOTE )
685cdf0e10cSrcweir 				{
686cdf0e10cSrcweir 					SCROW nStartRow = rColumn.pItems[nStartIndex].nRow;
687cdf0e10cSrcweir 					SCROW nEndRow = nStartRow;
688cdf0e10cSrcweir 
689cdf0e10cSrcweir 					//	find consecutive non-empty cells
690cdf0e10cSrcweir 
691cdf0e10cSrcweir 					while ( nEndRow < nRow2-nDy &&
692cdf0e10cSrcweir 							nEndIndex+1 < rColumn.nCount &&
693cdf0e10cSrcweir 							rColumn.pItems[nEndIndex+1].nRow == nEndRow+1 &&
694cdf0e10cSrcweir 							rColumn.pItems[nEndIndex+1].pCell->GetCellType() != CELLTYPE_NOTE )
695cdf0e10cSrcweir 					{
696cdf0e10cSrcweir 						++nEndIndex;
697cdf0e10cSrcweir 						++nEndRow;
698cdf0e10cSrcweir 					}
699cdf0e10cSrcweir 
700cdf0e10cSrcweir 					rColumn.pAttrArray->CopyAreaSafe( nStartRow+nDy, nEndRow+nDy, nDy, *pAttrArray );
701cdf0e10cSrcweir 				}
702cdf0e10cSrcweir 				nStartIndex = nEndIndex + 1;
703cdf0e10cSrcweir 			}
704cdf0e10cSrcweir 		}
705cdf0e10cSrcweir 		else
706cdf0e10cSrcweir 			rColumn.pAttrArray->CopyAreaSafe( nRow1, nRow2, nDy, *pAttrArray );
707cdf0e10cSrcweir 	}
708cdf0e10cSrcweir     if ((nInsFlag & IDF_CONTENTS) == 0)
709cdf0e10cSrcweir 		return;
710cdf0e10cSrcweir 
711cdf0e10cSrcweir 	if ( bAsLink && nInsFlag == IDF_ALL )
712cdf0e10cSrcweir 	{
713cdf0e10cSrcweir 		//	bei "alles" werden auch leere Zellen referenziert
714cdf0e10cSrcweir 		//!	IDF_ALL muss immer mehr Flags enthalten, als bei "Inhalte Einfuegen"
715cdf0e10cSrcweir 		//!	einzeln ausgewaehlt werden koennen!
716cdf0e10cSrcweir 
717cdf0e10cSrcweir 		Resize( nCount + static_cast<SCSIZE>(nRow2-nRow1+1) );
718cdf0e10cSrcweir 
719cdf0e10cSrcweir 		ScAddress aDestPos( nCol, 0, nTab );		// Row wird angepasst
720cdf0e10cSrcweir 
721cdf0e10cSrcweir 		//	Referenz erzeugen (Quell-Position)
722cdf0e10cSrcweir 		ScSingleRefData aRef;
723cdf0e10cSrcweir 		aRef.nCol = rColumn.nCol;
724cdf0e10cSrcweir 		//	nRow wird angepasst
725cdf0e10cSrcweir 		aRef.nTab = rColumn.nTab;
726cdf0e10cSrcweir 		aRef.InitFlags();							// -> alles absolut
727cdf0e10cSrcweir 		aRef.SetFlag3D(sal_True);
728cdf0e10cSrcweir 
729cdf0e10cSrcweir 		for (SCROW nDestRow = nRow1; nDestRow <= nRow2; nDestRow++)
730cdf0e10cSrcweir 		{
731cdf0e10cSrcweir 			aRef.nRow = nDestRow - nDy;				// Quell-Zeile
732cdf0e10cSrcweir 			aDestPos.SetRow( nDestRow );
733cdf0e10cSrcweir 
734cdf0e10cSrcweir 			aRef.CalcRelFromAbs( aDestPos );
735cdf0e10cSrcweir 			ScTokenArray aArr;
736cdf0e10cSrcweir 			aArr.AddSingleReference( aRef );
737cdf0e10cSrcweir 			Insert( nDestRow, new ScFormulaCell( pDocument, aDestPos, &aArr ) );
738cdf0e10cSrcweir 		}
739cdf0e10cSrcweir 
740cdf0e10cSrcweir 		return;
741cdf0e10cSrcweir 	}
742cdf0e10cSrcweir 
743cdf0e10cSrcweir 	SCSIZE nColCount = rColumn.nCount;
744cdf0e10cSrcweir 
745cdf0e10cSrcweir     // ignore IDF_FORMULA - "all contents but no formulas" results in the same number of cells
746cdf0e10cSrcweir 	if ((nInsFlag & ( IDF_CONTENTS & ~IDF_FORMULA )) == ( IDF_CONTENTS & ~IDF_FORMULA ) && nRow2-nRow1 >= 64)
747cdf0e10cSrcweir 	{
748cdf0e10cSrcweir         //! Always do the Resize from the outside, where the number of repetitions is known
749cdf0e10cSrcweir         //! (then it can be removed here)
750cdf0e10cSrcweir 
751cdf0e10cSrcweir 		SCSIZE nNew = nCount + nColCount;
752cdf0e10cSrcweir 		if ( nLimit < nNew )
753cdf0e10cSrcweir 			Resize( nNew );
754cdf0e10cSrcweir 	}
755cdf0e10cSrcweir 
756cdf0e10cSrcweir     // IDF_ADDNOTES must be passed without other content flags than IDF_NOTE
757cdf0e10cSrcweir     bool bAddNotes = (nInsFlag & (IDF_CONTENTS | IDF_ADDNOTES)) == (IDF_NOTE | IDF_ADDNOTES);
758cdf0e10cSrcweir 
759cdf0e10cSrcweir 	sal_Bool bAtEnd = sal_False;
760cdf0e10cSrcweir 	for (SCSIZE i = 0; i < nColCount && !bAtEnd; i++)
761cdf0e10cSrcweir 	{
762cdf0e10cSrcweir 		SCsROW nDestRow = rColumn.pItems[i].nRow + nDy;
763cdf0e10cSrcweir 		if ( nDestRow > (SCsROW) nRow2 )
764cdf0e10cSrcweir 			bAtEnd = sal_True;
765cdf0e10cSrcweir 		else if ( nDestRow >= (SCsROW) nRow1 )
766cdf0e10cSrcweir 		{
767cdf0e10cSrcweir 			//	rows at the beginning may be skipped if filtered rows are left out,
768cdf0e10cSrcweir 			//	nDestRow may be negative then
769cdf0e10cSrcweir 
770cdf0e10cSrcweir             ScAddress aDestPos( nCol, (SCROW)nDestRow, nTab );
771cdf0e10cSrcweir 
772cdf0e10cSrcweir             /*  #i102056# Paste from clipboard needs to paste the cell notes in
773cdf0e10cSrcweir                 a second pass. This must not overwrite the existing cells
774cdf0e10cSrcweir                 already copied to the destination position in the first pass.
775cdf0e10cSrcweir                 To indicate this special case, the modifier IDF_ADDNOTES is
776cdf0e10cSrcweir                 passed together with IDF_NOTE in nInsFlag. Of course, there is
777cdf0e10cSrcweir                 still the need to create a new cell, if there is no cell at the
778cdf0e10cSrcweir                 destination position at all. */
779cdf0e10cSrcweir             ScBaseCell* pAddNoteCell = bAddNotes ? GetCell( aDestPos.Row() ) : 0;
780cdf0e10cSrcweir             if (pAddNoteCell)
781cdf0e10cSrcweir             {
782cdf0e10cSrcweir                 // do nothing if source cell does not contain a note
783cdf0e10cSrcweir                 const ScBaseCell* pSourceCell = rColumn.pItems[i].pCell;
784cdf0e10cSrcweir                 const ScPostIt* pSourceNote = pSourceCell ? pSourceCell->GetNote() : 0;
785cdf0e10cSrcweir                 if (pSourceNote)
786cdf0e10cSrcweir                 {
787cdf0e10cSrcweir                     DBG_ASSERT( !pAddNoteCell->HasNote(), "ScColumn::CopyFromClip - unexpected note at destination cell" );
788cdf0e10cSrcweir                     bool bCloneCaption = (nInsFlag & IDF_NOCAPTIONS) == 0;
789cdf0e10cSrcweir                     // #i52342# if caption is cloned, the note must be constructed with the destination document
790cdf0e10cSrcweir                     ScAddress aSourcePos( rColumn.nCol, rColumn.pItems[i].nRow, rColumn.nTab );
791cdf0e10cSrcweir                     ScPostIt* pNewNote = pSourceNote->Clone( aSourcePos, *pDocument, aDestPos, bCloneCaption );
792cdf0e10cSrcweir                     pAddNoteCell->TakeNote( pNewNote );
793cdf0e10cSrcweir                 }
794cdf0e10cSrcweir             }
795cdf0e10cSrcweir             else
796cdf0e10cSrcweir             {
797cdf0e10cSrcweir                 ScBaseCell* pNewCell = bAsLink ?
798cdf0e10cSrcweir                     rColumn.CreateRefCell( pDocument, aDestPos, i, nInsFlag ) :
799cdf0e10cSrcweir                     rColumn.CloneCell( i, nInsFlag, *pDocument, aDestPos );
800cdf0e10cSrcweir                 if (pNewCell)
801cdf0e10cSrcweir                     Insert( aDestPos.Row(), pNewCell );
802cdf0e10cSrcweir             }
803cdf0e10cSrcweir 		}
804cdf0e10cSrcweir 	}
805cdf0e10cSrcweir }
806cdf0e10cSrcweir 
807cdf0e10cSrcweir 
808cdf0e10cSrcweir namespace {
809cdf0e10cSrcweir 
810cdf0e10cSrcweir /** Helper for ScColumn::CloneCell - decides whether to clone a value cell depending on clone flags and number format. */
lclCanCloneValue(ScDocument & rDoc,const ScColumn & rCol,SCROW nRow,bool bCloneValue,bool bCloneDateTime)811cdf0e10cSrcweir bool lclCanCloneValue( ScDocument& rDoc, const ScColumn& rCol, SCROW nRow, bool bCloneValue, bool bCloneDateTime )
812cdf0e10cSrcweir {
813cdf0e10cSrcweir     // values and dates, or nothing to be cloned -> not needed to check number format
814cdf0e10cSrcweir     if( bCloneValue == bCloneDateTime )
815cdf0e10cSrcweir         return bCloneValue;
816cdf0e10cSrcweir 
817cdf0e10cSrcweir     // check number format of value cell
818cdf0e10cSrcweir     sal_uLong nNumIndex = (sal_uLong)((SfxUInt32Item*)rCol.GetAttr( nRow, ATTR_VALUE_FORMAT ))->GetValue();
819cdf0e10cSrcweir     short nTyp = rDoc.GetFormatTable()->GetType( nNumIndex );
820cdf0e10cSrcweir     bool bIsDateTime = (nTyp == NUMBERFORMAT_DATE) || (nTyp == NUMBERFORMAT_TIME) || (nTyp == NUMBERFORMAT_DATETIME);
821cdf0e10cSrcweir     return bIsDateTime ? bCloneDateTime : bCloneValue;
822cdf0e10cSrcweir }
823cdf0e10cSrcweir 
824cdf0e10cSrcweir } // namespace
825cdf0e10cSrcweir 
826cdf0e10cSrcweir 
CloneCell(SCSIZE nIndex,sal_uInt16 nFlags,ScDocument & rDestDoc,const ScAddress & rDestPos)827cdf0e10cSrcweir ScBaseCell* ScColumn::CloneCell(SCSIZE nIndex, sal_uInt16 nFlags, ScDocument& rDestDoc, const ScAddress& rDestPos)
828cdf0e10cSrcweir {
829cdf0e10cSrcweir     bool bCloneValue    = (nFlags & IDF_VALUE) != 0;
830cdf0e10cSrcweir     bool bCloneDateTime = (nFlags & IDF_DATETIME) != 0;
831cdf0e10cSrcweir     bool bCloneString   = (nFlags & IDF_STRING) != 0;
832cdf0e10cSrcweir     bool bCloneFormula  = (nFlags & IDF_FORMULA) != 0;
833cdf0e10cSrcweir     bool bCloneNote     = (nFlags & IDF_NOTE) != 0;
834cdf0e10cSrcweir 
835cdf0e10cSrcweir     ScBaseCell* pNew = 0;
836cdf0e10cSrcweir     ScBaseCell& rSource = *pItems[nIndex].pCell;
837cdf0e10cSrcweir     switch (rSource.GetCellType())
838cdf0e10cSrcweir 	{
839cdf0e10cSrcweir 		case CELLTYPE_NOTE:
840cdf0e10cSrcweir             // note will be cloned below
841cdf0e10cSrcweir         break;
842cdf0e10cSrcweir 
843cdf0e10cSrcweir         case CELLTYPE_STRING:
844cdf0e10cSrcweir 		case CELLTYPE_EDIT:
845cdf0e10cSrcweir             // note will be cloned below
846cdf0e10cSrcweir             if (bCloneString)
847cdf0e10cSrcweir                 pNew = rSource.CloneWithoutNote( rDestDoc, rDestPos );
848cdf0e10cSrcweir         break;
849cdf0e10cSrcweir 
850cdf0e10cSrcweir 		case CELLTYPE_VALUE:
851cdf0e10cSrcweir             // note will be cloned below
852cdf0e10cSrcweir             if (lclCanCloneValue( *pDocument, *this, pItems[nIndex].nRow, bCloneValue, bCloneDateTime ))
853cdf0e10cSrcweir                 pNew = rSource.CloneWithoutNote( rDestDoc, rDestPos );
854cdf0e10cSrcweir         break;
855cdf0e10cSrcweir 
856cdf0e10cSrcweir 		case CELLTYPE_FORMULA:
857cdf0e10cSrcweir             if (bCloneFormula)
858cdf0e10cSrcweir             {
859cdf0e10cSrcweir                 // note will be cloned below
860cdf0e10cSrcweir                 pNew = rSource.CloneWithoutNote( rDestDoc, rDestPos );
861cdf0e10cSrcweir             }
862cdf0e10cSrcweir             else if ( (bCloneValue || bCloneDateTime || bCloneString) && !rDestDoc.IsUndo() )
863cdf0e10cSrcweir             {
864cdf0e10cSrcweir                 //  #48491# ins Undo-Dokument immer nur die Original-Zelle kopieren,
865cdf0e10cSrcweir                 //  aus Formeln keine Value/String-Zellen erzeugen
866cdf0e10cSrcweir                 ScFormulaCell& rForm = (ScFormulaCell&)rSource;
867cdf0e10cSrcweir                 sal_uInt16 nErr = rForm.GetErrCode();
868cdf0e10cSrcweir                 if ( nErr )
869cdf0e10cSrcweir                 {
870cdf0e10cSrcweir                     // error codes are cloned with values
871cdf0e10cSrcweir                     if (bCloneValue)
872cdf0e10cSrcweir                     {
873cdf0e10cSrcweir                         ScFormulaCell* pErrCell = new ScFormulaCell( &rDestDoc, rDestPos );
874cdf0e10cSrcweir                         pErrCell->SetErrCode( nErr );
875cdf0e10cSrcweir                         pNew = pErrCell;
876cdf0e10cSrcweir                     }
877cdf0e10cSrcweir                 }
878cdf0e10cSrcweir                 else if (rForm.IsValue())
879cdf0e10cSrcweir                 {
880cdf0e10cSrcweir                     if (lclCanCloneValue( *pDocument, *this, pItems[nIndex].nRow, bCloneValue, bCloneDateTime ))
881cdf0e10cSrcweir                     {
882cdf0e10cSrcweir                         double nVal = rForm.GetValue();
883cdf0e10cSrcweir                         pNew = new ScValueCell(nVal);
884cdf0e10cSrcweir                     }
885cdf0e10cSrcweir                 }
886cdf0e10cSrcweir                 else if (bCloneString)
887cdf0e10cSrcweir                 {
888cdf0e10cSrcweir                     String aString;
889cdf0e10cSrcweir                     rForm.GetString( aString );
890cdf0e10cSrcweir                     // #33224# do not clone empty string
891cdf0e10cSrcweir                     if (aString.Len() > 0)
892cdf0e10cSrcweir                     {
893cdf0e10cSrcweir                         if ( rForm.IsMultilineResult() )
894cdf0e10cSrcweir                         {
895cdf0e10cSrcweir                             pNew = new ScEditCell( aString, &rDestDoc );
896cdf0e10cSrcweir                         }
897cdf0e10cSrcweir                         else
898cdf0e10cSrcweir                         {
899cdf0e10cSrcweir                             pNew = new ScStringCell( aString );
900cdf0e10cSrcweir                         }
901cdf0e10cSrcweir                     }
902cdf0e10cSrcweir                 }
903cdf0e10cSrcweir             }
904cdf0e10cSrcweir         break;
905cdf0e10cSrcweir 
906cdf0e10cSrcweir         default: DBG_ERRORFILE( "ScColumn::CloneCell - unknown cell type" );
907cdf0e10cSrcweir 	}
908cdf0e10cSrcweir 
909cdf0e10cSrcweir     // clone the cell note
910cdf0e10cSrcweir     if (bCloneNote)
911cdf0e10cSrcweir     {
912cdf0e10cSrcweir         if (ScPostIt* pNote = rSource.GetNote())
913cdf0e10cSrcweir         {
914cdf0e10cSrcweir             bool bCloneCaption = (nFlags & IDF_NOCAPTIONS) == 0;
915cdf0e10cSrcweir             // #i52342# if caption is cloned, the note must be constructed with the destination document
916cdf0e10cSrcweir             ScAddress aOwnPos( nCol, pItems[nIndex].nRow, nTab );
917cdf0e10cSrcweir             ScPostIt* pNewNote = pNote->Clone( aOwnPos, rDestDoc, rDestPos, bCloneCaption );
918cdf0e10cSrcweir             if (!pNew)
919cdf0e10cSrcweir                 pNew = new ScNoteCell( pNewNote );
920cdf0e10cSrcweir             else
921cdf0e10cSrcweir                 pNew->TakeNote( pNewNote );
922cdf0e10cSrcweir         }
923cdf0e10cSrcweir     }
924cdf0e10cSrcweir 
925cdf0e10cSrcweir 	return pNew;
926cdf0e10cSrcweir }
927cdf0e10cSrcweir 
928cdf0e10cSrcweir 
MixMarked(const ScMarkData & rMark,sal_uInt16 nFunction,sal_Bool bSkipEmpty,ScColumn & rSrcCol)929cdf0e10cSrcweir void ScColumn::MixMarked( const ScMarkData& rMark, sal_uInt16 nFunction,
930cdf0e10cSrcweir 							sal_Bool bSkipEmpty, ScColumn& rSrcCol )
931cdf0e10cSrcweir {
932cdf0e10cSrcweir 	SCROW nRow1, nRow2;
933cdf0e10cSrcweir 
934cdf0e10cSrcweir 	if (rMark.IsMultiMarked())
935cdf0e10cSrcweir 	{
936cdf0e10cSrcweir 		ScMarkArrayIter aIter( rMark.GetArray()+nCol );
937cdf0e10cSrcweir 		while (aIter.Next( nRow1, nRow2 ))
938cdf0e10cSrcweir 			MixData( nRow1, nRow2, nFunction, bSkipEmpty, rSrcCol );
939cdf0e10cSrcweir 	}
940cdf0e10cSrcweir }
941cdf0e10cSrcweir 
942cdf0e10cSrcweir 
943cdf0e10cSrcweir //	Ergebnis in rVal1
944cdf0e10cSrcweir 
lcl_DoFunction(double & rVal1,double nVal2,sal_uInt16 nFunction)945cdf0e10cSrcweir sal_Bool lcl_DoFunction( double& rVal1, double nVal2, sal_uInt16 nFunction )
946cdf0e10cSrcweir {
947cdf0e10cSrcweir 	sal_Bool bOk = sal_False;
948cdf0e10cSrcweir 	switch (nFunction)
949cdf0e10cSrcweir 	{
950cdf0e10cSrcweir 		case PASTE_ADD:
951cdf0e10cSrcweir 			bOk = SubTotal::SafePlus( rVal1, nVal2 );
952cdf0e10cSrcweir 			break;
953cdf0e10cSrcweir 		case PASTE_SUB:
954cdf0e10cSrcweir 			nVal2 = -nVal2;		//! geht das immer ohne Fehler?
955cdf0e10cSrcweir 			bOk = SubTotal::SafePlus( rVal1, nVal2 );
956cdf0e10cSrcweir 			break;
957cdf0e10cSrcweir 		case PASTE_MUL:
958cdf0e10cSrcweir 			bOk = SubTotal::SafeMult( rVal1, nVal2 );
959cdf0e10cSrcweir 			break;
960cdf0e10cSrcweir 		case PASTE_DIV:
961cdf0e10cSrcweir 			bOk = SubTotal::SafeDiv( rVal1, nVal2 );
962cdf0e10cSrcweir 			break;
963cdf0e10cSrcweir 	}
964cdf0e10cSrcweir 	return bOk;
965cdf0e10cSrcweir }
966cdf0e10cSrcweir 
967cdf0e10cSrcweir 
lcl_AddCode(ScTokenArray & rArr,ScFormulaCell * pCell)968cdf0e10cSrcweir void lcl_AddCode( ScTokenArray& rArr, ScFormulaCell* pCell )
969cdf0e10cSrcweir {
970cdf0e10cSrcweir 	rArr.AddOpCode(ocOpen);
971cdf0e10cSrcweir 
972cdf0e10cSrcweir 	ScTokenArray* pCode = pCell->GetCode();
973cdf0e10cSrcweir 	if (pCode)
974cdf0e10cSrcweir 	{
975cdf0e10cSrcweir         const formula::FormulaToken* pToken = pCode->First();
976cdf0e10cSrcweir 		while (pToken)
977cdf0e10cSrcweir 		{
978cdf0e10cSrcweir 			rArr.AddToken( *pToken );
979cdf0e10cSrcweir 			pToken = pCode->Next();
980cdf0e10cSrcweir 		}
981cdf0e10cSrcweir 	}
982cdf0e10cSrcweir 
983cdf0e10cSrcweir 	rArr.AddOpCode(ocClose);
984cdf0e10cSrcweir }
985cdf0e10cSrcweir 
986cdf0e10cSrcweir 
MixData(SCROW nRow1,SCROW nRow2,sal_uInt16 nFunction,sal_Bool bSkipEmpty,ScColumn & rSrcCol)987cdf0e10cSrcweir void ScColumn::MixData( SCROW nRow1, SCROW nRow2,
988cdf0e10cSrcweir 							sal_uInt16 nFunction, sal_Bool bSkipEmpty,
989cdf0e10cSrcweir 							ScColumn& rSrcCol )
990cdf0e10cSrcweir {
991cdf0e10cSrcweir 	SCSIZE nSrcCount = rSrcCol.nCount;
992cdf0e10cSrcweir 
993cdf0e10cSrcweir 	SCSIZE nIndex;
994cdf0e10cSrcweir 	Search( nRow1, nIndex );
995cdf0e10cSrcweir 
996cdf0e10cSrcweir //	SCSIZE nSrcIndex = 0;
997cdf0e10cSrcweir 	SCSIZE nSrcIndex;
998cdf0e10cSrcweir 	rSrcCol.Search( nRow1, nSrcIndex );			//! Testen, ob Daten ganz vorne
999cdf0e10cSrcweir 
1000cdf0e10cSrcweir 	SCROW nNextThis = MAXROW+1;
1001cdf0e10cSrcweir 	if ( nIndex < nCount )
1002cdf0e10cSrcweir 		nNextThis = pItems[nIndex].nRow;
1003cdf0e10cSrcweir 	SCROW nNextSrc = MAXROW+1;
1004cdf0e10cSrcweir 	if ( nSrcIndex < nSrcCount )
1005cdf0e10cSrcweir 		nNextSrc = rSrcCol.pItems[nSrcIndex].nRow;
1006cdf0e10cSrcweir 
1007cdf0e10cSrcweir 	while ( nNextThis <= nRow2 || nNextSrc <= nRow2 )
1008cdf0e10cSrcweir 	{
1009cdf0e10cSrcweir 		SCROW nRow = Min( nNextThis, nNextSrc );
1010cdf0e10cSrcweir 
1011cdf0e10cSrcweir 		ScBaseCell* pSrc = NULL;
1012cdf0e10cSrcweir 		ScBaseCell* pDest = NULL;
1013cdf0e10cSrcweir 		ScBaseCell* pNew = NULL;
1014cdf0e10cSrcweir 		sal_Bool bDelete = sal_False;
1015cdf0e10cSrcweir 
1016cdf0e10cSrcweir 		if ( nSrcIndex < nSrcCount && nNextSrc == nRow )
1017cdf0e10cSrcweir 			pSrc = rSrcCol.pItems[nSrcIndex].pCell;
1018cdf0e10cSrcweir 
1019cdf0e10cSrcweir 		if ( nIndex < nCount && nNextThis == nRow )
1020cdf0e10cSrcweir 			pDest = pItems[nIndex].pCell;
1021cdf0e10cSrcweir 
1022cdf0e10cSrcweir         DBG_ASSERT( pSrc || pDest, "Nanu ?" );
1023cdf0e10cSrcweir 
1024cdf0e10cSrcweir 		CellType eSrcType  = pSrc  ? pSrc->GetCellType()  : CELLTYPE_NONE;
1025cdf0e10cSrcweir 		CellType eDestType = pDest ? pDest->GetCellType() : CELLTYPE_NONE;
1026cdf0e10cSrcweir 
1027cdf0e10cSrcweir 		sal_Bool bSrcEmpty = ( eSrcType == CELLTYPE_NONE || eSrcType == CELLTYPE_NOTE );
1028cdf0e10cSrcweir 		sal_Bool bDestEmpty = ( eDestType == CELLTYPE_NONE || eDestType == CELLTYPE_NOTE );
1029cdf0e10cSrcweir 
1030cdf0e10cSrcweir 		if ( bSkipEmpty && bDestEmpty )		// Originalzelle wiederherstellen
1031cdf0e10cSrcweir 		{
1032cdf0e10cSrcweir 			if ( pSrc )						// war da eine Zelle?
1033cdf0e10cSrcweir 			{
1034cdf0e10cSrcweir                 pNew = pSrc->CloneWithoutNote( *pDocument );
1035cdf0e10cSrcweir 			}
1036cdf0e10cSrcweir 		}
1037cdf0e10cSrcweir 		else if ( nFunction )				// wirklich Rechenfunktion angegeben
1038cdf0e10cSrcweir 		{
1039cdf0e10cSrcweir 			double nVal1;
1040cdf0e10cSrcweir 			double nVal2;
1041cdf0e10cSrcweir 			if ( eSrcType == CELLTYPE_VALUE )
1042cdf0e10cSrcweir 				nVal1 = ((ScValueCell*)pSrc)->GetValue();
1043cdf0e10cSrcweir 			else
1044cdf0e10cSrcweir 				nVal1 = 0.0;
1045cdf0e10cSrcweir 			if ( eDestType == CELLTYPE_VALUE )
1046cdf0e10cSrcweir 				nVal2 = ((ScValueCell*)pDest)->GetValue();
1047cdf0e10cSrcweir 			else
1048cdf0e10cSrcweir 				nVal2 = 0.0;
1049cdf0e10cSrcweir 
1050cdf0e10cSrcweir 			//	leere Zellen werden als Werte behandelt
1051cdf0e10cSrcweir 
1052cdf0e10cSrcweir 			sal_Bool bSrcVal  = ( bSrcEmpty || eSrcType == CELLTYPE_VALUE );
1053cdf0e10cSrcweir 			sal_Bool bDestVal  = ( bDestEmpty || eDestType == CELLTYPE_VALUE );
1054cdf0e10cSrcweir 
1055cdf0e10cSrcweir 			sal_Bool bSrcText = ( eSrcType == CELLTYPE_STRING ||
1056cdf0e10cSrcweir 								eSrcType == CELLTYPE_EDIT );
1057cdf0e10cSrcweir 			sal_Bool bDestText = ( eDestType == CELLTYPE_STRING ||
1058cdf0e10cSrcweir 								eDestType == CELLTYPE_EDIT );
1059cdf0e10cSrcweir 
1060cdf0e10cSrcweir 			//	sonst bleibt nur Formel...
1061cdf0e10cSrcweir 
1062cdf0e10cSrcweir 			if ( bSrcEmpty && bDestEmpty )
1063cdf0e10cSrcweir 			{
1064cdf0e10cSrcweir 				//	beide leer -> nix
1065cdf0e10cSrcweir 			}
1066cdf0e10cSrcweir 			else if ( bSrcVal && bDestVal )
1067cdf0e10cSrcweir 			{
1068cdf0e10cSrcweir 				//	neuen Wert eintragen, oder Fehler bei Ueberlauf
1069cdf0e10cSrcweir 
1070cdf0e10cSrcweir 				sal_Bool bOk = lcl_DoFunction( nVal1, nVal2, nFunction );
1071cdf0e10cSrcweir 
1072cdf0e10cSrcweir 				if (bOk)
1073cdf0e10cSrcweir 					pNew = new ScValueCell( nVal1 );
1074cdf0e10cSrcweir 				else
1075cdf0e10cSrcweir 				{
1076cdf0e10cSrcweir 					ScFormulaCell* pFC = new ScFormulaCell( pDocument,
1077cdf0e10cSrcweir 												ScAddress( nCol, nRow, nTab ) );
1078cdf0e10cSrcweir 					pFC->SetErrCode( errNoValue );
1079cdf0e10cSrcweir 					//!	oder NOVALUE, dann auch in consoli,
1080cdf0e10cSrcweir 					//!	sonst in Interpreter::GetCellValue die Abfrage auf errNoValue raus
1081cdf0e10cSrcweir 					//!	(dann geht Stringzelle+Wertzelle nicht mehr)
1082cdf0e10cSrcweir 					pNew = pFC;
1083cdf0e10cSrcweir 				}
1084cdf0e10cSrcweir 			}
1085cdf0e10cSrcweir 			else if ( bSrcText || bDestText )
1086cdf0e10cSrcweir 			{
1087cdf0e10cSrcweir 				//	mit Texten wird nicht gerechnet - immer "alte" Zelle, also pSrc
1088cdf0e10cSrcweir 
1089cdf0e10cSrcweir 				if (pSrc)
1090cdf0e10cSrcweir                     pNew = pSrc->CloneWithoutNote( *pDocument );
1091cdf0e10cSrcweir 				else if (pDest)
1092cdf0e10cSrcweir 					bDelete = sal_True;
1093cdf0e10cSrcweir 			}
1094cdf0e10cSrcweir 			else
1095cdf0e10cSrcweir 			{
1096cdf0e10cSrcweir 				//	Kombination aus Wert und mindestens einer Formel -> Formel erzeugen
1097cdf0e10cSrcweir 
1098cdf0e10cSrcweir 				ScTokenArray aArr;
1099cdf0e10cSrcweir 
1100cdf0e10cSrcweir 				//	erste Zelle
1101cdf0e10cSrcweir 				if ( eSrcType == CELLTYPE_FORMULA )
1102cdf0e10cSrcweir 					lcl_AddCode( aArr, (ScFormulaCell*)pSrc );
1103cdf0e10cSrcweir 				else
1104cdf0e10cSrcweir 					aArr.AddDouble( nVal1 );
1105cdf0e10cSrcweir 
1106cdf0e10cSrcweir 				//	Operator
1107cdf0e10cSrcweir 				OpCode eOp = ocAdd;
1108cdf0e10cSrcweir 				switch ( nFunction )
1109cdf0e10cSrcweir 				{
1110cdf0e10cSrcweir 					case PASTE_ADD:	eOp = ocAdd; break;
1111cdf0e10cSrcweir 					case PASTE_SUB:	eOp = ocSub; break;
1112cdf0e10cSrcweir 					case PASTE_MUL:	eOp = ocMul; break;
1113cdf0e10cSrcweir 					case PASTE_DIV:	eOp = ocDiv; break;
1114cdf0e10cSrcweir 				}
1115cdf0e10cSrcweir 				aArr.AddOpCode(eOp);				// Funktion
1116cdf0e10cSrcweir 
1117cdf0e10cSrcweir 				//	zweite Zelle
1118cdf0e10cSrcweir 				if ( eDestType == CELLTYPE_FORMULA )
1119cdf0e10cSrcweir 					lcl_AddCode( aArr, (ScFormulaCell*)pDest );
1120cdf0e10cSrcweir 				else
1121cdf0e10cSrcweir 					aArr.AddDouble( nVal2 );
1122cdf0e10cSrcweir 
1123cdf0e10cSrcweir 				pNew = new ScFormulaCell( pDocument, ScAddress( nCol, nRow, nTab ), &aArr );
1124cdf0e10cSrcweir 			}
1125cdf0e10cSrcweir 		}
1126cdf0e10cSrcweir 
1127cdf0e10cSrcweir 
1128cdf0e10cSrcweir 		if ( pNew || bDelete )			// neues Ergebnis ?
1129cdf0e10cSrcweir 		{
1130cdf0e10cSrcweir 			if (pDest && !pNew)						// alte Zelle da ?
1131cdf0e10cSrcweir 			{
1132cdf0e10cSrcweir 				if ( pDest->GetBroadcaster() )
1133cdf0e10cSrcweir 					pNew = new ScNoteCell;			// Broadcaster uebernehmen
1134cdf0e10cSrcweir 				else
1135cdf0e10cSrcweir 					Delete(nRow);					// -> loeschen
1136cdf0e10cSrcweir 			}
1137cdf0e10cSrcweir 			if (pNew)
1138cdf0e10cSrcweir 				Insert(nRow, pNew);		// neue einfuegen
1139cdf0e10cSrcweir 
1140cdf0e10cSrcweir 			Search( nRow, nIndex );		// alles kann sich verschoben haben
1141cdf0e10cSrcweir 			if (pNew)
1142cdf0e10cSrcweir 				nNextThis = nRow;		// nIndex zeigt jetzt genau auf nRow
1143cdf0e10cSrcweir 			else
1144cdf0e10cSrcweir 				nNextThis = ( nIndex < nCount ) ? pItems[nIndex].nRow : MAXROW+1;
1145cdf0e10cSrcweir 		}
1146cdf0e10cSrcweir 
1147cdf0e10cSrcweir 		if ( nNextThis == nRow )
1148cdf0e10cSrcweir 		{
1149cdf0e10cSrcweir 			++nIndex;
1150cdf0e10cSrcweir 			nNextThis = ( nIndex < nCount ) ? pItems[nIndex].nRow : MAXROW+1;
1151cdf0e10cSrcweir 		}
1152cdf0e10cSrcweir 		if ( nNextSrc == nRow )
1153cdf0e10cSrcweir 		{
1154cdf0e10cSrcweir 			++nSrcIndex;
1155cdf0e10cSrcweir 			nNextSrc = ( nSrcIndex < nSrcCount ) ?
1156cdf0e10cSrcweir 							rSrcCol.pItems[nSrcIndex].nRow :
1157cdf0e10cSrcweir 							MAXROW+1;
1158cdf0e10cSrcweir 		}
1159cdf0e10cSrcweir 	}
1160cdf0e10cSrcweir }
1161cdf0e10cSrcweir 
1162cdf0e10cSrcweir 
CreateAttrIterator(SCROW nStartRow,SCROW nEndRow) const1163cdf0e10cSrcweir ScAttrIterator* ScColumn::CreateAttrIterator( SCROW nStartRow, SCROW nEndRow ) const
1164cdf0e10cSrcweir {
1165cdf0e10cSrcweir 	return new ScAttrIterator( pAttrArray, nStartRow, nEndRow );
1166cdf0e10cSrcweir }
1167cdf0e10cSrcweir 
1168cdf0e10cSrcweir 
StartAllListeners()1169cdf0e10cSrcweir void ScColumn::StartAllListeners()
1170cdf0e10cSrcweir {
1171cdf0e10cSrcweir 	if (pItems)
1172cdf0e10cSrcweir 		for (SCSIZE i = 0; i < nCount; i++)
1173cdf0e10cSrcweir 		{
1174cdf0e10cSrcweir 			ScBaseCell* pCell = pItems[i].pCell;
1175cdf0e10cSrcweir 			if ( pCell->GetCellType() == CELLTYPE_FORMULA )
1176cdf0e10cSrcweir 			{
1177cdf0e10cSrcweir 				SCROW nRow = pItems[i].nRow;
1178cdf0e10cSrcweir 				((ScFormulaCell*)pCell)->StartListeningTo( pDocument );
1179cdf0e10cSrcweir 				if ( nRow != pItems[i].nRow )
1180cdf0e10cSrcweir 					Search( nRow, i );		// Listener eingefuegt?
1181cdf0e10cSrcweir 			}
1182cdf0e10cSrcweir 		}
1183cdf0e10cSrcweir }
1184cdf0e10cSrcweir 
1185cdf0e10cSrcweir 
StartNeededListeners()1186cdf0e10cSrcweir void ScColumn::StartNeededListeners()
1187cdf0e10cSrcweir {
1188cdf0e10cSrcweir 	if (pItems)
1189cdf0e10cSrcweir     {
1190cdf0e10cSrcweir 		for (SCSIZE i = 0; i < nCount; i++)
1191cdf0e10cSrcweir 		{
1192cdf0e10cSrcweir 			ScBaseCell* pCell = pItems[i].pCell;
1193cdf0e10cSrcweir 			if ( pCell->GetCellType() == CELLTYPE_FORMULA )
1194cdf0e10cSrcweir 			{
1195cdf0e10cSrcweir                 ScFormulaCell* pFCell = static_cast<ScFormulaCell*>(pCell);
1196cdf0e10cSrcweir                 if (pFCell->NeedsListening())
1197cdf0e10cSrcweir                 {
1198cdf0e10cSrcweir                     SCROW nRow = pItems[i].nRow;
1199cdf0e10cSrcweir                     pFCell->StartListeningTo( pDocument );
1200cdf0e10cSrcweir                     if ( nRow != pItems[i].nRow )
1201cdf0e10cSrcweir                         Search( nRow, i );		// Listener eingefuegt?
1202cdf0e10cSrcweir                 }
1203cdf0e10cSrcweir 			}
1204cdf0e10cSrcweir 		}
1205cdf0e10cSrcweir     }
1206cdf0e10cSrcweir }
1207cdf0e10cSrcweir 
1208cdf0e10cSrcweir 
BroadcastInArea(SCROW nRow1,SCROW nRow2)1209cdf0e10cSrcweir void ScColumn::BroadcastInArea( SCROW nRow1, SCROW nRow2 )
1210cdf0e10cSrcweir {
1211cdf0e10cSrcweir 	if ( pItems )
1212cdf0e10cSrcweir 	{
1213cdf0e10cSrcweir         SCROW nRow;
1214cdf0e10cSrcweir         SCSIZE nIndex;
1215cdf0e10cSrcweir 		Search( nRow1, nIndex );
1216cdf0e10cSrcweir 		while ( nIndex < nCount && (nRow = pItems[nIndex].nRow) <= nRow2 )
1217cdf0e10cSrcweir 		{
1218cdf0e10cSrcweir 			ScBaseCell* pCell = pItems[nIndex].pCell;
1219cdf0e10cSrcweir 			if ( pCell->GetCellType() == CELLTYPE_FORMULA )
1220cdf0e10cSrcweir 				((ScFormulaCell*)pCell)->SetDirty();
1221cdf0e10cSrcweir 			else
1222cdf0e10cSrcweir 				pDocument->Broadcast( ScHint( SC_HINT_DATACHANGED,
1223cdf0e10cSrcweir 					ScAddress( nCol, nRow, nTab ), pCell ) );
1224cdf0e10cSrcweir 			nIndex++;
1225cdf0e10cSrcweir 		}
1226cdf0e10cSrcweir 	}
1227cdf0e10cSrcweir }
1228cdf0e10cSrcweir 
1229cdf0e10cSrcweir 
StartListeningInArea(SCROW nRow1,SCROW nRow2)1230cdf0e10cSrcweir void ScColumn::StartListeningInArea( SCROW nRow1, SCROW nRow2 )
1231cdf0e10cSrcweir {
1232cdf0e10cSrcweir 	if ( pItems )
1233cdf0e10cSrcweir 	{
1234cdf0e10cSrcweir         SCROW nRow;
1235cdf0e10cSrcweir         SCSIZE nIndex;
1236cdf0e10cSrcweir 		Search( nRow1, nIndex );
1237cdf0e10cSrcweir 		while ( nIndex < nCount && (nRow = pItems[nIndex].nRow) <= nRow2 )
1238cdf0e10cSrcweir 		{
1239cdf0e10cSrcweir 			ScBaseCell* pCell = pItems[nIndex].pCell;
1240cdf0e10cSrcweir 			if ( pCell->GetCellType() == CELLTYPE_FORMULA )
1241cdf0e10cSrcweir 				((ScFormulaCell*)pCell)->StartListeningTo( pDocument );
1242cdf0e10cSrcweir 			if ( nRow != pItems[nIndex].nRow )
1243cdf0e10cSrcweir 				Search( nRow, nIndex );		// durch Listening eingefuegt
1244cdf0e10cSrcweir 			nIndex++;
1245cdf0e10cSrcweir 		}
1246cdf0e10cSrcweir 	}
1247cdf0e10cSrcweir }
1248cdf0e10cSrcweir 
1249cdf0e10cSrcweir 
1250cdf0e10cSrcweir //	sal_True = Zahlformat gesetzt
SetString(SCROW nRow,SCTAB nTabP,const String & rString,formula::FormulaGrammar::AddressConvention eConv,SvNumberFormatter * pLangFormatter,bool bDetectNumberFormat)1251cdf0e10cSrcweir sal_Bool ScColumn::SetString( SCROW nRow, SCTAB nTabP, const String& rString,
1252cdf0e10cSrcweir                           formula::FormulaGrammar::AddressConvention eConv,
1253cdf0e10cSrcweir                           SvNumberFormatter* pLangFormatter, bool bDetectNumberFormat )
1254cdf0e10cSrcweir {
1255cdf0e10cSrcweir 	sal_Bool bNumFmtSet = sal_False;
1256cdf0e10cSrcweir 	if (VALIDROW(nRow))
1257cdf0e10cSrcweir 	{
1258cdf0e10cSrcweir 		ScBaseCell* pNewCell = NULL;
1259cdf0e10cSrcweir 		sal_Bool bIsLoading = sal_False;
1260cdf0e10cSrcweir 		if (rString.Len() > 0)
1261cdf0e10cSrcweir 		{
1262cdf0e10cSrcweir 			double nVal;
1263cdf0e10cSrcweir             sal_uInt32 nIndex, nOldIndex = 0;
1264cdf0e10cSrcweir 			sal_Unicode cFirstChar;
1265cdf0e10cSrcweir             // #i110979# If a different NumberFormatter is passed in (pLangFormatter),
1266cdf0e10cSrcweir             // its formats aren't valid in the document.
1267cdf0e10cSrcweir             // Only use the language / LocaleDataWrapper from pLangFormatter,
1268cdf0e10cSrcweir             // always the document's number formatter for IsNumberFormat.
1269cdf0e10cSrcweir             SvNumberFormatter* pFormatter = pDocument->GetFormatTable();
1270cdf0e10cSrcweir 			SfxObjectShell* pDocSh = pDocument->GetDocumentShell();
1271cdf0e10cSrcweir 			if ( pDocSh )
1272cdf0e10cSrcweir 				bIsLoading = pDocSh->IsLoading();
1273cdf0e10cSrcweir 			// IsLoading bei ConvertFrom Import
1274cdf0e10cSrcweir 			if ( !bIsLoading )
1275cdf0e10cSrcweir 			{
1276cdf0e10cSrcweir 				nIndex = nOldIndex = GetNumberFormat( nRow );
1277cdf0e10cSrcweir 				if ( rString.Len() > 1
1278cdf0e10cSrcweir 						&& pFormatter->GetType(nIndex) != NUMBERFORMAT_TEXT )
1279cdf0e10cSrcweir 					cFirstChar = rString.GetChar(0);
1280cdf0e10cSrcweir 				else
1281cdf0e10cSrcweir 					cFirstChar = 0;								// Text
1282cdf0e10cSrcweir 			}
1283cdf0e10cSrcweir 			else
1284cdf0e10cSrcweir 			{	// waehrend ConvertFrom Import gibt es keine gesetzten Formate
1285cdf0e10cSrcweir 				cFirstChar = rString.GetChar(0);
1286cdf0e10cSrcweir 			}
1287cdf0e10cSrcweir 
1288cdf0e10cSrcweir 			if ( cFirstChar == '=' )
1289cdf0e10cSrcweir 			{
1290cdf0e10cSrcweir 				if ( rString.Len() == 1 )						// = Text
1291cdf0e10cSrcweir 					pNewCell = new ScStringCell( rString );
1292cdf0e10cSrcweir 				else											// =Formel
1293cdf0e10cSrcweir 					pNewCell = new ScFormulaCell( pDocument,
1294cdf0e10cSrcweir                         ScAddress( nCol, nRow, nTabP ), rString,
1295cdf0e10cSrcweir                         formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_DEFAULT,
1296cdf0e10cSrcweir                             eConv), MM_NONE );
1297cdf0e10cSrcweir 			}
1298cdf0e10cSrcweir 			else if ( cFirstChar == '\'')						// 'Text
1299cdf0e10cSrcweir 				pNewCell = new ScStringCell( rString.Copy(1) );
1300cdf0e10cSrcweir 			else
1301cdf0e10cSrcweir 			{
1302cdf0e10cSrcweir 				sal_Bool bIsText = sal_False;
1303cdf0e10cSrcweir 				if ( bIsLoading )
1304cdf0e10cSrcweir 				{
1305cdf0e10cSrcweir 					if ( pItems && nCount )
1306cdf0e10cSrcweir 					{
1307cdf0e10cSrcweir 						String aStr;
1308cdf0e10cSrcweir 						SCSIZE i = nCount;
1309cdf0e10cSrcweir 						SCSIZE nStop = (i >= 3 ? i - 3 : 0);
1310cdf0e10cSrcweir 						// die letzten Zellen vergleichen, ob gleicher String
1311cdf0e10cSrcweir 						// und IsNumberFormat eingespart werden kann
1312cdf0e10cSrcweir 						do
1313cdf0e10cSrcweir 						{
1314cdf0e10cSrcweir 							i--;
1315cdf0e10cSrcweir 							ScBaseCell* pCell = pItems[i].pCell;
1316cdf0e10cSrcweir 							switch ( pCell->GetCellType() )
1317cdf0e10cSrcweir 							{
1318cdf0e10cSrcweir 								case CELLTYPE_STRING :
1319cdf0e10cSrcweir 									((ScStringCell*)pCell)->GetString( aStr );
1320cdf0e10cSrcweir 									if ( rString == aStr )
1321cdf0e10cSrcweir 										bIsText = sal_True;
1322cdf0e10cSrcweir 								break;
1323cdf0e10cSrcweir 								case CELLTYPE_NOTE :	// durch =Formel referenziert
1324cdf0e10cSrcweir 								break;
1325cdf0e10cSrcweir 								default:
1326cdf0e10cSrcweir 									if ( i == nCount - 1 )
1327cdf0e10cSrcweir 										i = 0;
1328cdf0e10cSrcweir 										// wahrscheinlich ganze Spalte kein String
1329cdf0e10cSrcweir 							}
1330cdf0e10cSrcweir 						} while ( i && i > nStop && !bIsText );
1331cdf0e10cSrcweir 					}
1332cdf0e10cSrcweir 					// nIndex fuer IsNumberFormat vorbelegen
1333cdf0e10cSrcweir 					if ( !bIsText )
1334cdf0e10cSrcweir 						nIndex = nOldIndex = pFormatter->GetStandardIndex();
1335cdf0e10cSrcweir 				}
1336cdf0e10cSrcweir 
1337cdf0e10cSrcweir                 do
1338cdf0e10cSrcweir                 {
1339cdf0e10cSrcweir                     if (bIsText)
1340cdf0e10cSrcweir                         break;
1341cdf0e10cSrcweir 
1342cdf0e10cSrcweir                     if (bDetectNumberFormat)
1343cdf0e10cSrcweir                     {
1344cdf0e10cSrcweir                         if ( pLangFormatter )
1345cdf0e10cSrcweir                         {
1346cdf0e10cSrcweir                             // for number detection: valid format index for selected language
1347cdf0e10cSrcweir                             nIndex = pFormatter->GetStandardIndex( pLangFormatter->GetLanguage() );
1348cdf0e10cSrcweir                         }
1349cdf0e10cSrcweir 
1350cdf0e10cSrcweir                         if (!pFormatter->IsNumberFormat(rString, nIndex, nVal))
1351cdf0e10cSrcweir                             break;
1352cdf0e10cSrcweir 
1353cdf0e10cSrcweir                         if ( pLangFormatter )
1354cdf0e10cSrcweir                         {
1355cdf0e10cSrcweir                             // convert back to the original language if a built-in format was detected
1356cdf0e10cSrcweir                             const SvNumberformat* pOldFormat = pFormatter->GetEntry( nOldIndex );
1357cdf0e10cSrcweir                             if ( pOldFormat )
1358cdf0e10cSrcweir                                 nIndex = pFormatter->GetFormatForLanguageIfBuiltIn( nIndex, pOldFormat->GetLanguage() );
1359cdf0e10cSrcweir                         }
1360cdf0e10cSrcweir 
1361cdf0e10cSrcweir                         pNewCell = new ScValueCell( nVal );
1362cdf0e10cSrcweir                         if ( nIndex != nOldIndex)
1363cdf0e10cSrcweir                         {
1364cdf0e10cSrcweir                             // #i22345# New behavior: Apply the detected number format only if
1365cdf0e10cSrcweir                             // the old one was the default number, date, time or boolean format.
1366cdf0e10cSrcweir                             // Exception: If the new format is boolean, always apply it.
1367cdf0e10cSrcweir 
1368cdf0e10cSrcweir                             sal_Bool bOverwrite = sal_False;
1369cdf0e10cSrcweir                             const SvNumberformat* pOldFormat = pFormatter->GetEntry( nOldIndex );
1370cdf0e10cSrcweir                             if ( pOldFormat )
1371cdf0e10cSrcweir                             {
1372cdf0e10cSrcweir                                 short nOldType = pOldFormat->GetType() & ~NUMBERFORMAT_DEFINED;
1373cdf0e10cSrcweir                                 if ( nOldType == NUMBERFORMAT_NUMBER || nOldType == NUMBERFORMAT_DATE ||
1374cdf0e10cSrcweir                                      nOldType == NUMBERFORMAT_TIME || nOldType == NUMBERFORMAT_LOGICAL )
1375cdf0e10cSrcweir                                 {
1376cdf0e10cSrcweir                                     if ( nOldIndex == pFormatter->GetStandardFormat(
1377cdf0e10cSrcweir                                                         nOldType, pOldFormat->GetLanguage() ) )
1378cdf0e10cSrcweir                                     {
1379cdf0e10cSrcweir                                         bOverwrite = sal_True;      // default of these types can be overwritten
1380cdf0e10cSrcweir                                     }
1381cdf0e10cSrcweir                                 }
1382cdf0e10cSrcweir                             }
1383cdf0e10cSrcweir                             if ( !bOverwrite && pFormatter->GetType( nIndex ) == NUMBERFORMAT_LOGICAL )
1384cdf0e10cSrcweir                             {
1385cdf0e10cSrcweir                                 bOverwrite = sal_True;              // overwrite anything if boolean was detected
1386cdf0e10cSrcweir                             }
1387cdf0e10cSrcweir 
1388cdf0e10cSrcweir                             if ( bOverwrite )
1389cdf0e10cSrcweir                             {
1390cdf0e10cSrcweir                                 ApplyAttr( nRow, SfxUInt32Item( ATTR_VALUE_FORMAT,
1391cdf0e10cSrcweir                                     (sal_uInt32) nIndex) );
1392cdf0e10cSrcweir                                 bNumFmtSet = sal_True;
1393cdf0e10cSrcweir                             }
1394cdf0e10cSrcweir                         }
1395cdf0e10cSrcweir                     }
1396cdf0e10cSrcweir                     else
1397cdf0e10cSrcweir                     {
1398cdf0e10cSrcweir                         // Only check if the string is a regular number.
1399cdf0e10cSrcweir                         SvNumberFormatter* pLocaleSource = pLangFormatter ? pLangFormatter : pFormatter;
1400cdf0e10cSrcweir                         const LocaleDataWrapper* pLocale = pLocaleSource->GetLocaleData();
1401cdf0e10cSrcweir                         if (!pLocale)
1402cdf0e10cSrcweir                             break;
1403cdf0e10cSrcweir 
1404cdf0e10cSrcweir                         LocaleDataItem aLocaleItem = pLocale->getLocaleItem();
1405cdf0e10cSrcweir                         const OUString& rDecSep = aLocaleItem.decimalSeparator;
1406cdf0e10cSrcweir                         const OUString& rGroupSep = aLocaleItem.thousandSeparator;
1407cdf0e10cSrcweir                         if (rDecSep.getLength() != 1 || rGroupSep.getLength() != 1)
1408cdf0e10cSrcweir                             break;
1409cdf0e10cSrcweir 
1410cdf0e10cSrcweir                         sal_Unicode dsep = rDecSep.getStr()[0];
1411cdf0e10cSrcweir                         sal_Unicode gsep = rGroupSep.getStr()[0];
1412cdf0e10cSrcweir 
1413cdf0e10cSrcweir                         if (!ScStringUtil::parseSimpleNumber(rString, dsep, gsep, nVal))
1414cdf0e10cSrcweir                             break;
1415cdf0e10cSrcweir 
1416cdf0e10cSrcweir                         pNewCell = new ScValueCell(nVal);
1417cdf0e10cSrcweir                     }
1418cdf0e10cSrcweir                 }
1419cdf0e10cSrcweir                 while (false);
1420cdf0e10cSrcweir 
1421cdf0e10cSrcweir                 if (!pNewCell)
1422cdf0e10cSrcweir                     pNewCell = new ScStringCell(rString);
1423cdf0e10cSrcweir             }
1424cdf0e10cSrcweir         }
1425cdf0e10cSrcweir 
1426cdf0e10cSrcweir 		if ( bIsLoading && (!nCount || nRow > pItems[nCount-1].nRow) )
1427cdf0e10cSrcweir 		{	// Search einsparen und ohne Umweg ueber Insert, Listener aufbauen
1428cdf0e10cSrcweir 			// und Broadcast kommt eh erst nach dem Laden
1429cdf0e10cSrcweir 			if ( pNewCell )
1430cdf0e10cSrcweir 				Append( nRow, pNewCell );
1431cdf0e10cSrcweir 		}
1432cdf0e10cSrcweir 		else
1433cdf0e10cSrcweir 		{
1434cdf0e10cSrcweir 			SCSIZE i;
1435cdf0e10cSrcweir 			if (Search(nRow, i))
1436cdf0e10cSrcweir 			{
1437cdf0e10cSrcweir 				ScBaseCell* pOldCell = pItems[i].pCell;
1438cdf0e10cSrcweir 				ScPostIt* pNote = pOldCell->ReleaseNote();
1439cdf0e10cSrcweir                 SvtBroadcaster* pBC = pOldCell->ReleaseBroadcaster();
1440cdf0e10cSrcweir 				if (pNewCell || pNote || pBC)
1441cdf0e10cSrcweir 				{
1442cdf0e10cSrcweir 					if (pNewCell)
1443cdf0e10cSrcweir                         pNewCell->TakeNote( pNote );
1444cdf0e10cSrcweir                     else
1445cdf0e10cSrcweir 						pNewCell = new ScNoteCell( pNote );
1446cdf0e10cSrcweir 					if (pBC)
1447cdf0e10cSrcweir 					{
1448cdf0e10cSrcweir                         pNewCell->TakeBroadcaster(pBC);
1449cdf0e10cSrcweir 						pLastFormulaTreeTop = 0;	// Err527 Workaround
1450cdf0e10cSrcweir 					}
1451cdf0e10cSrcweir 
1452cdf0e10cSrcweir 					if ( pOldCell->GetCellType() == CELLTYPE_FORMULA )
1453cdf0e10cSrcweir 					{
1454cdf0e10cSrcweir 						pOldCell->EndListeningTo( pDocument );
1455cdf0e10cSrcweir 						// falls in EndListening NoteCell in gleicher Col zerstoert
1456cdf0e10cSrcweir 						if ( i >= nCount || pItems[i].nRow != nRow )
1457cdf0e10cSrcweir 							Search(nRow, i);
1458cdf0e10cSrcweir 					}
1459cdf0e10cSrcweir 					pOldCell->Delete();
1460cdf0e10cSrcweir 					pItems[i].pCell = pNewCell;			// ersetzen
1461cdf0e10cSrcweir 					if ( pNewCell->GetCellType() == CELLTYPE_FORMULA )
1462cdf0e10cSrcweir 					{
1463cdf0e10cSrcweir 						pNewCell->StartListeningTo( pDocument );
1464cdf0e10cSrcweir 						((ScFormulaCell*)pNewCell)->SetDirty();
1465cdf0e10cSrcweir 					}
1466cdf0e10cSrcweir 					else
1467cdf0e10cSrcweir 						pDocument->Broadcast( ScHint( SC_HINT_DATACHANGED,
1468cdf0e10cSrcweir                             ScAddress( nCol, nRow, nTabP ), pNewCell ) );
1469cdf0e10cSrcweir 				}
1470cdf0e10cSrcweir 				else
1471cdf0e10cSrcweir 				{
1472cdf0e10cSrcweir 					DeleteAtIndex(i);					// loeschen und Broadcast
1473cdf0e10cSrcweir 				}
1474cdf0e10cSrcweir 			}
1475cdf0e10cSrcweir 			else if (pNewCell)
1476cdf0e10cSrcweir 			{
1477cdf0e10cSrcweir 				Insert(nRow, pNewCell);					// neu eintragen und Broadcast
1478cdf0e10cSrcweir 			}
1479cdf0e10cSrcweir 		}
1480cdf0e10cSrcweir 
1481cdf0e10cSrcweir 		//	hier keine Formate mehr fuer Formeln setzen!
1482cdf0e10cSrcweir 		//	(werden bei der Ausgabe abgefragt)
1483cdf0e10cSrcweir 
1484cdf0e10cSrcweir 	}
1485cdf0e10cSrcweir 	return bNumFmtSet;
1486cdf0e10cSrcweir }
1487cdf0e10cSrcweir 
1488cdf0e10cSrcweir 
GetFilterEntries(SCROW nStartRow,SCROW nEndRow,TypedScStrCollection & rStrings,bool & rHasDates)1489cdf0e10cSrcweir void ScColumn::GetFilterEntries(SCROW nStartRow, SCROW nEndRow, TypedScStrCollection& rStrings, bool& rHasDates)
1490cdf0e10cSrcweir {
1491cdf0e10cSrcweir     bool bHasDates = false;
1492cdf0e10cSrcweir 	SvNumberFormatter* pFormatter = pDocument->GetFormatTable();
1493cdf0e10cSrcweir 	String aString;
1494cdf0e10cSrcweir     SCROW nRow = 0;
1495cdf0e10cSrcweir 	SCSIZE nIndex;
1496cdf0e10cSrcweir 
1497cdf0e10cSrcweir 	Search( nStartRow, nIndex );
1498cdf0e10cSrcweir 
1499cdf0e10cSrcweir 	while ( (nIndex < nCount) ? ((nRow=pItems[nIndex].nRow) <= nEndRow) : sal_False )
1500cdf0e10cSrcweir 	{
1501cdf0e10cSrcweir 		ScBaseCell*			 pCell	  = pItems[nIndex].pCell;
1502cdf0e10cSrcweir 		TypedStrData*		 pData;
1503cdf0e10cSrcweir 		sal_uLong				 nFormat  = GetNumberFormat( nRow );
1504cdf0e10cSrcweir 
1505cdf0e10cSrcweir 		ScCellFormat::GetInputString( pCell, nFormat, aString, *pFormatter );
1506cdf0e10cSrcweir 
1507cdf0e10cSrcweir 		if ( pDocument->HasStringData( nCol, nRow, nTab ) )
1508cdf0e10cSrcweir 			pData = new TypedStrData( aString );
1509cdf0e10cSrcweir 		else
1510cdf0e10cSrcweir 		{
1511cdf0e10cSrcweir 			double nValue;
1512cdf0e10cSrcweir 
1513cdf0e10cSrcweir 			switch ( pCell->GetCellType() )
1514cdf0e10cSrcweir 			{
1515cdf0e10cSrcweir 				case CELLTYPE_VALUE:
1516cdf0e10cSrcweir 					nValue = ((ScValueCell*)pCell)->GetValue();
1517cdf0e10cSrcweir 					break;
1518cdf0e10cSrcweir 
1519cdf0e10cSrcweir 				case CELLTYPE_FORMULA:
1520cdf0e10cSrcweir 					nValue = ((ScFormulaCell*)pCell)->GetValue();
1521cdf0e10cSrcweir 					break;
1522cdf0e10cSrcweir 
1523cdf0e10cSrcweir 				default:
1524cdf0e10cSrcweir 					nValue = 0.0;
1525cdf0e10cSrcweir 			}
1526cdf0e10cSrcweir 
1527cdf0e10cSrcweir             if (pFormatter)
1528cdf0e10cSrcweir             {
1529cdf0e10cSrcweir                 short nType = pFormatter->GetType(nFormat);
1530cdf0e10cSrcweir                 if ((nType & NUMBERFORMAT_DATE) && !(nType & NUMBERFORMAT_TIME))
1531cdf0e10cSrcweir                 {
1532cdf0e10cSrcweir                     // special case for date values.  Disregard the time
1533cdf0e10cSrcweir                     // element if the number format is of date type.
1534cdf0e10cSrcweir                     nValue = ::rtl::math::approxFloor(nValue);
1535cdf0e10cSrcweir                     bHasDates = true;
1536cdf0e10cSrcweir                 }
1537cdf0e10cSrcweir             }
1538cdf0e10cSrcweir 
1539cdf0e10cSrcweir 			pData = new TypedStrData( aString, nValue, SC_STRTYPE_VALUE );
1540cdf0e10cSrcweir 		}
1541cdf0e10cSrcweir #if 0 // DR
1542cdf0e10cSrcweir 		ScPostIt aCellNote( ScPostIt::UNINITIALIZED );
1543cdf0e10cSrcweir 		// Hide visible notes during Filtering.
1544cdf0e10cSrcweir 		if(pCell->GetNote(aCellNote) && aCellNote.IsCaptionShown())
1545cdf0e10cSrcweir 		{
1546cdf0e10cSrcweir 		    ScDetectiveFunc( pDocument, nTab ).HideComment( nCol, nRow );
1547cdf0e10cSrcweir 		    aCellNote.SetShown( false );
1548cdf0e10cSrcweir 		    pCell->SetNote(aCellNote);
1549cdf0e10cSrcweir 		}
1550cdf0e10cSrcweir #endif
1551cdf0e10cSrcweir 
1552cdf0e10cSrcweir 		if ( !rStrings.Insert( pData ) )
1553cdf0e10cSrcweir 			delete pData;								// doppelt
1554cdf0e10cSrcweir 
1555cdf0e10cSrcweir 		++nIndex;
1556cdf0e10cSrcweir 	}
1557cdf0e10cSrcweir 
1558cdf0e10cSrcweir     rHasDates = bHasDates;
1559cdf0e10cSrcweir }
1560cdf0e10cSrcweir 
1561cdf0e10cSrcweir //
1562cdf0e10cSrcweir //	GetDataEntries - Strings aus zusammenhaengendem Bereich um nRow
1563cdf0e10cSrcweir //
1564cdf0e10cSrcweir 
1565cdf0e10cSrcweir //	DATENT_MAX		- max. Anzahl Eintrage in Liste fuer Auto-Eingabe
1566cdf0e10cSrcweir //	DATENT_SEARCH	- max. Anzahl Zellen, die durchsucht werden - neu: nur Strings zaehlen
1567cdf0e10cSrcweir #define DATENT_MAX		200
1568cdf0e10cSrcweir #define DATENT_SEARCH	2000
1569cdf0e10cSrcweir 
1570cdf0e10cSrcweir 
GetDataEntries(SCROW nStartRow,TypedScStrCollection & rStrings,sal_Bool bLimit)1571cdf0e10cSrcweir sal_Bool ScColumn::GetDataEntries(SCROW nStartRow, TypedScStrCollection& rStrings, sal_Bool bLimit)
1572cdf0e10cSrcweir {
1573cdf0e10cSrcweir 	sal_Bool bFound = sal_False;
1574cdf0e10cSrcweir 	SCSIZE nThisIndex;
1575cdf0e10cSrcweir 	sal_Bool bThisUsed = Search( nStartRow, nThisIndex );
1576cdf0e10cSrcweir 	String aString;
1577cdf0e10cSrcweir 	sal_uInt16 nCells = 0;
1578cdf0e10cSrcweir 
1579cdf0e10cSrcweir 	//	Die Beschraenkung auf angrenzende Zellen (ohne Luecken) ist nicht mehr gewollt
1580cdf0e10cSrcweir 	//	(Featurekommission zur 5.1), stattdessen abwechselnd nach oben und unten suchen,
1581cdf0e10cSrcweir 	//	damit naheliegende Zellen wenigstens zuerst gefunden werden.
1582cdf0e10cSrcweir 	//!	Abstaende der Zeilennummern vergleichen? (Performance??)
1583cdf0e10cSrcweir 
1584cdf0e10cSrcweir 	SCSIZE nUpIndex = nThisIndex;		// zeigt hinter die Zelle
1585cdf0e10cSrcweir 	SCSIZE nDownIndex = nThisIndex;		// zeigt auf die Zelle
1586cdf0e10cSrcweir 	if (bThisUsed)
1587cdf0e10cSrcweir 		++nDownIndex;					// Startzelle ueberspringen
1588cdf0e10cSrcweir 
1589cdf0e10cSrcweir 	while ( nUpIndex || nDownIndex < nCount )
1590cdf0e10cSrcweir 	{
1591cdf0e10cSrcweir 		if ( nUpIndex )					// nach oben
1592cdf0e10cSrcweir 		{
1593cdf0e10cSrcweir 			ScBaseCell* pCell = pItems[nUpIndex-1].pCell;
1594cdf0e10cSrcweir 			CellType eType = pCell->GetCellType();
1595cdf0e10cSrcweir 			if (eType == CELLTYPE_STRING || eType == CELLTYPE_EDIT)		// nur Strings interessieren
1596cdf0e10cSrcweir 			{
1597cdf0e10cSrcweir 				if (eType == CELLTYPE_STRING)
1598cdf0e10cSrcweir 					((ScStringCell*)pCell)->GetString(aString);
1599cdf0e10cSrcweir 				else
1600cdf0e10cSrcweir 					((ScEditCell*)pCell)->GetString(aString);
1601cdf0e10cSrcweir 
1602cdf0e10cSrcweir 				TypedStrData* pData = new TypedStrData(aString);
1603cdf0e10cSrcweir 				if ( !rStrings.Insert( pData ) )
1604cdf0e10cSrcweir 					delete pData;											// doppelt
1605cdf0e10cSrcweir 				else if ( bLimit && rStrings.GetCount() >= DATENT_MAX )
1606cdf0e10cSrcweir 					break;													// Maximum erreicht
1607cdf0e10cSrcweir 				bFound = sal_True;
1608cdf0e10cSrcweir 
1609cdf0e10cSrcweir 				if ( bLimit )
1610cdf0e10cSrcweir 					if (++nCells >= DATENT_SEARCH)
1611cdf0e10cSrcweir 						break;									// genug gesucht
1612cdf0e10cSrcweir 			}
1613cdf0e10cSrcweir 			--nUpIndex;
1614cdf0e10cSrcweir 		}
1615cdf0e10cSrcweir 
1616cdf0e10cSrcweir 		if ( nDownIndex < nCount )		// nach unten
1617cdf0e10cSrcweir 		{
1618cdf0e10cSrcweir 			ScBaseCell* pCell = pItems[nDownIndex].pCell;
1619cdf0e10cSrcweir 			CellType eType = pCell->GetCellType();
1620cdf0e10cSrcweir 			if (eType == CELLTYPE_STRING || eType == CELLTYPE_EDIT)		// nur Strings interessieren
1621cdf0e10cSrcweir 			{
1622cdf0e10cSrcweir 				if (eType == CELLTYPE_STRING)
1623cdf0e10cSrcweir 					((ScStringCell*)pCell)->GetString(aString);
1624cdf0e10cSrcweir 				else
1625cdf0e10cSrcweir 					((ScEditCell*)pCell)->GetString(aString);
1626cdf0e10cSrcweir 
1627cdf0e10cSrcweir 				TypedStrData* pData = new TypedStrData(aString);
1628cdf0e10cSrcweir 				if ( !rStrings.Insert( pData ) )
1629cdf0e10cSrcweir 					delete pData;											// doppelt
1630cdf0e10cSrcweir 				else if ( bLimit && rStrings.GetCount() >= DATENT_MAX )
1631cdf0e10cSrcweir 					break;													// Maximum erreicht
1632cdf0e10cSrcweir 				bFound = sal_True;
1633cdf0e10cSrcweir 
1634cdf0e10cSrcweir 				if ( bLimit )
1635cdf0e10cSrcweir 					if (++nCells >= DATENT_SEARCH)
1636cdf0e10cSrcweir 						break;									// genug gesucht
1637cdf0e10cSrcweir 			}
1638cdf0e10cSrcweir 			++nDownIndex;
1639cdf0e10cSrcweir 		}
1640cdf0e10cSrcweir 	}
1641cdf0e10cSrcweir 
1642cdf0e10cSrcweir 	return bFound;
1643cdf0e10cSrcweir }
1644cdf0e10cSrcweir 
1645cdf0e10cSrcweir #undef DATENT_MAX
1646cdf0e10cSrcweir #undef DATENT_SEARCH
1647cdf0e10cSrcweir 
1648cdf0e10cSrcweir 
RemoveProtected(SCROW nStartRow,SCROW nEndRow)1649cdf0e10cSrcweir void ScColumn::RemoveProtected( SCROW nStartRow, SCROW nEndRow )
1650cdf0e10cSrcweir {
1651cdf0e10cSrcweir 	ScAttrIterator aAttrIter( pAttrArray, nStartRow, nEndRow );
1652cdf0e10cSrcweir 	SCROW nTop = -1;
1653cdf0e10cSrcweir 	SCROW nBottom = -1;
1654cdf0e10cSrcweir 	SCSIZE nIndex;
1655cdf0e10cSrcweir 	const ScPatternAttr* pPattern = aAttrIter.Next( nTop, nBottom );
1656cdf0e10cSrcweir 	while (pPattern)
1657cdf0e10cSrcweir 	{
1658cdf0e10cSrcweir 		const ScProtectionAttr* pAttr = (const ScProtectionAttr*)&pPattern->GetItem(ATTR_PROTECTION);
1659cdf0e10cSrcweir 		if ( pAttr->GetHideCell() )
1660cdf0e10cSrcweir 			DeleteArea( nTop, nBottom, IDF_CONTENTS );
1661cdf0e10cSrcweir 		else if ( pAttr->GetHideFormula() )
1662cdf0e10cSrcweir 		{
1663cdf0e10cSrcweir 			Search( nTop, nIndex );
1664cdf0e10cSrcweir 			while ( nIndex<nCount && pItems[nIndex].nRow<=nBottom )
1665cdf0e10cSrcweir 			{
1666cdf0e10cSrcweir 				if ( pItems[nIndex].pCell->GetCellType() == CELLTYPE_FORMULA )
1667cdf0e10cSrcweir 				{
1668cdf0e10cSrcweir 					ScFormulaCell* pFormula = (ScFormulaCell*)pItems[nIndex].pCell;
1669cdf0e10cSrcweir 					if (pFormula->IsValue())
1670cdf0e10cSrcweir 					{
1671cdf0e10cSrcweir 						double nVal = pFormula->GetValue();
1672cdf0e10cSrcweir 						pItems[nIndex].pCell = new ScValueCell( nVal );
1673cdf0e10cSrcweir 					}
1674cdf0e10cSrcweir 					else
1675cdf0e10cSrcweir 					{
1676cdf0e10cSrcweir 						String aString;
1677cdf0e10cSrcweir 						pFormula->GetString(aString);
1678cdf0e10cSrcweir 						pItems[nIndex].pCell = new ScStringCell( aString );
1679cdf0e10cSrcweir 					}
1680cdf0e10cSrcweir 					delete pFormula;
1681cdf0e10cSrcweir 				}
1682cdf0e10cSrcweir 				++nIndex;
1683cdf0e10cSrcweir 			}
1684cdf0e10cSrcweir 		}
1685cdf0e10cSrcweir 
1686cdf0e10cSrcweir 		pPattern = aAttrIter.Next( nTop, nBottom );
1687cdf0e10cSrcweir 	}
1688cdf0e10cSrcweir }
1689cdf0e10cSrcweir 
1690cdf0e10cSrcweir 
SetError(SCROW nRow,const sal_uInt16 nError)1691cdf0e10cSrcweir void ScColumn::SetError( SCROW nRow, const sal_uInt16 nError)
1692cdf0e10cSrcweir {
1693cdf0e10cSrcweir 	if (VALIDROW(nRow))
1694cdf0e10cSrcweir 	{
1695cdf0e10cSrcweir 		ScFormulaCell* pCell = new ScFormulaCell
1696cdf0e10cSrcweir 			( pDocument, ScAddress( nCol, nRow, nTab ) );
1697cdf0e10cSrcweir 		pCell->SetErrCode( nError );
1698cdf0e10cSrcweir 		Insert( nRow, pCell );
1699cdf0e10cSrcweir 	}
1700cdf0e10cSrcweir }
1701cdf0e10cSrcweir 
1702cdf0e10cSrcweir 
SetValue(SCROW nRow,const double & rVal)1703cdf0e10cSrcweir void ScColumn::SetValue( SCROW nRow, const double& rVal)
1704cdf0e10cSrcweir {
1705cdf0e10cSrcweir 	if (VALIDROW(nRow))
1706cdf0e10cSrcweir 	{
1707cdf0e10cSrcweir 		ScBaseCell* pCell = new ScValueCell(rVal);
1708cdf0e10cSrcweir 		Insert( nRow, pCell );
1709cdf0e10cSrcweir 	}
1710cdf0e10cSrcweir }
1711cdf0e10cSrcweir 
1712cdf0e10cSrcweir 
GetString(SCROW nRow,String & rString) const1713cdf0e10cSrcweir void ScColumn::GetString( SCROW nRow, String& rString ) const
1714cdf0e10cSrcweir {
1715cdf0e10cSrcweir 	SCSIZE	nIndex;
1716cdf0e10cSrcweir 	Color* pColor;
1717cdf0e10cSrcweir 	if (Search(nRow, nIndex))
1718cdf0e10cSrcweir 	{
1719cdf0e10cSrcweir 		ScBaseCell* pCell = pItems[nIndex].pCell;
1720cdf0e10cSrcweir 		if (pCell->GetCellType() != CELLTYPE_NOTE)
1721cdf0e10cSrcweir 		{
1722cdf0e10cSrcweir 			sal_uLong nFormat = GetNumberFormat( nRow );
1723cdf0e10cSrcweir 			ScCellFormat::GetString( pCell, nFormat, rString, &pColor, *(pDocument->GetFormatTable()) );
1724cdf0e10cSrcweir 		}
1725cdf0e10cSrcweir 		else
1726cdf0e10cSrcweir 			rString.Erase();
1727cdf0e10cSrcweir 	}
1728cdf0e10cSrcweir 	else
1729cdf0e10cSrcweir 		rString.Erase();
1730cdf0e10cSrcweir }
1731cdf0e10cSrcweir 
1732b4df81e3SWang Lei template<>
FillDPCacheT(long nDim,SCROW nStartRow,SCROW nEndRow,const boost::function<void (ScDPItemData *)> & rAddLabel,const boost::function<sal_Bool (long,ScDPItemData *,bool)> & rAddData)1733*7a6646f1SWang Lei void  ScColumn::FillDPCacheT( long nDim, SCROW nStartRow, SCROW nEndRow, const boost::function<void(ScDPItemData*)> & rAddLabel, const boost::function<sal_Bool(long,ScDPItemData*, bool)> & rAddData )
1734b4df81e3SWang Lei {
1735b4df81e3SWang Lei     SCROW nPattenRowStart = -1, nPatternRowEnd = -1;
1736b4df81e3SWang Lei     SvNumberFormatter* pFormatter = pDocument->GetFormatTable();
1737b4df81e3SWang Lei     sal_uLong nNumberFormat = 0;
1738b4df81e3SWang Lei     sal_uLong nNumberFormatType = NUMBERFORMAT_NUMBER;
1739b4df81e3SWang Lei     SCROW nCurRow = nStartRow;
1740b4df81e3SWang Lei     ScDPItemData * pDPItemData = NULL;
1741b4df81e3SWang Lei 
1742b4df81e3SWang Lei     if ( pItems )
1743b4df81e3SWang Lei     {
1744b4df81e3SWang Lei         SCSIZE nIndex;
1745b4df81e3SWang Lei 
1746b4df81e3SWang Lei         for ( Search( nStartRow, nIndex ) ? void( ) : void(nIndex = nCount); nIndex < nCount && pItems[nIndex].nRow <= nEndRow; ++nIndex, ++nCurRow )
1747b4df81e3SWang Lei         {
1748b4df81e3SWang Lei             for( ; nCurRow < pItems[nIndex].nRow; nCurRow++ )
1749b4df81e3SWang Lei                 if( nCurRow == nStartRow )
1750b4df81e3SWang Lei                     rAddLabel( new ScDPItemData() );
1751b4df81e3SWang Lei                 else
1752*7a6646f1SWang Lei                     rAddData( nDim, new ScDPItemData(), false);
1753b4df81e3SWang Lei 
1754b4df81e3SWang Lei             if( nCurRow > nPatternRowEnd )
1755b4df81e3SWang Lei                 if( const ScPatternAttr* pPattern = pAttrArray ? pAttrArray->GetPatternRange( nPattenRowStart, nPatternRowEnd, nCurRow ) : NULL )
1756b4df81e3SWang Lei                     nNumberFormatType = pFormatter->GetType( nNumberFormat = pPattern->GetNumberFormat( pFormatter ) );
1757b4df81e3SWang Lei                 else
1758b4df81e3SWang Lei                     nNumberFormatType = NUMBERFORMAT_NUMBER, nNumberFormat = 0;
1759b4df81e3SWang Lei 
1760b4df81e3SWang Lei             if( ScBaseCell* pCell = pItems[nIndex].pCell )
1761b4df81e3SWang Lei                 if( pCell->GetCellType() == CELLTYPE_FORMULA && ((ScFormulaCell*)pCell)->GetErrCode() )
1762b4df81e3SWang Lei 		{
1763b4df81e3SWang Lei 		    String str( GetStringFromCell( pCell, nNumberFormat, pFormatter ) );
1764b4df81e3SWang Lei 		    sal_uInt8 bFlag = ScDPItemData::MK_ERR;
1765b4df81e3SWang Lei                     pDPItemData = new ScDPItemData( 0, str, 0.0, bFlag );
1766b4df81e3SWang Lei 		}
1767b4df81e3SWang Lei                 else if( pCell->HasValueData() )
1768b4df81e3SWang Lei                 {
1769b4df81e3SWang Lei                     double fVal = GetValueFromCell( pCell );
1770b4df81e3SWang Lei                     String str( GetStringFromCell( pCell, nNumberFormat, pFormatter ) );
1771b4df81e3SWang Lei                     sal_uInt8 bFlag = ScDPItemData::MK_VAL|ScDPItemData::MK_DATA|(ScDPItemData::MK_DATE * isDateFormat( nNumberFormatType ));
1772b4df81e3SWang Lei                     pDPItemData = new ScDPItemData( nNumberFormat, str, fVal, bFlag );
1773b4df81e3SWang Lei                 }
1774b4df81e3SWang Lei                 else if( !pCell->IsBlank() )
1775b4df81e3SWang Lei                     pDPItemData = new ScDPItemData( GetStringFromCell( pCell, nNumberFormat, pFormatter ) );
1776b4df81e3SWang Lei                 else
1777b4df81e3SWang Lei                     pDPItemData = new ScDPItemData();
1778b4df81e3SWang Lei             else
1779b4df81e3SWang Lei                 pDPItemData = new ScDPItemData();
1780b4df81e3SWang Lei 
1781b4df81e3SWang Lei             if( nCurRow == nStartRow )
1782b4df81e3SWang Lei                 rAddLabel( pDPItemData );
1783b4df81e3SWang Lei             else
1784*7a6646f1SWang Lei                 rAddData( nDim, pDPItemData, false );
1785b4df81e3SWang Lei         }
1786b4df81e3SWang Lei     }
1787b4df81e3SWang Lei 
1788b4df81e3SWang Lei     for( ; nCurRow <= nEndRow; nCurRow++ )
1789b4df81e3SWang Lei         if( nCurRow == nStartRow )
1790b4df81e3SWang Lei             rAddLabel( new ScDPItemData() );
1791b4df81e3SWang Lei         else
1792*7a6646f1SWang Lei             rAddData( nDim, new ScDPItemData(), false );
1793b4df81e3SWang Lei }
FillDPCache(ScDPTableDataCache * pCache,long nDim,SCROW nStartRow,SCROW nEndRow)1794b4df81e3SWang Lei void  ScColumn::FillDPCache( ScDPTableDataCache * pCache, long nDim, SCROW nStartRow, SCROW nEndRow )
1795b4df81e3SWang Lei {
1796*7a6646f1SWang Lei     FillDPCacheT<boost::function<void(ScDPItemData*)>, boost::function<sal_Bool(long,ScDPItemData*, bool)> >( nDim, nStartRow, nEndRow, boost::bind( &ScDPTableDataCache::AddLabel, pCache, _1 ), boost::bind( &ScDPTableDataCache::AddData, pCache, _1, _2, _3 ) );
1797b4df81e3SWang Lei }
1798cdf0e10cSrcweir 
GetInputString(SCROW nRow,String & rString) const1799cdf0e10cSrcweir void ScColumn::GetInputString( SCROW nRow, String& rString ) const
1800cdf0e10cSrcweir {
1801cdf0e10cSrcweir 	SCSIZE	nIndex;
1802cdf0e10cSrcweir 	if (Search(nRow, nIndex))
1803cdf0e10cSrcweir 	{
1804cdf0e10cSrcweir 		ScBaseCell* pCell = pItems[nIndex].pCell;
1805cdf0e10cSrcweir 		if (pCell->GetCellType() != CELLTYPE_NOTE)
1806cdf0e10cSrcweir 		{
1807cdf0e10cSrcweir 			sal_uLong nFormat = GetNumberFormat( nRow );
1808cdf0e10cSrcweir 			ScCellFormat::GetInputString( pCell, nFormat, rString, *(pDocument->GetFormatTable()) );
1809cdf0e10cSrcweir 		}
1810cdf0e10cSrcweir 		else
1811cdf0e10cSrcweir 			rString.Erase();
1812cdf0e10cSrcweir 	}
1813cdf0e10cSrcweir 	else
1814cdf0e10cSrcweir 		rString.Erase();
1815cdf0e10cSrcweir }
1816cdf0e10cSrcweir 
1817cdf0e10cSrcweir 
GetValue(SCROW nRow) const1818cdf0e10cSrcweir double ScColumn::GetValue( SCROW nRow ) const
1819cdf0e10cSrcweir {
1820cdf0e10cSrcweir 	SCSIZE	nIndex;
1821cdf0e10cSrcweir 	if (Search(nRow, nIndex))
1822cdf0e10cSrcweir 	{
1823cdf0e10cSrcweir 		ScBaseCell* pCell = pItems[nIndex].pCell;
1824cdf0e10cSrcweir 		switch (pCell->GetCellType())
1825cdf0e10cSrcweir 		{
1826cdf0e10cSrcweir 			case CELLTYPE_VALUE:
1827cdf0e10cSrcweir 				return ((ScValueCell*)pCell)->GetValue();
1828cdf0e10cSrcweir //                break;
1829cdf0e10cSrcweir 			case CELLTYPE_FORMULA:
1830cdf0e10cSrcweir 				{
1831cdf0e10cSrcweir 					if (((ScFormulaCell*)pCell)->IsValue())
1832cdf0e10cSrcweir 						return ((ScFormulaCell*)pCell)->GetValue();
1833cdf0e10cSrcweir 					else
1834cdf0e10cSrcweir 						return 0.0;
1835cdf0e10cSrcweir 				}
1836cdf0e10cSrcweir //                break;
1837cdf0e10cSrcweir 			default:
1838cdf0e10cSrcweir 				return 0.0;
1839cdf0e10cSrcweir //                break;
1840cdf0e10cSrcweir 		}
1841cdf0e10cSrcweir 	}
1842cdf0e10cSrcweir 	return 0.0;
1843cdf0e10cSrcweir }
1844cdf0e10cSrcweir 
1845cdf0e10cSrcweir 
GetFormula(SCROW nRow,String & rFormula,sal_Bool) const1846cdf0e10cSrcweir void ScColumn::GetFormula( SCROW nRow, String& rFormula, sal_Bool ) const
1847cdf0e10cSrcweir {
1848cdf0e10cSrcweir 	SCSIZE	nIndex;
1849cdf0e10cSrcweir 	if (Search(nRow, nIndex))
1850cdf0e10cSrcweir 	{
1851cdf0e10cSrcweir 		ScBaseCell* pCell = pItems[nIndex].pCell;
1852cdf0e10cSrcweir 		if (pCell->GetCellType() == CELLTYPE_FORMULA)
1853cdf0e10cSrcweir 			((ScFormulaCell*)pCell)->GetFormula( rFormula );
1854cdf0e10cSrcweir 		else
1855cdf0e10cSrcweir 			rFormula.Erase();
1856cdf0e10cSrcweir 	}
1857cdf0e10cSrcweir 	else
1858cdf0e10cSrcweir 		rFormula.Erase();
1859cdf0e10cSrcweir }
1860cdf0e10cSrcweir 
1861cdf0e10cSrcweir 
GetCellType(SCROW nRow) const1862cdf0e10cSrcweir CellType ScColumn::GetCellType( SCROW nRow ) const
1863cdf0e10cSrcweir {
1864cdf0e10cSrcweir 	SCSIZE	nIndex;
1865cdf0e10cSrcweir 	if (Search(nRow, nIndex))
1866cdf0e10cSrcweir 		return pItems[nIndex].pCell->GetCellType();
1867cdf0e10cSrcweir 	return CELLTYPE_NONE;
1868cdf0e10cSrcweir }
1869cdf0e10cSrcweir 
1870cdf0e10cSrcweir 
GetErrCode(SCROW nRow) const1871cdf0e10cSrcweir sal_uInt16 ScColumn::GetErrCode( SCROW nRow ) const
1872cdf0e10cSrcweir {
1873cdf0e10cSrcweir 	SCSIZE	nIndex;
1874cdf0e10cSrcweir 	if (Search(nRow, nIndex))
1875cdf0e10cSrcweir 	{
1876cdf0e10cSrcweir 		ScBaseCell* pCell = pItems[nIndex].pCell;
1877cdf0e10cSrcweir 		if (pCell->GetCellType() == CELLTYPE_FORMULA)
1878cdf0e10cSrcweir 			return ((ScFormulaCell*)pCell)->GetErrCode();
1879cdf0e10cSrcweir 	}
1880cdf0e10cSrcweir 	return 0;
1881cdf0e10cSrcweir }
1882cdf0e10cSrcweir 
1883cdf0e10cSrcweir 
HasStringData(SCROW nRow) const1884cdf0e10cSrcweir sal_Bool ScColumn::HasStringData( SCROW nRow ) const
1885cdf0e10cSrcweir {
1886cdf0e10cSrcweir 	SCSIZE	nIndex;
1887cdf0e10cSrcweir 	if (Search(nRow, nIndex))
1888cdf0e10cSrcweir 		return (pItems[nIndex].pCell)->HasStringData();
1889cdf0e10cSrcweir 	return sal_False;
1890cdf0e10cSrcweir }
1891cdf0e10cSrcweir 
1892cdf0e10cSrcweir 
HasValueData(SCROW nRow) const1893cdf0e10cSrcweir sal_Bool ScColumn::HasValueData( SCROW nRow ) const
1894cdf0e10cSrcweir {
1895cdf0e10cSrcweir 	SCSIZE	nIndex;
1896cdf0e10cSrcweir 	if (Search(nRow, nIndex))
1897cdf0e10cSrcweir 		return (pItems[nIndex].pCell)->HasValueData();
1898cdf0e10cSrcweir 	return sal_False;
1899cdf0e10cSrcweir }
1900cdf0e10cSrcweir 
HasStringCells(SCROW nStartRow,SCROW nEndRow) const1901cdf0e10cSrcweir sal_Bool ScColumn::HasStringCells( SCROW nStartRow, SCROW nEndRow ) const
1902cdf0e10cSrcweir {
1903cdf0e10cSrcweir 	//	sal_True, wenn String- oder Editzellen im Bereich
1904cdf0e10cSrcweir 
1905cdf0e10cSrcweir 	if ( pItems )
1906cdf0e10cSrcweir 	{
1907cdf0e10cSrcweir 		SCSIZE nIndex;
1908cdf0e10cSrcweir 		Search( nStartRow, nIndex );
1909cdf0e10cSrcweir 		while ( nIndex < nCount && pItems[nIndex].nRow <= nEndRow )
1910cdf0e10cSrcweir 		{
1911cdf0e10cSrcweir 			CellType eType = pItems[nIndex].pCell->GetCellType();
1912cdf0e10cSrcweir 			if ( eType == CELLTYPE_STRING || eType == CELLTYPE_EDIT )
1913cdf0e10cSrcweir 				return sal_True;
1914cdf0e10cSrcweir 			++nIndex;
1915cdf0e10cSrcweir 		}
1916cdf0e10cSrcweir 	}
1917cdf0e10cSrcweir 	return sal_False;
1918cdf0e10cSrcweir }
1919cdf0e10cSrcweir 
1920cdf0e10cSrcweir 
GetNote(SCROW nRow)1921cdf0e10cSrcweir ScPostIt* ScColumn::GetNote( SCROW nRow )
1922cdf0e10cSrcweir {
1923cdf0e10cSrcweir 	SCSIZE nIndex;
1924cdf0e10cSrcweir 	return Search( nRow, nIndex ) ? pItems[ nIndex ].pCell->GetNote() : 0;
1925cdf0e10cSrcweir }
1926cdf0e10cSrcweir 
1927cdf0e10cSrcweir 
TakeNote(SCROW nRow,ScPostIt * pNote)1928cdf0e10cSrcweir void ScColumn::TakeNote( SCROW nRow, ScPostIt* pNote )
1929cdf0e10cSrcweir {
1930cdf0e10cSrcweir 	SCSIZE nIndex;
1931cdf0e10cSrcweir 	if( Search( nRow, nIndex ) )
1932cdf0e10cSrcweir 		pItems[ nIndex ].pCell->TakeNote( pNote );
1933cdf0e10cSrcweir     else
1934cdf0e10cSrcweir         Insert( nRow, new ScNoteCell( pNote ) );
1935cdf0e10cSrcweir }
1936cdf0e10cSrcweir 
1937cdf0e10cSrcweir 
ReleaseNote(SCROW nRow)1938cdf0e10cSrcweir ScPostIt* ScColumn::ReleaseNote( SCROW nRow )
1939cdf0e10cSrcweir {
1940cdf0e10cSrcweir     ScPostIt* pNote = 0;
1941cdf0e10cSrcweir 	SCSIZE nIndex;
1942cdf0e10cSrcweir 	if( Search( nRow, nIndex ) )
1943cdf0e10cSrcweir 	{
1944cdf0e10cSrcweir 		ScBaseCell* pCell = pItems[ nIndex ].pCell;
1945cdf0e10cSrcweir         pNote = pCell->ReleaseNote();
1946cdf0e10cSrcweir 		if( (pCell->GetCellType() == CELLTYPE_NOTE) && !pCell->GetBroadcaster() )
1947cdf0e10cSrcweir 			DeleteAtIndex( nIndex );
1948cdf0e10cSrcweir 	}
1949cdf0e10cSrcweir     return pNote;
1950cdf0e10cSrcweir }
1951cdf0e10cSrcweir 
1952cdf0e10cSrcweir 
DeleteNote(SCROW nRow)1953cdf0e10cSrcweir void ScColumn::DeleteNote( SCROW nRow )
1954cdf0e10cSrcweir {
1955cdf0e10cSrcweir     delete ReleaseNote( nRow );
1956cdf0e10cSrcweir }
1957cdf0e10cSrcweir 
1958cdf0e10cSrcweir 
GetMaxStringLen(SCROW nRowStart,SCROW nRowEnd,CharSet eCharSet) const1959cdf0e10cSrcweir sal_Int32 ScColumn::GetMaxStringLen( SCROW nRowStart, SCROW nRowEnd, CharSet eCharSet ) const
1960cdf0e10cSrcweir {
1961cdf0e10cSrcweir 	sal_Int32 nStringLen = 0;
1962cdf0e10cSrcweir 	if ( pItems )
1963cdf0e10cSrcweir 	{
1964cdf0e10cSrcweir 		String aString;
1965cdf0e10cSrcweir         rtl::OString aOString;
1966cdf0e10cSrcweir         bool bIsOctetTextEncoding = rtl_isOctetTextEncoding( eCharSet);
1967cdf0e10cSrcweir 		SvNumberFormatter* pNumFmt = pDocument->GetFormatTable();
1968cdf0e10cSrcweir         SCSIZE nIndex;
1969cdf0e10cSrcweir         SCROW nRow;
1970cdf0e10cSrcweir 		Search( nRowStart, nIndex );
1971cdf0e10cSrcweir 		while ( nIndex < nCount && (nRow = pItems[nIndex].nRow) <= nRowEnd )
1972cdf0e10cSrcweir 		{
1973cdf0e10cSrcweir 			ScBaseCell* pCell = pItems[nIndex].pCell;
1974cdf0e10cSrcweir 			if ( pCell->GetCellType() != CELLTYPE_NOTE )
1975cdf0e10cSrcweir 			{
1976cdf0e10cSrcweir 				Color* pColor;
1977cdf0e10cSrcweir 				sal_uLong nFormat = (sal_uLong) ((SfxUInt32Item*) GetAttr(
1978cdf0e10cSrcweir 					nRow, ATTR_VALUE_FORMAT ))->GetValue();
1979cdf0e10cSrcweir 				ScCellFormat::GetString( pCell, nFormat, aString, &pColor,
1980cdf0e10cSrcweir 					*pNumFmt );
1981cdf0e10cSrcweir                 sal_Int32 nLen;
1982cdf0e10cSrcweir                 if (bIsOctetTextEncoding)
1983cdf0e10cSrcweir                 {
1984cdf0e10cSrcweir                     rtl::OUString aOUString( aString);
1985cdf0e10cSrcweir                     if (!aOUString.convertToString( &aOString, eCharSet,
1986cdf0e10cSrcweir                                 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
1987cdf0e10cSrcweir                                 RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR))
1988cdf0e10cSrcweir                     {
1989cdf0e10cSrcweir                         // TODO: anything? this is used by the dBase export filter
1990cdf0e10cSrcweir                         // that throws an error anyway, but in case of another
1991cdf0e10cSrcweir                         // context we might want to indicate a conversion error
1992cdf0e10cSrcweir                         // early.
1993cdf0e10cSrcweir                     }
1994cdf0e10cSrcweir                     nLen = aOString.getLength();
1995cdf0e10cSrcweir                 }
1996cdf0e10cSrcweir                 else
1997cdf0e10cSrcweir                     nLen = aString.Len() * sizeof(sal_Unicode);
1998cdf0e10cSrcweir 				if ( nStringLen < nLen)
1999cdf0e10cSrcweir 					nStringLen = nLen;
2000cdf0e10cSrcweir 			}
2001cdf0e10cSrcweir 			nIndex++;
2002cdf0e10cSrcweir 		}
2003cdf0e10cSrcweir 	}
2004cdf0e10cSrcweir 	return nStringLen;
2005cdf0e10cSrcweir }
2006cdf0e10cSrcweir 
2007cdf0e10cSrcweir 
GetMaxNumberStringLen(sal_uInt16 & nPrecision,SCROW nRowStart,SCROW nRowEnd) const2008cdf0e10cSrcweir xub_StrLen ScColumn::GetMaxNumberStringLen(
2009cdf0e10cSrcweir     sal_uInt16& nPrecision, SCROW nRowStart, SCROW nRowEnd ) const
2010cdf0e10cSrcweir {
2011cdf0e10cSrcweir     xub_StrLen nStringLen = 0;
2012cdf0e10cSrcweir     nPrecision = pDocument->GetDocOptions().GetStdPrecision();
2013cdf0e10cSrcweir     if ( nPrecision == SvNumberFormatter::UNLIMITED_PRECISION )
2014cdf0e10cSrcweir         // In case of unlimited precision, use 2 instead.
2015cdf0e10cSrcweir         nPrecision = 2;
2016cdf0e10cSrcweir 
2017cdf0e10cSrcweir     if ( pItems )
2018cdf0e10cSrcweir     {
2019cdf0e10cSrcweir         String aString;
2020cdf0e10cSrcweir         SvNumberFormatter* pNumFmt = pDocument->GetFormatTable();
2021cdf0e10cSrcweir         SCSIZE nIndex;
2022cdf0e10cSrcweir         SCROW nRow;
2023cdf0e10cSrcweir         Search( nRowStart, nIndex );
2024cdf0e10cSrcweir         while ( nIndex < nCount && (nRow = pItems[nIndex].nRow) <= nRowEnd )
2025cdf0e10cSrcweir         {
2026cdf0e10cSrcweir             ScBaseCell* pCell = pItems[nIndex].pCell;
2027cdf0e10cSrcweir             CellType eType = pCell->GetCellType();
2028cdf0e10cSrcweir             if ( eType == CELLTYPE_VALUE || (eType == CELLTYPE_FORMULA
2029cdf0e10cSrcweir                     && ((ScFormulaCell*)pCell)->IsValue()) )
2030cdf0e10cSrcweir             {
2031cdf0e10cSrcweir                 sal_uLong nFormat = (sal_uLong) ((SfxUInt32Item*) GetAttr(
2032cdf0e10cSrcweir                     nRow, ATTR_VALUE_FORMAT ))->GetValue();
2033cdf0e10cSrcweir                 ScCellFormat::GetInputString( pCell, nFormat, aString, *pNumFmt );
2034cdf0e10cSrcweir                 xub_StrLen nLen = aString.Len();
2035cdf0e10cSrcweir                 if ( nLen )
2036cdf0e10cSrcweir                 {
2037cdf0e10cSrcweir                     if ( nFormat )
2038cdf0e10cSrcweir                     {   // more decimals than standard?
2039cdf0e10cSrcweir                         sal_uInt16 nPrec = pNumFmt->GetFormatPrecision( nFormat );
2040cdf0e10cSrcweir                         if ( nPrec != SvNumberFormatter::UNLIMITED_PRECISION && nPrec > nPrecision )
2041cdf0e10cSrcweir                             nPrecision = nPrec;
2042cdf0e10cSrcweir                     }
2043cdf0e10cSrcweir                     if ( nPrecision )
2044cdf0e10cSrcweir                     {   // less than nPrecision in string => widen it
2045cdf0e10cSrcweir                         // more => shorten it
2046cdf0e10cSrcweir                         String aSep = pNumFmt->GetFormatDecimalSep( nFormat );
2047cdf0e10cSrcweir                         xub_StrLen nTmp = aString.Search( aSep );
2048cdf0e10cSrcweir                         if ( nTmp == STRING_NOTFOUND )
2049cdf0e10cSrcweir                             nLen += nPrecision + aSep.Len();
2050cdf0e10cSrcweir                         else
2051cdf0e10cSrcweir                         {
2052cdf0e10cSrcweir                             nTmp = aString.Len() - (nTmp + aSep.Len());
2053cdf0e10cSrcweir                             if ( nTmp != nPrecision )
2054cdf0e10cSrcweir                                 nLen += nPrecision - nTmp;
2055cdf0e10cSrcweir                                 // nPrecision > nTmp : nLen + Diff
2056cdf0e10cSrcweir                                 // nPrecision < nTmp : nLen - Diff
2057cdf0e10cSrcweir                         }
2058cdf0e10cSrcweir                     }
2059cdf0e10cSrcweir                     if ( nStringLen < nLen )
2060cdf0e10cSrcweir                         nStringLen = nLen;
2061cdf0e10cSrcweir                 }
2062cdf0e10cSrcweir             }
2063cdf0e10cSrcweir             nIndex++;
2064cdf0e10cSrcweir         }
2065cdf0e10cSrcweir     }
2066cdf0e10cSrcweir     return nStringLen;
2067cdf0e10cSrcweir }
2068cdf0e10cSrcweir 
2069