1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*b3f79822SAndrew Rist * distributed with this work for additional information
6*b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10*b3f79822SAndrew Rist *
11*b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist *
13*b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17*b3f79822SAndrew Rist * specific language governing permissions and limitations
18*b3f79822SAndrew Rist * under the License.
19*b3f79822SAndrew Rist *
20*b3f79822SAndrew Rist *************************************************************/
21*b3f79822SAndrew Rist
22*b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include <string.h>
30cdf0e10cSrcweir #include <tools/stream.hxx>
31cdf0e10cSrcweir #include <unotools/transliterationwrapper.hxx>
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include "rechead.hxx"
34cdf0e10cSrcweir #include "collect.hxx"
35cdf0e10cSrcweir #include "document.hxx" // fuer TypedStrData Konstruktor
36cdf0e10cSrcweir
37cdf0e10cSrcweir // -----------------------------------------------------------------------
38cdf0e10cSrcweir
~ScDataObject()39cdf0e10cSrcweir ScDataObject::~ScDataObject()
40cdf0e10cSrcweir {
41cdf0e10cSrcweir }
42cdf0e10cSrcweir
43cdf0e10cSrcweir //------------------------------------------------------------------------
44cdf0e10cSrcweir // Collection
45cdf0e10cSrcweir //------------------------------------------------------------------------
46cdf0e10cSrcweir
lcl_DeleteScDataObjects(ScDataObject ** p,sal_uInt16 nCount)47cdf0e10cSrcweir void lcl_DeleteScDataObjects( ScDataObject** p, sal_uInt16 nCount )
48cdf0e10cSrcweir {
49cdf0e10cSrcweir if ( p )
50cdf0e10cSrcweir {
51cdf0e10cSrcweir for (sal_uInt16 i = 0; i < nCount; i++) delete p[i];
52cdf0e10cSrcweir delete[] p;
53cdf0e10cSrcweir p = NULL;
54cdf0e10cSrcweir }
55cdf0e10cSrcweir }
56cdf0e10cSrcweir
ScCollection(sal_uInt16 nLim,sal_uInt16 nDel)57cdf0e10cSrcweir ScCollection::ScCollection(sal_uInt16 nLim, sal_uInt16 nDel) :
58cdf0e10cSrcweir nCount ( 0 ),
59cdf0e10cSrcweir nLimit ( nLim ),
60cdf0e10cSrcweir nDelta ( nDel ),
61cdf0e10cSrcweir pItems ( NULL )
62cdf0e10cSrcweir {
63cdf0e10cSrcweir if (nDelta > MAXDELTA)
64cdf0e10cSrcweir nDelta = MAXDELTA;
65cdf0e10cSrcweir else if (nDelta == 0)
66cdf0e10cSrcweir nDelta = 1;
67cdf0e10cSrcweir if (nLimit > MAXCOLLECTIONSIZE)
68cdf0e10cSrcweir nLimit = MAXCOLLECTIONSIZE;
69cdf0e10cSrcweir else if (nLimit < nDelta)
70cdf0e10cSrcweir nLimit = nDelta;
71cdf0e10cSrcweir pItems = new ScDataObject*[nLimit];
72cdf0e10cSrcweir }
73cdf0e10cSrcweir
ScCollection(const ScCollection & rCollection)74cdf0e10cSrcweir ScCollection::ScCollection(const ScCollection& rCollection)
75cdf0e10cSrcweir : ScDataObject(),
76cdf0e10cSrcweir nCount ( 0 ),
77cdf0e10cSrcweir nLimit ( 0 ),
78cdf0e10cSrcweir nDelta ( 0 ),
79cdf0e10cSrcweir pItems ( NULL )
80cdf0e10cSrcweir {
81cdf0e10cSrcweir *this = rCollection;
82cdf0e10cSrcweir }
83cdf0e10cSrcweir
84cdf0e10cSrcweir //------------------------------------------------------------------------
85cdf0e10cSrcweir
~ScCollection()86cdf0e10cSrcweir ScCollection::~ScCollection()
87cdf0e10cSrcweir {
88cdf0e10cSrcweir lcl_DeleteScDataObjects( pItems, nCount );
89cdf0e10cSrcweir }
90cdf0e10cSrcweir
91cdf0e10cSrcweir //------------------------------------------------------------------------
GetCount() const92cdf0e10cSrcweir sal_uInt16 ScCollection::GetCount() const { return nCount; }
AtFree(sal_uInt16 nIndex)93cdf0e10cSrcweir void ScCollection::AtFree(sal_uInt16 nIndex)
94cdf0e10cSrcweir {
95cdf0e10cSrcweir if ((pItems) && (nIndex < nCount))
96cdf0e10cSrcweir {
97cdf0e10cSrcweir delete pItems[nIndex];
98cdf0e10cSrcweir --nCount; // before memmove
99cdf0e10cSrcweir memmove ( &pItems[nIndex], &pItems[nIndex + 1], (nCount - nIndex) * sizeof(ScDataObject*));
100cdf0e10cSrcweir pItems[nCount] = NULL;
101cdf0e10cSrcweir }
102cdf0e10cSrcweir }
103cdf0e10cSrcweir
104cdf0e10cSrcweir //------------------------------------------------------------------------
105cdf0e10cSrcweir
Free(ScDataObject * pScDataObject)106cdf0e10cSrcweir void ScCollection::Free(ScDataObject* pScDataObject)
107cdf0e10cSrcweir {
108cdf0e10cSrcweir AtFree(IndexOf(pScDataObject));
109cdf0e10cSrcweir }
110cdf0e10cSrcweir
111cdf0e10cSrcweir //------------------------------------------------------------------------
112cdf0e10cSrcweir
FreeAll()113cdf0e10cSrcweir void ScCollection::FreeAll()
114cdf0e10cSrcweir {
115cdf0e10cSrcweir lcl_DeleteScDataObjects( pItems, nCount );
116cdf0e10cSrcweir nCount = 0;
117cdf0e10cSrcweir pItems = new ScDataObject*[nLimit];
118cdf0e10cSrcweir }
119cdf0e10cSrcweir
120cdf0e10cSrcweir //------------------------------------------------------------------------
121cdf0e10cSrcweir
AtInsert(sal_uInt16 nIndex,ScDataObject * pScDataObject)122cdf0e10cSrcweir sal_Bool ScCollection::AtInsert(sal_uInt16 nIndex, ScDataObject* pScDataObject)
123cdf0e10cSrcweir {
124cdf0e10cSrcweir if ((nCount < MAXCOLLECTIONSIZE) && (nIndex <= nCount) && pItems)
125cdf0e10cSrcweir {
126cdf0e10cSrcweir if (nCount == nLimit)
127cdf0e10cSrcweir {
128cdf0e10cSrcweir ScDataObject** pNewItems = new ScDataObject*[nLimit + nDelta];
129cdf0e10cSrcweir if (!pNewItems)
130cdf0e10cSrcweir return sal_False;
131cdf0e10cSrcweir nLimit = sal::static_int_cast<sal_uInt16>( nLimit + nDelta );
132cdf0e10cSrcweir memmove(pNewItems, pItems, nCount * sizeof(ScDataObject*));
133cdf0e10cSrcweir delete[] pItems;
134cdf0e10cSrcweir pItems = pNewItems;
135cdf0e10cSrcweir }
136cdf0e10cSrcweir if (nCount > nIndex)
137cdf0e10cSrcweir memmove(&pItems[nIndex + 1], &pItems[nIndex], (nCount - nIndex) * sizeof(ScDataObject*));
138cdf0e10cSrcweir pItems[nIndex] = pScDataObject;
139cdf0e10cSrcweir nCount++;
140cdf0e10cSrcweir return sal_True;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir return sal_False;
143cdf0e10cSrcweir }
144cdf0e10cSrcweir
145cdf0e10cSrcweir //------------------------------------------------------------------------
146cdf0e10cSrcweir
Insert(ScDataObject * pScDataObject)147cdf0e10cSrcweir sal_Bool ScCollection::Insert(ScDataObject* pScDataObject)
148cdf0e10cSrcweir {
149cdf0e10cSrcweir return AtInsert(nCount, pScDataObject);
150cdf0e10cSrcweir }
151cdf0e10cSrcweir
152cdf0e10cSrcweir //------------------------------------------------------------------------
153cdf0e10cSrcweir
At(sal_uInt16 nIndex) const154cdf0e10cSrcweir ScDataObject* ScCollection::At(sal_uInt16 nIndex) const
155cdf0e10cSrcweir {
156cdf0e10cSrcweir if (nIndex < nCount)
157cdf0e10cSrcweir return pItems[nIndex];
158cdf0e10cSrcweir else
159cdf0e10cSrcweir return NULL;
160cdf0e10cSrcweir }
161cdf0e10cSrcweir
162cdf0e10cSrcweir //------------------------------------------------------------------------
163cdf0e10cSrcweir
IndexOf(ScDataObject * pScDataObject) const164cdf0e10cSrcweir sal_uInt16 ScCollection::IndexOf(ScDataObject* pScDataObject) const
165cdf0e10cSrcweir {
166cdf0e10cSrcweir sal_uInt16 nIndex = 0xffff;
167cdf0e10cSrcweir for (sal_uInt16 i = 0; ((i < nCount) && (nIndex == 0xffff)); i++)
168cdf0e10cSrcweir {
169cdf0e10cSrcweir if (pItems[i] == pScDataObject) nIndex = i;
170cdf0e10cSrcweir }
171cdf0e10cSrcweir return nIndex;
172cdf0e10cSrcweir }
173cdf0e10cSrcweir
174cdf0e10cSrcweir //------------------------------------------------------------------------
175cdf0e10cSrcweir
operator =(const ScCollection & r)176cdf0e10cSrcweir ScCollection& ScCollection::operator=( const ScCollection& r )
177cdf0e10cSrcweir {
178cdf0e10cSrcweir lcl_DeleteScDataObjects( pItems, nCount );
179cdf0e10cSrcweir
180cdf0e10cSrcweir nCount = r.nCount;
181cdf0e10cSrcweir nLimit = r.nLimit;
182cdf0e10cSrcweir nDelta = r.nDelta;
183cdf0e10cSrcweir pItems = new ScDataObject*[nLimit];
184cdf0e10cSrcweir for ( sal_uInt16 i=0; i<nCount; i++ )
185cdf0e10cSrcweir pItems[i] = r.pItems[i]->Clone();
186cdf0e10cSrcweir
187cdf0e10cSrcweir return *this;
188cdf0e10cSrcweir }
189cdf0e10cSrcweir
190cdf0e10cSrcweir //------------------------------------------------------------------------
191cdf0e10cSrcweir
Clone() const192cdf0e10cSrcweir ScDataObject* ScCollection::Clone() const
193cdf0e10cSrcweir {
194cdf0e10cSrcweir return new ScCollection(*this);
195cdf0e10cSrcweir }
196cdf0e10cSrcweir
197cdf0e10cSrcweir //------------------------------------------------------------------------
198cdf0e10cSrcweir // ScSortedCollection
199cdf0e10cSrcweir //------------------------------------------------------------------------
200cdf0e10cSrcweir
ScSortedCollection(sal_uInt16 nLim,sal_uInt16 nDel,sal_Bool bDup)201cdf0e10cSrcweir ScSortedCollection::ScSortedCollection(sal_uInt16 nLim, sal_uInt16 nDel, sal_Bool bDup) :
202cdf0e10cSrcweir ScCollection (nLim, nDel),
203cdf0e10cSrcweir bDuplicates ( bDup)
204cdf0e10cSrcweir {
205cdf0e10cSrcweir }
206cdf0e10cSrcweir
207cdf0e10cSrcweir //------------------------------------------------------------------------
208cdf0e10cSrcweir
IndexOf(ScDataObject * pScDataObject) const209cdf0e10cSrcweir sal_uInt16 ScSortedCollection::IndexOf(ScDataObject* pScDataObject) const
210cdf0e10cSrcweir {
211cdf0e10cSrcweir sal_uInt16 nIndex;
212cdf0e10cSrcweir if (Search(pScDataObject, nIndex))
213cdf0e10cSrcweir return nIndex;
214cdf0e10cSrcweir else
215cdf0e10cSrcweir return 0xffff;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir
218cdf0e10cSrcweir //------------------------------------------------------------------------
219cdf0e10cSrcweir
Search(ScDataObject * pScDataObject,sal_uInt16 & rIndex) const220cdf0e10cSrcweir sal_Bool ScSortedCollection::Search(ScDataObject* pScDataObject, sal_uInt16& rIndex) const
221cdf0e10cSrcweir {
222cdf0e10cSrcweir rIndex = nCount;
223cdf0e10cSrcweir sal_Bool bFound = sal_False;
224cdf0e10cSrcweir short nLo = 0;
225cdf0e10cSrcweir short nHi = nCount - 1;
226cdf0e10cSrcweir short nIndex;
227cdf0e10cSrcweir short nCompare;
228cdf0e10cSrcweir while (nLo <= nHi)
229cdf0e10cSrcweir {
230cdf0e10cSrcweir nIndex = (nLo + nHi) / 2;
231cdf0e10cSrcweir nCompare = Compare(pItems[nIndex], pScDataObject);
232cdf0e10cSrcweir if (nCompare < 0)
233cdf0e10cSrcweir nLo = nIndex + 1;
234cdf0e10cSrcweir else
235cdf0e10cSrcweir {
236cdf0e10cSrcweir nHi = nIndex - 1;
237cdf0e10cSrcweir if (nCompare == 0)
238cdf0e10cSrcweir {
239cdf0e10cSrcweir bFound = sal_True;
240cdf0e10cSrcweir nLo = nIndex;
241cdf0e10cSrcweir }
242cdf0e10cSrcweir }
243cdf0e10cSrcweir }
244cdf0e10cSrcweir rIndex = nLo;
245cdf0e10cSrcweir return bFound;
246cdf0e10cSrcweir }
247cdf0e10cSrcweir
248cdf0e10cSrcweir //------------------------------------------------------------------------
249cdf0e10cSrcweir
Insert(ScDataObject * pScDataObject)250cdf0e10cSrcweir sal_Bool ScSortedCollection::Insert(ScDataObject* pScDataObject)
251cdf0e10cSrcweir {
252cdf0e10cSrcweir sal_uInt16 nIndex;
253cdf0e10cSrcweir sal_Bool bFound = Search(pScDataObject, nIndex);
254cdf0e10cSrcweir if (bFound)
255cdf0e10cSrcweir {
256cdf0e10cSrcweir if (bDuplicates)
257cdf0e10cSrcweir return AtInsert(nIndex, pScDataObject);
258cdf0e10cSrcweir else
259cdf0e10cSrcweir return sal_False;
260cdf0e10cSrcweir }
261cdf0e10cSrcweir else
262cdf0e10cSrcweir return AtInsert(nIndex, pScDataObject);
263cdf0e10cSrcweir }
264cdf0e10cSrcweir
265cdf0e10cSrcweir //------------------------------------------------------------------------
266cdf0e10cSrcweir
InsertPos(ScDataObject * pScDataObject,sal_uInt16 & nIndex)267cdf0e10cSrcweir sal_Bool ScSortedCollection::InsertPos(ScDataObject* pScDataObject, sal_uInt16& nIndex)
268cdf0e10cSrcweir {
269cdf0e10cSrcweir sal_Bool bFound = Search(pScDataObject, nIndex);
270cdf0e10cSrcweir if (bFound)
271cdf0e10cSrcweir {
272cdf0e10cSrcweir if (bDuplicates)
273cdf0e10cSrcweir return AtInsert(nIndex, pScDataObject);
274cdf0e10cSrcweir else
275cdf0e10cSrcweir return sal_False;
276cdf0e10cSrcweir }
277cdf0e10cSrcweir else
278cdf0e10cSrcweir return AtInsert(nIndex, pScDataObject);
279cdf0e10cSrcweir }
280cdf0e10cSrcweir
281cdf0e10cSrcweir //------------------------------------------------------------------------
282cdf0e10cSrcweir
operator ==(const ScSortedCollection & rCmp) const283cdf0e10cSrcweir sal_Bool ScSortedCollection::operator==(const ScSortedCollection& rCmp) const
284cdf0e10cSrcweir {
285cdf0e10cSrcweir if ( nCount != rCmp.nCount )
286cdf0e10cSrcweir return sal_False;
287cdf0e10cSrcweir for (sal_uInt16 i=0; i<nCount; i++)
288cdf0e10cSrcweir if ( !IsEqual(pItems[i],rCmp.pItems[i]) )
289cdf0e10cSrcweir return sal_False;
290cdf0e10cSrcweir return sal_True;
291cdf0e10cSrcweir }
292cdf0e10cSrcweir
293cdf0e10cSrcweir //------------------------------------------------------------------------
294cdf0e10cSrcweir
295cdf0e10cSrcweir // IsEqual - komplette Inhalte vergleichen
296cdf0e10cSrcweir
IsEqual(ScDataObject * pKey1,ScDataObject * pKey2) const297cdf0e10cSrcweir sal_Bool ScSortedCollection::IsEqual(ScDataObject* pKey1, ScDataObject* pKey2) const
298cdf0e10cSrcweir {
299cdf0e10cSrcweir return ( Compare(pKey1, pKey2) == 0 ); // Default: nur Index vergleichen
300cdf0e10cSrcweir }
301cdf0e10cSrcweir
302cdf0e10cSrcweir //------------------------------------------------------------------------
303cdf0e10cSrcweir
Clone() const304cdf0e10cSrcweir ScDataObject* StrData::Clone() const
305cdf0e10cSrcweir {
306cdf0e10cSrcweir return new StrData(*this);
307cdf0e10cSrcweir }
308cdf0e10cSrcweir
309cdf0e10cSrcweir //------------------------------------------------------------------------
310cdf0e10cSrcweir
Compare(ScDataObject * pKey1,ScDataObject * pKey2) const311cdf0e10cSrcweir short ScStrCollection::Compare(ScDataObject* pKey1, ScDataObject* pKey2) const
312cdf0e10cSrcweir {
313cdf0e10cSrcweir StringCompare eComp = ((StrData*)pKey1)->aStr.CompareTo(((StrData*)pKey2)->aStr);
314cdf0e10cSrcweir if (eComp == COMPARE_EQUAL)
315cdf0e10cSrcweir return 0;
316cdf0e10cSrcweir else if (eComp == COMPARE_LESS)
317cdf0e10cSrcweir return -1;
318cdf0e10cSrcweir else
319cdf0e10cSrcweir return 1;
320cdf0e10cSrcweir }
321cdf0e10cSrcweir
322cdf0e10cSrcweir //------------------------------------------------------------------------
323cdf0e10cSrcweir
Clone() const324cdf0e10cSrcweir ScDataObject* ScStrCollection::Clone() const
325cdf0e10cSrcweir {
326cdf0e10cSrcweir return new ScStrCollection(*this);
327cdf0e10cSrcweir }
328cdf0e10cSrcweir
329cdf0e10cSrcweir //------------------------------------------------------------------------
330cdf0e10cSrcweir // TypedScStrCollection
331cdf0e10cSrcweir //------------------------------------------------------------------------
332cdf0e10cSrcweir
333cdf0e10cSrcweir //UNUSED2008-05 TypedStrData::TypedStrData( ScDocument* pDoc, SCCOL nCol, SCROW nRow, SCTAB nTab,
334cdf0e10cSrcweir //UNUSED2008-05 sal_Bool bAllStrings )
335cdf0e10cSrcweir //UNUSED2008-05 {
336cdf0e10cSrcweir //UNUSED2008-05 if ( pDoc->HasValueData( nCol, nRow, nTab ) )
337cdf0e10cSrcweir //UNUSED2008-05 {
338cdf0e10cSrcweir //UNUSED2008-05 pDoc->GetValue( nCol, nRow, nTab, nValue );
339cdf0e10cSrcweir //UNUSED2008-05 if (bAllStrings)
340cdf0e10cSrcweir //UNUSED2008-05 pDoc->GetString( nCol, nRow, nTab, aStrValue );
341cdf0e10cSrcweir //UNUSED2008-05 nStrType = 0;
342cdf0e10cSrcweir //UNUSED2008-05 }
343cdf0e10cSrcweir //UNUSED2008-05 else
344cdf0e10cSrcweir //UNUSED2008-05 {
345cdf0e10cSrcweir //UNUSED2008-05 pDoc->GetString( nCol, nRow, nTab, aStrValue );
346cdf0e10cSrcweir //UNUSED2008-05 nValue = 0.0;
347cdf0e10cSrcweir //UNUSED2008-05 nStrType = 1; //! Typ uebergeben ?
348cdf0e10cSrcweir //UNUSED2008-05 }
349cdf0e10cSrcweir //UNUSED2008-05 }
350cdf0e10cSrcweir
351cdf0e10cSrcweir
Clone() const352cdf0e10cSrcweir ScDataObject* TypedStrData::Clone() const
353cdf0e10cSrcweir {
354cdf0e10cSrcweir return new TypedStrData(*this);
355cdf0e10cSrcweir }
356cdf0e10cSrcweir
TypedScStrCollection(sal_uInt16 nLim,sal_uInt16 nDel,sal_Bool bDup)357cdf0e10cSrcweir TypedScStrCollection::TypedScStrCollection( sal_uInt16 nLim , sal_uInt16 nDel , sal_Bool bDup )
358cdf0e10cSrcweir : ScSortedCollection( nLim, nDel, bDup )
359cdf0e10cSrcweir {
360cdf0e10cSrcweir bCaseSensitive = sal_False;
361cdf0e10cSrcweir }
362cdf0e10cSrcweir
~TypedScStrCollection()363cdf0e10cSrcweir TypedScStrCollection::~TypedScStrCollection()
364cdf0e10cSrcweir {}
Clone() const365cdf0e10cSrcweir ScDataObject* TypedScStrCollection::Clone() const
366cdf0e10cSrcweir {
367cdf0e10cSrcweir return new TypedScStrCollection(*this);
368cdf0e10cSrcweir }
369cdf0e10cSrcweir
operator [](const sal_uInt16 nIndex) const370cdf0e10cSrcweir TypedStrData* TypedScStrCollection::operator[]( const sal_uInt16 nIndex) const
371cdf0e10cSrcweir {
372cdf0e10cSrcweir return (TypedStrData*)At(nIndex);
373cdf0e10cSrcweir }
374cdf0e10cSrcweir
SetCaseSensitive(sal_Bool bSet)375cdf0e10cSrcweir void TypedScStrCollection::SetCaseSensitive( sal_Bool bSet )
376cdf0e10cSrcweir {
377cdf0e10cSrcweir bCaseSensitive = bSet;
378cdf0e10cSrcweir }
379cdf0e10cSrcweir
Compare(ScDataObject * pKey1,ScDataObject * pKey2) const380cdf0e10cSrcweir short TypedScStrCollection::Compare( ScDataObject* pKey1, ScDataObject* pKey2 ) const
381cdf0e10cSrcweir {
382cdf0e10cSrcweir short nResult = 0;
383cdf0e10cSrcweir
384cdf0e10cSrcweir if ( pKey1 && pKey2 )
385cdf0e10cSrcweir {
386cdf0e10cSrcweir TypedStrData& rData1 = (TypedStrData&)*pKey1;
387cdf0e10cSrcweir TypedStrData& rData2 = (TypedStrData&)*pKey2;
388cdf0e10cSrcweir
389cdf0e10cSrcweir if ( rData1.nStrType > rData2.nStrType )
390cdf0e10cSrcweir nResult = 1;
391cdf0e10cSrcweir else if ( rData1.nStrType < rData2.nStrType )
392cdf0e10cSrcweir nResult = -1;
393cdf0e10cSrcweir else if ( !rData1.nStrType /* && !rData2.nStrType */ )
394cdf0e10cSrcweir {
395cdf0e10cSrcweir //--------------------
396cdf0e10cSrcweir // Zahlen vergleichen:
397cdf0e10cSrcweir //--------------------
398cdf0e10cSrcweir if ( rData1.nValue == rData2.nValue )
399cdf0e10cSrcweir nResult = 0;
400cdf0e10cSrcweir else if ( rData1.nValue < rData2.nValue )
401cdf0e10cSrcweir nResult = -1;
402cdf0e10cSrcweir else
403cdf0e10cSrcweir nResult = 1;
404cdf0e10cSrcweir }
405cdf0e10cSrcweir else /* if ( rData1.nStrType && rData2.nStrType ) */
406cdf0e10cSrcweir {
407cdf0e10cSrcweir //---------------------
408cdf0e10cSrcweir // Strings vergleichen:
409cdf0e10cSrcweir //---------------------
410cdf0e10cSrcweir if ( bCaseSensitive )
411cdf0e10cSrcweir nResult = (short) ScGlobal::GetCaseTransliteration()->compareString(
412cdf0e10cSrcweir rData1.aStrValue, rData2.aStrValue );
413cdf0e10cSrcweir else
414cdf0e10cSrcweir nResult = (short) ScGlobal::GetpTransliteration()->compareString(
415cdf0e10cSrcweir rData1.aStrValue, rData2.aStrValue );
416cdf0e10cSrcweir }
417cdf0e10cSrcweir }
418cdf0e10cSrcweir
419cdf0e10cSrcweir return nResult;
420cdf0e10cSrcweir }
421cdf0e10cSrcweir
FindText(const String & rStart,String & rResult,sal_uInt16 & rPos,sal_Bool bBack) const422cdf0e10cSrcweir sal_Bool TypedScStrCollection::FindText( const String& rStart, String& rResult,
423cdf0e10cSrcweir sal_uInt16& rPos, sal_Bool bBack ) const
424cdf0e10cSrcweir {
425cdf0e10cSrcweir // Die Collection ist nach String-Vergleichen sortiert, darum muss hier
426cdf0e10cSrcweir // alles durchsucht werden
427cdf0e10cSrcweir
428cdf0e10cSrcweir sal_Bool bFound = sal_False;
429cdf0e10cSrcweir
430cdf0e10cSrcweir String aOldResult;
431cdf0e10cSrcweir if ( rPos != SCPOS_INVALID && rPos < nCount )
432cdf0e10cSrcweir {
433cdf0e10cSrcweir TypedStrData* pData = (TypedStrData*) pItems[rPos];
434cdf0e10cSrcweir if (pData->nStrType)
435cdf0e10cSrcweir aOldResult = pData->aStrValue;
436cdf0e10cSrcweir }
437cdf0e10cSrcweir
438cdf0e10cSrcweir if ( bBack ) // rueckwaerts
439cdf0e10cSrcweir {
440cdf0e10cSrcweir sal_uInt16 nStartPos = nCount;
441cdf0e10cSrcweir if ( rPos != SCPOS_INVALID )
442cdf0e10cSrcweir nStartPos = rPos; // weitersuchen...
443cdf0e10cSrcweir
444cdf0e10cSrcweir for ( sal_uInt16 i=nStartPos; i>0; )
445cdf0e10cSrcweir {
446cdf0e10cSrcweir --i;
447cdf0e10cSrcweir TypedStrData* pData = (TypedStrData*) pItems[i];
448cdf0e10cSrcweir if (pData->nStrType)
449cdf0e10cSrcweir {
450cdf0e10cSrcweir if ( ScGlobal::GetpTransliteration()->isMatch( rStart, pData->aStrValue ) )
451cdf0e10cSrcweir {
452cdf0e10cSrcweir // If the collection is case sensitive, it may contain several entries
453cdf0e10cSrcweir // that are equal when compared case-insensitive. They are skipped here.
454cdf0e10cSrcweir if ( !bCaseSensitive || !aOldResult.Len() ||
455cdf0e10cSrcweir !ScGlobal::GetpTransliteration()->isEqual(
456cdf0e10cSrcweir pData->aStrValue, aOldResult ) )
457cdf0e10cSrcweir {
458cdf0e10cSrcweir rResult = pData->aStrValue;
459cdf0e10cSrcweir rPos = i;
460cdf0e10cSrcweir bFound = sal_True;
461cdf0e10cSrcweir break;
462cdf0e10cSrcweir }
463cdf0e10cSrcweir }
464cdf0e10cSrcweir }
465cdf0e10cSrcweir }
466cdf0e10cSrcweir }
467cdf0e10cSrcweir else // vorwaerts
468cdf0e10cSrcweir {
469cdf0e10cSrcweir sal_uInt16 nStartPos = 0;
470cdf0e10cSrcweir if ( rPos != SCPOS_INVALID )
471cdf0e10cSrcweir nStartPos = rPos + 1; // weitersuchen...
472cdf0e10cSrcweir
473cdf0e10cSrcweir for ( sal_uInt16 i=nStartPos; i<nCount; i++ )
474cdf0e10cSrcweir {
475cdf0e10cSrcweir TypedStrData* pData = (TypedStrData*) pItems[i];
476cdf0e10cSrcweir if (pData->nStrType)
477cdf0e10cSrcweir {
478cdf0e10cSrcweir if ( ScGlobal::GetpTransliteration()->isMatch( rStart, pData->aStrValue ) )
479cdf0e10cSrcweir {
480cdf0e10cSrcweir // If the collection is case sensitive, it may contain several entries
481cdf0e10cSrcweir // that are equal when compared case-insensitive. They are skipped here.
482cdf0e10cSrcweir if ( !bCaseSensitive || !aOldResult.Len() ||
483cdf0e10cSrcweir !ScGlobal::GetpTransliteration()->isEqual(
484cdf0e10cSrcweir pData->aStrValue, aOldResult ) )
485cdf0e10cSrcweir {
486cdf0e10cSrcweir rResult = pData->aStrValue;
487cdf0e10cSrcweir rPos = i;
488cdf0e10cSrcweir bFound = sal_True;
489cdf0e10cSrcweir break;
490cdf0e10cSrcweir }
491cdf0e10cSrcweir }
492cdf0e10cSrcweir }
493cdf0e10cSrcweir }
494cdf0e10cSrcweir }
495cdf0e10cSrcweir
496cdf0e10cSrcweir return bFound;
497cdf0e10cSrcweir }
498cdf0e10cSrcweir
499cdf0e10cSrcweir // Gross-/Kleinschreibung anpassen
500cdf0e10cSrcweir
GetExactMatch(String & rString) const501cdf0e10cSrcweir sal_Bool TypedScStrCollection::GetExactMatch( String& rString ) const
502cdf0e10cSrcweir {
503cdf0e10cSrcweir for (sal_uInt16 i=0; i<nCount; i++)
504cdf0e10cSrcweir {
505cdf0e10cSrcweir TypedStrData* pData = (TypedStrData*) pItems[i];
506cdf0e10cSrcweir if ( pData->nStrType && ScGlobal::GetpTransliteration()->isEqual(
507cdf0e10cSrcweir pData->aStrValue, rString ) )
508cdf0e10cSrcweir {
509cdf0e10cSrcweir rString = pData->aStrValue; // String anpassen
510cdf0e10cSrcweir return sal_True;
511cdf0e10cSrcweir }
512cdf0e10cSrcweir }
513cdf0e10cSrcweir
514cdf0e10cSrcweir return sal_False;
515cdf0e10cSrcweir }
516cdf0e10cSrcweir
517cdf0e10cSrcweir
518cdf0e10cSrcweir
519