LibreOffice Module sc (master) 1
clipparam.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 <clipparam.hxx>
21
22
24 meDirection(Unspecified),
25 mbCutMode(false),
26 mnSourceDocID(0)
27{
28}
29
30ScClipParam::ScClipParam(const ScRange& rRange, bool bCutMode) :
31 meDirection(Unspecified),
32 mbCutMode(bCutMode),
33 mnSourceDocID(0)
34{
35 maRanges.push_back(rRange);
36}
37
39{
40 return maRanges.size() > 1;
41}
42
44{
45 if (maRanges.empty())
46 return 0;
47
48 switch (meDirection)
49 {
51 {
52 SCCOL nColSize = 0;
53 for ( size_t i = 0, nListSize = maRanges.size(); i < nListSize; ++i )
54 {
55 const ScRange& rRange = maRanges[ i ];
56 nColSize += rRange.aEnd.Col() - rRange.aStart.Col() + 1;
57 }
58 return nColSize;
59 }
61 {
62 // We assume that all ranges have identical column size.
63 const ScRange& rRange = maRanges.front();
64 return rRange.aEnd.Col() - rRange.aStart.Col() + 1;
65 }
67 default:
68 ;
69 }
70 return 0;
71}
72
73SCROW ScClipParam::getPasteRowSize(const ScDocument& rSrcDoc, bool bIncludeFiltered)
74{
75 if (maRanges.empty())
76 return 0;
77
78 switch (meDirection)
79 {
81 {
82 // We assume that all ranges have identical row size.
83 const ScRange& rRange = maRanges.front();
84 return bIncludeFiltered
85 ? rRange.aEnd.Row() - rRange.aStart.Row() + 1
86 : rSrcDoc.CountNonFilteredRows(rRange.aStart.Row(), rRange.aEnd.Row(),
87 rRange.aStart.Tab());
88 }
90 {
91 SCROW nRowSize = 0;
92 for ( size_t i = 0, nListSize = maRanges.size(); i < nListSize; ++i )
93 {
94 const ScRange& rRange = maRanges[ i ];
95 nRowSize += bIncludeFiltered ? rRange.aEnd.Row() - rRange.aStart.Row() + 1
96 : rSrcDoc.CountNonFilteredRows(rRange.aStart.Row(),
97 rRange.aEnd.Row(),
98 rRange.aStart.Tab());
99 }
100 return nRowSize;
101 }
103 default:
104 ;
105 }
106 return 0;
107}
108
110{
111 return maRanges.Combine();
112}
113
114void ScClipParam::transpose(const ScDocument& rSrcDoc, bool bIncludeFiltered,
115 bool bIsMultiRangeRowFilteredTranspose)
116{
117 mbTransposed = true;
118
119 switch (meDirection)
120 {
121 case Column:
123 break;
124 case Row:
126 break;
127 case Unspecified:
128 default:
129 ;
130 }
131
132 ScRangeList aNewRanges;
133 if (!maRanges.empty())
134 {
135 const ScRange & rRange1 = maRanges.front();
136 SCCOL nColOrigin = rRange1.aStart.Col();
137 SCROW nRowOrigin = rRange1.aStart.Row();
138 SCROW nRowCount = 0;
139 for ( size_t i = 0, n = maRanges.size(); i < n; ++i )
140 {
141 const ScRange & rRange = maRanges[ i ];
142 SCCOL nColDelta = rRange.aStart.Col() - nColOrigin;
143 SCROW nRowDelta = rRange.aStart.Row() - nRowOrigin;
144 SCROW nNonFilteredRows = rSrcDoc.CountNonFilteredRows(
145 rRange.aStart.Row(), rRange.aEnd.Row(), rRange.aStart.Tab());
146 if (!bIsMultiRangeRowFilteredTranspose)
147 {
148 SCCOL nCol1 = 0;
149 SCCOL nCol2 = bIncludeFiltered
150 ? static_cast<SCCOL>(rRange.aEnd.Row() - rRange.aStart.Row())
151 : nNonFilteredRows - 1;
152 SCROW nRow1 = 0;
153 SCROW nRow2 = static_cast<SCROW>(rRange.aEnd.Col() - rRange.aStart.Col());
154 nCol1 += static_cast<SCCOL>(nRowDelta);
155 nCol2 += static_cast<SCCOL>(nRowDelta);
156 nRow1 += static_cast<SCROW>(nColDelta);
157 nRow2 += static_cast<SCROW>(nColDelta);
158 aNewRanges.push_back(ScRange(nColOrigin + nCol1, nRowOrigin + nRow1,
159 rRange.aStart.Tab(), nColOrigin + nCol2,
160 nRowOrigin + nRow2, rRange.aStart.Tab()));
161 }
162 else
163 nRowCount += nNonFilteredRows;
164 }
165
166 // Transpose of filtered multi range row selection is a special case since filtering
167 // and selection are in the same dimension (i.e. row), see ScDocument::TransposeClip()
168 if (bIsMultiRangeRowFilteredTranspose)
169 {
170 assert(!bIncludeFiltered && "bIsMultiRangeRowFilteredTranspose can only be true if bIncludeFiltered is false");
171 SCCOL nColDelta = rRange1.aStart.Col() - nColOrigin;
172 SCROW nRowDelta = rRange1.aStart.Row() - nRowOrigin;
173 SCCOL nCol1 = 0;
174 SCCOL nCol2 = nRowCount - 1;
175 SCROW nRow1 = 0;
176 SCROW nRow2 = static_cast<SCROW>(rRange1.aEnd.Col() - rRange1.aStart.Col());
177 nCol1 += static_cast<SCCOL>(nRowDelta);
178 nCol2 += static_cast<SCCOL>(nRowDelta);
179 nRow1 += static_cast<SCROW>(nColDelta);
180 nRow2 += static_cast<SCROW>(nColDelta);
181 aNewRanges.push_back(ScRange(nColOrigin + nCol1, nRowOrigin + nRow1,
182 rRange1.aStart.Tab(), nColOrigin + nCol2,
183 nRowOrigin + nRow2, rRange1.aStart.Tab()));
184 }
185 }
186 maRanges = aNewRanges;
187}
188
189/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SCTAB Tab() const
Definition: address.hxx:283
SCROW Row() const
Definition: address.hxx:274
SCCOL Col() const
Definition: address.hxx:279
SCROW CountNonFilteredRows(SCROW nStartRow, SCROW nEndRow, SCTAB nTab) const
Definition: document.cxx:4516
ScRange & front()
Definition: rangelst.hxx:92
ScRange Combine() const
Definition: rangelst.cxx:1107
bool empty() const
Definition: rangelst.hxx:88
void push_back(const ScRange &rRange)
Definition: rangelst.cxx:1137
size_t size() const
Definition: rangelst.hxx:89
ScAddress aEnd
Definition: address.hxx:498
ScAddress aStart
Definition: address.hxx:497
sal_Int64 n
int i
bool isMultiRange() const
Definition: clipparam.cxx:38
SCCOL getPasteColSize()
Get the column size of a pasted range.
Definition: clipparam.cxx:43
SCROW getPasteRowSize(const ScDocument &rSrcDoc, bool bIncludeFiltered)
Same as the above method, but returns the row size of the compressed range.
Definition: clipparam.cxx:73
bool mbTransposed
Was this clip transposed?
Definition: clipparam.hxx:40
void transpose(const ScDocument &rSrcDoc, bool bIncludeFiltered, bool bIsMultiRangeRowFilteredTranspose)
Transpose the clip parameters.
Definition: clipparam.cxx:114
Direction meDirection
Definition: clipparam.hxx:35
ScRangeList maRanges
Definition: clipparam.hxx:34
ScRange getWholeRange() const
Return a single range that encompasses all individual ranges.
Definition: clipparam.cxx:109
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17