Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Initial Developer of the Original Code is
16 : * Kohei Yoshida <kyoshida@novell.com> (Novell, Inc.)
17 : * Portions created by the Initial Developer are Copyright (C) 2010 the
18 : * Initial Developer. All Rights Reserved.
19 : *
20 : * Contributor(s):
21 : *
22 : * Alternatively, the contents of this file may be used under the terms of
23 : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 : * instead of those above.
27 : */
28 :
29 :
30 : #include "subtotalparam.hxx"
31 :
32 18 : ScSubTotalParam::ScSubTotalParam()
33 : {
34 72 : for ( sal_uInt16 i=0; i<MAXSUBTOTAL; i++ )
35 : {
36 54 : nSubTotals[i] = 0;
37 54 : pSubTotals[i] = NULL;
38 54 : pFunctions[i] = NULL;
39 : }
40 :
41 18 : Clear();
42 18 : }
43 :
44 : //------------------------------------------------------------------------
45 :
46 16 : ScSubTotalParam::ScSubTotalParam( const ScSubTotalParam& r ) :
47 : nCol1(r.nCol1),nRow1(r.nRow1),nCol2(r.nCol2),nRow2(r.nRow2),nUserIndex(r.nUserIndex),
48 : bRemoveOnly(r.bRemoveOnly),bReplace(r.bReplace),bPagebreak(r.bPagebreak),bCaseSens(r.bCaseSens),
49 : bDoSort(r.bDoSort),bAscending(r.bAscending),bUserDef(r.bUserDef),
50 16 : bIncludePattern(r.bIncludePattern)
51 : {
52 64 : for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
53 : {
54 48 : bGroupActive[i] = r.bGroupActive[i];
55 48 : nField[i] = r.nField[i];
56 :
57 48 : if ( (r.nSubTotals[i] > 0) && r.pSubTotals[i] && r.pFunctions[i] )
58 : {
59 0 : nSubTotals[i] = r.nSubTotals[i];
60 0 : pSubTotals[i] = new SCCOL [r.nSubTotals[i]];
61 0 : pFunctions[i] = new ScSubTotalFunc [r.nSubTotals[i]];
62 :
63 0 : for (SCCOL j=0; j<r.nSubTotals[i]; j++)
64 : {
65 0 : pSubTotals[i][j] = r.pSubTotals[i][j];
66 0 : pFunctions[i][j] = r.pFunctions[i][j];
67 0 : }
68 : }
69 : else
70 : {
71 48 : nSubTotals[i] = 0;
72 48 : pSubTotals[i] = NULL;
73 48 : pFunctions[i] = NULL;
74 : }
75 : }
76 16 : }
77 :
78 : //------------------------------------------------------------------------
79 :
80 18 : void ScSubTotalParam::Clear()
81 : {
82 18 : nCol1=nCol2= 0;
83 18 : nRow1=nRow2 = 0;
84 18 : nUserIndex = 0;
85 18 : bPagebreak=bCaseSens=bUserDef=bIncludePattern=bRemoveOnly = false;
86 18 : bAscending=bReplace=bDoSort = true;
87 :
88 72 : for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
89 : {
90 54 : bGroupActive[i] = false;
91 54 : nField[i] = 0;
92 :
93 54 : if ( (nSubTotals[i] > 0) && pSubTotals[i] && pFunctions[i] )
94 : {
95 0 : for ( SCCOL j=0; j<nSubTotals[i]; j++ ) {
96 0 : pSubTotals[i][j] = 0;
97 0 : pFunctions[i][j] = SUBTOTAL_FUNC_NONE;
98 : }
99 : }
100 : }
101 18 : }
102 :
103 : //------------------------------------------------------------------------
104 :
105 0 : ScSubTotalParam& ScSubTotalParam::operator=( const ScSubTotalParam& r )
106 : {
107 0 : nCol1 = r.nCol1;
108 0 : nRow1 = r.nRow1;
109 0 : nCol2 = r.nCol2;
110 0 : nRow2 = r.nRow2;
111 0 : bRemoveOnly = r.bRemoveOnly;
112 0 : bReplace = r.bReplace;
113 0 : bPagebreak = r.bPagebreak;
114 0 : bCaseSens = r.bCaseSens;
115 0 : bDoSort = r.bDoSort;
116 0 : bAscending = r.bAscending;
117 0 : bUserDef = r.bUserDef;
118 0 : nUserIndex = r.nUserIndex;
119 0 : bIncludePattern = r.bIncludePattern;
120 :
121 0 : for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
122 : {
123 0 : bGroupActive[i] = r.bGroupActive[i];
124 0 : nField[i] = r.nField[i];
125 0 : nSubTotals[i] = r.nSubTotals[i];
126 :
127 0 : if ( pSubTotals[i] ) delete [] pSubTotals[i];
128 0 : if ( pFunctions[i] ) delete [] pFunctions[i];
129 :
130 0 : if ( r.nSubTotals[i] > 0 )
131 : {
132 0 : pSubTotals[i] = new SCCOL [r.nSubTotals[i]];
133 0 : pFunctions[i] = new ScSubTotalFunc [r.nSubTotals[i]];
134 :
135 0 : for (SCCOL j=0; j<r.nSubTotals[i]; j++)
136 : {
137 0 : pSubTotals[i][j] = r.pSubTotals[i][j];
138 0 : pFunctions[i][j] = r.pFunctions[i][j];
139 : }
140 : }
141 : else
142 : {
143 0 : nSubTotals[i] = 0;
144 0 : pSubTotals[i] = NULL;
145 0 : pFunctions[i] = NULL;
146 : }
147 : }
148 :
149 0 : return *this;
150 : }
151 :
152 : //------------------------------------------------------------------------
153 :
154 0 : bool ScSubTotalParam::operator==( const ScSubTotalParam& rOther ) const
155 : {
156 : bool bEqual = (nCol1 == rOther.nCol1)
157 : && (nRow1 == rOther.nRow1)
158 : && (nCol2 == rOther.nCol2)
159 : && (nRow2 == rOther.nRow2)
160 : && (nUserIndex == rOther.nUserIndex)
161 : && (bRemoveOnly == rOther.bRemoveOnly)
162 : && (bReplace == rOther.bReplace)
163 : && (bPagebreak == rOther.bPagebreak)
164 : && (bDoSort == rOther.bDoSort)
165 : && (bCaseSens == rOther.bCaseSens)
166 : && (bAscending == rOther.bAscending)
167 : && (bUserDef == rOther.bUserDef)
168 0 : && (bIncludePattern== rOther.bIncludePattern);
169 :
170 0 : if ( bEqual )
171 : {
172 0 : bEqual = true;
173 0 : for ( sal_uInt16 i=0; i<MAXSUBTOTAL && bEqual; i++ )
174 : {
175 0 : bEqual = (bGroupActive[i] == rOther.bGroupActive[i])
176 0 : && (nField[i] == rOther.nField[i])
177 0 : && (nSubTotals[i] == rOther.nSubTotals[i]);
178 :
179 0 : if ( bEqual && (nSubTotals[i] > 0) )
180 : {
181 0 : bEqual = (pSubTotals != NULL) && (pFunctions != NULL);
182 :
183 0 : for (SCCOL j=0; (j<nSubTotals[i]) && bEqual; j++)
184 : {
185 : bEqual = bEqual
186 0 : && (pSubTotals[i][j] == rOther.pSubTotals[i][j])
187 0 : && (pFunctions[i][j] == rOther.pFunctions[i][j]);
188 : }
189 : }
190 : }
191 : }
192 :
193 0 : return bEqual;
194 : }
195 :
196 : //------------------------------------------------------------------------
197 :
198 0 : void ScSubTotalParam::SetSubTotals( sal_uInt16 nGroup,
199 : const SCCOL* ptrSubTotals,
200 : const ScSubTotalFunc* ptrFunctions,
201 : sal_uInt16 nCount )
202 : {
203 : OSL_ENSURE( (nGroup <= MAXSUBTOTAL),
204 : "ScSubTotalParam::SetSubTotals(): nGroup > MAXSUBTOTAL!" );
205 : OSL_ENSURE( ptrSubTotals,
206 : "ScSubTotalParam::SetSubTotals(): ptrSubTotals == NULL!" );
207 : OSL_ENSURE( ptrFunctions,
208 : "ScSubTotalParam::SetSubTotals(): ptrFunctions == NULL!" );
209 : OSL_ENSURE( (nCount > 0),
210 : "ScSubTotalParam::SetSubTotals(): nCount <= 0!" );
211 :
212 0 : if ( ptrSubTotals && ptrFunctions && (nCount > 0) && (nGroup <= MAXSUBTOTAL) )
213 : {
214 : // 0 wird als 1 aufgefasst, sonst zum Array-Index dekrementieren
215 0 : if (nGroup != 0)
216 0 : nGroup--;
217 :
218 0 : delete [] pSubTotals[nGroup];
219 0 : delete [] pFunctions[nGroup];
220 :
221 0 : pSubTotals[nGroup] = new SCCOL [nCount];
222 0 : pFunctions[nGroup] = new ScSubTotalFunc [nCount];
223 0 : nSubTotals[nGroup] = static_cast<SCCOL>(nCount);
224 :
225 0 : for ( sal_uInt16 i=0; i<nCount; i++ )
226 : {
227 0 : pSubTotals[nGroup][i] = ptrSubTotals[i];
228 0 : pFunctions[nGroup][i] = ptrFunctions[i];
229 : }
230 : }
231 0 : }
232 :
233 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|