Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "sortparam.hxx"
21 : #include "global.hxx"
22 : #include "address.hxx"
23 : #include "queryparam.hxx"
24 : #include "subtotalparam.hxx"
25 :
26 :
27 : //------------------------------------------------------------------------
28 :
29 290 : ScSortParam::ScSortParam()
30 : {
31 290 : Clear();
32 290 : }
33 :
34 : //------------------------------------------------------------------------
35 :
36 16 : ScSortParam::ScSortParam( const ScSortParam& r ) :
37 : nCol1(r.nCol1),nRow1(r.nRow1),nCol2(r.nCol2),nRow2(r.nRow2),nUserIndex(r.nUserIndex),
38 : bHasHeader(r.bHasHeader),bByRow(r.bByRow),bCaseSens(r.bCaseSens),
39 : bNaturalSort(r.bNaturalSort),bUserDef(r.bUserDef),
40 : bIncludePattern(r.bIncludePattern),bInplace(r.bInplace),
41 : nDestTab(r.nDestTab),nDestCol(r.nDestCol),nDestRow(r.nDestRow),
42 : maKeyState( r.maKeyState ),
43 : aCollatorLocale( r.aCollatorLocale ), aCollatorAlgorithm( r.aCollatorAlgorithm ),
44 16 : nCompatHeader( r.nCompatHeader )
45 : {
46 16 : }
47 :
48 : //------------------------------------------------------------------------
49 :
50 290 : void ScSortParam::Clear()
51 : {
52 : ScSortKeyState aKeyState;
53 :
54 290 : nCol1=nCol2=nDestCol = 0;
55 290 : nRow1=nRow2=nDestRow = 0;
56 290 : nCompatHeader = 2;
57 290 : nDestTab = 0;
58 290 : nUserIndex = 0;
59 290 : bHasHeader=bCaseSens=bUserDef=bNaturalSort = false;
60 290 : bByRow=bIncludePattern=bInplace = true;
61 290 : aCollatorLocale = ::com::sun::star::lang::Locale();
62 290 : aCollatorAlgorithm = ::rtl::OUString();
63 :
64 290 : aKeyState.bDoSort = false;
65 290 : aKeyState.nField = 0;
66 290 : aKeyState.bAscending = true;
67 :
68 : // Initialize to default size
69 290 : maKeyState.assign( DEFSORT, aKeyState );
70 290 : }
71 :
72 : //------------------------------------------------------------------------
73 :
74 2 : ScSortParam& ScSortParam::operator=( const ScSortParam& r )
75 : {
76 2 : nCol1 = r.nCol1;
77 2 : nRow1 = r.nRow1;
78 2 : nCol2 = r.nCol2;
79 2 : nRow2 = r.nRow2;
80 2 : nUserIndex = r.nUserIndex;
81 2 : bHasHeader = r.bHasHeader;
82 2 : bByRow = r.bByRow;
83 2 : bCaseSens = r.bCaseSens;
84 2 : bNaturalSort = r.bNaturalSort;
85 2 : bUserDef = r.bUserDef;
86 2 : bIncludePattern = r.bIncludePattern;
87 2 : bInplace = r.bInplace;
88 2 : nDestTab = r.nDestTab;
89 2 : nDestCol = r.nDestCol;
90 2 : nDestRow = r.nDestRow;
91 2 : maKeyState = r.maKeyState;
92 2 : aCollatorLocale = r.aCollatorLocale;
93 2 : aCollatorAlgorithm = r.aCollatorAlgorithm;
94 2 : nCompatHeader = r.nCompatHeader;
95 :
96 2 : return *this;
97 : }
98 :
99 : //------------------------------------------------------------------------
100 :
101 0 : bool ScSortParam::operator==( const ScSortParam& rOther ) const
102 : {
103 0 : bool bEqual = false;
104 : // Anzahl der Sorts gleich?
105 0 : sal_uInt16 nLast = 0;
106 0 : sal_uInt16 nOtherLast = 0;
107 0 : sal_uInt16 nSortSize = GetSortKeyCount();
108 :
109 0 : if ( !maKeyState.empty() )
110 : {
111 0 : while ( maKeyState[nLast++].bDoSort && nLast < nSortSize ) ;
112 0 : nLast--;
113 : }
114 :
115 0 : if ( !rOther.maKeyState.empty() )
116 : {
117 0 : while ( rOther.maKeyState[nOtherLast++].bDoSort && nOtherLast < nSortSize ) ;
118 0 : nOtherLast--;
119 : }
120 :
121 0 : if ( (nLast == nOtherLast)
122 : && (nCol1 == rOther.nCol1)
123 : && (nRow1 == rOther.nRow1)
124 : && (nCol2 == rOther.nCol2)
125 : && (nRow2 == rOther.nRow2)
126 : && (bHasHeader == rOther.bHasHeader)
127 : && (bByRow == rOther.bByRow)
128 : && (bCaseSens == rOther.bCaseSens)
129 : && (bNaturalSort == rOther.bNaturalSort)
130 : && (bUserDef == rOther.bUserDef)
131 : && (nUserIndex == rOther.nUserIndex)
132 : && (bIncludePattern == rOther.bIncludePattern)
133 : && (bInplace == rOther.bInplace)
134 : && (nDestTab == rOther.nDestTab)
135 : && (nDestCol == rOther.nDestCol)
136 : && (nDestRow == rOther.nDestRow)
137 0 : && (aCollatorLocale.Language == rOther.aCollatorLocale.Language)
138 0 : && (aCollatorLocale.Country == rOther.aCollatorLocale.Country)
139 0 : && (aCollatorLocale.Variant == rOther.aCollatorLocale.Variant)
140 0 : && (aCollatorAlgorithm == rOther.aCollatorAlgorithm)
141 0 : && ( !maKeyState.empty() || !rOther.maKeyState.empty() )
142 : )
143 : {
144 0 : bEqual = true;
145 0 : for ( sal_uInt16 i=0; i<=nLast && bEqual; i++ )
146 0 : bEqual = ( maKeyState[i].nField == rOther.maKeyState[i].nField ) &&
147 0 : ( maKeyState[i].bAscending == rOther.maKeyState[i].bAscending );
148 : }
149 0 : if ( maKeyState.empty() && rOther.maKeyState.empty() )
150 0 : bEqual = true;
151 :
152 0 : return bEqual;
153 : }
154 :
155 : //------------------------------------------------------------------------
156 :
157 0 : ScSortParam::ScSortParam( const ScSubTotalParam& rSub, const ScSortParam& rOld ) :
158 : nCol1(rSub.nCol1),nRow1(rSub.nRow1),nCol2(rSub.nCol2),nRow2(rSub.nRow2),nUserIndex(rSub.nUserIndex),
159 : bHasHeader(true),bByRow(true),bCaseSens(rSub.bCaseSens),bNaturalSort(rOld.bNaturalSort),
160 : bUserDef(rSub.bUserDef),bIncludePattern(rSub.bIncludePattern),
161 : bInplace(true),
162 : nDestTab(0),nDestCol(0),nDestRow(0),
163 : aCollatorLocale( rOld.aCollatorLocale ), aCollatorAlgorithm( rOld.aCollatorAlgorithm ),
164 0 : nCompatHeader( rOld.nCompatHeader )
165 : {
166 : sal_uInt16 i;
167 :
168 : // zuerst die Gruppen aus den Teilergebnissen
169 0 : if (rSub.bDoSort)
170 0 : for (i=0; i<MAXSUBTOTAL; i++)
171 0 : if (rSub.bGroupActive[i])
172 : {
173 : ScSortKeyState key;
174 0 : key.bDoSort = true;
175 0 : key.nField = rSub.nField[i];
176 0 : key.bAscending = rSub.bAscending;
177 0 : maKeyState.push_back(key);
178 : }
179 :
180 : // dann dahinter die alten Einstellungen
181 0 : for (i=0; i < rOld.GetSortKeyCount(); i++)
182 0 : if (rOld.maKeyState[i].bDoSort)
183 : {
184 0 : SCCOLROW nThisField = rOld.maKeyState[i].nField;
185 0 : bool bDouble = false;
186 0 : for (sal_uInt16 j = 0; j < GetSortKeyCount(); j++)
187 0 : if ( maKeyState[j].nField == nThisField )
188 0 : bDouble = true;
189 0 : if (!bDouble) // ein Feld nicht zweimal eintragen
190 : {
191 : ScSortKeyState key;
192 0 : key.bDoSort = true;
193 0 : key.nField = nThisField;
194 0 : key.bAscending = rOld.maKeyState[i].bAscending;
195 0 : maKeyState.push_back(key);
196 : }
197 : }
198 0 : }
199 :
200 : //------------------------------------------------------------------------
201 :
202 0 : ScSortParam::ScSortParam( const ScQueryParam& rParam, SCCOL nCol ) :
203 : nCol1(nCol),nRow1(rParam.nRow1),nCol2(nCol),nRow2(rParam.nRow2),nUserIndex(0),
204 : bHasHeader(rParam.bHasHeader),bByRow(true),bCaseSens(rParam.bCaseSens),
205 : bNaturalSort(false),
206 : //! TODO: what about Locale and Algorithm?
207 : bUserDef(false),bIncludePattern(false),
208 : bInplace(true),
209 0 : nDestTab(0),nDestCol(0),nDestRow(0), nCompatHeader(2)
210 : {
211 : ScSortKeyState aKeyState;
212 0 : aKeyState.bDoSort = true;
213 0 : aKeyState.nField = nCol;
214 0 : aKeyState.bAscending = true;
215 :
216 0 : maKeyState.push_back( aKeyState );
217 :
218 : // Set the rest
219 0 : aKeyState.bDoSort = false;
220 0 : aKeyState.nField = 0;
221 :
222 0 : for (sal_uInt16 i=1; i<GetSortKeyCount(); i++)
223 0 : maKeyState.push_back( aKeyState );
224 0 : }
225 :
226 : //------------------------------------------------------------------------
227 :
228 0 : void ScSortParam::MoveToDest()
229 : {
230 0 : if (!bInplace)
231 : {
232 0 : SCsCOL nDifX = ((SCsCOL) nDestCol) - ((SCsCOL) nCol1);
233 0 : SCsROW nDifY = ((SCsROW) nDestRow) - ((SCsROW) nRow1);
234 :
235 0 : nCol1 = sal::static_int_cast<SCCOL>( nCol1 + nDifX );
236 0 : nRow1 = sal::static_int_cast<SCROW>( nRow1 + nDifY );
237 0 : nCol2 = sal::static_int_cast<SCCOL>( nCol2 + nDifX );
238 0 : nRow2 = sal::static_int_cast<SCROW>( nRow2 + nDifY );
239 0 : for (sal_uInt16 i=0; i<GetSortKeyCount(); i++)
240 0 : if (bByRow)
241 0 : maKeyState[i].nField += nDifX;
242 : else
243 0 : maKeyState[i].nField += nDifY;
244 :
245 0 : bInplace = true;
246 : }
247 : else
248 : {
249 : OSL_FAIL("MoveToDest, bInplace == TRUE");
250 : }
251 0 : }
252 :
253 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|