1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26
27
28
29 #include "sortparam.hxx"
30 #include "global.hxx"
31 #include "address.hxx"
32 #include "queryparam.hxx"
33 #include <tools/debug.hxx>
34
35
36 //------------------------------------------------------------------------
37
ScSortParam()38 ScSortParam::ScSortParam()
39 {
40 Clear();
41 }
42
43 //------------------------------------------------------------------------
44
ScSortParam(const ScSortParam & r)45 ScSortParam::ScSortParam( const ScSortParam& r ) :
46 nCol1(r.nCol1),nRow1(r.nRow1),nCol2(r.nCol2),nRow2(r.nRow2),
47 bHasHeader(r.bHasHeader),bByRow(r.bByRow),bCaseSens(r.bCaseSens),
48 bUserDef(r.bUserDef),nUserIndex(r.nUserIndex),bIncludePattern(r.bIncludePattern),
49 bInplace(r.bInplace),
50 nDestTab(r.nDestTab),nDestCol(r.nDestCol),nDestRow(r.nDestRow),
51 aCollatorLocale( r.aCollatorLocale ), aCollatorAlgorithm( r.aCollatorAlgorithm )
52 {
53 for (sal_uInt16 i=0; i<MAXSORT; i++)
54 {
55 bDoSort[i] = r.bDoSort[i];
56 nField[i] = r.nField[i];
57 bAscending[i] = r.bAscending[i];
58 }
59 }
60
61 //------------------------------------------------------------------------
62
Clear()63 void ScSortParam::Clear()
64 {
65 nCol1=nCol2=nDestCol = 0;
66 nRow1=nRow2=nDestRow = 0;
67 nCompatHeader = 2;
68 nDestTab = 0;
69 nUserIndex = 0;
70 bHasHeader=bCaseSens=bUserDef = sal_False;
71 bByRow=bIncludePattern=bInplace = sal_True;
72 aCollatorLocale = ::com::sun::star::lang::Locale();
73 aCollatorAlgorithm.Erase();
74
75 for (sal_uInt16 i=0; i<MAXSORT; i++)
76 {
77 bDoSort[i] = sal_False;
78 nField[i] = 0;
79 bAscending[i] = sal_True;
80 }
81 }
82
83 //------------------------------------------------------------------------
84
operator =(const ScSortParam & r)85 ScSortParam& ScSortParam::operator=( const ScSortParam& r )
86 {
87 nCol1 = r.nCol1;
88 nRow1 = r.nRow1;
89 nCol2 = r.nCol2;
90 nRow2 = r.nRow2;
91 bHasHeader = r.bHasHeader;
92 bCaseSens = r.bCaseSens;
93 bByRow = r.bByRow;
94 bUserDef = r.bUserDef;
95 nUserIndex = r.nUserIndex;
96 bIncludePattern = r.bIncludePattern;
97 bInplace = r.bInplace;
98 nDestTab = r.nDestTab;
99 nDestCol = r.nDestCol;
100 nDestRow = r.nDestRow;
101 aCollatorLocale = r.aCollatorLocale;
102 aCollatorAlgorithm = r.aCollatorAlgorithm;
103
104 for (sal_uInt16 i=0; i<MAXSORT; i++)
105 {
106 bDoSort[i] = r.bDoSort[i];
107 nField[i] = r.nField[i];
108 bAscending[i] = r.bAscending[i];
109 }
110
111 return *this;
112 }
113
114 //------------------------------------------------------------------------
115
operator ==(const ScSortParam & rOther) const116 sal_Bool ScSortParam::operator==( const ScSortParam& rOther ) const
117 {
118 sal_Bool bEqual = sal_False;
119 // Anzahl der Sorts gleich?
120 sal_uInt16 nLast = 0;
121 sal_uInt16 nOtherLast = 0;
122 while ( bDoSort[nLast++] && nLast < MAXSORT ) ;
123 while ( rOther.bDoSort[nOtherLast++] && nOtherLast < MAXSORT ) ;
124 nLast--;
125 nOtherLast--;
126 if ( (nLast == nOtherLast)
127 && (nCol1 == rOther.nCol1)
128 && (nRow1 == rOther.nRow1)
129 && (nCol2 == rOther.nCol2)
130 && (nRow2 == rOther.nRow2)
131 && (bHasHeader == rOther.bHasHeader)
132 && (bByRow == rOther.bByRow)
133 && (bCaseSens == rOther.bCaseSens)
134 && (bUserDef == rOther.bUserDef)
135 && (nUserIndex == rOther.nUserIndex)
136 && (bIncludePattern == rOther.bIncludePattern)
137 && (bInplace == rOther.bInplace)
138 && (nDestTab == rOther.nDestTab)
139 && (nDestCol == rOther.nDestCol)
140 && (nDestRow == rOther.nDestRow)
141 && (aCollatorLocale.Language == rOther.aCollatorLocale.Language)
142 && (aCollatorLocale.Country == rOther.aCollatorLocale.Country)
143 && (aCollatorLocale.Variant == rOther.aCollatorLocale.Variant)
144 && (aCollatorAlgorithm == rOther.aCollatorAlgorithm)
145 )
146 {
147 bEqual = sal_True;
148 for ( sal_uInt16 i=0; i<=nLast && bEqual; i++ )
149 {
150 bEqual = (nField[i] == rOther.nField[i]) && (bAscending[i] == rOther.bAscending[i]);
151 }
152 }
153 return bEqual;
154 }
155
156 //------------------------------------------------------------------------
157
ScSortParam(const ScSubTotalParam & rSub,const ScSortParam & rOld)158 ScSortParam::ScSortParam( const ScSubTotalParam& rSub, const ScSortParam& rOld ) :
159 nCol1(rSub.nCol1),nRow1(rSub.nRow1),nCol2(rSub.nCol2),nRow2(rSub.nRow2),
160 bHasHeader(sal_True),bByRow(sal_True),bCaseSens(rSub.bCaseSens),
161 bUserDef(rSub.bUserDef),nUserIndex(rSub.nUserIndex),bIncludePattern(rSub.bIncludePattern),
162 bInplace(sal_True),
163 nDestTab(0),nDestCol(0),nDestRow(0),
164 aCollatorLocale( rOld.aCollatorLocale ), aCollatorAlgorithm( rOld.aCollatorAlgorithm )
165 {
166 sal_uInt16 nNewCount = 0;
167 sal_uInt16 i;
168
169 // zuerst die Gruppen aus den Teilergebnissen
170 if (rSub.bDoSort)
171 for (i=0; i<MAXSUBTOTAL; i++)
172 if (rSub.bGroupActive[i])
173 {
174 if (nNewCount < MAXSORT)
175 {
176 bDoSort[nNewCount] = sal_True;
177 nField[nNewCount] = rSub.nField[i];
178 bAscending[nNewCount] = rSub.bAscending;
179 ++nNewCount;
180 }
181 }
182
183 // dann dahinter die alten Einstellungen
184 for (i=0; i<MAXSORT; i++)
185 if (rOld.bDoSort[i])
186 {
187 SCCOLROW nThisField = rOld.nField[i];
188 sal_Bool bDouble = sal_False;
189 for (sal_uInt16 j=0; j<nNewCount; j++)
190 if ( nField[j] == nThisField )
191 bDouble = sal_True;
192 if (!bDouble) // ein Feld nicht zweimal eintragen
193 {
194 if (nNewCount < MAXSORT)
195 {
196 bDoSort[nNewCount] = sal_True;
197 nField[nNewCount] = nThisField;
198 bAscending[nNewCount] = rOld.bAscending[i];
199 ++nNewCount;
200 }
201 }
202 }
203
204 for (i=nNewCount; i<MAXSORT; i++) // Rest loeschen
205 {
206 bDoSort[i] = sal_False;
207 nField[i] = 0;
208 bAscending[i] = sal_True;
209 }
210 }
211
212 //------------------------------------------------------------------------
213
ScSortParam(const ScQueryParam & rParam,SCCOL nCol)214 ScSortParam::ScSortParam( const ScQueryParam& rParam, SCCOL nCol ) :
215 nCol1(nCol),nRow1(rParam.nRow1),nCol2(nCol),nRow2(rParam.nRow2),
216 bHasHeader(rParam.bHasHeader),bByRow(sal_True),bCaseSens(rParam.bCaseSens),
217 //! TODO: what about Locale and Algorithm?
218 bUserDef(sal_False),nUserIndex(0),bIncludePattern(sal_False),
219 bInplace(sal_True),
220 nDestTab(0),nDestCol(0),nDestRow(0)
221 {
222 bDoSort[0] = sal_True;
223 nField[0] = nCol;
224 bAscending[0] = sal_True;
225 for (sal_uInt16 i=1; i<MAXSORT; i++)
226 {
227 bDoSort[i] = sal_False;
228 nField[i] = 0;
229 bAscending[i] = sal_True;
230 }
231 }
232
233 //------------------------------------------------------------------------
234
MoveToDest()235 void ScSortParam::MoveToDest()
236 {
237 if (!bInplace)
238 {
239 SCsCOL nDifX = ((SCsCOL) nDestCol) - ((SCsCOL) nCol1);
240 SCsROW nDifY = ((SCsROW) nDestRow) - ((SCsROW) nRow1);
241
242 nCol1 = sal::static_int_cast<SCCOL>( nCol1 + nDifX );
243 nRow1 = sal::static_int_cast<SCROW>( nRow1 + nDifY );
244 nCol2 = sal::static_int_cast<SCCOL>( nCol2 + nDifX );
245 nRow2 = sal::static_int_cast<SCROW>( nRow2 + nDifY );
246 for (sal_uInt16 i=0; i<MAXSORT; i++)
247 if (bByRow)
248 nField[i] += nDifX;
249 else
250 nField[i] += nDifY;
251
252 bInplace = sal_True;
253 }
254 else
255 {
256 DBG_ERROR("MoveToDest, bInplace == TRUE");
257 }
258 }
259
260