tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / vba / vbapane.cxx
blob2edff464e2472e145a45938ceae608b4e910026e
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 <utility>
26 #include "vbarange.hxx"
28 using namespace com::sun::star;
29 using namespace ooo::vba;
31 ScVbaPane::ScVbaPane(
32 const css::uno::Reference< ov::XHelperInterface >& xParent,
33 uno::Reference< uno::XComponentContext > xContext,
34 const uno::Reference< frame::XModel >& rModel,
35 const uno::Reference< sheet::XViewPane >& rViewPane ) :
36 m_xModel(rModel, uno::UNO_SET_THROW),
37 m_xViewPane(rViewPane, uno::UNO_SET_THROW),
38 m_xParent(xParent),
39 m_xContext(std::move(xContext))
43 sal_Int32 SAL_CALL
44 ScVbaPane::getScrollColumn()
46 return ( m_xViewPane->getFirstVisibleColumn() + 1 );
49 void SAL_CALL
50 ScVbaPane::setScrollColumn( sal_Int32 _scrollcolumn )
52 if( _scrollcolumn < 1 )
54 throw uno::RuntimeException(u"Column number should not be less than 1"_ustr );
56 m_xViewPane->setFirstVisibleColumn( _scrollcolumn - 1 );
59 sal_Int32 SAL_CALL
60 ScVbaPane::getScrollRow()
62 return ( m_xViewPane->getFirstVisibleRow() + 1 );
65 void SAL_CALL
66 ScVbaPane::setScrollRow( sal_Int32 _scrollrow )
68 if( _scrollrow < 1 )
70 throw uno::RuntimeException(u"Row number should not be less than 1"_ustr );
72 m_xViewPane->setFirstVisibleRow( _scrollrow - 1 );
75 uno::Reference< excel::XRange > SAL_CALL
76 ScVbaPane::getVisibleRange()
78 // TODO: Excel includes partly visible rows/columns, Calc does not
79 table::CellRangeAddress aRangeAddr = m_xViewPane->getVisibleRange();
80 uno::Reference< sheet::XSpreadsheetDocument > xDoc( m_xModel, uno::UNO_QUERY_THROW );
81 uno::Reference< container::XIndexAccess > xSheetsIA( xDoc->getSheets(), uno::UNO_QUERY_THROW );
82 uno::Reference< sheet::XSpreadsheet > xSheet( xSheetsIA->getByIndex( aRangeAddr.Sheet ), uno::UNO_QUERY_THROW );
83 uno::Reference< table::XCellRange > xRange( xSheet->getCellRangeByPosition( aRangeAddr.StartColumn, aRangeAddr.StartRow, aRangeAddr.EndColumn, aRangeAddr.EndRow ), uno::UNO_SET_THROW );
84 // TODO: m_xParent is the window, Range needs the worksheet
85 return new ScVbaRange( m_xParent, m_xContext, xRange );
88 //Method
89 void SAL_CALL
90 ScVbaPane::SmallScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft )
92 OUString messageBuffer;
93 sal_Int32 downRows = 0;
94 sal_Int32 rightCols = 0;
95 table::CellRangeAddress visibleRange = m_xViewPane->getVisibleRange();
97 if( Down.hasValue() )
99 sal_Int32 down = 0;
100 if( Down >>= down )
101 downRows += down;
102 else
103 messageBuffer += "Error getting parameter: Down\n";
105 if( Up.hasValue() )
107 sal_Int32 up = 0;
108 if( Up >>= up )
109 downRows -= up;
110 else
111 messageBuffer += "Error getting parameter: Up\n";
113 if( ToRight.hasValue() )
115 sal_Int32 right = 0;
116 if( ToRight >>= right )
117 rightCols += right;
118 else
119 messageBuffer += "Error getting parameter: ToRight\n";
121 if( ToLeft.hasValue() )
123 sal_Int32 left = 0;
124 if( ToLeft >>= left )
125 rightCols -= left;
126 else
127 messageBuffer += "Error getting parameter: ToLeft\n";
129 if( !messageBuffer.isEmpty() )
130 throw uno::RuntimeException( messageBuffer );
132 sal_Int32 newStartRow = visibleRange.StartRow + downRows;
133 if( newStartRow < 0 )
134 newStartRow = 0;
135 sal_Int32 newStartCol = visibleRange.StartColumn + rightCols;
136 if( newStartCol < 0 )
137 newStartCol = 0;
138 m_xViewPane->setFirstVisibleRow( newStartRow );
139 m_xViewPane->setFirstVisibleColumn( newStartCol );
142 void SAL_CALL
143 ScVbaPane::LargeScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft )
145 OUString messageBuffer;
146 table::CellRangeAddress visibleRange = m_xViewPane->getVisibleRange();
148 sal_Int32 vertPageSize = 1 + visibleRange.EndRow - visibleRange.StartRow;
149 sal_Int32 horizPageSize = 1 + visibleRange.EndColumn - visibleRange.StartColumn;
150 sal_Int32 downPages = 0;
151 sal_Int32 acrossPages = 0;
152 if( Down.hasValue() )
154 sal_Int32 down = 0;
155 if( Down >>= down )
156 downPages += down;
157 else
158 messageBuffer += "Error getting parameter: Down\n";
160 if( Up.hasValue() )
162 sal_Int32 up = 0;
163 if( Up >>= up )
164 downPages -= up;
165 else
166 messageBuffer += "Error getting parameter: Up\n";
168 if( ToRight.hasValue() )
170 sal_Int32 right = 0;
171 if( ToRight >>= right )
172 acrossPages += right;
173 else
174 messageBuffer += "Error getting parameter: ToRight\n";
176 if( ToLeft.hasValue() )
178 sal_Int32 left = 0;
179 if( ToLeft >>= left )
180 acrossPages -= left;
181 else
182 messageBuffer += "Error getting parameter: ToLeft\n";
184 if( !messageBuffer.isEmpty() )
185 throw uno::RuntimeException( messageBuffer );
187 sal_Int32 newStartRow = visibleRange.StartRow + (downPages * vertPageSize );
188 if( newStartRow < 0 )
189 newStartRow = 0;
190 sal_Int32 newStartCol = visibleRange.StartColumn + (acrossPages * horizPageSize );
191 if( newStartCol < 0 )
192 newStartCol = 0;
193 m_xViewPane->setFirstVisibleRow( newStartRow );
194 m_xViewPane->setFirstVisibleColumn( newStartCol );
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */