xref: /trunk/main/svx/source/table/cellrange.cxx (revision f6e50924)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #include "cellrange.hxx"
28 
29 // -----------------------------------------------------------------------------
30 
31 using ::rtl::OUString;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::lang;
34 using namespace ::com::sun::star::container;
35 using namespace ::com::sun::star::table;
36 
37 // -----------------------------------------------------------------------------
38 
39 namespace sdr { namespace table {
40 
41 // -----------------------------------------------------------------------------
42 // CellRange
43 // -----------------------------------------------------------------------------
44 
CellRange(const TableModelRef & xTable,sal_Int32 nLeft,sal_Int32 nTop,sal_Int32 nRight,sal_Int32 nBottom)45 CellRange::CellRange( const TableModelRef & xTable, sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom )
46 : mxTable( xTable )
47 , mnLeft(nLeft)
48 , mnTop(nTop)
49 , mnRight(nRight)
50 , mnBottom(nBottom)
51 {
52 }
53 
54 // -----------------------------------------------------------------------------
55 
~CellRange()56 CellRange::~CellRange()
57 {
58 }
59 
60 // -----------------------------------------------------------------------------
61 // ICellRange
62 // -----------------------------------------------------------------------------
63 
getLeft()64 sal_Int32 CellRange::getLeft()
65 {
66 	return mnLeft;
67 }
68 
getTop()69 sal_Int32 CellRange::getTop()
70 {
71 	return mnTop;
72 }
73 
getRight()74 sal_Int32 CellRange::getRight()
75 {
76 	return mnRight;
77 }
78 
getBottom()79 sal_Int32 CellRange::getBottom()
80 {
81 	return mnBottom;
82 }
83 
getTable()84 Reference< XTable > CellRange::getTable()
85 {
86 	return mxTable.get();
87 }
88 
89 // -----------------------------------------------------------------------------
90 // XCellRange
91 // -----------------------------------------------------------------------------
92 
getCellByPosition(sal_Int32 nColumn,sal_Int32 nRow)93 Reference< XCell > SAL_CALL CellRange::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow ) throw (IndexOutOfBoundsException, RuntimeException)
94 {
95 	return mxTable->getCellByPosition( mnLeft + nColumn, mnTop + nRow );
96 }
97 
98 // -----------------------------------------------------------------------------
99 
getCellRangeByPosition(sal_Int32 nLeft,sal_Int32 nTop,sal_Int32 nRight,sal_Int32 nBottom)100 Reference< XCellRange > SAL_CALL CellRange::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ) throw (IndexOutOfBoundsException, RuntimeException)
101 {
102 	if( (nLeft >= 0 ) && (nTop >= 0) && (nRight >= nLeft) && (nBottom >= nTop)  )
103 	{
104 		nLeft += mnLeft;
105 		nTop += mnTop;
106 		nRight += mnLeft;
107 		nBottom += mnTop;
108 
109 		const sal_Int32 nMaxColumns = (mnRight == -1) ? mxTable->getColumnCount() : mnLeft;
110 		const sal_Int32 nMaxRows = (mnBottom == -1) ? mxTable->getRowCount() : mnBottom;
111 		if( (nLeft < nMaxColumns) && (nRight < nMaxColumns) && (nTop < nMaxRows) && (nBottom < nMaxRows) )
112 		{
113 			return mxTable->getCellRangeByPosition( nLeft, nTop, nRight, nBottom );
114 		}
115 	}
116 	throw IndexOutOfBoundsException();
117 }
118 
119 // -----------------------------------------------------------------------------
120 
getCellRangeByName(const OUString &)121 Reference< XCellRange > SAL_CALL CellRange::getCellRangeByName( const OUString& /*aRange*/ ) throw (RuntimeException)
122 {
123 	return Reference< XCellRange >();
124 }
125 
126 // -----------------------------------------------------------------------------
127 
128 } }
129