nss: upgrade to release 3.73
[LibreOffice.git] / sc / source / ui / vba / vbapane.cxx
blob1f7f0b540565c4f22aa77f8f177bb8e6c838ae24
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 "vbapane.hxx"
21 #include <com/sun/star/frame/XModel.hpp>
22 #include <com/sun/star/sheet/XSpreadsheet.hpp>
23 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
24 #include <com/sun/star/table/CellRangeAddress.hpp>
25 #include "vbarange.hxx"
27 using namespace com::sun::star;
28 using namespace ooo::vba;
30 ScVbaPane::ScVbaPane(
31 const css::uno::Reference< ov::XHelperInterface >& xParent,
32 const uno::Reference< uno::XComponentContext >& xContext,
33 const uno::Reference< frame::XModel >& rModel,
34 const uno::Reference< sheet::XViewPane >& rViewPane ) :
35 m_xModel(rModel, uno::UNO_SET_THROW),
36 m_xViewPane(rViewPane, uno::UNO_SET_THROW),
37 m_xParent(xParent),
38 m_xContext(xContext)
42 sal_Int32 SAL_CALL
43 ScVbaPane::getScrollColumn()
45 return ( m_xViewPane->getFirstVisibleColumn() + 1 );
48 void SAL_CALL
49 ScVbaPane::setScrollColumn( sal_Int32 _scrollcolumn )
51 if( _scrollcolumn < 1 )
53 throw uno::RuntimeException("Column number should not be less than 1" );
55 m_xViewPane->setFirstVisibleColumn( _scrollcolumn - 1 );
58 sal_Int32 SAL_CALL
59 ScVbaPane::getScrollRow()
61 return ( m_xViewPane->getFirstVisibleRow() + 1 );
64 void SAL_CALL
65 ScVbaPane::setScrollRow( sal_Int32 _scrollrow )
67 if( _scrollrow < 1 )
69 throw uno::RuntimeException("Row number should not be less than 1" );
71 m_xViewPane->setFirstVisibleRow( _scrollrow - 1 );
74 uno::Reference< excel::XRange > SAL_CALL
75 ScVbaPane::getVisibleRange()
77 // TODO: Excel includes partly visible rows/columns, Calc does not
78 table::CellRangeAddress aRangeAddr = m_xViewPane->getVisibleRange();
79 uno::Reference< sheet::XSpreadsheetDocument > xDoc( m_xModel, uno::UNO_QUERY_THROW );
80 uno::Reference< container::XIndexAccess > xSheetsIA( xDoc->getSheets(), uno::UNO_QUERY_THROW );
81 uno::Reference< sheet::XSpreadsheet > xSheet( xSheetsIA->getByIndex( aRangeAddr.Sheet ), uno::UNO_QUERY_THROW );
82 uno::Reference< table::XCellRange > xRange( xSheet->getCellRangeByPosition( aRangeAddr.StartColumn, aRangeAddr.StartRow, aRangeAddr.EndColumn, aRangeAddr.EndRow ), uno::UNO_SET_THROW );
83 // TODO: m_xParent is the window, Range needs the worksheet
84 return new ScVbaRange( m_xParent, m_xContext, xRange );
87 //Method
88 void SAL_CALL
89 ScVbaPane::SmallScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft )
91 OUString messageBuffer;
92 sal_Int32 downRows = 0;
93 sal_Int32 rightCols = 0;
94 table::CellRangeAddress visibleRange = m_xViewPane->getVisibleRange();
96 if( Down.hasValue() )
98 sal_Int32 down = 0;
99 if( Down >>= down )
100 downRows += down;
101 else
102 messageBuffer += "Error getting parameter: Down\n";
104 if( Up.hasValue() )
106 sal_Int32 up = 0;
107 if( Up >>= up )
108 downRows -= up;
109 else
110 messageBuffer += "Error getting parameter: Up\n";
112 if( ToRight.hasValue() )
114 sal_Int32 right = 0;
115 if( ToRight >>= right )
116 rightCols += right;
117 else
118 messageBuffer += "Error getting parameter: ToRight\n";
120 if( ToLeft.hasValue() )
122 sal_Int32 left = 0;
123 if( ToLeft >>= left )
124 rightCols -= left;
125 else
126 messageBuffer += "Error getting parameter: ToLeft\n";
128 if( !messageBuffer.isEmpty() )
129 throw uno::RuntimeException( messageBuffer );
131 sal_Int32 newStartRow = visibleRange.StartRow + downRows;
132 if( newStartRow < 0 )
133 newStartRow = 0;
134 sal_Int32 newStartCol = visibleRange.StartColumn + rightCols;
135 if( newStartCol < 0 )
136 newStartCol = 0;
137 m_xViewPane->setFirstVisibleRow( newStartRow );
138 m_xViewPane->setFirstVisibleColumn( newStartCol );
141 void SAL_CALL
142 ScVbaPane::LargeScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft )
144 OUString messageBuffer;
145 table::CellRangeAddress visibleRange = m_xViewPane->getVisibleRange();
147 sal_Int32 vertPageSize = 1 + visibleRange.EndRow - visibleRange.StartRow;
148 sal_Int32 horizPageSize = 1 + visibleRange.EndColumn - visibleRange.StartColumn;
149 sal_Int32 downPages = 0;
150 sal_Int32 acrossPages = 0;
151 if( Down.hasValue() )
153 sal_Int32 down = 0;
154 if( Down >>= down )
155 downPages += down;
156 else
157 messageBuffer += "Error getting parameter: Down\n";
159 if( Up.hasValue() )
161 sal_Int32 up = 0;
162 if( Up >>= up )
163 downPages -= up;
164 else
165 messageBuffer += "Error getting parameter: Up\n";
167 if( ToRight.hasValue() )
169 sal_Int32 right = 0;
170 if( ToRight >>= right )
171 acrossPages += right;
172 else
173 messageBuffer += "Error getting parameter: ToRight\n";
175 if( ToLeft.hasValue() )
177 sal_Int32 left = 0;
178 if( ToLeft >>= left )
179 acrossPages -= left;
180 else
181 messageBuffer += "Error getting parameter: ToLeft\n";
183 if( !messageBuffer.isEmpty() )
184 throw uno::RuntimeException( messageBuffer );
186 sal_Int32 newStartRow = visibleRange.StartRow + (downPages * vertPageSize );
187 if( newStartRow < 0 )
188 newStartRow = 0;
189 sal_Int32 newStartCol = visibleRange.StartColumn + (acrossPages * horizPageSize );
190 if( newStartCol < 0 )
191 newStartCol = 0;
192 m_xViewPane->setFirstVisibleRow( newStartRow );
193 m_xViewPane->setFirstVisibleColumn( newStartCol );
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */