LibreOffice Module sc (master) 1
dpoutputgeometry.cxx
Go to the documentation of this file.
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
25using ::std::vector;
26
27ScDPOutputGeometry::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)
37{
38}
39
41{
43}
44
46{
48}
49
51{
53}
54
56{
58}
59
61{
63}
64
66{
67 mbHeaderLayout = bHeaderLayout;
68}
69
71{
72 mbCompactMode = bCompactMode;
73}
74
75void ScDPOutputGeometry::getColumnFieldPositions(vector<ScAddress>& rAddrs) const
76{
77 sal_uInt32 nColumnFields, nRowFields;
78 adjustFieldsForDataLayout(nColumnFields, nRowFields);
79
80 vector<ScAddress> aAddrs;
81 if (!nColumnFields)
82 {
83 rAddrs.swap(aAddrs);
84 return;
85 }
86
87 SCROW nCurRow = maOutRange.aStart.Row();
88
89 if (mnPageFields)
90 {
91 SCROW nRowStart = maOutRange.aStart.Row() + int(mbShowFilter);
92 SCROW nRowEnd = nRowStart + static_cast<SCCOL>(mnPageFields-1);
93 nCurRow = nRowEnd + 2;
94 }
95 else if (mbShowFilter)
96 nCurRow += 2;
97
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);
104
105 for (SCCOL nCol = nColStart; nCol <= nColEnd; ++nCol)
106 aAddrs.emplace_back(nCol, nRow, nTab);
107 rAddrs.swap(aAddrs);
108}
109
110void ScDPOutputGeometry::getRowFieldPositions(vector<ScAddress>& rAddrs) const
111{
112 sal_uInt32 nColumnFields, nRowFields;
113 adjustFieldsForDataLayout(nColumnFields, nRowFields);
114
115 vector<ScAddress> aAddrs;
116 if (!nRowFields)
117 {
118 rAddrs.swap(aAddrs);
119 return;
120 }
121
123 SCTAB nTab = maOutRange.aStart.Tab();
124 SCCOL nColStart = maOutRange.aStart.Col();
125 SCCOL nColEnd = nColStart + static_cast<SCCOL>(nRowFields-1);
126
127 if(mbCompactMode)
128 nColEnd = nColStart; // We have only one row in compact mode
129
130 for (SCCOL nCol = nColStart; nCol <= nColEnd; ++nCol)
131 aAddrs.emplace_back(nCol, nRow, nTab);
132 rAddrs.swap(aAddrs);
133}
134
135void ScDPOutputGeometry::getPageFieldPositions(vector<ScAddress>& rAddrs) const
136{
137 vector<ScAddress> aAddrs;
138 if (!mnPageFields)
139 {
140 rAddrs.swap(aAddrs);
141 return;
142 }
143
144 SCTAB nTab = maOutRange.aStart.Tab();
145 SCCOL nCol = maOutRange.aStart.Col();
146
147 SCROW nRowStart = maOutRange.aStart.Row() + int(mbShowFilter);
148 SCROW nRowEnd = nRowStart + static_cast<SCCOL>(mnPageFields-1);
149
150 for (SCROW nRow = nRowStart; nRow <= nRowEnd; ++nRow)
151 aAddrs.emplace_back(nCol, nRow, nTab);
152 rAddrs.swap(aAddrs);
153}
154
156{
157 SCROW nCurRow = maOutRange.aStart.Row();
158 sal_uInt32 nColumnFields, nRowFields;
159 adjustFieldsForDataLayout(nColumnFields, nRowFields);
160
161 if (mnPageFields)
162 {
163 SCROW nRowStart = maOutRange.aStart.Row() + int(mbShowFilter);
164 SCROW nRowEnd = nRowStart + static_cast<SCCOL>(mnPageFields-1);
165 nCurRow = nRowEnd + 2;
166 }
167 else if (mbShowFilter)
168 nCurRow += 2;
169
170 if (nColumnFields)
171 nCurRow += static_cast<SCROW>(nColumnFields);
172 else if (nRowFields && mbHeaderLayout)
173 ++nCurRow;
174
175 return nCurRow;
176}
177
178void ScDPOutputGeometry::adjustFieldsForDataLayout(sal_uInt32& rColumnFields, sal_uInt32& rRowFields) const
179{
180 rRowFields = mnRowFields;
181 rColumnFields = mnColumnFields;
182
183 if (mnDataFields >= 2)
184 return;
185
186 // Data layout field can be either row or column field, never page field.
187 switch (meDataLayoutType)
188 {
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:
198 ;
199 }
200}
201
202std::pair<ScDPOutputGeometry::FieldType, size_t>
204{
205 SCROW nCurRow = maOutRange.aStart.Row();
206 sal_uInt32 nColumnFields, nRowFields;
207 adjustFieldsForDataLayout(nColumnFields, nRowFields);
208
209 if (mnPageFields)
210 {
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)
215 {
216 size_t nPos = static_cast<size_t>(rPos.Row() - nRowStart);
217 return std::pair<FieldType, size_t>(Page, nPos);
218 }
219
220 nCurRow = nRowEnd + 2;
221 }
222 else if (mbShowFilter)
223 nCurRow += 2;
224
225 if (nColumnFields)
226 {
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)
231 {
232 size_t nPos = static_cast<size_t>(rPos.Col() - nColStart);
233 return std::pair<FieldType, size_t>(Column, nPos);
234 }
235
236 nCurRow += static_cast<SCROW>(nColumnFields);
237 }
238 else if (mbHeaderLayout)
239 ++nCurRow;
240
241 if (nRowFields)
242 {
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)
246 {
247 size_t nPos = static_cast<size_t>(rPos.Col() - nColStart);
248 return std::pair<FieldType, size_t>(Row, nPos);
249 }
250 }
251
252 return std::pair<FieldType, size_t>(None, 0);
253}
254
255/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _ADOColumn Column
SCTAB Tab() const
Definition: address.hxx:283
SCROW Row() const
Definition: address.hxx:274
SCCOL Col() const
Definition: address.hxx:279
std::pair< FieldType, size_t > getFieldButtonType(const ScAddress &rPos) const
void setColumnFieldCount(sal_uInt32 nCount)
void adjustFieldsForDataLayout(sal_uInt32 &rColumnFields, sal_uInt32 &rRowFields) const
void setCompactMode(bool bCompactMode)
void setRowFieldCount(sal_uInt32 nCount)
void getPageFieldPositions(::std::vector< ScAddress > &rAddrs) const
void setHeaderLayout(bool bHeaderLayout)
void setPageFieldCount(sal_uInt32 nCount)
void setDataFieldCount(sal_uInt32 nCount)
ScDPOutputGeometry()=delete
void getRowFieldPositions(::std::vector< ScAddress > &rAddrs) const
SCROW getRowFieldHeaderRow() const
void setDataLayoutType(FieldType eType)
void getColumnFieldPositions(::std::vector< ScAddress > &rAddrs) const
sal_uInt32 mnColumnFields
number of row fields
ScAddress aStart
Definition: address.hxx:497
int nCount
DocumentType eType
sal_uInt16 nPos
None
const wchar_t *typedef int(__stdcall *DllNativeUnregProc)(int
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17