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
),
35 mbHeaderLayout (false),
40 void ScDPOutputGeometry::setRowFieldCount(sal_uInt32 nCount
)
45 void ScDPOutputGeometry::setColumnFieldCount(sal_uInt32 nCount
)
47 mnColumnFields
= nCount
;
50 void ScDPOutputGeometry::setPageFieldCount(sal_uInt32 nCount
)
52 mnPageFields
= nCount
;
55 void ScDPOutputGeometry::setDataFieldCount(sal_uInt32 nCount
)
57 mnDataFields
= nCount
;
60 void ScDPOutputGeometry::setDataLayoutType(FieldType eType
)
62 meDataLayoutType
= eType
;
65 void ScDPOutputGeometry::setHeaderLayout(bool bHeaderLayout
)
67 mbHeaderLayout
= bHeaderLayout
;
70 void ScDPOutputGeometry::setCompactMode(bool bCompactMode
)
72 mbCompactMode
= bCompactMode
;
75 void ScDPOutputGeometry::getColumnFieldPositions(vector
<ScAddress
>& rAddrs
) const
77 sal_uInt32 nColumnFields
, nRowFields
;
78 adjustFieldsForDataLayout(nColumnFields
, nRowFields
);
80 vector
<ScAddress
> aAddrs
;
87 SCROW nCurRow
= maOutRange
.aStart
.Row();
91 SCROW nRowStart
= maOutRange
.aStart
.Row() + int(mbShowFilter
);
92 SCROW nRowEnd
= nRowStart
+ static_cast<SCCOL
>(mnPageFields
-1);
93 nCurRow
= nRowEnd
+ 2;
95 else if (mbShowFilter
)
99 SCTAB nTab
= maOutRange
.aStart
.Tab();
100 SCCOL nColStart
= static_cast<SCCOL
>(maOutRange
.aStart
.Col() + nRowFields
);
102 nColStart
= static_cast<SCCOL
>(maOutRange
.aStart
.Col() + 1); // We have only one row in compact mode
103 SCCOL nColEnd
= nColStart
+ static_cast<SCCOL
>(nColumnFields
-1);
105 for (SCCOL nCol
= nColStart
; nCol
<= nColEnd
; ++nCol
)
106 aAddrs
.emplace_back(nCol
, nRow
, nTab
);
110 void ScDPOutputGeometry::getRowFieldPositions(vector
<ScAddress
>& rAddrs
) const
112 sal_uInt32 nColumnFields
, nRowFields
;
113 adjustFieldsForDataLayout(nColumnFields
, nRowFields
);
115 vector
<ScAddress
> aAddrs
;
122 SCROW nRow
= getRowFieldHeaderRow();
123 SCTAB nTab
= maOutRange
.aStart
.Tab();
124 SCCOL nColStart
= maOutRange
.aStart
.Col();
125 SCCOL nColEnd
= nColStart
+ static_cast<SCCOL
>(nRowFields
-1);
128 nColEnd
= nColStart
; // We have only one row in compact mode
130 for (SCCOL nCol
= nColStart
; nCol
<= nColEnd
; ++nCol
)
131 aAddrs
.emplace_back(nCol
, nRow
, nTab
);
135 void ScDPOutputGeometry::getPageFieldPositions(vector
<ScAddress
>& rAddrs
) const
137 vector
<ScAddress
> aAddrs
;
144 SCTAB nTab
= maOutRange
.aStart
.Tab();
145 SCCOL nCol
= maOutRange
.aStart
.Col();
147 SCROW nRowStart
= maOutRange
.aStart
.Row() + int(mbShowFilter
);
148 SCROW nRowEnd
= nRowStart
+ static_cast<SCCOL
>(mnPageFields
-1);
150 for (SCROW nRow
= nRowStart
; nRow
<= nRowEnd
; ++nRow
)
151 aAddrs
.emplace_back(nCol
, nRow
, nTab
);
155 SCROW
ScDPOutputGeometry::getRowFieldHeaderRow() const
157 SCROW nCurRow
= maOutRange
.aStart
.Row();
158 sal_uInt32 nColumnFields
, nRowFields
;
159 adjustFieldsForDataLayout(nColumnFields
, nRowFields
);
163 SCROW nRowStart
= maOutRange
.aStart
.Row() + int(mbShowFilter
);
164 SCROW nRowEnd
= nRowStart
+ static_cast<SCCOL
>(mnPageFields
-1);
165 nCurRow
= nRowEnd
+ 2;
167 else if (mbShowFilter
)
171 nCurRow
+= static_cast<SCROW
>(nColumnFields
);
172 else if (nRowFields
&& mbHeaderLayout
)
178 void ScDPOutputGeometry::adjustFieldsForDataLayout(sal_uInt32
& rColumnFields
, sal_uInt32
& rRowFields
) const
180 rRowFields
= mnRowFields
;
181 rColumnFields
= mnColumnFields
;
183 if (mnDataFields
>= 2)
186 // Data layout field can be either row or column field, never page field.
187 switch (meDataLayoutType
)
190 if (rColumnFields
> 0)
202 std::pair
<ScDPOutputGeometry::FieldType
, size_t>
203 ScDPOutputGeometry::getFieldButtonType(const ScAddress
& rPos
) const
205 SCROW nCurRow
= maOutRange
.aStart
.Row();
206 sal_uInt32 nColumnFields
, nRowFields
;
207 adjustFieldsForDataLayout(nColumnFields
, nRowFields
);
211 SCCOL nCol
= maOutRange
.aStart
.Col();
212 SCROW nRowStart
= maOutRange
.aStart
.Row() + int(mbShowFilter
);
213 SCROW nRowEnd
= nRowStart
+ static_cast<SCCOL
>(mnPageFields
-1);
214 if (rPos
.Col() == nCol
&& nRowStart
<= rPos
.Row() && rPos
.Row() <= nRowEnd
)
216 size_t nPos
= static_cast<size_t>(rPos
.Row() - nRowStart
);
217 return std::pair
<FieldType
, size_t>(Page
, nPos
);
220 nCurRow
= nRowEnd
+ 2;
222 else if (mbShowFilter
)
227 SCROW nRow
= nCurRow
;
228 SCCOL nColStart
= static_cast<SCCOL
>(maOutRange
.aStart
.Col() + nRowFields
);
229 SCCOL nColEnd
= nColStart
+ static_cast<SCCOL
>(nColumnFields
-1);
230 if (rPos
.Row() == nRow
&& nColStart
<= rPos
.Col() && rPos
.Col() <= nColEnd
)
232 size_t nPos
= static_cast<size_t>(rPos
.Col() - nColStart
);
233 return std::pair
<FieldType
, size_t>(Column
, nPos
);
236 nCurRow
+= static_cast<SCROW
>(nColumnFields
);
238 else if (mbHeaderLayout
)
243 SCCOL nColStart
= maOutRange
.aStart
.Col();
244 SCCOL nColEnd
= nColStart
+ static_cast<SCCOL
>(nRowFields
-1);
245 if (rPos
.Row() == nCurRow
&& nColStart
<= rPos
.Col() && rPos
.Col() <= nColEnd
)
247 size_t nPos
= static_cast<size_t>(rPos
.Col() - nColStart
);
248 return std::pair
<FieldType
, size_t>(Row
, nPos
);
252 return std::pair
<FieldType
, size_t>(None
, 0);
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */