Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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"
25 :
26 : using namespace com::sun::star;
27 : using namespace ooo::vba;
28 :
29 60 : 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 60 : m_xContext(xContext)
38 : {
39 60 : }
40 :
41 : sal_Int32 SAL_CALL
42 8 : ScVbaPane::getScrollColumn() throw (uno::RuntimeException, std::exception)
43 : {
44 8 : return ( m_xViewPane->getFirstVisibleColumn() + 1 );
45 : }
46 :
47 : void SAL_CALL
48 2 : ScVbaPane::setScrollColumn( sal_Int32 _scrollcolumn ) throw (uno::RuntimeException, std::exception)
49 : {
50 2 : if( _scrollcolumn < 1 )
51 : {
52 0 : throw uno::RuntimeException("Column number should not less than 1" );
53 : }
54 2 : m_xViewPane->setFirstVisibleColumn( _scrollcolumn - 1 );
55 2 : }
56 :
57 : sal_Int32 SAL_CALL
58 6 : ScVbaPane::getScrollRow() throw (uno::RuntimeException, std::exception)
59 : {
60 6 : return ( m_xViewPane->getFirstVisibleRow() + 1 );
61 : }
62 :
63 : void SAL_CALL
64 2 : ScVbaPane::setScrollRow( sal_Int32 _scrollrow ) throw (uno::RuntimeException, std::exception)
65 : {
66 2 : if( _scrollrow < 1 )
67 : {
68 0 : throw uno::RuntimeException("Row number should not less than 1" );
69 : }
70 2 : m_xViewPane->setFirstVisibleRow( _scrollrow - 1 );
71 2 : }
72 :
73 : uno::Reference< excel::XRange > SAL_CALL
74 0 : ScVbaPane::getVisibleRange() throw (uno::RuntimeException, std::exception)
75 : {
76 : // TODO: Excel includes partly visible rows/columns, Calc does not
77 0 : table::CellRangeAddress aRangeAddr = m_xViewPane->getVisibleRange();
78 0 : uno::Reference< sheet::XSpreadsheetDocument > xDoc( m_xModel, uno::UNO_QUERY_THROW );
79 0 : uno::Reference< container::XIndexAccess > xSheetsIA( xDoc->getSheets(), uno::UNO_QUERY_THROW );
80 0 : uno::Reference< sheet::XSpreadsheet > xSheet( xSheetsIA->getByIndex( aRangeAddr.Sheet ), uno::UNO_QUERY_THROW );
81 0 : 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 0 : return new ScVbaRange( m_xParent, m_xContext, xRange );
84 : }
85 :
86 : //Method
87 : void SAL_CALL
88 4 : ScVbaPane::SmallScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException, std::exception)
89 : {
90 4 : OUString messageBuffer;
91 4 : sal_Int32 downRows = 0;
92 4 : sal_Int32 rightCols = 0;
93 4 : table::CellRangeAddress visibleRange = m_xViewPane->getVisibleRange();
94 :
95 4 : if( Down.hasValue() )
96 : {
97 0 : sal_Int32 down = 0;
98 0 : if( Down >>= down )
99 0 : downRows += down;
100 : else
101 0 : messageBuffer += OUString( "Error getting parameter: Down\n" );
102 : }
103 4 : if( Up.hasValue() )
104 : {
105 0 : sal_Int32 up = 0;
106 0 : if( Up >>= up )
107 0 : downRows -= up;
108 : else
109 0 : messageBuffer += OUString( "Error getting parameter: Up\n" );
110 : }
111 4 : if( ToRight.hasValue() )
112 : {
113 2 : sal_Int32 right = 0;
114 2 : if( ToRight >>= right )
115 2 : rightCols += right;
116 : else
117 0 : messageBuffer += OUString( "Error getting parameter: ToRight\n" );
118 : }
119 4 : if( ToLeft.hasValue() )
120 : {
121 2 : sal_Int32 left = 0;
122 2 : if( ToLeft >>= left )
123 2 : rightCols -= left;
124 : else
125 0 : messageBuffer += OUString( "Error getting parameter: ToLeft\n" );
126 : }
127 4 : if( !messageBuffer.isEmpty() )
128 0 : throw uno::RuntimeException( messageBuffer );
129 :
130 4 : sal_Int32 newStartRow = visibleRange.StartRow + downRows;
131 4 : if( newStartRow < 0 )
132 0 : newStartRow = 0;
133 4 : sal_Int32 newStartCol = visibleRange.StartColumn + rightCols;
134 4 : if( newStartCol < 0 )
135 0 : newStartCol = 0;
136 4 : m_xViewPane->setFirstVisibleRow( newStartRow );
137 4 : m_xViewPane->setFirstVisibleColumn( newStartCol );
138 4 : }
139 :
140 : void SAL_CALL
141 8 : ScVbaPane::LargeScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException, std::exception)
142 : {
143 8 : OUString messageBuffer;
144 8 : table::CellRangeAddress visibleRange = m_xViewPane->getVisibleRange();
145 :
146 8 : sal_Int32 vertPageSize = 1 + visibleRange.EndRow - visibleRange.StartRow;
147 8 : sal_Int32 horizPageSize = 1 + visibleRange.EndColumn - visibleRange.StartColumn;
148 8 : sal_Int32 downPages = 0;
149 8 : sal_Int32 acrossPages = 0;
150 8 : if( Down.hasValue() )
151 : {
152 2 : sal_Int32 down = 0;
153 2 : if( Down >>= down )
154 2 : downPages += down;
155 : else
156 0 : messageBuffer += OUString( "Error getting parameter: Down\n" );
157 : }
158 8 : if( Up.hasValue() )
159 : {
160 2 : sal_Int32 up = 0;
161 2 : if( Up >>= up )
162 2 : downPages -= up;
163 : else
164 0 : messageBuffer += OUString( "Error getting parameter: Up\n" );
165 : }
166 8 : if( ToRight.hasValue() )
167 : {
168 2 : sal_Int32 right = 0;
169 2 : if( ToRight >>= right )
170 2 : acrossPages += right;
171 : else
172 0 : messageBuffer += OUString( "Error getting parameter: ToRight\n" );
173 : }
174 8 : if( ToLeft.hasValue() )
175 : {
176 2 : sal_Int32 left = 0;
177 2 : if( ToLeft >>= left )
178 2 : acrossPages -= left;
179 : else
180 0 : messageBuffer += OUString( "Error getting parameter: ToLeft\n" );
181 : }
182 8 : if( !messageBuffer.isEmpty() )
183 0 : throw uno::RuntimeException( messageBuffer );
184 :
185 8 : sal_Int32 newStartRow = visibleRange.StartRow + (downPages * vertPageSize );
186 8 : if( newStartRow < 0 )
187 0 : newStartRow = 0;
188 8 : sal_Int32 newStartCol = visibleRange.StartColumn + (acrossPages * horizPageSize );
189 8 : if( newStartCol < 0 )
190 0 : newStartCol = 0;
191 8 : m_xViewPane->setFirstVisibleRow( newStartRow );
192 8 : m_xViewPane->setFirstVisibleColumn( newStartCol );
193 17 : }
194 :
195 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|