1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "sortparam.hxx"
22 #include "address.hxx"
23 #include "queryparam.hxx"
24 #include "subtotalparam.hxx"
27 //------------------------------------------------------------------------
29 ScSortParam::ScSortParam()
34 //------------------------------------------------------------------------
36 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 nCompatHeader( r
.nCompatHeader
)
48 ScSortParam::~ScSortParam() {}
50 //------------------------------------------------------------------------
52 void ScSortParam::Clear()
54 ScSortKeyState aKeyState
;
56 nCol1
=nCol2
=nDestCol
= 0;
57 nRow1
=nRow2
=nDestRow
= 0;
61 bHasHeader
=bCaseSens
=bUserDef
=bNaturalSort
= false;
62 bByRow
=bIncludePattern
=bInplace
= true;
63 aCollatorLocale
= ::com::sun::star::lang::Locale();
64 aCollatorAlgorithm
= OUString();
66 aKeyState
.bDoSort
= false;
68 aKeyState
.bAscending
= true;
70 // Initialize to default size
71 maKeyState
.assign( DEFSORT
, aKeyState
);
74 //------------------------------------------------------------------------
76 ScSortParam
& ScSortParam::operator=( const ScSortParam
& r
)
82 nUserIndex
= r
.nUserIndex
;
83 bHasHeader
= r
.bHasHeader
;
85 bCaseSens
= r
.bCaseSens
;
86 bNaturalSort
= r
.bNaturalSort
;
87 bUserDef
= r
.bUserDef
;
88 bIncludePattern
= r
.bIncludePattern
;
89 bInplace
= r
.bInplace
;
90 nDestTab
= r
.nDestTab
;
91 nDestCol
= r
.nDestCol
;
92 nDestRow
= r
.nDestRow
;
93 maKeyState
= r
.maKeyState
;
94 aCollatorLocale
= r
.aCollatorLocale
;
95 aCollatorAlgorithm
= r
.aCollatorAlgorithm
;
96 nCompatHeader
= r
.nCompatHeader
;
101 //------------------------------------------------------------------------
103 bool ScSortParam::operator==( const ScSortParam
& rOther
) const
106 // Anzahl der Sorts gleich?
107 sal_uInt16 nLast
= 0;
108 sal_uInt16 nOtherLast
= 0;
109 sal_uInt16 nSortSize
= GetSortKeyCount();
111 if ( !maKeyState
.empty() )
113 while ( maKeyState
[nLast
++].bDoSort
&& nLast
< nSortSize
) ;
117 if ( !rOther
.maKeyState
.empty() )
119 while ( rOther
.maKeyState
[nOtherLast
++].bDoSort
&& nOtherLast
< nSortSize
) ;
123 if ( (nLast
== nOtherLast
)
124 && (nCol1
== rOther
.nCol1
)
125 && (nRow1
== rOther
.nRow1
)
126 && (nCol2
== rOther
.nCol2
)
127 && (nRow2
== rOther
.nRow2
)
128 && (bHasHeader
== rOther
.bHasHeader
)
129 && (bByRow
== rOther
.bByRow
)
130 && (bCaseSens
== rOther
.bCaseSens
)
131 && (bNaturalSort
== rOther
.bNaturalSort
)
132 && (bUserDef
== rOther
.bUserDef
)
133 && (nUserIndex
== rOther
.nUserIndex
)
134 && (bIncludePattern
== rOther
.bIncludePattern
)
135 && (bInplace
== rOther
.bInplace
)
136 && (nDestTab
== rOther
.nDestTab
)
137 && (nDestCol
== rOther
.nDestCol
)
138 && (nDestRow
== rOther
.nDestRow
)
139 && (aCollatorLocale
.Language
== rOther
.aCollatorLocale
.Language
)
140 && (aCollatorLocale
.Country
== rOther
.aCollatorLocale
.Country
)
141 && (aCollatorLocale
.Variant
== rOther
.aCollatorLocale
.Variant
)
142 && (aCollatorAlgorithm
== rOther
.aCollatorAlgorithm
)
143 && ( !maKeyState
.empty() || !rOther
.maKeyState
.empty() )
147 for ( sal_uInt16 i
=0; i
<=nLast
&& bEqual
; i
++ )
148 bEqual
= ( maKeyState
[i
].nField
== rOther
.maKeyState
[i
].nField
) &&
149 ( maKeyState
[i
].bAscending
== rOther
.maKeyState
[i
].bAscending
);
151 if ( maKeyState
.empty() && rOther
.maKeyState
.empty() )
157 //------------------------------------------------------------------------
159 ScSortParam::ScSortParam( const ScSubTotalParam
& rSub
, const ScSortParam
& rOld
) :
160 nCol1(rSub
.nCol1
),nRow1(rSub
.nRow1
),nCol2(rSub
.nCol2
),nRow2(rSub
.nRow2
),nUserIndex(rSub
.nUserIndex
),
161 bHasHeader(true),bByRow(true),bCaseSens(rSub
.bCaseSens
),bNaturalSort(rOld
.bNaturalSort
),
162 bUserDef(rSub
.bUserDef
),bIncludePattern(rSub
.bIncludePattern
),
164 nDestTab(0),nDestCol(0),nDestRow(0),
165 aCollatorLocale( rOld
.aCollatorLocale
), aCollatorAlgorithm( rOld
.aCollatorAlgorithm
),
166 nCompatHeader( rOld
.nCompatHeader
)
170 // zuerst die Gruppen aus den Teilergebnissen
172 for (i
=0; i
<MAXSUBTOTAL
; i
++)
173 if (rSub
.bGroupActive
[i
])
177 key
.nField
= rSub
.nField
[i
];
178 key
.bAscending
= rSub
.bAscending
;
179 maKeyState
.push_back(key
);
182 // dann dahinter die alten Einstellungen
183 for (i
=0; i
< rOld
.GetSortKeyCount(); i
++)
184 if (rOld
.maKeyState
[i
].bDoSort
)
186 SCCOLROW nThisField
= rOld
.maKeyState
[i
].nField
;
187 bool bDouble
= false;
188 for (sal_uInt16 j
= 0; j
< GetSortKeyCount(); j
++)
189 if ( maKeyState
[j
].nField
== nThisField
)
191 if (!bDouble
) // ein Feld nicht zweimal eintragen
195 key
.nField
= nThisField
;
196 key
.bAscending
= rOld
.maKeyState
[i
].bAscending
;
197 maKeyState
.push_back(key
);
202 //------------------------------------------------------------------------
204 ScSortParam::ScSortParam( const ScQueryParam
& rParam
, SCCOL nCol
) :
205 nCol1(nCol
),nRow1(rParam
.nRow1
),nCol2(nCol
),nRow2(rParam
.nRow2
),nUserIndex(0),
206 bHasHeader(rParam
.bHasHeader
),bByRow(true),bCaseSens(rParam
.bCaseSens
),
208 //! TODO: what about Locale and Algorithm?
209 bUserDef(false),bIncludePattern(false),
211 nDestTab(0),nDestCol(0),nDestRow(0), nCompatHeader(2)
213 ScSortKeyState aKeyState
;
214 aKeyState
.bDoSort
= true;
215 aKeyState
.nField
= nCol
;
216 aKeyState
.bAscending
= true;
218 maKeyState
.push_back( aKeyState
);
221 aKeyState
.bDoSort
= false;
222 aKeyState
.nField
= 0;
224 for (sal_uInt16 i
=1; i
<GetSortKeyCount(); i
++)
225 maKeyState
.push_back( aKeyState
);
228 //------------------------------------------------------------------------
230 void ScSortParam::MoveToDest()
234 SCsCOL nDifX
= ((SCsCOL
) nDestCol
) - ((SCsCOL
) nCol1
);
235 SCsROW nDifY
= ((SCsROW
) nDestRow
) - ((SCsROW
) nRow1
);
237 nCol1
= sal::static_int_cast
<SCCOL
>( nCol1
+ nDifX
);
238 nRow1
= sal::static_int_cast
<SCROW
>( nRow1
+ nDifY
);
239 nCol2
= sal::static_int_cast
<SCCOL
>( nCol2
+ nDifX
);
240 nRow2
= sal::static_int_cast
<SCROW
>( nRow2
+ nDifY
);
241 for (sal_uInt16 i
=0; i
<GetSortKeyCount(); i
++)
243 maKeyState
[i
].nField
+= nDifX
;
245 maKeyState
[i
].nField
+= nDifY
;
251 OSL_FAIL("MoveToDest, bInplace == TRUE");
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */