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 <tools/debug.hxx>
42 //------------------------------------------------------------------------
44 ScSortParam::ScSortParam()
49 //------------------------------------------------------------------------
51 ScSortParam::ScSortParam( const ScSortParam
& r
) :
52 nCol1(r
.nCol1
),nRow1(r
.nRow1
),nCol2(r
.nCol2
),nRow2(r
.nRow2
),
53 bHasHeader(r
.bHasHeader
),bByRow(r
.bByRow
),bCaseSens(r
.bCaseSens
),bNaturalSort(r
.bNaturalSort
),
54 bUserDef(r
.bUserDef
),nUserIndex(r
.nUserIndex
),bIncludePattern(r
.bIncludePattern
),
56 nDestTab(r
.nDestTab
),nDestCol(r
.nDestCol
),nDestRow(r
.nDestRow
),
57 aCollatorLocale( r
.aCollatorLocale
), aCollatorAlgorithm( r
.aCollatorAlgorithm
)
59 for (USHORT i
=0; i
<MAXSORT
; i
++)
61 bDoSort
[i
] = r
.bDoSort
[i
];
62 nField
[i
] = r
.nField
[i
];
63 bAscending
[i
] = r
.bAscending
[i
];
67 //------------------------------------------------------------------------
69 void ScSortParam::Clear()
71 nCol1
=nCol2
=nDestCol
= 0;
72 nRow1
=nRow2
=nDestRow
= 0;
76 bHasHeader
=bCaseSens
=bUserDef
=bNaturalSort
= FALSE
;
77 bByRow
=bIncludePattern
=bInplace
= TRUE
;
78 aCollatorLocale
= ::com::sun::star::lang::Locale();
79 aCollatorAlgorithm
.Erase();
81 for (USHORT i
=0; i
<MAXSORT
; i
++)
89 //------------------------------------------------------------------------
91 ScSortParam
& ScSortParam::operator=( const ScSortParam
& r
)
97 bHasHeader
= r
.bHasHeader
;
98 bCaseSens
= r
.bCaseSens
;
99 bNaturalSort
= r
.bNaturalSort
;
101 bUserDef
= r
.bUserDef
;
102 nUserIndex
= r
.nUserIndex
;
103 bIncludePattern
= r
.bIncludePattern
;
104 bInplace
= r
.bInplace
;
105 nDestTab
= r
.nDestTab
;
106 nDestCol
= r
.nDestCol
;
107 nDestRow
= r
.nDestRow
;
108 aCollatorLocale
= r
.aCollatorLocale
;
109 aCollatorAlgorithm
= r
.aCollatorAlgorithm
;
111 for (USHORT i
=0; i
<MAXSORT
; i
++)
113 bDoSort
[i
] = r
.bDoSort
[i
];
114 nField
[i
] = r
.nField
[i
];
115 bAscending
[i
] = r
.bAscending
[i
];
121 //------------------------------------------------------------------------
123 BOOL
ScSortParam::operator==( const ScSortParam
& rOther
) const
126 // Anzahl der Sorts gleich?
128 USHORT nOtherLast
= 0;
129 while ( bDoSort
[nLast
++] && nLast
< MAXSORT
) ;
130 while ( rOther
.bDoSort
[nOtherLast
++] && nOtherLast
< MAXSORT
) ;
133 if ( (nLast
== nOtherLast
)
134 && (nCol1
== rOther
.nCol1
)
135 && (nRow1
== rOther
.nRow1
)
136 && (nCol2
== rOther
.nCol2
)
137 && (nRow2
== rOther
.nRow2
)
138 && (bHasHeader
== rOther
.bHasHeader
)
139 && (bByRow
== rOther
.bByRow
)
140 && (bCaseSens
== rOther
.bCaseSens
)
141 && (bNaturalSort
== rOther
.bNaturalSort
)
142 && (bUserDef
== rOther
.bUserDef
)
143 && (nUserIndex
== rOther
.nUserIndex
)
144 && (bIncludePattern
== rOther
.bIncludePattern
)
145 && (bInplace
== rOther
.bInplace
)
146 && (nDestTab
== rOther
.nDestTab
)
147 && (nDestCol
== rOther
.nDestCol
)
148 && (nDestRow
== rOther
.nDestRow
)
149 && (aCollatorLocale
.Language
== rOther
.aCollatorLocale
.Language
)
150 && (aCollatorLocale
.Country
== rOther
.aCollatorLocale
.Country
)
151 && (aCollatorLocale
.Variant
== rOther
.aCollatorLocale
.Variant
)
152 && (aCollatorAlgorithm
== rOther
.aCollatorAlgorithm
)
156 for ( USHORT i
=0; i
<=nLast
&& bEqual
; i
++ )
158 bEqual
= (nField
[i
] == rOther
.nField
[i
]) && (bAscending
[i
] == rOther
.bAscending
[i
]);
164 //------------------------------------------------------------------------
166 ScSortParam::ScSortParam( const ScSubTotalParam
& rSub
, const ScSortParam
& rOld
) :
167 nCol1(rSub
.nCol1
),nRow1(rSub
.nRow1
),nCol2(rSub
.nCol2
),nRow2(rSub
.nRow2
),
168 bHasHeader(TRUE
),bByRow(TRUE
),bCaseSens(rSub
.bCaseSens
),
169 bUserDef(rSub
.bUserDef
),nUserIndex(rSub
.nUserIndex
),bIncludePattern(rSub
.bIncludePattern
),
171 nDestTab(0),nDestCol(0),nDestRow(0),
172 aCollatorLocale( rOld
.aCollatorLocale
), aCollatorAlgorithm( rOld
.aCollatorAlgorithm
)
174 USHORT nNewCount
= 0;
177 // zuerst die Gruppen aus den Teilergebnissen
179 for (i
=0; i
<MAXSUBTOTAL
; i
++)
180 if (rSub
.bGroupActive
[i
])
182 if (nNewCount
< MAXSORT
)
184 bDoSort
[nNewCount
] = TRUE
;
185 nField
[nNewCount
] = rSub
.nField
[i
];
186 bAscending
[nNewCount
] = rSub
.bAscending
;
191 // dann dahinter die alten Einstellungen
192 for (i
=0; i
<MAXSORT
; i
++)
195 SCCOLROW nThisField
= rOld
.nField
[i
];
196 BOOL bDouble
= FALSE
;
197 for (USHORT j
=0; j
<nNewCount
; j
++)
198 if ( nField
[j
] == nThisField
)
200 if (!bDouble
) // ein Feld nicht zweimal eintragen
202 if (nNewCount
< MAXSORT
)
204 bDoSort
[nNewCount
] = TRUE
;
205 nField
[nNewCount
] = nThisField
;
206 bAscending
[nNewCount
] = rOld
.bAscending
[i
];
212 for (i
=nNewCount
; i
<MAXSORT
; i
++) // Rest loeschen
216 bAscending
[i
] = TRUE
;
220 //------------------------------------------------------------------------
222 ScSortParam::ScSortParam( const ScQueryParam
& rParam
, SCCOL nCol
) :
223 nCol1(nCol
),nRow1(rParam
.nRow1
),nCol2(nCol
),nRow2(rParam
.nRow2
),
224 bHasHeader(rParam
.bHasHeader
),bByRow(TRUE
),bCaseSens(rParam
.bCaseSens
),
225 //! TODO: what about Locale and Algorithm?
226 bUserDef(FALSE
),nUserIndex(0),bIncludePattern(FALSE
),
228 nDestTab(0),nDestCol(0),nDestRow(0)
232 bAscending
[0] = TRUE
;
233 for (USHORT i
=1; i
<MAXSORT
; i
++)
237 bAscending
[i
] = TRUE
;
241 //------------------------------------------------------------------------
243 void ScSortParam::MoveToDest()
247 SCsCOL nDifX
= ((SCsCOL
) nDestCol
) - ((SCsCOL
) nCol1
);
248 SCsROW nDifY
= ((SCsROW
) nDestRow
) - ((SCsROW
) nRow1
);
250 nCol1
= sal::static_int_cast
<SCCOL
>( nCol1
+ nDifX
);
251 nRow1
= sal::static_int_cast
<SCROW
>( nRow1
+ nDifY
);
252 nCol2
= sal::static_int_cast
<SCCOL
>( nCol2
+ nDifX
);
253 nRow2
= sal::static_int_cast
<SCROW
>( nRow2
+ nDifY
);
254 for (USHORT i
=0; i
<MAXSORT
; i
++)
264 DBG_ERROR("MoveToDest, bInplace == TRUE");