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 
41 {
42 }
43 
44 void ScDPOutputGeometry::setRowFieldCount(sal_uInt32 nCount)
45 {
46  mnRowFields = nCount;
47 }
48 
50 {
51  mnColumnFields = nCount;
52 }
53 
55 {
56  mnPageFields = nCount;
57 }
58 
60 {
61  mnDataFields = nCount;
62 }
63 
65 {
66  meDataLayoutType = eType;
67 }
68 
69 void ScDPOutputGeometry::setHeaderLayout(bool bHeaderLayout)
70 {
71  mbHeaderLayout = bHeaderLayout;
72 }
73 
74 void ScDPOutputGeometry::setCompactMode(bool bCompactMode)
75 {
76  mbCompactMode = bCompactMode;
77 }
78 
79 void ScDPOutputGeometry::getColumnFieldPositions(vector<ScAddress>& rAddrs) const
80 {
81  sal_uInt32 nColumnFields, nRowFields;
82  adjustFieldsForDataLayout(nColumnFields, nRowFields);
83 
84  vector<ScAddress> aAddrs;
85  if (!nColumnFields)
86  {
87  rAddrs.swap(aAddrs);
88  return;
89  }
90 
91  SCROW nCurRow = maOutRange.aStart.Row();
92 
93  if (mnPageFields)
94  {
95  SCROW nRowStart = maOutRange.aStart.Row() + int(mbShowFilter);
96  SCROW nRowEnd = nRowStart + static_cast<SCCOL>(mnPageFields-1);
97  nCurRow = nRowEnd + 2;
98  }
99  else if (mbShowFilter)
100  nCurRow += 2;
101 
102  SCROW nRow = nCurRow;
103  SCTAB nTab = maOutRange.aStart.Tab();
104  SCCOL nColStart = static_cast<SCCOL>(maOutRange.aStart.Col() + nRowFields);
105  if(mbCompactMode)
106  nColStart = static_cast<SCCOL>(maOutRange.aStart.Col() + 1); // We have only one row in compact mode
107  SCCOL nColEnd = nColStart + static_cast<SCCOL>(nColumnFields-1);
108 
109  for (SCCOL nCol = nColStart; nCol <= nColEnd; ++nCol)
110  aAddrs.emplace_back(nCol, nRow, nTab);
111  rAddrs.swap(aAddrs);
112 }
113 
114 void ScDPOutputGeometry::getRowFieldPositions(vector<ScAddress>& rAddrs) const
115 {
116  sal_uInt32 nColumnFields, nRowFields;
117  adjustFieldsForDataLayout(nColumnFields, nRowFields);
118 
119  vector<ScAddress> aAddrs;
120  if (!nRowFields)
121  {
122  rAddrs.swap(aAddrs);
123  return;
124  }
125 
126  SCROW nRow = getRowFieldHeaderRow();
127  SCTAB nTab = maOutRange.aStart.Tab();
128  SCCOL nColStart = maOutRange.aStart.Col();
129  SCCOL nColEnd = nColStart + static_cast<SCCOL>(nRowFields-1);
130 
131  if(mbCompactMode)
132  nColEnd = nColStart; // We have only one row in compact mode
133 
134  for (SCCOL nCol = nColStart; nCol <= nColEnd; ++nCol)
135  aAddrs.emplace_back(nCol, nRow, nTab);
136  rAddrs.swap(aAddrs);
137 }
138 
139 void ScDPOutputGeometry::getPageFieldPositions(vector<ScAddress>& rAddrs) const
140 {
141  vector<ScAddress> aAddrs;
142  if (!mnPageFields)
143  {
144  rAddrs.swap(aAddrs);
145  return;
146  }
147 
148  SCTAB nTab = maOutRange.aStart.Tab();
149  SCCOL nCol = maOutRange.aStart.Col();
150 
151  SCROW nRowStart = maOutRange.aStart.Row() + int(mbShowFilter);
152  SCROW nRowEnd = nRowStart + static_cast<SCCOL>(mnPageFields-1);
153 
154  for (SCROW nRow = nRowStart; nRow <= nRowEnd; ++nRow)
155  aAddrs.emplace_back(nCol, nRow, nTab);
156  rAddrs.swap(aAddrs);
157 }
158 
160 {
161  SCROW nCurRow = maOutRange.aStart.Row();
162  sal_uInt32 nColumnFields, nRowFields;
163  adjustFieldsForDataLayout(nColumnFields, nRowFields);
164 
165  if (mnPageFields)
166  {
167  SCROW nRowStart = maOutRange.aStart.Row() + int(mbShowFilter);
168  SCROW nRowEnd = nRowStart + static_cast<SCCOL>(mnPageFields-1);
169  nCurRow = nRowEnd + 2;
170  }
171  else if (mbShowFilter)
172  nCurRow += 2;
173 
174  if (nColumnFields)
175  nCurRow += static_cast<SCROW>(nColumnFields);
176  else if (nRowFields && mbHeaderLayout)
177  ++nCurRow;
178 
179  return nCurRow;
180 }
181 
182 void ScDPOutputGeometry::adjustFieldsForDataLayout(sal_uInt32& rColumnFields, sal_uInt32& rRowFields) const
183 {
184  rRowFields = mnRowFields;
185  rColumnFields = mnColumnFields;
186 
187  if (mnDataFields >= 2)
188  return;
189 
190  // Data layout field can be either row or column field, never page field.
191  switch (meDataLayoutType)
192  {
193  case Column:
194  if (rColumnFields > 0)
195  rColumnFields -= 1;
196  break;
197  case Row:
198  if (rRowFields > 0)
199  rRowFields -= 1;
200  break;
201  default:
202  ;
203  }
204 }
205 
206 std::pair<ScDPOutputGeometry::FieldType, size_t>
208 {
209  SCROW nCurRow = maOutRange.aStart.Row();
210  sal_uInt32 nColumnFields, nRowFields;
211  adjustFieldsForDataLayout(nColumnFields, nRowFields);
212 
213  if (mnPageFields)
214  {
215  SCCOL nCol = maOutRange.aStart.Col();
216  SCROW nRowStart = maOutRange.aStart.Row() + int(mbShowFilter);
217  SCROW nRowEnd = nRowStart + static_cast<SCCOL>(mnPageFields-1);
218  if (rPos.Col() == nCol && nRowStart <= rPos.Row() && rPos.Row() <= nRowEnd)
219  {
220  size_t nPos = static_cast<size_t>(rPos.Row() - nRowStart);
221  return std::pair<FieldType, size_t>(Page, nPos);
222  }
223 
224  nCurRow = nRowEnd + 2;
225  }
226  else if (mbShowFilter)
227  nCurRow += 2;
228 
229  if (nColumnFields)
230  {
231  SCROW nRow = nCurRow;
232  SCCOL nColStart = static_cast<SCCOL>(maOutRange.aStart.Col() + nRowFields);
233  SCCOL nColEnd = nColStart + static_cast<SCCOL>(nColumnFields-1);
234  if (rPos.Row() == nRow && nColStart <= rPos.Col() && rPos.Col() <= nColEnd)
235  {
236  size_t nPos = static_cast<size_t>(rPos.Col() - nColStart);
237  return std::pair<FieldType, size_t>(Column, nPos);
238  }
239 
240  nCurRow += static_cast<SCROW>(nColumnFields);
241  }
242  else if (mbHeaderLayout)
243  ++nCurRow;
244 
245  if (nRowFields)
246  {
247  SCCOL nColStart = maOutRange.aStart.Col();
248  SCCOL nColEnd = nColStart + static_cast<SCCOL>(nRowFields-1);
249  if (rPos.Row() == nCurRow && nColStart <= rPos.Col() && rPos.Col() <= nColEnd)
250  {
251  size_t nPos = static_cast<size_t>(rPos.Col() - nColStart);
252  return std::pair<FieldType, size_t>(Row, nPos);
253  }
254  }
255 
256  return std::pair<FieldType, size_t>(None, 0);
257 }
258 
259 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void adjustFieldsForDataLayout(sal_uInt32 &rColumnFields, sal_uInt32 &rRowFields) const
ScAddress aStart
Definition: address.hxx:500
SCROW Row() const
Definition: address.hxx:262
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:271
void setPageFieldCount(sal_uInt32 nCount)
ScDPOutputGeometry()=delete
void setCompactMode(bool bCompactMode)
sal_Int16 SCCOL
Definition: types.hxx:22
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:267
void getColumnFieldPositions(::std::vector< ScAddress > &rAddrs) const
SCROW getRowFieldHeaderRow() const
sal_Int32 SCROW
Definition: types.hxx:18
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:23