Branch data 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 : 292 : ScSubTotalParam::ScSubTotalParam()
33 : : {
34 [ + + ]: 1168 : for ( sal_uInt16 i=0; i<MAXSUBTOTAL; i++ )
35 : : {
36 : 876 : nSubTotals[i] = 0;
37 : 876 : pSubTotals[i] = NULL;
38 : 876 : pFunctions[i] = NULL;
39 : : }
40 : :
41 : 292 : Clear();
42 : 292 : }
43 : :
44 : : //------------------------------------------------------------------------
45 : :
46 : 698 : 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 : 698 : bIncludePattern(r.bIncludePattern)
51 : : {
52 [ + + ]: 2792 : for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
53 : : {
54 : 2094 : bGroupActive[i] = r.bGroupActive[i];
55 : 2094 : nField[i] = r.nField[i];
56 : :
57 [ + + ][ + - ]: 2094 : if ( (r.nSubTotals[i] > 0) && r.pSubTotals[i] && r.pFunctions[i] )
[ + - ]
58 : : {
59 : 8 : nSubTotals[i] = r.nSubTotals[i];
60 : 8 : pSubTotals[i] = new SCCOL [r.nSubTotals[i]];
61 : 8 : pFunctions[i] = new ScSubTotalFunc [r.nSubTotals[i]];
62 : :
63 [ + + ]: 16 : for (SCCOL j=0; j<r.nSubTotals[i]; j++)
64 : : {
65 : 8 : pSubTotals[i][j] = r.pSubTotals[i][j];
66 : 8 : pFunctions[i][j] = r.pFunctions[i][j];
67 : 8 : }
68 : : }
69 : : else
70 : : {
71 : 2086 : nSubTotals[i] = 0;
72 : 2086 : pSubTotals[i] = NULL;
73 : 2086 : pFunctions[i] = NULL;
74 : : }
75 : : }
76 : 698 : }
77 : :
78 : : //------------------------------------------------------------------------
79 : :
80 : 292 : void ScSubTotalParam::Clear()
81 : : {
82 : 292 : nCol1=nCol2= 0;
83 : 292 : nRow1=nRow2 = 0;
84 : 292 : nUserIndex = 0;
85 : 292 : bPagebreak=bCaseSens=bUserDef=bIncludePattern=bRemoveOnly = false;
86 : 292 : bAscending=bReplace=bDoSort = true;
87 : :
88 [ + + ]: 1168 : for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
89 : : {
90 : 876 : bGroupActive[i] = false;
91 : 876 : nField[i] = 0;
92 : :
93 [ - + ][ # # ]: 876 : 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 : 292 : }
102 : :
103 : : //------------------------------------------------------------------------
104 : :
105 : 175 : ScSubTotalParam& ScSubTotalParam::operator=( const ScSubTotalParam& r )
106 : : {
107 : 175 : nCol1 = r.nCol1;
108 : 175 : nRow1 = r.nRow1;
109 : 175 : nCol2 = r.nCol2;
110 : 175 : nRow2 = r.nRow2;
111 : 175 : bRemoveOnly = r.bRemoveOnly;
112 : 175 : bReplace = r.bReplace;
113 : 175 : bPagebreak = r.bPagebreak;
114 : 175 : bCaseSens = r.bCaseSens;
115 : 175 : bDoSort = r.bDoSort;
116 : 175 : bAscending = r.bAscending;
117 : 175 : bUserDef = r.bUserDef;
118 : 175 : nUserIndex = r.nUserIndex;
119 : 175 : bIncludePattern = r.bIncludePattern;
120 : :
121 [ + + ]: 700 : for (sal_uInt16 i=0; i<MAXSUBTOTAL; i++)
122 : : {
123 : 525 : bGroupActive[i] = r.bGroupActive[i];
124 : 525 : nField[i] = r.nField[i];
125 : 525 : nSubTotals[i] = r.nSubTotals[i];
126 : :
127 [ + + ][ + - ]: 525 : if ( pSubTotals[i] ) delete [] pSubTotals[i];
128 [ + + ][ + - ]: 525 : if ( pFunctions[i] ) delete [] pFunctions[i];
129 : :
130 [ + + ]: 525 : if ( r.nSubTotals[i] > 0 )
131 : : {
132 : 165 : pSubTotals[i] = new SCCOL [r.nSubTotals[i]];
133 : 165 : pFunctions[i] = new ScSubTotalFunc [r.nSubTotals[i]];
134 : :
135 [ + + ]: 332 : for (SCCOL j=0; j<r.nSubTotals[i]; j++)
136 : : {
137 : 167 : pSubTotals[i][j] = r.pSubTotals[i][j];
138 : 167 : pFunctions[i][j] = r.pFunctions[i][j];
139 : : }
140 : : }
141 : : else
142 : : {
143 : 360 : nSubTotals[i] = 0;
144 : 360 : pSubTotals[i] = NULL;
145 : 360 : pFunctions[i] = NULL;
146 : : }
147 : : }
148 : :
149 : 175 : 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: */
|