Update ooo320-m1
[ooovba.git] / sc / source / core / data / dpoutputgeometry.cxx
blob999ab2866159dfd2eaff79e1d06bca63182af7ce
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmldpimp.cxx,v $
10 * $Revision: 1.27.134.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
38 #include "dpoutputgeometry.hxx"
39 #include "address.hxx"
41 #include <vector>
43 using ::std::vector;
45 ScDPOutputGeometry::ScDPOutputGeometry(const ScRange& rOutRange, bool bShowFilter, ImportType eImportType) :
46 maOutRange(rOutRange),
47 mnRowFields(0),
48 mnColumnFields(0),
49 mnPageFields(0),
50 mnDataFields(0),
51 meImportType(eImportType),
52 mbShowFilter(bShowFilter)
56 ScDPOutputGeometry::~ScDPOutputGeometry()
60 void ScDPOutputGeometry::setRowFieldCount(sal_uInt32 nCount)
62 mnRowFields = nCount;
65 void ScDPOutputGeometry::setColumnFieldCount(sal_uInt32 nCount)
67 mnColumnFields = nCount;
70 void ScDPOutputGeometry::setPageFieldCount(sal_uInt32 nCount)
72 mnPageFields = nCount;
75 void ScDPOutputGeometry::setDataFieldCount(sal_uInt32 nCount)
77 mnDataFields = nCount;
80 void ScDPOutputGeometry::getColumnFieldPositions(vector<ScAddress>& rAddrs) const
82 vector<ScAddress> aAddrs;
83 if (!mnColumnFields)
85 rAddrs.swap(aAddrs);
86 return;
89 bool bDataLayout = mnDataFields > 1;
91 SCROW nCurRow = maOutRange.aStart.Row();
93 if (mnPageFields)
95 SCROW nRowStart = maOutRange.aStart.Row() + mbShowFilter;
96 SCROW nRowEnd = nRowStart + static_cast<SCCOL>(mnPageFields-1);
97 nCurRow = nRowEnd + 2;
99 else if (mbShowFilter)
100 nCurRow += 2;
102 SCROW nRow = nCurRow;
103 SCTAB nTab = maOutRange.aStart.Tab();
104 SCCOL nColStart = maOutRange.aStart.Col() + mnRowFields + bDataLayout;
105 SCCOL nColEnd = nColStart + static_cast<SCCOL>(mnColumnFields-1);
107 for (SCCOL nCol = nColStart; nCol <= nColEnd; ++nCol)
108 aAddrs.push_back(ScAddress(nCol, nRow, nTab));
109 rAddrs.swap(aAddrs);
112 void ScDPOutputGeometry::getRowFieldPositions(vector<ScAddress>& rAddrs) const
114 vector<ScAddress> aAddrs;
115 if (!mnRowFields)
117 rAddrs.swap(aAddrs);
118 return;
121 SCROW nRow = getRowFieldHeaderRow();
122 SCTAB nTab = maOutRange.aStart.Tab();
123 SCCOL nColStart = maOutRange.aStart.Col();
124 SCCOL nColEnd = nColStart + static_cast<SCCOL>(mnRowFields-1);
126 for (SCCOL nCol = nColStart; nCol <= nColEnd; ++nCol)
127 aAddrs.push_back(ScAddress(nCol, nRow, nTab));
128 rAddrs.swap(aAddrs);
131 void ScDPOutputGeometry::getPageFieldPositions(vector<ScAddress>& rAddrs) const
133 vector<ScAddress> aAddrs;
134 if (!mnPageFields)
136 rAddrs.swap(aAddrs);
137 return;
140 SCTAB nTab = maOutRange.aStart.Tab();
141 SCCOL nCol = maOutRange.aStart.Col();
143 SCROW nRowStart = maOutRange.aStart.Row() + mbShowFilter;
144 SCROW nRowEnd = nRowStart + static_cast<SCCOL>(mnPageFields-1);
146 for (SCROW nRow = nRowStart; nRow <= nRowEnd; ++nRow)
147 aAddrs.push_back(ScAddress(nCol, nRow, nTab));
148 rAddrs.swap(aAddrs);
151 SCROW ScDPOutputGeometry::getRowFieldHeaderRow() const
153 SCROW nCurRow = maOutRange.aStart.Row();
155 if (mnPageFields)
157 SCROW nRowStart = maOutRange.aStart.Row() + mbShowFilter;
158 SCROW nRowEnd = nRowStart + static_cast<SCCOL>(mnPageFields-1);
159 nCurRow = nRowEnd + 2;
161 else if (mbShowFilter)
162 nCurRow += 2;
164 if (mnColumnFields)
165 nCurRow += static_cast<SCROW>(mnColumnFields);
166 else if (mnRowFields)
167 ++nCurRow;
169 return nCurRow;
172 ScDPOutputGeometry::FieldType ScDPOutputGeometry::getFieldButtonType(const ScAddress& rPos) const
174 // We will ignore the table position for now.
176 bool bExtraTitleRow = (mnColumnFields == 0 && meImportType == ScDPOutputGeometry::XLS);
177 bool bDataLayout = mnDataFields > 1;
179 SCROW nCurRow = maOutRange.aStart.Row();
181 if (mnPageFields)
183 SCCOL nCol = maOutRange.aStart.Col();
184 SCROW nRowStart = maOutRange.aStart.Row() + mbShowFilter;
185 SCROW nRowEnd = nRowStart + static_cast<SCCOL>(mnPageFields-1);
186 if (rPos.Col() == nCol && nRowStart <= rPos.Row() && rPos.Row() <= nRowEnd)
187 return Page;
189 nCurRow = nRowEnd + 2;
191 else if (mbShowFilter)
192 nCurRow += 2;
194 if (mnColumnFields)
196 SCROW nRow = nCurRow;
197 SCCOL nColStart = maOutRange.aStart.Col() + mnRowFields + bDataLayout;
198 SCCOL nColEnd = nColStart + static_cast<SCCOL>(mnColumnFields-1);
199 if (rPos.Row() == nRow && nColStart <= rPos.Col() && rPos.Col() <= nColEnd)
200 return Column;
202 nCurRow += static_cast<SCROW>(mnColumnFields);
205 if (bExtraTitleRow)
206 ++nCurRow;
208 if (mnRowFields)
210 SCCOL nColStart = maOutRange.aStart.Col();
211 SCCOL nColEnd = nColStart + static_cast<SCCOL>(mnRowFields-1);
212 if (rPos.Row() == nCurRow && nColStart <= rPos.Col() && rPos.Col() <= nColEnd)
213 return Row;
216 return None;