1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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"
40 #include "refupdat.hxx"
41 #include "rechead.hxx"
42 #include "document.hxx"
43 #include "queryparam.hxx"
44 #include "globstr.hrc"
47 //---------------------------------------------------------------------------------------
49 ScDBData::ScDBData( const String
& rName
,
51 SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
,
52 BOOL bByR
, BOOL bHasH
) :
72 ScSortParam aSortParam
;
73 ScQueryParam aQueryParam
;
74 ScSubTotalParam aSubTotalParam
;
75 ScImportParam aImportParam
;
77 for (i
=0; i
<MAXQUERY
; i
++)
78 pQueryStr
[i
] = new String
;
80 for (i
=0; i
<MAXSUBTOTAL
; i
++)
87 SetSortParam( aSortParam
);
88 SetQueryParam( aQueryParam
);
89 SetSubTotalParam( aSubTotalParam
);
90 SetImportParam( aImportParam
);
93 ScDBData::ScDBData( const ScDBData
& rData
) :
95 ScRefreshTimer ( rData
),
97 nTable (rData
.nTable
),
98 nStartCol (rData
.nStartCol
),
99 nStartRow (rData
.nStartRow
),
100 nEndCol (rData
.nEndCol
),
101 nEndRow (rData
.nEndRow
),
102 bByRow (rData
.bByRow
),
103 bHasHeader (rData
.bHasHeader
),
104 bDoSize (rData
.bDoSize
),
105 bKeepFmt (rData
.bKeepFmt
),
106 bStripData (rData
.bStripData
),
107 bSortCaseSens (rData
.bSortCaseSens
),
108 bSortNaturalSort (rData
.bSortNaturalSort
),
109 bIncludePattern (rData
.bIncludePattern
),
110 bSortInplace (rData
.bSortInplace
),
111 bSortUserDef (rData
.bSortUserDef
),
112 nSortUserIndex (rData
.nSortUserIndex
),
113 nSortDestTab (rData
.nSortDestTab
),
114 nSortDestCol (rData
.nSortDestCol
),
115 nSortDestRow (rData
.nSortDestRow
),
116 aSortLocale (rData
.aSortLocale
),
117 aSortAlgorithm (rData
.aSortAlgorithm
),
118 bQueryInplace (rData
.bQueryInplace
),
119 bQueryCaseSens (rData
.bQueryCaseSens
),
120 bQueryRegExp (rData
.bQueryRegExp
),
121 bQueryDuplicate (rData
.bQueryDuplicate
),
122 nQueryDestTab (rData
.nQueryDestTab
),
123 nQueryDestCol (rData
.nQueryDestCol
),
124 nQueryDestRow (rData
.nQueryDestRow
),
125 bIsAdvanced (rData
.bIsAdvanced
),
126 aAdvSource (rData
.aAdvSource
),
127 bSubRemoveOnly (rData
.bSubRemoveOnly
),
128 bSubReplace (rData
.bSubReplace
),
129 bSubPagebreak (rData
.bSubPagebreak
),
130 bSubCaseSens (rData
.bSubCaseSens
),
131 bSubDoSort (rData
.bSubDoSort
),
132 bSubAscending (rData
.bSubAscending
),
133 bSubIncludePattern (rData
.bSubIncludePattern
),
134 bSubUserDef (rData
.bSubUserDef
),
135 nSubUserIndex (rData
.nSubUserIndex
),
136 bDBImport (rData
.bDBImport
),
137 aDBName (rData
.aDBName
),
138 aDBStatement (rData
.aDBStatement
),
139 bDBNative (rData
.bDBNative
),
140 bDBSelection (rData
.bDBSelection
),
141 bDBSql (rData
.bDBSql
),
142 nDBType (rData
.nDBType
),
143 nIndex (rData
.nIndex
),
144 bAutoFilter (rData
.bAutoFilter
),
145 bModified (rData
.bModified
)
150 for (i
=0; i
<MAXSORT
; i
++)
152 bDoSort
[i
] = rData
.bDoSort
[i
];
153 nSortField
[i
] = rData
.nSortField
[i
];
154 bAscending
[i
] = rData
.bAscending
[i
];
156 for (i
=0; i
<MAXQUERY
; i
++)
158 bDoQuery
[i
] = rData
.bDoQuery
[i
];
159 nQueryField
[i
] = rData
.nQueryField
[i
];
160 eQueryOp
[i
] = rData
.eQueryOp
[i
];
161 bQueryByString
[i
] = rData
.bQueryByString
[i
];
162 bQueryByDate
[i
] = rData
.bQueryByDate
[i
];
163 pQueryStr
[i
] = new String( *(rData
.pQueryStr
[i
]) );
164 nQueryVal
[i
] = rData
.nQueryVal
[i
];
165 eQueryConnect
[i
] = rData
.eQueryConnect
[i
];
167 for (i
=0; i
<MAXSUBTOTAL
; i
++)
169 bDoSubTotal
[i
] = rData
.bDoSubTotal
[i
];
170 nSubField
[i
] = rData
.nSubField
[i
];
172 SCCOL nCount
= rData
.nSubTotals
[i
];
173 nSubTotals
[i
] = nCount
;
174 pFunctions
[i
] = nCount
> 0 ? new ScSubTotalFunc
[nCount
] : NULL
;
175 pSubTotals
[i
] = nCount
> 0 ? new SCCOL
[nCount
] : NULL
;
177 for (j
=0; j
<nCount
; j
++)
179 pSubTotals
[i
][j
] = rData
.pSubTotals
[i
][j
];
180 pFunctions
[i
][j
] = rData
.pFunctions
[i
][j
];
185 ScDBData
& ScDBData::operator= (const ScDBData
& rData
)
190 ScRefreshTimer::operator=( rData
);
192 nTable
= rData
.nTable
;
193 nStartCol
= rData
.nStartCol
;
194 nStartRow
= rData
.nStartRow
;
195 nEndCol
= rData
.nEndCol
;
196 nEndRow
= rData
.nEndRow
;
197 bByRow
= rData
.bByRow
;
198 bHasHeader
= rData
.bHasHeader
;
199 bDoSize
= rData
.bDoSize
;
200 bKeepFmt
= rData
.bKeepFmt
;
201 bStripData
= rData
.bStripData
;
202 bSortCaseSens
= rData
.bSortCaseSens
;
203 bSortNaturalSort
= rData
.bSortNaturalSort
;
204 bIncludePattern
= rData
.bIncludePattern
;
205 bSortInplace
= rData
.bSortInplace
;
206 nSortDestTab
= rData
.nSortDestTab
;
207 nSortDestCol
= rData
.nSortDestCol
;
208 nSortDestRow
= rData
.nSortDestRow
;
209 bSortUserDef
= rData
.bSortUserDef
;
210 nSortUserIndex
= rData
.nSortUserIndex
;
211 aSortLocale
= rData
.aSortLocale
;
212 aSortAlgorithm
= rData
.aSortAlgorithm
;
213 bQueryInplace
= rData
.bQueryInplace
;
214 bQueryCaseSens
= rData
.bQueryCaseSens
;
215 bQueryRegExp
= rData
.bQueryRegExp
;
216 bQueryDuplicate
= rData
.bQueryDuplicate
;
217 nQueryDestTab
= rData
.nQueryDestTab
;
218 nQueryDestCol
= rData
.nQueryDestCol
;
219 nQueryDestRow
= rData
.nQueryDestRow
;
220 bIsAdvanced
= rData
.bIsAdvanced
;
221 aAdvSource
= rData
.aAdvSource
;
222 bSubRemoveOnly
= rData
.bSubRemoveOnly
;
223 bSubReplace
= rData
.bSubReplace
;
224 bSubPagebreak
= rData
.bSubPagebreak
;
225 bSubCaseSens
= rData
.bSubCaseSens
;
226 bSubDoSort
= rData
.bSubDoSort
;
227 bSubAscending
= rData
.bSubAscending
;
228 bSubIncludePattern
= rData
.bSubIncludePattern
;
229 bSubUserDef
= rData
.bSubUserDef
;
230 nSubUserIndex
= rData
.nSubUserIndex
;
231 bDBImport
= rData
.bDBImport
;
232 aDBName
= rData
.aDBName
;
233 aDBStatement
= rData
.aDBStatement
;
234 bDBNative
= rData
.bDBNative
;
235 bDBSelection
= rData
.bDBSelection
;
236 bDBSql
= rData
.bDBSql
;
237 nDBType
= rData
.nDBType
;
238 nIndex
= rData
.nIndex
;
239 bAutoFilter
= rData
.bAutoFilter
;
241 for (i
=0; i
<MAXSORT
; i
++)
243 bDoSort
[i
] = rData
.bDoSort
[i
];
244 nSortField
[i
] = rData
.nSortField
[i
];
245 bAscending
[i
] = rData
.bAscending
[i
];
247 for (i
=0; i
<MAXQUERY
; i
++)
249 bDoQuery
[i
] = rData
.bDoQuery
[i
];
250 nQueryField
[i
] = rData
.nQueryField
[i
];
251 eQueryOp
[i
] = rData
.eQueryOp
[i
];
252 bQueryByString
[i
] = rData
.bQueryByString
[i
];
253 bQueryByDate
[i
] = rData
.bQueryByDate
[i
];
254 *pQueryStr
[i
] = *rData
.pQueryStr
[i
];
255 nQueryVal
[i
] = rData
.nQueryVal
[i
];
256 eQueryConnect
[i
] = rData
.eQueryConnect
[i
];
258 for (i
=0; i
<MAXSUBTOTAL
; i
++)
260 bDoSubTotal
[i
] = rData
.bDoSubTotal
[i
];
261 nSubField
[i
] = rData
.nSubField
[i
];
262 SCCOL nCount
= rData
.nSubTotals
[i
];
263 nSubTotals
[i
] = nCount
;
265 delete[] pSubTotals
[i
];
266 delete[] pFunctions
[i
];
268 pSubTotals
[i
] = nCount
> 0 ? new SCCOL
[nCount
] : NULL
;
269 pFunctions
[i
] = nCount
> 0 ? new ScSubTotalFunc
[nCount
] : NULL
;
270 for (j
=0; j
<nCount
; j
++)
272 pSubTotals
[i
][j
] = rData
.pSubTotals
[i
][j
];
273 pFunctions
[i
][j
] = rData
.pFunctions
[i
][j
];
280 BOOL
ScDBData::operator== (const ScDBData
& rData
) const
282 // Daten, die nicht in den Params sind
284 if ( nTable
!= rData
.nTable
||
285 bDoSize
!= rData
.bDoSize
||
286 bKeepFmt
!= rData
.bKeepFmt
||
287 bIsAdvanced
!= rData
.bIsAdvanced
||
288 bStripData
!= rData
.bStripData
||
289 // SAB: I think this should be here, but I don't want to break something
290 // bAutoFilter!= rData.bAutoFilter||
291 ScRefreshTimer::operator!=( rData
)
295 if ( bIsAdvanced
&& aAdvSource
!= rData
.aAdvSource
)
298 ScSortParam aSort1
, aSort2
;
299 GetSortParam(aSort1
);
300 rData
.GetSortParam(aSort2
);
301 if (!(aSort1
== aSort2
))
304 ScQueryParam aQuery1
, aQuery2
;
305 GetQueryParam(aQuery1
);
306 rData
.GetQueryParam(aQuery2
);
307 if (!(aQuery1
== aQuery2
))
310 ScSubTotalParam aSubTotal1
, aSubTotal2
;
311 GetSubTotalParam(aSubTotal1
);
312 rData
.GetSubTotalParam(aSubTotal2
);
313 if (!(aSubTotal1
== aSubTotal2
))
316 ScImportParam aImport1
, aImport2
;
317 GetImportParam(aImport1
);
318 rData
.GetImportParam(aImport2
);
319 if (!(aImport1
== aImport2
))
325 ScDBData::~ScDBData()
330 for (i
=0; i
<MAXQUERY
; i
++)
332 for (i
=0; i
<MAXSUBTOTAL
; i
++)
334 delete[] pSubTotals
[i
];
335 delete[] pFunctions
[i
];
339 //UNUSED2008-05 BOOL ScDBData::IsBeyond(SCROW nMaxRow) const
341 //UNUSED2008-05 return ( nStartRow > nMaxRow ||
342 //UNUSED2008-05 nEndRow > nMaxRow ||
343 //UNUSED2008-05 nQueryDestRow > nMaxRow );
346 String
ScDBData::GetSourceString() const
353 aVal
+= aDBStatement
;
358 String
ScDBData::GetOperations() const
362 aVal
= ScGlobal::GetRscString(STR_OPERATION_FILTER
);
367 aVal
.AppendAscii( RTL_CONSTASCII_STRINGPARAM(", ") );
368 aVal
+= ScGlobal::GetRscString(STR_OPERATION_SORT
);
371 if (bDoSubTotal
[0] && !bSubRemoveOnly
)
374 aVal
.AppendAscii( RTL_CONSTASCII_STRINGPARAM(", ") );
375 aVal
+= ScGlobal::GetRscString(STR_OPERATION_SUBTOTAL
);
379 aVal
= ScGlobal::GetRscString(STR_OPERATION_NONE
);
384 void ScDBData::GetArea(SCTAB
& rTab
, SCCOL
& rCol1
, SCROW
& rRow1
, SCCOL
& rCol2
, SCROW
& rRow2
,
385 bool bUseDynamicRange
) const
391 rRow2
= bUseDynamicRange
? nDynamicEndRow
: nEndRow
;
394 void ScDBData::GetArea(ScRange
& rRange
, bool bUseDynamicRange
) const
396 SCROW nNewEndRow
= bUseDynamicRange
? nDynamicEndRow
: nEndRow
;
397 rRange
= ScRange( nStartCol
, nStartRow
, nTable
, nEndCol
, nNewEndRow
, nTable
);
400 void ScDBData::SetArea(SCTAB nTab
, SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
)
409 void ScDBData::SetDynamicEndRow(SCROW nRow
)
411 nDynamicEndRow
= nRow
;
414 void ScDBData::MoveTo(SCTAB nTab
, SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
)
417 long nDifX
= ((long) nCol1
) - ((long) nStartCol
);
418 long nDifY
= ((long) nRow1
) - ((long) nStartRow
);
420 long nSortDif
= bByRow
? nDifX
: nDifY
;
421 long nSortEnd
= bByRow
? static_cast<long>(nCol2
) : static_cast<long>(nRow2
);
423 for (i
=0; i
<MAXSORT
; i
++)
425 nSortField
[i
] += nSortDif
;
426 if (nSortField
[i
] > nSortEnd
)
432 for (i
=0; i
<MAXQUERY
; i
++)
434 nQueryField
[i
] += nDifX
;
435 if (nQueryField
[i
] > nCol2
)
441 for (i
=0; i
<MAXSUBTOTAL
; i
++)
443 nSubField
[i
] = sal::static_int_cast
<SCCOL
>( nSubField
[i
] + nDifX
);
444 if (nSubField
[i
] > nCol2
)
447 bDoSubTotal
[i
] = FALSE
;
451 SetArea( nTab
, nCol1
, nRow1
, nCol2
, nRow2
);
454 void ScDBData::GetSortParam( ScSortParam
& rSortParam
) const
456 rSortParam
.nCol1
= nStartCol
;
457 rSortParam
.nRow1
= nStartRow
;
458 rSortParam
.nCol2
= nEndCol
;
459 rSortParam
.nRow2
= nEndRow
;
460 rSortParam
.bByRow
= bByRow
;
461 rSortParam
.bHasHeader
= bHasHeader
;
462 rSortParam
.bCaseSens
= bSortCaseSens
;
463 rSortParam
.bNaturalSort
= bSortNaturalSort
;
464 rSortParam
.bInplace
= bSortInplace
;
465 rSortParam
.nDestTab
= nSortDestTab
;
466 rSortParam
.nDestCol
= nSortDestCol
;
467 rSortParam
.nDestRow
= nSortDestRow
;
468 rSortParam
.bIncludePattern
= bIncludePattern
;
469 rSortParam
.bUserDef
= bSortUserDef
;
470 rSortParam
.nUserIndex
= nSortUserIndex
;
471 for (USHORT i
=0; i
<MAXSORT
; i
++)
473 rSortParam
.bDoSort
[i
] = bDoSort
[i
];
474 rSortParam
.nField
[i
] = nSortField
[i
];
475 rSortParam
.bAscending
[i
] = bAscending
[i
];
477 rSortParam
.aCollatorLocale
= aSortLocale
;
478 rSortParam
.aCollatorAlgorithm
= aSortAlgorithm
;
481 void ScDBData::SetSortParam( const ScSortParam
& rSortParam
)
483 bSortCaseSens
= rSortParam
.bCaseSens
;
484 bSortNaturalSort
= rSortParam
.bNaturalSort
;
485 bIncludePattern
= rSortParam
.bIncludePattern
;
486 bSortInplace
= rSortParam
.bInplace
;
487 nSortDestTab
= rSortParam
.nDestTab
;
488 nSortDestCol
= rSortParam
.nDestCol
;
489 nSortDestRow
= rSortParam
.nDestRow
;
490 bSortUserDef
= rSortParam
.bUserDef
;
491 nSortUserIndex
= rSortParam
.nUserIndex
;
492 for (USHORT i
=0; i
<MAXSORT
; i
++)
494 bDoSort
[i
] = rSortParam
.bDoSort
[i
];
495 nSortField
[i
] = rSortParam
.nField
[i
];
496 bAscending
[i
] = rSortParam
.bAscending
[i
];
498 aSortLocale
= rSortParam
.aCollatorLocale
;
499 aSortAlgorithm
= rSortParam
.aCollatorAlgorithm
;
501 //#98317#; set the orientation
502 bByRow
= rSortParam
.bByRow
;
505 void ScDBData::GetQueryParam( ScQueryParam
& rQueryParam
) const
507 rQueryParam
.nCol1
= nStartCol
;
508 rQueryParam
.nRow1
= nStartRow
;
509 rQueryParam
.nCol2
= nEndCol
;
510 rQueryParam
.nRow2
= nEndRow
;
511 rQueryParam
.nTab
= nTable
;
512 rQueryParam
.bByRow
= bByRow
;
513 rQueryParam
.bHasHeader
= bHasHeader
;
514 rQueryParam
.bInplace
= bQueryInplace
;
515 rQueryParam
.bCaseSens
= bQueryCaseSens
;
516 rQueryParam
.bRegExp
= bQueryRegExp
;
517 rQueryParam
.bDuplicate
= bQueryDuplicate
;
518 rQueryParam
.nDestTab
= nQueryDestTab
;
519 rQueryParam
.nDestCol
= nQueryDestCol
;
520 rQueryParam
.nDestRow
= nQueryDestRow
;
521 rQueryParam
.nDynamicEndRow
= nDynamicEndRow
;
523 rQueryParam
.Resize( MAXQUERY
);
524 for (SCSIZE i
=0; i
<MAXQUERY
; i
++)
526 ScQueryEntry
& rEntry
= rQueryParam
.GetEntry(i
);
528 rEntry
.bDoQuery
= bDoQuery
[i
];
529 rEntry
.nField
= nQueryField
[i
];
530 rEntry
.eOp
= eQueryOp
[i
];
531 rEntry
.bQueryByString
= bQueryByString
[i
];
532 rEntry
.bQueryByDate
= bQueryByDate
[i
];
533 *rEntry
.pStr
= *pQueryStr
[i
];
534 rEntry
.nVal
= nQueryVal
[i
];
535 rEntry
.eConnect
= eQueryConnect
[i
];
539 void ScDBData::SetQueryParam(const ScQueryParam
& rQueryParam
)
541 DBG_ASSERT( rQueryParam
.GetEntryCount() <= MAXQUERY
||
542 !rQueryParam
.GetEntry(MAXQUERY
).bDoQuery
,
543 "zuviele Eintraege bei ScDBData::SetQueryParam" );
545 // set bIsAdvanced to FALSE for everything that is not from the
546 // advanced filter dialog
549 bQueryInplace
= rQueryParam
.bInplace
;
550 bQueryCaseSens
= rQueryParam
.bCaseSens
;
551 bQueryRegExp
= rQueryParam
.bRegExp
;
552 bQueryDuplicate
= rQueryParam
.bDuplicate
;
553 nQueryDestTab
= rQueryParam
.nDestTab
;
554 nQueryDestCol
= rQueryParam
.nDestCol
;
555 nQueryDestRow
= rQueryParam
.nDestRow
;
556 for (SCSIZE i
=0; i
<MAXQUERY
; i
++)
558 ScQueryEntry
& rEntry
= rQueryParam
.GetEntry(i
);
560 bDoQuery
[i
] = rEntry
.bDoQuery
;
561 nQueryField
[i
] = rEntry
.nField
;
562 eQueryOp
[i
] = rEntry
.eOp
;
563 bQueryByString
[i
] = rEntry
.bQueryByString
;
564 bQueryByDate
[i
] = rEntry
.bQueryByDate
;
565 *pQueryStr
[i
] = *rEntry
.pStr
;
566 nQueryVal
[i
] = rEntry
.nVal
;
567 eQueryConnect
[i
] = rEntry
.eConnect
;
571 void ScDBData::SetAdvancedQuerySource(const ScRange
* pSource
)
575 aAdvSource
= *pSource
;
582 BOOL
ScDBData::GetAdvancedQuerySource(ScRange
& rSource
) const
584 rSource
= aAdvSource
;
588 void ScDBData::GetSubTotalParam(ScSubTotalParam
& rSubTotalParam
) const
593 rSubTotalParam
.nCol1
= nStartCol
;
594 rSubTotalParam
.nRow1
= nStartRow
;
595 rSubTotalParam
.nCol2
= nEndCol
;
596 rSubTotalParam
.nRow2
= nEndRow
;
598 rSubTotalParam
.bRemoveOnly
= bSubRemoveOnly
;
599 rSubTotalParam
.bReplace
= bSubReplace
;
600 rSubTotalParam
.bPagebreak
= bSubPagebreak
;
601 rSubTotalParam
.bCaseSens
= bSubCaseSens
;
602 rSubTotalParam
.bDoSort
= bSubDoSort
;
603 rSubTotalParam
.bAscending
= bSubAscending
;
604 rSubTotalParam
.bIncludePattern
= bSubIncludePattern
;
605 rSubTotalParam
.bUserDef
= bSubUserDef
;
606 rSubTotalParam
.nUserIndex
= nSubUserIndex
;
608 for (i
=0; i
<MAXSUBTOTAL
; i
++)
610 rSubTotalParam
.bGroupActive
[i
] = bDoSubTotal
[i
];
611 rSubTotalParam
.nField
[i
] = nSubField
[i
];
612 SCCOL nCount
= nSubTotals
[i
];
614 rSubTotalParam
.nSubTotals
[i
] = nCount
;
615 delete[] rSubTotalParam
.pSubTotals
[i
];
616 delete[] rSubTotalParam
.pFunctions
[i
];
617 rSubTotalParam
.pSubTotals
[i
] = nCount
> 0 ? new SCCOL
[nCount
] : NULL
;
618 rSubTotalParam
.pFunctions
[i
] = nCount
> 0 ? new ScSubTotalFunc
[nCount
]
620 for (j
=0; j
<nCount
; j
++)
622 rSubTotalParam
.pSubTotals
[i
][j
] = pSubTotals
[i
][j
];
623 rSubTotalParam
.pFunctions
[i
][j
] = pFunctions
[i
][j
];
628 void ScDBData::SetSubTotalParam(const ScSubTotalParam
& rSubTotalParam
)
633 bSubRemoveOnly
= rSubTotalParam
.bRemoveOnly
;
634 bSubReplace
= rSubTotalParam
.bReplace
;
635 bSubPagebreak
= rSubTotalParam
.bPagebreak
;
636 bSubCaseSens
= rSubTotalParam
.bCaseSens
;
637 bSubDoSort
= rSubTotalParam
.bDoSort
;
638 bSubAscending
= rSubTotalParam
.bAscending
;
639 bSubIncludePattern
= rSubTotalParam
.bIncludePattern
;
640 bSubUserDef
= rSubTotalParam
.bUserDef
;
641 nSubUserIndex
= rSubTotalParam
.nUserIndex
;
643 for (i
=0; i
<MAXSUBTOTAL
; i
++)
645 bDoSubTotal
[i
] = rSubTotalParam
.bGroupActive
[i
];
646 nSubField
[i
] = rSubTotalParam
.nField
[i
];
647 SCCOL nCount
= rSubTotalParam
.nSubTotals
[i
];
649 nSubTotals
[i
] = nCount
;
650 delete[] pSubTotals
[i
];
651 delete[] pFunctions
[i
];
652 pSubTotals
[i
] = nCount
> 0 ? new SCCOL
[nCount
] : NULL
;
653 pFunctions
[i
] = nCount
> 0 ? new ScSubTotalFunc
[nCount
] : NULL
;
654 for (j
=0; j
<nCount
; j
++)
656 pSubTotals
[i
][j
] = rSubTotalParam
.pSubTotals
[i
][j
];
657 pFunctions
[i
][j
] = rSubTotalParam
.pFunctions
[i
][j
];
662 void ScDBData::GetImportParam(ScImportParam
& rImportParam
) const
664 rImportParam
.nCol1
= nStartCol
;
665 rImportParam
.nRow1
= nStartRow
;
666 rImportParam
.nCol2
= nEndCol
;
667 rImportParam
.nRow2
= nEndRow
;
669 rImportParam
.bImport
= bDBImport
;
670 rImportParam
.aDBName
= aDBName
;
671 rImportParam
.aStatement
= aDBStatement
;
672 rImportParam
.bNative
= bDBNative
;
673 rImportParam
.bSql
= bDBSql
;
674 rImportParam
.nType
= nDBType
;
677 void ScDBData::SetImportParam(const ScImportParam
& rImportParam
)
679 bDBImport
= rImportParam
.bImport
;
680 aDBName
= rImportParam
.aDBName
;
681 aDBStatement
= rImportParam
.aStatement
;
682 bDBNative
= rImportParam
.bNative
;
683 bDBSql
= rImportParam
.bSql
;
684 nDBType
= rImportParam
.nType
;
687 BOOL
ScDBData::IsDBAtCursor(SCCOL nCol
, SCROW nRow
, SCTAB nTab
, BOOL bStartOnly
) const
692 return ( nCol
== nStartCol
&& nRow
== nStartRow
);
694 return ( nCol
>= nStartCol
&& nCol
<= nEndCol
&&
695 nRow
>= nStartRow
&& nRow
<= nEndRow
);
701 BOOL
ScDBData::IsDBAtArea(SCTAB nTab
, SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
) const
703 return (BOOL
)((nTab
== nTable
)
704 && (nCol1
== nStartCol
) && (nRow1
== nStartRow
)
705 && (nCol2
== nEndCol
) && (nRow2
== nEndRow
));
708 ScDataObject
* ScDBData::Clone() const
710 return new ScDBData(*this);
714 //---------------------------------------------------------------------------------------
715 // Compare zum Sortieren
717 short ScDBCollection::Compare(ScDataObject
* pKey1
, ScDataObject
* pKey2
) const
719 const String
& rStr1
= ((ScDBData
*)pKey1
)->GetName();
720 const String
& rStr2
= ((ScDBData
*)pKey2
)->GetName();
721 return (short) ScGlobal::GetpTransliteration()->compareString( rStr1
, rStr2
);
724 // IsEqual - alles gleich
726 BOOL
ScDBCollection::IsEqual(ScDataObject
* pKey1
, ScDataObject
* pKey2
) const
728 return *(ScDBData
*)pKey1
== *(ScDBData
*)pKey2
;
731 ScDBData
* ScDBCollection::GetDBAtCursor(SCCOL nCol
, SCROW nRow
, SCTAB nTab
, BOOL bStartOnly
) const
733 ScDBData
* pNoNameData
= NULL
;
736 const String
& rNoName
= ScGlobal::GetRscString( STR_DB_NONAME
);
738 for (USHORT i
= 0; i
< nCount
; i
++)
739 if (((ScDBData
*)pItems
[i
])->IsDBAtCursor(nCol
, nRow
, nTab
, bStartOnly
))
741 ScDBData
* pDB
= (ScDBData
*)pItems
[i
];
742 if ( pDB
->GetName() == rNoName
)
748 return pNoNameData
; // "unbenannt" nur zurueck, wenn sonst nichts gefunden
751 ScDBData
* ScDBCollection::GetDBAtArea(SCTAB nTab
, SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
) const
753 ScDBData
* pNoNameData
= NULL
;
756 const String
& rNoName
= ScGlobal::GetRscString( STR_DB_NONAME
);
758 for (USHORT i
= 0; i
< nCount
; i
++)
759 if (((ScDBData
*)pItems
[i
])->IsDBAtArea(nTab
, nCol1
, nRow1
, nCol2
, nRow2
))
761 ScDBData
* pDB
= (ScDBData
*)pItems
[i
];
762 if ( pDB
->GetName() == rNoName
)
768 return pNoNameData
; // "unbenannt" nur zurueck, wenn sonst nichts gefunden
771 BOOL
ScDBCollection::SearchName( const String
& rName
, USHORT
& rIndex
) const
773 ScDBData
aDataObj( rName
, 0,0,0,0,0 );
774 return Search( &aDataObj
, rIndex
);
777 void ScDBCollection::DeleteOnTab( SCTAB nTab
)
780 while ( nPos
< nCount
)
782 // look for output positions on the deleted sheet
784 SCCOL nEntryCol1
, nEntryCol2
;
785 SCROW nEntryRow1
, nEntryRow2
;
787 static_cast<const ScDBData
*>(At(nPos
))->GetArea( nEntryTab
, nEntryCol1
, nEntryRow1
, nEntryCol2
, nEntryRow2
);
788 if ( nEntryTab
== nTab
)
795 void ScDBCollection::UpdateReference(UpdateRefMode eUpdateRefMode
,
796 SCCOL nCol1
, SCROW nRow1
, SCTAB nTab1
,
797 SCCOL nCol2
, SCROW nRow2
, SCTAB nTab2
,
798 SCsCOL nDx
, SCsROW nDy
, SCsTAB nDz
)
800 for (USHORT i
=0; i
<nCount
; i
++)
808 ((ScDBData
*)pItems
[i
])->GetArea( theTab1
, theCol1
, theRow1
, theCol2
, theRow2
);
811 BOOL bDoUpdate
= ScRefUpdate::Update( pDoc
, eUpdateRefMode
,
812 nCol1
,nRow1
,nTab1
, nCol2
,nRow2
,nTab2
, nDx
,nDy
,nDz
,
813 theCol1
,theRow1
,theTab1
, theCol2
,theRow2
,theTab2
) != UR_NOTHING
;
815 ((ScDBData
*)pItems
[i
])->MoveTo( theTab1
, theCol1
, theRow1
, theCol2
, theRow2
);
818 if ( ((ScDBData
*)pItems
[i
])->GetAdvancedQuerySource(aAdvSource
) )
820 aAdvSource
.GetVars( theCol1
,theRow1
,theTab1
, theCol2
,theRow2
,theTab2
);
821 if ( ScRefUpdate::Update( pDoc
, eUpdateRefMode
,
822 nCol1
,nRow1
,nTab1
, nCol2
,nRow2
,nTab2
, nDx
,nDy
,nDz
,
823 theCol1
,theRow1
,theTab1
, theCol2
,theRow2
,theTab2
) )
825 aAdvSource
.aStart
.Set( theCol1
,theRow1
,theTab1
);
826 aAdvSource
.aEnd
.Set( theCol2
,theRow2
,theTab2
);
827 ((ScDBData
*)pItems
[i
])->SetAdvancedQuerySource( &aAdvSource
);
829 bDoUpdate
= TRUE
; // DBData is modified
833 ((ScDBData
*)pItems
[i
])->SetModified(bDoUpdate
);
835 //! Testen, ob mitten aus dem Bereich geloescht/eingefuegt wurde !!!
840 void ScDBCollection::UpdateMoveTab( SCTAB nOldPos
, SCTAB nNewPos
)
842 // wenn nOldPos vor nNewPos liegt, ist nNewPos schon angepasst
844 for (USHORT i
=0; i
<nCount
; i
++)
847 ScDBData
* pData
= (ScDBData
*)pItems
[i
];
848 pData
->GetArea( aRange
);
849 SCTAB nTab
= aRange
.aStart
.Tab(); // hat nur eine Tabelle
851 // anpassen wie die aktuelle Tabelle bei ScTablesHint (tabvwsh5.cxx)
853 if ( nTab
== nOldPos
) // verschobene Tabelle
855 else if ( nOldPos
< nNewPos
) // nach hinten verschoben
857 if ( nTab
> nOldPos
&& nTab
<= nNewPos
) // nachrueckender Bereich
860 else // nach vorne verschoben
862 if ( nTab
>= nNewPos
&& nTab
< nOldPos
) // nachrueckender Bereich
866 BOOL bChanged
= ( nTab
!= aRange
.aStart
.Tab() );
868 pData
->SetArea( nTab
, aRange
.aStart
.Col(), aRange
.aStart
.Row(),
869 aRange
.aEnd
.Col(),aRange
.aEnd
.Row() );
871 // MoveTo ist nicht noetig, wenn nur die Tabelle geaendert ist
873 pData
->SetModified(bChanged
);
878 ScDBData
* ScDBCollection::FindIndex(USHORT nIndex
)
883 if ((*this)[i
]->GetIndex() == nIndex
)
890 BOOL
ScDBCollection::Insert(ScDataObject
* pScDataObject
)
892 ScDBData
* pData
= (ScDBData
*) pScDataObject
;
893 if (!pData
->GetIndex()) // schon gesetzt?
894 pData
->SetIndex(nEntryIndex
++);
895 BOOL bInserted
= ScSortedCollection::Insert(pScDataObject
);
896 if ( bInserted
&& pData
->HasImportParam() && !pData
->HasImportSelection() )
898 pData
->SetRefreshHandler( GetRefreshHandler() );
899 pData
->SetRefreshControl( pDoc
->GetRefreshTimerControlAddress() );