Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / core / data / subtotalparam.cxx
blobb449ba2db353400b586dda1daf204294a27bc617
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
11 #include "subtotalparam.hxx"
13 ScSubTotalParam::ScSubTotalParam()
15 for ( sal_uInt16 i=0; i<MAXSUBTOTAL; i++ )
17 nSubTotals[i] = 0;
18 pSubTotals[i] = NULL;
19 pFunctions[i] = NULL;
22 Clear();
25 //------------------------------------------------------------------------
27 ScSubTotalParam::ScSubTotalParam( const ScSubTotalParam& r ) :
28 nCol1(r.nCol1),nRow1(r.nRow1),nCol2(r.nCol2),nRow2(r.nRow2),nUserIndex(r.nUserIndex),
29 bRemoveOnly(r.bRemoveOnly),bReplace(r.bReplace),bPagebreak(r.bPagebreak),bCaseSens(r.bCaseSens),
30 bDoSort(r.bDoSort),bAscending(r.bAscending),bUserDef(r.bUserDef),
31 bIncludePattern(r.bIncludePattern)
33 for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
35 bGroupActive[i] = r.bGroupActive[i];
36 nField[i] = r.nField[i];
38 if ( (r.nSubTotals[i] > 0) && r.pSubTotals[i] && r.pFunctions[i] )
40 nSubTotals[i] = r.nSubTotals[i];
41 pSubTotals[i] = new SCCOL [r.nSubTotals[i]];
42 pFunctions[i] = new ScSubTotalFunc [r.nSubTotals[i]];
44 for (SCCOL j=0; j<r.nSubTotals[i]; j++)
46 pSubTotals[i][j] = r.pSubTotals[i][j];
47 pFunctions[i][j] = r.pFunctions[i][j];
50 else
52 nSubTotals[i] = 0;
53 pSubTotals[i] = NULL;
54 pFunctions[i] = NULL;
59 //------------------------------------------------------------------------
61 void ScSubTotalParam::Clear()
63 nCol1=nCol2= 0;
64 nRow1=nRow2 = 0;
65 nUserIndex = 0;
66 bPagebreak=bCaseSens=bUserDef=bIncludePattern=bRemoveOnly = false;
67 bAscending=bReplace=bDoSort = true;
69 for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
71 bGroupActive[i] = false;
72 nField[i] = 0;
74 if ( (nSubTotals[i] > 0) && pSubTotals[i] && pFunctions[i] )
76 for ( SCCOL j=0; j<nSubTotals[i]; j++ ) {
77 pSubTotals[i][j] = 0;
78 pFunctions[i][j] = SUBTOTAL_FUNC_NONE;
84 //------------------------------------------------------------------------
86 ScSubTotalParam& ScSubTotalParam::operator=( const ScSubTotalParam& r )
88 nCol1 = r.nCol1;
89 nRow1 = r.nRow1;
90 nCol2 = r.nCol2;
91 nRow2 = r.nRow2;
92 bRemoveOnly = r.bRemoveOnly;
93 bReplace = r.bReplace;
94 bPagebreak = r.bPagebreak;
95 bCaseSens = r.bCaseSens;
96 bDoSort = r.bDoSort;
97 bAscending = r.bAscending;
98 bUserDef = r.bUserDef;
99 nUserIndex = r.nUserIndex;
100 bIncludePattern = r.bIncludePattern;
102 for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
104 bGroupActive[i] = r.bGroupActive[i];
105 nField[i] = r.nField[i];
106 nSubTotals[i] = r.nSubTotals[i];
108 if ( pSubTotals[i] ) delete [] pSubTotals[i];
109 if ( pFunctions[i] ) delete [] pFunctions[i];
111 if ( r.nSubTotals[i] > 0 )
113 pSubTotals[i] = new SCCOL [r.nSubTotals[i]];
114 pFunctions[i] = new ScSubTotalFunc [r.nSubTotals[i]];
116 for (SCCOL j=0; j<r.nSubTotals[i]; j++)
118 pSubTotals[i][j] = r.pSubTotals[i][j];
119 pFunctions[i][j] = r.pFunctions[i][j];
122 else
124 nSubTotals[i] = 0;
125 pSubTotals[i] = NULL;
126 pFunctions[i] = NULL;
130 return *this;
133 //------------------------------------------------------------------------
135 bool ScSubTotalParam::operator==( const ScSubTotalParam& rOther ) const
137 bool bEqual = (nCol1 == rOther.nCol1)
138 && (nRow1 == rOther.nRow1)
139 && (nCol2 == rOther.nCol2)
140 && (nRow2 == rOther.nRow2)
141 && (nUserIndex == rOther.nUserIndex)
142 && (bRemoveOnly == rOther.bRemoveOnly)
143 && (bReplace == rOther.bReplace)
144 && (bPagebreak == rOther.bPagebreak)
145 && (bDoSort == rOther.bDoSort)
146 && (bCaseSens == rOther.bCaseSens)
147 && (bAscending == rOther.bAscending)
148 && (bUserDef == rOther.bUserDef)
149 && (bIncludePattern== rOther.bIncludePattern);
151 if ( bEqual )
153 bEqual = true;
154 for ( sal_uInt16 i=0; i<MAXSUBTOTAL && bEqual; i++ )
156 bEqual = (bGroupActive[i] == rOther.bGroupActive[i])
157 && (nField[i] == rOther.nField[i])
158 && (nSubTotals[i] == rOther.nSubTotals[i]);
160 if ( bEqual && (nSubTotals[i] > 0) )
162 for (SCCOL j=0; (j<nSubTotals[i]) && bEqual; j++)
164 bEqual = bEqual
165 && (pSubTotals[i][j] == rOther.pSubTotals[i][j])
166 && (pFunctions[i][j] == rOther.pFunctions[i][j]);
172 return bEqual;
175 //------------------------------------------------------------------------
177 void ScSubTotalParam::SetSubTotals( sal_uInt16 nGroup,
178 const SCCOL* ptrSubTotals,
179 const ScSubTotalFunc* ptrFunctions,
180 sal_uInt16 nCount )
182 OSL_ENSURE( (nGroup <= MAXSUBTOTAL),
183 "ScSubTotalParam::SetSubTotals(): nGroup > MAXSUBTOTAL!" );
184 OSL_ENSURE( ptrSubTotals,
185 "ScSubTotalParam::SetSubTotals(): ptrSubTotals == NULL!" );
186 OSL_ENSURE( ptrFunctions,
187 "ScSubTotalParam::SetSubTotals(): ptrFunctions == NULL!" );
188 OSL_ENSURE( (nCount > 0),
189 "ScSubTotalParam::SetSubTotals(): nCount <= 0!" );
191 if ( ptrSubTotals && ptrFunctions && (nCount > 0) && (nGroup <= MAXSUBTOTAL) )
193 // 0 wird als 1 aufgefasst, sonst zum Array-Index dekrementieren
194 if (nGroup != 0)
195 nGroup--;
197 delete [] pSubTotals[nGroup];
198 delete [] pFunctions[nGroup];
200 pSubTotals[nGroup] = new SCCOL [nCount];
201 pFunctions[nGroup] = new ScSubTotalFunc [nCount];
202 nSubTotals[nGroup] = static_cast<SCCOL>(nCount);
204 for ( sal_uInt16 i=0; i<nCount; i++ )
206 pSubTotals[nGroup][i] = ptrSubTotals[i];
207 pFunctions[nGroup][i] = ptrFunctions[i];
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */