LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/vba - vbaname.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 52 93 55.9 %
Date: 2013-07-09 Functions: 14 29 48.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : #include <vbahelper/helperdecl.hxx>
      20             : 
      21             : #include <com/sun/star/table/XCellRange.hpp>
      22             : #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
      23             : #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
      24             : 
      25             : #include "vbaname.hxx"
      26             : #include "vbarange.hxx"
      27             : #include "vbaglobals.hxx"
      28             : #include <vector>
      29             : #include <rangenam.hxx>
      30             : #include <vcl/msgbox.hxx>
      31             : #include "tabvwsh.hxx"
      32             : #include "viewdata.hxx"
      33             : #include "nameuno.hxx"
      34             : #include "compiler.hxx"
      35             : #include "tokenarray.hxx"
      36             : 
      37             : using namespace ::ooo::vba;
      38             : using namespace ::com::sun::star;
      39             : 
      40          12 : ScVbaName::ScVbaName(const css::uno::Reference< ov::XHelperInterface >& xParent,
      41             :             const css::uno::Reference< css::uno::XComponentContext >& xContext,
      42             :             const css::uno::Reference< css::sheet::XNamedRange >& xName,
      43             :             const css::uno::Reference< css::sheet::XNamedRanges >& xNames,
      44             :             const css::uno::Reference< css::frame::XModel >& xModel ):
      45             :             NameImpl_BASE(  xParent , xContext ),
      46             :             mxModel( xModel ),
      47             :             mxNamedRange( xName ),
      48          12 :             mxNames( xNames )
      49             : {
      50          12 : }
      51             : 
      52          24 : ScVbaName::~ScVbaName()
      53             : {
      54          24 : }
      55             : 
      56             : css::uno::Reference< ov::excel::XWorksheet >
      57           0 : ScVbaName::getWorkSheet() throw (css::uno::RuntimeException)
      58             : {
      59           0 :     uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
      60           0 :     return xApplication->getActiveSheet();
      61             : }
      62             : 
      63             : OUString
      64           3 : ScVbaName::getName() throw (css::uno::RuntimeException)
      65             : {
      66           3 :     return mxNamedRange->getName();
      67             : }
      68             : 
      69             : void
      70           0 : ScVbaName::setName( const OUString & rName ) throw (css::uno::RuntimeException)
      71             : {
      72           0 :     mxNamedRange->setName( rName );
      73           0 : }
      74             : 
      75             : OUString
      76           0 : ScVbaName::getNameLocal() throw (css::uno::RuntimeException)
      77             : {
      78           0 :     return getName();
      79             : }
      80             : 
      81             : void
      82           0 : ScVbaName::setNameLocal( const OUString & rName ) throw (css::uno::RuntimeException)
      83             : {
      84           0 :     setName( rName );
      85           0 : }
      86             : 
      87             : sal_Bool
      88           0 : ScVbaName::getVisible() throw (css::uno::RuntimeException)
      89             : {
      90           0 :     return true;
      91             : }
      92             : 
      93             : void
      94           0 : ScVbaName::setVisible( sal_Bool /*bVisible*/ ) throw (css::uno::RuntimeException)
      95             : {
      96           0 : }
      97             : 
      98           7 : OUString ScVbaName::getContent( const formula::FormulaGrammar::Grammar eGrammar, bool bPrependEquals )
      99             : {
     100           7 :     ScNamedRangeObj* pNamedRange = dynamic_cast< ScNamedRangeObj* >( mxNamedRange.get() );
     101           7 :     OUString aContent;
     102           7 :     if ( pNamedRange )
     103             :     {
     104           7 :         ScRangeData* pData = pNamedRange->GetRangeData_Impl();
     105           7 :         if (pData)
     106           7 :             pData->GetSymbol( aContent, eGrammar );
     107             :     }
     108           7 :     if ( bPrependEquals )
     109             :     {
     110           7 :         if (aContent.indexOf('=') != 0)
     111           7 :             aContent = "=" + aContent;
     112             :     }
     113           7 :     return aContent;
     114             : }
     115             : 
     116           1 : void  ScVbaName::setContent( const OUString& rContent, const formula::FormulaGrammar::Grammar eGrammar, bool bRemoveEquals )
     117             : {
     118           1 :     OUString sContent( rContent );
     119           1 :     if ( bRemoveEquals )
     120             :     {
     121           1 :         if (sContent.indexOf('=') == 0)
     122           1 :             sContent = sContent.copy(1);
     123             :     }
     124           1 :     ScNamedRangeObj* pNamedRange = dynamic_cast< ScNamedRangeObj* >( mxNamedRange.get() );
     125             : 
     126             :     // We should be able to do the below by just setting calling SetCode on pNamedRange
     127             :     // right?
     128           1 :     if ( pNamedRange && pNamedRange->pDocShell )
     129             :     {
     130             : 
     131           1 :         ScDocument* pDoc = pNamedRange->pDocShell->GetDocument();
     132           1 :         ScRangeData* pOldData = pNamedRange->GetRangeData_Impl();
     133           1 :         if (pOldData)
     134             :         {
     135             :             // Shorter way of doing this ?
     136           1 :             ScCompiler aComp( pDoc, pOldData->GetPos() );
     137           1 :             aComp.SetGrammar( eGrammar );
     138           2 :             ScTokenArray aArray(*aComp.CompileString( sContent ) );
     139           2 :             pOldData->SetCode( aArray );
     140             :         }
     141           1 :     }
     142           1 : }
     143             : 
     144             : OUString
     145           4 : ScVbaName::getValue() throw (css::uno::RuntimeException)
     146             : {
     147           4 :     rtl::OUString sResult = getContent( formula::FormulaGrammar::GRAM_NATIVE_XL_A1, true );
     148             : 
     149           4 :     return sResult;
     150             : }
     151             : 
     152             : void
     153           0 : ScVbaName::setValue( const OUString & rValue ) throw (css::uno::RuntimeException)
     154             : {
     155           0 :     setContent( rValue, formula::FormulaGrammar::GRAM_NATIVE_XL_A1, true );
     156           0 : }
     157             : 
     158             : OUString
     159           4 : ScVbaName::getRefersTo() throw (css::uno::RuntimeException)
     160             : {
     161           4 :     return getValue();
     162             : }
     163             : 
     164             : void
     165           0 : ScVbaName::setRefersTo( const OUString & rRefersTo ) throw (css::uno::RuntimeException)
     166             : {
     167           0 :     setValue( rRefersTo );
     168           0 : }
     169             : 
     170             : OUString
     171           0 : ScVbaName::getRefersToLocal() throw (css::uno::RuntimeException)
     172             : {
     173           0 :     return getRefersTo();
     174             : }
     175             : 
     176             : void
     177           0 : ScVbaName::setRefersToLocal( const OUString & rRefersTo ) throw (css::uno::RuntimeException)
     178             : {
     179           0 :     setRefersTo( rRefersTo );
     180           0 : }
     181             : 
     182             : OUString
     183           3 : ScVbaName::getRefersToR1C1() throw (css::uno::RuntimeException)
     184             : {
     185           3 :     rtl::OUString sResult = getContent( formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1, true );
     186           3 :     return  sResult;
     187             : }
     188             : 
     189             : void
     190           1 : ScVbaName::setRefersToR1C1( const OUString & rRefersTo ) throw (css::uno::RuntimeException)
     191             : {
     192           1 :     setContent( rRefersTo, formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1, true );
     193           1 : }
     194             : 
     195             : OUString
     196           0 : ScVbaName::getRefersToR1C1Local() throw (css::uno::RuntimeException)
     197             : {
     198           0 :     return getRefersToR1C1();
     199             : }
     200             : 
     201             : void
     202           0 : ScVbaName::setRefersToR1C1Local( const OUString & rRefersTo ) throw (css::uno::RuntimeException)
     203             : {
     204           0 :     setRefersTo( rRefersTo );
     205           0 : }
     206             : 
     207             : css::uno::Reference< ov::excel::XRange >
     208           3 : ScVbaName::getRefersToRange() throw (css::uno::RuntimeException)
     209             : {
     210             :     uno::Reference< ov::excel::XRange > xRange = ScVbaRange::getRangeObjectForName(
     211           3 :         mxContext, mxNamedRange->getName(), excel::getDocShell( mxModel ), formula::FormulaGrammar::CONV_XL_R1C1 );
     212           3 :     return xRange;
     213             : }
     214             : 
     215             : void
     216           0 : ScVbaName::setRefersToRange( const css::uno::Reference< ov::excel::XRange > /*rRange*/ ) throw (css::uno::RuntimeException)
     217             : {
     218           0 : }
     219             : 
     220             : void
     221           5 : ScVbaName::Delete() throw (css::uno::RuntimeException)
     222             : {
     223           5 :     mxNames->removeByName( mxNamedRange->getName() );
     224           5 : }
     225             : 
     226             : OUString
     227           0 : ScVbaName::getServiceImplName()
     228             : {
     229           0 :     return OUString( "ScVbaName" );
     230             : }
     231             : 
     232             : uno::Sequence< OUString >
     233           0 : ScVbaName::getServiceNames()
     234             : {
     235           0 :     static uno::Sequence< OUString > aServiceNames;
     236           0 :     if ( aServiceNames.getLength() == 0 )
     237             :     {
     238           0 :         aServiceNames.realloc( 1 );
     239           0 :         aServiceNames[ 0 ] = OUString( "ooo.vba.excel.Name" );
     240             :     }
     241           0 :     return aServiceNames;
     242           6 : }
     243             : 
     244             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10