merge the formfield patch from ooo-build
[ooovba.git] / sc / source / core / data / global2.cxx
blob6f3c424f6aa226e83f4171c9c911f5d1b1aee91f
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() :
149 bDoQuery(FALSE),
150 bQueryByString(FALSE),
151 bQueryByDate(false),
152 nField(0),
153 eOp(SC_EQUAL),
154 eConnect(SC_AND),
155 pStr(new String),
156 nVal(0.0),
157 pSearchParam(NULL),
158 pSearchText(NULL)
162 ScQueryEntry::ScQueryEntry(const ScQueryEntry& r) :
163 bDoQuery(r.bDoQuery),
164 bQueryByString(r.bQueryByString),
165 bQueryByDate(r.bQueryByDate),
166 nField(r.nField),
167 eOp(r.eOp),
168 eConnect(r.eConnect),
169 pStr(new String(*r.pStr)),
170 nVal(r.nVal),
171 pSearchParam(NULL),
172 pSearchText(NULL)
176 ScQueryEntry::~ScQueryEntry()
178 delete pStr;
179 if ( pSearchParam )
181 delete pSearchParam;
182 delete pSearchText;
186 ScQueryEntry& ScQueryEntry::operator=( const ScQueryEntry& r )
188 bDoQuery = r.bDoQuery;
189 bQueryByString = r.bQueryByString;
190 bQueryByDate = r.bQueryByDate;
191 eOp = r.eOp;
192 eConnect = r.eConnect;
193 nField = r.nField;
194 nVal = r.nVal;
195 *pStr = *r.pStr;
196 if ( pSearchParam )
198 delete pSearchParam;
199 delete pSearchText;
201 pSearchParam = NULL;
202 pSearchText = NULL;
204 return *this;
207 void ScQueryEntry::Clear()
209 bDoQuery = FALSE;
210 bQueryByString = FALSE;
211 bQueryByDate = false;
212 eOp = SC_EQUAL;
213 eConnect = SC_AND;
214 nField = 0;
215 nVal = 0.0;
216 pStr->Erase();
217 if ( pSearchParam )
219 delete pSearchParam;
220 delete pSearchText;
222 pSearchParam = NULL;
223 pSearchText = NULL;
226 BOOL ScQueryEntry::operator==( const ScQueryEntry& r ) const
228 return bDoQuery == r.bDoQuery
229 && bQueryByString == r.bQueryByString
230 && bQueryByDate == r.bQueryByDate
231 && eOp == r.eOp
232 && eConnect == r.eConnect
233 && nField == r.nField
234 && nVal == r.nVal
235 && *pStr == *r.pStr;
236 //! pSearchParam und pSearchText nicht vergleichen
239 utl::TextSearch* ScQueryEntry::GetSearchTextPtr( BOOL bCaseSens )
241 if ( !pSearchParam )
243 pSearchParam = new utl::SearchParam( *pStr, utl::SearchParam::SRCH_REGEXP,
244 bCaseSens, FALSE, FALSE );
245 pSearchText = new utl::TextSearch( *pSearchParam, *ScGlobal::pCharClass );
247 return pSearchText;
250 //------------------------------------------------------------------------
251 // struct ScSubTotalParam:
253 ScSubTotalParam::ScSubTotalParam()
255 for ( USHORT i=0; i<MAXSUBTOTAL; i++ )
257 nSubTotals[i] = 0;
258 pSubTotals[i] = NULL;
259 pFunctions[i] = NULL;
262 Clear();
265 //------------------------------------------------------------------------
267 ScSubTotalParam::ScSubTotalParam( const ScSubTotalParam& r ) :
268 nCol1(r.nCol1),nRow1(r.nRow1),nCol2(r.nCol2),nRow2(r.nRow2),
269 bRemoveOnly(r.bRemoveOnly),bReplace(r.bReplace),bPagebreak(r.bPagebreak),bCaseSens(r.bCaseSens),
270 bDoSort(r.bDoSort),bAscending(r.bAscending),bUserDef(r.bUserDef),nUserIndex(r.nUserIndex),
271 bIncludePattern(r.bIncludePattern)
273 for (USHORT i=0; i<MAXSUBTOTAL; i++)
275 bGroupActive[i] = r.bGroupActive[i];
276 nField[i] = r.nField[i];
278 if ( (r.nSubTotals[i] > 0) && r.pSubTotals[i] && r.pFunctions[i] )
280 nSubTotals[i] = r.nSubTotals[i];
281 pSubTotals[i] = new SCCOL [r.nSubTotals[i]];
282 pFunctions[i] = new ScSubTotalFunc [r.nSubTotals[i]];
284 for (SCCOL j=0; j<r.nSubTotals[i]; j++)
286 pSubTotals[i][j] = r.pSubTotals[i][j];
287 pFunctions[i][j] = r.pFunctions[i][j];
290 else
292 nSubTotals[i] = 0;
293 pSubTotals[i] = NULL;
294 pFunctions[i] = NULL;
299 //------------------------------------------------------------------------
301 void ScSubTotalParam::Clear()
303 nCol1=nCol2= 0;
304 nRow1=nRow2 = 0;
305 nUserIndex = 0;
306 bPagebreak=bCaseSens=bUserDef=bIncludePattern=bRemoveOnly = FALSE;
307 bAscending=bReplace=bDoSort = TRUE;
309 for (USHORT i=0; i<MAXSUBTOTAL; i++)
311 bGroupActive[i] = FALSE;
312 nField[i] = 0;
314 if ( (nSubTotals[i] > 0) && pSubTotals[i] && pFunctions[i] )
316 for ( SCCOL j=0; j<nSubTotals[i]; j++ ) {
317 pSubTotals[i][j] = 0;
318 pFunctions[i][j] = SUBTOTAL_FUNC_NONE;
324 //------------------------------------------------------------------------
326 ScSubTotalParam& ScSubTotalParam::operator=( const ScSubTotalParam& r )
328 nCol1 = r.nCol1;
329 nRow1 = r.nRow1;
330 nCol2 = r.nCol2;
331 nRow2 = r.nRow2;
332 bRemoveOnly = r.bRemoveOnly;
333 bReplace = r.bReplace;
334 bPagebreak = r.bPagebreak;
335 bCaseSens = r.bCaseSens;
336 bDoSort = r.bDoSort;
337 bAscending = r.bAscending;
338 bUserDef = r.bUserDef;
339 nUserIndex = r.nUserIndex;
340 bIncludePattern = r.bIncludePattern;
342 for (USHORT i=0; i<MAXSUBTOTAL; i++)
344 bGroupActive[i] = r.bGroupActive[i];
345 nField[i] = r.nField[i];
346 nSubTotals[i] = r.nSubTotals[i];
348 if ( pSubTotals[i] ) delete [] pSubTotals[i];
349 if ( pFunctions[i] ) delete [] pFunctions[i];
351 if ( r.nSubTotals[i] > 0 )
353 pSubTotals[i] = new SCCOL [r.nSubTotals[i]];
354 pFunctions[i] = new ScSubTotalFunc [r.nSubTotals[i]];
356 for (SCCOL j=0; j<r.nSubTotals[i]; j++)
358 pSubTotals[i][j] = r.pSubTotals[i][j];
359 pFunctions[i][j] = r.pFunctions[i][j];
362 else
364 nSubTotals[i] = 0;
365 pSubTotals[i] = NULL;
366 pFunctions[i] = NULL;
370 return *this;
373 //------------------------------------------------------------------------
375 BOOL ScSubTotalParam::operator==( const ScSubTotalParam& rOther ) const
377 BOOL bEqual = (nCol1 == rOther.nCol1)
378 && (nRow1 == rOther.nRow1)
379 && (nCol2 == rOther.nCol2)
380 && (nRow2 == rOther.nRow2)
381 && (bRemoveOnly == rOther.bRemoveOnly)
382 && (bReplace == rOther.bReplace)
383 && (bPagebreak == rOther.bPagebreak)
384 && (bDoSort == rOther.bDoSort)
385 && (bCaseSens == rOther.bCaseSens)
386 && (bAscending == rOther.bAscending)
387 && (bUserDef == rOther.bUserDef)
388 && (nUserIndex == rOther.nUserIndex)
389 && (bIncludePattern== rOther.bIncludePattern);
391 if ( bEqual )
393 bEqual = TRUE;
394 for ( USHORT i=0; i<MAXSUBTOTAL && bEqual; i++ )
396 bEqual = (bGroupActive[i] == rOther.bGroupActive[i])
397 && (nField[i] == rOther.nField[i])
398 && (nSubTotals[i] == rOther.nSubTotals[i]);
400 if ( bEqual && (nSubTotals[i] > 0) )
402 bEqual = (pSubTotals != NULL) && (pFunctions != NULL);
404 for (SCCOL j=0; (j<nSubTotals[i]) && bEqual; j++)
406 bEqual = bEqual
407 && (pSubTotals[i][j] == rOther.pSubTotals[i][j])
408 && (pFunctions[i][j] == rOther.pFunctions[i][j]);
414 return bEqual;
417 //------------------------------------------------------------------------
419 void ScSubTotalParam::SetSubTotals( USHORT nGroup,
420 const SCCOL* ptrSubTotals,
421 const ScSubTotalFunc* ptrFunctions,
422 USHORT nCount )
424 DBG_ASSERT( (nGroup <= MAXSUBTOTAL),
425 "ScSubTotalParam::SetSubTotals(): nGroup > MAXSUBTOTAL!" );
426 DBG_ASSERT( ptrSubTotals,
427 "ScSubTotalParam::SetSubTotals(): ptrSubTotals == NULL!" );
428 DBG_ASSERT( ptrFunctions,
429 "ScSubTotalParam::SetSubTotals(): ptrFunctions == NULL!" );
430 DBG_ASSERT( (nCount > 0),
431 "ScSubTotalParam::SetSubTotals(): nCount <= 0!" );
433 if ( ptrSubTotals && ptrFunctions && (nCount > 0) && (nGroup <= MAXSUBTOTAL) )
435 // 0 wird als 1 aufgefasst, sonst zum Array-Index dekrementieren
436 if (nGroup != 0)
437 nGroup--;
439 delete [] pSubTotals[nGroup];
440 delete [] pFunctions[nGroup];
442 pSubTotals[nGroup] = new SCCOL [nCount];
443 pFunctions[nGroup] = new ScSubTotalFunc [nCount];
444 nSubTotals[nGroup] = static_cast<SCCOL>(nCount);
446 for ( USHORT i=0; i<nCount; i++ )
448 pSubTotals[nGroup][i] = ptrSubTotals[i];
449 pFunctions[nGroup][i] = ptrFunctions[i];
454 //------------------------------------------------------------------------
455 // struct ScConsolidateParam:
457 ScConsolidateParam::ScConsolidateParam() :
458 ppDataAreas( NULL )
460 Clear();
463 //------------------------------------------------------------------------
465 ScConsolidateParam::ScConsolidateParam( const ScConsolidateParam& r ) :
466 nCol(r.nCol),nRow(r.nRow),nTab(r.nTab),
467 eFunction(r.eFunction),nDataAreaCount(0),
468 ppDataAreas( NULL ),
469 bByCol(r.bByCol),bByRow(r.bByRow),bReferenceData(r.bReferenceData)
471 if ( r.nDataAreaCount > 0 )
473 nDataAreaCount = r.nDataAreaCount;
474 ppDataAreas = new ScArea*[nDataAreaCount];
475 for ( USHORT i=0; i<nDataAreaCount; i++ )
476 ppDataAreas[i] = new ScArea( *(r.ppDataAreas[i]) );
480 //------------------------------------------------------------------------
482 __EXPORT ScConsolidateParam::~ScConsolidateParam()
484 ClearDataAreas();
487 //------------------------------------------------------------------------
489 void __EXPORT ScConsolidateParam::ClearDataAreas()
491 if ( ppDataAreas )
493 for ( USHORT i=0; i<nDataAreaCount; i++ )
494 delete ppDataAreas[i];
495 delete [] ppDataAreas;
496 ppDataAreas = NULL;
498 nDataAreaCount = 0;
501 //------------------------------------------------------------------------
503 void __EXPORT ScConsolidateParam::Clear()
505 ClearDataAreas();
507 nCol = 0;
508 nRow = 0;
509 nTab = 0;
510 bByCol = bByRow = bReferenceData = FALSE;
511 eFunction = SUBTOTAL_FUNC_SUM;
514 //------------------------------------------------------------------------
516 ScConsolidateParam& __EXPORT ScConsolidateParam::operator=( const ScConsolidateParam& r )
518 nCol = r.nCol;
519 nRow = r.nRow;
520 nTab = r.nTab;
521 bByCol = r.bByCol;
522 bByRow = r.bByRow;
523 bReferenceData = r.bReferenceData;
524 eFunction = r.eFunction;
525 SetAreas( r.ppDataAreas, r.nDataAreaCount );
527 return *this;
530 //------------------------------------------------------------------------
532 BOOL __EXPORT ScConsolidateParam::operator==( const ScConsolidateParam& r ) const
534 BOOL bEqual = (nCol == r.nCol)
535 && (nRow == r.nRow)
536 && (nTab == r.nTab)
537 && (bByCol == r.bByCol)
538 && (bByRow == r.bByRow)
539 && (bReferenceData == r.bReferenceData)
540 && (nDataAreaCount == r.nDataAreaCount)
541 && (eFunction == r.eFunction);
543 if ( nDataAreaCount == 0 )
544 bEqual = bEqual && (ppDataAreas == NULL) && (r.ppDataAreas == NULL);
545 else
546 bEqual = bEqual && (ppDataAreas != NULL) && (r.ppDataAreas != NULL);
548 if ( bEqual && (nDataAreaCount > 0) )
549 for ( USHORT i=0; i<nDataAreaCount && bEqual; i++ )
550 bEqual = *(ppDataAreas[i]) == *(r.ppDataAreas[i]);
552 return bEqual;
555 //------------------------------------------------------------------------
557 void __EXPORT ScConsolidateParam::SetAreas( ScArea* const* ppAreas, USHORT nCount )
559 ClearDataAreas();
560 if ( ppAreas && nCount > 0 )
562 ppDataAreas = new ScArea*[nCount];
563 for ( USHORT i=0; i<nCount; i++ )
564 ppDataAreas[i] = new ScArea( *(ppAreas[i]) );
565 nDataAreaCount = nCount;
569 // -----------------------------------------------------------------------
571 PivotField::PivotField( SCsCOL nNewCol, USHORT nNewFuncMask ) :
572 nCol( nNewCol ),
573 nFuncMask( nNewFuncMask ),
574 nFuncCount( 0 )
578 bool PivotField::operator==( const PivotField& r ) const
580 return (nCol == r.nCol)
581 && (nFuncMask == r.nFuncMask)
582 && (nFuncCount == r.nFuncCount)
583 && (maFieldRef.ReferenceType == r.maFieldRef.ReferenceType)
584 && (maFieldRef.ReferenceField == r.maFieldRef.ReferenceField)
585 && (maFieldRef.ReferenceItemType == r.maFieldRef.ReferenceItemType)
586 && (maFieldRef.ReferenceItemName == r.maFieldRef.ReferenceItemName);
589 //------------------------------------------------------------------------
590 // struct ScPivotParam:
592 ScPivotParam::ScPivotParam()
593 : nCol(0), nRow(0), nTab(0),
594 nPageCount(0), nColCount(0), nRowCount(0), nDataCount(0),
595 bIgnoreEmptyRows(FALSE), bDetectCategories(FALSE),
596 bMakeTotalCol(TRUE), bMakeTotalRow(TRUE)
600 //------------------------------------------------------------------------
602 ScPivotParam::ScPivotParam( const ScPivotParam& r )
603 : nCol( r.nCol ), nRow( r.nRow ), nTab( r.nTab ),
604 nPageCount(0), nColCount(0), nRowCount(0), nDataCount(0),
605 bIgnoreEmptyRows(r.bIgnoreEmptyRows),
606 bDetectCategories(r.bDetectCategories),
607 bMakeTotalCol(r.bMakeTotalCol),
608 bMakeTotalRow(r.bMakeTotalRow)
610 SetPivotArrays ( r.aPageArr, r.aColArr, r.aRowArr, r.aDataArr,
611 r.nPageCount, r.nColCount, r.nRowCount, r.nDataCount );
613 SetLabelData(r.maLabelArray);
616 //------------------------------------------------------------------------
618 __EXPORT ScPivotParam::~ScPivotParam()
622 //------------------------------------------------------------------------
624 //UNUSED2009-05 void __EXPORT ScPivotParam::Clear()
625 //UNUSED2009-05 {
626 //UNUSED2009-05 nCol = 0;
627 //UNUSED2009-05 nRow = 0;
628 //UNUSED2009-05 nTab = 0;
629 //UNUSED2009-05 bIgnoreEmptyRows = bDetectCategories = FALSE;
630 //UNUSED2009-05 bMakeTotalCol = bMakeTotalRow = TRUE;
631 //UNUSED2009-05 ClearLabelData();
632 //UNUSED2009-05 ClearPivotArrays();
633 //UNUSED2009-05 }
635 void __EXPORT ScPivotParam::ClearPivotArrays()
637 memset( aPageArr, 0, PIVOT_MAXPAGEFIELD * sizeof(PivotField) );
638 memset( aColArr, 0, PIVOT_MAXFIELD * sizeof(PivotField) );
639 memset( aRowArr, 0, PIVOT_MAXFIELD * sizeof(PivotField) );
640 memset( aDataArr, 0, PIVOT_MAXFIELD * sizeof(PivotField) );
641 nPageCount = 0;
642 nColCount = 0;
643 nRowCount = 0;
644 nDataCount = 0;
647 void ScPivotParam::SetLabelData(const vector<ScDPLabelDataRef>& r)
649 vector<ScDPLabelDataRef> aNewArray;
650 aNewArray.reserve(r.size());
651 for (vector<ScDPLabelDataRef>::const_iterator itr = r.begin(), itrEnd = r.end();
652 itr != itrEnd; ++itr)
654 ScDPLabelDataRef p(new ScDPLabelData(**itr));
655 aNewArray.push_back(p);
657 maLabelArray.swap(aNewArray);
660 //------------------------------------------------------------------------
662 void __EXPORT ScPivotParam::SetPivotArrays ( const PivotField* pPageArr,
663 const PivotField* pColArr,
664 const PivotField* pRowArr,
665 const PivotField* pDataArr,
666 SCSIZE nPageCnt,
667 SCSIZE nColCnt,
668 SCSIZE nRowCnt,
669 SCSIZE nDataCnt )
671 ClearPivotArrays();
673 if ( pPageArr && pColArr && pRowArr && pDataArr )
675 nPageCount = (nPageCnt>PIVOT_MAXPAGEFIELD) ? PIVOT_MAXPAGEFIELD : nPageCnt;
676 nColCount = (nColCnt>PIVOT_MAXFIELD) ? PIVOT_MAXFIELD : nColCnt;
677 nRowCount = (nRowCnt>PIVOT_MAXFIELD) ? PIVOT_MAXFIELD : nRowCnt;
678 nDataCount = (nDataCnt>PIVOT_MAXFIELD) ? PIVOT_MAXFIELD : nDataCnt;
680 memcpy( aPageArr, pPageArr, nPageCount * sizeof(PivotField) );
681 memcpy( aColArr, pColArr, nColCount * sizeof(PivotField) );
682 memcpy( aRowArr, pRowArr, nRowCount * sizeof(PivotField) );
683 memcpy( aDataArr, pDataArr, nDataCount * sizeof(PivotField) );
687 //------------------------------------------------------------------------
689 ScPivotParam& __EXPORT ScPivotParam::operator=( const ScPivotParam& r )
691 nCol = r.nCol;
692 nRow = r.nRow;
693 nTab = r.nTab;
694 bIgnoreEmptyRows = r.bIgnoreEmptyRows;
695 bDetectCategories = r.bDetectCategories;
696 bMakeTotalCol = r.bMakeTotalCol;
697 bMakeTotalRow = r.bMakeTotalRow;
699 SetPivotArrays ( r.aPageArr, r.aColArr, r.aRowArr, r.aDataArr,
700 r.nPageCount, r.nColCount, r.nRowCount, r.nDataCount );
701 SetLabelData(r.maLabelArray);
702 return *this;
705 //------------------------------------------------------------------------
707 BOOL __EXPORT ScPivotParam::operator==( const ScPivotParam& r ) const
709 BOOL bEqual = (nCol == r.nCol)
710 && (nRow == r.nRow)
711 && (nTab == r.nTab)
712 && (bIgnoreEmptyRows == r.bIgnoreEmptyRows)
713 && (bDetectCategories == r.bDetectCategories)
714 && (bMakeTotalCol == r.bMakeTotalCol)
715 && (bMakeTotalRow == r.bMakeTotalRow)
716 && (maLabelArray.size() == r.maLabelArray.size())
717 && (nPageCount == r.nPageCount)
718 && (nColCount == r.nColCount)
719 && (nRowCount == r.nRowCount)
720 && (nDataCount == r.nDataCount);
722 if ( bEqual )
724 SCSIZE i;
726 for ( i=0; i<nPageCount && bEqual; i++ )
727 bEqual = ( aPageArr[i] == r.aPageArr[i] );
729 for ( i=0; i<nColCount && bEqual; i++ )
730 bEqual = ( aColArr[i] == r.aColArr[i] );
732 for ( i=0; i<nRowCount && bEqual; i++ )
733 bEqual = ( aRowArr[i] == r.aRowArr[i] );
735 for ( i=0; i<nDataCount && bEqual; i++ )
736 bEqual = ( aDataArr[i] == r.aDataArr[i] );
739 return bEqual;
742 //------------------------------------------------------------------------
743 // struct ScSolveParam
745 ScSolveParam::ScSolveParam()
746 : pStrTargetVal( NULL )
750 //------------------------------------------------------------------------
752 ScSolveParam::ScSolveParam( const ScSolveParam& r )
753 : aRefFormulaCell ( r.aRefFormulaCell ),
754 aRefVariableCell( r.aRefVariableCell ),
755 pStrTargetVal ( r.pStrTargetVal
756 ? new String(*r.pStrTargetVal)
757 : NULL )
761 //------------------------------------------------------------------------
763 ScSolveParam::ScSolveParam( const ScAddress& rFormulaCell,
764 const ScAddress& rVariableCell,
765 const String& rTargetValStr )
766 : aRefFormulaCell ( rFormulaCell ),
767 aRefVariableCell( rVariableCell ),
768 pStrTargetVal ( new String(rTargetValStr) )
772 //------------------------------------------------------------------------
774 ScSolveParam::~ScSolveParam()
776 delete pStrTargetVal;
779 //------------------------------------------------------------------------
781 ScSolveParam& __EXPORT ScSolveParam::operator=( const ScSolveParam& r )
783 delete pStrTargetVal;
785 aRefFormulaCell = r.aRefFormulaCell;
786 aRefVariableCell = r.aRefVariableCell;
787 pStrTargetVal = r.pStrTargetVal
788 ? new String(*r.pStrTargetVal)
789 : NULL;
790 return *this;
793 //------------------------------------------------------------------------
795 BOOL ScSolveParam::operator==( const ScSolveParam& r ) const
797 BOOL bEqual = (aRefFormulaCell == r.aRefFormulaCell)
798 && (aRefVariableCell == r.aRefVariableCell);
800 if ( bEqual )
802 if ( !pStrTargetVal && !r.pStrTargetVal )
803 bEqual = TRUE;
804 else if ( !pStrTargetVal || !r.pStrTargetVal )
805 bEqual = FALSE;
806 else if ( pStrTargetVal && r.pStrTargetVal )
807 bEqual = ( *pStrTargetVal == *(r.pStrTargetVal) );
810 return bEqual;
814 //------------------------------------------------------------------------
815 // struct ScTabOpParam
817 ScTabOpParam::ScTabOpParam( const ScTabOpParam& r )
818 : aRefFormulaCell ( r.aRefFormulaCell ),
819 aRefFormulaEnd ( r.aRefFormulaEnd ),
820 aRefRowCell ( r.aRefRowCell ),
821 aRefColCell ( r.aRefColCell ),
822 nMode ( r.nMode )
826 //------------------------------------------------------------------------
828 ScTabOpParam::ScTabOpParam( const ScRefAddress& rFormulaCell,
829 const ScRefAddress& rFormulaEnd,
830 const ScRefAddress& rRowCell,
831 const ScRefAddress& rColCell,
832 BYTE nMd)
833 : aRefFormulaCell ( rFormulaCell ),
834 aRefFormulaEnd ( rFormulaEnd ),
835 aRefRowCell ( rRowCell ),
836 aRefColCell ( rColCell ),
837 nMode ( nMd )
841 //------------------------------------------------------------------------
843 ScTabOpParam& ScTabOpParam::operator=( const ScTabOpParam& r )
845 aRefFormulaCell = r.aRefFormulaCell;
846 aRefFormulaEnd = r.aRefFormulaEnd;
847 aRefRowCell = r.aRefRowCell;
848 aRefColCell = r.aRefColCell;
849 nMode = r.nMode;
850 return *this;
853 //------------------------------------------------------------------------
855 BOOL __EXPORT ScTabOpParam::operator==( const ScTabOpParam& r ) const
857 return ( (aRefFormulaCell == r.aRefFormulaCell)
858 && (aRefFormulaEnd == r.aRefFormulaEnd)
859 && (aRefRowCell == r.aRefRowCell)
860 && (aRefColCell == r.aRefColCell)
861 && (nMode == r.nMode) );
864 String ScGlobal::GetAbsDocName( const String& rFileName,
865 SfxObjectShell* pShell )
867 String aAbsName;
868 if ( !pShell->HasName() )
869 { // maybe relative to document path working directory
870 INetURLObject aObj;
871 SvtPathOptions aPathOpt;
872 aObj.SetSmartURL( aPathOpt.GetWorkPath() );
873 aObj.setFinalSlash(); // it IS a path
874 bool bWasAbs = true;
875 aAbsName = aObj.smartRel2Abs( rFileName, bWasAbs ).GetMainURL(INetURLObject::NO_DECODE);
876 // returned string must be encoded because it's used directly to create SfxMedium
878 else
880 const SfxMedium* pMedium = pShell->GetMedium();
881 if ( pMedium )
883 bool bWasAbs = true;
884 aAbsName = pMedium->GetURLObject().smartRel2Abs( rFileName, bWasAbs ).GetMainURL(INetURLObject::NO_DECODE);
886 else
887 { // This can't happen, but ...
888 // just to be sure to have the same encoding
889 INetURLObject aObj;
890 aObj.SetSmartURL( aAbsName );
891 aAbsName = aObj.GetMainURL(INetURLObject::NO_DECODE);
894 return aAbsName;
898 String ScGlobal::GetDocTabName( const String& rFileName,
899 const String& rTabName )
901 String aDocTab( '\'' );
902 aDocTab += rFileName;
903 xub_StrLen nPos = 1;
904 while( (nPos = aDocTab.Search( '\'', nPos ))
905 != STRING_NOTFOUND )
906 { // escape Quotes
907 aDocTab.Insert( '\\', nPos );
908 nPos += 2;
910 aDocTab += '\'';
911 aDocTab += SC_COMPILER_FILE_TAB_SEP;
912 aDocTab += rTabName; // "'Doc'#Tab"
913 return aDocTab;
916 // ============================================================================
918 ScSimpleSharedString::StringTable::StringTable() :
919 mnStrCount(0)
921 // empty string (ID = 0)
922 maSharedStrings.push_back(String());
923 maSharedStringIds.insert( SharedStrMap::value_type(String(), mnStrCount++) );
926 ScSimpleSharedString::StringTable::StringTable(const ScSimpleSharedString::StringTable& r) :
927 maSharedStrings(r.maSharedStrings),
928 maSharedStringIds(r.maSharedStringIds),
929 mnStrCount(r.mnStrCount)
933 ScSimpleSharedString::StringTable::~StringTable()
937 sal_Int32 ScSimpleSharedString::StringTable::insertString(const String& aStr)
939 SharedStrMap::const_iterator itr = maSharedStringIds.find(aStr),
940 itrEnd = maSharedStringIds.end();
942 if (itr == itrEnd)
944 // new string.
945 maSharedStrings.push_back(aStr);
946 maSharedStringIds.insert( SharedStrMap::value_type(aStr, mnStrCount) );
947 return mnStrCount++;
950 // existing string.
951 return itr->second;
954 sal_Int32 ScSimpleSharedString::StringTable::getStringId(const String& aStr)
956 SharedStrMap::const_iterator itr = maSharedStringIds.find(aStr),
957 itrEnd = maSharedStringIds.end();
958 if (itr == itrEnd)
960 // string not found.
961 return insertString(aStr);
963 return itr->second;
966 const String* ScSimpleSharedString::StringTable::getString(sal_Int32 nId) const
968 if (nId >= mnStrCount)
969 return NULL;
971 return &maSharedStrings[nId];
974 // ----------------------------------------------------------------------------
976 ScSimpleSharedString::ScSimpleSharedString()
980 ScSimpleSharedString::ScSimpleSharedString(const ScSimpleSharedString& r) :
981 maStringTable(r.maStringTable)
985 ScSimpleSharedString::~ScSimpleSharedString()
989 sal_Int32 ScSimpleSharedString::insertString(const String& aStr)
991 return maStringTable.insertString(aStr);
994 const String* ScSimpleSharedString::getString(sal_Int32 nId)
996 return maStringTable.getString(nId);
999 sal_Int32 ScSimpleSharedString::getStringId(const String& aStr)
1001 return maStringTable.getStringId(aStr);