update dev300-m57
[ooovba.git] / sc / source / core / tool / dbcolect.cxx
blob8eb32cebcd43f47761872b0eaacbef5fcba8f19e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dbcolect.cxx,v $
10 * $Revision: 1.17.32.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
35 #include <tools/debug.hxx>
36 #include <unotools/transliterationwrapper.hxx>
38 #include "dbcolect.hxx"
39 #include "global.hxx"
40 #include "refupdat.hxx"
41 #include "rechead.hxx"
42 #include "document.hxx"
43 #include "globstr.hrc"
46 //---------------------------------------------------------------------------------------
48 ScDBData::ScDBData( const String& rName,
49 SCTAB nTab,
50 SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
51 BOOL bByR, BOOL bHasH) :
52 aName (rName),
53 nTable (nTab),
54 nStartCol (nCol1),
55 nStartRow (nRow1),
56 nEndCol (nCol2),
57 nEndRow (nRow2),
58 bByRow (bByR),
59 bHasHeader (bHasH),
60 bDoSize (FALSE),
61 bKeepFmt (FALSE),
62 bStripData (FALSE),
63 bIsAdvanced (FALSE),
64 bDBSelection(FALSE),
65 nIndex (0),
66 bAutoFilter (FALSE),
67 bModified (FALSE)
69 USHORT i;
71 ScSortParam aSortParam;
72 ScQueryParam aQueryParam;
73 ScSubTotalParam aSubTotalParam;
74 ScImportParam aImportParam;
76 for (i=0; i<MAXQUERY; i++)
77 pQueryStr[i] = new String;
79 for (i=0; i<MAXSUBTOTAL; i++)
81 nSubTotals[i] = 0;
82 pSubTotals[i] = NULL;
83 pFunctions[i] = NULL;
86 SetSortParam( aSortParam );
87 SetQueryParam( aQueryParam );
88 SetSubTotalParam( aSubTotalParam );
89 SetImportParam( aImportParam );
92 ScDBData::ScDBData( const ScDBData& rData ) :
93 ScDataObject(),
94 ScRefreshTimer ( rData ),
95 aName (rData.aName),
96 nTable (rData.nTable),
97 nStartCol (rData.nStartCol),
98 nStartRow (rData.nStartRow),
99 nEndCol (rData.nEndCol),
100 nEndRow (rData.nEndRow),
101 bByRow (rData.bByRow),
102 bHasHeader (rData.bHasHeader),
103 bDoSize (rData.bDoSize),
104 bKeepFmt (rData.bKeepFmt),
105 bStripData (rData.bStripData),
106 bSortCaseSens (rData.bSortCaseSens),
107 bSortNaturalSort (rData.bSortNaturalSort),
108 bIncludePattern (rData.bIncludePattern),
109 bSortInplace (rData.bSortInplace),
110 bSortUserDef (rData.bSortUserDef),
111 nSortUserIndex (rData.nSortUserIndex),
112 nSortDestTab (rData.nSortDestTab),
113 nSortDestCol (rData.nSortDestCol),
114 nSortDestRow (rData.nSortDestRow),
115 aSortLocale (rData.aSortLocale),
116 aSortAlgorithm (rData.aSortAlgorithm),
117 bQueryInplace (rData.bQueryInplace),
118 bQueryCaseSens (rData.bQueryCaseSens),
119 bQueryRegExp (rData.bQueryRegExp),
120 bQueryDuplicate (rData.bQueryDuplicate),
121 nQueryDestTab (rData.nQueryDestTab),
122 nQueryDestCol (rData.nQueryDestCol),
123 nQueryDestRow (rData.nQueryDestRow),
124 bIsAdvanced (rData.bIsAdvanced),
125 aAdvSource (rData.aAdvSource),
126 bSubRemoveOnly (rData.bSubRemoveOnly),
127 bSubReplace (rData.bSubReplace),
128 bSubPagebreak (rData.bSubPagebreak),
129 bSubCaseSens (rData.bSubCaseSens),
130 bSubDoSort (rData.bSubDoSort),
131 bSubAscending (rData.bSubAscending),
132 bSubIncludePattern (rData.bSubIncludePattern),
133 bSubUserDef (rData.bSubUserDef),
134 nSubUserIndex (rData.nSubUserIndex),
135 bDBImport (rData.bDBImport),
136 aDBName (rData.aDBName),
137 aDBStatement (rData.aDBStatement),
138 bDBNative (rData.bDBNative),
139 bDBSelection (rData.bDBSelection),
140 bDBSql (rData.bDBSql),
141 nDBType (rData.nDBType),
142 nIndex (rData.nIndex),
143 bAutoFilter (rData.bAutoFilter),
144 bModified (rData.bModified)
146 USHORT i;
147 USHORT j;
149 for (i=0; i<MAXSORT; i++)
151 bDoSort[i] = rData.bDoSort[i];
152 nSortField[i] = rData.nSortField[i];
153 bAscending[i] = rData.bAscending[i];
155 for (i=0; i<MAXQUERY; i++)
157 bDoQuery[i] = rData.bDoQuery[i];
158 nQueryField[i] = rData.nQueryField[i];
159 eQueryOp[i] = rData.eQueryOp[i];
160 bQueryByString[i] = rData.bQueryByString[i];
161 pQueryStr[i] = new String( *(rData.pQueryStr[i]) );
162 nQueryVal[i] = rData.nQueryVal[i];
163 eQueryConnect[i] = rData.eQueryConnect[i];
165 for (i=0; i<MAXSUBTOTAL; i++)
167 bDoSubTotal[i] = rData.bDoSubTotal[i];
168 nSubField[i] = rData.nSubField[i];
170 SCCOL nCount = rData.nSubTotals[i];
171 nSubTotals[i] = nCount;
172 pFunctions[i] = nCount > 0 ? new ScSubTotalFunc [nCount] : NULL;
173 pSubTotals[i] = nCount > 0 ? new SCCOL [nCount] : NULL;
175 for (j=0; j<nCount; j++)
177 pSubTotals[i][j] = rData.pSubTotals[i][j];
178 pFunctions[i][j] = rData.pFunctions[i][j];
183 ScDBData& ScDBData::operator= (const ScDBData& rData)
185 USHORT i;
186 USHORT j;
188 ScRefreshTimer::operator=( rData );
189 aName = rData.aName;
190 nTable = rData.nTable;
191 nStartCol = rData.nStartCol;
192 nStartRow = rData.nStartRow;
193 nEndCol = rData.nEndCol;
194 nEndRow = rData.nEndRow;
195 bByRow = rData.bByRow;
196 bHasHeader = rData.bHasHeader;
197 bDoSize = rData.bDoSize;
198 bKeepFmt = rData.bKeepFmt;
199 bStripData = rData.bStripData;
200 bSortCaseSens = rData.bSortCaseSens;
201 bSortNaturalSort = rData.bSortNaturalSort;
202 bIncludePattern = rData.bIncludePattern;
203 bSortInplace = rData.bSortInplace;
204 nSortDestTab = rData.nSortDestTab;
205 nSortDestCol = rData.nSortDestCol;
206 nSortDestRow = rData.nSortDestRow;
207 bSortUserDef = rData.bSortUserDef;
208 nSortUserIndex = rData.nSortUserIndex;
209 aSortLocale = rData.aSortLocale;
210 aSortAlgorithm = rData.aSortAlgorithm;
211 bQueryInplace = rData.bQueryInplace;
212 bQueryCaseSens = rData.bQueryCaseSens;
213 bQueryRegExp = rData.bQueryRegExp;
214 bQueryDuplicate = rData.bQueryDuplicate;
215 nQueryDestTab = rData.nQueryDestTab;
216 nQueryDestCol = rData.nQueryDestCol;
217 nQueryDestRow = rData.nQueryDestRow;
218 bIsAdvanced = rData.bIsAdvanced;
219 aAdvSource = rData.aAdvSource;
220 bSubRemoveOnly = rData.bSubRemoveOnly;
221 bSubReplace = rData.bSubReplace;
222 bSubPagebreak = rData.bSubPagebreak;
223 bSubCaseSens = rData.bSubCaseSens;
224 bSubDoSort = rData.bSubDoSort;
225 bSubAscending = rData.bSubAscending;
226 bSubIncludePattern = rData.bSubIncludePattern;
227 bSubUserDef = rData.bSubUserDef;
228 nSubUserIndex = rData.nSubUserIndex;
229 bDBImport = rData.bDBImport;
230 aDBName = rData.aDBName;
231 aDBStatement = rData.aDBStatement;
232 bDBNative = rData.bDBNative;
233 bDBSelection = rData.bDBSelection;
234 bDBSql = rData.bDBSql;
235 nDBType = rData.nDBType;
236 nIndex = rData.nIndex;
237 bAutoFilter = rData.bAutoFilter;
239 for (i=0; i<MAXSORT; i++)
241 bDoSort[i] = rData.bDoSort[i];
242 nSortField[i] = rData.nSortField[i];
243 bAscending[i] = rData.bAscending[i];
245 for (i=0; i<MAXQUERY; i++)
247 bDoQuery[i] = rData.bDoQuery[i];
248 nQueryField[i] = rData.nQueryField[i];
249 eQueryOp[i] = rData.eQueryOp[i];
250 bQueryByString[i] = rData.bQueryByString[i];
251 *pQueryStr[i] = *rData.pQueryStr[i];
252 nQueryVal[i] = rData.nQueryVal[i];
253 eQueryConnect[i] = rData.eQueryConnect[i];
255 for (i=0; i<MAXSUBTOTAL; i++)
257 bDoSubTotal[i] = rData.bDoSubTotal[i];
258 nSubField[i] = rData.nSubField[i];
259 SCCOL nCount = rData.nSubTotals[i];
260 nSubTotals[i] = nCount;
262 delete[] pSubTotals[i];
263 delete[] pFunctions[i];
265 pSubTotals[i] = nCount > 0 ? new SCCOL [nCount] : NULL;
266 pFunctions[i] = nCount > 0 ? new ScSubTotalFunc [nCount] : NULL;
267 for (j=0; j<nCount; j++)
269 pSubTotals[i][j] = rData.pSubTotals[i][j];
270 pFunctions[i][j] = rData.pFunctions[i][j];
274 return *this;
277 BOOL ScDBData::operator== (const ScDBData& rData) const
279 // Daten, die nicht in den Params sind
281 if ( nTable != rData.nTable ||
282 bDoSize != rData.bDoSize ||
283 bKeepFmt != rData.bKeepFmt ||
284 bIsAdvanced!= rData.bIsAdvanced||
285 bStripData != rData.bStripData ||
286 // SAB: I think this should be here, but I don't want to break something
287 // bAutoFilter!= rData.bAutoFilter||
288 ScRefreshTimer::operator!=( rData )
290 return FALSE;
292 if ( bIsAdvanced && aAdvSource != rData.aAdvSource )
293 return FALSE;
295 ScSortParam aSort1, aSort2;
296 GetSortParam(aSort1);
297 rData.GetSortParam(aSort2);
298 if (!(aSort1 == aSort2))
299 return FALSE;
301 ScQueryParam aQuery1, aQuery2;
302 GetQueryParam(aQuery1);
303 rData.GetQueryParam(aQuery2);
304 if (!(aQuery1 == aQuery2))
305 return FALSE;
307 ScSubTotalParam aSubTotal1, aSubTotal2;
308 GetSubTotalParam(aSubTotal1);
309 rData.GetSubTotalParam(aSubTotal2);
310 if (!(aSubTotal1 == aSubTotal2))
311 return FALSE;
313 ScImportParam aImport1, aImport2;
314 GetImportParam(aImport1);
315 rData.GetImportParam(aImport2);
316 if (!(aImport1 == aImport2))
317 return FALSE;
319 return TRUE;
322 ScDBData::~ScDBData()
324 StopRefreshTimer();
325 USHORT i;
327 for (i=0; i<MAXQUERY; i++)
328 delete pQueryStr[i];
329 for (i=0; i<MAXSUBTOTAL; i++)
331 delete[] pSubTotals[i];
332 delete[] pFunctions[i];
336 //UNUSED2008-05 BOOL ScDBData::IsBeyond(SCROW nMaxRow) const
337 //UNUSED2008-05 {
338 //UNUSED2008-05 return ( nStartRow > nMaxRow ||
339 //UNUSED2008-05 nEndRow > nMaxRow ||
340 //UNUSED2008-05 nQueryDestRow > nMaxRow );
341 //UNUSED2008-05 }
343 String ScDBData::GetSourceString() const
345 String aVal;
346 if (bDBImport)
348 aVal = aDBName;
349 aVal += '/';
350 aVal += aDBStatement;
352 return aVal;
355 String ScDBData::GetOperations() const
357 String aVal;
358 if (bDoQuery[0])
359 aVal = ScGlobal::GetRscString(STR_OPERATION_FILTER);
361 if (bDoSort[0])
363 if (aVal.Len())
364 aVal.AppendAscii( RTL_CONSTASCII_STRINGPARAM(", ") );
365 aVal += ScGlobal::GetRscString(STR_OPERATION_SORT);
368 if (bDoSubTotal[0] && !bSubRemoveOnly)
370 if (aVal.Len())
371 aVal.AppendAscii( RTL_CONSTASCII_STRINGPARAM(", ") );
372 aVal += ScGlobal::GetRscString(STR_OPERATION_SUBTOTAL);
375 if (!aVal.Len())
376 aVal = ScGlobal::GetRscString(STR_OPERATION_NONE);
378 return aVal;
381 void ScDBData::GetArea(SCTAB& rTab, SCCOL& rCol1, SCROW& rRow1, SCCOL& rCol2, SCROW& rRow2,
382 bool bUseDynamicRange) const
384 rTab = nTable;
385 rCol1 = nStartCol;
386 rRow1 = nStartRow;
387 rCol2 = nEndCol;
388 rRow2 = bUseDynamicRange ? nDynamicEndRow : nEndRow;
391 void ScDBData::GetArea(ScRange& rRange, bool bUseDynamicRange) const
393 SCROW nNewEndRow = bUseDynamicRange ? nDynamicEndRow : nEndRow;
394 rRange = ScRange( nStartCol, nStartRow, nTable, nEndCol, nNewEndRow, nTable );
397 void ScDBData::SetArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
399 nTable = nTab;
400 nStartCol = nCol1;
401 nStartRow = nRow1;
402 nEndCol = nCol2;
403 nEndRow = nRow2;
406 void ScDBData::SetDynamicEndRow(SCROW nRow)
408 nDynamicEndRow = nRow;
411 void ScDBData::MoveTo(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2)
413 USHORT i;
414 long nDifX = ((long) nCol1) - ((long) nStartCol);
415 long nDifY = ((long) nRow1) - ((long) nStartRow);
417 long nSortDif = bByRow ? nDifX : nDifY;
418 long nSortEnd = bByRow ? static_cast<long>(nCol2) : static_cast<long>(nRow2);
420 for (i=0; i<MAXSORT; i++)
422 nSortField[i] += nSortDif;
423 if (nSortField[i] > nSortEnd)
425 nSortField[i] = 0;
426 bDoSort[i] = FALSE;
429 for (i=0; i<MAXQUERY; i++)
431 nQueryField[i] += nDifX;
432 if (nQueryField[i] > nCol2)
434 nQueryField[i] = 0;
435 bDoQuery[i] = FALSE;
438 for (i=0; i<MAXSUBTOTAL; i++)
440 nSubField[i] = sal::static_int_cast<SCCOL>( nSubField[i] + nDifX );
441 if (nSubField[i] > nCol2)
443 nSubField[i] = 0;
444 bDoSubTotal[i] = FALSE;
448 SetArea( nTab, nCol1, nRow1, nCol2, nRow2 );
451 void ScDBData::GetSortParam( ScSortParam& rSortParam ) const
453 rSortParam.nCol1 = nStartCol;
454 rSortParam.nRow1 = nStartRow;
455 rSortParam.nCol2 = nEndCol;
456 rSortParam.nRow2 = nEndRow;
457 rSortParam.bByRow = bByRow;
458 rSortParam.bHasHeader = bHasHeader;
459 rSortParam.bCaseSens = bSortCaseSens;
460 rSortParam.bNaturalSort = bSortNaturalSort;
461 rSortParam.bInplace = bSortInplace;
462 rSortParam.nDestTab = nSortDestTab;
463 rSortParam.nDestCol = nSortDestCol;
464 rSortParam.nDestRow = nSortDestRow;
465 rSortParam.bIncludePattern = bIncludePattern;
466 rSortParam.bUserDef = bSortUserDef;
467 rSortParam.nUserIndex = nSortUserIndex;
468 for (USHORT i=0; i<MAXSORT; i++)
470 rSortParam.bDoSort[i] = bDoSort[i];
471 rSortParam.nField[i] = nSortField[i];
472 rSortParam.bAscending[i] = bAscending[i];
474 rSortParam.aCollatorLocale = aSortLocale;
475 rSortParam.aCollatorAlgorithm = aSortAlgorithm;
478 void ScDBData::SetSortParam( const ScSortParam& rSortParam )
480 bSortCaseSens = rSortParam.bCaseSens;
481 bSortNaturalSort = rSortParam.bNaturalSort;
482 bIncludePattern = rSortParam.bIncludePattern;
483 bSortInplace = rSortParam.bInplace;
484 nSortDestTab = rSortParam.nDestTab;
485 nSortDestCol = rSortParam.nDestCol;
486 nSortDestRow = rSortParam.nDestRow;
487 bSortUserDef = rSortParam.bUserDef;
488 nSortUserIndex = rSortParam.nUserIndex;
489 for (USHORT i=0; i<MAXSORT; i++)
491 bDoSort[i] = rSortParam.bDoSort[i];
492 nSortField[i] = rSortParam.nField[i];
493 bAscending[i] = rSortParam.bAscending[i];
495 aSortLocale = rSortParam.aCollatorLocale;
496 aSortAlgorithm = rSortParam.aCollatorAlgorithm;
498 //#98317#; set the orientation
499 bByRow = rSortParam.bByRow;
502 void ScDBData::GetQueryParam( ScQueryParam& rQueryParam ) const
504 rQueryParam.nCol1 = nStartCol;
505 rQueryParam.nRow1 = nStartRow;
506 rQueryParam.nCol2 = nEndCol;
507 rQueryParam.nRow2 = nEndRow;
508 rQueryParam.nTab = nTable;
509 rQueryParam.bByRow = bByRow;
510 rQueryParam.bHasHeader = bHasHeader;
511 rQueryParam.bInplace = bQueryInplace;
512 rQueryParam.bCaseSens = bQueryCaseSens;
513 rQueryParam.bRegExp = bQueryRegExp;
514 rQueryParam.bDuplicate = bQueryDuplicate;
515 rQueryParam.nDestTab = nQueryDestTab;
516 rQueryParam.nDestCol = nQueryDestCol;
517 rQueryParam.nDestRow = nQueryDestRow;
518 rQueryParam.nDynamicEndRow = nDynamicEndRow;
520 rQueryParam.Resize( MAXQUERY );
521 for (SCSIZE i=0; i<MAXQUERY; i++)
523 ScQueryEntry& rEntry = rQueryParam.GetEntry(i);
525 rEntry.bDoQuery = bDoQuery[i];
526 rEntry.nField = nQueryField[i];
527 rEntry.eOp = eQueryOp[i];
528 rEntry.bQueryByString = bQueryByString[i];
529 *rEntry.pStr = *pQueryStr[i];
530 rEntry.nVal = nQueryVal[i];
531 rEntry.eConnect = eQueryConnect[i];
535 void ScDBData::SetQueryParam(const ScQueryParam& rQueryParam)
537 DBG_ASSERT( rQueryParam.GetEntryCount() <= MAXQUERY ||
538 !rQueryParam.GetEntry(MAXQUERY).bDoQuery,
539 "zuviele Eintraege bei ScDBData::SetQueryParam" );
541 // set bIsAdvanced to FALSE for everything that is not from the
542 // advanced filter dialog
543 bIsAdvanced = FALSE;
545 bQueryInplace = rQueryParam.bInplace;
546 bQueryCaseSens = rQueryParam.bCaseSens;
547 bQueryRegExp = rQueryParam.bRegExp;
548 bQueryDuplicate = rQueryParam.bDuplicate;
549 nQueryDestTab = rQueryParam.nDestTab;
550 nQueryDestCol = rQueryParam.nDestCol;
551 nQueryDestRow = rQueryParam.nDestRow;
552 for (SCSIZE i=0; i<MAXQUERY; i++)
554 ScQueryEntry& rEntry = rQueryParam.GetEntry(i);
556 bDoQuery[i] = rEntry.bDoQuery;
557 nQueryField[i] = rEntry.nField;
558 eQueryOp[i] = rEntry.eOp;
559 bQueryByString[i] = rEntry.bQueryByString;
560 *pQueryStr[i] = *rEntry.pStr;
561 nQueryVal[i] = rEntry.nVal;
562 eQueryConnect[i] = rEntry.eConnect;
566 void ScDBData::SetAdvancedQuerySource(const ScRange* pSource)
568 if (pSource)
570 aAdvSource = *pSource;
571 bIsAdvanced = TRUE;
573 else
574 bIsAdvanced = FALSE;
577 BOOL ScDBData::GetAdvancedQuerySource(ScRange& rSource) const
579 rSource = aAdvSource;
580 return bIsAdvanced;
583 void ScDBData::GetSubTotalParam(ScSubTotalParam& rSubTotalParam) const
585 USHORT i;
586 USHORT j;
588 rSubTotalParam.nCol1 = nStartCol;
589 rSubTotalParam.nRow1 = nStartRow;
590 rSubTotalParam.nCol2 = nEndCol;
591 rSubTotalParam.nRow2 = nEndRow;
593 rSubTotalParam.bRemoveOnly = bSubRemoveOnly;
594 rSubTotalParam.bReplace = bSubReplace;
595 rSubTotalParam.bPagebreak = bSubPagebreak;
596 rSubTotalParam.bCaseSens = bSubCaseSens;
597 rSubTotalParam.bDoSort = bSubDoSort;
598 rSubTotalParam.bAscending = bSubAscending;
599 rSubTotalParam.bIncludePattern = bSubIncludePattern;
600 rSubTotalParam.bUserDef = bSubUserDef;
601 rSubTotalParam.nUserIndex = nSubUserIndex;
603 for (i=0; i<MAXSUBTOTAL; i++)
605 rSubTotalParam.bGroupActive[i] = bDoSubTotal[i];
606 rSubTotalParam.nField[i] = nSubField[i];
607 SCCOL nCount = nSubTotals[i];
609 rSubTotalParam.nSubTotals[i] = nCount;
610 delete[] rSubTotalParam.pSubTotals[i];
611 delete[] rSubTotalParam.pFunctions[i];
612 rSubTotalParam.pSubTotals[i] = nCount > 0 ? new SCCOL[nCount] : NULL;
613 rSubTotalParam.pFunctions[i] = nCount > 0 ? new ScSubTotalFunc[nCount]
614 : NULL;
615 for (j=0; j<nCount; j++)
617 rSubTotalParam.pSubTotals[i][j] = pSubTotals[i][j];
618 rSubTotalParam.pFunctions[i][j] = pFunctions[i][j];
623 void ScDBData::SetSubTotalParam(const ScSubTotalParam& rSubTotalParam)
625 USHORT i;
626 USHORT j;
628 bSubRemoveOnly = rSubTotalParam.bRemoveOnly;
629 bSubReplace = rSubTotalParam.bReplace;
630 bSubPagebreak = rSubTotalParam.bPagebreak;
631 bSubCaseSens = rSubTotalParam.bCaseSens;
632 bSubDoSort = rSubTotalParam.bDoSort;
633 bSubAscending = rSubTotalParam.bAscending;
634 bSubIncludePattern = rSubTotalParam.bIncludePattern;
635 bSubUserDef = rSubTotalParam.bUserDef;
636 nSubUserIndex = rSubTotalParam.nUserIndex;
638 for (i=0; i<MAXSUBTOTAL; i++)
640 bDoSubTotal[i] = rSubTotalParam.bGroupActive[i];
641 nSubField[i] = rSubTotalParam.nField[i];
642 SCCOL nCount = rSubTotalParam.nSubTotals[i];
644 nSubTotals[i] = nCount;
645 delete[] pSubTotals[i];
646 delete[] pFunctions[i];
647 pSubTotals[i] = nCount > 0 ? new SCCOL [nCount] : NULL;
648 pFunctions[i] = nCount > 0 ? new ScSubTotalFunc [nCount] : NULL;
649 for (j=0; j<nCount; j++)
651 pSubTotals[i][j] = rSubTotalParam.pSubTotals[i][j];
652 pFunctions[i][j] = rSubTotalParam.pFunctions[i][j];
657 void ScDBData::GetImportParam(ScImportParam& rImportParam) const
659 rImportParam.nCol1 = nStartCol;
660 rImportParam.nRow1 = nStartRow;
661 rImportParam.nCol2 = nEndCol;
662 rImportParam.nRow2 = nEndRow;
664 rImportParam.bImport = bDBImport;
665 rImportParam.aDBName = aDBName;
666 rImportParam.aStatement = aDBStatement;
667 rImportParam.bNative = bDBNative;
668 rImportParam.bSql = bDBSql;
669 rImportParam.nType = nDBType;
672 void ScDBData::SetImportParam(const ScImportParam& rImportParam)
674 bDBImport = rImportParam.bImport;
675 aDBName = rImportParam.aDBName;
676 aDBStatement = rImportParam.aStatement;
677 bDBNative = rImportParam.bNative;
678 bDBSql = rImportParam.bSql;
679 nDBType = rImportParam.nType;
682 BOOL ScDBData::IsDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, BOOL bStartOnly) const
684 if (nTab == nTable)
686 if ( bStartOnly )
687 return ( nCol == nStartCol && nRow == nStartRow );
688 else
689 return ( nCol >= nStartCol && nCol <= nEndCol &&
690 nRow >= nStartRow && nRow <= nEndRow );
693 return FALSE;
696 BOOL ScDBData::IsDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const
698 return (BOOL)((nTab == nTable)
699 && (nCol1 == nStartCol) && (nRow1 == nStartRow)
700 && (nCol2 == nEndCol) && (nRow2 == nEndRow));
703 ScDataObject* ScDBData::Clone() const
705 return new ScDBData(*this);
709 //---------------------------------------------------------------------------------------
710 // Compare zum Sortieren
712 short ScDBCollection::Compare(ScDataObject* pKey1, ScDataObject* pKey2) const
714 const String& rStr1 = ((ScDBData*)pKey1)->GetName();
715 const String& rStr2 = ((ScDBData*)pKey2)->GetName();
716 return (short) ScGlobal::pTransliteration->compareString( rStr1, rStr2 );
719 // IsEqual - alles gleich
721 BOOL ScDBCollection::IsEqual(ScDataObject* pKey1, ScDataObject* pKey2) const
723 return *(ScDBData*)pKey1 == *(ScDBData*)pKey2;
726 ScDBData* ScDBCollection::GetDBAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab, BOOL bStartOnly) const
728 ScDBData* pNoNameData = NULL;
729 if (pItems)
731 const String& rNoName = ScGlobal::GetRscString( STR_DB_NONAME );
733 for (USHORT i = 0; i < nCount; i++)
734 if (((ScDBData*)pItems[i])->IsDBAtCursor(nCol, nRow, nTab, bStartOnly))
736 ScDBData* pDB = (ScDBData*)pItems[i];
737 if ( pDB->GetName() == rNoName )
738 pNoNameData = pDB;
739 else
740 return pDB;
743 return pNoNameData; // "unbenannt" nur zurueck, wenn sonst nichts gefunden
746 ScDBData* ScDBCollection::GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const
748 ScDBData* pNoNameData = NULL;
749 if (pItems)
751 const String& rNoName = ScGlobal::GetRscString( STR_DB_NONAME );
753 for (USHORT i = 0; i < nCount; i++)
754 if (((ScDBData*)pItems[i])->IsDBAtArea(nTab, nCol1, nRow1, nCol2, nRow2))
756 ScDBData* pDB = (ScDBData*)pItems[i];
757 if ( pDB->GetName() == rNoName )
758 pNoNameData = pDB;
759 else
760 return pDB;
763 return pNoNameData; // "unbenannt" nur zurueck, wenn sonst nichts gefunden
766 BOOL ScDBCollection::SearchName( const String& rName, USHORT& rIndex ) const
768 ScDBData aDataObj( rName, 0,0,0,0,0 );
769 return Search( &aDataObj, rIndex );
772 void ScDBCollection::DeleteOnTab( SCTAB nTab )
774 USHORT nPos = 0;
775 while ( nPos < nCount )
777 // look for output positions on the deleted sheet
779 SCCOL nEntryCol1, nEntryCol2;
780 SCROW nEntryRow1, nEntryRow2;
781 SCTAB nEntryTab;
782 static_cast<const ScDBData*>(At(nPos))->GetArea( nEntryTab, nEntryCol1, nEntryRow1, nEntryCol2, nEntryRow2 );
783 if ( nEntryTab == nTab )
784 AtFree(nPos);
785 else
786 ++nPos;
790 void ScDBCollection::UpdateReference(UpdateRefMode eUpdateRefMode,
791 SCCOL nCol1, SCROW nRow1, SCTAB nTab1,
792 SCCOL nCol2, SCROW nRow2, SCTAB nTab2,
793 SCsCOL nDx, SCsROW nDy, SCsTAB nDz )
795 for (USHORT i=0; i<nCount; i++)
797 SCCOL theCol1;
798 SCROW theRow1;
799 SCTAB theTab1;
800 SCCOL theCol2;
801 SCROW theRow2;
802 SCTAB theTab2;
803 ((ScDBData*)pItems[i])->GetArea( theTab1, theCol1, theRow1, theCol2, theRow2 );
804 theTab2 = theTab1;
806 BOOL bDoUpdate = ScRefUpdate::Update( pDoc, eUpdateRefMode,
807 nCol1,nRow1,nTab1, nCol2,nRow2,nTab2, nDx,nDy,nDz,
808 theCol1,theRow1,theTab1, theCol2,theRow2,theTab2 ) != UR_NOTHING;
809 if (bDoUpdate)
810 ((ScDBData*)pItems[i])->MoveTo( theTab1, theCol1, theRow1, theCol2, theRow2 );
812 ScRange aAdvSource;
813 if ( ((ScDBData*)pItems[i])->GetAdvancedQuerySource(aAdvSource) )
815 aAdvSource.GetVars( theCol1,theRow1,theTab1, theCol2,theRow2,theTab2 );
816 if ( ScRefUpdate::Update( pDoc, eUpdateRefMode,
817 nCol1,nRow1,nTab1, nCol2,nRow2,nTab2, nDx,nDy,nDz,
818 theCol1,theRow1,theTab1, theCol2,theRow2,theTab2 ) )
820 aAdvSource.aStart.Set( theCol1,theRow1,theTab1 );
821 aAdvSource.aEnd.Set( theCol2,theRow2,theTab2 );
822 ((ScDBData*)pItems[i])->SetAdvancedQuerySource( &aAdvSource );
824 bDoUpdate = TRUE; // DBData is modified
828 ((ScDBData*)pItems[i])->SetModified(bDoUpdate);
830 //! Testen, ob mitten aus dem Bereich geloescht/eingefuegt wurde !!!
835 void ScDBCollection::UpdateMoveTab( SCTAB nOldPos, SCTAB nNewPos )
837 // wenn nOldPos vor nNewPos liegt, ist nNewPos schon angepasst
839 for (USHORT i=0; i<nCount; i++)
841 ScRange aRange;
842 ScDBData* pData = (ScDBData*)pItems[i];
843 pData->GetArea( aRange );
844 SCTAB nTab = aRange.aStart.Tab(); // hat nur eine Tabelle
846 // anpassen wie die aktuelle Tabelle bei ScTablesHint (tabvwsh5.cxx)
848 if ( nTab == nOldPos ) // verschobene Tabelle
849 nTab = nNewPos;
850 else if ( nOldPos < nNewPos ) // nach hinten verschoben
852 if ( nTab > nOldPos && nTab <= nNewPos ) // nachrueckender Bereich
853 --nTab;
855 else // nach vorne verschoben
857 if ( nTab >= nNewPos && nTab < nOldPos ) // nachrueckender Bereich
858 ++nTab;
861 BOOL bChanged = ( nTab != aRange.aStart.Tab() );
862 if (bChanged)
863 pData->SetArea( nTab, aRange.aStart.Col(), aRange.aStart.Row(),
864 aRange.aEnd.Col(),aRange.aEnd .Row() );
866 // MoveTo ist nicht noetig, wenn nur die Tabelle geaendert ist
868 pData->SetModified(bChanged);
873 ScDBData* ScDBCollection::FindIndex(USHORT nIndex)
875 USHORT i = 0;
876 while (i < nCount)
878 if ((*this)[i]->GetIndex() == nIndex)
879 return (*this)[i];
880 i++;
882 return NULL;
885 BOOL ScDBCollection::Insert(ScDataObject* pScDataObject)
887 ScDBData* pData = (ScDBData*) pScDataObject;
888 if (!pData->GetIndex()) // schon gesetzt?
889 pData->SetIndex(nEntryIndex++);
890 BOOL bInserted = ScSortedCollection::Insert(pScDataObject);
891 if ( bInserted && pData->HasImportParam() && !pData->HasImportSelection() )
893 pData->SetRefreshHandler( GetRefreshHandler() );
894 pData->SetRefreshControl( pDoc->GetRefreshTimerControlAddress() );
896 return bInserted;