1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
26 #include "vbarange.hxx"
28 using namespace com::sun::star
;
29 using namespace ooo::vba
;
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
),
39 m_xContext(std::move(xContext
))
44 ScVbaPane::getScrollColumn()
46 return ( m_xViewPane
->getFirstVisibleColumn() + 1 );
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 );
60 ScVbaPane::getScrollRow()
62 return ( m_xViewPane
->getFirstVisibleRow() + 1 );
66 ScVbaPane::setScrollRow( sal_Int32 _scrollrow
)
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
);
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();
103 messageBuffer
+= "Error getting parameter: Down\n";
111 messageBuffer
+= "Error getting parameter: Up\n";
113 if( ToRight
.hasValue() )
116 if( ToRight
>>= right
)
119 messageBuffer
+= "Error getting parameter: ToRight\n";
121 if( ToLeft
.hasValue() )
124 if( ToLeft
>>= left
)
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 )
135 sal_Int32 newStartCol
= visibleRange
.StartColumn
+ rightCols
;
136 if( newStartCol
< 0 )
138 m_xViewPane
->setFirstVisibleRow( newStartRow
);
139 m_xViewPane
->setFirstVisibleColumn( newStartCol
);
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() )
158 messageBuffer
+= "Error getting parameter: Down\n";
166 messageBuffer
+= "Error getting parameter: Up\n";
168 if( ToRight
.hasValue() )
171 if( ToRight
>>= right
)
172 acrossPages
+= right
;
174 messageBuffer
+= "Error getting parameter: ToRight\n";
176 if( ToLeft
.hasValue() )
179 if( ToLeft
>>= left
)
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 )
190 sal_Int32 newStartCol
= visibleRange
.StartColumn
+ (acrossPages
* horizPageSize
);
191 if( newStartCol
< 0 )
193 m_xViewPane
->setFirstVisibleRow( newStartRow
);
194 m_xViewPane
->setFirstVisibleColumn( newStartCol
);
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */