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