LCOV - code coverage report
Current view: top level - sc/source/ui/vba - vbarange.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 443 3268 13.6 %
Date: 2012-08-25 Functions: 63 300 21.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 443 7186 6.2 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "vbarange.hxx"
      30                 :            : 
      31                 :            : #include <vbahelper/helperdecl.hxx>
      32                 :            : 
      33                 :            : #include <comphelper/unwrapargs.hxx>
      34                 :            : #include <comphelper/processfactory.hxx>
      35                 :            : #include <sfx2/objsh.hxx>
      36                 :            : 
      37                 :            : #include <com/sun/star/script/ArrayWrapper.hpp>
      38                 :            : #include <com/sun/star/script/vba/VBAEventId.hpp>
      39                 :            : #include <com/sun/star/script/vba/XVBAEventProcessor.hpp>
      40                 :            : #include <com/sun/star/sheet/XDatabaseRange.hpp>
      41                 :            : #include <com/sun/star/sheet/XUnnamedDatabaseRanges.hpp>
      42                 :            : #include <com/sun/star/sheet/XGoalSeek.hpp>
      43                 :            : #include <com/sun/star/sheet/XSheetOperation.hpp>
      44                 :            : #include <com/sun/star/sheet/CellFlags.hpp>
      45                 :            : #include <com/sun/star/table/XColumnRowRange.hpp>
      46                 :            : #include <com/sun/star/sheet/XCellAddressable.hpp>
      47                 :            : #include <com/sun/star/table/CellContentType.hpp>
      48                 :            : #include <com/sun/star/sheet/XCellSeries.hpp>
      49                 :            : #include <com/sun/star/text/XTextRange.hpp>
      50                 :            : #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
      51                 :            : #include <com/sun/star/table/CellRangeAddress.hpp>
      52                 :            : #include <com/sun/star/sheet/XSpreadsheetView.hpp>
      53                 :            : #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
      54                 :            : #include <com/sun/star/sheet/XSheetCellRange.hpp>
      55                 :            : #include <com/sun/star/sheet/XSpreadsheet.hpp>
      56                 :            : #include <com/sun/star/sheet/XSheetCellCursor.hpp>
      57                 :            : #include <com/sun/star/sheet/XArrayFormulaRange.hpp>
      58                 :            : #include <com/sun/star/sheet/XNamedRange.hpp>
      59                 :            : #include <com/sun/star/sheet/XNamedRanges.hpp>
      60                 :            : #include <com/sun/star/sheet/XPrintAreas.hpp>
      61                 :            : #include <com/sun/star/sheet/XCellRangesQuery.hpp>
      62                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      63                 :            : #include <com/sun/star/sheet/XFunctionAccess.hpp>
      64                 :            : #include <com/sun/star/frame/XModel.hpp>
      65                 :            : #include <com/sun/star/view/XSelectionSupplier.hpp>
      66                 :            : #include <com/sun/star/table/XCellCursor.hpp>
      67                 :            : #include <com/sun/star/table/XTableRows.hpp>
      68                 :            : #include <com/sun/star/table/XTableColumns.hpp>
      69                 :            : #include <com/sun/star/table/TableSortField.hpp>
      70                 :            : #include <com/sun/star/util/XMergeable.hpp>
      71                 :            : #include <com/sun/star/uno/XComponentContext.hpp>
      72                 :            : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
      73                 :            : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      74                 :            : #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
      75                 :            : #include <com/sun/star/util/XNumberFormats.hpp>
      76                 :            : #include <com/sun/star/util/NumberFormat.hpp>
      77                 :            : #include <com/sun/star/util/XNumberFormatTypes.hpp>
      78                 :            : #include <com/sun/star/util/XReplaceable.hpp>
      79                 :            : #include <com/sun/star/util/XSortable.hpp>
      80                 :            : #include <com/sun/star/sheet/XCellRangeMovement.hpp>
      81                 :            : #include <com/sun/star/sheet/XCellRangeData.hpp>
      82                 :            : #include <com/sun/star/sheet/FormulaResult.hpp>
      83                 :            : #include <com/sun/star/sheet/FilterOperator2.hpp>
      84                 :            : #include <com/sun/star/sheet/TableFilterField.hpp>
      85                 :            : #include <com/sun/star/sheet/TableFilterField2.hpp>
      86                 :            : #include <com/sun/star/sheet/XSheetFilterDescriptor2.hpp>
      87                 :            : #include <com/sun/star/sheet/XSheetFilterable.hpp>
      88                 :            : #include <com/sun/star/sheet/FilterConnection.hpp>
      89                 :            : #include <com/sun/star/util/CellProtection.hpp>
      90                 :            : #include <com/sun/star/util/TriState.hpp>
      91                 :            : 
      92                 :            : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
      93                 :            : #include <com/sun/star/awt/XDevice.hpp>
      94                 :            : 
      95                 :            : #include <com/sun/star/sheet/XSubTotalCalculatable.hpp>
      96                 :            : #include <com/sun/star/sheet/XSubTotalDescriptor.hpp>
      97                 :            : #include <com/sun/star/sheet/GeneralFunction.hpp>
      98                 :            : 
      99                 :            : #include <com/sun/star/sheet/XSheetAnnotationsSupplier.hpp>
     100                 :            : #include <com/sun/star/sheet/XSheetAnnotations.hpp>
     101                 :            : 
     102                 :            : #include <com/sun/star/sheet/XDataPilotTable.hpp>
     103                 :            : #include <com/sun/star/sheet/XDataPilotTable2.hpp>
     104                 :            : #include <com/sun/star/sheet/XDataPilotTablesSupplier.hpp>
     105                 :            : #include <com/sun/star/sheet/DataPilotTablePositionData.hpp>
     106                 :            : #include <com/sun/star/sheet/DataPilotTablePositionType.hpp>
     107                 :            : 
     108                 :            : #include <ooo/vba/excel/XlPasteSpecialOperation.hpp>
     109                 :            : #include <ooo/vba/excel/XlPasteType.hpp>
     110                 :            : #include <ooo/vba/excel/Constants.hpp>
     111                 :            : #include <ooo/vba/excel/XlFindLookIn.hpp>
     112                 :            : #include <ooo/vba/excel/XlLookAt.hpp>
     113                 :            : #include <ooo/vba/excel/XlSearchOrder.hpp>
     114                 :            : #include <ooo/vba/excel/XlSortOrder.hpp>
     115                 :            : #include <ooo/vba/excel/XlYesNoGuess.hpp>
     116                 :            : #include <ooo/vba/excel/XlSortOrientation.hpp>
     117                 :            : #include <ooo/vba/excel/XlSortMethod.hpp>
     118                 :            : #include <ooo/vba/excel/XlDirection.hpp>
     119                 :            : #include <ooo/vba/excel/XlSortDataOption.hpp>
     120                 :            : #include <ooo/vba/excel/XlDeleteShiftDirection.hpp>
     121                 :            : #include <ooo/vba/excel/XlInsertShiftDirection.hpp>
     122                 :            : #include <ooo/vba/excel/XlReferenceStyle.hpp>
     123                 :            : #include <ooo/vba/excel/XlBordersIndex.hpp>
     124                 :            : #include <ooo/vba/excel/XlPageBreak.hpp>
     125                 :            : #include <ooo/vba/excel/XlAutoFilterOperator.hpp>
     126                 :            : #include <ooo/vba/excel/XlAutoFillType.hpp>
     127                 :            : #include <ooo/vba/excel/XlTextParsingType.hpp>
     128                 :            : #include <ooo/vba/excel/XlTextQualifier.hpp>
     129                 :            : #include <ooo/vba/excel/XlCellType.hpp>
     130                 :            : #include <ooo/vba/excel/XlSpecialCellsValue.hpp>
     131                 :            : #include <ooo/vba/excel/XlConsolidationFunction.hpp>
     132                 :            : #include <ooo/vba/excel/XlSearchDirection.hpp>
     133                 :            : #include <ooo/vba/excel/XlColumnDataType.hpp>
     134                 :            : #include <ooo/vba/excel/XlFilterAction.hpp>
     135                 :            : 
     136                 :            : #include <scitems.hxx>
     137                 :            : #include <svl/srchitem.hxx>
     138                 :            : #include <cellsuno.hxx>
     139                 :            : #include <dbdata.hxx>
     140                 :            : #include "docfunc.hxx"
     141                 :            : #include <docuno.hxx>
     142                 :            : 
     143                 :            : #include <sfx2/dispatch.hxx>
     144                 :            : #include <sfx2/app.hxx>
     145                 :            : #include <sfx2/bindings.hxx>
     146                 :            : #include <sfx2/request.hxx>
     147                 :            : #include <sfx2/viewfrm.hxx>
     148                 :            : #include <sfx2/itemwrapper.hxx>
     149                 :            : #include <sc.hrc>
     150                 :            : #include <globstr.hrc>
     151                 :            : #include <unonames.hxx>
     152                 :            : #include <tools/stream.hxx>
     153                 :            : 
     154                 :            : #include "vbaapplication.hxx"
     155                 :            : #include "vbafont.hxx"
     156                 :            : #include "vbacomment.hxx"
     157                 :            : #include "vbainterior.hxx"
     158                 :            : #include "vbacharacters.hxx"
     159                 :            : #include "vbaborders.hxx"
     160                 :            : #include "vbaworksheet.hxx"
     161                 :            : #include "vbavalidation.hxx"
     162                 :            : #include "vbahyperlinks.hxx"
     163                 :            : 
     164                 :            : #include "vbapivottable.hxx"
     165                 :            : 
     166                 :            : #include "asciiopt.hxx"
     167                 :            : #include "impex.hxx"
     168                 :            : #include "tabvwsh.hxx"
     169                 :            : #include "rangelst.hxx"
     170                 :            : #include "rangenam.hxx"
     171                 :            : #include "convuno.hxx"
     172                 :            : #include "compiler.hxx"
     173                 :            : #include "attrib.hxx"
     174                 :            : #include "undodat.hxx"
     175                 :            : #include "dbdocfun.hxx"
     176                 :            : #include "patattr.hxx"
     177                 :            : #include "olinetab.hxx"
     178                 :            : #include "transobj.hxx"
     179                 :            : #include "queryentry.hxx"
     180                 :            : #include "markdata.hxx"
     181                 :            : #include <comphelper/anytostring.hxx>
     182                 :            : 
     183                 :            : #include <global.hxx>
     184                 :            : 
     185                 :            : #include "vbaglobals.hxx"
     186                 :            : #include "vbastyle.hxx"
     187                 :            : #include "vbaname.hxx"
     188                 :            : #include "vbanames.hxx"
     189                 :            : #include <vector>
     190                 :            : #include <vbahelper/vbacollectionimpl.hxx>
     191                 :            : // begin test includes
     192                 :            : #include <com/sun/star/sheet/FunctionArgument.hpp>
     193                 :            : // end test includes
     194                 :            : 
     195                 :            : #include <ooo/vba/excel/Range.hpp>
     196                 :            : #include <com/sun/star/bridge/oleautomation/Date.hpp>
     197                 :            : 
     198                 :            : using namespace ::ooo::vba;
     199                 :            : using namespace ::com::sun::star;
     200                 :            : using ::std::vector;
     201                 :            : 
     202                 :            : // difference between VBA and file format width, in character units
     203                 :            : const double fExtraWidth = 182.0 / 256.0;
     204                 :            : 
     205                 :            : //    * 1 point = 1/72 inch = 20 twips
     206                 :            : //    * 1 inch = 72 points = 1440 twips
     207                 :            : //    * 1 cm = 567 twips
     208                 :          0 : double lcl_hmmToPoints( double nVal ) { return ( (double)((nVal /1000 ) * 567 ) / 20 ); }
     209                 :            : 
     210                 :            : static const sal_Int16 supportedIndexTable[] = {  excel::XlBordersIndex::xlEdgeLeft, excel::XlBordersIndex::xlEdgeTop, excel::XlBordersIndex::xlEdgeBottom, excel::XlBordersIndex::xlEdgeRight, excel::XlBordersIndex::xlDiagonalDown, excel::XlBordersIndex::xlDiagonalUp, excel::XlBordersIndex::xlInsideVertical, excel::XlBordersIndex::xlInsideHorizontal };
     211                 :            : 
     212                 :          0 : sal_uInt16 lcl_pointsToTwips( double nVal )
     213                 :            : {
     214                 :          0 :     nVal = nVal * static_cast<double>(20);
     215                 :          0 :     short nTwips = static_cast<short>(nVal);
     216                 :          0 :     return nTwips;
     217                 :            : }
     218                 :          0 : double lcl_TwipsToPoints( sal_uInt16 nVal )
     219                 :            : {
     220                 :          0 :     double nPoints = nVal;
     221                 :          0 :     return nPoints / 20;
     222                 :            : }
     223                 :            : 
     224                 :          0 : double lcl_Round2DecPlaces( double nVal )
     225                 :            : {
     226                 :          0 :     nVal  = (nVal * (double)100);
     227                 :          0 :     long tmp = static_cast<long>(nVal);
     228         [ #  # ]:          0 :     if ( ( ( nVal - tmp ) >= 0.5 ) )
     229                 :          0 :         ++tmp;
     230                 :          0 :     nVal = tmp;
     231                 :          0 :     nVal = nVal/100;
     232                 :          0 :     return nVal;
     233                 :            : }
     234                 :            : 
     235                 :          6 : uno::Any lcl_makeRange( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Any aAny, bool bIsRows, bool bIsColumns )
     236                 :            : {
     237         [ +  - ]:          6 :     uno::Reference< table::XCellRange > xCellRange( aAny, uno::UNO_QUERY_THROW );
     238 [ +  - ][ +  - ]:          6 :     return uno::makeAny( uno::Reference< excel::XRange >( new ScVbaRange( xParent, xContext, xCellRange, bIsRows, bIsColumns ) ) );
         [ +  - ][ +  - ]
     239                 :            : }
     240                 :            : 
     241                 :          0 : uno::Reference< excel::XRange > lcl_makeXRangeFromSheetCellRanges( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< sheet::XSheetCellRanges >& xLocSheetCellRanges, ScDocShell* pDoc )
     242                 :            : {
     243                 :          0 :     uno::Reference< excel::XRange > xRange;
     244 [ #  # ][ #  # ]:          0 :     uno::Sequence< table::CellRangeAddress  > sAddresses = xLocSheetCellRanges->getRangeAddresses();
     245         [ #  # ]:          0 :     ScRangeList aCellRanges;
     246                 :          0 :     sal_Int32 nLen = sAddresses.getLength();
     247         [ #  # ]:          0 :     if ( nLen )
     248                 :            :            {
     249         [ #  # ]:          0 :     for ( sal_Int32 index = 0; index < nLen; ++index )
     250                 :            :     {
     251                 :          0 :         ScRange refRange;
     252         [ #  # ]:          0 :         ScUnoConversion::FillScRange( refRange, sAddresses[ index ] );
     253         [ #  # ]:          0 :         aCellRanges.Append( refRange );
     254                 :            :     }
     255                 :            :     // Single range
     256 [ #  # ][ #  # ]:          0 :     if ( aCellRanges.size() == 1 )
     257                 :            :     {
     258 [ #  # ][ #  # ]:          0 :         uno::Reference< table::XCellRange > xTmpRange( new ScCellRangeObj( pDoc, *aCellRanges.front() ) );
         [ #  # ][ #  # ]
     259 [ #  # ][ #  # ]:          0 :         xRange = new ScVbaRange( xParent, xContext, xTmpRange );
                 [ #  # ]
     260                 :            :     }
     261                 :            :     else
     262                 :            :     {
     263 [ #  # ][ #  # ]:          0 :         uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( pDoc, aCellRanges ) );
                 [ #  # ]
     264 [ #  # ][ #  # ]:          0 :         xRange = new ScVbaRange( xParent, xContext, xRanges );
                 [ #  # ]
     265                 :            :     }
     266                 :            :     }
     267 [ #  # ][ #  # ]:          0 :     return xRange;
     268                 :            : }
     269                 :            : 
     270                 :         62 : ScCellRangesBase* ScVbaRange::getCellRangesBase() throw ( uno::RuntimeException )
     271                 :            : {
     272         [ -  + ]:         62 :     if( mxRanges.is() )
     273         [ #  # ]:          0 :         return ScCellRangesBase::getImplementation( mxRanges );
     274         [ +  - ]:         62 :     if( mxRange.is() )
     275         [ +  - ]:         62 :         return ScCellRangesBase::getImplementation( mxRange );
     276         [ #  # ]:         62 :     throw uno::RuntimeException( rtl::OUString("General Error creating range - Unknown" ), uno::Reference< uno::XInterface >() );
     277                 :            : }
     278                 :            : 
     279                 :          0 : ScCellRangeObj* ScVbaRange::getCellRangeObj() throw ( uno::RuntimeException )
     280                 :            : {
     281         [ #  # ]:          0 :     return dynamic_cast< ScCellRangeObj* >( getCellRangesBase() );
     282                 :            : }
     283                 :            : 
     284                 :          0 : SfxItemSet*  ScVbaRange::getCurrentDataSet( ) throw ( uno::RuntimeException )
     285                 :            : {
     286                 :          0 :     SfxItemSet* pDataSet = excel::ScVbaCellRangeAccess::GetDataSet( getCellRangesBase() );
     287         [ #  # ]:          0 :     if ( !pDataSet )
     288         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString(  "Can't access Itemset for range"  ), uno::Reference< uno::XInterface >() );
     289                 :          0 :     return pDataSet;
     290                 :            : }
     291                 :            : 
     292                 :          8 : void ScVbaRange::fireChangeEvent()
     293                 :            : {
     294         [ +  - ]:          8 :     if( ScVbaApplication::getDocumentEventsEnabled() )
     295                 :            :     {
     296         [ +  - ]:          8 :         if( ScDocument* pDoc = getScDocument() )
     297                 :            :         {
     298         [ +  - ]:          8 :             uno::Reference< script::vba::XVBAEventProcessor > xVBAEvents = pDoc->GetVbaEventProcessor();
     299         [ +  - ]:          8 :             if( xVBAEvents.is() ) try
     300                 :            :             {
     301         [ +  - ]:          8 :                 uno::Sequence< uno::Any > aArgs( 1 );
     302 [ +  - ][ +  - ]:          8 :                 aArgs[ 0 ] <<= uno::Reference< excel::XRange >( this );
                 [ +  - ]
     303 [ +  - ][ +  - ]:          8 :                 xVBAEvents->processVbaEvent( script::vba::VBAEventId::WORKSHEET_CHANGE, aArgs );
         [ #  # ][ +  - ]
     304                 :            :             }
     305         [ #  # ]:          0 :             catch( uno::Exception& )
     306                 :            :             {
     307                 :          8 :             }
     308                 :            :         }
     309                 :            :     }
     310                 :          8 : }
     311                 :            : 
     312         [ #  # ]:          0 : class SingleRangeEnumeration : public EnumerationHelper_BASE
     313                 :            : {
     314                 :            :     uno::Reference< XHelperInterface > m_xParent;
     315                 :            :     uno::Reference< table::XCellRange > m_xRange;
     316                 :            :     uno::Reference< uno::XComponentContext > mxContext;
     317                 :            :     bool bHasMore;
     318                 :            : public:
     319                 :            : 
     320                 :          0 :     SingleRangeEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< css::uno::XComponentContext >& xContext, const uno::Reference< table::XCellRange >& xRange ) throw ( uno::RuntimeException ) : m_xParent( xParent ), m_xRange( xRange ), mxContext( xContext ), bHasMore( true ) { }
     321                 :          0 :     virtual ::sal_Bool SAL_CALL hasMoreElements(  ) throw (uno::RuntimeException) { return bHasMore; }
     322                 :          0 :     virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
     323                 :            :     {
     324         [ #  # ]:          0 :         if ( !bHasMore )
     325         [ #  # ]:          0 :             throw container::NoSuchElementException();
     326                 :          0 :         bHasMore = false;
     327                 :          0 :         return uno::makeAny( m_xRange );
     328                 :            :     }
     329                 :            : };
     330                 :            : 
     331                 :            : // very simple class to pass to ScVbaCollectionBaseImpl containing
     332                 :            : // just one item
     333                 :            : typedef ::cppu::WeakImplHelper2< container::XIndexAccess, container::XEnumerationAccess > SingleRange_BASE;
     334                 :            : 
     335         [ -  + ]:        424 : class SingleRangeIndexAccess : public SingleRange_BASE
     336                 :            : {
     337                 :            : private:
     338                 :            :     uno::Reference< XHelperInterface > mxParent;
     339                 :            :     uno::Reference< table::XCellRange > m_xRange;
     340                 :            :     uno::Reference< uno::XComponentContext > mxContext;
     341                 :            :     SingleRangeIndexAccess(); // not defined
     342                 :            : public:
     343                 :        212 :     SingleRangeIndexAccess( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< table::XCellRange >& xRange ):mxParent( xParent ), m_xRange( xRange ), mxContext( xContext ) {}
     344                 :            :     // XIndexAccess
     345                 :        316 :     virtual ::sal_Int32 SAL_CALL getCount() throw (::uno::RuntimeException) { return 1; }
     346                 :          0 :     virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
     347                 :            :     {
     348         [ #  # ]:          0 :         if ( Index != 0 )
     349         [ #  # ]:          0 :             throw lang::IndexOutOfBoundsException();
     350                 :          0 :         return uno::makeAny( m_xRange );
     351                 :            :     }
     352                 :            :         // XElementAccess
     353                 :          0 :         virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException){ return table::XCellRange::static_type(0); }
     354                 :            : 
     355                 :          0 :         virtual ::sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException) { return sal_True; }
     356                 :            :     // XEnumerationAccess
     357 [ #  # ][ #  # ]:          0 :     virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration() throw (uno::RuntimeException) { return new SingleRangeEnumeration( mxParent, mxContext, m_xRange ); }
     358                 :            : 
     359                 :            : };
     360                 :            : 
     361                 :            : 
     362                 :            : 
     363         [ #  # ]:          0 : class RangesEnumerationImpl : public EnumerationHelperImpl
     364                 :            : {
     365                 :            :     bool mbIsRows;
     366                 :            :     bool mbIsColumns;
     367                 :            : public:
     368                 :            : 
     369                 :          0 :     RangesEnumerationImpl( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration, bool bIsRows, bool bIsColumns ) throw ( uno::RuntimeException ) : EnumerationHelperImpl( xParent, xContext, xEnumeration ), mbIsRows( bIsRows ), mbIsColumns( bIsColumns ) {}
     370                 :          0 :     virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
     371                 :            :     {
     372 [ #  # ][ #  # ]:          0 :         return lcl_makeRange( m_xParent, m_xContext, m_xEnumeration->nextElement(), mbIsRows, mbIsColumns );
     373                 :            :     }
     374                 :            : };
     375                 :            : 
     376                 :            : 
     377         [ -  + ]:        428 : class ScVbaRangeAreas : public ScVbaCollectionBaseImpl
     378                 :            : {
     379                 :            :     bool mbIsRows;
     380                 :            :     bool mbIsColumns;
     381                 :            : public:
     382         [ +  - ]:        214 :     ScVbaRangeAreas( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess >& xIndexAccess, bool bIsRows, bool bIsColumns ) : ScVbaCollectionBaseImpl( xParent, xContext, xIndexAccess ), mbIsRows( bIsRows ), mbIsColumns( bIsColumns ) {}
     383                 :            : 
     384                 :            :     // XEnumerationAccess
     385                 :            :     virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration() throw (uno::RuntimeException);
     386                 :            : 
     387                 :            :     // XElementAccess
     388                 :          0 :     virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException){ return excel::XRange::static_type(0); }
     389                 :            : 
     390                 :            :     virtual uno::Any createCollectionObject( const uno::Any& aSource );
     391                 :            : 
     392                 :          0 :     virtual rtl::OUString getServiceImplName() { return rtl::OUString(); }
     393                 :            : 
     394                 :          0 :     virtual uno::Sequence< rtl::OUString > getServiceNames() { return uno::Sequence< rtl::OUString >(); }
     395                 :            : 
     396                 :            : };
     397                 :            : 
     398                 :            : uno::Reference< container::XEnumeration > SAL_CALL
     399                 :          0 : ScVbaRangeAreas::createEnumeration() throw (uno::RuntimeException)
     400                 :            : {
     401         [ #  # ]:          0 :     uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
     402 [ #  # ][ #  # ]:          0 :     return new RangesEnumerationImpl( mxParent, mxContext, xEnumAccess->createEnumeration(), mbIsRows, mbIsColumns );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     403                 :            : }
     404                 :            : 
     405                 :            : uno::Any
     406                 :          6 : ScVbaRangeAreas::createCollectionObject( const uno::Any& aSource )
     407                 :            : {
     408 [ +  - ][ +  - ]:          6 :     return lcl_makeRange( mxParent, mxContext, aSource, mbIsRows, mbIsColumns );
     409                 :            : }
     410                 :            : 
     411                 :            : ScDocument*
     412                 :          8 : ScVbaRange::getScDocument() throw (uno::RuntimeException)
     413                 :            : {
     414         [ -  + ]:          8 :     if ( mxRanges.is() )
     415                 :            :     {
     416         [ #  # ]:          0 :         uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW );
     417 [ #  # ][ #  # ]:          0 :         uno::Reference< table::XCellRange > xRange( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
                 [ #  # ]
     418         [ #  # ]:          0 :         return excel::GetDocumentFromRange( xRange );
     419                 :            :     }
     420                 :          8 :     return excel::GetDocumentFromRange( mxRange );
     421                 :            : }
     422                 :            : 
     423                 :            : ScDocShell*
     424                 :        170 : ScVbaRange::getScDocShell() throw (uno::RuntimeException)
     425                 :            : {
     426         [ -  + ]:        170 :     if ( mxRanges.is() )
     427                 :            :     {
     428         [ #  # ]:          0 :         uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW );
     429 [ #  # ][ #  # ]:          0 :         uno::Reference< table::XCellRange > xRange( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
                 [ #  # ]
     430         [ #  # ]:          0 :         return excel::GetDocShellFromRange( xRange );
     431                 :            :     }
     432                 :        170 :     return excel::GetDocShellFromRange( mxRange );
     433                 :            : }
     434                 :            : 
     435                 :          0 : ScVbaRange* ScVbaRange::getImplementation( const uno::Reference< excel::XRange >& rxRange )
     436                 :            : {
     437                 :            :     // FIXME: always save to use dynamic_cast? Or better to (implement and) use XTunnel?
     438         [ #  # ]:          0 :     return dynamic_cast< ScVbaRange* >( rxRange.get() );
     439                 :            : }
     440                 :            : 
     441                 :          0 : uno::Reference< frame::XModel > ScVbaRange::getUnoModel() throw (uno::RuntimeException)
     442                 :            : {
     443         [ #  # ]:          0 :     if( ScDocShell* pDocShell = getScDocShell() )
     444                 :          0 :         return pDocShell->GetModel();
     445         [ #  # ]:          0 :     throw uno::RuntimeException();
     446                 :            : }
     447                 :            : 
     448                 :          0 : uno::Reference< frame::XModel > ScVbaRange::getUnoModel( const uno::Reference< excel::XRange >& rxRange ) throw (uno::RuntimeException)
     449                 :            : {
     450         [ #  # ]:          0 :     if( ScVbaRange* pScVbaRange = getImplementation( rxRange ) )
     451                 :          0 :         return pScVbaRange->getUnoModel();
     452         [ #  # ]:          0 :     throw uno::RuntimeException();
     453                 :            : }
     454                 :            : 
     455                 :          0 : const ScRangeList& ScVbaRange::getScRangeList() throw (uno::RuntimeException)
     456                 :            : {
     457         [ #  # ]:          0 :     if( ScCellRangesBase* pScRangesBase = getCellRangesBase() )
     458                 :          0 :         return pScRangesBase->GetRangeList();
     459         [ #  # ]:          0 :     throw uno::RuntimeException( ::rtl::OUString(  "Cannot obtain UNO range implementation object"  ), uno::Reference< uno::XInterface >() );
     460                 :            : }
     461                 :            : 
     462                 :          0 : const ScRangeList& ScVbaRange::getScRangeList( const uno::Reference< excel::XRange >& rxRange ) throw (uno::RuntimeException)
     463                 :            : {
     464         [ #  # ]:          0 :     if( ScVbaRange* pScVbaRange = getImplementation( rxRange ) )
     465                 :          0 :         return pScVbaRange->getScRangeList();
     466         [ #  # ]:          0 :     throw uno::RuntimeException( ::rtl::OUString(  "Cannot obtain VBA range implementation object"  ), uno::Reference< uno::XInterface >() );
     467                 :            : }
     468                 :            : 
     469                 :            : 
     470                 :          6 : class NumFormatHelper
     471                 :            : {
     472                 :            :     uno::Reference< util::XNumberFormatsSupplier > mxSupplier;
     473                 :            :     uno::Reference< beans::XPropertySet > mxRangeProps;
     474                 :            :     uno::Reference< util::XNumberFormats > mxFormats;
     475                 :            : public:
     476                 :          6 :     NumFormatHelper( const uno::Reference< table::XCellRange >& xRange )
     477                 :          6 :     {
     478 [ +  - ][ +  - ]:          6 :         mxSupplier.set( excel::GetModelFromRange( xRange ), uno::UNO_QUERY_THROW );
     479         [ +  - ]:          6 :         mxRangeProps.set( xRange, uno::UNO_QUERY_THROW);
     480 [ +  - ][ +  - ]:          6 :         mxFormats = mxSupplier->getNumberFormats();
                 [ +  - ]
     481                 :          6 :     }
     482                 :          8 :     uno::Reference< beans::XPropertySet > getNumberProps()
     483                 :            :     {
     484                 :          8 :         long nIndexKey = 0;
     485 [ +  - ][ +  - ]:          8 :         uno::Any aValue = mxRangeProps->getPropertyValue(rtl::OUString( "NumberFormat"));
     486                 :          8 :         aValue >>= nIndexKey;
     487                 :            : 
     488         [ +  - ]:          8 :         if ( mxFormats.is() )
     489 [ +  - ][ +  - ]:          8 :             return  mxFormats->getByKey( nIndexKey );
     490                 :          8 :         return  uno::Reference< beans::XPropertySet > ();
     491                 :            :     }
     492                 :            : 
     493                 :          6 :     bool isBooleanType()
     494                 :            :     {
     495                 :            : 
     496         [ -  + ]:          6 :         if ( getNumberFormat() & util::NumberFormat::LOGICAL )
     497                 :          0 :             return true;
     498                 :          6 :         return false;
     499                 :            :     }
     500                 :            : 
     501                 :          2 :     bool isDateType()
     502                 :            :     {
     503                 :          2 :         sal_Int16 nType = getNumberFormat();
     504         [ -  + ]:          2 :         if(( nType & util::NumberFormat::DATETIME ))
     505                 :            :         {
     506                 :          0 :             return true;
     507                 :            :         }
     508                 :          2 :         return false;
     509                 :            :     }
     510                 :            : 
     511                 :          0 :     rtl::OUString getNumberFormatString()
     512                 :            :     {
     513         [ #  # ]:          0 :         uno::Reference< uno::XInterface > xIf( mxRangeProps, uno::UNO_QUERY_THROW );
     514         [ #  # ]:          0 :         ScCellRangesBase* pUnoCellRange = ScCellRangesBase::getImplementation( xIf );
     515         [ #  # ]:          0 :         if ( pUnoCellRange )
     516                 :            :         {
     517                 :            : 
     518         [ #  # ]:          0 :             SfxItemSet* pDataSet =  excel::ScVbaCellRangeAccess::GetDataSet( pUnoCellRange );
     519         [ #  # ]:          0 :             SfxItemState eState = pDataSet->GetItemState( ATTR_VALUE_FORMAT, true, NULL);
     520                 :            :             // one of the cells in the range is not like the other ;-)
     521                 :            :             // so return a zero length format to indicate that
     522         [ #  # ]:          0 :             if ( eState == SFX_ITEM_DONTCARE )
     523                 :          0 :                 return rtl::OUString();
     524                 :            :         }
     525                 :            : 
     526                 :            : 
     527 [ #  # ][ #  # ]:          0 :         uno::Reference< beans::XPropertySet > xNumberProps( getNumberProps(), uno::UNO_QUERY_THROW );
     528                 :          0 :         ::rtl::OUString aFormatString;
     529 [ #  # ][ #  # ]:          0 :         uno::Any aString = xNumberProps->getPropertyValue(rtl::OUString( "FormatString"));
     530                 :          0 :         aString >>= aFormatString;
     531                 :          0 :         return aFormatString;
     532                 :            :     }
     533                 :            : 
     534                 :          8 :     sal_Int16 getNumberFormat()
     535                 :            :     {
     536         [ +  - ]:          8 :         uno::Reference< beans::XPropertySet > xNumberProps = getNumberProps();
     537                 :            :         sal_Int16 nType = ::comphelper::getINT16(
     538 [ +  - ][ +  - ]:          8 :             xNumberProps->getPropertyValue( ::rtl::OUString( "Type" ) ) );
                 [ +  - ]
     539                 :          8 :         return nType;
     540                 :            :     }
     541                 :            : 
     542                 :          0 :     bool setNumberFormat( const rtl::OUString& rFormat )
     543                 :            :     {
     544                 :            :         // #163288# treat "General" as "Standard" format
     545                 :          0 :         sal_Int32 nNewIndex = 0;
     546         [ #  # ]:          0 :         if( !rFormat.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "General" ) ) )
     547                 :            :         {
     548                 :          0 :             lang::Locale aLocale;
     549         [ #  # ]:          0 :             uno::Reference< beans::XPropertySet > xNumProps = getNumberProps();
     550 [ #  # ][ #  # ]:          0 :             xNumProps->getPropertyValue( ::rtl::OUString(  "Locale"  ) ) >>= aLocale;
                 [ #  # ]
     551 [ #  # ][ #  # ]:          0 :             nNewIndex = mxFormats->queryKey( rFormat, aLocale, false );
     552         [ #  # ]:          0 :             if ( nNewIndex == -1 ) // format not defined
     553 [ #  # ][ #  # ]:          0 :                 nNewIndex = mxFormats->addNew( rFormat, aLocale );
     554                 :            :         }
     555 [ #  # ][ #  # ]:          0 :         mxRangeProps->setPropertyValue( rtl::OUString( "NumberFormat" ), uno::makeAny( nNewIndex ) );
                 [ #  # ]
     556                 :          0 :         return true;
     557                 :            :     }
     558                 :            : 
     559                 :          0 :     bool setNumberFormat( sal_Int16 nType )
     560                 :            :     {
     561         [ #  # ]:          0 :         uno::Reference< beans::XPropertySet > xNumberProps = getNumberProps();
     562                 :          0 :         lang::Locale aLocale;
     563 [ #  # ][ #  # ]:          0 :         xNumberProps->getPropertyValue( ::rtl::OUString( "Locale" ) ) >>= aLocale;
                 [ #  # ]
     564         [ #  # ]:          0 :         uno::Reference<util::XNumberFormatTypes> xTypes( mxFormats, uno::UNO_QUERY );
     565         [ #  # ]:          0 :         if ( xTypes.is() )
     566                 :            :         {
     567 [ #  # ][ #  # ]:          0 :             sal_Int32 nNewIndex = xTypes->getStandardFormat( nType, aLocale );
     568 [ #  # ][ #  # ]:          0 :                mxRangeProps->setPropertyValue( rtl::OUString( "NumberFormat" ), uno::makeAny( nNewIndex ) );
                 [ #  # ]
     569                 :          0 :             return true;
     570                 :            :         }
     571                 :          0 :         return false;
     572                 :            :     }
     573                 :            : 
     574                 :            : };
     575                 :            : 
     576                 :            : struct CellPos
     577                 :            : {
     578                 :            :     CellPos():m_nRow(-1), m_nCol(-1), m_nArea(0) {};
     579                 :          0 :     CellPos( sal_Int32 nRow, sal_Int32 nCol, sal_Int32 nArea ):m_nRow(nRow), m_nCol(nCol), m_nArea( nArea ) {};
     580                 :            : sal_Int32 m_nRow;
     581                 :            : sal_Int32 m_nCol;
     582                 :            : sal_Int32 m_nArea;
     583                 :            : };
     584                 :            : 
     585                 :            : typedef ::cppu::WeakImplHelper1< container::XEnumeration > CellsEnumeration_BASE;
     586                 :            : typedef ::std::vector< CellPos > vCellPos;
     587                 :            : 
     588                 :            : // #FIXME - QUICK
     589                 :            : // we could probably could and should modify CellsEnumeration below
     590                 :            : // to handle rows and columns ( but I do this seperately for now
     591                 :            : // and.. this class only handles singe areas ( does it have to handle
     592                 :            : // multi area ranges?? )
     593         [ #  # ]:          0 : class ColumnsRowEnumeration: public CellsEnumeration_BASE
     594                 :            : {
     595                 :            :     uno::Reference< uno::XComponentContext > mxContext;
     596                 :            :         uno::Reference< excel::XRange > mxRange;
     597                 :            :     sal_Int32 mMaxElems;
     598                 :            :     sal_Int32 mCurElem;
     599                 :            : 
     600                 :            : public:
     601                 :          0 :     ColumnsRowEnumeration( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< excel::XRange >& xRange, sal_Int32 nElems ) : mxContext( xContext ), mxRange( xRange ), mMaxElems( nElems ), mCurElem( 0 )
     602                 :            :         {
     603                 :          0 :     }
     604                 :            : 
     605                 :          0 :     virtual ::sal_Bool SAL_CALL hasMoreElements() throw (::uno::RuntimeException){ return mCurElem < mMaxElems; }
     606                 :            : 
     607                 :          0 :     virtual uno::Any SAL_CALL nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
     608                 :            :     {
     609 [ #  # ][ #  # ]:          0 :         if ( !hasMoreElements() )
     610         [ #  # ]:          0 :             throw container::NoSuchElementException();
     611                 :          0 :         sal_Int32 vbaIndex = 1 + mCurElem++;
     612 [ #  # ][ #  # ]:          0 :         return uno::makeAny( mxRange->Item( uno::makeAny( vbaIndex ), uno::Any() ) );
         [ #  # ][ #  # ]
     613                 :            :     }
     614                 :            : };
     615                 :            : 
     616 [ #  # ][ #  # ]:          0 : class CellsEnumeration : public CellsEnumeration_BASE
     617                 :            : {
     618                 :            :     uno::WeakReference< XHelperInterface > mxParent;
     619                 :            :     uno::Reference< uno::XComponentContext > mxContext;
     620                 :            :     uno::Reference< XCollection > m_xAreas;
     621                 :            :     vCellPos m_CellPositions;
     622                 :            :     vCellPos::const_iterator m_it;
     623                 :            : 
     624                 :          0 :     uno::Reference< table::XCellRange > getArea( sal_Int32 nVBAIndex ) throw ( uno::RuntimeException )
     625                 :            :     {
     626 [ #  # ][ #  # ]:          0 :         if ( nVBAIndex < 1 || nVBAIndex > m_xAreas->getCount() )
         [ #  # ][ #  # ]
                 [ #  # ]
     627         [ #  # ]:          0 :             throw uno::RuntimeException();
     628 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( m_xAreas->Item( uno::makeAny(nVBAIndex), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
     629 [ #  # ][ #  # ]:          0 :         uno::Reference< table::XCellRange > xCellRange( ScVbaRange::getCellRange( xRange ), uno::UNO_QUERY_THROW );
     630                 :          0 :         return xCellRange;
     631                 :            :     }
     632                 :            : 
     633                 :          0 :     void populateArea( sal_Int32 nVBAIndex )
     634                 :            :     {
     635         [ #  # ]:          0 :         uno::Reference< table::XCellRange > xRange = getArea( nVBAIndex );
     636         [ #  # ]:          0 :         uno::Reference< table::XColumnRowRange > xColumnRowRange(xRange, uno::UNO_QUERY_THROW );
     637 [ #  # ][ #  # ]:          0 :         sal_Int32 nRowCount =  xColumnRowRange->getRows()->getCount();
         [ #  # ][ #  # ]
     638 [ #  # ][ #  # ]:          0 :         sal_Int32 nColCount = xColumnRowRange->getColumns()->getCount();
         [ #  # ][ #  # ]
     639         [ #  # ]:          0 :         for ( sal_Int32 i=0; i<nRowCount; ++i )
     640                 :            :         {
     641         [ #  # ]:          0 :             for ( sal_Int32 j=0; j<nColCount; ++j )
     642         [ #  # ]:          0 :                 m_CellPositions.push_back( CellPos( i,j,nVBAIndex ) );
     643                 :          0 :         }
     644                 :          0 :     }
     645                 :            : public:
     646 [ #  # ][ #  # ]:          0 :     CellsEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< XCollection >& xAreas ): mxParent( xParent ), mxContext( xContext ), m_xAreas( xAreas )
     647                 :            :     {
     648 [ #  # ][ #  # ]:          0 :         sal_Int32 nItems = m_xAreas->getCount();
     649         [ #  # ]:          0 :         for ( sal_Int32 index=1; index <= nItems; ++index )
     650                 :            :         {
     651         [ #  # ]:          0 :                 populateArea( index );
     652                 :            :         }
     653         [ #  # ]:          0 :         m_it = m_CellPositions.begin();
     654                 :          0 :     }
     655         [ #  # ]:          0 :     virtual ::sal_Bool SAL_CALL hasMoreElements() throw (::uno::RuntimeException){ return m_it != m_CellPositions.end(); }
     656                 :            : 
     657                 :          0 :     virtual uno::Any SAL_CALL nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
     658                 :            :     {
     659 [ #  # ][ #  # ]:          0 :         if ( !hasMoreElements() )
     660         [ #  # ]:          0 :             throw container::NoSuchElementException();
     661         [ #  # ]:          0 :         CellPos aPos = *(m_it)++;
     662                 :            : 
     663         [ #  # ]:          0 :         uno::Reference< table::XCellRange > xRangeArea = getArea( aPos.m_nArea );
     664 [ #  # ][ #  # ]:          0 :         uno::Reference< table::XCellRange > xCellRange( xRangeArea->getCellByPosition(  aPos.m_nCol, aPos.m_nRow ), uno::UNO_QUERY_THROW );
                 [ #  # ]
     665 [ #  # ][ #  # ]:          0 :         return uno::makeAny( uno::Reference< excel::XRange >( new ScVbaRange( mxParent, mxContext, xCellRange ) ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     666                 :            : 
     667                 :            :     }
     668                 :            : };
     669                 :            : 
     670                 :            : 
     671                 :          3 : const static ::rtl::OUString ISVISIBLE(   "IsVisible");
     672                 :          3 : const static ::rtl::OUString POSITION(   "Position");
     673                 :          3 : const static rtl::OUString EQUALS( "=" );
     674                 :          3 : const static rtl::OUString NOTEQUALS( "<>" );
     675                 :          3 : const static rtl::OUString GREATERTHAN( ">" );
     676                 :          3 : const static rtl::OUString GREATERTHANEQUALS( ">=" );
     677                 :          3 : const static rtl::OUString LESSTHAN( "<" );
     678                 :          3 : const static rtl::OUString LESSTHANEQUALS( "<=" );
     679                 :          3 : const static rtl::OUString CONTS_HEADER( "ContainsHeader" );
     680                 :          3 : const static rtl::OUString INSERTPAGEBREAKS( "InsertPageBreaks" );
     681                 :          3 : const static rtl::OUString STR_ERRORMESSAGE_APPLIESTOSINGLERANGEONLY( "The command you chose cannot be performed with multiple selections.\nSelect a single range and click the command again" );
     682                 :          3 : const static rtl::OUString STR_ERRORMESSAGE_NOCELLSWEREFOUND( "No cells were found" );
     683                 :          3 : const static rtl::OUString CELLSTYLE( "CellStyle" );
     684                 :            : 
     685         [ -  + ]:          6 : class CellValueSetter : public ValueSetter
     686                 :            : {
     687                 :            : protected:
     688                 :            :     uno::Any maValue;
     689                 :            :     uno::TypeClass mTypeClass;
     690                 :            : public:
     691                 :            :     CellValueSetter( const uno::Any& aValue );
     692                 :            :     virtual bool processValue( const uno::Any& aValue,  const uno::Reference< table::XCell >& xCell );
     693                 :            :     virtual void visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< table::XCell >& xCell );
     694                 :            : 
     695                 :            : };
     696                 :            : 
     697                 :          6 : CellValueSetter::CellValueSetter( const uno::Any& aValue ): maValue( aValue ), mTypeClass( aValue.getValueTypeClass() ) {}
     698                 :            : 
     699                 :            : void
     700                 :          6 : CellValueSetter::visitNode( sal_Int32 /*i*/, sal_Int32 /*j*/, const uno::Reference< table::XCell >& xCell )
     701                 :            : {
     702                 :          6 :     processValue( maValue, xCell );
     703                 :          6 : }
     704                 :            : 
     705                 :            : bool
     706                 :          6 : CellValueSetter::processValue( const uno::Any& aValue, const uno::Reference< table::XCell >& xCell )
     707                 :            : {
     708                 :            : 
     709                 :          6 :     bool isExtracted = false;
     710      [ -  +  + ]:          6 :     switch ( aValue.getValueTypeClass() )
     711                 :            :     {
     712                 :            :         case  uno::TypeClass_BOOLEAN:
     713                 :            :         {
     714                 :          0 :             sal_Bool bState = false;
     715         [ #  # ]:          0 :             if ( aValue >>= bState   )
     716                 :            :             {
     717         [ #  # ]:          0 :                 uno::Reference< table::XCellRange > xRange( xCell, uno::UNO_QUERY_THROW );
     718         [ #  # ]:          0 :                 if ( bState )
     719 [ #  # ][ #  # ]:          0 :                     xCell->setValue( (double) 1 );
     720                 :            :                 else
     721 [ #  # ][ #  # ]:          0 :                     xCell->setValue( (double) 0 );
     722         [ #  # ]:          0 :                 NumFormatHelper cellNumFormat( xRange );
     723 [ #  # ][ #  # ]:          0 :                 cellNumFormat.setNumberFormat( util::NumberFormat::LOGICAL );
     724                 :            :             }
     725                 :            :             break;
     726                 :            :         }
     727                 :            :         case uno::TypeClass_STRING:
     728                 :            :         {
     729                 :          2 :             rtl::OUString aString;
     730         [ +  - ]:          2 :             if ( aValue >>= aString )
     731                 :            :             {
     732                 :            :                 // The required behavior for a string value is:
     733                 :            :                 // 1. If the first character is a single quote, use the rest as a string cell, regardless of the cell's number format.
     734                 :            :                 // 2. Otherwise, if the cell's number format is "text", use the string value as a string cell.
     735                 :            :                 // 3. Otherwise, parse the string value in English locale, and apply a corresponding number format with the cell's locale
     736                 :            :                 //    if the cell's number format was "General".
     737                 :            :                 // Case 1 is handled here, the rest in ScCellObj::InputEnglishString
     738                 :            : 
     739         [ -  + ]:          2 :                 if ( aString.toChar() == '\'' )     // case 1 - handle with XTextRange
     740                 :            :                 {
     741                 :          0 :                     rtl::OUString aRemainder( aString.copy(1) );    // strip the quote
     742         [ #  # ]:          0 :                     uno::Reference< text::XTextRange > xTextRange( xCell, uno::UNO_QUERY_THROW );
     743 [ #  # ][ #  # ]:          0 :                     xTextRange->setString( aRemainder );
     744                 :            :                 }
     745                 :            :                 else
     746                 :            :                 {
     747                 :            :                     // call implementation method InputEnglishString
     748 [ +  - ][ -  + ]:          2 :                     ScCellObj* pCellObj = dynamic_cast< ScCellObj* >( xCell.get() );
     749         [ +  - ]:          2 :                     if ( pCellObj )
     750         [ +  - ]:          2 :                         pCellObj->InputEnglishString( aString );
     751                 :            :                 }
     752                 :            :             }
     753                 :            :             else
     754                 :          0 :                 isExtracted = false;
     755                 :          2 :             break;
     756                 :            :         }
     757                 :            :         default:
     758                 :            :         {
     759                 :          4 :             double nDouble = 0.0;
     760         [ +  - ]:          4 :             if ( aValue >>= nDouble )
     761                 :            :             {
     762 [ +  - ][ +  - ]:          4 :                 xCell->setValue( nDouble );
     763         [ +  - ]:          4 :                 uno::Reference< table::XCellRange > xRange( xCell, uno::UNO_QUERY_THROW );
     764         [ +  - ]:          4 :                 NumFormatHelper cellNumFormat( xRange );
     765 [ +  - ][ -  + ]:          4 :                 if ( cellNumFormat.isBooleanType() )
     766                 :            :                 {
     767         [ #  # ]:          0 :                     cellNumFormat.setNumberFormat( util::NumberFormat::NUMBER );
     768         [ +  - ]:          4 :                 }
     769                 :            :             }
     770                 :            :             else
     771                 :          4 :                 isExtracted = false;
     772                 :            :             break;
     773                 :            :         }
     774                 :            :     }
     775                 :          6 :     return isExtracted;
     776                 :            : 
     777                 :            : }
     778                 :            : 
     779                 :            : 
     780         [ -  + ]:          2 : class CellValueGetter : public ValueGetter
     781                 :            : {
     782                 :            : protected:
     783                 :            :     uno::Any maValue;
     784                 :            :     uno::TypeClass mTypeClass;
     785                 :            : public:
     786                 :          2 :     CellValueGetter() {}
     787                 :            :     virtual void visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< table::XCell >& xCell );
     788                 :            :     virtual void processValue( sal_Int32 x, sal_Int32 y, const uno::Any& aValue );
     789                 :          2 :     const uno::Any& getValue() const { return maValue; }
     790                 :            : 
     791                 :            : };
     792                 :            : 
     793                 :            : void
     794                 :          2 : CellValueGetter::processValue(  sal_Int32 /*x*/, sal_Int32 /*y*/, const uno::Any& aValue )
     795                 :            : {
     796                 :          2 :     maValue = aValue;
     797                 :          2 : }
     798                 :          2 : void CellValueGetter::visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< table::XCell >& xCell )
     799                 :            : {
     800                 :          2 :     uno::Any aValue;
     801 [ +  - ][ +  - ]:          2 :     table::CellContentType eType = xCell->getType();
     802 [ -  + ][ #  # ]:          2 :     if( eType == table::CellContentType_VALUE || eType == table::CellContentType_FORMULA )
     803                 :            :     {
     804         [ -  + ]:          2 :         if ( eType == table::CellContentType_FORMULA )
     805                 :            :         {
     806                 :            : 
     807 [ #  # ][ #  # ]:          0 :             rtl::OUString sFormula = xCell->getFormula();
     808         [ #  # ]:          0 :             if ( sFormula == "=TRUE()" )
     809         [ #  # ]:          0 :                 aValue <<= sal_True;
     810         [ #  # ]:          0 :             else if ( sFormula == "=FALSE()" )
     811         [ #  # ]:          0 :                 aValue <<= false;
     812                 :            :             else
     813                 :            :             {
     814         [ #  # ]:          0 :                 uno::Reference< beans::XPropertySet > xProp( xCell, uno::UNO_QUERY_THROW );
     815                 :            : 
     816                 :          0 :                 table::CellContentType eFormulaType = table::CellContentType_VALUE;
     817                 :            :                 // some formulas give textual results
     818 [ #  # ][ #  # ]:          0 :                 xProp->getPropertyValue( rtl::OUString( "FormulaResultType"  ) ) >>= eFormulaType;
                 [ #  # ]
     819                 :            : 
     820         [ #  # ]:          0 :                 if ( eFormulaType == table::CellContentType_TEXT )
     821                 :            :                 {
     822         [ #  # ]:          0 :                     uno::Reference< text::XTextRange > xTextRange(xCell, ::uno::UNO_QUERY_THROW);
     823 [ #  # ][ #  # ]:          0 :                     aValue <<= xTextRange->getString();
                 [ #  # ]
     824                 :            :                 }
     825                 :            :                 else
     826 [ #  # ][ #  # ]:          0 :                     aValue <<= xCell->getValue();
                 [ #  # ]
     827                 :          0 :             }
     828                 :            :         }
     829                 :            :         else
     830                 :            :         {
     831         [ +  - ]:          2 :             uno::Reference< table::XCellRange > xRange( xCell, uno::UNO_QUERY_THROW );
     832         [ +  - ]:          2 :             NumFormatHelper cellFormat( xRange );
     833 [ +  - ][ -  + ]:          2 :             if ( cellFormat.isBooleanType() )
     834 [ #  # ][ #  # ]:          0 :                 aValue = uno::makeAny( ( xCell->getValue() != 0.0 ) );
                 [ #  # ]
     835 [ +  - ][ -  + ]:          2 :             else if ( cellFormat.isDateType() )
     836 [ #  # ][ #  # ]:          0 :                 aValue = uno::makeAny( bridge::oleautomation::Date( xCell->getValue() ) );
                 [ #  # ]
     837                 :            :             else
     838 [ +  - ][ +  - ]:          2 :                 aValue <<= xCell->getValue();
         [ +  - ][ +  - ]
     839                 :            :         }
     840                 :            :     }
     841         [ -  + ]:          2 :     if( eType == table::CellContentType_TEXT )
     842                 :            :     {
     843         [ #  # ]:          0 :         uno::Reference< text::XTextRange > xTextRange(xCell, ::uno::UNO_QUERY_THROW);
     844 [ #  # ][ #  # ]:          0 :         aValue <<= xTextRange->getString();
                 [ #  # ]
     845                 :            :     }
     846         [ +  - ]:          2 :     processValue( x,y,aValue );
     847                 :          2 : }
     848                 :            : 
     849         [ #  # ]:          0 : class CellFormulaValueSetter : public CellValueSetter
     850                 :            : {
     851                 :            : private:
     852                 :            :     ScDocument*  m_pDoc;
     853                 :            :     formula::FormulaGrammar::Grammar m_eGrammar;
     854                 :            : public:
     855                 :          0 :     CellFormulaValueSetter( const uno::Any& aValue, ScDocument* pDoc, formula::FormulaGrammar::Grammar eGram ):CellValueSetter( aValue ),  m_pDoc( pDoc ), m_eGrammar( eGram ){}
     856                 :            : protected:
     857                 :          0 :     bool processValue( const uno::Any& aValue, const uno::Reference< table::XCell >& xCell )
     858                 :            :     {
     859                 :          0 :         rtl::OUString sFormula;
     860                 :          0 :         double aDblValue = 0.0;
     861         [ #  # ]:          0 :         if ( aValue >>= sFormula )
     862                 :            :         {
     863                 :            :             // convert to GRAM_PODF_A1 style grammar because XCell::setFormula
     864                 :            :             // always compile it in that grammar. Perhaps
     865                 :            :             // css.sheet.FormulaParser should be used in future to directly
     866                 :            :             // pass formula tokens when that API stabilizes.
     867 [ #  # ][ #  # ]:          0 :             if ( m_eGrammar != formula::FormulaGrammar::GRAM_PODF_A1 && ( sFormula.trim().indexOf('=') == 0 ) )
         [ #  # ][ #  # ]
     868                 :            :             {
     869         [ #  # ]:          0 :                 uno::Reference< uno::XInterface > xIf( xCell, uno::UNO_QUERY_THROW );
     870 [ #  # ][ #  # ]:          0 :                 ScCellRangesBase* pUnoRangesBase = dynamic_cast< ScCellRangesBase* >( xIf.get() );
     871         [ #  # ]:          0 :                 if ( pUnoRangesBase )
     872                 :            :                 {
     873         [ #  # ]:          0 :                     ScRangeList aCellRanges = pUnoRangesBase->GetRangeList();
     874 [ #  # ][ #  # ]:          0 :                     ScCompiler aCompiler( m_pDoc, aCellRanges.front()->aStart );
     875         [ #  # ]:          0 :                     aCompiler.SetGrammar(m_eGrammar);
     876                 :            :                     // compile the string in the format passed in
     877 [ #  # ][ #  # ]:          0 :                     aCompiler.CompileString( sFormula );
                 [ #  # ]
     878                 :            :                     // set desired convention to that of the document
     879         [ #  # ]:          0 :                     aCompiler.SetGrammar( formula::FormulaGrammar::GRAM_PODF_A1 );
     880         [ #  # ]:          0 :                     String sConverted;
     881         [ #  # ]:          0 :                     aCompiler.CreateStringFromTokenArray(sConverted);
     882 [ #  # ][ #  # ]:          0 :                     sFormula = EQUALS + sConverted;
         [ #  # ][ #  # ]
     883                 :          0 :                 }
     884                 :            :             }
     885                 :            : 
     886 [ #  # ][ #  # ]:          0 :             xCell->setFormula( sFormula );
     887                 :          0 :             return true;
     888                 :            :         }
     889         [ #  # ]:          0 :         else if ( aValue >>= aDblValue )
     890                 :            :         {
     891 [ #  # ][ #  # ]:          0 :             xCell->setValue( aDblValue );
     892                 :          0 :             return true;
     893                 :            :         }
     894                 :          0 :         return false;
     895                 :            :     }
     896                 :            : 
     897                 :            : };
     898                 :            : 
     899         [ #  # ]:          0 : class CellFormulaValueGetter : public CellValueGetter
     900                 :            : {
     901                 :            : private:
     902                 :            :     ScDocument*  m_pDoc;
     903                 :            :     formula::FormulaGrammar::Grammar m_eGrammar;
     904                 :            : public:
     905                 :          0 :     CellFormulaValueGetter(ScDocument* pDoc, formula::FormulaGrammar::Grammar eGram ) : CellValueGetter( ), m_pDoc( pDoc ), m_eGrammar( eGram ) {}
     906                 :          0 :     virtual void visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< table::XCell >& xCell )
     907                 :            :     {
     908                 :          0 :         uno::Any aValue;
     909 [ #  # ][ #  # ]:          0 :         aValue <<= xCell->getFormula();
                 [ #  # ]
     910                 :          0 :         rtl::OUString sVal;
     911                 :          0 :         aValue >>= sVal;
     912         [ #  # ]:          0 :         uno::Reference< uno::XInterface > xIf( xCell, uno::UNO_QUERY_THROW );
     913 [ #  # ][ #  # ]:          0 :         ScCellRangesBase* pUnoRangesBase = dynamic_cast< ScCellRangesBase* >( xIf.get() );
     914 [ #  # ][ #  # ]:          0 :         if ( ( xCell->getType() == table::CellContentType_FORMULA ) &&
         [ #  # ][ #  # ]
                 [ #  # ]
     915                 :            :             pUnoRangesBase )
     916                 :            :         {
     917         [ #  # ]:          0 :             ScRangeList aCellRanges = pUnoRangesBase->GetRangeList();
     918 [ #  # ][ #  # ]:          0 :             ScCompiler aCompiler( m_pDoc, aCellRanges.front()->aStart );
     919         [ #  # ]:          0 :             aCompiler.SetGrammar(formula::FormulaGrammar::GRAM_DEFAULT);
     920 [ #  # ][ #  # ]:          0 :             aCompiler.CompileString( sVal );
                 [ #  # ]
     921                 :            :             // set desired convention
     922         [ #  # ]:          0 :             aCompiler.SetGrammar( m_eGrammar );
     923         [ #  # ]:          0 :             String sConverted;
     924         [ #  # ]:          0 :             aCompiler.CreateStringFromTokenArray(sConverted);
     925         [ #  # ]:          0 :             sVal = EQUALS + sConverted;
     926 [ #  # ][ #  # ]:          0 :             aValue <<= sVal;
         [ #  # ][ #  # ]
     927                 :            :         }
     928                 :            : 
     929         [ #  # ]:          0 :         processValue( x,y,aValue );
     930                 :          0 :     }
     931                 :            : 
     932                 :            : };
     933                 :            : 
     934                 :            : 
     935         [ #  # ]:          0 : class Dim2ArrayValueGetter : public ArrayVisitor
     936                 :            : {
     937                 :            : protected:
     938                 :            :     uno::Any maValue;
     939                 :            :     ValueGetter& mValueGetter;
     940                 :          0 :     virtual void processValue( sal_Int32 x, sal_Int32 y, const uno::Any& aValue )
     941                 :            :     {
     942                 :          0 :         uno::Sequence< uno::Sequence< uno::Any > >& aMatrix = *( uno::Sequence< uno::Sequence< uno::Any > >* )( maValue.getValue() );
     943                 :          0 :         aMatrix[x][y] = aValue;
     944                 :          0 :     }
     945                 :            : 
     946                 :            : public:
     947                 :          0 :     Dim2ArrayValueGetter(sal_Int32 nRowCount, sal_Int32 nColCount, ValueGetter& rValueGetter ): mValueGetter(rValueGetter)
     948                 :            :     {
     949         [ #  # ]:          0 :         uno::Sequence< uno::Sequence< uno::Any > > aMatrix;
     950         [ #  # ]:          0 :         aMatrix.realloc( nRowCount );
     951         [ #  # ]:          0 :         for ( sal_Int32 index = 0; index < nRowCount; ++index )
     952 [ #  # ][ #  # ]:          0 :             aMatrix[index].realloc( nColCount );
     953 [ #  # ][ #  # ]:          0 :         maValue <<= aMatrix;
     954                 :          0 :     }
     955                 :          0 :     void visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< table::XCell >& xCell )
     956                 :            : 
     957                 :            :     {
     958                 :          0 :         mValueGetter.visitNode( x, y, xCell );
     959                 :          0 :         processValue( x, y, mValueGetter.getValue() );
     960                 :          0 :     }
     961                 :          0 :     const uno::Any& getValue() const { return maValue; }
     962                 :            : 
     963                 :            : };
     964                 :            : 
     965                 :          3 : const static rtl::OUString sNA("#N/A");
     966                 :            : 
     967 [ #  # ][ #  # ]:          0 : class Dim1ArrayValueSetter : public ArrayVisitor
     968                 :            : {
     969                 :            :     uno::Sequence< uno::Any > aMatrix;
     970                 :            :     sal_Int32 nColCount;
     971                 :            :     ValueSetter& mCellValueSetter;
     972                 :            : public:
     973         [ #  # ]:          0 :     Dim1ArrayValueSetter( const uno::Any& aValue, ValueSetter& rCellValueSetter ):mCellValueSetter( rCellValueSetter )
     974                 :            :     {
     975         [ #  # ]:          0 :         aValue >>= aMatrix;
     976                 :          0 :         nColCount = aMatrix.getLength();
     977                 :          0 :     }
     978                 :          0 :     virtual void visitNode( sal_Int32 /*x*/, sal_Int32 y, const uno::Reference< table::XCell >& xCell )
     979                 :            :     {
     980         [ #  # ]:          0 :         if ( y < nColCount )
     981                 :          0 :             mCellValueSetter.processValue( aMatrix[ y ], xCell );
     982                 :            :         else
     983         [ #  # ]:          0 :             mCellValueSetter.processValue( uno::makeAny( sNA ), xCell );
     984                 :          0 :     }
     985                 :            : };
     986                 :            : 
     987                 :            : 
     988                 :            : 
     989 [ #  # ][ #  # ]:          0 : class Dim2ArrayValueSetter : public ArrayVisitor
     990                 :            : {
     991                 :            :     uno::Sequence< uno::Sequence< uno::Any > > aMatrix;
     992                 :            :     ValueSetter& mCellValueSetter;
     993                 :            :     sal_Int32 nRowCount;
     994                 :            :     sal_Int32 nColCount;
     995                 :            : public:
     996         [ #  # ]:          0 :     Dim2ArrayValueSetter( const uno::Any& aValue, ValueSetter& rCellValueSetter ) : mCellValueSetter( rCellValueSetter )
     997                 :            :     {
     998         [ #  # ]:          0 :         aValue >>= aMatrix;
     999                 :          0 :         nRowCount = aMatrix.getLength();
    1000         [ #  # ]:          0 :         nColCount = aMatrix[0].getLength();
    1001                 :          0 :     }
    1002                 :            : 
    1003                 :          0 :     virtual void visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< table::XCell >& xCell )
    1004                 :            :     {
    1005 [ #  # ][ #  # ]:          0 :         if ( x < nRowCount && y < nColCount )
    1006                 :          0 :             mCellValueSetter.processValue( aMatrix[ x ][ y ], xCell );
    1007                 :            :         else
    1008         [ #  # ]:          0 :             mCellValueSetter.processValue( uno::makeAny( sNA ), xCell );
    1009                 :            : 
    1010                 :          0 :     }
    1011                 :            : };
    1012                 :            : 
    1013                 :          0 : class RangeProcessor
    1014                 :            : {
    1015                 :            : public:
    1016                 :            :     virtual void process( const uno::Reference< excel::XRange >& xRange ) = 0;
    1017                 :            : 
    1018                 :            : protected:
    1019                 :          0 :     ~RangeProcessor() {}
    1020                 :            : };
    1021                 :            : 
    1022                 :            : class RangeValueProcessor : public RangeProcessor
    1023                 :            : {
    1024                 :            :     const uno::Any& m_aVal;
    1025                 :            : public:
    1026                 :          0 :     RangeValueProcessor( const uno::Any& rVal ):m_aVal( rVal ) {}
    1027         [ #  # ]:          0 :     virtual ~RangeValueProcessor() {}
    1028                 :          0 :     virtual void process( const uno::Reference< excel::XRange >& xRange )
    1029                 :            :     {
    1030                 :          0 :         xRange->setValue( m_aVal );
    1031                 :          0 :     }
    1032                 :            : };
    1033                 :            : 
    1034                 :            : class RangeFormulaProcessor : public RangeProcessor
    1035                 :            : {
    1036                 :            :     const uno::Any& m_aVal;
    1037                 :            : public:
    1038                 :          0 :     RangeFormulaProcessor( const uno::Any& rVal ):m_aVal( rVal ) {}
    1039         [ #  # ]:          0 :     virtual ~RangeFormulaProcessor() {}
    1040                 :          0 :     virtual void process( const uno::Reference< excel::XRange >& xRange )
    1041                 :            :     {
    1042                 :          0 :         xRange->setFormula( m_aVal );
    1043                 :          0 :     }
    1044                 :            : };
    1045                 :            : 
    1046                 :            : class RangeCountProcessor : public RangeProcessor
    1047                 :            : {
    1048                 :            :     sal_Int32 nCount;
    1049                 :            : public:
    1050                 :          0 :     RangeCountProcessor():nCount(0){}
    1051         [ #  # ]:          0 :     virtual ~RangeCountProcessor() {}
    1052                 :          0 :     virtual void process( const uno::Reference< excel::XRange >& xRange )
    1053                 :            :     {
    1054                 :          0 :         nCount = nCount + xRange->getCount();
    1055                 :          0 :     }
    1056                 :          0 :     sal_Int32 value() { return nCount; }
    1057                 :            : };
    1058                 :          0 : class AreasVisitor
    1059                 :            : {
    1060                 :            : private:
    1061                 :            :     uno::Reference< XCollection > m_Areas;
    1062                 :            : public:
    1063                 :          0 :     AreasVisitor( const uno::Reference< XCollection >& rAreas ):m_Areas( rAreas ){}
    1064                 :            : 
    1065                 :          0 :     void visit( RangeProcessor& processor )
    1066                 :            :     {
    1067         [ #  # ]:          0 :         if ( m_Areas.is() )
    1068                 :            :         {
    1069                 :          0 :             sal_Int32 nItems = m_Areas->getCount();
    1070         [ #  # ]:          0 :             for ( sal_Int32 index=1; index <= nItems; ++index )
    1071                 :            :             {
    1072 [ #  # ][ #  # ]:          0 :                 uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    1073         [ #  # ]:          0 :                 processor.process( xRange );
    1074                 :          0 :             }
    1075                 :            :         }
    1076                 :          0 :     }
    1077                 :            : };
    1078                 :            : 
    1079                 :        240 : class RangeHelper
    1080                 :            : {
    1081                 :            :     uno::Reference< table::XCellRange > m_xCellRange;
    1082                 :            : 
    1083                 :            : public:
    1084                 :        240 :     RangeHelper( const uno::Reference< table::XCellRange >& xCellRange ) throw (uno::RuntimeException) : m_xCellRange( xCellRange )
    1085                 :            :     {
    1086         [ -  + ]:        240 :         if ( !m_xCellRange.is() )
    1087         [ #  # ]:          0 :             throw uno::RuntimeException();
    1088                 :        240 :     }
    1089                 :          0 :     RangeHelper( const uno::Any aCellRange ) throw (uno::RuntimeException)
    1090                 :          0 :     {
    1091         [ #  # ]:          0 :         m_xCellRange.set( aCellRange, uno::UNO_QUERY_THROW );
    1092                 :          0 :     }
    1093                 :         70 :     uno::Reference< sheet::XSheetCellRange > getSheetCellRange() throw (uno::RuntimeException)
    1094                 :            :     {
    1095                 :         70 :         return uno::Reference< sheet::XSheetCellRange >(m_xCellRange, uno::UNO_QUERY_THROW);
    1096                 :            :     }
    1097                 :         70 :     uno::Reference< sheet::XSpreadsheet >  getSpreadSheet() throw (uno::RuntimeException)
    1098                 :            :     {
    1099 [ +  - ][ +  - ]:         70 :         return getSheetCellRange()->getSpreadsheet();
    1100                 :            :     }
    1101                 :            : 
    1102                 :         70 :     uno::Reference< table::XCellRange > getCellRangeFromSheet() throw (uno::RuntimeException)
    1103                 :            :     {
    1104         [ +  - ]:         70 :         return uno::Reference< table::XCellRange >(getSpreadSheet(), uno::UNO_QUERY_THROW );
    1105                 :            :     }
    1106                 :            : 
    1107                 :        172 :     uno::Reference< sheet::XCellRangeAddressable >  getCellRangeAddressable() throw (uno::RuntimeException)
    1108                 :            :     {
    1109                 :        172 :         return uno::Reference< sheet::XCellRangeAddressable >(m_xCellRange, ::uno::UNO_QUERY_THROW);
    1110                 :            : 
    1111                 :            :     }
    1112                 :            : 
    1113                 :          0 :     uno::Reference< sheet::XSheetCellCursor > getSheetCellCursor() throw ( uno::RuntimeException )
    1114                 :            :     {
    1115 [ #  # ][ #  # ]:          0 :         return  uno::Reference< sheet::XSheetCellCursor >( getSpreadSheet()->createCursorByRange( getSheetCellRange() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    1116                 :            :     }
    1117                 :            : 
    1118                 :          0 :     static uno::Reference< excel::XRange > createRangeFromRange( const uno::Reference< XHelperInterface >& xParent, const uno::Reference<uno::XComponentContext >& xContext,
    1119                 :            :         const uno::Reference< table::XCellRange >& xRange, const uno::Reference< sheet::XCellRangeAddressable >& xCellRangeAddressable,
    1120                 :            :         sal_Int32 nStartColOffset = 0, sal_Int32 nStartRowOffset = 0, sal_Int32 nEndColOffset = 0, sal_Int32 nEndRowOffset = 0 )
    1121                 :            :     {
    1122                 :            :         return uno::Reference< excel::XRange >( new ScVbaRange( xParent, xContext,
    1123                 :          0 :             xRange->getCellRangeByPosition(
    1124         [ #  # ]:          0 :                 xCellRangeAddressable->getRangeAddress().StartColumn + nStartColOffset,
    1125         [ #  # ]:          0 :                 xCellRangeAddressable->getRangeAddress().StartRow + nStartRowOffset,
    1126         [ #  # ]:          0 :                 xCellRangeAddressable->getRangeAddress().EndColumn + nEndColOffset,
    1127 [ #  # ][ #  # ]:          0 :                 xCellRangeAddressable->getRangeAddress().EndRow + nEndRowOffset ) ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1128                 :            :     }
    1129                 :            : 
    1130                 :            : };
    1131                 :            : 
    1132                 :            : bool
    1133                 :         72 : getCellRangesForAddress( sal_uInt16& rResFlags, const rtl::OUString& sAddress, ScDocShell* pDocSh, ScRangeList& rCellRanges, formula::FormulaGrammar::AddressConvention& eConv, char cDelimiter = 0 )
    1134                 :            : {
    1135                 :            : 
    1136                 :         72 :     ScDocument* pDoc = NULL;
    1137         [ +  - ]:         72 :     if ( pDocSh )
    1138                 :            :     {
    1139                 :         72 :         pDoc = pDocSh->GetDocument();
    1140         [ +  - ]:         72 :         String aString(sAddress);
    1141                 :         72 :         sal_uInt16 nMask = SCA_VALID;
    1142 [ +  - ][ +  - ]:         72 :         rResFlags = rCellRanges.Parse( sAddress, pDoc, nMask, eConv, cDelimiter );
                 [ +  - ]
    1143         [ +  + ]:         72 :         if ( rResFlags & SCA_VALID )
    1144                 :            :         {
    1145                 :         72 :             return true;
    1146 [ +  - ][ +  + ]:         72 :         }
    1147                 :            :     }
    1148                 :         72 :     return false;
    1149                 :            : }
    1150                 :            : 
    1151                 :         68 : bool getScRangeListForAddress( const rtl::OUString& sName, ScDocShell* pDocSh, ScRange& refRange, ScRangeList& aCellRanges, formula::FormulaGrammar::AddressConvention aConv = formula::FormulaGrammar::CONV_XL_A1 ) throw ( uno::RuntimeException )
    1152                 :            : {
    1153                 :            :     // see if there is a match with a named range
    1154 [ +  - ][ +  - ]:         68 :     uno::Reference< beans::XPropertySet > xProps( pDocSh->GetModel(), uno::UNO_QUERY_THROW );
    1155 [ +  - ][ +  - ]:         68 :     uno::Reference< container::XNameAccess > xNameAccess( xProps->getPropertyValue( rtl::OUString( "NamedRanges" ) ), uno::UNO_QUERY_THROW );
                 [ +  - ]
    1156                 :            :     // Strangly enough you can have Range( "namedRange1, namedRange2, etc," )
    1157                 :            :     // loop around each ',' seperated name
    1158         [ +  - ]:         68 :     std::vector< rtl::OUString > vNames;
    1159                 :         68 :     sal_Int32 nIndex = 0;
    1160         [ +  + ]:         72 :     do
    1161                 :            :     {
    1162                 :         72 :         rtl::OUString aToken = sName.getToken( 0, ',', nIndex );
    1163         [ +  - ]:         72 :         vNames.push_back( aToken );
    1164                 :            :     } while ( nIndex >= 0 );
    1165                 :            : 
    1166         [ -  + ]:         68 :     if ( vNames.empty() )
    1167         [ #  # ]:          0 :         vNames.push_back( sName );
    1168                 :            : 
    1169                 :         68 :     std::vector< rtl::OUString >::iterator it = vNames.begin();
    1170                 :         68 :     std::vector< rtl::OUString >::iterator it_end = vNames.end();
    1171 [ +  - ][ +  + ]:        140 :     for ( ; it != it_end; ++it )
    1172                 :            :     {
    1173                 :            : 
    1174                 :         72 :         formula::FormulaGrammar::AddressConvention eConv = aConv;
    1175                 :            :         // spaces are illegal ( but the user of course can enter them )
    1176                 :         72 :         rtl::OUString sAddress = (*it).trim();
    1177                 :            :         // if a local name ( on the active sheet ) exists this will
    1178                 :            :         // take precedence over a global with the same name
    1179                 :         72 :         bool bLocalName = false;
    1180 [ +  - ][ +  - ]:         72 :         if ( !xNameAccess->hasByName( sAddress ) && pDocSh )
         [ +  - ][ +  - ]
                 [ +  - ]
    1181                 :            :         {
    1182                 :            :             // try a local name
    1183                 :         72 :             ScDocument* pDoc = pDocSh->GetDocument();
    1184         [ +  - ]:         72 :             if ( pDoc )
    1185                 :            :             {
    1186         [ +  - ]:         72 :                 SCTAB nCurTab = pDocSh->GetCurTab();
    1187         [ +  - ]:         72 :                 ScRangeName* pRangeName = pDoc->GetRangeName(nCurTab);
    1188         [ +  - ]:         72 :                 if (pRangeName)
    1189                 :            :                 {
    1190 [ +  - ][ +  - ]:         72 :                     bLocalName = pRangeName->findByUpperName(ScGlobal::pCharClass->uppercase(sAddress)) != NULL;
    1191                 :            :                     // TODO: Handle local names correctly.
    1192                 :            :                     (void)bLocalName;
    1193                 :            :                 }
    1194                 :            :             }
    1195                 :            :         }
    1196                 :         72 :         char aChar = 0;
    1197 [ +  - ][ +  - ]:         72 :         if ( xNameAccess->hasByName( sAddress ) )
                 [ -  + ]
    1198                 :            :         {
    1199 [ #  # ][ #  # ]:          0 :             uno::Reference< sheet::XNamedRange > xNamed( xNameAccess->getByName( sAddress ), uno::UNO_QUERY_THROW );
                 [ #  # ]
    1200 [ #  # ][ #  # ]:          0 :             sAddress = xNamed->getContent();
    1201                 :            :             // As the address comes from OOO, the addressing
    1202                 :            :             // style is may not be XL_A1
    1203         [ #  # ]:          0 :             eConv = pDocSh->GetDocument()->GetAddressConvention();
    1204                 :          0 :             aChar = ';';
    1205                 :            :         }
    1206                 :            : 
    1207                 :         72 :         sal_uInt16 nFlags = 0;
    1208 [ +  - ][ +  + ]:         72 :         if ( !getCellRangesForAddress( nFlags, sAddress, pDocSh, aCellRanges, eConv, aChar ) )
    1209                 :          4 :             return false;
    1210                 :            : 
    1211                 :         68 :         bool bTabFromReferrer = !( nFlags & SCA_TAB_3D );
    1212                 :            : 
    1213 [ +  - ][ +  + ]:        142 :         for ( size_t i = 0, nRanges = aCellRanges.size(); i < nRanges; ++i )
    1214                 :            :         {
    1215         [ +  - ]:         74 :             ScRange* pRange = aCellRanges[ i ];
    1216                 :         74 :             pRange->aStart.SetCol( refRange.aStart.Col() + pRange->aStart.Col() );
    1217                 :         74 :             pRange->aStart.SetRow( refRange.aStart.Row() + pRange->aStart.Row() );
    1218         [ +  + ]:         74 :             pRange->aStart.SetTab( bTabFromReferrer ? refRange.aStart.Tab()  : pRange->aStart.Tab() );
    1219                 :         74 :             pRange->aEnd.SetCol( refRange.aStart.Col() + pRange->aEnd.Col() );
    1220                 :         74 :             pRange->aEnd.SetRow( refRange.aStart.Row() + pRange->aEnd.Row() );
    1221         [ +  + ]:         74 :             pRange->aEnd.SetTab( bTabFromReferrer ? refRange.aEnd.Tab()  : pRange->aEnd.Tab() );
    1222                 :            :         }
    1223         [ +  + ]:         72 :     }
    1224                 :         68 :     return true;
    1225                 :            : }
    1226                 :            : 
    1227                 :            : 
    1228                 :            : ScVbaRange*
    1229                 :         68 : getRangeForName( const uno::Reference< uno::XComponentContext >& xContext, const rtl::OUString& sName, ScDocShell* pDocSh, table::CellRangeAddress& pAddr, formula::FormulaGrammar::AddressConvention eConv = formula::FormulaGrammar::CONV_XL_A1 ) throw ( uno::RuntimeException )
    1230                 :            : {
    1231         [ +  - ]:         68 :     ScRangeList aCellRanges;
    1232                 :         68 :     ScRange refRange;
    1233                 :         68 :     ScUnoConversion::FillScRange( refRange, pAddr );
    1234 [ +  + ][ +  - ]:         68 :     if ( !getScRangeListForAddress ( sName, pDocSh, refRange, aCellRanges, eConv ) )
    1235         [ +  - ]:          4 :         throw uno::RuntimeException();
    1236                 :            :     // Single range
    1237 [ +  - ][ +  + ]:         64 :     if ( aCellRanges.size() == 1 )
    1238                 :            :     {
    1239 [ +  - ][ +  - ]:         62 :         uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( pDocSh, *aCellRanges.front() ) );
         [ +  - ][ +  - ]
    1240         [ +  - ]:         62 :         uno::Reference< XHelperInterface > xFixThisParent = excel::getUnoSheetModuleObj( xRange );
    1241         [ +  - ]:         62 :         return new ScVbaRange( xFixThisParent, xContext, xRange );
    1242                 :            :     }
    1243 [ +  - ][ +  - ]:          2 :     uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( pDocSh, aCellRanges ) );
                 [ +  - ]
    1244                 :            : 
    1245         [ +  - ]:          2 :     uno::Reference< XHelperInterface > xFixThisParent = excel::getUnoSheetModuleObj( xRanges );
    1246 [ +  - ][ +  - ]:         68 :     return new ScVbaRange( xFixThisParent, xContext, xRanges );
    1247                 :            : }
    1248                 :            : 
    1249                 :            : // ----------------------------------------------------------------------------
    1250                 :            : 
    1251                 :            : namespace {
    1252                 :            : 
    1253                 :            : template< typename RangeType >
    1254                 :          0 : inline table::CellRangeAddress lclGetRangeAddress( const uno::Reference< RangeType >& rxCellRange ) throw (uno::RuntimeException)
    1255                 :            : {
    1256 [ #  # ][ #  # ]:          0 :     return uno::Reference< sheet::XCellRangeAddressable >( rxCellRange, uno::UNO_QUERY_THROW )->getRangeAddress();
         [ #  # ][ #  # ]
    1257                 :            : }
    1258                 :            : 
    1259                 :          0 : void lclClearRange( const uno::Reference< table::XCellRange >& rxCellRange ) throw (uno::RuntimeException)
    1260                 :            : {
    1261                 :            :     using namespace ::com::sun::star::sheet::CellFlags;
    1262                 :          0 :     sal_Int32 nFlags = VALUE | DATETIME | STRING | ANNOTATION | FORMULA | HARDATTR | STYLES | EDITATTR | FORMATTED;
    1263         [ #  # ]:          0 :     uno::Reference< sheet::XSheetOperation > xSheetOperation( rxCellRange, uno::UNO_QUERY_THROW );
    1264 [ #  # ][ #  # ]:          0 :     xSheetOperation->clearContents( nFlags );
    1265                 :          0 : }
    1266                 :            : 
    1267                 :          0 : uno::Reference< sheet::XSheetCellRange > lclExpandToMerged( const uno::Reference< table::XCellRange >& rxCellRange, bool bRecursive ) throw (uno::RuntimeException)
    1268                 :            : {
    1269         [ #  # ]:          0 :     uno::Reference< sheet::XSheetCellRange > xNewCellRange( rxCellRange, uno::UNO_QUERY_THROW );
    1270 [ #  # ][ #  # ]:          0 :     uno::Reference< sheet::XSpreadsheet > xSheet( xNewCellRange->getSpreadsheet(), uno::UNO_SET_THROW );
                 [ #  # ]
    1271         [ #  # ]:          0 :     table::CellRangeAddress aNewAddress = lclGetRangeAddress( xNewCellRange );
    1272                 :          0 :     table::CellRangeAddress aOldAddress;
    1273                 :            :     // expand as long as there are new merged ranges included
    1274         [ #  # ]:          0 :     do
           [ #  #  #  # ]
    1275                 :            :     {
    1276                 :          0 :         aOldAddress = aNewAddress;
    1277 [ #  # ][ #  # ]:          0 :         uno::Reference< sheet::XSheetCellCursor > xCursor( xSheet->createCursorByRange( xNewCellRange ), uno::UNO_SET_THROW );
                 [ #  # ]
    1278 [ #  # ][ #  # ]:          0 :         xCursor->collapseToMergedArea();
    1279         [ #  # ]:          0 :         xNewCellRange.set( xCursor, uno::UNO_QUERY_THROW );
    1280         [ #  # ]:          0 :         aNewAddress = lclGetRangeAddress( xNewCellRange );
    1281                 :            :     }
    1282                 :          0 :     while( bRecursive && (aOldAddress != aNewAddress) );
    1283                 :          0 :     return xNewCellRange;
    1284                 :            : }
    1285                 :            : 
    1286                 :          0 : uno::Reference< sheet::XSheetCellRangeContainer > lclExpandToMerged( const uno::Reference< sheet::XSheetCellRangeContainer >& rxCellRanges, bool bRecursive ) throw (uno::RuntimeException)
    1287                 :            : {
    1288         [ #  # ]:          0 :     if( !rxCellRanges.is() )
    1289         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString(  "Missing cell ranges object"  ), uno::Reference< uno::XInterface >() );
    1290 [ #  # ][ #  # ]:          0 :     sal_Int32 nCount = rxCellRanges->getCount();
    1291         [ #  # ]:          0 :     if( nCount < 1 )
    1292         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString(  "Missing cell ranges object"  ), uno::Reference< uno::XInterface >() );
    1293                 :            : 
    1294         [ #  # ]:          0 :     ScRangeList aScRanges;
    1295         [ #  # ]:          0 :     for( sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex )
    1296                 :            :     {
    1297 [ #  # ][ #  # ]:          0 :         uno::Reference< table::XCellRange > xRange( rxCellRanges->getByIndex( nIndex ), uno::UNO_QUERY_THROW );
                 [ #  # ]
    1298 [ #  # ][ #  # ]:          0 :         table::CellRangeAddress aRangeAddr = lclGetRangeAddress( lclExpandToMerged( xRange, bRecursive ) );
    1299                 :          0 :         ScRange aScRange;
    1300                 :          0 :         ScUnoConversion::FillScRange( aScRange, aRangeAddr );
    1301         [ #  # ]:          0 :         aScRanges.Append( aScRange );
    1302                 :          0 :     }
    1303 [ #  # ][ #  # ]:          0 :     return new ScCellRangesObj( excel::GetDocShellFromRanges( rxCellRanges ), aScRanges );
         [ #  # ][ #  # ]
                 [ #  # ]
    1304                 :            : }
    1305                 :            : 
    1306                 :          0 : void lclExpandAndMerge( const uno::Reference< table::XCellRange >& rxCellRange, bool bMerge ) throw (uno::RuntimeException)
    1307                 :            : {
    1308 [ #  # ][ #  # ]:          0 :     uno::Reference< util::XMergeable > xMerge( lclExpandToMerged( rxCellRange, true ), uno::UNO_QUERY_THROW );
    1309                 :            :     // Calc cannot merge over merged ranges, always unmerge first
    1310 [ #  # ][ #  # ]:          0 :     xMerge->merge( false );
    1311         [ #  # ]:          0 :     if( bMerge )
    1312                 :            :     {
    1313                 :            :         // clear all contents of the covered cells (not the top-left cell)
    1314         [ #  # ]:          0 :         table::CellRangeAddress aRangeAddr = lclGetRangeAddress( rxCellRange );
    1315                 :          0 :         sal_Int32 nLastColIdx = aRangeAddr.EndColumn - aRangeAddr.StartColumn;
    1316                 :          0 :         sal_Int32 nLastRowIdx = aRangeAddr.EndRow - aRangeAddr.StartRow;
    1317                 :            :         // clear cells of top row, right of top-left cell
    1318         [ #  # ]:          0 :         if( nLastColIdx > 0 )
    1319 [ #  # ][ #  # ]:          0 :             lclClearRange( rxCellRange->getCellRangeByPosition( 1, 0, nLastColIdx, 0 ) );
                 [ #  # ]
    1320                 :            :         // clear all rows below top row
    1321         [ #  # ]:          0 :         if( nLastRowIdx > 0 )
    1322 [ #  # ][ #  # ]:          0 :             lclClearRange( rxCellRange->getCellRangeByPosition( 0, 1, nLastColIdx, nLastRowIdx ) );
                 [ #  # ]
    1323                 :            :         // merge the range
    1324 [ #  # ][ #  # ]:          0 :         xMerge->merge( sal_True );
    1325                 :          0 :     }
    1326                 :          0 : }
    1327                 :            : 
    1328                 :          0 : util::TriState lclGetMergedState( const uno::Reference< table::XCellRange >& rxCellRange ) throw (uno::RuntimeException)
    1329                 :            : {
    1330                 :            :     /*  1) Check if range is completely inside one single merged range. To do
    1331                 :            :         this, try to extend from top-left cell only (not from entire range).
    1332                 :            :         This will exclude cases where this range consists of several merged
    1333                 :            :         ranges (or parts of them). */
    1334         [ #  # ]:          0 :     table::CellRangeAddress aRangeAddr = lclGetRangeAddress( rxCellRange );
    1335 [ #  # ][ #  # ]:          0 :     uno::Reference< table::XCellRange > xTopLeft( rxCellRange->getCellRangeByPosition( 0, 0, 0, 0 ), uno::UNO_SET_THROW );
                 [ #  # ]
    1336 [ #  # ][ #  # ]:          0 :     uno::Reference< sheet::XSheetCellRange > xExpanded( lclExpandToMerged( xTopLeft, false ), uno::UNO_SET_THROW );
    1337         [ #  # ]:          0 :     table::CellRangeAddress aExpAddr = lclGetRangeAddress( xExpanded );
    1338                 :            :     // check that expanded range has more than one cell (really merged)
    1339 [ #  # ][ #  # ]:          0 :     if( ((aExpAddr.StartColumn < aExpAddr.EndColumn) || (aExpAddr.StartRow < aExpAddr.EndRow)) && ScUnoConversion::Contains( aExpAddr, aRangeAddr ) )
         [ #  # ][ #  # ]
    1340                 :          0 :         return util::TriState_YES;
    1341                 :            : 
    1342                 :            :     /*  2) Check if this range contains any merged cells (completely or
    1343                 :            :         partly). This seems to be hardly possible via API, as
    1344                 :            :         XMergeable::getIsMerged() returns only true, if the top-left cell of a
    1345                 :            :         merged range is part of this range, so cases where just the lower part
    1346                 :            :         of a merged range is part of this range are not covered. */
    1347                 :          0 :     ScRange aScRange;
    1348                 :          0 :     ScUnoConversion::FillScRange( aScRange, aRangeAddr );
    1349 [ #  # ][ #  # ]:          0 :     bool bHasMerged = excel::GetDocumentFromRange( rxCellRange )->HasAttrib( aScRange, HASATTR_MERGED | HASATTR_OVERLAPPED );
    1350         [ #  # ]:          0 :     return bHasMerged ? util::TriState_INDETERMINATE : util::TriState_NO;
    1351                 :            : }
    1352                 :            : 
    1353                 :            : } // namespace
    1354                 :            : 
    1355                 :            : // ----------------------------------------------------------------------------
    1356                 :            : 
    1357                 :            : css::uno::Reference< excel::XRange >
    1358                 :          0 : ScVbaRange::getRangeObjectForName(
    1359                 :            :         const uno::Reference< uno::XComponentContext >& xContext, const rtl::OUString& sRangeName,
    1360                 :            :         ScDocShell* pDocSh, formula::FormulaGrammar::AddressConvention eConv ) throw ( uno::RuntimeException )
    1361                 :            : {
    1362                 :          0 :     table::CellRangeAddress refAddr;
    1363 [ #  # ][ #  # ]:          0 :     return getRangeForName( xContext, sRangeName, pDocSh, refAddr, eConv );
                 [ #  # ]
    1364                 :            : }
    1365                 :            : 
    1366                 :          0 : table::CellAddress ScVbaRange::getLeftUpperCellAddress()
    1367                 :            : {
    1368                 :          0 :     table::CellAddress aCellAddress;
    1369                 :          0 :     uno::Reference< table::XCellRange > xCellRange = mxRange;
    1370 [ #  # ][ #  # ]:          0 :     if ( mxRanges.is() && m_Areas.is() && m_Areas->getCount() > 1 )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1371                 :            :     {
    1372         [ #  # ]:          0 :         uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY );
    1373 [ #  # ][ #  # ]:          0 :         if ( xIndex.is() && xIndex->getCount() > 0 )
         [ #  # ][ #  # ]
                 [ #  # ]
    1374                 :            :         {
    1375 [ #  # ][ #  # ]:          0 :             xCellRange.set( xIndex->getByIndex( 0 ), uno::UNO_QUERY );
                 [ #  # ]
    1376                 :          0 :         }
    1377                 :            :     }
    1378         [ #  # ]:          0 :     if ( xCellRange.is() )
    1379                 :            :     {
    1380 [ #  # ][ #  # ]:          0 :         uno::Reference< sheet::XCellAddressable > xCellAddr( xCellRange->getCellByPosition( 0, 0 ), uno::UNO_QUERY );
                 [ #  # ]
    1381         [ #  # ]:          0 :         if ( xCellAddr.is() )
    1382                 :            :         {
    1383 [ #  # ][ #  # ]:          0 :             aCellAddress = xCellAddr->getCellAddress();
    1384                 :          0 :         }
    1385                 :            :     }
    1386                 :          0 :     return aCellAddress;
    1387                 :            : }
    1388                 :            : 
    1389                 :          0 : table::CellRangeAddress getCellRangeAddressForVBARange( const uno::Any& aParam, ScDocShell* pDocSh,  formula::FormulaGrammar::AddressConvention aConv = formula::FormulaGrammar::CONV_XL_A1) throw ( uno::RuntimeException )
    1390                 :            : {
    1391                 :          0 :     uno::Reference< table::XCellRange > xRangeParam;
    1392      [ #  #  # ]:          0 :     switch ( aParam.getValueTypeClass() )
    1393                 :            :     {
    1394                 :            :         case uno::TypeClass_STRING:
    1395                 :            :         {
    1396                 :          0 :             rtl::OUString rString;
    1397                 :          0 :             aParam >>= rString;
    1398         [ #  # ]:          0 :             ScRangeList aCellRanges;
    1399                 :          0 :             ScRange refRange;
    1400 [ #  # ][ #  # ]:          0 :             if ( getScRangeListForAddress ( rString, pDocSh, refRange, aCellRanges, aConv ) )
    1401                 :            :             {
    1402 [ #  # ][ #  # ]:          0 :                 if ( aCellRanges.size() == 1 )
    1403                 :            :                 {
    1404                 :          0 :                     table::CellRangeAddress aRangeAddress;
    1405         [ #  # ]:          0 :                     ScUnoConversion::FillApiRange( aRangeAddress, *aCellRanges.front() );
    1406                 :          0 :                     return aRangeAddress;
    1407                 :            :                 }
    1408 [ #  # ][ #  # ]:          0 :             }
                 [ #  # ]
    1409                 :            :         }
    1410                 :            :         case uno::TypeClass_INTERFACE:
    1411                 :            :         {
    1412                 :          0 :             uno::Reference< excel::XRange > xRange;
    1413         [ #  # ]:          0 :             aParam >>= xRange;
    1414         [ #  # ]:          0 :             if ( xRange.is() )
    1415                 :            :             {
    1416 [ #  # ][ #  # ]:          0 :                 ScVbaRange* pRange = dynamic_cast< ScVbaRange* >( xRange.get() );
    1417 [ #  # ][ #  # ]:          0 :                 if ( pRange && pDocSh && pRange->getScDocument() != pDocSh->GetDocument() )
         [ #  # ][ #  # ]
                 [ #  # ]
    1418                 :            :                 {
    1419         [ #  # ]:          0 :                     throw uno::RuntimeException( rtl::OUString( "Invalid range"  ), uno::Reference< uno::XInterface >() );
    1420                 :            :                 }
    1421 [ #  # ][ #  # ]:          0 :                 xRange->getCellRange() >>= xRangeParam;
                 [ #  # ]
    1422                 :            :             }
    1423                 :          0 :             break;
    1424                 :            :         }
    1425                 :            :         default:
    1426         [ #  # ]:          0 :             throw uno::RuntimeException( rtl::OUString( "Can't extact CellRangeAddress from type"  ), uno::Reference< uno::XInterface >() );
    1427                 :            :     }
    1428         [ #  # ]:          0 :     return lclGetRangeAddress( xRangeParam );
    1429                 :            : }
    1430                 :            : 
    1431                 :            : uno::Reference< XCollection >
    1432                 :          0 : lcl_setupBorders( const uno::Reference< excel::XRange >& xParentRange, const uno::Reference<uno::XComponentContext>& xContext,  const uno::Reference< table::XCellRange >& xRange  ) throw( uno::RuntimeException )
    1433                 :            : {
    1434         [ #  # ]:          0 :     uno::Reference< XHelperInterface > xParent( xParentRange, uno::UNO_QUERY_THROW );
    1435         [ #  # ]:          0 :     ScDocument* pDoc = excel::GetDocumentFromRange(xRange);
    1436         [ #  # ]:          0 :     if ( !pDoc )
    1437         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString(  "Failed to access document from shell"  ), uno::Reference< uno::XInterface >() );
    1438                 :          0 :     ScVbaPalette aPalette( pDoc->GetDocumentShell() );
    1439 [ #  # ][ #  # ]:          0 :      uno::Reference< XCollection > borders( new ScVbaBorders( xParent, xContext, xRange, aPalette ) );
                 [ #  # ]
    1440                 :          0 :     return borders;
    1441                 :            : }
    1442                 :            : 
    1443                 :          0 : void lcl_NotifyRangeChanges( const uno::Reference< frame::XModel >& xModel, ScCellRangesBase* pUnoRangesBase )
    1444                 :            : {
    1445 [ #  # ][ #  # ]:          0 :     if ( xModel.is() && pUnoRangesBase )
                 [ #  # ]
    1446                 :            :     {
    1447         [ #  # ]:          0 :         ScModelObj* pModelObj = ScModelObj::getImplementation( xModel );
    1448                 :          0 :         const ScRangeList& aCellRanges = pUnoRangesBase->GetRangeList();
    1449 [ #  # ][ #  # ]:          0 :         if ( pModelObj && pModelObj->HasChangesListeners() )
                 [ #  # ]
    1450                 :            :         {
    1451         [ #  # ]:          0 :             pModelObj->NotifyChanges( ::rtl::OUString(  "cell-change"  ), aCellRanges );
    1452                 :            :         }
    1453                 :            :     }
    1454                 :          0 : }
    1455                 :            : 
    1456                 :          0 : ScVbaRange::ScVbaRange( uno::Sequence< uno::Any> const & args,
    1457 [ #  # ][ #  # ]:          0 :     uno::Reference< uno::XComponentContext> const & xContext )  throw ( lang::IllegalArgumentException ) : ScVbaRange_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0 ), xContext, getXSomethingFromArgs< beans::XPropertySet >( args, 1, false ), excel::GetModelFromRange( getXSomethingFromArgs< uno::XInterface >( args, 1 ) ), true ), mbIsRows( false ), mbIsColumns( false )
         [ #  # ][ #  # ]
    1458                 :            : {
    1459         [ #  # ]:          0 :     mxRange.set( mxPropertySet, uno::UNO_QUERY );
    1460         [ #  # ]:          0 :     mxRanges.set( mxPropertySet, uno::UNO_QUERY );
    1461                 :          0 :     uno::Reference< container::XIndexAccess >  xIndex;
    1462         [ #  # ]:          0 :     if ( mxRange.is() )
    1463                 :            :     {
    1464 [ #  # ][ #  # ]:          0 :         xIndex = new SingleRangeIndexAccess( mxParent, mxContext, mxRange );
         [ #  # ][ #  # ]
    1465                 :            :     }
    1466         [ #  # ]:          0 :     else if ( mxRanges.is() )
    1467                 :            :     {
    1468         [ #  # ]:          0 :         xIndex.set( mxRanges, uno::UNO_QUERY_THROW );
    1469                 :            :     }
    1470 [ #  # ][ #  # ]:          0 :     m_Areas = new ScVbaRangeAreas( mxParent, mxContext, xIndex, mbIsRows, mbIsColumns );
         [ #  # ][ #  # ]
    1471                 :          0 : }
    1472                 :            : 
    1473                 :        212 : ScVbaRange::ScVbaRange( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< table::XCellRange >& xRange, sal_Bool bIsRows, sal_Bool bIsColumns ) throw( lang::IllegalArgumentException )
    1474                 :        212 : : ScVbaRange_BASE( xParent, xContext, uno::Reference< beans::XPropertySet >( xRange, uno::UNO_QUERY_THROW ), excel::GetModelFromRange( xRange), true ), mxRange( xRange ),
    1475                 :            :                 mbIsRows( bIsRows ),
    1476 [ +  - ][ +  - ]:        212 :                 mbIsColumns( bIsColumns )
    1477                 :            : {
    1478         [ -  + ]:        212 :     if  ( !xContext.is() )
    1479         [ #  # ]:          0 :         throw lang::IllegalArgumentException( rtl::OUString(  "context is not set "  ), uno::Reference< uno::XInterface >() , 1 );
    1480         [ -  + ]:        212 :     if  ( !xRange.is() )
    1481         [ #  # ]:          0 :         throw lang::IllegalArgumentException( rtl::OUString(  "range is not set "  ), uno::Reference< uno::XInterface >() , 1 );
    1482                 :            : 
    1483 [ +  - ][ +  - ]:        212 :     uno::Reference< container::XIndexAccess > xIndex( new SingleRangeIndexAccess( mxParent, mxContext, xRange ) );
         [ +  - ][ +  - ]
    1484 [ +  - ][ +  - ]:        212 :     m_Areas = new ScVbaRangeAreas( mxParent, mxContext, xIndex, mbIsRows, mbIsColumns );
         [ +  - ][ +  - ]
    1485                 :            : 
    1486                 :        212 : }
    1487                 :            : 
    1488                 :          2 : ScVbaRange::ScVbaRange( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< sheet::XSheetCellRangeContainer >& xRanges,  sal_Bool bIsRows, sal_Bool bIsColumns  ) throw ( lang::IllegalArgumentException )
    1489 [ +  - ][ +  - ]:          2 : : ScVbaRange_BASE( xParent, xContext, uno::Reference< beans::XPropertySet >( xRanges, uno::UNO_QUERY_THROW ), excel::GetModelFromRange( uno::Reference< uno::XInterface >( xRanges, uno::UNO_QUERY_THROW ) ), true ), mxRanges( xRanges ),mbIsRows( bIsRows ), mbIsColumns( bIsColumns )
                 [ +  - ]
    1490                 :            : 
    1491                 :            : {
    1492         [ +  - ]:          2 :     uno::Reference< container::XIndexAccess >  xIndex( mxRanges, uno::UNO_QUERY_THROW );
    1493 [ +  - ][ +  - ]:          2 :     m_Areas  = new ScVbaRangeAreas( xParent, mxContext, xIndex, mbIsRows, mbIsColumns );
                 [ +  - ]
    1494                 :            : 
    1495                 :          2 : }
    1496                 :            : 
    1497                 :        214 : ScVbaRange::~ScVbaRange()
    1498                 :            : {
    1499         [ -  + ]:        428 : }
    1500                 :            : 
    1501                 :          0 : uno::Reference< XCollection >& ScVbaRange::getBorders()
    1502                 :            : {
    1503         [ #  # ]:          0 :     if ( !m_Borders.is() )
    1504                 :            :     {
    1505 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(1) ), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    1506 [ #  # ][ #  # ]:          0 :         m_Borders = lcl_setupBorders( this, mxContext, uno::Reference< table::XCellRange >( xRange->getCellRange(), uno::UNO_QUERY_THROW ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1507                 :            :     }
    1508                 :          0 :     return m_Borders;
    1509                 :            : }
    1510                 :            : 
    1511                 :            : void
    1512                 :          8 : ScVbaRange::visitArray( ArrayVisitor& visitor )
    1513                 :            : {
    1514         [ +  - ]:          8 :     uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY_THROW );
    1515 [ +  - ][ +  - ]:          8 :     sal_Int32 nRowCount = xColumnRowRange->getRows()->getCount();
         [ +  - ][ +  - ]
    1516 [ +  - ][ +  - ]:          8 :     sal_Int32 nColCount = xColumnRowRange->getColumns()->getCount();
         [ +  - ][ +  - ]
    1517         [ +  + ]:         16 :     for ( sal_Int32 i=0; i<nRowCount; ++i )
    1518                 :            :     {
    1519         [ +  + ]:         16 :         for ( sal_Int32 j=0; j<nColCount; ++j )
    1520                 :            :         {
    1521 [ +  - ][ +  - ]:          8 :             uno::Reference< table::XCell > xCell( mxRange->getCellByPosition( j, i ), uno::UNO_QUERY_THROW );
                 [ +  - ]
    1522                 :            : 
    1523         [ +  - ]:          8 :             visitor.visitNode( i, j, xCell );
    1524                 :          8 :         }
    1525                 :          8 :     }
    1526                 :          8 : }
    1527                 :            : 
    1528                 :          0 : uno::Any SAL_CALL ScVbaRange::getName() throw (uno::RuntimeException)
    1529                 :            : {
    1530                 :          0 :     uno::Reference< excel::XName > xName;
    1531                 :            : 
    1532         [ #  # ]:          0 :     ScDocShell* pDocShell = getScDocShell();
    1533 [ #  # ][ #  # ]:          0 :     uno::Reference< frame::XModel > xModel = pDocShell ? pDocShell->GetModel() : NULL;
                 [ #  # ]
    1534         [ #  # ]:          0 :     if ( !xModel.is() )
    1535                 :            :     {
    1536         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString( "Invalid document" ), uno::Reference< uno::XInterface >() );
    1537                 :            :     }
    1538         [ #  # ]:          0 :     uno::Reference< beans::XPropertySet > xPropertySet( xModel, uno::UNO_QUERY_THROW );
    1539 [ #  # ][ #  # ]:          0 :     uno::Reference< sheet::XNamedRanges > xNamedRanges( xPropertySet->getPropertyValue( rtl::OUString("NamedRanges")) , uno::UNO_QUERY_THROW );
                 [ #  # ]
    1540                 :            : 
    1541 [ #  # ][ #  # ]:          0 :     uno::Reference< excel::XNames > xNames( new ScVbaNames( uno::Reference< XHelperInterface >(), mxContext , xNamedRanges , xModel ) );
                 [ #  # ]
    1542 [ #  # ][ #  # ]:          0 :     sal_Int32 nCount = xNames->getCount();
    1543         [ #  # ]:          0 :     ScCellRangesBase* pUnoRangesBase = getCellRangesBase();
    1544 [ #  # ][ #  # ]:          0 :     if ( pUnoRangesBase && nCount > 0 )
    1545                 :            :     {
    1546         [ #  # ]:          0 :         ScRangeList aRangeList = pUnoRangesBase->GetRangeList();
    1547         [ #  # ]:          0 :         for ( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
    1548                 :            :         {
    1549 [ #  # ][ #  # ]:          0 :             uno::Reference< excel::XName > xTmpName( xNames->Item( uno::makeAny( nIndex + 1 ), uno::Any() ), uno::UNO_QUERY );
         [ #  # ][ #  # ]
    1550         [ #  # ]:          0 :             if ( xTmpName.is() )
    1551                 :            :             {
    1552                 :            :                 try
    1553                 :            :                 {
    1554 [ #  # ][ #  # ]:          0 :                     uno::Reference< excel::XRange > xRange = xTmpName->getRefersToRange();
    1555         [ #  # ]:          0 :                     if ( xRange.is() )
    1556                 :            :                     {
    1557 [ #  # ][ #  # ]:          0 :                         ScVbaRange* pRange = dynamic_cast< ScVbaRange* >( xRange.get() );
    1558 [ #  # ][ #  # ]:          0 :                         ScCellRangesBase* pCurRangesBase = pRange ? pRange->getCellRangesBase() : NULL;
    1559 [ #  # ][ #  # ]:          0 :                         if ( pCurRangesBase && aRangeList ==  pCurRangesBase->GetRangeList() )
         [ #  # ][ #  # ]
    1560                 :            :                         {
    1561         [ #  # ]:          0 :                             xName = xTmpName;
    1562                 :            :                             break;
    1563                 :            :                         }
    1564 [ #  # ][ #  # ]:          0 :                     }
    1565                 :            :                 }
    1566         [ #  # ]:          0 :                 catch (const uno::Exception&)
    1567                 :            :                 {
    1568                 :            :                 }
    1569                 :            :             }
    1570 [ #  # ][ #  # ]:          0 :         }
    1571                 :            :     }
    1572                 :            : 
    1573         [ #  # ]:          0 :     return uno::makeAny( xName );
    1574                 :            : }
    1575                 :            : 
    1576                 :            : void
    1577                 :          0 : ScVbaRange::setName( const uno::Any& aName ) throw (uno::RuntimeException)
    1578                 :            : {
    1579                 :          0 :     uno::Reference< excel::XName > xName;
    1580                 :            : 
    1581         [ #  # ]:          0 :     ScDocShell* pDocShell = getScDocShell();
    1582 [ #  # ][ #  # ]:          0 :     uno::Reference< frame::XModel > xModel = pDocShell ? pDocShell->GetModel() : NULL;
                 [ #  # ]
    1583         [ #  # ]:          0 :     if ( !xModel.is() )
    1584                 :            :     {
    1585         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString( "Invalid document" ), uno::Reference< uno::XInterface >() );
    1586                 :            :     }
    1587         [ #  # ]:          0 :     uno::Reference< beans::XPropertySet > xPropertySet( xModel, uno::UNO_QUERY_THROW );
    1588 [ #  # ][ #  # ]:          0 :     uno::Reference< sheet::XNamedRanges > xNamedRanges( xPropertySet->getPropertyValue( rtl::OUString("NamedRanges")) , uno::UNO_QUERY_THROW );
                 [ #  # ]
    1589                 :            : 
    1590 [ #  # ][ #  # ]:          0 :     uno::Reference< excel::XNames > xNames( new ScVbaNames( uno::Reference< XHelperInterface >(), mxContext , xNamedRanges , xModel ) );
                 [ #  # ]
    1591                 :            : 
    1592                 :          0 :     uno::Any aDummy;
    1593                 :            :     //uno::Any aRefersTo;
    1594                 :            :     //    aRefersTo <<= uno::Reference< excel::XRange >(this, uno::UNO_QUERY);
    1595         [ #  # ]:          0 :     xNames->Add(aName, getCellRange(), aDummy, aDummy, aDummy, aDummy,
    1596 [ #  # ][ #  # ]:          0 :                 aDummy, aDummy, aDummy, aDummy, aDummy);
    1597                 :          0 : }
    1598                 :            : 
    1599                 :            : uno::Any
    1600                 :          2 : ScVbaRange::getValue( ValueGetter& valueGetter) throw (uno::RuntimeException)
    1601                 :            : {
    1602         [ +  - ]:          2 :     uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY_THROW );
    1603                 :            :     // single cell range
    1604 [ +  - ][ +  - ]:          2 :     if ( isSingleCellRange() )
    1605                 :            :     {
    1606         [ +  - ]:          2 :         visitArray( valueGetter );
    1607         [ +  - ]:          2 :         return valueGetter.getValue();
    1608                 :            :     }
    1609 [ #  # ][ #  # ]:          0 :     sal_Int32 nRowCount = xColumnRowRange->getRows()->getCount();
         [ #  # ][ #  # ]
    1610 [ #  # ][ #  # ]:          0 :     sal_Int32 nColCount = xColumnRowRange->getColumns()->getCount();
         [ #  # ][ #  # ]
    1611                 :            :     // multi cell range ( return array )
    1612         [ #  # ]:          0 :     Dim2ArrayValueGetter arrayGetter( nRowCount, nColCount, valueGetter );
    1613         [ #  # ]:          0 :     visitArray( arrayGetter );
    1614         [ #  # ]:          2 :     return uno::makeAny( script::ArrayWrapper( false, arrayGetter.getValue() ) );
    1615                 :            : }
    1616                 :            : 
    1617                 :            : uno::Any SAL_CALL
    1618                 :          2 : ScVbaRange::getValue() throw (uno::RuntimeException)
    1619                 :            : {
    1620                 :            :     // #TODO code within the test below "if ( m_Areas.... " can be removed
    1621                 :            :     // Test is performed only because m_xRange is NOT set to be
    1622                 :            :     // the first range in m_Areas ( to force failure while
    1623                 :            :     // the implementations for each method are being updated )
    1624 [ +  - ][ +  - ]:          2 :     if ( m_Areas->getCount() > 1 )
                 [ -  + ]
    1625                 :            :     {
    1626 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
    1627 [ #  # ][ #  # ]:          0 :         return xRange->getValue();
    1628                 :            :     }
    1629                 :            : 
    1630                 :          2 :     CellValueGetter valueGetter;
    1631         [ +  - ]:          2 :     return getValue( valueGetter );
    1632                 :            : 
    1633                 :            : }
    1634                 :            : 
    1635                 :            : 
    1636                 :            : void
    1637                 :          6 : ScVbaRange::setValue( const uno::Any& aValue, ValueSetter& valueSetter, bool bFireEvent ) throw (uno::RuntimeException)
    1638                 :            : {
    1639                 :          6 :     uno::TypeClass aClass = aValue.getValueTypeClass();
    1640         [ -  + ]:          6 :     if ( aClass == uno::TypeClass_SEQUENCE )
    1641                 :            :     {
    1642         [ #  # ]:          0 :         uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext );
    1643                 :          0 :         uno::Any aConverted;
    1644                 :            :         try
    1645                 :            :         {
    1646                 :            :             // test for single dimension, could do
    1647                 :            :             // with a better test than this
    1648         [ #  # ]:          0 :             if ( aValue.getValueTypeName().indexOf('[') ==  aValue.getValueTypeName().lastIndexOf('[') )
    1649                 :            :             {
    1650 [ #  # ][ #  # ]:          0 :                 aConverted = xConverter->convertTo( aValue, getCppuType((uno::Sequence< uno::Any >*)0) );
                 [ #  # ]
    1651         [ #  # ]:          0 :                 Dim1ArrayValueSetter setter( aConverted, valueSetter );
    1652 [ #  # ][ #  # ]:          0 :                 visitArray( setter );
    1653                 :            :             }
    1654                 :            :             else
    1655                 :            :             {
    1656 [ #  # ][ #  # ]:          0 :                 aConverted = xConverter->convertTo( aValue, getCppuType((uno::Sequence< uno::Sequence< uno::Any > >*)0) );
                 [ #  # ]
    1657         [ #  # ]:          0 :                 Dim2ArrayValueSetter setter( aConverted, valueSetter );
    1658 [ #  # ][ #  # ]:          0 :                 visitArray( setter );
                 [ #  # ]
    1659                 :            :             }
    1660                 :            :         }
    1661         [ #  # ]:          0 :         catch ( const uno::Exception& e )
    1662                 :            :         {
    1663                 :            :             OSL_TRACE("Bahhh, caught exception %s",
    1664                 :            :                 rtl::OUStringToOString( e.Message,
    1665                 :            :                     RTL_TEXTENCODING_UTF8 ).getStr() );
    1666                 :          0 :         }
    1667                 :            :     }
    1668                 :            :     else
    1669                 :            :     {
    1670                 :          6 :         visitArray( valueSetter );
    1671                 :            :     }
    1672         [ +  - ]:          6 :     if( bFireEvent ) fireChangeEvent();
    1673                 :          6 : }
    1674                 :            : 
    1675                 :            : void SAL_CALL
    1676                 :          6 : ScVbaRange::setValue( const uno::Any  &aValue ) throw (uno::RuntimeException)
    1677                 :            : {
    1678                 :            :     // If this is a multiple selection apply setValue over all areas
    1679 [ +  - ][ +  - ]:          6 :     if ( m_Areas->getCount() > 1 )
                 [ -  + ]
    1680                 :            :     {
    1681         [ #  # ]:          0 :         AreasVisitor aVisitor( m_Areas );
    1682                 :          0 :         RangeValueProcessor valueProcessor( aValue );
    1683         [ #  # ]:          0 :         aVisitor.visit( valueProcessor );
    1684         [ #  # ]:          6 :         return;
    1685                 :            :     }
    1686                 :          6 :     CellValueSetter valueSetter( aValue );
    1687         [ +  - ]:          6 :     setValue( aValue, valueSetter, true );
    1688                 :            : 
    1689                 :            : #if 0 // TODO: Noel, do we still need this?
    1690                 :            :     // Fires the range change event.
    1691                 :            :     lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() );
    1692                 :            : #endif
    1693                 :            : }
    1694                 :            : 
    1695                 :            : void SAL_CALL
    1696                 :          2 : ScVbaRange::Clear() throw (uno::RuntimeException)
    1697                 :            : {
    1698                 :            :     using namespace ::com::sun::star::sheet::CellFlags;
    1699                 :          2 :     sal_Int32 nFlags = VALUE | DATETIME | STRING | FORMULA | HARDATTR | EDITATTR | FORMATTED;
    1700                 :          2 :     ClearContents( nFlags, true );
    1701                 :            : 
    1702                 :            : #if 0 // TODO: do we still need this?
    1703                 :            :     // Fires the range change event.
    1704                 :            :     lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() );
    1705                 :            : #endif
    1706                 :          2 : }
    1707                 :            : 
    1708                 :            : //helper ClearContent
    1709                 :            : void
    1710                 :          2 : ScVbaRange::ClearContents( sal_Int32 nFlags, bool bFireEvent ) throw (uno::RuntimeException)
    1711                 :            : {
    1712                 :            :     // #TODO code within the test below "if ( m_Areas.... " can be removed
    1713                 :            :     // Test is performed only because m_xRange is NOT set to be
    1714                 :            :     // the first range in m_Areas ( to force failure while
    1715                 :            :     // the implementations for each method are being updated )
    1716 [ +  - ][ +  - ]:          2 :     if ( m_Areas->getCount() > 1 )
                 [ -  + ]
    1717                 :            :     {
    1718 [ #  # ][ #  # ]:          0 :         sal_Int32 nItems = m_Areas->getCount();
    1719         [ #  # ]:          0 :         for ( sal_Int32 index=1; index <= nItems; ++index )
    1720                 :            :         {
    1721 [ #  # ][ #  # ]:          0 :             uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    1722         [ #  # ]:          0 :             ScVbaRange* pRange = getImplementation( xRange );
    1723         [ #  # ]:          0 :             if ( pRange )
    1724         [ #  # ]:          0 :                 pRange->ClearContents( nFlags, false ); // do not fire for single ranges
    1725                 :          0 :         }
    1726                 :            :         // fire change event for the entire range list
    1727 [ #  # ][ #  # ]:          0 :         if( bFireEvent ) fireChangeEvent();
    1728                 :          2 :         return;
    1729                 :            :     }
    1730                 :            : 
    1731                 :            : 
    1732         [ +  - ]:          2 :     uno::Reference< sheet::XSheetOperation > xSheetOperation(mxRange, uno::UNO_QUERY_THROW);
    1733 [ +  - ][ +  - ]:          2 :     xSheetOperation->clearContents( nFlags );
    1734 [ +  - ][ +  - ]:          2 :     if( bFireEvent ) fireChangeEvent();
    1735                 :            : }
    1736                 :            : 
    1737                 :            : void SAL_CALL
    1738                 :          0 : ScVbaRange::ClearComments() throw (uno::RuntimeException)
    1739                 :            : {
    1740                 :          0 :     ClearContents( sheet::CellFlags::ANNOTATION, false );
    1741                 :          0 : }
    1742                 :            : 
    1743                 :            : void SAL_CALL
    1744                 :          0 : ScVbaRange::ClearContents() throw (uno::RuntimeException)
    1745                 :            : {
    1746                 :            :     sal_Int32 nClearFlags = ( sheet::CellFlags::VALUE |
    1747                 :            :         sheet::CellFlags::STRING |  sheet::CellFlags::DATETIME |
    1748                 :          0 :         sheet::CellFlags::FORMULA );
    1749                 :          0 :     ClearContents( nClearFlags, true );
    1750                 :            : 
    1751                 :            : #if 0 // TODO: do we still need this?
    1752                 :            :     // Fires the range change event.
    1753                 :            :     lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() );
    1754                 :            : #endif
    1755                 :          0 : }
    1756                 :            : 
    1757                 :            : void SAL_CALL
    1758                 :          0 : ScVbaRange::ClearFormats() throw (uno::RuntimeException)
    1759                 :            : {
    1760                 :            :     //FIXME: need to check if we need to combine sheet::CellFlags::FORMATTED
    1761                 :          0 :     sal_Int32 nClearFlags = sheet::CellFlags::HARDATTR | sheet::CellFlags::FORMATTED | sheet::CellFlags::EDITATTR;
    1762                 :          0 :     ClearContents( nClearFlags, false );
    1763                 :            : 
    1764                 :            : #if 0 // TODO: do we still need this?
    1765                 :            :     // Fires the range change event.
    1766                 :            :     lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() );
    1767                 :            : #endif
    1768                 :          0 : }
    1769                 :            : 
    1770                 :            : void
    1771                 :          0 : ScVbaRange::setFormulaValue( const uno::Any& rFormula, formula::FormulaGrammar::Grammar eGram, bool bFireEvent ) throw (uno::RuntimeException)
    1772                 :            : {
    1773                 :            :     // If this is a multiple selection apply setFormula over all areas
    1774 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    1775                 :            :     {
    1776         [ #  # ]:          0 :         AreasVisitor aVisitor( m_Areas );
    1777                 :          0 :         RangeFormulaProcessor valueProcessor( rFormula );
    1778         [ #  # ]:          0 :         aVisitor.visit( valueProcessor );
    1779         [ #  # ]:          0 :         return;
    1780                 :            :     }
    1781         [ #  # ]:          0 :     CellFormulaValueSetter formulaValueSetter( rFormula, getScDocument(), eGram );
    1782         [ #  # ]:          0 :     setValue( rFormula, formulaValueSetter, bFireEvent );
    1783                 :            : 
    1784                 :            : #if 0 // TODO: ditto
    1785                 :            :     // Fires the range change event.
    1786                 :            :     lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() );
    1787                 :            : #endif
    1788                 :            : }
    1789                 :            : 
    1790                 :            : uno::Any
    1791                 :          0 : ScVbaRange::getFormulaValue( formula::FormulaGrammar::Grammar eGram ) throw (uno::RuntimeException)
    1792                 :            : {
    1793                 :            :     // #TODO code within the test below "if ( m_Areas.... " can be removed
    1794                 :            :     // Test is performed only because m_xRange is NOT set to be
    1795                 :            :     // the first range in m_Areas ( to force failure while
    1796                 :            :     // the implementations for each method are being updated )
    1797 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    1798                 :            :     {
    1799 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
    1800 [ #  # ][ #  # ]:          0 :         return xRange->getFormula();
    1801                 :            :     }
    1802         [ #  # ]:          0 :     CellFormulaValueGetter valueGetter( getScDocument(), eGram );
    1803         [ #  # ]:          0 :     return getValue( valueGetter );
    1804                 :            : 
    1805                 :            : }
    1806                 :            : 
    1807                 :            : void
    1808                 :          0 : ScVbaRange::setFormula(const uno::Any &rFormula ) throw (uno::RuntimeException)
    1809                 :            : {
    1810                 :            :     // #FIXME converting "=$a$1" e.g. CONV_XL_A1 -> CONV_OOO                            // results in "=$a$1:a1", temporalily disable conversion
    1811                 :          0 :     setFormulaValue( rFormula,formula::FormulaGrammar::GRAM_NATIVE_XL_A1, true );
    1812                 :          0 : }
    1813                 :            : 
    1814                 :            : uno::Any
    1815                 :          0 : ScVbaRange::getFormulaR1C1() throw (::com::sun::star::uno::RuntimeException)
    1816                 :            : {
    1817                 :          0 :     return getFormulaValue( formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1 );
    1818                 :            : }
    1819                 :            : 
    1820                 :            : void
    1821                 :          0 : ScVbaRange::setFormulaR1C1(const uno::Any& rFormula ) throw (uno::RuntimeException)
    1822                 :            : {
    1823                 :          0 :     setFormulaValue( rFormula,formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1, true );
    1824                 :          0 : }
    1825                 :            : 
    1826                 :            : uno::Any
    1827                 :          0 : ScVbaRange::getFormula() throw (::com::sun::star::uno::RuntimeException)
    1828                 :            : {
    1829                 :          0 :     return getFormulaValue( formula::FormulaGrammar::GRAM_NATIVE_XL_A1 );
    1830                 :            : }
    1831                 :            : 
    1832                 :            : sal_Int32
    1833                 :          0 : ScVbaRange::getCount() throw (uno::RuntimeException)
    1834                 :            : {
    1835                 :            :     // If this is a multiple selection apply setValue over all areas
    1836 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    1837                 :            :     {
    1838         [ #  # ]:          0 :         AreasVisitor aVisitor( m_Areas );
    1839                 :          0 :         RangeCountProcessor valueProcessor;
    1840         [ #  # ]:          0 :         aVisitor.visit( valueProcessor );
    1841         [ #  # ]:          0 :         return valueProcessor.value();
    1842                 :            :     }
    1843                 :          0 :     sal_Int32 rowCount = 0;
    1844                 :          0 :     sal_Int32 colCount = 0;
    1845         [ #  # ]:          0 :     uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY_THROW );
    1846 [ #  # ][ #  # ]:          0 :     rowCount = xColumnRowRange->getRows()->getCount();
         [ #  # ][ #  # ]
    1847 [ #  # ][ #  # ]:          0 :     colCount = xColumnRowRange->getColumns()->getCount();
         [ #  # ][ #  # ]
    1848                 :            : 
    1849         [ #  # ]:          0 :     if( IsRows() )
    1850                 :          0 :         return rowCount;
    1851         [ #  # ]:          0 :     if( IsColumns() )
    1852                 :          0 :         return colCount;
    1853                 :          0 :     return rowCount * colCount;
    1854                 :            : }
    1855                 :            : 
    1856                 :            : sal_Int32
    1857                 :         68 : ScVbaRange::getRow() throw (uno::RuntimeException)
    1858                 :            : {
    1859                 :            :     // #TODO code within the test below "if ( m_Areas.... " can be removed
    1860                 :            :     // Test is performed only because m_xRange is NOT set to be
    1861                 :            :     // the first range in m_Areas ( to force failure while
    1862                 :            :     // the implementations for each method are being updated )
    1863 [ +  - ][ +  - ]:         68 :     if ( m_Areas->getCount() > 1 )
                 [ -  + ]
    1864                 :            :     {
    1865 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
    1866 [ #  # ][ #  # ]:          0 :         return xRange->getRow();
    1867                 :            :     }
    1868 [ +  - ][ +  - ]:         68 :     uno::Reference< sheet::XCellAddressable > xCellAddressable(mxRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW );
                 [ +  - ]
    1869 [ +  - ][ +  - ]:         68 :     return xCellAddressable->getCellAddress().Row + 1; // Zero value indexing
    1870                 :            : }
    1871                 :            : 
    1872                 :            : sal_Int32
    1873                 :         68 : ScVbaRange::getColumn() throw (uno::RuntimeException)
    1874                 :            : {
    1875                 :            :     // #TODO code within the test below "if ( m_Areas.... " can be removed
    1876                 :            :     // Test is performed only because m_xRange is NOT set to be
    1877                 :            :     // the first range in m_Areas ( to force failure while
    1878                 :            :     // the implementations for each method are being updated )
    1879 [ +  - ][ +  - ]:         68 :     if ( m_Areas->getCount() > 1 )
                 [ -  + ]
    1880                 :            :     {
    1881 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
    1882 [ #  # ][ #  # ]:          0 :         return xRange->getColumn();
    1883                 :            :     }
    1884 [ +  - ][ +  - ]:         68 :     uno::Reference< sheet::XCellAddressable > xCellAddressable(mxRange->getCellByPosition(0, 0), uno::UNO_QUERY_THROW );
                 [ +  - ]
    1885 [ +  - ][ +  - ]:         68 :     return xCellAddressable->getCellAddress().Column + 1; // Zero value indexing
    1886                 :            : }
    1887                 :            : 
    1888                 :            : uno::Any
    1889                 :          0 : ScVbaRange::HasFormula() throw (uno::RuntimeException)
    1890                 :            : {
    1891 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    1892                 :            :     {
    1893 [ #  # ][ #  # ]:          0 :         sal_Int32 nItems = m_Areas->getCount();
    1894         [ #  # ]:          0 :         uno::Any aResult = aNULL();
    1895         [ #  # ]:          0 :         for ( sal_Int32 index=1; index <= nItems; ++index )
    1896                 :            :         {
    1897 [ #  # ][ #  # ]:          0 :             uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    1898                 :            :             // if the HasFormula for any area is different to another
    1899                 :            :             // return null
    1900         [ #  # ]:          0 :             if ( index > 1 )
    1901 [ #  # ][ #  # ]:          0 :                 if ( aResult != xRange->HasFormula() )
                 [ #  # ]
    1902         [ #  # ]:          0 :                     return aNULL();
    1903 [ #  # ][ #  # ]:          0 :             aResult = xRange->HasFormula();
    1904 [ #  # ][ #  # ]:          0 :             if ( aNULL() == aResult )
    1905         [ #  # ]:          0 :                 return aNULL();
    1906         [ #  # ]:          0 :         }
    1907                 :          0 :         return aResult;
    1908                 :            :     }
    1909         [ #  # ]:          0 :     uno::Reference< uno::XInterface > xIf( mxRange, uno::UNO_QUERY_THROW );
    1910 [ #  # ][ #  # ]:          0 :     ScCellRangesBase* pThisRanges = dynamic_cast< ScCellRangesBase * > ( xIf.get() );
    1911         [ #  # ]:          0 :     if ( pThisRanges )
    1912                 :            :     {
    1913 [ #  # ][ #  # ]:          0 :         uno::Reference<uno::XInterface>  xRanges( pThisRanges->queryFormulaCells( ( sheet::FormulaResult::ERROR | sheet::FormulaResult::VALUE |  sheet::FormulaResult::STRING ) ), uno::UNO_QUERY_THROW );
    1914 [ #  # ][ #  # ]:          0 :         ScCellRangesBase* pFormulaRanges = dynamic_cast< ScCellRangesBase * > ( xRanges.get() );
    1915                 :            :         // check if there are no formula cell, return false
    1916 [ #  # ][ #  # ]:          0 :         if ( pFormulaRanges->GetRangeList().empty() )
    1917         [ #  # ]:          0 :             return uno::makeAny(sal_False);
    1918                 :            : 
    1919                 :            :         // chech if there are holes (where some cells are not formulas)
    1920                 :            :         // or returned range is not equal to this range
    1921 [ #  # ][ #  #  :          0 :         if (  ( pFormulaRanges->GetRangeList().size() > 1 )
             #  #  #  # ]
                 [ #  # ]
    1922 [ #  # ][ #  # ]:          0 :            || ( pFormulaRanges->GetRangeList().front()->aStart != pThisRanges->GetRangeList().front()->aStart )
    1923 [ #  # ][ #  # ]:          0 :            || ( pFormulaRanges->GetRangeList().front()->aEnd   != pThisRanges->GetRangeList().front()->aEnd   )
    1924                 :            :            )
    1925 [ #  # ][ #  # ]:          0 :             return aNULL(); // should return aNULL;
    1926                 :            :     }
    1927         [ #  # ]:          0 :     return uno::makeAny( sal_True );
    1928                 :            : }
    1929                 :            : void
    1930                 :          0 : ScVbaRange::fillSeries( sheet::FillDirection nFillDirection, sheet::FillMode nFillMode, sheet::FillDateMode nFillDateMode, double fStep, double fEndValue ) throw( uno::RuntimeException )
    1931                 :            : {
    1932 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    1933                 :            :     {
    1934                 :            :         // Multi-Area Range
    1935         [ #  # ]:          0 :         uno::Reference< XCollection > xCollection( m_Areas, uno::UNO_QUERY_THROW );
    1936 [ #  # ][ #  # ]:          0 :         for ( sal_Int32 index = 1; index <= xCollection->getCount(); ++index )
                 [ #  # ]
    1937                 :            :         {
    1938 [ #  # ][ #  # ]:          0 :             uno::Reference< excel::XRange > xRange( xCollection->Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    1939         [ #  # ]:          0 :             ScVbaRange* pThisRange = getImplementation( xRange );
    1940         [ #  # ]:          0 :             pThisRange->fillSeries( nFillDirection, nFillMode, nFillDateMode, fStep, fEndValue );
    1941                 :            : 
    1942                 :          0 :         }
    1943                 :          0 :         return;
    1944                 :            :     }
    1945                 :            : 
    1946         [ #  # ]:          0 :     uno::Reference< sheet::XCellSeries > xCellSeries(mxRange, uno::UNO_QUERY_THROW );
    1947 [ #  # ][ #  # ]:          0 :     xCellSeries->fillSeries( nFillDirection, nFillMode, nFillDateMode, fStep, fEndValue );
    1948                 :            : 
    1949                 :            :     // Fires the range change event.
    1950 [ #  # ][ #  # ]:          0 :     lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() );
         [ #  # ][ #  # ]
    1951                 :            : }
    1952                 :            : 
    1953                 :            : void
    1954                 :          0 : ScVbaRange::FillLeft() throw (uno::RuntimeException)
    1955                 :            : {
    1956                 :            :     fillSeries(sheet::FillDirection_TO_LEFT,
    1957                 :          0 :         sheet::FillMode_SIMPLE, sheet::FillDateMode_FILL_DATE_DAY, 0, 0x7FFFFFFF);
    1958                 :          0 : }
    1959                 :            : 
    1960                 :            : void
    1961                 :          0 : ScVbaRange::FillRight() throw (uno::RuntimeException)
    1962                 :            : {
    1963                 :            :     fillSeries(sheet::FillDirection_TO_RIGHT,
    1964                 :          0 :         sheet::FillMode_SIMPLE, sheet::FillDateMode_FILL_DATE_DAY, 0, 0x7FFFFFFF);
    1965                 :          0 : }
    1966                 :            : 
    1967                 :            : void
    1968                 :          0 : ScVbaRange::FillUp() throw (uno::RuntimeException)
    1969                 :            : {
    1970                 :            :     fillSeries(sheet::FillDirection_TO_TOP,
    1971                 :          0 :         sheet::FillMode_SIMPLE, sheet::FillDateMode_FILL_DATE_DAY, 0, 0x7FFFFFFF);
    1972                 :          0 : }
    1973                 :            : 
    1974                 :            : void
    1975                 :          0 : ScVbaRange::FillDown() throw (uno::RuntimeException)
    1976                 :            : {
    1977                 :            :     fillSeries(sheet::FillDirection_TO_BOTTOM,
    1978                 :          0 :         sheet::FillMode_SIMPLE, sheet::FillDateMode_FILL_DATE_DAY, 0, 0x7FFFFFFF);
    1979                 :          0 : }
    1980                 :            : 
    1981                 :            : ::rtl::OUString
    1982                 :          0 : ScVbaRange::getText() throw (uno::RuntimeException)
    1983                 :            : {
    1984                 :            :     // #TODO code within the test below "if ( m_Areas.... " can be removed
    1985                 :            :     // Test is performed only because m_xRange is NOT set to be
    1986                 :            :     // the first range in m_Areas ( to force failure while
    1987                 :            :     // the implementations for each method are being updated )
    1988 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    1989                 :            :     {
    1990 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
    1991 [ #  # ][ #  # ]:          0 :         return xRange->getText();
    1992                 :            :     }
    1993 [ #  # ][ #  # ]:          0 :     uno::Reference< text::XTextRange > xTextRange(mxRange->getCellByPosition(0,0), uno::UNO_QUERY_THROW );
                 [ #  # ]
    1994 [ #  # ][ #  # ]:          0 :     return xTextRange->getString();
    1995                 :            : }
    1996                 :            : 
    1997                 :            : uno::Reference< excel::XRange >
    1998                 :          0 : ScVbaRange::Offset( const ::uno::Any &nRowOff, const uno::Any &nColOff ) throw (uno::RuntimeException)
    1999                 :            : {
    2000                 :          0 :     SCROW nRowOffset = 0;
    2001                 :          0 :     SCCOL nColOffset = 0;
    2002                 :          0 :     sal_Bool bIsRowOffset = ( nRowOff >>= nRowOffset );
    2003                 :          0 :     sal_Bool bIsColumnOffset = ( nColOff >>= nColOffset );
    2004         [ #  # ]:          0 :     ScCellRangesBase* pUnoRangesBase = getCellRangesBase();
    2005                 :            : 
    2006         [ #  # ]:          0 :     ScRangeList aCellRanges = pUnoRangesBase->GetRangeList();
    2007                 :            : 
    2008                 :            : 
    2009 [ #  # ][ #  # ]:          0 :     for ( size_t i = 0, nRanges = aCellRanges.size(); i < nRanges; ++i )
    2010                 :            :     {
    2011         [ #  # ]:          0 :         ScRange* pRange = aCellRanges[ i ];
    2012         [ #  # ]:          0 :         if ( bIsColumnOffset )
    2013                 :            :         {
    2014                 :          0 :             pRange->aStart.SetCol( pRange->aStart.Col() + nColOffset );
    2015                 :          0 :             pRange->aEnd.SetCol( pRange->aEnd.Col() + nColOffset );
    2016                 :            :         }
    2017         [ #  # ]:          0 :         if ( bIsRowOffset )
    2018                 :            :         {
    2019                 :          0 :             pRange->aStart.SetRow( pRange->aStart.Row() + nRowOffset );
    2020                 :          0 :             pRange->aEnd.SetRow( pRange->aEnd.Row() + nRowOffset );
    2021                 :            :         }
    2022                 :            :     }
    2023                 :            : 
    2024 [ #  # ][ #  # ]:          0 :     if ( aCellRanges.size() > 1 ) // Multi-Area
    2025                 :            :     {
    2026 [ #  # ][ #  # ]:          0 :         uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( pUnoRangesBase->GetDocShell(), aCellRanges ) );
                 [ #  # ]
    2027 [ #  # ][ #  # ]:          0 :         return new ScVbaRange( mxParent, mxContext, xRanges );
         [ #  # ][ #  # ]
    2028                 :            :     }
    2029                 :            :     // normal range
    2030 [ #  # ][ #  # ]:          0 :     uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( pUnoRangesBase->GetDocShell(), *aCellRanges.front() ) );
         [ #  # ][ #  # ]
    2031 [ #  # ][ #  # ]:          0 :     return new ScVbaRange( mxParent, mxContext, xRange  );
         [ #  # ][ #  # ]
                 [ #  # ]
    2032                 :            : }
    2033                 :            : 
    2034                 :            : uno::Reference< excel::XRange >
    2035                 :          0 : ScVbaRange::CurrentRegion() throw (uno::RuntimeException)
    2036                 :            : {
    2037                 :            :     // #TODO code within the test below "if ( m_Areas.... " can be removed
    2038                 :            :     // Test is performed only because m_xRange is NOT set to be
    2039                 :            :     // the first range in m_Areas ( to force failure while
    2040                 :            :     // the implementations for each method are being updated )
    2041 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    2042                 :            :     {
    2043 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
    2044 [ #  # ][ #  # ]:          0 :         return xRange->CurrentRegion();
    2045                 :            :     }
    2046                 :            : 
    2047         [ #  # ]:          0 :     RangeHelper helper( mxRange );
    2048                 :            :     uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor =
    2049         [ #  # ]:          0 :         helper.getSheetCellCursor();
    2050 [ #  # ][ #  # ]:          0 :     xSheetCellCursor->collapseToCurrentRegion();
    2051         [ #  # ]:          0 :     uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xSheetCellCursor, uno::UNO_QUERY_THROW);
    2052 [ #  # ][ #  # ]:          0 :     return RangeHelper::createRangeFromRange( mxParent, mxContext, helper.getCellRangeFromSheet(), xCellRangeAddressable );
         [ #  # ][ #  # ]
    2053                 :            : }
    2054                 :            : 
    2055                 :            : uno::Reference< excel::XRange >
    2056                 :          0 : ScVbaRange::CurrentArray() throw (uno::RuntimeException)
    2057                 :            : {
    2058                 :            :     // #TODO code within the test below "if ( m_Areas.... " can be removed
    2059                 :            :     // Test is performed only because m_xRange is NOT set to be
    2060                 :            :     // the first range in m_Areas ( to force failure while
    2061                 :            :     // the implementations for each method are being updated )
    2062 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    2063                 :            :     {
    2064 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
    2065 [ #  # ][ #  # ]:          0 :         return xRange->CurrentArray();
    2066                 :            :     }
    2067         [ #  # ]:          0 :     RangeHelper helper( mxRange );
    2068                 :            :     uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor =
    2069         [ #  # ]:          0 :         helper.getSheetCellCursor();
    2070 [ #  # ][ #  # ]:          0 :     xSheetCellCursor->collapseToCurrentArray();
    2071         [ #  # ]:          0 :     uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xSheetCellCursor, uno::UNO_QUERY_THROW);
    2072 [ #  # ][ #  # ]:          0 :     return RangeHelper::createRangeFromRange( mxParent, mxContext, helper.getCellRangeFromSheet(), xCellRangeAddressable );
         [ #  # ][ #  # ]
    2073                 :            : }
    2074                 :            : 
    2075                 :            : uno::Any
    2076                 :          0 : ScVbaRange::getFormulaArray() throw (uno::RuntimeException)
    2077                 :            : {
    2078                 :            :     // #TODO code within the test below "if ( m_Areas.... " can be removed
    2079                 :            :     // Test is performed only because m_xRange is NOT set to be
    2080                 :            :     // the first range in m_Areas ( to force failure while
    2081                 :            :     // the implementations for each method are being updated )
    2082 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    2083                 :            :     {
    2084 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
    2085 [ #  # ][ #  # ]:          0 :         return xRange->getFormulaArray();
    2086                 :            :     }
    2087                 :            : 
    2088         [ #  # ]:          0 :     uno::Reference< sheet::XCellRangeFormula> xCellRangeFormula( mxRange, uno::UNO_QUERY_THROW );
    2089         [ #  # ]:          0 :     uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext );
    2090                 :          0 :     uno::Any aMatrix;
    2091                 :            : 
    2092 [ #  # ][ #  # ]:          0 :     uno::Sequence< uno::Sequence<rtl::OUString> > aFmArray = xCellRangeFormula->getFormulaArray();
    2093         [ #  # ]:          0 :     if( aFmArray.getLength() )
    2094                 :            :     {
    2095 [ #  # ][ #  # ]:          0 :         if( aFmArray.getLength() == 1 && aFmArray[0].getLength() == 1 )
         [ #  # ][ #  # ]
    2096 [ #  # ][ #  # ]:          0 :             aMatrix <<= aFmArray[0][0];
                 [ #  # ]
    2097                 :            :         else
    2098 [ #  # ][ #  # ]:          0 :             aMatrix = xConverter->convertTo( uno::makeAny( xCellRangeFormula->getFormulaArray() ) , getCppuType((uno::Sequence< uno::Sequence< uno::Any > >*)0)  ) ;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    2099                 :            :     }
    2100         [ #  # ]:          0 :     return aMatrix;
    2101                 :            : }
    2102                 :            : 
    2103                 :            : void
    2104                 :          0 : ScVbaRange::setFormulaArray(const uno::Any& rFormula) throw (uno::RuntimeException)
    2105                 :            : {
    2106                 :            :     // #TODO code within the test below "if ( m_Areas.... " can be removed
    2107                 :            :     // Test is performed only because m_xRange is NOT set to be
    2108                 :            :     // the first range in m_Areas ( to force failure while
    2109                 :            :     // the implementations for each method are being updated )
    2110         [ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
    2111                 :            :     {
    2112 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
    2113 [ #  # ][ #  # ]:          0 :         return xRange->setFormulaArray( rFormula );
    2114                 :            :     }
    2115                 :            :     // #TODO need to distinguish between getFormula and getFormulaArray e.g. (R1C1)
    2116                 :            :     // but for the moment its just easier to treat them the same for setting
    2117                 :            : 
    2118                 :          0 :     setFormula( rFormula );
    2119                 :            : }
    2120                 :            : 
    2121                 :            : ::rtl::OUString
    2122                 :          0 : ScVbaRange::Characters(const uno::Any& Start, const uno::Any& Length) throw (uno::RuntimeException)
    2123                 :            : {
    2124                 :            :     // #TODO code within the test below "if ( m_Areas.... " can be removed
    2125                 :            :     // Test is performed only because m_xRange is NOT set to be
    2126                 :            :     // the first range in m_Areas ( to force failure while
    2127                 :            :     // the implementations for each method are being updated )
    2128 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    2129                 :            :     {
    2130 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
    2131 [ #  # ][ #  # ]:          0 :         return xRange->Characters( Start, Length );
    2132                 :            :     }
    2133                 :            : 
    2134                 :          0 :     long nIndex = 0, nCount = 0;
    2135                 :          0 :     ::rtl::OUString rString;
    2136         [ #  # ]:          0 :     uno::Reference< text::XTextRange > xTextRange(mxRange, ::uno::UNO_QUERY_THROW );
    2137 [ #  # ][ #  # ]:          0 :     rString = xTextRange->getString();
    2138 [ #  # ][ #  # ]:          0 :     if( !( Start >>= nIndex ) && !( Length >>= nCount ) )
                 [ #  # ]
    2139                 :          0 :         return rString;
    2140         [ #  # ]:          0 :     if(!( Start >>= nIndex ) )
    2141                 :          0 :         nIndex = 1;
    2142         [ #  # ]:          0 :     if(!( Length >>= nCount ) )
    2143                 :          0 :         nIndex = rString.getLength();
    2144                 :          0 :     return rString.copy( --nIndex, nCount ); // Zero value indexing
    2145                 :            : }
    2146                 :            : 
    2147                 :            : ::rtl::OUString
    2148                 :        104 : ScVbaRange::Address(  const uno::Any& RowAbsolute, const uno::Any& ColumnAbsolute, const uno::Any& ReferenceStyle, const uno::Any& External, const uno::Any& RelativeTo ) throw (uno::RuntimeException)
    2149                 :            : {
    2150 [ +  - ][ +  - ]:        104 :     if ( m_Areas->getCount() > 1 )
                 [ +  + ]
    2151                 :            :     {
    2152                 :            :         // Multi-Area Range
    2153                 :          2 :         rtl::OUString sAddress;
    2154         [ +  - ]:          2 :         uno::Reference< XCollection > xCollection( m_Areas, uno::UNO_QUERY_THROW );
    2155                 :          2 :                 uno::Any aExternalCopy = External;
    2156 [ +  - ][ +  - ]:          8 :         for ( sal_Int32 index = 1; index <= xCollection->getCount(); ++index )
                 [ +  + ]
    2157                 :            :         {
    2158 [ +  - ][ +  - ]:          6 :             uno::Reference< excel::XRange > xRange( xCollection->Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
         [ +  - ][ +  - ]
    2159         [ +  + ]:          6 :             if ( index > 1 )
    2160                 :            :             {
    2161                 :          4 :                 sAddress += rtl::OUString( ',' );
    2162                 :            :                                 // force external to be false
    2163                 :            :                                 // only first address should have the
    2164                 :            :                                 // document and sheet specifications
    2165         [ +  - ]:          4 :                                 aExternalCopy = uno::makeAny(sal_False);
    2166                 :            :             }
    2167 [ +  - ][ +  - ]:          6 :             sAddress += xRange->Address( RowAbsolute, ColumnAbsolute, ReferenceStyle, aExternalCopy, RelativeTo );
    2168                 :          6 :         }
    2169                 :          2 :         return sAddress;
    2170                 :            : 
    2171                 :            :     }
    2172                 :        102 :     ScAddress::Details dDetails( formula::FormulaGrammar::CONV_XL_A1, 0, 0 );
    2173         [ +  + ]:        102 :     if ( ReferenceStyle.hasValue() )
    2174                 :            :     {
    2175                 :         28 :         sal_Int32 refStyle = excel::XlReferenceStyle::xlA1;
    2176                 :         28 :         ReferenceStyle >>= refStyle;
    2177         [ +  - ]:         28 :         if ( refStyle == excel::XlReferenceStyle::xlR1C1 )
    2178                 :         28 :             dDetails = ScAddress::Details( formula::FormulaGrammar::CONV_XL_R1C1, 0, 0 );
    2179                 :            :     }
    2180                 :        102 :     sal_uInt16 nFlags = SCA_VALID;
    2181         [ +  - ]:        102 :     ScDocShell* pDocShell =  getScDocShell();
    2182                 :        102 :     ScDocument* pDoc =  pDocShell->GetDocument();
    2183                 :            : 
    2184         [ +  - ]:        102 :     RangeHelper thisRange( mxRange );
    2185 [ +  - ][ +  - ]:        102 :     table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
                 [ +  - ]
    2186                 :        102 :     ScRange aRange( static_cast< SCCOL >( thisAddress.StartColumn ), static_cast< SCROW >( thisAddress.StartRow ), static_cast< SCTAB >( thisAddress.Sheet ), static_cast< SCCOL >( thisAddress.EndColumn ), static_cast< SCROW >( thisAddress.EndRow ), static_cast< SCTAB >( thisAddress.Sheet ) );
    2187         [ +  - ]:        102 :     String sRange;
    2188                 :        102 :     sal_uInt16 ROW_ABSOLUTE = ( SCA_ROW_ABSOLUTE | SCA_ROW2_ABSOLUTE );
    2189                 :        102 :     sal_uInt16 COL_ABSOLUTE = ( SCA_COL_ABSOLUTE | SCA_COL2_ABSOLUTE );
    2190                 :            :     // default
    2191                 :        102 :     nFlags |= ( SCA_TAB_ABSOLUTE | SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB2_ABSOLUTE | SCA_COL2_ABSOLUTE | SCA_ROW2_ABSOLUTE );
    2192         [ +  + ]:        102 :     if ( RowAbsolute.hasValue() )
    2193                 :            :     {
    2194                 :          2 :         sal_Bool bVal = sal_True;
    2195                 :          2 :         RowAbsolute >>= bVal;
    2196         [ +  - ]:          2 :         if ( !bVal )
    2197                 :          2 :             nFlags &= ~ROW_ABSOLUTE;
    2198                 :            :     }
    2199         [ +  + ]:        102 :     if ( ColumnAbsolute.hasValue() )
    2200                 :            :     {
    2201                 :          2 :         sal_Bool bVal = sal_True;
    2202                 :          2 :         ColumnAbsolute >>= bVal;
    2203         [ +  - ]:          2 :         if ( !bVal )
    2204                 :          2 :             nFlags &= ~COL_ABSOLUTE;
    2205                 :            :     }
    2206                 :        102 :     sal_Bool bLocal = false;
    2207         [ +  + ]:        102 :     if ( External.hasValue() )
    2208                 :            :     {
    2209                 :         12 :         External >>= bLocal;
    2210         [ +  + ]:         12 :         if (  bLocal )
    2211                 :          8 :             nFlags |= SCA_TAB_3D | SCA_FORCE_DOC;
    2212                 :            :     }
    2213         [ -  + ]:        102 :     if ( RelativeTo.hasValue() )
    2214                 :            :     {
    2215                 :            :         // #TODO should I throw an error if R1C1 is not set?
    2216                 :            : 
    2217         [ #  # ]:          0 :         table::CellRangeAddress refAddress = getCellRangeAddressForVBARange( RelativeTo, pDocShell );
    2218                 :          0 :         dDetails = ScAddress::Details( formula::FormulaGrammar::CONV_XL_R1C1, static_cast< SCROW >( refAddress.StartRow ), static_cast< SCCOL >( refAddress.StartColumn ) );
    2219                 :            :     }
    2220         [ +  - ]:        102 :     aRange.Format( sRange,  nFlags, pDoc, dDetails );
    2221 [ +  - ][ +  - ]:        104 :     return sRange;
                 [ +  - ]
    2222                 :            : }
    2223                 :            : 
    2224                 :            : uno::Reference < excel::XFont >
    2225                 :          0 : ScVbaRange::Font() throw ( script::BasicErrorException, uno::RuntimeException)
    2226                 :            : {
    2227         [ #  # ]:          0 :     uno::Reference< beans::XPropertySet > xProps(mxRange, ::uno::UNO_QUERY );
    2228         [ #  # ]:          0 :     ScDocument* pDoc = getScDocument();
    2229         [ #  # ]:          0 :     if ( mxRange.is() )
    2230         [ #  # ]:          0 :         xProps.set(mxRange, ::uno::UNO_QUERY );
    2231         [ #  # ]:          0 :     else if ( mxRanges.is() )
    2232         [ #  # ]:          0 :         xProps.set(mxRanges, ::uno::UNO_QUERY );
    2233         [ #  # ]:          0 :     if ( !pDoc )
    2234 [ #  # ][ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString(  "Failed to access document from shell"  ), uno::Reference< uno::XInterface >() );
    2235                 :            : 
    2236                 :          0 :     ScVbaPalette aPalette( pDoc->GetDocumentShell() );
    2237                 :          0 :     ScCellRangeObj* pRangeObj = NULL;
    2238                 :            :     try
    2239                 :            :     {
    2240         [ #  # ]:          0 :         pRangeObj = getCellRangeObj();
    2241                 :            :     }
    2242         [ #  # ]:          0 :     catch( uno::Exception& )
    2243                 :            :     {
    2244                 :            :     }
    2245 [ #  # ][ #  # ]:          0 :     return  new ScVbaFont( this, mxContext, aPalette, xProps, pRangeObj );
         [ #  # ][ #  # ]
    2246                 :            : }
    2247                 :            : 
    2248                 :            : uno::Reference< excel::XRange >
    2249                 :          0 : ScVbaRange::Cells( const uno::Any &nRowIndex, const uno::Any &nColumnIndex ) throw(uno::RuntimeException)
    2250                 :            : {
    2251                 :            :     // #TODO code within the test below "if ( m_Areas.... " can be removed
    2252                 :            :     // Test is performed only because m_xRange is NOT set to be
    2253                 :            :     // the first range in m_Areas ( to force failure while
    2254                 :            :     // the implementations for each method are being updated )
    2255         [ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
    2256                 :            :     {
    2257 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
    2258 [ #  # ][ #  # ]:          0 :         return xRange->Cells( nRowIndex, nColumnIndex );
    2259                 :            :     }
    2260                 :            : 
    2261                 :            :     // Performance: Use a common helper method for ScVbaRange::Cells and ScVbaWorksheet::Cells,
    2262                 :            :     // instead of creating a new ScVbaRange object in often-called ScVbaWorksheet::Cells
    2263         [ #  # ]:          0 :     return CellsHelper( mxParent, mxContext, mxRange, nRowIndex, nColumnIndex );
    2264                 :            : }
    2265                 :            : 
    2266                 :            : // static
    2267                 :            : uno::Reference< excel::XRange >
    2268                 :          2 : ScVbaRange::CellsHelper( const uno::Reference< ov::XHelperInterface >& xParent,
    2269                 :            :                          const uno::Reference< uno::XComponentContext >& xContext,
    2270                 :            :                          const uno::Reference< css::table::XCellRange >& xRange,
    2271                 :            :                          const uno::Any &nRowIndex, const uno::Any &nColumnIndex ) throw(uno::RuntimeException)
    2272                 :            : {
    2273                 :          2 :     sal_Int32 nRow = 0, nColumn = 0;
    2274                 :            : 
    2275                 :          2 :     sal_Bool bIsIndex = nRowIndex.hasValue();
    2276                 :          2 :     sal_Bool bIsColumnIndex = nColumnIndex.hasValue();
    2277                 :            : 
    2278                 :            :     // Sometimes we might get a float or a double or whatever
    2279                 :            :     // set in the Any, we should convert as appropriate
    2280                 :            :     // #FIXME - perhaps worth turning this into some sort of
    2281                 :            :     // convertion routine e.g. bSuccess = getValueFromAny( nRow, nRowIndex, getCppuType((sal_Int32*)0) )
    2282                 :          2 :     uno::Any aRowIndexAny = nRowIndex;
    2283         [ -  + ]:          2 :     if ( aRowIndexAny.getValueTypeClass() == uno::TypeClass_INTERFACE )
    2284                 :            :     {
    2285                 :            :         try
    2286                 :            :         {
    2287         [ #  # ]:          0 :             aRowIndexAny = getDefaultPropByIntrospection( aRowIndexAny );
    2288                 :            :         }
    2289   [ #  #  #  # ]:          0 :         catch( uno::Exception& ) {}
    2290                 :            :     }
    2291 [ +  - ][ -  + ]:          2 :     else if ( aRowIndexAny.hasValue() && !( aRowIndexAny >>= nRow ) )
                 [ -  + ]
    2292                 :            :     {
    2293         [ #  # ]:          0 :         uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( xContext );
    2294                 :          0 :         uno::Any aConverted;
    2295                 :            :         try
    2296                 :            :         {
    2297 [ #  # ][ #  # ]:          0 :             aConverted = xConverter->convertTo( aRowIndexAny, getCppuType((sal_Int32*)0) );
                 [ #  # ]
    2298                 :          0 :             bIsIndex = ( aConverted >>= nRow );
    2299                 :            :         }
    2300         [ #  # ]:          0 :         catch( uno::Exception& ) {} // silence any errors
    2301                 :            :     }
    2302                 :            : 
    2303                 :          2 :     uno::Any aColumnAny = nColumnIndex;
    2304                 :            : 
    2305         [ +  - ]:          2 :     if ( bIsColumnIndex )
    2306                 :            :     {
    2307                 :            :          // Column index can be a col address e.g Cells( 1, "B" ) etc.
    2308                 :          2 :         rtl::OUString sCol;
    2309         [ -  + ]:          2 :         if ( nColumnIndex >>= sCol )
    2310                 :            :         {
    2311                 :          0 :             ScAddress::Details dDetails( formula::FormulaGrammar::CONV_XL_A1, 0, 0 );
    2312                 :          0 :             ScRange tmpRange;
    2313 [ #  # ][ #  # ]:          0 :             sal_uInt16 flags = tmpRange.ParseCols( sCol, excel::GetDocumentFromRange( xRange ), dDetails );
         [ #  # ][ #  # ]
    2314         [ #  # ]:          0 :             if ( ( flags & 0x200 ) != 0x200 )
    2315 [ #  # ][ #  # ]:          0 :                throw uno::RuntimeException();
    2316                 :          0 :             nColumn = tmpRange.aStart.Col() + 1;
    2317                 :            :         }
    2318                 :            :         else
    2319                 :            :         {
    2320         [ -  + ]:          2 :             if ( aColumnAny.getValueTypeClass() == uno::TypeClass_INTERFACE )
    2321                 :            :             {
    2322                 :            :                 try
    2323                 :            :                 {
    2324         [ #  # ]:          0 :                     aColumnAny = getDefaultPropByIntrospection( aColumnAny );
    2325                 :            :                 }
    2326   [ #  #  #  # ]:          0 :                 catch( uno::Exception& ) {}
    2327                 :            :             }
    2328         [ -  + ]:          2 :             if ( !( aColumnAny >>= nColumn ) )
    2329                 :            :             {
    2330         [ #  # ]:          0 :                 uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( xContext );
    2331                 :          0 :                 uno::Any aConverted;
    2332                 :            :                 try
    2333                 :            :                 {
    2334 [ #  # ][ #  # ]:          0 :                     aConverted = xConverter->convertTo( aColumnAny, getCppuType((sal_Int32*)0) );
                 [ #  # ]
    2335                 :          0 :                     bIsColumnIndex = ( aConverted >>= nColumn );
    2336                 :            :                 }
    2337         [ #  # ]:          0 :                 catch( uno::Exception& ) {} // silence any errors
    2338                 :            :             }
    2339                 :          2 :        }
    2340                 :            :     }
    2341         [ +  - ]:          2 :     RangeHelper thisRange( xRange );
    2342 [ +  - ][ +  - ]:          2 :     table::CellRangeAddress thisRangeAddress =  thisRange.getCellRangeAddressable()->getRangeAddress();
                 [ +  - ]
    2343         [ +  - ]:          2 :     uno::Reference< table::XCellRange > xSheetRange = thisRange.getCellRangeFromSheet();
    2344 [ -  + ][ #  # ]:          2 :     if( !bIsIndex && !bIsColumnIndex ) // .Cells
    2345                 :            :         // #FIXE needs proper parent ( Worksheet )
    2346 [ #  # ][ #  # ]:          0 :         return uno::Reference< excel::XRange >( new ScVbaRange( xParent, xContext, xRange ) );
                 [ #  # ]
    2347                 :            : 
    2348                 :          2 :     sal_Int32 nIndex = --nRow;
    2349 [ +  - ][ -  + ]:          2 :     if( bIsIndex && !bIsColumnIndex ) // .Cells(n)
    2350                 :            :     {
    2351         [ #  # ]:          0 :         uno::Reference< table::XColumnRowRange > xColumnRowRange(xRange, ::uno::UNO_QUERY_THROW);
    2352 [ #  # ][ #  # ]:          0 :         sal_Int32 nColCount = xColumnRowRange->getColumns()->getCount();
         [ #  # ][ #  # ]
    2353                 :            : 
    2354 [ #  # ][ #  # ]:          0 :         if ( !nIndex || nIndex < 0 )
    2355                 :          0 :             nRow = 0;
    2356                 :            :         else
    2357                 :          0 :             nRow = nIndex / nColCount;
    2358                 :          0 :         nColumn = nIndex % nColCount;
    2359                 :            :     }
    2360                 :            :     else
    2361                 :          2 :         --nColumn;
    2362                 :          2 :     nRow = nRow + thisRangeAddress.StartRow;
    2363                 :          2 :     nColumn =  nColumn + thisRangeAddress.StartColumn;
    2364 [ +  - ][ +  - ]:          2 :     return new ScVbaRange( xParent, xContext, xSheetRange->getCellRangeByPosition( nColumn, nRow, nColumn, nRow ) );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ #  # ]
    2365                 :            : }
    2366                 :            : 
    2367                 :            : void
    2368                 :          0 : ScVbaRange::Select() throw (uno::RuntimeException)
    2369                 :            : {
    2370                 :          0 :     ScCellRangesBase* pUnoRangesBase = getCellRangesBase();
    2371         [ #  # ]:          0 :     if ( !pUnoRangesBase )
    2372         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString(  "Failed to access underlying uno range object"  ), uno::Reference< uno::XInterface >()  );
    2373                 :          0 :     ScDocShell* pShell = pUnoRangesBase->GetDocShell();
    2374         [ #  # ]:          0 :     if ( pShell )
    2375                 :            :     {
    2376 [ #  # ][ #  # ]:          0 :         uno::Reference< frame::XModel > xModel( pShell->GetModel(), uno::UNO_QUERY_THROW );
    2377 [ #  # ][ #  # ]:          0 :         uno::Reference< view::XSelectionSupplier > xSelection( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
                 [ #  # ]
    2378         [ #  # ]:          0 :         if ( mxRanges.is() )
    2379 [ #  # ][ #  # ]:          0 :             xSelection->select( uno::Any( lclExpandToMerged( mxRanges, true ) ) );
         [ #  # ][ #  # ]
    2380                 :            :         else
    2381 [ #  # ][ #  # ]:          0 :             xSelection->select( uno::Any( lclExpandToMerged( mxRange, true ) ) );
         [ #  # ][ #  # ]
    2382                 :            :         // set focus on document e.g.
    2383                 :            :         // ThisComponent.CurrentController.Frame.getContainerWindow.SetFocus
    2384                 :            :         try
    2385                 :            :         {
    2386 [ #  # ][ #  # ]:          0 :             uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
                 [ #  # ]
    2387 [ #  # ][ #  # ]:          0 :             uno::Reference< frame::XFrame > xFrame( xController->getFrame(), uno::UNO_QUERY_THROW );
                 [ #  # ]
    2388 [ #  # ][ #  # ]:          0 :             uno::Reference< awt::XWindow > xWin( xFrame->getContainerWindow(), uno::UNO_QUERY_THROW );
                 [ #  # ]
    2389 [ #  # ][ #  # ]:          0 :             xWin->setFocus();
                 [ #  # ]
    2390                 :            :         }
    2391         [ #  # ]:          0 :         catch( uno::Exception& )
    2392                 :            :         {
    2393                 :          0 :         }
    2394                 :            :     }
    2395                 :          0 : }
    2396                 :            : 
    2397                 :          0 : bool cellInRange( const table::CellRangeAddress& rAddr, const sal_Int32& nCol, const sal_Int32& nRow )
    2398                 :            : {
    2399 [ #  # ][ #  # ]:          0 :     if ( nCol >= rAddr.StartColumn && nCol <= rAddr.EndColumn &&
         [ #  # ][ #  # ]
    2400                 :            :         nRow >= rAddr.StartRow && nRow <= rAddr.EndRow )
    2401                 :          0 :         return true;
    2402                 :          0 :     return false;
    2403                 :            : }
    2404                 :            : 
    2405                 :          0 : void setCursor(  const SCCOL& nCol, const SCROW& nRow, const uno::Reference< frame::XModel >& xModel,  bool bInSel = true )
    2406                 :            : {
    2407                 :          0 :     ScTabViewShell* pShell = excel::getBestViewShell( xModel );
    2408         [ #  # ]:          0 :     if ( pShell )
    2409                 :            :     {
    2410         [ #  # ]:          0 :         if ( bInSel )
    2411                 :          0 :             pShell->SetCursor( nCol, nRow );
    2412                 :            :         else
    2413                 :          0 :             pShell->MoveCursorAbs( nCol, nRow, SC_FOLLOW_NONE, false, false, sal_True, false );
    2414                 :            :     }
    2415                 :          0 : }
    2416                 :            : 
    2417                 :            : void
    2418                 :          0 : ScVbaRange::Activate() throw (uno::RuntimeException)
    2419                 :            : {
    2420                 :            :     // get first cell of current range
    2421                 :          0 :     uno::Reference< table::XCellRange > xCellRange;
    2422         [ #  # ]:          0 :     if ( mxRanges.is() )
    2423                 :            :     {
    2424         [ #  # ]:          0 :         uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW  );
    2425 [ #  # ][ #  # ]:          0 :         xCellRange.set( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
                 [ #  # ]
    2426                 :            :     }
    2427                 :            :     else
    2428         [ #  # ]:          0 :         xCellRange.set( mxRange, uno::UNO_QUERY_THROW );
    2429                 :            : 
    2430         [ #  # ]:          0 :     RangeHelper thisRange( xCellRange );
    2431         [ #  # ]:          0 :     uno::Reference< sheet::XCellRangeAddressable > xThisRangeAddress = thisRange.getCellRangeAddressable();
    2432 [ #  # ][ #  # ]:          0 :     table::CellRangeAddress thisRangeAddress = xThisRangeAddress->getRangeAddress();
    2433                 :          0 :         uno::Reference< frame::XModel > xModel;
    2434         [ #  # ]:          0 :         ScDocShell* pShell = getScDocShell();
    2435                 :            : 
    2436         [ #  # ]:          0 :         if ( pShell )
    2437 [ #  # ][ #  # ]:          0 :             xModel = pShell->GetModel();
    2438                 :            : 
    2439         [ #  # ]:          0 :         if ( !xModel.is() )
    2440         [ #  # ]:          0 :             throw uno::RuntimeException();
    2441                 :            : 
    2442                 :            :     // get current selection
    2443 [ #  # ][ #  # ]:          0 :     uno::Reference< sheet::XCellRangeAddressable > xRange( xModel->getCurrentSelection(), ::uno::UNO_QUERY);
                 [ #  # ]
    2444                 :            : 
    2445 [ #  # ][ #  # ]:          0 :     uno::Reference< sheet::XSheetCellRanges > xRanges( xModel->getCurrentSelection(), ::uno::UNO_QUERY);
                 [ #  # ]
    2446                 :            : 
    2447         [ #  # ]:          0 :     if ( xRanges.is() )
    2448                 :            :     {
    2449 [ #  # ][ #  # ]:          0 :         uno::Sequence< table::CellRangeAddress > nAddrs = xRanges->getRangeAddresses();
    2450         [ #  # ]:          0 :         for ( sal_Int32 index = 0; index < nAddrs.getLength(); ++index )
    2451                 :            :         {
    2452 [ #  # ][ #  # ]:          0 :             if ( cellInRange( nAddrs[index], thisRangeAddress.StartColumn, thisRangeAddress.StartRow ) )
    2453                 :            :             {
    2454         [ #  # ]:          0 :                 setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), xModel );
    2455                 :          0 :                 return;
    2456                 :            :             }
    2457                 :            : 
    2458 [ #  # ][ #  # ]:          0 :         }
    2459                 :            :     }
    2460                 :            : 
    2461 [ #  # ][ #  # ]:          0 :     if ( xRange.is() && cellInRange( xRange->getRangeAddress(), thisRangeAddress.StartColumn, thisRangeAddress.StartRow ) )
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
    2462         [ #  # ]:          0 :         setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), xModel );
    2463                 :            :     else
    2464                 :            :     {
    2465                 :            :         // if this range is multi cell select the range other
    2466                 :            :         // wise just position the cell at this single range position
    2467 [ #  # ][ #  # ]:          0 :         if ( isSingleCellRange() )
    2468                 :            :             // This top-leftmost cell of this Range is not in the current
    2469                 :            :             // selection so just select this range
    2470         [ #  # ]:          0 :             setCursor( static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), xModel, false  );
    2471                 :            :         else
    2472         [ #  # ]:          0 :             Select();
    2473 [ #  # ][ #  # ]:          0 :     }
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    2474                 :            : 
    2475                 :            : }
    2476                 :            : 
    2477                 :            : uno::Reference< excel::XRange >
    2478                 :         10 : ScVbaRange::Rows(const uno::Any& aIndex ) throw (uno::RuntimeException)
    2479                 :            : {
    2480                 :         10 :     rtl::OUString sAddress;
    2481                 :            : 
    2482         [ +  - ]:         10 :     if ( aIndex.hasValue() )
    2483                 :            :     {
    2484                 :         10 :         sal_Int32 nValue = 0;
    2485         [ +  - ]:         10 :         ScCellRangesBase* pUnoRangesBase = getCellRangesBase();
    2486         [ +  - ]:         10 :         ScRangeList aCellRanges = pUnoRangesBase->GetRangeList();
    2487                 :            : 
    2488         [ +  - ]:         10 :         ScRange aRange = *aCellRanges.front();
    2489         [ +  + ]:         10 :         if( aIndex >>= nValue )
    2490                 :            :         {
    2491                 :          2 :             aRange.aStart.SetRow( aRange.aStart.Row() + --nValue );
    2492                 :          2 :             aRange.aEnd.SetRow( aRange.aStart.Row() );
    2493                 :            :         }
    2494         [ +  - ]:          8 :         else if ( aIndex >>= sAddress )
    2495                 :            :         {
    2496                 :          8 :             ScAddress::Details dDetails( formula::FormulaGrammar::CONV_XL_A1, 0, 0 );
    2497                 :          8 :             ScRange tmpRange;
    2498 [ +  - ][ +  - ]:          8 :             tmpRange.ParseRows( sAddress, excel::GetDocumentFromRange( mxRange ), dDetails );
         [ +  - ][ +  - ]
    2499                 :          8 :             SCROW nStartRow = tmpRange.aStart.Row();
    2500                 :          8 :             SCROW nEndRow = tmpRange.aEnd.Row();
    2501                 :            : 
    2502                 :          8 :             aRange.aStart.SetRow( aRange.aStart.Row() + nStartRow );
    2503                 :          8 :             aRange.aEnd.SetRow( aRange.aStart.Row() + ( nEndRow  - nStartRow ));
    2504                 :            :         }
    2505                 :            :         else
    2506         [ #  # ]:          0 :             throw uno::RuntimeException( rtl::OUString( "Illegal param"  ), uno::Reference< uno::XInterface >() );
    2507                 :            : 
    2508 [ +  - ][ -  + ]:         10 :         if ( aRange.aStart.Row() < 0 || aRange.aEnd.Row() < 0 )
                 [ -  + ]
    2509         [ #  # ]:          0 :             throw uno::RuntimeException( rtl::OUString("Internal failure, illegal param"), uno::Reference< uno::XInterface >() );
    2510                 :            :         // return a normal range ( even for multi-selection
    2511 [ +  - ][ +  - ]:         10 :         uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( pUnoRangesBase->GetDocShell(), aRange ) );
                 [ +  - ]
    2512 [ +  - ][ +  - ]:         10 :         return new ScVbaRange( mxParent, mxContext, xRange, true  );
         [ +  - ][ +  - ]
                 [ +  - ]
    2513                 :            :     }
    2514                 :            :     // Rows() - no params
    2515 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    2516 [ #  # ][ #  # ]:          0 :         return new ScVbaRange(  mxParent, mxContext, mxRanges, true );
         [ #  # ][ #  # ]
    2517 [ #  # ][ #  # ]:         10 :     return new ScVbaRange(  mxParent, mxContext, mxRange, true );
         [ #  # ][ #  # ]
    2518                 :            : }
    2519                 :            : 
    2520                 :            : uno::Reference< excel::XRange >
    2521                 :         44 : ScVbaRange::Columns(const uno::Any& aIndex ) throw (uno::RuntimeException)
    2522                 :            : {
    2523                 :         44 :     rtl::OUString sAddress;
    2524                 :            : 
    2525         [ +  - ]:         44 :     ScCellRangesBase* pUnoRangesBase = getCellRangesBase();
    2526         [ +  - ]:         44 :     ScRangeList aCellRanges = pUnoRangesBase->GetRangeList();
    2527                 :            : 
    2528         [ +  - ]:         44 :     ScRange aRange = *aCellRanges.front();
    2529         [ +  + ]:         44 :     if ( aIndex.hasValue() )
    2530                 :            :     {
    2531                 :         40 :         sal_Int32 nValue = 0;
    2532         [ +  + ]:         40 :         if ( aIndex >>= nValue )
    2533                 :            :         {
    2534                 :         14 :             aRange.aStart.SetCol( aRange.aStart.Col() + static_cast< SCCOL > ( --nValue ) );
    2535                 :         14 :             aRange.aEnd.SetCol( aRange.aStart.Col() );
    2536                 :            :         }
    2537                 :            : 
    2538         [ +  - ]:         26 :         else if ( aIndex >>= sAddress )
    2539                 :            :         {
    2540                 :         26 :             ScAddress::Details dDetails( formula::FormulaGrammar::CONV_XL_A1, 0, 0 );
    2541                 :         26 :             ScRange tmpRange;
    2542 [ +  - ][ +  - ]:         26 :             tmpRange.ParseCols( sAddress, excel::GetDocumentFromRange( mxRange ), dDetails );
         [ +  - ][ +  - ]
    2543                 :         26 :             SCCOL nStartCol = tmpRange.aStart.Col();
    2544                 :         26 :             SCCOL nEndCol = tmpRange.aEnd.Col();
    2545                 :            : 
    2546                 :         26 :             aRange.aStart.SetCol( aRange.aStart.Col() + nStartCol );
    2547                 :         26 :             aRange.aEnd.SetCol( aRange.aStart.Col() + ( nEndCol  - nStartCol ));
    2548                 :            :         }
    2549                 :            :         else
    2550         [ #  # ]:          0 :             throw uno::RuntimeException( rtl::OUString( "Illegal param"  ), uno::Reference< uno::XInterface >() );
    2551                 :            : 
    2552 [ +  - ][ -  + ]:         40 :         if ( aRange.aStart.Col() < 0 || aRange.aEnd.Col() < 0 )
                 [ -  + ]
    2553         [ #  # ]:         40 :             throw uno::RuntimeException( rtl::OUString("Internal failure, illegal param"), uno::Reference< uno::XInterface >() );
    2554                 :            :     }
    2555                 :            :     // Columns() - no params
    2556 [ +  - ][ +  - ]:         44 :     uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( pUnoRangesBase->GetDocShell(), aRange ) );
                 [ +  - ]
    2557 [ +  - ][ +  - ]:         44 :     return new ScVbaRange( mxParent, mxContext, xRange, false, true  );
         [ +  - ][ +  - ]
                 [ +  - ]
    2558                 :            : }
    2559                 :            : 
    2560                 :            : void
    2561                 :          0 : ScVbaRange::setMergeCells( const uno::Any& aIsMerged ) throw (script::BasicErrorException, uno::RuntimeException)
    2562                 :            : {
    2563                 :          0 :     bool bMerge = extractBoolFromAny( aIsMerged );
    2564                 :            : 
    2565         [ #  # ]:          0 :     if( mxRanges.is() )
    2566                 :            :     {
    2567 [ #  # ][ #  # ]:          0 :         sal_Int32 nCount = mxRanges->getCount();
    2568                 :            : 
    2569                 :            :         // VBA does nothing (no error) if the own ranges overlap somehow
    2570         [ #  # ]:          0 :         ::std::vector< table::CellRangeAddress > aList;
    2571         [ #  # ]:          0 :         for( sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex )
    2572                 :            :         {
    2573 [ #  # ][ #  # ]:          0 :             uno::Reference< sheet::XCellRangeAddressable > xRangeAddr( mxRanges->getByIndex( nIndex ), uno::UNO_QUERY_THROW );
                 [ #  # ]
    2574 [ #  # ][ #  # ]:          0 :             table::CellRangeAddress aAddress = xRangeAddr->getRangeAddress();
    2575 [ #  # ][ #  # ]:          0 :             for( ::std::vector< table::CellRangeAddress >::const_iterator aIt = aList.begin(), aEnd = aList.end(); aIt != aEnd; ++aIt )
         [ #  # ][ #  # ]
    2576 [ #  # ][ #  # ]:          0 :                 if( ScUnoConversion::Intersects( *aIt, aAddress ) )
    2577                 :            :                     return;
    2578 [ #  # ][ #  # ]:          0 :             aList.push_back( aAddress );
    2579                 :          0 :         }
    2580                 :            : 
    2581                 :            :         // (un)merge every range after it has been extended to intersecting merged ranges from sheet
    2582         [ #  # ]:          0 :         for( sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex )
    2583                 :            :         {
    2584 [ #  # ][ #  # ]:          0 :             uno::Reference< table::XCellRange > xRange( mxRanges->getByIndex( nIndex ), uno::UNO_QUERY_THROW );
                 [ #  # ]
    2585         [ #  # ]:          0 :             lclExpandAndMerge( xRange, bMerge );
    2586                 :          0 :         }
    2587                 :          0 :         return;
    2588                 :            :     }
    2589                 :            : 
    2590                 :            :     // otherwise, merge single range
    2591                 :          0 :     lclExpandAndMerge( mxRange, bMerge );
    2592                 :            : }
    2593                 :            : 
    2594                 :            : uno::Any
    2595                 :          0 : ScVbaRange::getMergeCells() throw (script::BasicErrorException, uno::RuntimeException)
    2596                 :            : {
    2597         [ #  # ]:          0 :     if( mxRanges.is() )
    2598                 :            :     {
    2599                 :          0 :         sal_Int32 nCount = mxRanges->getCount();
    2600         [ #  # ]:          0 :         for( sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex )
    2601                 :            :         {
    2602 [ #  # ][ #  # ]:          0 :             uno::Reference< table::XCellRange > xRange( mxRanges->getByIndex( nIndex ), uno::UNO_QUERY_THROW );
                 [ #  # ]
    2603         [ #  # ]:          0 :             util::TriState eMerged = lclGetMergedState( xRange );
    2604                 :            :             /*  Excel always returns NULL, if one range of the range list is
    2605                 :            :                 partly or completely merged. Even if all ranges are completely
    2606                 :            :                 merged, the return value is still NULL. */
    2607         [ #  # ]:          0 :             if( eMerged != util::TriState_NO )
    2608         [ #  # ]:          0 :                 return aNULL();
    2609         [ #  # ]:          0 :         }
    2610                 :            :         // no range is merged anyhow, return false
    2611                 :          0 :         return uno::Any( false );
    2612                 :            :     }
    2613                 :            : 
    2614                 :            :     // otherwise, check single range
    2615      [ #  #  # ]:          0 :     switch( lclGetMergedState( mxRange ) )
    2616                 :            :     {
    2617                 :          0 :         case util::TriState_YES:    return uno::Any( true );
    2618                 :          0 :         case util::TriState_NO:     return uno::Any( false );
    2619                 :          0 :         default:                    return aNULL();
    2620                 :            :     }
    2621                 :            : }
    2622                 :            : 
    2623                 :            : void
    2624                 :          0 : ScVbaRange::Copy(const ::uno::Any& Destination) throw (uno::RuntimeException)
    2625                 :            : {
    2626         [ #  # ]:          0 :     if ( Destination.hasValue() )
    2627                 :            :     {
    2628                 :            :         // #TODO support ( if necessary ) multi-area range in this scenario
    2629 [ #  # ][ #  # ]:          0 :         if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    2630         [ #  # ]:          0 :             throw uno::RuntimeException( rtl::OUString( "!!! That command cannot be used on multiple selections"  ), uno::Reference< uno::XInterface >() );
    2631         [ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( Destination, uno::UNO_QUERY_THROW );
    2632 [ #  # ][ #  # ]:          0 :         uno::Any aRange = xRange->getCellRange();
    2633                 :          0 :         uno::Reference< table::XCellRange > xCellRange;
    2634         [ #  # ]:          0 :         aRange >>= xCellRange;
    2635         [ #  # ]:          0 :         uno::Reference< sheet::XSheetCellRange > xSheetCellRange(xCellRange, ::uno::UNO_QUERY_THROW);
    2636 [ #  # ][ #  # ]:          0 :         uno::Reference< sheet::XSpreadsheet > xSheet = xSheetCellRange->getSpreadsheet();
    2637         [ #  # ]:          0 :         uno::Reference< table::XCellRange > xDest( xSheet, uno::UNO_QUERY_THROW );
    2638         [ #  # ]:          0 :         uno::Reference< sheet::XCellRangeMovement > xMover( xSheet, uno::UNO_QUERY_THROW);
    2639         [ #  # ]:          0 :         uno::Reference< sheet::XCellAddressable > xDestination( xDest->getCellByPosition(
    2640 [ #  # ][ #  # ]:          0 :                                                 xRange->getColumn()-1,xRange->getRow()-1), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    2641         [ #  # ]:          0 :         uno::Reference< sheet::XCellRangeAddressable > xSource( mxRange, uno::UNO_QUERY);
    2642 [ #  # ][ #  # ]:          0 :         xMover->copyRange( xDestination->getCellAddress(), xSource->getRangeAddress() );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    2643                 :            :     }
    2644                 :            :     else
    2645                 :            :     {
    2646         [ #  # ]:          0 :         if ( m_Areas->getCount() > 1 )
    2647                 :            :         {
    2648         [ #  # ]:          0 :             uno::Reference< frame::XModel > xModel = excel::GetModelFromRange( mxRanges );
    2649         [ #  # ]:          0 :             ScCellRangesBase* pUnoRangesBase = getCellRangesBase();
    2650         [ #  # ]:          0 :             ScRangeList aList =  pUnoRangesBase->GetRangeList();
    2651 [ #  # ][ #  # ]:          0 :             if ( !excel::implnCopyRanges( xModel, aList ) )
    2652                 :            :             {
    2653         [ #  # ]:          0 :                 throw uno::RuntimeException( rtl::OUString( "That command cannot be used on multiple selections"  ), uno::Reference< uno::XInterface >() );
    2654         [ #  # ]:          0 :             }
    2655                 :            :         }
    2656                 :            :         else
    2657                 :            :         {
    2658                 :          0 :             ScRange aRange;
    2659         [ #  # ]:          0 :             RangeHelper thisRange( mxRange );
    2660         [ #  # ]:          0 :             uno::Reference< frame::XModel > xModel = excel::GetModelFromRange( mxRange );
    2661 [ #  # ][ #  # ]:          0 :             ScUnoConversion::FillScRange( aRange, thisRange.getCellRangeAddressable()->getRangeAddress() );
                 [ #  # ]
    2662 [ #  # ][ #  # ]:          0 :             excel::implnCopyRange( xModel, aRange );
    2663                 :            :         }
    2664                 :            :     }
    2665                 :          0 : }
    2666                 :            : 
    2667                 :            : void
    2668                 :          0 : ScVbaRange::Cut(const ::uno::Any& Destination) throw (uno::RuntimeException)
    2669                 :            : {
    2670         [ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
    2671         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString( "That command cannot be used on multiple selections"  ), uno::Reference< uno::XInterface >() );
    2672         [ #  # ]:          0 :     if (Destination.hasValue())
    2673                 :            :     {
    2674         [ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( Destination, uno::UNO_QUERY_THROW );
    2675 [ #  # ][ #  # ]:          0 :         uno::Reference< table::XCellRange > xCellRange( xRange->getCellRange(), uno::UNO_QUERY_THROW );
                 [ #  # ]
    2676         [ #  # ]:          0 :         uno::Reference< sheet::XSheetCellRange > xSheetCellRange(xCellRange, ::uno::UNO_QUERY_THROW );
    2677 [ #  # ][ #  # ]:          0 :         uno::Reference< sheet::XSpreadsheet > xSheet = xSheetCellRange->getSpreadsheet();
    2678         [ #  # ]:          0 :         uno::Reference< table::XCellRange > xDest( xSheet, uno::UNO_QUERY_THROW );
    2679         [ #  # ]:          0 :         uno::Reference< sheet::XCellRangeMovement > xMover( xSheet, uno::UNO_QUERY_THROW);
    2680         [ #  # ]:          0 :         uno::Reference< sheet::XCellAddressable > xDestination( xDest->getCellByPosition(
    2681 [ #  # ][ #  # ]:          0 :                                                 xRange->getColumn()-1,xRange->getRow()-1), uno::UNO_QUERY);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    2682         [ #  # ]:          0 :         uno::Reference< sheet::XCellRangeAddressable > xSource( mxRange, uno::UNO_QUERY);
    2683 [ #  # ][ #  # ]:          0 :         xMover->moveRange( xDestination->getCellAddress(), xSource->getRangeAddress() );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    2684                 :            :     }
    2685                 :            :     else {
    2686         [ #  # ]:          0 :         uno::Reference< frame::XModel > xModel = excel::GetModelFromRange( mxRange );
    2687         [ #  # ]:          0 :         Select();
    2688         [ #  # ]:          0 :         excel::implnCut( xModel );
    2689                 :            :     }
    2690                 :          0 : }
    2691                 :            : 
    2692                 :            : void
    2693                 :          0 : ScVbaRange::setNumberFormat( const uno::Any& aFormat ) throw ( script::BasicErrorException, uno::RuntimeException)
    2694                 :            : {
    2695                 :          0 :     rtl::OUString sFormat;
    2696                 :          0 :     aFormat >>= sFormat;
    2697 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    2698                 :            :     {
    2699 [ #  # ][ #  # ]:          0 :         sal_Int32 nItems = m_Areas->getCount();
    2700         [ #  # ]:          0 :         for ( sal_Int32 index=1; index <= nItems; ++index )
    2701                 :            :         {
    2702 [ #  # ][ #  # ]:          0 :             uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    2703 [ #  # ][ #  # ]:          0 :             xRange->setNumberFormat( aFormat );
    2704                 :          0 :         }
    2705                 :          0 :         return;
    2706                 :            :     }
    2707         [ #  # ]:          0 :     NumFormatHelper numFormat( mxRange );
    2708 [ #  # ][ #  # ]:          0 :     numFormat.setNumberFormat( sFormat );
                 [ #  # ]
    2709                 :            : }
    2710                 :            : 
    2711                 :            : uno::Any
    2712                 :          0 : ScVbaRange::getNumberFormat() throw ( script::BasicErrorException, uno::RuntimeException)
    2713                 :            : {
    2714                 :            : 
    2715 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    2716                 :            :     {
    2717 [ #  # ][ #  # ]:          0 :         sal_Int32 nItems = m_Areas->getCount();
    2718         [ #  # ]:          0 :         uno::Any aResult = aNULL();
    2719         [ #  # ]:          0 :         for ( sal_Int32 index=1; index <= nItems; ++index )
    2720                 :            :         {
    2721 [ #  # ][ #  # ]:          0 :             uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    2722                 :            :             // if the numberformat of one area is different to another
    2723                 :            :             // return null
    2724         [ #  # ]:          0 :             if ( index > 1 )
    2725 [ #  # ][ #  # ]:          0 :                 if ( aResult != xRange->getNumberFormat() )
                 [ #  # ]
    2726         [ #  # ]:          0 :                     return aNULL();
    2727 [ #  # ][ #  # ]:          0 :             aResult = xRange->getNumberFormat();
    2728 [ #  # ][ #  # ]:          0 :             if ( aNULL() == aResult )
    2729         [ #  # ]:          0 :                 return aNULL();
    2730         [ #  # ]:          0 :         }
    2731                 :          0 :         return aResult;
    2732                 :            :     }
    2733         [ #  # ]:          0 :     NumFormatHelper numFormat( mxRange );
    2734         [ #  # ]:          0 :     rtl::OUString sFormat = numFormat.getNumberFormatString();
    2735         [ #  # ]:          0 :     if ( !sFormat.isEmpty() )
    2736         [ #  # ]:          0 :         return uno::makeAny( sFormat );
    2737 [ #  # ][ #  # ]:          0 :     return aNULL();
    2738                 :            : }
    2739                 :            : 
    2740                 :            : uno::Reference< excel::XRange >
    2741                 :          0 : ScVbaRange::Resize( const uno::Any &RowSize, const uno::Any &ColumnSize ) throw (uno::RuntimeException)
    2742                 :            : {
    2743                 :          0 :     long nRowSize = 0, nColumnSize = 0;
    2744                 :          0 :     sal_Bool bIsRowChanged = ( RowSize >>= nRowSize ), bIsColumnChanged = ( ColumnSize >>= nColumnSize );
    2745         [ #  # ]:          0 :     uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, ::uno::UNO_QUERY_THROW);
    2746         [ #  # ]:          0 :     uno::Reference< sheet::XSheetCellRange > xSheetRange(mxRange, ::uno::UNO_QUERY_THROW);
    2747 [ #  # ][ #  # ]:          0 :     uno::Reference< sheet::XSheetCellCursor > xCursor( xSheetRange->getSpreadsheet()->createCursorByRange(xSheetRange), ::uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
                 [ #  # ]
    2748                 :            : 
    2749         [ #  # ]:          0 :     if( !bIsRowChanged )
    2750 [ #  # ][ #  # ]:          0 :         nRowSize = xColumnRowRange->getRows()->getCount();
         [ #  # ][ #  # ]
    2751         [ #  # ]:          0 :     if( !bIsColumnChanged )
    2752 [ #  # ][ #  # ]:          0 :         nColumnSize = xColumnRowRange->getColumns()->getCount();
         [ #  # ][ #  # ]
    2753                 :            : 
    2754 [ #  # ][ #  # ]:          0 :     xCursor->collapseToSize( nColumnSize, nRowSize );
    2755         [ #  # ]:          0 :     uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xCursor, ::uno::UNO_QUERY_THROW );
    2756 [ #  # ][ #  # ]:          0 :     uno::Reference< table::XCellRange > xRange( xSheetRange->getSpreadsheet(), ::uno::UNO_QUERY_THROW );
                 [ #  # ]
    2757         [ #  # ]:          0 :     return new ScVbaRange( mxParent, mxContext,xRange->getCellRangeByPosition(
    2758         [ #  # ]:          0 :                                         xCellRangeAddressable->getRangeAddress().StartColumn,
    2759         [ #  # ]:          0 :                                         xCellRangeAddressable->getRangeAddress().StartRow,
    2760         [ #  # ]:          0 :                                         xCellRangeAddressable->getRangeAddress().EndColumn,
    2761 [ #  # ][ #  # ]:          0 :                                         xCellRangeAddressable->getRangeAddress().EndRow ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    2762                 :            : }
    2763                 :            : 
    2764                 :            : void
    2765                 :          0 : ScVbaRange::setWrapText( const uno::Any& aIsWrapped ) throw (script::BasicErrorException, uno::RuntimeException)
    2766                 :            : {
    2767 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    2768                 :            :     {
    2769 [ #  # ][ #  # ]:          0 :         sal_Int32 nItems = m_Areas->getCount();
    2770                 :          0 :         uno::Any aResult;
    2771         [ #  # ]:          0 :         for ( sal_Int32 index=1; index <= nItems; ++index )
    2772                 :            :         {
    2773 [ #  # ][ #  # ]:          0 :             uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    2774 [ #  # ][ #  # ]:          0 :             xRange->setWrapText( aIsWrapped );
    2775                 :          0 :         }
    2776                 :          0 :         return;
    2777                 :            :     }
    2778                 :            : 
    2779         [ #  # ]:          0 :     uno::Reference< beans::XPropertySet > xProps(mxRange, ::uno::UNO_QUERY_THROW );
    2780         [ #  # ]:          0 :     bool bIsWrapped = extractBoolFromAny( aIsWrapped );
    2781 [ #  # ][ #  # ]:          0 :     xProps->setPropertyValue( rtl::OUString(  "IsTextWrapped"  ), uno::Any( bIsWrapped ) );
                 [ #  # ]
    2782                 :            : }
    2783                 :            : 
    2784                 :            : uno::Any
    2785                 :          0 : ScVbaRange::getWrapText() throw (script::BasicErrorException, uno::RuntimeException)
    2786                 :            : {
    2787 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    2788                 :            :     {
    2789 [ #  # ][ #  # ]:          0 :         sal_Int32 nItems = m_Areas->getCount();
    2790                 :          0 :         uno::Any aResult;
    2791         [ #  # ]:          0 :         for ( sal_Int32 index=1; index <= nItems; ++index )
    2792                 :            :         {
    2793 [ #  # ][ #  # ]:          0 :                 uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    2794         [ #  # ]:          0 :                 if ( index > 1 )
    2795 [ #  # ][ #  # ]:          0 :                 if ( aResult != xRange->getWrapText() )
                 [ #  # ]
    2796         [ #  # ]:          0 :                     return aNULL();
    2797 [ #  # ][ #  # ]:          0 :             aResult = xRange->getWrapText();
                 [ #  # ]
    2798                 :          0 :         }
    2799                 :          0 :         return aResult;
    2800                 :            :     }
    2801                 :            : 
    2802         [ #  # ]:          0 :     SfxItemSet* pDataSet = getCurrentDataSet();
    2803                 :            : 
    2804         [ #  # ]:          0 :     SfxItemState eState = pDataSet->GetItemState( ATTR_LINEBREAK, true, NULL);
    2805         [ #  # ]:          0 :     if ( eState == SFX_ITEM_DONTCARE )
    2806         [ #  # ]:          0 :         return aNULL();
    2807                 :            : 
    2808         [ #  # ]:          0 :     uno::Reference< beans::XPropertySet > xProps(mxRange, ::uno::UNO_QUERY_THROW );
    2809 [ #  # ][ #  # ]:          0 :     uno::Any aValue = xProps->getPropertyValue( rtl::OUString(  "IsTextWrapped"  ) );
    2810                 :          0 :     return aValue;
    2811                 :            : }
    2812                 :            : 
    2813                 :          0 : uno::Reference< excel::XInterior > ScVbaRange::Interior( ) throw ( script::BasicErrorException, uno::RuntimeException)
    2814                 :            : {
    2815         [ #  # ]:          0 :     uno::Reference< beans::XPropertySet > xProps( mxRange, uno::UNO_QUERY_THROW );
    2816 [ #  # ][ #  # ]:          0 :         return new ScVbaInterior ( this, mxContext, xProps, getScDocument() );
         [ #  # ][ #  # ]
                 [ #  # ]
    2817                 :            : }
    2818                 :            : uno::Reference< excel::XRange >
    2819                 :         20 : ScVbaRange::Range( const uno::Any &Cell1, const uno::Any &Cell2 ) throw (uno::RuntimeException)
    2820                 :            : {
    2821                 :         20 :     return Range( Cell1, Cell2, false );
    2822                 :            : }
    2823                 :            : uno::Reference< excel::XRange >
    2824                 :         68 : ScVbaRange::Range( const uno::Any &Cell1, const uno::Any &Cell2, bool bForceUseInpuRangeTab ) throw (uno::RuntimeException)
    2825                 :            : 
    2826                 :            : {
    2827                 :         68 :     uno::Reference< table::XCellRange > xCellRange = mxRange;
    2828                 :            : 
    2829 [ +  - ][ -  + ]:         68 :     if ( m_Areas->getCount() > 1 )
                 [ +  - ]
    2830                 :            :     {
    2831         [ #  # ]:          0 :         uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW );
    2832 [ #  # ][ #  # ]:          0 :         xCellRange.set( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
                 [ #  # ]
    2833                 :            :     }
    2834                 :            :     else
    2835         [ +  - ]:         68 :         xCellRange.set( mxRange );
    2836                 :            : 
    2837         [ +  - ]:         68 :     RangeHelper thisRange( xCellRange );
    2838         [ +  - ]:         68 :     uno::Reference< table::XCellRange > xRanges = thisRange.getCellRangeFromSheet();
    2839         [ +  - ]:         68 :     uno::Reference< sheet::XCellRangeAddressable > xAddressable( xRanges, uno::UNO_QUERY_THROW );
    2840                 :            : 
    2841                 :            :     uno::Reference< table::XCellRange > xReferrer =
    2842 [ +  - ][ +  - ]:        136 :         xRanges->getCellRangeByPosition( getColumn()-1, getRow()-1,
                 [ +  - ]
    2843         [ +  - ]:         68 :                 xAddressable->getRangeAddress().EndColumn,
    2844 [ +  - ][ +  - ]:        204 :                 xAddressable->getRangeAddress().EndRow );
         [ +  - ][ +  - ]
    2845                 :            :     // xAddressable now for this range
    2846         [ +  - ]:         68 :     xAddressable.set( xReferrer, uno::UNO_QUERY_THROW );
    2847                 :            : 
    2848         [ -  + ]:         68 :     if( !Cell1.hasValue() )
    2849                 :            :         throw uno::RuntimeException(
    2850                 :            :             rtl::OUString(  " Invalid Argument "  ),
    2851         [ #  # ]:          0 :             uno::Reference< XInterface >() );
    2852                 :            : 
    2853                 :         68 :     table::CellRangeAddress resultAddress;
    2854 [ +  - ][ +  - ]:         68 :     table::CellRangeAddress parentRangeAddress = xAddressable->getRangeAddress();
    2855                 :            : 
    2856                 :         68 :     ScRange aRange;
    2857                 :            :     // Cell1 defined only
    2858         [ +  - ]:         68 :     if ( !Cell2.hasValue() )
    2859                 :            :     {
    2860                 :         68 :         rtl::OUString sName;
    2861                 :         68 :         Cell1 >>= sName;
    2862         [ +  - ]:         68 :         RangeHelper referRange( xReferrer );
    2863 [ +  - ][ +  - ]:         68 :         table::CellRangeAddress referAddress = referRange.getCellRangeAddressable()->getRangeAddress();
                 [ +  - ]
    2864 [ +  + ][ +  - ]:         68 :         return getRangeForName( mxContext, sName, getScDocShell(), referAddress );
         [ +  - ][ +  - ]
                 [ +  - ]
    2865                 :            : 
    2866                 :            :     }
    2867                 :            :     else
    2868                 :            :     {
    2869                 :          0 :         table::CellRangeAddress  cell1, cell2;
    2870 [ #  # ][ #  # ]:          0 :         cell1 = getCellRangeAddressForVBARange( Cell1, getScDocShell() );
    2871                 :            :         // Cell1 & Cell2 defined
    2872                 :            :         // Excel seems to combine the range as the range defined by
    2873                 :            :         // the combination of Cell1 & Cell2
    2874                 :            : 
    2875 [ #  # ][ #  # ]:          0 :         cell2 = getCellRangeAddressForVBARange( Cell2, getScDocShell() );
    2876                 :            : 
    2877         [ #  # ]:          0 :         resultAddress.StartColumn = ( cell1.StartColumn <  cell2.StartColumn ) ? cell1.StartColumn : cell2.StartColumn;
    2878         [ #  # ]:          0 :         resultAddress.StartRow = ( cell1.StartRow <  cell2.StartRow ) ? cell1.StartRow : cell2.StartRow;
    2879         [ #  # ]:          0 :         resultAddress.EndColumn = ( cell1.EndColumn >  cell2.EndColumn ) ? cell1.EndColumn : cell2.EndColumn;
    2880         [ #  # ]:          0 :         resultAddress.EndRow = ( cell1.EndRow >  cell2.EndRow ) ? cell1.EndRow : cell2.EndRow;
    2881         [ #  # ]:          0 :         if ( bForceUseInpuRangeTab )
    2882                 :            :         {
    2883                 :            :             // this is a call from Application.Range( x,y )
    2884                 :            :             // its possiblefor x or y to specify a different sheet from
    2885                 :            :             // the current or active on ( but they must be the same )
    2886         [ #  # ]:          0 :             if ( cell1.Sheet != cell2.Sheet )
    2887         [ #  # ]:          0 :                 throw uno::RuntimeException();
    2888                 :          0 :             parentRangeAddress.Sheet = cell1.Sheet;
    2889                 :            :         }
    2890                 :            :         else
    2891                 :            :         {
    2892                 :            :             // this is not a call from Application.Range( x,y )
    2893                 :            :             // if a different sheet from this range is specified it's
    2894                 :            :             // an error
    2895 [ #  # ][ #  # ]:          0 :             if ( parentRangeAddress.Sheet != cell1.Sheet
    2896                 :            :             || parentRangeAddress.Sheet != cell2.Sheet
    2897                 :            :             )
    2898         [ #  # ]:          0 :                 throw uno::RuntimeException();
    2899                 :            : 
    2900                 :            :         }
    2901                 :          0 :         ScUnoConversion::FillScRange( aRange, resultAddress );
    2902                 :            :     }
    2903                 :          0 :     ScRange parentAddress;
    2904                 :          0 :     ScUnoConversion::FillScRange( parentAddress, parentRangeAddress);
    2905 [ #  # ][ #  # ]:          0 :     if ( aRange.aStart.Col() >= 0 && aRange.aStart.Row() >= 0 && aRange.aEnd.Col() >= 0 && aRange.aEnd.Row() >= 0 )
         [ #  # ][ #  # ]
                 [ #  # ]
    2906                 :            :     {
    2907                 :          0 :         sal_Int32 nStartX = parentAddress.aStart.Col() + aRange.aStart.Col();
    2908                 :          0 :         sal_Int32 nStartY = parentAddress.aStart.Row() + aRange.aStart.Row();
    2909                 :          0 :         sal_Int32 nEndX = parentAddress.aStart.Col() + aRange.aEnd.Col();
    2910                 :          0 :         sal_Int32 nEndY = parentAddress.aStart.Row() + aRange.aEnd.Row();
    2911                 :            : 
    2912         [ #  # ]:          0 :         if ( nStartX <= nEndX && nEndX <= parentAddress.aEnd.Col() &&
           [ #  #  #  # ]
         [ #  # ][ #  # ]
    2913                 :          0 :              nStartY <= nEndY && nEndY <= parentAddress.aEnd.Row() )
    2914                 :            :         {
    2915                 :          0 :             ScRange aNew( (SCCOL)nStartX, (SCROW)nStartY, parentAddress.aStart.Tab(),
    2916                 :          0 :                           (SCCOL)nEndX, (SCROW)nEndY, parentAddress.aEnd.Tab() );
    2917 [ #  # ][ #  # ]:          0 :             xCellRange = new ScCellRangeObj( getScDocShell(), aNew );
         [ #  # ][ #  # ]
    2918                 :            :         }
    2919                 :            :     }
    2920                 :            : 
    2921 [ #  # ][ #  # ]:         68 :     return new ScVbaRange( mxParent, mxContext, xCellRange );
         [ #  # ][ #  # ]
                 [ +  - ]
    2922                 :            : 
    2923                 :            : }
    2924                 :            : 
    2925                 :            : // Allow access to underlying openoffice uno api ( useful for debugging
    2926                 :            : // with openoffice basic )
    2927                 :          0 : uno::Any SAL_CALL ScVbaRange::getCellRange(  ) throw (uno::RuntimeException)
    2928                 :            : {
    2929                 :          0 :     uno::Any aAny;
    2930         [ #  # ]:          0 :     if ( mxRanges.is() )
    2931         [ #  # ]:          0 :         aAny <<= mxRanges;
    2932         [ #  # ]:          0 :     else if ( mxRange.is() )
    2933         [ #  # ]:          0 :         aAny <<= mxRange;
    2934                 :          0 :     return aAny;
    2935                 :            : }
    2936                 :            : 
    2937                 :          0 : uno::Any ScVbaRange::getCellRange( const uno::Reference< excel::XRange >& rxRange ) throw (uno::RuntimeException)
    2938                 :            : {
    2939         [ #  # ]:          0 :     if( ScVbaRange* pVbaRange = getImplementation( rxRange ) )
    2940                 :          0 :         return pVbaRange->getCellRange();
    2941         [ #  # ]:          0 :     throw uno::RuntimeException();
    2942                 :            : }
    2943                 :            : 
    2944                 :            : static sal_uInt16
    2945                 :          0 : getPasteFlags (sal_Int32 Paste)
    2946                 :            : {
    2947                 :          0 :     sal_uInt16 nFlags = IDF_NONE;
    2948   [ #  #  #  #  :          0 :     switch (Paste) {
                #  #  # ]
    2949                 :            :         case excel::XlPasteType::xlPasteComments:
    2950                 :          0 :         nFlags = IDF_NOTE;break;
    2951                 :            :         case excel::XlPasteType::xlPasteFormats:
    2952                 :          0 :         nFlags = IDF_ATTRIB;break;
    2953                 :            :         case excel::XlPasteType::xlPasteFormulas:
    2954                 :          0 :         nFlags = IDF_FORMULA;break;
    2955                 :            :         case excel::XlPasteType::xlPasteFormulasAndNumberFormats :
    2956                 :            :         case excel::XlPasteType::xlPasteValues:
    2957                 :            : #ifdef VBA_OOBUILD_HACK
    2958                 :          0 :         nFlags = ( IDF_VALUE | IDF_DATETIME | IDF_STRING | IDF_SPECIAL_BOOLEAN ); break;
    2959                 :            : #else
    2960                 :            :         nFlags = ( IDF_VALUE | IDF_DATETIME | IDF_STRING ); break;
    2961                 :            : #endif
    2962                 :            :         case excel::XlPasteType::xlPasteValuesAndNumberFormats:
    2963                 :          0 :         nFlags = IDF_VALUE | IDF_ATTRIB; break;
    2964                 :            :         case excel::XlPasteType::xlPasteColumnWidths:
    2965                 :            :         case excel::XlPasteType::xlPasteValidation:
    2966                 :          0 :         nFlags = IDF_NONE;break;
    2967                 :            :     case excel::XlPasteType::xlPasteAll:
    2968                 :            :         case excel::XlPasteType::xlPasteAllExceptBorders:
    2969                 :            :     default:
    2970                 :          0 :         nFlags = IDF_ALL;break;
    2971                 :            :     };
    2972                 :          0 : return nFlags;
    2973                 :            : }
    2974                 :            : 
    2975                 :            : static sal_uInt16
    2976                 :          0 : getPasteFormulaBits( sal_Int32 Operation)
    2977                 :            : {
    2978                 :          0 :     sal_uInt16 nFormulaBits = PASTE_NOFUNC ;
    2979   [ #  #  #  #  :          0 :     switch (Operation)
                      # ]
    2980                 :            :     {
    2981                 :            :     case excel::XlPasteSpecialOperation::xlPasteSpecialOperationAdd:
    2982                 :          0 :         nFormulaBits = PASTE_ADD;break;
    2983                 :            :     case excel::XlPasteSpecialOperation::xlPasteSpecialOperationSubtract:
    2984                 :          0 :         nFormulaBits = PASTE_SUB;break;
    2985                 :            :     case excel::XlPasteSpecialOperation::xlPasteSpecialOperationMultiply:
    2986                 :          0 :         nFormulaBits = PASTE_MUL;break;
    2987                 :            :     case excel::XlPasteSpecialOperation::xlPasteSpecialOperationDivide:
    2988                 :          0 :         nFormulaBits = PASTE_DIV;break;
    2989                 :            : 
    2990                 :            :     case excel::XlPasteSpecialOperation::xlPasteSpecialOperationNone:
    2991                 :            :     default:
    2992                 :          0 :         nFormulaBits = PASTE_NOFUNC; break;
    2993                 :            :     };
    2994                 :            : 
    2995                 :          0 : return nFormulaBits;
    2996                 :            : }
    2997                 :            : void SAL_CALL
    2998                 :          0 : ScVbaRange::PasteSpecial( const uno::Any& Paste, const uno::Any& Operation, const uno::Any& SkipBlanks, const uno::Any& Transpose ) throw (::com::sun::star::uno::RuntimeException)
    2999                 :            : {
    3000 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    3001         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString( "That command cannot be used on multiple selections"  ), uno::Reference< uno::XInterface >() );
    3002         [ #  # ]:          0 :         ScDocShell* pShell = getScDocShell();
    3003                 :            : 
    3004 [ #  # ][ #  # ]:          0 :         uno::Reference< frame::XModel > xModel( ( pShell ? pShell->GetModel() : NULL ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    3005 [ #  # ][ #  # ]:          0 :     uno::Reference< view::XSelectionSupplier > xSelection( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
                 [ #  # ]
    3006                 :            :     // select this range
    3007 [ #  # ][ #  # ]:          0 :     xSelection->select( uno::makeAny( mxRange ) );
                 [ #  # ]
    3008                 :            :     // set up defaults
    3009                 :          0 :     sal_Int32 nPaste = excel::XlPasteType::xlPasteAll;
    3010                 :          0 :     sal_Int32 nOperation = excel::XlPasteSpecialOperation::xlPasteSpecialOperationNone;
    3011                 :          0 :     sal_Bool bTranspose = false;
    3012                 :          0 :     sal_Bool bSkipBlanks = false;
    3013                 :            : 
    3014         [ #  # ]:          0 :     if ( Paste.hasValue() )
    3015                 :          0 :         Paste >>= nPaste;
    3016         [ #  # ]:          0 :     if ( Operation.hasValue() )
    3017                 :          0 :         Operation >>= nOperation;
    3018         [ #  # ]:          0 :     if ( SkipBlanks.hasValue() )
    3019                 :          0 :         SkipBlanks >>= bSkipBlanks;
    3020         [ #  # ]:          0 :     if ( Transpose.hasValue() )
    3021                 :          0 :         Transpose >>= bTranspose;
    3022                 :            : 
    3023                 :          0 :     sal_uInt16 nFlags = getPasteFlags(nPaste);
    3024                 :          0 :     sal_uInt16 nFormulaBits = getPasteFormulaBits(nOperation);
    3025 [ #  # ][ #  # ]:          0 :     excel::implnPasteSpecial(pShell->GetModel(), nFlags,nFormulaBits,bSkipBlanks,bTranspose);
    3026                 :          0 : }
    3027                 :            : 
    3028                 :            : uno::Reference< excel::XRange >
    3029                 :          8 : ScVbaRange::getEntireColumnOrRow( bool bColumn ) throw (uno::RuntimeException)
    3030                 :            : {
    3031         [ +  - ]:          8 :     ScCellRangesBase* pUnoRangesBase = getCellRangesBase();
    3032                 :            :     // copy the range list
    3033         [ +  - ]:          8 :     ScRangeList aCellRanges = pUnoRangesBase->GetRangeList();
    3034                 :            : 
    3035 [ +  - ][ +  + ]:         16 :     for ( size_t i = 0, nRanges = aCellRanges.size(); i < nRanges; ++i )
    3036                 :            :     {
    3037         [ +  - ]:          8 :         ScRange* pRange = aCellRanges[ i ];
    3038         [ +  + ]:          8 :         if ( bColumn )
    3039                 :            :         {
    3040                 :          6 :             pRange->aStart.SetRow( 0 );
    3041                 :          6 :             pRange->aEnd.SetRow( MAXROW );
    3042                 :            :         }
    3043                 :            :         else
    3044                 :            :         {
    3045                 :          2 :             pRange->aStart.SetCol( 0 );
    3046                 :          2 :             pRange->aEnd.SetCol( MAXCOL );
    3047                 :            :         }
    3048                 :            :     }
    3049 [ +  - ][ -  + ]:          8 :     if ( aCellRanges.size() > 1 ) // Multi-Area
    3050                 :            :     {
    3051 [ #  # ][ #  # ]:          0 :         uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( pUnoRangesBase->GetDocShell(), aCellRanges ) );
                 [ #  # ]
    3052                 :            : 
    3053 [ #  # ][ #  # ]:          0 :         return new ScVbaRange( mxParent, mxContext, xRanges, !bColumn, bColumn );
         [ #  # ][ #  # ]
    3054                 :            :     }
    3055 [ +  - ][ +  - ]:          8 :     uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( pUnoRangesBase->GetDocShell(), *aCellRanges.front() ) );
         [ +  - ][ +  - ]
    3056 [ +  - ][ +  - ]:          8 :     return new ScVbaRange( mxParent, mxContext, xRange, !bColumn, bColumn  );
         [ +  - ][ +  - ]
                 [ +  - ]
    3057                 :            : }
    3058                 :            : 
    3059                 :            : uno::Reference< excel::XRange > SAL_CALL
    3060                 :          2 : ScVbaRange::getEntireRow() throw (uno::RuntimeException)
    3061                 :            : {
    3062                 :          2 :     return getEntireColumnOrRow(false);
    3063                 :            : }
    3064                 :            : 
    3065                 :            : uno::Reference< excel::XRange > SAL_CALL
    3066                 :          6 : ScVbaRange::getEntireColumn() throw (uno::RuntimeException)
    3067                 :            : {
    3068                 :          6 :     return getEntireColumnOrRow();
    3069                 :            : }
    3070                 :            : 
    3071                 :            : uno::Reference< excel::XComment > SAL_CALL
    3072                 :          0 : ScVbaRange::AddComment( const uno::Any& Text ) throw (uno::RuntimeException)
    3073                 :            : {
    3074                 :            :     // if there is already a comment in the top-left cell then throw
    3075 [ #  # ][ #  # ]:          0 :     if( getComment().is() )
    3076         [ #  # ]:          0 :         throw uno::RuntimeException();
    3077                 :            : 
    3078                 :            :     // workaround: Excel allows to create empty comment, Calc does not
    3079                 :          0 :     ::rtl::OUString aNoteText;
    3080 [ #  # ][ #  # ]:          0 :     if( Text.hasValue() && !(Text >>= aNoteText) )
                 [ #  # ]
    3081         [ #  # ]:          0 :         throw uno::RuntimeException();
    3082         [ #  # ]:          0 :     if( aNoteText.isEmpty() )
    3083                 :          0 :         aNoteText = ::rtl::OUString( sal_Unicode( ' ' ) );
    3084                 :            : 
    3085                 :            :     // try to create a new annotation
    3086         [ #  # ]:          0 :     table::CellRangeAddress aRangePos = lclGetRangeAddress( mxRange );
    3087                 :          0 :     table::CellAddress aNotePos( aRangePos.Sheet, aRangePos.StartColumn, aRangePos.StartRow );
    3088         [ #  # ]:          0 :     uno::Reference< sheet::XSheetCellRange > xCellRange( mxRange, uno::UNO_QUERY_THROW );
    3089 [ #  # ][ #  # ]:          0 :     uno::Reference< sheet::XSheetAnnotationsSupplier > xAnnosSupp( xCellRange->getSpreadsheet(), uno::UNO_QUERY_THROW );
                 [ #  # ]
    3090 [ #  # ][ #  # ]:          0 :     uno::Reference< sheet::XSheetAnnotations > xAnnos( xAnnosSupp->getAnnotations(), uno::UNO_SET_THROW );
                 [ #  # ]
    3091 [ #  # ][ #  # ]:          0 :     xAnnos->insertNew( aNotePos, aNoteText );
    3092 [ #  # ][ #  # ]:          0 :     return new ScVbaComment( this, mxContext, getUnoModel(), mxRange );
         [ #  # ][ #  # ]
                 [ #  # ]
    3093                 :            : }
    3094                 :            : 
    3095                 :            : uno::Reference< excel::XComment > SAL_CALL
    3096                 :          0 : ScVbaRange::getComment() throw (uno::RuntimeException)
    3097                 :            : {
    3098                 :            :     // intentional behavior to return a null object if no
    3099                 :            :     // comment defined
    3100 [ #  # ][ #  # ]:          0 :     uno::Reference< excel::XComment > xComment( new ScVbaComment( this, mxContext, getUnoModel(), mxRange ) );
         [ #  # ][ #  # ]
                 [ #  # ]
    3101 [ #  # ][ #  # ]:          0 :     if ( xComment->Text( uno::Any(), uno::Any(), uno::Any() ).isEmpty() )
                 [ #  # ]
    3102         [ #  # ]:          0 :         return NULL;
    3103                 :          0 :     return xComment;
    3104                 :            : 
    3105                 :            : }
    3106                 :            : 
    3107                 :            : uno::Reference< beans::XPropertySet >
    3108                 :          0 : getRowOrColumnProps( const uno::Reference< table::XCellRange >& xCellRange, bool bRows ) throw ( uno::RuntimeException )
    3109                 :            : {
    3110         [ #  # ]:          0 :     uno::Reference< table::XColumnRowRange > xColRow( xCellRange, uno::UNO_QUERY_THROW );
    3111                 :          0 :     uno::Reference< beans::XPropertySet > xProps;
    3112         [ #  # ]:          0 :     if ( bRows )
    3113 [ #  # ][ #  # ]:          0 :         xProps.set( xColRow->getRows(), uno::UNO_QUERY_THROW );
                 [ #  # ]
    3114                 :            :     else
    3115 [ #  # ][ #  # ]:          0 :         xProps.set( xColRow->getColumns(), uno::UNO_QUERY_THROW );
                 [ #  # ]
    3116                 :          0 :     return xProps;
    3117                 :            : }
    3118                 :            : 
    3119                 :            : uno::Any SAL_CALL
    3120                 :          0 : ScVbaRange::getHidden() throw (uno::RuntimeException)
    3121                 :            : {
    3122                 :            :     // if multi-area result is the result of the
    3123                 :            :     // first area
    3124 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    3125                 :            :     {
    3126 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(sal_Int32(1)), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    3127 [ #  # ][ #  # ]:          0 :         return xRange->getHidden();
    3128                 :            :     }
    3129                 :          0 :     bool bIsVisible = false;
    3130                 :            :     try
    3131                 :            :     {
    3132         [ #  # ]:          0 :         uno::Reference< beans::XPropertySet > xProps = getRowOrColumnProps( mxRange, mbIsRows );
    3133 [ #  # ][ #  # ]:          0 :         if ( !( xProps->getPropertyValue( ISVISIBLE ) >>= bIsVisible ) )
                 [ #  # ]
    3134         [ #  # ]:          0 :             throw uno::RuntimeException( rtl::OUString(  "Failed to get IsVisible property"), uno::Reference< uno::XInterface >() );
    3135                 :            :     }
    3136         [ #  # ]:          0 :     catch( const uno::Exception& e )
    3137                 :            :     {
    3138         [ #  # ]:          0 :         throw uno::RuntimeException( e.Message, uno::Reference< uno::XInterface >() );
    3139                 :            :     }
    3140         [ #  # ]:          0 :     return uno::makeAny( !bIsVisible );
    3141                 :            : }
    3142                 :            : 
    3143                 :            : void SAL_CALL
    3144                 :          0 : ScVbaRange::setHidden( const uno::Any& _hidden ) throw (uno::RuntimeException)
    3145                 :            : {
    3146         [ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
    3147                 :            :     {
    3148                 :          0 :         sal_Int32 nItems = m_Areas->getCount();
    3149         [ #  # ]:          0 :         for ( sal_Int32 index=1; index <= nItems; ++index )
    3150                 :            :         {
    3151 [ #  # ][ #  # ]:          0 :             uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    3152 [ #  # ][ #  # ]:          0 :             xRange->setHidden( _hidden );
    3153                 :          0 :         }
    3154                 :          0 :         return;
    3155                 :            :     }
    3156                 :            : 
    3157                 :          0 :     bool bHidden = extractBoolFromAny( _hidden );
    3158                 :            :     try
    3159                 :            :     {
    3160         [ #  # ]:          0 :         uno::Reference< beans::XPropertySet > xProps = getRowOrColumnProps( mxRange, mbIsRows );
    3161 [ #  # ][ #  # ]:          0 :         xProps->setPropertyValue( ISVISIBLE, uno::Any( !bHidden ) );
                 [ #  # ]
    3162                 :            :     }
    3163         [ #  # ]:          0 :     catch( const uno::Exception& e )
    3164                 :            :     {
    3165         [ #  # ]:          0 :         throw uno::RuntimeException( e.Message, uno::Reference< uno::XInterface >() );
    3166                 :            :     }
    3167                 :            : }
    3168                 :            : 
    3169                 :            : ::sal_Bool SAL_CALL
    3170                 :          0 : ScVbaRange::Replace( const ::rtl::OUString& What, const ::rtl::OUString& Replacement, const uno::Any& LookAt, const uno::Any& SearchOrder, const uno::Any& MatchCase, const uno::Any& MatchByte, const uno::Any& SearchFormat, const uno::Any& ReplaceFormat  ) throw (uno::RuntimeException)
    3171                 :            : {
    3172 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    3173                 :            :     {
    3174 [ #  # ][ #  # ]:          0 :         for ( sal_Int32 index = 1; index <= m_Areas->getCount(); ++index )
                 [ #  # ]
    3175                 :            :         {
    3176 [ #  # ][ #  # ]:          0 :             uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    3177 [ #  # ][ #  # ]:          0 :             xRange->Replace( What, Replacement,  LookAt, SearchOrder, MatchCase, MatchByte, SearchFormat, ReplaceFormat );
    3178                 :          0 :         }
    3179                 :          0 :         return sal_True; // seems to return true always ( or at least I haven't found the trick of
    3180                 :            :     }
    3181                 :            : 
    3182                 :            :     // sanity check required params
    3183         [ #  # ]:          0 :     if ( What.isEmpty()  )
    3184         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString( "Range::Replace, missing params" ) , uno::Reference< uno::XInterface >() );
    3185         [ #  # ]:          0 :     rtl::OUString sWhat = VBAToRegexp( What);
    3186                 :            :     // #TODO #FIXME SearchFormat & ReplacesFormat are not processed
    3187                 :            :     // What do we do about MatchByte.. we don't seem to support that
    3188         [ #  # ]:          0 :     const SvxSearchItem& globalSearchOptions = ScGlobal::GetSearchItem();
    3189         [ #  # ]:          0 :     SvxSearchItem newOptions( globalSearchOptions );
    3190                 :            : 
    3191         [ #  # ]:          0 :     sal_Int16 nLook =  globalSearchOptions.GetWordOnly() ?  excel::XlLookAt::xlPart : excel::XlLookAt::xlWhole;
    3192         [ #  # ]:          0 :     sal_Int16 nSearchOrder = globalSearchOptions.GetRowDirection() ? excel::XlSearchOrder::xlByRows : excel::XlSearchOrder::xlByColumns;
    3193                 :            : 
    3194                 :          0 :     sal_Bool bMatchCase = false;
    3195         [ #  # ]:          0 :     uno::Reference< util::XReplaceable > xReplace( mxRange, uno::UNO_QUERY );
    3196         [ #  # ]:          0 :     if ( xReplace.is() )
    3197                 :            :     {
    3198                 :            :         uno::Reference< util::XReplaceDescriptor > xDescriptor =
    3199 [ #  # ][ #  # ]:          0 :             xReplace->createReplaceDescriptor();
    3200                 :            : 
    3201 [ #  # ][ #  # ]:          0 :         xDescriptor->setSearchString( sWhat);
    3202 [ #  # ][ #  # ]:          0 :         xDescriptor->setPropertyValue( rtl::OUString(  SC_UNO_SRCHREGEXP  ), uno::makeAny( sal_True ) );
                 [ #  # ]
    3203 [ #  # ][ #  # ]:          0 :         xDescriptor->setReplaceString( Replacement);
    3204         [ #  # ]:          0 :         if ( LookAt.hasValue() )
    3205                 :            :         {
    3206                 :            :             // sets SearchWords ( true is Cell match )
    3207         [ #  # ]:          0 :             nLook =  ::comphelper::getINT16( LookAt );
    3208                 :          0 :             sal_Bool bSearchWords = false;
    3209         [ #  # ]:          0 :             if ( nLook == excel::XlLookAt::xlPart )
    3210                 :          0 :                 bSearchWords = false;
    3211         [ #  # ]:          0 :             else if ( nLook == excel::XlLookAt::xlWhole )
    3212                 :          0 :                 bSearchWords = sal_True;
    3213                 :            :             else
    3214         [ #  # ]:          0 :                 throw uno::RuntimeException( rtl::OUString( "Range::Replace, illegal value for LookAt" ) , uno::Reference< uno::XInterface >() );
    3215                 :            :             // set global search props ( affects the find dialog
    3216                 :            :             // and of course the defaults for this method
    3217         [ #  # ]:          0 :             newOptions.SetWordOnly( bSearchWords );
    3218 [ #  # ][ #  # ]:          0 :             xDescriptor->setPropertyValue( rtl::OUString(  SC_UNO_SRCHWORDS  ), uno::makeAny( bSearchWords ) );
                 [ #  # ]
    3219                 :            :         }
    3220                 :            :         // sets SearchByRow ( true for Rows )
    3221         [ #  # ]:          0 :         if ( SearchOrder.hasValue() )
    3222                 :            :         {
    3223         [ #  # ]:          0 :             nSearchOrder =  ::comphelper::getINT16( SearchOrder );
    3224                 :          0 :             sal_Bool bSearchByRow = false;
    3225         [ #  # ]:          0 :             if ( nSearchOrder == excel::XlSearchOrder::xlByColumns )
    3226                 :          0 :                 bSearchByRow = false;
    3227         [ #  # ]:          0 :             else if ( nSearchOrder == excel::XlSearchOrder::xlByRows )
    3228                 :          0 :                 bSearchByRow = sal_True;
    3229                 :            :             else
    3230         [ #  # ]:          0 :                 throw uno::RuntimeException( rtl::OUString( "Range::Replace, illegal value for SearchOrder" ) , uno::Reference< uno::XInterface >() );
    3231                 :            : 
    3232                 :          0 :             newOptions.SetRowDirection( bSearchByRow );
    3233 [ #  # ][ #  # ]:          0 :             xDescriptor->setPropertyValue( rtl::OUString(  SC_UNO_SRCHBYROW  ), uno::makeAny( bSearchByRow ) );
                 [ #  # ]
    3234                 :            :         }
    3235         [ #  # ]:          0 :         if ( MatchCase.hasValue() )
    3236                 :            :         {
    3237                 :            :             // SearchCaseSensitive
    3238                 :          0 :             MatchCase >>= bMatchCase;
    3239 [ #  # ][ #  # ]:          0 :             xDescriptor->setPropertyValue( rtl::OUString(  SC_UNO_SRCHCASE  ), uno::makeAny( bMatchCase ) );
                 [ #  # ]
    3240                 :            :         }
    3241                 :            : 
    3242         [ #  # ]:          0 :         ScGlobal::SetSearchItem( newOptions );
    3243                 :            :         // ignore MatchByte for the moment, its not supported in
    3244                 :            :         // OOo.org afaik
    3245                 :            : 
    3246         [ #  # ]:          0 :         uno::Reference< util::XSearchDescriptor > xSearch( xDescriptor, uno::UNO_QUERY );
    3247                 :            :         // Find all cells that being replaced, used to fire the range changed event.
    3248 [ #  # ][ #  # ]:          0 :         uno::Reference< container::XIndexAccess > xIndexAccess = xReplace->findAll( xSearch );
    3249 [ #  # ][ #  # ]:          0 :         xReplace->replaceAll( xSearch );
    3250                 :            : 
    3251 [ #  # ][ #  # ]:          0 :         if ( xIndexAccess.is() && xIndexAccess->getCount() > 0 )
         [ #  # ][ #  # ]
                 [ #  # ]
    3252                 :            :         {
    3253                 :            :             // Fires the range change event.
    3254         [ #  # ]:          0 :             ScCellRangesBase* pScCellRangesBase = ScCellRangesBase::getImplementation( xIndexAccess );
    3255 [ #  # ][ #  # ]:          0 :             lcl_NotifyRangeChanges( getScDocShell()->GetModel(), pScCellRangesBase ); // the original convert method will fail in SUSE
                 [ #  # ]
    3256                 :          0 :         }
    3257                 :            :     }
    3258         [ #  # ]:          0 :     return sal_True; // always
    3259                 :            : }
    3260                 :            : 
    3261                 :            : uno::Reference< excel::XRange > SAL_CALL
    3262                 :          0 : ScVbaRange::Find( const uno::Any& What, const uno::Any& After, const uno::Any& LookIn, const uno::Any& LookAt, const uno::Any& SearchOrder, const uno::Any& SearchDirection, const uno::Any& MatchCase, const uno::Any& /*MatchByte*/, const uno::Any& /*SearchFormat*/ ) throw (uno::RuntimeException)
    3263                 :            : {
    3264                 :            :     // return a Range object that represents the first cell where that information is found.
    3265                 :          0 :     rtl::OUString sWhat;
    3266                 :          0 :     sal_Int32 nWhat = 0;
    3267                 :          0 :     double fWhat = 0.0;
    3268                 :            : 
    3269                 :            :     // string.
    3270         [ #  # ]:          0 :     if( What >>= sWhat )
    3271                 :            :     {
    3272         [ #  # ]:          0 :         if( sWhat.isEmpty() )
    3273         [ #  # ]:          0 :             throw uno::RuntimeException( rtl::OUString( "Range::Find, missing params" ) , uno::Reference< uno::XInterface >() );
    3274                 :            :     }
    3275         [ #  # ]:          0 :     else if( What >>= nWhat )
    3276                 :            :     {
    3277                 :          0 :         sWhat = rtl::OUString::valueOf( nWhat );
    3278                 :            :     }
    3279         [ #  # ]:          0 :     else if( What >>= fWhat )
    3280                 :            :     {
    3281                 :          0 :         sWhat = rtl::OUString::valueOf( fWhat );
    3282                 :            :     }
    3283                 :            :     else
    3284         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString( "Range::Find, missing params" ) , uno::Reference< uno::XInterface >() );
    3285                 :            : 
    3286         [ #  # ]:          0 :     rtl::OUString sSearch = VBAToRegexp( sWhat );
    3287                 :            : 
    3288         [ #  # ]:          0 :     const SvxSearchItem& globalSearchOptions = ScGlobal::GetSearchItem();
    3289         [ #  # ]:          0 :     SvxSearchItem newOptions( globalSearchOptions );
    3290                 :            : 
    3291         [ #  # ]:          0 :     sal_Int16 nLookAt =  globalSearchOptions.GetWordOnly() ?  excel::XlLookAt::xlPart : excel::XlLookAt::xlWhole;
    3292         [ #  # ]:          0 :     sal_Int16 nSearchOrder = globalSearchOptions.GetRowDirection() ? excel::XlSearchOrder::xlByRows : excel::XlSearchOrder::xlByColumns;
    3293                 :            : 
    3294         [ #  # ]:          0 :     uno::Reference< util::XSearchable > xSearch( mxRange, uno::UNO_QUERY );
    3295         [ #  # ]:          0 :     if( xSearch.is() )
    3296                 :            :     {
    3297 [ #  # ][ #  # ]:          0 :         uno::Reference< util::XSearchDescriptor > xDescriptor = xSearch->createSearchDescriptor();
    3298 [ #  # ][ #  # ]:          0 :         xDescriptor->setSearchString( sSearch );
    3299 [ #  # ][ #  # ]:          0 :         xDescriptor->setPropertyValue( rtl::OUString(  SC_UNO_SRCHREGEXP  ), uno::Any( true ) );
                 [ #  # ]
    3300                 :            : 
    3301                 :          0 :         uno::Reference< excel::XRange > xAfterRange;
    3302                 :          0 :         uno::Reference< table::XCellRange > xStartCell;
    3303 [ #  # ][ #  # ]:          0 :         if( After >>= xAfterRange )
    3304                 :            :         {
    3305                 :            :             // After must be a single cell in the range
    3306 [ #  # ][ #  # ]:          0 :             if( xAfterRange->getCount() > 1 )
                 [ #  # ]
    3307         [ #  # ]:          0 :                 throw uno::RuntimeException( rtl::OUString( "After must be a single cell." ) , uno::Reference< uno::XInterface >() );
    3308 [ #  # ][ #  # ]:          0 :             uno::Reference< excel::XRange > xCell( Cells( uno::makeAny( xAfterRange->getRow() ), uno::makeAny( xAfterRange->getColumn() ) ), uno::UNO_QUERY );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    3309         [ #  # ]:          0 :             if( !xCell.is() )
    3310         [ #  # ]:          0 :                 throw uno::RuntimeException( rtl::OUString( "After must be in range." ) , uno::Reference< uno::XInterface >() );
    3311 [ #  # ][ #  # ]:          0 :             xStartCell.set( xAfterRange->getCellRange(), uno::UNO_QUERY_THROW );
                 [ #  # ]
    3312                 :            :         }
    3313                 :            : 
    3314                 :            :         // LookIn
    3315         [ #  # ]:          0 :         if( LookIn.hasValue() )
    3316                 :            :         {
    3317                 :          0 :             sal_Int32 nLookIn = 0;
    3318         [ #  # ]:          0 :             if( LookIn >>= nLookIn )
    3319                 :            :             {
    3320                 :          0 :                 sal_Int16 nSearchType = 0;
    3321   [ #  #  #  # ]:          0 :                 switch( nLookIn )
    3322                 :            :                 {
    3323                 :            :                     case excel::XlFindLookIn::xlComments :
    3324                 :          0 :                         nSearchType = SVX_SEARCHIN_NOTE; // Notes
    3325                 :          0 :                     break;
    3326                 :            :                     case excel::XlFindLookIn::xlFormulas :
    3327                 :          0 :                         nSearchType = SVX_SEARCHIN_FORMULA;
    3328                 :          0 :                     break;
    3329                 :            :                     case excel::XlFindLookIn::xlValues :
    3330                 :          0 :                         nSearchType = SVX_SEARCHIN_VALUE;
    3331                 :          0 :                     break;
    3332                 :            :                     default:
    3333         [ #  # ]:          0 :                         throw uno::RuntimeException( rtl::OUString( "Range::Replace, illegal value for LookIn." ) , uno::Reference< uno::XInterface >() );
    3334                 :            :                 }
    3335                 :          0 :                 newOptions.SetCellType( nSearchType );
    3336 [ #  # ][ #  # ]:          0 :                 xDescriptor->setPropertyValue( rtl::OUString( "SearchType" ), uno::makeAny( nSearchType ) );
                 [ #  # ]
    3337                 :            :             }
    3338                 :            :         }
    3339                 :            : 
    3340                 :            :         // LookAt
    3341         [ #  # ]:          0 :         if ( LookAt.hasValue() )
    3342                 :            :         {
    3343         [ #  # ]:          0 :             nLookAt =  ::comphelper::getINT16( LookAt );
    3344                 :          0 :             sal_Bool bSearchWords = false;
    3345         [ #  # ]:          0 :             if ( nLookAt == excel::XlLookAt::xlPart )
    3346                 :          0 :                 bSearchWords = false;
    3347         [ #  # ]:          0 :             else if ( nLookAt == excel::XlLookAt::xlWhole )
    3348                 :          0 :                 bSearchWords = sal_True;
    3349                 :            :             else
    3350         [ #  # ]:          0 :                 throw uno::RuntimeException( rtl::OUString( "Range::Replace, illegal value for LookAt" ) , uno::Reference< uno::XInterface >() );
    3351         [ #  # ]:          0 :             newOptions.SetWordOnly( bSearchWords );
    3352 [ #  # ][ #  # ]:          0 :             xDescriptor->setPropertyValue( rtl::OUString(  SC_UNO_SRCHWORDS  ), uno::makeAny( bSearchWords ) );
                 [ #  # ]
    3353                 :            :         }
    3354                 :            : 
    3355                 :            :         // SearchOrder
    3356         [ #  # ]:          0 :         if ( SearchOrder.hasValue() )
    3357                 :            :         {
    3358         [ #  # ]:          0 :             nSearchOrder =  ::comphelper::getINT16( SearchOrder );
    3359                 :          0 :             sal_Bool bSearchByRow = false;
    3360         [ #  # ]:          0 :             if ( nSearchOrder == excel::XlSearchOrder::xlByColumns )
    3361                 :          0 :                 bSearchByRow = false;
    3362         [ #  # ]:          0 :             else if ( nSearchOrder == excel::XlSearchOrder::xlByRows )
    3363                 :          0 :                 bSearchByRow = sal_True;
    3364                 :            :             else
    3365         [ #  # ]:          0 :                 throw uno::RuntimeException( rtl::OUString( "Range::Replace, illegal value for SearchOrder" ) , uno::Reference< uno::XInterface >() );
    3366                 :            : 
    3367                 :          0 :             newOptions.SetRowDirection( bSearchByRow );
    3368 [ #  # ][ #  # ]:          0 :             xDescriptor->setPropertyValue( rtl::OUString(  SC_UNO_SRCHBYROW  ), uno::makeAny( bSearchByRow ) );
                 [ #  # ]
    3369                 :            :         }
    3370                 :            : 
    3371                 :            :         // SearchDirection
    3372         [ #  # ]:          0 :         if ( SearchDirection.hasValue() )
    3373                 :            :         {
    3374                 :          0 :             sal_Int32 nSearchDirection = 0;
    3375         [ #  # ]:          0 :             if( SearchDirection >>= nSearchDirection )
    3376                 :            :             {
    3377                 :          0 :                 sal_Bool bSearchBackwards = false;
    3378         [ #  # ]:          0 :                 if ( nSearchDirection == excel::XlSearchDirection::xlNext )
    3379                 :          0 :                     bSearchBackwards = false;
    3380         [ #  # ]:          0 :                 else if( nSearchDirection == excel::XlSearchDirection::xlPrevious )
    3381                 :          0 :                     bSearchBackwards = sal_True;
    3382                 :            :                 else
    3383         [ #  # ]:          0 :                     throw uno::RuntimeException( rtl::OUString( "Range::Replace, illegal value for SearchDirection" ) , uno::Reference< uno::XInterface >() );
    3384                 :          0 :                 newOptions.SetBackward( bSearchBackwards );
    3385 [ #  # ][ #  # ]:          0 :                 xDescriptor->setPropertyValue( rtl::OUString( "SearchBackwards" ), uno::makeAny( bSearchBackwards ) );
                 [ #  # ]
    3386                 :            :             }
    3387                 :            :         }
    3388                 :            : 
    3389                 :            :         // MatchCase
    3390                 :          0 :         sal_Bool bMatchCase = false;
    3391         [ #  # ]:          0 :         if ( MatchCase.hasValue() )
    3392                 :            :         {
    3393                 :            :             // SearchCaseSensitive
    3394         [ #  # ]:          0 :             if( !( MatchCase >>= bMatchCase ) )
    3395         [ #  # ]:          0 :                 throw uno::RuntimeException( rtl::OUString( "Range::Replace, illegal value for MatchCase" ) , uno::Reference< uno::XInterface >() );
    3396                 :            :         }
    3397 [ #  # ][ #  # ]:          0 :         xDescriptor->setPropertyValue( rtl::OUString(  SC_UNO_SRCHCASE  ), uno::makeAny( bMatchCase ) );
                 [ #  # ]
    3398                 :            : 
    3399                 :            :         // MatchByte
    3400                 :            :         // SearchFormat
    3401                 :            :         // ignore
    3402                 :            : 
    3403         [ #  # ]:          0 :         ScGlobal::SetSearchItem( newOptions );
    3404                 :            : 
    3405 [ #  # ][ #  # ]:          0 :         uno::Reference< uno::XInterface > xInterface = xStartCell.is() ? xSearch->findNext( xStartCell, xDescriptor) : xSearch->findFirst( xDescriptor );
         [ #  # ][ #  # ]
                 [ #  # ]
    3406         [ #  # ]:          0 :         uno::Reference< table::XCellRange > xCellRange( xInterface, uno::UNO_QUERY );
    3407                 :            :         // if we are searching from a starting cell and failed to find a match
    3408                 :            :         // then try from the begining
    3409 [ #  # ][ #  # ]:          0 :         if ( !xCellRange.is() && xStartCell.is() )
                 [ #  # ]
    3410                 :            :         {
    3411 [ #  # ][ #  # ]:          0 :             xInterface = xSearch->findFirst( xDescriptor );
                 [ #  # ]
    3412         [ #  # ]:          0 :             xCellRange.set( xInterface, uno::UNO_QUERY );
    3413                 :            :         }
    3414         [ #  # ]:          0 :         if ( xCellRange.is() )
    3415                 :            :         {
    3416 [ #  # ][ #  # ]:          0 :             uno::Reference< excel::XRange > xResultRange = new ScVbaRange( mxParent, mxContext, xCellRange );
         [ #  # ][ #  # ]
    3417         [ #  # ]:          0 :             if( xResultRange.is() )
    3418                 :            :             {
    3419 [ #  # ][ #  # ]:          0 :                 xResultRange->Select();
    3420                 :          0 :                 return xResultRange;
    3421         [ #  # ]:          0 :             }
    3422 [ #  # ][ #  # ]:          0 :         }
         [ #  # ][ #  # ]
                 [ #  # ]
    3423                 :            : 
    3424                 :            :     }
    3425                 :            : 
    3426         [ #  # ]:          0 :     return uno::Reference< excel::XRange >();
    3427                 :            : }
    3428                 :            : 
    3429                 :          0 : uno::Reference< table::XCellRange > processKey( const uno::Any& Key, uno::Reference<  uno::XComponentContext >& xContext, ScDocShell* pDocSh )
    3430                 :            : {
    3431                 :          0 :     uno::Reference< excel::XRange > xKeyRange;
    3432 [ #  # ][ #  # ]:          0 :     if ( Key.getValueType() == excel::XRange::static_type() )
    3433                 :            :     {
    3434         [ #  # ]:          0 :         xKeyRange.set( Key, uno::UNO_QUERY_THROW );
    3435                 :            :     }
    3436 [ #  # ][ #  # ]:          0 :     else if ( Key.getValueType() == ::getCppuType( static_cast< const rtl::OUString* >(0) )  )
    3437                 :            : 
    3438                 :            :     {
    3439         [ #  # ]:          0 :         rtl::OUString sRangeName = ::comphelper::getString( Key );
    3440                 :          0 :         table::CellRangeAddress  aRefAddr;
    3441         [ #  # ]:          0 :         if ( !pDocSh )
    3442         [ #  # ]:          0 :             throw uno::RuntimeException( rtl::OUString("Range::Sort no docshell to calculate key param"), uno::Reference< uno::XInterface >() );
    3443 [ #  # ][ #  # ]:          0 :         xKeyRange = getRangeForName( xContext, sRangeName, pDocSh, aRefAddr );
                 [ #  # ]
    3444                 :            :     }
    3445                 :            :     else
    3446         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString("Range::Sort illegal type value for key param"), uno::Reference< uno::XInterface >() );
    3447                 :          0 :     uno::Reference< table::XCellRange > xKey;
    3448 [ #  # ][ #  # ]:          0 :     xKey.set( xKeyRange->getCellRange(), uno::UNO_QUERY_THROW );
                 [ #  # ]
    3449                 :          0 :     return xKey;
    3450                 :            : }
    3451                 :            : 
    3452                 :            : // helper method for Sort
    3453                 :          0 : sal_Int32 findSortPropertyIndex( const uno::Sequence< beans::PropertyValue >& props,
    3454                 :            : const rtl::OUString& sPropName ) throw( uno::RuntimeException )
    3455                 :            : {
    3456                 :          0 :     const beans::PropertyValue* pProp = props.getConstArray();
    3457                 :          0 :     sal_Int32 nItems = props.getLength();
    3458                 :            : 
    3459                 :          0 :      sal_Int32 count=0;
    3460         [ #  # ]:          0 :     for ( ; count < nItems; ++count, ++pProp )
    3461         [ #  # ]:          0 :         if ( pProp->Name.equals( sPropName ) )
    3462                 :          0 :             return count;
    3463         [ #  # ]:          0 :     if ( count == nItems )
    3464         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString("Range::Sort unknown sort property"), uno::Reference< uno::XInterface >() );
    3465                 :          0 :     return -1; //should never reach here ( satisfy compiler )
    3466                 :            : }
    3467                 :            : 
    3468                 :            : // helper method for Sort
    3469                 :          0 : void updateTableSortField( const uno::Reference< table::XCellRange >& xParentRange,
    3470                 :            :     const uno::Reference< table::XCellRange >& xColRowKey, sal_Int16 nOrder,
    3471                 :            :     table::TableSortField& aTableField, sal_Bool bIsSortColumn, sal_Bool bMatchCase ) throw ( uno::RuntimeException )
    3472                 :            : {
    3473         [ #  # ]:          0 :         RangeHelper parentRange( xParentRange );
    3474         [ #  # ]:          0 :         RangeHelper colRowRange( xColRowKey );
    3475                 :            : 
    3476 [ #  # ][ #  # ]:          0 :         table::CellRangeAddress parentRangeAddress = parentRange.getCellRangeAddressable()->getRangeAddress();
                 [ #  # ]
    3477                 :            : 
    3478 [ #  # ][ #  # ]:          0 :         table::CellRangeAddress colRowKeyAddress = colRowRange.getCellRangeAddressable()->getRangeAddress();
                 [ #  # ]
    3479                 :            : 
    3480                 :            :         // make sure that upper left poing of key range is within the
    3481                 :            :         // parent range
    3482 [ #  # ][ #  # ]:          0 :         if (  ( !bIsSortColumn && colRowKeyAddress.StartColumn >= parentRangeAddress.StartColumn &&
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    3483                 :            :             colRowKeyAddress.StartColumn <= parentRangeAddress.EndColumn ) || ( bIsSortColumn &&
    3484                 :            :             colRowKeyAddress.StartRow >= parentRangeAddress.StartRow &&
    3485                 :            :             colRowKeyAddress.StartRow <= parentRangeAddress.EndRow  ) )
    3486                 :            :         {
    3487                 :            :             //determine col/row index
    3488         [ #  # ]:          0 :             if ( bIsSortColumn )
    3489                 :          0 :                 aTableField.Field = colRowKeyAddress.StartRow - parentRangeAddress.StartRow;
    3490                 :            :             else
    3491                 :          0 :                 aTableField.Field = colRowKeyAddress.StartColumn - parentRangeAddress.StartColumn;
    3492                 :          0 :             aTableField.IsCaseSensitive = bMatchCase;
    3493                 :            : 
    3494         [ #  # ]:          0 :             if ( nOrder ==  excel::XlSortOrder::xlAscending )
    3495                 :          0 :                 aTableField.IsAscending = sal_True;
    3496                 :            :             else
    3497                 :          0 :                 aTableField.IsAscending = false;
    3498                 :            :         }
    3499                 :            :         else
    3500 [ #  # ][ #  # ]:          0 :             throw uno::RuntimeException( rtl::OUString(  "Illegal Key param"  ), uno::Reference< uno::XInterface >() );
                 [ #  # ]
    3501                 :            : 
    3502                 :            : 
    3503                 :          0 : }
    3504                 :            : 
    3505                 :            : void SAL_CALL
    3506                 :          0 : ScVbaRange::Sort( const uno::Any& Key1, const uno::Any& Order1, const uno::Any& Key2, const uno::Any& /*Type*/, const uno::Any& Order2, const uno::Any& Key3, const uno::Any& Order3, const uno::Any& Header, const uno::Any& OrderCustom, const uno::Any& MatchCase, const uno::Any& Orientation, const uno::Any& SortMethod,  const uno::Any& DataOption1, const uno::Any& DataOption2, const uno::Any& DataOption3  ) throw (uno::RuntimeException)
    3507                 :            : {
    3508                 :            :     // #TODO# #FIXME# can we do something with Type
    3509 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    3510         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString( "That command cannot be used on multiple selections"  ), uno::Reference< uno::XInterface >() );
    3511                 :            : 
    3512                 :          0 :     sal_Int16 nDataOption1 = excel::XlSortDataOption::xlSortNormal;
    3513                 :          0 :     sal_Int16 nDataOption2 = excel::XlSortDataOption::xlSortNormal;
    3514                 :          0 :     sal_Int16 nDataOption3 = excel::XlSortDataOption::xlSortNormal;
    3515                 :            : 
    3516         [ #  # ]:          0 :     ScDocument* pDoc = getScDocument();
    3517         [ #  # ]:          0 :     if ( !pDoc )
    3518         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString(  "Failed to access document from shell"  ), uno::Reference< uno::XInterface >() );
    3519                 :            : 
    3520         [ #  # ]:          0 :     RangeHelper thisRange( mxRange );
    3521 [ #  # ][ #  # ]:          0 :     table::CellRangeAddress thisRangeAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
                 [ #  # ]
    3522         [ #  # ]:          0 :     ScSortParam aSortParam;
    3523                 :          0 :     SCTAB nTab = thisRangeAddress.Sheet;
    3524         [ #  # ]:          0 :     pDoc->GetSortParam( aSortParam, nTab );
    3525                 :            : 
    3526         [ #  # ]:          0 :     if ( DataOption1.hasValue() )
    3527                 :          0 :         DataOption1 >>= nDataOption1;
    3528         [ #  # ]:          0 :     if ( DataOption2.hasValue() )
    3529                 :          0 :         DataOption2 >>= nDataOption2;
    3530         [ #  # ]:          0 :     if ( DataOption3.hasValue() )
    3531                 :          0 :         DataOption3 >>= nDataOption3;
    3532                 :            : 
    3533                 :            :     // 1) #TODO #FIXME need to process DataOption[1..3] not used currently
    3534                 :            :     // 2) #TODO #FIXME need to refactor this ( below ) into a IsSingleCell() method
    3535         [ #  # ]:          0 :     uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY_THROW );
    3536                 :            : 
    3537                 :            :     // set up defaults
    3538                 :            : 
    3539         [ #  # ]:          0 :     sal_Int16 nOrder1 = aSortParam.maKeyState[1].bAscending ? excel::XlSortOrder::xlAscending : excel::XlSortOrder::xlDescending;
    3540         [ #  # ]:          0 :     sal_Int16 nOrder2 = aSortParam.maKeyState[2].bAscending ? excel::XlSortOrder::xlAscending : excel::XlSortOrder::xlDescending;
    3541         [ #  # ]:          0 :     sal_Int16 nOrder3 = aSortParam.maKeyState[3].bAscending ? excel::XlSortOrder::xlAscending : excel::XlSortOrder::xlDescending;
    3542                 :            : 
    3543                 :          0 :     sal_Int16 nCustom = aSortParam.nUserIndex;
    3544                 :          0 :     sal_Int16 nSortMethod = excel::XlSortMethod::xlPinYin;
    3545                 :          0 :     sal_Bool bMatchCase = aSortParam.bCaseSens;
    3546                 :            : 
    3547                 :            :     // seems to work opposite to expected, see below
    3548         [ #  # ]:          0 :     sal_Int16 nOrientation = aSortParam.bByRow ?  excel::XlSortOrientation::xlSortColumns :  excel::XlSortOrientation::xlSortRows;
    3549                 :            : 
    3550         [ #  # ]:          0 :     if ( Orientation.hasValue() )
    3551                 :            :     {
    3552                 :            :         // Documentation says xlSortRows is default but that doesn't appear to be
    3553                 :            :         // the case. Also it appears that xlSortColumns is the default which
    3554                 :            :         // strangely enought sorts by Row
    3555         [ #  # ]:          0 :         nOrientation = ::comphelper::getINT16( Orientation );
    3556                 :            :         // persist new option to be next calls default
    3557         [ #  # ]:          0 :         if ( nOrientation == excel::XlSortOrientation::xlSortRows )
    3558                 :          0 :             aSortParam.bByRow = false;
    3559                 :            :         else
    3560                 :          0 :             aSortParam.bByRow = sal_True;
    3561                 :            : 
    3562                 :            :     }
    3563                 :            : 
    3564                 :          0 :     sal_Bool bIsSortColumns=false; // sort by row
    3565                 :            : 
    3566         [ #  # ]:          0 :     if ( nOrientation == excel::XlSortOrientation::xlSortRows )
    3567                 :          0 :         bIsSortColumns = sal_True;
    3568                 :          0 :     sal_Int16 nHeader = 0;
    3569                 :            : #ifdef VBA_OOBUILD_HACK
    3570                 :          0 :     nHeader = aSortParam.nCompatHeader;
    3571                 :            : #endif
    3572                 :          0 :     sal_Bool bContainsHeader = false;
    3573                 :            : 
    3574         [ #  # ]:          0 :     if ( Header.hasValue() )
    3575                 :            :     {
    3576         [ #  # ]:          0 :         nHeader = ::comphelper::getINT16( Header );
    3577                 :            : #ifdef VBA_OOBUILD_HACK
    3578                 :          0 :         aSortParam.nCompatHeader = nHeader;
    3579                 :            : #endif
    3580                 :            :     }
    3581                 :            : 
    3582         [ #  # ]:          0 :     if ( nHeader == excel::XlYesNoGuess::xlGuess )
    3583                 :            :     {
    3584         [ #  # ]:          0 :         bool bHasColHeader = pDoc->HasColHeader(  static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), static_cast< SCCOL >( thisRangeAddress.EndColumn ), static_cast< SCROW >( thisRangeAddress.EndRow ), static_cast< SCTAB >( thisRangeAddress.Sheet ));
    3585         [ #  # ]:          0 :         bool bHasRowHeader = pDoc->HasRowHeader(  static_cast< SCCOL >( thisRangeAddress.StartColumn ), static_cast< SCROW >( thisRangeAddress.StartRow ), static_cast< SCCOL >( thisRangeAddress.EndColumn ), static_cast< SCROW >( thisRangeAddress.EndRow ), static_cast< SCTAB >( thisRangeAddress.Sheet ) );
    3586 [ #  # ][ #  # ]:          0 :         if ( bHasColHeader || bHasRowHeader )
    3587                 :          0 :             nHeader =  excel::XlYesNoGuess::xlYes;
    3588                 :            :         else
    3589                 :          0 :             nHeader =  excel::XlYesNoGuess::xlNo;
    3590                 :            : #ifdef VBA_OOBUILD_HACK
    3591                 :          0 :         aSortParam.nCompatHeader = nHeader;
    3592                 :            : #endif
    3593                 :            :     }
    3594                 :            : 
    3595         [ #  # ]:          0 :     if ( nHeader == excel::XlYesNoGuess::xlYes )
    3596                 :          0 :         bContainsHeader = sal_True;
    3597                 :            : 
    3598         [ #  # ]:          0 :     if ( SortMethod.hasValue() )
    3599                 :            :     {
    3600         [ #  # ]:          0 :         nSortMethod = ::comphelper::getINT16( SortMethod );
    3601                 :            :     }
    3602                 :            : 
    3603         [ #  # ]:          0 :     if ( OrderCustom.hasValue() )
    3604                 :            :     {
    3605                 :          0 :         OrderCustom >>= nCustom;
    3606                 :          0 :         --nCustom; // 0-based in OOo
    3607                 :          0 :         aSortParam.nUserIndex = nCustom;
    3608                 :            :     }
    3609                 :            : 
    3610         [ #  # ]:          0 :     if ( MatchCase.hasValue() )
    3611                 :            :     {
    3612                 :          0 :         MatchCase >>= bMatchCase;
    3613                 :          0 :         aSortParam.bCaseSens = bMatchCase;
    3614                 :            :     }
    3615                 :            : 
    3616         [ #  # ]:          0 :     if ( Order1.hasValue() )
    3617                 :            :     {
    3618         [ #  # ]:          0 :         nOrder1 = ::comphelper::getINT16(Order1);
    3619         [ #  # ]:          0 :         if (  nOrder1 == excel::XlSortOrder::xlAscending )
    3620                 :          0 :             aSortParam.maKeyState[0].bAscending  = true;
    3621                 :            :         else
    3622                 :          0 :             aSortParam.maKeyState[0].bAscending  = false;
    3623                 :            : 
    3624                 :            :     }
    3625         [ #  # ]:          0 :     if ( Order2.hasValue() )
    3626                 :            :     {
    3627         [ #  # ]:          0 :         nOrder2 = ::comphelper::getINT16(Order2);
    3628         [ #  # ]:          0 :         if ( nOrder2 == excel::XlSortOrder::xlAscending )
    3629                 :          0 :             aSortParam.maKeyState[1].bAscending  = true;
    3630                 :            :         else
    3631                 :          0 :             aSortParam.maKeyState[1].bAscending  = false;
    3632                 :            :     }
    3633         [ #  # ]:          0 :     if ( Order3.hasValue() )
    3634                 :            :     {
    3635         [ #  # ]:          0 :         nOrder3 = ::comphelper::getINT16(Order3);
    3636         [ #  # ]:          0 :         if ( nOrder3 == excel::XlSortOrder::xlAscending )
    3637                 :          0 :             aSortParam.maKeyState[2].bAscending  = true;
    3638                 :            :         else
    3639                 :          0 :             aSortParam.maKeyState[2].bAscending  = false;
    3640                 :            :     }
    3641                 :            : 
    3642                 :          0 :     uno::Reference< table::XCellRange > xKey1;
    3643                 :          0 :     uno::Reference< table::XCellRange > xKey2;
    3644                 :          0 :     uno::Reference< table::XCellRange > xKey3;
    3645         [ #  # ]:          0 :     ScDocShell* pDocShell = getScDocShell();
    3646 [ #  # ][ #  # ]:          0 :     xKey1 = processKey( Key1, mxContext, pDocShell );
    3647         [ #  # ]:          0 :     if ( !xKey1.is() )
    3648         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString("Range::Sort needs a key1 param"), uno::Reference< uno::XInterface >() );
    3649                 :            : 
    3650         [ #  # ]:          0 :     if ( Key2.hasValue() )
    3651 [ #  # ][ #  # ]:          0 :         xKey2 = processKey( Key2, mxContext, pDocShell );
    3652         [ #  # ]:          0 :     if ( Key3.hasValue() )
    3653 [ #  # ][ #  # ]:          0 :         xKey3 = processKey( Key3, mxContext, pDocShell );
    3654                 :            : 
    3655         [ #  # ]:          0 :     uno::Reference< util::XSortable > xSort( mxRange, uno::UNO_QUERY_THROW );
    3656 [ #  # ][ #  # ]:          0 :     uno::Sequence< beans::PropertyValue > sortDescriptor = xSort->createSortDescriptor();
    3657         [ #  # ]:          0 :     sal_Int32 nTableSortFieldIndex = findSortPropertyIndex( sortDescriptor, rtl::OUString( "SortFields" ) );
    3658                 :            : 
    3659         [ #  # ]:          0 :     uno::Sequence< table::TableSortField > sTableFields(1);
    3660                 :          0 :     sal_Int32 nTableIndex = 0;
    3661 [ #  # ][ #  # ]:          0 :     updateTableSortField(  mxRange, xKey1, nOrder1, sTableFields[ nTableIndex++ ], bIsSortColumns, bMatchCase );
    3662                 :            : 
    3663         [ #  # ]:          0 :     if ( xKey2.is() )
    3664                 :            :     {
    3665         [ #  # ]:          0 :         sTableFields.realloc( sTableFields.getLength() + 1 );
    3666 [ #  # ][ #  # ]:          0 :         updateTableSortField(  mxRange, xKey2, nOrder2, sTableFields[ nTableIndex++ ], bIsSortColumns, bMatchCase );
    3667                 :            :     }
    3668         [ #  # ]:          0 :     if ( xKey3.is()  )
    3669                 :            :     {
    3670         [ #  # ]:          0 :         sTableFields.realloc( sTableFields.getLength() + 1 );
    3671 [ #  # ][ #  # ]:          0 :         updateTableSortField(  mxRange, xKey3, nOrder3, sTableFields[ nTableIndex++ ], bIsSortColumns, bMatchCase );
    3672                 :            :     }
    3673 [ #  # ][ #  # ]:          0 :     sortDescriptor[ nTableSortFieldIndex ].Value <<= sTableFields;
    3674                 :            : 
    3675         [ #  # ]:          0 :     sal_Int32 nIndex =  findSortPropertyIndex( sortDescriptor,  rtl::OUString("IsSortColumns") );
    3676 [ #  # ][ #  # ]:          0 :     sortDescriptor[ nIndex ].Value <<= bIsSortColumns;
    3677                 :            : 
    3678         [ #  # ]:          0 :     nIndex =    findSortPropertyIndex( sortDescriptor, CONTS_HEADER );
    3679 [ #  # ][ #  # ]:          0 :     sortDescriptor[ nIndex ].Value <<= bContainsHeader;
    3680                 :            : 
    3681         [ #  # ]:          0 :     pDoc->SetSortParam( aSortParam, nTab );
    3682 [ #  # ][ #  # ]:          0 :     xSort->sort( sortDescriptor );
    3683                 :            : 
    3684                 :            :     // #FIXME #TODO
    3685                 :            :     // The SortMethod param is not processed ( not sure what its all about, need to
    3686 [ #  # ][ #  # ]:          0 :     (void)nSortMethod;
         [ #  # ][ #  # ]
    3687                 :          0 : }
    3688                 :            : 
    3689                 :            : uno::Reference< excel::XRange > SAL_CALL
    3690                 :          0 : ScVbaRange::End( ::sal_Int32 Direction )  throw (uno::RuntimeException)
    3691                 :            : {
    3692 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    3693                 :            :     {
    3694 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( getArea( 0 ), uno::UNO_QUERY_THROW );
    3695 [ #  # ][ #  # ]:          0 :         return xRange->End( Direction );
    3696                 :            :     }
    3697                 :            : 
    3698         [ #  # ]:          0 :     table::CellAddress aAddress = getLeftUpperCellAddress();
    3699                 :          0 :     SCTAB nTab = aAddress.Sheet;
    3700                 :          0 :     SCCOL nCurX = aAddress.Column;
    3701                 :          0 :     SCROW nCurY = aAddress.Row;
    3702                 :          0 :     SCCOL nNewX = nCurX;
    3703                 :          0 :     SCROW nNewY = nCurY;
    3704                 :            : 
    3705         [ #  # ]:          0 :     ScDocShell* pDocShell = getScDocShell();
    3706                 :          0 :     ScDocument* pDoc = pDocShell->GetDocument();
    3707                 :            : 
    3708                 :            :     ScMoveDirection eDirection;
    3709   [ #  #  #  #  :          0 :     switch ( Direction )
                      # ]
    3710                 :            :     {
    3711                 :            :     case excel::XlDirection::xlDown:
    3712                 :          0 :         eDirection = SC_MOVE_DOWN;
    3713                 :          0 :         break;
    3714                 :            :     case excel::XlDirection::xlUp:
    3715                 :          0 :         eDirection = SC_MOVE_UP;
    3716                 :          0 :         break;
    3717                 :            :     case excel::XlDirection::xlToLeft:
    3718                 :          0 :         eDirection = SC_MOVE_LEFT;
    3719                 :          0 :         break;
    3720                 :            :     case excel::XlDirection::xlToRight:
    3721                 :          0 :         eDirection = SC_MOVE_RIGHT;
    3722                 :          0 :         break;
    3723                 :            :     default:
    3724         [ #  # ]:          0 :         throw uno::RuntimeException( ::rtl::OUString(  "Invalid Direction"  ), uno::Reference< uno::XInterface >() );
    3725                 :            :     }
    3726                 :            : 
    3727         [ #  # ]:          0 :     if ( pDoc )
    3728                 :            :     {
    3729         [ #  # ]:          0 :         pDoc->FindAreaPos( nNewX, nNewY, nTab, eDirection );
    3730                 :            :     }
    3731                 :            : 
    3732                 :          0 :     ScRange aNewRange( (SCCOL)nNewX, (SCROW)nNewY, nTab, (SCCOL)nNewX, (SCROW)nNewY, nTab );
    3733 [ #  # ][ #  # ]:          0 :     uno::Reference< table::XCellRange > xCellRange( new ScCellRangeObj( getScDocShell(), aNewRange ) );
         [ #  # ][ #  # ]
    3734 [ #  # ][ #  # ]:          0 :     uno::Reference< excel::XRange > xResultRange = new ScVbaRange( mxParent, mxContext, xCellRange );
         [ #  # ][ #  # ]
    3735                 :          0 :     return xResultRange;
    3736                 :            : }
    3737                 :            : 
    3738                 :            : bool
    3739                 :          2 : ScVbaRange::isSingleCellRange()
    3740                 :            : {
    3741         [ +  - ]:          2 :     uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY);
    3742 [ +  - ][ +  - ]:          2 :     if ( xColumnRowRange.is() && xColumnRowRange->getRows()->getCount() == 1 && xColumnRowRange->getColumns()->getCount() == 1 )
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  -  
             #  #  #  # ]
    3743                 :          2 :         return true;
    3744                 :          2 :     return false;
    3745                 :            : }
    3746                 :            : 
    3747                 :            : uno::Reference< excel::XCharacters > SAL_CALL
    3748                 :          0 : ScVbaRange::characters( const uno::Any& Start, const uno::Any& Length ) throw (uno::RuntimeException)
    3749                 :            : {
    3750 [ #  # ][ #  # ]:          0 :     if ( !isSingleCellRange() )
    3751         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString( "Can't create Characters property for multicell range " ), uno::Reference< uno::XInterface >() );
    3752 [ #  # ][ #  # ]:          0 :     uno::Reference< text::XSimpleText > xSimple(mxRange->getCellByPosition(0,0) , uno::UNO_QUERY_THROW );
                 [ #  # ]
    3753         [ #  # ]:          0 :     ScDocument* pDoc = excel::GetDocumentFromRange(mxRange);
    3754         [ #  # ]:          0 :     if ( !pDoc )
    3755         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString(  "Failed to access document from shell"  ), uno::Reference< uno::XInterface >() );
    3756                 :            : 
    3757                 :          0 :     ScVbaPalette aPalette( pDoc->GetDocumentShell() );
    3758 [ #  # ][ #  # ]:          0 :     return  new ScVbaCharacters( this, mxContext, aPalette, xSimple, Start, Length );
         [ #  # ][ #  # ]
    3759                 :            : }
    3760                 :            : 
    3761                 :            :  void SAL_CALL
    3762                 :          0 : ScVbaRange::Delete( const uno::Any& Shift ) throw (uno::RuntimeException)
    3763                 :            : {
    3764 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    3765                 :            :     {
    3766 [ #  # ][ #  # ]:          0 :         sal_Int32 nItems = m_Areas->getCount();
    3767         [ #  # ]:          0 :         for ( sal_Int32 index=1; index <= nItems; ++index )
    3768                 :            :         {
    3769 [ #  # ][ #  # ]:          0 :             uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    3770 [ #  # ][ #  # ]:          0 :             xRange->Delete( Shift );
    3771                 :          0 :         }
    3772                 :          0 :         return;
    3773                 :            :     }
    3774                 :          0 :     sheet::CellDeleteMode mode = sheet::CellDeleteMode_NONE ;
    3775         [ #  # ]:          0 :     RangeHelper thisRange( mxRange );
    3776 [ #  # ][ #  # ]:          0 :     table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
                 [ #  # ]
    3777         [ #  # ]:          0 :     if ( Shift.hasValue() )
    3778                 :            :     {
    3779                 :          0 :         sal_Int32 nShift = 0;
    3780                 :          0 :         Shift >>= nShift;
    3781      [ #  #  # ]:          0 :         switch ( nShift )
    3782                 :            :         {
    3783                 :            :             case excel::XlDeleteShiftDirection::xlShiftUp:
    3784                 :          0 :                 mode = sheet::CellDeleteMode_UP;
    3785                 :          0 :                 break;
    3786                 :            :             case excel::XlDeleteShiftDirection::xlShiftToLeft:
    3787                 :          0 :                 mode = sheet::CellDeleteMode_LEFT;
    3788                 :          0 :                 break;
    3789                 :            :             default:
    3790         [ #  # ]:          0 :                 throw uno::RuntimeException( rtl::OUString( "Illegal paramater " ), uno::Reference< uno::XInterface >() );
    3791                 :            :         }
    3792                 :            :     }
    3793                 :            :     else
    3794                 :            :         {
    3795 [ #  # ][ #  # ]:          0 :         bool bFullRow = ( thisAddress.StartColumn == 0 && thisAddress.EndColumn == MAXCOL );
    3796                 :          0 :             sal_Int32 nCols = thisAddress.EndColumn - thisAddress.StartColumn;
    3797                 :          0 :             sal_Int32 nRows = thisAddress.EndRow - thisAddress.StartRow;
    3798 [ #  # ][ #  # ]:          0 :         if ( mbIsRows || bFullRow || ( nCols >=  nRows ) )
                 [ #  # ]
    3799                 :          0 :             mode = sheet::CellDeleteMode_UP;
    3800                 :            :         else
    3801                 :          0 :             mode = sheet::CellDeleteMode_LEFT;
    3802                 :            :     }
    3803 [ #  # ][ #  # ]:          0 :     uno::Reference< sheet::XCellRangeMovement > xCellRangeMove( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
    3804 [ #  # ][ #  # ]:          0 :     xCellRangeMove->removeRange( thisAddress, mode );
                 [ #  # ]
    3805                 :            : 
    3806                 :            : }
    3807                 :            : 
    3808                 :            : //XElementAccess
    3809                 :            : sal_Bool SAL_CALL
    3810                 :          0 : ScVbaRange::hasElements() throw (uno::RuntimeException)
    3811                 :            : {
    3812         [ #  # ]:          0 :     uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY );
    3813         [ #  # ]:          0 :     if ( xColumnRowRange.is() )
    3814 [ #  # ][ #  # ]:          0 :         if ( xColumnRowRange->getRows()->getCount() ||
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
    3815 [ #  # ][ #  # ]:          0 :             xColumnRowRange->getColumns()->getCount() )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    3816                 :          0 :             return sal_True;
    3817                 :          0 :     return false;
    3818                 :            : }
    3819                 :            : 
    3820                 :            : // XEnumerationAccess
    3821                 :            : uno::Reference< container::XEnumeration > SAL_CALL
    3822                 :          0 : ScVbaRange::createEnumeration() throw (uno::RuntimeException)
    3823                 :            : {
    3824 [ #  # ][ #  # ]:          0 :     if ( mbIsColumns || mbIsRows )
    3825                 :            :     {
    3826         [ #  # ]:          0 :         uno::Reference< table::XColumnRowRange > xColumnRowRange(mxRange, uno::UNO_QUERY );
    3827 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(1) ), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    3828                 :          0 :                 sal_Int32 nElems = 0;
    3829         [ #  # ]:          0 :         if ( mbIsColumns )
    3830 [ #  # ][ #  # ]:          0 :             nElems = xColumnRowRange->getColumns()->getCount();
         [ #  # ][ #  # ]
    3831                 :            :         else
    3832 [ #  # ][ #  # ]:          0 :             nElems = xColumnRowRange->getRows()->getCount();
         [ #  # ][ #  # ]
    3833 [ #  # ][ #  # ]:          0 :                 return new ColumnsRowEnumeration( mxContext, xRange, nElems );
                 [ #  # ]
    3834                 :            : 
    3835                 :            :     }
    3836 [ #  # ][ #  # ]:          0 :     return new CellsEnumeration( mxParent, mxContext, m_Areas );
                 [ #  # ]
    3837                 :            : }
    3838                 :            : 
    3839                 :            : ::rtl::OUString SAL_CALL
    3840                 :          0 : ScVbaRange::getDefaultMethodName(  ) throw (uno::RuntimeException)
    3841                 :            : {
    3842 [ #  # ][ #  # ]:          0 :     const static rtl::OUString sName( "Item" );
    3843                 :          0 :     return sName;
    3844                 :            : }
    3845                 :            : 
    3846                 :            : 
    3847                 :            : uno::Reference< awt::XDevice >
    3848                 :          0 : getDeviceFromDoc( const uno::Reference< frame::XModel >& xModel ) throw( uno::RuntimeException )
    3849                 :            : {
    3850 [ #  # ][ #  # ]:          0 :     uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
                 [ #  # ]
    3851 [ #  # ][ #  # ]:          0 :     uno::Reference< frame::XFrame> xFrame( xController->getFrame(), uno::UNO_QUERY_THROW );
                 [ #  # ]
    3852 [ #  # ][ #  # ]:          0 :     uno::Reference< awt::XDevice > xDevice( xFrame->getComponentWindow(), uno::UNO_QUERY_THROW );
                 [ #  # ]
    3853                 :          0 :     return xDevice;
    3854                 :            : }
    3855                 :            : 
    3856                 :            : // returns calc internal col. width ( in points )
    3857                 :            : double
    3858                 :          0 : ScVbaRange::getCalcColWidth( const table::CellRangeAddress& rAddress) throw (uno::RuntimeException)
    3859                 :            : {
    3860                 :          0 :     ScDocument* pDoc = getScDocument();
    3861                 :          0 :     sal_uInt16 nWidth = pDoc->GetOriginalWidth( static_cast< SCCOL >( rAddress.StartColumn ), static_cast< SCTAB >( rAddress.Sheet ) );
    3862                 :          0 :     double nPoints = lcl_TwipsToPoints( nWidth );
    3863                 :          0 :     nPoints = lcl_Round2DecPlaces( nPoints );
    3864                 :          0 :     return nPoints;
    3865                 :            : }
    3866                 :            : 
    3867                 :            : double
    3868                 :          0 : ScVbaRange::getCalcRowHeight( const table::CellRangeAddress& rAddress ) throw (uno::RuntimeException)
    3869                 :            : {
    3870                 :          0 :     ScDocument* pDoc = excel::GetDocumentFromRange( mxRange );
    3871                 :          0 :     sal_uInt16 nWidth = pDoc->GetOriginalHeight( rAddress.StartRow, rAddress.Sheet );
    3872                 :          0 :     double nPoints = lcl_TwipsToPoints( nWidth );
    3873                 :          0 :     nPoints = lcl_Round2DecPlaces( nPoints );
    3874                 :          0 :     return nPoints;
    3875                 :            : }
    3876                 :            : 
    3877                 :            : // return Char Width in points
    3878                 :          0 : double getDefaultCharWidth( const uno::Reference< frame::XModel >& xModel ) throw ( uno::RuntimeException )
    3879                 :            : {
    3880 [ #  # ][ #  # ]:          0 :     const static rtl::OUString sDflt( "Default");
    3881 [ #  # ][ #  # ]:          0 :     const static rtl::OUString sCharFontName( "CharFontName");
    3882 [ #  # ][ #  # ]:          0 :     const static rtl::OUString sPageStyles( "PageStyles");
    3883                 :            :     // get the font from the default style
    3884         [ #  # ]:          0 :     uno::Reference< style::XStyleFamiliesSupplier > xStyleSupplier( xModel, uno::UNO_QUERY_THROW );
    3885 [ #  # ][ #  # ]:          0 :     uno::Reference< container::XNameAccess > xNameAccess( xStyleSupplier->getStyleFamilies(), uno::UNO_QUERY_THROW );
                 [ #  # ]
    3886 [ #  # ][ #  # ]:          0 :     uno::Reference< container::XNameAccess > xNameAccess2( xNameAccess->getByName( sPageStyles ), uno::UNO_QUERY_THROW );
                 [ #  # ]
    3887 [ #  # ][ #  # ]:          0 :     uno::Reference< beans::XPropertySet > xProps( xNameAccess2->getByName( sDflt ), uno::UNO_QUERY_THROW );
                 [ #  # ]
    3888                 :          0 :     rtl::OUString sFontName;
    3889 [ #  # ][ #  # ]:          0 :     xProps->getPropertyValue( sCharFontName ) >>= sFontName;
    3890                 :            : 
    3891         [ #  # ]:          0 :     uno::Reference< awt::XDevice > xDevice = getDeviceFromDoc( xModel );
    3892                 :          0 :     awt::FontDescriptor aDesc;
    3893                 :          0 :     aDesc.Name = sFontName;
    3894 [ #  # ][ #  # ]:          0 :     uno::Reference< awt::XFont > xFont( xDevice->getFont( aDesc ), uno::UNO_QUERY_THROW );
                 [ #  # ]
    3895 [ #  # ][ #  # ]:          0 :     double nCharPixelWidth =  xFont->getCharWidth( (sal_Int8)'0' );
    3896                 :            : 
    3897 [ #  # ][ #  # ]:          0 :     double nPixelsPerMeter = xDevice->getInfo().PixelPerMeterX;
    3898                 :          0 :     double nCharWidth = nCharPixelWidth /  nPixelsPerMeter;
    3899                 :          0 :     nCharWidth = nCharWidth * (double)56700;// in twips
    3900                 :          0 :     return lcl_TwipsToPoints( (sal_uInt16)nCharWidth );
    3901                 :            : }
    3902                 :            : 
    3903                 :          0 : double getDefaultCharWidth( ScDocShell* pDocShell )
    3904                 :            : {
    3905                 :          0 :     ScDocument* pDoc = pDocShell->GetDocument();
    3906         [ #  # ]:          0 :     OutputDevice* pRefDevice = pDoc->GetRefDevice();
    3907         [ #  # ]:          0 :     ScPatternAttr* pAttr = pDoc->GetDefPattern();
    3908         [ #  # ]:          0 :     ::Font aDefFont;
    3909         [ #  # ]:          0 :     pAttr->GetFont( aDefFont, SC_AUTOCOL_BLACK, pRefDevice );
    3910         [ #  # ]:          0 :     pRefDevice->SetFont( aDefFont );
    3911 [ #  # ][ #  # ]:          0 :     long nCharWidth = pRefDevice->GetTextWidth( rtl::OUString('0') );        // 1/100th mm
                 [ #  # ]
    3912         [ #  # ]:          0 :     return lcl_hmmToPoints( nCharWidth );
    3913                 :            : }
    3914                 :            : 
    3915                 :            : uno::Any SAL_CALL
    3916                 :          0 : ScVbaRange::getColumnWidth() throw (uno::RuntimeException)
    3917                 :            : {
    3918 [ #  # ][ #  # ]:          0 :     sal_Int32 nLen = m_Areas->getCount();
    3919         [ #  # ]:          0 :     if ( nLen > 1 )
    3920                 :            :     {
    3921 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(1) ), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    3922 [ #  # ][ #  # ]:          0 :         return xRange->getColumnWidth();
    3923                 :            :     }
    3924                 :            : 
    3925                 :          0 :     double nColWidth =  0;
    3926         [ #  # ]:          0 :     ScDocShell* pShell = getScDocShell();
    3927         [ #  # ]:          0 :     if ( pShell )
    3928                 :            :     {
    3929         [ #  # ]:          0 :         uno::Reference< frame::XModel > xModel = pShell->GetModel();
    3930         [ #  # ]:          0 :         double defaultCharWidth = getDefaultCharWidth( xModel );
    3931         [ #  # ]:          0 :         RangeHelper thisRange( mxRange );
    3932 [ #  # ][ #  # ]:          0 :         table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
                 [ #  # ]
    3933                 :          0 :         sal_Int32 nStartCol = thisAddress.StartColumn;
    3934                 :          0 :         sal_Int32 nEndCol = thisAddress.EndColumn;
    3935                 :          0 :         sal_uInt16 nColTwips = 0;
    3936         [ #  # ]:          0 :         for( sal_Int32 nCol = nStartCol ; nCol <= nEndCol; ++nCol )
    3937                 :            :         {
    3938                 :          0 :             thisAddress.StartColumn = nCol;
    3939         [ #  # ]:          0 :             sal_uInt16 nCurTwips = pShell->GetDocument()->GetOriginalWidth( static_cast< SCCOL >( thisAddress.StartColumn ), static_cast< SCTAB >( thisAddress.Sheet ) );
    3940         [ #  # ]:          0 :             if ( nCol == nStartCol )
    3941                 :          0 :                 nColTwips =  nCurTwips;
    3942         [ #  # ]:          0 :             if ( nColTwips != nCurTwips )
    3943         [ #  # ]:          0 :                 return aNULL();
    3944                 :            :         }
    3945                 :          0 :         nColWidth = lcl_TwipsToPoints( nColTwips );
    3946         [ #  # ]:          0 :         if ( nColWidth != 0.0 )
    3947 [ #  # ][ #  # ]:          0 :             nColWidth = ( nColWidth / defaultCharWidth ) - fExtraWidth;
                 [ #  # ]
    3948                 :            :     }
    3949                 :          0 :     nColWidth = lcl_Round2DecPlaces( nColWidth );
    3950         [ #  # ]:          0 :     return uno::makeAny( nColWidth );
    3951                 :            : }
    3952                 :            : 
    3953                 :            : void SAL_CALL
    3954                 :          0 : ScVbaRange::setColumnWidth( const uno::Any& _columnwidth ) throw (uno::RuntimeException)
    3955                 :            : {
    3956 [ #  # ][ #  # ]:          0 :     sal_Int32 nLen = m_Areas->getCount();
    3957         [ #  # ]:          0 :     if ( nLen > 1 )
    3958                 :            :     {
    3959         [ #  # ]:          0 :         for ( sal_Int32 index = 1; index != nLen; ++index )
    3960                 :            :         {
    3961 [ #  # ][ #  # ]:          0 :             uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(index) ), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    3962 [ #  # ][ #  # ]:          0 :             xRange->setColumnWidth( _columnwidth );
    3963                 :          0 :         }
    3964                 :          0 :         return;
    3965                 :            :     }
    3966                 :          0 :     double nColWidth = 0;
    3967                 :          0 :     _columnwidth >>= nColWidth;
    3968                 :          0 :     nColWidth = lcl_Round2DecPlaces( nColWidth );
    3969         [ #  # ]:          0 :     ScDocShell* pDocShell = getScDocShell();
    3970         [ #  # ]:          0 :     if ( pDocShell )
    3971                 :            :     {
    3972         [ #  # ]:          0 :         if ( nColWidth != 0.0 )
    3973         [ #  # ]:          0 :             nColWidth = ( nColWidth + fExtraWidth ) * getDefaultCharWidth( pDocShell );
    3974         [ #  # ]:          0 :         RangeHelper thisRange( mxRange );
    3975 [ #  # ][ #  # ]:          0 :         table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
                 [ #  # ]
    3976                 :          0 :         sal_uInt16 nTwips = lcl_pointsToTwips( nColWidth );
    3977                 :            : 
    3978                 :            :         SCCOLROW nColArr[2];
    3979                 :          0 :         nColArr[0] = thisAddress.StartColumn;
    3980                 :          0 :         nColArr[1] = thisAddress.EndColumn;
    3981                 :            :         // #163561# use mode SC_SIZE_DIRECT: hide for width 0, show for other values
    3982                 :          0 :         pDocShell->GetDocFunc().SetWidthOrHeight( true, 1, nColArr, thisAddress.Sheet,
    3983 [ #  # ][ #  # ]:          0 :                                                   SC_SIZE_DIRECT, nTwips, true, true );
    3984                 :            : 
    3985                 :            :     }
    3986                 :            : }
    3987                 :            : 
    3988                 :            : uno::Any SAL_CALL
    3989                 :          0 : ScVbaRange::getWidth() throw (uno::RuntimeException)
    3990                 :            : {
    3991 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    3992                 :            :     {
    3993 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(1) ), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    3994 [ #  # ][ #  # ]:          0 :         return xRange->getWidth();
    3995                 :            :     }
    3996         [ #  # ]:          0 :     uno::Reference< table::XColumnRowRange > xColRowRange( mxRange, uno::UNO_QUERY_THROW );
    3997 [ #  # ][ #  # ]:          0 :     uno::Reference< container::XIndexAccess > xIndexAccess( xColRowRange->getColumns(), uno::UNO_QUERY_THROW );
                 [ #  # ]
    3998 [ #  # ][ #  # ]:          0 :     sal_Int32 nElems = xIndexAccess->getCount();
    3999                 :          0 :     double nWidth = 0;
    4000         [ #  # ]:          0 :     for ( sal_Int32 index=0; index<nElems; ++index )
    4001                 :            :     {
    4002 [ #  # ][ #  # ]:          0 :         uno::Reference< sheet::XCellRangeAddressable > xAddressable( xIndexAccess->getByIndex( index ), uno::UNO_QUERY_THROW );
                 [ #  # ]
    4003 [ #  # ][ #  # ]:          0 :         double nTmpWidth = getCalcColWidth( xAddressable->getRangeAddress() );
                 [ #  # ]
    4004                 :          0 :         nWidth += nTmpWidth;
    4005                 :          0 :     }
    4006         [ #  # ]:          0 :     return uno::makeAny( nWidth );
    4007                 :            : }
    4008                 :            : 
    4009                 :            : uno::Any SAL_CALL
    4010                 :          0 : ScVbaRange::Areas( const uno::Any& item) throw (uno::RuntimeException)
    4011                 :            : {
    4012         [ #  # ]:          0 :     if ( !item.hasValue() )
    4013                 :          0 :         return uno::makeAny( m_Areas );
    4014         [ #  # ]:          0 :     return m_Areas->Item( item, uno::Any() );
    4015                 :            : }
    4016                 :            : 
    4017                 :            : uno::Reference< excel::XRange >
    4018                 :          0 : ScVbaRange::getArea( sal_Int32 nIndex ) throw( css::uno::RuntimeException )
    4019                 :            : {
    4020         [ #  # ]:          0 :     if ( !m_Areas.is() )
    4021         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString("No areas available"), uno::Reference< uno::XInterface >() );
    4022 [ #  # ][ #  # ]:          0 :     uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( ++nIndex ), uno::Any() ), uno::UNO_QUERY_THROW );
                 [ #  # ]
    4023                 :          0 :     return xRange;
    4024                 :            : }
    4025                 :            : 
    4026                 :            : uno::Any
    4027                 :          0 : ScVbaRange::Borders( const uno::Any& item ) throw( script::BasicErrorException, uno::RuntimeException )
    4028                 :            : {
    4029         [ #  # ]:          0 :     if ( !item.hasValue() )
    4030                 :          0 :         return uno::makeAny( getBorders() );
    4031         [ #  # ]:          0 :     return getBorders()->Item( item, uno::Any() );
    4032                 :            : }
    4033                 :            : 
    4034                 :            : uno::Any SAL_CALL
    4035                 :          0 : ScVbaRange::BorderAround( const css::uno::Any& LineStyle, const css::uno::Any& Weight,
    4036                 :            :                 const css::uno::Any& ColorIndex, const css::uno::Any& Color ) throw (css::uno::RuntimeException)
    4037                 :            : {
    4038                 :          0 :     sal_Int32 nCount = getBorders()->getCount();
    4039                 :            : 
    4040         [ #  # ]:          0 :     for( sal_Int32 i = 0; i < nCount; i++ )
    4041                 :            :     {
    4042                 :          0 :         const sal_Int32 nLineType = supportedIndexTable[i];
    4043      [ #  #  # ]:          0 :         switch( nLineType )
    4044                 :            :         {
    4045                 :            :             case excel::XlBordersIndex::xlEdgeLeft:
    4046                 :            :             case excel::XlBordersIndex::xlEdgeTop:
    4047                 :            :             case excel::XlBordersIndex::xlEdgeBottom:
    4048                 :            :             case excel::XlBordersIndex::xlEdgeRight:
    4049                 :            :             {
    4050 [ #  # ][ #  # ]:          0 :                 uno::Reference< excel::XBorder > xBorder( m_Borders->Item( uno::makeAny( nLineType ), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    4051         [ #  # ]:          0 :                 if( LineStyle.hasValue() )
    4052                 :            :                 {
    4053 [ #  # ][ #  # ]:          0 :                     xBorder->setLineStyle( LineStyle );
    4054                 :            :                 }
    4055         [ #  # ]:          0 :                 if( Weight.hasValue() )
    4056                 :            :                 {
    4057 [ #  # ][ #  # ]:          0 :                     xBorder->setWeight( Weight );
    4058                 :            :                 }
    4059         [ #  # ]:          0 :                 if( ColorIndex.hasValue() )
    4060                 :            :                 {
    4061 [ #  # ][ #  # ]:          0 :                     xBorder->setColorIndex( ColorIndex );
    4062                 :            :                 }
    4063         [ #  # ]:          0 :                 if( Color.hasValue() )
    4064                 :            :                 {
    4065 [ #  # ][ #  # ]:          0 :                     xBorder->setColor( Color );
    4066                 :            :                 }
    4067                 :          0 :                 break;
    4068                 :            :             }
    4069                 :            :             case excel::XlBordersIndex::xlInsideVertical:
    4070                 :            :             case excel::XlBordersIndex::xlInsideHorizontal:
    4071                 :            :             case excel::XlBordersIndex::xlDiagonalDown:
    4072                 :            :             case excel::XlBordersIndex::xlDiagonalUp:
    4073                 :          0 :                 break;
    4074                 :            :             default:
    4075         [ #  # ]:          0 :                 return uno::makeAny( false );
    4076                 :            :         }
    4077                 :            :     }
    4078         [ #  # ]:          0 :     return uno::makeAny( sal_True );
    4079                 :            : }
    4080                 :            : 
    4081                 :            : uno::Any SAL_CALL
    4082                 :          0 : ScVbaRange::getRowHeight() throw (uno::RuntimeException)
    4083                 :            : {
    4084 [ #  # ][ #  # ]:          0 :     sal_Int32 nLen = m_Areas->getCount();
    4085         [ #  # ]:          0 :     if ( nLen > 1 )
    4086                 :            :     {
    4087 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(1) ), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    4088 [ #  # ][ #  # ]:          0 :         return xRange->getRowHeight();
    4089                 :            :     }
    4090                 :            : 
    4091                 :            :     // if any row's RowHeight in the
    4092                 :            :     // range is different from any other then return NULL
    4093         [ #  # ]:          0 :     RangeHelper thisRange( mxRange );
    4094 [ #  # ][ #  # ]:          0 :     table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
                 [ #  # ]
    4095                 :            : 
    4096                 :          0 :     sal_Int32 nStartRow = thisAddress.StartRow;
    4097                 :          0 :     sal_Int32 nEndRow = thisAddress.EndRow;
    4098                 :          0 :         sal_uInt16 nRowTwips = 0;
    4099                 :            :     // #TODO probably possible to use the SfxItemSet ( and see if
    4100                 :            :     //  SFX_ITEM_DONTCARE is set ) to improve performance
    4101                 :            : // #CHECKME looks like this is general behaviour not just row Range specific
    4102                 :            : //  if ( mbIsRows )
    4103         [ #  # ]:          0 :     ScDocShell* pShell = getScDocShell();
    4104         [ #  # ]:          0 :     if ( pShell )
    4105                 :            :     {
    4106         [ #  # ]:          0 :         for ( sal_Int32 nRow = nStartRow ; nRow <= nEndRow; ++nRow )
    4107                 :            :         {
    4108                 :          0 :             thisAddress.StartRow = nRow;
    4109         [ #  # ]:          0 :             sal_uInt16 nCurTwips = pShell->GetDocument()->GetOriginalHeight( thisAddress.StartRow, thisAddress.Sheet );
    4110         [ #  # ]:          0 :             if ( nRow == nStartRow )
    4111                 :          0 :                 nRowTwips = nCurTwips;
    4112         [ #  # ]:          0 :             if ( nRowTwips != nCurTwips )
    4113         [ #  # ]:          0 :                 return aNULL();
    4114                 :            :         }
    4115                 :            :     }
    4116                 :          0 :     double nHeight = lcl_Round2DecPlaces( lcl_TwipsToPoints( nRowTwips ) );
    4117 [ #  # ][ #  # ]:          0 :     return uno::makeAny( nHeight );
    4118                 :            : }
    4119                 :            : 
    4120                 :            : void SAL_CALL
    4121                 :          0 : ScVbaRange::setRowHeight( const uno::Any& _rowheight) throw (uno::RuntimeException)
    4122                 :            : {
    4123 [ #  # ][ #  # ]:          0 :     sal_Int32 nLen = m_Areas->getCount();
    4124         [ #  # ]:          0 :     if ( nLen > 1 )
    4125                 :            :     {
    4126         [ #  # ]:          0 :         for ( sal_Int32 index = 1; index != nLen; ++index )
    4127                 :            :         {
    4128 [ #  # ][ #  # ]:          0 :             uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(index) ), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    4129 [ #  # ][ #  # ]:          0 :             xRange->setRowHeight( _rowheight );
    4130                 :          0 :         }
    4131                 :          0 :         return;
    4132                 :            :     }
    4133                 :          0 :     double nHeight = 0; // Incomming height is in points
    4134                 :          0 :         _rowheight >>= nHeight;
    4135                 :          0 :     nHeight = lcl_Round2DecPlaces( nHeight );
    4136         [ #  # ]:          0 :     RangeHelper thisRange( mxRange );
    4137 [ #  # ][ #  # ]:          0 :     table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
                 [ #  # ]
    4138                 :          0 :     sal_uInt16 nTwips = lcl_pointsToTwips( nHeight );
    4139                 :            : 
    4140         [ #  # ]:          0 :     ScDocShell* pDocShell = excel::GetDocShellFromRange( mxRange );
    4141                 :            :     SCCOLROW nRowArr[2];
    4142                 :          0 :     nRowArr[0] = thisAddress.StartRow;
    4143                 :          0 :     nRowArr[1] = thisAddress.EndRow;
    4144                 :          0 :     pDocShell->GetDocFunc().SetWidthOrHeight( false, 1, nRowArr, thisAddress.Sheet, SC_SIZE_ORIGINAL,
    4145 [ #  # ][ #  # ]:          0 :                                                                         nTwips, true, true );
    4146                 :            : }
    4147                 :            : 
    4148                 :            : uno::Any SAL_CALL
    4149                 :          0 : ScVbaRange::getPageBreak() throw (uno::RuntimeException)
    4150                 :            : {
    4151                 :          0 :     sal_Int32 nPageBreak = excel::XlPageBreak::xlPageBreakNone;
    4152         [ #  # ]:          0 :     ScDocShell* pShell = excel::GetDocShellFromRange( mxRange );
    4153         [ #  # ]:          0 :     if ( pShell )
    4154                 :            :     {
    4155         [ #  # ]:          0 :         RangeHelper thisRange( mxRange );
    4156 [ #  # ][ #  # ]:          0 :         table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
                 [ #  # ]
    4157                 :          0 :         sal_Bool bColumn = false;
    4158                 :            : 
    4159         [ #  # ]:          0 :         if (thisAddress.StartRow==0)
    4160                 :          0 :             bColumn = true;
    4161                 :            : 
    4162         [ #  # ]:          0 :         uno::Reference< frame::XModel > xModel = pShell->GetModel();
    4163         [ #  # ]:          0 :         if ( xModel.is() )
    4164                 :            :         {
    4165         [ #  # ]:          0 :             ScDocument* pDoc = excel::GetDocumentFromRange( mxRange );
    4166                 :            : 
    4167                 :          0 :             ScBreakType nBreak = BREAK_NONE;
    4168         [ #  # ]:          0 :             if ( !bColumn )
    4169         [ #  # ]:          0 :                 nBreak = pDoc->HasRowBreak(thisAddress.StartRow, thisAddress.Sheet);
    4170                 :            :             else
    4171         [ #  # ]:          0 :                 nBreak = pDoc->HasColBreak(thisAddress.StartColumn, thisAddress.Sheet);
    4172                 :            : 
    4173         [ #  # ]:          0 :             if (nBreak & BREAK_PAGE)
    4174                 :          0 :                 nPageBreak = excel::XlPageBreak::xlPageBreakAutomatic;
    4175                 :            : 
    4176         [ #  # ]:          0 :             if (nBreak & BREAK_MANUAL)
    4177                 :          0 :                 nPageBreak = excel::XlPageBreak::xlPageBreakManual;
    4178         [ #  # ]:          0 :         }
    4179                 :            :     }
    4180                 :            : 
    4181         [ #  # ]:          0 :     return uno::makeAny( nPageBreak );
    4182                 :            : }
    4183                 :            : 
    4184                 :            : void SAL_CALL
    4185                 :          0 : ScVbaRange::setPageBreak( const uno::Any& _pagebreak) throw (uno::RuntimeException)
    4186                 :            : {
    4187                 :          0 :     sal_Int32 nPageBreak = 0;
    4188                 :          0 :     _pagebreak >>= nPageBreak;
    4189                 :            : 
    4190         [ #  # ]:          0 :     ScDocShell* pShell = excel::GetDocShellFromRange( mxRange );
    4191         [ #  # ]:          0 :     if ( pShell )
    4192                 :            :     {
    4193         [ #  # ]:          0 :         RangeHelper thisRange( mxRange );
    4194 [ #  # ][ #  # ]:          0 :         table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
                 [ #  # ]
    4195 [ #  # ][ #  # ]:          0 :         if ((thisAddress.StartColumn==0) && (thisAddress.StartRow==0))
    4196                 :          0 :             return;
    4197                 :          0 :         sal_Bool bColumn = false;
    4198                 :            : 
    4199         [ #  # ]:          0 :         if (thisAddress.StartRow==0)
    4200                 :          0 :             bColumn = true;
    4201                 :            : 
    4202                 :          0 :         ScAddress aAddr( static_cast<SCCOL>(thisAddress.StartColumn), thisAddress.StartRow, thisAddress.Sheet );
    4203         [ #  # ]:          0 :         uno::Reference< frame::XModel > xModel = pShell->GetModel();
    4204         [ #  # ]:          0 :         if ( xModel.is() )
    4205                 :            :         {
    4206         [ #  # ]:          0 :             ScTabViewShell* pViewShell = excel::getBestViewShell( xModel );
    4207         [ #  # ]:          0 :             if ( nPageBreak == excel::XlPageBreak::xlPageBreakManual )
    4208         [ #  # ]:          0 :                 pViewShell->InsertPageBreak( bColumn, sal_True, &aAddr);
    4209         [ #  # ]:          0 :             else if ( nPageBreak == excel::XlPageBreak::xlPageBreakNone )
    4210         [ #  # ]:          0 :                 pViewShell->DeletePageBreak( bColumn, sal_True, &aAddr);
    4211 [ #  # ][ #  # ]:          0 :         }
    4212                 :            :     }
    4213                 :            : }
    4214                 :            : 
    4215                 :            : uno::Any SAL_CALL
    4216                 :          0 : ScVbaRange::getHeight() throw (uno::RuntimeException)
    4217                 :            : {
    4218 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    4219                 :            :     {
    4220 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(1) ), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    4221 [ #  # ][ #  # ]:          0 :         return xRange->getHeight();
    4222                 :            :     }
    4223                 :            : 
    4224         [ #  # ]:          0 :     uno::Reference< table::XColumnRowRange > xColRowRange( mxRange, uno::UNO_QUERY_THROW );
    4225 [ #  # ][ #  # ]:          0 :     uno::Reference< container::XIndexAccess > xIndexAccess( xColRowRange->getRows(), uno::UNO_QUERY_THROW );
                 [ #  # ]
    4226 [ #  # ][ #  # ]:          0 :     sal_Int32 nElems = xIndexAccess->getCount();
    4227                 :          0 :     double nHeight = 0;
    4228         [ #  # ]:          0 :     for ( sal_Int32 index=0; index<nElems; ++index )
    4229                 :            :     {
    4230 [ #  # ][ #  # ]:          0 :             uno::Reference< sheet::XCellRangeAddressable > xAddressable( xIndexAccess->getByIndex( index ), uno::UNO_QUERY_THROW );
                 [ #  # ]
    4231 [ #  # ][ #  # ]:          0 :         nHeight += getCalcRowHeight(xAddressable->getRangeAddress() );
                 [ #  # ]
    4232                 :          0 :     }
    4233         [ #  # ]:          0 :     return uno::makeAny( nHeight );
    4234                 :            : }
    4235                 :            : 
    4236                 :            : awt::Point
    4237                 :          0 : ScVbaRange::getPosition() throw ( uno::RuntimeException )
    4238                 :            : {
    4239                 :          0 :         awt::Point aPoint;
    4240                 :          0 :     uno::Reference< beans::XPropertySet > xProps;
    4241         [ #  # ]:          0 :     if ( mxRange.is() )
    4242         [ #  # ]:          0 :         xProps.set( mxRange, uno::UNO_QUERY_THROW );
    4243                 :            :     else
    4244         [ #  # ]:          0 :         xProps.set( mxRanges, uno::UNO_QUERY_THROW );
    4245 [ #  # ][ #  # ]:          0 :     xProps->getPropertyValue(POSITION) >>= aPoint;
                 [ #  # ]
    4246                 :          0 :     return aPoint;
    4247                 :            : }
    4248                 :            : uno::Any SAL_CALL
    4249                 :          0 : ScVbaRange::getLeft() throw (uno::RuntimeException)
    4250                 :            : {
    4251                 :            :     // helperapi returns the first ranges left ( and top below )
    4252 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    4253 [ #  # ][ #  # ]:          0 :         return getArea( 0 )->getLeft();
                 [ #  # ]
    4254         [ #  # ]:          0 :         awt::Point aPoint = getPosition();
    4255         [ #  # ]:          0 :     return uno::makeAny( lcl_hmmToPoints( aPoint.X ) );
    4256                 :            : }
    4257                 :            : 
    4258                 :            : 
    4259                 :            : uno::Any SAL_CALL
    4260                 :          0 : ScVbaRange::getTop() throw (uno::RuntimeException)
    4261                 :            : {
    4262                 :            :     // helperapi returns the first ranges top
    4263 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    4264 [ #  # ][ #  # ]:          0 :         return getArea( 0 )->getTop();
                 [ #  # ]
    4265         [ #  # ]:          0 :         awt::Point aPoint= getPosition();
    4266         [ #  # ]:          0 :     return uno::makeAny( lcl_hmmToPoints( aPoint.Y ) );
    4267                 :            : }
    4268                 :            : 
    4269                 :            : uno::Reference< excel::XWorksheet >
    4270                 :          0 : ScVbaRange::getWorksheet() throw (uno::RuntimeException)
    4271                 :            : {
    4272                 :            :     // #TODO #FIXME parent should always be set up ( currently thats not
    4273                 :            :     // the case )
    4274         [ #  # ]:          0 :     uno::Reference< excel::XWorksheet > xSheet( getParent(), uno::UNO_QUERY );
    4275         [ #  # ]:          0 :     if ( !xSheet.is() )
    4276                 :            :     {
    4277                 :          0 :         uno::Reference< table::XCellRange > xRange = mxRange;
    4278                 :            : 
    4279         [ #  # ]:          0 :         if ( mxRanges.is() ) // assign xRange to first range
    4280                 :            :         {
    4281         [ #  # ]:          0 :             uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW );
    4282 [ #  # ][ #  # ]:          0 :             xRange.set( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
                 [ #  # ]
    4283                 :            :         }
    4284         [ #  # ]:          0 :         ScDocShell* pDocShell = excel::GetDocShellFromRange(xRange);
    4285         [ #  # ]:          0 :         RangeHelper rHelper(xRange);
    4286                 :            :         // parent should be Thisworkbook
    4287 [ #  # ][ #  # ]:          0 :            xSheet.set( new ScVbaWorksheet( uno::Reference< XHelperInterface >(), mxContext,rHelper.getSpreadSheet(),pDocShell->GetModel()) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    4288                 :            :     }
    4289                 :          0 :     return xSheet;
    4290                 :            : }
    4291                 :            : 
    4292                 :            : // #TODO remove this ugly application processing
    4293                 :            : // Process an application Range request e.g. 'Range("a1,b2,a4:b6")
    4294                 :            : uno::Reference< excel::XRange >
    4295                 :         48 : ScVbaRange::ApplicationRange( const uno::Reference< uno::XComponentContext >& xContext, const css::uno::Any &Cell1, const css::uno::Any &Cell2 ) throw (css::uno::RuntimeException)
    4296                 :            : {
    4297                 :            :     // Althought the documentation seems clear that Range without a
    4298                 :            :     // qualifier then its a shortcut for ActiveSheet.Range
    4299                 :            :     // however, similarly Application.Range is apparently also a
    4300                 :            :     // shortcut for ActiveSheet.Range
    4301                 :            :     // The is however a subtle behavioural difference I've come across
    4302                 :            :     // wrt to named ranges.
    4303                 :            :     // If a named range "test" exists { Sheet1!$A1 } and the active sheet
    4304                 :            :     // is Sheet2 then the following will fail
    4305                 :            :     // msgbox ActiveSheet.Range("test").Address ' failes
    4306                 :            :     // msgbox WorkSheets("Sheet2").Range("test").Address
    4307                 :            :     // but !!!
    4308                 :            :     // msgbox Range("test").Address ' works
    4309                 :            :     // msgbox Application.Range("test").Address ' works
    4310                 :            : 
    4311                 :            :     // Single param Range
    4312                 :         48 :     rtl::OUString sRangeName;
    4313                 :         48 :     Cell1 >>= sRangeName;
    4314 [ +  - ][ +  - ]:         48 :     if ( Cell1.hasValue() && !Cell2.hasValue() && !sRangeName.isEmpty() )
         [ +  - ][ +  - ]
    4315                 :            :     {
    4316 [ +  + ][ +  - ]:         48 :         const static rtl::OUString sNamedRanges( "NamedRanges");
    4317 [ +  - ][ +  - ]:         48 :         uno::Reference< beans::XPropertySet > xPropSet( getCurrentExcelDoc(xContext), uno::UNO_QUERY_THROW );
    4318                 :            : 
    4319 [ +  - ][ +  - ]:         48 :         uno::Reference< container::XNameAccess > xNamed( xPropSet->getPropertyValue( sNamedRanges ), uno::UNO_QUERY_THROW );
                 [ +  - ]
    4320                 :         48 :         uno::Reference< sheet::XCellRangeReferrer > xReferrer;
    4321                 :            :         try
    4322                 :            :         {
    4323 [ -  + ][ #  # ]:         48 :             xReferrer.set ( xNamed->getByName( sRangeName ), uno::UNO_QUERY );
         [ -  + ][ +  - ]
    4324                 :            :         }
    4325         [ +  - ]:         48 :         catch( uno::Exception& /*e*/ )
    4326                 :            :         {
    4327                 :            :             // do nothing
    4328                 :            :         }
    4329         [ -  + ]:         48 :         if ( xReferrer.is() )
    4330                 :            :         {
    4331 [ #  # ][ #  # ]:          0 :             uno::Reference< table::XCellRange > xRange = xReferrer->getReferredCells();
    4332         [ #  # ]:          0 :             if ( xRange.is() )
    4333                 :            :             {
    4334 [ #  # ][ #  # ]:          0 :                 uno::Reference< excel::XRange > xVbRange =  new ScVbaRange( excel::getUnoSheetModuleObj( xRange ), xContext, xRange );
         [ #  # ][ #  # ]
    4335                 :          0 :                 return xVbRange;
    4336         [ #  # ]:         48 :             }
    4337 [ -  + ][ -  + ]:         48 :         }
                 [ +  - ]
    4338                 :            :     }
    4339                 :            : 
    4340                 :            :     // Add these codes for supporting shortcut: Application.Range(Range1, Range2), Range1 or Range2 is not the range of current active sheet.
    4341                 :            :     // If Range1 and Range2 are not in current active sheet, we should not use the active sheet, but use the sheet of Range1 and Range2.
    4342                 :            :     // If Range1 and Range2 are not in the same sheet, we throw an exception.
    4343                 :         48 :     uno::Reference< sheet::XSpreadsheet > xSpreadsheet;
    4344 [ +  - ][ +  - ]:         48 :     uno::Reference< excel::XRange > xRange1( Cell1, uno::UNO_QUERY ), xRange2( Cell2, uno::UNO_QUERY );
    4345         [ -  + ]:         48 :     if ( xRange1.is() )
    4346                 :            :     {
    4347 [ #  # ][ #  # ]:          0 :         RangeHelper thisRange( xRange1->getCellRange() );
                 [ #  # ]
    4348 [ #  # ][ #  # ]:          0 :         xSpreadsheet = thisRange.getSpreadSheet();
                 [ #  # ]
    4349                 :            :     }
    4350         [ -  + ]:         48 :     else if ( xRange2.is() )
    4351                 :            :     {
    4352 [ #  # ][ #  # ]:          0 :         RangeHelper thisRange( xRange2->getCellRange() );
                 [ #  # ]
    4353 [ #  # ][ #  # ]:          0 :         xSpreadsheet = thisRange.getSpreadSheet();
                 [ #  # ]
    4354                 :            :     }
    4355         [ +  - ]:         48 :     if ( !xSpreadsheet.is() )
    4356                 :            :     {
    4357         [ +  - ]:         48 :         uno::Reference< frame::XModel > xModel = getCurrentExcelDoc( xContext );
    4358         [ +  - ]:         48 :         if ( xModel.is() )
    4359                 :            :         {
    4360 [ +  - ][ +  - ]:         48 :             uno::Reference< sheet::XSpreadsheetView > xView( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
                 [ +  - ]
    4361 [ +  - ][ +  - ]:         48 :             xSpreadsheet = xView->getActiveSheet();
                 [ +  - ]
    4362                 :         48 :         }
    4363                 :            :     }
    4364                 :            : 
    4365         [ +  - ]:         48 :     uno::Reference< table::XCellRange > xSheetRange( xSpreadsheet, uno::UNO_QUERY_THROW );
    4366 [ +  - ][ +  - ]:         48 :     ScVbaRange* pRange = new ScVbaRange( excel::getUnoSheetModuleObj( xSheetRange ), xContext, xSheetRange );
    4367                 :            : 
    4368 [ +  - ][ +  - ]:         48 :     uno::Reference< excel::XRange > xVbSheetRange( pRange );
    4369         [ +  + ]:         48 :     return pRange->Range( Cell1, Cell2, true );
    4370                 :            : }
    4371                 :            : 
    4372                 :            : // Helper functions for AutoFilter
    4373                 :          0 : ScDBData* lcl_GetDBData_Impl( ScDocShell* pDocShell, sal_Int16 nSheet )
    4374                 :            : {
    4375                 :          0 :     ScDBData* pRet = NULL;
    4376         [ #  # ]:          0 :     if (pDocShell)
    4377                 :            :     {
    4378                 :          0 :         pRet = pDocShell->GetDocument()->GetAnonymousDBData(nSheet);
    4379                 :            :     }
    4380                 :          0 :     return pRet;
    4381                 :            : }
    4382                 :            : 
    4383                 :          0 : void lcl_SelectAll( ScDocShell* pDocShell, ScQueryParam& aParam )
    4384                 :            : {
    4385         [ #  # ]:          0 :     if ( pDocShell )
    4386                 :            :     {
    4387                 :          0 :         ScViewData* pViewData = pDocShell->GetViewData();
    4388         [ #  # ]:          0 :         if ( pViewData )
    4389                 :            :         {
    4390                 :            :             OSL_TRACE("Pushing out SelectAll query");
    4391                 :          0 :             pViewData->GetView()->Query( aParam, NULL, sal_True );
    4392                 :            :         }
    4393                 :            :     }
    4394                 :          0 : }
    4395                 :            : 
    4396                 :          0 : ScQueryParam lcl_GetQueryParam( ScDocShell* pDocShell, sal_Int16 nSheet )
    4397                 :            : {
    4398                 :          0 :     ScDBData* pDBData = lcl_GetDBData_Impl( pDocShell, nSheet );
    4399                 :          0 :     ScQueryParam aParam;
    4400         [ #  # ]:          0 :     if (pDBData)
    4401                 :            :     {
    4402         [ #  # ]:          0 :         pDBData->GetQueryParam( aParam );
    4403                 :            :     }
    4404                 :          0 :     return aParam;
    4405                 :            : }
    4406                 :            : 
    4407                 :          0 : void lcl_SetAllQueryForField( ScDocShell* pDocShell, SCCOLROW nField, sal_Int16 nSheet )
    4408                 :            : {
    4409         [ #  # ]:          0 :     ScQueryParam aParam = lcl_GetQueryParam( pDocShell, nSheet );
    4410         [ #  # ]:          0 :     aParam.RemoveEntryByField(nField);
    4411 [ #  # ][ #  # ]:          0 :     lcl_SelectAll( pDocShell, aParam );
    4412                 :          0 : }
    4413                 :            : 
    4414                 :            : // Modifies sCriteria, and nOp depending on the value of sCriteria
    4415                 :          0 : void lcl_setTableFieldsFromCriteria( rtl::OUString& sCriteria1, uno::Reference< beans::XPropertySet >& xDescProps, sheet::TableFilterField2& rFilterField )
    4416                 :            : {
    4417                 :            :     // #TODO make this more efficient and cycle through
    4418                 :            :     // sCriteria1 character by character to pick up <,<>,=, * etc.
    4419                 :            :     // right now I am more concerned with just getting it to work right
    4420                 :            : 
    4421                 :          0 :     sCriteria1 = sCriteria1.trim();
    4422                 :            :     // table of translation of criteria text to FilterOperators
    4423                 :            :     // <>searchtext - NOT_EQUAL
    4424                 :            :     //  =searchtext - EQUAL
    4425                 :            :     //  *searchtext - startwith
    4426                 :            :     //  <>*searchtext - doesn't startwith
    4427                 :            :     //  *searchtext* - contains
    4428                 :            :     //  <>*searchtext* - doesn't contain
    4429                 :            :     // [>|>=|<=|...]searchtext for GREATER_value, GREATER_EQUAL_value etc.
    4430                 :          0 :     sal_Int32 nPos = 0;
    4431                 :          0 :     bool bIsNumeric = false;
    4432         [ #  # ]:          0 :     if ( ( nPos = sCriteria1.indexOf( EQUALS ) ) == 0 )
    4433                 :            :     {
    4434         [ #  # ]:          0 :         if ( sCriteria1.getLength() == EQUALS.getLength() )
    4435                 :          0 :             rFilterField.Operator = sheet::FilterOperator2::EMPTY;
    4436                 :            :         else
    4437                 :            :         {
    4438                 :          0 :             rFilterField.Operator = sheet::FilterOperator2::EQUAL;
    4439                 :          0 :             sCriteria1 = sCriteria1.copy( EQUALS.getLength() );
    4440                 :          0 :             sCriteria1 = VBAToRegexp( sCriteria1 );
    4441                 :            :             // UseRegularExpressions
    4442         [ #  # ]:          0 :             if ( xDescProps.is() )
    4443 [ #  # ][ #  # ]:          0 :                 xDescProps->setPropertyValue( rtl::OUString(  "UseRegularExpressions"  ), uno::Any( sal_True ) );
    4444                 :            :         }
    4445                 :            : 
    4446                 :            :     }
    4447         [ #  # ]:          0 :     else if ( ( nPos = sCriteria1.indexOf( NOTEQUALS ) ) == 0 )
    4448                 :            :     {
    4449         [ #  # ]:          0 :         if ( sCriteria1.getLength() == NOTEQUALS.getLength() )
    4450                 :          0 :             rFilterField.Operator = sheet::FilterOperator2::NOT_EMPTY;
    4451                 :            :         else
    4452                 :            :         {
    4453                 :          0 :             rFilterField.Operator = sheet::FilterOperator2::NOT_EQUAL;
    4454                 :          0 :             sCriteria1 = sCriteria1.copy( NOTEQUALS.getLength() );
    4455                 :          0 :             sCriteria1 = VBAToRegexp( sCriteria1 );
    4456                 :            :             // UseRegularExpressions
    4457         [ #  # ]:          0 :             if ( xDescProps.is() )
    4458 [ #  # ][ #  # ]:          0 :                 xDescProps->setPropertyValue( rtl::OUString(  "UseRegularExpressions"  ), uno::Any( sal_True ) );
    4459                 :            :         }
    4460                 :            :     }
    4461         [ #  # ]:          0 :     else if ( ( nPos = sCriteria1.indexOf( GREATERTHAN ) ) == 0 )
    4462                 :            :     {
    4463                 :          0 :         bIsNumeric = true;
    4464         [ #  # ]:          0 :         if ( ( nPos = sCriteria1.indexOf( GREATERTHANEQUALS ) ) == 0 )
    4465                 :            :         {
    4466                 :          0 :             sCriteria1 = sCriteria1.copy( GREATERTHANEQUALS.getLength() );
    4467                 :          0 :             rFilterField.Operator = sheet::FilterOperator2::GREATER_EQUAL;
    4468                 :            :         }
    4469                 :            :         else
    4470                 :            :         {
    4471                 :          0 :             sCriteria1 = sCriteria1.copy( GREATERTHAN.getLength() );
    4472                 :          0 :             rFilterField.Operator = sheet::FilterOperator2::GREATER;
    4473                 :            :         }
    4474                 :            : 
    4475                 :            :     }
    4476         [ #  # ]:          0 :     else if ( ( nPos = sCriteria1.indexOf( LESSTHAN ) ) == 0 )
    4477                 :            :     {
    4478                 :          0 :         bIsNumeric = true;
    4479         [ #  # ]:          0 :         if ( ( nPos = sCriteria1.indexOf( LESSTHANEQUALS ) ) == 0 )
    4480                 :            :         {
    4481                 :          0 :             sCriteria1 = sCriteria1.copy( LESSTHANEQUALS.getLength() );
    4482                 :          0 :             rFilterField.Operator = sheet::FilterOperator2::LESS_EQUAL;
    4483                 :            :         }
    4484                 :            :         else
    4485                 :            :         {
    4486                 :          0 :             sCriteria1 = sCriteria1.copy( LESSTHAN.getLength() );
    4487                 :          0 :             rFilterField.Operator = sheet::FilterOperator2::LESS;
    4488                 :            :         }
    4489                 :            : 
    4490                 :            :     }
    4491                 :            :     else
    4492                 :          0 :         rFilterField.Operator = sheet::FilterOperator2::EQUAL;
    4493                 :            : 
    4494         [ #  # ]:          0 :     if ( bIsNumeric )
    4495                 :            :     {
    4496                 :          0 :         rFilterField.IsNumeric= sal_True;
    4497                 :          0 :         rFilterField.NumericValue = sCriteria1.toDouble();
    4498                 :            :     }
    4499                 :          0 :     rFilterField.StringValue = sCriteria1;
    4500                 :          0 : }
    4501                 :            : 
    4502                 :            : void SAL_CALL
    4503                 :          0 : ScVbaRange::AutoFilter( const uno::Any& Field, const uno::Any& Criteria1, const uno::Any& Operator, const uno::Any& Criteria2, const uno::Any& VisibleDropDown ) throw (uno::RuntimeException)
    4504                 :            : {
    4505                 :            :     // Is there an existing autofilter
    4506         [ #  # ]:          0 :     RangeHelper thisRange( mxRange );
    4507 [ #  # ][ #  # ]:          0 :     table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
                 [ #  # ]
    4508                 :          0 :     sal_Int16 nSheet = thisAddress.Sheet;
    4509         [ #  # ]:          0 :     ScDocShell* pShell = getScDocShell();
    4510                 :          0 :     sal_Bool bHasAuto = false;
    4511         [ #  # ]:          0 :     uno::Reference< sheet::XDatabaseRange > xDataBaseRange = excel::GetAutoFiltRange( pShell, nSheet );
    4512         [ #  # ]:          0 :     if ( xDataBaseRange.is() )
    4513                 :          0 :         bHasAuto = true;
    4514                 :            : 
    4515                 :          0 :     uno::Reference< table::XCellRange > xFilterRange;
    4516         [ #  # ]:          0 :     if ( !bHasAuto )
    4517                 :            :     {
    4518 [ #  # ][ #  # ]:          0 :         if (  m_Areas->getCount() > 1 )
                 [ #  # ]
    4519         [ #  # ]:          0 :             throw uno::RuntimeException( STR_ERRORMESSAGE_APPLIESTOSINGLERANGEONLY, uno::Reference< uno::XInterface >() );
    4520                 :            : 
    4521                 :          0 :         table::CellRangeAddress autoFiltAddress;
    4522                 :            :         //CurrentRegion()
    4523 [ #  # ][ #  # ]:          0 :         if ( isSingleCellRange() )
    4524                 :            :         {
    4525         [ #  # ]:          0 :             uno::Reference< excel::XRange > xCurrent( CurrentRegion() );
    4526         [ #  # ]:          0 :             if ( xCurrent.is() )
    4527                 :            :             {
    4528         [ #  # ]:          0 :                 ScVbaRange* pRange = getImplementation( xCurrent );
    4529         [ #  # ]:          0 :                 if ( pRange )
    4530                 :            :                 {
    4531 [ #  # ][ #  # ]:          0 :                     if ( pRange->isSingleCellRange() )
    4532         [ #  # ]:          0 :                        throw uno::RuntimeException( rtl::OUString( "Can't create AutoFilter" ), uno::Reference< uno::XInterface >() );
    4533         [ #  # ]:          0 :                     RangeHelper currentRegion( pRange->mxRange );
    4534 [ #  # ][ #  # ]:          0 :                     autoFiltAddress = currentRegion.getCellRangeAddressable()->getRangeAddress();
         [ #  # ][ #  # ]
    4535                 :            :                 }
    4536                 :          0 :             }
    4537                 :            :         }
    4538                 :            :         else // multi-cell range
    4539                 :            :         {
    4540         [ #  # ]:          0 :             RangeHelper multiCellRange( mxRange );
    4541 [ #  # ][ #  # ]:          0 :             autoFiltAddress = multiCellRange.getCellRangeAddressable()->getRangeAddress();
                 [ #  # ]
    4542                 :            :             // #163530# Filter box shows only entry of first row
    4543         [ #  # ]:          0 :             ScDocument* pDocument = ( pShell ? pShell->GetDocument() : NULL );
    4544         [ #  # ]:          0 :             if ( pDocument )
    4545                 :            :             {
    4546                 :          0 :                 SCCOL nStartCol = autoFiltAddress.StartColumn;
    4547                 :          0 :                 SCROW nStartRow = autoFiltAddress.StartRow;
    4548                 :          0 :                 SCCOL nEndCol = autoFiltAddress.EndColumn;
    4549                 :          0 :                 SCROW nEndRow = autoFiltAddress.EndRow;
    4550         [ #  # ]:          0 :                 pDocument->GetDataArea( autoFiltAddress.Sheet, nStartCol, nStartRow, nEndCol, nEndRow, true, true );
    4551                 :          0 :                 autoFiltAddress.StartColumn = nStartCol;
    4552                 :          0 :                 autoFiltAddress.StartRow = nStartRow;
    4553                 :          0 :                 autoFiltAddress.EndColumn = nEndCol;
    4554                 :          0 :                 autoFiltAddress.EndRow = nEndRow;
    4555         [ #  # ]:          0 :             }
    4556                 :            :         }
    4557                 :            : 
    4558         [ #  # ]:          0 :         uno::Reference< sheet::XUnnamedDatabaseRanges > xDBRanges = excel::GetUnnamedDataBaseRanges( pShell );
    4559         [ #  # ]:          0 :         if ( xDBRanges.is() )
    4560                 :            :         {
    4561                 :            :             OSL_TRACE("Going to add new autofilter range.. sheet %i", nSheet );
    4562 [ #  # ][ #  # ]:          0 :             if ( !xDBRanges->hasByTable( nSheet ) )
                 [ #  # ]
    4563 [ #  # ][ #  # ]:          0 :                 xDBRanges->setByTable( autoFiltAddress );
    4564 [ #  # ][ #  # ]:          0 :             xDataBaseRange.set( xDBRanges->getByTable(nSheet ), uno::UNO_QUERY_THROW );
                 [ #  # ]
    4565                 :            :         }
    4566         [ #  # ]:          0 :         if ( !xDataBaseRange.is() )
    4567         [ #  # ]:          0 :             throw uno::RuntimeException( rtl::OUString( "Failed to find the autofilter placeholder range"  ), uno::Reference< uno::XInterface >() );
    4568                 :            : 
    4569         [ #  # ]:          0 :         uno::Reference< beans::XPropertySet > xDBRangeProps( xDataBaseRange, uno::UNO_QUERY_THROW );
    4570                 :            :         // set autofilt
    4571 [ #  # ][ #  # ]:          0 :         xDBRangeProps->setPropertyValue( rtl::OUString( "AutoFilter" ), uno::Any(sal_True) );
                 [ #  # ]
    4572                 :            :         // set header
    4573 [ #  # ][ #  # ]:          0 :         uno::Reference< beans::XPropertySet > xFiltProps( xDataBaseRange->getFilterDescriptor(), uno::UNO_QUERY_THROW );
                 [ #  # ]
    4574                 :          0 :         sal_Bool bHasColHeader = false;
    4575         [ #  # ]:          0 :         ScDocument* pDoc = pShell ? pShell->GetDocument() : NULL;
    4576                 :            : 
    4577 [ #  # ][ #  # ]:          0 :         bHasColHeader = pDoc->HasColHeader(  static_cast< SCCOL >( autoFiltAddress.StartColumn ), static_cast< SCROW >( autoFiltAddress.StartRow ), static_cast< SCCOL >( autoFiltAddress.EndColumn ), static_cast< SCROW >( autoFiltAddress.EndRow ), static_cast< SCTAB >( autoFiltAddress.Sheet ) ) ? sal_True : false;
    4578 [ #  # ][ #  # ]:          0 :         xFiltProps->setPropertyValue( rtl::OUString( "ContainsHeader" ), uno::Any( bHasColHeader ) );
                 [ #  # ]
    4579                 :            :     }
    4580                 :            : 
    4581                 :            : 
    4582                 :          0 :     sal_Int32 nField = 0; // *IS* 1 based
    4583                 :          0 :     rtl::OUString sCriteria1;
    4584                 :          0 :     sal_Int32 nOperator = excel::XlAutoFilterOperator::xlAnd;
    4585                 :            : 
    4586                 :          0 :     sal_Bool bVisible = sal_True;
    4587                 :          0 :     VisibleDropDown >>= bVisible;
    4588                 :            : 
    4589         [ #  # ]:          0 :     if ( bVisible == bHasAuto ) // dropdown is displayed/notdisplayed as required
    4590                 :          0 :         bVisible = false;
    4591                 :          0 :     sheet::FilterConnection nConn = sheet::FilterConnection_AND;
    4592                 :          0 :     double nCriteria1 = 0;
    4593                 :            : 
    4594                 :          0 :     bool bHasCritValue = Criteria1.hasValue();
    4595                 :          0 :     bool bCritHasNumericValue = false; // not sure if a numeric criteria is possible
    4596         [ #  # ]:          0 :     if ( bHasCritValue )
    4597                 :          0 :         bCritHasNumericValue = ( Criteria1 >>= nCriteria1 );
    4598                 :            : 
    4599 [ #  # ][ #  # ]:          0 :     if (  !Field.hasValue() && ( Criteria1.hasValue() || Operator.hasValue() || Criteria2.hasValue() ) )
         [ #  # ][ #  # ]
                 [ #  # ]
    4600 [ #  # ][ #  # ]:          0 :         throw uno::RuntimeException();
    4601                 :            :     // Use the normal uno api, sometimes e.g. when you want to use ALL as the filter
    4602                 :            :     // we can't use refresh as the uno interface doesn't have a concept of ALL
    4603                 :            :     // in this case we just call the core calc functionality -
    4604                 :          0 :     bool bAll = false;
    4605         [ #  # ]:          0 :     uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext );
    4606                 :          0 :     bool bIsValidFieldValue = ( Field >>= nField );
    4607 [ #  # ][ #  # ]:          0 :     if ( !bIsValidFieldValue && xConverter.is() )
                 [ #  # ]
    4608                 :            :     {
    4609                 :            :         try
    4610                 :            :         {
    4611 [ #  # ][ #  # ]:          0 :             uno::Any aConverted = xConverter->convertTo( Field, getCppuType( (sal_Int32*)0 ) );
                 [ #  # ]
    4612                 :          0 :             bIsValidFieldValue = ( aConverted >>= nField );
    4613                 :            :         }
    4614         [ #  # ]:          0 :         catch( const uno::Exception& )
    4615                 :            :         {
    4616                 :            :         }
    4617                 :            :     }
    4618         [ #  # ]:          0 :     if ( bIsValidFieldValue )
    4619                 :            :     {
    4620                 :            :         uno::Reference< sheet::XSheetFilterDescriptor2 > xDesc(
    4621 [ #  # ][ #  # ]:          0 :                 xDataBaseRange->getFilterDescriptor(), uno::UNO_QUERY );
         [ #  # ][ #  # ]
    4622         [ #  # ]:          0 :         if ( xDesc.is() )
    4623                 :            :         {
    4624         [ #  # ]:          0 :             uno::Sequence< sheet::TableFilterField2 > sTabFilts;
    4625         [ #  # ]:          0 :             uno::Reference< beans::XPropertySet > xDescProps( xDesc, uno::UNO_QUERY_THROW );
    4626         [ #  # ]:          0 :         if ( Criteria1.hasValue() )
    4627                 :            :         {
    4628         [ #  # ]:          0 :             sTabFilts.realloc( 1 );
    4629         [ #  # ]:          0 :             sTabFilts[0].Operator = sheet::FilterOperator2::EQUAL;// sensible default
    4630         [ #  # ]:          0 :             if ( !bCritHasNumericValue )
    4631                 :            :             {
    4632                 :          0 :                 Criteria1 >>= sCriteria1;
    4633         [ #  # ]:          0 :                 sTabFilts[0].IsNumeric = bCritHasNumericValue;
    4634 [ #  # ][ #  # ]:          0 :                 if ( bHasCritValue && !sCriteria1.isEmpty() )
                 [ #  # ]
    4635 [ #  # ][ #  # ]:          0 :                     lcl_setTableFieldsFromCriteria( sCriteria1, xDescProps, sTabFilts[0]  );
    4636                 :            :                 else
    4637                 :          0 :                     bAll = true;
    4638                 :            :             }
    4639                 :            :             else // numeric
    4640                 :            :             {
    4641         [ #  # ]:          0 :                 sTabFilts[0].IsNumeric = sal_True;
    4642         [ #  # ]:          0 :                 sTabFilts[0].NumericValue = nCriteria1;
    4643                 :            :             }
    4644                 :            :         }
    4645                 :            :         else // no value specified
    4646                 :          0 :             bAll = true;
    4647                 :            :         // not sure what the relationship between Criteria1 and Operator is,
    4648                 :            :         // e.g. can you have a Operator without a Criteria ? in openoffice it
    4649 [ #  # ][ #  # ]:          0 :         bool bIsValidOpValue = ( Operator.hasValue()  && ( Operator >>= nOperator ) );
    4650 [ #  # ][ #  # ]:          0 :         if ( Operator.hasValue() && !bIsValidOpValue && xConverter.is() )
         [ #  # ][ #  # ]
    4651                 :            :         {
    4652                 :            :             try
    4653                 :            :             {
    4654 [ #  # ][ #  # ]:          0 :                 uno::Any aConverted = xConverter->convertTo( Operator, getCppuType( (sal_Int32*)0 ) );
                 [ #  # ]
    4655                 :          0 :                 bIsValidOpValue = ( aConverted >>= nOperator );
    4656                 :            :             }
    4657         [ #  # ]:          0 :             catch( const uno::Exception& )
    4658                 :            :             {
    4659                 :            :             }
    4660                 :            :         }
    4661         [ #  # ]:          0 :         if ( bIsValidOpValue )
    4662                 :            :         {
    4663                 :            :             // if its a bottom/top Ten(Percent/Value) and there
    4664                 :            :             // is no value specified for critera1 set it to 10
    4665 [ #  # ][ #  # ]:          0 :             if ( !bCritHasNumericValue && sCriteria1.isEmpty() && ( nOperator != excel::XlAutoFilterOperator::xlOr ) && ( nOperator != excel::XlAutoFilterOperator::xlAnd ) )
         [ #  # ][ #  # ]
                 [ #  # ]
    4666                 :            :             {
    4667         [ #  # ]:          0 :                 sTabFilts[0].IsNumeric = sal_True;
    4668         [ #  # ]:          0 :                 sTabFilts[0].NumericValue = 10;
    4669                 :          0 :                 bAll = false;
    4670                 :            :             }
    4671   [ #  #  #  #  :          0 :             switch ( nOperator )
                #  #  # ]
    4672                 :            :             {
    4673                 :            :                 case excel::XlAutoFilterOperator::xlBottom10Items:
    4674         [ #  # ]:          0 :                     sTabFilts[0].Operator = sheet::FilterOperator2::BOTTOM_VALUES;
    4675                 :          0 :                     break;
    4676                 :            :                 case excel::XlAutoFilterOperator::xlBottom10Percent:
    4677         [ #  # ]:          0 :                     sTabFilts[0].Operator = sheet::FilterOperator2::BOTTOM_PERCENT;
    4678                 :          0 :                     break;
    4679                 :            :                 case excel::XlAutoFilterOperator::xlTop10Items:
    4680         [ #  # ]:          0 :                     sTabFilts[0].Operator = sheet::FilterOperator2::TOP_VALUES;
    4681                 :          0 :                     break;
    4682                 :            :                 case excel::XlAutoFilterOperator::xlTop10Percent:
    4683         [ #  # ]:          0 :                     sTabFilts[0].Operator = sheet::FilterOperator2::TOP_PERCENT;
    4684                 :          0 :                     break;
    4685                 :            :                 case excel::XlAutoFilterOperator::xlOr:
    4686                 :          0 :                     nConn = sheet::FilterConnection_OR;
    4687                 :          0 :                     break;
    4688                 :            :                 case excel::XlAutoFilterOperator::xlAnd:
    4689                 :          0 :                     nConn = sheet::FilterConnection_AND;
    4690                 :          0 :                     break;
    4691                 :            :                 default:
    4692         [ #  # ]:          0 :                     throw uno::RuntimeException( rtl::OUString( "UnknownOption" ), uno::Reference< uno::XInterface >() );
    4693                 :            : 
    4694                 :            :             }
    4695                 :            : 
    4696                 :            :         }
    4697         [ #  # ]:          0 :         if ( !bAll )
    4698                 :            :         {
    4699         [ #  # ]:          0 :             sTabFilts[0].Connection = sheet::FilterConnection_AND;
    4700         [ #  # ]:          0 :             sTabFilts[0].Field = (nField - 1);
    4701                 :            : 
    4702                 :          0 :             rtl::OUString sCriteria2;
    4703         [ #  # ]:          0 :             if ( Criteria2.hasValue() ) // there is a Criteria2
    4704                 :            :             {
    4705         [ #  # ]:          0 :                 sTabFilts.realloc(2);
    4706 [ #  # ][ #  # ]:          0 :                 sTabFilts[1].Field = sTabFilts[0].Field;
    4707         [ #  # ]:          0 :                 sTabFilts[1].Connection = nConn;
    4708                 :            : 
    4709         [ #  # ]:          0 :                 if ( Criteria2 >>= sCriteria2 )
    4710                 :            :                 {
    4711         [ #  # ]:          0 :                     if ( !sCriteria2.isEmpty() )
    4712                 :            :                     {
    4713                 :          0 :                         uno::Reference< beans::XPropertySet > xProps;
    4714 [ #  # ][ #  # ]:          0 :                         lcl_setTableFieldsFromCriteria( sCriteria2, xProps,  sTabFilts[1] );
    4715         [ #  # ]:          0 :                         sTabFilts[1].IsNumeric = false;
    4716                 :            :                     }
    4717                 :            :                 }
    4718                 :            :                 else // numeric
    4719                 :            :                 {
    4720         [ #  # ]:          0 :                     Criteria2 >>= sTabFilts[1].NumericValue;
    4721         [ #  # ]:          0 :                     sTabFilts[1].IsNumeric = sal_True;
    4722         [ #  # ]:          0 :                     sTabFilts[1].Operator = sheet::FilterOperator2::EQUAL;
    4723                 :            :                 }
    4724                 :          0 :             }
    4725                 :            :         }
    4726                 :            : 
    4727 [ #  # ][ #  # ]:          0 :         xDesc->setFilterFields2( sTabFilts );
    4728         [ #  # ]:          0 :         if ( !bAll )
    4729                 :            :         {
    4730 [ #  # ][ #  # ]:          0 :             xDataBaseRange->refresh();
    4731                 :            :         }
    4732                 :            :         else
    4733                 :            :             // was 0 based now seems to be 1
    4734 [ #  # ][ #  # ]:          0 :             lcl_SetAllQueryForField( pShell, nField, nSheet );
    4735                 :          0 :         }
    4736                 :            :     }
    4737                 :            :     else
    4738                 :            :     {
    4739                 :            :         // this is just to toggle autofilter on and off ( not to be confused with
    4740                 :            :         // a VisibleDropDown option combined with a field, in that case just the
    4741                 :            :         // button should be disabled ) - currently we don't support that
    4742         [ #  # ]:          0 :         uno::Reference< beans::XPropertySet > xDBRangeProps( xDataBaseRange, uno::UNO_QUERY_THROW );
    4743         [ #  # ]:          0 :         if ( bHasAuto )
    4744                 :            :         {
    4745                 :            :             // find the any field with the query and select all
    4746         [ #  # ]:          0 :             ScQueryParam aParam = lcl_GetQueryParam( pShell, nSheet );
    4747 [ #  # ][ #  # ]:          0 :             for (SCSIZE i = 0; i< aParam.GetEntryCount(); ++i)
    4748                 :            :             {
    4749         [ #  # ]:          0 :                 ScQueryEntry& rEntry = aParam.GetEntry(i);
    4750         [ #  # ]:          0 :                 if ( rEntry.bDoQuery )
    4751         [ #  # ]:          0 :                     lcl_SetAllQueryForField( pShell, rEntry.nField, nSheet );
    4752                 :            :             }
    4753                 :            :             // remove exising filters
    4754                 :            :             uno::Reference< sheet::XSheetFilterDescriptor2 > xSheetFilterDescriptor(
    4755 [ #  # ][ #  # ]:          0 :                     xDataBaseRange->getFilterDescriptor(), uno::UNO_QUERY );
                 [ #  # ]
    4756         [ #  # ]:          0 :             if( xSheetFilterDescriptor.is() )
    4757 [ #  # ][ #  # ]:          0 :                 xSheetFilterDescriptor->setFilterFields2( uno::Sequence< sheet::TableFilterField2 >() );
         [ #  # ][ #  # ]
                 [ #  # ]
    4758                 :            :         }
    4759 [ #  # ][ #  # ]:          0 :         xDBRangeProps->setPropertyValue( rtl::OUString( "AutoFilter" ), uno::Any(!bHasAuto) );
                 [ #  # ]
    4760                 :            : 
    4761         [ #  # ]:          0 :     }
    4762                 :          0 : }
    4763                 :            : 
    4764                 :            : void SAL_CALL
    4765                 :          0 : ScVbaRange::Insert( const uno::Any& Shift, const uno::Any& /*CopyOrigin*/ ) throw (uno::RuntimeException)
    4766                 :            : {
    4767                 :            :     // It appears ( from the web ) that the undocumented CopyOrigin
    4768                 :            :     // param should contain member of enum XlInsertFormatOrigin
    4769                 :            :     // which can have values xlFormatFromLeftOrAbove or xlFormatFromRightOrBelow
    4770                 :            :     // #TODO investigate resultant behaviour using these constants
    4771                 :            :     // currently just processing Shift
    4772                 :            : 
    4773                 :          0 :     sheet::CellInsertMode mode = sheet::CellInsertMode_NONE;
    4774         [ #  # ]:          0 :     if ( Shift.hasValue() )
    4775                 :            :     {
    4776                 :          0 :         sal_Int32 nShift = 0;
    4777                 :          0 :         Shift >>= nShift;
    4778      [ #  #  # ]:          0 :         switch ( nShift )
    4779                 :            :         {
    4780                 :            :             case excel::XlInsertShiftDirection::xlShiftToRight:
    4781                 :          0 :                 mode = sheet::CellInsertMode_RIGHT;
    4782                 :          0 :                 break;
    4783                 :            :             case excel::XlInsertShiftDirection::xlShiftDown:
    4784                 :          0 :                 mode = sheet::CellInsertMode_DOWN;
    4785                 :          0 :                 break;
    4786                 :            :             default:
    4787         [ #  # ]:          0 :                 throw uno::RuntimeException( rtl::OUString( "Illegal paramater " ), uno::Reference< uno::XInterface >() );
    4788                 :            :         }
    4789                 :            :     }
    4790                 :            :     else
    4791                 :            :     {
    4792 [ #  # ][ #  # ]:          0 :         if ( getRow() >=  getColumn() )
                 [ #  # ]
    4793                 :          0 :             mode = sheet::CellInsertMode_DOWN;
    4794                 :            :         else
    4795                 :          0 :             mode = sheet::CellInsertMode_RIGHT;
    4796                 :            :     }
    4797         [ #  # ]:          0 :     RangeHelper thisRange( mxRange );
    4798 [ #  # ][ #  # ]:          0 :     table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
                 [ #  # ]
    4799 [ #  # ][ #  # ]:          0 :     uno::Reference< sheet::XCellRangeMovement > xCellRangeMove( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
    4800 [ #  # ][ #  # ]:          0 :     xCellRangeMove->insertCells( thisAddress, mode );
    4801                 :            : 
    4802                 :            :     // Paste from clipboard only if the clipboard content was copied via VBA, and not already pasted via VBA again.
    4803                 :            :     // "Insert" behavior should not depend on random clipboard content previously copied by the user.
    4804         [ #  # ]:          0 :     ScTransferObj* pClipObj = ScTransferObj::GetOwnClipboard( NULL );
    4805 [ #  # ][ #  # ]:          0 :     if ( pClipObj && pClipObj->GetUseInApi() )
                 [ #  # ]
    4806                 :            :     {
    4807                 :            :         // After the insert ( this range ) actually has moved
    4808                 :          0 :         ScRange aRange( static_cast< SCCOL >( thisAddress.StartColumn ), static_cast< SCROW >( thisAddress.StartRow ), static_cast< SCTAB >( thisAddress.Sheet ), static_cast< SCCOL >( thisAddress.EndColumn ), static_cast< SCROW >( thisAddress.EndRow ), static_cast< SCTAB >( thisAddress.Sheet ) );
    4809 [ #  # ][ #  # ]:          0 :         uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( excel::GetDocShellFromRange( mxRange ) , aRange ) );
         [ #  # ][ #  # ]
    4810 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xVbaRange( new ScVbaRange( mxParent, mxContext, xRange, mbIsRows, mbIsColumns ) );
         [ #  # ][ #  # ]
    4811 [ #  # ][ #  # ]:          0 :         xVbaRange->PasteSpecial( uno::Any(), uno::Any(), uno::Any(), uno::Any() );
    4812         [ #  # ]:          0 :     }
    4813                 :          0 : }
    4814                 :            : 
    4815                 :            : void SAL_CALL
    4816                 :          0 : ScVbaRange::Autofit() throw (uno::RuntimeException)
    4817                 :            : {
    4818                 :          0 :     sal_Int32 nLen = m_Areas->getCount();
    4819         [ #  # ]:          0 :     if ( nLen > 1 )
    4820                 :            :     {
    4821         [ #  # ]:          0 :         for ( sal_Int32 index = 1; index != nLen; ++index )
    4822                 :            :         {
    4823 [ #  # ][ #  # ]:          0 :             uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32(index) ), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    4824 [ #  # ][ #  # ]:          0 :             xRange->Autofit();
    4825                 :          0 :         }
    4826                 :          0 :         return;
    4827                 :            :     }
    4828                 :            :         // if the range is a not a row or column range autofit will
    4829                 :            :         // throw an error
    4830                 :            : 
    4831 [ #  # ][ #  # ]:          0 :         if ( !( mbIsColumns || mbIsRows ) )
    4832         [ #  # ]:          0 :             DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
    4833                 :          0 :         ScDocShell* pDocShell = excel::GetDocShellFromRange( mxRange );
    4834         [ #  # ]:          0 :         if ( pDocShell )
    4835                 :            :         {
    4836         [ #  # ]:          0 :             RangeHelper thisRange( mxRange );
    4837 [ #  # ][ #  # ]:          0 :             table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
                 [ #  # ]
    4838                 :            : 
    4839                 :            :             SCCOLROW nColArr[2];
    4840                 :          0 :             nColArr[0] = thisAddress.StartColumn;
    4841                 :          0 :             nColArr[1] = thisAddress.EndColumn;
    4842                 :          0 :             sal_Bool bDirection = sal_True;
    4843         [ #  # ]:          0 :             if ( mbIsRows )
    4844                 :            :             {
    4845                 :          0 :                 bDirection = false;
    4846                 :          0 :                 nColArr[0] = thisAddress.StartRow;
    4847                 :          0 :                 nColArr[1] = thisAddress.EndRow;
    4848                 :            :             }
    4849                 :          0 :             pDocShell->GetDocFunc().SetWidthOrHeight( bDirection, 1, nColArr, thisAddress.Sheet,
    4850 [ #  # ][ #  # ]:          0 :                                                       SC_SIZE_OPTIMAL, 0, true, true );
    4851                 :            :     }
    4852                 :            : }
    4853                 :            : 
    4854                 :            : /***************************************************************************************
    4855                 :            :  * interface for text:
    4856                 :            :  * com.sun.star.text.XText, com.sun.star.table.XCell, com.sun.star.container.XEnumerationAccess
    4857                 :            :  * com.sun.star.text.XTextRange,
    4858                 :            :  * the main problem is to recognize the numeric and date, which assosiate with DecimalSeparator, ThousandsSeparator,
    4859                 :            :  * TrailingMinusNumbers and FieldInfo.
    4860                 :            : ***************************************************************************************/
    4861                 :            : void SAL_CALL
    4862                 :          0 : ScVbaRange::TextToColumns( const css::uno::Any& Destination, const css::uno::Any& DataType, const css::uno::Any& TextQualifier,
    4863                 :            :         const css::uno::Any& ConsecutiveDelimiter, const css::uno::Any& Tab, const css::uno::Any& Semicolon, const css::uno::Any& Comma,
    4864                 :            :         const css::uno::Any& Space, const css::uno::Any& Other, const css::uno::Any& OtherChar, const css::uno::Any& FieldInfo,
    4865                 :            :         const css::uno::Any& DecimalSeparator, const css::uno::Any& ThousandsSeparator, const css::uno::Any& /*TrailingMinusNumbers*/  ) throw (css::uno::RuntimeException)
    4866                 :            : {
    4867                 :          0 :     uno::Reference< excel::XRange > xRange;
    4868         [ #  # ]:          0 :     if( Destination.hasValue() )
    4869                 :            :     {
    4870 [ #  # ][ #  # ]:          0 :         if( !( Destination >>= xRange ) )
    4871                 :            :             throw uno::RuntimeException( rtl::OUString( "Destination parameter should be a range" ),
    4872         [ #  # ]:          0 :                     uno::Reference< uno::XInterface >() );
    4873                 :            :         OSL_TRACE("set range");
    4874                 :            :     }
    4875                 :            :     else
    4876                 :            :     {
    4877                 :            :         //set as current
    4878         [ #  # ]:          0 :         xRange = this;
    4879                 :            :         OSL_TRACE("set range as himself");
    4880                 :            :     }
    4881                 :            : 
    4882                 :          0 :    sal_Int16 xlTextParsingType = excel::XlTextParsingType::xlDelimited;
    4883         [ #  # ]:          0 :     if ( DataType.hasValue() )
    4884                 :            :     {
    4885         [ #  # ]:          0 :         if( !( DataType >>= xlTextParsingType ) )
    4886                 :            :             throw uno::RuntimeException( rtl::OUString( "DataType parameter should be a short" ),
    4887         [ #  # ]:          0 :                     uno::Reference< uno::XInterface >() );
    4888                 :            :         OSL_TRACE("set Datatype" );
    4889                 :            :     }
    4890                 :          0 :     sal_Bool bDilimited = ( xlTextParsingType == excel::XlTextParsingType::xlDelimited );
    4891                 :            : 
    4892                 :          0 :     sal_Int16 xlTextQualifier = excel::XlTextQualifier::xlTextQualifierDoubleQuote;
    4893         [ #  # ]:          0 :     if( TextQualifier.hasValue() )
    4894                 :            :     {
    4895         [ #  # ]:          0 :         if( !( TextQualifier >>= xlTextQualifier ))
    4896                 :            :              throw uno::RuntimeException( rtl::OUString( "TextQualifier parameter should be a short" ),
    4897         [ #  # ]:          0 :                     uno::Reference< uno::XInterface >() );
    4898                 :            :         OSL_TRACE("set TextQualifier");
    4899                 :            :     }
    4900                 :            : 
    4901                 :          0 :     sal_Bool bConsecutiveDelimiter = false;
    4902         [ #  # ]:          0 :     if( ConsecutiveDelimiter.hasValue() )
    4903                 :            :     {
    4904         [ #  # ]:          0 :         if( !( ConsecutiveDelimiter >>= bConsecutiveDelimiter ) )
    4905                 :            :             throw uno::RuntimeException( rtl::OUString( "ConsecutiveDelimiter parameter should be a boolean" ),
    4906         [ #  # ]:          0 :                     uno::Reference< uno::XInterface >() );
    4907                 :            :         OSL_TRACE("set ConsecutiveDelimiter");
    4908                 :            :     }
    4909                 :            : 
    4910                 :          0 :     sal_Bool bTab = false;
    4911 [ #  # ][ #  # ]:          0 :     if( Tab.hasValue() && bDilimited )
                 [ #  # ]
    4912                 :            :     {
    4913         [ #  # ]:          0 :         if( !( Tab >>= bTab ) )
    4914                 :            :             throw uno::RuntimeException( rtl::OUString( "Tab parameter should be a boolean" ),
    4915         [ #  # ]:          0 :                     uno::Reference< uno::XInterface >() );
    4916                 :            :         OSL_TRACE("set Tab");
    4917                 :            :     }
    4918                 :            : 
    4919                 :          0 :     sal_Bool bSemicolon = false;
    4920 [ #  # ][ #  # ]:          0 :     if( Semicolon.hasValue() && bDilimited )
                 [ #  # ]
    4921                 :            :     {
    4922         [ #  # ]:          0 :         if( !( Semicolon >>= bSemicolon ) )
    4923                 :            :             throw uno::RuntimeException( rtl::OUString( "Semicolon parameter should be a boolean" ),
    4924         [ #  # ]:          0 :                     uno::Reference< uno::XInterface >() );
    4925                 :            :         OSL_TRACE("set Semicolon");
    4926                 :            :     }
    4927                 :          0 :     sal_Bool bComma = false;
    4928 [ #  # ][ #  # ]:          0 :     if( Comma.hasValue() && bDilimited )
                 [ #  # ]
    4929                 :            :     {
    4930         [ #  # ]:          0 :         if( !( Comma >>= bComma ) )
    4931                 :            :             throw uno::RuntimeException( rtl::OUString( "Comma parameter should be a boolean" ),
    4932         [ #  # ]:          0 :                     uno::Reference< uno::XInterface >() );
    4933                 :            :         OSL_TRACE("set Comma");
    4934                 :            :     }
    4935                 :          0 :     sal_Bool bSpace = false;
    4936 [ #  # ][ #  # ]:          0 :     if( Space.hasValue() && bDilimited )
                 [ #  # ]
    4937                 :            :     {
    4938         [ #  # ]:          0 :         if( !( Space >>= bSpace ) )
    4939                 :            :             throw uno::RuntimeException( rtl::OUString( "Space parameter should be a boolean" ),
    4940         [ #  # ]:          0 :                     uno::Reference< uno::XInterface >() );
    4941                 :            :         OSL_TRACE("set Space");
    4942                 :            :     }
    4943                 :          0 :     sal_Bool bOther = false;
    4944                 :          0 :     rtl::OUString sOtherChar;
    4945 [ #  # ][ #  # ]:          0 :     if( Other.hasValue() && bDilimited )
                 [ #  # ]
    4946                 :            :     {
    4947         [ #  # ]:          0 :         if( Other >>= bOther )
    4948                 :            :         {
    4949         [ #  # ]:          0 :             if( OtherChar.hasValue() )
    4950         [ #  # ]:          0 :                 if( !( OtherChar >>= sOtherChar ) )
    4951                 :            :                     throw uno::RuntimeException( rtl::OUString( "OtherChar parameter should be a String" ),
    4952         [ #  # ]:          0 :                         uno::Reference< uno::XInterface >() );
    4953                 :            :         OSL_TRACE("set OtherChar" );
    4954                 :            :         }
    4955         [ #  # ]:          0 :      else if( bOther )
    4956                 :            :             throw uno::RuntimeException( rtl::OUString( "Other parameter should be a True" ),
    4957         [ #  # ]:          0 :                     uno::Reference< uno::XInterface >() );
    4958                 :            :     }
    4959                 :            :     // FieldInfo, Optional Variant. An array containing parse information for the individual columns of data.
    4960                 :            :     // The interpretation depends on the value of DataType. When the data is delimited, this argument is an array
    4961                 :            :     // of two-element arrays, with each two-element array specifying the conversion options for a particular column.
    4962                 :            :     // The first element is the column number (1-based), and the second element is one of the xlColumnDataType
    4963                 :            :     // constants specifying how the column is parsed.
    4964         [ #  # ]:          0 :     uno::Sequence< uno::Sequence< uno::Any > > sFieldInfo;
    4965         [ #  # ]:          0 :     FieldInfo >>= sFieldInfo;
    4966                 :            : 
    4967                 :          0 :     rtl::OUString sDecimalSeparator;
    4968         [ #  # ]:          0 :     if( DecimalSeparator.hasValue() )
    4969                 :            :     {
    4970         [ #  # ]:          0 :         if( !( DecimalSeparator >>= sDecimalSeparator ) )
    4971                 :            :             throw uno::RuntimeException( rtl::OUString( "DecimalSeparator parameter should be a String" ),
    4972         [ #  # ]:          0 :                 uno::Reference< uno::XInterface >() );
    4973                 :            :         OSL_TRACE("set DecimalSeparator" );
    4974                 :            :     }
    4975                 :          0 :     rtl::OUString sThousandsSeparator;
    4976         [ #  # ]:          0 :     if( ThousandsSeparator.hasValue() )
    4977                 :            :     {
    4978         [ #  # ]:          0 :         if( !( ThousandsSeparator >>= sThousandsSeparator ) )
    4979                 :            :             throw uno::RuntimeException( rtl::OUString( "ThousandsSeparator parameter should be a String" ),
    4980         [ #  # ]:          0 :                 uno::Reference< uno::XInterface >() );
    4981                 :            :         OSL_TRACE("set ThousandsSpeparator" );
    4982                 :            :     }
    4983                 :            :     //TODO* TrailingMinusNumbers  Optional Variant. Numbers that begin with a minus character.
    4984                 :            : 
    4985                 :            :     // Get the destination range's left-upper cell address.
    4986 [ #  # ][ #  # ]:          0 :     ScVbaRange* pDestVbaRange = dynamic_cast< ScVbaRange* >( xRange.get() );
    4987                 :          0 :     ScAddress aScDestAddress;
    4988         [ #  # ]:          0 :     if ( pDestVbaRange )
    4989                 :            :     {
    4990         [ #  # ]:          0 :         ScUnoConversion::FillScAddress( aScDestAddress, pDestVbaRange->getLeftUpperCellAddress() );
    4991                 :            :     }
    4992                 :            : 
    4993                 :            :     // Parse the value of parameter FieldInfo.
    4994                 :          0 :     sal_uInt16 nRealCount = 0;
    4995                 :          0 :     sal_Int32* pColumns = NULL;
    4996                 :          0 :     sal_uInt8* pFormats = NULL;
    4997         [ #  # ]:          0 :     if ( sFieldInfo.getLength() > 0 )
    4998                 :            :     {
    4999                 :          0 :         sal_uInt16 nCount = sFieldInfo.getLength();
    5000         [ #  # ]:          0 :         pColumns = new sal_Int32[nCount];
    5001         [ #  # ]:          0 :         pFormats = new sal_uInt8[nCount];
    5002                 :          0 :         sal_uInt16 nFormat = 1;
    5003         [ #  # ]:          0 :         uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext );
    5004         [ #  # ]:          0 :         for ( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ )
    5005                 :            :         {
    5006 [ #  # ][ #  # ]:          0 :             if ( sFieldInfo[nIndex].getLength() >= 2 )
    5007                 :            :             {
    5008                 :          0 :                 nFormat = 1;
    5009                 :            :                 try
    5010                 :            :                 {
    5011 [ #  # ][ #  # ]:          0 :                     uno::Any aConverted = xConverter->convertTo( sFieldInfo[nIndex][0], getCppuType((sal_Int32*)0) );
         [ #  # ][ #  # ]
                 [ #  # ]
    5012                 :          0 :                     aConverted >>= pColumns[nRealCount];
    5013 [ #  # ][ #  # ]:          0 :                     aConverted = xConverter->convertTo( sFieldInfo[nIndex][1], getCppuType((sal_uInt16*)0) );
         [ #  # ][ #  # ]
                 [ #  # ]
    5014         [ #  # ]:          0 :                     aConverted >>= nFormat;
    5015                 :            :                 }
    5016         [ #  # ]:          0 :                 catch( const uno::Exception& )
    5017                 :            :                 {
    5018                 :            :                 }
    5019                 :          0 :                 pFormats[nRealCount++] = nFormat;
    5020                 :            :             }
    5021                 :          0 :         }
    5022                 :            :     }
    5023                 :            : 
    5024                 :          0 :     sal_Unicode cTextQualifier = '"';
    5025         [ #  # ]:          0 :     cTextQualifier = xlTextQualifier == excel::XlTextQualifier::xlTextQualifierNone ? '\0' : cTextQualifier;
    5026         [ #  # ]:          0 :     cTextQualifier = xlTextQualifier == excel::XlTextQualifier::xlTextQualifierSingleQuote ? '\'' : cTextQualifier;
    5027                 :            : 
    5028                 :            :     // Get field delimiters.
    5029         [ #  # ]:          0 :     String rFieldDelimiters;
    5030 [ #  # ][ #  # ]:          0 :     if ( bTab       ) rFieldDelimiters += '\t';
    5031 [ #  # ][ #  # ]:          0 :     if ( bSemicolon ) rFieldDelimiters += ';';
    5032 [ #  # ][ #  # ]:          0 :     if ( bComma     ) rFieldDelimiters += ',';
    5033 [ #  # ][ #  # ]:          0 :     if ( bSpace     ) rFieldDelimiters += ' ';
    5034 [ #  # ][ #  # ]:          0 :     if ( bOther     ) rFieldDelimiters += *sOtherChar.getStr();
    5035                 :            : 
    5036                 :            :     // Get the text in current range to SvMemoryStream.
    5037                 :          0 :     ScRange aSrcScRange;
    5038         [ #  # ]:          0 :     ScCellRangesBase* pSrcCellRangesBase = getCellRangesBase();
    5039         [ #  # ]:          0 :     if ( pSrcCellRangesBase )
    5040                 :            :     {
    5041         [ #  # ]:          0 :         ScRangeList aRangeList = pSrcCellRangesBase->GetRangeList();
    5042 [ #  # ][ #  # ]:          0 :         if ( !aRangeList.empty() )
    5043                 :            :         {
    5044         [ #  # ]:          0 :             aSrcScRange = *aRangeList.front();
    5045         [ #  # ]:          0 :         }
    5046                 :            :     }
    5047 [ #  # ][ #  # ]:          0 :     ScImportExport aExport( getScDocument(), aSrcScRange );
    5048                 :          0 :     aExport.SetDelimiter( static_cast< sal_Unicode >( 0 ) );
    5049         [ #  # ]:          0 :     SvMemoryStream aStream;
    5050                 :          0 :     aStream.SetStreamCharSet( RTL_TEXTENCODING_UNICODE );
    5051         [ #  # ]:          0 :     ScImportExport::SetNoEndianSwap( aStream );
    5052 [ #  # ][ #  # ]:          0 :     aExport.ExportStream( aStream, String(), FORMAT_STRING );
                 [ #  # ]
    5053         [ #  # ]:          0 :     aStream.Seek( 0 );
    5054                 :            : 
    5055                 :            :     // Set ScAsciiOptions according to the input parameters.
    5056         [ #  # ]:          0 :     ScAsciiOptions aOptions;
    5057                 :          0 :     aOptions.SetFixedLen( !bDilimited );
    5058                 :          0 :     aOptions.SetStartRow( 0 );
    5059         [ #  # ]:          0 :     aOptions.SetColInfo( nRealCount, pColumns, pFormats );
    5060         [ #  # ]:          0 :     if ( bDilimited )
    5061                 :            :     {
    5062         [ #  # ]:          0 :         aOptions.SetFieldSeps( rFieldDelimiters );
    5063                 :          0 :         aOptions.SetMergeSeps( bConsecutiveDelimiter );
    5064                 :          0 :         aOptions.SetTextSep( cTextQualifier );
    5065                 :            :     }
    5066                 :            : 
    5067                 :            :     // Split the String in to columns.
    5068 [ #  # ][ #  # ]:          0 :     if ( pDestVbaRange && pDestVbaRange->getScDocument() )
         [ #  # ][ #  # ]
    5069                 :            :     {
    5070 [ #  # ][ #  # ]:          0 :         ScImportExport aImport( pDestVbaRange->getScDocument(), aScDestAddress );
    5071         [ #  # ]:          0 :         aImport.SetExtOptions( aOptions );
    5072                 :          0 :         aImport.SetApi( false );
    5073 [ #  # ][ #  # ]:          0 :         aImport.ImportStream( aStream, String(), FORMAT_STRING );
         [ #  # ][ #  # ]
    5074                 :            :     }
    5075         [ #  # ]:          0 :     if ( pColumns )
    5076                 :            :     {
    5077                 :          0 :         DELETEZ( pColumns );
    5078                 :            :     }
    5079         [ #  # ]:          0 :     if ( pFormats )
    5080                 :            :     {
    5081                 :          0 :         DELETEZ( pFormats );
    5082 [ #  # ][ #  # ]:          0 :     }
         [ #  # ][ #  # ]
                 [ #  # ]
    5083                 :          0 : }
    5084                 :            : 
    5085                 :            : uno::Any SAL_CALL
    5086                 :          0 : ScVbaRange::Hyperlinks( const uno::Any& aIndex ) throw (uno::RuntimeException)
    5087                 :            : {
    5088                 :            :     /*  The range object always returns a new Hyperlinks object containing a
    5089                 :            :         fixed list of existing hyperlinks in the range.
    5090                 :            :         See vbahyperlinks.hxx for more details. */
    5091                 :            : 
    5092                 :            :     // get the global hyperlink object of the sheet (sheet should always be the parent of a Range object)
    5093 [ #  # ][ #  # ]:          0 :     uno::Reference< excel::XWorksheet > xWorksheet( getParent(), uno::UNO_QUERY_THROW );
    5094 [ #  # ][ #  # ]:          0 :     uno::Reference< excel::XHyperlinks > xSheetHlinks( xWorksheet->Hyperlinks( uno::Any() ), uno::UNO_QUERY_THROW );
                 [ #  # ]
    5095 [ #  # ][ #  # ]:          0 :     ScVbaHyperlinksRef xScSheetHlinks( dynamic_cast< ScVbaHyperlinks* >( xSheetHlinks.get() ) );
    5096         [ #  # ]:          0 :     if( !xScSheetHlinks.is() )
    5097         [ #  # ]:          0 :         throw uno::RuntimeException( ::rtl::OUString(  "Cannot obtain hyperlinks implementation object"  ), uno::Reference< uno::XInterface >() );
    5098                 :            : 
    5099                 :            :     // create a new local hyperlinks object based on the sheet hyperlinks
    5100 [ #  # ][ #  # ]:          0 :     ScVbaHyperlinksRef xHlinks( new ScVbaHyperlinks( getParent(), mxContext, xScSheetHlinks, getScRangeList() ) );
                 [ #  # ]
    5101         [ #  # ]:          0 :     if( aIndex.hasValue() )
    5102         [ #  # ]:          0 :         return xHlinks->Item( aIndex, uno::Any() );
    5103 [ #  # ][ #  # ]:          0 :     return uno::Any( uno::Reference< excel::XHyperlinks >( xHlinks.get() ) );
                 [ #  # ]
    5104                 :            : }
    5105                 :            : 
    5106                 :            : css::uno::Reference< excel::XValidation > SAL_CALL
    5107                 :          0 : ScVbaRange::getValidation() throw (css::uno::RuntimeException)
    5108                 :            : {
    5109         [ #  # ]:          0 :     if ( !m_xValidation.is() )
    5110 [ #  # ][ #  # ]:          0 :         m_xValidation = new ScVbaValidation( this, mxContext, mxRange );
                 [ #  # ]
    5111                 :          0 :     return m_xValidation;
    5112                 :            : }
    5113                 :            : 
    5114                 :            : namespace {
    5115                 :            : 
    5116                 :          0 : sal_Unicode lclGetPrefixChar( const uno::Reference< table::XCell >& rxCell ) throw (uno::RuntimeException)
    5117                 :            : {
    5118                 :            :     /*  TODO/FIXME: We need an apostroph-prefix property at the cell to
    5119                 :            :         implement this correctly. For now, return an apostroph for every text
    5120                 :            :         cell.
    5121                 :            : 
    5122                 :            :         TODO/FIXME: When Application.TransitionNavigKeys is supported and true,
    5123                 :            :         this function needs to inspect the cell formatting and return different
    5124                 :            :         prefixes according to the horizontal cell alignment.
    5125                 :            :      */
    5126         [ #  # ]:          0 :     return (rxCell->getType() == table::CellContentType_TEXT) ? '\'' : 0;
    5127                 :            : }
    5128                 :            : 
    5129                 :          0 : sal_Unicode lclGetPrefixChar( const uno::Reference< table::XCellRange >& rxRange ) throw (uno::RuntimeException)
    5130                 :            : {
    5131                 :            :     /*  This implementation is able to handle different prefixes (needed if
    5132                 :            :         Application.TransitionNavigKeys is true). The function lclGetPrefixChar
    5133                 :            :         for single cells called from here may return any prefix. If that
    5134                 :            :         function returns an empty prefix (NUL character) or different non-empty
    5135                 :            :         prefixes for two cells, this function returns 0.
    5136                 :            :      */
    5137                 :          0 :     sal_Unicode cCurrPrefix = 0;
    5138         [ #  # ]:          0 :     table::CellRangeAddress aRangeAddr = lclGetRangeAddress( rxRange );
    5139                 :          0 :     sal_Int32 nEndCol = aRangeAddr.EndColumn - aRangeAddr.StartColumn;
    5140                 :          0 :     sal_Int32 nEndRow = aRangeAddr.EndRow - aRangeAddr.StartRow;
    5141         [ #  # ]:          0 :     for( sal_Int32 nRow = 0; nRow <= nEndRow; ++nRow )
    5142                 :            :     {
    5143         [ #  # ]:          0 :         for( sal_Int32 nCol = 0; nCol <= nEndCol; ++nCol )
    5144                 :            :         {
    5145 [ #  # ][ #  # ]:          0 :             uno::Reference< table::XCell > xCell( rxRange->getCellByPosition( nCol, nRow ), uno::UNO_SET_THROW );
                 [ #  # ]
    5146         [ #  # ]:          0 :             sal_Unicode cNewPrefix = lclGetPrefixChar( xCell );
    5147 [ #  # ][ #  # ]:          0 :             if( (cNewPrefix == 0) || ((cCurrPrefix != 0) && (cNewPrefix != cCurrPrefix)) )
                 [ #  # ]
    5148                 :          0 :                 return 0;
    5149         [ #  # ]:          0 :             cCurrPrefix = cNewPrefix;
    5150                 :          0 :         }
    5151                 :            :     }
    5152                 :            :     // all cells contain the same prefix - return it
    5153                 :          0 :     return cCurrPrefix;
    5154                 :            : }
    5155                 :            : 
    5156                 :          0 : sal_Unicode lclGetPrefixChar( const uno::Reference< sheet::XSheetCellRangeContainer >& rxRanges ) throw (uno::RuntimeException)
    5157                 :            : {
    5158                 :          0 :     sal_Unicode cCurrPrefix = 0;
    5159         [ #  # ]:          0 :     uno::Reference< container::XEnumerationAccess > xRangesEA( rxRanges, uno::UNO_QUERY_THROW );
    5160 [ #  # ][ #  # ]:          0 :     uno::Reference< container::XEnumeration > xRangesEnum( xRangesEA->createEnumeration(), uno::UNO_SET_THROW );
                 [ #  # ]
    5161 [ #  # ][ #  # ]:          0 :     while( xRangesEnum->hasMoreElements() )
                 [ #  # ]
    5162                 :            :     {
    5163 [ #  # ][ #  # ]:          0 :         uno::Reference< table::XCellRange > xRange( xRangesEnum->nextElement(), uno::UNO_QUERY_THROW );
                 [ #  # ]
    5164         [ #  # ]:          0 :         sal_Unicode cNewPrefix = lclGetPrefixChar( xRange );
    5165 [ #  # ][ #  # ]:          0 :         if( (cNewPrefix == 0) || ((cCurrPrefix != 0) && (cNewPrefix != cCurrPrefix)) )
                 [ #  # ]
    5166                 :          0 :             return 0;
    5167         [ #  # ]:          0 :         cCurrPrefix = cNewPrefix;
    5168                 :          0 :     }
    5169                 :            :     // all ranges contain the same prefix - return it
    5170                 :          0 :     return cCurrPrefix;
    5171                 :            : }
    5172                 :            : 
    5173                 :          0 : inline uno::Any lclGetPrefixVariant( sal_Unicode cPrefixChar )
    5174                 :            : {
    5175 [ #  # ][ #  # ]:          0 :     return uno::Any( (cPrefixChar == 0) ? ::rtl::OUString() : ::rtl::OUString( cPrefixChar ) );
    5176                 :            : }
    5177                 :            : 
    5178                 :            : } // namespace
    5179                 :            : 
    5180                 :          0 : uno::Any SAL_CALL ScVbaRange::getPrefixCharacter() throw (uno::RuntimeException)
    5181                 :            : {
    5182                 :            :     /*  (1) If Application.TransitionNavigKeys is false, this function returns
    5183                 :            :         an apostroph character if the text cell begins with an apostroph
    5184                 :            :         character (formula return values are not taken into account); otherwise
    5185                 :            :         an empty string.
    5186                 :            : 
    5187                 :            :         (2) If Application.TransitionNavigKeys is true, this function returns
    5188                 :            :         an apostroph character, if the cell is left-aligned; a double-quote
    5189                 :            :         character, if the cell is right-aligned; a circumflex character, if the
    5190                 :            :         cell is centered; a backslash character, if the cell is set to filled;
    5191                 :            :         or an empty string, if nothing of the above.
    5192                 :            : 
    5193                 :            :         If a range or a list of ranges contains texts with leading apostroph
    5194                 :            :         character as well as other cells, this function returns an empty
    5195                 :            :         string.
    5196                 :            :      */
    5197                 :            : 
    5198         [ #  # ]:          0 :     if( mxRange.is() )
    5199                 :          0 :         return lclGetPrefixVariant( lclGetPrefixChar( mxRange ) );
    5200         [ #  # ]:          0 :     if( mxRanges.is() )
    5201                 :          0 :         return lclGetPrefixVariant( lclGetPrefixChar( mxRanges ) );
    5202         [ #  # ]:          0 :     throw uno::RuntimeException( ::rtl::OUString(  "Unexpected empty Range object"  ), uno::Reference< uno::XInterface >() );
    5203                 :            : }
    5204                 :            : 
    5205                 :          0 : uno::Any ScVbaRange::getShowDetail() throw ( css::uno::RuntimeException)
    5206                 :            : {
    5207                 :            :     // #FIXME, If the specified range is in a PivotTable report
    5208                 :            : 
    5209                 :            :     // In MSO VBA, the specified range must be a single summary column or row in an outline. otherwise throw exception
    5210 [ #  # ][ #  # ]:          0 :     if( m_Areas->getCount() > 1 )
                 [ #  # ]
    5211         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString( "Can not get Range.ShowDetail attribute "), uno::Reference< uno::XInterface >() );
    5212                 :            : 
    5213                 :          0 :     sal_Bool bShowDetail = false;
    5214                 :            : 
    5215         [ #  # ]:          0 :     RangeHelper helper( mxRange );
    5216         [ #  # ]:          0 :     uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = helper.getSheetCellCursor();
    5217 [ #  # ][ #  # ]:          0 :     xSheetCellCursor->collapseToCurrentRegion();
    5218         [ #  # ]:          0 :     uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xSheetCellCursor, uno::UNO_QUERY_THROW);
    5219 [ #  # ][ #  # ]:          0 :     table::CellRangeAddress aOutlineAddress = xCellRangeAddressable->getRangeAddress();
    5220                 :            : 
    5221                 :            :     // check if the specified range is a single summary column or row.
    5222 [ #  # ][ #  # ]:          0 :     table::CellRangeAddress thisAddress = helper.getCellRangeAddressable()->getRangeAddress();
                 [ #  # ]
    5223 [ #  # ][ #  # ]:          0 :     if( (thisAddress.StartRow == thisAddress.EndRow &&  thisAddress.EndRow == aOutlineAddress.EndRow ) ||
         [ #  # ][ #  # ]
    5224                 :            :         (thisAddress.StartColumn == thisAddress.EndColumn && thisAddress.EndColumn == aOutlineAddress.EndColumn ))
    5225                 :            :     {
    5226                 :          0 :         sal_Bool bColumn =thisAddress.StartRow == thisAddress.EndRow ? false:sal_True;
    5227         [ #  # ]:          0 :         ScDocument* pDoc = excel::GetDocumentFromRange( mxRange );
    5228         [ #  # ]:          0 :         ScOutlineTable* pOutlineTable = pDoc->GetOutlineTable(static_cast<SCTAB>(thisAddress.Sheet), sal_True);
    5229         [ #  # ]:          0 :         const ScOutlineArray* pOutlineArray =  bColumn ? pOutlineTable->GetColArray(): pOutlineTable->GetRowArray();
    5230         [ #  # ]:          0 :         if( pOutlineArray )
    5231                 :            :         {
    5232         [ #  # ]:          0 :             SCCOLROW nPos = bColumn ? (SCCOLROW)(thisAddress.EndColumn-1):(SCCOLROW)(thisAddress.EndRow-1);
    5233         [ #  # ]:          0 :             const ScOutlineEntry* pEntry = pOutlineArray->GetEntryByPos( 0, nPos );
    5234         [ #  # ]:          0 :             if( pEntry )
    5235                 :            :             {
    5236         [ #  # ]:          0 :                 bShowDetail = !pEntry->IsHidden();
    5237         [ #  # ]:          0 :                 return uno::makeAny( bShowDetail );
    5238                 :            :             }
    5239                 :          0 :         }
    5240                 :            :     }
    5241                 :            :     else
    5242                 :            :     {
    5243         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString( "Can not set Range.ShowDetail attribute "), uno::Reference< uno::XInterface >() );
    5244                 :            :     }
    5245 [ #  # ][ #  # ]:          0 :     return aNULL();
    5246                 :            : }
    5247                 :            : 
    5248                 :          0 : void ScVbaRange::setShowDetail(const uno::Any& aShowDetail) throw ( css::uno::RuntimeException)
    5249                 :            : {
    5250                 :            :     // #FIXME, If the specified range is in a PivotTable report
    5251                 :            : 
    5252                 :            :     // In MSO VBA, the specified range must be a single summary column or row in an outline. otherwise throw exception
    5253 [ #  # ][ #  # ]:          0 :     if( m_Areas->getCount() > 1 )
                 [ #  # ]
    5254         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString( "Can not set Range.ShowDetail attribute "), uno::Reference< uno::XInterface >() );
    5255                 :            : 
    5256         [ #  # ]:          0 :     bool bShowDetail = extractBoolFromAny( aShowDetail );
    5257                 :            : 
    5258         [ #  # ]:          0 :     RangeHelper helper( mxRange );
    5259         [ #  # ]:          0 :     uno::Reference< sheet::XSheetCellCursor > xSheetCellCursor = helper.getSheetCellCursor();
    5260 [ #  # ][ #  # ]:          0 :     xSheetCellCursor->collapseToCurrentRegion();
    5261         [ #  # ]:          0 :     uno::Reference< sheet::XCellRangeAddressable > xCellRangeAddressable(xSheetCellCursor, uno::UNO_QUERY_THROW);
    5262 [ #  # ][ #  # ]:          0 :     table::CellRangeAddress aOutlineAddress = xCellRangeAddressable->getRangeAddress();
    5263                 :            : 
    5264                 :            :     // check if the specified range is a single summary column or row.
    5265 [ #  # ][ #  # ]:          0 :     table::CellRangeAddress thisAddress = helper.getCellRangeAddressable()->getRangeAddress();
                 [ #  # ]
    5266 [ #  # ][ #  # ]:          0 :     if( (thisAddress.StartRow == thisAddress.EndRow &&  thisAddress.EndRow == aOutlineAddress.EndRow ) ||
         [ #  # ][ #  # ]
    5267                 :            :         (thisAddress.StartColumn == thisAddress.EndColumn && thisAddress.EndColumn == aOutlineAddress.EndColumn ))
    5268                 :            :     {
    5269                 :            :         // #FIXME, seems there is a different behavior between MSO and OOo.
    5270                 :            :         //  In OOo, the showDetail will show all the level entrys, while only show the first level entry in MSO
    5271 [ #  # ][ #  # ]:          0 :         uno::Reference< sheet::XSheetOutline > xSheetOutline( helper.getSpreadSheet(), uno::UNO_QUERY_THROW );
    5272         [ #  # ]:          0 :         if( bShowDetail )
    5273 [ #  # ][ #  # ]:          0 :             xSheetOutline->showDetail( aOutlineAddress );
    5274                 :            :         else
    5275 [ #  # ][ #  # ]:          0 :             xSheetOutline->hideDetail( aOutlineAddress );
    5276                 :            :     }
    5277                 :            :     else
    5278                 :            :     {
    5279         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString( "Can not set Range.ShowDetail attribute "), uno::Reference< uno::XInterface >() );
    5280         [ #  # ]:          0 :     }
    5281                 :          0 : }
    5282                 :            : 
    5283                 :            : ::com::sun::star::uno::Reference< ::ooo::vba::excel::XQueryTable > SAL_CALL
    5284                 :          0 : ScVbaRange::getQueryTable() throw (::com::sun::star::uno::RuntimeException)
    5285                 :            : {
    5286         [ #  # ]:          0 :     if (!m_xQueryTable.is())
    5287                 :            :     {
    5288 [ #  # ][ #  # ]:          0 :         m_xQueryTable = new ScVbaQueryTable(mxParent ,mxContext, getScDocument(), this);
         [ #  # ][ #  # ]
    5289                 :            :     }
    5290                 :            : 
    5291                 :          0 :     return m_xQueryTable;
    5292                 :            : }
    5293                 :            : 
    5294                 :            : uno::Reference< excel::XRange > SAL_CALL
    5295                 :          0 : ScVbaRange::MergeArea() throw (script::BasicErrorException, uno::RuntimeException)
    5296                 :            : {
    5297 [ #  # ][ #  # ]:          0 :     uno::Reference< sheet::XSheetCellRange > xMergeShellCellRange(mxRange->getCellRangeByPosition(0,0,0,0), uno::UNO_QUERY_THROW);
                 [ #  # ]
    5298 [ #  # ][ #  # ]:          0 :     uno::Reference< sheet::XSheetCellCursor > xMergeSheetCursor(xMergeShellCellRange->getSpreadsheet()->createCursorByRange( xMergeShellCellRange ), uno::UNO_QUERY_THROW);
         [ #  # ][ #  # ]
                 [ #  # ]
    5299         [ #  # ]:          0 :     if( xMergeSheetCursor.is() )
    5300                 :            :     {
    5301 [ #  # ][ #  # ]:          0 :         xMergeSheetCursor->collapseToMergedArea();
    5302         [ #  # ]:          0 :         uno::Reference<sheet::XCellRangeAddressable> xMergeCellAddress(xMergeSheetCursor, uno::UNO_QUERY_THROW);
    5303         [ #  # ]:          0 :         if( xMergeCellAddress.is() )
    5304                 :            :         {
    5305 [ #  # ][ #  # ]:          0 :             table::CellRangeAddress aCellAddress = xMergeCellAddress->getRangeAddress();
    5306 [ #  # ][ #  # ]:          0 :             if( aCellAddress.StartColumn ==0 && aCellAddress.EndColumn==0 &&
         [ #  # ][ #  # ]
    5307                 :            :                 aCellAddress.StartRow==0 && aCellAddress.EndRow==0)
    5308                 :            :             {
    5309 [ #  # ][ #  # ]:          0 :                 return new ScVbaRange( mxParent,mxContext,mxRange );
         [ #  # ][ #  # ]
    5310                 :            :             }
    5311                 :            :             else
    5312                 :            :             {
    5313                 :            :                 ScRange refRange( static_cast< SCCOL >( aCellAddress.StartColumn ), static_cast< SCROW >( aCellAddress.StartRow ), static_cast< SCTAB >( aCellAddress.Sheet ),
    5314                 :          0 :                                   static_cast< SCCOL >( aCellAddress.EndColumn ), static_cast< SCROW >( aCellAddress.EndRow ), static_cast< SCTAB >( aCellAddress.Sheet ) );
    5315 [ #  # ][ #  # ]:          0 :                 uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( getScDocShell() , refRange ) );
         [ #  # ][ #  # ]
    5316 [ #  # ][ #  # ]:          0 :                 return new ScVbaRange( mxParent, mxContext,xRange );
         [ #  # ][ #  # ]
    5317                 :            :             }
    5318         [ #  # ]:          0 :         }
    5319                 :            :     }
    5320 [ #  # ][ #  # ]:          0 :     return new ScVbaRange( mxParent, mxContext, mxRange );
         [ #  # ][ #  # ]
    5321                 :            : }
    5322                 :            : 
    5323                 :            : //The recordset's member: Recordset.Fields.Item will get a Field obj.
    5324                 :            : //Field.value is the column value.
    5325                 :            : ::sal_Int32 SAL_CALL
    5326                 :          0 : ScVbaRange::CopyFromRecordset( const ::com::sun::star::uno::Any& Data,  const ::com::sun::star::uno::Any& MaxRows, const ::com::sun::star::uno::Any& MaxColumns )
    5327                 :            : throw (::com::sun::star::script::BasicErrorException, ::com::sun::star::uno::RuntimeException)
    5328                 :            : {
    5329         [ #  # ]:          0 :     uno::Sequence< uno::Any > aParams;
    5330         [ #  # ]:          0 :     uno::Sequence< uno::Any > aFieldsParams(1);
    5331         [ #  # ]:          0 :     uno::Sequence< sal_Int16 > aOutParamIndex;
    5332         [ #  # ]:          0 :     uno::Sequence< uno::Any > aOutParam;
    5333                 :          0 :     uno::Reference< uno::XInterface > xIntRes;
    5334                 :          0 :     uno::Reference< uno::XInterface > xIntFields;
    5335                 :          0 :     uno::Reference< uno::XInterface > xIntFld;
    5336                 :          0 :     uno::Any aRet;
    5337                 :          0 :     uno::Any aPar;
    5338                 :          0 :     uno::Any aCrrCol;
    5339                 :          0 :     uno::Any aCrrRow;
    5340                 :          0 :     sal_Int16 nCrrCol = 0;
    5341                 :          0 :     sal_Int32 nCrrRow = 0;
    5342                 :            :     sal_Int32  nCol;
    5343                 :          0 :     sal_Int32 nMaxRows = 0;
    5344                 :          0 :     sal_Int32 nMaxColumns = 0;
    5345                 :          0 :     sal_Bool bEof = false;
    5346                 :          0 :     long lColCnt = 0;
    5347         [ #  # ]:          0 :     if (MaxColumns.hasValue())
    5348                 :            :     {
    5349                 :          0 :         MaxColumns >>= nMaxColumns;
    5350                 :            :     }
    5351                 :            : 
    5352                 :          0 :     long lMaxCol = nMaxColumns;
    5353                 :            : 
    5354         [ #  # ]:          0 :     if (MaxRows.hasValue())
    5355                 :            :     {
    5356                 :          0 :         MaxRows >>= nMaxRows;
    5357                 :            :     }
    5358                 :            : 
    5359                 :            : 
    5360         [ #  # ]:          0 :     Data >>= xIntRes;
    5361         [ #  # ]:          0 :     uno::Reference< script::XInvocation > xInvRes(xIntRes, uno::UNO_QUERY_THROW);
    5362                 :          0 :     rtl::OUString oMoveNext("MoveNext") ;
    5363                 :          0 :     rtl::OUString oEof("EOF") ;
    5364                 :          0 :     rtl::OUString oFields("Fields") ;
    5365                 :            : 
    5366 [ #  # ][ #  # ]:          0 :     if( !xInvRes->hasMethod(oMoveNext))
                 [ #  # ]
    5367                 :            :     {
    5368                 :          0 :         return -1;
    5369                 :            :     }
    5370                 :            : 
    5371                 :            :     //Get columns count
    5372 [ #  # ][ #  # ]:          0 :     aRet = xInvRes->getValue(oFields);
    5373         [ #  # ]:          0 :     aRet >>= xIntFields;
    5374         [ #  # ]:          0 :     uno::Reference< script::XInvocation > xInvFields(xIntFields, uno::UNO_QUERY_THROW);
    5375 [ #  # ][ #  # ]:          0 :     aRet = xInvFields->getValue( rtl::OUString("Count")) ;
    5376                 :          0 :     aRet >>= lColCnt;
    5377                 :            : 
    5378                 :            :     //Set the assign column number
    5379         [ #  # ]:          0 :     if (lMaxCol != 0)
    5380                 :            :     {
    5381         [ #  # ]:          0 :         if (lColCnt > lMaxCol)
    5382                 :            :         {
    5383                 :          0 :             lColCnt = lMaxCol;
    5384                 :            :         }
    5385                 :            :     }
    5386                 :            : 
    5387         [ #  # ]:          0 :     aCrrRow <<= nCrrRow;
    5388         [ #  # ]:          0 :     aCrrCol <<= nCrrCol;
    5389                 :            : 
    5390                 :            : 
    5391                 :            :     //Get start position
    5392 [ #  # ][ #  # ]:          0 :     uno::Reference< excel::XRange > xRngStartRow = Rows(uno::Any(sal_Int32(1)) );
    5393 [ #  # ][ #  # ]:          0 :     uno::Reference< excel::XRange > xRngPos = xRngStartRow->Columns( uno::Any(sal_Int32(1)) );
                 [ #  # ]
    5394                 :            : 
    5395                 :          0 :     while(1)
    5396                 :            :     {//travel recordset
    5397                 :            :         //get every column
    5398         [ #  # ]:          0 :         for (long l = 0; l < lColCnt ; l++)
    5399                 :            :         {
    5400                 :          0 :             nCol = l;
    5401         [ #  # ]:          0 :             aPar <<= nCol;
    5402                 :            :             //get every field
    5403 [ #  # ][ #  # ]:          0 :             aRet = xInvFields->invoke( rtl::OUString("Item"), uno::Sequence< uno::Any >(&aPar,1) , aOutParamIndex,aOutParam);
         [ #  # ][ #  # ]
    5404         [ #  # ]:          0 :             aRet >>= xIntFld;
    5405         [ #  # ]:          0 :             uno::Reference< script::XInvocation > xInvFld(xIntFld, uno::UNO_QUERY_THROW); //Get the Field obj
    5406                 :            : 
    5407                 :            :             //set the field value
    5408 [ #  # ][ #  # ]:          0 :             aRet = xInvFld->getValue( rtl::OUString("Value") );
    5409 [ #  # ][ #  # ]:          0 :             uno::Reference< excel::XRange > xRngToFill = xRngPos->Offset(aCrrRow,aCrrCol );
    5410                 :            : 
    5411 [ #  # ][ #  # ]:          0 :             xRngToFill->setValue(aRet);
    5412                 :          0 :             nCrrCol++;
    5413         [ #  # ]:          0 :             aCrrCol <<= nCrrCol;
    5414                 :          0 :         }
    5415                 :            : 
    5416 [ #  # ][ #  # ]:          0 :         aRet = xInvRes->invoke(oMoveNext, aParams,aOutParamIndex,aOutParam );
    5417 [ #  # ][ #  # ]:          0 :         aRet = xInvRes->getValue(oEof);
    5418                 :          0 :         aRet >>= bEof;
    5419 [ #  # ][ #  # ]:          0 :         if (bEof || ( nCrrRow >= nMaxRows && nMaxRows != 0) )
                 [ #  # ]
    5420                 :            :         {//Arrive the end of recordset
    5421                 :          0 :             break;
    5422                 :            :         }
    5423                 :            : 
    5424                 :          0 :         nCrrRow++;
    5425         [ #  # ]:          0 :         aCrrRow <<= nCrrRow;
    5426                 :          0 :         nCrrCol = 0;
    5427         [ #  # ]:          0 :         aCrrCol <<= nCrrCol;
    5428                 :            :     }
    5429                 :            : 
    5430 [ #  # ][ #  # ]:          0 :     return 0;
         [ #  # ][ #  # ]
    5431                 :            : }
    5432                 :            : 
    5433                 :            : void SAL_CALL
    5434                 :          0 : ScVbaRange::PrintOut( const uno::Any& From, const uno::Any& To, const uno::Any& Copies, const uno::Any& Preview, const uno::Any& ActivePrinter, const uno::Any& PrintToFile, const uno::Any& Collate, const uno::Any& PrToFileName ) throw (uno::RuntimeException)
    5435                 :            : {
    5436                 :          0 :     ScDocShell* pShell = NULL;
    5437                 :            : 
    5438 [ #  # ][ #  # ]:          0 :     sal_Int32 nItems = m_Areas->getCount();
    5439         [ #  # ]:          0 :     uno::Sequence<  table::CellRangeAddress > printAreas( nItems );
    5440                 :          0 :     uno::Reference< sheet::XPrintAreas > xPrintAreas;
    5441         [ #  # ]:          0 :     for ( sal_Int32 index=1; index <= nItems; ++index )
    5442                 :            :     {
    5443 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    5444                 :            : 
    5445 [ #  # ][ #  # ]:          0 :         RangeHelper thisRange( xRange->getCellRange() );
                 [ #  # ]
    5446 [ #  # ][ #  # ]:          0 :         table::CellRangeAddress rangeAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
                 [ #  # ]
    5447         [ #  # ]:          0 :         if ( index == 1 )
    5448                 :            :         {
    5449         [ #  # ]:          0 :             ScVbaRange* pRange = getImplementation( xRange );
    5450                 :            :             // initialise the doc shell and the printareas
    5451         [ #  # ]:          0 :             pShell = excel::GetDocShellFromRange( pRange->mxRange );
    5452 [ #  # ][ #  # ]:          0 :             xPrintAreas.set( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
    5453                 :            :         }
    5454         [ #  # ]:          0 :         printAreas[ index - 1 ] = rangeAddress;
    5455         [ #  # ]:          0 :     }
    5456         [ #  # ]:          0 :     if ( pShell )
    5457                 :            :     {
    5458         [ #  # ]:          0 :         if ( xPrintAreas.is() )
    5459                 :            :         {
    5460 [ #  # ][ #  # ]:          0 :             xPrintAreas->setPrintAreas( printAreas );
    5461         [ #  # ]:          0 :             uno::Reference< frame::XModel > xModel = pShell->GetModel();
    5462 [ #  # ][ #  # ]:          0 :             PrintOutHelper( excel::getBestViewShell( xModel ), From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, sal_True );
    5463                 :            :         }
    5464         [ #  # ]:          0 :     }
    5465                 :          0 : }
    5466                 :            : 
    5467                 :            : void SAL_CALL
    5468                 :          0 : ScVbaRange::AutoFill(  const uno::Reference< excel::XRange >& Destination, const uno::Any& Type ) throw (uno::RuntimeException)
    5469                 :            : {
    5470         [ #  # ]:          0 :     uno::Reference< excel::XRange > xDest( Destination, uno::UNO_QUERY_THROW );
    5471         [ #  # ]:          0 :     ScVbaRange* pRange = getImplementation( xDest );
    5472         [ #  # ]:          0 :     RangeHelper destRangeHelper( pRange->mxRange );
    5473 [ #  # ][ #  # ]:          0 :     table::CellRangeAddress destAddress = destRangeHelper.getCellRangeAddressable()->getRangeAddress();
                 [ #  # ]
    5474                 :            : 
    5475         [ #  # ]:          0 :     RangeHelper thisRange( mxRange );
    5476 [ #  # ][ #  # ]:          0 :     table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
                 [ #  # ]
    5477                 :          0 :     ScRange sourceRange;
    5478                 :          0 :     ScRange destRange;
    5479                 :            : 
    5480                 :          0 :     ScUnoConversion::FillScRange( destRange, destAddress );
    5481                 :          0 :     ScUnoConversion::FillScRange( sourceRange, thisAddress );
    5482                 :            : 
    5483                 :          0 :     FillDir eDir = FILL_TO_BOTTOM;
    5484                 :          0 :     double fStep = 1.0;
    5485                 :            : 
    5486                 :          0 :     ScRange aRange( destRange );
    5487                 :          0 :     ScRange aSourceRange( destRange );
    5488                 :            : 
    5489                 :            :     // default to include the number of Rows in the source range;
    5490                 :          0 :     SCCOLROW nSourceCount = ( sourceRange.aEnd.Row() - sourceRange.aStart.Row() ) + 1;
    5491                 :          0 :     SCCOLROW nCount = 0;
    5492                 :            : 
    5493         [ #  # ]:          0 :     if ( sourceRange != destRange )
    5494                 :            :     {
    5495                 :            :         // Find direction of fill, vertical or horizontal
    5496         [ #  # ]:          0 :         if ( sourceRange.aStart == destRange.aStart )
    5497                 :            :         {
    5498         [ #  # ]:          0 :             if ( sourceRange.aEnd.Row() == destRange.aEnd.Row() )
    5499                 :            :             {
    5500                 :          0 :                 nSourceCount = ( sourceRange.aEnd.Col() - sourceRange.aStart.Col() + 1 );
    5501                 :          0 :                 aSourceRange.aEnd.SetCol( static_cast<SCCOL>( aSourceRange.aStart.Col() + nSourceCount - 1 ) );
    5502                 :          0 :                 eDir = FILL_TO_RIGHT;
    5503                 :          0 :                 nCount = aRange.aEnd.Col() - aSourceRange.aEnd.Col();
    5504                 :            :             }
    5505         [ #  # ]:          0 :             else if ( sourceRange.aEnd.Col() == destRange.aEnd.Col() )
    5506                 :            :             {
    5507                 :          0 :                 aSourceRange.aEnd.SetRow( static_cast<SCROW>( aSourceRange.aStart.Row() + nSourceCount ) - 1 );
    5508                 :          0 :                 nCount = aRange.aEnd.Row() - aSourceRange.aEnd.Row();
    5509                 :          0 :                 eDir = FILL_TO_BOTTOM;
    5510                 :            :             }
    5511                 :            :         }
    5512                 :            : 
    5513         [ #  # ]:          0 :         else if ( aSourceRange.aEnd == destRange.aEnd )
    5514                 :            :         {
    5515         [ #  # ]:          0 :             if ( sourceRange.aStart.Col() == destRange.aStart.Col() )
    5516                 :            :             {
    5517                 :          0 :                 aSourceRange.aStart.SetRow( static_cast<SCROW>( aSourceRange.aEnd.Row() - nSourceCount + 1 ) );
    5518                 :          0 :                 nCount = aSourceRange.aStart.Row() - aRange.aStart.Row();
    5519                 :          0 :                 eDir = FILL_TO_TOP;
    5520                 :          0 :                 fStep = -fStep;
    5521                 :            :             }
    5522         [ #  # ]:          0 :             else if ( sourceRange.aStart.Row() == destRange.aStart.Row() )
    5523                 :            :             {
    5524                 :          0 :                 nSourceCount = ( sourceRange.aEnd.Col() - sourceRange.aStart.Col() ) + 1;
    5525                 :          0 :                 aSourceRange.aStart.SetCol( static_cast<SCCOL>( aSourceRange.aEnd.Col() - nSourceCount + 1 ) );
    5526                 :          0 :                 nCount = aSourceRange.aStart.Col() - aRange.aStart.Col();
    5527                 :          0 :                 eDir = FILL_TO_LEFT;
    5528                 :          0 :                 fStep = -fStep;
    5529                 :            :             }
    5530                 :            :         }
    5531                 :            :     }
    5532                 :            : 
    5533                 :          0 :     FillCmd eCmd = FILL_AUTO;
    5534                 :          0 :     FillDateCmd eDateCmd = FILL_DAY;
    5535                 :            : 
    5536         [ #  # ]:          0 :     if ( Type.hasValue() )
    5537                 :            :     {
    5538                 :          0 :         sal_Int16 nFillType = excel::XlAutoFillType::xlFillDefault;
    5539                 :          0 :         Type >>= nFillType;
    5540   [ #  #  #  #  :          0 :         switch ( nFillType )
             #  #  #  #  
                      # ]
    5541                 :            :         {
    5542                 :            :             case excel::XlAutoFillType::xlFillCopy:
    5543                 :          0 :                 eCmd =  FILL_SIMPLE;
    5544                 :          0 :                 fStep = 0.0;
    5545                 :          0 :                 break;
    5546                 :            :             case excel::XlAutoFillType::xlFillDays:
    5547                 :          0 :                 eCmd = FILL_DATE;
    5548                 :          0 :                 break;
    5549                 :            :             case excel::XlAutoFillType::xlFillMonths:
    5550                 :          0 :                 eCmd = FILL_DATE;
    5551                 :          0 :                 eDateCmd = FILL_MONTH;
    5552                 :          0 :                 break;
    5553                 :            :             case excel::XlAutoFillType::xlFillWeekdays:
    5554                 :          0 :                 eCmd = FILL_DATE;
    5555                 :          0 :                 eDateCmd = FILL_WEEKDAY;
    5556                 :          0 :                 break;
    5557                 :            :             case excel::XlAutoFillType::xlFillYears:
    5558                 :          0 :                 eCmd = FILL_DATE;
    5559                 :          0 :                 eDateCmd = FILL_YEAR;
    5560                 :          0 :                 break;
    5561                 :            :             case excel::XlAutoFillType::xlGrowthTrend:
    5562                 :          0 :                 eCmd = FILL_GROWTH;
    5563                 :          0 :                 break;
    5564                 :            :             case excel::XlAutoFillType::xlFillFormats:
    5565         [ #  # ]:          0 :                 throw uno::RuntimeException( rtl::OUString(  "xlFillFormat not supported for AutoFill"  ), uno::Reference< uno::XInterface >() );
    5566                 :            :             case excel::XlAutoFillType::xlFillValues:
    5567                 :            :             case excel::XlAutoFillType::xlFillSeries:
    5568                 :            :             case excel::XlAutoFillType::xlLinearTrend:
    5569                 :          0 :                 eCmd = FILL_LINEAR;
    5570                 :          0 :                 break;
    5571                 :            :             case excel::XlAutoFillType::xlFillDefault:
    5572                 :            :             default:
    5573                 :          0 :                 eCmd =  FILL_AUTO;
    5574                 :          0 :                 break;
    5575                 :            :         }
    5576                 :            :     }
    5577                 :            : #ifdef VBA_OOBUILD_HACK
    5578                 :          0 :     double fEndValue =  MAXDOUBLE;
    5579         [ #  # ]:          0 :     ScDocShell* pDocSh = excel::GetDocShellFromRange( mxRange );
    5580                 :          0 :     pDocSh->GetDocFunc().FillAuto( aSourceRange, NULL, eDir, eCmd, eDateCmd,
    5581 [ #  # ][ #  # ]:          0 :                                    nCount, fStep, fEndValue, sal_True, sal_True );
                 [ #  # ]
    5582                 :            : #endif
    5583                 :          0 : }
    5584                 :            : sal_Bool SAL_CALL
    5585                 :          0 : ScVbaRange::GoalSeek( const uno::Any& Goal, const uno::Reference< excel::XRange >& ChangingCell ) throw (uno::RuntimeException)
    5586                 :            : {
    5587                 :          0 :     ScDocShell* pDocShell = getScDocShell();
    5588                 :          0 :     sal_Bool bRes = sal_True;
    5589         [ #  # ]:          0 :     ScVbaRange* pRange = static_cast< ScVbaRange* >( ChangingCell.get() );
    5590 [ #  # ][ #  # ]:          0 :     if ( pDocShell && pRange )
    5591                 :            :     {
    5592 [ #  # ][ #  # ]:          0 :         uno::Reference< sheet::XGoalSeek > xGoalSeek(  pDocShell->GetModel(), uno::UNO_QUERY_THROW );
    5593         [ #  # ]:          0 :         RangeHelper thisRange( mxRange );
    5594 [ #  # ][ #  # ]:          0 :         table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
                 [ #  # ]
    5595         [ #  # ]:          0 :         RangeHelper changingCellRange( pRange->mxRange );
    5596 [ #  # ][ #  # ]:          0 :         table::CellRangeAddress changingCellAddr = changingCellRange.getCellRangeAddressable()->getRangeAddress();
                 [ #  # ]
    5597         [ #  # ]:          0 :         rtl::OUString sGoal = getAnyAsString( Goal );
    5598                 :          0 :         table::CellAddress thisCell( thisAddress.Sheet, thisAddress.StartColumn, thisAddress.StartRow );
    5599                 :          0 :         table::CellAddress changingCell( changingCellAddr.Sheet, changingCellAddr.StartColumn, changingCellAddr.StartRow );
    5600 [ #  # ][ #  # ]:          0 :         sheet::GoalResult res = xGoalSeek->seekGoal( thisCell, changingCell, sGoal );
    5601 [ #  # ][ #  # ]:          0 :         ChangingCell->setValue( uno::makeAny( res.Result ) );
                 [ #  # ]
    5602                 :            : 
    5603                 :            :         // openoffice behaves differently, result is 0 if the divergence is too great
    5604                 :            :                 // but... if it detects 0 is the value it requires then it will use that
    5605                 :            :         // e.g. divergence & result both = 0.0 does NOT mean there is an error
    5606 [ #  # ][ #  # ]:          0 :         if ( ( res.Divergence != 0.0 ) && ( res.Result == 0.0 ) )
    5607 [ #  # ][ #  # ]:          0 :             bRes = false;
    5608                 :            :     }
    5609                 :            :     else
    5610                 :          0 :         bRes = false;
    5611                 :          0 :     return bRes;
    5612                 :            : }
    5613                 :            : 
    5614                 :            : void
    5615                 :          0 : ScVbaRange::Calculate(  ) throw (script::BasicErrorException, uno::RuntimeException)
    5616                 :            : {
    5617 [ #  # ][ #  # ]:          0 :     getWorksheet()->Calculate();
    5618                 :          0 : }
    5619                 :            : 
    5620                 :            : uno::Reference< excel::XRange > SAL_CALL
    5621                 :          0 : ScVbaRange::Item( const uno::Any& row, const uno::Any& column ) throw (script::BasicErrorException, uno::RuntimeException)
    5622                 :            : {
    5623 [ #  # ][ #  # ]:          0 :     if ( mbIsRows || mbIsColumns )
    5624                 :            :     {
    5625         [ #  # ]:          0 :         if ( column.hasValue() )
    5626         [ #  # ]:          0 :             DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() );
    5627                 :          0 :         uno::Reference< excel::XRange > xRange;
    5628         [ #  # ]:          0 :         if ( mbIsColumns )
    5629 [ #  # ][ #  # ]:          0 :             xRange = Columns( row );
    5630                 :            :         else
    5631 [ #  # ][ #  # ]:          0 :             xRange = Rows( row );
    5632                 :          0 :         return xRange;
    5633                 :            :     }
    5634                 :          0 :     return Cells( row, column );
    5635                 :            : }
    5636                 :            : 
    5637                 :            : void
    5638                 :          0 : ScVbaRange::AutoOutline(  ) throw (script::BasicErrorException, uno::RuntimeException)
    5639                 :            : {
    5640                 :            :     // #TODO #FIXME needs to check for summary row/col ( whatever they are )
    5641                 :            :     // not valid for multi Area Addresses
    5642 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    5643         [ #  # ]:          0 :         DebugHelper::exception(SbERR_METHOD_FAILED, STR_ERRORMESSAGE_APPLIESTOSINGLERANGEONLY);
    5644                 :            :     // So needs to either span an entire Row or a just be a single cell
    5645                 :            :     // ( that contains a summary RowColumn )
    5646                 :            :     // also the Single cell cause doesn't seem to be handled specially in
    5647                 :            :     // this code ( ported from the helperapi RangeImpl.java,
    5648                 :            :     // RangeRowsImpl.java, RangesImpl.java, RangeSingleCellImpl.java
    5649         [ #  # ]:          0 :     RangeHelper thisRange( mxRange );
    5650 [ #  # ][ #  # ]:          0 :     table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
                 [ #  # ]
    5651                 :            : 
    5652 [ #  # ][ #  # ]:          0 :     uno::Reference< sheet::XSheetOutline > xSheetOutline( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
    5653 [ #  # ][ #  # ]:          0 :     xSheetOutline->autoOutline( thisAddress );
                 [ #  # ]
    5654                 :          0 : }
    5655                 :            : 
    5656                 :            : void SAL_CALL
    5657                 :          0 : ScVbaRange:: ClearOutline(  ) throw (script::BasicErrorException, uno::RuntimeException)
    5658                 :            : {
    5659 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    5660                 :            :     {
    5661 [ #  # ][ #  # ]:          0 :         sal_Int32 nItems = m_Areas->getCount();
    5662         [ #  # ]:          0 :         for ( sal_Int32 index=1; index <= nItems; ++index )
    5663                 :            :         {
    5664 [ #  # ][ #  # ]:          0 :             uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    5665 [ #  # ][ #  # ]:          0 :             xRange->ClearOutline();
    5666                 :          0 :         }
    5667                 :          0 :         return;
    5668                 :            :     }
    5669         [ #  # ]:          0 :     RangeHelper thisRange( mxRange );
    5670 [ #  # ][ #  # ]:          0 :     uno::Reference< sheet::XSheetOutline > xSheetOutline( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
    5671 [ #  # ][ #  # ]:          0 :     xSheetOutline->clearOutline();
                 [ #  # ]
    5672                 :            : }
    5673                 :            : 
    5674                 :            : void
    5675                 :          0 : ScVbaRange::groupUnGroup( bool bUnGroup ) throw ( script::BasicErrorException, uno::RuntimeException )
    5676                 :            : {
    5677 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    5678         [ #  # ]:          0 :          DebugHelper::exception(SbERR_METHOD_FAILED, STR_ERRORMESSAGE_APPLIESTOSINGLERANGEONLY);
    5679                 :          0 :     table::TableOrientation nOrient = table::TableOrientation_COLUMNS;
    5680         [ #  # ]:          0 :     if ( mbIsRows )
    5681                 :          0 :         nOrient = table::TableOrientation_ROWS;
    5682         [ #  # ]:          0 :     RangeHelper thisRange( mxRange );
    5683 [ #  # ][ #  # ]:          0 :     table::CellRangeAddress thisAddress = thisRange.getCellRangeAddressable()->getRangeAddress();
                 [ #  # ]
    5684 [ #  # ][ #  # ]:          0 :     uno::Reference< sheet::XSheetOutline > xSheetOutline( thisRange.getSpreadSheet(), uno::UNO_QUERY_THROW );
    5685         [ #  # ]:          0 :     if ( bUnGroup )
    5686 [ #  # ][ #  # ]:          0 :             xSheetOutline->ungroup( thisAddress, nOrient );
    5687                 :            :     else
    5688 [ #  # ][ #  # ]:          0 :             xSheetOutline->group( thisAddress, nOrient );
                 [ #  # ]
    5689                 :          0 : }
    5690                 :            : 
    5691                 :            : void SAL_CALL
    5692                 :          0 : ScVbaRange::Group(  ) throw (script::BasicErrorException, uno::RuntimeException)
    5693                 :            : {
    5694                 :          0 :     groupUnGroup();
    5695                 :          0 : }
    5696                 :            : void SAL_CALL
    5697                 :          0 : ScVbaRange::Ungroup(  ) throw (script::BasicErrorException, uno::RuntimeException)
    5698                 :            : {
    5699                 :          0 :     groupUnGroup(true);
    5700                 :          0 : }
    5701                 :            : 
    5702                 :          0 : void lcl_mergeCellsOfRange( const uno::Reference< table::XCellRange >& xCellRange, sal_Bool _bMerge = sal_True ) throw ( uno::RuntimeException )
    5703                 :            : {
    5704         [ #  # ]:          0 :         uno::Reference< util::XMergeable > xMergeable( xCellRange, uno::UNO_QUERY_THROW );
    5705 [ #  # ][ #  # ]:          0 :         xMergeable->merge(_bMerge);
    5706                 :          0 : }
    5707                 :            : void SAL_CALL
    5708                 :          0 : ScVbaRange::Merge( const uno::Any& Across ) throw (script::BasicErrorException, uno::RuntimeException)
    5709                 :            : {
    5710 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    5711                 :            :     {
    5712 [ #  # ][ #  # ]:          0 :         sal_Int32 nItems = m_Areas->getCount();
    5713         [ #  # ]:          0 :         for ( sal_Int32 index=1; index <= nItems; ++index )
    5714                 :            :         {
    5715 [ #  # ][ #  # ]:          0 :             uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    5716 [ #  # ][ #  # ]:          0 :             xRange->Merge(Across);
    5717                 :          0 :         }
    5718                 :          0 :         return;
    5719                 :            :     }
    5720                 :          0 :     uno::Reference< table::XCellRange > oCellRange;
    5721                 :          0 :     sal_Bool bAcross = false;
    5722                 :          0 :     Across >>= bAcross;
    5723         [ #  # ]:          0 :     if ( !bAcross )
    5724         [ #  # ]:          0 :         lcl_mergeCellsOfRange( mxRange );
    5725                 :            :     else
    5726                 :            :     {
    5727         [ #  # ]:          0 :         uno::Reference< excel::XRange > oRangeRowsImpl = Rows( uno::Any() );
    5728                 :            :         // #TODO #FIXME this seems incredibly lame, this can't be right
    5729 [ #  # ][ #  # ]:          0 :         for (sal_Int32 i=1; i <= oRangeRowsImpl->getCount();i++)
                 [ #  # ]
    5730                 :            :         {
    5731 [ #  # ][ #  # ]:          0 :             oRangeRowsImpl->Cells( uno::makeAny( i ), uno::Any() )->Merge( uno::makeAny( false ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    5732                 :          0 :         }
    5733                 :          0 :     }
    5734                 :            : }
    5735                 :            : 
    5736                 :            : void SAL_CALL
    5737                 :          0 : ScVbaRange::UnMerge(  ) throw (script::BasicErrorException, uno::RuntimeException)
    5738                 :            : {
    5739         [ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
    5740                 :            :     {
    5741                 :          0 :         sal_Int32 nItems = m_Areas->getCount();
    5742         [ #  # ]:          0 :         for ( sal_Int32 index=1; index <= nItems; ++index )
    5743                 :            :         {
    5744 [ #  # ][ #  # ]:          0 :             uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    5745 [ #  # ][ #  # ]:          0 :             xRange->UnMerge();
    5746                 :          0 :         }
    5747                 :          0 :         return;
    5748                 :            :     }
    5749                 :          0 :     lcl_mergeCellsOfRange( mxRange, false);
    5750                 :            : }
    5751                 :            : 
    5752                 :            : uno::Any SAL_CALL
    5753                 :          0 : ScVbaRange::getStyle() throw (uno::RuntimeException)
    5754                 :            : {
    5755 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    5756                 :            :     {
    5757 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32( 1 ) ), uno::Any() ), uno::UNO_QUERY_THROW  );
         [ #  # ][ #  # ]
    5758 [ #  # ][ #  # ]:          0 :         return xRange->getStyle();
    5759                 :            :     }
    5760         [ #  # ]:          0 :     uno::Reference< beans::XPropertySet > xProps( mxRange, uno::UNO_QUERY_THROW );
    5761                 :          0 :     rtl::OUString sStyleName;
    5762 [ #  # ][ #  # ]:          0 :     xProps->getPropertyValue(CELLSTYLE) >>= sStyleName;
    5763         [ #  # ]:          0 :     ScDocShell* pShell = getScDocShell();
    5764         [ #  # ]:          0 :     uno::Reference< frame::XModel > xModel( pShell->GetModel() );
    5765 [ #  # ][ #  # ]:          0 :     uno::Reference< excel::XStyle > xStyle = new ScVbaStyle( this, mxContext,  sStyleName, xModel );
         [ #  # ][ #  # ]
    5766         [ #  # ]:          0 :     return uno::makeAny( xStyle );
    5767                 :            : }
    5768                 :            : void SAL_CALL
    5769                 :          0 : ScVbaRange::setStyle( const uno::Any& _style ) throw (uno::RuntimeException)
    5770                 :            : {
    5771 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    5772                 :            :     {
    5773 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32( 1 ) ), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    5774 [ #  # ][ #  # ]:          0 :         xRange->setStyle( _style );
    5775                 :          0 :         return;
    5776                 :            :     }
    5777         [ #  # ]:          0 :     uno::Reference< beans::XPropertySet > xProps( mxRange, uno::UNO_QUERY_THROW );
    5778                 :          0 :     uno::Reference< excel::XStyle > xStyle;
    5779         [ #  # ]:          0 :     _style >>= xStyle;
    5780 [ #  # ][ #  # ]:          0 :     xProps->setPropertyValue(CELLSTYLE, uno::makeAny(xStyle->getName()));
         [ #  # ][ #  # ]
                 [ #  # ]
    5781                 :            : }
    5782                 :            : 
    5783                 :            : uno::Reference< excel::XRange >
    5784                 :          0 : ScVbaRange::PreviousNext( bool bIsPrevious )
    5785                 :            : {
    5786         [ #  # ]:          0 :     ScMarkData markedRange;
    5787                 :          0 :     ScRange refRange;
    5788         [ #  # ]:          0 :     RangeHelper thisRange( mxRange );
    5789                 :            : 
    5790 [ #  # ][ #  # ]:          0 :     ScUnoConversion::FillScRange( refRange, thisRange.getCellRangeAddressable()->getRangeAddress());
                 [ #  # ]
    5791         [ #  # ]:          0 :     markedRange. SetMarkArea( refRange );
    5792         [ #  # ]:          0 :     short nMove = bIsPrevious ? -1 : 1;
    5793                 :            : 
    5794                 :          0 :     SCCOL nNewX = refRange.aStart.Col();
    5795                 :          0 :     SCROW nNewY = refRange.aStart.Row();
    5796                 :          0 :     SCTAB nTab = refRange.aStart.Tab();
    5797                 :            : 
    5798         [ #  # ]:          0 :     ScDocument* pDoc = getScDocument();
    5799         [ #  # ]:          0 :     pDoc->GetNextPos( nNewX,nNewY, nTab, nMove,0, true,true, markedRange );
    5800                 :          0 :     refRange.aStart.SetCol( nNewX );
    5801                 :          0 :     refRange.aStart.SetRow( nNewY );
    5802                 :          0 :     refRange.aStart.SetTab( nTab );
    5803                 :          0 :     refRange.aEnd.SetCol( nNewX );
    5804                 :          0 :     refRange.aEnd.SetRow( nNewY );
    5805                 :          0 :     refRange.aEnd.SetTab( nTab );
    5806                 :            : 
    5807 [ #  # ][ #  # ]:          0 :     uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( getScDocShell() , refRange ) );
         [ #  # ][ #  # ]
    5808                 :            : 
    5809 [ #  # ][ #  # ]:          0 :     return new ScVbaRange( mxParent, mxContext, xRange );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    5810                 :            : }
    5811                 :            : 
    5812                 :            : uno::Reference< excel::XRange > SAL_CALL
    5813                 :          0 : ScVbaRange::Next() throw (script::BasicErrorException, uno::RuntimeException)
    5814                 :            : {
    5815         [ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
    5816                 :            :     {
    5817 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32( 1 ) ), uno::Any() ) , uno::UNO_QUERY_THROW  );
         [ #  # ][ #  # ]
    5818 [ #  # ][ #  # ]:          0 :         return xRange->Next();
    5819                 :            :     }
    5820                 :          0 :     return PreviousNext( false );
    5821                 :            : }
    5822                 :            : 
    5823                 :            : uno::Reference< excel::XRange > SAL_CALL
    5824                 :          0 : ScVbaRange::Previous() throw (script::BasicErrorException, uno::RuntimeException)
    5825                 :            : {
    5826         [ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
    5827                 :            :     {
    5828 [ #  # ][ #  # ]:          0 :         uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny( sal_Int32( 1 ) ), uno::Any() ), uno::UNO_QUERY_THROW  );
         [ #  # ][ #  # ]
    5829 [ #  # ][ #  # ]:          0 :         return xRange->Previous();
    5830                 :            :     }
    5831                 :          0 :     return PreviousNext( true );
    5832                 :            : }
    5833                 :            : 
    5834                 :            : uno::Reference< excel::XRange > SAL_CALL
    5835                 :          0 : ScVbaRange::SpecialCells( const uno::Any& _oType, const uno::Any& _oValue) throw ( script::BasicErrorException )
    5836                 :            : {
    5837         [ #  # ]:          0 :     bool bIsSingleCell = isSingleCellRange();
    5838 [ #  # ][ #  # ]:          0 :     bool bIsMultiArea = ( m_Areas->getCount() > 1 );
    5839                 :          0 :     ScVbaRange* pRangeToUse = this;
    5840 [ #  # ][ #  # ]:          0 :     uno::Reference< excel::XRange > xUsedRange( getWorksheet()->getUsedRange() );
                 [ #  # ]
    5841                 :          0 :     sal_Int32 nType = 0;
    5842         [ #  # ]:          0 :     if ( !( _oType >>= nType ) )
    5843         [ #  # ]:          0 :         DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() );
    5844      [ #  #  # ]:          0 :     switch(nType)
    5845                 :            :     {
    5846                 :            :         case excel::XlCellType::xlCellTypeSameFormatConditions:
    5847                 :            :         case excel::XlCellType::xlCellTypeAllValidation:
    5848                 :            :         case excel::XlCellType::xlCellTypeSameValidation:
    5849         [ #  # ]:          0 :             DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString());
    5850                 :          0 :             break;
    5851                 :            :         case excel::XlCellType::xlCellTypeBlanks:
    5852                 :            :         case excel::XlCellType::xlCellTypeComments:
    5853                 :            :         case excel::XlCellType::xlCellTypeConstants:
    5854                 :            :         case excel::XlCellType::xlCellTypeFormulas:
    5855                 :            :         case excel::XlCellType::xlCellTypeVisible:
    5856                 :            :         case excel::XlCellType::xlCellTypeLastCell:
    5857                 :            :         {
    5858         [ #  # ]:          0 :             if ( bIsMultiArea )
    5859                 :            :             {
    5860                 :            :                 // need to process each area, gather the results and
    5861                 :            :                 // create a new range from those
    5862         [ #  # ]:          0 :                 std::vector< table::CellRangeAddress > rangeResults;
    5863 [ #  # ][ #  # ]:          0 :                 sal_Int32 nItems = ( m_Areas->getCount() + 1 );
    5864         [ #  # ]:          0 :                 for ( sal_Int32 index=1; index <= nItems; ++index )
    5865                 :            :                 {
    5866 [ #  # ][ #  # ]:          0 :                     uno::Reference< excel::XRange > xRange( m_Areas->Item( uno::makeAny(index), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    5867 [ #  # ][ #  # ]:          0 :                     xRange = xRange->SpecialCells( _oType,  _oValue);
                 [ #  # ]
    5868         [ #  # ]:          0 :                     ScVbaRange* pRange = getImplementation( xRange );
    5869 [ #  # ][ #  # ]:          0 :                     if ( xRange.is() && pRange )
                 [ #  # ]
    5870                 :            :                     {
    5871 [ #  # ][ #  # ]:          0 :                         sal_Int32 nElems = ( pRange->m_Areas->getCount() + 1 );
    5872         [ #  # ]:          0 :                         for ( sal_Int32 nArea = 1; nArea < nElems; ++nArea )
    5873                 :            :                         {
    5874 [ #  # ][ #  # ]:          0 :                             uno::Reference< excel::XRange > xTmpRange( m_Areas->Item( uno::makeAny( nArea ), uno::Any() ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
    5875 [ #  # ][ #  # ]:          0 :                             RangeHelper rHelper( xTmpRange->getCellRange() );
                 [ #  # ]
    5876 [ #  # ][ #  # ]:          0 :                             rangeResults.push_back( rHelper.getCellRangeAddressable()->getRangeAddress() );
         [ #  # ][ #  # ]
    5877         [ #  # ]:          0 :                         }
    5878                 :            :                     }
    5879                 :          0 :                 }
    5880         [ #  # ]:          0 :                 ScRangeList aCellRanges;
    5881                 :          0 :                 std::vector< table::CellRangeAddress >::iterator it = rangeResults.begin();
    5882                 :          0 :                 std::vector< table::CellRangeAddress >::iterator it_end = rangeResults.end();
    5883 [ #  # ][ #  # ]:          0 :                 for ( ; it != it_end; ++ it )
    5884                 :            :                 {
    5885                 :          0 :                     ScRange refRange;
    5886                 :          0 :                     ScUnoConversion::FillScRange( refRange, *it );
    5887         [ #  # ]:          0 :                     aCellRanges.Append( refRange );
    5888                 :            :                 }
    5889                 :            :                 // Single range
    5890 [ #  # ][ #  # ]:          0 :                 if ( aCellRanges.size() == 1 )
    5891                 :            :                 {
    5892 [ #  # ][ #  # ]:          0 :                     uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( getScDocShell(), *aCellRanges.front() ) );
         [ #  # ][ #  # ]
                 [ #  # ]
    5893 [ #  # ][ #  # ]:          0 :                     return new ScVbaRange( mxParent, mxContext, xRange );
         [ #  # ][ #  # ]
    5894                 :            :                 }
    5895 [ #  # ][ #  # ]:          0 :                 uno::Reference< sheet::XSheetCellRangeContainer > xRanges( new ScCellRangesObj( getScDocShell(), aCellRanges ) );
         [ #  # ][ #  # ]
    5896                 :            : 
    5897 [ #  # ][ #  # ]:          0 :                 return new ScVbaRange( mxParent, mxContext, xRanges );
         [ #  # ][ #  # ]
                 [ #  # ]
    5898                 :            :             }
    5899         [ #  # ]:          0 :             else if ( bIsSingleCell )
    5900                 :            :             {
    5901 [ #  # ][ #  # ]:          0 :                 pRangeToUse = static_cast< ScVbaRange* >( xUsedRange.get() );
    5902                 :            :             }
    5903                 :            : 
    5904                 :          0 :             break;
    5905                 :            :         }
    5906                 :            :         default:
    5907         [ #  # ]:          0 :         DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() );
    5908                 :          0 :             break;
    5909                 :            :     }
    5910         [ #  # ]:          0 :     if ( !pRangeToUse )
    5911         [ #  # ]:          0 :         DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() );
    5912         [ #  # ]:          0 :     return pRangeToUse->SpecialCellsImpl( nType, _oValue );
    5913                 :            : }
    5914                 :            : 
    5915                 :          0 : sal_Int32 lcl_getFormulaResultFlags(const uno::Any& aType) throw ( script::BasicErrorException )
    5916                 :            : {
    5917                 :          0 :     sal_Int32 nType = excel::XlSpecialCellsValue::xlNumbers;
    5918                 :          0 :     aType >>= nType;
    5919                 :          0 :     sal_Int32 nRes = sheet::FormulaResult::VALUE;
    5920                 :            : 
    5921   [ #  #  #  #  :          0 :     switch(nType)
                      # ]
    5922                 :            :     {
    5923                 :            :         case excel::XlSpecialCellsValue::xlErrors:
    5924                 :          0 :             nRes= sheet::FormulaResult::ERROR;
    5925                 :          0 :             break;
    5926                 :            :         case excel::XlSpecialCellsValue::xlLogical:
    5927                 :            :             //TODO bc93774: ask NN if this is really an appropriate substitute
    5928                 :          0 :             nRes = sheet::FormulaResult::VALUE;
    5929                 :          0 :             break;
    5930                 :            :         case excel::XlSpecialCellsValue::xlNumbers:
    5931                 :          0 :             nRes = sheet::FormulaResult::VALUE;
    5932                 :          0 :             break;
    5933                 :            :         case excel::XlSpecialCellsValue::xlTextValues:
    5934                 :          0 :             nRes = sheet::FormulaResult::STRING;
    5935                 :          0 :             break;
    5936                 :            :         default:
    5937         [ #  # ]:          0 :             DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() );
    5938                 :            :     }
    5939                 :          0 :     return nRes;
    5940                 :            : }
    5941                 :            : 
    5942                 :            : uno::Reference< excel::XRange >
    5943                 :          0 : ScVbaRange::SpecialCellsImpl( sal_Int32 nType, const uno::Any& _oValue) throw ( script::BasicErrorException )
    5944                 :            : {
    5945                 :          0 :     uno::Reference< excel::XRange > xRange;
    5946                 :            :     try
    5947                 :            :     {
    5948         [ #  # ]:          0 :         uno::Reference< sheet::XCellRangesQuery > xQuery( mxRange, uno::UNO_QUERY_THROW );
    5949                 :          0 :         uno::Reference< excel::XRange > oLocRangeImpl;
    5950                 :          0 :         uno::Reference< sheet::XSheetCellRanges > xLocSheetCellRanges;
    5951   [ #  #  #  #  :          0 :         switch(nType)
             #  #  #  # ]
    5952                 :            :         {
    5953                 :            :             case excel::XlCellType::xlCellTypeAllFormatConditions:
    5954                 :            :             case excel::XlCellType::xlCellTypeSameFormatConditions:
    5955                 :            :             case excel::XlCellType::xlCellTypeAllValidation:
    5956                 :            :             case excel::XlCellType::xlCellTypeSameValidation:
    5957                 :            :                 // Shouldn't get here ( should be filtered out by
    5958                 :            :                 // ScVbaRange::SpecialCells()
    5959         [ #  # ]:          0 :                 DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString());
    5960                 :          0 :                 break;
    5961                 :            :             case excel::XlCellType::xlCellTypeBlanks:
    5962 [ #  # ][ #  # ]:          0 :                 xLocSheetCellRanges = xQuery->queryEmptyCells();
                 [ #  # ]
    5963                 :          0 :                 break;
    5964                 :            :             case excel::XlCellType::xlCellTypeComments:
    5965 [ #  # ][ #  # ]:          0 :                 xLocSheetCellRanges = xQuery->queryContentCells(sheet::CellFlags::ANNOTATION);
                 [ #  # ]
    5966                 :          0 :                 break;
    5967                 :            :             case excel::XlCellType::xlCellTypeConstants:
    5968 [ #  # ][ #  # ]:          0 :                 xLocSheetCellRanges = xQuery->queryContentCells(23);
                 [ #  # ]
    5969                 :          0 :                 break;
    5970                 :            :             case excel::XlCellType::xlCellTypeFormulas:
    5971                 :            :             {
    5972         [ #  # ]:          0 :                 sal_Int32 nFormulaResult = lcl_getFormulaResultFlags(_oValue);
    5973 [ #  # ][ #  # ]:          0 :                 xLocSheetCellRanges = xQuery->queryFormulaCells(nFormulaResult);
                 [ #  # ]
    5974                 :          0 :                 break;
    5975                 :            :             }
    5976                 :            :             case excel::XlCellType::xlCellTypeLastCell:
    5977 [ #  # ][ #  # ]:          0 :                 xRange = Cells( uno::makeAny( getCount() ), uno::Any() );
         [ #  # ][ #  # ]
    5978                 :            :             case excel::XlCellType::xlCellTypeVisible:
    5979 [ #  # ][ #  # ]:          0 :                 xLocSheetCellRanges = xQuery->queryVisibleCells();
                 [ #  # ]
    5980                 :          0 :                 break;
    5981                 :            :             default:
    5982         [ #  # ]:          0 :                 DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() );
    5983                 :          0 :                 break;
    5984                 :            :         }
    5985         [ #  # ]:          0 :         if (xLocSheetCellRanges.is())
    5986                 :            :         {
    5987 [ #  # ][ #  # ]:          0 :             xRange = lcl_makeXRangeFromSheetCellRanges( getParent(), mxContext, xLocSheetCellRanges, getScDocShell() );
         [ #  # ][ #  # ]
    5988                 :          0 :         }
    5989                 :            :     }
    5990   [ #  #  #  # ]:          0 :     catch (uno::Exception& )
    5991                 :            :     {
    5992         [ #  # ]:          0 :         DebugHelper::exception(SbERR_METHOD_FAILED, STR_ERRORMESSAGE_NOCELLSWEREFOUND);
    5993                 :            :     }
    5994                 :          0 :     return xRange;
    5995                 :            : }
    5996                 :            : 
    5997                 :            : void SAL_CALL
    5998                 :          0 : ScVbaRange::RemoveSubtotal(  ) throw (script::BasicErrorException, uno::RuntimeException)
    5999                 :            : {
    6000         [ #  # ]:          0 :     uno::Reference< sheet::XSubTotalCalculatable > xSub( mxRange, uno::UNO_QUERY_THROW );
    6001 [ #  # ][ #  # ]:          0 :     xSub->removeSubTotals();
    6002                 :          0 : }
    6003                 :            : 
    6004                 :            : void SAL_CALL
    6005                 :          0 : ScVbaRange::Subtotal( ::sal_Int32 _nGroupBy, ::sal_Int32 _nFunction, const uno::Sequence< ::sal_Int32 >& _nTotalList, const uno::Any& aReplace, const uno::Any& PageBreaks, const uno::Any& /*SummaryBelowData*/ ) throw (script::BasicErrorException, uno::RuntimeException)
    6006                 :            : {
    6007                 :            :     try
    6008                 :            :     {
    6009                 :          0 :         sal_Bool bDoReplace = false;
    6010                 :          0 :         aReplace >>= bDoReplace;
    6011                 :          0 :         sal_Bool bAddPageBreaks = false;
    6012                 :          0 :         PageBreaks >>= bAddPageBreaks;
    6013                 :            : 
    6014         [ #  # ]:          0 :         uno::Reference< sheet::XSubTotalCalculatable> xSub(mxRange, uno::UNO_QUERY_THROW );
    6015 [ #  # ][ #  # ]:          0 :         uno::Reference< sheet::XSubTotalDescriptor > xSubDesc = xSub->createSubTotalDescriptor(sal_True);
    6016         [ #  # ]:          0 :         uno::Reference< beans::XPropertySet > xSubDescPropertySet( xSubDesc, uno::UNO_QUERY_THROW );
    6017 [ #  # ][ #  # ]:          0 :         xSubDescPropertySet->setPropertyValue(INSERTPAGEBREAKS, uno::makeAny( bAddPageBreaks));
                 [ #  # ]
    6018                 :          0 :         sal_Int32 nLen = _nTotalList.getLength();
    6019         [ #  # ]:          0 :         uno::Sequence< sheet::SubTotalColumn > aColumns( nLen );
    6020         [ #  # ]:          0 :         for (int i = 0; i < nLen; i++)
    6021                 :            :         {
    6022         [ #  # ]:          0 :             aColumns[i].Column = _nTotalList[i] - 1;
    6023   [ #  #  #  #  :          0 :             switch (_nFunction)
          #  #  #  #  #  
             #  #  #  # ]
    6024                 :            :             {
    6025                 :            :                 case excel::XlConsolidationFunction::xlAverage:
    6026         [ #  # ]:          0 :                     aColumns[i].Function = sheet::GeneralFunction_AVERAGE;
    6027                 :          0 :                     break;
    6028                 :            :                 case excel::XlConsolidationFunction::xlCount:
    6029         [ #  # ]:          0 :                     aColumns[i].Function = sheet::GeneralFunction_COUNT;
    6030                 :          0 :                     break;
    6031                 :            :                 case excel::XlConsolidationFunction::xlCountNums:
    6032         [ #  # ]:          0 :                     aColumns[i].Function = sheet::GeneralFunction_COUNTNUMS;
    6033                 :          0 :                     break;
    6034                 :            :                 case excel::XlConsolidationFunction::xlMax:
    6035         [ #  # ]:          0 :                     aColumns[i].Function = sheet::GeneralFunction_MAX;
    6036                 :          0 :                     break;
    6037                 :            :                 case excel::XlConsolidationFunction::xlMin:
    6038         [ #  # ]:          0 :                     aColumns[i].Function = sheet::GeneralFunction_MIN;
    6039                 :          0 :                     break;
    6040                 :            :                 case excel::XlConsolidationFunction::xlProduct:
    6041         [ #  # ]:          0 :                     aColumns[i].Function = sheet::GeneralFunction_PRODUCT;
    6042                 :          0 :                     break;
    6043                 :            :                 case excel::XlConsolidationFunction::xlStDev:
    6044         [ #  # ]:          0 :                     aColumns[i].Function = sheet::GeneralFunction_STDEV;
    6045                 :          0 :                     break;
    6046                 :            :                 case excel::XlConsolidationFunction::xlStDevP:
    6047         [ #  # ]:          0 :                     aColumns[i].Function = sheet::GeneralFunction_STDEVP;
    6048                 :          0 :                     break;
    6049                 :            :                 case excel::XlConsolidationFunction::xlSum:
    6050         [ #  # ]:          0 :                     aColumns[i].Function = sheet::GeneralFunction_SUM;
    6051                 :          0 :                     break;
    6052                 :            :                 case excel::XlConsolidationFunction::xlUnknown:
    6053         [ #  # ]:          0 :                     aColumns[i].Function = sheet::GeneralFunction_NONE;
    6054                 :          0 :                     break;
    6055                 :            :                 case excel::XlConsolidationFunction::xlVar:
    6056         [ #  # ]:          0 :                     aColumns[i].Function = sheet::GeneralFunction_VAR;
    6057                 :          0 :                     break;
    6058                 :            :                 case excel::XlConsolidationFunction::xlVarP:
    6059         [ #  # ]:          0 :                     aColumns[i].Function = sheet::GeneralFunction_VARP;
    6060                 :          0 :                     break;
    6061                 :            :                 default:
    6062         [ #  # ]:          0 :                     DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString()) ;
    6063                 :          0 :                     return;
    6064                 :            :             }
    6065                 :            :         }
    6066 [ #  # ][ #  # ]:          0 :         xSubDesc->addNew(aColumns, _nGroupBy - 1);
    6067 [ #  # ][ #  # ]:          0 :         xSub->applySubTotals(xSubDesc, bDoReplace);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    6068                 :            :     }
    6069         [ #  # ]:          0 :     catch (uno::Exception& )
    6070                 :            :     {
    6071         [ #  # ]:          0 :         DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
    6072                 :            :     }
    6073                 :            : }
    6074                 :            : 
    6075                 :          0 : uno::Any SAL_CALL ScVbaRange::AdvancedFilter( sal_Int32 Action, const uno::Any& CriteriaRange,
    6076                 :            :     const uno::Any& CopyToRange, const uno::Any& Unique ) throw (script::BasicErrorException, uno::RuntimeException)
    6077                 :            : {
    6078                 :          0 :     uno::Any aRet;
    6079         [ #  # ]:          0 :     aRet <<= sal_True;
    6080                 :            : 
    6081         [ #  # ]:          0 :     uno::Reference< script::XTypeConverter > xConverter = getTypeConverter( mxContext );
    6082         [ #  # ]:          0 :     ScDocument* pDoc = getScDocument();
    6083         [ #  # ]:          0 :     if ( !pDoc )
    6084                 :            :     {
    6085         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString(  "Failed to access document from range"  ), uno::Reference< uno::XInterface >() );
    6086                 :            :     }
    6087                 :            : 
    6088                 :            :     // Action
    6089 [ #  # ][ #  # ]:          0 :     if ( Action != excel::XlFilterAction::xlFilterInPlace && Action != excel::XlFilterAction::xlFilterCopy )
    6090                 :            :     {
    6091         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString( "Invalid input parameter"  ), uno::Reference< uno::XInterface >() );
    6092                 :            :     }
    6093 [ #  # ][ #  # ]:          0 :     if ( m_Areas->getCount() > 1 )
                 [ #  # ]
    6094                 :            :     {
    6095         [ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString( "Invalid range"  ), uno::Reference< uno::XInterface >() );
    6096                 :            :     }
    6097                 :            : 
    6098                 :          0 :     sal_Bool bCopyOut = ( Action != excel::XlFilterAction::xlFilterInPlace );
    6099                 :          0 :     uno::Reference< sheet::XSheetFilterDescriptor > xFilterDesc;
    6100         [ #  # ]:          0 :     uno::Reference< sheet::XSheetFilterable > xSheetFilter( mxRange, uno::UNO_QUERY_THROW );
    6101                 :            : 
    6102                 :            :     // CriteriaRange
    6103         [ #  # ]:          0 :     String aBuiltInCriteria; // Excel Built-In Filter Criteria.
    6104                 :          0 :     table::CellRangeAddress refParentAddr;
    6105                 :          0 :     uno::Any aCriteriaRange = CriteriaRange;
    6106                 :          0 :     formula::FormulaGrammar::AddressConvention aConv = formula::FormulaGrammar::CONV_XL_A1;
    6107 [ #  # ][ #  # ]:          0 :     if ( aCriteriaRange.hasValue() &&  aCriteriaRange.getValueTypeClass() == uno::TypeClass_STRING )
                 [ #  # ]
    6108                 :            :     {
    6109                 :          0 :         rtl::OUString rRangeString;
    6110                 :          0 :         aCriteriaRange >>= rRangeString;
    6111 [ #  # ][ #  # ]:          0 :         aConv = excel::IsR1C1ReferFormat( pDoc, rRangeString ) ? formula::FormulaGrammar::CONV_XL_R1C1 : aConv;
    6112                 :            :     }
    6113                 :            :     else
    6114                 :            :     {
    6115                 :            :         // Get Excel BuiltIn Filter Criteria.
    6116         [ #  # ]:          0 :         ScRangeName* pRangeNames = pDoc->GetRangeName();
    6117         [ #  # ]:          0 :         if (pRangeNames)
    6118                 :            :         {
    6119 [ #  # ][ #  # ]:          0 :             ScRangeName::const_iterator itr = pRangeNames->begin(), itrEnd = pRangeNames->end();
         [ #  # ][ #  # ]
    6120 [ #  # ][ #  # ]:          0 :             for (; itr != itrEnd; ++itr)
                 [ #  # ]
    6121                 :            :             {
    6122 [ #  # ][ #  # ]:          0 :                 if (itr->second->HasType(RT_CRITERIA))
    6123                 :            :                 {
    6124 [ #  # ][ #  # ]:          0 :                     itr->second->GetSymbol( aBuiltInCriteria, formula::FormulaGrammar::GRAM_NATIVE_XL_A1 );
    6125                 :          0 :                     break;
    6126                 :            :                 }
    6127                 :            :             }
    6128                 :            :         }
    6129 [ #  # ][ #  # ]:          0 :         aCriteriaRange = aBuiltInCriteria.Len() > 0 ? uno::makeAny( rtl::OUString( aBuiltInCriteria ) ) : aCriteriaRange;
         [ #  # ][ #  # ]
                 [ #  # ]
    6130                 :            :     }
    6131         [ #  # ]:          0 :     if ( aCriteriaRange.hasValue() )
    6132                 :            :     {
    6133 [ #  # ][ #  # ]:          0 :         table::CellRangeAddress criteriaRangeAddress = getCellRangeAddressForVBARange( aCriteriaRange, getScDocShell(), aConv );
    6134                 :          0 :         ScRange refRange;
    6135                 :          0 :         ScUnoConversion::FillScRange( refRange, criteriaRangeAddress );
    6136 [ #  # ][ #  # ]:          0 :         uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( getScDocShell(), refRange ) );
         [ #  # ][ #  # ]
    6137         [ #  # ]:          0 :         uno::Reference< sheet::XSheetFilterableEx > xCriteria( xRange, uno::UNO_QUERY );
    6138         [ #  # ]:          0 :         if ( xCriteria.is() )
    6139                 :            :         {
    6140 [ #  # ][ #  # ]:          0 :             xFilterDesc = xCriteria->createFilterDescriptorByObject( xSheetFilter );
                 [ #  # ]
    6141                 :          0 :         }
    6142                 :            :     }
    6143         [ #  # ]:          0 :     else if ( mxRange.is() )
    6144                 :            :     {
    6145         [ #  # ]:          0 :         uno::Reference< sheet::XSheetFilterableEx > xCriteria( mxRange, uno::UNO_QUERY );
    6146         [ #  # ]:          0 :         if ( xCriteria.is() )
    6147                 :            :         {
    6148 [ #  # ][ #  # ]:          0 :             xFilterDesc = xCriteria->createFilterDescriptorByObject( xSheetFilter );
                 [ #  # ]
    6149                 :          0 :         }
    6150                 :            :     }
    6151                 :            : 
    6152         [ #  # ]:          0 :     uno::Reference< beans::XPropertySet > xPropertySet( xFilterDesc, uno::UNO_QUERY );
    6153         [ #  # ]:          0 :     if ( xPropertySet.is() )
    6154                 :            :     {
    6155 [ #  # ][ #  # ]:          0 :         xPropertySet->setPropertyValue( rtl::OUString(  SC_UNONAME_COPYOUT  ), uno::makeAny( bCopyOut ) );
                 [ #  # ]
    6156                 :            :     }
    6157                 :            : 
    6158                 :            :     // CopyToRange
    6159 [ #  # ][ #  # ]:          0 :     if ( bCopyOut && CopyToRange.hasValue() && xPropertySet.is() )
         [ #  # ][ #  # ]
    6160                 :            :     {
    6161                 :          0 :         formula::FormulaGrammar::AddressConvention aTmpConv = formula::FormulaGrammar::CONV_XL_A1;
    6162         [ #  # ]:          0 :         if ( CopyToRange.getValueTypeClass() == uno::TypeClass_STRING )
    6163                 :            :         {
    6164                 :          0 :             rtl::OUString rRangeString;
    6165                 :          0 :             CopyToRange >>= rRangeString;
    6166 [ #  # ][ #  # ]:          0 :             aTmpConv = excel::IsR1C1ReferFormat( pDoc, rRangeString ) ? formula::FormulaGrammar::CONV_XL_R1C1 : aConv;
    6167                 :            :         }
    6168                 :          0 :         ScRange refRange;
    6169 [ #  # ][ #  # ]:          0 :         ScUnoConversion::FillScRange( refRange, getCellRangeAddressForVBARange( CopyToRange, getScDocShell(), aTmpConv ) );
    6170 [ #  # ][ #  # ]:          0 :         uno::Reference< table::XCellRange > xRange( new ScCellRangeObj( getScDocShell(), refRange ) );
         [ #  # ][ #  # ]
    6171 [ #  # ][ #  # ]:          0 :         uno::Reference< sheet::XCellAddressable > xCellAddr( xRange->getCellByPosition( 0, 0 ), uno::UNO_QUERY_THROW );
                 [ #  # ]
    6172 [ #  # ][ #  # ]:          0 :         xPropertySet->setPropertyValue( rtl::OUString(  SC_UNONAME_OUTPOS  ), uno::makeAny( xCellAddr->getCellAddress() ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    6173                 :            :     }
    6174                 :            : 
    6175                 :            :     // Unique
    6176         [ #  # ]:          0 :     if ( xPropertySet.is() )
    6177                 :            :     {
    6178                 :          0 :         sal_Bool bUnique = false;
    6179                 :          0 :         uno::Any aUnique;
    6180                 :            :         try
    6181                 :            :         {
    6182         [ #  # ]:          0 :             aUnique <<= bUnique;
    6183 [ #  # ][ #  # ]:          0 :             aUnique = ( xConverter.is() && Unique.hasValue() ) ? xConverter->convertTo( Unique, getCppuType( ( sal_Bool* ) 0 ) ) : aUnique;
         [ #  # ][ #  # ]
                 [ #  # ]
    6184                 :            :         }
    6185         [ #  # ]:          0 :         catch( const uno::Exception& )
    6186                 :            :         {
    6187                 :            :         }
    6188 [ #  # ][ #  # ]:          0 :         xPropertySet->setPropertyValue( rtl::OUString(  SC_UNONAME_SKIPDUP  ), aUnique );
    6189                 :            :     }
    6190                 :            : 
    6191                 :            :     // Do filter.
    6192         [ #  # ]:          0 :     if ( xFilterDesc.is() )
    6193                 :            :     {
    6194 [ #  # ][ #  # ]:          0 :         xSheetFilter->filter( xFilterDesc );
    6195                 :            :     }
    6196                 :            : 
    6197         [ #  # ]:          0 :     return aRet;
    6198                 :            : }
    6199                 :            : 
    6200                 :            : //Range.PivotTable.
    6201                 :            : //Returns a PivotTable object that represents the PivotTable report containing the upper-left corner of the specified range.
    6202                 :            : uno::Reference< excel::XPivotTable >
    6203                 :          0 : ScVbaRange::PivotTable() throw (uno::RuntimeException)
    6204                 :            : {
    6205                 :          0 :     uno::Reference< excel::XPivotTable > xDestPVTable;
    6206                 :            : 
    6207                 :          0 :     uno::Reference< sheet::XSpreadsheet > xSheet;
    6208         [ #  # ]:          0 :     if ( mxRange.is() )
    6209                 :            :     {
    6210         [ #  # ]:          0 :         RangeHelper thisRange( mxRange );
    6211 [ #  # ][ #  # ]:          0 :         xSheet = thisRange.getSpreadSheet();
                 [ #  # ]
    6212                 :            :     }
    6213         [ #  # ]:          0 :     else if ( mxRanges.is() )
    6214                 :            :     {
    6215         [ #  # ]:          0 :         uno::Reference< container::XIndexAccess > xIndex( mxRanges, uno::UNO_QUERY_THROW );
    6216 [ #  # ][ #  # ]:          0 :         uno::Reference< table::XCellRange > xRange( xIndex->getByIndex( 0 ), uno::UNO_QUERY_THROW );
                 [ #  # ]
    6217         [ #  # ]:          0 :         RangeHelper thisRange( xRange );
    6218 [ #  # ][ #  # ]:          0 :         xSheet = thisRange.getSpreadSheet();
                 [ #  # ]
    6219                 :            :     }
    6220                 :            : 
    6221         [ #  # ]:          0 :     uno::Reference< sheet::XDataPilotTablesSupplier > xTables(xSheet, uno::UNO_QUERY_THROW ) ;
    6222 [ #  # ][ #  # ]:          0 :     uno::Reference< container::XIndexAccess > xIndexAccess( xTables->getDataPilotTables(), uno::UNO_QUERY_THROW );
                 [ #  # ]
    6223         [ #  # ]:          0 :     if ( xIndexAccess.is() )
    6224                 :            :     {
    6225                 :            :         //get the upper-left cell address
    6226         [ #  # ]:          0 :         table::CellAddress aAddress = getLeftUpperCellAddress();
    6227                 :            : 
    6228 [ #  # ][ #  # ]:          0 :         sal_Int32 nCount = xIndexAccess->getCount();
    6229         [ #  # ]:          0 :         for (sal_Int32 i=0; i < nCount; i++)
    6230                 :            :         {
    6231 [ #  # ][ #  # ]:          0 :             uno::Reference< sheet::XDataPilotTable > xDPTable(xIndexAccess->getByIndex(i), uno::UNO_QUERY);
                 [ #  # ]
    6232         [ #  # ]:          0 :             uno::Reference< sheet::XDataPilotTable2 > xDPTable2(xDPTable, uno::UNO_QUERY);
    6233                 :            : 
    6234                 :            :             //check if the cell is in the pivot table
    6235 [ #  # ][ #  # ]:          0 :             sheet::DataPilotTablePositionData posData = xDPTable2->getPositionData(aAddress);
    6236 [ #  # ][ #  # ]:          0 :             table::CellRangeAddress aCellRangeAddress = xDPTable->getOutputRange();
    6237                 :            :             ScRange aScRange( aCellRangeAddress.StartColumn, aCellRangeAddress.StartRow, aCellRangeAddress.Sheet,
    6238                 :          0 :                 aCellRangeAddress.EndColumn, aCellRangeAddress.EndRow, aCellRangeAddress.Sheet );
    6239                 :          0 :             ScAddress aPos( aAddress.Column, aAddress.Row, aAddress.Sheet );
    6240 [ #  # ][ #  # ]:          0 :             if( !(posData.PositionType == sheet::DataPilotTablePositionType::NOT_IN_TABLE) || aScRange.In( aPos ) )
                 [ #  # ]
    6241                 :            :             {
    6242 [ #  # ][ #  # ]:          0 :                 xDestPVTable = new ScVbaPivotTable( mxContext, xDPTable );
                 [ #  # ]
    6243                 :            :                 break;
    6244                 :            :             }
    6245 [ #  # ][ #  # ]:          0 :         }
                 [ #  # ]
    6246                 :            :     }
    6247                 :          0 :     return xDestPVTable;
    6248                 :            : }
    6249                 :            : 
    6250                 :            : 
    6251                 :            : rtl::OUString
    6252                 :          0 : ScVbaRange::getServiceImplName()
    6253                 :            : {
    6254                 :          0 :     return rtl::OUString("ScVbaRange");
    6255                 :            : }
    6256                 :            : 
    6257                 :            : uno::Sequence< rtl::OUString >
    6258                 :          0 : ScVbaRange::getServiceNames()
    6259                 :            : {
    6260 [ #  # ][ #  # ]:          0 :     static uno::Sequence< rtl::OUString > aServiceNames;
         [ #  # ][ #  # ]
    6261         [ #  # ]:          0 :     if ( aServiceNames.getLength() == 0 )
    6262                 :            :     {
    6263                 :          0 :         aServiceNames.realloc( 1 );
    6264         [ #  # ]:          0 :         aServiceNames[ 0 ] = rtl::OUString( "ooo.vba.excel.Range"  );
    6265                 :            :     }
    6266                 :          0 :     return aServiceNames;
    6267                 :            : }
    6268                 :            : 
    6269                 :            : sal_Bool SAL_CALL
    6270                 :          0 : ScVbaRange::hasError() throw (uno::RuntimeException)
    6271                 :            : {
    6272                 :          0 :     double dResult = false;
    6273 [ #  # ][ #  # ]:          0 :     uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
    6274 [ #  # ][ #  # ]:          0 :     uno::Reference< script::XInvocation > xInvoc( xApplication->WorksheetFunction(), uno::UNO_QUERY_THROW );
                 [ #  # ]
    6275                 :            : 
    6276 [ #  # ][ #  # ]:          0 :     static rtl::OUString FunctionName( "IsError" );
    6277         [ #  # ]:          0 :     uno::Sequence< uno::Any > Params(1);
    6278         [ #  # ]:          0 :     uno::Reference< excel::XRange > aRange( this );
    6279 [ #  # ][ #  # ]:          0 :     Params[0] = uno::makeAny( aRange );
    6280         [ #  # ]:          0 :     uno::Sequence< sal_Int16 > OutParamIndex;
    6281         [ #  # ]:          0 :     uno::Sequence< uno::Any > OutParam;
    6282 [ #  # ][ #  # ]:          0 :     xInvoc->invoke( FunctionName, Params, OutParamIndex, OutParam ) >>= dResult;
    6283         [ #  # ]:          0 :     if ( dResult > 0.0 )
    6284                 :          0 :          return sal_True;
    6285 [ #  # ][ #  # ]:          0 :     return false;
                 [ #  # ]
    6286                 :            : }
    6287                 :            : 
    6288                 :            : namespace range
    6289                 :            : {
    6290                 :            : namespace sdecl = comphelper::service_decl;
    6291                 :          3 : sdecl::vba_service_class_<ScVbaRange, sdecl::with_args<true> > serviceImpl;
    6292                 :          3 : extern sdecl::ServiceDecl const serviceDecl(
    6293                 :            :     serviceImpl,
    6294                 :            :     "SvVbaRange",
    6295                 :            :     "ooo.vba.excel.Range" );
    6296 [ +  - ][ +  - ]:          9 : }
    6297                 :            : 
    6298                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10