fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / core / data / dpoutputgeometry.cxx
blobf0ec629fe21c59c5c72cb11acc10df635e0cb629
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
23 #include <vector>
25 using ::std::vector;
27 ScDPOutputGeometry::ScDPOutputGeometry(const ScRange& rOutRange, bool bShowFilter) :
28 maOutRange(rOutRange),
29 mnRowFields(0),
30 mnColumnFields(0),
31 mnPageFields(0),
32 mnDataFields(0),
33 meDataLayoutType(None),
34 mbShowFilter(bShowFilter)
38 ScDPOutputGeometry::~ScDPOutputGeometry()
42 void ScDPOutputGeometry::setRowFieldCount(sal_uInt32 nCount)
44 mnRowFields = 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;
73 if (!nColumnFields)
75 rAddrs.swap(aAddrs);
76 return;
79 SCROW nCurRow = maOutRange.aStart.Row();
81 if (mnPageFields)
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)
88 nCurRow += 2;
90 SCROW nRow = nCurRow;
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));
97 rAddrs.swap(aAddrs);
100 void ScDPOutputGeometry::getRowFieldPositions(vector<ScAddress>& rAddrs) const
102 sal_uInt32 nColumnFields, nRowFields;
103 adjustFieldsForDataLayout(nColumnFields, nRowFields);
105 vector<ScAddress> aAddrs;
106 if (!nRowFields)
108 rAddrs.swap(aAddrs);
109 return;
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));
119 rAddrs.swap(aAddrs);
122 void ScDPOutputGeometry::getPageFieldPositions(vector<ScAddress>& rAddrs) const
124 vector<ScAddress> aAddrs;
125 if (!mnPageFields)
127 rAddrs.swap(aAddrs);
128 return;
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));
139 rAddrs.swap(aAddrs);
142 SCROW ScDPOutputGeometry::getRowFieldHeaderRow() const
144 SCROW nCurRow = maOutRange.aStart.Row();
145 sal_uInt32 nColumnFields, nRowFields;
146 adjustFieldsForDataLayout(nColumnFields, nRowFields);
148 if (mnPageFields)
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)
155 nCurRow += 2;
157 if (nColumnFields)
158 nCurRow += static_cast<SCROW>(nColumnFields);
159 else if (nRowFields)
160 ++nCurRow;
162 return nCurRow;
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)
175 case Column:
176 if (rColumnFields > 0)
177 rColumnFields -= 1;
178 break;
179 case Row:
180 if (rRowFields > 0)
181 rRowFields -= 1;
182 default:
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);
195 if (mnPageFields)
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)
209 nCurRow += 2;
211 if (nColumnFields)
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);
224 else
225 ++nCurRow;
227 if (nRowFields)
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: */