Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "sortparam.hxx"
30 : : #include "global.hxx"
31 : : #include "address.hxx"
32 : : #include "queryparam.hxx"
33 : : #include "subtotalparam.hxx"
34 : :
35 : :
36 : : //------------------------------------------------------------------------
37 : :
38 : 2546 : ScSortParam::ScSortParam()
39 : : {
40 [ + - ]: 2546 : Clear();
41 : 2546 : }
42 : :
43 : : //------------------------------------------------------------------------
44 : :
45 : 714 : ScSortParam::ScSortParam( const ScSortParam& r ) :
46 : : nCol1(r.nCol1),nRow1(r.nRow1),nCol2(r.nCol2),nRow2(r.nRow2),nUserIndex(r.nUserIndex),
47 : : bHasHeader(r.bHasHeader),bByRow(r.bByRow),bCaseSens(r.bCaseSens),
48 : : bNaturalSort(r.bNaturalSort),bUserDef(r.bUserDef),
49 : : bIncludePattern(r.bIncludePattern),bInplace(r.bInplace),
50 : : nDestTab(r.nDestTab),nDestCol(r.nDestCol),nDestRow(r.nDestRow),
51 : : maKeyState( r.maKeyState ),
52 : : aCollatorLocale( r.aCollatorLocale ), aCollatorAlgorithm( r.aCollatorAlgorithm ),
53 : 714 : nCompatHeader( r.nCompatHeader )
54 : : {
55 : 714 : }
56 : :
57 : : //------------------------------------------------------------------------
58 : :
59 : 2546 : void ScSortParam::Clear()
60 : : {
61 : : ScSortKeyState aKeyState;
62 : :
63 : 2546 : nCol1=nCol2=nDestCol = 0;
64 : 2546 : nRow1=nRow2=nDestRow = 0;
65 : 2546 : nCompatHeader = 2;
66 : 2546 : nDestTab = 0;
67 : 2546 : nUserIndex = 0;
68 : 2546 : bHasHeader=bCaseSens=bUserDef=bNaturalSort = false;
69 : 2546 : bByRow=bIncludePattern=bInplace = true;
70 : 2546 : aCollatorLocale = ::com::sun::star::lang::Locale();
71 : 2546 : aCollatorAlgorithm = ::rtl::OUString();
72 : :
73 : 2546 : aKeyState.bDoSort = false;
74 : 2546 : aKeyState.nField = 0;
75 : 2546 : aKeyState.bAscending = true;
76 : :
77 : : // Initialize to default size
78 [ + - ]: 2546 : maKeyState.assign( DEFSORT, aKeyState );
79 : 2546 : }
80 : :
81 : : //------------------------------------------------------------------------
82 : :
83 : 24 : ScSortParam& ScSortParam::operator=( const ScSortParam& r )
84 : : {
85 : 24 : nCol1 = r.nCol1;
86 : 24 : nRow1 = r.nRow1;
87 : 24 : nCol2 = r.nCol2;
88 : 24 : nRow2 = r.nRow2;
89 : 24 : nUserIndex = r.nUserIndex;
90 : 24 : bHasHeader = r.bHasHeader;
91 : 24 : bByRow = r.bByRow;
92 : 24 : bCaseSens = r.bCaseSens;
93 : 24 : bNaturalSort = r.bNaturalSort;
94 : 24 : bUserDef = r.bUserDef;
95 : 24 : bIncludePattern = r.bIncludePattern;
96 : 24 : bInplace = r.bInplace;
97 : 24 : nDestTab = r.nDestTab;
98 : 24 : nDestCol = r.nDestCol;
99 : 24 : nDestRow = r.nDestRow;
100 : 24 : maKeyState = r.maKeyState;
101 : 24 : aCollatorLocale = r.aCollatorLocale;
102 : 24 : aCollatorAlgorithm = r.aCollatorAlgorithm;
103 : 24 : nCompatHeader = r.nCompatHeader;
104 : :
105 : 24 : return *this;
106 : : }
107 : :
108 : : //------------------------------------------------------------------------
109 : :
110 : 0 : bool ScSortParam::operator==( const ScSortParam& rOther ) const
111 : : {
112 : 0 : bool bEqual = false;
113 : : // Anzahl der Sorts gleich?
114 : 0 : sal_uInt16 nLast = 0;
115 : 0 : sal_uInt16 nOtherLast = 0;
116 : 0 : sal_uInt16 nSortSize = GetSortKeyCount();
117 : :
118 [ # # ]: 0 : if ( !maKeyState.empty() )
119 : : {
120 [ # # ][ # # ]: 0 : while ( maKeyState[nLast++].bDoSort && nLast < nSortSize ) ;
[ # # ]
121 : 0 : nLast--;
122 : : }
123 : :
124 [ # # ]: 0 : if ( !rOther.maKeyState.empty() )
125 : : {
126 [ # # ][ # # ]: 0 : while ( rOther.maKeyState[nOtherLast++].bDoSort && nOtherLast < nSortSize ) ;
[ # # ]
127 : 0 : nOtherLast--;
128 : : }
129 : :
130 [ # # ][ # # ]: 0 : if ( (nLast == nOtherLast)
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # #
# # # # #
# # # # #
# # ][ # # ]
131 : : && (nCol1 == rOther.nCol1)
132 : : && (nRow1 == rOther.nRow1)
133 : : && (nCol2 == rOther.nCol2)
134 : : && (nRow2 == rOther.nRow2)
135 : : && (bHasHeader == rOther.bHasHeader)
136 : : && (bByRow == rOther.bByRow)
137 : : && (bCaseSens == rOther.bCaseSens)
138 : : && (bNaturalSort == rOther.bNaturalSort)
139 : : && (bUserDef == rOther.bUserDef)
140 : : && (nUserIndex == rOther.nUserIndex)
141 : : && (bIncludePattern == rOther.bIncludePattern)
142 : : && (bInplace == rOther.bInplace)
143 : : && (nDestTab == rOther.nDestTab)
144 : : && (nDestCol == rOther.nDestCol)
145 : : && (nDestRow == rOther.nDestRow)
146 : 0 : && (aCollatorLocale.Language == rOther.aCollatorLocale.Language)
147 : 0 : && (aCollatorLocale.Country == rOther.aCollatorLocale.Country)
148 : 0 : && (aCollatorLocale.Variant == rOther.aCollatorLocale.Variant)
149 : 0 : && (aCollatorAlgorithm == rOther.aCollatorAlgorithm)
150 : 0 : && ( !maKeyState.empty() || !rOther.maKeyState.empty() )
151 : : )
152 : : {
153 : 0 : bEqual = true;
154 [ # # ][ # # ]: 0 : for ( sal_uInt16 i=0; i<=nLast && bEqual; i++ )
[ # # ]
155 : 0 : bEqual = ( maKeyState[i].nField == rOther.maKeyState[i].nField ) &&
156 [ # # ][ # # ]: 0 : ( maKeyState[i].bAscending == rOther.maKeyState[i].bAscending );
157 : : }
158 [ # # ][ # # ]: 0 : if ( maKeyState.empty() && rOther.maKeyState.empty() )
[ # # ]
159 : 0 : bEqual = true;
160 : :
161 : 0 : return bEqual;
162 : : }
163 : :
164 : : //------------------------------------------------------------------------
165 : :
166 : 2 : ScSortParam::ScSortParam( const ScSubTotalParam& rSub, const ScSortParam& rOld ) :
167 : : nCol1(rSub.nCol1),nRow1(rSub.nRow1),nCol2(rSub.nCol2),nRow2(rSub.nRow2),nUserIndex(rSub.nUserIndex),
168 : : bHasHeader(true),bByRow(true),bCaseSens(rSub.bCaseSens),bNaturalSort(rOld.bNaturalSort),
169 : : bUserDef(rSub.bUserDef),bIncludePattern(rSub.bIncludePattern),
170 : : bInplace(true),
171 : : nDestTab(0),nDestCol(0),nDestRow(0),
172 : : aCollatorLocale( rOld.aCollatorLocale ), aCollatorAlgorithm( rOld.aCollatorAlgorithm ),
173 : 2 : nCompatHeader( rOld.nCompatHeader )
174 : : {
175 : : sal_uInt16 i;
176 : :
177 : : // zuerst die Gruppen aus den Teilergebnissen
178 [ + - ]: 2 : if (rSub.bDoSort)
179 [ + + ]: 8 : for (i=0; i<MAXSUBTOTAL; i++)
180 [ + + ]: 6 : if (rSub.bGroupActive[i])
181 : : {
182 : : ScSortKeyState key;
183 : 2 : key.bDoSort = true;
184 : 2 : key.nField = rSub.nField[i];
185 : 2 : key.bAscending = rSub.bAscending;
186 [ + - ]: 2 : maKeyState.push_back(key);
187 : : }
188 : :
189 : : // dann dahinter die alten Einstellungen
190 [ + + ]: 8 : for (i=0; i < rOld.GetSortKeyCount(); i++)
191 [ - + ]: 6 : if (rOld.maKeyState[i].bDoSort)
192 : : {
193 : 0 : SCCOLROW nThisField = rOld.maKeyState[i].nField;
194 : 0 : bool bDouble = false;
195 [ # # ]: 0 : for (sal_uInt16 j = 0; j < GetSortKeyCount(); j++)
196 [ # # ]: 0 : if ( maKeyState[j].nField == nThisField )
197 : 0 : bDouble = true;
198 [ # # ]: 0 : if (!bDouble) // ein Feld nicht zweimal eintragen
199 : : {
200 : : ScSortKeyState key;
201 : 0 : key.bDoSort = true;
202 : 0 : key.nField = nThisField;
203 : 0 : key.bAscending = rOld.maKeyState[i].bAscending;
204 [ # # ]: 0 : maKeyState.push_back(key);
205 : : }
206 : : }
207 : 2 : }
208 : :
209 : : //------------------------------------------------------------------------
210 : :
211 : 0 : ScSortParam::ScSortParam( const ScQueryParam& rParam, SCCOL nCol ) :
212 : : nCol1(nCol),nRow1(rParam.nRow1),nCol2(nCol),nRow2(rParam.nRow2),nUserIndex(0),
213 : : bHasHeader(rParam.bHasHeader),bByRow(true),bCaseSens(rParam.bCaseSens),
214 : : bNaturalSort(false),
215 : : //! TODO: what about Locale and Algorithm?
216 : : bUserDef(false),bIncludePattern(false),
217 : : bInplace(true),
218 : 0 : nDestTab(0),nDestCol(0),nDestRow(0), nCompatHeader(2)
219 : : {
220 : : ScSortKeyState aKeyState;
221 : 0 : aKeyState.bDoSort = true;
222 : 0 : aKeyState.nField = nCol;
223 : 0 : aKeyState.bAscending = true;
224 : :
225 [ # # ]: 0 : maKeyState.push_back( aKeyState );
226 : :
227 : : // Set the rest
228 : 0 : aKeyState.bDoSort = false;
229 : 0 : aKeyState.nField = 0;
230 : :
231 [ # # ]: 0 : for (sal_uInt16 i=1; i<GetSortKeyCount(); i++)
232 [ # # ]: 0 : maKeyState.push_back( aKeyState );
233 : 0 : }
234 : :
235 : : //------------------------------------------------------------------------
236 : :
237 : 0 : void ScSortParam::MoveToDest()
238 : : {
239 [ # # ]: 0 : if (!bInplace)
240 : : {
241 : 0 : SCsCOL nDifX = ((SCsCOL) nDestCol) - ((SCsCOL) nCol1);
242 : 0 : SCsROW nDifY = ((SCsROW) nDestRow) - ((SCsROW) nRow1);
243 : :
244 : 0 : nCol1 = sal::static_int_cast<SCCOL>( nCol1 + nDifX );
245 : 0 : nRow1 = sal::static_int_cast<SCROW>( nRow1 + nDifY );
246 : 0 : nCol2 = sal::static_int_cast<SCCOL>( nCol2 + nDifX );
247 : 0 : nRow2 = sal::static_int_cast<SCROW>( nRow2 + nDifY );
248 [ # # ]: 0 : for (sal_uInt16 i=0; i<GetSortKeyCount(); i++)
249 [ # # ]: 0 : if (bByRow)
250 : 0 : maKeyState[i].nField += nDifX;
251 : : else
252 : 0 : maKeyState[i].nField += nDifY;
253 : :
254 : 0 : bInplace = true;
255 : : }
256 : : else
257 : : {
258 : : OSL_FAIL("MoveToDest, bInplace == TRUE");
259 : : }
260 : 0 : }
261 : :
262 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|