update dev300-m57
[ooovba.git] / sc / source / core / data / dpoutputgeometry.cxx
blobbc5513bf2267a76ef521ce7954f3a38cf0d384a5
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) :
46 maOutRange(rOutRange),
47 mnRowFields(0),
48 mnColumnFields(0),
49 mnPageFields(0),
50 mnDataFields(0),
51 mbShowFilter(bShowFilter)
55 ScDPOutputGeometry::~ScDPOutputGeometry()
59 void ScDPOutputGeometry::setRowFieldCount(sal_uInt32 nCount)
61 mnRowFields = nCount;
64 void ScDPOutputGeometry::setColumnFieldCount(sal_uInt32 nCount)
66 mnColumnFields = nCount;
69 void ScDPOutputGeometry::setPageFieldCount(sal_uInt32 nCount)
71 mnPageFields = nCount;
74 void ScDPOutputGeometry::setDataFieldCount(sal_uInt32 nCount)
76 mnDataFields = nCount;
79 void ScDPOutputGeometry::getColumnFieldPositions(vector<ScAddress>& rAddrs) const
81 vector<ScAddress> aAddrs;
82 if (!mnColumnFields)
84 rAddrs.swap(aAddrs);
85 return;
88 bool bDataLayout = mnDataFields > 1;
90 SCROW nCurRow = maOutRange.aStart.Row();
92 if (mnPageFields)
94 SCROW nRowStart = maOutRange.aStart.Row() + mbShowFilter;
95 SCROW nRowEnd = nRowStart + static_cast<SCCOL>(mnPageFields-1);
96 nCurRow = nRowEnd + 2;
98 else if (mbShowFilter)
99 nCurRow += 2;
101 SCROW nRow = nCurRow;
102 SCTAB nTab = maOutRange.aStart.Tab();
103 SCCOL nColStart = maOutRange.aStart.Col() + mnRowFields + bDataLayout;
104 SCCOL nColEnd = nColStart + static_cast<SCCOL>(mnColumnFields-1);
106 for (SCCOL nCol = nColStart; nCol <= nColEnd; ++nCol)
107 aAddrs.push_back(ScAddress(nCol, nRow, nTab));
108 rAddrs.swap(aAddrs);
111 void ScDPOutputGeometry::getRowFieldPositions(vector<ScAddress>& rAddrs) const
113 vector<ScAddress> aAddrs;
114 if (!mnRowFields)
116 rAddrs.swap(aAddrs);
117 return;
120 SCROW nCurRow = maOutRange.aStart.Row();
122 if (mnPageFields)
124 SCROW nRowStart = maOutRange.aStart.Row() + mbShowFilter;
125 SCROW nRowEnd = nRowStart + static_cast<SCCOL>(mnPageFields-1);
126 nCurRow = nRowEnd + 2;
128 else if (mbShowFilter)
129 nCurRow += 2;
131 nCurRow += static_cast<SCROW>(mnColumnFields);
133 SCROW nRow = nCurRow;
134 SCTAB nTab = maOutRange.aStart.Tab();
135 SCCOL nColStart = maOutRange.aStart.Col();
136 SCCOL nColEnd = nColStart + static_cast<SCCOL>(mnRowFields-1);
138 for (SCCOL nCol = nColStart; nCol <= nColEnd; ++nCol)
139 aAddrs.push_back(ScAddress(nCol, nRow, nTab));
140 rAddrs.swap(aAddrs);
143 void ScDPOutputGeometry::getPageFieldPositions(vector<ScAddress>& rAddrs) const
145 vector<ScAddress> aAddrs;
146 if (!mnPageFields)
148 rAddrs.swap(aAddrs);
149 return;
152 SCTAB nTab = maOutRange.aStart.Tab();
153 SCCOL nCol = maOutRange.aStart.Col();
155 SCROW nRowStart = maOutRange.aStart.Row() + mbShowFilter;
156 SCROW nRowEnd = nRowStart + static_cast<SCCOL>(mnPageFields-1);
158 for (SCROW nRow = nRowStart; nRow <= nRowEnd; ++nRow)
159 aAddrs.push_back(ScAddress(nCol, nRow, nTab));
160 rAddrs.swap(aAddrs);
163 ScDPOutputGeometry::FieldType ScDPOutputGeometry::getFieldButtonType(const ScAddress& rPos) const
165 // We will ignore the table position for now.
167 bool bDataLayout = mnDataFields > 1;
169 SCROW nCurRow = maOutRange.aStart.Row();
171 if (mnPageFields)
173 SCCOL nCol = maOutRange.aStart.Col();
174 SCROW nRowStart = maOutRange.aStart.Row() + mbShowFilter;
175 SCROW nRowEnd = nRowStart + static_cast<SCCOL>(mnPageFields-1);
176 if (rPos.Col() == nCol && nRowStart <= rPos.Row() && rPos.Row() <= nRowEnd)
177 return Page;
179 nCurRow = nRowEnd + 2;
181 else if (mbShowFilter)
182 nCurRow += 2;
184 if (mnColumnFields)
186 SCROW nRow = nCurRow;
187 SCCOL nColStart = maOutRange.aStart.Col() + mnRowFields + bDataLayout;
188 SCCOL nColEnd = nColStart + static_cast<SCCOL>(mnColumnFields-1);
189 if (rPos.Row() == nRow && nColStart <= rPos.Col() && rPos.Col() <= nColEnd)
190 return Column;
192 nCurRow += static_cast<SCROW>(mnColumnFields);
195 if (mnRowFields)
197 SCCOL nColStart = maOutRange.aStart.Col();
198 SCCOL nColEnd = nColStart + static_cast<SCCOL>(mnRowFields-1);
199 if (rPos.Row() == nCurRow && nColStart <= rPos.Col() && rPos.Col() <= nColEnd)
200 return Row;
203 return None;