LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/vba - vbastyles.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 64 0.0 %
Date: 2012-12-27 Functions: 0 17 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 "vbastyles.hxx"
      20             : #include "vbastyle.hxx"
      21             : #include <ooo/vba/excel/XRange.hpp>
      22             : 
      23             : using namespace ::ooo::vba;
      24             : using namespace ::com::sun::star;
      25             : 
      26           0 : static rtl::OUString SDEFAULTCELLSTYLENAME( RTL_CONSTASCII_USTRINGPARAM("Default") );
      27             : static css::uno::Any
      28           0 : lcl_createAPIStyleToVBAObject( const css::uno::Any& aObject, const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel )
      29             : {
      30           0 :     uno::Reference< beans::XPropertySet > xStyleProps( aObject, uno::UNO_QUERY_THROW );
      31           0 :     uno::Reference< excel::XStyle > xStyle( new ScVbaStyle( xParent, xContext, xStyleProps, xModel ) );
      32           0 :     return uno::makeAny( xStyle );
      33             : }
      34             : 
      35             : 
      36           0 : ScVbaStyles::ScVbaStyles( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< css::uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel ) throw ( script::BasicErrorException ) : ScVbaStyles_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( ScVbaStyle::getStylesNameContainer( xModel ), uno::UNO_QUERY_THROW ) ), mxModel( xModel ), mxParent( xParent )
      37             : {
      38             :     try
      39             :     {
      40           0 :         mxMSF.set( mxModel, uno::UNO_QUERY_THROW );
      41           0 :         mxNameContainerCellStyles.set( m_xNameAccess, uno::UNO_QUERY_THROW );
      42             :     }
      43           0 :     catch (uno::Exception& )
      44             :     {
      45           0 :         DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
      46             :     }
      47           0 : }
      48             : 
      49             : uno::Sequence< rtl::OUString >
      50           0 : ScVbaStyles::getStyleNames() throw ( uno::RuntimeException )
      51             : {
      52           0 :     return mxNameContainerCellStyles->getElementNames();
      53             : }
      54             : 
      55             : 
      56             : uno::Any
      57           0 : ScVbaStyles::createCollectionObject(const uno::Any& aObject)
      58             : {
      59           0 :     return lcl_createAPIStyleToVBAObject( aObject, mxParent, mxContext, mxModel );
      60             : }
      61             : 
      62             : uno::Type SAL_CALL
      63           0 : ScVbaStyles::getElementType() throw (uno::RuntimeException)
      64             : {
      65           0 :     return excel::XStyle::static_type(0);
      66             : }
      67             : 
      68           0 : class EnumWrapper : public EnumerationHelper_BASE
      69             : {
      70             :         uno::Reference<container::XIndexAccess > m_xIndexAccess;
      71             :         uno::Reference<XHelperInterface > m_xParent;
      72             :         uno::Reference<uno::XComponentContext > m_xContext;
      73             :         uno::Reference<frame::XModel > m_xModel;
      74             : 
      75             :         sal_Int32 nIndex;
      76             : public:
      77           0 :         EnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess, const uno::Reference<XHelperInterface >& xParent, const uno::Reference<uno::XComponentContext >& xContext, const uno::Reference<frame::XModel >& xModel ) : m_xIndexAccess( xIndexAccess ), m_xParent( xParent ), m_xContext( xContext ), m_xModel( xModel ), nIndex( 0 ) {}
      78           0 :         virtual ::sal_Bool SAL_CALL hasMoreElements(  ) throw (uno::RuntimeException)
      79             :         {
      80           0 :                 return ( nIndex < m_xIndexAccess->getCount() );
      81             :         }
      82           0 :         virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
      83             :         {
      84           0 :                 if ( nIndex < m_xIndexAccess->getCount() )
      85           0 :                         return lcl_createAPIStyleToVBAObject( m_xIndexAccess->getByIndex( nIndex++ ), m_xParent, m_xContext, m_xModel );
      86           0 :                 throw container::NoSuchElementException();
      87             :         }
      88             : };
      89             : 
      90             : uno::Reference< container::XEnumeration > SAL_CALL
      91           0 : ScVbaStyles::createEnumeration() throw (uno::RuntimeException)
      92             : {
      93           0 :     return new EnumWrapper( m_xIndexAccess, mxParent, mxContext, mxModel );
      94             : }
      95             : 
      96             : uno::Reference< excel::XStyle > SAL_CALL
      97           0 : ScVbaStyles::Add( const ::rtl::OUString& _sName, const uno::Any& _aBasedOn ) throw (script::BasicErrorException, uno::RuntimeException)
      98             : {
      99           0 :     uno::Reference< excel::XStyle > aRet;
     100             :     try
     101             :     {
     102           0 :         rtl::OUString sParentCellStyleName( RTL_CONSTASCII_USTRINGPARAM("Default"));
     103           0 :         if ( _aBasedOn.hasValue() )
     104             :         {
     105           0 :             uno::Reference< excel::XRange > oRange;
     106           0 :             if ( _aBasedOn >>= oRange)
     107             :             {
     108           0 :                 uno::Reference< excel::XStyle > oStyle( oRange->getStyle(), uno::UNO_QUERY_THROW );
     109           0 :                 if ( oStyle.is() )
     110             :                 {
     111           0 :                     sParentCellStyleName = oStyle->getName();
     112             :                 }
     113             :                 else
     114             :                 {
     115           0 :                     DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString() );
     116           0 :                 }
     117             :             }
     118             :             else
     119             :             {
     120           0 :                 DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString());
     121           0 :             }
     122             :         }
     123             : 
     124           0 :         uno::Reference< style::XStyle > xStyle( mxMSF->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.style.CellStyle"))), uno::UNO_QUERY_THROW );
     125             : 
     126           0 :         if (!mxNameContainerCellStyles->hasByName(_sName))
     127             :         {
     128           0 :             mxNameContainerCellStyles->insertByName(_sName, uno::makeAny( xStyle) );
     129             :         }
     130           0 :         if (!sParentCellStyleName.equals(SDEFAULTCELLSTYLENAME))
     131             :         {
     132           0 :             xStyle->setParentStyle( sParentCellStyleName );
     133             :         }
     134           0 :         aRet.set( Item( uno::makeAny( _sName ), uno::Any() ), uno::UNO_QUERY_THROW );
     135             :     }
     136           0 :     catch (uno::Exception& )
     137             :     {
     138           0 :         DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
     139             :     }
     140           0 :     return aRet;
     141             : }
     142             : 
     143             : void
     144           0 : ScVbaStyles::Delete(const rtl::OUString _sStyleName) throw ( script::BasicErrorException )
     145             : {
     146             :     try
     147             :     {
     148           0 :         if (mxNameContainerCellStyles->hasByName( _sStyleName ) )
     149           0 :             mxNameContainerCellStyles->removeByName( _sStyleName );
     150             :     }
     151           0 :     catch (uno::Exception& )
     152             :     {
     153           0 :         DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
     154             :     }
     155           0 : }
     156             : 
     157             : rtl::OUString
     158           0 : ScVbaStyles::getServiceImplName()
     159             : {
     160           0 :     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScVbaStyles"));
     161             : }
     162             : 
     163             : uno::Sequence< rtl::OUString >
     164           0 : ScVbaStyles::getServiceNames()
     165             : {
     166           0 :         static uno::Sequence< rtl::OUString > aServiceNames;
     167           0 :         if ( aServiceNames.getLength() == 0 )
     168             :         {
     169           0 :                 aServiceNames.realloc( 1 );
     170           0 :                 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.XStyles" ) );
     171             :         }
     172           0 :         return aServiceNames;
     173           0 : }
     174             : 
     175             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10