fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / vba / vbapane.cxx
blobdb9c0e9739b3dc06b64901cd3a232711d46fde67
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/sheet/XSpreadsheet.hpp>
22 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
23 #include <com/sun/star/table/CellRangeAddress.hpp>
24 #include "vbarange.hxx"
26 using namespace com::sun::star;
27 using namespace ooo::vba;
29 ScVbaPane::ScVbaPane(
30 const css::uno::Reference< ov::XHelperInterface >& xParent,
31 const uno::Reference< uno::XComponentContext >& xContext,
32 const uno::Reference< frame::XModel >& rModel,
33 const uno::Reference< sheet::XViewPane >& rViewPane ) throw (uno::RuntimeException) :
34 m_xModel(rModel, uno::UNO_SET_THROW),
35 m_xViewPane(rViewPane, uno::UNO_SET_THROW),
36 m_xParent(xParent),
37 m_xContext(xContext)
41 sal_Int32 SAL_CALL
42 ScVbaPane::getScrollColumn() throw (uno::RuntimeException, std::exception)
44 return ( m_xViewPane->getFirstVisibleColumn() + 1 );
47 void SAL_CALL
48 ScVbaPane::setScrollColumn( sal_Int32 _scrollcolumn ) throw (uno::RuntimeException, std::exception)
50 if( _scrollcolumn < 1 )
52 throw uno::RuntimeException("Column number should not less than 1" );
54 m_xViewPane->setFirstVisibleColumn( _scrollcolumn - 1 );
57 sal_Int32 SAL_CALL
58 ScVbaPane::getScrollRow() throw (uno::RuntimeException, std::exception)
60 return ( m_xViewPane->getFirstVisibleRow() + 1 );
63 void SAL_CALL
64 ScVbaPane::setScrollRow( sal_Int32 _scrollrow ) throw (uno::RuntimeException, std::exception)
66 if( _scrollrow < 1 )
68 throw uno::RuntimeException("Row number should not less than 1" );
70 m_xViewPane->setFirstVisibleRow( _scrollrow - 1 );
73 uno::Reference< excel::XRange > SAL_CALL
74 ScVbaPane::getVisibleRange() throw (uno::RuntimeException, std::exception)
76 // TODO: Excel includes partly visible rows/columns, Calc does not
77 table::CellRangeAddress aRangeAddr = m_xViewPane->getVisibleRange();
78 uno::Reference< sheet::XSpreadsheetDocument > xDoc( m_xModel, uno::UNO_QUERY_THROW );
79 uno::Reference< container::XIndexAccess > xSheetsIA( xDoc->getSheets(), uno::UNO_QUERY_THROW );
80 uno::Reference< sheet::XSpreadsheet > xSheet( xSheetsIA->getByIndex( aRangeAddr.Sheet ), uno::UNO_QUERY_THROW );
81 uno::Reference< table::XCellRange > xRange( xSheet->getCellRangeByPosition( aRangeAddr.StartColumn, aRangeAddr.StartRow, aRangeAddr.EndColumn, aRangeAddr.EndRow ), uno::UNO_SET_THROW );
82 // TODO: m_xParent is the window, Range needs the worksheet
83 return new ScVbaRange( m_xParent, m_xContext, xRange );
86 //Method
87 void SAL_CALL
88 ScVbaPane::SmallScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException, std::exception)
90 OUString messageBuffer;
91 sal_Int32 downRows = 0;
92 sal_Int32 rightCols = 0;
93 table::CellRangeAddress visibleRange = m_xViewPane->getVisibleRange();
95 if( Down.hasValue() )
97 sal_Int32 down = 0;
98 if( Down >>= down )
99 downRows += down;
100 else
101 messageBuffer += OUString( "Error getting parameter: Down\n" );
103 if( Up.hasValue() )
105 sal_Int32 up = 0;
106 if( Up >>= up )
107 downRows -= up;
108 else
109 messageBuffer += OUString( "Error getting parameter: Up\n" );
111 if( ToRight.hasValue() )
113 sal_Int32 right = 0;
114 if( ToRight >>= right )
115 rightCols += right;
116 else
117 messageBuffer += OUString( "Error getting parameter: ToRight\n" );
119 if( ToLeft.hasValue() )
121 sal_Int32 left = 0;
122 if( ToLeft >>= left )
123 rightCols -= left;
124 else
125 messageBuffer += OUString( "Error getting parameter: ToLeft\n" );
127 if( !messageBuffer.isEmpty() )
128 throw uno::RuntimeException( messageBuffer );
130 sal_Int32 newStartRow = visibleRange.StartRow + downRows;
131 if( newStartRow < 0 )
132 newStartRow = 0;
133 sal_Int32 newStartCol = visibleRange.StartColumn + rightCols;
134 if( newStartCol < 0 )
135 newStartCol = 0;
136 m_xViewPane->setFirstVisibleRow( newStartRow );
137 m_xViewPane->setFirstVisibleColumn( newStartCol );
140 void SAL_CALL
141 ScVbaPane::LargeScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException, std::exception)
143 OUString messageBuffer;
144 table::CellRangeAddress visibleRange = m_xViewPane->getVisibleRange();
146 sal_Int32 vertPageSize = 1 + visibleRange.EndRow - visibleRange.StartRow;
147 sal_Int32 horizPageSize = 1 + visibleRange.EndColumn - visibleRange.StartColumn;
148 sal_Int32 downPages = 0;
149 sal_Int32 acrossPages = 0;
150 if( Down.hasValue() )
152 sal_Int32 down = 0;
153 if( Down >>= down )
154 downPages += down;
155 else
156 messageBuffer += OUString( "Error getting parameter: Down\n" );
158 if( Up.hasValue() )
160 sal_Int32 up = 0;
161 if( Up >>= up )
162 downPages -= up;
163 else
164 messageBuffer += OUString( "Error getting parameter: Up\n" );
166 if( ToRight.hasValue() )
168 sal_Int32 right = 0;
169 if( ToRight >>= right )
170 acrossPages += right;
171 else
172 messageBuffer += OUString( "Error getting parameter: ToRight\n" );
174 if( ToLeft.hasValue() )
176 sal_Int32 left = 0;
177 if( ToLeft >>= left )
178 acrossPages -= left;
179 else
180 messageBuffer += OUString( "Error getting parameter: ToLeft\n" );
182 if( !messageBuffer.isEmpty() )
183 throw uno::RuntimeException( messageBuffer );
185 sal_Int32 newStartRow = visibleRange.StartRow + (downPages * vertPageSize );
186 if( newStartRow < 0 )
187 newStartRow = 0;
188 sal_Int32 newStartCol = visibleRange.StartColumn + (acrossPages * horizPageSize );
189 if( newStartCol < 0 )
190 newStartCol = 0;
191 m_xViewPane->setFirstVisibleRow( newStartRow );
192 m_xViewPane->setFirstVisibleColumn( newStartCol );
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */