merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / vba / vbapane.cxx
blobb7f53a19bb836583be80a3010042d32891b457dc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vbapane.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include<com/sun/star/table/CellRangeAddress.hpp>
31 #include<vbapane.hxx>
33 using namespace com::sun::star;
34 using namespace ooo::vba;
37 ScVbaPane::ScVbaPane( uno::Reference< uno::XComponentContext > xContext, uno::Refrence< sheet::XViewPane > xViewPane )
38 : m_xContext( xContext ), m_xViewPane( xViewPane )
43 sal_Int32 SAL_CALL
44 ScVbaPane::getScrollColumn() throw (uno::RuntimeException)
46 return ( m_xViewPane->getFirstVisibleColumn() + 1 );
49 void SAL_CALL
50 ScVbaPane::setScrollColumn( sal_Int32 _scrollcolumn ) throw (uno::RuntimeException)
52 if( _scrollcolumn < 1 )
54 throw uno::RuntimeException( rtl::OUString::createFromAscii( "Column number should not less than 1" ),
55 uno::Reference< uno::XInterface >() );
57 m_xViewPane->setFirstVisibleColumn( _scrollcolumn - 1 );
60 sal_Int32 SAL_CALL
61 ScVbaPane::getScrollRow() throw (uno::RuntimeException)
63 return ( m_xViewPane->getFirstVisibleRow() + 1 );
66 void SAL_CALL
67 ScVbaPane::setScrollRow( sal_Int32 _scrollrow ) throw (uno::RuntimeException)
69 if( _scrollrow < 1 )
71 throw uno::RuntimeException( rtl::OUString::createFromAscii( "Row number should not less than 1" ),
72 uno::Reference< uno::XInterface >() );
74 m_xViewPane->setFirstVisibleRow( _scrollrow - 1 );
77 //Method
78 void SAL_CALL
79 ScVbaPane::SmallScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException)
81 rtl::OUString messageBuffer;
82 sal_Int32 downRows = 0;
83 sal_Int32 rightCols = 0;
84 table::CellRangeAddress visibleRange = m_xViewPane->getVisibleRange();
86 if( Down.hasValue() )
88 sal_Int32 down = 0;
89 try
91 Down >>= down;
92 downRows += down;
94 catch ( uno::Exception )
96 messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: Down\n" );
99 if( Up.hasValue() )
101 sal_Int32 up = 0;
104 Up >>= up;
105 downRows -= up;
107 catch ( uno::Exception )
109 messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: Up\n" );
112 if( ToRight.hasValue() )
114 sal_Int32 right = 0;
117 ToRight >>= right;
118 rightCols += right;
120 catch ( uno::Exception )
122 messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: ToRight\n" );
125 if( ToLeft.hasValue() )
127 sal_Int32 left = 0;
130 ToLeft >>= left;
131 rightCols -= left;
133 catch ( uno::Exception )
135 messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: ToLeft\n" );
138 if( messageBuffer.getLength() > 0 )
139 throw(uno::RuntimeException( messageBuffer, uno::Reference< uno::XInterface >() ) );
141 sal_Int32 newStartRow = visibleRange.StartRow + downRows;
142 if( newStartRow < 0 )
143 newStartRow = 0;
144 sal_Int32 newStartCol = visibleRange.StartColumn + rightCols;
145 if( newStartCol < 0 )
146 newStartCol = 0;
147 m_xViewPane->setFirstVisibleRow( newStartRow );
148 m_xViewPane->setFirstVisibleColumn( newStartCol );
151 void SAL_CALL
152 ScVbaPane::LargeScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException)
154 rtl::OUString messageBuffer;
155 table::CellRangeAddress visibleRange = m_xViewPane->getVisibleRange();
157 sal_Int32 vertPageSize = 1 + visibleRange.EndRow - visibleRange.StartRow;
158 sal_Int32 horizPageSize = 1 + visibleRange.EndColumn - visibleRange.StartColumn;
159 sal_Int32 downPages = 0;
160 sal_Int32 acrossPages = 0;
161 if( Down.hasValue() )
163 sal_Int32 down = 0;
166 Down >>= down;
167 downPages += down;
169 catch ( uno::Exception )
171 messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: Down\n" );
174 if( Up.hasValue() )
176 sal_Int32 up = 0;
179 Up >>= up;
180 downPages -= up;
182 catch ( uno::Exception )
184 messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: Up\n" );
187 if( ToRight.hasValue() )
189 sal_Int32 right = 0;
192 ToRight >>= right;
193 acrossPages += right;
195 catch ( uno::Exception )
197 messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: ToRight\n" );
200 if( ToLeft.hasValue() )
202 sal_Int32 left = 0;
205 ToLeft >>= left;
206 acrossPages -= left;
208 catch ( uno::Exception )
210 messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: ToLeft\n" );
214 if( messageBuffer.getLength() > 0 )
215 throw(uno::RuntimeException( messageBuffer, uno::Reference< uno::XInterface >() ) );
217 sal_Int32 newStartRow = visibleRange.StartRow + (downPages * vertPageSize );
218 if( newStartRow < 0 )
219 newStartRow = 0;
220 sal_Int32 newStartCol = visibleRange.StartColumn + (acrossPages * horizPageSize );
221 if( newStartCol < 0 )
222 newStartCol = 0;
223 m_xViewPane->setFirstVisibleRow( newStartRow );
224 m_xViewPane->setFirstVisibleColumn( newStartCol );