LibreOffice Module svx (master) 1
cellrange.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 <sal/config.h>
21
22#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
23#include <utility>
24
25#include "cellrange.hxx"
26
27
28using namespace ::com::sun::star::uno;
29using namespace ::com::sun::star::lang;
30using namespace ::com::sun::star::container;
31using namespace ::com::sun::star::table;
32
33
34namespace sdr::table {
35
36CellRange::CellRange( TableModelRef xTable, sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom )
37: mxTable(std::move( xTable ))
38, mnLeft(nLeft)
39, mnTop(nTop)
40, mnRight(nRight)
41, mnBottom(nBottom)
42{
43}
44
45
47{
48}
49
50
51// ICellRange
52
53
55{
56 return mnLeft;
57}
58
60{
61 return mnTop;
62}
63
65{
66 return mnRight;
67}
68
70{
71 return mnBottom;
72}
73
74Reference< XTable > CellRange::getTable()
75{
76 return mxTable;
77}
78
79
80// XCellRange
81
82
83Reference< XCell > SAL_CALL CellRange::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow )
84{
85 return mxTable->getCellByPosition( mnLeft + nColumn, mnTop + nRow );
86}
87
88
89Reference< XCellRange > SAL_CALL CellRange::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom )
90{
91 if( (nLeft >= 0 ) && (nTop >= 0) && (nRight >= nLeft) && (nBottom >= nTop) )
92 {
93 nLeft += mnLeft;
94 nTop += mnTop;
95 nRight += mnLeft;
96 nBottom += mnTop;
97
98 const sal_Int32 nMaxColumns = (mnRight == -1) ? mxTable->getColumnCount() : mnLeft;
99 const sal_Int32 nMaxRows = (mnBottom == -1) ? mxTable->getRowCount() : mnBottom;
100 if( (nLeft < nMaxColumns) && (nRight < nMaxColumns) && (nTop < nMaxRows) && (nBottom < nMaxRows) )
101 {
102 return mxTable->getCellRangeByPosition( nLeft, nTop, nRight, nBottom );
103 }
104 }
105 throw IndexOutOfBoundsException();
106}
107
108
109Reference< XCellRange > SAL_CALL CellRange::getCellRangeByName( const OUString& /*aRange*/ )
110{
111 return Reference< XCellRange >();
112}
113
114
115}
116
117/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 mnTop
sal_Int32 mnRight
sal_Int32 mnBottom
sal_Int32 mnLeft
virtual sal_Int32 getLeft() override
Definition: cellrange.cxx:54
virtual ~CellRange() override
Definition: cellrange.cxx:46
virtual sal_Int32 getBottom() override
Definition: cellrange.cxx:69
virtual css::uno::Reference< css::table::XTable > getTable() override
Definition: cellrange.cxx:74
TableModelRef mxTable
Definition: cellrange.hxx:50
virtual sal_Int32 getRight() override
Definition: cellrange.cxx:64
virtual css::uno::Reference< css::table::XCellRange > SAL_CALL getCellRangeByName(const OUString &aRange) override
Definition: cellrange.cxx:109
virtual sal_Int32 getTop() override
Definition: cellrange.cxx:59
virtual css::uno::Reference< css::table::XCellRange > SAL_CALL getCellRangeByPosition(sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom) override
Definition: cellrange.cxx:89
CellRange(TableModelRef xTable, sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom)
Definition: cellrange.cxx:36
virtual css::uno::Reference< css::table::XCell > SAL_CALL getCellByPosition(sal_Int32 nColumn, sal_Int32 nRow) override
Definition: cellrange.cxx:83