Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "dpoutputgeometry.hxx"
30 : : #include "address.hxx"
31 : :
32 : : #include <vector>
33 : :
34 : : using ::std::vector;
35 : :
36 : 6 : ScDPOutputGeometry::ScDPOutputGeometry(const ScRange& rOutRange, bool bShowFilter) :
37 : : maOutRange(rOutRange),
38 : : mnRowFields(0),
39 : : mnColumnFields(0),
40 : : mnPageFields(0),
41 : : mnDataFields(0),
42 : 6 : mbShowFilter(bShowFilter)
43 : : {
44 : 6 : }
45 : :
46 : 6 : ScDPOutputGeometry::~ScDPOutputGeometry()
47 : : {
48 : 6 : }
49 : :
50 : 6 : void ScDPOutputGeometry::setRowFieldCount(sal_uInt32 nCount)
51 : : {
52 : 6 : mnRowFields = nCount;
53 : 6 : }
54 : :
55 : 6 : void ScDPOutputGeometry::setColumnFieldCount(sal_uInt32 nCount)
56 : : {
57 : 6 : mnColumnFields = nCount;
58 : 6 : }
59 : :
60 : 6 : void ScDPOutputGeometry::setPageFieldCount(sal_uInt32 nCount)
61 : : {
62 : 6 : mnPageFields = nCount;
63 : 6 : }
64 : :
65 : 6 : void ScDPOutputGeometry::setDataFieldCount(sal_uInt32 nCount)
66 : : {
67 : 6 : mnDataFields = nCount;
68 : 6 : }
69 : :
70 : 0 : void ScDPOutputGeometry::getColumnFieldPositions(vector<ScAddress>& rAddrs) const
71 : : {
72 [ # # ]: 0 : vector<ScAddress> aAddrs;
73 [ # # ]: 0 : if (!mnColumnFields)
74 : : {
75 : 0 : rAddrs.swap(aAddrs);
76 : 0 : return;
77 : : }
78 : :
79 : 0 : SCROW nCurRow = maOutRange.aStart.Row();
80 : :
81 [ # # ]: 0 : if (mnPageFields)
82 : : {
83 : 0 : SCROW nRowStart = maOutRange.aStart.Row() + mbShowFilter;
84 : 0 : SCROW nRowEnd = nRowStart + static_cast<SCCOL>(mnPageFields-1);
85 : 0 : nCurRow = nRowEnd + 2;
86 : : }
87 [ # # ]: 0 : else if (mbShowFilter)
88 : 0 : nCurRow += 2;
89 : :
90 : 0 : SCROW nRow = nCurRow;
91 : 0 : SCTAB nTab = maOutRange.aStart.Tab();
92 : 0 : SCCOL nColStart = static_cast<SCCOL>(maOutRange.aStart.Col() + mnRowFields);
93 : 0 : SCCOL nColEnd = nColStart + static_cast<SCCOL>(mnColumnFields-1);
94 : :
95 [ # # ]: 0 : for (SCCOL nCol = nColStart; nCol <= nColEnd; ++nCol)
96 [ # # ]: 0 : aAddrs.push_back(ScAddress(nCol, nRow, nTab));
97 [ # # ]: 0 : rAddrs.swap(aAddrs);
98 : : }
99 : :
100 : 0 : void ScDPOutputGeometry::getRowFieldPositions(vector<ScAddress>& rAddrs) const
101 : : {
102 [ # # ]: 0 : vector<ScAddress> aAddrs;
103 [ # # ]: 0 : if (!mnRowFields)
104 : : {
105 : 0 : rAddrs.swap(aAddrs);
106 : 0 : return;
107 : : }
108 : :
109 [ # # ]: 0 : SCROW nRow = getRowFieldHeaderRow();
110 : 0 : SCTAB nTab = maOutRange.aStart.Tab();
111 : 0 : SCCOL nColStart = maOutRange.aStart.Col();
112 : 0 : SCCOL nColEnd = nColStart + static_cast<SCCOL>(mnRowFields-1);
113 : :
114 [ # # ]: 0 : for (SCCOL nCol = nColStart; nCol <= nColEnd; ++nCol)
115 [ # # ]: 0 : aAddrs.push_back(ScAddress(nCol, nRow, nTab));
116 [ # # ]: 0 : rAddrs.swap(aAddrs);
117 : : }
118 : :
119 : 0 : void ScDPOutputGeometry::getPageFieldPositions(vector<ScAddress>& rAddrs) const
120 : : {
121 [ # # ]: 0 : vector<ScAddress> aAddrs;
122 [ # # ]: 0 : if (!mnPageFields)
123 : : {
124 : 0 : rAddrs.swap(aAddrs);
125 : 0 : return;
126 : : }
127 : :
128 : 0 : SCTAB nTab = maOutRange.aStart.Tab();
129 : 0 : SCCOL nCol = maOutRange.aStart.Col();
130 : :
131 : 0 : SCROW nRowStart = maOutRange.aStart.Row() + mbShowFilter;
132 : 0 : SCROW nRowEnd = nRowStart + static_cast<SCCOL>(mnPageFields-1);
133 : :
134 [ # # ]: 0 : for (SCROW nRow = nRowStart; nRow <= nRowEnd; ++nRow)
135 [ # # ]: 0 : aAddrs.push_back(ScAddress(nCol, nRow, nTab));
136 [ # # ]: 0 : rAddrs.swap(aAddrs);
137 : : }
138 : :
139 : 0 : SCROW ScDPOutputGeometry::getRowFieldHeaderRow() const
140 : : {
141 : 0 : SCROW nCurRow = maOutRange.aStart.Row();
142 : :
143 [ # # ]: 0 : if (mnPageFields)
144 : : {
145 : 0 : SCROW nRowStart = maOutRange.aStart.Row() + mbShowFilter;
146 : 0 : SCROW nRowEnd = nRowStart + static_cast<SCCOL>(mnPageFields-1);
147 : 0 : nCurRow = nRowEnd + 2;
148 : : }
149 [ # # ]: 0 : else if (mbShowFilter)
150 : 0 : nCurRow += 2;
151 : :
152 [ # # ]: 0 : if (mnColumnFields)
153 : 0 : nCurRow += static_cast<SCROW>(mnColumnFields);
154 [ # # ]: 0 : else if (mnRowFields)
155 : 0 : ++nCurRow;
156 : :
157 : 0 : return nCurRow;
158 : : }
159 : :
160 : : std::pair<ScDPOutputGeometry::FieldType, size_t>
161 : 20 : ScDPOutputGeometry::getFieldButtonType(const ScAddress& rPos) const
162 : : {
163 : : // We will ignore the table position for now.
164 : :
165 : 20 : SCROW nCurRow = maOutRange.aStart.Row();
166 : :
167 [ + + ]: 20 : if (mnPageFields)
168 : : {
169 : 8 : SCCOL nCol = maOutRange.aStart.Col();
170 : 8 : SCROW nRowStart = maOutRange.aStart.Row() + mbShowFilter;
171 : 8 : SCROW nRowEnd = nRowStart + static_cast<SCCOL>(mnPageFields-1);
172 [ + + ][ + + ]: 8 : if (rPos.Col() == nCol && nRowStart <= rPos.Row() && rPos.Row() <= nRowEnd)
[ + + ][ + + ]
173 : : {
174 : 2 : size_t nPos = static_cast<size_t>(rPos.Row() - nRowStart);
175 [ + - ]: 2 : return std::pair<FieldType, size_t>(Page, nPos);
176 : : }
177 : :
178 : 6 : nCurRow = nRowEnd + 2;
179 : : }
180 [ + - ]: 12 : else if (mbShowFilter)
181 : 12 : nCurRow += 2;
182 : :
183 [ + + ]: 18 : if (mnColumnFields)
184 : : {
185 : 16 : SCROW nRow = nCurRow;
186 : 16 : SCCOL nColStart = static_cast<SCCOL>(maOutRange.aStart.Col() + mnRowFields);
187 : 16 : SCCOL nColEnd = nColStart + static_cast<SCCOL>(mnColumnFields-1);
188 [ + + ][ + - ]: 16 : if (rPos.Row() == nRow && nColStart <= rPos.Col() && rPos.Col() <= nColEnd)
[ + + ][ + + ]
189 : : {
190 : 4 : size_t nPos = static_cast<size_t>(rPos.Col() - nColStart);
191 [ + - ]: 4 : return std::pair<FieldType, size_t>(Column, nPos);
192 : : }
193 : :
194 : 12 : nCurRow += static_cast<SCROW>(mnColumnFields);
195 : : }
196 : : else
197 : 2 : ++nCurRow;
198 : :
199 [ + + ]: 14 : if (mnRowFields)
200 : : {
201 : 12 : SCCOL nColStart = maOutRange.aStart.Col();
202 : 12 : SCCOL nColEnd = nColStart + static_cast<SCCOL>(mnRowFields-1);
203 [ + - ][ + - ]: 12 : if (rPos.Row() == nCurRow && nColStart <= rPos.Col() && rPos.Col() <= nColEnd)
[ + + ][ + + ]
204 : : {
205 : 6 : size_t nPos = static_cast<size_t>(rPos.Col() - nColStart);
206 [ + - ]: 6 : return std::pair<FieldType, size_t>(Row, nPos);
207 : : }
208 : : }
209 : :
210 [ + - ]: 20 : return std::pair<FieldType, size_t>(None, 0);
211 : : }
212 : :
213 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|