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 
30 ScClipParam::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  }
60  case ScClipParam::Row:
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 
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 rRange.aEnd.Row() - rRange.aStart.Row() + 1;
85  }
86  case ScClipParam::Row:
87  {
88  SCROW nRowSize = 0;
89  for ( size_t i = 0, nListSize = maRanges.size(); i < nListSize; ++i )
90  {
91  const ScRange& rRange = maRanges[ i ];
92  nRowSize += rRange.aEnd.Row() - rRange.aStart.Row() + 1;
93  }
94  return nRowSize;
95  }
97  default:
98  ;
99  }
100  return 0;
101 }
102 
104 {
105  return maRanges.Combine();
106 }
107 
109 {
110  switch (meDirection)
111  {
112  case Column:
114  break;
115  case Row:
117  break;
118  case Unspecified:
119  default:
120  ;
121  }
122 
123  ScRangeList aNewRanges;
124  if (!maRanges.empty())
125  {
126  const ScRange & rRange1 = maRanges.front();
127  SCCOL nColOrigin = rRange1.aStart.Col();
128  SCROW nRowOrigin = rRange1.aStart.Row();
129 
130  for ( size_t i = 0, n = maRanges.size(); i < n; ++i )
131  {
132  const ScRange & rRange = maRanges[ i ];
133  SCCOL nColDelta = rRange.aStart.Col() - nColOrigin;
134  SCROW nRowDelta = rRange.aStart.Row() - nRowOrigin;
135  SCCOL nCol1 = 0;
136  SCCOL nCol2 = static_cast<SCCOL>(rRange.aEnd.Row() - rRange.aStart.Row());
137  SCROW nRow1 = 0;
138  SCROW nRow2 = static_cast<SCROW>(rRange.aEnd.Col() - rRange.aStart.Col());
139  nCol1 += static_cast<SCCOL>(nRowDelta);
140  nCol2 += static_cast<SCCOL>(nRowDelta);
141  nRow1 += static_cast<SCROW>(nColDelta);
142  nRow2 += static_cast<SCROW>(nColDelta);
143  aNewRanges.push_back( ScRange(nCol1, nRow1, rRange.aStart.Tab(), nCol2, nRow2, rRange.aStart.Tab() ) );
144  }
145  }
146  maRanges = aNewRanges;
147 }
148 
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SCROW getPasteRowSize()
Same as the above method, but returns the row size of the compressed range.
Definition: clipparam.cxx:73
ScAddress aStart
Definition: address.hxx:500
SCROW Row() const
Definition: address.hxx:262
sal_Int64 n
struct _ADOColumn Column
ScRange Combine() const
Definition: rangelst.cxx:1114
ScAddress aEnd
Definition: address.hxx:501
Direction meDirection
Definition: clipparam.hxx:35
SCCOL getPasteColSize()
Get the column size of a pasted range.
Definition: clipparam.cxx:43
void push_back(const ScRange &rRange)
Definition: rangelst.cxx:1144
SCTAB Tab() const
Definition: address.hxx:271
bool empty() const
Definition: rangelst.hxx:89
int i
sal_Int16 SCCOL
Definition: types.hxx:22
size_t size() const
Definition: rangelst.hxx:90
ScRangeList maRanges
Definition: clipparam.hxx:34
SCCOL Col() const
Definition: address.hxx:267
sal_Int32 SCROW
Definition: types.hxx:18
ScRange getWholeRange() const
Return a single range that encompasses all individual ranges.
Definition: clipparam.cxx:103
ScRange & front()
Definition: rangelst.hxx:93
void transpose()
Definition: clipparam.cxx:108
bool isMultiRange() const
Definition: clipparam.cxx:38