LCOV - code coverage report
Current view: top level - sc/source/ui/vba - vbaformatcondition.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 69 1.4 %
Date: 2014-11-03 Functions: 2 18 11.1 %
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 "vbaformatcondition.hxx"
      20             : #include "vbaformatconditions.hxx"
      21             : #include <ooo/vba/excel/XlFormatConditionType.hpp>
      22             : 
      23             : using namespace ::ooo::vba;
      24             : using namespace ::com::sun::star;
      25             : 
      26             : static ScVbaFormatConditions*
      27           0 : lcl_getScVbaFormatConditionsPtr( const uno::Reference< excel::XFormatConditions >& xFormatConditions ) throw ( script::BasicErrorException )
      28             : {
      29           0 :     ScVbaFormatConditions* pFormatConditions = static_cast< ScVbaFormatConditions* >( xFormatConditions.get() );
      30           0 :     if ( !pFormatConditions )
      31           0 :         DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString() );
      32           0 :     return pFormatConditions;
      33             : }
      34             : 
      35           0 : ScVbaFormatCondition::ScVbaFormatCondition( const uno::Reference< XHelperInterface >& xParent,
      36             :                                             const uno::Reference< uno::XComponentContext > & xContext,
      37             :                                             const uno::Reference< sheet::XSheetConditionalEntry >& _xSheetConditionalEntry,
      38             :                                             const uno::Reference< excel::XStyle >& _xStyle,
      39             :                                             const uno::Reference< excel::XFormatConditions >& _xFormatConditions,
      40             :                                             const uno::Reference< css::beans::XPropertySet >& _xPropertySet ) throw ( css::uno::RuntimeException, css::script::BasicErrorException )
      41             :     : ScVbaFormatCondition_BASE( xParent, xContext,
      42             :                                  uno::Reference< sheet::XSheetCondition >( _xSheetConditionalEntry, css::uno::UNO_QUERY_THROW ) ),
      43           0 :                                  moFormatConditions( _xFormatConditions ), mxStyle( _xStyle ), mxParentRangePropertySet( _xPropertySet )
      44             : {
      45           0 :         mxSheetConditionalEntries = lcl_getScVbaFormatConditionsPtr( moFormatConditions )->getSheetConditionalEntries();
      46             : 
      47           0 :         mxSheetConditionalEntry = _xSheetConditionalEntry;
      48           0 :         msStyleName = mxStyle->getName();
      49           0 : }
      50             : 
      51             : void SAL_CALL
      52           0 : ScVbaFormatCondition::Delete(  ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
      53             : {
      54           0 :     ScVbaFormatConditions* pFormatConditions = lcl_getScVbaFormatConditionsPtr( moFormatConditions );
      55           0 :     pFormatConditions->removeFormatCondition(msStyleName, true);
      56           0 :         notifyRange();
      57           0 : }
      58             : 
      59             : void SAL_CALL
      60           0 : ScVbaFormatCondition::Modify( ::sal_Int32 _nType, const uno::Any& _aOperator, const uno::Any& _aFormula1, const uno::Any& _aFormula2 ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
      61             : {
      62             :     try
      63             :     {
      64           0 :         ScVbaFormatConditions* pFormatConditions = lcl_getScVbaFormatConditionsPtr( moFormatConditions );
      65           0 :         pFormatConditions->removeFormatCondition(msStyleName, false);
      66           0 :         pFormatConditions->Add(_nType, _aOperator, _aFormula1, _aFormula2, mxStyle);
      67             :     }
      68           0 :     catch (const uno::Exception&)
      69             :     {
      70           0 :         DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString() );
      71             :     }
      72           0 : }
      73             : 
      74             : uno::Reference< excel::XInterior > SAL_CALL
      75           0 : ScVbaFormatCondition::Interior(  ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
      76             : {
      77           0 :     return mxStyle->Interior();
      78             : }
      79             : 
      80             : uno::Reference< excel::XFont > SAL_CALL
      81           0 : ScVbaFormatCondition::Font(  ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
      82             : {
      83           0 :     return mxStyle->Font();
      84             : }
      85             : uno::Any SAL_CALL
      86           0 : ScVbaFormatCondition::Borders( const uno::Any& Index ) throw (script::BasicErrorException, uno::RuntimeException, std::exception)
      87           0 : { return mxStyle->Borders( Index );
      88             : }
      89             : 
      90             : sheet::ConditionOperator
      91           0 : ScVbaFormatCondition::retrieveAPIType(sal_Int32 _nVBAType, const uno::Reference< sheet::XSheetCondition >& _xSheetCondition ) throw ( script::BasicErrorException )
      92             : {
      93           0 :     sheet::ConditionOperator aAPIType = sheet::ConditionOperator_NONE;
      94           0 :     switch (_nVBAType)
      95             :     {
      96             :         case excel::XlFormatConditionType::xlExpression:
      97           0 :             aAPIType = sheet::ConditionOperator_FORMULA;
      98           0 :             break;
      99             :         case excel::XlFormatConditionType::xlCellValue:
     100           0 :             if ( _xSheetCondition.is() && (_xSheetCondition->getOperator() == sheet::ConditionOperator_FORMULA ) )
     101           0 :                 aAPIType = sheet::ConditionOperator_NONE;
     102           0 :             break;
     103             :         default:
     104           0 :             DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString() );
     105             :     }
     106           0 :     return aAPIType;
     107             : }
     108             : 
     109             : void
     110           0 : ScVbaFormatCondition::setFormula1( const uno::Any& _aFormula1) throw ( script::BasicErrorException )
     111             : {
     112             :     // getA1Formula *SHOULD* detect whether the formula is r1c1 or A1 syntax
     113             :     // and if R1C1 convert to A1
     114           0 :     ScVbaFormatCondition_BASE::setFormula1( uno::makeAny( lcl_getScVbaFormatConditionsPtr( moFormatConditions )->getA1Formula(_aFormula1) ) );
     115           0 : }
     116             : 
     117             : void
     118           0 : ScVbaFormatCondition::setFormula2( const uno::Any& _aFormula2) throw ( script::BasicErrorException )
     119             : {
     120           0 :     ScVbaFormatCondition_BASE::setFormula1( uno::makeAny( lcl_getScVbaFormatConditionsPtr( moFormatConditions )->getA1Formula(_aFormula2)) );
     121           0 : }
     122             : 
     123             : ::sal_Int32 SAL_CALL
     124           0 : ScVbaFormatCondition::Type(  ) throw ( script::BasicErrorException, uno::RuntimeException, std::exception )
     125             : {
     126           0 :     sal_Int32 nReturnType = 0;
     127           0 :     if ( mxSheetCondition->getOperator() == sheet::ConditionOperator_FORMULA)
     128           0 :         nReturnType = excel::XlFormatConditionType::xlExpression;
     129             :     else
     130           0 :         nReturnType = excel::XlFormatConditionType::xlCellValue;
     131           0 :     return nReturnType;
     132             : }
     133             : 
     134             : ::sal_Int32
     135           0 : ScVbaFormatCondition::Operator( bool bVal ) throw (script::BasicErrorException )
     136             : {
     137           0 :     return ScVbaFormatCondition_BASE::Operator( bVal );
     138             : }
     139             : ::sal_Int32 SAL_CALL
     140           0 : ScVbaFormatCondition::Operator(  ) throw (script::BasicErrorException, uno::RuntimeException)
     141             : {
     142           0 :     return ScVbaFormatCondition_BASE::Operator( true );
     143             : }
     144             : 
     145             : void
     146           0 : ScVbaFormatCondition::notifyRange() throw ( script::BasicErrorException )
     147             : {
     148             :     try
     149             :     {
     150           0 :         mxParentRangePropertySet->setPropertyValue("ConditionalFormat", uno::makeAny( mxSheetConditionalEntries) );
     151             :     }
     152           0 :     catch (uno::Exception& )
     153             :     {
     154           0 :         DebugHelper::basicexception(SbERR_METHOD_FAILED, OUString() );
     155             :     }
     156           0 : }
     157             : 
     158             : OUString
     159           0 : ScVbaFormatCondition::getServiceImplName()
     160             : {
     161           0 :     return OUString("ScVbaFormatCondition");
     162             : }
     163             : 
     164             : uno::Sequence< OUString >
     165           0 : ScVbaFormatCondition::getServiceNames()
     166             : {
     167           0 :     static uno::Sequence< OUString > aServiceNames;
     168           0 :     if ( aServiceNames.getLength() == 0 )
     169             :     {
     170           0 :         aServiceNames.realloc( 1 );
     171           0 :         aServiceNames[ 0 ] = "ooo.vba.excel.FormatCondition";
     172             :     }
     173           0 :     return aServiceNames;
     174          12 : }
     175             : 
     176             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10