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/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
;
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
),
42 ScVbaPane::getScrollColumn() throw (uno::RuntimeException
, std::exception
)
44 return ( m_xViewPane
->getFirstVisibleColumn() + 1 );
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 );
58 ScVbaPane::getScrollRow() throw (uno::RuntimeException
, std::exception
)
60 return ( m_xViewPane
->getFirstVisibleRow() + 1 );
64 ScVbaPane::setScrollRow( sal_Int32 _scrollrow
) throw (uno::RuntimeException
, std::exception
)
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
);
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();
101 messageBuffer
+= OUString( "Error getting parameter: Down\n" );
109 messageBuffer
+= OUString( "Error getting parameter: Up\n" );
111 if( ToRight
.hasValue() )
114 if( ToRight
>>= right
)
117 messageBuffer
+= OUString( "Error getting parameter: ToRight\n" );
119 if( ToLeft
.hasValue() )
122 if( ToLeft
>>= left
)
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 )
133 sal_Int32 newStartCol
= visibleRange
.StartColumn
+ rightCols
;
134 if( newStartCol
< 0 )
136 m_xViewPane
->setFirstVisibleRow( newStartRow
);
137 m_xViewPane
->setFirstVisibleColumn( newStartCol
);
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() )
156 messageBuffer
+= OUString( "Error getting parameter: Down\n" );
164 messageBuffer
+= OUString( "Error getting parameter: Up\n" );
166 if( ToRight
.hasValue() )
169 if( ToRight
>>= right
)
170 acrossPages
+= right
;
172 messageBuffer
+= OUString( "Error getting parameter: ToRight\n" );
174 if( ToLeft
.hasValue() )
177 if( ToLeft
>>= left
)
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 )
188 sal_Int32 newStartCol
= visibleRange
.StartColumn
+ (acrossPages
* horizPageSize
);
189 if( newStartCol
< 0 )
191 m_xViewPane
->setFirstVisibleRow( newStartRow
);
192 m_xViewPane
->setFirstVisibleColumn( newStartCol
);
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */