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 
25 using ::std::vector;
26 
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)
37 {
38 }
39 
40 void ScDPOutputGeometry::setRowFieldCount(sal_uInt32 nCount)
41 {
42  mnRowFields = nCount;
43 }
44 
46 {
47  mnColumnFields = nCount;
48 }
49 
51 {
52  mnPageFields = nCount;
53 }
54 
56 {
57  mnDataFields = nCount;
58 }
59 
61 {
62  meDataLayoutType = eType;
63 }
64 
65 void ScDPOutputGeometry::setHeaderLayout(bool bHeaderLayout)
66 {
67  mbHeaderLayout = bHeaderLayout;
68 }
69 
70 void ScDPOutputGeometry::setCompactMode(bool bCompactMode)
71 {
72  mbCompactMode = bCompactMode;
73 }
74 
75 void 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 
110 void 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 
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);
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 
135 void 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 
178 void 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 
202 std::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: */
void adjustFieldsForDataLayout(sal_uInt32 &rColumnFields, sal_uInt32 &rRowFields) const
ScAddress aStart
Definition: address.hxx:497
SCROW Row() const
Definition: address.hxx:274
void setDataLayoutType(FieldType eType)
const wchar_t *typedef int(__stdcall *DllNativeUnregProc)(int
struct _ADOColumn Column
void setColumnFieldCount(sal_uInt32 nCount)
None
void getRowFieldPositions(::std::vector< ScAddress > &rAddrs) const
SCTAB Tab() const
Definition: address.hxx:283
void setPageFieldCount(sal_uInt32 nCount)
ScDPOutputGeometry()=delete
void setCompactMode(bool bCompactMode)
sal_Int16 SCCOL
Definition: types.hxx:21
std::pair< FieldType, size_t > getFieldButtonType(const ScAddress &rPos) const
void setRowFieldCount(sal_uInt32 nCount)
void setHeaderLayout(bool bHeaderLayout)
SCCOL Col() const
Definition: address.hxx:279
void getColumnFieldPositions(::std::vector< ScAddress > &rAddrs) const
SCROW getRowFieldHeaderRow() const
sal_Int32 SCROW
Definition: types.hxx:17
void setDataFieldCount(sal_uInt32 nCount)
void getPageFieldPositions(::std::vector< ScAddress > &rAddrs) const
sal_uInt32 mnColumnFields
number of row fields
sal_uInt16 nPos
sal_Int16 SCTAB
Definition: types.hxx:22
bool m_bDetectedRangeSegmentation false