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 "dpoutputgeometry.hxx"
21 #include "address.hxx"
27 ScDPOutputGeometry::ScDPOutputGeometry(const ScRange
& rOutRange
, bool bShowFilter
) :
28 maOutRange(rOutRange
),
33 meDataLayoutType(None
),
34 mbShowFilter(bShowFilter
)
38 ScDPOutputGeometry::~ScDPOutputGeometry()
42 void ScDPOutputGeometry::setRowFieldCount(sal_uInt32 nCount
)
47 void ScDPOutputGeometry::setColumnFieldCount(sal_uInt32 nCount
)
49 mnColumnFields
= nCount
;
52 void ScDPOutputGeometry::setPageFieldCount(sal_uInt32 nCount
)
54 mnPageFields
= nCount
;
57 void ScDPOutputGeometry::setDataFieldCount(sal_uInt32 nCount
)
59 mnDataFields
= nCount
;
62 void ScDPOutputGeometry::setDataLayoutType(FieldType eType
)
64 meDataLayoutType
= eType
;
67 void ScDPOutputGeometry::getColumnFieldPositions(vector
<ScAddress
>& rAddrs
) const
69 sal_uInt32 nColumnFields
, nRowFields
;
70 adjustFieldsForDataLayout(nColumnFields
, nRowFields
);
72 vector
<ScAddress
> aAddrs
;
79 SCROW nCurRow
= maOutRange
.aStart
.Row();
83 SCROW nRowStart
= maOutRange
.aStart
.Row() + int(mbShowFilter
);
84 SCROW nRowEnd
= nRowStart
+ static_cast<SCCOL
>(mnPageFields
-1);
85 nCurRow
= nRowEnd
+ 2;
87 else if (mbShowFilter
)
91 SCTAB nTab
= maOutRange
.aStart
.Tab();
92 SCCOL nColStart
= static_cast<SCCOL
>(maOutRange
.aStart
.Col() + nRowFields
);
93 SCCOL nColEnd
= nColStart
+ static_cast<SCCOL
>(nColumnFields
-1);
95 for (SCCOL nCol
= nColStart
; nCol
<= nColEnd
; ++nCol
)
96 aAddrs
.push_back(ScAddress(nCol
, nRow
, nTab
));
100 void ScDPOutputGeometry::getRowFieldPositions(vector
<ScAddress
>& rAddrs
) const
102 sal_uInt32 nColumnFields
, nRowFields
;
103 adjustFieldsForDataLayout(nColumnFields
, nRowFields
);
105 vector
<ScAddress
> aAddrs
;
112 SCROW nRow
= getRowFieldHeaderRow();
113 SCTAB nTab
= maOutRange
.aStart
.Tab();
114 SCCOL nColStart
= maOutRange
.aStart
.Col();
115 SCCOL nColEnd
= nColStart
+ static_cast<SCCOL
>(nRowFields
-1);
117 for (SCCOL nCol
= nColStart
; nCol
<= nColEnd
; ++nCol
)
118 aAddrs
.push_back(ScAddress(nCol
, nRow
, nTab
));
122 void ScDPOutputGeometry::getPageFieldPositions(vector
<ScAddress
>& rAddrs
) const
124 vector
<ScAddress
> aAddrs
;
131 SCTAB nTab
= maOutRange
.aStart
.Tab();
132 SCCOL nCol
= maOutRange
.aStart
.Col();
134 SCROW nRowStart
= maOutRange
.aStart
.Row() + int(mbShowFilter
);
135 SCROW nRowEnd
= nRowStart
+ static_cast<SCCOL
>(mnPageFields
-1);
137 for (SCROW nRow
= nRowStart
; nRow
<= nRowEnd
; ++nRow
)
138 aAddrs
.push_back(ScAddress(nCol
, nRow
, nTab
));
142 SCROW
ScDPOutputGeometry::getRowFieldHeaderRow() const
144 SCROW nCurRow
= maOutRange
.aStart
.Row();
145 sal_uInt32 nColumnFields
, nRowFields
;
146 adjustFieldsForDataLayout(nColumnFields
, nRowFields
);
150 SCROW nRowStart
= maOutRange
.aStart
.Row() + int(mbShowFilter
);
151 SCROW nRowEnd
= nRowStart
+ static_cast<SCCOL
>(mnPageFields
-1);
152 nCurRow
= nRowEnd
+ 2;
154 else if (mbShowFilter
)
158 nCurRow
+= static_cast<SCROW
>(nColumnFields
);
165 void ScDPOutputGeometry::adjustFieldsForDataLayout(sal_uInt32
& rColumnFields
, sal_uInt32
& rRowFields
) const
167 rRowFields
= mnRowFields
;
168 rColumnFields
= mnColumnFields
;
170 if (mnDataFields
< 2)
172 // Data layout field can be either row or column field, never page field.
173 switch (meDataLayoutType
)
176 if (rColumnFields
> 0)
188 std::pair
<ScDPOutputGeometry::FieldType
, size_t>
189 ScDPOutputGeometry::getFieldButtonType(const ScAddress
& rPos
) const
191 SCROW nCurRow
= maOutRange
.aStart
.Row();
192 sal_uInt32 nColumnFields
, nRowFields
;
193 adjustFieldsForDataLayout(nColumnFields
, nRowFields
);
197 SCCOL nCol
= maOutRange
.aStart
.Col();
198 SCROW nRowStart
= maOutRange
.aStart
.Row() + int(mbShowFilter
);
199 SCROW nRowEnd
= nRowStart
+ static_cast<SCCOL
>(mnPageFields
-1);
200 if (rPos
.Col() == nCol
&& nRowStart
<= rPos
.Row() && rPos
.Row() <= nRowEnd
)
202 size_t nPos
= static_cast<size_t>(rPos
.Row() - nRowStart
);
203 return std::pair
<FieldType
, size_t>(Page
, nPos
);
206 nCurRow
= nRowEnd
+ 2;
208 else if (mbShowFilter
)
213 SCROW nRow
= nCurRow
;
214 SCCOL nColStart
= static_cast<SCCOL
>(maOutRange
.aStart
.Col() + nRowFields
);
215 SCCOL nColEnd
= nColStart
+ static_cast<SCCOL
>(nColumnFields
-1);
216 if (rPos
.Row() == nRow
&& nColStart
<= rPos
.Col() && rPos
.Col() <= nColEnd
)
218 size_t nPos
= static_cast<size_t>(rPos
.Col() - nColStart
);
219 return std::pair
<FieldType
, size_t>(Column
, nPos
);
222 nCurRow
+= static_cast<SCROW
>(nColumnFields
);
229 SCCOL nColStart
= maOutRange
.aStart
.Col();
230 SCCOL nColEnd
= nColStart
+ static_cast<SCCOL
>(nRowFields
-1);
231 if (rPos
.Row() == nCurRow
&& nColStart
<= rPos
.Col() && rPos
.Col() <= nColEnd
)
233 size_t nPos
= static_cast<size_t>(rPos
.Col() - nColStart
);
234 return std::pair
<FieldType
, size_t>(Row
, nPos
);
238 return std::pair
<FieldType
, size_t>(None
, 0);
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */