xref: /aoo42x/main/sc/source/ui/vba/vbapane.cxx (revision b3f79822)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "vbapane.hxx"
25 #include <com/sun/star/sheet/XSpreadsheet.hpp>
26 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
27 #include <com/sun/star/table/CellRangeAddress.hpp>
28 #include "vbarange.hxx"
29 
30 using namespace com::sun::star;
31 using namespace ooo::vba;
32 
ScVbaPane(const css::uno::Reference<ov::XHelperInterface> & xParent,const uno::Reference<uno::XComponentContext> & xContext,const uno::Reference<frame::XModel> & xModel,const uno::Reference<sheet::XViewPane> xViewPane)33 ScVbaPane::ScVbaPane(
34         const css::uno::Reference< ov::XHelperInterface >& xParent,
35         const uno::Reference< uno::XComponentContext >& xContext,
36         const uno::Reference< frame::XModel >& xModel,
37         const uno::Reference< sheet::XViewPane > xViewPane ) throw (uno::RuntimeException) :
38     ScVbaPane_BASE( xParent, xContext ),
39     m_xModel( xModel, uno::UNO_SET_THROW ),
40     m_xViewPane( xViewPane, uno::UNO_SET_THROW )
41 {
42 }
43 
44 sal_Int32 SAL_CALL
getScrollColumn()45 ScVbaPane::getScrollColumn() throw (uno::RuntimeException)
46 {
47     return ( m_xViewPane->getFirstVisibleColumn() + 1 );
48 }
49 
50 void SAL_CALL
setScrollColumn(sal_Int32 _scrollcolumn)51 ScVbaPane::setScrollColumn( sal_Int32 _scrollcolumn ) throw (uno::RuntimeException)
52 {
53     if( _scrollcolumn < 1 )
54     {
55         throw uno::RuntimeException( rtl::OUString::createFromAscii( "Column number should not less than 1" ),
56                 uno::Reference< uno::XInterface >() );
57     }
58     m_xViewPane->setFirstVisibleColumn( _scrollcolumn - 1 );
59 }
60 
61 sal_Int32 SAL_CALL
getScrollRow()62 ScVbaPane::getScrollRow() throw (uno::RuntimeException)
63 {
64     return ( m_xViewPane->getFirstVisibleRow() + 1 );
65 }
66 
67 void SAL_CALL
setScrollRow(sal_Int32 _scrollrow)68 ScVbaPane::setScrollRow( sal_Int32 _scrollrow ) throw (uno::RuntimeException)
69 {
70     if( _scrollrow < 1 )
71     {
72         throw uno::RuntimeException( rtl::OUString::createFromAscii( "Row number should not less than 1" ),
73                 uno::Reference< uno::XInterface >() );
74     }
75     m_xViewPane->setFirstVisibleRow( _scrollrow - 1 );
76 }
77 
78 uno::Reference< excel::XRange > SAL_CALL
getVisibleRange()79 ScVbaPane::getVisibleRange() throw (uno::RuntimeException)
80 {
81     // TODO: Excel includes partly visible rows/columns, Calc does not
82     table::CellRangeAddress aRangeAddr = m_xViewPane->getVisibleRange();
83     uno::Reference< sheet::XSpreadsheetDocument > xDoc( m_xModel, uno::UNO_QUERY_THROW );
84     uno::Reference< container::XIndexAccess > xSheetsIA( xDoc->getSheets(), uno::UNO_QUERY_THROW );
85     uno::Reference< sheet::XSpreadsheet > xSheet( xSheetsIA->getByIndex( aRangeAddr.Sheet ), uno::UNO_QUERY_THROW );
86     uno::Reference< table::XCellRange > xRange( xSheet->getCellRangeByPosition( aRangeAddr.StartColumn, aRangeAddr.StartRow, aRangeAddr.EndColumn, aRangeAddr.EndRow ), uno::UNO_SET_THROW );
87     // TODO: getParent() returns the window, Range needs the worksheet
88 	return new ScVbaRange( getParent(), mxContext, xRange );
89 }
90 
91 //Method
92 void SAL_CALL
SmallScroll(const uno::Any & Down,const uno::Any & Up,const uno::Any & ToRight,const uno::Any & ToLeft)93 ScVbaPane::SmallScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException)
94 {
95     rtl::OUString messageBuffer;
96     sal_Int32 downRows = 0;
97     sal_Int32 rightCols = 0;
98     table::CellRangeAddress visibleRange = m_xViewPane->getVisibleRange();
99 
100     if( Down.hasValue() )
101     {
102         sal_Int32 down = 0;
103         if( Down >>= down )
104             downRows += down;
105         else
106             messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: Down\n" );
107     }
108     if( Up.hasValue() )
109     {
110         sal_Int32 up = 0;
111         if( Up >>= up )
112             downRows -= up;
113         else
114             messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: Up\n" );
115     }
116     if( ToRight.hasValue() )
117     {
118         sal_Int32 right = 0;
119         if( ToRight >>= right )
120             rightCols += right;
121         else
122             messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: ToRight\n" );
123     }
124     if( ToLeft.hasValue() )
125     {
126         sal_Int32 left = 0;
127         if( ToLeft >>= left )
128             rightCols -= left;
129         else
130             messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: ToLeft\n" );
131     }
132     if( messageBuffer.getLength() > 0 )
133         throw(uno::RuntimeException( messageBuffer, uno::Reference< uno::XInterface >() ) );
134 
135     sal_Int32 newStartRow = visibleRange.StartRow + downRows;
136     if( newStartRow < 0 )
137         newStartRow = 0;
138     sal_Int32 newStartCol = visibleRange.StartColumn + rightCols;
139     if( newStartCol < 0 )
140         newStartCol = 0;
141     m_xViewPane->setFirstVisibleRow( newStartRow );
142     m_xViewPane->setFirstVisibleColumn( newStartCol );
143 }
144 
145 void SAL_CALL
LargeScroll(const uno::Any & Down,const uno::Any & Up,const uno::Any & ToRight,const uno::Any & ToLeft)146 ScVbaPane::LargeScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException)
147 {
148     rtl::OUString messageBuffer;
149     table::CellRangeAddress visibleRange = m_xViewPane->getVisibleRange();
150 
151     sal_Int32 vertPageSize = 1 + visibleRange.EndRow - visibleRange.StartRow;
152     sal_Int32 horizPageSize = 1 + visibleRange.EndColumn - visibleRange.StartColumn;
153     sal_Int32 downPages = 0;
154     sal_Int32 acrossPages = 0;
155     if( Down.hasValue() )
156     {
157         sal_Int32 down = 0;
158         if( Down >>= down )
159             downPages += down;
160         else
161             messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: Down\n" );
162     }
163     if( Up.hasValue() )
164     {
165         sal_Int32 up = 0;
166         if( Up >>= up )
167             downPages -= up;
168         else
169             messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: Up\n" );
170     }
171     if( ToRight.hasValue() )
172     {
173         sal_Int32 right = 0;
174         if( ToRight >>= right )
175             acrossPages += right;
176         else
177             messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: ToRight\n" );
178     }
179     if( ToLeft.hasValue() )
180     {
181         sal_Int32 left = 0;
182         if( ToLeft >>= left )
183             acrossPages -= left;
184         else
185             messageBuffer += rtl::OUString::createFromAscii( "Error getting parameter: ToLeft\n" );
186     }
187     if( messageBuffer.getLength() > 0 )
188         throw(uno::RuntimeException( messageBuffer, uno::Reference< uno::XInterface >() ) );
189 
190     sal_Int32 newStartRow = visibleRange.StartRow + (downPages * vertPageSize );
191     if( newStartRow < 0 )
192         newStartRow = 0;
193     sal_Int32 newStartCol = visibleRange.StartColumn + (acrossPages * horizPageSize );
194     if( newStartCol < 0 )
195         newStartCol = 0;
196     m_xViewPane->setFirstVisibleRow( newStartRow );
197     m_xViewPane->setFirstVisibleColumn( newStartCol );
198 }
199 
200 // XHelperInterface
201 
202 VBAHELPER_IMPL_XHELPERINTERFACE( ScVbaPane, "ooo.vba.excel.Pane" )
203