Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / table / cellrange.cxx
blob1a6c039dcfd2daadd77c53d1e4d51b33057fcdd7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
23 #include <utility>
25 #include "cellrange.hxx"
28 using namespace ::com::sun::star::uno;
29 using namespace ::com::sun::star::lang;
30 using namespace ::com::sun::star::container;
31 using namespace ::com::sun::star::table;
34 namespace sdr::table {
36 CellRange::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)
46 CellRange::~CellRange()
51 // ICellRange
54 sal_Int32 CellRange::getLeft()
56 return mnLeft;
59 sal_Int32 CellRange::getTop()
61 return mnTop;
64 sal_Int32 CellRange::getRight()
66 return mnRight;
69 sal_Int32 CellRange::getBottom()
71 return mnBottom;
74 Reference< XTable > CellRange::getTable()
76 return mxTable;
80 // XCellRange
83 Reference< XCell > SAL_CALL CellRange::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow )
85 return mxTable->getCellByPosition( mnLeft + nColumn, mnTop + nRow );
89 Reference< XCellRange > SAL_CALL CellRange::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom )
91 if( (nLeft >= 0 ) && (nTop >= 0) && (nRight >= nLeft) && (nBottom >= nTop) )
93 nLeft += mnLeft;
94 nTop += mnTop;
95 nRight += mnLeft;
96 nBottom += mnTop;
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) )
102 return mxTable->getCellRangeByPosition( nLeft, nTop, nRight, nBottom );
105 throw IndexOutOfBoundsException();
109 Reference< XCellRange > SAL_CALL CellRange::getCellRangeByName( const OUString& /*aRange*/ )
111 return Reference< XCellRange >();
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */