LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/vba - vbaname.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 117 0.0 %
Date: 2012-12-27 Functions: 0 27 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : #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             : 
      34             : using namespace ::ooo::vba;
      35             : using namespace ::com::sun::star;
      36             : 
      37           0 : ScVbaName::ScVbaName(const css::uno::Reference< ov::XHelperInterface >& xParent,
      38             :             const css::uno::Reference< css::uno::XComponentContext >& xContext,
      39             :             const css::uno::Reference< css::sheet::XNamedRange >& xName,
      40             :             const css::uno::Reference< css::sheet::XNamedRanges >& xNames,
      41             :             const css::uno::Reference< css::frame::XModel >& xModel ):
      42             :             NameImpl_BASE(  xParent , xContext ),
      43             :             mxModel( xModel ),
      44             :             mxNamedRange( xName ),
      45           0 :             mxNames( xNames )
      46             : {
      47           0 : }
      48             : 
      49           0 : ScVbaName::~ScVbaName()
      50             : {
      51           0 : }
      52             : 
      53             : css::uno::Reference< ov::excel::XWorksheet >
      54           0 : ScVbaName::getWorkSheet() throw (css::uno::RuntimeException)
      55             : {
      56           0 :     uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW );
      57           0 :     return xApplication->getActiveSheet();
      58             : }
      59             : 
      60             : ::rtl::OUString
      61           0 : ScVbaName::getName() throw (css::uno::RuntimeException)
      62             : {
      63           0 :     String sName;
      64           0 :     sName += UniString ( mxNamedRange->getName() );
      65           0 :     return ::rtl::OUString( sName );
      66             : }
      67             : 
      68             : void
      69           0 : ScVbaName::setName( const ::rtl::OUString & rName ) throw (css::uno::RuntimeException)
      70             : {
      71           0 :     mxNamedRange->setName( rName );
      72           0 : }
      73             : 
      74             : ::rtl::OUString
      75           0 : ScVbaName::getNameLocal() throw (css::uno::RuntimeException)
      76             : {
      77           0 :     return getName();
      78             : }
      79             : 
      80             : void
      81           0 : ScVbaName::setNameLocal( const ::rtl::OUString & rName ) throw (css::uno::RuntimeException)
      82             : {
      83           0 :     setName( rName );
      84           0 : }
      85             : 
      86             : sal_Bool
      87           0 : ScVbaName::getVisible() throw (css::uno::RuntimeException)
      88             : {
      89           0 :     return true;
      90             : }
      91             : 
      92             : void
      93           0 : ScVbaName::setVisible( sal_Bool /*bVisible*/ ) throw (css::uno::RuntimeException)
      94             : {
      95           0 : }
      96             : 
      97             : ::rtl::OUString
      98           0 : ScVbaName::getValue() throw (css::uno::RuntimeException)
      99             : {
     100           0 :     ::rtl::OUString sValue = mxNamedRange->getContent();
     101           0 :     ::rtl::OUString sSheetName = getWorkSheet()->getName();
     102           0 :     ::rtl::OUString sSegmentation = ::rtl::OUString::createFromAscii( ";" );
     103           0 :     ::rtl::OUString sNewSegmentation = ::rtl::OUString::createFromAscii( "," );
     104           0 :     ::rtl::OUString sResult;
     105           0 :     sal_Int32 nFrom = 0;
     106           0 :     sal_Int32 nTo = 0;
     107           0 :     nTo = sValue.indexOf( sSegmentation, nFrom );
     108           0 :     while ( nTo != -1 )
     109             :     {
     110           0 :         ::rtl::OUString sTmpValue = sValue.copy( nFrom, nTo - nFrom );
     111           0 :         if ( sTmpValue.toChar() == '$' )
     112             :         {
     113           0 :             ::rtl::OUString sTmp = sTmpValue.copy( 1 );
     114           0 :             sTmp = sTmp.replaceAt(0, OUString(sSheetName + ::rtl::OUString::createFromAscii(".")).getLength(), sSheetName + ::rtl::OUString::createFromAscii("!"));
     115           0 :             sResult += sTmp;
     116           0 :             sResult += sNewSegmentation;
     117             :         }
     118           0 :         nFrom = nTo + 1;
     119           0 :         nTo = sValue.indexOf( sSegmentation, nFrom );
     120           0 :     }
     121           0 :     ::rtl::OUString sTmpValue = sValue.copy( nFrom );
     122           0 :     if ( sTmpValue.toChar() == '$' )
     123             :     {
     124           0 :         ::rtl::OUString sTmp = sTmpValue.copy(1);
     125           0 :         sTmp = sTmp.replaceAt(0, OUString(sSheetName + ::rtl::OUString::createFromAscii(".")).getLength(), sSheetName + ::rtl::OUString::createFromAscii("!"));
     126           0 :         sResult += sTmp;
     127             :     }
     128           0 :     if (sResult.indexOf('=') != 0)
     129             :     {
     130           0 :         sResult = ::rtl::OUString::createFromAscii("=") + sResult;
     131             :     }
     132           0 :     return sResult;
     133             : }
     134             : 
     135             : void
     136           0 : ScVbaName::setValue( const ::rtl::OUString & rValue ) throw (css::uno::RuntimeException)
     137             : {
     138           0 :     ::rtl::OUString sSheetName = getWorkSheet()->getName();
     139           0 :     ::rtl::OUString sValue = rValue;
     140           0 :     ::rtl::OUString sSegmentation = ::rtl::OUString::createFromAscii( "," );
     141           0 :     ::rtl::OUString sNewSegmentation = ::rtl::OUString::createFromAscii( ";" );
     142           0 :     ::rtl::OUString sResult;
     143           0 :     sal_Int32 nFrom = 0;
     144           0 :     sal_Int32 nTo = 0;
     145           0 :     if (sValue.indexOf('=') == 0)
     146             :     {
     147           0 :         ::rtl::OUString sTmp = sValue.copy(1);
     148           0 :         sValue = sTmp;
     149             :     }
     150           0 :     nTo = sValue.indexOf( sSegmentation, nFrom );
     151           0 :     while ( nTo != -1 )
     152             :     {
     153           0 :         ::rtl::OUString sTmpValue = sValue.copy( nFrom, nTo - nFrom );
     154           0 :         sTmpValue = sTmpValue.replaceAt(0, OUString(sSheetName + ::rtl::OUString::createFromAscii("!")).getLength(), sSheetName + ::rtl::OUString::createFromAscii("."));
     155           0 :         if (sTmpValue.copy(0, sSheetName.getLength()).equals(sSheetName))
     156             :         {
     157           0 :             sTmpValue = ::rtl::OUString::createFromAscii("$") + sTmpValue;
     158             :         }
     159           0 :         sTmpValue += sNewSegmentation;
     160           0 :         sResult += sTmpValue;
     161           0 :         nFrom = nTo + 1;
     162           0 :         nTo = sValue.indexOf( sSegmentation, nFrom );
     163           0 :     }
     164           0 :     ::rtl::OUString sTmpValue = sValue.copy( nFrom );
     165           0 :     sTmpValue = sTmpValue.replaceAt(0, OUString(sSheetName + ::rtl::OUString::createFromAscii("!")).getLength(), sSheetName + ::rtl::OUString::createFromAscii("."));
     166           0 :     if (sTmpValue.copy(0, sSheetName.getLength()).equals(sSheetName))
     167             :     {
     168           0 :         sTmpValue = ::rtl::OUString::createFromAscii("$") + sTmpValue;
     169             :     }
     170           0 :     sResult += sTmpValue;
     171           0 :     mxNamedRange->setContent(sResult);
     172           0 : }
     173             : 
     174             : ::rtl::OUString
     175           0 : ScVbaName::getRefersTo() throw (css::uno::RuntimeException)
     176             : {
     177           0 :     return getValue();
     178             : }
     179             : 
     180             : void
     181           0 : ScVbaName::setRefersTo( const ::rtl::OUString & rRefersTo ) throw (css::uno::RuntimeException)
     182             : {
     183           0 :     setValue( rRefersTo );
     184           0 : }
     185             : 
     186             : ::rtl::OUString
     187           0 : ScVbaName::getRefersToLocal() throw (css::uno::RuntimeException)
     188             : {
     189           0 :     return getRefersTo();
     190             : }
     191             : 
     192             : void
     193           0 : ScVbaName::setRefersToLocal( const ::rtl::OUString & rRefersTo ) throw (css::uno::RuntimeException)
     194             : {
     195           0 :     setRefersTo( rRefersTo );
     196           0 : }
     197             : 
     198             : ::rtl::OUString
     199           0 : ScVbaName::getRefersToR1C1() throw (css::uno::RuntimeException)
     200             : {
     201           0 :     return getRefersTo();
     202             : }
     203             : 
     204             : void
     205           0 : ScVbaName::setRefersToR1C1( const ::rtl::OUString & rRefersTo ) throw (css::uno::RuntimeException)
     206             : {
     207           0 :     setRefersTo( rRefersTo );
     208           0 : }
     209             : 
     210             : ::rtl::OUString
     211           0 : ScVbaName::getRefersToR1C1Local() throw (css::uno::RuntimeException)
     212             : {
     213           0 :     return getRefersTo();
     214             : }
     215             : 
     216             : void
     217           0 : ScVbaName::setRefersToR1C1Local( const ::rtl::OUString & rRefersTo ) throw (css::uno::RuntimeException)
     218             : {
     219           0 :     setRefersTo( rRefersTo );
     220           0 : }
     221             : 
     222             : css::uno::Reference< ov::excel::XRange >
     223           0 : ScVbaName::getRefersToRange() throw (css::uno::RuntimeException)
     224             : {
     225             :     uno::Reference< ov::excel::XRange > xRange = ScVbaRange::getRangeObjectForName(
     226           0 :         mxContext, mxNamedRange->getName(), excel::getDocShell( mxModel ), formula::FormulaGrammar::CONV_XL_R1C1 );
     227           0 :     return xRange;
     228             : }
     229             : 
     230             : void
     231           0 : ScVbaName::setRefersToRange( const css::uno::Reference< ov::excel::XRange > /*rRange*/ ) throw (css::uno::RuntimeException)
     232             : {
     233           0 : }
     234             : 
     235             : void
     236           0 : ScVbaName::Delete() throw (css::uno::RuntimeException)
     237             : {
     238           0 :     mxNames->removeByName( mxNamedRange->getName() );
     239           0 : }
     240             : 
     241             : rtl::OUString
     242           0 : ScVbaName::getServiceImplName()
     243             : {
     244           0 :     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScVbaName"));
     245             : }
     246             : 
     247             : uno::Sequence< rtl::OUString >
     248           0 : ScVbaName::getServiceNames()
     249             : {
     250           0 :     static uno::Sequence< rtl::OUString > aServiceNames;
     251           0 :     if ( aServiceNames.getLength() == 0 )
     252             :     {
     253           0 :         aServiceNames.realloc( 1 );
     254           0 :         aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Name" ) );
     255             :     }
     256           0 :     return aServiceNames;
     257           0 : }
     258             : 
     259             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10