Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "dpoutputgeometry.hxx"
21 : #include "address.hxx"
22 :
23 : #include <vector>
24 :
25 : using ::std::vector;
26 :
27 1 : 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 1 : mbShowFilter(bShowFilter)
35 : {
36 1 : }
37 :
38 1 : ScDPOutputGeometry::~ScDPOutputGeometry()
39 : {
40 1 : }
41 :
42 1 : void ScDPOutputGeometry::setRowFieldCount(sal_uInt32 nCount)
43 : {
44 1 : mnRowFields = nCount;
45 1 : }
46 :
47 1 : void ScDPOutputGeometry::setColumnFieldCount(sal_uInt32 nCount)
48 : {
49 1 : mnColumnFields = nCount;
50 1 : }
51 :
52 1 : void ScDPOutputGeometry::setPageFieldCount(sal_uInt32 nCount)
53 : {
54 1 : mnPageFields = nCount;
55 1 : }
56 :
57 1 : void ScDPOutputGeometry::setDataFieldCount(sal_uInt32 nCount)
58 : {
59 1 : mnDataFields = nCount;
60 1 : }
61 :
62 1 : void ScDPOutputGeometry::setDataLayoutType(FieldType eType)
63 : {
64 1 : meDataLayoutType = eType;
65 1 : }
66 :
67 0 : void ScDPOutputGeometry::getColumnFieldPositions(vector<ScAddress>& rAddrs) const
68 : {
69 : sal_uInt32 nColumnFields, nRowFields;
70 0 : adjustFieldsForDataLayout(nColumnFields, nRowFields);
71 :
72 0 : vector<ScAddress> aAddrs;
73 0 : if (!nColumnFields)
74 : {
75 0 : rAddrs.swap(aAddrs);
76 0 : return;
77 : }
78 :
79 0 : SCROW nCurRow = maOutRange.aStart.Row();
80 :
81 0 : if (mnPageFields)
82 : {
83 0 : SCROW nRowStart = maOutRange.aStart.Row() + mbShowFilter;
84 0 : SCROW nRowEnd = nRowStart + static_cast<SCCOL>(mnPageFields-1);
85 0 : nCurRow = nRowEnd + 2;
86 : }
87 0 : else if (mbShowFilter)
88 0 : nCurRow += 2;
89 :
90 0 : SCROW nRow = nCurRow;
91 0 : SCTAB nTab = maOutRange.aStart.Tab();
92 0 : SCCOL nColStart = static_cast<SCCOL>(maOutRange.aStart.Col() + nRowFields);
93 0 : SCCOL nColEnd = nColStart + static_cast<SCCOL>(nColumnFields-1);
94 :
95 0 : for (SCCOL nCol = nColStart; nCol <= nColEnd; ++nCol)
96 0 : aAddrs.push_back(ScAddress(nCol, nRow, nTab));
97 0 : rAddrs.swap(aAddrs);
98 : }
99 :
100 0 : void ScDPOutputGeometry::getRowFieldPositions(vector<ScAddress>& rAddrs) const
101 : {
102 : sal_uInt32 nColumnFields, nRowFields;
103 0 : adjustFieldsForDataLayout(nColumnFields, nRowFields);
104 :
105 0 : vector<ScAddress> aAddrs;
106 0 : if (!nRowFields)
107 : {
108 0 : rAddrs.swap(aAddrs);
109 0 : return;
110 : }
111 :
112 0 : SCROW nRow = getRowFieldHeaderRow();
113 0 : SCTAB nTab = maOutRange.aStart.Tab();
114 0 : SCCOL nColStart = maOutRange.aStart.Col();
115 0 : SCCOL nColEnd = nColStart + static_cast<SCCOL>(nRowFields-1);
116 :
117 0 : for (SCCOL nCol = nColStart; nCol <= nColEnd; ++nCol)
118 0 : aAddrs.push_back(ScAddress(nCol, nRow, nTab));
119 0 : rAddrs.swap(aAddrs);
120 : }
121 :
122 0 : void ScDPOutputGeometry::getPageFieldPositions(vector<ScAddress>& rAddrs) const
123 : {
124 0 : vector<ScAddress> aAddrs;
125 0 : if (!mnPageFields)
126 : {
127 0 : rAddrs.swap(aAddrs);
128 0 : return;
129 : }
130 :
131 0 : SCTAB nTab = maOutRange.aStart.Tab();
132 0 : SCCOL nCol = maOutRange.aStart.Col();
133 :
134 0 : SCROW nRowStart = maOutRange.aStart.Row() + mbShowFilter;
135 0 : SCROW nRowEnd = nRowStart + static_cast<SCCOL>(mnPageFields-1);
136 :
137 0 : for (SCROW nRow = nRowStart; nRow <= nRowEnd; ++nRow)
138 0 : aAddrs.push_back(ScAddress(nCol, nRow, nTab));
139 0 : rAddrs.swap(aAddrs);
140 : }
141 :
142 0 : SCROW ScDPOutputGeometry::getRowFieldHeaderRow() const
143 : {
144 0 : SCROW nCurRow = maOutRange.aStart.Row();
145 : sal_uInt32 nColumnFields, nRowFields;
146 0 : adjustFieldsForDataLayout(nColumnFields, nRowFields);
147 :
148 0 : if (mnPageFields)
149 : {
150 0 : SCROW nRowStart = maOutRange.aStart.Row() + mbShowFilter;
151 0 : SCROW nRowEnd = nRowStart + static_cast<SCCOL>(mnPageFields-1);
152 0 : nCurRow = nRowEnd + 2;
153 : }
154 0 : else if (mbShowFilter)
155 0 : nCurRow += 2;
156 :
157 0 : if (nColumnFields)
158 0 : nCurRow += static_cast<SCROW>(nColumnFields);
159 0 : else if (nRowFields)
160 0 : ++nCurRow;
161 :
162 0 : return nCurRow;
163 : }
164 :
165 7 : void ScDPOutputGeometry::adjustFieldsForDataLayout(sal_uInt32& rColumnFields, sal_uInt32& rRowFields) const
166 : {
167 7 : rRowFields = mnRowFields;
168 7 : rColumnFields = mnColumnFields;
169 :
170 7 : if (mnDataFields < 2)
171 : {
172 : // Data layout field can be either row or column field, never page field.
173 7 : switch (meDataLayoutType)
174 : {
175 : case Column:
176 0 : if (rColumnFields > 0)
177 0 : rColumnFields -= 1;
178 0 : break;
179 : case Row:
180 7 : if (rRowFields > 0)
181 7 : rRowFields -= 1;
182 : default:
183 : ;
184 : }
185 : }
186 7 : }
187 :
188 : std::pair<ScDPOutputGeometry::FieldType, size_t>
189 7 : ScDPOutputGeometry::getFieldButtonType(const ScAddress& rPos) const
190 : {
191 7 : SCROW nCurRow = maOutRange.aStart.Row();
192 : sal_uInt32 nColumnFields, nRowFields;
193 7 : adjustFieldsForDataLayout(nColumnFields, nRowFields);
194 :
195 7 : if (mnPageFields)
196 : {
197 7 : SCCOL nCol = maOutRange.aStart.Col();
198 7 : SCROW nRowStart = maOutRange.aStart.Row() + mbShowFilter;
199 7 : SCROW nRowEnd = nRowStart + static_cast<SCCOL>(mnPageFields-1);
200 7 : if (rPos.Col() == nCol && nRowStart <= rPos.Row() && rPos.Row() <= nRowEnd)
201 : {
202 2 : size_t nPos = static_cast<size_t>(rPos.Row() - nRowStart);
203 2 : return std::pair<FieldType, size_t>(Page, nPos);
204 : }
205 :
206 5 : nCurRow = nRowEnd + 2;
207 : }
208 0 : else if (mbShowFilter)
209 0 : nCurRow += 2;
210 :
211 5 : if (nColumnFields)
212 : {
213 5 : SCROW nRow = nCurRow;
214 5 : SCCOL nColStart = static_cast<SCCOL>(maOutRange.aStart.Col() + nRowFields);
215 5 : SCCOL nColEnd = nColStart + static_cast<SCCOL>(nColumnFields-1);
216 5 : if (rPos.Row() == nRow && nColStart <= rPos.Col() && rPos.Col() <= nColEnd)
217 : {
218 2 : size_t nPos = static_cast<size_t>(rPos.Col() - nColStart);
219 2 : return std::pair<FieldType, size_t>(Column, nPos);
220 : }
221 :
222 3 : nCurRow += static_cast<SCROW>(nColumnFields);
223 : }
224 : else
225 0 : ++nCurRow;
226 :
227 3 : if (nRowFields)
228 : {
229 3 : SCCOL nColStart = maOutRange.aStart.Col();
230 3 : SCCOL nColEnd = nColStart + static_cast<SCCOL>(nRowFields-1);
231 3 : if (rPos.Row() == nCurRow && nColStart <= rPos.Col() && rPos.Col() <= nColEnd)
232 : {
233 2 : size_t nPos = static_cast<size_t>(rPos.Col() - nColStart);
234 2 : return std::pair<FieldType, size_t>(Row, nPos);
235 : }
236 : }
237 :
238 1 : return std::pair<FieldType, size_t>(None, 0);
239 : }
240 :
241 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|