LCOV - code coverage report
Current view: top level - sc/source/ui/vba - vbapane.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 69 98 70.4 %
Date: 2014-11-03 Functions: 9 10 90.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      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"
      25             : 
      26             : using namespace com::sun::star;
      27             : using namespace ooo::vba;
      28             : 
      29         120 : ScVbaPane::ScVbaPane(
      30             :         const css::uno::Reference< ov::XHelperInterface >& xParent,
      31             :         const uno::Reference< uno::XComponentContext >& xContext,
      32             :         const uno::Reference< frame::XModel >& xModel,
      33             :         const uno::Reference< sheet::XViewPane > xViewPane ) throw (uno::RuntimeException) :
      34             :     m_xModel( xModel, uno::UNO_SET_THROW ),
      35             :     m_xViewPane( xViewPane, uno::UNO_SET_THROW ),
      36             :     m_xParent(xParent),
      37         120 :     m_xContext(xContext)
      38             : {
      39         120 : }
      40             : 
      41             : sal_Int32 SAL_CALL
      42          16 : ScVbaPane::getScrollColumn() throw (uno::RuntimeException, std::exception)
      43             : {
      44          16 :     return ( m_xViewPane->getFirstVisibleColumn() + 1 );
      45             : }
      46             : 
      47             : void SAL_CALL
      48           4 : ScVbaPane::setScrollColumn( sal_Int32 _scrollcolumn ) throw (uno::RuntimeException, std::exception)
      49             : {
      50           4 :     if( _scrollcolumn < 1 )
      51             :     {
      52           0 :         throw uno::RuntimeException("Column number should not less than 1" );
      53             :     }
      54           4 :     m_xViewPane->setFirstVisibleColumn( _scrollcolumn - 1 );
      55           4 : }
      56             : 
      57             : sal_Int32 SAL_CALL
      58          12 : ScVbaPane::getScrollRow() throw (uno::RuntimeException, std::exception)
      59             : {
      60          12 :     return ( m_xViewPane->getFirstVisibleRow() + 1 );
      61             : }
      62             : 
      63             : void SAL_CALL
      64           4 : ScVbaPane::setScrollRow( sal_Int32 _scrollrow ) throw (uno::RuntimeException, std::exception)
      65             : {
      66           4 :     if( _scrollrow < 1 )
      67             :     {
      68           0 :         throw uno::RuntimeException("Row number should not less than 1" );
      69             :     }
      70           4 :     m_xViewPane->setFirstVisibleRow( _scrollrow - 1 );
      71           4 : }
      72             : 
      73             : uno::Reference< excel::XRange > SAL_CALL
      74           0 : ScVbaPane::getVisibleRange() throw (uno::RuntimeException, std::exception)
      75             : {
      76             :     // TODO: Excel includes partly visible rows/columns, Calc does not
      77           0 :     table::CellRangeAddress aRangeAddr = m_xViewPane->getVisibleRange();
      78           0 :     uno::Reference< sheet::XSpreadsheetDocument > xDoc( m_xModel, uno::UNO_QUERY_THROW );
      79           0 :     uno::Reference< container::XIndexAccess > xSheetsIA( xDoc->getSheets(), uno::UNO_QUERY_THROW );
      80           0 :     uno::Reference< sheet::XSpreadsheet > xSheet( xSheetsIA->getByIndex( aRangeAddr.Sheet ), uno::UNO_QUERY_THROW );
      81           0 :     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           0 :     return new ScVbaRange( m_xParent, m_xContext, xRange );
      84             : }
      85             : 
      86             : //Method
      87             : void SAL_CALL
      88           8 : ScVbaPane::SmallScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException, std::exception)
      89             : {
      90           8 :     OUString messageBuffer;
      91           8 :     sal_Int32 downRows = 0;
      92           8 :     sal_Int32 rightCols = 0;
      93           8 :     table::CellRangeAddress visibleRange = m_xViewPane->getVisibleRange();
      94             : 
      95           8 :     if( Down.hasValue() )
      96             :     {
      97           0 :         sal_Int32 down = 0;
      98           0 :         if( Down >>= down )
      99           0 :             downRows += down;
     100             :         else
     101           0 :             messageBuffer += OUString( "Error getting parameter: Down\n" );
     102             :     }
     103           8 :     if( Up.hasValue() )
     104             :     {
     105           0 :         sal_Int32 up = 0;
     106           0 :         if( Up >>= up )
     107           0 :             downRows -= up;
     108             :         else
     109           0 :             messageBuffer += OUString( "Error getting parameter: Up\n" );
     110             :     }
     111           8 :     if( ToRight.hasValue() )
     112             :     {
     113           4 :         sal_Int32 right = 0;
     114           4 :         if( ToRight >>= right )
     115           4 :             rightCols += right;
     116             :         else
     117           0 :             messageBuffer += OUString( "Error getting parameter: ToRight\n" );
     118             :     }
     119           8 :     if( ToLeft.hasValue() )
     120             :     {
     121           4 :         sal_Int32 left = 0;
     122           4 :         if( ToLeft >>= left )
     123           4 :             rightCols -= left;
     124             :         else
     125           0 :             messageBuffer += OUString( "Error getting parameter: ToLeft\n" );
     126             :     }
     127           8 :     if( !messageBuffer.isEmpty() )
     128           0 :         throw uno::RuntimeException( messageBuffer );
     129             : 
     130           8 :     sal_Int32 newStartRow = visibleRange.StartRow + downRows;
     131           8 :     if( newStartRow < 0 )
     132           0 :         newStartRow = 0;
     133           8 :     sal_Int32 newStartCol = visibleRange.StartColumn + rightCols;
     134           8 :     if( newStartCol < 0 )
     135           0 :         newStartCol = 0;
     136           8 :     m_xViewPane->setFirstVisibleRow( newStartRow );
     137           8 :     m_xViewPane->setFirstVisibleColumn( newStartCol );
     138           8 : }
     139             : 
     140             : void SAL_CALL
     141          16 : ScVbaPane::LargeScroll( const uno::Any& Down, const uno::Any& Up, const uno::Any& ToRight, const uno::Any& ToLeft ) throw (uno::RuntimeException, std::exception)
     142             : {
     143          16 :     OUString messageBuffer;
     144          16 :     table::CellRangeAddress visibleRange = m_xViewPane->getVisibleRange();
     145             : 
     146          16 :     sal_Int32 vertPageSize = 1 + visibleRange.EndRow - visibleRange.StartRow;
     147          16 :     sal_Int32 horizPageSize = 1 + visibleRange.EndColumn - visibleRange.StartColumn;
     148          16 :     sal_Int32 downPages = 0;
     149          16 :     sal_Int32 acrossPages = 0;
     150          16 :     if( Down.hasValue() )
     151             :     {
     152           4 :         sal_Int32 down = 0;
     153           4 :         if( Down >>= down )
     154           4 :             downPages += down;
     155             :         else
     156           0 :             messageBuffer += OUString( "Error getting parameter: Down\n" );
     157             :     }
     158          16 :     if( Up.hasValue() )
     159             :     {
     160           4 :         sal_Int32 up = 0;
     161           4 :         if( Up >>= up )
     162           4 :             downPages -= up;
     163             :         else
     164           0 :             messageBuffer += OUString( "Error getting parameter: Up\n" );
     165             :     }
     166          16 :     if( ToRight.hasValue() )
     167             :     {
     168           4 :         sal_Int32 right = 0;
     169           4 :         if( ToRight >>= right )
     170           4 :             acrossPages += right;
     171             :         else
     172           0 :             messageBuffer += OUString( "Error getting parameter: ToRight\n" );
     173             :     }
     174          16 :     if( ToLeft.hasValue() )
     175             :     {
     176           4 :         sal_Int32 left = 0;
     177           4 :         if( ToLeft >>= left )
     178           4 :             acrossPages -= left;
     179             :         else
     180           0 :             messageBuffer += OUString( "Error getting parameter: ToLeft\n" );
     181             :     }
     182          16 :     if( !messageBuffer.isEmpty() )
     183           0 :         throw uno::RuntimeException( messageBuffer );
     184             : 
     185          16 :     sal_Int32 newStartRow = visibleRange.StartRow + (downPages * vertPageSize );
     186          16 :     if( newStartRow < 0 )
     187           0 :         newStartRow = 0;
     188          16 :     sal_Int32 newStartCol = visibleRange.StartColumn + (acrossPages * horizPageSize );
     189          16 :     if( newStartCol < 0 )
     190           0 :         newStartCol = 0;
     191          16 :     m_xViewPane->setFirstVisibleRow( newStartRow );
     192          16 :     m_xViewPane->setFirstVisibleColumn( newStartCol );
     193          28 : }
     194             : 
     195             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10