1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "vbapane.hxx" 29 #include <com/sun/star/sheet/XSpreadsheet.hpp> 30 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp> 31 #include <com/sun/star/table/CellRangeAddress.hpp> 32 #include "vbarange.hxx" 33 34 using namespace com::sun::star; 35 using namespace ooo::vba; 36 37 ScVbaPane::ScVbaPane( 38 const css::uno::Reference< ov::XHelperInterface >& xParent, 39 const uno::Reference< uno::XComponentContext >& xContext, 40 const uno::Reference< frame::XModel >& xModel, 41 const uno::Reference< sheet::XViewPane > xViewPane ) throw (uno::RuntimeException) : 42 ScVbaPane_BASE( xParent, xContext ), 43 m_xModel( xModel, uno::UNO_SET_THROW ), 44 m_xViewPane( xViewPane, uno::UNO_SET_THROW ) 45 { 46 } 47 48 sal_Int32 SAL_CALL 49 ScVbaPane::getScrollColumn() throw (uno::RuntimeException) 50 { 51 return ( m_xViewPane->getFirstVisibleColumn() + 1 ); 52 } 53 54 void SAL_CALL 55 ScVbaPane::setScrollColumn( sal_Int32 _scrollcolumn ) throw (uno::RuntimeException) 56 { 57 if( _scrollcolumn < 1 ) 58 { 59 throw uno::RuntimeException( rtl::OUString::createFromAscii( "Column number should not less than 1" ), 60 uno::Reference< uno::XInterface >() ); 61 } 62 m_xViewPane->setFirstVisibleColumn( _scrollcolumn - 1 ); 63 } 64 65 sal_Int32 SAL_CALL 66 ScVbaPane::getScrollRow() throw (uno::RuntimeException) 67 { 68 return ( m_xViewPane->getFirstVisibleRow() + 1 ); 69 } 70 71 void SAL_CALL 72 ScVbaPane::setScrollRow( sal_Int32 _scrollrow ) throw (uno::RuntimeException) 73 { 74 if( _scrollrow < 1 ) 75 { 76 throw uno::RuntimeException( rtl::OUString::createFromAscii( "Row number should not less than 1" ), 77 uno::Reference< uno::XInterface >() ); 78 } 79 m_xViewPane->setFirstVisibleRow( _scrollrow - 1 ); 80 } 81 82 uno::Reference< excel::XRange > SAL_CALL 83 ScVbaPane::getVisibleRange() throw (uno::RuntimeException) 84 { 85 // TODO: Excel includes partly visible rows/columns, Calc does not 86 table::CellRangeAddress aRangeAddr = m_xViewPane->getVisibleRange(); 87 uno::Reference< sheet::XSpreadsheetDocument > xDoc( m_xModel, uno::UNO_QUERY_THROW ); 88 uno::Reference< container::XIndexAccess > xSheetsIA( xDoc->getSheets(), uno::UNO_QUERY_THROW ); 89 uno::Reference< sheet::XSpreadsheet > xSheet( xSheetsIA->getByIndex( aRangeAddr.Sheet ), uno::UNO_QUERY_THROW ); 90 uno::Reference< table::XCellRange > xRange( xSheet->getCellRangeByPosition( aRangeAddr.StartColumn, aRangeAddr.StartRow, aRangeAddr.EndColumn, aRangeAddr.EndRow ), uno::UNO_SET_THROW ); 91 // TODO: getParent() returns the window, Range needs the worksheet 92 return new ScVbaRange( getParent(), mxContext, xRange ); 93 } 94 95 //Method 96 void SAL_CALL 97 ScVbaPane::SmallScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException) 98 { 99 rtl::OUString messageBuffer; 100 sal_Int32 downRows = 0; 101 sal_Int32 rightCols = 0; 102 table::CellRangeAddress visibleRange = m_xViewPane->getVisibleRange(); 103 104 if( Down.hasValue() ) 105 { 106 sal_Int32 down = 0; 107 if( Down >>= down ) 108 downRows += down; 109 else 110 messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: Down\n" ); 111 } 112 if( Up.hasValue() ) 113 { 114 sal_Int32 up = 0; 115 if( Up >>= up ) 116 downRows -= up; 117 else 118 messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: Up\n" ); 119 } 120 if( ToRight.hasValue() ) 121 { 122 sal_Int32 right = 0; 123 if( ToRight >>= right ) 124 rightCols += right; 125 else 126 messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: ToRight\n" ); 127 } 128 if( ToLeft.hasValue() ) 129 { 130 sal_Int32 left = 0; 131 if( ToLeft >>= left ) 132 rightCols -= left; 133 else 134 messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: ToLeft\n" ); 135 } 136 if( messageBuffer.getLength() > 0 ) 137 throw(uno::RuntimeException( messageBuffer, uno::Reference< uno::XInterface >() ) ); 138 139 sal_Int32 newStartRow = visibleRange.StartRow + downRows; 140 if( newStartRow < 0 ) 141 newStartRow = 0; 142 sal_Int32 newStartCol = visibleRange.StartColumn + rightCols; 143 if( newStartCol < 0 ) 144 newStartCol = 0; 145 m_xViewPane->setFirstVisibleRow( newStartRow ); 146 m_xViewPane->setFirstVisibleColumn( newStartCol ); 147 } 148 149 void SAL_CALL 150 ScVbaPane::LargeScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException) 151 { 152 rtl::OUString messageBuffer; 153 table::CellRangeAddress visibleRange = m_xViewPane->getVisibleRange(); 154 155 sal_Int32 vertPageSize = 1 + visibleRange.EndRow - visibleRange.StartRow; 156 sal_Int32 horizPageSize = 1 + visibleRange.EndColumn - visibleRange.StartColumn; 157 sal_Int32 downPages = 0; 158 sal_Int32 acrossPages = 0; 159 if( Down.hasValue() ) 160 { 161 sal_Int32 down = 0; 162 if( Down >>= down ) 163 downPages += down; 164 else 165 messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: Down\n" ); 166 } 167 if( Up.hasValue() ) 168 { 169 sal_Int32 up = 0; 170 if( Up >>= up ) 171 downPages -= up; 172 else 173 messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: Up\n" ); 174 } 175 if( ToRight.hasValue() ) 176 { 177 sal_Int32 right = 0; 178 if( ToRight >>= right ) 179 acrossPages += right; 180 else 181 messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: ToRight\n" ); 182 } 183 if( ToLeft.hasValue() ) 184 { 185 sal_Int32 left = 0; 186 if( ToLeft >>= left ) 187 acrossPages -= left; 188 else 189 messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: ToLeft\n" ); 190 } 191 if( messageBuffer.getLength() > 0 ) 192 throw(uno::RuntimeException( messageBuffer, uno::Reference< uno::XInterface >() ) ); 193 194 sal_Int32 newStartRow = visibleRange.StartRow + (downPages * vertPageSize ); 195 if( newStartRow < 0 ) 196 newStartRow = 0; 197 sal_Int32 newStartCol = visibleRange.StartColumn + (acrossPages * horizPageSize ); 198 if( newStartCol < 0 ) 199 newStartCol = 0; 200 m_xViewPane->setFirstVisibleRow( newStartRow ); 201 m_xViewPane->setFirstVisibleColumn( newStartCol ); 202 } 203 204 // XHelperInterface 205 206 VBAHELPER_IMPL_XHELPERINTERFACE( ScVbaPane, "ooo.vba.excel.Pane" ) 207