Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / sc / source / core / data / dpoutputgeometry.cxx
blob0c5307258c9b89002b9504ea970efd4d0dfb5f2d
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),
35 mbHeaderLayout (false),
36 mbCompactMode (false)
40 void ScDPOutputGeometry::setRowFieldCount(sal_uInt32 nCount)
42 mnRowFields = 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;
81 if (!nColumnFields)
83 rAddrs.swap(aAddrs);
84 return;
87 SCROW nCurRow = maOutRange.aStart.Row();
89 if (mnPageFields)
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)
96 nCurRow += 2;
98 SCROW nRow = nCurRow;
99 SCTAB nTab = maOutRange.aStart.Tab();
100 SCCOL nColStart = static_cast<SCCOL>(maOutRange.aStart.Col() + nRowFields);
101 if(mbCompactMode)
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);
107 rAddrs.swap(aAddrs);
110 void ScDPOutputGeometry::getRowFieldPositions(vector<ScAddress>& rAddrs) const
112 sal_uInt32 nColumnFields, nRowFields;
113 adjustFieldsForDataLayout(nColumnFields, nRowFields);
115 vector<ScAddress> aAddrs;
116 if (!nRowFields)
118 rAddrs.swap(aAddrs);
119 return;
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);
127 if(mbCompactMode)
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);
132 rAddrs.swap(aAddrs);
135 void ScDPOutputGeometry::getPageFieldPositions(vector<ScAddress>& rAddrs) const
137 vector<ScAddress> aAddrs;
138 if (!mnPageFields)
140 rAddrs.swap(aAddrs);
141 return;
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);
152 rAddrs.swap(aAddrs);
155 SCROW ScDPOutputGeometry::getRowFieldHeaderRow() const
157 SCROW nCurRow = maOutRange.aStart.Row();
158 sal_uInt32 nColumnFields, nRowFields;
159 adjustFieldsForDataLayout(nColumnFields, nRowFields);
161 if (mnPageFields)
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)
168 nCurRow += 2;
170 if (nColumnFields)
171 nCurRow += static_cast<SCROW>(nColumnFields);
172 else if (nRowFields && mbHeaderLayout)
173 ++nCurRow;
175 return nCurRow;
178 void ScDPOutputGeometry::adjustFieldsForDataLayout(sal_uInt32& rColumnFields, sal_uInt32& rRowFields) const
180 rRowFields = mnRowFields;
181 rColumnFields = mnColumnFields;
183 if (mnDataFields >= 2)
184 return;
186 // Data layout field can be either row or column field, never page field.
187 switch (meDataLayoutType)
189 case Column:
190 if (rColumnFields > 0)
191 rColumnFields -= 1;
192 break;
193 case Row:
194 if (rRowFields > 0)
195 rRowFields -= 1;
196 break;
197 default:
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);
209 if (mnPageFields)
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)
223 nCurRow += 2;
225 if (nColumnFields)
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)
239 ++nCurRow;
241 if (nRowFields)
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: */