1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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"
38 #include "address.hxx"
39 #include "queryparam.hxx"
40 #include <tools/debug.hxx>
43 //------------------------------------------------------------------------
45 ScSortParam::ScSortParam()
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
),
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;
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
++)
90 //------------------------------------------------------------------------
92 ScSortParam
& ScSortParam::operator=( const ScSortParam
& r
)
98 bHasHeader
= r
.bHasHeader
;
99 bCaseSens
= r
.bCaseSens
;
100 bNaturalSort
= r
.bNaturalSort
;
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
];
122 //------------------------------------------------------------------------
124 BOOL
ScSortParam::operator==( const ScSortParam
& rOther
) const
127 // Anzahl der Sorts gleich?
129 USHORT nOtherLast
= 0;
130 while ( bDoSort
[nLast
++] && nLast
< MAXSORT
) ;
131 while ( rOther
.bDoSort
[nOtherLast
++] && nOtherLast
< MAXSORT
) ;
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
)
157 for ( USHORT i
=0; i
<=nLast
&& bEqual
; i
++ )
159 bEqual
= (nField
[i
] == rOther
.nField
[i
]) && (bAscending
[i
] == rOther
.bAscending
[i
]);
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
),
172 nDestTab(0),nDestCol(0),nDestRow(0),
173 aCollatorLocale( rOld
.aCollatorLocale
), aCollatorAlgorithm( rOld
.aCollatorAlgorithm
)
175 USHORT nNewCount
= 0;
178 // zuerst die Gruppen aus den Teilergebnissen
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
;
192 // dann dahinter die alten Einstellungen
193 for (i
=0; i
<MAXSORT
; i
++)
196 SCCOLROW nThisField
= rOld
.nField
[i
];
197 BOOL bDouble
= FALSE
;
198 for (USHORT j
=0; j
<nNewCount
; j
++)
199 if ( nField
[j
] == nThisField
)
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
];
213 for (i
=nNewCount
; i
<MAXSORT
; i
++) // Rest loeschen
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
),
229 nDestTab(0),nDestCol(0),nDestRow(0)
233 bAscending
[0] = TRUE
;
234 for (USHORT i
=1; i
<MAXSORT
; i
++)
238 bAscending
[i
] = TRUE
;
242 //------------------------------------------------------------------------
244 void ScSortParam::MoveToDest()
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
++)
265 DBG_ERROR("MoveToDest, bInplace == TRUE");