LibreOffice Module sc (master) 1
vbapane.cxx
Go to the documentation of this file.
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/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"
27
28using namespace com::sun::star;
29using namespace ooo::vba;
30
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))
40{
41}
42
43sal_Int32 SAL_CALL
45{
46 return ( m_xViewPane->getFirstVisibleColumn() + 1 );
47}
48
49void SAL_CALL
50ScVbaPane::setScrollColumn( sal_Int32 _scrollcolumn )
51{
52 if( _scrollcolumn < 1 )
53 {
54 throw uno::RuntimeException("Column number should not be less than 1" );
55 }
56 m_xViewPane->setFirstVisibleColumn( _scrollcolumn - 1 );
57}
58
59sal_Int32 SAL_CALL
61{
62 return ( m_xViewPane->getFirstVisibleRow() + 1 );
63}
64
65void SAL_CALL
66ScVbaPane::setScrollRow( sal_Int32 _scrollrow )
67{
68 if( _scrollrow < 1 )
69 {
70 throw uno::RuntimeException("Row number should not be less than 1" );
71 }
72 m_xViewPane->setFirstVisibleRow( _scrollrow - 1 );
73}
74
75uno::Reference< excel::XRange > SAL_CALL
77{
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 );
86}
87
88//Method
89void SAL_CALL
90ScVbaPane::SmallScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft )
91{
92 OUString messageBuffer;
93 sal_Int32 downRows = 0;
94 sal_Int32 rightCols = 0;
95 table::CellRangeAddress visibleRange = m_xViewPane->getVisibleRange();
96
97 if( Down.hasValue() )
98 {
99 sal_Int32 down = 0;
100 if( Down >>= down )
101 downRows += down;
102 else
103 messageBuffer += "Error getting parameter: Down\n";
104 }
105 if( Up.hasValue() )
106 {
107 sal_Int32 up = 0;
108 if( Up >>= up )
109 downRows -= up;
110 else
111 messageBuffer += "Error getting parameter: Up\n";
112 }
113 if( ToRight.hasValue() )
114 {
115 sal_Int32 right = 0;
116 if( ToRight >>= right )
117 rightCols += right;
118 else
119 messageBuffer += "Error getting parameter: ToRight\n";
120 }
121 if( ToLeft.hasValue() )
122 {
123 sal_Int32 left = 0;
124 if( ToLeft >>= left )
125 rightCols -= left;
126 else
127 messageBuffer += "Error getting parameter: ToLeft\n";
128 }
129 if( !messageBuffer.isEmpty() )
130 throw uno::RuntimeException( messageBuffer );
131
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 );
140}
141
142void SAL_CALL
143ScVbaPane::LargeScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft )
144{
145 OUString messageBuffer;
146 table::CellRangeAddress visibleRange = m_xViewPane->getVisibleRange();
147
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() )
153 {
154 sal_Int32 down = 0;
155 if( Down >>= down )
156 downPages += down;
157 else
158 messageBuffer += "Error getting parameter: Down\n";
159 }
160 if( Up.hasValue() )
161 {
162 sal_Int32 up = 0;
163 if( Up >>= up )
164 downPages -= up;
165 else
166 messageBuffer += "Error getting parameter: Up\n";
167 }
168 if( ToRight.hasValue() )
169 {
170 sal_Int32 right = 0;
171 if( ToRight >>= right )
172 acrossPages += right;
173 else
174 messageBuffer += "Error getting parameter: ToRight\n";
175 }
176 if( ToLeft.hasValue() )
177 {
178 sal_Int32 left = 0;
179 if( ToLeft >>= left )
180 acrossPages -= left;
181 else
182 messageBuffer += "Error getting parameter: ToLeft\n";
183 }
184 if( !messageBuffer.isEmpty() )
185 throw uno::RuntimeException( messageBuffer );
186
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 );
195}
196
197/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XComponentContext > m_xContext
virtual sal_Int32 SAL_CALL getScrollRow() override
Definition: vbapane.cxx:60
css::uno::Reference< css::frame::XModel > m_xModel
Definition: vbapane.hxx:49
virtual void SAL_CALL setScrollColumn(sal_Int32 _scrollcolumn) override
Definition: vbapane.cxx:50
virtual css::uno::Reference< ov::excel::XRange > SAL_CALL getVisibleRange() override
Definition: vbapane.cxx:76
css::uno::WeakReference< ov::XHelperInterface > m_xParent
Definition: vbapane.hxx:51
virtual void SAL_CALL SmallScroll(const css::uno::Any &Down, const css::uno::Any &Up, const css::uno::Any &ToRight, const css::uno::Any &ToLeft) override
Definition: vbapane.cxx:90
virtual sal_Int32 SAL_CALL getScrollColumn() override
Definition: vbapane.cxx:44
ScVbaPane(const css::uno::Reference< ov::XHelperInterface > &rParent, css::uno::Reference< css::uno::XComponentContext > xContext, const css::uno::Reference< css::frame::XModel > &rModel, const css::uno::Reference< css::sheet::XViewPane > &rViewPane)
Definition: vbapane.cxx:31
css::uno::Reference< css::sheet::XViewPane > m_xViewPane
Definition: vbapane.hxx:50
virtual void SAL_CALL setScrollRow(sal_Int32 _scrollrow) override
Definition: vbapane.cxx:66
virtual void SAL_CALL LargeScroll(const css::uno::Any &Down, const css::uno::Any &Up, const css::uno::Any &ToRight, const css::uno::Any &ToLeft) override
Definition: vbapane.cxx:143
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: vbapane.hxx:52
Reference< frame::XModel > m_xModel
OString right
DECL_LISTENERMULTIPLEXER_END void SAL_CALL up(const css::awt::SpinEvent &rEvent) override
void SAL_CALL down(const css::awt::SpinEvent &rEvent) override
bool hasValue()
sal_uInt64 left