merge the formfield patch from ooo-build
[ooovba.git] / sc / source / core / data / sortparam.cxx
blob332772e1e7c4226ba1a78918277e38049f75d4f6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sortparam.cxx,v $
10 * $Revision: 1.8.146.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 #include "sortparam.hxx"
37 #include "global.hxx"
38 #include "address.hxx"
39 #include "queryparam.hxx"
40 #include <tools/debug.hxx>
43 //------------------------------------------------------------------------
45 ScSortParam::ScSortParam()
47 Clear();
50 //------------------------------------------------------------------------
52 ScSortParam::ScSortParam( const ScSortParam& r ) :
53 nCol1(r.nCol1),nRow1(r.nRow1),nCol2(r.nCol2),nRow2(r.nRow2),
54 bHasHeader(r.bHasHeader),bByRow(r.bByRow),bCaseSens(r.bCaseSens),bNaturalSort(r.bNaturalSort),
55 bUserDef(r.bUserDef),nUserIndex(r.nUserIndex),bIncludePattern(r.bIncludePattern),
56 bInplace(r.bInplace),
57 nDestTab(r.nDestTab),nDestCol(r.nDestCol),nDestRow(r.nDestRow),
58 aCollatorLocale( r.aCollatorLocale ), aCollatorAlgorithm( r.aCollatorAlgorithm )
60 for (USHORT i=0; i<MAXSORT; i++)
62 bDoSort[i] = r.bDoSort[i];
63 nField[i] = r.nField[i];
64 bAscending[i] = r.bAscending[i];
68 //------------------------------------------------------------------------
70 void ScSortParam::Clear()
72 nCol1=nCol2=nDestCol = 0;
73 nRow1=nRow2=nDestRow = 0;
74 nCompatHeader = 2;
75 nDestTab = 0;
76 nUserIndex = 0;
77 bHasHeader=bCaseSens=bUserDef=bNaturalSort = FALSE;
78 bByRow=bIncludePattern=bInplace = TRUE;
79 aCollatorLocale = ::com::sun::star::lang::Locale();
80 aCollatorAlgorithm.Erase();
82 for (USHORT i=0; i<MAXSORT; i++)
84 bDoSort[i] = FALSE;
85 nField[i] = 0;
86 bAscending[i] = TRUE;
90 //------------------------------------------------------------------------
92 ScSortParam& ScSortParam::operator=( const ScSortParam& r )
94 nCol1 = r.nCol1;
95 nRow1 = r.nRow1;
96 nCol2 = r.nCol2;
97 nRow2 = r.nRow2;
98 bHasHeader = r.bHasHeader;
99 bCaseSens = r.bCaseSens;
100 bNaturalSort = r.bNaturalSort;
101 bByRow = r.bByRow;
102 bUserDef = r.bUserDef;
103 nUserIndex = r.nUserIndex;
104 bIncludePattern = r.bIncludePattern;
105 bInplace = r.bInplace;
106 nDestTab = r.nDestTab;
107 nDestCol = r.nDestCol;
108 nDestRow = r.nDestRow;
109 aCollatorLocale = r.aCollatorLocale;
110 aCollatorAlgorithm = r.aCollatorAlgorithm;
112 for (USHORT i=0; i<MAXSORT; i++)
114 bDoSort[i] = r.bDoSort[i];
115 nField[i] = r.nField[i];
116 bAscending[i] = r.bAscending[i];
119 return *this;
122 //------------------------------------------------------------------------
124 BOOL ScSortParam::operator==( const ScSortParam& rOther ) const
126 BOOL bEqual = FALSE;
127 // Anzahl der Sorts gleich?
128 USHORT nLast = 0;
129 USHORT nOtherLast = 0;
130 while ( bDoSort[nLast++] && nLast < MAXSORT ) ;
131 while ( rOther.bDoSort[nOtherLast++] && nOtherLast < MAXSORT ) ;
132 nLast--;
133 nOtherLast--;
134 if ( (nLast == nOtherLast)
135 && (nCol1 == rOther.nCol1)
136 && (nRow1 == rOther.nRow1)
137 && (nCol2 == rOther.nCol2)
138 && (nRow2 == rOther.nRow2)
139 && (bHasHeader == rOther.bHasHeader)
140 && (bByRow == rOther.bByRow)
141 && (bCaseSens == rOther.bCaseSens)
142 && (bNaturalSort == rOther.bNaturalSort)
143 && (bUserDef == rOther.bUserDef)
144 && (nUserIndex == rOther.nUserIndex)
145 && (bIncludePattern == rOther.bIncludePattern)
146 && (bInplace == rOther.bInplace)
147 && (nDestTab == rOther.nDestTab)
148 && (nDestCol == rOther.nDestCol)
149 && (nDestRow == rOther.nDestRow)
150 && (aCollatorLocale.Language == rOther.aCollatorLocale.Language)
151 && (aCollatorLocale.Country == rOther.aCollatorLocale.Country)
152 && (aCollatorLocale.Variant == rOther.aCollatorLocale.Variant)
153 && (aCollatorAlgorithm == rOther.aCollatorAlgorithm)
156 bEqual = TRUE;
157 for ( USHORT i=0; i<=nLast && bEqual; i++ )
159 bEqual = (nField[i] == rOther.nField[i]) && (bAscending[i] == rOther.bAscending[i]);
162 return bEqual;
165 //------------------------------------------------------------------------
167 ScSortParam::ScSortParam( const ScSubTotalParam& rSub, const ScSortParam& rOld ) :
168 nCol1(rSub.nCol1),nRow1(rSub.nRow1),nCol2(rSub.nCol2),nRow2(rSub.nRow2),
169 bHasHeader(TRUE),bByRow(TRUE),bCaseSens(rSub.bCaseSens),
170 bUserDef(rSub.bUserDef),nUserIndex(rSub.nUserIndex),bIncludePattern(rSub.bIncludePattern),
171 bInplace(TRUE),
172 nDestTab(0),nDestCol(0),nDestRow(0),
173 aCollatorLocale( rOld.aCollatorLocale ), aCollatorAlgorithm( rOld.aCollatorAlgorithm )
175 USHORT nNewCount = 0;
176 USHORT i;
178 // zuerst die Gruppen aus den Teilergebnissen
179 if (rSub.bDoSort)
180 for (i=0; i<MAXSUBTOTAL; i++)
181 if (rSub.bGroupActive[i])
183 if (nNewCount < MAXSORT)
185 bDoSort[nNewCount] = TRUE;
186 nField[nNewCount] = rSub.nField[i];
187 bAscending[nNewCount] = rSub.bAscending;
188 ++nNewCount;
192 // dann dahinter die alten Einstellungen
193 for (i=0; i<MAXSORT; i++)
194 if (rOld.bDoSort[i])
196 SCCOLROW nThisField = rOld.nField[i];
197 BOOL bDouble = FALSE;
198 for (USHORT j=0; j<nNewCount; j++)
199 if ( nField[j] == nThisField )
200 bDouble = TRUE;
201 if (!bDouble) // ein Feld nicht zweimal eintragen
203 if (nNewCount < MAXSORT)
205 bDoSort[nNewCount] = TRUE;
206 nField[nNewCount] = nThisField;
207 bAscending[nNewCount] = rOld.bAscending[i];
208 ++nNewCount;
213 for (i=nNewCount; i<MAXSORT; i++) // Rest loeschen
215 bDoSort[i] = FALSE;
216 nField[i] = 0;
217 bAscending[i] = TRUE;
221 //------------------------------------------------------------------------
223 ScSortParam::ScSortParam( const ScQueryParam& rParam, SCCOL nCol ) :
224 nCol1(nCol),nRow1(rParam.nRow1),nCol2(nCol),nRow2(rParam.nRow2),
225 bHasHeader(rParam.bHasHeader),bByRow(TRUE),bCaseSens(rParam.bCaseSens),
226 //! TODO: what about Locale and Algorithm?
227 bUserDef(FALSE),nUserIndex(0),bIncludePattern(FALSE),
228 bInplace(TRUE),
229 nDestTab(0),nDestCol(0),nDestRow(0)
231 bDoSort[0] = TRUE;
232 nField[0] = nCol;
233 bAscending[0] = TRUE;
234 for (USHORT i=1; i<MAXSORT; i++)
236 bDoSort[i] = FALSE;
237 nField[i] = 0;
238 bAscending[i] = TRUE;
242 //------------------------------------------------------------------------
244 void ScSortParam::MoveToDest()
246 if (!bInplace)
248 SCsCOL nDifX = ((SCsCOL) nDestCol) - ((SCsCOL) nCol1);
249 SCsROW nDifY = ((SCsROW) nDestRow) - ((SCsROW) nRow1);
251 nCol1 = sal::static_int_cast<SCCOL>( nCol1 + nDifX );
252 nRow1 = sal::static_int_cast<SCROW>( nRow1 + nDifY );
253 nCol2 = sal::static_int_cast<SCCOL>( nCol2 + nDifX );
254 nRow2 = sal::static_int_cast<SCROW>( nRow2 + nDifY );
255 for (USHORT i=0; i<MAXSORT; i++)
256 if (bByRow)
257 nField[i] += nDifX;
258 else
259 nField[i] += nDifY;
261 bInplace = TRUE;
263 else
265 DBG_ERROR("MoveToDest, bInplace == TRUE");