update dev300-m57
[ooovba.git] / sc / source / core / data / global2.cxx
blobbe16aeddd49eee9b9f5c3403811f451d6c93c3ed
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: global2.cxx,v $
10 * $Revision: 1.23.32.2 $
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"
36 // INCLUDE ---------------------------------------------------------------
38 #include <sfx2/docfile.hxx>
39 #include <sfx2/objsh.hxx>
40 #include <unotools/textsearch.hxx>
41 #include <svtools/pathoptions.hxx>
42 #include <svtools/useroptions.hxx>
43 #include <tools/urlobj.hxx>
44 #include <unotools/charclass.hxx>
45 #include <stdlib.h>
46 #include <ctype.h>
47 #include <svtools/syslocale.hxx>
49 #include "global.hxx"
50 #include "rangeutl.hxx"
51 #include "pivot.hxx"
52 #include "rechead.hxx"
53 #include "compiler.hxx"
54 #include "paramisc.hxx"
56 #include "sc.hrc"
57 #include "globstr.hrc"
59 using ::std::vector;
61 // -----------------------------------------------------------------------
65 #define MAX_LABELS 256 //!!! aus fieldwnd.hxx, muss noch nach global.hxx ???
67 //------------------------------------------------------------------------
68 // struct ScImportParam:
70 ScImportParam::ScImportParam() :
71 nCol1(0),
72 nRow1(0),
73 nCol2(0),
74 nRow2(0),
75 bImport(FALSE),
76 bNative(FALSE),
77 bSql(TRUE),
78 nType(ScDbTable)
82 ScImportParam::ScImportParam( const ScImportParam& r ) :
83 nCol1 (r.nCol1),
84 nRow1 (r.nRow1),
85 nCol2 (r.nCol2),
86 nRow2 (r.nRow2),
87 bImport (r.bImport),
88 aDBName (r.aDBName),
89 aStatement (r.aStatement),
90 bNative (r.bNative),
91 bSql (r.bSql),
92 nType (r.nType)
96 ScImportParam::~ScImportParam()
100 //UNUSED2009-05 void ScImportParam::Clear()
101 //UNUSED2009-05 {
102 //UNUSED2009-05 nCol1 = nCol2 = 0;
103 //UNUSED2009-05 nRow1 = nRow2 = 0;
104 //UNUSED2009-05 bImport = FALSE;
105 //UNUSED2009-05 bNative = FALSE;
106 //UNUSED2009-05 bSql = TRUE;
107 //UNUSED2009-05 nType = ScDbTable;
108 //UNUSED2009-05 aDBName.Erase();
109 //UNUSED2009-05 aStatement.Erase();
110 //UNUSED2009-05 }
112 ScImportParam& ScImportParam::operator=( const ScImportParam& r )
114 nCol1 = r.nCol1;
115 nRow1 = r.nRow1;
116 nCol2 = r.nCol2;
117 nRow2 = r.nRow2;
118 bImport = r.bImport;
119 aDBName = r.aDBName;
120 aStatement = r.aStatement;
121 bNative = r.bNative;
122 bSql = r.bSql;
123 nType = r.nType;
125 return *this;
128 BOOL ScImportParam::operator==( const ScImportParam& rOther ) const
130 return( nCol1 == rOther.nCol1 &&
131 nRow1 == rOther.nRow1 &&
132 nCol2 == rOther.nCol2 &&
133 nRow2 == rOther.nRow2 &&
134 bImport == rOther.bImport &&
135 aDBName == rOther.aDBName &&
136 aStatement == rOther.aStatement &&
137 bNative == rOther.bNative &&
138 bSql == rOther.bSql &&
139 nType == rOther.nType );
141 //! nQuerySh und pConnection sind gleich ?
145 //------------------------------------------------------------------------
146 // struct ScQueryParam:
148 ScQueryEntry::ScQueryEntry()
150 bDoQuery = FALSE;
151 bQueryByString = FALSE;
152 eOp = SC_EQUAL;
153 eConnect = SC_AND;
154 nField = 0;
155 nVal = 0.0;
156 pStr = new String;
157 pSearchParam = NULL;
158 pSearchText = NULL;
161 ScQueryEntry::ScQueryEntry(const ScQueryEntry& r)
163 bDoQuery = r.bDoQuery;
164 bQueryByString = r.bQueryByString;
165 eOp = r.eOp;
166 eConnect = r.eConnect;
167 nField = r.nField;
168 nVal = r.nVal;
169 pStr = new String(*r.pStr);
170 pSearchParam = NULL;
171 pSearchText = NULL;
174 ScQueryEntry::~ScQueryEntry()
176 delete pStr;
177 if ( pSearchParam )
179 delete pSearchParam;
180 delete pSearchText;
184 ScQueryEntry& ScQueryEntry::operator=( const ScQueryEntry& r )
186 bDoQuery = r.bDoQuery;
187 bQueryByString = r.bQueryByString;
188 eOp = r.eOp;
189 eConnect = r.eConnect;
190 nField = r.nField;
191 nVal = r.nVal;
192 *pStr = *r.pStr;
193 if ( pSearchParam )
195 delete pSearchParam;
196 delete pSearchText;
198 pSearchParam = NULL;
199 pSearchText = NULL;
201 return *this;
204 void ScQueryEntry::Clear()
206 bDoQuery = FALSE;
207 bQueryByString = FALSE;
208 eOp = SC_EQUAL;
209 eConnect = SC_AND;
210 nField = 0;
211 nVal = 0.0;
212 pStr->Erase();
213 if ( pSearchParam )
215 delete pSearchParam;
216 delete pSearchText;
218 pSearchParam = NULL;
219 pSearchText = NULL;
222 BOOL ScQueryEntry::operator==( const ScQueryEntry& r ) const
224 return bDoQuery == r.bDoQuery
225 && bQueryByString == r.bQueryByString
226 && eOp == r.eOp
227 && eConnect == r.eConnect
228 && nField == r.nField
229 && nVal == r.nVal
230 && *pStr == *r.pStr;
231 //! pSearchParam und pSearchText nicht vergleichen
234 utl::TextSearch* ScQueryEntry::GetSearchTextPtr( BOOL bCaseSens )
236 if ( !pSearchParam )
238 pSearchParam = new utl::SearchParam( *pStr, utl::SearchParam::SRCH_REGEXP,
239 bCaseSens, FALSE, FALSE );
240 pSearchText = new utl::TextSearch( *pSearchParam, *ScGlobal::pCharClass );
242 return pSearchText;
245 //------------------------------------------------------------------------
247 ScQueryParam::ScQueryParam()
249 nEntryCount = 0;
250 Clear();
253 //------------------------------------------------------------------------
255 ScQueryParam::ScQueryParam( const ScQueryParam& r ) :
256 nCol1(r.nCol1),nRow1(r.nRow1),nCol2(r.nCol2),nRow2(r.nRow2),nTab(r.nTab),
257 bHasHeader(r.bHasHeader), bByRow(r.bByRow), bInplace(r.bInplace), bCaseSens(r.bCaseSens),
258 bRegExp(r.bRegExp), bMixedComparison(r.bMixedComparison),
259 bDuplicate(r.bDuplicate), bDestPers(r.bDestPers),
260 nDestTab(r.nDestTab), nDestCol(r.nDestCol), nDestRow(r.nDestRow),
261 nDynamicEndRow(r.nDynamicEndRow), bUseDynamicRange(r.bUseDynamicRange)
263 nEntryCount = 0;
265 Resize( r.nEntryCount );
266 for (USHORT i=0; i<nEntryCount; i++)
267 pEntries[i] = r.pEntries[i];
270 //------------------------------------------------------------------------
272 ScQueryParam::~ScQueryParam()
274 delete[] pEntries;
277 //------------------------------------------------------------------------
279 void ScQueryParam::Clear()
281 nCol1=nCol2=nDestCol = 0;
282 nRow1=nRow2=nDestRow = 0;
283 nDestTab = 0;
284 nTab = SCTAB_MAX;
285 bHasHeader = bCaseSens = bRegExp = bMixedComparison = FALSE;
286 bInplace = bByRow = bDuplicate = bDestPers = TRUE;
287 nDynamicEndRow = 0;
288 bUseDynamicRange = false;
290 Resize( MAXQUERY );
291 for (USHORT i=0; i<MAXQUERY; i++)
292 pEntries[i].Clear();
295 //------------------------------------------------------------------------
297 ScQueryParam& ScQueryParam::operator=( const ScQueryParam& r )
299 nCol1 = r.nCol1;
300 nRow1 = r.nRow1;
301 nCol2 = r.nCol2;
302 nRow2 = r.nRow2;
303 nTab = r.nTab;
304 nDestTab = r.nDestTab;
305 nDestCol = r.nDestCol;
306 nDestRow = r.nDestRow;
307 bHasHeader = r.bHasHeader;
308 bInplace = r.bInplace;
309 bCaseSens = r.bCaseSens;
310 bRegExp = r.bRegExp;
311 bMixedComparison = r.bMixedComparison;
312 bDuplicate = r.bDuplicate;
313 bByRow = r.bByRow;
314 bDestPers = r.bDestPers;
315 nDynamicEndRow = r.nDynamicEndRow;
316 bUseDynamicRange = r.bUseDynamicRange;
318 Resize( r.nEntryCount );
319 for (USHORT i=0; i<nEntryCount; i++)
320 pEntries[i] = r.pEntries[i];
322 return *this;
325 //------------------------------------------------------------------------
327 BOOL ScQueryParam::operator==( const ScQueryParam& rOther ) const
329 BOOL bEqual = FALSE;
331 // Anzahl der Queries gleich?
332 USHORT nUsed = 0;
333 USHORT nOtherUsed = 0;
334 while ( nUsed<nEntryCount && pEntries[nUsed].bDoQuery ) ++nUsed;
335 while ( nOtherUsed<rOther.nEntryCount && rOther.pEntries[nOtherUsed].bDoQuery )
336 ++nOtherUsed;
338 if ( (nUsed == nOtherUsed)
339 && (nCol1 == rOther.nCol1)
340 && (nRow1 == rOther.nRow1)
341 && (nCol2 == rOther.nCol2)
342 && (nRow2 == rOther.nRow2)
343 && (nTab == rOther.nTab)
344 && (bHasHeader == rOther.bHasHeader)
345 && (bByRow == rOther.bByRow)
346 && (bInplace == rOther.bInplace)
347 && (bCaseSens == rOther.bCaseSens)
348 && (bRegExp == rOther.bRegExp)
349 && (bMixedComparison == rOther.bMixedComparison)
350 && (bDuplicate == rOther.bDuplicate)
351 && (bDestPers == rOther.bDestPers)
352 && (nDestTab == rOther.nDestTab)
353 && (nDestCol == rOther.nDestCol)
354 && (nDestRow == rOther.nDestRow)
355 && (nDynamicEndRow == rOther.nDynamicEndRow)
356 && (bUseDynamicRange == rOther.bUseDynamicRange) )
358 bEqual = TRUE;
359 for ( USHORT i=0; i<nUsed && bEqual; i++ )
360 bEqual = pEntries[i] == rOther.pEntries[i];
362 return bEqual;
365 //------------------------------------------------------------------------
367 void ScQueryParam::DeleteQuery( SCSIZE nPos )
369 if (nPos<nEntryCount)
371 for (SCSIZE i=nPos; i+1<nEntryCount; i++)
372 pEntries[i] = pEntries[i+1];
374 pEntries[nEntryCount-1].Clear();
376 else
378 DBG_ERROR("Falscher Parameter bei ScQueryParam::DeleteQuery");
382 //------------------------------------------------------------------------
384 void ScQueryParam::Resize(SCSIZE nNew)
386 if ( nNew < MAXQUERY )
387 nNew = MAXQUERY; // nie weniger als MAXQUERY
389 ScQueryEntry* pNewEntries = NULL;
390 if ( nNew )
391 pNewEntries = new ScQueryEntry[nNew];
393 SCSIZE nCopy = Min( nEntryCount, nNew );
394 for (SCSIZE i=0; i<nCopy; i++)
395 pNewEntries[i] = pEntries[i];
397 if ( nEntryCount )
398 delete[] pEntries;
399 nEntryCount = nNew;
400 pEntries = pNewEntries;
403 //------------------------------------------------------------------------
405 void ScQueryParam::MoveToDest()
407 if (!bInplace)
409 SCsCOL nDifX = ((SCsCOL) nDestCol) - ((SCsCOL) nCol1);
410 SCsROW nDifY = ((SCsROW) nDestRow) - ((SCsROW) nRow1);
411 SCsTAB nDifZ = ((SCsTAB) nDestTab) - ((SCsTAB) nTab);
413 nCol1 = sal::static_int_cast<SCCOL>( nCol1 + nDifX );
414 nRow1 = sal::static_int_cast<SCROW>( nRow1 + nDifY );
415 nCol2 = sal::static_int_cast<SCCOL>( nCol2 + nDifX );
416 nRow2 = sal::static_int_cast<SCROW>( nRow2 + nDifY );
417 nTab = sal::static_int_cast<SCTAB>( nTab + nDifZ );
418 nDynamicEndRow = sal::static_int_cast<SCROW>( nDynamicEndRow + nDifY );
419 for (USHORT i=0; i<nEntryCount; i++)
420 pEntries[i].nField += nDifX;
422 bInplace = TRUE;
424 else
426 DBG_ERROR("MoveToDest, bInplace == TRUE");
430 //------------------------------------------------------------------------
432 void ScQueryParam::FillInExcelSyntax(String& aCellStr, SCSIZE nIndex)
434 if (aCellStr.Len() > 0)
436 if ( nIndex >= nEntryCount )
437 Resize( nIndex+1 );
439 ScQueryEntry& rEntry = pEntries[nIndex];
441 rEntry.bDoQuery = TRUE;
442 // Operatoren herausfiltern
443 if (aCellStr.GetChar(0) == '<')
445 if (aCellStr.GetChar(1) == '>')
447 *rEntry.pStr = aCellStr.Copy(2);
448 rEntry.eOp = SC_NOT_EQUAL;
450 else if (aCellStr.GetChar(1) == '=')
452 *rEntry.pStr = aCellStr.Copy(2);
453 rEntry.eOp = SC_LESS_EQUAL;
455 else
457 *rEntry.pStr = aCellStr.Copy(1);
458 rEntry.eOp = SC_LESS;
461 else if (aCellStr.GetChar(0) == '>')
463 if (aCellStr.GetChar(1) == '=')
465 *rEntry.pStr = aCellStr.Copy(2);
466 rEntry.eOp = SC_GREATER_EQUAL;
468 else
470 *rEntry.pStr = aCellStr.Copy(1);
471 rEntry.eOp = SC_GREATER;
474 else
476 if (aCellStr.GetChar(0) == '=')
477 *rEntry.pStr = aCellStr.Copy(1);
478 else
479 *rEntry.pStr = aCellStr;
480 rEntry.eOp = SC_EQUAL;
485 //------------------------------------------------------------------------
486 // struct ScSubTotalParam:
488 ScSubTotalParam::ScSubTotalParam()
490 for ( USHORT i=0; i<MAXSUBTOTAL; i++ )
492 nSubTotals[i] = 0;
493 pSubTotals[i] = NULL;
494 pFunctions[i] = NULL;
497 Clear();
500 //------------------------------------------------------------------------
502 ScSubTotalParam::ScSubTotalParam( const ScSubTotalParam& r ) :
503 nCol1(r.nCol1),nRow1(r.nRow1),nCol2(r.nCol2),nRow2(r.nRow2),
504 bRemoveOnly(r.bRemoveOnly),bReplace(r.bReplace),bPagebreak(r.bPagebreak),bCaseSens(r.bCaseSens),
505 bDoSort(r.bDoSort),bAscending(r.bAscending),bUserDef(r.bUserDef),nUserIndex(r.nUserIndex),
506 bIncludePattern(r.bIncludePattern)
508 for (USHORT i=0; i<MAXSUBTOTAL; i++)
510 bGroupActive[i] = r.bGroupActive[i];
511 nField[i] = r.nField[i];
513 if ( (r.nSubTotals[i] > 0) && r.pSubTotals[i] && r.pFunctions[i] )
515 nSubTotals[i] = r.nSubTotals[i];
516 pSubTotals[i] = new SCCOL [r.nSubTotals[i]];
517 pFunctions[i] = new ScSubTotalFunc [r.nSubTotals[i]];
519 for (SCCOL j=0; j<r.nSubTotals[i]; j++)
521 pSubTotals[i][j] = r.pSubTotals[i][j];
522 pFunctions[i][j] = r.pFunctions[i][j];
525 else
527 nSubTotals[i] = 0;
528 pSubTotals[i] = NULL;
529 pFunctions[i] = NULL;
534 //------------------------------------------------------------------------
536 void ScSubTotalParam::Clear()
538 nCol1=nCol2= 0;
539 nRow1=nRow2 = 0;
540 nUserIndex = 0;
541 bPagebreak=bCaseSens=bUserDef=bIncludePattern=bRemoveOnly = FALSE;
542 bAscending=bReplace=bDoSort = TRUE;
544 for (USHORT i=0; i<MAXSUBTOTAL; i++)
546 bGroupActive[i] = FALSE;
547 nField[i] = 0;
549 if ( (nSubTotals[i] > 0) && pSubTotals[i] && pFunctions[i] )
551 for ( SCCOL j=0; j<nSubTotals[i]; j++ ) {
552 pSubTotals[i][j] = 0;
553 pFunctions[i][j] = SUBTOTAL_FUNC_NONE;
559 //------------------------------------------------------------------------
561 ScSubTotalParam& ScSubTotalParam::operator=( const ScSubTotalParam& r )
563 nCol1 = r.nCol1;
564 nRow1 = r.nRow1;
565 nCol2 = r.nCol2;
566 nRow2 = r.nRow2;
567 bRemoveOnly = r.bRemoveOnly;
568 bReplace = r.bReplace;
569 bPagebreak = r.bPagebreak;
570 bCaseSens = r.bCaseSens;
571 bDoSort = r.bDoSort;
572 bAscending = r.bAscending;
573 bUserDef = r.bUserDef;
574 nUserIndex = r.nUserIndex;
575 bIncludePattern = r.bIncludePattern;
577 for (USHORT i=0; i<MAXSUBTOTAL; i++)
579 bGroupActive[i] = r.bGroupActive[i];
580 nField[i] = r.nField[i];
581 nSubTotals[i] = r.nSubTotals[i];
583 if ( pSubTotals[i] ) delete [] pSubTotals[i];
584 if ( pFunctions[i] ) delete [] pFunctions[i];
586 if ( r.nSubTotals[i] > 0 )
588 pSubTotals[i] = new SCCOL [r.nSubTotals[i]];
589 pFunctions[i] = new ScSubTotalFunc [r.nSubTotals[i]];
591 for (SCCOL j=0; j<r.nSubTotals[i]; j++)
593 pSubTotals[i][j] = r.pSubTotals[i][j];
594 pFunctions[i][j] = r.pFunctions[i][j];
597 else
599 nSubTotals[i] = 0;
600 pSubTotals[i] = NULL;
601 pFunctions[i] = NULL;
605 return *this;
608 //------------------------------------------------------------------------
610 BOOL ScSubTotalParam::operator==( const ScSubTotalParam& rOther ) const
612 BOOL bEqual = (nCol1 == rOther.nCol1)
613 && (nRow1 == rOther.nRow1)
614 && (nCol2 == rOther.nCol2)
615 && (nRow2 == rOther.nRow2)
616 && (bRemoveOnly == rOther.bRemoveOnly)
617 && (bReplace == rOther.bReplace)
618 && (bPagebreak == rOther.bPagebreak)
619 && (bDoSort == rOther.bDoSort)
620 && (bCaseSens == rOther.bCaseSens)
621 && (bAscending == rOther.bAscending)
622 && (bUserDef == rOther.bUserDef)
623 && (nUserIndex == rOther.nUserIndex)
624 && (bIncludePattern== rOther.bIncludePattern);
626 if ( bEqual )
628 bEqual = TRUE;
629 for ( USHORT i=0; i<MAXSUBTOTAL && bEqual; i++ )
631 bEqual = (bGroupActive[i] == rOther.bGroupActive[i])
632 && (nField[i] == rOther.nField[i])
633 && (nSubTotals[i] == rOther.nSubTotals[i]);
635 if ( bEqual && (nSubTotals[i] > 0) )
637 bEqual = (pSubTotals != NULL) && (pFunctions != NULL);
639 for (SCCOL j=0; (j<nSubTotals[i]) && bEqual; j++)
641 bEqual = bEqual
642 && (pSubTotals[i][j] == rOther.pSubTotals[i][j])
643 && (pFunctions[i][j] == rOther.pFunctions[i][j]);
649 return bEqual;
652 //------------------------------------------------------------------------
654 void ScSubTotalParam::SetSubTotals( USHORT nGroup,
655 const SCCOL* ptrSubTotals,
656 const ScSubTotalFunc* ptrFunctions,
657 USHORT nCount )
659 DBG_ASSERT( (nGroup <= MAXSUBTOTAL),
660 "ScSubTotalParam::SetSubTotals(): nGroup > MAXSUBTOTAL!" );
661 DBG_ASSERT( ptrSubTotals,
662 "ScSubTotalParam::SetSubTotals(): ptrSubTotals == NULL!" );
663 DBG_ASSERT( ptrFunctions,
664 "ScSubTotalParam::SetSubTotals(): ptrFunctions == NULL!" );
665 DBG_ASSERT( (nCount > 0),
666 "ScSubTotalParam::SetSubTotals(): nCount <= 0!" );
668 if ( ptrSubTotals && ptrFunctions && (nCount > 0) && (nGroup <= MAXSUBTOTAL) )
670 // 0 wird als 1 aufgefasst, sonst zum Array-Index dekrementieren
671 if (nGroup != 0)
672 nGroup--;
674 delete [] pSubTotals[nGroup];
675 delete [] pFunctions[nGroup];
677 pSubTotals[nGroup] = new SCCOL [nCount];
678 pFunctions[nGroup] = new ScSubTotalFunc [nCount];
679 nSubTotals[nGroup] = static_cast<SCCOL>(nCount);
681 for ( USHORT i=0; i<nCount; i++ )
683 pSubTotals[nGroup][i] = ptrSubTotals[i];
684 pFunctions[nGroup][i] = ptrFunctions[i];
689 //------------------------------------------------------------------------
690 // struct ScConsolidateParam:
692 ScConsolidateParam::ScConsolidateParam() :
693 ppDataAreas( NULL )
695 Clear();
698 //------------------------------------------------------------------------
700 ScConsolidateParam::ScConsolidateParam( const ScConsolidateParam& r ) :
701 nCol(r.nCol),nRow(r.nRow),nTab(r.nTab),
702 eFunction(r.eFunction),nDataAreaCount(0),
703 ppDataAreas( NULL ),
704 bByCol(r.bByCol),bByRow(r.bByRow),bReferenceData(r.bReferenceData)
706 if ( r.nDataAreaCount > 0 )
708 nDataAreaCount = r.nDataAreaCount;
709 ppDataAreas = new ScArea*[nDataAreaCount];
710 for ( USHORT i=0; i<nDataAreaCount; i++ )
711 ppDataAreas[i] = new ScArea( *(r.ppDataAreas[i]) );
715 //------------------------------------------------------------------------
717 __EXPORT ScConsolidateParam::~ScConsolidateParam()
719 ClearDataAreas();
722 //------------------------------------------------------------------------
724 void __EXPORT ScConsolidateParam::ClearDataAreas()
726 if ( ppDataAreas )
728 for ( USHORT i=0; i<nDataAreaCount; i++ )
729 delete ppDataAreas[i];
730 delete [] ppDataAreas;
731 ppDataAreas = NULL;
733 nDataAreaCount = 0;
736 //------------------------------------------------------------------------
738 void __EXPORT ScConsolidateParam::Clear()
740 ClearDataAreas();
742 nCol = 0;
743 nRow = 0;
744 nTab = 0;
745 bByCol = bByRow = bReferenceData = FALSE;
746 eFunction = SUBTOTAL_FUNC_SUM;
749 //------------------------------------------------------------------------
751 ScConsolidateParam& __EXPORT ScConsolidateParam::operator=( const ScConsolidateParam& r )
753 nCol = r.nCol;
754 nRow = r.nRow;
755 nTab = r.nTab;
756 bByCol = r.bByCol;
757 bByRow = r.bByRow;
758 bReferenceData = r.bReferenceData;
759 eFunction = r.eFunction;
760 SetAreas( r.ppDataAreas, r.nDataAreaCount );
762 return *this;
765 //------------------------------------------------------------------------
767 BOOL __EXPORT ScConsolidateParam::operator==( const ScConsolidateParam& r ) const
769 BOOL bEqual = (nCol == r.nCol)
770 && (nRow == r.nRow)
771 && (nTab == r.nTab)
772 && (bByCol == r.bByCol)
773 && (bByRow == r.bByRow)
774 && (bReferenceData == r.bReferenceData)
775 && (nDataAreaCount == r.nDataAreaCount)
776 && (eFunction == r.eFunction);
778 if ( nDataAreaCount == 0 )
779 bEqual = bEqual && (ppDataAreas == NULL) && (r.ppDataAreas == NULL);
780 else
781 bEqual = bEqual && (ppDataAreas != NULL) && (r.ppDataAreas != NULL);
783 if ( bEqual && (nDataAreaCount > 0) )
784 for ( USHORT i=0; i<nDataAreaCount && bEqual; i++ )
785 bEqual = *(ppDataAreas[i]) == *(r.ppDataAreas[i]);
787 return bEqual;
790 //------------------------------------------------------------------------
792 void __EXPORT ScConsolidateParam::SetAreas( ScArea* const* ppAreas, USHORT nCount )
794 ClearDataAreas();
795 if ( ppAreas && nCount > 0 )
797 ppDataAreas = new ScArea*[nCount];
798 for ( USHORT i=0; i<nCount; i++ )
799 ppDataAreas[i] = new ScArea( *(ppAreas[i]) );
800 nDataAreaCount = nCount;
804 // -----------------------------------------------------------------------
806 PivotField::PivotField( SCsCOL nNewCol, USHORT nNewFuncMask ) :
807 nCol( nNewCol ),
808 nFuncMask( nNewFuncMask ),
809 nFuncCount( 0 )
813 bool PivotField::operator==( const PivotField& r ) const
815 return (nCol == r.nCol)
816 && (nFuncMask == r.nFuncMask)
817 && (nFuncCount == r.nFuncCount)
818 && (maFieldRef.ReferenceType == r.maFieldRef.ReferenceType)
819 && (maFieldRef.ReferenceField == r.maFieldRef.ReferenceField)
820 && (maFieldRef.ReferenceItemType == r.maFieldRef.ReferenceItemType)
821 && (maFieldRef.ReferenceItemName == r.maFieldRef.ReferenceItemName);
824 //------------------------------------------------------------------------
825 // struct ScPivotParam:
827 ScPivotParam::ScPivotParam()
828 : nCol(0), nRow(0), nTab(0),
829 nPageCount(0), nColCount(0), nRowCount(0), nDataCount(0),
830 bIgnoreEmptyRows(FALSE), bDetectCategories(FALSE),
831 bMakeTotalCol(TRUE), bMakeTotalRow(TRUE)
835 //------------------------------------------------------------------------
837 ScPivotParam::ScPivotParam( const ScPivotParam& r )
838 : nCol( r.nCol ), nRow( r.nRow ), nTab( r.nTab ),
839 nPageCount(0), nColCount(0), nRowCount(0), nDataCount(0),
840 bIgnoreEmptyRows(r.bIgnoreEmptyRows),
841 bDetectCategories(r.bDetectCategories),
842 bMakeTotalCol(r.bMakeTotalCol),
843 bMakeTotalRow(r.bMakeTotalRow)
845 SetPivotArrays ( r.aPageArr, r.aColArr, r.aRowArr, r.aDataArr,
846 r.nPageCount, r.nColCount, r.nRowCount, r.nDataCount );
848 SetLabelData(r.maLabelArray);
851 //------------------------------------------------------------------------
853 __EXPORT ScPivotParam::~ScPivotParam()
857 //------------------------------------------------------------------------
859 //UNUSED2009-05 void __EXPORT ScPivotParam::Clear()
860 //UNUSED2009-05 {
861 //UNUSED2009-05 nCol = 0;
862 //UNUSED2009-05 nRow = 0;
863 //UNUSED2009-05 nTab = 0;
864 //UNUSED2009-05 bIgnoreEmptyRows = bDetectCategories = FALSE;
865 //UNUSED2009-05 bMakeTotalCol = bMakeTotalRow = TRUE;
866 //UNUSED2009-05 ClearPivotArrays();
867 //UNUSED2009-05 maLabelArray.clear();
868 //UNUSED2009-05 }
870 void __EXPORT ScPivotParam::ClearPivotArrays()
872 memset( aPageArr, 0, PIVOT_MAXPAGEFIELD * sizeof(PivotField) );
873 memset( aColArr, 0, PIVOT_MAXFIELD * sizeof(PivotField) );
874 memset( aRowArr, 0, PIVOT_MAXFIELD * sizeof(PivotField) );
875 memset( aDataArr, 0, PIVOT_MAXFIELD * sizeof(PivotField) );
876 nPageCount = 0;
877 nColCount = 0;
878 nRowCount = 0;
879 nDataCount = 0;
882 void ScPivotParam::SetLabelData(const vector<ScDPLabelDataRef>& r)
884 vector<ScDPLabelDataRef> aNewArray;
885 aNewArray.reserve(r.size());
886 for (vector<ScDPLabelDataRef>::const_iterator itr = r.begin(), itrEnd = r.end();
887 itr != itrEnd; ++itr)
889 ScDPLabelDataRef p(new ScDPLabelData(**itr));
890 aNewArray.push_back(p);
892 maLabelArray.swap(aNewArray);
895 //------------------------------------------------------------------------
897 void __EXPORT ScPivotParam::SetPivotArrays ( const PivotField* pPageArr,
898 const PivotField* pColArr,
899 const PivotField* pRowArr,
900 const PivotField* pDataArr,
901 SCSIZE nPageCnt,
902 SCSIZE nColCnt,
903 SCSIZE nRowCnt,
904 SCSIZE nDataCnt )
906 ClearPivotArrays();
908 if ( pPageArr && pColArr && pRowArr && pDataArr )
910 nPageCount = (nPageCnt>PIVOT_MAXPAGEFIELD) ? PIVOT_MAXPAGEFIELD : nPageCnt;
911 nColCount = (nColCnt>PIVOT_MAXFIELD) ? PIVOT_MAXFIELD : nColCnt;
912 nRowCount = (nRowCnt>PIVOT_MAXFIELD) ? PIVOT_MAXFIELD : nRowCnt;
913 nDataCount = (nDataCnt>PIVOT_MAXFIELD) ? PIVOT_MAXFIELD : nDataCnt;
915 memcpy( aPageArr, pPageArr, nPageCount * sizeof(PivotField) );
916 memcpy( aColArr, pColArr, nColCount * sizeof(PivotField) );
917 memcpy( aRowArr, pRowArr, nRowCount * sizeof(PivotField) );
918 memcpy( aDataArr, pDataArr, nDataCount * sizeof(PivotField) );
922 //------------------------------------------------------------------------
924 ScPivotParam& __EXPORT ScPivotParam::operator=( const ScPivotParam& r )
926 nCol = r.nCol;
927 nRow = r.nRow;
928 nTab = r.nTab;
929 bIgnoreEmptyRows = r.bIgnoreEmptyRows;
930 bDetectCategories = r.bDetectCategories;
931 bMakeTotalCol = r.bMakeTotalCol;
932 bMakeTotalRow = r.bMakeTotalRow;
934 SetPivotArrays ( r.aPageArr, r.aColArr, r.aRowArr, r.aDataArr,
935 r.nPageCount, r.nColCount, r.nRowCount, r.nDataCount );
936 SetLabelData(r.maLabelArray);
937 return *this;
940 //------------------------------------------------------------------------
942 BOOL __EXPORT ScPivotParam::operator==( const ScPivotParam& r ) const
944 BOOL bEqual = (nCol == r.nCol)
945 && (nRow == r.nRow)
946 && (nTab == r.nTab)
947 && (bIgnoreEmptyRows == r.bIgnoreEmptyRows)
948 && (bDetectCategories == r.bDetectCategories)
949 && (bMakeTotalCol == r.bMakeTotalCol)
950 && (bMakeTotalRow == r.bMakeTotalRow)
951 && (maLabelArray.size() == r.maLabelArray.size())
952 && (nPageCount == r.nPageCount)
953 && (nColCount == r.nColCount)
954 && (nRowCount == r.nRowCount)
955 && (nDataCount == r.nDataCount);
957 if ( bEqual )
959 SCSIZE i;
961 for ( i=0; i<nPageCount && bEqual; i++ )
962 bEqual = ( aPageArr[i] == r.aPageArr[i] );
964 for ( i=0; i<nColCount && bEqual; i++ )
965 bEqual = ( aColArr[i] == r.aColArr[i] );
967 for ( i=0; i<nRowCount && bEqual; i++ )
968 bEqual = ( aRowArr[i] == r.aRowArr[i] );
970 for ( i=0; i<nDataCount && bEqual; i++ )
971 bEqual = ( aDataArr[i] == r.aDataArr[i] );
974 return bEqual;
977 //------------------------------------------------------------------------
978 // struct ScSolveParam
980 ScSolveParam::ScSolveParam()
981 : pStrTargetVal( NULL )
985 //------------------------------------------------------------------------
987 ScSolveParam::ScSolveParam( const ScSolveParam& r )
988 : aRefFormulaCell ( r.aRefFormulaCell ),
989 aRefVariableCell( r.aRefVariableCell ),
990 pStrTargetVal ( r.pStrTargetVal
991 ? new String(*r.pStrTargetVal)
992 : NULL )
996 //------------------------------------------------------------------------
998 ScSolveParam::ScSolveParam( const ScAddress& rFormulaCell,
999 const ScAddress& rVariableCell,
1000 const String& rTargetValStr )
1001 : aRefFormulaCell ( rFormulaCell ),
1002 aRefVariableCell( rVariableCell ),
1003 pStrTargetVal ( new String(rTargetValStr) )
1007 //------------------------------------------------------------------------
1009 ScSolveParam::~ScSolveParam()
1011 delete pStrTargetVal;
1014 //------------------------------------------------------------------------
1016 ScSolveParam& __EXPORT ScSolveParam::operator=( const ScSolveParam& r )
1018 delete pStrTargetVal;
1020 aRefFormulaCell = r.aRefFormulaCell;
1021 aRefVariableCell = r.aRefVariableCell;
1022 pStrTargetVal = r.pStrTargetVal
1023 ? new String(*r.pStrTargetVal)
1024 : NULL;
1025 return *this;
1028 //------------------------------------------------------------------------
1030 BOOL ScSolveParam::operator==( const ScSolveParam& r ) const
1032 BOOL bEqual = (aRefFormulaCell == r.aRefFormulaCell)
1033 && (aRefVariableCell == r.aRefVariableCell);
1035 if ( bEqual )
1037 if ( !pStrTargetVal && !r.pStrTargetVal )
1038 bEqual = TRUE;
1039 else if ( !pStrTargetVal || !r.pStrTargetVal )
1040 bEqual = FALSE;
1041 else if ( pStrTargetVal && r.pStrTargetVal )
1042 bEqual = ( *pStrTargetVal == *(r.pStrTargetVal) );
1045 return bEqual;
1049 //------------------------------------------------------------------------
1050 // struct ScTabOpParam
1052 ScTabOpParam::ScTabOpParam( const ScTabOpParam& r )
1053 : aRefFormulaCell ( r.aRefFormulaCell ),
1054 aRefFormulaEnd ( r.aRefFormulaEnd ),
1055 aRefRowCell ( r.aRefRowCell ),
1056 aRefColCell ( r.aRefColCell ),
1057 nMode ( r.nMode )
1061 //------------------------------------------------------------------------
1063 ScTabOpParam::ScTabOpParam( const ScRefAddress& rFormulaCell,
1064 const ScRefAddress& rFormulaEnd,
1065 const ScRefAddress& rRowCell,
1066 const ScRefAddress& rColCell,
1067 BYTE nMd)
1068 : aRefFormulaCell ( rFormulaCell ),
1069 aRefFormulaEnd ( rFormulaEnd ),
1070 aRefRowCell ( rRowCell ),
1071 aRefColCell ( rColCell ),
1072 nMode ( nMd )
1076 //------------------------------------------------------------------------
1078 ScTabOpParam& ScTabOpParam::operator=( const ScTabOpParam& r )
1080 aRefFormulaCell = r.aRefFormulaCell;
1081 aRefFormulaEnd = r.aRefFormulaEnd;
1082 aRefRowCell = r.aRefRowCell;
1083 aRefColCell = r.aRefColCell;
1084 nMode = r.nMode;
1085 return *this;
1088 //------------------------------------------------------------------------
1090 BOOL __EXPORT ScTabOpParam::operator==( const ScTabOpParam& r ) const
1092 return ( (aRefFormulaCell == r.aRefFormulaCell)
1093 && (aRefFormulaEnd == r.aRefFormulaEnd)
1094 && (aRefRowCell == r.aRefRowCell)
1095 && (aRefColCell == r.aRefColCell)
1096 && (nMode == r.nMode) );
1099 String ScGlobal::GetAbsDocName( const String& rFileName,
1100 SfxObjectShell* pShell )
1102 String aAbsName;
1103 if ( !pShell->HasName() )
1104 { // maybe relative to document path working directory
1105 INetURLObject aObj;
1106 SvtPathOptions aPathOpt;
1107 aObj.SetSmartURL( aPathOpt.GetWorkPath() );
1108 aObj.setFinalSlash(); // it IS a path
1109 bool bWasAbs = true;
1110 aAbsName = aObj.smartRel2Abs( rFileName, bWasAbs ).GetMainURL(INetURLObject::NO_DECODE);
1111 // returned string must be encoded because it's used directly to create SfxMedium
1113 else
1115 const SfxMedium* pMedium = pShell->GetMedium();
1116 if ( pMedium )
1118 bool bWasAbs = true;
1119 aAbsName = pMedium->GetURLObject().smartRel2Abs( rFileName, bWasAbs ).GetMainURL(INetURLObject::NO_DECODE);
1121 else
1122 { // This can't happen, but ...
1123 // just to be sure to have the same encoding
1124 INetURLObject aObj;
1125 aObj.SetSmartURL( aAbsName );
1126 aAbsName = aObj.GetMainURL(INetURLObject::NO_DECODE);
1129 return aAbsName;
1133 String ScGlobal::GetDocTabName( const String& rFileName,
1134 const String& rTabName )
1136 String aDocTab( '\'' );
1137 aDocTab += rFileName;
1138 xub_StrLen nPos = 1;
1139 while( (nPos = aDocTab.Search( '\'', nPos ))
1140 != STRING_NOTFOUND )
1141 { // escape Quotes
1142 aDocTab.Insert( '\\', nPos );
1143 nPos += 2;
1145 aDocTab += '\'';
1146 aDocTab += SC_COMPILER_FILE_TAB_SEP;
1147 aDocTab += rTabName; // "'Doc'#Tab"
1148 return aDocTab;
1151 // ============================================================================
1153 ScSimpleSharedString::StringTable::StringTable() :
1154 mnStrCount(0)
1156 // empty string (ID = 0)
1157 maSharedStrings.push_back(String());
1158 maSharedStringIds.insert( SharedStrMap::value_type(String(), mnStrCount++) );
1161 ScSimpleSharedString::StringTable::StringTable(const ScSimpleSharedString::StringTable& r) :
1162 maSharedStrings(r.maSharedStrings),
1163 maSharedStringIds(r.maSharedStringIds),
1164 mnStrCount(r.mnStrCount)
1168 ScSimpleSharedString::StringTable::~StringTable()
1172 sal_Int32 ScSimpleSharedString::StringTable::insertString(const String& aStr)
1174 SharedStrMap::const_iterator itr = maSharedStringIds.find(aStr),
1175 itrEnd = maSharedStringIds.end();
1177 if (itr == itrEnd)
1179 // new string.
1180 maSharedStrings.push_back(aStr);
1181 maSharedStringIds.insert( SharedStrMap::value_type(aStr, mnStrCount) );
1182 return mnStrCount++;
1185 // existing string.
1186 return itr->second;
1189 sal_Int32 ScSimpleSharedString::StringTable::getStringId(const String& aStr)
1191 SharedStrMap::const_iterator itr = maSharedStringIds.find(aStr),
1192 itrEnd = maSharedStringIds.end();
1193 if (itr == itrEnd)
1195 // string not found.
1196 return insertString(aStr);
1198 return itr->second;
1201 const String* ScSimpleSharedString::StringTable::getString(sal_Int32 nId) const
1203 if (nId >= mnStrCount)
1204 return NULL;
1206 return &maSharedStrings[nId];
1209 // ----------------------------------------------------------------------------
1211 ScSimpleSharedString::ScSimpleSharedString()
1215 ScSimpleSharedString::ScSimpleSharedString(const ScSimpleSharedString& r) :
1216 maStringTable(r.maStringTable)
1220 ScSimpleSharedString::~ScSimpleSharedString()
1224 sal_Int32 ScSimpleSharedString::insertString(const String& aStr)
1226 return maStringTable.insertString(aStr);
1229 const String* ScSimpleSharedString::getString(sal_Int32 nId)
1231 return maStringTable.getString(nId);
1234 sal_Int32 ScSimpleSharedString::getStringId(const String& aStr)
1236 return maStringTable.getStringId(aStr);